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 <map> | 7 #include <map> |
8 | 8 |
9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
10 #include "gpu/command_buffer/client/atomicops.h" | 10 #include "base/synchronization/lock.h" |
11 #include "gpu/command_buffer/client/gles2_implementation.h" | 11 #include "gpu/command_buffer/client/gles2_implementation.h" |
12 #include "gpu/command_buffer/common/gles2_cmd_utils.h" | 12 #include "gpu/command_buffer/common/gles2_cmd_utils.h" |
13 | 13 |
14 namespace gpu { | 14 namespace gpu { |
15 namespace gles2 { | 15 namespace gles2 { |
16 | 16 |
17 class NonCachedProgramInfoManager : public ProgramInfoManager { | 17 class NonCachedProgramInfoManager : public ProgramInfoManager { |
18 public: | 18 public: |
19 NonCachedProgramInfoManager(); | 19 NonCachedProgramInfoManager(); |
20 virtual ~NonCachedProgramInfoManager(); | 20 virtual ~NonCachedProgramInfoManager(); |
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
214 bool link_status_; | 214 bool link_status_; |
215 }; | 215 }; |
216 | 216 |
217 Program* GetProgramInfo(GLES2Implementation* gl, GLuint program); | 217 Program* GetProgramInfo(GLES2Implementation* gl, GLuint program); |
218 | 218 |
219 // TODO(gman): Switch to a faster container. | 219 // TODO(gman): Switch to a faster container. |
220 typedef std::map<GLuint, Program> ProgramInfoMap; | 220 typedef std::map<GLuint, Program> ProgramInfoMap; |
221 | 221 |
222 ProgramInfoMap program_infos_; | 222 ProgramInfoMap program_infos_; |
223 | 223 |
224 mutable Lock lock_; | 224 mutable base::Lock lock_; |
225 }; | 225 }; |
226 | 226 |
227 CachedProgramInfoManager::Program::UniformInfo::UniformInfo( | 227 CachedProgramInfoManager::Program::UniformInfo::UniformInfo( |
228 GLsizei _size, GLenum _type, const std::string& _name) | 228 GLsizei _size, GLenum _type, const std::string& _name) |
229 : size(_size), | 229 : size(_size), |
230 type(_type), | 230 type(_type), |
231 name(_name) { | 231 name(_name) { |
232 is_array = (!name.empty() && name[name.size() - 1] == ']'); | 232 is_array = (!name.empty() && name[name.size() - 1] == ']'); |
233 DCHECK(!(size > 1 && !is_array)); | 233 DCHECK(!(size > 1 && !is_array)); |
234 } | 234 } |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
386 ProgramInfoMap::iterator it = program_infos_.find(program); | 386 ProgramInfoMap::iterator it = program_infos_.find(program); |
387 if (it == program_infos_.end()) { | 387 if (it == program_infos_.end()) { |
388 return NULL; | 388 return NULL; |
389 } | 389 } |
390 Program* info = &it->second; | 390 Program* info = &it->second; |
391 info->Update(gl, program); | 391 info->Update(gl, program); |
392 return info; | 392 return info; |
393 } | 393 } |
394 | 394 |
395 void CachedProgramInfoManager::CreateInfo(GLuint program) { | 395 void CachedProgramInfoManager::CreateInfo(GLuint program) { |
396 AutoLock auto_lock(lock_); | 396 base::AutoLock auto_lock(lock_); |
397 DeleteInfo(program); | 397 DeleteInfo(program); |
398 std::pair<ProgramInfoMap::iterator, bool> result = | 398 std::pair<ProgramInfoMap::iterator, bool> result = |
399 program_infos_.insert(std::make_pair(program, Program())); | 399 program_infos_.insert(std::make_pair(program, Program())); |
400 | 400 |
401 DCHECK(result.second); | 401 DCHECK(result.second); |
402 } | 402 } |
403 | 403 |
404 void CachedProgramInfoManager::DeleteInfo(GLuint program) { | 404 void CachedProgramInfoManager::DeleteInfo(GLuint program) { |
405 program_infos_.erase(program); | 405 program_infos_.erase(program); |
406 } | 406 } |
407 | 407 |
408 bool CachedProgramInfoManager::GetProgramiv( | 408 bool CachedProgramInfoManager::GetProgramiv( |
409 GLES2Implementation* gl, GLuint program, GLenum pname, GLint* params) { | 409 GLES2Implementation* gl, GLuint program, GLenum pname, GLint* params) { |
410 AutoLock auto_lock(lock_); | 410 base::AutoLock auto_lock(lock_); |
411 Program* info = GetProgramInfo(gl, program); | 411 Program* info = GetProgramInfo(gl, program); |
412 if (!info) { | 412 if (!info) { |
413 return false; | 413 return false; |
414 } | 414 } |
415 return info->GetProgramiv(pname, params); | 415 return info->GetProgramiv(pname, params); |
416 } | 416 } |
417 | 417 |
418 GLint CachedProgramInfoManager::GetAttribLocation( | 418 GLint CachedProgramInfoManager::GetAttribLocation( |
419 GLES2Implementation* gl, GLuint program, const char* name) { | 419 GLES2Implementation* gl, GLuint program, const char* name) { |
420 AutoLock auto_lock(lock_); | 420 base::AutoLock auto_lock(lock_); |
421 Program* info = GetProgramInfo(gl, program); | 421 Program* info = GetProgramInfo(gl, program); |
422 if (info) { | 422 if (info) { |
423 return info->GetAttribLocation(name); | 423 return info->GetAttribLocation(name); |
424 } | 424 } |
425 return gl->GetAttribLocationHelper(program, name); | 425 return gl->GetAttribLocationHelper(program, name); |
426 } | 426 } |
427 | 427 |
428 GLint CachedProgramInfoManager::GetUniformLocation( | 428 GLint CachedProgramInfoManager::GetUniformLocation( |
429 GLES2Implementation* gl, GLuint program, const char* name) { | 429 GLES2Implementation* gl, GLuint program, const char* name) { |
430 AutoLock auto_lock(lock_); | 430 base::AutoLock auto_lock(lock_); |
431 Program* info = GetProgramInfo(gl, program); | 431 Program* info = GetProgramInfo(gl, program); |
432 if (info) { | 432 if (info) { |
433 return info->GetUniformLocation(name); | 433 return info->GetUniformLocation(name); |
434 } | 434 } |
435 return gl->GetUniformLocationHelper(program, name); | 435 return gl->GetUniformLocationHelper(program, name); |
436 } | 436 } |
437 | 437 |
438 bool CachedProgramInfoManager::GetActiveAttrib( | 438 bool CachedProgramInfoManager::GetActiveAttrib( |
439 GLES2Implementation* gl, | 439 GLES2Implementation* gl, |
440 GLuint program, GLuint index, GLsizei bufsize, GLsizei* length, | 440 GLuint program, GLuint index, GLsizei bufsize, GLsizei* length, |
441 GLint* size, GLenum* type, char* name) { | 441 GLint* size, GLenum* type, char* name) { |
442 AutoLock auto_lock(lock_); | 442 base::AutoLock auto_lock(lock_); |
443 Program* info = GetProgramInfo(gl, program); | 443 Program* info = GetProgramInfo(gl, program); |
444 if (info) { | 444 if (info) { |
445 const Program::VertexAttrib* attrib_info = | 445 const Program::VertexAttrib* attrib_info = |
446 info->GetAttribInfo(index); | 446 info->GetAttribInfo(index); |
447 if (attrib_info) { | 447 if (attrib_info) { |
448 if (size) { | 448 if (size) { |
449 *size = attrib_info->size; | 449 *size = attrib_info->size; |
450 } | 450 } |
451 if (type) { | 451 if (type) { |
452 *type = attrib_info->type; | 452 *type = attrib_info->type; |
(...skipping 14 matching lines...) Expand all Loading... |
467 } | 467 } |
468 } | 468 } |
469 return gl->GetActiveAttribHelper( | 469 return gl->GetActiveAttribHelper( |
470 program, index, bufsize, length, size, type, name); | 470 program, index, bufsize, length, size, type, name); |
471 } | 471 } |
472 | 472 |
473 bool CachedProgramInfoManager::GetActiveUniform( | 473 bool CachedProgramInfoManager::GetActiveUniform( |
474 GLES2Implementation* gl, | 474 GLES2Implementation* gl, |
475 GLuint program, GLuint index, GLsizei bufsize, GLsizei* length, | 475 GLuint program, GLuint index, GLsizei bufsize, GLsizei* length, |
476 GLint* size, GLenum* type, char* name) { | 476 GLint* size, GLenum* type, char* name) { |
477 AutoLock auto_lock(lock_); | 477 base::AutoLock auto_lock(lock_); |
478 Program* info = GetProgramInfo(gl, program); | 478 Program* info = GetProgramInfo(gl, program); |
479 if (info) { | 479 if (info) { |
480 const Program::UniformInfo* uniform_info = info->GetUniformInfo(index); | 480 const Program::UniformInfo* uniform_info = info->GetUniformInfo(index); |
481 if (uniform_info) { | 481 if (uniform_info) { |
482 if (size) { | 482 if (size) { |
483 *size = uniform_info->size; | 483 *size = uniform_info->size; |
484 } | 484 } |
485 if (type) { | 485 if (type) { |
486 *type = uniform_info->type; | 486 *type = uniform_info->type; |
487 } | 487 } |
(...skipping 27 matching lines...) Expand all Loading... |
515 if (shared_resources_across_processes) { | 515 if (shared_resources_across_processes) { |
516 return new NonCachedProgramInfoManager(); | 516 return new NonCachedProgramInfoManager(); |
517 } else { | 517 } else { |
518 return new CachedProgramInfoManager(); | 518 return new CachedProgramInfoManager(); |
519 } | 519 } |
520 } | 520 } |
521 | 521 |
522 } // namespace gles2 | 522 } // namespace gles2 |
523 } // namespace gpu | 523 } // namespace gpu |
524 | 524 |
OLD | NEW |