<div dir="ltr"><pre class="gmail-content"><span class="gmail-quote">Any plan to support for drmModeAddFB2WithModifiers and query preferred FB modifier?</span></pre></div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Sep 26, 2017 at 12:15 PM, Daniel Stone <span dir="ltr"><<a href="mailto:daniels@collabora.com" target="_blank">daniels@collabora.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">We currently do the same thing in two places, and will soon have a<br>
third.<br>
<br>
Signed-off-by: Daniel Stone <<a href="mailto:daniels@collabora.com">daniels@collabora.com</a>><br>
---<br>
 libweston/compositor-drm.c | 93 ++++++++++++++++++++++++------<wbr>----------------<br>
 1 file changed, 48 insertions(+), 45 deletions(-)<br>
<br>
diff --git a/libweston/compositor-drm.c b/libweston/compositor-drm.c<br>
index e03f8f7e..7557ef55 100644<br>
--- a/libweston/compositor-drm.c<br>
+++ b/libweston/compositor-drm.c<br>
@@ -283,7 +283,10 @@ struct drm_fb {<br>
<br>
        int refcnt;<br>
<br>
-       uint32_t fb_id, stride, handle, size;<br>
+       uint32_t fb_id, size;<br>
+       uint32_t handles[4];<br>
+       uint32_t strides[4];<br>
+       uint32_t offsets[4];<br>
        const struct pixel_format_info *format;<br>
        int width, height;<br>
        int fd;<br>
@@ -801,7 +804,7 @@ drm_fb_destroy_dumb(struct drm_fb *fb)<br>
                munmap(fb->map, fb->size);<br>
<br>
        memset(&destroy_arg, 0, sizeof(destroy_arg));<br>
-       destroy_arg.handle = fb->handle;<br>
+       destroy_arg.handle = fb->handles[0];<br>
        drmIoctl(fb->fd, DRM_IOCTL_MODE_DESTROY_DUMB, &destroy_arg);<br>
<br>
        drm_fb_destroy(fb);<br>
@@ -817,6 +820,32 @@ drm_fb_destroy_gbm(struct gbm_bo *bo, void *data)<br>
        drm_fb_destroy(fb);<br>
 }<br>
<br>
+static int<br>
+drm_fb_addfb(struct drm_fb *fb)<br>
+{<br>
+       int ret;<br>
+<br>
+       ret = drmModeAddFB2(fb->fd, fb->width, fb->height, fb->format->format,<br>
+                           fb->handles, fb->strides, fb->offsets, &fb->fb_id,<br>
+                           0);<br>
+       if (ret == 0)<br>
+               return 0;<br>
+<br>
+       /* Legacy AddFB can't always infer the format from depth/bpp alone, so<br>
+        * check if our format is one of the lucky ones. */<br>
+       if (!fb->format->depth || !fb->format->bpp)<br>
+               return ret;<br>
+<br>
+       /* Cannot fall back to AddFB for multi-planar formats either. */<br>
+       if (fb->handles[1] || fb->handles[2] || fb->handles[3])<br>
+               return ret;<br>
+<br>
+       ret = drmModeAddFB(fb->fd, fb->width, fb->height,<br>
+                          fb->format->depth, fb->format->bpp,<br>
+                          fb->strides[0], fb->handles[0], &fb->fb_id);<br>
+       return ret;<br>
+}<br>
+<br>
 static struct drm_fb *<br>
 drm_fb_create_dumb(struct drm_backend *b, int width, int height,<br>
                   uint32_t format)<br>
@@ -827,12 +856,10 @@ drm_fb_create_dumb(struct drm_backend *b, int width, int height,<br>
        struct drm_mode_create_dumb create_arg;<br>
        struct drm_mode_destroy_dumb destroy_arg;<br>
        struct drm_mode_map_dumb map_arg;<br>
-       uint32_t handles[4] = { 0 }, pitches[4] = { 0 }, offsets[4] = { 0 };<br>
<br>
        fb = zalloc(sizeof *fb);<br>
        if (!fb)<br>
                return NULL;<br>
-<br>
        fb->refcnt = 1;<br>
<br>
        fb->format = pixel_format_get_info(format);<br>
@@ -858,32 +885,20 @@ drm_fb_create_dumb(struct drm_backend *b, int width, int height,<br>
                goto err_fb;<br>
<br>
        fb->type = BUFFER_PIXMAN_DUMB;<br>
-       fb->handle = create_arg.handle;<br>
-       fb->stride = create_arg.pitch;<br>
+       fb->handles[0] = create_arg.handle;<br>
+       fb->strides[0] = create_arg.pitch;<br>
        fb->size = create_arg.size;<br>
        fb->width = width;<br>
        fb->height = height;<br>
        fb->fd = b->drm.fd;<br>
<br>
-       ret = -1;<br>
-<br>
-       handles[0] = fb->handle;<br>
-       pitches[0] = fb->stride;<br>
-       offsets[0] = 0;<br>
-<br>
-       ret = drmModeAddFB2(b->drm.fd, width, height, fb->format->format,<br>
-                           handles, pitches, offsets, &fb->fb_id, 0);<br>
-       if (ret) {<br>
-               ret = drmModeAddFB(b->drm.fd, width, height,<br>
-                                  fb->format->depth, fb->format->bpp,<br>
-                                  fb->stride, fb->handle, &fb->fb_id);<br>
-       }<br>
-<br>
-       if (ret)<br>
+       if (drm_fb_addfb(fb) != 0) {<br>
+               weston_log("failed to create kms fb: %m\n");<br>
                goto err_bo;<br>
+       }<br>
<br>
        memset(&map_arg, 0, sizeof map_arg);<br>
-       map_arg.handle = fb->handle;<br>
+       map_arg.handle = fb->handles[0];<br>
        ret = drmIoctl(fb->fd, DRM_IOCTL_MODE_MAP_DUMB, &map_arg);<br>
        if (ret)<br>
                goto err_add_fb;<br>
@@ -918,8 +933,6 @@ drm_fb_get_from_bo(struct gbm_bo *bo, struct drm_backend *backend,<br>
                   bool is_opaque, enum drm_fb_type type)<br>
 {<br>
        struct drm_fb *fb = gbm_bo_get_user_data(bo);<br>
-       uint32_t handles[4] = { 0 }, pitches[4] = { 0 }, offsets[4] = { 0 };<br>
-       int ret;<br>
<br>
        if (fb) {<br>
                assert(fb->type == type);<br>
@@ -936,10 +949,10 @@ drm_fb_get_from_bo(struct gbm_bo *bo, struct drm_backend *backend,<br>
<br>
        fb->width = gbm_bo_get_width(bo);<br>
        fb->height = gbm_bo_get_height(bo);<br>
-       fb->stride = gbm_bo_get_stride(bo);<br>
-       fb->handle = gbm_bo_get_handle(bo).u32;<br>
+       fb->strides[0] = gbm_bo_get_stride(bo);<br>
+       fb->handles[0] = gbm_bo_get_handle(bo).u32;<br>
        fb->format = pixel_format_get_info(gbm_bo_<wbr>get_format(bo));<br>
-       fb->size = fb->stride * fb->height;<br>
+       fb->size = fb->strides[0] * fb->height;<br>
        fb->fd = backend->drm.fd;<br>
<br>
        if (!fb->format) {<br>
@@ -959,19 +972,7 @@ drm_fb_get_from_bo(struct gbm_bo *bo, struct drm_backend *backend,<br>
                goto err_free;<br>
        }<br>
<br>
-       handles[0] = fb->handle;<br>
-       pitches[0] = fb->stride;<br>
-       offsets[0] = 0;<br>
-<br>
-       ret = drmModeAddFB2(backend->drm.fd, fb->width, fb->height,<br>
-                           fb->format->format, handles, pitches, offsets,<br>
-                           &fb->fb_id, 0);<br>
-       if (ret && fb->format->depth && fb->format->bpp)<br>
-               ret = drmModeAddFB(backend->drm.fd, fb->width, fb->height,<br>
-                                  fb->format->depth, fb->format->bpp,<br>
-                                  fb->stride, fb->handle, &fb->fb_id);<br>
-<br>
-       if (ret) {<br>
+       if (drm_fb_addfb(fb) != 0) {<br>
                weston_log("failed to create kms fb: %m\n");<br>
                goto err_free;<br>
        }<br>
@@ -1895,8 +1896,10 @@ drm_output_apply_state_legacy(<wbr>struct drm_output_state *state)<br>
        assert(scanout_state->dest_h == scanout_state->src_h >> 16);<br>
<br>
        mode = to_drm_mode(output->base.<wbr>current_mode);<br>
-       if (backend->state_invalid || !scanout_plane->state_cur->fb ||<br>
-           scanout_plane->state_cur->fb-><wbr>stride != scanout_state->fb->stride) {<br>
+       if (backend->state_invalid ||<br>
+           !scanout_plane->state_cur->fb ||<br>
+           scanout_plane->state_cur->fb-><wbr>strides[0] !=<br>
+           scanout_state->fb->strides[0]) {<br>
                ret = drmModeSetCrtc(backend->drm.<wbr>fd, output->crtc_id,<br>
                                     scanout_state->fb->fb_id,<br>
                                     0, 0,<br>
@@ -3894,7 +3897,7 @@ drm_output_init_pixman(struct drm_output *output, struct drm_backend *b)<br>
                output->image[i] =<br>
                        pixman_image_create_bits(<wbr>pixman_format, w, h,<br>
                                                 output->dumb[i]->map,<br>
-                                                output->dumb[i]->stride);<br>
+                                                output->dumb[i]->strides[0]);<br>
                if (!output->image[i])<br>
                        goto err;<br>
        }<br>
@@ -5103,7 +5106,7 @@ recorder_frame_notify(struct wl_listener *listener, void *data)<br>
                return;<br>
<br>
        ret = drmPrimeHandleToFD(b->drm.fd,<br>
-                                output->scanout_plane->state_<wbr>cur->fb->handle,<br>
+                                output->scanout_plane->state_<wbr>cur->fb->handles[0],<br>
                                 DRM_CLOEXEC, &fd);<br>
        if (ret) {<br>
                weston_log("[libva recorder] "<br>
@@ -5112,7 +5115,7 @@ recorder_frame_notify(struct wl_listener *listener, void *data)<br>
        }<br>
<br>
        ret = vaapi_recorder_frame(output-><wbr>recorder, fd,<br>
-                                  output->scanout_plane->state_<wbr>cur->fb->stride);<br>
+                                  output->scanout_plane->state_<wbr>cur->fb->strides[0]);<br>
        if (ret < 0) {<br>
                weston_log("[libva recorder] aborted: %m\n");<br>
                recorder_destroy(output);<br>
<span class="HOEnZb"><font color="#888888">--<br>
2.14.1<br>
<br>
______________________________<wbr>_________________<br>
wayland-devel mailing list<br>
<a href="mailto:wayland-devel@lists.freedesktop.org">wayland-devel@lists.<wbr>freedesktop.org</a><br>
<a href="https://lists.freedesktop.org/mailman/listinfo/wayland-devel" rel="noreferrer" target="_blank">https://lists.freedesktop.org/<wbr>mailman/listinfo/wayland-devel</a><br>
</font></span></blockquote></div><br></div>