This source file includes following definitions.
- create
- registerContextExtensions
#include "config.h"
#include "core/html/canvas/WebGLRenderingContext.h"
#include "core/frame/LocalFrame.h"
#include "core/html/canvas/ANGLEInstancedArrays.h"
#include "core/html/canvas/EXTFragDepth.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/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/FrameLoader.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 WebCore {
PassOwnPtr<WebGLRenderingContext> 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();
if (!frame->loader().client()->allowWebGL(settings && settings->webGLEnabled())) {
canvas->dispatchEvent(WebGLContextEvent::create(EventTypeNames::webglcontextcreationerror, false, true, "Web page was not allowed to create a WebGL context."));
return nullptr;
}
RefPtr<WebGLContextAttributes> defaultAttrs;
if (!attrs) {
defaultAttrs = WebGLContextAttributes::create();
attrs = defaultAttrs.get();
}
blink::WebGraphicsContext3D::Attributes attributes = attrs->attributes(document.topDocument().url().string(), settings);
OwnPtr<blink::WebGraphicsContext3D> context = adoptPtr(blink::Platform::current()->createOffscreenGraphicsContext3D(attributes, 0));
if (!context || !context->makeContextCurrent()) {
canvas->dispatchEvent(WebGLContextEvent::create(EventTypeNames::webglcontextcreationerror, false, true, "Could not create a WebGL context."));
return nullptr;
}
Extensions3DUtil extensionsUtil(context.get());
if (extensionsUtil.supportsExtension("GL_EXT_debug_marker"))
context->pushGroupMarkerEXT("WebGLRenderingContext");
OwnPtr<WebGLRenderingContext> renderingContext = adoptPtr(new WebGLRenderingContext(canvas, context.release(), attrs));
renderingContext->registerContextExtensions();
renderingContext->suspendIfNeeded();
if (renderingContext->m_drawingBuffer->isZeroSized()) {
canvas->dispatchEvent(WebGLContextEvent::create(EventTypeNames::webglcontextcreationerror, false, true, "Could not create a WebGL context."));
return nullptr;
}
return renderingContext.release();
}
WebGLRenderingContext::WebGLRenderingContext(HTMLCanvasElement* passedCanvas, PassOwnPtr<blink::WebGraphicsContext3D> context, WebGLContextAttributes* requestedAttributes)
: WebGLRenderingContextBase(passedCanvas, context, requestedAttributes)
{
ScriptWrappable::init(this);
}
WebGLRenderingContext::~WebGLRenderingContext()
{
}
void WebGLRenderingContext::registerContextExtensions()
{
static const char* const webkitPrefix[] = { "WEBKIT_", 0, };
static const char* const bothPrefixes[] = { "", "WEBKIT_", 0, };
registerExtension<ANGLEInstancedArrays>(m_angleInstancedArrays);
registerExtension<EXTTextureFilterAnisotropic>(m_extTextureFilterAnisotropic, ApprovedExtension, bothPrefixes);
registerExtension<OESElementIndexUint>(m_oesElementIndexUint);
registerExtension<OESStandardDerivatives>(m_oesStandardDerivatives);
registerExtension<OESTextureFloat>(m_oesTextureFloat);
registerExtension<OESTextureFloatLinear>(m_oesTextureFloatLinear);
registerExtension<OESTextureHalfFloat>(m_oesTextureHalfFloat);
registerExtension<OESTextureHalfFloatLinear>(m_oesTextureHalfFloatLinear);
registerExtension<OESVertexArrayObject>(m_oesVertexArrayObject);
registerExtension<WebGLCompressedTextureATC>(m_webglCompressedTextureATC, EnabledDraftExtension, webkitPrefix);
registerExtension<WebGLCompressedTexturePVRTC>(m_webglCompressedTexturePVRTC, EnabledDraftExtension, webkitPrefix);
registerExtension<WebGLCompressedTextureS3TC>(m_webglCompressedTextureS3TC, ApprovedExtension, bothPrefixes);
registerExtension<WebGLDepthTexture>(m_webglDepthTexture, ApprovedExtension, bothPrefixes);
registerExtension<WebGLDrawBuffers>(m_webglDrawBuffers);
registerExtension<WebGLLoseContext>(m_webglLoseContext, ApprovedExtension, bothPrefixes);
registerExtension<EXTFragDepth>(m_extFragDepth, DraftExtension);
registerExtension<WebGLDebugRendererInfo>(m_webglDebugRendererInfo, WebGLDebugRendererInfoExtension);
registerExtension<WebGLDebugShaders>(m_webglDebugShaders, PrivilegedExtension);
}
}