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 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
76 return getOffscreenCanvas()->height(); | 76 return getOffscreenCanvas()->height(); |
77 } | 77 } |
78 | 78 |
79 bool OffscreenCanvasRenderingContext2D::hasImageBuffer() const | 79 bool OffscreenCanvasRenderingContext2D::hasImageBuffer() const |
80 { | 80 { |
81 return !!m_imageBuffer; | 81 return !!m_imageBuffer; |
82 } | 82 } |
83 | 83 |
84 static bool shouldAccelerate(IntSize surfaceSize) | 84 static bool shouldAccelerate(IntSize surfaceSize) |
85 { | 85 { |
| 86 if (!isMainThread()) |
| 87 return false; // Add support on Workers crbug.com/ |
86 return RuntimeEnabledFeatures::accelerated2dCanvasEnabled(); | 88 return RuntimeEnabledFeatures::accelerated2dCanvasEnabled(); |
87 } | 89 } |
88 | 90 |
89 ImageBuffer* OffscreenCanvasRenderingContext2D::imageBuffer() const | 91 ImageBuffer* OffscreenCanvasRenderingContext2D::imageBuffer() const |
90 { | 92 { |
91 if (!m_imageBuffer) { | 93 if (!m_imageBuffer) { |
92 IntSize surfaceSize(width(), height()); | 94 IntSize surfaceSize(width(), height()); |
93 OpacityMode opacityMode = hasAlpha() ? NonOpaque : Opaque; | 95 OpacityMode opacityMode = hasAlpha() ? NonOpaque : Opaque; |
94 std::unique_ptr<ImageBufferSurface> surface; | 96 std::unique_ptr<ImageBufferSurface> surface; |
95 if (shouldAccelerate(surfaceSize)) { | 97 if (shouldAccelerate(surfaceSize)) { |
(...skipping 14 matching lines...) Expand all Loading... |
110 } | 112 } |
111 | 113 |
112 return m_imageBuffer.get(); | 114 return m_imageBuffer.get(); |
113 } | 115 } |
114 | 116 |
115 ImageBitmap* OffscreenCanvasRenderingContext2D::transferToImageBitmap(ExceptionS
tate& exceptionState) | 117 ImageBitmap* OffscreenCanvasRenderingContext2D::transferToImageBitmap(ExceptionS
tate& exceptionState) |
116 { | 118 { |
117 if (!imageBuffer()) | 119 if (!imageBuffer()) |
118 return nullptr; | 120 return nullptr; |
119 sk_sp<SkImage> skImage = m_imageBuffer->newSkImageSnapshot(PreferAcceleratio
n, SnapshotReasonTransferToImageBitmap); | 121 sk_sp<SkImage> skImage = m_imageBuffer->newSkImageSnapshot(PreferAcceleratio
n, SnapshotReasonTransferToImageBitmap); |
| 122 DCHECK(isMainThread() || !skImage->isTextureBacked()); // Acceleration not y
et supported in Workers |
120 RefPtr<StaticBitmapImage> image = StaticBitmapImage::create(std::move(skImag
e)); | 123 RefPtr<StaticBitmapImage> image = StaticBitmapImage::create(std::move(skImag
e)); |
121 image->setOriginClean(this->originClean()); | 124 image->setOriginClean(this->originClean()); |
122 m_imageBuffer.reset(); // "Transfer" means no retained buffer | 125 m_imageBuffer.reset(); // "Transfer" means no retained buffer |
123 m_needsMatrixClipRestore = true; | 126 m_needsMatrixClipRestore = true; |
124 return ImageBitmap::create(image.release()); | 127 return ImageBitmap::create(image.release()); |
125 } | 128 } |
126 | 129 |
127 PassRefPtr<Image> OffscreenCanvasRenderingContext2D::getImage(SnapshotReason rea
son) const | 130 PassRefPtr<Image> OffscreenCanvasRenderingContext2D::getImage(SnapshotReason rea
son) const |
128 { | 131 { |
129 if (!imageBuffer()) | 132 if (!imageBuffer()) |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
198 bool OffscreenCanvasRenderingContext2D::isContextLost() const | 201 bool OffscreenCanvasRenderingContext2D::isContextLost() const |
199 { | 202 { |
200 return false; | 203 return false; |
201 } | 204 } |
202 | 205 |
203 bool OffscreenCanvasRenderingContext2D::isPaintable() const | 206 bool OffscreenCanvasRenderingContext2D::isPaintable() const |
204 { | 207 { |
205 return this->imageBuffer(); | 208 return this->imageBuffer(); |
206 } | 209 } |
207 } | 210 } |
OLD | NEW |