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