Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(60)

Unified Diff: experimental/SkV8Example/gears.js

Issue 183883017: Start prototyping what DisplayList support will look like. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: experimental/SkV8Example/gears.js
diff --git a/experimental/SkV8Example/gears.js b/experimental/SkV8Example/gears.js
index 1c5a272e4f40a73725a20b838ff5de6cfabf003f..a901f9d9211e927df000e4385ff33e5838155805 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]
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698