Commit c59f418f authored by Adam Barth's avatar Adam Barth

Merge pull request #530 from abarth/move_scale

Simplify SkPicture
parents b2de6696 e3d9ea67
...@@ -47,7 +47,9 @@ void drawText(sky.Canvas canvas, String lh) { ...@@ -47,7 +47,9 @@ void drawText(sky.Canvas canvas, String lh) {
void main() { void main() {
// prepare the rendering // prepare the rendering
sky.PictureRecorder recorder = new sky.PictureRecorder(); 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 // background
sky.Paint paint = new sky.Paint(); sky.Paint paint = new sky.Paint();
......
...@@ -8,7 +8,9 @@ Picture draw(int a, int r, int g, int b) { ...@@ -8,7 +8,9 @@ Picture draw(int a, int r, int g, int b) {
Size size = new Size(view.width, view.height); Size size = new Size(view.width, view.height);
PictureRecorder recorder = new PictureRecorder(); 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; double radius = size.shortestSide * 0.45;
Paint paint = new Paint()..color = new Color.fromARGB(a, r, g, b); Paint paint = new Paint()..color = new Color.fromARGB(a, r, g, b);
......
...@@ -202,7 +202,9 @@ void doFrame(double timeStamp) { ...@@ -202,7 +202,9 @@ void doFrame(double timeStamp) {
// draw the result // draw the result
report("recording..."); report("recording...");
sky.PictureRecorder recorder = new sky.PictureRecorder(); 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.maxWidth = sky.view.width;
layoutRoot.layout(); layoutRoot.layout();
layoutRoot.paint(canvas); layoutRoot.paint(canvas);
......
...@@ -9,7 +9,9 @@ import 'dart:typed_data'; ...@@ -9,7 +9,9 @@ import 'dart:typed_data';
void beginFrame(double timeStamp) { void beginFrame(double timeStamp) {
sky.Size size = new sky.Size(sky.view.width, sky.view.height); sky.Size size = new sky.Size(sky.view.width, sky.view.height);
sky.PictureRecorder recorder = new sky.PictureRecorder(); 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.Paint paint = new sky.Paint();
sky.Point mid = size.center(sky.Point.origin); sky.Point mid = size.center(sky.Point.origin);
......
...@@ -6,11 +6,12 @@ import 'dart:sky'; ...@@ -6,11 +6,12 @@ import 'dart:sky';
PaintingNode paintingNode = null; PaintingNode paintingNode = null;
Picture draw(int a, int r, int g, int b) { 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); Size size = new Size(view.width, view.height);
PictureRecorder recorder = new PictureRecorder(); 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; double radius = size.shortestSide * 0.45;
Paint paint = new Paint()..color = new Color.fromARGB(a, r, g, b); 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) { ...@@ -20,7 +21,7 @@ Picture draw(int a, int r, int g, int b) {
paintingNode = new PaintingNode(); paintingNode = new PaintingNode();
Paint innerPaint = new Paint()..color = new Color.fromARGB(a, 255 - r, 255 - g, 255 - b); Paint innerPaint = new Paint()..color = new Color.fromARGB(a, 255 - r, 255 - g, 255 - b);
PictureRecorder innerRecorder = new PictureRecorder(); 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); innerCanvas.drawCircle(size.center(Point.origin), radius * 0.5, innerPaint);
paintingNode.setBackingDrawable(innerRecorder.endRecordingAsDrawable()); paintingNode.setBackingDrawable(innerRecorder.endRecordingAsDrawable());
......
...@@ -7,7 +7,9 @@ import 'dart:sky'; ...@@ -7,7 +7,9 @@ import 'dart:sky';
void beginFrame(double timeStamp) { void beginFrame(double timeStamp) {
double size = 100.0; double size = 100.0;
PictureRecorder recorder = new PictureRecorder(); 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); canvas.translate(size + 10.0, size + 10.0);
Paint paint = new Paint(); Paint paint = new Paint();
......
...@@ -13,7 +13,9 @@ void beginFrame(double timeStamp) { ...@@ -13,7 +13,9 @@ void beginFrame(double timeStamp) {
timeBase = timeStamp; timeBase = timeStamp;
double delta = timeStamp - timeBase; double delta = timeStamp - timeBase;
PictureRecorder recorder = new PictureRecorder(); 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.translate(view.width / 2.0, view.height / 2.0);
canvas.rotate(math.PI * delta / 1800); canvas.rotate(math.PI * delta / 1800);
canvas.drawRect(new Rect.fromLTRB(-100.0, -100.0, 100.0, 100.0), canvas.drawRect(new Rect.fromLTRB(-100.0, -100.0, 100.0, 100.0),
......
...@@ -18,7 +18,9 @@ void beginFrame(double timeStamp) { ...@@ -18,7 +18,9 @@ void beginFrame(double timeStamp) {
timeBase = timeStamp; timeBase = timeStamp;
double delta = timeStamp - timeBase; double delta = timeStamp - timeBase;
PictureRecorder recorder = new PictureRecorder(); 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.translate(view.width / 2.0, view.height / 2.0);
canvas.rotate(math.PI * delta / 1800); canvas.rotate(math.PI * delta / 1800);
canvas.scale(0.2, 0.2); canvas.scale(0.2, 0.2);
......
...@@ -13,7 +13,9 @@ void beginFrame(double timeStamp) { ...@@ -13,7 +13,9 @@ void beginFrame(double timeStamp) {
timeBase = timeStamp; timeBase = timeStamp;
double delta = timeStamp - timeBase; double delta = timeStamp - timeBase;
PictureRecorder recorder = new PictureRecorder(); 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.translate(view.width / 2.0, view.height / 2.0);
canvas.rotate(math.PI * delta / 1800); canvas.rotate(math.PI * delta / 1800);
canvas.drawRect(new Rect.fromLTRB(-100.0, -100.0, 100.0, 100.0), canvas.drawRect(new Rect.fromLTRB(-100.0, -100.0, 100.0, 100.0),
......
...@@ -1716,9 +1716,13 @@ class RenderView extends RenderObject with RenderObjectWithChildMixin<RenderBox> ...@@ -1716,9 +1716,13 @@ class RenderView extends RenderObject with RenderObjectWithChildMixin<RenderBox>
void paintFrame() { void paintFrame() {
sky.tracing.begin('RenderView.paintFrame'); sky.tracing.begin('RenderView.paintFrame');
try { try {
double devicePixelRatio = sky.view.devicePixelRatio;
sky.PictureRecorder recorder = new sky.PictureRecorder(); sky.PictureRecorder recorder = new sky.PictureRecorder();
PaintingCanvas canvas = new PaintingCanvas(recorder, paintBounds); Rect cullRect = Point.origin & (size * devicePixelRatio);
canvas.drawPaintingNode(paintingNode, Point.origin); 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(); sky.view.picture = recorder.endRecording();
} finally { } finally {
sky.tracing.end('RenderView.paintFrame'); sky.tracing.end('RenderView.paintFrame');
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment