Chromium Code Reviews| 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/hash_tables.h" | 10 #include "base/hash_tables.h" |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 27 // This is used to keep the source code for a shader. This is because in order | 27 // This is used to keep the source code for a shader. This is because in order |
| 28 // to emluate GLES2 the shaders will have to be re-written before passed to | 28 // to emluate GLES2 the shaders will have to be re-written before passed to |
| 29 // the underlying OpenGL. But, when the user calls glGetShaderSource they | 29 // the underlying OpenGL. But, when the user calls glGetShaderSource they |
| 30 // should get the source they passed in, not the re-written source. | 30 // should get the source they passed in, not the re-written source. |
| 31 class GPU_EXPORT ShaderInfo : public base::RefCounted<ShaderInfo> { | 31 class GPU_EXPORT ShaderInfo : public base::RefCounted<ShaderInfo> { |
| 32 public: | 32 public: |
| 33 typedef scoped_refptr<ShaderInfo> Ref; | 33 typedef scoped_refptr<ShaderInfo> Ref; |
| 34 typedef ShaderTranslator::VariableInfo VariableInfo; | 34 typedef ShaderTranslator::VariableInfo VariableInfo; |
| 35 | 35 |
| 36 void UpdateSource(const char* source) { | 36 void UpdateSource(const char* source) { |
| 37 // prevent the compiled source from getting deleted when source_ is reset | |
|
greggman
2012/07/16 19:41:24
I'm confused by this implementation.
It seems lik
dmurph
2012/07/16 20:00:37
I'm doing it slightly differently, and I think it
| |
| 38 if(!compilation_source_.get() && source_.get()) { | |
|
greggman
2012/07/16 21:57:26
Okay then maybe a bunch of comments need to change
dmurph
2012/07/17 18:17:13
Updated comment, simplified this statement
| |
| 39 compilation_source_.reset(source_.release()); | |
| 40 } | |
| 37 source_.reset(source ? new std::string(source) : NULL); | 41 source_.reset(source ? new std::string(source) : NULL); |
| 38 translated_source_.reset(NULL); | 42 translated_source_.reset(NULL); |
| 39 } | 43 } |
| 40 | 44 |
| 41 void UpdateTranslatedSource(const char* translated_source) { | 45 void UpdateTranslatedSource(const char* translated_source) { |
| 42 translated_source_.reset( | 46 translated_source_.reset( |
| 43 translated_source ? new std::string(translated_source) : NULL); | 47 translated_source ? new std::string(translated_source) : NULL); |
| 44 } | 48 } |
| 45 | 49 |
| 46 GLuint service_id() const { | 50 GLuint service_id() const { |
| 47 return service_id_; | 51 return service_id_; |
| 48 } | 52 } |
| 49 | 53 |
| 50 GLenum shader_type() const { | 54 GLenum shader_type() const { |
| 51 return shader_type_; | 55 return shader_type_; |
| 52 } | 56 } |
| 53 | 57 |
| 54 const std::string* source() const { | 58 const std::string* source() const { |
| 55 return source_.get(); | 59 return source_.get(); |
| 56 } | 60 } |
| 57 | 61 |
| 58 const std::string* translated_source() const { | 62 const std::string* translated_source() const { |
| 59 return translated_source_.get(); | 63 return translated_source_.get(); |
| 60 } | 64 } |
| 61 | 65 |
| 62 void SetStatus( | 66 void SetStatus( |
| 63 bool valid, const char* log, | 67 bool valid, const char* log, |
| 64 ShaderTranslatorInterface* translator); | 68 ShaderTranslatorInterface* translator); |
| 65 | 69 |
| 70 bool pending_compilation() const { | |
| 71 return pending_cache_miss_compilation_; | |
| 72 } | |
| 73 | |
| 74 // The source that was compiled for this shader | |
|
greggman
2012/07/16 21:57:26
How about
// The source that was used when the us
dmurph
2012/07/17 18:17:13
How about deferred_compilation_source?
| |
| 75 const std::string* compilation_source() const { | |
| 76 return compilation_source_.get() != NULL ? | |
| 77 compilation_source_.get() : | |
| 78 source_.get(); | |
| 79 } | |
| 80 | |
| 81 // Stores the current source as the compiled source | |
|
greggman
2012/07/16 21:57:26
This comment does not match what this function doe
dmurph
2012/07/17 18:17:13
Did some refactoring to try and help clear all of
| |
| 82 void SetSourceAsCompiled(bool pending_cache_miss_compilation) { | |
|
greggman
2012/07/16 21:57:26
Also, there needs to be unit tests for these new f
dmurph
2012/07/17 18:17:13
Done.
| |
| 83 pending_cache_miss_compilation_ = pending_cache_miss_compilation; | |
| 84 compilation_source_.reset(); | |
| 85 } | |
| 86 | |
| 66 const VariableInfo* GetAttribInfo(const std::string& name) const; | 87 const VariableInfo* GetAttribInfo(const std::string& name) const; |
| 67 const VariableInfo* GetUniformInfo(const std::string& name) const; | 88 const VariableInfo* GetUniformInfo(const std::string& name) const; |
| 68 | 89 |
| 69 // If the original_name is not found, return NULL. | 90 // If the original_name is not found, return NULL. |
| 70 const std::string* GetAttribMappedName( | 91 const std::string* GetAttribMappedName( |
| 71 const std::string& original_name) const; | 92 const std::string& original_name) const; |
| 72 | 93 |
| 73 const std::string* log_info() const { | 94 const std::string* log_info() const { |
| 74 return log_info_.get(); | 95 return log_info_.get(); |
| 75 } | 96 } |
| 76 | 97 |
| 77 bool IsValid() const { | 98 bool IsValid() const { |
| 78 return valid_; | 99 return valid_; |
| 79 } | 100 } |
| 80 | 101 |
| 81 bool IsDeleted() const { | 102 bool IsDeleted() const { |
| 82 return service_id_ == 0; | 103 return service_id_ == 0; |
| 83 } | 104 } |
| 84 | 105 |
| 85 bool InUse() const { | 106 bool InUse() const { |
| 86 DCHECK_GE(use_count_, 0); | 107 DCHECK_GE(use_count_, 0); |
| 87 return use_count_ != 0; | 108 return use_count_ != 0; |
| 88 } | 109 } |
| 89 | 110 |
| 111 // Used by program cache. | |
| 112 const ShaderTranslator::VariableMap& attrib_map() const { | |
| 113 return attrib_map_; | |
| 114 } | |
| 115 | |
| 116 // Used by program cache. | |
| 117 const ShaderTranslator::VariableMap& uniform_map() const { | |
| 118 return uniform_map_; | |
| 119 } | |
| 120 | |
| 121 // Used by program cache. | |
| 122 void set_attrib_map(const ShaderTranslator::VariableMap& attrib_map) { | |
| 123 // copied because cache might be cleared | |
| 124 attrib_map_ = ShaderTranslator::VariableMap(attrib_map); | |
| 125 } | |
| 126 | |
| 127 // Used by program cache. | |
| 128 void set_uniform_map(const ShaderTranslator::VariableMap& uniform_map) { | |
| 129 // copied because cache might be cleared | |
| 130 uniform_map_ = ShaderTranslator::VariableMap(uniform_map); | |
| 131 } | |
| 132 | |
| 90 private: | 133 private: |
| 91 typedef ShaderTranslator::VariableMap VariableMap; | 134 typedef ShaderTranslator::VariableMap VariableMap; |
| 92 | 135 |
| 93 friend class base::RefCounted<ShaderInfo>; | 136 friend class base::RefCounted<ShaderInfo>; |
| 94 friend class ShaderManager; | 137 friend class ShaderManager; |
| 95 | 138 |
| 96 ShaderInfo(GLuint service_id, GLenum shader_type); | 139 ShaderInfo(GLuint service_id, GLenum shader_type); |
| 97 ~ShaderInfo(); | 140 ~ShaderInfo(); |
| 98 | 141 |
| 99 void IncUseCount(); | 142 void IncUseCount(); |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 115 | 158 |
| 116 // The translated shader source. | 159 // The translated shader source. |
| 117 scoped_ptr<std::string> translated_source_; | 160 scoped_ptr<std::string> translated_source_; |
| 118 | 161 |
| 119 // The shader translation log. | 162 // The shader translation log. |
| 120 scoped_ptr<std::string> log_info_; | 163 scoped_ptr<std::string> log_info_; |
| 121 | 164 |
| 122 // The type info when the shader was last compiled. | 165 // The type info when the shader was last compiled. |
| 123 VariableMap attrib_map_; | 166 VariableMap attrib_map_; |
| 124 VariableMap uniform_map_; | 167 VariableMap uniform_map_; |
| 168 | |
| 169 // If compilation was delayed for possible cache hit | |
| 170 bool pending_cache_miss_compilation_; | |
| 171 | |
| 172 // Holds on to the source that was supposed to be compiled | |
|
greggman
2012/07/16 21:57:26
This comment makes sense but I might be better to
dmurph
2012/07/17 18:17:13
Done.
| |
| 173 scoped_ptr<std::string> compilation_source_; | |
| 125 }; | 174 }; |
| 126 | 175 |
| 127 ShaderManager(); | 176 ShaderManager(); |
| 128 ~ShaderManager(); | 177 ~ShaderManager(); |
| 129 | 178 |
| 130 // Must call before destruction. | 179 // Must call before destruction. |
| 131 void Destroy(bool have_context); | 180 void Destroy(bool have_context); |
| 132 | 181 |
| 133 // Creates a shader info for the given shader ID. | 182 // Creates a shader info for the given shader ID. |
| 134 ShaderInfo* CreateShaderInfo( | 183 ShaderInfo* CreateShaderInfo( |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 163 void RemoveShaderInfoIfUnused(ShaderInfo* info); | 212 void RemoveShaderInfoIfUnused(ShaderInfo* info); |
| 164 | 213 |
| 165 DISALLOW_COPY_AND_ASSIGN(ShaderManager); | 214 DISALLOW_COPY_AND_ASSIGN(ShaderManager); |
| 166 }; | 215 }; |
| 167 | 216 |
| 168 } // namespace gles2 | 217 } // namespace gles2 |
| 169 } // namespace gpu | 218 } // namespace gpu |
| 170 | 219 |
| 171 #endif // GPU_COMMAND_BUFFER_SERVICE_SHADER_MANAGER_H_ | 220 #endif // GPU_COMMAND_BUFFER_SERVICE_SHADER_MANAGER_H_ |
| 172 | 221 |
| OLD | NEW |