[PATCH weston v12 26/40] compositor-drm: Extract drm_fb_addfb into a helper

Prabhu S prabhusundar at gmail.com
Tue Sep 26 17:25:16 UTC 2017


Any plan to support for drmModeAddFB2WithModifiers and query preferred
FB modifier?


On Tue, Sep 26, 2017 at 12:15 PM, Daniel Stone <daniels at collabora.com>
wrote:

> We currently do the same thing in two places, and will soon have a
> third.
>
> Signed-off-by: Daniel Stone <daniels at collabora.com>
> ---
>  libweston/compositor-drm.c | 93 ++++++++++++++++++++++++------
> ----------------
>  1 file changed, 48 insertions(+), 45 deletions(-)
>
> diff --git a/libweston/compositor-drm.c b/libweston/compositor-drm.c
> index e03f8f7e..7557ef55 100644
> --- a/libweston/compositor-drm.c
> +++ b/libweston/compositor-drm.c
> @@ -283,7 +283,10 @@ struct drm_fb {
>
>         int refcnt;
>
> -       uint32_t fb_id, stride, handle, size;
> +       uint32_t fb_id, size;
> +       uint32_t handles[4];
> +       uint32_t strides[4];
> +       uint32_t offsets[4];
>         const struct pixel_format_info *format;
>         int width, height;
>         int fd;
> @@ -801,7 +804,7 @@ drm_fb_destroy_dumb(struct drm_fb *fb)
>                 munmap(fb->map, fb->size);
>
>         memset(&destroy_arg, 0, sizeof(destroy_arg));
> -       destroy_arg.handle = fb->handle;
> +       destroy_arg.handle = fb->handles[0];
>         drmIoctl(fb->fd, DRM_IOCTL_MODE_DESTROY_DUMB, &destroy_arg);
>
>         drm_fb_destroy(fb);
> @@ -817,6 +820,32 @@ drm_fb_destroy_gbm(struct gbm_bo *bo, void *data)
>         drm_fb_destroy(fb);
>  }
>
> +static int
> +drm_fb_addfb(struct drm_fb *fb)
> +{
> +       int ret;
> +
> +       ret = drmModeAddFB2(fb->fd, fb->width, fb->height,
> fb->format->format,
> +                           fb->handles, fb->strides, fb->offsets,
> &fb->fb_id,
> +                           0);
> +       if (ret == 0)
> +               return 0;
> +
> +       /* Legacy AddFB can't always infer the format from depth/bpp
> alone, so
> +        * check if our format is one of the lucky ones. */
> +       if (!fb->format->depth || !fb->format->bpp)
> +               return ret;
> +
> +       /* Cannot fall back to AddFB for multi-planar formats either. */
> +       if (fb->handles[1] || fb->handles[2] || fb->handles[3])
> +               return ret;
> +
> +       ret = drmModeAddFB(fb->fd, fb->width, fb->height,
> +                          fb->format->depth, fb->format->bpp,
> +                          fb->strides[0], fb->handles[0], &fb->fb_id);
> +       return ret;
> +}
> +
>  static struct drm_fb *
>  drm_fb_create_dumb(struct drm_backend *b, int width, int height,
>                    uint32_t format)
> @@ -827,12 +856,10 @@ drm_fb_create_dumb(struct drm_backend *b, int width,
> int height,
>         struct drm_mode_create_dumb create_arg;
>         struct drm_mode_destroy_dumb destroy_arg;
>         struct drm_mode_map_dumb map_arg;
> -       uint32_t handles[4] = { 0 }, pitches[4] = { 0 }, offsets[4] = { 0
> };
>
>         fb = zalloc(sizeof *fb);
>         if (!fb)
>                 return NULL;
> -
>         fb->refcnt = 1;
>
>         fb->format = pixel_format_get_info(format);
> @@ -858,32 +885,20 @@ drm_fb_create_dumb(struct drm_backend *b, int width,
> int height,
>                 goto err_fb;
>
>         fb->type = BUFFER_PIXMAN_DUMB;
> -       fb->handle = create_arg.handle;
> -       fb->stride = create_arg.pitch;
> +       fb->handles[0] = create_arg.handle;
> +       fb->strides[0] = create_arg.pitch;
>         fb->size = create_arg.size;
>         fb->width = width;
>         fb->height = height;
>         fb->fd = b->drm.fd;
>
> -       ret = -1;
> -
> -       handles[0] = fb->handle;
> -       pitches[0] = fb->stride;
> -       offsets[0] = 0;
> -
> -       ret = drmModeAddFB2(b->drm.fd, width, height, fb->format->format,
> -                           handles, pitches, offsets, &fb->fb_id, 0);
> -       if (ret) {
> -               ret = drmModeAddFB(b->drm.fd, width, height,
> -                                  fb->format->depth, fb->format->bpp,
> -                                  fb->stride, fb->handle, &fb->fb_id);
> -       }
> -
> -       if (ret)
> +       if (drm_fb_addfb(fb) != 0) {
> +               weston_log("failed to create kms fb: %m\n");
>                 goto err_bo;
> +       }
>
>         memset(&map_arg, 0, sizeof map_arg);
> -       map_arg.handle = fb->handle;
> +       map_arg.handle = fb->handles[0];
>         ret = drmIoctl(fb->fd, DRM_IOCTL_MODE_MAP_DUMB, &map_arg);
>         if (ret)
>                 goto err_add_fb;
> @@ -918,8 +933,6 @@ drm_fb_get_from_bo(struct gbm_bo *bo, struct
> drm_backend *backend,
>                    bool is_opaque, enum drm_fb_type type)
>  {
>         struct drm_fb *fb = gbm_bo_get_user_data(bo);
> -       uint32_t handles[4] = { 0 }, pitches[4] = { 0 }, offsets[4] = { 0
> };
> -       int ret;
>
>         if (fb) {
>                 assert(fb->type == type);
> @@ -936,10 +949,10 @@ drm_fb_get_from_bo(struct gbm_bo *bo, struct
> drm_backend *backend,
>
>         fb->width = gbm_bo_get_width(bo);
>         fb->height = gbm_bo_get_height(bo);
> -       fb->stride = gbm_bo_get_stride(bo);
> -       fb->handle = gbm_bo_get_handle(bo).u32;
> +       fb->strides[0] = gbm_bo_get_stride(bo);
> +       fb->handles[0] = gbm_bo_get_handle(bo).u32;
>         fb->format = pixel_format_get_info(gbm_bo_get_format(bo));
> -       fb->size = fb->stride * fb->height;
> +       fb->size = fb->strides[0] * fb->height;
>         fb->fd = backend->drm.fd;
>
>         if (!fb->format) {
> @@ -959,19 +972,7 @@ drm_fb_get_from_bo(struct gbm_bo *bo, struct
> drm_backend *backend,
>                 goto err_free;
>         }
>
> -       handles[0] = fb->handle;
> -       pitches[0] = fb->stride;
> -       offsets[0] = 0;
> -
> -       ret = drmModeAddFB2(backend->drm.fd, fb->width, fb->height,
> -                           fb->format->format, handles, pitches, offsets,
> -                           &fb->fb_id, 0);
> -       if (ret && fb->format->depth && fb->format->bpp)
> -               ret = drmModeAddFB(backend->drm.fd, fb->width, fb->height,
> -                                  fb->format->depth, fb->format->bpp,
> -                                  fb->stride, fb->handle, &fb->fb_id);
> -
> -       if (ret) {
> +       if (drm_fb_addfb(fb) != 0) {
>                 weston_log("failed to create kms fb: %m\n");
>                 goto err_free;
>         }
> @@ -1895,8 +1896,10 @@ drm_output_apply_state_legacy(struct
> drm_output_state *state)
>         assert(scanout_state->dest_h == scanout_state->src_h >> 16);
>
>         mode = to_drm_mode(output->base.current_mode);
> -       if (backend->state_invalid || !scanout_plane->state_cur->fb ||
> -           scanout_plane->state_cur->fb->stride !=
> scanout_state->fb->stride) {
> +       if (backend->state_invalid ||
> +           !scanout_plane->state_cur->fb ||
> +           scanout_plane->state_cur->fb->strides[0] !=
> +           scanout_state->fb->strides[0]) {
>                 ret = drmModeSetCrtc(backend->drm.fd, output->crtc_id,
>                                      scanout_state->fb->fb_id,
>                                      0, 0,
> @@ -3894,7 +3897,7 @@ drm_output_init_pixman(struct drm_output *output,
> struct drm_backend *b)
>                 output->image[i] =
>                         pixman_image_create_bits(pixman_format, w, h,
>                                                  output->dumb[i]->map,
> -                                                output->dumb[i]->stride);
> +
> output->dumb[i]->strides[0]);
>                 if (!output->image[i])
>                         goto err;
>         }
> @@ -5103,7 +5106,7 @@ recorder_frame_notify(struct wl_listener *listener,
> void *data)
>                 return;
>
>         ret = drmPrimeHandleToFD(b->drm.fd,
> -                                output->scanout_plane->state_
> cur->fb->handle,
> +                                output->scanout_plane->state_
> cur->fb->handles[0],
>                                  DRM_CLOEXEC, &fd);
>         if (ret) {
>                 weston_log("[libva recorder] "
> @@ -5112,7 +5115,7 @@ recorder_frame_notify(struct wl_listener *listener,
> void *data)
>         }
>
>         ret = vaapi_recorder_frame(output->recorder, fd,
> -                                  output->scanout_plane->state_
> cur->fb->stride);
> +                                  output->scanout_plane->state_
> cur->fb->strides[0]);
>         if (ret < 0) {
>                 weston_log("[libva recorder] aborted: %m\n");
>                 recorder_destroy(output);
> --
> 2.14.1
>
> _______________________________________________
> wayland-devel mailing list
> wayland-devel at lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/wayland-devel
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.freedesktop.org/archives/wayland-devel/attachments/20170926/0162e92c/attachment.html>


More information about the wayland-devel mailing list