From 9815a20559a4103eb34c2c7e6d4e6e26c165bf95 Mon Sep 17 00:00:00 2001 From: Kaushik Iska Date: Wed, 3 Jul 2019 19:53:01 -0700 Subject: [PATCH] Raster now returns an enum rather than boolean (flutter/engine#9661) This is part of a bigger change that will facilitate us to act on this `RasterStatus`. The specific case is where after pre-roll we might decide to want to merge the threads and re-submit the frame -- `RasterStatus::kResubmit` can then let us achieve this result. --- engine/src/flutter/flow/compositor_context.cc | 7 ++++--- engine/src/flutter/flow/compositor_context.h | 5 ++++- engine/src/flutter/shell/common/rasterizer.cc | 16 ++++++++++------ engine/src/flutter/shell/common/rasterizer.h | 2 +- .../fuchsia/flutter/compositor_context.cc | 8 ++++---- 5 files changed, 23 insertions(+), 15 deletions(-) diff --git a/engine/src/flutter/flow/compositor_context.cc b/engine/src/flutter/flow/compositor_context.cc index bf38894b10..06da75d208 100644 --- a/engine/src/flutter/flow/compositor_context.cc +++ b/engine/src/flutter/flow/compositor_context.cc @@ -60,8 +60,9 @@ CompositorContext::ScopedFrame::~ScopedFrame() { context_.EndFrame(*this, instrumentation_enabled_); } -bool CompositorContext::ScopedFrame::Raster(flutter::LayerTree& layer_tree, - bool ignore_raster_cache) { +RasterStatus CompositorContext::ScopedFrame::Raster( + flutter::LayerTree& layer_tree, + bool ignore_raster_cache) { layer_tree.Preroll(*this, ignore_raster_cache); // Clearing canvas after preroll reduces one render target switch when preroll // paints some raster cache. @@ -69,7 +70,7 @@ bool CompositorContext::ScopedFrame::Raster(flutter::LayerTree& layer_tree, canvas()->clear(SK_ColorTRANSPARENT); } layer_tree.Paint(*this, ignore_raster_cache); - return true; + return RasterStatus::kSuccess; } void CompositorContext::OnGrContextCreated() { diff --git a/engine/src/flutter/flow/compositor_context.h b/engine/src/flutter/flow/compositor_context.h index 4266c943d1..a690a618f9 100644 --- a/engine/src/flutter/flow/compositor_context.h +++ b/engine/src/flutter/flow/compositor_context.h @@ -20,6 +20,8 @@ namespace flutter { class LayerTree; +enum class RasterStatus { kSuccess, kFailed }; + class CompositorContext { public: class ScopedFrame { @@ -45,7 +47,8 @@ class CompositorContext { GrContext* gr_context() const { return gr_context_; } - virtual bool Raster(LayerTree& layer_tree, bool ignore_raster_cache); + virtual RasterStatus Raster(LayerTree& layer_tree, + bool ignore_raster_cache); private: CompositorContext& context_; diff --git a/engine/src/flutter/shell/common/rasterizer.cc b/engine/src/flutter/shell/common/rasterizer.cc index b8f35edf28..fadfb8f9f1 100644 --- a/engine/src/flutter/shell/common/rasterizer.cc +++ b/engine/src/flutter/shell/common/rasterizer.cc @@ -187,7 +187,7 @@ void Rasterizer::DoDraw(std::unique_ptr layer_tree) { PersistentCache* persistent_cache = PersistentCache::GetCacheForProcess(); persistent_cache->ResetStoredNewShaders(); - if (DrawToSurface(*layer_tree)) { + if (DrawToSurface(*layer_tree) == RasterStatus::kSuccess) { last_layer_tree_ = std::move(layer_tree); } @@ -205,13 +205,13 @@ void Rasterizer::DoDraw(std::unique_ptr layer_tree) { delegate_.OnFrameRasterized(timing); } -bool Rasterizer::DrawToSurface(flutter::LayerTree& layer_tree) { +RasterStatus Rasterizer::DrawToSurface(flutter::LayerTree& layer_tree) { FML_DCHECK(surface_); auto frame = surface_->AcquireFrame(layer_tree.frame_size()); if (frame == nullptr) { - return false; + return RasterStatus::kFailed; } // There is no way for the compositor to know how long the layer tree @@ -231,7 +231,11 @@ bool Rasterizer::DrawToSurface(flutter::LayerTree& layer_tree) { surface_->GetContext(), canvas, external_view_embedder, surface_->GetRootTransformation(), true); - if (compositor_frame && compositor_frame->Raster(layer_tree, false)) { + if (compositor_frame) { + RasterStatus raster_status = compositor_frame->Raster(layer_tree, false); + if (raster_status == RasterStatus::kFailed) { + return raster_status; + } frame->Submit(); if (external_view_embedder != nullptr) { external_view_embedder->SubmitFrame(surface_->GetContext()); @@ -241,10 +245,10 @@ bool Rasterizer::DrawToSurface(flutter::LayerTree& layer_tree) { if (surface_->GetContext()) surface_->GetContext()->performDeferredCleanup(kSkiaCleanupExpiration); - return true; + return raster_status; } - return false; + return RasterStatus::kFailed; } static sk_sp SerializeTypeface(SkTypeface* typeface, void* ctx) { diff --git a/engine/src/flutter/shell/common/rasterizer.h b/engine/src/flutter/shell/common/rasterizer.h index ffeb0488f8..052fb64685 100644 --- a/engine/src/flutter/shell/common/rasterizer.h +++ b/engine/src/flutter/shell/common/rasterizer.h @@ -116,7 +116,7 @@ class Rasterizer final : public SnapshotDelegate { void DoDraw(std::unique_ptr layer_tree); - bool DrawToSurface(flutter::LayerTree& layer_tree); + RasterStatus DrawToSurface(flutter::LayerTree& layer_tree); void FireNextFrameCallbackIfPresent(); diff --git a/engine/src/flutter/shell/platform/fuchsia/flutter/compositor_context.cc b/engine/src/flutter/shell/platform/fuchsia/flutter/compositor_context.cc index 6c56d262a2..1f4c8e854f 100644 --- a/engine/src/flutter/shell/platform/fuchsia/flutter/compositor_context.cc +++ b/engine/src/flutter/shell/platform/fuchsia/flutter/compositor_context.cc @@ -25,10 +25,10 @@ class ScopedFrame final : public flutter::CompositorContext::ScopedFrame { private: SessionConnection& session_connection_; - bool Raster(flutter::LayerTree& layer_tree, - bool ignore_raster_cache) override { + flutter::RasterStatus Raster(flutter::LayerTree& layer_tree, + bool ignore_raster_cache) override { if (!session_connection_.has_metrics()) { - return true; + return flutter::RasterStatus::kSuccess; } { @@ -52,7 +52,7 @@ class ScopedFrame final : public flutter::CompositorContext::ScopedFrame { session_connection_.Present(*this); } - return true; + return flutter::RasterStatus::kSuccess; } FML_DISALLOW_COPY_AND_ASSIGN(ScopedFrame);