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_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 // When the GLES2 impl is done with a texture (the texture is being deleted), |
| 23 // it should call FreeTexture to allow helper memory to be reclaimed. |
| 24 class GPU_EXPORT ClientDiscardableManager { |
| 25 public: |
| 26 ClientDiscardableManager(); |
| 27 ~ClientDiscardableManager(); |
| 28 ClientDiscardableHandle InitializeTexture(CommandBuffer* command_buffer, |
| 29 uint32_t texture_id); |
| 30 bool LockTexture(uint32_t texture_id); |
| 31 void FreeTexture(uint32_t texture_id); |
| 32 bool TextureIsValid(uint32_t texture_id) const; |
| 33 |
| 34 // Test only functions. |
| 35 void CheckPendingForTesting(CommandBuffer* command_buffer) { |
| 36 CheckPending(command_buffer); |
| 37 } |
| 38 void SetElementCountForTesting(size_t count) { |
| 39 elements_per_allocation_ = count; |
| 40 allocation_size_ = count * element_size_; |
| 41 } |
| 42 ClientDiscardableHandle GetHandleForTesting(uint32_t texture_id); |
| 43 |
| 44 private: |
| 45 void FindAllocation(CommandBuffer* command_buffer, |
| 46 scoped_refptr<Buffer>* buffer, |
| 47 int32_t* shm_id, |
| 48 uint32_t* offset); |
| 49 void ReturnAllocation(CommandBuffer* command_buffer, |
| 50 const ClientDiscardableHandle& handle); |
| 51 void CheckPending(CommandBuffer* command_buffer); |
| 52 |
| 53 private: |
| 54 size_t allocation_size_; |
| 55 size_t element_size_ = sizeof(base::subtle::Atomic32); |
| 56 uint32_t elements_per_allocation_ = allocation_size_ / element_size_; |
| 57 |
| 58 struct Allocation; |
| 59 std::vector<std::unique_ptr<Allocation>> allocations_; |
| 60 std::map<uint32_t, ClientDiscardableHandle> texture_handles_; |
| 61 |
| 62 // Handles that are pending service deletion, and can be re-used once |
| 63 // ClientDiscardableHandle::CanBeReUsed returns true. |
| 64 std::queue<ClientDiscardableHandle> pending_handles_; |
| 65 |
| 66 DISALLOW_COPY_AND_ASSIGN(ClientDiscardableManager); |
| 67 }; |
| 68 |
| 69 } // namespace gpu |
| 70 |
| 71 #endif // GPU_COMMAND_BUFFER_CLIENT_CLIENT_DISCARDABLE_MANAGER_H_ |
OLD | NEW |