diff --git a/src/renderer/AsyncResourceManager.cpp b/src/renderer/AsyncResourceManager.cpp index 3698811..987c52c 100644 --- a/src/renderer/AsyncResourceManager.cpp +++ b/src/renderer/AsyncResourceManager.cpp @@ -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(); @@ -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(); -} diff --git a/src/renderer/AsyncResourceManager.hpp b/src/renderer/AsyncResourceManager.hpp index e07059d..ceda39b 100644 --- a/src/renderer/AsyncResourceManager.hpp +++ b/src/renderer/AsyncResourceManager.hpp @@ -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& widget); // adds a new resource to m_resources and passes it to m_gatherer void enqueue(ResourceID resourceID, const ASP& resource, const AWP& 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;