| 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" |
| 11 #include "base/logging.h" | 11 #include "base/logging.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 "gpu/command_buffer/service/gl_utils.h" | 14 #include "gpu/command_buffer/service/gl_utils.h" |
| 15 #include "gpu/command_buffer/service/shader_translator.h" | 15 #include "gpu/command_buffer/service/shader_translator.h" |
| 16 #include "gpu/gpu_export.h" | 16 #include "gpu/gpu_export.h" |
| 17 | 17 |
| 18 namespace gpu { | 18 namespace gpu { |
| 19 namespace gles2 { | 19 namespace gles2 { |
| 20 | 20 |
| 21 // This is used to keep the source code for a shader. This is because in order | 21 // This is used to keep the source code for a shader. This is because in order |
| 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 { |
| 28 kANGLE, |
| 29 kGL, // GL or GLES |
| 30 }; |
| 31 |
| 27 typedef ShaderTranslator::VariableInfo VariableInfo; | 32 typedef ShaderTranslator::VariableInfo VariableInfo; |
| 28 | 33 |
| 29 void UpdateSource(const char* source) { | 34 void DoCompile(ShaderTranslatorInterface* translator, |
| 30 source_.reset(source ? new std::string(source) : NULL); | 35 TranslatedShaderSourceType type); |
| 31 } | |
| 32 | |
| 33 void UpdateTranslatedSource(const char* translated_source) { | |
| 34 translated_source_.reset( | |
| 35 translated_source ? new std::string(translated_source) : NULL); | |
| 36 } | |
| 37 | 36 |
| 38 GLuint service_id() const { | 37 GLuint service_id() const { |
| 39 return service_id_; | 38 return service_id_; |
| 40 } | 39 } |
| 41 | 40 |
| 42 GLenum shader_type() const { | 41 GLenum shader_type() const { |
| 43 return shader_type_; | 42 return shader_type_; |
| 44 } | 43 } |
| 45 | 44 |
| 46 const std::string* source() const { | 45 const std::string& source() const { |
| 47 return source_.get(); | 46 return source_; |
| 48 } | 47 } |
| 49 | 48 |
| 50 const std::string* translated_source() const { | 49 void set_source(const std::string& source) { |
| 51 return translated_source_.get(); | 50 source_ = source; |
| 52 } | 51 } |
| 53 | 52 |
| 54 const std::string* signature_source() const { | 53 const std::string& translated_source() const { |
| 55 return signature_source_.get(); | 54 return translated_source_; |
| 56 } | 55 } |
| 57 | 56 |
| 58 void SetStatus( | 57 const std::string& signature_source() const { |
| 59 bool valid, const char* log, | 58 return signature_source_; |
| 60 ShaderTranslatorInterface* translator); | 59 } |
| 61 | 60 |
| 62 const VariableInfo* GetAttribInfo(const std::string& name) const; | 61 const VariableInfo* GetAttribInfo(const std::string& name) const; |
| 63 const VariableInfo* GetUniformInfo(const std::string& name) const; | 62 const VariableInfo* GetUniformInfo(const std::string& name) const; |
| 63 const VariableInfo* GetVaryingInfo(const std::string& name) const; |
| 64 | 64 |
| 65 // If the original_name is not found, return NULL. | 65 // If the original_name is not found, return NULL. |
| 66 const std::string* GetAttribMappedName( | 66 const std::string* GetAttribMappedName( |
| 67 const std::string& original_name) const; | 67 const std::string& original_name) const; |
| 68 | 68 |
| 69 // If the hashed_name is not found, return NULL. | 69 // If the hashed_name is not found, return NULL. |
| 70 const std::string* GetOriginalNameFromHashedName( | 70 const std::string* GetOriginalNameFromHashedName( |
| 71 const std::string& hashed_name) const; | 71 const std::string& hashed_name) const; |
| 72 | 72 |
| 73 const std::string* log_info() const { | 73 const std::string& log_info() const { |
| 74 return log_info_.get(); | 74 return log_info_; |
| 75 } | 75 } |
| 76 | 76 |
| 77 bool IsValid() const { | 77 bool valid() const { |
| 78 return valid_; | 78 return valid_; |
| 79 } | 79 } |
| 80 | 80 |
| 81 bool IsDeleted() const { | 81 bool IsDeleted() const { |
| 82 return service_id_ == 0; | 82 return service_id_ == 0; |
| 83 } | 83 } |
| 84 | 84 |
| 85 bool InUse() const { | 85 bool InUse() const { |
| 86 DCHECK_GE(use_count_, 0); | 86 DCHECK_GE(use_count_, 0); |
| 87 return use_count_ != 0; | 87 return use_count_ != 0; |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 138 | 138 |
| 139 // The shader this Shader is tracking. | 139 // The shader this Shader is tracking. |
| 140 GLuint service_id_; | 140 GLuint service_id_; |
| 141 // Type of shader - GL_VERTEX_SHADER or GL_FRAGMENT_SHADER. | 141 // Type of shader - GL_VERTEX_SHADER or GL_FRAGMENT_SHADER. |
| 142 GLenum shader_type_; | 142 GLenum shader_type_; |
| 143 | 143 |
| 144 // True if compilation succeeded. | 144 // True if compilation succeeded. |
| 145 bool valid_; | 145 bool valid_; |
| 146 | 146 |
| 147 // The shader source as passed to glShaderSource. | 147 // The shader source as passed to glShaderSource. |
| 148 scoped_ptr<std::string> source_; | 148 std::string source_; |
| 149 | 149 |
| 150 // The source the last compile used. | 150 // The source the last compile used. |
| 151 scoped_ptr<std::string> signature_source_; | 151 std::string signature_source_; |
| 152 | 152 |
| 153 // The translated shader source. | 153 // The translated shader source. |
| 154 scoped_ptr<std::string> translated_source_; | 154 std::string translated_source_; |
| 155 | 155 |
| 156 // The shader translation log. | 156 // The shader translation log. |
| 157 scoped_ptr<std::string> log_info_; | 157 std::string log_info_; |
| 158 | 158 |
| 159 // The type info when the shader was last compiled. | 159 // The type info when the shader was last compiled. |
| 160 VariableMap attrib_map_; | 160 VariableMap attrib_map_; |
| 161 VariableMap uniform_map_; | 161 VariableMap uniform_map_; |
| 162 VariableMap varying_map_; | 162 VariableMap varying_map_; |
| 163 | 163 |
| 164 // The name hashing info when the shader was last compiled. | 164 // The name hashing info when the shader was last compiled. |
| 165 NameMap name_map_; | 165 NameMap name_map_; |
| 166 }; | 166 }; |
| 167 | 167 |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 212 void RemoveShader(Shader* shader); | 212 void RemoveShader(Shader* shader); |
| 213 | 213 |
| 214 DISALLOW_COPY_AND_ASSIGN(ShaderManager); | 214 DISALLOW_COPY_AND_ASSIGN(ShaderManager); |
| 215 }; | 215 }; |
| 216 | 216 |
| 217 } // namespace gles2 | 217 } // namespace gles2 |
| 218 } // namespace gpu | 218 } // namespace gpu |
| 219 | 219 |
| 220 #endif // GPU_COMMAND_BUFFER_SERVICE_SHADER_MANAGER_H_ | 220 #endif // GPU_COMMAND_BUFFER_SERVICE_SHADER_MANAGER_H_ |
| 221 | 221 |
| OLD | NEW |