OLD | NEW |
---|---|
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 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
54 #include "core/loader/FrameLoader.h" | 54 #include "core/loader/FrameLoader.h" |
55 #include "core/loader/FrameLoaderClient.h" | 55 #include "core/loader/FrameLoaderClient.h" |
56 #include "core/frame/Settings.h" | 56 #include "core/frame/Settings.h" |
57 #include "core/rendering/RenderBox.h" | 57 #include "core/rendering/RenderBox.h" |
58 #include "platform/CheckedInt.h" | 58 #include "platform/CheckedInt.h" |
59 #include "platform/graphics/gpu/DrawingBuffer.h" | 59 #include "platform/graphics/gpu/DrawingBuffer.h" |
60 #include "public/platform/Platform.h" | 60 #include "public/platform/Platform.h" |
61 | 61 |
62 namespace blink { | 62 namespace blink { |
63 | 63 |
64 static bool shouldFailContextCreationForTesting = false; | |
65 | |
64 PassOwnPtrWillBeRawPtr<WebGLRenderingContext> WebGLRenderingContext::create(HTML CanvasElement* canvas, WebGLContextAttributes* attrs) | 66 PassOwnPtrWillBeRawPtr<WebGLRenderingContext> WebGLRenderingContext::create(HTML CanvasElement* canvas, WebGLContextAttributes* attrs) |
65 { | 67 { |
66 Document& document = canvas->document(); | 68 Document& document = canvas->document(); |
67 LocalFrame* frame = document.frame(); | 69 LocalFrame* frame = document.frame(); |
68 if (!frame) { | 70 if (!frame) { |
69 canvas->dispatchEvent(WebGLContextEvent::create(EventTypeNames::webglcon textcreationerror, false, true, "Web page was not allowed to create a WebGL cont ext.")); | 71 canvas->dispatchEvent(WebGLContextEvent::create(EventTypeNames::webglcon textcreationerror, false, true, "Web page was not allowed to create a WebGL cont ext.")); |
70 return nullptr; | 72 return nullptr; |
71 } | 73 } |
72 Settings* settings = frame->settings(); | 74 Settings* settings = frame->settings(); |
73 | 75 |
74 // The FrameLoaderClient might block creation of a new WebGL context despite the page settings; in | 76 // The FrameLoaderClient might block creation of a new WebGL context despite the page settings; in |
75 // particular, if WebGL contexts were lost one or more times via the GL_ARB_ robustness extension. | 77 // particular, if WebGL contexts were lost one or more times via the GL_ARB_ robustness extension. |
76 if (!frame->loader().client()->allowWebGL(settings && settings->webGLEnabled ())) { | 78 if (!frame->loader().client()->allowWebGL(settings && settings->webGLEnabled ())) { |
77 canvas->dispatchEvent(WebGLContextEvent::create(EventTypeNames::webglcon textcreationerror, false, true, "Web page was not allowed to create a WebGL cont ext.")); | 79 canvas->dispatchEvent(WebGLContextEvent::create(EventTypeNames::webglcon textcreationerror, false, true, "Web page was not allowed to create a WebGL cont ext.")); |
78 return nullptr; | 80 return nullptr; |
79 } | 81 } |
80 | 82 |
81 // The only situation that attrs is null is through Document::getCSSCanvasCo ntext(). | 83 // The only situation that attrs is null is through Document::getCSSCanvasCo ntext(). |
82 RefPtrWillBeRawPtr<WebGLContextAttributes> defaultAttrs = nullptr; | 84 RefPtrWillBeRawPtr<WebGLContextAttributes> defaultAttrs = nullptr; |
83 if (!attrs) { | 85 if (!attrs) { |
84 defaultAttrs = WebGLContextAttributes::create(); | 86 defaultAttrs = WebGLContextAttributes::create(); |
85 attrs = defaultAttrs.get(); | 87 attrs = defaultAttrs.get(); |
86 } | 88 } |
87 blink::WebGraphicsContext3D::Attributes attributes = attrs->attributes(docum ent.topDocument().url().string(), settings, 1); | 89 blink::WebGraphicsContext3D::Attributes attributes = attrs->attributes(docum ent.topDocument().url().string(), settings, 1); |
88 blink::WebGLInfo glInfo; | 90 blink::WebGLInfo glInfo; |
89 OwnPtr<blink::WebGraphicsContext3D> context = adoptPtr(blink::Platform::curr ent()->createOffscreenGraphicsContext3D(attributes, 0, &glInfo)); | 91 OwnPtr<blink::WebGraphicsContext3D> context = adoptPtr(blink::Platform::curr ent()->createOffscreenGraphicsContext3D(attributes, 0, &glInfo)); |
90 if (!context) { | 92 if (!context || shouldFailContextCreationForTesting) { |
91 String statusMessage("Could not create a WebGL context for VendorInfo = "); | 93 String statusMessage("Could not create a WebGL context for VendorInfo = "); |
92 statusMessage.append(glInfo.vendorInfo); | 94 statusMessage.append(glInfo.vendorInfo); |
93 statusMessage.append(", RendererInfo = "); | 95 statusMessage.append(", RendererInfo = "); |
94 statusMessage.append(glInfo.rendererInfo); | 96 statusMessage.append(glInfo.rendererInfo); |
95 statusMessage.append(", DriverInfo = "); | 97 statusMessage.append(", DriverInfo = "); |
96 statusMessage.append(glInfo.driverVersion); | 98 statusMessage.append(glInfo.driverVersion); |
97 statusMessage.append("."); | 99 statusMessage.append("."); |
98 canvas->dispatchEvent(WebGLContextEvent::create(EventTypeNames::webglcon textcreationerror, false, true, statusMessage)); | 100 canvas->dispatchEvent(WebGLContextEvent::create(EventTypeNames::webglcon textcreationerror, false, true, statusMessage)); |
101 shouldFailContextCreationForTesting = false; | |
Ken Russell (switch to Gerrit)
2014/11/12 21:26:02
This should be moved up to the beginning of the bl
sivag
2014/11/13 03:40:31
Done.
| |
99 return nullptr; | 102 return nullptr; |
100 } | 103 } |
101 | 104 |
102 OwnPtr<Extensions3DUtil> extensionsUtil = Extensions3DUtil::create(context.g et()); | 105 OwnPtr<Extensions3DUtil> extensionsUtil = Extensions3DUtil::create(context.g et()); |
103 if (!extensionsUtil) | 106 if (!extensionsUtil) |
104 return nullptr; | 107 return nullptr; |
105 if (extensionsUtil->supportsExtension("GL_EXT_debug_marker")) | 108 if (extensionsUtil->supportsExtension("GL_EXT_debug_marker")) |
106 context->pushGroupMarkerEXT("WebGLRenderingContext"); | 109 context->pushGroupMarkerEXT("WebGLRenderingContext"); |
107 | 110 |
108 OwnPtrWillBeRawPtr<WebGLRenderingContext> renderingContext = adoptPtrWillBeN oop(new WebGLRenderingContext(canvas, context.release(), attrs)); | 111 OwnPtrWillBeRawPtr<WebGLRenderingContext> renderingContext = adoptPtrWillBeN oop(new WebGLRenderingContext(canvas, context.release(), attrs)); |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
175 visitor->trace(m_webglDebugShaders); | 178 visitor->trace(m_webglDebugShaders); |
176 visitor->trace(m_webglDrawBuffers); | 179 visitor->trace(m_webglDrawBuffers); |
177 visitor->trace(m_webglCompressedTextureATC); | 180 visitor->trace(m_webglCompressedTextureATC); |
178 visitor->trace(m_webglCompressedTextureETC1); | 181 visitor->trace(m_webglCompressedTextureETC1); |
179 visitor->trace(m_webglCompressedTexturePVRTC); | 182 visitor->trace(m_webglCompressedTexturePVRTC); |
180 visitor->trace(m_webglCompressedTextureS3TC); | 183 visitor->trace(m_webglCompressedTextureS3TC); |
181 visitor->trace(m_webglDepthTexture); | 184 visitor->trace(m_webglDepthTexture); |
182 WebGLRenderingContextBase::trace(visitor); | 185 WebGLRenderingContextBase::trace(visitor); |
183 } | 186 } |
184 | 187 |
188 void WebGLRenderingContext::forceNextWebGLContextCreationToFail() | |
189 { | |
190 shouldFailContextCreationForTesting = true; | |
191 } | |
192 | |
185 } // namespace blink | 193 } // namespace blink |
OLD | NEW |