| 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 enum ShaderState { |
| 33 kShaderStateWaiting, |
| 34 kShaderStateCompileRequested, |
| 35 kShaderStateCompiled, // Signifies compile happened, not valid compile. |
| 36 }; |
| 37 |
| 38 void RequestCompile(); |
| 39 |
| 32 void DoCompile(ShaderTranslatorInterface* translator, | 40 void DoCompile(ShaderTranslatorInterface* translator, |
| 33 TranslatedShaderSourceType type); | 41 TranslatedShaderSourceType type); |
| 34 | 42 |
| 43 ShaderState shader_state() const { |
| 44 return shader_state_; |
| 45 } |
| 46 |
| 35 GLuint service_id() const { | 47 GLuint service_id() const { |
| 36 return service_id_; | 48 return service_id_; |
| 37 } | 49 } |
| 38 | 50 |
| 39 GLenum shader_type() const { | 51 GLenum shader_type() const { |
| 40 return shader_type_; | 52 return shader_type_; |
| 41 } | 53 } |
| 42 | 54 |
| 43 const std::string& source() const { | 55 const std::string& source() const { |
| 44 return source_; | 56 return source_; |
| 45 } | 57 } |
| 46 | 58 |
| 47 void set_source(const std::string& source) { | 59 void set_source(const std::string& source) { |
| 48 source_ = source; | 60 source_ = source; |
| 49 } | 61 } |
| 50 | 62 |
| 51 const std::string& translated_source() const { | 63 const std::string& translated_source() const { |
| 52 return translated_source_; | 64 return translated_source_; |
| 53 } | 65 } |
| 54 | 66 |
| 55 const std::string& signature_source() const { | 67 const std::string& last_compiled_source() const { |
| 56 return signature_source_; | 68 return last_compiled_source_; |
| 57 } | 69 } |
| 58 | 70 |
| 59 const sh::Attribute* GetAttribInfo(const std::string& name) const; | 71 const sh::Attribute* GetAttribInfo(const std::string& name) const; |
| 60 const sh::Uniform* GetUniformInfo(const std::string& name) const; | 72 const sh::Uniform* GetUniformInfo(const std::string& name) const; |
| 61 const sh::Varying* GetVaryingInfo(const std::string& name) const; | 73 const sh::Varying* GetVaryingInfo(const std::string& name) const; |
| 62 | 74 |
| 63 // If the original_name is not found, return NULL. | 75 // If the original_name is not found, return NULL. |
| 64 const std::string* GetAttribMappedName( | 76 const std::string* GetAttribMappedName( |
| 65 const std::string& original_name) const; | 77 const std::string& original_name) const; |
| 66 | 78 |
| 67 // If the hashed_name is not found, return NULL. | 79 // If the hashed_name is not found, return NULL. |
| 68 const std::string* GetOriginalNameFromHashedName( | 80 const std::string* GetOriginalNameFromHashedName( |
| 69 const std::string& hashed_name) const; | 81 const std::string& hashed_name) const; |
| 70 | 82 |
| 71 const std::string& log_info() const { | 83 const std::string& log_info() const { |
| 72 return log_info_; | 84 return log_info_; |
| 73 } | 85 } |
| 74 | 86 |
| 75 bool valid() const { | 87 bool valid() const { |
| 76 return valid_; | 88 return shader_state_ == kShaderStateCompiled && valid_; |
| 77 } | 89 } |
| 78 | 90 |
| 79 bool IsDeleted() const { | 91 bool IsDeleted() const { |
| 80 return service_id_ == 0; | 92 return service_id_ == 0; |
| 81 } | 93 } |
| 82 | 94 |
| 83 bool InUse() const { | 95 bool InUse() const { |
| 84 DCHECK_GE(use_count_, 0); | 96 DCHECK_GE(use_count_, 0); |
| 85 return use_count_ != 0; | 97 return use_count_ != 0; |
| 86 } | 98 } |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 124 | 136 |
| 125 Shader(GLuint service_id, GLenum shader_type); | 137 Shader(GLuint service_id, GLenum shader_type); |
| 126 ~Shader(); | 138 ~Shader(); |
| 127 | 139 |
| 128 void IncUseCount(); | 140 void IncUseCount(); |
| 129 void DecUseCount(); | 141 void DecUseCount(); |
| 130 void MarkAsDeleted(); | 142 void MarkAsDeleted(); |
| 131 | 143 |
| 132 int use_count_; | 144 int use_count_; |
| 133 | 145 |
| 146 // The current state of the shader. |
| 147 ShaderState shader_state_; |
| 148 |
| 134 // The shader this Shader is tracking. | 149 // The shader this Shader is tracking. |
| 135 GLuint service_id_; | 150 GLuint service_id_; |
| 151 |
| 136 // Type of shader - GL_VERTEX_SHADER or GL_FRAGMENT_SHADER. | 152 // Type of shader - GL_VERTEX_SHADER or GL_FRAGMENT_SHADER. |
| 137 GLenum shader_type_; | 153 GLenum shader_type_; |
| 138 | 154 |
| 139 // True if compilation succeeded. | 155 // True if compilation succeeded. |
| 140 bool valid_; | 156 bool valid_; |
| 141 | 157 |
| 142 // The shader source as passed to glShaderSource. | 158 // The shader source as passed to glShaderSource. |
| 143 std::string source_; | 159 std::string source_; |
| 144 | 160 |
| 145 // The source the last compile used. | 161 // The source the last compile used. |
| 146 std::string signature_source_; | 162 std::string last_compiled_source_; |
| 147 | 163 |
| 148 // The translated shader source. | 164 // The translated shader source. |
| 149 std::string translated_source_; | 165 std::string translated_source_; |
| 150 | 166 |
| 151 // The shader translation log. | 167 // The shader translation log. |
| 152 std::string log_info_; | 168 std::string log_info_; |
| 153 | 169 |
| 154 // The type info when the shader was last compiled. | 170 // The type info when the shader was last compiled. |
| 155 AttributeMap attrib_map_; | 171 AttributeMap attrib_map_; |
| 156 UniformMap uniform_map_; | 172 UniformMap uniform_map_; |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 207 void RemoveShader(Shader* shader); | 223 void RemoveShader(Shader* shader); |
| 208 | 224 |
| 209 DISALLOW_COPY_AND_ASSIGN(ShaderManager); | 225 DISALLOW_COPY_AND_ASSIGN(ShaderManager); |
| 210 }; | 226 }; |
| 211 | 227 |
| 212 } // namespace gles2 | 228 } // namespace gles2 |
| 213 } // namespace gpu | 229 } // namespace gpu |
| 214 | 230 |
| 215 #endif // GPU_COMMAND_BUFFER_SERVICE_SHADER_MANAGER_H_ | 231 #endif // GPU_COMMAND_BUFFER_SERVICE_SHADER_MANAGER_H_ |
| 216 | 232 |
| OLD | NEW |