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

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

Issue 2192493003: Enable GPU acceleration in 2D OffscreenCanvases on main thread (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix dev tools failure Created 4 years, 4 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"
11 #include "core/workers/WorkerSettings.h" 11 #include "core/workers/WorkerSettings.h"
12 #include "platform/graphics/ImageBuffer.h" 12 #include "platform/graphics/ImageBuffer.h"
13 #include "platform/graphics/StaticBitmapImage.h" 13 #include "platform/graphics/StaticBitmapImage.h"
14 #include "platform/graphics/UnacceleratedImageBufferSurface.h"
15 #include "platform/graphics/gpu/AcceleratedImageBufferSurface.h"
14 #include "wtf/Assertions.h" 16 #include "wtf/Assertions.h"
15 17
16 #define UNIMPLEMENTED ASSERT_NOT_REACHED 18 #define UNIMPLEMENTED ASSERT_NOT_REACHED
17 19
18 namespace blink { 20 namespace blink {
19 21
20 OffscreenCanvasRenderingContext2D::~OffscreenCanvasRenderingContext2D() 22 OffscreenCanvasRenderingContext2D::~OffscreenCanvasRenderingContext2D()
21 { 23 {
22 } 24 }
23 25
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 int OffscreenCanvasRenderingContext2D::height() const 75 int OffscreenCanvasRenderingContext2D::height() const
74 { 76 {
75 return getOffscreenCanvas()->height(); 77 return getOffscreenCanvas()->height();
76 } 78 }
77 79
78 bool OffscreenCanvasRenderingContext2D::hasImageBuffer() const 80 bool OffscreenCanvasRenderingContext2D::hasImageBuffer() const
79 { 81 {
80 return !!m_imageBuffer; 82 return !!m_imageBuffer;
81 } 83 }
82 84
85 static bool shouldAccelerate(IntSize surfaceSize)
86 {
87 if (!isMainThread())
88 return false; // Add support on Workers crbug.com/
89 return RuntimeEnabledFeatures::accelerated2dCanvasEnabled();
90 }
91
83 ImageBuffer* OffscreenCanvasRenderingContext2D::imageBuffer() const 92 ImageBuffer* OffscreenCanvasRenderingContext2D::imageBuffer() const
84 { 93 {
85 if (!m_imageBuffer) { 94 if (!m_imageBuffer) {
86 // TODO: crbug.com/593514 Add support for GPU rendering 95 IntSize surfaceSize(width(), height());
96 OpacityMode opacityMode = m_hasAlpha ? NonOpaque : Opaque;
97 std::unique_ptr<ImageBufferSurface> surface;
98 if (shouldAccelerate(surfaceSize)) {
99 surface.reset(new AcceleratedImageBufferSurface(surfaceSize, opacity Mode));
100 }
101
102 if (!surface || !surface->isValid()) {
103 surface.reset(new UnacceleratedImageBufferSurface(surfaceSize, opaci tyMode, InitializeImagePixels));
104 }
105
87 OffscreenCanvasRenderingContext2D* nonConstThis = const_cast<OffscreenCa nvasRenderingContext2D*>(this); 106 OffscreenCanvasRenderingContext2D* nonConstThis = const_cast<OffscreenCa nvasRenderingContext2D*>(this);
88 nonConstThis->m_imageBuffer = ImageBuffer::create(IntSize(width(), heigh t()), m_hasAlpha ? NonOpaque : Opaque, InitializeImagePixels); 107 nonConstThis->m_imageBuffer = ImageBuffer::create(std::move(surface));
89 108
90 if (m_needsMatrixClipRestore) { 109 if (m_needsMatrixClipRestore) {
91 restoreMatrixClipStack(m_imageBuffer->canvas()); 110 restoreMatrixClipStack(m_imageBuffer->canvas());
92 nonConstThis->m_needsMatrixClipRestore = false; 111 nonConstThis->m_needsMatrixClipRestore = false;
93 } 112 }
94 } 113 }
95 114
96 return m_imageBuffer.get(); 115 return m_imageBuffer.get();
97 } 116 }
98 117
99 ImageBitmap* OffscreenCanvasRenderingContext2D::transferToImageBitmap(ExceptionS tate& exceptionState) 118 ImageBitmap* OffscreenCanvasRenderingContext2D::transferToImageBitmap(ExceptionS tate& exceptionState)
100 { 119 {
101 if (!imageBuffer()) 120 if (!imageBuffer())
102 return nullptr; 121 return nullptr;
103 // TODO: crbug.com/593514 Add support for GPU rendering 122 RefPtr<SkImage> skImage = m_imageBuffer->newSkImageSnapshot(PreferAccelerati on, SnapshotReasonTransferToImageBitmap);
104 RefPtr<SkImage> skImage = m_imageBuffer->newSkImageSnapshot(PreferNoAccelera tion, SnapshotReasonTransferToImageBitmap); 123 DCHECK(isMainThread() || !skImage->isTextureBacked()); // Acceleration not y et supported in Workers
105 RefPtr<StaticBitmapImage> image = StaticBitmapImage::create(skImage.release( )); 124 RefPtr<StaticBitmapImage> image = StaticBitmapImage::create(skImage.release( ));
106 image->setOriginClean(this->originClean()); 125 image->setOriginClean(this->originClean());
107 m_imageBuffer.reset(); // "Transfer" means no retained buffer 126 m_imageBuffer.reset(); // "Transfer" means no retained buffer
108 m_needsMatrixClipRestore = true; 127 m_needsMatrixClipRestore = true;
109 return ImageBitmap::create(image.release()); 128 return ImageBitmap::create(image.release());
110 } 129 }
111 130
112 void OffscreenCanvasRenderingContext2D::setOffscreenCanvasGetContextResult(Offsc reenRenderingContext& result) 131 void OffscreenCanvasRenderingContext2D::setOffscreenCanvasGetContextResult(Offsc reenRenderingContext& result)
113 { 132 {
114 result.setOffscreenCanvasRenderingContext2D(this); 133 result.setOffscreenCanvasRenderingContext2D(this);
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
170 } 189 }
171 #endif 190 #endif
172 } 191 }
173 192
174 bool OffscreenCanvasRenderingContext2D::isContextLost() const 193 bool OffscreenCanvasRenderingContext2D::isContextLost() const
175 { 194 {
176 return false; 195 return false;
177 } 196 }
178 197
179 } 198 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698