From e3d9ea67da0eb2563b68b67aba52618e7f3b9b68 Mon Sep 17 00:00:00 2001 From: Adam Barth Date: Mon, 10 Aug 2015 13:25:28 -0700 Subject: [PATCH] Simplify SkPicture This patch simplifies the SkPicture we generate for Skia. Instead of drawing everything into a nested SkPicture, we now draw everything into the top-level picture, which requires us to apply the device scale factor in Dart. --- examples/raw/baseline.dart | 4 +++- examples/raw/hello_world.dart | 4 +++- examples/raw/mutating-dom.dart | 4 +++- examples/raw/painting.dart | 4 +++- examples/raw/painting_node.dart | 7 ++++--- examples/raw/shadow.dart | 4 +++- examples/raw/spinning_arabic.dart | 4 +++- examples/raw/spinning_image.dart | 4 +++- examples/raw/spinning_square.dart | 4 +++- packages/flutter/lib/rendering/box.dart | 8 ++++++-- 10 files changed, 34 insertions(+), 13 deletions(-) diff --git a/examples/raw/baseline.dart b/examples/raw/baseline.dart index 4d88108616..0e1e86690e 100644 --- a/examples/raw/baseline.dart +++ b/examples/raw/baseline.dart @@ -47,7 +47,9 @@ void drawText(sky.Canvas canvas, String lh) { void main() { // prepare the rendering sky.PictureRecorder recorder = new sky.PictureRecorder(); - sky.Canvas canvas = new sky.Canvas(recorder, new sky.Rect.fromLTWH(0.0, 0.0, sky.view.width, sky.view.height)); + final double devicePixelRatio = sky.view.devicePixelRatio; + sky.Canvas canvas = new sky.Canvas(recorder, new sky.Rect.fromLTWH(0.0, 0.0, sky.view.width * devicePixelRatio, sky.view.height * devicePixelRatio)); + canvas.scale(devicePixelRatio, devicePixelRatio); // background sky.Paint paint = new sky.Paint(); diff --git a/examples/raw/hello_world.dart b/examples/raw/hello_world.dart index b091338b9b..c9ed52af24 100644 --- a/examples/raw/hello_world.dart +++ b/examples/raw/hello_world.dart @@ -8,7 +8,9 @@ Picture draw(int a, int r, int g, int b) { Size size = new Size(view.width, view.height); PictureRecorder recorder = new PictureRecorder(); - Canvas canvas = new Canvas(recorder, Point.origin & size); + final double devicePixelRatio = sky.view.devicePixelRatio; + Canvas canvas = new Canvas(recorder, Point.origin & (size * devicePixelRatio)); + canvas.scale(devicePixelRatio, devicePixelRatio); double radius = size.shortestSide * 0.45; Paint paint = new Paint()..color = new Color.fromARGB(a, r, g, b); diff --git a/examples/raw/mutating-dom.dart b/examples/raw/mutating-dom.dart index 6de893c478..8ec6ec8cbe 100644 --- a/examples/raw/mutating-dom.dart +++ b/examples/raw/mutating-dom.dart @@ -202,7 +202,9 @@ void doFrame(double timeStamp) { // draw the result report("recording..."); sky.PictureRecorder recorder = new sky.PictureRecorder(); - sky.Canvas canvas = new sky.Canvas(recorder, new sky.Rect.fromLTWH(0.0, 0.0, sky.view.width, sky.view.height)); + final double devicePixelRatio = sky.view.devicePixelRatio; + sky.Canvas canvas = new sky.Canvas(recorder, new sky.Rect.fromLTWH(0.0, 0.0, sky.view.width * devicePixelRatio, sky.view.height * devicePixelRatio)); + canvas.scale(devicePixelRatio, devicePixelRatio); layoutRoot.maxWidth = sky.view.width; layoutRoot.layout(); layoutRoot.paint(canvas); diff --git a/examples/raw/painting.dart b/examples/raw/painting.dart index 2b34532016..03fcd071e1 100644 --- a/examples/raw/painting.dart +++ b/examples/raw/painting.dart @@ -9,7 +9,9 @@ import 'dart:typed_data'; void beginFrame(double timeStamp) { sky.Size size = new sky.Size(sky.view.width, sky.view.height); sky.PictureRecorder recorder = new sky.PictureRecorder(); - sky.Canvas canvas = new sky.Canvas(recorder, sky.Point.origin & size); + final double devicePixelRatio = sky.view.devicePixelRatio; + sky.Canvas canvas = new sky.Canvas(recorder, sky.Point.origin & (size * devicePixelRatio)); + canvas.scale(devicePixelRatio, devicePixelRatio); sky.Paint paint = new sky.Paint(); sky.Point mid = size.center(sky.Point.origin); diff --git a/examples/raw/painting_node.dart b/examples/raw/painting_node.dart index a550812bed..2a7e67f5ab 100644 --- a/examples/raw/painting_node.dart +++ b/examples/raw/painting_node.dart @@ -6,11 +6,12 @@ import 'dart:sky'; PaintingNode paintingNode = null; Picture draw(int a, int r, int g, int b) { - Rect bounds = new Rect.fromLTRB(0.0, 0.0, view.width, view.height); + final double devicePixelRatio = view.devicePixelRatio; Size size = new Size(view.width, view.height); PictureRecorder recorder = new PictureRecorder(); - Canvas canvas = new Canvas(recorder, bounds); + Canvas canvas = new Canvas(recorder, new Rect.fromLTRB(0.0, 0.0, view.width * devicePixelRatio, view.height * devicePixelRatio)); + canvas.scale(devicePixelRatio, devicePixelRatio); double radius = size.shortestSide * 0.45; Paint paint = new Paint()..color = new Color.fromARGB(a, r, g, b); @@ -20,7 +21,7 @@ Picture draw(int a, int r, int g, int b) { paintingNode = new PaintingNode(); Paint innerPaint = new Paint()..color = new Color.fromARGB(a, 255 - r, 255 - g, 255 - b); PictureRecorder innerRecorder = new PictureRecorder(); - Canvas innerCanvas = new Canvas(innerRecorder, bounds); + Canvas innerCanvas = new Canvas(innerRecorder, Point.origin & bounds); innerCanvas.drawCircle(size.center(Point.origin), radius * 0.5, innerPaint); paintingNode.setBackingDrawable(innerRecorder.endRecordingAsDrawable()); diff --git a/examples/raw/shadow.dart b/examples/raw/shadow.dart index 5f44336c83..eb63c60aff 100644 --- a/examples/raw/shadow.dart +++ b/examples/raw/shadow.dart @@ -7,7 +7,9 @@ import 'dart:sky'; void beginFrame(double timeStamp) { double size = 100.0; PictureRecorder recorder = new PictureRecorder(); - Canvas canvas = new Canvas(recorder, new Rect.fromLTWH(0.0, 0.0, view.width, view.height)); + final double devicePixelRatio = view.devicePixelRatio; + Canvas canvas = new Canvas(recorder, new Rect.fromLTWH(0.0, 0.0, view.width * devicePixelRatio, view.height * devicePixelRatio)); + canvas.scale(devicePixelRatio, devicePixelRatio); canvas.translate(size + 10.0, size + 10.0); Paint paint = new Paint(); diff --git a/examples/raw/spinning_arabic.dart b/examples/raw/spinning_arabic.dart index 45ceeefeec..5fef68d5d4 100644 --- a/examples/raw/spinning_arabic.dart +++ b/examples/raw/spinning_arabic.dart @@ -13,7 +13,9 @@ void beginFrame(double timeStamp) { timeBase = timeStamp; double delta = timeStamp - timeBase; PictureRecorder recorder = new PictureRecorder(); - Canvas canvas = new Canvas(recorder, new Rect.fromLTWH(0.0, 0.0, view.width, view.height)); + final double devicePixelRatio = view.devicePixelRatio; + Canvas canvas = new Canvas(recorder, new Rect.fromLTWH(0.0, 0.0, view.width * devicePixelRatio, view.height * devicePixelRatio)); + canvas.scale(devicePixelRatio, devicePixelRatio); canvas.translate(view.width / 2.0, view.height / 2.0); canvas.rotate(math.PI * delta / 1800); canvas.drawRect(new Rect.fromLTRB(-100.0, -100.0, 100.0, 100.0), diff --git a/examples/raw/spinning_image.dart b/examples/raw/spinning_image.dart index 743f1a92d5..8e5267b8b5 100644 --- a/examples/raw/spinning_image.dart +++ b/examples/raw/spinning_image.dart @@ -18,7 +18,9 @@ void beginFrame(double timeStamp) { timeBase = timeStamp; double delta = timeStamp - timeBase; PictureRecorder recorder = new PictureRecorder(); - Canvas canvas = new Canvas(recorder, Point.origin & new Size(view.width, view.height)); + final double devicePixelRatio = view.devicePixelRatio; + Canvas canvas = new Canvas(recorder, Point.origin & new Size(view.width * devicePixelRatio, view.height * devicePixelRatio)); + cavnas.scale(devicePixelRatio, devicePixelRatio); canvas.translate(view.width / 2.0, view.height / 2.0); canvas.rotate(math.PI * delta / 1800); canvas.scale(0.2, 0.2); diff --git a/examples/raw/spinning_square.dart b/examples/raw/spinning_square.dart index bb461741b8..9119f3a390 100644 --- a/examples/raw/spinning_square.dart +++ b/examples/raw/spinning_square.dart @@ -13,7 +13,9 @@ void beginFrame(double timeStamp) { timeBase = timeStamp; double delta = timeStamp - timeBase; PictureRecorder recorder = new PictureRecorder(); - Canvas canvas = new Canvas(recorder, new Rect.fromLTWH(0.0, 0.0, view.width, view.height)); + final double devicePixelRatio = view.devicePixelRatio; + Canvas canvas = new Canvas(recorder, new Rect.fromLTWH(0.0, 0.0, view.width * devicePixelRatio, view.height * devicePixelRatio)); + canvas.scale(devicePixelRatio, devicePixelRatio); canvas.translate(view.width / 2.0, view.height / 2.0); canvas.rotate(math.PI * delta / 1800); canvas.drawRect(new Rect.fromLTRB(-100.0, -100.0, 100.0, 100.0), diff --git a/packages/flutter/lib/rendering/box.dart b/packages/flutter/lib/rendering/box.dart index 8f527b8b6b..d02966fbf5 100644 --- a/packages/flutter/lib/rendering/box.dart +++ b/packages/flutter/lib/rendering/box.dart @@ -1716,9 +1716,13 @@ class RenderView extends RenderObject with RenderObjectWithChildMixin void paintFrame() { sky.tracing.begin('RenderView.paintFrame'); try { + double devicePixelRatio = sky.view.devicePixelRatio; sky.PictureRecorder recorder = new sky.PictureRecorder(); - PaintingCanvas canvas = new PaintingCanvas(recorder, paintBounds); - canvas.drawPaintingNode(paintingNode, Point.origin); + Rect cullRect = Point.origin & (size * devicePixelRatio); + PaintingCanvas canvas = new PaintingCanvas(recorder, cullRect); + canvas.drawColor(const Color(0xFF000000), sky.TransferMode.src); + canvas.scale(devicePixelRatio, devicePixelRatio); + canvas.paintChild(child, Point.origin); sky.view.picture = recorder.endRecording(); } finally { sky.tracing.end('RenderView.paintFrame');