Commit 1e141107 authored by Andres Calderon Jaramillo's avatar Andres Calderon Jaramillo Committed by Commit Bot

Let ClientTransferCache lock entries without creating on the service.

This CL adds a method to ClientTransferCache that allows the client to
get a ClientDiscardableHandle without
ClientTransferCache::Client::IssueCreateTransferCacheEntry getting
called so that the client can essentially start a locked entry but
trigger the creation of the service-side entry using some other
mechanism, e.g., an IPC message.

This is needed for hardware-accelerated image decodes because the decode
will be started by sending an IPC message, and the service-side cache
entry shouldn't be created until the decode is done, so the usual flow
of triggering the cache entry creation using the command buffer won't
do.

Additionally, some documentation is updated.

Bug: 868400
Change-Id: I24cf9b921b8a0ea2e7038c1801f2b7c36fda1927
Reviewed-on: https://chromium-review.googlesource.com/c/1328184Reviewed-by: default avatarAntoine Labour <piman@chromium.org>
Reviewed-by: default avatarKhushal <khushalsagar@chromium.org>
Commit-Queue: Andres Calderon Jaramillo <andrescj@chromium.org>
Cr-Commit-Position: refs/heads/master@{#607438}
parent 18b8e187
......@@ -78,6 +78,21 @@ void ClientTransferCache::AddTransferCacheEntry(uint32_t type,
shm_offset, size);
}
void ClientTransferCache::StartTransferCacheEntry(
uint32_t type,
uint32_t id,
base::OnceCallback<void(ClientDiscardableHandle)> create_entry_cb) {
DCHECK(!mapped_ptr_);
EntryKey key(type, id);
base::AutoLock hold(lock_);
// Call |create_entry_cb| while |lock_| is held so that in case another thread
// tries to lock the cache entry later, it can assume that the creation of the
// service-side cache entry has been triggered.
std::move(create_entry_cb).Run(CreateDiscardableHandle(key));
}
ClientDiscardableHandle ClientTransferCache::CreateDiscardableHandle(
const EntryKey& key) {
lock_.AssertAcquired();
......
......@@ -7,6 +7,7 @@
#include <map>
#include "base/callback.h"
#include "base/optional.h"
#include "base/synchronization/lock.h"
#include "gpu/command_buffer/client/client_discardable_manager.h"
......@@ -21,18 +22,31 @@ class MappedMemoryManager;
// ClientTransferCache allows for ClientTransferCacheEntries to be inserted
// into the cache, which will send them to the ServiceTransferCache, making
// them available for consumption in the GPU process. Typical usage is:
// 1) Insert a new entry via CreateCacheEntry. It starts locked.
// 2) Use the new entry's ID in one or more commands.
// 3) Unlock the entry via UnlockTransferCacheEntries after dependent commands
// have been issued.
// 1) Create a new ClientTransferCacheEntry.
// 2) Map a memory allocation for the entry using either MapEntry() or
// MapTransferBufferEntry().
// 3) Write the entry data to the mapped allocation using
// ClientTransferCacheEntry::Serialize().
// 4) Unmap the allocation using UnmapAndCreateEntry(). This will ensure that
// the entry starts locked and will trigger the creation of the
// service-side cache entry.
// 5) Use the new entry's ID in one or more commands.
// 6) Unlock the entry via UnlockEntries() after dependent commands have been
// issued.
//
// If an entry is needed again:
// 4) Attempt to lock the entry via LockTransferCacheEntry.
// 4a) If this fails, DeleteTransferCacheEntry then go to (1)
// 4b) If this succeeds, go to (2).
// 7) Attempt to lock the entry via LockEntry().
// 7a) If this fails, DeleteEntry() then go to (1).
// 7b) If this succeeds, go to (5).
//
// If an entry is no longer needed:
// 5) DeleteTransferCacheEntry
// 8) DeleteEntry().
//
// If the client wants to send the cache entry without using the |client| passed
// to the constructor, it should replace steps (2)-(4) with a call to
// StartTransferCacheEntry() and send the information needed to create the cache
// entry on the service side using some external mechanism, e.g., an IPC
// message.
//
// NOTE: The presence of locking on this class does not make it threadsafe.
// The underlying locking *only* allows calling LockTransferCacheEntry
......@@ -67,6 +81,20 @@ class GLES2_IMPL_EXPORT ClientTransferCache {
uint32_t shm_offset,
size_t size);
// Similar to AddTransferCacheEntry() but doesn't use |client_| to trigger the
// creation of the service-side cache entry. Instead, it calls
// |create_entry_cb| passing a ClientDiscardableHandle which
// |create_entry_cb| can use to trigger the creation of an initially locked
// service-side cache entry using some external mechanism, e.g., an IPC
// message. This external mechanism should guarantee that it is safe for
// command buffer commands to reference the cache entry after
// |create_entry_cb| returns. Note that this function calls |create_entry_cb|
// before returning.
void StartTransferCacheEntry(
uint32_t type,
uint32_t id,
base::OnceCallback<void(ClientDiscardableHandle)> create_entry_cb);
// Map(of either type) must always be followed by an Unmap.
void* MapEntry(MappedMemoryManager* mapped_memory, size_t size);
void* MapTransferBufferEntry(TransferBufferInterface* transfer_buffer,
......
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