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

Side by Side Diff: third_party/WebKit/Source/modules/webgl/WebGL2RenderingContext.cpp

Issue 2509193002: Correct the OffscreenCanvas.getContext API (Closed)
Patch Set: support webgl2 Created 4 years, 1 month 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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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/webgl/WebGL2RenderingContext.h" 5 #include "modules/webgl/WebGL2RenderingContext.h"
6 6
7 #include "bindings/modules/v8/OffscreenCanvasRenderingContext2DOrWebGLRenderingC ontextOrWebGL2RenderingContext.h" 7 #include "bindings/modules/v8/OffscreenCanvasRenderingContext2DOrWebGLRenderingC ontextOrWebGL2RenderingContext.h"
8 #include "bindings/modules/v8/RenderingContext.h" 8 #include "bindings/modules/v8/RenderingContext.h"
9 #include "core/frame/LocalFrame.h" 9 #include "core/frame/LocalFrame.h"
10 #include "core/frame/Settings.h" 10 #include "core/frame/Settings.h"
(...skipping 16 matching lines...) Expand all
27 #include "modules/webgl/WebGLDebugRendererInfo.h" 27 #include "modules/webgl/WebGLDebugRendererInfo.h"
28 #include "modules/webgl/WebGLDebugShaders.h" 28 #include "modules/webgl/WebGLDebugShaders.h"
29 #include "modules/webgl/WebGLLoseContext.h" 29 #include "modules/webgl/WebGLLoseContext.h"
30 #include "platform/graphics/gpu/DrawingBuffer.h" 30 #include "platform/graphics/gpu/DrawingBuffer.h"
31 #include "public/platform/Platform.h" 31 #include "public/platform/Platform.h"
32 #include "public/platform/WebGraphicsContext3DProvider.h" 32 #include "public/platform/WebGraphicsContext3DProvider.h"
33 #include <memory> 33 #include <memory>
34 34
35 namespace blink { 35 namespace blink {
36 36
37 // An helper function for the two create() methods. The return value is an
38 // indicate of whether the create() should return nullptr or not.
39 static bool shouldCreateContext(WebGraphicsContext3DProvider* contextProvider,
40 HTMLCanvasElement* canvas,
41 OffscreenCanvas* offscreenCanvas) {
42 if (!contextProvider) {
43 if (canvas) {
44 canvas->dispatchEvent(WebGLContextEvent::create(
45 EventTypeNames::webglcontextcreationerror, false, true,
46 "Failed to create a WebGL2 context."));
47 } else {
48 offscreenCanvas->dispatchEvent(WebGLContextEvent::create(
49 EventTypeNames::webglcontextcreationerror, false, true,
50 "Failed to create a WebGL2 context."));
51 }
52 return false;
53 }
54
55 gpu::gles2::GLES2Interface* gl = contextProvider->contextGL();
56 std::unique_ptr<Extensions3DUtil> extensionsUtil =
57 Extensions3DUtil::create(gl);
58 if (!extensionsUtil)
59 return false;
60 if (extensionsUtil->supportsExtension("GL_EXT_debug_marker")) {
61 String contextLabel(
62 String::format("WebGL2RenderingContext-%p", contextProvider));
63 gl->PushGroupMarkerEXT(0, contextLabel.ascii().data());
64 }
65 return true;
66 }
67
37 CanvasRenderingContext* WebGL2RenderingContext::Factory::create( 68 CanvasRenderingContext* WebGL2RenderingContext::Factory::create(
38 HTMLCanvasElement* canvas, 69 HTMLCanvasElement* canvas,
39 const CanvasContextCreationAttributes& attrs, 70 const CanvasContextCreationAttributes& attrs,
40 Document&) { 71 Document&) {
41 std::unique_ptr<WebGraphicsContext3DProvider> contextProvider( 72 std::unique_ptr<WebGraphicsContext3DProvider> contextProvider(
42 createWebGraphicsContext3DProvider(canvas, attrs, 2)); 73 createWebGraphicsContext3DProvider(canvas, attrs, 2));
43 if (!contextProvider) { 74 if (!shouldCreateContext(contextProvider.get(), canvas, nullptr))
44 canvas->dispatchEvent(WebGLContextEvent::create(
45 EventTypeNames::webglcontextcreationerror, false, true,
46 "Failed to create a WebGL2 context."));
47 return nullptr; 75 return nullptr;
48 }
49 gpu::gles2::GLES2Interface* gl = contextProvider->contextGL();
50 std::unique_ptr<Extensions3DUtil> extensionsUtil =
51 Extensions3DUtil::create(gl);
52 if (!extensionsUtil)
53 return nullptr;
54 if (extensionsUtil->supportsExtension("GL_EXT_debug_marker")) {
55 String contextLabel(
56 String::format("WebGL2RenderingContext-%p", contextProvider.get()));
57 gl->PushGroupMarkerEXT(0, contextLabel.ascii().data());
58 }
59
60 WebGL2RenderingContext* renderingContext = 76 WebGL2RenderingContext* renderingContext =
61 new WebGL2RenderingContext(canvas, std::move(contextProvider), attrs); 77 new WebGL2RenderingContext(canvas, std::move(contextProvider), attrs);
62 78
63 if (!renderingContext->drawingBuffer()) { 79 if (!renderingContext->drawingBuffer()) {
64 canvas->dispatchEvent(WebGLContextEvent::create( 80 canvas->dispatchEvent(WebGLContextEvent::create(
65 EventTypeNames::webglcontextcreationerror, false, true, 81 EventTypeNames::webglcontextcreationerror, false, true,
66 "Could not create a WebGL2 context.")); 82 "Could not create a WebGL2 context."));
67 return nullptr; 83 return nullptr;
68 } 84 }
69 85
70 renderingContext->initializeNewContext(); 86 renderingContext->initializeNewContext();
71 renderingContext->registerContextExtensions(); 87 renderingContext->registerContextExtensions();
72 88
73 return renderingContext; 89 return renderingContext;
74 } 90 }
75 91
92 CanvasRenderingContext* WebGL2RenderingContext::Factory::create(
93 ScriptState* scriptState,
94 OffscreenCanvas* offscreenCanvas,
95 const CanvasContextCreationAttributes& attrs) {
96 std::unique_ptr<WebGraphicsContext3DProvider> contextProvider(
97 createWebGraphicsContext3DProvider(scriptState, attrs, 2));
98 if (!shouldCreateContext(contextProvider.get(), nullptr, offscreenCanvas))
99 return nullptr;
100 WebGL2RenderingContext* renderingContext = new WebGL2RenderingContext(
101 offscreenCanvas, std::move(contextProvider), attrs);
102
103 if (!renderingContext->drawingBuffer()) {
104 offscreenCanvas->dispatchEvent(WebGLContextEvent::create(
105 EventTypeNames::webglcontextcreationerror, false, true,
106 "Could not create a WebGL2 context."));
107 return nullptr;
108 }
109
110 renderingContext->initializeNewContext();
111 renderingContext->registerContextExtensions();
112
113 return renderingContext;
114 }
115
76 void WebGL2RenderingContext::Factory::onError(HTMLCanvasElement* canvas, 116 void WebGL2RenderingContext::Factory::onError(HTMLCanvasElement* canvas,
77 const String& error) { 117 const String& error) {
78 canvas->dispatchEvent(WebGLContextEvent::create( 118 canvas->dispatchEvent(WebGLContextEvent::create(
79 EventTypeNames::webglcontextcreationerror, false, true, error)); 119 EventTypeNames::webglcontextcreationerror, false, true, error));
80 } 120 }
81 121
82 WebGL2RenderingContext::WebGL2RenderingContext( 122 WebGL2RenderingContext::WebGL2RenderingContext(
83 HTMLCanvasElement* passedCanvas, 123 HTMLCanvasElement* passedCanvas,
84 std::unique_ptr<WebGraphicsContext3DProvider> contextProvider, 124 std::unique_ptr<WebGraphicsContext3DProvider> contextProvider,
85 const CanvasContextCreationAttributes& requestedAttributes) 125 const CanvasContextCreationAttributes& requestedAttributes)
86 : WebGL2RenderingContextBase(passedCanvas, 126 : WebGL2RenderingContextBase(passedCanvas,
87 std::move(contextProvider), 127 std::move(contextProvider),
88 requestedAttributes) {} 128 requestedAttributes) {}
89 129
130 WebGL2RenderingContext::WebGL2RenderingContext(
131 OffscreenCanvas* passedOffscreenCanvas,
132 std::unique_ptr<WebGraphicsContext3DProvider> contextProvider,
133 const CanvasContextCreationAttributes& requestedAttributes)
134 : WebGL2RenderingContextBase(passedOffscreenCanvas,
135 std::move(contextProvider),
136 requestedAttributes) {}
137
90 WebGL2RenderingContext::~WebGL2RenderingContext() {} 138 WebGL2RenderingContext::~WebGL2RenderingContext() {}
91 139
92 void WebGL2RenderingContext::setCanvasGetContextResult( 140 void WebGL2RenderingContext::setCanvasGetContextResult(
93 RenderingContext& result) { 141 RenderingContext& result) {
94 result.setWebGL2RenderingContext(this); 142 result.setWebGL2RenderingContext(this);
95 } 143 }
96 144
97 void WebGL2RenderingContext::setOffscreenCanvasGetContextResult( 145 void WebGL2RenderingContext::setOffscreenCanvasGetContextResult(
98 OffscreenRenderingContext& result) { 146 OffscreenRenderingContext& result) {
99 result.setWebGL2RenderingContext(this); 147 result.setWebGL2RenderingContext(this);
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
142 visitor->trace(m_webglLoseContext); 190 visitor->trace(m_webglLoseContext);
143 WebGL2RenderingContextBase::trace(visitor); 191 WebGL2RenderingContextBase::trace(visitor);
144 } 192 }
145 193
146 DEFINE_TRACE_WRAPPERS(WebGL2RenderingContext) { 194 DEFINE_TRACE_WRAPPERS(WebGL2RenderingContext) {
147 // Extensions are managed by WebGL2RenderingContextBase. 195 // Extensions are managed by WebGL2RenderingContextBase.
148 WebGL2RenderingContextBase::traceWrappers(visitor); 196 WebGL2RenderingContextBase::traceWrappers(visitor);
149 } 197 }
150 198
151 } // namespace blink 199 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698