master
h 88 lines 2.25 KB
Raw
1 /*
2 * SPDX-License-Identifier: GPL-2.0-or-later
3 * QEMU UI Console
4 */
5 #ifndef SURFACE_H
6 #define SURFACE_H
7
8 #include "ui/qemu-pixman.h"
9
10 #ifdef CONFIG_OPENGL
11 # include "ui/shader.h"
12 #endif
13
14 #define QEMU_ALLOCATED_FLAG 0x01
15 #define QEMU_PLACEHOLDER_FLAG 0x02
16
17 typedef struct DisplaySurface {
18 pixman_image_t *image;
19 uint8_t flags;
20 #ifdef CONFIG_OPENGL
21 uint32_t texture;
22 #endif
23 qemu_pixman_shareable share_handle;
24 uint32_t share_handle_offset;
25 } DisplaySurface;
26
27 DisplaySurface *qemu_create_displaysurface_from(int width, int height,
28 pixman_format_code_t format,
29 int linesize, uint8_t *data);
30 DisplaySurface *qemu_create_displaysurface_pixman(pixman_image_t *image);
31 DisplaySurface *qemu_create_placeholder_surface(int w, int h,
32 const char *msg);
33
34 void qemu_displaysurface_set_share_handle(DisplaySurface *surface,
35 qemu_pixman_shareable handle,
36 uint32_t offset);
37
38 DisplaySurface *qemu_create_displaysurface(int width, int height);
39 void qemu_free_displaysurface(DisplaySurface *surface);
40
41 static inline int surface_is_allocated(DisplaySurface *surface)
42 {
43 return surface->flags & QEMU_ALLOCATED_FLAG;
44 }
45
46 static inline int surface_is_placeholder(DisplaySurface *surface)
47 {
48 return surface->flags & QEMU_PLACEHOLDER_FLAG;
49 }
50
51 static inline int surface_stride(DisplaySurface *s)
52 {
53 return pixman_image_get_stride(s->image);
54 }
55
56 static inline void *surface_data(DisplaySurface *s)
57 {
58 return pixman_image_get_data(s->image);
59 }
60
61 static inline int surface_width(DisplaySurface *s)
62 {
63 return pixman_image_get_width(s->image);
64 }
65
66 static inline int surface_height(DisplaySurface *s)
67 {
68 return pixman_image_get_height(s->image);
69 }
70
71 static inline pixman_format_code_t surface_format(DisplaySurface *s)
72 {
73 return pixman_image_get_format(s->image);
74 }
75
76 static inline int surface_bits_per_pixel(DisplaySurface *s)
77 {
78 int bits = PIXMAN_FORMAT_BPP(surface_format(s));
79 return bits;
80 }
81
82 static inline int surface_bytes_per_pixel(DisplaySurface *s)
83 {
84 int bits = PIXMAN_FORMAT_BPP(surface_format(s));
85 return DIV_ROUND_UP(bits, 8);
86 }
87
88 #endif