tcg/aarch64: Return false on failure from patch_reloc
[qemu/ar7.git] / ui / sdl2-2d.c
blob091ecfcc7ff20f04109233ceb0cb7341d28e66dc
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 "qemu-common.h"
28 #include "ui/console.h"
29 #include "ui/input.h"
30 #include "ui/sdl2.h"
31 #include "sysemu/sysemu.h"
33 void sdl2_2d_update(DisplayChangeListener *dcl,
34 int x, int y, int w, int h)
36 struct sdl2_console *scon = container_of(dcl, struct sdl2_console, dcl);
37 DisplaySurface *surf = qemu_console_surface(dcl->con);
38 SDL_Rect rect;
39 size_t surface_data_offset;
40 assert(!scon->opengl);
42 if (!surf) {
43 return;
45 if (!scon->texture) {
46 return;
49 surface_data_offset = surface_bytes_per_pixel(surf) * x +
50 surface_stride(surf) * y;
51 rect.x = x;
52 rect.y = y;
53 rect.w = w;
54 rect.h = h;
56 SDL_UpdateTexture(scon->texture, &rect,
57 surface_data(surf) + surface_data_offset,
58 surface_stride(surf));
59 SDL_RenderClear(scon->real_renderer);
60 SDL_RenderCopy(scon->real_renderer, scon->texture, NULL, NULL);
61 SDL_RenderPresent(scon->real_renderer);
64 void sdl2_2d_switch(DisplayChangeListener *dcl,
65 DisplaySurface *new_surface)
67 struct sdl2_console *scon = container_of(dcl, struct sdl2_console, dcl);
68 DisplaySurface *old_surface = scon->surface;
69 int format = 0;
71 assert(!scon->opengl);
73 scon->surface = new_surface;
75 if (scon->texture) {
76 SDL_DestroyTexture(scon->texture);
77 scon->texture = NULL;
80 if (!new_surface) {
81 sdl2_window_destroy(scon);
82 return;
85 if (!scon->real_window) {
86 sdl2_window_create(scon);
87 } else if (old_surface &&
88 ((surface_width(old_surface) != surface_width(new_surface)) ||
89 (surface_height(old_surface) != surface_height(new_surface)))) {
90 sdl2_window_resize(scon);
93 SDL_RenderSetLogicalSize(scon->real_renderer,
94 surface_width(new_surface),
95 surface_height(new_surface));
97 switch (surface_format(scon->surface)) {
98 case PIXMAN_x1r5g5b5:
99 format = SDL_PIXELFORMAT_ARGB1555;
100 break;
101 case PIXMAN_r5g6b5:
102 format = SDL_PIXELFORMAT_RGB565;
103 break;
104 case PIXMAN_a8r8g8b8:
105 case PIXMAN_x8r8g8b8:
106 format = SDL_PIXELFORMAT_ARGB8888;
107 break;
108 case PIXMAN_a8b8g8r8:
109 case PIXMAN_x8b8g8r8:
110 format = SDL_PIXELFORMAT_ABGR8888;
111 break;
112 case PIXMAN_r8g8b8a8:
113 case PIXMAN_r8g8b8x8:
114 format = SDL_PIXELFORMAT_RGBA8888;
115 break;
116 case PIXMAN_b8g8r8x8:
117 format = SDL_PIXELFORMAT_BGRX8888;
118 break;
119 case PIXMAN_b8g8r8a8:
120 format = SDL_PIXELFORMAT_BGRA8888;
121 break;
122 default:
123 g_assert_not_reached();
125 scon->texture = SDL_CreateTexture(scon->real_renderer, format,
126 SDL_TEXTUREACCESS_STREAMING,
127 surface_width(new_surface),
128 surface_height(new_surface));
129 sdl2_2d_redraw(scon);
132 void sdl2_2d_refresh(DisplayChangeListener *dcl)
134 struct sdl2_console *scon = container_of(dcl, struct sdl2_console, dcl);
136 assert(!scon->opengl);
137 graphic_hw_update(dcl->con);
138 sdl2_poll_events(scon);
141 void sdl2_2d_redraw(struct sdl2_console *scon)
143 assert(!scon->opengl);
145 if (!scon->surface) {
146 return;
148 sdl2_2d_update(&scon->dcl, 0, 0,
149 surface_width(scon->surface),
150 surface_height(scon->surface));
153 bool sdl2_2d_check_format(DisplayChangeListener *dcl,
154 pixman_format_code_t format)
157 * We let SDL convert for us a few more formats than,
158 * the native ones. Thes are the ones I have tested.
160 return (format == PIXMAN_x8r8g8b8 ||
161 format == PIXMAN_a8r8g8b8 ||
162 format == PIXMAN_a8b8g8r8 ||
163 format == PIXMAN_x8b8g8r8 ||
164 format == PIXMAN_b8g8r8x8 ||
165 format == PIXMAN_b8g8r8a8 ||
166 format == PIXMAN_r8g8b8x8 ||
167 format == PIXMAN_r8g8b8a8 ||
168 format == PIXMAN_x1r5g5b5 ||
169 format == PIXMAN_r5g6b5);