[PATCH 3/8] weston-info: report presentation clock

Louis-Francis Ratté-Boulianne lfrb at collabora.com
Tue Sep 23 19:08:44 PDT 2014


From: Pekka Paalanen <pekka.paalanen at collabora.co.uk>

Signed-off-by: Pekka Paalanen <pekka.paalanen at collabora.co.uk>
v3 Reviewed-by: Mario Kleiner <mario.kleiner.de at gmail.com>
---
 Makefile.am           |  3 ++
 clients/weston-info.c | 81 +++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 84 insertions(+)

diff --git a/Makefile.am b/Makefile.am
index b1dcc21..6a91a8f 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -582,6 +582,9 @@ weston_simple_im_LDADD = $(CLIENT_LIBS)
 weston_simple_im_CFLAGS = $(AM_CFLAGS) $(CLIENT_CFLAGS)
 
 weston_info_SOURCES = clients/weston-info.c
+nodist_weston_info_SOURCES =				\
+	protocol/presentation_timing-protocol.c		\
+	protocol/presentation_timing-client-protocol.h
 weston_info_LDADD = $(WESTON_INFO_LIBS) libshared.la
 weston_info_CFLAGS = $(AM_CFLAGS) $(CLIENT_CFLAGS)
 
diff --git a/clients/weston-info.c b/clients/weston-info.c
index c53ac74..f777982 100644
--- a/clients/weston-info.c
+++ b/clients/weston-info.c
@@ -27,10 +27,14 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include <time.h>
 
 #include <wayland-client.h>
 
 #include "../shared/os-compatibility.h"
+#include "presentation_timing-client-protocol.h"
+
+#define ARRAY_LENGTH(a) (sizeof (a) / sizeof (a)[0])
 
 #define MIN(x,y) (((x) < (y)) ? (x) : (y))
 
@@ -98,6 +102,13 @@ struct seat_info {
 	int32_t repeat_delay;
 };
 
+struct presentation_info {
+	struct global_info global;
+	struct presentation *presentation;
+
+	clockid_t clk_id;
+};
+
 struct weston_info {
 	struct wl_display *display;
 	struct wl_registry *registry;
@@ -554,6 +565,74 @@ add_output_info(struct weston_info *info, uint32_t id, uint32_t version)
 }
 
 static void
+destroy_presentation_info(void *info)
+{
+	struct presentation_info *prinfo = info;
+
+	presentation_destroy(prinfo->presentation);
+}
+
+static const char *
+clock_name(clockid_t clk_id)
+{
+	static const char *names[] = {
+		[CLOCK_REALTIME] =		"CLOCK_REALTIME",
+		[CLOCK_MONOTONIC] =		"CLOCK_MONOTONIC",
+		[CLOCK_MONOTONIC_RAW] =		"CLOCK_MONOTONIC_RAW",
+		[CLOCK_REALTIME_COARSE] =	"CLOCK_REALTIME_COARSE",
+		[CLOCK_MONOTONIC_COARSE] =	"CLOCK_MONOTONIC_COARSE",
+		[CLOCK_BOOTTIME] =		"CLOCK_BOOTTIME",
+	};
+
+	if (clk_id < 0 || (unsigned)clk_id >= ARRAY_LENGTH(names))
+		return "unknown";
+
+	return names[clk_id];
+}
+
+static void
+print_presentation_info(void *info)
+{
+	struct presentation_info *prinfo = info;
+
+	print_global_info(info);
+
+	printf("\tpresentation clock id: %d (%s)\n",
+		prinfo->clk_id, clock_name(prinfo->clk_id));
+}
+
+static void
+presentation_handle_clock_id(void *data, struct presentation *presentation,
+			     uint32_t clk_id)
+{
+	struct presentation_info *prinfo = data;
+
+	prinfo->clk_id = clk_id;
+}
+
+static const struct presentation_listener presentation_listener = {
+	presentation_handle_clock_id
+};
+
+static void
+add_presentation_info(struct weston_info *info, uint32_t id, uint32_t version)
+{
+	struct presentation_info *prinfo = xzalloc(sizeof *prinfo);
+
+	init_global_info(info, &prinfo->global, id, "presentation", version);
+	prinfo->global.print = print_presentation_info;
+	prinfo->global.destroy = destroy_presentation_info;
+
+	prinfo->clk_id = -1;
+	prinfo->presentation = wl_registry_bind(info->registry, id,
+						&presentation_interface, 1);
+	presentation_add_listener(prinfo->presentation, &presentation_listener,
+				  prinfo);
+
+	info->roundtrip_needed = true;
+}
+
+static void
 destroy_global_info(void *data)
 {
 }
@@ -581,6 +660,8 @@ global_handler(void *data, struct wl_registry *registry, uint32_t id,
 		add_shm_info(info, id, version);
 	else if (!strcmp(interface, "wl_output"))
 		add_output_info(info, id, version);
+	else if (!strcmp(interface, "presentation"))
+		add_presentation_info(info, id, version);
 	else
 		add_global_info(info, id, interface, version);
 }
-- 
1.9.3



More information about the wayland-devel mailing list