summaryrefslogtreecommitdiffstats
path: root/src/vulkan/overlay-layer/overlay_params.c
diff options
context:
space:
mode:
authorLionel Landwerlin <[email protected]>2019-02-25 12:37:27 +0000
committerLionel Landwerlin <[email protected]>2019-02-28 12:40:57 +0000
commitb6b275212dc4eef9014f9e8bd247b72debde4b8b (patch)
tree738e012b6cc6e76251323407827a7e0d313d7e2c /src/vulkan/overlay-layer/overlay_params.c
parent4e29a1d36ae72e0192c52efe6865d5b0e58a1358 (diff)
vulkan/overlay: rework option parsing
Makes adding new options easier. Signed-off-by: Lionel Landwerlin <[email protected]> Reviewed-by: Eric Engestrom <[email protected]>
Diffstat (limited to 'src/vulkan/overlay-layer/overlay_params.c')
-rw-r--r--src/vulkan/overlay-layer/overlay_params.c142
1 files changed, 142 insertions, 0 deletions
diff --git a/src/vulkan/overlay-layer/overlay_params.c b/src/vulkan/overlay-layer/overlay_params.c
new file mode 100644
index 00000000000..d28799ccf06
--- /dev/null
+++ b/src/vulkan/overlay-layer/overlay_params.c
@@ -0,0 +1,142 @@
+/*
+ * Copyright © 2019 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.
+ */
+
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+
+#include "overlay_params.h"
+
+static enum overlay_param_position
+parse_position(const char *str)
+{
+ if (!str || !strcmp(str, "top-left"))
+ return LAYER_POSITION_TOP_LEFT;
+ if (!strcmp(str, "top-right"))
+ return LAYER_POSITION_TOP_RIGHT;
+ if (!strcmp(str, "bottom-left"))
+ return LAYER_POSITION_BOTTOM_LEFT;
+ if (!strcmp(str, "bottom-right"))
+ return LAYER_POSITION_BOTTOM_RIGHT;
+ return LAYER_POSITION_TOP_LEFT;
+}
+
+static bool
+parse_help(const char *str)
+{
+ fprintf(stderr, "Layer params using VK_LAYER_MESA_OVERLAY_CONFIG=\n");
+#define OVERLAY_PARAM_BOOL(name) \
+ fprintf(stderr, "\t%s=0/1\n", #name);
+#define OVERLAY_PARAM_CUSTOM(name)
+ OVERLAY_PARAMS
+#undef OVERLAY_PARAM_BOOL
+#undef OVERLAY_PARAM_CUSTOM
+ fprintf(stderr, "\tposition=\n"
+ "\t\ttop-left\n"
+ "\t\ttop-right\n"
+ "\t\tbottom-left\n"
+ "\t\tbottom-right\n");
+
+ return true;
+}
+
+static bool is_delimiter(char c)
+{
+ return c == 0 || c == ',' || c == ':' || c == ';' || c == '=';
+}
+
+static int
+parse_string(const char *s, char *out_param, char *out_value)
+{
+ int i = 0;
+
+ for (; !is_delimiter(*s); s++, out_param++, i++)
+ *out_param = *s;
+
+ *out_param = 0;
+
+ if (*s == '=') {
+ s++;
+ i++;
+ for (; !is_delimiter(*s); s++, out_value++, i++)
+ *out_value = *s;
+ }
+ *out_value = 0;
+
+ if (*s && is_delimiter(*s)) {
+ s++;
+ i++;
+ }
+
+ if (*s && !i) {
+ fprintf(stderr, "mesa-overlay: syntax error: unexpected '%c' (%i) while "
+ "parsing a string\n", *s, *s);
+ fflush(stderr);
+ }
+
+ return i;
+}
+
+const char *overlay_param_names[] = {
+#define OVERLAY_PARAM_BOOL(name) #name,
+#define OVERLAY_PARAM_CUSTOM(name)
+ OVERLAY_PARAMS
+#undef OVERLAY_PARAM_BOOL
+#undef OVERLAY_PARAM_CUSTOM
+};
+
+void
+parse_overlay_env(struct overlay_params *params,
+ const char *env)
+{
+ uint32_t num;
+ char key[256], value[256];
+
+ memset(params, 0, sizeof(*params));
+
+ /* Visible by default */
+ params->enabled[OVERLAY_PARAM_ENABLED_fps] = true;
+ params->enabled[OVERLAY_PARAM_ENABLED_frame_timing] = true;
+
+ if (!env)
+ return;
+
+ while ((num = parse_string(env, key, value)) != 0) {
+ env += num;
+
+#define OVERLAY_PARAM_BOOL(name) \
+ if (!strcmp(#name, key)) { \
+ params->enabled[OVERLAY_PARAM_ENABLED_##name] = strtol(value, NULL, 0); \
+ continue; \
+ }
+#define OVERLAY_PARAM_CUSTOM(name) \
+ if (!strcmp(#name, key)) { \
+ params->name = parse_##name(value); \
+ continue; \
+ }
+ OVERLAY_PARAMS
+#undef OVERLAY_PARAM_BOOL
+#undef OVERLAY_PARAM_CUSTOM
+ fprintf(stderr, "Unknown option '%s'\n", key);
+ }
+}