mirror of
https://github.com/brl/mutter.git
synced 2025-06-13 16:59:30 +00:00
frame-clock: Add API to inhibit/uninhibit updates
Equivalent to pause/resume, but ref counted. https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1285
This commit is contained in:
@ -78,11 +78,32 @@ struct _ClutterFrameClock
|
||||
|
||||
gboolean pending_reschedule;
|
||||
gboolean pending_reschedule_now;
|
||||
|
||||
int inhibit_count;
|
||||
};
|
||||
|
||||
G_DEFINE_TYPE (ClutterFrameClock, clutter_frame_clock,
|
||||
G_TYPE_OBJECT)
|
||||
|
||||
static void
|
||||
maybe_reschedule_update (ClutterFrameClock *frame_clock)
|
||||
{
|
||||
if (frame_clock->pending_reschedule)
|
||||
{
|
||||
frame_clock->pending_reschedule = FALSE;
|
||||
|
||||
if (frame_clock->pending_reschedule_now)
|
||||
{
|
||||
frame_clock->pending_reschedule_now = FALSE;
|
||||
clutter_frame_clock_schedule_update_now (frame_clock);
|
||||
}
|
||||
else
|
||||
{
|
||||
clutter_frame_clock_schedule_update (frame_clock);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
clutter_frame_clock_notify_presented (ClutterFrameClock *frame_clock,
|
||||
int64_t presentation_time_us)
|
||||
@ -111,21 +132,7 @@ clutter_frame_clock_notify_presented (ClutterFrameClock *frame_clock,
|
||||
case CLUTTER_FRAME_CLOCK_STATE_DISPATCHING:
|
||||
case CLUTTER_FRAME_CLOCK_STATE_PENDING_PRESENTED:
|
||||
frame_clock->state = CLUTTER_FRAME_CLOCK_STATE_IDLE;
|
||||
|
||||
if (frame_clock->pending_reschedule)
|
||||
{
|
||||
frame_clock->pending_reschedule = FALSE;
|
||||
|
||||
if (frame_clock->pending_reschedule_now)
|
||||
{
|
||||
frame_clock->pending_reschedule_now = FALSE;
|
||||
clutter_frame_clock_schedule_update_now (frame_clock);
|
||||
}
|
||||
else
|
||||
{
|
||||
clutter_frame_clock_schedule_update (frame_clock);
|
||||
}
|
||||
}
|
||||
maybe_reschedule_update (frame_clock);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -194,11 +201,54 @@ calculate_next_update_time_us (ClutterFrameClock *frame_clock,
|
||||
*out_next_presentation_time_us = next_presentation_time_us;
|
||||
}
|
||||
|
||||
void
|
||||
clutter_frame_clock_inhibit (ClutterFrameClock *frame_clock)
|
||||
{
|
||||
frame_clock->inhibit_count++;
|
||||
|
||||
if (frame_clock->inhibit_count == 1)
|
||||
{
|
||||
switch (frame_clock->state)
|
||||
{
|
||||
case CLUTTER_FRAME_CLOCK_STATE_INIT:
|
||||
case CLUTTER_FRAME_CLOCK_STATE_IDLE:
|
||||
break;
|
||||
case CLUTTER_FRAME_CLOCK_STATE_SCHEDULED:
|
||||
frame_clock->pending_reschedule = TRUE;
|
||||
frame_clock->state = CLUTTER_FRAME_CLOCK_STATE_IDLE;
|
||||
break;
|
||||
case CLUTTER_FRAME_CLOCK_STATE_DISPATCHING:
|
||||
case CLUTTER_FRAME_CLOCK_STATE_PENDING_PRESENTED:
|
||||
break;
|
||||
}
|
||||
|
||||
g_source_set_ready_time (frame_clock->source, -1);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
clutter_frame_clock_uninhibit (ClutterFrameClock *frame_clock)
|
||||
{
|
||||
g_return_if_fail (frame_clock->inhibit_count > 0);
|
||||
|
||||
frame_clock->inhibit_count--;
|
||||
|
||||
if (frame_clock->inhibit_count == 0)
|
||||
maybe_reschedule_update (frame_clock);
|
||||
}
|
||||
|
||||
void
|
||||
clutter_frame_clock_schedule_update_now (ClutterFrameClock *frame_clock)
|
||||
{
|
||||
int64_t next_update_time_us = -1;
|
||||
|
||||
if (frame_clock->inhibit_count > 0)
|
||||
{
|
||||
frame_clock->pending_reschedule = TRUE;
|
||||
frame_clock->pending_reschedule_now = TRUE;
|
||||
return;
|
||||
}
|
||||
|
||||
switch (frame_clock->state)
|
||||
{
|
||||
case CLUTTER_FRAME_CLOCK_STATE_INIT:
|
||||
@ -226,6 +276,12 @@ clutter_frame_clock_schedule_update (ClutterFrameClock *frame_clock)
|
||||
{
|
||||
int64_t next_update_time_us = -1;
|
||||
|
||||
if (frame_clock->inhibit_count > 0)
|
||||
{
|
||||
frame_clock->pending_reschedule = TRUE;
|
||||
return;
|
||||
}
|
||||
|
||||
switch (frame_clock->state)
|
||||
{
|
||||
case CLUTTER_FRAME_CLOCK_STATE_INIT:
|
||||
|
@ -61,4 +61,10 @@ void clutter_frame_clock_schedule_update (ClutterFrameClock *frame_clock);
|
||||
CLUTTER_EXPORT
|
||||
void clutter_frame_clock_schedule_update_now (ClutterFrameClock *frame_clock);
|
||||
|
||||
CLUTTER_EXPORT
|
||||
void clutter_frame_clock_inhibit (ClutterFrameClock *frame_clock);
|
||||
|
||||
CLUTTER_EXPORT
|
||||
void clutter_frame_clock_uninhibit (ClutterFrameClock *frame_clock);
|
||||
|
||||
#endif /* CLUTTER_FRAME_CLOCK_H */
|
||||
|
Reference in New Issue
Block a user