From 65e74322f123afc313d74ef884226b0c782ca985 Mon Sep 17 00:00:00 2001 From: Tong Mu Date: Fri, 12 May 2023 16:27:43 -0700 Subject: [PATCH 1/3] Extract recommitted --- shell/common/rasterizer.cc | 56 +++++++++++++++++++++++--------------- shell/common/rasterizer.h | 23 +++++++++++----- 2 files changed, 50 insertions(+), 29 deletions(-) diff --git a/shell/common/rasterizer.cc b/shell/common/rasterizer.cc index 3041e84d2706c..1415385663e49 100644 --- a/shell/common/rasterizer.cc +++ b/shell/common/rasterizer.cc @@ -192,18 +192,19 @@ RasterStatus Rasterizer::Draw( .GetRasterTaskRunner() ->RunsTasksOnCurrentThread()); - RasterStatus raster_status = RasterStatus::kFailed; + DoDrawResult draw_result; LayerTreePipeline::Consumer consumer = - [&](std::unique_ptr item) { + [this, &draw_result, + &discard_callback](std::unique_ptr item) { std::unique_ptr layer_tree = std::move(item->layer_tree); std::unique_ptr frame_timings_recorder = std::move(item->frame_timings_recorder); float device_pixel_ratio = item->device_pixel_ratio; if (discard_callback(*layer_tree.get())) { - raster_status = RasterStatus::kDiscarded; + draw_result.raster_status = RasterStatus::kDiscarded; } else { - raster_status = DoDraw(std::move(frame_timings_recorder), - std::move(layer_tree), device_pixel_ratio); + draw_result = DoDraw(std::move(frame_timings_recorder), + std::move(layer_tree), device_pixel_ratio); } }; @@ -214,18 +215,19 @@ RasterStatus Rasterizer::Draw( // if the raster status is to resubmit the frame, we push the frame to the // front of the queue and also change the consume status to more available. - bool should_resubmit_frame = ShouldResubmitFrame(raster_status); + bool should_resubmit_frame = ShouldResubmitFrame(draw_result.raster_status); if (should_resubmit_frame) { auto resubmitted_layer_tree_item = std::make_unique( - std::move(resubmitted_layer_tree_), std::move(resubmitted_recorder_), - resubmitted_pixel_ratio_); + std::move(draw_result.resubmitted_layer_tree), + std::move(draw_result.resubmitted_recorder), + draw_result.resubmitted_pixel_ratio); auto front_continuation = pipeline->ProduceIfEmpty(); - PipelineProduceResult result = + PipelineProduceResult pipeline_result = front_continuation.Complete(std::move(resubmitted_layer_tree_item)); - if (result.success) { + if (pipeline_result.success) { consume_result = PipelineConsumeResult::MoreAvailable; } - } else if (raster_status == RasterStatus::kEnqueuePipeline) { + } else if (draw_result.raster_status == RasterStatus::kEnqueuePipeline) { consume_result = PipelineConsumeResult::MoreAvailable; } @@ -254,7 +256,7 @@ RasterStatus Rasterizer::Draw( break; } - return raster_status; + return draw_result.raster_status; } bool Rasterizer::ShouldResubmitFrame(const RasterStatus& raster_status) { @@ -375,7 +377,7 @@ fml::Milliseconds Rasterizer::GetFrameBudget() const { return delegate_.GetFrameBudget(); }; -RasterStatus Rasterizer::DoDraw( +Rasterizer::DoDrawResult Rasterizer::DoDraw( std::unique_ptr frame_timings_recorder, std::unique_ptr layer_tree, float device_pixel_ratio) { @@ -386,7 +388,9 @@ RasterStatus Rasterizer::DoDraw( ->RunsTasksOnCurrentThread()); if (!layer_tree || !surface_) { - return RasterStatus::kFailed; + return DoDrawResult{ + .raster_status = RasterStatus::kFailed, + }; } PersistentCache* persistent_cache = PersistentCache::GetCacheForProcess(); @@ -398,13 +402,17 @@ RasterStatus Rasterizer::DoDraw( last_layer_tree_ = std::move(layer_tree); last_device_pixel_ratio_ = device_pixel_ratio; } else if (ShouldResubmitFrame(raster_status)) { - resubmitted_pixel_ratio_ = device_pixel_ratio; - resubmitted_layer_tree_ = std::move(layer_tree); - resubmitted_recorder_ = frame_timings_recorder->CloneUntil( - FrameTimingsRecorder::State::kBuildEnd); - return raster_status; + return DoDrawResult{ + .raster_status = raster_status, + .resubmitted_layer_tree = std::move(layer_tree), + .resubmitted_recorder = frame_timings_recorder->CloneUntil( + FrameTimingsRecorder::State::kBuildEnd), + .resubmitted_pixel_ratio = device_pixel_ratio, + }; } else if (raster_status == RasterStatus::kDiscarded) { - return raster_status; + return DoDrawResult{ + .raster_status = raster_status, + }; } if (persistent_cache->IsDumpingSkp() && @@ -472,11 +480,15 @@ RasterStatus Rasterizer::DoDraw( if (raster_thread_merger_) { if (raster_thread_merger_->DecrementLease() == fml::RasterThreadStatus::kUnmergedNow) { - return RasterStatus::kEnqueuePipeline; + return DoDrawResult{ + .raster_status = RasterStatus::kEnqueuePipeline, + }; } } - return raster_status; + return DoDrawResult{ + .raster_status = raster_status, + }; } RasterStatus Rasterizer::DrawToSurface( diff --git a/shell/common/rasterizer.h b/shell/common/rasterizer.h index b17242342c084..1e996d319630a 100644 --- a/shell/common/rasterizer.h +++ b/shell/common/rasterizer.h @@ -500,6 +500,21 @@ class Rasterizer final : public SnapshotDelegate, void DisableThreadMergerIfNeeded(); private: + // The result of `DoDraw`. + // + // Normally `DrDraw` returns simply a raster status. However, sometimes we + // need to attempt to rasterize the layer tree again. This happens when + // layer_tree has not successfully rasterized due to changes in the thread + // configuration, in which case the resubmitted task will be inserted to the + // front of the pipeline. + struct DoDrawResult { + RasterStatus raster_status = RasterStatus::kFailed; + + std::unique_ptr resubmitted_layer_tree; + std::unique_ptr resubmitted_recorder; + float resubmitted_pixel_ratio; + }; + // |SnapshotDelegate| std::unique_ptr MakeSkiaGpuImage( sk_sp display_list, @@ -554,7 +569,7 @@ class Rasterizer final : public SnapshotDelegate, GrDirectContext* surface_context, bool compressed); - RasterStatus DoDraw( + DoDrawResult DoDraw( std::unique_ptr frame_timings_recorder, std::unique_ptr layer_tree, float device_pixel_ratio); @@ -581,12 +596,6 @@ class Rasterizer final : public SnapshotDelegate, // This is the last successfully rasterized layer tree. std::unique_ptr last_layer_tree_; float last_device_pixel_ratio_; - // Set when we need attempt to rasterize the layer tree again. This layer_tree - // has not successfully rasterized. This can happen due to the change in the - // thread configuration. This will be inserted to the front of the pipeline. - std::unique_ptr resubmitted_layer_tree_; - std::unique_ptr resubmitted_recorder_; - float resubmitted_pixel_ratio_; fml::closure next_frame_callback_; bool user_override_resource_cache_bytes_; std::optional max_cache_bytes_; From c7ebf4e43fe310acd0a18586ccb0742b2d4a3169 Mon Sep 17 00:00:00 2001 From: Tong Mu Date: Fri, 12 May 2023 16:38:05 -0700 Subject: [PATCH 2/3] Create layer tree item early --- shell/common/rasterizer.cc | 17 +++++++---------- shell/common/rasterizer.h | 4 +--- 2 files changed, 8 insertions(+), 13 deletions(-) diff --git a/shell/common/rasterizer.cc b/shell/common/rasterizer.cc index 1415385663e49..6d79d3f822ef5 100644 --- a/shell/common/rasterizer.cc +++ b/shell/common/rasterizer.cc @@ -217,13 +217,9 @@ RasterStatus Rasterizer::Draw( bool should_resubmit_frame = ShouldResubmitFrame(draw_result.raster_status); if (should_resubmit_frame) { - auto resubmitted_layer_tree_item = std::make_unique( - std::move(draw_result.resubmitted_layer_tree), - std::move(draw_result.resubmitted_recorder), - draw_result.resubmitted_pixel_ratio); auto front_continuation = pipeline->ProduceIfEmpty(); - PipelineProduceResult pipeline_result = - front_continuation.Complete(std::move(resubmitted_layer_tree_item)); + PipelineProduceResult pipeline_result = front_continuation.Complete( + std::move(draw_result.resubmitted_layer_tree_item)); if (pipeline_result.success) { consume_result = PipelineConsumeResult::MoreAvailable; } @@ -404,10 +400,11 @@ Rasterizer::DoDrawResult Rasterizer::DoDraw( } else if (ShouldResubmitFrame(raster_status)) { return DoDrawResult{ .raster_status = raster_status, - .resubmitted_layer_tree = std::move(layer_tree), - .resubmitted_recorder = frame_timings_recorder->CloneUntil( - FrameTimingsRecorder::State::kBuildEnd), - .resubmitted_pixel_ratio = device_pixel_ratio, + .resubmitted_layer_tree_item = std::make_unique( + std::move(layer_tree), + frame_timings_recorder->CloneUntil( + FrameTimingsRecorder::State::kBuildEnd), + device_pixel_ratio), }; } else if (raster_status == RasterStatus::kDiscarded) { return DoDrawResult{ diff --git a/shell/common/rasterizer.h b/shell/common/rasterizer.h index 1e996d319630a..a41ec24d881b7 100644 --- a/shell/common/rasterizer.h +++ b/shell/common/rasterizer.h @@ -510,9 +510,7 @@ class Rasterizer final : public SnapshotDelegate, struct DoDrawResult { RasterStatus raster_status = RasterStatus::kFailed; - std::unique_ptr resubmitted_layer_tree; - std::unique_ptr resubmitted_recorder; - float resubmitted_pixel_ratio; + std::unique_ptr resubmitted_layer_tree_item; }; // |SnapshotDelegate| From 84263c4ca87add62a5d2f1e40ed7f88628668477 Mon Sep 17 00:00:00 2001 From: Tong Mu Date: Fri, 12 May 2023 16:38:54 -0700 Subject: [PATCH 3/3] Typo --- shell/common/rasterizer.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shell/common/rasterizer.h b/shell/common/rasterizer.h index a41ec24d881b7..93747c3f77505 100644 --- a/shell/common/rasterizer.h +++ b/shell/common/rasterizer.h @@ -502,7 +502,7 @@ class Rasterizer final : public SnapshotDelegate, private: // The result of `DoDraw`. // - // Normally `DrDraw` returns simply a raster status. However, sometimes we + // Normally `DoDraw` returns simply a raster status. However, sometimes we // need to attempt to rasterize the layer tree again. This happens when // layer_tree has not successfully rasterized due to changes in the thread // configuration, in which case the resubmitted task will be inserted to the