xref: /openbmc/qemu/include/ui/surface.h (revision 1c37425423f60c3e0deec6e942cfb17982fd8b6d)
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     GLuint mem_obj;
26 #endif
27     qemu_pixman_shareable share_handle;
28     uint32_t share_handle_offset;
29 } DisplaySurface;
30 
31 PixelFormat qemu_default_pixelformat(int bpp);
32 
33 DisplaySurface *qemu_create_displaysurface_from(int width, int height,
34                                                 pixman_format_code_t format,
35                                                 int linesize, uint8_t *data);
36 DisplaySurface *qemu_create_displaysurface_pixman(pixman_image_t *image);
37 DisplaySurface *qemu_create_placeholder_surface(int w, int h,
38                                                 const char *msg);
39 
40 void qemu_displaysurface_set_share_handle(DisplaySurface *surface,
41                                           qemu_pixman_shareable handle,
42                                           uint32_t offset);
43 
44 DisplaySurface *qemu_create_displaysurface(int width, int height);
45 void qemu_free_displaysurface(DisplaySurface *surface);
46 
surface_is_allocated(DisplaySurface * surface)47 static inline int surface_is_allocated(DisplaySurface *surface)
48 {
49     return surface->flags & QEMU_ALLOCATED_FLAG;
50 }
51 
surface_is_placeholder(DisplaySurface * surface)52 static inline int surface_is_placeholder(DisplaySurface *surface)
53 {
54     return surface->flags & QEMU_PLACEHOLDER_FLAG;
55 }
56 
surface_stride(DisplaySurface * s)57 static inline int surface_stride(DisplaySurface *s)
58 {
59     return pixman_image_get_stride(s->image);
60 }
61 
surface_data(DisplaySurface * s)62 static inline void *surface_data(DisplaySurface *s)
63 {
64     return pixman_image_get_data(s->image);
65 }
66 
surface_width(DisplaySurface * s)67 static inline int surface_width(DisplaySurface *s)
68 {
69     return pixman_image_get_width(s->image);
70 }
71 
surface_height(DisplaySurface * s)72 static inline int surface_height(DisplaySurface *s)
73 {
74     return pixman_image_get_height(s->image);
75 }
76 
surface_format(DisplaySurface * s)77 static inline pixman_format_code_t surface_format(DisplaySurface *s)
78 {
79     return pixman_image_get_format(s->image);
80 }
81 
surface_bits_per_pixel(DisplaySurface * s)82 static inline int surface_bits_per_pixel(DisplaySurface *s)
83 {
84     int bits = PIXMAN_FORMAT_BPP(surface_format(s));
85     return bits;
86 }
87 
surface_bytes_per_pixel(DisplaySurface * s)88 static inline int surface_bytes_per_pixel(DisplaySurface *s)
89 {
90     int bits = PIXMAN_FORMAT_BPP(surface_format(s));
91     return DIV_ROUND_UP(bits, 8);
92 }
93 
94 #endif
95