gtk-egl.c (384d9d554aa4de0aa81a5b0be074d8c02f0941d4) gtk-egl.c (a4f113fd691899d926425ffd74b8f341cebf672c)
1/*
2 * GTK UI -- egl opengl code.
3 *
4 * Note that gtk 3.16+ (released 2015-03-23) has a GtkGLArea widget,
5 * which is GtkDrawingArea like widget with opengl rendering support.
6 *
7 * This code handles opengl support on older gtk versions, using egl
8 * to get a opengl context for the X11 window.

--- 16 unchanged lines hidden (view full) ---

25static void gtk_egl_set_scanout_mode(VirtualConsole *vc, bool scanout)
26{
27 if (vc->gfx.scanout_mode == scanout) {
28 return;
29 }
30
31 vc->gfx.scanout_mode = scanout;
32 if (!vc->gfx.scanout_mode) {
1/*
2 * GTK UI -- egl opengl code.
3 *
4 * Note that gtk 3.16+ (released 2015-03-23) has a GtkGLArea widget,
5 * which is GtkDrawingArea like widget with opengl rendering support.
6 *
7 * This code handles opengl support on older gtk versions, using egl
8 * to get a opengl context for the X11 window.

--- 16 unchanged lines hidden (view full) ---

25static void gtk_egl_set_scanout_mode(VirtualConsole *vc, bool scanout)
26{
27 if (vc->gfx.scanout_mode == scanout) {
28 return;
29 }
30
31 vc->gfx.scanout_mode = scanout;
32 if (!vc->gfx.scanout_mode) {
33 if (vc->gfx.fbo_id) {
34 glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT,
35 GL_COLOR_ATTACHMENT0_EXT,
36 GL_TEXTURE_2D, 0, 0);
37 glBindFramebuffer(GL_FRAMEBUFFER_EXT, 0);
38 glDeleteFramebuffers(1, &vc->gfx.fbo_id);
39 vc->gfx.fbo_id = 0;
40 }
33 egl_fb_destroy(&vc->gfx.guest_fb);
41 if (vc->gfx.surface) {
42 surface_gl_destroy_texture(vc->gfx.gls, vc->gfx.ds);
43 surface_gl_create_texture(vc->gfx.gls, vc->gfx.ds);
44 }
45 }
46}
47
48/** DisplayState Callbacks (opengl version) **/

--- 122 unchanged lines hidden (view full) ---

171}
172
173void gd_egl_scanout_disable(DisplayChangeListener *dcl)
174{
175 VirtualConsole *vc = container_of(dcl, VirtualConsole, gfx.dcl);
176
177 vc->gfx.w = 0;
178 vc->gfx.h = 0;
34 if (vc->gfx.surface) {
35 surface_gl_destroy_texture(vc->gfx.gls, vc->gfx.ds);
36 surface_gl_create_texture(vc->gfx.gls, vc->gfx.ds);
37 }
38 }
39}
40
41/** DisplayState Callbacks (opengl version) **/

--- 122 unchanged lines hidden (view full) ---

164}
165
166void gd_egl_scanout_disable(DisplayChangeListener *dcl)
167{
168 VirtualConsole *vc = container_of(dcl, VirtualConsole, gfx.dcl);
169
170 vc->gfx.w = 0;
171 vc->gfx.h = 0;
179 vc->gfx.tex_id = 0;
180 gtk_egl_set_scanout_mode(vc, false);
181}
182
183void gd_egl_scanout_texture(DisplayChangeListener *dcl,
184 uint32_t backing_id, bool backing_y_0_top,
185 uint32_t backing_width, uint32_t backing_height,
186 uint32_t x, uint32_t y,
187 uint32_t w, uint32_t h)
188{
189 VirtualConsole *vc = container_of(dcl, VirtualConsole, gfx.dcl);
190
191 vc->gfx.x = x;
192 vc->gfx.y = y;
193 vc->gfx.w = w;
194 vc->gfx.h = h;
172 gtk_egl_set_scanout_mode(vc, false);
173}
174
175void gd_egl_scanout_texture(DisplayChangeListener *dcl,
176 uint32_t backing_id, bool backing_y_0_top,
177 uint32_t backing_width, uint32_t backing_height,
178 uint32_t x, uint32_t y,
179 uint32_t w, uint32_t h)
180{
181 VirtualConsole *vc = container_of(dcl, VirtualConsole, gfx.dcl);
182
183 vc->gfx.x = x;
184 vc->gfx.y = y;
185 vc->gfx.w = w;
186 vc->gfx.h = h;
195 vc->gfx.tex_id = backing_id;
196 vc->gfx.y0_top = backing_y_0_top;
197
198 eglMakeCurrent(qemu_egl_display, vc->gfx.esurface,
199 vc->gfx.esurface, vc->gfx.ectx);
200
201 gtk_egl_set_scanout_mode(vc, true);
187 vc->gfx.y0_top = backing_y_0_top;
188
189 eglMakeCurrent(qemu_egl_display, vc->gfx.esurface,
190 vc->gfx.esurface, vc->gfx.ectx);
191
192 gtk_egl_set_scanout_mode(vc, true);
202 if (!vc->gfx.fbo_id) {
203 glGenFramebuffers(1, &vc->gfx.fbo_id);
204 }
205
206 glBindFramebuffer(GL_FRAMEBUFFER_EXT, vc->gfx.fbo_id);
207 glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT,
208 GL_TEXTURE_2D, vc->gfx.tex_id, 0);
193 egl_fb_create_for_tex(&vc->gfx.guest_fb, backing_width, backing_height,
194 backing_id);
209}
210
211void gd_egl_scanout_flush(DisplayChangeListener *dcl,
212 uint32_t x, uint32_t y, uint32_t w, uint32_t h)
213{
214 VirtualConsole *vc = container_of(dcl, VirtualConsole, gfx.dcl);
215 GdkWindow *window;
195}
196
197void gd_egl_scanout_flush(DisplayChangeListener *dcl,
198 uint32_t x, uint32_t y, uint32_t w, uint32_t h)
199{
200 VirtualConsole *vc = container_of(dcl, VirtualConsole, gfx.dcl);
201 GdkWindow *window;
216 int ww, wh, y1, y2;
202 int ww, wh;
217
218 if (!vc->gfx.scanout_mode) {
219 return;
220 }
203
204 if (!vc->gfx.scanout_mode) {
205 return;
206 }
221 if (!vc->gfx.fbo_id) {
207 if (!vc->gfx.guest_fb.framebuffer) {
222 return;
223 }
224
225 eglMakeCurrent(qemu_egl_display, vc->gfx.esurface,
226 vc->gfx.esurface, vc->gfx.ectx);
227
208 return;
209 }
210
211 eglMakeCurrent(qemu_egl_display, vc->gfx.esurface,
212 vc->gfx.esurface, vc->gfx.ectx);
213
228 glBindFramebuffer(GL_READ_FRAMEBUFFER, vc->gfx.fbo_id);
229 glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
230
231 window = gtk_widget_get_window(vc->gfx.drawing_area);
232 gdk_drawable_get_size(window, &ww, &wh);
214 window = gtk_widget_get_window(vc->gfx.drawing_area);
215 gdk_drawable_get_size(window, &ww, &wh);
233 glViewport(0, 0, ww, wh);
234 y1 = vc->gfx.y0_top ? 0 : vc->gfx.h;
235 y2 = vc->gfx.y0_top ? vc->gfx.h : 0;
236 glBlitFramebuffer(0, y1, vc->gfx.w, y2,
237 0, 0, ww, wh,
238 GL_COLOR_BUFFER_BIT, GL_NEAREST);
239 glBindFramebuffer(GL_FRAMEBUFFER_EXT, vc->gfx.fbo_id);
216 egl_fb_setup_default(&vc->gfx.win_fb, ww, wh);
217 egl_fb_blit(&vc->gfx.win_fb, &vc->gfx.guest_fb, !vc->gfx.y0_top);
240
241 eglSwapBuffers(qemu_egl_display, vc->gfx.esurface);
242}
243
244void gtk_egl_init(void)
245{
246 GdkDisplay *gdk_display = gdk_display_get_default();
247 Display *x11_display = gdk_x11_display_get_xdisplay(gdk_display);

--- 16 unchanged lines hidden ---
218
219 eglSwapBuffers(qemu_egl_display, vc->gfx.esurface);
220}
221
222void gtk_egl_init(void)
223{
224 GdkDisplay *gdk_display = gdk_display_get_default();
225 Display *x11_display = gdk_x11_display_get_xdisplay(gdk_display);

--- 16 unchanged lines hidden ---