Skip to content

Commit 8a99d10

Browse files
author
Michael Klimushyn
authored
Turn on RasterCache based on view hierarchy (flutter#13762)
This is a duplicate of flutter/engine#13360 with the test switched to use the software backend instead of the GL backend. After some debugging and testing on another GL embedder I think the issue with the test is some bug having to do with the GL implementation in the test harness specifically. Fixes flutter#38903
1 parent 31cd2df commit 8a99d10

File tree

16 files changed

+296
-47
lines changed

16 files changed

+296
-47
lines changed

ci/licenses_golden/licenses_flutter

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -878,6 +878,7 @@ FILE: ../../../flutter/shell/platform/embedder/fixtures/main.dart
878878
FILE: ../../../flutter/shell/platform/embedder/fixtures/scene_without_custom_compositor.png
879879
FILE: ../../../flutter/shell/platform/embedder/fixtures/scene_without_custom_compositor_with_xform.png
880880
FILE: ../../../flutter/shell/platform/embedder/fixtures/verifyb143464703.png
881+
FILE: ../../../flutter/shell/platform/embedder/fixtures/verifyb143464703_soft_noxform.png
881882
FILE: ../../../flutter/shell/platform/embedder/platform_view_embedder.cc
882883
FILE: ../../../flutter/shell/platform/embedder/platform_view_embedder.h
883884
FILE: ../../../flutter/shell/platform/embedder/vsync_waiter_embedder.cc

flow/layers/container_layer.cc

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,28 @@ void ContainerLayer::Preroll(PrerollContext* context, const SkMatrix& matrix) {
2626
void ContainerLayer::PrerollChildren(PrerollContext* context,
2727
const SkMatrix& child_matrix,
2828
SkRect* child_paint_bounds) {
29+
// Platform views have no children, so context->has_platform_view should
30+
// always be false.
31+
FML_DCHECK(!context->has_platform_view);
32+
bool child_has_platform_view = false;
2933
for (auto& layer : layers_) {
34+
// Reset context->has_platform_view to false so that layers aren't treated
35+
// as if they have a platform view based on one being previously found in a
36+
// sibling tree.
37+
context->has_platform_view = false;
38+
3039
layer->Preroll(context, child_matrix);
3140

3241
if (layer->needs_system_composite()) {
3342
set_needs_system_composite(true);
3443
}
3544
child_paint_bounds->join(layer->paint_bounds());
45+
46+
child_has_platform_view =
47+
child_has_platform_view || context->has_platform_view;
3648
}
49+
50+
context->has_platform_view = child_has_platform_view;
3751
}
3852

3953
void ContainerLayer::PaintChildren(PaintContext& context) const {

flow/layers/layer.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ struct PrerollContext {
5858
TextureRegistry& texture_registry;
5959
const bool checkerboard_offscreen_layers;
6060
float total_elevation = 0.0f;
61+
bool has_platform_view = false;
6162
};
6263

6364
// Represents a single composited layer. Created on the UI thread but then

flow/layers/opacity_layer.cc

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ void OpacityLayer::Preroll(PrerollContext* context, const SkMatrix& matrix) {
4646
set_paint_bounds(paint_bounds().makeOffset(offset_.fX, offset_.fY));
4747
// See |EnsureSingleChild|.
4848
FML_DCHECK(layers().size() == 1);
49-
if (context->view_embedder == nullptr && context->raster_cache &&
49+
if (!context->has_platform_view && context->raster_cache &&
5050
SkRect::Intersects(context->cull_rect, paint_bounds())) {
5151
Layer* child = layers()[0].get();
5252
SkMatrix ctm = child_matrix;
@@ -75,11 +75,7 @@ void OpacityLayer::Paint(PaintContext& context) const {
7575
// See |EnsureSingleChild|.
7676
FML_DCHECK(layers().size() == 1);
7777

78-
// Embedded platform views are changing the canvas in the middle of the paint
79-
// traversal. To make sure we paint on the right canvas, when the embedded
80-
// platform views preview is enabled (context.view_embedded is not null) we
81-
// don't use the cache.
82-
if (context.view_embedder == nullptr && context.raster_cache) {
78+
if (context.raster_cache) {
8379
const SkMatrix& ctm = context.leaf_nodes_canvas->getTotalMatrix();
8480
RasterCacheResult child_cache =
8581
context.raster_cache->Get(layers()[0].get(), ctm);

flow/layers/platform_view_layer.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ void PlatformViewLayer::Preroll(PrerollContext* context,
2323
"does not support embedding";
2424
return;
2525
}
26+
context->has_platform_view = true;
2627
std::unique_ptr<EmbeddedViewParams> params =
2728
std::make_unique<EmbeddedViewParams>();
2829
params->offsetPixels =

flow/raster_cache.cc

Lines changed: 26 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -157,27 +157,28 @@ void RasterCache::Prepare(PrerollContext* context,
157157
entry.access_count = ClampSize(entry.access_count + 1, 0, access_threshold_);
158158
entry.used_this_frame = true;
159159
if (!entry.image.is_valid()) {
160-
entry.image = Rasterize(context->gr_context, ctm, context->dst_color_space,
161-
checkerboard_images_, layer->paint_bounds(),
162-
[layer, context](SkCanvas* canvas) {
163-
SkISize canvas_size = canvas->getBaseLayerSize();
164-
SkNWayCanvas internal_nodes_canvas(
165-
canvas_size.width(), canvas_size.height());
166-
internal_nodes_canvas.addCanvas(canvas);
167-
Layer::PaintContext paintContext = {
168-
(SkCanvas*)&internal_nodes_canvas,
169-
canvas,
170-
context->gr_context,
171-
nullptr,
172-
context->raster_time,
173-
context->ui_time,
174-
context->texture_registry,
175-
context->raster_cache,
176-
context->checkerboard_offscreen_layers};
177-
if (layer->needs_painting()) {
178-
layer->Paint(paintContext);
179-
}
180-
});
160+
entry.image = Rasterize(
161+
context->gr_context, ctm, context->dst_color_space,
162+
checkerboard_images_, layer->paint_bounds(),
163+
[layer, context](SkCanvas* canvas) {
164+
SkISize canvas_size = canvas->getBaseLayerSize();
165+
SkNWayCanvas internal_nodes_canvas(canvas_size.width(),
166+
canvas_size.height());
167+
internal_nodes_canvas.addCanvas(canvas);
168+
Layer::PaintContext paintContext = {
169+
(SkCanvas*)&internal_nodes_canvas,
170+
canvas,
171+
context->gr_context,
172+
nullptr,
173+
context->raster_time,
174+
context->ui_time,
175+
context->texture_registry,
176+
context->has_platform_view ? nullptr : context->raster_cache,
177+
context->checkerboard_offscreen_layers};
178+
if (layer->needs_painting()) {
179+
layer->Paint(paintContext);
180+
}
181+
});
181182
}
182183
}
183184

@@ -250,6 +251,10 @@ void RasterCache::Clear() {
250251
layer_cache_.clear();
251252
}
252253

254+
size_t RasterCache::GetCachedEntriesCount() const {
255+
return layer_cache_.size() + picture_cache_.size();
256+
}
257+
253258
void RasterCache::SetCheckboardCacheImages(bool checkerboard) {
254259
if (checkerboard_images_ == checkerboard) {
255260
return;

flow/raster_cache.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,8 @@ class RasterCache {
100100

101101
void SetCheckboardCacheImages(bool checkerboard);
102102

103+
size_t GetCachedEntriesCount() const;
104+
103105
private:
104106
struct Entry {
105107
bool used_this_frame = false;

shell/common/shell.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -523,7 +523,7 @@ const TaskRunners& Shell::GetTaskRunners() const {
523523
return task_runners_;
524524
}
525525

526-
fml::WeakPtr<Rasterizer> Shell::GetRasterizer() {
526+
fml::WeakPtr<Rasterizer> Shell::GetRasterizer() const {
527527
FML_DCHECK(is_setup_);
528528
return weak_rasterizer_;
529529
}

shell/common/shell.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ class Shell final : public PlatformView::Delegate,
210210
///
211211
/// @return A weak pointer to the rasterizer.
212212
///
213-
fml::WeakPtr<Rasterizer> GetRasterizer();
213+
fml::WeakPtr<Rasterizer> GetRasterizer() const;
214214

215215
//------------------------------------------------------------------------------
216216
/// @brief Engines may only be accessed on the UI thread. This method is

shell/platform/embedder/BUILD.gn

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ test_fixtures("fixtures") {
9898
"fixtures/scene_without_custom_compositor.png",
9999
"fixtures/scene_without_custom_compositor_with_xform.png",
100100
"fixtures/verifyb143464703.png",
101+
"fixtures/verifyb143464703_soft_noxform.png",
101102
]
102103
}
103104

@@ -125,6 +126,7 @@ if (current_toolchain == host_toolchain) {
125126
deps = [
126127
":embedder",
127128
":fixtures",
129+
"$flutter_root/flow",
128130
"$flutter_root/lib/ui",
129131
"$flutter_root/runtime",
130132
"$flutter_root/testing:dart",

0 commit comments

Comments
 (0)