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