// Copyright 2015 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "config.h" #include "modules/webgl/WebGL2RenderingContext.h" #include "core/frame/LocalFrame.h" #include "core/frame/Settings.h" #include "core/loader/FrameLoader.h" #include "core/loader/FrameLoaderClient.h" #include "modules/webgl/CHROMIUMSubscribeUniform.h" #include "modules/webgl/EXTColorBufferFloat.h" #include "modules/webgl/EXTTextureFilterAnisotropic.h" #include "modules/webgl/OESTextureFloatLinear.h" #include "modules/webgl/WebGLCompressedTextureASTC.h" #include "modules/webgl/WebGLCompressedTextureATC.h" #include "modules/webgl/WebGLCompressedTextureETC1.h" #include "modules/webgl/WebGLCompressedTexturePVRTC.h" #include "modules/webgl/WebGLCompressedTextureS3TC.h" #include "modules/webgl/WebGLContextAttributeHelpers.h" #include "modules/webgl/WebGLContextEvent.h" #include "modules/webgl/WebGLDebugRendererInfo.h" #include "modules/webgl/WebGLDebugShaders.h" #include "modules/webgl/WebGLLoseContext.h" #include "platform/graphics/gpu/DrawingBuffer.h" #include "public/platform/Platform.h" namespace blink { PassOwnPtrWillBeRawPtr WebGL2RenderingContext::Factory::create(HTMLCanvasElement* canvas, const CanvasContextCreationAttributes& attrs, Document&) { if (!RuntimeEnabledFeatures::unsafeES3APIsEnabled()) { canvas->dispatchEvent(WebGLContextEvent::create(EventTypeNames::webglcontextcreationerror, false, true, "Creation of WebGL2 contexts disabled.")); return nullptr; } WebGLContextAttributes attributes = toWebGLContextAttributes(attrs); OwnPtr context(createWebGraphicsContext3D(canvas, attributes, 2)); if (!context) return nullptr; OwnPtr extensionsUtil = Extensions3DUtil::create(context.get()); if (!extensionsUtil) return nullptr; if (extensionsUtil->supportsExtension("GL_EXT_debug_marker")) { String contextLabel(String::format("WebGL2RenderingContext-%p", context.get())); context->pushGroupMarkerEXT(contextLabel.ascii().data()); } OwnPtrWillBeRawPtr renderingContext = adoptPtrWillBeNoop(new WebGL2RenderingContext(canvas, context.release(), attributes)); if (!renderingContext->drawingBuffer()) { canvas->dispatchEvent(WebGLContextEvent::create(EventTypeNames::webglcontextcreationerror, false, true, "Could not create a WebGL2 context.")); return nullptr; } renderingContext->initializeNewContext(); renderingContext->registerContextExtensions(); return renderingContext.release(); } void WebGL2RenderingContext::Factory::onError(HTMLCanvasElement* canvas, const String& error) { canvas->dispatchEvent(WebGLContextEvent::create(EventTypeNames::webglcontextcreationerror, false, true, error)); } WebGL2RenderingContext::WebGL2RenderingContext(HTMLCanvasElement* passedCanvas, PassOwnPtr context, const WebGLContextAttributes& requestedAttributes) : WebGL2RenderingContextBase(passedCanvas, context, requestedAttributes) { } WebGL2RenderingContext::~WebGL2RenderingContext() { } void WebGL2RenderingContext::registerContextExtensions() { // Register extensions. registerExtension(m_chromiumSubscribeUniform); registerExtension(m_extColorBufferFloat, DraftExtension); registerExtension(m_extTextureFilterAnisotropic); registerExtension(m_oesTextureFloatLinear); registerExtension(m_webglCompressedTextureASTC); registerExtension(m_webglCompressedTextureATC); registerExtension(m_webglCompressedTextureETC1); registerExtension(m_webglCompressedTexturePVRTC); registerExtension(m_webglCompressedTextureS3TC); registerExtension(m_webglDebugRendererInfo); registerExtension(m_webglDebugShaders); registerExtension(m_webglLoseContext); } DEFINE_TRACE(WebGL2RenderingContext) { visitor->trace(m_chromiumSubscribeUniform); visitor->trace(m_extColorBufferFloat); visitor->trace(m_extTextureFilterAnisotropic); visitor->trace(m_oesTextureFloatLinear); visitor->trace(m_webglCompressedTextureASTC); visitor->trace(m_webglCompressedTextureATC); visitor->trace(m_webglCompressedTextureETC1); visitor->trace(m_webglCompressedTexturePVRTC); visitor->trace(m_webglCompressedTextureS3TC); visitor->trace(m_webglDebugRendererInfo); visitor->trace(m_webglDebugShaders); visitor->trace(m_webglLoseContext); WebGL2RenderingContextBase::trace(visitor); } } // namespace blink