sun4u: remove pci_ebus_init() function
[qemu.git] / ui / gtk-gl-area.c
blob147ad6f9b5062b148ac2a586b80899e124dc3447
1 /*
2 * GTK UI -- glarea opengl code.
4 * Requires 3.16+ (GtkGLArea widget).
6 * This work is licensed under the terms of the GNU GPL, version 2 or later.
7 * See the COPYING file in the top-level directory.
8 */
10 #include "qemu/osdep.h"
11 #include "qemu-common.h"
13 #include "trace.h"
15 #include "ui/console.h"
16 #include "ui/gtk.h"
17 #include "ui/egl-helpers.h"
19 #include "sysemu/sysemu.h"
21 static void gtk_gl_area_set_scanout_mode(VirtualConsole *vc, bool scanout)
23 if (vc->gfx.scanout_mode == scanout) {
24 return;
27 vc->gfx.scanout_mode = scanout;
28 if (!vc->gfx.scanout_mode) {
29 egl_fb_destroy(&vc->gfx.guest_fb);
30 if (vc->gfx.surface) {
31 surface_gl_destroy_texture(vc->gfx.gls, vc->gfx.ds);
32 surface_gl_create_texture(vc->gfx.gls, vc->gfx.ds);
37 /** DisplayState Callbacks (opengl version) **/
39 void gd_gl_area_draw(VirtualConsole *vc)
41 int ww, wh, y1, y2;
43 if (!vc->gfx.gls) {
44 return;
47 gtk_gl_area_make_current(GTK_GL_AREA(vc->gfx.drawing_area));
48 ww = gtk_widget_get_allocated_width(vc->gfx.drawing_area);
49 wh = gtk_widget_get_allocated_height(vc->gfx.drawing_area);
51 if (vc->gfx.scanout_mode) {
52 if (!vc->gfx.guest_fb.framebuffer) {
53 return;
56 glBindFramebuffer(GL_READ_FRAMEBUFFER, vc->gfx.guest_fb.framebuffer);
57 /* GtkGLArea sets GL_DRAW_FRAMEBUFFER for us */
59 glViewport(0, 0, ww, wh);
60 y1 = vc->gfx.y0_top ? 0 : vc->gfx.h;
61 y2 = vc->gfx.y0_top ? vc->gfx.h : 0;
62 glBlitFramebuffer(0, y1, vc->gfx.w, y2,
63 0, 0, ww, wh,
64 GL_COLOR_BUFFER_BIT, GL_NEAREST);
65 } else {
66 if (!vc->gfx.ds) {
67 return;
69 gtk_gl_area_make_current(GTK_GL_AREA(vc->gfx.drawing_area));
71 surface_gl_setup_viewport(vc->gfx.gls, vc->gfx.ds, ww, wh);
72 surface_gl_render_texture(vc->gfx.gls, vc->gfx.ds);
76 void gd_gl_area_update(DisplayChangeListener *dcl,
77 int x, int y, int w, int h)
79 VirtualConsole *vc = container_of(dcl, VirtualConsole, gfx.dcl);
81 if (!vc->gfx.gls || !vc->gfx.ds) {
82 return;
85 gtk_gl_area_make_current(GTK_GL_AREA(vc->gfx.drawing_area));
86 surface_gl_update_texture(vc->gfx.gls, vc->gfx.ds, x, y, w, h);
87 vc->gfx.glupdates++;
90 void gd_gl_area_refresh(DisplayChangeListener *dcl)
92 VirtualConsole *vc = container_of(dcl, VirtualConsole, gfx.dcl);
94 if (!vc->gfx.gls) {
95 if (!gtk_widget_get_realized(vc->gfx.drawing_area)) {
96 return;
98 gtk_gl_area_make_current(GTK_GL_AREA(vc->gfx.drawing_area));
99 vc->gfx.gls = qemu_gl_init_shader();
100 if (vc->gfx.ds) {
101 surface_gl_create_texture(vc->gfx.gls, vc->gfx.ds);
105 graphic_hw_update(dcl->con);
107 if (vc->gfx.glupdates) {
108 vc->gfx.glupdates = 0;
109 gtk_gl_area_set_scanout_mode(vc, false);
110 gtk_gl_area_queue_render(GTK_GL_AREA(vc->gfx.drawing_area));
114 void gd_gl_area_switch(DisplayChangeListener *dcl,
115 DisplaySurface *surface)
117 VirtualConsole *vc = container_of(dcl, VirtualConsole, gfx.dcl);
118 bool resized = true;
120 trace_gd_switch(vc->label, surface_width(surface), surface_height(surface));
122 if (vc->gfx.ds &&
123 surface_width(vc->gfx.ds) == surface_width(surface) &&
124 surface_height(vc->gfx.ds) == surface_height(surface)) {
125 resized = false;
128 if (vc->gfx.gls) {
129 gtk_gl_area_make_current(GTK_GL_AREA(vc->gfx.drawing_area));
130 surface_gl_destroy_texture(vc->gfx.gls, vc->gfx.ds);
131 surface_gl_create_texture(vc->gfx.gls, surface);
133 vc->gfx.ds = surface;
135 if (resized) {
136 gd_update_windowsize(vc);
140 QEMUGLContext gd_gl_area_create_context(DisplayChangeListener *dcl,
141 QEMUGLParams *params)
143 VirtualConsole *vc = container_of(dcl, VirtualConsole, gfx.dcl);
144 GdkWindow *window;
145 GdkGLContext *ctx;
146 GError *err = NULL;
148 gtk_gl_area_make_current(GTK_GL_AREA(vc->gfx.drawing_area));
149 window = gtk_widget_get_window(vc->gfx.drawing_area);
150 ctx = gdk_window_create_gl_context(window, &err);
151 gdk_gl_context_set_required_version(ctx,
152 params->major_ver,
153 params->minor_ver);
154 gdk_gl_context_realize(ctx, &err);
155 return ctx;
158 void gd_gl_area_destroy_context(DisplayChangeListener *dcl, QEMUGLContext ctx)
160 /* FIXME */
163 void gd_gl_area_scanout_texture(DisplayChangeListener *dcl,
164 uint32_t backing_id,
165 bool backing_y_0_top,
166 uint32_t backing_width,
167 uint32_t backing_height,
168 uint32_t x, uint32_t y,
169 uint32_t w, uint32_t h)
171 VirtualConsole *vc = container_of(dcl, VirtualConsole, gfx.dcl);
173 vc->gfx.x = x;
174 vc->gfx.y = y;
175 vc->gfx.w = w;
176 vc->gfx.h = h;
177 vc->gfx.y0_top = backing_y_0_top;
179 gtk_gl_area_make_current(GTK_GL_AREA(vc->gfx.drawing_area));
181 if (backing_id == 0 || vc->gfx.w == 0 || vc->gfx.h == 0) {
182 gtk_gl_area_set_scanout_mode(vc, false);
183 return;
186 gtk_gl_area_set_scanout_mode(vc, true);
187 egl_fb_setup_for_tex(&vc->gfx.guest_fb, backing_width, backing_height,
188 backing_id, false);
191 void gd_gl_area_scanout_flush(DisplayChangeListener *dcl,
192 uint32_t x, uint32_t y, uint32_t w, uint32_t h)
194 VirtualConsole *vc = container_of(dcl, VirtualConsole, gfx.dcl);
196 gtk_gl_area_queue_render(GTK_GL_AREA(vc->gfx.drawing_area));
199 void gtk_gl_area_init(void)
201 display_opengl = 1;
204 QEMUGLContext gd_gl_area_get_current_context(DisplayChangeListener *dcl)
206 return gdk_gl_context_get_current();
209 int gd_gl_area_make_current(DisplayChangeListener *dcl,
210 QEMUGLContext ctx)
212 gdk_gl_context_make_current(ctx);
213 return 0;