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