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_SERVICE_SERVICE_DISCARDABLE_MANAGER_H_ |
| 6 #define GPU_COMMAND_BUFFER_SERVICE_SERVICE_DISCARDABLE_MANAGER_H_ |
| 7 |
| 8 #include <vector> |
| 9 |
| 10 #include "base/containers/mru_cache.h" |
| 11 #include "gpu/command_buffer/common/discardable_handle.h" |
| 12 #include "gpu/command_buffer/service/context_group.h" |
| 13 #include "gpu/command_buffer/service/texture_manager.h" |
| 14 #include "gpu/gpu_export.h" |
| 15 |
| 16 namespace gpu { |
| 17 class GPU_EXPORT ServiceDiscardableManager { |
| 18 public: |
| 19 ServiceDiscardableManager(); |
| 20 ~ServiceDiscardableManager(); |
| 21 |
| 22 void InsertLockedTexture(uint32_t texture_id, |
| 23 size_t texture_size, |
| 24 gles2::TextureManager* texture_manager, |
| 25 ServiceDiscardableHandle handle); |
| 26 |
| 27 // Unlocks the indicated texture. If *|texture_to_unbind| is not nullptr, |
| 28 // ServiceDiscardableManager has taken ownership of the given texture, and |
| 29 // it is the callers responsibility to unbind it from any other objects. |
| 30 // Returns false if the given texture_id has not been initialized for use |
| 31 // with discardable. |
| 32 bool UnlockTexture(uint32_t texture_id, |
| 33 gles2::TextureManager* texture_manager, |
| 34 gles2::TextureRef** texture_to_unbind); |
| 35 // Locks the indicated texture, allowing it to be used in future GL commands. |
| 36 // Returns false if the given texture_id has not been initialized for use |
| 37 // with discardable. |
| 38 bool LockTexture(uint32_t texture_id, gles2::TextureManager* texture_manager); |
| 39 |
| 40 // Returns all unlocked texture refs to the texture_manager for deletion. |
| 41 // After this point, this class will have no references to the given |
| 42 // |texture_manager|. |
| 43 void OnTextureManagerDestruction(gles2::TextureManager* texture_manager); |
| 44 |
| 45 // Called when a texture is deleted, to clean up state. |
| 46 void OnTextureDeleted(uint32_t texture_id, |
| 47 gles2::TextureManager* texture_manager); |
| 48 |
| 49 // Called by the TextureManager when a texture's size changes. |
| 50 void OnTextureSizeChanged(uint32_t texture_id, |
| 51 gles2::TextureManager* texture_manager, |
| 52 size_t new_size); |
| 53 |
| 54 // Test only functions: |
| 55 size_t NumCacheEntriesForTesting() const { return entries_.size(); } |
| 56 bool IsEntryLockedForTesting(uint32_t texture_id, |
| 57 gles2::TextureManager* texture_manager) const; |
| 58 size_t TotalSizeForTesting() const { return total_size_; } |
| 59 gles2::TextureRef* UnlockedTextureRefForTesting( |
| 60 uint32_t texture_id, |
| 61 gles2::TextureManager* texture_manager) const; |
| 62 |
| 63 private: |
| 64 void EnforceLimits(); |
| 65 |
| 66 struct GpuDiscardableEntry { |
| 67 public: |
| 68 GpuDiscardableEntry(ServiceDiscardableHandle handle, size_t size); |
| 69 GpuDiscardableEntry(const GpuDiscardableEntry& other); |
| 70 GpuDiscardableEntry(GpuDiscardableEntry&& other); |
| 71 ~GpuDiscardableEntry(); |
| 72 |
| 73 ServiceDiscardableHandle handle; |
| 74 scoped_refptr<gles2::TextureRef> unlocked_texture_ref; |
| 75 // The current ref count of this object with regards to command buffer |
| 76 // execution. May be out of sync with the handle's refcount, as the handle |
| 77 // can be locked out of band with the command buffer. |
| 78 uint32_t service_ref_count_ = 1; |
| 79 size_t size; |
| 80 }; |
| 81 struct GpuDiscardableEntryKey { |
| 82 uint32_t texture_id; |
| 83 gles2::TextureManager* texture_manager; |
| 84 }; |
| 85 struct GpuDiscardableEntryKeyCompare { |
| 86 bool operator()(const GpuDiscardableEntryKey& lhs, |
| 87 const GpuDiscardableEntryKey& rhs) const { |
| 88 return std::tie(lhs.texture_manager, lhs.texture_id) < |
| 89 std::tie(rhs.texture_manager, rhs.texture_id); |
| 90 } |
| 91 }; |
| 92 using EntryCache = base::MRUCache<GpuDiscardableEntryKey, |
| 93 GpuDiscardableEntry, |
| 94 GpuDiscardableEntryKeyCompare>; |
| 95 EntryCache entries_; |
| 96 |
| 97 // Total size of all |entries_|. The same as summing |
| 98 // GpuDiscardableEntry::size for each entry. |
| 99 size_t total_size_ = 0; |
| 100 |
| 101 DISALLOW_COPY_AND_ASSIGN(ServiceDiscardableManager); |
| 102 }; |
| 103 |
| 104 } // namespace gpu |
| 105 |
| 106 #endif // GPU_COMMAND_BUFFER_SERVICE_SERVICE_DISCARDABLE_MANAGER_H_ |
OLD | NEW |