Xbox GDKX support (#5869)

* Xbox GDK support (14 squashed commits)

* Added basic keyboard testing

* Update readme

* Code review fixes

* Fixed issue where controller add/removal wasn't working (since the device notification events don't work on Xbox, have to use the joystick thread to poll XInput)
This commit is contained in:
chalonverse
2022-07-01 13:59:14 -07:00
committed by GitHub
parent 0025621b80
commit f317d619cc
77 changed files with 2573 additions and 74 deletions

View File

@@ -581,6 +581,10 @@ SDL_GetPlatform(void)
return "WinRT";
#elif __WINGDK__
return "WinGDK";
#elif __XBOXONE__
return "Xbox One";
#elif __XBOXSERIES__
return "Xbox Series";
#elif __TVOS__
return "tvOS";
#elif __IPHONEOS__

View File

@@ -96,6 +96,9 @@ WIN_CoInitialize(void)
attribute, which, AFAIK, should initialize COM.
*/
return S_OK;
#elif defined(__XBOXONE__) || defined(__XBOXSERIES__)
/* On Xbox, there's no need to call CoInitializeEx (and it's not implemented) */
return S_OK;
#else
HRESULT hr = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
if (hr == RPC_E_CHANGED_MODE) {
@@ -179,7 +182,7 @@ WIN_RoUninitialize(void)
#endif
}
#ifndef __WINRT__
#if !defined(__WINRT__) && !defined(__XBOXONE__) && !defined(__XBOXSERIES__)
static BOOL
IsWindowsVersionOrGreater(WORD wMajorVersion, WORD wMinorVersion, WORD wServicePackMajor)
{
@@ -203,7 +206,7 @@ IsWindowsVersionOrGreater(WORD wMajorVersion, WORD wMinorVersion, WORD wServiceP
BOOL WIN_IsWindowsVistaOrGreater(void)
{
#ifdef __WINRT__
#if defined(__WINRT__) || defined(__XBOXONE__) || defined(__XBOXSERIES__)
return TRUE;
#else
return IsWindowsVersionOrGreater(HIBYTE(_WIN32_WINNT_VISTA), LOBYTE(_WIN32_WINNT_VISTA), 0);
@@ -212,7 +215,7 @@ BOOL WIN_IsWindowsVistaOrGreater(void)
BOOL WIN_IsWindows7OrGreater(void)
{
#ifdef __WINRT__
#if defined(__WINRT__) || defined(__XBOXONE__) || defined(__XBOXSERIES__)
return TRUE;
#else
return IsWindowsVersionOrGreater(HIBYTE(_WIN32_WINNT_WIN7), LOBYTE(_WIN32_WINNT_WIN7), 0);
@@ -221,7 +224,7 @@ BOOL WIN_IsWindows7OrGreater(void)
BOOL WIN_IsWindows8OrGreater(void)
{
#ifdef __WINRT__
#if defined(__WINRT__) || defined(__XBOXONE__) || defined(__XBOXSERIES__)
return TRUE;
#else
return IsWindowsVersionOrGreater(HIBYTE(_WIN32_WINNT_WIN8), LOBYTE(_WIN32_WINNT_WIN8), 0);
@@ -252,8 +255,8 @@ WASAPI doesn't need this. This is just for DirectSound/WinMM.
char *
WIN_LookupAudioDeviceName(const WCHAR *name, const GUID *guid)
{
#if __WINRT__
return WIN_StringToUTF8(name); /* No registry access on WinRT/UWP, go with what we've got. */
#if defined(__WINRT__) || defined(__XBOXONE__) || defined(__XBOXSERIES__)
return WIN_StringToUTF8(name); /* No registry access on WinRT/UWP and Xbox, go with what we've got. */
#else
static const GUID nullguid = { 0 };
const unsigned char *ptr;

View File

@@ -50,6 +50,20 @@
#undef _WIN32_WINNT
#define _WIN32_WINNT 0xA00
#define WINVER _WIN32_WINNT
#elif defined(__XBOXONE__) || defined(__XBOXSERIES__)
#ifndef WIN32_LEAN_AND_MEAN
#define WIN32_LEAN_AND_MEAN
#endif
#ifndef STRICT
#define STRICT
#endif
#ifndef UNICODE
#define UNICODE 1
#endif
#undef WINVER
#undef _WIN32_WINNT
#define _WIN32_WINNT 0xA00
#define WINVER _WIN32_WINNT
#endif
#include <windows.h>

View File

@@ -22,6 +22,10 @@
#include "SDL_xinput.h"
/* Set up for C function definitions, even when using C++ */
#ifdef __cplusplus
extern "C" {
#endif
XInputGetState_t SDL_XInputGetState = NULL;
XInputSetState_t SDL_XInputSetState = NULL;
@@ -33,7 +37,7 @@ static HANDLE s_pXInputDLL = 0;
static int s_XInputDLLRefCount = 0;
#ifdef __WINRT__
#if defined(__WINRT__) || defined(__XBOXONE__) || defined(__XBOXSERIES__)
int
WIN_LoadXInputDLL(void)
@@ -66,7 +70,7 @@ WIN_UnloadXInputDLL(void)
{
}
#else /* !__WINRT__ */
#else /* !(defined(__WINRT__) || defined(__XBOXONE__) || defined(__XBOXSERIES__)) */
int
WIN_LoadXInputDLL(void)
@@ -136,4 +140,9 @@ WIN_UnloadXInputDLL(void)
#endif /* __WINRT__ */
/* Ends C function definitions when using C++ */
#ifdef __cplusplus
}
#endif
/* vi: set ts=4 sw=4 expandtab: */

View File

@@ -26,7 +26,13 @@
#include "SDL_windows.h"
#ifdef HAVE_XINPUT_H
#if defined(__XBOXONE__) || defined(__XBOXSERIES__)
/* Xbox supports an XInput wrapper which is a C++-only header... */
#include <XInputOnGameInput.h>
using namespace XInputOnGameInput;
#else
#include <xinput.h>
#endif
#endif /* HAVE_XINPUT_H */
#ifndef XUSER_MAX_COUNT
@@ -147,6 +153,11 @@
#define BATTERY_LEVEL_FULL 0x03
#endif
/* Set up for C function definitions, even when using C++ */
#ifdef __cplusplus
extern "C" {
#endif
/* typedef's for XInput structs we use */
#ifndef HAVE_XINPUT_GAMEPAD_EX
@@ -243,6 +254,11 @@ extern XInputGetCapabilities_t SDL_XInputGetCapabilities;
extern XInputGetBatteryInformation_t SDL_XInputGetBatteryInformation;
extern DWORD SDL_XInputVersion; /* ((major << 16) & 0xFF00) | (minor & 0xFF) */
/* Ends C function definitions when using C++ */
#ifdef __cplusplus
}
#endif
#define XINPUTGETSTATE SDL_XInputGetState
#define XINPUTSETSTATE SDL_XInputSetState
#define XINPUTGETCAPABILITIES SDL_XInputGetCapabilities

View File

@@ -291,7 +291,7 @@ static void dynapi_warn(const char *msg)
{
const char *caption = "SDL Dynamic API Failure!";
/* SDL_ShowSimpleMessageBox() is a too heavy for here. */
#if defined(WIN32) || defined(_WIN32) || defined(__CYGWIN__)
#if (defined(WIN32) || defined(_WIN32) || defined(__CYGWIN__)) && !defined(__XBOXONE__) && !defined(__XBOXSERIES__)
MessageBoxA(NULL, msg, caption, MB_OK | MB_ICONERROR);
#elif defined(HAVE_STDIO_H)
fprintf(stderr, "\n\n%s\n%s\n\n", caption, msg);

View File

@@ -55,7 +55,7 @@ SDL_MouseDoubleClickTimeChanged(void *userdata, const char *name, const char *ol
if (hint && *hint) {
mouse->double_click_time = SDL_atoi(hint);
} else {
#if defined(__WIN32__) || defined(__GDK__)
#if defined(__WIN32__) || defined(__WINGDK__)
mouse->double_click_time = GetDoubleClickTime();
#elif defined(__OS2__)
mouse->double_click_time = WinQuerySysValue(HWND_DESKTOP, SV_DBLCLKTIME);

View File

@@ -75,7 +75,9 @@
static int SDLCALL
windows_file_open(SDL_RWops * context, const char *filename, const char *mode)
{
#if !defined(__XBOXONE__) && !defined(__XBOXSERIES__)
UINT old_error_mode;
#endif
HANDLE h;
DWORD r_right, w_right;
DWORD must_exist, truncate;
@@ -112,9 +114,11 @@ windows_file_open(SDL_RWops * context, const char *filename, const char *mode)
if (!context->hidden.windowsio.buffer.data) {
return SDL_OutOfMemory();
}
#if !defined(__XBOXONE__) && !defined(__XBOXSERIES__)
/* Do not open a dialog box if failure */
old_error_mode =
SetErrorMode(SEM_NOOPENFILEERRORBOX | SEM_FAILCRITICALERRORS);
#endif
{
LPTSTR tstr = WIN_UTF8ToString(filename);
@@ -125,8 +129,10 @@ windows_file_open(SDL_RWops * context, const char *filename, const char *mode)
SDL_free(tstr);
}
#if !defined(__XBOXONE__) && !defined(__XBOXSERIES__)
/* restore old behavior */
SetErrorMode(old_error_mode);
#endif
if (h == INVALID_HANDLE_VALUE) {
SDL_free(context->hidden.windowsio.buffer.data);

View File

@@ -172,4 +172,23 @@ SDL_GetPrefPath(const char *org, const char *app)
#endif /* SDL_FILESYSTEM_WINDOWS */
#ifdef SDL_FILESYSTEM_XBOX
#include "SDL_filesystem.h"
#include "SDL_error.h"
char *
SDL_GetBasePath(void)
{
SDL_Unsupported();
return NULL;
}
char *
SDL_GetPrefPath(const char *org, const char *app)
{
SDL_Unsupported();
return NULL;
}
#endif /* SDL_FILESYSTEM_XBOX */
/* vi: set ts=4 sw=4 expandtab: */

View File

@@ -26,6 +26,10 @@
#include "SDL_haptic.h"
/* Set up for C function definitions, even when using C++ */
#ifdef __cplusplus
extern "C" {
#endif
struct haptic_effect
{
@@ -203,6 +207,11 @@ extern int SDL_SYS_HapticUnpause(SDL_Haptic * haptic);
*/
extern int SDL_SYS_HapticStopAll(SDL_Haptic * haptic);
/* Ends C function definitions when using C++ */
#ifdef __cplusplus
}
#endif
#endif /* SDL_syshaptic_h_ */
/* vi: set ts=4 sw=4 expandtab: */

View File

@@ -23,6 +23,10 @@
#include "SDL_haptic.h"
#include "SDL_windowshaptic_c.h"
/* Set up for C function definitions, even when using C++ */
#ifdef __cplusplus
extern "C" {
#endif
extern int SDL_DINPUT_HapticInit(void);
extern int SDL_DINPUT_HapticMaybeAddDevice(const DIDEVICEINSTANCE *pdidInstance);
@@ -44,4 +48,9 @@ extern int SDL_DINPUT_HapticPause(SDL_Haptic * haptic);
extern int SDL_DINPUT_HapticUnpause(SDL_Haptic * haptic);
extern int SDL_DINPUT_HapticStopAll(SDL_Haptic * haptic);
/* Ends C function definitions when using C++ */
#ifdef __cplusplus
}
#endif
/* vi: set ts=4 sw=4 expandtab: */

View File

@@ -37,6 +37,10 @@
#include "SDL_dinputhaptic_c.h"
#include "SDL_xinputhaptic_c.h"
/* Set up for C function definitions, even when using C++ */
#ifdef __cplusplus
extern "C" {
#endif
/*
* Internal stuff.
@@ -466,6 +470,11 @@ SDL_SYS_HapticStopAll(SDL_Haptic * haptic)
}
}
/* Ends C function definitions when using C++ */
#ifdef __cplusplus
}
#endif
#endif /* SDL_HAPTIC_DINPUT || SDL_HAPTIC_XINPUT */
/* vi: set ts=4 sw=4 expandtab: */

View File

@@ -28,6 +28,11 @@
#include "../../core/windows/SDL_directx.h"
#include "../../core/windows/SDL_xinput.h"
/* Set up for C function definitions, even when using C++ */
#ifdef __cplusplus
extern "C" {
#endif
/*
* Haptic system hardware data.
*/
@@ -84,6 +89,11 @@ extern SDL_hapticlist_item *SDL_hapticlist;
extern int SDL_SYS_AddHapticDevice(SDL_hapticlist_item *item);
extern int SDL_SYS_RemoveHapticDevice(SDL_hapticlist_item *prev, SDL_hapticlist_item *item);
/* Ends C function definitions when using C++ */
#ifdef __cplusplus
}
#endif
#endif /* SDL_windowshaptic_c_h_ */
/* vi: set ts=4 sw=4 expandtab: */

View File

@@ -35,6 +35,11 @@
#include "../../joystick/windows/SDL_windowsjoystick_c.h"
#include "../../thread/SDL_systhread.h"
/* Set up for C function definitions, even when using C++ */
#ifdef __cplusplus
extern "C" {
#endif
/*
* Internal stuff.
*/
@@ -45,7 +50,7 @@ int
SDL_XINPUT_HapticInit(void)
{
if (SDL_GetHintBoolean(SDL_HINT_XINPUT_ENABLED, SDL_TRUE)) {
loaded_xinput = (WIN_LoadXInputDLL() == 0);
loaded_xinput = (WIN_LoadXInputDLL() == 0) ? SDL_TRUE : SDL_FALSE;
}
/* If the joystick subsystem is active, it will manage adding XInput haptic devices */
@@ -365,6 +370,11 @@ SDL_XINPUT_HapticStopAll(SDL_Haptic * haptic)
return (XINPUTSETSTATE(haptic->hwdata->userid, &vibration) == ERROR_SUCCESS) ? 0 : -1;
}
/* Ends C function definitions when using C++ */
#ifdef __cplusplus
}
#endif
#else /* !SDL_HAPTIC_XINPUT */
#include "../../core/windows/SDL_windows.h"

View File

@@ -23,6 +23,10 @@
#include "SDL_haptic.h"
#include "SDL_windowshaptic_c.h"
/* Set up for C function definitions, even when using C++ */
#ifdef __cplusplus
extern "C" {
#endif
extern int SDL_XINPUT_HapticInit(void);
extern int SDL_XINPUT_HapticMaybeAddDevice(const DWORD dwUserid);
@@ -44,4 +48,9 @@ extern int SDL_XINPUT_HapticPause(SDL_Haptic * haptic);
extern int SDL_XINPUT_HapticUnpause(SDL_Haptic * haptic);
extern int SDL_XINPUT_HapticStopAll(SDL_Haptic * haptic);
/* Ends C function definitions when using C++ */
#ifdef __cplusplus
}
#endif
/* vi: set ts=4 sw=4 expandtab: */

View File

@@ -28,6 +28,11 @@
#include "SDL_gamecontroller.h"
#include "SDL_joystick.h"
/* Set up for C function definitions, even when using C++ */
#ifdef __cplusplus
extern "C" {
#endif
struct _SDL_JoystickDriver;
/* Initialization and shutdown functions */
@@ -187,6 +192,11 @@ typedef struct _SDL_GamepadMapping
extern SDL_bool SDL_PrivateJoystickGetAutoGamepadMapping(int device_index,
SDL_GamepadMapping *out);
/* Ends C function definitions when using C++ */
#ifdef __cplusplus
}
#endif
#endif /* SDL_joystick_c_h_ */
/* vi: set ts=4 sw=4 expandtab: */

View File

@@ -27,6 +27,11 @@
#include "SDL_joystick.h"
#include "SDL_joystick_c.h"
/* Set up for C function definitions, even when using C++ */
#ifdef __cplusplus
extern "C" {
#endif
/* The SDL joystick structure */
typedef struct _SDL_JoystickAxisInfo
{
@@ -230,6 +235,11 @@ extern SDL_JoystickDriver SDL_PS2_JoystickDriver;
extern SDL_JoystickDriver SDL_PSP_JoystickDriver;
extern SDL_JoystickDriver SDL_VITA_JoystickDriver;
/* Ends C function definitions when using C++ */
#ifdef __cplusplus
}
#endif
#endif /* SDL_sysjoystick_h_ */
/* vi: set ts=4 sw=4 expandtab: */

View File

@@ -20,6 +20,11 @@
*/
#include "../../SDL_internal.h"
/* Set up for C function definitions, even when using C++ */
#ifdef __cplusplus
extern "C" {
#endif
extern int SDL_DINPUT_JoystickInit(void);
extern void SDL_DINPUT_JoystickDetect(JoyStick_DeviceData **pContext);
extern SDL_bool SDL_DINPUT_JoystickPresent(Uint16 vendor, Uint16 product, Uint16 version);
@@ -30,4 +35,9 @@ extern void SDL_DINPUT_JoystickUpdate(SDL_Joystick * joystick);
extern void SDL_DINPUT_JoystickClose(SDL_Joystick * joystick);
extern void SDL_DINPUT_JoystickQuit(void);
/* Ends C function definitions when using C++ */
#ifdef __cplusplus
}
#endif
/* vi: set ts=4 sw=4 expandtab: */

View File

@@ -41,7 +41,7 @@
#include "../SDL_sysjoystick.h"
#include "../../thread/SDL_systhread.h"
#include "../../core/windows/SDL_windows.h"
#if !defined(__WINRT__)
#if !defined(__WINRT__) && !defined(__XBOXONE__) && !defined(__XBOXSERIES__)
#include <dbt.h>
#endif
@@ -63,6 +63,11 @@
#define CR_SUCCESS (0x00000000)
/* Set up for C function definitions, even when using C++ */
#ifdef __cplusplus
extern "C" {
#endif
DECLARE_HANDLE(HCMNOTIFICATION);
typedef HCMNOTIFICATION* PHCMNOTIFICATION;
@@ -141,7 +146,7 @@ static GUID GUID_DEVINTERFACE_HID = { 0x4D1E55B2L, 0xF16F, 0x11CF, { 0x88, 0xCB,
JoyStick_DeviceData *SYS_Joystick; /* array to hold joystick ID values */
#ifndef __WINRT__
#if !defined(__WINRT__) && !defined(__XBOXONE__) && !defined(__XBOXSERIES__)
static HMODULE cfgmgr32_lib_handle;
static CM_Register_NotificationFunc CM_Register_Notification;
static CM_Unregister_NotificationFunc CM_Unregister_Notification;
@@ -327,7 +332,14 @@ SDL_WaitForDeviceNotification(SDL_DeviceNotificationData *data, SDL_mutex *mutex
return (lastret != -1) ? SDL_TRUE : SDL_FALSE;
}
#endif /* !defined(__WINRT__) && !defined(__XBOXONE__) && !defined(__XBOXSERIES__) */
#if !defined(__WINRT__)
#if !defined(__XBOXONE__) && !defined(__XBOXSERIES__)
static SDL_DeviceNotificationData s_notification_data;
#endif
/* Function/thread to scan the system for joysticks. */
static int SDLCALL
@@ -338,13 +350,19 @@ SDL_JoystickThread(void *_data)
SDL_zeroa(bOpenedXInputDevices);
#endif
#if !defined(__XBOXONE__) && !defined(__XBOXSERIES__)
if (SDL_CreateDeviceNotification(&s_notification_data) < 0) {
return -1;
}
#endif
SDL_LockMutex(s_mutexJoyStickEnum);
while (s_bJoystickThreadQuit == SDL_FALSE) {
#if !defined(__XBOXONE__) && !defined(__XBOXSERIES__)
if (SDL_WaitForDeviceNotification(&s_notification_data, s_mutexJoyStickEnum) == SDL_FALSE) {
#else
{
#endif
#if SDL_JOYSTICK_XINPUT
/* WM_DEVICECHANGE not working, poll for new XINPUT controllers */
SDL_CondWaitTimeout(s_condJoystickThread, s_mutexJoyStickEnum, 1000);
@@ -354,7 +372,7 @@ SDL_JoystickThread(void *_data)
for (userId = 0; userId < XUSER_MAX_COUNT; userId++) {
XINPUT_CAPABILITIES capabilities;
const DWORD result = XINPUTGETCAPABILITIES(userId, XINPUT_FLAG_GAMEPAD, &capabilities);
const SDL_bool available = (result == ERROR_SUCCESS);
const SDL_bool available = (result == ERROR_SUCCESS) ? SDL_TRUE : SDL_FALSE;
if (bOpenedXInputDevices[userId] != available) {
s_bWindowsDeviceChanged = SDL_TRUE;
bOpenedXInputDevices[userId] = available;
@@ -367,9 +385,12 @@ SDL_JoystickThread(void *_data)
#endif /* SDL_JOYSTICK_XINPUT */
}
}
SDL_UnlockMutex(s_mutexJoyStickEnum);
#if !defined(__XBOXONE__) && !defined(__XBOXSERIES__)
SDL_CleanupDeviceNotification(&s_notification_data);
#endif
return 1;
}
@@ -419,7 +440,7 @@ SDL_StopJoystickThread(void)
s_joystickThread = NULL;
}
#endif /* !__WINRT__ */
#endif /* !defined(__WINRT__) */
void WINDOWS_AddJoystickDevice(JoyStick_DeviceData *device)
{
@@ -453,7 +474,7 @@ WINDOWS_JoystickInit(void)
WINDOWS_JoystickDetect();
#ifndef __WINRT__
#if !defined(__WINRT__) && !defined(__XBOXONE__) && !defined(__XBOXSERIES__)
SDL_CreateDeviceNotificationFunc();
s_bJoystickThread = SDL_GetHintBoolean(SDL_HINT_JOYSTICK_THREAD, SDL_FALSE);
@@ -467,6 +488,14 @@ WINDOWS_JoystickInit(void)
}
}
#endif
#if defined(__XBOXONE__) || defined(__XBOXSERIES__)
/* On Xbox, force create the joystick thread for device detection (since other methods don't work */
s_bJoystickThread = SDL_TRUE;
if (SDL_StartJoystickThread() < 0) {
return -1;
}
#endif
return 0;
}
@@ -738,7 +767,7 @@ WINDOWS_JoystickQuit(void)
}
SYS_Joystick = NULL;
#ifndef __WINRT__
#if !defined(__WINRT__) && !defined(__XBOXONE__) && !defined(__XBOXSERIES__)
if (s_bJoystickThread) {
SDL_StopJoystickThread();
} else {
@@ -748,6 +777,12 @@ WINDOWS_JoystickQuit(void)
SDL_CleanupDeviceNotificationFunc();
#endif
#if defined(__XBOXONE__) || defined(__XBOXSERIES__)
if (s_bJoystickThread) {
SDL_StopJoystickThread();
}
#endif
SDL_DINPUT_JoystickQuit();
SDL_XINPUT_JoystickQuit();
@@ -784,6 +819,11 @@ SDL_JoystickDriver SDL_WINDOWS_JoystickDriver =
WINDOWS_JoystickGetGamepadMapping
};
/* Ends C function definitions when using C++ */
#ifdef __cplusplus
}
#endif
#else
#if SDL_JOYSTICK_RAWINPUT

View File

@@ -27,6 +27,11 @@
#define MAX_INPUTS 256 /* each joystick can have up to 256 inputs */
/* Set up for C function definitions, even when using C++ */
#ifdef __cplusplus
extern "C" {
#endif
typedef struct JoyStick_DeviceData
{
SDL_JoystickGUID guid;
@@ -91,4 +96,9 @@ extern const DIDATAFORMAT SDL_c_dfDIJoystick2;
extern void WINDOWS_AddJoystickDevice(JoyStick_DeviceData *device);
/* Ends C function definitions when using C++ */
#ifdef __cplusplus
}
#endif
/* vi: set ts=4 sw=4 expandtab: */

View File

@@ -31,6 +31,11 @@
#include "SDL_rawinputjoystick_c.h"
#include "../hidapi/SDL_hidapijoystick_c.h"
/* Set up for C function definitions, even when using C++ */
#ifdef __cplusplus
extern "C" {
#endif
/*
* Internal stuff.
*/
@@ -45,6 +50,8 @@ SDL_XInputUseOldJoystickMapping()
/* TODO: remove this __WINRT__ block, but only after integrating with UWP/WinRT's HID API */
/* FIXME: Why are Win8/10 different here? -flibit */
return (NTDDI_VERSION < NTDDI_WIN10);
#elif defined(__XBOXONE__) || defined(__XBOXSERIES__)
return SDL_FALSE;
#else
static int s_XInputUseOldJoystickMapping = -1;
if (s_XInputUseOldJoystickMapping < 0) {
@@ -126,7 +133,7 @@ GetXInputName(const Uint8 userid, BYTE SubType)
static void
GuessXInputDevice(Uint8 userid, Uint16 *pVID, Uint16 *pPID, Uint16 *pVersion)
{
#ifndef __WINRT__ /* TODO: remove this ifndef __WINRT__ block, but only after integrating with UWP/WinRT's HID API */
#if !defined(__WINRT__) && !defined(__XBOXONE__) && !defined(__XBOXSERIES__) /* TODO: remove this ifndef __WINRT__ block, but only after integrating with UWP/WinRT's HID API */
PRAWINPUTDEVICELIST devices = NULL;
UINT i, j, device_count = 0;
@@ -386,7 +393,7 @@ SDL_XINPUT_JoystickOpen(SDL_Joystick * joystick, JoyStick_DeviceData *joystickde
return SDL_SetError("Failed to obtain XInput device capabilities. Device disconnected?");
}
SDL_zero(state);
joystick->hwdata->bXInputHaptic = (XINPUTSETSTATE(userId, &state) == ERROR_SUCCESS);
joystick->hwdata->bXInputHaptic = (XINPUTSETSTATE(userId, &state) == ERROR_SUCCESS) ? SDL_TRUE : SDL_FALSE;
joystick->hwdata->userid = userId;
/* The XInput API has a hard coded button/axis mapping, so we just match it */
@@ -541,6 +548,10 @@ SDL_XINPUT_JoystickUpdate(SDL_Joystick * joystick)
result = XINPUTGETBATTERYINFORMATION(joystick->hwdata->userid, BATTERY_DEVTYPE_GAMEPAD, &XBatteryInformation);
}
#if defined(__XBOXONE__) || defined(__XBOXSERIES__)
/* XInputOnGameInput doesn't ever change dwPacketNumber, so have to just update every frame */
UpdateXInputJoystickState(joystick, &XInputState, &XBatteryInformation);
#else
/* only fire events if the data changed from last time */
if (XInputState.dwPacketNumber && XInputState.dwPacketNumber != joystick->hwdata->dwPacketNumber) {
if (SDL_XInputUseOldJoystickMapping()) {
@@ -550,6 +561,7 @@ SDL_XINPUT_JoystickUpdate(SDL_Joystick * joystick)
}
joystick->hwdata->dwPacketNumber = XInputState.dwPacketNumber;
}
#endif
}
void
@@ -565,6 +577,11 @@ SDL_XINPUT_JoystickQuit(void)
}
}
/* Ends C function definitions when using C++ */
#ifdef __cplusplus
}
#endif
#else /* !SDL_JOYSTICK_XINPUT */
typedef struct JoyStick_DeviceData JoyStick_DeviceData;

View File

@@ -22,6 +22,11 @@
#include "../../core/windows/SDL_xinput.h"
/* Set up for C function definitions, even when using C++ */
#ifdef __cplusplus
extern "C" {
#endif
extern SDL_bool SDL_XINPUT_Enabled(void);
extern int SDL_XINPUT_JoystickInit(void);
extern void SDL_XINPUT_JoystickDetect(JoyStick_DeviceData **pContext);
@@ -32,4 +37,9 @@ extern void SDL_XINPUT_JoystickUpdate(SDL_Joystick * joystick);
extern void SDL_XINPUT_JoystickClose(SDL_Joystick * joystick);
extern void SDL_XINPUT_JoystickQuit(void);
/* Ends C function definitions when using C++ */
#ifdef __cplusplus
}
#endif
/* vi: set ts=4 sw=4 expandtab: */

View File

@@ -24,6 +24,14 @@
#include <shellapi.h>
#if defined(__XBOXONE__) || defined(__XBOXSERIES__)
int
SDL_SYS_OpenURL(const char *url)
{
/* Not supported */
return SDL_Unsupported();
}
#else
/* https://msdn.microsoft.com/en-us/library/windows/desktop/bb762153%28v=vs.85%29.aspx */
int
SDL_SYS_OpenURL(const char *url)
@@ -49,6 +57,7 @@ SDL_SYS_OpenURL(const char *url)
WIN_CoUninitialize();
return (rc > ((HINSTANCE) 32)) ? 0 : WIN_SetError("Couldn't open given URL.");
}
#endif
/* vi: set ts=4 sw=4 expandtab: */

View File

@@ -38,10 +38,17 @@
#include "../SDL_sysrender.h"
#include "../SDL_d3dmath.h"
#if defined(__XBOXONE__) || defined(__XBOXSERIES__)
#include "SDL_render_d3d12_xbox.h"
#ifndef D3D12_TEXTURE_DATA_PITCH_ALIGNMENT
#define D3D12_TEXTURE_DATA_PITCH_ALIGNMENT 256
#endif
#else
#include <d3d12.h>
#include <dxgi1_6.h>
#include <dxgidebug.h>
#include <d3d12sdklayers.h>
#endif
#include "SDL_shaders_d3d12.h"
@@ -153,14 +160,18 @@ typedef struct
{
void *hDXGIMod;
void *hD3D12Mod;
#if defined(__XBOXONE__) || defined(__XBOXSERIES__)
UINT64 frameToken;
#else
IDXGIFactory6 *dxgiFactory;
IDXGIAdapter4 *dxgiAdapter;
IDXGIDebug *dxgiDebug;
IDXGISwapChain4 *swapChain;
#endif
ID3D12Device1 *d3dDevice;
ID3D12Debug *debugInterface;
IDXGIDebug *dxgiDebug;
ID3D12CommandQueue *commandQueue;
ID3D12GraphicsCommandList2 *commandList;
IDXGISwapChain4 *swapChain;
DXGI_SWAP_EFFECT swapEffect;
/* Descriptor heaps */
@@ -231,7 +242,7 @@ typedef struct
static const GUID SDL_IID_IDXGIFactory6 = { 0xc1b6694f, 0xff09, 0x44a9, { 0xb0, 0x3c, 0x77, 0x90, 0x0a, 0x0a, 0x1d, 0x17 } };
static const GUID SDL_IID_IDXGIAdapter4 = { 0x3c8d99d1, 0x4fbf, 0x4181, { 0xa8, 0x2c, 0xaf, 0x66, 0xbf, 0x7b, 0xd2, 0x4e } };
static const GUID SDL_IID_IDXGIDevice1 = { 0x77db970f, 0x6276, 0x48ba, { 0xba, 0x28, 0x07, 0x01, 0x43, 0xb4, 0x39, 0x2c } };
static const GUID SDL_IID_ID3D12Device5 = { 0x8b4f173b, 0x2fea, 0x4b80, { 0x8f, 0x58, 0x43, 0x07, 0x19, 0x1a, 0xb9, 0x5d } };
static const GUID SDL_IID_ID3D12Device1 = { 0x77acce80, 0x638e, 0x4e65, { 0x88, 0x95, 0xc1, 0xf2, 0x33, 0x86, 0x86, 0x3e } };
static const GUID SDL_IID_IDXGISwapChain4 = { 0x3D585D5A, 0xBD4A, 0x489E, { 0xB1, 0xF4, 0x3D, 0xBC, 0xB6, 0x45, 0x2F, 0xFB } };
static const GUID SDL_IID_IDXGIDebug1 = { 0xc5a05f0c, 0x16f2, 0x4adf, { 0x9f, 0x4d, 0xa8, 0xc4, 0xd5, 0x8a, 0xc5, 0x50 } };
static const GUID SDL_IID_IDXGIInfoQueue = { 0xD67441C7,0x672A,0x476f, { 0x9E,0x82,0xCD,0x55,0xB4,0x49,0x49,0xCE } };
@@ -307,8 +318,11 @@ D3D12_ReleaseAll(SDL_Renderer * renderer)
if (data) {
int i;
#if !defined(__XBOXONE__) && !defined(__XBOXSERIES__)
SAFE_RELEASE(data->dxgiFactory);
SAFE_RELEASE(data->dxgiAdapter);
SAFE_RELEASE(data->swapChain);
#endif
SAFE_RELEASE(data->d3dDevice);
SAFE_RELEASE(data->debugInterface);
SAFE_RELEASE(data->commandQueue);
@@ -317,7 +331,6 @@ D3D12_ReleaseAll(SDL_Renderer * renderer)
SAFE_RELEASE(data->textureRTVDescriptorHeap);
SAFE_RELEASE(data->srvDescriptorHeap);
SAFE_RELEASE(data->samplerDescriptorHeap);
SAFE_RELEASE(data->swapChain);
SAFE_RELEASE(data->fence);
for (i = 0; i < SDL_D3D12_NUM_BUFFERS; ++i) {
@@ -345,12 +358,14 @@ D3D12_ReleaseAll(SDL_Renderer * renderer)
data->currentRenderTargetView.ptr = 0;
data->currentSampler.ptr = 0;
#if !defined(__XBOXONE__) && !defined(__XBOXSERIES__)
/* Check for any leaks if in debug mode */
if (data->dxgiDebug) {
DXGI_DEBUG_RLO_FLAGS rloFlags = (DXGI_DEBUG_RLO_FLAGS)(DXGI_DEBUG_RLO_SUMMARY | DXGI_DEBUG_RLO_IGNORE_INTERNAL);
D3D_CALL(data->dxgiDebug, ReportLiveObjects, SDL_DXGI_DEBUG_ALL, rloFlags);
SAFE_RELEASE(data->dxgiDebug);
}
#endif
/* Unload the D3D libraries. This should be done last, in order
* to prevent IUnknown::Release() calls from crashing.
@@ -700,10 +715,12 @@ D3D12_CreateVertexBuffer(D3D12_RenderData *data, size_t vbidx, size_t size)
static HRESULT
D3D12_CreateDeviceResources(SDL_Renderer* renderer)
{
#if !defined(__XBOXONE__) && !defined(__XBOXSERIES__)
typedef HRESULT(WINAPI* PFN_CREATE_DXGI_FACTORY)(UINT flags, REFIID riid, void** ppFactory);
PFN_CREATE_DXGI_FACTORY CreateDXGIFactoryFunc;
D3D12_RenderData* data = (D3D12_RenderData*)renderer->driverdata;
PFN_D3D12_CREATE_DEVICE D3D12CreateDeviceFunc;
#endif
D3D12_RenderData* data = (D3D12_RenderData*)renderer->driverdata;
ID3D12Device* d3dDevice = NULL;
HRESULT result = S_OK;
UINT creationFlags = 0;
@@ -728,6 +745,10 @@ D3D12_CreateDeviceResources(SDL_Renderer* renderer)
DXGI_FORMAT_R8_UNORM
};
/* See if we need debug interfaces */
createDebug = SDL_GetHintBoolean(SDL_HINT_RENDER_DIRECT3D11_DEBUG, SDL_FALSE);
#if !defined(__XBOXONE__) && !defined(__XBOXSERIES__)
data->hDXGIMod = SDL_LoadObject("dxgi.dll");
if (!data->hDXGIMod) {
result = E_FAIL;
@@ -752,9 +773,6 @@ D3D12_CreateDeviceResources(SDL_Renderer* renderer)
goto done;
}
/* See if we need debug interfaces */
createDebug = SDL_GetHintBoolean(SDL_HINT_RENDER_DIRECT3D11_DEBUG, SDL_FALSE);
if (createDebug) {
PFN_D3D12_GET_DEBUG_INTERFACE D3D12GetDebugInterfaceFunc;
@@ -766,7 +784,15 @@ D3D12_CreateDeviceResources(SDL_Renderer* renderer)
D3D12GetDebugInterfaceFunc(D3D_GUID(SDL_IID_ID3D12Debug), (void**)&data->debugInterface);
D3D_CALL(data->debugInterface, EnableDebugLayer);
}
#endif /*!defined(__XBOXONE__) && !defined(__XBOXSERIES__)*/
#if defined(__XBOXONE__) || defined(__XBOXSERIES__)
result = D3D12_XBOX_CreateDevice(&d3dDevice, createDebug);
if (FAILED(result)) {
/* SDL Error is set by D3D12_XBOX_CreateDevice */
goto done;
}
#else
if (createDebug) {
#ifdef __IDXGIInfoQueue_INTERFACE_DEFINED__
IDXGIInfoQueue *dxgiInfoQueue = NULL;
@@ -818,7 +844,7 @@ D3D12_CreateDeviceResources(SDL_Renderer* renderer)
result = D3D12CreateDeviceFunc((IUnknown *)data->dxgiAdapter,
D3D_FEATURE_LEVEL_11_0, /* Request minimum feature level 11.0 for maximum compatibility */
D3D_GUID(SDL_IID_ID3D12Device5),
D3D_GUID(SDL_IID_ID3D12Device1),
(void **)&d3dDevice
);
if (FAILED(result)) {
@@ -848,10 +874,11 @@ D3D12_CreateDeviceResources(SDL_Renderer* renderer)
SAFE_RELEASE(infoQueue);
}
#endif /*!defined(__XBOXONE__) && !defined(__XBOXSERIES__)*/
result = D3D_CALL(d3dDevice, QueryInterface, D3D_GUID(SDL_IID_ID3D12Device5), (void **)&data->d3dDevice);
result = D3D_CALL(d3dDevice, QueryInterface, D3D_GUID(SDL_IID_ID3D12Device1), (void **)&data->d3dDevice);
if (FAILED(result)) {
WIN_SetErrorFromHRESULT(SDL_COMPOSE_ERROR("ID3D12Device to ID3D12Device5"), result);
WIN_SetErrorFromHRESULT(SDL_COMPOSE_ERROR("ID3D12Device to ID3D12Device1"), result);
goto done;
}
@@ -1120,6 +1147,7 @@ D3D12_GetViewportAlignedD3DRect(SDL_Renderer * renderer, const SDL_Rect * sdlRec
return 0;
}
#if !defined(__XBOXONE__) && !defined(__XBOXSERIES__)
static HRESULT
D3D12_CreateSwapChain(SDL_Renderer * renderer, int w, int h)
{
@@ -1187,6 +1215,7 @@ done:
SAFE_RELEASE(swapChain);
return result;
}
#endif
static HRESULT D3D12_UpdateForWindowSizeChange(SDL_Renderer * renderer);
@@ -1246,6 +1275,7 @@ D3D12_CreateWindowSizeDependentResources(SDL_Renderer * renderer)
h = tmp;
}
#if !defined(__XBOXONE__) && !defined(__XBOXSERIES__)
if (data->swapChain) {
/* If the swap chain already exists, resize it. */
result = D3D_CALL(data->swapChain, ResizeBuffers,
@@ -1283,9 +1313,17 @@ D3D12_CreateWindowSizeDependentResources(SDL_Renderer * renderer)
}
}
}
#endif /*!defined(__XBOXONE__) && !defined(__XBOXSERIES__)*/
/* Get each back buffer render target and create render target views */
for (i = 0; i < SDL_D3D12_NUM_BUFFERS; ++i) {
#if defined(__XBOXONE__) || defined(__XBOXSERIES__)
result = D3D12_XBOX_CreateBackBufferTarget(data->d3dDevice, renderer->window->w, renderer->window->h, (void **) &data->renderTargets[i]);
if (FAILED(result)) {
WIN_SetErrorFromHRESULT(SDL_COMPOSE_ERROR("D3D12_XBOX_CreateBackBufferTarget"), result);
goto done;
}
#else
result = D3D_CALL(data->swapChain, GetBuffer,
i,
D3D_GUID(SDL_IID_ID3D12Resource),
@@ -1295,6 +1333,7 @@ D3D12_CreateWindowSizeDependentResources(SDL_Renderer * renderer)
WIN_SetErrorFromHRESULT(SDL_COMPOSE_ERROR("IDXGISwapChain4::GetBuffer"), result);
goto done;
}
#endif
SDL_zero(rtvDesc);
rtvDesc.Format = DXGI_FORMAT_B8G8R8A8_UNORM;
@@ -1307,7 +1346,11 @@ D3D12_CreateWindowSizeDependentResources(SDL_Renderer * renderer)
}
/* Set back buffer index to current buffer */
#if defined(__XBOXONE__) || defined(__XBOXSERIES__)
data->currentBackBufferIndex = 0;
#else
data->currentBackBufferIndex = D3D_CALL(data->swapChain, GetCurrentBackBufferIndex);
#endif
/* Set the swap chain target immediately, so that a target is always set
* even before we get to SetDrawState. Without this it's possible to hit
@@ -1323,6 +1366,10 @@ D3D12_CreateWindowSizeDependentResources(SDL_Renderer * renderer)
data->viewportDirty = SDL_TRUE;
#if defined(__XBOXONE__) || defined(__XBOXSERIES__)
D3D12_XBOX_StartFrame(data->d3dDevice, &data->frameToken);
#endif
done:
return result;
}
@@ -2870,8 +2917,10 @@ static void
D3D12_RenderPresent(SDL_Renderer * renderer)
{
D3D12_RenderData *data = (D3D12_RenderData *) renderer->driverdata;
#if !defined(__XBOXONE__) && !defined(__XBOXSERIES__)
UINT syncInterval;
UINT presentFlags;
#endif
HRESULT result;
/* Transition the render target to present state */
@@ -2885,6 +2934,9 @@ D3D12_RenderPresent(SDL_Renderer * renderer)
result = D3D_CALL(data->commandList, Close);
D3D_CALL(data->commandQueue, ExecuteCommandLists, 1, (ID3D12CommandList * const *)&data->commandList);
#if defined(__XBOXONE__) || defined(__XBOXSERIES__)
result = D3D12_XBOX_PresentFrame(data->commandQueue, data->frameToken, data->renderTargets[data->currentBackBufferIndex]);
#else
if (renderer->info.flags & SDL_RENDERER_PRESENTVSYNC) {
syncInterval = 1;
presentFlags = 0;
@@ -2897,6 +2949,7 @@ D3D12_RenderPresent(SDL_Renderer * renderer)
* rects to improve efficiency in certain scenarios.
*/
result = D3D_CALL(data->swapChain, Present, syncInterval, presentFlags);
#endif
if (FAILED(result) && result != DXGI_ERROR_WAS_STILL_DRAWING) {
/* If the device was removed either by a disconnect or a driver upgrade, we
@@ -2923,7 +2976,12 @@ D3D12_RenderPresent(SDL_Renderer * renderer)
}
data->fenceValue++;
#if defined(__XBOXONE__) || defined(__XBOXSERIES__)
data->currentBackBufferIndex++;
data->currentBackBufferIndex %= SDL_D3D12_NUM_BUFFERS;
#else
data->currentBackBufferIndex = D3D_CALL(data->swapChain, GetCurrentBackBufferIndex);
#endif
/* Reset the command allocator and command list, and transition back to render target */
D3D12_ResetCommandList(data);
@@ -2932,6 +2990,10 @@ D3D12_RenderPresent(SDL_Renderer * renderer)
D3D12_RESOURCE_STATE_PRESENT,
D3D12_RESOURCE_STATE_RENDER_TARGET
);
#if defined(__XBOXONE__) || defined(__XBOXSERIES__)
D3D12_XBOX_StartFrame(data->d3dDevice, &data->frameToken);
#endif
}
}

View File

@@ -0,0 +1,27 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2022 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"
#if SDL_VIDEO_RENDER_D3D12 && !SDL_RENDER_DISABLED && (defined(__XBOXONE__) || defined(__XBOXSERIES__))
#include "SDL_render_d3d12_xbox.h"
#error "This is a placeholder Xbox file, as the real one is under NDA. See README-gdk.md for more info."
#endif

View File

@@ -0,0 +1,22 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2022 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.
*/
#error "This is a placeholder Xbox file, as the real one is under NDA. See README-gdk.md for more info."

View File

@@ -20,11 +20,10 @@
*/
#include "../../SDL_internal.h"
#if SDL_VIDEO_RENDER_D3D12 && !SDL_RENDER_DISABLED
#if SDL_VIDEO_RENDER_D3D12 && !SDL_RENDER_DISABLED && !defined(__XBOXONE__) && !defined(__XBOXSERIES__)
#include "SDL_stdinc.h"
#define COBJMACROS
#include "../../core/windows/SDL_windows.h"
#include <d3d12.h>
@@ -59,11 +58,6 @@
xxd --include <FILE>
*/
#if WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP
#define D3D12_USE_SHADER_MODEL_4_0_level_9_3
#else
#define D3D12_USE_SHADER_MODEL_4_0_level_9_1
#endif
/* The color-only-rendering pixel shader:
@@ -6962,6 +6956,6 @@ void D3D12_GetRootSignatureData(D3D12_RootSignature rootSig, D3D12_SHADER_BYTECO
outBytecode->BytecodeLength = D3D12_rootsigs[rootSig].rs_shader_size;
}
#endif /* SDL_VIDEO_RENDER_D3D12 && !SDL_RENDER_DISABLED */
#endif /* SDL_VIDEO_RENDER_D3D12 && !SDL_RENDER_DISABLED && !defined(__XBOXONE__) && !defined(__XBOXSERIES__) */
/* vi: set ts=4 sw=4 expandtab: */

View File

@@ -0,0 +1,29 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2022 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"
#if SDL_VIDEO_RENDER_D3D12 && !SDL_RENDER_DISABLED && defined(__XBOXONE__)
#error "This is a placeholder Xbox file, as the real one is under NDA. See README-gdk.md for more info."
#endif /* SDL_VIDEO_RENDER_D3D12 && !SDL_RENDER_DISABLED && defined(__XBOXONE__) */
/* vi: set ts=4 sw=4 expandtab: */

View File

@@ -0,0 +1,29 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2022 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"
#if SDL_VIDEO_RENDER_D3D12 && !SDL_RENDER_DISABLED && defined(__XBOXSERIES__)
#error "This is a placeholder Xbox file, as the real one is under NDA. See README-gdk.md for more info."
#endif /* SDL_VIDEO_RENDER_D3D12 && !SDL_RENDER_DISABLED && defined(__XBOXSERIES__) */
/* vi: set ts=4 sw=4 expandtab: */

View File

@@ -487,7 +487,9 @@ DEFAULT_MMAP_THRESHOLD default: 256K
#endif /* WIN32 */
#ifdef WIN32
#ifndef WIN32_LEAN_AND_MEAN
#define WIN32_LEAN_AND_MEAN
#endif
#include <windows.h>
#define HAVE_MMAP 1
#define HAVE_MORECORE 0

View File

@@ -1196,7 +1196,7 @@ SDLTest_CommonInit(SDLTest_CommonState * state)
}
}
#if SDL_VIDEO_DRIVER_WINDOWS
#if SDL_VIDEO_DRIVER_WINDOWS && !defined(__XBOXONE__) && !defined(__XBOXSERIES__)
/* Print the D3D9 adapter index */
adapterIndex = SDL_Direct3D9GetAdapterIndex( i );
SDL_Log("D3D9 Adapter Index: %d", adapterIndex);

View File

@@ -28,6 +28,11 @@
#include "SDL_thread.h"
#include "SDL_thread_c.h"
/* Set up for C function definitions, even when using C++ */
#ifdef __cplusplus
extern "C" {
#endif
/* This function creates a thread, passing args to SDL_RunThread(),
saves a system-dependent thread id in thread->id, and returns 0
on success.
@@ -65,6 +70,11 @@ extern SDL_Thread *
SDL_CreateThreadInternal(int (SDLCALL * fn) (void *), const char *name,
const size_t stacksize, void *data);
/* Ends C function definitions when using C++ */
#ifdef __cplusplus
}
#endif
#endif /* SDL_systhread_h_ */
/* vi: set ts=4 sw=4 expandtab: */

View File

@@ -41,7 +41,7 @@ static LARGE_INTEGER ticks_per_second;
static void
SDL_SetSystemTimerResolution(const UINT uPeriod)
{
#ifndef __WINRT__
#if !defined(__WINRT__) && !defined(__XBOXONE__) && !defined(__XBOXSERIES__)
static UINT timer_period = 0;
if (uPeriod != timer_period) {

View File

@@ -4390,7 +4390,7 @@ SDL_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonid)
retval = 0;
}
#endif
#if SDL_VIDEO_DRIVER_WINDOWS
#if SDL_VIDEO_DRIVER_WINDOWS && !defined(__XBOXONE__) && !defined(__XBOXSERIES__)
if (retval == -1 &&
SDL_MessageboxValidForDriver(messageboxdata, SDL_SYSWM_WINDOWS) &&
WIN_ShowMessageBox(messageboxdata, buttonid) == 0) {

View File

@@ -20,7 +20,7 @@
*/
#include "../../SDL_internal.h"
#if SDL_VIDEO_DRIVER_WINDOWS
#if SDL_VIDEO_DRIVER_WINDOWS && !defined(__XBOXONE__) && !defined(__XBOXSERIES__)
#include "SDL_windowsvideo.h"
#include "SDL_windowswindow.h"

View File

@@ -265,6 +265,7 @@ WindowsScanCodeToSDLScanCode(LPARAM lParam, WPARAM wParam)
return code;
}
#if !defined(__XBOXONE__) && !defined(__XBOXSERIES__)
static SDL_bool
WIN_ShouldIgnoreFocusClick()
{
@@ -460,6 +461,7 @@ WIN_UpdateFocus(SDL_Window *window, SDL_bool expect_focus)
data->in_window_deactivation = SDL_FALSE;
}
}
#endif /*!defined(__XBOXONE__) && !defined(__XBOXSERIES__)*/
static BOOL
WIN_ConvertUTF32toUTF8(UINT32 codepoint, char * text)
@@ -502,6 +504,7 @@ ShouldGenerateWindowCloseOnAltF4(void)
return !SDL_GetHintBoolean(SDL_HINT_WINDOWS_NO_CLOSE_ON_ALT_F4, SDL_FALSE);
}
#if !defined(__XBOXONE__) && !defined(__XBOXSERIES__)
/* We want to generate mouse events from mouse and pen, and touch events from touchscreens */
#define MI_WP_SIGNATURE 0xFF515700
#define MI_WP_SIGNATURE_MASK 0xFFFFFF00
@@ -532,6 +535,7 @@ static SDL_MOUSE_EVENT_SOURCE GetMouseMessageSource()
}
return SDL_MOUSE_EVENT_SOURCE_MOUSE;
}
#endif /*!defined(__XBOXONE__) && !defined(__XBOXSERIES__)*/
static SDL_WindowData *
WIN_GetWindowDataFromHWND(HWND hwnd)
@@ -550,6 +554,7 @@ WIN_GetWindowDataFromHWND(HWND hwnd)
return NULL;
}
#if !defined(__XBOXONE__) && !defined(__XBOXSERIES__)
LRESULT CALLBACK
WIN_KeyboardHookProc(int nCode, WPARAM wParam, LPARAM lParam)
{
@@ -635,6 +640,7 @@ static void WIN_CheckICMProfileChanged(SDL_Window* window)
}
}
}
#endif /*!defined(__XBOXONE__) && !defined(__XBOXSERIES__)*/
LRESULT CALLBACK
WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
@@ -657,10 +663,12 @@ WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
/* Get the window data for the window */
data = WIN_GetWindowDataFromHWND(hwnd);
#if !defined(__XBOXONE__) && !defined(__XBOXSERIES__)
if (!data) {
/* Fallback */
data = (SDL_WindowData *) GetProp(hwnd, TEXT("SDL_WindowData"));
}
#endif
if (!data) {
return CallWindowProc(DefWindowProc, hwnd, msg, wParam, lParam);
}
@@ -677,8 +685,10 @@ WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
}
#endif /* WMMSG_DEBUG */
#if !defined(__XBOXONE__) && !defined(__XBOXSERIES__)
if (IME_HandleMessage(hwnd, msg, wParam, &lParam, data->videodata))
return 0;
#endif
switch (msg) {
@@ -692,6 +702,7 @@ WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
}
break;
#if !defined(__XBOXONE__) && !defined(__XBOXSERIES__)
case WM_NCACTIVATE:
{
/* Don't immediately clip the cursor in case we're clicking minimize/maximize buttons */
@@ -941,6 +952,7 @@ WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
returnCode = 0;
break;
#endif /*!defined(__XBOXONE__) && !defined(__XBOXSERIES__)*/
case WM_KEYDOWN:
case WM_SYSKEYDOWN:
@@ -1022,6 +1034,7 @@ WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
returnCode = 0;
break;
#if !defined(__XBOXONE__) && !defined(__XBOXSERIES__)
#ifdef WM_INPUTLANGCHANGE
case WM_INPUTLANGCHANGE:
{
@@ -1621,6 +1634,7 @@ WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
return 0;
}
break;
#endif /*!defined(__XBOXONE__) && !defined(__XBOXSERIES__)*/
}
/* If there's a window proc, assume it's going to handle messages */
@@ -1633,6 +1647,7 @@ WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
}
}
#if !defined(__XBOXONE__) && !defined(__XBOXSERIES__)
static void WIN_UpdateClipCursorForWindows()
{
SDL_VideoDevice *_this = SDL_GetVideoDevice();
@@ -1679,6 +1694,7 @@ static void WIN_UpdateMouseCapture()
}
}
}
#endif /*!defined(__XBOXONE__) && !defined(__XBOXSERIES__)*/
/* A message hook called before TranslateMessage() */
static SDL_WindowsMessageHook g_WindowsMessageHook = NULL;
@@ -1736,11 +1752,13 @@ WIN_SendWakeupEvent(_THIS, SDL_Window *window)
void
WIN_PumpEvents(_THIS)
{
const Uint8 *keystate;
MSG msg;
DWORD end_ticks = GetTickCount() + 1;
int new_messages = 0;
#if !defined(__XBOXONE__) && !defined(__XBOXSERIES__)
const Uint8 *keystate;
SDL_Window *focusWindow;
#endif
if (g_WindowsEnableMessageLoop) {
while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) {
@@ -1748,6 +1766,7 @@ WIN_PumpEvents(_THIS)
g_WindowsMessageHook(g_WindowsMessageHookData, msg.hwnd, msg.message, msg.wParam, msg.lParam);
}
#if !defined(__XBOXONE__) && !defined(__XBOXSERIES__)
/* Don't dispatch any mouse motion queued prior to or including the last mouse warp */
if (msg.message == WM_MOUSEMOVE && SDL_last_warp_time) {
if (!SDL_TICKS_PASSED(msg.time, (SDL_last_warp_time + 1))) {
@@ -1757,6 +1776,7 @@ WIN_PumpEvents(_THIS)
/* This mouse message happened after the warp */
SDL_last_warp_time = 0;
}
#endif !defined(__XBOXONE__) && !defined(__XBOXSERIES__)
/* Always translate the message in case it's a non-SDL window (e.g. with Qt integration) */
TranslateMessage(&msg);
@@ -1777,6 +1797,7 @@ WIN_PumpEvents(_THIS)
}
}
#if !defined(__XBOXONE__) && !defined(__XBOXSERIES__)
/* Windows loses a shift KEYUP event when you have both pressed at once and let go of one.
You won't get a KEYUP until both are released, and that keyup will only be for the second
key you released. Take heroic measures and check the keystate as of the last handled event,
@@ -1807,6 +1828,7 @@ WIN_PumpEvents(_THIS)
/* Update mouse capture */
WIN_UpdateMouseCapture();
#endif /*!defined(__XBOXONE__) && !defined(__XBOXSERIES__)*/
#ifdef __GDK__
GDK_DispatchTaskQueue();
@@ -1821,8 +1843,10 @@ HINSTANCE SDL_Instance = NULL;
static void WIN_CleanRegisterApp(WNDCLASSEX wcex)
{
#if !defined(__XBOXONE__) && !defined(__XBOXSERIES__)
if (wcex.hIcon) DestroyIcon(wcex.hIcon);
if (wcex.hIconSm) DestroyIcon(wcex.hIconSm);
#endif
SDL_free(SDL_Appname);
SDL_Appname = NULL;
}
@@ -1831,9 +1855,11 @@ static void WIN_CleanRegisterApp(WNDCLASSEX wcex)
int
SDL_RegisterApp(const char *name, Uint32 style, void *hInst)
{
const char *hint;
WNDCLASSEX wcex;
#if !defined(__XBOXONE__) && !defined(__XBOXSERIES__)
const char *hint;
TCHAR path[MAX_PATH];
#endif
/* Only do this once... */
if (app_registered) {
@@ -1865,6 +1891,7 @@ SDL_RegisterApp(const char *name, Uint32 style, void *hInst)
wcex.cbClsExtra = 0;
wcex.cbWndExtra = 0;
#if !defined(__XBOXONE__) && !defined(__XBOXSERIES__)
hint = SDL_GetHint(SDL_HINT_WINDOWS_INTRESOURCE_ICON);
if (hint && *hint) {
wcex.hIcon = LoadIcon(SDL_Instance, MAKEINTRESOURCE(SDL_atoi(hint)));
@@ -1878,6 +1905,7 @@ SDL_RegisterApp(const char *name, Uint32 style, void *hInst)
GetModuleFileName(SDL_Instance, path, MAX_PATH);
ExtractIconEx(path, 0, &wcex.hIcon, &wcex.hIconSm, 1);
}
#endif /*!defined(__XBOXONE__) && !defined(__XBOXSERIES__)*/
if (!RegisterClassEx(&wcex)) {
WIN_CleanRegisterApp(wcex);
@@ -1904,9 +1932,11 @@ SDL_UnregisterApp()
wcex.hIcon = NULL;
wcex.hIconSm = NULL;
/* Check for any registered window classes. */
#if !defined(__XBOXONE__) && !defined(__XBOXSERIES__)
if (GetClassInfoEx(SDL_Instance, SDL_Appname, &wcex)) {
UnregisterClass(SDL_Appname, SDL_Instance);
}
#endif
WIN_CleanRegisterApp(wcex);
}
}

View File

@@ -20,7 +20,7 @@
*/
#include "../../SDL_internal.h"
#if SDL_VIDEO_DRIVER_WINDOWS
#if SDL_VIDEO_DRIVER_WINDOWS && !defined(__XBOXONE__) && !defined(__XBOXSERIES__)
#include "SDL_windowsvideo.h"

View File

@@ -20,7 +20,7 @@
*/
#include "../../SDL_internal.h"
#if SDL_VIDEO_DRIVER_WINDOWS
#if SDL_VIDEO_DRIVER_WINDOWS && !defined(__XBOXONE__) && !defined(__XBOXSERIES__)
#include "SDL_windowsvideo.h"
#include "SDL_hints.h"

View File

@@ -20,7 +20,7 @@
*/
#include "../../SDL_internal.h"
#if SDL_VIDEO_DRIVER_WINDOWS
#if SDL_VIDEO_DRIVER_WINDOWS && !defined(__XBOXONE__) && !defined(__XBOXSERIES__)
#ifdef HAVE_LIMITS_H
#include <limits.h>

View File

@@ -20,7 +20,7 @@
*/
#include "../../SDL_internal.h"
#if SDL_VIDEO_DRIVER_WINDOWS
#if SDL_VIDEO_DRIVER_WINDOWS && !defined(__XBOXONE__) && !defined(__XBOXSERIES__)
#include "SDL_windowsvideo.h"
#include "../../events/SDL_displayevents_c.h"

View File

@@ -20,7 +20,7 @@
*/
#include "../../SDL_internal.h"
#if SDL_VIDEO_DRIVER_WINDOWS
#if SDL_VIDEO_DRIVER_WINDOWS && !defined(__XBOXONE__) && !defined(__XBOXSERIES__)
#include "SDL_windowsvideo.h"

View File

@@ -20,7 +20,7 @@
*/
#include "../../SDL_internal.h"
#if SDL_VIDEO_DRIVER_WINDOWS
#if SDL_VIDEO_DRIVER_WINDOWS && !defined(__XBOXONE__) && !defined(__XBOXSERIES__)
#include "SDL_loadso.h"
#include "SDL_windowsvideo.h"

View File

@@ -20,7 +20,7 @@
*/
#include "../../SDL_internal.h"
#if SDL_VIDEO_DRIVER_WINDOWS && SDL_VIDEO_OPENGL_EGL
#if SDL_VIDEO_DRIVER_WINDOWS && SDL_VIDEO_OPENGL_EGL && !defined(__XBOXONE__) && !defined(__XBOXSERIES__)
#include "SDL_windowsvideo.h"
#include "SDL_windowsopengles.h"

View File

@@ -20,7 +20,7 @@
*/
#include "../../SDL_internal.h"
#if SDL_VIDEO_DRIVER_WINDOWS
#if SDL_VIDEO_DRIVER_WINDOWS && !defined(__XBOXONE__) && !defined(__XBOXSERIES__)
#include "SDL_windowsshape.h"
#include "SDL_windowsvideo.h"

View File

@@ -65,6 +65,7 @@ UpdateWindowFrameUsableWhileCursorHidden(void *userdata, const char *name, const
}
}
#if !defined(__XBOXONE__) && !defined(__XBOXSERIES__)
static void WIN_SuspendScreenSaver(_THIS)
{
if (_this->suspend_screensaver) {
@@ -73,6 +74,11 @@ static void WIN_SuspendScreenSaver(_THIS)
SetThreadExecutionState(ES_CONTINUOUS);
}
}
#endif
#if defined(__XBOXONE__) || defined(__XBOXSERIES__)
extern void D3D12_XBOX_GetResolution(Uint32 *width, Uint32 *height);
#endif
/* Windows driver bootstrap functions */
@@ -83,12 +89,14 @@ WIN_DeleteDevice(SDL_VideoDevice * device)
SDL_VideoData *data = (SDL_VideoData *) device->driverdata;
SDL_UnregisterApp();
#if !defined(__XBOXONE__) && !defined(__XBOXSERIES__)
if (data->userDLL) {
SDL_UnloadObject(data->userDLL);
}
if (data->shcoreDLL) {
SDL_UnloadObject(data->shcoreDLL);
}
#endif
if (device->wakeup_lock) {
SDL_DestroyMutex(device->wakeup_lock);
}
@@ -119,6 +127,7 @@ WIN_CreateDevice(int devindex)
device->driverdata = data;
device->wakeup_lock = SDL_CreateMutex();
#if !defined(__XBOXONE__) && !defined(__XBOXSERIES__)
data->userDLL = SDL_LoadObject("USER32.DLL");
if (data->userDLL) {
data->CloseTouchInputHandle = (BOOL (WINAPI *)(HTOUCHINPUT)) SDL_LoadFunction(data->userDLL, "CloseTouchInputHandle");
@@ -145,19 +154,24 @@ WIN_CreateDevice(int devindex)
} else {
SDL_ClearError();
}
#endif /* #if !defined(__XBOXONE__) && !defined(__XBOXSERIES__) */
/* Set the function pointers */
device->VideoInit = WIN_VideoInit;
device->VideoQuit = WIN_VideoQuit;
#if !defined(__XBOXONE__) && !defined(__XBOXSERIES__)
device->GetDisplayBounds = WIN_GetDisplayBounds;
device->GetDisplayUsableBounds = WIN_GetDisplayUsableBounds;
device->GetDisplayDPI = WIN_GetDisplayDPI;
device->GetDisplayModes = WIN_GetDisplayModes;
device->SetDisplayMode = WIN_SetDisplayMode;
#endif
device->PumpEvents = WIN_PumpEvents;
device->WaitEventTimeout = WIN_WaitEventTimeout;
#if !defined(__XBOXONE__) && !defined(__XBOXSERIES__)
device->SendWakeupEvent = WIN_SendWakeupEvent;
device->SuspendScreenSaver = WIN_SuspendScreenSaver;
#endif
device->CreateSDLWindow = WIN_CreateWindow;
device->CreateSDLWindowFrom = WIN_CreateWindowFrom;
@@ -177,14 +191,17 @@ WIN_CreateDevice(int devindex)
device->SetWindowResizable = WIN_SetWindowResizable;
device->SetWindowAlwaysOnTop = WIN_SetWindowAlwaysOnTop;
device->SetWindowFullscreen = WIN_SetWindowFullscreen;
#if !defined(__XBOXONE__) && !defined(__XBOXSERIES__)
device->SetWindowGammaRamp = WIN_SetWindowGammaRamp;
device->GetWindowICCProfile = WIN_GetWindowICCProfile;
device->GetWindowGammaRamp = WIN_GetWindowGammaRamp;
device->SetWindowMouseRect = WIN_SetWindowMouseRect;
device->SetWindowMouseGrab = WIN_SetWindowMouseGrab;
device->SetWindowKeyboardGrab = WIN_SetWindowKeyboardGrab;
#endif
device->DestroyWindow = WIN_DestroyWindow;
device->GetWindowWMInfo = WIN_GetWindowWMInfo;
#if !defined(__XBOXONE__) && !defined(__XBOXSERIES__)
device->CreateWindowFramebuffer = WIN_CreateWindowFramebuffer;
device->UpdateWindowFramebuffer = WIN_UpdateWindowFramebuffer;
device->DestroyWindowFramebuffer = WIN_DestroyWindowFramebuffer;
@@ -196,6 +213,7 @@ WIN_CreateDevice(int devindex)
device->shape_driver.CreateShaper = Win32_CreateShaper;
device->shape_driver.SetWindowShape = Win32_SetWindowShape;
device->shape_driver.ResizeWindowShape = Win32_ResizeWindowShape;
#endif
#if SDL_VIDEO_OPENGL_WGL
device->GL_LoadLibrary = WIN_GL_LoadLibrary;
@@ -229,6 +247,7 @@ WIN_CreateDevice(int devindex)
device->Vulkan_GetDrawableSize = WIN_GL_GetDrawableSize;
#endif
#if !defined(__XBOXONE__) && !defined(__XBOXSERIES__)
device->StartTextInput = WIN_StartTextInput;
device->StopTextInput = WIN_StopTextInput;
device->SetTextInputRect = WIN_SetTextInputRect;
@@ -238,6 +257,7 @@ WIN_CreateDevice(int devindex)
device->SetClipboardText = WIN_SetClipboardText;
device->GetClipboardText = WIN_GetClipboardText;
device->HasClipboardText = WIN_HasClipboardText;
#endif
device->free = WIN_DeleteDevice;
@@ -252,6 +272,7 @@ VideoBootStrap WINDOWS_bootstrap = {
static BOOL
WIN_DeclareDPIAwareUnaware(_THIS)
{
#if !defined(__XBOXONE__) && !defined(__XBOXSERIES__)
SDL_VideoData* data = (SDL_VideoData*)_this->driverdata;
if (data->SetProcessDpiAwarenessContext) {
@@ -260,12 +281,14 @@ WIN_DeclareDPIAwareUnaware(_THIS)
/* Windows 8.1 */
return SUCCEEDED(data->SetProcessDpiAwareness(PROCESS_DPI_UNAWARE));
}
#endif
return FALSE;
}
static BOOL
WIN_DeclareDPIAwareSystem(_THIS)
{
#if !defined(__XBOXONE__) && !defined(__XBOXSERIES__)
SDL_VideoData* data = (SDL_VideoData*)_this->driverdata;
if (data->SetProcessDpiAwarenessContext) {
@@ -278,12 +301,14 @@ WIN_DeclareDPIAwareSystem(_THIS)
/* Windows Vista */
return data->SetProcessDPIAware();
}
#endif
return FALSE;
}
static BOOL
WIN_DeclareDPIAwarePerMonitor(_THIS)
{
#if !defined(__XBOXONE__) && !defined(__XBOXSERIES__)
SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
if (data->SetProcessDpiAwarenessContext) {
@@ -296,12 +321,16 @@ WIN_DeclareDPIAwarePerMonitor(_THIS)
/* Older OS: fall back to system DPI aware */
return WIN_DeclareDPIAwareSystem(_this);
}
#endif
return FALSE;
}
static BOOL
WIN_DeclareDPIAwarePerMonitorV2(_THIS)
{
#if defined(__XBOXONE__) || defined(__XBOXSERIES__)
return FALSE;
#else
SDL_VideoData* data = (SDL_VideoData*)_this->driverdata;
/* Declare DPI aware (may have been done in external code or a manifest, as well) */
@@ -332,6 +361,7 @@ WIN_DeclareDPIAwarePerMonitorV2(_THIS)
/* Older OS: fall back to per-monitor (or system) */
return WIN_DeclareDPIAwarePerMonitor(_this);
}
#endif
}
#ifdef HIGHDPI_DEBUG
@@ -402,17 +432,38 @@ WIN_VideoInit(_THIS)
SDL_Log("DPI awareness: %s", WIN_GetDPIAwareness(_this));
#endif
#if defined(__XBOXONE__) || defined(__XBOXSERIES__)
/* For Xbox, we just need to create the single display */
{
SDL_VideoDisplay display;
SDL_DisplayMode current_mode;
SDL_zero(current_mode);
D3D12_XBOX_GetResolution(&current_mode.w, &current_mode.h);
current_mode.refresh_rate = 60;
current_mode.format = SDL_PIXELFORMAT_ARGB8888;
SDL_zero(display);
display.desktop_mode = current_mode;
display.current_mode = current_mode;
SDL_AddVideoDisplay(&display, SDL_FALSE);
}
#else /*!defined(__XBOXONE__) && !defined(__XBOXSERIES__)*/
if (WIN_InitModes(_this) < 0) {
return -1;
}
WIN_InitKeyboard(_this);
WIN_InitMouse(_this);
#endif
SDL_AddHintCallback(SDL_HINT_WINDOWS_ENABLE_MESSAGELOOP, UpdateWindowsEnableMessageLoop, NULL);
SDL_AddHintCallback(SDL_HINT_WINDOW_FRAME_USABLE_WHILE_CURSOR_HIDDEN, UpdateWindowFrameUsableWhileCursorHidden, NULL);
#if !defined(__XBOXONE__) && !defined(__XBOXSERIES__)
data->_SDL_WAKEUP = RegisterWindowMessageA("_SDL_WAKEUP");
#endif
return 0;
}
@@ -420,12 +471,15 @@ WIN_VideoInit(_THIS)
void
WIN_VideoQuit(_THIS)
{
#if !defined(__XBOXONE__) && !defined(__XBOXSERIES__)
WIN_QuitModes(_this);
WIN_QuitKeyboard(_this);
WIN_QuitMouse(_this);
#endif
}
#if !defined(__XBOXONE__) && !defined(__XBOXSERIES__)
#define D3D_DEBUG_INFO
#include <d3d9.h>
@@ -526,6 +580,7 @@ SDL_Direct3D9GetAdapterIndex(int displayIndex)
return adapterIndex;
}
}
#endif /* !defined(__XBOXONE__) && !defined(__XBOXSERIES__) */
#if HAVE_DXGI_H
#define CINTERFACE
@@ -640,6 +695,7 @@ SDL_DXGIGetOutputInfo(int displayIndex, int *adapterIndex, int *outputIndex)
SDL_bool
WIN_IsPerMonitorV2DPIAware(_THIS)
{
#if !defined(__XBOXONE__) && !defined(__XBOXSERIES__)
SDL_VideoData* data = (SDL_VideoData*) _this->driverdata;
if (data->AreDpiAwarenessContextsEqual && data->GetThreadDpiAwarenessContext) {
@@ -647,6 +703,7 @@ WIN_IsPerMonitorV2DPIAware(_THIS)
return (SDL_bool)data->AreDpiAwarenessContextsEqual(DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2,
data->GetThreadDpiAwarenessContext());
}
#endif
return SDL_FALSE;
}

View File

@@ -27,7 +27,7 @@
#include "../SDL_sysvideo.h"
#if defined(_MSC_VER) && (_MSC_VER >= 1500)
#if defined(_MSC_VER) && (_MSC_VER >= 1500) && !defined(__XBOXONE__) && !defined(__XBOXSERIES__)
#include <msctf.h>
#else
#include "SDL_msctf.h"
@@ -41,11 +41,15 @@
#include "SDL_windowsclipboard.h"
#include "SDL_windowsevents.h"
#if !defined(__XBOXONE__) && !defined(__XBOXSERIES__)
#include "SDL_windowskeyboard.h"
#include "SDL_windowsmodes.h"
#include "SDL_windowsmouse.h"
#include "SDL_windowsopengl.h"
#include "SDL_windowsopengles.h"
#endif
#include "SDL_windowswindow.h"
#include "SDL_events.h"
#include "SDL_loadso.h"
@@ -330,6 +334,7 @@ typedef struct
void *data;
} TSFSink;
#ifndef SDL_DISABLE_WINDOWS_IME
/* Definition from Win98DDK version of IMM.H */
typedef struct tagINPUTCONTEXT2 {
HWND hWnd;
@@ -353,6 +358,7 @@ typedef struct tagINPUTCONTEXT2 {
DWORD fdwInit;
DWORD dwReserve[3];
} INPUTCONTEXT2, *PINPUTCONTEXT2, NEAR *NPINPUTCONTEXT2, FAR *LPINPUTCONTEXT2;
#endif /* !SDL_DISABLE_WINDOWS_IME */
/* Private display data */
@@ -362,6 +368,7 @@ typedef struct SDL_VideoData
DWORD clipboard_count;
#if !defined(__XBOXONE__) && !defined(__XBOXSERIES__) /* Xbox doesn't support user32/shcore*/
/* Touch input functions */
void* userDLL;
BOOL (WINAPI *CloseTouchInputHandle)( HTOUCHINPUT );
@@ -384,9 +391,11 @@ typedef struct SDL_VideoData
UINT *dpiX,
UINT *dpiY );
HRESULT (WINAPI *SetProcessDpiAwareness)(PROCESS_DPI_AWARENESS dpiAwareness);
#endif /*!defined(__XBOXONE__) && !defined(__XBOXSERIES__)*/
SDL_bool dpi_scaling_enabled;
#ifndef SDL_DISABLE_WINDOWS_IME
SDL_bool ime_com_initialized;
struct ITfThreadMgr *ime_threadmgr;
SDL_bool ime_initialized;
@@ -435,6 +444,7 @@ typedef struct SDL_VideoData
TSFSink *ime_uielemsink;
TSFSink *ime_ippasink;
LONG ime_uicontext;
#endif /* !SDL_DISABLE_WINDOWS_IME */
BYTE pre_hook_key_state[256];
UINT _SDL_WAKEUP;

View File

@@ -125,8 +125,10 @@ WIN_AdjustWindowRectWithStyle(SDL_Window *window, DWORD style, BOOL menu, int *x
{
SDL_VideoData* videodata = SDL_GetVideoDevice() ? SDL_GetVideoDevice()->driverdata : NULL;
RECT rect;
int dpi;
int dpi = 96;
#if !defined(__XBOXONE__) && !defined(__XBOXSERIES__)
UINT frame_dpi;
#endif
/* Client rect, in SDL screen coordinates */
*x = (use_current ? window->x : window->windowed.x);
@@ -135,7 +137,9 @@ WIN_AdjustWindowRectWithStyle(SDL_Window *window, DWORD style, BOOL menu, int *x
*height = (use_current ? window->h : window->windowed.h);
/* Convert client rect from SDL coordinates to pixels (no-op if DPI scaling not enabled) */
#if !defined(__XBOXONE__) && !defined(__XBOXSERIES__)
WIN_ScreenPointFromSDL(x, y, &dpi);
#endif
/* Note, use the guessed DPI returned from WIN_ScreenPointFromSDL rather than the cached one in
data->scaling_dpi.
@@ -158,6 +162,9 @@ WIN_AdjustWindowRectWithStyle(SDL_Window *window, DWORD style, BOOL menu, int *x
expanding the window client area to the previous window + chrome size, so shouldn't need to adjust the window size for the set styles.
*/
if (!(window->flags & SDL_WINDOW_BORDERLESS)) {
#if defined(__XBOXONE__) || defined(__XBOXSERIES__)
AdjustWindowRectEx(&rect, style, menu, 0);
#else
if (WIN_IsPerMonitorV2DPIAware(SDL_GetVideoDevice())) {
/* With per-monitor v2, the window border/titlebar size depend on the DPI, so we need to call AdjustWindowRectExForDpi instead of
AdjustWindowRectEx. */
@@ -180,7 +187,8 @@ WIN_AdjustWindowRectWithStyle(SDL_Window *window, DWORD style, BOOL menu, int *x
videodata->AdjustWindowRectExForDpi(&rect, style, menu, 0, frame_dpi);
} else {
AdjustWindowRectEx(&rect, style, menu, 0);
}
}
#endif
}
/* Final rect in Windows screen space, including the frame */
@@ -208,7 +216,11 @@ WIN_AdjustWindowRect(SDL_Window *window, int *x, int *y, int *width, int *height
BOOL menu;
style = GetWindowLong(hwnd, GWL_STYLE);
#if defined(__XBOXONE__) || defined(__XBOXSERIES__)
menu = FALSE;
#else
menu = (style & WS_CHILDWINDOW) ? FALSE : (GetMenu(hwnd) != NULL);
#endif
WIN_AdjustWindowRectWithStyle(window, style, menu, x, y, width, height, use_current);
}
@@ -245,6 +257,9 @@ WIN_MouseRelativeModeCenterChanged(void *userdata, const char *name, const char
static int
WIN_GetScalingDPIForHWND(const SDL_VideoData *videodata, HWND hwnd)
{
#if defined(__XBOXONE__) || defined(__XBOXSERIES__)
return 96;
#else
/* DPI scaling not requested? */
if (!videodata->dpi_scaling_enabled) {
return 96;
@@ -277,6 +292,7 @@ WIN_GetScalingDPIForHWND(const SDL_VideoData *videodata, HWND hwnd)
}
return 96;
}
#endif
}
static int
@@ -293,7 +309,9 @@ SetupWindowData(_THIS, SDL_Window * window, HWND hwnd, HWND parent, SDL_bool cre
data->window = window;
data->hwnd = hwnd;
data->parent = parent;
#if !defined(__XBOXONE__) && !defined(__XBOXSERIES__)
data->hdc = GetDC(hwnd);
#endif
data->hinstance = (HINSTANCE) GetWindowLongPtr(hwnd, GWLP_HINSTANCE);
data->created = created;
data->high_surrogate = 0;
@@ -311,12 +329,14 @@ SetupWindowData(_THIS, SDL_Window * window, HWND hwnd, HWND parent, SDL_bool cre
window->driverdata = data;
#if !defined(__XBOXONE__) && !defined(__XBOXSERIES__)
/* Associate the data with the window */
if (!SetProp(hwnd, TEXT("SDL_WindowData"), data)) {
ReleaseDC(hwnd, data->hdc);
SDL_free(data);
return WIN_SetError("SetProp() failed");
}
#endif
/* Set up the window proc function */
#ifdef GWLP_WNDPROC
@@ -357,6 +377,7 @@ SetupWindowData(_THIS, SDL_Window * window, HWND hwnd, HWND parent, SDL_bool cre
}
}
}
#if !defined(__XBOXONE__) && !defined(__XBOXSERIES__)
{
POINT point;
point.x = 0;
@@ -369,6 +390,7 @@ SetupWindowData(_THIS, SDL_Window * window, HWND hwnd, HWND parent, SDL_bool cre
window->y = y;
}
}
#endif
{
DWORD style = GetWindowLong(hwnd, GWL_STYLE);
if (style & WS_VISIBLE) {
@@ -403,16 +425,22 @@ SetupWindowData(_THIS, SDL_Window * window, HWND hwnd, HWND parent, SDL_bool cre
window->flags &= ~SDL_WINDOW_MINIMIZED;
}
}
#if defined(__XBOXONE__) || defined(__XBOXSERIES__)
window->flags |= SDL_WINDOW_INPUT_FOCUS;
#else
if (GetFocus() == hwnd) {
window->flags |= SDL_WINDOW_INPUT_FOCUS;
SDL_SetKeyboardFocus(window);
WIN_UpdateClipCursor(window);
}
#endif
#if !defined(__XBOXONE__) && !defined(__XBOXSERIES__)
/* Enable multi-touch */
if (videodata->RegisterTouchWindow) {
videodata->RegisterTouchWindow(hwnd, (TWF_FINETOUCH|TWF_WANTPALM));
}
#endif
/* Force the SDL_WINDOW_ALLOW_HIGHDPI window flag if we are doing DPI scaling */
if (videodata->dpi_scaling_enabled) {
@@ -432,11 +460,13 @@ static void CleanupWindowData(_THIS, SDL_Window * window)
if (data) {
SDL_DelHintCallback(SDL_HINT_MOUSE_RELATIVE_MODE_CENTER, WIN_MouseRelativeModeCenterChanged, data);
#if !defined(__XBOXONE__) && !defined(__XBOXSERIES__)
if (data->keyboard_hook) {
UnhookWindowsHookEx(data->keyboard_hook);
}
ReleaseDC(data->hwnd, data->hdc);
RemoveProp(data->hwnd, TEXT("SDL_WindowData"));
#endif
if (data->created) {
DestroyWindow(data->hwnd);
if (data->parent) {
@@ -538,6 +568,9 @@ WIN_CreateWindow(_THIS, SDL_Window * window)
int
WIN_CreateWindowFrom(_THIS, SDL_Window * window, const void *data)
{
#if defined(__XBOXONE__) || defined(__XBOXSERIES__)
return -1;
#else
HWND hwnd = (HWND) data;
LPTSTR title;
int titleLen;
@@ -589,20 +622,24 @@ WIN_CreateWindowFrom(_THIS, SDL_Window * window, const void *data)
}
#endif
return 0;
#endif /*!defined(__XBOXONE__) && !defined(__XBOXSERIES__)*/
}
void
WIN_SetWindowTitle(_THIS, SDL_Window * window)
{
#if !defined(__XBOXONE__) && !defined(__XBOXSERIES__)
HWND hwnd = ((SDL_WindowData *) window->driverdata)->hwnd;
LPTSTR title = WIN_UTF8ToString(window->title);
SetWindowText(hwnd, title);
SDL_free(title);
#endif
}
void
WIN_SetWindowIcon(_THIS, SDL_Window * window, SDL_Surface * icon)
{
#if !defined(__XBOXONE__) && !defined(__XBOXSERIES__)
HWND hwnd = ((SDL_WindowData *) window->driverdata)->hwnd;
HICON hicon = NULL;
BYTE *icon_bmp;
@@ -654,6 +691,7 @@ WIN_SetWindowIcon(_THIS, SDL_Window * window, SDL_Surface * icon)
/* Set the icon in the task manager (should we do this?) */
SendMessage(hwnd, WM_SETICON, ICON_BIG, (LPARAM) hicon);
#endif
}
void
@@ -674,6 +712,21 @@ WIN_SetWindowSize(_THIS, SDL_Window * window)
int
WIN_GetWindowBordersSize(_THIS, SDL_Window * window, int *top, int *left, int *bottom, int *right)
{
#if defined(__XBOXONE__) || defined(__XBOXSERIES__)
HWND hwnd = ((SDL_WindowData *) window->driverdata)->hwnd;
RECT rcClient;
/* rcClient stores the size of the inner window, while rcWindow stores the outer size relative to the top-left
* screen position; so the top/left values of rcClient are always {0,0} and bottom/right are {height,width} */
GetClientRect(hwnd, &rcClient);
*top = rcClient.top;
*left = rcClient.left;
*bottom = rcClient.bottom;
*right = rcClient.right;
return 0;
#else /*!defined(__XBOXONE__) && !defined(__XBOXSERIES__)*/
HWND hwnd = ((SDL_WindowData *) window->driverdata)->hwnd;
RECT rcClient, rcWindow;
POINT ptDiff;
@@ -712,6 +765,7 @@ WIN_GetWindowBordersSize(_THIS, SDL_Window * window, int *top, int *left, int *b
*right = rcWindow.right - rcClient.right;
return 0;
#endif /*!defined(__XBOXONE__) && !defined(__XBOXSERIES__)*/
}
void
@@ -740,6 +794,7 @@ WIN_HideWindow(_THIS, SDL_Window * window)
void
WIN_RaiseWindow(_THIS, SDL_Window * window)
{
#if !defined(__XBOXONE__) && !defined(__XBOXSERIES__)
/* If desired, raise the window more forcefully.
* Technique taken from http://stackoverflow.com/questions/916259/ .
* Specifically, http://stackoverflow.com/a/34414846 .
@@ -772,6 +827,7 @@ WIN_RaiseWindow(_THIS, SDL_Window * window)
SetFocus(hwnd);
SetActiveWindow(hwnd);
}
#endif /*!defined(__XBOXONE__) && !defined(__XBOXSERIES__)*/
}
void
@@ -850,6 +906,7 @@ WIN_RestoreWindow(_THIS, SDL_Window * window)
void
WIN_SetWindowFullscreen(_THIS, SDL_Window * window, SDL_VideoDisplay * display, SDL_bool fullscreen)
{
#if !defined(__XBOXONE__) && !defined(__XBOXSERIES__)
SDL_DisplayData *displaydata = (SDL_DisplayData *) display->driverdata;
SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
HWND hwnd = data->hwnd;
@@ -932,8 +989,11 @@ WIN_SetWindowFullscreen(_THIS, SDL_Window * window, SDL_VideoDisplay * display,
#ifdef HIGHDPI_DEBUG
SDL_Log("WIN_SetWindowFullscreen: %d finished. Set window to %d,%d, %dx%d", (int)fullscreen, x, y, w, h);
#endif
#endif /*!defined(__XBOXONE__) && !defined(__XBOXSERIES__)*/
}
#if !defined(__XBOXONE__) && !defined(__XBOXSERIES__)
int
WIN_SetWindowGammaRamp(_THIS, SDL_Window * window, const Uint16 * ramp)
{
@@ -1063,6 +1123,7 @@ WIN_SetWindowKeyboardGrab(_THIS, SDL_Window * window, SDL_bool grabbed)
WIN_UngrabKeyboard(window);
}
}
#endif /*!defined(__XBOXONE__) && !defined(__XBOXSERIES__)*/
void
WIN_DestroyWindow(_THIS, SDL_Window * window)
@@ -1165,6 +1226,7 @@ SDL_HelperWindowDestroy(void)
}
}
#if !defined(__XBOXONE__) && !defined(__XBOXSERIES__)
void WIN_OnWindowEnter(_THIS, SDL_Window * window)
{
SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
@@ -1277,10 +1339,14 @@ WIN_SetWindowHitTest(SDL_Window *window, SDL_bool enabled)
{
return 0; /* just succeed, the real work is done elsewhere. */
}
#endif /*!defined(__XBOXONE__) && !defined(__XBOXSERIES__)*/
int
WIN_SetWindowOpacity(_THIS, SDL_Window * window, float opacity)
{
#if defined(__XBOXONE__) || defined(__XBOXSERIES__)
return -1;
#else
const SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
const HWND hwnd = data->hwnd;
const LONG style = GetWindowLong(hwnd, GWL_EXSTYLE);
@@ -1309,6 +1375,7 @@ WIN_SetWindowOpacity(_THIS, SDL_Window * window, float opacity)
}
return 0;
#endif /*!defined(__XBOXONE__) && !defined(__XBOXSERIES__)*/
}
/**
@@ -1366,6 +1433,7 @@ WIN_ClientPointFromSDL(const SDL_Window *window, int *x, int *y)
*y = MulDiv(*y, data->scaling_dpi, 96);
}
#if !defined(__XBOXONE__) && !defined(__XBOXSERIES__)
void
WIN_AcceptDragAndDrop(SDL_Window * window, SDL_bool accept)
{
@@ -1400,6 +1468,7 @@ WIN_FlashWindow(_THIS, SDL_Window * window, SDL_FlashOperation operation)
return 0;
}
#endif /*!defined(__XBOXONE__) && !defined(__XBOXSERIES__)*/
#endif /* SDL_VIDEO_DRIVER_WINDOWS */

View File

@@ -25,6 +25,8 @@
#if SDL_VIDEO_OPENGL_EGL
#include "../SDL_egl_c.h"
#else
#include "../SDL_sysvideo.h"
#endif
/* Set up for C function definitions, even when using C++ */