/* * Copyright (C) 2009 Apple Inc. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include "config.h" #include "core/html/canvas/WebGLRenderingContext.h" #include "core/frame/LocalFrame.h" #include "core/html/canvas/ANGLEInstancedArrays.h" #include "core/html/canvas/EXTBlendMinMax.h" #include "core/html/canvas/EXTFragDepth.h" #include "core/html/canvas/EXTShaderTextureLOD.h" #include "core/html/canvas/EXTTextureFilterAnisotropic.h" #include "core/html/canvas/OESElementIndexUint.h" #include "core/html/canvas/OESStandardDerivatives.h" #include "core/html/canvas/OESTextureFloat.h" #include "core/html/canvas/OESTextureFloatLinear.h" #include "core/html/canvas/OESTextureHalfFloat.h" #include "core/html/canvas/OESTextureHalfFloatLinear.h" #include "core/html/canvas/OESVertexArrayObject.h" #include "core/html/canvas/WebGLCompressedTextureATC.h" #include "core/html/canvas/WebGLCompressedTextureETC1.h" #include "core/html/canvas/WebGLCompressedTexturePVRTC.h" #include "core/html/canvas/WebGLCompressedTextureS3TC.h" #include "core/html/canvas/WebGLContextAttributes.h" #include "core/html/canvas/WebGLContextEvent.h" #include "core/html/canvas/WebGLDebugRendererInfo.h" #include "core/html/canvas/WebGLDebugShaders.h" #include "core/html/canvas/WebGLDepthTexture.h" #include "core/html/canvas/WebGLDrawBuffers.h" #include "core/html/canvas/WebGLLoseContext.h" #include "core/loader/FrameLoaderClient.h" #include "core/frame/Settings.h" #include "core/rendering/RenderBox.h" #include "platform/CheckedInt.h" #include "platform/NotImplemented.h" #include "platform/graphics/gpu/DrawingBuffer.h" #include "public/platform/Platform.h" namespace blink { PassOwnPtrWillBeRawPtr WebGLRenderingContext::create(HTMLCanvasElement* canvas, WebGLContextAttributes* attrs) { Document& document = canvas->document(); LocalFrame* frame = document.frame(); if (!frame) { canvas->dispatchEvent(WebGLContextEvent::create(EventTypeNames::webglcontextcreationerror, false, true, "Web page was not allowed to create a WebGL context.")); return nullptr; } Settings* settings = frame->settings(); // The only situation that attrs is null is through Document::getCSSCanvasContext(). RefPtrWillBeRawPtr defaultAttrs = nullptr; if (!attrs) { defaultAttrs = WebGLContextAttributes::create(); attrs = defaultAttrs.get(); } blink::WebGraphicsContext3D::Attributes attributes = attrs->attributes(document.topDocument().url().string(), settings, 1); OwnPtr context = adoptPtr(blink::Platform::current()->createOffscreenGraphicsContext3D(attributes, 0)); if (!context) { canvas->dispatchEvent(WebGLContextEvent::create(EventTypeNames::webglcontextcreationerror, false, true, "Could not create a WebGL context.")); return nullptr; } OwnPtr extensionsUtil = Extensions3DUtil::create(context.get()); if (!extensionsUtil) return nullptr; if (extensionsUtil->supportsExtension("GL_EXT_debug_marker")) context->pushGroupMarkerEXT("WebGLRenderingContext"); OwnPtrWillBeRawPtr renderingContext = adoptPtrWillBeNoop(new WebGLRenderingContext(canvas, context.release(), attrs)); renderingContext->registerContextExtensions(); renderingContext->suspendIfNeeded(); if (!renderingContext->drawingBuffer()) { canvas->dispatchEvent(WebGLContextEvent::create(EventTypeNames::webglcontextcreationerror, false, true, "Could not create a WebGL context.")); return nullptr; } return renderingContext.release(); } WebGLRenderingContext::WebGLRenderingContext(HTMLCanvasElement* passedCanvas, PassOwnPtr context, WebGLContextAttributes* requestedAttributes) : WebGLRenderingContextBase(passedCanvas, context, requestedAttributes) { ScriptWrappable::init(this); } WebGLRenderingContext::~WebGLRenderingContext() { } void WebGLRenderingContext::registerContextExtensions() { // Register extensions. static const char* const bothPrefixes[] = { "", "WEBKIT_", 0, }; registerExtension(m_angleInstancedArrays); registerExtension(m_extBlendMinMax); registerExtension(m_extFragDepth); registerExtension(m_extShaderTextureLOD); registerExtension(m_extTextureFilterAnisotropic, ApprovedExtension, bothPrefixes); registerExtension(m_oesElementIndexUint); registerExtension(m_oesStandardDerivatives); registerExtension(m_oesTextureFloat); registerExtension(m_oesTextureFloatLinear); registerExtension(m_oesTextureHalfFloat); registerExtension(m_oesTextureHalfFloatLinear); registerExtension(m_oesVertexArrayObject); registerExtension(m_webglCompressedTextureATC, ApprovedExtension, bothPrefixes); registerExtension(m_webglCompressedTextureETC1); registerExtension(m_webglCompressedTexturePVRTC, ApprovedExtension, bothPrefixes); registerExtension(m_webglCompressedTextureS3TC, ApprovedExtension, bothPrefixes); registerExtension(m_webglDebugRendererInfo); registerExtension(m_webglDebugShaders); registerExtension(m_webglDepthTexture, ApprovedExtension, bothPrefixes); registerExtension(m_webglDrawBuffers); registerExtension(m_webglLoseContext, ApprovedExtension, bothPrefixes); } void WebGLRenderingContext::trace(Visitor* visitor) { visitor->trace(m_angleInstancedArrays); visitor->trace(m_extBlendMinMax); visitor->trace(m_extFragDepth); visitor->trace(m_extShaderTextureLOD); visitor->trace(m_extTextureFilterAnisotropic); visitor->trace(m_oesTextureFloat); visitor->trace(m_oesTextureFloatLinear); visitor->trace(m_oesTextureHalfFloat); visitor->trace(m_oesTextureHalfFloatLinear); visitor->trace(m_oesStandardDerivatives); visitor->trace(m_oesVertexArrayObject); visitor->trace(m_oesElementIndexUint); visitor->trace(m_webglLoseContext); visitor->trace(m_webglDebugRendererInfo); visitor->trace(m_webglDebugShaders); visitor->trace(m_webglDrawBuffers); visitor->trace(m_webglCompressedTextureATC); visitor->trace(m_webglCompressedTextureETC1); visitor->trace(m_webglCompressedTexturePVRTC); visitor->trace(m_webglCompressedTextureS3TC); visitor->trace(m_webglDepthTexture); WebGLRenderingContextBase::trace(visitor); } } // namespace blink