static void global_handler(struct display *display, uint32_t name, const char *interface, uint32_t version, void *data) { struct box *box = data; if (strcmp(interface, "wl_scaler") == 0) { box->scaler_version = version < 2 ? version : 2; box->scaler = display_bind(display, name, &wl_scaler_interface, box->scaler_version); box->viewport = wl_scaler_get_viewport(box->scaler, widget_get_wl_surface(box->widget)); set_my_viewport(box); } }
static GstWlWindow * gst_wl_window_new_internal (GstWlDisplay * display, struct wl_surface *surface) { GstWlWindow *window; struct wl_region *region; g_return_val_if_fail (surface != NULL, NULL); window = g_object_new (GST_TYPE_WL_WINDOW, NULL); window->display = g_object_ref (display); window->surface = surface; /* make sure the surface runs on our local queue */ wl_proxy_set_queue ((struct wl_proxy *) surface, display->queue); window->viewport = wl_scaler_get_viewport (display->scaler, window->surface); /* do not accept input */ region = wl_compositor_create_region (display->compositor); wl_surface_set_input_region (surface, region); wl_region_destroy (region); return window; }
static gboolean gst_mfx_window_wayland_create (GstMfxWindow * window, guint * width, guint * height) { GstMfxWindowWaylandPrivate *const priv = GST_MFX_WINDOW_WAYLAND_GET_PRIVATE (window); GstMfxDisplayWaylandPrivate *const priv_display = GST_MFX_DISPLAY_WAYLAND_GET_PRIVATE (GST_MFX_WINDOW_DISPLAY (window)); struct wl_display *const wl_display = GST_MFX_DISPLAY_HANDLE (GST_MFX_WINDOW_DISPLAY (window)); GError *err = NULL; GST_DEBUG ("create window, size %ux%u", *width, *height); g_return_val_if_fail (priv_display->compositor != NULL, FALSE); g_return_val_if_fail (priv_display->shell != NULL, FALSE); GST_MFX_DISPLAY_LOCK (GST_MFX_WINDOW_DISPLAY (window)); priv->event_queue = wl_display_create_queue (wl_display); GST_MFX_DISPLAY_UNLOCK (GST_MFX_WINDOW_DISPLAY (window)); if (!priv->event_queue) return FALSE; GST_MFX_DISPLAY_LOCK (GST_MFX_WINDOW_DISPLAY (window)); priv->surface = wl_compositor_create_surface (priv_display->compositor); GST_MFX_DISPLAY_UNLOCK (GST_MFX_WINDOW_DISPLAY (window)); if (!priv->surface) return FALSE; wl_proxy_set_queue ((struct wl_proxy *) priv->surface, priv->event_queue); GST_MFX_DISPLAY_LOCK (GST_MFX_WINDOW_DISPLAY (window)); priv->shell_surface = wl_shell_get_shell_surface (priv_display->shell, priv->surface); GST_MFX_DISPLAY_UNLOCK (GST_MFX_WINDOW_DISPLAY (window)); if (!priv->shell_surface) return FALSE; wl_proxy_set_queue ((struct wl_proxy *) priv->shell_surface, priv->event_queue); wl_shell_surface_add_listener (priv->shell_surface, &shell_surface_listener, window); wl_shell_surface_set_toplevel (priv->shell_surface); #ifdef USE_WESTON_4_0 if (priv_display->viewporter) { GST_MFX_DISPLAY_LOCK (GST_MFX_WINDOW_DISPLAY (window)); priv->wp_viewport = wp_viewporter_get_viewport (priv_display->viewporter, priv->surface); GST_MFX_DISPLAY_UNLOCK (GST_MFX_WINDOW_DISPLAY (window)); } #else if (priv_display->scaler) { GST_MFX_DISPLAY_LOCK (GST_MFX_WINDOW_DISPLAY (window)); priv->viewport = wl_scaler_get_viewport (priv_display->scaler, priv->surface); GST_MFX_DISPLAY_UNLOCK (GST_MFX_WINDOW_DISPLAY (window)); } #endif priv->poll = gst_poll_new (TRUE); gst_poll_fd_init (&priv->pollfd); if (priv->fullscreen_on_show) gst_mfx_window_wayland_set_fullscreen (window, TRUE); #ifdef USE_EGL if (gst_mfx_display_has_opengl (GST_MFX_WINDOW_DISPLAY (window))) { priv->egl_window = wl_egl_window_create (priv->surface, *width, *height); if (!priv->egl_window) return FALSE; GST_MFX_WINDOW_ID (window) = GPOINTER_TO_INT(priv->egl_window); } #endif priv->thread = g_thread_try_new ("wayland-thread", gst_mfx_window_wayland_thread_run, window, &err); if (err) return FALSE; priv->is_shown = TRUE; return TRUE; }
static struct window * create_window(struct display *display, int width, int height, enum wl_output_transform transform, int scale, enum window_flags flags) { struct window *window; if (display->compositor_version < 2 && (transform != WL_OUTPUT_TRANSFORM_NORMAL || flags & WINDOW_FLAG_ROTATING_TRANSFORM)) { fprintf(stderr, "wl_surface.buffer_transform unsupported in " "wl_surface version %d\n", display->compositor_version); exit(1); } if (display->compositor_version < 3 && (! (flags & WINDOW_FLAG_USE_VIEWPORT)) && scale != 1) { fprintf(stderr, "wl_surface.buffer_scale unsupported in " "wl_surface version %d\n", display->compositor_version); exit(1); } if (display->scaler == NULL && (flags & WINDOW_FLAG_USE_VIEWPORT)) { fprintf(stderr, "Compositor does not support wl_viewport"); exit(1); } window = calloc(1, sizeof *window); if (!window) return NULL; window->callback = NULL; window->display = display; window->width = width; window->height = height; window->border = 10; window->flags = flags; window->transform = transform; window->scale = scale; window_init_game(window); window->surface = wl_compositor_create_surface(display->compositor); if (window->flags & WINDOW_FLAG_USE_VIEWPORT) window->viewport = wl_scaler_get_viewport(display->scaler, window->surface); if (display->shell) { window->xdg_surface = xdg_shell_get_xdg_surface(display->shell, window->surface); assert(window->xdg_surface); xdg_surface_add_listener(window->xdg_surface, &xdg_surface_listener, window); xdg_surface_set_title(window->xdg_surface, "simple-damage"); } else if (display->fshell) { _wl_fullscreen_shell_present_surface(display->fshell, window->surface, _WL_FULLSCREEN_SHELL_PRESENT_METHOD_DEFAULT, NULL); } else { assert(0); } /* Initialise damage to full surface, so the padding gets painted */ wl_surface_damage(window->surface, 0, 0, INT32_MAX, INT32_MAX); return window; }
static GstWlWindow * gst_wl_window_new_internal (GstWlDisplay * display) { GstWlWindow *window; GstVideoInfo info; GstBuffer *buf; GstMapInfo mapinfo; struct wl_buffer *wlbuf; GstWlBuffer *gwlbuf; struct wl_region *region; window = g_object_new (GST_TYPE_WL_WINDOW, NULL); window->display = g_object_ref (display); window->area_surface = wl_compositor_create_surface (display->compositor); window->video_surface = wl_compositor_create_surface (display->compositor); wl_proxy_set_queue ((struct wl_proxy *) window->area_surface, display->queue); wl_proxy_set_queue ((struct wl_proxy *) window->video_surface, display->queue); /* embed video_surface in area_surface */ window->video_subsurface = wl_subcompositor_get_subsurface (display->subcompositor, window->video_surface, window->area_surface); wl_subsurface_set_desync (window->video_subsurface); window->area_viewport = wl_scaler_get_viewport (display->scaler, window->area_surface); window->video_viewport = wl_scaler_get_viewport (display->scaler, window->video_surface); /* draw the area_subsurface */ gst_video_info_set_format (&info, /* we want WL_SHM_FORMAT_XRGB8888 */ #if G_BYTE_ORDER == G_BIG_ENDIAN GST_VIDEO_FORMAT_xRGB, #else GST_VIDEO_FORMAT_BGRx, #endif 1, 1); buf = gst_buffer_new_allocate (gst_wl_shm_allocator_get (), info.size, NULL); gst_buffer_map (buf, &mapinfo, GST_MAP_WRITE); *((guint32 *) mapinfo.data) = 0; /* paint it black */ gst_buffer_unmap (buf, &mapinfo); wlbuf = gst_wl_shm_memory_construct_wl_buffer (gst_buffer_peek_memory (buf, 0), display, &info); gwlbuf = gst_buffer_add_wl_buffer (buf, wlbuf, display); gst_wl_buffer_attach (gwlbuf, window->area_surface); /* at this point, the GstWlBuffer keeps the buffer * alive and will free it on wl_buffer::release */ gst_buffer_unref (buf); /* do not accept input */ region = wl_compositor_create_region (display->compositor); wl_surface_set_input_region (window->area_surface, region); wl_region_destroy (region); region = wl_compositor_create_region (display->compositor); wl_surface_set_input_region (window->video_surface, region); wl_region_destroy (region); return window; }