Make the rasterizer own the compositor context. (flutter/engine#5034)
This allows the texture registry to be accessed before render surface acquisition.
This commit is contained in:
committed by
Todd Volkert
parent
77b1a14fde
commit
e01a739b45
@@ -28,19 +28,17 @@ fml::WeakPtr<Rasterizer> Rasterizer::GetWeakPtr() const {
|
||||
|
||||
void Rasterizer::Setup(std::unique_ptr<Surface> surface) {
|
||||
surface_ = std::move(surface);
|
||||
compositor_context_.OnGrContextCreated();
|
||||
}
|
||||
|
||||
void Rasterizer::Teardown() {
|
||||
compositor_context_.OnGrContextDestroyed();
|
||||
surface_.reset();
|
||||
last_layer_tree_.reset();
|
||||
}
|
||||
|
||||
flow::TextureRegistry* Rasterizer::GetTextureRegistry() {
|
||||
if (!surface_) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return &(surface_->GetCompositorContext().texture_registry());
|
||||
return &compositor_context_.texture_registry();
|
||||
}
|
||||
|
||||
flow::LayerTree* Rasterizer::GetLastLayerTree() {
|
||||
@@ -97,14 +95,12 @@ bool Rasterizer::DrawToSurface(flow::LayerTree& layer_tree) {
|
||||
return false;
|
||||
}
|
||||
|
||||
auto& compositor_context = surface_->GetCompositorContext();
|
||||
|
||||
// There is no way for the compositor to know how long the layer tree
|
||||
// construction took. Fortunately, the layer tree does. Grab that time
|
||||
// for instrumentation.
|
||||
compositor_context.engine_time().SetLapTime(layer_tree.construction_time());
|
||||
compositor_context_.engine_time().SetLapTime(layer_tree.construction_time());
|
||||
|
||||
auto compositor_frame = compositor_context.AcquireFrame(
|
||||
auto compositor_frame = compositor_context_.AcquireFrame(
|
||||
surface_->GetContext(), frame->SkiaCanvas(), true);
|
||||
|
||||
if (compositor_frame && compositor_frame->Raster(layer_tree, false)) {
|
||||
|
||||
@@ -62,7 +62,7 @@ class Rasterizer final {
|
||||
private:
|
||||
blink::TaskRunners task_runners_;
|
||||
std::unique_ptr<Surface> surface_;
|
||||
std::unique_ptr<flow::CompositorContext> compositor_context_;
|
||||
flow::CompositorContext compositor_context_;
|
||||
std::unique_ptr<flow::LayerTree> last_layer_tree_;
|
||||
fxl::Closure next_frame_callback_;
|
||||
fml::WeakPtr<Rasterizer> weak_prototype_;
|
||||
|
||||
@@ -60,22 +60,8 @@ bool SurfaceFrame::PerformSubmit() {
|
||||
return false;
|
||||
}
|
||||
|
||||
Surface::Surface() : Surface(std::make_unique<flow::CompositorContext>()) {}
|
||||
Surface::Surface() = default;
|
||||
|
||||
Surface::Surface(std::unique_ptr<flow::CompositorContext> compositor_context)
|
||||
: compositor_context_(std::move(compositor_context)) {
|
||||
FXL_DCHECK(compositor_context_);
|
||||
// TODO: Get rid of these explicit calls and move the logic to the c/dtors of
|
||||
// the compositor context.
|
||||
compositor_context_->OnGrContextCreated();
|
||||
}
|
||||
|
||||
Surface::~Surface() {
|
||||
compositor_context_->OnGrContextDestroyed();
|
||||
}
|
||||
|
||||
flow::CompositorContext& Surface::GetCompositorContext() {
|
||||
return *compositor_context_;
|
||||
}
|
||||
Surface::~Surface() = default;
|
||||
|
||||
} // namespace shell
|
||||
|
||||
@@ -45,8 +45,6 @@ class Surface {
|
||||
public:
|
||||
Surface();
|
||||
|
||||
Surface(std::unique_ptr<flow::CompositorContext> compositor_context);
|
||||
|
||||
virtual ~Surface();
|
||||
|
||||
virtual bool IsValid() = 0;
|
||||
@@ -55,11 +53,7 @@ class Surface {
|
||||
|
||||
virtual GrContext* GetContext() = 0;
|
||||
|
||||
flow::CompositorContext& GetCompositorContext();
|
||||
|
||||
private:
|
||||
std::unique_ptr<flow::CompositorContext> compositor_context_;
|
||||
|
||||
FXL_DISALLOW_COPY_AND_ASSIGN(Surface);
|
||||
};
|
||||
|
||||
|
||||
@@ -72,8 +72,6 @@ GPUSurfaceGL::~GPUSurfaceGL() {
|
||||
return;
|
||||
}
|
||||
|
||||
GetCompositorContext().OnGrContextDestroyed();
|
||||
|
||||
onscreen_surface_ = nullptr;
|
||||
context_->releaseResourcesAndAbandonContext();
|
||||
context_ = nullptr;
|
||||
|
||||
Reference in New Issue
Block a user