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 // If the source is flagged as compiled, then store our previous source |
| 38 // for deferred compile and caching. |
| 39 if (!deferred_compilation_source_.get()) { |
| 40 deferred_compilation_source_.reset(source_.release()); |
| 41 } |
37 source_.reset(source ? new std::string(source) : NULL); | 42 source_.reset(source ? new std::string(source) : NULL); |
38 translated_source_.reset(NULL); | 43 translated_source_.reset(NULL); |
39 } | 44 } |
40 | 45 |
41 void UpdateTranslatedSource(const char* translated_source) { | 46 void UpdateTranslatedSource(const char* translated_source) { |
42 translated_source_.reset( | 47 translated_source_.reset( |
43 translated_source ? new std::string(translated_source) : NULL); | 48 translated_source ? new std::string(translated_source) : NULL); |
44 } | 49 } |
45 | 50 |
46 GLuint service_id() const { | 51 GLuint service_id() const { |
47 return service_id_; | 52 return service_id_; |
48 } | 53 } |
49 | 54 |
50 GLenum shader_type() const { | 55 GLenum shader_type() const { |
51 return shader_type_; | 56 return shader_type_; |
52 } | 57 } |
53 | 58 |
54 const std::string* source() const { | 59 const std::string* source() const { |
55 return source_.get(); | 60 return source_.get(); |
56 } | 61 } |
57 | 62 |
58 const std::string* translated_source() const { | 63 const std::string* translated_source() const { |
59 return translated_source_.get(); | 64 return translated_source_.get(); |
60 } | 65 } |
61 | 66 |
62 void SetStatus( | 67 void SetStatus( |
63 bool valid, const char* log, | 68 bool valid, const char* log, |
64 ShaderTranslatorInterface* translator); | 69 ShaderTranslatorInterface* translator); |
65 | 70 |
| 71 // If the source was actually compiled (compilation wasn't deferred) |
| 72 bool source_compiled() const { |
| 73 return source_compiled_; |
| 74 } |
| 75 |
| 76 // The source that was used when the user called CompileShader. |
| 77 // This is used for a deferred compile and in the program cache |
| 78 const std::string* deferred_compilation_source() const { |
| 79 return deferred_compilation_source_.get() != NULL ? |
| 80 deferred_compilation_source_.get() : |
| 81 source_.get(); |
| 82 } |
| 83 |
| 84 // Resets our deferred compilation source and stores if the source was |
| 85 // actually compiled, or if we're expecting a cache hit |
| 86 void FlagSourceAsCompiled(bool actually_compiled) { |
| 87 source_compiled_ = actually_compiled; |
| 88 deferred_compilation_source_.reset(); |
| 89 } |
| 90 |
66 const VariableInfo* GetAttribInfo(const std::string& name) const; | 91 const VariableInfo* GetAttribInfo(const std::string& name) const; |
67 const VariableInfo* GetUniformInfo(const std::string& name) const; | 92 const VariableInfo* GetUniformInfo(const std::string& name) const; |
68 | 93 |
69 // If the original_name is not found, return NULL. | 94 // If the original_name is not found, return NULL. |
70 const std::string* GetAttribMappedName( | 95 const std::string* GetAttribMappedName( |
71 const std::string& original_name) const; | 96 const std::string& original_name) const; |
72 | 97 |
73 const std::string* log_info() const { | 98 const std::string* log_info() const { |
74 return log_info_.get(); | 99 return log_info_.get(); |
75 } | 100 } |
76 | 101 |
77 bool IsValid() const { | 102 bool IsValid() const { |
78 return valid_; | 103 return valid_; |
79 } | 104 } |
80 | 105 |
81 bool IsDeleted() const { | 106 bool IsDeleted() const { |
82 return service_id_ == 0; | 107 return service_id_ == 0; |
83 } | 108 } |
84 | 109 |
85 bool InUse() const { | 110 bool InUse() const { |
86 DCHECK_GE(use_count_, 0); | 111 DCHECK_GE(use_count_, 0); |
87 return use_count_ != 0; | 112 return use_count_ != 0; |
88 } | 113 } |
89 | 114 |
| 115 // Used by program cache. |
| 116 const ShaderTranslator::VariableMap& attrib_map() const { |
| 117 return attrib_map_; |
| 118 } |
| 119 |
| 120 // Used by program cache. |
| 121 const ShaderTranslator::VariableMap& uniform_map() const { |
| 122 return uniform_map_; |
| 123 } |
| 124 |
| 125 // Used by program cache. |
| 126 void set_attrib_map(const ShaderTranslator::VariableMap& attrib_map) { |
| 127 // copied because cache might be cleared |
| 128 attrib_map_ = ShaderTranslator::VariableMap(attrib_map); |
| 129 } |
| 130 |
| 131 // Used by program cache. |
| 132 void set_uniform_map(const ShaderTranslator::VariableMap& uniform_map) { |
| 133 // copied because cache might be cleared |
| 134 uniform_map_ = ShaderTranslator::VariableMap(uniform_map); |
| 135 } |
| 136 |
90 private: | 137 private: |
91 typedef ShaderTranslator::VariableMap VariableMap; | 138 typedef ShaderTranslator::VariableMap VariableMap; |
92 | 139 |
93 friend class base::RefCounted<ShaderInfo>; | 140 friend class base::RefCounted<ShaderInfo>; |
94 friend class ShaderManager; | 141 friend class ShaderManager; |
95 | 142 |
96 ShaderInfo(GLuint service_id, GLenum shader_type); | 143 ShaderInfo(GLuint service_id, GLenum shader_type); |
97 ~ShaderInfo(); | 144 ~ShaderInfo(); |
98 | 145 |
99 void IncUseCount(); | 146 void IncUseCount(); |
(...skipping 15 matching lines...) Expand all Loading... |
115 | 162 |
116 // The translated shader source. | 163 // The translated shader source. |
117 scoped_ptr<std::string> translated_source_; | 164 scoped_ptr<std::string> translated_source_; |
118 | 165 |
119 // The shader translation log. | 166 // The shader translation log. |
120 scoped_ptr<std::string> log_info_; | 167 scoped_ptr<std::string> log_info_; |
121 | 168 |
122 // The type info when the shader was last compiled. | 169 // The type info when the shader was last compiled. |
123 VariableMap attrib_map_; | 170 VariableMap attrib_map_; |
124 VariableMap uniform_map_; | 171 VariableMap uniform_map_; |
| 172 |
| 173 // If the source was actually compiled (otherwise we're deferring |
| 174 // compilation because of a possible cache hit) |
| 175 bool source_compiled_; |
| 176 |
| 177 // Holds on to the source for a deferred compile. |
| 178 scoped_ptr<std::string> deferred_compilation_source_; |
125 }; | 179 }; |
126 | 180 |
127 ShaderManager(); | 181 ShaderManager(); |
128 ~ShaderManager(); | 182 ~ShaderManager(); |
129 | 183 |
130 // Must call before destruction. | 184 // Must call before destruction. |
131 void Destroy(bool have_context); | 185 void Destroy(bool have_context); |
132 | 186 |
133 // Creates a shader info for the given shader ID. | 187 // Creates a shader info for the given shader ID. |
134 ShaderInfo* CreateShaderInfo( | 188 ShaderInfo* CreateShaderInfo( |
(...skipping 28 matching lines...) Expand all Loading... |
163 void RemoveShaderInfoIfUnused(ShaderInfo* info); | 217 void RemoveShaderInfoIfUnused(ShaderInfo* info); |
164 | 218 |
165 DISALLOW_COPY_AND_ASSIGN(ShaderManager); | 219 DISALLOW_COPY_AND_ASSIGN(ShaderManager); |
166 }; | 220 }; |
167 | 221 |
168 } // namespace gles2 | 222 } // namespace gles2 |
169 } // namespace gpu | 223 } // namespace gpu |
170 | 224 |
171 #endif // GPU_COMMAND_BUFFER_SERVICE_SHADER_MANAGER_H_ | 225 #endif // GPU_COMMAND_BUFFER_SERVICE_SHADER_MANAGER_H_ |
172 | 226 |
OLD | NEW |