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

Unified Diff: Source/core/page/ImageBitmap.cpp

Issue 22613002: Allow ImageBitmaps derived from HTMLImageElements to be evicted from RAM. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Make destructor virtual. 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/page/ImageBitmap.h ('k') | Source/core/page/ImageBitmapTest.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/page/ImageBitmap.cpp
diff --git a/Source/core/page/ImageBitmap.cpp b/Source/core/page/ImageBitmap.cpp
index 2f83dd31d15ef34c1697d544f39b783227b699fb..ffe3af0dfa65d59ae71c04122efe6fad942d5949 100644
--- a/Source/core/page/ImageBitmap.cpp
+++ b/Source/core/page/ImageBitmap.cpp
@@ -38,8 +38,9 @@ ImageBitmap::ImageBitmap(HTMLImageElement* image, const IntRect& cropRect)
{
m_imageElement->addClient(this);
- IntSize bitmapSize = intersection(cropRect, IntRect(0, 0, image->width(), image->height())).size();
- m_bitmapRect = IntRect(IntPoint(max(0, -cropRect.x()), max(0, -cropRect.y())), bitmapSize);
+ IntRect srcRect = intersection(cropRect, IntRect(0, 0, image->width(), image->height()));
+ m_bitmapRect = IntRect(IntPoint(max(0, -cropRect.x()), max(0, -cropRect.y())), srcRect.size());
+ m_bitmapOffset = srcRect.location();
ScriptWrappable::init(this);
}
@@ -47,6 +48,7 @@ ImageBitmap::ImageBitmap(HTMLImageElement* image, const IntRect& cropRect)
ImageBitmap::ImageBitmap(HTMLVideoElement* video, const IntRect& cropRect)
: m_cropRect(cropRect)
, m_imageElement(0)
+ , m_bitmapOffset(IntPoint())
{
IntRect videoRect = IntRect(IntPoint(), video->player()->naturalSize());
IntRect srcRect = intersection(cropRect, videoRect);
@@ -66,6 +68,7 @@ ImageBitmap::ImageBitmap(HTMLVideoElement* video, const IntRect& cropRect)
ImageBitmap::ImageBitmap(HTMLCanvasElement* canvas, const IntRect& cropRect)
: m_cropRect(cropRect)
, m_imageElement(0)
+ , m_bitmapOffset(IntPoint())
{
IntSize canvasSize = canvas->size();
IntRect srcRect = intersection(cropRect, IntRect(IntPoint(), canvasSize));
@@ -82,6 +85,7 @@ ImageBitmap::ImageBitmap(HTMLCanvasElement* canvas, const IntRect& cropRect)
ImageBitmap::ImageBitmap(ImageData* data, const IntRect& cropRect)
: m_cropRect(cropRect)
, m_imageElement(0)
+ , m_bitmapOffset(IntPoint())
{
IntRect srcRect = intersection(cropRect, IntRect(IntPoint(), data->size()));
@@ -98,14 +102,16 @@ ImageBitmap::ImageBitmap(ImageData* data, const IntRect& cropRect)
ImageBitmap::ImageBitmap(ImageBitmap* bitmap, const IntRect& cropRect)
: m_cropRect(cropRect)
, m_imageElement(bitmap->imageElement())
+ , m_bitmapOffset(IntPoint())
{
IntRect oldBitmapRect = bitmap->bitmapRect();
- IntSize bitmapSize = intersection(cropRect, oldBitmapRect).size();
- IntPoint bitmapOffset(max(0, oldBitmapRect.x() - cropRect.x()), max(0, oldBitmapRect.y() - cropRect.y()));
- m_bitmapRect = IntRect(bitmapOffset, bitmapSize);
+ IntRect srcRect = intersection(cropRect, oldBitmapRect);
+ m_bitmapRect = IntRect(IntPoint(max(0, oldBitmapRect.x() - cropRect.x()), max(0, oldBitmapRect.y() - cropRect.y())), srcRect.size());
+
if (m_imageElement) {
m_imageElement->addClient(this);
m_bitmap = 0;
+ m_bitmapOffset = srcRect.location();
} else {
IntRect adjustedCropRect(IntPoint(cropRect.x() -oldBitmapRect.x(), cropRect.y() - oldBitmapRect.y()), cropRect.size());
m_bitmap = cropImage(bitmap->bitmapImage().get(), adjustedCropRect);
@@ -157,6 +163,7 @@ PassRefPtr<ImageBitmap> ImageBitmap::create(ImageBitmap* bitmap, const IntRect&
void ImageBitmap::notifyImageSourceChanged()
{
m_bitmap = cropImage(m_imageElement->cachedImage()->image(), m_cropRect);
+ m_bitmapOffset = IntPoint();
m_imageElement = 0;
}
@@ -164,7 +171,7 @@ PassRefPtr<Image> ImageBitmap::bitmapImage() const
{
ASSERT((m_imageElement || m_bitmap) && (!m_imageElement || !m_bitmap));
if (m_imageElement)
- return cropImage(m_imageElement->cachedImage()->image(), m_cropRect);
+ return m_imageElement->cachedImage()->image();
return m_bitmap;
}
« no previous file with comments | « Source/core/page/ImageBitmap.h ('k') | Source/core/page/ImageBitmapTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698