ui: move DisplaySurface functions to display-surface.c
Extract DisplaySurface creation and destruction functions from console.c into their own file to reduce the size of console.c and improve code organization. Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Marc-André Lureau committed
Feb 16, 2026 at 18:41 UTC
dcc580c8d827db1c4d1e749c4145ba1620bcc97a
3 files changed
+108
-96
ui/console.c
-96
@@ -505,102 +505,6 @@ qemu_graphic_console_init(Object *obj)
505
{
506
}
507
508
-void qemu_displaysurface_set_share_handle(DisplaySurface *surface,
509
- qemu_pixman_shareable handle,
510
- uint32_t offset)
511
-{
512
- assert(surface->share_handle == SHAREABLE_NONE);
513
-
514
- surface->share_handle = handle;
515
- surface->share_handle_offset = offset;
516
-
517
-}
518
-
519
-DisplaySurface *qemu_create_displaysurface(int width, int height)
520
-{
521
- trace_displaysurface_create(width, height);
522
-
523
- return qemu_create_displaysurface_from(
524
- width, height,
525
- PIXMAN_x8r8g8b8,
526
- width * 4, NULL
527
- );
528
-}
529
-
530
-DisplaySurface *qemu_create_displaysurface_from(int width, int height,
531
- pixman_format_code_t format,
532
- int linesize, uint8_t *data)
533
-{
534
- DisplaySurface *surface = g_new0(DisplaySurface, 1);
535
-
536
- trace_displaysurface_create_from(surface, width, height, format);
537
- surface->share_handle = SHAREABLE_NONE;
538
-
539
- if (data) {
540
- surface->image = pixman_image_create_bits(format,
541
- width, height,
542
- (void *)data, linesize);
543
- } else {
544
- qemu_pixman_image_new_shareable(&surface->image,
545
- &surface->share_handle,
546
- "displaysurface",
547
- format,
548
- width,
549
- height,
550
- linesize,
551
- &error_abort);
552
- surface->flags = QEMU_ALLOCATED_FLAG;
553
- }
554
-
555
- assert(surface->image != NULL);
556
- return surface;
557
-}
558
-
559
-DisplaySurface *qemu_create_displaysurface_pixman(pixman_image_t *image)
560
-{
561
- DisplaySurface *surface = g_new0(DisplaySurface, 1);
562
-
563
- trace_displaysurface_create_pixman(surface);
564
- surface->share_handle = SHAREABLE_NONE;
565
- surface->image = pixman_image_ref(image);
566
-
567
- return surface;
568
-}
569
-
570
-DisplaySurface *qemu_create_placeholder_surface(int w, int h,
571
- const char *msg)
572
-{
573
- DisplaySurface *surface = qemu_create_displaysurface(w, h);
574
-#ifdef CONFIG_PIXMAN
575
- pixman_color_t bg = QEMU_PIXMAN_COLOR_BLACK;
576
- pixman_color_t fg = QEMU_PIXMAN_COLOR_GRAY;
577
- pixman_image_t *glyph;
578
- int len, x, y, i;
579
-
580
- len = strlen(msg);
581
- x = (w / FONT_WIDTH - len) / 2;
582
- y = (h / FONT_HEIGHT - 1) / 2;
583
- for (i = 0; i < len; i++) {
584
- glyph = qemu_pixman_glyph_from_vgafont(FONT_HEIGHT, vgafont16, msg[i]);
585
- qemu_pixman_glyph_render(glyph, surface->image, &fg, &bg,
586
- x+i, y, FONT_WIDTH, FONT_HEIGHT);
587
- qemu_pixman_image_unref(glyph);
588
- }
589
-#endif
590
- surface->flags |= QEMU_PLACEHOLDER_FLAG;
591
- return surface;
592
-}
593
-
594
-void qemu_free_displaysurface(DisplaySurface *surface)
595
-{
596
- if (surface == NULL) {
597
- return;
598
- }
599
- trace_displaysurface_free(surface);
600
- qemu_pixman_image_unref(surface->image);
601
- g_free(surface);
602
-}
603
-
508
bool console_has_gl(QemuConsole *con)
509
{
510
return con->gl != NULL;
ui/display-surface.c
new
+107
@@ -0,0 +1,107 @@
1
+/*
2
+ * QEMU graphical console surface helper
3
+ *
4
+ * Copyright (c) 2004 Fabrice Bellard
5
+ *
6
+ * SPDX-License-Identifier: MIT
7
+ */
8
+#include "qemu/osdep.h"
9
+#include "ui/console.h"
10
+#include "ui/vgafont.h"
11
+#include "trace.h"
12
+
13
+void qemu_displaysurface_set_share_handle(DisplaySurface *surface,
14
+ qemu_pixman_shareable handle,
15
+ uint32_t offset)
16
+{
17
+ assert(surface->share_handle == SHAREABLE_NONE);
18
+
19
+ surface->share_handle = handle;
20
+ surface->share_handle_offset = offset;
21
+
22
+}
23
+
24
+DisplaySurface *qemu_create_displaysurface(int width, int height)
25
+{
26
+ trace_displaysurface_create(width, height);
27
+
28
+ return qemu_create_displaysurface_from(
29
+ width, height,
30
+ PIXMAN_x8r8g8b8,
31
+ width * 4, NULL
32
+ );
33
+}
34
+
35
+DisplaySurface *qemu_create_displaysurface_from(int width, int height,
36
+ pixman_format_code_t format,
37
+ int linesize, uint8_t *data)
38
+{
39
+ DisplaySurface *surface = g_new0(DisplaySurface, 1);
40
+
41
+ trace_displaysurface_create_from(surface, width, height, format);
42
+ surface->share_handle = SHAREABLE_NONE;
43
+
44
+ if (data) {
45
+ surface->image = pixman_image_create_bits(format,
46
+ width, height,
47
+ (void *)data, linesize);
48
+ } else {
49
+ qemu_pixman_image_new_shareable(&surface->image,
50
+ &surface->share_handle,
51
+ "displaysurface",
52
+ format,
53
+ width,
54
+ height,
55
+ linesize,
56
+ &error_abort);
57
+ surface->flags = QEMU_ALLOCATED_FLAG;
58
+ }
59
+
60
+ assert(surface->image != NULL);
61
+ return surface;
62
+}
63
+
64
+DisplaySurface *qemu_create_displaysurface_pixman(pixman_image_t *image)
65
+{
66
+ DisplaySurface *surface = g_new0(DisplaySurface, 1);
67
+
68
+ trace_displaysurface_create_pixman(surface);
69
+ surface->share_handle = SHAREABLE_NONE;
70
+ surface->image = pixman_image_ref(image);
71
+
72
+ return surface;
73
+}
74
+
75
+DisplaySurface *qemu_create_placeholder_surface(int w, int h,
76
+ const char *msg)
77
+{
78
+ DisplaySurface *surface = qemu_create_displaysurface(w, h);
79
+#ifdef CONFIG_PIXMAN
80
+ pixman_color_t bg = QEMU_PIXMAN_COLOR_BLACK;
81
+ pixman_color_t fg = QEMU_PIXMAN_COLOR_GRAY;
82
+ pixman_image_t *glyph;
83
+ int len, x, y, i;
84
+
85
+ len = strlen(msg);
86
+ x = (w / FONT_WIDTH - len) / 2;
87
+ y = (h / FONT_HEIGHT - 1) / 2;
88
+ for (i = 0; i < len; i++) {
89
+ glyph = qemu_pixman_glyph_from_vgafont(FONT_HEIGHT, vgafont16, msg[i]);
90
+ qemu_pixman_glyph_render(glyph, surface->image, &fg, &bg,
91
+ x + i, y, FONT_WIDTH, FONT_HEIGHT);
92
+ qemu_pixman_image_unref(glyph);
93
+ }
94
+#endif
95
+ surface->flags |= QEMU_PLACEHOLDER_FLAG;
96
+ return surface;
97
+}
98
+
99
+void qemu_free_displaysurface(DisplaySurface *surface)
100
+{
101
+ if (surface == NULL) {
102
+ return;
103
+ }
104
+ trace_displaysurface_free(surface);
105
+ qemu_pixman_image_unref(surface->image);
106
+ g_free(surface);
107
+}
ui/meson.build
+1
@@ -4,6 +4,7 @@ system_ss.add(files(
4
'clipboard.c',
5
'console.c',
6
'cursor.c',
7
+ 'display-surface.c',
8
'dmabuf.c',
9
'input-keymap.c',
10
'input-legacy.c',