mirror of
https://github.com/libsdl-org/SDL.git
synced 2026-04-30 13:27:26 +02:00
Update for SDL3 coding style (#6717)
I updated .clang-format and ran clang-format 14 over the src and test directories to standardize the code base.
In general I let clang-format have it's way, and added markup to prevent formatting of code that would break or be completely unreadable if formatted.
The script I ran for the src directory is added as build-scripts/clang-format-src.sh
This fixes:
#6592
#6593
#6594
(cherry picked from commit 5750bcb174)
This commit is contained in:
@@ -38,8 +38,6 @@ void RPI_PumpEvents(_THIS)
|
||||
#ifdef SDL_INPUT_LINUXEV
|
||||
SDL_EVDEV_Poll();
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
#endif /* SDL_VIDEO_DRIVER_RPI */
|
||||
|
||||
|
||||
@@ -34,49 +34,47 @@
|
||||
|
||||
/* Copied from vc_vchi_dispmanx.h which is bugged and tries to include a non existing file */
|
||||
/* Attributes changes flag mask */
|
||||
#define ELEMENT_CHANGE_LAYER (1<<0)
|
||||
#define ELEMENT_CHANGE_OPACITY (1<<1)
|
||||
#define ELEMENT_CHANGE_DEST_RECT (1<<2)
|
||||
#define ELEMENT_CHANGE_SRC_RECT (1<<3)
|
||||
#define ELEMENT_CHANGE_MASK_RESOURCE (1<<4)
|
||||
#define ELEMENT_CHANGE_TRANSFORM (1<<5)
|
||||
#define ELEMENT_CHANGE_LAYER (1 << 0)
|
||||
#define ELEMENT_CHANGE_OPACITY (1 << 1)
|
||||
#define ELEMENT_CHANGE_DEST_RECT (1 << 2)
|
||||
#define ELEMENT_CHANGE_SRC_RECT (1 << 3)
|
||||
#define ELEMENT_CHANGE_MASK_RESOURCE (1 << 4)
|
||||
#define ELEMENT_CHANGE_TRANSFORM (1 << 5)
|
||||
/* End copied from vc_vchi_dispmanx.h */
|
||||
|
||||
static SDL_Cursor *RPI_CreateDefaultCursor(void);
|
||||
static SDL_Cursor *RPI_CreateCursor(SDL_Surface * surface, int hot_x, int hot_y);
|
||||
static int RPI_ShowCursor(SDL_Cursor * cursor);
|
||||
static void RPI_MoveCursor(SDL_Cursor * cursor);
|
||||
static void RPI_FreeCursor(SDL_Cursor * cursor);
|
||||
static void RPI_WarpMouse(SDL_Window * window, int x, int y);
|
||||
static SDL_Cursor *RPI_CreateCursor(SDL_Surface *surface, int hot_x, int hot_y);
|
||||
static int RPI_ShowCursor(SDL_Cursor *cursor);
|
||||
static void RPI_MoveCursor(SDL_Cursor *cursor);
|
||||
static void RPI_FreeCursor(SDL_Cursor *cursor);
|
||||
static void RPI_WarpMouse(SDL_Window *window, int x, int y);
|
||||
static int RPI_WarpMouseGlobal(int x, int y);
|
||||
|
||||
static SDL_Cursor *global_cursor;
|
||||
|
||||
static SDL_Cursor *
|
||||
RPI_CreateDefaultCursor(void)
|
||||
static SDL_Cursor *RPI_CreateDefaultCursor(void)
|
||||
{
|
||||
return SDL_CreateCursor(default_cdata, default_cmask, DEFAULT_CWIDTH, DEFAULT_CHEIGHT, DEFAULT_CHOTX, DEFAULT_CHOTY);
|
||||
}
|
||||
|
||||
/* Create a cursor from a surface */
|
||||
static SDL_Cursor *
|
||||
RPI_CreateCursor(SDL_Surface * surface, int hot_x, int hot_y)
|
||||
static SDL_Cursor *RPI_CreateCursor(SDL_Surface *surface, int hot_x, int hot_y)
|
||||
{
|
||||
RPI_CursorData *curdata;
|
||||
SDL_Cursor *cursor;
|
||||
int ret;
|
||||
VC_RECT_T dst_rect;
|
||||
Uint32 dummy;
|
||||
|
||||
|
||||
SDL_assert(surface->format->format == SDL_PIXELFORMAT_ARGB8888);
|
||||
SDL_assert(surface->pitch == surface->w * 4);
|
||||
|
||||
cursor = (SDL_Cursor *) SDL_calloc(1, sizeof(*cursor));
|
||||
|
||||
cursor = (SDL_Cursor *)SDL_calloc(1, sizeof(*cursor));
|
||||
if (cursor == NULL) {
|
||||
SDL_OutOfMemory();
|
||||
return NULL;
|
||||
}
|
||||
curdata = (RPI_CursorData *) SDL_calloc(1, sizeof(*curdata));
|
||||
curdata = (RPI_CursorData *)SDL_calloc(1, sizeof(*curdata));
|
||||
if (curdata == NULL) {
|
||||
SDL_OutOfMemory();
|
||||
SDL_free(cursor);
|
||||
@@ -87,29 +85,27 @@ RPI_CreateCursor(SDL_Surface * surface, int hot_x, int hot_y)
|
||||
curdata->hot_y = hot_y;
|
||||
curdata->w = surface->w;
|
||||
curdata->h = surface->h;
|
||||
|
||||
|
||||
/* This usage is inspired by Wayland/Weston RPI code, how they figured this out is anyone's guess */
|
||||
curdata->resource = vc_dispmanx_resource_create(VC_IMAGE_ARGB8888, surface->w | (surface->pitch << 16), surface->h | (surface->h << 16), &dummy);
|
||||
SDL_assert(curdata->resource);
|
||||
vc_dispmanx_rect_set(&dst_rect, 0, 0, curdata->w, curdata->h);
|
||||
/* A note from Weston:
|
||||
/* A note from Weston:
|
||||
* vc_dispmanx_resource_write_data() ignores ifmt,
|
||||
* rect.x, rect.width, and uses stride only for computing
|
||||
* the size of the transfer as rect.height * stride.
|
||||
* Therefore we can only write rows starting at x=0.
|
||||
*/
|
||||
ret = vc_dispmanx_resource_write_data(curdata->resource, VC_IMAGE_ARGB8888, surface->pitch, surface->pixels, &dst_rect);
|
||||
SDL_assert (ret == DISPMANX_SUCCESS);
|
||||
|
||||
cursor->driverdata = curdata;
|
||||
|
||||
return cursor;
|
||||
SDL_assert(ret == DISPMANX_SUCCESS);
|
||||
|
||||
cursor->driverdata = curdata;
|
||||
|
||||
return cursor;
|
||||
}
|
||||
|
||||
/* Show the specified cursor, or hide if cursor is NULL */
|
||||
static int
|
||||
RPI_ShowCursor(SDL_Cursor * cursor)
|
||||
static int RPI_ShowCursor(SDL_Cursor *cursor)
|
||||
{
|
||||
int ret;
|
||||
DISPMANX_UPDATE_HANDLE_T update;
|
||||
@@ -118,7 +114,7 @@ RPI_ShowCursor(SDL_Cursor * cursor)
|
||||
SDL_Mouse *mouse;
|
||||
SDL_VideoDisplay *display;
|
||||
SDL_DisplayData *data;
|
||||
VC_DISPMANX_ALPHA_T alpha = { DISPMANX_FLAGS_ALPHA_FROM_SOURCE /* flags */ , 255 /*opacity 0->255*/, 0 /* mask */ };
|
||||
VC_DISPMANX_ALPHA_T alpha = { DISPMANX_FLAGS_ALPHA_FROM_SOURCE /* flags */, 255 /*opacity 0->255*/, 0 /* mask */ };
|
||||
uint32_t layer = SDL_RPI_MOUSELAYER;
|
||||
const char *env;
|
||||
|
||||
@@ -126,10 +122,10 @@ RPI_ShowCursor(SDL_Cursor * cursor)
|
||||
if (mouse == NULL) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
if (cursor != global_cursor) {
|
||||
if (global_cursor != NULL) {
|
||||
curdata = (RPI_CursorData *) global_cursor->driverdata;
|
||||
curdata = (RPI_CursorData *)global_cursor->driverdata;
|
||||
if (curdata && curdata->element > DISPMANX_NO_HANDLE) {
|
||||
update = vc_dispmanx_update_start(0);
|
||||
SDL_assert(update);
|
||||
@@ -146,12 +142,12 @@ RPI_ShowCursor(SDL_Cursor * cursor)
|
||||
if (cursor == NULL) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
curdata = (RPI_CursorData *) cursor->driverdata;
|
||||
|
||||
curdata = (RPI_CursorData *)cursor->driverdata;
|
||||
if (curdata == NULL) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
if (mouse->focus == NULL) {
|
||||
return -1;
|
||||
}
|
||||
@@ -160,16 +156,16 @@ RPI_ShowCursor(SDL_Cursor * cursor)
|
||||
if (display == NULL) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
data = (SDL_DisplayData*) display->driverdata;
|
||||
|
||||
data = (SDL_DisplayData *)display->driverdata;
|
||||
if (data == NULL) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
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, mouse->x - curdata->hot_x, mouse->y - curdata->hot_y, curdata->w, curdata->h);
|
||||
|
||||
|
||||
update = vc_dispmanx_update_start(0);
|
||||
SDL_assert(update);
|
||||
|
||||
@@ -179,34 +175,33 @@ RPI_ShowCursor(SDL_Cursor * cursor)
|
||||
}
|
||||
|
||||
curdata->element = vc_dispmanx_element_add(update,
|
||||
data->dispman_display,
|
||||
layer,
|
||||
&dst_rect,
|
||||
curdata->resource,
|
||||
&src_rect,
|
||||
DISPMANX_PROTECTION_NONE,
|
||||
&alpha,
|
||||
DISPMANX_NO_HANDLE, // clamp
|
||||
DISPMANX_NO_ROTATE);
|
||||
data->dispman_display,
|
||||
layer,
|
||||
&dst_rect,
|
||||
curdata->resource,
|
||||
&src_rect,
|
||||
DISPMANX_PROTECTION_NONE,
|
||||
&alpha,
|
||||
DISPMANX_NO_HANDLE, // clamp
|
||||
DISPMANX_NO_ROTATE);
|
||||
SDL_assert(curdata->element > DISPMANX_NO_HANDLE);
|
||||
ret = vc_dispmanx_update_submit_sync(update);
|
||||
SDL_assert(ret == DISPMANX_SUCCESS);
|
||||
}
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Free a window manager cursor */
|
||||
static void
|
||||
RPI_FreeCursor(SDL_Cursor * cursor)
|
||||
static void RPI_FreeCursor(SDL_Cursor *cursor)
|
||||
{
|
||||
int ret;
|
||||
DISPMANX_UPDATE_HANDLE_T update;
|
||||
RPI_CursorData *curdata;
|
||||
|
||||
|
||||
if (cursor != NULL) {
|
||||
curdata = (RPI_CursorData *) cursor->driverdata;
|
||||
|
||||
curdata = (RPI_CursorData *)cursor->driverdata;
|
||||
|
||||
if (curdata != NULL) {
|
||||
if (curdata->element != DISPMANX_NO_HANDLE) {
|
||||
update = vc_dispmanx_update_start(0);
|
||||
@@ -216,12 +211,12 @@ RPI_FreeCursor(SDL_Cursor * cursor)
|
||||
ret = vc_dispmanx_update_submit_sync(update);
|
||||
SDL_assert(ret == DISPMANX_SUCCESS);
|
||||
}
|
||||
|
||||
|
||||
if (curdata->resource != DISPMANX_NO_HANDLE) {
|
||||
ret = vc_dispmanx_resource_delete(curdata->resource);
|
||||
SDL_assert(ret == DISPMANX_SUCCESS);
|
||||
}
|
||||
|
||||
|
||||
SDL_free(cursor->driverdata);
|
||||
}
|
||||
SDL_free(cursor);
|
||||
@@ -232,15 +227,13 @@ RPI_FreeCursor(SDL_Cursor * cursor)
|
||||
}
|
||||
|
||||
/* Warp the mouse to (x,y) */
|
||||
static void
|
||||
RPI_WarpMouse(SDL_Window * window, int x, int y)
|
||||
static void RPI_WarpMouse(SDL_Window *window, int x, int y)
|
||||
{
|
||||
RPI_WarpMouseGlobal(x, y);
|
||||
}
|
||||
|
||||
/* Warp the mouse to (x,y) */
|
||||
static int
|
||||
RPI_WarpMouseGlobal(int x, int y)
|
||||
static int RPI_WarpMouseGlobal(int x, int y)
|
||||
{
|
||||
RPI_CursorData *curdata;
|
||||
DISPMANX_UPDATE_HANDLE_T update;
|
||||
@@ -248,7 +241,7 @@ RPI_WarpMouseGlobal(int x, int y)
|
||||
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;
|
||||
}
|
||||
@@ -256,7 +249,7 @@ RPI_WarpMouseGlobal(int x, int y)
|
||||
/* Update internal mouse position. */
|
||||
SDL_SendMouseMotion(mouse->focus, mouse->mouseID, 0, x, y);
|
||||
|
||||
curdata = (RPI_CursorData *) mouse->cur_cursor->driverdata;
|
||||
curdata = (RPI_CursorData *)mouse->cur_cursor->driverdata;
|
||||
if (curdata->element == DISPMANX_NO_HANDLE) {
|
||||
return 0;
|
||||
}
|
||||
@@ -268,11 +261,11 @@ RPI_WarpMouseGlobal(int x, int y)
|
||||
|
||||
src_rect.x = 0;
|
||||
src_rect.y = 0;
|
||||
src_rect.width = curdata->w << 16;
|
||||
src_rect.width = curdata->w << 16;
|
||||
src_rect.height = curdata->h << 16;
|
||||
dst_rect.x = x - curdata->hot_x;
|
||||
dst_rect.y = y - curdata->hot_y;
|
||||
dst_rect.width = curdata->w;
|
||||
dst_rect.width = curdata->w;
|
||||
dst_rect.height = curdata->h;
|
||||
|
||||
ret = vc_dispmanx_element_change_attributes(
|
||||
@@ -298,8 +291,7 @@ RPI_WarpMouseGlobal(int x, int y)
|
||||
}
|
||||
|
||||
/* Warp the mouse to (x,y) */
|
||||
static int
|
||||
RPI_WarpMouseGlobalGraphicOnly(int x, int y)
|
||||
static int RPI_WarpMouseGlobalGraphicOnly(int x, int y)
|
||||
{
|
||||
RPI_CursorData *curdata;
|
||||
DISPMANX_UPDATE_HANDLE_T update;
|
||||
@@ -307,12 +299,12 @@ RPI_WarpMouseGlobalGraphicOnly(int x, int y)
|
||||
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;
|
||||
curdata = (RPI_CursorData *)mouse->cur_cursor->driverdata;
|
||||
if (curdata->element == DISPMANX_NO_HANDLE) {
|
||||
return 0;
|
||||
}
|
||||
@@ -324,11 +316,11 @@ RPI_WarpMouseGlobalGraphicOnly(int x, int y)
|
||||
|
||||
src_rect.x = 0;
|
||||
src_rect.y = 0;
|
||||
src_rect.width = curdata->w << 16;
|
||||
src_rect.width = curdata->w << 16;
|
||||
src_rect.height = curdata->h << 16;
|
||||
dst_rect.x = x - curdata->hot_x;
|
||||
dst_rect.y = y - curdata->hot_y;
|
||||
dst_rect.width = curdata->w;
|
||||
dst_rect.width = curdata->w;
|
||||
dst_rect.height = curdata->h;
|
||||
|
||||
ret = vc_dispmanx_element_change_attributes(
|
||||
@@ -353,10 +345,9 @@ RPI_WarpMouseGlobalGraphicOnly(int x, int y)
|
||||
return 0;
|
||||
}
|
||||
|
||||
void
|
||||
RPI_InitMouse(_THIS)
|
||||
void RPI_InitMouse(_THIS)
|
||||
{
|
||||
/* FIXME: Using UDEV it should be possible to scan all mice
|
||||
/* FIXME: Using UDEV it should be possible to scan all mice
|
||||
* but there's no point in doing so as there's no multimice support...yet!
|
||||
*/
|
||||
SDL_Mouse *mouse = SDL_GetMouse();
|
||||
@@ -371,17 +362,15 @@ RPI_InitMouse(_THIS)
|
||||
SDL_SetDefaultCursor(RPI_CreateDefaultCursor());
|
||||
}
|
||||
|
||||
void
|
||||
RPI_QuitMouse(_THIS)
|
||||
void RPI_QuitMouse(_THIS)
|
||||
{
|
||||
}
|
||||
|
||||
/* This is called when a mouse motion event occurs */
|
||||
static void
|
||||
RPI_MoveCursor(SDL_Cursor * cursor)
|
||||
static void RPI_MoveCursor(SDL_Cursor *cursor)
|
||||
{
|
||||
SDL_Mouse *mouse = SDL_GetMouse();
|
||||
/* We must NOT call SDL_SendMouseMotion() on the next call or we will enter recursivity,
|
||||
/* 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);
|
||||
}
|
||||
|
||||
@@ -27,13 +27,13 @@
|
||||
typedef struct _RPI_CursorData RPI_CursorData;
|
||||
struct _RPI_CursorData
|
||||
{
|
||||
DISPMANX_RESOURCE_HANDLE_T resource;
|
||||
DISPMANX_ELEMENT_HANDLE_T element;
|
||||
int hot_x, hot_y;
|
||||
int w, h;
|
||||
DISPMANX_RESOURCE_HANDLE_T resource;
|
||||
DISPMANX_ELEMENT_HANDLE_T element;
|
||||
int hot_x, hot_y;
|
||||
int w, h;
|
||||
};
|
||||
|
||||
#define SDL_RPI_CURSORDATA(curs) RPI_CursorData *curdata = (RPI_CursorData *) ((curs) ? (curs)->driverdata : NULL)
|
||||
#define SDL_RPI_CURSORDATA(curs) RPI_CursorData *curdata = (RPI_CursorData *)((curs) ? (curs)->driverdata : NULL)
|
||||
|
||||
extern void RPI_InitMouse(_THIS);
|
||||
extern void RPI_QuitMouse(_THIS);
|
||||
|
||||
@@ -29,22 +29,21 @@
|
||||
|
||||
/* EGL implementation of SDL OpenGL support */
|
||||
|
||||
void
|
||||
RPI_GLES_DefaultProfileConfig(_THIS, int *mask, int *major, int *minor)
|
||||
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) {
|
||||
int RPI_GLES_LoadLibrary(_THIS, const char *path)
|
||||
{
|
||||
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);
|
||||
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.");
|
||||
@@ -63,9 +62,8 @@ RPI_GLES_SwapWindow(_THIS, SDL_Window * window) {
|
||||
}
|
||||
|
||||
SDL_EGL_CreateContext_impl(RPI)
|
||||
SDL_EGL_MakeCurrent_impl(RPI)
|
||||
SDL_EGL_MakeCurrent_impl(RPI)
|
||||
|
||||
#endif /* SDL_VIDEO_DRIVER_RPI && SDL_VIDEO_OPENGL_EGL */
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
|
||||
@@ -34,12 +34,12 @@
|
||||
#define RPI_GLES_UnloadLibrary SDL_EGL_UnloadLibrary
|
||||
#define RPI_GLES_SetSwapInterval SDL_EGL_SetSwapInterval
|
||||
#define RPI_GLES_GetSwapInterval SDL_EGL_GetSwapInterval
|
||||
#define RPI_GLES_DeleteContext SDL_EGL_DeleteContext
|
||||
#define RPI_GLES_DeleteContext SDL_EGL_DeleteContext
|
||||
|
||||
extern int RPI_GLES_LoadLibrary(_THIS, const char *path);
|
||||
extern SDL_GLContext RPI_GLES_CreateContext(_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 SDL_GLContext RPI_GLES_CreateContext(_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 */
|
||||
|
||||
@@ -50,45 +50,40 @@
|
||||
#include "SDL_rpiopengles.h"
|
||||
#include "SDL_rpimouse.h"
|
||||
|
||||
static void
|
||||
RPI_Destroy(SDL_VideoDevice * device)
|
||||
static void RPI_Destroy(SDL_VideoDevice *device)
|
||||
{
|
||||
SDL_free(device->driverdata);
|
||||
SDL_free(device);
|
||||
}
|
||||
|
||||
static int
|
||||
RPI_GetRefreshRate()
|
||||
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
|
||||
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 */
|
||||
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 *
|
||||
RPI_Create()
|
||||
static SDL_VideoDevice *RPI_Create()
|
||||
{
|
||||
SDL_VideoDevice *device;
|
||||
SDL_VideoData *phdata;
|
||||
|
||||
/* Initialize SDL_VideoDevice structure */
|
||||
device = (SDL_VideoDevice *) SDL_calloc(1, sizeof(SDL_VideoDevice));
|
||||
device = (SDL_VideoDevice *)SDL_calloc(1, sizeof(SDL_VideoDevice));
|
||||
if (device == NULL) {
|
||||
SDL_OutOfMemory();
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Initialize internal data */
|
||||
phdata = (SDL_VideoData *) SDL_calloc(1, sizeof(SDL_VideoData));
|
||||
phdata = (SDL_VideoData *)SDL_calloc(1, sizeof(SDL_VideoData));
|
||||
if (phdata == NULL) {
|
||||
SDL_OutOfMemory();
|
||||
SDL_free(device);
|
||||
@@ -146,13 +141,11 @@ VideoBootStrap RPI_bootstrap = {
|
||||
RPI_Create
|
||||
};
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
/* SDL Video and Display initialization/handling functions */
|
||||
/*****************************************************************************/
|
||||
|
||||
static void
|
||||
AddDispManXDisplay(const int display_id)
|
||||
static void AddDispManXDisplay(const int display_id)
|
||||
{
|
||||
DISPMANX_MODEINFO_T modeinfo;
|
||||
DISPMANX_DISPLAY_HANDLE_T handle;
|
||||
@@ -162,7 +155,7 @@ AddDispManXDisplay(const int display_id)
|
||||
|
||||
handle = vc_dispmanx_display_open(display_id);
|
||||
if (!handle) {
|
||||
return; /* this display isn't available */
|
||||
return; /* this display isn't available */
|
||||
}
|
||||
|
||||
if (vc_dispmanx_display_get_info(handle, &modeinfo) < 0) {
|
||||
@@ -185,10 +178,10 @@ AddDispManXDisplay(const int display_id)
|
||||
display.current_mode = current_mode;
|
||||
|
||||
/* Allocate display internal data */
|
||||
data = (SDL_DisplayData *) SDL_calloc(1, sizeof(SDL_DisplayData));
|
||||
data = (SDL_DisplayData *)SDL_calloc(1, sizeof(SDL_DisplayData));
|
||||
if (data == NULL) {
|
||||
vc_dispmanx_display_close(handle);
|
||||
return; /* oh well */
|
||||
return; /* oh well */
|
||||
}
|
||||
|
||||
data->dispman_display = handle;
|
||||
@@ -198,82 +191,76 @@ AddDispManXDisplay(const int display_id)
|
||||
SDL_AddVideoDisplay(&display, SDL_FALSE);
|
||||
}
|
||||
|
||||
int
|
||||
RPI_VideoInit(_THIS)
|
||||
int RPI_VideoInit(_THIS)
|
||||
{
|
||||
/* Initialize BCM Host */
|
||||
bcm_host_init();
|
||||
|
||||
AddDispManXDisplay(DISPMANX_ID_MAIN_LCD); /* your default display */
|
||||
AddDispManXDisplay(DISPMANX_ID_FORCE_OTHER); /* an "other" display...maybe DSI-connected screen while HDMI is your main */
|
||||
AddDispManXDisplay(DISPMANX_ID_MAIN_LCD); /* your default display */
|
||||
AddDispManXDisplay(DISPMANX_ID_FORCE_OTHER); /* an "other" display...maybe DSI-connected screen while HDMI is your main */
|
||||
|
||||
#ifdef SDL_INPUT_LINUXEV
|
||||
#ifdef SDL_INPUT_LINUXEV
|
||||
if (SDL_EVDEV_Init() < 0) {
|
||||
return -1;
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
RPI_InitMouse(_this);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
void
|
||||
RPI_VideoQuit(_THIS)
|
||||
void RPI_VideoQuit(_THIS)
|
||||
{
|
||||
#ifdef SDL_INPUT_LINUXEV
|
||||
#ifdef SDL_INPUT_LINUXEV
|
||||
SDL_EVDEV_Quit();
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
void
|
||||
RPI_GetDisplayModes(_THIS, SDL_VideoDisplay * display)
|
||||
void RPI_GetDisplayModes(_THIS, SDL_VideoDisplay *display)
|
||||
{
|
||||
/* Only one display mode available, the current one */
|
||||
SDL_AddDisplayMode(display, &display->current_mode);
|
||||
}
|
||||
|
||||
int
|
||||
RPI_SetDisplayMode(_THIS, SDL_VideoDisplay * display, SDL_DisplayMode * mode)
|
||||
int RPI_SetDisplayMode(_THIS, SDL_VideoDisplay *display, SDL_DisplayMode *mode)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void
|
||||
RPI_vsync_callback(DISPMANX_UPDATE_HANDLE_T u, void *data)
|
||||
static void RPI_vsync_callback(DISPMANX_UPDATE_HANDLE_T u, void *data)
|
||||
{
|
||||
SDL_WindowData *wdata = ((SDL_WindowData *) data);
|
||||
SDL_WindowData *wdata = ((SDL_WindowData *)data);
|
||||
|
||||
SDL_LockMutex(wdata->vsync_cond_mutex);
|
||||
SDL_CondSignal(wdata->vsync_cond);
|
||||
SDL_UnlockMutex(wdata->vsync_cond_mutex);
|
||||
SDL_LockMutex(wdata->vsync_cond_mutex);
|
||||
SDL_CondSignal(wdata->vsync_cond);
|
||||
SDL_UnlockMutex(wdata->vsync_cond_mutex);
|
||||
}
|
||||
|
||||
int
|
||||
RPI_CreateWindow(_THIS, SDL_Window * window)
|
||||
int RPI_CreateWindow(_THIS, SDL_Window *window)
|
||||
{
|
||||
SDL_WindowData *wdata;
|
||||
SDL_VideoDisplay *display;
|
||||
SDL_DisplayData *displaydata;
|
||||
VC_RECT_T dst_rect;
|
||||
VC_RECT_T src_rect;
|
||||
VC_DISPMANX_ALPHA_T dispman_alpha;
|
||||
VC_DISPMANX_ALPHA_T dispman_alpha;
|
||||
DISPMANX_UPDATE_HANDLE_T dispman_update;
|
||||
uint32_t layer = SDL_RPI_VIDEOLAYER;
|
||||
const char *env;
|
||||
|
||||
/* Disable alpha, otherwise the app looks composed with whatever dispman is showing (X11, console,etc) */
|
||||
dispman_alpha.flags = DISPMANX_FLAGS_ALPHA_FIXED_ALL_PIXELS;
|
||||
dispman_alpha.opacity = 0xFF;
|
||||
dispman_alpha.flags = DISPMANX_FLAGS_ALPHA_FIXED_ALL_PIXELS;
|
||||
dispman_alpha.opacity = 0xFF;
|
||||
dispman_alpha.mask = 0;
|
||||
|
||||
/* Allocate window internal data */
|
||||
wdata = (SDL_WindowData *) SDL_calloc(1, sizeof(SDL_WindowData));
|
||||
wdata = (SDL_WindowData *)SDL_calloc(1, sizeof(SDL_WindowData));
|
||||
if (wdata == NULL) {
|
||||
return SDL_OutOfMemory();
|
||||
}
|
||||
display = SDL_GetDisplayForWindow(window);
|
||||
displaydata = (SDL_DisplayData *) display->driverdata;
|
||||
displaydata = (SDL_DisplayData *)display->driverdata;
|
||||
|
||||
/* Windows have one size for now */
|
||||
window->w = display->desktop_mode.w;
|
||||
@@ -298,27 +285,27 @@ RPI_CreateWindow(_THIS, SDL_Window * window)
|
||||
layer = SDL_atoi(env);
|
||||
}
|
||||
|
||||
dispman_update = vc_dispmanx_update_start( 0 );
|
||||
wdata->dispman_window.element = vc_dispmanx_element_add (dispman_update,
|
||||
displaydata->dispman_display,
|
||||
layer /* layer */,
|
||||
&dst_rect,
|
||||
0 /*src*/,
|
||||
&src_rect,
|
||||
DISPMANX_PROTECTION_NONE,
|
||||
&dispman_alpha /*alpha*/,
|
||||
0 /*clamp*/,
|
||||
0 /*transform*/);
|
||||
dispman_update = vc_dispmanx_update_start(0);
|
||||
wdata->dispman_window.element = vc_dispmanx_element_add(dispman_update,
|
||||
displaydata->dispman_display,
|
||||
layer /* layer */,
|
||||
&dst_rect,
|
||||
0 /*src*/,
|
||||
&src_rect,
|
||||
DISPMANX_PROTECTION_NONE,
|
||||
&dispman_alpha /*alpha*/,
|
||||
0 /*clamp*/,
|
||||
0 /*transform*/);
|
||||
wdata->dispman_window.width = window->w;
|
||||
wdata->dispman_window.height = window->h;
|
||||
vc_dispmanx_update_submit_sync(dispman_update);
|
||||
|
||||
|
||||
if (!_this->egl_data) {
|
||||
if (SDL_GL_LoadLibrary(NULL) < 0) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
wdata->egl_surface = SDL_EGL_CreateSurface(_this, (NativeWindowType) &wdata->dispman_window);
|
||||
wdata->egl_surface = SDL_EGL_CreateSurface(_this, (NativeWindowType)&wdata->dispman_window);
|
||||
|
||||
if (wdata->egl_surface == EGL_NO_SURFACE) {
|
||||
return SDL_SetError("Could not create GLES window surface");
|
||||
@@ -330,7 +317,7 @@ RPI_CreateWindow(_THIS, SDL_Window * window)
|
||||
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);
|
||||
vc_dispmanx_vsync_callback(displaydata->dispman_display, RPI_vsync_callback, (void *)wdata);
|
||||
}
|
||||
|
||||
/* Setup driver data for this window */
|
||||
@@ -344,12 +331,11 @@ RPI_CreateWindow(_THIS, SDL_Window * window)
|
||||
return 0;
|
||||
}
|
||||
|
||||
void
|
||||
RPI_DestroyWindow(_THIS, SDL_Window * window)
|
||||
void RPI_DestroyWindow(_THIS, SDL_Window *window)
|
||||
{
|
||||
SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
|
||||
SDL_WindowData *data = (SDL_WindowData *)window->driverdata;
|
||||
SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window);
|
||||
SDL_DisplayData *displaydata = (SDL_DisplayData *) display->driverdata;
|
||||
SDL_DisplayData *displaydata = (SDL_DisplayData *)display->driverdata;
|
||||
|
||||
if (data) {
|
||||
if (data->double_buffer) {
|
||||
@@ -374,50 +360,39 @@ RPI_DestroyWindow(_THIS, SDL_Window * window)
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
RPI_CreateWindowFrom(_THIS, SDL_Window * window, const void *data)
|
||||
int RPI_CreateWindowFrom(_THIS, SDL_Window *window, const void *data)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
void
|
||||
RPI_SetWindowTitle(_THIS, SDL_Window * window)
|
||||
void RPI_SetWindowTitle(_THIS, SDL_Window *window)
|
||||
{
|
||||
}
|
||||
void
|
||||
RPI_SetWindowIcon(_THIS, SDL_Window * window, SDL_Surface * icon)
|
||||
void RPI_SetWindowIcon(_THIS, SDL_Window *window, SDL_Surface *icon)
|
||||
{
|
||||
}
|
||||
void
|
||||
RPI_SetWindowPosition(_THIS, SDL_Window * window)
|
||||
void RPI_SetWindowPosition(_THIS, SDL_Window *window)
|
||||
{
|
||||
}
|
||||
void
|
||||
RPI_SetWindowSize(_THIS, SDL_Window * window)
|
||||
void RPI_SetWindowSize(_THIS, SDL_Window *window)
|
||||
{
|
||||
}
|
||||
void
|
||||
RPI_ShowWindow(_THIS, SDL_Window * window)
|
||||
void RPI_ShowWindow(_THIS, SDL_Window *window)
|
||||
{
|
||||
}
|
||||
void
|
||||
RPI_HideWindow(_THIS, SDL_Window * window)
|
||||
void RPI_HideWindow(_THIS, SDL_Window *window)
|
||||
{
|
||||
}
|
||||
void
|
||||
RPI_RaiseWindow(_THIS, SDL_Window * window)
|
||||
void RPI_RaiseWindow(_THIS, SDL_Window *window)
|
||||
{
|
||||
}
|
||||
void
|
||||
RPI_MaximizeWindow(_THIS, SDL_Window * window)
|
||||
void RPI_MaximizeWindow(_THIS, SDL_Window *window)
|
||||
{
|
||||
}
|
||||
void
|
||||
RPI_MinimizeWindow(_THIS, SDL_Window * window)
|
||||
void RPI_MinimizeWindow(_THIS, SDL_Window *window)
|
||||
{
|
||||
}
|
||||
void
|
||||
RPI_RestoreWindow(_THIS, SDL_Window * window)
|
||||
void RPI_RestoreWindow(_THIS, SDL_Window *window)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
@@ -32,25 +32,23 @@
|
||||
|
||||
typedef struct SDL_VideoData
|
||||
{
|
||||
uint32_t egl_refcount; /* OpenGL ES reference count */
|
||||
uint32_t egl_refcount; /* OpenGL ES reference count */
|
||||
} SDL_VideoData;
|
||||
|
||||
|
||||
typedef struct SDL_DisplayData
|
||||
{
|
||||
DISPMANX_DISPLAY_HANDLE_T dispman_display;
|
||||
} SDL_DisplayData;
|
||||
|
||||
|
||||
typedef struct SDL_WindowData
|
||||
{
|
||||
EGL_DISPMANX_WINDOW_T dispman_window;
|
||||
#if SDL_VIDEO_OPENGL_EGL
|
||||
#if SDL_VIDEO_OPENGL_EGL
|
||||
EGLSurface egl_surface;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/* Vsync callback cond and mutex */
|
||||
SDL_cond *vsync_cond;
|
||||
SDL_cond *vsync_cond;
|
||||
SDL_mutex *vsync_cond_mutex;
|
||||
SDL_bool double_buffer;
|
||||
|
||||
@@ -59,7 +57,6 @@ typedef struct SDL_WindowData
|
||||
#define SDL_RPI_VIDEOLAYER 10000 /* High enough so to occlude everything */
|
||||
#define SDL_RPI_MOUSELAYER SDL_RPI_VIDEOLAYER + 1
|
||||
|
||||
|
||||
/****************************************************************************/
|
||||
/* SDL_VideoDevice functions declaration */
|
||||
/****************************************************************************/
|
||||
@@ -67,21 +64,21 @@ typedef struct SDL_WindowData
|
||||
/* Display and window functions */
|
||||
int RPI_VideoInit(_THIS);
|
||||
void RPI_VideoQuit(_THIS);
|
||||
void RPI_GetDisplayModes(_THIS, SDL_VideoDisplay * display);
|
||||
int RPI_SetDisplayMode(_THIS, SDL_VideoDisplay * display, SDL_DisplayMode * mode);
|
||||
int RPI_CreateWindow(_THIS, SDL_Window * window);
|
||||
int RPI_CreateWindowFrom(_THIS, SDL_Window * window, const void *data);
|
||||
void RPI_SetWindowTitle(_THIS, SDL_Window * window);
|
||||
void RPI_SetWindowIcon(_THIS, SDL_Window * window, SDL_Surface * icon);
|
||||
void RPI_SetWindowPosition(_THIS, SDL_Window * window);
|
||||
void RPI_SetWindowSize(_THIS, SDL_Window * window);
|
||||
void RPI_ShowWindow(_THIS, SDL_Window * window);
|
||||
void RPI_HideWindow(_THIS, SDL_Window * window);
|
||||
void RPI_RaiseWindow(_THIS, SDL_Window * window);
|
||||
void RPI_MaximizeWindow(_THIS, SDL_Window * window);
|
||||
void RPI_MinimizeWindow(_THIS, SDL_Window * window);
|
||||
void RPI_RestoreWindow(_THIS, SDL_Window * window);
|
||||
void RPI_DestroyWindow(_THIS, SDL_Window * window);
|
||||
void RPI_GetDisplayModes(_THIS, SDL_VideoDisplay *display);
|
||||
int RPI_SetDisplayMode(_THIS, SDL_VideoDisplay *display, SDL_DisplayMode *mode);
|
||||
int RPI_CreateWindow(_THIS, SDL_Window *window);
|
||||
int RPI_CreateWindowFrom(_THIS, SDL_Window *window, const void *data);
|
||||
void RPI_SetWindowTitle(_THIS, SDL_Window *window);
|
||||
void RPI_SetWindowIcon(_THIS, SDL_Window *window, SDL_Surface *icon);
|
||||
void RPI_SetWindowPosition(_THIS, SDL_Window *window);
|
||||
void RPI_SetWindowSize(_THIS, SDL_Window *window);
|
||||
void RPI_ShowWindow(_THIS, SDL_Window *window);
|
||||
void RPI_HideWindow(_THIS, SDL_Window *window);
|
||||
void RPI_RaiseWindow(_THIS, SDL_Window *window);
|
||||
void RPI_MaximizeWindow(_THIS, SDL_Window *window);
|
||||
void RPI_MinimizeWindow(_THIS, SDL_Window *window);
|
||||
void RPI_RestoreWindow(_THIS, SDL_Window *window);
|
||||
void RPI_DestroyWindow(_THIS, SDL_Window *window);
|
||||
|
||||
/* Window manager function */
|
||||
SDL_bool RPI_GetWindowWMInfo(_THIS, SDL_Window * window,
|
||||
@@ -91,11 +88,11 @@ SDL_bool RPI_GetWindowWMInfo(_THIS, SDL_Window * window,
|
||||
int RPI_GLES_LoadLibrary(_THIS, const char *path);
|
||||
void *RPI_GLES_GetProcAddress(_THIS, const char *proc);
|
||||
void RPI_GLES_UnloadLibrary(_THIS);
|
||||
SDL_GLContext RPI_GLES_CreateContext(_THIS, SDL_Window * window);
|
||||
int RPI_GLES_MakeCurrent(_THIS, SDL_Window * window, SDL_GLContext context);
|
||||
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);
|
||||
int 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__ */
|
||||
|
||||
Reference in New Issue
Block a user