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

Unified Diff: sdk/lib/html/dartium/html_dartium.dart

Side-by-side diff isn't available for this file because of its large size.
Issue 12774014: Update drawImage to create more fast paths. (Closed) Base URL: https://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:
Download patch
« no previous file with comments | « sdk/lib/html/dart2js/html_dart2js.dart ('k') | tests/html/canvasrenderingcontext2d_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sdk/lib/html/dartium/html_dartium.dart
diff --git a/sdk/lib/html/dartium/html_dartium.dart b/sdk/lib/html/dartium/html_dartium.dart
index 9e74e4fa9d4b08c067295a9f561c995a7a139356..cdd2585fca71336f4a3b6227060bead4d6888603 100644
--- a/sdk/lib/html/dartium/html_dartium.dart
+++ b/sdk/lib/html/dartium/html_dartium.dart
@@ -1882,11 +1882,73 @@ class CanvasRenderingContext2D extends CanvasRenderingContext {
}
/**
+ * Draws an image from a CanvasImageSource to an area of this canvas.
+ *
+ * The image will be drawn to an area of this canvas defined by
+ * [destRect]. [sourceRect] defines the region of the source image that is
+ * drawn.
+ * If [sourceRect] is not provided, then
+ * the entire rectangular image from [source] will be drawn to this context.
+ *
+ * If the image is larger than canvas
+ * will allow, the image will be clipped to fit the available space.
+ *
+ * CanvasElement canvas = new CanvasElement(width: 600, height: 600);
+ * CanvasRenderingContext2D ctx = canvas.context2d;
+ * ImageElement img = document.query('img');
+ * img.width = 100;
+ * img.height = 100;
+ *
+ * // Scale the image to 20x20.
+ * ctx.drawImageToRect(img, new Rect(50, 50, 20, 20));
+ *
+ * VideoElement video = document.query('video');
+ * video.width = 100;
+ * video.height = 100;
+ * // Take the middle 20x20 pixels from the video and stretch them.
+ * ctx.drawImageToRect(video, new Rect(50, 50, 100, 100),
+ * sourceRect: new Rect(40, 40, 20, 20));
+ *
+ * // Draw the top 100x20 pixels from the otherCanvas.
+ * CanvasElement otherCanvas = document.query('canvas');
+ * ctx.drawImageToRect(otherCanvas, new Rect(0, 0, 100, 20),
+ * sourceRect: new Rect(0, 0, 100, 20));
+ *
+ * See also:
+ *
+ * * [CanvasImageSource] for more information on what data is retrieved
+ * from [source].
+ * * [drawImage](http://www.whatwg.org/specs/web-apps/current-work/multipage/the-canvas-element.html#dom-context-2d-drawimage)
+ * from the WHATWG.
+ */
+ @DomName('CanvasRenderingContext2D.drawImage')
+ void drawImageToRect(CanvasImageSource source, Rect destRect,
+ {Rect sourceRect}) {
+ if (sourceRect == null) {
+ $dom_drawImage(source,
+ destRect.left,
+ destRect.top,
+ destRect.width,
+ destRect.height);
+ } else {
+ $dom_drawImage(source,
+ sourceRect.left,
+ sourceRect.top,
+ sourceRect.width,
+ sourceRect.height,
+ destRect.left,
+ destRect.top,
+ destRect.width,
+ destRect.height);
+ }
+ }
+
+ /**
* Draws an image from a CanvasImageSource to this canvas.
*
* The entire image from [source] will be drawn to this context with its top
- * left corner at the point ([destinationX], [destinationY]). If the image is
- * larger than canvas will allow, the image will be cropped to fit the
+ * left corner at the point ([destX], [destY]). If the image is
+ * larger than canvas will allow, the image will be clipped to fit the
* available space.
*
* CanvasElement canvas = new CanvasElement(width: 600, height: 600);
@@ -1901,7 +1963,7 @@ class CanvasRenderingContext2D extends CanvasRenderingContext {
* CanvasElement otherCanvas = document.query('canvas');
* otherCanvas.width = 100;
* otherCanvas.height = 100;
- * ctx.drawImage(otherCanvas, 590, 590); // will get cropped
+ * ctx.drawImage(otherCanvas, 590, 590); // will get clipped
*
* See also:
*
@@ -1911,20 +1973,19 @@ class CanvasRenderingContext2D extends CanvasRenderingContext {
* from the WHATWG.
*/
@DomName('CanvasRenderingContext2D.drawImage')
- void drawImage(CanvasImageSource source, num destinationX, num destinationY) {
- $dom_drawImage(source, destinationX, destinationY);
+ void drawImage(CanvasImageSource source, num destX, num destY) {
+ $dom_drawImage(source, destX, destY);
}
/**
* Draws an image from a CanvasImageSource to an area of this canvas.
*
- * The image will be drawn to an area of this canvas defined by
- * [destinationRect]. If [sourceRect] is not provided, then
- * the entire rectangular image from [source] will be drawn to this context.
- * If the dimensions of [source] or [sourceRect]
- * differ from [destinationRect], then the image will be scaled to fit.
+ * The image will be drawn to this context with its top left corner at the
+ * point ([destX], [destY]) and will be scaled to be [destWidth] wide and
+ * [destHeight] tall.
+ *
* If the image is larger than canvas
- * will allow, the image will be cropped to fit the available space.
+ * will allow, the image will be clipped to fit the available space.
*
* CanvasElement canvas = new CanvasElement(width: 600, height: 600);
* CanvasRenderingContext2D ctx = canvas.context2d;
@@ -1932,20 +1993,43 @@ class CanvasRenderingContext2D extends CanvasRenderingContext {
* img.width = 100;
* img.height = 100;
*
- * // Scale the image to 20x20.
- * ctx.drawImageAtScale(img, new Rect(50, 50, 20, 20));
+ * // Scale the image to 300x50 at the point (20, 20)
+ * ctx.drawImageScaled(img, 20, 20, 300, 50);
+ *
+ * See also:
+ *
+ * * [CanvasImageSource] for more information on what data is retrieved
+ * from [source].
+ * * [drawImage](http://www.whatwg.org/specs/web-apps/current-work/multipage/the-canvas-element.html#dom-context-2d-drawimage)
+ * from the WHATWG.
+ */
+ @DomName('CanvasRenderingContext2D.drawImage')
+ void drawImageScaled(CanvasImageSource source,
+ num destX, num destY, num destWidth, num destHeight) {
+ $dom_drawImage(source, destX, destY, destWidth, destHeight);
+ }
+
+ /**
+ * Draws an image from a CanvasImageSource to an area of this canvas.
+ *
+ * The image is a region of [source] that is [sourceWidth] wide and
+ * [destHeight] tall with top left corner at ([sourceX], [sourceY]).
+ * The image will be drawn to this context with its top left corner at the
+ * point ([destX], [destY]) and will be scaled to be [destWidth] wide and
+ * [destHeight] tall.
+ *
+ * If the image is larger than canvas
+ * will allow, the image will be clipped to fit the available space.
*
* VideoElement video = document.query('video');
* video.width = 100;
* video.height = 100;
* // Take the middle 20x20 pixels from the video and stretch them.
- * ctx.drawImageAtScale(video, new Rect(50, 50, 100, 100),
- * sourceRect: new Rect(40, 40, 20, 20));
+ * ctx.drawImageScaledFromSource(video, 40, 40, 20, 20, 50, 50, 100, 100);
*
- * // Draw the top 100x20 pixels from the otherCanvas.
+ * // Draw the top 100x20 pixels from the otherCanvas to this one.
* CanvasElement otherCanvas = document.query('canvas');
- * ctx.drawImageAtScale(otherCanvas, new Rect(0, 0, 100, 20),
- * sourceRect: new Rect(0, 0, 100, 20));
+ * ctx.drawImageScaledFromSource(otherCanvas, 0, 0, 100, 20, 0, 0, 100, 20);
*
* See also:
*
@@ -1955,28 +2039,17 @@ class CanvasRenderingContext2D extends CanvasRenderingContext {
* from the WHATWG.
*/
@DomName('CanvasRenderingContext2D.drawImage')
- void drawImageAtScale(CanvasImageSource source, Rect destinationRect,
- {Rect sourceRect}) {
- if (sourceRect == null) {
- $dom_drawImage(source,
- destinationRect.left,
- destinationRect.top,
- destinationRect.width,
- destinationRect.height);
- } else {
- $dom_drawImage(source,
- sourceRect.left,
- sourceRect.top,
- sourceRect.width,
- sourceRect.height,
- destinationRect.left,
- destinationRect.top,
- destinationRect.width,
- destinationRect.height);
- }
+ void drawImageScaledFromSource(CanvasImageSource source,
+ num sourceX, num sourceY, num sourceWidth, num sourceHeight,
+ num destX, num destY, num destWidth, num destHeight) {
+ $dom_drawImage(source, sourceX, sourceY, sourceWidth, sourceHeight,
+ destX, destY, destWidth, destHeight);
}
+ // TODO(amouravski): Add Dartium native methods for drawImage once we figure
+ // out how to not break native bindings.
}
+
// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
@@ -32832,8 +32905,10 @@ class _DataAttributeMap implements Map<String, String> {
/**
* An object that can be drawn to a [CanvasRenderingContext2D] object with
- * [CanvasRenderingContext2D.drawImage] or
- * [CanvasRenderingContext2D.drawImageAtScale].
+ * [CanvasRenderingContext2D.drawImage],
+ * [CanvasRenderingContext2D.drawImageRect],
+ * [CanvasRenderingContext2D.drawImageScaled], or
+ * [CanvasRenderingContext2D.drawImageScaledFromSource].
*
* If the CanvasImageSource is an [ImageElement] then the element's image is
* used. If the [ImageElement] is an animated image, then the poster frame is
@@ -32849,6 +32924,8 @@ class _DataAttributeMap implements Map<String, String> {
*
* * [CanvasImageSource](http://www.whatwg.org/specs/web-apps/current-work/multipage/the-canvas-element.html#image-sources-for-2d-rendering-contexts)
* from the WHATWG.
+ * * [drawImage](http://www.whatwg.org/specs/web-apps/current-work/multipage/the-canvas-element.html#dom-context-2d-drawimage)
+ * from the WHATWG.
*/
abstract class CanvasImageSource {}
// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
« no previous file with comments | « sdk/lib/html/dart2js/html_dart2js.dart ('k') | tests/html/canvasrenderingcontext2d_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698