| 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 #ifndef GPU_COMMAND_BUFFER_SERVICE_SHADER_TRANSLATOR_H_ | 5 #ifndef GPU_COMMAND_BUFFER_SERVICE_SHADER_TRANSLATOR_H_ |
| 6 #define GPU_COMMAND_BUFFER_SERVICE_SHADER_TRANSLATOR_H_ | 6 #define GPU_COMMAND_BUFFER_SERVICE_SHADER_TRANSLATOR_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| 11 #include "base/containers/hash_tables.h" | 11 #include "base/containers/hash_tables.h" |
| 12 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
| 13 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
| 14 #include "base/observer_list.h" | 14 #include "base/observer_list.h" |
| 15 #include "gpu/gpu_export.h" | 15 #include "gpu/gpu_export.h" |
| 16 #include "third_party/angle/include/GLSLANG/ShaderLang.h" | 16 #include "third_party/angle/include/GLSLANG/ShaderLang.h" |
| 17 | 17 |
| 18 namespace gfx { |
| 19 struct GLVersionInfo; |
| 20 } |
| 21 |
| 18 namespace gpu { | 22 namespace gpu { |
| 19 namespace gles2 { | 23 namespace gles2 { |
| 20 | 24 |
| 21 // Mapping between variable name and info. | 25 // Mapping between variable name and info. |
| 22 typedef base::hash_map<std::string, sh::Attribute> AttributeMap; | 26 typedef base::hash_map<std::string, sh::Attribute> AttributeMap; |
| 23 typedef base::hash_map<std::string, sh::Uniform> UniformMap; | 27 typedef base::hash_map<std::string, sh::Uniform> UniformMap; |
| 24 typedef base::hash_map<std::string, sh::Varying> VaryingMap; | 28 typedef base::hash_map<std::string, sh::Varying> VaryingMap; |
| 25 // Mapping between hashed name and original name. | 29 // Mapping between hashed name and original name. |
| 26 typedef base::hash_map<std::string, std::string> NameMap; | 30 typedef base::hash_map<std::string, std::string> NameMap; |
| 27 | 31 |
| 28 // Translates a GLSL ES 2.0 shader to desktop GLSL shader, or just | 32 // Translates a GLSL ES 2.0 shader to desktop GLSL shader, or just |
| 29 // validates GLSL ES 2.0 shaders on a true GLSL ES implementation. | 33 // validates GLSL ES 2.0 shaders on a true GLSL ES implementation. |
| 30 class ShaderTranslatorInterface | 34 class ShaderTranslatorInterface |
| 31 : public base::RefCounted<ShaderTranslatorInterface> { | 35 : public base::RefCounted<ShaderTranslatorInterface> { |
| 32 public: | 36 public: |
| 33 ShaderTranslatorInterface() {} | 37 ShaderTranslatorInterface() {} |
| 34 enum GlslImplementationType { | |
| 35 kGlsl, | |
| 36 kGlslES | |
| 37 }; | |
| 38 | 38 |
| 39 // Initializes the translator. | 39 // Initializes the translator. |
| 40 // Must be called once before using the translator object. | 40 // Must be called once before using the translator object. |
| 41 virtual bool Init( | 41 virtual bool Init(sh::GLenum shader_type, |
| 42 sh::GLenum shader_type, | 42 ShShaderSpec shader_spec, |
| 43 ShShaderSpec shader_spec, | 43 const ShBuiltInResources* resources, |
| 44 const ShBuiltInResources* resources, | 44 ShShaderOutput shader_output_language, |
| 45 GlslImplementationType glsl_implementation_type, | 45 ShCompileOptions driver_bug_workarounds) = 0; |
| 46 ShCompileOptions driver_bug_workarounds) = 0; | |
| 47 | 46 |
| 48 // Translates the given shader source. | 47 // Translates the given shader source. |
| 49 // Returns true if translation is successful, false otherwise. | 48 // Returns true if translation is successful, false otherwise. |
| 50 // Always fill |info_log| if it's non-null. | 49 // Always fill |info_log| if it's non-null. |
| 51 // Upon success, fill |translated_shader|, |attrib_map|, |uniform_map|, | 50 // Upon success, fill |translated_shader|, |attrib_map|, |uniform_map|, |
| 52 // |varying_map|, and |name_map| if they are non-null. | 51 // |varying_map|, and |name_map| if they are non-null. |
| 53 virtual bool Translate(const std::string& shader_source, | 52 virtual bool Translate(const std::string& shader_source, |
| 54 std::string* info_log, | 53 std::string* info_log, |
| 55 std::string* translated_shader, | 54 std::string* translated_shader, |
| 56 int* shader_version, | 55 int* shader_version, |
| (...skipping 24 matching lines...) Expand all Loading... |
| 81 virtual ~DestructionObserver(); | 80 virtual ~DestructionObserver(); |
| 82 | 81 |
| 83 virtual void OnDestruct(ShaderTranslator* translator) = 0; | 82 virtual void OnDestruct(ShaderTranslator* translator) = 0; |
| 84 | 83 |
| 85 private: | 84 private: |
| 86 DISALLOW_COPY_AND_ASSIGN(DestructionObserver); | 85 DISALLOW_COPY_AND_ASSIGN(DestructionObserver); |
| 87 }; | 86 }; |
| 88 | 87 |
| 89 ShaderTranslator(); | 88 ShaderTranslator(); |
| 90 | 89 |
| 90 // Return shader output lanaguage type based on the context version. |
| 91 static ShShaderOutput GetShaderOutputLanguageForContext( |
| 92 const gfx::GLVersionInfo& context_version); |
| 93 |
| 91 // Overridden from ShaderTranslatorInterface. | 94 // Overridden from ShaderTranslatorInterface. |
| 92 bool Init(sh::GLenum shader_type, | 95 bool Init(sh::GLenum shader_type, |
| 93 ShShaderSpec shader_spec, | 96 ShShaderSpec shader_spec, |
| 94 const ShBuiltInResources* resources, | 97 const ShBuiltInResources* resources, |
| 95 GlslImplementationType glsl_implementation_type, | 98 ShShaderOutput shader_output_language, |
| 96 ShCompileOptions driver_bug_workarounds) override; | 99 ShCompileOptions driver_bug_workarounds) override; |
| 97 | 100 |
| 98 // Overridden from ShaderTranslatorInterface. | 101 // Overridden from ShaderTranslatorInterface. |
| 99 bool Translate(const std::string& shader_source, | 102 bool Translate(const std::string& shader_source, |
| 100 std::string* info_log, | 103 std::string* info_log, |
| 101 std::string* translated_source, | 104 std::string* translated_source, |
| 102 int* shader_version, | 105 int* shader_version, |
| 103 AttributeMap* attrib_map, | 106 AttributeMap* attrib_map, |
| 104 UniformMap* uniform_map, | 107 UniformMap* uniform_map, |
| 105 VaryingMap* varying_map, | 108 VaryingMap* varying_map, |
| 106 NameMap* name_map) const override; | 109 NameMap* name_map) const override; |
| 107 | 110 |
| 108 std::string GetStringForOptionsThatWouldAffectCompilation() const override; | 111 std::string GetStringForOptionsThatWouldAffectCompilation() const override; |
| 109 | 112 |
| 110 void AddDestructionObserver(DestructionObserver* observer); | 113 void AddDestructionObserver(DestructionObserver* observer); |
| 111 void RemoveDestructionObserver(DestructionObserver* observer); | 114 void RemoveDestructionObserver(DestructionObserver* observer); |
| 112 | 115 |
| 113 private: | 116 private: |
| 114 ~ShaderTranslator() override; | 117 ~ShaderTranslator() override; |
| 115 | 118 |
| 116 int GetCompileOptions() const; | 119 int GetCompileOptions() const; |
| 117 | 120 |
| 118 ShHandle compiler_; | 121 ShHandle compiler_; |
| 119 bool implementation_is_glsl_es_; | |
| 120 ShCompileOptions driver_bug_workarounds_; | 122 ShCompileOptions driver_bug_workarounds_; |
| 121 base::ObserverList<DestructionObserver> destruction_observers_; | 123 base::ObserverList<DestructionObserver> destruction_observers_; |
| 122 }; | 124 }; |
| 123 | 125 |
| 124 } // namespace gles2 | 126 } // namespace gles2 |
| 125 } // namespace gpu | 127 } // namespace gpu |
| 126 | 128 |
| 127 #endif // GPU_COMMAND_BUFFER_SERVICE_SHADER_TRANSLATOR_H_ | 129 #endif // GPU_COMMAND_BUFFER_SERVICE_SHADER_TRANSLATOR_H_ |
| 128 | 130 |
| OLD | NEW |