backends: Move clutter frame clock freeze/thaw API to ClutterSTage

It had nothing to do with EGL or the eglnative backend, and will be used
by non-native backends, so move it to a common place.

https://gitlab.gnome.org/GNOME/mutter/merge_requests/170
This commit is contained in:
Jonas Ådahl 2018-07-12 15:01:55 +02:00
parent 9adf8826d2
commit 213ed80284
5 changed files with 68 additions and 66 deletions

View File

@ -46,6 +46,12 @@ void clutter_stage_capture_into (ClutterStage *stage,
cairo_rectangle_int_t *rect,
uint8_t *data);
CLUTTER_EXPORT
void clutter_stage_freeze_updates (ClutterStage *stage);
CLUTTER_EXPORT
void clutter_stage_thaw_updates (ClutterStage *stage);
#undef __CLUTTER_H_INSIDE__
#endif /* __CLUTTER_MUTTER_H__ */

View File

@ -146,6 +146,8 @@ struct _ClutterStagePrivate
gpointer paint_data;
GDestroyNotify paint_notify;
int update_freeze_count;
guint relayout_pending : 1;
guint redraw_pending : 1;
guint is_fullscreen : 1;
@ -4900,3 +4902,58 @@ clutter_stage_capture_into (ClutterStage *stage,
view = get_view_at_rect (stage, rect);
capture_view_into (stage, paint, view, rect, data, rect->width * bpp);
}
/**
* clutter_stage_freeze_updates:
*
* Freezing updates makes Clutter stop processing events,
* redrawing, and advancing timelines, by pausing the master clock. This is
* necessary when implementing a display server, to ensure that Clutter doesn't
* keep trying to page flip when DRM master has been dropped, e.g. when VT
* switched away.
*
* The master clock starts out running, so if you are VT switched away on
* startup, you need to call this immediately.
*
* To thaw updates, use clutter_stage_thaw_updates().
*/
void
clutter_stage_freeze_updates (ClutterStage *stage)
{
ClutterStagePrivate *priv = stage->priv;
priv->update_freeze_count++;
if (priv->update_freeze_count == 1)
{
ClutterMasterClock *master_clock;
master_clock = _clutter_master_clock_get_default ();
_clutter_master_clock_set_paused (master_clock, TRUE);
}
}
/**
* clutter_stage_thaw_updates:
*
* Resumes a master clock that has previously been frozen with
* clutter_stage_freeze_updates(), and start pumping the master clock
* again at the next iteration. Note that if you're switching back to your
* own VT, you should probably also queue a stage redraw with
* clutter_stage_ensure_redraw().
*/
void
clutter_stage_thaw_updates (ClutterStage *stage)
{
ClutterStagePrivate *priv = stage->priv;
g_assert (priv->update_freeze_count > 0);
priv->update_freeze_count--;
if (priv->update_freeze_count == 0)
{
ClutterMasterClock *master_clock;
master_clock = _clutter_master_clock_get_default ();
_clutter_master_clock_set_paused (master_clock, FALSE);
}
}

View File

@ -333,57 +333,3 @@ clutter_egl_get_egl_display (void)
return 0;
#endif
}
/**
* clutter_egl_freeze_master_clock:
*
* Freezing the master clock makes Clutter stop processing events,
* redrawing, and advancing timelines. This is necessary when implementing
* a display server, to ensure that Clutter doesn't keep trying to page
* flip when DRM master has been dropped, e.g. when VT switched away.
*
* The master clock starts out running, so if you are VT switched away on
* startup, you need to call this immediately.
*
* If you're also using the evdev backend, make sure to also use
* clutter_evdev_release_devices() to make sure that Clutter doesn't also
* access revoked evdev devices when VT switched away.
*
* To unthaw a frozen master clock, use clutter_egl_thaw_master_clock().
*
* Since: 1.20
*/
void
clutter_egl_freeze_master_clock (void)
{
ClutterMasterClock *master_clock;
g_return_if_fail (CLUTTER_IS_BACKEND_EGL_NATIVE (clutter_get_default_backend ()));
master_clock = _clutter_master_clock_get_default ();
_clutter_master_clock_set_paused (master_clock, TRUE);
}
/**
* clutter_egl_thaw_master_clock:
*
* Thaws a master clock that has previously been frozen with
* clutter_egl_freeze_master_clock(), and start pumping the master clock
* again at the next iteration. Note that if you're switching back to your
* own VT, you should probably also queue a stage redraw with
* clutter_stage_ensure_redraw().
*
* Since: 1.20
*/
void
clutter_egl_thaw_master_clock (void)
{
ClutterMasterClock *master_clock;
g_return_if_fail (CLUTTER_IS_BACKEND_EGL_NATIVE (clutter_get_default_backend ()));
master_clock = _clutter_master_clock_get_default ();
_clutter_master_clock_set_paused (master_clock, FALSE);
_clutter_master_clock_start_running (master_clock);
}

View File

@ -87,11 +87,6 @@ EGLDisplay clutter_egl_display (void);
CLUTTER_EXPORT
EGLDisplay clutter_egl_get_egl_display (void);
CLUTTER_EXPORT
void clutter_egl_freeze_master_clock (void);
CLUTTER_EXPORT
void clutter_egl_thaw_master_clock (void);
G_END_DECLS
#endif /* __CLUTTER_EGL_H__ */

View File

@ -44,8 +44,6 @@
#include "backends/native/meta-renderer-native.h"
#include "backends/native/meta-stage-native.h"
#include "clutter/evdev/clutter-evdev.h"
#include "clutter/egl/clutter-egl.h"
#include "clutter/evdev/clutter-evdev.h"
#include "core/meta-border.h"
#include "meta/main.h"
@ -625,13 +623,14 @@ void
meta_backend_native_pause (MetaBackendNative *native)
{
MetaBackend *backend = META_BACKEND (native);
ClutterStage *stage = CLUTTER_STAGE (meta_backend_get_stage (backend));
MetaMonitorManager *monitor_manager =
meta_backend_get_monitor_manager (backend);
MetaMonitorManagerKms *monitor_manager_kms =
META_MONITOR_MANAGER_KMS (monitor_manager);
clutter_evdev_release_devices ();
clutter_egl_freeze_master_clock ();
clutter_stage_freeze_updates (stage);
meta_monitor_manager_kms_pause (monitor_manager_kms);
}
@ -639,20 +638,19 @@ meta_backend_native_pause (MetaBackendNative *native)
void meta_backend_native_resume (MetaBackendNative *native)
{
MetaBackend *backend = META_BACKEND (native);
ClutterStage *stage = CLUTTER_STAGE (meta_backend_get_stage (backend));
MetaMonitorManager *monitor_manager =
meta_backend_get_monitor_manager (backend);
MetaMonitorManagerKms *monitor_manager_kms =
META_MONITOR_MANAGER_KMS (monitor_manager);
ClutterActor *stage;
MetaIdleMonitor *idle_monitor;
meta_monitor_manager_kms_resume (monitor_manager_kms);
clutter_evdev_reclaim_devices ();
clutter_egl_thaw_master_clock ();
clutter_stage_thaw_updates (stage);
stage = meta_backend_get_stage (backend);
clutter_actor_queue_redraw (stage);
clutter_actor_queue_redraw (CLUTTER_ACTOR (stage));
idle_monitor = meta_backend_get_idle_monitor (backend, 0);
meta_idle_monitor_reset_idletime (idle_monitor);