OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "modules/offscreencanvas2d/OffscreenCanvasRenderingContext2D.h" | 5 #include "modules/offscreencanvas2d/OffscreenCanvasRenderingContext2D.h" |
6 | 6 |
7 #include "bindings/modules/v8/OffscreenCanvasRenderingContext2DOrWebGLRenderingC
ontextOrWebGL2RenderingContext.h" | 7 #include "bindings/modules/v8/OffscreenCanvasRenderingContext2DOrWebGLRenderingC
ontextOrWebGL2RenderingContext.h" |
8 #include "core/frame/ImageBitmap.h" | 8 #include "core/frame/ImageBitmap.h" |
9 #include "core/frame/Settings.h" | 9 #include "core/frame/Settings.h" |
10 #include "core/workers/WorkerGlobalScope.h" | 10 #include "core/workers/WorkerGlobalScope.h" |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
52 } | 52 } |
53 | 53 |
54 void OffscreenCanvasRenderingContext2D::setOriginTainted() | 54 void OffscreenCanvasRenderingContext2D::setOriginTainted() |
55 { | 55 { |
56 return getOffscreenCanvas()->setOriginTainted(); | 56 return getOffscreenCanvas()->setOriginTainted(); |
57 } | 57 } |
58 | 58 |
59 bool OffscreenCanvasRenderingContext2D::wouldTaintOrigin(CanvasImageSource* sour
ce, ExecutionContext* executionContext) | 59 bool OffscreenCanvasRenderingContext2D::wouldTaintOrigin(CanvasImageSource* sour
ce, ExecutionContext* executionContext) |
60 { | 60 { |
61 if (executionContext->isWorkerGlobalScope()) { | 61 if (executionContext->isWorkerGlobalScope()) { |
62 // Currently, we only support passing in ImageBitmap as source image in | 62 // We only support passing in ImageBitmap and OffscreenCanvases as sourc
e images |
63 // drawImage() or createPattern() in a OffscreenCanvas2d in worker. | 63 // in drawImage() or createPattern() in a OffscreenCanvas2d in worker. |
64 ASSERT(source->isImageBitmap()); | 64 DCHECK(source->isImageBitmap() || source->isOffscreenCanvas()); |
65 } | 65 } |
66 | 66 |
67 return CanvasRenderingContext::wouldTaintOrigin(source, executionContext->ge
tSecurityOrigin()); | 67 return CanvasRenderingContext::wouldTaintOrigin(source, executionContext->ge
tSecurityOrigin()); |
68 } | 68 } |
69 | 69 |
70 int OffscreenCanvasRenderingContext2D::width() const | 70 int OffscreenCanvasRenderingContext2D::width() const |
71 { | 71 { |
72 return getOffscreenCanvas()->width(); | 72 return getOffscreenCanvas()->width(); |
73 } | 73 } |
74 | 74 |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
121 return nullptr; | 121 return nullptr; |
122 RefPtr<SkImage> skImage = m_imageBuffer->newSkImageSnapshot(PreferAccelerati
on, SnapshotReasonTransferToImageBitmap); | 122 RefPtr<SkImage> skImage = m_imageBuffer->newSkImageSnapshot(PreferAccelerati
on, SnapshotReasonTransferToImageBitmap); |
123 DCHECK(isMainThread() || !skImage->isTextureBacked()); // Acceleration not y
et supported in Workers | 123 DCHECK(isMainThread() || !skImage->isTextureBacked()); // Acceleration not y
et supported in Workers |
124 RefPtr<StaticBitmapImage> image = StaticBitmapImage::create(skImage.release(
)); | 124 RefPtr<StaticBitmapImage> image = StaticBitmapImage::create(skImage.release(
)); |
125 image->setOriginClean(this->originClean()); | 125 image->setOriginClean(this->originClean()); |
126 m_imageBuffer.reset(); // "Transfer" means no retained buffer | 126 m_imageBuffer.reset(); // "Transfer" means no retained buffer |
127 m_needsMatrixClipRestore = true; | 127 m_needsMatrixClipRestore = true; |
128 return ImageBitmap::create(image.release()); | 128 return ImageBitmap::create(image.release()); |
129 } | 129 } |
130 | 130 |
| 131 PassRefPtr<Image> OffscreenCanvasRenderingContext2D::getImage(SnapshotReason rea
son) const |
| 132 { |
| 133 if (!imageBuffer()) |
| 134 return nullptr; |
| 135 RefPtr<SkImage> skImage = m_imageBuffer->newSkImageSnapshot(PreferAccelerati
on, reason); |
| 136 RefPtr<StaticBitmapImage> image = StaticBitmapImage::create(skImage.release(
)); |
| 137 return image; |
| 138 } |
| 139 |
131 void OffscreenCanvasRenderingContext2D::setOffscreenCanvasGetContextResult(Offsc
reenRenderingContext& result) | 140 void OffscreenCanvasRenderingContext2D::setOffscreenCanvasGetContextResult(Offsc
reenRenderingContext& result) |
132 { | 141 { |
133 result.setOffscreenCanvasRenderingContext2D(this); | 142 result.setOffscreenCanvasRenderingContext2D(this); |
134 } | 143 } |
135 | 144 |
136 bool OffscreenCanvasRenderingContext2D::parseColorOrCurrentColor(Color& color, c
onst String& colorString) const | 145 bool OffscreenCanvasRenderingContext2D::parseColorOrCurrentColor(Color& color, c
onst String& colorString) const |
137 { | 146 { |
138 return ::blink::parseColorOrCurrentColor(color, colorString, nullptr); | 147 return ::blink::parseColorOrCurrentColor(color, colorString, nullptr); |
139 } | 148 } |
140 | 149 |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
193 bool OffscreenCanvasRenderingContext2D::isContextLost() const | 202 bool OffscreenCanvasRenderingContext2D::isContextLost() const |
194 { | 203 { |
195 return false; | 204 return false; |
196 } | 205 } |
197 | 206 |
198 bool OffscreenCanvasRenderingContext2D::isPaintable() const | 207 bool OffscreenCanvasRenderingContext2D::isPaintable() const |
199 { | 208 { |
200 return this->imageBuffer(); | 209 return this->imageBuffer(); |
201 } | 210 } |
202 } | 211 } |
OLD | NEW |