From patchwork Tue Jan 7 17:41:43 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Gaignard X-Patchwork-Id: 22919 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-yh0-f69.google.com (mail-yh0-f69.google.com [209.85.213.69]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 6C575216D9 for ; Tue, 7 Jan 2014 17:42:21 +0000 (UTC) Received: by mail-yh0-f69.google.com with SMTP id a41sf533130yho.8 for ; Tue, 07 Jan 2014 09:42:20 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:from:to:date:message-id:in-reply-to :references:subject:precedence:list-id:list-unsubscribe:list-archive :list-post:list-help:list-subscribe:mime-version:errors-to:sender :x-original-sender:x-original-authentication-results:mailing-list :content-type:content-transfer-encoding; bh=nrkpW9MYZoEMUsveqieAGaHYss3njiME70Rf6tnDQYk=; b=iDDNn9FvAl+eIhdNIl62c5mci8AbjqJJMsy7bWJpODrts/Y0ewcCcup3Kfel2+8gnc p91BIyEu+8Xag+wVSi0igZytyWxJlaG8gKnkB1abxmYpOJTOY0OYKdTqFYvSGdBAlckX WODvnKGd2UOi+rb8r9gDtsoxmTQe2bobqCY82AVcVV9W2PdEjtuWI7iDBXbZLAvpKjBb I9MVNmYOpD+ClsTSlR+xJAl4ppWsRL6SVToO23ltjLtX/jRITBNc/WqqqRfkkGygWXeJ 3/5QpS5763kx52xlDQ1JWAp8hGDO/tvTnYT7ImYmN+aI8mV4bhEKvLKSUf8twnQyItgz ac7g== X-Gm-Message-State: ALoCoQny5YfGv4Aw3S7Z2qZoYWZxN4K6OSxdZO5JD+3gyViFBDxRZzkKOK90Wy8E60gxtPP9YMTR X-Received: by 10.58.34.142 with SMTP id z14mr45652699vei.23.1389116540400; Tue, 07 Jan 2014 09:42:20 -0800 (PST) X-BeenThere: patchwork-forward@linaro.org Received: by 10.49.130.195 with SMTP id og3ls193486qeb.62.gmail; Tue, 07 Jan 2014 09:42:20 -0800 (PST) X-Received: by 10.52.24.20 with SMTP id q20mr3359147vdf.54.1389116540309; Tue, 07 Jan 2014 09:42:20 -0800 (PST) Received: from mail-ve0-f170.google.com (mail-ve0-f170.google.com [209.85.128.170]) by mx.google.com with ESMTPS id at4si34383312ved.113.2014.01.07.09.42.20 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 07 Jan 2014 09:42:20 -0800 (PST) Received-SPF: neutral (google.com: 209.85.128.170 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=209.85.128.170; Received: by mail-ve0-f170.google.com with SMTP id oy12so387923veb.15 for ; Tue, 07 Jan 2014 09:42:20 -0800 (PST) X-Received: by 10.58.243.37 with SMTP id wv5mr4108650vec.41.1389116540162; Tue, 07 Jan 2014 09:42:20 -0800 (PST) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patches@linaro.org Received: by 10.59.13.131 with SMTP id ey3csp174189ved; Tue, 7 Jan 2014 09:42:19 -0800 (PST) X-Received: by 10.15.67.142 with SMTP id u14mr41257836eex.59.1389116539002; Tue, 07 Jan 2014 09:42:19 -0800 (PST) Received: from ip-10-141-164-156.ec2.internal (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTPS id j47si89821353eeo.179.2014.01.07.09.42.17 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Tue, 07 Jan 2014 09:42:18 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linaro-mm-sig-bounces@lists.linaro.org designates 54.225.227.206 as permitted sender) client-ip=54.225.227.206; Received: from localhost ([127.0.0.1] helo=ip-10-141-164-156.ec2.internal) by ip-10-141-164-156.ec2.internal with esmtp (Exim 4.76) (envelope-from ) id 1W0afA-0006E0-0R; Tue, 07 Jan 2014 17:42:00 +0000 Received: from mail-wi0-f171.google.com ([209.85.212.171]) by ip-10-141-164-156.ec2.internal with esmtp (Exim 4.76) (envelope-from ) id 1W0aex-0006DA-Rs for linaro-mm-sig@lists.linaro.org; Tue, 07 Jan 2014 17:41:48 +0000 Received: by mail-wi0-f171.google.com with SMTP id bz8so4466554wib.4 for ; Tue, 07 Jan 2014 09:41:54 -0800 (PST) X-Received: by 10.194.142.174 with SMTP id rx14mr8906256wjb.45.1389116514911; Tue, 07 Jan 2014 09:41:54 -0800 (PST) Received: from lmenx321.lme.st.com (lya72-2-88-175-155-153.fbx.proxad.net. [88.175.155.153]) by mx.google.com with ESMTPSA id f7sm45992553wjb.7.2014.01.07.09.41.53 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 07 Jan 2014 09:41:54 -0800 (PST) From: benjamin.gaignard@linaro.org To: wayland-devel@lists.freedesktop.org, linaro-mm-sig@lists.linaro.org Date: Tue, 7 Jan 2014 18:41:43 +0100 Message-Id: <1389116504-3923-3-git-send-email-benjamin.gaignard@linaro.org> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1389116504-3923-1-git-send-email-benjamin.gaignard@linaro.org> References: <1389116504-3923-1-git-send-email-benjamin.gaignard@linaro.org> Subject: [Linaro-mm-sig] [PATCH v4 3/3] compositor-drm: allow to be a wl_dmabuf server X-BeenThere: linaro-mm-sig@lists.linaro.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: , List-Help: , List-Subscribe: , MIME-Version: 1.0 Errors-To: linaro-mm-sig-bounces@lists.linaro.org Sender: linaro-mm-sig-bounces@lists.linaro.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: benjamin.gaignard@linaro.org X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.128.170 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 From: Benjamin Gaignard Make drm compositor aware of the wl_dmabuf protocol if pixman is used. Add functions to have a wl_dmabuf server inside drm compositor. Change pixman to let it know how use a wl_dmabuf buffer. Signed-off-by: Benjamin Gaignard --- src/compositor-drm.c | 83 ++++++++++++++++++++++++++++++++++++++++--- src/compositor.c | 4 ++- src/compositor.h | 2 ++ src/pixman-renderer.c | 93 ++++++++++++++++++++++++++++++++++++------------- 4 files changed, 152 insertions(+), 30 deletions(-) diff --git a/src/compositor-drm.c b/src/compositor-drm.c index 4f015d1..669ee45 100644 --- a/src/compositor-drm.c +++ b/src/compositor-drm.c @@ -49,6 +49,8 @@ #include "udev-seat.h" #include "launcher-util.h" #include "vaapi-recorder.h" +#include "wayland-dmabuf.h" +#include "wayland-dmabuf-server-protocol.h" #ifndef DRM_CAP_TIMESTAMP_MONOTONIC #define DRM_CAP_TIMESTAMP_MONOTONIC 0x6 @@ -826,7 +828,8 @@ drm_output_prepare_overlay_surface(struct weston_output *output_base, if (es->alpha != 1.0f) return NULL; - if (wl_shm_buffer_get(es->buffer_ref.buffer->resource)) + if (wl_shm_buffer_get(es->buffer_ref.buffer->resource) + || wl_dmabuf_buffer_get(es->buffer_ref.buffer->resource)) return NULL; if (!drm_surface_transform_supported(es)) @@ -951,7 +954,8 @@ drm_output_prepare_cursor_surface(struct weston_output *output_base, if (c->cursors_are_broken) return NULL; if (es->buffer_ref.buffer == NULL || - !wl_shm_buffer_get(es->buffer_ref.buffer->resource) || + (!wl_shm_buffer_get(es->buffer_ref.buffer->resource) && + !wl_dmabuf_buffer_get(es->buffer_ref.buffer->resource))|| es->geometry.width > 64 || es->geometry.height > 64) return NULL; @@ -985,12 +989,25 @@ drm_output_set_cursor(struct drm_output *output) output->current_cursor ^= 1; bo = output->cursor_bo[output->current_cursor]; memset(buf, 0, sizeof buf); - stride = wl_shm_buffer_get_stride(es->buffer_ref.buffer->shm_buffer); - s = wl_shm_buffer_get_data(es->buffer_ref.buffer->shm_buffer); + if (wl_shm_buffer_get(es->buffer_ref.buffer->resource)) { + stride = wl_shm_buffer_get_stride(es->buffer_ref.buffer->shm_buffer); + s = wl_shm_buffer_get_data(es->buffer_ref.buffer->shm_buffer); + } + if (wl_dmabuf_buffer_get(es->buffer_ref.buffer->resource)) { + stride = wl_dmabuf_buffer_get_stride(es->buffer_ref.buffer->dmabuf_buffer); + s = wl_dmabuf_buffer_get_data(es->buffer_ref.buffer->dmabuf_buffer); + if (!s) { + weston_log("failed to get data from dmabuf buffer"); + return; + } + } for (i = 0; i < es->geometry.height; i++) memcpy(buf + i * 64, s + i * stride, es->geometry.width * 4); + if (wl_dmabuf_buffer_get(es->buffer_ref.buffer->resource)) + wl_dmabuf_buffer_put_data(es->buffer_ref.buffer->dmabuf_buffer); + if (gbm_bo_write(bo, buf, sizeof buf) < 0) weston_log("failed update cursor: %m\n"); @@ -1044,7 +1061,8 @@ drm_assign_planes(struct weston_output *output) * non-shm, or small enough to be a cursor */ if ((es->buffer_ref.buffer && - !wl_shm_buffer_get(es->buffer_ref.buffer->resource)) || + (!wl_shm_buffer_get(es->buffer_ref.buffer->resource)) + && !wl_dmabuf_buffer_get(es->buffer_ref.buffer->resource)) || (es->geometry.width <= 64 && es->geometry.height <= 64)) es->keep_buffer = 1; else @@ -1268,6 +1286,57 @@ init_drm(struct drm_compositor *ec, struct udev_device *device) return 0; } +static void dmabuf_send_supported_formats(void *user_data, struct wl_resource *resource) +{ + struct drm_compositor *ec = user_data; + drmModePlaneRes *plane_resources; + unsigned int i, j; + + weston_log("send supported formats\n"); + + plane_resources = drmModeGetPlaneResources(ec->drm.fd); + if (!plane_resources) + return; + + for (i = 0; i < plane_resources->count_planes; i++) { + drmModePlane *ovr = drmModeGetPlane(ec->drm.fd, plane_resources->planes[i]); + + for (j = 0 ; j < ovr->count_formats; j++) { + weston_log("server support format %4.4s\n", (char *)&ovr->formats[j]); + wl_dmabuf_send_format(resource, ovr->formats[j]); + } + drmModeFreePlane(ovr); + } + + drmModeFreePlaneResources(plane_resources); +} + +static void dmabuf_send_device_name(void *user_data, struct wl_resource *resource) +{ + struct drm_compositor *ec = user_data; + weston_log("send device name %s\n", ec->drm.filename); + + wl_dmabuf_send_device(resource, ec->drm.filename); +} + +static void dmabuf_send_server_info(void *user_data, struct wl_resource *resource) +{ + dmabuf_send_supported_formats(user_data, resource); + dmabuf_send_device_name(user_data, resource); +} + +static struct wl_dmabuf_callbacks wl_dmabuf_callbacks = { + dmabuf_send_server_info +}; + +static int +init_dmabuf_protocol(struct drm_compositor *ec) +{ + wl_dmabuf_init(ec->base.wl_display, + &wl_dmabuf_callbacks, ec, 0); + return 0; +} + static int init_egl(struct drm_compositor *ec) { @@ -1955,6 +2024,10 @@ create_output_for_connector(struct drm_compositor *ec, weston_log("Failed to init output pixman state\n"); goto err_output; } + if (init_dmabuf_protocol(ec) < 0) { + weston_log("Failed to init wl_dmabuf server\n"); + goto err_output; + } } else if (drm_output_init_egl(output, ec) < 0) { weston_log("Failed to init output gl state\n"); goto err_output; diff --git a/src/compositor.c b/src/compositor.c index 4cb44e5..037b695 100644 --- a/src/compositor.c +++ b/src/compositor.c @@ -1257,7 +1257,9 @@ surface_accumulate_damage(struct weston_surface *surface, pixman_region32_t *opaque) { if (surface->buffer_ref.buffer && - wl_shm_buffer_get(surface->buffer_ref.buffer->resource)) + (wl_shm_buffer_get(surface->buffer_ref.buffer->resource) + || wl_dmabuf_buffer_get(surface->buffer_ref.buffer->resource)) + ) surface->compositor->renderer->flush_damage(surface); if (surface->transform.enabled) { diff --git a/src/compositor.h b/src/compositor.h index 0dcb604..537a9b7 100644 --- a/src/compositor.h +++ b/src/compositor.h @@ -33,6 +33,7 @@ extern "C" { #define WL_HIDE_DEPRECATED #include +#include #include "version.h" #include "matrix.h" @@ -626,6 +627,7 @@ struct weston_buffer { union { struct wl_shm_buffer *shm_buffer; + struct wl_dmabuf_buffer *dmabuf_buffer; void *legacy_buffer; }; int32_t width, height; diff --git a/src/pixman-renderer.c b/src/pixman-renderer.c index 987c539..0a88c58 100644 --- a/src/pixman-renderer.c +++ b/src/pixman-renderer.c @@ -528,11 +528,19 @@ pixman_renderer_flush_damage(struct weston_surface *surface) /* No-op for pixman renderer */ } +static void wl_dmabuf_pixman_destroy (pixman_image_t *image, void *data) +{ + struct wl_dmabuf_buffer *dmabuf_buffer = data; + wl_dmabuf_buffer_put_data(dmabuf_buffer); +} + static void pixman_renderer_attach(struct weston_surface *es, struct weston_buffer *buffer) { struct pixman_surface_state *ps = get_surface_state(es); struct wl_shm_buffer *shm_buffer; + struct wl_dmabuf_buffer *dmabuf_buffer; + pixman_format_code_t pixman_format; weston_buffer_reference(&ps->buffer_ref, buffer); @@ -544,40 +552,77 @@ pixman_renderer_attach(struct weston_surface *es, struct weston_buffer *buffer) if (!buffer) return; - + shm_buffer = wl_shm_buffer_get(buffer->resource); + dmabuf_buffer = wl_dmabuf_buffer_get(buffer->resource); - if (! shm_buffer) { - weston_log("Pixman renderer supports only SHM buffers\n"); + if (!shm_buffer && !dmabuf_buffer) { + weston_log("Pixman renderer supports only SHM and DMABUF buffers\n"); weston_buffer_reference(&ps->buffer_ref, NULL); return; } - switch (wl_shm_buffer_get_format(shm_buffer)) { - case WL_SHM_FORMAT_XRGB8888: - pixman_format = PIXMAN_x8r8g8b8; - break; - case WL_SHM_FORMAT_ARGB8888: - pixman_format = PIXMAN_a8r8g8b8; - break; - case WL_SHM_FORMAT_RGB565: - pixman_format = PIXMAN_r5g6b5; + if (shm_buffer) { + switch (wl_shm_buffer_get_format(shm_buffer)) { + case WL_SHM_FORMAT_XRGB8888: + pixman_format = PIXMAN_x8r8g8b8; + break; + case WL_SHM_FORMAT_ARGB8888: + pixman_format = PIXMAN_a8r8g8b8; + break; + case WL_SHM_FORMAT_RGB565: + pixman_format = PIXMAN_r5g6b5; + break; + default: + weston_log("Unsupported SHM buffer format\n"); + weston_buffer_reference(&ps->buffer_ref, NULL); + return; break; - default: - weston_log("Unsupported SHM buffer format\n"); - weston_buffer_reference(&ps->buffer_ref, NULL); - return; - break; + } + + 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(pixman_format, + buffer->width, buffer->height, + wl_shm_buffer_get_data(shm_buffer), + wl_shm_buffer_get_stride(shm_buffer)); } - buffer->shm_buffer = shm_buffer; - buffer->width = wl_shm_buffer_get_width(shm_buffer); - buffer->height = wl_shm_buffer_get_height(shm_buffer); + if (dmabuf_buffer) { + void *data; + switch (wl_dmabuf_buffer_get_format(dmabuf_buffer)) { + case WL_DMABUF_FORMAT_XRGB8888: + pixman_format = PIXMAN_x8r8g8b8; + break; + case WL_DMABUF_FORMAT_ARGB8888: + pixman_format = PIXMAN_a8r8g8b8; + break; + case WL_DMABUF_FORMAT_RGB565: + pixman_format = PIXMAN_r5g6b5; + break; + default: + weston_log("Unsupported DMABUF buffer format\n"); + weston_buffer_reference(&ps->buffer_ref, NULL); + return; + break; + } - ps->image = pixman_image_create_bits(pixman_format, - buffer->width, buffer->height, - wl_shm_buffer_get_data(shm_buffer), - wl_shm_buffer_get_stride(shm_buffer)); + buffer->dmabuf_buffer = dmabuf_buffer; + buffer->width = wl_dmabuf_buffer_get_width(dmabuf_buffer); + buffer->height = wl_dmabuf_buffer_get_height(dmabuf_buffer); + + data = wl_dmabuf_buffer_get_data(dmabuf_buffer); + if (data) { + ps->image = pixman_image_create_bits(pixman_format, + buffer->width, buffer->height, data, + wl_dmabuf_buffer_get_stride(dmabuf_buffer)); + + pixman_image_set_destroy_function(ps->image, wl_dmabuf_pixman_destroy, dmabuf_buffer); + } else + weston_log("failed to get data from dmabuf buffer"); + } } static int