Merge tag 'pull-sp-20240412' of https://gitlab.com/rth7680/qemu into staging
[qemu/armbru.git] / include / ui / surface.h
blob4244e0ca4a3298dde2f4fdda7d8de3410894f6a6
1 /*
2 * SPDX-License-Identifier: GPL-2.0-or-later
3 * QEMU UI Console
4 */
5 #ifndef SURFACE_H
6 #define SURFACE_H
8 #include "ui/qemu-pixman.h"
10 #ifdef CONFIG_OPENGL
11 # include <epoxy/gl.h>
12 # include "ui/shader.h"
13 #endif
15 #define QEMU_ALLOCATED_FLAG 0x01
16 #define QEMU_PLACEHOLDER_FLAG 0x02
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 #endif
30 } DisplaySurface;
32 PixelFormat qemu_default_pixelformat(int bpp);
34 DisplaySurface *qemu_create_displaysurface_from(int width, int height,
35 pixman_format_code_t format,
36 int linesize, uint8_t *data);
37 DisplaySurface *qemu_create_displaysurface_pixman(pixman_image_t *image);
38 DisplaySurface *qemu_create_placeholder_surface(int w, int h,
39 const char *msg);
40 #ifdef WIN32
41 void qemu_displaysurface_win32_set_handle(DisplaySurface *surface,
42 HANDLE h, uint32_t offset);
43 #endif
45 DisplaySurface *qemu_create_displaysurface(int width, int height);
46 void qemu_free_displaysurface(DisplaySurface *surface);
48 static inline int is_buffer_shared(DisplaySurface *surface)
50 return !(surface->flags & QEMU_ALLOCATED_FLAG);
53 static inline int is_placeholder(DisplaySurface *surface)
55 return surface->flags & QEMU_PLACEHOLDER_FLAG;
58 static inline int surface_stride(DisplaySurface *s)
60 return pixman_image_get_stride(s->image);
63 static inline void *surface_data(DisplaySurface *s)
65 return pixman_image_get_data(s->image);
68 static inline int surface_width(DisplaySurface *s)
70 return pixman_image_get_width(s->image);
73 static inline int surface_height(DisplaySurface *s)
75 return pixman_image_get_height(s->image);
78 static inline pixman_format_code_t surface_format(DisplaySurface *s)
80 return pixman_image_get_format(s->image);
83 static inline int surface_bits_per_pixel(DisplaySurface *s)
85 int bits = PIXMAN_FORMAT_BPP(surface_format(s));
86 return bits;
89 static inline int surface_bytes_per_pixel(DisplaySurface *s)
91 int bits = PIXMAN_FORMAT_BPP(surface_format(s));
92 return DIV_ROUND_UP(bits, 8);
95 #endif