| 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 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 88 | 88 |
| 89 IntRect videoRect = IntRect(IntPoint(), playerSize); | 89 IntRect videoRect = IntRect(IntPoint(), playerSize); |
| 90 IntRect srcRect = intersection(cropRect, videoRect); | 90 IntRect srcRect = intersection(cropRect, videoRect); |
| 91 OwnPtr<ImageBuffer> buffer = ImageBuffer::create(cropRect.size(), NonOpaque,
DoNotInitializeImagePixels); | 91 OwnPtr<ImageBuffer> buffer = ImageBuffer::create(cropRect.size(), NonOpaque,
DoNotInitializeImagePixels); |
| 92 if (!buffer) | 92 if (!buffer) |
| 93 return; | 93 return; |
| 94 | 94 |
| 95 IntPoint dstPoint = IntPoint(std::max(0, -cropRect.x()), std::max(0, -cropRe
ct.y())); | 95 IntPoint dstPoint = IntPoint(std::max(0, -cropRect.x()), std::max(0, -cropRe
ct.y())); |
| 96 video->paintCurrentFrame(buffer->canvas(), IntRect(dstPoint, srcRect.size())
, nullptr); | 96 video->paintCurrentFrame(buffer->canvas(), IntRect(dstPoint, srcRect.size())
, nullptr); |
| 97 if (options.imageOrientation() == imageOrientationFlipY) | 97 if (options.imageOrientation() == imageOrientationFlipY) |
| 98 m_image = StaticBitmapImage::create(adoptRef(flipSkImageVertically(buffe
r->newSkImageSnapshot(PreferNoAcceleration).get()))); | 98 m_image = StaticBitmapImage::create(adoptRef(flipSkImageVertically(buffe
r->newSkImageSnapshot(PreferNoAcceleration, SnapshotReasonUnknown).get()))); |
| 99 else | 99 else |
| 100 m_image = StaticBitmapImage::create(buffer->newSkImageSnapshot(PreferNoA
cceleration)); | 100 m_image = StaticBitmapImage::create(buffer->newSkImageSnapshot(PreferNoA
cceleration, SnapshotReasonUnknown)); |
| 101 m_image->setOriginClean(!video->wouldTaintOrigin(document->securityOrigin())
); | 101 m_image->setOriginClean(!video->wouldTaintOrigin(document->securityOrigin())
); |
| 102 } | 102 } |
| 103 | 103 |
| 104 ImageBitmap::ImageBitmap(HTMLCanvasElement* canvas, const IntRect& cropRect, con
st ImageBitmapOptions& options) | 104 ImageBitmap::ImageBitmap(HTMLCanvasElement* canvas, const IntRect& cropRect, con
st ImageBitmapOptions& options) |
| 105 { | 105 { |
| 106 ASSERT(canvas->isPaintable()); | 106 ASSERT(canvas->isPaintable()); |
| 107 if (options.imageOrientation() == imageOrientationFlipY) | 107 if (options.imageOrientation() == imageOrientationFlipY) |
| 108 m_image = cropImage(canvas->copiedImage(BackBuffer, PreferAcceleration).
get(), cropRect, true); | 108 m_image = cropImage(canvas->copiedImage(BackBuffer, PreferAcceleration).
get(), cropRect, true); |
| 109 else | 109 else |
| 110 m_image = cropImage(canvas->copiedImage(BackBuffer, PreferAcceleration).
get(), cropRect, false); | 110 m_image = cropImage(canvas->copiedImage(BackBuffer, PreferAcceleration).
get(), cropRect, false); |
| 111 m_image->setOriginClean(canvas->originClean()); | 111 m_image->setOriginClean(canvas->originClean()); |
| 112 } | 112 } |
| 113 | 113 |
| 114 ImageBitmap::ImageBitmap(ImageData* data, const IntRect& cropRect, const ImageBi
tmapOptions& options) | 114 ImageBitmap::ImageBitmap(ImageData* data, const IntRect& cropRect, const ImageBi
tmapOptions& options) |
| 115 { | 115 { |
| 116 IntRect srcRect = intersection(cropRect, IntRect(IntPoint(), data->size())); | 116 IntRect srcRect = intersection(cropRect, IntRect(IntPoint(), data->size())); |
| 117 | 117 |
| 118 OwnPtr<ImageBuffer> buffer = ImageBuffer::create(cropRect.size(), NonOpaque,
DoNotInitializeImagePixels); | 118 OwnPtr<ImageBuffer> buffer = ImageBuffer::create(cropRect.size(), NonOpaque,
DoNotInitializeImagePixels); |
| 119 if (!buffer) | 119 if (!buffer) |
| 120 return; | 120 return; |
| 121 | 121 |
| 122 if (srcRect.isEmpty()) { | 122 if (srcRect.isEmpty()) { |
| 123 m_image = StaticBitmapImage::create(buffer->newSkImageSnapshot(PreferNoA
cceleration)); | 123 m_image = StaticBitmapImage::create(buffer->newSkImageSnapshot(PreferNoA
cceleration, SnapshotReasonUnknown)); |
| 124 return; | 124 return; |
| 125 } | 125 } |
| 126 | 126 |
| 127 IntPoint dstPoint = IntPoint(std::min(0, -cropRect.x()), std::min(0, -cropRe
ct.y())); | 127 IntPoint dstPoint = IntPoint(std::min(0, -cropRect.x()), std::min(0, -cropRe
ct.y())); |
| 128 if (cropRect.x() < 0) | 128 if (cropRect.x() < 0) |
| 129 dstPoint.setX(-cropRect.x()); | 129 dstPoint.setX(-cropRect.x()); |
| 130 if (cropRect.y() < 0) | 130 if (cropRect.y() < 0) |
| 131 dstPoint.setY(-cropRect.y()); | 131 dstPoint.setY(-cropRect.y()); |
| 132 buffer->putByteArray(Unmultiplied, data->data()->data(), data->size(), srcRe
ct, dstPoint); | 132 buffer->putByteArray(Unmultiplied, data->data()->data(), data->size(), srcRe
ct, dstPoint); |
| 133 if (options.imageOrientation() == imageOrientationFlipY) | 133 if (options.imageOrientation() == imageOrientationFlipY) |
| 134 m_image = StaticBitmapImage::create(adoptRef(flipSkImageVertically(buffe
r->newSkImageSnapshot(PreferNoAcceleration).get()))); | 134 m_image = StaticBitmapImage::create(adoptRef(flipSkImageVertically(buffe
r->newSkImageSnapshot(PreferNoAcceleration, SnapshotReasonUnknown).get()))); |
| 135 else | 135 else |
| 136 m_image = StaticBitmapImage::create(buffer->newSkImageSnapshot(PreferNoA
cceleration)); | 136 m_image = StaticBitmapImage::create(buffer->newSkImageSnapshot(PreferNoA
cceleration, SnapshotReasonUnknown)); |
| 137 } | 137 } |
| 138 | 138 |
| 139 ImageBitmap::ImageBitmap(ImageBitmap* bitmap, const IntRect& cropRect, const Ima
geBitmapOptions& options) | 139 ImageBitmap::ImageBitmap(ImageBitmap* bitmap, const IntRect& cropRect, const Ima
geBitmapOptions& options) |
| 140 { | 140 { |
| 141 if (options.imageOrientation() == imageOrientationFlipY) | 141 if (options.imageOrientation() == imageOrientationFlipY) |
| 142 m_image = cropImage(bitmap->bitmapImage(), cropRect, true); | 142 m_image = cropImage(bitmap->bitmapImage(), cropRect, true); |
| 143 else | 143 else |
| 144 m_image = cropImage(bitmap->bitmapImage(), cropRect, false); | 144 m_image = cropImage(bitmap->bitmapImage(), cropRect, false); |
| 145 m_image->setOriginClean(bitmap->originClean()); | 145 m_image->setOriginClean(bitmap->originClean()); |
| 146 } | 146 } |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 258 exceptionState.throwDOMException(IndexSizeError, String::format("The sou
rce %s provided is 0.", sw ? "height" : "width")); | 258 exceptionState.throwDOMException(IndexSizeError, String::format("The sou
rce %s provided is 0.", sw ? "height" : "width")); |
| 259 return ScriptPromise(); | 259 return ScriptPromise(); |
| 260 } | 260 } |
| 261 return ImageBitmapSource::fulfillImageBitmap(scriptState, create(this, IntRe
ct(sx, sy, sw, sh), options)); | 261 return ImageBitmapSource::fulfillImageBitmap(scriptState, create(this, IntRe
ct(sx, sy, sw, sh), options)); |
| 262 } | 262 } |
| 263 | 263 |
| 264 void ImageBitmap::notifyImageSourceChanged() | 264 void ImageBitmap::notifyImageSourceChanged() |
| 265 { | 265 { |
| 266 } | 266 } |
| 267 | 267 |
| 268 PassRefPtr<Image> ImageBitmap::getSourceImageForCanvas(SourceImageStatus* status
, AccelerationHint) const | 268 PassRefPtr<Image> ImageBitmap::getSourceImageForCanvas(SourceImageStatus* status
, AccelerationHint, SnapshotReason) const |
| 269 { | 269 { |
| 270 *status = NormalSourceImageStatus; | 270 *status = NormalSourceImageStatus; |
| 271 return m_image ? m_image : nullptr; | 271 return m_image ? m_image : nullptr; |
| 272 } | 272 } |
| 273 | 273 |
| 274 void ImageBitmap::adjustDrawRects(FloatRect* srcRect, FloatRect* dstRect) const | 274 void ImageBitmap::adjustDrawRects(FloatRect* srcRect, FloatRect* dstRect) const |
| 275 { | 275 { |
| 276 } | 276 } |
| 277 | 277 |
| 278 FloatSize ImageBitmap::elementSize() const | 278 FloatSize ImageBitmap::elementSize() const |
| 279 { | 279 { |
| 280 return FloatSize(width(), height()); | 280 return FloatSize(width(), height()); |
| 281 } | 281 } |
| 282 | 282 |
| 283 DEFINE_TRACE(ImageBitmap) | 283 DEFINE_TRACE(ImageBitmap) |
| 284 { | 284 { |
| 285 ImageLoaderClient::trace(visitor); | 285 ImageLoaderClient::trace(visitor); |
| 286 } | 286 } |
| 287 | 287 |
| 288 } // namespace blink | 288 } // namespace blink |
| OLD | NEW |