forked from Green-Sky/tomato
Merge commit 'dec0d4ec4153bf9fc2b78ae6c2df45b6ea8dde7a' as 'external/sdl/SDL'
This commit is contained in:
45
external/sdl/SDL/src/video/n3ds/SDL_n3dsevents.c
vendored
Normal file
45
external/sdl/SDL/src/video/n3ds/SDL_n3dsevents.c
vendored
Normal file
@ -0,0 +1,45 @@
|
||||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2023 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
|
||||
arising from the use of this software.
|
||||
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it
|
||||
freely, subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not
|
||||
claim that you wrote the original software. If you use this software
|
||||
in a product, an acknowledgment in the product documentation would be
|
||||
appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be
|
||||
misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
#include "SDL_internal.h"
|
||||
|
||||
#ifdef SDL_VIDEO_DRIVER_N3DS
|
||||
|
||||
#include <3ds.h>
|
||||
|
||||
#include "../../events/SDL_events_c.h"
|
||||
#include "SDL_n3dsevents_c.h"
|
||||
#include "SDL_n3dstouch.h"
|
||||
|
||||
void N3DS_PumpEvents(SDL_VideoDevice *_this)
|
||||
{
|
||||
hidScanInput();
|
||||
N3DS_PollTouch();
|
||||
|
||||
if (!aptMainLoop()) {
|
||||
SDL_Event ev;
|
||||
ev.type = SDL_EVENT_QUIT;
|
||||
ev.common.timestamp = 0;
|
||||
SDL_PushEvent(&ev);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* SDL_VIDEO_DRIVER_N3DS */
|
29
external/sdl/SDL/src/video/n3ds/SDL_n3dsevents_c.h
vendored
Normal file
29
external/sdl/SDL/src/video/n3ds/SDL_n3dsevents_c.h
vendored
Normal file
@ -0,0 +1,29 @@
|
||||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2023 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
|
||||
arising from the use of this software.
|
||||
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it
|
||||
freely, subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not
|
||||
claim that you wrote the original software. If you use this software
|
||||
in a product, an acknowledgment in the product documentation would be
|
||||
appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be
|
||||
misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
#ifndef SDL_n3dsevents_c_h_
|
||||
#define SDL_n3dsevents_c_h_
|
||||
|
||||
#include "SDL_internal.h"
|
||||
|
||||
extern void N3DS_PumpEvents(SDL_VideoDevice *_this);
|
||||
|
||||
#endif /* SDL_n3dsevents_c_h_ */
|
135
external/sdl/SDL/src/video/n3ds/SDL_n3dsframebuffer.c
vendored
Normal file
135
external/sdl/SDL/src/video/n3ds/SDL_n3dsframebuffer.c
vendored
Normal file
@ -0,0 +1,135 @@
|
||||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2023 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
|
||||
arising from the use of this software.
|
||||
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it
|
||||
freely, subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not
|
||||
claim that you wrote the original software. If you use this software
|
||||
in a product, an acknowledgment in the product documentation would be
|
||||
appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be
|
||||
misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
#include "SDL_internal.h"
|
||||
|
||||
#ifdef SDL_VIDEO_DRIVER_N3DS
|
||||
|
||||
#include "../SDL_sysvideo.h"
|
||||
#include "SDL_n3dsframebuffer_c.h"
|
||||
#include "SDL_n3dsvideo.h"
|
||||
|
||||
#define N3DS_SURFACE "_SDL_N3DSSurface"
|
||||
|
||||
typedef struct
|
||||
{
|
||||
int width, height;
|
||||
} Dimensions;
|
||||
|
||||
static void FreePreviousWindowFramebuffer(SDL_Window *window);
|
||||
static SDL_Surface *CreateNewWindowFramebuffer(SDL_Window *window);
|
||||
static void CopyFramebuffertoN3DS(u32 *dest, const Dimensions dest_dim, const u32 *source, const Dimensions source_dim);
|
||||
static int GetDestOffset(int x, int y, int dest_width);
|
||||
static int GetSourceOffset(int x, int y, int source_width);
|
||||
static void FlushN3DSBuffer(const void *buffer, u32 bufsize, gfxScreen_t screen);
|
||||
|
||||
int SDL_N3DS_CreateWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *window, Uint32 *format, void **pixels, int *pitch)
|
||||
{
|
||||
SDL_Surface *framebuffer;
|
||||
|
||||
FreePreviousWindowFramebuffer(window);
|
||||
framebuffer = CreateNewWindowFramebuffer(window);
|
||||
|
||||
if (framebuffer == NULL) {
|
||||
return SDL_OutOfMemory();
|
||||
}
|
||||
|
||||
SDL_SetWindowData(window, N3DS_SURFACE, framebuffer);
|
||||
*format = FRAMEBUFFER_FORMAT;
|
||||
*pixels = framebuffer->pixels;
|
||||
*pitch = framebuffer->pitch;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void FreePreviousWindowFramebuffer(SDL_Window *window)
|
||||
{
|
||||
SDL_Surface *surface = (SDL_Surface *)SDL_GetWindowData(window, N3DS_SURFACE);
|
||||
SDL_DestroySurface(surface);
|
||||
}
|
||||
|
||||
static SDL_Surface *CreateNewWindowFramebuffer(SDL_Window *window)
|
||||
{
|
||||
int w, h;
|
||||
SDL_GetWindowSizeInPixels(window, &w, &h);
|
||||
return SDL_CreateSurface(w, h, FRAMEBUFFER_FORMAT);
|
||||
}
|
||||
|
||||
int SDL_N3DS_UpdateWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *window, const SDL_Rect *rects, int numrects)
|
||||
{
|
||||
SDL_WindowData *drv_data = window->driverdata;
|
||||
SDL_Surface *surface;
|
||||
u16 width, height;
|
||||
u32 *framebuffer;
|
||||
u32 bufsize;
|
||||
|
||||
surface = (SDL_Surface *)SDL_GetWindowData(window, N3DS_SURFACE);
|
||||
if (surface == NULL) {
|
||||
return SDL_SetError("%s: Unable to get the window surface.", __func__);
|
||||
}
|
||||
|
||||
/* Get the N3DS internal framebuffer and its size */
|
||||
framebuffer = (u32 *)gfxGetFramebuffer(drv_data->screen, GFX_LEFT, &width, &height);
|
||||
bufsize = width * height * 4;
|
||||
|
||||
CopyFramebuffertoN3DS(framebuffer, (Dimensions){ width, height },
|
||||
surface->pixels, (Dimensions){ surface->w, surface->h });
|
||||
FlushN3DSBuffer(framebuffer, bufsize, drv_data->screen);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void CopyFramebuffertoN3DS(u32 *dest, const Dimensions dest_dim, const u32 *source, const Dimensions source_dim)
|
||||
{
|
||||
int rows = SDL_min(dest_dim.width, source_dim.height);
|
||||
int cols = SDL_min(dest_dim.height, source_dim.width);
|
||||
for (int y = 0; y < rows; ++y) {
|
||||
for (int x = 0; x < cols; ++x) {
|
||||
SDL_memcpy(
|
||||
dest + GetDestOffset(x, y, dest_dim.width),
|
||||
source + GetSourceOffset(x, y, source_dim.width),
|
||||
4);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static int GetDestOffset(int x, int y, int dest_width)
|
||||
{
|
||||
return dest_width - y - 1 + dest_width * x;
|
||||
}
|
||||
|
||||
static int GetSourceOffset(int x, int y, int source_width)
|
||||
{
|
||||
return x + y * source_width;
|
||||
}
|
||||
|
||||
static void FlushN3DSBuffer(const void *buffer, u32 bufsize, gfxScreen_t screen)
|
||||
{
|
||||
GSPGPU_FlushDataCache(buffer, bufsize);
|
||||
gfxScreenSwapBuffers(screen, false);
|
||||
}
|
||||
|
||||
void SDL_N3DS_DestroyWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *window)
|
||||
{
|
||||
SDL_Surface *surface;
|
||||
surface = (SDL_Surface *)SDL_SetWindowData(window, N3DS_SURFACE, NULL);
|
||||
SDL_DestroySurface(surface);
|
||||
}
|
||||
|
||||
#endif /* SDL_VIDEO_DRIVER_N3DS */
|
31
external/sdl/SDL/src/video/n3ds/SDL_n3dsframebuffer_c.h
vendored
Normal file
31
external/sdl/SDL/src/video/n3ds/SDL_n3dsframebuffer_c.h
vendored
Normal file
@ -0,0 +1,31 @@
|
||||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2023 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
|
||||
arising from the use of this software.
|
||||
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it
|
||||
freely, subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not
|
||||
claim that you wrote the original software. If you use this software
|
||||
in a product, an acknowledgment in the product documentation would be
|
||||
appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be
|
||||
misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
#ifndef SDL_n3dsframebuffer_c_h_
|
||||
#define SDL_n3dsframebuffer_c_h_
|
||||
|
||||
#include "SDL_internal.h"
|
||||
|
||||
int SDL_N3DS_CreateWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *window, Uint32 *format, void **pixels, int *pitch);
|
||||
int SDL_N3DS_UpdateWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *window, const SDL_Rect *rects, int numrects);
|
||||
void SDL_N3DS_DestroyWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *window);
|
||||
|
||||
#endif /* SDL_n3dsframebuffer_c_h_ */
|
68
external/sdl/SDL/src/video/n3ds/SDL_n3dsswkb.c
vendored
Normal file
68
external/sdl/SDL/src/video/n3ds/SDL_n3dsswkb.c
vendored
Normal file
@ -0,0 +1,68 @@
|
||||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2023 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
|
||||
arising from the use of this software.
|
||||
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it
|
||||
freely, subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not
|
||||
claim that you wrote the original software. If you use this software
|
||||
in a product, an acknowledgment in the product documentation would be
|
||||
appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be
|
||||
misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
#include "SDL_internal.h"
|
||||
|
||||
#ifdef SDL_VIDEO_DRIVER_N3DS
|
||||
|
||||
#include <3ds.h>
|
||||
|
||||
#include "SDL_n3dsswkb.h"
|
||||
|
||||
static SwkbdState sw_keyboard;
|
||||
const static size_t BUFFER_SIZE = 256;
|
||||
|
||||
void N3DS_SwkbInit()
|
||||
{
|
||||
swkbdInit(&sw_keyboard, SWKBD_TYPE_NORMAL, 2, -1);
|
||||
}
|
||||
|
||||
void N3DS_SwkbPoll()
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
void N3DS_SwkbQuit()
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
SDL_bool N3DS_HasScreenKeyboardSupport(SDL_VideoDevice *_this)
|
||||
{
|
||||
return SDL_TRUE;
|
||||
}
|
||||
|
||||
void N3DS_StartTextInput(SDL_VideoDevice *_this)
|
||||
{
|
||||
char buffer[BUFFER_SIZE];
|
||||
SwkbdButton button_pressed;
|
||||
button_pressed = swkbdInputText(&sw_keyboard, buffer, BUFFER_SIZE);
|
||||
if (button_pressed == SWKBD_BUTTON_CONFIRM) {
|
||||
SDL_SendKeyboardText(buffer);
|
||||
}
|
||||
}
|
||||
|
||||
void N3DS_StopTextInput(SDL_VideoDevice *_this)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
#endif /* SDL_VIDEO_DRIVER_N3DS */
|
36
external/sdl/SDL/src/video/n3ds/SDL_n3dsswkb.h
vendored
Normal file
36
external/sdl/SDL/src/video/n3ds/SDL_n3dsswkb.h
vendored
Normal file
@ -0,0 +1,36 @@
|
||||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2023 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
|
||||
arising from the use of this software.
|
||||
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it
|
||||
freely, subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not
|
||||
claim that you wrote the original software. If you use this software
|
||||
in a product, an acknowledgment in the product documentation would be
|
||||
appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be
|
||||
misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
#ifndef SDL_n3dskeyboard_h_
|
||||
#define SDL_n3dskeyboard_h_
|
||||
|
||||
#include "../../events/SDL_events_c.h"
|
||||
|
||||
void N3DS_SwkbInit();
|
||||
void N3DS_SwkbPoll();
|
||||
void N3DS_SwkbQuit();
|
||||
|
||||
SDL_bool N3DS_HasScreenKeyboardSupport(SDL_VideoDevice *_this);
|
||||
|
||||
void N3DS_StartTextInput(SDL_VideoDevice *_this);
|
||||
void N3DS_StopTextInput(SDL_VideoDevice *_this);
|
||||
|
||||
#endif /* SDL_n3dskeyboard_h_ */
|
79
external/sdl/SDL/src/video/n3ds/SDL_n3dstouch.c
vendored
Normal file
79
external/sdl/SDL/src/video/n3ds/SDL_n3dstouch.c
vendored
Normal file
@ -0,0 +1,79 @@
|
||||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2023 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
|
||||
arising from the use of this software.
|
||||
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it
|
||||
freely, subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not
|
||||
claim that you wrote the original software. If you use this software
|
||||
in a product, an acknowledgment in the product documentation would be
|
||||
appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be
|
||||
misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
#include "SDL_internal.h"
|
||||
|
||||
#ifdef SDL_VIDEO_DRIVER_N3DS
|
||||
|
||||
#include <3ds.h>
|
||||
|
||||
#include "../../events/SDL_touch_c.h"
|
||||
#include "SDL_n3dstouch.h"
|
||||
|
||||
#define N3DS_TOUCH_ID 0
|
||||
|
||||
/*
|
||||
Factors used to convert touchscreen coordinates to
|
||||
SDL's 0-1 values. Note that the N3DS's screen is
|
||||
internally in a portrait disposition so the
|
||||
GSP_SCREEN constants are flipped.
|
||||
*/
|
||||
#define TOUCHSCREEN_SCALE_X 1.0f / GSP_SCREEN_HEIGHT_BOTTOM
|
||||
#define TOUCHSCREEN_SCALE_Y 1.0f / GSP_SCREEN_WIDTH
|
||||
|
||||
void N3DS_InitTouch(void)
|
||||
{
|
||||
SDL_AddTouch(N3DS_TOUCH_ID, SDL_TOUCH_DEVICE_DIRECT, "Touchscreen");
|
||||
}
|
||||
|
||||
void N3DS_QuitTouch(void)
|
||||
{
|
||||
SDL_DelTouch(N3DS_TOUCH_ID);
|
||||
}
|
||||
|
||||
void N3DS_PollTouch(void)
|
||||
{
|
||||
touchPosition touch;
|
||||
static SDL_bool was_pressed = SDL_FALSE;
|
||||
SDL_bool pressed;
|
||||
hidTouchRead(&touch);
|
||||
pressed = (touch.px != 0 || touch.py != 0);
|
||||
|
||||
if (pressed != was_pressed) {
|
||||
was_pressed = pressed;
|
||||
SDL_SendTouch(0, N3DS_TOUCH_ID,
|
||||
0,
|
||||
NULL,
|
||||
pressed,
|
||||
touch.px * TOUCHSCREEN_SCALE_X,
|
||||
touch.py * TOUCHSCREEN_SCALE_Y,
|
||||
pressed ? 1.0f : 0.0f);
|
||||
} else if (pressed) {
|
||||
SDL_SendTouchMotion(0, N3DS_TOUCH_ID,
|
||||
0,
|
||||
NULL,
|
||||
touch.px * TOUCHSCREEN_SCALE_X,
|
||||
touch.py * TOUCHSCREEN_SCALE_Y,
|
||||
1.0f);
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* SDL_VIDEO_DRIVER_N3DS */
|
29
external/sdl/SDL/src/video/n3ds/SDL_n3dstouch.h
vendored
Normal file
29
external/sdl/SDL/src/video/n3ds/SDL_n3dstouch.h
vendored
Normal file
@ -0,0 +1,29 @@
|
||||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2023 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
|
||||
arising from the use of this software.
|
||||
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it
|
||||
freely, subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not
|
||||
claim that you wrote the original software. If you use this software
|
||||
in a product, an acknowledgment in the product documentation would be
|
||||
appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be
|
||||
misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
#ifndef SDL_n3dstouch_h_
|
||||
#define SDL_n3dstouch_h_
|
||||
|
||||
void N3DS_InitTouch(void);
|
||||
void N3DS_QuitTouch(void);
|
||||
void N3DS_PollTouch(void);
|
||||
|
||||
#endif /* SDL_n3dstouch_h_ */
|
176
external/sdl/SDL/src/video/n3ds/SDL_n3dsvideo.c
vendored
Normal file
176
external/sdl/SDL/src/video/n3ds/SDL_n3dsvideo.c
vendored
Normal file
@ -0,0 +1,176 @@
|
||||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2023 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
|
||||
arising from the use of this software.
|
||||
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it
|
||||
freely, subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not
|
||||
claim that you wrote the original software. If you use this software
|
||||
in a product, an acknowledgment in the product documentation would be
|
||||
appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be
|
||||
misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
#include "SDL_internal.h"
|
||||
|
||||
#ifdef SDL_VIDEO_DRIVER_N3DS
|
||||
|
||||
#include "../SDL_sysvideo.h"
|
||||
#include "SDL_n3dsevents_c.h"
|
||||
#include "SDL_n3dsframebuffer_c.h"
|
||||
#include "SDL_n3dsswkb.h"
|
||||
#include "SDL_n3dstouch.h"
|
||||
#include "SDL_n3dsvideo.h"
|
||||
|
||||
#define N3DSVID_DRIVER_NAME "n3ds"
|
||||
|
||||
static int AddN3DSDisplay(gfxScreen_t screen);
|
||||
|
||||
static int N3DS_VideoInit(SDL_VideoDevice *_this);
|
||||
static void N3DS_VideoQuit(SDL_VideoDevice *_this);
|
||||
static int N3DS_GetDisplayBounds(SDL_VideoDevice *_this, SDL_VideoDisplay *display, SDL_Rect *rect);
|
||||
static int N3DS_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window);
|
||||
static void N3DS_DestroyWindow(SDL_VideoDevice *_this, SDL_Window *window);
|
||||
|
||||
struct SDL_DisplayData
|
||||
{
|
||||
gfxScreen_t screen;
|
||||
};
|
||||
|
||||
/* N3DS driver bootstrap functions */
|
||||
|
||||
static void N3DS_DeleteDevice(SDL_VideoDevice *device)
|
||||
{
|
||||
SDL_free(device->displays);
|
||||
SDL_free(device->driverdata);
|
||||
SDL_free(device);
|
||||
}
|
||||
|
||||
static SDL_VideoDevice *N3DS_CreateDevice(void)
|
||||
{
|
||||
SDL_VideoDevice *device = (SDL_VideoDevice *)SDL_calloc(1, sizeof(SDL_VideoDevice));
|
||||
if (device == NULL) {
|
||||
SDL_OutOfMemory();
|
||||
return 0;
|
||||
}
|
||||
|
||||
device->VideoInit = N3DS_VideoInit;
|
||||
device->VideoQuit = N3DS_VideoQuit;
|
||||
|
||||
device->GetDisplayBounds = N3DS_GetDisplayBounds;
|
||||
|
||||
device->CreateSDLWindow = N3DS_CreateWindow;
|
||||
device->DestroyWindow = N3DS_DestroyWindow;
|
||||
|
||||
device->HasScreenKeyboardSupport = N3DS_HasScreenKeyboardSupport;
|
||||
device->StartTextInput = N3DS_StartTextInput;
|
||||
device->StopTextInput = N3DS_StopTextInput;
|
||||
|
||||
device->PumpEvents = N3DS_PumpEvents;
|
||||
|
||||
device->CreateWindowFramebuffer = SDL_N3DS_CreateWindowFramebuffer;
|
||||
device->UpdateWindowFramebuffer = SDL_N3DS_UpdateWindowFramebuffer;
|
||||
device->DestroyWindowFramebuffer = SDL_N3DS_DestroyWindowFramebuffer;
|
||||
|
||||
device->free = N3DS_DeleteDevice;
|
||||
|
||||
return device;
|
||||
}
|
||||
|
||||
VideoBootStrap N3DS_bootstrap = { N3DSVID_DRIVER_NAME, "N3DS Video Driver", N3DS_CreateDevice };
|
||||
|
||||
static int N3DS_VideoInit(SDL_VideoDevice *_this)
|
||||
{
|
||||
gfxInit(GSP_RGBA8_OES, GSP_RGBA8_OES, false);
|
||||
hidInit();
|
||||
|
||||
AddN3DSDisplay(GFX_TOP);
|
||||
AddN3DSDisplay(GFX_BOTTOM);
|
||||
|
||||
N3DS_InitTouch();
|
||||
N3DS_SwkbInit();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int AddN3DSDisplay(gfxScreen_t screen)
|
||||
{
|
||||
SDL_DisplayMode mode;
|
||||
SDL_VideoDisplay display;
|
||||
SDL_DisplayData *display_driver_data = SDL_calloc(1, sizeof(SDL_DisplayData));
|
||||
if (display_driver_data == NULL) {
|
||||
return SDL_OutOfMemory();
|
||||
}
|
||||
|
||||
SDL_zero(mode);
|
||||
SDL_zero(display);
|
||||
|
||||
display_driver_data->screen = screen;
|
||||
|
||||
mode.w = (screen == GFX_TOP) ? GSP_SCREEN_HEIGHT_TOP : GSP_SCREEN_HEIGHT_BOTTOM;
|
||||
mode.h = GSP_SCREEN_WIDTH;
|
||||
mode.refresh_rate = 60.0f;
|
||||
mode.format = FRAMEBUFFER_FORMAT;
|
||||
|
||||
display.name = (screen == GFX_TOP) ? "N3DS top screen" : "N3DS bottom screen";
|
||||
display.desktop_mode = mode;
|
||||
display.driverdata = display_driver_data;
|
||||
|
||||
SDL_AddVideoDisplay(&display, SDL_FALSE);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void N3DS_VideoQuit(SDL_VideoDevice *_this)
|
||||
{
|
||||
N3DS_SwkbQuit();
|
||||
N3DS_QuitTouch();
|
||||
|
||||
hidExit();
|
||||
gfxExit();
|
||||
}
|
||||
|
||||
static int N3DS_GetDisplayBounds(SDL_VideoDevice *_this, SDL_VideoDisplay *display, SDL_Rect *rect)
|
||||
{
|
||||
SDL_DisplayData *driver_data = display->driverdata;
|
||||
|
||||
if (driver_data == NULL) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
rect->x = 0;
|
||||
rect->y = (driver_data->screen == GFX_TOP) ? 0 : GSP_SCREEN_WIDTH;
|
||||
rect->w = display->current_mode->w;
|
||||
rect->h = display->current_mode->h;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int N3DS_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window)
|
||||
{
|
||||
SDL_DisplayData *display_data;
|
||||
SDL_WindowData *window_data = (SDL_WindowData *)SDL_calloc(1, sizeof(SDL_WindowData));
|
||||
if (window_data == NULL) {
|
||||
return SDL_OutOfMemory();
|
||||
}
|
||||
display_data = SDL_GetDisplayDriverDataForWindow(window);
|
||||
window_data->screen = display_data->screen;
|
||||
window->driverdata = window_data;
|
||||
SDL_SetKeyboardFocus(window);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void N3DS_DestroyWindow(SDL_VideoDevice *_this, SDL_Window *window)
|
||||
{
|
||||
if (window == NULL) {
|
||||
return;
|
||||
}
|
||||
SDL_free(window->driverdata);
|
||||
}
|
||||
|
||||
#endif /* SDL_VIDEO_DRIVER_N3DS */
|
37
external/sdl/SDL/src/video/n3ds/SDL_n3dsvideo.h
vendored
Normal file
37
external/sdl/SDL/src/video/n3ds/SDL_n3dsvideo.h
vendored
Normal file
@ -0,0 +1,37 @@
|
||||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2023 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
|
||||
arising from the use of this software.
|
||||
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it
|
||||
freely, subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not
|
||||
claim that you wrote the original software. If you use this software
|
||||
in a product, an acknowledgment in the product documentation would be
|
||||
appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be
|
||||
misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
#include "SDL_internal.h"
|
||||
|
||||
#ifndef SDL_n3dsvideo_h_
|
||||
#define SDL_n3dsvideo_h_
|
||||
|
||||
#include <3ds.h>
|
||||
|
||||
#include "../SDL_sysvideo.h"
|
||||
|
||||
struct SDL_WindowData
|
||||
{
|
||||
gfxScreen_t screen; /**< Keeps track of which N3DS screen is targeted */
|
||||
};
|
||||
|
||||
#define FRAMEBUFFER_FORMAT SDL_PIXELFORMAT_RGBA8888
|
||||
|
||||
#endif /* SDL_n3dsvideo_h_ */
|
Reference in New Issue
Block a user