Skip to content

Commit c6e6da5

Browse files
authored
Revert "Allow raster caching any layer subtree (#6442)" (#6506)
Reverts flutter/engine#6442 container_layer.h file is not synced which broke the bots
1 parent 6447418 commit c6e6da5

15 files changed

+119
-248
lines changed

flow/compositor_context.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ CompositorContext::ScopedFrame::~ScopedFrame() {
6363
bool CompositorContext::ScopedFrame::Raster(flow::LayerTree& layer_tree,
6464
bool ignore_raster_cache) {
6565
layer_tree.Preroll(*this, ignore_raster_cache);
66-
layer_tree.Paint(*this, ignore_raster_cache);
66+
layer_tree.Paint(*this);
6767
return true;
6868
}
6969

flow/debug_print.cc

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,9 @@ std::ostream& operator<<(std::ostream& os, const flow::MatrixDecomposition& m) {
2525

2626
std::ostream& operator<<(std::ostream& os, const SkMatrix& m) {
2727
SkString string;
28-
string.printf("[%8.4f %8.4f %8.4f][%8.4f %8.4f %8.4f][%8.4f %8.4f %8.4f]",
29-
m[0], m[1], m[2], m[3], m[4], m[5], m[6], m[7], m[8]);
28+
string.printf(
29+
"[%8.4f %8.4f %8.4f][%8.4f %8.4f %8.4f][%8.4f %8.4f %8.4f]",
30+
m[0], m[1], m[2], m[3], m[4], m[5], m[6], m[7], m[8]);
3031
os << string.c_str();
3132
return os;
3233
}
@@ -71,9 +72,8 @@ std::ostream& operator<<(std::ostream& os, const SkPoint& r) {
7172
return os;
7273
}
7374

74-
std::ostream& operator<<(std::ostream& os,
75-
const flow::PictureRasterCacheKey& k) {
76-
os << "Picture: " << k.id() << " matrix: " << k.matrix();
75+
std::ostream& operator<<(std::ostream& os, const flow::RasterCacheKey& k) {
76+
os << "Picture: " << k.picture_id() << " matrix: " << k.matrix();
7777
return os;
7878
}
7979

flow/debug_print.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
#define DEF_PRINTER(x) std::ostream& operator<<(std::ostream&, const x&);
1717

1818
DEF_PRINTER(flow::MatrixDecomposition);
19-
DEF_PRINTER(flow::PictureRasterCacheKey);
19+
DEF_PRINTER(flow::RasterCacheKey);
2020
DEF_PRINTER(SkISize);
2121
DEF_PRINTER(SkMatrix);
2222
DEF_PRINTER(SkMatrix44);

flow/layers/layer.h

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -40,34 +40,27 @@ enum Clip { none, hardEdge, antiAlias, antiAliasWithSaveLayer };
4040

4141
class ContainerLayer;
4242

43-
struct PrerollContext {
44-
RasterCache* raster_cache;
45-
GrContext* gr_context;
46-
SkColorSpace* dst_color_space;
47-
SkRect child_paint_bounds;
48-
49-
// The following allows us to paint in the end of subtree preroll
50-
const Stopwatch& frame_time;
51-
const Stopwatch& engine_time;
52-
TextureRegistry& texture_registry;
53-
const bool checkerboard_offscreen_layers;
54-
};
55-
5643
// Represents a single composited layer. Created on the UI thread but then
5744
// subquently used on the Rasterizer thread.
5845
class Layer {
5946
public:
6047
Layer();
6148
virtual ~Layer();
6249

50+
struct PrerollContext {
51+
RasterCache* raster_cache;
52+
GrContext* gr_context;
53+
SkColorSpace* dst_color_space;
54+
SkRect child_paint_bounds;
55+
};
56+
6357
virtual void Preroll(PrerollContext* context, const SkMatrix& matrix);
6458

6559
struct PaintContext {
6660
SkCanvas& canvas;
6761
const Stopwatch& frame_time;
6862
const Stopwatch& engine_time;
6963
TextureRegistry& texture_registry;
70-
const RasterCache* raster_cache;
7164
const bool checkerboard_offscreen_layers;
7265
};
7366

flow/layers/layer_tree.cc

Lines changed: 16 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,12 @@ void LayerTree::Preroll(CompositorContext::ScopedFrame& frame,
2525
frame.canvas() ? frame.canvas()->imageInfo().colorSpace() : nullptr;
2626
frame.context().raster_cache().SetCheckboardCacheImages(
2727
checkerboard_raster_cache_images_);
28-
PrerollContext context = {
28+
Layer::PrerollContext context = {
2929
ignore_raster_cache ? nullptr : &frame.context().raster_cache(),
3030
frame.gr_context(),
3131
color_space,
3232
SkRect::MakeEmpty(),
33-
frame.context().frame_time(),
34-
frame.context().engine_time(),
35-
frame.context().texture_registry(),
36-
checkerboard_offscreen_layers_};
33+
};
3734

3835
root_layer_->Preroll(&context, frame.root_surface_transformation());
3936
}
@@ -63,16 +60,15 @@ void LayerTree::UpdateScene(SceneUpdateContext& context,
6360
}
6461
#endif
6562

66-
void LayerTree::Paint(CompositorContext::ScopedFrame& frame,
67-
bool ignore_raster_cache) const {
63+
void LayerTree::Paint(CompositorContext::ScopedFrame& frame) const {
6864
TRACE_EVENT0("flutter", "LayerTree::Paint");
6965
Layer::PaintContext context = {
70-
*frame.canvas(),
71-
frame.context().frame_time(),
72-
frame.context().engine_time(),
73-
frame.context().texture_registry(),
74-
ignore_raster_cache ? nullptr : &frame.context().raster_cache(),
75-
checkerboard_offscreen_layers_};
66+
*frame.canvas(), //
67+
frame.context().frame_time(), //
68+
frame.context().engine_time(), //
69+
frame.context().texture_registry(), //
70+
checkerboard_offscreen_layers_ //
71+
};
7672

7773
if (root_layer_->needs_painting())
7874
root_layer_->Paint(context);
@@ -88,29 +84,24 @@ sk_sp<SkPicture> LayerTree::Flatten(const SkRect& bounds) {
8884
return nullptr;
8985
}
9086

87+
Layer::PrerollContext preroll_context{
88+
nullptr, // raster_cache (don't consult the cache)
89+
nullptr, // gr_context (used for the raster cache)
90+
nullptr, // SkColorSpace* dst_color_space
91+
SkRect::MakeEmpty(), // SkRect child_paint_bounds
92+
};
93+
9194
const Stopwatch unused_stopwatch;
9295
TextureRegistry unused_texture_registry;
9396
SkMatrix root_surface_transformation;
9497
// No root surface transformation. So assume identity.
9598
root_surface_transformation.reset();
9699

97-
PrerollContext preroll_context{
98-
nullptr, // raster_cache (don't consult the cache)
99-
nullptr, // gr_context (used for the raster cache)
100-
nullptr, // SkColorSpace* dst_color_space
101-
SkRect::MakeEmpty(), // SkRect child_paint_bounds
102-
unused_stopwatch, // frame time (dont care)
103-
unused_stopwatch, // engine time (dont care)
104-
unused_texture_registry, // texture registry (not supported)
105-
false, // checkerboard_offscreen_layers
106-
};
107-
108100
Layer::PaintContext paint_context = {
109101
*canvas, // canvas
110102
unused_stopwatch, // frame time (dont care)
111103
unused_stopwatch, // engine time (dont care)
112104
unused_texture_registry, // texture registry (not supported)
113-
nullptr, // raster cache
114105
false // checkerboard offscreen layers
115106
};
116107

flow/layers/layer_tree.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,7 @@ class LayerTree {
3232
scenic::ContainerNode& container);
3333
#endif
3434

35-
void Paint(CompositorContext::ScopedFrame& frame,
36-
bool ignore_raster_cache = false) const;
35+
void Paint(CompositorContext::ScopedFrame& frame) const;
3736

3837
sk_sp<SkPicture> Flatten(const SkRect& bounds);
3938

flow/layers/opacity_layer.cc

Lines changed: 1 addition & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -10,42 +10,14 @@ OpacityLayer::OpacityLayer() = default;
1010

1111
OpacityLayer::~OpacityLayer() = default;
1212

13-
void OpacityLayer::Preroll(PrerollContext* context, const SkMatrix& matrix) {
14-
ContainerLayer::Preroll(context, matrix);
15-
if (context->raster_cache && layers().size() == 1) {
16-
std::shared_ptr<Layer> child = layers()[0];
17-
SkMatrix ctm = matrix;
18-
#ifndef SUPPORT_FRACTIONAL_TRANSLATION
19-
ctm = RasterCache::GetIntegralTransCTM(ctm);
20-
#endif
21-
context->raster_cache->Prepare(context, child, ctm);
22-
}
23-
}
24-
2513
void OpacityLayer::Paint(PaintContext& context) const {
2614
TRACE_EVENT0("flutter", "OpacityLayer::Paint");
2715
FML_DCHECK(needs_painting());
2816

2917
SkPaint paint;
3018
paint.setAlpha(alpha_);
3119

32-
SkAutoCanvasRestore save(&context.canvas, true);
33-
34-
#ifndef SUPPORT_FRACTIONAL_TRANSLATION
35-
context.canvas.setMatrix(
36-
RasterCache::GetIntegralTransCTM(context.canvas.getTotalMatrix()));
37-
#endif
38-
39-
if (layers().size() == 1 && context.raster_cache) {
40-
const SkMatrix& ctm = context.canvas.getTotalMatrix();
41-
RasterCacheResult child_cache = context.raster_cache->Get(layers()[0], ctm);
42-
if (child_cache.is_valid()) {
43-
child_cache.draw(context.canvas, &paint);
44-
return;
45-
}
46-
}
47-
48-
Layer::AutoSaveLayer save_layer =
20+
Layer::AutoSaveLayer save =
4921
Layer::AutoSaveLayer::Create(context, paint_bounds(), &paint);
5022
PaintChildren(context);
5123
}

flow/layers/opacity_layer.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@ class OpacityLayer : public ContainerLayer {
1616

1717
void set_alpha(int alpha) { alpha_ = alpha; }
1818

19-
void Preroll(PrerollContext* context, const SkMatrix& matrix) override;
20-
2119
void Paint(PaintContext& context) const override;
2220

2321
// TODO(chinmaygarde): Once MZ-139 is addressed, introduce a new node in the

flow/layers/picture_layer.cc

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,11 @@ void PictureLayer::Preroll(PrerollContext* context, const SkMatrix& matrix) {
2121
#ifndef SUPPORT_FRACTIONAL_TRANSLATION
2222
ctm = RasterCache::GetIntegralTransCTM(ctm);
2323
#endif
24-
cache->Prepare(context->gr_context, sk_picture, ctm,
25-
context->dst_color_space, is_complex_, will_change_);
24+
raster_cache_result_ = cache->GetPrerolledImage(
25+
context->gr_context, sk_picture, ctm, context->dst_color_space,
26+
is_complex_, will_change_);
27+
} else {
28+
raster_cache_result_ = RasterCacheResult();
2629
}
2730

2831
SkRect bounds = sk_picture->cullRect().makeOffset(offset_.x(), offset_.y());
@@ -41,15 +44,11 @@ void PictureLayer::Paint(PaintContext& context) const {
4144
RasterCache::GetIntegralTransCTM(context.canvas.getTotalMatrix()));
4245
#endif
4346

44-
if (context.raster_cache) {
45-
const SkMatrix& ctm = context.canvas.getTotalMatrix();
46-
RasterCacheResult result = context.raster_cache->Get(*picture(), ctm);
47-
if (result.is_valid()) {
48-
result.draw(context.canvas);
49-
return;
50-
}
47+
if (raster_cache_result_.is_valid()) {
48+
raster_cache_result_.draw(context.canvas);
49+
} else {
50+
context.canvas.drawPicture(picture());
5151
}
52-
context.canvas.drawPicture(picture());
5352
}
5453

5554
} // namespace flow

flow/layers/picture_layer.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ class PictureLayer : public Layer {
3939
SkiaGPUObject<SkPicture> picture_;
4040
bool is_complex_ = false;
4141
bool will_change_ = false;
42+
RasterCacheResult raster_cache_result_;
4243

4344
FML_DISALLOW_COPY_AND_ASSIGN(PictureLayer);
4445
};

0 commit comments

Comments
 (0)