Skip to content
Commits on Source (13)
......@@ -118,8 +118,9 @@ drm_backend_create_gl_renderer(struct drm_backend *b)
int
init_egl(struct drm_backend *b)
{
b->gbm = create_gbm_device(b->drm.fd);
struct drm_device *device = b->drm;
b->gbm = create_gbm_device(device->drm.fd);
if (!b->gbm)
return -1;
......@@ -145,6 +146,7 @@ static void drm_output_fini_cursor_egl(struct drm_output *output)
static int
drm_output_init_cursor_egl(struct drm_output *output, struct drm_backend *b)
{
struct drm_device *device = output->device;
unsigned int i;
/* No point creating cursors if we don't have a plane for them. */
......@@ -154,14 +156,14 @@ drm_output_init_cursor_egl(struct drm_output *output, struct drm_backend *b)
for (i = 0; i < ARRAY_LENGTH(output->gbm_cursor_fb); i++) {
struct gbm_bo *bo;
bo = gbm_bo_create(b->gbm, b->cursor_width, b->cursor_height,
bo = gbm_bo_create(b->gbm, device->cursor_width, device->cursor_height,
GBM_FORMAT_ARGB8888,
GBM_BO_USE_CURSOR | GBM_BO_USE_WRITE);
if (!bo)
goto err;
output->gbm_cursor_fb[i] =
drm_fb_get_from_bo(bo, b, false, BUFFER_CURSOR);
drm_fb_get_from_bo(bo, device, false, BUFFER_CURSOR);
if (!output->gbm_cursor_fb[i]) {
gbm_bo_destroy(bo);
goto err;
......@@ -173,7 +175,7 @@ drm_output_init_cursor_egl(struct drm_output *output, struct drm_backend *b)
err:
weston_log("cursor buffers unavailable, using gl cursors\n");
b->cursors_are_broken = true;
device->cursors_are_broken = true;
drm_output_fini_cursor_egl(output);
return -1;
}
......@@ -183,6 +185,7 @@ create_gbm_surface(struct gbm_device *gbm, struct drm_output *output)
{
struct weston_mode *mode = output->base.current_mode;
struct drm_plane *plane = output->scanout_plane;
const struct pixel_format_info *pixel_format;
struct weston_drm_format *fmt;
const uint64_t *modifiers;
unsigned int num_modifiers;
......@@ -190,8 +193,15 @@ create_gbm_surface(struct gbm_device *gbm, struct drm_output *output)
fmt = weston_drm_format_array_find_format(&plane->formats,
output->gbm_format);
if (!fmt) {
weston_log("format 0x%x not supported by output %s\n",
output->gbm_format, output->base.name);
pixel_format = pixel_format_get_info(output->gbm_format);
if (pixel_format)
weston_log("format %s not supported by output %s\n",
pixel_format->drm_format_name,
output->base.name);
else
weston_log("format 0x%x not supported by output %s\n",
output->gbm_format,
output->base.name);
return;
}
......@@ -280,7 +290,7 @@ struct drm_fb *
drm_output_render_gl(struct drm_output_state *state, pixman_region32_t *damage)
{
struct drm_output *output = state->output;
struct drm_backend *b = to_drm_backend(output->base.compositor);
struct drm_device *device = output->device;
struct gbm_bo *bo;
struct drm_fb *ret;
......@@ -295,7 +305,7 @@ drm_output_render_gl(struct drm_output_state *state, pixman_region32_t *damage)
}
/* The renderer always produces an opaque image. */
ret = drm_fb_get_from_bo(bo, b, true, BUFFER_GBM_SURFACE);
ret = drm_fb_get_from_bo(bo, device, true, BUFFER_GBM_SURFACE);
if (!ret) {
weston_log("failed to get drm_fb for bo\n");
gbm_surface_release_buffer(output->gbm_surface, bo);
......@@ -309,6 +319,7 @@ drm_output_render_gl(struct drm_output_state *state, pixman_region32_t *damage)
static void
switch_to_gl_renderer(struct drm_backend *b)
{
struct drm_device *device = b->drm;
struct drm_output *output;
bool dmabuf_support_inited;
bool linux_explicit_sync_inited;
......@@ -322,7 +333,7 @@ switch_to_gl_renderer(struct drm_backend *b)
weston_log("Switching to GL renderer\n");
b->gbm = create_gbm_device(b->drm.fd);
b->gbm = create_gbm_device(device->drm.fd);
if (!b->gbm) {
weston_log("Failed to create gbm device. "
"Aborting renderer switch\n");
......
......@@ -259,15 +259,8 @@ enum actions_needed_dmabuf_feedback {
ACTION_NEEDED_REMOVE_SCANOUT_TRANCHE = (1 << 1),
};
struct drm_backend {
struct weston_backend base;
struct weston_compositor *compositor;
struct udev *udev;
struct wl_event_source *drm_source;
struct udev_monitor *udev_monitor;
struct wl_event_source *udev_drm_source;
struct drm_device {
struct drm_backend *backend;
struct {
int id;
......@@ -275,50 +268,63 @@ struct drm_backend {
char *filename;
dev_t devnum;
} drm;
struct gbm_device *gbm;
struct wl_listener session_listener;
uint32_t gbm_format;
/* we need these parameters in order to not fail drmModeAddFB2()
* due to out of bounds dimensions, and then mistakenly set
* sprites_are_broken:
*/
int min_width, max_width;
int min_height, max_height;
/* drm_crtc::link */
struct wl_list crtc_list;
struct wl_list plane_list;
void *repaint_data;
/* drm_writeback::link */
struct wl_list writeback_connector_list;
bool state_invalid;
/* drm_crtc::link */
struct wl_list crtc_list;
bool atomic_modeset;
/* drm_writeback::link */
struct wl_list writeback_connector_list;
bool aspect_ratio_supported;
int32_t cursor_width;
int32_t cursor_height;
bool sprites_are_broken;
bool cursors_are_broken;
bool sprites_are_broken;
bool atomic_modeset;
void *repaint_data;
bool fb_modifiers;
/* we need these parameters in order to not fail drmModeAddFB2()
* due to out of bounds dimensions, and then mistakenly set
* sprites_are_broken:
*/
int min_width, max_width;
int min_height, max_height;
};
struct drm_backend {
struct weston_backend base;
struct weston_compositor *compositor;
struct udev *udev;
struct wl_event_source *drm_source;
struct udev_monitor *udev_monitor;
struct wl_event_source *udev_drm_source;
struct drm_device *drm;
struct gbm_device *gbm;
struct wl_listener session_listener;
uint32_t gbm_format;
bool use_pixman;
bool use_pixman_shadow;
struct udev_input input;
int32_t cursor_width;
int32_t cursor_height;
uint32_t pageflip_timeout;
bool shutting_down;
bool aspect_ratio_supported;
bool fb_modifiers;
struct weston_log_scope *debug;
};
......@@ -382,7 +388,7 @@ struct drm_edid {
* output state will complete and be retired separately.
*/
struct drm_pending_state {
struct drm_backend *backend;
struct drm_device *device;
struct wl_list output_list;
};
......@@ -460,7 +466,7 @@ struct drm_plane_state {
struct drm_plane {
struct weston_plane base;
struct drm_backend *backend;
struct drm_device *device;
enum wdrm_plane_type type;
......@@ -482,7 +488,7 @@ struct drm_plane {
};
struct drm_connector {
struct drm_backend *backend;
struct drm_device *device;
drmModeConnector *conn;
uint32_t connector_id;
......@@ -494,16 +500,15 @@ struct drm_connector {
};
struct drm_writeback {
/* drm_backend::writeback_connector_list */
/* drm_device::writeback_connector_list */
struct wl_list link;
struct drm_backend *backend;
struct drm_device *device;
struct drm_connector connector;
};
struct drm_head {
struct weston_head base;
struct drm_backend *backend;
struct drm_connector connector;
struct drm_edid edid;
......@@ -515,9 +520,9 @@ struct drm_head {
};
struct drm_crtc {
/* drm_backend::crtc_list */
/* drm_device::crtc_list */
struct wl_list link;
struct drm_backend *backend;
struct drm_device *device;
/* The output driven by the CRTC */
struct drm_output *output;
......@@ -531,7 +536,7 @@ struct drm_crtc {
struct drm_output {
struct weston_output base;
struct drm_backend *backend;
struct drm_device *device;
struct drm_crtc *crtc;
bool page_flip_pending;
......@@ -619,7 +624,7 @@ drm_output_get_plane_type_name(struct drm_plane *p)
}
struct drm_crtc *
drm_crtc_find(struct drm_backend *b, uint32_t crtc_id);
drm_crtc_find(struct drm_device *device, uint32_t crtc_id);
struct drm_head *
drm_head_find_by_connector(struct drm_backend *backend, uint32_t connector_id);
......@@ -644,7 +649,7 @@ drm_view_transform_supported(struct weston_view *ev, struct weston_output *outpu
}
int
drm_mode_ensure_blob(struct drm_backend *backend, struct drm_mode *mode);
drm_mode_ensure_blob(struct drm_device *device, struct drm_mode *mode);
struct drm_mode *
drm_output_choose_mode(struct drm_output *output,
......@@ -653,7 +658,7 @@ void
update_head_from_connector(struct drm_head *head);
void
drm_mode_list_destroy(struct drm_backend *backend, struct wl_list *mode_list);
drm_mode_list_destroy(struct drm_device *device, struct wl_list *mode_list);
void
drm_output_print_modes(struct drm_output *output);
......@@ -664,7 +669,7 @@ drm_output_set_mode(struct weston_output *base,
const char *modeline);
void
drm_property_info_populate(struct drm_backend *b,
drm_property_info_populate(struct drm_device *device,
const struct drm_property_info *src,
struct drm_property_info *info,
unsigned int num_infos,
......@@ -692,7 +697,7 @@ extern const struct drm_property_info connector_props[];
extern const struct drm_property_info crtc_props[];
int
init_kms_caps(struct drm_backend *b);
init_kms_caps(struct drm_device *device);
int
drm_pending_state_test(struct drm_pending_state *pending_state);
......@@ -719,10 +724,10 @@ void
drm_fb_unref(struct drm_fb *fb);
struct drm_fb *
drm_fb_create_dumb(struct drm_backend *b, int width, int height,
drm_fb_create_dumb(struct drm_device *device, int width, int height,
uint32_t format);
struct drm_fb *
drm_fb_get_from_bo(struct gbm_bo *bo, struct drm_backend *backend,
drm_fb_get_from_bo(struct gbm_bo *bo, struct drm_device *device,
bool is_opaque, enum drm_fb_type type);
void
......@@ -754,7 +759,7 @@ drm_can_scanout_dmabuf(struct weston_compositor *ec,
#endif
struct drm_pending_state *
drm_pending_state_alloc(struct drm_backend *backend);
drm_pending_state_alloc(struct drm_device *device);
void
drm_pending_state_free(struct drm_pending_state *pending_state);
struct drm_output_state *
......
......@@ -47,7 +47,7 @@
* CRTC's. Also, as this is a fake CRTC, it will not try to populate props.
*/
static struct drm_crtc *
drm_virtual_crtc_create(struct drm_backend *b, struct drm_output *output)
drm_virtual_crtc_create(struct drm_device *device, struct drm_output *output)
{
struct drm_crtc *crtc;
......@@ -55,7 +55,7 @@ drm_virtual_crtc_create(struct drm_backend *b, struct drm_output *output)
if (!crtc)
return NULL;
crtc->backend = b;
crtc->device = device;
crtc->output = output;
crtc->crtc_id = 0;
......@@ -86,12 +86,13 @@ drm_virtual_crtc_destroy(struct drm_crtc *crtc)
*
* Call drm_virtual_plane_destroy to clean up the plane.
*
* @param b DRM compositor backend
* @param device DRM device
* @param output Output to create internal plane for
*/
static struct drm_plane *
drm_virtual_plane_create(struct drm_backend *b, struct drm_output *output)
drm_virtual_plane_create(struct drm_device *device, struct drm_output *output)
{
struct drm_backend *b = device->backend;
struct drm_plane *plane;
struct weston_drm_format *fmt;
uint64_t mod;
......@@ -103,7 +104,7 @@ drm_virtual_plane_create(struct drm_backend *b, struct drm_output *output)
}
plane->type = WDRM_PLANE_TYPE_PRIMARY;
plane->backend = b;
plane->device = device;
plane->state_cur = drm_plane_state_alloc(NULL, plane);
plane->state_cur->complete = true;
......@@ -115,7 +116,7 @@ drm_virtual_plane_create(struct drm_backend *b, struct drm_output *output)
/* If output supports linear modifier, we add it to the plane.
* Otherwise we add DRM_FORMAT_MOD_INVALID, as explicit modifiers
* are not supported. */
if ((output->gbm_bo_flags & GBM_BO_USE_LINEAR) && b->fb_modifiers)
if ((output->gbm_bo_flags & GBM_BO_USE_LINEAR) && device->fb_modifiers)
mod = DRM_FORMAT_MOD_LINEAR;
else
mod = DRM_FORMAT_MOD_INVALID;
......@@ -124,7 +125,7 @@ drm_virtual_plane_create(struct drm_backend *b, struct drm_output *output)
goto err;
weston_plane_init(&plane->base, b->compositor, 0, 0);
wl_list_insert(&b->plane_list, &plane->link);
wl_list_insert(&device->plane_list, &plane->link);
return plane;
......@@ -163,11 +164,10 @@ static int
drm_virtual_output_submit_frame(struct drm_output *output,
struct drm_fb *fb)
{
struct drm_backend *b = to_drm_backend(output->base.compositor);
int fd, ret;
assert(fb->num_planes == 1);
ret = drmPrimeHandleToFD(b->drm.fd, fb->handles[0], DRM_CLOEXEC, &fd);
ret = drmPrimeHandleToFD(fb->fd, fb->handles[0], DRM_CLOEXEC, &fd);
if (ret) {
weston_log("drmPrimeHandleFD failed, errno=%d\n", errno);
return -1;
......@@ -192,12 +192,12 @@ drm_virtual_output_repaint(struct weston_output *output_base,
struct drm_plane *scanout_plane = output->scanout_plane;
struct drm_plane_state *scanout_state;
struct drm_pending_state *pending_state;
struct drm_backend *backend;
struct drm_device *device;
assert(output->virtual);
backend = output->backend;
pending_state = backend->repaint_data;
device = output->device;
pending_state = device->repaint_data;
if (output->disable_pending || output->destroy_pending)
goto err;
......@@ -266,7 +266,8 @@ static int
drm_virtual_output_enable(struct weston_output *output_base)
{
struct drm_output *output = to_drm_output(output_base);
struct drm_backend *b = to_drm_backend(output_base->compositor);
struct drm_device *device = output->device;
struct drm_backend *b = device->backend;
assert(output->virtual);
......@@ -280,7 +281,7 @@ drm_virtual_output_enable(struct weston_output *output_base)
goto err;
}
output->scanout_plane = drm_virtual_plane_create(b, output);
output->scanout_plane = drm_virtual_plane_create(device, output);
if (!output->scanout_plane) {
weston_log("Failed to find primary plane for output %s\n",
output->base.name);
......@@ -327,19 +328,21 @@ drm_virtual_output_create(struct weston_compositor *c, char *name)
{
struct drm_output *output;
struct drm_backend *b = to_drm_backend(c);
/* Always use the main device for virtual outputs */
struct drm_device *device = b->drm;
output = zalloc(sizeof *output);
if (!output)
return NULL;
output->crtc = drm_virtual_crtc_create(b, output);
output->device = device;
output->crtc = drm_virtual_crtc_create(device, output);
if (!output->crtc) {
free(output);
return NULL;
}
output->virtual = true;
output->backend = b;
output->gbm_bo_flags = GBM_BO_USE_LINEAR | GBM_BO_USE_RENDERING;
weston_output_init(&output->base, c, name);
......@@ -361,7 +364,8 @@ drm_virtual_output_set_gbm_format(struct weston_output *base,
const char *gbm_format)
{
struct drm_output *output = to_drm_output(base);
struct drm_backend *b = to_drm_backend(base->compositor);
struct drm_device *device = output->device;
struct drm_backend *b = device->backend;
if (parse_gbm_format(gbm_format, b->gbm_format, &output->gbm_format) == -1)
output->gbm_format = b->gbm_format;
......
This diff is collapsed.
......@@ -69,7 +69,7 @@ drm_fb_destroy_dumb(struct drm_fb *fb)
}
static int
drm_fb_addfb(struct drm_backend *b, struct drm_fb *fb)
drm_fb_addfb(struct drm_device *device, struct drm_fb *fb)
{
int ret = -EINVAL;
uint64_t mods[4] = { };
......@@ -77,7 +77,7 @@ drm_fb_addfb(struct drm_backend *b, struct drm_fb *fb)
/* If we have a modifier set, we must only use the WithModifiers
* entrypoint; we cannot import it through legacy ioctls. */
if (b->fb_modifiers && fb->modifier != DRM_FORMAT_MOD_INVALID) {
if (device->fb_modifiers && fb->modifier != DRM_FORMAT_MOD_INVALID) {
/* KMS demands that if a modifier is set, it must be the same
* for all planes. */
for (i = 0; i < ARRAY_LENGTH(mods) && fb->handles[i]; i++)
......@@ -112,7 +112,7 @@ drm_fb_addfb(struct drm_backend *b, struct drm_fb *fb)
}
struct drm_fb *
drm_fb_create_dumb(struct drm_backend *b, int width, int height,
drm_fb_create_dumb(struct drm_device *device, int width, int height,
uint32_t format)
{
struct drm_fb *fb;
......@@ -145,7 +145,7 @@ drm_fb_create_dumb(struct drm_backend *b, int width, int height,
create_arg.width = width;
create_arg.height = height;
ret = drmIoctl(b->drm.fd, DRM_IOCTL_MODE_CREATE_DUMB, &create_arg);
ret = drmIoctl(device->drm.fd, DRM_IOCTL_MODE_CREATE_DUMB, &create_arg);
if (ret)
goto err_fb;
......@@ -157,9 +157,9 @@ drm_fb_create_dumb(struct drm_backend *b, int width, int height,
fb->size = create_arg.size;
fb->width = width;
fb->height = height;
fb->fd = b->drm.fd;
fb->fd = device->drm.fd;
if (drm_fb_addfb(b, fb) != 0) {
if (drm_fb_addfb(device, fb) != 0) {
weston_log("failed to create kms fb: %s\n", strerror(errno));
goto err_bo;
}
......@@ -171,18 +171,18 @@ drm_fb_create_dumb(struct drm_backend *b, int width, int height,
goto err_add_fb;
fb->map = mmap(NULL, fb->size, PROT_WRITE,
MAP_SHARED, b->drm.fd, map_arg.offset);
MAP_SHARED, device->drm.fd, map_arg.offset);
if (fb->map == MAP_FAILED)
goto err_add_fb;
return fb;
err_add_fb:
drmModeRmFB(b->drm.fd, fb->fb_id);
drmModeRmFB(device->drm.fd, fb->fb_id);
err_bo:
memset(&destroy_arg, 0, sizeof(destroy_arg));
destroy_arg.handle = create_arg.handle;
drmIoctl(b->drm.fd, DRM_IOCTL_MODE_DESTROY_DUMB, &destroy_arg);
drmIoctl(device->drm.fd, DRM_IOCTL_MODE_DESTROY_DUMB, &destroy_arg);
err_fb:
free(fb);
return NULL;
......@@ -218,7 +218,7 @@ drm_fb_destroy_dmabuf(struct drm_fb *fb)
static struct drm_fb *
drm_fb_get_from_dmabuf(struct linux_dmabuf_buffer *dmabuf,
struct drm_backend *backend, bool is_opaque,
struct drm_device *device, bool is_opaque,
uint32_t *try_view_on_plane_failure_reasons)
{
#ifndef HAVE_GBM_FD_IMPORT
......@@ -227,6 +227,7 @@ drm_fb_get_from_dmabuf(struct linux_dmabuf_buffer *dmabuf,
* of GBM_BO_IMPORT_FD_MODIFIER. */
return NULL;
#else
struct drm_backend *backend = device->backend;
struct drm_fb *fb;
int i;
struct gbm_import_fd_modifier_data import_mod = {
......@@ -287,7 +288,7 @@ drm_fb_get_from_dmabuf(struct linux_dmabuf_buffer *dmabuf,
fb->height = dmabuf->attributes.height;
fb->modifier = dmabuf->attributes.modifier[0];
fb->size = 0;
fb->fd = backend->drm.fd;
fb->fd = device->drm.fd;
ARRAY_COPY(fb->strides, dmabuf->attributes.stride);
ARRAY_COPY(fb->offsets, dmabuf->attributes.offset);
......@@ -302,10 +303,10 @@ drm_fb_get_from_dmabuf(struct linux_dmabuf_buffer *dmabuf,
if (is_opaque)
fb->format = pixel_format_get_opaque_substitute(fb->format);
if (backend->min_width > fb->width ||
fb->width > backend->max_width ||
backend->min_height > fb->height ||
fb->height > backend->max_height) {
if (device->min_width > fb->width ||
fb->width > device->max_width ||
device->min_height > fb->height ||
fb->height > device->max_height) {
weston_log("bo geometry out of bounds\n");
goto err_free;
}
......@@ -323,7 +324,7 @@ drm_fb_get_from_dmabuf(struct linux_dmabuf_buffer *dmabuf,
fb->handles[i] = handle.u32;
}
if (drm_fb_addfb(backend, fb) != 0) {
if (drm_fb_addfb(device, fb) != 0) {
if (try_view_on_plane_failure_reasons)
*try_view_on_plane_failure_reasons |=
FAILURE_REASONS_ADD_FB_FAILED;
......@@ -339,7 +340,7 @@ err_free:
}
struct drm_fb *
drm_fb_get_from_bo(struct gbm_bo *bo, struct drm_backend *backend,
drm_fb_get_from_bo(struct gbm_bo *bo, struct drm_device *device,
bool is_opaque, enum drm_fb_type type)
{
struct drm_fb *fb = gbm_bo_get_user_data(bo);
......@@ -359,7 +360,7 @@ drm_fb_get_from_bo(struct gbm_bo *bo, struct drm_backend *backend,
fb->type = type;
fb->refcnt = 1;
fb->bo = bo;
fb->fd = backend->drm.fd;
fb->fd = device->drm.fd;
fb->width = gbm_bo_get_width(bo);
fb->height = gbm_bo_get_height(bo);
......@@ -392,15 +393,15 @@ drm_fb_get_from_bo(struct gbm_bo *bo, struct drm_backend *backend,
if (is_opaque)
fb->format = pixel_format_get_opaque_substitute(fb->format);
if (backend->min_width > fb->width ||
fb->width > backend->max_width ||
backend->min_height > fb->height ||
fb->height > backend->max_height) {
if (device->min_width > fb->width ||
fb->width > device->max_width ||
device->min_height > fb->height ||
fb->height > device->max_height) {
weston_log("bo geometry out of bounds\n");
goto err_free;
}
if (drm_fb_addfb(backend, fb) != 0) {
if (drm_fb_addfb(device, fb) != 0) {
if (type == BUFFER_GBM_SURFACE)
weston_log("failed to create kms fb: %s\n",
strerror(errno));
......@@ -456,10 +457,11 @@ drm_can_scanout_dmabuf(struct weston_compositor *ec,
{
struct drm_fb *fb;
struct drm_backend *b = to_drm_backend(ec);
struct drm_device *device = b->drm;
bool ret = false;
uint32_t try_reason = 0x0;
fb = drm_fb_get_from_dmabuf(dmabuf, b, true, &try_reason);
fb = drm_fb_get_from_dmabuf(dmabuf, device, true, &try_reason);
if (fb)
ret = true;
......@@ -472,7 +474,8 @@ drm_can_scanout_dmabuf(struct weston_compositor *ec,
static bool
drm_fb_compatible_with_plane(struct drm_fb *fb, struct drm_plane *plane)
{
struct drm_backend *b = plane->backend;
struct drm_device *device = plane->device;
struct drm_backend *b = device->backend;
struct weston_drm_format *fmt;
/* Check whether the format is supported */
......@@ -529,6 +532,7 @@ drm_fb_get_from_view(struct drm_output_state *state, struct weston_view *ev,
{
struct drm_output *output = state->output;
struct drm_backend *b = to_drm_backend(output->base.compositor);
struct drm_device *device = output->device;
struct weston_buffer *buffer = ev->surface->buffer_ref.buffer;
struct drm_buffer_fb *buf_fb;
bool is_opaque = weston_view_is_opaque(ev, &ev->transform.boundingbox);
......@@ -577,7 +581,7 @@ drm_fb_get_from_view(struct drm_output_state *state, struct weston_view *ev,
}
if (buffer->type == WESTON_BUFFER_DMABUF) {
fb = drm_fb_get_from_dmabuf(buffer->dmabuf, b, is_opaque,
fb = drm_fb_get_from_dmabuf(buffer->dmabuf, device, is_opaque,
&buf_fb->failure_reasons);
if (!fb)
goto unsuitable;
......@@ -589,7 +593,7 @@ drm_fb_get_from_view(struct drm_output_state *state, struct weston_view *ev,
if (!bo)
goto unsuitable;
fb = drm_fb_get_from_bo(bo, b, is_opaque, BUFFER_CLIENT);
fb = drm_fb_get_from_bo(bo, device, is_opaque, BUFFER_CLIENT);
if (!fb) {
*try_view_on_plane_failure_reasons |=
(1 << FAILURE_REASONS_ADD_FB_FAILED);
......@@ -603,7 +607,7 @@ drm_fb_get_from_view(struct drm_output_state *state, struct weston_view *ev,
/* Check if this buffer can ever go on any planes. If it can't, we have
* no reason to ever have a drm_fb, so we fail it here. */
wl_list_for_each(plane, &b->plane_list, link) {
wl_list_for_each(plane, &device->plane_list, link) {
/* only SHM buffers can go into cursor planes */
if (plane->type == WDRM_PLANE_TYPE_CURSOR)
continue;
......
......@@ -108,6 +108,7 @@ weston_hdr_metadata_type1_to_kms(struct hdr_metadata_infoframe *dst,
int
drm_output_ensure_hdr_output_metadata_blob(struct drm_output *output)
{
struct drm_device *device = output->device;
const struct weston_hdr_metadata_type1 *src;
struct hdr_output_metadata meta;
uint32_t blob_id = 0;
......@@ -160,7 +161,7 @@ drm_output_ensure_hdr_output_metadata_blob(struct drm_output *output)
return -1;
}
ret = drmModeCreatePropertyBlob(output->backend->drm.fd,
ret = drmModeCreatePropertyBlob(device->drm.fd,
&meta, sizeof meta, &blob_id);
if (ret != 0) {
weston_log("Error: failed to create KMS blob for HDR metadata on output '%s': %s\n",
......@@ -168,7 +169,7 @@ drm_output_ensure_hdr_output_metadata_blob(struct drm_output *output)
return -1;
}
drmModeDestroyPropertyBlob(output->backend->drm.fd,
drmModeDestroyPropertyBlob(device->drm.fd,
output->hdr_output_metadata_blob_id);
output->hdr_output_metadata_blob_id = blob_id;
......
This diff is collapsed.
......@@ -98,14 +98,15 @@ drm_subpixel_to_wayland(int drm_value)
}
int
drm_mode_ensure_blob(struct drm_backend *backend, struct drm_mode *mode)
drm_mode_ensure_blob(struct drm_device *device, struct drm_mode *mode)
{
struct drm_backend *backend = device->backend;
int ret;
if (mode->blob_id)
return 0;
ret = drmModeCreatePropertyBlob(backend->drm.fd,
ret = drmModeCreatePropertyBlob(device->drm.fd,
&mode->mode_info,
sizeof(mode->mode_info),
&mode->blob_id);
......@@ -320,6 +321,7 @@ find_and_parse_output_edid(struct drm_head *head,
const char **serial_number,
uint32_t *eotf_mask)
{
struct drm_device *device = head->connector.device;
drmModePropertyBlobPtr edid_blob = NULL;
uint32_t blob_id;
int rc;
......@@ -331,7 +333,7 @@ find_and_parse_output_edid(struct drm_head *head,
if (!blob_id)
return;
edid_blob = drmModeGetPropertyBlob(head->backend->drm.fd, blob_id);
edid_blob = drmModeGetPropertyBlob(device->drm.fd, blob_id);
if (!edid_blob)
return;
......@@ -360,7 +362,7 @@ prune_eotf_modes_by_kms_support(struct drm_head *head, uint32_t *eotf_mask)
/* Without the KMS property, cannot do anything but SDR. */
info = &head->connector.props[WDRM_CONNECTOR_HDR_OUTPUT_METADATA];
if (!head->backend->atomic_modeset || info->prop_id == 0)
if (!head->connector.device->atomic_modeset || info->prop_id == 0)
*eotf_mask = WESTON_EOTF_MODE_SDR;
}
......@@ -424,26 +426,26 @@ drm_output_add_mode(struct drm_output *output, const drmModeModeInfo *info)
* Destroys a mode, and removes it from the list.
*/
static void
drm_output_destroy_mode(struct drm_backend *backend, struct drm_mode *mode)
drm_output_destroy_mode(struct drm_device *device, struct drm_mode *mode)
{
if (mode->blob_id)
drmModeDestroyPropertyBlob(backend->drm.fd, mode->blob_id);
drmModeDestroyPropertyBlob(device->drm.fd, mode->blob_id);
wl_list_remove(&mode->base.link);
free(mode);
}
/** Destroy a list of drm_modes
*
* @param backend The backend for releasing mode property blobs.
* @param device The device for releasing mode property blobs.
* @param mode_list The list linked by drm_mode::base.link.
*/
void
drm_mode_list_destroy(struct drm_backend *backend, struct wl_list *mode_list)
drm_mode_list_destroy(struct drm_device *device, struct wl_list *mode_list)
{
struct drm_mode *mode, *next;
wl_list_for_each_safe(mode, next, mode_list, base.link)
drm_output_destroy_mode(backend, mode);
drm_output_destroy_mode(device, mode);
}
void
......@@ -487,16 +489,16 @@ drm_output_choose_mode(struct drm_output *output,
struct drm_mode *tmp_mode = NULL, *mode_fall_back = NULL, *mode;
enum weston_mode_aspect_ratio src_aspect = WESTON_MODE_PIC_AR_NONE;
enum weston_mode_aspect_ratio target_aspect = WESTON_MODE_PIC_AR_NONE;
struct drm_backend *b;
struct drm_device *device;
b = to_drm_backend(output->base.compositor);
device = output->device;
target_aspect = target_mode->aspect_ratio;
src_aspect = output->base.current_mode->aspect_ratio;
if (output->base.current_mode->width == target_mode->width &&
output->base.current_mode->height == target_mode->height &&
(output->base.current_mode->refresh == target_mode->refresh ||
target_mode->refresh == 0)) {
if (!b->aspect_ratio_supported || src_aspect == target_aspect)
if (!device->aspect_ratio_supported || src_aspect == target_aspect)
return to_drm_mode(output->base.current_mode);
}
......@@ -507,7 +509,7 @@ drm_output_choose_mode(struct drm_output *output,
mode->mode_info.vdisplay == target_mode->height) {
if (mode->base.refresh == target_mode->refresh ||
target_mode->refresh == 0) {
if (!b->aspect_ratio_supported ||
if (!device->aspect_ratio_supported ||
src_aspect == target_aspect)
return mode;
else if (!mode_fall_back)
......@@ -560,7 +562,7 @@ update_head_from_connector(struct drm_head *head)
* Find the most suitable mode to use for initial setup (or reconfiguration on
* hotplug etc) for a DRM output.
*
* @param backend the DRM backend
* @param device the DRM device
* @param output DRM output to choose mode for
* @param mode Strategy and preference to use when choosing mode
* @param modeline Manually-entered mode (may be NULL)
......@@ -568,7 +570,7 @@ update_head_from_connector(struct drm_head *head)
* @returns A mode from the output's mode list, or NULL if none available
*/
static struct drm_mode *
drm_output_choose_initial_mode(struct drm_backend *backend,
drm_output_choose_initial_mode(struct drm_device *device,
struct drm_output *output,
enum weston_drm_backend_output_mode mode,
const char *modeline,
......@@ -592,7 +594,7 @@ drm_output_choose_initial_mode(struct drm_backend *backend,
if (mode == WESTON_DRM_BACKEND_OUTPUT_PREFERRED && modeline) {
n = sscanf(modeline, "%dx%d@%d %u:%u", &width, &height,
&refresh, &aspect_width, &aspect_height);
if (backend->aspect_ratio_supported && n == 5) {
if (device->aspect_ratio_supported && n == 5) {
if (aspect_width == 4 && aspect_height == 3)
aspect_ratio = WESTON_MODE_PIC_AR_4_3;
else if (aspect_width == 16 && aspect_height == 9)
......@@ -623,7 +625,7 @@ drm_output_choose_initial_mode(struct drm_backend *backend,
if (width == drm_mode->base.width &&
height == drm_mode->base.height &&
(refresh == 0 || refresh == drm_mode->mode_info.vrefresh)) {
if (!backend->aspect_ratio_supported ||
if (!device->aspect_ratio_supported ||
aspect_ratio == drm_mode->base.aspect_ratio)
configured = drm_mode;
else
......@@ -735,7 +737,7 @@ drm_output_try_add_mode(struct drm_output *output, const drmModeModeInfo *info)
{
struct weston_mode *base;
struct drm_mode *mode = NULL;
struct drm_backend *backend;
struct drm_device *device = output->device;
const drmModeModeInfo *chosen = NULL;
assert(info);
......@@ -749,8 +751,7 @@ drm_output_try_add_mode(struct drm_output *output, const drmModeModeInfo *info)
if (chosen == info) {
assert(mode);
backend = to_drm_backend(output->base.compositor);
drm_output_destroy_mode(backend, mode);
drm_output_destroy_mode(device, mode);
chosen = NULL;
}
......@@ -777,7 +778,7 @@ drm_output_try_add_mode(struct drm_output *output, const drmModeModeInfo *info)
static int
drm_output_update_modelist_from_heads(struct drm_output *output)
{
struct drm_backend *backend = to_drm_backend(output->base.compositor);
struct drm_device *device = output->device;
struct weston_head *head_base;
struct drm_head *head;
drmModeConnector *conn;
......@@ -786,7 +787,7 @@ drm_output_update_modelist_from_heads(struct drm_output *output)
assert(!output->base.enabled);
drm_mode_list_destroy(backend, &output->base.mode_list);
drm_mode_list_destroy(device, &output->base.mode_list);
wl_list_for_each(head_base, &output->base.head_list, output_link) {
head = to_drm_head(head_base);
......@@ -807,7 +808,7 @@ drm_output_set_mode(struct weston_output *base,
const char *modeline)
{
struct drm_output *output = to_drm_output(base);
struct drm_backend *b = to_drm_backend(base->compositor);
struct drm_device *device = output->device;
struct drm_head *head = to_drm_head(weston_output_get_first_head(base));
struct drm_mode *current;
......@@ -818,7 +819,7 @@ drm_output_set_mode(struct weston_output *base,
if (drm_output_update_modelist_from_heads(output) < 0)
return -1;
current = drm_output_choose_initial_mode(b, output, mode, modeline,
current = drm_output_choose_initial_mode(device, output, mode, modeline,
&head->inherited_mode);
if (!current)
return -1;
......
......@@ -73,6 +73,8 @@ drm_plane_state_alloc(struct drm_output_state *state_output,
void
drm_plane_state_free(struct drm_plane_state *state, bool force)
{
struct drm_device *device;
if (!state)
return;
......@@ -86,7 +88,9 @@ drm_plane_state_free(struct drm_plane_state *state, bool force)
* by the kernel, which means we can safely discard it.
*/
if (state->damage_blob_id != 0) {
drmModeDestroyPropertyBlob(state->plane->backend->drm.fd,
device = state->plane->device;
drmModeDestroyPropertyBlob(device->drm.fd,
state->damage_blob_id);
state->damage_blob_id = 0;
}
......@@ -432,11 +436,11 @@ drm_output_state_free(struct drm_output_state *state)
* Allocate a new, empty, 'pending state' structure to be used across a
* repaint cycle or similar.
*
* @param backend DRM backend
* @param device DRM device
* @returns Newly-allocated pending state structure
*/
struct drm_pending_state *
drm_pending_state_alloc(struct drm_backend *backend)
drm_pending_state_alloc(struct drm_device *device)
{
struct drm_pending_state *ret;
......@@ -444,7 +448,7 @@ drm_pending_state_alloc(struct drm_backend *backend)
if (!ret)
return NULL;
ret->backend = backend;
ret->device = device;
wl_list_init(&ret->output_list);
return ret;
......
......@@ -83,13 +83,13 @@ drm_output_try_view_on_plane(struct drm_plane *plane,
struct drm_fb *fb, uint64_t zpos)
{
struct drm_output *output = output_state->output;
struct weston_compositor *ec = output->base.compositor;
struct weston_surface *surface = ev->surface;
struct drm_backend *b = to_drm_backend(ec);
struct drm_device *device = output->device;
struct drm_backend *b = device->backend;
struct drm_plane_state *state = NULL;
assert(!b->sprites_are_broken);
assert(b->atomic_modeset);
assert(!device->sprites_are_broken);
assert(device->atomic_modeset);
assert(fb);
assert(mode == DRM_OUTPUT_PROPOSE_STATE_PLANES_ONLY ||
(mode == DRM_OUTPUT_PROPOSE_STATE_MIXED &&
......@@ -161,17 +161,18 @@ out:
static void
cursor_bo_update(struct drm_plane_state *plane_state, struct weston_view *ev)
{
struct drm_backend *b = plane_state->plane->backend;
struct drm_output *output = plane_state->output;
struct drm_device *device = output->device;
struct gbm_bo *bo = plane_state->fb->bo;
struct weston_buffer *buffer = ev->surface->buffer_ref.buffer;
uint32_t buf[b->cursor_width * b->cursor_height];
uint32_t buf[device->cursor_width * device->cursor_height];
int32_t stride;
uint8_t *s;
int i;
assert(buffer && buffer->shm_buffer);
assert(buffer->width <= b->cursor_width);
assert(buffer->height <= b->cursor_height);
assert(buffer->width <= device->cursor_width);
assert(buffer->height <= device->cursor_height);
memset(buf, 0, sizeof buf);
stride = wl_shm_buffer_get_stride(buffer->shm_buffer);
......@@ -179,7 +180,7 @@ cursor_bo_update(struct drm_plane_state *plane_state, struct weston_view *ev)
wl_shm_buffer_begin_access(buffer->shm_buffer);
for (i = 0; i < buffer->height; i++)
memcpy(buf + i * b->cursor_width,
memcpy(buf + i * device->cursor_width,
s + i * stride,
buffer->width * 4);
wl_shm_buffer_end_access(buffer->shm_buffer);
......@@ -193,13 +194,14 @@ drm_output_prepare_cursor_view(struct drm_output_state *output_state,
struct weston_view *ev, uint64_t zpos)
{
struct drm_output *output = output_state->output;
struct drm_backend *b = to_drm_backend(output->base.compositor);
struct drm_device *device = output->device;
struct drm_backend *b = device->backend;
struct drm_plane *plane = output->cursor_plane;
struct drm_plane_state *plane_state;
bool needs_update = false;
const char *p_name = drm_output_get_plane_type_name(plane);
assert(!b->cursors_are_broken);
assert(!device->cursors_are_broken);
assert(plane);
assert(plane->state_cur->complete);
assert(!plane->state_cur->output || plane->state_cur->output == output);
......@@ -220,8 +222,8 @@ drm_output_prepare_cursor_view(struct drm_output_state *output_state,
}
if (plane_state->src_x != 0 || plane_state->src_y != 0 ||
plane_state->src_w > (unsigned) b->cursor_width << 16 ||
plane_state->src_h > (unsigned) b->cursor_height << 16 ||
plane_state->src_w > (unsigned) device->cursor_width << 16 ||
plane_state->src_h > (unsigned) device->cursor_height << 16 ||
plane_state->src_w != plane_state->dest_w << 16 ||
plane_state->src_h != plane_state->dest_h << 16) {
drm_debug(b, "\t\t\t\t[%s] not assigning view %p to %s plane "
......@@ -260,10 +262,10 @@ drm_output_prepare_cursor_view(struct drm_output_state *output_state,
* a buffer which is always cursor_width x cursor_height, even if the
* surface we want to promote is actually smaller than this. Manually
* mangle the plane state to deal with this. */
plane_state->src_w = b->cursor_width << 16;
plane_state->src_h = b->cursor_height << 16;
plane_state->dest_w = b->cursor_width;
plane_state->dest_h = b->cursor_height;
plane_state->src_w = device->cursor_width << 16;
plane_state->src_h = device->cursor_height << 16;
plane_state->dest_w = device->cursor_width;
plane_state->dest_h = device->cursor_height;
drm_debug(b, "\t\t\t\t[%s] provisionally assigned view %p to cursor\n",
p_name, ev);
......@@ -323,12 +325,13 @@ drm_output_check_zpos_plane_states(struct drm_output_state *state)
}
static bool
dmabuf_feedback_maybe_update(struct drm_backend *b, struct weston_view *ev,
dmabuf_feedback_maybe_update(struct drm_device *device, struct weston_view *ev,
uint32_t try_view_on_plane_failure_reasons)
{
struct weston_dmabuf_feedback *dmabuf_feedback = ev->surface->dmabuf_feedback;
struct weston_dmabuf_feedback_tranche *scanout_tranche;
dev_t scanout_dev = b->drm.devnum;
struct drm_backend *b = device->backend;
dev_t scanout_dev = device->drm.devnum;
uint32_t scanout_flags = ZWP_LINUX_DMABUF_FEEDBACK_V1_TRANCHE_FLAGS_SCANOUT;
uint32_t action_needed = ACTION_NEEDED_NONE;
struct timespec current_time, delta_time;
......@@ -427,7 +430,8 @@ drm_output_find_plane_for_view(struct drm_output_state *state,
uint64_t current_lowest_zpos)
{
struct drm_output *output = state->output;
struct drm_backend *b = to_drm_backend(output->base.compositor);
struct drm_device *device = output->device;
struct drm_backend *b = device->backend;
struct drm_plane_state *ps = NULL;
struct drm_plane *plane;
......@@ -454,7 +458,7 @@ drm_output_find_plane_for_view(struct drm_output_state *state,
FAILURE_REASONS_FB_FORMAT_INCOMPATIBLE;
return NULL;
} else if (buffer->type == WESTON_BUFFER_SHM) {
if (!output->cursor_plane || b->cursors_are_broken) {
if (!output->cursor_plane || device->cursors_are_broken) {
pnode->try_view_on_plane_failure_reasons |=
FAILURE_REASONS_FB_FORMAT_INCOMPATIBLE;
return NULL;
......@@ -471,8 +475,8 @@ drm_output_find_plane_for_view(struct drm_output_state *state,
return NULL;
}
if (buffer->width > b->cursor_width ||
buffer->height > b->cursor_height) {
if (buffer->width > device->cursor_width ||
buffer->height > device->cursor_height) {
drm_debug(b, "\t\t\t\t[view] not assigning view %p to plane "
"(buffer (%dx%d) too large for cursor plane)\n",
ev, buffer->width, buffer->height);
......@@ -507,7 +511,7 @@ drm_output_find_plane_for_view(struct drm_output_state *state,
state);
/* assemble a list with possible candidates */
wl_list_for_each(plane, &b->plane_list, link) {
wl_list_for_each(plane, &device->plane_list, link) {
const char *p_name = drm_output_get_plane_type_name(plane);
uint64_t zpos;
......@@ -632,7 +636,8 @@ drm_output_propose_state(struct weston_output *output_base,
enum drm_output_propose_state_mode mode)
{
struct drm_output *output = to_drm_output(output_base);
struct drm_backend *b = to_drm_backend(output->base.compositor);
struct drm_device *device = output->device;
struct drm_backend *b = device->backend;
struct weston_paint_node *pnode;
struct drm_output_state *state;
struct drm_plane_state *scanout_state = NULL;
......@@ -911,9 +916,10 @@ err:
void
drm_assign_planes(struct weston_output *output_base)
{
struct drm_backend *b = to_drm_backend(output_base->compositor);
struct drm_pending_state *pending_state = b->repaint_data;
struct drm_output *output = to_drm_output(output_base);
struct drm_device *device = output->device;
struct drm_backend *b = device->backend;
struct drm_pending_state *pending_state = device->repaint_data;
struct drm_output_state *state = NULL;
struct drm_plane_state *plane_state;
struct weston_paint_node *pnode;
......@@ -923,7 +929,7 @@ drm_assign_planes(struct weston_output *output_base)
drm_debug(b, "\t[repaint] preparing state for output %s (%lu)\n",
output_base->name, (unsigned long) output_base->id);
if (!b->sprites_are_broken && !output->virtual && b->gbm) {
if (!device->sprites_are_broken && !output->virtual && b->gbm) {
drm_debug(b, "\t[repaint] trying planes-only build state\n");
state = drm_output_propose_state(output_base, pending_state, mode);
if (!state) {
......@@ -965,7 +971,7 @@ drm_assign_planes(struct weston_output *output_base)
/* Update dmabuf-feedback if needed */
if (ev->surface->dmabuf_feedback)
dmabuf_feedback_maybe_update(b, ev,
dmabuf_feedback_maybe_update(device, ev,
pnode->try_view_on_plane_failure_reasons);
pnode->try_view_on_plane_failure_reasons = FAILURE_REASONS_NONE;
......@@ -985,8 +991,8 @@ drm_assign_planes(struct weston_output *output_base)
buffer->type == WESTON_BUFFER_RENDERER_OPAQUE)
ev->surface->keep_buffer = true;
else if (buffer->type == WESTON_BUFFER_SHM &&
(ev->surface->width <= b->cursor_width &&
ev->surface->height <= b->cursor_height))
(ev->surface->width <= device->cursor_width &&
ev->surface->height <= device->cursor_height))
ev->surface->keep_buffer = true;
}
......