2 * QEMU SDL display driver -- opengl support
4 * Copyright (c) 2014 Red Hat
7 * Gerd Hoffmann <kraxel@redhat.com>
9 * Permission is hereby granted, free of charge, to any person obtaining a copy
10 * of this software and associated documentation files (the "Software"), to deal
11 * in the Software without restriction, including without limitation the rights
12 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 * copies of the Software, and to permit persons to whom the Software is
14 * furnished to do so, subject to the following conditions:
16 * The above copyright notice and this permission notice shall be included in
17 * all copies or substantial portions of the Software.
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
22 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
28 #include "qemu-common.h"
29 #include "ui/console.h"
32 #include "sysemu/sysemu.h"
34 static void sdl2_gl_render_surface(struct sdl2_console
*scon
)
38 SDL_GL_MakeCurrent(scon
->real_window
, scon
->winctx
);
40 SDL_GetWindowSize(scon
->real_window
, &ww
, &wh
);
41 surface_gl_setup_viewport(scon
->gls
, scon
->surface
, ww
, wh
);
43 surface_gl_render_texture(scon
->gls
, scon
->surface
);
44 SDL_GL_SwapWindow(scon
->real_window
);
47 void sdl2_gl_update(DisplayChangeListener
*dcl
,
48 int x
, int y
, int w
, int h
)
50 struct sdl2_console
*scon
= container_of(dcl
, struct sdl2_console
, dcl
);
54 SDL_GL_MakeCurrent(scon
->real_window
, scon
->winctx
);
55 surface_gl_update_texture(scon
->gls
, scon
->surface
, x
, y
, w
, h
);
59 void sdl2_gl_switch(DisplayChangeListener
*dcl
,
60 DisplaySurface
*new_surface
)
62 struct sdl2_console
*scon
= container_of(dcl
, struct sdl2_console
, dcl
);
63 DisplaySurface
*old_surface
= scon
->surface
;
67 SDL_GL_MakeCurrent(scon
->real_window
, scon
->winctx
);
68 surface_gl_destroy_texture(scon
->gls
, scon
->surface
);
70 scon
->surface
= new_surface
;
73 console_gl_fini_context(scon
->gls
);
75 sdl2_window_destroy(scon
);
79 if (!scon
->real_window
) {
80 sdl2_window_create(scon
);
81 scon
->gls
= console_gl_init_context();
82 } else if (old_surface
&&
83 ((surface_width(old_surface
) != surface_width(new_surface
)) ||
84 (surface_height(old_surface
) != surface_height(new_surface
)))) {
85 sdl2_window_resize(scon
);
88 surface_gl_create_texture(scon
->gls
, scon
->surface
);
91 void sdl2_gl_refresh(DisplayChangeListener
*dcl
)
93 struct sdl2_console
*scon
= container_of(dcl
, struct sdl2_console
, dcl
);
97 graphic_hw_update(dcl
->con
);
98 if (scon
->updates
&& scon
->surface
) {
100 sdl2_gl_render_surface(scon
);
102 sdl2_poll_events(scon
);
105 void sdl2_gl_redraw(struct sdl2_console
*scon
)
107 assert(scon
->opengl
);
110 sdl2_gl_render_surface(scon
);