Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(99)

Side by Side Diff: third_party/WebKit/Source/modules/offscreencanvas2d/OffscreenCanvasRenderingContext2D.cpp

Issue 2300633004: Allow canvases to be GPU-accelerated in Workers (Closed)
Patch Set: Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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
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 RefPtr<SkImage> skImage = m_imageBuffer->newSkImageSnapshot(PreferAccelerati on, SnapshotReasonTransferToImageBitmap); 119 RefPtr<SkImage> skImage = m_imageBuffer->newSkImageSnapshot(PreferAccelerati on, SnapshotReasonTransferToImageBitmap);
122 DCHECK(isMainThread() || !skImage->isTextureBacked()); // Acceleration not y et supported in Workers
123 RefPtr<StaticBitmapImage> image = StaticBitmapImage::create(skImage.release( )); 120 RefPtr<StaticBitmapImage> image = StaticBitmapImage::create(skImage.release( ));
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 void OffscreenCanvasRenderingContext2D::setOffscreenCanvasGetContextResult(Offsc reenRenderingContext& result) 127 void OffscreenCanvasRenderingContext2D::setOffscreenCanvasGetContextResult(Offsc reenRenderingContext& result)
131 { 128 {
132 result.setOffscreenCanvasRenderingContext2D(this); 129 result.setOffscreenCanvasRenderingContext2D(this);
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
192 bool OffscreenCanvasRenderingContext2D::isContextLost() const 189 bool OffscreenCanvasRenderingContext2D::isContextLost() const
193 { 190 {
194 return false; 191 return false;
195 } 192 }
196 193
197 bool OffscreenCanvasRenderingContext2D::isPaintable() const 194 bool OffscreenCanvasRenderingContext2D::isPaintable() const
198 { 195 {
199 return this->imageBuffer(); 196 return this->imageBuffer();
200 } 197 }
201 } 198 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698