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

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

Issue 19393004: Allow eviction of ImageBitmaps that are created from ImageElements. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Fix for assertion failure. Created 7 years, 4 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Source/core/html/HTMLImageElement.h ('k') | Source/core/loader/ImageLoader.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/html/canvas/CanvasRenderingContext2D.cpp
diff --git a/Source/core/html/canvas/CanvasRenderingContext2D.cpp b/Source/core/html/canvas/CanvasRenderingContext2D.cpp
index e8342072089e713747687c4ec34c892029963a88..52051710cdfbcf65fbedcd02311e9408f102a090 100644
--- a/Source/core/html/canvas/CanvasRenderingContext2D.cpp
+++ b/Source/core/html/canvas/CanvasRenderingContext2D.cpp
@@ -1255,10 +1255,10 @@ void CanvasRenderingContext2D::drawImage(ImageBitmap* bitmap,
es.throwDOMException(TypeMismatchError);
return;
}
- if (!bitmap->bitmapWidth() || !bitmap->bitmapHeight())
+ if (!bitmap->bitmapRect().width() || !bitmap->bitmapRect().height())
return;
- drawImage(bitmap, 0, 0, bitmap->bitmapWidth(), bitmap->bitmapHeight(), x, y, width, height, es);
+ drawImage(bitmap, 0, 0, bitmap->width(), bitmap->height(), x, y, width, height, es);
}
void CanvasRenderingContext2D::drawImage(ImageBitmap* bitmap,
@@ -1272,6 +1272,7 @@ void CanvasRenderingContext2D::drawImage(ImageBitmap* bitmap,
FloatRect srcRect(sx, sy, sw, sh);
FloatRect dstRect(dx, dy, dw, dh);
+ FloatRect bitmapRect = bitmap->bitmapRect();
if (!std::isfinite(dstRect.x()) || !std::isfinite(dstRect.y()) || !std::isfinite(dstRect.width()) || !std::isfinite(dstRect.height())
|| !std::isfinite(srcRect.x()) || !std::isfinite(srcRect.y()) || !std::isfinite(srcRect.width()) || !std::isfinite(srcRect.height()))
@@ -1279,28 +1280,34 @@ void CanvasRenderingContext2D::drawImage(ImageBitmap* bitmap,
if (!dstRect.width() || !dstRect.height())
return;
+ if (!srcRect.width() || !srcRect.height()) {
+ es.throwDOMException(IndexSizeError);
+ 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()) {
- es.throwDOMException(IndexSizeError);
- return;
- }
- if (!imageRect.intersects(normalizedSrcRect))
- return;
+ // Clip the rects to where the user thinks that the image is situated.
+ clipRectsToImageRect(IntRect(IntPoint(), bitmap->size()), &normalizedSrcRect, &normalizedDstRect);
- clipRectsToImageRect(imageRect, &normalizedSrcRect, &actualDstRect);
+ FloatRect intersectRect = intersection(bitmapRect, normalizedSrcRect);
+ FloatRect actualSrcRect(intersectRect);
+ actualSrcRect.move(-bitmapRect.x(), -bitmapRect.y());
- Image* imageForRendering = bitmap->bitmapImage();
+ FloatRect imageRect = FloatRect(FloatPoint(), bitmapRect.size());
+
+ FloatRect actualDstRect(FloatPoint(intersectRect.location() - normalizedSrcRect.location()), bitmapRect.size());
+ actualDstRect.scale(normalizedDstRect.width() / normalizedSrcRect.width() * intersectRect.width() / bitmapRect.width(),
+ normalizedDstRect.height() / normalizedSrcRect.height() * intersectRect.height() / bitmapRect.height());
+ actualDstRect.moveBy(normalizedDstRect.location());
+
+ if (!imageRect.intersects(actualSrcRect))
+ return;
- drawImageInternal(imageForRendering, normalizedSrcRect, actualDstRect, state().m_globalComposite, state().m_globalBlend);
+ RefPtr<Image> imageForRendering = bitmap->bitmapImage();
+ drawImageInternal(imageForRendering.get(), actualSrcRect, actualDstRect, state().m_globalComposite, state().m_globalBlend);
}
void CanvasRenderingContext2D::drawImage(HTMLImageElement* image, float x, float y, ExceptionState& es)
« no previous file with comments | « Source/core/html/HTMLImageElement.h ('k') | Source/core/loader/ImageLoader.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698