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 "core/frame/ImageBitmap.h" | 5 #include "core/frame/ImageBitmap.h" |
6 | 6 |
7 #include "core/html/HTMLCanvasElement.h" | 7 #include "core/html/HTMLCanvasElement.h" |
8 #include "core/html/HTMLVideoElement.h" | 8 #include "core/html/HTMLVideoElement.h" |
9 #include "core/html/ImageData.h" | 9 #include "core/html/ImageData.h" |
10 #include "third_party/skia/include/core/SkSurface.h" | 10 #include "third_party/skia/include/core/SkSurface.h" |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
58 playerSize = video->webMediaPlayer()->naturalSize(); | 58 playerSize = video->webMediaPlayer()->naturalSize(); |
59 | 59 |
60 IntRect videoRect = IntRect(IntPoint(), playerSize); | 60 IntRect videoRect = IntRect(IntPoint(), playerSize); |
61 IntRect srcRect = intersection(cropRect, videoRect); | 61 IntRect srcRect = intersection(cropRect, videoRect); |
62 OwnPtr<ImageBuffer> buffer = ImageBuffer::create(cropRect.size(), NonOpaque,
DoNotInitializeImagePixels); | 62 OwnPtr<ImageBuffer> buffer = ImageBuffer::create(cropRect.size(), NonOpaque,
DoNotInitializeImagePixels); |
63 if (!buffer) | 63 if (!buffer) |
64 return; | 64 return; |
65 | 65 |
66 IntPoint dstPoint = IntPoint(std::max(0, -cropRect.x()), std::max(0, -cropRe
ct.y())); | 66 IntPoint dstPoint = IntPoint(std::max(0, -cropRect.x()), std::max(0, -cropRe
ct.y())); |
67 video->paintCurrentFrame(buffer->canvas(), IntRect(dstPoint, srcRect.size())
, nullptr); | 67 video->paintCurrentFrame(buffer->canvas(), IntRect(dstPoint, srcRect.size())
, nullptr); |
68 m_image = StaticBitmapImage::create(buffer->newSkImageSnapshot(PreferNoAccel
eration)); | 68 m_image = StaticBitmapImage::create(buffer->newSkImageSnapshot(PreferNoAccel
eration, SnapshotReasonUnknown)); |
69 m_image->setOriginClean(!video->wouldTaintOrigin(document->securityOrigin())
); | 69 m_image->setOriginClean(!video->wouldTaintOrigin(document->securityOrigin())
); |
70 } | 70 } |
71 | 71 |
72 ImageBitmap::ImageBitmap(HTMLCanvasElement* canvas, const IntRect& cropRect) | 72 ImageBitmap::ImageBitmap(HTMLCanvasElement* canvas, const IntRect& cropRect) |
73 { | 73 { |
74 ASSERT(canvas->isPaintable()); | 74 ASSERT(canvas->isPaintable()); |
75 m_image = cropImage(canvas->copiedImage(BackBuffer, PreferAcceleration).get(
), cropRect); | 75 m_image = cropImage(canvas->copiedImage(BackBuffer, PreferAcceleration).get(
), cropRect); |
76 m_image->setOriginClean(canvas->originClean()); | 76 m_image->setOriginClean(canvas->originClean()); |
77 } | 77 } |
78 | 78 |
79 ImageBitmap::ImageBitmap(ImageData* data, const IntRect& cropRect) | 79 ImageBitmap::ImageBitmap(ImageData* data, const IntRect& cropRect) |
80 { | 80 { |
81 IntRect srcRect = intersection(cropRect, IntRect(IntPoint(), data->size())); | 81 IntRect srcRect = intersection(cropRect, IntRect(IntPoint(), data->size())); |
82 | 82 |
83 OwnPtr<ImageBuffer> buffer = ImageBuffer::create(cropRect.size(), NonOpaque,
DoNotInitializeImagePixels); | 83 OwnPtr<ImageBuffer> buffer = ImageBuffer::create(cropRect.size(), NonOpaque,
DoNotInitializeImagePixels); |
84 if (!buffer) | 84 if (!buffer) |
85 return; | 85 return; |
86 | 86 |
87 if (srcRect.isEmpty()) { | 87 if (srcRect.isEmpty()) { |
88 m_image = StaticBitmapImage::create(buffer->newSkImageSnapshot(PreferNoA
cceleration)); | 88 m_image = StaticBitmapImage::create(buffer->newSkImageSnapshot(PreferNoA
cceleration, SnapshotReasonUnknown)); |
89 return; | 89 return; |
90 } | 90 } |
91 | 91 |
92 IntPoint dstPoint = IntPoint(std::min(0, -cropRect.x()), std::min(0, -cropRe
ct.y())); | 92 IntPoint dstPoint = IntPoint(std::min(0, -cropRect.x()), std::min(0, -cropRe
ct.y())); |
93 if (cropRect.x() < 0) | 93 if (cropRect.x() < 0) |
94 dstPoint.setX(-cropRect.x()); | 94 dstPoint.setX(-cropRect.x()); |
95 if (cropRect.y() < 0) | 95 if (cropRect.y() < 0) |
96 dstPoint.setY(-cropRect.y()); | 96 dstPoint.setY(-cropRect.y()); |
97 buffer->putByteArray(Unmultiplied, data->data()->data(), data->size(), srcRe
ct, dstPoint); | 97 buffer->putByteArray(Unmultiplied, data->data()->data(), data->size(), srcRe
ct, dstPoint); |
98 m_image = StaticBitmapImage::create(buffer->newSkImageSnapshot(PreferNoAccel
eration)); | 98 m_image = StaticBitmapImage::create(buffer->newSkImageSnapshot(PreferNoAccel
eration, SnapshotReasonUnknown)); |
99 } | 99 } |
100 | 100 |
101 ImageBitmap::ImageBitmap(ImageBitmap* bitmap, const IntRect& cropRect) | 101 ImageBitmap::ImageBitmap(ImageBitmap* bitmap, const IntRect& cropRect) |
102 { | 102 { |
103 m_image = cropImage(bitmap->bitmapImage(), cropRect); | 103 m_image = cropImage(bitmap->bitmapImage(), cropRect); |
104 m_image->setOriginClean(bitmap->originClean()); | 104 m_image->setOriginClean(bitmap->originClean()); |
105 } | 105 } |
106 | 106 |
107 ImageBitmap::ImageBitmap(PassRefPtr<StaticBitmapImage> image, const IntRect& cro
pRect) | 107 ImageBitmap::ImageBitmap(PassRefPtr<StaticBitmapImage> image, const IntRect& cro
pRect) |
108 { | 108 { |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
197 exceptionState.throwDOMException(IndexSizeError, String::format("The sou
rce %s provided is 0.", sw ? "height" : "width")); | 197 exceptionState.throwDOMException(IndexSizeError, String::format("The sou
rce %s provided is 0.", sw ? "height" : "width")); |
198 return ScriptPromise(); | 198 return ScriptPromise(); |
199 } | 199 } |
200 return ImageBitmapSource::fulfillImageBitmap(scriptState, create(this, IntRe
ct(sx, sy, sw, sh))); | 200 return ImageBitmapSource::fulfillImageBitmap(scriptState, create(this, IntRe
ct(sx, sy, sw, sh))); |
201 } | 201 } |
202 | 202 |
203 void ImageBitmap::notifyImageSourceChanged() | 203 void ImageBitmap::notifyImageSourceChanged() |
204 { | 204 { |
205 } | 205 } |
206 | 206 |
207 PassRefPtr<Image> ImageBitmap::getSourceImageForCanvas(SourceImageStatus* status
, AccelerationHint) const | 207 PassRefPtr<Image> ImageBitmap::getSourceImageForCanvas(SourceImageStatus* status
, AccelerationHint, SnapshotReason) const |
208 { | 208 { |
209 *status = NormalSourceImageStatus; | 209 *status = NormalSourceImageStatus; |
210 return m_image ? m_image : nullptr; | 210 return m_image ? m_image : nullptr; |
211 } | 211 } |
212 | 212 |
213 void ImageBitmap::adjustDrawRects(FloatRect* srcRect, FloatRect* dstRect) const | 213 void ImageBitmap::adjustDrawRects(FloatRect* srcRect, FloatRect* dstRect) const |
214 { | 214 { |
215 } | 215 } |
216 | 216 |
217 FloatSize ImageBitmap::elementSize() const | 217 FloatSize ImageBitmap::elementSize() const |
218 { | 218 { |
219 return FloatSize(width(), height()); | 219 return FloatSize(width(), height()); |
220 } | 220 } |
221 | 221 |
222 DEFINE_TRACE(ImageBitmap) | 222 DEFINE_TRACE(ImageBitmap) |
223 { | 223 { |
224 ImageLoaderClient::trace(visitor); | 224 ImageLoaderClient::trace(visitor); |
225 } | 225 } |
226 | 226 |
227 } // namespace blink | 227 } // namespace blink |
OLD | NEW |