Chromium Code Reviews| Index: Source/core/html/canvas/CanvasRenderingContext2D.cpp |
| diff --git a/Source/core/html/canvas/CanvasRenderingContext2D.cpp b/Source/core/html/canvas/CanvasRenderingContext2D.cpp |
| index b2701331d1dffccff104b5be49378965be011792..33bea5145e0595fa33c481ad665a904b360b9d74 100644 |
| --- a/Source/core/html/canvas/CanvasRenderingContext2D.cpp |
| +++ b/Source/core/html/canvas/CanvasRenderingContext2D.cpp |
| @@ -1191,7 +1191,7 @@ static inline FloatRect normalizeRect(const FloatRect& rect) |
| max(rect.height(), -rect.height())); |
| } |
| -void CanvasRenderingContext2D::drawImageInternal(Image* image, const FloatRect& srcRect, const FloatRect& dstRect, const CompositeOperator& op, const BlendMode& blendMode) |
| +template<class T> void CanvasRenderingContext2D::drawImageInternal(T* image, const FloatRect& srcRect, const FloatRect& dstRect, const CompositeOperator& op, const BlendMode& blendMode) |
| { |
| if (!image) |
| return; |
| @@ -1260,12 +1260,8 @@ void CanvasRenderingContext2D::drawImage(ImageBitmap* bitmap, |
| return; |
| ASSERT(bitmap->height() && bitmap->width()); |
| - |
| FloatRect normalizedSrcRect = normalizeRect(srcRect); |
| FloatRect normalizedDstRect = normalizeRect(dstRect); |
| - FloatRect actualDstRect(FloatPoint(bitmap->bitmapOffset()), bitmap->bitmapSize()); |
| - actualDstRect.scale(normalizedDstRect.width() / bitmap->width(), normalizedDstRect.height() / bitmap->height()); |
| - actualDstRect.moveBy(normalizedDstRect.location()); |
| FloatRect imageRect = FloatRect(FloatPoint(), bitmap->bitmapSize()); |
| if (!srcRect.width() || !srcRect.height()) { |
| @@ -1275,9 +1271,17 @@ void CanvasRenderingContext2D::drawImage(ImageBitmap* bitmap, |
| if (!imageRect.contains(normalizedSrcRect)) |
| return; |
| - Image* imageForRendering = bitmap->bitmapImage(); |
| - |
| - drawImageInternal(imageForRendering, normalizedSrcRect, actualDstRect, state().m_globalComposite, state().m_globalBlend); |
| + if (bitmap->canvasImage()) { |
| + FloatRect originalCropRect(bitmap->cropRect()); |
| + normalizedSrcRect.moveBy(originalCropRect.location()); |
| + FloatRect actualSrcRect = intersection(originalCropRect, normalizedSrcRect); |
| + drawImageInternal(bitmap->canvasImage(), actualSrcRect, normalizedDstRect, state().m_globalComposite, state().m_globalBlend); |
| + } else { |
| + FloatRect actualDstRect(FloatPoint(bitmap->bitmapOffset()), bitmap->bitmapSize()); |
| + actualDstRect.scale(normalizedDstRect.width() / bitmap->width(), normalizedDstRect.height() / bitmap->height()); |
| + actualDstRect.moveBy(normalizedDstRect.location()); |
| + drawImageInternal(bitmap->bitmapImage().get(), normalizedSrcRect, actualDstRect, state().m_globalComposite, state().m_globalBlend); |
| + } |
| } |
| void CanvasRenderingContext2D::drawImage(HTMLImageElement* image, float x, float y, ExceptionCode& ec) |
| @@ -1611,6 +1615,11 @@ static void drawImageToContext(Image* image, GraphicsContext* context, FloatRect |
| context->drawImage(image, dest, src, op); |
| } |
| +static void drawImageToContext(SkImage* image, GraphicsContext* context, FloatRect& dest, const FloatRect& src, CompositeOperator op) |
|
Justin Novosad
2013/07/22 15:35:41
Don't use skia classes outside of core/platform/ u
|
| +{ |
| + context->drawImage(image, dest, src, op); |
| +} |
| + |
| static void drawImageToContext(ImageBuffer* imageBuffer, GraphicsContext* context, const FloatRect& dest, const FloatRect& src, CompositeOperator op) |
| { |
| context->drawImageBuffer(imageBuffer, dest, src, op); |