Phosphor
Qt6 / Wayland library suite for window-management tools
 
Loading...
Searching...
No Matches
AnimatedValue_lifecycle_extras.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2026 fuddlesworth
2// SPDX-License-Identifier: LGPL-2.1-or-later
3
4#pragma once
5
6// Auxiliary lifecycle helpers for AnimatedValue<T, Space>: rebindClock,
7// seedFrom, seedSpecFrom. Included from AnimatedValue.h — do not
8// include directly.
9
10namespace PhosphorAnimation {
11
16template<typename T, ColorSpace Space>
18{
19 if (newClock == m_spec.clock) {
20 return;
21 }
22 if (!newClock) {
23 cancel();
24 return;
25 }
26 // Epoch-compatibility gate: rebase arithmetic assumes both clocks
27 // share a monotonic time base. Checked even before first advance
28 // to prevent silently installing an incompatible clock.
29 if (m_spec.clock) {
30 if (!IMotionClock::epochCompatible(m_spec.clock, newClock)) {
31 if (!m_loggedEpochMismatch) {
32 qCWarning(lcAnimatedValue)
33 << "rebindClock refused: epoch identity mismatch "
34 << "(old=" << m_spec.clock->epochIdentity() << ", new=" << newClock->epochIdentity()
35 << ") — rebase would corrupt progress. Keeping captured clock.";
36 m_loggedEpochMismatch = true;
37 }
38 return;
39 }
40 if (m_startTime) {
41 const auto oldNow = m_spec.clock->now();
42 const auto newNow = newClock->now();
43 const auto delta = newNow - oldNow;
44 *m_startTime += delta;
45 if (m_lastTickTime) {
46 *m_lastTickTime += delta;
47 }
48 }
49 }
50 m_spec.clock = newClock;
51 if (m_isAnimating) {
52 newClock->requestFrame();
53 }
54}
55
58template<typename T, ColorSpace Space>
59template<ColorSpace OtherSpace>
61{
62 if (m_isAnimating || other.m_isAnimating) {
63 return;
64 }
65 m_from = other.m_from;
66 m_to = other.m_to;
67 m_current = other.m_current;
68 m_isComplete = other.m_isComplete;
69}
70
73template<typename T, ColorSpace Space>
74template<ColorSpace OtherSpace>
76{
77 if (m_isAnimating) {
78 return;
79 }
80 m_spec.clock = other.m_spec.clock;
81 m_spec.onValueChanged = other.m_spec.onValueChanged;
82 m_spec.onComplete = other.m_spec.onComplete;
83 m_spec.retargetPolicy = other.m_spec.retargetPolicy;
84}
85
86} // namespace PhosphorAnimation
Unified motion primitive: one value of type T transitioning from start to target over time,...
Definition AnimatedValue.h:44
void rebindClock(IMotionClock *newClock)
Swap the driving clock without touching target/state/interpolation.
Definition AnimatedValue_lifecycle_extras.h:17
void seedSpecFrom(const AnimatedValue< T, OtherSpace > &other)
Companion to seedFrom — copies clock + callbacks, leaves profile alone.
Definition AnimatedValue_lifecycle_extras.h:75
void seedFrom(const AnimatedValue< T, OtherSpace > &other)
Cross-Space idle-state copy for color-space wrapper dispatch.
Definition AnimatedValue_lifecycle_extras.h:60
Abstract clock interface for the motion runtime.
Definition IMotionClock.h:18
static bool epochCompatible(const IMotionClock *a, const IMotionClock *b)
True iff both clocks are non-null and share the same non-null epochIdentity.
Definition IMotionClock.h:48
virtual void requestFrame()=0
Schedule another paint tick. Idempotent within a single frame.
virtual std::chrono::nanoseconds now() const =0
Monotonically non-decreasing steady-clock reading (nanoseconds).
virtual const void * epochIdentity() const
Opaque epoch identity for rebindClock compatibility.
Definition IMotionClock.h:39
Definition AnimatedValue.h:31