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

Side by Side Diff: Source/platform/graphics/Canvas2DLayerBridge.cpp

Issue 552423002: Fix crash in Canvas2DLayerBridge after a GPU resource is lost (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 3 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | Source/platform/graphics/Canvas2DLayerBridgeTest.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2012 Google Inc. All rights reserved. 2 * Copyright (C) 2012 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 7 *
8 * 1. Redistributions of source code must retain the above copyright 8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright 10 * 2. Redistributions in binary form must reproduce the above copyright
(...skipping 406 matching lines...) Expand 10 before | Expand all | Expand 10 after
417 if (image->uniqueID() == m_lastImageId) 417 if (image->uniqueID() == m_lastImageId)
418 return false; 418 return false;
419 m_lastImageId = image->uniqueID(); 419 m_lastImageId = image->uniqueID();
420 420
421 MailboxInfo* mailboxInfo = createMailboxInfo(); 421 MailboxInfo* mailboxInfo = createMailboxInfo();
422 mailboxInfo->m_status = MailboxInUse; 422 mailboxInfo->m_status = MailboxInUse;
423 mailboxInfo->m_image = image; 423 mailboxInfo->m_image = image;
424 424
425 ASSERT(mailboxInfo->m_mailbox.syncPoint == 0); 425 ASSERT(mailboxInfo->m_mailbox.syncPoint == 0);
426 ASSERT(mailboxInfo->m_image.get()); 426 ASSERT(mailboxInfo->m_image.get());
427
428 // set m_parentLayerBridge to make sure 'this' stays alive as long as it has
429 // live mailboxes
430 ASSERT(!mailboxInfo->m_parentLayerBridge);
431 mailboxInfo->m_parentLayerBridge = this;
432 *outMailbox = mailboxInfo->m_mailbox;
433
434 GrContext* grContext = m_contextProvider->grContext();
435 if (!grContext)
436 return true; // for testing: skip gl stuff when using a mock graphics co ntext.
437
427 ASSERT(mailboxInfo->m_image->getTexture()); 438 ASSERT(mailboxInfo->m_image->getTexture());
428 439
429 // Because of texture sharing with the compositor, we must invalidate 440 // Because of texture sharing with the compositor, we must invalidate
430 // the state cached in skia so that the deferred copy on write 441 // the state cached in skia so that the deferred copy on write
431 // in SkSurface_Gpu does not make any false assumptions. 442 // in SkSurface_Gpu does not make any false assumptions.
432 mailboxInfo->m_image->getTexture()->textureParamsModified(); 443 mailboxInfo->m_image->getTexture()->textureParamsModified();
433 444
434 webContext->bindTexture(GL_TEXTURE_2D, mailboxInfo->m_image->getTexture()->g etTextureHandle()); 445 webContext->bindTexture(GL_TEXTURE_2D, mailboxInfo->m_image->getTexture()->g etTextureHandle());
435 webContext->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); 446 webContext->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
436 webContext->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); 447 webContext->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
437 webContext->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE ); 448 webContext->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE );
438 webContext->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE ); 449 webContext->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE );
439 webContext->produceTextureCHROMIUM(GL_TEXTURE_2D, mailboxInfo->m_mailbox.nam e); 450 webContext->produceTextureCHROMIUM(GL_TEXTURE_2D, mailboxInfo->m_mailbox.nam e);
440 if (isHidden()) { 451 if (isHidden()) {
441 // With hidden canvases, we release the SkImage immediately because 452 // With hidden canvases, we release the SkImage immediately because
442 // there is no need for animations to be double buffered. 453 // there is no need for animations to be double buffered.
443 mailboxInfo->m_image.clear(); 454 mailboxInfo->m_image.clear();
444 } else { 455 } else {
445 webContext->flush(); 456 webContext->flush();
446 mailboxInfo->m_mailbox.syncPoint = webContext->insertSyncPoint(); 457 mailboxInfo->m_mailbox.syncPoint = webContext->insertSyncPoint();
447 } 458 }
448 webContext->bindTexture(GL_TEXTURE_2D, 0); 459 webContext->bindTexture(GL_TEXTURE_2D, 0);
449 // Because we are changing the texture binding without going through skia, 460 // Because we are changing the texture binding without going through skia,
450 // we must dirty the context. 461 // we must dirty the context.
451 m_contextProvider->grContext()->resetContext(kTextureBinding_GrGLBackendStat e); 462 grContext->resetContext(kTextureBinding_GrGLBackendState);
452
453 // set m_parentLayerBridge to make sure 'this' stays alive as long as it has
454 // live mailboxes
455 ASSERT(!mailboxInfo->m_parentLayerBridge);
456 mailboxInfo->m_parentLayerBridge = this;
457 *outMailbox = mailboxInfo->m_mailbox;
458 463
459 return true; 464 return true;
460 } 465 }
461 466
462 Canvas2DLayerBridge::MailboxInfo* Canvas2DLayerBridge::createMailboxInfo() { 467 Canvas2DLayerBridge::MailboxInfo* Canvas2DLayerBridge::createMailboxInfo() {
463 ASSERT(!m_destructionInProgress); 468 ASSERT(!m_destructionInProgress);
464 MailboxInfo* mailboxInfo; 469 MailboxInfo* mailboxInfo;
465 for (mailboxInfo = m_mailboxes.begin(); mailboxInfo < m_mailboxes.end(); mai lboxInfo++) { 470 for (mailboxInfo = m_mailboxes.begin(); mailboxInfo < m_mailboxes.end(); mai lboxInfo++) {
466 if (mailboxInfo->m_status == MailboxAvailable) { 471 if (mailboxInfo->m_status == MailboxAvailable) {
467 return mailboxInfo; 472 return mailboxInfo;
(...skipping 30 matching lines...) Expand all
498 // No need to clean up the mailbox resource, but make sure the 503 // No need to clean up the mailbox resource, but make sure the
499 // mailbox can also be reusable once the context is restored. 504 // mailbox can also be reusable once the context is restored.
500 mailboxInfo->m_status = MailboxAvailable; 505 mailboxInfo->m_status = MailboxAvailable;
501 m_releasedMailboxInfoIndex = InvalidMailboxIndex; 506 m_releasedMailboxInfoIndex = InvalidMailboxIndex;
502 Canvas2DLayerManager::get().layerTransientResourceAllocationChan ged(this); 507 Canvas2DLayerManager::get().layerTransientResourceAllocationChan ged(this);
503 } else if (lostResource) { 508 } else if (lostResource) {
504 // In case of the resource is lost, we need to delete the backin g 509 // In case of the resource is lost, we need to delete the backin g
505 // texture and remove the mailbox from list to avoid reusing it 510 // texture and remove the mailbox from list to avoid reusing it
506 // in future. 511 // in future.
507 if (mailboxInfo->m_image) { 512 if (mailboxInfo->m_image) {
508 mailboxInfo->m_image->getTexture()->resetFlag( 513 if (mailboxInfo->m_image->getTexture()) {
Stephen White 2014/09/09 20:33:06 Nit: refactor out mailboxInfo->m_image->getTexture
509 static_cast<GrTextureFlags>(GrTexture::kReturnToCache_Fl agBit)); 514 mailboxInfo->m_image->getTexture()->resetFlag(
510 mailboxInfo->m_image->getTexture()->textureParamsModified(); 515 static_cast<GrTextureFlags>(GrTexture::kReturnToCach e_FlagBit));
516 mailboxInfo->m_image->getTexture()->textureParamsModifie d();
517 }
511 mailboxInfo->m_image.clear(); 518 mailboxInfo->m_image.clear();
512 } 519 }
513 size_t i = mailboxInfo - m_mailboxes.begin(); 520 if (m_destructionInProgress) {
514 m_mailboxes.remove(i); 521 #if ENABLE(ASSERT)
Stephen White 2014/09/09 20:33:06 Code paths that are conditional on asserts give me
515 Canvas2DLayerManager::get().layerTransientResourceAllocationChan ged(this); 522 mailboxInfo->m_status = MailboxAvailable; // To satisfy asse rt in destructor
516 // Here we need to return early since mailboxInfo removal would 523 #endif
517 // also clear m_parentLayerBridge reference. 524 // The following line may trigger self destruction. We do no t care about
525 // not cleaning up m_mailboxes during destruction sequence b ecause
526 // mailboxes will not be recycled after this point. Calling remove()
527 // could trigger a memory use after free, so we just clear t he self
528 // reference to be safe, and we let the Canvas2DLayerBridge destructor
529 // take care of freeing m_mailboxes.
530 mailboxInfo->m_parentLayerBridge.clear();
531 } else {
532 size_t i = mailboxInfo - m_mailboxes.begin();
533 m_mailboxes.remove(i); // indirectly clears mailboxInfo->m_p arentLayerBridge
534 Canvas2DLayerManager::get().layerTransientResourceAllocation Changed(this);
535 }
536 // mailboxInfo is not valid from this point, so we return immedi ately.
518 return; 537 return;
519 } else { 538 } else {
520 mailboxInfo->m_status = MailboxReleased; 539 mailboxInfo->m_status = MailboxReleased;
521 m_releasedMailboxInfoIndex = mailboxInfo - m_mailboxes.begin(); 540 m_releasedMailboxInfoIndex = mailboxInfo - m_mailboxes.begin();
522 m_framesSinceMailboxRelease = 0; 541 m_framesSinceMailboxRelease = 0;
523 if (isHidden()) { 542 if (isHidden()) {
524 freeReleasedMailbox(); 543 freeReleasedMailbox();
525 } else { 544 } else {
526 ASSERT(!m_destructionInProgress); 545 ASSERT(!m_destructionInProgress);
527 Canvas2DLayerManager::get().layerTransientResourceAllocation Changed(this); 546 Canvas2DLayerManager::get().layerTransientResourceAllocation Changed(this);
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
569 // This copy constructor should only be used for Vector reallocation 588 // This copy constructor should only be used for Vector reallocation
570 // Assuming 'other' is to be destroyed, we transfer m_image and 589 // Assuming 'other' is to be destroyed, we transfer m_image and
571 // m_parentLayerBridge ownership rather than do a refcount dance. 590 // m_parentLayerBridge ownership rather than do a refcount dance.
572 memcpy(&m_mailbox, &other.m_mailbox, sizeof(m_mailbox)); 591 memcpy(&m_mailbox, &other.m_mailbox, sizeof(m_mailbox));
573 m_image = const_cast<MailboxInfo*>(&other)->m_image.release(); 592 m_image = const_cast<MailboxInfo*>(&other)->m_image.release();
574 m_parentLayerBridge = const_cast<MailboxInfo*>(&other)->m_parentLayerBridge. release(); 593 m_parentLayerBridge = const_cast<MailboxInfo*>(&other)->m_parentLayerBridge. release();
575 m_status = other.m_status; 594 m_status = other.m_status;
576 } 595 }
577 596
578 } // namespace blink 597 } // namespace blink
OLDNEW
« no previous file with comments | « no previous file | Source/platform/graphics/Canvas2DLayerBridgeTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698