sdl 2.0.8 update

This commit is contained in:
Tim 2018-05-09 23:09:05 +10:00
parent d6f6bc65a5
commit ec8f56b3b0
894 changed files with 66879 additions and 43299 deletions

View file

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages

View file

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@ -19,8 +19,8 @@
3. This notice may not be removed or altered from any source distribution.
*/
#ifndef _SDL_rpievents_c_h
#define _SDL_rpievents_c_h
#ifndef SDL_rpievents_c_h_
#define SDL_rpievents_c_h_
#include "SDL_rpivideo.h"
@ -28,4 +28,4 @@ void RPI_PumpEvents(_THIS);
void RPI_EventInit(_THIS);
void RPI_EventQuit(_THIS);
#endif /* _SDL_rpievents_c_h */
#endif /* SDL_rpievents_c_h_ */

View file

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@ -165,7 +165,7 @@ RPI_ShowCursor(SDL_Cursor * cursor)
if (curdata->element == DISPMANX_NO_HANDLE) {
vc_dispmanx_rect_set(&src_rect, 0, 0, curdata->w << 16, curdata->h << 16);
vc_dispmanx_rect_set(&dst_rect, 0, 0, curdata->w, curdata->h);
vc_dispmanx_rect_set(&dst_rect, mouse->x, mouse->y, curdata->w, curdata->h);
update = vc_dispmanx_update_start(10);
SDL_assert(update);
@ -247,6 +247,65 @@ RPI_WarpMouseGlobal(int x, int y)
return 0;
}
/* Update internal mouse position. */
SDL_SendMouseMotion(mouse->focus, mouse->mouseID, 0, x, y);
curdata = (RPI_CursorData *) mouse->cur_cursor->driverdata;
if (curdata->element == DISPMANX_NO_HANDLE) {
return 0;
}
update = vc_dispmanx_update_start(10);
if (!update) {
return 0;
}
src_rect.x = 0;
src_rect.y = 0;
src_rect.width = curdata->w << 16;
src_rect.height = curdata->h << 16;
dst_rect.x = x;
dst_rect.y = y;
dst_rect.width = curdata->w;
dst_rect.height = curdata->h;
ret = vc_dispmanx_element_change_attributes(
update,
curdata->element,
0,
0,
0,
&dst_rect,
&src_rect,
DISPMANX_NO_HANDLE,
DISPMANX_NO_ROTATE);
if (ret != DISPMANX_SUCCESS) {
return SDL_SetError("vc_dispmanx_element_change_attributes() failed");
}
/* Submit asynchronously, otherwise the peformance suffers a lot */
ret = vc_dispmanx_update_submit(update, 0, NULL);
if (ret != DISPMANX_SUCCESS) {
return SDL_SetError("vc_dispmanx_update_submit() failed");
}
return 0;
}
/* Warp the mouse to (x,y) */
static int
RPI_WarpMouseGlobalGraphicOnly(int x, int y)
{
RPI_CursorData *curdata;
DISPMANX_UPDATE_HANDLE_T update;
int ret;
VC_RECT_T dst_rect;
VC_RECT_T src_rect;
SDL_Mouse *mouse = SDL_GetMouse();
if (mouse == NULL || mouse->cur_cursor == NULL || mouse->cur_cursor->driverdata == NULL) {
return 0;
}
curdata = (RPI_CursorData *) mouse->cur_cursor->driverdata;
if (curdata->element == DISPMANX_NO_HANDLE) {
return 0;
@ -317,7 +376,9 @@ static void
RPI_MoveCursor(SDL_Cursor * cursor)
{
SDL_Mouse *mouse = SDL_GetMouse();
RPI_WarpMouse(mouse->focus, mouse->x, mouse->y);
/* We must NOT call SDL_SendMouseMotion() on the next call or we will enter recursivity,
* so we create a version of WarpMouseGlobal without it. */
RPI_WarpMouseGlobalGraphicOnly(mouse->x, mouse->y);
}
#endif /* SDL_VIDEO_DRIVER_RPI */

View file

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@ -19,8 +19,8 @@
3. This notice may not be removed or altered from any source distribution.
*/
#ifndef _SDL_RPI_mouse_h
#define _SDL_RPI_mouse_h
#ifndef SDL_RPI_mouse_h_
#define SDL_RPI_mouse_h_
#include "../SDL_sysvideo.h"
@ -38,6 +38,6 @@ struct _RPI_CursorData
extern void RPI_InitMouse(_THIS);
extern void RPI_QuitMouse(_THIS);
#endif /* _SDL_RPI_mouse_h */
#endif /* SDL_RPI_mouse_h_ */
/* vi: set ts=4 sw=4 expandtab: */

View file

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@ -19,6 +19,8 @@
3. This notice may not be removed or altered from any source distribution.
*/
#include "../../SDL_internal.h"
#include "SDL_hints.h"
#include "SDL_log.h"
#if SDL_VIDEO_DRIVER_RPI && SDL_VIDEO_OPENGL_EGL
@ -27,13 +29,40 @@
/* EGL implementation of SDL OpenGL support */
void
RPI_GLES_DefaultProfileConfig(_THIS, int *mask, int *major, int *minor)
{
*mask = SDL_GL_CONTEXT_PROFILE_ES;
*major = 2;
*minor = 0;
}
int
RPI_GLES_LoadLibrary(_THIS, const char *path) {
return SDL_EGL_LoadLibrary(_this, path, EGL_DEFAULT_DISPLAY);
return SDL_EGL_LoadLibrary(_this, path, EGL_DEFAULT_DISPLAY, 0);
}
int
RPI_GLES_SwapWindow(_THIS, SDL_Window * window) {
SDL_WindowData *wdata = ((SDL_WindowData *) window->driverdata);
if (!(_this->egl_data->eglSwapBuffers(_this->egl_data->egl_display, wdata->egl_surface))) {
SDL_LogError(SDL_LOG_CATEGORY_VIDEO, "eglSwapBuffers failed.");
return 0;
}
/* Wait immediately for vsync (as if we only had two buffers), for low input-lag scenarios.
* Run your SDL2 program with "SDL_RPI_DOUBLE_BUFFER=1 <program_name>" to enable this. */
if (wdata->double_buffer) {
SDL_LockMutex(wdata->vsync_cond_mutex);
SDL_CondWait(wdata->vsync_cond, wdata->vsync_cond_mutex);
SDL_UnlockMutex(wdata->vsync_cond_mutex);
}
return 0;
}
SDL_EGL_CreateContext_impl(RPI)
SDL_EGL_SwapWindow_impl(RPI)
SDL_EGL_MakeCurrent_impl(RPI)
#endif /* SDL_VIDEO_DRIVER_RPI && SDL_VIDEO_OPENGL_EGL */

View file

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@ -20,8 +20,8 @@
*/
#include "../../SDL_internal.h"
#ifndef _SDL_rpiopengles_h
#define _SDL_rpiopengles_h
#ifndef SDL_rpiopengles_h_
#define SDL_rpiopengles_h_
#if SDL_VIDEO_DRIVER_RPI && SDL_VIDEO_OPENGL_EGL
@ -38,11 +38,12 @@
extern int RPI_GLES_LoadLibrary(_THIS, const char *path);
extern SDL_GLContext RPI_GLES_CreateContext(_THIS, SDL_Window * window);
extern void RPI_GLES_SwapWindow(_THIS, SDL_Window * window);
extern int RPI_GLES_SwapWindow(_THIS, SDL_Window * window);
extern int RPI_GLES_MakeCurrent(_THIS, SDL_Window * window, SDL_GLContext context);
extern void RPI_GLES_DefaultProfileConfig(_THIS, int *mask, int *major, int *minor);
#endif /* SDL_VIDEO_DRIVER_RPI && SDL_VIDEO_OPENGL_EGL */
#endif /* _SDL_rpiopengles_h */
#endif /* SDL_rpiopengles_h_ */
/* vi: set ts=4 sw=4 expandtab: */

View file

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@ -59,11 +59,25 @@ RPI_Available(void)
static void
RPI_Destroy(SDL_VideoDevice * device)
{
/* SDL_VideoData *phdata = (SDL_VideoData *) device->driverdata; */
SDL_free(device->driverdata);
SDL_free(device);
}
if (device->driverdata != NULL) {
device->driverdata = NULL;
}
static int
RPI_GetRefreshRate()
{
TV_DISPLAY_STATE_T tvstate;
if (vc_tv_get_display_state( &tvstate ) == 0) {
//The width/height parameters are in the same position in the union
//for HDMI and SDTV
HDMI_PROPERTY_PARAM_T property;
property.property = HDMI_PROPERTY_PIXEL_CLOCK_TYPE;
vc_tv_hdmi_get_property(&property);
return property.param1 == HDMI_PIXEL_CLOCK_TYPE_NTSC ?
tvstate.display.hdmi.frame_rate * (1000.0f/1001.0f) :
tvstate.display.hdmi.frame_rate;
}
return 60; /* Failed to get display state, default to 60 */
}
static SDL_VideoDevice *
@ -100,8 +114,8 @@ RPI_Create()
device->VideoQuit = RPI_VideoQuit;
device->GetDisplayModes = RPI_GetDisplayModes;
device->SetDisplayMode = RPI_SetDisplayMode;
device->CreateWindow = RPI_CreateWindow;
device->CreateWindowFrom = RPI_CreateWindowFrom;
device->CreateSDLWindow = RPI_CreateWindow;
device->CreateSDLWindowFrom = RPI_CreateWindowFrom;
device->SetWindowTitle = RPI_SetWindowTitle;
device->SetWindowIcon = RPI_SetWindowIcon;
device->SetWindowPosition = RPI_SetWindowPosition;
@ -114,7 +128,9 @@ RPI_Create()
device->RestoreWindow = RPI_RestoreWindow;
device->SetWindowGrab = RPI_SetWindowGrab;
device->DestroyWindow = RPI_DestroyWindow;
#if 0
device->GetWindowWMInfo = RPI_GetWindowWMInfo;
#endif
device->GL_LoadLibrary = RPI_GLES_LoadLibrary;
device->GL_GetProcAddress = RPI_GLES_GetProcAddress;
device->GL_UnloadLibrary = RPI_GLES_UnloadLibrary;
@ -124,6 +140,7 @@ RPI_Create()
device->GL_GetSwapInterval = RPI_GLES_GetSwapInterval;
device->GL_SwapWindow = RPI_GLES_SwapWindow;
device->GL_DeleteContext = RPI_GLES_DeleteContext;
device->GL_DefaultProfileConfig = RPI_GLES_DefaultProfileConfig;
device->PumpEvents = RPI_PumpEvents;
@ -159,8 +176,7 @@ RPI_VideoInit(_THIS)
current_mode.w = w;
current_mode.h = h;
/* FIXME: Is there a way to tell the actual refresh rate? */
current_mode.refresh_rate = 60;
current_mode.refresh_rate = RPI_GetRefreshRate();
/* 32 bpp for default */
current_mode.format = SDL_PIXELFORMAT_ABGR8888;
@ -183,7 +199,9 @@ RPI_VideoInit(_THIS)
SDL_AddVideoDisplay(&display);
#ifdef SDL_INPUT_LINUXEV
SDL_EVDEV_Init();
if (SDL_EVDEV_Init() < 0) {
return -1;
}
#endif
RPI_InitMouse(_this);
@ -212,6 +230,16 @@ RPI_SetDisplayMode(_THIS, SDL_VideoDisplay * display, SDL_DisplayMode * mode)
return 0;
}
static void
RPI_vsync_callback(DISPMANX_UPDATE_HANDLE_T u, void *data)
{
SDL_WindowData *wdata = ((SDL_WindowData *) data);
SDL_LockMutex(wdata->vsync_cond_mutex);
SDL_CondSignal(wdata->vsync_cond);
SDL_UnlockMutex(wdata->vsync_cond_mutex);
}
int
RPI_CreateWindow(_THIS, SDL_Window * window)
{
@ -287,9 +315,18 @@ RPI_CreateWindow(_THIS, SDL_Window * window)
return SDL_SetError("Could not create GLES window surface");
}
/* Start generating vsync callbacks if necesary */
wdata->double_buffer = SDL_FALSE;
if (SDL_GetHintBoolean(SDL_HINT_VIDEO_DOUBLE_BUFFER, SDL_FALSE)) {
wdata->vsync_cond = SDL_CreateCond();
wdata->vsync_cond_mutex = SDL_CreateMutex();
wdata->double_buffer = SDL_TRUE;
vc_dispmanx_vsync_callback(displaydata->dispman_display, RPI_vsync_callback, (void*)wdata);
}
/* Setup driver data for this window */
window->driverdata = wdata;
/* One window, it always has focus */
SDL_SetMouseFocus(window);
SDL_SetKeyboardFocus(window);
@ -302,7 +339,22 @@ void
RPI_DestroyWindow(_THIS, SDL_Window * window)
{
SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window);
SDL_DisplayData *displaydata = (SDL_DisplayData *) display->driverdata;
if(data) {
if (data->double_buffer) {
/* Wait for vsync, and then stop vsync callbacks and destroy related stuff, if needed */
SDL_LockMutex(data->vsync_cond_mutex);
SDL_CondWait(data->vsync_cond, data->vsync_cond_mutex);
SDL_UnlockMutex(data->vsync_cond_mutex);
vc_dispmanx_vsync_callback(displaydata->dispman_display, NULL, NULL);
SDL_DestroyCond(data->vsync_cond);
SDL_DestroyMutex(data->vsync_cond_mutex);
}
#if SDL_VIDEO_OPENGL_EGL
if (data->egl_surface != EGL_NO_SURFACE) {
SDL_EGL_DestroySurface(_this, data->egl_surface);
@ -368,13 +420,14 @@ RPI_SetWindowGrab(_THIS, SDL_Window * window, SDL_bool grabbed)
/*****************************************************************************/
/* SDL Window Manager function */
/*****************************************************************************/
#if 0
SDL_bool
RPI_GetWindowWMInfo(_THIS, SDL_Window * window, struct SDL_SysWMinfo *info)
{
if (info->version.major <= SDL_MAJOR_VERSION) {
return SDL_TRUE;
} else {
SDL_SetError("application not compiled with SDL %d.%d\n",
SDL_SetError("application not compiled with SDL %d.%d",
SDL_MAJOR_VERSION, SDL_MINOR_VERSION);
return SDL_FALSE;
}
@ -382,6 +435,7 @@ RPI_GetWindowWMInfo(_THIS, SDL_Window * window, struct SDL_SysWMinfo *info)
/* Failed to get window manager information */
return SDL_FALSE;
}
#endif
#endif /* SDL_VIDEO_DRIVER_RPI */

View file

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@ -25,7 +25,7 @@
#include "../../SDL_internal.h"
#include "../SDL_sysvideo.h"
#include "bcm_host.h"
#include <bcm_host.h>
#include "GLES/gl.h"
#include "EGL/egl.h"
#include "EGL/eglext.h"
@ -48,6 +48,12 @@ typedef struct SDL_WindowData
#if SDL_VIDEO_OPENGL_EGL
EGLSurface egl_surface;
#endif
/* Vsync callback cond and mutex */
SDL_cond *vsync_cond;
SDL_mutex *vsync_cond_mutex;
SDL_bool double_buffer;
} SDL_WindowData;
#define SDL_RPI_VIDEOLAYER 10000 /* High enough so to occlude everything */
@ -90,7 +96,7 @@ SDL_GLContext RPI_GLES_CreateContext(_THIS, SDL_Window * window);
int RPI_GLES_MakeCurrent(_THIS, SDL_Window * window, SDL_GLContext context);
int RPI_GLES_SetSwapInterval(_THIS, int interval);
int RPI_GLES_GetSwapInterval(_THIS);
void RPI_GLES_SwapWindow(_THIS, SDL_Window * window);
int RPI_GLES_SwapWindow(_THIS, SDL_Window * window);
void RPI_GLES_DeleteContext(_THIS, SDL_GLContext context);
#endif /* __SDL_RPIVIDEO_H__ */