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

Side by Side Diff: gpu/command_buffer/client/client_discardable_manager.h

Issue 2751633002: ClientDiscardableManager Implementation
Patch Set: AllocationSize cleanup Created 3 years, 8 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_CLIENT_CLIENT_DISCARDABLE_MANAGER_H_
6 #define GPU_COMMAND_BUFFER_CLIENT_CLIENT_DISCARDABLE_MANAGER_H_
7
8 #include <map>
9 #include <queue>
10 #include <set>
11
12 #include "gpu/command_buffer/common/command_buffer.h"
13 #include "gpu/command_buffer/common/discardable_handle.h"
14 #include "gpu/gpu_export.h"
15
16 namespace gpu {
17
18 // ClientDiscardableManager is a helper class used by the client GLES2
19 // implementation. Currently, this class only supports textures, but it could
20 // be extended to other types in the future.
21 //
22 // The GLES2 impl can call GetForTexture to retreive the
23 // ClientDiscardableHandle for a given texture. If no handle exists, one
24 // will be created.
25 //
26 // When the GLES2 impl is done with a texture (the texture is being deleted),
27 // it should call FreeForTexture to allow helper memory to be reclaimed.
28 class GPU_EXPORT ClientDiscardableManager {
29 public:
30 ClientDiscardableManager();
31 ~ClientDiscardableManager();
32 ClientDiscardableHandle GetForTexture(CommandBuffer* command_buffer,
33 uint32_t texture_id);
34 void FreeForTexture(uint32_t texture_id);
35
36 // Test only functions.
37 void CheckPendingForTesting(CommandBuffer* command_buffer) {
38 CheckPending(command_buffer);
39 }
40 void SetElementCountForTesting(size_t count) {
41 elements_per_allocation_ = count;
42 allocation_size_ = count * element_size_;
43 }
44
45 private:
46 void FindAllocation(CommandBuffer* command_buffer,
47 scoped_refptr<Buffer>* buffer,
48 int32_t* shm_id,
49 uint32_t* offset);
50 void ReturnAllocation(CommandBuffer* command_buffer,
51 const ClientDiscardableHandle& handle);
52 void CheckPending(CommandBuffer* command_buffer);
53
54 private:
55 size_t allocation_size_;
56 size_t element_size_ = sizeof(base::subtle::Atomic32);
57 uint32_t elements_per_allocation_ = allocation_size_ / element_size_;
58
59 struct Allocation;
60 std::vector<std::unique_ptr<Allocation>> allocations_;
61 std::map<uint32_t, ClientDiscardableHandle> texture_handles_;
62
63 // Handles that are pending service deletion, and can be re-used once
64 // ClientDiscardableHandle::CanBeReUsed returns true.
65 std::queue<ClientDiscardableHandle> pending_handles_;
66
67 DISALLOW_COPY_AND_ASSIGN(ClientDiscardableManager);
68 };
69
70 } // namespace gpu
71
72 #endif // GPU_COMMAND_BUFFER_CLIENT_CLIENT_DISCARDABLE_MANAGER_H_
OLDNEW
« no previous file with comments | « gpu/command_buffer/client/BUILD.gn ('k') | gpu/command_buffer/client/client_discardable_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698