GstWlDisplay * gst_wl_display_new_existing (struct wl_display * display, gboolean take_ownership, GError ** error) { GstWlDisplay *self; GError *err = NULL; gint i; g_return_val_if_fail (display != NULL, NULL); self = g_object_new (GST_TYPE_WL_DISPLAY, NULL); self->display = display; self->own_display = take_ownership; self->queue = wl_display_create_queue (self->display); self->registry = wl_display_get_registry (self->display); wl_proxy_set_queue ((struct wl_proxy *) self->registry, self->queue); wl_registry_add_listener (self->registry, ®istry_listener, self); /* we need exactly 2 roundtrips to discover global objects and their state */ for (i = 0; i < 2; i++) { if (gst_wl_display_roundtrip (self) < 0) { *error = g_error_new (g_quark_from_static_string ("GstWlDisplay"), 0, "Error communicating with the wayland display"); g_object_unref (self); return NULL; } } /* verify we got all the required interfaces */ #define VERIFY_INTERFACE_EXISTS(var, interface) \ if (!self->var) { \ g_set_error (error, g_quark_from_static_string ("GstWlDisplay"), 0, \ "Could not bind to " interface ". Either it is not implemented in " \ "the compositor, or the implemented version doesn't match"); \ g_object_unref (self); \ return NULL; \ } VERIFY_INTERFACE_EXISTS (compositor, "wl_compositor"); VERIFY_INTERFACE_EXISTS (subcompositor, "wl_subcompositor"); VERIFY_INTERFACE_EXISTS (shell, "wl_shell"); VERIFY_INTERFACE_EXISTS (shm, "wl_shm"); VERIFY_INTERFACE_EXISTS (scaler, "wl_scaler"); #undef VERIFY_INTERFACE_EXISTS self->thread = g_thread_try_new ("GstWlDisplay", gst_wl_display_thread_run, self, &err); if (err) { g_propagate_prefixed_error (error, err, "Failed to start thread for the display's events"); g_object_unref (self); return NULL; } return self; }
GstWlDisplay * gst_wl_display_new_existing (struct wl_display * display, gboolean take_ownership, GError ** error) { GstWlDisplay *self; GError *err = NULL; gint i; g_return_val_if_fail (display != NULL, NULL); self = g_object_new (GST_TYPE_WL_DISPLAY, NULL); self->display = display; self->own_display = take_ownership; self->queue = wl_display_create_queue (self->display); self->registry = wl_display_get_registry (self->display); wl_proxy_set_queue ((struct wl_proxy *) self->registry, self->queue); wl_registry_add_listener (self->registry, ®istry_listener, self); /* we need exactly 2 roundtrips to discover global objects and their state */ for (i = 0; i < 2; i++) { if (gst_wl_display_roundtrip (self) < 0) { *error = g_error_new (g_quark_from_static_string ("GstWlDisplay"), 0, "Error communicating with the wayland display"); g_object_unref (self); return NULL; } } /* verify we got all the required interfaces */ #define VERIFY_INTERFACE_EXISTS(var, interface) \ if (!self->var) { \ g_set_error (error, g_quark_from_static_string ("GstWlDisplay"), 0, \ "Could not bind to " interface ". Either it is not implemented in " \ "the compositor, or the implemented version doesn't match"); \ g_object_unref (self); \ return NULL; \ } VERIFY_INTERFACE_EXISTS (compositor, "wl_compositor"); VERIFY_INTERFACE_EXISTS (subcompositor, "wl_subcompositor"); VERIFY_INTERFACE_EXISTS (shell, "wl_shell"); VERIFY_INTERFACE_EXISTS (shm, "wl_shm"); #undef VERIFY_INTERFACE_EXISTS /* We make the viewporter optional even though it may cause bad display. * This is so one can test wayland display on older compositor or on * compositor that don't implement this extension. */ if (!self->viewporter) { g_warning ("Wayland compositor is missing the ability to scale, video " "display may not work properly."); } if (!self->dmabuf) { g_warning ("Could not bind to zwp_linux_dmabuf_v1"); } self->thread = g_thread_try_new ("GstWlDisplay", gst_wl_display_thread_run, self, &err); if (err) { g_propagate_prefixed_error (error, err, "Failed to start thread for the display's events"); g_object_unref (self); return NULL; } return self; }