]>
Commit | Line | Data |
---|---|---|
f1ddebd8 GH |
1 | /* |
2 | * QEMU SDL display driver | |
3 | * | |
4 | * Copyright (c) 2003 Fabrice Bellard | |
5 | * | |
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: | |
12 | * | |
13 | * The above copyright notice and this permission notice shall be included in | |
14 | * all copies or substantial portions of the Software. | |
15 | * | |
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. | |
23 | */ | |
24 | /* Ported SDL 1.2 code to 2.0 by Dave Airlie. */ | |
25 | ||
f1ddebd8 GH |
26 | #include "qemu-common.h" |
27 | #include "ui/console.h" | |
28 | #include "ui/input.h" | |
29 | #include "ui/sdl2.h" | |
30 | #include "sysemu/sysemu.h" | |
31 | ||
32 | void sdl2_2d_update(DisplayChangeListener *dcl, | |
33 | int x, int y, int w, int h) | |
34 | { | |
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 | ||
39 | if (!surf) { | |
40 | return; | |
41 | } | |
42 | if (!scon->texture) { | |
43 | return; | |
44 | } | |
45 | ||
46 | rect.x = x; | |
47 | rect.y = y; | |
48 | rect.w = w; | |
49 | rect.h = h; | |
50 | ||
51 | SDL_UpdateTexture(scon->texture, NULL, surface_data(surf), | |
52 | surface_stride(surf)); | |
53 | SDL_RenderCopy(scon->real_renderer, scon->texture, &rect, &rect); | |
54 | SDL_RenderPresent(scon->real_renderer); | |
55 | } | |
2c3056f1 GH |
56 | |
57 | void sdl2_2d_switch(DisplayChangeListener *dcl, | |
58 | DisplaySurface *new_surface) | |
59 | { | |
60 | struct sdl2_console *scon = container_of(dcl, struct sdl2_console, dcl); | |
61 | DisplaySurface *old_surface = scon->surface; | |
62 | int format = 0; | |
63 | ||
64 | scon->surface = new_surface; | |
65 | ||
66 | if (scon->texture) { | |
67 | SDL_DestroyTexture(scon->texture); | |
68 | scon->texture = NULL; | |
69 | } | |
70 | ||
71 | if (!new_surface) { | |
72 | sdl2_window_destroy(scon); | |
73 | return; | |
74 | } | |
75 | ||
76 | if (!scon->real_window) { | |
77 | sdl2_window_create(scon); | |
78 | } else if (old_surface && | |
79 | ((surface_width(old_surface) != surface_width(new_surface)) || | |
80 | (surface_height(old_surface) != surface_height(new_surface)))) { | |
81 | sdl2_window_resize(scon); | |
82 | } | |
83 | ||
84 | SDL_RenderSetLogicalSize(scon->real_renderer, | |
85 | surface_width(new_surface), | |
86 | surface_height(new_surface)); | |
87 | ||
88 | if (surface_bits_per_pixel(scon->surface) == 16) { | |
89 | format = SDL_PIXELFORMAT_RGB565; | |
90 | } else if (surface_bits_per_pixel(scon->surface) == 32) { | |
91 | format = SDL_PIXELFORMAT_ARGB8888; | |
92 | } | |
93 | scon->texture = SDL_CreateTexture(scon->real_renderer, format, | |
94 | SDL_TEXTUREACCESS_STREAMING, | |
95 | surface_width(new_surface), | |
96 | surface_height(new_surface)); | |
0d01b7ce GH |
97 | sdl2_2d_redraw(scon); |
98 | } | |
99 | ||
62959ffe GH |
100 | void sdl2_2d_refresh(DisplayChangeListener *dcl) |
101 | { | |
102 | struct sdl2_console *scon = container_of(dcl, struct sdl2_console, dcl); | |
103 | ||
104 | graphic_hw_update(dcl->con); | |
105 | sdl2_poll_events(scon); | |
106 | } | |
107 | ||
0d01b7ce GH |
108 | void sdl2_2d_redraw(struct sdl2_console *scon) |
109 | { | |
110 | if (!scon->surface) { | |
111 | return; | |
112 | } | |
113 | sdl2_2d_update(&scon->dcl, 0, 0, | |
114 | surface_width(scon->surface), | |
115 | surface_height(scon->surface)); | |
2c3056f1 | 116 | } |
877417d9 GH |
117 | |
118 | bool sdl2_2d_check_format(DisplayChangeListener *dcl, | |
119 | pixman_format_code_t format) | |
120 | { | |
121 | /* | |
122 | * We let SDL convert for us a few more formats than, | |
123 | * the native ones. Thes are the ones I have tested. | |
124 | */ | |
125 | return (format == PIXMAN_x8r8g8b8 || | |
126 | format == PIXMAN_b8g8r8x8 || | |
127 | format == PIXMAN_x1r5g5b5 || | |
128 | format == PIXMAN_r5g6b5); | |
129 | } |