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