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>
14#include "flutter/fml/macros.h"
40 :
public std::enable_shared_from_this<ResourceManagerVK> {
54 static std::shared_ptr<ResourceManagerVK>
Create();
66 void Reclaim(std::unique_ptr<ResourceVK> resource);
76 using Reclaimables = std::vector<std::unique_ptr<ResourceVK>>;
79 std::mutex reclaimables_mutex_;
80 std::condition_variable reclaimables_cv_;
81 Reclaimables reclaimables_;
82 bool should_exit_ =
false;
113template <
class ResourceType_>
122 : resource_(
std::move(resource)) {}
144template <
class ResourceType_>
155 : resource_manager_(
std::move(resource_manager)) {}
166 : resource_manager_(
std::move(resource_manager)),
175 FML_CHECK(resource_) <<
"UniqueResourceVKT was reclaimed.";
177 return resource_.get()->Get();
185 resource_ = std::make_unique<ResourceVKT<ResourceType>>(std::move(other));
196 if (
auto manager = resource_manager_.lock()) {
197 manager->Reclaim(std::move(resource_));
203 std::weak_ptr<ResourceManagerVK> resource_manager_;
204 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.
An internal type that is used to move a resource reference.
ResourceType_ ResourceType
ResourceVKT(ResourceType &&resource)
Construct a resource from a move-constructible resource.
const ResourceType * Get() const
Returns a pointer to the resource.
A resource that may be reclaimed by a |ResourceManagerVK|.
virtual ~ResourceVK()=default
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
#define FML_CHECK(condition)