2012-04-21 21:13:50 +00:00
|
|
|
/* RetroArch - A frontend for libretro.
|
2014-01-01 00:50:59 +00:00
|
|
|
* Copyright (C) 2010-2014 - Hans-Kristian Arntzen
|
2017-01-22 12:40:32 +00:00
|
|
|
* Copyright (C) 2011-2017 - Daniel De Matteis
|
|
|
|
* Copyright (C) 2011-2017 - Higor Euripedes
|
2011-04-21 01:23:44 +00:00
|
|
|
*
|
2012-04-21 21:13:50 +00:00
|
|
|
* RetroArch is free software: you can redistribute it and/or modify it under the terms
|
2011-04-21 01:23:44 +00:00
|
|
|
* of the GNU General Public License as published by the Free Software Found-
|
|
|
|
* ation, either version 3 of the License, or (at your option) any later version.
|
|
|
|
*
|
2012-04-21 21:13:50 +00:00
|
|
|
* RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
2011-04-21 01:23:44 +00:00
|
|
|
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
|
|
|
* PURPOSE. See the GNU General Public License for more details.
|
|
|
|
*
|
2012-04-21 21:31:57 +00:00
|
|
|
* You should have received a copy of the GNU General Public License along with RetroArch.
|
2011-04-21 01:23:44 +00:00
|
|
|
* If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2015-11-22 12:32:46 +00:00
|
|
|
|
2016-02-13 03:49:42 +00:00
|
|
|
#include <retro_assert.h>
|
2015-11-22 12:32:46 +00:00
|
|
|
#include <gfx/scaler/scaler.h>
|
2016-11-08 14:35:24 +00:00
|
|
|
#include <gfx/video_frame.h>
|
2016-02-16 19:24:00 +00:00
|
|
|
#include <retro_assert.h>
|
2016-09-11 14:10:41 +00:00
|
|
|
#include "../../verbosity.h"
|
2015-11-22 12:32:46 +00:00
|
|
|
|
2016-09-11 12:46:53 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "../../config.h"
|
|
|
|
#endif
|
|
|
|
|
2017-01-18 21:20:47 +00:00
|
|
|
#ifdef HAVE_MENU
|
|
|
|
#include "../../menu/menu_driver.h"
|
|
|
|
#endif
|
|
|
|
|
2016-09-11 12:46:53 +00:00
|
|
|
#ifdef HAVE_X11
|
|
|
|
#include "../common/x11_common.h"
|
|
|
|
#endif
|
|
|
|
|
2015-11-22 12:32:46 +00:00
|
|
|
#include "SDL.h"
|
2016-09-11 12:46:53 +00:00
|
|
|
#include "SDL_syswm.h"
|
2015-11-22 12:32:46 +00:00
|
|
|
|
2017-01-19 16:20:42 +00:00
|
|
|
#include "../font_driver.h"
|
2017-01-19 16:48:03 +00:00
|
|
|
#include "../video_driver.h"
|
2017-01-19 16:20:42 +00:00
|
|
|
|
2016-09-05 16:31:32 +00:00
|
|
|
#include "../../configuration.h"
|
2016-05-04 14:56:16 +00:00
|
|
|
|
2015-01-12 20:53:04 +00:00
|
|
|
#include "../video_context_driver.h"
|
2012-07-25 04:52:57 +00:00
|
|
|
|
2014-08-08 02:34:50 +00:00
|
|
|
typedef struct sdl_menu_frame
|
|
|
|
{
|
|
|
|
bool active;
|
|
|
|
SDL_Surface *frame;
|
|
|
|
struct scaler_ctx scaler;
|
|
|
|
|
|
|
|
} sdl_menu_frame_t;
|
|
|
|
|
2011-12-24 12:46:12 +00:00
|
|
|
typedef struct sdl_video
|
2011-04-21 01:23:44 +00:00
|
|
|
{
|
2012-11-20 22:35:40 +00:00
|
|
|
SDL_Surface *screen;
|
2011-04-21 01:23:44 +00:00
|
|
|
bool quitting;
|
2011-04-23 17:15:15 +00:00
|
|
|
|
2012-12-14 21:33:04 +00:00
|
|
|
void *font;
|
2012-12-14 19:25:40 +00:00
|
|
|
const font_renderer_driver_t *font_driver;
|
2011-09-06 16:32:40 +00:00
|
|
|
uint8_t font_r;
|
|
|
|
uint8_t font_g;
|
|
|
|
uint8_t font_b;
|
2012-09-02 12:30:46 +00:00
|
|
|
|
|
|
|
struct scaler_ctx scaler;
|
2014-08-08 02:34:50 +00:00
|
|
|
|
|
|
|
sdl_menu_frame_t menu;
|
2011-12-24 12:46:12 +00:00
|
|
|
} sdl_video_t;
|
2011-04-21 01:23:44 +00:00
|
|
|
|
|
|
|
static void sdl_gfx_free(void *data)
|
|
|
|
{
|
2011-12-24 12:46:12 +00:00
|
|
|
sdl_video_t *vid = (sdl_video_t*)data;
|
2011-04-21 01:23:44 +00:00
|
|
|
if (!vid)
|
|
|
|
return;
|
|
|
|
|
2014-08-08 02:34:50 +00:00
|
|
|
if (vid->menu.frame)
|
|
|
|
SDL_FreeSurface(vid->menu.frame);
|
|
|
|
|
2011-04-21 01:23:44 +00:00
|
|
|
SDL_QuitSubSystem(SDL_INIT_VIDEO);
|
|
|
|
|
2011-04-22 01:13:09 +00:00
|
|
|
if (vid->font)
|
2012-12-14 19:25:40 +00:00
|
|
|
vid->font_driver->free(vid->font);
|
2011-04-22 01:13:09 +00:00
|
|
|
|
2012-09-02 12:30:46 +00:00
|
|
|
scaler_ctx_gen_reset(&vid->scaler);
|
2014-08-27 02:57:29 +00:00
|
|
|
scaler_ctx_gen_reset(&vid->menu.scaler);
|
2012-09-02 12:30:46 +00:00
|
|
|
|
2011-04-21 01:23:44 +00:00
|
|
|
free(vid);
|
|
|
|
}
|
|
|
|
|
2011-04-22 01:13:09 +00:00
|
|
|
static void sdl_init_font(sdl_video_t *vid, const char *font_path, unsigned font_size)
|
|
|
|
{
|
2015-01-21 23:32:24 +00:00
|
|
|
int r, g, b;
|
2015-03-20 21:08:36 +00:00
|
|
|
settings_t *settings = config_get_ptr();
|
|
|
|
|
2017-04-27 22:53:06 +00:00
|
|
|
if (!settings->bools.video_font_enable)
|
2011-11-09 23:15:41 +00:00
|
|
|
return;
|
|
|
|
|
2015-12-12 16:54:27 +00:00
|
|
|
if (!font_renderer_create_default((const void**)&vid->font_driver, &vid->font,
|
2016-04-28 17:52:25 +00:00
|
|
|
*settings->path.font ? settings->path.font : NULL,
|
2017-04-28 12:57:55 +00:00
|
|
|
settings->floats.video_font_size))
|
2011-04-22 01:13:09 +00:00
|
|
|
{
|
2015-01-21 23:32:24 +00:00
|
|
|
RARCH_LOG("[SDL]: Could not initialize fonts.\n");
|
|
|
|
return;
|
|
|
|
}
|
2011-09-06 16:32:40 +00:00
|
|
|
|
2017-04-28 12:57:55 +00:00
|
|
|
r = settings->floats.video_msg_color_r * 255;
|
|
|
|
g = settings->floats.video_msg_color_g * 255;
|
|
|
|
b = settings->floats.video_msg_color_b * 255;
|
2011-09-06 16:32:40 +00:00
|
|
|
|
2015-01-21 23:32:24 +00:00
|
|
|
r = (r < 0) ? 0 : (r > 255 ? 255 : r);
|
|
|
|
g = (g < 0) ? 0 : (g > 255 ? 255 : g);
|
|
|
|
b = (b < 0) ? 0 : (b > 255 ? 255 : b);
|
|
|
|
|
|
|
|
vid->font_r = r;
|
|
|
|
vid->font_g = g;
|
|
|
|
vid->font_b = b;
|
2011-04-22 01:13:09 +00:00
|
|
|
}
|
|
|
|
|
2012-11-20 22:35:40 +00:00
|
|
|
static void sdl_render_msg(sdl_video_t *vid, SDL_Surface *buffer,
|
|
|
|
const char *msg, unsigned width, unsigned height, const SDL_PixelFormat *fmt)
|
2011-04-22 01:13:09 +00:00
|
|
|
{
|
2014-09-05 23:27:46 +00:00
|
|
|
int x, y, msg_base_x, msg_base_y;
|
2014-04-30 02:04:59 +00:00
|
|
|
unsigned rshift, gshift, bshift;
|
2015-03-20 21:08:36 +00:00
|
|
|
const struct font_atlas *atlas = NULL;
|
|
|
|
settings_t *settings = config_get_ptr();
|
2014-04-30 02:04:59 +00:00
|
|
|
|
2011-05-23 09:45:44 +00:00
|
|
|
if (!vid->font)
|
|
|
|
return;
|
|
|
|
|
2015-03-20 21:08:36 +00:00
|
|
|
atlas = vid->font_driver->get_atlas(vid->font);
|
2011-04-22 01:13:09 +00:00
|
|
|
|
2015-03-20 21:08:36 +00:00
|
|
|
msg_base_x = settings->video.msg_pos_x * width;
|
|
|
|
msg_base_y = (1.0f - settings->video.msg_pos_y) * height;
|
2011-04-22 01:13:09 +00:00
|
|
|
|
2014-04-30 02:04:59 +00:00
|
|
|
rshift = fmt->Rshift;
|
|
|
|
gshift = fmt->Gshift;
|
|
|
|
bshift = fmt->Bshift;
|
2011-04-23 17:15:15 +00:00
|
|
|
|
2014-06-08 11:01:55 +00:00
|
|
|
for (; *msg; msg++)
|
2011-04-22 01:13:09 +00:00
|
|
|
{
|
2016-03-20 04:24:05 +00:00
|
|
|
int glyph_width, glyph_height;
|
|
|
|
int base_x, base_y, max_width, max_height;
|
|
|
|
uint32_t *out = NULL;
|
|
|
|
const uint8_t *src = NULL;
|
2014-06-08 11:01:55 +00:00
|
|
|
const struct font_glyph *glyph = vid->font_driver->get_glyph(vid->font, (uint8_t)*msg);
|
|
|
|
if (!glyph)
|
|
|
|
continue;
|
2014-04-30 02:04:59 +00:00
|
|
|
|
2016-03-20 04:24:05 +00:00
|
|
|
glyph_width = glyph->width;
|
|
|
|
glyph_height = glyph->height;
|
2012-09-26 23:41:35 +00:00
|
|
|
|
2016-03-20 04:24:05 +00:00
|
|
|
base_x = msg_base_x + glyph->draw_offset_x;
|
|
|
|
base_y = msg_base_y + glyph->draw_offset_y;
|
|
|
|
src = atlas->buffer + glyph->atlas_offset_x
|
|
|
|
+ glyph->atlas_offset_y * atlas->width;
|
2012-09-26 23:41:35 +00:00
|
|
|
|
|
|
|
if (base_x < 0)
|
|
|
|
{
|
|
|
|
src -= base_x;
|
|
|
|
glyph_width += base_x;
|
|
|
|
base_x = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (base_y < 0)
|
|
|
|
{
|
2014-06-08 11:01:55 +00:00
|
|
|
src -= base_y * (int)atlas->width;
|
2012-09-26 23:41:35 +00:00
|
|
|
glyph_height += base_y;
|
|
|
|
base_y = 0;
|
|
|
|
}
|
|
|
|
|
2016-03-20 04:24:05 +00:00
|
|
|
max_width = width - base_x;
|
|
|
|
max_height = height - base_y;
|
2012-09-26 23:41:35 +00:00
|
|
|
|
|
|
|
if (max_width <= 0 || max_height <= 0)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (glyph_width > max_width)
|
|
|
|
glyph_width = max_width;
|
|
|
|
if (glyph_height > max_height)
|
|
|
|
glyph_height = max_height;
|
|
|
|
|
2016-03-20 04:24:05 +00:00
|
|
|
out = (uint32_t*)buffer->pixels + base_y * (buffer->pitch >> 2) + base_x;
|
2012-09-26 23:41:35 +00:00
|
|
|
|
2014-06-08 11:01:55 +00:00
|
|
|
for (y = 0; y < glyph_height; y++, src += atlas->width, out += buffer->pitch >> 2)
|
2011-04-22 01:13:09 +00:00
|
|
|
{
|
2013-10-22 19:26:33 +00:00
|
|
|
for (x = 0; x < glyph_width; x++)
|
2011-04-22 01:13:09 +00:00
|
|
|
{
|
2012-09-26 23:41:35 +00:00
|
|
|
unsigned blend = src[x];
|
|
|
|
unsigned out_pix = out[x];
|
|
|
|
unsigned r = (out_pix >> rshift) & 0xff;
|
|
|
|
unsigned g = (out_pix >> gshift) & 0xff;
|
|
|
|
unsigned b = (out_pix >> bshift) & 0xff;
|
|
|
|
|
|
|
|
unsigned out_r = (r * (256 - blend) + vid->font_r * blend) >> 8;
|
|
|
|
unsigned out_g = (g * (256 - blend) + vid->font_g * blend) >> 8;
|
|
|
|
unsigned out_b = (b * (256 - blend) + vid->font_b * blend) >> 8;
|
|
|
|
out[x] = (out_r << rshift) | (out_g << gshift) | (out_b << bshift);
|
2011-04-22 01:13:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-08 11:01:55 +00:00
|
|
|
msg_base_x += glyph->advance_x;
|
|
|
|
msg_base_y += glyph->advance_y;
|
|
|
|
}
|
2011-04-22 01:13:09 +00:00
|
|
|
}
|
|
|
|
|
2012-09-28 20:38:42 +00:00
|
|
|
static void sdl_gfx_set_handles(void)
|
|
|
|
{
|
2015-01-21 23:32:24 +00:00
|
|
|
/* SysWMinfo headers are broken on OSX. */
|
2014-08-27 03:10:38 +00:00
|
|
|
#if defined(_WIN32) || defined(HAVE_X11)
|
2012-09-28 20:38:42 +00:00
|
|
|
SDL_SysWMinfo info;
|
|
|
|
SDL_VERSION(&info.version);
|
|
|
|
|
2015-01-21 23:32:24 +00:00
|
|
|
if (SDL_GetWMInfo(&info) != 1)
|
|
|
|
return;
|
|
|
|
|
2014-08-27 03:10:38 +00:00
|
|
|
#if defined(_WIN32)
|
2015-11-29 00:12:49 +00:00
|
|
|
video_driver_display_type_set(RARCH_DISPLAY_WIN32);
|
|
|
|
video_driver_display_set(0);
|
|
|
|
video_driver_window_set((uintptr_t)info.window);
|
2012-09-28 20:38:42 +00:00
|
|
|
#elif defined(HAVE_X11)
|
2015-11-29 00:12:49 +00:00
|
|
|
video_driver_display_type_set(RARCH_DISPLAY_X11);
|
|
|
|
video_driver_display_set((uintptr_t)info.info.x11.display);
|
|
|
|
video_driver_window_set((uintptr_t)info.info.x11.window);
|
2014-08-27 03:10:38 +00:00
|
|
|
#endif
|
2012-09-28 20:38:42 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2017-04-24 10:25:14 +00:00
|
|
|
static void *sdl_gfx_init(const video_info_t *video, const input_driver_t **input, void **input_data)
|
2011-04-21 01:23:44 +00:00
|
|
|
{
|
2015-01-21 23:32:24 +00:00
|
|
|
unsigned full_x, full_y;
|
2015-10-26 02:18:13 +00:00
|
|
|
const SDL_VideoInfo *video_info = NULL;
|
2015-01-21 23:32:24 +00:00
|
|
|
sdl_video_t *vid = NULL;
|
2015-03-20 21:08:36 +00:00
|
|
|
settings_t *settings = config_get_ptr();
|
|
|
|
|
2013-04-13 12:35:24 +00:00
|
|
|
#ifdef HAVE_X11
|
|
|
|
XInitThreads();
|
|
|
|
#endif
|
|
|
|
|
2014-08-27 02:53:22 +00:00
|
|
|
if (SDL_WasInit(0) == 0)
|
|
|
|
{
|
|
|
|
if (SDL_Init(SDL_INIT_VIDEO) < 0)
|
|
|
|
return NULL;
|
|
|
|
}
|
2014-08-11 20:37:53 +00:00
|
|
|
else if (SDL_InitSubSystem(SDL_INIT_VIDEO) < 0)
|
|
|
|
return NULL;
|
2011-04-21 01:23:44 +00:00
|
|
|
|
2015-01-21 23:32:24 +00:00
|
|
|
vid = (sdl_video_t*)calloc(1, sizeof(*vid));
|
2011-04-21 01:23:44 +00:00
|
|
|
if (!vid)
|
|
|
|
return NULL;
|
|
|
|
|
2015-10-26 02:18:13 +00:00
|
|
|
video_info = SDL_GetVideoInfo();
|
|
|
|
retro_assert(video_info);
|
2015-01-21 23:32:24 +00:00
|
|
|
full_x = video_info->current_w;
|
|
|
|
full_y = video_info->current_h;
|
2014-08-27 02:53:22 +00:00
|
|
|
RARCH_LOG("[SDL]: Detecting desktop resolution %ux%u.\n", full_x, full_y);
|
2011-12-24 12:46:12 +00:00
|
|
|
|
2011-04-24 00:44:02 +00:00
|
|
|
if (!video->fullscreen)
|
2014-08-27 02:53:22 +00:00
|
|
|
RARCH_LOG("[SDL]: Creating window @ %ux%u\n", video->width, video->height);
|
2011-04-24 00:44:02 +00:00
|
|
|
|
2012-11-20 22:23:18 +00:00
|
|
|
vid->screen = SDL_SetVideoMode(video->width, video->height, 32,
|
|
|
|
SDL_HWSURFACE | SDL_HWACCEL | SDL_DOUBLEBUF | (video->fullscreen ? SDL_FULLSCREEN : 0));
|
2011-04-23 16:06:48 +00:00
|
|
|
|
2015-01-21 23:32:24 +00:00
|
|
|
/* We assume that SDL chooses ARGB8888.
|
|
|
|
* Assuming this simplifies the driver *a ton*.
|
|
|
|
*/
|
2012-11-20 22:35:40 +00:00
|
|
|
|
2011-04-21 01:23:44 +00:00
|
|
|
if (!vid->screen)
|
|
|
|
{
|
2017-03-24 00:33:22 +00:00
|
|
|
RARCH_ERR("[SDL1]: Failed to init SDL surface: %s\n", SDL_GetError());
|
2011-04-21 01:23:44 +00:00
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
2012-10-28 10:04:07 +00:00
|
|
|
if (video->fullscreen)
|
|
|
|
SDL_ShowCursor(SDL_DISABLE);
|
2011-04-21 11:12:45 +00:00
|
|
|
|
2012-09-28 20:38:42 +00:00
|
|
|
sdl_gfx_set_handles();
|
|
|
|
|
2013-02-16 01:21:43 +00:00
|
|
|
if (input && input_data)
|
2011-04-21 01:23:44 +00:00
|
|
|
{
|
2017-01-10 20:01:13 +00:00
|
|
|
void *sdl_input = input_sdl.init(settings->input.joypad_driver);
|
2015-01-21 23:32:24 +00:00
|
|
|
|
2013-02-16 01:21:43 +00:00
|
|
|
if (sdl_input)
|
|
|
|
{
|
|
|
|
*input = &input_sdl;
|
|
|
|
*input_data = sdl_input;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
*input = NULL;
|
|
|
|
*input_data = NULL;
|
|
|
|
}
|
2011-12-14 15:37:31 +00:00
|
|
|
}
|
2011-04-21 01:23:44 +00:00
|
|
|
|
2017-04-28 12:57:55 +00:00
|
|
|
sdl_init_font(vid, settings->path.font, settings->floats.video_font_size);
|
2011-04-22 01:13:09 +00:00
|
|
|
|
2017-01-10 17:16:22 +00:00
|
|
|
vid->scaler.scaler_type = video->smooth ? SCALER_TYPE_BILINEAR : SCALER_TYPE_POINT;
|
|
|
|
vid->scaler.in_fmt = video->rgb32 ? SCALER_FMT_ARGB8888 : SCALER_FMT_RGB565;
|
|
|
|
vid->scaler.out_fmt = SCALER_FMT_ARGB8888;
|
2012-09-02 12:30:46 +00:00
|
|
|
|
2017-01-10 17:16:22 +00:00
|
|
|
vid->menu.scaler = vid->scaler;
|
2014-08-08 02:34:50 +00:00
|
|
|
vid->menu.scaler.scaler_type = SCALER_TYPE_BILINEAR;
|
|
|
|
|
2017-01-10 17:16:22 +00:00
|
|
|
vid->menu.frame = SDL_ConvertSurface(
|
|
|
|
vid->screen, vid->screen->format, vid->screen->flags | SDL_SRCALPHA);
|
2014-08-08 02:34:50 +00:00
|
|
|
|
|
|
|
if (!vid->menu.frame)
|
|
|
|
{
|
2017-03-24 00:33:22 +00:00
|
|
|
RARCH_ERR("[SDL1]: Failed to init menu surface: %s\n", SDL_GetError());
|
2014-08-08 02:34:50 +00:00
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
2011-04-21 01:23:44 +00:00
|
|
|
return vid;
|
|
|
|
|
|
|
|
error:
|
|
|
|
sdl_gfx_free(vid);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2015-04-03 02:20:50 +00:00
|
|
|
static void sdl_gfx_check_window(sdl_video_t *vid)
|
2011-06-11 10:54:14 +00:00
|
|
|
{
|
|
|
|
SDL_Event event;
|
2014-08-22 22:58:47 +00:00
|
|
|
|
|
|
|
SDL_PumpEvents();
|
|
|
|
while (SDL_PeepEvents(&event, 1, SDL_GETEVENT, SDL_QUITMASK))
|
2011-06-11 10:54:14 +00:00
|
|
|
{
|
2015-01-21 23:32:24 +00:00
|
|
|
if (event.type != SDL_QUIT)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
vid->quitting = true;
|
|
|
|
break;
|
2011-06-11 10:54:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-08-27 02:53:22 +00:00
|
|
|
static bool sdl_gfx_frame(void *data, const void *frame, unsigned width,
|
2015-08-03 21:01:07 +00:00
|
|
|
unsigned height, uint64_t frame_count,
|
2017-01-18 16:41:27 +00:00
|
|
|
unsigned pitch, const char *msg, video_frame_info_t *video_info)
|
2011-04-21 01:23:44 +00:00
|
|
|
{
|
2015-09-20 08:02:47 +00:00
|
|
|
sdl_video_t *vid = (sdl_video_t*)data;
|
2017-01-19 17:51:22 +00:00
|
|
|
char title[128];
|
2015-01-18 19:03:33 +00:00
|
|
|
|
2012-06-23 16:01:01 +00:00
|
|
|
if (!frame)
|
|
|
|
return true;
|
|
|
|
|
2017-01-19 17:51:22 +00:00
|
|
|
title[0] = '\0';
|
|
|
|
|
|
|
|
video_driver_get_window_title(title, sizeof(title));
|
|
|
|
|
2012-09-02 12:30:46 +00:00
|
|
|
if (SDL_MUSTLOCK(vid->screen))
|
|
|
|
SDL_LockSurface(vid->screen);
|
2011-04-21 01:23:44 +00:00
|
|
|
|
2016-05-04 14:56:16 +00:00
|
|
|
video_frame_scale(
|
|
|
|
&vid->scaler,
|
|
|
|
vid->screen->pixels,
|
|
|
|
frame,
|
|
|
|
vid->scaler.in_fmt,
|
|
|
|
vid->screen->w,
|
|
|
|
vid->screen->h,
|
|
|
|
vid->screen->pitch,
|
|
|
|
width,
|
|
|
|
height,
|
|
|
|
pitch);
|
2013-11-18 12:44:41 +00:00
|
|
|
|
2017-01-18 21:20:47 +00:00
|
|
|
#ifdef HAVE_MENU
|
|
|
|
menu_driver_frame(video_info);
|
|
|
|
#endif
|
|
|
|
|
2014-08-08 02:34:50 +00:00
|
|
|
if (vid->menu.active)
|
|
|
|
SDL_BlitSurface(vid->menu.frame, NULL, vid->screen, NULL);
|
|
|
|
|
2012-11-20 22:35:40 +00:00
|
|
|
if (msg)
|
|
|
|
sdl_render_msg(vid, vid->screen, msg, vid->screen->w, vid->screen->h, vid->screen->format);
|
2011-04-21 01:23:44 +00:00
|
|
|
|
2012-09-02 12:30:46 +00:00
|
|
|
if (SDL_MUSTLOCK(vid->screen))
|
|
|
|
SDL_UnlockSurface(vid->screen);
|
2011-04-21 01:23:44 +00:00
|
|
|
|
2017-01-19 17:51:22 +00:00
|
|
|
if (title[0])
|
|
|
|
SDL_WM_SetCaption(title, NULL);
|
2011-04-21 01:39:03 +00:00
|
|
|
|
|
|
|
SDL_Flip(vid->screen);
|
|
|
|
|
2011-04-21 01:23:44 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void sdl_gfx_set_nonblock_state(void *data, bool state)
|
|
|
|
{
|
2016-03-20 04:24:05 +00:00
|
|
|
(void)data; /* Can SDL even do this? */
|
2011-04-21 01:23:44 +00:00
|
|
|
(void)state;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool sdl_gfx_alive(void *data)
|
|
|
|
{
|
2011-12-24 12:46:12 +00:00
|
|
|
sdl_video_t *vid = (sdl_video_t*)data;
|
2015-04-03 02:20:50 +00:00
|
|
|
sdl_gfx_check_window(vid);
|
2011-04-21 01:23:44 +00:00
|
|
|
return !vid->quitting;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool sdl_gfx_focus(void *data)
|
|
|
|
{
|
|
|
|
(void)data;
|
|
|
|
return (SDL_GetAppState() & (SDL_APPINPUTFOCUS | SDL_APPACTIVE)) == (SDL_APPINPUTFOCUS | SDL_APPACTIVE);
|
|
|
|
}
|
|
|
|
|
2015-01-18 21:32:14 +00:00
|
|
|
static bool sdl_gfx_suppress_screensaver(void *data, bool enable)
|
|
|
|
{
|
2015-11-29 00:12:49 +00:00
|
|
|
(void)data;
|
|
|
|
(void)enable;
|
2015-09-29 15:35:28 +00:00
|
|
|
#ifdef HAVE_X11
|
2015-11-29 00:12:49 +00:00
|
|
|
if (video_driver_display_type_get() == RARCH_DISPLAY_X11)
|
2015-01-18 21:32:14 +00:00
|
|
|
{
|
2016-05-08 17:19:31 +00:00
|
|
|
x11_suspend_screensaver(video_driver_window_get(), enable);
|
2015-01-18 21:32:14 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-10-08 15:23:02 +00:00
|
|
|
static bool sdl_gfx_has_windowed(void *data)
|
|
|
|
{
|
|
|
|
(void)data;
|
|
|
|
|
|
|
|
/* TODO - implement. */
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-02-14 04:52:05 +00:00
|
|
|
static void sdl_gfx_viewport_info(void *data, struct video_viewport *vp)
|
2012-10-28 10:04:07 +00:00
|
|
|
{
|
|
|
|
sdl_video_t *vid = (sdl_video_t*)data;
|
|
|
|
vp->x = vp->y = 0;
|
2013-01-11 15:23:04 +00:00
|
|
|
vp->width = vp->full_width = vid->screen->w;
|
|
|
|
vp->height = vp->full_height = vid->screen->h;
|
2012-10-28 10:04:07 +00:00
|
|
|
}
|
|
|
|
|
2014-08-08 02:34:50 +00:00
|
|
|
static void sdl_set_filtering(void *data, unsigned index, bool smooth)
|
|
|
|
{
|
|
|
|
sdl_video_t *vid = (sdl_video_t*)data;
|
|
|
|
vid->scaler.scaler_type = smooth ? SCALER_TYPE_BILINEAR : SCALER_TYPE_POINT;
|
|
|
|
}
|
|
|
|
|
2015-11-21 12:13:55 +00:00
|
|
|
static void sdl_set_aspect_ratio(void *data, unsigned aspect_ratio_idx)
|
2014-08-08 02:34:50 +00:00
|
|
|
{
|
2015-11-21 12:13:55 +00:00
|
|
|
switch (aspect_ratio_idx)
|
2014-08-08 02:34:50 +00:00
|
|
|
{
|
|
|
|
case ASPECT_RATIO_SQUARE:
|
2016-05-08 12:00:51 +00:00
|
|
|
video_driver_set_viewport_square_pixel();
|
2014-08-08 02:34:50 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case ASPECT_RATIO_CORE:
|
2016-05-08 12:00:51 +00:00
|
|
|
video_driver_set_viewport_core();
|
2014-08-08 02:34:50 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case ASPECT_RATIO_CONFIG:
|
2016-05-08 12:00:51 +00:00
|
|
|
video_driver_set_viewport_config();
|
2014-08-08 02:34:50 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2015-11-26 01:29:43 +00:00
|
|
|
video_driver_set_aspect_ratio_value(aspectratio_lut[aspect_ratio_idx].value);
|
2014-08-08 02:34:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void sdl_apply_state_changes(void *data)
|
|
|
|
{
|
|
|
|
(void)data;
|
|
|
|
}
|
|
|
|
|
2016-05-17 06:02:13 +00:00
|
|
|
#ifdef HAVE_MENU
|
2014-08-08 02:34:50 +00:00
|
|
|
static void sdl_set_texture_frame(void *data, const void *frame, bool rgb32,
|
2015-04-03 02:20:50 +00:00
|
|
|
unsigned width, unsigned height, float alpha)
|
2014-08-08 02:34:50 +00:00
|
|
|
{
|
2016-05-04 14:56:16 +00:00
|
|
|
enum scaler_pix_fmt format = rgb32
|
|
|
|
? SCALER_FMT_ARGB8888 : SCALER_FMT_RGBA4444;
|
|
|
|
sdl_video_t *vid = (sdl_video_t*)data;
|
|
|
|
|
|
|
|
video_frame_scale(
|
|
|
|
&vid->menu.scaler,
|
|
|
|
vid->menu.frame->pixels,
|
|
|
|
frame,
|
|
|
|
format,
|
|
|
|
vid->menu.frame->w,
|
|
|
|
vid->menu.frame->h,
|
|
|
|
vid->menu.frame->pitch,
|
|
|
|
width,
|
|
|
|
height,
|
|
|
|
width * (rgb32 ? sizeof(uint32_t) : sizeof(uint16_t))
|
|
|
|
);
|
2014-08-08 02:34:50 +00:00
|
|
|
|
|
|
|
SDL_SetAlpha(vid->menu.frame, SDL_SRCALPHA, 255.0 * alpha);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void sdl_set_texture_enable(void *data, bool state, bool full_screen)
|
|
|
|
{
|
|
|
|
sdl_video_t *vid = (sdl_video_t*)data;
|
2015-04-03 02:20:50 +00:00
|
|
|
|
|
|
|
(void)full_screen;
|
|
|
|
|
2014-08-08 02:34:50 +00:00
|
|
|
vid->menu.active = state;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void sdl_show_mouse(void *data, bool state)
|
|
|
|
{
|
|
|
|
(void)data;
|
2015-04-03 02:20:50 +00:00
|
|
|
|
2014-08-08 02:34:50 +00:00
|
|
|
SDL_ShowCursor(state);
|
|
|
|
}
|
2016-05-17 06:02:13 +00:00
|
|
|
#endif
|
2014-08-08 02:34:50 +00:00
|
|
|
|
|
|
|
static void sdl_grab_mouse_toggle(void *data)
|
|
|
|
{
|
|
|
|
const SDL_GrabMode mode = SDL_WM_GrabInput(SDL_GRAB_QUERY);
|
2015-04-03 02:20:50 +00:00
|
|
|
|
|
|
|
(void)data;
|
|
|
|
|
2014-08-08 02:34:50 +00:00
|
|
|
SDL_WM_GrabInput(mode == SDL_GRAB_ON ? SDL_GRAB_OFF : SDL_GRAB_ON);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const video_poke_interface_t sdl_poke_interface = {
|
2015-12-20 19:52:23 +00:00
|
|
|
NULL,
|
|
|
|
NULL,
|
2015-02-24 20:57:51 +00:00
|
|
|
NULL,
|
2014-08-08 02:34:50 +00:00
|
|
|
sdl_set_filtering,
|
2015-02-24 19:06:58 +00:00
|
|
|
NULL, /* get_video_output_size */
|
2015-02-24 20:36:23 +00:00
|
|
|
NULL, /* get_video_output_prev */
|
|
|
|
NULL, /* get_video_output_next */
|
2015-04-25 00:35:06 +00:00
|
|
|
NULL, /* get_current_framebuffer */
|
|
|
|
NULL, /* get_proc_address */
|
2014-08-08 02:34:50 +00:00
|
|
|
sdl_set_aspect_ratio,
|
|
|
|
sdl_apply_state_changes,
|
|
|
|
#ifdef HAVE_MENU
|
|
|
|
sdl_set_texture_frame,
|
|
|
|
#endif
|
2016-05-17 06:02:13 +00:00
|
|
|
#ifdef HAVE_MENU
|
|
|
|
sdl_set_texture_enable,
|
2014-08-08 02:34:50 +00:00
|
|
|
NULL,
|
|
|
|
sdl_show_mouse,
|
2016-05-17 06:02:13 +00:00
|
|
|
#else
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
#endif
|
2014-08-08 02:34:50 +00:00
|
|
|
sdl_grab_mouse_toggle,
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
|
|
|
static void sdl_get_poke_interface(void *data, const video_poke_interface_t **iface)
|
|
|
|
{
|
|
|
|
(void)data;
|
2015-04-03 02:20:50 +00:00
|
|
|
|
2014-08-08 02:34:50 +00:00
|
|
|
*iface = &sdl_poke_interface;
|
|
|
|
}
|
|
|
|
|
2014-09-09 18:18:06 +00:00
|
|
|
static bool sdl_gfx_set_shader(void *data,
|
|
|
|
enum rarch_shader_type type, const char *path)
|
|
|
|
{
|
|
|
|
(void)data;
|
|
|
|
(void)type;
|
|
|
|
(void)path;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void sdl_gfx_set_rotation(void *data, unsigned rotation)
|
|
|
|
{
|
|
|
|
(void)data;
|
|
|
|
(void)rotation;
|
|
|
|
}
|
|
|
|
|
2017-01-22 17:17:48 +00:00
|
|
|
static bool sdl_gfx_read_viewport(void *data, uint8_t *buffer, bool is_idle)
|
2014-09-09 18:18:06 +00:00
|
|
|
{
|
|
|
|
(void)data;
|
|
|
|
(void)buffer;
|
|
|
|
|
2014-09-09 20:41:04 +00:00
|
|
|
return true;
|
2014-09-09 18:18:06 +00:00
|
|
|
}
|
|
|
|
|
2014-09-11 05:06:20 +00:00
|
|
|
video_driver_t video_sdl = {
|
2011-12-24 12:46:12 +00:00
|
|
|
sdl_gfx_init,
|
|
|
|
sdl_gfx_frame,
|
|
|
|
sdl_gfx_set_nonblock_state,
|
|
|
|
sdl_gfx_alive,
|
|
|
|
sdl_gfx_focus,
|
2015-01-18 21:32:14 +00:00
|
|
|
sdl_gfx_suppress_screensaver,
|
2014-10-08 15:23:02 +00:00
|
|
|
sdl_gfx_has_windowed,
|
2014-09-09 18:18:06 +00:00
|
|
|
sdl_gfx_set_shader,
|
2011-12-24 12:46:12 +00:00
|
|
|
sdl_gfx_free,
|
2012-10-28 10:04:07 +00:00
|
|
|
"sdl",
|
2015-04-26 17:46:59 +00:00
|
|
|
NULL,
|
2014-09-09 18:18:06 +00:00
|
|
|
sdl_gfx_set_rotation,
|
2012-10-28 10:04:07 +00:00
|
|
|
sdl_gfx_viewport_info,
|
2014-09-09 18:18:06 +00:00
|
|
|
sdl_gfx_read_viewport,
|
2015-03-16 08:33:16 +00:00
|
|
|
NULL, /* read_frame_raw */
|
2014-08-08 02:34:50 +00:00
|
|
|
#ifdef HAVE_OVERLAY
|
|
|
|
NULL,
|
|
|
|
#endif
|
|
|
|
sdl_get_poke_interface
|
2011-04-21 01:23:44 +00:00
|
|
|
};
|