gpu-kms: Pass GPU on page flip callbacks

https://bugzilla.gnome.org/show_bug.cgi?id=785381
This commit is contained in:
Jonas Ådahl 2017-07-24 17:29:22 +08:00
parent 60781bc6c2
commit 376dcd3b92
2 changed files with 35 additions and 9 deletions

View File

@ -150,13 +150,19 @@ meta_gpu_kms_apply_crtc_mode (MetaGpuKms *gpu_kms,
} }
static void 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 (&param, G_TYPE_POINTER); g_value_init (&params[0], G_TYPE_POINTER);
g_value_set_pointer (&param, flip_closure); g_value_set_pointer (&params[0], flip_closure);
g_closure_invoke (flip_closure, NULL, 1, &param, NULL); g_value_init (&params[1], G_TYPE_OBJECT);
g_value_set_object (&params[1], gpu_kms);
g_closure_invoke (flip_closure, NULL, 2, params, NULL);
g_closure_unref (flip_closure); g_closure_unref (flip_closure);
} }
@ -169,6 +175,8 @@ meta_gpu_kms_is_crtc_active (MetaGpuKms *gpu_kms,
GList *l; GList *l;
gboolean connected_crtc_found; 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) if (monitor_manager->power_save_mode != META_POWER_SAVE_ON)
return FALSE; return FALSE;
@ -190,6 +198,12 @@ meta_gpu_kms_is_crtc_active (MetaGpuKms *gpu_kms,
return TRUE; return TRUE;
} }
typedef struct _GpuClosureContainer
{
GClosure *flip_closure;
MetaGpuKms *gpu_kms;
} GpuClosureContainer;
gboolean gboolean
meta_gpu_kms_flip_crtc (MetaGpuKms *gpu_kms, meta_gpu_kms_flip_crtc (MetaGpuKms *gpu_kms,
MetaCrtc *crtc, MetaCrtc *crtc,
@ -213,15 +227,23 @@ meta_gpu_kms_flip_crtc (MetaGpuKms *gpu_kms,
if (!gpu_kms->page_flips_not_supported) if (!gpu_kms->page_flips_not_supported)
{ {
GpuClosureContainer *closure_container;
int kms_fd = meta_gpu_kms_get_fd (gpu_kms); 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, ret = drmModePageFlip (kms_fd,
crtc->crtc_id, crtc->crtc_id,
fb_id, fb_id,
DRM_MODE_PAGE_FLIP_EVENT, DRM_MODE_PAGE_FLIP_EVENT,
flip_closure); closure_container);
if (ret != 0 && ret != -EACCES) if (ret != 0 && ret != -EACCES)
{ {
g_free (closure_container);
g_warning ("Failed to flip: %s", strerror (-ret)); g_warning ("Failed to flip: %s", strerror (-ret));
gpu_kms->page_flips_not_supported = TRUE; gpu_kms->page_flips_not_supported = TRUE;
} }
@ -252,9 +274,12 @@ page_flip_handler (int fd,
unsigned int usec, unsigned int usec,
void *user_data) 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 gboolean

View File

@ -548,6 +548,7 @@ meta_onscreen_native_swap_drm_fb (CoglOnscreen *onscreen)
static void static void
on_crtc_flipped (GClosure *closure, on_crtc_flipped (GClosure *closure,
MetaGpuKms *gpu_kms,
MetaRendererView *view) MetaRendererView *view)
{ {
ClutterStageView *stage_view = CLUTTER_STAGE_VIEW (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), flip_closure = g_cclosure_new (G_CALLBACK (on_crtc_flipped),
g_object_ref (view), g_object_ref (view),
(GClosureNotify) flip_closure_destroyed); (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 /* 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. * of the stage, or all of the CRTC's if we are drawing the whole stage.