From 376dcd3b92931635306c357e0d7e2cb3f3073495 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20=C3=85dahl?= Date: Mon, 24 Jul 2017 17:29:22 +0800 Subject: [PATCH] gpu-kms: Pass GPU on page flip callbacks https://bugzilla.gnome.org/show_bug.cgi?id=785381 --- src/backends/native/meta-gpu-kms.c | 41 +++++++++++++++++----- src/backends/native/meta-renderer-native.c | 3 +- 2 files changed, 35 insertions(+), 9 deletions(-) diff --git a/src/backends/native/meta-gpu-kms.c b/src/backends/native/meta-gpu-kms.c index 0b70c3864..38c2e9b95 100644 --- a/src/backends/native/meta-gpu-kms.c +++ b/src/backends/native/meta-gpu-kms.c @@ -150,13 +150,19 @@ meta_gpu_kms_apply_crtc_mode (MetaGpuKms *gpu_kms, } static void -invoke_flip_closure (GClosure *flip_closure) +invoke_flip_closure (GClosure *flip_closure, + MetaGpuKms *gpu_kms) { - GValue param = G_VALUE_INIT; + GValue params[] = { + G_VALUE_INIT, + G_VALUE_INIT + }; - g_value_init (¶m, G_TYPE_POINTER); - g_value_set_pointer (¶m, flip_closure); - g_closure_invoke (flip_closure, NULL, 1, ¶m, NULL); + g_value_init (¶ms[0], G_TYPE_POINTER); + g_value_set_pointer (¶ms[0], flip_closure); + g_value_init (¶ms[1], G_TYPE_OBJECT); + g_value_set_object (¶ms[1], gpu_kms); + g_closure_invoke (flip_closure, NULL, 2, params, NULL); g_closure_unref (flip_closure); } @@ -169,6 +175,8 @@ meta_gpu_kms_is_crtc_active (MetaGpuKms *gpu_kms, GList *l; gboolean connected_crtc_found; + g_assert (meta_crtc_get_gpu (crtc) == META_GPU (gpu_kms)); + if (monitor_manager->power_save_mode != META_POWER_SAVE_ON) return FALSE; @@ -190,6 +198,12 @@ meta_gpu_kms_is_crtc_active (MetaGpuKms *gpu_kms, return TRUE; } +typedef struct _GpuClosureContainer +{ + GClosure *flip_closure; + MetaGpuKms *gpu_kms; +} GpuClosureContainer; + gboolean meta_gpu_kms_flip_crtc (MetaGpuKms *gpu_kms, MetaCrtc *crtc, @@ -213,15 +227,23 @@ meta_gpu_kms_flip_crtc (MetaGpuKms *gpu_kms, if (!gpu_kms->page_flips_not_supported) { + GpuClosureContainer *closure_container; int kms_fd = meta_gpu_kms_get_fd (gpu_kms); + closure_container = g_new0 (GpuClosureContainer, 1); + *closure_container = (GpuClosureContainer) { + .flip_closure = flip_closure, + .gpu_kms = gpu_kms + }; + ret = drmModePageFlip (kms_fd, crtc->crtc_id, fb_id, DRM_MODE_PAGE_FLIP_EVENT, - flip_closure); + closure_container); if (ret != 0 && ret != -EACCES) { + g_free (closure_container); g_warning ("Failed to flip: %s", strerror (-ret)); gpu_kms->page_flips_not_supported = TRUE; } @@ -252,9 +274,12 @@ page_flip_handler (int fd, unsigned int usec, void *user_data) { - GClosure *flip_closure = user_data; + GpuClosureContainer *closure_container = user_data; + GClosure *flip_closure = closure_container->flip_closure; + MetaGpuKms *gpu_kms = closure_container->gpu_kms; - invoke_flip_closure (flip_closure); + invoke_flip_closure (flip_closure, gpu_kms); + g_free (closure_container); } gboolean diff --git a/src/backends/native/meta-renderer-native.c b/src/backends/native/meta-renderer-native.c index ede5ac3f7..c986bd763 100644 --- a/src/backends/native/meta-renderer-native.c +++ b/src/backends/native/meta-renderer-native.c @@ -548,6 +548,7 @@ meta_onscreen_native_swap_drm_fb (CoglOnscreen *onscreen) static void on_crtc_flipped (GClosure *closure, + MetaGpuKms *gpu_kms, MetaRendererView *view) { ClutterStageView *stage_view = CLUTTER_STAGE_VIEW (view); @@ -852,7 +853,7 @@ meta_onscreen_native_flip_crtcs (CoglOnscreen *onscreen) flip_closure = g_cclosure_new (G_CALLBACK (on_crtc_flipped), g_object_ref (view), (GClosureNotify) flip_closure_destroyed); - g_closure_set_marshal (flip_closure, g_cclosure_marshal_VOID__VOID); + g_closure_set_marshal (flip_closure, g_cclosure_marshal_VOID__OBJECT); /* Either flip the CRTC's of the monitor info, if we are drawing just part * of the stage, or all of the CRTC's if we are drawing the whole stage.