| 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 27 matching lines...) Expand all Loading... |
| 38 SkScalar dstLeft = std::min(0, -cropRect.x()); | 38 SkScalar dstLeft = std::min(0, -cropRect.x()); |
| 39 SkScalar dstTop = std::min(0, -cropRect.y()); | 39 SkScalar dstTop = std::min(0, -cropRect.y()); |
| 40 if (cropRect.x() < 0) | 40 if (cropRect.x() < 0) |
| 41 dstLeft = -cropRect.x(); | 41 dstLeft = -cropRect.x(); |
| 42 if (cropRect.y() < 0) | 42 if (cropRect.y() < 0) |
| 43 dstTop = -cropRect.y(); | 43 dstTop = -cropRect.y(); |
| 44 surface->getCanvas()->drawImage(image->imageForCurrentFrame().get(), dstLeft
, dstTop); | 44 surface->getCanvas()->drawImage(image->imageForCurrentFrame().get(), dstLeft
, dstTop); |
| 45 return StaticBitmapImage::create(adoptRef(surface->newImageSnapshot())); | 45 return StaticBitmapImage::create(adoptRef(surface->newImageSnapshot())); |
| 46 } | 46 } |
| 47 | 47 |
| 48 ImageBitmap::ImageBitmap(HTMLImageElement* image, const IntRect& cropRect) | 48 ImageBitmap::ImageBitmap(HTMLImageElement* image, const IntRect& cropRect, Docum
ent* document) |
| 49 { | 49 { |
| 50 m_isOriginClean = !image->wouldTaintOrigin(document->securityOrigin()); |
| 50 m_image = cropImage(image->cachedImage()->image(), cropRect); | 51 m_image = cropImage(image->cachedImage()->image(), cropRect); |
| 51 } | 52 } |
| 52 | 53 |
| 53 ImageBitmap::ImageBitmap(HTMLVideoElement* video, const IntRect& cropRect) | 54 ImageBitmap::ImageBitmap(HTMLVideoElement* video, const IntRect& cropRect, Docum
ent* document) |
| 54 { | 55 { |
| 55 IntSize playerSize; | 56 IntSize playerSize; |
| 56 if (video->webMediaPlayer()) | 57 if (video->webMediaPlayer()) |
| 57 playerSize = video->webMediaPlayer()->naturalSize(); | 58 playerSize = video->webMediaPlayer()->naturalSize(); |
| 58 | 59 |
| 59 IntRect videoRect = IntRect(IntPoint(), playerSize); | 60 IntRect videoRect = IntRect(IntPoint(), playerSize); |
| 60 IntRect srcRect = intersection(cropRect, videoRect); | 61 IntRect srcRect = intersection(cropRect, videoRect); |
| 61 OwnPtr<ImageBuffer> buffer = ImageBuffer::create(cropRect.size(), NonOpaque,
DoNotInitializeImagePixels); | 62 OwnPtr<ImageBuffer> buffer = ImageBuffer::create(cropRect.size(), NonOpaque,
DoNotInitializeImagePixels); |
| 62 if (!buffer) | 63 if (!buffer) |
| 63 return; | 64 return; |
| 64 | 65 |
| 65 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())); |
| 66 video->paintCurrentFrame(buffer->canvas(), IntRect(dstPoint, srcRect.size())
, nullptr); | 67 video->paintCurrentFrame(buffer->canvas(), IntRect(dstPoint, srcRect.size())
, nullptr); |
| 68 m_isOriginClean = !video->wouldTaintOrigin(document->securityOrigin()); |
| 67 m_image = StaticBitmapImage::create(buffer->newSkImageSnapshot(PreferNoAccel
eration)); | 69 m_image = StaticBitmapImage::create(buffer->newSkImageSnapshot(PreferNoAccel
eration)); |
| 68 } | 70 } |
| 69 | 71 |
| 70 ImageBitmap::ImageBitmap(HTMLCanvasElement* canvas, const IntRect& cropRect) | 72 ImageBitmap::ImageBitmap(HTMLCanvasElement* canvas, const IntRect& cropRect) |
| 71 { | 73 { |
| 72 ASSERT(canvas->isPaintable()); | 74 ASSERT(canvas->isPaintable()); |
| 75 m_isOriginClean = canvas->originClean(); |
| 73 m_image = cropImage(canvas->copiedImage(BackBuffer, PreferAcceleration).get(
), cropRect); | 76 m_image = cropImage(canvas->copiedImage(BackBuffer, PreferAcceleration).get(
), cropRect); |
| 74 } | 77 } |
| 75 | 78 |
| 76 ImageBitmap::ImageBitmap(ImageData* data, const IntRect& cropRect) | 79 ImageBitmap::ImageBitmap(ImageData* data, const IntRect& cropRect) |
| 77 { | 80 { |
| 78 IntRect srcRect = intersection(cropRect, IntRect(IntPoint(), data->size())); | 81 IntRect srcRect = intersection(cropRect, IntRect(IntPoint(), data->size())); |
| 79 | 82 |
| 80 OwnPtr<ImageBuffer> buffer = ImageBuffer::create(cropRect.size(), NonOpaque,
DoNotInitializeImagePixels); | 83 OwnPtr<ImageBuffer> buffer = ImageBuffer::create(cropRect.size(), NonOpaque,
DoNotInitializeImagePixels); |
| 81 if (!buffer) | 84 if (!buffer) |
| 82 return; | 85 return; |
| 83 | 86 |
| 84 if (srcRect.isEmpty()) { | 87 if (srcRect.isEmpty()) { |
| 85 m_image = StaticBitmapImage::create(buffer->newSkImageSnapshot(PreferNoA
cceleration)); | 88 m_image = StaticBitmapImage::create(buffer->newSkImageSnapshot(PreferNoA
cceleration)); |
| 86 return; | 89 return; |
| 87 } | 90 } |
| 88 | 91 |
| 89 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())); |
| 90 if (cropRect.x() < 0) | 93 if (cropRect.x() < 0) |
| 91 dstPoint.setX(-cropRect.x()); | 94 dstPoint.setX(-cropRect.x()); |
| 92 if (cropRect.y() < 0) | 95 if (cropRect.y() < 0) |
| 93 dstPoint.setY(-cropRect.y()); | 96 dstPoint.setY(-cropRect.y()); |
| 94 buffer->putByteArray(Unmultiplied, data->data()->data(), data->size(), srcRe
ct, dstPoint); | 97 buffer->putByteArray(Unmultiplied, data->data()->data(), data->size(), srcRe
ct, dstPoint); |
| 95 m_image = StaticBitmapImage::create(buffer->newSkImageSnapshot(PreferNoAccel
eration)); | 98 m_image = StaticBitmapImage::create(buffer->newSkImageSnapshot(PreferNoAccel
eration)); |
| 96 } | 99 } |
| 97 | 100 |
| 98 ImageBitmap::ImageBitmap(ImageBitmap* bitmap, const IntRect& cropRect) | 101 ImageBitmap::ImageBitmap(ImageBitmap* bitmap, const IntRect& cropRect) |
| 99 { | 102 { |
| 103 m_isOriginClean = bitmap->originClean(); |
| 100 m_image = cropImage(bitmap->bitmapImage(), cropRect); | 104 m_image = cropImage(bitmap->bitmapImage(), cropRect); |
| 101 } | 105 } |
| 102 | 106 |
| 103 ImageBitmap::ImageBitmap(Image* image, const IntRect& cropRect) | 107 ImageBitmap::ImageBitmap(Image* image, const IntRect& cropRect) |
| 104 { | 108 { |
| 109 m_isOriginClean = image->currentFrameHasSingleSecurityOrigin(); |
| 105 m_image = cropImage(image, cropRect); | 110 m_image = cropImage(image, cropRect); |
| 106 } | 111 } |
| 107 | 112 |
| 108 ImageBitmap::ImageBitmap(PassRefPtr<StaticBitmapImage> image) | 113 ImageBitmap::ImageBitmap(PassRefPtr<StaticBitmapImage> image) |
| 109 { | 114 { |
| 115 m_isOriginClean = image->currentFrameHasSingleSecurityOrigin(); |
| 110 m_image = image; | 116 m_image = image; |
| 111 } | 117 } |
| 112 | 118 |
| 113 PassRefPtr<StaticBitmapImage> ImageBitmap::transfer() | 119 PassRefPtr<StaticBitmapImage> ImageBitmap::transfer() |
| 114 { | 120 { |
| 115 ASSERT(!isNeutered()); | 121 ASSERT(!isNeutered()); |
| 116 m_isNeutered = true; | 122 m_isNeutered = true; |
| 117 return m_image.release(); | 123 return m_image.release(); |
| 118 } | 124 } |
| 119 | 125 |
| 120 ImageBitmap::~ImageBitmap() | 126 ImageBitmap::~ImageBitmap() |
| 121 { | 127 { |
| 122 } | 128 } |
| 123 | 129 |
| 124 PassRefPtrWillBeRawPtr<ImageBitmap> ImageBitmap::create(HTMLImageElement* image,
const IntRect& cropRect) | 130 PassRefPtrWillBeRawPtr<ImageBitmap> ImageBitmap::create(HTMLImageElement* image,
const IntRect& cropRect, Document* document) |
| 125 { | 131 { |
| 126 IntRect normalizedCropRect = normalizeRect(cropRect); | 132 IntRect normalizedCropRect = normalizeRect(cropRect); |
| 127 return adoptRefWillBeNoop(new ImageBitmap(image, normalizedCropRect)); | 133 return adoptRefWillBeNoop(new ImageBitmap(image, normalizedCropRect, documen
t)); |
| 128 } | 134 } |
| 129 | 135 |
| 130 PassRefPtrWillBeRawPtr<ImageBitmap> ImageBitmap::create(HTMLVideoElement* video,
const IntRect& cropRect) | 136 PassRefPtrWillBeRawPtr<ImageBitmap> ImageBitmap::create(HTMLVideoElement* video,
const IntRect& cropRect, Document* document) |
| 131 { | 137 { |
| 132 IntRect normalizedCropRect = normalizeRect(cropRect); | 138 IntRect normalizedCropRect = normalizeRect(cropRect); |
| 133 return adoptRefWillBeNoop(new ImageBitmap(video, normalizedCropRect)); | 139 return adoptRefWillBeNoop(new ImageBitmap(video, normalizedCropRect, documen
t)); |
| 134 } | 140 } |
| 135 | 141 |
| 136 PassRefPtrWillBeRawPtr<ImageBitmap> ImageBitmap::create(HTMLCanvasElement* canva
s, const IntRect& cropRect) | 142 PassRefPtrWillBeRawPtr<ImageBitmap> ImageBitmap::create(HTMLCanvasElement* canva
s, const IntRect& cropRect) |
| 137 { | 143 { |
| 138 IntRect normalizedCropRect = normalizeRect(cropRect); | 144 IntRect normalizedCropRect = normalizeRect(cropRect); |
| 139 return adoptRefWillBeNoop(new ImageBitmap(canvas, normalizedCropRect)); | 145 return adoptRefWillBeNoop(new ImageBitmap(canvas, normalizedCropRect)); |
| 140 } | 146 } |
| 141 | 147 |
| 142 PassRefPtrWillBeRawPtr<ImageBitmap> ImageBitmap::create(ImageData* data, const I
ntRect& cropRect) | 148 PassRefPtrWillBeRawPtr<ImageBitmap> ImageBitmap::create(ImageData* data, const I
ntRect& cropRect) |
| 143 { | 149 { |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 213 { | 219 { |
| 214 return FloatSize(width(), height()); | 220 return FloatSize(width(), height()); |
| 215 } | 221 } |
| 216 | 222 |
| 217 DEFINE_TRACE(ImageBitmap) | 223 DEFINE_TRACE(ImageBitmap) |
| 218 { | 224 { |
| 219 ImageLoaderClient::trace(visitor); | 225 ImageLoaderClient::trace(visitor); |
| 220 } | 226 } |
| 221 | 227 |
| 222 } // namespace blink | 228 } // namespace blink |
| OLD | NEW |