[RFC weston 06/14] compositor-drm: Rename drm_sprite to drm_plane
Daniel Stone
daniels at collabora.com
Thu May 21 00:29:03 PDT 2015
We make the differentiation where planes are an abstract framebuffer
with a position within a CRTC/output, and sprites are special cases of
planes that are neither the primary (base/framebuffer) nor cursor plane.
drm_sprite, OTOH, contains nothing that's actually specific to sprites,
and we end up duplicating a lot of code to deal with them, especially
when we come to use an entirely plane-based interface with atomic
modesetting.
Rename drm_sprite to drm_plane, to reflect that it's actually generic.
No functional changes.
Signed-off-by: Daniel Stone <daniels at collabora.com>
---
src/compositor-drm.c | 179 +++++++++++++++++++++++++++------------------------
1 file changed, 95 insertions(+), 84 deletions(-)
diff --git a/src/compositor-drm.c b/src/compositor-drm.c
index 038bafc..15ecec2 100644
--- a/src/compositor-drm.c
+++ b/src/compositor-drm.c
@@ -153,6 +153,42 @@ struct drm_edid {
char serial_number[13];
};
+/**
+ * A plane represents one buffer, positioned within a CRTC, and stacked
+ * relative to other planes on the same CRTC.
+ *
+ * Each CRTC has a 'primary plane', which use used to display the classic
+ * framebuffer contents, as accessed through the legacy drmModeSetCrtc
+ * call (which combines setting the CRTC's actual physical mode, and the
+ * properties of the primary plane).
+ *
+ * The cursor plane also has its own alternate legacy API.
+ *
+ * Other planes are used opportunistically to display content we do not
+ * wish to blit into the primary plane. These non-primary/cursor planes
+ * are referred to as 'sprites'.
+ */
+struct drm_plane {
+ struct wl_list link;
+
+ struct weston_plane base;
+
+ struct drm_fb *current, *next;
+ struct drm_output *output;
+ struct drm_compositor *compositor;
+
+ uint32_t possible_crtcs;
+ uint32_t plane_id;
+ uint32_t count_formats;
+
+ int32_t src_x, src_y;
+ uint32_t src_w, src_h;
+ uint32_t dest_x, dest_y;
+ uint32_t dest_w, dest_h;
+
+ uint32_t formats[];
+};
+
struct drm_output {
struct weston_output base;
@@ -186,31 +222,6 @@ struct drm_output {
struct wl_listener recorder_frame_listener;
};
-/*
- * An output has a primary display plane plus zero or more sprites for
- * blending display contents.
- */
-struct drm_sprite {
- struct wl_list link;
-
- struct weston_plane plane;
-
- struct drm_fb *current, *next;
- struct drm_output *output;
- struct drm_compositor *compositor;
-
- uint32_t possible_crtcs;
- uint32_t plane_id;
- uint32_t count_formats;
-
- int32_t src_x, src_y;
- uint32_t src_w, src_h;
- uint32_t dest_x, dest_y;
- uint32_t dest_w, dest_h;
-
- uint32_t formats[];
-};
-
struct drm_parameters {
int connector;
int tty;
@@ -226,7 +237,7 @@ static void
drm_output_set_cursor(struct drm_output *output);
static int
-drm_sprite_crtc_supported(struct drm_output *output, uint32_t supported)
+drm_plane_crtc_supported(struct drm_output *output, uint32_t supported)
{
struct weston_compositor *ec = output->base.compositor;
struct drm_compositor *c = (struct drm_compositor *)ec;
@@ -600,7 +611,7 @@ drm_output_repaint(struct weston_output *output_base,
struct drm_output *output = (struct drm_output *) output_base;
struct drm_compositor *compositor =
(struct drm_compositor *) output->base.compositor;
- struct drm_sprite *s;
+ struct drm_plane *s;
struct drm_mode *mode;
int ret = 0;
@@ -648,7 +659,7 @@ drm_output_repaint(struct weston_output *output_base,
};
if ((!s->current && !s->next) ||
- !drm_sprite_crtc_supported(output, s->possible_crtcs))
+ !drm_plane_crtc_supported(output, s->possible_crtcs))
continue;
if (s->next && !compositor->sprites_hidden)
@@ -743,7 +754,7 @@ static void
vblank_handler(int fd, unsigned int frame, unsigned int sec, unsigned int usec,
void *data)
{
- struct drm_sprite *s = (struct drm_sprite *)data;
+ struct drm_plane *s = (struct drm_plane *)data;
struct drm_output *output = s->output;
struct timespec ts;
uint32_t flags = PRESENTATION_FEEDBACK_KIND_HW_COMPLETION |
@@ -804,7 +815,7 @@ page_flip_handler(int fd, unsigned int frame,
}
static uint32_t
-drm_output_check_sprite_format(struct drm_sprite *s,
+drm_output_check_plane_format(struct drm_plane *p,
struct weston_view *ev, struct gbm_bo *bo)
{
uint32_t i, format;
@@ -825,8 +836,8 @@ drm_output_check_sprite_format(struct drm_sprite *s,
pixman_region32_fini(&r);
}
- for (i = 0; i < s->count_formats; i++)
- if (s->formats[i] == format)
+ for (i = 0; i < p->count_formats; i++)
+ if (p->formats[i] == format)
return format;
return 0;
@@ -846,7 +857,7 @@ drm_output_prepare_overlay_view(struct drm_output *output,
struct weston_compositor *ec = output->base.compositor;
struct drm_compositor *c = (struct drm_compositor *)ec;
struct weston_buffer_viewport *viewport = &ev->surface->buffer_viewport;
- struct drm_sprite *s;
+ struct drm_plane *p;
int found = 0;
struct gbm_bo *bo;
pixman_region32_t dest_rect, src_rect;
@@ -881,11 +892,11 @@ drm_output_prepare_overlay_view(struct drm_output *output,
if (!drm_view_transform_supported(ev))
return NULL;
- wl_list_for_each(s, &c->sprite_list, link) {
- if (!drm_sprite_crtc_supported(output, s->possible_crtcs))
+ wl_list_for_each(p, &c->sprite_list, link) {
+ if (!drm_plane_crtc_supported(output, p->possible_crtcs))
continue;
- if (!s->next) {
+ if (!p->next) {
found = 1;
break;
}
@@ -901,23 +912,23 @@ drm_output_prepare_overlay_view(struct drm_output *output,
if (!bo)
return NULL;
- format = drm_output_check_sprite_format(s, ev, bo);
+ format = drm_output_check_plane_format(p, ev, bo);
if (format == 0) {
gbm_bo_destroy(bo);
return NULL;
}
- s->next = drm_fb_get_from_bo(bo, c, format);
- if (!s->next) {
+ p->next = drm_fb_get_from_bo(bo, c, format);
+ if (!p->next) {
gbm_bo_destroy(bo);
return NULL;
}
- drm_fb_set_buffer(s->next, ev->surface->buffer_ref.buffer);
+ drm_fb_set_buffer(p->next, ev->surface->buffer_ref.buffer);
box = pixman_region32_extents(&ev->transform.boundingbox);
- s->plane.x = box->x1;
- s->plane.y = box->y1;
+ p->base.x = box->x1;
+ p->base.y = box->y1;
/*
* Calculate the source & dest rects properly based on actual
@@ -934,10 +945,10 @@ drm_output_prepare_overlay_view(struct drm_output *output,
output->base.transform,
output->base.current_scale,
*box);
- s->dest_x = tbox.x1;
- s->dest_y = tbox.y1;
- s->dest_w = tbox.x2 - tbox.x1;
- s->dest_h = tbox.y2 - tbox.y1;
+ p->dest_x = tbox.x1;
+ p->dest_y = tbox.y1;
+ p->dest_w = tbox.x2 - tbox.x1;
+ p->dest_h = tbox.y2 - tbox.y1;
pixman_region32_fini(&dest_rect);
pixman_region32_init(&src_rect);
@@ -974,13 +985,13 @@ drm_output_prepare_overlay_view(struct drm_output *output,
viewport->buffer.scale,
tbox);
- s->src_x = tbox.x1 << 8;
- s->src_y = tbox.y1 << 8;
- s->src_w = (tbox.x2 - tbox.x1) << 8;
- s->src_h = (tbox.y2 - tbox.y1) << 8;
+ p->src_x = tbox.x1 << 8;
+ p->src_y = tbox.y1 << 8;
+ p->src_w = (tbox.x2 - tbox.x1) << 8;
+ p->src_h = (tbox.y2 - tbox.y1) << 8;
pixman_region32_fini(&src_rect);
- return &s->plane;
+ return &p->base;
}
static struct weston_plane *
@@ -2276,69 +2287,69 @@ err_free:
static void
create_sprites(struct drm_compositor *ec)
{
- struct drm_sprite *sprite;
- drmModePlaneRes *plane_res;
- drmModePlane *plane;
+ struct drm_plane *plane;
+ drmModePlaneRes *kplane_res;
+ drmModePlane *kplane;
uint32_t i;
- plane_res = drmModeGetPlaneResources(ec->drm.fd);
- if (!plane_res) {
+ kplane_res = drmModeGetPlaneResources(ec->drm.fd);
+ if (!kplane_res) {
weston_log("failed to get plane resources: %s\n",
strerror(errno));
return;
}
- for (i = 0; i < plane_res->count_planes; i++) {
- plane = drmModeGetPlane(ec->drm.fd, plane_res->planes[i]);
- if (!plane)
+ for (i = 0; i < kplane_res->count_planes; i++) {
+ kplane = drmModeGetPlane(ec->drm.fd, kplane_res->planes[i]);
+ if (!kplane)
continue;
- sprite = zalloc(sizeof(*sprite) + ((sizeof(uint32_t)) *
- plane->count_formats));
- if (!sprite) {
+ plane = zalloc(sizeof(*plane) + ((sizeof(uint32_t)) *
+ kplane->count_formats));
+ if (!plane) {
weston_log("%s: out of memory\n",
__func__);
- drmModeFreePlane(plane);
+ drmModeFreePlane(kplane);
continue;
}
- sprite->possible_crtcs = plane->possible_crtcs;
- sprite->plane_id = plane->plane_id;
- sprite->current = NULL;
- sprite->next = NULL;
- sprite->compositor = ec;
- sprite->count_formats = plane->count_formats;
- memcpy(sprite->formats, plane->formats,
- plane->count_formats * sizeof(plane->formats[0]));
- drmModeFreePlane(plane);
- weston_plane_init(&sprite->plane, &ec->base, 0, 0);
- weston_compositor_stack_plane(&ec->base, &sprite->plane,
+ plane->possible_crtcs = kplane->possible_crtcs;
+ plane->plane_id = kplane->plane_id;
+ plane->current = NULL;
+ plane->next = NULL;
+ plane->compositor = ec;
+ plane->count_formats = kplane->count_formats;
+ memcpy(plane->formats, kplane->formats,
+ kplane->count_formats * sizeof(kplane->formats[0]));
+ drmModeFreePlane(kplane);
+ weston_plane_init(&plane->base, &ec->base, 0, 0);
+ weston_compositor_stack_plane(&ec->base, &plane->base,
&ec->base.primary_plane);
- wl_list_insert(&ec->sprite_list, &sprite->link);
+ wl_list_insert(&ec->sprite_list, &plane->link);
}
- drmModeFreePlaneResources(plane_res);
+ drmModeFreePlaneResources(kplane_res);
}
static void
destroy_sprites(struct drm_compositor *compositor)
{
- struct drm_sprite *sprite, *next;
+ struct drm_plane *plane, *next;
struct drm_output *output;
output = container_of(compositor->base.output_list.next,
struct drm_output, base.link);
- wl_list_for_each_safe(sprite, next, &compositor->sprite_list, link) {
+ wl_list_for_each_safe(plane, next, &compositor->sprite_list, link) {
drmModeSetPlane(compositor->drm.fd,
- sprite->plane_id,
+ plane->plane_id,
output->crtc_id, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0);
- drm_output_release_fb(output, sprite->current);
- drm_output_release_fb(output, sprite->next);
- weston_plane_release(&sprite->plane);
- free(sprite);
+ drm_output_release_fb(output, plane->current);
+ drm_output_release_fb(output, plane->next);
+ weston_plane_release(&plane->base);
+ free(plane);
}
}
@@ -2576,7 +2587,7 @@ session_notify(struct wl_listener *listener, void *data)
{
struct weston_compositor *compositor = data;
struct drm_compositor *ec = data;
- struct drm_sprite *sprite;
+ struct drm_plane *sprite;
struct drm_output *output;
if (ec->base.session_active) {
--
2.4.1
More information about the wayland-devel
mailing list