compositor-drm: Store format in drm_fb

This uses the new pixel-format helpers, so we can also replace depth/bpp
with these.

Signed-off-by: Daniel Stone <daniels@collabora.com>
Reviewed-by: Pekka Paalanen <pekka.paalaneN@collabora.co.uk>
dev
Daniel Stone 8 years ago committed by Pekka Paalanen
parent fc175a7ec8
commit 0b70fa4b56
  1. 44
      libweston/compositor-drm.c

@ -54,6 +54,7 @@
#include "gl-renderer.h" #include "gl-renderer.h"
#include "weston-egl-ext.h" #include "weston-egl-ext.h"
#include "pixman-renderer.h" #include "pixman-renderer.h"
#include "pixel-formats.h"
#include "libbacklight.h" #include "libbacklight.h"
#include "libinput-seat.h" #include "libinput-seat.h"
#include "launcher-util.h" #include "launcher-util.h"
@ -138,6 +139,7 @@ struct drm_fb {
enum drm_fb_type type; enum drm_fb_type type;
uint32_t fb_id, stride, handle, size; uint32_t fb_id, stride, handle, size;
const struct pixel_format_info *format;
int width, height; int width, height;
int fd; int fd;
struct weston_buffer_reference buffer_ref; struct weston_buffer_reference buffer_ref;
@ -344,7 +346,6 @@ drm_fb_create_dumb(struct drm_backend *b, int width, int height,
{ {
struct drm_fb *fb; struct drm_fb *fb;
int ret; int ret;
uint32_t bpp, depth;
struct drm_mode_create_dumb create_arg; struct drm_mode_create_dumb create_arg;
struct drm_mode_destroy_dumb destroy_arg; struct drm_mode_destroy_dumb destroy_arg;
@ -354,20 +355,21 @@ drm_fb_create_dumb(struct drm_backend *b, int width, int height,
if (!fb) if (!fb)
return NULL; return NULL;
switch (format) { fb->format = pixel_format_get_info(format);
case GBM_FORMAT_XRGB8888: if (!fb->format) {
bpp = 32; weston_log("failed to look up format 0x%lx\n",
depth = 24; (unsigned long) format);
break; goto err_fb;
case GBM_FORMAT_RGB565: }
bpp = depth = 16;
break; if (!fb->format->depth || !fb->format->bpp) {
default: weston_log("format 0x%lx is not compatible with dumb buffers\n",
return NULL; (unsigned long) format);
goto err_fb;
} }
memset(&create_arg, 0, sizeof create_arg); memset(&create_arg, 0, sizeof create_arg);
create_arg.bpp = bpp; create_arg.bpp = fb->format->bpp;
create_arg.width = width; create_arg.width = width;
create_arg.height = height; create_arg.height = height;
@ -393,7 +395,8 @@ drm_fb_create_dumb(struct drm_backend *b, int width, int height,
offsets[0] = 0; offsets[0] = 0;
ret = drmModeAddFB2(b->drm.fd, width, height, ret = drmModeAddFB2(b->drm.fd, width, height,
format, handles, pitches, offsets, fb->format->format,
handles, pitches, offsets,
&fb->fb_id, 0); &fb->fb_id, 0);
if (ret) { if (ret) {
weston_log("addfb2 failed: %m\n"); weston_log("addfb2 failed: %m\n");
@ -402,7 +405,8 @@ drm_fb_create_dumb(struct drm_backend *b, int width, int height,
} }
if (ret) { 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); fb->stride, fb->handle, &fb->fb_id);
} }
@ -481,9 +485,16 @@ drm_fb_get_from_bo(struct gbm_bo *bo, struct drm_backend *backend,
fb->height = gbm_bo_get_height(bo); fb->height = gbm_bo_get_height(bo);
fb->stride = gbm_bo_get_stride(bo); fb->stride = gbm_bo_get_stride(bo);
fb->handle = gbm_bo_get_handle(bo).u32; fb->handle = gbm_bo_get_handle(bo).u32;
fb->format = pixel_format_get_info(format);
fb->size = fb->stride * fb->height; fb->size = fb->stride * fb->height;
fb->fd = backend->drm.fd; 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 || if (backend->min_width > fb->width ||
fb->width > backend->max_width || fb->width > backend->max_width ||
backend->min_height > fb->height || backend->min_height > fb->height ||
@ -509,9 +520,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, 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) { if (ret) {
weston_log("failed to create kms fb: %m\n"); weston_log("failed to create kms fb: %m\n");

Loading…
Cancel
Save