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

Unified Diff: Source/core/html/canvas/CanvasRenderingContext2D.cpp

Issue 703783004: Use CanvasImageSource union type instead of overloading (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: don't append canvases to document.body Created 6 years, 1 month 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
Index: Source/core/html/canvas/CanvasRenderingContext2D.cpp
diff --git a/Source/core/html/canvas/CanvasRenderingContext2D.cpp b/Source/core/html/canvas/CanvasRenderingContext2D.cpp
index fe0cdba7cea9198e06615357f1ed1a0d008bbeba..ff631c0a2ff171559eecd23d4da6441cb2781650 100644
--- a/Source/core/html/canvas/CanvasRenderingContext2D.cpp
+++ b/Source/core/html/canvas/CanvasRenderingContext2D.cpp
@@ -1483,25 +1483,42 @@ static inline void clipRectsToImageRect(const FloatRect& imageRect, FloatRect* s
dstRect->move(offset);
}
-void CanvasRenderingContext2D::drawImage(CanvasImageSource* imageSource, float x, float y, ExceptionState& exceptionState)
+static inline CanvasImageSource* toImageSourceInternal(const CanvasImageSourceUnion& value)
+{
+ if (value.isHTMLImageElement())
+ return value.getAsHTMLImageElement().get();
+ if (value.isHTMLVideoElement())
+ return value.getAsHTMLVideoElement().get();
+ if (value.isHTMLCanvasElement())
+ return value.getAsHTMLCanvasElement().get();
+ if (value.isImageBitmap())
+ return value.getAsImageBitmap().get();
+ ASSERT_NOT_REACHED();
+ return nullptr;
+}
+
+void CanvasRenderingContext2D::drawImage(const CanvasImageSourceUnion& imageSource, float x, float y, ExceptionState& exceptionState)
{
- FloatSize sourceRectSize = imageSource->sourceSize();
- FloatSize destRectSize = imageSource->defaultDestinationSize();
- drawImageInternal(imageSource, 0, 0, sourceRectSize.width(), sourceRectSize.height(), x, y, destRectSize.width(), destRectSize.height(), exceptionState);
+ CanvasImageSource* imageSourceInternal = toImageSourceInternal(imageSource);
+ FloatSize sourceRectSize = imageSourceInternal->sourceSize();
+ FloatSize destRectSize = imageSourceInternal->defaultDestinationSize();
+ drawImageInternal(imageSourceInternal, 0, 0, sourceRectSize.width(), sourceRectSize.height(), x, y, destRectSize.width(), destRectSize.height(), exceptionState);
}
-void CanvasRenderingContext2D::drawImage(CanvasImageSource* imageSource,
+void CanvasRenderingContext2D::drawImage(const CanvasImageSourceUnion& imageSource,
float x, float y, float width, float height, ExceptionState& exceptionState)
{
- FloatSize sourceRectSize = imageSource->sourceSize();
- drawImageInternal(imageSource, 0, 0, sourceRectSize.width(), sourceRectSize.height(), x, y, width, height, exceptionState);
+ CanvasImageSource* imageSourceInternal = toImageSourceInternal(imageSource);
+ FloatSize sourceRectSize = imageSourceInternal->sourceSize();
+ drawImageInternal(imageSourceInternal, 0, 0, sourceRectSize.width(), sourceRectSize.height(), x, y, width, height, exceptionState);
}
-void CanvasRenderingContext2D::drawImage(CanvasImageSource* imageSource,
+void CanvasRenderingContext2D::drawImage(const CanvasImageSourceUnion& imageSource,
float sx, float sy, float sw, float sh,
float dx, float dy, float dw, float dh, ExceptionState& exceptionState)
{
- drawImageInternal(imageSource, sx, sy, sw, sh, dx, dy, dw, dh, exceptionState);
+ CanvasImageSource* imageSourceInternal = toImageSourceInternal(imageSource);
+ drawImageInternal(imageSourceInternal, sx, sy, sw, sh, dx, dy, dw, dh, exceptionState);
}
static void drawVideo(GraphicsContext* c, CanvasImageSource* imageSource, FloatRect srcRect, FloatRect dstRect)
@@ -1683,7 +1700,7 @@ PassRefPtrWillBeRawPtr<CanvasGradient> CanvasRenderingContext2D::createRadialGra
return gradient.release();
}
-PassRefPtrWillBeRawPtr<CanvasPattern> CanvasRenderingContext2D::createPattern(CanvasImageSource* imageSource,
+PassRefPtrWillBeRawPtr<CanvasPattern> CanvasRenderingContext2D::createPattern(const CanvasImageSourceUnion& imageSource,
const String& repetitionType, ExceptionState& exceptionState)
{
Pattern::RepeatMode repeatMode = CanvasPattern::parseRepetitionType(repetitionType, exceptionState);
@@ -1691,13 +1708,14 @@ PassRefPtrWillBeRawPtr<CanvasPattern> CanvasRenderingContext2D::createPattern(Ca
return nullptr;
SourceImageStatus status;
- RefPtr<Image> imageForRendering = imageSource->getSourceImageForCanvas(CopySourceImageIfVolatile, &status);
+ CanvasImageSource* imageSourceInternal = toImageSourceInternal(imageSource);
+ RefPtr<Image> imageForRendering = imageSourceInternal->getSourceImageForCanvas(CopySourceImageIfVolatile, &status);
switch (status) {
case NormalSourceImageStatus:
break;
case ZeroSizeCanvasSourceImageStatus:
- exceptionState.throwDOMException(InvalidStateError, String::format("The canvas %s is 0.", imageSource->sourceSize().width() ? "height" : "width"));
+ exceptionState.throwDOMException(InvalidStateError, String::format("The canvas %s is 0.", imageSourceInternal->sourceSize().width() ? "height" : "width"));
return nullptr;
case UndecodableSourceImageStatus:
exceptionState.throwDOMException(InvalidStateError, "Source image is in the 'broken' state.");
@@ -1714,7 +1732,7 @@ PassRefPtrWillBeRawPtr<CanvasPattern> CanvasRenderingContext2D::createPattern(Ca
}
ASSERT(imageForRendering);
- bool originClean = !wouldTaintOrigin(imageSource);
+ bool originClean = !wouldTaintOrigin(imageSourceInternal);
return CanvasPattern::create(imageForRendering.release(), repeatMode, originClean);
}
« no previous file with comments | « Source/core/html/canvas/CanvasRenderingContext2D.h ('k') | Source/core/html/canvas/CanvasRenderingContext2D.idl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698