Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(750)

Unified Diff: gpu/command_buffer/common/discardable_handle.h

Issue 2732223004: DiscardableHandle Implementation (Closed)
Patch Set: remove unused var Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « gpu/command_buffer/common/BUILD.gn ('k') | gpu/command_buffer/common/discardable_handle.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: gpu/command_buffer/common/discardable_handle.h
diff --git a/gpu/command_buffer/common/discardable_handle.h b/gpu/command_buffer/common/discardable_handle.h
new file mode 100644
index 0000000000000000000000000000000000000000..a3b17691da9a2d6b5d6893660856d2b36a1bfab2
--- /dev/null
+++ b/gpu/command_buffer/common/discardable_handle.h
@@ -0,0 +1,105 @@
+// Copyright (c) 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef GPU_COMMAND_BUFFER_COMMON_DISCARDABLE_HANDLE_H_
+#define GPU_COMMAND_BUFFER_COMMON_DISCARDABLE_HANDLE_H_
+
+#include "base/memory/ref_counted.h"
+#include "gpu/gpu_export.h"
+
+namespace gpu {
+
+class Buffer;
+
+// DiscardableHandleBase is the base class for the discardable handle
+// implementation. In order to facilitate transfering handles across the
+// command buffer, DiscardableHandleBase is backed by a gpu::Buffer and an
+// offset into that buffer. It uses a single uint32_t of data at the given
+// offset.
+//
+// DiscardableHandleBase is never used directly, but is instead modified by the
+// Client/ServiceDiscardableHandle subclasses. These subclasses implement the
+// Lock/Unlock/Delete functionality, making it explicit which operations occur
+// in which process.
+//
+// Via these subclasses, a discardable handle can be transitioned between one
+// of three states:
+// ╔════════════╗ ╔════════════╗ ╔═══════════╗
+// ║ Locked ║ ──────> ║ Unlocked ║ ──────> ║ Deleted ║
+// ╚════════════╝ ╚════════════╝ ╚═══════════╝
+// └───────────<──────────┘
+//
+// Note that a handle can be locked multiple times, and stores a lock-count.
+class GPU_EXPORT DiscardableHandleBase {
+ public:
+ int32_t shm_id() const { return shm_id_; }
+ uint32_t byte_offset() const { return byte_offset_; }
+
+ // Test only functions.
+ bool IsLockedForTesting();
+ bool IsDeletedForTesting();
+
+ protected:
+ DiscardableHandleBase(scoped_refptr<Buffer> buffer,
+ uint32_t byte_offset,
+ int32_t shm_id);
+ DiscardableHandleBase(const DiscardableHandleBase& other);
+ DiscardableHandleBase(DiscardableHandleBase&& other);
+ DiscardableHandleBase& operator=(const DiscardableHandleBase& other);
+ DiscardableHandleBase& operator=(DiscardableHandleBase&& other);
+ ~DiscardableHandleBase();
+
+ volatile base::subtle::Atomic32* AsAtomic() const;
+
+ private:
+ scoped_refptr<Buffer> buffer_;
+ uint32_t byte_offset_ = 0;
+ uint32_t shm_id_ = 0;
+};
+
+// ClientDiscardableHandle enables the instantiation of a new discardable
+// handle (via the constructor), and can Lock an existing handle.
+class GPU_EXPORT ClientDiscardableHandle : public DiscardableHandleBase {
+ public:
+ ClientDiscardableHandle(scoped_refptr<Buffer> buffer,
+ uint32_t byte_offset,
+ int32_t shm_id);
+ ClientDiscardableHandle(const ClientDiscardableHandle& other);
+ ClientDiscardableHandle(ClientDiscardableHandle&& other);
+ ClientDiscardableHandle& operator=(const ClientDiscardableHandle& other);
+ ClientDiscardableHandle& operator=(ClientDiscardableHandle&& other);
+
+ // Tries to lock the handle. Returns true if successfully locked. Returns
+ // false if the handle has already been deleted on the service.
+ bool Lock();
+
+ // Returns true if the handle has been deleted on service side and can be
+ // re-used on the client.
+ bool CanBeReUsed() const;
+};
+
+// ServiceDiscardableHandle can wrap an existing handle (via the constructor),
+// and can unlock and delete this handle.
+class GPU_EXPORT ServiceDiscardableHandle : public DiscardableHandleBase {
+ public:
+ ServiceDiscardableHandle(scoped_refptr<Buffer> buffer,
+ uint32_t byte_offset,
+ int32_t shm_id);
+ ServiceDiscardableHandle(const ServiceDiscardableHandle& other);
+ ServiceDiscardableHandle(ServiceDiscardableHandle&& other);
+ ServiceDiscardableHandle& operator=(const ServiceDiscardableHandle& other);
+ ServiceDiscardableHandle& operator=(ServiceDiscardableHandle&& other);
+
+ // Unlocks the handle. This should always be paired with a client-side call
+ // to lock, or with a new handle, which starts locked.
+ void Unlock();
+
+ // Tries to delete the handle. Returns true if successfully deleted. Returns
+ // false if the handle is locked client-side and cannot be deleted.
+ bool Delete();
+};
+
+} // namespace gpu
+
+#endif // GPU_COMMAND_BUFFER_COMMON_DISCARDABLE_HANDLE_H_
« no previous file with comments | « gpu/command_buffer/common/BUILD.gn ('k') | gpu/command_buffer/common/discardable_handle.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698