static void cogland_surface_attach_buffer (struct wl_client *wayland_client, struct wl_resource *wayland_surface_resource, struct wl_resource *wayland_buffer_resource, int32_t dx, int32_t dy) { struct wl_buffer *wayland_buffer = wayland_buffer_resource->data; CoglandBuffer *buffer = wayland_buffer->user_data; CoglandSurface *surface = wayland_surface_resource->data; CoglandCompositor *compositor = surface->compositor; /* XXX: in the case where we are reattaching the same buffer we can * simply bail out. Note this is important because if we don't bail * out then the _detach_buffer will actually end up destroying the * buffer we're trying to attach. */ if (buffer && surface->buffer == buffer) return; cogland_surface_detach_buffer (surface); /* XXX: it seems like for shm buffers we will have been notified of * the buffer already via the callbacks, but for drm buffers I guess * this will be the first we know of them? */ if (!buffer) { buffer = cogland_buffer_new (wayland_buffer); wayland_buffer->user_data = buffer; } g_return_if_fail (g_list_find (buffer->surfaces_attached_to, surface) == NULL); buffer->surfaces_attached_to = g_list_prepend (buffer->surfaces_attached_to, surface); if (!buffer->texture) { CoglError *error = NULL; buffer->texture = cogl_wayland_texture_2d_new_from_buffer (compositor->cogl_context, wayland_buffer, &error); if (!buffer->texture) g_error ("Failed to create texture_2d from wayland buffer: %s", error->message); } surface->buffer = buffer; }
static void cogland_surface_attach_buffer (struct wl_client *wayland_client, struct wl_surface *wayland_surface, struct wl_buffer *wayland_buffer, gint32 dx, gint32 dy) { CoglandBuffer *buffer = wayland_buffer->user_data; CoglandSurface *surface = container_of (wayland_surface, CoglandSurface, wayland_surface); CoglandCompositor *compositor = surface->compositor; cogland_surface_detach_buffer (surface); /* XXX: it seems like for shm buffers we will have been notified of * the buffer already via the callbacks, but for drm buffers I guess * this will be the first we know of them? */ if (!buffer) { buffer = cogland_buffer_new (wayland_buffer); wayland_buffer->user_data = buffer; } /* wayland-drm.c: drm_create_buffer doesn't fill this in for us...*/ if (!wayland_buffer->compositor) wayland_buffer->compositor = &compositor->wayland_compositor; g_return_if_fail (g_list_find (buffer->surfaces_attached_to, surface) == NULL); buffer->surfaces_attached_to = g_list_prepend (buffer->surfaces_attached_to, surface); if (!buffer->texture) { GError *error = NULL; buffer->texture = cogl_wayland_texture_2d_new_from_buffer (compositor->cogl_context, wayland_buffer, &error); if (!buffer->texture) g_error ("Failed to create texture_2d from wayland buffer: %s", error->message); } surface->buffer = buffer; }
static void cogland_surface_commit (struct wl_client *client, struct wl_resource *resource) { CoglandSurface *surface = wl_resource_get_user_data (resource); CoglandCompositor *compositor = surface->compositor; /* wl_surface.attach */ if (surface->pending.newly_attached && surface->buffer_ref.buffer != surface->pending.buffer) { CoglError *error = NULL; if (surface->texture) { cogl_object_unref (surface->texture); surface->texture = NULL; } cogland_buffer_reference (&surface->buffer_ref, surface->pending.buffer); if (surface->pending.buffer) { struct wl_resource *buffer_resource = surface->pending.buffer->resource; surface->texture = cogl_wayland_texture_2d_new_from_buffer (compositor->cogl_context, buffer_resource, &error); if (!surface->texture) { g_error ("Failed to create texture_2d from wayland buffer: %s", error->message); cogl_error_free (error); } } } if (surface->pending.buffer) { wl_list_remove (&surface->pending.buffer_destroy_listener.link); surface->pending.buffer = NULL; } surface->pending.sx = 0; surface->pending.sy = 0; surface->pending.newly_attached = FALSE; /* wl_surface.damage */ if (surface->buffer_ref.buffer && surface->texture && !region_is_empty (&surface->pending.damage)) { CoglandRegion *region = &surface->pending.damage; CoglTexture *texture = surface->texture; if (region->x2 > cogl_texture_get_width (texture)) region->x2 = cogl_texture_get_width (texture); if (region->y2 > cogl_texture_get_height (texture)) region->y2 = cogl_texture_get_height (texture); if (region->x1 < 0) region->x1 = 0; if (region->y1 < 0) region->y1 = 0; surface_damaged (surface, region->x1, region->y1, region->x2 - region->x1, region->y2 - region->y1); } region_init (&surface->pending.damage); /* wl_surface.frame */ wl_list_insert_list (&compositor->frame_callbacks, &surface->pending.frame_callback_list); wl_list_init (&surface->pending.frame_callback_list); }