Chromium Code Reviews| Index: gpu/command_buffer/service/service_discardable_manager.h |
| diff --git a/gpu/command_buffer/service/service_discardable_manager.h b/gpu/command_buffer/service/service_discardable_manager.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..46c6228be0e0a20d80a96d3a9db8035a79f7c858 |
| --- /dev/null |
| +++ b/gpu/command_buffer/service/service_discardable_manager.h |
| @@ -0,0 +1,72 @@ |
| +// Copyright (c) 2017 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef GPU_COMMAND_BUFFER_SERVICE_SERVICE_DISCARDABLE_MANAGER_H_ |
| +#define GPU_COMMAND_BUFFER_SERVICE_SERVICE_DISCARDABLE_MANAGER_H_ |
| + |
| +#include <vector> |
| + |
| +#include "base/containers/mru_cache.h" |
| +#include "gpu/command_buffer/common/discardable_handle.h" |
| +#include "gpu/command_buffer/service/context_group.h" |
| +#include "gpu/gpu_export.h" |
| + |
| +namespace gpu { |
| + |
| +class GPU_EXPORT ServiceDiscardableManager |
| + : public base::RefCounted<ServiceDiscardableManager> { |
|
piman
2017/05/02 22:21:03
nit: does this need to be refcounted, or could it
ericrk
2017/05/10 21:36:03
This is now a singly-owned object on GpuChannelMan
|
| + public: |
| + ServiceDiscardableManager(); |
| + |
| + void InsertLockedTexture(uint32_t texture_id, |
| + size_t texture_size, |
| + gles2::ContextGroup* context_group, |
| + ServiceDiscardableHandle handle); |
| + // Returns false if texture_id does not exist. |
| + bool UnlockTexture(uint32_t texture_id, |
| + const gles2::ContextGroup* context_group); |
| + |
| + // Called when a texture is deleted externally, via glDeleteTextures, to |
| + // clean up state. |
| + void OnTextureDeleted(uint32_t texture_id, |
| + const gles2::ContextGroup* context_group); |
| + |
| + // Test only functions: |
| + size_t NumCacheEntriesForTesting() const { return entries_.size(); } |
| + bool IsEntryLockedForTesting(uint32_t texture_id, |
| + const gles2::ContextGroup* context_group) const; |
| + |
| + private: |
| + friend class base::RefCounted<ServiceDiscardableManager>; |
| + ~ServiceDiscardableManager(); |
| + |
| + void EnforceLimits(); |
| + |
| + struct GpuDiscardableEntry { |
| + ServiceDiscardableHandle handle; |
| + size_t size; |
| + }; |
| + struct GpuDiscardableEntryKey { |
| + uint32_t texture_id; |
| + const gles2::ContextGroup* context_group; |
| + }; |
| + struct GpuDiscardableEntryKeyCompare { |
| + bool operator()(const GpuDiscardableEntryKey& lhs, |
| + const GpuDiscardableEntryKey& rhs) const { |
| + return lhs.context_group < rhs.context_group || |
| + (lhs.context_group == rhs.context_group && |
| + lhs.texture_id < rhs.texture_id); |
| + } |
| + }; |
| + using EntryCache = base::MRUCache<GpuDiscardableEntryKey, |
| + GpuDiscardableEntry, |
| + GpuDiscardableEntryKeyCompare>; |
| + EntryCache entries_; |
| + |
| + size_t total_size_ = 0; |
| +}; |
| + |
| +} // namespace gpu |
| + |
| +#endif // GPU_COMMAND_BUFFER_SERVICE_SERVICE_DISCARDABLE_MANAGER_H_ |