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