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

Side by Side 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 unified diff | Download patch
OLDNEW
(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 "base/memory/shared_memory.h"
10 #include "gpu/command_buffer/common/buffer.h"
11
12 namespace gpu {
13
14 // DiscardableHandle provides a threadsafe object which can be transitioned
15 // between one of three states:
16 // ╔════════════╗ ╔════════════╗ ╔═══════════╗
17 // ║ Locked ║ ──────> ║ Unlocked ║ ──────> ║ Deleted ║
18 // ╚════════════╝ ╚════════════╝ ╚═══════════╝
19 // └───────────<──────────┘
20 // Note that a DiscardableHAndle can be locked multiple times, and stores
21 // a lock-count.
22 //
23 // In order to facilitate transfering DiscardableHandles across the command
24 // buffer, a DiscardableHandle is backed by a gpu::Buffer and an offset
25 // into that buffer. The handle uses a single uint32_t of data at the given
26 // offset.
27 class GPU_EXPORT DiscardableHandle {
28 public:
29 void InitializeWithNewData(scoped_refptr<Buffer> buffer,
30 uint32_t byte_offset,
31 int32_t shm_id);
32 void InitializeWithExistingData(scoped_refptr<Buffer> buffer,
33 uint32_t byte_offset,
34 int32_t shm_id);
35
36 bool Lock();
37 void Unlock();
38 bool Delete();
39
40 bool IsInitialized() const { return !!shm_id_; }
41 int32_t shm_id() const { return shm_id_; }
42 uint32_t byte_offset() const { return byte_offset_; }
43 bool IsDeleted() const;
44
45 // Test only functions.
46 bool IsLockedForTesting();
47
48 private:
49 volatile base::subtle::Atomic32* AsAtomic() const;
50
51 scoped_refptr<Buffer> buffer_;
52 uint32_t byte_offset_ = 0;
53 uint32_t shm_id_ = 0;
54 };
55
56 } // namespace gpu
57
58 #endif // GPU_COMMAND_BUFFER_COMMON_DISCARDABLE_HANDLE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698