@@ -35,6 +35,11 @@ class BackdropFilterOperation implements LayerOperation {
35
35
36
36
@override
37
37
PlatformViewStyling createPlatformViewStyling () => const PlatformViewStyling ();
38
+
39
+ // The backdrop filter actually has an effect on the scene even if it contains
40
+ // no pictures, so we return true here.
41
+ @override
42
+ bool get shouldDrawIfEmpty => true ;
38
43
}
39
44
40
45
class ClipPathLayer
@@ -70,6 +75,9 @@ class ClipPathOperation implements LayerOperation {
70
75
PlatformViewStyling createPlatformViewStyling () {
71
76
return PlatformViewStyling (clip: PlatformViewPathClip (path));
72
77
}
78
+
79
+ @override
80
+ bool get shouldDrawIfEmpty => false ;
73
81
}
74
82
75
83
class ClipRectLayer
@@ -105,6 +113,9 @@ class ClipRectOperation implements LayerOperation {
105
113
PlatformViewStyling createPlatformViewStyling () {
106
114
return PlatformViewStyling (clip: PlatformViewRectClip (rect));
107
115
}
116
+
117
+ @override
118
+ bool get shouldDrawIfEmpty => false ;
108
119
}
109
120
110
121
class ClipRRectLayer
@@ -140,6 +151,9 @@ class ClipRRectOperation implements LayerOperation {
140
151
PlatformViewStyling createPlatformViewStyling () {
141
152
return PlatformViewStyling (clip: PlatformViewRRectClip (rrect));
142
153
}
154
+
155
+ @override
156
+ bool get shouldDrawIfEmpty => false ;
143
157
}
144
158
145
159
class ColorFilterLayer
@@ -165,6 +179,9 @@ class ColorFilterOperation implements LayerOperation {
165
179
166
180
@override
167
181
PlatformViewStyling createPlatformViewStyling () => const PlatformViewStyling ();
182
+
183
+ @override
184
+ bool get shouldDrawIfEmpty => false ;
168
185
}
169
186
170
187
class ImageFilterLayer
@@ -207,6 +224,9 @@ class ImageFilterOperation implements LayerOperation {
207
224
return const PlatformViewStyling ();
208
225
}
209
226
}
227
+
228
+ @override
229
+ bool get shouldDrawIfEmpty => false ;
210
230
}
211
231
212
232
class OffsetLayer
@@ -236,6 +256,9 @@ class OffsetOperation implements LayerOperation {
236
256
PlatformViewStyling createPlatformViewStyling () => PlatformViewStyling (
237
257
position: PlatformViewPosition .offset (ui.Offset (dx, dy))
238
258
);
259
+
260
+ @override
261
+ bool get shouldDrawIfEmpty => false ;
239
262
}
240
263
241
264
class OpacityLayer
@@ -276,6 +299,9 @@ class OpacityOperation implements LayerOperation {
276
299
position: offset != ui.Offset .zero ? PlatformViewPosition .offset (offset) : const PlatformViewPosition .zero (),
277
300
opacity: alpha.toDouble () / 255.0 ,
278
301
);
302
+
303
+ @override
304
+ bool get shouldDrawIfEmpty => false ;
279
305
}
280
306
281
307
class TransformLayer
@@ -307,6 +333,9 @@ class TransformOperation implements LayerOperation {
307
333
PlatformViewStyling createPlatformViewStyling () => PlatformViewStyling (
308
334
position: PlatformViewPosition .transform (matrix),
309
335
);
336
+
337
+ @override
338
+ bool get shouldDrawIfEmpty => false ;
310
339
}
311
340
312
341
class ShaderMaskLayer
@@ -346,6 +375,9 @@ class ShaderMaskOperation implements LayerOperation {
346
375
347
376
@override
348
377
PlatformViewStyling createPlatformViewStyling () => const PlatformViewStyling ();
378
+
379
+ @override
380
+ bool get shouldDrawIfEmpty => false ;
349
381
}
350
382
351
383
class PlatformView {
@@ -414,6 +446,11 @@ abstract class LayerOperation {
414
446
void post (SceneCanvas canvas, ui.Rect contentRect);
415
447
416
448
PlatformViewStyling createPlatformViewStyling ();
449
+
450
+ /// Indicates whether this operation's `pre` and `post` methods should be
451
+ /// invoked even if it contains no pictures. (Most operations don't need to
452
+ /// actually be performed at all if they don't contain any pictures.)
453
+ bool get shouldDrawIfEmpty;
417
454
}
418
455
419
456
class PictureDrawCommand {
@@ -771,7 +808,7 @@ class LayerBuilder {
771
808
}
772
809
773
810
void flushSlices () {
774
- if (pendingPictures.isNotEmpty) {
811
+ if (pendingPictures.isNotEmpty || (operation ? .shouldDrawIfEmpty ?? false ) ) {
775
812
// Merge the existing draw commands into a single picture and add a slice
776
813
// with that picture to the slice list.
777
814
final ui.Rect drawnRect = picturesRect ?? ui.Rect .zero;
0 commit comments