2 * Copyright © 2019 Intel Corporation
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
28 #include "overlay_params.h"
30 static enum overlay_param_position
31 parse_position(const char *str
)
33 if (!str
|| !strcmp(str
, "top-left"))
34 return LAYER_POSITION_TOP_LEFT
;
35 if (!strcmp(str
, "top-right"))
36 return LAYER_POSITION_TOP_RIGHT
;
37 if (!strcmp(str
, "bottom-left"))
38 return LAYER_POSITION_BOTTOM_LEFT
;
39 if (!strcmp(str
, "bottom-right"))
40 return LAYER_POSITION_BOTTOM_RIGHT
;
41 return LAYER_POSITION_TOP_LEFT
;
45 parse_output_file(const char *str
)
47 return fopen(str
, "w+");
51 parse_fps_sampling_period(const char *str
)
53 return strtol(str
, NULL
, 0) * 1000;
57 parse_no_display(const char *str
)
59 return strtol(str
, NULL
, 0) != 0;
63 parse_help(const char *str
)
65 fprintf(stderr
, "Layer params using VK_LAYER_MESA_OVERLAY_CONFIG=\n");
66 #define OVERLAY_PARAM_BOOL(name) \
67 fprintf(stderr, "\t%s=0|1\n", #name);
68 #define OVERLAY_PARAM_CUSTOM(name)
70 #undef OVERLAY_PARAM_BOOL
71 #undef OVERLAY_PARAM_CUSTOM
72 fprintf(stderr
, "\tposition=top-left|top-right|bottom-left|bottom-right\n");
73 fprintf(stderr
, "\tfps_sampling_period=number-of-milliseconds\n");
74 fprintf(stderr
, "\tno_display=0|1\n");
75 fprintf(stderr
, "\toutput_file=/path/to/output.txt\n");
80 static bool is_delimiter(char c
)
82 return c
== 0 || c
== ',' || c
== ':' || c
== ';' || c
== '=';
86 parse_string(const char *s
, char *out_param
, char *out_value
)
90 for (; !is_delimiter(*s
); s
++, out_param
++, i
++)
98 for (; !is_delimiter(*s
); s
++, out_value
++, i
++)
101 *(out_value
++) = '1';
104 if (*s
&& is_delimiter(*s
)) {
110 fprintf(stderr
, "mesa-overlay: syntax error: unexpected '%c' (%i) while "
111 "parsing a string\n", *s
, *s
);
118 const char *overlay_param_names
[] = {
119 #define OVERLAY_PARAM_BOOL(name) #name,
120 #define OVERLAY_PARAM_CUSTOM(name)
122 #undef OVERLAY_PARAM_BOOL
123 #undef OVERLAY_PARAM_CUSTOM
127 parse_overlay_env(struct overlay_params
*params
,
131 char key
[256], value
[256];
133 memset(params
, 0, sizeof(*params
));
135 /* Visible by default */
136 params
->enabled
[OVERLAY_PARAM_ENABLED_fps
] = true;
137 params
->enabled
[OVERLAY_PARAM_ENABLED_frame_timing
] = true;
138 params
->fps_sampling_period
= 500000; /* 500ms */
143 while ((num
= parse_string(env
, key
, value
)) != 0) {
146 #define OVERLAY_PARAM_BOOL(name) \
147 if (!strcmp(#name, key)) { \
148 params->enabled[OVERLAY_PARAM_ENABLED_##name] = \
149 strtol(value, NULL, 0); \
152 #define OVERLAY_PARAM_CUSTOM(name) \
153 if (!strcmp(#name, key)) { \
154 params->name = parse_##name(value); \
158 #undef OVERLAY_PARAM_BOOL
159 #undef OVERLAY_PARAM_CUSTOM
160 fprintf(stderr
, "Unknown option '%s'\n", key
);