| Index: Source/core/page/ImageBitmap.cpp
|
| diff --git a/Source/core/page/ImageBitmap.cpp b/Source/core/page/ImageBitmap.cpp
|
| index ffe3af0dfa65d59ae71c04122efe6fad942d5949..e4a738814bc82312b1d75f7dc4402634b497ba52 100644
|
| --- a/Source/core/page/ImageBitmap.cpp
|
| +++ b/Source/core/page/ImageBitmap.cpp
|
| @@ -35,6 +35,8 @@ static inline PassRefPtr<Image> cropImage(Image* image, const IntRect& cropRect)
|
| ImageBitmap::ImageBitmap(HTMLImageElement* image, const IntRect& cropRect)
|
| : m_cropRect(cropRect)
|
| , m_imageElement(image)
|
| + , m_bitmap(0)
|
| + , m_derivedFromCanvas(false)
|
| {
|
| m_imageElement->addClient(this);
|
|
|
| @@ -49,6 +51,7 @@ ImageBitmap::ImageBitmap(HTMLVideoElement* video, const IntRect& cropRect)
|
| : m_cropRect(cropRect)
|
| , m_imageElement(0)
|
| , m_bitmapOffset(IntPoint())
|
| + , m_derivedFromCanvas(false)
|
| {
|
| IntRect videoRect = IntRect(IntPoint(), video->player()->naturalSize());
|
| IntRect srcRect = intersection(cropRect, videoRect);
|
| @@ -68,16 +71,13 @@ ImageBitmap::ImageBitmap(HTMLVideoElement* video, const IntRect& cropRect)
|
| ImageBitmap::ImageBitmap(HTMLCanvasElement* canvas, const IntRect& cropRect)
|
| : m_cropRect(cropRect)
|
| , m_imageElement(0)
|
| + , m_bitmap(canvas->buffer()->imageSnapshot())
|
| , m_bitmapOffset(IntPoint())
|
| + , m_derivedFromCanvas(true)
|
| {
|
| - IntSize canvasSize = canvas->size();
|
| - IntRect srcRect = intersection(cropRect, IntRect(IntPoint(), canvasSize));
|
| - IntRect dstRect(IntPoint(), srcRect.size());
|
| -
|
| - m_buffer = ImageBuffer::create(canvasSize);
|
| - m_buffer->context()->drawImageBuffer(canvas->buffer(), dstRect, srcRect);
|
| - m_bitmap = m_buffer->copyImage(DontCopyBackingStore);
|
| + IntRect srcRect = intersection(cropRect, IntRect(IntPoint(), canvas->size()));
|
| m_bitmapRect = IntRect(IntPoint(max(0, -cropRect.x()), max(0, -cropRect.y())), srcRect.size());
|
| + m_bitmapOffset = srcRect.location();
|
|
|
| ScriptWrappable::init(this);
|
| }
|
| @@ -86,6 +86,7 @@ ImageBitmap::ImageBitmap(ImageData* data, const IntRect& cropRect)
|
| : m_cropRect(cropRect)
|
| , m_imageElement(0)
|
| , m_bitmapOffset(IntPoint())
|
| + , m_derivedFromCanvas(false)
|
| {
|
| IntRect srcRect = intersection(cropRect, IntRect(IntPoint(), data->size()));
|
|
|
| @@ -103,19 +104,24 @@ ImageBitmap::ImageBitmap(ImageBitmap* bitmap, const IntRect& cropRect)
|
| : m_cropRect(cropRect)
|
| , m_imageElement(bitmap->imageElement())
|
| , m_bitmapOffset(IntPoint())
|
| + , m_derivedFromCanvas(bitmap->derivedFromCanvas())
|
| {
|
| IntRect oldBitmapRect = bitmap->bitmapRect();
|
| 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_imageElement->addClient(this);
|
| + m_bitmapOffset = srcRect.location();
|
| + } else if (m_derivedFromCanvas) {
|
| + m_bitmap = bitmap->bitmapImage();
|
| m_bitmapOffset = srcRect.location();
|
| } else {
|
| - IntRect adjustedCropRect(IntPoint(cropRect.x() -oldBitmapRect.x(), cropRect.y() - oldBitmapRect.y()), cropRect.size());
|
| + IntRect adjustedCropRect(IntPoint(cropRect.x() - oldBitmapRect.x(), cropRect.y() - oldBitmapRect.y()), cropRect.size());
|
| m_bitmap = cropImage(bitmap->bitmapImage().get(), adjustedCropRect);
|
| }
|
| +
|
| ScriptWrappable::init(this);
|
| }
|
|
|
| @@ -170,6 +176,8 @@ void ImageBitmap::notifyImageSourceChanged()
|
| PassRefPtr<Image> ImageBitmap::bitmapImage() const
|
| {
|
| ASSERT((m_imageElement || m_bitmap) && (!m_imageElement || !m_bitmap));
|
| + ASSERT((m_imageElement || m_derivedFromCanvas) && (!m_imageElement || !m_derivedFromCanvas));
|
| +
|
| if (m_imageElement)
|
| return m_imageElement->cachedImage()->image();
|
| return m_bitmap;
|
|
|