Merge commit '852f2a6343518919e5ca8d3c1bbcab9f493e3cd8'
This commit is contained in:
44
external/sdl/SDL/src/sensor/SDL_sensor.c
vendored
44
external/sdl/SDL/src/sensor/SDL_sensor.c
vendored
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2024 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
|
||||
@@ -58,7 +58,6 @@ static SDL_AtomicInt SDL_sensor_lock_pending;
|
||||
static int SDL_sensors_locked;
|
||||
static SDL_bool SDL_sensors_initialized;
|
||||
static SDL_Sensor *SDL_sensors SDL_GUARDED_BY(SDL_sensor_lock) = NULL;
|
||||
static SDL_AtomicInt SDL_last_sensor_instance_id SDL_GUARDED_BY(SDL_sensor_lock);
|
||||
static char SDL_sensor_magic;
|
||||
|
||||
#define CHECK_SENSOR_MAGIC(sensor, retval) \
|
||||
@@ -116,7 +115,7 @@ void SDL_UnlockSensors(void)
|
||||
|
||||
SDL_bool SDL_SensorsLocked(void)
|
||||
{
|
||||
return (SDL_sensors_locked > 0) ? SDL_TRUE : SDL_FALSE;
|
||||
return (SDL_sensors_locked > 0);
|
||||
}
|
||||
|
||||
void SDL_AssertSensorsLocked(void)
|
||||
@@ -209,8 +208,6 @@ SDL_SensorID *SDL_GetSensors(int *count)
|
||||
if (count) {
|
||||
*count = 0;
|
||||
}
|
||||
|
||||
SDL_OutOfMemory();
|
||||
}
|
||||
}
|
||||
SDL_UnlockSensors();
|
||||
@@ -218,15 +215,6 @@ SDL_SensorID *SDL_GetSensors(int *count)
|
||||
return sensors;
|
||||
}
|
||||
|
||||
/*
|
||||
* Return the next available sensor instance ID
|
||||
* This may be called by drivers from multiple threads, unprotected by any locks
|
||||
*/
|
||||
SDL_SensorID SDL_GetNextSensorInstanceID(void)
|
||||
{
|
||||
return SDL_AtomicIncRef(&SDL_last_sensor_instance_id) + 1;
|
||||
}
|
||||
|
||||
/*
|
||||
* Get the driver and device index for a sensor instance ID
|
||||
* This should be called while the sensor lock is held, to prevent another thread from updating the list
|
||||
@@ -248,7 +236,7 @@ static SDL_bool SDL_GetDriverAndSensorIndex(SDL_SensorID instance_id, SDL_Sensor
|
||||
}
|
||||
}
|
||||
}
|
||||
SDL_SetError("Sensor %" SDL_PRIs32 " not found", instance_id);
|
||||
SDL_SetError("Sensor %" SDL_PRIu32 " not found", instance_id);
|
||||
return SDL_FALSE;
|
||||
}
|
||||
|
||||
@@ -339,8 +327,7 @@ SDL_Sensor *SDL_OpenSensor(SDL_SensorID instance_id)
|
||||
|
||||
/* Create and initialize the sensor */
|
||||
sensor = (SDL_Sensor *)SDL_calloc(sizeof(*sensor), 1);
|
||||
if (sensor == NULL) {
|
||||
SDL_OutOfMemory();
|
||||
if (!sensor) {
|
||||
SDL_UnlockSensors();
|
||||
return NULL;
|
||||
}
|
||||
@@ -393,6 +380,27 @@ SDL_Sensor *SDL_GetSensorFromInstanceID(SDL_SensorID instance_id)
|
||||
return sensor;
|
||||
}
|
||||
|
||||
/*
|
||||
* Get the properties associated with a sensor.
|
||||
*/
|
||||
SDL_PropertiesID SDL_GetSensorProperties(SDL_Sensor *sensor)
|
||||
{
|
||||
SDL_PropertiesID retval;
|
||||
|
||||
SDL_LockSensors();
|
||||
{
|
||||
CHECK_SENSOR_MAGIC(sensor, 0);
|
||||
|
||||
if (sensor->props == 0) {
|
||||
sensor->props = SDL_CreateProperties();
|
||||
}
|
||||
retval = sensor->props;
|
||||
}
|
||||
SDL_UnlockSensors();
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
/*
|
||||
* Get the friendly name of this sensor
|
||||
*/
|
||||
@@ -500,6 +508,8 @@ void SDL_CloseSensor(SDL_Sensor *sensor)
|
||||
return;
|
||||
}
|
||||
|
||||
SDL_DestroyProperties(sensor->props);
|
||||
|
||||
sensor->driver->Close(sensor);
|
||||
sensor->hwdata = NULL;
|
||||
|
||||
|
||||
5
external/sdl/SDL/src/sensor/SDL_sensor_c.h
vendored
5
external/sdl/SDL/src/sensor/SDL_sensor_c.h
vendored
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2024 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
|
||||
@@ -31,9 +31,6 @@ struct SDL_SensorDriver;
|
||||
|
||||
/* Useful functions and variables from SDL_sensor.c */
|
||||
|
||||
/* Function to get the next available sensor instance ID */
|
||||
extern SDL_SensorID SDL_GetNextSensorInstanceID(void);
|
||||
|
||||
/* Initialization and shutdown functions */
|
||||
extern int SDL_InitSensors(void);
|
||||
extern void SDL_QuitSensors(void);
|
||||
|
||||
4
external/sdl/SDL/src/sensor/SDL_syssensor.h
vendored
4
external/sdl/SDL/src/sensor/SDL_syssensor.h
vendored
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2024 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
|
||||
@@ -45,6 +45,8 @@ struct SDL_Sensor
|
||||
|
||||
struct sensor_hwdata *hwdata _guarded; /* Driver dependent information */
|
||||
|
||||
SDL_PropertiesID props _guarded;
|
||||
|
||||
int ref_count _guarded; /* Reference count for multiple opens */
|
||||
|
||||
struct SDL_Sensor *next _guarded; /* pointer to next sensor we have allocated */
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2024 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
|
||||
@@ -138,7 +138,7 @@ static int SDL_ANDROID_SensorInit(void)
|
||||
ASensorList sensors;
|
||||
|
||||
SDL_sensor_manager = ASensorManager_getInstance();
|
||||
if (SDL_sensor_manager == NULL) {
|
||||
if (!SDL_sensor_manager) {
|
||||
return SDL_SetError("Couldn't create sensor manager");
|
||||
}
|
||||
|
||||
@@ -146,13 +146,13 @@ static int SDL_ANDROID_SensorInit(void)
|
||||
sensors_count = ASensorManager_getSensorList(SDL_sensor_manager, &sensors);
|
||||
if (sensors_count > 0) {
|
||||
SDL_sensors = (SDL_AndroidSensor *)SDL_calloc(sensors_count, sizeof(*SDL_sensors));
|
||||
if (SDL_sensors == NULL) {
|
||||
return SDL_OutOfMemory();
|
||||
if (!SDL_sensors) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
for (i = 0; i < sensors_count; ++i) {
|
||||
SDL_sensors[i].asensor = sensors[i];
|
||||
SDL_sensors[i].instance_id = SDL_GetNextSensorInstanceID();
|
||||
SDL_sensors[i].instance_id = SDL_GetNextObjectID();
|
||||
}
|
||||
SDL_sensors_count = sensors_count;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2024 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
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2024 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
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2024 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
|
||||
@@ -57,18 +57,18 @@ static int SDL_COREMOTION_SensorInit(void)
|
||||
if (sensors_count > 0) {
|
||||
SDL_sensors = (SDL_CoreMotionSensor *)SDL_calloc(sensors_count, sizeof(*SDL_sensors));
|
||||
if (!SDL_sensors) {
|
||||
return SDL_OutOfMemory();
|
||||
return -1;
|
||||
}
|
||||
|
||||
i = 0;
|
||||
if (SDL_motion_manager.accelerometerAvailable) {
|
||||
SDL_sensors[i].type = SDL_SENSOR_ACCEL;
|
||||
SDL_sensors[i].instance_id = SDL_GetNextSensorInstanceID();
|
||||
SDL_sensors[i].instance_id = SDL_GetNextObjectID();
|
||||
++i;
|
||||
}
|
||||
if (SDL_motion_manager.gyroAvailable) {
|
||||
SDL_sensors[i].type = SDL_SENSOR_GYRO;
|
||||
SDL_sensors[i].instance_id = SDL_GetNextSensorInstanceID();
|
||||
SDL_sensors[i].instance_id = SDL_GetNextObjectID();
|
||||
++i;
|
||||
}
|
||||
SDL_sensors_count = sensors_count;
|
||||
@@ -118,7 +118,7 @@ static int SDL_COREMOTION_SensorOpen(SDL_Sensor *sensor, int device_index)
|
||||
|
||||
hwdata = (struct sensor_hwdata *)SDL_calloc(1, sizeof(*hwdata));
|
||||
if (hwdata == NULL) {
|
||||
return SDL_OutOfMemory();
|
||||
return -1;
|
||||
}
|
||||
sensor->hwdata = hwdata;
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2024 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
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2024 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
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2024 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
|
||||
@@ -54,9 +54,9 @@ static int N3DS_SensorInit(void)
|
||||
}
|
||||
|
||||
N3DS_sensors[0].type = SDL_SENSOR_ACCEL;
|
||||
N3DS_sensors[0].instance_id = SDL_GetNextSensorInstanceID();
|
||||
N3DS_sensors[0].instance_id = SDL_GetNextObjectID();
|
||||
N3DS_sensors[1].type = SDL_SENSOR_GYRO;
|
||||
N3DS_sensors[1].instance_id = SDL_GetNextSensorInstanceID();
|
||||
N3DS_sensors[1].instance_id = SDL_GetNextObjectID();
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2024 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
|
||||
@@ -51,14 +51,14 @@ static int SDL_VITA_SensorInit(void)
|
||||
SDL_sensors_count = 2;
|
||||
|
||||
SDL_sensors = (SDL_VitaSensor *)SDL_calloc(SDL_sensors_count, sizeof(*SDL_sensors));
|
||||
if (SDL_sensors == NULL) {
|
||||
return SDL_OutOfMemory();
|
||||
if (!SDL_sensors) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
SDL_sensors[0].type = SDL_SENSOR_ACCEL;
|
||||
SDL_sensors[0].instance_id = SDL_GetNextSensorInstanceID();
|
||||
SDL_sensors[0].instance_id = SDL_GetNextObjectID();
|
||||
SDL_sensors[1].type = SDL_SENSOR_GYRO;
|
||||
SDL_sensors[1].instance_id = SDL_GetNextSensorInstanceID();
|
||||
SDL_sensors[1].instance_id = SDL_GetNextObjectID();
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -118,8 +118,8 @@ static int SDL_VITA_SensorOpen(SDL_Sensor *sensor, int device_index)
|
||||
struct sensor_hwdata *hwdata;
|
||||
|
||||
hwdata = (struct sensor_hwdata *)SDL_calloc(1, sizeof(*hwdata));
|
||||
if (hwdata == NULL) {
|
||||
return SDL_OutOfMemory();
|
||||
if (!hwdata) {
|
||||
return -1;
|
||||
}
|
||||
sensor->hwdata = hwdata;
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2024 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
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2024 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
|
||||
@@ -62,7 +62,7 @@ static int DisconnectSensor(ISensor *sensor);
|
||||
|
||||
static HRESULT STDMETHODCALLTYPE ISensorManagerEventsVtbl_QueryInterface(ISensorManagerEvents *This, REFIID riid, void **ppvObject)
|
||||
{
|
||||
if (ppvObject == NULL) {
|
||||
if (!ppvObject) {
|
||||
return E_INVALIDARG;
|
||||
}
|
||||
|
||||
@@ -102,7 +102,7 @@ static ISensorManagerEvents sensor_manager_events = {
|
||||
|
||||
static HRESULT STDMETHODCALLTYPE ISensorEventsVtbl_QueryInterface(ISensorEvents *This, REFIID riid, void **ppvObject)
|
||||
{
|
||||
if (ppvObject == NULL) {
|
||||
if (!ppvObject) {
|
||||
return E_INVALIDARG;
|
||||
}
|
||||
|
||||
@@ -150,7 +150,7 @@ static HRESULT STDMETHODCALLTYPE ISensorEventsVtbl_OnDataUpdated(ISensorEvents *
|
||||
if (pSensor == SDL_sensors[i].sensor) {
|
||||
if (SDL_sensors[i].sensor_opened) {
|
||||
HRESULT hrX, hrY, hrZ;
|
||||
PROPVARIANT valueX, valueY, valueZ;
|
||||
PROPVARIANT valueX = { 0 }, valueY = { 0 }, valueZ = { 0 };
|
||||
SYSTEMTIME sensor_systemtime;
|
||||
FILETIME sensor_filetime;
|
||||
Uint64 sensor_timestamp;
|
||||
@@ -295,16 +295,16 @@ static int ConnectSensor(ISensor *sensor)
|
||||
if (bstr_name != NULL) {
|
||||
SysFreeString(bstr_name);
|
||||
}
|
||||
if (name == NULL) {
|
||||
return SDL_OutOfMemory();
|
||||
if (!name) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
SDL_LockSensors();
|
||||
new_sensors = (SDL_Windows_Sensor *)SDL_realloc(SDL_sensors, (SDL_num_sensors + 1) * sizeof(SDL_Windows_Sensor));
|
||||
if (new_sensors == NULL) {
|
||||
if (!new_sensors) {
|
||||
SDL_UnlockSensors();
|
||||
SDL_free(name);
|
||||
return SDL_OutOfMemory();
|
||||
return -1;
|
||||
}
|
||||
|
||||
ISensor_AddRef(sensor);
|
||||
@@ -315,7 +315,7 @@ static int ConnectSensor(ISensor *sensor)
|
||||
++SDL_num_sensors;
|
||||
|
||||
SDL_zerop(new_sensor);
|
||||
new_sensor->id = SDL_GetNextSensorInstanceID();
|
||||
new_sensor->id = SDL_GetNextObjectID();
|
||||
new_sensor->sensor = sensor;
|
||||
new_sensor->type = type;
|
||||
new_sensor->name = name;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2024 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
|
||||
|
||||
Reference in New Issue
Block a user