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(PassRefPtrWillBeRawPtr<StaticBitmapImage> image, const
IntRect& cropRect) |
104 { | 108 { |
105 m_image = cropImage(image, cropRect); | 109 m_isOriginClean = image->originClean(); |
| 110 m_image = cropImage(image.get(), cropRect); |
106 } | 111 } |
107 | 112 |
108 ImageBitmap::ImageBitmap(PassRefPtr<StaticBitmapImage> image) | 113 ImageBitmap::ImageBitmap(PassRefPtr<StaticBitmapImage> image) |
109 { | 114 { |
| 115 m_isOriginClean = image->originClean(); |
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; |
| 123 m_image->setOriginClean(m_isOriginClean); |
117 return m_image.release(); | 124 return m_image.release(); |
118 } | 125 } |
119 | 126 |
120 ImageBitmap::~ImageBitmap() | 127 ImageBitmap::~ImageBitmap() |
121 { | 128 { |
122 } | 129 } |
123 | 130 |
124 PassRefPtrWillBeRawPtr<ImageBitmap> ImageBitmap::create(HTMLImageElement* image,
const IntRect& cropRect) | 131 PassRefPtrWillBeRawPtr<ImageBitmap> ImageBitmap::create(HTMLImageElement* image,
const IntRect& cropRect, Document* document) |
125 { | 132 { |
126 IntRect normalizedCropRect = normalizeRect(cropRect); | 133 IntRect normalizedCropRect = normalizeRect(cropRect); |
127 return adoptRefWillBeNoop(new ImageBitmap(image, normalizedCropRect)); | 134 return adoptRefWillBeNoop(new ImageBitmap(image, normalizedCropRect, documen
t)); |
128 } | 135 } |
129 | 136 |
130 PassRefPtrWillBeRawPtr<ImageBitmap> ImageBitmap::create(HTMLVideoElement* video,
const IntRect& cropRect) | 137 PassRefPtrWillBeRawPtr<ImageBitmap> ImageBitmap::create(HTMLVideoElement* video,
const IntRect& cropRect, Document* document) |
131 { | 138 { |
132 IntRect normalizedCropRect = normalizeRect(cropRect); | 139 IntRect normalizedCropRect = normalizeRect(cropRect); |
133 return adoptRefWillBeNoop(new ImageBitmap(video, normalizedCropRect)); | 140 return adoptRefWillBeNoop(new ImageBitmap(video, normalizedCropRect, documen
t)); |
134 } | 141 } |
135 | 142 |
136 PassRefPtrWillBeRawPtr<ImageBitmap> ImageBitmap::create(HTMLCanvasElement* canva
s, const IntRect& cropRect) | 143 PassRefPtrWillBeRawPtr<ImageBitmap> ImageBitmap::create(HTMLCanvasElement* canva
s, const IntRect& cropRect) |
137 { | 144 { |
138 IntRect normalizedCropRect = normalizeRect(cropRect); | 145 IntRect normalizedCropRect = normalizeRect(cropRect); |
139 return adoptRefWillBeNoop(new ImageBitmap(canvas, normalizedCropRect)); | 146 return adoptRefWillBeNoop(new ImageBitmap(canvas, normalizedCropRect)); |
140 } | 147 } |
141 | 148 |
142 PassRefPtrWillBeRawPtr<ImageBitmap> ImageBitmap::create(ImageData* data, const I
ntRect& cropRect) | 149 PassRefPtrWillBeRawPtr<ImageBitmap> ImageBitmap::create(ImageData* data, const I
ntRect& cropRect) |
143 { | 150 { |
144 IntRect normalizedCropRect = normalizeRect(cropRect); | 151 IntRect normalizedCropRect = normalizeRect(cropRect); |
145 return adoptRefWillBeNoop(new ImageBitmap(data, normalizedCropRect)); | 152 return adoptRefWillBeNoop(new ImageBitmap(data, normalizedCropRect)); |
146 } | 153 } |
147 | 154 |
148 PassRefPtrWillBeRawPtr<ImageBitmap> ImageBitmap::create(ImageBitmap* bitmap, con
st IntRect& cropRect) | 155 PassRefPtrWillBeRawPtr<ImageBitmap> ImageBitmap::create(ImageBitmap* bitmap, con
st IntRect& cropRect) |
149 { | 156 { |
150 IntRect normalizedCropRect = normalizeRect(cropRect); | 157 IntRect normalizedCropRect = normalizeRect(cropRect); |
151 return adoptRefWillBeNoop(new ImageBitmap(bitmap, normalizedCropRect)); | 158 return adoptRefWillBeNoop(new ImageBitmap(bitmap, normalizedCropRect)); |
152 } | 159 } |
153 | 160 |
154 PassRefPtrWillBeRawPtr<ImageBitmap> ImageBitmap::create(Image* image, const IntR
ect& cropRect) | 161 PassRefPtrWillBeRawPtr<ImageBitmap> ImageBitmap::create(PassRefPtr<StaticBitmapI
mage> image, const IntRect& cropRect) |
155 { | 162 { |
156 IntRect normalizedCropRect = normalizeRect(cropRect); | 163 IntRect normalizedCropRect = normalizeRect(cropRect); |
157 return adoptRefWillBeNoop(new ImageBitmap(image, normalizedCropRect)); | 164 return adoptRefWillBeNoop(new ImageBitmap(image, normalizedCropRect)); |
158 } | 165 } |
159 | 166 |
160 PassRefPtrWillBeRawPtr<ImageBitmap> ImageBitmap::create(PassRefPtr<StaticBitmapI
mage> image) | 167 PassRefPtrWillBeRawPtr<ImageBitmap> ImageBitmap::create(PassRefPtr<StaticBitmapI
mage> image) |
161 { | 168 { |
162 return adoptRefWillBeNoop(new ImageBitmap(image)); | 169 return adoptRefWillBeNoop(new ImageBitmap(image)); |
163 } | 170 } |
164 | 171 |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
213 { | 220 { |
214 return FloatSize(width(), height()); | 221 return FloatSize(width(), height()); |
215 } | 222 } |
216 | 223 |
217 DEFINE_TRACE(ImageBitmap) | 224 DEFINE_TRACE(ImageBitmap) |
218 { | 225 { |
219 ImageLoaderClient::trace(visitor); | 226 ImageLoaderClient::trace(visitor); |
220 } | 227 } |
221 | 228 |
222 } // namespace blink | 229 } // namespace blink |
OLD | NEW |