5 #ifndef FLUTTER_IMPELLER_RENDERER_BACKEND_VULKAN_RESOURCE_MANAGER_VK_H_
6 #define FLUTTER_IMPELLER_RENDERER_BACKEND_VULKAN_RESOURCE_MANAGER_VK_H_
8 #include <condition_variable>
38 :
public std::enable_shared_from_this<ResourceManagerVK> {
52 static std::shared_ptr<ResourceManagerVK>
Create();
64 void Reclaim(std::unique_ptr<ResourceVK> resource);
74 using Reclaimables = std::vector<std::unique_ptr<ResourceVK>>;
77 std::mutex reclaimables_mutex_;
78 std::condition_variable reclaimables_cv_;
79 Reclaimables reclaimables_;
80 bool should_exit_ =
false;
111 template <
class ResourceType_>
120 : resource_(
std::move(resource)) {}
142 template <
class ResourceType_>
153 : resource_manager_(
std::move(resource_manager)) {}
164 : resource_manager_(
std::move(resource_manager)),
173 FML_CHECK(resource_) <<
"UniqueResourceVKT was reclaimed.";
175 return resource_.get()->Get();
183 resource_ = std::make_unique<ResourceVKT<ResourceType>>(std::move(other));
194 if (
auto manager = resource_manager_.lock()) {
195 manager->Reclaim(std::move(resource_));
201 std::weak_ptr<ResourceManagerVK> resource_manager_;
202 std::unique_ptr<ResourceVKT<ResourceType>> resource_;
A resource manager controls how resources are allocated and reclaimed.
static std::shared_ptr< ResourceManagerVK > Create()
Creates a shared resource manager (a dedicated thread).
void Reclaim(std::unique_ptr< ResourceVK > resource)
Mark a resource as being reclaimable.
~ResourceManagerVK()
Destroys the resource manager.
A resource that may be reclaimed by a |ResourceManagerVK|.
virtual ~ResourceVK()=default
An internal type that is used to move a resource reference.
const ResourceType * Get() const
Returns a pointer to the resource.
ResourceType_ ResourceType
ResourceVKT(ResourceType &&resource)
Construct a resource from a move-constructible resource.
A unique handle to a resource which will be reclaimed by the specified resource manager.
void Reset()
Reclaims the existing resource, if any.
const ResourceType * operator->() const
Returns a pointer to the resource.
void Swap(ResourceType &&other)
Reclaims the existing resource, if any, and replaces it.
UniqueResourceVKT(std::weak_ptr< ResourceManagerVK > resource_manager)
Construct a unique resource handle belonging to a manager.
UniqueResourceVKT(std::weak_ptr< ResourceManagerVK > resource_manager, ResourceType &&resource)
Construct a unique resource handle belonging to a manager.
ResourceType_ ResourceType