Skip to content

Commit

Permalink
cc: Add "lost" field to the ReturnedResource type.
Browse files Browse the repository at this point in the history
When a resource is lost in a parent compositor, we inform the child
through the "lost" field in the ReturnedResource. The lost field is
passed down through intermediate parent/child compositors to its
final home.

Lost resources are considered in use by the parent who lost them
since you can not tell when you would be able to write to the texture
safely ever again at that point.

Tests:
ResourceProviderTest.LostResourceInParent
ResourceProviderTest.LostResourceInGrandParent
ResourceProviderTest.LostMailboxInParent
ResourceProviderTest.LostMailboxInGrandParent

R=piman
BUG=263069
Depends on: https://codereview.chromium.org/24078024/

Review URL: https://chromiumcodereview.appspot.com/24290003

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@224792 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
danakj@chromium.org committed Sep 23, 2013
1 parent f9ae4e7 commit 2d1ecef
Show file tree
Hide file tree
Showing 5 changed files with 356 additions and 14 deletions.
29 changes: 19 additions & 10 deletions cc/resources/resource_provider.cc
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ ResourceProvider::Resource::Resource()
image_id(0),
texture_pool(0),
wrap_mode(0),
lost(false),
hint(TextureUsageAny),
type(static_cast<ResourceType>(0)),
format(RGBA_8888) {}
Expand Down Expand Up @@ -147,6 +148,7 @@ ResourceProvider::Resource::Resource(unsigned texture_id,
image_id(0),
texture_pool(texture_pool),
wrap_mode(wrap_mode),
lost(false),
hint(hint),
type(GLTexture),
format(format) {
Expand Down Expand Up @@ -181,6 +183,7 @@ ResourceProvider::Resource::Resource(uint8_t* pixels,
image_id(0),
texture_pool(0),
wrap_mode(wrap_mode),
lost(false),
hint(TextureUsageAny),
type(Bitmap),
format(RGBA_8888) {
Expand Down Expand Up @@ -226,7 +229,13 @@ ResourceProvider::~ResourceProvider() {

bool ResourceProvider::InUseByConsumer(ResourceId id) {
Resource* resource = GetResource(id);
return resource->lock_for_read_count > 0 || resource->exported_count > 0;
return resource->lock_for_read_count > 0 || resource->exported_count > 0 ||
resource->lost;
}

bool ResourceProvider::IsLost(ResourceId id) {
Resource* resource = GetResource(id);
return resource->lost;
}

ResourceProvider::ResourceId ResourceProvider::CreateResource(
Expand Down Expand Up @@ -392,7 +401,7 @@ void ResourceProvider::DeleteResource(ResourceId id) {
void ResourceProvider::DeleteResourceInternal(ResourceMap::iterator it,
DeleteStyle style) {
Resource* resource = &it->second;
bool lost_resource = lost_output_surface_;
bool lost_resource = lost_output_surface_ || resource->lost;

DCHECK(resource->exported_count == 0 || style != Normal);
if (style == ForShutdown && resource->exported_count > 0)
Expand Down Expand Up @@ -624,6 +633,7 @@ const ResourceProvider::Resource* ResourceProvider::LockForWrite(
DCHECK(!resource->lock_for_read_count);
DCHECK_EQ(resource->exported_count, 0);
DCHECK(!resource->external);
DCHECK(!resource->lost);
DCHECK(ReadLockFenceHasPassed(resource));
LazyAllocate(resource);

Expand All @@ -633,11 +643,9 @@ const ResourceProvider::Resource* ResourceProvider::LockForWrite(

bool ResourceProvider::CanLockForWrite(ResourceId id) {
Resource* resource = GetResource(id);
return !resource->locked_for_write &&
!resource->lock_for_read_count &&
!resource->exported_count &&
!resource->external &&
ReadLockFenceHasPassed(resource);
return !resource->locked_for_write && !resource->lock_for_read_count &&
!resource->exported_count && !resource->external && !resource->lost &&
ReadLockFenceHasPassed(resource);
}

void ResourceProvider::UnlockForWrite(ResourceId id) {
Expand Down Expand Up @@ -1020,6 +1028,7 @@ void ResourceProvider::ReceiveReturnsFromParent(

CHECK_GE(resource->exported_count, returned.count);
resource->exported_count -= returned.count;
resource->lost |= returned.lost;
if (resource->exported_count)
continue;

Expand Down Expand Up @@ -1133,7 +1142,7 @@ void ResourceProvider::DeleteAndReturnUnusedResourcesToChild(
ResourceId child_id = child_info->parent_to_child_map[local_id];
DCHECK(child_info->child_to_parent_map.count(child_id));

// TODO(danakj): bool is_lost = false;
bool is_lost = resource.lost || lost_output_surface_;
if (resource.exported_count > 0) {
if (style != ForShutdown) {
// Defer this until we receive the resource back from the parent.
Expand All @@ -1142,7 +1151,7 @@ void ResourceProvider::DeleteAndReturnUnusedResourcesToChild(
}

// We still have an exported_count, so we'll have to lose it.
// TODO(danakj): is_lost = true;
is_lost = true;
}

if (resource.filter != resource.original_filter) {
Expand All @@ -1166,7 +1175,7 @@ void ResourceProvider::DeleteAndReturnUnusedResourcesToChild(
if (!returned.sync_point)
need_sync_point = true;
returned.count = resource.imported_count;
// TODO(danakj): Save the |is_lost| bit.
returned.lost = is_lost;
to_return.push_back(returned);

child_info->parent_to_child_map.erase(local_id);
Expand Down
2 changes: 2 additions & 0 deletions cc/resources/resource_provider.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ class CC_EXPORT ResourceProvider {
// Checks whether a resource is in use by a consumer.
bool InUseByConsumer(ResourceId id);

bool IsLost(ResourceId id);

// Producer interface.

Expand Down Expand Up @@ -392,6 +393,7 @@ class CC_EXPORT ResourceProvider {
unsigned image_id;
GLenum texture_pool;
GLint wrap_mode;
bool lost;
TextureUsageHint hint;
ResourceType type;
ResourceFormat format;
Expand Down
Loading

0 comments on commit 2d1ecef

Please sign in to comment.