diff --git a/libweston/compositor.c b/libweston/compositor.c index 27d46c02..610f46c1 100644 --- a/libweston/compositor.c +++ b/libweston/compositor.c @@ -2388,6 +2388,8 @@ WL_EXPORT struct weston_buffer * weston_buffer_from_resource(struct wl_resource *resource) { struct weston_buffer *buffer; + struct wl_shm_buffer *shm; + struct linux_dmabuf_buffer *dmabuf; struct wl_listener *listener; listener = wl_resource_get_destroy_listener(resource, @@ -2404,9 +2406,20 @@ weston_buffer_from_resource(struct wl_resource *resource) buffer->resource = resource; wl_signal_init(&buffer->destroy_signal); buffer->destroy_listener.notify = weston_buffer_destroy_handler; - buffer->y_inverted = 1; wl_resource_add_destroy_listener(resource, &buffer->destroy_listener); + if ((shm = wl_shm_buffer_get(buffer->resource))) { + buffer->shm_buffer = shm; + buffer->width = wl_shm_buffer_get_width(shm); + buffer->height = wl_shm_buffer_get_height(shm); + buffer->y_inverted = true; + } else if ((dmabuf = linux_dmabuf_buffer_get(buffer->resource))) { + buffer->width = dmabuf->attributes.width; + buffer->height = dmabuf->attributes.height; + buffer->y_inverted = + !(dmabuf->attributes.flags & ZWP_LINUX_BUFFER_PARAMS_V1_FLAGS_Y_INVERT); + } + return buffer; } diff --git a/libweston/pixman-renderer.c b/libweston/pixman-renderer.c index 271bc198..90a1248f 100644 --- a/libweston/pixman-renderer.c +++ b/libweston/pixman-renderer.c @@ -666,10 +666,6 @@ pixman_renderer_attach(struct weston_surface *es, struct weston_buffer *buffer) es->is_opaque = pixel_format_is_opaque(pixel_info); - buffer->shm_buffer = shm_buffer; - buffer->width = wl_shm_buffer_get_width(shm_buffer); - buffer->height = wl_shm_buffer_get_height(shm_buffer); - ps->image = pixman_image_create_bits(pixel_info->pixman_format, buffer->width, buffer->height, wl_shm_buffer_get_data(shm_buffer), diff --git a/libweston/renderer-gl/gl-renderer.c b/libweston/renderer-gl/gl-renderer.c index 4de92a37..d82df49d 100644 --- a/libweston/renderer-gl/gl-renderer.c +++ b/libweston/renderer-gl/gl-renderer.c @@ -1965,10 +1965,6 @@ gl_renderer_attach_shm(struct weston_surface *es, struct weston_buffer *buffer, int num_planes; bool using_glesv2 = gr->gl_version < gr_gl_version(3, 0); - buffer->shm_buffer = shm_buffer; - buffer->width = wl_shm_buffer_get_width(shm_buffer); - buffer->height = wl_shm_buffer_get_height(shm_buffer); - num_planes = 1; gs->offset[0] = 0; gs->hsub[0] = 1; @@ -2820,17 +2816,6 @@ gl_renderer_attach_dmabuf(struct weston_surface *surface, GLenum target; int i; - buffer->width = dmabuf->attributes.width; - buffer->height = dmabuf->attributes.height; - - /* - * GL-renderer uses the OpenGL convention of texture coordinates, where - * the origin is at bottom-left. Because dmabuf buffers have the origin - * at top-left, we must invert the Y_INVERT flag to get the image right. - */ - buffer->y_inverted = - !(dmabuf->attributes.flags & ZWP_LINUX_BUFFER_PARAMS_V1_FLAGS_Y_INVERT); - for (i = 0; i < gs->num_images; i++) egl_image_unref(gs->images[i]); gs->num_images = 0; diff --git a/libweston/screenshooter.c b/libweston/screenshooter.c index fedc4805..4205412f 100644 --- a/libweston/screenshooter.c +++ b/libweston/screenshooter.c @@ -186,10 +186,6 @@ weston_screenshooter_shoot(struct weston_output *output, return -1; } - buffer->shm_buffer = wl_shm_buffer_get(buffer->resource); - buffer->width = wl_shm_buffer_get_width(buffer->shm_buffer); - buffer->height = wl_shm_buffer_get_height(buffer->shm_buffer); - if (buffer->width < output->current_mode->width || buffer->height < output->current_mode->height) { done(data, WESTON_SCREENSHOOTER_BAD_BUFFER);