2 * Copyright (C) 2010 Apple Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
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.
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.
30 #include "ANGLEWebKitBridge.h"
31 #include <wtf/OwnArrayPtr.h>
36 ANGLEWebKitBridge::ANGLEWebKitBridge() :
37 builtCompilers(false),
38 m_fragmentCompiler(0),
44 ANGLEWebKitBridge::~ANGLEWebKitBridge()
49 void ANGLEWebKitBridge::cleanupCompilers()
51 if (m_fragmentCompiler)
52 ShDestruct(m_fragmentCompiler);
53 m_fragmentCompiler = 0;
55 ShDestruct(m_vertexCompiler);
58 builtCompilers = false;
61 void ANGLEWebKitBridge::setResources(ShBuiltInResources resources)
63 // Resources are (possibly) changing - cleanup compilers if we had them already
66 m_resources = resources;
69 bool ANGLEWebKitBridge::validateShaderSource(const char* shaderSource, ANGLEShaderType shaderType, String& translatedShaderSource, String& shaderValidationLog)
71 if (!builtCompilers) {
72 m_fragmentCompiler = ShConstructCompiler(SH_FRAGMENT_SHADER, SH_WEBGL_SPEC, SH_GLSL_OUTPUT, &m_resources);
73 m_vertexCompiler = ShConstructCompiler(SH_VERTEX_SHADER, SH_WEBGL_SPEC, SH_GLSL_OUTPUT, &m_resources);
74 if (!m_fragmentCompiler || !m_vertexCompiler) {
79 builtCompilers = true;
84 if (shaderType == SHADER_TYPE_VERTEX)
85 compiler = m_vertexCompiler;
87 compiler = m_fragmentCompiler;
89 const char* const shaderSourceStrings[] = { shaderSource };
91 bool validateSuccess = ShCompile(compiler, shaderSourceStrings, 1, SH_OBJECT_CODE);
92 if (!validateSuccess) {
94 ShGetInfo(compiler, SH_INFO_LOG_LENGTH, &logSize);
96 OwnArrayPtr<char> logBuffer = adoptArrayPtr(new char[logSize]);
98 ShGetInfoLog(compiler, logBuffer.get());
99 shaderValidationLog = logBuffer.get();
105 int translationLength = 0;
106 ShGetInfo(compiler, SH_OBJECT_CODE_LENGTH, &translationLength);
107 if (translationLength > 1) {
108 OwnArrayPtr<char> translationBuffer = adoptArrayPtr(new char[translationLength]);
109 if (!translationBuffer)
111 ShGetObjectCode(compiler, translationBuffer.get());
112 translatedShaderSource = translationBuffer.get();
120 #endif // ENABLE(WEBGL)