Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 476d3c3

Browse files
authored
Revert "[Rasterizer] Make resubmit information temporary" (#42455)
Reverts #42001 due to being the likely culprit to flakiness flutter/flutter#127936 .
1 parent efe0a9c commit 476d3c3

File tree

2 files changed

+31
-47
lines changed

2 files changed

+31
-47
lines changed

shell/common/rasterizer.cc

Lines changed: 24 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -197,19 +197,18 @@ RasterStatus Rasterizer::Draw(
197197
.GetRasterTaskRunner()
198198
->RunsTasksOnCurrentThread());
199199

200-
DoDrawResult draw_result;
200+
RasterStatus raster_status = RasterStatus::kFailed;
201201
LayerTreePipeline::Consumer consumer =
202-
[this, &draw_result,
203-
&discard_callback](std::unique_ptr<LayerTreeItem> item) {
202+
[&](std::unique_ptr<LayerTreeItem> item) {
204203
std::unique_ptr<LayerTree> layer_tree = std::move(item->layer_tree);
205204
std::unique_ptr<FrameTimingsRecorder> frame_timings_recorder =
206205
std::move(item->frame_timings_recorder);
207206
float device_pixel_ratio = item->device_pixel_ratio;
208207
if (discard_callback(*layer_tree.get())) {
209-
draw_result.raster_status = RasterStatus::kDiscarded;
208+
raster_status = RasterStatus::kDiscarded;
210209
} else {
211-
draw_result = DoDraw(std::move(frame_timings_recorder),
212-
std::move(layer_tree), device_pixel_ratio);
210+
raster_status = DoDraw(std::move(frame_timings_recorder),
211+
std::move(layer_tree), device_pixel_ratio);
213212
}
214213
};
215214

@@ -220,15 +219,18 @@ RasterStatus Rasterizer::Draw(
220219
// if the raster status is to resubmit the frame, we push the frame to the
221220
// front of the queue and also change the consume status to more available.
222221

223-
bool should_resubmit_frame = ShouldResubmitFrame(draw_result.raster_status);
222+
bool should_resubmit_frame = ShouldResubmitFrame(raster_status);
224223
if (should_resubmit_frame) {
224+
auto resubmitted_layer_tree_item = std::make_unique<LayerTreeItem>(
225+
std::move(resubmitted_layer_tree_), std::move(resubmitted_recorder_),
226+
resubmitted_pixel_ratio_);
225227
auto front_continuation = pipeline->ProduceIfEmpty();
226-
PipelineProduceResult pipeline_result = front_continuation.Complete(
227-
std::move(draw_result.resubmitted_layer_tree_item));
228-
if (pipeline_result.success) {
228+
PipelineProduceResult result =
229+
front_continuation.Complete(std::move(resubmitted_layer_tree_item));
230+
if (result.success) {
229231
consume_result = PipelineConsumeResult::MoreAvailable;
230232
}
231-
} else if (draw_result.raster_status == RasterStatus::kEnqueuePipeline) {
233+
} else if (raster_status == RasterStatus::kEnqueuePipeline) {
232234
consume_result = PipelineConsumeResult::MoreAvailable;
233235
}
234236

@@ -257,7 +259,7 @@ RasterStatus Rasterizer::Draw(
257259
break;
258260
}
259261

260-
return draw_result.raster_status;
262+
return raster_status;
261263
}
262264

263265
bool Rasterizer::ShouldResubmitFrame(const RasterStatus& raster_status) {
@@ -378,7 +380,7 @@ fml::Milliseconds Rasterizer::GetFrameBudget() const {
378380
return delegate_.GetFrameBudget();
379381
};
380382

381-
Rasterizer::DoDrawResult Rasterizer::DoDraw(
383+
RasterStatus Rasterizer::DoDraw(
382384
std::unique_ptr<FrameTimingsRecorder> frame_timings_recorder,
383385
std::unique_ptr<flutter::LayerTree> layer_tree,
384386
float device_pixel_ratio) {
@@ -389,9 +391,7 @@ Rasterizer::DoDrawResult Rasterizer::DoDraw(
389391
->RunsTasksOnCurrentThread());
390392

391393
if (!layer_tree || !surface_) {
392-
return DoDrawResult{
393-
.raster_status = RasterStatus::kFailed,
394-
};
394+
return RasterStatus::kFailed;
395395
}
396396

397397
PersistentCache* persistent_cache = PersistentCache::GetCacheForProcess();
@@ -403,18 +403,13 @@ Rasterizer::DoDrawResult Rasterizer::DoDraw(
403403
last_layer_tree_ = std::move(layer_tree);
404404
last_device_pixel_ratio_ = device_pixel_ratio;
405405
} else if (ShouldResubmitFrame(raster_status)) {
406-
return DoDrawResult{
407-
.raster_status = raster_status,
408-
.resubmitted_layer_tree_item = std::make_unique<LayerTreeItem>(
409-
std::move(layer_tree),
410-
frame_timings_recorder->CloneUntil(
411-
FrameTimingsRecorder::State::kBuildEnd),
412-
device_pixel_ratio),
413-
};
406+
resubmitted_pixel_ratio_ = device_pixel_ratio;
407+
resubmitted_layer_tree_ = std::move(layer_tree);
408+
resubmitted_recorder_ = frame_timings_recorder->CloneUntil(
409+
FrameTimingsRecorder::State::kBuildEnd);
410+
return raster_status;
414411
} else if (raster_status == RasterStatus::kDiscarded) {
415-
return DoDrawResult{
416-
.raster_status = raster_status,
417-
};
412+
return raster_status;
418413
}
419414

420415
if (persistent_cache->IsDumpingSkp() &&
@@ -482,15 +477,11 @@ Rasterizer::DoDrawResult Rasterizer::DoDraw(
482477
if (raster_thread_merger_) {
483478
if (raster_thread_merger_->DecrementLease() ==
484479
fml::RasterThreadStatus::kUnmergedNow) {
485-
return DoDrawResult{
486-
.raster_status = RasterStatus::kEnqueuePipeline,
487-
};
480+
return RasterStatus::kEnqueuePipeline;
488481
}
489482
}
490483

491-
return DoDrawResult{
492-
.raster_status = raster_status,
493-
};
484+
return raster_status;
494485
}
495486

496487
RasterStatus Rasterizer::DrawToSurface(

shell/common/rasterizer.h

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

502502
private:
503-
// The result of `DoDraw`.
504-
//
505-
// Normally `DoDraw` returns simply a raster status. However, sometimes we
506-
// need to attempt to rasterize the layer tree again. This happens when
507-
// layer_tree has not successfully rasterized due to changes in the thread
508-
// configuration, in which case the resubmitted task will be inserted to the
509-
// front of the pipeline.
510-
struct DoDrawResult {
511-
RasterStatus raster_status = RasterStatus::kFailed;
512-
513-
std::unique_ptr<LayerTreeItem> resubmitted_layer_tree_item;
514-
};
515-
516503
// |SnapshotDelegate|
517504
std::unique_ptr<GpuImageResult> MakeSkiaGpuImage(
518505
sk_sp<DisplayList> display_list,
@@ -567,7 +554,7 @@ class Rasterizer final : public SnapshotDelegate,
567554
GrDirectContext* surface_context,
568555
bool compressed);
569556

570-
DoDrawResult DoDraw(
557+
RasterStatus DoDraw(
571558
std::unique_ptr<FrameTimingsRecorder> frame_timings_recorder,
572559
std::unique_ptr<flutter::LayerTree> layer_tree,
573560
float device_pixel_ratio);
@@ -594,6 +581,12 @@ class Rasterizer final : public SnapshotDelegate,
594581
// This is the last successfully rasterized layer tree.
595582
std::unique_ptr<flutter::LayerTree> last_layer_tree_;
596583
float last_device_pixel_ratio_;
584+
// Set when we need attempt to rasterize the layer tree again. This layer_tree
585+
// has not successfully rasterized. This can happen due to the change in the
586+
// thread configuration. This will be inserted to the front of the pipeline.
587+
std::unique_ptr<flutter::LayerTree> resubmitted_layer_tree_;
588+
std::unique_ptr<FrameTimingsRecorder> resubmitted_recorder_;
589+
float resubmitted_pixel_ratio_;
597590
fml::closure next_frame_callback_;
598591
bool user_override_resource_cache_bytes_;
599592
std::optional<size_t> max_cache_bytes_;

0 commit comments

Comments
 (0)