forked from firka/flutter
Flesh out the CanvasKit backend some more (flutter/engine#13275)
* Flesh out the CanvasKit backend some more - Implement `drawOval` and `addOval` - Use the Canvas's own `getSaveCount` - Implement `skew` - Implement `saveLayerWithoutBounds` - Document things which we don't plan to implement in the Skia backend * Remove `rasterCache` fake support * Remove saveCount setter
This commit is contained in:
@@ -97,6 +97,4 @@ class SkCanvas {
|
||||
bool transparentOccluder) {
|
||||
drawSkShadow(skCanvas, path, color, elevation, transparentOccluder);
|
||||
}
|
||||
|
||||
Matrix4 get currentTransform => throw 'currentTransform';
|
||||
}
|
||||
|
||||
@@ -289,14 +289,6 @@ class PictureLayer extends Layer {
|
||||
|
||||
@override
|
||||
void preroll(PrerollContext prerollContext, Matrix4 matrix) {
|
||||
final RasterCache cache = prerollContext.rasterCache;
|
||||
if (cache != null) {
|
||||
final Matrix4 translateMatrix = Matrix4.identity()
|
||||
..setTranslationRaw(offset.dx, offset.dy, 0);
|
||||
final Matrix4 cacheMatrix = translateMatrix * matrix;
|
||||
cache.prepare(picture, cacheMatrix, isComplex, willChange);
|
||||
}
|
||||
|
||||
paintBounds = picture.cullRect.shift(offset);
|
||||
}
|
||||
|
||||
@@ -308,15 +300,6 @@ class PictureLayer extends Layer {
|
||||
paintContext.canvas.save();
|
||||
paintContext.canvas.translate(offset.dx, offset.dy);
|
||||
|
||||
if (paintContext.rasterCache != null) {
|
||||
final Matrix4 cacheMatrix = paintContext.canvas.currentTransform;
|
||||
final RasterCacheResult result =
|
||||
paintContext.rasterCache.get(picture, cacheMatrix);
|
||||
if (result.isValid) {
|
||||
result.draw(paintContext.canvas);
|
||||
return;
|
||||
}
|
||||
}
|
||||
paintContext.canvas.drawPicture(picture);
|
||||
paintContext.canvas.restore();
|
||||
}
|
||||
|
||||
@@ -46,9 +46,7 @@ class SkPath implements ui.Path {
|
||||
|
||||
@override
|
||||
void addOval(ui.Rect oval) {
|
||||
// TODO(het): Use `addOval` instead when CanvasKit exposes it.
|
||||
// Since CanvasKit doesn't expose `addOval`, use `addArc` instead.
|
||||
_skPath.callMethod('addArc', <dynamic>[makeSkRect(oval), 0.0, 360.0]);
|
||||
_skPath.callMethod('addOval', <js.JsObject>[makeSkRect(oval)]);
|
||||
}
|
||||
|
||||
@override
|
||||
|
||||
@@ -15,7 +15,11 @@ class SkRecordingCanvas implements RecordingCanvas {
|
||||
bool _hasArbitraryPaint = true;
|
||||
|
||||
@override
|
||||
int saveCount = 0;
|
||||
int get saveCount => skCanvas.callMethod('getSaveCount');
|
||||
|
||||
// This is required to implement RecordingCanvas.
|
||||
@override
|
||||
int _saveCount = -1;
|
||||
|
||||
@override
|
||||
// TODO: implement _commands
|
||||
@@ -27,7 +31,7 @@ class SkRecordingCanvas implements RecordingCanvas {
|
||||
|
||||
@override
|
||||
void apply(EngineCanvas engineCanvas) {
|
||||
throw 'apply';
|
||||
throw UnimplementedError("The Skia backend doesn't support apply()");
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -76,22 +80,26 @@ class SkRecordingCanvas implements RecordingCanvas {
|
||||
|
||||
@override
|
||||
ui.Rect computePaintBounds() {
|
||||
throw 'computePaintBounds';
|
||||
throw UnimplementedError(
|
||||
"The Skia backend doesn't use computePaintBounds()");
|
||||
}
|
||||
|
||||
@override
|
||||
void debugDumpCommands() {
|
||||
throw 'debugDumpCommands';
|
||||
throw UnimplementedError(
|
||||
"The Skia backend doesn't use debugDumpCommands()");
|
||||
}
|
||||
|
||||
@override
|
||||
void debugEnforceArbitraryPaint() {
|
||||
throw 'debugEnforceArbitraryPaint';
|
||||
throw UnimplementedError(
|
||||
"The Skia backend doesn't use debugEnforceArbitraryPaint()");
|
||||
}
|
||||
|
||||
@override
|
||||
String debugPrintCommands() {
|
||||
throw 'debugPrintCommands';
|
||||
throw UnimplementedError(
|
||||
"The Skia backend doesn't use debugPrintCommands()");
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -109,6 +117,7 @@ class SkRecordingCanvas implements RecordingCanvas {
|
||||
|
||||
@override
|
||||
void drawColor(ui.Color color, ui.BlendMode blendMode) {
|
||||
// TODO(het): Implement this once SkCanvas.drawColor becomes available.
|
||||
throw 'drawColor';
|
||||
}
|
||||
|
||||
@@ -123,7 +132,13 @@ class SkRecordingCanvas implements RecordingCanvas {
|
||||
|
||||
@override
|
||||
void drawImage(ui.Image image, ui.Offset offset, ui.Paint paint) {
|
||||
throw 'drawImage';
|
||||
final SkImage skImage = image;
|
||||
skCanvas.callMethod('drawImage', <dynamic>[
|
||||
skImage.skImage,
|
||||
offset.dx,
|
||||
offset.dy,
|
||||
makeSkPaint(paint),
|
||||
]);
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -151,12 +166,15 @@ class SkRecordingCanvas implements RecordingCanvas {
|
||||
|
||||
@override
|
||||
void drawOval(ui.Rect rect, ui.Paint paint) {
|
||||
throw 'drawOval';
|
||||
skCanvas.callMethod('drawOval', <js.JsObject>[
|
||||
makeSkRect(rect),
|
||||
makeSkPaint(paint),
|
||||
]);
|
||||
}
|
||||
|
||||
@override
|
||||
void drawPaint(ui.Paint paint) {
|
||||
throw 'drawPaint';
|
||||
skCanvas.callMethod('drawPaint', <js.JsObject>[makeSkPaint(paint)]);
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -230,7 +248,6 @@ class SkRecordingCanvas implements RecordingCanvas {
|
||||
@override
|
||||
void restore() {
|
||||
skCanvas.callMethod('restore');
|
||||
saveCount--;
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -242,7 +259,6 @@ class SkRecordingCanvas implements RecordingCanvas {
|
||||
@override
|
||||
void save() {
|
||||
skCanvas.callMethod('save');
|
||||
saveCount++;
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -251,12 +267,11 @@ class SkRecordingCanvas implements RecordingCanvas {
|
||||
makeSkRect(bounds),
|
||||
makeSkPaint(paint),
|
||||
]);
|
||||
saveCount++;
|
||||
}
|
||||
|
||||
@override
|
||||
void saveLayerWithoutBounds(ui.Paint paint) {
|
||||
throw 'saveLayerWithoutBounds';
|
||||
skCanvas.callMethod('saveLayer', <js.JsObject>[null, makeSkPaint(paint)]);
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -266,7 +281,7 @@ class SkRecordingCanvas implements RecordingCanvas {
|
||||
|
||||
@override
|
||||
void skew(double sx, double sy) {
|
||||
throw 'skew';
|
||||
skCanvas.callMethod('skew', <double>[sx, sy]);
|
||||
}
|
||||
|
||||
@override
|
||||
|
||||
@@ -102,7 +102,7 @@ class RecordingCanvas {
|
||||
void save() {
|
||||
_paintBounds.saveTransformsAndClip();
|
||||
_commands.add(const PaintSave());
|
||||
saveCount++;
|
||||
_saveCount++;
|
||||
}
|
||||
|
||||
void saveLayerWithoutBounds(ui.Paint paint) {
|
||||
@@ -110,7 +110,7 @@ class RecordingCanvas {
|
||||
// TODO(het): Implement this correctly using another canvas.
|
||||
_commands.add(const PaintSave());
|
||||
_paintBounds.saveTransformsAndClip();
|
||||
saveCount++;
|
||||
_saveCount++;
|
||||
}
|
||||
|
||||
void saveLayer(ui.Rect bounds, ui.Paint paint) {
|
||||
@@ -118,7 +118,7 @@ class RecordingCanvas {
|
||||
// TODO(het): Implement this correctly using another canvas.
|
||||
_commands.add(const PaintSave());
|
||||
_paintBounds.saveTransformsAndClip();
|
||||
saveCount++;
|
||||
_saveCount++;
|
||||
}
|
||||
|
||||
void restore() {
|
||||
@@ -132,7 +132,7 @@ class RecordingCanvas {
|
||||
} else {
|
||||
_commands.add(const PaintRestore());
|
||||
}
|
||||
saveCount--;
|
||||
_saveCount--;
|
||||
}
|
||||
|
||||
void translate(double dx, double dy) {
|
||||
@@ -382,7 +382,8 @@ class RecordingCanvas {
|
||||
_commands.add(PaintVertices(vertices, blendMode, paint.webOnlyPaintData));
|
||||
}
|
||||
|
||||
int saveCount = 1;
|
||||
int _saveCount = 1;
|
||||
int get saveCount => _saveCount;
|
||||
|
||||
/// Prints the commands recorded by this canvas to the console.
|
||||
void debugDumpCommands() {
|
||||
|
||||
Reference in New Issue
Block a user