| 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 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 82 } | 82 } |
| 83 | 83 |
| 84 ImageBitmap::ImageBitmap(HTMLCanvasElement* canvas, const IntRect& cropRect) | 84 ImageBitmap::ImageBitmap(HTMLCanvasElement* canvas, const IntRect& cropRect) |
| 85 : m_imageElement(nullptr) | 85 : m_imageElement(nullptr) |
| 86 , m_cropRect(cropRect) | 86 , m_cropRect(cropRect) |
| 87 , m_bitmapOffset(IntPoint()) | 87 , m_bitmapOffset(IntPoint()) |
| 88 { | 88 { |
| 89 IntRect srcRect = intersection(cropRect, IntRect(IntPoint(), canvas->size())
); | 89 IntRect srcRect = intersection(cropRect, IntRect(IntPoint(), canvas->size())
); |
| 90 m_bitmapRect = IntRect(IntPoint(std::max(0, -cropRect.x()), std::max(0, -cro
pRect.y())), srcRect.size()); | 90 m_bitmapRect = IntRect(IntPoint(std::max(0, -cropRect.x()), std::max(0, -cro
pRect.y())), srcRect.size()); |
| 91 ASSERT(canvas->isPaintable()); | 91 ASSERT(canvas->isPaintable()); |
| 92 m_bitmap = cropImage(canvas->copiedImage(BackBuffer), cropRect); | 92 m_bitmap = cropImage(canvas->copiedImage(BackBuffer, PreferAcceleration), cr
opRect); |
| 93 } | 93 } |
| 94 | 94 |
| 95 ImageBitmap::ImageBitmap(ImageData* data, const IntRect& cropRect) | 95 ImageBitmap::ImageBitmap(ImageData* data, const IntRect& cropRect) |
| 96 : m_imageElement(nullptr) | 96 : m_imageElement(nullptr) |
| 97 , m_cropRect(cropRect) | 97 , m_cropRect(cropRect) |
| 98 , m_bitmapOffset(IntPoint()) | 98 , m_bitmapOffset(IntPoint()) |
| 99 { | 99 { |
| 100 IntRect srcRect = intersection(cropRect, IntRect(IntPoint(), data->size())); | 100 IntRect srcRect = intersection(cropRect, IntRect(IntPoint(), data->size())); |
| 101 OwnPtr<ImageBuffer> buffer = ImageBuffer::create(data->size()); | 101 OwnPtr<ImageBuffer> buffer = ImageBuffer::create(data->size()); |
| 102 if (!buffer) | 102 if (!buffer) |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 189 } | 189 } |
| 190 | 190 |
| 191 PassRefPtr<Image> ImageBitmap::bitmapImage() const | 191 PassRefPtr<Image> ImageBitmap::bitmapImage() const |
| 192 { | 192 { |
| 193 ASSERT((m_imageElement || m_bitmap || !m_bitmapRect.width() || !m_bitmapRect
.height()) && (!m_imageElement || !m_bitmap)); | 193 ASSERT((m_imageElement || m_bitmap || !m_bitmapRect.width() || !m_bitmapRect
.height()) && (!m_imageElement || !m_bitmap)); |
| 194 if (m_imageElement) | 194 if (m_imageElement) |
| 195 return m_imageElement->cachedImage()->image(); | 195 return m_imageElement->cachedImage()->image(); |
| 196 return m_bitmap; | 196 return m_bitmap; |
| 197 } | 197 } |
| 198 | 198 |
| 199 PassRefPtr<Image> ImageBitmap::getSourceImageForCanvas(SourceImageStatus* status
) const | 199 PassRefPtr<Image> ImageBitmap::getSourceImageForCanvas(SourceImageStatus* status
, AccelerationHint) const |
| 200 { | 200 { |
| 201 *status = NormalSourceImageStatus; | 201 *status = NormalSourceImageStatus; |
| 202 return bitmapImage(); | 202 return bitmapImage(); |
| 203 } | 203 } |
| 204 | 204 |
| 205 void ImageBitmap::adjustDrawRects(FloatRect* srcRect, FloatRect* dstRect) const | 205 void ImageBitmap::adjustDrawRects(FloatRect* srcRect, FloatRect* dstRect) const |
| 206 { | 206 { |
| 207 FloatRect intersectRect = intersection(m_bitmapRect, *srcRect); | 207 FloatRect intersectRect = intersection(m_bitmapRect, *srcRect); |
| 208 FloatRect newSrcRect = intersectRect; | 208 FloatRect newSrcRect = intersectRect; |
| 209 newSrcRect.move(m_bitmapOffset - m_bitmapRect.location()); | 209 newSrcRect.move(m_bitmapOffset - m_bitmapRect.location()); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 220 return FloatSize(width(), height()); | 220 return FloatSize(width(), height()); |
| 221 } | 221 } |
| 222 | 222 |
| 223 DEFINE_TRACE(ImageBitmap) | 223 DEFINE_TRACE(ImageBitmap) |
| 224 { | 224 { |
| 225 visitor->trace(m_imageElement); | 225 visitor->trace(m_imageElement); |
| 226 ImageLoaderClient::trace(visitor); | 226 ImageLoaderClient::trace(visitor); |
| 227 } | 227 } |
| 228 | 228 |
| 229 } // namespace blink | 229 } // namespace blink |
| OLD | NEW |