vtest: refactor vtest_server_run_renderer

Refactor command dispatching to a separate function,
vtest_client_dispatch_commands.

Signed-off-by: Chia-I Wu <olvaffe@gmail.com>
Reviewed-By: Gert Wollny <gert.wollny@collabora.com>
Reviewed-By: Gurchetan Singh <gurchetansingh@chromium.org>
macos/master
Chia-I Wu 5 years ago
parent 3b8bf6b3eb
commit b88a34d5d3
  1. 121
      vtest/vtest_server.c

@ -102,6 +102,7 @@ static void vtest_server_run_renderer(struct vtest_client *client);
static void vtest_server_wait_for_socket_accept(void); static void vtest_server_wait_for_socket_accept(void);
static void vtest_server_tidy_fds(void); static void vtest_server_tidy_fds(void);
static void vtest_server_close_socket(void); static void vtest_server_close_socket(void);
static int vtest_client_dispatch_commands(struct vtest_client *client);
int main(int argc, char **argv) int main(int argc, char **argv)
@ -367,6 +368,33 @@ static void vtest_server_wait_for_socket_accept(void)
client->input.read = vtest_block_read; client->input.read = vtest_block_read;
} }
static void vtest_server_run_renderer(struct vtest_client *client)
{
int err, ret;
do {
ret = vtest_wait_for_fd_read(client->in_fd);
if (ret < 0) {
err = 1;
break;
}
err = vtest_client_dispatch_commands(client);
if (err) {
break;
}
} while (1);
fprintf(stderr, "socket failed (%d) - closing renderer\n", err);
if (client->context) {
vtest_destroy_context(client->context);
client->context = NULL;
}
vtest_cleanup_renderer();
}
typedef int (*vtest_cmd_fptr_t)(uint32_t); typedef int (*vtest_cmd_fptr_t)(uint32_t);
static const vtest_cmd_fptr_t vtest_commands[] = { static const vtest_cmd_fptr_t vtest_commands[] = {
@ -387,78 +415,57 @@ static const vtest_cmd_fptr_t vtest_commands[] = {
vtest_transfer_put2, vtest_transfer_put2,
}; };
static void vtest_server_run_renderer(struct vtest_client *client) static int vtest_client_dispatch_commands(struct vtest_client *client)
{ {
int err, ret; int ret;
uint32_t header[VTEST_HDR_SIZE]; uint32_t header[VTEST_HDR_SIZE];
do { ret = client->input.read(&client->input, &header, sizeof(header));
ret = vtest_wait_for_fd_read(client->in_fd); if (ret < 0 || (size_t)ret < sizeof(header)) {
if (ret < 0) { return 2;
err = 1; }
break;
}
ret = client->input.read(&client->input, &header, sizeof(header));
if (ret < 0 || (size_t)ret < sizeof(header)) {
err = 2;
break;
}
if (!client->context) { if (!client->context) {
/* The first command MUST be VCMD_CREATE_RENDERER */ /* The first command MUST be VCMD_CREATE_RENDERER */
if (header[1] != VCMD_CREATE_RENDERER) { if (header[1] != VCMD_CREATE_RENDERER) {
err = 3; return 3;
break;
}
ret = vtest_init_renderer(server.ctx_flags, server.render_device);
if (ret >= 0) {
ret = vtest_create_context(&client->input, client->out_fd,
header[0], &client->context);
}
if (ret < 0) {
err = 4;
break;
}
printf("%s: vtest initialized.\n", __func__);
vtest_set_current_context(client->context);
vtest_poll();
continue;
} }
vtest_poll(); ret = vtest_init_renderer(server.ctx_flags, server.render_device);
if (header[1] <= 0 || header[1] >= ARRAY_SIZE(vtest_commands)) { if (ret >= 0) {
err = 5; ret = vtest_create_context(&client->input, client->out_fd,
break; header[0], &client->context);
}
if (vtest_commands[header[1]] == NULL) {
err = 6;
break;
} }
ret = vtest_commands[header[1]](header[0]);
if (ret < 0) { if (ret < 0) {
err = 7; return 4;
break;
} }
printf("%s: vtest initialized.\n", __func__);
vtest_set_current_context(client->context);
vtest_poll();
/* GL draws are fenced, while possible fence creations are too */ return 0;
if (header[1] == VCMD_SUBMIT_CMD || header[1] == VCMD_RESOURCE_CREATE || }
header[1] == VCMD_RESOURCE_CREATE2)
vtest_renderer_create_fence();
} while (1); vtest_poll();
if (header[1] <= 0 || header[1] >= ARRAY_SIZE(vtest_commands)) {
return 5;
}
fprintf(stderr, "socket failed (%d) - closing renderer\n", err); if (vtest_commands[header[1]] == NULL) {
return 6;
}
if (client->context) { ret = vtest_commands[header[1]](header[0]);
vtest_destroy_context(client->context); if (ret < 0) {
client->context = NULL; return 7;
} }
vtest_cleanup_renderer(); /* GL draws are fenced, while possible fence creations are too */
if (header[1] == VCMD_SUBMIT_CMD || header[1] == VCMD_RESOURCE_CREATE ||
header[1] == VCMD_RESOURCE_CREATE2)
vtest_renderer_create_fence();
return 0;
} }
static void vtest_server_tidy_fds(void) static void vtest_server_tidy_fds(void)

Loading…
Cancel
Save