migration/postcopy: PostcopyState is already set in loadvm_postcopy_handle_advise()
[qemu/ar7.git] / ui / sdl2-2d.c
blobdb191aaa7910e0e7deca47575a20a2611c649633
1 /*
2 * QEMU SDL display driver
4 * Copyright (c) 2003 Fabrice Bellard
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 * THE SOFTWARE.
24 /* Ported SDL 1.2 code to 2.0 by Dave Airlie. */
26 #include "qemu/osdep.h"
27 #include "ui/console.h"
28 #include "ui/input.h"
29 #include "ui/sdl2.h"
30 #include "sysemu/sysemu.h"
32 void sdl2_2d_update(DisplayChangeListener *dcl,
33 int x, int y, int w, int h)
35 struct sdl2_console *scon = container_of(dcl, struct sdl2_console, dcl);
36 DisplaySurface *surf = qemu_console_surface(dcl->con);
37 SDL_Rect rect;
38 size_t surface_data_offset;
39 assert(!scon->opengl);
41 if (!surf) {
42 return;
44 if (!scon->texture) {
45 return;
48 surface_data_offset = surface_bytes_per_pixel(surf) * x +
49 surface_stride(surf) * y;
50 rect.x = x;
51 rect.y = y;
52 rect.w = w;
53 rect.h = h;
55 SDL_UpdateTexture(scon->texture, &rect,
56 surface_data(surf) + surface_data_offset,
57 surface_stride(surf));
58 SDL_RenderClear(scon->real_renderer);
59 SDL_RenderCopy(scon->real_renderer, scon->texture, NULL, NULL);
60 SDL_RenderPresent(scon->real_renderer);
63 void sdl2_2d_switch(DisplayChangeListener *dcl,
64 DisplaySurface *new_surface)
66 struct sdl2_console *scon = container_of(dcl, struct sdl2_console, dcl);
67 DisplaySurface *old_surface = scon->surface;
68 int format = 0;
70 assert(!scon->opengl);
72 scon->surface = new_surface;
74 if (scon->texture) {
75 SDL_DestroyTexture(scon->texture);
76 scon->texture = NULL;
79 if (!new_surface) {
80 sdl2_window_destroy(scon);
81 return;
84 if (!scon->real_window) {
85 sdl2_window_create(scon);
86 } else if (old_surface &&
87 ((surface_width(old_surface) != surface_width(new_surface)) ||
88 (surface_height(old_surface) != surface_height(new_surface)))) {
89 sdl2_window_resize(scon);
92 SDL_RenderSetLogicalSize(scon->real_renderer,
93 surface_width(new_surface),
94 surface_height(new_surface));
96 switch (surface_format(scon->surface)) {
97 case PIXMAN_x1r5g5b5:
98 format = SDL_PIXELFORMAT_ARGB1555;
99 break;
100 case PIXMAN_r5g6b5:
101 format = SDL_PIXELFORMAT_RGB565;
102 break;
103 case PIXMAN_a8r8g8b8:
104 case PIXMAN_x8r8g8b8:
105 format = SDL_PIXELFORMAT_ARGB8888;
106 break;
107 case PIXMAN_a8b8g8r8:
108 case PIXMAN_x8b8g8r8:
109 format = SDL_PIXELFORMAT_ABGR8888;
110 break;
111 case PIXMAN_r8g8b8a8:
112 case PIXMAN_r8g8b8x8:
113 format = SDL_PIXELFORMAT_RGBA8888;
114 break;
115 case PIXMAN_b8g8r8x8:
116 format = SDL_PIXELFORMAT_BGRX8888;
117 break;
118 case PIXMAN_b8g8r8a8:
119 format = SDL_PIXELFORMAT_BGRA8888;
120 break;
121 default:
122 g_assert_not_reached();
124 scon->texture = SDL_CreateTexture(scon->real_renderer, format,
125 SDL_TEXTUREACCESS_STREAMING,
126 surface_width(new_surface),
127 surface_height(new_surface));
128 sdl2_2d_redraw(scon);
131 void sdl2_2d_refresh(DisplayChangeListener *dcl)
133 struct sdl2_console *scon = container_of(dcl, struct sdl2_console, dcl);
135 assert(!scon->opengl);
136 graphic_hw_update(dcl->con);
137 sdl2_poll_events(scon);
140 void sdl2_2d_redraw(struct sdl2_console *scon)
142 assert(!scon->opengl);
144 if (!scon->surface) {
145 return;
147 sdl2_2d_update(&scon->dcl, 0, 0,
148 surface_width(scon->surface),
149 surface_height(scon->surface));
152 bool sdl2_2d_check_format(DisplayChangeListener *dcl,
153 pixman_format_code_t format)
156 * We let SDL convert for us a few more formats than,
157 * the native ones. Thes are the ones I have tested.
159 return (format == PIXMAN_x8r8g8b8 ||
160 format == PIXMAN_a8r8g8b8 ||
161 format == PIXMAN_a8b8g8r8 ||
162 format == PIXMAN_x8b8g8r8 ||
163 format == PIXMAN_b8g8r8x8 ||
164 format == PIXMAN_b8g8r8a8 ||
165 format == PIXMAN_r8g8b8x8 ||
166 format == PIXMAN_r8g8b8a8 ||
167 format == PIXMAN_x1r5g5b5 ||
168 format == PIXMAN_r5g6b5);