[go: nahoru, domu]

Vend resources from ResourcePool with an RAII object.

This RAII object, InUsePoolResource wraps an underlying backing from
the ResourcePool, and verifies at runtime that the object is passed
back to the ResourcePool exactly once to indicate the backing is no
longer in use and release it into the pool again.

The RAII object exposes the backing but requires the caller to know if
they are expecting a software or gpu backing when they ask for it. This
means that TileManager can no longer try to access the backing, and must
always go through the RasterBufferProvider. It was already doing this
mostly, but the API was a bit lazy and leaked the backing info (the
ResourceId) into TileManager in a couple places, so we must resolve
that and make it use InUsePoolResource exclusively.

PictureLayerImpl grabs a ResourceId off the TileDrawInfo as before, but
it is explicitly marked as an id meant for export to the display
compositor, as opposed to a backing that can be written to. For now
the backing is still a ResourceId for both software/gpu and it is
written to via the ResourceProvider locks, but this sets us up to be
able to change that.

R=vmpstr@chromium.org

Bug: 730660
Cq-Include-Trybots: master.tryserver.blink:linux_trusty_blink_rel;master.tryserver.chromium.android:android_optional_gpu_tests_rel
Change-Id: I79292834482a8d1a3858d61a8313f14b3221337e
Reviewed-on: https://chromium-review.googlesource.com/868713
Reviewed-by: vmpstr <vmpstr@chromium.org>
Commit-Queue: danakj <danakj@chromium.org>
Cr-Commit-Position: refs/heads/master@{#530286}
diff --git a/cc/raster/gpu_raster_buffer_provider.cc b/cc/raster/gpu_raster_buffer_provider.cc
index f6fe0f54a..f98568ce 100644
--- a/cc/raster/gpu_raster_buffer_provider.cc
+++ b/cc/raster/gpu_raster_buffer_provider.cc
@@ -188,13 +188,14 @@
 }
 
 std::unique_ptr<RasterBuffer> GpuRasterBufferProvider::AcquireBufferForRaster(
-    const Resource* resource,
+    const ResourcePool::InUsePoolResource& resource,
     uint64_t resource_content_id,
     uint64_t previous_content_id) {
   bool resource_has_previous_content =
       resource_content_id && resource_content_id == previous_content_id;
-  return std::make_unique<RasterBufferImpl>(
-      this, resource_provider_, resource->id(), resource_has_previous_content);
+  return std::make_unique<RasterBufferImpl>(this, resource_provider_,
+                                            resource.gpu_backing_resource_id(),
+                                            resource_has_previous_content);
 }
 
 void GpuRasterBufferProvider::OrderingBarrier() {
@@ -238,9 +239,9 @@
 }
 
 bool GpuRasterBufferProvider::IsResourceReadyToDraw(
-    viz::ResourceId resource_id) const {
-  gpu::SyncToken sync_token =
-      resource_provider_->GetSyncTokenForResources({resource_id});
+    const ResourcePool::InUsePoolResource& resource) const {
+  gpu::SyncToken sync_token = resource_provider_->GetSyncTokenForResources(
+      {resource.gpu_backing_resource_id()});
   if (!sync_token.HasData())
     return true;
 
@@ -250,9 +251,13 @@
 }
 
 uint64_t GpuRasterBufferProvider::SetReadyToDrawCallback(
-    const ResourceProvider::ResourceIdArray& resource_ids,
+    const std::vector<const ResourcePool::InUsePoolResource*>& resources,
     const base::Closure& callback,
     uint64_t pending_callback_id) const {
+  std::vector<viz::ResourceId> resource_ids;
+  resource_ids.reserve(resources.size());
+  for (auto* resource : resources)
+    resource_ids.push_back(resource->gpu_backing_resource_id());
   gpu::SyncToken sync_token =
       resource_provider_->GetSyncTokenForResources(resource_ids);
   uint64_t callback_id = sync_token.release_count();