kvm-all: put kvm_mem_flags to more work
[qemu/ar7.git] / ui / sdl2-gl.c
blobb604c0671e84737dba2f639c2587bb0a73844eee
1 /*
2 * QEMU SDL display driver -- opengl support
4 * Copyright (c) 2014 Red Hat
6 * Authors:
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
25 * THE SOFTWARE.
28 #include "qemu-common.h"
29 #include "ui/console.h"
30 #include "ui/input.h"
31 #include "ui/sdl2.h"
32 #include "sysemu/sysemu.h"
34 static void sdl2_gl_render_surface(struct sdl2_console *scon)
36 int ww, wh;
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);
52 assert(scon->opengl);
54 SDL_GL_MakeCurrent(scon->real_window, scon->winctx);
55 surface_gl_update_texture(scon->gls, scon->surface, x, y, w, h);
56 scon->updates++;
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;
65 assert(scon->opengl);
67 SDL_GL_MakeCurrent(scon->real_window, scon->winctx);
68 surface_gl_destroy_texture(scon->gls, scon->surface);
70 scon->surface = new_surface;
72 if (!new_surface) {
73 console_gl_fini_context(scon->gls);
74 scon->gls = NULL;
75 sdl2_window_destroy(scon);
76 return;
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);
95 assert(scon->opengl);
97 graphic_hw_update(dcl->con);
98 if (scon->updates && scon->surface) {
99 scon->updates = 0;
100 sdl2_gl_render_surface(scon);
102 sdl2_poll_events(scon);
105 void sdl2_gl_redraw(struct sdl2_console *scon)
107 assert(scon->opengl);
109 if (scon->surface) {
110 sdl2_gl_render_surface(scon);