]> git.proxmox.com Git - mirror_qemu.git/blame - ui/egl-headless.c
i386: Update new x86_apicid parsing rules with die_offset support
[mirror_qemu.git] / ui / egl-headless.c
CommitLineData
bb1599b6 1#include "qemu/osdep.h"
0b8fa32f 2#include "qemu/module.h"
bb1599b6
GH
3#include "sysemu/sysemu.h"
4#include "ui/console.h"
5#include "ui/egl-helpers.h"
6#include "ui/egl-context.h"
a3517917 7#include "ui/shader.h"
bb1599b6
GH
8
9typedef struct egl_dpy {
10 DisplayChangeListener dcl;
11 DisplaySurface *ds;
a3517917 12 QemuGLShader *gls;
d8dc67e1 13 egl_fb guest_fb;
a3517917 14 egl_fb cursor_fb;
d8dc67e1 15 egl_fb blit_fb;
bb1599b6 16 bool y_0_top;
a3517917
GH
17 uint32_t pos_x;
18 uint32_t pos_y;
bb1599b6
GH
19} egl_dpy;
20
d8dc67e1
GH
21/* ------------------------------------------------------------------ */
22
bb1599b6
GH
23static void egl_refresh(DisplayChangeListener *dcl)
24{
25 graphic_hw_update(dcl->con);
26}
27
28static void egl_gfx_update(DisplayChangeListener *dcl,
29 int x, int y, int w, int h)
30{
31}
32
33static void egl_gfx_switch(DisplayChangeListener *dcl,
34 struct DisplaySurface *new_surface)
35{
36 egl_dpy *edpy = container_of(dcl, egl_dpy, dcl);
37
38 edpy->ds = new_surface;
39}
40
952e5d58
GH
41static QEMUGLContext egl_create_context(DisplayChangeListener *dcl,
42 QEMUGLParams *params)
43{
44 eglMakeCurrent(qemu_egl_display, EGL_NO_SURFACE, EGL_NO_SURFACE,
45 qemu_egl_rn_ctx);
46 return qemu_egl_create_context(dcl, params);
47}
48
bb1599b6
GH
49static void egl_scanout_disable(DisplayChangeListener *dcl)
50{
51 egl_dpy *edpy = container_of(dcl, egl_dpy, dcl);
52
d8dc67e1
GH
53 egl_fb_destroy(&edpy->guest_fb);
54 egl_fb_destroy(&edpy->blit_fb);
bb1599b6
GH
55}
56
57static void egl_scanout_texture(DisplayChangeListener *dcl,
58 uint32_t backing_id,
59 bool backing_y_0_top,
60 uint32_t backing_width,
61 uint32_t backing_height,
62 uint32_t x, uint32_t y,
63 uint32_t w, uint32_t h)
64{
65 egl_dpy *edpy = container_of(dcl, egl_dpy, dcl);
66
bb1599b6
GH
67 edpy->y_0_top = backing_y_0_top;
68
69 /* source framebuffer */
74083f9c
GH
70 egl_fb_setup_for_tex(&edpy->guest_fb,
71 backing_width, backing_height, backing_id, false);
bb1599b6
GH
72
73 /* dest framebuffer */
d8dc67e1
GH
74 if (edpy->blit_fb.width != backing_width ||
75 edpy->blit_fb.height != backing_height) {
76 egl_fb_destroy(&edpy->blit_fb);
74083f9c 77 egl_fb_setup_new_tex(&edpy->blit_fb, backing_width, backing_height);
bb1599b6
GH
78 }
79}
80
a3517917
GH
81static void egl_scanout_dmabuf(DisplayChangeListener *dcl,
82 QemuDmaBuf *dmabuf)
83{
84 egl_dmabuf_import_texture(dmabuf);
85 if (!dmabuf->texture) {
86 return;
87 }
88
89 egl_scanout_texture(dcl, dmabuf->texture,
90 false, dmabuf->width, dmabuf->height,
91 0, 0, dmabuf->width, dmabuf->height);
92}
93
94static void egl_cursor_dmabuf(DisplayChangeListener *dcl,
6e1f2cb5
GH
95 QemuDmaBuf *dmabuf, bool have_hot,
96 uint32_t hot_x, uint32_t hot_y)
a3517917
GH
97{
98 egl_dpy *edpy = container_of(dcl, egl_dpy, dcl);
99
b0916928
GH
100 if (dmabuf) {
101 egl_dmabuf_import_texture(dmabuf);
102 if (!dmabuf->texture) {
103 return;
104 }
105 egl_fb_setup_for_tex(&edpy->cursor_fb, dmabuf->width, dmabuf->height,
106 dmabuf->texture, false);
107 } else {
108 egl_fb_destroy(&edpy->cursor_fb);
a3517917 109 }
a3517917
GH
110}
111
6e1f2cb5
GH
112static void egl_cursor_position(DisplayChangeListener *dcl,
113 uint32_t pos_x, uint32_t pos_y)
114{
115 egl_dpy *edpy = container_of(dcl, egl_dpy, dcl);
116
117 edpy->pos_x = pos_x;
118 edpy->pos_y = pos_y;
119}
120
a3517917
GH
121static void egl_release_dmabuf(DisplayChangeListener *dcl,
122 QemuDmaBuf *dmabuf)
123{
124 egl_dmabuf_release_texture(dmabuf);
125}
126
bb1599b6
GH
127static void egl_scanout_flush(DisplayChangeListener *dcl,
128 uint32_t x, uint32_t y,
129 uint32_t w, uint32_t h)
130{
131 egl_dpy *edpy = container_of(dcl, egl_dpy, dcl);
bb1599b6 132
d8dc67e1 133 if (!edpy->guest_fb.texture || !edpy->ds) {
bb1599b6
GH
134 return;
135 }
d8dc67e1
GH
136 assert(surface_width(edpy->ds) == edpy->guest_fb.width);
137 assert(surface_height(edpy->ds) == edpy->guest_fb.height);
bb1599b6
GH
138 assert(surface_format(edpy->ds) == PIXMAN_x8r8g8b8);
139
a3517917
GH
140 if (edpy->cursor_fb.texture) {
141 /* have cursor -> render using textures */
142 egl_texture_blit(edpy->gls, &edpy->blit_fb, &edpy->guest_fb,
143 !edpy->y_0_top);
144 egl_texture_blend(edpy->gls, &edpy->blit_fb, &edpy->cursor_fb,
051a0cde
CZ
145 !edpy->y_0_top, edpy->pos_x, edpy->pos_y,
146 1.0, 1.0);
a3517917
GH
147 } else {
148 /* no cursor -> use simple framebuffer blit */
149 egl_fb_blit(&edpy->blit_fb, &edpy->guest_fb, edpy->y_0_top);
150 }
d8dc67e1 151
a3517917 152 egl_fb_read(surface_data(edpy->ds), &edpy->blit_fb);
bb1599b6
GH
153 dpy_gfx_update(edpy->dcl.con, x, y, w, h);
154}
155
156static const DisplayChangeListenerOps egl_ops = {
157 .dpy_name = "egl-headless",
158 .dpy_refresh = egl_refresh,
159 .dpy_gfx_update = egl_gfx_update,
160 .dpy_gfx_switch = egl_gfx_switch,
161
952e5d58 162 .dpy_gl_ctx_create = egl_create_context,
bb1599b6
GH
163 .dpy_gl_ctx_destroy = qemu_egl_destroy_context,
164 .dpy_gl_ctx_make_current = qemu_egl_make_context_current,
165 .dpy_gl_ctx_get_current = qemu_egl_get_current_context,
166
167 .dpy_gl_scanout_disable = egl_scanout_disable,
168 .dpy_gl_scanout_texture = egl_scanout_texture,
a3517917
GH
169 .dpy_gl_scanout_dmabuf = egl_scanout_dmabuf,
170 .dpy_gl_cursor_dmabuf = egl_cursor_dmabuf,
6e1f2cb5 171 .dpy_gl_cursor_position = egl_cursor_position,
a3517917 172 .dpy_gl_release_dmabuf = egl_release_dmabuf,
bb1599b6
GH
173 .dpy_gl_update = egl_scanout_flush,
174};
175
16ab0a74
GH
176static void early_egl_headless_init(DisplayOptions *opts)
177{
178 display_opengl = 1;
179}
180
181static void egl_headless_init(DisplayState *ds, DisplayOptions *opts)
bb1599b6 182{
54d208ff 183 DisplayGLMode mode = opts->has_gl ? opts->gl : DISPLAYGL_MODE_ON;
bb1599b6
GH
184 QemuConsole *con;
185 egl_dpy *edpy;
186 int idx;
187
91e61947 188 if (egl_rendernode_init(opts->u.egl_headless.rendernode, mode) < 0) {
bb1599b6
GH
189 error_report("egl: render node init failed");
190 exit(1);
191 }
192
193 for (idx = 0;; idx++) {
194 con = qemu_console_lookup_by_index(idx);
195 if (!con || !qemu_console_is_graphic(con)) {
196 break;
197 }
198
199 edpy = g_new0(egl_dpy, 1);
200 edpy->dcl.con = con;
201 edpy->dcl.ops = &egl_ops;
a3517917 202 edpy->gls = qemu_gl_init_shader();
bb1599b6
GH
203 register_displaychangelistener(&edpy->dcl);
204 }
205}
16ab0a74
GH
206
207static QemuDisplay qemu_display_egl = {
208 .type = DISPLAY_TYPE_EGL_HEADLESS,
209 .early_init = early_egl_headless_init,
210 .init = egl_headless_init,
211};
212
213static void register_egl(void)
214{
215 qemu_display_register(&qemu_display_egl);
216}
217
218type_init(register_egl);