forked from firka/flutter
Cliprect op (flutter/engine#20837)
* Switched PathCommand apply parameter to non-nullable. Add clip op parameter to ClipCommand.
This commit is contained in:
@@ -96,7 +96,7 @@ class SurfaceCanvas implements ui.Canvas {
|
||||
}
|
||||
|
||||
void _clipRect(ui.Rect rect, ui.ClipOp clipOp, bool doAntiAlias) {
|
||||
_canvas.clipRect(rect);
|
||||
_canvas.clipRect(rect, clipOp);
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -212,8 +212,8 @@ class SurfaceCanvas implements ui.Canvas {
|
||||
}
|
||||
|
||||
@override
|
||||
void drawArc(ui.Rect rect, double startAngle, double sweepAngle, bool useCenter,
|
||||
ui.Paint paint) {
|
||||
void drawArc(ui.Rect rect, double startAngle, double sweepAngle,
|
||||
bool useCenter, ui.Paint paint) {
|
||||
assert(rectIsValid(rect));
|
||||
assert(paint != null); // ignore: unnecessary_null_comparison
|
||||
const double pi = math.pi;
|
||||
@@ -283,12 +283,14 @@ class SurfaceCanvas implements ui.Canvas {
|
||||
_drawImageRect(image, src, dst, paint);
|
||||
}
|
||||
|
||||
void _drawImageRect(ui.Image image, ui.Rect src, ui.Rect dst, ui.Paint paint) {
|
||||
void _drawImageRect(
|
||||
ui.Image image, ui.Rect src, ui.Rect dst, ui.Paint paint) {
|
||||
_canvas.drawImageRect(image, src, dst, paint as SurfacePaint);
|
||||
}
|
||||
|
||||
@override
|
||||
void drawImageNine(ui.Image image, ui.Rect center, ui.Rect dst, ui.Paint paint) {
|
||||
void drawImageNine(
|
||||
ui.Image image, ui.Rect center, ui.Rect dst, ui.Paint paint) {
|
||||
// ignore: unnecessary_null_comparison
|
||||
assert(image != null); // image is checked on the engine side
|
||||
assert(rectIsValid(center));
|
||||
@@ -458,16 +460,18 @@ class SurfaceCanvas implements ui.Canvas {
|
||||
}
|
||||
|
||||
@override
|
||||
void drawPoints(ui.PointMode pointMode, List<ui.Offset> points, ui.Paint paint) {
|
||||
void drawPoints(
|
||||
ui.PointMode pointMode, List<ui.Offset> points, ui.Paint paint) {
|
||||
assert(pointMode != null); // ignore: unnecessary_null_comparison
|
||||
assert(points != null); // ignore: unnecessary_null_comparison
|
||||
assert(paint != null); // ignore: unnecessary_null_comparison
|
||||
final Float32List pointList = offsetListToFloat32List(points);
|
||||
final Float32List pointList = offsetListToFloat32List(points);
|
||||
drawRawPoints(pointMode, pointList, paint);
|
||||
}
|
||||
|
||||
@override
|
||||
void drawRawPoints(ui.PointMode pointMode, Float32List points, ui.Paint paint) {
|
||||
void drawRawPoints(
|
||||
ui.PointMode pointMode, Float32List points, ui.Paint paint) {
|
||||
assert(pointMode != null); // ignore: unnecessary_null_comparison
|
||||
assert(points != null); // ignore: unnecessary_null_comparison
|
||||
assert(paint != null); // ignore: unnecessary_null_comparison
|
||||
@@ -478,11 +482,13 @@ class SurfaceCanvas implements ui.Canvas {
|
||||
}
|
||||
|
||||
@override
|
||||
void drawVertices(ui.Vertices vertices, ui.BlendMode blendMode, ui.Paint paint) {
|
||||
void drawVertices(
|
||||
ui.Vertices vertices, ui.BlendMode blendMode, ui.Paint paint) {
|
||||
//assert(vertices != null); // vertices is checked on the engine side
|
||||
assert(paint != null); // ignore: unnecessary_null_comparison
|
||||
assert(blendMode != null); // ignore: unnecessary_null_comparison
|
||||
_canvas.drawVertices(vertices as SurfaceVertices, blendMode, paint as SurfacePaint);
|
||||
_canvas.drawVertices(
|
||||
vertices as SurfaceVertices, blendMode, paint as SurfacePaint);
|
||||
}
|
||||
|
||||
@override
|
||||
|
||||
@@ -171,7 +171,8 @@ class PersistedPicture extends PersistedLeafSurface {
|
||||
if (parent!._projectedClip == null) {
|
||||
_exactLocalCullRect = localPaintBounds;
|
||||
} else {
|
||||
_exactLocalCullRect = localPaintBounds!.intersect(parent!._projectedClip!);
|
||||
_exactLocalCullRect =
|
||||
localPaintBounds!.intersect(parent!._projectedClip!);
|
||||
}
|
||||
if (_exactLocalCullRect!.width <= 0 || _exactLocalCullRect!.height <= 0) {
|
||||
_exactLocalCullRect = ui.Rect.zero;
|
||||
@@ -229,17 +230,25 @@ class PersistedPicture extends PersistedLeafSurface {
|
||||
|
||||
// Compute the delta, by which each of the side of the clip rect has "moved"
|
||||
// since the last time we updated the cull rect.
|
||||
final double leftwardDelta = oldOptimalLocalCullRect.left - _exactLocalCullRect!.left;
|
||||
final double upwardDelta = oldOptimalLocalCullRect.top - _exactLocalCullRect!.top;
|
||||
final double rightwardDelta = _exactLocalCullRect!.right - oldOptimalLocalCullRect.right;
|
||||
final double bottomwardDelta = _exactLocalCullRect!.bottom - oldOptimalLocalCullRect.bottom;
|
||||
final double leftwardDelta =
|
||||
oldOptimalLocalCullRect.left - _exactLocalCullRect!.left;
|
||||
final double upwardDelta =
|
||||
oldOptimalLocalCullRect.top - _exactLocalCullRect!.top;
|
||||
final double rightwardDelta =
|
||||
_exactLocalCullRect!.right - oldOptimalLocalCullRect.right;
|
||||
final double bottomwardDelta =
|
||||
_exactLocalCullRect!.bottom - oldOptimalLocalCullRect.bottom;
|
||||
|
||||
// Compute the new optimal rect to paint into.
|
||||
final ui.Rect newLocalCullRect = ui.Rect.fromLTRB(
|
||||
_exactLocalCullRect!.left - _predictTrend(leftwardDelta, _exactLocalCullRect!.width),
|
||||
_exactLocalCullRect!.top - _predictTrend(upwardDelta, _exactLocalCullRect!.height),
|
||||
_exactLocalCullRect!.right + _predictTrend(rightwardDelta, _exactLocalCullRect!.width),
|
||||
_exactLocalCullRect!.bottom + _predictTrend(bottomwardDelta, _exactLocalCullRect!.height),
|
||||
_exactLocalCullRect!.left -
|
||||
_predictTrend(leftwardDelta, _exactLocalCullRect!.width),
|
||||
_exactLocalCullRect!.top -
|
||||
_predictTrend(upwardDelta, _exactLocalCullRect!.height),
|
||||
_exactLocalCullRect!.right +
|
||||
_predictTrend(rightwardDelta, _exactLocalCullRect!.width),
|
||||
_exactLocalCullRect!.bottom +
|
||||
_predictTrend(bottomwardDelta, _exactLocalCullRect!.height),
|
||||
).intersect(localPaintBounds!);
|
||||
|
||||
final bool localCullRectChanged = _optimalLocalCullRect != newLocalCullRect;
|
||||
@@ -333,8 +342,9 @@ class PersistedPicture extends PersistedLeafSurface {
|
||||
// The canvas needs to be resized before painting.
|
||||
return 1.0;
|
||||
} else {
|
||||
final int newPixelCount = BitmapCanvas._widthToPhysical(_exactLocalCullRect!.width)
|
||||
* BitmapCanvas._heightToPhysical(_exactLocalCullRect!.height);
|
||||
final int newPixelCount =
|
||||
BitmapCanvas._widthToPhysical(_exactLocalCullRect!.width) *
|
||||
BitmapCanvas._heightToPhysical(_exactLocalCullRect!.height);
|
||||
final int oldPixelCount =
|
||||
oldCanvas._widthInBitmapPixels * oldCanvas._heightInBitmapPixels;
|
||||
|
||||
@@ -366,7 +376,7 @@ class PersistedPicture extends PersistedLeafSurface {
|
||||
_canvas = DomCanvas();
|
||||
domRenderer.clearDom(rootElement!);
|
||||
rootElement!.append(_canvas!.rootElement);
|
||||
picture.recordingCanvas!.apply(_canvas, _optimalLocalCullRect);
|
||||
picture.recordingCanvas!.apply(_canvas!, _optimalLocalCullRect);
|
||||
}
|
||||
|
||||
void _applyBitmapPaint(EngineCanvas? oldCanvas) {
|
||||
@@ -380,7 +390,7 @@ class PersistedPicture extends PersistedLeafSurface {
|
||||
_canvas = oldCanvas;
|
||||
oldCanvas.setElementCache(_elementCache);
|
||||
_canvas!.clear();
|
||||
picture.recordingCanvas!.apply(_canvas, _optimalLocalCullRect);
|
||||
picture.recordingCanvas!.apply(_canvas!, _optimalLocalCullRect);
|
||||
} else {
|
||||
// We can't use the old canvas because the size has changed, so we put
|
||||
// it in a cache for later reuse.
|
||||
@@ -393,8 +403,8 @@ class PersistedPicture extends PersistedLeafSurface {
|
||||
canvasSize: _optimalLocalCullRect!.size,
|
||||
paintCallback: () {
|
||||
_canvas = _findOrCreateCanvas(_optimalLocalCullRect!);
|
||||
assert(_canvas is BitmapCanvas
|
||||
&& (_canvas as BitmapCanvas?)!._elementCache == _elementCache);
|
||||
assert(_canvas is BitmapCanvas &&
|
||||
(_canvas as BitmapCanvas?)!._elementCache == _elementCache);
|
||||
if (_debugExplainSurfaceStats) {
|
||||
final BitmapCanvas bitmapCanvas = _canvas as BitmapCanvas;
|
||||
_surfaceStatsFor(this).paintPixelCount +=
|
||||
@@ -403,7 +413,7 @@ class PersistedPicture extends PersistedLeafSurface {
|
||||
domRenderer.clearDom(rootElement!);
|
||||
rootElement!.append(_canvas!.rootElement);
|
||||
_canvas!.clear();
|
||||
picture.recordingCanvas!.apply(_canvas, _optimalLocalCullRect);
|
||||
picture.recordingCanvas!.apply(_canvas!, _optimalLocalCullRect);
|
||||
},
|
||||
));
|
||||
}
|
||||
|
||||
@@ -19,8 +19,7 @@ double _measureBorderRadius(double x, double y) {
|
||||
return clampedX * clampedX + clampedY * clampedY;
|
||||
}
|
||||
|
||||
class RawRecordingCanvas extends BitmapCanvas
|
||||
implements ui.PictureRecorder {
|
||||
class RawRecordingCanvas extends BitmapCanvas implements ui.PictureRecorder {
|
||||
RawRecordingCanvas(ui.Size size) : super(ui.Offset.zero & size);
|
||||
|
||||
@override
|
||||
@@ -28,8 +27,7 @@ class RawRecordingCanvas extends BitmapCanvas
|
||||
clear();
|
||||
}
|
||||
|
||||
RecordingCanvas beginRecording(ui.Rect bounds) =>
|
||||
throw UnsupportedError('');
|
||||
RecordingCanvas beginRecording(ui.Rect bounds) => throw UnsupportedError('');
|
||||
|
||||
@override
|
||||
ui.Picture endRecording() => throw UnsupportedError('');
|
||||
@@ -63,6 +61,7 @@ class RecordingCanvas {
|
||||
);
|
||||
return _pictureBounds;
|
||||
}
|
||||
|
||||
ui.Rect? _pictureBounds;
|
||||
|
||||
final List<PaintCommand> _commands = <PaintCommand>[];
|
||||
@@ -75,7 +74,8 @@ class RecordingCanvas {
|
||||
throw UnsupportedError('For debugging only.');
|
||||
}
|
||||
|
||||
RecordingCanvas(ui.Rect? bounds) : _paintBounds = _PaintBounds(bounds ?? ui.Rect.largest);
|
||||
RecordingCanvas(ui.Rect? bounds)
|
||||
: _paintBounds = _PaintBounds(bounds ?? ui.Rect.largest);
|
||||
|
||||
/// Whether this canvas is doing arbitrary paint operations not expressible
|
||||
/// via DOM elements.
|
||||
@@ -128,13 +128,13 @@ 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} '
|
||||
'--- Applying RecordingCanvas to ${engineCanvas.runtimeType} '
|
||||
'with bounds $_paintBounds and clip $clipRect (w = ${clipRect!.width},'
|
||||
' h = ${clipRect.height})');
|
||||
for (int i = 0; i < _commands.length; i++) {
|
||||
@@ -185,7 +185,7 @@ class RecordingCanvas {
|
||||
}
|
||||
}
|
||||
}
|
||||
engineCanvas!.endOfPaint();
|
||||
engineCanvas.endOfPaint();
|
||||
}
|
||||
|
||||
/// Prints recorded commands.
|
||||
@@ -273,10 +273,17 @@ class RecordingCanvas {
|
||||
_commands.add(PaintSkew(sx, sy));
|
||||
}
|
||||
|
||||
void clipRect(ui.Rect rect) {
|
||||
void clipRect(ui.Rect rect, ui.ClipOp clipOp) {
|
||||
assert(!_recordingEnded);
|
||||
final PaintClipRect command = PaintClipRect(rect);
|
||||
_paintBounds.clipRect(rect, command);
|
||||
final PaintClipRect command = PaintClipRect(rect, clipOp);
|
||||
switch (clipOp) {
|
||||
case ui.ClipOp.intersect:
|
||||
_paintBounds.clipRect(rect, command);
|
||||
break;
|
||||
case ui.ClipOp.difference:
|
||||
// Since this refers to inverse, can't shrink paintBounds.
|
||||
break;
|
||||
}
|
||||
_hasArbitraryPaint = true;
|
||||
_commands.add(command);
|
||||
}
|
||||
@@ -410,7 +417,8 @@ class RecordingCanvas {
|
||||
_hasArbitraryPaint = true;
|
||||
_didDraw = true;
|
||||
final double paintSpread = _getPaintSpread(paint);
|
||||
final PaintDrawDRRect command = PaintDrawDRRect(outer, inner, paint.paintData);
|
||||
final PaintDrawDRRect command =
|
||||
PaintDrawDRRect(outer, inner, paint.paintData);
|
||||
_paintBounds.growLTRB(
|
||||
outer.left - paintSpread,
|
||||
outer.top - paintSpread,
|
||||
@@ -480,7 +488,8 @@ class RecordingCanvas {
|
||||
}
|
||||
// Clone path so it can be reused for subsequent draw calls.
|
||||
final ui.Path clone = SurfacePath._shallowCopy(path);
|
||||
final PaintDrawPath command = PaintDrawPath(clone as SurfacePath, paint.paintData);
|
||||
final PaintDrawPath command =
|
||||
PaintDrawPath(clone as SurfacePath, paint.paintData);
|
||||
_paintBounds.grow(pathBounds, command);
|
||||
clone.fillType = sPath.fillType;
|
||||
_commands.add(command);
|
||||
@@ -494,7 +503,8 @@ class RecordingCanvas {
|
||||
final double left = offset.dx;
|
||||
final double top = offset.dy;
|
||||
final command = PaintDrawImage(image, offset, paint.paintData);
|
||||
_paintBounds.growLTRB(left, top, left + image.width, top + image.height, command);
|
||||
_paintBounds.growLTRB(
|
||||
left, top, left + image.width, top + image.height, command);
|
||||
_commands.add(command);
|
||||
}
|
||||
|
||||
@@ -503,7 +513,8 @@ class RecordingCanvas {
|
||||
assert(!_recordingEnded);
|
||||
_hasArbitraryPaint = true;
|
||||
_didDraw = true;
|
||||
final PaintDrawImageRect command = PaintDrawImageRect(image, src, dst, paint.paintData);
|
||||
final PaintDrawImageRect command =
|
||||
PaintDrawImageRect(image, src, dst, paint.paintData);
|
||||
_paintBounds.grow(dst, command);
|
||||
_commands.add(command);
|
||||
}
|
||||
@@ -522,7 +533,8 @@ class RecordingCanvas {
|
||||
}
|
||||
final double left = offset.dx;
|
||||
final double top = offset.dy;
|
||||
final PaintDrawParagraph command = PaintDrawParagraph(engineParagraph, offset);
|
||||
final PaintDrawParagraph command =
|
||||
PaintDrawParagraph(engineParagraph, offset);
|
||||
_paintBounds.growLTRB(
|
||||
left,
|
||||
top,
|
||||
@@ -540,7 +552,8 @@ class RecordingCanvas {
|
||||
_didDraw = true;
|
||||
final ui.Rect shadowRect =
|
||||
computePenumbraBounds(path.getBounds(), elevation);
|
||||
final PaintDrawShadow command = PaintDrawShadow(path as SurfacePath, color, elevation, transparentOccluder);
|
||||
final PaintDrawShadow command = PaintDrawShadow(
|
||||
path as SurfacePath, color, elevation, transparentOccluder);
|
||||
_paintBounds.grow(shadowRect, command);
|
||||
_commands.add(command);
|
||||
}
|
||||
@@ -550,7 +563,8 @@ class RecordingCanvas {
|
||||
assert(!_recordingEnded);
|
||||
_hasArbitraryPaint = true;
|
||||
_didDraw = true;
|
||||
final PaintDrawVertices command = PaintDrawVertices(vertices, blendMode, paint.paintData);
|
||||
final PaintDrawVertices command =
|
||||
PaintDrawVertices(vertices, blendMode, paint.paintData);
|
||||
_growPaintBoundsByPoints(vertices._positions, 0, paint, command);
|
||||
_commands.add(command);
|
||||
}
|
||||
@@ -560,12 +574,14 @@ class RecordingCanvas {
|
||||
assert(!_recordingEnded);
|
||||
_hasArbitraryPaint = true;
|
||||
_didDraw = true;
|
||||
final PaintDrawPoints command = PaintDrawPoints(pointMode, points, paint.paintData);
|
||||
final PaintDrawPoints command =
|
||||
PaintDrawPoints(pointMode, points, paint.paintData);
|
||||
_growPaintBoundsByPoints(points, paint.strokeWidth, paint, command);
|
||||
_commands.add(command);
|
||||
}
|
||||
|
||||
void _growPaintBoundsByPoints(Float32List points, double thickness, SurfacePaint paint, DrawCommand command) {
|
||||
void _growPaintBoundsByPoints(Float32List points, double thickness,
|
||||
SurfacePaint paint, DrawCommand command) {
|
||||
double minValueX, maxValueX, minValueY, maxValueY;
|
||||
minValueX = maxValueX = points[0];
|
||||
minValueY = maxValueY = points[1];
|
||||
@@ -607,7 +623,7 @@ class RecordingCanvas {
|
||||
abstract class PaintCommand {
|
||||
const PaintCommand();
|
||||
|
||||
void apply(EngineCanvas? canvas);
|
||||
void apply(EngineCanvas canvas);
|
||||
}
|
||||
|
||||
/// A [PaintCommand] that affect pixels on the screen (unlike, for example, the
|
||||
@@ -641,9 +657,9 @@ abstract class DrawCommand extends PaintCommand {
|
||||
// Check top and bottom first because vertical scrolling is more common
|
||||
// than horizontal scrolling.
|
||||
return bottomBound < clipRect!.top ||
|
||||
topBound > clipRect.bottom ||
|
||||
rightBound < clipRect.left ||
|
||||
leftBound > clipRect.right;
|
||||
topBound > clipRect.bottom ||
|
||||
rightBound < clipRect.left ||
|
||||
leftBound > clipRect.right;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -651,8 +667,8 @@ class PaintSave extends PaintCommand {
|
||||
const PaintSave();
|
||||
|
||||
@override
|
||||
void apply(EngineCanvas? canvas) {
|
||||
canvas!.save();
|
||||
void apply(EngineCanvas canvas) {
|
||||
canvas.save();
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -669,8 +685,8 @@ class PaintRestore extends PaintCommand {
|
||||
const PaintRestore();
|
||||
|
||||
@override
|
||||
void apply(EngineCanvas? canvas) {
|
||||
canvas!.restore();
|
||||
void apply(EngineCanvas canvas) {
|
||||
canvas.restore();
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -690,8 +706,8 @@ class PaintTranslate extends PaintCommand {
|
||||
PaintTranslate(this.dx, this.dy);
|
||||
|
||||
@override
|
||||
void apply(EngineCanvas? canvas) {
|
||||
canvas!.translate(dx, dy);
|
||||
void apply(EngineCanvas canvas) {
|
||||
canvas.translate(dx, dy);
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -711,8 +727,8 @@ class PaintScale extends PaintCommand {
|
||||
PaintScale(this.sx, this.sy);
|
||||
|
||||
@override
|
||||
void apply(EngineCanvas? canvas) {
|
||||
canvas!.scale(sx, sy);
|
||||
void apply(EngineCanvas canvas) {
|
||||
canvas.scale(sx, sy);
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -731,8 +747,8 @@ class PaintRotate extends PaintCommand {
|
||||
PaintRotate(this.radians);
|
||||
|
||||
@override
|
||||
void apply(EngineCanvas? canvas) {
|
||||
canvas!.rotate(radians);
|
||||
void apply(EngineCanvas canvas) {
|
||||
canvas.rotate(radians);
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -751,8 +767,8 @@ class PaintTransform extends PaintCommand {
|
||||
PaintTransform(this.matrix4);
|
||||
|
||||
@override
|
||||
void apply(EngineCanvas? canvas) {
|
||||
canvas!.transform(matrix4);
|
||||
void apply(EngineCanvas canvas) {
|
||||
canvas.transform(matrix4);
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -772,8 +788,8 @@ class PaintSkew extends PaintCommand {
|
||||
PaintSkew(this.sx, this.sy);
|
||||
|
||||
@override
|
||||
void apply(EngineCanvas? canvas) {
|
||||
canvas!.skew(sx, sy);
|
||||
void apply(EngineCanvas canvas) {
|
||||
canvas.skew(sx, sy);
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -788,12 +804,13 @@ class PaintSkew extends PaintCommand {
|
||||
|
||||
class PaintClipRect extends DrawCommand {
|
||||
final ui.Rect rect;
|
||||
final ui.ClipOp clipOp;
|
||||
|
||||
PaintClipRect(this.rect);
|
||||
PaintClipRect(this.rect, this.clipOp);
|
||||
|
||||
@override
|
||||
void apply(EngineCanvas? canvas) {
|
||||
canvas!.clipRect(rect);
|
||||
void apply(EngineCanvas canvas) {
|
||||
canvas.clipRect(rect);
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -812,8 +829,8 @@ class PaintClipRRect extends DrawCommand {
|
||||
PaintClipRRect(this.rrect);
|
||||
|
||||
@override
|
||||
void apply(EngineCanvas? canvas) {
|
||||
canvas!.clipRRect(rrect);
|
||||
void apply(EngineCanvas canvas) {
|
||||
canvas.clipRRect(rrect);
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -832,8 +849,8 @@ class PaintClipPath extends DrawCommand {
|
||||
PaintClipPath(this.path);
|
||||
|
||||
@override
|
||||
void apply(EngineCanvas? canvas) {
|
||||
canvas!.clipPath(path);
|
||||
void apply(EngineCanvas canvas) {
|
||||
canvas.clipPath(path);
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -853,8 +870,8 @@ class PaintDrawColor extends DrawCommand {
|
||||
PaintDrawColor(this.color, this.blendMode);
|
||||
|
||||
@override
|
||||
void apply(EngineCanvas? canvas) {
|
||||
canvas!.drawColor(color, blendMode);
|
||||
void apply(EngineCanvas canvas) {
|
||||
canvas.drawColor(color, blendMode);
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -875,8 +892,8 @@ class PaintDrawLine extends DrawCommand {
|
||||
PaintDrawLine(this.p1, this.p2, this.paint);
|
||||
|
||||
@override
|
||||
void apply(EngineCanvas? canvas) {
|
||||
canvas!.drawLine(p1, p2, paint);
|
||||
void apply(EngineCanvas canvas) {
|
||||
canvas.drawLine(p1, p2, paint);
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -895,8 +912,8 @@ class PaintDrawPaint extends DrawCommand {
|
||||
PaintDrawPaint(this.paint);
|
||||
|
||||
@override
|
||||
void apply(EngineCanvas? canvas) {
|
||||
canvas!.drawPaint(paint);
|
||||
void apply(EngineCanvas canvas) {
|
||||
canvas.drawPaint(paint);
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -916,8 +933,8 @@ class PaintDrawVertices extends DrawCommand {
|
||||
PaintDrawVertices(this.vertices, this.blendMode, this.paint);
|
||||
|
||||
@override
|
||||
void apply(EngineCanvas? canvas) {
|
||||
canvas!.drawVertices(vertices as SurfaceVertices, blendMode, paint);
|
||||
void apply(EngineCanvas canvas) {
|
||||
canvas.drawVertices(vertices as SurfaceVertices, blendMode, paint);
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -937,8 +954,8 @@ class PaintDrawPoints extends DrawCommand {
|
||||
PaintDrawPoints(this.pointMode, this.points, this.paint);
|
||||
|
||||
@override
|
||||
void apply(EngineCanvas? canvas) {
|
||||
canvas!.drawPoints(pointMode, points, paint);
|
||||
void apply(EngineCanvas canvas) {
|
||||
canvas.drawPoints(pointMode, points, paint);
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -958,8 +975,8 @@ class PaintDrawRect extends DrawCommand {
|
||||
PaintDrawRect(this.rect, this.paint);
|
||||
|
||||
@override
|
||||
void apply(EngineCanvas? canvas) {
|
||||
canvas!.drawRect(rect, paint);
|
||||
void apply(EngineCanvas canvas) {
|
||||
canvas.drawRect(rect, paint);
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -979,8 +996,8 @@ class PaintDrawRRect extends DrawCommand {
|
||||
PaintDrawRRect(this.rrect, this.paint);
|
||||
|
||||
@override
|
||||
void apply(EngineCanvas? canvas) {
|
||||
canvas!.drawRRect(rrect, paint);
|
||||
void apply(EngineCanvas canvas) {
|
||||
canvas.drawRRect(rrect, paint);
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -1007,8 +1024,8 @@ class PaintDrawDRRect extends DrawCommand {
|
||||
}
|
||||
|
||||
@override
|
||||
void apply(EngineCanvas? canvas) {
|
||||
canvas!.drawPath(path!, paint);
|
||||
void apply(EngineCanvas canvas) {
|
||||
canvas.drawPath(path!, paint);
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -1028,8 +1045,8 @@ class PaintDrawOval extends DrawCommand {
|
||||
PaintDrawOval(this.rect, this.paint);
|
||||
|
||||
@override
|
||||
void apply(EngineCanvas? canvas) {
|
||||
canvas!.drawOval(rect, paint);
|
||||
void apply(EngineCanvas canvas) {
|
||||
canvas.drawOval(rect, paint);
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -1050,8 +1067,8 @@ class PaintDrawCircle extends DrawCommand {
|
||||
PaintDrawCircle(this.c, this.radius, this.paint);
|
||||
|
||||
@override
|
||||
void apply(EngineCanvas? canvas) {
|
||||
canvas!.drawCircle(c, radius, paint);
|
||||
void apply(EngineCanvas canvas) {
|
||||
canvas.drawCircle(c, radius, paint);
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -1071,8 +1088,8 @@ class PaintDrawPath extends DrawCommand {
|
||||
PaintDrawPath(this.path, this.paint);
|
||||
|
||||
@override
|
||||
void apply(EngineCanvas? canvas) {
|
||||
canvas!.drawPath(path, paint);
|
||||
void apply(EngineCanvas canvas) {
|
||||
canvas.drawPath(path, paint);
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -1095,8 +1112,8 @@ class PaintDrawShadow extends DrawCommand {
|
||||
final bool transparentOccluder;
|
||||
|
||||
@override
|
||||
void apply(EngineCanvas? canvas) {
|
||||
canvas!.drawShadow(path, color, elevation, transparentOccluder);
|
||||
void apply(EngineCanvas canvas) {
|
||||
canvas.drawShadow(path, color, elevation, transparentOccluder);
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -1117,8 +1134,8 @@ class PaintDrawImage extends DrawCommand {
|
||||
PaintDrawImage(this.image, this.offset, this.paint);
|
||||
|
||||
@override
|
||||
void apply(EngineCanvas? canvas) {
|
||||
canvas!.drawImage(image, offset, paint);
|
||||
void apply(EngineCanvas canvas) {
|
||||
canvas.drawImage(image, offset, paint);
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -1140,8 +1157,8 @@ class PaintDrawImageRect extends DrawCommand {
|
||||
PaintDrawImageRect(this.image, this.src, this.dst, this.paint);
|
||||
|
||||
@override
|
||||
void apply(EngineCanvas? canvas) {
|
||||
canvas!.drawImageRect(image, src, dst, paint);
|
||||
void apply(EngineCanvas canvas) {
|
||||
canvas.drawImageRect(image, src, dst, paint);
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -1161,8 +1178,8 @@ class PaintDrawParagraph extends DrawCommand {
|
||||
PaintDrawParagraph(this.paragraph, this.offset);
|
||||
|
||||
@override
|
||||
void apply(EngineCanvas? canvas) {
|
||||
canvas!.drawParagraph(paragraph, offset);
|
||||
void apply(EngineCanvas canvas) {
|
||||
canvas.drawParagraph(paragraph, offset);
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -1610,9 +1627,9 @@ class _PaintBounds {
|
||||
double _bottom = -double.maxFinite;
|
||||
|
||||
// Stack of transforms.
|
||||
late List<Matrix4> _transforms = <Matrix4>[];
|
||||
final List<Matrix4> _transforms = <Matrix4>[];
|
||||
// Stack of clip bounds.
|
||||
late List<ui.Rect?> _clipStack = <ui.Rect?>[];
|
||||
final List<ui.Rect?> _clipStack = <ui.Rect?>[];
|
||||
bool _currentMatrixIsIdentity = true;
|
||||
Matrix4 _currentMatrix = Matrix4.identity();
|
||||
bool _clipRectInitialized = false;
|
||||
@@ -1705,7 +1722,8 @@ class _PaintBounds {
|
||||
_currentClipBottom = bottom;
|
||||
}
|
||||
}
|
||||
if (_currentClipLeft >= _currentClipRight || _currentClipTop >= _currentClipBottom) {
|
||||
if (_currentClipLeft >= _currentClipRight ||
|
||||
_currentClipTop >= _currentClipBottom) {
|
||||
command.isClippedOut = true;
|
||||
} else {
|
||||
command.leftBound = _currentClipLeft;
|
||||
@@ -1721,7 +1739,8 @@ class _PaintBounds {
|
||||
}
|
||||
|
||||
/// Grow painted area to include given rectangle.
|
||||
void growLTRB(double left, double top, double right, double bottom, DrawCommand command) {
|
||||
void growLTRB(double left, double top, double right, double bottom,
|
||||
DrawCommand command) {
|
||||
if (left == right || top == bottom) {
|
||||
command.isClippedOut = true;
|
||||
return;
|
||||
|
||||
@@ -35,8 +35,9 @@ void testMain() {
|
||||
underTest.apply(mockCanvas, screenRect);
|
||||
|
||||
_expectDrawDRRectCall(mockCanvas, <String, dynamic>{
|
||||
'path': 'Path(MoveTo(10, 47) LineTo(10, 13) Conic(10, 10, 10, 13, w = 0.7071067690849304) LineTo(47, 10) Conic(50, 10, 10, 50, w = 0.7071067690849304) LineTo(50, 47) Conic(50, 50, 50, 47, w = 0.7071067690849304) LineTo(13, 50) Conic(10, 50, 50, 10, w = 0.7071067690849304) Close() MoveTo(11, 47) LineTo(11, 13) Conic(11, 11, 11, 13, w = 0.7071067690849304) LineTo(47, 11) Conic(49, 11, 11, 49, w = 0.7071067690849304) LineTo(49, 47) Conic(49, 49, 49, 47, w = 0.7071067690849304) LineTo(13, 49) Conic(11, 49, 49, 11, w = 0.7071067690849304) Close())',
|
||||
'paint': somePaint.paintData,
|
||||
'path':
|
||||
'Path(MoveTo(10, 47) LineTo(10, 13) Conic(10, 10, 10, 13, w = 0.7071067690849304) LineTo(47, 10) Conic(50, 10, 10, 50, w = 0.7071067690849304) LineTo(50, 47) Conic(50, 50, 50, 47, w = 0.7071067690849304) LineTo(13, 50) Conic(10, 50, 50, 10, w = 0.7071067690849304) Close() MoveTo(11, 47) LineTo(11, 13) Conic(11, 11, 11, 13, w = 0.7071067690849304) LineTo(47, 11) Conic(49, 11, 11, 49, w = 0.7071067690849304) LineTo(49, 47) Conic(49, 49, 49, 47, w = 0.7071067690849304) LineTo(13, 49) Conic(11, 49, 49, 11, w = 0.7071067690849304) Close())',
|
||||
'paint': somePaint.paintData,
|
||||
});
|
||||
});
|
||||
|
||||
@@ -86,7 +87,8 @@ void testMain() {
|
||||
|
||||
// Expect to draw, even when inner has negative radii (which get ignored by canvas)
|
||||
_expectDrawDRRectCall(mockCanvas, <String, dynamic>{
|
||||
'path': 'Path(MoveTo(0, 42) LineTo(0, 6) Conic(0, 0, 0, 6, w = 0.7071067690849304) LineTo(88, 0) Conic(88, 0, 0, 88, w = 0.7071067690849304) LineTo(88, 48) Conic(88, 48, 48, 88, w = 0.7071067690849304) LineTo(6, 48) Conic(0, 48, 48, 0, w = 0.7071067690849304) Close() MoveTo(1, 42) LineTo(1, 6) Conic(1, 1, 1, 6, w = 0.7071067690849304) LineTo(87, 1) Conic(87, 1, 1, 87, w = 0.7071067690849304) LineTo(87, 47) Conic(87, 47, 47, 87, w = 0.7071067690849304) LineTo(6, 47) Conic(1, 47, 47, 1, w = 0.7071067690849304) Close())',
|
||||
'path':
|
||||
'Path(MoveTo(0, 42) LineTo(0, 6) Conic(0, 0, 0, 6, w = 0.7071067690849304) LineTo(88, 0) Conic(88, 0, 0, 88, w = 0.7071067690849304) LineTo(88, 48) Conic(88, 48, 48, 88, w = 0.7071067690849304) LineTo(6, 48) Conic(0, 48, 48, 0, w = 0.7071067690849304) Close() MoveTo(1, 42) LineTo(1, 6) Conic(1, 1, 1, 6, w = 0.7071067690849304) LineTo(87, 1) Conic(87, 1, 1, 87, w = 0.7071067690849304) LineTo(87, 47) Conic(87, 47, 47, 87, w = 0.7071067690849304) LineTo(6, 47) Conic(1, 47, 47, 1, w = 0.7071067690849304) Close())',
|
||||
'paint': somePaint.paintData,
|
||||
});
|
||||
});
|
||||
@@ -102,7 +104,8 @@ void testMain() {
|
||||
underTest.apply(mockCanvas, screenRect);
|
||||
|
||||
_expectDrawDRRectCall(mockCanvas, <String, dynamic>{
|
||||
'path': 'Path(MoveTo(10, 20) LineTo(30, 20) LineTo(30, 40) LineTo(10, 40) Close() MoveTo(12, 22) LineTo(28, 22) LineTo(28, 38) LineTo(12, 38) Close())',
|
||||
'path':
|
||||
'Path(MoveTo(10, 20) LineTo(30, 20) LineTo(30, 40) LineTo(10, 40) Close() MoveTo(12, 22) LineTo(28, 22) LineTo(28, 38) LineTo(12, 38) Close())',
|
||||
'paint': somePaint.paintData,
|
||||
});
|
||||
});
|
||||
@@ -123,7 +126,7 @@ void testMain() {
|
||||
|
||||
// Inside the layer clip but clipped out by a canvas clip
|
||||
underTest.save();
|
||||
underTest.clipRect(Rect.fromLTWH(0, 0, 10, 10));
|
||||
underTest.clipRect(Rect.fromLTWH(0, 0, 10, 10), ClipOp.intersect);
|
||||
underTest.drawRect(Rect.fromLTWH(20.0, 20.0, 10.0, 10.0), Paint());
|
||||
underTest.restore();
|
||||
|
||||
|
||||
@@ -28,7 +28,7 @@ void testMain() async {
|
||||
// Commit a recording canvas to a bitmap, and compare with the expected
|
||||
Future<void> _checkScreenshot(RecordingCanvas rc, String fileName,
|
||||
{Rect region = const Rect.fromLTWH(0, 0, 500, 500),
|
||||
double maxDiffRatePercent = 0.0}) async {
|
||||
double maxDiffRatePercent = 0.0}) async {
|
||||
final EngineCanvas engineCanvas = BitmapCanvas(screenRect);
|
||||
|
||||
rc.endRecording();
|
||||
@@ -203,7 +203,7 @@ void testMain() async {
|
||||
Image testImage = createTestImage();
|
||||
double testWidth = testImage.width.toDouble();
|
||||
double testHeight = testImage.height.toDouble();
|
||||
rc.clipRect(Rect.fromLTRB(75, 75, 160, 160));
|
||||
rc.clipRect(Rect.fromLTRB(75, 75, 160, 160), ClipOp.intersect);
|
||||
rc.drawImageRect(testImage, Rect.fromLTRB(0, 0, testWidth, testHeight),
|
||||
Rect.fromLTRB(100, 30, 2 * testWidth, 2 * testHeight), new Paint());
|
||||
rc.drawCircle(
|
||||
@@ -229,7 +229,7 @@ void testMain() async {
|
||||
rc.translate(100, 100);
|
||||
rc.rotate(math.pi / 4.0);
|
||||
rc.translate(-100, -100);
|
||||
rc.clipRect(Rect.fromLTRB(75, 75, 160, 160));
|
||||
rc.clipRect(Rect.fromLTRB(75, 75, 160, 160), ClipOp.intersect);
|
||||
rc.drawImageRect(testImage, Rect.fromLTRB(0, 0, testWidth, testHeight),
|
||||
Rect.fromLTRB(100, 30, 2 * testWidth, 2 * testHeight), new Paint());
|
||||
rc.drawCircle(
|
||||
@@ -256,7 +256,7 @@ void testMain() async {
|
||||
rc.rotate(-math.pi / 4.0);
|
||||
rc.save();
|
||||
rc.translate(-100, -100);
|
||||
rc.clipRect(Rect.fromLTRB(75, 75, 160, 160));
|
||||
rc.clipRect(Rect.fromLTRB(75, 75, 160, 160), ClipOp.intersect);
|
||||
rc.drawImageRect(testImage, Rect.fromLTRB(0, 0, testWidth, testHeight),
|
||||
Rect.fromLTRB(100, 30, 2 * testWidth, 2 * testHeight), new Paint());
|
||||
rc.drawCircle(
|
||||
@@ -358,7 +358,7 @@ void testMain() async {
|
||||
EnginePictureRecorder recorder = EnginePictureRecorder();
|
||||
final Canvas canvas = Canvas(recorder, region);
|
||||
Image testImage = createNineSliceImage();
|
||||
canvas.clipRect(Rect.fromLTWH(0, 0,420, 200));
|
||||
canvas.clipRect(Rect.fromLTWH(0, 0, 420, 200));
|
||||
canvas.drawImageNine(testImage, Rect.fromLTWH(20, 20, 20, 20),
|
||||
Rect.fromLTWH(20, 20, 400, 400), Paint());
|
||||
Picture picture = recorder.endRecording();
|
||||
@@ -395,11 +395,10 @@ void testMain() async {
|
||||
..lineTo(50, 10)
|
||||
..lineTo(50, 30)
|
||||
..lineTo(10, 30)
|
||||
..close()
|
||||
);
|
||||
..close());
|
||||
canvas.drawImage(createNineSliceImage(), Offset.zero, Paint());
|
||||
await _checkScreenshot(canvas, 'draw_clipped_and_transformed_image', region: region,
|
||||
maxDiffRatePercent: 1.0);
|
||||
await _checkScreenshot(canvas, 'draw_clipped_and_transformed_image',
|
||||
region: region, maxDiffRatePercent: 1.0);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -535,14 +534,12 @@ const String base64ImageData = 'data:image/png;base64,iVBORw0KGgoAAAANSUh'
|
||||
|
||||
HtmlImage createNineSliceImage() {
|
||||
return HtmlImage(
|
||||
html.ImageElement()
|
||||
..src = base64ImageData,
|
||||
html.ImageElement()..src = base64ImageData,
|
||||
60,
|
||||
60,
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
HtmlImage createTestImage({int width = 100, int height = 50}) {
|
||||
html.CanvasElement canvas =
|
||||
new html.CanvasElement(width: width, height: height);
|
||||
|
||||
@@ -136,13 +136,13 @@ void drawQuickBrownFox(RecordingCanvas canvas) {
|
||||
|
||||
void paintTextWithClipRect(RecordingCanvas canvas) {
|
||||
drawBackground(canvas);
|
||||
canvas.clipRect(testBounds.inflate(-40));
|
||||
canvas.clipRect(testBounds.inflate(-40), ClipOp.intersect);
|
||||
drawQuickBrownFox(canvas);
|
||||
}
|
||||
|
||||
void paintTextWithClipRectTranslated(RecordingCanvas canvas) {
|
||||
drawBackground(canvas);
|
||||
canvas.clipRect(testBounds.inflate(-40));
|
||||
canvas.clipRect(testBounds.inflate(-40), ClipOp.intersect);
|
||||
canvas.translate(30, 10);
|
||||
drawQuickBrownFox(canvas);
|
||||
}
|
||||
@@ -190,10 +190,10 @@ void paintTextWithClipPath(RecordingCanvas canvas) {
|
||||
void paintTextWithClipStack(RecordingCanvas canvas) {
|
||||
drawBackground(canvas);
|
||||
final Rect inflatedRect = testBounds.inflate(-40);
|
||||
canvas.clipRect(inflatedRect);
|
||||
canvas.clipRect(inflatedRect, ClipOp.intersect);
|
||||
canvas.rotate(math.pi / 8.0);
|
||||
canvas.translate(40, -40);
|
||||
canvas.clipRect(inflatedRect);
|
||||
canvas.clipRect(inflatedRect, ClipOp.intersect);
|
||||
canvas.drawRect(
|
||||
inflatedRect,
|
||||
Paint()
|
||||
|
||||
@@ -92,8 +92,8 @@ void testMain() async {
|
||||
testPaint);
|
||||
rc.endRecording();
|
||||
// The off by one is due to the minimum stroke width of 1.
|
||||
expect(rc.pictureBounds,
|
||||
const Rect.fromLTRB(49.0, 99.0, screenWidth, 141.0));
|
||||
expect(
|
||||
rc.pictureBounds, const Rect.fromLTRB(49.0, 99.0, screenWidth, 141.0));
|
||||
await _checkScreenshot(rc, 'draw_line_exceeding_limits');
|
||||
});
|
||||
|
||||
@@ -199,8 +199,11 @@ void testMain() async {
|
||||
rc.transform(matrix);
|
||||
rc.drawRect(const Rect.fromLTRB(10, 20, 30, 40), testPaint);
|
||||
rc.endRecording();
|
||||
expect(rc.pictureBounds,
|
||||
within(distance: 0.001, from: const Rect.fromLTRB(168.0, 283.6, 224.0, 368.4)));
|
||||
expect(
|
||||
rc.pictureBounds,
|
||||
within(
|
||||
distance: 0.001,
|
||||
from: const Rect.fromLTRB(168.0, 283.6, 224.0, 368.4)));
|
||||
await _checkScreenshot(rc, 'complex_transform');
|
||||
});
|
||||
|
||||
@@ -270,16 +273,14 @@ void testMain() async {
|
||||
RecordingCanvas rc = RecordingCanvas(screenRect);
|
||||
rc.drawCircle(const Offset(20, 20), 10.0, testPaint);
|
||||
rc.endRecording();
|
||||
expect(
|
||||
rc.pictureBounds, const Rect.fromLTRB(10.0, 10.0, 30.0, 30.0));
|
||||
expect(rc.pictureBounds, const Rect.fromLTRB(10.0, 10.0, 30.0, 30.0));
|
||||
|
||||
// Paint bounds of a union of two circles.
|
||||
rc = RecordingCanvas(screenRect);
|
||||
rc.drawCircle(const Offset(20, 20), 10.0, testPaint);
|
||||
rc.drawCircle(const Offset(200, 300), 100.0, testPaint);
|
||||
rc.endRecording();
|
||||
expect(
|
||||
rc.pictureBounds, const Rect.fromLTRB(10.0, 10.0, 300.0, 400.0));
|
||||
expect(rc.pictureBounds, const Rect.fromLTRB(10.0, 10.0, 300.0, 400.0));
|
||||
await _checkScreenshot(rc, 'draw_circle');
|
||||
});
|
||||
|
||||
@@ -287,8 +288,7 @@ void testMain() async {
|
||||
final RecordingCanvas rc = RecordingCanvas(screenRect);
|
||||
rc.drawImage(TestImage(), const Offset(50, 100), Paint());
|
||||
rc.endRecording();
|
||||
expect(
|
||||
rc.pictureBounds, const Rect.fromLTRB(50.0, 100.0, 70.0, 110.0));
|
||||
expect(rc.pictureBounds, const Rect.fromLTRB(50.0, 100.0, 70.0, 110.0));
|
||||
});
|
||||
|
||||
test('Computes paint bounds for draw image rect', () {
|
||||
@@ -296,8 +296,7 @@ void testMain() async {
|
||||
rc.drawImageRect(TestImage(), const Rect.fromLTRB(1, 1, 20, 10),
|
||||
const Rect.fromLTRB(5, 6, 400, 500), Paint());
|
||||
rc.endRecording();
|
||||
expect(
|
||||
rc.pictureBounds, const Rect.fromLTRB(5.0, 6.0, 400.0, 500.0));
|
||||
expect(rc.pictureBounds, const Rect.fromLTRB(5.0, 6.0, 400.0, 500.0));
|
||||
});
|
||||
|
||||
test('Computes paint bounds for single-line draw paragraph', () async {
|
||||
@@ -336,14 +335,14 @@ void testMain() async {
|
||||
test('Should exclude painting outside simple clipRect', () async {
|
||||
// One clipped line.
|
||||
RecordingCanvas rc = RecordingCanvas(screenRect);
|
||||
rc.clipRect(const Rect.fromLTRB(50, 50, 100, 100));
|
||||
rc.clipRect(const Rect.fromLTRB(50, 50, 100, 100), ClipOp.intersect);
|
||||
rc.drawLine(const Offset(10, 11), const Offset(20, 21), testPaint);
|
||||
rc.endRecording();
|
||||
expect(rc.pictureBounds, Rect.zero);
|
||||
|
||||
// Two clipped lines.
|
||||
rc = RecordingCanvas(screenRect);
|
||||
rc.clipRect(const Rect.fromLTRB(50, 50, 100, 100));
|
||||
rc.clipRect(const Rect.fromLTRB(50, 50, 100, 100), ClipOp.intersect);
|
||||
rc.drawLine(const Offset(10, 11), const Offset(20, 21), testPaint);
|
||||
rc.drawLine(const Offset(52, 53), const Offset(55, 56), testPaint);
|
||||
rc.endRecording();
|
||||
@@ -355,14 +354,14 @@ void testMain() async {
|
||||
|
||||
test('Should include intersection of clipRect and painting', () async {
|
||||
RecordingCanvas rc = RecordingCanvas(screenRect);
|
||||
rc.clipRect(const Rect.fromLTRB(50, 50, 100, 100));
|
||||
rc.clipRect(const Rect.fromLTRB(50, 50, 100, 100), ClipOp.intersect);
|
||||
rc.drawRect(const Rect.fromLTRB(20, 60, 120, 70), testPaint);
|
||||
rc.endRecording();
|
||||
expect(rc.pictureBounds, const Rect.fromLTRB(50, 60, 100, 70));
|
||||
await _checkScreenshot(rc, 'clip_rect_intersects_paint_left_to_right');
|
||||
|
||||
rc = RecordingCanvas(screenRect);
|
||||
rc.clipRect(const Rect.fromLTRB(50, 50, 100, 100));
|
||||
rc.clipRect(const Rect.fromLTRB(50, 50, 100, 100), ClipOp.intersect);
|
||||
rc.drawRect(const Rect.fromLTRB(60, 20, 70, 200), testPaint);
|
||||
rc.endRecording();
|
||||
expect(rc.pictureBounds, const Rect.fromLTRB(60, 50, 70, 100));
|
||||
@@ -371,9 +370,9 @@ void testMain() async {
|
||||
|
||||
test('Should intersect rects for multiple clipRect calls', () async {
|
||||
final RecordingCanvas rc = RecordingCanvas(screenRect);
|
||||
rc.clipRect(const Rect.fromLTRB(50, 50, 100, 100));
|
||||
rc.clipRect(const Rect.fromLTRB(50, 50, 100, 100), ClipOp.intersect);
|
||||
rc.scale(2.0, 2.0);
|
||||
rc.clipRect(const Rect.fromLTRB(30, 30, 45, 45));
|
||||
rc.clipRect(const Rect.fromLTRB(30, 30, 45, 45), ClipOp.intersect);
|
||||
rc.drawRect(const Rect.fromLTRB(10, 30, 60, 35), testPaint);
|
||||
rc.endRecording();
|
||||
|
||||
@@ -391,7 +390,8 @@ void testMain() async {
|
||||
|
||||
expect(
|
||||
rc.pictureBounds,
|
||||
within(distance: 0.05, from: const Rect.fromLTRB(17.9, 28.5, 103.5, 114.1)),
|
||||
within(
|
||||
distance: 0.05, from: const Rect.fromLTRB(17.9, 28.5, 103.5, 114.1)),
|
||||
);
|
||||
await _checkScreenshot(rc, 'path_with_shadow');
|
||||
});
|
||||
@@ -408,12 +408,11 @@ void testMain() async {
|
||||
rc
|
||||
..translate(0, 100)
|
||||
..scale(1, -1)
|
||||
..clipRect(const Rect.fromLTRB(0, 0, 100, 50))
|
||||
..clipRect(const Rect.fromLTRB(0, 0, 100, 50), ClipOp.intersect)
|
||||
..drawRect(const Rect.fromLTRB(0, 0, 100, 100), Paint());
|
||||
rc.endRecording();
|
||||
|
||||
expect(
|
||||
rc.pictureBounds, const Rect.fromLTRB(0.0, 50.0, 100.0, 100.0));
|
||||
expect(rc.pictureBounds, const Rect.fromLTRB(0.0, 50.0, 100.0, 100.0));
|
||||
await _checkScreenshot(rc, 'scale_negative');
|
||||
});
|
||||
|
||||
@@ -423,13 +422,16 @@ void testMain() async {
|
||||
rc
|
||||
..translate(50, 50)
|
||||
..rotate(math.pi / 4.0)
|
||||
..clipRect(const Rect.fromLTWH(-20, -20, 40, 40))
|
||||
..clipRect(const Rect.fromLTWH(-20, -20, 40, 40), ClipOp.intersect)
|
||||
..drawRect(const Rect.fromLTWH(-80, -80, 160, 160), Paint());
|
||||
rc.endRecording();
|
||||
|
||||
expect(
|
||||
rc.pictureBounds,
|
||||
within(distance: 0.001, from: Rect.fromCircle(center: const Offset(50, 50), radius: 20 * math.sqrt(2))),
|
||||
within(
|
||||
distance: 0.001,
|
||||
from: Rect.fromCircle(
|
||||
center: const Offset(50, 50), radius: 20 * math.sqrt(2))),
|
||||
);
|
||||
await _checkScreenshot(rc, 'clip_rect_rotated');
|
||||
});
|
||||
@@ -681,12 +683,13 @@ void testMain() async {
|
||||
});
|
||||
}
|
||||
|
||||
typedef PaintSpreadPainter = void Function(RecordingCanvas canvas, SurfacePaint paint);
|
||||
typedef PaintSpreadPainter = void Function(
|
||||
RecordingCanvas canvas, SurfacePaint paint);
|
||||
|
||||
const String _base64Encoded20x20TestImage = 'iVBORw0KGgoAAAANSUhEUgAAABQAAAAUC'
|
||||
'AIAAAAC64paAAAACXBIWXMAAC4jAAAuIwF4pT92AAAA'
|
||||
'B3RJTUUH5AMFFBksg4i3gQAAABl0RVh0Q29tbWVudABDcmVhdGVkIHdpdGggR0lNUFeBDhcAAAAj'
|
||||
'SURBVDjLY2TAC/7jlWVioACMah4ZmhnxpyHG0QAb1UyZZgBjWAIm/clP0AAAAABJRU5ErkJggg==';
|
||||
'B3RJTUUH5AMFFBksg4i3gQAAABl0RVh0Q29tbWVudABDcmVhdGVkIHdpdGggR0lNUFeBDhcAAAAj'
|
||||
'SURBVDjLY2TAC/7jlWVioACMah4ZmhnxpyHG0QAb1UyZZgBjWAIm/clP0AAAAABJRU5ErkJggg==';
|
||||
|
||||
HtmlImage _createRealTestImage() {
|
||||
return HtmlImage(
|
||||
|
||||
Reference in New Issue
Block a user