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

Side by Side Diff: runtime/embedders/openglui/common/gl.dart

Issue 12212074: Support for non-DOM canvases/contexts (backed by bitaps). (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 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 unified diff | Download patch | Annotate | Revision Log
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 library android_extension; 5 library android_extension;
6 6
7 class CanvasElement { 7 class CanvasElement {
8 int _height; 8 int _height;
9 int _width; 9 int _width;
10 10
11 get height => _height; 11 get height => _height;
12 get width => _width; 12 get width => _width;
13 13
14 CanvasRenderingContext2D _context2d; 14 CanvasRenderingContext2D _context2d;
15 WebGLRenderingContext _context3d; 15 WebGLRenderingContext _context3d;
16 16
17 // For use with drawImage, we want to support a src property
18 // like ImageElement, which maps to the context handle in native
19 // code.
20 get src => "context2d://${_context2d.handle}";
21
17 CanvasElement({int width, int height}) { 22 CanvasElement({int width, int height}) {
18 _width = (width == null) ? getDeviceScreenWidth() : width; 23 _width = (width == null) ? getDeviceScreenWidth() : width;
19 _height = (height == null) ? getDeviceScreenHeight() : height; 24 _height = (height == null) ? getDeviceScreenHeight() : height;
20 } 25 }
21 26
22 CanvasRenderingContext getContext(String contextId) { 27 CanvasRenderingContext getContext(String contextId) {
23 if (contextId == "2d") { 28 if (contextId == "2d") {
24 if (_context2d == null) { 29 if (_context2d == null) {
25 _context2d = new CanvasRenderingContext2D(this, _width, _height); 30 _context2d = new CanvasRenderingContext2D(this, _width, _height);
26 } 31 }
(...skipping 362 matching lines...) Expand 10 before | Expand all | Expand 10 after
389 final num width; 394 final num width;
390 TextMetrics(this.width); 395 TextMetrics(this.width);
391 } 396 }
392 397
393 class CanvasRenderingContext2D extends CanvasRenderingContext { 398 class CanvasRenderingContext2D extends CanvasRenderingContext {
394 // TODO(gram): We need to support multiple contexts, for cached content 399 // TODO(gram): We need to support multiple contexts, for cached content
395 // prerendered to an offscreen buffer. For this we will use handles, with 400 // prerendered to an offscreen buffer. For this we will use handles, with
396 // handle 0 being the physical display. 401 // handle 0 being the physical display.
397 static int _next_handle = 0; 402 static int _next_handle = 0;
398 int _handle = 0; 403 int _handle = 0;
404 get handle => _handle;
399 405
400 int _width, _height; 406 int _width, _height;
401 set width(int w) { _width = C2DSetWidth(_handle, w); } 407 set width(int w) { _width = C2DSetWidth(_handle, w); }
402 get width => _width; 408 get width => _width;
403 set height(int h) { _height = C2DSetHeight(_handle, h); } 409 set height(int h) { _height = C2DSetHeight(_handle, h); }
404 get height => _height; 410 get height => _height;
405 411
406 CanvasRenderingContext2D(canvas, width, height) : super(canvas) { 412 CanvasRenderingContext2D(canvas, width, height) : super(canvas) {
407 _width = width; 413 _width = width;
408 _height = height; 414 _height = height;
409 C2DCreateNativeContext(_handle = _next_handle++, width, height); 415 C2DCreateNativeContext(_handle = _next_handle++, width, height);
410 } 416 }
411 417
412 double _alpha = 1.0; 418 double _alpha = 1.0;
413 set globalAlpha(numa) { 419 set globalAlpha(num a) {
414 _alpha = C2DSetGlobalAlpha(_handle, a.toDouble()); 420 _alpha = C2DSetGlobalAlpha(_handle, a.toDouble());
415 } 421 }
416 get globalAlpha => _alpha; 422 get globalAlpha => _alpha;
417 423
418 // TODO(gram): make sure we support compound assignments like: 424 // TODO(gram): make sure we support compound assignments like:
419 // fillStyle = strokeStyle = "red" 425 // fillStyle = strokeStyle = "red"
420 var _fillStyle = "#000"; 426 var _fillStyle = "#000";
421 set fillStyle(fs) { 427 set fillStyle(fs) {
422 C2DSetFillStyle(_handle, _fillStyle = fs); 428 C2DSetFillStyle(_handle, _fillStyle = fs);
423 } 429 }
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
567 } 573 }
568 574
569 CanvasPattern createPattern(canvas_OR_image, String repetitionType) { 575 CanvasPattern createPattern(canvas_OR_image, String repetitionType) {
570 throw new Exception('Unimplemented createPattern'); 576 throw new Exception('Unimplemented createPattern');
571 } 577 }
572 578
573 CanvasGradient createRadialGradient(num x0, num y0, num x1, num y1, num r1) { 579 CanvasGradient createRadialGradient(num x0, num y0, num x1, num y1, num r1) {
574 throw new Exception('Unimplemented createRadialGradient'); 580 throw new Exception('Unimplemented createRadialGradient');
575 } 581 }
576 582
577 void drawImage(ImageElement image, num x1, num y1, 583 void drawImage(element, num x1, num y1,
578 [num w1, num h1, num x2, num y2, num w2, num h2]) { 584 [num w1, num h1, num x2, num y2, num w2, num h2]) {
579 var w = (image.width == null) ? 0 : image.width; 585 var w = (element.width == null) ? 0 : element.width;
580 var h = (image.height == null) ? 0 : image.height; 586 var h = (element.height == null) ? 0 : element.height;
581 if (!?w1) { // drawImage(image, dx, dy) 587 if (!?w1) { // drawImage(element, dx, dy)
582 C2DDrawImage(_handle, image.src, 0, 0, false, w, h, 588 C2DDrawImage(_handle, element.src.toString(), 0, 0, false, w, h,
vsm 2013/02/08 22:11:06 isn't element.src already a String?
gram 2013/02/09 01:37:39 Just playing safe.... but I'll remove it.
583 x1.toInt(), y1.toInt(), false, 0, 0); 589 x1.toInt(), y1.toInt(), false, 0, 0);
584 } else if (!?x2) { // drawImage(image, dx, dy, dw, dh) 590 } else if (!?x2) { // drawImage(element, dx, dy, dw, dh)
585 C2DDrawImage(_handle, image.src, 0, 0, false, w, h, 591 C2DDrawImage(_handle, element.src.toString(), 0, 0, false, w, h,
586 x1.toInt(), y1.toInt(), true, w1.toInt(), h1.toInt()); 592 x1.toInt(), y1.toInt(), true, w1.toInt(), h1.toInt());
587 } else { // drawImage(image, sx, sy, sw, sh, dx, dy, dw, dh) 593 } else { // drawImage(image, sx, sy, sw, sh, dx, dy, dw, dh)
588 C2DDrawImage(_handle, image.src, 594 C2DDrawImage(_handle, element.src.toString(),
589 x1.toInt(), y1.toInt(), true, w1.toInt(), h1.toInt(), 595 x1.toInt(), y1.toInt(), true, w1.toInt(), h1.toInt(),
590 x2.toInt(), y2.toInt(), true, w2.toInt(), h2.toInt()); 596 x2.toInt(), y2.toInt(), true, w2.toInt(), h2.toInt());
591 } 597 }
592 } 598 }
593 599
594 void fill() => C2DFill(_handle); 600 void fill() => C2DFill(_handle);
595 601
596 void fillRect(num x, num y, num w, num h) => 602 void fillRect(num x, num y, num w, num h) =>
597 C2DFillRect(_handle, x.toDouble(), y.toDouble(), 603 C2DFillRect(_handle, x.toDouble(), y.toDouble(),
598 w.toDouble(), h.toDouble()); 604 w.toDouble(), h.toDouble());
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
726 num dirtyWidth, num dirtyHeight]) { 732 num dirtyWidth, num dirtyHeight]) {
727 throw new Exception('Unimplemented webkitGetImageDataHD'); 733 throw new Exception('Unimplemented webkitGetImageDataHD');
728 } 734 }
729 735
730 // TODO(vsm): Kill. 736 // TODO(vsm): Kill.
731 noSuchMethod(invocation) { 737 noSuchMethod(invocation) {
732 throw new Exception('Unimplemented/unknown ${invocation.memberName}'); 738 throw new Exception('Unimplemented/unknown ${invocation.memberName}');
733 } 739 }
734 } 740 }
735 741
OLDNEW
« no previous file with comments | « runtime/embedders/openglui/common/extension.cc ('k') | runtime/embedders/openglui/common/graphics_handler.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698