diff --git a/src/renderer/widgets/Image.cpp b/src/renderer/widgets/Image.cpp index f5d1412..2e7a1b3 100644 --- a/src/renderer/widgets/Image.cpp +++ b/src/renderer/widgets/Image.cpp @@ -20,7 +20,11 @@ static void onTimer(std::shared_ptr self, void* data) { static void onAssetCallback(void* data) { const auto PIMAGE = (CImage*)data; - PIMAGE->renderSuper(); + PIMAGE->renderUpdate(); +} + +static void onAssetCallbackTimer(std::shared_ptr self, void* data) { + onAssetCallback(data); } void CImage::onTimerUpdate() { @@ -100,23 +104,6 @@ CImage::CImage(const Vector2D& viewport_, COutput* output_, const std::string& r bool CImage::draw(const SRenderData& data) { - if (!pendingResourceID.empty()) { - auto newAsset = g_pRenderer->asyncResourceGatherer->getAssetByID(pendingResourceID); - if (newAsset) { - if (newAsset->texture.m_iType == TEXTURE_INVALID) { - g_pRenderer->asyncResourceGatherer->unloadAsset(newAsset); - } else if (resourceID != pendingResourceID) { - g_pRenderer->asyncResourceGatherer->unloadAsset(asset); - imageFB.release(); - - asset = newAsset; - resourceID = pendingResourceID; - firstRender = true; - } - pendingResourceID = ""; - } - } - if (resourceID.empty()) return false; @@ -190,14 +177,25 @@ bool CImage::draw(const SRenderData& data) { return data.opacity < 1.0; } -static void onAssetCallbackTimer(std::shared_ptr self, void* data) { - const auto PIMAGE = (CImage*)data; - PIMAGE->renderSuper(); -} +void CImage::renderUpdate() { + auto newAsset = g_pRenderer->asyncResourceGatherer->getAssetByID(pendingResourceID); + if (newAsset) { + if (newAsset->texture.m_iType == TEXTURE_INVALID) { + g_pRenderer->asyncResourceGatherer->unloadAsset(newAsset); + } else if (resourceID != pendingResourceID) { + g_pRenderer->asyncResourceGatherer->unloadAsset(asset); + imageFB.release(); -void CImage::renderSuper() { - g_pHyprlock->renderOutput(output->stringPort); + asset = newAsset; + resourceID = pendingResourceID; + firstRender = true; + } + pendingResourceID = ""; + } else if (!pendingResourceID.empty()) { + Debug::log(WARN, "Asset {} not available after the asyncResourceGatherer's callback!", pendingResourceID); - if (!pendingResourceID.empty()) /* did not consume the pending resource */ g_pHyprlock->addTimer(std::chrono::milliseconds(100), onAssetCallbackTimer, this); + } + + g_pHyprlock->renderOutput(output->stringPort); } diff --git a/src/renderer/widgets/Image.hpp b/src/renderer/widgets/Image.hpp index 8a9906e..81fd374 100644 --- a/src/renderer/widgets/Image.hpp +++ b/src/renderer/widgets/Image.hpp @@ -21,7 +21,7 @@ class CImage : public IWidget { virtual bool draw(const SRenderData& data); - void renderSuper(); + void renderUpdate(); void onTimerUpdate(); void plantTimer(); diff --git a/src/renderer/widgets/Label.cpp b/src/renderer/widgets/Label.cpp index adc09ed..9559bcb 100644 --- a/src/renderer/widgets/Label.cpp +++ b/src/renderer/widgets/Label.cpp @@ -27,7 +27,11 @@ static void onTimer(std::shared_ptr self, void* data) { static void onAssetCallback(void* data) { const auto PLABEL = (CLabel*)data; - PLABEL->renderSuper(); + PLABEL->renderUpdate(); +} + +static void onAssetCallbackTimer(std::shared_ptr self, void* data) { + onAssetCallback(data); } std::string CLabel::getUniqueResourceId() { @@ -122,19 +126,6 @@ bool CLabel::draw(const SRenderData& data) { shadow.markShadowDirty(); } - if (!pendingResourceID.empty()) { - // new asset is pending - auto newAsset = g_pRenderer->asyncResourceGatherer->getAssetByID(pendingResourceID); - if (newAsset) { - // new asset is ready :D - g_pRenderer->asyncResourceGatherer->unloadAsset(asset); - asset = newAsset; - resourceID = pendingResourceID; - pendingResourceID = ""; - shadow.markShadowDirty(); - } - } - shadow.draw(data); // calc pos @@ -147,6 +138,21 @@ bool CLabel::draw(const SRenderData& data) { return false; } -void CLabel::renderSuper() { +void CLabel::renderUpdate() { + auto newAsset = g_pRenderer->asyncResourceGatherer->getAssetByID(pendingResourceID); + if (newAsset) { + // new asset is ready :D + g_pRenderer->asyncResourceGatherer->unloadAsset(asset); + asset = newAsset; + resourceID = pendingResourceID; + pendingResourceID = ""; + shadow.markShadowDirty(); + } else { + Debug::log(WARN, "Asset {} not available after the asyncResourceGatherer's callback!", pendingResourceID); + + g_pHyprlock->addTimer(std::chrono::milliseconds(100), onAssetCallbackTimer, this); + return; + } + g_pHyprlock->renderOutput(outputStringPort); } diff --git a/src/renderer/widgets/Label.hpp b/src/renderer/widgets/Label.hpp index 26b938d..d9bad77 100644 --- a/src/renderer/widgets/Label.hpp +++ b/src/renderer/widgets/Label.hpp @@ -19,7 +19,7 @@ class CLabel : public IWidget { virtual bool draw(const SRenderData& data); - void renderSuper(); + void renderUpdate(); void onTimerUpdate(); void plantTimer();