Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(255)

Side by Side Diff: gpu/command_buffer/service/shader_manager.h

Issue 10795037: Revert 147328 - Current status of patch: (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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 }
42 source_.reset(source ? new std::string(source) : NULL); 37 source_.reset(source ? new std::string(source) : NULL);
43 translated_source_.reset(NULL); 38 translated_source_.reset(NULL);
44 } 39 }
45 40
46 void UpdateTranslatedSource(const char* translated_source) { 41 void UpdateTranslatedSource(const char* translated_source) {
47 translated_source_.reset( 42 translated_source_.reset(
48 translated_source ? new std::string(translated_source) : NULL); 43 translated_source ? new std::string(translated_source) : NULL);
49 } 44 }
50 45
51 GLuint service_id() const { 46 GLuint service_id() const {
52 return service_id_; 47 return service_id_;
53 } 48 }
54 49
55 GLenum shader_type() const { 50 GLenum shader_type() const {
56 return shader_type_; 51 return shader_type_;
57 } 52 }
58 53
59 const std::string* source() const { 54 const std::string* source() const {
60 return source_.get(); 55 return source_.get();
61 } 56 }
62 57
63 const std::string* translated_source() const { 58 const std::string* translated_source() const {
64 return translated_source_.get(); 59 return translated_source_.get();
65 } 60 }
66 61
67 void SetStatus( 62 void SetStatus(
68 bool valid, const char* log, 63 bool valid, const char* log,
69 ShaderTranslatorInterface* translator); 64 ShaderTranslatorInterface* translator);
70 65
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
91 const VariableInfo* GetAttribInfo(const std::string& name) const; 66 const VariableInfo* GetAttribInfo(const std::string& name) const;
92 const VariableInfo* GetUniformInfo(const std::string& name) const; 67 const VariableInfo* GetUniformInfo(const std::string& name) const;
93 68
94 // If the original_name is not found, return NULL. 69 // If the original_name is not found, return NULL.
95 const std::string* GetAttribMappedName( 70 const std::string* GetAttribMappedName(
96 const std::string& original_name) const; 71 const std::string& original_name) const;
97 72
98 const std::string* log_info() const { 73 const std::string* log_info() const {
99 return log_info_.get(); 74 return log_info_.get();
100 } 75 }
101 76
102 bool IsValid() const { 77 bool IsValid() const {
103 return valid_; 78 return valid_;
104 } 79 }
105 80
106 bool IsDeleted() const { 81 bool IsDeleted() const {
107 return service_id_ == 0; 82 return service_id_ == 0;
108 } 83 }
109 84
110 bool InUse() const { 85 bool InUse() const {
111 DCHECK_GE(use_count_, 0); 86 DCHECK_GE(use_count_, 0);
112 return use_count_ != 0; 87 return use_count_ != 0;
113 } 88 }
114 89
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
137 private: 90 private:
138 typedef ShaderTranslator::VariableMap VariableMap; 91 typedef ShaderTranslator::VariableMap VariableMap;
139 92
140 friend class base::RefCounted<ShaderInfo>; 93 friend class base::RefCounted<ShaderInfo>;
141 friend class ShaderManager; 94 friend class ShaderManager;
142 95
143 ShaderInfo(GLuint service_id, GLenum shader_type); 96 ShaderInfo(GLuint service_id, GLenum shader_type);
144 ~ShaderInfo(); 97 ~ShaderInfo();
145 98
146 void IncUseCount(); 99 void IncUseCount();
(...skipping 15 matching lines...) Expand all
162 115
163 // The translated shader source. 116 // The translated shader source.
164 scoped_ptr<std::string> translated_source_; 117 scoped_ptr<std::string> translated_source_;
165 118
166 // The shader translation log. 119 // The shader translation log.
167 scoped_ptr<std::string> log_info_; 120 scoped_ptr<std::string> log_info_;
168 121
169 // The type info when the shader was last compiled. 122 // The type info when the shader was last compiled.
170 VariableMap attrib_map_; 123 VariableMap attrib_map_;
171 VariableMap uniform_map_; 124 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_;
179 }; 125 };
180 126
181 ShaderManager(); 127 ShaderManager();
182 ~ShaderManager(); 128 ~ShaderManager();
183 129
184 // Must call before destruction. 130 // Must call before destruction.
185 void Destroy(bool have_context); 131 void Destroy(bool have_context);
186 132
187 // Creates a shader info for the given shader ID. 133 // Creates a shader info for the given shader ID.
188 ShaderInfo* CreateShaderInfo( 134 ShaderInfo* CreateShaderInfo(
(...skipping 28 matching lines...) Expand all
217 void RemoveShaderInfoIfUnused(ShaderInfo* info); 163 void RemoveShaderInfoIfUnused(ShaderInfo* info);
218 164
219 DISALLOW_COPY_AND_ASSIGN(ShaderManager); 165 DISALLOW_COPY_AND_ASSIGN(ShaderManager);
220 }; 166 };
221 167
222 } // namespace gles2 168 } // namespace gles2
223 } // namespace gpu 169 } // namespace gpu
224 170
225 #endif // GPU_COMMAND_BUFFER_SERVICE_SHADER_MANAGER_H_ 171 #endif // GPU_COMMAND_BUFFER_SERVICE_SHADER_MANAGER_H_
226 172
OLDNEW
« no previous file with comments | « gpu/command_buffer/service/program_manager_unittest.cc ('k') | gpu/command_buffer/service/shader_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698