| 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/frame/ImageBitmap.h" | 6 #include "core/frame/ImageBitmap.h" |
| 7 | 7 |
| 8 #include "core/html/HTMLCanvasElement.h" | 8 #include "core/html/HTMLCanvasElement.h" |
| 9 #include "core/html/HTMLVideoElement.h" | 9 #include "core/html/HTMLVideoElement.h" |
| 10 #include "core/html/ImageData.h" | 10 #include "core/html/ImageData.h" |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 56 | 56 |
| 57 ImageBitmap::ImageBitmap(HTMLVideoElement* video, const IntRect& cropRect) | 57 ImageBitmap::ImageBitmap(HTMLVideoElement* video, const IntRect& cropRect) |
| 58 : m_imageElement(0) | 58 : m_imageElement(0) |
| 59 , m_cropRect(cropRect) | 59 , m_cropRect(cropRect) |
| 60 , m_bitmapOffset(IntPoint()) | 60 , m_bitmapOffset(IntPoint()) |
| 61 { | 61 { |
| 62 IntRect videoRect = IntRect(IntPoint(), video->player()->naturalSize()); | 62 IntRect videoRect = IntRect(IntPoint(), video->player()->naturalSize()); |
| 63 IntRect srcRect = intersection(cropRect, videoRect); | 63 IntRect srcRect = intersection(cropRect, videoRect); |
| 64 IntRect dstRect(IntPoint(), srcRect.size()); | 64 IntRect dstRect(IntPoint(), srcRect.size()); |
| 65 | 65 |
| 66 OwnPtr<ImageBuffer> buf = ImageBuffer::create(videoRect.size(), 1, Unacceler
atedNonPlatformBuffer); | 66 OwnPtr<ImageBuffer> buf = ImageBuffer::create(videoRect.size()); |
| 67 if (!buf) |
| 68 return; |
| 67 GraphicsContext* c = buf->context(); | 69 GraphicsContext* c = buf->context(); |
| 68 c->clip(dstRect); | 70 c->clip(dstRect); |
| 69 c->translate(-srcRect.x(), -srcRect.y()); | 71 c->translate(-srcRect.x(), -srcRect.y()); |
| 70 video->paintCurrentFrameInContext(c, videoRect); | 72 video->paintCurrentFrameInContext(c, videoRect); |
| 71 m_bitmap = buf->copyImage(DontCopyBackingStore); | 73 m_bitmap = buf->copyImage(DontCopyBackingStore); |
| 72 m_bitmapRect = IntRect(IntPoint(max(0, -cropRect.x()), max(0, -cropRect.y())
), srcRect.size()); | 74 m_bitmapRect = IntRect(IntPoint(max(0, -cropRect.x()), max(0, -cropRect.y())
), srcRect.size()); |
| 73 | 75 |
| 74 ScriptWrappable::init(this); | 76 ScriptWrappable::init(this); |
| 75 } | 77 } |
| 76 | 78 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 90 ScriptWrappable::init(this); | 92 ScriptWrappable::init(this); |
| 91 } | 93 } |
| 92 | 94 |
| 93 ImageBitmap::ImageBitmap(ImageData* data, const IntRect& cropRect) | 95 ImageBitmap::ImageBitmap(ImageData* data, const IntRect& cropRect) |
| 94 : m_imageElement(0) | 96 : m_imageElement(0) |
| 95 , m_cropRect(cropRect) | 97 , m_cropRect(cropRect) |
| 96 , m_bitmapOffset(IntPoint()) | 98 , m_bitmapOffset(IntPoint()) |
| 97 { | 99 { |
| 98 IntRect srcRect = intersection(cropRect, IntRect(IntPoint(), data->size())); | 100 IntRect srcRect = intersection(cropRect, IntRect(IntPoint(), data->size())); |
| 99 | 101 |
| 100 OwnPtr<ImageBuffer> buf = ImageBuffer::create(data->size(), 1, Unaccelerated
NonPlatformBuffer); | 102 OwnPtr<ImageBuffer> buf = ImageBuffer::create(data->size()); |
| 103 if (!buf) |
| 104 return; |
| 101 if (srcRect.width() > 0 && srcRect.height() > 0) | 105 if (srcRect.width() > 0 && srcRect.height() > 0) |
| 102 buf->putByteArray(Premultiplied, data->data(), data->size(), srcRect, In
tPoint(min(0, -cropRect.x()), min(0, -cropRect.y()))); | 106 buf->putByteArray(Premultiplied, data->data(), data->size(), srcRect, In
tPoint(min(0, -cropRect.x()), min(0, -cropRect.y()))); |
| 103 | 107 |
| 104 m_bitmap = buf->copyImage(DontCopyBackingStore); | 108 m_bitmap = buf->copyImage(DontCopyBackingStore); |
| 105 m_bitmapRect = IntRect(IntPoint(max(0, -cropRect.x()), max(0, -cropRect.y())
), srcRect.size()); | 109 m_bitmapRect = IntRect(IntPoint(max(0, -cropRect.x()), max(0, -cropRect.y())
), srcRect.size()); |
| 106 | 110 |
| 107 ScriptWrappable::init(this); | 111 ScriptWrappable::init(this); |
| 108 } | 112 } |
| 109 | 113 |
| 110 ImageBitmap::ImageBitmap(ImageBitmap* bitmap, const IntRect& cropRect) | 114 ImageBitmap::ImageBitmap(ImageBitmap* bitmap, const IntRect& cropRect) |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 190 | 194 |
| 191 PassRefPtr<Image> ImageBitmap::bitmapImage() const | 195 PassRefPtr<Image> ImageBitmap::bitmapImage() const |
| 192 { | 196 { |
| 193 ASSERT((m_imageElement || m_bitmap || !m_bitmapRect.width() || !m_bitmapRect
.height()) && (!m_imageElement || !m_bitmap)); | 197 ASSERT((m_imageElement || m_bitmap || !m_bitmapRect.width() || !m_bitmapRect
.height()) && (!m_imageElement || !m_bitmap)); |
| 194 if (m_imageElement) | 198 if (m_imageElement) |
| 195 return m_imageElement->cachedImage()->image(); | 199 return m_imageElement->cachedImage()->image(); |
| 196 return m_bitmap; | 200 return m_bitmap; |
| 197 } | 201 } |
| 198 | 202 |
| 199 } | 203 } |
| OLD | NEW |