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

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

Issue 369043003: Let canvas decide how to handle the case of resource lost reported by client: 2D part (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: release mailbox immediately if resource is lost Created 6 years, 5 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 /* 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 305 matching lines...) Expand 10 before | Expand all | Expand 10 after
316 if (!mailboxInfo) 316 if (!mailboxInfo)
317 return; 317 return;
318 318
319 ASSERT(mailboxInfo->m_status == MailboxReleased); 319 ASSERT(mailboxInfo->m_status == MailboxReleased);
320 if (mailboxInfo->m_mailbox.syncPoint) { 320 if (mailboxInfo->m_mailbox.syncPoint) {
321 context()->waitSyncPoint(mailboxInfo->m_mailbox.syncPoint); 321 context()->waitSyncPoint(mailboxInfo->m_mailbox.syncPoint);
322 mailboxInfo->m_mailbox.syncPoint = 0; 322 mailboxInfo->m_mailbox.syncPoint = 0;
323 } 323 }
324 // Invalidate texture state in case the compositor altered it since the copy -on-write. 324 // Invalidate texture state in case the compositor altered it since the copy -on-write.
325 if (mailboxInfo->m_image) { 325 if (mailboxInfo->m_image) {
326 if (isHidden() || releasedMailboxHasExpired()) 326 if (isHidden() || releasedMailboxHasExpired())
dshwang 2014/07/09 08:14:50 Is "|| lostResource" needed?
Justin Novosad 2014/07/11 17:22:38 Not necessary. If we are in a state where resource
327 mailboxInfo->m_image->getTexture()->resetFlag(static_cast<GrTextureF lags>(GrTexture::kReturnToCache_FlagBit)); 327 mailboxInfo->m_image->getTexture()->resetFlag(static_cast<GrTextureF lags>(GrTexture::kReturnToCache_FlagBit));
328 mailboxInfo->m_image->getTexture()->textureParamsModified(); 328 mailboxInfo->m_image->getTexture()->textureParamsModified();
329 mailboxInfo->m_image.clear(); 329 mailboxInfo->m_image.clear();
330 } 330 }
331 mailboxInfo->m_status = MailboxAvailable; 331 mailboxInfo->m_status = MailboxAvailable;
332 m_releasedMailboxInfoIndex = InvalidMailboxIndex; 332 m_releasedMailboxInfoIndex = InvalidMailboxIndex;
333 Canvas2DLayerManager::get().layerTransientResourceAllocationChanged(this); 333 Canvas2DLayerManager::get().layerTransientResourceAllocationChanged(this);
334 } 334 }
335 335
336 blink::WebGraphicsContext3D* Canvas2DLayerBridge::context() 336 blink::WebGraphicsContext3D* Canvas2DLayerBridge::context()
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 m_releasedMailboxInfoIndex = mailboxInfo - m_mailboxes.begin();
505 m_framesSinceMailboxRelease = 0;
506 if (isHidden()) {
507 freeReleasedMailbox();
508 } else {
509 ASSERT(!m_destructionInProgress);
510 Canvas2DLayerManager::get().layerTransientResourceAllocationChan ged(this);
511 }
512 ASSERT(mailboxInfo->m_parentLayerBridge.get() == this); 504 ASSERT(mailboxInfo->m_parentLayerBridge.get() == this);
513 mailboxInfo->m_parentLayerBridge.clear(); 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);
dshwang 2014/07/09 08:14:50 Do we need to remove the given mailboxInfo from m_
Justin Novosad 2014/07/11 17:22:38 That is a good question. A generated mailbox is no
danakj 2014/07/11 17:31:07 To be sure we're on the same page the |lostResourc
513 } else {
514 mailboxInfo->m_status = MailboxReleased;
515 m_releasedMailboxInfoIndex = mailboxInfo - m_mailboxes.begin();
516 m_framesSinceMailboxRelease = 0;
517 if (isHidden() || lostResource) {
Justin Novosad 2014/07/11 18:05:05 According to Dana's most recent comment, we probab
Hongbo Min 2014/07/15 13:51:13 To make code much clean, I reset the syncPoint to
518 freeReleasedMailbox();
519 } else {
520 ASSERT(!m_destructionInProgress);
521 Canvas2DLayerManager::get().layerTransientResourceAllocation Changed(this);
522 }
523 }
514 return; 524 return;
515 } 525 }
516 } 526 }
517 } 527 }
518 528
519 blink::WebLayer* Canvas2DLayerBridge::layer() const 529 blink::WebLayer* Canvas2DLayerBridge::layer() const
520 { 530 {
521 ASSERT(!m_destructionInProgress); 531 ASSERT(!m_destructionInProgress);
522 ASSERT(m_layer); 532 ASSERT(m_layer);
523 return m_layer->layer(); 533 return m_layer->layer();
(...skipping 24 matching lines...) Expand all
548 Canvas2DLayerBridge::MailboxInfo::MailboxInfo(const MailboxInfo& other) { 558 Canvas2DLayerBridge::MailboxInfo::MailboxInfo(const MailboxInfo& other) {
549 // This copy constructor should only be used for Vector reallocation 559 // This copy constructor should only be used for Vector reallocation
550 // Assuming 'other' is to be destroyed, we transfer m_image ownership 560 // Assuming 'other' is to be destroyed, we transfer m_image ownership
551 // rather than do a refcount dance. 561 // rather than do a refcount dance.
552 memcpy(&m_mailbox, &other.m_mailbox, sizeof(m_mailbox)); 562 memcpy(&m_mailbox, &other.m_mailbox, sizeof(m_mailbox));
553 m_image = const_cast<MailboxInfo*>(&other)->m_image.release(); 563 m_image = const_cast<MailboxInfo*>(&other)->m_image.release();
554 m_status = other.m_status; 564 m_status = other.m_status;
555 } 565 }
556 566
557 } 567 }
OLDNEW
« no previous file with comments | « Source/platform/graphics/Canvas2DLayerBridge.h ('k') | Source/platform/graphics/gpu/DrawingBuffer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698