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/containers/hash_tables.h" | 10 #include "base/containers/hash_tables.h" |
11 #include "base/macros.h" | 11 #include "base/macros.h" |
12 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
13 #include "base/observer_list.h" | 13 #include "base/observer_list.h" |
14 #include "gpu/gpu_export.h" | 14 #include "gpu/gpu_export.h" |
15 #include "third_party/angle/include/GLSLANG/ShaderLang.h" | 15 #include "third_party/angle/include/GLSLANG/ShaderLang.h" |
16 | 16 |
17 namespace gl { | 17 namespace gl { |
18 struct GLVersionInfo; | 18 struct GLVersionInfo; |
19 } | 19 } |
20 | 20 |
21 namespace gpu { | 21 namespace gpu { |
22 namespace gles2 { | 22 namespace gles2 { |
23 | 23 |
24 // Mapping between variable name and info. | 24 // Mapping between variable name and info. |
25 typedef base::hash_map<std::string, sh::Attribute> AttributeMap; | 25 typedef base::hash_map<std::string, sh::Attribute> AttributeMap; |
26 typedef std::vector<sh::OutputVariable> OutputVariableList; | 26 typedef std::vector<sh::OutputVariable> OutputVariableList; |
27 typedef base::hash_map<std::string, sh::Uniform> UniformMap; | 27 typedef base::hash_map<std::string, sh::Uniform> UniformMap; |
28 typedef base::hash_map<std::string, sh::Varying> VaryingMap; | 28 typedef base::hash_map<std::string, sh::Varying> VaryingMap; |
29 typedef base::hash_map<std::string, sh::InterfaceBlock> InterfaceBlockMap; | 29 typedef base::hash_map<std::string, sh::InterfaceBlock> InterfaceBlockMap; |
30 // Mapping between hashed name and original name. | |
31 typedef base::hash_map<std::string, std::string> NameMap; | |
32 | 30 |
33 // Translates a GLSL ES 2.0 shader to desktop GLSL shader, or just | 31 // Translates a GLSL ES 2.0 shader to desktop GLSL shader, or just |
34 // validates GLSL ES 2.0 shaders on a true GLSL ES implementation. | 32 // validates GLSL ES 2.0 shaders on a true GLSL ES implementation. |
35 class ShaderTranslatorInterface | 33 class ShaderTranslatorInterface |
36 : public base::RefCounted<ShaderTranslatorInterface> { | 34 : public base::RefCounted<ShaderTranslatorInterface> { |
37 public: | 35 public: |
38 ShaderTranslatorInterface() {} | 36 ShaderTranslatorInterface() {} |
39 | 37 |
40 // Initializes the translator. | 38 // Initializes the translator. |
41 // Must be called once before using the translator object. | 39 // Must be called once before using the translator object. |
(...skipping 10 matching lines...) Expand all Loading... |
52 // Upon success, fill |translated_shader|, |attrib_map|, |uniform_map|, | 50 // Upon success, fill |translated_shader|, |attrib_map|, |uniform_map|, |
53 // |varying_map|, and |name_map| if they are non-null. | 51 // |varying_map|, and |name_map| if they are non-null. |
54 virtual bool Translate(const std::string& shader_source, | 52 virtual bool Translate(const std::string& shader_source, |
55 std::string* info_log, | 53 std::string* info_log, |
56 std::string* translated_shader, | 54 std::string* translated_shader, |
57 int* shader_version, | 55 int* shader_version, |
58 AttributeMap* attrib_map, | 56 AttributeMap* attrib_map, |
59 UniformMap* uniform_map, | 57 UniformMap* uniform_map, |
60 VaryingMap* varying_map, | 58 VaryingMap* varying_map, |
61 InterfaceBlockMap* interface_block_map, | 59 InterfaceBlockMap* interface_block_map, |
62 OutputVariableList* output_variable_list, | 60 OutputVariableList* output_variable_list) const = 0; |
63 NameMap* name_map) const = 0; | |
64 | 61 |
65 // Return a string that is unique for a specfic set of options that would | 62 // Return a string that is unique for a specfic set of options that would |
66 // possibly affect compilation. | 63 // possibly affect compilation. |
67 virtual std::string GetStringForOptionsThatWouldAffectCompilation() const = 0; | 64 virtual std::string GetStringForOptionsThatWouldAffectCompilation() const = 0; |
68 | 65 |
69 protected: | 66 protected: |
70 virtual ~ShaderTranslatorInterface() {} | 67 virtual ~ShaderTranslatorInterface() {} |
71 | 68 |
72 private: | 69 private: |
73 friend class base::RefCounted<ShaderTranslatorInterface>; | 70 friend class base::RefCounted<ShaderTranslatorInterface>; |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
105 | 102 |
106 // Overridden from ShaderTranslatorInterface. | 103 // Overridden from ShaderTranslatorInterface. |
107 bool Translate(const std::string& shader_source, | 104 bool Translate(const std::string& shader_source, |
108 std::string* info_log, | 105 std::string* info_log, |
109 std::string* translated_source, | 106 std::string* translated_source, |
110 int* shader_version, | 107 int* shader_version, |
111 AttributeMap* attrib_map, | 108 AttributeMap* attrib_map, |
112 UniformMap* uniform_map, | 109 UniformMap* uniform_map, |
113 VaryingMap* varying_map, | 110 VaryingMap* varying_map, |
114 InterfaceBlockMap* interface_block_map, | 111 InterfaceBlockMap* interface_block_map, |
115 OutputVariableList* output_variable_list, | 112 OutputVariableList* output_variable_list) const override; |
116 NameMap* name_map) const override; | |
117 | 113 |
118 std::string GetStringForOptionsThatWouldAffectCompilation() const override; | 114 std::string GetStringForOptionsThatWouldAffectCompilation() const override; |
119 | 115 |
120 void AddDestructionObserver(DestructionObserver* observer); | 116 void AddDestructionObserver(DestructionObserver* observer); |
121 void RemoveDestructionObserver(DestructionObserver* observer); | 117 void RemoveDestructionObserver(DestructionObserver* observer); |
122 | 118 |
123 private: | 119 private: |
124 ~ShaderTranslator() override; | 120 ~ShaderTranslator() override; |
125 | 121 |
126 ShCompileOptions GetCompileOptions() const; | 122 ShCompileOptions GetCompileOptions() const; |
127 | 123 |
128 ShHandle compiler_; | 124 ShHandle compiler_; |
129 ShCompileOptions compile_options_; | 125 ShCompileOptions compile_options_; |
130 base::ObserverList<DestructionObserver> destruction_observers_; | 126 base::ObserverList<DestructionObserver> destruction_observers_; |
131 }; | 127 }; |
132 | 128 |
133 } // namespace gles2 | 129 } // namespace gles2 |
134 } // namespace gpu | 130 } // namespace gpu |
135 | 131 |
136 #endif // GPU_COMMAND_BUFFER_SERVICE_SHADER_TRANSLATOR_H_ | 132 #endif // GPU_COMMAND_BUFFER_SERVICE_SHADER_TRANSLATOR_H_ |
137 | 133 |
OLD | NEW |