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) {
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();
......
......@@ -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);
......
......@@ -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);
......
......@@ -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);
......
......@@ -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());
......
......@@ -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();
......
......@@ -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),
......
......@@ -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);
......
......@@ -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),
......
......@@ -1716,9 +1716,13 @@ class RenderView extends RenderObject with RenderObjectWithChildMixin<RenderBox>
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');
......
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