diff options
author | commit-bot@chromium.org <commit-bot@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2014-03-04 19:05:50 +0000 |
---|---|---|
committer | commit-bot@chromium.org <commit-bot@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2014-03-04 19:05:50 +0000 |
commit | cb336874e468d5a2cb9e6287a3388fdd7a66dc1f (patch) | |
tree | 04e54d140edb3f90d8cbcb860efa4d0dbc5f6cdf /experimental | |
parent | e09244d463695cd9d2b089794ca18f59f1e4a621 (diff) |
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
Diffstat (limited to 'experimental')
-rw-r--r-- | experimental/SkV8Example/gears.js | 45 |
1 files changed, 43 insertions, 2 deletions
diff --git a/experimental/SkV8Example/gears.js b/experimental/SkV8Example/gears.js index 1c5a272e4f..a901f9d921 100644 --- a/experimental/SkV8Example/gears.js +++ b/experimental/SkV8Example/gears.js @@ -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); - strokeGear(ctx, gear); + if (HAS_DISPLAY_LIST) { + ctx.draw(gear.gearStroke); + } else { + strokeGear(ctx, gear); + } + } + if (HAS_DISPLAY_LIST) { + ctx.draw(gear.gearFill); + } else { + fillGear(ctx, gear); } - 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] |