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

Side by Side Diff: gpu/command_buffer/service/program_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_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>
11 #include "base/basictypes.h" 11 #include "base/basictypes.h"
12 #include "base/logging.h" 12 #include "base/logging.h"
13 #include "base/memory/ref_counted.h" 13 #include "base/memory/ref_counted.h"
14 #include "base/memory/scoped_ptr.h"
14 #include "gpu/command_buffer/service/common_decoder.h" 15 #include "gpu/command_buffer/service/common_decoder.h"
15 #include "gpu/command_buffer/service/gl_utils.h" 16 #include "gpu/command_buffer/service/gl_utils.h"
16 #include "gpu/command_buffer/service/shader_manager.h" 17 #include "gpu/command_buffer/service/shader_manager.h"
17 #include "gpu/gpu_export.h" 18 #include "gpu/gpu_export.h"
18 19
19 namespace gpu { 20 namespace gpu {
20 namespace gles2 { 21 namespace gles2 {
21 class ProgramCache;
22 class FeatureInfo;
23 22
24 // Tracks the Programs. 23 // Tracks the Programs.
25 // 24 //
26 // NOTE: To support shared resources an instance of this class will 25 // NOTE: To support shared resources an instance of this class will
27 // need to be shared by multiple GLES2Decoders. 26 // need to be shared by multiple GLES2Decoders.
28 class GPU_EXPORT ProgramManager { 27 class GPU_EXPORT ProgramManager {
29 public: 28 public:
30 typedef std::map<std::string, GLint> LocationMap;
31
32 // This is used to track which attributes a particular program needs 29 // This is used to track which attributes a particular program needs
33 // 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
34 // or if enabled that it points to a valid source. 31 // or if enabled that it points to a valid source.
35 class GPU_EXPORT ProgramInfo : public base::RefCounted<ProgramInfo> { 32 class GPU_EXPORT ProgramInfo : public base::RefCounted<ProgramInfo> {
36 public: 33 public:
37 typedef scoped_refptr<ProgramInfo> Ref; 34 typedef scoped_refptr<ProgramInfo> Ref;
38 35
39 static const int kMaxAttachedShaders = 2; 36 static const int kMaxAttachedShaders = 2;
40 37
41 struct UniformInfo { 38 struct UniformInfo {
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
146 bool IsValid() const { 143 bool IsValid() const {
147 return valid_; 144 return valid_;
148 } 145 }
149 146
150 bool AttachShader(ShaderManager* manager, ShaderManager::ShaderInfo* info); 147 bool AttachShader(ShaderManager* manager, ShaderManager::ShaderInfo* info);
151 bool DetachShader(ShaderManager* manager, ShaderManager::ShaderInfo* info); 148 bool DetachShader(ShaderManager* manager, ShaderManager::ShaderInfo* info);
152 149
153 bool CanLink() const; 150 bool CanLink() const;
154 151
155 // Performs glLinkProgram and related activities. 152 // Performs glLinkProgram and related activities.
156 bool Link(ShaderManager* manager, 153 bool Link();
157 ShaderTranslator* vertex_translator,
158 ShaderTranslator* fragment_shader,
159 FeatureInfo* feature_info);
160 154
161 // Performs glValidateProgram and related activities. 155 // Performs glValidateProgram and related activities.
162 void Validate(); 156 void Validate();
163 157
164 const std::string* log_info() const { 158 const std::string* log_info() const {
165 return log_info_.get(); 159 return log_info_.get();
166 } 160 }
167 161
168 bool InUse() const { 162 bool InUse() const {
169 DCHECK_GE(use_count_, 0); 163 DCHECK_GE(use_count_, 0);
170 return use_count_ != 0; 164 return use_count_ != 0;
171 } 165 }
172 166
173 // Sets attribute-location binding from a glBindAttribLocation() call. 167 // Sets attribute-location binding from a glBindAttribLocation() call.
174 void SetAttribLocationBinding(const std::string& attrib, GLint location) { 168 void SetAttribLocationBinding(const std::string& attrib, GLint location) {
175 bind_attrib_location_map_[attrib] = location; 169 bind_attrib_location_map_[attrib] = location;
176 } 170 }
177 171
178 // Sets uniform-location binding from a glBindUniformLocationCHROMIUM call. 172 // Sets uniform-location binding from a glBindUniformLocationCHROMIUM call.
179 // returns false if error. 173 // returns false if error.
180 bool SetUniformLocationBinding(const std::string& name, GLint location); 174 bool SetUniformLocationBinding(const std::string& name, GLint location);
181 175
182 // Detects if there are attribute location conflicts from 176 // Detects if there are attribute location conflicts from
183 // glBindAttribLocation() calls. 177 // glBindAttribLocation() calls.
184 // We only consider the declared attributes in the program. 178 // We only consider the declared attributes in the program.
185 bool DetectAttribLocationBindingConflicts() const; 179 bool DetectAttribLocationBindingConflicts() const;
186 180
187 // Visible for testing
188 const LocationMap& bind_attrib_location_map() const {
189 return bind_attrib_location_map_;
190 }
191
192 private: 181 private:
193 friend class base::RefCounted<ProgramInfo>; 182 friend class base::RefCounted<ProgramInfo>;
194 friend class ProgramManager; 183 friend class ProgramManager;
195 184
185 typedef std::map<std::string, GLint> LocationMap;
186
196 ~ProgramInfo(); 187 ~ProgramInfo();
197 188
198 void set_log_info(const char* str) { 189 void set_log_info(const char* str) {
199 log_info_.reset(str ? new std::string(str) : NULL); 190 log_info_.reset(str ? new std::string(str) : NULL);
200 } 191 }
201 192
202 void ClearLinkStatus() { 193 void ClearLinkStatus() {
203 link_status_ = false; 194 link_status_ = false;
204 } 195 }
205 196
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
301 // Log info 292 // Log info
302 scoped_ptr<std::string> log_info_; 293 scoped_ptr<std::string> log_info_;
303 294
304 // attribute-location binding map from glBindAttribLocation() calls. 295 // attribute-location binding map from glBindAttribLocation() calls.
305 LocationMap bind_attrib_location_map_; 296 LocationMap bind_attrib_location_map_;
306 297
307 // uniform-location binding map from glBindUniformLocationCHROMIUM() calls. 298 // uniform-location binding map from glBindUniformLocationCHROMIUM() calls.
308 LocationMap bind_uniform_location_map_; 299 LocationMap bind_uniform_location_map_;
309 }; 300 };
310 301
311 explicit ProgramManager(ProgramCache* program_cache); 302 ProgramManager();
312 ~ProgramManager(); 303 ~ProgramManager();
313 304
314 // Must call before destruction. 305 // Must call before destruction.
315 void Destroy(bool have_context); 306 void Destroy(bool have_context);
316 307
317 // Creates a new program info. 308 // Creates a new program info.
318 ProgramInfo* CreateProgramInfo(GLuint client_id, GLuint service_id); 309 ProgramInfo* CreateProgramInfo(GLuint client_id, GLuint service_id);
319 310
320 // Gets a program info 311 // Gets a program info
321 ProgramInfo* GetProgramInfo(GLuint client_id); 312 ProgramInfo* GetProgramInfo(GLuint client_id);
322 313
323 // Gets a client id for a given service id. 314 // Gets a client id for a given service id.
324 bool GetClientId(GLuint service_id, GLuint* client_id) const; 315 bool GetClientId(GLuint service_id, GLuint* client_id) const;
325 316
326 // Gets the shader cache
327 ProgramCache* program_cache() const;
328
329 // Marks a program as deleted. If it is not used the info will be deleted. 317 // Marks a program as deleted. If it is not used the info will be deleted.
330 void MarkAsDeleted(ShaderManager* shader_manager, ProgramInfo* info); 318 void MarkAsDeleted(ShaderManager* shader_manager, ProgramInfo* info);
331 319
332 // Marks a program as used. 320 // Marks a program as used.
333 void UseProgram(ProgramInfo* info); 321 void UseProgram(ProgramInfo* info);
334 322
335 // Makes a program as unused. If deleted the program info will be removed. 323 // Makes a program as unused. If deleted the program info will be removed.
336 void UnuseProgram(ShaderManager* shader_manager, ProgramInfo* info); 324 void UnuseProgram(ShaderManager* shader_manager, ProgramInfo* info);
337 325
338 // Clears the uniforms for this program. 326 // Clears the uniforms for this program.
339 void ClearUniforms(ProgramInfo* info); 327 void ClearUniforms(ProgramInfo* info);
340 328
341 // Returns true if prefix is invalid for gl. 329 // Returns true if prefix is invalid for gl.
342 static bool IsInvalidPrefix(const char* name, size_t length); 330 static bool IsInvalidPrefix(const char* name, size_t length);
343 331
344 // Check if a ProgramInfo is owned by this ProgramManager. 332 // Check if a ProgramInfo is owned by this ProgramManager.
345 bool IsOwned(ProgramInfo* info); 333 bool IsOwned(ProgramInfo* info);
346 334
347 static int32 MakeFakeLocation(int32 index, int32 element); 335 static int32 MakeFakeLocation(int32 index, int32 element);
348 336
349 // Cache-aware shader compiling. If no cache or if the shader wasn't
350 // previously compiled, ForceCompileShader is called
351 void DoCompileShader(ShaderManager::ShaderInfo* info,
352 ShaderTranslator* translator,
353 FeatureInfo* feature_info);
354
355 private: 337 private:
356 // Actually compiles the shader
357 void ForceCompileShader(const std::string* source,
358 ShaderManager::ShaderInfo* info,
359 ShaderTranslator* translator,
360 FeatureInfo* feature_info);
361
362 void StartTracking(ProgramInfo* info); 338 void StartTracking(ProgramInfo* info);
363 void StopTracking(ProgramInfo* info); 339 void StopTracking(ProgramInfo* info);
364 340
365 // Info for each "successfully linked" program by service side program Id. 341 // Info for each "successfully linked" program by service side program Id.
366 // TODO(gman): Choose a faster container. 342 // TODO(gman): Choose a faster container.
367 typedef std::map<GLuint, ProgramInfo::Ref> ProgramInfoMap; 343 typedef std::map<GLuint, ProgramInfo::Ref> ProgramInfoMap;
368 ProgramInfoMap program_infos_; 344 ProgramInfoMap program_infos_;
369 345
370 // Counts the number of ProgramInfo allocated with 'this' as its manager. 346 // Counts the number of ProgramInfo allocated with 'this' as its manager.
371 // Allows to check no ProgramInfo will outlive this. 347 // Allows to check no ProgramInfo will outlive this.
372 unsigned int program_info_count_; 348 unsigned int program_info_count_;
373 349
374 bool have_context_; 350 bool have_context_;
375 351
376 bool disable_workarounds_; 352 bool disable_workarounds_;
377 353
378 // Used to clear uniforms. 354 // Used to clear uniforms.
379 std::vector<uint8> zero_; 355 std::vector<uint8> zero_;
380 356
381 ProgramCache* program_cache_;
382
383 void RemoveProgramInfoIfUnused( 357 void RemoveProgramInfoIfUnused(
384 ShaderManager* shader_manager, ProgramInfo* info); 358 ShaderManager* shader_manager, ProgramInfo* info);
385 359
386 DISALLOW_COPY_AND_ASSIGN(ProgramManager); 360 DISALLOW_COPY_AND_ASSIGN(ProgramManager);
387 }; 361 };
388 362
389 } // namespace gles2 363 } // namespace gles2
390 } // namespace gpu 364 } // namespace gpu
391 365
392 #endif // GPU_COMMAND_BUFFER_SERVICE_PROGRAM_MANAGER_H_ 366 #endif // GPU_COMMAND_BUFFER_SERVICE_PROGRAM_MANAGER_H_
OLDNEW
« no previous file with comments | « gpu/command_buffer/service/program_cache_unittest.cc ('k') | gpu/command_buffer/service/program_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698