static gboolean gst_gl_window_wayland_egl_open (GstGLWindow * window, GError ** error) { GstGLDisplayWayland *display; GstGLWindowWaylandEGL *window_egl = GST_GL_WINDOW_WAYLAND_EGL (window); if (!GST_IS_GL_DISPLAY_WAYLAND (window->display)) { g_set_error (error, GST_GL_WINDOW_ERROR, GST_GL_WINDOW_ERROR_RESOURCE_UNAVAILABLE, "Failed to retrieve Wayland display (wrong type?)"); return FALSE; } display = GST_GL_DISPLAY_WAYLAND (window->display); if (!display->display) { g_set_error (error, GST_GL_WINDOW_ERROR, GST_GL_WINDOW_ERROR_RESOURCE_UNAVAILABLE, "Failed to retrieve Wayland display"); return FALSE; } window_egl->window.queue = wl_display_create_queue (display->display); window_egl->wl_source = wayland_event_source_new (display->display, window_egl->window.queue); if (!GST_GL_WINDOW_CLASS (parent_class)->open (window, error)) return FALSE; g_source_attach (window_egl->wl_source, g_main_context_get_thread_default ()); return TRUE; }
void meta_wayland_init (void) { MetaWaylandCompositor *compositor = meta_wayland_compositor_get_default (); GSource *wayland_event_source; if (!wl_global_create (compositor->wayland_display, &wl_compositor_interface, META_WL_COMPOSITOR_VERSION, compositor, compositor_bind)) g_error ("Failed to register the global wl_compositor"); wayland_event_source = wayland_event_source_new (compositor->wayland_display); /* XXX: Here we are setting the wayland event source to have a * slightly lower priority than the X event source, because we are * much more likely to get confused being told about surface changes * relating to X clients when we don't know what's happened to them * according to the X protocol. * * At some point we could perhaps try and get the X protocol proxied * over the wayland protocol so that we don't have to worry about * synchronizing the two command streams. */ g_source_set_priority (wayland_event_source, GDK_PRIORITY_EVENTS + 1); g_source_attach (wayland_event_source, NULL); wl_display_init_shm (compositor->wayland_display); meta_wayland_outputs_init (compositor); meta_wayland_data_device_manager_init (compositor); meta_wayland_shell_init (compositor); meta_wayland_seat_init (compositor); /* FIXME: find the first free name instead */ compositor->display_name = wl_display_add_socket_auto (compositor->wayland_display); if (compositor->display_name == NULL) g_error ("Failed to create socket"); /* XXX: It's important that we only try and start xwayland after we * have initialized EGL because EGL implements the "wl_drm" * interface which xwayland requires to determine what drm device * name it should use. * * By waiting until we've shown the stage above we ensure that the * underlying GL resources for the surface have also been allocated * and so EGL must be initialized by this point. */ if (!meta_xwayland_start (&compositor->xwayland_manager, compositor->wayland_display)) g_error ("Failed to start X Wayland"); set_gnome_env ("DISPLAY", meta_wayland_get_xwayland_display_name (compositor)); set_gnome_env ("WAYLAND_DISPLAY", meta_wayland_get_wayland_display_name (compositor)); }
static gboolean gst_gl_window_wayland_egl_open (GstGLWindow * window, GError ** error) { GstGLWindowWaylandEGL *window_egl = GST_GL_WINDOW_WAYLAND_EGL (window); window_egl->display.display = wl_display_connect (NULL); if (!window_egl->display.display) { g_set_error (error, GST_GL_WINDOW_ERROR, GST_GL_WINDOW_ERROR_RESOURCE_UNAVAILABLE, "Failed to connect to Wayland display server"); goto error; } window_egl->display.registry = wl_display_get_registry (window_egl->display.display); wl_registry_add_listener (window_egl->display.registry, ®istry_listener, window_egl); wl_display_dispatch (window_egl->display.display); create_surface (window_egl); window_egl->display.cursor_surface = wl_compositor_create_surface (window_egl->display.compositor); window_egl->wl_source = wayland_event_source_new (window_egl->display.display); window_egl->main_context = g_main_context_new (); window_egl->loop = g_main_loop_new (window_egl->main_context, FALSE); g_source_attach (window_egl->wl_source, window_egl->main_context); return TRUE; error: return FALSE; }
int main (int argc, char **argv) { CoglandCompositor compositor; GMainLoop *loop; CoglError *error = NULL; GError *gerror = NULL; CoglVertexP2C4 triangle_vertices[] = { {0, 0.7, 0xff, 0x00, 0x00, 0xff}, {-0.7, -0.7, 0x00, 0xff, 0x00, 0xff}, {0.7, -0.7, 0x00, 0x00, 0xff, 0xff} }; GSource *cogl_source; if (!process_arguments (&argc, &argv, &gerror)) { fprintf (stderr, "%s\n", gerror->message); return EXIT_FAILURE; } memset (&compositor, 0, sizeof (compositor)); compositor.wayland_display = wl_display_create (); if (compositor.wayland_display == NULL) g_error ("failed to create wayland display"); wl_list_init (&compositor.frame_callbacks); if (!wl_display_add_global (compositor.wayland_display, &wl_compositor_interface, &compositor, compositor_bind)) g_error ("Failed to register wayland compositor object"); wl_display_init_shm (compositor.wayland_display); loop = g_main_loop_new (NULL, FALSE); compositor.wayland_loop = wl_display_get_event_loop (compositor.wayland_display); compositor.wayland_event_source = wayland_event_source_new (compositor.wayland_display); g_source_attach (compositor.wayland_event_source, NULL); /* We want Cogl to use an EGL renderer because otherwise it won't * set up the wl_drm object and only SHM buffers will work. */ compositor.cogl_context = create_cogl_context (&compositor, TRUE /* use EGL constraint */, &error); if (compositor.cogl_context == NULL) { /* If we couldn't get an EGL context then try any type of * context */ cogl_error_free (error); error = NULL; compositor.cogl_context = create_cogl_context (&compositor, FALSE, /* don't set EGL constraint */ &error); if (compositor.cogl_context) g_warning ("Failed to create context with EGL constraint, " "falling back"); else g_error ("Failed to create a Cogl context: %s\n", error->message); } compositor.virtual_width = 800; compositor.virtual_height = 600; if (option_multiple_outputs) { int hw = compositor.virtual_width / 2; int hh = compositor.virtual_height / 2; /* Emulate compositing with multiple monitors... */ cogland_compositor_create_output (&compositor, 0, 0, hw, hh); cogland_compositor_create_output (&compositor, hw, 0, hw, hh); cogland_compositor_create_output (&compositor, 0, hh, hw, hh); cogland_compositor_create_output (&compositor, hw, hh, hw, hh); } else { cogland_compositor_create_output (&compositor, 0, 0, compositor.virtual_width, compositor.virtual_height); } if (wl_display_add_global (compositor.wayland_display, &wl_shell_interface, &compositor, bind_shell) == NULL) g_error ("Failed to register a global shell object"); if (wl_display_add_socket (compositor.wayland_display, "wayland-0")) g_error ("Failed to create socket"); compositor.triangle = cogl_primitive_new_p2c4 (compositor.cogl_context, COGL_VERTICES_MODE_TRIANGLES, 3, triangle_vertices); compositor.triangle_pipeline = cogl_pipeline_new (compositor.cogl_context); cogl_source = cogl_glib_source_new (compositor.cogl_context, G_PRIORITY_DEFAULT); g_source_attach (cogl_source, NULL); g_main_loop_run (loop); return 0; }
int main (int argc, char **argv) { CoglandCompositor compositor; GMainLoop *loop; CoglError *error = NULL; CoglVertexP2C4 triangle_vertices[] = { {0, 0.7, 0xff, 0x00, 0x00, 0x80}, {-0.7, -0.7, 0x00, 0xff, 0x00, 0xff}, {0.7, -0.7, 0x00, 0x00, 0xff, 0xff} }; GSource *cogl_source; memset (&compositor, 0, sizeof (compositor)); compositor.wayland_display = wl_display_create (); if (compositor.wayland_display == NULL) g_error ("failed to create wayland display"); g_queue_init (&compositor.frame_callbacks); if (!wl_display_add_global (compositor.wayland_display, &wl_compositor_interface, &compositor, compositor_bind)) g_error ("Failed to register wayland compositor object"); compositor.wayland_shm = wl_shm_init (compositor.wayland_display, &shm_callbacks); if (!compositor.wayland_shm) g_error ("Failed to allocate setup wayland shm callbacks"); loop = g_main_loop_new (NULL, FALSE); compositor.wayland_loop = wl_display_get_event_loop (compositor.wayland_display); compositor.wayland_event_source = wayland_event_source_new (compositor.wayland_loop); g_source_attach (compositor.wayland_event_source, NULL); compositor.cogl_display = cogl_display_new (NULL, NULL); cogl_wayland_display_set_compositor_display (compositor.cogl_display, compositor.wayland_display); compositor.cogl_context = cogl_context_new (compositor.cogl_display, &error); if (!compositor.cogl_context) g_error ("Failed to create a Cogl context: %s\n", error->message); compositor.virtual_width = 640; compositor.virtual_height = 480; /* Emulate compositing with multiple monitors... */ cogland_compositor_create_output (&compositor, 0, 0, 320, 240); cogland_compositor_create_output (&compositor, 320, 0, 320, 240); cogland_compositor_create_output (&compositor, 0, 240, 320, 240); cogland_compositor_create_output (&compositor, 320, 240, 320, 240); if (wl_display_add_global (compositor.wayland_display, &wl_shell_interface, &compositor, bind_shell) == NULL) g_error ("Failed to register a global shell object"); if (wl_display_add_socket (compositor.wayland_display, "wayland-0")) g_error ("Failed to create socket"); compositor.triangle = cogl_primitive_new_p2c4 (compositor.cogl_context, COGL_VERTICES_MODE_TRIANGLES, 3, triangle_vertices); compositor.triangle_pipeline = cogl_pipeline_new (compositor.cogl_context); g_timeout_add (16, paint_cb, &compositor); cogl_source = cogl_glib_source_new (compositor.cogl_context, G_PRIORITY_DEFAULT); g_source_attach (cogl_source, NULL); g_main_loop_run (loop); return 0; }