Skip to content

Commit

Permalink
NNBD cleanup (#24529)
Browse files Browse the repository at this point in the history
  • Loading branch information
ferhatb committed Feb 20, 2021
1 parent 57c5777 commit ceafbef
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 23 deletions.
31 changes: 16 additions & 15 deletions lib/web_ui/lib/src/engine/html/picture.dart
Expand Up @@ -417,24 +417,26 @@ class PersistedPicture extends PersistedLeafSurface {

void _applyDomPaint(EngineCanvas? oldCanvas) {
_recycleCanvas(_canvas);
_canvas = DomCanvas(rootElement!);
final DomCanvas domCanvas = DomCanvas(rootElement!);
_canvas = domCanvas;
domRenderer.clearDom(rootElement!);
picture.recordingCanvas!.apply(_canvas!, _optimalLocalCullRect);
picture.recordingCanvas!.apply(domCanvas, _optimalLocalCullRect!);
}

void _applyBitmapPaint(EngineCanvas? oldCanvas) {
if (oldCanvas is BitmapCanvas &&
oldCanvas.doesFitBounds(_optimalLocalCullRect!, _density) &&
oldCanvas.isReusable()) {
final BitmapCanvas reusedCanvas = oldCanvas;
if (_debugShowCanvasReuseStats) {
DebugCanvasReuseOverlay.instance.keptCount++;
}
// Re-use old bitmap canvas.
oldCanvas.bounds = _optimalLocalCullRect!;
_canvas = oldCanvas;
oldCanvas.setElementCache(_elementCache);
_canvas!.clear();
picture.recordingCanvas!.apply(_canvas!, _optimalLocalCullRect);
reusedCanvas.bounds = _optimalLocalCullRect!;
_canvas = reusedCanvas;
reusedCanvas.setElementCache(_elementCache);
reusedCanvas.clear();
picture.recordingCanvas!.apply(reusedCanvas, _optimalLocalCullRect!);
} else {
// We can't use the old canvas because the size has changed, so we put
// it in a cache for later reuse.
Expand All @@ -450,19 +452,18 @@ class PersistedPicture extends PersistedLeafSurface {
_paintQueue.add(_PaintRequest(
canvasSize: _optimalLocalCullRect!.size,
paintCallback: () {
_canvas = _findOrCreateCanvas(_optimalLocalCullRect!);
if (_canvas is BitmapCanvas) {
(_canvas as BitmapCanvas).setElementCache(_elementCache);
}
final BitmapCanvas bitmapCanvas =
_findOrCreateCanvas(_optimalLocalCullRect!);
_canvas = bitmapCanvas;
bitmapCanvas.setElementCache(_elementCache);
if (_debugExplainSurfaceStats) {
final BitmapCanvas bitmapCanvas = _canvas as BitmapCanvas;
_surfaceStatsFor(this).paintPixelCount +=
bitmapCanvas.bitmapPixelCount;
}
domRenderer.clearDom(rootElement!);
rootElement!.append(_canvas!.rootElement);
_canvas!.clear();
picture.recordingCanvas!.apply(_canvas!, _optimalLocalCullRect);
rootElement!.append(bitmapCanvas.rootElement);
bitmapCanvas.clear();
picture.recordingCanvas!.apply(bitmapCanvas, _optimalLocalCullRect!);
},
));
}
Expand Down
16 changes: 8 additions & 8 deletions lib/web_ui/lib/src/engine/html/recording_canvas.dart
Expand Up @@ -126,14 +126,14 @@ class RecordingCanvas {
/// a minimum). The commands that fall outside the clip are skipped and are
/// not applied to the [engineCanvas]. A command must have a non-zero
/// intersection with the clip in order to be applied.
void apply(EngineCanvas engineCanvas, ui.Rect? clipRect) {
void apply(EngineCanvas engineCanvas, ui.Rect clipRect) {
assert(_recordingEnded);
if (_debugDumpPaintCommands) {
final StringBuffer debugBuf = StringBuffer();
int skips = 0;
debugBuf.writeln(
'--- Applying RecordingCanvas to ${engineCanvas.runtimeType} '
'with bounds $_paintBounds and clip $clipRect (w = ${clipRect!.width},'
'with bounds $_paintBounds and clip $clipRect (w = ${clipRect.width},'
' h = ${clipRect.height})');
for (int i = 0; i < _commands.length; i++) {
final PaintCommand command = _commands[i];
Expand All @@ -155,7 +155,7 @@ class RecordingCanvas {
print(debugBuf);
} else {
try {
if (rectContainsOther(clipRect!, _pictureBounds!)) {
if (rectContainsOther(clipRect, _pictureBounds!)) {
// No need to check if commands fit in the clip rect if we already
// know that the entire picture fits it.
for (int i = 0, len = _commands.length; i < len; i++) {
Expand Down Expand Up @@ -286,10 +286,10 @@ class RecordingCanvas {
_commands.add(command);
}

void clipRRect(ui.RRect rrect) {
void clipRRect(ui.RRect roundedRect) {
assert(!_recordingEnded);
final PaintClipRRect command = PaintClipRRect(rrect);
_paintBounds.clipRect(rrect.outerRect, command);
final PaintClipRRect command = PaintClipRRect(roundedRect);
_paintBounds.clipRect(roundedRect.outerRect, command);
renderStrategy.hasArbitraryPaint = true;
_commands.add(command);
}
Expand Down Expand Up @@ -654,14 +654,14 @@ abstract class DrawCommand extends PaintCommand {
double bottomBound = double.infinity;

/// Whether this command intersects with the [clipRect].
bool isInvisible(ui.Rect? clipRect) {
bool isInvisible(ui.Rect clipRect) {
if (isClippedOut) {
return true;
}

// Check top and bottom first because vertical scrolling is more common
// than horizontal scrolling.
return bottomBound < clipRect!.top ||
return bottomBound < clipRect.top ||
topBound > clipRect.bottom ||
rightBound < clipRect.left ||
leftBound > clipRect.right;
Expand Down

0 comments on commit ceafbef

Please sign in to comment.