Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(867)

Side by Side Diff: gpu/command_buffer/client/program_info_manager.cc

Issue 613843003: Avoid holding locks across sync IPCs in command buffer (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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
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
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);
403 } 422 }
404 423
405 void CachedProgramInfoManager::DeleteInfo(GLuint program) { 424 void CachedProgramInfoManager::DeleteInfo(GLuint program) {
406 base::AutoLock auto_lock(lock_); 425 base::AutoLock auto_lock(lock_);
407 program_infos_.erase(program); 426 program_infos_.erase(program);
408 } 427 }
409 428
410 bool CachedProgramInfoManager::GetProgramiv( 429 bool CachedProgramInfoManager::GetProgramiv(
411 GLES2Implementation* gl, GLuint program, GLenum pname, GLint* params) { 430 GLES2Implementation* gl, GLuint program, GLenum pname, GLint* params) {
412 base::AutoLock auto_lock(lock_); 431 base::AutoLock auto_lock(lock_);
413 Program* info = GetProgramInfo(gl, program); 432 Program* info = GetProgramInfo(gl, program);
414 if (!info) { 433 if (!info) {
415 return false; 434 return false;
416 } 435 }
417 return info->GetProgramiv(pname, params); 436 return info->GetProgramiv(pname, params);
418 } 437 }
419 438
420 GLint CachedProgramInfoManager::GetAttribLocation( 439 GLint CachedProgramInfoManager::GetAttribLocation(
421 GLES2Implementation* gl, GLuint program, const char* name) { 440 GLES2Implementation* gl, GLuint program, const char* name) {
422 base::AutoLock auto_lock(lock_); 441 {
423 Program* info = GetProgramInfo(gl, program); 442 base::AutoLock auto_lock(lock_);
424 if (info) { 443 Program* info = GetProgramInfo(gl, program);
425 return info->GetAttribLocation(name); 444 if (info) {
445 return info->GetAttribLocation(name);
446 }
426 } 447 }
427 return gl->GetAttribLocationHelper(program, name); 448 return gl->GetAttribLocationHelper(program, name);
428 } 449 }
429 450
430 GLint CachedProgramInfoManager::GetUniformLocation( 451 GLint CachedProgramInfoManager::GetUniformLocation(
431 GLES2Implementation* gl, GLuint program, const char* name) { 452 GLES2Implementation* gl, GLuint program, const char* name) {
432 base::AutoLock auto_lock(lock_); 453 {
433 Program* info = GetProgramInfo(gl, program); 454 base::AutoLock auto_lock(lock_);
434 if (info) { 455 Program* info = GetProgramInfo(gl, program);
435 return info->GetUniformLocation(name); 456 if (info) {
457 return info->GetUniformLocation(name);
458 }
436 } 459 }
437 return gl->GetUniformLocationHelper(program, name); 460 return gl->GetUniformLocationHelper(program, name);
438 } 461 }
439 462
440 bool CachedProgramInfoManager::GetActiveAttrib( 463 bool CachedProgramInfoManager::GetActiveAttrib(
441 GLES2Implementation* gl, 464 GLES2Implementation* gl,
442 GLuint program, GLuint index, GLsizei bufsize, GLsizei* length, 465 GLuint program, GLuint index, GLsizei bufsize, GLsizei* length,
443 GLint* size, GLenum* type, char* name) { 466 GLint* size, GLenum* type, char* name) {
444 base::AutoLock auto_lock(lock_); 467 {
445 Program* info = GetProgramInfo(gl, program); 468 base::AutoLock auto_lock(lock_);
446 if (info) { 469 Program* info = GetProgramInfo(gl, program);
447 const Program::VertexAttrib* attrib_info = 470 if (info) {
448 info->GetAttribInfo(index); 471 const Program::VertexAttrib* attrib_info = info->GetAttribInfo(index);
449 if (attrib_info) { 472 if (attrib_info) {
450 if (size) { 473 if (size) {
451 *size = attrib_info->size; 474 *size = attrib_info->size;
475 }
476 if (type) {
477 *type = attrib_info->type;
478 }
479 if (length || name) {
480 GLsizei max_size = std::min(
481 static_cast<size_t>(bufsize) - 1,
482 std::max(static_cast<size_t>(0), attrib_info->name.size()));
483 if (length) {
484 *length = max_size;
485 }
486 if (name && bufsize > 0) {
487 memcpy(name, attrib_info->name.c_str(), max_size);
488 name[max_size] = '\0';
489 }
490 }
491 return true;
452 } 492 }
453 if (type) {
454 *type = attrib_info->type;
455 }
456 if (length || name) {
457 GLsizei max_size = std::min(static_cast<size_t>(bufsize) - 1,
458 std::max(static_cast<size_t>(0),
459 attrib_info->name.size()));
460 if (length) {
461 *length = max_size;
462 }
463 if (name && bufsize > 0) {
464 memcpy(name, attrib_info->name.c_str(), max_size);
465 name[max_size] = '\0';
466 }
467 }
468 return true;
469 } 493 }
470 } 494 }
471 return gl->GetActiveAttribHelper( 495 return gl->GetActiveAttribHelper(
472 program, index, bufsize, length, size, type, name); 496 program, index, bufsize, length, size, type, name);
473 } 497 }
474 498
475 bool CachedProgramInfoManager::GetActiveUniform( 499 bool CachedProgramInfoManager::GetActiveUniform(
476 GLES2Implementation* gl, 500 GLES2Implementation* gl,
477 GLuint program, GLuint index, GLsizei bufsize, GLsizei* length, 501 GLuint program, GLuint index, GLsizei bufsize, GLsizei* length,
478 GLint* size, GLenum* type, char* name) { 502 GLint* size, GLenum* type, char* name) {
479 base::AutoLock auto_lock(lock_); 503 {
480 Program* info = GetProgramInfo(gl, program); 504 base::AutoLock auto_lock(lock_);
481 if (info) { 505 Program* info = GetProgramInfo(gl, program);
482 const Program::UniformInfo* uniform_info = info->GetUniformInfo(index); 506 if (info) {
483 if (uniform_info) { 507 const Program::UniformInfo* uniform_info = info->GetUniformInfo(index);
484 if (size) { 508 if (uniform_info) {
485 *size = uniform_info->size; 509 if (size) {
510 *size = uniform_info->size;
511 }
512 if (type) {
513 *type = uniform_info->type;
514 }
515 if (length || name) {
516 GLsizei max_size = std::min(
517 static_cast<size_t>(bufsize) - 1,
518 std::max(static_cast<size_t>(0), uniform_info->name.size()));
519 if (length) {
520 *length = max_size;
521 }
522 if (name && bufsize > 0) {
523 memcpy(name, uniform_info->name.c_str(), max_size);
524 name[max_size] = '\0';
525 }
526 }
527 return true;
486 } 528 }
487 if (type) {
488 *type = uniform_info->type;
489 }
490 if (length || name) {
491 GLsizei max_size = std::min(static_cast<size_t>(bufsize) - 1,
492 std::max(static_cast<size_t>(0),
493 uniform_info->name.size()));
494 if (length) {
495 *length = max_size;
496 }
497 if (name && bufsize > 0) {
498 memcpy(name, uniform_info->name.c_str(), max_size);
499 name[max_size] = '\0';
500 }
501 }
502 return true;
503 } 529 }
504 } 530 }
505 return gl->GetActiveUniformHelper( 531 return gl->GetActiveUniformHelper(
506 program, index, bufsize, length, size, type, name); 532 program, index, bufsize, length, size, type, name);
507 } 533 }
508 534
509 ProgramInfoManager::ProgramInfoManager() { 535 ProgramInfoManager::ProgramInfoManager() {
510 } 536 }
511 537
512 ProgramInfoManager::~ProgramInfoManager() { 538 ProgramInfoManager::~ProgramInfoManager() {
513 } 539 }
514 540
515 ProgramInfoManager* ProgramInfoManager::Create( 541 ProgramInfoManager* ProgramInfoManager::Create(
516 bool shared_resources_across_processes) { 542 bool shared_resources_across_processes) {
517 if (shared_resources_across_processes) { 543 if (shared_resources_across_processes) {
518 return new NonCachedProgramInfoManager(); 544 return new NonCachedProgramInfoManager();
519 } else { 545 } else {
520 return new CachedProgramInfoManager(); 546 return new CachedProgramInfoManager();
521 } 547 }
522 } 548 }
523 549
524 } // namespace gles2 550 } // namespace gles2
525 } // namespace gpu 551 } // namespace gpu
526 552
OLDNEW
« no previous file with comments | « no previous file | gpu/command_buffer/client/share_group.cc » ('j') | gpu/command_buffer/client/share_group.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698