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_PROGRAM_MANAGER_H_ | 5 #ifndef GPU_COMMAND_BUFFER_SERVICE_PROGRAM_MANAGER_H_ |
6 #define GPU_COMMAND_BUFFER_SERVICE_PROGRAM_MANAGER_H_ | 6 #define GPU_COMMAND_BUFFER_SERVICE_PROGRAM_MANAGER_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
(...skipping 18 matching lines...) Expand all Loading... |
29 // This is used to track which attributes a particular program needs | 29 // This is used to track which attributes a particular program needs |
30 // so we can verify at glDrawXXX time that every attribute is either disabled | 30 // so we can verify at glDrawXXX time that every attribute is either disabled |
31 // or if enabled that it points to a valid source. | 31 // or if enabled that it points to a valid source. |
32 class GPU_EXPORT ProgramInfo : public base::RefCounted<ProgramInfo> { | 32 class GPU_EXPORT ProgramInfo : public base::RefCounted<ProgramInfo> { |
33 public: | 33 public: |
34 typedef scoped_refptr<ProgramInfo> Ref; | 34 typedef scoped_refptr<ProgramInfo> Ref; |
35 | 35 |
36 static const int kMaxAttachedShaders = 2; | 36 static const int kMaxAttachedShaders = 2; |
37 | 37 |
38 struct UniformInfo { | 38 struct UniformInfo { |
| 39 UniformInfo(); |
39 UniformInfo( | 40 UniformInfo( |
40 GLsizei _size, GLenum _type, GLint _fake_location_base, | 41 GLsizei _size, GLenum _type, GLint _fake_location_base, |
41 const std::string& _name); | 42 const std::string& _name); |
42 ~UniformInfo(); | 43 ~UniformInfo(); |
43 | 44 |
| 45 bool IsValid() const { |
| 46 return size != 0; |
| 47 } |
| 48 |
44 bool IsSampler() const { | 49 bool IsSampler() const { |
45 return type == GL_SAMPLER_2D || type == GL_SAMPLER_2D_RECT_ARB || | 50 return type == GL_SAMPLER_2D || type == GL_SAMPLER_2D_RECT_ARB || |
46 type == GL_SAMPLER_CUBE || type == GL_SAMPLER_EXTERNAL_OES; | 51 type == GL_SAMPLER_CUBE || type == GL_SAMPLER_EXTERNAL_OES; |
47 } | 52 } |
48 | 53 |
49 GLsizei size; | 54 GLsizei size; |
50 GLenum type; | 55 GLenum type; |
51 GLint fake_location_base; | 56 GLint fake_location_base; |
52 bool is_array; | 57 bool is_array; |
53 std::string name; | 58 std::string name; |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
96 const VertexAttribInfo* GetAttribInfoByLocation(GLuint location) const { | 101 const VertexAttribInfo* GetAttribInfoByLocation(GLuint location) const { |
97 if (location < attrib_location_to_index_map_.size()) { | 102 if (location < attrib_location_to_index_map_.size()) { |
98 GLint index = attrib_location_to_index_map_[location]; | 103 GLint index = attrib_location_to_index_map_[location]; |
99 if (index >= 0) { | 104 if (index >= 0) { |
100 return &attrib_infos_[index]; | 105 return &attrib_infos_[index]; |
101 } | 106 } |
102 } | 107 } |
103 return NULL; | 108 return NULL; |
104 } | 109 } |
105 | 110 |
106 const UniformInfo* GetUniformInfo(GLint index) const { | 111 const UniformInfo* GetUniformInfo(GLint index) const; |
107 return (static_cast<size_t>(index) < uniform_infos_.size()) ? | |
108 &uniform_infos_[index] : NULL; | |
109 } | |
110 | 112 |
111 // If the original name is not found, return NULL. | 113 // If the original name is not found, return NULL. |
112 const std::string* GetAttribMappedName( | 114 const std::string* GetAttribMappedName( |
113 const std::string& original_name) const; | 115 const std::string& original_name) const; |
114 | 116 |
115 // Gets the fake location of a uniform by name. | 117 // Gets the fake location of a uniform by name. |
116 GLint GetUniformFakeLocation(const std::string& name) const; | 118 GLint GetUniformFakeLocation(const std::string& name) const; |
117 | 119 |
118 // Gets the UniformInfo of a uniform by location. | 120 // Gets the UniformInfo of a uniform by location. |
119 const UniformInfo* GetUniformInfoByFakeLocation( | 121 const UniformInfo* GetUniformInfoByFakeLocation( |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
156 const std::string* log_info() const { | 158 const std::string* log_info() const { |
157 return log_info_.get(); | 159 return log_info_.get(); |
158 } | 160 } |
159 | 161 |
160 bool InUse() const { | 162 bool InUse() const { |
161 DCHECK_GE(use_count_, 0); | 163 DCHECK_GE(use_count_, 0); |
162 return use_count_ != 0; | 164 return use_count_ != 0; |
163 } | 165 } |
164 | 166 |
165 // Sets attribute-location binding from a glBindAttribLocation() call. | 167 // Sets attribute-location binding from a glBindAttribLocation() call. |
166 void SetAttribLocationBinding(const std::string& attrib, | 168 void SetAttribLocationBinding(const std::string& attrib, GLint location) { |
167 GLint location) { | |
168 bind_attrib_location_map_[attrib] = location; | 169 bind_attrib_location_map_[attrib] = location; |
169 } | 170 } |
170 | 171 |
| 172 // Sets uniform-location binding from a glBindUniformLocationCHROMIUM call. |
| 173 // returns false if error. |
| 174 bool SetUniformLocationBinding(const std::string& name, GLint location); |
| 175 |
171 // Detects if there are attribute location conflicts from | 176 // Detects if there are attribute location conflicts from |
172 // glBindAttribLocation() calls. | 177 // glBindAttribLocation() calls. |
173 // We only consider the declared attributes in the program. | 178 // We only consider the declared attributes in the program. |
174 bool DetectAttribLocationBindingConflicts() const; | 179 bool DetectAttribLocationBindingConflicts() const; |
175 | 180 |
176 private: | 181 private: |
177 friend class base::RefCounted<ProgramInfo>; | 182 friend class base::RefCounted<ProgramInfo>; |
178 friend class ProgramManager; | 183 friend class ProgramManager; |
179 | 184 |
| 185 typedef std::map<std::string, GLint> LocationMap; |
| 186 |
180 ~ProgramInfo(); | 187 ~ProgramInfo(); |
181 | 188 |
182 void set_log_info(const char* str) { | 189 void set_log_info(const char* str) { |
183 log_info_.reset(str ? new std::string(str) : NULL); | 190 log_info_.reset(str ? new std::string(str) : NULL); |
184 } | 191 } |
185 | 192 |
186 void ClearLinkStatus() { | 193 void ClearLinkStatus() { |
187 link_status_ = false; | 194 link_status_ = false; |
188 } | 195 } |
189 | 196 |
(...skipping 22 matching lines...) Expand all Loading... |
212 | 219 |
213 // Clears all the uniforms. | 220 // Clears all the uniforms. |
214 void ClearUniforms(std::vector<uint8>* zero_buffer); | 221 void ClearUniforms(std::vector<uint8>* zero_buffer); |
215 | 222 |
216 // If long attribate names are mapped during shader translation, call | 223 // If long attribate names are mapped during shader translation, call |
217 // glBindAttribLocation() again with the mapped names. | 224 // glBindAttribLocation() again with the mapped names. |
218 // This is called right before the glLink() call, but after shaders are | 225 // This is called right before the glLink() call, but after shaders are |
219 // translated. | 226 // translated. |
220 void ExecuteBindAttribLocationCalls(); | 227 void ExecuteBindAttribLocationCalls(); |
221 | 228 |
222 const UniformInfo* AddUniformInfo( | 229 bool AddUniformInfo( |
223 GLsizei size, GLenum type, GLint location, | 230 GLsizei size, GLenum type, GLint location, GLint fake_base_location, |
224 const std::string& name, const std::string& original_name); | 231 const std::string& name, const std::string& original_name, |
| 232 size_t* next_available_index); |
225 | 233 |
226 void GetCorrectedVariableInfo( | 234 void GetCorrectedVariableInfo( |
227 bool use_uniforms, const std::string& name, std::string* corrected_name, | 235 bool use_uniforms, const std::string& name, std::string* corrected_name, |
228 std::string* original_name, GLsizei* size, GLenum* type) const; | 236 std::string* original_name, GLsizei* size, GLenum* type) const; |
229 | 237 |
230 void DetachShaders(ShaderManager* manager); | 238 void DetachShaders(ShaderManager* manager); |
231 | 239 |
232 static inline GLint GetUniformInfoIndexFromFakeLocation( | 240 static inline GLint GetUniformInfoIndexFromFakeLocation( |
233 GLint fake_location) { | 241 GLint fake_location) { |
234 return fake_location & 0xFFFF; | 242 return fake_location & 0xFFFF; |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
270 | 278 |
271 // This is true if glLinkProgram was successful at least once. | 279 // This is true if glLinkProgram was successful at least once. |
272 bool valid_; | 280 bool valid_; |
273 | 281 |
274 // This is true if glLinkProgram was successful last time it was called. | 282 // This is true if glLinkProgram was successful last time it was called. |
275 bool link_status_; | 283 bool link_status_; |
276 | 284 |
277 // True if the uniforms have been cleared. | 285 // True if the uniforms have been cleared. |
278 bool uniforms_cleared_; | 286 bool uniforms_cleared_; |
279 | 287 |
| 288 // This is different than uniform_infos_.size() because |
| 289 // that is a sparce array. |
| 290 GLint num_uniforms_; |
| 291 |
280 // Log info | 292 // Log info |
281 scoped_ptr<std::string> log_info_; | 293 scoped_ptr<std::string> log_info_; |
282 | 294 |
283 // attribute-location binding map from glBindAttribLocation() calls. | 295 // attribute-location binding map from glBindAttribLocation() calls. |
284 std::map<std::string, GLint> bind_attrib_location_map_; | 296 LocationMap bind_attrib_location_map_; |
| 297 |
| 298 // uniform-location binding map from glBindUniformLocationCHROMIUM() calls. |
| 299 LocationMap bind_uniform_location_map_; |
285 }; | 300 }; |
286 | 301 |
287 ProgramManager(); | 302 ProgramManager(); |
288 ~ProgramManager(); | 303 ~ProgramManager(); |
289 | 304 |
290 // Must call before destruction. | 305 // Must call before destruction. |
291 void Destroy(bool have_context); | 306 void Destroy(bool have_context); |
292 | 307 |
293 // Creates a new program info. | 308 // Creates a new program info. |
294 ProgramInfo* CreateProgramInfo(GLuint client_id, GLuint service_id); | 309 ProgramInfo* CreateProgramInfo(GLuint client_id, GLuint service_id); |
(...skipping 15 matching lines...) Expand all Loading... |
310 | 325 |
311 // Clears the uniforms for this program. | 326 // Clears the uniforms for this program. |
312 void ClearUniforms(ProgramInfo* info); | 327 void ClearUniforms(ProgramInfo* info); |
313 | 328 |
314 // Returns true if prefix is invalid for gl. | 329 // Returns true if prefix is invalid for gl. |
315 static bool IsInvalidPrefix(const char* name, size_t length); | 330 static bool IsInvalidPrefix(const char* name, size_t length); |
316 | 331 |
317 // Check if a ProgramInfo is owned by this ProgramManager. | 332 // Check if a ProgramInfo is owned by this ProgramManager. |
318 bool IsOwned(ProgramInfo* info); | 333 bool IsOwned(ProgramInfo* info); |
319 | 334 |
| 335 static int32 MakeFakeLocation(int32 index, int32 element); |
| 336 |
320 private: | 337 private: |
321 void StartTracking(ProgramInfo* info); | 338 void StartTracking(ProgramInfo* info); |
322 void StopTracking(ProgramInfo* info); | 339 void StopTracking(ProgramInfo* info); |
323 | 340 |
324 // Info for each "successfully linked" program by service side program Id. | 341 // Info for each "successfully linked" program by service side program Id. |
325 // TODO(gman): Choose a faster container. | 342 // TODO(gman): Choose a faster container. |
326 typedef std::map<GLuint, ProgramInfo::Ref> ProgramInfoMap; | 343 typedef std::map<GLuint, ProgramInfo::Ref> ProgramInfoMap; |
327 ProgramInfoMap program_infos_; | 344 ProgramInfoMap program_infos_; |
328 | 345 |
329 // Counts the number of ProgramInfo allocated with 'this' as its manager. | 346 // Counts the number of ProgramInfo allocated with 'this' as its manager. |
(...skipping 10 matching lines...) Expand all Loading... |
340 void RemoveProgramInfoIfUnused( | 357 void RemoveProgramInfoIfUnused( |
341 ShaderManager* shader_manager, ProgramInfo* info); | 358 ShaderManager* shader_manager, ProgramInfo* info); |
342 | 359 |
343 DISALLOW_COPY_AND_ASSIGN(ProgramManager); | 360 DISALLOW_COPY_AND_ASSIGN(ProgramManager); |
344 }; | 361 }; |
345 | 362 |
346 } // namespace gles2 | 363 } // namespace gles2 |
347 } // namespace gpu | 364 } // namespace gpu |
348 | 365 |
349 #endif // GPU_COMMAND_BUFFER_SERVICE_PROGRAM_MANAGER_H_ | 366 #endif // GPU_COMMAND_BUFFER_SERVICE_PROGRAM_MANAGER_H_ |
OLD | NEW |