[weston,12/13] main, compositor: Add a stereoscopy config option.

Submitted by Emmanuel Gil Peyrot on Nov. 14, 2017, 3:05 p.m.

Details

Message ID 20171114150600.1763-13-linkmauve@linkmauve.fr
State New
Headers show
Series "Add stereoscopy support" ( rev: 1 ) in Wayland

Not browsing as part of any series.

Commit Message

Emmanuel Gil Peyrot Nov. 14, 2017, 3:05 p.m.
From: Emmanuel Gil Peyrot <emmanuel.peyrot@collabora.com>

It can take the values "", "frame-packing", "top-and-bottom" and
"side-by-side".  Any mode not corresponding to one of these will be
discarded.

Signed-off-by: Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
---
 Makefile.am            |  4 +++-
 compositor/main.c      | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++
 libweston/compositor.c | 24 ++++++++++++++++++++
 libweston/compositor.h |  7 ++++++
 man/weston-drm.man     |  6 ++++-
 5 files changed, 99 insertions(+), 2 deletions(-)

Patch hide | download patch | download mbox

diff --git a/Makefile.am b/Makefile.am
index e1cdb289..39b71b88 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -691,7 +691,9 @@  nodist_libtoytoolkit_la_SOURCES =			\
 	protocol/pointer-constraints-unstable-v1-protocol.c		\
 	protocol/pointer-constraints-unstable-v1-client-protocol.h	\
 	protocol/relative-pointer-unstable-v1-protocol.c		\
-	protocol/relative-pointer-unstable-v1-client-protocol.h
+	protocol/relative-pointer-unstable-v1-client-protocol.h		\
+	protocol/stereoscopy-unstable-v1-protocol.c			\
+	protocol/stereoscopy-unstable-v1-client-protocol.h
 
 BUILT_SOURCES += $(nodist_libtoytoolkit_la_SOURCES)
 
diff --git a/compositor/main.c b/compositor/main.c
index 9e4451e5..ffbfeb95 100644
--- a/compositor/main.c
+++ b/compositor/main.c
@@ -65,6 +65,8 @@ 
 #include "compositor-wayland.h"
 #include "windowed-output-api.h"
 
+#include "stereoscopy-unstable-v1-server-protocol.h"
+
 #define WINDOW_TITLE "Weston Compositor"
 
 struct wet_output_config {
@@ -978,6 +980,28 @@  weston_transform_to_string(uint32_t output_transform)
 	return "<illegal value>";
 }
 
+static const struct { const char *name; uint32_t token; } stereoscopy_layouts[] = {
+	{ "",               ZWP_STEREOSCOPY_V1_LAYOUT_NONE },
+	{ "frame-packing",  ZWP_STEREOSCOPY_V1_LAYOUT_FRAME_PACKING },
+	{ "top-and-bottom", ZWP_STEREOSCOPY_V1_LAYOUT_TOP_AND_BOTTOM },
+	{ "side-by-side",   ZWP_STEREOSCOPY_V1_LAYOUT_SIDE_BY_SIDE },
+};
+
+WL_EXPORT int
+weston_parse_stereoscopy_layout(const char *layout, uint32_t *out)
+{
+	unsigned int i;
+
+	for (i = 0; i < ARRAY_LENGTH(stereoscopy_layouts); i++)
+		if (strcmp(stereoscopy_layouts[i].name, layout) == 0) {
+			*out = stereoscopy_layouts[i].token;
+			return 0;
+		}
+
+	*out = ZWP_STEREOSCOPY_V1_LAYOUT_NONE;
+	return -1;
+}
+
 static int
 load_configuration(struct weston_config **config, int32_t noconfig,
 		   const char *config_file)
@@ -1068,6 +1092,36 @@  wet_output_set_transform(struct weston_output *output,
 	weston_output_set_transform(output, transform);
 }
 
+/* UINT32_MAX is treated as invalid because 0 is a valid
+ * enumeration value and the parameter is unsigned
+ */
+static void
+wet_output_set_stereoscopy_layout(struct weston_output *output,
+                                  struct weston_config_section *section,
+                                  uint32_t default_layout,
+                                  uint32_t parsed_layout)
+{
+	char *t;
+	uint32_t layout = default_layout;
+
+	if (section) {
+		weston_config_section_get_string(section,
+		                                 "stereoscopy", &t, "");
+
+		if (weston_parse_stereoscopy_layout(t, &layout) < 0) {
+			weston_log("Invalid stereoscopy layout \"%s\" for output %s\n",
+			           t, output->name);
+			layout = default_layout;
+		}
+		free(t);
+	}
+
+	if (parsed_layout != UINT32_MAX)
+		layout = parsed_layout;
+
+	weston_output_set_stereoscopy_layout(output, layout);
+}
+
 static int
 wet_configure_windowed_output_from_config(struct weston_output *output,
 					  struct wet_output_config *defaults)
@@ -1185,6 +1239,12 @@  drm_backend_output_configure(struct wl_listener *listener, void *data)
 	}
 	free(s);
 
+	/* This must be parsed before setting the mode, otherwise we will
+	 * always choose a mono mode. */
+	wet_output_set_stereoscopy_layout(output, section,
+					  ZWP_STEREOSCOPY_V1_LAYOUT_NONE,
+	                                  UINT32_MAX);
+
 	if (api->set_mode(output, mode, modeline) < 0) {
 		weston_log("Cannot configure an output using weston_drm_output_api.\n");
 		free(modeline);
diff --git a/libweston/compositor.c b/libweston/compositor.c
index 723dec02..7766e8c4 100644
--- a/libweston/compositor.c
+++ b/libweston/compositor.c
@@ -4758,6 +4758,30 @@  weston_output_set_transform(struct weston_output *output,
 	output->transform = transform;
 }
 
+/** Sets the stereoscopy layout for a given output.
+ *
+ * \param output    The weston_output object that the layout is set for.
+ * \param layout    Layout value for the given output.
+ *
+ * It only supports setting the layout for an output that is
+ * not enabled.
+ *
+ * Refer to wp_stereoscopy::layout section located at
+ * https://cgit.freedesktop.org/wayland/wayland-protocols/tree/unstable/stereoscopy/stereoscopy-unstable-v1.xml
+ * for list of values that can be passed to this function.
+ *
+ * \memberof weston_output
+ */
+WL_EXPORT void
+weston_output_set_stereoscopy_layout(struct weston_output *output,
+                                     uint32_t layout)
+{
+	/* We can only set the layout on a disabled output */
+	assert(!output->enabled);
+
+	output->stereoscopy_layout = layout;
+}
+
 /** Initializes a weston_output object with enough data so
  ** an output can be configured.
  *
diff --git a/libweston/compositor.h b/libweston/compositor.h
index 165f257c..09585d15 100644
--- a/libweston/compositor.h
+++ b/libweston/compositor.h
@@ -1915,6 +1915,9 @@  weston_parse_transform(const char *transform, uint32_t *out);
 const char *
 weston_transform_to_string(uint32_t output_transform);
 
+int
+weston_parse_stereoscopy_layout(const char *layout, uint32_t *out);
+
 struct weston_keyboard *
 weston_seat_get_keyboard(struct weston_seat *seat);
 
@@ -1939,6 +1942,10 @@  void
 weston_output_set_transform(struct weston_output *output,
 			    uint32_t transform);
 
+void
+weston_output_set_stereoscopy_layout(struct weston_output *output,
+                                     uint32_t transform);
+
 void
 weston_output_init(struct weston_output *output,
 		   struct weston_compositor *compositor,
diff --git a/man/weston-drm.man b/man/weston-drm.man
index d7fd5614..9fdbaf8f 100644
--- a/man/weston-drm.man
+++ b/man/weston-drm.man
@@ -78,7 +78,11 @@  can generate detailed mode lines.
 Transform for the output, which can be rotated in 90-degree steps
 and possibly flipped. Possible values are
 .BR normal ", " 90 ", " 180 ", " 270 ", "
-.BR flipped ", " flipped-90 ", " flipped-180 ", and " flipped-270 .
+.BR flipped ", " flipped-90 ", " flipped-180 ", and " flipped-270 " .
+\fBstereoscopy\fR=\fIlayout\fR
+Stereoscopy layout for the output, which is currently only supported on
+monitors exposing HDMI 3D modes.  Possible values are nothing,
+.BR frame-packing ", " top-and-bottom ", and " side-by-side ".
 .
 .\" ***************************************************************
 .SH OPTIONS