Index: cc/resources/resource_provider.cc |
diff --git a/cc/resources/resource_provider.cc b/cc/resources/resource_provider.cc |
index 11eaab07a287c4d3282aa24e8a17c9dda2da8ef9..02bf48e7dbe85367d04c74954c3ef26d3ae08d31 100644 |
--- a/cc/resources/resource_provider.cc |
+++ b/cc/resources/resource_provider.cc |
@@ -73,9 +73,10 @@ ResourceProvider::Resource::Resource() |
pixels(NULL), |
pixel_buffer(NULL), |
lock_for_read_count(0), |
+ imported_count(0), |
+ exported_count(0), |
locked_for_write(false), |
external(false), |
- exported(false), |
marked_for_deletion(false), |
pending_set_pixels(false), |
set_pixels_completion_forced(false), |
@@ -105,9 +106,10 @@ ResourceProvider::Resource::Resource( |
pixels(NULL), |
pixel_buffer(NULL), |
lock_for_read_count(0), |
+ imported_count(0), |
+ exported_count(0), |
locked_for_write(false), |
external(false), |
- exported(false), |
marked_for_deletion(false), |
pending_set_pixels(false), |
set_pixels_completion_forced(false), |
@@ -130,9 +132,10 @@ ResourceProvider::Resource::Resource( |
pixels(pixels), |
pixel_buffer(NULL), |
lock_for_read_count(0), |
+ imported_count(0), |
+ exported_count(0), |
locked_for_write(false), |
external(false), |
- exported(false), |
marked_for_deletion(false), |
pending_set_pixels(false), |
set_pixels_completion_forced(false), |
@@ -189,7 +192,7 @@ bool ResourceProvider::InUseByConsumer(ResourceId id) { |
ResourceMap::iterator it = resources_.find(id); |
CHECK(it != resources_.end()); |
Resource* resource = &it->second; |
- return !!resource->lock_for_read_count || resource->exported; |
+ return !!resource->lock_for_read_count || !!resource->exported_count; |
danakj
2013/08/15 21:30:53
nit: i like x>0 a lot more than !!x for integers
piman
2013/08/16 04:29:55
Done.
|
} |
ResourceProvider::ResourceId ResourceProvider::CreateResource( |
@@ -311,7 +314,7 @@ void ResourceProvider::DeleteResource(ResourceId id) { |
DCHECK(!resource->marked_for_deletion); |
danakj
2013/08/15 21:30:53
Can we DCHECK(!imported_count)? Is it okay to dele
danakj
2013/08/15 21:32:01
Oops, bad reviewer. I mean DCHECK_EQ(0, imported_c
piman
2013/08/16 04:29:55
DCHECK_EQ(imported_count, 0).
DCHECK doesn't diffe
|
DCHECK(resource->pending_set_pixels || !resource->locked_for_write); |
- if (resource->exported) { |
+ if (!!resource->exported_count) { |
resource->marked_for_deletion = true; |
return; |
} else { |
@@ -324,8 +327,8 @@ void ResourceProvider::DeleteResourceInternal(ResourceMap::iterator it, |
Resource* resource = &it->second; |
bool lost_resource = lost_output_surface_; |
- DCHECK(!resource->exported || style != Normal); |
- if (style == ForShutdown && resource->exported) |
+ DCHECK(!resource->exported_count || style != Normal); |
+ if (style == ForShutdown && !!resource->exported_count) |
lost_resource = true; |
if (resource->image_id) { |
@@ -396,7 +399,7 @@ void ResourceProvider::SetPixels(ResourceId id, |
DCHECK(!resource->locked_for_write); |
DCHECK(!resource->lock_for_read_count); |
DCHECK(!resource->external); |
- DCHECK(!resource->exported); |
+ DCHECK(!resource->exported_count); |
DCHECK(ReadLockFenceHasPassed(resource)); |
LazyAllocate(resource); |
@@ -503,7 +506,7 @@ const ResourceProvider::Resource* ResourceProvider::LockForRead(ResourceId id) { |
resource->set_pixels_completion_forced) << |
"locked for write: " << resource->locked_for_write << |
" pixels completion forced: " << resource->set_pixels_completion_forced; |
- DCHECK(!resource->exported); |
+ DCHECK(!resource->exported_count); |
// Uninitialized! Call SetPixels or LockForWrite first. |
DCHECK(resource->allocated); |
@@ -539,7 +542,7 @@ void ResourceProvider::UnlockForRead(ResourceId id) { |
CHECK(it != resources_.end()); |
Resource* resource = &it->second; |
DCHECK_GT(resource->lock_for_read_count, 0); |
- DCHECK(!resource->exported); |
+ DCHECK(!resource->exported_count); |
resource->lock_for_read_count--; |
} |
@@ -551,7 +554,7 @@ const ResourceProvider::Resource* ResourceProvider::LockForWrite( |
Resource* resource = &it->second; |
DCHECK(!resource->locked_for_write); |
DCHECK(!resource->lock_for_read_count); |
- DCHECK(!resource->exported); |
+ DCHECK(!resource->exported_count); |
DCHECK(!resource->external); |
DCHECK(ReadLockFenceHasPassed(resource)); |
LazyAllocate(resource); |
@@ -567,7 +570,7 @@ bool ResourceProvider::CanLockForWrite(ResourceId id) { |
Resource* resource = &it->second; |
return !resource->locked_for_write && |
!resource->lock_for_read_count && |
- !resource->exported && |
+ !resource->exported_count && |
!resource->external && |
ReadLockFenceHasPassed(resource); |
} |
@@ -578,7 +581,7 @@ void ResourceProvider::UnlockForWrite(ResourceId id) { |
CHECK(it != resources_.end()); |
Resource* resource = &it->second; |
DCHECK(resource->locked_for_write); |
- DCHECK(!resource->exported); |
+ DCHECK(!resource->exported_count); |
DCHECK(!resource->external); |
resource->locked_for_write = false; |
} |
@@ -795,12 +798,11 @@ void ResourceProvider::PrepareSendToParent(const ResourceIdArray& resources, |
it != resources.end(); |
++it) { |
TransferableResource resource; |
- if (TransferResource(context3d, *it, &resource)) { |
- if (!resource.sync_point) |
- need_sync_point = true; |
- resources_.find(*it)->second.exported = true; |
- list->push_back(resource); |
- } |
+ TransferResource(context3d, *it, &resource); |
+ if (!resource.sync_point) |
+ need_sync_point = true; |
+ ++resources_.find(*it)->second.exported_count; |
+ list->push_back(resource); |
} |
if (need_sync_point) { |
unsigned int sync_point = context3d->insertSyncPoint(); |
@@ -828,8 +830,7 @@ void ResourceProvider::PrepareSendToChild(int child, |
it != resources.end(); |
++it) { |
TransferableResource resource; |
- if (!TransferResource(context3d, *it, &resource)) |
- NOTREACHED(); |
+ TransferResource(context3d, *it, &resource); |
if (!resource.sync_point) |
need_sync_point = true; |
DCHECK(child_info.parent_to_child_map.find(*it) != |
@@ -837,7 +838,8 @@ void ResourceProvider::PrepareSendToChild(int child, |
resource.id = child_info.parent_to_child_map[*it]; |
child_info.parent_to_child_map.erase(*it); |
child_info.child_to_parent_map.erase(resource.id); |
- list->push_back(resource); |
+ for (unsigned i = 0; i < resources_[*it].imported_count; ++i) |
danakj
2013/08/15 21:30:53
int
piman
2013/08/16 04:29:55
Done.
|
+ list->push_back(resource); |
danakj
2013/08/15 21:30:53
You'd need to --imported_count to DCHECK in the De
piman
2013/08/16 04:29:55
Done.
|
DeleteResource(*it); |
} |
if (need_sync_point) { |
@@ -863,6 +865,11 @@ void ResourceProvider::ReceiveFromChild( |
for (TransferableResourceArray::const_iterator it = resources.begin(); |
it != resources.end(); |
++it) { |
+ if (child_info.child_to_parent_map.find(it->id) != |
+ child_info.child_to_parent_map.end()) { |
+ resources_[child_info.child_to_parent_map[it->id]].imported_count++; |
danakj
2013/08/15 21:30:53
We just did a find() on line 868. Save the iterato
piman
2013/08/16 04:29:55
Done.
|
+ continue; |
+ } |
unsigned texture_id; |
// NOTE: If the parent is a browser and the child a renderer, the parent |
// is not supposed to have its context wait, because that could induce |
@@ -882,6 +889,7 @@ void ResourceProvider::ReceiveFromChild( |
resource.mailbox.SetName(it->mailbox); |
// Don't allocate a texture for a child. |
resource.allocated = true; |
+ resource.imported_count = 1; |
resources_[id] = resource; |
child_info.parent_to_child_map[id] = it->id; |
child_info.child_to_parent_map[it->id] = id; |
@@ -902,8 +910,10 @@ void ResourceProvider::ReceiveFromParent( |
ResourceMap::iterator map_iterator = resources_.find(it->id); |
DCHECK(map_iterator != resources_.end()); |
Resource* resource = &map_iterator->second; |
- DCHECK(resource->exported); |
- resource->exported = false; |
+ DCHECK(!!resource->exported_count); |
danakj
2013/08/15 21:30:53
DCHECK_GT?
piman
2013/08/16 04:29:55
Done.
|
+ --resource->exported_count; |
+ if (resource->exported_count) |
+ continue; |
resource->filter = it->filter; |
DCHECK(resource->mailbox.ContainsMailbox(it->mailbox)); |
if (resource->gl_id) { |
@@ -919,7 +929,7 @@ void ResourceProvider::ReceiveFromParent( |
} |
} |
-bool ResourceProvider::TransferResource(WebGraphicsContext3D* context, |
+void ResourceProvider::TransferResource(WebGraphicsContext3D* context, |
ResourceId id, |
TransferableResource* resource) { |
DCHECK(thread_checker_.CalledOnValidThread()); |
@@ -930,8 +940,6 @@ bool ResourceProvider::TransferResource(WebGraphicsContext3D* context, |
DCHECK(!source->lock_for_read_count); |
DCHECK(!source->external || (source->external && source->mailbox.IsValid())); |
DCHECK(source->allocated); |
- if (source->exported) |
- return false; |
resource->id = id; |
resource->format = source->format; |
resource->filter = source->filter; |
@@ -956,8 +964,6 @@ bool ResourceProvider::TransferResource(WebGraphicsContext3D* context, |
resource->sync_point = source->mailbox.sync_point(); |
source->mailbox.ResetSyncPoint(); |
} |
- |
- return true; |
} |
void ResourceProvider::AcquirePixelBuffer(ResourceId id) { |
@@ -966,7 +972,7 @@ void ResourceProvider::AcquirePixelBuffer(ResourceId id) { |
CHECK(it != resources_.end()); |
Resource* resource = &it->second; |
DCHECK(!resource->external); |
- DCHECK(!resource->exported); |
+ DCHECK(!resource->exported_count); |
DCHECK(!resource->image_id); |
if (resource->type == GLTexture) { |
@@ -999,7 +1005,7 @@ void ResourceProvider::ReleasePixelBuffer(ResourceId id) { |
CHECK(it != resources_.end()); |
Resource* resource = &it->second; |
DCHECK(!resource->external); |
- DCHECK(!resource->exported); |
+ DCHECK(!resource->exported_count); |
DCHECK(!resource->image_id); |
// The pixel buffer can be released while there is a pending "set pixels" |
@@ -1044,7 +1050,7 @@ uint8_t* ResourceProvider::MapPixelBuffer(ResourceId id) { |
CHECK(it != resources_.end()); |
Resource* resource = &it->second; |
DCHECK(!resource->external); |
- DCHECK(!resource->exported); |
+ DCHECK(!resource->exported_count); |
DCHECK(!resource->image_id); |
if (resource->type == GLTexture) { |
@@ -1075,7 +1081,7 @@ void ResourceProvider::UnmapPixelBuffer(ResourceId id) { |
CHECK(it != resources_.end()); |
Resource* resource = &it->second; |
DCHECK(!resource->external); |
- DCHECK(!resource->exported); |
+ DCHECK(!resource->exported_count); |
DCHECK(!resource->image_id); |
if (resource->type == GLTexture) { |
@@ -1342,7 +1348,7 @@ void ResourceProvider::AcquireImage(ResourceId id) { |
Resource* resource = &it->second; |
DCHECK(!resource->external); |
- DCHECK(!resource->exported); |
+ DCHECK(!resource->exported_count); |
if (resource->type != GLTexture) |
return; |
@@ -1365,7 +1371,7 @@ void ResourceProvider::ReleaseImage(ResourceId id) { |
Resource* resource = &it->second; |
DCHECK(!resource->external); |
- DCHECK(!resource->exported); |
+ DCHECK(!resource->exported_count); |
if (!resource->image_id) |
return; |
@@ -1385,7 +1391,7 @@ uint8_t* ResourceProvider::MapImage(ResourceId id) { |
DCHECK(ReadLockFenceHasPassed(resource)); |
DCHECK(!resource->external); |
- DCHECK(!resource->exported); |
+ DCHECK(!resource->exported_count); |
if (resource->image_id) { |
WebGraphicsContext3D* context3d = output_surface_->context3d(); |
@@ -1407,7 +1413,7 @@ void ResourceProvider::UnmapImage(ResourceId id) { |
Resource* resource = &it->second; |
DCHECK(!resource->external); |
- DCHECK(!resource->exported); |
+ DCHECK(!resource->exported_count); |
if (resource->image_id) { |
WebGraphicsContext3D* context3d = output_surface_->context3d(); |
@@ -1423,7 +1429,7 @@ int ResourceProvider::GetImageStride(ResourceId id) { |
Resource* resource = &it->second; |
DCHECK(!resource->external); |
- DCHECK(!resource->exported); |
+ DCHECK(!resource->exported_count); |
int stride = 0; |