vhost: use QEMU_ALIGN_DOWN
[qemu/ar7.git] / ui / egl-headless.c
blob809bfde99cf9a5adaf1d272db0289a8694e930c8
1 #include "qemu/osdep.h"
2 #include "qemu-common.h"
3 #include "sysemu/sysemu.h"
4 #include "ui/console.h"
5 #include "ui/egl-helpers.h"
6 #include "ui/egl-context.h"
8 typedef struct egl_dpy {
9 DisplayChangeListener dcl;
10 DisplaySurface *ds;
11 egl_fb guest_fb;
12 egl_fb blit_fb;
13 bool y_0_top;
14 } egl_dpy;
16 /* ------------------------------------------------------------------ */
18 static void egl_refresh(DisplayChangeListener *dcl)
20 graphic_hw_update(dcl->con);
23 static void egl_gfx_update(DisplayChangeListener *dcl,
24 int x, int y, int w, int h)
28 static void egl_gfx_switch(DisplayChangeListener *dcl,
29 struct DisplaySurface *new_surface)
31 egl_dpy *edpy = container_of(dcl, egl_dpy, dcl);
33 edpy->ds = new_surface;
36 static void egl_scanout_disable(DisplayChangeListener *dcl)
38 egl_dpy *edpy = container_of(dcl, egl_dpy, dcl);
40 egl_fb_destroy(&edpy->guest_fb);
41 egl_fb_destroy(&edpy->blit_fb);
44 static void egl_scanout_texture(DisplayChangeListener *dcl,
45 uint32_t backing_id,
46 bool backing_y_0_top,
47 uint32_t backing_width,
48 uint32_t backing_height,
49 uint32_t x, uint32_t y,
50 uint32_t w, uint32_t h)
52 egl_dpy *edpy = container_of(dcl, egl_dpy, dcl);
54 edpy->y_0_top = backing_y_0_top;
56 /* source framebuffer */
57 egl_fb_create_for_tex(&edpy->guest_fb,
58 backing_width, backing_height, backing_id);
60 /* dest framebuffer */
61 if (edpy->blit_fb.width != backing_width ||
62 edpy->blit_fb.height != backing_height) {
63 egl_fb_destroy(&edpy->blit_fb);
64 egl_fb_create_new_tex(&edpy->blit_fb, backing_width, backing_height);
68 static void egl_scanout_flush(DisplayChangeListener *dcl,
69 uint32_t x, uint32_t y,
70 uint32_t w, uint32_t h)
72 egl_dpy *edpy = container_of(dcl, egl_dpy, dcl);
74 if (!edpy->guest_fb.texture || !edpy->ds) {
75 return;
77 assert(surface_width(edpy->ds) == edpy->guest_fb.width);
78 assert(surface_height(edpy->ds) == edpy->guest_fb.height);
79 assert(surface_format(edpy->ds) == PIXMAN_x8r8g8b8);
81 egl_fb_blit(&edpy->blit_fb, &edpy->guest_fb, edpy->y_0_top);
82 egl_fb_read(surface_data(edpy->ds), &edpy->blit_fb);
84 dpy_gfx_update(edpy->dcl.con, x, y, w, h);
87 static const DisplayChangeListenerOps egl_ops = {
88 .dpy_name = "egl-headless",
89 .dpy_refresh = egl_refresh,
90 .dpy_gfx_update = egl_gfx_update,
91 .dpy_gfx_switch = egl_gfx_switch,
93 .dpy_gl_ctx_create = qemu_egl_create_context,
94 .dpy_gl_ctx_destroy = qemu_egl_destroy_context,
95 .dpy_gl_ctx_make_current = qemu_egl_make_context_current,
96 .dpy_gl_ctx_get_current = qemu_egl_get_current_context,
98 .dpy_gl_scanout_disable = egl_scanout_disable,
99 .dpy_gl_scanout_texture = egl_scanout_texture,
100 .dpy_gl_update = egl_scanout_flush,
103 void egl_headless_init(void)
105 QemuConsole *con;
106 egl_dpy *edpy;
107 int idx;
109 if (egl_rendernode_init(NULL) < 0) {
110 error_report("egl: render node init failed");
111 exit(1);
114 for (idx = 0;; idx++) {
115 con = qemu_console_lookup_by_index(idx);
116 if (!con || !qemu_console_is_graphic(con)) {
117 break;
120 edpy = g_new0(egl_dpy, 1);
121 edpy->dcl.con = con;
122 edpy->dcl.ops = &egl_ops;
123 register_displaychangelistener(&edpy->dcl);