Compositor::Compositor() : m_display(wl_display_create()) , m_time(0) { wl_list_init(&m_outputResources); if (wl_display_add_socket(m_display, 0)) { fprintf(stderr, "Fatal: Failed to open server socket\n"); exit(EXIT_FAILURE); } wl_display_add_global(m_display, &wl_compositor_interface, this, bindCompositor); m_data_device_manager.reset(new DataDeviceManager(this, m_display)); wl_display_init_shm(m_display); m_seat.reset(new Seat(this, m_display)); m_pointer = m_seat->pointer(); m_keyboard = m_seat->keyboard(); wl_display_add_global(m_display, &wl_output_interface, this, bindOutput); wl_display_add_global(m_display, &wl_shell_interface, this, bindShell); m_loop = wl_display_get_event_loop(m_display); m_fd = wl_event_loop_get_fd(m_loop); }
int main(int argc, char *argv[]) { display = wl_display_create(); if (!display) return EXIT_FAILURE; if (wl_display_add_socket(display, NULL) != 0) return EXIT_FAILURE; if (!swc_initialize(display, NULL, &manager)) return EXIT_FAILURE; swc_add_binding(SWC_BINDING_KEY, SWC_MOD_LOGO, XKB_KEY_Return, &spawn, terminal_command); swc_add_binding(SWC_BINDING_KEY, SWC_MOD_LOGO, XKB_KEY_r, &spawn, dmenu_command); swc_add_binding(SWC_BINDING_KEY, SWC_MOD_LOGO, XKB_KEY_q, &quit, NULL); event_loop = wl_display_get_event_loop(display); wl_display_run(display); wl_display_destroy(display); return EXIT_SUCCESS; }
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; }
Compositor::Compositor(QWaylandCompositor *qt_compositor) : m_display(new Display) , m_default_input_device(0) , m_pageFlipper(0) , m_current_frame(0) , m_last_queued_buf(-1) , m_qt_compositor(qt_compositor) , m_orientation(Qt::PrimaryOrientation) , m_directRenderSurface(0) , m_directRenderContext(0) , m_directRenderActive(false) #if defined (QT_COMPOSITOR_WAYLAND_GL) , m_graphics_hw_integration(0) #endif , m_outputExtension(0) , m_surfaceExtension(0) , m_subSurfaceExtension(0) , m_touchExtension(0) , m_retainNotify(0) { compositor = this; #if defined (QT_COMPOSITOR_WAYLAND_GL) QWindow *window = qt_compositor->window(); if (window && window->surfaceType() != QWindow::RasterSurface) { QStringList keys = QWaylandGraphicsHardwareIntegrationFactory::keys(); QString targetKey; QByteArray hardwareIntegration = qgetenv("QT_WAYLAND_HARDWARE_INTEGRATION"); if (keys.contains(QString::fromLocal8Bit(hardwareIntegration.constData()))) { targetKey = QString::fromLocal8Bit(hardwareIntegration.constData()); } else if (keys.contains(QString::fromLatin1("wayland-egl"))) { targetKey = QString::fromLatin1("wayland-egl"); } else if (!keys.isEmpty()) { targetKey = keys.first(); } if (!targetKey.isEmpty()) { m_graphics_hw_integration = QWaylandGraphicsHardwareIntegrationFactory::create(targetKey, QStringList()); if (m_graphics_hw_integration) { m_graphics_hw_integration->setCompositor(qt_compositor); } } //BUG: if there is no hw_integration, bad things will probably happen } #endif m_windowManagerIntegration = new WindowManagerServerIntegration(qt_compositor, this); wl_display_add_global(m_display->handle(),&wl_compositor_interface,this,Compositor::bind_func); m_data_device_manager = new DataDeviceManager(this); wl_display_init_shm(m_display->handle()); m_output_global = new OutputGlobal(m_display->handle()); m_shell = new Shell(); wl_display_add_global(m_display->handle(), &wl_shell_interface, m_shell, Shell::bind_func); m_outputExtension = new OutputExtensionGlobal(this); m_surfaceExtension = new SurfaceExtensionGlobal(this); m_qtkeyExtension = new QtKeyExtensionGlobal(this); m_touchExtension = new TouchExtensionGlobal(this); if (wl_display_add_socket(m_display->handle(), qt_compositor->socketName())) { fprintf(stderr, "Fatal: Failed to open server socket\n"); exit(EXIT_FAILURE); } m_loop = wl_display_get_event_loop(m_display->handle()); int fd = wl_event_loop_get_fd(m_loop); QSocketNotifier *sockNot = new QSocketNotifier(fd, QSocketNotifier::Read, this); connect(sockNot, SIGNAL(activated(int)), this, SLOT(processWaylandEvents())); QAbstractEventDispatcher *dispatcher = QGuiApplicationPrivate::eventDispatcher; connect(dispatcher, SIGNAL(aboutToBlock()), this, SLOT(processWaylandEvents())); qRegisterMetaType<SurfaceBuffer*>("SurfaceBuffer*"); //initialize distancefieldglyphcache here }
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; }