[PATCH weston v11 06/13] compositor-drm: Introduce drm_pending_state structure

Daniel Stone daniels at collabora.com
Tue Jul 18 13:14:28 UTC 2017


drm_pending_state is currently skeletal, but will be used to retain
data through begin_repaint -> assign_planes -> repaint -> repaint_flush.

The flush and cancel functions are currently identical, only freeing the
state, but they will be used for different purposes in later patches.
Specifically, the intent is to apply any pending output changes (through
PageFlip/SetCrtc, or the atomic ioctls) in flush, and only free the
state in cancel.

Signed-off-by: Daniel Stone <daniels at collabora.com>
---
 libweston/compositor-drm.c | 100 +++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 100 insertions(+)

diff --git a/libweston/compositor-drm.c b/libweston/compositor-drm.c
index d1ac3855..eae78ea3 100644
--- a/libweston/compositor-drm.c
+++ b/libweston/compositor-drm.c
@@ -170,6 +170,8 @@ struct drm_backend {
 	int sprites_are_broken;
 	int sprites_hidden;
 
+	void *repaint_data;
+
 	int cursors_are_broken;
 
 	bool universal_planes;
@@ -225,6 +227,16 @@ struct drm_edid {
 };
 
 /**
+ * Pending state holds one or more drm_output_state structures, collected from
+ * performing repaint. This pending state is transient, and only lives between
+ * beginning a repaint group and flushing the results: after flush, each
+ * output state will complete and be retired separately.
+ */
+struct drm_pending_state {
+	struct drm_backend *backend;
+};
+
+/**
  * A plane represents one buffer, positioned within a CRTC, and stacked
  * relative to other planes on the same CRTC.
  *
@@ -898,6 +910,42 @@ drm_view_transform_supported(struct weston_view *ev)
 		(ev->transform.matrix.type < WESTON_MATRIX_TRANSFORM_ROTATE);
 }
 
+/**
+ * Allocate a new drm_pending_state
+ *
+ * Allocate a new, empty, 'pending state' structure to be used across a
+ * repaint cycle or similar.
+ *
+ * @param backend DRM backend
+ * @returns Newly-allocated pending state structure
+ */
+static struct drm_pending_state *
+drm_pending_state_alloc(struct drm_backend *backend)
+{
+	struct drm_pending_state *ret;
+
+	ret = calloc(1, sizeof(*ret));
+	if (!ret)
+		return NULL;
+
+	ret->backend = backend;
+
+	return ret;
+}
+
+/**
+ * Free a drm_pending_state structure
+ *
+ * Frees a pending_state structure.
+ *
+ * @param pending_state Pending state structure to free
+ */
+static void
+drm_pending_state_free(struct drm_pending_state *pending_state)
+{
+	free(pending_state);
+}
+
 static uint32_t
 drm_output_check_scanout_format(struct drm_output *output,
 				struct weston_surface *es, struct gbm_bo *bo)
@@ -1411,6 +1459,55 @@ page_flip_handler(int fd, unsigned int frame,
 	}
 }
 
+/**
+ * Begin a new repaint cycle
+ *
+ * Called by the core compositor at the beginning of a repaint cycle.
+ */
+static void *
+drm_repaint_begin(struct weston_compositor *compositor)
+{
+	struct drm_backend *b = to_drm_backend(compositor);
+	struct drm_pending_state *ret;
+
+	ret = drm_pending_state_alloc(b);
+	b->repaint_data = ret;
+
+	return ret;
+}
+
+/**
+ * Flush a repaint set
+ *
+ * Called by the core compositor when a repaint cycle has been completed
+ * and should be flushed.
+ */
+static void
+drm_repaint_flush(struct weston_compositor *compositor, void *repaint_data)
+{
+	struct drm_backend *b = to_drm_backend(compositor);
+	struct drm_pending_state *pending_state = repaint_data;
+
+	drm_pending_state_free(pending_state);
+	b->repaint_data = NULL;
+}
+
+/**
+ * Cancel a repaint set
+ *
+ * Called by the core compositor when a repaint has finished, so the data
+ * held across the repaint cycle should be discarded.
+ */
+static void
+drm_repaint_cancel(struct weston_compositor *compositor, void *repaint_data)
+{
+	struct drm_backend *b = to_drm_backend(compositor);
+	struct drm_pending_state *pending_state = repaint_data;
+
+	drm_pending_state_free(pending_state);
+	b->repaint_data = NULL;
+}
+
 static uint32_t
 drm_output_check_plane_format(struct drm_plane *p,
 			       struct weston_view *ev, struct gbm_bo *bo)
@@ -3939,6 +4036,9 @@ drm_backend_create(struct weston_compositor *compositor,
 
 	b->base.destroy = drm_destroy;
 	b->base.restore = drm_restore;
+	b->base.repaint_begin = drm_repaint_begin;
+	b->base.repaint_flush = drm_repaint_flush;
+	b->base.repaint_cancel = drm_repaint_cancel;
 
 	weston_setup_vt_switch_bindings(compositor);
 
-- 
2.13.3



More information about the wayland-devel mailing list