| OLD | NEW |
| (Empty) | |
| 1 // Copyright (c) 2017 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef GPU_COMMAND_BUFFER_COMMON_DISCARDABLE_HANDLE_H_ |
| 6 #define GPU_COMMAND_BUFFER_COMMON_DISCARDABLE_HANDLE_H_ |
| 7 |
| 8 #include "base/memory/ref_counted.h" |
| 9 #include "gpu/gpu_export.h" |
| 10 |
| 11 namespace gpu { |
| 12 |
| 13 class Buffer; |
| 14 |
| 15 // DiscardableHandleBase is the base class for the discardable handle |
| 16 // implementation. In order to facilitate transfering handles across the |
| 17 // command buffer, DiscardableHandleBase is backed by a gpu::Buffer and an |
| 18 // offset into that buffer. It uses a single uint32_t of data at the given |
| 19 // offset. |
| 20 // |
| 21 // DiscardableHandleBase is never used directly, but is instead modified by the |
| 22 // Client/ServiceDiscardableHandle subclasses. These subclasses implement the |
| 23 // Lock/Unlock/Delete functionality, making it explicit which operations occur |
| 24 // in which process. |
| 25 // |
| 26 // Via these subclasses, a discardable handle can be transitioned between one |
| 27 // of three states: |
| 28 // ╔════════════╗ ╔════════════╗ ╔═══════════╗ |
| 29 // ║ Locked ║ ──────> ║ Unlocked ║ ──────> ║ Deleted ║ |
| 30 // ╚════════════╝ ╚════════════╝ ╚═══════════╝ |
| 31 // └───────────<──────────┘ |
| 32 // |
| 33 // Note that a handle can be locked multiple times, and stores a lock-count. |
| 34 class GPU_EXPORT DiscardableHandleBase { |
| 35 public: |
| 36 int32_t shm_id() const { return shm_id_; } |
| 37 uint32_t byte_offset() const { return byte_offset_; } |
| 38 |
| 39 // Test only functions. |
| 40 bool IsLockedForTesting(); |
| 41 bool IsDeletedForTesting(); |
| 42 |
| 43 protected: |
| 44 DiscardableHandleBase(scoped_refptr<Buffer> buffer, |
| 45 uint32_t byte_offset, |
| 46 int32_t shm_id); |
| 47 DiscardableHandleBase(const DiscardableHandleBase& other); |
| 48 DiscardableHandleBase(DiscardableHandleBase&& other); |
| 49 DiscardableHandleBase& operator=(const DiscardableHandleBase& other); |
| 50 DiscardableHandleBase& operator=(DiscardableHandleBase&& other); |
| 51 ~DiscardableHandleBase(); |
| 52 |
| 53 volatile base::subtle::Atomic32* AsAtomic() const; |
| 54 |
| 55 private: |
| 56 scoped_refptr<Buffer> buffer_; |
| 57 uint32_t byte_offset_ = 0; |
| 58 uint32_t shm_id_ = 0; |
| 59 }; |
| 60 |
| 61 // ClientDiscardableHandle enables the instantiation of a new discardable |
| 62 // handle (via the constructor), and can Lock an existing handle. |
| 63 class GPU_EXPORT ClientDiscardableHandle : public DiscardableHandleBase { |
| 64 public: |
| 65 ClientDiscardableHandle(scoped_refptr<Buffer> buffer, |
| 66 uint32_t byte_offset, |
| 67 int32_t shm_id); |
| 68 ClientDiscardableHandle(const ClientDiscardableHandle& other); |
| 69 ClientDiscardableHandle(ClientDiscardableHandle&& other); |
| 70 ClientDiscardableHandle& operator=(const ClientDiscardableHandle& other); |
| 71 ClientDiscardableHandle& operator=(ClientDiscardableHandle&& other); |
| 72 |
| 73 // Tries to lock the handle. Returns true if successfully locked. Returns |
| 74 // false if the handle has already been deleted on the service. |
| 75 bool Lock(); |
| 76 |
| 77 // Returns true if the handle has been deleted on service side and can be |
| 78 // re-used on the client. |
| 79 bool CanBeReUsed() const; |
| 80 }; |
| 81 |
| 82 // ServiceDiscardableHandle can wrap an existing handle (via the constructor), |
| 83 // and can unlock and delete this handle. |
| 84 class GPU_EXPORT ServiceDiscardableHandle : public DiscardableHandleBase { |
| 85 public: |
| 86 ServiceDiscardableHandle(scoped_refptr<Buffer> buffer, |
| 87 uint32_t byte_offset, |
| 88 int32_t shm_id); |
| 89 ServiceDiscardableHandle(const ServiceDiscardableHandle& other); |
| 90 ServiceDiscardableHandle(ServiceDiscardableHandle&& other); |
| 91 ServiceDiscardableHandle& operator=(const ServiceDiscardableHandle& other); |
| 92 ServiceDiscardableHandle& operator=(ServiceDiscardableHandle&& other); |
| 93 |
| 94 // Unlocks the handle. This should always be paired with a client-side call |
| 95 // to lock, or with a new handle, which starts locked. |
| 96 void Unlock(); |
| 97 |
| 98 // Tries to delete the handle. Returns true if successfully deleted. Returns |
| 99 // false if the handle is locked client-side and cannot be deleted. |
| 100 bool Delete(); |
| 101 }; |
| 102 |
| 103 } // namespace gpu |
| 104 |
| 105 #endif // GPU_COMMAND_BUFFER_COMMON_DISCARDABLE_HANDLE_H_ |
| OLD | NEW |