-
Notifications
You must be signed in to change notification settings - Fork 74
Expand file tree
/
Copy pathwindow-sw.c
More file actions
666 lines (597 loc) · 21 KB
/
Copy pathwindow-sw.c
File metadata and controls
666 lines (597 loc) · 21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
#include <SDL.h>
#include <inttypes.h>
#include <limits.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#if SEMU_HAS(VIRTIOGPU)
#include "vgpu-display.h"
#include "virtio-gpu.h"
#endif
#if SEMU_HAS(VIRTIOINPUT)
#include "virtio-input-event.h"
#endif
#include "window.h"
#define WINDOW_LOG_PREFIX "[SEMU WINDOW] "
static int wake_write_fd = -1;
static bool sdl_initialized = false;
static bool headless_mode = false;
static bool should_exit = false;
#if SEMU_HAS(VIRTIOINPUT)
static bool mouse_grabbed = false;
static SDL_Window *sdl_input_window;
#else
#define SDL_EVENT_WAIT_TIMEOUT_MS 1 /* ms */
#define SDL_EVENT_BURST_LIMIT 64U
#endif
#if SEMU_HAS(VIRTIOGPU)
/* SDL-owned retained state for a single plane. Textures live only on the SDL
* thread and are updated from immutable CPU-frame display resources.
*/
struct sdl_plane_info {
uint32_t width;
uint32_t height;
uint32_t sdl_format;
bool alpha_blend;
SDL_Texture *texture;
};
/* SDL-owned retained state for one scanout. 'window_init_sw()' creates the
* window/renderer, then 'window_drain_display_queue()' updates the primary and
* cursor planes from queued display payloads before rendering them.
*/
struct sdl_scanout_info {
struct sdl_plane_info primary_plane;
struct sdl_plane_info cursor_plane;
SDL_Rect cursor_rect;
uint32_t cursor_hot_x;
uint32_t cursor_hot_y;
uint32_t window_width;
uint32_t window_height;
SDL_Window *window;
SDL_Renderer *renderer;
};
static struct sdl_scanout_info sdl_scanouts[VIRTIO_GPU_MAX_SCANOUTS];
#endif
static void window_set_wake_fd_sw(int fd)
{
wake_write_fd = fd;
}
static void window_wake_backend_sw(void)
{
if (wake_write_fd >= 0) {
char byte = 1;
/* Best-effort wakeup: the pipe is non-blocking, and the byte value has
* no meaning beyond making the read end readable.
*/
ssize_t bytes_written = write(wake_write_fd, &byte, 1);
(void) bytes_written;
}
}
static void window_shutdown_sw(void)
{
/* Both user-driven close and emulator-driven shutdown funnel through the
* same flag so the main thread and emulator thread observe one exit state.
*/
__atomic_store_n(&should_exit, true, __ATOMIC_RELAXED);
/* Unblock any 'poll(-1)' in the SMP emulator loop immediately. */
window_wake_backend_sw();
}
static bool window_is_closed_sw(void)
{
return __atomic_load_n(&should_exit, __ATOMIC_RELAXED);
}
#if SEMU_HAS(VIRTIOINPUT)
/* Main-thread-only helper for relative-pointer devices. SDL's grab and
* relative mouse APIs are part of the windowing backend, so callers use this
* to switch between normal host-pointer mode and guest-directed mouse mode.
*/
static void window_set_mouse_grab_sw(bool grabbed)
{
if (headless_mode || !sdl_input_window) {
mouse_grabbed = false;
return;
}
if (mouse_grabbed == grabbed)
return;
if (grabbed) {
if (SDL_SetRelativeMouseMode(SDL_TRUE) < 0) {
fprintf(stderr,
"window_set_mouse_grab_sw(): failed to enable relative "
"mouse mode: %s\n",
SDL_GetError());
return;
}
SDL_SetWindowGrab(sdl_input_window, SDL_TRUE);
SDL_ShowCursor(SDL_DISABLE);
} else {
SDL_SetWindowGrab(sdl_input_window, SDL_FALSE);
SDL_SetRelativeMouseMode(SDL_FALSE);
SDL_ShowCursor(SDL_ENABLE);
}
mouse_grabbed = grabbed;
}
static bool window_is_mouse_grabbed_sw(void)
{
return mouse_grabbed;
}
#endif
#if SEMU_HAS(VIRTIOGPU)
static bool vgpu_format_to_sdl_format(enum virtio_gpu_formats virtio_gpu_format,
uint32_t *sdl_format)
{
switch (virtio_gpu_format) {
case VIRTIO_GPU_FORMAT_B8G8R8A8_UNORM:
*sdl_format = SDL_PIXELFORMAT_ARGB8888;
return true;
case VIRTIO_GPU_FORMAT_B8G8R8X8_UNORM:
*sdl_format = SDL_PIXELFORMAT_XRGB8888;
return true;
case VIRTIO_GPU_FORMAT_A8R8G8B8_UNORM:
*sdl_format = SDL_PIXELFORMAT_BGRA8888;
return true;
case VIRTIO_GPU_FORMAT_X8R8G8B8_UNORM:
*sdl_format = SDL_PIXELFORMAT_BGRX8888;
return true;
case VIRTIO_GPU_FORMAT_R8G8B8A8_UNORM:
*sdl_format = SDL_PIXELFORMAT_ABGR8888;
return true;
case VIRTIO_GPU_FORMAT_X8B8G8R8_UNORM:
*sdl_format = SDL_PIXELFORMAT_RGBX8888;
return true;
case VIRTIO_GPU_FORMAT_A8B8G8R8_UNORM:
*sdl_format = SDL_PIXELFORMAT_RGBA8888;
return true;
case VIRTIO_GPU_FORMAT_R8G8B8X8_UNORM:
*sdl_format = SDL_PIXELFORMAT_XBGR8888;
return true;
default:
return false;
}
}
static void sdl_plane_info_reset(struct sdl_plane_info *plane)
{
bool alpha_blend = plane->alpha_blend;
if (plane->texture)
SDL_DestroyTexture(plane->texture);
memset(plane, 0, sizeof(*plane));
plane->alpha_blend = alpha_blend;
}
static void sdl_plane_info_cleanup(struct sdl_plane_info *plane)
{
if (plane->texture)
SDL_DestroyTexture(plane->texture);
memset(plane, 0, sizeof(*plane));
}
static void sdl_scanout_info_cleanup(struct sdl_scanout_info *scanout)
{
sdl_plane_info_cleanup(&scanout->primary_plane);
sdl_plane_info_cleanup(&scanout->cursor_plane);
if (scanout->renderer)
SDL_DestroyRenderer(scanout->renderer);
if (scanout->window)
SDL_DestroyWindow(scanout->window);
memset(scanout, 0, sizeof(*scanout));
}
static bool sdl_plane_info_get_sdl_format(
const struct sdl_plane_info *plane,
const struct vgpu_display_payload *payload,
uint32_t *sdl_format)
{
/* The plane keeps its SDL objects across frames, but the payload format is
* still per-update data. Resolve the incoming VirtIO-GPU format first,
* then adjust it below if this plane requires alpha.
*/
const struct vgpu_display_cpu_payload *frame = &payload->cpu;
if (!vgpu_format_to_sdl_format(frame->format, sdl_format)) {
fprintf(stderr, "%s(): invalid resource format %u\n", __func__,
(uint32_t) frame->format);
return false;
}
/* Cursor textures need an alpha-capable SDL format. If the incoming format
* is an XRGB/XBGR/BGRX/RGBX variant, switch to the matching alpha version
* so the high byte is preserved as transparency instead of being ignored.
*/
if (plane->alpha_blend) {
switch (*sdl_format) {
case SDL_PIXELFORMAT_XRGB8888:
*sdl_format = SDL_PIXELFORMAT_ARGB8888;
break;
case SDL_PIXELFORMAT_BGRX8888:
*sdl_format = SDL_PIXELFORMAT_BGRA8888;
break;
case SDL_PIXELFORMAT_RGBX8888:
*sdl_format = SDL_PIXELFORMAT_RGBA8888;
break;
case SDL_PIXELFORMAT_XBGR8888:
*sdl_format = SDL_PIXELFORMAT_ABGR8888;
break;
default:
break;
}
}
return true;
}
static SDL_Texture *sdl_plane_info_create_texture(
SDL_Renderer *renderer,
const struct sdl_plane_info *plane,
const struct vgpu_display_cpu_payload *frame,
uint32_t sdl_format)
{
SDL_Texture *texture =
SDL_CreateTexture(renderer, sdl_format, SDL_TEXTUREACCESS_STREAMING,
frame->width, frame->height);
if (!texture) {
fprintf(stderr, "%s(): failed to create texture: %s\n", __func__,
SDL_GetError());
return NULL;
}
if (plane->alpha_blend) {
if (SDL_SetTextureBlendMode(texture, SDL_BLENDMODE_BLEND) < 0) {
fprintf(stderr, "%s(): failed to enable texture blending: %s\n",
__func__, SDL_GetError());
}
}
return texture;
}
static bool sdl_plane_info_update_texture(
SDL_Renderer *renderer,
struct sdl_plane_info *plane,
const struct vgpu_display_payload *payload,
const char *plane_name)
{
const struct vgpu_display_cpu_payload *frame = &payload->cpu;
uint32_t sdl_format;
if (!sdl_plane_info_get_sdl_format(plane, payload, &sdl_format))
return false;
bool reuse_texture = plane->texture && plane->width == frame->width &&
plane->height == frame->height &&
plane->sdl_format == sdl_format;
SDL_Texture *texture = plane->texture;
if (!reuse_texture) {
texture =
sdl_plane_info_create_texture(renderer, plane, frame, sdl_format);
if (!texture)
return false;
}
/* Keep the retained plane state unchanged until the new pixels are known
* to be uploaded successfully.
*/
if (SDL_UpdateTexture(texture, NULL, frame->pixels, frame->stride) != 0) {
fprintf(stderr, "%s(): failed to update %s texture: %s\n", __func__,
plane_name, SDL_GetError());
if (!reuse_texture)
SDL_DestroyTexture(texture);
return false;
}
if (!reuse_texture) {
if (plane->texture)
SDL_DestroyTexture(plane->texture);
plane->texture = texture;
}
plane->width = frame->width;
plane->height = frame->height;
plane->sdl_format = sdl_format;
return true;
}
static bool sdl_cursor_rect_update_position(SDL_Rect *rect,
int32_t x,
int32_t y,
uint32_t hot_x,
uint32_t hot_y)
{
int64_t rect_x = (int64_t) x - (int64_t) hot_x;
int64_t rect_y = (int64_t) y - (int64_t) hot_y;
if (rect_x < INT_MIN || rect_x > INT_MAX || rect_y < INT_MIN ||
rect_y > INT_MAX) {
fprintf(stderr,
WINDOW_LOG_PREFIX
"%s(): cursor position out of SDL range "
"(x=%" PRId32 " y=%" PRId32 " hot_x=%u hot_y=%u)\n",
__func__, x, y, (unsigned) hot_x, (unsigned) hot_y);
return false;
}
rect->x = (int) rect_x;
rect->y = (int) rect_y;
return true;
}
static bool sdl_scanout_apply_cursor_frame(
struct sdl_scanout_info *scanout,
const struct vgpu_display_payload *payload,
int32_t x,
int32_t y,
uint32_t hot_x,
uint32_t hot_y)
{
const struct vgpu_display_cpu_payload *frame = &payload->cpu;
struct sdl_plane_info *plane = &scanout->cursor_plane;
SDL_Rect new_cursor_rect = scanout->cursor_rect;
if (frame->width > INT_MAX || frame->height > INT_MAX) {
fprintf(stderr,
WINDOW_LOG_PREFIX
"%s(): cursor size out of SDL range (%ux%u)\n",
__func__, frame->width, frame->height);
return false;
}
if (!sdl_cursor_rect_update_position(&new_cursor_rect, x, y, hot_x, hot_y))
return false;
if (!sdl_plane_info_update_texture(scanout->renderer, plane, payload,
"cursor"))
return false;
scanout->cursor_hot_x = hot_x;
scanout->cursor_hot_y = hot_y;
new_cursor_rect.w = (int) frame->width;
new_cursor_rect.h = (int) frame->height;
scanout->cursor_rect = new_cursor_rect;
return true;
}
static void sdl_scanout_render(const struct sdl_scanout_info *scanout)
{
SDL_RenderClear(scanout->renderer);
if (scanout->primary_plane.texture)
SDL_RenderCopy(scanout->renderer, scanout->primary_plane.texture, NULL,
NULL);
if (scanout->cursor_plane.texture)
SDL_RenderCopy(scanout->renderer, scanout->cursor_plane.texture, NULL,
&scanout->cursor_rect);
SDL_RenderPresent(scanout->renderer);
}
static void window_drain_display_queue(void)
{
bool dirty_scanouts[VIRTIO_GPU_MAX_SCANOUTS] = {0};
struct vgpu_display_cmd cmd;
/* Drain display bridge commands, update only SDL-owned state, then render
* each affected scanout once. The bridge publishes reliable clear
* generations and filters stale lossy frame/move queue entries.
*/
while (vgpu_display_pop_cmd(&cmd)) {
/* 'scanout_id' was validated by the guest-facing backend before the
* command entered the display bridge.
*/
struct sdl_scanout_info *scanout = &sdl_scanouts[cmd.scanout_id];
if (!scanout->window || !scanout->renderer) {
vgpu_display_release_cmd(&cmd);
continue;
}
switch (cmd.type) {
case VGPU_DISPLAY_CMD_PRIMARY_CLEAR:
sdl_plane_info_reset(&scanout->primary_plane);
dirty_scanouts[cmd.scanout_id] = true;
break;
case VGPU_DISPLAY_CMD_CURSOR_CLEAR:
memset(&scanout->cursor_rect, 0, sizeof(scanout->cursor_rect));
scanout->cursor_hot_x = 0;
scanout->cursor_hot_y = 0;
sdl_plane_info_reset(&scanout->cursor_plane);
dirty_scanouts[cmd.scanout_id] = true;
break;
case VGPU_DISPLAY_CMD_PRIMARY_SET:
/* Use '|=' to keep earlier dirty state for this scanout. A failed
* upload leaves the old texture visible and does not dirty the
* scanout by itself.
*/
dirty_scanouts[cmd.scanout_id] |= sdl_plane_info_update_texture(
scanout->renderer, &scanout->primary_plane,
cmd.u.primary_set.payload, "primary");
break;
case VGPU_DISPLAY_CMD_CURSOR_SET:
/* Use '|=' to keep earlier dirty state for this scanout. A failed
* upload leaves the old cursor visible and does not dirty the
* scanout by itself.
*/
dirty_scanouts[cmd.scanout_id] |= sdl_scanout_apply_cursor_frame(
scanout, cmd.u.cursor_set.payload, cmd.u.cursor_set.x,
cmd.u.cursor_set.y, cmd.u.cursor_set.hot_x,
cmd.u.cursor_set.hot_y);
break;
case VGPU_DISPLAY_CMD_CURSOR_MOVE:
if (!sdl_cursor_rect_update_position(
&scanout->cursor_rect, cmd.u.cursor_move.x,
cmd.u.cursor_move.y, scanout->cursor_hot_x,
scanout->cursor_hot_y))
break;
dirty_scanouts[cmd.scanout_id] = true;
break;
}
vgpu_display_release_cmd(&cmd);
}
for (uint32_t i = 0; i < VIRTIO_GPU_MAX_SCANOUTS; i++) {
if (!dirty_scanouts[i] || !sdl_scanouts[i].window ||
!sdl_scanouts[i].renderer)
continue;
sdl_scanout_render(&sdl_scanouts[i]);
}
}
#endif
/* Main loop runs on the main thread */
static void window_main_loop_sw(void)
{
if (headless_mode) {
/* Block until the emulator calls 'window_shutdown_sw()', so 'main()'
* can proceed to 'pthread_join()' rather than stopping the emulator
* immediately. There is no SDL event loop in this mode, so the main
* thread just polls the shared close flag.
*/
while (!window_is_closed_sw())
usleep(10000);
return;
}
/* relaxed ordering is sufficient: the only consequence of reading a stale
* false is a few extra loop iterations. Ordering with the emulator thread
* is provided by 'pthread_join()', not by this flag.
*/
while (!window_is_closed_sw()) {
#if SEMU_HAS(VIRTIOINPUT)
if (vinput_handle_events()) {
/* User closed the window. Set the flag so 'window_shutdown_sw()'
* (called from the emulator thread) does not race with us, then
* return normally so 'main()' can 'pthread_join()' the emulator
* thread and collect its exit code.
*/
window_shutdown_sw();
return;
}
#else
SDL_Event e;
/* Without 'virtio-input', there is no SDL event pump to wake on display
* commands. Use a short timeout so 'VIRTIOGPU'-only builds periodically
* drain the display bridge; a future SDL user-event bridge could make
* this fully event-driven.
*/
if (SDL_WaitEventTimeout(&e, SDL_EVENT_WAIT_TIMEOUT_MS)) {
uint32_t processed = 0;
do {
if (e.type == SDL_QUIT) {
window_shutdown_sw();
return;
}
processed++;
} while (processed < SDL_EVENT_BURST_LIMIT && SDL_PollEvent(&e));
}
#endif
#if SEMU_HAS(VIRTIOGPU)
window_drain_display_queue();
#endif
}
}
static void window_init_sw(bool headless, uint32_t width, uint32_t height)
{
if (headless) {
headless_mode = true;
#if SEMU_HAS(VIRTIOGPU)
vgpu_display_set_unavailable();
#endif
return;
}
if (SDL_Init(SDL_INIT_VIDEO) < 0) {
fprintf(stderr,
"window_init_sw(): failed to initialize SDL: %s\n"
"Running in headless mode.\n",
SDL_GetError());
headless_mode = true;
#if SEMU_HAS(VIRTIOGPU)
vgpu_display_set_unavailable();
#endif
return;
}
sdl_initialized = true;
#if SEMU_HAS(VIRTIOGPU)
/* The current machine setup registers exactly one scanout before calling
* 'window_init_sw()', so materialize scanout 0 directly here. If semu grows
* multiple scanouts later, this can be extended to iterate all registered
* scanouts or restored to an explicit per-scanout setup path.
*/
struct sdl_scanout_info *scanout = &sdl_scanouts[0];
scanout->window = SDL_CreateWindow("semu", SDL_WINDOWPOS_UNDEFINED,
SDL_WINDOWPOS_UNDEFINED, width, height,
SDL_WINDOW_SHOWN);
if (!scanout->window) {
fprintf(stderr,
"window_init_sw(): failed to create SDL window for display "
"0: %s\n"
"Running in headless mode.\n",
SDL_GetError());
headless_mode = true;
SDL_Quit();
sdl_initialized = false;
vgpu_display_set_unavailable();
return;
}
scanout->renderer =
SDL_CreateRenderer(scanout->window, -1, SDL_RENDERER_ACCELERATED);
if (!scanout->renderer) {
fprintf(stderr,
"window_init_sw(): accelerated renderer not available, "
"trying software renderer: %s\n",
SDL_GetError());
scanout->renderer =
SDL_CreateRenderer(scanout->window, -1, SDL_RENDERER_SOFTWARE);
}
if (!scanout->renderer) {
fprintf(stderr,
"window_init_sw(): failed to create renderer for display "
"0: %s\n"
"Running in headless mode.\n",
SDL_GetError());
SDL_DestroyWindow(scanout->window);
scanout->window = NULL;
headless_mode = true;
SDL_Quit();
sdl_initialized = false;
vgpu_display_set_unavailable();
return;
}
scanout->window_width = width;
scanout->window_height = height;
scanout->cursor_plane.alpha_blend = true;
#if SEMU_HAS(VIRTIOINPUT)
if (!sdl_input_window)
sdl_input_window = scanout->window;
#endif
SDL_SetRenderDrawColor(scanout->renderer, 0, 0, 0, 255);
SDL_RenderClear(scanout->renderer);
SDL_RenderPresent(scanout->renderer);
#else /* !SEMU_HAS(VIRTIOGPU) */
sdl_input_window = SDL_CreateWindow("semu", SDL_WINDOWPOS_UNDEFINED,
SDL_WINDOWPOS_UNDEFINED, width, height,
SDL_WINDOW_SHOWN);
if (!sdl_input_window) {
fprintf(stderr,
"window_init_sw(): failed to create SDL window: %s\n"
"Running in headless mode.\n",
SDL_GetError());
headless_mode = true;
SDL_Quit();
sdl_initialized = false;
return;
}
#endif
}
static void window_cleanup_sw(void)
{
#if SEMU_HAS(VIRTIOINPUT)
if (sdl_initialized)
window_set_mouse_grab_sw(false);
/* Keep cleanup idempotent when SDL was never initialized or grab release
* returned early.
*/
mouse_grabbed = false;
#endif
wake_write_fd = -1;
#if SEMU_HAS(VIRTIOGPU)
for (uint32_t i = 0; i < VIRTIO_GPU_MAX_SCANOUTS; i++)
sdl_scanout_info_cleanup(&sdl_scanouts[i]);
struct vgpu_display_cmd cmd;
while (vgpu_display_pop_cmd(&cmd))
vgpu_display_release_cmd(&cmd);
#elif SEMU_HAS(VIRTIOINPUT)
if (sdl_input_window)
SDL_DestroyWindow(sdl_input_window);
#endif
#if SEMU_HAS(VIRTIOINPUT)
sdl_input_window = NULL;
#endif
if (sdl_initialized) {
SDL_Quit();
sdl_initialized = false;
}
/* Cleanup normally runs before process exit. Reset frontend flags anyway
* so a future re-init path cannot inherit stale headless/shutdown state.
*/
headless_mode = false;
should_exit = false;
}
const struct window_backend g_window = {
.window_init = window_init_sw,
.window_main_loop = window_main_loop_sw,
.window_shutdown = window_shutdown_sw,
.window_cleanup = window_cleanup_sw,
.window_is_closed = window_is_closed_sw,
.window_set_wake_fd = window_set_wake_fd_sw,
.window_wake_backend = window_wake_backend_sw,
#if SEMU_HAS(VIRTIOINPUT)
.window_set_mouse_grab = window_set_mouse_grab_sw,
.window_is_mouse_grabbed = window_is_mouse_grabbed_sw,
#endif
};