| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "../client/program_info_manager.h" | 5 #include "../client/program_info_manager.h" |
| 6 #include "../client/atomicops.h" |
| 6 #include "../client/gles2_implementation.h" | 7 #include "../client/gles2_implementation.h" |
| 7 | 8 |
| 8 #include <map> | 9 #include <map> |
| 9 | 10 |
| 10 namespace gpu { | 11 namespace gpu { |
| 11 namespace gles2 { | 12 namespace gles2 { |
| 12 | 13 |
| 13 class NonCachedProgramInfoManager : public ProgramInfoManager { | 14 class NonCachedProgramInfoManager : public ProgramInfoManager { |
| 14 public: | 15 public: |
| 15 NonCachedProgramInfoManager(); | 16 NonCachedProgramInfoManager(); |
| (...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 186 // This is true if glLinkProgram was successful last time it was called. | 187 // This is true if glLinkProgram was successful last time it was called. |
| 187 bool link_status_; | 188 bool link_status_; |
| 188 }; | 189 }; |
| 189 | 190 |
| 190 ProgramInfo* GetProgramInfo(GLES2Implementation* gl, GLuint program); | 191 ProgramInfo* GetProgramInfo(GLES2Implementation* gl, GLuint program); |
| 191 | 192 |
| 192 // TODO(gman): Switch to a faster container. | 193 // TODO(gman): Switch to a faster container. |
| 193 typedef std::map<GLuint, ProgramInfo> ProgramInfoMap; | 194 typedef std::map<GLuint, ProgramInfo> ProgramInfoMap; |
| 194 | 195 |
| 195 ProgramInfoMap program_infos_; | 196 ProgramInfoMap program_infos_; |
| 197 |
| 198 mutable Lock lock_; |
| 196 }; | 199 }; |
| 197 | 200 |
| 198 CachedProgramInfoManager::ProgramInfo::UniformInfo::UniformInfo( | 201 CachedProgramInfoManager::ProgramInfo::UniformInfo::UniformInfo( |
| 199 GLsizei _size, GLenum _type, const std::string& _name) | 202 GLsizei _size, GLenum _type, const std::string& _name) |
| 200 : size(_size), | 203 : size(_size), |
| 201 type(_type), | 204 type(_type), |
| 202 name(_name) { | 205 name(_name) { |
| 203 is_array = (!name.empty() && name[name.size() - 1] == ']'); | 206 is_array = (!name.empty() && name[name.size() - 1] == ']'); |
| 204 GPU_DCHECK(!(size > 1 && !is_array)); | 207 GPU_DCHECK(!(size > 1 && !is_array)); |
| 205 } | 208 } |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 365 ProgramInfoMap::iterator it = program_infos_.find(program); | 368 ProgramInfoMap::iterator it = program_infos_.find(program); |
| 366 if (it == program_infos_.end()) { | 369 if (it == program_infos_.end()) { |
| 367 return NULL; | 370 return NULL; |
| 368 } | 371 } |
| 369 ProgramInfo* info = &it->second; | 372 ProgramInfo* info = &it->second; |
| 370 info->Update(gl, program); | 373 info->Update(gl, program); |
| 371 return info; | 374 return info; |
| 372 } | 375 } |
| 373 | 376 |
| 374 void CachedProgramInfoManager::CreateInfo(GLuint program) { | 377 void CachedProgramInfoManager::CreateInfo(GLuint program) { |
| 378 AutoLock auto_lock(lock_); |
| 375 DeleteInfo(program); | 379 DeleteInfo(program); |
| 376 std::pair<ProgramInfoMap::iterator, bool> result = | 380 std::pair<ProgramInfoMap::iterator, bool> result = |
| 377 program_infos_.insert(std::make_pair(program, ProgramInfo())); | 381 program_infos_.insert(std::make_pair(program, ProgramInfo())); |
| 378 | 382 |
| 379 GPU_DCHECK(result.second); | 383 GPU_DCHECK(result.second); |
| 380 } | 384 } |
| 381 | 385 |
| 382 void CachedProgramInfoManager::DeleteInfo(GLuint program) { | 386 void CachedProgramInfoManager::DeleteInfo(GLuint program) { |
| 383 program_infos_.erase(program); | 387 program_infos_.erase(program); |
| 384 } | 388 } |
| 385 | 389 |
| 386 bool CachedProgramInfoManager::GetProgramiv( | 390 bool CachedProgramInfoManager::GetProgramiv( |
| 387 GLES2Implementation* gl, GLuint program, GLenum pname, GLint* params) { | 391 GLES2Implementation* gl, GLuint program, GLenum pname, GLint* params) { |
| 392 AutoLock auto_lock(lock_); |
| 388 ProgramInfo* info = GetProgramInfo(gl, program); | 393 ProgramInfo* info = GetProgramInfo(gl, program); |
| 389 if (!info) { | 394 if (!info) { |
| 390 return false; | 395 return false; |
| 391 } | 396 } |
| 392 return info->GetProgramiv(pname, params); | 397 return info->GetProgramiv(pname, params); |
| 393 } | 398 } |
| 394 | 399 |
| 395 GLint CachedProgramInfoManager::GetAttribLocation( | 400 GLint CachedProgramInfoManager::GetAttribLocation( |
| 396 GLES2Implementation* gl, GLuint program, const char* name) { | 401 GLES2Implementation* gl, GLuint program, const char* name) { |
| 402 AutoLock auto_lock(lock_); |
| 397 ProgramInfo* info = GetProgramInfo(gl, program); | 403 ProgramInfo* info = GetProgramInfo(gl, program); |
| 398 if (info) { | 404 if (info) { |
| 399 return info->GetAttribLocation(name); | 405 return info->GetAttribLocation(name); |
| 400 } | 406 } |
| 401 return gl->GetAttribLocationHelper(program, name); | 407 return gl->GetAttribLocationHelper(program, name); |
| 402 } | 408 } |
| 403 | 409 |
| 404 GLint CachedProgramInfoManager::GetUniformLocation( | 410 GLint CachedProgramInfoManager::GetUniformLocation( |
| 405 GLES2Implementation* gl, GLuint program, const char* name) { | 411 GLES2Implementation* gl, GLuint program, const char* name) { |
| 412 AutoLock auto_lock(lock_); |
| 406 ProgramInfo* info = GetProgramInfo(gl, program); | 413 ProgramInfo* info = GetProgramInfo(gl, program); |
| 407 if (info) { | 414 if (info) { |
| 408 return info->GetUniformLocation(name); | 415 return info->GetUniformLocation(name); |
| 409 } | 416 } |
| 410 return gl->GetUniformLocationHelper(program, name); | 417 return gl->GetUniformLocationHelper(program, name); |
| 411 } | 418 } |
| 412 | 419 |
| 413 bool CachedProgramInfoManager::GetActiveAttrib( | 420 bool CachedProgramInfoManager::GetActiveAttrib( |
| 414 GLES2Implementation* gl, | 421 GLES2Implementation* gl, |
| 415 GLuint program, GLuint index, GLsizei bufsize, GLsizei* length, | 422 GLuint program, GLuint index, GLsizei bufsize, GLsizei* length, |
| 416 GLint* size, GLenum* type, char* name) { | 423 GLint* size, GLenum* type, char* name) { |
| 424 AutoLock auto_lock(lock_); |
| 417 ProgramInfo* info = GetProgramInfo(gl, program); | 425 ProgramInfo* info = GetProgramInfo(gl, program); |
| 418 if (info) { | 426 if (info) { |
| 419 const ProgramInfo::VertexAttribInfo* attrib_info = | 427 const ProgramInfo::VertexAttribInfo* attrib_info = |
| 420 info->GetAttribInfo(index); | 428 info->GetAttribInfo(index); |
| 421 if (attrib_info) { | 429 if (attrib_info) { |
| 422 if (size) { | 430 if (size) { |
| 423 *size = attrib_info->size; | 431 *size = attrib_info->size; |
| 424 } | 432 } |
| 425 if (type) { | 433 if (type) { |
| 426 *type = attrib_info->type; | 434 *type = attrib_info->type; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 441 } | 449 } |
| 442 } | 450 } |
| 443 return gl->GetActiveAttribHelper( | 451 return gl->GetActiveAttribHelper( |
| 444 program, index, bufsize, length, size, type, name); | 452 program, index, bufsize, length, size, type, name); |
| 445 } | 453 } |
| 446 | 454 |
| 447 bool CachedProgramInfoManager::GetActiveUniform( | 455 bool CachedProgramInfoManager::GetActiveUniform( |
| 448 GLES2Implementation* gl, | 456 GLES2Implementation* gl, |
| 449 GLuint program, GLuint index, GLsizei bufsize, GLsizei* length, | 457 GLuint program, GLuint index, GLsizei bufsize, GLsizei* length, |
| 450 GLint* size, GLenum* type, char* name) { | 458 GLint* size, GLenum* type, char* name) { |
| 459 AutoLock auto_lock(lock_); |
| 451 ProgramInfo* info = GetProgramInfo(gl, program); | 460 ProgramInfo* info = GetProgramInfo(gl, program); |
| 452 if (info) { | 461 if (info) { |
| 453 const ProgramInfo::UniformInfo* uniform_info = info->GetUniformInfo(index); | 462 const ProgramInfo::UniformInfo* uniform_info = info->GetUniformInfo(index); |
| 454 if (uniform_info) { | 463 if (uniform_info) { |
| 455 if (size) { | 464 if (size) { |
| 456 *size = uniform_info->size; | 465 *size = uniform_info->size; |
| 457 } | 466 } |
| 458 if (type) { | 467 if (type) { |
| 459 *type = uniform_info->type; | 468 *type = uniform_info->type; |
| 460 } | 469 } |
| (...skipping 26 matching lines...) Expand all Loading... |
| 487 if (shared_resources) { | 496 if (shared_resources) { |
| 488 return new NonCachedProgramInfoManager(); | 497 return new NonCachedProgramInfoManager(); |
| 489 } else { | 498 } else { |
| 490 return new CachedProgramInfoManager(); | 499 return new CachedProgramInfoManager(); |
| 491 } | 500 } |
| 492 } | 501 } |
| 493 | 502 |
| 494 } // namespace gles2 | 503 } // namespace gles2 |
| 495 } // namespace gpu | 504 } // namespace gpu |
| 496 | 505 |
| OLD | NEW |