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

Side by Side Diff: samples/openglui/src/openglui_canvas_tests.dart

Issue 12506004: Added window.requestAnimationFrame. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 9 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « samples/openglui/android/android.gyp ('k') | samples/openglui/src/openglui_raytrace.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 // 4 //
5 // Canvas API tests. Some of these are adapted from: 5 // Canvas API tests. Some of these are adapted from:
6 // 6 //
7 // http://www.html5canvastutorials.com/ 7 // http://www.html5canvastutorials.com/
8 8
9 library openglui_canvas_tests; 9 library openglui_canvas_tests;
10 10
(...skipping 25 matching lines...) Expand all
36 }); 36 });
37 canvas.onKeyDown.listen((e) { 37 canvas.onKeyDown.listen((e) {
38 ++testnum; 38 ++testnum;
39 isDirty = true; 39 isDirty = true;
40 }); 40 });
41 ctx = canvas.getContext("2d"); 41 ctx = canvas.getContext("2d");
42 if (ctx == null) { 42 if (ctx == null) {
43 throw "Failed to get 2D context"; 43 throw "Failed to get 2D context";
44 } 44 }
45 resize(w, h); 45 resize(w, h);
46 window.requestAnimationFrame(update);
46 log("Done setup"); 47 log("Done setup");
47 } 48 }
48 49
49 resetCanvas() { 50 resetCanvas() {
50 ctx.globalCompositeOperation = "source-over"; 51 ctx.globalCompositeOperation = "source-over";
51 ctx.setTransform(1, 0, 0, 1, 0, 0); 52 ctx.setTransform(1, 0, 0, 1, 0, 0);
52 ctx.fillStyle = "#FFFFFF"; 53 ctx.fillStyle = "#FFFFFF";
53 ctx.clearRect(0, 0, width, height); 54 ctx.clearRect(0, 0, width, height);
54 ctx.shadowOffsetX = ctx.shadowOffsetY = ctx.shadowBlur = 0.0; 55 ctx.shadowOffsetX = ctx.shadowOffsetY = ctx.shadowBlur = 0.0;
55 ctx.beginPath(); 56 ctx.beginPath();
(...skipping 436 matching lines...) Expand 10 before | Expand all | Expand 10 after
492 ctx.setLineDash([]); 493 ctx.setLineDash([]);
493 ctx.strokeStyle = "#0000FF"; 494 ctx.strokeStyle = "#0000FF";
494 ctx.strokeStyle = "rgba(128,128,128, 0.5)"; 495 ctx.strokeStyle = "rgba(128,128,128, 0.5)";
495 ctx.strokeRect(width / 5, height / 10, width / 2, height / 8); 496 ctx.strokeRect(width / 5, height / 10, width / 2, height / 8);
496 log("Width = $width"); 497 log("Width = $width");
497 } 498 }
498 499
499 void loadImage() { 500 void loadImage() {
500 initTest("Image loading"); 501 initTest("Image loading");
501 var imageObj = new ImageElement(); 502 var imageObj = new ImageElement();
503 // TODO(Gram): Change gl.dart to handle to onLoad.listen.
502 imageObj.on.load.add((e) { 504 imageObj.on.load.add((e) {
503 ctx.drawImage(e, 69, 50); 505 ctx.drawImage(e, 69, 50);
504 }); 506 });
505 imageObj.src = 'chrome.png'; 507 imageObj.src = 'chrome.png';
506 } 508 }
507 509
508 void clip() { 510 void clip() {
509 initTest("Clipping"); 511 initTest("Clipping");
510 var x = width / 2; 512 var x = width / 2;
511 var y = height / 2; 513 var y = height / 2;
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
648 ctx.rect(myRectangle.x, myRectangle.y, myRectangle.width, myRectangle.height); 650 ctx.rect(myRectangle.x, myRectangle.y, myRectangle.width, myRectangle.height);
649 ctx.fillStyle = '#8ED6FF'; 651 ctx.fillStyle = '#8ED6FF';
650 ctx.fill(); 652 ctx.fill();
651 ctx.lineWidth = myRectangle.borderWidth; 653 ctx.lineWidth = myRectangle.borderWidth;
652 ctx.strokeStyle = 'black'; 654 ctx.strokeStyle = 'black';
653 ctx.stroke(); 655 ctx.stroke();
654 } 656 }
655 657
656 int testnum = 0; // Set this to -1 to start with last test. 658 int testnum = 0; // Set this to -1 to start with last test.
657 659
658 void update() { 660 void update(num when) {
661 window.requestAnimationFrame(update);
659 if (testnum == 0) { 662 if (testnum == 0) {
660 anim(); 663 anim();
661 return; 664 return;
662 } 665 }
663 if (!isDirty) return; 666 if (!isDirty) return;
664 switch(testnum) { 667 switch(testnum) {
665 case 1: 668 case 1:
666 helloWorld(); 669 helloWorld();
667 break; 670 break;
668 case 2: 671 case 2:
(...skipping 327 matching lines...) Expand 10 before | Expand all | Expand 10 after
996 for (int x = 0; x < screenWidth; x++) { 999 for (int x = 0; x < screenWidth; x++) {
997 var color = _traceRay(new Ray(scene.camera.pos, 1000 var color = _traceRay(new Ray(scene.camera.pos,
998 getPoint(x, y, scene.camera) ), scene, 0); 1001 getPoint(x, y, scene.camera) ), scene, 0);
999 ctx.fillStyle = Color.toDrawingRGB(color); 1002 ctx.fillStyle = Color.toDrawingRGB(color);
1000 ctx.fillRect(x, y, x + 1, y + 1); 1003 ctx.fillRect(x, y, x + 1, y + 1);
1001 } 1004 }
1002 } 1005 }
1003 } 1006 }
1004 } 1007 }
1005 1008
1006
1007
1008
OLDNEW
« no previous file with comments | « samples/openglui/android/android.gyp ('k') | samples/openglui/src/openglui_raytrace.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698