| 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_MANAGER_H_ | 5 #ifndef GPU_COMMAND_BUFFER_SERVICE_SHADER_MANAGER_H_ |
| 6 #define GPU_COMMAND_BUFFER_SERVICE_SHADER_MANAGER_H_ | 6 #define GPU_COMMAND_BUFFER_SERVICE_SHADER_MANAGER_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
| 10 #include "base/containers/hash_tables.h" | 10 #include "base/containers/hash_tables.h" |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 // to emluate GLES2 the shaders will have to be re-written before passed to | 22 // to emluate GLES2 the shaders will have to be re-written before passed to |
| 23 // the underlying OpenGL. But, when the user calls glGetShaderSource they | 23 // the underlying OpenGL. But, when the user calls glGetShaderSource they |
| 24 // should get the source they passed in, not the re-written source. | 24 // should get the source they passed in, not the re-written source. |
| 25 class GPU_EXPORT Shader : public base::RefCounted<Shader> { | 25 class GPU_EXPORT Shader : public base::RefCounted<Shader> { |
| 26 public: | 26 public: |
| 27 enum TranslatedShaderSourceType { | 27 enum TranslatedShaderSourceType { |
| 28 kANGLE, | 28 kANGLE, |
| 29 kGL, // GL or GLES | 29 kGL, // GL or GLES |
| 30 }; | 30 }; |
| 31 | 31 |
| 32 typedef ShaderTranslator::VariableInfo VariableInfo; | |
| 33 | |
| 34 void DoCompile(ShaderTranslatorInterface* translator, | 32 void DoCompile(ShaderTranslatorInterface* translator, |
| 35 TranslatedShaderSourceType type); | 33 TranslatedShaderSourceType type); |
| 36 | 34 |
| 37 GLuint service_id() const { | 35 GLuint service_id() const { |
| 38 return service_id_; | 36 return service_id_; |
| 39 } | 37 } |
| 40 | 38 |
| 41 GLenum shader_type() const { | 39 GLenum shader_type() const { |
| 42 return shader_type_; | 40 return shader_type_; |
| 43 } | 41 } |
| 44 | 42 |
| 45 const std::string& source() const { | 43 const std::string& source() const { |
| 46 return source_; | 44 return source_; |
| 47 } | 45 } |
| 48 | 46 |
| 49 void set_source(const std::string& source) { | 47 void set_source(const std::string& source) { |
| 50 source_ = source; | 48 source_ = source; |
| 51 } | 49 } |
| 52 | 50 |
| 53 const std::string& translated_source() const { | 51 const std::string& translated_source() const { |
| 54 return translated_source_; | 52 return translated_source_; |
| 55 } | 53 } |
| 56 | 54 |
| 57 const std::string& signature_source() const { | 55 const std::string& signature_source() const { |
| 58 return signature_source_; | 56 return signature_source_; |
| 59 } | 57 } |
| 60 | 58 |
| 61 const VariableInfo* GetAttribInfo(const std::string& name) const; | 59 const sh::Attribute* GetAttribInfo(const std::string& name) const; |
| 62 const VariableInfo* GetUniformInfo(const std::string& name) const; | 60 const sh::Uniform* GetUniformInfo(const std::string& name) const; |
| 63 const VariableInfo* GetVaryingInfo(const std::string& name) const; | 61 const sh::Varying* GetVaryingInfo(const std::string& name) const; |
| 64 | 62 |
| 65 // If the original_name is not found, return NULL. | 63 // If the original_name is not found, return NULL. |
| 66 const std::string* GetAttribMappedName( | 64 const std::string* GetAttribMappedName( |
| 67 const std::string& original_name) const; | 65 const std::string& original_name) const; |
| 68 | 66 |
| 69 // If the hashed_name is not found, return NULL. | 67 // If the hashed_name is not found, return NULL. |
| 70 const std::string* GetOriginalNameFromHashedName( | 68 const std::string* GetOriginalNameFromHashedName( |
| 71 const std::string& hashed_name) const; | 69 const std::string& hashed_name) const; |
| 72 | 70 |
| 73 const std::string& log_info() const { | 71 const std::string& log_info() const { |
| 74 return log_info_; | 72 return log_info_; |
| 75 } | 73 } |
| 76 | 74 |
| 77 bool valid() const { | 75 bool valid() const { |
| 78 return valid_; | 76 return valid_; |
| 79 } | 77 } |
| 80 | 78 |
| 81 bool IsDeleted() const { | 79 bool IsDeleted() const { |
| 82 return service_id_ == 0; | 80 return service_id_ == 0; |
| 83 } | 81 } |
| 84 | 82 |
| 85 bool InUse() const { | 83 bool InUse() const { |
| 86 DCHECK_GE(use_count_, 0); | 84 DCHECK_GE(use_count_, 0); |
| 87 return use_count_ != 0; | 85 return use_count_ != 0; |
| 88 } | 86 } |
| 89 | 87 |
| 90 // Used by program cache. | 88 // Used by program cache. |
| 91 const ShaderTranslator::VariableMap& attrib_map() const { | 89 const AttributeMap& attrib_map() const { |
| 92 return attrib_map_; | 90 return attrib_map_; |
| 93 } | 91 } |
| 94 | 92 |
| 95 // Used by program cache. | 93 // Used by program cache. |
| 96 const ShaderTranslator::VariableMap& uniform_map() const { | 94 const UniformMap& uniform_map() const { |
| 97 return uniform_map_; | 95 return uniform_map_; |
| 98 } | 96 } |
| 99 | 97 |
| 100 // Used by program cache. | 98 // Used by program cache. |
| 101 const ShaderTranslator::VariableMap& varying_map() const { | 99 const VaryingMap& varying_map() const { |
| 102 return varying_map_; | 100 return varying_map_; |
| 103 } | 101 } |
| 104 | 102 |
| 105 // Used by program cache. | 103 // Used by program cache. |
| 106 void set_attrib_map(const ShaderTranslator::VariableMap& attrib_map) { | 104 void set_attrib_map(const AttributeMap& attrib_map) { |
| 107 // copied because cache might be cleared | 105 // copied because cache might be cleared |
| 108 attrib_map_ = ShaderTranslator::VariableMap(attrib_map); | 106 attrib_map_ = AttributeMap(attrib_map); |
| 109 } | 107 } |
| 110 | 108 |
| 111 // Used by program cache. | 109 // Used by program cache. |
| 112 void set_uniform_map(const ShaderTranslator::VariableMap& uniform_map) { | 110 void set_uniform_map(const UniformMap& uniform_map) { |
| 113 // copied because cache might be cleared | 111 // copied because cache might be cleared |
| 114 uniform_map_ = ShaderTranslator::VariableMap(uniform_map); | 112 uniform_map_ = UniformMap(uniform_map); |
| 115 } | 113 } |
| 116 | 114 |
| 117 // Used by program cache. | 115 // Used by program cache. |
| 118 void set_varying_map(const ShaderTranslator::VariableMap& varying_map) { | 116 void set_varying_map(const VaryingMap& varying_map) { |
| 119 // copied because cache might be cleared | 117 // copied because cache might be cleared |
| 120 varying_map_ = ShaderTranslator::VariableMap(varying_map); | 118 varying_map_ = VaryingMap(varying_map); |
| 121 } | 119 } |
| 122 | 120 |
| 123 private: | 121 private: |
| 124 typedef ShaderTranslator::VariableMap VariableMap; | |
| 125 typedef ShaderTranslator::NameMap NameMap; | |
| 126 | |
| 127 friend class base::RefCounted<Shader>; | 122 friend class base::RefCounted<Shader>; |
| 128 friend class ShaderManager; | 123 friend class ShaderManager; |
| 129 | 124 |
| 130 Shader(GLuint service_id, GLenum shader_type); | 125 Shader(GLuint service_id, GLenum shader_type); |
| 131 ~Shader(); | 126 ~Shader(); |
| 132 | 127 |
| 133 void IncUseCount(); | 128 void IncUseCount(); |
| 134 void DecUseCount(); | 129 void DecUseCount(); |
| 135 void MarkAsDeleted(); | 130 void MarkAsDeleted(); |
| 136 | 131 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 150 // The source the last compile used. | 145 // The source the last compile used. |
| 151 std::string signature_source_; | 146 std::string signature_source_; |
| 152 | 147 |
| 153 // The translated shader source. | 148 // The translated shader source. |
| 154 std::string translated_source_; | 149 std::string translated_source_; |
| 155 | 150 |
| 156 // The shader translation log. | 151 // The shader translation log. |
| 157 std::string log_info_; | 152 std::string log_info_; |
| 158 | 153 |
| 159 // The type info when the shader was last compiled. | 154 // The type info when the shader was last compiled. |
| 160 VariableMap attrib_map_; | 155 AttributeMap attrib_map_; |
| 161 VariableMap uniform_map_; | 156 UniformMap uniform_map_; |
| 162 VariableMap varying_map_; | 157 VaryingMap varying_map_; |
| 163 | 158 |
| 164 // The name hashing info when the shader was last compiled. | 159 // The name hashing info when the shader was last compiled. |
| 165 NameMap name_map_; | 160 NameMap name_map_; |
| 166 }; | 161 }; |
| 167 | 162 |
| 168 // Tracks the Shaders. | 163 // Tracks the Shaders. |
| 169 // | 164 // |
| 170 // NOTE: To support shared resources an instance of this class will | 165 // NOTE: To support shared resources an instance of this class will |
| 171 // need to be shared by multiple GLES2Decoders. | 166 // need to be shared by multiple GLES2Decoders. |
| 172 class GPU_EXPORT ShaderManager { | 167 class GPU_EXPORT ShaderManager { |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 212 void RemoveShader(Shader* shader); | 207 void RemoveShader(Shader* shader); |
| 213 | 208 |
| 214 DISALLOW_COPY_AND_ASSIGN(ShaderManager); | 209 DISALLOW_COPY_AND_ASSIGN(ShaderManager); |
| 215 }; | 210 }; |
| 216 | 211 |
| 217 } // namespace gles2 | 212 } // namespace gles2 |
| 218 } // namespace gpu | 213 } // namespace gpu |
| 219 | 214 |
| 220 #endif // GPU_COMMAND_BUFFER_SERVICE_SHADER_MANAGER_H_ | 215 #endif // GPU_COMMAND_BUFFER_SERVICE_SHADER_MANAGER_H_ |
| 221 | 216 |
| OLD | NEW |