mirror of
https://github.com/hyprwm/hyprlock.git
synced 2024-11-16 23:05:58 +01:00
widgets: move asset updates out of the draw function (#442)
* label: move asset updates out of the draw function This allows us to check if the label has actually updated after the callback from the asyncResourceGatherer. If it isn't we can requeue the renderUpdate() function. * image: move asset updates out of the draw function
This commit is contained in:
parent
3e71799b30
commit
cf0e975fed
4 changed files with 46 additions and 42 deletions
|
@ -20,7 +20,11 @@ static void onTimer(std::shared_ptr<CTimer> self, void* data) {
|
|||
|
||||
static void onAssetCallback(void* data) {
|
||||
const auto PIMAGE = (CImage*)data;
|
||||
PIMAGE->renderSuper();
|
||||
PIMAGE->renderUpdate();
|
||||
}
|
||||
|
||||
static void onAssetCallbackTimer(std::shared_ptr<CTimer> 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<CTimer> 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);
|
||||
}
|
||||
|
|
|
@ -21,7 +21,7 @@ class CImage : public IWidget {
|
|||
|
||||
virtual bool draw(const SRenderData& data);
|
||||
|
||||
void renderSuper();
|
||||
void renderUpdate();
|
||||
void onTimerUpdate();
|
||||
void plantTimer();
|
||||
|
||||
|
|
|
@ -27,7 +27,11 @@ static void onTimer(std::shared_ptr<CTimer> self, void* data) {
|
|||
|
||||
static void onAssetCallback(void* data) {
|
||||
const auto PLABEL = (CLabel*)data;
|
||||
PLABEL->renderSuper();
|
||||
PLABEL->renderUpdate();
|
||||
}
|
||||
|
||||
static void onAssetCallbackTimer(std::shared_ptr<CTimer> 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);
|
||||
}
|
||||
|
|
|
@ -19,7 +19,7 @@ class CLabel : public IWidget {
|
|||
|
||||
virtual bool draw(const SRenderData& data);
|
||||
|
||||
void renderSuper();
|
||||
void renderUpdate();
|
||||
void onTimerUpdate();
|
||||
void plantTimer();
|
||||
|
||||
|
|
Loading…
Reference in a new issue