2014-11-11 11:09:26 +01:00
|
|
|
/*
|
|
|
|
* QEMU SDL display driver
|
|
|
|
*
|
|
|
|
* Copyright (c) 2003 Fabrice Bellard
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
* of this software and associated documentation files (the "Software"), to deal
|
|
|
|
* in the Software without restriction, including without limitation the rights
|
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
* copies of the Software, and to permit persons to whom the Software is
|
|
|
|
* furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included in
|
|
|
|
* all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
|
|
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
* THE SOFTWARE.
|
|
|
|
*/
|
|
|
|
/* Ported SDL 1.2 code to 2.0 by Dave Airlie. */
|
|
|
|
|
2016-01-29 18:49:51 +01:00
|
|
|
#include "qemu/osdep.h"
|
2014-11-11 11:09:26 +01:00
|
|
|
#include "ui/console.h"
|
|
|
|
#include "ui/input.h"
|
|
|
|
#include "ui/sdl2.h"
|
|
|
|
|
|
|
|
void sdl2_2d_update(DisplayChangeListener *dcl,
|
|
|
|
int x, int y, int w, int h)
|
|
|
|
{
|
|
|
|
struct sdl2_console *scon = container_of(dcl, struct sdl2_console, dcl);
|
|
|
|
DisplaySurface *surf = qemu_console_surface(dcl->con);
|
|
|
|
SDL_Rect rect;
|
2018-05-15 20:58:14 +02:00
|
|
|
size_t surface_data_offset;
|
2014-11-11 16:54:45 +01:00
|
|
|
assert(!scon->opengl);
|
|
|
|
|
2014-11-11 11:09:26 +01:00
|
|
|
if (!surf) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (!scon->texture) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-05-15 20:58:14 +02:00
|
|
|
surface_data_offset = surface_bytes_per_pixel(surf) * x +
|
|
|
|
surface_stride(surf) * y;
|
2014-11-11 11:09:26 +01:00
|
|
|
rect.x = x;
|
|
|
|
rect.y = y;
|
|
|
|
rect.w = w;
|
|
|
|
rect.h = h;
|
|
|
|
|
2018-02-05 14:32:28 +01:00
|
|
|
SDL_UpdateTexture(scon->texture, &rect,
|
|
|
|
surface_data(surf) + surface_data_offset,
|
2014-11-11 11:09:26 +01:00
|
|
|
surface_stride(surf));
|
2018-02-05 14:32:28 +01:00
|
|
|
SDL_RenderClear(scon->real_renderer);
|
|
|
|
SDL_RenderCopy(scon->real_renderer, scon->texture, NULL, NULL);
|
2014-11-11 11:09:26 +01:00
|
|
|
SDL_RenderPresent(scon->real_renderer);
|
|
|
|
}
|
2014-11-11 13:22:49 +01:00
|
|
|
|
|
|
|
void sdl2_2d_switch(DisplayChangeListener *dcl,
|
|
|
|
DisplaySurface *new_surface)
|
|
|
|
{
|
|
|
|
struct sdl2_console *scon = container_of(dcl, struct sdl2_console, dcl);
|
|
|
|
DisplaySurface *old_surface = scon->surface;
|
|
|
|
int format = 0;
|
|
|
|
|
2014-11-11 16:54:45 +01:00
|
|
|
assert(!scon->opengl);
|
|
|
|
|
2014-11-11 13:22:49 +01:00
|
|
|
scon->surface = new_surface;
|
|
|
|
|
|
|
|
if (scon->texture) {
|
|
|
|
SDL_DestroyTexture(scon->texture);
|
|
|
|
scon->texture = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!new_surface) {
|
|
|
|
sdl2_window_destroy(scon);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!scon->real_window) {
|
|
|
|
sdl2_window_create(scon);
|
|
|
|
} else if (old_surface &&
|
|
|
|
((surface_width(old_surface) != surface_width(new_surface)) ||
|
|
|
|
(surface_height(old_surface) != surface_height(new_surface)))) {
|
|
|
|
sdl2_window_resize(scon);
|
|
|
|
}
|
|
|
|
|
|
|
|
SDL_RenderSetLogicalSize(scon->real_renderer,
|
|
|
|
surface_width(new_surface),
|
|
|
|
surface_height(new_surface));
|
|
|
|
|
2015-03-03 18:25:27 +01:00
|
|
|
switch (surface_format(scon->surface)) {
|
|
|
|
case PIXMAN_x1r5g5b5:
|
|
|
|
format = SDL_PIXELFORMAT_ARGB1555;
|
|
|
|
break;
|
|
|
|
case PIXMAN_r5g6b5:
|
2014-11-11 13:22:49 +01:00
|
|
|
format = SDL_PIXELFORMAT_RGB565;
|
2015-03-03 18:25:27 +01:00
|
|
|
break;
|
2018-10-08 20:50:13 +02:00
|
|
|
case PIXMAN_a8r8g8b8:
|
2015-03-03 18:25:27 +01:00
|
|
|
case PIXMAN_x8r8g8b8:
|
2014-11-11 13:22:49 +01:00
|
|
|
format = SDL_PIXELFORMAT_ARGB8888;
|
2015-03-03 18:25:27 +01:00
|
|
|
break;
|
2018-10-08 20:50:13 +02:00
|
|
|
case PIXMAN_a8b8g8r8:
|
|
|
|
case PIXMAN_x8b8g8r8:
|
|
|
|
format = SDL_PIXELFORMAT_ABGR8888;
|
|
|
|
break;
|
|
|
|
case PIXMAN_r8g8b8a8:
|
2015-03-03 18:25:27 +01:00
|
|
|
case PIXMAN_r8g8b8x8:
|
|
|
|
format = SDL_PIXELFORMAT_RGBA8888;
|
|
|
|
break;
|
2016-05-17 09:28:48 +02:00
|
|
|
case PIXMAN_b8g8r8x8:
|
|
|
|
format = SDL_PIXELFORMAT_BGRX8888;
|
|
|
|
break;
|
2018-10-08 20:50:13 +02:00
|
|
|
case PIXMAN_b8g8r8a8:
|
|
|
|
format = SDL_PIXELFORMAT_BGRA8888;
|
|
|
|
break;
|
2015-03-03 18:25:27 +01:00
|
|
|
default:
|
|
|
|
g_assert_not_reached();
|
2014-11-11 13:22:49 +01:00
|
|
|
}
|
|
|
|
scon->texture = SDL_CreateTexture(scon->real_renderer, format,
|
|
|
|
SDL_TEXTUREACCESS_STREAMING,
|
|
|
|
surface_width(new_surface),
|
|
|
|
surface_height(new_surface));
|
2014-11-11 13:31:08 +01:00
|
|
|
sdl2_2d_redraw(scon);
|
|
|
|
}
|
|
|
|
|
2014-11-12 08:03:34 +01:00
|
|
|
void sdl2_2d_refresh(DisplayChangeListener *dcl)
|
|
|
|
{
|
|
|
|
struct sdl2_console *scon = container_of(dcl, struct sdl2_console, dcl);
|
|
|
|
|
2014-11-11 16:54:45 +01:00
|
|
|
assert(!scon->opengl);
|
2014-11-12 08:03:34 +01:00
|
|
|
graphic_hw_update(dcl->con);
|
|
|
|
sdl2_poll_events(scon);
|
|
|
|
}
|
|
|
|
|
2014-11-11 13:31:08 +01:00
|
|
|
void sdl2_2d_redraw(struct sdl2_console *scon)
|
|
|
|
{
|
2014-11-11 16:54:45 +01:00
|
|
|
assert(!scon->opengl);
|
|
|
|
|
2014-11-11 13:31:08 +01:00
|
|
|
if (!scon->surface) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
sdl2_2d_update(&scon->dcl, 0, 0,
|
|
|
|
surface_width(scon->surface),
|
|
|
|
surface_height(scon->surface));
|
2014-11-11 13:22:49 +01:00
|
|
|
}
|
2015-01-09 09:27:09 +01:00
|
|
|
|
|
|
|
bool sdl2_2d_check_format(DisplayChangeListener *dcl,
|
|
|
|
pixman_format_code_t format)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* We let SDL convert for us a few more formats than,
|
|
|
|
* the native ones. Thes are the ones I have tested.
|
|
|
|
*/
|
|
|
|
return (format == PIXMAN_x8r8g8b8 ||
|
2018-10-08 20:50:13 +02:00
|
|
|
format == PIXMAN_a8r8g8b8 ||
|
|
|
|
format == PIXMAN_a8b8g8r8 ||
|
|
|
|
format == PIXMAN_x8b8g8r8 ||
|
2015-01-09 09:27:09 +01:00
|
|
|
format == PIXMAN_b8g8r8x8 ||
|
2018-10-08 20:50:13 +02:00
|
|
|
format == PIXMAN_b8g8r8a8 ||
|
|
|
|
format == PIXMAN_r8g8b8x8 ||
|
|
|
|
format == PIXMAN_r8g8b8a8 ||
|
2015-01-09 09:27:09 +01:00
|
|
|
format == PIXMAN_x1r5g5b5 ||
|
|
|
|
format == PIXMAN_r5g6b5);
|
|
|
|
}
|