Commit 6aa45354 authored by dyen's avatar dyen Committed by Commit bot

Added methods to generate sync tokens for resource id(s).

New functions have been added so a sync token can represent
multiple resources at once. Adding a single sync token at
the end of generating a multitude of resources can be a win.

The most obvious use cases of this is the video layer which
generates a resource for each layer. A single sync token is
now generated at the end of the layer generation.

The layer tree UI resource also generates its own sync token.

BUG=584381
CQ_INCLUDE_TRYBOTS=tryserver.blink:linux_blink_rel

Review URL: https://codereview.chromium.org/1707143002

Cr-Commit-Position: refs/heads/master@{#376039}
parent d77a90d6
......@@ -124,6 +124,8 @@ bool VideoLayerImpl::WillDraw(DrawMode draw_mode,
DCHECK_EQ(external_resources.mailboxes.size(),
external_resources.release_callbacks.size());
ResourceProvider::ResourceIdArray resource_ids;
resource_ids.reserve(external_resources.mailboxes.size());
for (size_t i = 0; i < external_resources.mailboxes.size(); ++i) {
unsigned resource_id = resource_provider->CreateResourceFromTextureMailbox(
external_resources.mailboxes[i],
......@@ -133,7 +135,9 @@ bool VideoLayerImpl::WillDraw(DrawMode draw_mode,
frame_resources_.push_back(FrameResource(
resource_id, external_resources.mailboxes[i].size_in_pixels(),
external_resources.mailboxes[i].is_overlay_candidate()));
resource_ids.push_back(resource_id);
}
resource_provider->GenerateSyncTokenForResources(resource_ids);
return true;
}
......
......@@ -753,6 +753,44 @@ void ResourceProvider::CopyToResource(ResourceId id,
}
}
void ResourceProvider::GenerateSyncTokenForResource(ResourceId resource_id) {
Resource* resource = GetResource(resource_id);
if (!resource->needs_sync_token())
return;
gpu::SyncToken sync_token;
GLES2Interface* gl = ContextGL();
DCHECK(gl);
const uint64_t fence_sync = gl->InsertFenceSyncCHROMIUM();
gl->OrderingBarrierCHROMIUM();
gl->GenUnverifiedSyncTokenCHROMIUM(fence_sync, sync_token.GetData());
resource->UpdateSyncToken(sync_token);
}
void ResourceProvider::GenerateSyncTokenForResources(
const ResourceIdArray& resource_ids) {
gpu::SyncToken sync_token;
bool created_sync_token = false;
for (ResourceId id : resource_ids) {
Resource* resource = GetResource(id);
if (resource->needs_sync_token()) {
if (!created_sync_token) {
GLES2Interface* gl = ContextGL();
DCHECK(gl);
const uint64_t fence_sync = gl->InsertFenceSyncCHROMIUM();
gl->OrderingBarrierCHROMIUM();
gl->GenUnverifiedSyncTokenCHROMIUM(fence_sync, sync_token.GetData());
created_sync_token = true;
}
resource->UpdateSyncToken(sync_token);
}
}
}
ResourceProvider::Resource* ResourceProvider::InsertResource(
ResourceId id,
const Resource& resource) {
......
......@@ -159,9 +159,9 @@ class CC_EXPORT ResourceProvider
const uint8_t* image,
const gfx::Size& image_size);
// Only flush the command buffer if supported.
// Returns true if the shallow flush occurred, false otherwise.
bool ShallowFlushIfSupported();
// Generates sync tokesn for resources which need a sync token.
void GenerateSyncTokenForResource(ResourceId resource_id);
void GenerateSyncTokenForResources(const ResourceIdArray& resource_ids);
// Creates accounting for a child. Returns a child ID.
int CreateChild(const ReturnCallback& return_callback);
......
......@@ -3648,6 +3648,8 @@ void LayerTreeHostImpl::CreateUIResource(UIResourceId uid,
AutoLockUIResourceBitmap bitmap_lock(bitmap);
resource_provider_->CopyToResource(id, bitmap_lock.GetPixels(),
bitmap.GetSize());
resource_provider_->GenerateSyncTokenForResource(id);
MarkUIResourceNotEvicted(uid);
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment