[PATCH weston 10/10] Refactor pixel copying routines to shared utilities

Bryce Harrington bryce at osg.samsung.com
Wed May 6 17:44:29 PDT 2015


This moves the four pixel copying routines from screenshooter to shared,
so that the test harness screenshot code can use them as well;
optimizations done on these routines will help both parts of the
codebase.

Signed-off-by: Bryce Harrington <bryce at osg.samsung.com>
---
 Makefile.am         |  4 ++-
 shared/pixel-util.c | 90 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 shared/pixel-util.h | 49 +++++++++++++++++++++++++++++
 src/screenshooter.c | 66 ++-------------------------------------
 tests/weston-test.c | 65 +-------------------------------------
 5 files changed, 145 insertions(+), 129 deletions(-)
 create mode 100644 shared/pixel-util.c
 create mode 100644 shared/pixel-util.h

diff --git a/Makefile.am b/Makefile.am
index 5bca9c2..c8b4d2c 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -910,7 +910,9 @@ libshared_la_SOURCES =				\
 	shared/file-util.c			\
 	shared/file-util.h			\
 	shared/os-compatibility.c		\
-	shared/os-compatibility.h
+	shared/os-compatibility.h		\
+	shared/pixel-util.c			\
+	shared/pixel-util.h
 
 libshared_cairo_la_CFLAGS =			\
 	-DDATADIR='"$(datadir)"'		\
diff --git a/shared/pixel-util.c b/shared/pixel-util.c
new file mode 100644
index 0000000..761cb12
--- /dev/null
+++ b/shared/pixel-util.c
@@ -0,0 +1,90 @@
+/*
+ * Copyright © 2015 Samsung Electronics Co., Ltd
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and
+ * its documentation for any purpose is hereby granted without fee, provided
+ * that the above copyright notice appear in all copies and that both that
+ * copyright notice and this permission notice appear in supporting
+ * documentation, and that the name of the copyright holders not be used in
+ * advertising or publicity pertaining to distribution of the software
+ * without specific, written prior permission.  The copyright holders make
+ * no representations about the suitability of this software for any
+ * purpose.  It is provided "as is" without express or implied warranty.
+ *
+ * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
+ * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
+ * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
+ * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
+ * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include "config.h"
+
+#include <string.h> // memcpy
+
+#include "pixel-util.h"
+
+void
+copy_bgra_yflip(uint8_t *dst, uint8_t *src, int height, int stride)
+{
+	uint8_t *end;
+
+	end = dst + height * stride;
+	while (dst < end) {
+		memcpy(dst, src, stride);
+		dst += stride;
+		src -= stride;
+	}
+}
+
+void
+copy_bgra(uint8_t *dst, uint8_t *src, int height, int stride)
+{
+	/* TODO: optimize this out */
+	memcpy(dst, src, height * stride);
+}
+
+static void
+copy_row_swap_RB(void *vdst, void *vsrc, int bytes)
+{
+	uint32_t *dst = vdst;
+	uint32_t *src = vsrc;
+	uint32_t *end = dst + bytes / 4;
+
+	while (dst < end) {
+		uint32_t v = *src++;
+		/*		      A R G B */
+		uint32_t tmp = v & 0xff00ff00;
+		tmp |= (v >> 16) & 0x000000ff;
+		tmp |= (v << 16) & 0x00ff0000;
+		*dst++ = tmp;
+	}
+}
+
+void
+copy_rgba_yflip(uint8_t *dst, uint8_t *src, int height, int stride)
+{
+	uint8_t *end;
+
+	end = dst + height * stride;
+	while (dst < end) {
+		copy_row_swap_RB(dst, src, stride);
+		dst += stride;
+		src -= stride;
+	}
+}
+
+void
+copy_rgba(uint8_t *dst, uint8_t *src, int height, int stride)
+{
+	uint8_t *end;
+
+	end = dst + height * stride;
+	while (dst < end) {
+		copy_row_swap_RB(dst, src, stride);
+		dst += stride;
+		src += stride;
+	}
+}
diff --git a/shared/pixel-util.h b/shared/pixel-util.h
new file mode 100644
index 0000000..40f7d93
--- /dev/null
+++ b/shared/pixel-util.h
@@ -0,0 +1,49 @@
+/*
+ * Copyright © 2015 Samsung Electronics Co., Ltd
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and
+ * its documentation for any purpose is hereby granted without fee, provided
+ * that the above copyright notice appear in all copies and that both that
+ * copyright notice and this permission notice appear in supporting
+ * documentation, and that the name of the copyright holders not be used in
+ * advertising or publicity pertaining to distribution of the software
+ * without specific, written prior permission.  The copyright holders make
+ * no representations about the suitability of this software for any
+ * purpose.  It is provided "as is" without express or implied warranty.
+ *
+ * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
+ * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
+ * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
+ * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
+ * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#ifndef WESTON_PIXEL_UTIL_H
+#define WESTON_PIXEL_UTIL_H
+
+#include <stdint.h>
+
+#ifdef  __cplusplus
+extern "C" {
+#endif
+
+void
+copy_bgra_yflip(uint8_t *dst, uint8_t *src, int height, int stride);
+
+void
+copy_bgra(uint8_t *dst, uint8_t *src, int height, int stride);
+
+void
+copy_rgba_yflip(uint8_t *dst, uint8_t *src, int height, int stride);
+
+void
+copy_rgba(uint8_t *dst, uint8_t *src, int height, int stride);
+
+
+#ifdef  __cplusplus
+}
+#endif
+
+#endif /* WESTON_PIXEL_UTIL_H */
diff --git a/src/screenshooter.c b/src/screenshooter.c
index 4e32db5..ed0c10b 100644
--- a/src/screenshooter.c
+++ b/src/screenshooter.c
@@ -24,12 +24,13 @@
 
 #include <stdlib.h>
 #include <stdio.h>
-#include <string.h>
 #include <linux/input.h>
 #include <fcntl.h>
 #include <unistd.h>
 #include <sys/uio.h>
 
+#include "../shared/pixel-util.h"
+
 #include "compositor.h"
 #include "screenshooter-server-protocol.h"
 
@@ -51,69 +52,6 @@ struct screenshooter_frame_listener {
 };
 
 static void
-copy_bgra_yflip(uint8_t *dst, uint8_t *src, int height, int stride)
-{
-	uint8_t *end;
-
-	end = dst + height * stride;
-	while (dst < end) {
-		memcpy(dst, src, stride);
-		dst += stride;
-		src -= stride;
-	}
-}
-
-static void
-copy_bgra(uint8_t *dst, uint8_t *src, int height, int stride)
-{
-	/* TODO: optimize this out */
-	memcpy(dst, src, height * stride);
-}
-
-static void
-copy_row_swap_RB(void *vdst, void *vsrc, int bytes)
-{
-	uint32_t *dst = vdst;
-	uint32_t *src = vsrc;
-	uint32_t *end = dst + bytes / 4;
-
-	while (dst < end) {
-		uint32_t v = *src++;
-		/*                    A R G B */
-		uint32_t tmp = v & 0xff00ff00;
-		tmp |= (v >> 16) & 0x000000ff;
-		tmp |= (v << 16) & 0x00ff0000;
-		*dst++ = tmp;
-	}
-}
-
-static void
-copy_rgba_yflip(uint8_t *dst, uint8_t *src, int height, int stride)
-{
-	uint8_t *end;
-
-	end = dst + height * stride;
-	while (dst < end) {
-		copy_row_swap_RB(dst, src, stride);
-		dst += stride;
-		src -= stride;
-	}
-}
-
-static void
-copy_rgba(uint8_t *dst, uint8_t *src, int height, int stride)
-{
-	uint8_t *end;
-
-	end = dst + height * stride;
-	while (dst < end) {
-		copy_row_swap_RB(dst, src, stride);
-		dst += stride;
-		src += stride;
-	}
-}
-
-static void
 screenshooter_frame_notify(struct wl_listener *listener, void *data)
 {
 	struct screenshooter_frame_listener *l =
diff --git a/tests/weston-test.c b/tests/weston-test.c
index 1d6d264..ff479c7 100644
--- a/tests/weston-test.c
+++ b/tests/weston-test.c
@@ -29,6 +29,7 @@
 #include <string.h>
 #include <cairo.h>
 
+#include "../shared/pixel-util.h"
 #include "../src/compositor.h"
 #include "weston-test-server-protocol.h"
 
@@ -295,70 +296,6 @@ struct test_screenshot_frame_listener {
 };
 
 static void
-copy_bgra_yflip(uint8_t *dst, uint8_t *src, int height, int stride)
-{
-	uint8_t *end;
-
-	end = dst + height * stride;
-	while (dst < end) {
-		memcpy(dst, src, stride);
-		dst += stride;
-		src -= stride;
-	}
-}
-
-
-static void
-copy_bgra(uint8_t *dst, uint8_t *src, int height, int stride)
-{
-	/* TODO: optimize this out */
-	memcpy(dst, src, height * stride);
-}
-
-static void
-copy_row_swap_RB(void *vdst, void *vsrc, int bytes)
-{
-	uint32_t *dst = vdst;
-	uint32_t *src = vsrc;
-	uint32_t *end = dst + bytes / 4;
-
-	while (dst < end) {
-		uint32_t v = *src++;
-		/*                    A R G B */
-		uint32_t tmp = v & 0xff00ff00;
-		tmp |= (v >> 16) & 0x000000ff;
-		tmp |= (v << 16) & 0x00ff0000;
-		*dst++ = tmp;
-	}
-}
-
-static void
-copy_rgba_yflip(uint8_t *dst, uint8_t *src, int height, int stride)
-{
-	uint8_t *end;
-
-	end = dst + height * stride;
-	while (dst < end) {
-		copy_row_swap_RB(dst, src, stride);
-		dst += stride;
-		src -= stride;
-	}
-}
-
-static void
-copy_rgba(uint8_t *dst, uint8_t *src, int height, int stride)
-{
-	uint8_t *end;
-
-	end = dst + height * stride;
-	while (dst < end) {
-		copy_row_swap_RB(dst, src, stride);
-		dst += stride;
-		src += stride;
-	}
-}
-
-static void
 test_screenshot_frame_notify(struct wl_listener *listener, void *data)
 {
 	struct test_screenshot_frame_listener *l =
-- 
1.9.1



More information about the wayland-devel mailing list