mirror of
https://github.com/libretro/RetroArch
synced 2025-01-29 09:32:52 +00:00
Add sdl2_common.c/.h
This commit is contained in:
parent
efdc07ab10
commit
c5b3428408
@ -1273,7 +1273,8 @@ endif
|
||||
|
||||
ifeq ($(HAVE_SDL2), 1)
|
||||
HAVE_SDL_COMMON = 1
|
||||
OBJ += gfx/drivers/sdl2_gfx.o
|
||||
OBJ += gfx/drivers/sdl2_gfx.o \
|
||||
gfx/common/sdl2_common.o
|
||||
DEF_FLAGS += $(SDL2_CFLAGS)
|
||||
LIBS += $(SDL2_LIBS)
|
||||
else ifeq ($(HAVE_SDL), 1)
|
||||
|
80
gfx/common/sdl2_common.c
Normal file
80
gfx/common/sdl2_common.c
Normal file
@ -0,0 +1,80 @@
|
||||
/* RetroArch - A frontend for libretro.
|
||||
* Copyright (C) 2011-2019 - Daniel De Matteis
|
||||
*
|
||||
* 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 <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "../../config.h"
|
||||
#endif
|
||||
|
||||
#include <retro_miscellaneous.h>
|
||||
|
||||
#include "sdl2_common.h"
|
||||
#include "../../retroarch.h"
|
||||
|
||||
#ifdef HAVE_SDL2
|
||||
#include "SDL.h"
|
||||
#include "SDL_syswm.h"
|
||||
|
||||
void sdl2_set_handles(void *data, enum rarch_display_type display_type)
|
||||
{
|
||||
/* SysWMinfo headers are broken on OSX. */
|
||||
SDL_SysWMinfo info;
|
||||
SDL_Window *window = (SDL_Window*)data;
|
||||
SDL_VERSION(&info.version);
|
||||
|
||||
if (SDL_GetWindowWMInfo(window, &info) != 1)
|
||||
return;
|
||||
|
||||
video_driver_display_userdata_set((uintptr_t)window);
|
||||
|
||||
switch (display_type)
|
||||
{
|
||||
case RARCH_DISPLAY_WIN32:
|
||||
#if defined(_WIN32)
|
||||
video_driver_display_type_set(RARCH_DISPLAY_WIN32);
|
||||
video_driver_display_set(0);
|
||||
video_driver_window_set((uintptr_t)info.info.win.window);
|
||||
#endif
|
||||
break;
|
||||
case RARCH_DISPLAY_X11:
|
||||
#if defined(HAVE_X11)
|
||||
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);
|
||||
#endif
|
||||
break;
|
||||
case RARCH_DISPLAY_OSX:
|
||||
#ifdef HAVE_COCOA
|
||||
video_driver_display_type_set(RARCH_DISPLAY_OSX);
|
||||
video_driver_display_set(0);
|
||||
video_driver_window_set((uintptr_t)info.info.cocoa.window);
|
||||
#endif
|
||||
break;
|
||||
case RARCH_DISPLAY_WAYLAND:
|
||||
#ifdef HAVE_WAYLAND
|
||||
video_driver_display_type_set(RARCH_DISPLAY_WAYLAND);
|
||||
video_driver_display_set((uintptr_t)info.info.wl.display);
|
||||
video_driver_window_set((uintptr_t)info.info.wl.surface);
|
||||
#endif
|
||||
break;
|
||||
default:
|
||||
case RARCH_DISPLAY_NONE:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
27
gfx/common/sdl2_common.h
Normal file
27
gfx/common/sdl2_common.h
Normal file
@ -0,0 +1,27 @@
|
||||
/* RetroArch - A frontend for libretro.
|
||||
* Copyright (C) 2011-2019 - Daniel De Matteis
|
||||
*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
#ifndef SDL2_COMMON_H__
|
||||
#define SDL2_COMMON_H__
|
||||
|
||||
#include <stdint.h>
|
||||
#include <boolean.h>
|
||||
|
||||
#include "../video_defines.h"
|
||||
|
||||
void sdl2_set_handles(void *data, enum rarch_display_type
|
||||
display_type);
|
||||
|
||||
#endif
|
@ -36,6 +36,10 @@
|
||||
#include "SDL.h"
|
||||
#include "SDL_syswm.h"
|
||||
|
||||
#ifdef HAVE_SDL2
|
||||
#include "../common/sdl2_common.h"
|
||||
#endif
|
||||
|
||||
#include "../font_driver.h"
|
||||
|
||||
#include "../../configuration.h"
|
||||
@ -211,29 +215,6 @@ static void sdl2_render_msg(sdl2_video_t *vid, const char *msg)
|
||||
}
|
||||
}
|
||||
|
||||
static void sdl2_gfx_set_handles(sdl2_video_t *vid)
|
||||
{
|
||||
/* SysWMinfo headers are broken on OSX. */
|
||||
#if defined(_WIN32) || defined(HAVE_X11)
|
||||
SDL_SysWMinfo info;
|
||||
SDL_VERSION(&info.version);
|
||||
|
||||
if (SDL_GetWindowWMInfo(vid->window, &info) != 1)
|
||||
return;
|
||||
|
||||
video_driver_display_userdata_set((uintptr_t)vid->window);
|
||||
#if defined(_WIN32)
|
||||
video_driver_display_type_set(RARCH_DISPLAY_WIN32);
|
||||
video_driver_display_set(0);
|
||||
video_driver_window_set((uintptr_t)info.info.win.window);
|
||||
#elif defined(HAVE_X11)
|
||||
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);
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
static void sdl2_init_renderer(sdl2_video_t *vid)
|
||||
{
|
||||
unsigned flags = SDL_RENDERER_ACCELERATED;
|
||||
@ -449,7 +430,13 @@ static void *sdl2_gfx_init(const video_info_t *video,
|
||||
sdl2_init_renderer(vid);
|
||||
sdl2_init_font(vid, settings->paths.path_font, settings->floats.video_font_size);
|
||||
|
||||
sdl2_gfx_set_handles(vid);
|
||||
#if defined(_WIN32)
|
||||
sdl2_set_handles(vid->window, RARCH_DISPLAY_WIN32);
|
||||
#elif defined(HAVE_X11)
|
||||
sdl2_set_handles(vid->window, RARCH_DISPLAY_X11);
|
||||
#elif defined(HAVE_COCOA)
|
||||
sdl2_set_handles(vid->window, RARCH_DISPLAY_OSX);
|
||||
#endif
|
||||
|
||||
sdl_refresh_viewport(vid);
|
||||
|
||||
|
@ -28,6 +28,10 @@
|
||||
|
||||
#include "SDL.h"
|
||||
|
||||
#ifdef HAVE_SDL2
|
||||
#include "../common/sdl2_common.h"
|
||||
#endif
|
||||
|
||||
static enum gfx_ctx_api sdl_api = GFX_CTX_OPENGL_API;
|
||||
static unsigned g_major = 2;
|
||||
static unsigned g_minor = 1;
|
||||
@ -214,6 +218,14 @@ static bool sdl_ctx_set_video_mode(void *data,
|
||||
goto error;
|
||||
|
||||
#ifdef HAVE_SDL2
|
||||
#if defined(_WIN32)
|
||||
sdl2_set_handles(sdl->g_win, RARCH_DISPLAY_WIN32);
|
||||
#elif defined(HAVE_X11)
|
||||
sdl2_set_handles(sdl->g_win, RARCH_DISPLAY_X11);
|
||||
#elif defined(HAVE_COCOA)
|
||||
sdl2_set_handles(sdl->g_win, RARCH_DISPLAY_OSX);
|
||||
#endif
|
||||
|
||||
if (sdl->g_ctx)
|
||||
video_driver_set_video_cache_context_ack();
|
||||
else
|
||||
@ -276,20 +288,18 @@ static void sdl_ctx_get_video_size(void *data,
|
||||
static void sdl_ctx_update_title(void *data, void *data2)
|
||||
{
|
||||
char title[128];
|
||||
|
||||
title[0] = '\0';
|
||||
|
||||
video_driver_get_window_title(title, sizeof(title));
|
||||
|
||||
#ifdef HAVE_SDL2
|
||||
gfx_ctx_sdl_data_t *sdl = (gfx_ctx_sdl_data_t*)data;
|
||||
|
||||
if (sdl && title[0])
|
||||
SDL_SetWindowTitle(sdl->g_win, title);
|
||||
#else
|
||||
if (title[0])
|
||||
{
|
||||
#ifdef HAVE_SDL2
|
||||
SDL_SetWindowTitle((SDL_Window*)video_driver_display_userdata_get(), title);
|
||||
#else
|
||||
SDL_WM_SetCaption(title, NULL);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
static void sdl_ctx_check_window(void *data, bool *quit,
|
||||
|
@ -76,6 +76,7 @@ enum rarch_display_type
|
||||
RARCH_DISPLAY_X11,
|
||||
/* video_display => N/A, video_window => HWND */
|
||||
RARCH_DISPLAY_WIN32,
|
||||
RARCH_DISPLAY_WAYLAND,
|
||||
RARCH_DISPLAY_OSX
|
||||
};
|
||||
|
||||
|
@ -406,6 +406,7 @@ VIDEO DRIVER
|
||||
|
||||
#ifdef HAVE_SDL2
|
||||
#include "../gfx/drivers/sdl2_gfx.c"
|
||||
#include "../gfx/common/sdl2_common.c"
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_VG
|
||||
|
Loading…
x
Reference in New Issue
Block a user