| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "gpu/command_buffer/service/shader_translator.h" | 5 #include "gpu/command_buffer/service/shader_translator.h" |
| 6 | 6 |
| 7 #include <string.h> | 7 #include <string.h> |
| 8 #include <GLES2/gl2.h> | 8 #include <GLES2/gl2.h> |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 | 10 |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 64 void GetVaryings(ShHandle compiler, VaryingMap* var_map) { | 64 void GetVaryings(ShHandle compiler, VaryingMap* var_map) { |
| 65 if (!var_map) | 65 if (!var_map) |
| 66 return; | 66 return; |
| 67 var_map->clear(); | 67 var_map->clear(); |
| 68 const std::vector<sh::Varying>* varyings = ShGetVaryings(compiler); | 68 const std::vector<sh::Varying>* varyings = ShGetVaryings(compiler); |
| 69 if (varyings) { | 69 if (varyings) { |
| 70 for (size_t ii = 0; ii < varyings->size(); ++ii) | 70 for (size_t ii = 0; ii < varyings->size(); ++ii) |
| 71 (*var_map)[(*varyings)[ii].mappedName] = (*varyings)[ii]; | 71 (*var_map)[(*varyings)[ii].mappedName] = (*varyings)[ii]; |
| 72 } | 72 } |
| 73 } | 73 } |
| 74 void GetOutputVariables(ShHandle compiler, OutputVariableList* var_list) { |
| 75 if (!var_list) |
| 76 return; |
| 77 *var_list = *ShGetOutputVariables(compiler); |
| 78 } |
| 74 | 79 |
| 75 void GetNameHashingInfo(ShHandle compiler, NameMap* name_map) { | 80 void GetNameHashingInfo(ShHandle compiler, NameMap* name_map) { |
| 76 if (!name_map) | 81 if (!name_map) |
| 77 return; | 82 return; |
| 78 name_map->clear(); | 83 name_map->clear(); |
| 79 | 84 |
| 80 typedef std::map<std::string, std::string> NameMapANGLE; | 85 typedef std::map<std::string, std::string> NameMapANGLE; |
| 81 const NameMapANGLE* angle_map = ShGetNameHashingMap(compiler); | 86 const NameMapANGLE* angle_map = ShGetNameHashingMap(compiler); |
| 82 DCHECK(angle_map); | 87 DCHECK(angle_map); |
| 83 | 88 |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 185 return compile_options; | 190 return compile_options; |
| 186 } | 191 } |
| 187 | 192 |
| 188 bool ShaderTranslator::Translate(const std::string& shader_source, | 193 bool ShaderTranslator::Translate(const std::string& shader_source, |
| 189 std::string* info_log, | 194 std::string* info_log, |
| 190 std::string* translated_source, | 195 std::string* translated_source, |
| 191 int* shader_version, | 196 int* shader_version, |
| 192 AttributeMap* attrib_map, | 197 AttributeMap* attrib_map, |
| 193 UniformMap* uniform_map, | 198 UniformMap* uniform_map, |
| 194 VaryingMap* varying_map, | 199 VaryingMap* varying_map, |
| 200 OutputVariableList* output_variable_list, |
| 195 NameMap* name_map) const { | 201 NameMap* name_map) const { |
| 196 // Make sure this instance is initialized. | 202 // Make sure this instance is initialized. |
| 197 DCHECK(compiler_ != NULL); | 203 DCHECK(compiler_ != NULL); |
| 198 | 204 |
| 199 bool success = false; | 205 bool success = false; |
| 200 { | 206 { |
| 201 TRACE_EVENT0("gpu", "ShCompile"); | 207 TRACE_EVENT0("gpu", "ShCompile"); |
| 202 const char* const shader_strings[] = { shader_source.c_str() }; | 208 const char* const shader_strings[] = { shader_source.c_str() }; |
| 203 success = ShCompile( | 209 success = ShCompile( |
| 204 compiler_, shader_strings, 1, GetCompileOptions()); | 210 compiler_, shader_strings, 1, GetCompileOptions()); |
| 205 } | 211 } |
| 206 if (success) { | 212 if (success) { |
| 207 // Get translated shader. | 213 // Get translated shader. |
| 208 if (translated_source) { | 214 if (translated_source) { |
| 209 *translated_source = ShGetObjectCode(compiler_); | 215 *translated_source = ShGetObjectCode(compiler_); |
| 210 } | 216 } |
| 211 // Get shader version. | 217 // Get shader version. |
| 212 *shader_version = ShGetShaderVersion(compiler_); | 218 *shader_version = ShGetShaderVersion(compiler_); |
| 213 // Get info for attribs, uniforms, and varyings. | 219 // Get info for attribs, uniforms, varyings and output variables. |
| 214 GetAttributes(compiler_, attrib_map); | 220 GetAttributes(compiler_, attrib_map); |
| 215 GetUniforms(compiler_, uniform_map); | 221 GetUniforms(compiler_, uniform_map); |
| 216 GetVaryings(compiler_, varying_map); | 222 GetVaryings(compiler_, varying_map); |
| 223 GetOutputVariables(compiler_, output_variable_list); |
| 217 // Get info for name hashing. | 224 // Get info for name hashing. |
| 218 GetNameHashingInfo(compiler_, name_map); | 225 GetNameHashingInfo(compiler_, name_map); |
| 219 } | 226 } |
| 220 | 227 |
| 221 // Get info log. | 228 // Get info log. |
| 222 if (info_log) { | 229 if (info_log) { |
| 223 *info_log = ShGetInfoLog(compiler_); | 230 *info_log = ShGetInfoLog(compiler_); |
| 224 } | 231 } |
| 225 | 232 |
| 226 // We don't need results in the compiler anymore. | 233 // We don't need results in the compiler anymore. |
| (...skipping 25 matching lines...) Expand all Loading... |
| 252 destruction_observers_, | 259 destruction_observers_, |
| 253 OnDestruct(this)); | 260 OnDestruct(this)); |
| 254 | 261 |
| 255 if (compiler_ != NULL) | 262 if (compiler_ != NULL) |
| 256 ShDestruct(compiler_); | 263 ShDestruct(compiler_); |
| 257 } | 264 } |
| 258 | 265 |
| 259 } // namespace gles2 | 266 } // namespace gles2 |
| 260 } // namespace gpu | 267 } // namespace gpu |
| 261 | 268 |
| OLD | NEW |