[PATCH weston 16/68] compositor-drm: Store format in drm_fb
Armin Krezović
krezovic.armin at gmail.com
Fri Dec 9 21:07:02 UTC 2016
On 09.12.2016 20:57, Daniel Stone wrote:
> This uses the new pixel-format helpers, so we can also replace depth/bpp
> with these.
>
> Signed-off-by: Daniel Stone <daniels at collabora.com>
>
> Differential Revision: https://phabricator.freedesktop.org/D1513
So, this is where code added by patch 1 is being used. I suggest
squashing it with this one (unless I missed an earlier patch that
also uses it).
> ---
> libweston/compositor-drm.c | 43 +++++++++++++++++++++++++++----------------
> 1 file changed, 27 insertions(+), 16 deletions(-)
>
> diff --git a/libweston/compositor-drm.c b/libweston/compositor-drm.c
> index 217db32..af43a15 100644
> --- a/libweston/compositor-drm.c
> +++ b/libweston/compositor-drm.c
> @@ -54,6 +54,7 @@
> #include "gl-renderer.h"
> #include "weston-egl-ext.h"
> #include "pixman-renderer.h"
> +#include "pixel-formats.h"
> #include "libbacklight.h"
> #include "libinput-seat.h"
> #include "launcher-util.h"
> @@ -140,6 +141,7 @@ struct drm_fb {
> enum drm_fb_type type;
>
> uint32_t fb_id, stride, handle, size;
> + const struct pixel_format_info *format;
> int width, height;
> int fd;
> struct weston_buffer_reference buffer_ref;
> @@ -267,7 +269,6 @@ drm_fb_create_dumb(struct drm_backend *b, int width, int height,
> {
> struct drm_fb *fb;
> int ret;
> - uint32_t bpp, depth;
>
> struct drm_mode_create_dumb create_arg;
> struct drm_mode_destroy_dumb destroy_arg;
> @@ -277,20 +278,20 @@ drm_fb_create_dumb(struct drm_backend *b, int width, int height,
> if (!fb)
> return NULL;
>
> - switch (format) {
> - case GBM_FORMAT_XRGB8888:
> - bpp = 32;
> - depth = 24;
> - break;
> - case GBM_FORMAT_RGB565:
> - bpp = depth = 16;
> - break;
> - default:
> - return NULL;
> + fb->format = pixel_format_get_info(format);
> + if (!fb->format) {
> + weston_log("failed to look up format 0x%lx\n",
> + (unsigned long) format);
> + goto err_fb;
> + }
> +
> + if (!fb->format->depth || !fb->format->bpp) {
> + weston_log("format 0x%lx is not compatible with dumb buffers\n",
> + (unsigned long) format);
> }
>
> memset(&create_arg, 0, sizeof create_arg);
> - create_arg.bpp = bpp;
> + create_arg.bpp = fb->format->bpp;
> create_arg.width = width;
> create_arg.height = height;
>
> @@ -316,7 +317,8 @@ drm_fb_create_dumb(struct drm_backend *b, int width, int height,
> offsets[0] = 0;
>
> ret = drmModeAddFB2(b->drm.fd, width, height,
> - format, handles, pitches, offsets,
> + fb->format->format,
> + handles, pitches, offsets,
> &fb->fb_id, 0);
> if (ret) {
> weston_log("addfb2 failed: %m\n");
> @@ -325,7 +327,8 @@ drm_fb_create_dumb(struct drm_backend *b, int width, int height,
> }
>
> if (ret) {
> - ret = drmModeAddFB(b->drm.fd, width, height, depth, bpp,
> + ret = drmModeAddFB(b->drm.fd, width, height,
> + fb->format->depth, fb->format->bpp,
> fb->stride, fb->handle, &fb->fb_id);
> }
>
> @@ -402,9 +405,16 @@ drm_fb_get_from_bo(struct gbm_bo *bo, struct drm_backend *backend,
> fb->height = gbm_bo_get_height(bo);
> fb->stride = gbm_bo_get_stride(bo);
> fb->handle = gbm_bo_get_handle(bo).u32;
> + fb->format = pixel_format_get_info(format);
> fb->size = fb->stride * fb->height;
> fb->fd = backend->drm.fd;
>
> + if (!fb->format) {
> + weston_log("couldn't look up format 0x%lx\n",
> + (unsigned long) format);
> + goto err_free;
> + }
> +
> if (backend->min_width > fb->width ||
> fb->width > backend->max_width ||
> backend->min_height > fb->height ||
> @@ -430,9 +440,10 @@ drm_fb_get_from_bo(struct gbm_bo *bo, struct drm_backend *backend,
> }
> }
>
> - if (ret)
> + if (ret && fb->format->depth && fb->format->bpp)
> ret = drmModeAddFB(backend->drm.fd, fb->width, fb->height,
> - 24, 32, fb->stride, fb->handle, &fb->fb_id);
> + fb->format->depth, fb->format->bpp,
> + fb->stride, fb->handle, &fb->fb_id);
>
> if (ret) {
> weston_log("failed to create kms fb: %m\n");
>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 870 bytes
Desc: OpenPGP digital signature
URL: <https://lists.freedesktop.org/archives/wayland-devel/attachments/20161209/4e5bf0a4/attachment.sig>
More information about the wayland-devel
mailing list