Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "config.h" | 5 #include "config.h" |
| 6 #include "core/page/ImageBitmap.h" | 6 #include "core/page/ImageBitmap.h" |
| 7 | 7 |
| 8 #include "core/html/HTMLCanvasElement.h" | 8 #include "core/html/HTMLCanvasElement.h" |
| 9 #include "core/html/HTMLImageElement.h" | 9 #include "core/html/HTMLImageElement.h" |
| 10 #include "core/html/HTMLVideoElement.h" | 10 #include "core/html/HTMLVideoElement.h" |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 27 | 27 |
| 28 static inline PassRefPtr<BitmapImage> cropImage(Image* image, IntRect cropRect) | 28 static inline PassRefPtr<BitmapImage> cropImage(Image* image, IntRect cropRect) |
| 29 { | 29 { |
| 30 SkBitmap cropped; | 30 SkBitmap cropped; |
| 31 image->nativeImageForCurrentFrame()->bitmap().extractSubset(&cropped, cropRe ct); | 31 image->nativeImageForCurrentFrame()->bitmap().extractSubset(&cropped, cropRe ct); |
| 32 return BitmapImage::create(NativeImageSkia::create(cropped)); | 32 return BitmapImage::create(NativeImageSkia::create(cropped)); |
| 33 } | 33 } |
| 34 | 34 |
| 35 ImageBitmap::ImageBitmap(HTMLImageElement* image, IntRect cropRect) | 35 ImageBitmap::ImageBitmap(HTMLImageElement* image, IntRect cropRect) |
| 36 : m_bitmapOffset(max(0, -cropRect.x()), max(0, -cropRect.y())) | 36 : m_bitmapOffset(max(0, -cropRect.x()), max(0, -cropRect.y())) |
| 37 , m_size(cropRect.size()) | 37 , m_cropRect(cropRect) |
| 38 , m_derivedFromCanvas(0) | |
|
Justin Novosad
2013/07/22 15:35:41
this is a bool, so initialize it with false instea
| |
| 38 { | 39 { |
| 39 Image* bitmapImage = image->cachedImage()->image(); | 40 Image* bitmapImage = image->cachedImage()->image(); |
| 40 m_bitmap = cropImage(bitmapImage, cropRect).get(); | 41 m_bitmap = cropImage(bitmapImage, cropRect); |
| 42 m_bitmapSize = IntSize(m_bitmap->size()); | |
| 41 | 43 |
| 42 ScriptWrappable::init(this); | 44 ScriptWrappable::init(this); |
| 43 } | 45 } |
| 44 | 46 |
| 45 ImageBitmap::ImageBitmap(HTMLVideoElement* video, IntRect cropRect) | 47 ImageBitmap::ImageBitmap(HTMLVideoElement* video, IntRect cropRect) |
| 46 : m_bitmapOffset(max(0, -cropRect.x()), max(0, -cropRect.y())) | 48 : m_bitmapOffset(max(0, -cropRect.x()), max(0, -cropRect.y())) |
| 47 , m_size(cropRect.size()) | 49 , m_cropRect(cropRect) |
| 50 , m_derivedFromCanvas(0) | |
| 48 { | 51 { |
| 49 IntRect videoRect = IntRect(IntPoint(), video->player()->naturalSize()); | 52 IntRect videoRect = IntRect(IntPoint(), video->player()->naturalSize()); |
| 50 IntRect srcRect = intersection(cropRect, videoRect); | 53 IntRect srcRect = intersection(cropRect, videoRect); |
| 51 IntRect dstRect(IntPoint(), srcRect.size()); | 54 IntRect dstRect(IntPoint(), srcRect.size()); |
| 52 | 55 |
| 53 m_buffer = ImageBuffer::create(videoRect.size()); | 56 m_buffer = ImageBuffer::create(videoRect.size()); |
| 54 GraphicsContext* c = m_buffer->context(); | 57 GraphicsContext* c = m_buffer->context(); |
| 55 c->clip(dstRect); | 58 c->clip(dstRect); |
| 56 c->translate(-srcRect.x(), -srcRect.y()); | 59 c->translate(-srcRect.x(), -srcRect.y()); |
| 57 video->paintCurrentFrameInContext(c, videoRect); | 60 video->paintCurrentFrameInContext(c, videoRect); |
| 58 m_bitmap = static_cast<BitmapImage*>(m_buffer->copyImage(DontCopyBackingStor e).get()); | 61 m_bitmap = m_buffer->copyImage(DontCopyBackingStore); |
| 62 m_bitmapSize = IntSize(m_bitmap->size()); | |
| 59 | 63 |
| 60 ScriptWrappable::init(this); | 64 ScriptWrappable::init(this); |
| 61 } | 65 } |
| 62 | 66 |
| 63 ImageBitmap::ImageBitmap(HTMLCanvasElement* canvas, IntRect cropRect) | 67 ImageBitmap::ImageBitmap(HTMLCanvasElement* canvas, IntRect cropRect) |
| 64 : m_bitmapOffset(max(0, -cropRect.x()), max(0, -cropRect.y())) | 68 : m_bitmapOffset(max(0, -cropRect.x()), max(0, -cropRect.y())) |
| 65 , m_size(cropRect.size()) | 69 , m_cropRect(cropRect) |
| 70 , m_derivedFromCanvas(1) | |
| 71 , m_bitmapSize(cropRect.size()) | |
| 66 { | 72 { |
| 67 IntSize canvasSize = canvas->size(); | 73 m_bitmap = canvas->buffer()->imageSnapshot(); |
| 68 IntRect srcRect = intersection(cropRect, IntRect(IntPoint(), canvasSize)); | |
| 69 IntRect dstRect(IntPoint(), srcRect.size()); | |
| 70 | |
| 71 m_buffer = ImageBuffer::create(canvasSize); | |
| 72 m_buffer->context()->drawImageBuffer(canvas->buffer(), dstRect, srcRect); | |
| 73 m_bitmap = static_cast<BitmapImage*>(m_buffer->copyImage(DontCopyBackingStor e).get()); | |
| 74 | 74 |
| 75 ScriptWrappable::init(this); | 75 ScriptWrappable::init(this); |
| 76 } | 76 } |
| 77 | 77 |
| 78 ImageBitmap::ImageBitmap(ImageData* data, IntRect cropRect) | 78 ImageBitmap::ImageBitmap(ImageData* data, IntRect cropRect) |
| 79 : m_bitmapOffset(max(0, -cropRect.x()), max(0, -cropRect.y())) | 79 : m_bitmapOffset(max(0, -cropRect.x()), max(0, -cropRect.y())) |
| 80 , m_size(cropRect.size()) | 80 , m_cropRect(cropRect) |
| 81 , m_derivedFromCanvas(0) | |
| 81 { | 82 { |
| 82 IntRect srcRect = intersection(cropRect, IntRect(IntPoint(), data->size())); | 83 IntRect srcRect = intersection(cropRect, IntRect(IntPoint(), data->size())); |
| 83 | 84 |
| 84 m_buffer = ImageBuffer::create(data->size()); | 85 m_buffer = ImageBuffer::create(data->size()); |
| 85 if (srcRect.width() > 0 && srcRect.height() > 0) | 86 if (srcRect.width() > 0 && srcRect.height() > 0) |
| 86 m_buffer->putByteArray(Unmultiplied, data->data(), data->size(), srcRect , IntPoint(min(0, -cropRect.x()), min(0, -cropRect.y()))); | 87 m_buffer->putByteArray(Unmultiplied, data->data(), data->size(), srcRect , IntPoint(min(0, -cropRect.x()), min(0, -cropRect.y()))); |
| 87 | 88 |
| 88 m_bitmap = static_cast<BitmapImage*>(m_buffer->copyImage(DontCopyBackingStor e).get()); | 89 m_bitmap = m_buffer->copyImage(DontCopyBackingStore); |
| 90 m_bitmapSize = IntSize(m_bitmap->size()); | |
| 89 | 91 |
| 90 ScriptWrappable::init(this); | 92 ScriptWrappable::init(this); |
| 91 } | 93 } |
| 92 | 94 |
| 93 ImageBitmap::ImageBitmap(ImageBitmap* bitmap, IntRect cropRect) | 95 ImageBitmap::ImageBitmap(ImageBitmap* bitmap, IntRect cropRect) |
| 94 : m_bitmapOffset(max(0, bitmap->bitmapOffset().x() - cropRect.x()), max(0, b itmap->bitmapOffset().y() - cropRect.y())) | 96 : m_bitmapOffset(max(0, bitmap->bitmapOffset().x() - cropRect.x()), max(0, b itmap->bitmapOffset().y() - cropRect.y())) |
| 95 , m_size(cropRect.size()) | 97 , m_cropRect(cropRect) |
| 98 , m_derivedFromCanvas(0) | |
| 96 { | 99 { |
| 97 Image* bitmapImage = bitmap->bitmapImage(); | 100 Image* bitmapImage = bitmap->bitmapImage().get(); |
| 98 cropRect.moveBy(IntPoint(-bitmap->bitmapOffset().x(), -bitmap->bitmapOffset( ).y())); | 101 cropRect.moveBy(IntPoint(-bitmap->bitmapOffset().x(), -bitmap->bitmapOffset( ).y())); |
| 99 m_bitmap = cropImage(bitmapImage, cropRect).get(); | 102 m_bitmap = cropImage(bitmapImage, cropRect); |
| 103 m_bitmapSize = IntSize(m_bitmap->size()); | |
| 100 | 104 |
| 101 ScriptWrappable::init(this); | 105 ScriptWrappable::init(this); |
| 102 } | 106 } |
| 103 | 107 |
| 104 PassRefPtr<ImageBitmap> ImageBitmap::create(HTMLImageElement* image, IntRect cro pRect) | 108 PassRefPtr<ImageBitmap> ImageBitmap::create(HTMLImageElement* image, IntRect cro pRect) |
| 105 { | 109 { |
| 106 IntRect normalizedCropRect = normalizeRect(cropRect); | 110 IntRect normalizedCropRect = normalizeRect(cropRect); |
| 107 RefPtr<ImageBitmap> imageBitmap(adoptRef(new ImageBitmap(image, normalizedCr opRect))); | 111 RefPtr<ImageBitmap> imageBitmap(adoptRef(new ImageBitmap(image, normalizedCr opRect))); |
| 108 return imageBitmap.release(); | 112 return imageBitmap.release(); |
| 109 } | 113 } |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 130 } | 134 } |
| 131 | 135 |
| 132 PassRefPtr<ImageBitmap> ImageBitmap::create(ImageBitmap* bitmap, IntRect cropRec t) | 136 PassRefPtr<ImageBitmap> ImageBitmap::create(ImageBitmap* bitmap, IntRect cropRec t) |
| 133 { | 137 { |
| 134 IntRect normalizedCropRect = normalizeRect(cropRect); | 138 IntRect normalizedCropRect = normalizeRect(cropRect); |
| 135 RefPtr<ImageBitmap> imageBitmap(adoptRef(new ImageBitmap(bitmap, normalizedC ropRect))); | 139 RefPtr<ImageBitmap> imageBitmap(adoptRef(new ImageBitmap(bitmap, normalizedC ropRect))); |
| 136 return imageBitmap.release(); | 140 return imageBitmap.release(); |
| 137 } | 141 } |
| 138 | 142 |
| 139 } | 143 } |
| OLD | NEW |