Skip to content

Commit

Permalink
add test for clipped out picture
Browse files Browse the repository at this point in the history
  • Loading branch information
harryterkelsen committed Sep 25, 2024
1 parent d0cca5f commit 91d631d
Show file tree
Hide file tree
Showing 5 changed files with 221 additions and 209 deletions.
3 changes: 3 additions & 0 deletions lib/web_ui/lib/src/engine/canvaskit/embedded_views.dart
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,9 @@ class HtmlViewEmbedder {
_context.sceneElements.map<SceneElement>((SceneElement element) {
if (element is PictureSceneElement) {
final CkPicture scenePicture = element.pictureRecorder.endRecording();
if (scenePicture.cullRect.isEmpty) {
element.picture.isCulled = true;
}
element.scenePicture = scenePicture;
scenePictureToRawPicture[scenePicture] = element.picture;
return element;
Expand Down
61 changes: 34 additions & 27 deletions lib/web_ui/lib/src/engine/canvaskit/layer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ abstract class Layer implements ui.EngineLayer {
bool get needsPainting => !paintBounds.isEmpty;

/// Implement layer visitor.
void accept<T>(LayerVisitor<T> visitor, T childData);
void accept(LayerVisitor visitor);

// TODO(dnfield): Implement ui.EngineLayer.dispose for CanvasKit.
// https://github.com/flutter/flutter/issues/82878
Expand Down Expand Up @@ -54,8 +54,8 @@ abstract class ContainerLayer extends Layer {
/// to [LayerSceneBuilder] without requiring a [ContainerLayer].
class RootLayer extends ContainerLayer {
@override
void accept<T>(LayerVisitor<T> visitor, T childData) {
visitor.visitRoot(this, childData);
void accept(LayerVisitor visitor) {
visitor.visitRoot(this);
}
}

Expand All @@ -67,8 +67,8 @@ class BackdropFilterEngineLayer extends ContainerLayer
final ui.BlendMode blendMode;

@override
void accept<T>(LayerVisitor<T> visitor, T childData) {
visitor.visitBackdropFilter(this, childData);
void accept(LayerVisitor visitor) {
visitor.visitBackdropFilter(this);
}

// TODO(dnfield): dispose of the _filter
Expand All @@ -86,8 +86,8 @@ class ClipPathEngineLayer extends ContainerLayer
final ui.Clip clipBehavior;

@override
void accept<T>(LayerVisitor<T> visitor, T childData) {
visitor.visitClipPath(this, childData);
void accept(LayerVisitor visitor) {
visitor.visitClipPath(this);
}
}

Expand All @@ -102,8 +102,8 @@ class ClipRectEngineLayer extends ContainerLayer
final ui.Clip clipBehavior;

@override
void accept<T>(LayerVisitor<T> visitor, T childData) {
visitor.visitClipRect(this, childData);
void accept(LayerVisitor visitor) {
visitor.visitClipRect(this);
}
}

Expand All @@ -118,8 +118,8 @@ class ClipRRectEngineLayer extends ContainerLayer
final ui.Clip? clipBehavior;

@override
void accept<T>(LayerVisitor<T> visitor, T childData) {
visitor.visitClipRRect(this, childData);
void accept(LayerVisitor visitor) {
visitor.visitClipRRect(this);
}
}

Expand All @@ -132,8 +132,8 @@ class OpacityEngineLayer extends ContainerLayer
final ui.Offset offset;

@override
void accept<T>(LayerVisitor<T> visitor, T childData) {
visitor.visitOpacity(this, childData);
void accept(LayerVisitor visitor) {
visitor.visitOpacity(this);
}
}

Expand All @@ -146,8 +146,8 @@ class TransformEngineLayer extends ContainerLayer
final Matrix4 transform;

@override
void accept<T>(LayerVisitor<T> visitor, T childData) {
visitor.visitTransform(this, childData);
void accept(LayerVisitor visitor) {
visitor.visitTransform(this);
}
}

Expand All @@ -162,8 +162,8 @@ class OffsetEngineLayer extends TransformEngineLayer
: super(Matrix4.translationValues(dx, dy, 0.0));

@override
void accept<T>(LayerVisitor<T> visitor, T childData) {
visitor.visitOffset(this, childData);
void accept(LayerVisitor visitor) {
visitor.visitOffset(this);
}
}

Expand All @@ -176,8 +176,8 @@ class ImageFilterEngineLayer extends ContainerLayer
final ui.ImageFilter filter;

@override
void accept<T>(LayerVisitor<T> visitor, T childData) {
visitor.visitImageFilter(this, childData);
void accept(LayerVisitor visitor) {
visitor.visitImageFilter(this);
}

// TODO(dnfield): dispose of the _filter
Expand All @@ -195,8 +195,8 @@ class ShaderMaskEngineLayer extends ContainerLayer
final ui.FilterQuality filterQuality;

@override
void accept<T>(LayerVisitor<T> visitor, T childData) {
visitor.visitShaderMask(this, childData);
void accept(LayerVisitor visitor) {
visitor.visitShaderMask(this);
}
}

Expand All @@ -216,10 +216,17 @@ class PictureLayer extends Layer {
/// A hint to the compositor that this picture is likely to change.
final bool willChange;

/// Whether or not this picture is culled in the final scene. We compute this
/// when we optimize the scene.
bool isCulled = false;

@override
void accept<T>(LayerVisitor<T> visitor, T childData) {
visitor.visitPicture(this, childData);
void accept(LayerVisitor visitor) {
visitor.visitPicture(this);
}

@override
bool get needsPainting => super.needsPainting && !isCulled;
}

/// A layer which contains a [ui.ColorFilter].
Expand All @@ -230,8 +237,8 @@ class ColorFilterEngineLayer extends ContainerLayer
final ui.ColorFilter filter;

@override
void accept<T>(LayerVisitor<T> visitor, T childData) {
visitor.visitColorFilter(this, childData);
void accept(LayerVisitor visitor) {
visitor.visitColorFilter(this);
}
}

Expand All @@ -245,7 +252,7 @@ class PlatformViewLayer extends Layer {
final double height;

@override
void accept<T>(LayerVisitor<T> visitor, T childData) {
visitor.visitPlatformView(this, childData);
void accept(LayerVisitor visitor) {
visitor.visitPlatformView(this);
}
}
11 changes: 5 additions & 6 deletions lib/web_ui/lib/src/engine/canvaskit/layer_tree.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import 'package:ui/ui.dart' as ui;

import '../../engine.dart' show kProfileApplyFrame, kProfilePrerollFrame;
import '../profiler.dart';
import '../vector_math.dart';
import 'canvas.dart';
import 'embedded_views.dart';
import 'layer.dart';
Expand All @@ -33,7 +32,7 @@ class LayerTree {
/// attempt to register pictures to cache.
void preroll(Frame frame, {bool ignoreRasterCache = false}) {
final PrerollVisitor prerollVisitor = PrerollVisitor(frame.viewEmbedder);
rootLayer.accept(prerollVisitor, Matrix4.identity());
rootLayer.accept(prerollVisitor);
}

/// Performs a paint pass with a recording canvas for each picture in the
Expand All @@ -49,7 +48,7 @@ class LayerTree {
frame.viewEmbedder!,
);
if (rootLayer.needsPainting) {
rootLayer.accept(measureVisitor, null);
rootLayer.accept(measureVisitor);
}
}

Expand All @@ -67,7 +66,7 @@ class LayerTree {
frame.viewEmbedder!,
);
if (rootLayer.needsPainting) {
rootLayer.accept(paintVisitor, null);
rootLayer.accept(paintVisitor);
}
}

Expand All @@ -78,14 +77,14 @@ class LayerTree {
final CkPictureRecorder recorder = CkPictureRecorder();
final CkCanvas canvas = recorder.beginRecording(ui.Offset.zero & size);
final PrerollVisitor prerollVisitor = PrerollVisitor(null);
rootLayer.accept(prerollVisitor, Matrix4.identity());
rootLayer.accept(prerollVisitor);

final CkNWayCanvas internalNodesCanvas = CkNWayCanvas();
internalNodesCanvas.addCanvas(canvas);
final PaintVisitor paintVisitor =
PaintVisitor.forToImage(internalNodesCanvas, canvas);
if (rootLayer.needsPainting) {
rootLayer.accept(paintVisitor, null);
rootLayer.accept(paintVisitor);
}
return recorder.endRecording();
}
Expand Down
Loading

0 comments on commit 91d631d

Please sign in to comment.