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 #include "gpu/command_buffer/client/program_info_manager.h" | 5 #include "gpu/command_buffer/client/program_info_manager.h" |
6 | 6 |
7 #include <string> | 7 namespace { |
8 | 8 |
9 #include "base/compiler_specific.h" | 9 template<typename T> static T LocalGetAs( |
10 #include "base/containers/hash_tables.h" | 10 const std::vector<int8>& data, uint32 offset, size_t size) { |
11 #include "base/synchronization/lock.h" | 11 const int8* p = &data[0] + offset; |
12 #include "gpu/command_buffer/client/gles2_implementation.h" | 12 if (offset + size > data.size()) { |
13 #include "gpu/command_buffer/common/gles2_cmd_utils.h" | 13 NOTREACHED(); |
| 14 return NULL; |
| 15 } |
| 16 return static_cast<T>(static_cast<const void*>(p)); |
| 17 } |
| 18 |
| 19 } // namespace anonymous |
14 | 20 |
15 namespace gpu { | 21 namespace gpu { |
16 namespace gles2 { | 22 namespace gles2 { |
17 | 23 |
18 class NonCachedProgramInfoManager : public ProgramInfoManager { | 24 ProgramInfoManager::Program::VertexAttrib::VertexAttrib( |
19 public: | 25 GLsizei _size, GLenum _type, const std::string& _name, GLint _location) |
20 NonCachedProgramInfoManager(); | 26 : size(_size), |
21 ~NonCachedProgramInfoManager() override; | 27 type(_type), |
22 | 28 location(_location), |
23 void CreateInfo(GLuint program) override; | 29 name(_name) { |
24 | |
25 void DeleteInfo(GLuint program) override; | |
26 | |
27 bool GetProgramiv(GLES2Implementation* gl, | |
28 GLuint program, | |
29 GLenum pname, | |
30 GLint* params) override; | |
31 | |
32 GLint GetAttribLocation(GLES2Implementation* gl, | |
33 GLuint program, | |
34 const char* name) override; | |
35 | |
36 GLint GetUniformLocation(GLES2Implementation* gl, | |
37 GLuint program, | |
38 const char* name) override; | |
39 | |
40 GLint GetFragDataLocation(GLES2Implementation* gl, | |
41 GLuint program, | |
42 const char* name) override; | |
43 | |
44 bool GetActiveAttrib(GLES2Implementation* gl, | |
45 GLuint program, | |
46 GLuint index, | |
47 GLsizei bufsize, | |
48 GLsizei* length, | |
49 GLint* size, | |
50 GLenum* type, | |
51 char* name) override; | |
52 | |
53 bool GetActiveUniform(GLES2Implementation* gl, | |
54 GLuint program, | |
55 GLuint index, | |
56 GLsizei bufsize, | |
57 GLsizei* length, | |
58 GLint* size, | |
59 GLenum* type, | |
60 char* name) override; | |
61 }; | |
62 | |
63 NonCachedProgramInfoManager::NonCachedProgramInfoManager() { | |
64 } | 30 } |
65 | 31 |
66 NonCachedProgramInfoManager::~NonCachedProgramInfoManager() { | 32 ProgramInfoManager::Program::VertexAttrib::~VertexAttrib() { |
67 } | 33 } |
68 | 34 |
69 void NonCachedProgramInfoManager::CreateInfo(GLuint /* program */) { | 35 ProgramInfoManager::Program::UniformInfo::UniformInfo( |
70 } | |
71 | |
72 void NonCachedProgramInfoManager::DeleteInfo(GLuint /* program */) { | |
73 } | |
74 | |
75 bool NonCachedProgramInfoManager::GetProgramiv( | |
76 GLES2Implementation* /* gl */, | |
77 GLuint /* program */, | |
78 GLenum /* pname */, | |
79 GLint* /* params */) { | |
80 return false; | |
81 } | |
82 | |
83 GLint NonCachedProgramInfoManager::GetAttribLocation( | |
84 GLES2Implementation* gl, GLuint program, const char* name) { | |
85 return gl->GetAttribLocationHelper(program, name); | |
86 } | |
87 | |
88 GLint NonCachedProgramInfoManager::GetUniformLocation( | |
89 GLES2Implementation* gl, GLuint program, const char* name) { | |
90 return gl->GetUniformLocationHelper(program, name); | |
91 } | |
92 | |
93 GLint NonCachedProgramInfoManager::GetFragDataLocation( | |
94 GLES2Implementation* gl, GLuint program, const char* name) { | |
95 return gl->GetFragDataLocationHelper(program, name); | |
96 } | |
97 | |
98 bool NonCachedProgramInfoManager::GetActiveAttrib( | |
99 GLES2Implementation* gl, | |
100 GLuint program, GLuint index, GLsizei bufsize, GLsizei* length, | |
101 GLint* size, GLenum* type, char* name) { | |
102 return gl->GetActiveAttribHelper( | |
103 program, index, bufsize, length, size, type, name); | |
104 } | |
105 | |
106 bool NonCachedProgramInfoManager::GetActiveUniform( | |
107 GLES2Implementation* gl, | |
108 GLuint program, GLuint index, GLsizei bufsize, GLsizei* length, | |
109 GLint* size, GLenum* type, char* name) { | |
110 return gl->GetActiveUniformHelper( | |
111 program, index, bufsize, length, size, type, name); | |
112 } | |
113 | |
114 class CachedProgramInfoManager : public ProgramInfoManager { | |
115 public: | |
116 CachedProgramInfoManager(); | |
117 ~CachedProgramInfoManager() override; | |
118 | |
119 void CreateInfo(GLuint program) override; | |
120 | |
121 void DeleteInfo(GLuint program) override; | |
122 | |
123 bool GetProgramiv(GLES2Implementation* gl, | |
124 GLuint program, | |
125 GLenum pname, | |
126 GLint* params) override; | |
127 | |
128 GLint GetAttribLocation(GLES2Implementation* gl, | |
129 GLuint program, | |
130 const char* name) override; | |
131 | |
132 GLint GetUniformLocation(GLES2Implementation* gl, | |
133 GLuint program, | |
134 const char* name) override; | |
135 | |
136 GLint GetFragDataLocation(GLES2Implementation* gl, | |
137 GLuint program, | |
138 const char* name) override; | |
139 | |
140 bool GetActiveAttrib(GLES2Implementation* gl, | |
141 GLuint program, | |
142 GLuint index, | |
143 GLsizei bufsize, | |
144 GLsizei* length, | |
145 GLint* size, | |
146 GLenum* type, | |
147 char* name) override; | |
148 | |
149 bool GetActiveUniform(GLES2Implementation* gl, | |
150 GLuint program, | |
151 GLuint index, | |
152 GLsizei bufsize, | |
153 GLsizei* length, | |
154 GLint* size, | |
155 GLenum* type, | |
156 char* name) override; | |
157 | |
158 private: | |
159 class Program { | |
160 public: | |
161 struct UniformInfo { | |
162 UniformInfo(GLsizei _size, GLenum _type, const std::string& _name); | |
163 | |
164 GLsizei size; | |
165 GLenum type; | |
166 bool is_array; | |
167 std::string name; | |
168 std::vector<GLint> element_locations; | |
169 }; | |
170 struct VertexAttrib { | |
171 VertexAttrib(GLsizei _size, GLenum _type, const std::string& _name, | |
172 GLint _location) | |
173 : size(_size), | |
174 type(_type), | |
175 location(_location), | |
176 name(_name) { | |
177 } | |
178 GLsizei size; | |
179 GLenum type; | |
180 GLint location; | |
181 std::string name; | |
182 }; | |
183 | |
184 typedef std::vector<UniformInfo> UniformInfoVector; | |
185 typedef std::vector<VertexAttrib> AttribInfoVector; | |
186 | |
187 Program(); | |
188 | |
189 const AttribInfoVector& GetAttribInfos() const { | |
190 return attrib_infos_; | |
191 } | |
192 | |
193 const VertexAttrib* GetAttribInfo(GLint index) const { | |
194 return (static_cast<size_t>(index) < attrib_infos_.size()) ? | |
195 &attrib_infos_[index] : NULL; | |
196 } | |
197 | |
198 GLint GetAttribLocation(const std::string& name) const; | |
199 | |
200 const UniformInfo* GetUniformInfo(GLint index) const { | |
201 return (static_cast<size_t>(index) < uniform_infos_.size()) ? | |
202 &uniform_infos_[index] : NULL; | |
203 } | |
204 | |
205 // Gets the location of a uniform by name. | |
206 GLint GetUniformLocation(const std::string& name) const; | |
207 | |
208 GLint GetFragDataLocation(const std::string& name) const; | |
209 void CacheFragDataLocation(const std::string& name, GLint loc); | |
210 | |
211 bool GetProgramiv(GLenum pname, GLint* params); | |
212 | |
213 // Updates the program info after a successful link. | |
214 void Update(GLES2Implementation* gl, | |
215 GLuint program, | |
216 const std::vector<int8>& result); | |
217 | |
218 bool cached() const { return cached_; } | |
219 | |
220 private: | |
221 bool cached_; | |
222 | |
223 GLsizei max_attrib_name_length_; | |
224 | |
225 // Attrib by index. | |
226 AttribInfoVector attrib_infos_; | |
227 | |
228 GLsizei max_uniform_name_length_; | |
229 | |
230 // Uniform info by index. | |
231 UniformInfoVector uniform_infos_; | |
232 | |
233 base::hash_map<std::string, GLint> frag_data_locations_; | |
234 | |
235 // This is true if glLinkProgram was successful last time it was called. | |
236 bool link_status_; | |
237 }; | |
238 | |
239 Program* GetProgramInfo(GLES2Implementation* gl, GLuint program); | |
240 | |
241 typedef base::hash_map<GLuint, Program> ProgramInfoMap; | |
242 | |
243 ProgramInfoMap program_infos_; | |
244 | |
245 mutable base::Lock lock_; | |
246 }; | |
247 | |
248 CachedProgramInfoManager::Program::UniformInfo::UniformInfo( | |
249 GLsizei _size, GLenum _type, const std::string& _name) | 36 GLsizei _size, GLenum _type, const std::string& _name) |
250 : size(_size), | 37 : size(_size), |
251 type(_type), | 38 type(_type), |
252 name(_name) { | 39 name(_name) { |
253 is_array = (!name.empty() && name[name.size() - 1] == ']'); | 40 is_array = (!name.empty() && name[name.size() - 1] == ']'); |
254 DCHECK(!(size > 1 && !is_array)); | 41 DCHECK(!(size > 1 && !is_array)); |
255 } | 42 } |
256 | 43 |
257 CachedProgramInfoManager::Program::Program() | 44 ProgramInfoManager::Program::UniformInfo::~UniformInfo() { |
| 45 } |
| 46 |
| 47 ProgramInfoManager::Program::Program() |
258 : cached_(false), | 48 : cached_(false), |
259 max_attrib_name_length_(0), | 49 max_attrib_name_length_(0), |
260 max_uniform_name_length_(0), | 50 max_uniform_name_length_(0), |
261 link_status_(false) { | 51 link_status_(false) { |
262 } | 52 } |
263 | 53 |
| 54 ProgramInfoManager::Program::~Program() { |
| 55 } |
| 56 |
264 // TODO(gman): Add a faster lookup. | 57 // TODO(gman): Add a faster lookup. |
265 GLint CachedProgramInfoManager::Program::GetAttribLocation( | 58 GLint ProgramInfoManager::Program::GetAttribLocation( |
266 const std::string& name) const { | 59 const std::string& name) const { |
267 for (GLuint ii = 0; ii < attrib_infos_.size(); ++ii) { | 60 for (GLuint ii = 0; ii < attrib_infos_.size(); ++ii) { |
268 const VertexAttrib& info = attrib_infos_[ii]; | 61 const VertexAttrib& info = attrib_infos_[ii]; |
269 if (info.name == name) { | 62 if (info.name == name) { |
270 return info.location; | 63 return info.location; |
271 } | 64 } |
272 } | 65 } |
273 return -1; | 66 return -1; |
274 } | 67 } |
275 | 68 |
276 GLint CachedProgramInfoManager::Program::GetUniformLocation( | 69 const ProgramInfoManager::Program::VertexAttrib* |
| 70 ProgramInfoManager::Program::GetAttribInfo(GLint index) const { |
| 71 return (static_cast<size_t>(index) < attrib_infos_.size()) ? |
| 72 &attrib_infos_[index] : NULL; |
| 73 } |
| 74 |
| 75 const ProgramInfoManager::Program::UniformInfo* |
| 76 ProgramInfoManager::Program::GetUniformInfo(GLint index) const { |
| 77 return (static_cast<size_t>(index) < uniform_infos_.size()) ? |
| 78 &uniform_infos_[index] : NULL; |
| 79 } |
| 80 |
| 81 GLint ProgramInfoManager::Program::GetUniformLocation( |
277 const std::string& name) const { | 82 const std::string& name) const { |
278 bool getting_array_location = false; | 83 bool getting_array_location = false; |
279 size_t open_pos = std::string::npos; | 84 size_t open_pos = std::string::npos; |
280 int index = 0; | 85 int index = 0; |
281 if (!GLES2Util::ParseUniformName( | 86 if (!GLES2Util::ParseUniformName( |
282 name, &open_pos, &index, &getting_array_location)) { | 87 name, &open_pos, &index, &getting_array_location)) { |
283 return -1; | 88 return -1; |
284 } | 89 } |
285 for (GLuint ii = 0; ii < uniform_infos_.size(); ++ii) { | 90 for (GLuint ii = 0; ii < uniform_infos_.size(); ++ii) { |
286 const UniformInfo& info = uniform_infos_[ii]; | 91 const UniformInfo& info = uniform_infos_[ii]; |
287 if (info.name == name || | 92 if (info.name == name || |
288 (info.is_array && | 93 (info.is_array && |
289 info.name.compare(0, info.name.size() - 3, name) == 0)) { | 94 info.name.compare(0, info.name.size() - 3, name) == 0)) { |
290 return info.element_locations[0]; | 95 return info.element_locations[0]; |
291 } else if (getting_array_location && info.is_array) { | 96 } else if (getting_array_location && info.is_array) { |
292 // Look for an array specification. | 97 // Look for an array specification. |
293 size_t open_pos_2 = info.name.find_last_of('['); | 98 size_t open_pos_2 = info.name.find_last_of('['); |
294 if (open_pos_2 == open_pos && | 99 if (open_pos_2 == open_pos && |
295 name.compare(0, open_pos, info.name, 0, open_pos) == 0) { | 100 name.compare(0, open_pos, info.name, 0, open_pos) == 0) { |
296 if (index >= 0 && index < info.size) { | 101 if (index >= 0 && index < info.size) { |
297 return info.element_locations[index]; | 102 return info.element_locations[index]; |
298 } | 103 } |
299 } | 104 } |
300 } | 105 } |
301 } | 106 } |
302 return -1; | 107 return -1; |
303 } | 108 } |
304 | 109 |
305 GLint CachedProgramInfoManager::Program::GetFragDataLocation( | 110 GLint ProgramInfoManager::Program::GetFragDataLocation( |
306 const std::string& name) const { | 111 const std::string& name) const { |
307 base::hash_map<std::string, GLint>::const_iterator iter = | 112 base::hash_map<std::string, GLint>::const_iterator iter = |
308 frag_data_locations_.find(name); | 113 frag_data_locations_.find(name); |
309 if (iter == frag_data_locations_.end()) | 114 if (iter == frag_data_locations_.end()) |
310 return -1; | 115 return -1; |
311 return iter->second; | 116 return iter->second; |
312 } | 117 } |
313 | 118 |
314 void CachedProgramInfoManager::Program::CacheFragDataLocation( | 119 void ProgramInfoManager::Program::CacheFragDataLocation( |
315 const std::string& name, GLint loc) { | 120 const std::string& name, GLint loc) { |
316 frag_data_locations_[name] = loc; | 121 frag_data_locations_[name] = loc; |
317 } | 122 } |
318 | 123 |
319 bool CachedProgramInfoManager::Program::GetProgramiv( | 124 bool ProgramInfoManager::Program::GetProgramiv( |
320 GLenum pname, GLint* params) { | 125 GLenum pname, GLint* params) { |
321 switch (pname) { | 126 switch (pname) { |
322 case GL_LINK_STATUS: | 127 case GL_LINK_STATUS: |
323 *params = link_status_; | 128 *params = link_status_; |
324 return true; | 129 return true; |
325 case GL_ACTIVE_ATTRIBUTES: | 130 case GL_ACTIVE_ATTRIBUTES: |
326 *params = attrib_infos_.size(); | 131 *params = attrib_infos_.size(); |
327 return true; | 132 return true; |
328 case GL_ACTIVE_ATTRIBUTE_MAX_LENGTH: | 133 case GL_ACTIVE_ATTRIBUTE_MAX_LENGTH: |
329 *params = max_attrib_name_length_; | 134 *params = max_attrib_name_length_; |
330 return true; | 135 return true; |
331 case GL_ACTIVE_UNIFORMS: | 136 case GL_ACTIVE_UNIFORMS: |
332 *params = uniform_infos_.size(); | 137 *params = uniform_infos_.size(); |
333 return true; | 138 return true; |
334 case GL_ACTIVE_UNIFORM_MAX_LENGTH: | 139 case GL_ACTIVE_UNIFORM_MAX_LENGTH: |
335 *params = max_uniform_name_length_; | 140 *params = max_uniform_name_length_; |
336 return true; | 141 return true; |
337 default: | 142 default: |
338 break; | 143 break; |
339 } | 144 } |
340 return false; | 145 return false; |
341 } | 146 } |
342 | 147 |
343 template<typename T> static T LocalGetAs( | 148 void ProgramInfoManager::Program::Update( |
344 const std::vector<int8>& data, uint32 offset, size_t size) { | |
345 const int8* p = &data[0] + offset; | |
346 if (offset + size > data.size()) { | |
347 NOTREACHED(); | |
348 return NULL; | |
349 } | |
350 return static_cast<T>(static_cast<const void*>(p)); | |
351 } | |
352 | |
353 void CachedProgramInfoManager::Program::Update( | |
354 GLES2Implementation* gl, | 149 GLES2Implementation* gl, |
355 GLuint program, | 150 GLuint program, |
356 const std::vector<int8>& result) { | 151 const std::vector<int8>& result) { |
357 if (cached_) { | 152 if (cached_) { |
358 return; | 153 return; |
359 } | 154 } |
360 if (result.empty()) { | 155 if (result.empty()) { |
361 // This should only happen on a lost context. | 156 // This should only happen on a lost context. |
362 return; | 157 return; |
363 } | 158 } |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
402 info.element_locations.push_back(locations[jj]); | 197 info.element_locations.push_back(locations[jj]); |
403 } | 198 } |
404 uniform_infos_.push_back(info); | 199 uniform_infos_.push_back(info); |
405 ++input; | 200 ++input; |
406 } | 201 } |
407 DCHECK_EQ(header->num_attribs + header->num_uniforms, | 202 DCHECK_EQ(header->num_attribs + header->num_uniforms, |
408 static_cast<uint32>(input - inputs)); | 203 static_cast<uint32>(input - inputs)); |
409 cached_ = true; | 204 cached_ = true; |
410 } | 205 } |
411 | 206 |
412 CachedProgramInfoManager::CachedProgramInfoManager() { | 207 bool ProgramInfoManager::Program::cached() const { |
| 208 return cached_; |
413 } | 209 } |
414 | 210 |
415 CachedProgramInfoManager::~CachedProgramInfoManager() { | |
416 | 211 |
| 212 ProgramInfoManager::ProgramInfoManager() { |
417 } | 213 } |
418 | 214 |
419 CachedProgramInfoManager::Program* | 215 ProgramInfoManager::~ProgramInfoManager() { |
420 CachedProgramInfoManager::GetProgramInfo( | 216 } |
421 GLES2Implementation* gl, GLuint program) { | 217 |
| 218 ProgramInfoManager::Program* ProgramInfoManager::GetProgramInfo( |
| 219 GLES2Implementation* gl, GLuint program) { |
422 lock_.AssertAcquired(); | 220 lock_.AssertAcquired(); |
423 ProgramInfoMap::iterator it = program_infos_.find(program); | 221 ProgramInfoMap::iterator it = program_infos_.find(program); |
424 if (it == program_infos_.end()) { | 222 if (it == program_infos_.end()) { |
425 return NULL; | 223 return NULL; |
426 } | 224 } |
427 Program* info = &it->second; | 225 Program* info = &it->second; |
428 if (info->cached()) | 226 if (info->cached()) |
429 return info; | 227 return info; |
430 std::vector<int8> result; | 228 std::vector<int8> result; |
431 { | 229 { |
432 base::AutoUnlock unlock(lock_); | 230 base::AutoUnlock unlock(lock_); |
433 // lock_ can't be held across IPC call or else it may deadlock in pepper. | 231 // lock_ can't be held across IPC call or else it may deadlock in pepper. |
434 // http://crbug.com/418651 | 232 // http://crbug.com/418651 |
435 gl->GetProgramInfoCHROMIUMHelper(program, &result); | 233 gl->GetProgramInfoCHROMIUMHelper(program, &result); |
436 } | 234 } |
437 | 235 |
438 it = program_infos_.find(program); | 236 it = program_infos_.find(program); |
439 if (it == program_infos_.end()) { | 237 if (it == program_infos_.end()) { |
440 return NULL; | 238 return NULL; |
441 } | 239 } |
442 info = &it->second; | 240 info = &it->second; |
443 info->Update(gl, program, result); | 241 info->Update(gl, program, result); |
444 return info; | 242 return info; |
445 } | 243 } |
446 | 244 |
447 void CachedProgramInfoManager::CreateInfo(GLuint program) { | 245 void ProgramInfoManager::CreateInfo(GLuint program) { |
448 base::AutoLock auto_lock(lock_); | 246 base::AutoLock auto_lock(lock_); |
449 program_infos_.erase(program); | 247 program_infos_.erase(program); |
450 std::pair<ProgramInfoMap::iterator, bool> result = | 248 std::pair<ProgramInfoMap::iterator, bool> result = |
451 program_infos_.insert(std::make_pair(program, Program())); | 249 program_infos_.insert(std::make_pair(program, Program())); |
452 | 250 |
453 DCHECK(result.second); | 251 DCHECK(result.second); |
454 } | 252 } |
455 | 253 |
456 void CachedProgramInfoManager::DeleteInfo(GLuint program) { | 254 void ProgramInfoManager::DeleteInfo(GLuint program) { |
457 base::AutoLock auto_lock(lock_); | 255 base::AutoLock auto_lock(lock_); |
458 program_infos_.erase(program); | 256 program_infos_.erase(program); |
459 } | 257 } |
460 | 258 |
461 bool CachedProgramInfoManager::GetProgramiv( | 259 bool ProgramInfoManager::GetProgramiv( |
462 GLES2Implementation* gl, GLuint program, GLenum pname, GLint* params) { | 260 GLES2Implementation* gl, GLuint program, GLenum pname, GLint* params) { |
463 base::AutoLock auto_lock(lock_); | 261 base::AutoLock auto_lock(lock_); |
464 Program* info = GetProgramInfo(gl, program); | 262 Program* info = GetProgramInfo(gl, program); |
465 if (!info) { | 263 if (!info) { |
466 return false; | 264 return false; |
467 } | 265 } |
468 return info->GetProgramiv(pname, params); | 266 return info->GetProgramiv(pname, params); |
469 } | 267 } |
470 | 268 |
471 GLint CachedProgramInfoManager::GetAttribLocation( | 269 GLint ProgramInfoManager::GetAttribLocation( |
472 GLES2Implementation* gl, GLuint program, const char* name) { | 270 GLES2Implementation* gl, GLuint program, const char* name) { |
473 { | 271 { |
474 base::AutoLock auto_lock(lock_); | 272 base::AutoLock auto_lock(lock_); |
475 Program* info = GetProgramInfo(gl, program); | 273 Program* info = GetProgramInfo(gl, program); |
476 if (info) { | 274 if (info) { |
477 return info->GetAttribLocation(name); | 275 return info->GetAttribLocation(name); |
478 } | 276 } |
479 } | 277 } |
480 return gl->GetAttribLocationHelper(program, name); | 278 return gl->GetAttribLocationHelper(program, name); |
481 } | 279 } |
482 | 280 |
483 GLint CachedProgramInfoManager::GetUniformLocation( | 281 GLint ProgramInfoManager::GetUniformLocation( |
484 GLES2Implementation* gl, GLuint program, const char* name) { | 282 GLES2Implementation* gl, GLuint program, const char* name) { |
485 { | 283 { |
486 base::AutoLock auto_lock(lock_); | 284 base::AutoLock auto_lock(lock_); |
487 Program* info = GetProgramInfo(gl, program); | 285 Program* info = GetProgramInfo(gl, program); |
488 if (info) { | 286 if (info) { |
489 return info->GetUniformLocation(name); | 287 return info->GetUniformLocation(name); |
490 } | 288 } |
491 } | 289 } |
492 return gl->GetUniformLocationHelper(program, name); | 290 return gl->GetUniformLocationHelper(program, name); |
493 } | 291 } |
494 | 292 |
495 GLint CachedProgramInfoManager::GetFragDataLocation( | 293 GLint ProgramInfoManager::GetFragDataLocation( |
496 GLES2Implementation* gl, GLuint program, const char* name) { | 294 GLES2Implementation* gl, GLuint program, const char* name) { |
497 // TODO(zmo): make FragData locations part of the ProgramInfo that are | 295 // TODO(zmo): make FragData locations part of the ProgramInfo that are |
498 // fetched altogether from the service side. See crbug.com/452104. | 296 // fetched altogether from the service side. See crbug.com/452104. |
499 { | 297 { |
500 base::AutoLock auto_lock(lock_); | 298 base::AutoLock auto_lock(lock_); |
501 Program* info = GetProgramInfo(gl, program); | 299 Program* info = GetProgramInfo(gl, program); |
502 if (info) { | 300 if (info) { |
503 GLint possible_loc = info->GetFragDataLocation(name); | 301 GLint possible_loc = info->GetFragDataLocation(name); |
504 if (possible_loc != -1) | 302 if (possible_loc != -1) |
505 return possible_loc; | 303 return possible_loc; |
506 } | 304 } |
507 } | 305 } |
508 GLint loc = gl->GetFragDataLocationHelper(program, name); | 306 GLint loc = gl->GetFragDataLocationHelper(program, name); |
509 if (loc != -1) { | 307 if (loc != -1) { |
510 base::AutoLock auto_lock(lock_); | 308 base::AutoLock auto_lock(lock_); |
511 Program* info = GetProgramInfo(gl, program); | 309 Program* info = GetProgramInfo(gl, program); |
512 if (info) { | 310 if (info) { |
513 info->CacheFragDataLocation(name, loc); | 311 info->CacheFragDataLocation(name, loc); |
514 } | 312 } |
515 } | 313 } |
516 return loc; | 314 return loc; |
517 } | 315 } |
518 | 316 |
519 bool CachedProgramInfoManager::GetActiveAttrib( | 317 bool ProgramInfoManager::GetActiveAttrib( |
520 GLES2Implementation* gl, | 318 GLES2Implementation* gl, |
521 GLuint program, GLuint index, GLsizei bufsize, GLsizei* length, | 319 GLuint program, GLuint index, GLsizei bufsize, GLsizei* length, |
522 GLint* size, GLenum* type, char* name) { | 320 GLint* size, GLenum* type, char* name) { |
523 { | 321 { |
524 base::AutoLock auto_lock(lock_); | 322 base::AutoLock auto_lock(lock_); |
525 Program* info = GetProgramInfo(gl, program); | 323 Program* info = GetProgramInfo(gl, program); |
526 if (info) { | 324 if (info) { |
527 const Program::VertexAttrib* attrib_info = info->GetAttribInfo(index); | 325 const Program::VertexAttrib* attrib_info = info->GetAttribInfo(index); |
528 if (attrib_info) { | 326 if (attrib_info) { |
529 if (size) { | 327 if (size) { |
(...skipping 15 matching lines...) Expand all Loading... |
545 } | 343 } |
546 } | 344 } |
547 return true; | 345 return true; |
548 } | 346 } |
549 } | 347 } |
550 } | 348 } |
551 return gl->GetActiveAttribHelper( | 349 return gl->GetActiveAttribHelper( |
552 program, index, bufsize, length, size, type, name); | 350 program, index, bufsize, length, size, type, name); |
553 } | 351 } |
554 | 352 |
555 bool CachedProgramInfoManager::GetActiveUniform( | 353 bool ProgramInfoManager::GetActiveUniform( |
556 GLES2Implementation* gl, | 354 GLES2Implementation* gl, |
557 GLuint program, GLuint index, GLsizei bufsize, GLsizei* length, | 355 GLuint program, GLuint index, GLsizei bufsize, GLsizei* length, |
558 GLint* size, GLenum* type, char* name) { | 356 GLint* size, GLenum* type, char* name) { |
559 { | 357 { |
560 base::AutoLock auto_lock(lock_); | 358 base::AutoLock auto_lock(lock_); |
561 Program* info = GetProgramInfo(gl, program); | 359 Program* info = GetProgramInfo(gl, program); |
562 if (info) { | 360 if (info) { |
563 const Program::UniformInfo* uniform_info = info->GetUniformInfo(index); | 361 const Program::UniformInfo* uniform_info = info->GetUniformInfo(index); |
564 if (uniform_info) { | 362 if (uniform_info) { |
565 if (size) { | 363 if (size) { |
(...skipping 15 matching lines...) Expand all Loading... |
581 } | 379 } |
582 } | 380 } |
583 return true; | 381 return true; |
584 } | 382 } |
585 } | 383 } |
586 } | 384 } |
587 return gl->GetActiveUniformHelper( | 385 return gl->GetActiveUniformHelper( |
588 program, index, bufsize, length, size, type, name); | 386 program, index, bufsize, length, size, type, name); |
589 } | 387 } |
590 | 388 |
591 ProgramInfoManager::ProgramInfoManager() { | |
592 } | |
593 | |
594 ProgramInfoManager::~ProgramInfoManager() { | |
595 } | |
596 | |
597 ProgramInfoManager* ProgramInfoManager::Create( | |
598 bool shared_resources_across_processes) { | |
599 if (shared_resources_across_processes) { | |
600 return new NonCachedProgramInfoManager(); | |
601 } else { | |
602 return new CachedProgramInfoManager(); | |
603 } | |
604 } | |
605 | |
606 } // namespace gles2 | 389 } // namespace gles2 |
607 } // namespace gpu | 390 } // namespace gpu |
608 | 391 |
OLD | NEW |