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" | |
9 #include "core/html/HTMLVideoElement.h" | 8 #include "core/html/HTMLVideoElement.h" |
10 #include "core/html/ImageData.h" | 9 #include "core/html/ImageData.h" |
11 #include "core/html/canvas/CanvasRenderingContext.h" | |
12 #include "platform/graphics/BitmapImage.h" | 10 #include "platform/graphics/BitmapImage.h" |
13 #include "platform/graphics/GraphicsContext.h" | 11 #include "platform/graphics/GraphicsContext.h" |
14 #include "platform/graphics/ImageBuffer.h" | 12 #include "platform/graphics/ImageBuffer.h" |
15 #include "wtf/RefPtr.h" | 13 #include "wtf/RefPtr.h" |
16 | 14 |
17 namespace blink { | 15 namespace blink { |
18 | 16 |
19 static inline IntRect normalizeRect(const IntRect& rect) | 17 static inline IntRect normalizeRect(const IntRect& rect) |
20 { | 18 { |
21 return IntRect(std::min(rect.x(), rect.maxX()), | 19 return IntRect(std::min(rect.x(), rect.maxX()), |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
68 if (!buf) | 66 if (!buf) |
69 return; | 67 return; |
70 GraphicsContext* c = buf->context(); | 68 GraphicsContext* c = buf->context(); |
71 c->clip(dstRect); | 69 c->clip(dstRect); |
72 c->translate(-srcRect.x(), -srcRect.y()); | 70 c->translate(-srcRect.x(), -srcRect.y()); |
73 video->paintCurrentFrameInContext(c, videoRect); | 71 video->paintCurrentFrameInContext(c, videoRect); |
74 m_bitmap = buf->copyImage(DontCopyBackingStore); | 72 m_bitmap = buf->copyImage(DontCopyBackingStore); |
75 m_bitmapRect = IntRect(IntPoint(std::max(0, -cropRect.x()), std::max(0, -cro
pRect.y())), srcRect.size()); | 73 m_bitmapRect = IntRect(IntPoint(std::max(0, -cropRect.x()), std::max(0, -cro
pRect.y())), srcRect.size()); |
76 } | 74 } |
77 | 75 |
78 ImageBitmap::ImageBitmap(HTMLCanvasElement* canvas, const IntRect& cropRect) | |
79 : m_imageElement(nullptr) | |
80 , m_cropRect(cropRect) | |
81 , m_bitmapOffset(IntPoint()) | |
82 { | |
83 CanvasRenderingContext* sourceContext = canvas->renderingContext(); | |
84 if (sourceContext && sourceContext->is3d()) | |
85 sourceContext->paintRenderingResultsToCanvas(BackBuffer); | |
86 | |
87 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()); | |
89 m_bitmap = cropImage(canvas->buffer()->copyImage(CopyBackingStore).get(), cr
opRect); | |
90 } | |
91 | |
92 ImageBitmap::ImageBitmap(ImageData* data, const IntRect& cropRect) | 76 ImageBitmap::ImageBitmap(ImageData* data, const IntRect& cropRect) |
93 : m_imageElement(nullptr) | 77 : m_imageElement(nullptr) |
94 , m_cropRect(cropRect) | 78 , m_cropRect(cropRect) |
95 , m_bitmapOffset(IntPoint()) | 79 , m_bitmapOffset(IntPoint()) |
96 { | 80 { |
97 IntRect srcRect = intersection(cropRect, IntRect(IntPoint(), data->size())); | 81 IntRect srcRect = intersection(cropRect, IntRect(IntPoint(), data->size())); |
98 | 82 |
99 OwnPtr<ImageBuffer> buf = ImageBuffer::create(data->size()); | 83 OwnPtr<ImageBuffer> buf = ImageBuffer::create(data->size()); |
100 if (!buf) | 84 if (!buf) |
101 return; | 85 return; |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
147 IntRect normalizedCropRect = normalizeRect(cropRect); | 131 IntRect normalizedCropRect = normalizeRect(cropRect); |
148 return adoptRefWillBeNoop(new ImageBitmap(image, normalizedCropRect)); | 132 return adoptRefWillBeNoop(new ImageBitmap(image, normalizedCropRect)); |
149 } | 133 } |
150 | 134 |
151 PassRefPtrWillBeRawPtr<ImageBitmap> ImageBitmap::create(HTMLVideoElement* video,
const IntRect& cropRect) | 135 PassRefPtrWillBeRawPtr<ImageBitmap> ImageBitmap::create(HTMLVideoElement* video,
const IntRect& cropRect) |
152 { | 136 { |
153 IntRect normalizedCropRect = normalizeRect(cropRect); | 137 IntRect normalizedCropRect = normalizeRect(cropRect); |
154 return adoptRefWillBeNoop(new ImageBitmap(video, normalizedCropRect)); | 138 return adoptRefWillBeNoop(new ImageBitmap(video, normalizedCropRect)); |
155 } | 139 } |
156 | 140 |
157 PassRefPtrWillBeRawPtr<ImageBitmap> ImageBitmap::create(HTMLCanvasElement* canva
s, const IntRect& cropRect) | |
158 { | |
159 IntRect normalizedCropRect = normalizeRect(cropRect); | |
160 return adoptRefWillBeNoop(new ImageBitmap(canvas, normalizedCropRect)); | |
161 } | |
162 | |
163 PassRefPtrWillBeRawPtr<ImageBitmap> ImageBitmap::create(ImageData* data, const I
ntRect& cropRect) | 141 PassRefPtrWillBeRawPtr<ImageBitmap> ImageBitmap::create(ImageData* data, const I
ntRect& cropRect) |
164 { | 142 { |
165 IntRect normalizedCropRect = normalizeRect(cropRect); | 143 IntRect normalizedCropRect = normalizeRect(cropRect); |
166 return adoptRefWillBeNoop(new ImageBitmap(data, normalizedCropRect)); | 144 return adoptRefWillBeNoop(new ImageBitmap(data, normalizedCropRect)); |
167 } | 145 } |
168 | 146 |
169 PassRefPtrWillBeRawPtr<ImageBitmap> ImageBitmap::create(ImageBitmap* bitmap, con
st IntRect& cropRect) | 147 PassRefPtrWillBeRawPtr<ImageBitmap> ImageBitmap::create(ImageBitmap* bitmap, con
st IntRect& cropRect) |
170 { | 148 { |
171 IntRect normalizedCropRect = normalizeRect(cropRect); | 149 IntRect normalizedCropRect = normalizeRect(cropRect); |
172 return adoptRefWillBeNoop(new ImageBitmap(bitmap, normalizedCropRect)); | 150 return adoptRefWillBeNoop(new ImageBitmap(bitmap, normalizedCropRect)); |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
217 return FloatSize(width(), height()); | 195 return FloatSize(width(), height()); |
218 } | 196 } |
219 | 197 |
220 void ImageBitmap::trace(Visitor* visitor) | 198 void ImageBitmap::trace(Visitor* visitor) |
221 { | 199 { |
222 visitor->trace(m_imageElement); | 200 visitor->trace(m_imageElement); |
223 ImageLoaderClient::trace(visitor); | 201 ImageLoaderClient::trace(visitor); |
224 } | 202 } |
225 | 203 |
226 } // namespace blink | 204 } // namespace blink |
OLD | NEW |