Decouple Canvas from DisplayList and map Picture and PictureRecorder more directly to their Skia counterparts.

Also changes the framework dart code to use the
refactored APIs and fixes the various examples and
tests.

R=abarth@chromium.org, ianh@chromium.org

Review URL: https://codereview.chromium.org/1190123003.
This commit is contained in:
Ian Fischer
2015-06-24 10:21:45 -07:00
parent 9b1985c237
commit 82d1eb2fdb
15 changed files with 54 additions and 45 deletions

View File

@@ -9,11 +9,12 @@ Picture draw(int a, int r, int g, int b) {
double width = view.width;
double height = view.height;
PictureRecorder recorder = new PictureRecorder(width, height);
PictureRecorder recorder = new PictureRecorder();
Canvas canvas = new Canvas(recorder, width, height);
double radius = min(width, height) * 0.45;
Paint paint = new Paint()..color = new Color.fromARGB(a, r, g, b);
recorder.drawCircle(width / 2, height / 2, radius, paint);
canvas.drawCircle(width / 2, height / 2, radius, paint);
return recorder.endRecording();
}

View File

@@ -12,11 +12,12 @@ Picture draw(int a, int r, int g, int b) {
double width = view.width;
double height = view.height;
PictureRecorder recorder = new PictureRecorder(width, height);
PictureRecorder recorder = new PictureRecorder();
Canvas canvas = new Canvas(recorder, width, height);
double radius = min(width, height) * 0.45;
Paint paint = new Paint()..color = new Color.fromARGB(a, r, g, b);
recorder.drawRect(new Rect.fromSize(new Size(width, height)), paint);
canvas.drawRect(new Rect.fromSize(new Size(width, height)), paint);
return recorder.endRecording();
}

View File

@@ -7,28 +7,29 @@ import 'dart:math' as math;
import 'dart:typed_data';
void beginFrame(double timeStamp) {
sky.PictureRecorder context = new sky.PictureRecorder(sky.view.width, 200.0);
sky.PictureRecorder recorder = new sky.PictureRecorder();
Canvas canvas = new Canvas(recorder, sky.view.width, 200.0);
sky.Paint paint = new sky.Paint();
sky.Point mid = new sky.Point(context.width / 2.0, context.height / 2.0);
sky.Point mid = new sky.Point(sky.view.width / 2.0, sky.view.height / 2.0);
double radius = math.min(mid.x, mid.y);
context.drawPaint(new sky.Paint()..color = const sky.Color(0xFFFFFFFF));
canvas.drawPaint(new sky.Paint()..color = const sky.Color(0xFFFFFFFF));
context.save();
canvas.save();
context.translate(-mid.x/2.0, context.height*2.0);
context.clipRect(
new sky.Rect.fromLTRB(0.0, -context.height, context.width, radius));
canvas.translate(-mid.x/2.0, sky.view.height*2.0);
canvas.clipRect(
new sky.Rect.fromLTRB(0.0, -sky.view.height, sky.view.width, radius));
context.translate(mid.x, mid.y);
canvas.translate(mid.x, mid.y);
paint.color = const sky.Color.fromARGB(128, 255, 0, 255);
context.rotate(math.PI/4.0);
canvas.rotate(math.PI/4.0);
sky.Gradient yellowBlue = new sky.Gradient.linear(
[new sky.Point(-radius, -radius), new sky.Point(0.0, 0.0)],
[const sky.Color(0xFFFFFF00), const sky.Color(0xFF0000FF)]);
context.drawRect(new sky.Rect.fromLTRB(-radius, -radius, radius, radius),
canvas.drawRect(new sky.Rect.fromLTRB(-radius, -radius, radius, radius),
new sky.Paint()..setShader(yellowBlue));
// Scale x and y by 0.5.
@@ -38,13 +39,13 @@ void beginFrame(double timeStamp) {
0.0, 0.0, 0.0, 0.0,
0.0, 0.0, 0.0, 1.0,
]);
context.concat(scaleMatrix);
canvas.concat(scaleMatrix);
paint.color = const sky.Color.fromARGB(128, 0, 255, 0);
context.drawCircle(0.0, 0.0, radius, paint);
canvas.drawCircle(0.0, 0.0, radius, paint);
context.restore();
canvas.restore();
context.translate(0.0, 50.0);
canvas.translate(0.0, 50.0);
var builder = new sky.LayerDrawLooperBuilder()
..addLayerOnTop(
new sky.DrawLooperLayerInfo()
@@ -80,9 +81,9 @@ void beginFrame(double timeStamp) {
layerPaint.color = const sky.Color.fromARGB(128, 255, 0, 0);
});
paint.setDrawLooper(builder.build());
context.drawCircle(0.0, 0.0, radius, paint);
canvas.drawCircle(0.0, 0.0, radius, paint);
sky.view.picture = context.endRecording();
sky.view.picture = recorder.endRecording();
}
void main() {

View File

@@ -6,7 +6,8 @@ import 'dart:sky';
void beginFrame(double timeStamp) {
var size = 100.0;
PictureRecorder canvas = new PictureRecorder(view.width, view.height);
PictureRecorder recorder = new PictureRecorder();
Canvas canvas = new Canvas(recorder, view.width, view.height);
canvas.translate(size + 10.0, size + 10.0);
Paint paint = new Paint();
@@ -30,7 +31,7 @@ void beginFrame(double timeStamp) {
canvas.drawPaint(
new Paint()..color = const Color.fromARGB(255, 255, 255, 255));
canvas.drawRect(new Rect.fromLTRB(-size, -size, size, size), paint);
view.picture = canvas.endRecording();
view.picture = recorder.endRecording();
}
void main() {

View File

@@ -12,7 +12,8 @@ void beginFrame(double timeStamp) {
if (timeBase == null)
timeBase = timeStamp;
double delta = timeStamp - timeBase;
PictureRecorder canvas = new PictureRecorder(view.width, view.height);
PictureRecorder recorder = new PictureRecorder();
Canvas canvas = new Canvas(recorder, view.width, view.height);
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),
@@ -25,7 +26,7 @@ void beginFrame(double timeStamp) {
canvas.translate(layoutRoot.maxWidth / -2.0, (layoutRoot.maxWidth / 2.0) - 125);
layoutRoot.paint(canvas);
view.picture = canvas.endRecording();
view.picture = recorder.endRecording();
view.scheduleFrame();
}

View File

@@ -4,6 +4,7 @@
import 'dart:math' as math;
import 'dart:sky';
import 'package:sky/mojo/net/image_cache.dart' as image_cache;
double timeBase = null;
@@ -15,7 +16,8 @@ String url2 = "http://i2.kym-cdn.com/photos/images/facebook/000/581/296/c09.jpg"
void beginFrame(double timeStamp) {
if (timeBase == null) timeBase = timeStamp;
double delta = timeStamp - timeBase;
PictureRecorder canvas = new PictureRecorder(view.width, view.height);
PictureRecorder recorder = new PictureRecorder();
Canvas canvas = new Canvas(recorder, view.width, view.height);
canvas.translate(view.width / 2.0, view.height / 2.0);
canvas.rotate(math.PI * delta / 1800);
canvas.scale(0.2, 0.2);
@@ -36,7 +38,7 @@ void beginFrame(double timeStamp) {
paint);
}
view.picture = canvas.endRecording();
view.picture = recorder.endRecording();
view.scheduleFrame();
}

View File

@@ -12,12 +12,13 @@ void beginFrame(double timeStamp) {
if (timeBase == null)
timeBase = timeStamp;
double delta = timeStamp - timeBase;
PictureRecorder canvas = new PictureRecorder(view.width, view.height);
PictureRecorder recorder = new PictureRecorder();
Canvas canvas = new Canvas(recorder, view.width, view.height);
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),
new Paint()..color = const Color.fromARGB(255, 0, 255, 0));
view.picture = canvas.endRecording();
view.picture = recorder.endRecording();
view.scheduleFrame();
tracing.end('beginFrame');
}