vulkan/overlay: Add a control socket.
authorRafael Antognolli <rafael.antognolli@intel.com>
Fri, 6 Dec 2019 22:38:07 +0000 (14:38 -0800)
committerRafael Antognolli <rafael.antognolli@intel.com>
Fri, 13 Dec 2019 20:53:44 +0000 (20:53 +0000)
v2: Use a socket instead of named pipe.

Reviewed-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com>
src/vulkan/overlay-layer/overlay.cpp
src/vulkan/overlay-layer/overlay_params.c
src/vulkan/overlay-layer/overlay_params.h

index 652478407e7ac073b8dd50c1b67b45f8330cb40d..f1cfb172b19c1c2e43ac76bc47736f957cf635a6 100644 (file)
@@ -37,6 +37,7 @@
 #include "util/list.h"
 #include "util/ralloc.h"
 #include "util/os_time.h"
+#include "util/os_socket.h"
 #include "util/simple_mtx.h"
 
 #include "vk_enum_to_str.h"
@@ -320,6 +321,8 @@ static void destroy_instance_data(struct instance_data *data)
 {
    if (data->params.output_file)
       fclose(data->params.output_file);
+   if (data->params.control >= 0)
+      os_socket_close(data->params.control);
    unmap_object(HKEY(data->instance));
    ralloc_free(data);
 }
index 2a09b6cf081d9ebebea41d009345ecd0ea1567ee..afc17ec07a92451b4a9d23eff9741ce51815d180 100644 (file)
 #include <stdio.h>
 #include <string.h>
 #include <stdlib.h>
+#include <string.h>
+#include <errno.h>
 
 #include "overlay_params.h"
 
+#include "util/os_socket.h"
+
 static enum overlay_param_position
 parse_position(const char *str)
 {
@@ -47,6 +51,21 @@ parse_output_file(const char *str)
    return fopen(str, "w+");
 }
 
+static int
+parse_control(const char *str)
+{
+   int ret = os_socket_listen_abstract(str, 1);
+   if (ret < 0) {
+      fprintf(stderr, "ERROR: Couldn't create socket pipe at '%s'\n", str);
+      fprintf(stderr, "ERROR: '%s'\n", strerror(errno));
+      return ret;
+   }
+
+   os_socket_block(ret, false);
+
+   return ret;
+}
+
 static uint32_t
 parse_fps_sampling_period(const char *str)
 {
@@ -148,6 +167,7 @@ parse_overlay_env(struct overlay_params *params,
    params->enabled[OVERLAY_PARAM_ENABLED_frame_timing] = true;
    params->fps_sampling_period = 500000; /* 500ms */
    params->width = params->height = 300;
+   params->control = -1;
 
    if (!env)
       return;
index a145dd429340b9b1e5aeee322b859f49b6dc9d63..7ff092daeff18c251caf3aeb83e8c99bd157a9e0 100644 (file)
@@ -69,6 +69,7 @@ extern "C" {
    OVERLAY_PARAM_CUSTOM(width)                       \
    OVERLAY_PARAM_CUSTOM(height)                      \
    OVERLAY_PARAM_CUSTOM(no_display)                  \
+   OVERLAY_PARAM_CUSTOM(control)                     \
    OVERLAY_PARAM_CUSTOM(help)
 
 enum overlay_param_position {
@@ -91,6 +92,7 @@ struct overlay_params {
    bool enabled[OVERLAY_PARAM_ENABLED_MAX];
    enum overlay_param_position position;
    FILE *output_file;
+   int control;
    uint32_t fps_sampling_period; /* us */
    bool help;
    bool no_display;