N3DS: Deduce screen from window's display.

This removes the need for a dedicated window creation flag.
This commit is contained in:
Pierre Wendling 2022-09-18 13:22:07 -04:00 committed by Sam Lantinga
parent 46a13ad97a
commit f9785702a6
3 changed files with 38 additions and 13 deletions

View File

@ -126,7 +126,6 @@ typedef enum
SDL_WINDOW_KEYBOARD_GRABBED = 0x00100000, /**< window has grabbed keyboard input */ SDL_WINDOW_KEYBOARD_GRABBED = 0x00100000, /**< window has grabbed keyboard input */
SDL_WINDOW_VULKAN = 0x10000000, /**< window usable for Vulkan surface */ SDL_WINDOW_VULKAN = 0x10000000, /**< window usable for Vulkan surface */
SDL_WINDOW_METAL = 0x20000000, /**< window usable for Metal view */ SDL_WINDOW_METAL = 0x20000000, /**< window usable for Metal view */
SDL_WINDOW_N3DS_BOTTOM = 0x40000000, /**< window should be on the bottom screen (N3DS only) */
SDL_WINDOW_INPUT_GRABBED = SDL_WINDOW_MOUSE_GRABBED /**< equivalent to SDL_WINDOW_MOUSE_GRABBED for compatibility */ SDL_WINDOW_INPUT_GRABBED = SDL_WINDOW_MOUSE_GRABBED /**< equivalent to SDL_WINDOW_MOUSE_GRABBED for compatibility */
} SDL_WindowFlags; } SDL_WindowFlags;

View File

@ -1501,7 +1501,7 @@ SDL_UpdateFullscreenMode(SDL_Window * window, SDL_bool fullscreen)
} }
#define CREATE_FLAGS \ #define CREATE_FLAGS \
(SDL_WINDOW_OPENGL | SDL_WINDOW_BORDERLESS | SDL_WINDOW_RESIZABLE | SDL_WINDOW_ALLOW_HIGHDPI | SDL_WINDOW_ALWAYS_ON_TOP | SDL_WINDOW_SKIP_TASKBAR | SDL_WINDOW_POPUP_MENU | SDL_WINDOW_UTILITY | SDL_WINDOW_TOOLTIP | SDL_WINDOW_VULKAN | SDL_WINDOW_MINIMIZED | SDL_WINDOW_METAL | SDL_WINDOW_N3DS_BOTTOM) (SDL_WINDOW_OPENGL | SDL_WINDOW_BORDERLESS | SDL_WINDOW_RESIZABLE | SDL_WINDOW_ALLOW_HIGHDPI | SDL_WINDOW_ALWAYS_ON_TOP | SDL_WINDOW_SKIP_TASKBAR | SDL_WINDOW_POPUP_MENU | SDL_WINDOW_UTILITY | SDL_WINDOW_TOOLTIP | SDL_WINDOW_VULKAN | SDL_WINDOW_MINIMIZED | SDL_WINDOW_METAL)
static SDL_INLINE SDL_bool static SDL_INLINE SDL_bool
IsAcceptingDragAndDrop(void) IsAcceptingDragAndDrop(void)

View File

@ -35,9 +35,15 @@ SDL_FORCE_INLINE void AddN3DSDisplay(gfxScreen_t screen);
static int N3DS_VideoInit(_THIS); static int N3DS_VideoInit(_THIS);
static void N3DS_VideoQuit(_THIS); static void N3DS_VideoQuit(_THIS);
static void N3DS_GetDisplayModes(_THIS, SDL_VideoDisplay *display); static void N3DS_GetDisplayModes(_THIS, SDL_VideoDisplay *display);
static int N3DS_GetDisplayBounds(_THIS, SDL_VideoDisplay *display, SDL_Rect *rect);
static int N3DS_CreateWindow(_THIS, SDL_Window *window); static int N3DS_CreateWindow(_THIS, SDL_Window *window);
static void N3DS_DestroyWindow(_THIS, SDL_Window *window); static void N3DS_DestroyWindow(_THIS, SDL_Window *window);
typedef struct
{
gfxScreen_t screen;
} DisplayDriverData;
/* N3DS driver bootstrap functions */ /* N3DS driver bootstrap functions */
static void static void
@ -61,6 +67,7 @@ N3DS_CreateDevice(void)
device->VideoQuit = N3DS_VideoQuit; device->VideoQuit = N3DS_VideoQuit;
device->GetDisplayModes = N3DS_GetDisplayModes; device->GetDisplayModes = N3DS_GetDisplayModes;
device->GetDisplayBounds = N3DS_GetDisplayBounds;
device->CreateSDLWindow = N3DS_CreateWindow; device->CreateSDLWindow = N3DS_CreateWindow;
device->DestroyWindow = N3DS_DestroyWindow; device->DestroyWindow = N3DS_DestroyWindow;
@ -100,19 +107,27 @@ AddN3DSDisplay(gfxScreen_t screen)
{ {
SDL_DisplayMode mode; SDL_DisplayMode mode;
SDL_VideoDisplay display; SDL_VideoDisplay display;
DisplayDriverData *display_driver_data = SDL_calloc(1, sizeof(DisplayDriverData));
if (display_driver_data == NULL) {
SDL_OutOfMemory();
return;
}
SDL_zero(mode); SDL_zero(mode);
SDL_zero(display); SDL_zero(display);
display_driver_data->screen = screen;
mode.w = (screen == GFX_TOP) ? GSP_SCREEN_HEIGHT_TOP : GSP_SCREEN_HEIGHT_BOTTOM; mode.w = (screen == GFX_TOP) ? GSP_SCREEN_HEIGHT_TOP : GSP_SCREEN_HEIGHT_BOTTOM;
mode.h = GSP_SCREEN_WIDTH; mode.h = GSP_SCREEN_WIDTH;
mode.refresh_rate = 60; mode.refresh_rate = 60;
mode.format = FRAMEBUFFER_FORMAT; mode.format = FRAMEBUFFER_FORMAT;
mode.driverdata = NULL; mode.driverdata = NULL;
display.name = (screen == GFX_TOP) ? "N3DS top screen" : "N3DS bottom screen";
display.desktop_mode = mode; display.desktop_mode = mode;
display.current_mode = mode; display.current_mode = mode;
display.driverdata = NULL; display.driverdata = display_driver_data;
SDL_AddVideoDisplay(&display, SDL_FALSE); SDL_AddVideoDisplay(&display, SDL_FALSE);
} }
@ -131,21 +146,32 @@ N3DS_GetDisplayModes(_THIS, SDL_VideoDisplay *display)
SDL_AddDisplayMode(display, &display->current_mode); SDL_AddDisplayMode(display, &display->current_mode);
} }
static int
N3DS_GetDisplayBounds(_THIS, SDL_VideoDisplay *display, SDL_Rect *rect)
{
DisplayDriverData *driver_data = (DisplayDriverData *) 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 static int
N3DS_CreateWindow(_THIS, SDL_Window *window) N3DS_CreateWindow(_THIS, SDL_Window *window)
{ {
SDL_WindowData *drv_data = (SDL_WindowData *) SDL_calloc(1, sizeof(SDL_WindowData)); DisplayDriverData *display_data;
if (drv_data == NULL) { SDL_WindowData *window_data = (SDL_WindowData *) SDL_calloc(1, sizeof(SDL_WindowData));
if (window_data == NULL) {
return SDL_OutOfMemory(); return SDL_OutOfMemory();
} }
display_data = (DisplayDriverData *) SDL_GetDisplayDriverData(window->display_index);
if (window->flags & SDL_WINDOW_N3DS_BOTTOM) { window_data->screen = display_data->screen;
drv_data->screen = GFX_BOTTOM; window->driverdata = window_data;
} else {
drv_data->screen = GFX_TOP;
}
window->driverdata = drv_data;
return 0; return 0;
} }