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 13 matching lines...) Expand all Loading... |
24 std::max(rect.width(), -rect.width()), | 24 std::max(rect.width(), -rect.width()), |
25 std::max(rect.height(), -rect.height())); | 25 std::max(rect.height(), -rect.height())); |
26 } | 26 } |
27 | 27 |
28 static inline PassRefPtr<Image> cropImage(Image* image, const IntRect& cropRect) | 28 static inline PassRefPtr<Image> cropImage(Image* image, const IntRect& cropRect) |
29 { | 29 { |
30 IntRect intersectRect = intersection(IntRect(IntPoint(), image->size()), cro
pRect); | 30 IntRect intersectRect = intersection(IntRect(IntPoint(), image->size()), cro
pRect); |
31 if (!intersectRect.width() || !intersectRect.height()) | 31 if (!intersectRect.width() || !intersectRect.height()) |
32 return nullptr; | 32 return nullptr; |
33 | 33 |
| 34 SkBitmap bitmap; |
| 35 if (!image->bitmapForCurrentFrame(&bitmap)) |
| 36 return nullptr; |
| 37 |
34 SkBitmap cropped; | 38 SkBitmap cropped; |
35 image->nativeImageForCurrentFrame()->bitmap().extractSubset(&cropped, inters
ectRect); | 39 bitmap.extractSubset(&cropped, intersectRect); |
36 return BitmapImage::create(NativeImageSkia::create(cropped)); | 40 return BitmapImage::create(cropped); |
37 } | 41 } |
38 | 42 |
39 ImageBitmap::ImageBitmap(HTMLImageElement* image, const IntRect& cropRect) | 43 ImageBitmap::ImageBitmap(HTMLImageElement* image, const IntRect& cropRect) |
40 : m_imageElement(image) | 44 : m_imageElement(image) |
41 , m_bitmap(nullptr) | 45 , m_bitmap(nullptr) |
42 , m_cropRect(cropRect) | 46 , m_cropRect(cropRect) |
43 { | 47 { |
44 IntRect srcRect = intersection(cropRect, IntRect(0, 0, image->width(), image
->height())); | 48 IntRect srcRect = intersection(cropRect, IntRect(0, 0, image->width(), image
->height())); |
45 m_bitmapRect = IntRect(IntPoint(std::max(0, -cropRect.x()), std::max(0, -cro
pRect.y())), srcRect.size()); | 49 m_bitmapRect = IntRect(IntPoint(std::max(0, -cropRect.x()), std::max(0, -cro
pRect.y())), srcRect.size()); |
46 m_bitmapOffset = srcRect.location(); | 50 m_bitmapOffset = srcRect.location(); |
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
235 return FloatSize(width(), height()); | 239 return FloatSize(width(), height()); |
236 } | 240 } |
237 | 241 |
238 DEFINE_TRACE(ImageBitmap) | 242 DEFINE_TRACE(ImageBitmap) |
239 { | 243 { |
240 visitor->trace(m_imageElement); | 244 visitor->trace(m_imageElement); |
241 ImageLoaderClient::trace(visitor); | 245 ImageLoaderClient::trace(visitor); |
242 } | 246 } |
243 | 247 |
244 } // namespace blink | 248 } // namespace blink |
OLD | NEW |