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 15 matching lines...) Expand all Loading... |
26 public: | 26 public: |
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 enum CompilationStatus { |
| 37 NOT_COMPILED, |
| 38 // We're pending compilation for a cache hit with the program cache. |
| 39 PENDING_DEFERRED_COMPILE, |
| 40 COMPILED |
| 41 }; |
| 42 |
36 void UpdateSource(const char* source) { | 43 void UpdateSource(const char* source) { |
37 // If the source is flagged as compiled, then store our previous source | 44 // If the source is flagged as compiled, then store our previous source |
38 // for deferred compile and caching. | 45 // for deferred compile and caching. |
39 if (!deferred_compilation_source_.get()) { | 46 if (!deferred_compilation_source_.get()) { |
40 deferred_compilation_source_.reset(source_.release()); | 47 deferred_compilation_source_.reset(source_.release()); |
41 } | 48 } |
42 source_.reset(source ? new std::string(source) : NULL); | 49 source_.reset(source ? new std::string(source) : NULL); |
43 translated_source_.reset(NULL); | |
44 } | 50 } |
45 | 51 |
46 void UpdateTranslatedSource(const char* translated_source) { | 52 void UpdateTranslatedSource(const char* translated_source) { |
47 translated_source_.reset( | 53 translated_source_.reset( |
48 translated_source ? new std::string(translated_source) : NULL); | 54 translated_source ? new std::string(translated_source) : NULL); |
49 } | 55 } |
50 | 56 |
51 GLuint service_id() const { | 57 GLuint service_id() const { |
52 return service_id_; | 58 return service_id_; |
53 } | 59 } |
54 | 60 |
55 GLenum shader_type() const { | 61 GLenum shader_type() const { |
56 return shader_type_; | 62 return shader_type_; |
57 } | 63 } |
58 | 64 |
59 const std::string* source() const { | 65 const std::string* source() const { |
60 return source_.get(); | 66 return source_.get(); |
61 } | 67 } |
62 | 68 |
63 const std::string* translated_source() const { | 69 const std::string* translated_source() const { |
64 return translated_source_.get(); | 70 return translated_source_.get(); |
65 } | 71 } |
66 | 72 |
67 void SetStatus( | 73 void SetStatus( |
68 bool valid, const char* log, | 74 bool valid, const char* log, |
69 ShaderTranslatorInterface* translator); | 75 ShaderTranslatorInterface* translator); |
70 | 76 |
71 // If the source was actually compiled (compilation wasn't deferred) | 77 CompilationStatus compilation_status() const { |
72 bool source_compiled() const { | 78 return compilation_status_; |
73 return source_compiled_; | |
74 } | 79 } |
75 | 80 |
76 // The source that was used when the user called CompileShader. | 81 // The source that was used when the user called CompileShader. |
77 // This is used for a deferred compile and in the program cache | 82 // This is used for a deferred compile and in the program cache |
78 const std::string* deferred_compilation_source() const { | 83 const std::string* deferred_compilation_source() const { |
79 return deferred_compilation_source_.get() != NULL ? | 84 return deferred_compilation_source_.get() != NULL ? |
80 deferred_compilation_source_.get() : | 85 deferred_compilation_source_.get() : |
81 source_.get(); | 86 source_.get(); |
82 } | 87 } |
83 | 88 |
84 // Resets our deferred compilation source and stores if the source was | 89 // Resets our deferred compilation source and stores if the source was |
85 // actually compiled, or if we're expecting a cache hit | 90 // actually compiled, or if we're expecting a cache hit |
86 void FlagSourceAsCompiled(bool actually_compiled) { | 91 void FlagSourceAsCompiled(bool actually_compiled) { |
87 source_compiled_ = actually_compiled; | 92 compilation_status_ = actually_compiled ? |
| 93 COMPILED : |
| 94 PENDING_DEFERRED_COMPILE; |
88 deferred_compilation_source_.reset(); | 95 deferred_compilation_source_.reset(); |
89 } | 96 } |
90 | 97 |
91 const VariableInfo* GetAttribInfo(const std::string& name) const; | 98 const VariableInfo* GetAttribInfo(const std::string& name) const; |
92 const VariableInfo* GetUniformInfo(const std::string& name) const; | 99 const VariableInfo* GetUniformInfo(const std::string& name) const; |
93 | 100 |
94 // If the original_name is not found, return NULL. | 101 // If the original_name is not found, return NULL. |
95 const std::string* GetAttribMappedName( | 102 const std::string* GetAttribMappedName( |
96 const std::string& original_name) const; | 103 const std::string& original_name) const; |
97 | 104 |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
163 // The translated shader source. | 170 // The translated shader source. |
164 scoped_ptr<std::string> translated_source_; | 171 scoped_ptr<std::string> translated_source_; |
165 | 172 |
166 // The shader translation log. | 173 // The shader translation log. |
167 scoped_ptr<std::string> log_info_; | 174 scoped_ptr<std::string> log_info_; |
168 | 175 |
169 // The type info when the shader was last compiled. | 176 // The type info when the shader was last compiled. |
170 VariableMap attrib_map_; | 177 VariableMap attrib_map_; |
171 VariableMap uniform_map_; | 178 VariableMap uniform_map_; |
172 | 179 |
173 // If the source was actually compiled (otherwise we're deferring | 180 // The current compilation status of the shader |
174 // compilation because of a possible cache hit) | 181 CompilationStatus compilation_status_; |
175 bool source_compiled_; | |
176 | 182 |
177 // Holds on to the source for a deferred compile. | 183 // Holds on to the source for a deferred compile. |
178 scoped_ptr<std::string> deferred_compilation_source_; | 184 scoped_ptr<std::string> deferred_compilation_source_; |
179 }; | 185 }; |
180 | 186 |
181 ShaderManager(); | 187 ShaderManager(); |
182 ~ShaderManager(); | 188 ~ShaderManager(); |
183 | 189 |
184 // Must call before destruction. | 190 // Must call before destruction. |
185 void Destroy(bool have_context); | 191 void Destroy(bool have_context); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
217 void RemoveShaderInfoIfUnused(ShaderInfo* info); | 223 void RemoveShaderInfoIfUnused(ShaderInfo* info); |
218 | 224 |
219 DISALLOW_COPY_AND_ASSIGN(ShaderManager); | 225 DISALLOW_COPY_AND_ASSIGN(ShaderManager); |
220 }; | 226 }; |
221 | 227 |
222 } // namespace gles2 | 228 } // namespace gles2 |
223 } // namespace gpu | 229 } // namespace gpu |
224 | 230 |
225 #endif // GPU_COMMAND_BUFFER_SERVICE_SHADER_MANAGER_H_ | 231 #endif // GPU_COMMAND_BUFFER_SERVICE_SHADER_MANAGER_H_ |
226 | 232 |
OLD | NEW |