Index: Source/core/page/ImageBitmap.cpp |
diff --git a/Source/core/page/ImageBitmap.cpp b/Source/core/page/ImageBitmap.cpp |
index fabe6847b5aabfeb1a3482cb5754b9cbb20caddd..9a0df9795314984a9c1fc09c0470eff97e7b1060 100644 |
--- a/Source/core/page/ImageBitmap.cpp |
+++ b/Source/core/page/ImageBitmap.cpp |
@@ -9,7 +9,7 @@ |
#include "core/html/HTMLImageElement.h" |
#include "core/html/HTMLVideoElement.h" |
#include "core/html/ImageData.h" |
-#include "core/page/ImageBitmapCallback.h" |
+#include "core/platform/graphics/BitmapImage.h" |
#include "core/platform/graphics/GraphicsContext.h" |
#include "wtf/RefPtr.h" |
@@ -17,7 +17,7 @@ using namespace std; |
namespace WebCore { |
-static inline IntRect normalizeRect(const IntRect rect) |
+static inline IntRect normalizeRect(const IntRect& rect) |
{ |
return IntRect(min(rect.x(), rect.maxX()), |
min(rect.y(), rect.maxY()), |
@@ -25,26 +25,26 @@ static inline IntRect normalizeRect(const IntRect rect) |
max(rect.height(), -rect.height())); |
} |
-static inline PassRefPtr<BitmapImage> cropImage(Image* image, IntRect cropRect) |
+static inline PassRefPtr<Image> cropImage(Image* image, const IntRect& cropRect) |
{ |
SkBitmap cropped; |
image->nativeImageForCurrentFrame()->bitmap().extractSubset(&cropped, cropRect); |
return BitmapImage::create(NativeImageSkia::create(cropped)); |
} |
-ImageBitmap::ImageBitmap(HTMLImageElement* image, IntRect cropRect) |
+ImageBitmap::ImageBitmap(HTMLImageElement* image, const IntRect& cropRect) |
: m_bitmapOffset(max(0, -cropRect.x()), max(0, -cropRect.y())) |
- , m_size(cropRect.size()) |
+ , m_cropRect(cropRect) |
{ |
- Image* bitmapImage = image->cachedImage()->image(); |
- m_bitmap = cropImage(bitmapImage, cropRect).get(); |
+ m_bitmap = new CachedImage(cropImage(image->cachedImage()->image(), cropRect).get()); |
Justin Novosad
2013/07/23 16:55:12
Why a new cached image? can we not take a ref on t
|
+ m_bitmap->setDecodePriority(CachedResource::DecodePriorityHigh); |
ScriptWrappable::init(this); |
} |
-ImageBitmap::ImageBitmap(HTMLVideoElement* video, IntRect cropRect) |
+ImageBitmap::ImageBitmap(HTMLVideoElement* video, const IntRect& cropRect) |
: m_bitmapOffset(max(0, -cropRect.x()), max(0, -cropRect.y())) |
- , m_size(cropRect.size()) |
+ , m_cropRect(cropRect) |
{ |
IntRect videoRect = IntRect(IntPoint(), video->player()->naturalSize()); |
IntRect srcRect = intersection(cropRect, videoRect); |
@@ -55,14 +55,15 @@ ImageBitmap::ImageBitmap(HTMLVideoElement* video, IntRect cropRect) |
c->clip(dstRect); |
c->translate(-srcRect.x(), -srcRect.y()); |
video->paintCurrentFrameInContext(c, videoRect); |
- m_bitmap = static_cast<BitmapImage*>(m_buffer->copyImage(DontCopyBackingStore).get()); |
+ m_bitmap = new CachedImage(m_buffer->copyImage(DontCopyBackingStore).get()); |
Justin Novosad
2013/07/23 16:55:12
When creating from a video, we have no way to rege
|
+ m_bitmap->setDecodePriority(CachedResource::DecodePriorityHigh); |
ScriptWrappable::init(this); |
} |
-ImageBitmap::ImageBitmap(HTMLCanvasElement* canvas, IntRect cropRect) |
+ImageBitmap::ImageBitmap(HTMLCanvasElement* canvas, const IntRect& cropRect) |
: m_bitmapOffset(max(0, -cropRect.x()), max(0, -cropRect.y())) |
- , m_size(cropRect.size()) |
+ , m_cropRect(cropRect) |
{ |
IntSize canvasSize = canvas->size(); |
IntRect srcRect = intersection(cropRect, IntRect(IntPoint(), canvasSize)); |
@@ -70,14 +71,15 @@ ImageBitmap::ImageBitmap(HTMLCanvasElement* canvas, IntRect cropRect) |
m_buffer = ImageBuffer::create(canvasSize); |
m_buffer->context()->drawImageBuffer(canvas->buffer(), dstRect, srcRect); |
- m_bitmap = static_cast<BitmapImage*>(m_buffer->copyImage(DontCopyBackingStore).get()); |
+ m_bitmap = new CachedImage(m_buffer->copyImage(DontCopyBackingStore).get()); |
Justin Novosad
2013/07/23 16:55:12
Same here. This should not ba a cached image.
|
+ m_bitmap->setDecodePriority(CachedResource::DecodePriorityHigh); |
ScriptWrappable::init(this); |
} |
-ImageBitmap::ImageBitmap(ImageData* data, IntRect cropRect) |
+ImageBitmap::ImageBitmap(ImageData* data, const IntRect& cropRect) |
: m_bitmapOffset(max(0, -cropRect.x()), max(0, -cropRect.y())) |
- , m_size(cropRect.size()) |
+ , m_cropRect(cropRect) |
{ |
IntRect srcRect = intersection(cropRect, IntRect(IntPoint(), data->size())); |
@@ -85,51 +87,53 @@ ImageBitmap::ImageBitmap(ImageData* data, IntRect cropRect) |
if (srcRect.width() > 0 && srcRect.height() > 0) |
m_buffer->putByteArray(Unmultiplied, data->data(), data->size(), srcRect, IntPoint(min(0, -cropRect.x()), min(0, -cropRect.y()))); |
- m_bitmap = static_cast<BitmapImage*>(m_buffer->copyImage(DontCopyBackingStore).get()); |
+ m_bitmap = new CachedImage(m_buffer->copyImage(DontCopyBackingStore).get()); |
Justin Novosad
2013/07/23 16:55:12
Should not be a cached image
|
+ m_bitmap->setDecodePriority(CachedResource::DecodePriorityHigh); |
ScriptWrappable::init(this); |
} |
-ImageBitmap::ImageBitmap(ImageBitmap* bitmap, IntRect cropRect) |
+ImageBitmap::ImageBitmap(ImageBitmap* bitmap, const IntRect& cropRect) |
: m_bitmapOffset(max(0, bitmap->bitmapOffset().x() - cropRect.x()), max(0, bitmap->bitmapOffset().y() - cropRect.y())) |
- , m_size(cropRect.size()) |
+ , m_cropRect(cropRect) |
{ |
- Image* bitmapImage = bitmap->bitmapImage(); |
- cropRect.moveBy(IntPoint(-bitmap->bitmapOffset().x(), -bitmap->bitmapOffset().y())); |
- m_bitmap = cropImage(bitmapImage, cropRect).get(); |
+ IntRect adjustedCropRect(IntPoint(cropRect.x() - bitmap->bitmapOffset().x(), cropRect.y() - bitmap->bitmapOffset().y()), cropRect.size()); |
+ |
+ m_bitmap = new CachedImage(cropImage(bitmap->bitmapImage(), adjustedCropRect).get()); |
Justin Novosad
2013/07/23 16:55:12
This function needs to be more complex. It should
|
+ m_bitmap->setDecodePriority(CachedResource::DecodePriorityHigh); |
ScriptWrappable::init(this); |
} |
-PassRefPtr<ImageBitmap> ImageBitmap::create(HTMLImageElement* image, IntRect cropRect) |
+PassRefPtr<ImageBitmap> ImageBitmap::create(HTMLImageElement* image, const IntRect& cropRect) |
{ |
IntRect normalizedCropRect = normalizeRect(cropRect); |
- RefPtr<ImageBitmap> imageBitmap(adoptRef(new ImageBitmap(image, normalizedCropRect))); |
+ RefPtr<ImageBitmap> imageBitmap(adoptRef(new ImageBitmap( image, normalizedCropRect))); |
return imageBitmap.release(); |
} |
-PassRefPtr<ImageBitmap> ImageBitmap::create(HTMLVideoElement* video, IntRect cropRect) |
+PassRefPtr<ImageBitmap> ImageBitmap::create(HTMLVideoElement* video, const IntRect& cropRect) |
{ |
IntRect normalizedCropRect = normalizeRect(cropRect); |
RefPtr<ImageBitmap> imageBitmap(adoptRef(new ImageBitmap(video, normalizedCropRect))); |
return imageBitmap.release(); |
} |
-PassRefPtr<ImageBitmap> ImageBitmap::create(HTMLCanvasElement* canvas, IntRect cropRect) |
+PassRefPtr<ImageBitmap> ImageBitmap::create(HTMLCanvasElement* canvas, const IntRect& cropRect) |
{ |
IntRect normalizedCropRect = normalizeRect(cropRect); |
RefPtr<ImageBitmap> imageBitmap(adoptRef(new ImageBitmap(canvas, normalizedCropRect))); |
return imageBitmap.release(); |
} |
-PassRefPtr<ImageBitmap> ImageBitmap::create(ImageData* data, IntRect cropRect) |
+PassRefPtr<ImageBitmap> ImageBitmap::create(ImageData* data, const IntRect& cropRect) |
{ |
IntRect normalizedCropRect = normalizeRect(cropRect); |
RefPtr<ImageBitmap> imageBitmap(adoptRef(new ImageBitmap(data, normalizedCropRect))); |
return imageBitmap.release(); |
} |
-PassRefPtr<ImageBitmap> ImageBitmap::create(ImageBitmap* bitmap, IntRect cropRect) |
+PassRefPtr<ImageBitmap> ImageBitmap::create(ImageBitmap* bitmap, const IntRect& cropRect) |
{ |
IntRect normalizedCropRect = normalizeRect(cropRect); |
RefPtr<ImageBitmap> imageBitmap(adoptRef(new ImageBitmap(bitmap, normalizedCropRect))); |