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