[PATCH 2/6] xf86drmMode: separate drmModeAtomicCommit() and drmModeAtomicCleanup()

Hyungwon Hwang human.hwang at samsung.com
Tue Aug 18 17:58:40 PDT 2015


This patch seprates the code, which sorts proprty sets and eliminates
duplicate properties, from drmModeAtomicCommit(). Now
drmModeAtomicCleanup() has to do the job before calling
drmModeAtomicCommit(), and drmModeAtomicCommit() just converts the cleaned
request to IOCTL argument.

Signed-off-by: Hyungwon Hwang <human.hwang at samsung.com>
---
 xf86drmMode.c | 72 +++++++++++++++++++++++++++++++++--------------------------
 xf86drmMode.h |  1 +
 2 files changed, 41 insertions(+), 32 deletions(-)

diff --git a/xf86drmMode.c b/xf86drmMode.c
index d4ed5c1..82c4c91 100644
--- a/xf86drmMode.c
+++ b/xf86drmMode.c
@@ -1303,10 +1303,39 @@ static int sort_req_list(const void *misc, const void *other)
 		return second->property_id - first->property_id;
 }
 
+void drmModeAtomicCleanup(drmModeAtomicReqPtr req)
+{
+	uint32_t last_obj_id = 0;
+	uint32_t i;
+
+	if (req->cursor == 0)
+		return;
+
+	/* Sort the list by object ID, then by property ID. */
+	qsort(req->items, req->cursor, sizeof(*req->items),
+	      sort_req_list);
+
+	/* Eliminate duplicate property sets. */
+	for (i = 0; i < req->cursor; i++) {
+		if (req->items[i].object_id != last_obj_id)
+			last_obj_id = req->items[i].object_id;
+
+		if (i == req->cursor - 1)
+			continue;
+
+		if (req->items[i].object_id != req->items[i + 1].object_id ||
+		    req->items[i].property_id != req->items[i + 1].property_id)
+			continue;
+
+		memmove(&req->items[i], &req->items[i + 1],
+			(req->cursor - i - 1) * sizeof(*req->items));
+		req->cursor--;
+	}
+}
+
 int drmModeAtomicCommit(int fd, drmModeAtomicReqPtr req, uint32_t flags,
 			void *user_data)
 {
-	drmModeAtomicReqPtr sorted;
 	struct drm_mode_atomic atomic;
 	uint32_t *objs_ptr = NULL;
 	uint32_t *count_props_ptr = NULL;
@@ -1320,33 +1349,13 @@ int drmModeAtomicCommit(int fd, drmModeAtomicReqPtr req, uint32_t flags,
 	if (req->cursor == 0)
 		return 0;
 
-	sorted = drmModeAtomicDuplicate(req);
-	if (sorted == NULL)
-		return -ENOMEM;
-
 	memclear(atomic);
 
-	/* Sort the list by object ID, then by property ID. */
-	qsort(sorted->items, sorted->cursor, sizeof(*sorted->items),
-	      sort_req_list);
-
-	/* Now the list is sorted, eliminate duplicate property sets. */
-	for (i = 0; i < sorted->cursor; i++) {
-		if (sorted->items[i].object_id != last_obj_id) {
+	for (i = 0; i < req->cursor; i++) {
+		if (req->items[i].object_id != last_obj_id) {
 			atomic.count_objs++;
-			last_obj_id = sorted->items[i].object_id;
+			last_obj_id = req->items[i].object_id;
 		}
-
-		if (i == sorted->cursor - 1)
-			continue;
-
-		if (sorted->items[i].object_id != sorted->items[i + 1].object_id ||
-		    sorted->items[i].property_id != sorted->items[i + 1].property_id)
-			continue;
-
-		memmove(&sorted->items[i], &sorted->items[i + 1],
-			(sorted->cursor - i - 1) * sizeof(*sorted->items));
-		sorted->cursor--;
 	}
 
 	objs_ptr = drmMalloc(atomic.count_objs * sizeof objs_ptr[0]);
@@ -1361,28 +1370,28 @@ int drmModeAtomicCommit(int fd, drmModeAtomicReqPtr req, uint32_t flags,
 		goto out;
 	}
 
-	props_ptr = drmMalloc(sorted->cursor * sizeof props_ptr[0]);
+	props_ptr = drmMalloc(req->cursor * sizeof props_ptr[0]);
 	if (!props_ptr) {
 		errno = ENOMEM;
 		goto out;
 	}
 
-	prop_values_ptr = drmMalloc(sorted->cursor * sizeof prop_values_ptr[0]);
+	prop_values_ptr = drmMalloc(req->cursor * sizeof prop_values_ptr[0]);
 	if (!prop_values_ptr) {
 		errno = ENOMEM;
 		goto out;
 	}
 
-	for (i = 0, last_obj_id = 0; i < sorted->cursor; i++) {
-		if (sorted->items[i].object_id != last_obj_id) {
+	for (i = 0, last_obj_id = 0; i < req->cursor; i++) {
+		if (req->items[i].object_id != last_obj_id) {
 			obj_idx++;
-			objs_ptr[obj_idx] = sorted->items[i].object_id;
+			objs_ptr[obj_idx] = req->items[i].object_id;
 			last_obj_id = objs_ptr[obj_idx];
 		}
 
 		count_props_ptr[obj_idx]++;
-		props_ptr[i] = sorted->items[i].property_id;
-		prop_values_ptr[i] = sorted->items[i].value;
+		props_ptr[i] = req->items[i].property_id;
+		prop_values_ptr[i] = req->items[i].value;
 
 	}
 
@@ -1400,7 +1409,6 @@ out:
 	drmFree(count_props_ptr);
 	drmFree(props_ptr);
 	drmFree(prop_values_ptr);
-	drmModeAtomicFree(sorted);
 
 	return ret;
 }
diff --git a/xf86drmMode.h b/xf86drmMode.h
index 4de7bbb..fe14078 100644
--- a/xf86drmMode.h
+++ b/xf86drmMode.h
@@ -498,6 +498,7 @@ extern int drmModeAtomicAddProperty(drmModeAtomicReqPtr req,
 				    uint32_t object_id,
 				    uint32_t property_id,
 				    uint64_t value);
+extern void drmModeAtomicCleanup(drmModeAtomicReqPtr req);
 extern int drmModeAtomicCommit(int fd,
 			       drmModeAtomicReqPtr req,
 			       uint32_t flags,
-- 
2.4.3



More information about the dri-devel mailing list