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

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

Issue 795833004: Use dictionaries for context creation attributes. Eliminate custom bindings. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Rebased. Created 6 years 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 | Annotate | Revision Log
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2009 Apple Inc. All rights reserved. 2 * Copyright (C) 2009 Apple Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
(...skipping 11 matching lines...) Expand all
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 */ 24 */
25 25
26 #include "config.h" 26 #include "config.h"
27 #include "core/html/canvas/WebGLRenderingContext.h" 27 #include "core/html/canvas/WebGLRenderingContext.h"
28 28
29 #include "core/frame/LocalFrame.h" 29 #include "core/frame/LocalFrame.h"
30 #include "core/html/canvas/ANGLEInstancedArrays.h" 30 #include "core/html/canvas/ANGLEInstancedArrays.h"
31 #include "core/html/canvas/CHROMIUMSubscribeUniform.h" 31 #include "core/html/canvas/CHROMIUMSubscribeUniform.h"
32 #include "core/html/canvas/ContextAttributeHelpers.h"
32 #include "core/html/canvas/EXTBlendMinMax.h" 33 #include "core/html/canvas/EXTBlendMinMax.h"
33 #include "core/html/canvas/EXTFragDepth.h" 34 #include "core/html/canvas/EXTFragDepth.h"
34 #include "core/html/canvas/EXTShaderTextureLOD.h" 35 #include "core/html/canvas/EXTShaderTextureLOD.h"
35 #include "core/html/canvas/EXTTextureFilterAnisotropic.h" 36 #include "core/html/canvas/EXTTextureFilterAnisotropic.h"
36 #include "core/html/canvas/EXTsRGB.h" 37 #include "core/html/canvas/EXTsRGB.h"
37 #include "core/html/canvas/OESElementIndexUint.h" 38 #include "core/html/canvas/OESElementIndexUint.h"
38 #include "core/html/canvas/OESStandardDerivatives.h" 39 #include "core/html/canvas/OESStandardDerivatives.h"
39 #include "core/html/canvas/OESTextureFloat.h" 40 #include "core/html/canvas/OESTextureFloat.h"
40 #include "core/html/canvas/OESTextureFloatLinear.h" 41 #include "core/html/canvas/OESTextureFloatLinear.h"
41 #include "core/html/canvas/OESTextureHalfFloat.h" 42 #include "core/html/canvas/OESTextureHalfFloat.h"
42 #include "core/html/canvas/OESTextureHalfFloatLinear.h" 43 #include "core/html/canvas/OESTextureHalfFloatLinear.h"
43 #include "core/html/canvas/OESVertexArrayObject.h" 44 #include "core/html/canvas/OESVertexArrayObject.h"
44 #include "core/html/canvas/WebGLCompressedTextureATC.h" 45 #include "core/html/canvas/WebGLCompressedTextureATC.h"
45 #include "core/html/canvas/WebGLCompressedTextureETC1.h" 46 #include "core/html/canvas/WebGLCompressedTextureETC1.h"
46 #include "core/html/canvas/WebGLCompressedTexturePVRTC.h" 47 #include "core/html/canvas/WebGLCompressedTexturePVRTC.h"
47 #include "core/html/canvas/WebGLCompressedTextureS3TC.h" 48 #include "core/html/canvas/WebGLCompressedTextureS3TC.h"
48 #include "core/html/canvas/WebGLContextAttributes.h"
49 #include "core/html/canvas/WebGLContextEvent.h" 49 #include "core/html/canvas/WebGLContextEvent.h"
50 #include "core/html/canvas/WebGLDebugRendererInfo.h" 50 #include "core/html/canvas/WebGLDebugRendererInfo.h"
51 #include "core/html/canvas/WebGLDebugShaders.h" 51 #include "core/html/canvas/WebGLDebugShaders.h"
52 #include "core/html/canvas/WebGLDepthTexture.h" 52 #include "core/html/canvas/WebGLDepthTexture.h"
53 #include "core/html/canvas/WebGLDrawBuffers.h" 53 #include "core/html/canvas/WebGLDrawBuffers.h"
54 #include "core/html/canvas/WebGLLoseContext.h" 54 #include "core/html/canvas/WebGLLoseContext.h"
55 #include "core/loader/FrameLoader.h" 55 #include "core/loader/FrameLoader.h"
56 #include "core/loader/FrameLoaderClient.h" 56 #include "core/loader/FrameLoaderClient.h"
57 #include "core/frame/Settings.h" 57 #include "core/frame/Settings.h"
58 #include "core/rendering/RenderBox.h" 58 #include "core/rendering/RenderBox.h"
59 #include "platform/CheckedInt.h" 59 #include "platform/CheckedInt.h"
60 #include "platform/graphics/gpu/DrawingBuffer.h" 60 #include "platform/graphics/gpu/DrawingBuffer.h"
61 #include "public/platform/Platform.h" 61 #include "public/platform/Platform.h"
62 62
63 namespace blink { 63 namespace blink {
64 64
65 static bool shouldFailContextCreationForTesting = false; 65 static bool shouldFailContextCreationForTesting = false;
66 66
67 PassOwnPtrWillBeRawPtr<WebGLRenderingContext> WebGLRenderingContext::create(HTML CanvasElement* canvas, WebGLContextAttributes* attrs) 67 PassOwnPtrWillBeRawPtr<WebGLRenderingContext> WebGLRenderingContext::create(HTML CanvasElement* canvas, const CanvasContextCreationAttributes& attrs)
68 { 68 {
69 Document& document = canvas->document(); 69 Document& document = canvas->document();
70 LocalFrame* frame = document.frame(); 70 LocalFrame* frame = document.frame();
71 if (!frame) { 71 if (!frame) {
72 canvas->dispatchEvent(WebGLContextEvent::create(EventTypeNames::webglcon textcreationerror, false, true, "Web page was not allowed to create a WebGL cont ext.")); 72 canvas->dispatchEvent(WebGLContextEvent::create(EventTypeNames::webglcon textcreationerror, false, true, "Web page was not allowed to create a WebGL cont ext."));
73 return nullptr; 73 return nullptr;
74 } 74 }
75 Settings* settings = frame->settings(); 75 Settings* settings = frame->settings();
76 76
77 // The FrameLoaderClient might block creation of a new WebGL context despite the page settings; in 77 // The FrameLoaderClient might block creation of a new WebGL context despite the page settings; in
78 // particular, if WebGL contexts were lost one or more times via the GL_ARB_ robustness extension. 78 // particular, if WebGL contexts were lost one or more times via the GL_ARB_ robustness extension.
79 if (!frame->loader().client()->allowWebGL(settings && settings->webGLEnabled ())) { 79 if (!frame->loader().client()->allowWebGL(settings && settings->webGLEnabled ())) {
80 canvas->dispatchEvent(WebGLContextEvent::create(EventTypeNames::webglcon textcreationerror, false, true, "Web page was not allowed to create a WebGL cont ext.")); 80 canvas->dispatchEvent(WebGLContextEvent::create(EventTypeNames::webglcon textcreationerror, false, true, "Web page was not allowed to create a WebGL cont ext."));
81 return nullptr; 81 return nullptr;
82 } 82 }
83 83
84 // The only situation that attrs is null is through Document::getCSSCanvasCo ntext(). 84 WebGLContextAttributes attributes = toWebGLContextAttributes(attrs);
85 RefPtrWillBeRawPtr<WebGLContextAttributes> defaultAttrs = nullptr; 85 blink::WebGraphicsContext3D::Attributes wgc3dAttributes = toWebGraphicsConte xt3DAttributes(attributes, document.topDocument().url().string(), settings, 1);
86 if (!attrs) {
87 defaultAttrs = WebGLContextAttributes::create();
88 attrs = defaultAttrs.get();
89 }
90 blink::WebGraphicsContext3D::Attributes attributes = attrs->attributes(docum ent.topDocument().url().string(), settings, 1);
91 blink::WebGLInfo glInfo; 86 blink::WebGLInfo glInfo;
92 OwnPtr<blink::WebGraphicsContext3D> context = adoptPtr(blink::Platform::curr ent()->createOffscreenGraphicsContext3D(attributes, 0, &glInfo)); 87 OwnPtr<blink::WebGraphicsContext3D> context = adoptPtr(blink::Platform::curr ent()->createOffscreenGraphicsContext3D(wgc3dAttributes, 0, &glInfo));
93 if (!context || shouldFailContextCreationForTesting) { 88 if (!context || shouldFailContextCreationForTesting) {
94 shouldFailContextCreationForTesting = false; 89 shouldFailContextCreationForTesting = false;
95 String statusMessage("Could not create a WebGL context for VendorInfo = "); 90 String statusMessage("Could not create a WebGL context for VendorInfo = ");
96 statusMessage.append(glInfo.vendorInfo); 91 statusMessage.append(glInfo.vendorInfo);
97 statusMessage.append(", RendererInfo = "); 92 statusMessage.append(", RendererInfo = ");
98 statusMessage.append(glInfo.rendererInfo); 93 statusMessage.append(glInfo.rendererInfo);
99 statusMessage.append(", DriverInfo = "); 94 statusMessage.append(", DriverInfo = ");
100 statusMessage.append(glInfo.driverVersion); 95 statusMessage.append(glInfo.driverVersion);
101 statusMessage.append("."); 96 statusMessage.append(".");
102 canvas->dispatchEvent(WebGLContextEvent::create(EventTypeNames::webglcon textcreationerror, false, true, statusMessage)); 97 canvas->dispatchEvent(WebGLContextEvent::create(EventTypeNames::webglcon textcreationerror, false, true, statusMessage));
103 return nullptr; 98 return nullptr;
104 } 99 }
105 100
106 OwnPtr<Extensions3DUtil> extensionsUtil = Extensions3DUtil::create(context.g et()); 101 OwnPtr<Extensions3DUtil> extensionsUtil = Extensions3DUtil::create(context.g et());
107 if (!extensionsUtil) 102 if (!extensionsUtil)
108 return nullptr; 103 return nullptr;
109 if (extensionsUtil->supportsExtension("GL_EXT_debug_marker")) 104 if (extensionsUtil->supportsExtension("GL_EXT_debug_marker"))
110 context->pushGroupMarkerEXT("WebGLRenderingContext"); 105 context->pushGroupMarkerEXT("WebGLRenderingContext");
111 106
112 OwnPtrWillBeRawPtr<WebGLRenderingContext> renderingContext = adoptPtrWillBeN oop(new WebGLRenderingContext(canvas, context.release(), attrs)); 107 OwnPtrWillBeRawPtr<WebGLRenderingContext> renderingContext = adoptPtrWillBeN oop(new WebGLRenderingContext(canvas, context.release(), attributes));
113 renderingContext->registerContextExtensions(); 108 renderingContext->registerContextExtensions();
114 renderingContext->suspendIfNeeded(); 109 renderingContext->suspendIfNeeded();
115 110
116 if (!renderingContext->drawingBuffer()) { 111 if (!renderingContext->drawingBuffer()) {
117 canvas->dispatchEvent(WebGLContextEvent::create(EventTypeNames::webglcon textcreationerror, false, true, "Could not create a WebGL context.")); 112 canvas->dispatchEvent(WebGLContextEvent::create(EventTypeNames::webglcon textcreationerror, false, true, "Could not create a WebGL context."));
118 return nullptr; 113 return nullptr;
119 } 114 }
120 115
121 return renderingContext.release(); 116 return renderingContext.release();
122 } 117 }
123 118
124 WebGLRenderingContext::WebGLRenderingContext(HTMLCanvasElement* passedCanvas, Pa ssOwnPtr<blink::WebGraphicsContext3D> context, WebGLContextAttributes* requested Attributes) 119 WebGLRenderingContext::WebGLRenderingContext(HTMLCanvasElement* passedCanvas, Pa ssOwnPtr<blink::WebGraphicsContext3D> context, const WebGLContextAttributes& req uestedAttributes)
125 : WebGLRenderingContextBase(passedCanvas, context, requestedAttributes) 120 : WebGLRenderingContextBase(passedCanvas, context, requestedAttributes)
126 { 121 {
127 } 122 }
128 123
129 WebGLRenderingContext::~WebGLRenderingContext() 124 WebGLRenderingContext::~WebGLRenderingContext()
130 { 125 {
131 } 126 }
132 127
133 void WebGLRenderingContext::registerContextExtensions() 128 void WebGLRenderingContext::registerContextExtensions()
134 { 129 {
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
187 visitor->trace(m_webglDepthTexture); 182 visitor->trace(m_webglDepthTexture);
188 WebGLRenderingContextBase::trace(visitor); 183 WebGLRenderingContextBase::trace(visitor);
189 } 184 }
190 185
191 void WebGLRenderingContext::forceNextWebGLContextCreationToFail() 186 void WebGLRenderingContext::forceNextWebGLContextCreationToFail()
192 { 187 {
193 shouldFailContextCreationForTesting = true; 188 shouldFailContextCreationForTesting = true;
194 } 189 }
195 190
196 } // namespace blink 191 } // namespace blink
OLDNEW
« no previous file with comments | « Source/core/html/canvas/WebGLRenderingContext.h ('k') | Source/core/html/canvas/WebGLRenderingContextBase.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698