Start prototyping what DisplayList support will look like.

None of the new codepaths get executed yet since DisplayList doesn't exist, but that will happening in the new few CLs.

BUG=skia:
R=robertphillips@google.com

Author: jcgregorio@google.com

Review URL: https://codereview.chromium.org/183883017

git-svn-id: http://skia.googlecode.com/svn/trunk@13657 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
commit-bot@chromium.org 2014-03-04 19:05:50 +00:00
parent e09244d463
commit cb336874e4

View File

@ -1,5 +1,6 @@
var IS_SKV8 = typeof document == "undefined";
var HAS_PATH = typeof Path2D != "undefined";
var HAS_DISPLAY_LIST = typeof DisplayList != "undefined";
var NumTeeth = 24;
var NumGears = 60;
@ -32,6 +33,36 @@ function gearPath(r) {
}
}
function gearDisplayListStroke(r, color) {
if (HAS_DISPLAY_LIST) {
p = new Path2D();
makeGear(p, r)
p.closePath();
var dl = new DisplayList();
dl.strokeStyle = color;
dl.stroke(p);
dl.finalize()
return dl;
} else {
return null;
}
}
function gearDisplayListFill(r, color) {
if (HAS_DISPLAY_LIST) {
p = new Path2D();
makeGear(p, r)
p.closePath();
var dl = new DisplayList();
dl.fillStyle = color;
dl.fill(p);
dl.finalize()
return dl;
} else {
return null;
}
}
function strokeGear(ctx, gear) {
if (HAS_PATH) {
ctx.stroke(gear.path);
@ -63,9 +94,17 @@ function draw3DGear(ctx, angle, gear) {
ctx.rotate(-angle);
ctx.translate(0.707, 0.707);
ctx.rotate(angle);
if (HAS_DISPLAY_LIST) {
ctx.draw(gear.gearStroke);
} else {
strokeGear(ctx, gear);
}
}
if (HAS_DISPLAY_LIST) {
ctx.draw(gear.gearFill);
} else {
fillGear(ctx, gear);
}
ctx.rotate(-angle);
}
@ -88,6 +127,8 @@ var onDraw = function() {
x: Math.random()*500,
y: Math.random()*500,
path: gearPath(r),
gearFill: gearDisplayListFill(r, FaceColors[color]),
gearStroke: gearDisplayListStroke(r, SideColors[color]),
r: r,
faceColor: FaceColors[color],
sideColor: SideColors[color]