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

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

Issue 2732223004: DiscardableHandle Implementation (Closed)
Patch Set: byte offset 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
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..8a490aed851c124a1aacc0153ab6d89e45ade391
--- /dev/null
+++ b/gpu/command_buffer/common/discardable_handle.h
@@ -0,0 +1,58 @@
+// 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 "base/memory/shared_memory.h"
+#include "gpu/command_buffer/common/buffer.h"
+
+namespace gpu {
+
+// DiscardableHandle provides a threadsafe object which can be transitioned
+// between one of three states:
+// ╔════════════╗ ╔════════════╗ ╔═══════════╗
+// ║ Locked ║ ──────> ║ Unlocked ║ ──────> ║ Deleted ║
+// ╚════════════╝ ╚════════════╝ ╚═══════════╝
+// └───────────<──────────┘
+// Note that a DiscardableHAndle can be locked multiple times, and stores
+// a lock-count.
+//
+// In order to facilitate transfering DiscardableHandles across the command
+// buffer, a DiscardableHandle is backed by a gpu::Buffer and an offset
+// into that buffer. The handle uses a single uint32_t of data at the given
+// offset.
+class GPU_EXPORT DiscardableHandle {
+ public:
+ void InitializeWithNewData(scoped_refptr<Buffer> buffer,
+ uint32_t byte_offset,
+ int32_t shm_id);
+ void InitializeWithExistingData(scoped_refptr<Buffer> buffer,
+ uint32_t byte_offset,
+ int32_t shm_id);
+
+ bool Lock();
+ void Unlock();
+ bool Delete();
+
+ bool IsInitialized() const { return !!shm_id_; }
+ int32_t shm_id() const { return shm_id_; }
+ uint32_t byte_offset() const { return byte_offset_; }
+ bool IsDeleted() const;
+
+ // Test only functions.
+ bool IsLockedForTesting();
+
+ private:
+ volatile base::subtle::Atomic32* AsAtomic() const;
+
+ scoped_refptr<Buffer> buffer_;
+ uint32_t byte_offset_ = 0;
+ uint32_t shm_id_ = 0;
+};
+
+} // namespace gpu
+
+#endif // GPU_COMMAND_BUFFER_COMMON_DISCARDABLE_HANDLE_H_

Powered by Google App Engine
This is Rietveld 408576698