master
c 107 lines 3.22 KB
Raw
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 }