Chromium Code Reviews

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

Issue 5676003: Make shader and program object lifetimes match OpenGL ES spec.... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 10 years ago
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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/ref_counted.h" 13 #include "base/ref_counted.h"
13 #include "gpu/command_buffer/service/gl_utils.h" 14 #include "gpu/command_buffer/service/gl_utils.h"
14 #include "gpu/command_buffer/service/shader_manager.h" 15 #include "gpu/command_buffer/service/shader_manager.h"
15 16
16 namespace gpu { 17 namespace gpu {
17 namespace gles2 { 18 namespace gles2 {
18 19
19 // Tracks the Programs. 20 // Tracks the Programs.
20 // 21 //
21 // NOTE: To support shared resources an instance of this class will 22 // NOTE: To support shared resources an instance of this class will
(...skipping 101 matching lines...)
123 bool IsDeleted() const { 124 bool IsDeleted() const {
124 return service_id_ == 0; 125 return service_id_ == 0;
125 } 126 }
126 127
127 void GetProgramiv(GLenum pname, GLint* params); 128 void GetProgramiv(GLenum pname, GLint* params);
128 129
129 bool IsValid() const { 130 bool IsValid() const {
130 return valid_; 131 return valid_;
131 } 132 }
132 133
133 bool AttachShader(ShaderManager::ShaderInfo* info); 134 bool AttachShader(ShaderManager* manager, ShaderManager::ShaderInfo* info);
134 void DetachShader(ShaderManager::ShaderInfo* info); 135 void DetachShader(ShaderManager* manager, ShaderManager::ShaderInfo* info);
135 136
136 bool CanLink() const; 137 bool CanLink() const;
137 138
138 const std::string& log_info() const { 139 const std::string& log_info() const {
139 return log_info_; 140 return log_info_;
140 } 141 }
141 142
142 void set_log_info(const std::string& str) { 143 void set_log_info(const std::string& str) {
143 log_info_ = str; 144 log_info_ = str;
144 } 145 }
145 146
147 bool InUse() const {
148 DCHECK_GE(use_count_, 0);
149 return use_count_ != 0;
150 }
151
146 private: 152 private:
147 friend class base::RefCounted<ProgramInfo>; 153 friend class base::RefCounted<ProgramInfo>;
148 friend class ProgramManager; 154 friend class ProgramManager;
149 155
150 ~ProgramInfo(); 156 ~ProgramInfo();
151 157
158 void IncUseCount() {
159 ++use_count_;
160 }
161
162 void DecUseCount() {
163 --use_count_;
164 DCHECK_GE(use_count_, 0);
165 }
166
152 void MarkAsDeleted() { 167 void MarkAsDeleted() {
168 DCHECK_NE(service_id_, 0u);
153 service_id_ = 0; 169 service_id_ = 0;
154 } 170 }
155 171
156 const UniformInfo* AddUniformInfo( 172 const UniformInfo* AddUniformInfo(
157 GLsizei size, GLenum type, GLint location, const std::string& name); 173 GLsizei size, GLenum type, GLint location, const std::string& name);
158 174
159 void GetCorrectedVariableInfo( 175 void GetCorrectedVariableInfo(
160 bool use_uniforms, const std::string& name, std::string* corrected_name, 176 bool use_uniforms, const std::string& name, std::string* corrected_name,
161 GLsizei* size, GLenum* type) const; 177 GLsizei* size, GLenum* type) const;
162 178
179 void DetachShaders(ShaderManager* manager);
180
181 int use_count_;
182
163 GLsizei max_attrib_name_length_; 183 GLsizei max_attrib_name_length_;
164 184
165 // Attrib by index. 185 // Attrib by index.
166 AttribInfoVector attrib_infos_; 186 AttribInfoVector attrib_infos_;
167 187
168 // Attrib by location to index. 188 // Attrib by location to index.
169 std::vector<GLint> attrib_location_to_index_map_; 189 std::vector<GLint> attrib_location_to_index_map_;
170 190
171 GLsizei max_uniform_name_length_; 191 GLsizei max_uniform_name_length_;
172 192
(...skipping 24 matching lines...)
197 217
198 // Must call before destruction. 218 // Must call before destruction.
199 void Destroy(bool have_context); 219 void Destroy(bool have_context);
200 220
201 // Creates a new program info. 221 // Creates a new program info.
202 void CreateProgramInfo(GLuint client_id, GLuint service_id); 222 void CreateProgramInfo(GLuint client_id, GLuint service_id);
203 223
204 // Gets a program info 224 // Gets a program info
205 ProgramInfo* GetProgramInfo(GLuint client_id); 225 ProgramInfo* GetProgramInfo(GLuint client_id);
206 226
207 // Deletes the program info for the given program.
208 void RemoveProgramInfo(GLuint client_id);
209
210 // Gets a client id for a given service id. 227 // Gets a client id for a given service id.
211 bool GetClientId(GLuint service_id, GLuint* client_id) const; 228 bool GetClientId(GLuint service_id, GLuint* client_id) const;
212 229
230 // Marks a program as deleted. If it is not used the info will be deleted.
231 void MarkAsDeleted(ShaderManager* shader_manager, ProgramInfo* info);
232
233 // Marks a program as used.
234 void UseProgram(ProgramInfo* info);
235
236 // Makes a program as unused. If deleted the program info will be removed.
237 void UnuseProgram(ShaderManager* shader_manager, ProgramInfo* info);
238
213 // Returns true if prefix is invalid for gl. 239 // Returns true if prefix is invalid for gl.
214 static bool IsInvalidPrefix(const char* name, size_t length); 240 static bool IsInvalidPrefix(const char* name, size_t length);
215 241
216 private: 242 private:
217 // Info for each "successfully linked" program by service side program Id. 243 // Info for each "successfully linked" program by service side program Id.
218 // TODO(gman): Choose a faster container. 244 // TODO(gman): Choose a faster container.
219 typedef std::map<GLuint, ProgramInfo::Ref> ProgramInfoMap; 245 typedef std::map<GLuint, ProgramInfo::Ref> ProgramInfoMap;
220 ProgramInfoMap program_infos_; 246 ProgramInfoMap program_infos_;
221 247
248 void RemoveProgramInfoIfUnused(
249 ShaderManager* shader_manager, ProgramInfo* info);
250
222 DISALLOW_COPY_AND_ASSIGN(ProgramManager); 251 DISALLOW_COPY_AND_ASSIGN(ProgramManager);
223 }; 252 };
224 253
225 } // namespace gles2 254 } // namespace gles2
226 } // namespace gpu 255 } // namespace gpu
227 256
228 #endif // GPU_COMMAND_BUFFER_SERVICE_PROGRAM_MANAGER_H_ 257 #endif // GPU_COMMAND_BUFFER_SERVICE_PROGRAM_MANAGER_H_
OLDNEW
« no previous file with comments | « gpu/command_buffer/service/gles2_cmd_decoder_unittest_1.cc ('k') | gpu/command_buffer/service/program_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine