summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Wilson <chris@chris-wilson.co.uk>2015-03-04 11:19:09 +0000
committerChris Wilson <chris@chris-wilson.co.uk>2015-03-04 11:20:50 +0000
commit8d76f90e2cd560c315595e679679cefbcf422fb4 (patch)
treef60d7cf975b6af2a10baa5ff9369830bcb02772f
parent3e390ec4110519746f2edbb3c38a40f0fc415430 (diff)
tools: Add simple tool to retrieve the current cursor from X
Slightly more funky would be to poke around in the CRTC, but that should require master. As it stands this should help verify that what X is supplying to the driver matches user expectations Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
-rw-r--r--configure.ac3
-rw-r--r--tools/.gitignore1
-rw-r--r--tools/Makefile.am10
-rw-r--r--tools/cursor.c107
4 files changed, 120 insertions, 1 deletions
diff --git a/configure.ac b/configure.ac
index a7cdd93f..c5356e2f 100644
--- a/configure.ac
+++ b/configure.ac
@@ -312,6 +312,9 @@ if test "x$tools" != "xno"; then
tools="no"
fi
+ PKG_CHECK_MODULES(TOOL_CURSOR, [xfixes x11 libpng], [cursor="yes"], [ivo="no"])
+ AM_CONDITIONAL(BUILD_TOOL_CURSOR, test "x$cursor" != "xno")
+
IVO_CFLAGS="$IVO_CFLAGS $extra_cflags"
fi
if test "x$tools" != "xno"; then
diff --git a/tools/.gitignore b/tools/.gitignore
index 3fd8cfb7..b09eaf00 100644
--- a/tools/.gitignore
+++ b/tools/.gitignore
@@ -1,3 +1,4 @@
+cursor
dri3info
intel-virtual-output
org.x.xf86-video-intel.backlight-helper.policy
diff --git a/tools/Makefile.am b/tools/Makefile.am
index 6c992f84..20f8a003 100644
--- a/tools/Makefile.am
+++ b/tools/Makefile.am
@@ -26,13 +26,21 @@ AM_CFLAGS = \
drivermandir = $(DRIVER_MAN_DIR)
policydir = $(datarootdir)/polkit-1/actions
+noinst_PROGRAMS =
+
if BUILD_TOOLS
bin_PROGRAMS = intel-virtual-output
driverman_DATA = intel-virtual-output.$(DRIVER_MAN_SUFFIX)
endif
+if BUILD_TOOL_CURSOR
+noinst_PROGRAMS += cursor
+cursor_CFLAGS = $(TOOL_CURSOR_CFLAGS)
+cursor_LDADD = $(TOOL_CURSOR_LIBS)
+endif
+
if X11_DRI3
-noinst_PROGRAMS = dri3info
+noinst_PROGRAMS += dri3info
dri3info_SOURCES = dri3info.c
dri3info_CFLAGS = $(X11_DRI3_CFLAGS) $(DRI_CFLAGS)
dri3info_LDADD = $(X11_DRI3_LIBS) $(DRI_LIBS)
diff --git a/tools/cursor.c b/tools/cursor.c
new file mode 100644
index 00000000..4ded17a6
--- /dev/null
+++ b/tools/cursor.c
@@ -0,0 +1,107 @@
+/*
+ * Copyright © 2015 Intel Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <X11/Xlib.h>
+#include <X11/extensions/Xfixes.h>
+
+#include <stdio.h>
+#include <stdint.h>
+#include <png.h>
+
+int main(int argc, char **argv)
+{
+ Display *dpy;
+ XFixesCursorImage *cur;
+ unsigned long *src; /* XXX deep sigh */
+ unsigned x, y;
+ png_struct *png;
+ png_info *info;
+ png_byte **rows;
+ FILE *file;
+
+ dpy = XOpenDisplay(NULL);
+ if (dpy == NULL)
+ return 1;
+
+ if (!XFixesQueryExtension(dpy, (int *)&x, (int *)&y))
+ return 1;
+
+ cur = XFixesGetCursorImage(dpy);
+ if (cur == NULL)
+ return 1;
+
+ printf("Cursor on display '%s': %dx%d, (hotspot %dx%d)\n",
+ DisplayString(dpy),
+ cur->width, cur->height,
+ cur->xhot, cur->yhot);
+
+ file = fopen("cursor.png", "wb");
+ if (file == NULL)
+ return 2;
+
+ png = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
+ info = png_create_info_struct(png);
+ png_init_io(png, file);
+ png_set_IHDR(png, info,
+ cur->width, cur->height, 8,
+ PNG_COLOR_TYPE_RGB_ALPHA,
+ PNG_INTERLACE_NONE,
+ PNG_COMPRESSION_TYPE_DEFAULT,
+ PNG_FILTER_TYPE_DEFAULT);
+ png_write_info(png, info);
+
+ src = cur->pixels;
+ rows = malloc(cur->height*sizeof(png_byte*));
+ for (y = 0; y < cur->height; y++) {
+ rows[y] = malloc(cur->width * 4);
+ for (x = 0; x < cur->width; x++) {
+ uint32_t p = *src++;
+ uint8_t r = p >> 0;
+ uint8_t g = p >> 8;
+ uint8_t b = p >> 16;
+ uint8_t a = p >> 24;
+
+ if (a > 0x00 && a < 0xff) {
+ r = (r * 0xff + a /2) / a;
+ g = (g * 0xff + a /2) / a;
+ b = (b * 0xff + a /2) / a;
+ }
+
+ rows[y][4*x + 0] = b;
+ rows[y][4*x + 1] = g;
+ rows[y][4*x + 2] = r;
+ rows[y][4*x + 3] = a;
+ }
+ }
+
+ png_write_image(png, rows);
+ png_write_end(png, NULL);
+ fclose(file);
+
+ return 0;
+}