check for unloaded before finished and some cleanup

This commit is contained in:
Maximilian Seidler 2025-09-26 11:22:35 +02:00
parent 07ada14564
commit b8982219d3
2 changed files with 15 additions and 13 deletions

View file

@ -146,8 +146,10 @@ void CAsyncResourceManager::screencopyToTexture(const CScreencopyFrame& scFrame)
std::erase_if(m_scFrames, [&scFrame](const auto& f) { return f.get() == &scFrame; });
if (m_scFrames.empty())
onScreencopyDone();
if (m_scFrames.empty()) {
Debug::log(TRACE, "Gathered all screencopy frames - removing dmabuf listeners");
g_pHyprlock->removeDmabufListener();
}
}
void CAsyncResourceManager::gatherInitialResources(wl_display* display) {
@ -292,10 +294,13 @@ void CAsyncResourceManager::onResourceFinished(ResourceID id) {
m_resources.erase(id);
m_resourcesMutex.unlock();
if (!m_assets.contains(id) || m_assets[id].refs == 0) // Not referenced? Drop it
return;
if (!RESOURCE || !RESOURCE->m_asset.cairoSurface)
return;
//Debug::log(TRACE, "Resource to texture id:{}", id);
Debug::log(TRACE, "Resource to texture id:{}", id);
const auto texture = makeAtomicShared<CTexture>();
@ -341,9 +346,3 @@ void CAsyncResourceManager::onResourceFinished(ResourceID id) {
m_resourcesMutex.unlock();
}
}
void CAsyncResourceManager::onScreencopyDone() {
// We are done with screencopy.
//Debug::log(TRACE, "Gathered all screencopy frames - removing dmabuf listeners");
g_pHyprlock->removeDmabufListener();
}

View file

@ -23,8 +23,9 @@ class CAsyncResourceManager {
// Why not use ASP/AWP for this?
// The problem is that we want to to increment the reference as soon as requesting the resource id.
// Not only when actually retrieving the asset with `getAssetById`.
// Also, this way a resource is static as long as it is not unloaded by all instances that requested it.
// TODO:: Make a wrapper object that contains the resource id and unload with RAII.
// Managing the ref count here also allows for having an asset outlife it's original reference.
//
// Improvement idea: Make a wrapper object that contains the resource id and unload with RAII.
// Those are hash functions that return the id for a requested resource.
static ResourceID resourceIDForTextRequest(const CTextResource::STextResourceData& s);
@ -65,9 +66,11 @@ class CAsyncResourceManager {
bool request(ResourceID id, const AWP<IWidget>& widget);
// adds a new resource to m_resources and passes it to m_gatherer
void enqueue(ResourceID resourceID, const ASP<IAsyncResource>& resource, const AWP<IWidget>& widget);
// callback for finished resoruces.
// copies the resources cairo surface to a GL_TEXTURE_2D and sets it in the asset map.
// removes the entry in m_resources.
// call onAssetUpdate for all stored widget references.
void onResourceFinished(ResourceID id);
void onScreencopyDone();
// for polling when using gatherInitialResources
bool m_gathered = false;