RetroArch/gfx/drivers/sdl2_gfx.c

778 lines
19 KiB
C
Raw Normal View History

2014-08-10 16:35:18 +00:00
/* RetroArch - A frontend for libretro.
* Copyright (C) 2010-2014 - Hans-Kristian Arntzen
2015-01-07 17:06:50 +00:00
* Copyright (C) 2011-2015 - Higor Euripedes
2014-08-10 16:35:18 +00:00
*
* RetroArch is free software: you can redistribute it and/or modify it under the terms
* 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.
*
* RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with RetroArch.
* If not, see <http://www.gnu.org/licenses/>.
*/
#include "SDL.h"
#include "SDL_syswm.h"
#include "../../driver.h"
2014-08-10 16:35:18 +00:00
#include <stdlib.h>
#include <string.h>
#include "../../general.h"
#include "../../retroarch.h"
#include "../../runloop.h"
#include "../../performance.h"
#include <retro_inline.h>
2014-10-23 02:34:35 +00:00
#include <gfx/scaler/scaler.h>
2015-01-18 22:59:57 +00:00
#include "../video_viewport.h"
#include "../video_monitor.h"
#include "../video_context_driver.h"
2015-01-12 22:34:10 +00:00
#include "../font_renderer_driver.h"
2014-08-10 16:35:18 +00:00
#ifdef HAVE_X11
2015-04-09 03:02:57 +00:00
#include "../common/x11_common.h"
2014-08-10 16:35:18 +00:00
#endif
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
typedef struct sdl2_tex
{
SDL_Texture *tex;
2015-03-16 16:52:55 +00:00
unsigned w;
unsigned h;
size_t pitch;
2014-08-10 16:35:18 +00:00
bool active;
bool rgb32;
} sdl2_tex_t;
2014-08-10 21:07:37 +00:00
typedef struct _sdl2_video
2014-08-10 16:35:18 +00:00
{
2014-08-10 18:00:21 +00:00
SDL_Window *window;
2014-08-10 16:35:18 +00:00
SDL_Renderer *renderer;
sdl2_tex_t frame;
sdl2_tex_t menu;
sdl2_tex_t font;
bool gl;
bool quitting;
void *font_data;
const font_renderer_driver_t *font_driver;
uint8_t font_r;
uint8_t font_g;
uint8_t font_b;
2015-02-14 04:52:05 +00:00
struct video_viewport vp;
2014-08-10 16:35:18 +00:00
video_info_t video;
bool should_resize;
double rotation;
} sdl2_video_t;
static void sdl2_gfx_free(void *data);
static INLINE void sdl_tex_zero(sdl2_tex_t *t)
2014-08-10 16:35:18 +00:00
{
if (t->tex)
SDL_DestroyTexture(t->tex);
t->tex = NULL;
t->w = t->h = t->pitch = 0;
}
static void sdl2_init_font(sdl2_video_t *vid, const char *font_path,
unsigned font_size)
{
2015-01-22 00:08:20 +00:00
int i, r, g, b;
SDL_Color colors[256];
SDL_Surface *tmp;
SDL_Palette *pal = NULL;
const struct font_atlas *atlas = NULL;
2015-03-20 21:08:36 +00:00
settings_t *settings = config_get_ptr();
2015-01-22 00:08:20 +00:00
2015-03-20 21:08:36 +00:00
if (!settings->video.font_enable)
2014-08-10 16:35:18 +00:00
return;
2015-01-22 00:08:20 +00:00
if (!font_renderer_create_default(&vid->font_driver, &vid->font_data,
2014-08-10 16:35:18 +00:00
*font_path ? font_path : NULL, font_size))
{
RARCH_WARN("[SDL]: Could not initialize fonts.\n");
return;
}
2015-03-20 21:08:36 +00:00
r = settings->video.msg_color_r * 255;
g = settings->video.msg_color_g * 255;
b = settings->video.msg_color_b * 255;
2014-08-10 16:35:18 +00:00
2015-01-22 00:08:20 +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;
atlas = vid->font_driver->get_atlas(vid->font_data);
tmp = SDL_CreateRGBSurfaceFrom(atlas->buffer, atlas->width,
atlas->height, 8, atlas->width,
0, 0, 0, 0);
2014-08-10 16:35:18 +00:00
for (i = 0; i < 256; ++i)
{
colors[i].r = colors[i].g = colors[i].b = i;
colors[i].a = 255;
}
2015-01-22 00:08:20 +00:00
pal = SDL_AllocPalette(256);
2014-08-10 16:35:18 +00:00
SDL_SetPaletteColors(pal, colors, 0, 256);
SDL_SetSurfacePalette(tmp, pal);
SDL_SetColorKey(tmp, SDL_TRUE, 0);
vid->font.tex = SDL_CreateTextureFromSurface(vid->renderer, tmp);
if (vid->font.tex)
{
vid->font.w = atlas->width;
vid->font.h = atlas->height;
vid->font.active = true;
SDL_SetTextureBlendMode(vid->font.tex, SDL_BLENDMODE_ADD);
}
else
RARCH_WARN("[SDL]: Failed to initialize font texture: %s\n", SDL_GetError());
SDL_FreePalette(pal);
SDL_FreeSurface(tmp);
}
static void sdl2_render_msg(sdl2_video_t *vid, const char *msg)
{
2015-01-22 00:08:20 +00:00
int x, y, delta_x, delta_y;
2014-08-10 16:35:18 +00:00
unsigned width = vid->vp.width;
unsigned height = vid->vp.height;
2015-03-20 21:08:36 +00:00
settings_t *settings = config_get_ptr();
2014-08-10 16:35:18 +00:00
if (!vid->font_data)
return;
2015-03-20 21:08:36 +00:00
x = settings->video.msg_pos_x * width;
y = (1.0f - settings->video.msg_pos_y) * height;
2014-08-10 16:35:18 +00:00
delta_x = 0;
delta_y = 0;
SDL_SetTextureColorMod(vid->font.tex, vid->font_r, vid->font_g, vid->font_b);
for (; *msg; msg++)
{
2015-01-22 00:08:20 +00:00
int off_x, off_y, tex_x, tex_y;
2014-08-10 16:35:18 +00:00
const struct font_glyph *gly = vid->font_driver->get_glyph(vid->font_data, (uint8_t)*msg);
if (!gly)
gly = vid->font_driver->get_glyph(vid->font_data, '?');
if (!gly)
continue;
2015-01-22 00:08:20 +00:00
off_x = gly->draw_offset_x;
off_y = gly->draw_offset_y;
tex_x = gly->atlas_offset_x;
tex_y = gly->atlas_offset_y;
2014-08-10 16:35:18 +00:00
SDL_Rect srcrect = {
tex_x, tex_y,
2015-03-16 16:52:55 +00:00
(int)gly->width, (int)gly->height
2014-08-10 16:35:18 +00:00
};
SDL_Rect dstrect = {
x + delta_x + off_x, y + delta_y + off_y,
2015-03-16 16:52:55 +00:00
(int)gly->width, (int)gly->height
2014-08-10 16:35:18 +00:00
};
SDL_RenderCopyEx(vid->renderer, vid->font.tex, &srcrect, &dstrect, 0, NULL, SDL_FLIP_NONE);
delta_x += gly->advance_x;
delta_y -= gly->advance_y;
}
}
static void sdl2_gfx_set_handles(sdl2_video_t *vid)
{
driver_t *driver = driver_get_ptr();
2015-01-22 00:08:20 +00:00
/* SysWMinfo headers are broken on OSX. */
#if defined(_WIN32) || defined(HAVE_X11)
2014-08-10 16:35:18 +00:00
SDL_SysWMinfo info;
SDL_VERSION(&info.version);
2015-01-22 00:08:20 +00:00
if (SDL_GetWindowWMInfo(vid->window, &info) != 1)
return;
#if defined(_WIN32)
driver->display_type = RARCH_DISPLAY_WIN32;
driver->video_display = 0;
driver->video_window = (uintptr_t)info.info.win.window;
2014-08-10 16:35:18 +00:00
#elif defined(HAVE_X11)
driver->display_type = RARCH_DISPLAY_X11;
driver->video_display = (uintptr_t)info.info.x11.display;
driver->video_window = (uintptr_t)info.info.x11.window;
#endif
2014-08-10 16:35:18 +00:00
#endif
}
static void sdl2_init_renderer(sdl2_video_t *vid)
{
unsigned flags = SDL_RENDERER_ACCELERATED;
if (vid->video.vsync)
flags |= SDL_RENDERER_PRESENTVSYNC;
SDL_ClearHints();
SDL_SetHintWithPriority(SDL_HINT_RENDER_VSYNC,
vid->video.vsync ? "1" : "0", SDL_HINT_OVERRIDE);
vid->renderer = SDL_CreateRenderer(vid->window, -1, flags);
if (!vid->renderer)
{
RARCH_ERR("[SDL]: Failed to initialize renderer: %s", SDL_GetError());
return;
}
SDL_SetRenderDrawColor(vid->renderer, 0, 0, 0, 255);
}
static void sdl_refresh_renderer(sdl2_video_t *vid)
{
SDL_RenderClear(vid->renderer);
2015-03-16 16:52:55 +00:00
SDL_Rect r = { vid->vp.x, vid->vp.y, (int)vid->vp.width, (int)vid->vp.height };
2014-08-10 16:35:18 +00:00
SDL_RenderSetViewport(vid->renderer, &r);
// breaks int scaling
// SDL_RenderSetLogicalSize(vid->renderer, vid->vp.width, vid->vp.height);
}
static void sdl_refresh_viewport(sdl2_video_t *vid)
{
int win_w, win_h;
2015-03-20 21:08:36 +00:00
settings_t *settings = config_get_ptr();
2015-03-21 04:42:49 +00:00
global_t *global = global_get_ptr();
2014-08-10 16:35:18 +00:00
SDL_GetWindowSize(vid->window, &win_w, &win_h);
vid->vp.x = 0;
vid->vp.y = 0;
vid->vp.width = win_w;
vid->vp.height = win_h;
vid->vp.full_width = win_w;
vid->vp.full_height = win_h;
2015-03-20 21:08:36 +00:00
if (settings->video.scale_integer)
2015-03-21 04:42:49 +00:00
video_viewport_get_scaled_integer(&vid->vp, win_w, win_h, global->system.aspect_ratio,
2014-08-10 16:35:18 +00:00
vid->video.force_aspect);
2015-03-20 21:08:36 +00:00
else if (settings->video.aspect_ratio_idx == ASPECT_RATIO_CUSTOM)
2014-08-10 16:35:18 +00:00
{
2015-03-21 04:42:49 +00:00
const struct video_viewport *custom = &global->console.screen.viewports.custom_vp;
2014-08-10 16:35:18 +00:00
2015-02-14 04:52:05 +00:00
if (custom)
{
vid->vp.x = custom->x;
vid->vp.y = custom->y;
vid->vp.width = custom->width;
vid->vp.height = custom->height;
}
2014-08-10 16:35:18 +00:00
}
else if (vid->video.force_aspect)
{
float delta;
float device_aspect = (float)win_w / win_h;
2015-03-21 04:42:49 +00:00
float desired_aspect = global->system.aspect_ratio;
2014-08-10 16:35:18 +00:00
if (fabsf(device_aspect - desired_aspect) < 0.0001f)
{
/* If the aspect ratios of screen and desired aspect ratio are
* sufficiently equal (floating point stuff), assume they are
* actually equal. */
}
else if (device_aspect > desired_aspect)
{
delta = (desired_aspect / device_aspect - 1.0f) / 2.0f + 0.5f;
vid->vp.x = (int)roundf(win_w * (0.5f - delta));
vid->vp.width = (unsigned)roundf(2.0f * win_w * delta);
}
else
{
delta = (device_aspect / desired_aspect - 1.0f) / 2.0f + 0.5f;
vid->vp.y = (int)roundf(win_h * (0.5f - delta));
vid->vp.height = (unsigned)roundf(2.0f * win_h * delta);
}
}
vid->should_resize = false;
sdl_refresh_renderer(vid);
}
static void sdl_refresh_input_size(sdl2_video_t *vid, bool menu, bool rgb32,
unsigned width, unsigned height, unsigned pitch)
{
sdl2_tex_t *target = menu ? &vid->menu : &vid->frame;
if (!target->tex || target->w != width || target->h != height
|| target->rgb32 != rgb32 || target->pitch != pitch)
{
unsigned format;
sdl_tex_zero(target);
RARCH_PERFORMANCE_INIT(sdl_create_texture);
RARCH_PERFORMANCE_START(sdl_create_texture);
if (menu)
format = rgb32 ? SDL_PIXELFORMAT_ARGB8888 : SDL_PIXELFORMAT_RGBA4444;
else /* this assumes the frontend will convert 0RGB1555 to RGB565 */
format = rgb32 ? SDL_PIXELFORMAT_ARGB8888 : SDL_PIXELFORMAT_RGB565;
2014-08-10 16:35:18 +00:00
SDL_SetHintWithPriority(SDL_HINT_RENDER_SCALE_QUALITY,
(vid->video.smooth || menu) ? "linear" : "nearest",
SDL_HINT_OVERRIDE);
target->tex = SDL_CreateTexture(vid->renderer, format,
SDL_TEXTUREACCESS_STREAMING, width, height);
RARCH_PERFORMANCE_STOP(sdl_create_texture);
if (!target->tex)
{
RARCH_ERR("Failed to create %s texture: %s\n", menu ? "menu" : "main",
SDL_GetError());
return;
}
if (menu)
SDL_SetTextureBlendMode(target->tex, SDL_BLENDMODE_BLEND);
target->w = width;
target->h = height;
target->pitch = pitch;
target->rgb32 = rgb32;
target->active = true;
}
}
static void *sdl2_gfx_init(const video_info_t *video, const input_driver_t **input, void **input_data)
{
2015-01-22 00:08:20 +00:00
int i;
unsigned flags;
2015-03-20 21:08:36 +00:00
settings_t *settings = config_get_ptr();
2014-08-10 16:35:18 +00:00
#ifdef HAVE_X11
XInitThreads();
#endif
if (SDL_WasInit(0) == 0)
{
if (SDL_Init(SDL_INIT_VIDEO) < 0)
return NULL;
}
else if (SDL_InitSubSystem(SDL_INIT_VIDEO) < 0)
return NULL;
2014-08-10 16:35:18 +00:00
sdl2_video_t *vid = (sdl2_video_t*)calloc(1, sizeof(*vid));
if (!vid)
return NULL;
2014-08-27 01:42:51 +00:00
RARCH_LOG("[SDL]: Available renderers (change with $SDL_RENDER_DRIVER):\n");
for (i = 0; i < SDL_GetNumRenderDrivers(); ++i)
{
2014-08-27 01:42:51 +00:00
SDL_RendererInfo renderer;
if (SDL_GetRenderDriverInfo(i, &renderer) == 0)
RARCH_LOG("\t%s\n", renderer.name);
}
2014-08-10 16:35:18 +00:00
RARCH_LOG("[SDL]: Available displays:\n");
for(i = 0; i < SDL_GetNumVideoDisplays(); ++i)
{
SDL_DisplayMode mode;
2014-08-21 01:11:30 +00:00
if (SDL_GetCurrentDisplayMode(i, &mode) < 0)
2014-08-10 16:35:18 +00:00
RARCH_LOG("\tDisplay #%i mode: unknown.\n", i);
else
RARCH_LOG("\tDisplay #%i mode: %ix%i@%ihz.\n", i, mode.w, mode.h,
mode.refresh_rate);
}
// void *sdl_input = NULL;
if (!video->fullscreen)
RARCH_LOG("[SDL]: Creating window @ %ux%u\n", video->width, video->height);
if (video->fullscreen)
2015-03-20 21:08:36 +00:00
flags = settings->video.windowed_fullscreen ? SDL_WINDOW_FULLSCREEN_DESKTOP : SDL_WINDOW_FULLSCREEN;
2014-08-10 16:35:18 +00:00
else
flags = SDL_WINDOW_RESIZABLE;
vid->window = SDL_CreateWindow("", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED,
video->width, video->height, flags);
if (!vid->window)
{
RARCH_ERR("[SDL]: Failed to init SDL window: %s\n", SDL_GetError());
goto error;
}
vid->video = *video;
2015-03-20 21:08:36 +00:00
vid->video.smooth = settings->video.smooth;
2014-08-10 16:35:18 +00:00
vid->should_resize = true;
sdl_tex_zero(&vid->frame);
sdl_tex_zero(&vid->menu);
if (video->fullscreen)
SDL_ShowCursor(SDL_DISABLE);
sdl2_init_renderer(vid);
2015-03-20 21:08:36 +00:00
sdl2_init_font(vid, settings->video.font_path, settings->video.font_size);
2014-08-10 16:35:18 +00:00
sdl2_gfx_set_handles(vid);
*input = NULL;
*input_data = NULL;
2014-08-10 16:35:18 +00:00
return vid;
error:
sdl2_gfx_free(vid);
return NULL;
}
static void check_window(sdl2_video_t *vid)
{
SDL_Event event;
SDL_PumpEvents();
while (SDL_PeepEvents(&event, 1, SDL_GETEVENT, SDL_QUIT, SDL_WINDOWEVENT) > 0)
2014-08-10 16:35:18 +00:00
{
switch (event.type)
{
case SDL_QUIT:
vid->quitting = true;
break;
case SDL_WINDOWEVENT:
if (event.window.event == SDL_WINDOWEVENT_RESIZED)
vid->should_resize = true;
2014-08-10 16:35:18 +00:00
break;
default:
break;
}
}
}
static bool sdl2_gfx_frame(void *data, const void *frame, unsigned width,
unsigned height, unsigned pitch, const char *msg)
{
char buf[128];
2014-08-10 16:35:18 +00:00
sdl2_video_t *vid = (sdl2_video_t*)data;
2015-03-18 05:47:22 +00:00
runloop_t *runloop = rarch_main_get_ptr();
driver_t *driver = driver_get_ptr();
2014-08-10 16:35:18 +00:00
if (vid->should_resize)
sdl_refresh_viewport(vid);
if (frame)
{
sdl_refresh_input_size(vid, false, vid->video.rgb32, width, height, pitch);
2014-08-10 16:35:18 +00:00
RARCH_PERFORMANCE_INIT(sdl_copy_frame);
RARCH_PERFORMANCE_START(sdl_copy_frame);
SDL_UpdateTexture(vid->frame.tex, NULL, frame, pitch);
RARCH_PERFORMANCE_STOP(sdl_copy_frame);
}
SDL_RenderCopyEx(vid->renderer, vid->frame.tex, NULL, NULL, vid->rotation, NULL, SDL_FLIP_NONE);
#ifdef HAVE_MENU
2015-03-22 04:27:19 +00:00
if (runloop->is_menu)
menu_driver_frame();
2014-08-10 16:35:18 +00:00
#endif
if (vid->menu.active)
SDL_RenderCopy(vid->renderer, vid->menu.tex, NULL, NULL);
if (msg)
sdl2_render_msg(vid, msg);
SDL_RenderPresent(vid->renderer);
if (video_monitor_get_fps(buf, sizeof(buf), NULL, 0))
2014-08-10 16:35:18 +00:00
SDL_SetWindowTitle(vid->window, buf);
return true;
}
static void sdl2_gfx_set_nonblock_state(void *data, bool toggle)
{
sdl2_video_t *vid = (sdl2_video_t*)data;
vid->video.vsync = !toggle;
sdl_refresh_renderer(vid);
}
static bool sdl2_gfx_alive(void *data)
{
sdl2_video_t *vid = (sdl2_video_t*)data;
check_window(vid);
return !vid->quitting;
}
static bool sdl2_gfx_focus(void *data)
{
sdl2_video_t *vid = (sdl2_video_t*)data;
unsigned flags = (SDL_WINDOW_INPUT_FOCUS | SDL_WINDOW_MOUSE_FOCUS);
return (SDL_GetWindowFlags(vid->window) & flags) == flags;
}
2015-01-18 21:32:14 +00:00
static bool sdl2_gfx_suppress_screensaver(void *data, bool enable)
{
driver_t *driver = driver_get_ptr();
2015-01-18 21:32:14 +00:00
(void)data;
(void)enable;
if (driver->display_type == RARCH_DISPLAY_X11)
2015-01-18 21:32:14 +00:00
{
#ifdef HAVE_X11
x11_suspend_screensaver(driver->video_window);
2015-01-18 21:32:14 +00:00
#endif
return true;
}
return false;
}
static bool sdl2_gfx_has_windowed(void *data)
{
(void)data;
/* TODO - implement */
return true;
}
2014-08-10 16:35:18 +00:00
static void sdl2_gfx_free(void *data)
{
sdl2_video_t *vid = (sdl2_video_t*)data;
if (!vid)
return;
if (vid->renderer)
SDL_DestroyRenderer(vid->renderer);
if (vid->window)
SDL_DestroyWindow(vid->window);
2014-08-10 16:35:18 +00:00
SDL_QuitSubSystem(SDL_INIT_VIDEO);
if (vid->font_data)
vid->font_driver->free(vid->font_data);
free(vid);
}
static void sdl2_gfx_set_rotation(void *data, unsigned rotation)
{
sdl2_video_t *vid = (sdl2_video_t*)data;
vid->rotation = 270 * rotation;
}
2015-02-14 04:52:05 +00:00
static void sdl2_gfx_viewport_info(void *data, struct video_viewport *vp)
2014-08-10 16:35:18 +00:00
{
sdl2_video_t *vid = (sdl2_video_t*)data;
*vp = vid->vp;
}
static bool sdl2_gfx_read_viewport(void *data, uint8_t *buffer)
{
sdl2_video_t *vid = (sdl2_video_t*)data;
RARCH_PERFORMANCE_INIT(sdl2_gfx_read_viewport);
RARCH_PERFORMANCE_START(sdl2_gfx_read_viewport);
rarch_render_cached_frame();
SDL_Surface *surf = SDL_GetWindowSurface(vid->window);
SDL_Surface *bgr24 = SDL_ConvertSurfaceFormat(surf, SDL_PIXELFORMAT_BGR24, 0);
if (!bgr24)
{
RARCH_WARN("Failed to convert viewport data to BGR24: %s", SDL_GetError());
return false;
}
memcpy(buffer, bgr24->pixels, bgr24->h * bgr24->pitch);
RARCH_PERFORMANCE_STOP(sdl2_gfx_read_viewport);
return true;
}
void sdl2_poke_set_filtering(void *data, unsigned index, bool smooth)
{
sdl2_video_t *vid = (sdl2_video_t*)data;
vid->video.smooth = smooth;
sdl_tex_zero(&vid->frame);
}
static void sdl2_poke_set_aspect_ratio(void *data, unsigned aspectratio_index)
{
2015-03-21 04:42:49 +00:00
sdl2_video_t *vid = (sdl2_video_t*)data;
global_t *global = global_get_ptr();
2014-08-10 16:35:18 +00:00
switch (aspectratio_index)
{
case ASPECT_RATIO_SQUARE:
2015-03-21 04:42:49 +00:00
video_viewport_set_square_pixel(global->system.av_info.geometry.base_width,
global->system.av_info.geometry.base_height);
2014-08-10 16:35:18 +00:00
break;
case ASPECT_RATIO_CORE:
2015-01-18 22:59:57 +00:00
video_viewport_set_core();
2014-08-10 16:35:18 +00:00
break;
case ASPECT_RATIO_CONFIG:
2015-01-18 22:59:57 +00:00
video_viewport_set_config();
2014-08-10 16:35:18 +00:00
break;
default:
break;
}
2015-03-21 04:42:49 +00:00
global->system.aspect_ratio = aspectratio_lut[aspectratio_index].value;
2014-08-10 16:35:18 +00:00
vid->video.force_aspect = true;
vid->should_resize = true;
}
void sdl2_poke_apply_state_changes(void *data)
{
sdl2_video_t *vid = (sdl2_video_t*)data;
vid->should_resize = true;
}
void sdl2_poke_set_texture_frame(void *data, const void *frame, bool rgb32,
unsigned width, unsigned height, float alpha)
{
sdl2_video_t *vid = (sdl2_video_t*)data;
if (frame)
{
sdl_refresh_input_size(vid, true, rgb32, width, height,
width * (rgb32 ? 4 : 2));
RARCH_PERFORMANCE_INIT(copy_texture_frame);
RARCH_PERFORMANCE_START(copy_texture_frame);
SDL_UpdateTexture(vid->menu.tex, NULL, frame, vid->menu.pitch);
RARCH_PERFORMANCE_STOP(copy_texture_frame);
}
}
void sdl2_poke_texture_enable(void *data, bool enable, bool full_screen)
{
sdl2_video_t *vid = (sdl2_video_t*)data;
vid->menu.active = enable;
}
void sdl2_poke_set_osd_msg(void *data, const char *msg, const struct font_params *params, void *font)
2014-08-10 16:35:18 +00:00
{
sdl2_video_t *vid = (sdl2_video_t*)data;
sdl2_render_msg(vid, msg);
fprintf(stderr, "[SDL]: OSD MSG: %s\n", msg);
}
void sdl2_show_mouse(void *data, bool state)
{
(void)data;
SDL_ShowCursor(state);
}
2014-08-10 18:00:21 +00:00
void sdl2_grab_mouse_toggle(void *data)
{
sdl2_video_t *vid = (sdl2_video_t*)data;
SDL_SetWindowGrab(vid->window, SDL_GetWindowGrab(vid->window));
}
2014-08-10 16:35:18 +00:00
static video_poke_interface_t sdl2_video_poke_interface = {
NULL,
2014-08-10 16:35:18 +00:00
sdl2_poke_set_filtering,
NULL, /* get_video_output_size */
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-10 16:35:18 +00:00
sdl2_poke_set_aspect_ratio,
sdl2_poke_apply_state_changes,
#ifdef HAVE_MENU
sdl2_poke_set_texture_frame,
sdl2_poke_texture_enable,
#endif
sdl2_poke_set_osd_msg,
sdl2_show_mouse,
2014-08-10 18:00:21 +00:00
sdl2_grab_mouse_toggle,
2014-08-10 16:35:18 +00:00
NULL,
};
void sdl2_gfx_poke_interface(void *data, const video_poke_interface_t **iface)
{
(void)data;
*iface = &sdl2_video_poke_interface;
}
static bool sdl2_gfx_set_shader(void *data,
enum rarch_shader_type type, const char *path)
{
(void)data;
(void)type;
(void)path;
return false;
}
2014-09-11 05:06:20 +00:00
video_driver_t video_sdl2 = {
2014-08-10 16:35:18 +00:00
sdl2_gfx_init,
sdl2_gfx_frame,
sdl2_gfx_set_nonblock_state,
sdl2_gfx_alive,
sdl2_gfx_focus,
2015-01-18 21:32:14 +00:00
sdl2_gfx_suppress_screensaver,
sdl2_gfx_has_windowed,
sdl2_gfx_set_shader,
2014-08-10 16:35:18 +00:00
sdl2_gfx_free,
"sdl2",
NULL,
2014-08-10 16:35:18 +00:00
sdl2_gfx_set_rotation,
sdl2_gfx_viewport_info,
sdl2_gfx_read_viewport,
NULL, /* read_frame_raw */
2014-08-10 16:35:18 +00:00
#ifdef HAVE_OVERLAY
2015-01-22 00:08:20 +00:00
NULL,
2014-08-10 16:35:18 +00:00
#endif
sdl2_gfx_poke_interface
};