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

Side by Side Diff: Source/core/html/canvas/WebGL2RenderingContext.cpp

Issue 894143002: Adding Blink bindings for WebGL 2 (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Updating objects to use the correct Oilpan transition types. Created 5 years, 10 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "config.h"
6 #include "core/html/canvas/WebGL2RenderingContext.h"
7
8 #include "core/frame/LocalFrame.h"
9 #include "core/frame/Settings.h"
10 #include "core/html/canvas/ContextAttributeHelpers.h"
11 #include "core/html/canvas/WebGLContextAttributes.h"
12 #include "core/html/canvas/WebGLContextEvent.h"
13 #include "core/html/canvas/WebGLDebugRendererInfo.h"
14 #include "core/html/canvas/WebGLDebugShaders.h"
15 #include "core/loader/FrameLoader.h"
16 #include "core/loader/FrameLoaderClient.h"
17 #include "platform/graphics/gpu/DrawingBuffer.h"
18 #include "public/platform/Platform.h"
19
20 namespace blink {
21
22 static bool shouldFailContextCreationForTesting = false;
23
24 PassOwnPtr<WebGL2RenderingContext> WebGL2RenderingContext::create(HTMLCanvasElem ent* canvas, const CanvasContextCreationAttributes& attrs)
25 {
26 if (!RuntimeEnabledFeatures::unsafeES3APIsEnabled()) {
27 canvas->dispatchEvent(WebGLContextEvent::create(EventTypeNames::webglcon textcreationerror, false, true, "Creation of WebGL2 contexts disabled."));
28 return nullptr;
29 }
30
31 Document& document = canvas->document();
32 LocalFrame* frame = document.frame();
33 if (!frame) {
34 canvas->dispatchEvent(WebGLContextEvent::create(EventTypeNames::webglcon textcreationerror, false, true, "Web page was not allowed to create a WebGL2 con text."));
35 return nullptr;
36 }
37 Settings* settings = frame->settings();
38
39 // The FrameLoaderClient might block creation of a new WebGL context despite the page settings; in
40 // particular, if WebGL contexts were lost one or more times via the GL_ARB_ robustness extension.
41 if (!frame->loader().client()->allowWebGL(settings && settings->webGLEnabled ())) {
42 canvas->dispatchEvent(WebGLContextEvent::create(EventTypeNames::webglcon textcreationerror, false, true, "Web page was not allowed to create a WebGL2 con text."));
43 return nullptr;
44 }
45
46 WebGLContextAttributes attributes = toWebGLContextAttributes(attrs);
47 blink::WebGraphicsContext3D::Attributes wgc3dAttributes = toWebGraphicsConte xt3DAttributes(attributes, document.topDocument().url().string(), settings, 2);
48 blink::WebGLInfo glInfo;
49 OwnPtr<blink::WebGraphicsContext3D> context = adoptPtr(blink::Platform::curr ent()->createOffscreenGraphicsContext3D(wgc3dAttributes, 0, &glInfo));
50 if (!context || shouldFailContextCreationForTesting) {
51 shouldFailContextCreationForTesting = false;
Ken Russell (switch to Gerrit) 2015/02/03 01:23:24 Please refactor this boilerplate error handling co
52 String statusMessage;
53 if (!glInfo.contextInfoCollectionFailure.isEmpty()) {
54 statusMessage.append("Could not create a WebGL2 context. ");
55 statusMessage.append(glInfo.contextInfoCollectionFailure);
56 } else {
57 statusMessage.append("Could not create a WebGL2 context");
58 if (!glInfo.vendorInfo.isEmpty()) {
59 statusMessage.append(" VendorInfo = ");
60 statusMessage.append(glInfo.vendorInfo);
61 } else {
62 statusMessage.append(" VendorInfo = Not Available");
63 }
64 if (!glInfo.rendererInfo.isEmpty()) {
65 statusMessage.append(", RendererInfo = ");
66 statusMessage.append(glInfo.rendererInfo);
67 } else {
68 statusMessage.append(", RendererInfo = Not Available");
69 }
70 if (!glInfo.driverVersion.isEmpty()) {
71 statusMessage.append(", DriverInfo = ");
72 statusMessage.append(glInfo.driverVersion);
73 } else {
74 statusMessage.append(", DriverInfo = Not Available");
75 }
76 statusMessage.append(".");
77 }
78 canvas->dispatchEvent(WebGLContextEvent::create(EventTypeNames::webglcon textcreationerror, false, true, statusMessage));
79 return nullptr;
80 }
81
82 OwnPtr<Extensions3DUtil> extensionsUtil = Extensions3DUtil::create(context.g et());
83 if (!extensionsUtil)
84 return nullptr;
85 if (extensionsUtil->supportsExtension("GL_EXT_debug_marker")) {
86 String contextLabel(String::format("WebGL2RenderingContext-%p", context. get()));
87 context->pushGroupMarkerEXT(contextLabel.ascii().data());
88 }
89
90 OwnPtrWillBeRawPtr<WebGL2RenderingContext> renderingContext = adoptPtrWillBe Noop(new WebGL2RenderingContext(canvas, context.release(), attributes));
91 renderingContext->registerContextExtensions();
92 renderingContext->suspendIfNeeded();
93
94 if (!renderingContext->drawingBuffer()) {
95 canvas->dispatchEvent(WebGLContextEvent::create(EventTypeNames::webglcon textcreationerror, false, true, "Could not create a WebGL2 context."));
96 return nullptr;
97 }
98
99 return renderingContext.release();
100 }
101
102 WebGL2RenderingContext::WebGL2RenderingContext(HTMLCanvasElement* passedCanvas, PassOwnPtr<blink::WebGraphicsContext3D> context, const WebGLContextAttributes& r equestedAttributes)
103 : WebGL2RenderingContextBase(passedCanvas, context, requestedAttributes)
104 {
105 }
106
107 WebGL2RenderingContext::~WebGL2RenderingContext()
108 {
109
110 }
111
112 void WebGL2RenderingContext::registerContextExtensions()
113 {
114 // Register privileged extensions.
115 registerExtension<WebGLDebugRendererInfo>(m_webglDebugRendererInfo);
116 registerExtension<WebGLDebugShaders>(m_webglDebugShaders);
117 }
118
119 void WebGL2RenderingContext::trace(Visitor* visitor)
120 {
121 visitor->trace(m_webglDebugRendererInfo);
122 visitor->trace(m_webglDebugShaders);
123 WebGL2RenderingContextBase::trace(visitor);
124 }
125
126 void WebGL2RenderingContext::forceNextWebGLContextCreationToFail()
127 {
128 shouldFailContextCreationForTesting = true;
129 }
130
131 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698