| 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 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 55 #include "core/html/canvas/WebGLLoseContext.h" | 55 #include "core/html/canvas/WebGLLoseContext.h" |
| 56 #include "core/loader/FrameLoader.h" | 56 #include "core/loader/FrameLoader.h" |
| 57 #include "core/loader/FrameLoaderClient.h" | 57 #include "core/loader/FrameLoaderClient.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; | |
| 66 | |
| 67 PassOwnPtrWillBeRawPtr<WebGLRenderingContext> WebGLRenderingContext::create(HTML
CanvasElement* canvas, const CanvasContextCreationAttributes& attrs) | 65 PassOwnPtrWillBeRawPtr<WebGLRenderingContext> WebGLRenderingContext::create(HTML
CanvasElement* canvas, const CanvasContextCreationAttributes& attrs) |
| 68 { | 66 { |
| 69 Document& document = canvas->document(); | 67 WebGLContextAttributes attributes = toWebGLContextAttributes(attrs); |
| 70 LocalFrame* frame = document.frame(); | 68 OwnPtr<blink::WebGraphicsContext3D> context(createWebGraphicsContext3D(canva
s, attributes, 1)); |
| 71 if (!frame) { | 69 if (!context) |
| 72 canvas->dispatchEvent(WebGLContextEvent::create(EventTypeNames::webglcon
textcreationerror, false, true, "Web page was not allowed to create a WebGL cont
ext.")); | |
| 73 return nullptr; | 70 return nullptr; |
| 74 } | |
| 75 Settings* settings = frame->settings(); | |
| 76 | |
| 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. | |
| 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.")); | |
| 81 return nullptr; | |
| 82 } | |
| 83 | |
| 84 WebGLContextAttributes attributes = toWebGLContextAttributes(attrs); | |
| 85 blink::WebGraphicsContext3D::Attributes wgc3dAttributes = toWebGraphicsConte
xt3DAttributes(attributes, document.topDocument().url().string(), settings, 1); | |
| 86 blink::WebGLInfo glInfo; | |
| 87 OwnPtr<blink::WebGraphicsContext3D> context = adoptPtr(blink::Platform::curr
ent()->createOffscreenGraphicsContext3D(wgc3dAttributes, 0, &glInfo)); | |
| 88 if (!context || shouldFailContextCreationForTesting) { | |
| 89 shouldFailContextCreationForTesting = false; | |
| 90 String statusMessage; | |
| 91 if (!glInfo.contextInfoCollectionFailure.isEmpty()) { | |
| 92 statusMessage.append("Could not create a WebGL context. "); | |
| 93 statusMessage.append(glInfo.contextInfoCollectionFailure); | |
| 94 } else { | |
| 95 statusMessage.append("Could not create a WebGL context"); | |
| 96 if (!glInfo.vendorInfo.isEmpty()) { | |
| 97 statusMessage.append(" VendorInfo = "); | |
| 98 statusMessage.append(glInfo.vendorInfo); | |
| 99 } else { | |
| 100 statusMessage.append(" VendorInfo = Not Available"); | |
| 101 } | |
| 102 if (!glInfo.rendererInfo.isEmpty()) { | |
| 103 statusMessage.append(", RendererInfo = "); | |
| 104 statusMessage.append(glInfo.rendererInfo); | |
| 105 } else { | |
| 106 statusMessage.append(", RendererInfo = Not Available"); | |
| 107 } | |
| 108 if (!glInfo.driverVersion.isEmpty()) { | |
| 109 statusMessage.append(", DriverInfo = "); | |
| 110 statusMessage.append(glInfo.driverVersion); | |
| 111 } else { | |
| 112 statusMessage.append(", DriverInfo = Not Available"); | |
| 113 } | |
| 114 statusMessage.append("."); | |
| 115 } | |
| 116 canvas->dispatchEvent(WebGLContextEvent::create(EventTypeNames::webglcon
textcreationerror, false, true, statusMessage)); | |
| 117 return nullptr; | |
| 118 } | |
| 119 | |
| 120 OwnPtr<Extensions3DUtil> extensionsUtil = Extensions3DUtil::create(context.g
et()); | 71 OwnPtr<Extensions3DUtil> extensionsUtil = Extensions3DUtil::create(context.g
et()); |
| 121 if (!extensionsUtil) | 72 if (!extensionsUtil) |
| 122 return nullptr; | 73 return nullptr; |
| 123 if (extensionsUtil->supportsExtension("GL_EXT_debug_marker")) { | 74 if (extensionsUtil->supportsExtension("GL_EXT_debug_marker")) { |
| 124 String contextLabel(String::format("WebGLRenderingContext-%p", context.g
et())); | 75 String contextLabel(String::format("WebGLRenderingContext-%p", context.g
et())); |
| 125 context->pushGroupMarkerEXT(contextLabel.ascii().data()); | 76 context->pushGroupMarkerEXT(contextLabel.ascii().data()); |
| 126 } | 77 } |
| 127 | 78 |
| 128 OwnPtrWillBeRawPtr<WebGLRenderingContext> renderingContext = adoptPtrWillBeN
oop(new WebGLRenderingContext(canvas, context.release(), attributes)); | 79 OwnPtrWillBeRawPtr<WebGLRenderingContext> renderingContext = adoptPtrWillBeN
oop(new WebGLRenderingContext(canvas, context.release(), attributes)); |
| 129 renderingContext->registerContextExtensions(); | 80 renderingContext->registerContextExtensions(); |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 197 visitor->trace(m_webglDebugShaders); | 148 visitor->trace(m_webglDebugShaders); |
| 198 visitor->trace(m_webglDrawBuffers); | 149 visitor->trace(m_webglDrawBuffers); |
| 199 visitor->trace(m_webglCompressedTextureATC); | 150 visitor->trace(m_webglCompressedTextureATC); |
| 200 visitor->trace(m_webglCompressedTextureETC1); | 151 visitor->trace(m_webglCompressedTextureETC1); |
| 201 visitor->trace(m_webglCompressedTexturePVRTC); | 152 visitor->trace(m_webglCompressedTexturePVRTC); |
| 202 visitor->trace(m_webglCompressedTextureS3TC); | 153 visitor->trace(m_webglCompressedTextureS3TC); |
| 203 visitor->trace(m_webglDepthTexture); | 154 visitor->trace(m_webglDepthTexture); |
| 204 WebGLRenderingContextBase::trace(visitor); | 155 WebGLRenderingContextBase::trace(visitor); |
| 205 } | 156 } |
| 206 | 157 |
| 207 void WebGLRenderingContext::forceNextWebGLContextCreationToFail() | |
| 208 { | |
| 209 shouldFailContextCreationForTesting = true; | |
| 210 } | |
| 211 | |
| 212 } // namespace blink | 158 } // namespace blink |
| OLD | NEW |