Skip to content

Commit 8049ea9

Browse files
committed
Framework support for checkerboardOffscreenLayers
See flutter#9473
1 parent b4e0e54 commit 8049ea9

8 files changed

Lines changed: 108 additions & 9 deletions

File tree

‎examples/flutter_gallery/lib/gallery/app.dart‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ class GalleryApp extends StatefulWidget {
3636
this.updateUrlFetcher,
3737
this.enablePerformanceOverlay: true,
3838
this.checkerboardRasterCacheImages: true,
39+
this.checkerboardOffscreenLayers: true,
3940
this.onSendFeedback,
4041
Key key}
4142
) : super(key: key);
@@ -46,6 +47,8 @@ class GalleryApp extends StatefulWidget {
4647

4748
final bool checkerboardRasterCacheImages;
4849

50+
final bool checkerboardOffscreenLayers;
51+
4952
final VoidCallback onSendFeedback;
5053

5154
@override
@@ -56,6 +59,7 @@ class GalleryAppState extends State<GalleryApp> {
5659
bool _useLightTheme = true;
5760
bool _showPerformanceOverlay = false;
5861
bool _checkerboardRasterCacheImages = false;
62+
bool _checkerboardOffscreenLayers = false;
5963
double _timeDilation = 1.0;
6064
TargetPlatform _platform;
6165

@@ -95,6 +99,12 @@ class GalleryAppState extends State<GalleryApp> {
9599
_checkerboardRasterCacheImages = value;
96100
});
97101
} : null,
102+
checkerboardOffscreenLayers: _checkerboardOffscreenLayers,
103+
onCheckerboardOffscreenLayersChanged: widget.checkerboardOffscreenLayers ? (bool value) {
104+
setState(() {
105+
_checkerboardOffscreenLayers = value;
106+
});
107+
} : null,
98108
onPlatformChanged: (TargetPlatform value) {
99109
setState(() {
100110
_platform = value == defaultTargetPlatform ? null : value;
@@ -134,6 +144,7 @@ class GalleryAppState extends State<GalleryApp> {
134144
theme: (_useLightTheme ? _kGalleryLightTheme : _kGalleryDarkTheme).copyWith(platform: _platform ?? defaultTargetPlatform),
135145
showPerformanceOverlay: _showPerformanceOverlay,
136146
checkerboardRasterCacheImages: _checkerboardRasterCacheImages,
147+
checkerboardOffscreenLayers: _checkerboardOffscreenLayers,
137148
routes: _kRoutes,
138149
home: home,
139150
);

‎examples/flutter_gallery/lib/gallery/drawer.dart‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,8 @@ class GalleryDrawer extends StatelessWidget {
9898
this.onShowPerformanceOverlayChanged,
9999
this.checkerboardRasterCacheImages,
100100
this.onCheckerboardRasterCacheImagesChanged,
101+
this.checkerboardOffscreenLayers,
102+
this.onCheckerboardOffscreenLayersChanged,
101103
this.onPlatformChanged,
102104
this.onSendFeedback,
103105
}) : super(key: key) {
@@ -117,6 +119,9 @@ class GalleryDrawer extends StatelessWidget {
117119
final bool checkerboardRasterCacheImages;
118120
final ValueChanged<bool> onCheckerboardRasterCacheImagesChanged;
119121

122+
final bool checkerboardOffscreenLayers;
123+
final ValueChanged<bool> onCheckerboardOffscreenLayersChanged;
124+
120125
final ValueChanged<TargetPlatform> onPlatformChanged;
121126

122127
final VoidCallback onSendFeedback;
@@ -299,6 +304,23 @@ class GalleryDrawer extends StatelessWidget {
299304
));
300305
}
301306

307+
if (onCheckerboardOffscreenLayersChanged != null) {
308+
allDrawerItems.insert(8, new ListTile(
309+
leading: const Icon(Icons.assessment),
310+
title: const Text('Checkerboard Offscreen Layers'),
311+
trailing: new Checkbox(
312+
value: checkerboardOffscreenLayers,
313+
onChanged: (bool value) {
314+
onCheckerboardOffscreenLayersChanged(!checkerboardOffscreenLayers);
315+
},
316+
),
317+
selected: checkerboardOffscreenLayers,
318+
onTap: () {
319+
onCheckerboardOffscreenLayersChanged(!checkerboardOffscreenLayers);
320+
},
321+
));
322+
}
323+
302324
return new Drawer(child: new ListView(primary: false, children: allDrawerItems));
303325
}
304326
}

‎examples/flutter_gallery/lib/gallery/home.dart‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,8 @@ class GalleryHome extends StatefulWidget {
7676
this.onShowPerformanceOverlayChanged,
7777
this.checkerboardRasterCacheImages,
7878
this.onCheckerboardRasterCacheImagesChanged,
79+
this.checkerboardOffscreenLayers,
80+
this.onCheckerboardOffscreenLayersChanged,
7981
this.onPlatformChanged,
8082
this.onSendFeedback,
8183
}) : super(key: key) {
@@ -95,6 +97,9 @@ class GalleryHome extends StatefulWidget {
9597
final bool checkerboardRasterCacheImages;
9698
final ValueChanged<bool> onCheckerboardRasterCacheImagesChanged;
9799

100+
final bool checkerboardOffscreenLayers;
101+
final ValueChanged<bool> onCheckerboardOffscreenLayersChanged;
102+
98103
final ValueChanged<TargetPlatform> onPlatformChanged;
99104

100105
final VoidCallback onSendFeedback;
@@ -161,6 +166,8 @@ class GalleryHomeState extends State<GalleryHome> with SingleTickerProviderState
161166
onShowPerformanceOverlayChanged: widget.onShowPerformanceOverlayChanged,
162167
checkerboardRasterCacheImages: widget.checkerboardRasterCacheImages,
163168
onCheckerboardRasterCacheImagesChanged: widget.onCheckerboardRasterCacheImagesChanged,
169+
checkerboardOffscreenLayers: widget.checkerboardOffscreenLayers,
170+
onCheckerboardOffscreenLayersChanged: widget.onCheckerboardOffscreenLayersChanged,
164171
onPlatformChanged: widget.onPlatformChanged,
165172
onSendFeedback: widget.onSendFeedback,
166173
),

‎packages/flutter/lib/src/material/app.dart‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ class MaterialApp extends StatefulWidget {
6060
this.debugShowMaterialGrid: false,
6161
this.showPerformanceOverlay: false,
6262
this.checkerboardRasterCacheImages: false,
63+
this.checkerboardOffscreenLayers: false,
6364
this.showSemanticsDebugger: false,
6465
this.debugShowCheckedModeBanner: true
6566
}) : super(key: key) {
@@ -135,6 +136,9 @@ class MaterialApp extends StatefulWidget {
135136
/// Turns on checkerboarding of raster cache images.
136137
final bool checkerboardRasterCacheImages;
137138

139+
/// Turns on checkerboarding of layers rendered to offscreen bitmaps.
140+
final bool checkerboardOffscreenLayers;
141+
138142
/// Turns on an overlay that shows the accessibility information
139143
/// reported by the framework.
140144
final bool showSemanticsDebugger;
@@ -240,6 +244,7 @@ class _MaterialAppState extends State<MaterialApp> {
240244
onLocaleChanged: widget.onLocaleChanged,
241245
showPerformanceOverlay: widget.showPerformanceOverlay,
242246
checkerboardRasterCacheImages: widget.checkerboardRasterCacheImages,
247+
checkerboardOffscreenLayers: widget.checkerboardOffscreenLayers,
243248
showSemanticsDebugger: widget.showSemanticsDebugger,
244249
debugShowCheckedModeBanner: widget.debugShowCheckedModeBanner
245250
)

‎packages/flutter/lib/src/rendering/layer.dart‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ class PerformanceOverlayLayer extends Layer {
163163
@required this.optionsMask,
164164
@required this.rasterizerThreshold,
165165
@required this.checkerboardRasterCacheImages,
166+
@required this.checkerboardOffscreenLayers,
166167
});
167168

168169
/// The rectangle in this layer's coordinate system that the overlay should occupy.
@@ -193,12 +194,23 @@ class PerformanceOverlayLayer extends Layer {
193194
/// that aid it in making better decisions about caching.
194195
final bool checkerboardRasterCacheImages;
195196

197+
/// Whether the compositor should checkerboard layers that are rendered to offscreen
198+
/// bitmaps. This can be useful for debugging rendering performance.
199+
///
200+
/// Render target switches are caused by using opacity layers (via a [FadeTransition] or
201+
/// [Opacity] widget), clips, shader mask layers, etc. Selecting a new render target
202+
/// and merging it with the rest of the scene has a performance cost. This can sometimes
203+
/// be avoided by using equivalent widgets that do not require these layers (for example,
204+
/// replacing an [Opacity] widget with an [widgets.Image] using a [BlendMode]).
205+
final bool checkerboardOffscreenLayers;
206+
196207
@override
197208
void addToScene(ui.SceneBuilder builder, Offset layerOffset) {
198209
assert(optionsMask != null);
199210
builder.addPerformanceOverlay(optionsMask, overlayRect.shift(layerOffset));
200211
builder.setRasterizerTracingThreshold(rasterizerThreshold);
201212
builder.setCheckerboardRasterCacheImages(checkerboardRasterCacheImages);
213+
builder.setCheckerboardOffscreenLayers(checkerboardOffscreenLayers);
202214
}
203215
}
204216

‎packages/flutter/lib/src/rendering/performance_overlay.dart‎

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,18 +59,21 @@ enum PerformanceOverlayOption {
5959
class RenderPerformanceOverlay extends RenderBox {
6060
/// Creates a performance overlay render object.
6161
///
62-
/// The [optionsMask], [rasterizerThreshold] and [checkerboardRasterCacheImages]
63-
/// arguments must not be null.
62+
/// The [optionsMask], [rasterizerThreshold], [checkerboardRasterCacheImages],
63+
/// and [checkerboardOffscreenLayers] arguments must not be null.
6464
RenderPerformanceOverlay({
6565
int optionsMask: 0,
6666
int rasterizerThreshold: 0,
6767
bool checkerboardRasterCacheImages: false,
68+
bool checkerboardOffscreenLayers: false,
6869
}) : _optionsMask = optionsMask,
6970
_rasterizerThreshold = rasterizerThreshold,
70-
_checkerboardRasterCacheImages = checkerboardRasterCacheImages {
71+
_checkerboardRasterCacheImages = checkerboardRasterCacheImages,
72+
_checkerboardOffscreenLayers = checkerboardOffscreenLayers {
7173
assert(optionsMask != null);
7274
assert(rasterizerThreshold != null);
7375
assert(checkerboardRasterCacheImages != null);
76+
assert(checkerboardOffscreenLayers != null);
7477
}
7578

7679
/// The mask is created by shifting 1 by the index of the specific
@@ -109,6 +112,17 @@ class RenderPerformanceOverlay extends RenderBox {
109112
markNeedsPaint();
110113
}
111114

115+
/// Whether the compositor should checkerboard layers rendered to offscreen bitmaps.
116+
bool get checkerboardOffscreenLayers => _checkerboardOffscreenLayers;
117+
bool _checkerboardOffscreenLayers;
118+
set checkerboardOffscreenLayers(bool value) {
119+
assert(value != null);
120+
if (value == _checkerboardOffscreenLayers)
121+
return;
122+
_checkerboardOffscreenLayers = value;
123+
markNeedsPaint();
124+
}
125+
112126
@override
113127
bool get sizedByParent => true;
114128

@@ -160,6 +174,7 @@ class RenderPerformanceOverlay extends RenderBox {
160174
optionsMask: optionsMask,
161175
rasterizerThreshold: rasterizerThreshold,
162176
checkerboardRasterCacheImages: checkerboardRasterCacheImages,
177+
checkerboardOffscreenLayers: checkerboardOffscreenLayers,
163178
));
164179
}
165180
}

‎packages/flutter/lib/src/widgets/app.dart‎

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,14 @@ class WidgetsApp extends StatefulWidget {
4949
this.onLocaleChanged,
5050
this.showPerformanceOverlay: false,
5151
this.checkerboardRasterCacheImages: false,
52+
this.checkerboardOffscreenLayers: false,
5253
this.showSemanticsDebugger: false,
5354
this.debugShowCheckedModeBanner: true
5455
}) : assert(color != null),
5556
assert(onGenerateRoute != null),
5657
assert(showPerformanceOverlay != null),
5758
assert(checkerboardRasterCacheImages != null),
59+
assert(checkerboardOffscreenLayers != null),
5860
assert(showSemanticsDebugger != null),
5961
super(key: key);
6062

@@ -89,8 +91,15 @@ class WidgetsApp extends StatefulWidget {
8991
final bool showPerformanceOverlay;
9092

9193
/// Checkerboards raster cache images.
94+
///
95+
/// See [PerformanceOverlay.checkerboardRasterCacheImages].
9296
final bool checkerboardRasterCacheImages;
9397

98+
/// Checkerboards layers rendered to offscreen bitmaps.
99+
///
100+
/// See [PerformanceOverlay.checkerboardOffscreenLayers].
101+
final bool checkerboardOffscreenLayers;
102+
94103
/// Turns on an overlay that shows the accessibility information
95104
/// reported by the framework.
96105
final bool showSemanticsDebugger;
@@ -220,9 +229,14 @@ class _WidgetsAppState extends State<WidgetsApp> implements WidgetsBindingObserv
220229
// options are set.
221230
if (widget.showPerformanceOverlay || WidgetsApp.showPerformanceOverlayOverride) {
222231
performanceOverlay = new PerformanceOverlay.allEnabled(
223-
checkerboardRasterCacheImages: widget.checkerboardRasterCacheImages);
224-
} else if (widget.checkerboardRasterCacheImages) {
225-
performanceOverlay = const PerformanceOverlay(checkerboardRasterCacheImages: true);
232+
checkerboardRasterCacheImages: widget.checkerboardRasterCacheImages,
233+
checkerboardOffscreenLayers: widget.checkerboardOffscreenLayers,
234+
);
235+
} else if (widget.checkerboardRasterCacheImages || widget.checkerboardOffscreenLayers) {
236+
performanceOverlay = new PerformanceOverlay(
237+
checkerboardRasterCacheImages: widget.checkerboardRasterCacheImages,
238+
checkerboardOffscreenLayers: widget.checkerboardOffscreenLayers,
239+
);
226240
}
227241

228242
if (performanceOverlay != null) {

‎packages/flutter/lib/src/widgets/performance_overlay.dart‎

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,15 @@ class PerformanceOverlay extends LeafRenderObjectWidget {
3131
Key key,
3232
this.optionsMask: 0,
3333
this.rasterizerThreshold: 0,
34-
this.checkerboardRasterCacheImages: false
34+
this.checkerboardRasterCacheImages: false,
35+
this.checkerboardOffscreenLayers: false,
3536
}) : super(key: key);
3637

3738
/// Create a performance overlay that displays all available statistics
3839
PerformanceOverlay.allEnabled({ Key key,
3940
this.rasterizerThreshold: 0,
40-
this.checkerboardRasterCacheImages: false })
41+
this.checkerboardRasterCacheImages: false,
42+
this.checkerboardOffscreenLayers: false })
4143
: optionsMask = (
4244
1 << PerformanceOverlayOption.displayRasterizerStatistics.index |
4345
1 << PerformanceOverlayOption.visualizeRasterizerStatistics.index |
@@ -91,11 +93,22 @@ class PerformanceOverlay extends LeafRenderObjectWidget {
9193
/// that aid it in making better decisions about caching.
9294
final bool checkerboardRasterCacheImages;
9395

96+
/// Whether the compositor should checkerboard layers that are rendered to offscreen
97+
/// bitmaps. This can be useful for debugging rendering performance.
98+
///
99+
/// Render target switches are caused by using opacity layers (via a [FadeTransition] or
100+
/// [Opacity] widget), clips, shader mask layers, etc. Selecting a new render target
101+
/// and merging it with the rest of the scene has a performance cost. This can sometimes
102+
/// be avoided by using equivalent widgets that do not require these layers (for example,
103+
/// replacing an [Opacity] widget with an [widgets.Image] using a [BlendMode]).
104+
final bool checkerboardOffscreenLayers;
105+
94106
@override
95107
RenderPerformanceOverlay createRenderObject(BuildContext context) => new RenderPerformanceOverlay(
96108
optionsMask: optionsMask,
97109
rasterizerThreshold: rasterizerThreshold,
98-
checkerboardRasterCacheImages: checkerboardRasterCacheImages
110+
checkerboardRasterCacheImages: checkerboardRasterCacheImages,
111+
checkerboardOffscreenLayers: checkerboardOffscreenLayers,
99112
);
100113

101114
@override

0 commit comments

Comments
 (0)