xref: /qemu/include/ui/surface.h (revision ec818df0005d1598d249f0cfea557226b6ad89a6)
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 <epoxy/gl.h>
12 # include "ui/shader.h"
13 #endif
14 
15 #define QEMU_ALLOCATED_FLAG     0x01
16 #define QEMU_PLACEHOLDER_FLAG   0x02
17 
18 typedef struct DisplaySurface {
19     pixman_image_t *image;
20     uint8_t flags;
21 #ifdef CONFIG_OPENGL
22     GLenum glformat;
23     GLenum gltype;
24     GLuint texture;
25 #endif
26 #ifdef WIN32
27     HANDLE handle;
28     uint32_t handle_offset;
29 #else
30     int shmfd;
31     uint32_t shmfd_offset;
32 #endif
33 } DisplaySurface;
34 
35 PixelFormat qemu_default_pixelformat(int bpp);
36 
37 DisplaySurface *qemu_create_displaysurface_from(int width, int height,
38                                                 pixman_format_code_t format,
39                                                 int linesize, uint8_t *data);
40 DisplaySurface *qemu_create_displaysurface_pixman(pixman_image_t *image);
41 DisplaySurface *qemu_create_placeholder_surface(int w, int h,
42                                                 const char *msg);
43 #ifdef WIN32
44 void qemu_displaysurface_win32_set_handle(DisplaySurface *surface,
45                                           HANDLE h, uint32_t offset);
46 #else
47 void qemu_displaysurface_set_shmfd(DisplaySurface *surface,
48                                    int shmfd, uint32_t offset);
49 #endif
50 
51 DisplaySurface *qemu_create_displaysurface(int width, int height);
52 void qemu_free_displaysurface(DisplaySurface *surface);
53 
54 static inline int surface_is_allocated(DisplaySurface *surface)
55 {
56     return surface->flags & QEMU_ALLOCATED_FLAG;
57 }
58 
59 static inline int surface_is_placeholder(DisplaySurface *surface)
60 {
61     return surface->flags & QEMU_PLACEHOLDER_FLAG;
62 }
63 
64 static inline int surface_stride(DisplaySurface *s)
65 {
66     return pixman_image_get_stride(s->image);
67 }
68 
69 static inline void *surface_data(DisplaySurface *s)
70 {
71     return pixman_image_get_data(s->image);
72 }
73 
74 static inline int surface_width(DisplaySurface *s)
75 {
76     return pixman_image_get_width(s->image);
77 }
78 
79 static inline int surface_height(DisplaySurface *s)
80 {
81     return pixman_image_get_height(s->image);
82 }
83 
84 static inline pixman_format_code_t surface_format(DisplaySurface *s)
85 {
86     return pixman_image_get_format(s->image);
87 }
88 
89 static inline int surface_bits_per_pixel(DisplaySurface *s)
90 {
91     int bits = PIXMAN_FORMAT_BPP(surface_format(s));
92     return bits;
93 }
94 
95 static inline int surface_bytes_per_pixel(DisplaySurface *s)
96 {
97     int bits = PIXMAN_FORMAT_BPP(surface_format(s));
98     return DIV_ROUND_UP(bits, 8);
99 }
100 
101 #endif
102