Chromium Code Reviews| 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 "base/synchronization/lock.h" | 10 #include "base/synchronization/lock.h" |
| (...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 188 return (static_cast<size_t>(index) < uniform_infos_.size()) ? | 188 return (static_cast<size_t>(index) < uniform_infos_.size()) ? |
| 189 &uniform_infos_[index] : NULL; | 189 &uniform_infos_[index] : NULL; |
| 190 } | 190 } |
| 191 | 191 |
| 192 // Gets the location of a uniform by name. | 192 // Gets the location of a uniform by name. |
| 193 GLint GetUniformLocation(const std::string& name) const; | 193 GLint GetUniformLocation(const std::string& name) const; |
| 194 | 194 |
| 195 bool GetProgramiv(GLenum pname, GLint* params); | 195 bool GetProgramiv(GLenum pname, GLint* params); |
| 196 | 196 |
| 197 // Updates the program info after a successful link. | 197 // Updates the program info after a successful link. |
| 198 void Update(GLES2Implementation* gl, GLuint program); | 198 void Update(GLES2Implementation* gl, |
| 199 GLuint program, | |
| 200 const std::vector<int8>& result); | |
| 201 | |
| 202 bool cached() const { return cached_; } | |
| 199 | 203 |
| 200 private: | 204 private: |
| 201 bool cached_; | 205 bool cached_; |
| 202 | 206 |
| 203 GLsizei max_attrib_name_length_; | 207 GLsizei max_attrib_name_length_; |
| 204 | 208 |
| 205 // Attrib by index. | 209 // Attrib by index. |
| 206 AttribInfoVector attrib_infos_; | 210 AttribInfoVector attrib_infos_; |
| 207 | 211 |
| 208 GLsizei max_uniform_name_length_; | 212 GLsizei max_uniform_name_length_; |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 309 const std::vector<int8>& data, uint32 offset, size_t size) { | 313 const std::vector<int8>& data, uint32 offset, size_t size) { |
| 310 const int8* p = &data[0] + offset; | 314 const int8* p = &data[0] + offset; |
| 311 if (offset + size > data.size()) { | 315 if (offset + size > data.size()) { |
| 312 NOTREACHED(); | 316 NOTREACHED(); |
| 313 return NULL; | 317 return NULL; |
| 314 } | 318 } |
| 315 return static_cast<T>(static_cast<const void*>(p)); | 319 return static_cast<T>(static_cast<const void*>(p)); |
| 316 } | 320 } |
| 317 | 321 |
| 318 void CachedProgramInfoManager::Program::Update( | 322 void CachedProgramInfoManager::Program::Update( |
| 319 GLES2Implementation* gl, GLuint program) { | 323 GLES2Implementation* gl, |
| 324 GLuint program, | |
| 325 const std::vector<int8>& result) { | |
| 320 if (cached_) { | 326 if (cached_) { |
| 321 return; | 327 return; |
| 322 } | 328 } |
| 323 std::vector<int8> result; | |
| 324 gl->GetProgramInfoCHROMIUMHelper(program, &result); | |
| 325 if (result.empty()) { | 329 if (result.empty()) { |
| 326 // This should only happen on a lost context. | 330 // This should only happen on a lost context. |
| 327 return; | 331 return; |
| 328 } | 332 } |
| 329 DCHECK_GE(result.size(), sizeof(ProgramInfoHeader)); | 333 DCHECK_GE(result.size(), sizeof(ProgramInfoHeader)); |
| 330 const ProgramInfoHeader* header = LocalGetAs<const ProgramInfoHeader*>( | 334 const ProgramInfoHeader* header = LocalGetAs<const ProgramInfoHeader*>( |
| 331 result, 0, sizeof(header)); | 335 result, 0, sizeof(header)); |
| 332 link_status_ = header->link_status != 0; | 336 link_status_ = header->link_status != 0; |
| 333 if (!link_status_) { | 337 if (!link_status_) { |
| 334 return; | 338 return; |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 382 | 386 |
| 383 CachedProgramInfoManager::Program* | 387 CachedProgramInfoManager::Program* |
| 384 CachedProgramInfoManager::GetProgramInfo( | 388 CachedProgramInfoManager::GetProgramInfo( |
| 385 GLES2Implementation* gl, GLuint program) { | 389 GLES2Implementation* gl, GLuint program) { |
| 386 lock_.AssertAcquired(); | 390 lock_.AssertAcquired(); |
| 387 ProgramInfoMap::iterator it = program_infos_.find(program); | 391 ProgramInfoMap::iterator it = program_infos_.find(program); |
| 388 if (it == program_infos_.end()) { | 392 if (it == program_infos_.end()) { |
| 389 return NULL; | 393 return NULL; |
| 390 } | 394 } |
| 391 Program* info = &it->second; | 395 Program* info = &it->second; |
| 392 info->Update(gl, program); | 396 if (info->cached()) |
| 397 return info; | |
| 398 std::vector<int8> result; | |
| 399 { | |
| 400 base::AutoUnlock unlock(lock_); | |
| 401 // lock_ can't be held across IPC call or else it may deadlock in pepper. | |
| 402 // http://crbug.com/418651 | |
| 403 gl->GetProgramInfoCHROMIUMHelper(program, &result); | |
| 404 } | |
| 405 | |
| 406 it = program_infos_.find(program); | |
| 407 if (it == program_infos_.end()) { | |
| 408 return NULL; | |
| 409 } | |
| 410 info = &it->second; | |
| 411 info->Update(gl, program, result); | |
| 393 return info; | 412 return info; |
| 394 } | 413 } |
| 395 | 414 |
| 396 void CachedProgramInfoManager::CreateInfo(GLuint program) { | 415 void CachedProgramInfoManager::CreateInfo(GLuint program) { |
| 397 base::AutoLock auto_lock(lock_); | 416 base::AutoLock auto_lock(lock_); |
| 398 program_infos_.erase(program); | 417 program_infos_.erase(program); |
| 399 std::pair<ProgramInfoMap::iterator, bool> result = | 418 std::pair<ProgramInfoMap::iterator, bool> result = |
| 400 program_infos_.insert(std::make_pair(program, Program())); | 419 program_infos_.insert(std::make_pair(program, Program())); |
| 401 | 420 |
| 402 DCHECK(result.second); | 421 DCHECK(result.second); |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 427 return gl->GetAttribLocationHelper(program, name); | 446 return gl->GetAttribLocationHelper(program, name); |
| 428 } | 447 } |
| 429 | 448 |
| 430 GLint CachedProgramInfoManager::GetUniformLocation( | 449 GLint CachedProgramInfoManager::GetUniformLocation( |
| 431 GLES2Implementation* gl, GLuint program, const char* name) { | 450 GLES2Implementation* gl, GLuint program, const char* name) { |
| 432 base::AutoLock auto_lock(lock_); | 451 base::AutoLock auto_lock(lock_); |
| 433 Program* info = GetProgramInfo(gl, program); | 452 Program* info = GetProgramInfo(gl, program); |
| 434 if (info) { | 453 if (info) { |
| 435 return info->GetUniformLocation(name); | 454 return info->GetUniformLocation(name); |
| 436 } | 455 } |
| 437 return gl->GetUniformLocationHelper(program, name); | 456 return gl->GetUniformLocationHelper(program, name); |
|
Peng
2014/09/29 23:28:59
Does this gl call use sync IPC?
| |
| 438 } | 457 } |
| 439 | 458 |
| 440 bool CachedProgramInfoManager::GetActiveAttrib( | 459 bool CachedProgramInfoManager::GetActiveAttrib( |
| 441 GLES2Implementation* gl, | 460 GLES2Implementation* gl, |
| 442 GLuint program, GLuint index, GLsizei bufsize, GLsizei* length, | 461 GLuint program, GLuint index, GLsizei bufsize, GLsizei* length, |
| 443 GLint* size, GLenum* type, char* name) { | 462 GLint* size, GLenum* type, char* name) { |
| 444 base::AutoLock auto_lock(lock_); | 463 base::AutoLock auto_lock(lock_); |
| 445 Program* info = GetProgramInfo(gl, program); | 464 Program* info = GetProgramInfo(gl, program); |
| 446 if (info) { | 465 if (info) { |
| 447 const Program::VertexAttrib* attrib_info = | 466 const Program::VertexAttrib* attrib_info = |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 461 *length = max_size; | 480 *length = max_size; |
| 462 } | 481 } |
| 463 if (name && bufsize > 0) { | 482 if (name && bufsize > 0) { |
| 464 memcpy(name, attrib_info->name.c_str(), max_size); | 483 memcpy(name, attrib_info->name.c_str(), max_size); |
| 465 name[max_size] = '\0'; | 484 name[max_size] = '\0'; |
| 466 } | 485 } |
| 467 } | 486 } |
| 468 return true; | 487 return true; |
| 469 } | 488 } |
| 470 } | 489 } |
| 471 return gl->GetActiveAttribHelper( | 490 return gl->GetActiveAttribHelper( |
|
Peng
2014/09/29 23:28:59
Same here?
| |
| 472 program, index, bufsize, length, size, type, name); | 491 program, index, bufsize, length, size, type, name); |
| 473 } | 492 } |
| 474 | 493 |
| 475 bool CachedProgramInfoManager::GetActiveUniform( | 494 bool CachedProgramInfoManager::GetActiveUniform( |
| 476 GLES2Implementation* gl, | 495 GLES2Implementation* gl, |
| 477 GLuint program, GLuint index, GLsizei bufsize, GLsizei* length, | 496 GLuint program, GLuint index, GLsizei bufsize, GLsizei* length, |
| 478 GLint* size, GLenum* type, char* name) { | 497 GLint* size, GLenum* type, char* name) { |
| 479 base::AutoLock auto_lock(lock_); | 498 base::AutoLock auto_lock(lock_); |
| 480 Program* info = GetProgramInfo(gl, program); | 499 Program* info = GetProgramInfo(gl, program); |
| 481 if (info) { | 500 if (info) { |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 495 *length = max_size; | 514 *length = max_size; |
| 496 } | 515 } |
| 497 if (name && bufsize > 0) { | 516 if (name && bufsize > 0) { |
| 498 memcpy(name, uniform_info->name.c_str(), max_size); | 517 memcpy(name, uniform_info->name.c_str(), max_size); |
| 499 name[max_size] = '\0'; | 518 name[max_size] = '\0'; |
| 500 } | 519 } |
| 501 } | 520 } |
| 502 return true; | 521 return true; |
| 503 } | 522 } |
| 504 } | 523 } |
| 505 return gl->GetActiveUniformHelper( | 524 return gl->GetActiveUniformHelper( |
|
Peng
2014/09/29 23:28:59
same?
| |
| 506 program, index, bufsize, length, size, type, name); | 525 program, index, bufsize, length, size, type, name); |
| 507 } | 526 } |
| 508 | 527 |
| 509 ProgramInfoManager::ProgramInfoManager() { | 528 ProgramInfoManager::ProgramInfoManager() { |
| 510 } | 529 } |
| 511 | 530 |
| 512 ProgramInfoManager::~ProgramInfoManager() { | 531 ProgramInfoManager::~ProgramInfoManager() { |
| 513 } | 532 } |
| 514 | 533 |
| 515 ProgramInfoManager* ProgramInfoManager::Create( | 534 ProgramInfoManager* ProgramInfoManager::Create( |
| 516 bool shared_resources_across_processes) { | 535 bool shared_resources_across_processes) { |
| 517 if (shared_resources_across_processes) { | 536 if (shared_resources_across_processes) { |
| 518 return new NonCachedProgramInfoManager(); | 537 return new NonCachedProgramInfoManager(); |
| 519 } else { | 538 } else { |
| 520 return new CachedProgramInfoManager(); | 539 return new CachedProgramInfoManager(); |
| 521 } | 540 } |
| 522 } | 541 } |
| 523 | 542 |
| 524 } // namespace gles2 | 543 } // namespace gles2 |
| 525 } // namespace gpu | 544 } // namespace gpu |
| 526 | 545 |
| OLD | NEW |