mirror of
https://github.com/TorqueGameEngines/Torque3D.git
synced 2026-07-13 15:44:36 +00:00
sdl 2.0.8 update
This commit is contained in:
parent
7f674a59c6
commit
bfb08f9482
894 changed files with 66879 additions and 43299 deletions
122
Engine/lib/sdl/test/CMakeLists.txt
Normal file
122
Engine/lib/sdl/test/CMakeLists.txt
Normal file
|
|
@ -0,0 +1,122 @@
|
|||
cmake_minimum_required(VERSION 2.8.11)
|
||||
project(SDL2 C)
|
||||
|
||||
# Global settings for all of the test targets
|
||||
# FIXME: is this wrong?
|
||||
remove_definitions(-DUSING_GENERATED_CONFIG_H)
|
||||
link_libraries(SDL2_test SDL2-static)
|
||||
|
||||
# FIXME: Parent directory CMakeLists.txt only sets these for mingw/cygwin,
|
||||
# but we need them for VS as well.
|
||||
if(WINDOWS)
|
||||
link_libraries(SDL2main)
|
||||
add_definitions(-Dmain=SDL_main)
|
||||
endif()
|
||||
|
||||
add_executable(checkkeys checkkeys.c)
|
||||
add_executable(loopwave loopwave.c)
|
||||
add_executable(loopwavequeue loopwavequeue.c)
|
||||
add_executable(testresample testresample.c)
|
||||
add_executable(testaudioinfo testaudioinfo.c)
|
||||
|
||||
file(GLOB TESTAUTOMATION_SOURCE_FILES testautomation*.c)
|
||||
add_executable(testautomation ${TESTAUTOMATION_SOURCE_FILES})
|
||||
|
||||
add_executable(testmultiaudio testmultiaudio.c)
|
||||
add_executable(testaudiohotplug testaudiohotplug.c)
|
||||
add_executable(testaudiocapture testaudiocapture.c)
|
||||
add_executable(testatomic testatomic.c)
|
||||
add_executable(testintersections testintersections.c)
|
||||
add_executable(testrelative testrelative.c)
|
||||
add_executable(testhittesting testhittesting.c)
|
||||
add_executable(testdraw2 testdraw2.c)
|
||||
add_executable(testdrawchessboard testdrawchessboard.c)
|
||||
add_executable(testdropfile testdropfile.c)
|
||||
add_executable(testerror testerror.c)
|
||||
add_executable(testfile testfile.c)
|
||||
add_executable(testgamecontroller testgamecontroller.c)
|
||||
add_executable(testgesture testgesture.c)
|
||||
add_executable(testgl2 testgl2.c)
|
||||
add_executable(testgles testgles.c)
|
||||
add_executable(testgles2 testgles2.c)
|
||||
add_executable(testhaptic testhaptic.c)
|
||||
add_executable(testhotplug testhotplug.c)
|
||||
add_executable(testrumble testrumble.c)
|
||||
add_executable(testthread testthread.c)
|
||||
add_executable(testiconv testiconv.c)
|
||||
add_executable(testime testime.c)
|
||||
add_executable(testjoystick testjoystick.c)
|
||||
add_executable(testkeys testkeys.c)
|
||||
add_executable(testloadso testloadso.c)
|
||||
add_executable(testlock testlock.c)
|
||||
|
||||
if(APPLE)
|
||||
add_executable(testnative testnative.c
|
||||
testnativecocoa.m
|
||||
testnativex11.c)
|
||||
elseif(WINDOWS)
|
||||
add_executable(testnative testnative.c testnativew32.c)
|
||||
elseif(UNIX)
|
||||
add_executable(testnative testnative.c testnativex11.c)
|
||||
endif()
|
||||
|
||||
add_executable(testoverlay2 testoverlay2.c testyuv_cvt.c)
|
||||
add_executable(testplatform testplatform.c)
|
||||
add_executable(testpower testpower.c)
|
||||
add_executable(testfilesystem testfilesystem.c)
|
||||
add_executable(testrendertarget testrendertarget.c)
|
||||
add_executable(testscale testscale.c)
|
||||
add_executable(testsem testsem.c)
|
||||
add_executable(testshader testshader.c)
|
||||
add_executable(testshape testshape.c)
|
||||
add_executable(testsprite2 testsprite2.c)
|
||||
add_executable(testspriteminimal testspriteminimal.c)
|
||||
add_executable(teststreaming teststreaming.c)
|
||||
add_executable(testtimer testtimer.c)
|
||||
add_executable(testver testver.c)
|
||||
add_executable(testviewport testviewport.c)
|
||||
add_executable(testwm2 testwm2.c)
|
||||
add_executable(testyuv testyuv.c testyuv_cvt.c)
|
||||
add_executable(torturethread torturethread.c)
|
||||
add_executable(testrendercopyex testrendercopyex.c)
|
||||
add_executable(testmessage testmessage.c)
|
||||
add_executable(testdisplayinfo testdisplayinfo.c)
|
||||
add_executable(testqsort testqsort.c)
|
||||
add_executable(testbounds testbounds.c)
|
||||
add_executable(testcustomcursor testcustomcursor.c)
|
||||
add_executable(controllermap controllermap.c)
|
||||
add_executable(testvulkan testvulkan.c)
|
||||
|
||||
# HACK: Dummy target to cause the resource files to be copied to the build directory.
|
||||
# Need to make it an executable so we can use the TARGET_FILE_DIR generator expression.
|
||||
# This is needed so they get copied to the correct Debug/Release subdirectory in Xcode.
|
||||
file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/resources_dummy.c "int main(int argc, const char **argv){ return 1; }\n")
|
||||
add_executable(SDL2_test_resoureces ${CMAKE_CURRENT_BINARY_DIR}/resources_dummy.c)
|
||||
|
||||
file(GLOB RESOURCE_FILES *.bmp *.wav)
|
||||
foreach(RESOURCE_FILE ${RESOURCE_FILES})
|
||||
add_custom_command(TARGET SDL2_test_resoureces POST_BUILD COMMAND ${CMAKE_COMMAND} ARGS -E copy_if_different ${RESOURCE_FILE} $<TARGET_FILE_DIR:SDL2_test_resoureces>)
|
||||
endforeach(RESOURCE_FILE)
|
||||
|
||||
file(COPY ${RESOURCE_FILES} DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
|
||||
|
||||
# TODO: Might be easier to make all targets depend on the resources...?
|
||||
add_dependencies(testscale SDL2_test_resoureces)
|
||||
add_dependencies(testrendercopyex SDL2_test_resoureces)
|
||||
add_dependencies(controllermap SDL2_test_resoureces)
|
||||
add_dependencies(testyuv SDL2_test_resoureces)
|
||||
add_dependencies(testgamecontroller SDL2_test_resoureces)
|
||||
add_dependencies(testshape SDL2_test_resoureces)
|
||||
add_dependencies(testshader SDL2_test_resoureces)
|
||||
add_dependencies(testnative SDL2_test_resoureces)
|
||||
add_dependencies(testspriteminimal SDL2_test_resoureces)
|
||||
add_dependencies(testautomation SDL2_test_resoureces)
|
||||
add_dependencies(testcustomcursor SDL2_test_resoureces)
|
||||
add_dependencies(testrendertarget SDL2_test_resoureces)
|
||||
add_dependencies(testsprite2 SDL2_test_resoureces)
|
||||
|
||||
add_dependencies(loopwave SDL2_test_resoureces)
|
||||
add_dependencies(loopwavequeue SDL2_test_resoureces)
|
||||
add_dependencies(testresample SDL2_test_resoureces)
|
||||
add_dependencies(testaudiohotplug SDL2_test_resoureces)
|
||||
add_dependencies(testmultiaudio SDL2_test_resoureces)
|
||||
|
|
@ -9,19 +9,23 @@ LIBS = @LIBS@
|
|||
|
||||
TARGETS = \
|
||||
checkkeys$(EXE) \
|
||||
controllermap$(EXE) \
|
||||
loopwave$(EXE) \
|
||||
loopwavequeue$(EXE) \
|
||||
testatomic$(EXE) \
|
||||
testaudioinfo$(EXE) \
|
||||
testaudiocapture$(EXE) \
|
||||
testaudiohotplug$(EXE) \
|
||||
testaudioinfo$(EXE) \
|
||||
testautomation$(EXE) \
|
||||
testbounds$(EXE) \
|
||||
testcustomcursor$(EXE) \
|
||||
testdisplayinfo$(EXE) \
|
||||
testdraw2$(EXE) \
|
||||
testdrawchessboard$(EXE) \
|
||||
testdropfile$(EXE) \
|
||||
testerror$(EXE) \
|
||||
testfile$(EXE) \
|
||||
testfilesystem$(EXE) \
|
||||
testgamecontroller$(EXE) \
|
||||
testgesture$(EXE) \
|
||||
testgl2$(EXE) \
|
||||
|
|
@ -29,26 +33,26 @@ TARGETS = \
|
|||
testgles2$(EXE) \
|
||||
testhaptic$(EXE) \
|
||||
testhittesting$(EXE) \
|
||||
testrumble$(EXE) \
|
||||
testhotplug$(EXE) \
|
||||
testthread$(EXE) \
|
||||
testiconv$(EXE) \
|
||||
testime$(EXE) \
|
||||
testintersections$(EXE) \
|
||||
testrelative$(EXE) \
|
||||
testjoystick$(EXE) \
|
||||
testkeys$(EXE) \
|
||||
testloadso$(EXE) \
|
||||
testlock$(EXE) \
|
||||
testmessage$(EXE) \
|
||||
testmultiaudio$(EXE) \
|
||||
testaudiohotplug$(EXE) \
|
||||
testnative$(EXE) \
|
||||
testoverlay2$(EXE) \
|
||||
testplatform$(EXE) \
|
||||
testpower$(EXE) \
|
||||
testfilesystem$(EXE) \
|
||||
testqsort$(EXE) \
|
||||
testrelative$(EXE) \
|
||||
testrendercopyex$(EXE) \
|
||||
testrendertarget$(EXE) \
|
||||
testresample$(EXE) \
|
||||
testrumble$(EXE) \
|
||||
testscale$(EXE) \
|
||||
testsem$(EXE) \
|
||||
testshader$(EXE) \
|
||||
|
|
@ -56,18 +60,16 @@ TARGETS = \
|
|||
testsprite2$(EXE) \
|
||||
testspriteminimal$(EXE) \
|
||||
teststreaming$(EXE) \
|
||||
testthread$(EXE) \
|
||||
testtimer$(EXE) \
|
||||
testver$(EXE) \
|
||||
testviewport$(EXE) \
|
||||
testvulkan$(EXE) \
|
||||
testwm2$(EXE) \
|
||||
testyuv$(EXE) \
|
||||
torturethread$(EXE) \
|
||||
testrendercopyex$(EXE) \
|
||||
testmessage$(EXE) \
|
||||
testdisplayinfo$(EXE) \
|
||||
testqsort$(EXE) \
|
||||
controllermap$(EXE) \
|
||||
|
||||
all: Makefile $(TARGETS)
|
||||
all: Makefile $(TARGETS) copydatafiles
|
||||
|
||||
Makefile: $(srcdir)/Makefile.in
|
||||
$(SHELL) config.status $@
|
||||
|
|
@ -217,7 +219,7 @@ endif
|
|||
endif
|
||||
endif
|
||||
|
||||
testoverlay2$(EXE): $(srcdir)/testoverlay2.c
|
||||
testoverlay2$(EXE): $(srcdir)/testoverlay2.c $(srcdir)/testyuv_cvt.c
|
||||
$(CC) -o $@ $^ $(CFLAGS) $(LIBS)
|
||||
|
||||
testplatform$(EXE): $(srcdir)/testplatform.c
|
||||
|
|
@ -265,6 +267,9 @@ testviewport$(EXE): $(srcdir)/testviewport.c
|
|||
testwm2$(EXE): $(srcdir)/testwm2.c
|
||||
$(CC) -o $@ $^ $(CFLAGS) $(LIBS)
|
||||
|
||||
testyuv$(EXE): $(srcdir)/testyuv.c $(srcdir)/testyuv_cvt.c
|
||||
$(CC) -o $@ $^ $(CFLAGS) $(LIBS)
|
||||
|
||||
torturethread$(EXE): $(srcdir)/torturethread.c
|
||||
$(CC) -o $@ $^ $(CFLAGS) $(LIBS)
|
||||
|
||||
|
|
@ -289,6 +294,9 @@ testcustomcursor$(EXE): $(srcdir)/testcustomcursor.c
|
|||
controllermap$(EXE): $(srcdir)/controllermap.c
|
||||
$(CC) -o $@ $^ $(CFLAGS) $(LIBS)
|
||||
|
||||
testvulkan$(EXE): $(srcdir)/testvulkan.c
|
||||
$(CC) -o $@ $^ $(CFLAGS) $(LIBS)
|
||||
|
||||
|
||||
clean:
|
||||
rm -f $(TARGETS)
|
||||
|
|
@ -297,3 +305,20 @@ distclean: clean
|
|||
rm -f Makefile
|
||||
rm -f config.status config.cache config.log
|
||||
rm -rf $(srcdir)/autom4te*
|
||||
|
||||
|
||||
%.bmp: $(srcdir)/%.bmp
|
||||
cp $< $@
|
||||
|
||||
%.wav: $(srcdir)/%.wav
|
||||
cp $< $@
|
||||
|
||||
copydatafiles: copybmpfiles copywavfiles
|
||||
.PHONY : copydatafiles
|
||||
|
||||
copybmpfiles: $(foreach bmp,$(wildcard $(srcdir)/*.bmp),$(notdir $(bmp)))
|
||||
.PHONY : copybmpfiles
|
||||
|
||||
copywavfiles: $(foreach wav,$(wildcard $(srcdir)/*.wav),$(notdir $(wav)))
|
||||
.PHONY : copywavfiles
|
||||
|
||||
|
|
|
|||
Binary file not shown.
|
Before Width: | Height: | Size: 3.7 KiB After Width: | Height: | Size: 9.9 KiB |
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2018 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
|
||||
|
|
@ -168,7 +168,19 @@ loop()
|
|||
PrintText("INPUT", event.text.text);
|
||||
break;
|
||||
case SDL_MOUSEBUTTONDOWN:
|
||||
/* Any button press quits the app... */
|
||||
/* Left button quits the app, other buttons toggles text input */
|
||||
if (event.button.button == SDL_BUTTON_LEFT) {
|
||||
done = 1;
|
||||
} else {
|
||||
if (SDL_IsTextInputActive()) {
|
||||
SDL_Log("Stopping text input\n");
|
||||
SDL_StopTextInput();
|
||||
} else {
|
||||
SDL_Log("Starting text input\n");
|
||||
SDL_StartTextInput();
|
||||
}
|
||||
}
|
||||
break;
|
||||
case SDL_QUIT:
|
||||
done = 1;
|
||||
break;
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2018 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
|
||||
|
|
@ -32,16 +32,124 @@
|
|||
#define MARKER_BUTTON 1
|
||||
#define MARKER_AXIS 2
|
||||
|
||||
typedef struct MappingStep
|
||||
enum
|
||||
{
|
||||
SDL_CONTROLLER_BINDING_AXIS_LEFTX_NEGATIVE,
|
||||
SDL_CONTROLLER_BINDING_AXIS_LEFTX_POSITIVE,
|
||||
SDL_CONTROLLER_BINDING_AXIS_LEFTY_NEGATIVE,
|
||||
SDL_CONTROLLER_BINDING_AXIS_LEFTY_POSITIVE,
|
||||
SDL_CONTROLLER_BINDING_AXIS_RIGHTX_NEGATIVE,
|
||||
SDL_CONTROLLER_BINDING_AXIS_RIGHTX_POSITIVE,
|
||||
SDL_CONTROLLER_BINDING_AXIS_RIGHTY_NEGATIVE,
|
||||
SDL_CONTROLLER_BINDING_AXIS_RIGHTY_POSITIVE,
|
||||
SDL_CONTROLLER_BINDING_AXIS_TRIGGERLEFT,
|
||||
SDL_CONTROLLER_BINDING_AXIS_TRIGGERRIGHT,
|
||||
SDL_CONTROLLER_BINDING_AXIS_MAX,
|
||||
};
|
||||
|
||||
#define BINDING_COUNT (SDL_CONTROLLER_BUTTON_MAX + SDL_CONTROLLER_BINDING_AXIS_MAX)
|
||||
|
||||
static struct
|
||||
{
|
||||
int x, y;
|
||||
double angle;
|
||||
int marker;
|
||||
char *field;
|
||||
int axis, button, hat, hat_value;
|
||||
char mapping[4096];
|
||||
}MappingStep;
|
||||
|
||||
} s_arrBindingDisplay[BINDING_COUNT] = {
|
||||
{ 387, 167, 0.0, MARKER_BUTTON }, /* SDL_CONTROLLER_BUTTON_A */
|
||||
{ 431, 132, 0.0, MARKER_BUTTON }, /* SDL_CONTROLLER_BUTTON_B */
|
||||
{ 342, 132, 0.0, MARKER_BUTTON }, /* SDL_CONTROLLER_BUTTON_X */
|
||||
{ 389, 101, 0.0, MARKER_BUTTON }, /* SDL_CONTROLLER_BUTTON_Y */
|
||||
{ 174, 132, 0.0, MARKER_BUTTON }, /* SDL_CONTROLLER_BUTTON_BACK */
|
||||
{ 233, 132, 0.0, MARKER_BUTTON }, /* SDL_CONTROLLER_BUTTON_GUIDE */
|
||||
{ 289, 132, 0.0, MARKER_BUTTON }, /* SDL_CONTROLLER_BUTTON_START */
|
||||
{ 75, 154, 0.0, MARKER_BUTTON }, /* SDL_CONTROLLER_BUTTON_LEFTSTICK */
|
||||
{ 305, 230, 0.0, MARKER_BUTTON }, /* SDL_CONTROLLER_BUTTON_RIGHTSTICK */
|
||||
{ 77, 40, 0.0, MARKER_BUTTON }, /* SDL_CONTROLLER_BUTTON_LEFTSHOULDER */
|
||||
{ 396, 36, 0.0, MARKER_BUTTON }, /* SDL_CONTROLLER_BUTTON_RIGHTSHOULDER */
|
||||
{ 154, 188, 0.0, MARKER_BUTTON }, /* SDL_CONTROLLER_BUTTON_DPAD_UP */
|
||||
{ 154, 249, 0.0, MARKER_BUTTON }, /* SDL_CONTROLLER_BUTTON_DPAD_DOWN */
|
||||
{ 116, 217, 0.0, MARKER_BUTTON }, /* SDL_CONTROLLER_BUTTON_DPAD_LEFT */
|
||||
{ 186, 217, 0.0, MARKER_BUTTON }, /* SDL_CONTROLLER_BUTTON_DPAD_RIGHT */
|
||||
{ 74, 153, 270.0, MARKER_AXIS }, /* SDL_CONTROLLER_BINDING_AXIS_LEFTX_NEGATIVE */
|
||||
{ 74, 153, 90.0, MARKER_AXIS }, /* SDL_CONTROLLER_BINDING_AXIS_LEFTX_POSITIVE */
|
||||
{ 74, 153, 0.0, MARKER_AXIS }, /* SDL_CONTROLLER_BINDING_AXIS_LEFTY_NEGATIVE */
|
||||
{ 74, 153, 180.0, MARKER_AXIS }, /* SDL_CONTROLLER_BINDING_AXIS_LEFTY_POSITIVE */
|
||||
{ 306, 231, 270.0, MARKER_AXIS }, /* SDL_CONTROLLER_BINDING_AXIS_RIGHTX_NEGATIVE */
|
||||
{ 306, 231, 90.0, MARKER_AXIS }, /* SDL_CONTROLLER_BINDING_AXIS_RIGHTX_POSITIVE */
|
||||
{ 306, 231, 0.0, MARKER_AXIS }, /* SDL_CONTROLLER_BINDING_AXIS_RIGHTY_NEGATIVE */
|
||||
{ 306, 231, 180.0, MARKER_AXIS }, /* SDL_CONTROLLER_BINDING_AXIS_RIGHTY_POSITIVE */
|
||||
{ 91, -20, 180.0, MARKER_AXIS }, /* SDL_CONTROLLER_BINDING_AXIS_TRIGGERLEFT */
|
||||
{ 375, -20, 180.0, MARKER_AXIS }, /* SDL_CONTROLLER_BINDING_AXIS_TRIGGERRIGHT */
|
||||
};
|
||||
|
||||
static int s_arrBindingOrder[BINDING_COUNT] = {
|
||||
SDL_CONTROLLER_BUTTON_A,
|
||||
SDL_CONTROLLER_BUTTON_B,
|
||||
SDL_CONTROLLER_BUTTON_Y,
|
||||
SDL_CONTROLLER_BUTTON_X,
|
||||
SDL_CONTROLLER_BUTTON_MAX + SDL_CONTROLLER_BINDING_AXIS_LEFTX_NEGATIVE,
|
||||
SDL_CONTROLLER_BUTTON_MAX + SDL_CONTROLLER_BINDING_AXIS_LEFTX_POSITIVE,
|
||||
SDL_CONTROLLER_BUTTON_MAX + SDL_CONTROLLER_BINDING_AXIS_LEFTY_NEGATIVE,
|
||||
SDL_CONTROLLER_BUTTON_MAX + SDL_CONTROLLER_BINDING_AXIS_LEFTY_POSITIVE,
|
||||
SDL_CONTROLLER_BUTTON_LEFTSTICK,
|
||||
SDL_CONTROLLER_BUTTON_MAX + SDL_CONTROLLER_BINDING_AXIS_RIGHTX_NEGATIVE,
|
||||
SDL_CONTROLLER_BUTTON_MAX + SDL_CONTROLLER_BINDING_AXIS_RIGHTX_POSITIVE,
|
||||
SDL_CONTROLLER_BUTTON_MAX + SDL_CONTROLLER_BINDING_AXIS_RIGHTY_NEGATIVE,
|
||||
SDL_CONTROLLER_BUTTON_MAX + SDL_CONTROLLER_BINDING_AXIS_RIGHTY_POSITIVE,
|
||||
SDL_CONTROLLER_BUTTON_RIGHTSTICK,
|
||||
SDL_CONTROLLER_BUTTON_LEFTSHOULDER,
|
||||
SDL_CONTROLLER_BUTTON_MAX + SDL_CONTROLLER_BINDING_AXIS_TRIGGERLEFT,
|
||||
SDL_CONTROLLER_BUTTON_RIGHTSHOULDER,
|
||||
SDL_CONTROLLER_BUTTON_MAX + SDL_CONTROLLER_BINDING_AXIS_TRIGGERRIGHT,
|
||||
SDL_CONTROLLER_BUTTON_DPAD_UP,
|
||||
SDL_CONTROLLER_BUTTON_DPAD_RIGHT,
|
||||
SDL_CONTROLLER_BUTTON_DPAD_DOWN,
|
||||
SDL_CONTROLLER_BUTTON_DPAD_LEFT,
|
||||
SDL_CONTROLLER_BUTTON_BACK,
|
||||
SDL_CONTROLLER_BUTTON_GUIDE,
|
||||
SDL_CONTROLLER_BUTTON_START,
|
||||
};
|
||||
|
||||
typedef struct
|
||||
{
|
||||
SDL_GameControllerBindType bindType;
|
||||
union
|
||||
{
|
||||
int button;
|
||||
|
||||
struct {
|
||||
int axis;
|
||||
int axis_min;
|
||||
int axis_max;
|
||||
} axis;
|
||||
|
||||
struct {
|
||||
int hat;
|
||||
int hat_mask;
|
||||
} hat;
|
||||
|
||||
} value;
|
||||
|
||||
SDL_bool committed;
|
||||
|
||||
} SDL_GameControllerExtendedBind;
|
||||
|
||||
static SDL_GameControllerExtendedBind s_arrBindings[BINDING_COUNT];
|
||||
|
||||
typedef struct
|
||||
{
|
||||
SDL_bool m_bMoving;
|
||||
int m_nStartingValue;
|
||||
int m_nFarthestValue;
|
||||
} AxisState;
|
||||
|
||||
static int s_nNumAxes;
|
||||
static AxisState *s_arrAxisState;
|
||||
|
||||
static int s_iCurrentBinding;
|
||||
static Uint32 s_unPendingAdvanceTime;
|
||||
static SDL_bool s_bBindingComplete;
|
||||
|
||||
SDL_Texture *
|
||||
LoadTexture(SDL_Renderer *renderer, const char *file, SDL_bool transparent)
|
||||
|
|
@ -60,23 +168,6 @@ LoadTexture(SDL_Renderer *renderer, const char *file, SDL_bool transparent)
|
|||
if (transparent) {
|
||||
if (temp->format->palette) {
|
||||
SDL_SetColorKey(temp, SDL_TRUE, *(Uint8 *) temp->pixels);
|
||||
} else {
|
||||
switch (temp->format->BitsPerPixel) {
|
||||
case 15:
|
||||
SDL_SetColorKey(temp, SDL_TRUE,
|
||||
(*(Uint16 *) temp->pixels) & 0x00007FFF);
|
||||
break;
|
||||
case 16:
|
||||
SDL_SetColorKey(temp, SDL_TRUE, *(Uint16 *) temp->pixels);
|
||||
break;
|
||||
case 24:
|
||||
SDL_SetColorKey(temp, SDL_TRUE,
|
||||
(*(Uint32 *) temp->pixels) & 0x00FFFFFF);
|
||||
break;
|
||||
case 32:
|
||||
SDL_SetColorKey(temp, SDL_TRUE, *(Uint32 *) temp->pixels);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -93,45 +184,186 @@ LoadTexture(SDL_Renderer *renderer, const char *file, SDL_bool transparent)
|
|||
return texture;
|
||||
}
|
||||
|
||||
static int
|
||||
StandardizeAxisValue(int nValue)
|
||||
{
|
||||
if (nValue > SDL_JOYSTICK_AXIS_MAX/2) {
|
||||
return SDL_JOYSTICK_AXIS_MAX;
|
||||
} else if (nValue < SDL_JOYSTICK_AXIS_MIN/2) {
|
||||
return SDL_JOYSTICK_AXIS_MIN;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
SetCurrentBinding(int iBinding)
|
||||
{
|
||||
int iIndex;
|
||||
SDL_GameControllerExtendedBind *pBinding;
|
||||
|
||||
if (iBinding < 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (iBinding == BINDING_COUNT) {
|
||||
s_bBindingComplete = SDL_TRUE;
|
||||
return;
|
||||
}
|
||||
|
||||
s_iCurrentBinding = iBinding;
|
||||
|
||||
pBinding = &s_arrBindings[s_arrBindingOrder[s_iCurrentBinding]];
|
||||
SDL_zerop(pBinding);
|
||||
|
||||
for (iIndex = 0; iIndex < s_nNumAxes; ++iIndex) {
|
||||
s_arrAxisState[iIndex].m_nFarthestValue = s_arrAxisState[iIndex].m_nStartingValue;
|
||||
}
|
||||
|
||||
s_unPendingAdvanceTime = 0;
|
||||
}
|
||||
|
||||
static SDL_bool
|
||||
BBindingContainsBinding(const SDL_GameControllerExtendedBind *pBindingA, const SDL_GameControllerExtendedBind *pBindingB)
|
||||
{
|
||||
if (pBindingA->bindType != pBindingB->bindType)
|
||||
{
|
||||
return SDL_FALSE;
|
||||
}
|
||||
switch (pBindingA->bindType)
|
||||
{
|
||||
case SDL_CONTROLLER_BINDTYPE_AXIS:
|
||||
if (pBindingA->value.axis.axis != pBindingB->value.axis.axis) {
|
||||
return SDL_FALSE;
|
||||
}
|
||||
if (!pBindingA->committed) {
|
||||
return SDL_FALSE;
|
||||
}
|
||||
{
|
||||
int minA = SDL_min(pBindingA->value.axis.axis_min, pBindingA->value.axis.axis_max);
|
||||
int maxA = SDL_max(pBindingA->value.axis.axis_min, pBindingA->value.axis.axis_max);
|
||||
int minB = SDL_min(pBindingB->value.axis.axis_min, pBindingB->value.axis.axis_max);
|
||||
int maxB = SDL_max(pBindingB->value.axis.axis_min, pBindingB->value.axis.axis_max);
|
||||
return (minA <= minB && maxA >= maxB);
|
||||
}
|
||||
/* Not reached */
|
||||
default:
|
||||
return SDL_memcmp(pBindingA, pBindingB, sizeof(*pBindingA)) == 0;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
ConfigureBinding(const SDL_GameControllerExtendedBind *pBinding)
|
||||
{
|
||||
SDL_GameControllerExtendedBind *pCurrent;
|
||||
int iIndex;
|
||||
int iCurrentElement = s_arrBindingOrder[s_iCurrentBinding];
|
||||
|
||||
/* Do we already have this binding? */
|
||||
for (iIndex = 0; iIndex < SDL_arraysize(s_arrBindings); ++iIndex) {
|
||||
pCurrent = &s_arrBindings[iIndex];
|
||||
if (BBindingContainsBinding(pCurrent, pBinding)) {
|
||||
if (iIndex == SDL_CONTROLLER_BUTTON_A && iCurrentElement != SDL_CONTROLLER_BUTTON_B) {
|
||||
/* Skip to the next binding */
|
||||
SetCurrentBinding(s_iCurrentBinding + 1);
|
||||
return;
|
||||
}
|
||||
|
||||
if (iIndex == SDL_CONTROLLER_BUTTON_B) {
|
||||
/* Go back to the previous binding */
|
||||
SetCurrentBinding(s_iCurrentBinding - 1);
|
||||
return;
|
||||
}
|
||||
|
||||
/* Already have this binding, ignore it */
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef DEBUG_CONTROLLERMAP
|
||||
switch ( pBinding->bindType )
|
||||
{
|
||||
case SDL_CONTROLLER_BINDTYPE_NONE:
|
||||
break;
|
||||
case SDL_CONTROLLER_BINDTYPE_BUTTON:
|
||||
SDL_Log("Configuring button binding for button %d\n", pBinding->value.button);
|
||||
break;
|
||||
case SDL_CONTROLLER_BINDTYPE_AXIS:
|
||||
SDL_Log("Configuring axis binding for axis %d %d/%d committed = %s\n", pBinding->value.axis.axis, pBinding->value.axis.axis_min, pBinding->value.axis.axis_max, pBinding->committed ? "true" : "false");
|
||||
break;
|
||||
case SDL_CONTROLLER_BINDTYPE_HAT:
|
||||
SDL_Log("Configuring hat binding for hat %d %d\n", pBinding->value.hat.hat, pBinding->value.hat.hat_mask);
|
||||
break;
|
||||
}
|
||||
#endif /* DEBUG_CONTROLLERMAP */
|
||||
|
||||
/* Should the new binding override the existing one? */
|
||||
pCurrent = &s_arrBindings[iCurrentElement];
|
||||
if (pCurrent->bindType != SDL_CONTROLLER_BINDTYPE_NONE) {
|
||||
SDL_bool bNativeDPad, bCurrentDPad;
|
||||
SDL_bool bNativeAxis, bCurrentAxis;
|
||||
|
||||
bNativeDPad = (iCurrentElement == SDL_CONTROLLER_BUTTON_DPAD_UP ||
|
||||
iCurrentElement == SDL_CONTROLLER_BUTTON_DPAD_DOWN ||
|
||||
iCurrentElement == SDL_CONTROLLER_BUTTON_DPAD_LEFT ||
|
||||
iCurrentElement == SDL_CONTROLLER_BUTTON_DPAD_RIGHT);
|
||||
bCurrentDPad = (pCurrent->bindType == SDL_CONTROLLER_BINDTYPE_HAT);
|
||||
if (bNativeDPad && bCurrentDPad) {
|
||||
/* We already have a binding of the type we want, ignore the new one */
|
||||
return;
|
||||
}
|
||||
|
||||
bNativeAxis = (iCurrentElement >= SDL_CONTROLLER_BUTTON_MAX);
|
||||
bCurrentAxis = (pCurrent->bindType == SDL_CONTROLLER_BINDTYPE_AXIS);
|
||||
if (bNativeAxis == bCurrentAxis &&
|
||||
(pBinding->bindType != SDL_CONTROLLER_BINDTYPE_AXIS ||
|
||||
pBinding->value.axis.axis != pCurrent->value.axis.axis)) {
|
||||
/* We already have a binding of the type we want, ignore the new one */
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
*pCurrent = *pBinding;
|
||||
|
||||
if (pBinding->committed) {
|
||||
s_unPendingAdvanceTime = SDL_GetTicks();
|
||||
} else {
|
||||
s_unPendingAdvanceTime = 0;
|
||||
}
|
||||
}
|
||||
|
||||
static SDL_bool
|
||||
BMergeAxisBindings(int iIndex)
|
||||
{
|
||||
SDL_GameControllerExtendedBind *pBindingA = &s_arrBindings[iIndex];
|
||||
SDL_GameControllerExtendedBind *pBindingB = &s_arrBindings[iIndex+1];
|
||||
if (pBindingA->bindType == SDL_CONTROLLER_BINDTYPE_AXIS &&
|
||||
pBindingB->bindType == SDL_CONTROLLER_BINDTYPE_AXIS &&
|
||||
pBindingA->value.axis.axis == pBindingB->value.axis.axis) {
|
||||
if (pBindingA->value.axis.axis_min == pBindingB->value.axis.axis_min) {
|
||||
pBindingA->value.axis.axis_min = pBindingA->value.axis.axis_max;
|
||||
pBindingA->value.axis.axis_max = pBindingB->value.axis.axis_max;
|
||||
pBindingB->bindType = SDL_CONTROLLER_BINDTYPE_NONE;
|
||||
return SDL_TRUE;
|
||||
}
|
||||
}
|
||||
return SDL_FALSE;
|
||||
}
|
||||
|
||||
static void
|
||||
WatchJoystick(SDL_Joystick * joystick)
|
||||
{
|
||||
SDL_Window *window = NULL;
|
||||
SDL_Renderer *screen = NULL;
|
||||
SDL_Texture *background, *button, *axis, *marker;
|
||||
const char *name = NULL;
|
||||
SDL_bool retval = SDL_FALSE;
|
||||
SDL_bool done = SDL_FALSE, next=SDL_FALSE;
|
||||
SDL_bool done = SDL_FALSE;
|
||||
SDL_Event event;
|
||||
SDL_Rect dst;
|
||||
int s, _s;
|
||||
Uint8 alpha=200, alpha_step = -1;
|
||||
Uint32 alpha_ticks = 0;
|
||||
char mapping[4096], temp[4096];
|
||||
MappingStep *step, *prev_step;
|
||||
MappingStep steps[] = {
|
||||
{342, 132, 0.0, MARKER_BUTTON, "x", -1, -1, -1, -1, ""},
|
||||
{387, 167, 0.0, MARKER_BUTTON, "a", -1, -1, -1, -1, ""},
|
||||
{431, 132, 0.0, MARKER_BUTTON, "b", -1, -1, -1, -1, ""},
|
||||
{389, 101, 0.0, MARKER_BUTTON, "y", -1, -1, -1, -1, ""},
|
||||
{174, 132, 0.0, MARKER_BUTTON, "back", -1, -1, -1, -1, ""},
|
||||
{233, 132, 0.0, MARKER_BUTTON, "guide", -1, -1, -1, -1, ""},
|
||||
{289, 132, 0.0, MARKER_BUTTON, "start", -1, -1, -1, -1, ""},
|
||||
{116, 217, 0.0, MARKER_BUTTON, "dpleft", -1, -1, -1, -1, ""},
|
||||
{154, 249, 0.0, MARKER_BUTTON, "dpdown", -1, -1, -1, -1, ""},
|
||||
{186, 217, 0.0, MARKER_BUTTON, "dpright", -1, -1, -1, -1, ""},
|
||||
{154, 188, 0.0, MARKER_BUTTON, "dpup", -1, -1, -1, -1, ""},
|
||||
{77, 40, 0.0, MARKER_BUTTON, "leftshoulder", -1, -1, -1, -1, ""},
|
||||
{91, 0, 0.0, MARKER_BUTTON, "lefttrigger", -1, -1, -1, -1, ""},
|
||||
{396, 36, 0.0, MARKER_BUTTON, "rightshoulder", -1, -1, -1, -1, ""},
|
||||
{375, 0, 0.0, MARKER_BUTTON, "righttrigger", -1, -1, -1, -1, ""},
|
||||
{75, 154, 0.0, MARKER_BUTTON, "leftstick", -1, -1, -1, -1, ""},
|
||||
{305, 230, 0.0, MARKER_BUTTON, "rightstick", -1, -1, -1, -1, ""},
|
||||
{75, 154, 0.0, MARKER_AXIS, "leftx", -1, -1, -1, -1, ""},
|
||||
{75, 154, 90.0, MARKER_AXIS, "lefty", -1, -1, -1, -1, ""},
|
||||
{305, 230, 0.0, MARKER_AXIS, "rightx", -1, -1, -1, -1, ""},
|
||||
{305, 230, 90.0, MARKER_AXIS, "righty", -1, -1, -1, -1, ""},
|
||||
};
|
||||
SDL_JoystickID nJoystickID;
|
||||
int iIndex;
|
||||
|
||||
/* Create a window to display joystick axis position */
|
||||
window = SDL_CreateWindow("Game Controller Map", SDL_WINDOWPOS_CENTERED,
|
||||
|
|
@ -139,14 +371,14 @@ WatchJoystick(SDL_Joystick * joystick)
|
|||
SCREEN_HEIGHT, 0);
|
||||
if (window == NULL) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create window: %s\n", SDL_GetError());
|
||||
return SDL_FALSE;
|
||||
return;
|
||||
}
|
||||
|
||||
screen = SDL_CreateRenderer(window, -1, 0);
|
||||
if (screen == NULL) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create renderer: %s\n", SDL_GetError());
|
||||
SDL_DestroyWindow(window);
|
||||
return SDL_FALSE;
|
||||
return;
|
||||
}
|
||||
|
||||
background = LoadTexture(screen, "controllermap.bmp", SDL_FALSE);
|
||||
|
|
@ -173,23 +405,24 @@ WatchJoystick(SDL_Joystick * joystick)
|
|||
To skip a button, press SPACE or click/touch the screen\n\
|
||||
To exit, press ESC\n\
|
||||
====================================================================================\n");
|
||||
|
||||
/* Initialize mapping with GUID and name */
|
||||
SDL_JoystickGetGUIDString(SDL_JoystickGetGUID(joystick), temp, SDL_arraysize(temp));
|
||||
SDL_snprintf(mapping, SDL_arraysize(mapping), "%s,%s,platform:%s,",
|
||||
temp, name ? name : "Unknown Joystick", SDL_GetPlatform());
|
||||
|
||||
nJoystickID = SDL_JoystickInstanceID(joystick);
|
||||
|
||||
s_nNumAxes = SDL_JoystickNumAxes(joystick);
|
||||
s_arrAxisState = (AxisState *)SDL_calloc(s_nNumAxes, sizeof(*s_arrAxisState));
|
||||
for (iIndex = 0; iIndex < s_nNumAxes; ++iIndex) {
|
||||
AxisState *pAxisState = &s_arrAxisState[iIndex];
|
||||
Sint16 nInitialValue;
|
||||
pAxisState->m_bMoving = SDL_JoystickGetAxisInitialState(joystick, iIndex, &nInitialValue);
|
||||
pAxisState->m_nStartingValue = nInitialValue;
|
||||
pAxisState->m_nFarthestValue = nInitialValue;
|
||||
}
|
||||
|
||||
/* Loop, getting joystick events! */
|
||||
for(s=0; s<SDL_arraysize(steps) && !done;) {
|
||||
/* blank screen, set up for drawing this frame. */
|
||||
step = &steps[s];
|
||||
SDL_strlcpy(step->mapping, mapping, SDL_arraysize(step->mapping));
|
||||
step->axis = -1;
|
||||
step->button = -1;
|
||||
step->hat = -1;
|
||||
step->hat_value = -1;
|
||||
|
||||
switch(step->marker) {
|
||||
while (!done && !s_bBindingComplete) {
|
||||
int iElement = s_arrBindingOrder[s_iCurrentBinding];
|
||||
|
||||
switch (s_arrBindingDisplay[iElement].marker) {
|
||||
case MARKER_AXIS:
|
||||
marker = axis;
|
||||
break;
|
||||
|
|
@ -200,137 +433,271 @@ WatchJoystick(SDL_Joystick * joystick)
|
|||
break;
|
||||
}
|
||||
|
||||
dst.x = step->x;
|
||||
dst.y = step->y;
|
||||
dst.x = s_arrBindingDisplay[iElement].x;
|
||||
dst.y = s_arrBindingDisplay[iElement].y;
|
||||
SDL_QueryTexture(marker, NULL, NULL, &dst.w, &dst.h);
|
||||
next=SDL_FALSE;
|
||||
|
||||
SDL_SetRenderDrawColor(screen, 0xFF, 0xFF, 0xFF, SDL_ALPHA_OPAQUE);
|
||||
|
||||
while (!done && !next) {
|
||||
if (SDL_GetTicks() - alpha_ticks > 5) {
|
||||
alpha_ticks = SDL_GetTicks();
|
||||
alpha += alpha_step;
|
||||
if (alpha == 255) {
|
||||
alpha_step = -1;
|
||||
}
|
||||
if (alpha < 128) {
|
||||
alpha_step = 1;
|
||||
}
|
||||
if (SDL_GetTicks() - alpha_ticks > 5) {
|
||||
alpha_ticks = SDL_GetTicks();
|
||||
alpha += alpha_step;
|
||||
if (alpha == 255) {
|
||||
alpha_step = -1;
|
||||
}
|
||||
|
||||
SDL_RenderClear(screen);
|
||||
SDL_RenderCopy(screen, background, NULL, NULL);
|
||||
SDL_SetTextureAlphaMod(marker, alpha);
|
||||
SDL_SetTextureColorMod(marker, 10, 255, 21);
|
||||
SDL_RenderCopyEx(screen, marker, NULL, &dst, step->angle, NULL, SDL_FLIP_NONE);
|
||||
SDL_RenderPresent(screen);
|
||||
|
||||
if (SDL_PollEvent(&event)) {
|
||||
switch (event.type) {
|
||||
case SDL_JOYAXISMOTION:
|
||||
if ((event.jaxis.value > 20000 || event.jaxis.value < -20000) && event.jaxis.value != -32768) {
|
||||
for (_s = 0; _s < s; _s++) {
|
||||
if (steps[_s].axis == event.jaxis.axis) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (_s == s) {
|
||||
step->axis = event.jaxis.axis;
|
||||
SDL_strlcat(mapping, step->field, SDL_arraysize(mapping));
|
||||
SDL_snprintf(temp, SDL_arraysize(temp), ":a%u,", event.jaxis.axis);
|
||||
SDL_strlcat(mapping, temp, SDL_arraysize(mapping));
|
||||
s++;
|
||||
next=SDL_TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
case SDL_JOYHATMOTION:
|
||||
if (event.jhat.value == SDL_HAT_CENTERED) {
|
||||
break; /* ignore centering, we're probably just coming back to the center from the previous item we set. */
|
||||
}
|
||||
for (_s = 0; _s < s; _s++) {
|
||||
if (steps[_s].hat == event.jhat.hat && steps[_s].hat_value == event.jhat.value) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (_s == s) {
|
||||
step->hat = event.jhat.hat;
|
||||
step->hat_value = event.jhat.value;
|
||||
SDL_strlcat(mapping, step->field, SDL_arraysize(mapping));
|
||||
SDL_snprintf(temp, SDL_arraysize(temp), ":h%u.%u,", event.jhat.hat, event.jhat.value );
|
||||
SDL_strlcat(mapping, temp, SDL_arraysize(mapping));
|
||||
s++;
|
||||
next=SDL_TRUE;
|
||||
}
|
||||
break;
|
||||
case SDL_JOYBALLMOTION:
|
||||
break;
|
||||
case SDL_JOYBUTTONUP:
|
||||
for (_s = 0; _s < s; _s++) {
|
||||
if (steps[_s].button == event.jbutton.button) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (_s == s) {
|
||||
step->button = event.jbutton.button;
|
||||
SDL_strlcat(mapping, step->field, SDL_arraysize(mapping));
|
||||
SDL_snprintf(temp, SDL_arraysize(temp), ":b%u,", event.jbutton.button);
|
||||
SDL_strlcat(mapping, temp, SDL_arraysize(mapping));
|
||||
s++;
|
||||
next=SDL_TRUE;
|
||||
}
|
||||
break;
|
||||
case SDL_FINGERDOWN:
|
||||
case SDL_MOUSEBUTTONDOWN:
|
||||
/* Skip this step */
|
||||
s++;
|
||||
next=SDL_TRUE;
|
||||
break;
|
||||
case SDL_KEYDOWN:
|
||||
if (event.key.keysym.sym == SDLK_BACKSPACE || event.key.keysym.sym == SDLK_AC_BACK) {
|
||||
/* Undo! */
|
||||
if (s > 0) {
|
||||
prev_step = &steps[--s];
|
||||
SDL_strlcpy(mapping, prev_step->mapping, SDL_arraysize(prev_step->mapping));
|
||||
next = SDL_TRUE;
|
||||
}
|
||||
break;
|
||||
}
|
||||
if (event.key.keysym.sym == SDLK_SPACE) {
|
||||
/* Skip this step */
|
||||
s++;
|
||||
next=SDL_TRUE;
|
||||
break;
|
||||
}
|
||||
|
||||
if ((event.key.keysym.sym != SDLK_ESCAPE)) {
|
||||
break;
|
||||
}
|
||||
/* Fall through to signal quit */
|
||||
case SDL_QUIT:
|
||||
done = SDL_TRUE;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
if (alpha < 128) {
|
||||
alpha_step = 1;
|
||||
}
|
||||
}
|
||||
|
||||
SDL_SetRenderDrawColor(screen, 0xFF, 0xFF, 0xFF, SDL_ALPHA_OPAQUE);
|
||||
SDL_RenderClear(screen);
|
||||
SDL_RenderCopy(screen, background, NULL, NULL);
|
||||
SDL_SetTextureAlphaMod(marker, alpha);
|
||||
SDL_SetTextureColorMod(marker, 10, 255, 21);
|
||||
SDL_RenderCopyEx(screen, marker, NULL, &dst, s_arrBindingDisplay[iElement].angle, NULL, SDL_FLIP_NONE);
|
||||
SDL_RenderPresent(screen);
|
||||
|
||||
while (SDL_PollEvent(&event) > 0) {
|
||||
switch (event.type) {
|
||||
case SDL_JOYDEVICEREMOVED:
|
||||
if (event.jaxis.which == nJoystickID) {
|
||||
done = SDL_TRUE;
|
||||
}
|
||||
break;
|
||||
case SDL_JOYAXISMOTION:
|
||||
if (event.jaxis.which == nJoystickID) {
|
||||
AxisState *pAxisState = &s_arrAxisState[event.jaxis.axis];
|
||||
int nValue = event.jaxis.value;
|
||||
int nCurrentDistance, nFarthestDistance;
|
||||
if (!pAxisState->m_bMoving) {
|
||||
pAxisState->m_bMoving = SDL_TRUE;
|
||||
pAxisState->m_nStartingValue = nValue;
|
||||
pAxisState->m_nFarthestValue = nValue;
|
||||
}
|
||||
nCurrentDistance = SDL_abs(nValue - pAxisState->m_nStartingValue);
|
||||
nFarthestDistance = SDL_abs(pAxisState->m_nFarthestValue - pAxisState->m_nStartingValue);
|
||||
if (nCurrentDistance > nFarthestDistance) {
|
||||
pAxisState->m_nFarthestValue = nValue;
|
||||
nFarthestDistance = SDL_abs(pAxisState->m_nFarthestValue - pAxisState->m_nStartingValue);
|
||||
}
|
||||
|
||||
#ifdef DEBUG_CONTROLLERMAP
|
||||
SDL_Log("AXIS %d nValue %d nCurrentDistance %d nFarthestDistance %d\n", event.jaxis.axis, nValue, nCurrentDistance, nFarthestDistance);
|
||||
#endif
|
||||
if (nFarthestDistance >= 16000) {
|
||||
/* If we've gone out far enough and started to come back, let's bind this axis */
|
||||
SDL_bool bCommitBinding = (nCurrentDistance <= 10000) ? SDL_TRUE : SDL_FALSE;
|
||||
SDL_GameControllerExtendedBind binding;
|
||||
SDL_zero(binding);
|
||||
binding.bindType = SDL_CONTROLLER_BINDTYPE_AXIS;
|
||||
binding.value.axis.axis = event.jaxis.axis;
|
||||
binding.value.axis.axis_min = StandardizeAxisValue(pAxisState->m_nStartingValue);
|
||||
binding.value.axis.axis_max = StandardizeAxisValue(pAxisState->m_nFarthestValue);
|
||||
binding.committed = bCommitBinding;
|
||||
ConfigureBinding(&binding);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case SDL_JOYHATMOTION:
|
||||
if (event.jhat.which == nJoystickID) {
|
||||
if (event.jhat.value != SDL_HAT_CENTERED) {
|
||||
SDL_GameControllerExtendedBind binding;
|
||||
|
||||
#ifdef DEBUG_CONTROLLERMAP
|
||||
SDL_Log("HAT %d %d\n", event.jhat.hat, event.jhat.value);
|
||||
#endif
|
||||
SDL_zero(binding);
|
||||
binding.bindType = SDL_CONTROLLER_BINDTYPE_HAT;
|
||||
binding.value.hat.hat = event.jhat.hat;
|
||||
binding.value.hat.hat_mask = event.jhat.value;
|
||||
binding.committed = SDL_TRUE;
|
||||
ConfigureBinding(&binding);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case SDL_JOYBALLMOTION:
|
||||
break;
|
||||
case SDL_JOYBUTTONDOWN:
|
||||
if (event.jbutton.which == nJoystickID) {
|
||||
SDL_GameControllerExtendedBind binding;
|
||||
|
||||
#ifdef DEBUG_CONTROLLERMAP
|
||||
SDL_Log("BUTTON %d\n", event.jbutton.button);
|
||||
#endif
|
||||
SDL_zero(binding);
|
||||
binding.bindType = SDL_CONTROLLER_BINDTYPE_BUTTON;
|
||||
binding.value.button = event.jbutton.button;
|
||||
binding.committed = SDL_TRUE;
|
||||
ConfigureBinding(&binding);
|
||||
}
|
||||
break;
|
||||
case SDL_FINGERDOWN:
|
||||
case SDL_MOUSEBUTTONDOWN:
|
||||
/* Skip this step */
|
||||
SetCurrentBinding(s_iCurrentBinding + 1);
|
||||
break;
|
||||
case SDL_KEYDOWN:
|
||||
if (event.key.keysym.sym == SDLK_BACKSPACE || event.key.keysym.sym == SDLK_AC_BACK) {
|
||||
SetCurrentBinding(s_iCurrentBinding - 1);
|
||||
break;
|
||||
}
|
||||
if (event.key.keysym.sym == SDLK_SPACE) {
|
||||
SetCurrentBinding(s_iCurrentBinding + 1);
|
||||
break;
|
||||
}
|
||||
|
||||
if ((event.key.keysym.sym != SDLK_ESCAPE)) {
|
||||
break;
|
||||
}
|
||||
/* Fall through to signal quit */
|
||||
case SDL_QUIT:
|
||||
done = SDL_TRUE;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
SDL_Delay(15);
|
||||
|
||||
/* Wait 100 ms for joystick events to stop coming in,
|
||||
in case a controller sends multiple events for a single control (e.g. axis and button for trigger)
|
||||
*/
|
||||
if (s_unPendingAdvanceTime && SDL_GetTicks() - s_unPendingAdvanceTime >= 100) {
|
||||
SetCurrentBinding(s_iCurrentBinding + 1);
|
||||
}
|
||||
}
|
||||
|
||||
if (s == SDL_arraysize(steps) ) {
|
||||
if (s_bBindingComplete) {
|
||||
char mapping[1024];
|
||||
char trimmed_name[128];
|
||||
char *spot;
|
||||
int iIndex;
|
||||
char pszElement[12];
|
||||
|
||||
SDL_strlcpy(trimmed_name, name, SDL_arraysize(trimmed_name));
|
||||
while (SDL_isspace(trimmed_name[0])) {
|
||||
SDL_memmove(&trimmed_name[0], &trimmed_name[1], SDL_strlen(trimmed_name));
|
||||
}
|
||||
while (trimmed_name[0] && SDL_isspace(trimmed_name[SDL_strlen(trimmed_name) - 1])) {
|
||||
trimmed_name[SDL_strlen(trimmed_name) - 1] = '\0';
|
||||
}
|
||||
while ((spot = SDL_strchr(trimmed_name, ',')) != NULL) {
|
||||
SDL_memmove(spot, spot + 1, SDL_strlen(spot));
|
||||
}
|
||||
|
||||
/* Initialize mapping with GUID and name */
|
||||
SDL_JoystickGetGUIDString(SDL_JoystickGetGUID(joystick), mapping, SDL_arraysize(mapping));
|
||||
SDL_strlcat(mapping, ",", SDL_arraysize(mapping));
|
||||
SDL_strlcat(mapping, trimmed_name, SDL_arraysize(mapping));
|
||||
SDL_strlcat(mapping, ",", SDL_arraysize(mapping));
|
||||
SDL_strlcat(mapping, "platform:", SDL_arraysize(mapping));
|
||||
SDL_strlcat(mapping, SDL_GetPlatform(), SDL_arraysize(mapping));
|
||||
SDL_strlcat(mapping, ",", SDL_arraysize(mapping));
|
||||
|
||||
for (iIndex = 0; iIndex < SDL_arraysize(s_arrBindings); ++iIndex) {
|
||||
SDL_GameControllerExtendedBind *pBinding = &s_arrBindings[iIndex];
|
||||
if (pBinding->bindType == SDL_CONTROLLER_BINDTYPE_NONE) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (iIndex < SDL_CONTROLLER_BUTTON_MAX) {
|
||||
SDL_GameControllerButton eButton = (SDL_GameControllerButton)iIndex;
|
||||
SDL_strlcat(mapping, SDL_GameControllerGetStringForButton(eButton), SDL_arraysize(mapping));
|
||||
} else {
|
||||
const char *pszAxisName;
|
||||
switch (iIndex - SDL_CONTROLLER_BUTTON_MAX) {
|
||||
case SDL_CONTROLLER_BINDING_AXIS_LEFTX_NEGATIVE:
|
||||
if (!BMergeAxisBindings(iIndex)) {
|
||||
SDL_strlcat(mapping, "-", SDL_arraysize(mapping));
|
||||
}
|
||||
pszAxisName = SDL_GameControllerGetStringForAxis(SDL_CONTROLLER_AXIS_LEFTX);
|
||||
break;
|
||||
case SDL_CONTROLLER_BINDING_AXIS_LEFTX_POSITIVE:
|
||||
SDL_strlcat(mapping, "+", SDL_arraysize(mapping));
|
||||
pszAxisName = SDL_GameControllerGetStringForAxis(SDL_CONTROLLER_AXIS_LEFTX);
|
||||
break;
|
||||
case SDL_CONTROLLER_BINDING_AXIS_LEFTY_NEGATIVE:
|
||||
if (!BMergeAxisBindings(iIndex)) {
|
||||
SDL_strlcat(mapping, "-", SDL_arraysize(mapping));
|
||||
}
|
||||
pszAxisName = SDL_GameControllerGetStringForAxis(SDL_CONTROLLER_AXIS_LEFTY);
|
||||
break;
|
||||
case SDL_CONTROLLER_BINDING_AXIS_LEFTY_POSITIVE:
|
||||
SDL_strlcat(mapping, "+", SDL_arraysize(mapping));
|
||||
pszAxisName = SDL_GameControllerGetStringForAxis(SDL_CONTROLLER_AXIS_LEFTY);
|
||||
break;
|
||||
case SDL_CONTROLLER_BINDING_AXIS_RIGHTX_NEGATIVE:
|
||||
if (!BMergeAxisBindings(iIndex)) {
|
||||
SDL_strlcat(mapping, "-", SDL_arraysize(mapping));
|
||||
}
|
||||
pszAxisName = SDL_GameControllerGetStringForAxis(SDL_CONTROLLER_AXIS_RIGHTX);
|
||||
break;
|
||||
case SDL_CONTROLLER_BINDING_AXIS_RIGHTX_POSITIVE:
|
||||
SDL_strlcat(mapping, "+", SDL_arraysize(mapping));
|
||||
pszAxisName = SDL_GameControllerGetStringForAxis(SDL_CONTROLLER_AXIS_RIGHTX);
|
||||
break;
|
||||
case SDL_CONTROLLER_BINDING_AXIS_RIGHTY_NEGATIVE:
|
||||
if (!BMergeAxisBindings(iIndex)) {
|
||||
SDL_strlcat(mapping, "-", SDL_arraysize(mapping));
|
||||
}
|
||||
pszAxisName = SDL_GameControllerGetStringForAxis(SDL_CONTROLLER_AXIS_RIGHTY);
|
||||
break;
|
||||
case SDL_CONTROLLER_BINDING_AXIS_RIGHTY_POSITIVE:
|
||||
SDL_strlcat(mapping, "+", SDL_arraysize(mapping));
|
||||
pszAxisName = SDL_GameControllerGetStringForAxis(SDL_CONTROLLER_AXIS_RIGHTY);
|
||||
break;
|
||||
case SDL_CONTROLLER_BINDING_AXIS_TRIGGERLEFT:
|
||||
pszAxisName = SDL_GameControllerGetStringForAxis(SDL_CONTROLLER_AXIS_TRIGGERLEFT);
|
||||
break;
|
||||
case SDL_CONTROLLER_BINDING_AXIS_TRIGGERRIGHT:
|
||||
pszAxisName = SDL_GameControllerGetStringForAxis(SDL_CONTROLLER_AXIS_TRIGGERRIGHT);
|
||||
break;
|
||||
}
|
||||
SDL_strlcat(mapping, pszAxisName, SDL_arraysize(mapping));
|
||||
}
|
||||
SDL_strlcat(mapping, ":", SDL_arraysize(mapping));
|
||||
|
||||
pszElement[0] = '\0';
|
||||
switch (pBinding->bindType) {
|
||||
case SDL_CONTROLLER_BINDTYPE_BUTTON:
|
||||
SDL_snprintf(pszElement, sizeof(pszElement), "b%d", pBinding->value.button);
|
||||
break;
|
||||
case SDL_CONTROLLER_BINDTYPE_AXIS:
|
||||
if (pBinding->value.axis.axis_min == 0 && pBinding->value.axis.axis_max == SDL_JOYSTICK_AXIS_MIN) {
|
||||
/* The negative half axis */
|
||||
SDL_snprintf(pszElement, sizeof(pszElement), "-a%d", pBinding->value.axis.axis);
|
||||
} else if (pBinding->value.axis.axis_min == 0 && pBinding->value.axis.axis_max == SDL_JOYSTICK_AXIS_MAX) {
|
||||
/* The positive half axis */
|
||||
SDL_snprintf(pszElement, sizeof(pszElement), "+a%d", pBinding->value.axis.axis);
|
||||
} else {
|
||||
SDL_snprintf(pszElement, sizeof(pszElement), "a%d", pBinding->value.axis.axis);
|
||||
if (pBinding->value.axis.axis_min > pBinding->value.axis.axis_max) {
|
||||
/* Invert the axis */
|
||||
SDL_strlcat(pszElement, "~", SDL_arraysize(pszElement));
|
||||
}
|
||||
}
|
||||
break;
|
||||
case SDL_CONTROLLER_BINDTYPE_HAT:
|
||||
SDL_snprintf(pszElement, sizeof(pszElement), "h%d.%d", pBinding->value.hat.hat, pBinding->value.hat.hat_mask);
|
||||
break;
|
||||
default:
|
||||
SDL_assert(!"Unknown bind type");
|
||||
break;
|
||||
}
|
||||
SDL_strlcat(mapping, pszElement, SDL_arraysize(mapping));
|
||||
SDL_strlcat(mapping, ",", SDL_arraysize(mapping));
|
||||
}
|
||||
|
||||
SDL_Log("Mapping:\n\n%s\n\n", mapping);
|
||||
/* Print to stdout as well so the user can cat the output somewhere */
|
||||
printf("%s\n", mapping);
|
||||
}
|
||||
|
||||
while(SDL_PollEvent(&event)) {};
|
||||
|
||||
SDL_free(s_arrAxisState);
|
||||
s_arrAxisState = NULL;
|
||||
|
||||
SDL_DestroyRenderer(screen);
|
||||
SDL_DestroyWindow(window);
|
||||
return retval;
|
||||
}
|
||||
|
||||
int
|
||||
|
|
@ -368,6 +735,7 @@ main(int argc, char *argv[])
|
|||
SDL_Log(" buttons: %d\n", SDL_JoystickNumButtons(joystick));
|
||||
SDL_Log("instance id: %d\n", SDL_JoystickInstanceID(joystick));
|
||||
SDL_Log(" guid: %s\n", guid);
|
||||
SDL_Log(" VID/PID: 0x%.4x/0x%.4x\n", SDL_JoystickGetVendor(joystick), SDL_JoystickGetProduct(joystick));
|
||||
SDL_JoystickClose(joystick);
|
||||
}
|
||||
}
|
||||
|
|
@ -377,9 +745,6 @@ main(int argc, char *argv[])
|
|||
#else
|
||||
if (argv[1]) {
|
||||
#endif
|
||||
SDL_bool reportederror = SDL_FALSE;
|
||||
SDL_bool keepGoing = SDL_TRUE;
|
||||
SDL_Event event;
|
||||
int device;
|
||||
#ifdef __ANDROID__
|
||||
device = 0;
|
||||
|
|
@ -387,34 +752,11 @@ main(int argc, char *argv[])
|
|||
device = atoi(argv[1]);
|
||||
#endif
|
||||
joystick = SDL_JoystickOpen(device);
|
||||
|
||||
while ( keepGoing ) {
|
||||
if (joystick == NULL) {
|
||||
if ( !reportederror ) {
|
||||
SDL_Log("Couldn't open joystick %d: %s\n", device, SDL_GetError());
|
||||
keepGoing = SDL_FALSE;
|
||||
reportederror = SDL_TRUE;
|
||||
}
|
||||
} else {
|
||||
reportederror = SDL_FALSE;
|
||||
keepGoing = WatchJoystick(joystick);
|
||||
SDL_JoystickClose(joystick);
|
||||
}
|
||||
|
||||
joystick = NULL;
|
||||
if (keepGoing) {
|
||||
SDL_Log("Waiting for attach\n");
|
||||
}
|
||||
while (keepGoing) {
|
||||
SDL_WaitEvent(&event);
|
||||
if ((event.type == SDL_QUIT) || (event.type == SDL_FINGERDOWN)
|
||||
|| (event.type == SDL_MOUSEBUTTONDOWN)) {
|
||||
keepGoing = SDL_FALSE;
|
||||
} else if (event.type == SDL_JOYDEVICEADDED) {
|
||||
joystick = SDL_JoystickOpen(device);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (joystick == NULL) {
|
||||
SDL_Log("Couldn't open joystick %d: %s\n", device, SDL_GetError());
|
||||
} else {
|
||||
WatchJoystick(joystick);
|
||||
SDL_JoystickClose(joystick);
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
|
@ -435,3 +777,5 @@ main(int argc, char *argv[])
|
|||
}
|
||||
|
||||
#endif
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2018 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
|
||||
|
|
@ -20,17 +20,13 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#if HAVE_SIGNAL_H
|
||||
#include <signal.h>
|
||||
#endif
|
||||
|
||||
#ifdef __EMSCRIPTEN__
|
||||
#include <emscripten/emscripten.h>
|
||||
#endif
|
||||
|
||||
#include "SDL.h"
|
||||
|
||||
struct
|
||||
static struct
|
||||
{
|
||||
SDL_AudioSpec spec;
|
||||
Uint8 *sound; /* Pointer to wave data */
|
||||
|
|
@ -38,6 +34,7 @@ struct
|
|||
int soundpos; /* Current play position */
|
||||
} wave;
|
||||
|
||||
static SDL_AudioDeviceID device;
|
||||
|
||||
/* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */
|
||||
static void
|
||||
|
|
@ -47,6 +44,37 @@ quit(int rc)
|
|||
exit(rc);
|
||||
}
|
||||
|
||||
static void
|
||||
close_audio()
|
||||
{
|
||||
if (device != 0) {
|
||||
SDL_CloseAudioDevice(device);
|
||||
device = 0;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
open_audio()
|
||||
{
|
||||
/* Initialize fillerup() variables */
|
||||
device = SDL_OpenAudioDevice(NULL, SDL_FALSE, &wave.spec, NULL, 0);
|
||||
if (!device) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't open audio: %s\n", SDL_GetError());
|
||||
SDL_FreeWAV(wave.sound);
|
||||
quit(2);
|
||||
}
|
||||
|
||||
|
||||
/* Let the audio run */
|
||||
SDL_PauseAudioDevice(device, SDL_FALSE);
|
||||
}
|
||||
|
||||
static void reopen_audio()
|
||||
{
|
||||
close_audio();
|
||||
open_audio();
|
||||
}
|
||||
|
||||
|
||||
void SDLCALL
|
||||
fillerup(void *unused, Uint8 * stream, int len)
|
||||
|
|
@ -72,17 +100,12 @@ fillerup(void *unused, Uint8 * stream, int len)
|
|||
}
|
||||
|
||||
static int done = 0;
|
||||
void
|
||||
poked(int sig)
|
||||
{
|
||||
done = 1;
|
||||
}
|
||||
|
||||
#ifdef __EMSCRIPTEN__
|
||||
void
|
||||
loop()
|
||||
{
|
||||
if(done || (SDL_GetAudioStatus() != SDL_AUDIO_PLAYING))
|
||||
if(done || (SDL_GetAudioDeviceStatus(device) != SDL_AUDIO_PLAYING))
|
||||
emscripten_cancel_main_loop();
|
||||
}
|
||||
#endif
|
||||
|
|
@ -97,7 +120,7 @@ main(int argc, char *argv[])
|
|||
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
|
||||
|
||||
/* Load the SDL library */
|
||||
if (SDL_Init(SDL_INIT_AUDIO) < 0) {
|
||||
if (SDL_Init(SDL_INIT_AUDIO|SDL_INIT_EVENTS) < 0) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL: %s\n", SDL_GetError());
|
||||
return (1);
|
||||
}
|
||||
|
|
@ -114,17 +137,6 @@ main(int argc, char *argv[])
|
|||
}
|
||||
|
||||
wave.spec.callback = fillerup;
|
||||
#if HAVE_SIGNAL_H
|
||||
/* Set the signals */
|
||||
#ifdef SIGHUP
|
||||
signal(SIGHUP, poked);
|
||||
#endif
|
||||
signal(SIGINT, poked);
|
||||
#ifdef SIGQUIT
|
||||
signal(SIGQUIT, poked);
|
||||
#endif
|
||||
signal(SIGTERM, poked);
|
||||
#endif /* HAVE_SIGNAL_H */
|
||||
|
||||
/* Show the list of available drivers */
|
||||
SDL_Log("Available audio drivers:");
|
||||
|
|
@ -132,27 +144,33 @@ main(int argc, char *argv[])
|
|||
SDL_Log("%i: %s", i, SDL_GetAudioDriver(i));
|
||||
}
|
||||
|
||||
/* Initialize fillerup() variables */
|
||||
if (SDL_OpenAudio(&wave.spec, NULL) < 0) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't open audio: %s\n", SDL_GetError());
|
||||
SDL_FreeWAV(wave.sound);
|
||||
quit(2);
|
||||
}
|
||||
|
||||
SDL_Log("Using audio driver: %s\n", SDL_GetCurrentAudioDriver());
|
||||
|
||||
/* Let the audio run */
|
||||
SDL_PauseAudio(0);
|
||||
open_audio();
|
||||
|
||||
SDL_FlushEvents(SDL_AUDIODEVICEADDED, SDL_AUDIODEVICEREMOVED);
|
||||
|
||||
#ifdef __EMSCRIPTEN__
|
||||
emscripten_set_main_loop(loop, 0, 1);
|
||||
#else
|
||||
while (!done && (SDL_GetAudioStatus() == SDL_AUDIO_PLAYING))
|
||||
SDL_Delay(1000);
|
||||
while (!done) {
|
||||
SDL_Event event;
|
||||
|
||||
while (SDL_PollEvent(&event) > 0) {
|
||||
if (event.type == SDL_QUIT) {
|
||||
done = 1;
|
||||
}
|
||||
if ((event.type == SDL_AUDIODEVICEADDED && !event.adevice.iscapture) ||
|
||||
(event.type == SDL_AUDIODEVICEREMOVED && !event.adevice.iscapture && event.adevice.which == device)) {
|
||||
reopen_audio();
|
||||
}
|
||||
}
|
||||
SDL_Delay(100);
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Clean up on signal */
|
||||
SDL_CloseAudio();
|
||||
close_audio();
|
||||
SDL_FreeWAV(wave.sound);
|
||||
SDL_Quit();
|
||||
return (0);
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2018 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
|
||||
|
|
@ -25,12 +25,11 @@
|
|||
#include <signal.h>
|
||||
#endif
|
||||
|
||||
struct
|
||||
static struct
|
||||
{
|
||||
SDL_AudioSpec spec;
|
||||
Uint8 *sound; /* Pointer to wave data */
|
||||
Uint32 soundlen; /* Length of wave data */
|
||||
int soundpos; /* Current play position */
|
||||
} wave;
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -39,7 +39,7 @@ var common = (function() {
|
|||
mimetype = 'application/x-ppapi-release';
|
||||
else
|
||||
mimetype = 'application/x-ppapi-debug';
|
||||
} else if (tool == 'pnacl' && isRelease) {
|
||||
} else if (tool == 'pnacl') {
|
||||
mimetype = 'application/x-pnacl';
|
||||
}
|
||||
return mimetype;
|
||||
|
|
@ -147,6 +147,11 @@ var common = (function() {
|
|||
var listenerDiv = document.getElementById('listener');
|
||||
listenerDiv.appendChild(moduleEl);
|
||||
|
||||
// Request the offsetTop property to force a relayout. As of Apr 10, 2014
|
||||
// this is needed if the module is being loaded on a Chrome App's
|
||||
// background page (see crbug.com/350445).
|
||||
moduleEl.offsetTop;
|
||||
|
||||
// Host plugins don't send a moduleDidLoad message. We'll fake it here.
|
||||
var isHost = isHostToolchain(tool);
|
||||
if (isHost) {
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2018 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
|
||||
|
|
@ -103,7 +103,10 @@ void RunBasicTest()
|
|||
#define NInter (CountTo/CountInc/NThreads)
|
||||
#define Expect (CountTo-NInter*CountInc*NThreads)
|
||||
|
||||
SDL_COMPILE_TIME_ASSERT(size, CountTo>0); /* check for rollover */
|
||||
enum {
|
||||
CountTo_GreaterThanZero = CountTo > 0,
|
||||
};
|
||||
SDL_COMPILE_TIME_ASSERT(size, CountTo_GreaterThanZero); /* check for rollover */
|
||||
|
||||
static SDL_atomic_t good = { 42 };
|
||||
|
||||
|
|
@ -114,7 +117,7 @@ static SDL_atomic_t threadsRunning;
|
|||
static SDL_sem *threadDone;
|
||||
|
||||
static
|
||||
int adder(void* junk)
|
||||
int SDLCALL adder(void* junk)
|
||||
{
|
||||
unsigned long N=NInter;
|
||||
SDL_Log("Thread subtracting %d %lu times\n",CountInc,N);
|
||||
|
|
@ -492,7 +495,7 @@ typedef struct
|
|||
char padding[SDL_CACHELINE_SIZE-(sizeof(SDL_EventQueue*)+sizeof(int)*NUM_WRITERS+sizeof(int)+sizeof(SDL_bool))%SDL_CACHELINE_SIZE];
|
||||
} ReaderData;
|
||||
|
||||
static int FIFO_Writer(void* _data)
|
||||
static int SDLCALL FIFO_Writer(void* _data)
|
||||
{
|
||||
WriterData *data = (WriterData *)_data;
|
||||
SDL_EventQueue *queue = data->queue;
|
||||
|
|
@ -527,7 +530,7 @@ static int FIFO_Writer(void* _data)
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int FIFO_Reader(void* _data)
|
||||
static int SDLCALL FIFO_Reader(void* _data)
|
||||
{
|
||||
ReaderData *data = (ReaderData *)_data;
|
||||
SDL_EventQueue *queue = data->queue;
|
||||
|
|
@ -567,7 +570,7 @@ static int FIFO_Reader(void* _data)
|
|||
|
||||
#ifdef TEST_SPINLOCK_FIFO
|
||||
/* This thread periodically locks the queue for no particular reason */
|
||||
static int FIFO_Watcher(void* _data)
|
||||
static int SDLCALL FIFO_Watcher(void* _data)
|
||||
{
|
||||
SDL_EventQueue *queue = (SDL_EventQueue *)_data;
|
||||
|
||||
|
|
@ -597,7 +600,7 @@ static void RunFIFOTest(SDL_bool lock_free)
|
|||
int i, j;
|
||||
int grand_total;
|
||||
char textBuffer[1024];
|
||||
int len;
|
||||
size_t len;
|
||||
|
||||
SDL_Log("\nFIFO test---------------------------------------\n\n");
|
||||
SDL_Log("Mode: %s\n", lock_free ? "LockFree" : "Mutex");
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2018 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,5 +1,5 @@
|
|||
/*
|
||||
Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2018 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,5 +1,5 @@
|
|||
/*
|
||||
Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2018 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,5 +1,5 @@
|
|||
/*
|
||||
Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2018 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
|
||||
|
|
|
|||
|
|
@ -46,7 +46,7 @@ int _audio_testCallbackLength;
|
|||
|
||||
|
||||
/* Test callback function */
|
||||
void _audio_testCallback(void *userdata, Uint8 *stream, int len)
|
||||
void SDLCALL _audio_testCallback(void *userdata, Uint8 *stream, int len)
|
||||
{
|
||||
/* track that callback was called */
|
||||
_audio_testCallbackCounter++;
|
||||
|
|
|
|||
|
|
@ -121,7 +121,7 @@ clipboard_testClipboardTextFunctions(void *arg)
|
|||
SDLTest_AssertCheck(
|
||||
charResult[0] == '\0',
|
||||
"Verify SDL_GetClipboardText returned string with length 0, got length %i",
|
||||
SDL_strlen(charResult));
|
||||
(int) SDL_strlen(charResult));
|
||||
intResult = SDL_SetClipboardText((const char *)text);
|
||||
SDLTest_AssertPass("Call to SDL_SetClipboardText succeeded");
|
||||
SDLTest_AssertCheck(
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ int _userdataValue1 = 1;
|
|||
int _userdataValue2 = 2;
|
||||
|
||||
/* Event filter that sets some flags and optionally checks userdata */
|
||||
int _events_sampleNullEventFilter(void *userdata, SDL_Event *event)
|
||||
int SDLCALL _events_sampleNullEventFilter(void *userdata, SDL_Event *event)
|
||||
{
|
||||
_eventFilterCalled = 1;
|
||||
|
||||
|
|
|
|||
|
|
@ -312,7 +312,7 @@ keyboard_getSetModState(void *arg)
|
|||
/* Get state, cache for later reset */
|
||||
result = SDL_GetModState();
|
||||
SDLTest_AssertPass("Call to SDL_GetModState()");
|
||||
SDLTest_AssertCheck(result >=0 && result <= allStates, "Verify result from call is valid, expected: 0 <= result <= %i, got: %i", allStates, result);
|
||||
SDLTest_AssertCheck(/*result >= 0 &&*/ result <= allStates, "Verify result from call is valid, expected: 0 <= result <= %i, got: %i", allStates, result);
|
||||
currentState = result;
|
||||
|
||||
/* Set random state */
|
||||
|
|
|
|||
|
|
@ -447,11 +447,23 @@ mouse_warpMouseInWindow(void *arg)
|
|||
{
|
||||
const int w = MOUSE_TESTWINDOW_WIDTH, h = MOUSE_TESTWINDOW_HEIGHT;
|
||||
int numPositions = 6;
|
||||
int xPositions[] = {-1, 0, 1, w-1, w, w+1 };
|
||||
int yPositions[] = {-1, 0, 1, h-1, h, h+1 };
|
||||
int xPositions[6];
|
||||
int yPositions[6];
|
||||
int x, y, i, j;
|
||||
SDL_Window *window;
|
||||
|
||||
xPositions[0] = -1;
|
||||
xPositions[1] = 0;
|
||||
xPositions[2] = 1;
|
||||
xPositions[3] = w-1;
|
||||
xPositions[4] = w;
|
||||
xPositions[5] = w+1;
|
||||
yPositions[0] = -1;
|
||||
yPositions[1] = 0;
|
||||
yPositions[2] = 1;
|
||||
yPositions[3] = h-1;
|
||||
yPositions[4] = h;
|
||||
yPositions[5] = h+1;
|
||||
/* Create test window */
|
||||
window = _createMouseSuiteTestWindow();
|
||||
if (window == NULL) return TEST_ABORTED;
|
||||
|
|
|
|||
|
|
@ -112,7 +112,7 @@ int platform_testGetFunctions (void *arg)
|
|||
char *platform;
|
||||
char *revision;
|
||||
int ret;
|
||||
int len;
|
||||
size_t len;
|
||||
|
||||
platform = (char *)SDL_GetPlatform();
|
||||
SDLTest_AssertPass("SDL_GetPlatform()");
|
||||
|
|
@ -122,7 +122,7 @@ int platform_testGetFunctions (void *arg)
|
|||
SDLTest_AssertCheck(len > 0,
|
||||
"SDL_GetPlatform(): expected non-empty platform, was platform: '%s', len: %i",
|
||||
platform,
|
||||
len);
|
||||
(int) len);
|
||||
}
|
||||
|
||||
ret = SDL_GetCPUCount();
|
||||
|
|
@ -282,7 +282,7 @@ int platform_testGetSetClearError(void *arg)
|
|||
int result;
|
||||
const char *testError = "Testing";
|
||||
char *lastError;
|
||||
int len;
|
||||
size_t len;
|
||||
|
||||
SDL_ClearError();
|
||||
SDLTest_AssertPass("SDL_ClearError()");
|
||||
|
|
@ -295,7 +295,7 @@ int platform_testGetSetClearError(void *arg)
|
|||
{
|
||||
len = SDL_strlen(lastError);
|
||||
SDLTest_AssertCheck(len == 0,
|
||||
"SDL_GetError(): no message expected, len: %i", len);
|
||||
"SDL_GetError(): no message expected, len: %i", (int) len);
|
||||
}
|
||||
|
||||
result = SDL_SetError("%s", testError);
|
||||
|
|
@ -309,8 +309,8 @@ int platform_testGetSetClearError(void *arg)
|
|||
len = SDL_strlen(lastError);
|
||||
SDLTest_AssertCheck(len == SDL_strlen(testError),
|
||||
"SDL_GetError(): expected message len %i, was len: %i",
|
||||
SDL_strlen(testError),
|
||||
len);
|
||||
(int) SDL_strlen(testError),
|
||||
(int) len);
|
||||
SDLTest_AssertCheck(SDL_strcmp(lastError, testError) == 0,
|
||||
"SDL_GetError(): expected message %s, was message: %s",
|
||||
testError,
|
||||
|
|
@ -334,7 +334,7 @@ int platform_testSetErrorEmptyInput(void *arg)
|
|||
int result;
|
||||
const char *testError = "";
|
||||
char *lastError;
|
||||
int len;
|
||||
size_t len;
|
||||
|
||||
result = SDL_SetError("%s", testError);
|
||||
SDLTest_AssertPass("SDL_SetError()");
|
||||
|
|
@ -347,8 +347,8 @@ int platform_testSetErrorEmptyInput(void *arg)
|
|||
len = SDL_strlen(lastError);
|
||||
SDLTest_AssertCheck(len == SDL_strlen(testError),
|
||||
"SDL_GetError(): expected message len %i, was len: %i",
|
||||
SDL_strlen(testError),
|
||||
len);
|
||||
(int) SDL_strlen(testError),
|
||||
(int) len);
|
||||
SDLTest_AssertCheck(SDL_strcmp(lastError, testError) == 0,
|
||||
"SDL_GetError(): expected message '%s', was message: '%s'",
|
||||
testError,
|
||||
|
|
@ -373,14 +373,14 @@ int platform_testSetErrorInvalidInput(void *arg)
|
|||
const char *invalidError = NULL;
|
||||
const char *probeError = "Testing";
|
||||
char *lastError;
|
||||
int len;
|
||||
size_t len;
|
||||
|
||||
/* Reset */
|
||||
SDL_ClearError();
|
||||
SDLTest_AssertPass("SDL_ClearError()");
|
||||
|
||||
/* Check for no-op */
|
||||
result = SDL_SetError(invalidError);
|
||||
result = SDL_SetError("%s", invalidError);
|
||||
SDLTest_AssertPass("SDL_SetError()");
|
||||
SDLTest_AssertCheck(result == -1, "SDL_SetError: expected -1, got: %i", result);
|
||||
lastError = (char *)SDL_GetError();
|
||||
|
|
@ -391,16 +391,16 @@ int platform_testSetErrorInvalidInput(void *arg)
|
|||
len = SDL_strlen(lastError);
|
||||
SDLTest_AssertCheck(len == 0,
|
||||
"SDL_GetError(): expected message len 0, was len: %i",
|
||||
len);
|
||||
(int) len);
|
||||
}
|
||||
|
||||
/* Set */
|
||||
result = SDL_SetError(probeError);
|
||||
result = SDL_SetError("%s", probeError);
|
||||
SDLTest_AssertPass("SDL_SetError('%s')", probeError);
|
||||
SDLTest_AssertCheck(result == -1, "SDL_SetError: expected -1, got: %i", result);
|
||||
|
||||
/* Check for no-op */
|
||||
result = SDL_SetError(invalidError);
|
||||
result = SDL_SetError("%s", invalidError);
|
||||
SDLTest_AssertPass("SDL_SetError(NULL)");
|
||||
SDLTest_AssertCheck(result == -1, "SDL_SetError: expected -1, got: %i", result);
|
||||
lastError = (char *)SDL_GetError();
|
||||
|
|
@ -411,7 +411,7 @@ int platform_testSetErrorInvalidInput(void *arg)
|
|||
len = SDL_strlen(lastError);
|
||||
SDLTest_AssertCheck(len == 0,
|
||||
"SDL_GetError(): expected message len 0, was len: %i",
|
||||
len);
|
||||
(int) len);
|
||||
}
|
||||
|
||||
/* Reset */
|
||||
|
|
@ -419,7 +419,7 @@ int platform_testSetErrorInvalidInput(void *arg)
|
|||
SDLTest_AssertPass("SDL_ClearError()");
|
||||
|
||||
/* Set and check */
|
||||
result = SDL_SetError(probeError);
|
||||
result = SDL_SetError("%s", probeError);
|
||||
SDLTest_AssertPass("SDL_SetError()");
|
||||
SDLTest_AssertCheck(result == -1, "SDL_SetError: expected -1, got: %i", result);
|
||||
lastError = (char *)SDL_GetError();
|
||||
|
|
@ -430,8 +430,8 @@ int platform_testSetErrorInvalidInput(void *arg)
|
|||
len = SDL_strlen(lastError);
|
||||
SDLTest_AssertCheck(len == SDL_strlen(probeError),
|
||||
"SDL_GetError(): expected message len %i, was len: %i",
|
||||
SDL_strlen(probeError),
|
||||
len);
|
||||
(int) SDL_strlen(probeError),
|
||||
(int) len);
|
||||
SDLTest_AssertCheck(SDL_strcmp(lastError, probeError) == 0,
|
||||
"SDL_GetError(): expected message '%s', was message: '%s'",
|
||||
probeError,
|
||||
|
|
|
|||
|
|
@ -32,9 +32,9 @@ static const char RWopsAlphabetString[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
|||
void
|
||||
RWopsSetUp(void *arg)
|
||||
{
|
||||
int fileLen;
|
||||
size_t fileLen;
|
||||
FILE *handle;
|
||||
int writtenLen;
|
||||
size_t writtenLen;
|
||||
int result;
|
||||
|
||||
/* Clean up from previous runs (if any); ignore errors */
|
||||
|
|
@ -49,8 +49,8 @@ RWopsSetUp(void *arg)
|
|||
|
||||
/* Write some known text into it */
|
||||
fileLen = SDL_strlen(RWopsHelloWorldTestString);
|
||||
writtenLen = (int)fwrite(RWopsHelloWorldTestString, 1, fileLen, handle);
|
||||
SDLTest_AssertCheck(fileLen == writtenLen, "Verify number of written bytes, expected %i, got %i", fileLen, writtenLen);
|
||||
writtenLen = fwrite(RWopsHelloWorldTestString, 1, fileLen, handle);
|
||||
SDLTest_AssertCheck(fileLen == writtenLen, "Verify number of written bytes, expected %i, got %i", (int) fileLen, (int) writtenLen);
|
||||
result = fclose(handle);
|
||||
SDLTest_AssertCheck(result == 0, "Verify result from fclose, expected 0, got %i", result);
|
||||
|
||||
|
|
@ -61,8 +61,8 @@ RWopsSetUp(void *arg)
|
|||
|
||||
/* Write alphabet text into it */
|
||||
fileLen = SDL_strlen(RWopsAlphabetString);
|
||||
writtenLen = (int)fwrite(RWopsAlphabetString, 1, fileLen, handle);
|
||||
SDLTest_AssertCheck(fileLen == writtenLen, "Verify number of written bytes, expected %i, got %i", fileLen, writtenLen);
|
||||
writtenLen = fwrite(RWopsAlphabetString, 1, fileLen, handle);
|
||||
SDLTest_AssertCheck(fileLen == writtenLen, "Verify number of written bytes, expected %i, got %i", (int) fileLen, (int) writtenLen);
|
||||
result = fclose(handle);
|
||||
SDLTest_AssertCheck(result == 0, "Verify result from fclose, expected 0, got %i", result);
|
||||
|
||||
|
|
@ -111,10 +111,10 @@ _testGenericRWopsValidations(SDL_RWops *rw, int write)
|
|||
s = SDL_RWwrite(rw, RWopsHelloWorldTestString, sizeof(RWopsHelloWorldTestString)-1, 1);
|
||||
SDLTest_AssertPass("Call to SDL_RWwrite succeeded");
|
||||
if (write) {
|
||||
SDLTest_AssertCheck(s == (size_t)1, "Verify result of writing one byte with SDL_RWwrite, expected 1, got %i", s);
|
||||
SDLTest_AssertCheck(s == (size_t)1, "Verify result of writing one byte with SDL_RWwrite, expected 1, got %i", (int) s);
|
||||
}
|
||||
else {
|
||||
SDLTest_AssertCheck(s == (size_t)0, "Verify result of writing with SDL_RWwrite, expected: 0, got %i", s);
|
||||
SDLTest_AssertCheck(s == (size_t)0, "Verify result of writing with SDL_RWwrite, expected: 0, got %i", (int) s);
|
||||
}
|
||||
|
||||
/* Test seek to random position */
|
||||
|
|
@ -133,8 +133,8 @@ _testGenericRWopsValidations(SDL_RWops *rw, int write)
|
|||
SDLTest_AssertCheck(
|
||||
s == (size_t)(sizeof(RWopsHelloWorldTestString)-1),
|
||||
"Verify result from SDL_RWread, expected %i, got %i",
|
||||
sizeof(RWopsHelloWorldTestString)-1,
|
||||
s);
|
||||
(int) (sizeof(RWopsHelloWorldTestString)-1),
|
||||
(int) s);
|
||||
SDLTest_AssertCheck(
|
||||
SDL_memcmp(buf, RWopsHelloWorldTestString, sizeof(RWopsHelloWorldTestString)-1 ) == 0,
|
||||
"Verify read bytes match expected string, expected '%s', got '%s'", RWopsHelloWorldTestString, buf);
|
||||
|
|
@ -144,25 +144,25 @@ _testGenericRWopsValidations(SDL_RWops *rw, int write)
|
|||
SDLTest_AssertPass("Call to SDL_RWseek(...,-4,RW_SEEK_CUR) succeeded");
|
||||
SDLTest_AssertCheck(
|
||||
i == (Sint64)(sizeof(RWopsHelloWorldTestString)-5),
|
||||
"Verify seek to -4 with SDL_RWseek (RW_SEEK_CUR), expected %i, got %"SDL_PRIs64,
|
||||
sizeof(RWopsHelloWorldTestString)-5,
|
||||
i);
|
||||
"Verify seek to -4 with SDL_RWseek (RW_SEEK_CUR), expected %i, got %i",
|
||||
(int) (sizeof(RWopsHelloWorldTestString)-5),
|
||||
(int) i);
|
||||
|
||||
i = SDL_RWseek( rw, -1, RW_SEEK_END );
|
||||
SDLTest_AssertPass("Call to SDL_RWseek(...,-1,RW_SEEK_END) succeeded");
|
||||
SDLTest_AssertCheck(
|
||||
i == (Sint64)(sizeof(RWopsHelloWorldTestString)-2),
|
||||
"Verify seek to -1 with SDL_RWseek (RW_SEEK_END), expected %i, got %"SDL_PRIs64,
|
||||
sizeof(RWopsHelloWorldTestString)-2,
|
||||
i);
|
||||
"Verify seek to -1 with SDL_RWseek (RW_SEEK_END), expected %i, got %i",
|
||||
(int) (sizeof(RWopsHelloWorldTestString)-2),
|
||||
(int) i);
|
||||
|
||||
/* Invalid whence seek */
|
||||
i = SDL_RWseek( rw, 0, 999 );
|
||||
SDLTest_AssertPass("Call to SDL_RWseek(...,0,invalid_whence) succeeded");
|
||||
SDLTest_AssertCheck(
|
||||
i == (Sint64)(-1),
|
||||
"Verify seek with SDL_RWseek (invalid_whence); expected: -1, got %"SDL_PRIs64,
|
||||
i);
|
||||
"Verify seek with SDL_RWseek (invalid_whence); expected: -1, got %i",
|
||||
(int) i);
|
||||
}
|
||||
|
||||
/* !
|
||||
|
|
@ -559,8 +559,8 @@ rwops_testCompareRWFromMemWithRWFromFile(void)
|
|||
SDLTest_AssertCheck(result == 0, "Verify result value is 0; got: %d", result);
|
||||
|
||||
/* Compare */
|
||||
SDLTest_AssertCheck(rv_mem == rv_file, "Verify returned read blocks matches for mem and file reads; got: rv_mem=%d rv_file=%d", rv_mem, rv_file);
|
||||
SDLTest_AssertCheck(sv_mem == sv_file, "Verify SEEK_END position matches for mem and file seeks; got: sv_mem=%"SDL_PRIu64" sv_file=%"SDL_PRIu64, sv_mem, sv_file);
|
||||
SDLTest_AssertCheck(rv_mem == rv_file, "Verify returned read blocks matches for mem and file reads; got: rv_mem=%d rv_file=%d", (int) rv_mem, (int) rv_file);
|
||||
SDLTest_AssertCheck(sv_mem == sv_file, "Verify SEEK_END position matches for mem and file seeks; got: sv_mem=%d sv_file=%d", (int) sv_mem, (int) sv_file);
|
||||
SDLTest_AssertCheck(buffer_mem[slen] == 0, "Verify mem buffer termination; expected: 0, got: %d", buffer_mem[slen]);
|
||||
SDLTest_AssertCheck(buffer_file[slen] == 0, "Verify file buffer termination; expected: 0, got: %d", buffer_file[slen]);
|
||||
SDLTest_AssertCheck(
|
||||
|
|
@ -648,27 +648,27 @@ rwops_testFileWriteReadEndian(void)
|
|||
/* Write test data */
|
||||
objectsWritten = SDL_WriteBE16(rw, BE16value);
|
||||
SDLTest_AssertPass("Call to SDL_WriteBE16()");
|
||||
SDLTest_AssertCheck(objectsWritten == 1, "Validate number of objects written, expected: 1, got: %i", objectsWritten);
|
||||
SDLTest_AssertCheck(objectsWritten == 1, "Validate number of objects written, expected: 1, got: %i", (int) objectsWritten);
|
||||
objectsWritten = SDL_WriteBE32(rw, BE32value);
|
||||
SDLTest_AssertPass("Call to SDL_WriteBE32()");
|
||||
SDLTest_AssertCheck(objectsWritten == 1, "Validate number of objects written, expected: 1, got: %i", objectsWritten);
|
||||
SDLTest_AssertCheck(objectsWritten == 1, "Validate number of objects written, expected: 1, got: %i", (int) objectsWritten);
|
||||
objectsWritten = SDL_WriteBE64(rw, BE64value);
|
||||
SDLTest_AssertPass("Call to SDL_WriteBE64()");
|
||||
SDLTest_AssertCheck(objectsWritten == 1, "Validate number of objects written, expected: 1, got: %i", objectsWritten);
|
||||
SDLTest_AssertCheck(objectsWritten == 1, "Validate number of objects written, expected: 1, got: %i", (int) objectsWritten);
|
||||
objectsWritten = SDL_WriteLE16(rw, LE16value);
|
||||
SDLTest_AssertPass("Call to SDL_WriteLE16()");
|
||||
SDLTest_AssertCheck(objectsWritten == 1, "Validate number of objects written, expected: 1, got: %i", objectsWritten);
|
||||
SDLTest_AssertCheck(objectsWritten == 1, "Validate number of objects written, expected: 1, got: %i", (int) objectsWritten);
|
||||
objectsWritten = SDL_WriteLE32(rw, LE32value);
|
||||
SDLTest_AssertPass("Call to SDL_WriteLE32()");
|
||||
SDLTest_AssertCheck(objectsWritten == 1, "Validate number of objects written, expected: 1, got: %i", objectsWritten);
|
||||
SDLTest_AssertCheck(objectsWritten == 1, "Validate number of objects written, expected: 1, got: %i", (int) objectsWritten);
|
||||
objectsWritten = SDL_WriteLE64(rw, LE64value);
|
||||
SDLTest_AssertPass("Call to SDL_WriteLE64()");
|
||||
SDLTest_AssertCheck(objectsWritten == 1, "Validate number of objects written, expected: 1, got: %i", objectsWritten);
|
||||
SDLTest_AssertCheck(objectsWritten == 1, "Validate number of objects written, expected: 1, got: %i", (int) objectsWritten);
|
||||
|
||||
/* Test seek to start */
|
||||
result = SDL_RWseek( rw, 0, RW_SEEK_SET );
|
||||
SDLTest_AssertPass("Call to SDL_RWseek succeeded");
|
||||
SDLTest_AssertCheck(result == 0, "Verify result from position 0 with SDL_RWseek, expected 0, got %"SDL_PRIs64, result);
|
||||
SDLTest_AssertCheck(result == 0, "Verify result from position 0 with SDL_RWseek, expected 0, got %i", (int) result);
|
||||
|
||||
/* Read test data */
|
||||
BE16test = SDL_ReadBE16(rw);
|
||||
|
|
|
|||
|
|
@ -2,17 +2,20 @@
|
|||
* SDL_test test suite
|
||||
*/
|
||||
|
||||
#include <limits.h>
|
||||
/* Visual Studio 2008 doesn't have stdint.h */
|
||||
#if defined(_MSC_VER) && _MSC_VER <= 1500
|
||||
#define UINT8_MAX ~(Uint8)0
|
||||
#define UINT16_MAX ~(Uint16)0
|
||||
#define UINT32_MAX ~(Uint32)0
|
||||
#define UINT64_MAX ~(Uint64)0
|
||||
#define UINT8_MAX _UI8_MAX
|
||||
#define UINT16_MAX _UI16_MAX
|
||||
#define UINT32_MAX _UI32_MAX
|
||||
#define INT64_MIN _I64_MIN
|
||||
#define INT64_MAX _I64_MAX
|
||||
#define UINT64_MAX _UI64_MAX
|
||||
#else
|
||||
#include <stdint.h>
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <limits.h>
|
||||
#include <float.h>
|
||||
#include <ctype.h>
|
||||
|
||||
|
|
@ -31,7 +34,8 @@ int
|
|||
sdltest_generateRunSeed(void *arg)
|
||||
{
|
||||
char* result;
|
||||
int i, l;
|
||||
size_t i, l;
|
||||
int j;
|
||||
|
||||
for (i = 1; i <= 10; i += 3) {
|
||||
result = SDLTest_GenerateRunSeed((const int)i);
|
||||
|
|
@ -39,14 +43,14 @@ sdltest_generateRunSeed(void *arg)
|
|||
SDLTest_AssertCheck(result != NULL, "Verify returned value is not NULL");
|
||||
if (result != NULL) {
|
||||
l = SDL_strlen(result);
|
||||
SDLTest_AssertCheck(l == i, "Verify length of returned value is %d, got: %d", i, l);
|
||||
SDLTest_AssertCheck(l == i, "Verify length of returned value is %d, got: %d", (int) i, (int) l);
|
||||
SDL_free(result);
|
||||
}
|
||||
}
|
||||
|
||||
/* Negative cases */
|
||||
for (i = -2; i <= 0; i++) {
|
||||
result = SDLTest_GenerateRunSeed((const int)i);
|
||||
for (j = -2; j <= 0; j++) {
|
||||
result = SDLTest_GenerateRunSeed((const int)j);
|
||||
SDLTest_AssertPass("Call to SDLTest_GenerateRunSeed()");
|
||||
SDLTest_AssertCheck(result == NULL, "Verify returned value is not NULL");
|
||||
}
|
||||
|
|
@ -988,38 +992,38 @@ sdltest_randomBoundaryNumberSint64(void *arg)
|
|||
"Validate result value for parameters (1,20,SDL_FALSE); expected: 0|21, got: %"SDL_PRIs64, sresult);
|
||||
|
||||
/* RandomSintXBoundaryValue(LLONG_MIN, 99, SDL_FALSE) returns 100 */
|
||||
sresult = (Sint64)SDLTest_RandomSint64BoundaryValue(LLONG_MIN, 99, SDL_FALSE);
|
||||
sresult = (Sint64)SDLTest_RandomSint64BoundaryValue(INT64_MIN, 99, SDL_FALSE);
|
||||
SDLTest_AssertPass("Call to SDLTest_RandomSint64BoundaryValue");
|
||||
SDLTest_AssertCheck(
|
||||
sresult == 100,
|
||||
"Validate result value for parameters (LLONG_MIN,99,SDL_FALSE); expected: 100, got: %"SDL_PRIs64, sresult);
|
||||
|
||||
/* RandomSintXBoundaryValue(LLONG_MIN + 1, LLONG_MAX, SDL_FALSE) returns LLONG_MIN (no error) */
|
||||
sresult = (Sint64)SDLTest_RandomSint64BoundaryValue(LLONG_MIN + 1, LLONG_MAX, SDL_FALSE);
|
||||
sresult = (Sint64)SDLTest_RandomSint64BoundaryValue(INT64_MIN + 1, INT64_MAX, SDL_FALSE);
|
||||
SDLTest_AssertPass("Call to SDLTest_RandomSint64BoundaryValue");
|
||||
SDLTest_AssertCheck(
|
||||
sresult == LLONG_MIN,
|
||||
"Validate result value for parameters (LLONG_MIN+1,LLONG_MAX,SDL_FALSE); expected: %"SDL_PRIs64", got: %"SDL_PRIs64, LLONG_MIN, sresult);
|
||||
sresult == INT64_MIN,
|
||||
"Validate result value for parameters (LLONG_MIN+1,LLONG_MAX,SDL_FALSE); expected: %"SDL_PRIs64", got: %"SDL_PRIs64, INT64_MIN, sresult);
|
||||
lastError = (char *)SDL_GetError();
|
||||
SDLTest_AssertPass("SDL_GetError()");
|
||||
SDLTest_AssertCheck(lastError == NULL || lastError[0] == '\0', "Validate no error message was set");
|
||||
|
||||
/* RandomSintXBoundaryValue(LLONG_MIN, LLONG_MAX - 1, SDL_FALSE) returns LLONG_MAX (no error) */
|
||||
sresult = (Sint64)SDLTest_RandomSint64BoundaryValue(LLONG_MIN, LLONG_MAX - 1, SDL_FALSE);
|
||||
sresult = (Sint64)SDLTest_RandomSint64BoundaryValue(INT64_MIN, INT64_MAX - 1, SDL_FALSE);
|
||||
SDLTest_AssertPass("Call to SDLTest_RandomSint64BoundaryValue");
|
||||
SDLTest_AssertCheck(
|
||||
sresult == LLONG_MAX,
|
||||
"Validate result value for parameters (LLONG_MIN,LLONG_MAX - 1,SDL_FALSE); expected: %"SDL_PRIs64", got: %"SDL_PRIs64, LLONG_MAX, sresult);
|
||||
sresult == INT64_MAX,
|
||||
"Validate result value for parameters (LLONG_MIN,LLONG_MAX - 1,SDL_FALSE); expected: %"SDL_PRIs64", got: %"SDL_PRIs64, INT64_MAX, sresult);
|
||||
lastError = (char *)SDL_GetError();
|
||||
SDLTest_AssertPass("SDL_GetError()");
|
||||
SDLTest_AssertCheck(lastError == NULL || lastError[0] == '\0', "Validate no error message was set");
|
||||
|
||||
/* RandomSintXBoundaryValue(LLONG_MIN, LLONG_MAX, SDL_FALSE) returns 0 (sets error) */
|
||||
sresult = (Sint64)SDLTest_RandomSint64BoundaryValue(LLONG_MIN, LLONG_MAX, SDL_FALSE);
|
||||
sresult = (Sint64)SDLTest_RandomSint64BoundaryValue(INT64_MIN, INT64_MAX, SDL_FALSE);
|
||||
SDLTest_AssertPass("Call to SDLTest_RandomSint64BoundaryValue");
|
||||
SDLTest_AssertCheck(
|
||||
sresult == LLONG_MIN,
|
||||
"Validate result value for parameters(LLONG_MIN,LLONG_MAX,SDL_FALSE); expected: %"SDL_PRIs64", got: %"SDL_PRIs64, LLONG_MIN, sresult);
|
||||
sresult == INT64_MIN,
|
||||
"Validate result value for parameters(LLONG_MIN,LLONG_MAX,SDL_FALSE); expected: %"SDL_PRIs64", got: %"SDL_PRIs64, INT64_MIN, sresult);
|
||||
lastError = (char *)SDL_GetError();
|
||||
SDLTest_AssertPass("SDL_GetError()");
|
||||
SDLTest_AssertCheck(lastError != NULL && SDL_strcmp(lastError, expectedError) == 0,
|
||||
|
|
@ -1116,16 +1120,16 @@ int
|
|||
sdltest_randomAsciiString(void *arg)
|
||||
{
|
||||
char* result;
|
||||
int len;
|
||||
size_t len;
|
||||
int nonAsciiCharacters;
|
||||
int i;
|
||||
size_t i;
|
||||
|
||||
result = SDLTest_RandomAsciiString();
|
||||
SDLTest_AssertPass("Call to SDLTest_RandomAsciiString()");
|
||||
SDLTest_AssertCheck(result != NULL, "Validate that result is not NULL");
|
||||
if (result != NULL) {
|
||||
len = SDL_strlen(result);
|
||||
SDLTest_AssertCheck(len >= 0 && len <= 255, "Validate that result length; expected: len=[1,255], got: %d", len);
|
||||
SDLTest_AssertCheck(len >= 1 && len <= 255, "Validate that result length; expected: len=[1,255], got: %d", (int) len);
|
||||
nonAsciiCharacters = 0;
|
||||
for (i=0; i<len; i++) {
|
||||
if (iscntrl(result[i])) {
|
||||
|
|
@ -1152,18 +1156,18 @@ sdltest_randomAsciiStringWithMaximumLength(void *arg)
|
|||
const char* expectedError = "Parameter 'maxLength' is invalid";
|
||||
char* lastError;
|
||||
char* result;
|
||||
int targetLen;
|
||||
int len;
|
||||
size_t targetLen;
|
||||
size_t len;
|
||||
int nonAsciiCharacters;
|
||||
int i;
|
||||
size_t i;
|
||||
|
||||
targetLen = 16 + SDLTest_RandomUint8();
|
||||
result = SDLTest_RandomAsciiStringWithMaximumLength(targetLen);
|
||||
result = SDLTest_RandomAsciiStringWithMaximumLength((int) targetLen);
|
||||
SDLTest_AssertPass("Call to SDLTest_RandomAsciiStringWithMaximumLength(%d)", targetLen);
|
||||
SDLTest_AssertCheck(result != NULL, "Validate that result is not NULL");
|
||||
if (result != NULL) {
|
||||
len = SDL_strlen(result);
|
||||
SDLTest_AssertCheck(len >= 0 && len <= targetLen, "Validate that result length; expected: len=[1,%d], got: %d", targetLen, len);
|
||||
SDLTest_AssertCheck(len >= 1 && len <= targetLen, "Validate that result length; expected: len=[1,%d], got: %d", (int) targetLen, (int) len);
|
||||
nonAsciiCharacters = 0;
|
||||
for (i=0; i<len; i++) {
|
||||
if (iscntrl(result[i])) {
|
||||
|
|
@ -1179,7 +1183,7 @@ sdltest_randomAsciiStringWithMaximumLength(void *arg)
|
|||
|
||||
/* Negative test */
|
||||
targetLen = 0;
|
||||
result = SDLTest_RandomAsciiStringWithMaximumLength(targetLen);
|
||||
result = SDLTest_RandomAsciiStringWithMaximumLength((int) targetLen);
|
||||
SDLTest_AssertPass("Call to SDLTest_RandomAsciiStringWithMaximumLength(%d)", targetLen);
|
||||
SDLTest_AssertCheck(result == NULL, "Validate that result is NULL");
|
||||
lastError = (char *)SDL_GetError();
|
||||
|
|
@ -1205,19 +1209,19 @@ sdltest_randomAsciiStringOfSize(void *arg)
|
|||
const char* expectedError = "Parameter 'size' is invalid";
|
||||
char* lastError;
|
||||
char* result;
|
||||
int targetLen;
|
||||
int len;
|
||||
size_t targetLen;
|
||||
size_t len;
|
||||
int nonAsciiCharacters;
|
||||
int i;
|
||||
size_t i;
|
||||
|
||||
/* Positive test */
|
||||
targetLen = 16 + SDLTest_RandomUint8();
|
||||
result = SDLTest_RandomAsciiStringOfSize(targetLen);
|
||||
result = SDLTest_RandomAsciiStringOfSize((int) targetLen);
|
||||
SDLTest_AssertPass("Call to SDLTest_RandomAsciiStringOfSize(%d)", targetLen);
|
||||
SDLTest_AssertCheck(result != NULL, "Validate that result is not NULL");
|
||||
if (result != NULL) {
|
||||
len = SDL_strlen(result);
|
||||
SDLTest_AssertCheck(len == targetLen, "Validate that result length; expected: len=%d, got: %d", targetLen, len);
|
||||
SDLTest_AssertCheck(len == targetLen, "Validate that result length; expected: len=%d, got: %d", (int) targetLen, (int) len);
|
||||
nonAsciiCharacters = 0;
|
||||
for (i=0; i<len; i++) {
|
||||
if (iscntrl(result[i])) {
|
||||
|
|
@ -1233,7 +1237,7 @@ sdltest_randomAsciiStringOfSize(void *arg)
|
|||
|
||||
/* Negative test */
|
||||
targetLen = 0;
|
||||
result = SDLTest_RandomAsciiStringOfSize(targetLen);
|
||||
result = SDLTest_RandomAsciiStringOfSize((int) targetLen);
|
||||
SDLTest_AssertPass("Call to SDLTest_RandomAsciiStringOfSize(%d)", targetLen);
|
||||
SDLTest_AssertCheck(result == NULL, "Validate that result is NULL");
|
||||
lastError = (char *)SDL_GetError();
|
||||
|
|
|
|||
|
|
@ -25,13 +25,13 @@ stdlib_strlcpy(void *arg)
|
|||
expected = "foo";
|
||||
SDLTest_AssertPass("Call to SDL_strlcpy(\"foo\")");
|
||||
SDLTest_AssertCheck(SDL_strcmp(text, expected) == 0, "Check text, expected: %s, got: %s", expected, text);
|
||||
SDLTest_AssertCheck(result == SDL_strlen(text), "Check result value, expected: %d, got: %d", SDL_strlen(text), result);
|
||||
SDLTest_AssertCheck(result == SDL_strlen(text), "Check result value, expected: %d, got: %d", (int) SDL_strlen(text), (int) result);
|
||||
|
||||
result = SDL_strlcpy(text, "foo", 2);
|
||||
expected = "f";
|
||||
SDLTest_AssertPass("Call to SDL_strlcpy(\"foo\") with buffer size 2");
|
||||
SDLTest_AssertCheck(SDL_strcmp(text, expected) == 0, "Check text, expected: %s, got: %s", expected, text);
|
||||
SDLTest_AssertCheck(result == 3, "Check result value, expected: 3, got: %d", result);
|
||||
SDLTest_AssertCheck(result == 3, "Check result value, expected: 3, got: %d", (int) result);
|
||||
|
||||
return TEST_COMPLETED;
|
||||
}
|
||||
|
|
@ -51,7 +51,7 @@ stdlib_snprintf(void *arg)
|
|||
expected = "foo";
|
||||
SDLTest_AssertPass("Call to SDL_snprintf(\"%%s\", \"foo\")");
|
||||
SDLTest_AssertCheck(SDL_strcmp(text, expected) == 0, "Check text, expected: %s, got: %s", expected, text);
|
||||
SDLTest_AssertCheck(result == SDL_strlen(text), "Check result value, expected: %d, got: %d", SDL_strlen(text), result);
|
||||
SDLTest_AssertCheck(result == SDL_strlen(text), "Check result value, expected: %d, got: %d", (int) SDL_strlen(text), result);
|
||||
|
||||
result = SDL_snprintf(text, 2, "%s", "foo");
|
||||
expected = "f";
|
||||
|
|
@ -66,49 +66,49 @@ stdlib_snprintf(void *arg)
|
|||
expected = "1.000000";
|
||||
SDLTest_AssertPass("Call to SDL_snprintf(\"%%f\", 1.0)");
|
||||
SDLTest_AssertCheck(SDL_strcmp(text, expected) == 0, "Check text, expected: %s, got: %s", expected, text);
|
||||
SDLTest_AssertCheck(result == SDL_strlen(text), "Check result value, expected: %d, got: %d", SDL_strlen(text), result);
|
||||
SDLTest_AssertCheck(result == SDL_strlen(text), "Check result value, expected: %d, got: %d", (int) SDL_strlen(text), result);
|
||||
|
||||
result = SDL_snprintf(text, sizeof(text), "%.f", 1.0);
|
||||
expected = "1";
|
||||
SDLTest_AssertPass("Call to SDL_snprintf(\"%%.f\", 1.0)");
|
||||
SDLTest_AssertCheck(SDL_strcmp(text, expected) == 0, "Check text, expected: %s, got: %s", expected, text);
|
||||
SDLTest_AssertCheck(result == SDL_strlen(text), "Check result value, expected: %d, got: %d", SDL_strlen(text), result);
|
||||
SDLTest_AssertCheck(result == SDL_strlen(text), "Check result value, expected: %d, got: %d", (int) SDL_strlen(text), result);
|
||||
|
||||
result = SDL_snprintf(text, sizeof(text), "%#.f", 1.0);
|
||||
expected = "1.";
|
||||
SDLTest_AssertPass("Call to SDL_snprintf(\"%%#.f\", 1.0)");
|
||||
SDLTest_AssertCheck(SDL_strcmp(text, expected) == 0, "Check text, expected: %s, got: %s", expected, text);
|
||||
SDLTest_AssertCheck(result == SDL_strlen(text), "Check result value, expected: %d, got: %d", SDL_strlen(text), result);
|
||||
SDLTest_AssertCheck(result == SDL_strlen(text), "Check result value, expected: %d, got: %d", (int) SDL_strlen(text), result);
|
||||
|
||||
result = SDL_snprintf(text, sizeof(text), "%f", 1.0 + 1.0 / 3.0);
|
||||
expected = "1.333333";
|
||||
SDLTest_AssertPass("Call to SDL_snprintf(\"%%f\", 1.0 + 1.0 / 3.0)");
|
||||
SDLTest_AssertCheck(SDL_strcmp(text, expected) == 0, "Check text, expected: %s, got: %s", expected, text);
|
||||
SDLTest_AssertCheck(result == SDL_strlen(text), "Check result value, expected: %d, got: %d", SDL_strlen(text), result);
|
||||
SDLTest_AssertCheck(result == SDL_strlen(text), "Check result value, expected: %d, got: %d", (int) SDL_strlen(text), result);
|
||||
|
||||
result = SDL_snprintf(text, sizeof(text), "%+f", 1.0 + 1.0 / 3.0);
|
||||
expected = "+1.333333";
|
||||
SDLTest_AssertPass("Call to SDL_snprintf(\"%%+f\", 1.0 + 1.0 / 3.0)");
|
||||
SDLTest_AssertCheck(SDL_strcmp(text, expected) == 0, "Check text, expected: %s, got: %s", expected, text);
|
||||
SDLTest_AssertCheck(result == SDL_strlen(text), "Check result value, expected: %d, got: %d", SDL_strlen(text), result);
|
||||
SDLTest_AssertCheck(result == SDL_strlen(text), "Check result value, expected: %d, got: %d", (int) SDL_strlen(text), result);
|
||||
|
||||
result = SDL_snprintf(text, sizeof(text), "%.2f", 1.0 + 1.0 / 3.0);
|
||||
expected = "1.33";
|
||||
SDLTest_AssertPass("Call to SDL_snprintf(\"%%.2f\", 1.0 + 1.0 / 3.0)");
|
||||
SDLTest_AssertCheck(SDL_strcmp(text, expected) == 0, "Check text, expected: %s, got: %s", expected, text);
|
||||
SDLTest_AssertCheck(result == SDL_strlen(text), "Check result value, expected: %d, got: %d", SDL_strlen(text), result);
|
||||
SDLTest_AssertCheck(result == SDL_strlen(text), "Check result value, expected: %d, got: %d", (int) SDL_strlen(text), result);
|
||||
|
||||
result = SDL_snprintf(text, sizeof(text), "%6.2f", 1.0 + 1.0 / 3.0);
|
||||
expected = " 1.33";
|
||||
SDLTest_AssertPass("Call to SDL_snprintf(\"%%6.2f\", 1.0 + 1.0 / 3.0)");
|
||||
SDLTest_AssertCheck(SDL_strcmp(text, expected) == 0, "Check text, expected: '%s', got: '%s'", expected, text);
|
||||
SDLTest_AssertCheck(result == SDL_strlen(text), "Check result value, expected: %d, got: %d", SDL_strlen(text), result);
|
||||
SDLTest_AssertCheck(result == SDL_strlen(text), "Check result value, expected: %d, got: %d", (int) SDL_strlen(text), result);
|
||||
|
||||
result = SDL_snprintf(text, sizeof(text), "%06.2f", 1.0 + 1.0 / 3.0);
|
||||
expected = "001.33";
|
||||
SDLTest_AssertPass("Call to SDL_snprintf(\"%%06.2f\", 1.0 + 1.0 / 3.0)");
|
||||
SDLTest_AssertCheck(SDL_strcmp(text, expected) == 0, "Check text, expected: '%s', got: '%s'", expected, text);
|
||||
SDLTest_AssertCheck(result == SDL_strlen(text), "Check result value, expected: %d, got: %d", SDL_strlen(text), result);
|
||||
SDLTest_AssertCheck(result == SDL_strlen(text), "Check result value, expected: %d, got: %d", (int) SDL_strlen(text), result);
|
||||
|
||||
result = SDL_snprintf(text, 5, "%06.2f", 1.0 + 1.0 / 3.0);
|
||||
expected = "001.";
|
||||
|
|
@ -146,7 +146,7 @@ stdlib_getsetenv(void *arg)
|
|||
text = SDL_getenv(name);
|
||||
SDLTest_AssertPass("Call to SDL_getenv('%s')", name);
|
||||
if (text != NULL) {
|
||||
SDLTest_Log("Expected: NULL, Got: '%s' (%i)", text, SDL_strlen(text));
|
||||
SDLTest_Log("Expected: NULL, Got: '%s' (%i)", text, (int) SDL_strlen(text));
|
||||
}
|
||||
} while (text != NULL);
|
||||
|
||||
|
|
|
|||
|
|
@ -104,7 +104,7 @@ timer_delayAndGetTicks(void *arg)
|
|||
}
|
||||
|
||||
/* Test callback */
|
||||
Uint32 _timerTestCallback(Uint32 interval, void *param)
|
||||
Uint32 SDLCALL _timerTestCallback(Uint32 interval, void *param)
|
||||
{
|
||||
_timerCallbackCalled = 1;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
Copyright (C) 1997-2014 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2018 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,5 +1,5 @@
|
|||
/*
|
||||
Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2018 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,5 +1,5 @@
|
|||
/*
|
||||
Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2018 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,5 +1,5 @@
|
|||
/*
|
||||
Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2018 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,5 +1,5 @@
|
|||
/*
|
||||
Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2018 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
|
||||
|
|
@ -25,6 +25,7 @@
|
|||
|
||||
SDL_Window *window;
|
||||
SDL_Renderer *renderer;
|
||||
SDL_Surface *surface;
|
||||
int done;
|
||||
|
||||
void
|
||||
|
|
@ -59,7 +60,20 @@ loop()
|
|||
{
|
||||
SDL_Event e;
|
||||
while (SDL_PollEvent(&e)) {
|
||||
if (e.type == SDL_QUIT) {
|
||||
|
||||
/* Re-create when window has been resized */
|
||||
if ((e.type == SDL_WINDOWEVENT) && (e.window.event == SDL_WINDOWEVENT_SIZE_CHANGED)) {
|
||||
|
||||
SDL_DestroyRenderer(renderer);
|
||||
|
||||
surface = SDL_GetWindowSurface(window);
|
||||
renderer = SDL_CreateSoftwareRenderer(surface);
|
||||
/* Clear the rendering surface with the specified color */
|
||||
SDL_SetRenderDrawColor(renderer, 0xFF, 0xFF, 0xFF, 0xFF);
|
||||
SDL_RenderClear(renderer);
|
||||
}
|
||||
|
||||
if (e.type == SDL_QUIT) {
|
||||
done = 1;
|
||||
#ifdef __EMSCRIPTEN__
|
||||
emscripten_cancel_main_loop();
|
||||
|
|
@ -86,8 +100,6 @@ loop()
|
|||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
SDL_Surface *surface;
|
||||
|
||||
/* Enable standard application logging */
|
||||
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
|
||||
|
||||
|
|
@ -100,7 +112,7 @@ main(int argc, char *argv[])
|
|||
|
||||
|
||||
/* Create window and renderer for given surface */
|
||||
window = SDL_CreateWindow("Chess Board", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 640, 480, 0);
|
||||
window = SDL_CreateWindow("Chess Board", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 640, 480, SDL_WINDOW_RESIZABLE);
|
||||
if(!window)
|
||||
{
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Window creation fail : %s\n",SDL_GetError());
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2018 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,5 +1,5 @@
|
|||
/*
|
||||
Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2018 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
|
||||
|
|
@ -14,7 +14,6 @@
|
|||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <signal.h>
|
||||
|
||||
#include "SDL.h"
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2018 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,5 +1,5 @@
|
|||
/*
|
||||
Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2018 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
|
||||
|
|
@ -46,6 +46,15 @@ main(int argc, char *argv[])
|
|||
SDL_Log("pref path: '%s'\n", pref_path);
|
||||
SDL_free(pref_path);
|
||||
|
||||
pref_path = SDL_GetPrefPath(NULL, "testfilesystem");
|
||||
if(pref_path == NULL){
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't find pref path without organization: %s\n",
|
||||
SDL_GetError());
|
||||
return 1;
|
||||
}
|
||||
SDL_Log("pref path: '%s'\n", pref_path);
|
||||
SDL_free(pref_path);
|
||||
|
||||
SDL_Quit();
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2018 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
|
||||
|
|
@ -53,12 +53,12 @@ static const struct { int x; int y; } button_positions[] = {
|
|||
|
||||
/* This is indexed by SDL_GameControllerAxis. */
|
||||
static const struct { int x; int y; double angle; } axis_positions[] = {
|
||||
{75, 154, 0.0}, /* LEFTX */
|
||||
{75, 154, 90.0}, /* LEFTY */
|
||||
{305, 230, 0.0}, /* RIGHTX */
|
||||
{305, 230, 90.0}, /* RIGHTY */
|
||||
{91, 0, 90.0}, /* TRIGGERLEFT */
|
||||
{375, 0, 90.0}, /* TRIGGERRIGHT */
|
||||
{74, 153, 270.0}, /* LEFTX */
|
||||
{74, 153, 0.0}, /* LEFTY */
|
||||
{306, 231, 270.0}, /* RIGHTX */
|
||||
{306, 231, 0.0}, /* RIGHTY */
|
||||
{91, -20, 0.0}, /* TRIGGERLEFT */
|
||||
{375, -20, 0.0}, /* TRIGGERRIGHT */
|
||||
};
|
||||
|
||||
SDL_Renderer *screen = NULL;
|
||||
|
|
@ -80,10 +80,6 @@ LoadTexture(SDL_Renderer *renderer, const char *file, SDL_bool transparent)
|
|||
if (transparent) {
|
||||
if (temp->format->BytesPerPixel == 1) {
|
||||
SDL_SetColorKey(temp, SDL_TRUE, *(Uint8 *)temp->pixels);
|
||||
} else {
|
||||
SDL_assert(!temp->format->palette);
|
||||
SDL_assert(temp->format->BitsPerPixel == 24);
|
||||
SDL_SetColorKey(temp, SDL_TRUE, (*(Uint32 *)temp->pixels) & 0x00FFFFFF);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -112,6 +108,13 @@ loop(void *arg)
|
|||
|
||||
while (SDL_PollEvent(&event)) {
|
||||
switch (event.type) {
|
||||
case SDL_CONTROLLERAXISMOTION:
|
||||
SDL_Log("Controller axis %s changed to %d\n", SDL_GameControllerGetStringForAxis((SDL_GameControllerAxis)event.caxis.axis), event.caxis.value);
|
||||
break;
|
||||
case SDL_CONTROLLERBUTTONDOWN:
|
||||
case SDL_CONTROLLERBUTTONUP:
|
||||
SDL_Log("Controller button %s %s\n", SDL_GameControllerGetStringForButton((SDL_GameControllerButton)event.cbutton.button), event.cbutton.state ? "pressed" : "released");
|
||||
break;
|
||||
case SDL_KEYDOWN:
|
||||
if (event.key.keysym.sym != SDLK_ESCAPE) {
|
||||
break;
|
||||
|
|
@ -259,6 +262,19 @@ main(int argc, char *argv[])
|
|||
|
||||
SDL_GameControllerAddMappingsFromFile("gamecontrollerdb.txt");
|
||||
|
||||
/* Print information about the mappings */
|
||||
if (!argv[1]) {
|
||||
SDL_Log("Supported mappings:\n");
|
||||
for (i = 0; i < SDL_GameControllerNumMappings(); ++i) {
|
||||
char *mapping = SDL_GameControllerMappingForIndex(i);
|
||||
if (mapping) {
|
||||
SDL_Log("\t%s\n", mapping);
|
||||
SDL_free(mapping);
|
||||
}
|
||||
}
|
||||
SDL_Log("\n");
|
||||
}
|
||||
|
||||
/* Print information about the controller */
|
||||
for (i = 0; i < SDL_NumJoysticks(); ++i) {
|
||||
const char *name;
|
||||
|
|
@ -276,7 +292,9 @@ main(int argc, char *argv[])
|
|||
name = SDL_JoystickNameForIndex(i);
|
||||
description = "Joystick";
|
||||
}
|
||||
SDL_Log("%s %d: %s (guid %s)\n", description, i, name ? name : "Unknown", guid);
|
||||
SDL_Log("%s %d: %s (guid %s, VID 0x%.4x, PID 0x%.4x)\n",
|
||||
description, i, name ? name : "Unknown", guid,
|
||||
SDL_JoystickGetDeviceVendor(i), SDL_JoystickGetDeviceProduct(i));
|
||||
}
|
||||
SDL_Log("There are %d game controller(s) attached (%d joystick(s))\n", nController, SDL_NumJoysticks());
|
||||
|
||||
|
|
@ -348,3 +366,5 @@ main(int argc, char *argv[])
|
|||
}
|
||||
|
||||
#endif
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2018 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
|
||||
|
|
@ -25,7 +25,6 @@
|
|||
#define WIDTH 640
|
||||
#define HEIGHT 480
|
||||
#define BPP 4
|
||||
#define DEPTH 32
|
||||
|
||||
/* MUST BE A POWER OF 2! */
|
||||
#define EVENT_BUF_SIZE 256
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2018 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
|
||||
|
|
@ -56,7 +56,7 @@ static int LoadContext(GL_Context * data)
|
|||
do { \
|
||||
data->func = SDL_GL_GetProcAddress(#func); \
|
||||
if ( ! data->func ) { \
|
||||
return SDL_SetError("Couldn't load GL function %s: %s\n", #func, SDL_GetError()); \
|
||||
return SDL_SetError("Couldn't load GL function %s: %s", #func, SDL_GetError()); \
|
||||
} \
|
||||
} while ( 0 );
|
||||
#endif /* __SDL_NOGETPROCADDR__ */
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2018 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,5 +1,5 @@
|
|||
/*
|
||||
Copyright (r) 1997-2016 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2018 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
|
||||
|
|
@ -20,7 +20,8 @@
|
|||
|
||||
#include "SDL_test_common.h"
|
||||
|
||||
#if defined(__IPHONEOS__) || defined(__ANDROID__) || defined(__EMSCRIPTEN__) || defined(__NACL__)
|
||||
#if defined(__IPHONEOS__) || defined(__ANDROID__) || defined(__EMSCRIPTEN__) || defined(__NACL__) \
|
||||
|| defined(__WINDOWS__) || defined(__LINUX__)
|
||||
#define HAVE_OPENGLES2
|
||||
#endif
|
||||
|
||||
|
|
@ -58,7 +59,7 @@ static int LoadContext(GLES2_Context * data)
|
|||
do { \
|
||||
data->func = SDL_GL_GetProcAddress(#func); \
|
||||
if ( ! data->func ) { \
|
||||
return SDL_SetError("Couldn't load GLES2 function %s: %s\n", #func, SDL_GetError()); \
|
||||
return SDL_SetError("Couldn't load GLES2 function %s: %s", #func, SDL_GetError()); \
|
||||
} \
|
||||
} while ( 0 );
|
||||
#endif /* __SDL_NOGETPROCADDR__ */
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ const SDL_Rect drag_areas[] = {
|
|||
static const SDL_Rect *areas = drag_areas;
|
||||
static int numareas = SDL_arraysize(drag_areas);
|
||||
|
||||
static SDL_HitTestResult
|
||||
static SDL_HitTestResult SDLCALL
|
||||
hitTest(SDL_Window *window, const SDL_Point *pt, void *data)
|
||||
{
|
||||
int i;
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2018 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,5 +1,5 @@
|
|||
/*
|
||||
Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2018 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,5 +1,5 @@
|
|||
/*
|
||||
Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2018 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
|
||||
|
|
@ -99,7 +99,7 @@ static Uint8 validate_hex(const char *cp, size_t len, Uint32 *np)
|
|||
return 1;
|
||||
}
|
||||
|
||||
static void unifont_init(const char *fontname)
|
||||
static int unifont_init(const char *fontname)
|
||||
{
|
||||
Uint8 hexBuffer[65];
|
||||
Uint32 numGlyphs = 0;
|
||||
|
|
@ -114,7 +114,7 @@ static void unifont_init(const char *fontname)
|
|||
if (unifontGlyph == NULL)
|
||||
{
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "unifont: Failed to allocate %d KiB for glyph data.\n", (int)(unifontGlyphSize + 1023) / 1024);
|
||||
exit(-1);
|
||||
return -1;
|
||||
}
|
||||
SDL_memset(unifontGlyph, 0, unifontGlyphSize);
|
||||
|
||||
|
|
@ -123,7 +123,7 @@ static void unifont_init(const char *fontname)
|
|||
if (unifontTexture == NULL)
|
||||
{
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "unifont: Failed to allocate %d KiB for texture pointer data.\n", (int)(unifontTextureSize + 1023) / 1024);
|
||||
exit(-1);
|
||||
return -1;
|
||||
}
|
||||
SDL_memset(unifontTexture, 0, unifontTextureSize);
|
||||
|
||||
|
|
@ -131,7 +131,7 @@ static void unifont_init(const char *fontname)
|
|||
if (hexFile == NULL)
|
||||
{
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "unifont: Failed to open font file: %s\n", fontname);
|
||||
exit(-1);
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Read all the glyph data into memory to make it accessible later when textures are created. */
|
||||
|
|
@ -146,8 +146,8 @@ static void unifont_init(const char *fontname)
|
|||
break; /* EOF */
|
||||
if ((numGlyphs == 0 && bytesRead == 0) || (numGlyphs > 0 && bytesRead < 9))
|
||||
{
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "unfiont: Unexpected end of hex file.\n");
|
||||
exit(-1);
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "unifont: Unexpected end of hex file.\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Looking for the colon that separates the codepoint and glyph data at position 2, 4, 6 and 8. */
|
||||
|
|
@ -162,13 +162,13 @@ static void unifont_init(const char *fontname)
|
|||
else
|
||||
{
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "unifont: Could not find codepoint and glyph data separator symbol in hex file on line %d.\n", lineNumber);
|
||||
exit(-1);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (!validate_hex((const char *)hexBuffer, codepointHexSize, &codepoint))
|
||||
{
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "unifont: Malformed hexadecimal number in hex file on line %d.\n", lineNumber);
|
||||
exit(-1);
|
||||
return -1;
|
||||
}
|
||||
if (codepoint > UNIFONT_MAX_CODEPOINT)
|
||||
SDL_LogWarn(SDL_LOG_CATEGORY_APPLICATION, "unifont: Codepoint on line %d exceeded limit of 0x%x.\n", lineNumber, UNIFONT_MAX_CODEPOINT);
|
||||
|
|
@ -181,7 +181,7 @@ static void unifont_init(const char *fontname)
|
|||
if (bytesRead < (33 - bytesOverread))
|
||||
{
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "unifont: Unexpected end of hex file.\n");
|
||||
exit(-1);
|
||||
return -1;
|
||||
}
|
||||
if (hexBuffer[32] == '\n')
|
||||
glyphWidth = 8;
|
||||
|
|
@ -192,14 +192,14 @@ static void unifont_init(const char *fontname)
|
|||
if (bytesRead < 32)
|
||||
{
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "unifont: Unexpected end of hex file.\n");
|
||||
exit(-1);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
if (!validate_hex((const char *)hexBuffer, glyphWidth * 4, NULL))
|
||||
{
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "unifont: Malformed hexadecimal glyph data in hex file on line %d.\n", lineNumber);
|
||||
exit(-1);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (codepoint <= UNIFONT_MAX_CODEPOINT)
|
||||
|
|
@ -221,6 +221,7 @@ static void unifont_init(const char *fontname)
|
|||
|
||||
SDL_RWclose(hexFile);
|
||||
SDL_Log("unifont: Loaded %u glyphs.\n", numGlyphs);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void unifont_make_rgba(Uint8 *src, Uint8 *dst, Uint8 width)
|
||||
|
|
@ -259,7 +260,7 @@ static void unifont_make_rgba(Uint8 *src, Uint8 *dst, Uint8 width)
|
|||
}
|
||||
}
|
||||
|
||||
static void unifont_load_texture(Uint32 textureID)
|
||||
static int unifont_load_texture(Uint32 textureID)
|
||||
{
|
||||
int i;
|
||||
Uint8 * textureRGBA;
|
||||
|
|
@ -267,14 +268,14 @@ static void unifont_load_texture(Uint32 textureID)
|
|||
if (textureID >= UNIFONT_NUM_TEXTURES)
|
||||
{
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "unifont: Tried to load out of range texture %u.\n", textureID);
|
||||
exit(-1);
|
||||
return -1;
|
||||
}
|
||||
|
||||
textureRGBA = (Uint8 *)SDL_malloc(UNIFONT_TEXTURE_SIZE);
|
||||
if (textureRGBA == NULL)
|
||||
{
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "unifont: Failed to allocate %d MiB for a texture.\n", UNIFONT_TEXTURE_SIZE / 1024 / 1024);
|
||||
exit(-1);
|
||||
return -1;
|
||||
}
|
||||
SDL_memset(textureRGBA, 0, UNIFONT_TEXTURE_SIZE);
|
||||
|
||||
|
|
@ -301,7 +302,7 @@ static void unifont_load_texture(Uint32 textureID)
|
|||
if (tex == NULL)
|
||||
{
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "unifont: Failed to create texture %u for renderer %d.\n", textureID, i);
|
||||
exit(-1);
|
||||
return -1;
|
||||
}
|
||||
unifontTexture[UNIFONT_NUM_TEXTURES * i + textureID] = tex;
|
||||
SDL_SetTextureBlendMode(tex, SDL_BLENDMODE_BLEND);
|
||||
|
|
@ -313,6 +314,7 @@ static void unifont_load_texture(Uint32 textureID)
|
|||
|
||||
SDL_free(textureRGBA);
|
||||
unifontTextureLoaded[textureID] = 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static Sint32 unifont_draw_glyph(Uint32 codepoint, int rendererID, SDL_Rect *dstrect)
|
||||
|
|
@ -321,10 +323,14 @@ static Sint32 unifont_draw_glyph(Uint32 codepoint, int rendererID, SDL_Rect *dst
|
|||
const Uint32 textureID = codepoint / UNIFONT_GLYPHS_IN_TEXTURE;
|
||||
SDL_Rect srcrect;
|
||||
srcrect.w = srcrect.h = 16;
|
||||
if (codepoint > UNIFONT_MAX_CODEPOINT)
|
||||
if (codepoint > UNIFONT_MAX_CODEPOINT) {
|
||||
return 0;
|
||||
if (!unifontTextureLoaded[textureID])
|
||||
unifont_load_texture(textureID);
|
||||
}
|
||||
if (!unifontTextureLoaded[textureID]) {
|
||||
if (unifont_load_texture(textureID) < 0) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
texture = unifontTexture[UNIFONT_NUM_TEXTURES * rendererID + textureID];
|
||||
if (texture != NULL)
|
||||
{
|
||||
|
|
@ -430,12 +436,10 @@ Uint32 utf8_decode(char *p, size_t len)
|
|||
void usage()
|
||||
{
|
||||
SDL_Log("usage: testime [--font fontfile]\n");
|
||||
exit(0);
|
||||
}
|
||||
|
||||
void InitInput()
|
||||
{
|
||||
|
||||
/* Prepare a rect for text input */
|
||||
textRect.x = textRect.y = 100;
|
||||
textRect.w = DEFAULT_WINDOW_WIDTH - 2 * textRect.x;
|
||||
|
|
@ -459,7 +463,8 @@ void CleanupVideo()
|
|||
#endif
|
||||
}
|
||||
|
||||
void _Redraw(int rendererID) {
|
||||
void _Redraw(int rendererID)
|
||||
{
|
||||
SDL_Renderer * renderer = state->renderers[rendererID];
|
||||
SDL_Rect drawnTextRect, cursorRect, underlineRect;
|
||||
drawnTextRect = textRect;
|
||||
|
|
@ -607,7 +612,8 @@ void _Redraw(int rendererID) {
|
|||
SDL_SetTextInputRect(&markedRect);
|
||||
}
|
||||
|
||||
void Redraw() {
|
||||
void Redraw()
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i < state->num_windows; ++i) {
|
||||
SDL_Renderer *renderer = state->renderers[i];
|
||||
|
|
@ -623,7 +629,8 @@ void Redraw() {
|
|||
}
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int i, done;
|
||||
SDL_Event event;
|
||||
const char *fontname = DEFAULT_FONT;
|
||||
|
|
@ -673,14 +680,15 @@ int main(int argc, char *argv[]) {
|
|||
if (! font)
|
||||
{
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to find font: %s\n", TTF_GetError());
|
||||
exit(-1);
|
||||
return -1;
|
||||
}
|
||||
#else
|
||||
unifont_init(fontname);
|
||||
if (unifont_init(fontname) < 0) {
|
||||
return -1;
|
||||
}
|
||||
#endif
|
||||
|
||||
SDL_Log("Using font: %s\n", fontname);
|
||||
atexit(SDL_Quit);
|
||||
|
||||
InitInput();
|
||||
/* Create the windows and initialize the renderers */
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2018 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,5 +1,5 @@
|
|||
/*
|
||||
Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2018 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
|
||||
|
|
@ -239,7 +239,7 @@ WatchJoystick(SDL_Joystick * joystick)
|
|||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
const char *name;
|
||||
const char *name, *type;
|
||||
int i;
|
||||
SDL_Joystick *joystick;
|
||||
|
||||
|
|
@ -268,12 +268,46 @@ main(int argc, char *argv[])
|
|||
SDL_assert(SDL_JoystickFromInstanceID(SDL_JoystickInstanceID(joystick)) == joystick);
|
||||
SDL_JoystickGetGUIDString(SDL_JoystickGetGUID(joystick),
|
||||
guid, sizeof (guid));
|
||||
switch (SDL_JoystickGetType(joystick)) {
|
||||
case SDL_JOYSTICK_TYPE_GAMECONTROLLER:
|
||||
type = "Game Controller";
|
||||
break;
|
||||
case SDL_JOYSTICK_TYPE_WHEEL:
|
||||
type = "Wheel";
|
||||
break;
|
||||
case SDL_JOYSTICK_TYPE_ARCADE_STICK:
|
||||
type = "Arcade Stick";
|
||||
break;
|
||||
case SDL_JOYSTICK_TYPE_FLIGHT_STICK:
|
||||
type = "Flight Stick";
|
||||
break;
|
||||
case SDL_JOYSTICK_TYPE_DANCE_PAD:
|
||||
type = "Dance Pad";
|
||||
break;
|
||||
case SDL_JOYSTICK_TYPE_GUITAR:
|
||||
type = "Guitar";
|
||||
break;
|
||||
case SDL_JOYSTICK_TYPE_DRUM_KIT:
|
||||
type = "Drum Kit";
|
||||
break;
|
||||
case SDL_JOYSTICK_TYPE_ARCADE_PAD:
|
||||
type = "Arcade Pad";
|
||||
break;
|
||||
case SDL_JOYSTICK_TYPE_THROTTLE:
|
||||
type = "Throttle";
|
||||
break;
|
||||
default:
|
||||
type = "Unknown";
|
||||
break;
|
||||
}
|
||||
SDL_Log(" type: %s\n", type);
|
||||
SDL_Log(" axes: %d\n", SDL_JoystickNumAxes(joystick));
|
||||
SDL_Log(" balls: %d\n", SDL_JoystickNumBalls(joystick));
|
||||
SDL_Log(" hats: %d\n", SDL_JoystickNumHats(joystick));
|
||||
SDL_Log(" buttons: %d\n", SDL_JoystickNumButtons(joystick));
|
||||
SDL_Log("instance id: %d\n", SDL_JoystickInstanceID(joystick));
|
||||
SDL_Log(" guid: %s\n", guid);
|
||||
SDL_Log(" VID/PID: 0x%.4x/0x%.4x\n", SDL_JoystickGetVendor(joystick), SDL_JoystickGetProduct(joystick));
|
||||
SDL_JoystickClose(joystick);
|
||||
}
|
||||
}
|
||||
|
|
@ -320,6 +354,7 @@ main(int argc, char *argv[])
|
|||
|| (event.type == SDL_MOUSEBUTTONDOWN)) {
|
||||
keepGoing = SDL_FALSE;
|
||||
} else if (event.type == SDL_JOYDEVICEADDED) {
|
||||
device = event.jdevice.which;
|
||||
joystick = SDL_JoystickOpen(device);
|
||||
if (joystick != NULL) {
|
||||
SDL_assert(SDL_JoystickFromInstanceID(SDL_JoystickInstanceID(joystick)) == joystick);
|
||||
|
|
@ -344,3 +379,5 @@ main(int argc, char *argv[])
|
|||
}
|
||||
|
||||
#endif
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2018 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,5 +1,5 @@
|
|||
/*
|
||||
Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2018 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,5 +1,5 @@
|
|||
/*
|
||||
Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2018 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,5 +1,5 @@
|
|||
/*
|
||||
Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2018 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
|
||||
|
|
@ -14,7 +14,6 @@
|
|||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <signal.h>
|
||||
|
||||
#include "SDL.h"
|
||||
|
||||
|
|
@ -26,7 +25,7 @@ quit(int rc)
|
|||
exit(rc);
|
||||
}
|
||||
|
||||
static int
|
||||
static int SDLCALL
|
||||
button_messagebox(void *eventNumber)
|
||||
{
|
||||
const SDL_MessageBoxButtonData buttons[] = {
|
||||
|
|
@ -47,12 +46,13 @@ button_messagebox(void *eventNumber)
|
|||
"Custom MessageBox",
|
||||
"This is a custom messagebox",
|
||||
2,
|
||||
buttons,
|
||||
NULL,/* buttons */
|
||||
NULL /* Default color scheme */
|
||||
};
|
||||
|
||||
int button = -1;
|
||||
int success = 0;
|
||||
data.buttons = buttons;
|
||||
if (eventNumber) {
|
||||
data.message = "This is a custom messagebox from a background thread.";
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2018 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,5 +1,5 @@
|
|||
/*
|
||||
Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2018 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,5 +1,5 @@
|
|||
/*
|
||||
Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2018 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,5 +1,5 @@
|
|||
/*
|
||||
Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2018 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,5 +1,5 @@
|
|||
/*
|
||||
Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2018 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,5 +1,5 @@
|
|||
/*
|
||||
Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2018 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
|
||||
|
|
@ -16,16 +16,14 @@
|
|||
* *
|
||||
********************************************************************************/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#ifdef __EMSCRIPTEN__
|
||||
#include <emscripten/emscripten.h>
|
||||
#endif
|
||||
|
||||
#include "SDL.h"
|
||||
|
||||
#include "testyuv_cvt.h"
|
||||
|
||||
#define MOOSEPIC_W 64
|
||||
#define MOOSEPIC_H 88
|
||||
|
||||
|
|
@ -33,110 +31,110 @@
|
|||
#define MOOSEFRAMES_COUNT 10
|
||||
|
||||
SDL_Color MooseColors[84] = {
|
||||
{49, 49, 49}
|
||||
, {66, 24, 0}
|
||||
, {66, 33, 0}
|
||||
, {66, 66, 66}
|
||||
{49, 49, 49, SDL_ALPHA_OPAQUE}
|
||||
, {66, 24, 0, SDL_ALPHA_OPAQUE}
|
||||
, {66, 33, 0, SDL_ALPHA_OPAQUE}
|
||||
, {66, 66, 66, SDL_ALPHA_OPAQUE}
|
||||
,
|
||||
{66, 115, 49}
|
||||
, {74, 33, 0}
|
||||
, {74, 41, 16}
|
||||
, {82, 33, 8}
|
||||
{66, 115, 49, SDL_ALPHA_OPAQUE}
|
||||
, {74, 33, 0, SDL_ALPHA_OPAQUE}
|
||||
, {74, 41, 16, SDL_ALPHA_OPAQUE}
|
||||
, {82, 33, 8, SDL_ALPHA_OPAQUE}
|
||||
,
|
||||
{82, 41, 8}
|
||||
, {82, 49, 16}
|
||||
, {82, 82, 82}
|
||||
, {90, 41, 8}
|
||||
{82, 41, 8, SDL_ALPHA_OPAQUE}
|
||||
, {82, 49, 16, SDL_ALPHA_OPAQUE}
|
||||
, {82, 82, 82, SDL_ALPHA_OPAQUE}
|
||||
, {90, 41, 8, SDL_ALPHA_OPAQUE}
|
||||
,
|
||||
{90, 41, 16}
|
||||
, {90, 57, 24}
|
||||
, {99, 49, 16}
|
||||
, {99, 66, 24}
|
||||
{90, 41, 16, SDL_ALPHA_OPAQUE}
|
||||
, {90, 57, 24, SDL_ALPHA_OPAQUE}
|
||||
, {99, 49, 16, SDL_ALPHA_OPAQUE}
|
||||
, {99, 66, 24, SDL_ALPHA_OPAQUE}
|
||||
,
|
||||
{99, 66, 33}
|
||||
, {99, 74, 33}
|
||||
, {107, 57, 24}
|
||||
, {107, 82, 41}
|
||||
{99, 66, 33, SDL_ALPHA_OPAQUE}
|
||||
, {99, 74, 33, SDL_ALPHA_OPAQUE}
|
||||
, {107, 57, 24, SDL_ALPHA_OPAQUE}
|
||||
, {107, 82, 41, SDL_ALPHA_OPAQUE}
|
||||
,
|
||||
{115, 57, 33}
|
||||
, {115, 66, 33}
|
||||
, {115, 66, 41}
|
||||
, {115, 74, 0}
|
||||
{115, 57, 33, SDL_ALPHA_OPAQUE}
|
||||
, {115, 66, 33, SDL_ALPHA_OPAQUE}
|
||||
, {115, 66, 41, SDL_ALPHA_OPAQUE}
|
||||
, {115, 74, 0, SDL_ALPHA_OPAQUE}
|
||||
,
|
||||
{115, 90, 49}
|
||||
, {115, 115, 115}
|
||||
, {123, 82, 0}
|
||||
, {123, 99, 57}
|
||||
{115, 90, 49, SDL_ALPHA_OPAQUE}
|
||||
, {115, 115, 115, SDL_ALPHA_OPAQUE}
|
||||
, {123, 82, 0, SDL_ALPHA_OPAQUE}
|
||||
, {123, 99, 57, SDL_ALPHA_OPAQUE}
|
||||
,
|
||||
{132, 66, 41}
|
||||
, {132, 74, 41}
|
||||
, {132, 90, 8}
|
||||
, {132, 99, 33}
|
||||
{132, 66, 41, SDL_ALPHA_OPAQUE}
|
||||
, {132, 74, 41, SDL_ALPHA_OPAQUE}
|
||||
, {132, 90, 8, SDL_ALPHA_OPAQUE}
|
||||
, {132, 99, 33, SDL_ALPHA_OPAQUE}
|
||||
,
|
||||
{132, 99, 66}
|
||||
, {132, 107, 66}
|
||||
, {140, 74, 49}
|
||||
, {140, 99, 16}
|
||||
{132, 99, 66, SDL_ALPHA_OPAQUE}
|
||||
, {132, 107, 66, SDL_ALPHA_OPAQUE}
|
||||
, {140, 74, 49, SDL_ALPHA_OPAQUE}
|
||||
, {140, 99, 16, SDL_ALPHA_OPAQUE}
|
||||
,
|
||||
{140, 107, 74}
|
||||
, {140, 115, 74}
|
||||
, {148, 107, 24}
|
||||
, {148, 115, 82}
|
||||
{140, 107, 74, SDL_ALPHA_OPAQUE}
|
||||
, {140, 115, 74, SDL_ALPHA_OPAQUE}
|
||||
, {148, 107, 24, SDL_ALPHA_OPAQUE}
|
||||
, {148, 115, 82, SDL_ALPHA_OPAQUE}
|
||||
,
|
||||
{148, 123, 74}
|
||||
, {148, 123, 90}
|
||||
, {156, 115, 33}
|
||||
, {156, 115, 90}
|
||||
{148, 123, 74, SDL_ALPHA_OPAQUE}
|
||||
, {148, 123, 90, SDL_ALPHA_OPAQUE}
|
||||
, {156, 115, 33, SDL_ALPHA_OPAQUE}
|
||||
, {156, 115, 90, SDL_ALPHA_OPAQUE}
|
||||
,
|
||||
{156, 123, 82}
|
||||
, {156, 132, 82}
|
||||
, {156, 132, 99}
|
||||
, {156, 156, 156}
|
||||
{156, 123, 82, SDL_ALPHA_OPAQUE}
|
||||
, {156, 132, 82, SDL_ALPHA_OPAQUE}
|
||||
, {156, 132, 99, SDL_ALPHA_OPAQUE}
|
||||
, {156, 156, 156, SDL_ALPHA_OPAQUE}
|
||||
,
|
||||
{165, 123, 49}
|
||||
, {165, 123, 90}
|
||||
, {165, 132, 82}
|
||||
, {165, 132, 90}
|
||||
{165, 123, 49, SDL_ALPHA_OPAQUE}
|
||||
, {165, 123, 90, SDL_ALPHA_OPAQUE}
|
||||
, {165, 132, 82, SDL_ALPHA_OPAQUE}
|
||||
, {165, 132, 90, SDL_ALPHA_OPAQUE}
|
||||
,
|
||||
{165, 132, 99}
|
||||
, {165, 140, 90}
|
||||
, {173, 132, 57}
|
||||
, {173, 132, 99}
|
||||
{165, 132, 99, SDL_ALPHA_OPAQUE}
|
||||
, {165, 140, 90, SDL_ALPHA_OPAQUE}
|
||||
, {173, 132, 57, SDL_ALPHA_OPAQUE}
|
||||
, {173, 132, 99, SDL_ALPHA_OPAQUE}
|
||||
,
|
||||
{173, 140, 107}
|
||||
, {173, 140, 115}
|
||||
, {173, 148, 99}
|
||||
, {173, 173, 173}
|
||||
{173, 140, 107, SDL_ALPHA_OPAQUE}
|
||||
, {173, 140, 115, SDL_ALPHA_OPAQUE}
|
||||
, {173, 148, 99, SDL_ALPHA_OPAQUE}
|
||||
, {173, 173, 173, SDL_ALPHA_OPAQUE}
|
||||
,
|
||||
{181, 140, 74}
|
||||
, {181, 148, 115}
|
||||
, {181, 148, 123}
|
||||
, {181, 156, 107}
|
||||
{181, 140, 74, SDL_ALPHA_OPAQUE}
|
||||
, {181, 148, 115, SDL_ALPHA_OPAQUE}
|
||||
, {181, 148, 123, SDL_ALPHA_OPAQUE}
|
||||
, {181, 156, 107, SDL_ALPHA_OPAQUE}
|
||||
,
|
||||
{189, 148, 123}
|
||||
, {189, 156, 82}
|
||||
, {189, 156, 123}
|
||||
, {189, 156, 132}
|
||||
{189, 148, 123, SDL_ALPHA_OPAQUE}
|
||||
, {189, 156, 82, SDL_ALPHA_OPAQUE}
|
||||
, {189, 156, 123, SDL_ALPHA_OPAQUE}
|
||||
, {189, 156, 132, SDL_ALPHA_OPAQUE}
|
||||
,
|
||||
{189, 189, 189}
|
||||
, {198, 156, 123}
|
||||
, {198, 165, 132}
|
||||
, {206, 165, 99}
|
||||
{189, 189, 189, SDL_ALPHA_OPAQUE}
|
||||
, {198, 156, 123, SDL_ALPHA_OPAQUE}
|
||||
, {198, 165, 132, SDL_ALPHA_OPAQUE}
|
||||
, {206, 165, 99, SDL_ALPHA_OPAQUE}
|
||||
,
|
||||
{206, 165, 132}
|
||||
, {206, 173, 140}
|
||||
, {206, 206, 206}
|
||||
, {214, 173, 115}
|
||||
{206, 165, 132, SDL_ALPHA_OPAQUE}
|
||||
, {206, 173, 140, SDL_ALPHA_OPAQUE}
|
||||
, {206, 206, 206, SDL_ALPHA_OPAQUE}
|
||||
, {214, 173, 115, SDL_ALPHA_OPAQUE}
|
||||
,
|
||||
{214, 173, 140}
|
||||
, {222, 181, 148}
|
||||
, {222, 189, 132}
|
||||
, {222, 189, 156}
|
||||
{214, 173, 140, SDL_ALPHA_OPAQUE}
|
||||
, {222, 181, 148, SDL_ALPHA_OPAQUE}
|
||||
, {222, 189, 132, SDL_ALPHA_OPAQUE}
|
||||
, {222, 189, 156, SDL_ALPHA_OPAQUE}
|
||||
,
|
||||
{222, 222, 222}
|
||||
, {231, 198, 165}
|
||||
, {231, 231, 231}
|
||||
, {239, 206, 173}
|
||||
{222, 222, 222, SDL_ALPHA_OPAQUE}
|
||||
, {231, 198, 165, SDL_ALPHA_OPAQUE}
|
||||
, {231, 231, 231, SDL_ALPHA_OPAQUE}
|
||||
, {239, 206, 173, SDL_ALPHA_OPAQUE}
|
||||
};
|
||||
|
||||
Uint8 MooseFrame[MOOSEFRAMES_COUNT][MOOSEFRAME_SIZE*2];
|
||||
|
|
@ -149,8 +147,7 @@ SDL_Renderer *renderer;
|
|||
int paused = 0;
|
||||
int i;
|
||||
SDL_bool done = SDL_FALSE;
|
||||
Uint32 pixel_format = SDL_PIXELFORMAT_YV12;
|
||||
int fpsdelay;
|
||||
static int fpsdelay;
|
||||
|
||||
/* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */
|
||||
static void
|
||||
|
|
@ -160,91 +157,6 @@ quit(int rc)
|
|||
exit(rc);
|
||||
}
|
||||
|
||||
/* All RGB2YUV conversion code and some other parts of code has been taken from testoverlay.c */
|
||||
|
||||
/* NOTE: These RGB conversion functions are not intended for speed,
|
||||
only as examples.
|
||||
*/
|
||||
|
||||
void
|
||||
RGBtoYUV(Uint8 * rgb, int *yuv, int monochrome, int luminance)
|
||||
{
|
||||
if (monochrome) {
|
||||
#if 1 /* these are the two formulas that I found on the FourCC site... */
|
||||
yuv[0] = (int)(0.299 * rgb[0] + 0.587 * rgb[1] + 0.114 * rgb[2]);
|
||||
yuv[1] = 128;
|
||||
yuv[2] = 128;
|
||||
#else
|
||||
yuv[0] = (int)(0.257 * rgb[0]) + (0.504 * rgb[1]) + (0.098 * rgb[2]) + 16;
|
||||
yuv[1] = 128;
|
||||
yuv[2] = 128;
|
||||
#endif
|
||||
} else {
|
||||
#if 1 /* these are the two formulas that I found on the FourCC site... */
|
||||
yuv[0] = (int)(0.299 * rgb[0] + 0.587 * rgb[1] + 0.114 * rgb[2]);
|
||||
yuv[1] = (int)((rgb[2] - yuv[0]) * 0.565 + 128);
|
||||
yuv[2] = (int)((rgb[0] - yuv[0]) * 0.713 + 128);
|
||||
#else
|
||||
yuv[0] = (0.257 * rgb[0]) + (0.504 * rgb[1]) + (0.098 * rgb[2]) + 16;
|
||||
yuv[1] = 128 - (0.148 * rgb[0]) - (0.291 * rgb[1]) + (0.439 * rgb[2]);
|
||||
yuv[2] = 128 + (0.439 * rgb[0]) - (0.368 * rgb[1]) - (0.071 * rgb[2]);
|
||||
#endif
|
||||
}
|
||||
|
||||
if (luminance != 100) {
|
||||
yuv[0] = yuv[0] * luminance / 100;
|
||||
if (yuv[0] > 255)
|
||||
yuv[0] = 255;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
ConvertRGBtoYV12(Uint8 *rgb, Uint8 *out, int w, int h,
|
||||
int monochrome, int luminance)
|
||||
{
|
||||
int x, y;
|
||||
int yuv[3];
|
||||
Uint8 *op[3];
|
||||
|
||||
op[0] = out;
|
||||
op[1] = op[0] + w*h;
|
||||
op[2] = op[1] + w*h/4;
|
||||
for (y = 0; y < h; ++y) {
|
||||
for (x = 0; x < w; ++x) {
|
||||
RGBtoYUV(rgb, yuv, monochrome, luminance);
|
||||
*(op[0]++) = yuv[0];
|
||||
if (x % 2 == 0 && y % 2 == 0) {
|
||||
*(op[1]++) = yuv[2];
|
||||
*(op[2]++) = yuv[1];
|
||||
}
|
||||
rgb += 3;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
ConvertRGBtoNV12(Uint8 *rgb, Uint8 *out, int w, int h,
|
||||
int monochrome, int luminance)
|
||||
{
|
||||
int x, y;
|
||||
int yuv[3];
|
||||
Uint8 *op[2];
|
||||
|
||||
op[0] = out;
|
||||
op[1] = op[0] + w*h;
|
||||
for (y = 0; y < h; ++y) {
|
||||
for (x = 0; x < w; ++x) {
|
||||
RGBtoYUV(rgb, yuv, monochrome, luminance);
|
||||
*(op[0]++) = yuv[0];
|
||||
if (x % 2 == 0 && y % 2 == 0) {
|
||||
*(op[1]++) = yuv[1];
|
||||
*(op[1]++) = yuv[2];
|
||||
}
|
||||
rgb += 3;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
PrintUsage(char *argv0)
|
||||
{
|
||||
|
|
@ -307,7 +219,7 @@ loop()
|
|||
if (!paused) {
|
||||
i = (i + 1) % MOOSEFRAMES_COUNT;
|
||||
|
||||
SDL_UpdateTexture(MooseTexture, NULL, MooseFrame[i], MOOSEPIC_W*SDL_BYTESPERPIXEL(pixel_format));
|
||||
SDL_UpdateTexture(MooseTexture, NULL, MooseFrame[i], MOOSEPIC_W);
|
||||
}
|
||||
SDL_RenderClear(renderer);
|
||||
SDL_RenderCopy(renderer, MooseTexture, NULL, &displayrect);
|
||||
|
|
@ -328,13 +240,7 @@ main(int argc, char **argv)
|
|||
SDL_Window *window;
|
||||
int j;
|
||||
int fps = 12;
|
||||
int fpsdelay;
|
||||
int nodelay = 0;
|
||||
#ifdef TEST_NV12
|
||||
Uint32 pixel_format = SDL_PIXELFORMAT_NV12;
|
||||
#else
|
||||
Uint32 pixel_format = SDL_PIXELFORMAT_YV12;
|
||||
#endif
|
||||
int scale = 5;
|
||||
|
||||
/* Enable standard application logging */
|
||||
|
|
@ -348,7 +254,7 @@ main(int argc, char **argv)
|
|||
while (argc > 1) {
|
||||
if (strcmp(argv[1], "-fps") == 0) {
|
||||
if (argv[2]) {
|
||||
fps = atoi(argv[2]);
|
||||
fps = SDL_atoi(argv[2]);
|
||||
if (fps == 0) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,
|
||||
"The -fps option requires an argument [from 1 to 1000], default is 12.\n");
|
||||
|
|
@ -372,7 +278,7 @@ main(int argc, char **argv)
|
|||
argc -= 1;
|
||||
} else if (strcmp(argv[1], "-scale") == 0) {
|
||||
if (argv[2]) {
|
||||
scale = atoi(argv[2]);
|
||||
scale = SDL_atoi(argv[2]);
|
||||
if (scale == 0) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,
|
||||
"The -scale option requires an argument [from 1 to 50], default is 5.\n");
|
||||
|
|
@ -404,7 +310,6 @@ main(int argc, char **argv)
|
|||
RawMooseData = (Uint8 *) malloc(MOOSEFRAME_SIZE * MOOSEFRAMES_COUNT);
|
||||
if (RawMooseData == NULL) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Can't allocate memory for movie !\n");
|
||||
free(RawMooseData);
|
||||
quit(1);
|
||||
}
|
||||
|
||||
|
|
@ -441,7 +346,7 @@ main(int argc, char **argv)
|
|||
quit(4);
|
||||
}
|
||||
|
||||
MooseTexture = SDL_CreateTexture(renderer, pixel_format, SDL_TEXTUREACCESS_STREAMING, MOOSEPIC_W, MOOSEPIC_H);
|
||||
MooseTexture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_YV12, SDL_TEXTUREACCESS_STREAMING, MOOSEPIC_W, MOOSEPIC_H);
|
||||
if (!MooseTexture) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't set create texture: %s\n", SDL_GetError());
|
||||
free(RawMooseData);
|
||||
|
|
@ -463,17 +368,9 @@ main(int argc, char **argv)
|
|||
rgb[2] = MooseColors[frame[j]].b;
|
||||
rgb += 3;
|
||||
}
|
||||
switch (pixel_format) {
|
||||
case SDL_PIXELFORMAT_YV12:
|
||||
ConvertRGBtoYV12(MooseFrameRGB, MooseFrame[i], MOOSEPIC_W, MOOSEPIC_H, 0, 100);
|
||||
break;
|
||||
case SDL_PIXELFORMAT_NV12:
|
||||
ConvertRGBtoNV12(MooseFrameRGB, MooseFrame[i], MOOSEPIC_W, MOOSEPIC_H, 0, 100);
|
||||
break;
|
||||
default:
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Unsupported pixel format\n");
|
||||
break;
|
||||
}
|
||||
ConvertRGBtoYUV(SDL_PIXELFORMAT_YV12, MooseFrameRGB, MOOSEPIC_W*3, MooseFrame[i], MOOSEPIC_W, MOOSEPIC_H,
|
||||
SDL_GetYUVConversionModeForResolution(MOOSEPIC_W, MOOSEPIC_H),
|
||||
0, 100);
|
||||
}
|
||||
|
||||
free(RawMooseData);
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2018 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
|
||||
|
|
@ -30,6 +30,26 @@ TestTypes(SDL_bool verbose)
|
|||
{
|
||||
int error = 0;
|
||||
|
||||
SDL_COMPILE_TIME_ASSERT(SDL_MAX_SINT8, SDL_MAX_SINT8 == 127);
|
||||
SDL_COMPILE_TIME_ASSERT(SDL_MIN_SINT8, SDL_MIN_SINT8 == -128);
|
||||
SDL_COMPILE_TIME_ASSERT(SDL_MAX_UINT8, SDL_MAX_UINT8 == 255);
|
||||
SDL_COMPILE_TIME_ASSERT(SDL_MIN_UINT8, SDL_MIN_UINT8 == 0);
|
||||
|
||||
SDL_COMPILE_TIME_ASSERT(SDL_MAX_SINT16, SDL_MAX_SINT16 == 32767);
|
||||
SDL_COMPILE_TIME_ASSERT(SDL_MIN_SINT16, SDL_MIN_SINT16 == -32768);
|
||||
SDL_COMPILE_TIME_ASSERT(SDL_MAX_UINT16, SDL_MAX_UINT16 == 65535);
|
||||
SDL_COMPILE_TIME_ASSERT(SDL_MIN_UINT16, SDL_MIN_UINT16 == 0);
|
||||
|
||||
SDL_COMPILE_TIME_ASSERT(SDL_MAX_SINT32, SDL_MAX_SINT32 == 2147483647);
|
||||
SDL_COMPILE_TIME_ASSERT(SDL_MIN_SINT32, SDL_MIN_SINT32 == ~0x7fffffff); /* Instead of -2147483648, which is treated as unsigned by some compilers */
|
||||
SDL_COMPILE_TIME_ASSERT(SDL_MAX_UINT32, SDL_MAX_UINT32 == 4294967295u);
|
||||
SDL_COMPILE_TIME_ASSERT(SDL_MIN_UINT32, SDL_MIN_UINT32 == 0);
|
||||
|
||||
SDL_COMPILE_TIME_ASSERT(SDL_MAX_SINT64, SDL_MAX_SINT64 == 9223372036854775807ll);
|
||||
SDL_COMPILE_TIME_ASSERT(SDL_MIN_SINT64, SDL_MIN_SINT64 == ~0x7fffffffffffffffll); /* Instead of -9223372036854775808, which is treated as unsigned by compilers */
|
||||
SDL_COMPILE_TIME_ASSERT(SDL_MAX_UINT64, SDL_MAX_UINT64 == 18446744073709551615ull);
|
||||
SDL_COMPILE_TIME_ASSERT(SDL_MIN_UINT64, SDL_MIN_UINT64 == 0);
|
||||
|
||||
if (badsize(sizeof(Uint8), 1)) {
|
||||
if (verbose)
|
||||
SDL_Log("sizeof(Uint8) != 1, instead = %u\n",
|
||||
|
|
@ -128,6 +148,220 @@ TestEndian(SDL_bool verbose)
|
|||
return (error ? 1 : 0);
|
||||
}
|
||||
|
||||
static int TST_allmul (void *a, void *b, int arg, void *result, void *expected)
|
||||
{
|
||||
(*(long long *)result) = ((*(long long *)a) * (*(long long *)b));
|
||||
return (*(long long *)result) == (*(long long *)expected);
|
||||
}
|
||||
|
||||
static int TST_alldiv (void *a, void *b, int arg, void *result, void *expected)
|
||||
{
|
||||
(*(long long *)result) = ((*(long long *)a) / (*(long long *)b));
|
||||
return (*(long long *)result) == (*(long long *)expected);
|
||||
}
|
||||
|
||||
static int TST_allrem (void *a, void *b, int arg, void *result, void *expected)
|
||||
{
|
||||
(*(long long *)result) = ((*(long long *)a) % (*(long long *)b));
|
||||
return (*(long long *)result) == (*(long long *)expected);
|
||||
}
|
||||
|
||||
static int TST_ualldiv (void *a, void *b, int arg, void *result, void *expected)
|
||||
{
|
||||
(*(unsigned long long *)result) = ((*(unsigned long long *)a) / (*(unsigned long long *)b));
|
||||
return (*(unsigned long long *)result) == (*(unsigned long long *)expected);
|
||||
}
|
||||
|
||||
static int TST_uallrem (void *a, void *b, int arg, void *result, void *expected)
|
||||
{
|
||||
(*(unsigned long long *)result) = ((*(unsigned long long *)a) % (*(unsigned long long *)b));
|
||||
return (*(unsigned long long *)result) == (*(unsigned long long *)expected);
|
||||
}
|
||||
|
||||
static int TST_allshl (void *a, void *b, int arg, void *result, void *expected)
|
||||
{
|
||||
(*(long long *)result) = (*(long long *)a) << arg;
|
||||
return (*(long long *)result) == (*(long long *)expected);
|
||||
}
|
||||
|
||||
static int TST_aullshl (void *a, void *b, int arg, void *result, void *expected)
|
||||
{
|
||||
(*(unsigned long long *)result) = (*(unsigned long long *)a) << arg;
|
||||
return (*(unsigned long long *)result) == (*(unsigned long long *)expected);
|
||||
}
|
||||
|
||||
static int TST_allshr (void *a, void *b, int arg, void *result, void *expected)
|
||||
{
|
||||
(*(long long *)result) = (*(long long *)a) >> arg;
|
||||
return (*(long long *)result) == (*(long long *)expected);
|
||||
}
|
||||
|
||||
static int TST_aullshr (void *a, void *b, int arg, void *result, void *expected)
|
||||
{
|
||||
(*(unsigned long long *)result) = (*(unsigned long long *)a) >> arg;
|
||||
return (*(unsigned long long *)result) == (*(unsigned long long *)expected);
|
||||
}
|
||||
|
||||
|
||||
typedef int (*LL_Intrinsic)(void *a, void *b, int arg, void *result, void *expected);
|
||||
|
||||
typedef struct {
|
||||
const char *operation;
|
||||
LL_Intrinsic routine;
|
||||
unsigned long long a, b;
|
||||
int arg;
|
||||
unsigned long long expected_result;
|
||||
} LL_Test;
|
||||
|
||||
static LL_Test LL_Tests[] =
|
||||
{
|
||||
/* UNDEFINED {"_allshl", &TST_allshl, 0xFFFFFFFFFFFFFFFFll, 0ll, 65, 0x0000000000000000ll}, */
|
||||
{"_allshl", &TST_allshl, 0xFFFFFFFFFFFFFFFFll, 0ll, 1, 0xFFFFFFFFFFFFFFFEll},
|
||||
{"_allshl", &TST_allshl, 0xFFFFFFFFFFFFFFFFll, 0ll, 32, 0xFFFFFFFF00000000ll},
|
||||
{"_allshl", &TST_allshl, 0xFFFFFFFFFFFFFFFFll, 0ll, 33, 0xFFFFFFFE00000000ll},
|
||||
{"_allshl", &TST_allshl, 0xFFFFFFFFFFFFFFFFll, 0ll, 0, 0xFFFFFFFFFFFFFFFFll},
|
||||
|
||||
{"_allshr", &TST_allshr, 0xAAAAAAAA55555555ll, 0ll, 63, 0xFFFFFFFFFFFFFFFFll},
|
||||
/* UNDEFINED {"_allshr", &TST_allshr, 0xFFFFFFFFFFFFFFFFll, 0ll, 65, 0xFFFFFFFFFFFFFFFFll}, */
|
||||
{"_allshr", &TST_allshr, 0xFFFFFFFFFFFFFFFFll, 0ll, 1, 0xFFFFFFFFFFFFFFFFll},
|
||||
{"_allshr", &TST_allshr, 0xFFFFFFFFFFFFFFFFll, 0ll, 32, 0xFFFFFFFFFFFFFFFFll},
|
||||
{"_allshr", &TST_allshr, 0xFFFFFFFFFFFFFFFFll, 0ll, 33, 0xFFFFFFFFFFFFFFFFll},
|
||||
{"_allshr", &TST_allshr, 0xFFFFFFFFFFFFFFFFll, 0ll, 0, 0xFFFFFFFFFFFFFFFFll},
|
||||
/* UNDEFINED {"_allshr", &TST_allshr, 0x5F5F5F5F5F5F5F5Fll, 0ll, 65, 0x0000000000000000ll}, */
|
||||
{"_allshr", &TST_allshr, 0x5F5F5F5F5F5F5F5Fll, 0ll, 1, 0x2FAFAFAFAFAFAFAFll},
|
||||
{"_allshr", &TST_allshr, 0x5F5F5F5F5F5F5F5Fll, 0ll, 32, 0x000000005F5F5F5Fll},
|
||||
{"_allshr", &TST_allshr, 0x5F5F5F5F5F5F5F5Fll, 0ll, 33, 0x000000002FAFAFAFll},
|
||||
|
||||
/* UNDEFINED {"_aullshl", &TST_aullshl, 0xFFFFFFFFFFFFFFFFll, 0ll, 65, 0x0000000000000000ll}, */
|
||||
{"_aullshl", &TST_aullshl, 0xFFFFFFFFFFFFFFFFll, 0ll, 1, 0xFFFFFFFFFFFFFFFEll},
|
||||
{"_aullshl", &TST_aullshl, 0xFFFFFFFFFFFFFFFFll, 0ll, 32, 0xFFFFFFFF00000000ll},
|
||||
{"_aullshl", &TST_aullshl, 0xFFFFFFFFFFFFFFFFll, 0ll, 33, 0xFFFFFFFE00000000ll},
|
||||
{"_aullshl", &TST_aullshl, 0xFFFFFFFFFFFFFFFFll, 0ll, 0, 0xFFFFFFFFFFFFFFFFll},
|
||||
|
||||
/* UNDEFINED {"_aullshr", &TST_aullshr, 0xFFFFFFFFFFFFFFFFll, 0ll, 65, 0x0000000000000000ll}, */
|
||||
{"_aullshr", &TST_aullshr, 0xFFFFFFFFFFFFFFFFll, 0ll, 1, 0x7FFFFFFFFFFFFFFFll},
|
||||
{"_aullshr", &TST_aullshr, 0xFFFFFFFFFFFFFFFFll, 0ll, 32, 0x00000000FFFFFFFFll},
|
||||
{"_aullshr", &TST_aullshr, 0xFFFFFFFFFFFFFFFFll, 0ll, 33, 0x000000007FFFFFFFll},
|
||||
{"_aullshr", &TST_aullshr, 0xFFFFFFFFFFFFFFFFll, 0ll, 0, 0xFFFFFFFFFFFFFFFFll},
|
||||
|
||||
{"_allmul", &TST_allmul, 0xFFFFFFFFFFFFFFFFll, 0x0000000000000000ll, 0, 0x0000000000000000ll},
|
||||
{"_allmul", &TST_allmul, 0x0000000000000000ll, 0xFFFFFFFFFFFFFFFFll, 0, 0x0000000000000000ll},
|
||||
{"_allmul", &TST_allmul, 0x000000000FFFFFFFll, 0x0000000000000001ll, 0, 0x000000000FFFFFFFll},
|
||||
{"_allmul", &TST_allmul, 0x0000000000000001ll, 0x000000000FFFFFFFll, 0, 0x000000000FFFFFFFll},
|
||||
{"_allmul", &TST_allmul, 0x000000000FFFFFFFll, 0x0000000000000010ll, 0, 0x00000000FFFFFFF0ll},
|
||||
{"_allmul", &TST_allmul, 0x0000000000000010ll, 0x000000000FFFFFFFll, 0, 0x00000000FFFFFFF0ll},
|
||||
{"_allmul", &TST_allmul, 0x000000000FFFFFFFll, 0x0000000000000100ll, 0, 0x0000000FFFFFFF00ll},
|
||||
{"_allmul", &TST_allmul, 0x0000000000000100ll, 0x000000000FFFFFFFll, 0, 0x0000000FFFFFFF00ll},
|
||||
{"_allmul", &TST_allmul, 0x000000000FFFFFFFll, 0x0000000010000000ll, 0, 0x00FFFFFFF0000000ll},
|
||||
{"_allmul", &TST_allmul, 0x0000000010000000ll, 0x000000000FFFFFFFll, 0, 0x00FFFFFFF0000000ll},
|
||||
{"_allmul", &TST_allmul, 0x000000000FFFFFFFll, 0x0000000080000000ll, 0, 0x07FFFFFF80000000ll},
|
||||
{"_allmul", &TST_allmul, 0x0000000080000000ll, 0x000000000FFFFFFFll, 0, 0x07FFFFFF80000000ll},
|
||||
{"_allmul", &TST_allmul, 0xFFFFFFFFFFFFFFFEll, 0x0000000080000000ll, 0, 0xFFFFFFFF00000000ll},
|
||||
{"_allmul", &TST_allmul, 0x0000000080000000ll, 0xFFFFFFFFFFFFFFFEll, 0, 0xFFFFFFFF00000000ll},
|
||||
{"_allmul", &TST_allmul, 0xFFFFFFFFFFFFFFFEll, 0x0000000080000008ll, 0, 0xFFFFFFFEFFFFFFF0ll},
|
||||
{"_allmul", &TST_allmul, 0x0000000080000008ll, 0xFFFFFFFFFFFFFFFEll, 0, 0xFFFFFFFEFFFFFFF0ll},
|
||||
{"_allmul", &TST_allmul, 0x00000000FFFFFFFFll, 0x00000000FFFFFFFFll, 0, 0xFFFFFFFE00000001ll},
|
||||
|
||||
{"_alldiv", &TST_alldiv, 0x0000000000000000ll, 0x0000000000000001ll, 0, 0x0000000000000000ll},
|
||||
{"_alldiv", &TST_alldiv, 0x0000000000000000ll, 0xFFFFFFFFFFFFFFFFll, 0, 0x0000000000000000ll},
|
||||
{"_alldiv", &TST_alldiv, 0x0000000000000001ll, 0xFFFFFFFFFFFFFFFFll, 0, 0xFFFFFFFFFFFFFFFFll},
|
||||
{"_alldiv", &TST_alldiv, 0xFFFFFFFFFFFFFFFFll, 0x0000000000000001ll, 0, 0xFFFFFFFFFFFFFFFFll},
|
||||
{"_alldiv", &TST_alldiv, 0x0000000000000001ll, 0xFFFFFFFFFFFFFFFFll, 0, 0xFFFFFFFFFFFFFFFFll},
|
||||
{"_alldiv", &TST_alldiv, 0x0000000000000001ll, 0x0000000000000001ll, 0, 0x0000000000000001ll},
|
||||
{"_alldiv", &TST_alldiv, 0xFFFFFFFFFFFFFFFFll, 0xFFFFFFFFFFFFFFFFll, 0, 0x0000000000000001ll},
|
||||
{"_alldiv", &TST_alldiv, 0x000000000FFFFFFFll, 0x0000000000000001ll, 0, 0x000000000FFFFFFFll},
|
||||
{"_alldiv", &TST_alldiv, 0x0000000FFFFFFFFFll, 0x0000000000000010ll, 0, 0x00000000FFFFFFFFll},
|
||||
{"_alldiv", &TST_alldiv, 0x0000000000000100ll, 0x000000000FFFFFFFll, 0, 0x0000000000000000ll},
|
||||
{"_alldiv", &TST_alldiv, 0x00FFFFFFF0000000ll, 0x0000000010000000ll, 0, 0x000000000FFFFFFFll},
|
||||
{"_alldiv", &TST_alldiv, 0x07FFFFFF80000000ll, 0x0000000080000000ll, 0, 0x000000000FFFFFFFll},
|
||||
{"_alldiv", &TST_alldiv, 0xFFFFFFFFFFFFFFFEll, 0x0000000080000000ll, 0, 0x0000000000000000ll},
|
||||
{"_alldiv", &TST_alldiv, 0xFFFFFFFEFFFFFFF0ll, 0xFFFFFFFFFFFFFFFEll, 0, 0x0000000080000008ll},
|
||||
{"_alldiv", &TST_alldiv, 0x7FFFFFFEFFFFFFF0ll, 0xFFFFFFFFFFFFFFFEll, 0, 0xC000000080000008ll},
|
||||
{"_alldiv", &TST_alldiv, 0x7FFFFFFEFFFFFFF0ll, 0x0000FFFFFFFFFFFEll, 0, 0x0000000000007FFFll},
|
||||
{"_alldiv", &TST_alldiv, 0x7FFFFFFEFFFFFFF0ll, 0x7FFFFFFEFFFFFFF0ll, 0, 0x0000000000000001ll},
|
||||
|
||||
{"_allrem", &TST_allrem, 0x0000000000000000ll, 0x0000000000000001ll, 0, 0x0000000000000000ll},
|
||||
{"_allrem", &TST_allrem, 0x0000000000000000ll, 0xFFFFFFFFFFFFFFFFll, 0, 0x0000000000000000ll},
|
||||
{"_allrem", &TST_allrem, 0x0000000000000001ll, 0xFFFFFFFFFFFFFFFFll, 0, 0x0000000000000000ll},
|
||||
{"_allrem", &TST_allrem, 0xFFFFFFFFFFFFFFFFll, 0x0000000000000001ll, 0, 0x0000000000000000ll},
|
||||
{"_allrem", &TST_allrem, 0x0000000000000001ll, 0xFFFFFFFFFFFFFFFFll, 0, 0x0000000000000000ll},
|
||||
{"_allrem", &TST_allrem, 0x0000000000000001ll, 0x0000000000000001ll, 0, 0x0000000000000000ll},
|
||||
{"_allrem", &TST_allrem, 0xFFFFFFFFFFFFFFFFll, 0xFFFFFFFFFFFFFFFFll, 0, 0x0000000000000000ll},
|
||||
{"_allrem", &TST_allrem, 0x000000000FFFFFFFll, 0x0000000000000001ll, 0, 0x0000000000000000ll},
|
||||
{"_allrem", &TST_allrem, 0x0000000FFFFFFFFFll, 0x0000000000000010ll, 0, 0x000000000000000Fll},
|
||||
{"_allrem", &TST_allrem, 0x0000000000000100ll, 0x000000000FFFFFFFll, 0, 0x0000000000000100ll},
|
||||
{"_allrem", &TST_allrem, 0x00FFFFFFF0000000ll, 0x0000000010000000ll, 0, 0x0000000000000000ll},
|
||||
{"_allrem", &TST_allrem, 0x07FFFFFF80000000ll, 0x0000000080000000ll, 0, 0x0000000000000000ll},
|
||||
{"_allrem", &TST_allrem, 0xFFFFFFFFFFFFFFFEll, 0x0000000080000000ll, 0, 0xFFFFFFFFFFFFFFFEll},
|
||||
{"_allrem", &TST_allrem, 0xFFFFFFFEFFFFFFF0ll, 0xFFFFFFFFFFFFFFFEll, 0, 0x0000000000000000ll},
|
||||
{"_allrem", &TST_allrem, 0x7FFFFFFEFFFFFFF0ll, 0xFFFFFFFFFFFFFFFEll, 0, 0x0000000000000000ll},
|
||||
{"_allrem", &TST_allrem, 0x7FFFFFFEFFFFFFF0ll, 0x0000FFFFFFFFFFFEll, 0, 0x0000FFFF0000FFEEll},
|
||||
{"_allrem", &TST_allrem, 0x7FFFFFFEFFFFFFF0ll, 0x7FFFFFFEFFFFFFF0ll, 0, 0x0000000000000000ll},
|
||||
|
||||
|
||||
{"_ualldiv", &TST_ualldiv, 0x0000000000000000ll, 0x0000000000000001ll, 0, 0x0000000000000000ll},
|
||||
{"_ualldiv", &TST_ualldiv, 0x0000000000000000ll, 0xFFFFFFFFFFFFFFFFll, 0, 0x0000000000000000ll},
|
||||
{"_ualldiv", &TST_ualldiv, 0x0000000000000001ll, 0xFFFFFFFFFFFFFFFFll, 0, 0x0000000000000000ll},
|
||||
{"_ualldiv", &TST_ualldiv, 0xFFFFFFFFFFFFFFFFll, 0x0000000000000001ll, 0, 0xFFFFFFFFFFFFFFFFll},
|
||||
{"_ualldiv", &TST_ualldiv, 0x0000000000000001ll, 0xFFFFFFFFFFFFFFFFll, 0, 0x0000000000000000ll},
|
||||
{"_ualldiv", &TST_ualldiv, 0x0000000000000001ll, 0x0000000000000001ll, 0, 0x0000000000000001ll},
|
||||
{"_ualldiv", &TST_ualldiv, 0xFFFFFFFFFFFFFFFFll, 0xFFFFFFFFFFFFFFFFll, 0, 0x0000000000000001ll},
|
||||
{"_ualldiv", &TST_ualldiv, 0x000000000FFFFFFFll, 0x0000000000000001ll, 0, 0x000000000FFFFFFFll},
|
||||
{"_ualldiv", &TST_ualldiv, 0x0000000FFFFFFFFFll, 0x0000000000000010ll, 0, 0x00000000FFFFFFFFll},
|
||||
{"_ualldiv", &TST_ualldiv, 0x0000000000000100ll, 0x000000000FFFFFFFll, 0, 0x0000000000000000ll},
|
||||
{"_ualldiv", &TST_ualldiv, 0x00FFFFFFF0000000ll, 0x0000000010000000ll, 0, 0x000000000FFFFFFFll},
|
||||
{"_ualldiv", &TST_ualldiv, 0x07FFFFFF80000000ll, 0x0000000080000000ll, 0, 0x000000000FFFFFFFll},
|
||||
{"_ualldiv", &TST_ualldiv, 0xFFFFFFFFFFFFFFFEll, 0x0000000080000000ll, 0, 0x00000001FFFFFFFFll},
|
||||
{"_ualldiv", &TST_ualldiv, 0xFFFFFFFEFFFFFFF0ll, 0xFFFFFFFFFFFFFFFEll, 0, 0x0000000000000000ll},
|
||||
{"_ualldiv", &TST_ualldiv, 0x7FFFFFFEFFFFFFF0ll, 0xFFFFFFFFFFFFFFFEll, 0, 0x0000000000000000ll},
|
||||
{"_ualldiv", &TST_ualldiv, 0x7FFFFFFEFFFFFFF0ll, 0x0000FFFFFFFFFFFEll, 0, 0x0000000000007FFFll},
|
||||
{"_ualldiv", &TST_ualldiv, 0x7FFFFFFEFFFFFFF0ll, 0x7FFFFFFEFFFFFFF0ll, 0, 0x0000000000000001ll},
|
||||
|
||||
{"_uallrem", &TST_uallrem, 0x0000000000000000ll, 0x0000000000000001ll, 0, 0x0000000000000000ll},
|
||||
{"_uallrem", &TST_uallrem, 0x0000000000000000ll, 0xFFFFFFFFFFFFFFFFll, 0, 0x0000000000000000ll},
|
||||
{"_uallrem", &TST_uallrem, 0x0000000000000001ll, 0xFFFFFFFFFFFFFFFFll, 0, 0x0000000000000001ll},
|
||||
{"_uallrem", &TST_uallrem, 0xFFFFFFFFFFFFFFFFll, 0x0000000000000001ll, 0, 0x0000000000000000ll},
|
||||
{"_uallrem", &TST_uallrem, 0x0000000000000001ll, 0xFFFFFFFFFFFFFFFFll, 0, 0x0000000000000001ll},
|
||||
{"_uallrem", &TST_uallrem, 0x0000000000000001ll, 0x0000000000000001ll, 0, 0x0000000000000000ll},
|
||||
{"_uallrem", &TST_uallrem, 0xFFFFFFFFFFFFFFFFll, 0xFFFFFFFFFFFFFFFFll, 0, 0x0000000000000000ll},
|
||||
{"_uallrem", &TST_uallrem, 0x000000000FFFFFFFll, 0x0000000000000001ll, 0, 0x0000000000000000ll},
|
||||
{"_uallrem", &TST_uallrem, 0x0000000FFFFFFFFFll, 0x0000000000000010ll, 0, 0x000000000000000Fll},
|
||||
{"_uallrem", &TST_uallrem, 0x0000000000000100ll, 0x000000000FFFFFFFll, 0, 0x0000000000000100ll},
|
||||
{"_uallrem", &TST_uallrem, 0x00FFFFFFF0000000ll, 0x0000000010000000ll, 0, 0x0000000000000000ll},
|
||||
{"_uallrem", &TST_uallrem, 0x07FFFFFF80000000ll, 0x0000000080000000ll, 0, 0x0000000000000000ll},
|
||||
{"_uallrem", &TST_uallrem, 0xFFFFFFFFFFFFFFFEll, 0x0000000080000000ll, 0, 0x000000007FFFFFFEll},
|
||||
{"_uallrem", &TST_uallrem, 0xFFFFFFFEFFFFFFF0ll, 0xFFFFFFFFFFFFFFFEll, 0, 0xFFFFFFFEFFFFFFF0ll},
|
||||
{"_uallrem", &TST_uallrem, 0x7FFFFFFEFFFFFFF0ll, 0xFFFFFFFFFFFFFFFEll, 0, 0x7FFFFFFEFFFFFFF0ll},
|
||||
{"_uallrem", &TST_uallrem, 0x7FFFFFFEFFFFFFF0ll, 0x0000FFFFFFFFFFFEll, 0, 0x0000FFFF0000FFEEll},
|
||||
{"_uallrem", &TST_uallrem, 0x7FFFFFFEFFFFFFF0ll, 0x7FFFFFFEFFFFFFF0ll, 0, 0x0000000000000000ll},
|
||||
|
||||
{NULL}
|
||||
};
|
||||
|
||||
int
|
||||
Test64Bit (SDL_bool verbose)
|
||||
{
|
||||
LL_Test *t;
|
||||
int failed = 0;
|
||||
|
||||
for (t = LL_Tests; t->routine != NULL; t++) {
|
||||
unsigned long long result = 0;
|
||||
unsigned int *al = (unsigned int *)&t->a;
|
||||
unsigned int *bl = (unsigned int *)&t->b;
|
||||
unsigned int *el = (unsigned int *)&t->expected_result;
|
||||
unsigned int *rl = (unsigned int *)&result;
|
||||
|
||||
if (!t->routine(&t->a, &t->b, t->arg, &result, &t->expected_result)) {
|
||||
if (verbose)
|
||||
SDL_Log("%s(0x%08X%08X, 0x%08X%08X, %3d, produced: 0x%08X%08X, expected: 0x%08X%08X\n",
|
||||
t->operation, al[1], al[0], bl[1], bl[0], t->arg, rl[1], rl[0], el[1], el[0]);
|
||||
++failed;
|
||||
}
|
||||
}
|
||||
if (verbose && (failed == 0))
|
||||
SDL_Log("All 64bit instrinsic tests passed\n");
|
||||
return (failed ? 1 : 0);
|
||||
}
|
||||
|
||||
int
|
||||
TestCPUInfo(SDL_bool verbose)
|
||||
|
|
@ -145,6 +379,8 @@ TestCPUInfo(SDL_bool verbose)
|
|||
SDL_Log("SSE4.1 %s\n", SDL_HasSSE41()? "detected" : "not detected");
|
||||
SDL_Log("SSE4.2 %s\n", SDL_HasSSE42()? "detected" : "not detected");
|
||||
SDL_Log("AVX %s\n", SDL_HasAVX()? "detected" : "not detected");
|
||||
SDL_Log("AVX2 %s\n", SDL_HasAVX2()? "detected" : "not detected");
|
||||
SDL_Log("NEON %s\n", SDL_HasNEON()? "detected" : "not detected");
|
||||
SDL_Log("System RAM %d MB\n", SDL_GetSystemRAM());
|
||||
}
|
||||
return (0);
|
||||
|
|
@ -197,6 +433,7 @@ main(int argc, char *argv[])
|
|||
|
||||
status += TestTypes(verbose);
|
||||
status += TestEndian(verbose);
|
||||
status += Test64Bit(verbose);
|
||||
status += TestCPUInfo(verbose);
|
||||
status += TestAssertions(verbose);
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2018 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,5 +1,5 @@
|
|||
/*
|
||||
Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2018 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,5 +1,5 @@
|
|||
/*
|
||||
Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2018 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,5 +1,5 @@
|
|||
/*
|
||||
Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2018 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,5 +1,5 @@
|
|||
/*
|
||||
Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2018 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,5 +1,5 @@
|
|||
/*
|
||||
Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2018 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
|
||||
|
|
@ -20,6 +20,7 @@ main(int argc, char **argv)
|
|||
Uint32 len = 0;
|
||||
Uint8 *data = NULL;
|
||||
int cvtfreq = 0;
|
||||
int cvtchans = 0;
|
||||
int bitsize = 0;
|
||||
int blockalign = 0;
|
||||
int avgbytes = 0;
|
||||
|
|
@ -28,12 +29,13 @@ main(int argc, char **argv)
|
|||
/* Enable standard application logging */
|
||||
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
|
||||
|
||||
if (argc != 4) {
|
||||
SDL_Log("USAGE: %s in.wav out.wav newfreq\n", argv[0]);
|
||||
if (argc != 5) {
|
||||
SDL_Log("USAGE: %s in.wav out.wav newfreq newchans\n", argv[0]);
|
||||
return 1;
|
||||
}
|
||||
|
||||
cvtfreq = SDL_atoi(argv[3]);
|
||||
cvtchans = SDL_atoi(argv[4]);
|
||||
|
||||
if (SDL_Init(SDL_INIT_AUDIO) == -1) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDL_Init() failed: %s\n", SDL_GetError());
|
||||
|
|
@ -47,7 +49,7 @@ main(int argc, char **argv)
|
|||
}
|
||||
|
||||
if (SDL_BuildAudioCVT(&cvt, spec.format, spec.channels, spec.freq,
|
||||
spec.format, spec.channels, cvtfreq) == -1) {
|
||||
spec.format, cvtchans, cvtfreq) == -1) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "failed to build CVT: %s\n", SDL_GetError());
|
||||
SDL_FreeWAV(data);
|
||||
SDL_Quit();
|
||||
|
|
@ -83,16 +85,16 @@ main(int argc, char **argv)
|
|||
}
|
||||
|
||||
bitsize = SDL_AUDIO_BITSIZE(spec.format);
|
||||
blockalign = (bitsize / 8) * spec.channels;
|
||||
blockalign = (bitsize / 8) * cvtchans;
|
||||
avgbytes = cvtfreq * blockalign;
|
||||
|
||||
SDL_WriteLE32(io, 0x46464952); /* RIFF */
|
||||
SDL_WriteLE32(io, len * cvt.len_mult + 36);
|
||||
SDL_WriteLE32(io, cvt.len_cvt + 36);
|
||||
SDL_WriteLE32(io, 0x45564157); /* WAVE */
|
||||
SDL_WriteLE32(io, 0x20746D66); /* fmt */
|
||||
SDL_WriteLE32(io, 16); /* chunk size */
|
||||
SDL_WriteLE16(io, 1); /* uncompressed */
|
||||
SDL_WriteLE16(io, spec.channels); /* channels */
|
||||
SDL_WriteLE16(io, cvtchans); /* channels */
|
||||
SDL_WriteLE32(io, cvtfreq); /* sample rate */
|
||||
SDL_WriteLE32(io, avgbytes); /* average bytes per second */
|
||||
SDL_WriteLE16(io, blockalign); /* block align */
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2018 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,6 +54,7 @@ main(int argc, char **argv)
|
|||
name = NULL;
|
||||
index = -1;
|
||||
if (argc > 1) {
|
||||
size_t l;
|
||||
name = argv[1];
|
||||
if ((strcmp(name, "--help") == 0) || (strcmp(name, "-h") == 0)) {
|
||||
SDL_Log("USAGE: %s [device]\n"
|
||||
|
|
@ -63,9 +64,9 @@ main(int argc, char **argv)
|
|||
return 0;
|
||||
}
|
||||
|
||||
i = strlen(name);
|
||||
if ((i < 3) && isdigit(name[0]) && ((i == 1) || isdigit(name[1]))) {
|
||||
index = atoi(name);
|
||||
l = SDL_strlen(name);
|
||||
if ((l < 3) && SDL_isdigit(name[0]) && ((l == 1) || SDL_isdigit(name[1]))) {
|
||||
index = SDL_atoi(name);
|
||||
name = NULL;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2018 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,5 +1,5 @@
|
|||
/*
|
||||
Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2018 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,5 +1,5 @@
|
|||
/*
|
||||
Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2018 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,5 +1,5 @@
|
|||
/*
|
||||
Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2018 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
|
||||
|
|
@ -48,7 +48,6 @@ int main(int argc,char** argv)
|
|||
SDL_Renderer *renderer;
|
||||
SDL_Color black = {0,0,0,0xff};
|
||||
SDL_Event event;
|
||||
int event_pending = 0;
|
||||
int should_exit = 0;
|
||||
unsigned int current_picture;
|
||||
int button_down;
|
||||
|
|
@ -81,7 +80,6 @@ int main(int argc,char** argv)
|
|||
pictures[i].surface = SDL_LoadBMP(argv[i+1]);
|
||||
pictures[i].name = argv[i+1];
|
||||
if(pictures[i].surface == NULL) {
|
||||
j = 0;
|
||||
for(j=0;j<num_pictures;j++)
|
||||
SDL_FreeSurface(pictures[j].surface);
|
||||
SDL_free(pictures);
|
||||
|
|
@ -130,8 +128,7 @@ int main(int argc,char** argv)
|
|||
for(i=0;i<num_pictures;i++) {
|
||||
pictures[i].texture = SDL_CreateTextureFromSurface(renderer,pictures[i].surface);
|
||||
if(pictures[i].texture == NULL) {
|
||||
j = 0;
|
||||
for(j=0;j<num_pictures;i++)
|
||||
for(i=0;i<num_pictures;i++)
|
||||
if(pictures[i].texture != NULL)
|
||||
SDL_DestroyTexture(pictures[i].texture);
|
||||
for(i=0;i<num_pictures;i++)
|
||||
|
|
@ -145,9 +142,7 @@ int main(int argc,char** argv)
|
|||
}
|
||||
}
|
||||
|
||||
event_pending = 0;
|
||||
should_exit = 0;
|
||||
event_pending = SDL_PollEvent(&event);
|
||||
current_picture = 0;
|
||||
button_down = 0;
|
||||
texture_dimensions.h = 0;
|
||||
|
|
@ -159,8 +154,7 @@ int main(int argc,char** argv)
|
|||
SDL_SetWindowSize(window,texture_dimensions.w,texture_dimensions.h);
|
||||
SDL_SetWindowShape(window,pictures[current_picture].surface,&pictures[current_picture].mode);
|
||||
while(should_exit == 0) {
|
||||
event_pending = SDL_PollEvent(&event);
|
||||
if(event_pending == 1) {
|
||||
while (SDL_PollEvent(&event)) {
|
||||
if(event.type == SDL_KEYDOWN) {
|
||||
button_down = 1;
|
||||
if(event.key.keysym.sym == SDLK_ESCAPE) {
|
||||
|
|
@ -178,9 +172,10 @@ int main(int argc,char** argv)
|
|||
SDL_SetWindowSize(window,texture_dimensions.w,texture_dimensions.h);
|
||||
SDL_SetWindowShape(window,pictures[current_picture].surface,&pictures[current_picture].mode);
|
||||
}
|
||||
if(event.type == SDL_QUIT)
|
||||
if (event.type == SDL_QUIT) {
|
||||
should_exit = 1;
|
||||
event_pending = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
render(renderer,pictures[current_picture].texture,texture_dimensions);
|
||||
SDL_Delay(10);
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2018 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
|
||||
|
|
@ -99,7 +99,12 @@ LoadSprite(const char *file)
|
|||
SDL_FreeSurface(temp);
|
||||
return (-1);
|
||||
}
|
||||
SDL_SetTextureBlendMode(sprites[i], blendMode);
|
||||
if (SDL_SetTextureBlendMode(sprites[i], blendMode) < 0) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't set blend mode: %s\n", SDL_GetError());
|
||||
SDL_FreeSurface(temp);
|
||||
SDL_DestroyTexture(sprites[i]);
|
||||
return (-1);
|
||||
}
|
||||
}
|
||||
SDL_FreeSurface(temp);
|
||||
|
||||
|
|
@ -295,6 +300,9 @@ main(int argc, char *argv[])
|
|||
} else if (SDL_strcasecmp(argv[i + 1], "mod") == 0) {
|
||||
blendMode = SDL_BLENDMODE_MOD;
|
||||
consumed = 2;
|
||||
} else if (SDL_strcasecmp(argv[i + 1], "sub") == 0) {
|
||||
blendMode = SDL_ComposeCustomBlendMode(SDL_BLENDFACTOR_SRC_ALPHA, SDL_BLENDFACTOR_ONE, SDL_BLENDOPERATION_SUBTRACT, SDL_BLENDFACTOR_ZERO, SDL_BLENDFACTOR_ONE, SDL_BLENDOPERATION_SUBTRACT);
|
||||
consumed = 2;
|
||||
}
|
||||
}
|
||||
} else if (SDL_strcasecmp(argv[i], "--iterations") == 0) {
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2018 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,5 +1,5 @@
|
|||
/*
|
||||
Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2018 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,5 +1,5 @@
|
|||
/*
|
||||
Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2018 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,5 +1,5 @@
|
|||
/*
|
||||
Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2018 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,5 +1,5 @@
|
|||
/*
|
||||
Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2018 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,5 +1,5 @@
|
|||
/*
|
||||
Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2018 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
|
||||
|
|
|
|||
1201
Engine/lib/sdl/test/testvulkan.c
Normal file
1201
Engine/lib/sdl/test/testvulkan.c
Normal file
File diff suppressed because it is too large
Load diff
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2018 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
|
||||
|
|
|
|||
BIN
Engine/lib/sdl/test/testyuv.bmp
Normal file
BIN
Engine/lib/sdl/test/testyuv.bmp
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 722 KiB |
455
Engine/lib/sdl/test/testyuv.c
Normal file
455
Engine/lib/sdl/test/testyuv.c
Normal file
|
|
@ -0,0 +1,455 @@
|
|||
/*
|
||||
Copyright (C) 1997-2018 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.
|
||||
*/
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "SDL.h"
|
||||
#include "SDL_test_font.h"
|
||||
#include "testyuv_cvt.h"
|
||||
|
||||
|
||||
/* 422 (YUY2, etc) formats are the largest */
|
||||
#define MAX_YUV_SURFACE_SIZE(W, H, P) (H*4*(W+P+1)/2)
|
||||
|
||||
|
||||
/* Return true if the YUV format is packed pixels */
|
||||
static SDL_bool is_packed_yuv_format(Uint32 format)
|
||||
{
|
||||
return (format == SDL_PIXELFORMAT_YUY2 ||
|
||||
format == SDL_PIXELFORMAT_UYVY ||
|
||||
format == SDL_PIXELFORMAT_YVYU);
|
||||
}
|
||||
|
||||
/* Create a surface with a good pattern for verifying YUV conversion */
|
||||
static SDL_Surface *generate_test_pattern(int pattern_size)
|
||||
{
|
||||
SDL_Surface *pattern = SDL_CreateRGBSurfaceWithFormat(0, pattern_size, pattern_size, 0, SDL_PIXELFORMAT_RGB24);
|
||||
|
||||
if (pattern) {
|
||||
int i, x, y;
|
||||
Uint8 *p, c;
|
||||
const int thickness = 2; /* Important so 2x2 blocks of color are the same, to avoid Cr/Cb interpolation over pixels */
|
||||
|
||||
/* R, G, B in alternating horizontal bands */
|
||||
for (y = 0; y < pattern->h; y += thickness) {
|
||||
for (i = 0; i < thickness; ++i) {
|
||||
p = (Uint8 *)pattern->pixels + (y + i) * pattern->pitch + ((y/thickness) % 3);
|
||||
for (x = 0; x < pattern->w; ++x) {
|
||||
*p = 0xFF;
|
||||
p += 3;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Black and white in alternating vertical bands */
|
||||
c = 0xFF;
|
||||
for (x = 1*thickness; x < pattern->w; x += 2*thickness) {
|
||||
for (i = 0; i < thickness; ++i) {
|
||||
p = (Uint8 *)pattern->pixels + (x + i)*3;
|
||||
for (y = 0; y < pattern->h; ++y) {
|
||||
SDL_memset(p, c, 3);
|
||||
p += pattern->pitch;
|
||||
}
|
||||
}
|
||||
if (c) {
|
||||
c = 0x00;
|
||||
} else {
|
||||
c = 0xFF;
|
||||
}
|
||||
}
|
||||
}
|
||||
return pattern;
|
||||
}
|
||||
|
||||
static SDL_bool verify_yuv_data(Uint32 format, const Uint8 *yuv, int yuv_pitch, SDL_Surface *surface)
|
||||
{
|
||||
const int tolerance = 20;
|
||||
const int size = (surface->h * surface->pitch);
|
||||
Uint8 *rgb;
|
||||
SDL_bool result = SDL_FALSE;
|
||||
|
||||
rgb = (Uint8 *)SDL_malloc(size);
|
||||
if (!rgb) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Out of memory");
|
||||
return SDL_FALSE;
|
||||
}
|
||||
|
||||
if (SDL_ConvertPixels(surface->w, surface->h, format, yuv, yuv_pitch, surface->format->format, rgb, surface->pitch) == 0) {
|
||||
int x, y;
|
||||
result = SDL_TRUE;
|
||||
for (y = 0; y < surface->h; ++y) {
|
||||
const Uint8 *actual = rgb + y * surface->pitch;
|
||||
const Uint8 *expected = (const Uint8 *)surface->pixels + y * surface->pitch;
|
||||
for (x = 0; x < surface->w; ++x) {
|
||||
int deltaR = (int)actual[0] - expected[0];
|
||||
int deltaG = (int)actual[1] - expected[1];
|
||||
int deltaB = (int)actual[2] - expected[2];
|
||||
int distance = (deltaR * deltaR + deltaG * deltaG + deltaB * deltaB);
|
||||
if (distance > tolerance) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Pixel at %d,%d was 0x%.2x,0x%.2x,0x%.2x, expected 0x%.2x,0x%.2x,0x%.2x, distance = %d\n", x, y, actual[0], actual[1], actual[2], expected[0], expected[1], expected[2], distance);
|
||||
result = SDL_FALSE;
|
||||
}
|
||||
actual += 3;
|
||||
expected += 3;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't convert %s to %s: %s\n", SDL_GetPixelFormatName(format), SDL_GetPixelFormatName(surface->format->format), SDL_GetError());
|
||||
}
|
||||
SDL_free(rgb);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
static int run_automated_tests(int pattern_size, int extra_pitch)
|
||||
{
|
||||
const Uint32 formats[] = {
|
||||
SDL_PIXELFORMAT_YV12,
|
||||
SDL_PIXELFORMAT_IYUV,
|
||||
SDL_PIXELFORMAT_NV12,
|
||||
SDL_PIXELFORMAT_NV21,
|
||||
SDL_PIXELFORMAT_YUY2,
|
||||
SDL_PIXELFORMAT_UYVY,
|
||||
SDL_PIXELFORMAT_YVYU
|
||||
};
|
||||
int i, j;
|
||||
SDL_Surface *pattern = generate_test_pattern(pattern_size);
|
||||
const int yuv_len = MAX_YUV_SURFACE_SIZE(pattern->w, pattern->h, extra_pitch);
|
||||
Uint8 *yuv1 = (Uint8 *)SDL_malloc(yuv_len);
|
||||
Uint8 *yuv2 = (Uint8 *)SDL_malloc(yuv_len);
|
||||
int yuv1_pitch, yuv2_pitch;
|
||||
int result = -1;
|
||||
|
||||
if (!pattern || !yuv1 || !yuv2) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't allocate test surfaces");
|
||||
goto done;
|
||||
}
|
||||
|
||||
/* Verify conversion from YUV formats */
|
||||
for (i = 0; i < SDL_arraysize(formats); ++i) {
|
||||
if (!ConvertRGBtoYUV(formats[i], pattern->pixels, pattern->pitch, yuv1, pattern->w, pattern->h, SDL_GetYUVConversionModeForResolution(pattern->w, pattern->h), 0, 100)) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "ConvertRGBtoYUV() doesn't support converting to %s\n", SDL_GetPixelFormatName(formats[i]));
|
||||
goto done;
|
||||
}
|
||||
yuv1_pitch = CalculateYUVPitch(formats[i], pattern->w);
|
||||
if (!verify_yuv_data(formats[i], yuv1, yuv1_pitch, pattern)) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed conversion from %s to RGB\n", SDL_GetPixelFormatName(formats[i]));
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
|
||||
/* Verify conversion to YUV formats */
|
||||
for (i = 0; i < SDL_arraysize(formats); ++i) {
|
||||
yuv1_pitch = CalculateYUVPitch(formats[i], pattern->w) + extra_pitch;
|
||||
if (SDL_ConvertPixels(pattern->w, pattern->h, pattern->format->format, pattern->pixels, pattern->pitch, formats[i], yuv1, yuv1_pitch) < 0) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't convert %s to %s: %s\n", SDL_GetPixelFormatName(pattern->format->format), SDL_GetPixelFormatName(formats[i]), SDL_GetError());
|
||||
goto done;
|
||||
}
|
||||
if (!verify_yuv_data(formats[i], yuv1, yuv1_pitch, pattern)) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed conversion from RGB to %s\n", SDL_GetPixelFormatName(formats[i]));
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
|
||||
/* Verify conversion between YUV formats */
|
||||
for (i = 0; i < SDL_arraysize(formats); ++i) {
|
||||
for (j = 0; j < SDL_arraysize(formats); ++j) {
|
||||
yuv1_pitch = CalculateYUVPitch(formats[i], pattern->w) + extra_pitch;
|
||||
yuv2_pitch = CalculateYUVPitch(formats[j], pattern->w) + extra_pitch;
|
||||
if (SDL_ConvertPixels(pattern->w, pattern->h, pattern->format->format, pattern->pixels, pattern->pitch, formats[i], yuv1, yuv1_pitch) < 0) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't convert %s to %s: %s\n", SDL_GetPixelFormatName(pattern->format->format), SDL_GetPixelFormatName(formats[i]), SDL_GetError());
|
||||
goto done;
|
||||
}
|
||||
if (SDL_ConvertPixels(pattern->w, pattern->h, formats[i], yuv1, yuv1_pitch, formats[j], yuv2, yuv2_pitch) < 0) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't convert %s to %s: %s\n", SDL_GetPixelFormatName(formats[i]), SDL_GetPixelFormatName(formats[j]), SDL_GetError());
|
||||
goto done;
|
||||
}
|
||||
if (!verify_yuv_data(formats[j], yuv2, yuv2_pitch, pattern)) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed conversion from %s to %s\n", SDL_GetPixelFormatName(formats[i]), SDL_GetPixelFormatName(formats[j]));
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Verify conversion between YUV formats in-place */
|
||||
for (i = 0; i < SDL_arraysize(formats); ++i) {
|
||||
for (j = 0; j < SDL_arraysize(formats); ++j) {
|
||||
if (is_packed_yuv_format(formats[i]) != is_packed_yuv_format(formats[j])) {
|
||||
/* Can't change plane vs packed pixel layout in-place */
|
||||
continue;
|
||||
}
|
||||
|
||||
yuv1_pitch = CalculateYUVPitch(formats[i], pattern->w) + extra_pitch;
|
||||
yuv2_pitch = CalculateYUVPitch(formats[j], pattern->w) + extra_pitch;
|
||||
if (SDL_ConvertPixels(pattern->w, pattern->h, pattern->format->format, pattern->pixels, pattern->pitch, formats[i], yuv1, yuv1_pitch) < 0) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't convert %s to %s: %s\n", SDL_GetPixelFormatName(pattern->format->format), SDL_GetPixelFormatName(formats[i]), SDL_GetError());
|
||||
goto done;
|
||||
}
|
||||
if (SDL_ConvertPixels(pattern->w, pattern->h, formats[i], yuv1, yuv1_pitch, formats[j], yuv1, yuv2_pitch) < 0) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't convert %s to %s: %s\n", SDL_GetPixelFormatName(formats[i]), SDL_GetPixelFormatName(formats[j]), SDL_GetError());
|
||||
goto done;
|
||||
}
|
||||
if (!verify_yuv_data(formats[j], yuv1, yuv2_pitch, pattern)) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed conversion from %s to %s\n", SDL_GetPixelFormatName(formats[i]), SDL_GetPixelFormatName(formats[j]));
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
result = 0;
|
||||
|
||||
done:
|
||||
SDL_free(yuv1);
|
||||
SDL_free(yuv2);
|
||||
SDL_FreeSurface(pattern);
|
||||
return result;
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
struct {
|
||||
SDL_bool enable_intrinsics;
|
||||
int pattern_size;
|
||||
int extra_pitch;
|
||||
} automated_test_params[] = {
|
||||
/* Test: even width and height */
|
||||
{ SDL_FALSE, 2, 0 },
|
||||
{ SDL_FALSE, 4, 0 },
|
||||
/* Test: odd width and height */
|
||||
{ SDL_FALSE, 1, 0 },
|
||||
{ SDL_FALSE, 3, 0 },
|
||||
/* Test: even width and height, extra pitch */
|
||||
{ SDL_FALSE, 2, 3 },
|
||||
{ SDL_FALSE, 4, 3 },
|
||||
/* Test: odd width and height, extra pitch */
|
||||
{ SDL_FALSE, 1, 3 },
|
||||
{ SDL_FALSE, 3, 3 },
|
||||
/* Test: even width and height with intrinsics */
|
||||
{ SDL_TRUE, 32, 0 },
|
||||
/* Test: odd width and height with intrinsics */
|
||||
{ SDL_TRUE, 33, 0 },
|
||||
{ SDL_TRUE, 37, 0 },
|
||||
/* Test: even width and height with intrinsics, extra pitch */
|
||||
{ SDL_TRUE, 32, 3 },
|
||||
/* Test: odd width and height with intrinsics, extra pitch */
|
||||
{ SDL_TRUE, 33, 3 },
|
||||
{ SDL_TRUE, 37, 3 },
|
||||
};
|
||||
int arg = 1;
|
||||
const char *filename;
|
||||
SDL_Surface *original;
|
||||
SDL_Surface *converted;
|
||||
SDL_Window *window;
|
||||
SDL_Renderer *renderer;
|
||||
SDL_Texture *output[3];
|
||||
const char *titles[3] = { "ORIGINAL", "SOFTWARE", "HARDWARE" };
|
||||
char title[128];
|
||||
const char *yuv_name;
|
||||
const char *yuv_mode;
|
||||
Uint32 rgb_format = SDL_PIXELFORMAT_RGBX8888;
|
||||
Uint32 yuv_format = SDL_PIXELFORMAT_YV12;
|
||||
int current = 0;
|
||||
int pitch;
|
||||
Uint8 *raw_yuv;
|
||||
Uint32 then, now, i, iterations = 100;
|
||||
SDL_bool should_run_automated_tests = SDL_FALSE;
|
||||
|
||||
while (argv[arg] && *argv[arg] == '-') {
|
||||
if (SDL_strcmp(argv[arg], "--jpeg") == 0) {
|
||||
SDL_SetYUVConversionMode(SDL_YUV_CONVERSION_JPEG);
|
||||
} else if (SDL_strcmp(argv[arg], "--bt601") == 0) {
|
||||
SDL_SetYUVConversionMode(SDL_YUV_CONVERSION_BT601);
|
||||
} else if (SDL_strcmp(argv[arg], "--bt709") == 0) {
|
||||
SDL_SetYUVConversionMode(SDL_YUV_CONVERSION_BT709);
|
||||
} else if (SDL_strcmp(argv[arg], "--auto") == 0) {
|
||||
SDL_SetYUVConversionMode(SDL_YUV_CONVERSION_AUTOMATIC);
|
||||
} else if (SDL_strcmp(argv[arg], "--yv12") == 0) {
|
||||
yuv_format = SDL_PIXELFORMAT_YV12;
|
||||
} else if (SDL_strcmp(argv[arg], "--iyuv") == 0) {
|
||||
yuv_format = SDL_PIXELFORMAT_IYUV;
|
||||
} else if (SDL_strcmp(argv[arg], "--yuy2") == 0) {
|
||||
yuv_format = SDL_PIXELFORMAT_YUY2;
|
||||
} else if (SDL_strcmp(argv[arg], "--uyvy") == 0) {
|
||||
yuv_format = SDL_PIXELFORMAT_UYVY;
|
||||
} else if (SDL_strcmp(argv[arg], "--yvyu") == 0) {
|
||||
yuv_format = SDL_PIXELFORMAT_YVYU;
|
||||
} else if (SDL_strcmp(argv[arg], "--nv12") == 0) {
|
||||
yuv_format = SDL_PIXELFORMAT_NV12;
|
||||
} else if (SDL_strcmp(argv[arg], "--nv21") == 0) {
|
||||
yuv_format = SDL_PIXELFORMAT_NV21;
|
||||
} else if (SDL_strcmp(argv[arg], "--rgb555") == 0) {
|
||||
rgb_format = SDL_PIXELFORMAT_RGB555;
|
||||
} else if (SDL_strcmp(argv[arg], "--rgb565") == 0) {
|
||||
rgb_format = SDL_PIXELFORMAT_RGB565;
|
||||
} else if (SDL_strcmp(argv[arg], "--rgb24") == 0) {
|
||||
rgb_format = SDL_PIXELFORMAT_RGB24;
|
||||
} else if (SDL_strcmp(argv[arg], "--argb") == 0) {
|
||||
rgb_format = SDL_PIXELFORMAT_ARGB8888;
|
||||
} else if (SDL_strcmp(argv[arg], "--abgr") == 0) {
|
||||
rgb_format = SDL_PIXELFORMAT_ABGR8888;
|
||||
} else if (SDL_strcmp(argv[arg], "--rgba") == 0) {
|
||||
rgb_format = SDL_PIXELFORMAT_RGBA8888;
|
||||
} else if (SDL_strcmp(argv[arg], "--bgra") == 0) {
|
||||
rgb_format = SDL_PIXELFORMAT_BGRA8888;
|
||||
} else if (SDL_strcmp(argv[arg], "--automated") == 0) {
|
||||
should_run_automated_tests = SDL_TRUE;
|
||||
} else {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Usage: %s [--jpeg|--bt601|-bt709|--auto] [--yv12|--iyuv|--yuy2|--uyvy|--yvyu|--nv12|--nv21] [--rgb555|--rgb565|--rgb24|--argb|--abgr|--rgba|--bgra] [image_filename]\n", argv[0]);
|
||||
return 1;
|
||||
}
|
||||
++arg;
|
||||
}
|
||||
|
||||
/* Run automated tests */
|
||||
if (should_run_automated_tests) {
|
||||
for (i = 0; i < SDL_arraysize(automated_test_params); ++i) {
|
||||
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "Running automated test, pattern size %d, extra pitch %d, intrinsics %s\n",
|
||||
automated_test_params[i].pattern_size,
|
||||
automated_test_params[i].extra_pitch,
|
||||
automated_test_params[i].enable_intrinsics ? "enabled" : "disabled");
|
||||
if (run_automated_tests(automated_test_params[i].pattern_size, automated_test_params[i].extra_pitch) < 0) {
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (argv[arg]) {
|
||||
filename = argv[arg];
|
||||
} else {
|
||||
filename = "testyuv.bmp";
|
||||
}
|
||||
original = SDL_ConvertSurfaceFormat(SDL_LoadBMP(filename), SDL_PIXELFORMAT_RGB24, 0);
|
||||
if (!original) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't load %s: %s\n", filename, SDL_GetError());
|
||||
return 3;
|
||||
}
|
||||
|
||||
raw_yuv = SDL_calloc(1, MAX_YUV_SURFACE_SIZE(original->w, original->h, 0));
|
||||
ConvertRGBtoYUV(yuv_format, original->pixels, original->pitch, raw_yuv, original->w, original->h,
|
||||
SDL_GetYUVConversionModeForResolution(original->w, original->h),
|
||||
0, 100);
|
||||
pitch = CalculateYUVPitch(yuv_format, original->w);
|
||||
|
||||
converted = SDL_CreateRGBSurfaceWithFormat(0, original->w, original->h, 0, rgb_format);
|
||||
if (!converted) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create converted surface: %s\n", SDL_GetError());
|
||||
return 3;
|
||||
}
|
||||
|
||||
then = SDL_GetTicks();
|
||||
for ( i = 0; i < iterations; ++i ) {
|
||||
SDL_ConvertPixels(original->w, original->h, yuv_format, raw_yuv, pitch, rgb_format, converted->pixels, converted->pitch);
|
||||
}
|
||||
now = SDL_GetTicks();
|
||||
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "%d iterations in %d ms, %.2fms each\n", iterations, (now - then), (float)(now - then)/iterations);
|
||||
|
||||
window = SDL_CreateWindow("YUV test",
|
||||
SDL_WINDOWPOS_UNDEFINED,
|
||||
SDL_WINDOWPOS_UNDEFINED,
|
||||
original->w, original->h,
|
||||
0);
|
||||
if (!window) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create window: %s\n", SDL_GetError());
|
||||
return 4;
|
||||
}
|
||||
|
||||
renderer = SDL_CreateRenderer(window, -1, 0);
|
||||
if (!renderer) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create renderer: %s\n", SDL_GetError());
|
||||
return 4;
|
||||
}
|
||||
|
||||
output[0] = SDL_CreateTextureFromSurface(renderer, original);
|
||||
output[1] = SDL_CreateTextureFromSurface(renderer, converted);
|
||||
output[2] = SDL_CreateTexture(renderer, yuv_format, SDL_TEXTUREACCESS_STREAMING, original->w, original->h);
|
||||
if (!output[0] || !output[1] || !output[2]) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't set create texture: %s\n", SDL_GetError());
|
||||
return 5;
|
||||
}
|
||||
SDL_UpdateTexture(output[2], NULL, raw_yuv, pitch);
|
||||
|
||||
yuv_name = SDL_GetPixelFormatName(yuv_format);
|
||||
if (SDL_strncmp(yuv_name, "SDL_PIXELFORMAT_", 16) == 0) {
|
||||
yuv_name += 16;
|
||||
}
|
||||
|
||||
switch (SDL_GetYUVConversionModeForResolution(original->w, original->h)) {
|
||||
case SDL_YUV_CONVERSION_JPEG:
|
||||
yuv_mode = "JPEG";
|
||||
break;
|
||||
case SDL_YUV_CONVERSION_BT601:
|
||||
yuv_mode = "BT.601";
|
||||
break;
|
||||
case SDL_YUV_CONVERSION_BT709:
|
||||
yuv_mode = "BT.709";
|
||||
break;
|
||||
default:
|
||||
yuv_mode = "UNKNOWN";
|
||||
break;
|
||||
}
|
||||
|
||||
{ int done = 0;
|
||||
while ( !done )
|
||||
{
|
||||
SDL_Event event;
|
||||
while (SDL_PollEvent(&event) > 0) {
|
||||
if (event.type == SDL_QUIT) {
|
||||
done = 1;
|
||||
}
|
||||
if (event.type == SDL_KEYDOWN) {
|
||||
if (event.key.keysym.sym == SDLK_ESCAPE) {
|
||||
done = 1;
|
||||
} else if (event.key.keysym.sym == SDLK_LEFT) {
|
||||
--current;
|
||||
} else if (event.key.keysym.sym == SDLK_RIGHT) {
|
||||
++current;
|
||||
}
|
||||
}
|
||||
if (event.type == SDL_MOUSEBUTTONDOWN) {
|
||||
if (event.button.x < (original->w/2)) {
|
||||
--current;
|
||||
} else {
|
||||
++current;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Handle wrapping */
|
||||
if (current < 0) {
|
||||
current += SDL_arraysize(output);
|
||||
}
|
||||
if (current >= SDL_arraysize(output)) {
|
||||
current -= SDL_arraysize(output);
|
||||
}
|
||||
|
||||
SDL_RenderClear(renderer);
|
||||
SDL_RenderCopy(renderer, output[current], NULL, NULL);
|
||||
SDL_SetRenderDrawColor(renderer, 0xFF, 0xFF, 0xFF, 0xFF);
|
||||
if (current == 0) {
|
||||
SDLTest_DrawString(renderer, 4, 4, titles[current]);
|
||||
} else {
|
||||
SDL_snprintf(title, sizeof(title), "%s %s %s", titles[current], yuv_name, yuv_mode);
|
||||
SDLTest_DrawString(renderer, 4, 4, title);
|
||||
}
|
||||
SDL_RenderPresent(renderer);
|
||||
SDL_Delay(10);
|
||||
}
|
||||
}
|
||||
SDL_Quit();
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
300
Engine/lib/sdl/test/testyuv_cvt.c
Normal file
300
Engine/lib/sdl/test/testyuv_cvt.c
Normal file
|
|
@ -0,0 +1,300 @@
|
|||
/*
|
||||
Copyright (C) 1997-2018 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.
|
||||
*/
|
||||
|
||||
#include "SDL.h"
|
||||
|
||||
#include "testyuv_cvt.h"
|
||||
|
||||
|
||||
static float clip3(float x, float y, float z)
|
||||
{
|
||||
return ((z < x) ? x : ((z > y) ? y : z));
|
||||
}
|
||||
|
||||
static void RGBtoYUV(Uint8 * rgb, int *yuv, SDL_YUV_CONVERSION_MODE mode, int monochrome, int luminance)
|
||||
{
|
||||
if (mode == SDL_YUV_CONVERSION_JPEG) {
|
||||
/* Full range YUV */
|
||||
yuv[0] = (int)(0.299 * rgb[0] + 0.587 * rgb[1] + 0.114 * rgb[2]);
|
||||
yuv[1] = (int)((rgb[2] - yuv[0]) * 0.565 + 128);
|
||||
yuv[2] = (int)((rgb[0] - yuv[0]) * 0.713 + 128);
|
||||
} else {
|
||||
// This formula is from Microsoft's documentation:
|
||||
// https://msdn.microsoft.com/en-us/library/windows/desktop/dd206750(v=vs.85).aspx
|
||||
// L = Kr * R + Kb * B + (1 - Kr - Kb) * G
|
||||
// Y = floor(2^(M-8) * (219*(L-Z)/S + 16) + 0.5);
|
||||
// U = clip3(0, (2^M)-1, floor(2^(M-8) * (112*(B-L) / ((1-Kb)*S) + 128) + 0.5));
|
||||
// V = clip3(0, (2^M)-1, floor(2^(M-8) * (112*(R-L) / ((1-Kr)*S) + 128) + 0.5));
|
||||
float S, Z, R, G, B, L, Kr, Kb, Y, U, V;
|
||||
|
||||
if (mode == SDL_YUV_CONVERSION_BT709) {
|
||||
/* BT.709 */
|
||||
Kr = 0.2126f;
|
||||
Kb = 0.0722f;
|
||||
} else {
|
||||
/* BT.601 */
|
||||
Kr = 0.299f;
|
||||
Kb = 0.114f;
|
||||
}
|
||||
|
||||
S = 255.0f;
|
||||
Z = 0.0f;
|
||||
R = rgb[0];
|
||||
G = rgb[1];
|
||||
B = rgb[2];
|
||||
L = Kr * R + Kb * B + (1 - Kr - Kb) * G;
|
||||
Y = (Uint8)SDL_floorf((219*(L-Z)/S + 16) + 0.5f);
|
||||
U = (Uint8)clip3(0, 255, SDL_floorf((112.0f*(B-L) / ((1.0f-Kb)*S) + 128) + 0.5f));
|
||||
V = (Uint8)clip3(0, 255, SDL_floorf((112.0f*(R-L) / ((1.0f-Kr)*S) + 128) + 0.5f));
|
||||
|
||||
yuv[0] = (Uint8)Y;
|
||||
yuv[1] = (Uint8)U;
|
||||
yuv[2] = (Uint8)V;
|
||||
}
|
||||
|
||||
if (monochrome) {
|
||||
yuv[1] = 128;
|
||||
yuv[2] = 128;
|
||||
}
|
||||
|
||||
if (luminance != 100) {
|
||||
yuv[0] = yuv[0] * luminance / 100;
|
||||
if (yuv[0] > 255)
|
||||
yuv[0] = 255;
|
||||
}
|
||||
}
|
||||
|
||||
static void ConvertRGBtoPlanar2x2(Uint32 format, Uint8 *src, int pitch, Uint8 *out, int w, int h, SDL_YUV_CONVERSION_MODE mode, int monochrome, int luminance)
|
||||
{
|
||||
int x, y;
|
||||
int yuv[4][3];
|
||||
Uint8 *Y1, *Y2, *U, *V;
|
||||
Uint8 *rgb1, *rgb2;
|
||||
int rgb_row_advance = (pitch - w*3) + pitch;
|
||||
int UV_advance;
|
||||
|
||||
rgb1 = src;
|
||||
rgb2 = src + pitch;
|
||||
|
||||
Y1 = out;
|
||||
Y2 = Y1 + w;
|
||||
switch (format) {
|
||||
case SDL_PIXELFORMAT_YV12:
|
||||
V = (Y1 + h * w);
|
||||
U = V + ((h + 1)/2)*((w + 1)/2);
|
||||
UV_advance = 1;
|
||||
break;
|
||||
case SDL_PIXELFORMAT_IYUV:
|
||||
U = (Y1 + h * w);
|
||||
V = U + ((h + 1)/2)*((w + 1)/2);
|
||||
UV_advance = 1;
|
||||
break;
|
||||
case SDL_PIXELFORMAT_NV12:
|
||||
U = (Y1 + h * w);
|
||||
V = U + 1;
|
||||
UV_advance = 2;
|
||||
break;
|
||||
case SDL_PIXELFORMAT_NV21:
|
||||
V = (Y1 + h * w);
|
||||
U = V + 1;
|
||||
UV_advance = 2;
|
||||
break;
|
||||
default:
|
||||
SDL_assert(!"Unsupported planar YUV format");
|
||||
return;
|
||||
}
|
||||
|
||||
for (y = 0; y < (h - 1); y += 2) {
|
||||
for (x = 0; x < (w - 1); x += 2) {
|
||||
RGBtoYUV(rgb1, yuv[0], mode, monochrome, luminance);
|
||||
rgb1 += 3;
|
||||
*Y1++ = (Uint8)yuv[0][0];
|
||||
|
||||
RGBtoYUV(rgb1, yuv[1], mode, monochrome, luminance);
|
||||
rgb1 += 3;
|
||||
*Y1++ = (Uint8)yuv[1][0];
|
||||
|
||||
RGBtoYUV(rgb2, yuv[2], mode, monochrome, luminance);
|
||||
rgb2 += 3;
|
||||
*Y2++ = (Uint8)yuv[2][0];
|
||||
|
||||
RGBtoYUV(rgb2, yuv[3], mode, monochrome, luminance);
|
||||
rgb2 += 3;
|
||||
*Y2++ = (Uint8)yuv[3][0];
|
||||
|
||||
*U = (Uint8)SDL_floorf((yuv[0][1] + yuv[1][1] + yuv[2][1] + yuv[3][1])/4.0f + 0.5f);
|
||||
U += UV_advance;
|
||||
|
||||
*V = (Uint8)SDL_floorf((yuv[0][2] + yuv[1][2] + yuv[2][2] + yuv[3][2])/4.0f + 0.5f);
|
||||
V += UV_advance;
|
||||
}
|
||||
/* Last column */
|
||||
if (x == (w - 1)) {
|
||||
RGBtoYUV(rgb1, yuv[0], mode, monochrome, luminance);
|
||||
rgb1 += 3;
|
||||
*Y1++ = (Uint8)yuv[0][0];
|
||||
|
||||
RGBtoYUV(rgb2, yuv[2], mode, monochrome, luminance);
|
||||
rgb2 += 3;
|
||||
*Y2++ = (Uint8)yuv[2][0];
|
||||
|
||||
*U = (Uint8)SDL_floorf((yuv[0][1] + yuv[2][1])/2.0f + 0.5f);
|
||||
U += UV_advance;
|
||||
|
||||
*V = (Uint8)SDL_floorf((yuv[0][2] + yuv[2][2])/2.0f + 0.5f);
|
||||
V += UV_advance;
|
||||
}
|
||||
Y1 += w;
|
||||
Y2 += w;
|
||||
rgb1 += rgb_row_advance;
|
||||
rgb2 += rgb_row_advance;
|
||||
}
|
||||
/* Last row */
|
||||
if (y == (h - 1)) {
|
||||
for (x = 0; x < (w - 1); x += 2) {
|
||||
RGBtoYUV(rgb1, yuv[0], mode, monochrome, luminance);
|
||||
rgb1 += 3;
|
||||
*Y1++ = (Uint8)yuv[0][0];
|
||||
|
||||
RGBtoYUV(rgb1, yuv[1], mode, monochrome, luminance);
|
||||
rgb1 += 3;
|
||||
*Y1++ = (Uint8)yuv[1][0];
|
||||
|
||||
*U = (Uint8)SDL_floorf((yuv[0][1] + yuv[1][1])/2.0f + 0.5f);
|
||||
U += UV_advance;
|
||||
|
||||
*V = (Uint8)SDL_floorf((yuv[0][2] + yuv[1][2])/2.0f + 0.5f);
|
||||
V += UV_advance;
|
||||
}
|
||||
/* Last column */
|
||||
if (x == (w - 1)) {
|
||||
RGBtoYUV(rgb1, yuv[0], mode, monochrome, luminance);
|
||||
*Y1++ = (Uint8)yuv[0][0];
|
||||
|
||||
*U = (Uint8)yuv[0][1];
|
||||
U += UV_advance;
|
||||
|
||||
*V = (Uint8)yuv[0][2];
|
||||
V += UV_advance;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void ConvertRGBtoPacked4(Uint32 format, Uint8 *src, int pitch, Uint8 *out, int w, int h, SDL_YUV_CONVERSION_MODE mode, int monochrome, int luminance)
|
||||
{
|
||||
int x, y;
|
||||
int yuv[2][3];
|
||||
Uint8 *Y1, *Y2, *U, *V;
|
||||
Uint8 *rgb;
|
||||
int rgb_row_advance = (pitch - w*3);
|
||||
|
||||
rgb = src;
|
||||
|
||||
switch (format) {
|
||||
case SDL_PIXELFORMAT_YUY2:
|
||||
Y1 = out;
|
||||
U = out+1;
|
||||
Y2 = out+2;
|
||||
V = out+3;
|
||||
break;
|
||||
case SDL_PIXELFORMAT_UYVY:
|
||||
U = out;
|
||||
Y1 = out+1;
|
||||
V = out+2;
|
||||
Y2 = out+3;
|
||||
break;
|
||||
case SDL_PIXELFORMAT_YVYU:
|
||||
Y1 = out;
|
||||
V = out+1;
|
||||
Y2 = out+2;
|
||||
U = out+3;
|
||||
break;
|
||||
default:
|
||||
SDL_assert(!"Unsupported packed YUV format");
|
||||
return;
|
||||
}
|
||||
|
||||
for (y = 0; y < h; ++y) {
|
||||
for (x = 0; x < (w - 1); x += 2) {
|
||||
RGBtoYUV(rgb, yuv[0], mode, monochrome, luminance);
|
||||
rgb += 3;
|
||||
*Y1 = (Uint8)yuv[0][0];
|
||||
Y1 += 4;
|
||||
|
||||
RGBtoYUV(rgb, yuv[1], mode, monochrome, luminance);
|
||||
rgb += 3;
|
||||
*Y2 = (Uint8)yuv[1][0];
|
||||
Y2 += 4;
|
||||
|
||||
*U = (Uint8)SDL_floorf((yuv[0][1] + yuv[1][1])/2.0f + 0.5f);
|
||||
U += 4;
|
||||
|
||||
*V = (Uint8)SDL_floorf((yuv[0][2] + yuv[1][2])/2.0f + 0.5f);
|
||||
V += 4;
|
||||
}
|
||||
/* Last column */
|
||||
if (x == (w - 1)) {
|
||||
RGBtoYUV(rgb, yuv[0], mode, monochrome, luminance);
|
||||
rgb += 3;
|
||||
*Y2 = *Y1 = (Uint8)yuv[0][0];
|
||||
Y1 += 4;
|
||||
Y2 += 4;
|
||||
|
||||
*U = (Uint8)yuv[0][1];
|
||||
U += 4;
|
||||
|
||||
*V = (Uint8)yuv[0][2];
|
||||
V += 4;
|
||||
}
|
||||
rgb += rgb_row_advance;
|
||||
}
|
||||
}
|
||||
|
||||
SDL_bool ConvertRGBtoYUV(Uint32 format, Uint8 *src, int pitch, Uint8 *out, int w, int h, SDL_YUV_CONVERSION_MODE mode, int monochrome, int luminance)
|
||||
{
|
||||
switch (format)
|
||||
{
|
||||
case SDL_PIXELFORMAT_YV12:
|
||||
case SDL_PIXELFORMAT_IYUV:
|
||||
case SDL_PIXELFORMAT_NV12:
|
||||
case SDL_PIXELFORMAT_NV21:
|
||||
ConvertRGBtoPlanar2x2(format, src, pitch, out, w, h, mode, monochrome, luminance);
|
||||
return SDL_TRUE;
|
||||
case SDL_PIXELFORMAT_YUY2:
|
||||
case SDL_PIXELFORMAT_UYVY:
|
||||
case SDL_PIXELFORMAT_YVYU:
|
||||
ConvertRGBtoPacked4(format, src, pitch, out, w, h, mode, monochrome, luminance);
|
||||
return SDL_TRUE;
|
||||
default:
|
||||
return SDL_FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
int CalculateYUVPitch(Uint32 format, int width)
|
||||
{
|
||||
switch (format)
|
||||
{
|
||||
case SDL_PIXELFORMAT_YV12:
|
||||
case SDL_PIXELFORMAT_IYUV:
|
||||
case SDL_PIXELFORMAT_NV12:
|
||||
case SDL_PIXELFORMAT_NV21:
|
||||
return width;
|
||||
case SDL_PIXELFORMAT_YUY2:
|
||||
case SDL_PIXELFORMAT_UYVY:
|
||||
case SDL_PIXELFORMAT_YVYU:
|
||||
return 4*((width + 1)/2);
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
16
Engine/lib/sdl/test/testyuv_cvt.h
Normal file
16
Engine/lib/sdl/test/testyuv_cvt.h
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
/*
|
||||
Copyright (C) 1997-2018 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.
|
||||
*/
|
||||
|
||||
/* These functions are designed for testing correctness, not for speed */
|
||||
|
||||
extern SDL_bool ConvertRGBtoYUV(Uint32 format, Uint8 *src, int pitch, Uint8 *out, int w, int h, SDL_YUV_CONVERSION_MODE mode, int monochrome, int luminance);
|
||||
extern int CalculateYUVPitch(Uint32 format, int width);
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2018 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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue