Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 471 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 482 // means there is a problem. | 482 // means there is a problem. |
| 483 // For the single-threaded case, this value needs to be at least | 483 // For the single-threaded case, this value needs to be at least |
| 484 // kMaxSwapBuffersPending+1 (in render_widget.h). | 484 // kMaxSwapBuffersPending+1 (in render_widget.h). |
| 485 // Because of crbug.com/247874, it needs to be kMaxSwapBuffersPending+2. | 485 // Because of crbug.com/247874, it needs to be kMaxSwapBuffersPending+2. |
| 486 // TODO(piman): fix this. | 486 // TODO(piman): fix this. |
| 487 ASSERT(m_mailboxes.size() <= 4); | 487 ASSERT(m_mailboxes.size() <= 4); |
| 488 ASSERT(mailboxInfo < m_mailboxes.end()); | 488 ASSERT(mailboxInfo < m_mailboxes.end()); |
| 489 return mailboxInfo; | 489 return mailboxInfo; |
| 490 } | 490 } |
| 491 | 491 |
| 492 void Canvas2DLayerBridge::mailboxReleased(const blink::WebExternalTextureMailbox & mailbox) | 492 void Canvas2DLayerBridge::mailboxReleased(const blink::WebExternalTextureMailbox & mailbox, bool lostResource) |
| 493 { | 493 { |
| 494 freeReleasedMailbox(); // Never have more than one mailbox in the released s tate. | 494 freeReleasedMailbox(); // Never have more than one mailbox in the released s tate. |
| 495 bool contextLost = m_contextProvider->context3d()->isContextLost() || !m_isS urfaceValid; | |
| 495 Vector<MailboxInfo>::iterator mailboxInfo; | 496 Vector<MailboxInfo>::iterator mailboxInfo; |
| 496 for (mailboxInfo = m_mailboxes.begin(); mailboxInfo < m_mailboxes.end(); ++m ailboxInfo) { | 497 for (mailboxInfo = m_mailboxes.begin(); mailboxInfo < m_mailboxes.end(); ++m ailboxInfo) { |
| 497 if (nameEquals(mailboxInfo->m_mailbox, mailbox)) { | 498 if (nameEquals(mailboxInfo->m_mailbox, mailbox)) { |
| 498 mailboxInfo->m_mailbox.syncPoint = mailbox.syncPoint; | 499 mailboxInfo->m_mailbox.syncPoint = mailbox.syncPoint; |
| 499 ASSERT(mailboxInfo->m_status == MailboxInUse); | 500 ASSERT(mailboxInfo->m_status == MailboxInUse); |
| 500 mailboxInfo->m_status = MailboxReleased; | |
| 501 // Trigger Canvas2DLayerBridge self-destruction if this is the | 501 // Trigger Canvas2DLayerBridge self-destruction if this is the |
| 502 // last live mailbox and the layer bridge is not externally | 502 // last live mailbox and the layer bridge is not externally |
| 503 // referenced. | 503 // referenced. |
| 504 ASSERT(mailboxInfo->m_parentLayerBridge.get() == this); | |
| 505 mailboxInfo->m_parentLayerBridge.clear(); | |
| 506 | |
| 507 if (contextLost) { | |
| 508 // No need to clean up the mailbox resource, but make sure the | |
| 509 // mailbox can also be reusable once the context is restored. | |
| 510 mailboxInfo->m_status = MailboxAvailable; | |
| 511 m_releasedMailboxInfoIndex = InvalidMailboxIndex; | |
| 512 Canvas2DLayerManager::get().layerTransientResourceAllocationChan ged(this); | |
| 513 return; | |
| 514 } | |
| 515 | |
| 516 // In case of the resource is lost, we need to delete the backing te xture | |
| 517 // and remove the mailbox from list to avoid reusing it in future. | |
| 518 if (lostResource) { | |
| 519 if (mailboxInfo->m_image) { | |
| 520 mailboxInfo->m_image->getTexture()->resetFlag( | |
| 521 static_cast<GrTextureFlags>(GrTexture::kReturnToCache_Fl agBit)); | |
| 522 mailboxInfo->m_image->getTexture()->textureParamsModified(); | |
| 523 mailboxInfo->m_image.clear(); | |
| 524 } | |
| 525 size_t i = mailboxInfo - m_mailboxes.begin(); | |
| 526 m_mailboxes.remove(i); | |
| 527 Canvas2DLayerManager::get().layerTransientResourceAllocationChan ged(this); | |
| 528 return; | |
|
Justin Novosad
2014/07/15 16:12:03
More readable if you put the code below inside an
Hongbo Min
2014/07/16 01:32:20
Done.
| |
| 529 } | |
| 530 | |
| 531 mailboxInfo->m_status = MailboxReleased; | |
| 504 m_releasedMailboxInfoIndex = mailboxInfo - m_mailboxes.begin(); | 532 m_releasedMailboxInfoIndex = mailboxInfo - m_mailboxes.begin(); |
| 505 m_framesSinceMailboxRelease = 0; | 533 m_framesSinceMailboxRelease = 0; |
| 506 if (isHidden()) { | 534 if (isHidden()) { |
| 507 freeReleasedMailbox(); | 535 freeReleasedMailbox(); |
| 508 } else { | 536 } else { |
| 509 ASSERT(!m_destructionInProgress); | 537 ASSERT(!m_destructionInProgress); |
| 510 Canvas2DLayerManager::get().layerTransientResourceAllocationChan ged(this); | 538 Canvas2DLayerManager::get().layerTransientResourceAllocationChan ged(this); |
| 511 } | 539 } |
| 512 ASSERT(mailboxInfo->m_parentLayerBridge.get() == this); | |
| 513 mailboxInfo->m_parentLayerBridge.clear(); | |
| 514 return; | 540 return; |
| 515 } | 541 } |
| 516 } | 542 } |
| 517 } | 543 } |
| 518 | 544 |
| 519 blink::WebLayer* Canvas2DLayerBridge::layer() const | 545 blink::WebLayer* Canvas2DLayerBridge::layer() const |
| 520 { | 546 { |
| 521 ASSERT(!m_destructionInProgress); | 547 ASSERT(!m_destructionInProgress); |
| 522 ASSERT(m_layer); | 548 ASSERT(m_layer); |
| 523 return m_layer->layer(); | 549 return m_layer->layer(); |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 548 Canvas2DLayerBridge::MailboxInfo::MailboxInfo(const MailboxInfo& other) { | 574 Canvas2DLayerBridge::MailboxInfo::MailboxInfo(const MailboxInfo& other) { |
| 549 // This copy constructor should only be used for Vector reallocation | 575 // This copy constructor should only be used for Vector reallocation |
| 550 // Assuming 'other' is to be destroyed, we transfer m_image ownership | 576 // Assuming 'other' is to be destroyed, we transfer m_image ownership |
| 551 // rather than do a refcount dance. | 577 // rather than do a refcount dance. |
| 552 memcpy(&m_mailbox, &other.m_mailbox, sizeof(m_mailbox)); | 578 memcpy(&m_mailbox, &other.m_mailbox, sizeof(m_mailbox)); |
| 553 m_image = const_cast<MailboxInfo*>(&other)->m_image.release(); | 579 m_image = const_cast<MailboxInfo*>(&other)->m_image.release(); |
| 554 m_status = other.m_status; | 580 m_status = other.m_status; |
| 555 } | 581 } |
| 556 | 582 |
| 557 } | 583 } |
| OLD | NEW |