OLD | NEW |
| (Empty) |
1 /* | |
2 * Copyright (C) 2009 Apple Inc. All rights reserved. | |
3 * | |
4 * Redistribution and use in source and binary forms, with or without | |
5 * modification, are permitted provided that the following conditions | |
6 * are met: | |
7 * 1. Redistributions of source code must retain the above copyright | |
8 * notice, this list of conditions and the following disclaimer. | |
9 * 2. Redistributions in binary form must reproduce the above copyright | |
10 * notice, this list of conditions and the following disclaimer in the | |
11 * documentation and/or other materials provided with the distribution. | |
12 * | |
13 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY | |
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | |
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR | |
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | |
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | |
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | |
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY | |
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
24 */ | |
25 | |
26 #include "sky/engine/config.h" | |
27 #include "sky/engine/core/html/canvas/WebGLRenderingContext.h" | |
28 | |
29 #include "sky/engine/core/frame/LocalFrame.h" | |
30 #include "sky/engine/core/frame/Settings.h" | |
31 #include "sky/engine/core/html/canvas/ANGLEInstancedArrays.h" | |
32 #include "sky/engine/core/html/canvas/EXTBlendMinMax.h" | |
33 #include "sky/engine/core/html/canvas/EXTFragDepth.h" | |
34 #include "sky/engine/core/html/canvas/EXTShaderTextureLOD.h" | |
35 #include "sky/engine/core/html/canvas/EXTTextureFilterAnisotropic.h" | |
36 #include "sky/engine/core/html/canvas/OESElementIndexUint.h" | |
37 #include "sky/engine/core/html/canvas/OESStandardDerivatives.h" | |
38 #include "sky/engine/core/html/canvas/OESTextureFloat.h" | |
39 #include "sky/engine/core/html/canvas/OESTextureFloatLinear.h" | |
40 #include "sky/engine/core/html/canvas/OESTextureHalfFloat.h" | |
41 #include "sky/engine/core/html/canvas/OESTextureHalfFloatLinear.h" | |
42 #include "sky/engine/core/html/canvas/OESVertexArrayObject.h" | |
43 #include "sky/engine/core/html/canvas/WebGLCompressedTextureATC.h" | |
44 #include "sky/engine/core/html/canvas/WebGLCompressedTextureETC1.h" | |
45 #include "sky/engine/core/html/canvas/WebGLCompressedTexturePVRTC.h" | |
46 #include "sky/engine/core/html/canvas/WebGLCompressedTextureS3TC.h" | |
47 #include "sky/engine/core/html/canvas/WebGLContextAttributes.h" | |
48 #include "sky/engine/core/html/canvas/WebGLContextEvent.h" | |
49 #include "sky/engine/core/html/canvas/WebGLDebugRendererInfo.h" | |
50 #include "sky/engine/core/html/canvas/WebGLDebugShaders.h" | |
51 #include "sky/engine/core/html/canvas/WebGLDepthTexture.h" | |
52 #include "sky/engine/core/html/canvas/WebGLDrawBuffers.h" | |
53 #include "sky/engine/core/html/canvas/WebGLLoseContext.h" | |
54 #include "sky/engine/core/loader/FrameLoaderClient.h" | |
55 #include "sky/engine/core/rendering/RenderBox.h" | |
56 #include "sky/engine/platform/CheckedInt.h" | |
57 #include "sky/engine/platform/NotImplemented.h" | |
58 #include "sky/engine/platform/graphics/gpu/DrawingBuffer.h" | |
59 #include "sky/engine/public/platform/Platform.h" | |
60 | |
61 namespace blink { | |
62 | |
63 PassOwnPtr<WebGLRenderingContext> WebGLRenderingContext::create(HTMLCanvasElemen
t* canvas, WebGLContextAttributes* attrs) | |
64 { | |
65 Document& document = canvas->document(); | |
66 LocalFrame* frame = document.frame(); | |
67 if (!frame) { | |
68 canvas->dispatchEvent(WebGLContextEvent::create(EventTypeNames::webglcon
textcreationerror, false, true, "Web page was not allowed to create a WebGL cont
ext.")); | |
69 return nullptr; | |
70 } | |
71 Settings* settings = frame->settings(); | |
72 | |
73 // TODO(esprehn): This should never be null. | |
74 RefPtr<WebGLContextAttributes> defaultAttrs = nullptr; | |
75 if (!attrs) { | |
76 defaultAttrs = WebGLContextAttributes::create(); | |
77 attrs = defaultAttrs.get(); | |
78 } | |
79 blink::WebGraphicsContext3D::Attributes attributes = attrs->attributes(docum
ent.topDocument().url().string(), settings, 1); | |
80 OwnPtr<blink::WebGraphicsContext3D> context = adoptPtr(blink::Platform::curr
ent()->createOffscreenGraphicsContext3D(attributes, 0)); | |
81 if (!context) { | |
82 canvas->dispatchEvent(WebGLContextEvent::create(EventTypeNames::webglcon
textcreationerror, false, true, "Could not create a WebGL context.")); | |
83 return nullptr; | |
84 } | |
85 | |
86 OwnPtr<Extensions3DUtil> extensionsUtil = Extensions3DUtil::create(context.g
et()); | |
87 if (!extensionsUtil) | |
88 return nullptr; | |
89 if (extensionsUtil->supportsExtension("GL_EXT_debug_marker")) | |
90 context->pushGroupMarkerEXT("WebGLRenderingContext"); | |
91 | |
92 OwnPtr<WebGLRenderingContext> renderingContext = adoptPtr(new WebGLRendering
Context(canvas, context.release(), attrs)); | |
93 renderingContext->registerContextExtensions(); | |
94 renderingContext->suspendIfNeeded(); | |
95 | |
96 if (!renderingContext->drawingBuffer()) { | |
97 canvas->dispatchEvent(WebGLContextEvent::create(EventTypeNames::webglcon
textcreationerror, false, true, "Could not create a WebGL context.")); | |
98 return nullptr; | |
99 } | |
100 | |
101 return renderingContext.release(); | |
102 } | |
103 | |
104 WebGLRenderingContext::WebGLRenderingContext(HTMLCanvasElement* passedCanvas, Pa
ssOwnPtr<blink::WebGraphicsContext3D> context, WebGLContextAttributes* requested
Attributes) | |
105 : WebGLRenderingContextBase(passedCanvas, context, requestedAttributes) | |
106 { | |
107 } | |
108 | |
109 WebGLRenderingContext::~WebGLRenderingContext() | |
110 { | |
111 } | |
112 | |
113 void WebGLRenderingContext::registerContextExtensions() | |
114 { | |
115 // Register extensions. | |
116 static const char* const bothPrefixes[] = { "", "WEBKIT_", 0, }; | |
117 | |
118 registerExtension<ANGLEInstancedArrays>(m_angleInstancedArrays); | |
119 registerExtension<EXTBlendMinMax>(m_extBlendMinMax); | |
120 registerExtension<EXTFragDepth>(m_extFragDepth); | |
121 registerExtension<EXTShaderTextureLOD>(m_extShaderTextureLOD); | |
122 registerExtension<EXTTextureFilterAnisotropic>(m_extTextureFilterAnisotropic
, ApprovedExtension, bothPrefixes); | |
123 registerExtension<OESElementIndexUint>(m_oesElementIndexUint); | |
124 registerExtension<OESStandardDerivatives>(m_oesStandardDerivatives); | |
125 registerExtension<OESTextureFloat>(m_oesTextureFloat); | |
126 registerExtension<OESTextureFloatLinear>(m_oesTextureFloatLinear); | |
127 registerExtension<OESTextureHalfFloat>(m_oesTextureHalfFloat); | |
128 registerExtension<OESTextureHalfFloatLinear>(m_oesTextureHalfFloatLinear); | |
129 registerExtension<OESVertexArrayObject>(m_oesVertexArrayObject); | |
130 registerExtension<WebGLCompressedTextureATC>(m_webglCompressedTextureATC, Ap
provedExtension, bothPrefixes); | |
131 registerExtension<WebGLCompressedTextureETC1>(m_webglCompressedTextureETC1); | |
132 registerExtension<WebGLCompressedTexturePVRTC>(m_webglCompressedTexturePVRTC
, ApprovedExtension, bothPrefixes); | |
133 registerExtension<WebGLCompressedTextureS3TC>(m_webglCompressedTextureS3TC,
ApprovedExtension, bothPrefixes); | |
134 registerExtension<WebGLDebugRendererInfo>(m_webglDebugRendererInfo); | |
135 registerExtension<WebGLDebugShaders>(m_webglDebugShaders); | |
136 registerExtension<WebGLDepthTexture>(m_webglDepthTexture, ApprovedExtension,
bothPrefixes); | |
137 registerExtension<WebGLDrawBuffers>(m_webglDrawBuffers); | |
138 registerExtension<WebGLLoseContext>(m_webglLoseContext, ApprovedExtension, b
othPrefixes); | |
139 } | |
140 | |
141 } // namespace blink | |
OLD | NEW |