mirror of
https://github.com/hyprwm/Hyprland
synced 2024-11-14 04:45:58 +01:00
animationmgr: avoid redundant ticks
This commit is contained in:
parent
b925f1b497
commit
a077b7a92e
5 changed files with 52 additions and 9 deletions
|
@ -82,8 +82,11 @@ float CAnimatedVariable::getCurveValue() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void CAnimatedVariable::connectToActive() {
|
void CAnimatedVariable::connectToActive() {
|
||||||
|
g_pAnimationManager->scheduleTick(); // otherwise the animation manager will never pick this up
|
||||||
|
|
||||||
if (!m_bIsConnectedToActive)
|
if (!m_bIsConnectedToActive)
|
||||||
g_pAnimationManager->m_vActiveAnimatedVariables.push_back(this);
|
g_pAnimationManager->m_vActiveAnimatedVariables.push_back(this);
|
||||||
|
|
||||||
m_bIsConnectedToActive = true;
|
m_bIsConnectedToActive = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -15,3 +15,7 @@ int CTimer::getMillis() {
|
||||||
float CTimer::getSeconds() {
|
float CTimer::getSeconds() {
|
||||||
return std::chrono::duration_cast<std::chrono::milliseconds>(getDuration()).count() / 1000.f;
|
return std::chrono::duration_cast<std::chrono::milliseconds>(getDuration()).count() / 1000.f;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const std::chrono::system_clock::time_point& CTimer::chrono() const {
|
||||||
|
return m_tpLastReset;
|
||||||
|
}
|
|
@ -4,9 +4,10 @@
|
||||||
|
|
||||||
class CTimer {
|
class CTimer {
|
||||||
public:
|
public:
|
||||||
void reset();
|
void reset();
|
||||||
float getSeconds();
|
float getSeconds();
|
||||||
int getMillis();
|
int getMillis();
|
||||||
|
const std::chrono::system_clock::time_point& chrono() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::chrono::system_clock::time_point m_tpLastReset;
|
std::chrono::system_clock::time_point m_tpLastReset;
|
||||||
|
|
|
@ -4,16 +4,15 @@
|
||||||
|
|
||||||
int wlTick(void* data) {
|
int wlTick(void* data) {
|
||||||
|
|
||||||
float refreshRate = g_pHyprRenderer->m_pMostHzMonitor ? g_pHyprRenderer->m_pMostHzMonitor->refreshRate : 60.f;
|
|
||||||
|
|
||||||
wl_event_source_timer_update(g_pAnimationManager->m_pAnimationTick, 1000 / refreshRate);
|
|
||||||
|
|
||||||
if (g_pCompositor->m_bSessionActive && g_pAnimationManager && g_pHookSystem &&
|
if (g_pCompositor->m_bSessionActive && g_pAnimationManager && g_pHookSystem &&
|
||||||
std::ranges::any_of(g_pCompositor->m_vMonitors, [](const auto& mon) { return mon->m_bEnabled && mon->output; })) {
|
std::ranges::any_of(g_pCompositor->m_vMonitors, [](const auto& mon) { return mon->m_bEnabled && mon->output; })) {
|
||||||
g_pAnimationManager->tick();
|
g_pAnimationManager->tick();
|
||||||
EMIT_HOOK_EVENT("tick", nullptr);
|
EMIT_HOOK_EVENT("tick", nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (g_pAnimationManager && g_pAnimationManager->shouldTickForNext())
|
||||||
|
g_pAnimationManager->scheduleTick();
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -40,10 +39,15 @@ void CAnimationManager::addBezierWithName(std::string name, const Vector2D& p1,
|
||||||
|
|
||||||
void CAnimationManager::tick() {
|
void CAnimationManager::tick() {
|
||||||
|
|
||||||
|
m_bTickScheduled = false;
|
||||||
|
|
||||||
static std::chrono::time_point lastTick = std::chrono::high_resolution_clock::now();
|
static std::chrono::time_point lastTick = std::chrono::high_resolution_clock::now();
|
||||||
m_fLastTickTime = std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::high_resolution_clock::now() - lastTick).count() / 1000.0;
|
m_fLastTickTime = std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::high_resolution_clock::now() - lastTick).count() / 1000.0;
|
||||||
lastTick = std::chrono::high_resolution_clock::now();
|
lastTick = std::chrono::high_resolution_clock::now();
|
||||||
|
|
||||||
|
if (m_vActiveAnimatedVariables.empty())
|
||||||
|
return;
|
||||||
|
|
||||||
bool animGlobalDisabled = false;
|
bool animGlobalDisabled = false;
|
||||||
|
|
||||||
static auto* const PANIMENABLED = &g_pConfigManager->getConfigValuePtr("animations:enabled")->intValue;
|
static auto* const PANIMENABLED = &g_pConfigManager->getConfigValuePtr("animations:enabled")->intValue;
|
||||||
|
@ -244,8 +248,8 @@ void CAnimationManager::tick() {
|
||||||
const auto EXTENTS = PDECO->getWindowDecorationExtents();
|
const auto EXTENTS = PDECO->getWindowDecorationExtents();
|
||||||
|
|
||||||
wlr_box dmg = {PWINDOW->m_vRealPosition.vec().x - EXTENTS.topLeft.x, PWINDOW->m_vRealPosition.vec().y - EXTENTS.topLeft.y,
|
wlr_box dmg = {PWINDOW->m_vRealPosition.vec().x - EXTENTS.topLeft.x, PWINDOW->m_vRealPosition.vec().y - EXTENTS.topLeft.y,
|
||||||
PWINDOW->m_vRealSize.vec().x + EXTENTS.topLeft.x + EXTENTS.bottomRight.x,
|
PWINDOW->m_vRealSize.vec().x + EXTENTS.topLeft.x + EXTENTS.bottomRight.x,
|
||||||
PWINDOW->m_vRealSize.vec().y + EXTENTS.topLeft.y + EXTENTS.bottomRight.y};
|
PWINDOW->m_vRealSize.vec().y + EXTENTS.topLeft.y + EXTENTS.bottomRight.y};
|
||||||
|
|
||||||
if (!*PSHADOWIGNOREWINDOW) {
|
if (!*PSHADOWIGNOREWINDOW) {
|
||||||
// easy, damage the entire box
|
// easy, damage the entire box
|
||||||
|
@ -504,3 +508,30 @@ CBezierCurve* CAnimationManager::getBezier(const std::string& name) {
|
||||||
std::unordered_map<std::string, CBezierCurve> CAnimationManager::getAllBeziers() {
|
std::unordered_map<std::string, CBezierCurve> CAnimationManager::getAllBeziers() {
|
||||||
return m_mBezierCurves;
|
return m_mBezierCurves;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool CAnimationManager::shouldTickForNext() {
|
||||||
|
return !m_vActiveAnimatedVariables.empty();
|
||||||
|
}
|
||||||
|
|
||||||
|
void CAnimationManager::scheduleTick() {
|
||||||
|
if (m_bTickScheduled)
|
||||||
|
return;
|
||||||
|
|
||||||
|
m_bTickScheduled = true;
|
||||||
|
|
||||||
|
const auto PMOSTHZ = g_pHyprRenderer->m_pMostHzMonitor;
|
||||||
|
|
||||||
|
float refreshRate = PMOSTHZ ? PMOSTHZ->refreshRate : 60.f;
|
||||||
|
float refreshDelayMs = std::floor(1000.0 / refreshRate);
|
||||||
|
|
||||||
|
if (!PMOSTHZ) {
|
||||||
|
wl_event_source_timer_update(m_pAnimationTick, refreshDelayMs);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const float SINCEPRES = std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::system_clock::now() - PMOSTHZ->lastPresentationTimer.chrono()).count() / 1000.0;
|
||||||
|
|
||||||
|
const auto TOPRES = std::clamp(refreshDelayMs - SINCEPRES, 1.1f, 1000.f); // we can't send 0, that will disarm it
|
||||||
|
|
||||||
|
wl_event_source_timer_update(m_pAnimationTick, std::floor(TOPRES));
|
||||||
|
}
|
||||||
|
|
|
@ -13,6 +13,8 @@ class CAnimationManager {
|
||||||
CAnimationManager();
|
CAnimationManager();
|
||||||
|
|
||||||
void tick();
|
void tick();
|
||||||
|
bool shouldTickForNext();
|
||||||
|
void scheduleTick();
|
||||||
void addBezierWithName(std::string, const Vector2D&, const Vector2D&);
|
void addBezierWithName(std::string, const Vector2D&, const Vector2D&);
|
||||||
void removeAllBeziers();
|
void removeAllBeziers();
|
||||||
|
|
||||||
|
@ -42,6 +44,8 @@ class CAnimationManager {
|
||||||
|
|
||||||
std::unordered_map<std::string, CBezierCurve> m_mBezierCurves;
|
std::unordered_map<std::string, CBezierCurve> m_mBezierCurves;
|
||||||
|
|
||||||
|
bool m_bTickScheduled = false;
|
||||||
|
|
||||||
// Anim stuff
|
// Anim stuff
|
||||||
void animationPopin(CWindow*, bool close = false, float minPerc = 0.f);
|
void animationPopin(CWindow*, bool close = false, float minPerc = 0.f);
|
||||||
void animationSlide(CWindow*, std::string force = "", bool close = false);
|
void animationSlide(CWindow*, std::string force = "", bool close = false);
|
||||||
|
|
Loading…
Reference in a new issue