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" |
11 #include "core/html/canvas/CanvasRenderingContext.h" | |
12 #include "platform/graphics/BitmapImage.h" | 11 #include "platform/graphics/BitmapImage.h" |
13 #include "platform/graphics/GraphicsContext.h" | 12 #include "platform/graphics/GraphicsContext.h" |
14 #include "platform/graphics/ImageBuffer.h" | 13 #include "platform/graphics/ImageBuffer.h" |
15 #include "wtf/RefPtr.h" | 14 #include "wtf/RefPtr.h" |
16 | 15 |
17 namespace blink { | 16 namespace blink { |
18 | 17 |
19 static inline IntRect normalizeRect(const IntRect& rect) | 18 static inline IntRect normalizeRect(const IntRect& rect) |
20 { | 19 { |
21 return IntRect(std::min(rect.x(), rect.maxX()), | 20 return IntRect(std::min(rect.x(), rect.maxX()), |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
73 video->paintCurrentFrameInContext(c, videoRect); | 72 video->paintCurrentFrameInContext(c, videoRect); |
74 m_bitmap = buf->copyImage(DontCopyBackingStore); | 73 m_bitmap = buf->copyImage(DontCopyBackingStore); |
75 m_bitmapRect = IntRect(IntPoint(std::max(0, -cropRect.x()), std::max(0, -cro
pRect.y())), srcRect.size()); | 74 m_bitmapRect = IntRect(IntPoint(std::max(0, -cropRect.x()), std::max(0, -cro
pRect.y())), srcRect.size()); |
76 } | 75 } |
77 | 76 |
78 ImageBitmap::ImageBitmap(HTMLCanvasElement* canvas, const IntRect& cropRect) | 77 ImageBitmap::ImageBitmap(HTMLCanvasElement* canvas, const IntRect& cropRect) |
79 : m_imageElement(nullptr) | 78 : m_imageElement(nullptr) |
80 , m_cropRect(cropRect) | 79 , m_cropRect(cropRect) |
81 , m_bitmapOffset(IntPoint()) | 80 , m_bitmapOffset(IntPoint()) |
82 { | 81 { |
83 CanvasRenderingContext* sourceContext = canvas->renderingContext(); | |
84 if (sourceContext && sourceContext->is3d()) | |
85 sourceContext->paintRenderingResultsToCanvas(BackBuffer); | |
86 | |
87 IntRect srcRect = intersection(cropRect, IntRect(IntPoint(), canvas->size())
); | 82 IntRect srcRect = intersection(cropRect, IntRect(IntPoint(), canvas->size())
); |
88 m_bitmapRect = IntRect(IntPoint(std::max(0, -cropRect.x()), std::max(0, -cro
pRect.y())), srcRect.size()); | 83 m_bitmapRect = IntRect(IntPoint(std::max(0, -cropRect.x()), std::max(0, -cro
pRect.y())), srcRect.size()); |
89 m_bitmap = cropImage(canvas->buffer()->copyImage(CopyBackingStore).get(), cr
opRect); | 84 ASSERT(canvas->isPaintable()); |
| 85 m_bitmap = cropImage(canvas->copiedImage(BackBuffer).get(), cropRect); |
90 } | 86 } |
91 | 87 |
92 ImageBitmap::ImageBitmap(ImageData* data, const IntRect& cropRect) | 88 ImageBitmap::ImageBitmap(ImageData* data, const IntRect& cropRect) |
93 : m_imageElement(nullptr) | 89 : m_imageElement(nullptr) |
94 , m_cropRect(cropRect) | 90 , m_cropRect(cropRect) |
95 , m_bitmapOffset(IntPoint()) | 91 , m_bitmapOffset(IntPoint()) |
96 { | 92 { |
97 IntRect srcRect = intersection(cropRect, IntRect(IntPoint(), data->size())); | 93 IntRect srcRect = intersection(cropRect, IntRect(IntPoint(), data->size())); |
98 | 94 |
99 OwnPtr<ImageBuffer> buf = ImageBuffer::create(data->size()); | 95 OwnPtr<ImageBuffer> buf = ImageBuffer::create(data->size()); |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
217 return FloatSize(width(), height()); | 213 return FloatSize(width(), height()); |
218 } | 214 } |
219 | 215 |
220 void ImageBitmap::trace(Visitor* visitor) | 216 void ImageBitmap::trace(Visitor* visitor) |
221 { | 217 { |
222 visitor->trace(m_imageElement); | 218 visitor->trace(m_imageElement); |
223 ImageLoaderClient::trace(visitor); | 219 ImageLoaderClient::trace(visitor); |
224 } | 220 } |
225 | 221 |
226 } // namespace blink | 222 } // namespace blink |
OLD | NEW |