[go: nahoru, domu]

Delay activation/draw on GPU tile work completion

Design doc: https://goo.gl/Ku9VBh

This change delays the activation of the pending tree as well as
drawing of active tree tiles on the completion of the required GL
work in the GPU process. This differs from our current
approach, where we only delay activation/draw on the issuing of GL
commands in the renderer, not on the commands being executed in the
GL process.

Note that this behavior is only added in cases where we've enabled the
async worker context via flags.

BUG=673434
CQ_INCLUDE_TRYBOTS=master.tryserver.blink:linux_trusty_blink_rel

Review-Url: https://codereview.chromium.org/2555743004
Cr-Commit-Position: refs/heads/master@{#447346}
diff --git a/cc/raster/gpu_raster_buffer_provider.cc b/cc/raster/gpu_raster_buffer_provider.cc
index 97fb581..d874928 100644
--- a/cc/raster/gpu_raster_buffer_provider.cc
+++ b/cc/raster/gpu_raster_buffer_provider.cc
@@ -17,6 +17,7 @@
 #include "cc/playback/raster_source.h"
 #include "cc/raster/scoped_gpu_raster.h"
 #include "cc/resources/resource.h"
+#include "gpu/command_buffer/client/context_support.h"
 #include "gpu/command_buffer/client/gles2_interface.h"
 #include "third_party/skia/include/core/SkMultiPictureDraw.h"
 #include "third_party/skia/include/core/SkPictureRecorder.h"
@@ -186,6 +187,47 @@
   return msaa_sample_count_ == 0;
 }
 
+bool GpuRasterBufferProvider::IsResourceReadyToDraw(
+    ResourceId resource_id) const {
+  if (!async_worker_context_enabled_)
+    return true;
+
+  ResourceProvider::ResourceIdArray resources;
+  resources.push_back(resource_id);
+  gpu::SyncToken sync_token =
+      resource_provider_->GetSyncTokenForResources(resources);
+  if (!sync_token.HasData())
+    return true;
+
+  // IsSyncTokenSignalled is threadsafe, no need for worker context lock.
+  return worker_context_provider_->ContextSupport()->IsSyncTokenSignalled(
+      sync_token);
+}
+
+uint64_t GpuRasterBufferProvider::SetReadyToDrawCallback(
+    const ResourceProvider::ResourceIdArray& resource_ids,
+    const base::Closure& callback,
+    uint64_t pending_callback_id) const {
+  if (!async_worker_context_enabled_)
+    return 0;
+
+  gpu::SyncToken sync_token =
+      resource_provider_->GetSyncTokenForResources(resource_ids);
+  uint64_t callback_id = sync_token.release_count();
+  DCHECK_NE(callback_id, 0u);
+
+  // If the callback is different from the one the caller is already waiting on,
+  // pass the callback through to SignalSinkToken. Otherwise the request is
+  // redundant.
+  if (callback_id != pending_callback_id) {
+    // SignalSyncToken is threadsafe, no need for worker context lock.
+    worker_context_provider_->ContextSupport()->SignalSyncToken(sync_token,
+                                                                callback);
+  }
+
+  return callback_id;
+}
+
 void GpuRasterBufferProvider::Shutdown() {
   pending_raster_buffers_.clear();
 }