Skip to content

Commit ce8a53d

Browse files
committed
Revert "Revert "[Rasterizer] Make resubmit information temporary" (flutter#42455)"
This reverts commit 476d3c3.
1 parent c380d1a commit ce8a53d

File tree

2 files changed

+46
-31
lines changed

2 files changed

+46
-31
lines changed

shell/common/rasterizer.cc

Lines changed: 32 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -206,9 +206,9 @@ RasterStatus Rasterizer::Draw(
206206
.GetRasterTaskRunner()
207207
->RunsTasksOnCurrentThread());
208208

209-
RasterStatus raster_status = RasterStatus::kFailed;
209+
DoDrawResult draw_result;
210210
LayerTreePipeline::Consumer consumer =
211-
[&raster_status, this,
211+
[&raster_status, this, &draw_result,
212212
&delegate = delegate_](std::unique_ptr<LayerTreeItem> item) {
213213
// TODO(dkwingsmt): Use a proper view ID when Rasterizer supports
214214
// multi-view.
@@ -218,10 +218,10 @@ RasterStatus Rasterizer::Draw(
218218
std::move(item->frame_timings_recorder);
219219
float device_pixel_ratio = item->device_pixel_ratio;
220220
if (delegate.ShouldDiscardLayerTree(view_id, *layer_tree.get())) {
221-
raster_status = RasterStatus::kDiscarded;
221+
draw_result.raster_status = RasterStatus::kDiscarded;
222222
} else {
223-
raster_status = DoDraw(std::move(frame_timings_recorder),
224-
std::move(layer_tree), device_pixel_ratio);
223+
draw_result = DoDraw(std::move(frame_timings_recorder),
224+
std::move(layer_tree), device_pixel_ratio);
225225
}
226226
};
227227

@@ -232,18 +232,15 @@ RasterStatus Rasterizer::Draw(
232232
// if the raster status is to resubmit the frame, we push the frame to the
233233
// front of the queue and also change the consume status to more available.
234234

235-
bool should_resubmit_frame = ShouldResubmitFrame(raster_status);
235+
bool should_resubmit_frame = ShouldResubmitFrame(draw_result.raster_status);
236236
if (should_resubmit_frame) {
237-
auto resubmitted_layer_tree_item = std::make_unique<LayerTreeItem>(
238-
std::move(resubmitted_layer_tree_), std::move(resubmitted_recorder_),
239-
resubmitted_pixel_ratio_);
240237
auto front_continuation = pipeline->ProduceIfEmpty();
241-
PipelineProduceResult result =
242-
front_continuation.Complete(std::move(resubmitted_layer_tree_item));
243-
if (result.success) {
238+
PipelineProduceResult pipeline_result = front_continuation.Complete(
239+
std::move(draw_result.resubmitted_layer_tree_item));
240+
if (pipeline_result.success) {
244241
consume_result = PipelineConsumeResult::MoreAvailable;
245242
}
246-
} else if (raster_status == RasterStatus::kEnqueuePipeline) {
243+
} else if (draw_result.raster_status == RasterStatus::kEnqueuePipeline) {
247244
consume_result = PipelineConsumeResult::MoreAvailable;
248245
}
249246

@@ -270,7 +267,7 @@ RasterStatus Rasterizer::Draw(
270267
break;
271268
}
272269

273-
return raster_status;
270+
return draw_result.raster_status;
274271
}
275272

276273
bool Rasterizer::ShouldResubmitFrame(const RasterStatus& raster_status) {
@@ -391,7 +388,7 @@ fml::Milliseconds Rasterizer::GetFrameBudget() const {
391388
return delegate_.GetFrameBudget();
392389
};
393390

394-
RasterStatus Rasterizer::DoDraw(
391+
Rasterizer::DoDrawResult Rasterizer::DoDraw(
395392
std::unique_ptr<FrameTimingsRecorder> frame_timings_recorder,
396393
std::unique_ptr<flutter::LayerTree> layer_tree,
397394
float device_pixel_ratio) {
@@ -403,7 +400,9 @@ RasterStatus Rasterizer::DoDraw(
403400
->RunsTasksOnCurrentThread());
404401

405402
if (!layer_tree || !surface_) {
406-
return RasterStatus::kFailed;
403+
return DoDrawResult{
404+
.raster_status = RasterStatus::kFailed,
405+
};
407406
}
408407

409408
PersistentCache* persistent_cache = PersistentCache::GetCacheForProcess();
@@ -415,13 +414,18 @@ RasterStatus Rasterizer::DoDraw(
415414
last_layer_tree_ = std::move(layer_tree);
416415
last_device_pixel_ratio_ = device_pixel_ratio;
417416
} else if (ShouldResubmitFrame(raster_status)) {
418-
resubmitted_pixel_ratio_ = device_pixel_ratio;
419-
resubmitted_layer_tree_ = std::move(layer_tree);
420-
resubmitted_recorder_ = frame_timings_recorder->CloneUntil(
421-
FrameTimingsRecorder::State::kBuildEnd);
422-
return raster_status;
417+
return DoDrawResult{
418+
.raster_status = raster_status,
419+
.resubmitted_layer_tree_item = std::make_unique<LayerTreeItem>(
420+
std::move(layer_tree),
421+
frame_timings_recorder->CloneUntil(
422+
FrameTimingsRecorder::State::kBuildEnd),
423+
device_pixel_ratio),
424+
};
423425
} else if (raster_status == RasterStatus::kDiscarded) {
424-
return raster_status;
426+
return DoDrawResult{
427+
.raster_status = raster_status,
428+
};
425429
}
426430

427431
if (persistent_cache->IsDumpingSkp() &&
@@ -489,11 +493,15 @@ RasterStatus Rasterizer::DoDraw(
489493
if (raster_thread_merger_) {
490494
if (raster_thread_merger_->DecrementLease() ==
491495
fml::RasterThreadStatus::kUnmergedNow) {
492-
return RasterStatus::kEnqueuePipeline;
496+
return DoDrawResult{
497+
.raster_status = RasterStatus::kEnqueuePipeline,
498+
};
493499
}
494500
}
495501

496-
return raster_status;
502+
return DoDrawResult{
503+
.raster_status = raster_status,
504+
};
497505
}
498506

499507
RasterStatus Rasterizer::DrawToSurface(

shell/common/rasterizer.h

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -512,6 +512,19 @@ class Rasterizer final : public SnapshotDelegate,
512512
void DisableThreadMergerIfNeeded();
513513

514514
private:
515+
// The result of `DoDraw`.
516+
//
517+
// Normally `DoDraw` returns simply a raster status. However, sometimes we
518+
// need to attempt to rasterize the layer tree again. This happens when
519+
// layer_tree has not successfully rasterized due to changes in the thread
520+
// configuration, in which case the resubmitted task will be inserted to the
521+
// front of the pipeline.
522+
struct DoDrawResult {
523+
RasterStatus raster_status = RasterStatus::kFailed;
524+
525+
std::unique_ptr<LayerTreeItem> resubmitted_layer_tree_item;
526+
};
527+
515528
// |SnapshotDelegate|
516529
std::unique_ptr<GpuImageResult> MakeSkiaGpuImage(
517530
sk_sp<DisplayList> display_list,
@@ -567,7 +580,7 @@ class Rasterizer final : public SnapshotDelegate,
567580
GrDirectContext* surface_context,
568581
bool compressed);
569582

570-
RasterStatus DoDraw(
583+
DoDrawResult DoDraw(
571584
std::unique_ptr<FrameTimingsRecorder> frame_timings_recorder,
572585
std::unique_ptr<flutter::LayerTree> layer_tree,
573586
float device_pixel_ratio);
@@ -593,12 +606,6 @@ class Rasterizer final : public SnapshotDelegate,
593606
// This is the last successfully rasterized layer tree.
594607
std::unique_ptr<flutter::LayerTree> last_layer_tree_;
595608
float last_device_pixel_ratio_;
596-
// Set when we need attempt to rasterize the layer tree again. This layer_tree
597-
// has not successfully rasterized. This can happen due to the change in the
598-
// thread configuration. This will be inserted to the front of the pipeline.
599-
std::unique_ptr<flutter::LayerTree> resubmitted_layer_tree_;
600-
std::unique_ptr<FrameTimingsRecorder> resubmitted_recorder_;
601-
float resubmitted_pixel_ratio_;
602609
fml::closure next_frame_callback_;
603610
bool user_override_resource_cache_bytes_;
604611
std::optional<size_t> max_cache_bytes_;

0 commit comments

Comments
 (0)