diff options
289 files changed, 10095 insertions, 10183 deletions
@@ -53,9 +53,11 @@ test/checkkeys test/loopwave test/testatomic test/testaudioinfo +test/testautomation test/testdraw2 test/testerror test/testfile +test/testgamecontroller test/testgesture test/testgl2 test/testgles @@ -19,9 +19,6 @@ Thanks to everyone who made this possible, including: * Holmes Futrell for port of SDL to the iPhone and iPod Touch during the Google Summer of Code 2008 -* Darren Alton for port of SDL to the Nintendo DS during the Google Summer - of Code 2008 - * Szymon "Wilku" Wilczek for adding support for multiple mice and tablets during the Google Summer of Code 2008 diff --git a/Makefile.ds b/Makefile.ds deleted file mode 100644 index 9a79f6f1b2..0000000000 --- a/Makefile.ds +++ /dev/null @@ -1,231 +0,0 @@ -#--------------------------------------------------------------------------------- -.SUFFIXES: -#--------------------------------------------------------------------------------- - -ifeq ($(strip $(DEVKITARM)),) -$(error "Please set DEVKITARM in your environment. export DEVKITARM=<path to>devkitARM") -endif - -include $(DEVKITARM)/ds_rules - -#--------------------------------------------------------------------------------- -# TARGET is the name of the output -# BUILD is the directory where object files & intermediate files will be placed -# SOURCES is a list of directories containing source code -# DATA is a list of directories containing data files -# INCLUDES is a list of directories containing header files -#--------------------------------------------------------------------------------- -TARGET := $(shell basename $(CURDIR)) -BUILD := src -SOURCES := src -DATA := data -INCLUDES := include - -#--------------------------------------------------------------------------------- -# options for code generation -#--------------------------------------------------------------------------------- -ARCH := -mthumb -mthumb-interwork \ - -D__NDS__ -DENABLE_NDS -DNO_SIGNAL_H -DDISABLE_THREADS -DPACKAGE=\"SDL\" \ - -DVERSION=\"2.0\" -DHAVE_ALLOCA_H=1 -DHAVE_ALLOCA=1 - -CFLAGS := -g -Wall -Os\ - -march=armv5te -mtune=arm946e-s \ - -fomit-frame-pointer -ffast-math \ - $(ARCH) - -CFLAGS += $(INCLUDE) -DARM9 -CXXFLAGS := $(CFLAGS) -fno-rtti -fno-exceptions - -ASFLAGS := -g $(ARCH) -march=armv5te -mtune=arm946e-s -LDFLAGS = -specs=ds_arm9.specs -g $(ARCH) -Wl,-Map,$(notdir $*.map) - -# Set to 0 to use a framer buffer, or 1 to use the GL like hardware -# renderer. Alas, both cannot be used at the same time for lack of -# display/texture memory. -USE_HW_RENDERER := 1 - -ifeq ($(USE_HW_RENDERER),1) -CFLAGS += -DUSE_HW_RENDERER -else -endif - -#--------------------------------------------------------------------------------- -# list of directories containing libraries, this must be the top level containing -# include and lib -#--------------------------------------------------------------------------------- -LIBDIRS := $(LIBNDS) $(PORTLIBS) - -#--------------------------------------------------------------------------------- -# no real need to edit anything past this point unless you need to add additional -# rules for different file extensions -#--------------------------------------------------------------------------------- -ifneq ($(BUILD),$(notdir $(CURDIR))) -#--------------------------------------------------------------------------------- - -export OUTPUT := $(CURDIR)/lib/lib$(TARGET).a - -export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \ - $(foreach dir,$(DATA),$(CURDIR)/$(dir)) - -export DEPSDIR := $(CURDIR)/$(BUILD) - -CFILES := \ - SDL.c \ - SDL_assert.c \ - SDL_error.c \ - SDL_fatal.c \ - SDL_hints.c \ - SDL_log.c \ - atomic/SDL_atomic.c \ - atomic/SDL_spinlock.arm.c \ - audio/SDL_audio.c \ - audio/SDL_audiocvt.c \ - audio/SDL_audiodev.c \ - audio/SDL_audiotypecvt.c \ - audio/SDL_mixer.c \ - audio/SDL_wave.c \ - audio/nds/SDL_ndsaudio.c \ - cpuinfo/SDL_cpuinfo.c \ - events/SDL_events.c \ - events/SDL_keyboard.c \ - events/SDL_mouse.c \ - events/SDL_quit.c \ - events/SDL_touch.c \ - events/SDL_windowevents.c \ - events/nds/SDL_ndsgesture.c \ - file/SDL_rwops.c \ - haptic/SDL_haptic.c \ - haptic/nds/SDL_syshaptic.c \ - joystick/SDL_joystick.c \ - joystick/nds/SDL_sysjoystick.c \ - power/SDL_power.c \ - power/nds/SDL_syspower.c \ - render/SDL_render.c \ - render/SDL_yuv_sw.c \ - render/nds/SDL_ndsrender.c \ - render/nds/SDL_libgl2D.c \ - render/software/SDL_blendfillrect.c \ - render/software/SDL_blendline.c \ - render/software/SDL_blendpoint.c \ - render/software/SDL_drawline.c \ - render/software/SDL_drawpoint.c \ - render/software/SDL_render_sw.c \ - stdlib/SDL_getenv.c \ - stdlib/SDL_iconv.c \ - stdlib/SDL_malloc.c \ - stdlib/SDL_qsort.c \ - stdlib/SDL_stdlib.c \ - stdlib/SDL_string.c \ - thread/SDL_thread.c \ - thread/nds/SDL_syscond.c \ - thread/nds/SDL_sysmutex.c \ - thread/nds/SDL_syssem.c \ - thread/nds/SDL_systhread.c \ - timer/SDL_timer.c \ - timer/nds/SDL_systimer.c \ - video/SDL_RLEaccel.c \ - video/SDL_blit.c \ - video/SDL_blit_0.c \ - video/SDL_blit_1.c \ - video/SDL_blit_A.c \ - video/SDL_blit_N.c \ - video/SDL_blit_auto.c \ - video/SDL_blit_copy.c \ - video/SDL_blit_slow.c \ - video/SDL_bmp.c \ - video/SDL_clipboard.c \ - video/SDL_fillrect.c \ - video/SDL_pixels.c \ - video/SDL_rect.c \ - video/SDL_stretch.c \ - video/SDL_surface.c \ - video/SDL_video.c \ - video/nds/SDL_ndsevents.c \ - video/nds/SDL_ndsvideo.c \ - video/nds/SDL_ndswindow.c - - -#CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp))) -#SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s))) -#BINFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*))) - -#--------------------------------------------------------------------------------- -# use CXX for linking C++ projects, CC for standard C -#--------------------------------------------------------------------------------- -ifeq ($(strip $(CPPFILES)),) -#--------------------------------------------------------------------------------- - export LD := $(CC) -#--------------------------------------------------------------------------------- -else -#--------------------------------------------------------------------------------- - export LD := $(CXX) -#--------------------------------------------------------------------------------- -endif -#--------------------------------------------------------------------------------- - -export OFILES := $(addsuffix .o,$(BINFILES)) \ - $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(SFILES:.s=.o) - -export INCLUDE := $(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \ - $(foreach dir,$(LIBDIRS),-I$(dir)/include) \ - -I$(CURDIR)/$(BUILD) \ - -I$(PORTLIBS)/include/SDL - -.PHONY: $(BUILD) clean all - -#--------------------------------------------------------------------------------- -all: arm_only $(BUILD) install nds_test - -lib: - @[ -d $@ ] || mkdir -p $@ - -$(BUILD): lib - @[ -d $@ ] || mkdir -p $@ - @$(MAKE) --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile.ds -s - -install: $(BUILD) - @mkdir -p $(PORTLIBS)/include/SDL/ - @rsync -a $(OUTPUT) $(PORTLIBS)/lib/ - @rsync -a include/*.h $(PORTLIBS)/include/SDL/ - -nds_test: - $(MAKE) -C test/nds-test-progs -s - -tags: - cd $(SOURCES); etags $(CFILES) - -# This file must be compiled with the ARM instruction set, not -# thumb. Use devkitpro way of doing things. -arm_only: src/atomic/SDL_spinlock.arm.c -src/atomic/SDL_spinlock.arm.c: src/atomic/SDL_spinlock.c - @cp $< $@ - -#--------------------------------------------------------------------------------- -clean: - @echo clean ... - @cd src; rm -fr $(OFILES) $(OFILES:.o=.d) lib - @rm -f $(OUTPUT) - @make -C test/nds-test-progs -s clean - -#--------------------------------------------------------------------------------- -else - -DEPENDS := $(OFILES:.o=.d) - -#--------------------------------------------------------------------------------- -# main targets -#--------------------------------------------------------------------------------- -$(OUTPUT) : $(OFILES) - -#--------------------------------------------------------------------------------- -%.bin.o : %.bin -#--------------------------------------------------------------------------------- - @echo $(notdir $<) - @$(bin2o) - - --include $(DEPENDS) - -#--------------------------------------------------------------------------------------- -endif -#--------------------------------------------------------------------------------------- diff --git a/Makefile.psp b/Makefile.psp new file mode 100644 index 0000000000..ec137806d9 --- /dev/null +++ b/Makefile.psp @@ -0,0 +1,92 @@ +TARGET_LIB = libSDL2.a +OBJS= src/SDL.o \ + src/SDL_assert.o \ + src/SDL_error.o \ + src/SDL_fatal.o \ + src/SDL_hints.o \ + src/SDL_log.o \ + src/atomic/SDL_atomic.o \ + src/atomic/SDL_spinlock.o \ + src/audio/SDL_audio.o \ + src/audio/SDL_audiocvt.o \ + src/audio/SDL_audiodev.o \ + src/audio/SDL_audiotypecvt.o \ + src/audio/SDL_mixer.o \ + src/audio/SDL_wave.o \ + src/audio/psp/SDL_pspaudio.o \ + src/cpuinfo/SDL_cpuinfo.o \ + src/events/SDL_clipboardevents.o \ + src/events/SDL_dropevents.o \ + src/events/SDL_events.o \ + src/events/SDL_gesture.o \ + src/events/SDL_keyboard.o \ + src/events/SDL_mouse.o \ + src/events/SDL_quit.o \ + src/events/SDL_touch.o \ + src/events/SDL_windowevents.o \ + src/file/SDL_rwops.o \ + src/haptic/SDL_haptic.o \ + src/haptic/dummy/SDL_syshaptic.o \ + src/joystick/SDL_joystick.o \ + src/joystick/SDL_gamecontroller.o \ + src/joystick/psp/SDL_sysjoystick.o \ + src/power/SDL_power.o \ + src/power/psp/SDL_syspower.o \ + src/render/SDL_render.o \ + src/render/SDL_yuv_sw.o \ + src/render/psp/SDL_render_psp.o \ + src/render/software/SDL_blendfillrect.o \ + src/render/software/SDL_blendline.o \ + src/render/software/SDL_blendpoint.o \ + src/render/software/SDL_drawline.o \ + src/render/software/SDL_drawpoint.o \ + src/render/software/SDL_render_sw.o \ + src/render/software/SDL_rotate.o \ + src/stdlib/SDL_getenv.o \ + src/stdlib/SDL_iconv.o \ + src/stdlib/SDL_malloc.o \ + src/stdlib/SDL_qsort.o \ + src/stdlib/SDL_stdlib.o \ + src/stdlib/SDL_string.o \ + src/thread/SDL_thread.o \ + src/thread/psp/SDL_syssem.o \ + src/thread/psp/SDL_systhread.o \ + src/thread/psp/SDL_sysmutex.o \ + src/thread/psp/SDL_syscond.o \ + src/timer/SDL_timer.o \ + src/timer/psp/SDL_systimer.o \ + src/video/SDL_RLEaccel.o \ + src/video/SDL_blit.o \ + src/video/SDL_blit_0.o \ + src/video/SDL_blit_1.o \ + src/video/SDL_blit_A.o \ + src/video/SDL_blit_N.o \ + src/video/SDL_blit_auto.o \ + src/video/SDL_blit_copy.o \ + src/video/SDL_blit_slow.o \ + src/video/SDL_bmp.o \ + src/video/SDL_clipboard.o \ + src/video/SDL_fillrect.o \ + src/video/SDL_pixels.o \ + src/video/SDL_rect.o \ + src/video/SDL_stretch.o \ + src/video/SDL_surface.o \ + src/video/SDL_video.o \ + src/video/psp/SDL_pspevents.o \ + src/video/psp/SDL_pspvideo.o \ + src/video/psp/SDL_pspgl.o \ + src/video/psp/SDL_pspmouse.o \ + +INCDIR = ./include +CFLAGS = -g -O2 -G0 -Wall -D__PSP__ -DHAVE_OPENGL +CXXFLAGS = $(CFLAGS) -fno-exceptions -fno-rtti +ASFLAGS = $(CFLAGS) + +LIBDIR = +LIBS = -lGL -lGLU -lglut -lz \ + -lpspvfpu -lpsphprm -lpspsdk -lpspctrl -lpspumd -lpsprtc -lpsppower -lpspgum -lpspgu -lpspaudiolib -lpspaudio -lpsphttp -lpspssl -lpspwlan \ + -lpspnet_adhocmatching -lpspnet_adhoc -lpspnet_adhocctl -lm -lpspvram + +PSPSDK=$(shell psp-config --pspsdk-path) +include $(PSPSDK)/lib/build.mak + @@ -12,7 +12,7 @@ This is the Simple DirectMedia Layer, a general API that provides low level access to audio, keyboard, mouse, joystick, 3D hardware via OpenGL, and 2D framebuffer across multiple platforms. -The current version supports Windows, Windows CE, Mac OS X, Linux, FreeBSD, +The current version supports Windows, Mac OS X, Linux, FreeBSD, NetBSD, OpenBSD, BSD/OS, Solaris, iOS, and Android. The code contains support for other operating systems but those are not officially supported. diff --git a/README-SDL.txt b/README-SDL.txt index 1a9feff5c4..fade0b9583 100644 --- a/README-SDL.txt +++ b/README-SDL.txt @@ -1,7 +1,7 @@ Please distribute this file with the SDL runtime environment: -The Simple DirectMedia Layer (SDL for short) is a cross-platfrom library +The Simple DirectMedia Layer (SDL for short) is a cross-platform library designed to make it easy to write multi-media software, such as games and emulators. diff --git a/README.DirectFB b/README.DirectFB index 68988136b0..9c16a7b67e 100644 --- a/README.DirectFB +++ b/README.DirectFB @@ -53,7 +53,7 @@ Simple Window Manager ===================== The driver has support for a very, very basic window manager you may -want to use when runnning with "wm=default". Use +want to use when running with "wm=default". Use export SDL_DIRECTFB_WM=1 @@ -62,10 +62,10 @@ you need to have the following font installed: /usr/share/fonts/truetype/freefont/FreeSans.ttf -OPENGL Support +OpenGL Support ============== -The following instructions will give you *software* opengl. However this +The following instructions will give you *software* OpenGL. However this works at least on all directfb supported platforms. As of this writing 20100802 you need to pull Mesa from git and do the following: diff --git a/README.MacOSX b/README.MacOSX index 3bc421371f..572a86b190 100644 --- a/README.MacOSX +++ b/README.MacOSX @@ -56,7 +56,7 @@ usually is "TestGame". You might also want to use @PACKAGE@ to use the package name as specified in your configure.in file. If your project builds more than one application, you will have to do a bit -more. For each of your target applications, you need a seperate rule. +more. For each of your target applications, you need a separate rule. If you want the created bundles to be installed, you may want to add this rule to your Makefile.am: @@ -75,13 +75,13 @@ the make rule accordingly. But beware! That is only part of the story! With the above, you end up with a bare bone .app bundle, which is double clickable from the Finder. But -there are some more things you should do before shipping yor product... +there are some more things you should do before shipping your product... 1) The bundle right now probably is dynamically linked against SDL. That means that when you copy it to another computer, *it will not run*, unless you also install SDL on that other computer. A good solution for this dilemma is to static link against SDL. On OS X, you can - achieve that by linkinag against the libraries listed by + achieve that by linking against the libraries listed by sdl-config --static-libs instead of those listed by sdl-config --libs @@ -120,7 +120,7 @@ normally from the Finder. - Building the Framework The SDL Library is packaged as a framework bundle, an organized -relocatable folder heirarchy of executible code, interface headers, +relocatable folder hierarchy of executable code, interface headers, and additional resources. For practical purposes, you can think of a framework as a more user and system-friendly shared library, whose library file behaves more or less like a standard UNIX shared library. @@ -162,11 +162,11 @@ following locations: - Building from command line Use pbxbuild in the same directory as your .pbproj file - + - Running your app You can send command line args to your app by either invoking it from the command line (in *.app/Contents/MacOS) or by entering them in the - "Executibles" panel of the target settings. + "Executables" panel of the target settings. - Implementation Notes Some things that may be of interest about how it all works... @@ -181,6 +181,6 @@ following locations: You are free to modify your Cocoa app with generally no consequence to SDL. You cannot, however, easily change the SDL window itself. Functionality may be added in the future to help this. - + Known bugs are listed in the file "BUGS" diff --git a/README.Platforms b/README.Platforms index 32fb0d0835..1e0e7a6aaf 100644 --- a/README.Platforms +++ b/README.Platforms @@ -11,7 +11,7 @@ Windows 7 Mac OS X 10.4+ Linux 2.6+ iOS 3.1.3+ -Android 2.1+ +Android 2.3.3+ Unofficially supported platforms ================================ @@ -24,9 +24,9 @@ Solaris Platforms supported by volunteers ================================= +Haiku - maintained by Axel Dörfler <axeld@pinc-software.de> +PSP - maintained by 527721088@qq.com Pandora - maintained by Scott Smith <pickle136@sbcglobal.net> Platforms that need maintainers =============================== -Nintendo DS -Haiku diff --git a/README.Porting b/README.Porting index 9bb4613e01..f8540b600b 100644 --- a/README.Porting +++ b/README.Porting @@ -26,12 +26,15 @@ There are two basic ways of building SDL at the moment: Add the top level include directory to the header search path, and then add the following sources to the project: src/*.c + src/atomic/*.c src/audio/*.c - src/cdrom/*.c src/cpuinfo/*.c src/events/*.c src/file/*.c + src/haptic/*.c src/joystick/*.c + src/power/*.c + src/render/*.c src/stdlib/*.c src/thread/*.c src/timer/*.c @@ -39,8 +42,9 @@ There are two basic ways of building SDL at the moment: src/audio/disk/*.c src/audio/dummy/*.c src/video/dummy/*.c + src/haptic/dummy/*.c src/joystick/dummy/*.c - src/cdrom/dummy/*.c + src/main/dummy/*.c src/thread/generic/*.c src/timer/dummy/*.c src/loadso/dummy/*.c diff --git a/README.android b/README.android index 77b443bf46..efc3ab302e 100644 --- a/README.android +++ b/README.android @@ -4,12 +4,13 @@ Simple DirectMedia Layer for Android Requirements: -Android SDK +Android SDK (version 10 or later) http://developer.android.com/sdk/index.html -Android NDK r4 or later +Android NDK r7 or later http://developer.android.com/sdk/ndk/index.html +Minimum API level supported by SDL: 10 (Android 2.3.3) ================================================================================ How the port works @@ -18,7 +19,7 @@ http://developer.android.com/sdk/ndk/index.html - Android applications are Java-based, optionally with parts written in C - As SDL apps are C-based, we use a small Java shim that uses JNI to talk to the SDL library -- This means that your application C code must be placed inside an android +- This means that your application C code must be placed inside an Android Java project, along with some C support code that communicates with Java - This eventually produces a standard Android .apk package @@ -46,7 +47,8 @@ Instructions: If you want to use the Eclipse IDE, skip to the Eclipse section below. -5. Edit <project>/local.properties to point to the Android SDK directory +5. Create <project>/local.properties and use that to point to the Android SDK directory, by writing a line with the following form: +sdk.dir=PATH_TO_ANDROID_SDK 6. Run 'ant debug' in android/project. This compiles the .java and eventually creates a .apk with the native code embedded 7. 'ant debug install' will push the apk to the device or emulator (if connected) @@ -59,8 +61,8 @@ android-project/ build.properties - empty build.xml - build description file, used by ant. The actual application name is specified here. - default.properties - holds the target ABI for the application, can range between - android-5 and android-16 + default.properties - holds the target ABI for the application, android-10 and up + project.properties - holds the target ABI for the application, android-10 and up local.properties - holds the SDK path, you should change this to the path to your SDK jni/ - directory holding native code jni/Android.mk - Android makefile that can call recursively the Android.mk files @@ -171,10 +173,10 @@ manually or quit the app (which is actually the kind of behaviour you'll see under iOS, if the OS can not restore your GL context it will just kill your app) ================================================================================ - Threads and the JAVA VM + Threads and the Java VM ================================================================================ -For a quick tour on how Linux native threads interoperate with the JAVA VM, take +For a quick tour on how Linux native threads interoperate with the Java VM, take a look here: http://developer.android.com/guide/practices/jni.html If you want to use threads in your SDL app, it's strongly recommended that you do so by creating them using SDL functions. This way, the required attach/detach @@ -342,6 +344,38 @@ output file: When you're done instrumenting with valgrind, you can disable the wrapper: adb shell setprop wrap.org.libsdl.app "" +================================================================================ + Why is API level 10 the minimum required? +================================================================================ + +API level 10 is required because SDL requires some functionality for running not +available on older devices and some for building which is not in older NDK/SDKs. + +Support for native OpenGL ES and ES2 applications was introduced in the NDK for +API level 4 and 8. EGL was made a stable API in the NDK for API level 9, which +has since then been obsoleted, with the recommendation to developers to bump the +required API level to 10. +As of this writing, according to http://developer.android.com/about/dashboards/index.html +about 90% of the Android devices accessing Google Play support API level 10 or +higher (March 2013). + +================================================================================ + A note regarding the use of the "dirty rectangles" rendering technique +================================================================================ + +If your app uses a variation of the "dirty rectangles" rendering technique, +where you only update a portion of the screen on each frame, you may notice a +variety of visual glitches on Android, that are not present on other platforms. +This is caused by SDL's use of EGL as the support system to handle OpenGL ES/ES2 +contexts, in particular the use of the eglSwapBuffers function. As stated in the +documentation for the function "The contents of ancillary buffers are always +undefined after calling eglSwapBuffers". +Setting the EGL_SWAP_BEHAVIOR attribute of the surface to EGL_BUFFER_PRESERVED +is not possible for SDL as it requires EGL 1.4, available only on the API level +17+, so the only workaround available on this platform is to redraw the entire +screen each frame. + +Reference: http://www.khronos.org/registry/egl/specs/EGLTechNote0001.html ================================================================================ Known issues diff --git a/README.ds b/README.ds deleted file mode 100644 index 40bf8823e7..0000000000 --- a/README.ds +++ /dev/null @@ -1,64 +0,0 @@ -================================================================================ -Simple DirectMedia Layer for Nintendo DS -================================================================================ - --Requirements- -* The devkitpro SDK available at http://devkitpro.org. - Read the information at http://devkitpro.org/wiki/Getting_Started/devkitARM - The necessary packages are devkitARM, libnds, libfat and default arm7. -* Optionally, use a DS emulator, such as desmume (http://desmume.org/) - to program and debug. - --Building SDL- - -After setting the devkitpro environment, cd into your SDL directory and type: - make -f Makefile.ds - -This will compile and install the library and headers into the -devkitpro's portlibs directory (../portlibs/arm/lib/ and -../portlibs/arm/include/). Additionally it will compile several tests -that you can run either on the DS or with desmume. For instance: - desmume --cflash-path=test/ test/nds-test-progs/testsprite2/testsprite2.nds - desmume --cflash-path=test/ test/nds-test-progs/testspriteminimal/testspriteminimal.nds - desmume --cflash-path=test/ test/nds-test-progs/testscale/testscale.nds - desmume test/nds-test-progs/general/general.nds - --Notes- -* The renderer code is based on the gl like engine. It's not using the sprite engine. -* The hardware renderer is using the parts of the libgl2d abstraction library that can be found at: - http://rel.phatcode.net/junk.php?id=117 - Used with the author's permission. -* The port is very basic and incomplete: - - SDL currently has to be compiled for either framebuffer mode or renderer mode. - See USE_HW_RENDERER in Makefile.ds. - - some optional renderer functions are not implemented. - - no sound - --Limitations- -* in hardware renderer mode, don't load too many textures. The internal format is - 2 bytes per pixel. And there is only 256KB reserved for the textures. For instance, - testscale won't display sample.bmp, unless it's resized to a smaller picture. -* the screen size is 256 x 384. Anything else won't work. -* there is no 8 bits/pixel mode because SDL 2.0 doesn't support palettes. - --Joystick mapping- -The Joystick presented to SDL has 2 axes and 8 buttons - - KEY | Code - A | 0 - B | 1 - X | 2 - Y | 3 - L | 4 - R | 5 - select | 6 - start | 7 - - Left-right is axe 0. - Up-down is axe 1. - --Mouse mapping- -todo - --Examples- -Due to memory limitations, to be able to successfully run the testscale example, sample.bmp must be resized to 256x105. diff --git a/README.gesture b/README.gesture index 187a598b1a..d52c4c5a29 100644 --- a/README.gesture +++ b/README.gesture @@ -16,7 +16,7 @@ Recording terminates as soon as a finger comes up. Recording is acknowledged by A SDL_DOLLARRECORD event is a dgesture with the following fields: event.dgesture.touchId - the Id of the touch used to record the gesture. -event.dgesture.gestureId - the unique id of the recoreded gesture. +event.dgesture.gestureId - the unique id of the recorded gesture. Performing: @@ -28,7 +28,7 @@ event.dgesture.gestureId - the unique id of the closest gesture to the performe event.dgesture.error - the difference between the gesture template and the actual performed gesture. Lower error is a better match. event.dgesture.numFingers - the number of fingers used to draw the stroke. -Most programs will want to define an appropriate error threshold and check to be sure taht the error of a gesture is not abnormally high (an indicator that no gesture was performed). +Most programs will want to define an appropriate error threshold and check to be sure that the error of a gesture is not abnormally high (an indicator that no gesture was performed). @@ -38,14 +38,14 @@ To save a template, call SDL_SaveDollarTemplate(gestureId, src) where gestureId To save all currently loaded templates, call SDL_SaveAllDollarTemplates(src) where source is an SDL_RWops pointer to the file where the gesture will be stored. -Both functions return the number of gestures sucessfully saved. +Both functions return the number of gestures successfully saved. Loading: -------- To load templates from a file, call SDL_LoadDollarTemplates(touchId,src) where touchId is the id of the touch to load to (or -1 to load to all touch devices), and src is an SDL_RWops pointer to a gesture save file. -SDL_LoadDollarTemplates returns the number of templates sucessfully loaded. +SDL_LoadDollarTemplates returns the number of templates successfully loaded. @@ -56,8 +56,8 @@ SDL provides simple support for pinch/rotate/swipe gestures. Every time a finger is moved an SDL_MULTIGESTURE event is sent with the following fields: event.mgesture.touchId - the Id of the touch on which the gesture was performed. -event.mgesture.x - the normalized x cooridinate of the gesture. (0..1) -event.mgesture.y - the normalized y cooridinate of the gesture. (0..1) +event.mgesture.x - the normalized x coordinate of the gesture. (0..1) +event.mgesture.y - the normalized y coordinate of the gesture. (0..1) event.mgesture.dTheta - the amount that the fingers rotated during this motion. event.mgesture.dDist - the amount that the fingers pinched during this motion. event.mgesture.numFingers - the number of fingers used in the gesture. diff --git a/README.pandora b/README.pandora index d360f84f34..d522bc77aa 100644 --- a/README.pandora +++ b/README.pandora @@ -1,7 +1,7 @@ SDL 2.0 with open pandora console support ( http://openpandora.org/ ) ===================================================================== -- A pandora specific video driver was writed to allow SDL 2.0 with OpenGL ES +- A pandora specific video driver was written to allow SDL 2.0 with OpenGL ES support to work on the pandora under the framebuffer. This driver do not have input support for now, so if you use it you will have to add your own control code. The video driver name is "pandora" so if you have problem running it from diff --git a/README.psp b/README.psp new file mode 100644 index 0000000000..469febb9ad --- /dev/null +++ b/README.psp @@ -0,0 +1,17 @@ +SDL port for the Sony PSP contributed by + Captian Lex + +Credit to + Marcus R.Brown,Jim Paris,Matthew H for the original SDL 1.2 for PSP + Geecko for his PSP GU lib "Glib2d" + +Building +-------- +To build for the PSP, make sure psp-config is in the path and run: + make -f Makefile.psp + + + +To Do +------ +PSP Screen Keyboard
\ No newline at end of file diff --git a/README.touch b/README.touch index 68b97c1be2..9e688330ff 100644 --- a/README.touch +++ b/README.touch @@ -5,7 +5,7 @@ Linux: The linux touch system is currently based off event streams, and proc/bus/devices. The active user must be given permissions to read /dev/input/TOUCHDEVICE, where TOUCHDEVICE is the event stream for your device. Currently only Wacom tablets are supported. If you have an unsupported tablet contact me at jim.tla+sdl_touch@gmail.com and I will help you get support for it. Mac: -The Mac and Iphone API's are pretty. If your touch device supports them then you'll be fine. If it doesn't, then there isn't much we can do. +The Mac and iPhone APIs are pretty. If your touch device supports them then you'll be fine. If it doesn't, then there isn't much we can do. iPhone: Works out of box. @@ -21,18 +21,18 @@ Sent when a finger (or stylus) is placed on a touch device. Fields: event.tfinger.touchId - the Id of the touch device. event.tfinger.fingerId - the Id of the finger which just went down. -event.tfinger.x - the x coordinate of the touch (0..touch.xres) -event.tfinger.y - the y coordinate of the touch (0..touch.yres) -event.tfinger.pressure - the pressure of the touch (0..touch.pressureres) +event.tfinger.x - the x coordinate of the touch (0..1) +event.tfinger.y - the y coordinate of the touch (0..1) +event.tfinger.pressure - the pressure of the touch (0..1) SDL_FINGERMOTION: Sent when a finger (or stylus) is moved on the touch device. Fields: Same as FINGERDOWN but with additional: -event.tfginer.dx - change in x coordinate during this motion event. -event.tfginer.dy - change in y coordinate during this motion event. +event.tfinger.dx - change in x coordinate during this motion event. +event.tfinger.dy - change in y coordinate during this motion event. -SDL_FINGERMOTION: +SDL_FINGERUP: Sent when a finger (or stylus) is lifted from the touch device. Fields: Same as FINGERDOWN. @@ -41,56 +41,38 @@ Same as FINGERDOWN. =========================================================================== Functions =========================================================================== -SDL provides the ability to access the underlying Touch and Finger structures. +SDL provides the ability to access the underlying Finger structures. These structures should _never_ be modified. -The following functions are included from SDL_Touch.h - -To get a SDL_Touch device call SDL_GetTouch(touchId). -This returns an SDL_Touch*. -IMPORTANT: If the touch has been removed, or there is no touch with the given ID, SDL_GetTouch will return null. Be sure to check for this! - -An SDL_Touch has the following fields: ->xres,yres,pressures: - The resolution at which x,y, and pressure values are reported. Currently these will always be equal to 2^15, but this may not always be the case. - ->pressure_max, pressure_min, x_max, x_min, y_max, y_min - Which give, respectively, the maximum and minumum values that the touch digitizer can return for pressure, x coordiniate, and y coordinate AS REPORTED BY THE OPERATING SYSTEM. -On Mac/iPhone systems _max will always be 0, and _min will always be 1. - ->native_xres,native_yres,native_pressureres: - The native resolution of the touch device AS REPORTED BY THE OPERATING SYSTEM. -On Mac/iPhone systems these will always be 1. +The following functions are included from SDL_touch.h ->num_fingers: - The number of fingers currently down on the device. +To get a SDL_TouchID call SDL_GetTouchDevice(index). +This returns a SDL_TouchID. +IMPORTANT: If the touch has been removed, or there is no touch with the given ID, SDL_GetTouchID will return 0. Be sure to check for this! ->fingers: - An array of pointers to the fingers which are on the device. +The number of touch devices can be queried with SDL_GetNumTouchDevices(). +A SDL_Touch may be used to get pointers to SDL_Finger. -The most common reason to access a touch device is to normalize inputs. This would be accomplished by code like the following: +SDL_GetNumTouchFingers(touchID) may be used to get the number of fingers currently down on the device. - SDL_Touch* inTouch = SDL_GetTouch(event.tfinger.touchId); - if(inTouch == NULL) continue; //The touch has been removed +The most common reason to access SDL_Finger is to query the fingers outside the event. In most cases accessing the fingers is using the event. This would be accomplished by code like the following: - float x = ((float)event.tfinger.x)/inTouch->xres; - float y = ((float)event.tfinger.y)/inTouch->yres; + float x = event.tfinger.x; + float y = event.tfinger.y; -To get an SDL_Finger, call SDL_GetFinger(touch,fingerId), where touch is a pointer to an SDL_Touch device, and fingerId is the id of the requested finger. -This returns an SDL_Finger*, or null if the finger does not exist, or has been removed. -An SDL_Finger is guaranteed to be persistent for the duration of a touch, but it will be de-allocated as soon as the finger is removed. This occurs when the SDL_FINGERUP event is _added_ to the event queue, and thus _before_ the FINGERUP event is polled. -As a result, be very careful to check for null return values. +To get a SDL_Finger, call SDL_GetTouchFinger(touchID,index), where touchID is a SDL_TouchID, and index is the requested finger. +This returns a SDL_Finger*, or NULL if the finger does not exist, or has been removed. +A SDL_Finger is guaranteed to be persistent for the duration of a touch, but it will be de-allocated as soon as the finger is removed. This occurs when the SDL_FINGERUP event is _added_ to the event queue, and thus _before_ the FINGERUP event is polled. +As a result, be very careful to check for NULL return values. -An SDL_Finger has the following fields: +A SDL_Finger has the following fields: >x,y,pressure: The current coordinates of the touch. ->xdelta,ydelta: - The change in position resulting from the last finger motion. ->last_x, last_y, last_pressure: - The previous coordinates of the touch. +>pressure: + The pressure of the touch. =========================================================================== Notes @@ -99,3 +81,4 @@ For a complete example see test/testgesture.c Please direct questions/comments to: jim.tla+sdl_touch@gmail.com + (original author, API was changed since) diff --git a/VisualC/SDL/SDL_VS2008.vcproj b/VisualC/SDL/SDL_VS2008.vcproj index 5fca5ab1db..8a6c37a2cc 100644 --- a/VisualC/SDL/SDL_VS2008.vcproj +++ b/VisualC/SDL/SDL_VS2008.vcproj @@ -1,2644 +1,1332 @@ <?xml version="1.0" encoding="Windows-1252"?> - <VisualStudioProject - ProjectType="Visual C++" - Version="9.00" - Name="SDL2" - ProjectGUID="{81CE8DAF-EBB2-4761-8E45-B71ABCCA8C68}" - RootNamespace="SDL" - TargetFrameworkVersion="131072" - > - <Platforms> - <Platform - Name="Win32" - /> - <Platform - Name="x64" - /> - </Platforms> - <ToolFiles> - </ToolFiles> - <Configurations> - <Configuration - Name="Debug|Win32" - OutputDirectory=".\Debug" - IntermediateDirectory=".\Debug" - ConfigurationType="2" - InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC70.vsprops" - UseOfMFC="0" - ATLMinimizesCRunTimeLibraryUsage="false" - > - <Tool - Name="VCPreBuildEventTool" - CommandLine="" - /> - <Tool - Name="VCCustomBuildTool" - /> - <Tool - Name="VCXMLDataGeneratorTool" - /> - <Tool - Name="VCWebServiceProxyGeneratorTool" - /> - <Tool - Name="VCMIDLTool" - PreprocessorDefinitions="_DEBUG" - MkTypLibCompatible="true" - SuppressStartupBanner="true" - TargetEnvironment="1" - TypeLibraryName=".\Debug/SDL.tlb" - /> - <Tool - Name="VCCLCompilerTool" - Optimization="0" - AdditionalIncludeDirectories="..\..\include" - PreprocessorDefinitions="_DEBUG;_WINDOWS" - + ExceptionHandling="2" RuntimeLibrary="3" - BufferSecurityCheck="false" - WarningLevel="3" - SuppressStartupBanner="true" - Detect64BitPortabilityProblems="false" - DebugInformationFormat="4" - CompileAs="0" - /> - <Tool - Name="VCManagedResourceCompilerTool" - /> - <Tool - Name="VCResourceCompilerTool" - PreprocessorDefinitions="_DEBUG" - Culture="1033" - /> - <Tool - Name="VCPreLinkEventTool" - /> - <Tool - Name="VCLinkerTool" - AdditionalDependencies="winmm.lib imm32.lib version.lib" - IgnoreAllDefaultLibraries="true" - GenerateDebugInformation="true" - SubSystem="2" - /> - <Tool - Name="VCALinkTool" - /> - <Tool - Name="VCManifestTool" - /> - <Tool - Name="VCXDCMakeTool" - /> - <Tool - Name="VCBscMakeTool" - /> - <Tool - Name="VCFxCopTool" - /> - <Tool - Name="VCAppVerifierTool" - /> - <Tool - Name="VCPostBuildEventTool" - /> - </Configuration> - <Configuration - Name="Debug|x64" - OutputDirectory="$(PlatformName)\$(ConfigurationName)" - IntermediateDirectory="$(PlatformName)\$(ConfigurationName)" - ConfigurationType="2" - InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC70.vsprops" - UseOfMFC="0" - ATLMinimizesCRunTimeLibraryUsage="false" - > - <Tool - Name="VCPreBuildEventTool" - /> - <Tool - Name="VCCustomBuildTool" - /> - <Tool - Name="VCXMLDataGeneratorTool" - /> - <Tool - Name="VCWebServiceProxyGeneratorTool" - /> - <Tool - Name="VCMIDLTool" - PreprocessorDefinitions="_DEBUG" - MkTypLibCompatible="true" - SuppressStartupBanner="true" - TargetEnvironment="3" - TypeLibraryName=".\Debug/SDL.tlb" - /> - <Tool - Name="VCCLCompilerTool" - Optimization="0" - AdditionalIncludeDirectories="..\..\include" - PreprocessorDefinitions="_DEBUG;_WINDOWS" - + ExceptionHandling="2" RuntimeLibrary="2" - BufferSecurityCheck="false" - WarningLevel="3" - SuppressStartupBanner="true" - Detect64BitPortabilityProblems="false" - DebugInformationFormat="3" - CompileAs="0" - /> - <Tool - Name="VCManagedResourceCompilerTool" - /> - <Tool - Name="VCResourceCompilerTool" - PreprocessorDefinitions="_DEBUG" - Culture="1033" - /> - <Tool - Name="VCPreLinkEventTool" - /> - <Tool - Name="VCLinkerTool" - AdditionalDependencies="winmm.lib imm32.lib version.lib" - IgnoreAllDefaultLibraries="true" - GenerateDebugInformation="true" - SubSystem="2" - TargetMachine="17" - /> - <Tool - Name="VCALinkTool" - /> - <Tool - Name="VCManifestTool" - /> - <Tool - Name="VCXDCMakeTool" - /> - <Tool - Name="VCBscMakeTool" - /> - <Tool - Name="VCFxCopTool" - /> - <Tool - Name="VCAppVerifierTool" - /> - <Tool - Name="VCPostBuildEventTool" - /> - </Configuration> - <Configuration - Name="Release|Win32" - OutputDirectory=".\Release" - IntermediateDirectory=".\Release" - ConfigurationType="2" - InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC70.vsprops" - UseOfMFC="0" - ATLMinimizesCRunTimeLibraryUsage="false" - > - <Tool - Name="VCPreBuildEventTool" - CommandLine="" - /> - <Tool - Name="VCCustomBuildTool" - /> - <Tool - Name="VCXMLDataGeneratorTool" - /> - <Tool - Name="VCWebServiceProxyGeneratorTool" - /> - <Tool - Name="VCMIDLTool" - PreprocessorDefinitions="NDEBUG" - MkTypLibCompatible="true" - SuppressStartupBanner="true" - TargetEnvironment="1" - TypeLibraryName=".\Release/SDL.tlb" - /> - <Tool - Name="VCCLCompilerTool" - InlineFunctionExpansion="1" - EnableIntrinsicFunctions="false" - AdditionalIncludeDirectories="..\..\include" - PreprocessorDefinitions="NDEBUG;_WINDOWS" - StringPooling="true" - + ExceptionHandling="2" RuntimeLibrary="2" - BufferSecurityCheck="false" - EnableFunctionLevelLinking="true" - WarningLevel="3" - SuppressStartupBanner="true" - Detect64BitPortabilityProblems="false" - CompileAs="0" - /> - <Tool - Name="VCManagedResourceCompilerTool" - /> - <Tool - Name="VCResourceCompilerTool" - PreprocessorDefinitions="NDEBUG" - Culture="1033" - /> - <Tool - Name="VCPreLinkEventTool" - /> - <Tool - Name="VCLinkerTool" - AdditionalDependencies="winmm.lib imm32.lib version.lib" - IgnoreAllDefaultLibraries="true" - + GenerateDebugInformation="true" SubSystem="2" - + OptimizeReferences="2" + EnableCOMDATFolding="2" /> - <Tool - Name="VCALinkTool" - /> - <Tool - Name="VCManifestTool" - /> - <Tool - Name="VCXDCMakeTool" - /> - <Tool - Name="VCBscMakeTool" - /> - <Tool - Name="VCFxCopTool" - /> - <Tool - Name="VCAppVerifierTool" - /> - <Tool - Name="VCPostBuildEventTool" - /> - </Configuration> - <Configuration - Name="Release|x64" - OutputDirectory="$(PlatformName)\$(ConfigurationName)" - IntermediateDirectory="$(PlatformName)\$(ConfigurationName)" - ConfigurationType="2" - InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC70.vsprops" - UseOfMFC="0" - ATLMinimizesCRunTimeLibraryUsage="false" - > - <Tool - Name="VCPreBuildEventTool" - /> - <Tool - Name="VCCustomBuildTool" - /> - <Tool - Name="VCXMLDataGeneratorTool" - /> - <Tool - Name="VCWebServiceProxyGeneratorTool" - /> - <Tool - Name="VCMIDLTool" - PreprocessorDefinitions="NDEBUG" - MkTypLibCompatible="true" - SuppressStartupBanner="true" - TargetEnvironment="3" - TypeLibraryName=".\Release/SDL.tlb" - /> - <Tool - Name="VCCLCompilerTool" - InlineFunctionExpansion="1" - EnableIntrinsicFunctions="false" - AdditionalIncludeDirectories="..\..\include" - PreprocessorDefinitions="NDEBUG;_WINDOWS" - StringPooling="true" - + ExceptionHandling="2" RuntimeLibrary="2" - BufferSecurityCheck="false" - EnableFunctionLevelLinking="true" - WarningLevel="3" - SuppressStartupBanner="true" - Detect64BitPortabilityProblems="false" - CompileAs="0" - /> - <Tool - Name="VCManagedResourceCompilerTool" - /> - <Tool - Name="VCResourceCompilerTool" - PreprocessorDefinitions="NDEBUG" - Culture="1033" - /> - <Tool - Name="VCPreLinkEventTool" - /> - <Tool - Name="VCLinkerTool" - AdditionalDependencies="winmm.lib imm32.lib version.lib" - IgnoreAllDefaultLibraries="true" - + GenerateDebugInformation="true" SubSystem="2" - + OptimizeReferences="2" + EnableCOMDATFolding="2" TargetMachine="17" - /> - <Tool - Name="VCALinkTool" - /> - <Tool - Name="VCManifestTool" - /> - <Tool - Name="VCXDCMakeTool" - /> - <Tool - Name="VCBscMakeTool" - /> - <Tool - Name="VCFxCopTool" - /> - <Tool - Name="VCAppVerifierTool" - /> - <Tool - Name="VCPostBuildEventTool" - /> - </Configuration> - </Configurations> - <References> - </References> - <Files> - <Filter - Name="API Headers" - > - <File - RelativePath="..\..\include\SDL.h" - > - </File> - <File - RelativePath="..\..\include\SDL_assert.h" - > - </File> - <File - RelativePath="..\..\include\SDL_atomic.h" - > - </File> - <File - RelativePath="..\..\include\SDL_audio.h" - > - </File> - <File - RelativePath="..\..\include\SDL_bits.h" - > - </File> - <File - RelativePath="..\..\include\SDL_blendmode.h" - > - </File> - <File - RelativePath="..\..\include\SDL_clipboard.h" - > - </File> - <File - RelativePath="..\..\include\SDL_config.h" - > - </File> - <File - RelativePath="..\..\include\SDL_config_windows.h" - > - </File> - <File - RelativePath="..\..\include\SDL_copying.h" - > - </File> - <File - RelativePath="..\..\include\SDL_cpuinfo.h" - > - </File> - <File - RelativePath="..\..\include\SDL_endian.h" - > - </File> - <File - RelativePath="..\..\include\SDL_error.h" - > - </File> - <File - RelativePath="..\..\include\SDL_events.h" - > - </File> - <File - RelativePath="..\..\include\SDL_gamecontroller.h" - > - </File> - <File - RelativePath="..\..\include\SDL_gesture.h" - > - </File> - <File - RelativePath="..\..\include\SDL_haptic.h" - > - </File> - <File - RelativePath="..\..\include\SDL_hints.h" - > - </File> - <File - RelativePath="..\..\include\SDL_joystick.h" - > - </File> - <File - RelativePath="..\..\include\SDL_keyboard.h" - > - </File> - <File - RelativePath="..\..\include\SDL_keycode.h" - > - </File> - <File - RelativePath="..\..\include\SDL_loadso.h" - > - </File> - <File - RelativePath="..\..\include\SDL_log.h" - > - </File> - <File - RelativePath="..\..\include\SDL_main.h" - > - </File> - <File - RelativePath="..\..\include\SDL_messagebox.h" - > - </File> - <File - RelativePath="..\..\include\SDL_mouse.h" - > - </File> - <File - RelativePath="..\..\include\SDL_mutex.h" - > - </File> - <File - RelativePath="..\..\include\SDL_name.h" - > - </File> - <File - RelativePath="..\..\include\SDL_opengl.h" - > - </File> - <File - RelativePath="..\..\include\SDL_opengles.h" - > - </File> - <File - RelativePath="..\..\include\SDL_pixels.h" - > - </File> - <File - RelativePath="..\..\include\SDL_platform.h" - > - </File> - <File - RelativePath="..\..\include\SDL_power.h" - > - </File> - <File - RelativePath="..\..\include\SDL_quit.h" - > - </File> - <File - RelativePath="..\..\include\SDL_rect.h" - > - </File> - <File - RelativePath="..\..\include\SDL_render.h" - > - </File> - <File - RelativePath="..\..\include\SDL_revision.h" - > - </File> - <File - RelativePath="..\..\include\SDL_rwops.h" - > - </File> - <File - RelativePath="..\..\include\SDL_scancode.h" - > - </File> - <File - RelativePath="..\..\include\SDL_shape.h" - > - </File> - <File - RelativePath="..\..\include\SDL_stdinc.h" - > - </File> - <File - RelativePath="..\..\include\SDL_surface.h" - > - </File> - <File - RelativePath="..\..\include\SDL_system.h" - > - </File> - <File - RelativePath="..\..\include\SDL_syswm.h" - > - </File> - <File - RelativePath="..\..\include\SDL_thread.h" - > - </File> - <File - RelativePath="..\..\include\SDL_timer.h" - > - </File> - <File - RelativePath="..\..\include\SDL_touch.h" - > - </File> - <File - RelativePath="..\..\include\SDL_types.h" - > - </File> - <File - RelativePath="..\..\include\SDL_version.h" - > - </File> - <File - RelativePath="..\..\include\SDL_video.h" - > - </File> - </Filter> - <File - RelativePath="..\..\src\events\blank_cursor.h" - > - </File> - <File - RelativePath="..\..\src\events\default_cursor.h" - > - </File> - <File - RelativePath="..\..\src\audio\directsound\directx.h" - > - </File> - <File - RelativePath="..\..\src\libm\e_atan2.c" - > - </File> - <File - RelativePath="..\..\src\libm\e_log.c" - > - </File> - <File - RelativePath="..\..\src\libm\e_pow.c" - > - </File> - <File - RelativePath="..\..\src\libm\e_rem_pio2.c" - > - </File> - <File - RelativePath="..\..\src\libm\e_sqrt.c" - > - </File> - <File - RelativePath="..\..\src\libm\k_cos.c" - > - </File> - <File - RelativePath="..\..\src\libm\k_rem_pio2.c" - > - </File> - <File - RelativePath="..\..\src\libm\k_sin.c" - > - </File> - <File - RelativePath="..\..\src\libm\math.h" - > - </File> - <File - RelativePath="..\..\src\libm\math_private.h" - > - </File> - <File - RelativePath="..\..\src\render\mmx.h" - > - </File> - <File - RelativePath=".\resource.h" - > - </File> - <File - RelativePath="..\..\src\libm\s_atan.c" - > - </File> - <File - RelativePath="..\..\src\libm\s_copysign.c" - > - </File> - <File - RelativePath="..\..\src\libm\s_cos.c" - > - </File> - <File - RelativePath="..\..\src\libm\s_fabs.c" - > - </File> - <File - RelativePath="..\..\src\libm\s_floor.c" - > - </File> - <File - RelativePath="..\..\src\libm\s_scalbn.c" - > - </File> - <File - RelativePath="..\..\src\libm\s_sin.c" - > - </File> - <File - RelativePath="..\..\src\SDL.c" - > - </File> - <File - RelativePath="..\..\src\SDL_assert.c" - > - </File> - <File - RelativePath="..\..\src\atomic\SDL_atomic.c" - > - </File> - <File - RelativePath="..\..\src\audio\SDL_audio.c" - > - </File> - <File - RelativePath="..\..\src\audio\SDL_audio_c.h" - > - </File> - <File - RelativePath="..\..\src\audio\SDL_audiocvt.c" - > - </File> - <File - RelativePath="..\..\src\audio\SDL_audiodev.c" - > - </File> - <File - RelativePath="..\..\src\audio\SDL_audiodev_c.h" - > - </File> - <File - RelativePath="..\..\src\audio\SDL_audiomem.h" - > - </File> - <File - RelativePath="..\..\src\audio\SDL_audiotypecvt.c" - > - </File> - <File - RelativePath="..\..\src\render\software\SDL_blendfillrect.c" - > - </File> - <File - RelativePath="..\..\src\render\software\SDL_blendfillrect.h" - > - </File> - <File - RelativePath="..\..\src\render\software\SDL_blendline.c" - > - </File> - <File - RelativePath="..\..\src\render\software\SDL_blendline.h" - > - </File> - <File - RelativePath="..\..\src\render\software\SDL_blendpoint.c" - > - </File> - <File - RelativePath="..\..\src\render\software\SDL_blendpoint.h" - > - </File> - <File - RelativePath="..\..\src\video\SDL_blit.c" - > - </File> - <File - RelativePath="..\..\src\video\SDL_blit.h" - > - </File> - <File - RelativePath="..\..\src\video\SDL_blit_0.c" - > - </File> - <File - RelativePath="..\..\src\video\SDL_blit_1.c" - > - </File> - <File - RelativePath="..\..\src\video\SDL_blit_A.c" - > - </File> - <File - RelativePath="..\..\src\video\SDL_blit_auto.c" - > - </File> - <File - RelativePath="..\..\src\video\SDL_blit_auto.h" - > - </File> - <File - RelativePath="..\..\src\video\SDL_blit_copy.c" - > - </File> - <File - RelativePath="..\..\src\video\SDL_blit_copy.h" - > - </File> - <File - RelativePath="..\..\src\video\SDL_blit_N.c" - > - </File> - <File - RelativePath="..\..\src\video\SDL_blit_slow.c" - > - </File> - <File - RelativePath="..\..\src\video\SDL_blit_slow.h" - > - </File> - <File - RelativePath="..\..\src\video\SDL_bmp.c" - > - </File> - <File - RelativePath="..\..\src\video\SDL_clipboard.c" - > - </File> - <File - RelativePath="..\..\src\events\SDL_clipboardevents.c" - > - </File> - <File - RelativePath="..\..\src\events\SDL_clipboardevents_c.h" - > - </File> - <File - RelativePath="..\..\src\cpuinfo\SDL_cpuinfo.c" - > - </File> - <File - RelativePath="..\..\src\audio\directsound\SDL_directsound.c" - > - </File> - <File - RelativePath="..\..\src\audio\directsound\SDL_directsound.h" - > - </File> - <File - RelativePath="..\..\src\audio\disk\SDL_diskaudio.c" - > - </File> - <File - RelativePath="..\..\src\audio\disk\SDL_diskaudio.h" - > - </File> - <File - RelativePath="..\..\src\render\software\SDL_draw.h" - > - </File> - <File - RelativePath="..\..\src\render\software\SDL_drawline.c" - > - </File> - <File - RelativePath="..\..\src\render\software\SDL_drawline.h" - > - </File> - <File - RelativePath="..\..\src\render\software\SDL_drawpoint.c" - > - </File> - <File - RelativePath="..\..\src\render\software\SDL_drawpoint.h" - > - </File> - <File - RelativePath="..\..\src\events\SDL_dropevents.c" - > - </File> - <File - RelativePath="..\..\src\events\SDL_dropevents_c.h" - > - </File> - <File - RelativePath="..\..\src\audio\dummy\SDL_dummyaudio.c" - > - </File> - <File - RelativePath="..\..\src\audio\dummy\SDL_dummyaudio.h" - > - </File> - <File - RelativePath="..\..\src\joystick\windows\SDL_dxjoystick.c" - > - </File> - <File - RelativePath="..\..\src\SDL_error.c" - > - </File> - <File - RelativePath="..\..\src\SDL_error_c.h" - > - </File> - <File - RelativePath="..\..\src\events\SDL_events.c" - > - </File> - <File - RelativePath="..\..\src\events\SDL_events_c.h" - > - </File> - <File - RelativePath="..\..\src\SDL_fatal.c" - > - </File> - <File - RelativePath="..\..\src\SDL_fatal.h" - > - </File> - <File - RelativePath="..\..\src\video\SDL_fillrect.c" - > - </File> - <File - RelativePath="..\..\src\joystick\SDL_gamecontroller.c" - > - </File> - <File - RelativePath="..\..\src\events\SDL_gesture.c" - > - </File> - <File - RelativePath="..\..\src\events\SDL_gesture_c.h" - > - </File> - <File - RelativePath="..\..\src\stdlib\SDL_getenv.c" - > - </File> - <File - RelativePath="..\..\src\video\SDL_glesfuncs.h" - > - </File> - <File - RelativePath="..\..\src\video\SDL_glfuncs.h" - > - </File> - <File - RelativePath="..\..\src\haptic\SDL_haptic.c" - > - </File> - <File - RelativePath="..\..\src\SDL_hints.c" - > - </File> - <File - RelativePath="..\..\src\SDL_hints_c.h" - > - </File> - <File - RelativePath="..\..\src\stdlib\SDL_iconv.c" - > - </File> - <File - RelativePath="..\..\src\joystick\SDL_joystick.c" - > - </File> - <File - RelativePath="..\..\src\joystick\SDL_joystick_c.h" - > - </File> - <File - RelativePath="..\..\src\events\SDL_keyboard.c" - > - </File> - <File - RelativePath="..\..\src\events\SDL_keyboard_c.h" - > - </File> - <File - RelativePath="..\..\src\SDL_log.c" - > - </File> - <File - RelativePath="..\..\src\stdlib\SDL_malloc.c" - > - </File> - <File - RelativePath="..\..\src\audio\SDL_mixer.c" - > - </File> - <File - RelativePath="..\..\src\joystick\windows\SDL_mmjoystick.c" - > - </File> - <File - RelativePath="..\..\src\events\SDL_mouse.c" - > - </File> - <File - RelativePath="..\..\src\events\SDL_mouse_c.h" - > - </File> - <File - RelativePath="..\..\src\video\dummy\SDL_nullevents.c" - > - </File> - <File - RelativePath="..\..\src\video\dummy\SDL_nullevents_c.h" - > - </File> - <File - RelativePath="..\..\src\video\dummy\SDL_nullframebuffer.c" - > - </File> - <File - RelativePath="..\..\src\video\dummy\SDL_nullframebuffer_c.h" - > - </File> - <File - RelativePath="..\..\src\video\dummy\SDL_nullvideo.c" - > - </File> - <File - RelativePath="..\..\src\video\dummy\SDL_nullvideo.h" - > - </File> - <File - RelativePath="..\..\src\video\SDL_pixels.c" - > - </File> - <File - RelativePath="..\..\src\video\SDL_pixels_c.h" - > - </File> - <File - RelativePath="..\..\src\power\SDL_power.c" - > - </File> - <File - RelativePath="..\..\src\stdlib\SDL_qsort.c" - > - </File> - <File - RelativePath="..\..\src\events\SDL_quit.c" - > - </File> - <File - RelativePath="..\..\src\video\SDL_rect.c" - > - </File> - <File - RelativePath="..\..\src\video\SDL_rect_c.h" - > - </File> - <File - RelativePath="..\..\src\render\SDL_render.c" - > - </File> - <File - RelativePath="..\..\src\render\direct3d\SDL_render_d3d.c" - > - </File> - <File - RelativePath="..\..\src\render\opengl\SDL_render_gl.c" - > - </File> - <File - RelativePath="..\..\src\render\software\SDL_render_sw.c" - > - </File> - <File - RelativePath="..\..\src\render\software\SDL_render_sw_c.h" - > - </File> - <File - RelativePath="..\..\src\video\SDL_RLEaccel.c" - > - </File> - <File - RelativePath="..\..\src\video\SDL_RLEaccel_c.h" - > - </File> - <File - RelativePath="..\..\src\render\software\SDL_rotate.c" - > - </File> - <File - RelativePath="..\..\src\render\software\SDL_rotate.h" - > - </File> - <File - RelativePath="..\..\src\file\SDL_rwops.c" - > - </File> - <File - RelativePath="..\..\src\render\opengl\SDL_shaders_gl.c" - > - </File> - <File - RelativePath="..\..\src\render\opengl\SDL_shaders_gl.h" - > - </File> - <File - RelativePath="..\..\src\video\SDL_shape.c" - > - </File> - <File - RelativePath="..\..\src\video\SDL_shape_internals.h" - > - </File> - <File - RelativePath="..\..\src\atomic\SDL_spinlock.c" - > - </File> - <File - RelativePath="..\..\src\stdlib\SDL_stdlib.c" - > - </File> - <File - RelativePath="..\..\src\video\SDL_stretch.c" - > - </File> - <File - RelativePath="..\..\src\stdlib\SDL_string.c" - > - </File> - <File - RelativePath="..\..\src\video\SDL_surface.c" - > - </File> - <File - RelativePath="..\..\src\audio\SDL_sysaudio.h" - > - </File> - <File - RelativePath="..\..\src\thread\generic\SDL_syscond.c" - > - </File> - <File - RelativePath="..\..\src\events\SDL_sysevents.h" - > - </File> - <File - RelativePath="..\..\src\haptic\windows\SDL_syshaptic.c" - > - </File> - <File - RelativePath="..\..\src\haptic\SDL_syshaptic.h" - > - </File> - <File - RelativePath="..\..\src\joystick\SDL_sysjoystick.h" - > - </File> - <File - RelativePath="..\..\src\loadso\windows\SDL_sysloadso.c" - > - </File> - <File - RelativePath="..\..\src\thread\windows\SDL_sysmutex.c" - > - </File> - <File - RelativePath="..\..\src\power\windows\SDL_syspower.c" - > - </File> - <File - RelativePath="..\..\src\render\SDL_sysrender.h" - > - </File> - <File - RelativePath="..\..\src\thread\windows\SDL_syssem.c" - > - </File> - <File - RelativePath="..\..\src\thread\windows\SDL_systhread.c" - > - </File> - <File - RelativePath="..\..\src\thread\SDL_systhread.h" - > - </File> - <File - RelativePath="..\..\src\thread\windows\SDL_systhread_c.h" - > - </File> - <File - RelativePath="..\..\src\timer\windows\SDL_systimer.c" - > - </File> - <File - RelativePath="..\..\src\timer\SDL_systimer.h" - > - </File> - <File - RelativePath="..\..\src\video\SDL_sysvideo.h" - > - </File> - <File - RelativePath="..\..\src\thread\SDL_thread.c" - > - </File> - <File - RelativePath="..\..\src\thread\SDL_thread_c.h" - > - </File> - <File - RelativePath="..\..\src\timer\SDL_timer.c" - > - </File> - <File - RelativePath="..\..\src\timer\SDL_timer_c.h" - > - </File> - <File - RelativePath="..\..\src\events\SDL_touch.c" - > - </File> - <File - RelativePath="..\..\src\events\SDL_touch_c.h" - > - </File> - <File - RelativePath="..\..\src\video\SDL_video.c" - > - </File> - <File - RelativePath="..\..\src\video\windows\SDL_vkeys.h" - > - </File> - <File - RelativePath="..\..\src\audio\SDL_wave.c" - > - </File> - <File - RelativePath="..\..\src\audio\SDL_wave.h" - > - </File> - <File - RelativePath="..\..\src\events\SDL_windowevents.c" - > - </File> - <File - RelativePath="..\..\src\events\SDL_windowevents_c.h" - > - </File> - <File - RelativePath="..\..\src\core\windows\SDL_windows.c" - > - </File> - <File - RelativePath="..\..\src\core\windows\SDL_windows.h" - > - </File> - <File - RelativePath="..\..\src\video\windows\SDL_windowsclipboard.c" - > - </File> - <File - RelativePath="..\..\src\video\windows\SDL_windowsclipboard.h" - > - </File> - <File - RelativePath="..\..\src\video\windows\SDL_windowsevents.c" - > - </File> - <File - RelativePath="..\..\src\video\windows\SDL_windowsevents.h" - > - </File> - <File - RelativePath="..\..\src\video\windows\SDL_windowsframebuffer.c" - > - </File> - <File - RelativePath="..\..\src\video\windows\SDL_windowsframebuffer.h" - > - </File> - <File - RelativePath="..\..\src\video\windows\SDL_windowskeyboard.c" - > - </File> - <File - RelativePath="..\..\src\video\windows\SDL_windowskeyboard.h" - > - </File> - <File - RelativePath="..\..\src\video\windows\SDL_windowsmessagebox.c" - > - </File> - <File - RelativePath="..\..\src\video\windows\SDL_windowsmessagebox.h" - > - </File> - <File - RelativePath="..\..\src\video\windows\SDL_windowsmodes.c" - > - </File> - <File - RelativePath="..\..\src\video\windows\SDL_windowsmodes.h" - > - </File> - <File - RelativePath="..\..\src\video\windows\SDL_windowsmouse.c" - > - </File> - <File - RelativePath="..\..\src\video\windows\SDL_windowsmouse.h" - > - </File> - <File - RelativePath="..\..\src\video\windows\SDL_windowsopengl.c" - > - </File> - <File - RelativePath="..\..\src\video\windows\SDL_windowsopengl.h" - > - </File> - <File - RelativePath="..\..\src\video\windows\SDL_windowsshape.c" - > - </File> - <File - RelativePath="..\..\src\video\windows\SDL_windowsshape.h" - > - </File> - <File - RelativePath="..\..\src\video\windows\SDL_windowsvideo.c" - > - </File> - <File - RelativePath="..\..\src\video\windows\SDL_windowsvideo.h" - > - </File> - <File - RelativePath="..\..\src\video\windows\SDL_windowswindow.c" - > - </File> - <File - RelativePath="..\..\src\video\windows\SDL_windowswindow.h" - > - </File> - <File - RelativePath="..\..\src\audio\winmm\SDL_winmm.c" - > - </File> - <File - RelativePath="..\..\src\audio\winmm\SDL_winmm.h" - > - </File> - <File - RelativePath="..\..\src\audio\xaudio2\SDL_xaudio2.c" - > - </File> - <File - RelativePath="..\..\src\render\SDL_yuv_mmx.c" - > - </File> - <File - RelativePath="..\..\src\render\SDL_yuv_sw.c" - > - </File> - <File - RelativePath="..\..\src\render\SDL_yuv_sw_c.h" - > - </File> - <File - RelativePath="..\..\src\main\windows\version.rc" - > - </File> - <File - RelativePath="..\..\src\video\windows\wmmsg.h" - > - </File> - </Files> - <Globals> - </Globals> - </VisualStudioProject> - diff --git a/VisualC/SDL/SDL_VS2010.vcxproj b/VisualC/SDL/SDL_VS2010.vcxproj index 7960d70a72..00c15332f6 100644 --- a/VisualC/SDL/SDL_VS2010.vcxproj +++ b/VisualC/SDL/SDL_VS2010.vcxproj @@ -92,6 +92,7 @@ <SuppressStartupBanner>true</SuppressStartupBanner> <DebugInformationFormat>EditAndContinue</DebugInformationFormat> <CompileAs>Default</CompileAs> + <ExceptionHandling>false</ExceptionHandling> </ClCompile> <ResourceCompile> <PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions> @@ -123,6 +124,7 @@ </PrecompiledHeader> <WarningLevel>Level3</WarningLevel> <DebugInformationFormat>ProgramDatabase</DebugInformationFormat> + <ExceptionHandling>false</ExceptionHandling> </ClCompile> <ResourceCompile> <PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions> @@ -159,6 +161,7 @@ <WarningLevel>Level3</WarningLevel> <SuppressStartupBanner>true</SuppressStartupBanner> <CompileAs>Default</CompileAs> + <ExceptionHandling>false</ExceptionHandling> </ClCompile> <ResourceCompile> <PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions> @@ -170,6 +173,8 @@ <SubSystem>Windows</SubSystem> <AdditionalLibraryDirectories>$(DXSDK_DIR)\lib\x86</AdditionalLibraryDirectories> <GenerateDebugInformation>true</GenerateDebugInformation> + <EnableCOMDATFolding>true</EnableCOMDATFolding> + <OptimizeReferences>true</OptimizeReferences> </Link> </ItemDefinitionGroup> <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> @@ -191,6 +196,7 @@ <PrecompiledHeader> </PrecompiledHeader> <WarningLevel>Level3</WarningLevel> + <ExceptionHandling>false</ExceptionHandling> </ClCompile> <ResourceCompile> <PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions> @@ -201,6 +207,9 @@ <IgnoreAllDefaultLibraries>true</IgnoreAllDefaultLibraries> <SubSystem>Windows</SubSystem> <AdditionalLibraryDirectories>$(DXSDK_DIR)\lib\x64</AdditionalLibraryDirectories> + <GenerateDebugInformation>true</GenerateDebugInformation> + <EnableCOMDATFolding>true</EnableCOMDATFolding> + <OptimizeReferences>true</OptimizeReferences> </Link> </ItemDefinitionGroup> <ItemGroup> @@ -451,4 +460,4 @@ <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> <ImportGroup Label="ExtensionTargets"> </ImportGroup> -</Project> +</Project>
\ No newline at end of file diff --git a/VisualC/SDL/SDL_VS2012.vcxproj b/VisualC/SDL/SDL_VS2012.vcxproj index 7ef76082fe..cdc427e664 100644 --- a/VisualC/SDL/SDL_VS2012.vcxproj +++ b/VisualC/SDL/SDL_VS2012.vcxproj @@ -1,457 +1,467 @@ -<?xml version="1.0" encoding="utf-8"?>
-<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
- <ItemGroup Label="ProjectConfigurations">
- <ProjectConfiguration Include="Debug|Win32">
- <Configuration>Debug</Configuration>
- <Platform>Win32</Platform>
- </ProjectConfiguration>
- <ProjectConfiguration Include="Debug|x64">
- <Configuration>Debug</Configuration>
- <Platform>x64</Platform>
- </ProjectConfiguration>
- <ProjectConfiguration Include="Release|Win32">
- <Configuration>Release</Configuration>
- <Platform>Win32</Platform>
- </ProjectConfiguration>
- <ProjectConfiguration Include="Release|x64">
- <Configuration>Release</Configuration>
- <Platform>x64</Platform>
- </ProjectConfiguration>
- </ItemGroup>
- <PropertyGroup Label="Globals">
- <ProjectName>SDL</ProjectName>
- <ProjectGuid>{81CE8DAF-EBB2-4761-8E45-B71ABCCA8C68}</ProjectGuid>
- <RootNamespace>SDL</RootNamespace>
- </PropertyGroup>
- <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
- <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
- <ConfigurationType>DynamicLibrary</ConfigurationType>
- <UseOfMfc>false</UseOfMfc>
- <PlatformToolset>v110</PlatformToolset>
- </PropertyGroup>
- <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
- <ConfigurationType>DynamicLibrary</ConfigurationType>
- <UseOfMfc>false</UseOfMfc>
- <PlatformToolset>v110</PlatformToolset>
- </PropertyGroup>
- <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
- <ConfigurationType>DynamicLibrary</ConfigurationType>
- <UseOfMfc>false</UseOfMfc>
- <PlatformToolset>v110</PlatformToolset>
- </PropertyGroup>
- <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
- <ConfigurationType>DynamicLibrary</ConfigurationType>
- <UseOfMfc>false</UseOfMfc>
- <CharacterSet>MultiByte</CharacterSet>
- <PlatformToolset>v110</PlatformToolset>
- </PropertyGroup>
- <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
- <ImportGroup Label="ExtensionSettings">
- </ImportGroup>
- <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="PropertySheets">
- <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
- <Import Project="$(VCTargetsPath)Microsoft.CPP.UpgradeFromVC70.props" />
- </ImportGroup>
- <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="PropertySheets">
- <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
- <Import Project="$(VCTargetsPath)Microsoft.CPP.UpgradeFromVC70.props" />
- </ImportGroup>
- <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="PropertySheets">
- <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
- <Import Project="$(VCTargetsPath)Microsoft.CPP.UpgradeFromVC70.props" />
- </ImportGroup>
- <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="PropertySheets">
- <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
- <Import Project="$(VCTargetsPath)Microsoft.CPP.UpgradeFromVC70.props" />
- </ImportGroup>
- <PropertyGroup Label="UserMacros" />
- <PropertyGroup>
- <_ProjectFileVersion>10.0.30319.1</_ProjectFileVersion>
- <OutDir Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(Platform)\$(Configuration)\</OutDir>
- <IntDir Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(Platform)\$(Configuration)\</IntDir>
- <OutDir Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">$(Platform)\$(Configuration)\</OutDir>
- <IntDir Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">$(Platform)\$(Configuration)\</IntDir>
- <OutDir Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(Platform)\$(Configuration)\</OutDir>
- <IntDir Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(Platform)\$(Configuration)\</IntDir>
- <OutDir Condition="'$(Configuration)|$(Platform)'=='Release|x64'">$(Platform)\$(Configuration)\</OutDir>
- <IntDir Condition="'$(Configuration)|$(Platform)'=='Release|x64'">$(Platform)\$(Configuration)\</IntDir>
- </PropertyGroup>
- <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
- <PreBuildEvent />
- <Midl>
- <PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
- <MkTypLibCompatible>true</MkTypLibCompatible>
- <SuppressStartupBanner>true</SuppressStartupBanner>
- <TargetEnvironment>Win32</TargetEnvironment>
- </Midl>
- <ClCompile>
- <Optimization>Disabled</Optimization>
- <AdditionalIncludeDirectories>..\..\include;%(AdditionalIncludeDirectories);"$(DXSDK_DIR)\Include";</AdditionalIncludeDirectories>
- <PreprocessorDefinitions>_DEBUG;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
- <RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
- <BufferSecurityCheck>false</BufferSecurityCheck>
- <PrecompiledHeader>
- </PrecompiledHeader>
- <WarningLevel>Level3</WarningLevel>
- <SuppressStartupBanner>true</SuppressStartupBanner>
- <DebugInformationFormat>EditAndContinue</DebugInformationFormat>
- <CompileAs>Default</CompileAs>
- </ClCompile>
- <ResourceCompile>
- <PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
- <Culture>0x0409</Culture>
- </ResourceCompile>
- <Link>
- <AdditionalDependencies>winmm.lib;imm32.lib;version.lib;%(AdditionalDependencies)</AdditionalDependencies>
- <IgnoreAllDefaultLibraries>true</IgnoreAllDefaultLibraries>
- <GenerateDebugInformation>true</GenerateDebugInformation>
- <SubSystem>Windows</SubSystem>
- <CLRUnmanagedCodeCheck>false</CLRUnmanagedCodeCheck>
- <AdditionalLibraryDirectories>$(DXSDK_DIR)\lib\x86</AdditionalLibraryDirectories>
- </Link>
- </ItemDefinitionGroup>
- <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
- <Midl>
- <PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
- <MkTypLibCompatible>true</MkTypLibCompatible>
- <SuppressStartupBanner>true</SuppressStartupBanner>
- <TargetEnvironment>X64</TargetEnvironment>
- </Midl>
- <ClCompile>
- <Optimization>Disabled</Optimization>
- <AdditionalIncludeDirectories>..\..\include;%(AdditionalIncludeDirectories);"$(DXSDK_DIR)\Include";</AdditionalIncludeDirectories>
- <PreprocessorDefinitions>_DEBUG;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
- <RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
- <BufferSecurityCheck>false</BufferSecurityCheck>
- <PrecompiledHeader>
- </PrecompiledHeader>
- <WarningLevel>Level3</WarningLevel>
- <DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
- </ClCompile>
- <ResourceCompile>
- <PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
- <Culture>0x0409</Culture>
- </ResourceCompile>
- <Link>
- <AdditionalDependencies>winmm.lib;imm32.lib;version.lib;%(AdditionalDependencies)</AdditionalDependencies>
- <IgnoreAllDefaultLibraries>true</IgnoreAllDefaultLibraries>
- <GenerateDebugInformation>true</GenerateDebugInformation>
- <SubSystem>Windows</SubSystem>
- <CLRUnmanagedCodeCheck>false</CLRUnmanagedCodeCheck>
- <AdditionalLibraryDirectories>$(DXSDK_DIR)\lib\x64</AdditionalLibraryDirectories>
- </Link>
- </ItemDefinitionGroup>
- <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
- <PreBuildEvent />
- <Midl>
- <PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
- <MkTypLibCompatible>true</MkTypLibCompatible>
- <SuppressStartupBanner>true</SuppressStartupBanner>
- <TargetEnvironment>Win32</TargetEnvironment>
- </Midl>
- <ClCompile>
- <InlineFunctionExpansion>OnlyExplicitInline</InlineFunctionExpansion>
- <IntrinsicFunctions>false</IntrinsicFunctions>
- <AdditionalIncludeDirectories>..\..\include;%(AdditionalIncludeDirectories);"$(DXSDK_DIR)\Include";</AdditionalIncludeDirectories>
- <PreprocessorDefinitions>NDEBUG;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
- <StringPooling>true</StringPooling>
- <RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
- <BufferSecurityCheck>false</BufferSecurityCheck>
- <FunctionLevelLinking>true</FunctionLevelLinking>
- <PrecompiledHeader>
- </PrecompiledHeader>
- <WarningLevel>Level3</WarningLevel>
- <SuppressStartupBanner>true</SuppressStartupBanner>
- <CompileAs>Default</CompileAs>
- </ClCompile>
- <ResourceCompile>
- <PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
- <Culture>0x0409</Culture>
- </ResourceCompile>
- <Link>
- <AdditionalDependencies>winmm.lib;imm32.lib;version.lib;%(AdditionalDependencies)</AdditionalDependencies>
- <IgnoreAllDefaultLibraries>true</IgnoreAllDefaultLibraries>
- <SubSystem>Windows</SubSystem>
- <AdditionalLibraryDirectories>$(DXSDK_DIR)\lib\x86</AdditionalLibraryDirectories>
- </Link>
- </ItemDefinitionGroup>
- <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
- <Midl>
- <PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
- <MkTypLibCompatible>true</MkTypLibCompatible>
- <SuppressStartupBanner>true</SuppressStartupBanner>
- <TargetEnvironment>X64</TargetEnvironment>
- </Midl>
- <ClCompile>
- <InlineFunctionExpansion>OnlyExplicitInline</InlineFunctionExpansion>
- <IntrinsicFunctions>false</IntrinsicFunctions>
- <AdditionalIncludeDirectories>..\..\include;%(AdditionalIncludeDirectories);"$(DXSDK_DIR)\Include";</AdditionalIncludeDirectories>
- <PreprocessorDefinitions>NDEBUG;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
- <StringPooling>true</StringPooling>
- <RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
- <BufferSecurityCheck>false</BufferSecurityCheck>
- <FunctionLevelLinking>true</FunctionLevelLinking>
- <PrecompiledHeader>
- </PrecompiledHeader>
- <WarningLevel>Level3</WarningLevel>
- </ClCompile>
- <ResourceCompile>
- <PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
- <Culture>0x0409</Culture>
- </ResourceCompile>
- <Link>
- <AdditionalDependencies>winmm.lib;imm32.lib;version.lib;%(AdditionalDependencies)</AdditionalDependencies>
- <IgnoreAllDefaultLibraries>true</IgnoreAllDefaultLibraries>
- <SubSystem>Windows</SubSystem>
- <AdditionalLibraryDirectories>$(DXSDK_DIR)\lib\x64</AdditionalLibraryDirectories>
- </Link>
- </ItemDefinitionGroup>
- <ItemGroup>
- <ClInclude Include="..\..\include\SDL.h" />
- <ClInclude Include="..\..\include\SDL_assert.h" />
- <ClInclude Include="..\..\include\SDL_atomic.h" />
- <ClInclude Include="..\..\include\SDL_audio.h" />
- <ClInclude Include="..\..\include\SDL_bits.h" />
- <ClInclude Include="..\..\include\SDL_blendmode.h" />
- <ClInclude Include="..\..\include\SDL_clipboard.h" />
- <ClInclude Include="..\..\include\SDL_config.h" />
- <ClInclude Include="..\..\include\SDL_config_windows.h" />
- <ClInclude Include="..\..\include\SDL_copying.h" />
- <ClInclude Include="..\..\include\SDL_cpuinfo.h" />
- <ClInclude Include="..\..\include\SDL_endian.h" />
- <ClInclude Include="..\..\include\SDL_error.h" />
- <ClInclude Include="..\..\include\SDL_events.h" />
- <ClInclude Include="..\..\include\SDL_gesture.h" />
- <ClInclude Include="..\..\include\SDL_haptic.h" />
- <ClInclude Include="..\..\include\SDL_hints.h" />
- <ClInclude Include="..\..\include\SDL_joystick.h" />
- <ClInclude Include="..\..\include\SDL_keyboard.h" />
- <ClInclude Include="..\..\include\SDL_keycode.h" />
- <ClInclude Include="..\..\include\SDL_loadso.h" />
- <ClInclude Include="..\..\include\SDL_log.h" />
- <ClInclude Include="..\..\include\SDL_main.h" />
- <ClInclude Include="..\..\include\SDL_mouse.h" />
- <ClInclude Include="..\..\include\SDL_mutex.h" />
- <ClInclude Include="..\..\include\SDL_name.h" />
- <ClInclude Include="..\..\include\SDL_opengl.h" />
- <ClInclude Include="..\..\include\SDL_opengles.h" />
- <ClInclude Include="..\..\include\SDL_pixels.h" />
- <ClInclude Include="..\..\include\SDL_platform.h" />
- <ClInclude Include="..\..\include\SDL_power.h" />
- <ClInclude Include="..\..\include\SDL_quit.h" />
- <ClInclude Include="..\..\include\SDL_rect.h" />
- <ClInclude Include="..\..\include\SDL_render.h" />
- <ClInclude Include="..\..\include\SDL_revision.h" />
- <ClInclude Include="..\..\include\SDL_rwops.h" />
- <ClInclude Include="..\..\include\SDL_scancode.h" />
- <ClInclude Include="..\..\include\SDL_shape.h" />
- <ClInclude Include="..\..\include\SDL_stdinc.h" />
- <ClInclude Include="..\..\include\SDL_surface.h" />
- <ClInclude Include="..\..\include\SDL_system.h" />
- <ClInclude Include="..\..\include\SDL_syswm.h" />
- <ClInclude Include="..\..\include\SDL_thread.h" />
- <ClInclude Include="..\..\include\SDL_timer.h" />
- <ClInclude Include="..\..\include\SDL_touch.h" />
- <ClInclude Include="..\..\include\SDL_types.h" />
- <ClInclude Include="..\..\include\SDL_version.h" />
- <ClInclude Include="..\..\include\SDL_video.h" />
- <ClInclude Include="..\..\include\SDL_gamecontroller.h" />
- <ClInclude Include="..\..\src\core\windows\SDL_windows.h" />
- <ClInclude Include="..\..\src\events\blank_cursor.h" />
- <ClInclude Include="..\..\src\events\default_cursor.h" />
- <ClInclude Include="..\..\src\audio\directsound\directx.h" />
- <ClInclude Include="..\..\src\events\SDL_clipboardevents_c.h" />
- <ClInclude Include="..\..\src\events\SDL_gesture_c.h" />
- <ClInclude Include="..\..\src\events\SDL_touch_c.h" />
- <ClInclude Include="..\..\src\libm\math.h" />
- <ClInclude Include="..\..\src\libm\math_private.h" />
- <ClInclude Include="..\..\src\render\mmx.h" />
- <ClInclude Include="..\..\src\render\opengl\SDL_shaders_gl.h" />
- <ClInclude Include="..\..\src\render\SDL_sysrender.h" />
- <ClInclude Include="..\..\src\render\SDL_yuv_sw_c.h" />
- <ClInclude Include="..\..\src\audio\SDL_audio_c.h" />
- <ClInclude Include="..\..\src\audio\SDL_audiodev_c.h" />
- <ClInclude Include="..\..\src\audio\SDL_audiomem.h" />
- <ClInclude Include="..\..\src\render\software\SDL_blendfillrect.h" />
- <ClInclude Include="..\..\src\render\software\SDL_blendline.h" />
- <ClInclude Include="..\..\src\render\software\SDL_blendpoint.h" />
- <ClInclude Include="..\..\src\render\software\SDL_draw.h" />
- <ClInclude Include="..\..\src\render\software\SDL_drawline.h" />
- <ClInclude Include="..\..\src\render\software\SDL_drawpoint.h" />
- <ClInclude Include="..\..\src\events\SDL_dropevents_c.h" />
- <ClInclude Include="..\..\src\render\software\SDL_render_sw_c.h" />
- <ClInclude Include="..\..\src\render\software\SDL_rotate.h" />
- <ClInclude Include="..\..\src\video\dummy\SDL_nullframebuffer_c.h" />
- <ClInclude Include="..\..\src\video\SDL_blit.h" />
- <ClInclude Include="..\..\src\video\SDL_blit_auto.h" />
- <ClInclude Include="..\..\src\video\SDL_blit_copy.h" />
- <ClInclude Include="..\..\src\video\SDL_blit_slow.h" />
- <ClInclude Include="..\..\src\video\SDL_shape_internals.h" />
- <ClInclude Include="..\..\src\audio\winmm\SDL_winmm.h" />
- <ClInclude Include="..\..\src\audio\disk\SDL_diskaudio.h" />
- <ClInclude Include="..\..\src\audio\dummy\SDL_dummyaudio.h" />
- <ClInclude Include="..\..\src\audio\directsound\SDL_directsound.h" />
- <ClInclude Include="..\..\src\SDL_error_c.h" />
- <ClInclude Include="..\..\src\SDL_hints_c.h" />
- <ClInclude Include="..\..\src\events\SDL_events_c.h" />
- <ClInclude Include="..\..\src\SDL_fatal.h" />
- <ClInclude Include="..\..\src\video\SDL_glesfuncs.h" />
- <ClInclude Include="..\..\src\video\SDL_glfuncs.h" />
- <ClInclude Include="..\..\src\joystick\SDL_joystick_c.h" />
- <ClInclude Include="..\..\src\events\SDL_keyboard_c.h" />
- <ClInclude Include="..\..\src\events\SDL_mouse_c.h" />
- <ClInclude Include="..\..\src\video\dummy\SDL_nullevents_c.h" />
- <ClInclude Include="..\..\src\video\dummy\SDL_nullvideo.h" />
- <ClInclude Include="..\..\src\video\SDL_pixels_c.h" />
- <ClInclude Include="..\..\src\video\SDL_rect_c.h" />
- <ClInclude Include="..\..\src\video\SDL_RLEaccel_c.h" />
- <ClInclude Include="..\..\src\video\SDL_stretch_c.h" />
- <ClInclude Include="..\..\src\audio\SDL_sysaudio.h" />
- <ClInclude Include="..\..\src\events\SDL_sysevents.h" />
- <ClInclude Include="..\..\src\haptic\SDL_syshaptic.h" />
- <ClInclude Include="..\..\src\joystick\SDL_sysjoystick.h" />
- <ClInclude Include="..\..\src\thread\SDL_systhread.h" />
- <ClInclude Include="..\..\src\thread\windows\SDL_systhread_c.h" />
- <ClInclude Include="..\..\src\timer\SDL_systimer.h" />
- <ClInclude Include="..\..\src\video\SDL_sysvideo.h" />
- <ClInclude Include="..\..\src\thread\SDL_thread_c.h" />
- <ClInclude Include="..\..\src\timer\SDL_timer_c.h" />
- <ClInclude Include="..\..\src\video\windows\SDL_vkeys.h" />
- <ClInclude Include="..\..\src\audio\SDL_wave.h" />
- <ClInclude Include="..\..\src\video\windows\SDL_windowsclipboard.h" />
- <ClInclude Include="..\..\src\video\windows\SDL_windowsevents.h" />
- <ClInclude Include="..\..\src\video\windows\SDL_windowsframebuffer.h" />
- <ClInclude Include="..\..\src\video\windows\SDL_windowskeyboard.h" />
- <ClInclude Include="..\..\src\video\windows\SDL_windowsmessagebox.h" />
- <ClInclude Include="..\..\src\video\windows\SDL_windowsmodes.h" />
- <ClInclude Include="..\..\src\video\windows\SDL_windowsmouse.h" />
- <ClInclude Include="..\..\src\video\windows\SDL_windowsopengl.h" />
- <ClInclude Include="..\..\src\video\windows\SDL_windowsshape.h" />
- <ClInclude Include="..\..\src\video\windows\SDL_windowsvideo.h" />
- <ClInclude Include="..\..\src\video\windows\SDL_windowswindow.h" />
- <ClInclude Include="..\..\src\events\SDL_windowevents_c.h" />
- <ClInclude Include="..\..\src\video\windows\wmmsg.h" />
- <ClInclude Include="resource.h" />
- </ItemGroup>
- <ItemGroup>
- <ClCompile Include="..\..\src\core\windows\SDL_windows.c" />
- <ClCompile Include="..\..\src\events\SDL_clipboardevents.c" />
- <ClCompile Include="..\..\src\events\SDL_gesture.c" />
- <ClCompile Include="..\..\src\events\SDL_touch.c" />
- <ClCompile Include="..\..\src\libm\e_atan2.c" />
- <ClCompile Include="..\..\src\libm\e_log.c" />
- <ClCompile Include="..\..\src\libm\e_pow.c" />
- <ClCompile Include="..\..\src\libm\e_rem_pio2.c" />
- <ClCompile Include="..\..\src\libm\e_sqrt.c" />
- <ClCompile Include="..\..\src\libm\k_cos.c" />
- <ClCompile Include="..\..\src\libm\k_rem_pio2.c" />
- <ClCompile Include="..\..\src\libm\k_sin.c" />
- <ClCompile Include="..\..\src\libm\s_atan.c" />
- <ClCompile Include="..\..\src\libm\s_copysign.c" />
- <ClCompile Include="..\..\src\libm\s_cos.c" />
- <ClCompile Include="..\..\src\libm\s_fabs.c" />
- <ClCompile Include="..\..\src\libm\s_floor.c" />
- <ClCompile Include="..\..\src\libm\s_scalbn.c" />
- <ClCompile Include="..\..\src\libm\s_sin.c" />
- <ClCompile Include="..\..\src\render\direct3d\SDL_render_d3d.c" />
- <ClCompile Include="..\..\src\render\opengl\SDL_render_gl.c" />
- <ClCompile Include="..\..\src\render\opengl\SDL_shaders_gl.c" />
- <ClCompile Include="..\..\src\render\SDL_render.c" />
- <ClCompile Include="..\..\src\render\SDL_yuv_mmx.c" />
- <ClCompile Include="..\..\src\render\SDL_yuv_sw.c" />
- <ClCompile Include="..\..\src\render\software\SDL_blendfillrect.c" />
- <ClCompile Include="..\..\src\render\software\SDL_blendline.c" />
- <ClCompile Include="..\..\src\render\software\SDL_blendpoint.c" />
- <ClCompile Include="..\..\src\render\software\SDL_drawline.c" />
- <ClCompile Include="..\..\src\render\software\SDL_drawpoint.c" />
- <ClCompile Include="..\..\src\render\software\SDL_render_sw.c" />
- <ClCompile Include="..\..\src\render\software\SDL_rotate.c" />
- <ClCompile Include="..\..\src\SDL.c" />
- <ClCompile Include="..\..\src\SDL_assert.c" />
- <ClCompile Include="..\..\src\atomic\SDL_atomic.c" />
- <ClCompile Include="..\..\src\atomic\SDL_spinlock.c" />
- <ClCompile Include="..\..\src\audio\SDL_audio.c" />
- <ClCompile Include="..\..\src\audio\SDL_audiocvt.c" />
- <ClCompile Include="..\..\src\audio\SDL_audiodev.c" />
- <ClCompile Include="..\..\src\audio\SDL_audiotypecvt.c" />
- <ClCompile Include="..\..\src\SDL_hints.c" />
- <ClCompile Include="..\..\src\SDL_log.c" />
- <ClCompile Include="..\..\src\video\dummy\SDL_nullframebuffer.c" />
- <ClCompile Include="..\..\src\video\SDL_blit.c" />
- <ClCompile Include="..\..\src\video\SDL_blit_0.c" />
- <ClCompile Include="..\..\src\video\SDL_blit_1.c" />
- <ClCompile Include="..\..\src\video\SDL_blit_A.c" />
- <ClCompile Include="..\..\src\video\SDL_blit_auto.c" />
- <ClCompile Include="..\..\src\video\SDL_blit_copy.c" />
- <ClCompile Include="..\..\src\video\SDL_blit_N.c" />
- <ClCompile Include="..\..\src\video\SDL_blit_slow.c" />
- <ClCompile Include="..\..\src\video\SDL_bmp.c" />
- <ClCompile Include="..\..\src\cpuinfo\SDL_cpuinfo.c" />
- <ClCompile Include="..\..\src\video\SDL_clipboard.c" />
- <ClCompile Include="..\..\src\video\SDL_shape.c" />
- <ClCompile Include="..\..\src\audio\winmm\SDL_winmm.c" />
- <ClCompile Include="..\..\src\audio\disk\SDL_diskaudio.c" />
- <ClCompile Include="..\..\src\audio\dummy\SDL_dummyaudio.c" />
- <ClCompile Include="..\..\src\audio\directsound\SDL_directsound.c" />
- <ClCompile Include="..\..\src\events\SDL_dropevents.c" />
- <ClCompile Include="..\..\src\audio\xaudio2\SDL_xaudio2.c" />
- <ClCompile Include="..\..\src\joystick\windows\SDL_dxjoystick.c" />
- <ClCompile Include="..\..\src\SDL_error.c" />
- <ClCompile Include="..\..\src\events\SDL_events.c" />
- <ClCompile Include="..\..\src\SDL_fatal.c" />
- <ClCompile Include="..\..\src\video\SDL_fillrect.c" />
- <ClCompile Include="..\..\src\stdlib\SDL_getenv.c" />
- <ClCompile Include="..\..\src\haptic\SDL_haptic.c" />
- <ClCompile Include="..\..\src\stdlib\SDL_iconv.c" />
- <ClCompile Include="..\..\src\joystick\SDL_joystick.c" />
- <ClCompile Include="..\..\src\events\SDL_keyboard.c" />
- <ClCompile Include="..\..\src\stdlib\SDL_malloc.c" />
- <ClCompile Include="..\..\src\audio\SDL_mixer.c" />
- <ClCompile Include="..\..\src\joystick\windows\SDL_mmjoystick.c" />
- <ClCompile Include="..\..\src\events\SDL_mouse.c" />
- <ClCompile Include="..\..\src\video\dummy\SDL_nullevents.c" />
- <ClCompile Include="..\..\src\video\dummy\SDL_nullvideo.c" />
- <ClCompile Include="..\..\src\video\SDL_pixels.c" />
- <ClCompile Include="..\..\src\power\SDL_power.c" />
- <ClCompile Include="..\..\src\stdlib\SDL_qsort.c" />
- <ClCompile Include="..\..\src\events\SDL_quit.c" />
- <ClCompile Include="..\..\src\video\SDL_rect.c" />
- <ClCompile Include="..\..\src\video\SDL_RLEaccel.c" />
- <ClCompile Include="..\..\src\file\SDL_rwops.c" />
- <ClCompile Include="..\..\src\stdlib\SDL_stdlib.c" />
- <ClCompile Include="..\..\src\video\SDL_stretch.c" />
- <ClCompile Include="..\..\src\stdlib\SDL_string.c" />
- <ClCompile Include="..\..\src\video\SDL_surface.c" />
- <ClCompile Include="..\..\src\thread\generic\SDL_syscond.c" />
- <ClCompile Include="..\..\src\haptic\windows\SDL_syshaptic.c" />
- <ClCompile Include="..\..\src\loadso\windows\SDL_sysloadso.c" />
- <ClCompile Include="..\..\src\thread\windows\SDL_sysmutex.c" />
- <ClCompile Include="..\..\src\power\windows\SDL_syspower.c" />
- <ClCompile Include="..\..\src\thread\windows\SDL_syssem.c" />
- <ClCompile Include="..\..\src\thread\windows\SDL_systhread.c" />
- <ClCompile Include="..\..\src\timer\windows\SDL_systimer.c" />
- <ClCompile Include="..\..\src\thread\SDL_thread.c" />
- <ClCompile Include="..\..\src\timer\SDL_timer.c" />
- <ClCompile Include="..\..\src\video\SDL_video.c" />
- <ClCompile Include="..\..\src\audio\SDL_wave.c" />
- <ClCompile Include="..\..\src\video\windows\SDL_windowsclipboard.c" />
- <ClCompile Include="..\..\src\video\windows\SDL_windowsevents.c" />
- <ClCompile Include="..\..\src\video\windows\SDL_windowsframebuffer.c" />
- <ClCompile Include="..\..\src\video\windows\SDL_windowskeyboard.c" />
- <ClCompile Include="..\..\src\video\windows\SDL_windowsmessagebox.c" />
- <ClCompile Include="..\..\src\video\windows\SDL_windowsmodes.c" />
- <ClCompile Include="..\..\src\video\windows\SDL_windowsmouse.c" />
- <ClCompile Include="..\..\src\video\windows\SDL_windowsopengl.c" />
- <ClCompile Include="..\..\src\video\windows\SDL_windowsshape.c" />
- <ClCompile Include="..\..\src\video\windows\SDL_windowsvideo.c" />
- <ClCompile Include="..\..\src\video\windows\SDL_windowswindow.c" />
- <ClCompile Include="..\..\src\events\SDL_windowevents.c" />
- <ClCompile Include="..\..\src\joystick\SDL_gamecontroller.c" />
- </ItemGroup>
- <ItemGroup>
- <ResourceCompile Include="..\..\src\main\windows\version.rc" />
- </ItemGroup>
- <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
- <ImportGroup Label="ExtensionTargets">
- </ImportGroup>
-</Project>
+<?xml version="1.0" encoding="utf-8"?> +<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> + <ItemGroup Label="ProjectConfigurations"> + <ProjectConfiguration Include="Debug|Win32"> + <Configuration>Debug</Configuration> + <Platform>Win32</Platform> + </ProjectConfiguration> + <ProjectConfiguration Include="Debug|x64"> + <Configuration>Debug</Configuration> + <Platform>x64</Platform> + </ProjectConfiguration> + <ProjectConfiguration Include="Release|Win32"> + <Configuration>Release</Configuration> + <Platform>Win32</Platform> + </ProjectConfiguration> + <ProjectConfiguration Include="Release|x64"> + <Configuration>Release</Configuration> + <Platform>x64</Platform> + </ProjectConfiguration> + </ItemGroup> + <PropertyGroup Label="Globals"> + <ProjectName>SDL</ProjectName> + <ProjectGuid>{81CE8DAF-EBB2-4761-8E45-B71ABCCA8C68}</ProjectGuid> + <RootNamespace>SDL</RootNamespace> + </PropertyGroup> + <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" /> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration"> + <ConfigurationType>DynamicLibrary</ConfigurationType> + <UseOfMfc>false</UseOfMfc> + <PlatformToolset>v110</PlatformToolset> + </PropertyGroup> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration"> + <ConfigurationType>DynamicLibrary</ConfigurationType> + <UseOfMfc>false</UseOfMfc> + <PlatformToolset>v110</PlatformToolset> + </PropertyGroup> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration"> + <ConfigurationType>DynamicLibrary</ConfigurationType> + <UseOfMfc>false</UseOfMfc> + <PlatformToolset>v110</PlatformToolset> + </PropertyGroup> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration"> + <ConfigurationType>DynamicLibrary</ConfigurationType> + <UseOfMfc>false</UseOfMfc> + <CharacterSet>MultiByte</CharacterSet> + <PlatformToolset>v110</PlatformToolset> + </PropertyGroup> + <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" /> + <ImportGroup Label="ExtensionSettings"> + </ImportGroup> + <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="PropertySheets"> + <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> + <Import Project="$(VCTargetsPath)Microsoft.CPP.UpgradeFromVC70.props" /> + </ImportGroup> + <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="PropertySheets"> + <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> + <Import Project="$(VCTargetsPath)Microsoft.CPP.UpgradeFromVC70.props" /> + </ImportGroup> + <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="PropertySheets"> + <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> + <Import Project="$(VCTargetsPath)Microsoft.CPP.UpgradeFromVC70.props" /> + </ImportGroup> + <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="PropertySheets"> + <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> + <Import Project="$(VCTargetsPath)Microsoft.CPP.UpgradeFromVC70.props" /> + </ImportGroup> + <PropertyGroup Label="UserMacros" /> + <PropertyGroup> + <_ProjectFileVersion>10.0.30319.1</_ProjectFileVersion> + <OutDir Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(Platform)\$(Configuration)\</OutDir> + <IntDir Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(Platform)\$(Configuration)\</IntDir> + <OutDir Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">$(Platform)\$(Configuration)\</OutDir> + <IntDir Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">$(Platform)\$(Configuration)\</IntDir> + <OutDir Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(Platform)\$(Configuration)\</OutDir> + <IntDir Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(Platform)\$(Configuration)\</IntDir> + <OutDir Condition="'$(Configuration)|$(Platform)'=='Release|x64'">$(Platform)\$(Configuration)\</OutDir> + <IntDir Condition="'$(Configuration)|$(Platform)'=='Release|x64'">$(Platform)\$(Configuration)\</IntDir> + </PropertyGroup> + <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> + <PreBuildEvent /> + <Midl> + <PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions> + <MkTypLibCompatible>true</MkTypLibCompatible> + <SuppressStartupBanner>true</SuppressStartupBanner> + <TargetEnvironment>Win32</TargetEnvironment> + </Midl> + <ClCompile> + <Optimization>Disabled</Optimization> + <AdditionalIncludeDirectories>..\..\include;%(AdditionalIncludeDirectories);"$(DXSDK_DIR)\Include";</AdditionalIncludeDirectories> + <PreprocessorDefinitions>_DEBUG;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions> + <RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary> + <BufferSecurityCheck>false</BufferSecurityCheck> + <PrecompiledHeader> + </PrecompiledHeader> + <WarningLevel>Level3</WarningLevel> + <SuppressStartupBanner>true</SuppressStartupBanner> + <DebugInformationFormat>EditAndContinue</DebugInformationFormat> + <CompileAs>Default</CompileAs> + <ExceptionHandling>false</ExceptionHandling> + </ClCompile> + <ResourceCompile> + <PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions> + <Culture>0x0409</Culture> + </ResourceCompile> + <Link> + <AdditionalDependencies>winmm.lib;imm32.lib;version.lib;%(AdditionalDependencies)</AdditionalDependencies> + <IgnoreAllDefaultLibraries>true</IgnoreAllDefaultLibraries> + <GenerateDebugInformation>true</GenerateDebugInformation> + <SubSystem>Windows</SubSystem> + <CLRUnmanagedCodeCheck>false</CLRUnmanagedCodeCheck> + <AdditionalLibraryDirectories>$(DXSDK_DIR)\lib\x86</AdditionalLibraryDirectories> + </Link> + </ItemDefinitionGroup> + <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> + <Midl> + <PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions> + <MkTypLibCompatible>true</MkTypLibCompatible> + <SuppressStartupBanner>true</SuppressStartupBanner> + <TargetEnvironment>X64</TargetEnvironment> + </Midl> + <ClCompile> + <Optimization>Disabled</Optimization> + <AdditionalIncludeDirectories>..\..\include;%(AdditionalIncludeDirectories);"$(DXSDK_DIR)\Include";</AdditionalIncludeDirectories> + <PreprocessorDefinitions>_DEBUG;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions> + <RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary> + <BufferSecurityCheck>false</BufferSecurityCheck> + <PrecompiledHeader> + </PrecompiledHeader> + <WarningLevel>Level3</WarningLevel> + <DebugInformationFormat>ProgramDatabase</DebugInformationFormat> + <ExceptionHandling>false</ExceptionHandling> + </ClCompile> + <ResourceCompile> + <PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions> + <Culture>0x0409</Culture> + </ResourceCompile> + <Link> + <AdditionalDependencies>winmm.lib;imm32.lib;version.lib;%(AdditionalDependencies)</AdditionalDependencies> + <IgnoreAllDefaultLibraries>true</IgnoreAllDefaultLibraries> + <GenerateDebugInformation>true</GenerateDebugInformation> + <SubSystem>Windows</SubSystem> + <CLRUnmanagedCodeCheck>false</CLRUnmanagedCodeCheck> + <AdditionalLibraryDirectories>$(DXSDK_DIR)\lib\x64</AdditionalLibraryDirectories> + </Link> + </ItemDefinitionGroup> + <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> + <PreBuildEvent /> + <Midl> + <PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions> + <MkTypLibCompatible>true</MkTypLibCompatible> + <SuppressStartupBanner>true</SuppressStartupBanner> + <TargetEnvironment>Win32</TargetEnvironment> + </Midl> + <ClCompile> + <InlineFunctionExpansion>OnlyExplicitInline</InlineFunctionExpansion> + <IntrinsicFunctions>false</IntrinsicFunctions> + <AdditionalIncludeDirectories>..\..\include;%(AdditionalIncludeDirectories);"$(DXSDK_DIR)\Include";</AdditionalIncludeDirectories> + <PreprocessorDefinitions>NDEBUG;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions> + <StringPooling>true</StringPooling> + <RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary> + <BufferSecurityCheck>false</BufferSecurityCheck> + <FunctionLevelLinking>true</FunctionLevelLinking> + <PrecompiledHeader> + </PrecompiledHeader> + <WarningLevel>Level3</WarningLevel> + <SuppressStartupBanner>true</SuppressStartupBanner> + <CompileAs>Default</CompileAs> + <ExceptionHandling>false</ExceptionHandling> + </ClCompile> + <ResourceCompile> + <PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions> + <Culture>0x0409</Culture> + </ResourceCompile> + <Link> + <AdditionalDependencies>winmm.lib;imm32.lib;version.lib;%(AdditionalDependencies)</AdditionalDependencies> + <IgnoreAllDefaultLibraries>true</IgnoreAllDefaultLibraries> + <SubSystem>Windows</SubSystem> + <AdditionalLibraryDirectories>$(DXSDK_DIR)\lib\x86</AdditionalLibraryDirectories> + <OptimizeReferences>true</OptimizeReferences> + <EnableCOMDATFolding>true</EnableCOMDATFolding> + <GenerateDebugInformation>true</GenerateDebugInformation> + </Link> + </ItemDefinitionGroup> + <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> + <Midl> + <PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions> + <MkTypLibCompatible>true</MkTypLibCompatible> + <SuppressStartupBanner>true</SuppressStartupBanner> + <TargetEnvironment>X64</TargetEnvironment> + </Midl> + <ClCompile> + <InlineFunctionExpansion>OnlyExplicitInline</InlineFunctionExpansion> + <IntrinsicFunctions>false</IntrinsicFunctions> + <AdditionalIncludeDirectories>..\..\include;%(AdditionalIncludeDirectories);"$(DXSDK_DIR)\Include";</AdditionalIncludeDirectories> + <PreprocessorDefinitions>NDEBUG;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions> + <StringPooling>true</StringPooling> + <RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary> + <BufferSecurityCheck>false</BufferSecurityCheck> + <FunctionLevelLinking>true</FunctionLevelLinking> + <PrecompiledHeader> + </PrecompiledHeader> + <WarningLevel>Level3</WarningLevel> + <ExceptionHandling>false</ExceptionHandling> + </ClCompile> + <ResourceCompile> + <PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions> + <Culture>0x0409</Culture> + </ResourceCompile> + <Link> + <AdditionalDependencies>winmm.lib;imm32.lib;version.lib;%(AdditionalDependencies)</AdditionalDependencies> + <IgnoreAllDefaultLibraries>true</IgnoreAllDefaultLibraries> + <SubSystem>Windows</SubSystem> + <AdditionalLibraryDirectories>$(DXSDK_DIR)\lib\x64</AdditionalLibraryDirectories> + <OptimizeReferences>true</OptimizeReferences> + <EnableCOMDATFolding>true</EnableCOMDATFolding> + <GenerateDebugInformation>true</GenerateDebugInformation> + </Link> + </ItemDefinitionGroup> + <ItemGroup> + <ClInclude Include="..\..\include\SDL.h" /> + <ClInclude Include="..\..\include\SDL_assert.h" /> + <ClInclude Include="..\..\include\SDL_atomic.h" /> + <ClInclude Include="..\..\include\SDL_audio.h" /> + <ClInclude Include="..\..\include\SDL_bits.h" /> + <ClInclude Include="..\..\include\SDL_blendmode.h" /> + <ClInclude Include="..\..\include\SDL_clipboard.h" /> + <ClInclude Include="..\..\include\SDL_config.h" /> + <ClInclude Include="..\..\include\SDL_config_windows.h" /> + <ClInclude Include="..\..\include\SDL_copying.h" /> + <ClInclude Include="..\..\include\SDL_cpuinfo.h" /> + <ClInclude Include="..\..\include\SDL_endian.h" /> + <ClInclude Include="..\..\include\SDL_error.h" /> + <ClInclude Include="..\..\include\SDL_events.h" /> + <ClInclude Include="..\..\include\SDL_gesture.h" /> + <ClInclude Include="..\..\include\SDL_haptic.h" /> + <ClInclude Include="..\..\include\SDL_hints.h" /> + <ClInclude Include="..\..\include\SDL_joystick.h" /> + <ClInclude Include="..\..\include\SDL_keyboard.h" /> + <ClInclude Include="..\..\include\SDL_keycode.h" /> + <ClInclude Include="..\..\include\SDL_loadso.h" /> + <ClInclude Include="..\..\include\SDL_log.h" /> + <ClInclude Include="..\..\include\SDL_main.h" /> + <ClInclude Include="..\..\include\SDL_mouse.h" /> + <ClInclude Include="..\..\include\SDL_mutex.h" /> + <ClInclude Include="..\..\include\SDL_name.h" /> + <ClInclude Include="..\..\include\SDL_opengl.h" /> + <ClInclude Include="..\..\include\SDL_opengles.h" /> + <ClInclude Include="..\..\include\SDL_pixels.h" /> + <ClInclude Include="..\..\include\SDL_platform.h" /> + <ClInclude Include="..\..\include\SDL_power.h" /> + <ClInclude Include="..\..\include\SDL_quit.h" /> + <ClInclude Include="..\..\include\SDL_rect.h" /> + <ClInclude Include="..\..\include\SDL_render.h" /> + <ClInclude Include="..\..\include\SDL_revision.h" /> + <ClInclude Include="..\..\include\SDL_rwops.h" /> + <ClInclude Include="..\..\include\SDL_scancode.h" /> + <ClInclude Include="..\..\include\SDL_shape.h" /> + <ClInclude Include="..\..\include\SDL_stdinc.h" /> + <ClInclude Include="..\..\include\SDL_surface.h" /> + <ClInclude Include="..\..\include\SDL_system.h" /> + <ClInclude Include="..\..\include\SDL_syswm.h" /> + <ClInclude Include="..\..\include\SDL_thread.h" /> + <ClInclude Include="..\..\include\SDL_timer.h" /> + <ClInclude Include="..\..\include\SDL_touch.h" /> + <ClInclude Include="..\..\include\SDL_types.h" /> + <ClInclude Include="..\..\include\SDL_version.h" /> + <ClInclude Include="..\..\include\SDL_video.h" /> + <ClInclude Include="..\..\include\SDL_gamecontroller.h" /> + <ClInclude Include="..\..\src\core\windows\SDL_windows.h" /> + <ClInclude Include="..\..\src\events\blank_cursor.h" /> + <ClInclude Include="..\..\src\events\default_cursor.h" /> + <ClInclude Include="..\..\src\audio\directsound\directx.h" /> + <ClInclude Include="..\..\src\events\SDL_clipboardevents_c.h" /> + <ClInclude Include="..\..\src\events\SDL_gesture_c.h" /> + <ClInclude Include="..\..\src\events\SDL_touch_c.h" /> + <ClInclude Include="..\..\src\libm\math.h" /> + <ClInclude Include="..\..\src\libm\math_private.h" /> + <ClInclude Include="..\..\src\render\mmx.h" /> + <ClInclude Include="..\..\src\render\opengl\SDL_shaders_gl.h" /> + <ClInclude Include="..\..\src\render\SDL_sysrender.h" /> + <ClInclude Include="..\..\src\render\SDL_yuv_sw_c.h" /> + <ClInclude Include="..\..\src\audio\SDL_audio_c.h" /> + <ClInclude Include="..\..\src\audio\SDL_audiodev_c.h" /> + <ClInclude Include="..\..\src\audio\SDL_audiomem.h" /> + <ClInclude Include="..\..\src\render\software\SDL_blendfillrect.h" /> + <ClInclude Include="..\..\src\render\software\SDL_blendline.h" /> + <ClInclude Include="..\..\src\render\software\SDL_blendpoint.h" /> + <ClInclude Include="..\..\src\render\software\SDL_draw.h" /> + <ClInclude Include="..\..\src\render\software\SDL_drawline.h" /> + <ClInclude Include="..\..\src\render\software\SDL_drawpoint.h" /> + <ClInclude Include="..\..\src\events\SDL_dropevents_c.h" /> + <ClInclude Include="..\..\src\render\software\SDL_render_sw_c.h" /> + <ClInclude Include="..\..\src\render\software\SDL_rotate.h" /> + <ClInclude Include="..\..\src\video\dummy\SDL_nullframebuffer_c.h" /> + <ClInclude Include="..\..\src\video\SDL_blit.h" /> + <ClInclude Include="..\..\src\video\SDL_blit_auto.h" /> + <ClInclude Include="..\..\src\video\SDL_blit_copy.h" /> + <ClInclude Include="..\..\src\video\SDL_blit_slow.h" /> + <ClInclude Include="..\..\src\video\SDL_shape_internals.h" /> + <ClInclude Include="..\..\src\audio\winmm\SDL_winmm.h" /> + <ClInclude Include="..\..\src\audio\disk\SDL_diskaudio.h" /> + <ClInclude Include="..\..\src\audio\dummy\SDL_dummyaudio.h" /> + <ClInclude Include="..\..\src\audio\directsound\SDL_directsound.h" /> + <ClInclude Include="..\..\src\SDL_error_c.h" /> + <ClInclude Include="..\..\src\SDL_hints_c.h" /> + <ClInclude Include="..\..\src\events\SDL_events_c.h" /> + <ClInclude Include="..\..\src\SDL_fatal.h" /> + <ClInclude Include="..\..\src\video\SDL_glesfuncs.h" /> + <ClInclude Include="..\..\src\video\SDL_glfuncs.h" /> + <ClInclude Include="..\..\src\joystick\SDL_joystick_c.h" /> + <ClInclude Include="..\..\src\events\SDL_keyboard_c.h" /> + <ClInclude Include="..\..\src\events\SDL_mouse_c.h" /> + <ClInclude Include="..\..\src\video\dummy\SDL_nullevents_c.h" /> + <ClInclude Include="..\..\src\video\dummy\SDL_nullvideo.h" /> + <ClInclude Include="..\..\src\video\SDL_pixels_c.h" /> + <ClInclude Include="..\..\src\video\SDL_rect_c.h" /> + <ClInclude Include="..\..\src\video\SDL_RLEaccel_c.h" /> + <ClInclude Include="..\..\src\video\SDL_stretch_c.h" /> + <ClInclude Include="..\..\src\audio\SDL_sysaudio.h" /> + <ClInclude Include="..\..\src\events\SDL_sysevents.h" /> + <ClInclude Include="..\..\src\haptic\SDL_syshaptic.h" /> + <ClInclude Include="..\..\src\joystick\SDL_sysjoystick.h" /> + <ClInclude Include="..\..\src\thread\SDL_systhread.h" /> + <ClInclude Include="..\..\src\thread\windows\SDL_systhread_c.h" /> + <ClInclude Include="..\..\src\timer\SDL_systimer.h" /> + <ClInclude Include="..\..\src\video\SDL_sysvideo.h" /> + <ClInclude Include="..\..\src\thread\SDL_thread_c.h" /> + <ClInclude Include="..\..\src\timer\SDL_timer_c.h" /> + <ClInclude Include="..\..\src\video\windows\SDL_vkeys.h" /> + <ClInclude Include="..\..\src\audio\SDL_wave.h" /> + <ClInclude Include="..\..\src\video\windows\SDL_windowsclipboard.h" /> + <ClInclude Include="..\..\src\video\windows\SDL_windowsevents.h" /> + <ClInclude Include="..\..\src\video\windows\SDL_windowsframebuffer.h" /> + <ClInclude Include="..\..\src\video\windows\SDL_windowskeyboard.h" /> + <ClInclude Include="..\..\src\video\windows\SDL_windowsmessagebox.h" /> + <ClInclude Include="..\..\src\video\windows\SDL_windowsmodes.h" /> + <ClInclude Include="..\..\src\video\windows\SDL_windowsmouse.h" /> + <ClInclude Include="..\..\src\video\windows\SDL_windowsopengl.h" /> + <ClInclude Include="..\..\src\video\windows\SDL_windowsshape.h" /> + <ClInclude Include="..\..\src\video\windows\SDL_windowsvideo.h" /> + <ClInclude Include="..\..\src\video\windows\SDL_windowswindow.h" /> + <ClInclude Include="..\..\src\events\SDL_windowevents_c.h" /> + <ClInclude Include="..\..\src\video\windows\wmmsg.h" /> + <ClInclude Include="resource.h" /> + </ItemGroup> + <ItemGroup> + <ClCompile Include="..\..\src\core\windows\SDL_windows.c" /> + <ClCompile Include="..\..\src\events\SDL_clipboardevents.c" /> + <ClCompile Include="..\..\src\events\SDL_gesture.c" /> + <ClCompile Include="..\..\src\events\SDL_touch.c" /> + <ClCompile Include="..\..\src\libm\e_atan2.c" /> + <ClCompile Include="..\..\src\libm\e_log.c" /> + <ClCompile Include="..\..\src\libm\e_pow.c" /> + <ClCompile Include="..\..\src\libm\e_rem_pio2.c" /> + <ClCompile Include="..\..\src\libm\e_sqrt.c" /> + <ClCompile Include="..\..\src\libm\k_cos.c" /> + <ClCompile Include="..\..\src\libm\k_rem_pio2.c" /> + <ClCompile Include="..\..\src\libm\k_sin.c" /> + <ClCompile Include="..\..\src\libm\s_atan.c" /> + <ClCompile Include="..\..\src\libm\s_copysign.c" /> + <ClCompile Include="..\..\src\libm\s_cos.c" /> + <ClCompile Include="..\..\src\libm\s_fabs.c" /> + <ClCompile Include="..\..\src\libm\s_floor.c" /> + <ClCompile Include="..\..\src\libm\s_scalbn.c" /> + <ClCompile Include="..\..\src\libm\s_sin.c" /> + <ClCompile Include="..\..\src\render\direct3d\SDL_render_d3d.c" /> + <ClCompile Include="..\..\src\render\opengl\SDL_render_gl.c" /> + <ClCompile Include="..\..\src\render\opengl\SDL_shaders_gl.c" /> + <ClCompile Include="..\..\src\render\SDL_render.c" /> + <ClCompile Include="..\..\src\render\SDL_yuv_mmx.c" /> + <ClCompile Include="..\..\src\render\SDL_yuv_sw.c" /> + <ClCompile Include="..\..\src\render\software\SDL_blendfillrect.c" /> + <ClCompile Include="..\..\src\render\software\SDL_blendline.c" /> + <ClCompile Include="..\..\src\render\software\SDL_blendpoint.c" /> + <ClCompile Include="..\..\src\render\software\SDL_drawline.c" /> + <ClCompile Include="..\..\src\render\software\SDL_drawpoint.c" /> + <ClCompile Include="..\..\src\render\software\SDL_render_sw.c" /> + <ClCompile Include="..\..\src\render\software\SDL_rotate.c" /> + <ClCompile Include="..\..\src\SDL.c" /> + <ClCompile Include="..\..\src\SDL_assert.c" /> + <ClCompile Include="..\..\src\atomic\SDL_atomic.c" /> + <ClCompile Include="..\..\src\atomic\SDL_spinlock.c" /> + <ClCompile Include="..\..\src\audio\SDL_audio.c" /> + <ClCompile Include="..\..\src\audio\SDL_audiocvt.c" /> + <ClCompile Include="..\..\src\audio\SDL_audiodev.c" /> + <ClCompile Include="..\..\src\audio\SDL_audiotypecvt.c" /> + <ClCompile Include="..\..\src\SDL_hints.c" /> + <ClCompile Include="..\..\src\SDL_log.c" /> + <ClCompile Include="..\..\src\video\dummy\SDL_nullframebuffer.c" /> + <ClCompile Include="..\..\src\video\SDL_blit.c" /> + <ClCompile Include="..\..\src\video\SDL_blit_0.c" /> + <ClCompile Include="..\..\src\video\SDL_blit_1.c" /> + <ClCompile Include="..\..\src\video\SDL_blit_A.c" /> + <ClCompile Include="..\..\src\video\SDL_blit_auto.c" /> + <ClCompile Include="..\..\src\video\SDL_blit_copy.c" /> + <ClCompile Include="..\..\src\video\SDL_blit_N.c" /> + <ClCompile Include="..\..\src\video\SDL_blit_slow.c" /> + <ClCompile Include="..\..\src\video\SDL_bmp.c" /> + <ClCompile Include="..\..\src\cpuinfo\SDL_cpuinfo.c" /> + <ClCompile Include="..\..\src\video\SDL_clipboard.c" /> + <ClCompile Include="..\..\src\video\SDL_shape.c" /> + <ClCompile Include="..\..\src\audio\winmm\SDL_winmm.c" /> + <ClCompile Include="..\..\src\audio\disk\SDL_diskaudio.c" /> + <ClCompile Include="..\..\src\audio\dummy\SDL_dummyaudio.c" /> + <ClCompile Include="..\..\src\audio\directsound\SDL_directsound.c" /> + <ClCompile Include="..\..\src\events\SDL_dropevents.c" /> + <ClCompile Include="..\..\src\audio\xaudio2\SDL_xaudio2.c" /> + <ClCompile Include="..\..\src\joystick\windows\SDL_dxjoystick.c" /> + <ClCompile Include="..\..\src\SDL_error.c" /> + <ClCompile Include="..\..\src\events\SDL_events.c" /> + <ClCompile Include="..\..\src\SDL_fatal.c" /> + <ClCompile Include="..\..\src\video\SDL_fillrect.c" /> + <ClCompile Include="..\..\src\stdlib\SDL_getenv.c" /> + <ClCompile Include="..\..\src\haptic\SDL_haptic.c" /> + <ClCompile Include="..\..\src\stdlib\SDL_iconv.c" /> + <ClCompile Include="..\..\src\joystick\SDL_joystick.c" /> + <ClCompile Include="..\..\src\events\SDL_keyboard.c" /> + <ClCompile Include="..\..\src\stdlib\SDL_malloc.c" /> + <ClCompile Include="..\..\src\audio\SDL_mixer.c" /> + <ClCompile Include="..\..\src\joystick\windows\SDL_mmjoystick.c" /> + <ClCompile Include="..\..\src\events\SDL_mouse.c" /> + <ClCompile Include="..\..\src\video\dummy\SDL_nullevents.c" /> + <ClCompile Include="..\..\src\video\dummy\SDL_nullvideo.c" /> + <ClCompile Include="..\..\src\video\SDL_pixels.c" /> + <ClCompile Include="..\..\src\power\SDL_power.c" /> + <ClCompile Include="..\..\src\stdlib\SDL_qsort.c" /> + <ClCompile Include="..\..\src\events\SDL_quit.c" /> + <ClCompile Include="..\..\src\video\SDL_rect.c" /> + <ClCompile Include="..\..\src\video\SDL_RLEaccel.c" /> + <ClCompile Include="..\..\src\file\SDL_rwops.c" /> + <ClCompile Include="..\..\src\stdlib\SDL_stdlib.c" /> + <ClCompile Include="..\..\src\video\SDL_stretch.c" /> + <ClCompile Include="..\..\src\stdlib\SDL_string.c" /> + <ClCompile Include="..\..\src\video\SDL_surface.c" /> + <ClCompile Include="..\..\src\thread\generic\SDL_syscond.c" /> + <ClCompile Include="..\..\src\haptic\windows\SDL_syshaptic.c" /> + <ClCompile Include="..\..\src\loadso\windows\SDL_sysloadso.c" /> + <ClCompile Include="..\..\src\thread\windows\SDL_sysmutex.c" /> + <ClCompile Include="..\..\src\power\windows\SDL_syspower.c" /> + <ClCompile Include="..\..\src\thread\windows\SDL_syssem.c" /> + <ClCompile Include="..\..\src\thread\windows\SDL_systhread.c" /> + <ClCompile Include="..\..\src\timer\windows\SDL_systimer.c" /> + <ClCompile Include="..\..\src\thread\SDL_thread.c" /> + <ClCompile Include="..\..\src\timer\SDL_timer.c" /> + <ClCompile Include="..\..\src\video\SDL_video.c" /> + <ClCompile Include="..\..\src\audio\SDL_wave.c" /> + <ClCompile Include="..\..\src\video\windows\SDL_windowsclipboard.c" /> + <ClCompile Include="..\..\src\video\windows\SDL_windowsevents.c" /> + <ClCompile Include="..\..\src\video\windows\SDL_windowsframebuffer.c" /> + <ClCompile Include="..\..\src\video\windows\SDL_windowskeyboard.c" /> + <ClCompile Include="..\..\src\video\windows\SDL_windowsmessagebox.c" /> + <ClCompile Include="..\..\src\video\windows\SDL_windowsmodes.c" /> + <ClCompile Include="..\..\src\video\windows\SDL_windowsmouse.c" /> + <ClCompile Include="..\..\src\video\windows\SDL_windowsopengl.c" /> + <ClCompile Include="..\..\src\video\windows\SDL_windowsshape.c" /> + <ClCompile Include="..\..\src\video\windows\SDL_windowsvideo.c" /> + <ClCompile Include="..\..\src\video\windows\SDL_windowswindow.c" /> + <ClCompile Include="..\..\src\events\SDL_windowevents.c" /> + <ClCompile Include="..\..\src\joystick\SDL_gamecontroller.c" /> + </ItemGroup> + <ItemGroup> + <ResourceCompile Include="..\..\src\main\windows\version.rc" /> + </ItemGroup> + <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> + <ImportGroup Label="ExtensionTargets"> + </ImportGroup> +</Project>
\ No newline at end of file diff --git a/VisualC/SDL_VS2010.sln b/VisualC/SDL_VS2010.sln index f11f437b44..5b95292abb 100644 --- a/VisualC/SDL_VS2010.sln +++ b/VisualC/SDL_VS2010.sln @@ -1,197 +1,160 @@ - -Microsoft Visual Studio Solution File, Format Version 11.00 -# Visual Studio 2010 -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "SDL2", "SDL\SDL_VS2010.vcxproj", "{81CE8DAF-EBB2-4761-8E45-B71ABCCA8C68}" -EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "SDL2main", "SDLmain\SDLmain_VS2010.vcxproj", "{DA956FD3-E142-46F2-9DD5-C78BEBB56B7A}" -EndProject -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{CE748C1F-3C21-4825-AA6A-F895A023F7E7}" -EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "loopwave", "tests\loopwave\loopwave_VS2010.vcxproj", "{AAAD1CB5-7ADA-47AE-85A0-08A6EC48FAFB}" - ProjectSection(ProjectDependencies) = postProject - {81CE8DAF-EBB2-4761-8E45-B71ABCCA8C68} = {81CE8DAF-EBB2-4761-8E45-B71ABCCA8C68} - {DA956FD3-E142-46F2-9DD5-C78BEBB56B7A} = {DA956FD3-E142-46F2-9DD5-C78BEBB56B7A} - EndProjectSection -EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "testplatform", "tests\testplatform\testplatform_VS2010.vcxproj", "{26932B24-EFC6-4E3A-B277-ED653DA37968}" - ProjectSection(ProjectDependencies) = postProject - {81CE8DAF-EBB2-4761-8E45-B71ABCCA8C68} = {81CE8DAF-EBB2-4761-8E45-B71ABCCA8C68} - {DA956FD3-E142-46F2-9DD5-C78BEBB56B7A} = {DA956FD3-E142-46F2-9DD5-C78BEBB56B7A} - EndProjectSection -EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "testfile", "tests\testfile\testfile_VS2010.vcxproj", "{CAE4F1D0-314F-4B10-805B-0EFD670133A0}" - ProjectSection(ProjectDependencies) = postProject - {81CE8DAF-EBB2-4761-8E45-B71ABCCA8C68} = {81CE8DAF-EBB2-4761-8E45-B71ABCCA8C68} - {DA956FD3-E142-46F2-9DD5-C78BEBB56B7A} = {DA956FD3-E142-46F2-9DD5-C78BEBB56B7A} - EndProjectSection -EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "testgl2", "tests\testgl2\testgl2_VS2010.vcxproj", "{8B5CFB38-CCBA-40A8-AD7A-89C57B070884}" - ProjectSection(ProjectDependencies) = postProject - {81CE8DAF-EBB2-4761-8E45-B71ABCCA8C68} = {81CE8DAF-EBB2-4761-8E45-B71ABCCA8C68} - {DA956FD3-E142-46F2-9DD5-C78BEBB56B7A} = {DA956FD3-E142-46F2-9DD5-C78BEBB56B7A} - {DA956FD3-E143-46F2-9FE5-C77BEBC56B1A} = {DA956FD3-E143-46F2-9FE5-C77BEBC56B1A} - EndProjectSection -EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "checkkeys", "tests\checkkeys\checkkeys_VS2010.vcxproj", "{26828762-C95D-4637-9CB1-7F0979523813}" - ProjectSection(ProjectDependencies) = postProject - {81CE8DAF-EBB2-4761-8E45-B71ABCCA8C68} = {81CE8DAF-EBB2-4761-8E45-B71ABCCA8C68} - {DA956FD3-E142-46F2-9DD5-C78BEBB56B7A} = {DA956FD3-E142-46F2-9DD5-C78BEBB56B7A} - EndProjectSection -EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "testsprite2", "tests\testsprite2\testsprite2_VS2010.vcxproj", "{40FB7794-D3C3-4CFE-BCF4-A80C96635682}" - ProjectSection(ProjectDependencies) = postProject - {81CE8DAF-EBB2-4761-8E45-B71ABCCA8C68} = {81CE8DAF-EBB2-4761-8E45-B71ABCCA8C68} - {DA956FD3-E142-46F2-9DD5-C78BEBB56B7A} = {DA956FD3-E142-46F2-9DD5-C78BEBB56B7A} - {DA956FD3-E143-46F2-9FE5-C77BEBC56B1A} = {DA956FD3-E143-46F2-9FE5-C77BEBC56B1A} - EndProjectSection -EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "testshape", "tests\testshape\testshape_VS2010.vcxproj", "{EDEA9D00-AF64-45DE-8F60-5957048F2F0F}" - ProjectSection(ProjectDependencies) = postProject - {81CE8DAF-EBB2-4761-8E45-B71ABCCA8C68} = {81CE8DAF-EBB2-4761-8E45-B71ABCCA8C68} - {DA956FD3-E142-46F2-9DD5-C78BEBB56B7A} = {DA956FD3-E142-46F2-9DD5-C78BEBB56B7A} - EndProjectSection -EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "testdraw2", "tests\testdraw2\testdraw2_VS2010.vcxproj", "{8682FE1E-0CF6-4EDD-9BB5-1733D8C8B4DF}" - ProjectSection(ProjectDependencies) = postProject - {81CE8DAF-EBB2-4761-8E45-B71ABCCA8C68} = {81CE8DAF-EBB2-4761-8E45-B71ABCCA8C68} - {DA956FD3-E142-46F2-9DD5-C78BEBB56B7A} = {DA956FD3-E142-46F2-9DD5-C78BEBB56B7A} - {DA956FD3-E143-46F2-9FE5-C77BEBC56B1A} = {DA956FD3-E143-46F2-9FE5-C77BEBC56B1A} - EndProjectSection -EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "testpower", "tests\testpower\testpower_VS2010.vcxproj", "{C4E04D18-EF76-4B42-B4C2-16A1BACDC0A3}" - ProjectSection(ProjectDependencies) = postProject - {81CE8DAF-EBB2-4761-8E45-B71ABCCA8C68} = {81CE8DAF-EBB2-4761-8E45-B71ABCCA8C68} - {DA956FD3-E142-46F2-9DD5-C78BEBB56B7A} = {DA956FD3-E142-46F2-9DD5-C78BEBB56B7A} - EndProjectSection -EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "SDL2test", "SDLtest\SDLtest_VS2010.vcxproj", "{DA956FD3-E143-46F2-9FE5-C77BEBC56B1A}" - ProjectSection(ProjectDependencies) = postProject - {81CE8DAF-EBB2-4761-8E45-B71ABCCA8C68} = {81CE8DAF-EBB2-4761-8E45-B71ABCCA8C68} - EndProjectSection -EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "testautomation", "tests\testautomation\testautomation_vs2010.vcxproj", "{FEE710DB-EC7B-4CCB-BD75-535D401A2FE0}" - ProjectSection(ProjectDependencies) = postProject - {81CE8DAF-EBB2-4761-8E45-B71ABCCA8C68} = {81CE8DAF-EBB2-4761-8E45-B71ABCCA8C68} - {DA956FD3-E142-46F2-9DD5-C78BEBB56B7A} = {DA956FD3-E142-46F2-9DD5-C78BEBB56B7A} - {DA956FD3-E143-46F2-9FE5-C77BEBC56B1A} = {DA956FD3-E143-46F2-9FE5-C77BEBC56B1A} - EndProjectSection -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|Win32 = Debug|Win32 - Debug|x64 = Debug|x64 - Release|Win32 = Release|Win32 - Release|x64 = Release|x64 - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {81CE8DAF-EBB2-4761-8E45-B71ABCCA8C68}.Debug|Win32.ActiveCfg = Debug|Win32 - {81CE8DAF-EBB2-4761-8E45-B71ABCCA8C68}.Debug|Win32.Build.0 = Debug|Win32 - {81CE8DAF-EBB2-4761-8E45-B71ABCCA8C68}.Debug|x64.ActiveCfg = Debug|x64 - {81CE8DAF-EBB2-4761-8E45-B71ABCCA8C68}.Debug|x64.Build.0 = Debug|x64 - {81CE8DAF-EBB2-4761-8E45-B71ABCCA8C68}.Release|Win32.ActiveCfg = Release|Win32 - {81CE8DAF-EBB2-4761-8E45-B71ABCCA8C68}.Release|Win32.Build.0 = Release|Win32 - {81CE8DAF-EBB2-4761-8E45-B71ABCCA8C68}.Release|x64.ActiveCfg = Release|x64 - {81CE8DAF-EBB2-4761-8E45-B71ABCCA8C68}.Release|x64.Build.0 = Release|x64 - {DA956FD3-E142-46F2-9DD5-C78BEBB56B7A}.Debug|Win32.ActiveCfg = Debug|Win32 - {DA956FD3-E142-46F2-9DD5-C78BEBB56B7A}.Debug|Win32.Build.0 = Debug|Win32 - {DA956FD3-E142-46F2-9DD5-C78BEBB56B7A}.Debug|x64.ActiveCfg = Debug|x64 - {DA956FD3-E142-46F2-9DD5-C78BEBB56B7A}.Debug|x64.Build.0 = Debug|x64 - {DA956FD3-E142-46F2-9DD5-C78BEBB56B7A}.Release|Win32.ActiveCfg = Release|Win32 - {DA956FD3-E142-46F2-9DD5-C78BEBB56B7A}.Release|Win32.Build.0 = Release|Win32 - {DA956FD3-E142-46F2-9DD5-C78BEBB56B7A}.Release|x64.ActiveCfg = Release|x64 - {DA956FD3-E142-46F2-9DD5-C78BEBB56B7A}.Release|x64.Build.0 = Release|x64 - {AAAD1CB5-7ADA-47AE-85A0-08A6EC48FAFB}.Debug|Win32.ActiveCfg = Debug|Win32 - {AAAD1CB5-7ADA-47AE-85A0-08A6EC48FAFB}.Debug|Win32.Build.0 = Debug|Win32 - {AAAD1CB5-7ADA-47AE-85A0-08A6EC48FAFB}.Debug|x64.ActiveCfg = Debug|x64 - {AAAD1CB5-7ADA-47AE-85A0-08A6EC48FAFB}.Debug|x64.Build.0 = Debug|x64 - {AAAD1CB5-7ADA-47AE-85A0-08A6EC48FAFB}.Release|Win32.ActiveCfg = Release|Win32 - {AAAD1CB5-7ADA-47AE-85A0-08A6EC48FAFB}.Release|Win32.Build.0 = Release|Win32 - {AAAD1CB5-7ADA-47AE-85A0-08A6EC48FAFB}.Release|x64.ActiveCfg = Release|Win32 - {26932B24-EFC6-4E3A-B277-ED653DA37968}.Debug|Win32.ActiveCfg = Debug|Win32 - {26932B24-EFC6-4E3A-B277-ED653DA37968}.Debug|Win32.Build.0 = Debug|Win32 - {26932B24-EFC6-4E3A-B277-ED653DA37968}.Debug|x64.ActiveCfg = Debug|x64 - {26932B24-EFC6-4E3A-B277-ED653DA37968}.Debug|x64.Build.0 = Debug|x64 - {26932B24-EFC6-4E3A-B277-ED653DA37968}.Release|Win32.ActiveCfg = Release|Win32 - {26932B24-EFC6-4E3A-B277-ED653DA37968}.Release|Win32.Build.0 = Release|Win32 - {26932B24-EFC6-4E3A-B277-ED653DA37968}.Release|x64.ActiveCfg = Release|Win32 - {CAE4F1D0-314F-4B10-805B-0EFD670133A0}.Debug|Win32.ActiveCfg = Debug|Win32 - {CAE4F1D0-314F-4B10-805B-0EFD670133A0}.Debug|Win32.Build.0 = Debug|Win32 - {CAE4F1D0-314F-4B10-805B-0EFD670133A0}.Debug|x64.ActiveCfg = Debug|x64 - {CAE4F1D0-314F-4B10-805B-0EFD670133A0}.Debug|x64.Build.0 = Debug|x64 - {CAE4F1D0-314F-4B10-805B-0EFD670133A0}.Release|Win32.ActiveCfg = Release|Win32 - {CAE4F1D0-314F-4B10-805B-0EFD670133A0}.Release|Win32.Build.0 = Release|Win32 - {CAE4F1D0-314F-4B10-805B-0EFD670133A0}.Release|x64.ActiveCfg = Release|Win32 - {8B5CFB38-CCBA-40A8-AD7A-89C57B070884}.Debug|Win32.ActiveCfg = Debug|Win32 - {8B5CFB38-CCBA-40A8-AD7A-89C57B070884}.Debug|Win32.Build.0 = Debug|Win32 - {8B5CFB38-CCBA-40A8-AD7A-89C57B070884}.Debug|x64.ActiveCfg = Debug|x64 - {8B5CFB38-CCBA-40A8-AD7A-89C57B070884}.Debug|x64.Build.0 = Debug|x64 - {8B5CFB38-CCBA-40A8-AD7A-89C57B070884}.Release|Win32.ActiveCfg = Release|Win32 - {8B5CFB38-CCBA-40A8-AD7A-89C57B070884}.Release|Win32.Build.0 = Release|Win32 - {8B5CFB38-CCBA-40A8-AD7A-89C57B070884}.Release|x64.ActiveCfg = Release|Win32 - {26828762-C95D-4637-9CB1-7F0979523813}.Debug|Win32.ActiveCfg = Debug|Win32 - {26828762-C95D-4637-9CB1-7F0979523813}.Debug|Win32.Build.0 = Debug|Win32 - {26828762-C95D-4637-9CB1-7F0979523813}.Debug|x64.ActiveCfg = Debug|x64 - {26828762-C95D-4637-9CB1-7F0979523813}.Debug|x64.Build.0 = Debug|x64 - {26828762-C95D-4637-9CB1-7F0979523813}.Release|Win32.ActiveCfg = Release|Win32 - {26828762-C95D-4637-9CB1-7F0979523813}.Release|Win32.Build.0 = Release|Win32 - {26828762-C95D-4637-9CB1-7F0979523813}.Release|x64.ActiveCfg = Release|Win32 - {40FB7794-D3C3-4CFE-BCF4-A80C96635682}.Debug|Win32.ActiveCfg = Debug|Win32 - {40FB7794-D3C3-4CFE-BCF4-A80C96635682}.Debug|Win32.Build.0 = Debug|Win32 - {40FB7794-D3C3-4CFE-BCF4-A80C96635682}.Debug|x64.ActiveCfg = Debug|x64 - {40FB7794-D3C3-4CFE-BCF4-A80C96635682}.Debug|x64.Build.0 = Debug|x64 - {40FB7794-D3C3-4CFE-BCF4-A80C96635682}.Release|Win32.ActiveCfg = Release|Win32 - {40FB7794-D3C3-4CFE-BCF4-A80C96635682}.Release|Win32.Build.0 = Release|Win32 - {40FB7794-D3C3-4CFE-BCF4-A80C96635682}.Release|x64.ActiveCfg = Release|Win32 - {EDEA9D00-AF64-45DE-8F60-5957048F2F0F}.Debug|Win32.ActiveCfg = Debug|Win32 - {EDEA9D00-AF64-45DE-8F60-5957048F2F0F}.Debug|Win32.Build.0 = Debug|Win32 - {EDEA9D00-AF64-45DE-8F60-5957048F2F0F}.Debug|x64.ActiveCfg = Debug|x64 - {EDEA9D00-AF64-45DE-8F60-5957048F2F0F}.Debug|x64.Build.0 = Debug|x64 - {EDEA9D00-AF64-45DE-8F60-5957048F2F0F}.Release|Win32.ActiveCfg = Release|Win32 - {EDEA9D00-AF64-45DE-8F60-5957048F2F0F}.Release|x64.ActiveCfg = Release|Win32 - {8682FE1E-0CF6-4EDD-9BB5-1733D8C8B4DF}.Debug|Win32.ActiveCfg = Debug|Win32 - {8682FE1E-0CF6-4EDD-9BB5-1733D8C8B4DF}.Debug|Win32.Build.0 = Debug|Win32 - {8682FE1E-0CF6-4EDD-9BB5-1733D8C8B4DF}.Debug|x64.ActiveCfg = Debug|x64 - {8682FE1E-0CF6-4EDD-9BB5-1733D8C8B4DF}.Debug|x64.Build.0 = Debug|x64 - {8682FE1E-0CF6-4EDD-9BB5-1733D8C8B4DF}.Release|Win32.ActiveCfg = Release|Win32 - {8682FE1E-0CF6-4EDD-9BB5-1733D8C8B4DF}.Release|Win32.Build.0 = Release|Win32 - {8682FE1E-0CF6-4EDD-9BB5-1733D8C8B4DF}.Release|x64.ActiveCfg = Release|Win32 - {C4E04D18-EF76-4B42-B4C2-16A1BACDC0A3}.Debug|Win32.ActiveCfg = Debug|Win32 - {C4E04D18-EF76-4B42-B4C2-16A1BACDC0A3}.Debug|Win32.Build.0 = Debug|Win32 - {C4E04D18-EF76-4B42-B4C2-16A1BACDC0A3}.Debug|x64.ActiveCfg = Debug|x64 - {C4E04D18-EF76-4B42-B4C2-16A1BACDC0A3}.Debug|x64.Build.0 = Debug|x64 - {C4E04D18-EF76-4B42-B4C2-16A1BACDC0A3}.Release|Win32.ActiveCfg = Release|Win32 - {C4E04D18-EF76-4B42-B4C2-16A1BACDC0A3}.Release|Win32.Build.0 = Release|Win32 - {C4E04D18-EF76-4B42-B4C2-16A1BACDC0A3}.Release|x64.ActiveCfg = Release|Win32 - {DA956FD3-E143-46F2-9FE5-C77BEBC56B1A}.Debug|Win32.ActiveCfg = Debug|Win32 - {DA956FD3-E143-46F2-9FE5-C77BEBC56B1A}.Debug|Win32.Build.0 = Debug|Win32 - {DA956FD3-E143-46F2-9FE5-C77BEBC56B1A}.Debug|x64.ActiveCfg = Debug|x64 - {DA956FD3-E143-46F2-9FE5-C77BEBC56B1A}.Debug|x64.Build.0 = Debug|x64 - {DA956FD3-E143-46F2-9FE5-C77BEBC56B1A}.Release|Win32.ActiveCfg = Release|Win32 - {DA956FD3-E143-46F2-9FE5-C77BEBC56B1A}.Release|Win32.Build.0 = Release|Win32 - {DA956FD3-E143-46F2-9FE5-C77BEBC56B1A}.Release|x64.ActiveCfg = Release|x64 - {DA956FD3-E143-46F2-9FE5-C77BEBC56B1A}.Release|x64.Build.0 = Release|x64 - {FEE710DB-EC7B-4CCB-BD75-535D401A2FE0}.Debug|Win32.ActiveCfg = Debug|Win32 - {FEE710DB-EC7B-4CCB-BD75-535D401A2FE0}.Debug|Win32.Build.0 = Debug|Win32 - {FEE710DB-EC7B-4CCB-BD75-535D401A2FE0}.Debug|x64.ActiveCfg = Debug|x64 - {FEE710DB-EC7B-4CCB-BD75-535D401A2FE0}.Debug|x64.Build.0 = Debug|x64 - {FEE710DB-EC7B-4CCB-BD75-535D401A2FE0}.Release|Win32.ActiveCfg = Release|Win32 - {FEE710DB-EC7B-4CCB-BD75-535D401A2FE0}.Release|Win32.Build.0 = Release|Win32 - {FEE710DB-EC7B-4CCB-BD75-535D401A2FE0}.Release|x64.ActiveCfg = Release|x64 - {FEE710DB-EC7B-4CCB-BD75-535D401A2FE0}.Release|x64.Build.0 = Release|x64 - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection - GlobalSection(NestedProjects) = preSolution - {AAAD1CB5-7ADA-47AE-85A0-08A6EC48FAFB} = {CE748C1F-3C21-4825-AA6A-F895A023F7E7} - {26932B24-EFC6-4E3A-B277-ED653DA37968} = {CE748C1F-3C21-4825-AA6A-F895A023F7E7} - {CAE4F1D0-314F-4B10-805B-0EFD670133A0} = {CE748C1F-3C21-4825-AA6A-F895A023F7E7} - {8B5CFB38-CCBA-40A8-AD7A-89C57B070884} = {CE748C1F-3C21-4825-AA6A-F895A023F7E7} - {26828762-C95D-4637-9CB1-7F0979523813} = {CE748C1F-3C21-4825-AA6A-F895A023F7E7} - {40FB7794-D3C3-4CFE-BCF4-A80C96635682} = {CE748C1F-3C21-4825-AA6A-F895A023F7E7} - {EDEA9D00-AF64-45DE-8F60-5957048F2F0F} = {CE748C1F-3C21-4825-AA6A-F895A023F7E7} - {8682FE1E-0CF6-4EDD-9BB5-1733D8C8B4DF} = {CE748C1F-3C21-4825-AA6A-F895A023F7E7} - {C4E04D18-EF76-4B42-B4C2-16A1BACDC0A3} = {CE748C1F-3C21-4825-AA6A-F895A023F7E7} - {FEE710DB-EC7B-4CCB-BD75-535D401A2FE0} = {CE748C1F-3C21-4825-AA6A-F895A023F7E7} - EndGlobalSection -EndGlobal +
+Microsoft Visual Studio Solution File, Format Version 11.00
+# Visual Studio 2010
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "SDL2", "SDL\SDL_VS2010.vcxproj", "{81CE8DAF-EBB2-4761-8E45-B71ABCCA8C68}"
+EndProject
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "SDL2main", "SDLmain\SDLmain_VS2010.vcxproj", "{DA956FD3-E142-46F2-9DD5-C78BEBB56B7A}"
+EndProject
+Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{CE748C1F-3C21-4825-AA6A-F895A023F7E7}"
+EndProject
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "loopwave", "tests\loopwave\loopwave_VS2010.vcxproj", "{AAAD1CB5-7ADA-47AE-85A0-08A6EC48FAFB}"
+EndProject
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "testplatform", "tests\testplatform\testplatform_VS2010.vcxproj", "{26932B24-EFC6-4E3A-B277-ED653DA37968}"
+EndProject
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "testfile", "tests\testfile\testfile_VS2010.vcxproj", "{CAE4F1D0-314F-4B10-805B-0EFD670133A0}"
+EndProject
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "testgl2", "tests\testgl2\testgl2_VS2010.vcxproj", "{8B5CFB38-CCBA-40A8-AD7A-89C57B070884}"
+EndProject
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "checkkeys", "tests\checkkeys\checkkeys_VS2010.vcxproj", "{26828762-C95D-4637-9CB1-7F0979523813}"
+EndProject
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "testsprite2", "tests\testsprite2\testsprite2_VS2010.vcxproj", "{40FB7794-D3C3-4CFE-BCF4-A80C96635682}"
+EndProject
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "testshape", "tests\testshape\testshape_VS2010.vcxproj", "{EDEA9D00-AF64-45DE-8F60-5957048F2F0F}"
+EndProject
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "testdraw2", "tests\testdraw2\testdraw2_VS2010.vcxproj", "{8682FE1E-0CF6-4EDD-9BB5-1733D8C8B4DF}"
+EndProject
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "testpower", "tests\testpower\testpower_VS2010.vcxproj", "{C4E04D18-EF76-4B42-B4C2-16A1BACDC0A3}"
+EndProject
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "SDL2test", "SDLtest\SDLtest_VS2010.vcxproj", "{DA956FD3-E143-46F2-9FE5-C77BEBC56B1A}"
+EndProject
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "testautomation", "tests\testautomation\testautomation_vs2010.vcxproj", "{FEE710DB-EC7B-4CCB-BD75-535D401A2FE0}"
+EndProject
+Global
+ GlobalSection(SolutionConfigurationPlatforms) = preSolution
+ Debug|Win32 = Debug|Win32
+ Debug|x64 = Debug|x64
+ Release|Win32 = Release|Win32
+ Release|x64 = Release|x64
+ EndGlobalSection
+ GlobalSection(ProjectConfigurationPlatforms) = postSolution
+ {81CE8DAF-EBB2-4761-8E45-B71ABCCA8C68}.Debug|Win32.ActiveCfg = Debug|Win32
+ {81CE8DAF-EBB2-4761-8E45-B71ABCCA8C68}.Debug|Win32.Build.0 = Debug|Win32
+ {81CE8DAF-EBB2-4761-8E45-B71ABCCA8C68}.Debug|x64.ActiveCfg = Debug|x64
+ {81CE8DAF-EBB2-4761-8E45-B71ABCCA8C68}.Debug|x64.Build.0 = Debug|x64
+ {81CE8DAF-EBB2-4761-8E45-B71ABCCA8C68}.Release|Win32.ActiveCfg = Release|Win32
+ {81CE8DAF-EBB2-4761-8E45-B71ABCCA8C68}.Release|Win32.Build.0 = Release|Win32
+ {81CE8DAF-EBB2-4761-8E45-B71ABCCA8C68}.Release|x64.ActiveCfg = Release|x64
+ {81CE8DAF-EBB2-4761-8E45-B71ABCCA8C68}.Release|x64.Build.0 = Release|x64
+ {DA956FD3-E142-46F2-9DD5-C78BEBB56B7A}.Debug|Win32.ActiveCfg = Debug|Win32
+ {DA956FD3-E142-46F2-9DD5-C78BEBB56B7A}.Debug|Win32.Build.0 = Debug|Win32
+ {DA956FD3-E142-46F2-9DD5-C78BEBB56B7A}.Debug|x64.ActiveCfg = Debug|x64
+ {DA956FD3-E142-46F2-9DD5-C78BEBB56B7A}.Debug|x64.Build.0 = Debug|x64
+ {DA956FD3-E142-46F2-9DD5-C78BEBB56B7A}.Release|Win32.ActiveCfg = Release|Win32
+ {DA956FD3-E142-46F2-9DD5-C78BEBB56B7A}.Release|Win32.Build.0 = Release|Win32
+ {DA956FD3-E142-46F2-9DD5-C78BEBB56B7A}.Release|x64.ActiveCfg = Release|x64
+ {DA956FD3-E142-46F2-9DD5-C78BEBB56B7A}.Release|x64.Build.0 = Release|x64
+ {AAAD1CB5-7ADA-47AE-85A0-08A6EC48FAFB}.Debug|Win32.ActiveCfg = Debug|Win32
+ {AAAD1CB5-7ADA-47AE-85A0-08A6EC48FAFB}.Debug|Win32.Build.0 = Debug|Win32
+ {AAAD1CB5-7ADA-47AE-85A0-08A6EC48FAFB}.Debug|x64.ActiveCfg = Debug|x64
+ {AAAD1CB5-7ADA-47AE-85A0-08A6EC48FAFB}.Debug|x64.Build.0 = Debug|x64
+ {AAAD1CB5-7ADA-47AE-85A0-08A6EC48FAFB}.Release|Win32.ActiveCfg = Release|Win32
+ {AAAD1CB5-7ADA-47AE-85A0-08A6EC48FAFB}.Release|Win32.Build.0 = Release|Win32
+ {AAAD1CB5-7ADA-47AE-85A0-08A6EC48FAFB}.Release|x64.ActiveCfg = Release|x64
+ {AAAD1CB5-7ADA-47AE-85A0-08A6EC48FAFB}.Release|x64.Build.0 = Release|x64
+ {26932B24-EFC6-4E3A-B277-ED653DA37968}.Debug|Win32.ActiveCfg = Debug|Win32
+ {26932B24-EFC6-4E3A-B277-ED653DA37968}.Debug|Win32.Build.0 = Debug|Win32
+ {26932B24-EFC6-4E3A-B277-ED653DA37968}.Debug|x64.ActiveCfg = Debug|x64
+ {26932B24-EFC6-4E3A-B277-ED653DA37968}.Debug|x64.Build.0 = Debug|x64
+ {26932B24-EFC6-4E3A-B277-ED653DA37968}.Release|Win32.ActiveCfg = Release|Win32
+ {26932B24-EFC6-4E3A-B277-ED653DA37968}.Release|Win32.Build.0 = Release|Win32
+ {26932B24-EFC6-4E3A-B277-ED653DA37968}.Release|x64.ActiveCfg = Release|x64
+ {26932B24-EFC6-4E3A-B277-ED653DA37968}.Release|x64.Build.0 = Release|x64
+ {CAE4F1D0-314F-4B10-805B-0EFD670133A0}.Debug|Win32.ActiveCfg = Debug|Win32
+ {CAE4F1D0-314F-4B10-805B-0EFD670133A0}.Debug|Win32.Build.0 = Debug|Win32
+ {CAE4F1D0-314F-4B10-805B-0EFD670133A0}.Debug|x64.ActiveCfg = Debug|x64
+ {CAE4F1D0-314F-4B10-805B-0EFD670133A0}.Debug|x64.Build.0 = Debug|x64
+ {CAE4F1D0-314F-4B10-805B-0EFD670133A0}.Release|Win32.ActiveCfg = Release|Win32
+ {CAE4F1D0-314F-4B10-805B-0EFD670133A0}.Release|Win32.Build.0 = Release|Win32
+ {CAE4F1D0-314F-4B10-805B-0EFD670133A0}.Release|x64.ActiveCfg = Release|x64
+ {CAE4F1D0-314F-4B10-805B-0EFD670133A0}.Release|x64.Build.0 = Release|x64
+ {8B5CFB38-CCBA-40A8-AD7A-89C57B070884}.Debug|Win32.ActiveCfg = Debug|Win32
+ {8B5CFB38-CCBA-40A8-AD7A-89C57B070884}.Debug|Win32.Build.0 = Debug|Win32
+ {8B5CFB38-CCBA-40A8-AD7A-89C57B070884}.Debug|x64.ActiveCfg = Debug|x64
+ {8B5CFB38-CCBA-40A8-AD7A-89C57B070884}.Debug|x64.Build.0 = Debug|x64
+ {8B5CFB38-CCBA-40A8-AD7A-89C57B070884}.Release|Win32.ActiveCfg = Release|Win32
+ {8B5CFB38-CCBA-40A8-AD7A-89C57B070884}.Release|Win32.Build.0 = Release|Win32
+ {8B5CFB38-CCBA-40A8-AD7A-89C57B070884}.Release|x64.ActiveCfg = Release|x64
+ {8B5CFB38-CCBA-40A8-AD7A-89C57B070884}.Release|x64.Build.0 = Release|x64
+ {26828762-C95D-4637-9CB1-7F0979523813}.Debug|Win32.ActiveCfg = Debug|Win32
+ {26828762-C95D-4637-9CB1-7F0979523813}.Debug|Win32.Build.0 = Debug|Win32
+ {26828762-C95D-4637-9CB1-7F0979523813}.Debug|x64.ActiveCfg = Debug|x64
+ {26828762-C95D-4637-9CB1-7F0979523813}.Debug|x64.Build.0 = Debug|x64
+ {26828762-C95D-4637-9CB1-7F0979523813}.Release|Win32.ActiveCfg = Release|Win32
+ {26828762-C95D-4637-9CB1-7F0979523813}.Release|Win32.Build.0 = Release|Win32
+ {26828762-C95D-4637-9CB1-7F0979523813}.Release|x64.ActiveCfg = Release|x64
+ {26828762-C95D-4637-9CB1-7F0979523813}.Release|x64.Build.0 = Release|x64
+ {40FB7794-D3C3-4CFE-BCF4-A80C96635682}.Debug|Win32.ActiveCfg = Debug|Win32
+ {40FB7794-D3C3-4CFE-BCF4-A80C96635682}.Debug|Win32.Build.0 = Debug|Win32
+ {40FB7794-D3C3-4CFE-BCF4-A80C96635682}.Debug|x64.ActiveCfg = Debug|x64
+ {40FB7794-D3C3-4CFE-BCF4-A80C96635682}.Debug|x64.Build.0 = Debug|x64
+ {40FB7794-D3C3-4CFE-BCF4-A80C96635682}.Release|Win32.ActiveCfg = Release|Win32
+ {40FB7794-D3C3-4CFE-BCF4-A80C96635682}.Release|Win32.Build.0 = Release|Win32
+ {40FB7794-D3C3-4CFE-BCF4-A80C96635682}.Release|x64.ActiveCfg = Release|x64
+ {40FB7794-D3C3-4CFE-BCF4-A80C96635682}.Release|x64.Build.0 = Release|x64
+ {EDEA9D00-AF64-45DE-8F60-5957048F2F0F}.Debug|Win32.ActiveCfg = Debug|Win32
+ {EDEA9D00-AF64-45DE-8F60-5957048F2F0F}.Debug|Win32.Build.0 = Debug|Win32
+ {EDEA9D00-AF64-45DE-8F60-5957048F2F0F}.Debug|x64.ActiveCfg = Debug|x64
+ {EDEA9D00-AF64-45DE-8F60-5957048F2F0F}.Debug|x64.Build.0 = Debug|x64
+ {EDEA9D00-AF64-45DE-8F60-5957048F2F0F}.Release|Win32.ActiveCfg = Release|Win32
+ {EDEA9D00-AF64-45DE-8F60-5957048F2F0F}.Release|Win32.Build.0 = Release|Win32
+ {EDEA9D00-AF64-45DE-8F60-5957048F2F0F}.Release|x64.ActiveCfg = Release|x64
+ {EDEA9D00-AF64-45DE-8F60-5957048F2F0F}.Release|x64.Build.0 = Release|x64
+ {8682FE1E-0CF6-4EDD-9BB5-1733D8C8B4DF}.Debug|Win32.ActiveCfg = Debug|Win32
+ {8682FE1E-0CF6-4EDD-9BB5-1733D8C8B4DF}.Debug|Win32.Build.0 = Debug|Win32
+ {8682FE1E-0CF6-4EDD-9BB5-1733D8C8B4DF}.Debug|x64.ActiveCfg = Debug|x64
+ {8682FE1E-0CF6-4EDD-9BB5-1733D8C8B4DF}.Debug|x64.Build.0 = Debug|x64
+ {8682FE1E-0CF6-4EDD-9BB5-1733D8C8B4DF}.Release|Win32.ActiveCfg = Release|Win32
+ {8682FE1E-0CF6-4EDD-9BB5-1733D8C8B4DF}.Release|Win32.Build.0 = Release|Win32
+ {8682FE1E-0CF6-4EDD-9BB5-1733D8C8B4DF}.Release|x64.ActiveCfg = Release|x64
+ {8682FE1E-0CF6-4EDD-9BB5-1733D8C8B4DF}.Release|x64.Build.0 = Release|x64
+ {C4E04D18-EF76-4B42-B4C2-16A1BACDC0A3}.Debug|Win32.ActiveCfg = Debug|Win32
+ {C4E04D18-EF76-4B42-B4C2-16A1BACDC0A3}.Debug|Win32.Build.0 = Debug|Win32
+ {C4E04D18-EF76-4B42-B4C2-16A1BACDC0A3}.Debug|x64.ActiveCfg = Debug|x64
+ {C4E04D18-EF76-4B42-B4C2-16A1BACDC0A3}.Debug|x64.Build.0 = Debug|x64
+ {C4E04D18-EF76-4B42-B4C2-16A1BACDC0A3}.Release|Win32.ActiveCfg = Release|Win32
+ {C4E04D18-EF76-4B42-B4C2-16A1BACDC0A3}.Release|Win32.Build.0 = Release|Win32
+ {C4E04D18-EF76-4B42-B4C2-16A1BACDC0A3}.Release|x64.ActiveCfg = Release|x64
+ {C4E04D18-EF76-4B42-B4C2-16A1BACDC0A3}.Release|x64.Build.0 = Release|x64
+ {DA956FD3-E143-46F2-9FE5-C77BEBC56B1A}.Debug|Win32.ActiveCfg = Debug|Win32
+ {DA956FD3-E143-46F2-9FE5-C77BEBC56B1A}.Debug|Win32.Build.0 = Debug|Win32
+ {DA956FD3-E143-46F2-9FE5-C77BEBC56B1A}.Debug|x64.ActiveCfg = Debug|x64
+ {DA956FD3-E143-46F2-9FE5-C77BEBC56B1A}.Debug|x64.Build.0 = Debug|x64
+ {DA956FD3-E143-46F2-9FE5-C77BEBC56B1A}.Release|Win32.ActiveCfg = Release|Win32
+ {DA956FD3-E143-46F2-9FE5-C77BEBC56B1A}.Release|Win32.Build.0 = Release|Win32
+ {DA956FD3-E143-46F2-9FE5-C77BEBC56B1A}.Release|x64.ActiveCfg = Release|x64
+ {DA956FD3-E143-46F2-9FE5-C77BEBC56B1A}.Release|x64.Build.0 = Release|x64
+ {FEE710DB-EC7B-4CCB-BD75-535D401A2FE0}.Debug|Win32.ActiveCfg = Debug|Win32
+ {FEE710DB-EC7B-4CCB-BD75-535D401A2FE0}.Debug|Win32.Build.0 = Debug|Win32
+ {FEE710DB-EC7B-4CCB-BD75-535D401A2FE0}.Debug|x64.ActiveCfg = Debug|x64
+ {FEE710DB-EC7B-4CCB-BD75-535D401A2FE0}.Debug|x64.Build.0 = Debug|x64
+ {FEE710DB-EC7B-4CCB-BD75-535D401A2FE0}.Release|Win32.ActiveCfg = Release|Win32
+ {FEE710DB-EC7B-4CCB-BD75-535D401A2FE0}.Release|Win32.Build.0 = Release|Win32
+ {FEE710DB-EC7B-4CCB-BD75-535D401A2FE0}.Release|x64.ActiveCfg = Release|x64
+ {FEE710DB-EC7B-4CCB-BD75-535D401A2FE0}.Release|x64.Build.0 = Release|x64
+ EndGlobalSection
+ GlobalSection(SolutionProperties) = preSolution
+ HideSolutionNode = FALSE
+ EndGlobalSection
+ GlobalSection(NestedProjects) = preSolution
+ {FEE710DB-EC7B-4CCB-BD75-535D401A2FE0} = {CE748C1F-3C21-4825-AA6A-F895A023F7E7}
+ {40FB7794-D3C3-4CFE-BCF4-A80C96635682} = {CE748C1F-3C21-4825-AA6A-F895A023F7E7}
+ {8682FE1E-0CF6-4EDD-9BB5-1733D8C8B4DF} = {CE748C1F-3C21-4825-AA6A-F895A023F7E7}
+ {CAE4F1D0-314F-4B10-805B-0EFD670133A0} = {CE748C1F-3C21-4825-AA6A-F895A023F7E7}
+ {8B5CFB38-CCBA-40A8-AD7A-89C57B070884} = {CE748C1F-3C21-4825-AA6A-F895A023F7E7}
+ {26932B24-EFC6-4E3A-B277-ED653DA37968} = {CE748C1F-3C21-4825-AA6A-F895A023F7E7}
+ {C4E04D18-EF76-4B42-B4C2-16A1BACDC0A3} = {CE748C1F-3C21-4825-AA6A-F895A023F7E7}
+ {EDEA9D00-AF64-45DE-8F60-5957048F2F0F} = {CE748C1F-3C21-4825-AA6A-F895A023F7E7}
+ {26828762-C95D-4637-9CB1-7F0979523813} = {CE748C1F-3C21-4825-AA6A-F895A023F7E7}
+ {AAAD1CB5-7ADA-47AE-85A0-08A6EC48FAFB} = {CE748C1F-3C21-4825-AA6A-F895A023F7E7}
+ EndGlobalSection
+EndGlobal
diff --git a/VisualC/SDLmain/SDLmain_VS2012.vcxproj b/VisualC/SDLmain/SDLmain_VS2012.vcxproj index 5a86801c0b..d95409bca7 100644 --- a/VisualC/SDLmain/SDLmain_VS2012.vcxproj +++ b/VisualC/SDLmain/SDLmain_VS2012.vcxproj @@ -144,7 +144,6 @@ <RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
<PrecompiledHeader>
</PrecompiledHeader>
- <PrecompiledHeaderOutputFile>.\Debug/SDLmain.pch</PrecompiledHeaderOutputFile>
<WarningLevel>Level3</WarningLevel>
<SuppressStartupBanner>true</SuppressStartupBanner>
<DebugInformationFormat>OldStyle</DebugInformationFormat>
diff --git a/VisualC/SDLtest/SDLtest_VS2012.vcxproj b/VisualC/SDLtest/SDLtest_VS2012.vcxproj index 2e306c0951..762f2b5fea 100644 --- a/VisualC/SDLtest/SDLtest_VS2012.vcxproj +++ b/VisualC/SDLtest/SDLtest_VS2012.vcxproj @@ -144,7 +144,6 @@ <RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
<PrecompiledHeader>
</PrecompiledHeader>
- <PrecompiledHeaderOutputFile>.\Debug/SDLtest.pch</PrecompiledHeaderOutputFile>
<WarningLevel>Level3</WarningLevel>
<SuppressStartupBanner>true</SuppressStartupBanner>
<DebugInformationFormat>OldStyle</DebugInformationFormat>
diff --git a/VisualC/tests/testplatform/testplatform_VS2012.vcxproj b/VisualC/tests/testplatform/testplatform_VS2012.vcxproj index ce8ef3d53c..d4f0475e94 100644 --- a/VisualC/tests/testplatform/testplatform_VS2012.vcxproj +++ b/VisualC/tests/testplatform/testplatform_VS2012.vcxproj @@ -168,7 +168,6 @@ <StringPooling>true</StringPooling>
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
<FunctionLevelLinking>true</FunctionLevelLinking>
- <PrecompiledHeaderOutputFile>.\Release/testplatform.pch</PrecompiledHeaderOutputFile>
<AssemblerListingLocation>$(IntDir)</AssemblerListingLocation>
<ObjectFileName>$(IntDir)</ObjectFileName>
<ProgramDataBaseFileName>$(IntDir)vc$(PlatformToolsetVersion).pdb</ProgramDataBaseFileName>
diff --git a/VisualC/tests/testpower/testpower_VS2012.vcxproj b/VisualC/tests/testpower/testpower_VS2012.vcxproj index 3cf7d6435c..3983a7bbbd 100644 --- a/VisualC/tests/testpower/testpower_VS2012.vcxproj +++ b/VisualC/tests/testpower/testpower_VS2012.vcxproj @@ -223,10 +223,7 @@ <Library Include="..\..\SDLmain\$(Platform)\$(Configuration)\SDLmain.lib" />
</ItemGroup>
<ItemGroup>
- <ClCompile Include="..\..\..\test\testpower.c">
- <PrecompiledHeaderOutputFile Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">.\Debug/testpower.pch</PrecompiledHeaderOutputFile>
- <PrecompiledHeaderOutputFile Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">.\Debug/testpower.pch</PrecompiledHeaderOutputFile>
- </ClCompile>
+ <ClCompile Include="..\..\..\test\testpower.c" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
diff --git a/Xcode-iOS/Template/SDL iOS Application/___PROJECTNAME___.xcodeproj/project.pbxproj b/Xcode-iOS/Template/SDL iOS Application/___PROJECTNAME___.xcodeproj/project.pbxproj index f786799eb8..3e0eb0c807 100755 --- a/Xcode-iOS/Template/SDL iOS Application/___PROJECTNAME___.xcodeproj/project.pbxproj +++ b/Xcode-iOS/Template/SDL iOS Application/___PROJECTNAME___.xcodeproj/project.pbxproj @@ -38,7 +38,6 @@ 0097E2A812F70C4D00724AC5 /* SDL_config_iphoneos.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SDL_config_iphoneos.h; sourceTree = "<group>"; }; 0097E2A912F70C4D00724AC5 /* SDL_config_macosx.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SDL_config_macosx.h; sourceTree = "<group>"; }; 0097E2AA12F70C4D00724AC5 /* SDL_config_minimal.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SDL_config_minimal.h; sourceTree = "<group>"; }; - 0097E2AB12F70C4D00724AC5 /* SDL_config_nintendods.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SDL_config_nintendods.h; sourceTree = "<group>"; }; 0097E2AC12F70C4D00724AC5 /* SDL_config_pandora.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SDL_config_pandora.h; sourceTree = "<group>"; }; 0097E2AD12F70C4D00724AC5 /* SDL_config_windows.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SDL_config_windows.h; sourceTree = "<group>"; }; 0097E2AE12F70C4D00724AC5 /* SDL_config_wiz.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SDL_config_wiz.h; sourceTree = "<group>"; }; @@ -142,7 +141,6 @@ 0097E2A812F70C4D00724AC5 /* SDL_config_iphoneos.h */, 0097E2A912F70C4D00724AC5 /* SDL_config_macosx.h */, 0097E2AA12F70C4D00724AC5 /* SDL_config_minimal.h */, - 0097E2AB12F70C4D00724AC5 /* SDL_config_nintendods.h */, 0097E2AC12F70C4D00724AC5 /* SDL_config_pandora.h */, 0097E2AD12F70C4D00724AC5 /* SDL_config_windows.h */, 0097E2AE12F70C4D00724AC5 /* SDL_config_wiz.h */, diff --git a/android-project/AndroidManifest.xml b/android-project/AndroidManifest.xml index c88b3fac35..ce7c056aea 100644 --- a/android-project/AndroidManifest.xml +++ b/android-project/AndroidManifest.xml @@ -18,7 +18,7 @@ An example Java class can be found in README.android --> <application android:label="@string/app_name" - android:icon="@drawable/icon" + android:icon="@drawable/ic_launcher" android:theme="@android:style/Theme.NoTitleBar.Fullscreen"> <activity android:name="SDLActivity" android:label="@string/app_name"> @@ -29,7 +29,7 @@ </activity> </application> - <!-- Android 2.1 --> + <!-- Android 2.3.3 --> <uses-sdk android:minSdkVersion="10" /> <!-- OpenGL ES 2.0 --> diff --git a/android-project/res/drawable-hdpi/ic_launcher.png b/android-project/res/drawable-hdpi/ic_launcher.png Binary files differnew file mode 100644 index 0000000000..d50bdaae06 --- /dev/null +++ b/android-project/res/drawable-hdpi/ic_launcher.png diff --git a/android-project/res/drawable-hdpi/icon.png b/android-project/res/drawable-hdpi/icon.png Binary files differdeleted file mode 100644 index 8074c4c571..0000000000 --- a/android-project/res/drawable-hdpi/icon.png +++ /dev/null diff --git a/android-project/res/drawable-ldpi/icon.png b/android-project/res/drawable-ldpi/icon.png Binary files differdeleted file mode 100644 index 1095584ec2..0000000000 --- a/android-project/res/drawable-ldpi/icon.png +++ /dev/null diff --git a/android-project/res/drawable-mdpi/ic_launcher.png b/android-project/res/drawable-mdpi/ic_launcher.png Binary files differnew file mode 100644 index 0000000000..0a299eb3cc --- /dev/null +++ b/android-project/res/drawable-mdpi/ic_launcher.png diff --git a/android-project/res/drawable-mdpi/icon.png b/android-project/res/drawable-mdpi/icon.png Binary files differdeleted file mode 100644 index a07c69fa5a..0000000000 --- a/android-project/res/drawable-mdpi/icon.png +++ /dev/null diff --git a/android-project/res/drawable-xhdpi/ic_launcher.png b/android-project/res/drawable-xhdpi/ic_launcher.png Binary files differnew file mode 100644 index 0000000000..a336ad5c2b --- /dev/null +++ b/android-project/res/drawable-xhdpi/ic_launcher.png diff --git a/android-project/res/drawable-xxhdpi/ic_launcher.png b/android-project/res/drawable-xxhdpi/ic_launcher.png Binary files differnew file mode 100644 index 0000000000..d423dac262 --- /dev/null +++ b/android-project/res/drawable-xxhdpi/ic_launcher.png diff --git a/android-project/src/org/libsdl/app/SDLActivity.java b/android-project/src/org/libsdl/app/SDLActivity.java index 1c77e730fc..e0a850f429 100644 --- a/android-project/src/org/libsdl/app/SDLActivity.java +++ b/android-project/src/org/libsdl/app/SDLActivity.java @@ -509,7 +509,7 @@ class SDLSurface extends SurfaceView implements SurfaceHolder.Callback, int format, int width, int height) { Log.v("SDL", "surfaceChanged()"); - int sdlFormat = 0x85151002; // SDL_PIXELFORMAT_RGB565 by default + int sdlFormat = 0x15151002; // SDL_PIXELFORMAT_RGB565 by default switch (format) { case PixelFormat.A_8: Log.v("SDL", "pixel format A_8"); @@ -522,32 +522,32 @@ class SDLSurface extends SurfaceView implements SurfaceHolder.Callback, break; case PixelFormat.RGBA_4444: Log.v("SDL", "pixel format RGBA_4444"); - sdlFormat = 0x85421002; // SDL_PIXELFORMAT_RGBA4444 + sdlFormat = 0x15421002; // SDL_PIXELFORMAT_RGBA4444 break; case PixelFormat.RGBA_5551: Log.v("SDL", "pixel format RGBA_5551"); - sdlFormat = 0x85441002; // SDL_PIXELFORMAT_RGBA5551 + sdlFormat = 0x15441002; // SDL_PIXELFORMAT_RGBA5551 break; case PixelFormat.RGBA_8888: Log.v("SDL", "pixel format RGBA_8888"); - sdlFormat = 0x86462004; // SDL_PIXELFORMAT_RGBA8888 + sdlFormat = 0x16462004; // SDL_PIXELFORMAT_RGBA8888 break; case PixelFormat.RGBX_8888: Log.v("SDL", "pixel format RGBX_8888"); - sdlFormat = 0x86262004; // SDL_PIXELFORMAT_RGBX8888 + sdlFormat = 0x16261804; // SDL_PIXELFORMAT_RGBX8888 break; case PixelFormat.RGB_332: Log.v("SDL", "pixel format RGB_332"); - sdlFormat = 0x84110801; // SDL_PIXELFORMAT_RGB332 + sdlFormat = 0x14110801; // SDL_PIXELFORMAT_RGB332 break; case PixelFormat.RGB_565: Log.v("SDL", "pixel format RGB_565"); - sdlFormat = 0x85151002; // SDL_PIXELFORMAT_RGB565 + sdlFormat = 0x15151002; // SDL_PIXELFORMAT_RGB565 break; case PixelFormat.RGB_888: Log.v("SDL", "pixel format RGB_888"); // Not sure this is right, maybe SDL_PIXELFORMAT_RGB24 instead? - sdlFormat = 0x86161804; // SDL_PIXELFORMAT_RGB888 + sdlFormat = 0x16161804; // SDL_PIXELFORMAT_RGB888 break; default: Log.v("SDL", "pixel format unknown " + format); diff --git a/build-scripts/updaterev.sh b/build-scripts/updaterev.sh index 61ae9b0235..485d045807 100755 --- a/build-scripts/updaterev.sh +++ b/build-scripts/updaterev.sh @@ -10,11 +10,11 @@ header=$outdir/include/SDL_revision.h rev=`sh showrev.sh 2>/dev/null` if [ "$rev" != "" -a "$rev" != "hg-0:baadf00d" ]; then revnum=`echo $rev | sed 's,hg-\([0-9]*\).*,\1,'` - echo "#define SDL_REVISION \"$rev\"" >$header.new - echo "#define SDL_REVISION_NUMBER $revnum" >>$header.new + echo "#define SDL_REVISION \"$rev\"" >"$header.new" + echo "#define SDL_REVISION_NUMBER $revnum" >>"$header.new" if diff $header $header.new >/dev/null 2>&1; then - rm $header.new + rm "$header.new" else - mv $header.new $header + mv "$header.new" "$header" fi fi @@ -20263,7 +20263,7 @@ fi else set -- `echo $DIRECTFB_REQUIRED_VERSION | sed 's/\./ /g'` NEED_VERSION=`expr $1 \* 10000 + $2 \* 100 + $3` - set -- `directfb-config --version | sed 's/\./ /g'` + set -- `$DIRECTFBCONFIG --version | sed 's/\./ /g'` HAVE_VERSION=`expr $1 \* 10000 + $2 \* 100 + $3` if test $HAVE_VERSION -ge $NEED_VERSION; then DIRECTFB_CFLAGS=`$DIRECTFBCONFIG --cflags` @@ -22324,6 +22324,15 @@ $as_echo "#define SDL_POWER_BEOS 1" >>confdefs.h # The iOS platform requires special setup. SOURCES="$SOURCES $srcdir/src/video/uikit/*.m" SOURCES="$SOURCES $srcdir/src/video/uikit/*.c" + EXTRA_CFLAGS="$EXTRA_CFLAGS -fpascal-strings" + EXTRA_LDFLAGS="$EXTRA_LDFLAGS -lm -liconv -lobjc" + EXTRA_LDFLAGS="$EXTRA_LDFLAGS -Wl,-framework,Foundation" + EXTRA_LDFLAGS="$EXTRA_LDFLAGS -Wl,-framework,UIKit" + EXTRA_LDFLAGS="$EXTRA_LDFLAGS -Wl,-framework,OpenGLES" + EXTRA_LDFLAGS="$EXTRA_LDFLAGS -Wl,-framework,QuartzCore" + EXTRA_LDFLAGS="$EXTRA_LDFLAGS -Wl,-framework,CoreAudio" + EXTRA_LDFLAGS="$EXTRA_LDFLAGS -Wl,-framework,AudioToolbox" + EXTRA_LDFLAGS="$EXTRA_LDFLAGS -Wl,-framework,CoreGraphics" ;; *-*-darwin* ) # This could be either full "Mac OS X", or plain "Darwin" which is diff --git a/configure.in b/configure.in index 56f96054a6..84444f3e6e 100644 --- a/configure.in +++ b/configure.in @@ -794,6 +794,14 @@ AC_HELP_STRING([--enable-pulseaudio-shared], [dynamically load PulseAudio suppor test x$enable_pulseaudio_shared = xyes && test x$pulseaudio_lib != x; then echo "-- dynamic libpulse-simple -> $pulseaudio_lib" AC_DEFINE_UNQUOTED(SDL_AUDIO_DRIVER_PULSEAUDIO_DYNAMIC, "$pulseaudio_lib", [ ]) + + case "$host" in + # On Solaris, pulseaudio must be linked deferred explicitly + # to prevent undefined symbol failures. + *-*-solaris*) + PULSEAUDIO_LIBS=`echo $PULSEAUDIO_LIBS | sed 's/\-l/-Wl,-l/g'` + EXTRA_LDFLAGS="$EXTRA_LDFLAGS -Wl,-zdeferred $PULSEAUDIO_LIBS -Wl,-znodeferred" + esac else EXTRA_LDFLAGS="$EXTRA_LDFLAGS $PULSEAUDIO_LIBS" fi @@ -1415,7 +1423,7 @@ AC_HELP_STRING([--enable-video-directfb], [use DirectFB video driver [[default=n else set -- `echo $DIRECTFB_REQUIRED_VERSION | sed 's/\./ /g'` NEED_VERSION=`expr $1 \* 10000 + $2 \* 100 + $3` - set -- `directfb-config --version | sed 's/\./ /g'` + set -- `$DIRECTFBCONFIG --version | sed 's/\./ /g'` HAVE_VERSION=`expr $1 \* 10000 + $2 \* 100 + $3` if test $HAVE_VERSION -ge $NEED_VERSION; then DIRECTFB_CFLAGS=`$DIRECTFBCONFIG --cflags` @@ -1767,9 +1775,20 @@ AC_HELP_STRING([--enable-pthread-sem], [use pthread semaphores [[default=yes]]]) pthread_cflags="-D_REENTRANT" pthread_lib="-pthread" ;; + *-*-solaris2.9) + # From Solaris 9+, posix4's preferred name is rt. + pthread_cflags="-D_REENTRANT" + pthread_lib="-lpthread -lrt" + ;; + *-*-solaris2.10) + # Solaris 10+ merged pthread into libc. + pthread_cflags="-D_REENTRANT" + pthread_lib="-lrt" + ;; *-*-solaris*) + # Solaris 11+ merged rt into libc. pthread_cflags="-D_REENTRANT" - pthread_lib="-lpthread -lposix4" + pthread_lib="" ;; *-*-sysv5*) pthread_cflags="-D_REENTRANT -Kthread" @@ -2499,6 +2518,15 @@ AC_HELP_STRING([--enable-render-d3d], [enable the Direct3D render driver [[defau # The iOS platform requires special setup. SOURCES="$SOURCES $srcdir/src/video/uikit/*.m" SOURCES="$SOURCES $srcdir/src/video/uikit/*.c" + EXTRA_CFLAGS="$EXTRA_CFLAGS -fpascal-strings" + EXTRA_LDFLAGS="$EXTRA_LDFLAGS -lm -liconv -lobjc" + EXTRA_LDFLAGS="$EXTRA_LDFLAGS -Wl,-framework,Foundation" + EXTRA_LDFLAGS="$EXTRA_LDFLAGS -Wl,-framework,UIKit" + EXTRA_LDFLAGS="$EXTRA_LDFLAGS -Wl,-framework,OpenGLES" + EXTRA_LDFLAGS="$EXTRA_LDFLAGS -Wl,-framework,QuartzCore" + EXTRA_LDFLAGS="$EXTRA_LDFLAGS -Wl,-framework,CoreAudio" + EXTRA_LDFLAGS="$EXTRA_LDFLAGS -Wl,-framework,AudioToolbox" + EXTRA_LDFLAGS="$EXTRA_LDFLAGS -Wl,-framework,CoreGraphics" ;; *-*-darwin* ) # This could be either full "Mac OS X", or plain "Darwin" which is diff --git a/include/SDL.h b/include/SDL.h index 2058ae15cc..0cfcdc71a2 100644 --- a/include/SDL.h +++ b/include/SDL.h @@ -41,10 +41,9 @@ * Guile, Haskell, Java, Lisp, Lua, ML, Objective C, Pascal, Perl, PHP, * Pike, Pliant, Python, Ruby, and Smalltalk. * - * This library is distributed under GNU LGPL version 2, which can be + * This library is distributed under the zlib license, which can be * found in the file "COPYING". This license allows you to use SDL - * freely in commercial programs as long as you link with the dynamic - * library. + * freely for any purpose as long as you retain the copyright notice. * * The best way to learn how to use SDL is to check out the header files in * the "include" subdirectory and the programs in the "test" subdirectory. @@ -73,7 +72,9 @@ #include "SDL_endian.h" #include "SDL_error.h" #include "SDL_events.h" +#include "SDL_joystick.h" #include "SDL_gamecontroller.h" +#include "SDL_haptic.h" #include "SDL_hints.h" #include "SDL_loadso.h" #include "SDL_log.h" @@ -112,7 +113,10 @@ extern "C" { #define SDL_INIT_HAPTIC 0x00001000 #define SDL_INIT_GAMECONTROLLER 0x00002000 /**< turn on game controller also implicitly does JOYSTICK */ #define SDL_INIT_NOPARACHUTE 0x00100000 /**< Don't catch fatal signals */ -#define SDL_INIT_EVERYTHING 0x0000FFFF +#define SDL_INIT_EVERYTHING ( \ + SDL_INIT_TIMER | SDL_INIT_AUDIO | SDL_INIT_VIDEO | \ + SDL_INIT_JOYSTICK | SDL_INIT_HAPTIC | SDL_INIT_GAMECONTROLLER \ + ) /*@}*/ /** diff --git a/include/SDL_atomic.h b/include/SDL_atomic.h index 2f1734963a..be60f99166 100644 --- a/include/SDL_atomic.h +++ b/include/SDL_atomic.h @@ -126,7 +126,7 @@ extern DECLSPEC void SDLCALL SDL_AtomicUnlock(SDL_SpinLock *lock); * The compiler barrier prevents the compiler from reordering * reads and writes to globally visible variables across the call. */ -#ifdef _MSC_VER +#if defined(_MSC_VER) && (_MSC_VER > 1200) void _ReadWriteBarrier(void); #pragma intrinsic(_ReadWriteBarrier) #define SDL_CompilerBarrier() _ReadWriteBarrier() @@ -134,7 +134,7 @@ void _ReadWriteBarrier(void); #define SDL_CompilerBarrier() __asm__ __volatile__ ("" : : : "memory") #else #define SDL_CompilerBarrier() \ -({ SDL_SpinLock _tmp = 0; SDL_AtomicLock(&_tmp); SDL_AtomicUnlock(&_tmp); }) +{ SDL_SpinLock _tmp = 0; SDL_AtomicLock(&_tmp); SDL_AtomicUnlock(&_tmp); } #endif /* Platform specific optimized versions of the atomic functions, @@ -196,9 +196,8 @@ typedef struct { int value; } SDL_atomic_t; * \note If you don't know what this function is for, you shouldn't use it! */ #ifndef SDL_AtomicCAS -#define SDL_AtomicCAS SDL_AtomicCAS_ +extern DECLSPEC SDL_bool SDLCALL SDL_AtomicCAS(SDL_atomic_t *a, int oldval, int newval); #endif -extern DECLSPEC SDL_bool SDLCALL SDL_AtomicCAS_(SDL_atomic_t *a, int oldval, int newval); /** * \brief Set an atomic variable to a value. @@ -206,7 +205,7 @@ extern DECLSPEC SDL_bool SDLCALL SDL_AtomicCAS_(SDL_atomic_t *a, int oldval, int * \return The previous value of the atomic variable. */ #ifndef SDL_AtomicSet -static __inline__ int SDL_AtomicSet(SDL_atomic_t *a, int v) +SDL_FORCE_INLINE int SDL_AtomicSet(SDL_atomic_t *a, int v) { int value; do { @@ -220,7 +219,7 @@ static __inline__ int SDL_AtomicSet(SDL_atomic_t *a, int v) * \brief Get the value of an atomic variable */ #ifndef SDL_AtomicGet -static __inline__ int SDL_AtomicGet(SDL_atomic_t *a) +SDL_FORCE_INLINE int SDL_AtomicGet(SDL_atomic_t *a) { int value = a->value; SDL_CompilerBarrier(); @@ -236,7 +235,7 @@ static __inline__ int SDL_AtomicGet(SDL_atomic_t *a) * \note This same style can be used for any number operation */ #ifndef SDL_AtomicAdd -static __inline__ int SDL_AtomicAdd(SDL_atomic_t *a, int v) +SDL_FORCE_INLINE int SDL_AtomicAdd(SDL_atomic_t *a, int v) { int value; do { @@ -271,9 +270,8 @@ static __inline__ int SDL_AtomicAdd(SDL_atomic_t *a, int v) * \note If you don't know what this function is for, you shouldn't use it! */ #ifndef SDL_AtomicCASPtr -#define SDL_AtomicCASPtr SDL_AtomicCASPtr_ +extern DECLSPEC SDL_bool SDLCALL SDL_AtomicCASPtr(void* *a, void *oldval, void *newval); #endif -extern DECLSPEC SDL_bool SDLCALL SDL_AtomicCASPtr_(void* *a, void *oldval, void *newval); /** * \brief Set a pointer to a value atomically. @@ -281,7 +279,7 @@ extern DECLSPEC SDL_bool SDLCALL SDL_AtomicCASPtr_(void* *a, void *oldval, void * \return The previous value of the pointer. */ #ifndef SDL_AtomicSetPtr -static __inline__ void* SDL_AtomicSetPtr(void* *a, void* v) +SDL_FORCE_INLINE void* SDL_AtomicSetPtr(void* *a, void* v) { void* value; do { @@ -295,7 +293,7 @@ static __inline__ void* SDL_AtomicSetPtr(void* *a, void* v) * \brief Get the value of a pointer atomically. */ #ifndef SDL_AtomicGetPtr -static __inline__ void* SDL_AtomicGetPtr(void* *a) +SDL_FORCE_INLINE void* SDL_AtomicGetPtr(void* *a) { void* value = *a; SDL_CompilerBarrier(); diff --git a/include/SDL_bits.h b/include/SDL_bits.h index 3192c8e41e..d678b78229 100644 --- a/include/SDL_bits.h +++ b/include/SDL_bits.h @@ -40,11 +40,6 @@ extern "C" { /** * \file SDL_bits.h - * - * Uses inline functions for compilers that support them, and static - * functions for those that do not. Because these functions become - * static for compilers that do not support inline functions, this - * header should only be included in files that actually use them. */ /** @@ -54,10 +49,10 @@ extern "C" { * * \return Index of the most significant bit. */ -static __inline__ Sint8 +SDL_FORCE_INLINE Sint8 SDL_MostSignificantBitIndex32(Uint32 x) { -#if defined(__GNUC__) +#if defined(__GNUC__) && __GNUC__ >= 4 /* Count Leading Zeroes builtin in GCC. * http://gcc.gnu.org/onlinedocs/gcc-4.3.4/gcc/Other-Builtins.html */ diff --git a/include/SDL_config.h b/include/SDL_config.h index dc6ad71896..f4ac5b3db0 100644 --- a/include/SDL_config.h +++ b/include/SDL_config.h @@ -39,8 +39,8 @@ #include "SDL_config_iphoneos.h" #elif defined(__ANDROID__) #include "SDL_config_android.h" -#elif defined(__NINTENDODS__) -#include "SDL_config_nintendods.h" +#elif defined(__PSP__) +#include "SDL_config_psp.h" #else /* This is a minimal configuration just to get SDL running on new platforms */ #include "SDL_config_minimal.h" diff --git a/include/SDL_config.h.cmake b/include/SDL_config.h.cmake index 5e5f6a769d..c3b9bc708b 100644 --- a/include/SDL_config.h.cmake +++ b/include/SDL_config.h.cmake @@ -195,7 +195,6 @@ #cmakedefine SDL_AUDIO_DRIVER_ESD_DYNAMIC @SDL_AUDIO_DRIVER_ESD_DYNAMIC@ #cmakedefine SDL_AUDIO_DRIVER_NAS @SDL_AUDIO_DRIVER_NAS@ #cmakedefine SDL_AUDIO_DRIVER_NAS_DYNAMIC @SDL_AUDIO_DRIVER_NAS_DYNAMIC@ -#cmakedefine SDL_AUDIO_DRIVER_NDS @SDL_AUDIO_DRIVER_NDS@ #cmakedefine SDL_AUDIO_DRIVER_OSS @SDL_AUDIO_DRIVER_OSS@ #cmakedefine SDL_AUDIO_DRIVER_OSS_SOUNDCARD_H @SDL_AUDIO_DRIVER_OSS_SOUNDCARD_H@ #cmakedefine SDL_AUDIO_DRIVER_PAUDIO @SDL_AUDIO_DRIVER_PAUDIO@ @@ -213,7 +212,6 @@ #cmakedefine SDL_JOYSTICK_DUMMY @SDL_JOYSTICK_DUMMY@ #cmakedefine SDL_JOYSTICK_IOKIT @SDL_JOYSTICK_IOKIT@ #cmakedefine SDL_JOYSTICK_LINUX @SDL_JOYSTICK_LINUX@ -#cmakedefine SDL_JOYSTICK_NDS @SDL_JOYSTICK_NDS@ #cmakedefine SDL_JOYSTICK_WINMM @SDL_JOYSTICK_WINMM@ #cmakedefine SDL_JOYSTICK_USBHID @SDL_JOYSTICK_USBHID@ #cmakedefine SDL_JOYSTICK_USBHID_MACHINE_JOYSTICK_H @SDL_JOYSTICK_USBHID_MACHINE_JOYSTICK_H@ @@ -231,7 +229,6 @@ /* Enable various threading systems */ #cmakedefine SDL_THREAD_BEOS @SDL_THREAD_BEOS@ -#cmakedefine SDL_THREAD_NDS @SDL_THREAD_NDS@ #cmakedefine SDL_THREAD_PTHREAD @SDL_THREAD_PTHREAD@ #cmakedefine SDL_THREAD_PTHREAD_RECURSIVE_MUTEX @SDL_THREAD_PTHREAD_RECURSIVE_MUTEX@ #cmakedefine SDL_THREAD_PTHREAD_RECURSIVE_MUTEX_NP @SDL_THREAD_PTHREAD_RECURSIVE_MUTEX_NP@ @@ -240,7 +237,6 @@ /* Enable various timer systems */ #cmakedefine SDL_TIMER_BEOS @SDL_TIMER_BEOS@ #cmakedefine SDL_TIMER_DUMMY @SDL_TIMER_DUMMY@ -#cmakedefine SDL_TIMER_NDS @SDL_TIMER_NDS@ #cmakedefine SDL_TIMER_UNIX @SDL_TIMER_UNIX@ #cmakedefine SDL_TIMER_WINDOWS @SDL_TIMER_WINDOWS@ #cmakedefine SDL_TIMER_WINCE @SDL_TIMER_WINCE@ @@ -251,7 +247,6 @@ #cmakedefine SDL_VIDEO_DRIVER_DIRECTFB @SDL_VIDEO_DRIVER_DIRECTFB@ #cmakedefine SDL_VIDEO_DRIVER_DIRECTFB_DYNAMIC @SDL_VIDEO_DRIVER_DIRECTFB_DYNAMIC@ #cmakedefine SDL_VIDEO_DRIVER_DUMMY @SDL_VIDEO_DRIVER_DUMMY@ -#cmakedefine SDL_VIDEO_DRIVER_NDS @SDL_VIDEO_DRIVER_NDS@ #cmakedefine SDL_VIDEO_DRIVER_WINDOWS @SDL_VIDEO_DRIVER_WINDOWS@ #cmakedefine SDL_VIDEO_DRIVER_X11 @SDL_VIDEO_DRIVER_X11@ #cmakedefine SDL_VIDEO_DRIVER_X11_DYNAMIC @SDL_VIDEO_DRIVER_X11_DYNAMIC@ @@ -295,7 +290,6 @@ #cmakedefine SDL_POWER_WINDOWS @SDL_POWER_WINDOWS@ #cmakedefine SDL_POWER_MACOSX @SDL_POWER_MACOSX@ #cmakedefine SDL_POWER_BEOS @SDL_POWER_BEOS@ -#cmakedefine SDL_POWER_NINTENDODS @SDL_POWER_NINTENDODS@ #cmakedefine SDL_POWER_HARDWIRED @SDL_POWER_HARDWIRED@ /* Enable assembly routines */ diff --git a/include/SDL_config.h.in b/include/SDL_config.h.in index 59d102dd3b..bd2be4b2f7 100644 --- a/include/SDL_config.h.in +++ b/include/SDL_config.h.in @@ -198,7 +198,6 @@ #undef SDL_AUDIO_DRIVER_ESD_DYNAMIC #undef SDL_AUDIO_DRIVER_NAS #undef SDL_AUDIO_DRIVER_NAS_DYNAMIC -#undef SDL_AUDIO_DRIVER_NDS #undef SDL_AUDIO_DRIVER_OSS #undef SDL_AUDIO_DRIVER_OSS_SOUNDCARD_H #undef SDL_AUDIO_DRIVER_PAUDIO @@ -216,7 +215,6 @@ #undef SDL_JOYSTICK_DUMMY #undef SDL_JOYSTICK_IOKIT #undef SDL_JOYSTICK_LINUX -#undef SDL_JOYSTICK_NDS #undef SDL_JOYSTICK_WINMM #undef SDL_JOYSTICK_USBHID #undef SDL_JOYSTICK_USBHID_MACHINE_JOYSTICK_H @@ -234,7 +232,6 @@ /* Enable various threading systems */ #undef SDL_THREAD_BEOS -#undef SDL_THREAD_NDS #undef SDL_THREAD_PTHREAD #undef SDL_THREAD_PTHREAD_RECURSIVE_MUTEX #undef SDL_THREAD_PTHREAD_RECURSIVE_MUTEX_NP @@ -243,7 +240,6 @@ /* Enable various timer systems */ #undef SDL_TIMER_BEOS #undef SDL_TIMER_DUMMY -#undef SDL_TIMER_NDS #undef SDL_TIMER_UNIX #undef SDL_TIMER_WINDOWS @@ -253,7 +249,6 @@ #undef SDL_VIDEO_DRIVER_DIRECTFB #undef SDL_VIDEO_DRIVER_DIRECTFB_DYNAMIC #undef SDL_VIDEO_DRIVER_DUMMY -#undef SDL_VIDEO_DRIVER_NDS #undef SDL_VIDEO_DRIVER_WINDOWS #undef SDL_VIDEO_DRIVER_X11 #undef SDL_VIDEO_DRIVER_X11_DYNAMIC @@ -297,7 +292,6 @@ #undef SDL_POWER_WINDOWS #undef SDL_POWER_MACOSX #undef SDL_POWER_BEOS -#undef SDL_POWER_NINTENDODS #undef SDL_POWER_HARDWIRED /* Enable assembly routines */ diff --git a/include/SDL_config_nintendods.h b/include/SDL_config_psp.h index 7b5c21e7c9..036b30b287 100644 --- a/include/SDL_config_nintendods.h +++ b/include/SDL_config_psp.h @@ -19,40 +19,29 @@ 3. This notice may not be removed or altered from any source distribution. */ -#ifndef _SDL_config_nintendods_h -#define _SDL_config_nintendods_h +#ifndef _SDL_config_psp_h +#define _SDL_config_psp_h #include "SDL_platform.h" -/* This is a set of defines to configure the SDL features */ - -#if !defined(_STDINT_H_) && (!defined(HAVE_STDINT_H) || !_HAVE_STDINT_H) -typedef signed char int8_t; -typedef unsigned char uint8_t; -typedef signed short int16_t; -typedef unsigned short uint16_t; -typedef signed int int32_t; -typedef unsigned int uint32_t; -typedef signed long long int64_t; -typedef unsigned long long uint64_t; - -/* LiF: __PTRDIFF_TYPE__ was causing errors of conflicting typedefs with the - <stdint.h> shipping with devkitARM. copied a similar ifdef from it. */ -#ifndef __PTRDIFF_TYPE__ -typedef unsigned long uintptr_t; -#else -typedef unsigned __PTRDIFF_TYPE__ uintptr_t; + + +#ifdef __GNUC__ +#define HAVE_GCC_SYNC_LOCK_TEST_AND_SET 1 #endif -#endif /* !_STDINT_H_ && !HAVE_STDINT_H */ -#define SIZEOF_VOIDP 4 +#define HAVE_GCC_ATOMICS 1 -/* Useful headers */ +#define HAVE_ALLOCA_H 1 #define HAVE_SYS_TYPES_H 1 #define HAVE_STDIO_H 1 #define STDC_HEADERS 1 #define HAVE_STRING_H 1 +#define HAVE_INTTYPES_H 1 +#define HAVE_STDINT_H 1 #define HAVE_CTYPE_H 1 +#define HAVE_MATH_H 1 +#define HAVE_SIGNAL_H 1 /* C library functions */ #define HAVE_MALLOC 1 @@ -63,6 +52,8 @@ typedef unsigned __PTRDIFF_TYPE__ uintptr_t; #define HAVE_GETENV 1 #define HAVE_SETENV 1 #define HAVE_PUTENV 1 +#define HAVE_SETENV 1 +#define HAVE_UNSETENV 1 #define HAVE_QSORT 1 #define HAVE_ABS 1 #define HAVE_BCOPY 1 @@ -71,59 +62,75 @@ typedef unsigned __PTRDIFF_TYPE__ uintptr_t; #define HAVE_MEMMOVE 1 #define HAVE_MEMCMP 1 #define HAVE_STRLEN 1 +#define HAVE_STRLCPY 1 +#define HAVE_STRLCAT 1 #define HAVE_STRDUP 1 -#define HAVE_INDEX 1 -#define HAVE_RINDEX 1 #define HAVE_STRCHR 1 #define HAVE_STRRCHR 1 #define HAVE_STRSTR 1 #define HAVE_STRTOL 1 +#define HAVE_STRTOUL 1 +#define HAVE_STRTOLL 1 +#define HAVE_STRTOULL 1 #define HAVE_STRTOD 1 #define HAVE_ATOI 1 #define HAVE_ATOF 1 #define HAVE_STRCMP 1 #define HAVE_STRNCMP 1 -#define HAVE_STRICMP 1 #define HAVE_STRCASECMP 1 +#define HAVE_STRNCASECMP 1 #define HAVE_SSCANF 1 #define HAVE_SNPRINTF 1 #define HAVE_VSNPRINTF 1 - -/* DS isn't that sophisticated */ +#define HAVE_M_PI 1 +#define HAVE_ATAN 1 +#define HAVE_ATAN2 1 +#define HAVE_CEIL 1 +#define HAVE_COPYSIGN 1 +#define HAVE_COS 1 +#define HAVE_COSF 1 +#define HAVE_FABS 1 +#define HAVE_FLOOR 1 +#define HAVE_LOG 1 +#define HAVE_POW 1 +#define HAVE_SCALBN 1 +#define HAVE_SIN 1 +#define HAVE_SINF 1 +#define HAVE_SQRT 1 +#define HAVE_SETJMP 1 +#define HAVE_NANOSLEEP 1 +//#define HAVE_SYSCONF 1 +//#define HAVE_SIGACTION 1 + + +/* PSP isn't that sophisticated */ #define LACKS_SYS_MMAN_H 1 -/* Enable various audio drivers */ -#define SDL_AUDIO_DRIVER_NDS 1 -/*#define SDL_AUDIO_DRIVER_DUMMY 1 TODO: uncomment this later*/ +/* Enable the stub thread support (src/thread/psp/\*.c) */ +#define SDL_THREAD_PSP 1 -/* Enable various input drivers */ -#define SDL_JOYSTICK_NDS 1 -/*#define SDL_JOYSTICK_DUMMY 1 TODO: uncomment this later*/ +/* Enable the stub timer support (src/timer/psp/\*.c) */ +#define SDL_TIMERS_PSP 1 -/* DS has no dynamic linking afaik */ -#define SDL_LOADSO_DISABLED 1 +/* Enable the stub joystick driver (src/joystick/psp/\*.c) */ +#define SDL_JOYSTICK_PSP 1 -/* Enable various threading systems */ -/*#define SDL_THREAD_NDS 1*/ -#define SDL_THREADS_DISABLED 1 +/* Enable the stub audio driver (src/audio/psp/\*.c) */ +#define SDL_AUDIO_DRIVER_PSP 1 -/* Enable various timer systems */ -#define SDL_TIMER_NDS 1 +/* PSP video dirver */ +#define SDL_VIDEO_DRIVER_PSP 1 -/* Enable various video drivers */ -#define SDL_VIDEO_DRIVER_NDS 1 -#ifdef USE_HW_RENDERER -#define SDL_VIDEO_RENDER_NDS 1 -#else -#define SDL_VIDEO_RENDER_NDS 0 -#endif +/* PSP render dirver */ +#define SDL_VIDEO_RENDER_PSP 1 + +#define SDL_POWER_PSP 1 -/* Enable system power support */ -#define SDL_POWER_NINTENDODS 1 +/* PSP doesn't have haptic device (src/haptic/dummy/\*.c) */ +#define SDL_HAPTIC_DISABLED 1 -/* Enable haptic support */ -#define SDL_HAPTIC_NDS 1 +/* PSP can't load shared object (src/loadso/dummy/\*.c) */ +#define SDL_LOADSO_DISABLED 1 -#define SDL_BYTEORDER SDL_LIL_ENDIAN -#endif /* _SDL_config_nintendods_h */ +#endif /* _SDL_config_minimal_h */ diff --git a/include/SDL_config_windowsrt.h b/include/SDL_config_windowsrt.h index a217774510..5e48338f45 100644 --- a/include/SDL_config_windowsrt.h +++ b/include/SDL_config_windowsrt.h @@ -109,7 +109,7 @@ typedef unsigned int uintptr_t; //#define HAVE__ULTOA 1 // TODO, WinRT: consider using _ultoa_s instead #define HAVE_STRTOL 1 #define HAVE_STRTOUL 1 -#define HAVE_STRTOLL 1 +//#define HAVE_STRTOLL 1 #define HAVE_STRTOD 1 #define HAVE_ATOI 1 #define HAVE_ATOF 1 @@ -123,14 +123,14 @@ typedef unsigned int uintptr_t; #define HAVE_ATAN 1 #define HAVE_ATAN2 1 #define HAVE_CEIL 1 -#define HAVE_COPYSIGN 1 +//#define HAVE_COPYSIGN 1 // TODO, WinRT: consider using _copysign instead #define HAVE_COS 1 #define HAVE_COSF 1 #define HAVE_FABS 1 #define HAVE_FLOOR 1 #define HAVE_LOG 1 #define HAVE_POW 1 -#define HAVE_SCALBN 1 +//#define HAVE_SCALBN 1 #define HAVE_SIN 1 #define HAVE_SINF 1 #define HAVE_SQRT 1 diff --git a/include/SDL_endian.h b/include/SDL_endian.h index 5cfa32e30c..a1a11df090 100644 --- a/include/SDL_endian.h +++ b/include/SDL_endian.h @@ -66,29 +66,24 @@ extern "C" { /** * \file SDL_endian.h - * - * Uses inline functions for compilers that support them, and static - * functions for those that do not. Because these functions become - * static for compilers that do not support inline functions, this - * header should only be included in files that actually use them. */ #if defined(__GNUC__) && defined(__i386__) && \ !(__GNUC__ == 2 && __GNUC_MINOR__ == 95 /* broken gcc version */) -static __inline__ Uint16 +SDL_FORCE_INLINE Uint16 SDL_Swap16(Uint16 x) { __asm__("xchgb %b0,%h0": "=q"(x):"0"(x)); return x; } #elif defined(__GNUC__) && defined(__x86_64__) -static __inline__ Uint16 +SDL_FORCE_INLINE Uint16 SDL_Swap16(Uint16 x) { __asm__("xchgb %b0,%h0": "=Q"(x):"0"(x)); return x; } #elif defined(__GNUC__) && (defined(__powerpc__) || defined(__ppc__)) -static __inline__ Uint16 +SDL_FORCE_INLINE Uint16 SDL_Swap16(Uint16 x) { int result; @@ -97,14 +92,14 @@ SDL_Swap16(Uint16 x) return (Uint16)result; } #elif defined(__GNUC__) && (defined(__M68000__) || defined(__M68020__)) && !defined(__mcoldfire__) -static __inline__ Uint16 +SDL_FORCE_INLINE Uint16 SDL_Swap16(Uint16 x) { __asm__("rorw #8,%0": "=d"(x): "0"(x):"cc"); return x; } #else -static __inline__ Uint16 +SDL_FORCE_INLINE Uint16 SDL_Swap16(Uint16 x) { return SDL_static_cast(Uint16, ((x << 8) | (x >> 8))); @@ -112,21 +107,21 @@ SDL_Swap16(Uint16 x) #endif #if defined(__GNUC__) && defined(__i386__) -static __inline__ Uint32 +SDL_FORCE_INLINE Uint32 SDL_Swap32(Uint32 x) { __asm__("bswap %0": "=r"(x):"0"(x)); return x; } #elif defined(__GNUC__) && defined(__x86_64__) -static __inline__ Uint32 +SDL_FORCE_INLINE Uint32 SDL_Swap32(Uint32 x) { __asm__("bswapl %0": "=r"(x):"0"(x)); return x; } #elif defined(__GNUC__) && (defined(__powerpc__) || defined(__ppc__)) -static __inline__ Uint32 +SDL_FORCE_INLINE Uint32 SDL_Swap32(Uint32 x) { Uint32 result; @@ -137,14 +132,14 @@ SDL_Swap32(Uint32 x) return result; } #elif defined(__GNUC__) && (defined(__M68000__) || defined(__M68020__)) && !defined(__mcoldfire__) -static __inline__ Uint32 +SDL_FORCE_INLINE Uint32 SDL_Swap32(Uint32 x) { __asm__("rorw #8,%0\n\tswap %0\n\trorw #8,%0": "=d"(x): "0"(x):"cc"); return x; } #else -static __inline__ Uint32 +SDL_FORCE_INLINE Uint32 SDL_Swap32(Uint32 x) { return SDL_static_cast(Uint32, ((x << 24) | ((x << 8) & 0x00FF0000) | @@ -153,7 +148,7 @@ SDL_Swap32(Uint32 x) #endif #if defined(__GNUC__) && defined(__i386__) -static __inline__ Uint64 +SDL_FORCE_INLINE Uint64 SDL_Swap64(Uint64 x) { union @@ -171,14 +166,14 @@ SDL_Swap64(Uint64 x) return v.u; } #elif defined(__GNUC__) && defined(__x86_64__) -static __inline__ Uint64 +SDL_FORCE_INLINE Uint64 SDL_Swap64(Uint64 x) { __asm__("bswapq %0": "=r"(x):"0"(x)); return x; } #else -static __inline__ Uint64 +SDL_FORCE_INLINE Uint64 SDL_Swap64(Uint64 x) { Uint32 hi, lo; @@ -195,7 +190,7 @@ SDL_Swap64(Uint64 x) #endif -static __inline__ float +SDL_FORCE_INLINE float SDL_SwapFloat(float x) { union diff --git a/include/SDL_error.h b/include/SDL_error.h index fe7f762cd6..81c64da66f 100644 --- a/include/SDL_error.h +++ b/include/SDL_error.h @@ -39,7 +39,8 @@ extern "C" { #endif /* Public functions */ -extern DECLSPEC void SDLCALL SDL_SetError(const char *fmt, ...); +/* SDL_SetError() unconditionally returns -1. */ +extern DECLSPEC int SDLCALL SDL_SetError(const char *fmt, ...); extern DECLSPEC const char *SDLCALL SDL_GetError(void); extern DECLSPEC void SDLCALL SDL_ClearError(void); @@ -62,7 +63,8 @@ typedef enum SDL_UNSUPPORTED, SDL_LASTERROR } SDL_errorcode; -extern DECLSPEC void SDLCALL SDL_Error(SDL_errorcode code); +/* SDL_Error() unconditionally returns -1. */ +extern DECLSPEC int SDLCALL SDL_Error(SDL_errorcode code); /*@}*//*Internal error functions*/ /* Ends C function definitions when using C++ */ diff --git a/include/SDL_events.h b/include/SDL_events.h index 4065e2b931..205467e9a7 100644 --- a/include/SDL_events.h +++ b/include/SDL_events.h @@ -77,14 +77,6 @@ typedef enum SDL_MOUSEBUTTONUP, /**< Mouse button released */ SDL_MOUSEWHEEL, /**< Mouse wheel motion */ - /* Tablet or multiple mice input device events */ - SDL_INPUTMOTION = 0x500, /**< Input moved */ - SDL_INPUTBUTTONDOWN, /**< Input button pressed */ - SDL_INPUTBUTTONUP, /**< Input button released */ - SDL_INPUTWHEEL, /**< Input wheel motion */ - SDL_INPUTPROXIMITYIN, /**< Input pen entered proximity */ - SDL_INPUTPROXIMITYOUT, /**< Input pen left proximity */ - /* Joystick events */ SDL_JOYAXISMOTION = 0x600, /**< Joystick axis motion */ SDL_JOYBALLMOTION, /**< Joystick trackball motion */ @@ -100,13 +92,12 @@ typedef enum SDL_CONTROLLERBUTTONUP, /**< Game controller button released */ SDL_CONTROLLERDEVICEADDED, /**< A new Game controller has been inserted into the system */ SDL_CONTROLLERDEVICEREMOVED, /**< An opened Game controller has been removed */ + SDL_CONTROLLERDEVICEREMAPPED, /**< The controller mapping was updated */ /* Touch events */ SDL_FINGERDOWN = 0x700, SDL_FINGERUP, SDL_FINGERMOTION, - SDL_TOUCHBUTTONDOWN, - SDL_TOUCHBUTTONUP, /* Gesture events */ SDL_DOLLARGESTURE = 0x800, @@ -131,6 +122,15 @@ typedef enum } SDL_EventType; /** + * \brief Fields shared by every event + */ +typedef struct SDL_GenericEvent +{ + Uint32 type; + Uint32 timestamp; +} SDL_GenericEvent; + +/** * \brief Window state change event data (event.window.*) */ typedef struct SDL_WindowEvent @@ -142,8 +142,8 @@ typedef struct SDL_WindowEvent Uint8 padding1; Uint8 padding2; Uint8 padding3; - int data1; /**< event dependent data */ - int data2; /**< event dependent data */ + Sint32 data1; /**< event dependent data */ + Sint32 data2; /**< event dependent data */ } SDL_WindowEvent; /** @@ -171,8 +171,8 @@ typedef struct SDL_TextEditingEvent Uint32 timestamp; Uint32 windowID; /**< The window with keyboard focus, if any */ char text[SDL_TEXTEDITINGEVENT_TEXT_SIZE]; /**< The editing text */ - int start; /**< The start cursor of selected editing text */ - int length; /**< The length of selected editing text */ + Sint32 start; /**< The start cursor of selected editing text */ + Sint32 length; /**< The length of selected editing text */ } SDL_TextEditingEvent; @@ -196,14 +196,15 @@ typedef struct SDL_MouseMotionEvent Uint32 type; /**< ::SDL_MOUSEMOTION */ Uint32 timestamp; Uint32 windowID; /**< The window with mouse focus, if any */ + Uint32 which; /**< The mouse instance id, or SDL_TOUCH_MOUSEID */ Uint8 state; /**< The current button state */ Uint8 padding1; Uint8 padding2; Uint8 padding3; - int x; /**< X coordinate, relative to window */ - int y; /**< Y coordinate, relative to window */ - int xrel; /**< The relative motion in the X direction */ - int yrel; /**< The relative motion in the Y direction */ + Sint32 x; /**< X coordinate, relative to window */ + Sint32 y; /**< Y coordinate, relative to window */ + Sint32 xrel; /**< The relative motion in the X direction */ + Sint32 yrel; /**< The relative motion in the Y direction */ } SDL_MouseMotionEvent; /** @@ -214,12 +215,13 @@ typedef struct SDL_MouseButtonEvent Uint32 type; /**< ::SDL_MOUSEBUTTONDOWN or ::SDL_MOUSEBUTTONUP */ Uint32 timestamp; Uint32 windowID; /**< The window with mouse focus, if any */ + Uint32 which; /**< The mouse instance id, or SDL_TOUCH_MOUSEID */ Uint8 button; /**< The mouse button index */ Uint8 state; /**< ::SDL_PRESSED or ::SDL_RELEASED */ Uint8 padding1; Uint8 padding2; - int x; /**< X coordinate, relative to window */ - int y; /**< Y coordinate, relative to window */ + Sint32 x; /**< X coordinate, relative to window */ + Sint32 y; /**< Y coordinate, relative to window */ } SDL_MouseButtonEvent; /** @@ -230,8 +232,9 @@ typedef struct SDL_MouseWheelEvent Uint32 type; /**< ::SDL_MOUSEWHEEL */ Uint32 timestamp; Uint32 windowID; /**< The window with mouse focus, if any */ - int x; /**< The amount scrolled horizontally */ - int y; /**< The amount scrolled vertically */ + Uint32 which; /**< The mouse instance id, or SDL_TOUCH_MOUSEID */ + Sint32 x; /**< The amount scrolled horizontally */ + Sint32 y; /**< The amount scrolled vertically */ } SDL_MouseWheelEvent; /** @@ -241,11 +244,13 @@ typedef struct SDL_JoyAxisEvent { Uint32 type; /**< ::SDL_JOYAXISMOTION */ Uint32 timestamp; - Uint8 which; /**< The joystick instance id */ + SDL_JoystickID which; /**< The joystick instance id */ Uint8 axis; /**< The joystick axis index */ Uint8 padding1; Uint8 padding2; - int value; /**< The axis value (range: -32768 to 32767) */ + Uint8 padding3; + Sint16 value; /**< The axis value (range: -32768 to 32767) */ + Uint16 padding4; } SDL_JoyAxisEvent; /** @@ -254,13 +259,14 @@ typedef struct SDL_JoyAxisEvent typedef struct SDL_JoyBallEvent { Uint32 type; /**< ::SDL_JOYBALLMOTION */ - Uint32 timestamp; - Uint8 which; /**< The joystick instance id */ + Uint32 timestamp; + SDL_JoystickID which; /**< The joystick instance id */ Uint8 ball; /**< The joystick trackball index */ Uint8 padding1; Uint8 padding2; - int xrel; /**< The relative motion in the X direction */ - int yrel; /**< The relative motion in the Y direction */ + Uint8 padding3; + Sint16 xrel; /**< The relative motion in the X direction */ + Sint16 yrel; /**< The relative motion in the Y direction */ } SDL_JoyBallEvent; /** @@ -269,8 +275,8 @@ typedef struct SDL_JoyBallEvent typedef struct SDL_JoyHatEvent { Uint32 type; /**< ::SDL_JOYHATMOTION */ - Uint32 timestamp; - Uint8 which; /**< The joystick instance id */ + Uint32 timestamp; + SDL_JoystickID which; /**< The joystick instance id */ Uint8 hat; /**< The joystick hat index */ Uint8 value; /**< The hat position value. * \sa ::SDL_HAT_LEFTUP ::SDL_HAT_UP ::SDL_HAT_RIGHTUP @@ -280,6 +286,7 @@ typedef struct SDL_JoyHatEvent * Note that zero means the POV is centered. */ Uint8 padding1; + Uint8 padding2; } SDL_JoyHatEvent; /** @@ -288,11 +295,12 @@ typedef struct SDL_JoyHatEvent typedef struct SDL_JoyButtonEvent { Uint32 type; /**< ::SDL_JOYBUTTONDOWN or ::SDL_JOYBUTTONUP */ - Uint32 timestamp; - Uint8 which; /**< The joystick instance id */ + Uint32 timestamp; + SDL_JoystickID which; /**< The joystick instance id */ Uint8 button; /**< The joystick button index */ Uint8 state; /**< ::SDL_PRESSED or ::SDL_RELEASED */ Uint8 padding1; + Uint8 padding2; } SDL_JoyButtonEvent; /** @@ -302,7 +310,7 @@ typedef struct SDL_JoyDeviceEvent { Uint32 type; /**< ::SDL_JOYDEVICEADDED or ::SDL_JOYDEVICEREMOVED */ Uint32 timestamp; - Uint32 which; /**< The joystick device index for ADD, instance_id for REMOVE*/ + Sint32 which; /**< The joystick device index for the ADDED event, instance id for the REMOVED event */ } SDL_JoyDeviceEvent; @@ -312,10 +320,14 @@ typedef struct SDL_JoyDeviceEvent typedef struct SDL_ControllerAxisEvent { Uint32 type; /**< ::SDL_CONTROLLERAXISMOTION */ - Uint32 timestamp; - Uint8 which; /**< The joystick instance id */ - SDL_CONTROLLER_AXIS axis; /**< The joystick axis index */ - int value; /**< The axis value (range: -32768 to 32767) */ + Uint32 timestamp; + SDL_JoystickID which; /**< The joystick instance id */ + Uint8 axis; /**< The controller axis (SDL_GameControllerAxis) */ + Uint8 padding1; + Uint8 padding2; + Uint8 padding3; + Sint16 value; /**< The axis value (range: -32768 to 32767) */ + Uint16 padding4; } SDL_ControllerAxisEvent; @@ -325,10 +337,12 @@ typedef struct SDL_ControllerAxisEvent typedef struct SDL_ControllerButtonEvent { Uint32 type; /**< ::SDL_CONTROLLERBUTTONDOWN or ::SDL_CONTROLLERBUTTONUP */ - Uint32 timestamp; - Uint8 which; /**< The joystick instance id */ - SDL_CONTROLLER_BUTTON button; /**< The joystick button index */ + Uint32 timestamp; + SDL_JoystickID which; /**< The joystick instance id */ + Uint8 button; /**< The controller button (SDL_GameControllerButton) */ Uint8 state; /**< ::SDL_PRESSED or ::SDL_RELEASED */ + Uint8 padding1; + Uint8 padding2; } SDL_ControllerButtonEvent; @@ -337,83 +351,57 @@ typedef struct SDL_ControllerButtonEvent */ typedef struct SDL_ControllerDeviceEvent { - Uint32 type; /**< ::SDL_CONTROLLERDEVICEADDED or ::SDL_CONTROLLERDEVICEREMOVED */ + Uint32 type; /**< ::SDL_CONTROLLERDEVICEADDED, ::SDL_CONTROLLERDEVICEREMOVED, or ::SDL_CONTROLLERDEVICEREMAPPED */ Uint32 timestamp; - Uint32 which; /**< The joystick device index for ADD, instance_id for REMOVE*/ + Sint32 which; /**< The joystick device index for the ADDED event, instance id for the REMOVED or REMAPPED event */ } SDL_ControllerDeviceEvent; /** - * \brief Touch finger motion/finger event structure (event.tfinger.*) + * \brief Touch finger event structure (event.tfinger.*) */ typedef struct SDL_TouchFingerEvent { - Uint32 type; /**< ::SDL_FINGERMOTION OR - SDL_FINGERDOWN OR SDL_FINGERUP*/ + Uint32 type; /**< ::SDL_FINGERMOTION or ::SDL_FINGERDOWN or ::SDL_FINGERUP */ Uint32 timestamp; - Uint32 windowID; /**< The window with mouse focus, if any */ - SDL_TouchID touchId; /**< The touch device id */ + SDL_TouchID touchId; /**< The touch device id */ SDL_FingerID fingerId; - Uint8 state; /**< The current button state */ - Uint8 padding1; - Uint8 padding2; - Uint8 padding3; - Uint16 x; - Uint16 y; - Sint16 dx; - Sint16 dy; - Uint16 pressure; + float x; /**< Normalized in the range 0...1 */ + float y; /**< Normalized in the range 0...1 */ + float dx; /**< Normalized in the range 0...1 */ + float dy; /**< Normalized in the range 0...1 */ + float pressure; /**< Normalized in the range 0...1 */ } SDL_TouchFingerEvent; /** - * \brief Touch finger motion/finger event structure (event.tbutton.*) - */ -typedef struct SDL_TouchButtonEvent -{ - Uint32 type; /**< ::SDL_TOUCHBUTTONUP OR SDL_TOUCHBUTTONDOWN */ - Uint32 timestamp; - Uint32 windowID; /**< The window with mouse focus, if any */ - SDL_TouchID touchId; /**< The touch device index */ - Uint8 state; /**< The current button state */ - Uint8 button; /**< The button changing state */ - Uint8 padding1; - Uint8 padding2; -} SDL_TouchButtonEvent; - - -/** * \brief Multiple Finger Gesture Event (event.mgesture.*) */ typedef struct SDL_MultiGestureEvent { Uint32 type; /**< ::SDL_MULTIGESTURE */ Uint32 timestamp; - Uint32 windowID; /**< The window with mouse focus, if any */ - SDL_TouchID touchId; /**< The touch device index */ + SDL_TouchID touchId; /**< The touch device index */ float dTheta; float dDist; - float x; /* currently 0...1. Change to screen coords? */ + float x; float y; Uint16 numFingers; Uint16 padding; } SDL_MultiGestureEvent; + /* (event.dgesture.*) */ typedef struct SDL_DollarGestureEvent { Uint32 type; /**< ::SDL_DOLLARGESTURE */ Uint32 timestamp; - Uint32 windowID; /**< The window with mouse focus, if any */ - SDL_TouchID touchId; /**< The touch device index */ + SDL_TouchID touchId; /**< The touch device id */ SDL_GestureID gestureId; Uint32 numFingers; float error; - /* - //TODO: Enable to give location? - float x; //currently 0...1. Change to screen coords? - float y; - */ + float x; /**< Normalized center of gesture */ + float y; /**< Normalized center of gesture */ } SDL_DollarGestureEvent; @@ -448,7 +436,7 @@ typedef struct SDL_UserEvent Uint32 type; /**< ::SDL_USEREVENT through ::SDL_NUMEVENTS-1 */ Uint32 timestamp; Uint32 windowID; /**< The associated window if any */ - int code; /**< User defined event code */ + Sint32 code; /**< User defined event code */ void *data1; /**< User defined data pointer */ void *data2; /**< User defined data pointer */ } SDL_UserEvent; @@ -476,6 +464,7 @@ typedef struct SDL_SysWMEvent typedef union SDL_Event { Uint32 type; /**< Event type, shared with all events */ + SDL_GenericEvent generic; /**< Generic event data */ SDL_WindowEvent window; /**< Window event data */ SDL_KeyboardEvent key; /**< Keyboard event data */ SDL_TextEditingEvent edit; /**< Text editing event data */ @@ -488,16 +477,15 @@ typedef union SDL_Event SDL_JoyHatEvent jhat; /**< Joystick hat event data */ SDL_JoyButtonEvent jbutton; /**< Joystick button event data */ SDL_JoyDeviceEvent jdevice; /**< Joystick device change event data */ - SDL_ControllerAxisEvent caxis; /**< Game Controller button event data */ + SDL_ControllerAxisEvent caxis; /**< Game Controller axis event data */ SDL_ControllerButtonEvent cbutton; /**< Game Controller button event data */ SDL_ControllerDeviceEvent cdevice; /**< Game Controller device event data */ SDL_QuitEvent quit; /**< Quit request event data */ SDL_UserEvent user; /**< Custom event data */ SDL_SysWMEvent syswm; /**< System dependent window event data */ SDL_TouchFingerEvent tfinger; /**< Touch finger event data */ - SDL_TouchButtonEvent tbutton; /**< Touch button event data */ - SDL_MultiGestureEvent mgesture; /**< Multi Finger Gesture data */ - SDL_DollarGestureEvent dgesture; /**< Multi Finger Gesture data */ + SDL_MultiGestureEvent mgesture; /**< Gesture event data */ + SDL_DollarGestureEvent dgesture; /**< Gesture event data */ SDL_DropEvent drop; /**< Drag and drop event data */ /* This is necessary for ABI compatibility between Visual C++ and GCC diff --git a/include/SDL_gamecontroller.h b/include/SDL_gamecontroller.h index 1969a2914b..b90c4009f9 100644 --- a/include/SDL_gamecontroller.h +++ b/include/SDL_gamecontroller.h @@ -59,25 +59,23 @@ typedef enum SDL_CONTROLLER_BINDTYPE_BUTTON, SDL_CONTROLLER_BINDTYPE_AXIS, SDL_CONTROLLER_BINDTYPE_HAT -} SDL_CONTROLLER_BINDTYPE; +} SDL_GameControllerBindType; + /** - * get the sdl joystick layer binding for this controller button/axis mapping + * Get the SDL joystick layer binding for this controller button/axis mapping */ -struct _SDL_GameControllerHatBind -{ - int hat; - int hat_mask; -}; - -typedef struct _SDL_GameControllerButtonBind +typedef struct SDL_GameControllerButtonBind { - SDL_CONTROLLER_BINDTYPE m_eBindType; + SDL_GameControllerBindType bindType; union { int button; int axis; - struct _SDL_GameControllerHatBind hat; - }; + struct { + int hat; + int hat_mask; + } hat; + } value; } SDL_GameControllerButtonBind; @@ -92,7 +90,7 @@ typedef struct _SDL_GameControllerButtonBind * } * } * - * Using the SDL_HINT_GAMECONTROLLERCONFIG hint you can add support for controllers SDL is unaware of or cause an existing controller to have a different binding. The format is: + * Using the SDL_HINT_GAMECONTROLLERCONFIG hint or the SDL_GameControllerAddMapping you can add support for controllers SDL is unaware of or cause an existing controller to have a different binding. The format is: * guid,name,mappings * * Where GUID is the string value from SDL_JoystickGetGUIDString(), name is the human readable string for the device and mappings are controller mappings to joystick ones. @@ -108,6 +106,26 @@ typedef struct _SDL_GameControllerButtonBind * */ +/** + * Add or update an existing mapping configuration + * + * \return 1 if mapping is added, 0 if updated, -1 on error + */ +extern DECLSPEC int SDLCALL SDL_GameControllerAddMapping( const char* mappingString ); + +/** + * Get a mapping string for a GUID + * + * \return the mapping string. Must be freed with SDL_free. Returns NULL if no mapping is available + */ +extern DECLSPEC char * SDLCALL SDL_GameControllerMappingForGUID( SDL_JoystickGUID guid ); + +/** + * Get a mapping string for an open GameController + * + * \return the mapping string. Must be freed with SDL_free. Returns NULL if no mapping is available + */ +extern DECLSPEC char * SDLCALL SDL_GameControllerMapping( SDL_GameController * gamecontroller ); /** * Is the joystick on this index supported by the game controller interface? @@ -160,6 +178,15 @@ extern DECLSPEC SDL_Joystick *SDLCALL SDL_GameControllerGetJoystick(SDL_GameCont extern DECLSPEC int SDLCALL SDL_GameControllerEventState(int state); /** + * Update the current state of the open game controllers. + * + * This is called automatically by the event loop if any game controller + * events are enabled. + */ +extern DECLSPEC void SDLCALL SDL_GameControllerUpdate(void); + + +/** * The list of axii available from a controller */ typedef enum @@ -172,19 +199,24 @@ typedef enum SDL_CONTROLLER_AXIS_TRIGGERLEFT, SDL_CONTROLLER_AXIS_TRIGGERRIGHT, SDL_CONTROLLER_AXIS_MAX -} SDL_CONTROLLER_AXIS; +} SDL_GameControllerAxis; /** * turn this string into a axis mapping */ -extern DECLSPEC SDL_CONTROLLER_AXIS SDLCALL SDL_GameControllerGetAxisFromString(const char *pchString); +extern DECLSPEC SDL_GameControllerAxis SDLCALL SDL_GameControllerGetAxisFromString(const char *pchString); /** - * get the sdl joystick layer binding for this controller button mapping + * turn this axis enum into a string mapping + */ +extern DECLSPEC const char* SDLCALL SDL_GameControllerGetStringForAxis(SDL_GameControllerAxis axis); + +/** + * Get the SDL joystick layer binding for this controller button mapping */ extern DECLSPEC SDL_GameControllerButtonBind SDLCALL SDL_GameControllerGetBindForAxis(SDL_GameController *gamecontroller, - SDL_CONTROLLER_AXIS button); + SDL_GameControllerAxis axis); /** * Get the current state of an axis control on a game controller. @@ -195,7 +227,7 @@ SDL_GameControllerGetBindForAxis(SDL_GameController *gamecontroller, */ extern DECLSPEC Sint16 SDLCALL SDL_GameControllerGetAxis(SDL_GameController *gamecontroller, - SDL_CONTROLLER_AXIS axis); + SDL_GameControllerAxis axis); /** * The list of buttons available from a controller @@ -219,20 +251,24 @@ typedef enum SDL_CONTROLLER_BUTTON_DPAD_LEFT, SDL_CONTROLLER_BUTTON_DPAD_RIGHT, SDL_CONTROLLER_BUTTON_MAX -} SDL_CONTROLLER_BUTTON; +} SDL_GameControllerButton; /** * turn this string into a button mapping */ -extern DECLSPEC SDL_CONTROLLER_BUTTON SDLCALL SDL_GameControllerGetButtonFromString(const char *pchString); +extern DECLSPEC SDL_GameControllerButton SDLCALL SDL_GameControllerGetButtonFromString(const char *pchString); +/** + * turn this button enum into a string mapping + */ +extern DECLSPEC const char* SDLCALL SDL_GameControllerGetStringForButton(SDL_GameControllerButton button); /** - * get the sdl joystick layer binding for this controller button mapping + * Get the SDL joystick layer binding for this controller button mapping */ extern DECLSPEC SDL_GameControllerButtonBind SDLCALL SDL_GameControllerGetBindForButton(SDL_GameController *gamecontroller, - SDL_CONTROLLER_BUTTON button); + SDL_GameControllerButton button); /** @@ -241,7 +277,7 @@ SDL_GameControllerGetBindForButton(SDL_GameController *gamecontroller, * The button indices start at index 0. */ extern DECLSPEC Uint8 SDLCALL SDL_GameControllerGetButton(SDL_GameController *gamecontroller, - SDL_CONTROLLER_BUTTON button); + SDL_GameControllerButton button); /** * Close a controller previously opened with SDL_GameControllerOpen(). diff --git a/include/SDL_hints.h b/include/SDL_hints.h index 1d4a3e5a74..315a33133a 100644 --- a/include/SDL_hints.h +++ b/include/SDL_hints.h @@ -197,9 +197,22 @@ extern "C" { /** + * \brief A variable that lets you disable the detection and use of Xinput gamepad devices + * + * The variable can be set to the following values: + * "0" - Disable XInput timer (only uses direct input) + * "1" - Enable XInput timer (the default) + */ +#define SDL_HINT_XINPUT_ENABLED "SDL_XINPUT_ENABLED" + + +/** * \brief A variable that lets you manually hint extra gamecontroller db entries + * + * The variable should be newline delimited rows of gamecontroller config data, see SDL_gamecontroller.h * - * The variable expected newline delimited rows of gamecontroller config data, see SDL_gamecontroller.h + * This hint must be set before calling SDL_Init(SDL_INIT_GAMECONTROLLER) + * You can update mappings after the system is initialized with SDL_GameControllerMappingForGUID() and SDL_GameControllerAddMapping() */ #define SDL_HINT_GAMECONTROLLERCONFIG "SDL_GAMECONTROLLERCONFIG" diff --git a/include/SDL_joystick.h b/include/SDL_joystick.h index 1065f16820..c948c05b32 100644 --- a/include/SDL_joystick.h +++ b/include/SDL_joystick.h @@ -67,7 +67,7 @@ typedef struct { Uint8 data[16]; } SDL_JoystickGUID; -typedef int SDL_JoystickID; +typedef Sint32 SDL_JoystickID; /* Function prototypes */ @@ -126,7 +126,7 @@ extern DECLSPEC SDL_JoystickGUID SDLCALL SDL_JoystickGetGUIDFromString(const cha extern DECLSPEC SDL_bool SDLCALL SDL_JoystickGetAttached(SDL_Joystick * joystick); /** - * Get the instance ID of an opened joystick. + * Get the instance ID of an opened joystick or -1 if the joystick is invalid. */ extern DECLSPEC SDL_JoystickID SDLCALL SDL_JoystickInstanceID(SDL_Joystick * joystick); diff --git a/include/SDL_mutex.h b/include/SDL_mutex.h index 562c3b06f2..30519b87f7 100644 --- a/include/SDL_mutex.h +++ b/include/SDL_mutex.h @@ -70,8 +70,15 @@ extern DECLSPEC SDL_mutex *SDLCALL SDL_CreateMutex(void); * * \return 0, or -1 on error. */ -#define SDL_LockMutex(m) SDL_mutexP(m) -extern DECLSPEC int SDLCALL SDL_mutexP(SDL_mutex * mutex); +#define SDL_mutexP(m) SDL_LockMutex(m) +extern DECLSPEC int SDLCALL SDL_LockMutex(SDL_mutex * mutex); + +/** + * Try to lock the mutex + * + * \return 0, SDL_MUTEX_TIMEDOUT, or -1 on error + */ +extern DECLSPEC int SDLCALL SDL_TryLockMutex(SDL_mutex * mutex); /** * Unlock the mutex. @@ -81,8 +88,8 @@ extern DECLSPEC int SDLCALL SDL_mutexP(SDL_mutex * mutex); * \warning It is an error to unlock a mutex that has not been locked by * the current thread, and doing so results in undefined behavior. */ -#define SDL_UnlockMutex(m) SDL_mutexV(m) -extern DECLSPEC int SDLCALL SDL_mutexV(SDL_mutex * mutex); +#define SDL_mutexV(m) SDL_UnlockMutex(m) +extern DECLSPEC int SDLCALL SDL_UnlockMutex(SDL_mutex * mutex); /** * Destroy a mutex. diff --git a/include/SDL_opengl.h b/include/SDL_opengl.h index 0e0394d2c0..079ed74e1b 100644 --- a/include/SDL_opengl.h +++ b/include/SDL_opengl.h @@ -44,10 +44,6 @@ #define NO_SDL_GLEXT 1 #endif -#ifdef __FreeBSD__ /* !!! FIXME: temp compiler warning fix... */ -#define NO_SDL_GLEXT 1 -#endif - #ifdef __glext_h_ /* Someone has already included glext.h */ #define NO_SDL_GLEXT diff --git a/include/SDL_pixels.h b/include/SDL_pixels.h index 14bac9bcb0..e73215260d 100644 --- a/include/SDL_pixels.h +++ b/include/SDL_pixels.h @@ -256,7 +256,7 @@ typedef struct SDL_Color Uint8 r; Uint8 g; Uint8 b; - Uint8 unused; + Uint8 a; } SDL_Color; #define SDL_Colour SDL_Color diff --git a/include/SDL_platform.h b/include/SDL_platform.h index ddccc90f15..e1794cd822 100644 --- a/include/SDL_platform.h +++ b/include/SDL_platform.h @@ -138,12 +138,10 @@ #endif /* if ! defined(WINAPI_FAMILY_PARTITION) ; else */ #endif /* if defined(WIN32) || defined(_WIN32) */ -#if defined(__NDS__) -#undef __NINTENDODS__ -#define __NINTENDODS__ 1 +#if defined(__PSP__) +#define __PSP__ 1 #endif - #include "begin_code.h" /* Set up for C function definitions, even when using C++ */ #ifdef __cplusplus diff --git a/include/SDL_rwops.h b/include/SDL_rwops.h index 933397bdf7..acc499ffbc 100644 --- a/include/SDL_rwops.h +++ b/include/SDL_rwops.h @@ -40,6 +40,14 @@ extern "C" { /* *INDENT-ON* */ #endif +/* RWops Types */ +#define SDL_RWOPS_UNKNOWN 0 /* Unknown stream type */ +#define SDL_RWOPS_WINFILE 1 /* Win32 file */ +#define SDL_RWOPS_STDFILE 2 /* Stdio file */ +#define SDL_RWOPS_JNIFILE 3 /* Android asset */ +#define SDL_RWOPS_MEMORY 4 /* Memory stream */ +#define SDL_RWOPS_MEMORY_RO 5 /* Read-Only memory stream */ + /** * This is the read/write operation structure -- very basic. */ @@ -54,7 +62,7 @@ typedef struct SDL_RWops * Seek to \c offset relative to \c whence, one of stdio's whence values: * RW_SEEK_SET, RW_SEEK_CUR, RW_SEEK_END * - * \return the final offset in the data stream. + * \return the final offset in the data stream, or -1 on error. */ Sint64 (SDLCALL * seek) (struct SDL_RWops * context, Sint64 offset, int whence); @@ -130,6 +138,7 @@ typedef struct SDL_RWops struct { void *data1; + int data2; } unknown; } hidden; diff --git a/include/SDL_scancode.h b/include/SDL_scancode.h index 32d9f4c718..26b8f36b56 100644 --- a/include/SDL_scancode.h +++ b/include/SDL_scancode.h @@ -38,7 +38,7 @@ * SDL_Event structure. * * The values in this enumeration are based on the USB usage page standard: - * http://www.usb.org/developers/devclass_docs/Hut1_12.pdf + * http://www.usb.org/developers/devclass_docs/Hut1_12v2.pdf */ typedef enum { @@ -385,6 +385,9 @@ typedef enum SDL_SCANCODE_EJECT = 281, SDL_SCANCODE_SLEEP = 282, + SDL_SCANCODE_APP1 = 283, + SDL_SCANCODE_APP2 = 284, + /*@}*//*Walther keys*/ /* Add any other keys here. */ diff --git a/include/SDL_stdinc.h b/include/SDL_stdinc.h index 380695a460..89a220a167 100644 --- a/include/SDL_stdinc.h +++ b/include/SDL_stdinc.h @@ -30,7 +30,6 @@ #include "SDL_config.h" - #ifdef HAVE_SYS_TYPES_H #include <sys/types.h> #endif @@ -182,14 +181,10 @@ SDL_COMPILE_TIME_ASSERT(sint64, sizeof(Sint64) == 8); enums having the size of an int must be enabled. This is "-b" for Borland C/C++ and "-ei" for Watcom C/C++ (v11). */ -/* Enable enums always int in CodeWarrior (for MPW use "-enum int") */ -#ifdef __MWERKS__ -#pragma enumsalwaysint on -#endif /** \cond */ #ifndef DOXYGEN_SHOULD_IGNORE_THIS -#if !defined(__NINTENDODS__) && !defined(__ANDROID__) +#if !defined(__ANDROID__) /* TODO: include/SDL_stdinc.h:174: error: size of array 'SDL_dummy_enum' is negative */ typedef enum { @@ -209,30 +204,6 @@ extern "C" { /* *INDENT-ON* */ #endif -#ifdef HAVE_MALLOC -#define SDL_malloc malloc -#else -extern DECLSPEC void *SDLCALL SDL_malloc(size_t size); -#endif - -#ifdef HAVE_CALLOC -#define SDL_calloc calloc -#else -extern DECLSPEC void *SDLCALL SDL_calloc(size_t nmemb, size_t size); -#endif - -#ifdef HAVE_REALLOC -#define SDL_realloc realloc -#else -extern DECLSPEC void *SDLCALL SDL_realloc(void *mem, size_t size); -#endif - -#ifdef HAVE_FREE -#define SDL_free free -#else -extern DECLSPEC void SDLCALL SDL_free(void *mem); -#endif - #if defined(HAVE_ALLOCA) && !defined(alloca) # if defined(HAVE_ALLOCA_H) # include <alloca.h> @@ -263,380 +234,460 @@ char *alloca(); #define SDL_stack_free(data) SDL_free(data) #endif -#ifdef HAVE_GETENV -#define SDL_getenv getenv -#else + +/* SDL stdinc inline functions: + + The theory here is that by default we forcibly inline what we can, and your + app will use the inline version by default. However we expose a non-inline + version too, so the symbol is always available in the library even if your app + bypassed the inline version. The SDL_*_inline versions aren't guaranteed to + exist, so never call them directly; use SDL_* instead, and trust the system + to give you the right thing. + + The benefit here is that you can dlsym() these functions, which you + couldn't if you had macros, you can link against a foreign build of SDL + even if you configured differently, and you can drop the unconfigured SDL + headers into a project without #defining HAVE_MALLOC (etc) and still link. +*/ + +extern DECLSPEC void *SDLCALL SDL_malloc(size_t size); +#ifdef HAVE_MALLOC +SDL_FORCE_INLINE void *SDL_malloc_inline(size_t size) { return malloc(size); } +#define SDL_malloc SDL_malloc_inline +#endif + +extern DECLSPEC void *SDLCALL SDL_calloc(size_t nmemb, size_t size); +#ifdef HAVE_CALLOC +SDL_FORCE_INLINE void *SDL_calloc_inline(size_t nmemb, size_t size) { return calloc(nmemb, size); } +#define SDL_calloc SDL_calloc_inline +#endif + +extern DECLSPEC void *SDLCALL SDL_realloc(void *mem, size_t size); +#ifdef HAVE_REALLOC +SDL_FORCE_INLINE void *SDL_realloc_inline(void *mem, size_t size) { return realloc(mem, size); } +#define SDL_realloc SDL_realloc_inline +#endif + +extern DECLSPEC void SDLCALL SDL_free(void *mem); +#ifdef HAVE_FREE +SDL_FORCE_INLINE void SDL_free_inline(void *mem) { free(mem); } +#define SDL_free SDL_free_inline +#endif + extern DECLSPEC char *SDLCALL SDL_getenv(const char *name); +#ifdef HAVE_GETENV +SDL_FORCE_INLINE char *SDL_getenv_inline(const char *name) { return getenv(name); } +#define SDL_getenv SDL_getenv_inline #endif -/* SDL_putenv() has moved to SDL_compat. */ +extern DECLSPEC int SDLCALL SDL_setenv(const char *name, const char *value, int overwrite); #ifdef HAVE_SETENV -#define SDL_setenv setenv -#else -extern DECLSPEC int SDLCALL SDL_setenv(const char *name, const char *value, - int overwrite); +SDL_FORCE_INLINE int SDL_setenv_inline(const char *name, const char *value, int overwrite) { return setenv(name, value, overwrite); } +#define SDL_setenv SDL_setenv_inline #endif +extern DECLSPEC void SDLCALL SDL_qsort(void *base, size_t nmemb, size_t size, int (*compare) (const void *, const void *)); #ifdef HAVE_QSORT -#define SDL_qsort qsort -#else -extern DECLSPEC void SDLCALL SDL_qsort(void *base, size_t nmemb, size_t size, - int (*compare) (const void *, - const void *)); +SDL_FORCE_INLINE void SDL_qsort_inline(void *base, size_t nmemb, size_t size, int (*compare) (const void *, const void *)) { qsort(base, nmemb, size, compare); } +#define SDL_qsort SDL_qsort_inline #endif +extern DECLSPEC int SDLCALL SDL_abs(int x); #ifdef HAVE_ABS -#define SDL_abs abs +SDL_FORCE_INLINE int SDL_abs_inline(int x) { return abs(x); } #else -#define SDL_abs(X) ((X) < 0 ? -(X) : (X)) +SDL_FORCE_INLINE int SDL_abs_inline(int x) { return ((x) < 0 ? -(x) : (x)); } #endif +#define SDL_abs SDL_abs_inline -#define SDL_min(x, y) (((x) < (y)) ? (x) : (y)) -#define SDL_max(x, y) (((x) > (y)) ? (x) : (y)) +/* !!! FIXME: these have side effects. You probably shouldn't use them. */ +/* !!! FIXME: Maybe we do forceinline functions of SDL_mini, SDL_minf, etc? */ +#define SDL_min(x, y) (((x) < (y)) ? (x) : (y)) +#define SDL_max(x, y) (((x) > (y)) ? (x) : (y)) +extern DECLSPEC int SDLCALL SDL_isdigit(int x); +extern DECLSPEC int SDLCALL SDL_isspace(int x); +extern DECLSPEC int SDLCALL SDL_toupper(int x); +extern DECLSPEC int SDLCALL SDL_tolower(int x); #ifdef HAVE_CTYPE_H -#define SDL_isdigit(X) isdigit(X) -#define SDL_isspace(X) isspace(X) -#define SDL_toupper(X) toupper(X) -#define SDL_tolower(X) tolower(X) +SDL_FORCE_INLINE int SDL_isdigit_inline(int x) { return isdigit(x); } +SDL_FORCE_INLINE int SDL_isspace_inline(int x) { return isspace(x); } +SDL_FORCE_INLINE int SDL_toupper_inline(int x) { return toupper(x); } +SDL_FORCE_INLINE int SDL_tolower_inline(int x) { return tolower(x); } #else -#define SDL_isdigit(X) (((X) >= '0') && ((X) <= '9')) -#define SDL_isspace(X) (((X) == ' ') || ((X) == '\t') || ((X) == '\r') || ((X) == '\n')) -#define SDL_toupper(X) (((X) >= 'a') && ((X) <= 'z') ? ('A'+((X)-'a')) : (X)) -#define SDL_tolower(X) (((X) >= 'A') && ((X) <= 'Z') ? ('a'+((X)-'A')) : (X)) +SDL_FORCE_INLINE int SDL_isdigit_inline(int x) { return ((x) >= '0') && ((x) <= '9'); } +SDL_FORCE_INLINE int SDL_isspace_inline(int x) { return ((x) == ' ') || ((x) == '\t') || ((x) == '\r') || ((x) == '\n'); } +SDL_FORCE_INLINE int SDL_toupper_inline(int x) { return ((x) >= 'a') && ((x) <= 'z') ? ('A'+((x)-'a')) : (x); } +SDL_FORCE_INLINE int SDL_tolower_inline(int x) { return ((x) >= 'A') && ((x) <= 'Z') ? ('a'+((x)-'A')) : (x); } #endif +#define SDL_isdigit SDL_isdigit_inline +#define SDL_isspace SDL_isspace_inline +#define SDL_toupper SDL_toupper_inline +#define SDL_tolower SDL_tolower_inline -#ifdef HAVE_MEMSET -#define SDL_memset memset -#else extern DECLSPEC void *SDLCALL SDL_memset(void *dst, int c, size_t len); +#ifdef HAVE_MEMSET +SDL_FORCE_INLINE void *SDL_memset_inline(void *dst, int c, size_t len) { return memset(dst, c, len); } +#define SDL_memset SDL_memset_inline #endif -#define SDL_zero(x) SDL_memset(&(x), 0, sizeof((x))) -#define SDL_zerop(x) SDL_memset((x), 0, sizeof(*(x))) +#define SDL_zero(x) SDL_memset(&(x), 0, sizeof((x))) +#define SDL_zerop(x) SDL_memset((x), 0, sizeof(*(x))) + +/* !!! FIXME: does this _really_ beat memset() on any modern platform? */ +SDL_FORCE_INLINE void SDL_memset4(void *dst, int val, size_t len) +{ #if defined(__GNUC__) && defined(i386) -#define SDL_memset4(dst, val, len) \ -do { \ - int u0, u1, u2; \ - __asm__ __volatile__ ( \ - "cld\n\t" \ - "rep ; stosl\n\t" \ - : "=&D" (u0), "=&a" (u1), "=&c" (u2) \ - : "0" (dst), "1" (val), "2" (SDL_static_cast(Uint32, len)) \ - : "memory" ); \ -} while(0) -#endif -#ifndef SDL_memset4 -#define SDL_memset4(dst, val, len) \ -do { \ - unsigned _count = (len); \ - unsigned _n = (_count + 3) / 4; \ - Uint32 *_p = SDL_static_cast(Uint32 *, dst); \ - Uint32 _val = (val); \ - if (len == 0) break; \ - switch (_count % 4) { \ - case 0: do { *_p++ = _val; \ - case 3: *_p++ = _val; \ - case 2: *_p++ = _val; \ - case 1: *_p++ = _val; \ - } while ( --_n ); \ - } \ -} while(0) -#endif - -/* We can count on memcpy existing on Mac OS X and being well-tuned. */ + int u0, u1, u2; + __asm__ __volatile__ ( + "cld \n\t" + "rep ; stosl \n\t" + : "=&D" (u0), "=&a" (u1), "=&c" (u2) + : "0" (dst), "1" (val), "2" (SDL_static_cast(Uint32, len)) + : "memory" + ); +/* !!! FIXME: amd64? */ +#else + size_t _n = (len + 3) / 4; + Uint32 *_p = SDL_static_cast(Uint32 *, dst); + Uint32 _val = (val); + if (len == 0) + return; + switch (len % 4) + { + case 0: do { *_p++ = _val; + case 3: *_p++ = _val; + case 2: *_p++ = _val; + case 1: *_p++ = _val; + } while ( --_n ); + } +#endif +} + + +extern DECLSPEC void *SDLCALL SDL_memcpy(void *dst, const void *src, size_t len); #if defined(__MACOSX__) -#define SDL_memcpy memcpy +SDL_FORCE_INLINE void *SDL_memcpy_inline(void *dst, const void *src, size_t len) +{ + /* We can count on memcpy existing on Mac OS X and being well-tuned. */ + return memcpy(dst, src, len); +} +#define SDL_memcpy SDL_memcpy_inline #elif defined(__GNUC__) && defined(i386) && !defined(__WIN32__) -#define SDL_memcpy(dst, src, len) \ -do { \ - int u0, u1, u2; \ - __asm__ __volatile__ ( \ - "cld\n\t" \ - "rep ; movsl\n\t" \ - "testb $2,%b4\n\t" \ - "je 1f\n\t" \ - "movsw\n" \ - "1:\ttestb $1,%b4\n\t" \ - "je 2f\n\t" \ - "movsb\n" \ - "2:" \ - : "=&c" (u0), "=&D" (u1), "=&S" (u2) \ - : "0" (SDL_static_cast(unsigned, len)/4), "q" (len), "1" (dst),"2" (src) \ - : "memory" ); \ -} while(0) -#endif -#ifndef SDL_memcpy -#ifdef HAVE_MEMCPY -#define SDL_memcpy memcpy -#elif defined(HAVE_BCOPY) -#define SDL_memcpy(d, s, n) bcopy((s), (d), (n)) -#else -extern DECLSPEC void *SDLCALL SDL_memcpy(void *dst, const void *src, - size_t len); -#endif +SDL_FORCE_INLINE void *SDL_memcpy_inline(void *dst, const void *src, size_t len) +{ + /* !!! FIXME: does this _really_ beat memcpy() on any modern platform? */ + /* !!! FIXME: shouldn't we just force the inputs to ecx/edi/esi instead of this tapdance with outputs? */ + /* !!! FIXME: amd64? */ + int u0, u1, u2; + __asm__ __volatile__ ( + "cld \n\t" + "rep ; movsl \n\t" + "testb $2,%b4 \n\t" + "je 1f \n\t" + "movsw \n" + "1:\ttestb $1,%b4 \n\t" + "je 2f \n\t" + "movsb \n" + "2:" + : "=&c" (u0), "=&D" (u1), "=&S" (u2) + : "0" (SDL_static_cast(unsigned, len)/4), "q" (len), "1" (dst), "2" (src) + : "memory" + ); + return dst; +} +#define SDL_memcpy SDL_memcpy_inline +#elif defined(HAVE_MEMCPY) +SDL_FORCE_INLINE void *SDL_memcpy_inline(void *dst, const void *src, size_t len) +{ + return memcpy(dst, src, len); +} +#define SDL_memcpy SDL_memcpy_inline +#elif defined(HAVE_BCOPY) /* !!! FIXME: is there _really_ ever a time where you have bcopy and not memcpy? */ +SDL_FORCE_INLINE void *SDL_memcpy_inline(void *dst, const void *src, size_t len) +{ + bcopy(src, dst, len); + return dst; +} +#define SDL_memcpy SDL_memcpy_inline #endif -/* We can count on memcpy existing on Mac OS X and being well-tuned. */ -#if defined(__MACOSX__) -#define SDL_memcpy4(dst, src, len) SDL_memcpy((dst), (src), (len) << 2) -#elif defined(__GNUC__) && defined(i386) -#define SDL_memcpy4(dst, src, len) \ -do { \ - int ecx, edi, esi; \ - __asm__ __volatile__ ( \ - "cld\n\t" \ - "rep ; movsl" \ - : "=&c" (ecx), "=&D" (edi), "=&S" (esi) \ - : "0" (SDL_static_cast(unsigned, len)), "1" (dst), "2" (src) \ - : "memory" ); \ -} while(0) -#endif -#ifndef SDL_memcpy4 -#define SDL_memcpy4(dst, src, len) SDL_memcpy((dst), (src), (len) << 2) + +SDL_FORCE_INLINE void *SDL_memcpy4(void *dst, const void *src, size_t dwords) +{ +#if defined(__GNUC__) && defined(i386) + /* !!! FIXME: does this _really_ beat memcpy() on any modern platform? */ + /* !!! FIXME: shouldn't we just force the inputs to ecx/edi/esi instead of this tapdance with outputs? */ + int ecx, edi, esi; + __asm__ __volatile__ ( + "cld \n\t" + "rep ; movsl \n\t" + : "=&c" (ecx), "=&D" (edi), "=&S" (esi) + : "0" (SDL_static_cast(unsigned, dwords)), "1" (dst), "2" (src) + : "memory" + ); + return dst; +#else + return SDL_memcpy(dst, src, dwords * 4); #endif +} +extern DECLSPEC void *SDLCALL SDL_memmove(void *dst, const void *src, size_t len); #ifdef HAVE_MEMMOVE -#define SDL_memmove memmove -#else -extern DECLSPEC void *SDLCALL SDL_memmove(void *dst, const void *src, - size_t len); +SDL_FORCE_INLINE void *SDL_memmove_inline(void *dst, const void *src, size_t len) { return memmove(dst, src, len); } +#define SDL_memmove SDL_memmove_inline #endif +extern DECLSPEC int SDLCALL SDL_memcmp(const void *s1, const void *s2, size_t len); #ifdef HAVE_MEMCMP -#define SDL_memcmp memcmp -#else -extern DECLSPEC int SDLCALL SDL_memcmp(const void *s1, const void *s2, - size_t len); +SDL_FORCE_INLINE int SDL_memcmp_inline(const void *s1, const void *s2, size_t len) { return memcmp(s1, s2, len); } +#define SDL_memcmp SDL_memcmp_inline #endif +extern DECLSPEC size_t SDLCALL SDL_strlen(const char *str); #ifdef HAVE_STRLEN -#define SDL_strlen strlen -#else -extern DECLSPEC size_t SDLCALL SDL_strlen(const char *string); +SDL_FORCE_INLINE size_t SDL_strlen_inline(const char *str) { return strlen(str); } +#define SDL_strlen SDL_strlen_inline #endif +extern DECLSPEC size_t SDLCALL SDL_wcslen(const wchar_t *wstr); #ifdef HAVE_WCSLEN -#define SDL_wcslen wcslen -#else -#if !defined(wchar_t) && defined(__NINTENDODS__) -#define wchar_t short /* TODO: figure out why libnds doesn't have this */ -#endif -extern DECLSPEC size_t SDLCALL SDL_wcslen(const wchar_t * string); +SDL_FORCE_INLINE size_t SDL_wcslen_inline(const wchar_t *wstr) { return wcslen(wstr); } +#define SDL_wcslen SDL_wcslen_inline #endif -#ifdef HAVE_WCSLCPY -#define SDL_wcslcpy wcslcpy -#else extern DECLSPEC size_t SDLCALL SDL_wcslcpy(wchar_t *dst, const wchar_t *src, size_t maxlen); +#ifdef HAVE_WCSLCPY +SDL_FORCE_INLINE size_t SDL_wcslcpy_inline(wchar_t *dst, const wchar_t *src, size_t maxlen) { return wcslcpy(dst, src, maxlen); } +#define SDL_wcslcpy SDL_wcslcpy_inline #endif -#ifdef HAVE_WCSLCAT -#define SDL_wcslcat wcslcat -#else extern DECLSPEC size_t SDLCALL SDL_wcslcat(wchar_t *dst, const wchar_t *src, size_t maxlen); +#ifdef HAVE_WCSLCAT +SDL_FORCE_INLINE size_t SDL_wcslcat_inline(wchar_t *dst, const wchar_t *src, size_t maxlen) { return wcslcat(dst, src, maxlen); } +#define SDL_wcslcat SDL_wcslcat_inline #endif - +extern DECLSPEC size_t SDLCALL SDL_strlcpy(char *dst, const char *src, size_t maxlen); #ifdef HAVE_STRLCPY -#define SDL_strlcpy strlcpy +SDL_FORCE_INLINE size_t SDL_strlcpy_inline(char *dst, const char *src, size_t maxlen) { return strlcpy(dst, src, maxlen); } +#define SDL_strlcpy SDL_strlcpy_inline #else -extern DECLSPEC size_t SDLCALL SDL_strlcpy(char *dst, const char *src, - size_t maxlen); #endif -extern DECLSPEC size_t SDLCALL SDL_utf8strlcpy(char *dst, const char *src, - size_t dst_bytes); +extern DECLSPEC size_t SDLCALL SDL_utf8strlcpy(char *dst, const char *src, size_t dst_bytes); +extern DECLSPEC size_t SDLCALL SDL_strlcat(char *dst, const char *src, size_t maxlen); #ifdef HAVE_STRLCAT -#define SDL_strlcat strlcat -#else -extern DECLSPEC size_t SDLCALL SDL_strlcat(char *dst, const char *src, - size_t maxlen); +SDL_FORCE_INLINE size_t SDL_strlcat_inline(char *dst, const char *src, size_t maxlen) { return strlcat(dst, src, maxlen); } +#define SDL_strlcat SDL_strlcat_inline #endif +extern DECLSPEC char *SDLCALL SDL_strdup(const char *str); #ifdef HAVE_STRDUP -#define SDL_strdup strdup -#else -extern DECLSPEC char *SDLCALL SDL_strdup(const char *string); +SDL_FORCE_INLINE char *SDL_strdup_inline(const char *str) { return strdup(str); } +#define SDL_strdup SDL_strdup_inline #endif +extern DECLSPEC char *SDLCALL SDL_strrev(char *str); #ifdef HAVE__STRREV -#define SDL_strrev _strrev -#else -extern DECLSPEC char *SDLCALL SDL_strrev(char *string); +SDL_FORCE_INLINE char *SDL_strrev_inline(char *str) { return _strrev(str); } +#define SDL_strrev SDL_strrev_inline #endif +extern DECLSPEC char *SDLCALL SDL_strupr(char *str); #ifdef HAVE__STRUPR -#define SDL_strupr _strupr -#else -extern DECLSPEC char *SDLCALL SDL_strupr(char *string); +SDL_FORCE_INLINE char *SDL_strupr_inline(char *str) { return _strupr(str); } +#define SDL_strupr SDL_strupr_inline #endif +extern DECLSPEC char *SDLCALL SDL_strlwr(char *str); #ifdef HAVE__STRLWR -#define SDL_strlwr _strlwr -#else -extern DECLSPEC char *SDLCALL SDL_strlwr(char *string); +SDL_FORCE_INLINE char *SDL_strlwr_inline(char *str) { return _strlwr(str); } +#define SDL_strlwr SDL_strlwr_inline #endif +extern DECLSPEC char *SDLCALL SDL_strchr(const char *str, int c); #ifdef HAVE_STRCHR -#define SDL_strchr strchr -#elif defined(HAVE_INDEX) -#define SDL_strchr index +SDL_FORCE_INLINE char *SDL_strchr_inline(const char *str, int c) { +#ifdef __cplusplus +return const_cast<char*>(strchr(str, c)); #else -extern DECLSPEC char *SDLCALL SDL_strchr(const char *string, int c); +return (char*)strchr(str, c); +#endif +} +#define SDL_strchr SDL_strchr_inline +#elif defined(HAVE_INDEX) /* !!! FIXME: is there anywhere that has this but not strchr? */ +SDL_FORCE_INLINE char *SDL_strchr_inline(const char *str, int c) { return index(str, c); } +#define SDL_strchr SDL_strchr_inline #endif +extern DECLSPEC char *SDLCALL SDL_strrchr(const char *str, int c); #ifdef HAVE_STRRCHR -#define SDL_strrchr strrchr -#elif defined(HAVE_RINDEX) -#define SDL_strrchr rindex +SDL_FORCE_INLINE char *SDL_strrchr_inline(const char *str, int c) { +#ifdef __cplusplus +return const_cast<char*>(strrchr(str, c)); #else -extern DECLSPEC char *SDLCALL SDL_strrchr(const char *string, int c); +return (char*)strrchr(str, c); #endif - -#ifdef HAVE_STRSTR -#define SDL_strstr strstr +} +#define SDL_strrchr SDL_strrchr_inline +#elif defined(HAVE_RINDEX) /* !!! FIXME: is there anywhere that has this but not strrchr? */ +SDL_FORCE_INLINE char *SDL_strrchr_inline(const char *str, int c) { +#ifdef __cplusplus +return const_cast<char*>(rindex(str, c)); #else -extern DECLSPEC char *SDLCALL SDL_strstr(const char *haystack, - const char *needle); +return (char*)rindex(str, c); +#endif +} +#define SDL_strrchr SDL_strrchr_inline #endif -#ifdef HAVE_ITOA -#define SDL_itoa itoa +extern DECLSPEC char *SDLCALL SDL_strstr(const char *haystack, const char *needle); +#ifdef HAVE_STRSTR +SDL_FORCE_INLINE char *SDL_strstr_inline(const char *haystack, const char *needle) { +#ifdef __cplusplus +return const_cast<char*>(strstr(haystack, needle)); #else -#define SDL_itoa(value, string, radix) SDL_ltoa((long)value, string, radix) +return (char*)strstr(haystack, needle); +#endif +} +#define SDL_strstr SDL_strstr_inline #endif +extern DECLSPEC char *SDLCALL SDL_ltoa(long value, char *str, int radix); #ifdef HAVE__LTOA -#define SDL_ltoa _ltoa -#else -extern DECLSPEC char *SDLCALL SDL_ltoa(long value, char *string, int radix); +SDL_FORCE_INLINE char *SDL_ltoa_inline(long value, char *str, int radix) { return _ltoa(value, str, radix); } +#define SDL_ltoa SDL_ltoa_inline #endif -#ifdef HAVE__UITOA -#define SDL_uitoa _uitoa +extern DECLSPEC char *SDLCALL SDL_itoa(int value, char *str, int radix); +#ifdef HAVE_ITOA +SDL_FORCE_INLINE char *SDL_itoa_inline(int value, char *str, int radix) { return itoa(value, str, radix); } #else -#define SDL_uitoa(value, string, radix) SDL_ultoa((long)value, string, radix) +SDL_FORCE_INLINE char *SDL_itoa_inline(int value, char *str, int radix) { return SDL_ltoa((long)value, str, radix); } #endif +#define SDL_itoa SDL_itoa_inline +extern DECLSPEC char *SDLCALL SDL_ultoa(unsigned long value, char *str, int radix); #ifdef HAVE__ULTOA -#define SDL_ultoa _ultoa +SDL_FORCE_INLINE char *SDL_ultoa_inline(unsigned long value, char *str, int radix) { return _ultoa(value, str, radix); } +#define SDL_ultoa SDL_ultoa_inline +#endif + +extern DECLSPEC char *SDLCALL SDL_uitoa(unsigned int value, char *str, int radix); +#ifdef HAVE__UITOA +SDL_FORCE_INLINE char *SDL_uitoa_inline(unsigned int value, char *str, int radix) { return _uitoa(value, str, radix); } #else -extern DECLSPEC char *SDLCALL SDL_ultoa(unsigned long value, char *string, - int radix); +SDL_FORCE_INLINE char *SDL_uitoa_inline(unsigned int value, char *str, int radix) { return SDL_ultoa((unsigned long)value, str, radix); } #endif +#define SDL_uitoa SDL_uitoa_inline + +extern DECLSPEC long SDLCALL SDL_strtol(const char *str, char **endp, int base); #ifdef HAVE_STRTOL -#define SDL_strtol strtol -#else -extern DECLSPEC long SDLCALL SDL_strtol(const char *string, char **endp, - int base); +SDL_FORCE_INLINE long SDL_strtol_inline(const char *str, char **endp, int base) { return strtol(str, endp, base); } +#define SDL_strtol SDL_strtol_inline #endif +extern DECLSPEC unsigned long SDLCALL SDL_strtoul(const char *str, char **endp, int base); #ifdef HAVE_STRTOUL -#define SDL_strtoul strtoul -#else -extern DECLSPEC unsigned long SDLCALL SDL_strtoul(const char *string, - char **endp, int base); +SDL_FORCE_INLINE unsigned long SDLCALL SDL_strtoul_inline(const char *str, char **endp, int base) { return strtoul(str, endp, base); } +#define SDL_strtoul SDL_strtoul_inline #endif +extern DECLSPEC char *SDLCALL SDL_lltoa(Sint64 value, char *str, int radix); #ifdef HAVE__I64TOA -#define SDL_lltoa _i64toa -#else -extern DECLSPEC char *SDLCALL SDL_lltoa(Sint64 value, char *string, - int radix); +SDL_FORCE_INLINE char *SDL_lltoa_inline(Sint64 value, char *str, int radix) { return _i64toa(value, str, radix); } +#define SDL_lltoa SDL_lltoa_inline #endif +extern DECLSPEC char *SDLCALL SDL_ulltoa(Uint64 value, char *str, int radix); #ifdef HAVE__UI64TOA -#define SDL_ulltoa _ui64toa -#else -extern DECLSPEC char *SDLCALL SDL_ulltoa(Uint64 value, char *string, - int radix); +SDL_FORCE_INLINE char *SDL_ulltoa_inline(Uint64 value, char *str, int radix) { return _ui64toa(value, str, radix); } +#define SDL_ulltoa SDL_ulltoa_inline #endif +extern DECLSPEC Sint64 SDLCALL SDL_strtoll(const char *str, char **endp, int base); #ifdef HAVE_STRTOLL -#define SDL_strtoll strtoll -#else -extern DECLSPEC Sint64 SDLCALL SDL_strtoll(const char *string, char **endp, - int base); +SDL_FORCE_INLINE Sint64 SDL_strtoll_inline(const char *str, char **endp, int base) { return strtoll(str, endp, base); } +#define SDL_strtoll SDL_strtoll_inline #endif +extern DECLSPEC Uint64 SDLCALL SDL_strtoull(const char *str, char **endp, int base); #ifdef HAVE_STRTOULL -#define SDL_strtoull strtoull -#else -extern DECLSPEC Uint64 SDLCALL SDL_strtoull(const char *string, char **endp, - int base); +SDL_FORCE_INLINE Uint64 SDL_strtoull_inline(const char *str, char **endp, int base) { return strtoull(str, endp, base); } +#define SDL_strtoull SDL_strtoull_inline #endif +extern DECLSPEC double SDLCALL SDL_strtod(const char *str, char **endp); #ifdef HAVE_STRTOD -#define SDL_strtod strtod -#else -extern DECLSPEC double SDLCALL SDL_strtod(const char *string, char **endp); +SDL_FORCE_INLINE double SDL_strtod_inline(const char *str, char **endp) { return strtod(str, endp); } +#define SDL_strtod SDL_strtod_inline #endif +extern DECLSPEC int SDLCALL SDL_atoi(const char *str); #ifdef HAVE_ATOI -#define SDL_atoi atoi +SDL_FORCE_INLINE int SDL_atoi_inline(const char *str) { return atoi(str); } #else -#define SDL_atoi(X) SDL_strtol(X, NULL, 0) +SDL_FORCE_INLINE int SDL_atoi_inline(const char *str) { return SDL_strtol(str, NULL, 0); } #endif +#define SDL_atoi SDL_atoi_inline +extern DECLSPEC double SDLCALL SDL_atof(const char *str); #ifdef HAVE_ATOF -#define SDL_atof atof +SDL_FORCE_INLINE double SDL_atof_inline(const char *str) { return (double) atof(str); } #else -#define SDL_atof(X) SDL_strtod(X, NULL) +SDL_FORCE_INLINE double SDL_atof_inline(const char *str) { return SDL_strtod(str, NULL); } #endif +#define SDL_atof SDL_atof_inline + -#ifdef HAVE_STRCMP -#define SDL_strcmp strcmp -#else extern DECLSPEC int SDLCALL SDL_strcmp(const char *str1, const char *str2); +#ifdef HAVE_STRCMP +SDL_FORCE_INLINE int SDL_strcmp_inline(const char *str1, const char *str2) { return strcmp(str1, str2); } +#define SDL_strcmp SDL_strcmp_inline #endif +extern DECLSPEC int SDLCALL SDL_strncmp(const char *str1, const char *str2, size_t maxlen); #ifdef HAVE_STRNCMP -#define SDL_strncmp strncmp -#else -extern DECLSPEC int SDLCALL SDL_strncmp(const char *str1, const char *str2, - size_t maxlen); +SDL_FORCE_INLINE int SDL_strncmp_inline(const char *str1, const char *str2, size_t maxlen) { return strncmp(str1, str2, maxlen); } +#define SDL_strncmp SDL_strncmp_inline #endif +extern DECLSPEC int SDLCALL SDL_strcasecmp(const char *str1, const char *str2); #ifdef HAVE_STRCASECMP -#define SDL_strcasecmp strcasecmp +SDL_FORCE_INLINE int SDL_strcasecmp_inline(const char *str1, const char *str2) { return strcasecmp(str1, str2); } +#define SDL_strcasecmp SDL_strcasecmp_inline #elif defined(HAVE__STRICMP) -#define SDL_strcasecmp _stricmp -#else -extern DECLSPEC int SDLCALL SDL_strcasecmp(const char *str1, - const char *str2); +SDL_FORCE_INLINE int SDL_strcasecmp_inline(const char *str1, const char *str2) { return _stricmp(str1, str2); } +#define SDL_strcasecmp SDL_strcasecmp_inline #endif +extern DECLSPEC int SDLCALL SDL_strncasecmp(const char *str1, const char *str2, size_t len); #ifdef HAVE_STRNCASECMP -#define SDL_strncasecmp strncasecmp +SDL_FORCE_INLINE int SDL_strncasecmp_inline(const char *str1, const char *str2, size_t len) { return strncasecmp(str1, str2, len); } +#define SDL_strncasecmp SDL_strncasecmp_inline #elif defined(HAVE__STRNICMP) -#define SDL_strncasecmp _strnicmp -#else -extern DECLSPEC int SDLCALL SDL_strncasecmp(const char *str1, - const char *str2, size_t maxlen); +SDL_FORCE_INLINE int SDL_strncasecmp_inline(const char *str1, const char *str2, size_t len) { return _strnicmp(str1, str2, len); } +#define SDL_strncasecmp SDL_strncasecmp_inline #endif +/* Not doing SDL_*_inline functions for these, because of the varargs. */ +extern DECLSPEC int SDLCALL SDL_sscanf(const char *text, const char *fmt, ...); #ifdef HAVE_SSCANF -#define SDL_sscanf sscanf -#else -extern DECLSPEC int SDLCALL SDL_sscanf(const char *text, const char *fmt, - ...); +#define SDL_sscanf sscanf #endif +extern DECLSPEC int SDLCALL SDL_snprintf(char *text, size_t maxlen, const char *fmt, ...); #ifdef HAVE_SNPRINTF -#define SDL_snprintf snprintf -#else -extern DECLSPEC int SDLCALL SDL_snprintf(char *text, size_t maxlen, - const char *fmt, ...); +#define SDL_snprintf snprintf #endif +extern DECLSPEC int SDLCALL SDL_vsnprintf(char *text, size_t maxlen, const char *fmt, va_list ap); #ifdef HAVE_VSNPRINTF -#define SDL_vsnprintf vsnprintf -#else -extern DECLSPEC int SDLCALL SDL_vsnprintf(char *text, size_t maxlen, - const char *fmt, va_list ap); +SDL_FORCE_INLINE int SDL_vsnprintf_inline(char *text, size_t maxlen, const char *fmt, va_list ap) { return vsnprintf(text, maxlen, fmt, ap); } +#define SDL_vsnprintf SDL_vsnprintf_inline #endif #ifndef HAVE_M_PI @@ -645,88 +696,94 @@ extern DECLSPEC int SDLCALL SDL_vsnprintf(char *text, size_t maxlen, #endif #endif -#ifdef HAVE_ATAN -#define SDL_atan atan -#else extern DECLSPEC double SDLCALL SDL_atan(double x); +#ifdef HAVE_ATAN +SDL_FORCE_INLINE double SDL_atan_inline(double x) { return atan(x); } +#define SDL_atan SDL_atan_inline #endif +extern DECLSPEC double SDLCALL SDL_atan2(double x, double y); #ifdef HAVE_ATAN2 -#define SDL_atan2 atan2 -#else -extern DECLSPEC double SDLCALL SDL_atan2(double y, double x); +SDL_FORCE_INLINE double SDL_atan2_inline(double x, double y) { return atan2(x, y); } +#define SDL_atan2 SDL_atan2_inline #endif +extern DECLSPEC double SDLCALL SDL_ceil(double x); #ifdef HAVE_CEIL -#define SDL_ceil ceil +SDL_FORCE_INLINE double SDL_ceil_inline(double x) { return ceil(x); } #else -#define SDL_ceil(x) ((double)(int)((x)+0.5)) +SDL_FORCE_INLINE double SDL_ceil_inline(double x) { return (double)(int)((x)+0.5); } #endif +#define SDL_ceil SDL_ceil_inline -#ifdef HAVE_COPYSIGN -#define SDL_copysign copysign -#else extern DECLSPEC double SDLCALL SDL_copysign(double x, double y); +#ifdef HAVE_COPYSIGN +SDL_FORCE_INLINE double SDL_copysign_inline(double x, double y) { return copysign(x, y); } +#define SDL_copysign SDL_copysign_inline #endif -#ifdef HAVE_COS -#define SDL_cos cos -#else extern DECLSPEC double SDLCALL SDL_cos(double x); +#ifdef HAVE_COS +SDL_FORCE_INLINE double SDL_cos_inline(double x) { return cos(x); } +#define SDL_cos SDL_cos_inline #endif +extern DECLSPEC float SDLCALL SDL_cosf(float x); #ifdef HAVE_COSF -#define SDL_cosf cosf +SDL_FORCE_INLINE float SDL_cosf_inline(float x) { return cosf(x); } #else -#define SDL_cosf(x) (float)SDL_cos((double)x) +SDL_FORCE_INLINE float SDL_cosf_inline(float x) { return (float)SDL_cos((double)x); } #endif +#define SDL_cosf SDL_cosf_inline -#ifdef HAVE_FABS -#define SDL_fabs fabs -#else extern DECLSPEC double SDLCALL SDL_fabs(double x); +#ifdef HAVE_FABS +SDL_FORCE_INLINE double SDL_fabs_inline(double x) { return fabs(x); } +#define SDL_fabs SDL_fabs_inline #endif -#ifdef HAVE_FLOOR -#define SDL_floor floor -#else extern DECLSPEC double SDLCALL SDL_floor(double x); +#ifdef HAVE_FLOOR +SDL_FORCE_INLINE double SDL_floor_inline(double x) { return floor(x); } +#define SDL_floor SDL_floor_inline #endif -#ifdef HAVE_LOG -#define SDL_log log -#else extern DECLSPEC double SDLCALL SDL_log(double x); +#ifdef HAVE_LOG +SDL_FORCE_INLINE double SDL_log_inline(double x) { return log(x); } +#define SDL_log SDL_log_inline #endif -#ifdef HAVE_POW -#define SDL_pow pow -#else extern DECLSPEC double SDLCALL SDL_pow(double x, double y); +#ifdef HAVE_POW +SDL_FORCE_INLINE double SDL_pow_inline(double x, double y) { return pow(x, y); } +#define SDL_pow SDL_pow_inline #endif -#ifdef HAVE_SCALBN -#define SDL_scalbn scalbn -#else extern DECLSPEC double SDLCALL SDL_scalbn(double x, int n); +#ifdef HAVE_SCALBN +SDL_FORCE_INLINE double SDL_scalbn_inline(double x, int n) { return scalbn(x, n); } +#define SDL_scalbn SDL_scalbn_inline #endif -#ifdef HAVE_SIN -#define SDL_sin sin -#else extern DECLSPEC double SDLCALL SDL_sin(double x); +#ifdef HAVE_SIN +SDL_FORCE_INLINE double SDL_sin_inline(double x) { return sin(x); } +#define SDL_sin SDL_sin_inline #endif +extern DECLSPEC float SDLCALL SDL_sinf(float x); #ifdef HAVE_SINF -#define SDL_sinf sinf +SDL_FORCE_INLINE float SDL_sinf_inline(float x) { return sinf(x); } #else -#define SDL_sinf(x) (float)SDL_sin((double)x) +SDL_FORCE_INLINE float SDL_sinf_inline(float x) { return (float)SDL_sin((double)x); } #endif +#define SDL_sinf SDL_sinf_inline -#ifdef HAVE_SQRT -#define SDL_sqrt sqrt -#else extern DECLSPEC double SDLCALL SDL_sqrt(double x); +#ifdef HAVE_SQRT +SDL_FORCE_INLINE double SDL_sqrt_inline(double x) { return sqrt(x); } +#define SDL_sqrt SDL_sqrt_inline #endif /* The SDL implementation of iconv() returns these error codes */ @@ -735,16 +792,11 @@ extern DECLSPEC double SDLCALL SDL_sqrt(double x); #define SDL_ICONV_EILSEQ (size_t)-3 #define SDL_ICONV_EINVAL (size_t)-4 -#if defined(HAVE_ICONV) && defined(HAVE_ICONV_H) -#define SDL_iconv_t iconv_t -#define SDL_iconv_open iconv_open -#define SDL_iconv_close iconv_close -#else +/* SDL_iconv_* are now always real symbols/types, not macros or inlined. */ typedef struct _SDL_iconv_t *SDL_iconv_t; extern DECLSPEC SDL_iconv_t SDLCALL SDL_iconv_open(const char *tocode, const char *fromcode); extern DECLSPEC int SDLCALL SDL_iconv_close(SDL_iconv_t cd); -#endif extern DECLSPEC size_t SDLCALL SDL_iconv(SDL_iconv_t cd, const char **inbuf, size_t * inbytesleft, char **outbuf, size_t * outbytesleft); diff --git a/include/SDL_test_common.h b/include/SDL_test_common.h index 4977bed70a..9e9122f1bc 100644 --- a/include/SDL_test_common.h +++ b/include/SDL_test_common.h @@ -34,9 +34,9 @@ #include "SDL.h" -#ifdef __NDS__ -#define DEFAULT_WINDOW_WIDTH 256 -#define DEFAULT_WINDOW_HEIGHT (2*192) +#if defined(__PSP__) +#define DEFAULT_WINDOW_WIDTH 480 +#define DEFAULT_WINDOW_HEIGHT 272 #else #define DEFAULT_WINDOW_WIDTH 640 #define DEFAULT_WINDOW_HEIGHT 480 diff --git a/include/SDL_test_images.h b/include/SDL_test_images.h index 5730cca881..ea72229282 100644 --- a/include/SDL_test_images.h +++ b/include/SDL_test_images.h @@ -53,11 +53,7 @@ typedef struct SDLTest_SurfaceImage_s { int width; int height; unsigned int bytes_per_pixel; /* 3:RGB, 4:RGBA */ -#if (defined(__GNUC__) && (__GNUC__ <= 2)) - unsigned char pixel_data[0]; -#else - unsigned char pixel_data[]; -#endif + const char *pixel_data; } SDLTest_SurfaceImage_t; /* Test images */ diff --git a/include/SDL_touch.h b/include/SDL_touch.h index c4820792f1..55176a1d91 100644 --- a/include/SDL_touch.h +++ b/include/SDL_touch.h @@ -40,77 +40,42 @@ extern "C" { /* *INDENT-ON* */ #endif - typedef Sint64 SDL_TouchID; typedef Sint64 SDL_FingerID; +typedef struct SDL_Finger +{ + SDL_FingerID id; + float x; + float y; + float pressure; +} SDL_Finger; -struct SDL_Finger { - SDL_FingerID id; - Uint16 x; - Uint16 y; - Uint16 pressure; - Uint16 xdelta; - Uint16 ydelta; - Uint16 last_x, last_y,last_pressure; /* the last reported coordinates */ - SDL_bool down; -}; - -typedef struct SDL_Touch SDL_Touch; -typedef struct SDL_Finger SDL_Finger; - - -struct SDL_Touch { - - /* Free the touch when it's time */ - void (*FreeTouch) (SDL_Touch * touch); - - /* data common for tablets */ - float pressure_max, pressure_min; - float x_max,x_min; - float y_max,y_min; - Uint16 xres,yres,pressureres; - float native_xres,native_yres,native_pressureres; - float tilt_x; /* for future use */ - float tilt_y; /* for future use */ - float rotation; /* for future use */ - - /* Data common to all touch */ - SDL_TouchID id; - SDL_Window *focus; - - char *name; - Uint8 buttonstate; - SDL_bool relative_mode; - SDL_bool flush_motion; - - int num_fingers; - int max_fingers; - SDL_Finger** fingers; - - void *driverdata; -}; - +/* Used as the device ID for mouse events simulated with touch input */ +#define SDL_TOUCH_MOUSEID ((Uint32)-1) /* Function prototypes */ /** - * \brief Get the touch object at the given id. - * - * + * \brief Get the number of registered touch devices. */ - extern DECLSPEC SDL_Touch* SDLCALL SDL_GetTouch(SDL_TouchID id); +extern DECLSPEC int SDLCALL SDL_GetNumTouchDevices(); +/** + * \brief Get the touch ID with the given index, or 0 if the index is invalid. + */ +extern DECLSPEC SDL_TouchID SDLCALL SDL_GetTouchDevice(int index); +/** + * \brief Get the number of active fingers for a given touch device. + */ +extern DECLSPEC int SDLCALL SDL_GetNumTouchFingers(SDL_TouchID touchID); /** - * \brief Get the finger object of the given touch, at the given id. - * - * + * \brief Get the finger object of the given touch, with the given index. */ - extern - DECLSPEC SDL_Finger* SDLCALL SDL_GetFinger(SDL_Touch *touch, SDL_FingerID id); +extern DECLSPEC SDL_Finger * SDLCALL SDL_GetTouchFinger(SDL_TouchID touchID, int index); /* Ends C function definitions when using C++ */ #ifdef __cplusplus diff --git a/include/SDL_video.h b/include/SDL_video.h index 8c3978ade6..4873da39b9 100644 --- a/include/SDL_video.h +++ b/include/SDL_video.h @@ -504,6 +504,9 @@ extern DECLSPEC void SDLCALL SDL_SetWindowPosition(SDL_Window * window, /** * \brief Get the position of a window. * + * \param x Pointer to variable for storing the x position, may be NULL + * \param y Pointer to variable for storing the y position, may be NULL + * * \sa SDL_SetWindowPosition() */ extern DECLSPEC void SDLCALL SDL_GetWindowPosition(SDL_Window * window, @@ -512,6 +515,9 @@ extern DECLSPEC void SDLCALL SDL_GetWindowPosition(SDL_Window * window, /** * \brief Set the size of a window's client area. * + * \param w The width of the window, must be >0 + * \param h The height of the window, must be >0 + * * \note You can't change the size of a fullscreen window, it automatically * matches the size of the display mode. * @@ -523,6 +529,9 @@ extern DECLSPEC void SDLCALL SDL_SetWindowSize(SDL_Window * window, int w, /** * \brief Get the size of a window's client area. * + * \param w Pointer to variable for storing the width, may be NULL + * \param h Pointer to variable for storing the height, may be NULL + * * \sa SDL_SetWindowSize() */ extern DECLSPEC void SDLCALL SDL_GetWindowSize(SDL_Window * window, int *w, @@ -530,6 +539,9 @@ extern DECLSPEC void SDLCALL SDL_GetWindowSize(SDL_Window * window, int *w, /** * \brief Set the minimum size of a window's client area. + * + * \param min_w The minimum width of the window, must be >0 + * \param min_h The minimum height of the window, must be >0 * * \note You can't change the minimum size of a fullscreen window, it * automatically matches the size of the display mode. @@ -542,7 +554,10 @@ extern DECLSPEC void SDLCALL SDL_SetWindowMinimumSize(SDL_Window * window, /** * \brief Get the minimum size of a window's client area. - * + * + * \param w Pointer to variable for storing the minimum width, may be NULL + * \param h Pointer to variable for storing the minimum height, may be NULL + * * \sa SDL_GetWindowMaximumSize() * \sa SDL_SetWindowMinimumSize() */ @@ -552,6 +567,9 @@ extern DECLSPEC void SDLCALL SDL_GetWindowMinimumSize(SDL_Window * window, /** * \brief Set the maximum size of a window's client area. * + * \param max_w The maximum width of the window, must be >0 + * \param max_h The maximum height of the window, must be >0 + * * \note You can't change the maximum size of a fullscreen window, it * automatically matches the size of the display mode. * @@ -563,6 +581,9 @@ extern DECLSPEC void SDLCALL SDL_SetWindowMaximumSize(SDL_Window * window, /** * \brief Get the maximum size of a window's client area. + * + * \param w Pointer to variable for storing the maximum width, may be NULL + * \param h Pointer to variable for storing the maximum height, may be NULL * * \sa SDL_GetWindowMinimumSize() * \sa SDL_SetWindowMaximumSize() @@ -673,7 +694,7 @@ extern DECLSPEC int SDLCALL SDL_UpdateWindowSurface(SDL_Window * window); * \sa SDL_UpdateWindowSurfaceRect() */ extern DECLSPEC int SDLCALL SDL_UpdateWindowSurfaceRects(SDL_Window * window, - SDL_Rect * rects, + const SDL_Rect * rects, int numrects); /** diff --git a/include/begin_code.h b/include/begin_code.h index 86797258b0..0a4b4a65c6 100644 --- a/include/begin_code.h +++ b/include/begin_code.h @@ -128,6 +128,16 @@ #define __inline__ #endif +#ifndef SDL_FORCE_INLINE +#if defined(_MSC_VER) +#define SDL_FORCE_INLINE __forceinline +#elif ( (defined(__GNUC__) && (__GNUC__ >= 4)) || defined(__clang__) ) +#define SDL_FORCE_INLINE __attribute__((always_inline)) static inline +#else +#define SDL_FORCE_INLINE static __inline__ +#endif +#endif + /* Apparently this is needed by several Windows compilers */ #if !defined(__MACH__) #ifndef NULL @@ -68,14 +68,9 @@ SDL_PrivateSubsystemRefCountDecr(Uint32 subsystem) /* Private helper to check if a system needs init. */ static SDL_bool -SDL_PrivateShouldInitSubsystem(Uint32 flags, Uint32 subsystem) +SDL_PrivateShouldInitSubsystem(Uint32 subsystem) { - int subsystem_index; - if ((flags & subsystem) == 0) { - return SDL_FALSE; - } - - subsystem_index = SDL_MostSignificantBitIndex32(subsystem); + int subsystem_index = SDL_MostSignificantBitIndex32(subsystem); SDL_assert(SDL_SubsystemRefCount[subsystem_index] < 255); return (SDL_SubsystemRefCount[subsystem_index] == 0); } @@ -105,41 +100,44 @@ SDL_InitSubSystem(Uint32 flags) #endif /* Initialize the timer subsystem */ - if (SDL_PrivateShouldInitSubsystem(flags, SDL_INIT_TIMER)) { + if ((flags & SDL_INIT_TIMER) ){ #if !SDL_TIMERS_DISABLED - if (SDL_TimerInit() < 0) { - return (-1); + if (SDL_PrivateShouldInitSubsystem(SDL_INIT_TIMER)) { + if (SDL_TimerInit() < 0) { + return (-1); + } } SDL_PrivateSubsystemRefCountIncr(SDL_INIT_TIMER); #else - SDL_SetError("SDL not built with timer support"); - return (-1); + return SDL_SetError("SDL not built with timer support"); #endif } /* Initialize the video/event subsystem */ - if (SDL_PrivateShouldInitSubsystem(flags, SDL_INIT_VIDEO)) { + if ((flags & SDL_INIT_VIDEO) ){ #if !SDL_VIDEO_DISABLED - if (SDL_VideoInit(NULL) < 0) { - return (-1); + if (SDL_PrivateShouldInitSubsystem(SDL_INIT_VIDEO)) { + if (SDL_VideoInit(NULL) < 0) { + return (-1); + } } SDL_PrivateSubsystemRefCountIncr(SDL_INIT_VIDEO); #else - SDL_SetError("SDL not built with video support"); - return (-1); + return SDL_SetError("SDL not built with video support"); #endif } /* Initialize the audio subsystem */ - if (SDL_PrivateShouldInitSubsystem(flags, SDL_INIT_AUDIO)) { + if ((flags & SDL_INIT_AUDIO) ){ #if !SDL_AUDIO_DISABLED - if (SDL_AudioInit(NULL) < 0) { - return (-1); + if (SDL_PrivateShouldInitSubsystem(SDL_INIT_AUDIO)) { + if (SDL_AudioInit(NULL) < 0) { + return (-1); + } } SDL_PrivateSubsystemRefCountIncr(SDL_INIT_AUDIO); #else - SDL_SetError("SDL not built with audio support"); - return (-1); + return SDL_SetError("SDL not built with audio support"); #endif } @@ -149,40 +147,43 @@ SDL_InitSubSystem(Uint32 flags) } /* Initialize the joystick subsystem */ - if (SDL_PrivateShouldInitSubsystem(flags, SDL_INIT_JOYSTICK)) { + if ((flags & SDL_INIT_JOYSTICK) ){ #if !SDL_JOYSTICK_DISABLED - if (SDL_JoystickInit() < 0) { - return (-1); + if (SDL_PrivateShouldInitSubsystem(SDL_INIT_JOYSTICK)) { + if (SDL_JoystickInit() < 0) { + return (-1); + } } SDL_PrivateSubsystemRefCountIncr(SDL_INIT_JOYSTICK); #else - SDL_SetError("SDL not built with joystick support"); - return (-1); + return SDL_SetError("SDL not built with joystick support"); #endif } - if (SDL_PrivateShouldInitSubsystem(flags, SDL_INIT_GAMECONTROLLER)) { + if ((flags & SDL_INIT_GAMECONTROLLER) ){ #if !SDL_JOYSTICK_DISABLED - if (SDL_GameControllerInit() < 0) { - return (-1); + if (SDL_PrivateShouldInitSubsystem(SDL_INIT_GAMECONTROLLER)) { + if (SDL_GameControllerInit() < 0) { + return (-1); + } } SDL_PrivateSubsystemRefCountIncr(SDL_INIT_GAMECONTROLLER); #else - SDL_SetError("SDL not built with joystick support"); - return (-1); + return SDL_SetError("SDL not built with joystick support"); #endif } /* Initialize the haptic subsystem */ - if (SDL_PrivateShouldInitSubsystem(flags, SDL_INIT_HAPTIC)) { + if ((flags & SDL_INIT_HAPTIC) ){ #if !SDL_HAPTIC_DISABLED - if (SDL_HapticInit() < 0) { - return (-1); + if (SDL_PrivateShouldInitSubsystem(SDL_INIT_HAPTIC)) { + if (SDL_HapticInit() < 0) { + return (-1); + } } SDL_PrivateSubsystemRefCountIncr(SDL_INIT_HAPTIC); #else - SDL_SetError("SDL not built with haptic (force feedback) support"); - return (-1); + return SDL_SetError("SDL not built with haptic (force feedback) support"); #endif } @@ -383,8 +384,6 @@ SDL_GetPlatform() return "Mac OS X"; #elif __NETBSD__ return "NetBSD"; -#elif __NDS__ - return "Nintendo DS"; #elif __OPENBSD__ return "OpenBSD"; #elif __OS2__ @@ -401,6 +400,8 @@ SDL_GetPlatform() return "Windows"; #elif __IPHONEOS__ return "iPhone OS"; +#elif __PSP__ + return "PlayStation Portable"; #else return "Unknown (see SDL_platform.h)"; #endif @@ -429,4 +430,4 @@ _DllMainCRTStartup(HANDLE hModule, #endif /* __WIN32__ */ -/* vi: set ts=4 sw=4 expandtab: */ +/* vi: set sts=4 ts=4 sw=4 expandtab: */ diff --git a/src/SDL_error.c b/src/SDL_error.c index a94b1827fe..40388124b5 100644 --- a/src/SDL_error.c +++ b/src/SDL_error.c @@ -49,14 +49,14 @@ SDL_LookupString(const char *key) /* Public functions */ -void +int SDL_SetError(const char *fmt, ...) { va_list ap; SDL_error *error; /* Ignore call if invalid format pointer was passed */ - if (fmt == NULL) return; + if (fmt == NULL) return -1; /* Copy in the key, mark error as valid */ error = SDL_GetErrBuf(); @@ -112,6 +112,8 @@ SDL_SetError(const char *fmt, ...) /* If we are in debug mode, print out an error message */ SDL_LogError(SDL_LOG_CATEGORY_ERROR, "%s", SDL_GetError()); + + return -1; } /* This function has a bit more overhead than most error functions @@ -216,28 +218,22 @@ SDL_ClearError(void) } /* Very common errors go here */ -void +int SDL_Error(SDL_errorcode code) { switch (code) { case SDL_ENOMEM: - SDL_SetError("Out of memory"); - break; + return SDL_SetError("Out of memory"); case SDL_EFREAD: - SDL_SetError("Error reading from datastream"); - break; + return SDL_SetError("Error reading from datastream"); case SDL_EFWRITE: - SDL_SetError("Error writing to datastream"); - break; + return SDL_SetError("Error writing to datastream"); case SDL_EFSEEK: - SDL_SetError("Error seeking in datastream"); - break; + return SDL_SetError("Error seeking in datastream"); case SDL_UNSUPPORTED: - SDL_SetError("That operation is not supported"); - break; + return SDL_SetError("That operation is not supported"); default: - SDL_SetError("Unknown SDL error"); - break; + return SDL_SetError("Unknown SDL error"); } } diff --git a/src/SDL_log.c b/src/SDL_log.c index c152112c8b..ad7b722eeb 100644 --- a/src/SDL_log.c +++ b/src/SDL_log.c @@ -327,6 +327,20 @@ SDL_LogOutput(void *userdata, int category, SDL_LogPriority priority, return; } } +#elif defined(__PSP__) +//Simple Log System for PSP + { + unsigned int length; + char* output; + FILE* pFile; + length = SDL_strlen(SDL_priority_prefixes[priority]) + 2 + SDL_strlen(message) + 1; + output = SDL_stack_alloc(char, length); + SDL_snprintf(output, length, "%s: %s", SDL_priority_prefixes[priority], message); + pFile = fopen ("SDL_Log.txt", "a"); + fwrite (output, strlen (output), 1, pFile); + SDL_stack_free(output); + fclose (pFile); + } #endif #if HAVE_STDIO_H fprintf(stderr, "%s: %s\n", SDL_priority_prefixes[priority], message); diff --git a/src/atomic/SDL_atomic.c b/src/atomic/SDL_atomic.c index 34a298edc7..6cf2384a5d 100644 --- a/src/atomic/SDL_atomic.c +++ b/src/atomic/SDL_atomic.c @@ -27,6 +27,8 @@ doesn't have that compiler. That way we always have a working set of atomic operations built into the library. */ +#undef SDL_AtomicCAS +#undef SDL_AtomicCASPtr /* If any of the operations are not provided then we must emulate some @@ -69,8 +71,8 @@ leaveLock(void *a) SDL_AtomicUnlock(&locks[index]); } -SDL_bool -SDL_AtomicCAS_(SDL_atomic_t *a, int oldval, int newval) +DECLSPEC SDL_bool SDLCALL +SDL_AtomicCAS(SDL_atomic_t *a, int oldval, int newval) { SDL_bool retval = SDL_FALSE; @@ -84,8 +86,8 @@ SDL_AtomicCAS_(SDL_atomic_t *a, int oldval, int newval) return retval; } -SDL_bool -SDL_AtomicCASPtr_(void **a, void *oldval, void *newval) +DECLSPEC SDL_bool SDLCALL +SDL_AtomicCASPtr(void **a, void *oldval, void *newval) { SDL_bool retval = SDL_FALSE; diff --git a/src/atomic/SDL_spinlock.c b/src/atomic/SDL_spinlock.c index dda01f7e37..b50565974b 100644 --- a/src/atomic/SDL_spinlock.c +++ b/src/atomic/SDL_spinlock.c @@ -41,13 +41,13 @@ SDL_AtomicTryLock(SDL_SpinLock *lock) /* Race condition on first lock... */ _spinlock_mutex = SDL_CreateMutex(); } - SDL_mutexP(_spinlock_mutex); + SDL_LockMutex(_spinlock_mutex); if (*lock == 0) { *lock = 1; - SDL_mutexV(_spinlock_mutex); + SDL_UnlockMutex(_spinlock_mutex); return SDL_TRUE; } else { - SDL_mutexV(_spinlock_mutex); + SDL_UnlockMutex(_spinlock_mutex); return SDL_FALSE; } diff --git a/src/audio/SDL_audio.c b/src/audio/SDL_audio.c index 090e0144b4..f6763f9b66 100644 --- a/src/audio/SDL_audio.c +++ b/src/audio/SDL_audio.c @@ -66,7 +66,7 @@ extern AudioBootStrap DART_bootstrap; extern AudioBootStrap NDSAUD_bootstrap; extern AudioBootStrap FUSIONSOUND_bootstrap; extern AudioBootStrap ANDROIDAUD_bootstrap; - +extern AudioBootStrap PSPAUD_bootstrap; /* Available audio drivers */ static const AudioBootStrap *const bootstrap[] = { @@ -121,15 +121,15 @@ static const AudioBootStrap *const bootstrap[] = { #if SDL_AUDIO_DRIVER_DUMMY &DUMMYAUD_bootstrap, #endif -#if SDL_AUDIO_DRIVER_NDS - &NDSAUD_bootstrap, -#endif #if SDL_AUDIO_DRIVER_FUSIONSOUND &FUSIONSOUND_bootstrap, #endif #if SDL_AUDIO_DRIVER_ANDROID &ANDROIDAUD_bootstrap, #endif +#if SDL_AUDIO_DRIVER_PSP + &PSPAUD_bootstrap, +#endif NULL }; @@ -191,7 +191,7 @@ SDL_AudioDeinitialize_Default(void) static int SDL_AudioOpenDevice_Default(_THIS, const char *devname, int iscapture) { - return 0; + return -1; } static void @@ -200,7 +200,7 @@ SDL_AudioLockDevice_Default(SDL_AudioDevice * device) if (device->thread && (SDL_ThreadID() == device->threadid)) { return; } - SDL_mutexP(device->mixer_lock); + SDL_LockMutex(device->mixer_lock); } static void @@ -209,7 +209,7 @@ SDL_AudioUnlockDevice_Default(SDL_AudioDevice * device) if (device->thread && (SDL_ThreadID() == device->threadid)) { return; } - SDL_mutexV(device->mixer_lock); + SDL_UnlockMutex(device->mixer_lock); } @@ -407,9 +407,9 @@ SDL_RunAudio(void *devicep) } /* Read from the callback into the _input_ stream */ - SDL_mutexP(device->mixer_lock); + SDL_LockMutex(device->mixer_lock); (*fill) (udata, istream, istream_len); - SDL_mutexV(device->mixer_lock); + SDL_UnlockMutex(device->mixer_lock); /* Convert the audio if necessary and write to the streamer */ if (device->convert.needed) { @@ -480,9 +480,9 @@ SDL_RunAudio(void *devicep) } } - SDL_mutexP(device->mixer_lock); + SDL_LockMutex(device->mixer_lock); (*fill) (udata, stream, stream_len); - SDL_mutexV(device->mixer_lock); + SDL_UnlockMutex(device->mixer_lock); /* Convert the audio if necessary */ if (device->convert.needed) { @@ -940,7 +940,7 @@ open_audio_device(const char *devname, int iscapture, ((!iscapture) && (current_audio.outputDevices == NULL)) ) SDL_GetNumAudioDevices(iscapture); - if (!current_audio.impl.OpenDevice(device, devname, iscapture)) { + if (current_audio.impl.OpenDevice(device, devname, iscapture) < 0) { close_audio_device(device); return 0; } diff --git a/src/audio/SDL_audiocvt.c b/src/audio/SDL_audiocvt.c index 1c6b493bd0..2d067e7799 100644 --- a/src/audio/SDL_audiocvt.c +++ b/src/audio/SDL_audiocvt.c @@ -970,28 +970,23 @@ SDL_BuildAudioCVT(SDL_AudioCVT * cvt, /* Sanity check target pointer */ if (cvt == NULL) { - SDL_InvalidParamError("cvt"); - return -1; + return SDL_InvalidParamError("cvt"); } /* there are no unsigned types over 16 bits, so catch this up front. */ if ((SDL_AUDIO_BITSIZE(src_fmt) > 16) && (!SDL_AUDIO_ISSIGNED(src_fmt))) { - SDL_SetError("Invalid source format"); - return -1; + return SDL_SetError("Invalid source format"); } if ((SDL_AUDIO_BITSIZE(dst_fmt) > 16) && (!SDL_AUDIO_ISSIGNED(dst_fmt))) { - SDL_SetError("Invalid destination format"); - return -1; + return SDL_SetError("Invalid destination format"); } /* prevent possible divisions by zero, etc. */ if ((src_channels == 0) || (dst_channels == 0)) { - SDL_SetError("Source or destination channels is zero"); - return -1; + return SDL_SetError("Source or destination channels is zero"); } if ((src_rate == 0) || (dst_rate == 0)) { - SDL_SetError("Source or destination rate is zero"); - return -1; + return SDL_SetError("Source or destination rate is zero"); } #ifdef DEBUG_CONVERT printf("Build format %04x->%04x, channels %u->%u, rate %d->%d\n", diff --git a/src/audio/SDL_wave.c b/src/audio/SDL_wave.c index 7bcc59e9fa..b1bd0538cb 100644 --- a/src/audio/SDL_wave.c +++ b/src/audio/SDL_wave.c @@ -134,8 +134,7 @@ MS_ADPCM_decode(Uint8 ** audio_buf, Uint32 * audio_len) MS_ADPCM_state.wavefmt.channels * sizeof(Sint16); *audio_buf = (Uint8 *) SDL_malloc(*audio_len); if (*audio_buf == NULL) { - SDL_Error(SDL_ENOMEM); - return (-1); + return SDL_OutOfMemory(); } decoded = *audio_buf; @@ -359,8 +358,7 @@ IMA_ADPCM_decode(Uint8 ** audio_buf, Uint32 * audio_len) IMA_ADPCM_state.wavefmt.channels * sizeof(Sint16); *audio_buf = (Uint8 *) SDL_malloc(*audio_len); if (*audio_buf == NULL) { - SDL_Error(SDL_ENOMEM); - return (-1); + return SDL_OutOfMemory(); } decoded = *audio_buf; @@ -620,14 +618,12 @@ ReadChunk(SDL_RWops * src, Chunk * chunk) chunk->length = SDL_ReadLE32(src); chunk->data = (Uint8 *) SDL_malloc(chunk->length); if (chunk->data == NULL) { - SDL_Error(SDL_ENOMEM); - return (-1); + return SDL_OutOfMemory(); } if (SDL_RWread(src, chunk->data, chunk->length, 1) != 1) { - SDL_Error(SDL_EFREAD); SDL_free(chunk->data); chunk->data = NULL; - return (-1); + return SDL_Error(SDL_EFREAD); } return (chunk->length); } diff --git a/src/audio/alsa/SDL_alsa_audio.c b/src/audio/alsa/SDL_alsa_audio.c index 3e33d1692f..9b5e75624a 100644 --- a/src/audio/alsa/SDL_alsa_audio.c +++ b/src/audio/alsa/SDL_alsa_audio.c @@ -482,8 +482,7 @@ ALSA_OpenDevice(_THIS, const char *devname, int iscapture) this->hidden = (struct SDL_PrivateAudioData *) SDL_malloc((sizeof *this->hidden)); if (this->hidden == NULL) { - SDL_OutOfMemory(); - return 0; + return SDL_OutOfMemory(); } SDL_memset(this->hidden, 0, (sizeof *this->hidden)); @@ -495,9 +494,8 @@ ALSA_OpenDevice(_THIS, const char *devname, int iscapture) if (status < 0) { ALSA_CloseDevice(this); - SDL_SetError("ALSA: Couldn't open audio device: %s", - ALSA_snd_strerror(status)); - return 0; + return SDL_SetError("ALSA: Couldn't open audio device: %s", + ALSA_snd_strerror(status)); } this->hidden->pcm_handle = pcm_handle; @@ -507,9 +505,8 @@ ALSA_OpenDevice(_THIS, const char *devname, int iscapture) status = ALSA_snd_pcm_hw_params_any(pcm_handle, hwparams); if (status < 0) { ALSA_CloseDevice(this); - SDL_SetError("ALSA: Couldn't get hardware config: %s", - ALSA_snd_strerror(status)); - return 0; + return SDL_SetError("ALSA: Couldn't get hardware config: %s", + ALSA_snd_strerror(status)); } /* SDL only uses interleaved sample output */ @@ -517,9 +514,8 @@ ALSA_OpenDevice(_THIS, const char *devname, int iscapture) SND_PCM_ACCESS_RW_INTERLEAVED); if (status < 0) { ALSA_CloseDevice(this); - SDL_SetError("ALSA: Couldn't set interleaved access: %s", + return SDL_SetError("ALSA: Couldn't set interleaved access: %s", ALSA_snd_strerror(status)); - return 0; } /* Try for a closest match on audio format */ @@ -572,8 +568,7 @@ ALSA_OpenDevice(_THIS, const char *devname, int iscapture) } if (status < 0) { ALSA_CloseDevice(this); - SDL_SetError("ALSA: Couldn't find any hardware audio formats"); - return 0; + return SDL_SetError("ALSA: Couldn't find any hardware audio formats"); } this->spec.format = test_format; @@ -585,8 +580,7 @@ ALSA_OpenDevice(_THIS, const char *devname, int iscapture) status = ALSA_snd_pcm_hw_params_get_channels(hwparams, &channels); if (status < 0) { ALSA_CloseDevice(this); - SDL_SetError("ALSA: Couldn't set audio channels"); - return 0; + return SDL_SetError("ALSA: Couldn't set audio channels"); } this->spec.channels = channels; } @@ -597,9 +591,8 @@ ALSA_OpenDevice(_THIS, const char *devname, int iscapture) &rate, NULL); if (status < 0) { ALSA_CloseDevice(this); - SDL_SetError("ALSA: Couldn't set audio frequency: %s", - ALSA_snd_strerror(status)); - return 0; + return SDL_SetError("ALSA: Couldn't set audio frequency: %s", + ALSA_snd_strerror(status)); } this->spec.freq = rate; @@ -609,8 +602,7 @@ ALSA_OpenDevice(_THIS, const char *devname, int iscapture) /* Failed to set desired buffer size, do the best you can... */ if ( ALSA_set_period_size(this, hwparams, 1) < 0 ) { ALSA_CloseDevice(this); - SDL_SetError("Couldn't set hardware audio parameters: %s", ALSA_snd_strerror(status)); - return(-1); + return SDL_SetError("Couldn't set hardware audio parameters: %s", ALSA_snd_strerror(status)); } } /* Set the software parameters */ @@ -618,31 +610,27 @@ ALSA_OpenDevice(_THIS, const char *devname, int iscapture) status = ALSA_snd_pcm_sw_params_current(pcm_handle, swparams); if (status < 0) { ALSA_CloseDevice(this); - SDL_SetError("ALSA: Couldn't get software config: %s", - ALSA_snd_strerror(status)); - return 0; + return SDL_SetError("ALSA: Couldn't get software config: %s", + ALSA_snd_strerror(status)); } status = ALSA_snd_pcm_sw_params_set_avail_min(pcm_handle, swparams, this->spec.samples); if (status < 0) { ALSA_CloseDevice(this); - SDL_SetError("Couldn't set minimum available samples: %s", - ALSA_snd_strerror(status)); - return 0; + return SDL_SetError("Couldn't set minimum available samples: %s", + ALSA_snd_strerror(status)); } status = ALSA_snd_pcm_sw_params_set_start_threshold(pcm_handle, swparams, 1); if (status < 0) { ALSA_CloseDevice(this); - SDL_SetError("ALSA: Couldn't set start threshold: %s", - ALSA_snd_strerror(status)); - return 0; + return SDL_SetError("ALSA: Couldn't set start threshold: %s", + ALSA_snd_strerror(status)); } status = ALSA_snd_pcm_sw_params(pcm_handle, swparams); if (status < 0) { ALSA_CloseDevice(this); - SDL_SetError("Couldn't set software audio parameters: %s", - ALSA_snd_strerror(status)); - return 0; + return SDL_SetError("Couldn't set software audio parameters: %s", + ALSA_snd_strerror(status)); } /* Calculate the final parameters for this audio specification */ @@ -653,8 +641,7 @@ ALSA_OpenDevice(_THIS, const char *devname, int iscapture) this->hidden->mixbuf = (Uint8 *) SDL_AllocAudioMem(this->hidden->mixlen); if (this->hidden->mixbuf == NULL) { ALSA_CloseDevice(this); - SDL_OutOfMemory(); - return 0; + return SDL_OutOfMemory(); } SDL_memset(this->hidden->mixbuf, this->spec.silence, this->spec.size); @@ -662,7 +649,7 @@ ALSA_OpenDevice(_THIS, const char *devname, int iscapture) ALSA_snd_pcm_nonblock(pcm_handle, 0); /* We're ready to rock and roll. :-) */ - return 1; + return 0; } static void diff --git a/src/audio/android/SDL_androidaudio.c b/src/audio/android/SDL_androidaudio.c index 0fe2e4e557..f828543853 100644 --- a/src/audio/android/SDL_androidaudio.c +++ b/src/audio/android/SDL_androidaudio.c @@ -42,21 +42,18 @@ AndroidAUD_OpenDevice(_THIS, const char *devname, int iscapture) if (iscapture) { //TODO: implement capture - SDL_SetError("Capture not supported on Android"); - return 0; + return SDL_SetError("Capture not supported on Android"); } if (audioDevice != NULL) { - SDL_SetError("Only one audio device at a time please!"); - return 0; + return SDL_SetError("Only one audio device at a time please!"); } audioDevice = this; this->hidden = SDL_malloc(sizeof(*(this->hidden))); if (!this->hidden) { - SDL_OutOfMemory(); - return 0; + return SDL_OutOfMemory(); } SDL_memset(this->hidden, 0, (sizeof *this->hidden)); @@ -71,8 +68,7 @@ AndroidAUD_OpenDevice(_THIS, const char *devname, int iscapture) if (test_format == 0) { // Didn't find a compatible format :( - SDL_SetError("No compatible audio format!"); - return 0; + return SDL_SetError("No compatible audio format!"); } if (this->spec.channels > 1) { @@ -94,11 +90,10 @@ AndroidAUD_OpenDevice(_THIS, const char *devname, int iscapture) if (this->spec.samples == 0) { // Init failed? - SDL_SetError("Java-side initialization failed!"); - return 0; + return SDL_SetError("Java-side initialization failed!"); } - return 1; + return 0; } static void diff --git a/src/audio/arts/SDL_artsaudio.c b/src/audio/arts/SDL_artsaudio.c index b4a94bcb9b..ac0bb9d5d0 100644 --- a/src/audio/arts/SDL_artsaudio.c +++ b/src/audio/arts/SDL_artsaudio.c @@ -241,8 +241,7 @@ ARTS_OpenDevice(_THIS, const char *devname, int iscapture) this->hidden = (struct SDL_PrivateAudioData *) SDL_malloc((sizeof *this->hidden)); if (this->hidden == NULL) { - SDL_OutOfMemory(); - return 0; + return SDL_OutOfMemory(); } SDL_memset(this->hidden, 0, (sizeof *this->hidden)); @@ -271,22 +270,19 @@ ARTS_OpenDevice(_THIS, const char *devname, int iscapture) } if (format == 0) { ARTS_CloseDevice(this); - SDL_SetError("Couldn't find any hardware audio formats"); - return 0; + return SDL_SetError("Couldn't find any hardware audio formats"); } this->spec.format = test_format; if ((rc = SDL_NAME(arts_init) ()) != 0) { ARTS_CloseDevice(this); - SDL_SetError("Unable to initialize ARTS: %s", - SDL_NAME(arts_error_text) (rc)); - return 0; + return SDL_SetError("Unable to initialize ARTS: %s", + SDL_NAME(arts_error_text) (rc)); } if (!ARTS_Suspend()) { ARTS_CloseDevice(this); - SDL_SetError("ARTS can not open audio device"); - return 0; + return SDL_SetError("ARTS can not open audio device"); } this->hidden->stream = SDL_NAME(arts_play_stream) (this->spec.freq, @@ -304,8 +300,7 @@ ARTS_OpenDevice(_THIS, const char *devname, int iscapture) for (frag_spec = 0; (0x01 << frag_spec) < this->spec.size; ++frag_spec); if ((0x01 << frag_spec) != this->spec.size) { ARTS_CloseDevice(this); - SDL_SetError("Fragment size must be a power of two"); - return 0; + return SDL_SetError("Fragment size must be a power of two"); } frag_spec |= 0x00020000; /* two fragments, for low latency */ @@ -326,8 +321,7 @@ ARTS_OpenDevice(_THIS, const char *devname, int iscapture) this->hidden->mixbuf = (Uint8 *) SDL_AllocAudioMem(this->hidden->mixlen); if (this->hidden->mixbuf == NULL) { ARTS_CloseDevice(this); - SDL_OutOfMemory(); - return 0; + return SDL_OutOfMemory(); } SDL_memset(this->hidden->mixbuf, this->spec.silence, this->spec.size); @@ -335,7 +329,7 @@ ARTS_OpenDevice(_THIS, const char *devname, int iscapture) this->hidden->parent = getpid(); /* We're ready to rock and roll. :-) */ - return 1; + return 0; } diff --git a/src/audio/baudio/SDL_beaudio.cc b/src/audio/baudio/SDL_beaudio.cc index 20396f31af..e2edf85fba 100644 --- a/src/audio/baudio/SDL_beaudio.cc +++ b/src/audio/baudio/SDL_beaudio.cc @@ -54,18 +54,18 @@ FillSound(void *device, void *stream, size_t len, if (!audio->paused) { if (audio->convert.needed) { - SDL_mutexP(audio->mixer_lock); + SDL_LockMutex(audio->mixer_lock); (*audio->spec.callback) (audio->spec.userdata, (Uint8 *) audio->convert.buf, audio->convert.len); - SDL_mutexV(audio->mixer_lock); + SDL_UnlockMutex(audio->mixer_lock); SDL_ConvertAudio(&audio->convert); SDL_memcpy(stream, audio->convert.buf, audio->convert.len_cvt); } else { - SDL_mutexP(audio->mixer_lock); + SDL_LockMutex(audio->mixer_lock); (*audio->spec.callback) (audio->spec.userdata, (Uint8 *) stream, len); - SDL_mutexV(audio->mixer_lock); + SDL_UnlockMutex(audio->mixer_lock); } } } @@ -95,8 +95,7 @@ BEOSAUDIO_OpenDevice(_THIS, const char *devname, int iscapture) /* Initialize all variables that we clean on shutdown */ _this->hidden = new SDL_PrivateAudioData; if (_this->hidden == NULL) { - SDL_OutOfMemory(); - return 0; + return SDL_OutOfMemory(); } SDL_memset(_this->hidden, 0, (sizeof *_this->hidden)); @@ -153,8 +152,7 @@ BEOSAUDIO_OpenDevice(_THIS, const char *devname, int iscapture) if (!valid_datatype) { /* shouldn't happen, but just in case... */ BEOSAUDIO_CloseDevice(_this); - SDL_SetError("Unsupported audio format"); - return 0; + return SDL_SetError("Unsupported audio format"); } /* Calculate the final parameters for this audio specification */ @@ -173,12 +171,11 @@ BEOSAUDIO_OpenDevice(_THIS, const char *devname, int iscapture) _this->hidden->audio_obj->SetHasData(true); } else { BEOSAUDIO_CloseDevice(_this); - SDL_SetError("Unable to start Be audio"); - return 0; + return SDL_SetError("Unable to start Be audio"); } /* We're running! */ - return 1; + return 0; } static void diff --git a/src/audio/bsd/SDL_bsdaudio.c b/src/audio/bsd/SDL_bsdaudio.c index d080d666ba..b63c838ad3 100644 --- a/src/audio/bsd/SDL_bsdaudio.c +++ b/src/audio/bsd/SDL_bsdaudio.c @@ -239,8 +239,7 @@ BSDAUDIO_OpenDevice(_THIS, const char *devname, int iscapture) if (devname == NULL) { devname = SDL_GetAudioDeviceName(0, iscapture); if (devname == NULL) { - SDL_SetError("No such audio device"); - return 0; + return SDL_SetError("No such audio device"); } } @@ -248,16 +247,14 @@ BSDAUDIO_OpenDevice(_THIS, const char *devname, int iscapture) this->hidden = (struct SDL_PrivateAudioData *) SDL_malloc((sizeof *this->hidden)); if (this->hidden == NULL) { - SDL_OutOfMemory(); - return 0; + return SDL_OutOfMemory(); } SDL_memset(this->hidden, 0, (sizeof *this->hidden)); /* Open the audio device */ this->hidden->audio_fd = open(devname, flags, 0); if (this->hidden->audio_fd < 0) { - SDL_SetError("Couldn't open %s: %s", devname, strerror(errno)); - return 0; + return SDL_SetError("Couldn't open %s: %s", devname, strerror(errno)); } AUDIO_INITINFO(&info); @@ -269,8 +266,7 @@ BSDAUDIO_OpenDevice(_THIS, const char *devname, int iscapture) info.mode = AUMODE_PLAY; if (ioctl(this->hidden->audio_fd, AUDIO_SETINFO, &info) < 0) { BSDAUDIO_CloseDevice(this); - SDL_SetError("Couldn't put device into play mode"); - return 0; + return SDL_SetError("Couldn't put device into play mode"); } AUDIO_INITINFO(&info); @@ -312,8 +308,7 @@ BSDAUDIO_OpenDevice(_THIS, const char *devname, int iscapture) if (!format) { BSDAUDIO_CloseDevice(this); - SDL_SetError("No supported encoding for 0x%x", this->spec.format); - return 0; + return SDL_SetError("No supported encoding for 0x%x", this->spec.format); } this->spec.format = format; @@ -336,15 +331,14 @@ BSDAUDIO_OpenDevice(_THIS, const char *devname, int iscapture) this->hidden->mixbuf = (Uint8 *) SDL_AllocAudioMem(this->hidden->mixlen); if (this->hidden->mixbuf == NULL) { BSDAUDIO_CloseDevice(this); - SDL_OutOfMemory(); - return 0; + return SDL_OutOfMemory(); } SDL_memset(this->hidden->mixbuf, this->spec.silence, this->spec.size); BSDAUDIO_Status(this); /* We're ready to rock and roll. :-) */ - return (0); + return 0; } static int diff --git a/src/audio/coreaudio/SDL_coreaudio.c b/src/audio/coreaudio/SDL_coreaudio.c index 533dcfdcaf..8f83d0b390 100644 --- a/src/audio/coreaudio/SDL_coreaudio.c +++ b/src/audio/coreaudio/SDL_coreaudio.c @@ -280,10 +280,10 @@ outputCallback(void *inRefCon, while (remaining > 0) { if (this->hidden->bufferOffset >= this->hidden->bufferSize) { /* Generate the data */ - SDL_mutexP(this->mixer_lock); + SDL_LockMutex(this->mixer_lock); (*this->spec.callback)(this->spec.userdata, this->hidden->buffer, this->hidden->bufferSize); - SDL_mutexV(this->mixer_lock); + SDL_UnlockMutex(this->mixer_lock); this->hidden->bufferOffset = 0; } @@ -469,8 +469,7 @@ COREAUDIO_OpenDevice(_THIS, const char *devname, int iscapture) this->hidden = (struct SDL_PrivateAudioData *) SDL_malloc((sizeof *this->hidden)); if (this->hidden == NULL) { - SDL_OutOfMemory(); - return (0); + return SDL_OutOfMemory(); } SDL_memset(this->hidden, 0, (sizeof *this->hidden)); @@ -511,8 +510,7 @@ COREAUDIO_OpenDevice(_THIS, const char *devname, int iscapture) if (!valid_datatype) { /* shouldn't happen, but just in case... */ COREAUDIO_CloseDevice(this); - SDL_SetError("Unsupported audio format"); - return 0; + return SDL_SetError("Unsupported audio format"); } strdesc.mBytesPerFrame = @@ -522,10 +520,10 @@ COREAUDIO_OpenDevice(_THIS, const char *devname, int iscapture) if (!prepare_audiounit(this, devname, iscapture, &strdesc)) { COREAUDIO_CloseDevice(this); - return 0; /* prepare_audiounit() will call SDL_SetError()... */ + return -1; /* prepare_audiounit() will call SDL_SetError()... */ } - return 1; /* good to go. */ + return 0; /* good to go. */ } static int diff --git a/src/audio/directsound/SDL_directsound.c b/src/audio/directsound/SDL_directsound.c index 24a599d54d..e320056b56 100644 --- a/src/audio/directsound/SDL_directsound.c +++ b/src/audio/directsound/SDL_directsound.c @@ -95,7 +95,7 @@ utf16_to_utf8(const WCHAR *S) (SDL_wcslen(S)+1)*sizeof(WCHAR)); } -static void +static int SetDSerror(const char *function, int code) { static const char *error; @@ -145,8 +145,7 @@ SetDSerror(const char *function, int code) SDL_snprintf(errbuf, SDL_arraysize(errbuf), "%s: %s", function, error); } - SDL_SetError("%s", errbuf); - return; + return SDL_SetError("%s", errbuf); } @@ -364,8 +363,7 @@ CreateSecondary(_THIS, HWND focus, WAVEFORMATEX * wavefmt) DSSCL_NORMAL); } if (result != DS_OK) { - SetDSerror("DirectSound SetCooperativeLevel", result); - return (-1); + return SetDSerror("DirectSound SetCooperativeLevel", result); } /* Try to create the secondary buffer */ @@ -380,16 +378,14 @@ CreateSecondary(_THIS, HWND focus, WAVEFORMATEX * wavefmt) format.dwBufferBytes = numchunks * chunksize; if ((format.dwBufferBytes < DSBSIZE_MIN) || (format.dwBufferBytes > DSBSIZE_MAX)) { - SDL_SetError("Sound buffer size must be between %d and %d", - DSBSIZE_MIN / numchunks, DSBSIZE_MAX / numchunks); - return (-1); + return SDL_SetError("Sound buffer size must be between %d and %d", + DSBSIZE_MIN / numchunks, DSBSIZE_MAX / numchunks); } format.dwReserved = 0; format.lpwfxFormat = wavefmt; result = IDirectSound_CreateSoundBuffer(sndObj, &format, sndbuf, NULL); if (result != DS_OK) { - SetDSerror("DirectSound CreateSoundBuffer", result); - return (-1); + return SetDSerror("DirectSound CreateSoundBuffer", result); } IDirectSoundBuffer_SetFormat(*sndbuf, wavefmt); @@ -452,8 +448,7 @@ DSOUND_OpenDevice(_THIS, const char *devname, int iscapture) pDirectSoundEnumerateW(FindDevGUID, &devguid); if (!devguid.found) { - SDL_SetError("DirectSound: Requested device not found"); - return 0; + return SDL_SetError("DirectSound: Requested device not found"); } guid = &devguid.guid; } @@ -462,8 +457,7 @@ DSOUND_OpenDevice(_THIS, const char *devname, int iscapture) this->hidden = (struct SDL_PrivateAudioData *) SDL_malloc((sizeof *this->hidden)); if (this->hidden == NULL) { - SDL_OutOfMemory(); - return 0; + return SDL_OutOfMemory(); } SDL_memset(this->hidden, 0, (sizeof *this->hidden)); @@ -481,8 +475,7 @@ DSOUND_OpenDevice(_THIS, const char *devname, int iscapture) if (!valid_format) { DSOUND_CloseDevice(this); - SDL_SetError("DirectSound: Unsupported audio format"); - return 0; + return SDL_SetError("DirectSound: Unsupported audio format"); } SDL_memset(&waveformat, 0, sizeof(waveformat)); @@ -502,21 +495,20 @@ DSOUND_OpenDevice(_THIS, const char *devname, int iscapture) result = pDirectSoundCreate8(guid, &this->hidden->sound, NULL); if (result != DS_OK) { DSOUND_CloseDevice(this); - SetDSerror("DirectSoundCreate", result); - return 0; + return SetDSerror("DirectSoundCreate", result); } /* Create the audio buffer to which we write */ this->hidden->num_buffers = CreateSecondary(this, NULL, &waveformat); if (this->hidden->num_buffers < 0) { DSOUND_CloseDevice(this); - return 0; + return -1; } /* The buffer will auto-start playing in DSOUND_WaitDevice() */ this->hidden->mixlen = this->spec.size; - return 1; /* good to go. */ + return 0; /* good to go. */ } diff --git a/src/audio/disk/SDL_diskaudio.c b/src/audio/disk/SDL_diskaudio.c index 3b5b7c9ff5..89687ed18a 100644 --- a/src/audio/disk/SDL_diskaudio.c +++ b/src/audio/disk/SDL_diskaudio.c @@ -110,8 +110,7 @@ DISKAUD_OpenDevice(_THIS, const char *devname, int iscapture) this->hidden = (struct SDL_PrivateAudioData *) SDL_malloc(sizeof(*this->hidden)); if (this->hidden == NULL) { - SDL_OutOfMemory(); - return 0; + return SDL_OutOfMemory(); } SDL_memset(this->hidden, 0, sizeof(*this->hidden)); @@ -119,14 +118,14 @@ DISKAUD_OpenDevice(_THIS, const char *devname, int iscapture) this->hidden->output = SDL_RWFromFile(fname, "wb"); if (this->hidden->output == NULL) { DISKAUD_CloseDevice(this); - return 0; + return -1; } /* Allocate mixing buffer */ this->hidden->mixbuf = (Uint8 *) SDL_AllocAudioMem(this->hidden->mixlen); if (this->hidden->mixbuf == NULL) { DISKAUD_CloseDevice(this); - return 0; + return -1; } SDL_memset(this->hidden->mixbuf, this->spec.silence, this->spec.size); @@ -141,7 +140,7 @@ DISKAUD_OpenDevice(_THIS, const char *devname, int iscapture) #endif /* We're ready to rock and roll. :-) */ - return 1; + return 0; } static int diff --git a/src/audio/dsp/SDL_dspaudio.c b/src/audio/dsp/SDL_dspaudio.c index c0a5d5be38..f868e874a1 100644 --- a/src/audio/dsp/SDL_dspaudio.c +++ b/src/audio/dsp/SDL_dspaudio.c @@ -89,8 +89,7 @@ DSP_OpenDevice(_THIS, const char *devname, int iscapture) if (devname == NULL) { devname = SDL_GetAudioDeviceName(0, iscapture); if (devname == NULL) { - SDL_SetError("No such audio device"); - return 0; + return SDL_SetError("No such audio device"); } } @@ -107,8 +106,7 @@ DSP_OpenDevice(_THIS, const char *devname, int iscapture) this->hidden = (struct SDL_PrivateAudioData *) SDL_malloc((sizeof *this->hidden)); if (this->hidden == NULL) { - SDL_OutOfMemory(); - return 0; + return SDL_OutOfMemory(); } SDL_memset(this->hidden, 0, (sizeof *this->hidden)); @@ -116,8 +114,7 @@ DSP_OpenDevice(_THIS, const char *devname, int iscapture) this->hidden->audio_fd = open(devname, flags, 0); if (this->hidden->audio_fd < 0) { DSP_CloseDevice(this); - SDL_SetError("Couldn't open %s: %s", devname, strerror(errno)); - return 0; + return SDL_SetError("Couldn't open %s: %s", devname, strerror(errno)); } this->hidden->mixbuf = NULL; @@ -128,8 +125,7 @@ DSP_OpenDevice(_THIS, const char *devname, int iscapture) ctlflags &= ~O_NONBLOCK; if (fcntl(this->hidden->audio_fd, F_SETFL, ctlflags) < 0) { DSP_CloseDevice(this); - SDL_SetError("Couldn't set audio blocking mode"); - return 0; + return SDL_SetError("Couldn't set audio blocking mode"); } } @@ -137,8 +133,7 @@ DSP_OpenDevice(_THIS, const char *devname, int iscapture) if (ioctl(this->hidden->audio_fd, SNDCTL_DSP_GETFMTS, &value) < 0) { perror("SNDCTL_DSP_GETFMTS"); DSP_CloseDevice(this); - SDL_SetError("Couldn't get audio format list"); - return 0; + return SDL_SetError("Couldn't get audio format list"); } /* Try for a closest match on audio format */ @@ -195,8 +190,7 @@ DSP_OpenDevice(_THIS, const char *devname, int iscapture) } if (format == 0) { DSP_CloseDevice(this); - SDL_SetError("Couldn't find any hardware audio formats"); - return 0; + return SDL_SetError("Couldn't find any hardware audio formats"); } this->spec.format = test_format; @@ -206,8 +200,7 @@ DSP_OpenDevice(_THIS, const char *devname, int iscapture) (value != format)) { perror("SNDCTL_DSP_SETFMT"); DSP_CloseDevice(this); - SDL_SetError("Couldn't set audio format"); - return 0; + return SDL_SetError("Couldn't set audio format"); } /* Set the number of channels of output */ @@ -215,8 +208,7 @@ DSP_OpenDevice(_THIS, const char *devname, int iscapture) if (ioctl(this->hidden->audio_fd, SNDCTL_DSP_CHANNELS, &value) < 0) { perror("SNDCTL_DSP_CHANNELS"); DSP_CloseDevice(this); - SDL_SetError("Cannot set the number of channels"); - return 0; + return SDL_SetError("Cannot set the number of channels"); } this->spec.channels = value; @@ -225,8 +217,7 @@ DSP_OpenDevice(_THIS, const char *devname, int iscapture) if (ioctl(this->hidden->audio_fd, SNDCTL_DSP_SPEED, &value) < 0) { perror("SNDCTL_DSP_SPEED"); DSP_CloseDevice(this); - SDL_SetError("Couldn't set audio frequency"); - return 0; + return SDL_SetError("Couldn't set audio frequency"); } this->spec.freq = value; @@ -237,8 +228,7 @@ DSP_OpenDevice(_THIS, const char *devname, int iscapture) for (frag_spec = 0; (0x01U << frag_spec) < this->spec.size; ++frag_spec); if ((0x01U << frag_spec) != this->spec.size) { DSP_CloseDevice(this); - SDL_SetError("Fragment size must be a power of two"); - return 0; + return SDL_SetError("Fragment size must be a power of two"); } frag_spec |= 0x00020000; /* two fragments, for low latency */ @@ -266,13 +256,12 @@ DSP_OpenDevice(_THIS, const char *devname, int iscapture) this->hidden->mixbuf = (Uint8 *) SDL_AllocAudioMem(this->hidden->mixlen); if (this->hidden->mixbuf == NULL) { DSP_CloseDevice(this); - SDL_OutOfMemory(); - return 0; + return SDL_OutOfMemory(); } SDL_memset(this->hidden->mixbuf, this->spec.silence, this->spec.size); /* We're ready to rock and roll. :-) */ - return 1; + return 0; } diff --git a/src/audio/dummy/SDL_dummyaudio.c b/src/audio/dummy/SDL_dummyaudio.c index 79106b91f1..c3e8ea415d 100644 --- a/src/audio/dummy/SDL_dummyaudio.c +++ b/src/audio/dummy/SDL_dummyaudio.c @@ -29,7 +29,7 @@ static int DUMMYAUD_OpenDevice(_THIS, const char *devname, int iscapture) { - return 1; /* always succeeds. */ + return 0; /* always succeeds. */ } static int diff --git a/src/audio/esd/SDL_esdaudio.c b/src/audio/esd/SDL_esdaudio.c index 307bba911f..cdc12120f4 100644 --- a/src/audio/esd/SDL_esdaudio.c +++ b/src/audio/esd/SDL_esdaudio.c @@ -228,8 +228,7 @@ ESD_OpenDevice(_THIS, const char *devname, int iscapture) this->hidden = (struct SDL_PrivateAudioData *) SDL_malloc((sizeof *this->hidden)); if (this->hidden == NULL) { - SDL_OutOfMemory(); - return 0; + return SDL_OutOfMemory(); } SDL_memset(this->hidden, 0, (sizeof *this->hidden)); this->hidden->audio_fd = -1; @@ -257,8 +256,7 @@ ESD_OpenDevice(_THIS, const char *devname, int iscapture) if (!found) { ESD_CloseDevice(this); - SDL_SetError("Couldn't find any hardware audio formats"); - return 0; + return SDL_SetError("Couldn't find any hardware audio formats"); } if (this->spec.channels == 1) { @@ -277,8 +275,7 @@ ESD_OpenDevice(_THIS, const char *devname, int iscapture) if (this->hidden->audio_fd < 0) { ESD_CloseDevice(this); - SDL_SetError("Couldn't open ESD connection"); - return 0; + return SDL_SetError("Couldn't open ESD connection"); } /* Calculate the final parameters for this audio specification */ @@ -292,8 +289,7 @@ ESD_OpenDevice(_THIS, const char *devname, int iscapture) this->hidden->mixbuf = (Uint8 *) SDL_AllocAudioMem(this->hidden->mixlen); if (this->hidden->mixbuf == NULL) { ESD_CloseDevice(this); - SDL_OutOfMemory(); - return 0; + return SDL_OutOfMemory(); } SDL_memset(this->hidden->mixbuf, this->spec.silence, this->spec.size); @@ -301,7 +297,7 @@ ESD_OpenDevice(_THIS, const char *devname, int iscapture) this->hidden->parent = getpid(); /* We're ready to rock and roll. :-) */ - return 1; + return 0; } static void diff --git a/src/audio/fusionsound/SDL_fsaudio.c b/src/audio/fusionsound/SDL_fsaudio.c index 8af02ffe1c..bc279fec6e 100644 --- a/src/audio/fusionsound/SDL_fsaudio.c +++ b/src/audio/fusionsound/SDL_fsaudio.c @@ -200,8 +200,7 @@ SDL_FS_OpenDevice(_THIS, const char *devname, int iscapture) this->hidden = (struct SDL_PrivateAudioData *) SDL_malloc((sizeof *this->hidden)); if (this->hidden == NULL) { - SDL_OutOfMemory(); - return 0; + return SDL_OutOfMemory(); } SDL_memset(this->hidden, 0, (sizeof *this->hidden)); @@ -243,8 +242,7 @@ SDL_FS_OpenDevice(_THIS, const char *devname, int iscapture) if (format == 0) { SDL_FS_CloseDevice(this); - SDL_SetError("Couldn't find any hardware audio formats"); - return 0; + return SDL_SetError("Couldn't find any hardware audio formats"); } this->spec.format = test_format; @@ -252,8 +250,7 @@ SDL_FS_OpenDevice(_THIS, const char *devname, int iscapture) ret = SDL_NAME(FusionSoundCreate) (&this->hidden->fs); if (ret) { SDL_FS_CloseDevice(this); - SDL_SetError("Unable to initialize FusionSound: %d", ret); - return 0; + return SDL_SetError("Unable to initialize FusionSound: %d", ret); } this->hidden->mixsamples = this->spec.size / bytes / this->spec.channels; @@ -272,8 +269,7 @@ SDL_FS_OpenDevice(_THIS, const char *devname, int iscapture) &this->hidden->stream); if (ret) { SDL_FS_CloseDevice(this); - SDL_SetError("Unable to create FusionSoundStream: %d", ret); - return 0; + return SDL_SetError("Unable to create FusionSoundStream: %d", ret); } /* See what we got */ @@ -294,13 +290,12 @@ SDL_FS_OpenDevice(_THIS, const char *devname, int iscapture) this->hidden->mixbuf = (Uint8 *) SDL_AllocAudioMem(this->hidden->mixlen); if (this->hidden->mixbuf == NULL) { SDL_FS_CloseDevice(this); - SDL_OutOfMemory(); - return 0; + return SDL_OutOfMemory(); } SDL_memset(this->hidden->mixbuf, this->spec.silence, this->spec.size); /* We're ready to rock and roll. :-) */ - return 1; + return 0; } diff --git a/src/audio/nas/SDL_nasaudio.c b/src/audio/nas/SDL_nasaudio.c index fac6ab3967..4e3dc0a136 100644 --- a/src/audio/nas/SDL_nasaudio.c +++ b/src/audio/nas/SDL_nasaudio.c @@ -288,8 +288,7 @@ NAS_OpenDevice(_THIS, const char *devname, int iscapture) this->hidden = (struct SDL_PrivateAudioData *) SDL_malloc((sizeof *this->hidden)); if (this->hidden == NULL) { - SDL_OutOfMemory(); - return 0; + return SDL_OutOfMemory(); } SDL_memset(this->hidden, 0, (sizeof *this->hidden)); @@ -304,24 +303,21 @@ NAS_OpenDevice(_THIS, const char *devname, int iscapture) } if (format == 0) { NAS_CloseDevice(this); - SDL_SetError("NAS: Couldn't find any hardware audio formats"); - return 0; + return SDL_SetError("NAS: Couldn't find any hardware audio formats"); } this->spec.format = test_format; this->hidden->aud = NAS_AuOpenServer("", 0, NULL, 0, NULL, NULL); if (this->hidden->aud == 0) { NAS_CloseDevice(this); - SDL_SetError("NAS: Couldn't open connection to NAS server"); - return 0; + return SDL_SetError("NAS: Couldn't open connection to NAS server"); } this->hidden->dev = find_device(this, this->spec.channels); if ((this->hidden->dev == AuNone) || (!(this->hidden->flow = NAS_AuCreateFlow(this->hidden->aud, 0)))) { NAS_CloseDevice(this); - SDL_SetError("NAS: Couldn't find a fitting device on NAS server"); - return 0; + return SDL_SetError("NAS: Couldn't find a fitting device on NAS server"); } buffer_size = this->spec.freq; @@ -354,13 +350,12 @@ NAS_OpenDevice(_THIS, const char *devname, int iscapture) this->hidden->mixbuf = (Uint8 *) SDL_AllocAudioMem(this->hidden->mixlen); if (this->hidden->mixbuf == NULL) { NAS_CloseDevice(this); - SDL_OutOfMemory(); - return 0; + return SDL_OutOfMemory(); } SDL_memset(this->hidden->mixbuf, this->spec.silence, this->spec.size); /* We're ready to rock and roll. :-) */ - return 1; + return 0; } static void diff --git a/src/audio/nds/SDL_ndsaudio.c b/src/audio/nds/SDL_ndsaudio.c deleted file mode 100644 index f729979ab1..0000000000 --- a/src/audio/nds/SDL_ndsaudio.c +++ /dev/null @@ -1,129 +0,0 @@ -/* - Simple DirectMedia Layer - Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org> - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. -*/ -#include "SDL_config.h" - -#if SDL_AUDIO_DRIVER_NDS - -/* Output audio to NDS */ - -#include <nds.h> - -#include "SDL_audio.h" -#include "../SDL_audio_c.h" -#include "SDL_ndsaudio.h" - -static int -NDSAUD_OpenDevice(_THIS, const char *devname, int iscapture) -{ - SDL_AudioFormat test_format = SDL_FirstAudioFormat(this->spec.format); - int valid_datatype = 0; - - this->hidden = SDL_malloc(sizeof(*(this->hidden))); - if (!this->hidden) { - SDL_OutOfMemory(); - return 0; - } - SDL_memset(this->hidden, 0, (sizeof *this->hidden)); - - while ((!valid_datatype) && (test_format)) { - this->spec.format = test_format; - switch (test_format) { - case AUDIO_S8: - /*case AUDIO_S16LSB: */ - valid_datatype = 1; - break; - default: - test_format = SDL_NextAudioFormat(); - break; - } - } - -#if 0 - /* set the generic sound parameters */ - setGenericSound(22050, /* sample rate */ - 127, /* volume */ - 64, /* panning/balance */ - 0); /* sound format */ -#endif - - return 1; -} - -static void -NDSAUD_PlayDevice(_THIS) -{ -#if 0 - playGenericSound(this->hidden->mixbuf, this->hidden->mixlen); - -// sound->data = this->hidden->mixbuf;/* pointer to raw audio data */ -// sound->len = this->hidden->mixlen; /* size of raw data pointed to above */ -// sound->rate = 22050; /* sample rate = 22050Hz */ -// sound->vol = 127; /* volume [0..127] for [min..max] */ -// sound->pan = 64; /* balance [0..127] for [left..right] */ -// sound->format = 0; /* 0 for 16-bit, 1 for 8-bit */ -// playSound(sound); -#endif -} - - -static Uint8 * -NDSAUD_GetDeviceBuf(_THIS) -{ - return this->hidden->mixbuf; /* is this right? */ -} - -static void -NDSAUD_WaitDevice(_THIS) -{ - /* stub */ -} - -static void -NDSAUD_CloseDevice(_THIS) -{ - /* stub */ -} - -static int -NDSAUD_Init(SDL_AudioDriverImpl * impl) -{ - /* Set the function pointers */ - impl->OpenDevice = NDSAUD_OpenDevice; - impl->PlayDevice = NDSAUD_PlayDevice; - impl->WaitDevice = NDSAUD_WaitDevice; - impl->GetDeviceBuf = NDSAUD_GetDeviceBuf; - impl->CloseDevice = NDSAUD_CloseDevice; - - /* and the capabilities */ - impl->HasCaptureSupport = 1; - impl->OnlyHasDefaultOutputDevice = 1; - impl->OnlyHasDefaultInputDevice = 1; - - return 1; /* this audio target is available. */ -} - -AudioBootStrap NDSAUD_bootstrap = { - "nds", "SDL NDS audio driver", NDSAUD_Init, 0 /*1? */ -}; - -#endif /* SDL_AUDIO_DRIVER_NDS */ - -/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/audio/paudio/SDL_paudio.c b/src/audio/paudio/SDL_paudio.c index 1cb77aa1c6..3966d1e7a2 100644 --- a/src/audio/paudio/SDL_paudio.c +++ b/src/audio/paudio/SDL_paudio.c @@ -264,8 +264,7 @@ PAUDIO_OpenDevice(_THIS, const char *devname, int iscapture) this->hidden = (struct SDL_PrivateAudioData *) SDL_malloc((sizeof *this->hidden)); if (this->hidden == NULL) { - SDL_OutOfMemory(); - return 0; + return SDL_OutOfMemory(); } SDL_memset(this->hidden, 0, (sizeof *this->hidden)); @@ -274,8 +273,7 @@ PAUDIO_OpenDevice(_THIS, const char *devname, int iscapture) this->hidden->audio_fd = fd; if (fd < 0) { PAUDIO_CloseDevice(this); - SDL_SetError("Couldn't open %s: %s", audiodev, strerror(errno)); - return 0; + return SDL_SetError("Couldn't open %s: %s", audiodev, strerror(errno)); } /* @@ -284,8 +282,7 @@ PAUDIO_OpenDevice(_THIS, const char *devname, int iscapture) */ if (ioctl(fd, AUDIO_BUFFER, &paud_bufinfo) < 0) { PAUDIO_CloseDevice(this); - SDL_SetError("Couldn't get audio buffer information"); - return 0; + return SDL_SetError("Couldn't get audio buffer information"); } if (this->spec.channels > 1) @@ -399,8 +396,7 @@ PAUDIO_OpenDevice(_THIS, const char *devname, int iscapture) fprintf(stderr, "Couldn't find any hardware audio formats\n"); #endif PAUDIO_CloseDevice(this); - SDL_SetError("Couldn't find any hardware audio formats"); - return 0; + return SDL_SetError("Couldn't find any hardware audio formats"); } this->spec.format = test_format; @@ -458,8 +454,7 @@ PAUDIO_OpenDevice(_THIS, const char *devname, int iscapture) if (err != NULL) { PAUDIO_CloseDevice(this); - SDL_SetError("Paudio: %s", err); - return 0; + return SDL_SetError("Paudio: %s", err); } /* Allocate mixing buffer */ @@ -467,8 +462,7 @@ PAUDIO_OpenDevice(_THIS, const char *devname, int iscapture) this->hidden->mixbuf = (Uint8 *) SDL_AllocAudioMem(this->hidden->mixlen); if (this->hidden->mixbuf == NULL) { PAUDIO_CloseDevice(this); - SDL_OutOfMemory(); - return 0; + return SDL_OutOfMemory(); } SDL_memset(this->hidden->mixbuf, this->spec.silence, this->spec.size); @@ -506,8 +500,7 @@ PAUDIO_OpenDevice(_THIS, const char *devname, int iscapture) #ifdef DEBUG_AUDIO fprintf(stderr, "Can't start audio play\n"); #endif - SDL_SetError("Can't start audio play"); - return 0; + return SDL_SetError("Can't start audio play"); } /* Check to see if we need to use select() workaround */ @@ -518,7 +511,7 @@ PAUDIO_OpenDevice(_THIS, const char *devname, int iscapture) } /* We're ready to rock and roll. :-) */ - return 1; + return 0; } static int diff --git a/src/audio/psp/SDL_pspaudio.c b/src/audio/psp/SDL_pspaudio.c new file mode 100644 index 0000000000..fc03a87544 --- /dev/null +++ b/src/audio/psp/SDL_pspaudio.c @@ -0,0 +1,195 @@ +/* + Simple DirectMedia Layer + Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org> + + This software is provided 'as-is', without any express or implied + warranty. In no event will the authors be held liable for any damages + arising from the use of this software. + + Permission is granted to anyone to use this software for any purpose, + including commercial applications, and to alter it and redistribute it + freely, subject to the following restrictions: + + 1. The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original software. + 3. This notice may not be removed or altered from any source distribution. +*/ + +#include <stdio.h> +#include <string.h> +#include <stdlib.h> +#include <malloc.h> + +#include "SDL_audio.h" +#include "SDL_error.h" +#include "SDL_timer.h" +#include "../SDL_audiomem.h" +#include "../SDL_audio_c.h" +#include "../SDL_audiodev_c.h" +#include "../SDL_sysaudio.h" +#include "SDL_pspaudio.h" + +#include <pspaudio.h> +#include <pspthreadman.h> + +/* The tag name used by PSP audio */ +#define PSPAUD_DRIVER_NAME "psp" + +static int +PSPAUD_OpenDevice(_THIS, const char *devname, int iscapture) +{ + int format, mixlen, i; + this->hidden = (struct SDL_PrivateAudioData *) + SDL_malloc(sizeof(*this->hidden)); + if (this->hidden == NULL) { + return SDL_OutOfMemory(); + } + SDL_memset(this->hidden, 0, sizeof(*this->hidden)); + switch (this->spec.format & 0xff) { + case 8: + case 16: + this->spec.format = AUDIO_S16LSB; + break; + default: + return SDL_SetError("Unsupported audio format"); + } + + /* The sample count must be a multiple of 64. */ + this->spec.samples = PSP_AUDIO_SAMPLE_ALIGN(this->spec.samples); + this->spec.freq = 44100; + + /* Update the fragment size as size in bytes. */ +// SDL_CalculateAudioSpec(this->spec); MOD + switch (this->spec.format) { + case AUDIO_U8: + this->spec.silence = 0x80; + break; + default: + this->spec.silence = 0x00; + break; + } + this->spec.size = SDL_AUDIO_BITSIZE(this->spec.format) / 8; + this->spec.size *= this->spec.channels; + this->spec.size *= this->spec.samples; + +//========================================== + + /* Allocate the mixing buffer. Its size and starting address must + be a multiple of 64 bytes. Our sample count is already a multiple of + 64, so spec->size should be a multiple of 64 as well. */ + mixlen = this->spec.size * NUM_BUFFERS; + this->hidden->rawbuf = (Uint8 *) memalign(64, mixlen); + if (this->hidden->rawbuf == NULL) { + return SDL_SetError("Couldn't allocate mixing buffer"); + } + + /* Setup the hardware channel. */ + if (this->spec.channels == 1) { + format = PSP_AUDIO_FORMAT_MONO; + } else { + format = PSP_AUDIO_FORMAT_STEREO; + } + this->hidden->channel = sceAudioChReserve(PSP_AUDIO_NEXT_CHANNEL, this->spec.samples, format); + if (this->hidden->channel < 0) { + free(this->hidden->rawbuf); + this->hidden->rawbuf = NULL; + return SDL_SetError("Couldn't reserve hardware channel"); + } + + memset(this->hidden->rawbuf, 0, mixlen); + for (i = 0; i < NUM_BUFFERS; i++) { + this->hidden->mixbufs[i] = &this->hidden->rawbuf[i * this->spec.size]; + } + + this->hidden->next_buffer = 0; + return 0; +} + +static void PSPAUD_PlayDevice(_THIS) +{ + Uint8 *mixbuf = this->hidden->mixbufs[this->hidden->next_buffer]; + + if (this->spec.channels == 1) { + sceAudioOutputBlocking(this->hidden->channel, PSP_AUDIO_VOLUME_MAX, mixbuf); + } else { + sceAudioOutputPannedBlocking(this->hidden->channel, PSP_AUDIO_VOLUME_MAX, PSP_AUDIO_VOLUME_MAX, mixbuf); + } + + this->hidden->next_buffer = (this->hidden->next_buffer + 1) % NUM_BUFFERS; +} + +/* This function waits until it is possible to write a full sound buffer */ +static void PSPAUD_WaitDevice(_THIS) +{ + /* Because we block when sending audio, there's no need for this function to do anything. */ +} +static Uint8 *PSPAUD_GetDeviceBuf(_THIS) +{ + return this->hidden->mixbufs[this->hidden->next_buffer]; +} + +static void PSPAUD_CloseDevice(_THIS) +{ + if (this->hidden->channel >= 0) { + sceAudioChRelease(this->hidden->channel); + this->hidden->channel = -1; + } + + if (this->hidden->rawbuf != NULL) { + free(this->hidden->rawbuf); + this->hidden->rawbuf = NULL; + } +} +static void PSPAUD_ThreadInit(_THIS) +{ + /* Increase the priority of this audio thread by 1 to put it + ahead of other SDL threads. */ + SceUID thid; + SceKernelThreadInfo status; + thid = sceKernelGetThreadId(); + status.size = sizeof(SceKernelThreadInfo); + if (sceKernelReferThreadStatus(thid, &status) == 0) { + sceKernelChangeThreadPriority(thid, status.currentPriority - 1); + } +} + + +static int +PSPAUD_Init(SDL_AudioDriverImpl * impl) +{ + + // Set the function pointers + impl->OpenDevice = PSPAUD_OpenDevice; + impl->PlayDevice = PSPAUD_PlayDevice; + impl->WaitDevice = PSPAUD_WaitDevice; + impl->GetDeviceBuf = PSPAUD_GetDeviceBuf; + impl->WaitDone = PSPAUD_WaitDevice; + impl->CloseDevice = PSPAUD_CloseDevice; + impl->ThreadInit = PSPAUD_ThreadInit; + + //PSP audio device + impl->OnlyHasDefaultOutputDevice = 1; +/* + impl->HasCaptureSupport = 1; + + impl->OnlyHasDefaultInputDevice = 1; +*/ + /* + impl->DetectDevices = DSOUND_DetectDevices; + impl->Deinitialize = DSOUND_Deinitialize; + */ + return 1; /* this audio target is available. */ +} + +AudioBootStrap PSPAUD_bootstrap = { + "psp", "PSP audio driver", PSPAUD_Init, 0 +}; + + /* SDL_AUDI*/ + + + diff --git a/src/audio/nds/SDL_ndsaudio.h b/src/audio/psp/SDL_pspaudio.h index 892c62f6ba..22cf2d327a 100644 --- a/src/audio/nds/SDL_ndsaudio.h +++ b/src/audio/psp/SDL_pspaudio.h @@ -18,25 +18,28 @@ misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ -#include "SDL_config.h" -#ifndef _SDL_ndsaudio_h -#define _SDL_ndsaudio_h +#ifndef _SDL_pspaudio_h +#define _SDL_pspaudio_h #include "../SDL_sysaudio.h" -#include <nds/arm9/sound.h> -/* Hidden "this" pointer for the audio functions */ +/* Hidden "this" pointer for the video functions */ #define _THIS SDL_AudioDevice *this -struct SDL_PrivateAudioData -{ - /* The file descriptor for the audio device */ - Uint8 *mixbuf; - Uint32 mixlen; - Uint32 write_delay; - Uint32 initial_calls; +#define NUM_BUFFERS 2 + +struct SDL_PrivateAudioData { + /* The hardware output channel. */ + int channel; + /* The raw allocated mixing buffer. */ + Uint8 *rawbuf; + /* Individual mixing buffers. */ + Uint8 *mixbufs[NUM_BUFFERS]; + /* Index of the next available mixing buffer. */ + int next_buffer; }; -#endif /* _SDL_ndsaudio_h */ -/* vi: set ts=4 sw=4 expandtab: */ +#endif /* _SDL_pspaudio_h */ +/* vim: ts=4 sw=4 + */ diff --git a/src/audio/pulseaudio/SDL_pulseaudio.c b/src/audio/pulseaudio/SDL_pulseaudio.c index 2d38975460..12021e6de8 100644 --- a/src/audio/pulseaudio/SDL_pulseaudio.c +++ b/src/audio/pulseaudio/SDL_pulseaudio.c @@ -205,6 +205,27 @@ load_pulseaudio_syms(void) } +/* Check to see if we can connect to PulseAudio */ +static SDL_bool +CheckPulseAudioAvailable() +{ + pa_simple *s; + pa_sample_spec ss; + + ss.format = PA_SAMPLE_S16NE; + ss.channels = 1; + ss.rate = 22050; + + s = PULSEAUDIO_pa_simple_new(NULL, "SDL", PA_STREAM_PLAYBACK, NULL, + "Test", &ss, NULL, NULL, NULL); + if (s) { + PULSEAUDIO_pa_simple_free(s); + return SDL_TRUE; + } else { + return SDL_FALSE; + } +} + /* This function waits until it is possible to write a full sound buffer */ static void PULSEAUDIO_WaitDevice(_THIS) @@ -316,8 +337,7 @@ PULSEAUDIO_OpenDevice(_THIS, const char *devname, int iscapture) this->hidden = (struct SDL_PrivateAudioData *) SDL_malloc((sizeof *this->hidden)); if (this->hidden == NULL) { - SDL_OutOfMemory(); - return 0; + return SDL_OutOfMemory(); } SDL_memset(this->hidden, 0, (sizeof *this->hidden)); h = this->hidden; @@ -350,8 +370,7 @@ PULSEAUDIO_OpenDevice(_THIS, const char *devname, int iscapture) } if (paspec.format == PA_SAMPLE_INVALID) { PULSEAUDIO_CloseDevice(this); - SDL_SetError("Couldn't find any hardware audio formats"); - return 0; + return SDL_SetError("Couldn't find any hardware audio formats"); } this->spec.format = test_format; @@ -366,8 +385,7 @@ PULSEAUDIO_OpenDevice(_THIS, const char *devname, int iscapture) h->mixbuf = (Uint8 *) SDL_AllocAudioMem(h->mixlen); if (h->mixbuf == NULL) { PULSEAUDIO_CloseDevice(this); - SDL_OutOfMemory(); - return 0; + return SDL_OutOfMemory(); } SDL_memset(h->mixbuf, this->spec.silence, this->spec.size); @@ -398,36 +416,31 @@ PULSEAUDIO_OpenDevice(_THIS, const char *devname, int iscapture) /* Set up a new main loop */ if (!(h->mainloop = PULSEAUDIO_pa_mainloop_new())) { PULSEAUDIO_CloseDevice(this); - SDL_SetError("pa_mainloop_new() failed"); - return 0; + return SDL_SetError("pa_mainloop_new() failed"); } h->mainloop_api = PULSEAUDIO_pa_mainloop_get_api(h->mainloop); h->context = PULSEAUDIO_pa_context_new(h->mainloop_api, NULL); if (!h->context) { PULSEAUDIO_CloseDevice(this); - SDL_SetError("pa_context_new() failed"); - return 0; + return SDL_SetError("pa_context_new() failed"); } /* Connect to the PulseAudio server */ if (PULSEAUDIO_pa_context_connect(h->context, NULL, 0, NULL) < 0) { PULSEAUDIO_CloseDevice(this); - SDL_SetError("Could not setup connection to PulseAudio"); - return 0; + return SDL_SetError("Could not setup connection to PulseAudio"); } do { if (PULSEAUDIO_pa_mainloop_iterate(h->mainloop, 1, NULL) < 0) { PULSEAUDIO_CloseDevice(this); - SDL_SetError("pa_mainloop_iterate() failed"); - return 0; + return SDL_SetError("pa_mainloop_iterate() failed"); } state = PULSEAUDIO_pa_context_get_state(h->context); if (!PA_CONTEXT_IS_GOOD(state)) { PULSEAUDIO_CloseDevice(this); - SDL_SetError("Could not connect to PulseAudio"); - return 0; + return SDL_SetError("Could not connect to PulseAudio"); } } while (state != PA_CONTEXT_READY); @@ -440,33 +453,29 @@ PULSEAUDIO_OpenDevice(_THIS, const char *devname, int iscapture) if (h->stream == NULL) { PULSEAUDIO_CloseDevice(this); - SDL_SetError("Could not set up PulseAudio stream"); - return 0; + return SDL_SetError("Could not set up PulseAudio stream"); } if (PULSEAUDIO_pa_stream_connect_playback(h->stream, NULL, &paattr, flags, NULL, NULL) < 0) { PULSEAUDIO_CloseDevice(this); - SDL_SetError("Could not connect PulseAudio stream"); - return 0; + return SDL_SetError("Could not connect PulseAudio stream"); } do { if (PULSEAUDIO_pa_mainloop_iterate(h->mainloop, 1, NULL) < 0) { PULSEAUDIO_CloseDevice(this); - SDL_SetError("pa_mainloop_iterate() failed"); - return 0; + return SDL_SetError("pa_mainloop_iterate() failed"); } state = PULSEAUDIO_pa_stream_get_state(h->stream); if (!PA_STREAM_IS_GOOD(state)) { PULSEAUDIO_CloseDevice(this); - SDL_SetError("Could not create to PulseAudio stream"); - return 0; + return SDL_SetError("Could not create to PulseAudio stream"); } } while (state != PA_STREAM_READY); /* We're ready to rock and roll. :-) */ - return 1; + return 0; } @@ -476,7 +485,6 @@ PULSEAUDIO_Deinitialize(void) UnloadPulseAudioLibrary(); } - static int PULSEAUDIO_Init(SDL_AudioDriverImpl * impl) { @@ -484,6 +492,11 @@ PULSEAUDIO_Init(SDL_AudioDriverImpl * impl) return 0; } + if (!CheckPulseAudioAvailable()) { + UnloadPulseAudioLibrary(); + return 0; + } + /* Set the function pointers */ impl->OpenDevice = PULSEAUDIO_OpenDevice; impl->PlayDevice = PULSEAUDIO_PlayDevice; diff --git a/src/audio/qsa/SDL_qsa_audio.c b/src/audio/qsa/SDL_qsa_audio.c index a72a19c6c2..e3877b4634 100644 --- a/src/audio/qsa/SDL_qsa_audio.c +++ b/src/audio/qsa/SDL_qsa_audio.c @@ -83,10 +83,10 @@ uint32_t qsa_playback_devices; QSA_Device qsa_capture_device[QSA_MAX_DEVICES]; uint32_t qsa_capture_devices; -static inline void +static inline int QSA_SetError(const char *fn, int status) { - SDL_SetError("QSA: %s() failed: %s", fn, snd_strerror(status)); + return SDL_SetError("QSA: %s() failed: %s", fn, snd_strerror(status)); } /* card names check to apply the workarounds */ @@ -183,13 +183,13 @@ QSA_WaitDevice(_THIS) switch (selectret) { case -1: { - SDL_SetError("QSA: select() failed: %s\n", strerror(errno)); + SDL_SetError("QSA: select() failed: %s", strerror(errno)); return; } break; case 0: { - SDL_SetError("QSA: timeout on buffer waiting occured\n"); + SDL_SetError("QSA: timeout on buffer waiting occured"); this->hidden->timeout_on_wait = 1; return; } @@ -237,7 +237,7 @@ QSA_PlayDevice(_THIS) /* the audio device driver */ if ((errno == EAGAIN) && (written == 0)) { if (this->hidden->timeout_on_wait != 0) { - SDL_SetError("QSA: buffer playback timeout\n"); + SDL_SetError("QSA: buffer playback timeout"); return; } } @@ -355,8 +355,7 @@ QSA_OpenDevice(_THIS, const char *devname, int iscapture) (struct SDL_PrivateAudioData))); if (this->hidden == NULL) { - SDL_OutOfMemory(); - return 0; + return SDL_OutOfMemory(); } SDL_memset(this->hidden, 0, sizeof(struct SDL_PrivateAudioData)); @@ -384,8 +383,7 @@ QSA_OpenDevice(_THIS, const char *devname, int iscapture) device++; if (device >= qsa_playback_devices) { QSA_CloseDevice(this); - SDL_SetError("No such playback device"); - return 0; + return SDL_SetError("No such playback device"); } } while (1); } @@ -409,8 +407,7 @@ QSA_OpenDevice(_THIS, const char *devname, int iscapture) device++; if (device >= qsa_capture_devices) { QSA_CloseDevice(this); - SDL_SetError("No such capture device"); - return 0; + return SDL_SetError("No such capture device"); } } while (1); } @@ -448,8 +445,7 @@ QSA_OpenDevice(_THIS, const char *devname, int iscapture) if (status < 0) { this->hidden->audio_handle = NULL; QSA_CloseDevice(this); - QSA_SetError("snd_pcm_open", status); - return 0; + return QSA_SetError("snd_pcm_open", status); } if (!QSA_CheckBuggyCards(this, QSA_MMAP_WORKAROUND)) { @@ -459,8 +455,7 @@ QSA_OpenDevice(_THIS, const char *devname, int iscapture) PLUGIN_DISABLE_MMAP); if (status < 0) { QSA_CloseDevice(this); - QSA_SetError("snd_pcm_plugin_set_disable", status); - return 0; + return QSA_SetError("snd_pcm_plugin_set_disable", status); } } @@ -546,8 +541,7 @@ QSA_OpenDevice(_THIS, const char *devname, int iscapture) /* assumes test_format not 0 on success */ if (test_format == 0) { QSA_CloseDevice(this); - SDL_SetError("QSA: Couldn't find any hardware audio formats"); - return 0; + return SDL_SetError("QSA: Couldn't find any hardware audio formats"); } this->spec.format = test_format; @@ -565,8 +559,7 @@ QSA_OpenDevice(_THIS, const char *devname, int iscapture) status = snd_pcm_plugin_params(this->hidden->audio_handle, &cparams); if (status < 0) { QSA_CloseDevice(this); - QSA_SetError("snd_pcm_channel_params", status); - return 0; + return QSA_SetError("snd_pcm_channel_params", status); } /* Make sure channel is setup right one last time */ @@ -580,8 +573,7 @@ QSA_OpenDevice(_THIS, const char *devname, int iscapture) /* Setup an audio channel */ if (snd_pcm_plugin_setup(this->hidden->audio_handle, &csetup) < 0) { QSA_CloseDevice(this); - SDL_SetError("QSA: Unable to setup channel\n"); - return 0; + return SDL_SetError("QSA: Unable to setup channel"); } /* Calculate the final parameters for this audio specification */ @@ -604,8 +596,7 @@ QSA_OpenDevice(_THIS, const char *devname, int iscapture) (Uint8 *) SDL_AllocAudioMem(this->hidden->pcm_len); if (this->hidden->pcm_buf == NULL) { QSA_CloseDevice(this); - SDL_OutOfMemory(); - return 0; + return SDL_OutOfMemory(); } SDL_memset(this->hidden->pcm_buf, this->spec.silence, this->hidden->pcm_len); @@ -623,8 +614,7 @@ QSA_OpenDevice(_THIS, const char *devname, int iscapture) if (this->hidden->audio_fd < 0) { QSA_CloseDevice(this); - QSA_SetError("snd_pcm_file_descriptor", status); - return 0; + return QSA_SetError("snd_pcm_file_descriptor", status); } /* Prepare an audio channel */ @@ -642,12 +632,11 @@ QSA_OpenDevice(_THIS, const char *devname, int iscapture) if (status < 0) { QSA_CloseDevice(this); - QSA_SetError("snd_pcm_plugin_prepare", status); - return 0; + return QSA_SetError("snd_pcm_plugin_prepare", status); } /* We're really ready to rock and roll. :-) */ - return 1; + return 0; } static void diff --git a/src/audio/sun/SDL_sunaudio.c b/src/audio/sun/SDL_sunaudio.c index d7ffbdb41a..37e175e107 100644 --- a/src/audio/sun/SDL_sunaudio.c +++ b/src/audio/sun/SDL_sunaudio.c @@ -22,11 +22,6 @@ #if SDL_AUDIO_DRIVER_SUNAUDIO -/* I'm gambling no one uses this audio backend...we'll see who emails. :) */ -#error this code has not been updated for SDL 1.3. -#error if no one emails icculus at icculus.org and tells him that this -#error code is needed, this audio backend will eventually be removed from SDL. - /* Allow access to a raw mixing buffer */ #include <fcntl.h> @@ -51,84 +46,21 @@ #include "SDL_sunaudio.h" /* Open the audio device for playback, and don't block if busy */ -#define OPEN_FLAGS (O_WRONLY|O_NONBLOCK) #if defined(AUDIO_GETINFO) && !defined(AUDIO_GETBUFINFO) #define AUDIO_GETBUFINFO AUDIO_GETINFO #endif /* Audio driver functions */ -static int DSP_OpenAudio(_THIS, SDL_AudioSpec * spec); -static void DSP_WaitAudio(_THIS); -static void DSP_PlayAudio(_THIS); -static Uint8 *DSP_GetAudioBuf(_THIS); -static void DSP_CloseAudio(_THIS); - static Uint8 snd2au(int sample); /* Audio driver bootstrap functions */ - -static int -Audio_Available(void) -{ - int fd; - int available; - - available = 0; - fd = SDL_OpenAudioPath(NULL, 0, OPEN_FLAGS, 1); - if (fd >= 0) { - available = 1; - close(fd); - } - return (available); -} - static void -Audio_DeleteDevice(SDL_AudioDevice * device) +SUNAUDIO_DetectDevices(int iscapture, SDL_AddAudioDevice addfn) { - SDL_free(device->hidden); - SDL_free(device); -} - -static SDL_AudioDevice * -Audio_CreateDevice(int devindex) -{ - SDL_AudioDevice *this; - - /* Initialize all variables that we clean on shutdown */ - this = (SDL_AudioDevice *) SDL_malloc(sizeof(SDL_AudioDevice)); - if (this) { - SDL_memset(this, 0, (sizeof *this)); - this->hidden = (struct SDL_PrivateAudioData *) - SDL_malloc((sizeof *this->hidden)); - } - if ((this == NULL) || (this->hidden == NULL)) { - SDL_OutOfMemory(); - if (this) { - SDL_free(this); - } - return (0); - } - SDL_memset(this->hidden, 0, (sizeof *this->hidden)); - audio_fd = -1; - - /* Set the function pointers */ - this->OpenAudio = DSP_OpenAudio; - this->WaitAudio = DSP_WaitAudio; - this->PlayAudio = DSP_PlayAudio; - this->GetAudioBuf = DSP_GetAudioBuf; - this->CloseAudio = DSP_CloseAudio; - - this->free = Audio_DeleteDevice; - - return this; + SDL_EnumUnixAudioDevices(iscapture, 1, (int (*)(int fd)) NULL, addfn); } -AudioBootStrap SUNAUDIO_bootstrap = { - "audio", "UNIX /dev/audio interface", - Audio_Available, Audio_CreateDevice, 0 -}; - #ifdef DEBUG_AUDIO void CheckUnderflow(_THIS) @@ -137,29 +69,29 @@ CheckUnderflow(_THIS) audio_info_t info; int left; - ioctl(audio_fd, AUDIO_GETBUFINFO, &info); - left = (written - info.play.samples); - if (written && (left == 0)) { + ioctl(this->hidden->audio_fd, AUDIO_GETBUFINFO, &info); + left = (this->hidden->written - info.play.samples); + if (this->hidden->written && (left == 0)) { fprintf(stderr, "audio underflow!\n"); } #endif } #endif -void -DSP_WaitAudio(_THIS) +static void +SUNAUDIO_WaitDevice(_THIS) { #ifdef AUDIO_GETBUFINFO #define SLEEP_FUDGE 10 /* 10 ms scheduling fudge factor */ audio_info_t info; Sint32 left; - ioctl(audio_fd, AUDIO_GETBUFINFO, &info); - left = (written - info.play.samples); - if (left > fragsize) { + ioctl(this->hidden->audio_fd, AUDIO_GETBUFINFO, &info); + left = (this->hidden->written - info.play.samples); + if (left > this->hidden->fragsize) { Sint32 sleepy; - sleepy = ((left - fragsize) / frequency); + sleepy = ((left - this->hidden->fragsize) / this->hidden->frequency); sleepy -= SLEEP_FUDGE; if (sleepy > 0) { SDL_Delay(sleepy); @@ -169,30 +101,30 @@ DSP_WaitAudio(_THIS) fd_set fdset; FD_ZERO(&fdset); - FD_SET(audio_fd, &fdset); - select(audio_fd + 1, NULL, &fdset, NULL, NULL); + FD_SET(this->hidden->audio_fd, &fdset); + select(this->hidden->audio_fd + 1, NULL, &fdset, NULL, NULL); #endif } -void -DSP_PlayAudio(_THIS) +static void +SUNAUDIO_PlayDevice(_THIS) { /* Write the audio data */ - if (ulaw_only) { + if (this->hidden->ulaw_only) { /* Assuming that this->spec.freq >= 8000 Hz */ int accum, incr, pos; Uint8 *aubuf; accum = 0; incr = this->spec.freq / 8; - aubuf = ulaw_buf; - switch (audio_fmt & 0xFF) { + aubuf = this->hidden->ulaw_buf; + switch (this->hidden->audio_fmt & 0xFF) { case 8: { Uint8 *sndbuf; - sndbuf = mixbuf; - for (pos = 0; pos < fragsize; ++pos) { + sndbuf = this->hidden->mixbuf; + for (pos = 0; pos < this->hidden->fragsize; ++pos) { *aubuf = snd2au((0x80 - *sndbuf) * 64); accum += incr; while (accum > 0) { @@ -207,8 +139,8 @@ DSP_PlayAudio(_THIS) { Sint16 *sndbuf; - sndbuf = (Sint16 *) mixbuf; - for (pos = 0; pos < fragsize; ++pos) { + sndbuf = (Sint16 *) this->hidden->mixbuf; + for (pos = 0; pos < this->hidden->fragsize; ++pos) { *aubuf = snd2au(*sndbuf / 4); accum += incr; while (accum > 0) { @@ -223,63 +155,93 @@ DSP_PlayAudio(_THIS) #ifdef DEBUG_AUDIO CheckUnderflow(this); #endif - if (write(audio_fd, ulaw_buf, fragsize) < 0) { + if (write(this->hidden->audio_fd, this->hidden->ulaw_buf, + this->hidden->fragsize) < 0) { /* Assume fatal error, for now */ this->enabled = 0; } - written += fragsize; + this->hidden->written += this->hidden->fragsize; } else { #ifdef DEBUG_AUDIO CheckUnderflow(this); #endif - if (write(audio_fd, mixbuf, this->spec.size) < 0) { + if (write(this->hidden->audio_fd, this->hidden->mixbuf, + this->spec.size) < 0) { /* Assume fatal error, for now */ this->enabled = 0; } - written += fragsize; + this->hidden->written += this->hidden->fragsize; } } -Uint8 * -DSP_GetAudioBuf(_THIS) +static Uint8 * +SUNAUDIO_GetDeviceBuf(_THIS) { - return (mixbuf); + return (this->hidden->mixbuf); } -void -DSP_CloseAudio(_THIS) +static void +SUNAUDIO_CloseDevice(_THIS) { - if (mixbuf != NULL) { - SDL_FreeAudioMem(mixbuf); - mixbuf = NULL; - } - if (ulaw_buf != NULL) { - SDL_free(ulaw_buf); - ulaw_buf = NULL; + if (this->hidden != NULL) { + if (this->hidden->mixbuf != NULL) { + SDL_FreeAudioMem(this->hidden->mixbuf); + this->hidden->mixbuf = NULL; + } + if (this->hidden->ulaw_buf != NULL) { + SDL_free(this->hidden->ulaw_buf); + this->hidden->ulaw_buf = NULL; + } + if (this->hidden->audio_fd >= 0) { + close(this->hidden->audio_fd); + this->hidden->audio_fd = -1; + } + SDL_free(this->hidden); + this->hidden = NULL; } - close(audio_fd); } -int -DSP_OpenAudio(_THIS, SDL_AudioSpec * spec) +static int +SUNAUDIO_OpenDevice(_THIS, const char *devname, int iscapture) { - char audiodev[1024]; + const int flags = ((iscapture) ? OPEN_FLAGS_INPUT : OPEN_FLAGS_OUTPUT); + SDL_AudioFormat format = 0; + audio_info_t info; + + /* We don't care what the devname is...we'll try to open anything. */ + /* ...but default to first name in the list... */ + if (devname == NULL) { + devname = SDL_GetAudioDeviceName(0, iscapture); + if (devname == NULL) { + return SDL_SetError("No such audio device"); + } + } + + /* Initialize all variables that we clean on shutdown */ + this->hidden = (struct SDL_PrivateAudioData *) + SDL_malloc((sizeof *this->hidden)); + if (this->hidden == NULL) { + return SDL_OutOfMemory(); + } + SDL_memset(this->hidden, 0, (sizeof *this->hidden)); + + /* Open the audio device */ + this->hidden->audio_fd = open(devname, flags, 0); + if (this->hidden->audio_fd < 0) { + return SDL_SetError("Couldn't open %s: %s", devname, strerror(errno)); + } + #ifdef AUDIO_SETINFO int enc; #endif - int desired_freq = spec->freq; - - /* Initialize our freeable variables, in case we fail */ - audio_fd = -1; - mixbuf = NULL; - ulaw_buf = NULL; + int desired_freq = this->spec.freq; /* Determine the audio parameters from the AudioSpec */ - switch (SDL_AUDIO_BITSIZE(spec->format)) { + switch (SDL_AUDIO_BITSIZE(this->spec.format)) { case 8: { /* Unsigned 8 bit audio data */ - spec->format = AUDIO_U8; + this->spec.format = AUDIO_U8; #ifdef AUDIO_SETINFO enc = AUDIO_ENCODING_LINEAR8; #endif @@ -288,7 +250,7 @@ DSP_OpenAudio(_THIS, SDL_AudioSpec * spec) case 16: { /* Signed 16 bit audio data */ - spec->format = AUDIO_S16SYS; + this->spec.format = AUDIO_S16SYS; #ifdef AUDIO_SETINFO enc = AUDIO_ENCODING_LINEAR; #endif @@ -298,44 +260,35 @@ DSP_OpenAudio(_THIS, SDL_AudioSpec * spec) default: { /* !!! FIXME: fallback to conversion on unsupported types! */ - SDL_SetError("Unsupported audio format"); - return (-1); + return SDL_SetError("Unsupported audio format"); } } - audio_fmt = spec->format; + this->hidden->audio_fmt = this->spec.format; - /* Open the audio device */ - audio_fd = SDL_OpenAudioPath(audiodev, sizeof(audiodev), OPEN_FLAGS, 1); - if (audio_fd < 0) { - SDL_SetError("Couldn't open %s: %s", audiodev, strerror(errno)); - return (-1); - } - - ulaw_only = 0; /* modern Suns do support linear audio */ + this->hidden->ulaw_only = 0; /* modern Suns do support linear audio */ #ifdef AUDIO_SETINFO for (;;) { audio_info_t info; AUDIO_INITINFO(&info); /* init all fields to "no change" */ /* Try to set the requested settings */ - info.play.sample_rate = spec->freq; - info.play.channels = spec->channels; + info.play.sample_rate = this->spec.freq; + info.play.channels = this->spec.channels; info.play.precision = (enc == AUDIO_ENCODING_ULAW) - ? 8 : spec->format & 0xff; + ? 8 : this->spec.format & 0xff; info.play.encoding = enc; - if (ioctl(audio_fd, AUDIO_SETINFO, &info) == 0) { + if (ioctl(this->hidden->audio_fd, AUDIO_SETINFO, &info) == 0) { /* Check to be sure we got what we wanted */ - if (ioctl(audio_fd, AUDIO_GETINFO, &info) < 0) { - SDL_SetError("Error getting audio parameters: %s", - strerror(errno)); - return -1; + if (ioctl(this->hidden->audio_fd, AUDIO_GETINFO, &info) < 0) { + return SDL_SetError("Error getting audio parameters: %s", + strerror(errno)); } if (info.play.encoding == enc - && info.play.precision == (spec->format & 0xff) - && info.play.channels == spec->channels) { + && info.play.precision == (this->spec.format & 0xff) + && info.play.channels == this->spec.channels) { /* Yow! All seems to be well! */ - spec->freq = info.play.sample_rate; + this->spec.freq = info.play.sample_rate; break; } } @@ -344,63 +297,61 @@ DSP_OpenAudio(_THIS, SDL_AudioSpec * spec) case AUDIO_ENCODING_LINEAR8: /* unsigned 8bit apparently not supported here */ enc = AUDIO_ENCODING_LINEAR; - spec->format = AUDIO_S16SYS; + this->spec.format = AUDIO_S16SYS; break; /* try again */ case AUDIO_ENCODING_LINEAR: /* linear 16bit didn't work either, resort to µ-law */ enc = AUDIO_ENCODING_ULAW; - spec->channels = 1; - spec->freq = 8000; - spec->format = AUDIO_U8; - ulaw_only = 1; + this->spec.channels = 1; + this->spec.freq = 8000; + this->spec.format = AUDIO_U8; + this->hidden->ulaw_only = 1; break; default: /* oh well... */ - SDL_SetError("Error setting audio parameters: %s", - strerror(errno)); - return -1; + return SDL_SetError("Error setting audio parameters: %s", + strerror(errno)); } } #endif /* AUDIO_SETINFO */ - written = 0; + this->hidden->written = 0; /* We can actually convert on-the-fly to U-Law */ - if (ulaw_only) { - spec->freq = desired_freq; - fragsize = (spec->samples * 1000) / (spec->freq / 8); - frequency = 8; - ulaw_buf = (Uint8 *) SDL_malloc(fragsize); - if (ulaw_buf == NULL) { - SDL_OutOfMemory(); - return (-1); + if (this->hidden->ulaw_only) { + this->spec.freq = desired_freq; + this->hidden->fragsize = (this->spec.samples * 1000) / + (this->spec.freq / 8); + this->hidden->frequency = 8; + this->hidden->ulaw_buf = (Uint8 *) SDL_malloc(this->hidden->fragsize); + if (this->hidden->ulaw_buf == NULL) { + return SDL_OutOfMemory(); } - spec->channels = 1; + this->spec.channels = 1; } else { - fragsize = spec->samples; - frequency = spec->freq / 1000; + this->hidden->fragsize = this->spec.samples; + this->hidden->frequency = this->spec.freq / 1000; } #ifdef DEBUG_AUDIO fprintf(stderr, "Audio device %s U-Law only\n", - ulaw_only ? "is" : "is not"); + this->hidden->ulaw_only ? "is" : "is not"); fprintf(stderr, "format=0x%x chan=%d freq=%d\n", - spec->format, spec->channels, spec->freq); + this->spec.format, this->spec.channels, this->spec.freq); #endif /* Update the fragment size as size in bytes */ - SDL_CalculateAudioSpec(spec); + SDL_CalculateAudioSpec(&this->spec); /* Allocate mixing buffer */ - mixbuf = (Uint8 *) SDL_AllocAudioMem(spec->size); - if (mixbuf == NULL) { - SDL_OutOfMemory(); - return (-1); + this->hidden->mixbuf = (Uint8 *) SDL_AllocAudioMem(this->spec.size); + if (this->hidden->mixbuf == NULL) { + return SDL_OutOfMemory(); } - SDL_memset(mixbuf, spec->silence, spec->size); + SDL_memset(this->hidden->mixbuf, this->spec.silence, this->spec.size); /* We're ready to rock and roll. :-) */ - return (0); + return 0; } /************************************************************************/ @@ -456,6 +407,24 @@ snd2au(int sample) return (mask & sample); } +static int +SUNAUDIO_Init(SDL_AudioDriverImpl * impl) +{ + /* Set the function pointers */ + impl->DetectDevices = SUNAUDIO_DetectDevices; + impl->OpenDevice = SUNAUDIO_OpenDevice; + impl->PlayDevice = SUNAUDIO_PlayDevice; + impl->WaitDevice = SUNAUDIO_WaitDevice; + impl->GetDeviceBuf = SUNAUDIO_GetDeviceBuf; + impl->CloseDevice = SUNAUDIO_CloseDevice; + + return 1; /* this audio target is available. */ +} + +AudioBootStrap SUNAUDIO_bootstrap = { + "audio", "UNIX /dev/audio interface", SUNAUDIO_Init, 0 +}; + #endif /* SDL_AUDIO_DRIVER_SUNAUDIO */ /* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/audio/sun/SDL_sunaudio.h b/src/audio/sun/SDL_sunaudio.h index 67b01dc1df..1f2c0b4f24 100644 --- a/src/audio/sun/SDL_sunaudio.h +++ b/src/audio/sun/SDL_sunaudio.h @@ -42,16 +42,6 @@ struct SDL_PrivateAudioData int frequency; /* The audio frequency in KHz */ }; -/* Old variable names */ -#define audio_fd (this->hidden->audio_fd) -#define audio_fmt (this->hidden->audio_fmt) -#define mixbuf (this->hidden->mixbuf) -#define ulaw_only (this->hidden->ulaw_only) -#define ulaw_buf (this->hidden->ulaw_buf) -#define written (this->hidden->written) -#define fragsize (this->hidden->fragsize) -#define frequency (this->hidden->frequency) - #endif /* _SDL_sunaudio_h */ /* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/audio/winmm/SDL_winmm.c b/src/audio/winmm/SDL_winmm.c index 990f4d11c2..f52a3afb1a 100644 --- a/src/audio/winmm/SDL_winmm.c +++ b/src/audio/winmm/SDL_winmm.c @@ -91,7 +91,7 @@ FillSound(HWAVEOUT hwo, UINT uMsg, DWORD_PTR dwInstance, ReleaseSemaphore(this->hidden->audio_sem, 1, NULL); } -static void +static int SetMMerror(char *function, MMRESULT code) { size_t len; @@ -105,7 +105,7 @@ SetMMerror(char *function, MMRESULT code) WideCharToMultiByte(CP_ACP, 0, werrbuf, -1, errbuf + len, MAXERRORLENGTH - len, NULL, NULL); - SDL_SetError("%s", errbuf); + return SDL_SetError("%s", errbuf); } static void @@ -234,8 +234,7 @@ WINMM_OpenDevice(_THIS, const char *devname, int iscapture) } if (devId == WAVE_MAPPER) { - SDL_SetError("Requested device not found"); - return 0; + return SDL_SetError("Requested device not found"); } } @@ -243,8 +242,7 @@ WINMM_OpenDevice(_THIS, const char *devname, int iscapture) this->hidden = (struct SDL_PrivateAudioData *) SDL_malloc((sizeof *this->hidden)); if (this->hidden == NULL) { - SDL_OutOfMemory(); - return 0; + return SDL_OutOfMemory(); } SDL_memset(this->hidden, 0, (sizeof *this->hidden)); @@ -270,8 +268,7 @@ WINMM_OpenDevice(_THIS, const char *devname, int iscapture) if (!valid_datatype) { WINMM_CloseDevice(this); - SDL_SetError("Unsupported audio format"); - return 0; + return SDL_SetError("Unsupported audio format"); } /* Set basic WAVE format parameters */ @@ -309,8 +306,7 @@ WINMM_OpenDevice(_THIS, const char *devname, int iscapture) if (result != MMSYSERR_NOERROR) { WINMM_CloseDevice(this); - SetMMerror("waveOutOpen()", result); - return 0; + return SetMMerror("waveOutOpen()", result); } #ifdef SOUND_DEBUG /* Check the sound device we retrieved */ @@ -321,8 +317,7 @@ WINMM_OpenDevice(_THIS, const char *devname, int iscapture) &caps, sizeof(caps)); if (result != MMSYSERR_NOERROR) { WINMM_CloseDevice(this); - SetMMerror("waveOutGetDevCaps()", result); - return 0; + return SetMMerror("waveOutGetDevCaps()", result); } printf("Audio device: %s\n", caps.szPname); } @@ -333,8 +328,7 @@ WINMM_OpenDevice(_THIS, const char *devname, int iscapture) CreateSemaphore(NULL, NUM_BUFFERS - 1, NUM_BUFFERS, NULL); if (this->hidden->audio_sem == NULL) { WINMM_CloseDevice(this); - SDL_SetError("Couldn't create semaphore"); - return 0; + return SDL_SetError("Couldn't create semaphore"); } /* Create the sound buffers */ @@ -342,8 +336,7 @@ WINMM_OpenDevice(_THIS, const char *devname, int iscapture) (Uint8 *) SDL_malloc(NUM_BUFFERS * this->spec.size); if (this->hidden->mixbuf == NULL) { WINMM_CloseDevice(this); - SDL_OutOfMemory(); - return 0; + return SDL_OutOfMemory(); } for (i = 0; i < NUM_BUFFERS; ++i) { SDL_memset(&this->hidden->wavebuf[i], 0, @@ -357,12 +350,11 @@ WINMM_OpenDevice(_THIS, const char *devname, int iscapture) sizeof(this->hidden->wavebuf[i])); if (result != MMSYSERR_NOERROR) { WINMM_CloseDevice(this); - SetMMerror("waveOutPrepareHeader()", result); - return 0; + return SetMMerror("waveOutPrepareHeader()", result); } } - return 1; /* Ready to go! */ + return 0; /* Ready to go! */ } diff --git a/src/audio/xaudio2/SDL_xaudio2.c b/src/audio/xaudio2/SDL_xaudio2.c index e86490767b..1452090c94 100644 --- a/src/audio/xaudio2/SDL_xaudio2.c +++ b/src/audio/xaudio2/SDL_xaudio2.c @@ -350,11 +350,9 @@ XAUDIO2_OpenDevice(_THIS, const char *devname, int iscapture) #endif if (iscapture) { - SDL_SetError("XAudio2: capture devices unsupported."); - return 0; + return SDL_SetError("XAudio2: capture devices unsupported."); } else if (XAudio2Create(&ixa2, 0, XAUDIO2_DEFAULT_PROCESSOR) != S_OK) { - SDL_SetError("XAudio2: XAudio2Create() failed."); - return 0; + return SDL_SetError("XAudio2: XAudio2Create() failed."); } /* XAUDIO2_DEBUG_CONFIGURATION debugConfig; @@ -374,8 +372,7 @@ XAUDIO2_OpenDevice(_THIS, const char *devname, int iscapture) if (IXAudio2_GetDeviceCount(ixa2, &devcount) != S_OK) { IXAudio2_Release(ixa2); - SDL_SetError("XAudio2: IXAudio2_GetDeviceCount() failed."); - return 0; + return SDL_SetError("XAudio2: IXAudio2_GetDeviceCount() failed."); } for (i = 0; i < devcount; i++) { XAUDIO2_DEVICE_DETAILS details; @@ -399,8 +396,7 @@ XAUDIO2_OpenDevice(_THIS, const char *devname, int iscapture) if (i == devcount) { IXAudio2_Release(ixa2); - SDL_SetError("XAudio2: Requested device not found."); - return 0; + return SDL_SetError("XAudio2: Requested device not found."); } } #endif @@ -410,8 +406,7 @@ XAUDIO2_OpenDevice(_THIS, const char *devname, int iscapture) SDL_malloc((sizeof *this->hidden)); if (this->hidden == NULL) { IXAudio2_Release(ixa2); - SDL_OutOfMemory(); - return 0; + return SDL_OutOfMemory(); } SDL_memset(this->hidden, 0, (sizeof *this->hidden)); @@ -419,8 +414,7 @@ XAUDIO2_OpenDevice(_THIS, const char *devname, int iscapture) this->hidden->semaphore = SDL_CreateSemaphore(1); if (this->hidden->semaphore == NULL) { XAUDIO2_CloseDevice(this); - SDL_SetError("XAudio2: CreateSemaphore() failed!"); - return 0; + return SDL_SetError("XAudio2: CreateSemaphore() failed!"); } while ((!valid_format) && (test_format)) { @@ -438,8 +432,7 @@ XAUDIO2_OpenDevice(_THIS, const char *devname, int iscapture) if (!valid_format) { XAUDIO2_CloseDevice(this); - SDL_SetError("XAudio2: Unsupported audio format"); - return 0; + return SDL_SetError("XAudio2: Unsupported audio format"); } /* Update the fragment size as size in bytes */ @@ -450,8 +443,7 @@ XAUDIO2_OpenDevice(_THIS, const char *devname, int iscapture) this->hidden->mixbuf = (Uint8 *) SDL_malloc(2 * this->hidden->mixlen); if (this->hidden->mixbuf == NULL) { XAUDIO2_CloseDevice(this); - SDL_OutOfMemory(); - return 0; + return SDL_OutOfMemory(); } this->hidden->nextbuf = this->hidden->mixbuf; SDL_memset(this->hidden->mixbuf, 0, 2 * this->hidden->mixlen); @@ -467,8 +459,7 @@ XAUDIO2_OpenDevice(_THIS, const char *devname, int iscapture) this->spec.freq, 0, devId, NULL); if (result != S_OK) { XAUDIO2_CloseDevice(this); - SDL_SetError("XAudio2: Couldn't create mastering voice"); - return 0; + return SDL_SetError("XAudio2: Couldn't create mastering voice"); } SDL_zero(waveformat); @@ -503,8 +494,7 @@ XAUDIO2_OpenDevice(_THIS, const char *devname, int iscapture) #endif if (result != S_OK) { XAUDIO2_CloseDevice(this); - SDL_SetError("XAudio2: Couldn't create source voice"); - return 0; + return SDL_SetError("XAudio2: Couldn't create source voice"); } this->hidden->source = source; @@ -512,18 +502,16 @@ XAUDIO2_OpenDevice(_THIS, const char *devname, int iscapture) result = IXAudio2_StartEngine(ixa2); if (result != S_OK) { XAUDIO2_CloseDevice(this); - SDL_SetError("XAudio2: Couldn't start engine"); - return 0; + return SDL_SetError("XAudio2: Couldn't start engine"); } result = IXAudio2SourceVoice_Start(source, 0, XAUDIO2_COMMIT_NOW); if (result != S_OK) { XAUDIO2_CloseDevice(this); - SDL_SetError("XAudio2: Couldn't start source voice"); - return 0; + return SDL_SetError("XAudio2: Couldn't start source voice"); } - return 1; /* good to go. */ + return 0; /* good to go. */ } static void diff --git a/src/core/android/SDL_android.cpp b/src/core/android/SDL_android.cpp index 02e28ff9a1..5ae8f93a04 100644 --- a/src/core/android/SDL_android.cpp +++ b/src/core/android/SDL_android.cpp @@ -509,7 +509,8 @@ extern "C" void Android_JNI_CloseAudioDevice() } // Test for an exception and call SDL_SetError with its detail if one occurs -static bool Android_JNI_ExceptionOccurred() +// If optional parameter silent is truthy then SDL_SetError() is not called. +static bool Android_JNI_ExceptionOccurred(bool silent = false) { SDL_assert(LocalReferenceHolder::IsActive()); JNIEnv *mEnv = Android_JNI_GetEnv(); @@ -521,26 +522,27 @@ static bool Android_JNI_ExceptionOccurred() // Until this happens most JNI operations have undefined behaviour mEnv->ExceptionClear(); - jclass exceptionClass = mEnv->GetObjectClass(exception); - jclass classClass = mEnv->FindClass("java/lang/Class"); + if (!silent) { + jclass exceptionClass = mEnv->GetObjectClass(exception); + jclass classClass = mEnv->FindClass("java/lang/Class"); - mid = mEnv->GetMethodID(classClass, "getName", "()Ljava/lang/String;"); - jstring exceptionName = (jstring)mEnv->CallObjectMethod(exceptionClass, mid); - const char* exceptionNameUTF8 = mEnv->GetStringUTFChars(exceptionName, 0); + mid = mEnv->GetMethodID(classClass, "getName", "()Ljava/lang/String;"); + jstring exceptionName = (jstring)mEnv->CallObjectMethod(exceptionClass, mid); + const char* exceptionNameUTF8 = mEnv->GetStringUTFChars(exceptionName, 0); - mid = mEnv->GetMethodID(exceptionClass, "getMessage", "()Ljava/lang/String;"); - jstring exceptionMessage = (jstring)mEnv->CallObjectMethod(exception, mid); + mid = mEnv->GetMethodID(exceptionClass, "getMessage", "()Ljava/lang/String;"); + jstring exceptionMessage = (jstring)mEnv->CallObjectMethod(exception, mid); - if (exceptionMessage != NULL) { - const char* exceptionMessageUTF8 = mEnv->GetStringUTFChars( - exceptionMessage, 0); - SDL_SetError("%s: %s", exceptionNameUTF8, exceptionMessageUTF8); - mEnv->ReleaseStringUTFChars(exceptionMessage, exceptionMessageUTF8); - } else { - SDL_SetError("%s", exceptionNameUTF8); - } + if (exceptionMessage != NULL) { + const char* exceptionMessageUTF8 = mEnv->GetStringUTFChars(exceptionMessage, 0); + SDL_SetError("%s: %s", exceptionNameUTF8, exceptionMessageUTF8); + mEnv->ReleaseStringUTFChars(exceptionMessage, exceptionMessageUTF8); + } else { + SDL_SetError("%s", exceptionNameUTF8); + } - mEnv->ReleaseStringUTFChars(exceptionName, exceptionNameUTF8); + mEnv->ReleaseStringUTFChars(exceptionName, exceptionNameUTF8); + } return true; } @@ -588,19 +590,19 @@ static int Android_JNI_FileOpen(SDL_RWops* ctx) */ mid = mEnv->GetMethodID(mEnv->GetObjectClass(assetManager), "openFd", "(Ljava/lang/String;)Landroid/content/res/AssetFileDescriptor;"); inputStream = mEnv->CallObjectMethod(assetManager, mid, fileNameJString); - if (Android_JNI_ExceptionOccurred()) { + if (Android_JNI_ExceptionOccurred(true)) { goto fallback; } mid = mEnv->GetMethodID(mEnv->GetObjectClass(inputStream), "getStartOffset", "()J"); ctx->hidden.androidio.offset = mEnv->CallLongMethod(inputStream, mid); - if (Android_JNI_ExceptionOccurred()) { + if (Android_JNI_ExceptionOccurred(true)) { goto fallback; } mid = mEnv->GetMethodID(mEnv->GetObjectClass(inputStream), "getDeclaredLength", "()J"); ctx->hidden.androidio.size = mEnv->CallLongMethod(inputStream, mid); - if (Android_JNI_ExceptionOccurred()) { + if (Android_JNI_ExceptionOccurred(true)) { goto fallback; } @@ -778,8 +780,7 @@ static int Android_JNI_FileClose(SDL_RWops* ctx, bool release) JNIEnv *mEnv = Android_JNI_GetEnv(); if (!refs.init(mEnv)) { - SDL_SetError("Failed to allocate enough JVM local references"); - return -1; + return SDL_SetError("Failed to allocate enough JVM local references"); } if (ctx) { @@ -842,8 +843,7 @@ extern "C" Sint64 Android_JNI_FileSeek(SDL_RWops* ctx, Sint64 offset, int whence offset = ctx->hidden.androidio.offset + ctx->hidden.androidio.size + offset; break; default: - SDL_SetError("Unknown value for 'whence'"); - return -1; + return SDL_SetError("Unknown value for 'whence'"); } whence = SEEK_SET; @@ -864,14 +864,12 @@ extern "C" Sint64 Android_JNI_FileSeek(SDL_RWops* ctx, Sint64 offset, int whence newPosition = ctx->hidden.androidio.size + offset; break; default: - SDL_SetError("Unknown value for 'whence'"); - return -1; + return SDL_SetError("Unknown value for 'whence'"); } /* Validate the new position */ if (newPosition < 0) { - SDL_Error(SDL_EFSEEK); - return -1; + return SDL_Error(SDL_EFSEEK); } if (newPosition > ctx->hidden.androidio.size) { newPosition = ctx->hidden.androidio.size; diff --git a/src/core/windows/SDL_windows.c b/src/core/windows/SDL_windows.c index 67c360cd42..2388f93faf 100644 --- a/src/core/windows/SDL_windows.c +++ b/src/core/windows/SDL_windows.c @@ -24,12 +24,12 @@ #include "SDL_error.h" #include "SDL_windows.h" +#include "SDL_assert.h" #include <objbase.h> /* for CoInitialize/CoUninitialize (Win32 only) */ - /* Sets an error message based on GetLastError() */ -void +int WIN_SetErrorFromHRESULT(const char *prefix, HRESULT hr) { TCHAR buffer[1024]; @@ -39,13 +39,14 @@ WIN_SetErrorFromHRESULT(const char *prefix, HRESULT hr) message = WIN_StringToUTF8(buffer); SDL_SetError("%s%s%s", prefix ? prefix : "", prefix ? ": " : "", message); SDL_free(message); + return -1; } /* Sets an error message based on GetLastError() */ -void +int WIN_SetError(const char *prefix) { - WIN_SetErrorFromHRESULT(prefix, GetLastError()); + return WIN_SetErrorFromHRESULT(prefix, GetLastError()); } HRESULT diff --git a/src/core/windows/SDL_windows.h b/src/core/windows/SDL_windows.h index fcb0ed90ff..ce614a998e 100644 --- a/src/core/windows/SDL_windows.h +++ b/src/core/windows/SDL_windows.h @@ -36,7 +36,6 @@ #include <windows.h> - /* Routines to convert from UTF8 to native Windows text */ #if UNICODE #define WIN_StringToUTF8(S) SDL_iconv_string("UTF-8", "UCS-2-INTERNAL", (char *)(S), (SDL_wcslen(S)+1)*sizeof(WCHAR)) @@ -47,10 +46,10 @@ #endif /* Sets an error message based on a given HRESULT */ -extern void WIN_SetErrorFromHRESULT(const char *prefix, HRESULT hr); +extern int WIN_SetErrorFromHRESULT(const char *prefix, HRESULT hr); -/* Sets an error message based on GetLastError() */ -extern void WIN_SetError(const char *prefix); +/* Sets an error message based on GetLastError(). Always return -1. */ +extern int WIN_SetError(const char *prefix); /* Wrap up the oddities of CoInitialize() into a common function. */ extern HRESULT WIN_CoInitialize(void); diff --git a/src/events/SDL_events.c b/src/events/SDL_events.c index 40bf8b0b49..ade28a697c 100644 --- a/src/events/SDL_events.c +++ b/src/events/SDL_events.c @@ -212,7 +212,7 @@ SDL_PeepEvents(SDL_Event * events, int numevents, SDL_eventaction action, } /* Lock the event queue */ used = 0; - if (!SDL_EventQ.lock || SDL_mutexP(SDL_EventQ.lock) == 0) { + if (!SDL_EventQ.lock || SDL_LockMutex(SDL_EventQ.lock) == 0) { if (action == SDL_ADDEVENT) { for (i = 0; i < numevents; ++i) { used += SDL_AddEvent(&events[i]); @@ -242,10 +242,9 @@ SDL_PeepEvents(SDL_Event * events, int numevents, SDL_eventaction action, } } } - SDL_mutexV(SDL_EventQ.lock); + SDL_UnlockMutex(SDL_EventQ.lock); } else { - SDL_SetError("Couldn't lock event queue"); - used = -1; + return SDL_SetError("Couldn't lock event queue"); } return (used); } @@ -285,7 +284,7 @@ SDL_FlushEvents(Uint32 minType, Uint32 maxType) #endif /* Lock the event queue */ - if (SDL_mutexP(SDL_EventQ.lock) == 0) { + if (SDL_LockMutex(SDL_EventQ.lock) == 0) { int spot = SDL_EventQ.head; while (spot != SDL_EventQ.tail) { Uint32 type = SDL_EventQ.event[spot].type; @@ -295,7 +294,7 @@ SDL_FlushEvents(Uint32 minType, Uint32 maxType) spot = (spot + 1) % MAXEVENTS; } } - SDL_mutexV(SDL_EventQ.lock); + SDL_UnlockMutex(SDL_EventQ.lock); } } @@ -365,7 +364,7 @@ int SDL_PushEvent(SDL_Event * event) { SDL_EventWatcher *curr; - event->window.timestamp = SDL_GetTicks(); + event->generic.timestamp = SDL_GetTicks(); if (SDL_EventOK && !SDL_EventOK(SDL_EventOKParam, event)) { return 0; } @@ -446,7 +445,7 @@ SDL_DelEventWatch(SDL_EventFilter filter, void *userdata) void SDL_FilterEvents(SDL_EventFilter filter, void *userdata) { - if (SDL_mutexP(SDL_EventQ.lock) == 0) { + if (SDL_LockMutex(SDL_EventQ.lock) == 0) { int spot; spot = SDL_EventQ.head; @@ -458,7 +457,7 @@ SDL_FilterEvents(SDL_EventFilter filter, void *userdata) } } } - SDL_mutexV(SDL_EventQ.lock); + SDL_UnlockMutex(SDL_EventQ.lock); } Uint8 diff --git a/src/events/SDL_gesture.c b/src/events/SDL_gesture.c index 7d2ab7c45e..a56aa3e554 100644 --- a/src/events/SDL_gesture.c +++ b/src/events/SDL_gesture.c @@ -27,7 +27,10 @@ #include "SDL_events_c.h" #include "SDL_gesture_c.h" +#if !defined(__PSP__) #include <memory.h> +#endif + #include <string.h> #include <stdio.h> #include <math.h> @@ -64,7 +67,6 @@ typedef struct { typedef struct { SDL_TouchID id; - SDL_FloatPoint res; SDL_FloatPoint centroid; SDL_DollarPath dollarPath; Uint16 numDownFingers; @@ -156,8 +158,7 @@ int SDL_SaveDollarTemplate(SDL_GestureID gestureId, SDL_RWops *src) } } } - SDL_SetError("Unknown gestureId"); - return -1; + return SDL_SetError("Unknown gestureId"); } //path is an already sampled set of points @@ -174,8 +175,7 @@ static int SDL_AddDollarGesture_one(SDL_GestureTouch* inTouch, SDL_FloatPoint* p (index + 1) * sizeof(SDL_DollarTemplate)); if (!dollarTemplate) { - SDL_OutOfMemory(); - return -1; + return SDL_OutOfMemory(); } inTouch->dollarTemplate = dollarTemplate; @@ -410,25 +410,20 @@ static float dollarRecognize(const SDL_DollarPath *path,int *bestTempl,SDL_Gestu return bestDiff; } -int SDL_GestureAddTouch(SDL_Touch* touch) +int SDL_GestureAddTouch(SDL_TouchID touchId) { SDL_GestureTouch *gestureTouch = (SDL_GestureTouch *)SDL_realloc(SDL_gestureTouch, (SDL_numGestureTouches + 1) * sizeof(SDL_GestureTouch)); if (!gestureTouch) { - SDL_OutOfMemory(); - return -1; + return SDL_OutOfMemory(); } SDL_gestureTouch = gestureTouch; - SDL_gestureTouch[SDL_numGestureTouches].res.x = touch->xres; - SDL_gestureTouch[SDL_numGestureTouches].res.y = touch->yres; SDL_gestureTouch[SDL_numGestureTouches].numDownFingers = 0; - - SDL_gestureTouch[SDL_numGestureTouches].res.x = touch->xres; - SDL_gestureTouch[SDL_numGestureTouches].id = touch->id; + SDL_gestureTouch[SDL_numGestureTouches].id = touchId; SDL_gestureTouch[SDL_numGestureTouches].numDollarTemplates = 0; @@ -468,11 +463,8 @@ static int SDL_SendGestureDollar(SDL_GestureTouch* touch, SDL_Event event; event.dgesture.type = SDL_DOLLARGESTURE; event.dgesture.touchId = touch->id; - /* - //TODO: Add this to give location of gesture? event.mgesture.x = touch->centroid.x; event.mgesture.y = touch->centroid.y; - */ event.dgesture.gestureId = gestureId; event.dgesture.error = error; //A finger came up to trigger this event. @@ -513,14 +505,8 @@ void SDL_GestureProcessEvent(SDL_Event* event) //Shouldn't be possible if (inTouch == NULL) return; - //printf("@ (%i,%i) with res: (%i,%i)\n",(int)event->tfinger.x, - // (int)event->tfinger.y, - // (int)inTouch->res.x,(int)inTouch->res.y); - - - x = ((float)event->tfinger.x)/(float)inTouch->res.x; - y = ((float)event->tfinger.y)/(float)inTouch->res.y; - + x = event->tfinger.x; + y = event->tfinger.y; //Finger Up if (event->type == SDL_FINGERUP) { @@ -569,9 +555,8 @@ void SDL_GestureProcessEvent(SDL_Event* event) } } else if (event->type == SDL_FINGERMOTION) { - float dx = ((float)event->tfinger.dx)/(float)inTouch->res.x; - float dy = ((float)event->tfinger.dy)/(float)inTouch->res.y; - //printf("dx,dy: (%f,%f)\n",dx,dy); + float dx = event->tfinger.dx; + float dy = event->tfinger.dy; #ifdef ENABLE_DOLLAR SDL_DollarPath* path = &inTouch->dollarPath; if (path->numPoints < MAXPATHSIZE) { diff --git a/src/events/SDL_gesture_c.h b/src/events/SDL_gesture_c.h index eb994890f5..08ba2e80c5 100644 --- a/src/events/SDL_gesture_c.h +++ b/src/events/SDL_gesture_c.h @@ -23,12 +23,12 @@ #ifndef _SDL_gesture_c_h #define _SDL_gesture_c_h +extern int SDL_GestureAddTouch(SDL_TouchID touchId); + extern void SDL_GestureProcessEvent(SDL_Event* event); extern int SDL_RecordGesture(SDL_TouchID touchId); -extern int SDL_GestureAddTouch(SDL_Touch* touch); - #endif /* _SDL_gesture_c_h */ /* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/events/SDL_keyboard.c b/src/events/SDL_keyboard.c index c79eaf4628..3454bf8bb8 100644 --- a/src/events/SDL_keyboard.c +++ b/src/events/SDL_keyboard.c @@ -861,7 +861,7 @@ SDL_GetKeyFromScancode(SDL_Scancode scancode) { SDL_Keyboard *keyboard = &SDL_keyboard; - if (scancode<SDL_SCANCODE_UNKNOWN || scancode >= SDL_NUM_SCANCODES) { + if (scancode < SDL_SCANCODE_UNKNOWN || scancode >= SDL_NUM_SCANCODES) { SDL_InvalidParamError("scancode"); return 0; } @@ -887,8 +887,13 @@ SDL_GetScancodeFromKey(SDL_Keycode key) const char * SDL_GetScancodeName(SDL_Scancode scancode) { - const char *name = SDL_scancode_names[scancode]; + const char *name; + if (scancode < SDL_SCANCODE_UNKNOWN || scancode >= SDL_NUM_SCANCODES) { + SDL_InvalidParamError("scancode"); + return ""; + } + name = SDL_scancode_names[scancode]; if (name) return name; else diff --git a/src/events/SDL_mouse.c b/src/events/SDL_mouse.c index 35274c8b9f..d467d07916 100644 --- a/src/events/SDL_mouse.c +++ b/src/events/SDL_mouse.c @@ -81,7 +81,7 @@ SDL_ResetMouse(void) #endif for (i = 1; i <= sizeof(mouse->buttonstate)*8; ++i) { if (mouse->buttonstate & SDL_BUTTON(i)) { - SDL_SendMouseButton(mouse->focus, SDL_RELEASED, i); + SDL_SendMouseButton(mouse->focus, mouse->mouseID, SDL_RELEASED, i); } } SDL_assert(mouse->buttonstate == 0); @@ -174,7 +174,7 @@ SDL_UpdateMouseFocus(SDL_Window * window, int x, int y, Uint32 buttonstate) } int -SDL_SendMouseMotion(SDL_Window * window, int relative, int x, int y) +SDL_SendMouseMotion(SDL_Window * window, SDL_MouseID mouseID, int relative, int x, int y) { SDL_Mouse *mouse = SDL_GetMouse(); int posted; @@ -252,6 +252,7 @@ SDL_SendMouseMotion(SDL_Window * window, int relative, int x, int y) SDL_Event event; event.motion.type = SDL_MOUSEMOTION; event.motion.windowID = mouse->focus ? mouse->focus->id : 0; + event.motion.which = mouseID; event.motion.state = mouse->buttonstate; event.motion.x = mouse->x; event.motion.y = mouse->y; @@ -266,7 +267,7 @@ SDL_SendMouseMotion(SDL_Window * window, int relative, int x, int y) } int -SDL_SendMouseButton(SDL_Window * window, Uint8 state, Uint8 button) +SDL_SendMouseButton(SDL_Window * window, SDL_MouseID mouseID, Uint8 state, Uint8 button) { SDL_Mouse *mouse = SDL_GetMouse(); int posted; @@ -304,11 +305,12 @@ SDL_SendMouseButton(SDL_Window * window, Uint8 state, Uint8 button) if (SDL_GetEventState(type) == SDL_ENABLE) { SDL_Event event; event.type = type; + event.button.windowID = mouse->focus ? mouse->focus->id : 0; + event.button.which = mouseID; event.button.state = state; event.button.button = button; event.button.x = mouse->x; event.button.y = mouse->y; - event.button.windowID = mouse->focus ? mouse->focus->id : 0; posted = (SDL_PushEvent(&event) > 0); } @@ -321,7 +323,7 @@ SDL_SendMouseButton(SDL_Window * window, Uint8 state, Uint8 button) } int -SDL_SendMouseWheel(SDL_Window * window, int x, int y) +SDL_SendMouseWheel(SDL_Window * window, SDL_MouseID mouseID, int x, int y) { SDL_Mouse *mouse = SDL_GetMouse(); int posted; @@ -340,6 +342,7 @@ SDL_SendMouseWheel(SDL_Window * window, int x, int y) SDL_Event event; event.type = SDL_MOUSEWHEEL; event.wheel.windowID = mouse->focus ? mouse->focus->id : 0; + event.wheel.which = mouseID; event.wheel.x = x; event.wheel.y = y; posted = (SDL_PushEvent(&event) > 0); @@ -396,7 +399,7 @@ SDL_WarpMouseInWindow(SDL_Window * window, int x, int y) if (mouse->WarpMouse) { mouse->WarpMouse(window, x, y); } else { - SDL_SendMouseMotion(window, 0, x, y); + SDL_SendMouseMotion(window, mouse->mouseID, 0, x, y); } } @@ -410,8 +413,7 @@ SDL_SetRelativeMouseMode(SDL_bool enabled) } if (!mouse->SetRelativeMouseMode) { - SDL_Unsupported(); - return -1; + return SDL_Unsupported(); } if (mouse->SetRelativeMouseMode(enabled) < 0) { diff --git a/src/events/SDL_mouse_c.h b/src/events/SDL_mouse_c.h index 2fc27eac79..7cb13cb3d5 100644 --- a/src/events/SDL_mouse_c.h +++ b/src/events/SDL_mouse_c.h @@ -25,6 +25,8 @@ #include "SDL_mouse.h" +typedef Uint32 SDL_MouseID; + struct SDL_Cursor { struct SDL_Cursor *next; @@ -55,6 +57,7 @@ typedef struct int (*SetRelativeMouseMode) (SDL_bool enabled); /* Data common to all mice */ + SDL_MouseID mouseID; SDL_Window *focus; int x; int y; @@ -86,13 +89,13 @@ extern void SDL_SetDefaultCursor(SDL_Cursor * cursor); extern void SDL_SetMouseFocus(SDL_Window * window); /* Send a mouse motion event */ -extern int SDL_SendMouseMotion(SDL_Window * window, int relative, int x, int y); +extern int SDL_SendMouseMotion(SDL_Window * window, SDL_MouseID mouseID, int relative, int x, int y); /* Send a mouse button event */ -extern int SDL_SendMouseButton(SDL_Window * window, Uint8 state, Uint8 button); +extern int SDL_SendMouseButton(SDL_Window * window, SDL_MouseID mouseID, Uint8 state, Uint8 button); /* Send a mouse wheel event */ -extern int SDL_SendMouseWheel(SDL_Window * window, int x, int y); +extern int SDL_SendMouseWheel(SDL_Window * window, SDL_MouseID mouseID, int x, int y); /* Shutdown the mouse subsystem */ extern void SDL_MouseQuit(void); diff --git a/src/events/SDL_touch.c b/src/events/SDL_touch.c index 6ba5f0bc91..c2bb22ecee 100644 --- a/src/events/SDL_touch.c +++ b/src/events/SDL_touch.c @@ -22,72 +22,46 @@ /* General touch handling code for SDL */ +#include "SDL_assert.h" #include "SDL_events.h" #include "SDL_events_c.h" -#include "../video/SDL_sysvideo.h" - -#include <stdio.h> static int SDL_num_touch = 0; -static SDL_Touch **SDL_touchPads = NULL; +static SDL_Touch **SDL_touchDevices = NULL; /* Public functions */ int SDL_TouchInit(void) { - return (0); + return (0); } -SDL_Touch * -SDL_GetTouch(SDL_TouchID id) +int +SDL_GetNumTouchDevices() { - int index = SDL_GetTouchIndexId(id); - if (index < 0 || index >= SDL_num_touch) { - return NULL; - } - return SDL_touchPads[index]; + return SDL_num_touch; } -SDL_Touch * -SDL_GetTouchIndex(int index) +SDL_TouchID +SDL_GetTouchDevice(int index) { if (index < 0 || index >= SDL_num_touch) { - return NULL; + SDL_SetError("Unknown touch device"); + return 0; } - return SDL_touchPads[index]; + return SDL_touchDevices[index]->id; } static int -SDL_GetFingerIndexId(SDL_Touch* touch,SDL_FingerID fingerid) -{ - int i; - for(i = 0;i < touch->num_fingers;i++) - if(touch->fingers[i]->id == fingerid) - return i; - return -1; -} - - -SDL_Finger * -SDL_GetFinger(SDL_Touch* touch,SDL_FingerID id) -{ - int index = SDL_GetFingerIndexId(touch,id); - if(index < 0 || index >= touch->num_fingers) - return NULL; - return touch->fingers[index]; -} - - -int -SDL_GetTouchIndexId(SDL_TouchID id) +SDL_GetTouchIndex(SDL_TouchID id) { int index; SDL_Touch *touch; for (index = 0; index < SDL_num_touch; ++index) { - touch = SDL_touchPads[index]; + touch = SDL_touchDevices[index]; if (touch->id == id) { return index; } @@ -95,479 +69,296 @@ SDL_GetTouchIndexId(SDL_TouchID id) return -1; } -int -SDL_AddTouch(const SDL_Touch * touch, char *name) +SDL_Touch * +SDL_GetTouch(SDL_TouchID id) { - SDL_Touch **touchPads; - int index; - size_t length; - - if (SDL_GetTouchIndexId(touch->id) != -1) { - SDL_SetError("Touch ID already in use"); - } - - /* Add the touch to the list of touch */ - touchPads = (SDL_Touch **) SDL_realloc(SDL_touchPads, - (SDL_num_touch + 1) * sizeof(*touch)); - if (!touchPads) { - SDL_OutOfMemory(); - return -1; - } - - SDL_touchPads = touchPads; - index = SDL_num_touch++; - - SDL_touchPads[index] = (SDL_Touch *) SDL_malloc(sizeof(*SDL_touchPads[index])); - if (!SDL_touchPads[index]) { - SDL_OutOfMemory(); - return -1; + int index = SDL_GetTouchIndex(id); + if (index < 0 || index >= SDL_num_touch) { + SDL_SetError("Unknown touch device"); + return NULL; } - SDL_memcpy(SDL_touchPads[index], touch, sizeof(*touch)); - - /* we're setting the touch properties */ - length = SDL_strlen(name); - SDL_touchPads[index]->focus = 0; - SDL_touchPads[index]->name = SDL_malloc((length + 2) * sizeof(char)); - SDL_strlcpy(SDL_touchPads[index]->name, name, length + 1); - - SDL_touchPads[index]->num_fingers = 0; - SDL_touchPads[index]->max_fingers = 1; - SDL_touchPads[index]->fingers = (SDL_Finger **) SDL_malloc(sizeof(SDL_Finger*)); - SDL_touchPads[index]->fingers[0] = NULL; - SDL_touchPads[index]->buttonstate = 0; - SDL_touchPads[index]->relative_mode = SDL_FALSE; - SDL_touchPads[index]->flush_motion = SDL_FALSE; - - SDL_touchPads[index]->xres = (1<<(16-1)); - SDL_touchPads[index]->yres = (1<<(16-1)); - SDL_touchPads[index]->pressureres = (1<<(16-1)); - //Do I want this here? Probably - SDL_GestureAddTouch(SDL_touchPads[index]); - - return index; + return SDL_touchDevices[index]; } -void -SDL_DelTouch(SDL_TouchID id) +static int +SDL_GetFingerIndex(const SDL_Touch * touch, SDL_FingerID fingerid) { - int index = SDL_GetTouchIndexId(id); - SDL_Touch *touch = SDL_GetTouch(id); - - if (!touch) { - return; - } - - - SDL_free(touch->name); - - if (touch->FreeTouch) { - touch->FreeTouch(touch); + int index; + for (index = 0; index < touch->num_fingers; ++index) { + if (touch->fingers[index]->id == fingerid) { + return index; + } } - SDL_free(touch); - - SDL_num_touch--; - SDL_touchPads[index] = SDL_touchPads[SDL_num_touch]; + return -1; } -void -SDL_TouchQuit(void) +SDL_Finger * +SDL_GetFinger(const SDL_Touch * touch, SDL_FingerID id) { - int i; - - for (i = SDL_num_touch-1; i > 0 ; --i) { - SDL_DelTouch(i); - } - SDL_num_touch = 0; - - if (SDL_touchPads) { - SDL_free(SDL_touchPads); - SDL_touchPads = NULL; + int index = SDL_GetFingerIndex(touch, id); + if (index < 0 || index >= touch->num_fingers) { + return NULL; } + return touch->fingers[index]; } int -SDL_GetNumTouch(void) +SDL_GetNumTouchFingers(SDL_TouchID touchID) { - return SDL_num_touch; + SDL_Touch *touch = SDL_GetTouch(touchID); + if (touch) { + return touch->num_fingers; + } + return 0; } -SDL_Window * -SDL_GetTouchFocusWindow(SDL_TouchID id) +SDL_Finger * +SDL_GetTouchFinger(SDL_TouchID touchID, int index) { - SDL_Touch *touch = SDL_GetTouch(id); - + SDL_Touch *touch = SDL_GetTouch(touchID); if (!touch) { - return 0; + return NULL; } - return touch->focus; + if (index < 0 || index >= touch->num_fingers) { + SDL_SetError("Unknown touch finger"); + return NULL; + } + return touch->fingers[index]; } -void -SDL_SetTouchFocus(SDL_TouchID id, SDL_Window * window) +int +SDL_AddTouch(SDL_TouchID touchID, const char *name) { - int index = SDL_GetTouchIndexId(id); - SDL_Touch *touch = SDL_GetTouch(id); - int i; - SDL_bool focus; + SDL_Touch **touchDevices; + int index; - if (!touch || (touch->focus == window)) { - return; + index = SDL_GetTouchIndex(touchID); + if (index >= 0) { + return index; } - /* See if the current window has lost focus */ - if (touch->focus) { - focus = SDL_FALSE; - for (i = 0; i < SDL_num_touch; ++i) { - SDL_Touch *check; - if (i != index) { - check = SDL_touchPads[i]; - if (check && check->focus == touch->focus) { - focus = SDL_TRUE; - break; - } - } - } - if (!focus) { - SDL_SendWindowEvent(touch->focus, SDL_WINDOWEVENT_LEAVE, 0, 0); - } + /* Add the touch to the list of touch */ + touchDevices = (SDL_Touch **) SDL_realloc(SDL_touchDevices, + (SDL_num_touch + 1) * sizeof(*touchDevices)); + if (!touchDevices) { + return SDL_OutOfMemory(); } - touch->focus = window; - - if (touch->focus) { - focus = SDL_FALSE; - for (i = 0; i < SDL_num_touch; ++i) { - SDL_Touch *check; - if (i != index) { - check = SDL_touchPads[i]; - if (check && check->focus == touch->focus) { - focus = SDL_TRUE; - break; - } - } - } - if (!focus) { - SDL_SendWindowEvent(touch->focus, SDL_WINDOWEVENT_ENTER, 0, 0); - } + SDL_touchDevices = touchDevices; + index = SDL_num_touch++; + + SDL_touchDevices[index] = (SDL_Touch *) SDL_malloc(sizeof(*SDL_touchDevices[index])); + if (!SDL_touchDevices[index]) { + return SDL_OutOfMemory(); } + + /* we're setting the touch properties */ + SDL_touchDevices[index]->id = touchID; + SDL_touchDevices[index]->num_fingers = 0; + SDL_touchDevices[index]->max_fingers = 0; + SDL_touchDevices[index]->fingers = NULL; + + /* Record this touch device for gestures */ + /* We could do this on the fly in the gesture code if we wanted */ + SDL_GestureAddTouch(touchID); + + return index; } -int -SDL_AddFinger(SDL_Touch* touch,SDL_Finger *finger) +static int +SDL_AddFinger(SDL_Touch *touch, SDL_FingerID fingerid, float x, float y, float pressure) { - int index; - SDL_Finger **fingers; - //printf("Adding Finger...\n"); - if (SDL_GetFingerIndexId(touch,finger->id) != -1) { - SDL_SetError("Finger ID already in use"); - } + SDL_Finger *finger; - /* Add the touch to the list of touch */ - if(touch->num_fingers >= touch->max_fingers){ - //printf("Making room for it!\n"); - fingers = (SDL_Finger **) SDL_realloc(touch->fingers, - (touch->num_fingers + 1) * sizeof(SDL_Finger *)); - if (!fingers) { - SDL_OutOfMemory(); - return -1; - } else { - touch->max_fingers = touch->num_fingers+1; - touch->fingers = fingers; - } + if (touch->num_fingers == touch->max_fingers) { + SDL_Finger **new_fingers; + new_fingers = (SDL_Finger **)SDL_realloc(touch->fingers, (touch->max_fingers+1)*sizeof(*touch->fingers)); + if (!new_fingers) { + return SDL_OutOfMemory(); } - - index = touch->num_fingers; - //printf("Max_Fingers: %i Index: %i\n",touch->max_fingers,index); - - touch->fingers[index] = (SDL_Finger *) SDL_malloc(sizeof(SDL_Finger)); - if (!touch->fingers[index]) { - SDL_OutOfMemory(); - return -1; + touch->fingers = new_fingers; + touch->fingers[touch->max_fingers] = (SDL_Finger *)SDL_malloc(sizeof(*finger)); + if (!touch->fingers[touch->max_fingers]) { + return SDL_OutOfMemory(); + } + touch->max_fingers++; } - *(touch->fingers[index]) = *finger; - touch->num_fingers++; - return index; + finger = touch->fingers[touch->num_fingers++]; + finger->id = fingerid; + finger->x = x; + finger->y = y; + finger->pressure = pressure; + return 0; } -int -SDL_DelFinger(SDL_Touch* touch,SDL_FingerID fingerid) +static int +SDL_DelFinger(SDL_Touch* touch, SDL_FingerID fingerid) { - int index = SDL_GetFingerIndexId(touch,fingerid); - SDL_Finger* finger = SDL_GetFinger(touch,fingerid); + SDL_Finger *temp; - if (!finger) { + int index = SDL_GetFingerIndex(touch, fingerid); + if (index < 0) { return -1; } - - SDL_free(finger); touch->num_fingers--; + temp = touch->fingers[index]; touch->fingers[index] = touch->fingers[touch->num_fingers]; + touch->fingers[touch->num_fingers] = temp; return 0; } - int -SDL_SendFingerDown(SDL_TouchID id, SDL_FingerID fingerid, SDL_bool down, - float xin, float yin, float pressurein) +SDL_SendTouch(SDL_TouchID id, SDL_FingerID fingerid, + SDL_bool down, float x, float y, float pressure) { int posted; - Uint16 x; - Uint16 y; - Uint16 pressure; - SDL_Finger *finger; + SDL_Finger *finger; SDL_Touch* touch = SDL_GetTouch(id); - - if(!touch) { - return SDL_TouchNotFoundError(id); + if (!touch) { + return -1; } - - //scale to Integer coordinates - x = (Uint16)((xin+touch->x_min)*(touch->xres)/(touch->native_xres)); - y = (Uint16)((yin+touch->y_min)*(touch->yres)/(touch->native_yres)); - pressure = (Uint16)((pressurein+touch->pressure_min)*(touch->pressureres)/(touch->native_pressureres)); - - finger = SDL_GetFinger(touch,fingerid); - if(down) { - if(finger == NULL) { - SDL_Finger nf; - nf.id = fingerid; - nf.x = x; - nf.y = y; - nf.pressure = pressure; - nf.xdelta = 0; - nf.ydelta = 0; - nf.last_x = x; - nf.last_y = y; - nf.last_pressure = pressure; - nf.down = SDL_FALSE; - if(SDL_AddFinger(touch,&nf) < 0) return 0; - finger = SDL_GetFinger(touch,fingerid); + finger = SDL_GetFinger(touch, fingerid); + if (down) { + if (finger) { + /* This finger is already down */ + return 0; } - else if(finger->down) return 0; - if(xin < touch->x_min || yin < touch->y_min) return 0; //should defer if only a partial input + + if (SDL_AddFinger(touch, fingerid, x, y, pressure) < 0) { + return 0; + } + posted = 0; if (SDL_GetEventState(SDL_FINGERDOWN) == SDL_ENABLE) { SDL_Event event; event.tfinger.type = SDL_FINGERDOWN; event.tfinger.touchId = id; + event.tfinger.fingerId = fingerid; event.tfinger.x = x; event.tfinger.y = y; event.tfinger.dx = 0; event.tfinger.dy = 0; event.tfinger.pressure = pressure; - event.tfinger.state = touch->buttonstate; - event.tfinger.windowID = touch->focus ? touch->focus->id : 0; - event.tfinger.fingerId = fingerid; posted = (SDL_PushEvent(&event) > 0); } - if(posted) finger->down = SDL_TRUE; - return posted; - } - else { - if(finger == NULL) { - SDL_SetError("Finger not found."); + } else { + if (!finger) { + /* This finger is already up */ return 0; - } + } + posted = 0; if (SDL_GetEventState(SDL_FINGERUP) == SDL_ENABLE) { SDL_Event event; event.tfinger.type = SDL_FINGERUP; event.tfinger.touchId = id; - event.tfinger.state = touch->buttonstate; - event.tfinger.windowID = touch->focus ? touch->focus->id : 0; event.tfinger.fingerId = fingerid; - //I don't trust the coordinates passed on fingerUp + /* I don't trust the coordinates passed on fingerUp */ event.tfinger.x = finger->x; event.tfinger.y = finger->y; event.tfinger.dx = 0; event.tfinger.dy = 0; event.tfinger.pressure = pressure; - - if(SDL_DelFinger(touch,fingerid) < 0) return 0; posted = (SDL_PushEvent(&event) > 0); - } - return posted; + } + + SDL_DelFinger(touch, fingerid); } + return posted; } int -SDL_SendTouchMotion(SDL_TouchID id, SDL_FingerID fingerid, int relative, - float xin, float yin, float pressurein) +SDL_SendTouchMotion(SDL_TouchID id, SDL_FingerID fingerid, + float x, float y, float pressure) { SDL_Touch *touch; SDL_Finger *finger; int posted; - Sint16 xrel, yrel; - Uint16 x; - Uint16 y; - Uint16 pressure; - + float xrel, yrel, prel; + touch = SDL_GetTouch(id); if (!touch) { - return SDL_TouchNotFoundError(id); + return -1; } - //scale to Integer coordinates - x = (Uint16)((xin+touch->x_min)*(touch->xres)/(touch->native_xres)); - y = (Uint16)((yin+touch->y_min)*(touch->yres)/(touch->native_yres)); - pressure = (Uint16)((pressurein+touch->pressure_min)*(touch->pressureres)/(touch->native_pressureres)); - if(touch->flush_motion) { - return 0; - } - finger = SDL_GetFinger(touch,fingerid); - if(finger == NULL || !finger->down) { - return SDL_SendFingerDown(id,fingerid,SDL_TRUE,xin,yin,pressurein); - } else { - /* the relative motion is calculated regarding the last position */ - if (relative) { - xrel = x; - yrel = y; - x = (finger->last_x + x); - y = (finger->last_y + y); - } else { - if(xin < touch->x_min) x = finger->last_x; /*If movement is only in one axis,*/ - if(yin < touch->y_min) y = finger->last_y; /*The other is marked as -1*/ - if(pressurein < touch->pressure_min) pressure = finger->last_pressure; - xrel = x - finger->last_x; - yrel = y - finger->last_y; - //printf("xrel,yrel (%i,%i)\n",(int)xrel,(int)yrel); - } - - /* Drop events that don't change state */ - if (!xrel && !yrel) { -#if 0 - printf("Touch event didn't change state - dropped!\n"); -#endif - return 0; - } - - /* Update internal touch coordinates */ - - finger->x = x; - finger->y = y; - - /*Should scale to window? Normalize? Maintain Aspect?*/ - //SDL_GetWindowSize(touch->focus, &x_max, &y_max); - - /* make sure that the pointers find themselves inside the windows */ - /* only check if touch->xmax is set ! */ - /* - if (x_max && touch->x > x_max) { - touch->x = x_max; - } else if (touch->x < 0) { - touch->x = 0; - } - - if (y_max && touch->y > y_max) { - touch->y = y_max; - } else if (touch->y < 0) { - touch->y = 0; - } - */ - finger->xdelta = xrel; - finger->ydelta = yrel; - finger->pressure = pressure; - - - - /* Post the event, if desired */ - posted = 0; - if (SDL_GetEventState(SDL_FINGERMOTION) == SDL_ENABLE) { - SDL_Event event; - event.tfinger.type = SDL_FINGERMOTION; - event.tfinger.touchId = id; - event.tfinger.fingerId = fingerid; - event.tfinger.x = x; - event.tfinger.y = y; - event.tfinger.dx = xrel; - event.tfinger.dy = yrel; - - event.tfinger.pressure = pressure; - event.tfinger.state = touch->buttonstate; - event.tfinger.windowID = touch->focus ? touch->focus->id : 0; - posted = (SDL_PushEvent(&event) > 0); - } - finger->last_x = finger->x; - finger->last_y = finger->y; - finger->last_pressure = finger->pressure; - return posted; + if (!finger) { + return SDL_SendTouch(id, fingerid, SDL_TRUE, x, y, pressure); } -} -int -SDL_SendTouchButton(SDL_TouchID id, Uint8 state, Uint8 button) -{ - SDL_Touch *touch; - int posted; - Uint32 type; - - - touch = SDL_GetTouch(id); - if (!touch) { - return SDL_TouchNotFoundError(id); - } + xrel = x - finger->x; + yrel = y - finger->y; + prel = pressure - finger->pressure; - /* Figure out which event to perform */ - switch (state) { - case SDL_PRESSED: - if (touch->buttonstate & SDL_BUTTON(button)) { - /* Ignore this event, no state change */ - return 0; - } - type = SDL_TOUCHBUTTONDOWN; - touch->buttonstate |= SDL_BUTTON(button); - break; - case SDL_RELEASED: - if (!(touch->buttonstate & SDL_BUTTON(button))) { - /* Ignore this event, no state change */ - return 0; - } - type = SDL_TOUCHBUTTONUP; - touch->buttonstate &= ~SDL_BUTTON(button); - break; - default: - /* Invalid state -- bail */ + /* Drop events that don't change state */ + if (!xrel && !yrel && !prel) { +#if 0 + printf("Touch event didn't change state - dropped!\n"); +#endif return 0; } + /* Update internal touch coordinates */ + finger->x = x; + finger->y = y; + finger->pressure = pressure; + /* Post the event, if desired */ posted = 0; - if (SDL_GetEventState(type) == SDL_ENABLE) { + if (SDL_GetEventState(SDL_FINGERMOTION) == SDL_ENABLE) { SDL_Event event; - event.type = type; - event.tbutton.touchId = touch->id; - event.tbutton.state = state; - event.tbutton.button = button; - event.tbutton.windowID = touch->focus ? touch->focus->id : 0; + event.tfinger.type = SDL_FINGERMOTION; + event.tfinger.touchId = id; + event.tfinger.fingerId = fingerid; + event.tfinger.x = x; + event.tfinger.y = y; + event.tfinger.dx = xrel; + event.tfinger.dy = yrel; + event.tfinger.pressure = pressure; posted = (SDL_PushEvent(&event) > 0); } return posted; } -char * -SDL_GetTouchName(SDL_TouchID id) +void +SDL_DelTouch(SDL_TouchID id) { + int i; + int index = SDL_GetTouchIndex(id); SDL_Touch *touch = SDL_GetTouch(id); + if (!touch) { - return NULL; + return; + } + + for (i = 0; i < touch->max_fingers; ++i) { + SDL_free(touch->fingers[i]); } - return touch->name; + SDL_free(touch->fingers); + SDL_free(touch); + + SDL_num_touch--; + SDL_touchDevices[index] = SDL_touchDevices[SDL_num_touch]; } -int SDL_TouchNotFoundError(SDL_TouchID id) { - //int i; - SDL_SetError("ERROR: Cannot send touch on non-existent device with id: %li make sure SDL_AddTouch has been called\n",id); -#if 0 - printf("ERROR: There are %i touches installed with Id's:\n",SDL_num_touch); - for(i=0;i < SDL_num_touch;i++) { - printf("ERROR: %li\n",SDL_touchPads[i]->id); - } -#endif - return 0; +void +SDL_TouchQuit(void) +{ + int i; + + for (i = SDL_num_touch; i--; ) { + SDL_DelTouch(SDL_touchDevices[i]->id); + } + SDL_assert(SDL_num_touch == 0); + + if (SDL_touchDevices) { + SDL_free(SDL_touchDevices); + SDL_touchDevices = NULL; + } } + /* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/events/SDL_touch_c.h b/src/events/SDL_touch_c.h index c4addf3643..8961d74e50 100644 --- a/src/events/SDL_touch_c.h +++ b/src/events/SDL_touch_c.h @@ -24,55 +24,38 @@ #ifndef _SDL_touch_c_h #define _SDL_touch_c_h +typedef struct SDL_Touch +{ + SDL_TouchID id; + int num_fingers; + int max_fingers; + SDL_Finger** fingers; +} SDL_Touch; /* Initialize the touch subsystem */ extern int SDL_TouchInit(void); -/*Get the touch at an index */ -extern SDL_Touch *SDL_GetTouchIndex(int index); - -/* Get the touch with id = id */ -extern SDL_Touch *SDL_GetTouch(SDL_TouchID id); - -/*Get the finger at an index */ -extern SDL_Finger *SDL_GetFingerIndex(SDL_Touch *touch, int index); - -/* Get the finger with id = id */ -extern SDL_Finger *SDL_GetFinger(SDL_Touch *touch,SDL_FingerID id); - - -/* Add a touch, possibly reattaching at a particular index (or -1), - returning the index of the touch, or -1 if there was an error. */ -extern int SDL_AddTouch(const SDL_Touch * touch, char *name); +/* Add a touch, returning the index of the touch, or -1 if there was an error. */ +extern int SDL_AddTouch(SDL_TouchID id, const char *name); +/* Get the touch with a given id */ +extern SDL_Touch *SDL_GetTouch(SDL_TouchID id); -/* Remove a touch at an index, clearing the slot for later */ -extern void SDL_DelTouch(SDL_TouchID id); - -/* Set the touch focus window */ -extern void SDL_SetTouchFocus(SDL_TouchID id, SDL_Window * window); +/* Send a touch down/up event for a touch */ +extern int SDL_SendTouch(SDL_TouchID id, SDL_FingerID fingerid, + SDL_bool down, float x, float y, float pressure); /* Send a touch motion event for a touch */ extern int SDL_SendTouchMotion(SDL_TouchID id, SDL_FingerID fingerid, - int relative, float x, float y, float z); - -/* Send a touch down/up event for a touch */ -extern int SDL_SendFingerDown(SDL_TouchID id, SDL_FingerID fingerid, - SDL_bool down, float x, float y, float pressure); + float x, float y, float pressure); -/* Send a touch button event for a touch */ -extern int SDL_SendTouchButton(SDL_TouchID id, Uint8 state, Uint8 button); +/* Remove a touch */ +extern void SDL_DelTouch(SDL_TouchID id); /* Shutdown the touch subsystem */ extern void SDL_TouchQuit(void); -/* Get the index of a touch device */ -extern int SDL_GetTouchIndexId(SDL_TouchID id); - -/* Print a debug message for a nonexistent touch */ -extern int SDL_TouchNotFoundError(SDL_TouchID id); - #endif /* _SDL_touch_c_h */ /* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/events/nds/SDL_ndsgesture.c b/src/events/nds/SDL_ndsgesture.c deleted file mode 100644 index 16597c73e2..0000000000 --- a/src/events/nds/SDL_ndsgesture.c +++ /dev/null @@ -1,41 +0,0 @@ -/* - Simple DirectMedia Layer - Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org> - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. -*/ - -#include "SDL_config.h" - -/* No supported under the NDS because of math operations. */ - -#include "SDL_events.h" -#include "../SDL_events_c.h" -#include "../SDL_gesture_c.h" - -int SDL_GestureAddTouch(SDL_Touch* touch) -{ - return 0; -} - -void SDL_GestureProcessEvent(SDL_Event* event) -{ - return; -} - -/* vi: set ts=4 sw=4 expandtab: */ - diff --git a/src/events/scancodes_windows.h b/src/events/scancodes_windows.h index 496227984f..7bf69b0ad7 100644 --- a/src/events/scancodes_windows.h +++ b/src/events/scancodes_windows.h @@ -20,267 +20,34 @@ */ #include "../../include/SDL_scancode.h" -/* Win32 virtual key code to SDL scancode mapping table - Sources: - - msdn.microsoft.com -*/ +/* Windows scancode to SDL scancode mapping table */ /* *INDENT-OFF* */ -static const SDL_Scancode windows_scancode_table[] = { - /* 0, 0x00 */ SDL_SCANCODE_UNKNOWN, - /* 1, 0x01 */ SDL_SCANCODE_UNKNOWN, - /* 2, 0x02 */ SDL_SCANCODE_UNKNOWN, - /* 3, 0x03 */ SDL_SCANCODE_UNKNOWN, - /* 4, 0x04 */ SDL_SCANCODE_UNKNOWN, - /* 5, 0x05 */ SDL_SCANCODE_UNKNOWN, - /* 6, 0x06 */ SDL_SCANCODE_UNKNOWN, - /* 7, 0x07 */ SDL_SCANCODE_UNKNOWN, - /* 8, 0x08 */ SDL_SCANCODE_BACKSPACE, - /* 9, 0x09 */ SDL_SCANCODE_TAB, - /* 10, 0x0a */ SDL_SCANCODE_KP_ENTER, /* Not a VKEY, SDL specific */ - /* 11, 0x0b */ SDL_SCANCODE_UNKNOWN, - /* 12, 0x0c */ SDL_SCANCODE_CLEAR, - /* 13, 0x0d */ SDL_SCANCODE_RETURN, - /* 14, 0x0e */ SDL_SCANCODE_UNKNOWN, - /* 15, 0x0f */ SDL_SCANCODE_UNKNOWN, - /* 16, 0x10 */ SDL_SCANCODE_UNKNOWN, - /* 17, 0x11 */ SDL_SCANCODE_UNKNOWN, - /* 18, 0x12 */ SDL_SCANCODE_APPLICATION, - /* 19, 0x13 */ SDL_SCANCODE_PAUSE, - /* 20, 0x14 */ SDL_SCANCODE_CAPSLOCK, - /* 21, 0x15 */ SDL_SCANCODE_UNKNOWN, - /* 22, 0x16 */ SDL_SCANCODE_UNKNOWN, - /* 23, 0x17 */ SDL_SCANCODE_UNKNOWN, - /* 24, 0x18 */ SDL_SCANCODE_UNKNOWN, - /* 25, 0x19 */ SDL_SCANCODE_UNKNOWN, - /* 26, 0x1a */ SDL_SCANCODE_UNKNOWN, - /* 27, 0x1b */ SDL_SCANCODE_ESCAPE, - /* 28, 0x1c */ SDL_SCANCODE_UNKNOWN, - /* 29, 0x1d */ SDL_SCANCODE_UNKNOWN, - /* 30, 0x1e */ SDL_SCANCODE_UNKNOWN, - /* 31, 0x1f */ SDL_SCANCODE_MODE, - /* 32, 0x20 */ SDL_SCANCODE_SPACE, - /* 33, 0x21 */ SDL_SCANCODE_PAGEUP, - /* 34, 0x22 */ SDL_SCANCODE_PAGEDOWN, - /* 35, 0x23 */ SDL_SCANCODE_END, - /* 36, 0x24 */ SDL_SCANCODE_HOME, - /* 37, 0x25 */ SDL_SCANCODE_LEFT, - /* 38, 0x26 */ SDL_SCANCODE_UP, - /* 39, 0x27 */ SDL_SCANCODE_RIGHT, - /* 40, 0x28 */ SDL_SCANCODE_DOWN, - /* 41, 0x29 */ SDL_SCANCODE_SELECT, - /* 42, 0x2a */ SDL_SCANCODE_UNKNOWN, /* VK_PRINT */ - /* 43, 0x2b */ SDL_SCANCODE_EXECUTE, - /* 44, 0x2c */ SDL_SCANCODE_PRINTSCREEN, - /* 45, 0x2d */ SDL_SCANCODE_INSERT, - /* 46, 0x2e */ SDL_SCANCODE_DELETE, - /* 47, 0x2f */ SDL_SCANCODE_HELP, - /* 48, 0x30 */ SDL_SCANCODE_0, - /* 49, 0x31 */ SDL_SCANCODE_1, - /* 50, 0x32 */ SDL_SCANCODE_2, - /* 51, 0x33 */ SDL_SCANCODE_3, - /* 52, 0x34 */ SDL_SCANCODE_4, - /* 53, 0x35 */ SDL_SCANCODE_5, - /* 54, 0x36 */ SDL_SCANCODE_6, - /* 55, 0x37 */ SDL_SCANCODE_7, - /* 56, 0x38 */ SDL_SCANCODE_8, - /* 57, 0x39 */ SDL_SCANCODE_9, - /* 58, 0x3a */ SDL_SCANCODE_UNKNOWN, - /* 59, 0x3b */ SDL_SCANCODE_UNKNOWN, - /* 60, 0x3c */ SDL_SCANCODE_UNKNOWN, - /* 61, 0x3d */ SDL_SCANCODE_UNKNOWN, - /* 62, 0x3e */ SDL_SCANCODE_UNKNOWN, - /* 63, 0x3f */ SDL_SCANCODE_UNKNOWN, - /* 64, 0x40 */ SDL_SCANCODE_UNKNOWN, - /* 65, 0x41 */ SDL_SCANCODE_A, - /* 66, 0x42 */ SDL_SCANCODE_B, - /* 67, 0x43 */ SDL_SCANCODE_C, - /* 68, 0x44 */ SDL_SCANCODE_D, - /* 69, 0x45 */ SDL_SCANCODE_E, - /* 70, 0x46 */ SDL_SCANCODE_F, - /* 71, 0x47 */ SDL_SCANCODE_G, - /* 72, 0x48 */ SDL_SCANCODE_H, - /* 73, 0x49 */ SDL_SCANCODE_I, - /* 74, 0x4a */ SDL_SCANCODE_J, - /* 75, 0x4b */ SDL_SCANCODE_K, - /* 76, 0x4c */ SDL_SCANCODE_L, - /* 77, 0x4d */ SDL_SCANCODE_M, - /* 78, 0x4e */ SDL_SCANCODE_N, - /* 79, 0x4f */ SDL_SCANCODE_O, - /* 80, 0x50 */ SDL_SCANCODE_P, - /* 81, 0x51 */ SDL_SCANCODE_Q, - /* 82, 0x52 */ SDL_SCANCODE_R, - /* 83, 0x53 */ SDL_SCANCODE_S, - /* 84, 0x54 */ SDL_SCANCODE_T, - /* 85, 0x55 */ SDL_SCANCODE_U, - /* 86, 0x56 */ SDL_SCANCODE_V, - /* 87, 0x57 */ SDL_SCANCODE_W, - /* 88, 0x58 */ SDL_SCANCODE_X, - /* 89, 0x59 */ SDL_SCANCODE_Y, - /* 90, 0x5a */ SDL_SCANCODE_Z, - /* 91, 0x5b */ SDL_SCANCODE_LGUI, - /* 92, 0x5c */ SDL_SCANCODE_RGUI, - /* 93, 0x5d */ SDL_SCANCODE_APPLICATION, - /* 94, 0x5e */ SDL_SCANCODE_UNKNOWN, - /* 95, 0x5f */ SDL_SCANCODE_UNKNOWN, - /* 96, 0x60 */ SDL_SCANCODE_KP_0, - /* 97, 0x61 */ SDL_SCANCODE_KP_1, - /* 98, 0x62 */ SDL_SCANCODE_KP_2, - /* 99, 0x63 */ SDL_SCANCODE_KP_3, - /* 100, 0x64 */ SDL_SCANCODE_KP_4, - /* 101, 0x65 */ SDL_SCANCODE_KP_5, - /* 102, 0x66 */ SDL_SCANCODE_KP_6, - /* 103, 0x67 */ SDL_SCANCODE_KP_7, - /* 104, 0x68 */ SDL_SCANCODE_KP_8, - /* 105, 0x69 */ SDL_SCANCODE_KP_9, - /* 106, 0x6a */ SDL_SCANCODE_KP_MULTIPLY, - /* 107, 0x6b */ SDL_SCANCODE_KP_PLUS, - /* 108, 0x6c */ SDL_SCANCODE_SEPARATOR, - /* 109, 0x6d */ SDL_SCANCODE_KP_MINUS, - /* 110, 0x6e */ SDL_SCANCODE_KP_DECIMAL, - /* 111, 0x6f */ SDL_SCANCODE_KP_DIVIDE, - /* 112, 0x70 */ SDL_SCANCODE_F1, - /* 113, 0x71 */ SDL_SCANCODE_F2, - /* 114, 0x72 */ SDL_SCANCODE_F3, - /* 115, 0x73 */ SDL_SCANCODE_F4, - /* 116, 0x74 */ SDL_SCANCODE_F5, - /* 117, 0x75 */ SDL_SCANCODE_F6, - /* 118, 0x76 */ SDL_SCANCODE_F7, - /* 119, 0x77 */ SDL_SCANCODE_F8, - /* 120, 0x78 */ SDL_SCANCODE_F9, - /* 121, 0x79 */ SDL_SCANCODE_F10, - /* 122, 0x7a */ SDL_SCANCODE_F11, - /* 123, 0x7b */ SDL_SCANCODE_F12, - /* 124, 0x7c */ SDL_SCANCODE_F13, - /* 125, 0x7d */ SDL_SCANCODE_F14, - /* 126, 0x7e */ SDL_SCANCODE_F15, - /* 127, 0x7f */ SDL_SCANCODE_F16, - /* 128, 0x80 */ SDL_SCANCODE_F17, /* or SDL_SCANCODE_AUDIONEXT */ - /* 129, 0x81 */ SDL_SCANCODE_F18, /* or SDL_SCANCODE_AUDIOPREV */ - /* 130, 0x82 */ SDL_SCANCODE_F19, /* or SDL_SCANCODE_AUDIOSTOP */ - /* 131, 0x83 */ SDL_SCANCODE_F20, /* or SDL_SCANCODE_AUDIOPLAY */ - /* 132, 0x84 */ SDL_SCANCODE_F21, /* or SDL_SCANCODE_MAIL */ - /* 133, 0x85 */ SDL_SCANCODE_F22, /* or SDL_SCANCODE_MEDIASELECT */ - /* 134, 0x86 */ SDL_SCANCODE_F23, /* or SDL_SCANCODE_WWW */ - /* 135, 0x87 */ SDL_SCANCODE_F24, /* or SDL_SCANCODE_CALCULATOR */ - /* 136, 0x88 */ SDL_SCANCODE_UNKNOWN, - /* 137, 0x89 */ SDL_SCANCODE_UNKNOWN, - /* 138, 0x8a */ SDL_SCANCODE_UNKNOWN, - /* 139, 0x8b */ SDL_SCANCODE_UNKNOWN, - /* 140, 0x8c */ SDL_SCANCODE_UNKNOWN, - /* 141, 0x8d */ SDL_SCANCODE_UNKNOWN, - /* 142, 0x8e */ SDL_SCANCODE_UNKNOWN, - /* 143, 0x8f */ SDL_SCANCODE_UNKNOWN, - /* 144, 0x90 */ SDL_SCANCODE_NUMLOCKCLEAR, - /* 145, 0x91 */ SDL_SCANCODE_SCROLLLOCK, - /* 146, 0x92 */ SDL_SCANCODE_KP_EQUALS, - /* 147, 0x93 */ SDL_SCANCODE_UNKNOWN, - /* 148, 0x94 */ SDL_SCANCODE_UNKNOWN, - /* 149, 0x95 */ SDL_SCANCODE_UNKNOWN, - /* 150, 0x96 */ SDL_SCANCODE_UNKNOWN, - /* 151, 0x97 */ SDL_SCANCODE_UNKNOWN, - /* 152, 0x98 */ SDL_SCANCODE_UNKNOWN, - /* 153, 0x99 */ SDL_SCANCODE_UNKNOWN, - /* 154, 0x9a */ SDL_SCANCODE_UNKNOWN, - /* 155, 0x9b */ SDL_SCANCODE_UNKNOWN, - /* 156, 0x9c */ SDL_SCANCODE_UNKNOWN, - /* 157, 0x9d */ SDL_SCANCODE_UNKNOWN, - /* 158, 0x9e */ SDL_SCANCODE_UNKNOWN, - /* 159, 0x9f */ SDL_SCANCODE_UNKNOWN, - /* 160, 0xa0 */ SDL_SCANCODE_LSHIFT, - /* 161, 0xa1 */ SDL_SCANCODE_RSHIFT, - /* 162, 0xa2 */ SDL_SCANCODE_LCTRL, - /* 163, 0xa3 */ SDL_SCANCODE_RCTRL, - /* 164, 0xa4 */ SDL_SCANCODE_LALT, - /* 165, 0xa5 */ SDL_SCANCODE_RALT, - /* 166, 0xa6 */ SDL_SCANCODE_AC_BACK, - /* 167, 0xa7 */ SDL_SCANCODE_AC_FORWARD, - /* 168, 0xa8 */ SDL_SCANCODE_AC_REFRESH, - /* 169, 0xa9 */ SDL_SCANCODE_AC_STOP, - /* 170, 0xaa */ SDL_SCANCODE_AC_SEARCH, - /* 171, 0xab */ SDL_SCANCODE_AC_BOOKMARKS, - /* 172, 0xac */ SDL_SCANCODE_AC_HOME, - /* 173, 0xad */ SDL_SCANCODE_AUDIOMUTE, - /* 174, 0xae */ SDL_SCANCODE_VOLUMEDOWN, - /* 175, 0xaf */ SDL_SCANCODE_VOLUMEUP, - /* 176, 0xb0 */ SDL_SCANCODE_AUDIONEXT, - /* 177, 0xb1 */ SDL_SCANCODE_AUDIOPREV, - /* 178, 0xb2 */ SDL_SCANCODE_AUDIOSTOP, - /* 179, 0xb3 */ SDL_SCANCODE_AUDIOPLAY, - /* 180, 0xb4 */ SDL_SCANCODE_MAIL, - /* 181, 0xb5 */ SDL_SCANCODE_MEDIASELECT, - /* 182, 0xb6 */ SDL_SCANCODE_UNKNOWN, /* VK_LAUNCH_APP1 */ - /* 183, 0xb7 */ SDL_SCANCODE_UNKNOWN, /* VK_LAUNCH_APP2 */ - /* 184, 0xb8 */ SDL_SCANCODE_UNKNOWN, - /* 185, 0xb9 */ SDL_SCANCODE_UNKNOWN, - /* 186, 0xba */ SDL_SCANCODE_SEMICOLON, - /* 187, 0xbb */ SDL_SCANCODE_EQUALS, - /* 188, 0xbc */ SDL_SCANCODE_COMMA, - /* 189, 0xbd */ SDL_SCANCODE_MINUS, - /* 190, 0xbe */ SDL_SCANCODE_PERIOD, - /* 191, 0xbf */ SDL_SCANCODE_SLASH, - /* 192, 0xc0 */ SDL_SCANCODE_GRAVE, - /* 193, 0xc1 */ SDL_SCANCODE_UNKNOWN, - /* 194, 0xc2 */ SDL_SCANCODE_UNKNOWN, - /* 195, 0xc3 */ SDL_SCANCODE_UNKNOWN, - /* 196, 0xc4 */ SDL_SCANCODE_UNKNOWN, - /* 197, 0xc5 */ SDL_SCANCODE_UNKNOWN, - /* 198, 0xc6 */ SDL_SCANCODE_UNKNOWN, - /* 199, 0xc7 */ SDL_SCANCODE_UNKNOWN, - /* 200, 0xc8 */ SDL_SCANCODE_UNKNOWN, - /* 201, 0xc9 */ SDL_SCANCODE_UNKNOWN, - /* 202, 0xca */ SDL_SCANCODE_UNKNOWN, - /* 203, 0xcb */ SDL_SCANCODE_UNKNOWN, - /* 204, 0xcc */ SDL_SCANCODE_UNKNOWN, - /* 205, 0xcd */ SDL_SCANCODE_UNKNOWN, - /* 206, 0xce */ SDL_SCANCODE_UNKNOWN, - /* 207, 0xcf */ SDL_SCANCODE_UNKNOWN, - /* 208, 0xd0 */ SDL_SCANCODE_UNKNOWN, - /* 209, 0xd1 */ SDL_SCANCODE_UNKNOWN, - /* 210, 0xd2 */ SDL_SCANCODE_UNKNOWN, - /* 211, 0xd3 */ SDL_SCANCODE_UNKNOWN, - /* 212, 0xd4 */ SDL_SCANCODE_UNKNOWN, - /* 213, 0xd5 */ SDL_SCANCODE_UNKNOWN, - /* 214, 0xd6 */ SDL_SCANCODE_UNKNOWN, - /* 215, 0xd7 */ SDL_SCANCODE_UNKNOWN, - /* 216, 0xd8 */ SDL_SCANCODE_UNKNOWN, - /* 217, 0xd9 */ SDL_SCANCODE_UNKNOWN, - /* 218, 0xda */ SDL_SCANCODE_UNKNOWN, - /* 219, 0xdb */ SDL_SCANCODE_LEFTBRACKET, - /* 220, 0xdc */ SDL_SCANCODE_BACKSLASH, - /* 221, 0xdd */ SDL_SCANCODE_RIGHTBRACKET, - /* 222, 0xde */ SDL_SCANCODE_APOSTROPHE, - /* 223, 0xdf */ SDL_SCANCODE_UNKNOWN, - /* 224, 0xe0 */ SDL_SCANCODE_UNKNOWN, - /* 225, 0xe1 */ SDL_SCANCODE_UNKNOWN, - /* 226, 0xe2 */ SDL_SCANCODE_NONUSBACKSLASH, - /* 227, 0xe3 */ SDL_SCANCODE_UNKNOWN, - /* 228, 0xe4 */ SDL_SCANCODE_UNKNOWN, - /* 229, 0xe5 */ SDL_SCANCODE_UNKNOWN, - /* 230, 0xe6 */ SDL_SCANCODE_UNKNOWN, - /* 231, 0xe7 */ SDL_SCANCODE_UNKNOWN, - /* 232, 0xe8 */ SDL_SCANCODE_UNKNOWN, - /* 233, 0xe9 */ SDL_SCANCODE_UNKNOWN, - /* 234, 0xea */ SDL_SCANCODE_UNKNOWN, - /* 235, 0xeb */ SDL_SCANCODE_UNKNOWN, - /* 236, 0xec */ SDL_SCANCODE_UNKNOWN, - /* 237, 0xed */ SDL_SCANCODE_UNKNOWN, - /* 238, 0xee */ SDL_SCANCODE_UNKNOWN, - /* 239, 0xef */ SDL_SCANCODE_UNKNOWN, - /* 240, 0xf0 */ SDL_SCANCODE_UNKNOWN, - /* 241, 0xf1 */ SDL_SCANCODE_UNKNOWN, - /* 242, 0xf2 */ SDL_SCANCODE_UNKNOWN, - /* 243, 0xf3 */ SDL_SCANCODE_UNKNOWN, - /* 244, 0xf4 */ SDL_SCANCODE_UNKNOWN, - /* 245, 0xf5 */ SDL_SCANCODE_UNKNOWN, - /* 246, 0xf6 */ SDL_SCANCODE_SYSREQ, - /* 247, 0xf7 */ SDL_SCANCODE_CRSEL, - /* 248, 0xf8 */ SDL_SCANCODE_EXSEL, - /* 249, 0xf9 */ SDL_SCANCODE_UNKNOWN, /* VK_EREOF */ - /* 250, 0xfa */ SDL_SCANCODE_UNKNOWN, /* VK_PLAY */ - /* 251, 0xfb */ SDL_SCANCODE_UNKNOWN, /* VK_ZOOM */ - /* 252, 0xfc */ SDL_SCANCODE_UNKNOWN, - /* 253, 0xfd */ SDL_SCANCODE_UNKNOWN, /* VK_PA1 */ - /* 254, 0xfe */ SDL_SCANCODE_CLEAR, - /* 255, 0xff */ SDL_SCANCODE_UNKNOWN, +static const SDL_Scancode windows_scancode_table[] = +{ + // 0 1 2 3 4 5 6 7 + // 8 9 A B C D E F + SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_ESCAPE, SDL_SCANCODE_1, SDL_SCANCODE_2, SDL_SCANCODE_3, SDL_SCANCODE_4, SDL_SCANCODE_5, SDL_SCANCODE_6, // 0 + SDL_SCANCODE_7, SDL_SCANCODE_8, SDL_SCANCODE_9, SDL_SCANCODE_0, SDL_SCANCODE_MINUS, SDL_SCANCODE_EQUALS, SDL_SCANCODE_BACKSPACE, SDL_SCANCODE_TAB, // 0 + + SDL_SCANCODE_Q, SDL_SCANCODE_W, SDL_SCANCODE_E, SDL_SCANCODE_R, SDL_SCANCODE_T, SDL_SCANCODE_Y, SDL_SCANCODE_U, SDL_SCANCODE_I, // 1 + SDL_SCANCODE_O, SDL_SCANCODE_P, SDL_SCANCODE_LEFTBRACKET, SDL_SCANCODE_RIGHTBRACKET, SDL_SCANCODE_RETURN, SDL_SCANCODE_LCTRL, SDL_SCANCODE_A, SDL_SCANCODE_S, // 1 + + SDL_SCANCODE_D, SDL_SCANCODE_F, SDL_SCANCODE_G, SDL_SCANCODE_H, SDL_SCANCODE_J, SDL_SCANCODE_K, SDL_SCANCODE_L, SDL_SCANCODE_SEMICOLON, // 2 + SDL_SCANCODE_APOSTROPHE, SDL_SCANCODE_GRAVE, SDL_SCANCODE_LSHIFT, SDL_SCANCODE_BACKSLASH, SDL_SCANCODE_Z, SDL_SCANCODE_X, SDL_SCANCODE_C, SDL_SCANCODE_V, // 2 + + SDL_SCANCODE_B, SDL_SCANCODE_N, SDL_SCANCODE_M, SDL_SCANCODE_COMMA, SDL_SCANCODE_PERIOD, SDL_SCANCODE_SLASH, SDL_SCANCODE_RSHIFT, SDL_SCANCODE_PRINTSCREEN,// 3 + SDL_SCANCODE_LALT, SDL_SCANCODE_SPACE, SDL_SCANCODE_CAPSLOCK, SDL_SCANCODE_F1, SDL_SCANCODE_F2, SDL_SCANCODE_F3, SDL_SCANCODE_F4, SDL_SCANCODE_F5, // 3 + + SDL_SCANCODE_F6, SDL_SCANCODE_F7, SDL_SCANCODE_F8, SDL_SCANCODE_F9, SDL_SCANCODE_F10, SDL_SCANCODE_NUMLOCKCLEAR, SDL_SCANCODE_SCROLLLOCK, SDL_SCANCODE_HOME, // 4 + SDL_SCANCODE_UP, SDL_SCANCODE_PAGEUP, SDL_SCANCODE_KP_MINUS, SDL_SCANCODE_LEFT, SDL_SCANCODE_KP_5, SDL_SCANCODE_RIGHT, SDL_SCANCODE_KP_PLUS, SDL_SCANCODE_END, // 4 + + SDL_SCANCODE_DOWN, SDL_SCANCODE_PAGEDOWN, SDL_SCANCODE_INSERT, SDL_SCANCODE_DELETE, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_NONUSBACKSLASH,SDL_SCANCODE_F11, // 5 + SDL_SCANCODE_F12, SDL_SCANCODE_PAUSE, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_LGUI, SDL_SCANCODE_RGUI, SDL_SCANCODE_APPLICATION, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, // 5 + + SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, // 6 + SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, // 6 + + SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, // 7 + SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN // 7 }; /* *INDENT-ON* */ diff --git a/src/file/SDL_rwops.c b/src/file/SDL_rwops.c index e521588db4..65493979b0 100644 --- a/src/file/SDL_rwops.c +++ b/src/file/SDL_rwops.c @@ -37,11 +37,6 @@ #include "../core/android/SDL_android.h" #endif -#ifdef __NDS__ -/* include libfat headers for fatInitDefault(). */ -#include <fat.h> -#endif /* __NDS__ */ - #ifdef __WIN32__ /* Functions to read/write Win32 API file pointers */ @@ -92,8 +87,7 @@ windows_file_open(SDL_RWops * context, const char *filename, const char *mode) context->hidden.windowsio.buffer.data = (char *) SDL_malloc(READAHEAD_BUFFER_SIZE); if (!context->hidden.windowsio.buffer.data) { - SDL_OutOfMemory(); - return -1; + return SDL_OutOfMemory(); } /* Do not open a dialog box if failure */ old_error_mode = @@ -129,13 +123,11 @@ windows_file_size(SDL_RWops * context) LARGE_INTEGER size; if (!context || context->hidden.windowsio.h == INVALID_HANDLE_VALUE) { - SDL_SetError("windows_file_size: invalid context/file not opened"); - return -1; + return SDL_SetError("windows_file_size: invalid context/file not opened"); } if (!GetFileSizeEx(context->hidden.windowsio.h, &size)) { - WIN_SetError("windows_file_size"); - return -1; + return WIN_SetError("windows_file_size"); } return size.QuadPart; @@ -148,8 +140,7 @@ windows_file_seek(SDL_RWops * context, Sint64 offset, int whence) LARGE_INTEGER windowsoffset; if (!context || context->hidden.windowsio.h == INVALID_HANDLE_VALUE) { - SDL_SetError("windows_file_seek: invalid context/file not opened"); - return -1; + return SDL_SetError("windows_file_seek: invalid context/file not opened"); } /* FIXME: We may be able to satisfy the seek within buffered data */ @@ -169,14 +160,12 @@ windows_file_seek(SDL_RWops * context, Sint64 offset, int whence) windowswhence = FILE_END; break; default: - SDL_SetError("windows_file_seek: Unknown value for 'whence'"); - return -1; + return SDL_SetError("windows_file_seek: Unknown value for 'whence'"); } windowsoffset.QuadPart = offset; if (!SetFilePointerEx(context->hidden.windowsio.h, windowsoffset, &windowsoffset, windowswhence)) { - WIN_SetError("windows_file_seek"); - return -1; + return WIN_SetError("windows_file_seek"); } return windowsoffset.QuadPart; } @@ -334,8 +323,7 @@ stdio_seek(SDL_RWops * context, Sint64 offset, int whence) return (ftell(context->hidden.stdio.fp)); } #endif - SDL_Error(SDL_EFSEEK); - return (-1); + return SDL_Error(SDL_EFSEEK); } static size_t SDLCALL @@ -370,8 +358,7 @@ stdio_close(SDL_RWops * context) if (context->hidden.stdio.autoclose) { /* WARNING: Check the return value here! */ if (fclose(context->hidden.stdio.fp) != 0) { - SDL_Error(SDL_EFWRITE); - status = -1; + status = SDL_Error(SDL_EFWRITE); } } SDL_FreeRW(context); @@ -404,8 +391,7 @@ mem_seek(SDL_RWops * context, Sint64 offset, int whence) newpos = context->hidden.mem.stop + offset; break; default: - SDL_SetError("Unknown value for 'whence'"); - return (-1); + return SDL_SetError("Unknown value for 'whence'"); } if (newpos < context->hidden.mem.base) { newpos = context->hidden.mem.base; @@ -455,7 +441,7 @@ static size_t SDLCALL mem_writeconst(SDL_RWops * context, const void *ptr, size_t size, size_t num) { SDL_SetError("Can't write to read-only memory"); - return (-1); + return (0); } static int SDLCALL @@ -517,6 +503,7 @@ SDL_RWFromFile(const char *file, const char *mode) rwops->read = Android_JNI_FileRead; rwops->write = Android_JNI_FileWrite; rwops->close = Android_JNI_FileClose; + rwops->type = SDL_RWOPS_JNIFILE; #elif defined(__WIN32__) rwops = SDL_AllocRW(); @@ -531,6 +518,7 @@ SDL_RWFromFile(const char *file, const char *mode) rwops->read = windows_file_read; rwops->write = windows_file_write; rwops->close = windows_file_close; + rwops->type = SDL_RWOPS_WINFILE; #elif HAVE_STDIO_H { @@ -561,13 +549,6 @@ SDL_RWFromFP(FILE * fp, SDL_bool autoclose) { SDL_RWops *rwops = NULL; -#if 0 -/*#ifdef __NDS__*/ - /* set it up so we can use stdio file function */ - fatInitDefault(); - printf("called fatInitDefault()"); -#endif /* __NDS__ */ - rwops = SDL_AllocRW(); if (rwops != NULL) { rwops->size = stdio_size; @@ -577,6 +558,7 @@ SDL_RWFromFP(FILE * fp, SDL_bool autoclose) rwops->close = stdio_close; rwops->hidden.stdio.fp = fp; rwops->hidden.stdio.autoclose = autoclose; + rwops->type = SDL_RWOPS_STDFILE; } return (rwops); } @@ -592,7 +574,15 @@ SDL_RWFromFP(void * fp, SDL_bool autoclose) SDL_RWops * SDL_RWFromMem(void *mem, int size) { - SDL_RWops *rwops; + SDL_RWops *rwops = NULL; + if (!mem) { + SDL_InvalidParamError("mem"); + return (rwops); + } + if (!size) { + SDL_InvalidParamError("size"); + return (rwops); + } rwops = SDL_AllocRW(); if (rwops != NULL) { @@ -604,6 +594,7 @@ SDL_RWFromMem(void *mem, int size) rwops->hidden.mem.base = (Uint8 *) mem; rwops->hidden.mem.here = rwops->hidden.mem.base; rwops->hidden.mem.stop = rwops->hidden.mem.base + size; + rwops->type = SDL_RWOPS_MEMORY; } return (rwops); } @@ -611,7 +602,15 @@ SDL_RWFromMem(void *mem, int size) SDL_RWops * SDL_RWFromConstMem(const void *mem, int size) { - SDL_RWops *rwops; + SDL_RWops *rwops = NULL; + if (!mem) { + SDL_InvalidParamError("mem"); + return (rwops); + } + if (!size) { + SDL_InvalidParamError("size"); + return (rwops); + } rwops = SDL_AllocRW(); if (rwops != NULL) { @@ -623,6 +622,7 @@ SDL_RWFromConstMem(const void *mem, int size) rwops->hidden.mem.base = (Uint8 *) mem; rwops->hidden.mem.here = rwops->hidden.mem.base; rwops->hidden.mem.stop = rwops->hidden.mem.base + size; + rwops->type = SDL_RWOPS_MEMORY_RO; } return (rwops); } @@ -636,6 +636,7 @@ SDL_AllocRW(void) if (area == NULL) { SDL_OutOfMemory(); } + area->type = SDL_RWOPS_UNKNOWN; return (area); } diff --git a/src/haptic/SDL_haptic.c b/src/haptic/SDL_haptic.c index d6b8a7b2ea..5952a455d9 100644 --- a/src/haptic/SDL_haptic.c +++ b/src/haptic/SDL_haptic.c @@ -447,8 +447,7 @@ SDL_HapticNewEffect(SDL_Haptic * haptic, SDL_HapticEffect * effect) /* Check to see if effect is supported */ if (SDL_HapticEffectSupported(haptic, effect) == SDL_FALSE) { - SDL_SetError("Haptic: Effect not supported by haptic device."); - return -1; + return SDL_SetError("Haptic: Effect not supported by haptic device."); } /* See if there's a free slot */ @@ -467,8 +466,7 @@ SDL_HapticNewEffect(SDL_Haptic * haptic, SDL_HapticEffect * effect) } } - SDL_SetError("Haptic: Device has no free space left."); - return -1; + return SDL_SetError("Haptic: Device has no free space left."); } /* @@ -497,8 +495,7 @@ SDL_HapticUpdateEffect(SDL_Haptic * haptic, int effect, /* Can't change type dynamically. */ if (data->type != haptic->effects[effect].effect.type) { - SDL_SetError("Haptic: Updating effect type is illegal."); - return -1; + return SDL_SetError("Haptic: Updating effect type is illegal."); } /* Updates the effect */ @@ -579,8 +576,7 @@ SDL_HapticGetEffectStatus(SDL_Haptic * haptic, int effect) } if ((haptic->supported & SDL_HAPTIC_STATUS) == 0) { - SDL_SetError("Haptic: Device does not support status queries."); - return -1; + return SDL_SetError("Haptic: Device does not support status queries."); } return SDL_SYS_HapticGetEffectStatus(haptic, &haptic->effects[effect]); @@ -600,13 +596,11 @@ SDL_HapticSetGain(SDL_Haptic * haptic, int gain) } if ((haptic->supported & SDL_HAPTIC_GAIN) == 0) { - SDL_SetError("Haptic: Device does not support setting gain."); - return -1; + return SDL_SetError("Haptic: Device does not support setting gain."); } if ((gain < 0) || (gain > 100)) { - SDL_SetError("Haptic: Gain must be between 0 and 100."); - return -1; + return SDL_SetError("Haptic: Gain must be between 0 and 100."); } /* We use the envvar to get the maximum gain. */ @@ -644,13 +638,11 @@ SDL_HapticSetAutocenter(SDL_Haptic * haptic, int autocenter) } if ((haptic->supported & SDL_HAPTIC_AUTOCENTER) == 0) { - SDL_SetError("Haptic: Device does not support setting autocenter."); - return -1; + return SDL_SetError("Haptic: Device does not support setting autocenter."); } if ((autocenter < 0) || (autocenter > 100)) { - SDL_SetError("Haptic: Autocenter must be between 0 and 100."); - return -1; + return SDL_SetError("Haptic: Autocenter must be between 0 and 100."); } if (SDL_SYS_HapticSetAutocenter(haptic, autocenter) < 0) { @@ -671,8 +663,7 @@ SDL_HapticPause(SDL_Haptic * haptic) } if ((haptic->supported & SDL_HAPTIC_PAUSE) == 0) { - SDL_SetError("Haptic: Device does not support setting pausing."); - return -1; + return SDL_SetError("Haptic: Device does not support setting pausing."); } return SDL_SYS_HapticPause(haptic); @@ -773,8 +764,7 @@ SDL_HapticRumblePlay(SDL_Haptic * haptic, float strength, Uint32 length) } if (haptic->rumble_id < 0) { - SDL_SetError("Haptic: Rumble effect not initialized on haptic device"); - return -1; + return SDL_SetError("Haptic: Rumble effect not initialized on haptic device"); } /* Clamp strength. */ @@ -805,8 +795,7 @@ SDL_HapticRumbleStop(SDL_Haptic * haptic) } if (haptic->rumble_id < 0) { - SDL_SetError("Haptic: Rumble effect not initialized on haptic device"); - return -1; + return SDL_SetError("Haptic: Rumble effect not initialized on haptic device"); } return SDL_HapticStopEffect(haptic, haptic->rumble_id); diff --git a/src/haptic/darwin/SDL_syshaptic.c b/src/haptic/darwin/SDL_syshaptic.c index 32548b3738..1af86b8b10 100644 --- a/src/haptic/darwin/SDL_syshaptic.c +++ b/src/haptic/darwin/SDL_syshaptic.c @@ -160,15 +160,13 @@ SDL_SYS_HapticInit(void) /* Get HID devices. */ match = IOServiceMatching(kIOHIDDeviceKey); if (match == NULL) { - SDL_SetError("Haptic: Failed to get IOServiceMatching."); - return -1; + return SDL_SetError("Haptic: Failed to get IOServiceMatching."); } /* Now search I/O Registry for matching devices. */ result = IOServiceGetMatchingServices(kIOMasterPortDefault, match, &iter); if (result != kIOReturnSuccess) { - SDL_SetError("Haptic: Couldn't create a HID object iterator."); - return -1; + return SDL_SetError("Haptic: Couldn't create a HID object iterator."); } /* IOServiceGetMatchingServices consumes dictionary. */ @@ -257,8 +255,7 @@ HIDGetDeviceProduct(io_service_t dev, char *name) ret = IORegistryEntryCreateCFProperties(dev, &hidProperties, kCFAllocatorDefault, kNilOptions); if ((ret != KERN_SUCCESS) || !hidProperties) { - SDL_SetError("Haptic: Unable to create CFProperties."); - return -1; + return SDL_SetError("Haptic: Unable to create CFProperties."); } /* Mac OS X currently is not mirroring all USB properties to HID page so need to look at USB device page also @@ -289,17 +286,15 @@ HIDGetDeviceProduct(io_service_t dev, char *name) if (refCF) { if (!CFStringGetCString(refCF, name, 256, CFStringGetSystemEncoding())) { - SDL_SetError + return SDL_SetError ("Haptic: CFStringGetCString error retrieving pDevice->product."); - return -1; } } CFRelease(usbProperties); } else { - SDL_SetError + return SDL_SetError ("Haptic: IORegistryEntryCreateCFProperties failed to create usbProperties."); - return -1; } /* Release stuff. */ @@ -310,8 +305,7 @@ HIDGetDeviceProduct(io_service_t dev, char *name) SDL_SetError("Haptic: IOObjectRelease error with parent1."); } } else { - SDL_SetError("Haptic: Error getting registry entries."); - return -1; + return SDL_SetError("Haptic: Error getting registry entries."); } return 0; @@ -336,8 +330,7 @@ GetSupportedFeatures(SDL_Haptic * haptic) ret = FFDeviceGetForceFeedbackCapabilities(device, &features); if (ret != FF_OK) { - SDL_SetError("Haptic: Unable to get device's supported features."); - return -1; + return SDL_SetError("Haptic: Unable to get device's supported features."); } supported = 0; @@ -366,9 +359,8 @@ GetSupportedFeatures(SDL_Haptic * haptic) if (ret == FF_OK) supported |= SDL_HAPTIC_GAIN; else if (ret != FFERR_UNSUPPORTED) { - SDL_SetError("Haptic: Unable to get if device supports gain: %s.", - FFStrError(ret)); - return -1; + return SDL_SetError("Haptic: Unable to get if device supports gain: %s.", + FFStrError(ret)); } /* Checks if supports autocenter. */ @@ -377,10 +369,9 @@ GetSupportedFeatures(SDL_Haptic * haptic) if (ret == FF_OK) supported |= SDL_HAPTIC_AUTOCENTER; else if (ret != FFERR_UNSUPPORTED) { - SDL_SetError + return SDL_SetError ("Haptic: Unable to get if device supports autocenter: %s.", FFStrError(ret)); - return -1; } /* Check for axes, we have an artificial limit on axes */ @@ -625,8 +616,7 @@ SDL_SYS_SetDirection(FFEFFECT * effect, SDL_HapticDirection * dir, int naxes) /* Has axes. */ rglDir = SDL_malloc(sizeof(LONG) * naxes); if (rglDir == NULL) { - SDL_OutOfMemory(); - return -1; + return SDL_OutOfMemory(); } SDL_memset(rglDir, 0, sizeof(LONG) * naxes); effect->rglDirection = rglDir; @@ -654,8 +644,7 @@ SDL_SYS_SetDirection(FFEFFECT * effect, SDL_HapticDirection * dir, int naxes) return 0; default: - SDL_SetError("Haptic: Unknown direction type."); - return -1; + return SDL_SetError("Haptic: Unknown direction type."); } } @@ -695,8 +684,7 @@ SDL_SYS_ToFFEFFECT(SDL_Haptic * haptic, FFEFFECT * dest, /* Envelope. */ envelope = SDL_malloc(sizeof(FFENVELOPE)); if (envelope == NULL) { - SDL_OutOfMemory(); - return -1; + return SDL_OutOfMemory(); } SDL_memset(envelope, 0, sizeof(FFENVELOPE)); dest->lpEnvelope = envelope; @@ -707,8 +695,7 @@ SDL_SYS_ToFFEFFECT(SDL_Haptic * haptic, FFEFFECT * dest, if (dest->cAxes > 0) { axes = SDL_malloc(sizeof(DWORD) * dest->cAxes); if (axes == NULL) { - SDL_OutOfMemory(); - return -1; + return SDL_OutOfMemory(); } axes[0] = haptic->hwdata->axes[0]; /* Always at least one axis. */ if (dest->cAxes > 1) { @@ -727,8 +714,7 @@ SDL_SYS_ToFFEFFECT(SDL_Haptic * haptic, FFEFFECT * dest, hap_constant = &src->constant; constant = SDL_malloc(sizeof(FFCONSTANTFORCE)); if (constant == NULL) { - SDL_OutOfMemory(); - return -1; + return SDL_OutOfMemory(); } SDL_memset(constant, 0, sizeof(FFCONSTANTFORCE)); @@ -771,8 +757,7 @@ SDL_SYS_ToFFEFFECT(SDL_Haptic * haptic, FFEFFECT * dest, hap_periodic = &src->periodic; periodic = SDL_malloc(sizeof(FFPERIODIC)); if (periodic == NULL) { - SDL_OutOfMemory(); - return -1; + return SDL_OutOfMemory(); } SDL_memset(periodic, 0, sizeof(FFPERIODIC)); @@ -817,8 +802,7 @@ SDL_SYS_ToFFEFFECT(SDL_Haptic * haptic, FFEFFECT * dest, hap_condition = &src->condition; condition = SDL_malloc(sizeof(FFCONDITION) * dest->cAxes); if (condition == NULL) { - SDL_OutOfMemory(); - return -1; + return SDL_OutOfMemory(); } SDL_memset(condition, 0, sizeof(FFCONDITION)); @@ -860,8 +844,7 @@ SDL_SYS_ToFFEFFECT(SDL_Haptic * haptic, FFEFFECT * dest, hap_ramp = &src->ramp; ramp = SDL_malloc(sizeof(FFRAMPFORCE)); if (ramp == NULL) { - SDL_OutOfMemory(); - return -1; + return SDL_OutOfMemory(); } SDL_memset(ramp, 0, sizeof(FFRAMPFORCE)); @@ -899,8 +882,7 @@ SDL_SYS_ToFFEFFECT(SDL_Haptic * haptic, FFEFFECT * dest, hap_custom = &src->custom; custom = SDL_malloc(sizeof(FFCUSTOMFORCE)); if (custom == NULL) { - SDL_OutOfMemory(); - return -1; + return SDL_OutOfMemory(); } SDL_memset(custom, 0, sizeof(FFCUSTOMFORCE)); @@ -944,8 +926,7 @@ SDL_SYS_ToFFEFFECT(SDL_Haptic * haptic, FFEFFECT * dest, default: - SDL_SetError("Haptic: Unknown effect type."); - return -1; + return SDL_SetError("Haptic: Unknown effect type."); } return 0; @@ -1150,9 +1131,8 @@ SDL_SYS_HapticRunEffect(SDL_Haptic * haptic, struct haptic_effect *effect, /* Run the effect. */ ret = FFEffectStart(effect->hweffect->ref, iter, 0); if (ret != FF_OK) { - SDL_SetError("Haptic: Unable to run the effect: %s.", - FFStrError(ret)); - return -1; + return SDL_SetError("Haptic: Unable to run the effect: %s.", + FFStrError(ret)); } return 0; @@ -1169,9 +1149,8 @@ SDL_SYS_HapticStopEffect(SDL_Haptic * haptic, struct haptic_effect *effect) ret = FFEffectStop(effect->hweffect->ref); if (ret != FF_OK) { - SDL_SetError("Haptic: Unable to stop the effect: %s.", - FFStrError(ret)); - return -1; + return SDL_SetError("Haptic: Unable to stop the effect: %s.", + FFStrError(ret)); } return 0; @@ -1236,8 +1215,7 @@ SDL_SYS_HapticSetGain(SDL_Haptic * haptic, int gain) FFDeviceSetForceFeedbackProperty(haptic->hwdata->device, FFPROP_FFGAIN, &val); if (ret != FF_OK) { - SDL_SetError("Haptic: Error setting gain: %s.", FFStrError(ret)); - return -1; + return SDL_SetError("Haptic: Error setting gain: %s.", FFStrError(ret)); } return 0; @@ -1262,9 +1240,8 @@ SDL_SYS_HapticSetAutocenter(SDL_Haptic * haptic, int autocenter) ret = FFDeviceSetForceFeedbackProperty(haptic->hwdata->device, FFPROP_AUTOCENTER, &val); if (ret != FF_OK) { - SDL_SetError("Haptic: Error setting autocenter: %s.", - FFStrError(ret)); - return -1; + return SDL_SetError("Haptic: Error setting autocenter: %s.", + FFStrError(ret)); } return 0; @@ -1282,8 +1259,7 @@ SDL_SYS_HapticPause(SDL_Haptic * haptic) ret = FFDeviceSendForceFeedbackCommand(haptic->hwdata->device, FFSFFC_PAUSE); if (ret != FF_OK) { - SDL_SetError("Haptic: Error pausing device: %s.", FFStrError(ret)); - return -1; + return SDL_SetError("Haptic: Error pausing device: %s.", FFStrError(ret)); } return 0; @@ -1301,8 +1277,7 @@ SDL_SYS_HapticUnpause(SDL_Haptic * haptic) ret = FFDeviceSendForceFeedbackCommand(haptic->hwdata->device, FFSFFC_CONTINUE); if (ret != FF_OK) { - SDL_SetError("Haptic: Error pausing device: %s.", FFStrError(ret)); - return -1; + return SDL_SetError("Haptic: Error pausing device: %s.", FFStrError(ret)); } return 0; @@ -1320,8 +1295,7 @@ SDL_SYS_HapticStopAll(SDL_Haptic * haptic) ret = FFDeviceSendForceFeedbackCommand(haptic->hwdata->device, FFSFFC_STOPALL); if (ret != FF_OK) { - SDL_SetError("Haptic: Error stopping device: %s.", FFStrError(ret)); - return -1; + return SDL_SetError("Haptic: Error stopping device: %s.", FFStrError(ret)); } return 0; diff --git a/src/haptic/linux/SDL_syshaptic.c b/src/haptic/linux/SDL_syshaptic.c index 6f40cd7750..e07c832f92 100644 --- a/src/haptic/linux/SDL_syshaptic.c +++ b/src/haptic/linux/SDL_syshaptic.c @@ -92,9 +92,8 @@ EV_IsHaptic(int fd) /* Ask device for what it has. */ ret = 0; if (ioctl(fd, EVIOCGBIT(EV_FF, sizeof(features)), features) < 0) { - SDL_SetError("Haptic: Unable to get device's features: %s", - strerror(errno)); - return -1; + return SDL_SetError("Haptic: Unable to get device's features: %s", + strerror(errno)); } /* Convert supported features to SDL_HAPTIC platform-neutral features. */ @@ -309,9 +308,8 @@ SDL_SYS_HapticOpen(SDL_Haptic * haptic) /* Open the character device */ fd = open(SDL_hapticlist[haptic->index].fname, O_RDWR, 0); if (fd < 0) { - SDL_SetError("Haptic: Unable to open %s: %s", - SDL_hapticlist[haptic->index], strerror(errno)); - return -1; + return SDL_SetError("Haptic: Unable to open %s: %s", + SDL_hapticlist[haptic->index], strerror(errno)); } /* Try to create the haptic. */ @@ -340,9 +338,8 @@ SDL_SYS_HapticMouse(void) /* Open the device. */ fd = open(SDL_hapticlist[i].fname, O_RDWR, 0); if (fd < 0) { - SDL_SetError("Haptic: Unable to open %s: %s", - SDL_hapticlist[i], strerror(errno)); - return -1; + return SDL_SetError("Haptic: Unable to open %s: %s", + SDL_hapticlist[i], strerror(errno)); } /* Is it a mouse? */ @@ -405,15 +402,13 @@ SDL_SYS_HapticOpenFromJoystick(SDL_Haptic * haptic, SDL_Joystick * joystick) } } if (i >= MAX_HAPTICS) { - SDL_SetError("Haptic: Joystick doesn't have Haptic capabilities"); - return -1; + return SDL_SetError("Haptic: Joystick doesn't have Haptic capabilities"); } fd = open(joystick->hwdata->fname, O_RDWR, 0); if (fd < 0) { - SDL_SetError("Haptic: Unable to open %s: %s", - joystick->hwdata->fname, strerror(errno)); - return -1; + return SDL_SetError("Haptic: Unable to open %s: %s", + joystick->hwdata->fname, strerror(errno)); } ret = SDL_SYS_HapticOpenFromFD(haptic, fd); /* Already closes on error. */ if (ret < 0) { @@ -544,8 +539,7 @@ SDL_SYS_ToDirection(SDL_HapticDirection * dir) return (Uint16) tmp; default: - SDL_SetError("Haptic: Unsupported direction type."); - return (Uint16) - 1; + return (Uint16) SDL_SetError("Haptic: Unsupported direction type."); } return 0; @@ -733,8 +727,7 @@ SDL_SYS_ToFFEffect(struct ff_effect *dest, SDL_HapticEffect * src) default: - SDL_SetError("Haptic: Unknown effect type."); - return -1; + return SDL_SetError("Haptic: Unknown effect type."); } return 0; @@ -754,8 +747,7 @@ SDL_SYS_HapticNewEffect(SDL_Haptic * haptic, struct haptic_effect *effect, effect->hweffect = (struct haptic_hweffect *) SDL_malloc(sizeof(struct haptic_hweffect)); if (effect->hweffect == NULL) { - SDL_OutOfMemory(); - return -1; + return SDL_OutOfMemory(); } /* Prepare the ff_effect */ @@ -802,9 +794,8 @@ SDL_SYS_HapticUpdateEffect(SDL_Haptic * haptic, /* See if it can be uploaded. */ if (ioctl(haptic->hwdata->fd, EVIOCSFF, &linux_effect) < 0) { - SDL_SetError("Haptic: Error updating the effect: %s", - strerror(errno)); - return -1; + return SDL_SetError("Haptic: Error updating the effect: %s", + strerror(errno)); } /* Copy the new effect into memory. */ @@ -831,8 +822,7 @@ SDL_SYS_HapticRunEffect(SDL_Haptic * haptic, struct haptic_effect *effect, run.value = (iterations > INT_MAX) ? INT_MAX : iterations; if (write(haptic->hwdata->fd, (const void *) &run, sizeof(run)) < 0) { - SDL_SetError("Haptic: Unable to run the effect: %s", strerror(errno)); - return -1; + return SDL_SetError("Haptic: Unable to run the effect: %s", strerror(errno)); } return 0; @@ -852,9 +842,8 @@ SDL_SYS_HapticStopEffect(SDL_Haptic * haptic, struct haptic_effect *effect) stop.value = 0; if (write(haptic->hwdata->fd, (const void *) &stop, sizeof(stop)) < 0) { - SDL_SetError("Haptic: Unable to stop the effect: %s", - strerror(errno)); - return -1; + return SDL_SetError("Haptic: Unable to stop the effect: %s", + strerror(errno)); } return 0; @@ -891,8 +880,7 @@ SDL_SYS_HapticGetEffectStatus(SDL_Haptic * haptic, ie.code = effect->hweffect->effect.id; if (write(haptic->hwdata->fd, &ie, sizeof(ie)) < 0) { - SDL_SetError("Haptic: Error getting device status."); - return -1; + return SDL_SetError("Haptic: Error getting device status."); } return 0; @@ -915,8 +903,7 @@ SDL_SYS_HapticSetGain(SDL_Haptic * haptic, int gain) ie.value = (0xFFFFUL * gain) / 100; if (write(haptic->hwdata->fd, &ie, sizeof(ie)) < 0) { - SDL_SetError("Haptic: Error setting gain: %s", strerror(errno)); - return -1; + return SDL_SetError("Haptic: Error setting gain: %s", strerror(errno)); } return 0; @@ -936,8 +923,7 @@ SDL_SYS_HapticSetAutocenter(SDL_Haptic * haptic, int autocenter) ie.value = (0xFFFFUL * autocenter) / 100; if (write(haptic->hwdata->fd, &ie, sizeof(ie)) < 0) { - SDL_SetError("Haptic: Error setting autocenter: %s", strerror(errno)); - return -1; + return SDL_SetError("Haptic: Error setting autocenter: %s", strerror(errno)); } return 0; @@ -977,9 +963,8 @@ SDL_SYS_HapticStopAll(SDL_Haptic * haptic) if (haptic->effects[i].hweffect != NULL) { ret = SDL_SYS_HapticStopEffect(haptic, &haptic->effects[i]); if (ret < 0) { - SDL_SetError + return SDL_SetError ("Haptic: Error while trying to stop all playing effects."); - return -1; } } } diff --git a/src/haptic/nds/SDL_syshaptic.c b/src/haptic/nds/SDL_syshaptic.c deleted file mode 100644 index e46f178dc7..0000000000 --- a/src/haptic/nds/SDL_syshaptic.c +++ /dev/null @@ -1,330 +0,0 @@ -/* - Simple DirectMedia Layer - Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org> - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. -*/ -#include "SDL_config.h" - -#ifdef SDL_HAPTIC_NDS - -#include "SDL_haptic.h" -#include "../SDL_syshaptic.h" -#include "SDL_joystick.h" -#include <nds/memory.h> -#include <nds/arm9/rumble.h> - -#define MAX_HAPTICS 1 -/* right now only the ezf3in1 (and maybe official rumble pak) are supported - and there can only be one of those in at a time (in GBA slot.) */ - -static SDL_Haptic *nds_haptic = NULL; - -struct haptic_hwdata -{ - enum - { NONE, OFFICIAL, EZF3IN1 } type; - int pos; -}; - - -void -NDS_EZF_OpenNorWrite() -{ - GBA_BUS[0x0FF0000] = 0xD200; - GBA_BUS[0x0000000] = 0x1500; - GBA_BUS[0x0010000] = 0xD200; - GBA_BUS[0x0020000] = 0x1500; - GBA_BUS[0x0E20000] = 0x1500; - GBA_BUS[0x0FE0000] = 0x1500; -} - -void -NDS_EZF_CloseNorWrite() -{ - GBA_BUS[0x0FF0000] = 0xD200; - GBA_BUS[0x0000000] = 0x1500; - GBA_BUS[0x0010000] = 0xD200; - GBA_BUS[0x0020000] = 0x1500; - GBA_BUS[0x0E20000] = 0xD200; - GBA_BUS[0x0FE0000] = 0x1500; -} - -void -NDS_EZF_ChipReset() -{ - GBA_BUS[0x0000] = 0x00F0; - GBA_BUS[0x1000] = 0x00F0; -} uint32 NDS_EZF_IsPresent() -{ - vuint16 id1, id2; - - NDS_EZF_OpenNorWrite(); - - GBA_BUS[0x0555] = 0x00AA; - GBA_BUS[0x02AA] = 0x0055; - GBA_BUS[0x0555] = 0x0090; - GBA_BUS[0x1555] = 0x00AA; - GBA_BUS[0x12AA] = 0x0055; - GBA_BUS[0x1555] = 0x0090; - id1 = GBA_BUS[0x0001]; - id2 = GBA_BUS[0x1001]; - if ((id1 != 0x227E) || (id2 != 0x227E)) { - NDS_EZF_CloseNorWrite(); - return 0; - } - id1 = GBA_BUS[0x000E]; - id2 = GBA_BUS[0x100E]; - - NDS_EZF_CloseNorWrite(); - if (id1 == 0x2218 && id2 == 0x2218) { - return 1; - } - return 0; -} -void -NDS_EZF_SetShake(u8 pos) -{ - u16 data = ((pos % 3) | 0x00F0); - GBA_BUS[0x0FF0000] = 0xD200; - GBA_BUS[0x0000000] = 0x1500; - GBA_BUS[0x0010000] = 0xD200; - GBA_BUS[0x0020000] = 0x1500; - GBA_BUS[0x0F10000] = data; - GBA_BUS[0x0FE0000] = 0x1500; - - GBA_BUS[0] = 0x0000; /* write any value for vibration. */ - GBA_BUS[0] = 0x0002; -} - -static int -SDL_SYS_LogicError(void) -{ - SDL_SetError("Logic error: No haptic devices available."); - return 0; -} - - -int -SDL_SYS_HapticInit(void) -{ - int ret = 0; - if (isRumbleInserted()) { - /* official rumble pak is present. */ - ret = 1; - printf("debug: haptic present: nintendo\n"); - } else if (NDS_EZF_IsPresent()) { - /* ezflash 3-in-1 pak is present. */ - ret = 1; - printf("debug: haptic present: ezf3in1\n"); - NDS_EZF_ChipReset(); - } else { - printf("debug: no haptic found\n"); - } - - return ret; -} - - -const char * -SDL_SYS_HapticName(int index) -{ - if (nds_haptic) { - switch (nds_haptic->hwdata->type) { - case OFFICIAL: - return "Nintendo DS Rumble Pak"; - case EZF3IN1: - return "EZFlash 3-in-1 Rumble"; - default: - return NULL; - } - } - return NULL; -} - - -int -SDL_SYS_HapticOpen(SDL_Haptic * haptic) -{ - if (!haptic) { - return -1; - } - - haptic->hwdata = SDL_malloc(sizeof(struct haptic_hwdata)); - if (!haptic->hwdata) { - SDL_OutOfMemory(); - return -1; - } - nds_haptic = haptic; - - haptic->supported = SDL_HAPTIC_CONSTANT; - - /* determine what is here, if anything */ - haptic->hwdata->type = NONE; - if (isRumbleInserted()) { - /* official rumble pak is present. */ - haptic->hwdata->type = OFFICIAL; - } else if (NDS_EZF_IsPresent()) { - /* ezflash 3-in-1 pak is present. */ - haptic->hwdata->type = EZF3IN1; - NDS_EZF_ChipReset(); - } else { - /* no haptic present */ - SDL_SYS_LogicError(); - return -1; - } - - return 0; -} - - -int -SDL_SYS_HapticMouse(void) -{ - return -1; -} - - -int -SDL_SYS_JoystickIsHaptic(SDL_Joystick * joystick) -{ - return 0; -} - - -int -SDL_SYS_HapticOpenFromJoystick(SDL_Haptic * haptic, SDL_Joystick * joystick) -{ - /*SDL_SYS_LogicError(); */ - return -1; -} - - -int -SDL_SYS_JoystickSameHaptic(SDL_Haptic * haptic, SDL_Joystick * joystick) -{ - return 0; -} - - -void -SDL_SYS_HapticClose(SDL_Haptic * haptic) -{ - return; -} - - -void -SDL_SYS_HapticQuit(void) -{ - return; -} - - -int -SDL_SYS_HapticNewEffect(SDL_Haptic * haptic, - struct haptic_effect *effect, SDL_HapticEffect * base) -{ - SDL_SYS_LogicError(); - return -1; -} - - -int -SDL_SYS_HapticUpdateEffect(SDL_Haptic * haptic, - struct haptic_effect *effect, - SDL_HapticEffect * data) -{ - SDL_SYS_LogicError(); - return -1; -} - - -int -SDL_SYS_HapticRunEffect(SDL_Haptic * haptic, struct haptic_effect *effect, - Uint32 iterations) -{ - SDL_SYS_LogicError(); - return -1; -} - - -int -SDL_SYS_HapticStopEffect(SDL_Haptic * haptic, struct haptic_effect *effect) -{ - SDL_SYS_LogicError(); - return -1; -} - - -void -SDL_SYS_HapticDestroyEffect(SDL_Haptic * haptic, struct haptic_effect *effect) -{ - SDL_SYS_LogicError(); - return; -} - - -int -SDL_SYS_HapticGetEffectStatus(SDL_Haptic * haptic, - struct haptic_effect *effect) -{ - SDL_SYS_LogicError(); - return -1; -} - - -int -SDL_SYS_HapticSetGain(SDL_Haptic * haptic, int gain) -{ - SDL_SYS_LogicError(); - return -1; -} - - -int -SDL_SYS_HapticSetAutocenter(SDL_Haptic * haptic, int autocenter) -{ - SDL_SYS_LogicError(); - return -1; -} - -int -SDL_SYS_HapticPause(SDL_Haptic * haptic) -{ - SDL_SYS_LogicError(); - return -1; -} - -int -SDL_SYS_HapticUnpause(SDL_Haptic * haptic) -{ - SDL_SYS_LogicError(); - return -1; -} - -int -SDL_SYS_HapticStopAll(SDL_Haptic * haptic) -{ - SDL_SYS_LogicError(); - return -1; -} - - - -#endif /* SDL_HAPTIC_NDS */ -/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/haptic/windows/SDL_syshaptic.c b/src/haptic/windows/SDL_syshaptic.c index 9993a5b250..9446ce52a5 100644 --- a/src/haptic/windows/SDL_syshaptic.c +++ b/src/haptic/windows/SDL_syshaptic.c @@ -22,16 +22,16 @@ #ifdef SDL_HAPTIC_DINPUT +#include "SDL_assert.h" +#include "SDL_hints.h" #include "SDL_haptic.h" #include "../SDL_syshaptic.h" #include "SDL_joystick.h" #include "../../joystick/SDL_sysjoystick.h" /* For the real SDL_Joystick */ #include "../../joystick/windows/SDL_dxjoystick_c.h" /* For joystick hwdata */ - #define MAX_HAPTICS 32 - /* * List of available haptic devices. */ @@ -41,6 +41,8 @@ static struct char *name; SDL_Haptic *haptic; DIDEVCAPS capabilities; + Uint8 bXInputHaptic; // Supports force feedback via XInput. + Uint8 userid; // XInput userid index for this joystick } SDL_hapticlist[MAX_HAPTICS]; @@ -52,6 +54,8 @@ struct haptic_hwdata LPDIRECTINPUTDEVICE8 device; DWORD axes[3]; /* Axes to use. */ int is_joystick; /* Device is loaded as joystick. */ + Uint8 bXInputHaptic; // Supports force feedback via XInput. + Uint8 userid; // XInput userid index for this joystick }; @@ -62,6 +66,7 @@ struct haptic_hweffect { DIEFFECT effect; LPDIRECTINPUTEFFECT ref; + XINPUT_VIBRATION vibration; }; @@ -70,6 +75,7 @@ struct haptic_hweffect */ static SDL_bool coinitialized = SDL_FALSE; static LPDIRECTINPUT8 dinput = NULL; +static SDL_bool loaded_xinput = SDL_FALSE; /* @@ -81,12 +87,13 @@ extern HWND SDL_HelperWindow; /* * Prototypes. */ -static void DI_SetError(const char *str, HRESULT err); +static int DI_SetError(const char *str, HRESULT err); static int DI_GUIDIsSame(const GUID * a, const GUID * b); static int SDL_SYS_HapticOpenFromInstance(SDL_Haptic * haptic, DIDEVICEINSTANCE instance); static int SDL_SYS_HapticOpenFromDevice8(SDL_Haptic * haptic, LPDIRECTINPUTDEVICE8 device8); +static int SDL_SYS_HapticOpenFromXInput(SDL_Haptic * haptic, Uint8 userid); static DWORD DIGetTriggerButton(Uint16 button); static int SDL_SYS_SetDirection(DIEFFECT * effect, SDL_HapticDirection * dir, int naxes); @@ -103,14 +110,14 @@ static BOOL CALLBACK DI_EffectCallback(LPCDIEFFECTINFO pei, LPVOID pv); /* * Like SDL_SetError but for DX error codes. */ -static void +static int DI_SetError(const char *str, HRESULT err) { /* SDL_SetError("Haptic: %s - %s: %s", str, DXGetErrorString8A(err), DXGetErrorDescription8A(err)); */ - SDL_SetError("Haptic error %s", str); + return SDL_SetError("Haptic error %s", str); } @@ -130,12 +137,12 @@ DI_GUIDIsSame(const GUID * a, const GUID * b) int SDL_SYS_HapticInit(void) { + const char *env = SDL_GetHint(SDL_HINT_XINPUT_ENABLED); HRESULT ret; HINSTANCE instance; if (dinput != NULL) { /* Already open. */ - SDL_SetError("Haptic: SubSystem already open."); - return -1; + return SDL_SetError("Haptic: SubSystem already open."); } /* Clear all the memory. */ @@ -145,8 +152,7 @@ SDL_SYS_HapticInit(void) ret = WIN_CoInitialize(); if (FAILED(ret)) { - DI_SetError("Coinitialize", ret); - return -1; + return DI_SetError("Coinitialize", ret); } coinitialized = SDL_TRUE; @@ -155,23 +161,20 @@ SDL_SYS_HapticInit(void) &IID_IDirectInput8, (LPVOID) & dinput); if (FAILED(ret)) { SDL_SYS_HapticQuit(); - DI_SetError("CoCreateInstance", ret); - return -1; + return DI_SetError("CoCreateInstance", ret); } /* Because we used CoCreateInstance, we need to Initialize it, first. */ instance = GetModuleHandle(NULL); if (instance == NULL) { SDL_SYS_HapticQuit(); - SDL_SetError("GetModuleHandle() failed with error code %d.", - GetLastError()); - return -1; + return SDL_SetError("GetModuleHandle() failed with error code %d.", + GetLastError()); } ret = IDirectInput8_Initialize(dinput, instance, DIRECTINPUT_VERSION); if (FAILED(ret)) { SDL_SYS_HapticQuit(); - DI_SetError("Initializing DirectInput device", ret); - return -1; + return DI_SetError("Initializing DirectInput device", ret); } /* Look for haptic devices. */ @@ -183,8 +186,31 @@ SDL_SYS_HapticInit(void) DIEDFL_ATTACHEDONLY); if (FAILED(ret)) { SDL_SYS_HapticQuit(); - DI_SetError("Enumerating DirectInput devices", ret); - return -1; + return DI_SetError("Enumerating DirectInput devices", ret); + } + + if (!env || SDL_atoi(env)) { + loaded_xinput = (WIN_LoadXInputDLL() == 0); + } + + if (loaded_xinput) { + DWORD i; + const SDL_bool bIs14OrLater = (SDL_XInputVersion >= ((1<<16)|4)); + + for (i = 0; (i < SDL_XINPUT_MAX_DEVICES) && (SDL_numhaptics < MAX_HAPTICS); i++) { + XINPUT_CAPABILITIES caps; + if (XINPUTGETCAPABILITIES(i, XINPUT_FLAG_GAMEPAD, &caps) == ERROR_SUCCESS) { + if ((!bIs14OrLater) || (caps.Flags & XINPUT_CAPS_FFB_SUPPORTED)) { + /* !!! FIXME: I'm not bothering to query for a real name right now. */ + char buf[64]; + SDL_snprintf(buf, sizeof (buf), "XInput Controller #%u", i+1); + SDL_hapticlist[SDL_numhaptics].name = SDL_strdup(buf); + SDL_hapticlist[SDL_numhaptics].bXInputHaptic = 1; + SDL_hapticlist[SDL_numhaptics].userid = (Uint8) i; + SDL_numhaptics++; + } + } + } } return SDL_numhaptics; @@ -363,6 +389,41 @@ SDL_SYS_HapticOpenFromInstance(SDL_Haptic * haptic, DIDEVICEINSTANCE instance) return -1; } +static int +SDL_SYS_HapticOpenFromXInput(SDL_Haptic * haptic, Uint8 userid) +{ + XINPUT_VIBRATION vibration = { 0, 0 }; /* stop any current vibration */ + XINPUTSETSTATE(userid, &vibration); + + /* !!! FIXME: we can probably do more than SINE if we figure out how to set up the left and right motors properly. */ + haptic->supported = SDL_HAPTIC_SINE; + + haptic->neffects = 1; + haptic->nplaying = 1; + + /* Prepare effects memory. */ + haptic->effects = (struct haptic_effect *) + SDL_malloc(sizeof(struct haptic_effect) * haptic->neffects); + if (haptic->effects == NULL) { + return SDL_OutOfMemory(); + } + /* Clear the memory */ + SDL_memset(haptic->effects, 0, + sizeof(struct haptic_effect) * haptic->neffects); + + haptic->hwdata = (struct haptic_hwdata *) SDL_malloc(sizeof(*haptic->hwdata)); + if (haptic->hwdata == NULL) { + SDL_free(haptic->effects); + haptic->effects = NULL; + return SDL_OutOfMemory(); + } + SDL_memset(haptic->hwdata, 0, sizeof(*haptic->hwdata)); + + haptic->hwdata->bXInputHaptic = 1; + haptic->hwdata->userid = userid; + + return 0; + } /* * Opens the haptic device from the file descriptor. @@ -504,9 +565,11 @@ SDL_SYS_HapticOpenFromDevice8(SDL_Haptic * haptic, int SDL_SYS_HapticOpen(SDL_Haptic * haptic) { - return SDL_SYS_HapticOpenFromInstance(haptic, - SDL_hapticlist[haptic->index]. - instance); + if (SDL_hapticlist[haptic->index].bXInputHaptic) { + return SDL_SYS_HapticOpenFromXInput(haptic, SDL_hapticlist[haptic->index].userid); + } + + return SDL_SYS_HapticOpenFromInstance(haptic, SDL_hapticlist[haptic->index].instance); } @@ -535,11 +598,9 @@ SDL_SYS_HapticMouse(void) int SDL_SYS_JoystickIsHaptic(SDL_Joystick * joystick) { - if (joystick->hwdata->Capabilities.dwFlags & DIDC_FORCEFEEDBACK) { - return SDL_TRUE; - } - - return SDL_FALSE; + const struct joystick_hwdata *hwdata = joystick->hwdata; + return ( (hwdata->bXInputHaptic) || + ((hwdata->Capabilities.dwFlags & DIDC_FORCEFEEDBACK) != 0) ); } @@ -549,25 +610,30 @@ SDL_SYS_JoystickIsHaptic(SDL_Joystick * joystick) int SDL_SYS_JoystickSameHaptic(SDL_Haptic * haptic, SDL_Joystick * joystick) { - HRESULT ret; - DIDEVICEINSTANCE hap_instance, joy_instance; - hap_instance.dwSize = sizeof(DIDEVICEINSTANCE); - joy_instance.dwSize = sizeof(DIDEVICEINSTANCE); + if ((joystick->hwdata->bXInputHaptic == haptic->hwdata->bXInputHaptic) && (haptic->hwdata->userid == joystick->hwdata->userid)) { + return 1; + } else { + HRESULT ret; + DIDEVICEINSTANCE hap_instance, joy_instance; - /* Get the device instances. */ - ret = IDirectInputDevice8_GetDeviceInfo(haptic->hwdata->device, + hap_instance.dwSize = sizeof(DIDEVICEINSTANCE); + joy_instance.dwSize = sizeof(DIDEVICEINSTANCE); + + /* Get the device instances. */ + ret = IDirectInputDevice8_GetDeviceInfo(haptic->hwdata->device, &hap_instance); - if (FAILED(ret)) { - return 0; - } - ret = IDirectInputDevice8_GetDeviceInfo(joystick->hwdata->InputDevice, - &joy_instance); - if (FAILED(ret)) { - return 0; - } + if (FAILED(ret)) { + return 0; + } + ret = IDirectInputDevice8_GetDeviceInfo(joystick->hwdata->InputDevice, + &joy_instance); + if (FAILED(ret)) { + return 0; + } - if (DI_GUIDIsSame(&hap_instance.guidInstance, &joy_instance.guidInstance)) - return 1; + if (DI_GUIDIsSame(&hap_instance.guidInstance, &joy_instance.guidInstance)) + return 1; + } return 0; } @@ -585,16 +651,27 @@ SDL_SYS_HapticOpenFromJoystick(SDL_Haptic * haptic, SDL_Joystick * joystick) joy_instance.dwSize = sizeof(DIDEVICEINSTANCE); /* Since it comes from a joystick we have to try to match it with a haptic device on our haptic list. */ - for (i=0; i<SDL_numhaptics; i++) { - idret = IDirectInputDevice8_GetDeviceInfo(joystick->hwdata->InputDevice, - &joy_instance); - if (FAILED(idret)) { - return -1; + if (joystick->hwdata->bXInputDevice) { + const Uint8 userid = joystick->hwdata->userid; + for (i=0; i<SDL_numhaptics; i++) { + if ((SDL_hapticlist[i].bXInputHaptic) && (SDL_hapticlist[i].userid == userid)) { + SDL_assert(joystick->hwdata->bXInputHaptic); + haptic->index = i; + break; + } } - if (DI_GUIDIsSame(&SDL_hapticlist[i].instance.guidInstance, - &joy_instance.guidInstance)) { - haptic->index = i; - break; + } else { + for (i=0; i<SDL_numhaptics; i++) { + idret = IDirectInputDevice8_GetDeviceInfo(joystick->hwdata->InputDevice, + &joy_instance); + if (FAILED(idret)) { + return -1; + } + if (DI_GUIDIsSame(&SDL_hapticlist[i].instance.guidInstance, + &joy_instance.guidInstance)) { + haptic->index = i; + break; + } } } if (i >= SDL_numhaptics) { @@ -605,20 +682,22 @@ SDL_SYS_HapticOpenFromJoystick(SDL_Haptic * haptic, SDL_Joystick * joystick) haptic->hwdata = (struct haptic_hwdata *) SDL_malloc(sizeof(*haptic->hwdata)); if (haptic->hwdata == NULL) { - SDL_OutOfMemory(); - return -1; + return SDL_OutOfMemory(); } SDL_memset(haptic->hwdata, 0, sizeof(*haptic->hwdata)); /* Now open the device. */ - ret = - SDL_SYS_HapticOpenFromDevice8(haptic, joystick->hwdata->InputDevice); - if (ret < 0) { - return -1; + if (!joystick->hwdata->bXInputHaptic) { + ret = SDL_SYS_HapticOpenFromDevice8(haptic, joystick->hwdata->InputDevice); + if (ret < 0) { + return -1; + } } /* It's using the joystick device. */ haptic->hwdata->is_joystick = 1; + haptic->hwdata->bXInputHaptic = joystick->hwdata->bXInputHaptic; + haptic->hwdata->userid = joystick->hwdata->userid; return 0; } @@ -638,10 +717,12 @@ SDL_SYS_HapticClose(SDL_Haptic * haptic) haptic->neffects = 0; /* Clean up */ - IDirectInputDevice8_Unacquire(haptic->hwdata->device); - /* Only release if isn't grabbed by a joystick. */ - if (haptic->hwdata->is_joystick == 0) { - IDirectInputDevice8_Release(haptic->hwdata->device); + if (!haptic->hwdata->bXInputHaptic) { + IDirectInputDevice8_Unacquire(haptic->hwdata->device); + /* Only release if isn't grabbed by a joystick. */ + if (haptic->hwdata->is_joystick == 0) { + IDirectInputDevice8_Release(haptic->hwdata->device); + } } /* Free */ @@ -659,6 +740,11 @@ SDL_SYS_HapticQuit(void) { int i; + if (loaded_xinput) { + WIN_UnloadXInputDLL(); + loaded_xinput = SDL_FALSE; + } + for (i = 0; i < SDL_arraysize(SDL_hapticlist); ++i) { if (SDL_hapticlist[i].name) { SDL_free(SDL_hapticlist[i].name); @@ -714,8 +800,7 @@ SDL_SYS_SetDirection(DIEFFECT * effect, SDL_HapticDirection * dir, int naxes) /* Has axes. */ rglDir = SDL_malloc(sizeof(LONG) * naxes); if (rglDir == NULL) { - SDL_OutOfMemory(); - return -1; + return SDL_OutOfMemory(); } SDL_memset(rglDir, 0, sizeof(LONG) * naxes); effect->rglDirection = rglDir; @@ -743,8 +828,7 @@ SDL_SYS_SetDirection(DIEFFECT * effect, SDL_HapticDirection * dir, int naxes) return 0; default: - SDL_SetError("Haptic: Unknown direction type."); - return -1; + return SDL_SetError("Haptic: Unknown direction type."); } } @@ -780,8 +864,7 @@ SDL_SYS_ToDIEFFECT(SDL_Haptic * haptic, DIEFFECT * dest, /* Envelope. */ envelope = SDL_malloc(sizeof(DIENVELOPE)); if (envelope == NULL) { - SDL_OutOfMemory(); - return -1; + return SDL_OutOfMemory(); } SDL_memset(envelope, 0, sizeof(DIENVELOPE)); dest->lpEnvelope = envelope; @@ -792,8 +875,7 @@ SDL_SYS_ToDIEFFECT(SDL_Haptic * haptic, DIEFFECT * dest, if (dest->cAxes > 0) { axes = SDL_malloc(sizeof(DWORD) * dest->cAxes); if (axes == NULL) { - SDL_OutOfMemory(); - return -1; + return SDL_OutOfMemory(); } axes[0] = haptic->hwdata->axes[0]; /* Always at least one axis. */ if (dest->cAxes > 1) { @@ -812,8 +894,7 @@ SDL_SYS_ToDIEFFECT(SDL_Haptic * haptic, DIEFFECT * dest, hap_constant = &src->constant; constant = SDL_malloc(sizeof(DICONSTANTFORCE)); if (constant == NULL) { - SDL_OutOfMemory(); - return -1; + return SDL_OutOfMemory(); } SDL_memset(constant, 0, sizeof(DICONSTANTFORCE)); @@ -856,8 +937,7 @@ SDL_SYS_ToDIEFFECT(SDL_Haptic * haptic, DIEFFECT * dest, hap_periodic = &src->periodic; periodic = SDL_malloc(sizeof(DIPERIODIC)); if (periodic == NULL) { - SDL_OutOfMemory(); - return -1; + return SDL_OutOfMemory(); } SDL_memset(periodic, 0, sizeof(DIPERIODIC)); @@ -902,8 +982,7 @@ SDL_SYS_ToDIEFFECT(SDL_Haptic * haptic, DIEFFECT * dest, hap_condition = &src->condition; condition = SDL_malloc(sizeof(DICONDITION) * dest->cAxes); if (condition == NULL) { - SDL_OutOfMemory(); - return -1; + return SDL_OutOfMemory(); } SDL_memset(condition, 0, sizeof(DICONDITION)); @@ -945,8 +1024,7 @@ SDL_SYS_ToDIEFFECT(SDL_Haptic * haptic, DIEFFECT * dest, hap_ramp = &src->ramp; ramp = SDL_malloc(sizeof(DIRAMPFORCE)); if (ramp == NULL) { - SDL_OutOfMemory(); - return -1; + return SDL_OutOfMemory(); } SDL_memset(ramp, 0, sizeof(DIRAMPFORCE)); @@ -984,8 +1062,7 @@ SDL_SYS_ToDIEFFECT(SDL_Haptic * haptic, DIEFFECT * dest, hap_custom = &src->custom; custom = SDL_malloc(sizeof(DICUSTOMFORCE)); if (custom == NULL) { - SDL_OutOfMemory(); - return -1; + return SDL_OutOfMemory(); } SDL_memset(custom, 0, sizeof(DICUSTOMFORCE)); @@ -1029,8 +1106,7 @@ SDL_SYS_ToDIEFFECT(SDL_Haptic * haptic, DIEFFECT * dest, default: - SDL_SetError("Haptic: Unknown effect type."); - return -1; + return SDL_SetError("Haptic: Unknown effect type."); } return 0; @@ -1127,9 +1203,8 @@ SDL_SYS_HapticNewEffect(SDL_Haptic * haptic, struct haptic_effect *effect, SDL_HapticEffect * base) { HRESULT ret; - - /* Get the type. */ REFGUID type = SDL_SYS_HapticEffectType(base); + if (type == NULL) { goto err_hweffect; } @@ -1142,6 +1217,13 @@ SDL_SYS_HapticNewEffect(SDL_Haptic * haptic, struct haptic_effect *effect, goto err_hweffect; } + SDL_zerop(effect->hweffect); + + if (haptic->hwdata->bXInputHaptic) { + SDL_assert(base->type == SDL_HAPTIC_SINE); /* should catch this at higher level */ + return SDL_SYS_HapticUpdateEffect(haptic, effect, base); + } + /* Get the effect. */ if (SDL_SYS_ToDIEFFECT(haptic, &effect->hweffect->effect, base) < 0) { goto err_effectdone; @@ -1181,6 +1263,23 @@ SDL_SYS_HapticUpdateEffect(SDL_Haptic * haptic, DWORD flags; DIEFFECT temp; + if (haptic->hwdata->bXInputHaptic) { + // !!! FIXME: this isn't close to right. We only support "sine" effects, + // !!! FIXME: we ignore most of the parameters, and we probably get + // !!! FIXME: the ones we don't ignore wrong, too. + // !!! FIXME: if I had a better understanding of how the two motors + // !!! FIXME: could be used in unison, perhaps I could implement other + // !!! FIXME: effect types? + /* From MSDN: + "Note that the right motor is the high-frequency motor, the left + motor is the low-frequency motor. They do not always need to be + set to the same amount, as they provide different effects." */ + XINPUT_VIBRATION *vib = &effect->hweffect->vibration; + SDL_assert(data->type == SDL_HAPTIC_SINE); + vib->wLeftMotorSpeed = vib->wRightMotorSpeed = data->periodic.magnitude * 2; + return 0; + } + /* Get the effect. */ SDL_memset(&temp, 0, sizeof(DIEFFECT)); if (SDL_SYS_ToDIEFFECT(haptic, &temp, data) < 0) { @@ -1226,6 +1325,11 @@ SDL_SYS_HapticRunEffect(SDL_Haptic * haptic, struct haptic_effect *effect, HRESULT ret; DWORD iter; + if (haptic->hwdata->bXInputHaptic) { + XINPUT_VIBRATION *vib = &effect->hweffect->vibration; + return (XINPUTSETSTATE(haptic->hwdata->userid, vib) == ERROR_SUCCESS); + } + /* Check if it's infinite. */ if (iterations == SDL_HAPTIC_INFINITY) { iter = INFINITE; @@ -1235,8 +1339,7 @@ SDL_SYS_HapticRunEffect(SDL_Haptic * haptic, struct haptic_effect *effect, /* Run the effect. */ ret = IDirectInputEffect_Start(effect->hweffect->ref, iter, 0); if (FAILED(ret)) { - DI_SetError("Running the effect", ret); - return -1; + return DI_SetError("Running the effect", ret); } return 0; @@ -1251,10 +1354,14 @@ SDL_SYS_HapticStopEffect(SDL_Haptic * haptic, struct haptic_effect *effect) { HRESULT ret; + if (haptic->hwdata->bXInputHaptic) { + XINPUT_VIBRATION vibration = { 0, 0 }; + return (XINPUTSETSTATE(haptic->hwdata->userid, &vibration) == ERROR_SUCCESS); + } + ret = IDirectInputEffect_Stop(effect->hweffect->ref); if (FAILED(ret)) { - DI_SetError("Unable to stop effect", ret); - return -1; + return DI_SetError("Unable to stop effect", ret); } return 0; @@ -1269,12 +1376,16 @@ SDL_SYS_HapticDestroyEffect(SDL_Haptic * haptic, struct haptic_effect *effect) { HRESULT ret; - ret = IDirectInputEffect_Unload(effect->hweffect->ref); - if (FAILED(ret)) { - DI_SetError("Removing effect from the device", ret); + if (haptic->hwdata->bXInputHaptic) { + SDL_SYS_HapticStopEffect(haptic, effect); + } else { + ret = IDirectInputEffect_Unload(effect->hweffect->ref); + if (FAILED(ret)) { + DI_SetError("Removing effect from the device", ret); + } + SDL_SYS_HapticFreeDIEFFECT(&effect->hweffect->effect, + effect->effect.type); } - SDL_SYS_HapticFreeDIEFFECT(&effect->hweffect->effect, - effect->effect.type); SDL_free(effect->hweffect); effect->hweffect = NULL; } @@ -1292,8 +1403,7 @@ SDL_SYS_HapticGetEffectStatus(SDL_Haptic * haptic, ret = IDirectInputEffect_GetEffectStatus(effect->hweffect->ref, &status); if (FAILED(ret)) { - DI_SetError("Getting effect status", ret); - return -1; + return DI_SetError("Getting effect status", ret); } if (status == 0) @@ -1322,8 +1432,7 @@ SDL_SYS_HapticSetGain(SDL_Haptic * haptic, int gain) ret = IDirectInputDevice8_SetProperty(haptic->hwdata->device, DIPROP_FFGAIN, &dipdw.diph); if (FAILED(ret)) { - DI_SetError("Setting gain", ret); - return -1; + return DI_SetError("Setting gain", ret); } return 0; @@ -1351,8 +1460,7 @@ SDL_SYS_HapticSetAutocenter(SDL_Haptic * haptic, int autocenter) ret = IDirectInputDevice8_SetProperty(haptic->hwdata->device, DIPROP_AUTOCENTER, &dipdw.diph); if (FAILED(ret)) { - DI_SetError("Setting autocenter", ret); - return -1; + return DI_SetError("Setting autocenter", ret); } return 0; @@ -1371,8 +1479,7 @@ SDL_SYS_HapticPause(SDL_Haptic * haptic) ret = IDirectInputDevice8_SendForceFeedbackCommand(haptic->hwdata->device, DISFFC_PAUSE); if (FAILED(ret)) { - DI_SetError("Pausing the device", ret); - return -1; + return DI_SetError("Pausing the device", ret); } return 0; @@ -1391,8 +1498,7 @@ SDL_SYS_HapticUnpause(SDL_Haptic * haptic) ret = IDirectInputDevice8_SendForceFeedbackCommand(haptic->hwdata->device, DISFFC_CONTINUE); if (FAILED(ret)) { - DI_SetError("Pausing the device", ret); - return -1; + return DI_SetError("Pausing the device", ret); } return 0; @@ -1407,12 +1513,16 @@ SDL_SYS_HapticStopAll(SDL_Haptic * haptic) { HRESULT ret; + if (haptic->hwdata->bXInputHaptic) { + XINPUT_VIBRATION vibration = { 0, 0 }; + return (XINPUTSETSTATE(haptic->hwdata->userid, &vibration) == ERROR_SUCCESS); + } + /* Try to stop the effects. */ ret = IDirectInputDevice8_SendForceFeedbackCommand(haptic->hwdata->device, DISFFC_STOPALL); if (FAILED(ret)) { - DI_SetError("Stopping the device", ret); - return -1; + return DI_SetError("Stopping the device", ret); } return 0; diff --git a/src/joystick/SDL_gamecontroller.c b/src/joystick/SDL_gamecontroller.c index d7d170a53b..a5e388f545 100644 --- a/src/joystick/SDL_gamecontroller.c +++ b/src/joystick/SDL_gamecontroller.c @@ -45,8 +45,10 @@ struct _SDL_HatMapping #define k_nMaxReverseEntries 20 -// We are encoding the "HAT" as 0xhm. where h == hat ID and m == mask -// MAX 4 hats supported +/** + * We are encoding the "HAT" as 0xhm. where h == hat ID and m == mask + * MAX 4 hats supported + */ #define k_nMaxHatEntries 0x3f + 1 /* our in memory mapping db between joystick objects and controller mappings*/ @@ -64,12 +66,12 @@ struct _SDL_ControllerMapping struct _SDL_HatMapping hatasbutton[SDL_CONTROLLER_BUTTON_MAX]; // reverse mapping, joystick indices to buttons - SDL_CONTROLLER_AXIS raxes[k_nMaxReverseEntries]; - SDL_CONTROLLER_AXIS rbuttonasaxis[k_nMaxReverseEntries]; + SDL_GameControllerAxis raxes[k_nMaxReverseEntries]; + SDL_GameControllerAxis rbuttonasaxis[k_nMaxReverseEntries]; - SDL_CONTROLLER_BUTTON rbuttons[k_nMaxReverseEntries]; - SDL_CONTROLLER_BUTTON raxesasbutton[k_nMaxReverseEntries]; - SDL_CONTROLLER_BUTTON rhatasbutton[k_nMaxHatEntries]; + SDL_GameControllerButton rbuttons[k_nMaxReverseEntries]; + SDL_GameControllerButton raxesasbutton[k_nMaxReverseEntries]; + SDL_GameControllerButton rhatasbutton[k_nMaxHatEntries]; }; @@ -79,7 +81,7 @@ typedef struct _ControllerMapping_t { SDL_JoystickGUID guid; char *name; - const char *mapping; + char *mapping; struct _ControllerMapping_t *next; } ControllerMapping_t; @@ -90,13 +92,28 @@ const char *s_ControllerMappings [] = #ifdef SDL_JOYSTICK_DINPUT "xinput,X360 Controller,a:b10,b:b11,y:b13,x:b12,start:b4,guide:b14,back:b5,dpup:b0,dpleft:b2,dpdown:b1,dpright:b3,leftshoulder:b8,rightshoulder:b9,leftstick:b6,rightstick:b7,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:a4,righttrigger:a5", "341a3608000000000000504944564944,Afterglow PS3 Controller,a:b1,b:b2,y:b3,x:b0,start:b9,guide:b12,back:b8,dpup:h0.1,dpleft:h0.8,dpdown:h0.4,dpright:h0.2,leftshoulder:b4,rightshoulder:b5,leftstick:b10,rightstick:b11,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:b6,righttrigger:b7", - "88880803000000000000504944564944,PS3,a:b2,b:b1,x:b0,y:b3,start:b11,back:b8,leftstick:b9,rightstick:b10,leftshoulder:b4,rightshoulder:b5,dpup:h0.1,dpleft:h0.4,dpdown:h0.8,dpright:h0.2,leftx:a0,lefty:a1,rightx:a3,righty:a4,lefttrigger:b6,righttrigger:b7,guide:b12", + "88880803000000000000504944564944,PS3 Controller,a:b2,b:b1,x:b0,y:b3,start:b11,back:b8,leftstick:b9,rightstick:b10,leftshoulder:b4,rightshoulder:b5,dpup:h0.1,dpleft:h0.4,dpdown:h0.8,dpright:h0.2,leftx:a0,lefty:a1,rightx:a3,righty:a4,lefttrigger:b6,righttrigger:b7,guide:b12", + "4c056802000000000000504944564944,PS3 Controller,a:b14,b:b13,y:b12,x:b15,start:b3,guide:b16,back:b0,leftstick:b1,rightstick:b2,leftshoulder:b10,rightshoulder:b11,dpup:b4,dpleft:b7,dpdown:b6,dpright:b5,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:b8,righttrigger:b9,", "25090500000000000000504944564944,PS3 DualShock,a:b2,b:b1,x:b0,y:b3,start:b8,guide:,back:b9,leftstick:b10,rightstick:b11,leftshoulder:b6,rightshoulder:b7,dpup:h0.1,dpleft:h0.4,dpdown:h0.8,dpright:h0.2,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:b4,righttrigger:b5", + "ffff0000000000000000504944564944,GameStop Gamepad,a:b0,b:b1,y:b3,x:b2,start:b9,guide:,back:b8,leftstick:b10,rightstick:b11,leftshoulder:b4,rightshoulder:b5,dpup:h0.1,dpleft:h0.8,dpdown:h0.4,dpright:h0.2,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:b6,righttrigger:b7,", + "6d0416c2000000000000504944564944,Generic DirectInput Controller,a:b1,b:b2,y:b3,x:b0,start:b9,back:b8,leftstick:b10,rightstick:b11,leftshoulder:b4,rightshoulder:b5,dpup:h0.1,dpleft:h0.8,dpdown:h0.4,dpright:h0.2,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:b6,righttrigger:b7,", #elif defined(__MACOSX__) "5e040000000000008e02000000000000,X360 Controller,a:b0,b:b1,y:b3,x:b2,start:b8,guide:b10,back:b9,dpup:b11,dpleft:b13,dpdown:b12,dpright:b14,leftshoulder:b4,rightshoulder:b5,leftstick:b6,rightstick:b7,leftx:a0,lefty:a1,rightx:a3,righty:a4,lefttrigger:a2,righttrigger:a5", "4c050000000000006802000000000000,PS3 Controller,a:b14,b:b13,x:b12,y:b15,start:b3,guide:b16,back:b0,leftstick:b1,rightstick:b2,leftshoulder:b10,rightshoulder:b11,dpup:b4,dpleft:b6,dpdown:b7,dpright:b5,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:b8,righttrigger:b9", + "0500000047532047616d657061640000,GameStop Gamepad,a:b0,b:b1,y:b3,x:b2,start:b9,guide:,back:b8,leftstick:b10,rightstick:b11,leftshoulder:b4,rightshoulder:b5,dpup:h0.1,dpleft:h0.8,dpdown:h0.4,dpright:h0.2,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:b6,righttrigger:b7,", + "6d040000000000001fc2000000000000,Logitech F710 Gamepad Controller (XInput),a:b0,b:b1,y:b3,x:b2,start:b8,guide:b10,back:b9,leftstick:b6,rightstick:b7,leftshoulder:b4,rightshoulder:b5,dpup:b11,dpleft:b13,dpdown:b12,dpright:b14,leftx:a0,lefty:a1,rightx:a3,righty:a4,lefttrigger:a2,righttrigger:a5,", + "6d0400000000000016c2000000000000,Logitech F310 Gamepad Controller (DInput),a:b1,b:b2,y:b3,x:b0,start:b9,back:b8,leftstick:b10,rightstick:b11,leftshoulder:b4,rightshoulder:b5,dpup:h0.1,dpleft:h0.8,dpdown:h0.4,dpright:h0.2,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:b6,righttrigger:b7,", // Guide button doesn't seem to be sent in DInput mode. + "6d0400000000000019c2000000000000,Logitech Wireless Gamepad Controller (DInput),a:b1,b:b2,y:b3,x:b0,start:b9,back:b8,leftstick:b10,rightstick:b11,leftshoulder:b4,rightshoulder:b5,dpup:h0.1,dpleft:h0.8,dpdown:h0.4,dpright:h0.2,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:b6,righttrigger:b7,", // This includes F710 in DInput mode and the "Logitech Cordless RumblePad 2", at the very least. #elif defined(__LINUX__) - + "030000005e0400008e02000014010000,X360 Controller,a:b0,b:b1,y:b3,x:b2,start:b7,guide:b8,back:b6,dpup:h0.1,dpleft:h0.8,dpdown:h0.4,dpright:h0.2,leftshoulder:b4,rightshoulder:b5,leftstick:b9,rightstick:b10,leftx:a0,lefty:a1,rightx:a3,righty:a4,lefttrigger:a2,righttrigger:a5", + "030000005e0400008e02000010010000,X360 Controller,a:b0,b:b1,y:b3,x:b2,start:b7,guide:b8,back:b6,leftstick:b9,rightstick:b10,leftshoulder:b4,rightshoulder:b5,dpup:h0.1,dpleft:h0.8,dpdown:h0.4,dpright:h0.2,leftx:a0,lefty:a1,rightx:a3,righty:a4,lefttrigger:a2,righttrigger:a5,", + "030000005e0400001907000000010000,X360 Wireless Controller,a:b0,b:b1,y:b3,x:b2,start:b7,guide:b8,back:b6,leftstick:b9,rightstick:b10,leftshoulder:b4,rightshoulder:b5,dpup:b13,dpleft:b11,dpdown:b14,dpright:b12,leftx:a0,lefty:a1,rightx:a3,righty:a4,lefttrigger:a2,righttrigger:a5,", + "030000004c0500006802000011010000,PS3 Controller,a:b14,b:b13,x:b15,y:b12,start:b3,guide:b16,back:b0,leftstick:b1,rightstick:b2,leftshoulder:b10,rightshoulder:b11,dpup:b4,dpleft:b7,dpdown:b6,dpright:b5,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:b8,righttrigger:b9", + "030000006d0400001fc2000005030000,Logitech F710 Gamepad Controller (XInput),a:b0,b:b1,y:b3,x:b2,start:b7,guide:b8,back:b6,leftstick:b9,rightstick:b10,leftshoulder:b4,rightshoulder:b5,dpup:h0.1,dpleft:h0.8,dpdown:h0.4,dpright:h0.2,leftx:a0,lefty:a1,rightx:a3,righty:a4,lefttrigger:a2,righttrigger:a5,", + "030000006d04000019c2000011010000,Logitech F710 Gamepad Controller (DInput),a:b1,b:b2,y:b3,x:b0,start:b9,back:b8,leftstick:b10,rightstick:b11,leftshoulder:b4,rightshoulder:b5,dpup:h0.1,dpleft:h0.8,dpdown:h0.4,dpright:h0.2,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:b6,righttrigger:b7,", // Guide button doesn't seem to be sent in DInput mode. + "030000006d0400001dc2000014400000,Logitech F310 Gamepad (XInput),a:b0,b:b1,y:b3,x:b2,start:b7,guide:b8,back:b6,leftstick:b9,rightstick:b10,leftshoulder:b4,rightshoulder:b5,dpup:h0.1,dpleft:h0.8,dpdown:h0.4,dpright:h0.2,leftx:a0,lefty:a1,rightx:a3,righty:a4,lefttrigger:a2,righttrigger:a5,", + "030000006d04000019c2000010010000,Logitech Cordless RumblePad 2,a:b1,b:b2,y:b3,x:b0,start:b9,guide:,back:b8,leftstick:b10,rightstick:b11,leftshoulder:b4,rightshoulder:b5,dpup:h0.1,dpleft:h0.8,dpdown:h0.4,dpright:h0.2,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:b6,righttrigger:b7,", + "0500000047532047616d657061640000,GameStop Gamepad,a:b0,b:b1,y:b3,x:b2,start:b9,guide:,back:b8,leftstick:b10,rightstick:b11,leftshoulder:b4,rightshoulder:b5,dpup:h0.1,dpleft:h0.8,dpdown:h0.4,dpright:h0.2,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:b6,righttrigger:b7,", #endif NULL }; @@ -117,8 +134,8 @@ struct _SDL_GameController }; -int SDL_PrivateGameControllerAxis(SDL_GameController * gamecontroller, SDL_CONTROLLER_AXIS axis, Sint16 value); -int SDL_PrivateGameControllerButton(SDL_GameController * gamecontroller, SDL_CONTROLLER_BUTTON button, Uint8 state); +int SDL_PrivateGameControllerAxis(SDL_GameController * gamecontroller, SDL_GameControllerAxis axis, Sint16 value); +int SDL_PrivateGameControllerButton(SDL_GameController * gamecontroller, SDL_GameControllerButton button, Uint8 state); /* * Event filter to fire controller events from joystick ones @@ -261,14 +278,27 @@ int SDL_GameControllerEventWatcher(void *userdata, SDL_Event * event) } /* - * Helper function to determine pre-caclulated offset to certain joystick mappings + * Helper function to scan the mappings database for a controller with the specified GUID */ -ControllerMapping_t *SDL_PrivateGetControllerMapping(int device_index) +ControllerMapping_t *SDL_PrivateGetControllerMappingForGUID(SDL_JoystickGUID *guid) { - if ( (device_index < 0) || (device_index >= SDL_NumJoysticks()) ) { + ControllerMapping_t *pSupportedController = s_pSupportedControllers; + while ( pSupportedController ) + { + if ( !SDL_memcmp( guid, &pSupportedController->guid, sizeof(*guid) ) ) + { + return pSupportedController; + } + pSupportedController = pSupportedController->next; + } return NULL; } +/* + * Helper function to determine pre-caclulated offset to certain joystick mappings + */ +ControllerMapping_t *SDL_PrivateGetControllerMapping(int device_index) +{ #ifdef SDL_JOYSTICK_DINPUT if ( SDL_SYS_IsXInputDeviceIndex(device_index) && s_pXInputMapping ) { @@ -278,87 +308,98 @@ ControllerMapping_t *SDL_PrivateGetControllerMapping(int device_index) #endif { SDL_JoystickGUID jGUID = SDL_JoystickGetDeviceGUID( device_index ); - ControllerMapping_t *pSupportedController = s_pSupportedControllers; - while ( pSupportedController ) - { - if ( !SDL_memcmp( &jGUID, &pSupportedController->guid, sizeof(jGUID) ) ) - { - return pSupportedController; - } - pSupportedController = pSupportedController->next; - } + return SDL_PrivateGetControllerMappingForGUID(&jGUID); } return NULL; } +static const char* map_StringForControllerAxis[] = { + "leftx", + "lefty", + "rightx", + "righty", + "lefttrigger", + "righttrigger", + NULL +}; + /* * convert a string to its enum equivalent */ -SDL_CONTROLLER_AXIS SDL_GameControllerGetAxisFromString( const char *pchString ) +SDL_GameControllerAxis SDL_GameControllerGetAxisFromString( const char *pchString ) { + int entry; if ( !pchString || !pchString[0] ) return SDL_CONTROLLER_AXIS_INVALID; - if ( !SDL_strcasecmp( pchString, "leftx" ) ) - return SDL_CONTROLLER_AXIS_LEFTX; - else if ( !SDL_strcasecmp( pchString, "lefty" ) ) - return SDL_CONTROLLER_AXIS_LEFTY; - else if ( !SDL_strcasecmp( pchString, "rightx" ) ) - return SDL_CONTROLLER_AXIS_RIGHTX; - else if ( !SDL_strcasecmp( pchString, "righty" ) ) - return SDL_CONTROLLER_AXIS_RIGHTY; - else if ( !SDL_strcasecmp( pchString, "lefttrigger" ) ) - return SDL_CONTROLLER_AXIS_TRIGGERLEFT; - else if ( !SDL_strcasecmp( pchString, "righttrigger" ) ) - return SDL_CONTROLLER_AXIS_TRIGGERRIGHT; - else + for ( entry = 0; map_StringForControllerAxis[entry]; ++entry) + { + if ( !SDL_strcasecmp( pchString, map_StringForControllerAxis[entry] ) ) + return entry; + } return SDL_CONTROLLER_AXIS_INVALID; } +/* + * convert an enum to its string equivalent + */ +const char* SDL_GameControllerGetStringForAxis( SDL_GameControllerAxis axis ) +{ + if (axis > SDL_CONTROLLER_AXIS_INVALID && axis < SDL_CONTROLLER_AXIS_MAX) + { + return map_StringForControllerAxis[axis]; + } + return NULL; +} + +static const char* map_StringForControllerButton[] = { + "a", + "b", + "x", + "y", + "back", + "guide", + "start", + "leftstick", + "rightstick", + "leftshoulder", + "rightshoulder", + "dpup", + "dpdown", + "dpleft", + "dpright", + NULL +}; /* * convert a string to its enum equivalent */ -SDL_CONTROLLER_BUTTON SDL_GameControllerGetButtonFromString( const char *pchString ) +SDL_GameControllerButton SDL_GameControllerGetButtonFromString( const char *pchString ) { + int entry; if ( !pchString || !pchString[0] ) return SDL_CONTROLLER_BUTTON_INVALID; - if ( !SDL_strcasecmp( pchString, "a" ) ) - return SDL_CONTROLLER_BUTTON_A; - else if ( !SDL_strcasecmp( pchString, "b" ) ) - return SDL_CONTROLLER_BUTTON_B; - else if ( !SDL_strcasecmp( pchString, "x" ) ) - return SDL_CONTROLLER_BUTTON_X; - else if ( !SDL_strcasecmp( pchString, "y" ) ) - return SDL_CONTROLLER_BUTTON_Y; - else if ( !SDL_strcasecmp( pchString, "start" ) ) - return SDL_CONTROLLER_BUTTON_START; - else if ( !SDL_strcasecmp( pchString, "guide" ) ) - return SDL_CONTROLLER_BUTTON_GUIDE; - else if ( !SDL_strcasecmp( pchString, "back" ) ) - return SDL_CONTROLLER_BUTTON_BACK; - else if ( !SDL_strcasecmp( pchString, "dpup" ) ) - return SDL_CONTROLLER_BUTTON_DPAD_UP; - else if ( !SDL_strcasecmp( pchString, "dpdown" ) ) - return SDL_CONTROLLER_BUTTON_DPAD_DOWN; - else if ( !SDL_strcasecmp( pchString, "dpleft" ) ) - return SDL_CONTROLLER_BUTTON_DPAD_LEFT; - else if ( !SDL_strcasecmp( pchString, "dpright" ) ) - return SDL_CONTROLLER_BUTTON_DPAD_RIGHT; - else if ( !SDL_strcasecmp( pchString, "leftshoulder" ) ) - return SDL_CONTROLLER_BUTTON_LEFTSHOULDER; - else if ( !SDL_strcasecmp( pchString, "rightshoulder" ) ) - return SDL_CONTROLLER_BUTTON_RIGHTSHOULDER; - else if ( !SDL_strcasecmp( pchString, "leftstick" ) ) - return SDL_CONTROLLER_BUTTON_LEFTSTICK; - else if ( !SDL_strcasecmp( pchString, "rightstick" ) ) - return SDL_CONTROLLER_BUTTON_RIGHTSTICK; - else - return SDL_CONTROLLER_BUTTON_INVALID; + for ( entry = 0; map_StringForControllerButton[entry]; ++entry) + { + if ( !SDL_strcasecmp( pchString, map_StringForControllerButton[entry] ) ) + return entry; + } + return SDL_CONTROLLER_BUTTON_INVALID; } +/* + * convert an enum to its string equivalent + */ +const char* SDL_GameControllerGetStringForButton( SDL_GameControllerButton axis ) +{ + if (axis > SDL_CONTROLLER_BUTTON_INVALID && axis < SDL_CONTROLLER_BUTTON_MAX) + { + return map_StringForControllerButton[axis]; + } + return NULL; +} /* * given a controller button name and a joystick name update our mapping structure with it @@ -366,8 +407,8 @@ SDL_CONTROLLER_BUTTON SDL_GameControllerGetButtonFromString( const char *pchStri void SDL_PrivateGameControllerParseButton( const char *szGameButton, const char *szJoystickButton, struct _SDL_ControllerMapping *pMapping ) { int iSDLButton = 0; - SDL_CONTROLLER_BUTTON button; - SDL_CONTROLLER_AXIS axis; + SDL_GameControllerButton button; + SDL_GameControllerAxis axis; button = SDL_GameControllerGetButtonFromString( szGameButton ); axis = SDL_GameControllerGetAxisFromString( szGameButton ); iSDLButton = SDL_atoi( &szJoystickButton[1] ); @@ -435,7 +476,7 @@ void SDL_PrivateGameControllerParseButton( const char *szGameButton, const char } else if ( axis != SDL_CONTROLLER_AXIS_INVALID ) { - SDL_assert( !"Support has as axis" ); + SDL_assert( !"Support hat as axis" ); } else { @@ -601,7 +642,7 @@ char *SDL_PrivateGetControllerNameFromMappingString( const char *pMapping ) /* * grab the button mapping string from a mapping string */ -const char *SDL_PrivateGetControllerMappingFromMappingString( const char *pMapping ) +char *SDL_PrivateGetControllerMappingFromMappingString( const char *pMapping ) { const char *pFirstComma, *pSecondComma; @@ -613,116 +654,178 @@ const char *SDL_PrivateGetControllerMappingFromMappingString( const char *pMappi if ( !pSecondComma ) return NULL; - return pSecondComma + 1; /* mapping is everything after the 3rd comma, no need to malloc it */ + return SDL_strdup(pSecondComma + 1); /* mapping is everything after the 3rd comma */ } +void SDL_PrivateGameControllerRefreshMapping( ControllerMapping_t *pControllerMapping ) +{ + SDL_GameController *gamecontrollerlist = SDL_gamecontrollers; + while ( gamecontrollerlist ) + { + if ( !SDL_memcmp( &gamecontrollerlist->mapping.guid, &pControllerMapping->guid, sizeof(pControllerMapping->guid) ) ) + { + SDL_Event event; + event.type = SDL_CONTROLLERDEVICEREMAPPED; + event.cdevice.which = gamecontrollerlist->joystick->instance_id; + SDL_PushEvent(&event); + + // Not really threadsafe. Should this lock access within SDL_GameControllerEventWatcher? + SDL_PrivateLoadButtonMapping(&gamecontrollerlist->mapping, pControllerMapping->guid, pControllerMapping->name, pControllerMapping->mapping); + } + + gamecontrollerlist = gamecontrollerlist->next; + } +} /* - * Initialize the game controller system, mostly load our DB of controller config mappings + * Add or update an entry into the Mappings Database */ int -SDL_GameControllerInit(void) +SDL_GameControllerAddMapping( const char *mappingString ) { - int i = 0; - const char *pMappingString = NULL; - s_pSupportedControllers = NULL; - pMappingString = s_ControllerMappings[i]; - while ( pMappingString ) - { - ControllerMapping_t *pControllerMapping; - char *pchGUID; - char *pchName; - const char *pchMapping; - pControllerMapping = SDL_malloc( sizeof(*pControllerMapping) ); - if ( !pControllerMapping ) - { - SDL_OutOfMemory(); - return -1; - } + char *pchGUID; + char *pchName; + char *pchMapping; + SDL_JoystickGUID jGUID; + ControllerMapping_t *pControllerMapping; +#ifdef SDL_JOYSTICK_DINPUT + SDL_bool is_xinput_mapping = SDL_FALSE; +#endif - pchGUID = SDL_PrivateGetControllerGUIDFromMappingString( pMappingString ); - pchName = SDL_PrivateGetControllerNameFromMappingString( pMappingString ); - pchMapping = SDL_PrivateGetControllerMappingFromMappingString( pMappingString ); - if ( pchGUID && pchName ) - { + pchGUID = SDL_PrivateGetControllerGUIDFromMappingString( mappingString ); + if (!pchGUID) { + return -1; + } #ifdef SDL_JOYSTICK_DINPUT - if ( !SDL_strcasecmp( pchGUID, "xinput" ) ) - { - s_pXInputMapping = pControllerMapping; - } + if ( !SDL_strcasecmp( pchGUID, "xinput" ) ) { + is_xinput_mapping = SDL_TRUE; + } #endif - pControllerMapping->guid = SDL_JoystickGetGUIDFromString( pchGUID ); - pControllerMapping->name = pchName; - pControllerMapping->mapping = pchMapping; - pControllerMapping->next = s_pSupportedControllers; - s_pSupportedControllers = pControllerMapping; + jGUID = SDL_JoystickGetGUIDFromString(pchGUID); + SDL_free(pchGUID); - SDL_free( pchGUID ); - } + pControllerMapping = SDL_PrivateGetControllerMappingForGUID(&jGUID); - i++; - pMappingString = s_ControllerMappings[i]; + pchName = SDL_PrivateGetControllerNameFromMappingString( mappingString ); + if (!pchName) return -1; + + pchMapping = SDL_PrivateGetControllerMappingFromMappingString( mappingString ); + if (!pchMapping) { + SDL_free( pchName ); + return -1; } - // load in any user supplied config - { - const char *hint = SDL_GetHint(SDL_HINT_GAMECONTROLLERCONFIG); - if ( hint && hint[0] ) + if (pControllerMapping) { + // Update existing mapping + SDL_free( pControllerMapping->name ); + pControllerMapping->name = pchName; + SDL_free( pControllerMapping->mapping ); + pControllerMapping->mapping = pchMapping; + // refresh open controllers + SDL_PrivateGameControllerRefreshMapping( pControllerMapping ); + return 0; + } else { + pControllerMapping = SDL_malloc( sizeof(*pControllerMapping) ); + if (!pControllerMapping) { + SDL_free( pchName ); + SDL_free( pchMapping ); + return SDL_OutOfMemory(); + } +#ifdef SDL_JOYSTICK_DINPUT + if ( is_xinput_mapping ) { - int nchHints = SDL_strlen( hint ); - char *pUserMappings = SDL_malloc( nchHints + 1 ); /* FIXME: memory leak, but we can't free it in this function because pchMapping below points into this memory */ - SDL_memcpy( pUserMappings, hint, nchHints + 1 ); - while ( pUserMappings ) - { - char *pchGUID; - char *pchName; - const char *pchMapping; - char *pchNewLine = NULL; - ControllerMapping_t *pControllerMapping; - - pchNewLine = SDL_strchr( pUserMappings, '\n' ); - if ( pchNewLine ) - *pchNewLine = '\0'; - - pControllerMapping = SDL_malloc( sizeof(*pControllerMapping) ); - if ( !pControllerMapping ) - { - SDL_OutOfMemory(); - return -1; - } + s_pXInputMapping = pControllerMapping; + } +#endif + pControllerMapping->guid = jGUID; + pControllerMapping->name = pchName; + pControllerMapping->mapping = pchMapping; + pControllerMapping->next = s_pSupportedControllers; + s_pSupportedControllers = pControllerMapping; + return 1; + } +} - pchGUID = SDL_PrivateGetControllerGUIDFromMappingString( pUserMappings ); - pchName = SDL_PrivateGetControllerNameFromMappingString( pUserMappings ); - pchMapping = SDL_PrivateGetControllerMappingFromMappingString( pUserMappings ); +/* + * Get the mapping string for this GUID + */ +char * +SDL_GameControllerMappingForGUID( SDL_JoystickGUID guid ) +{ + char *pMappingString = NULL; + ControllerMapping_t *mapping = SDL_PrivateGetControllerMappingForGUID(&guid); + if (mapping) { + char pchGUID[33]; + size_t needed; + SDL_JoystickGetGUIDString(guid, pchGUID, sizeof(pchGUID)); + // allocate enough memory for GUID + ',' + name + ',' + mapping + \0 + needed = SDL_strlen(pchGUID) + 1 + SDL_strlen(mapping->name) + 1 + SDL_strlen(mapping->mapping) + 1; + pMappingString = SDL_malloc( needed ); + SDL_snprintf( pMappingString, needed, "%s,%s,%s", pchGUID, mapping->name, mapping->mapping ); + } + return pMappingString; +} - if ( pchGUID && pchName ) - { -#ifdef SDL_JOYSTICK_DINPUT - if ( !SDL_strcasecmp( pchGUID, "xinput" ) ) - { - s_pXInputMapping = pControllerMapping; - } -#endif +/* + * Get the mapping string for this device + */ +char * +SDL_GameControllerMapping( SDL_GameController * gamecontroller ) +{ + return SDL_GameControllerMappingForGUID( gamecontroller->mapping.guid ); +} - pControllerMapping->guid = SDL_JoystickGetGUIDFromString( pchGUID ); - pControllerMapping->name = pchName; - pControllerMapping->mapping = pchMapping; - pControllerMapping->next = s_pSupportedControllers; - s_pSupportedControllers = pControllerMapping; +static void +SDL_GameControllerLoadHints() +{ + const char *hint = SDL_GetHint(SDL_HINT_GAMECONTROLLERCONFIG); + if ( hint && hint[0] ) { + int nchHints = SDL_strlen( hint ); + char *pUserMappings = SDL_malloc( nchHints + 1 ); + char *pTempMappings = pUserMappings; + SDL_memcpy( pUserMappings, hint, nchHints ); + while ( pUserMappings ) { + char *pchNewLine = NULL; + + pchNewLine = SDL_strchr( pUserMappings, '\n' ); + if ( pchNewLine ) + *pchNewLine = '\0'; + + SDL_GameControllerAddMapping( pUserMappings ); + + if ( pchNewLine ) + pUserMappings = pchNewLine + 1; + else + pUserMappings = NULL; + } + SDL_free(pTempMappings); + } +} - SDL_free( pchGUID ); - } +/* + * Initialize the game controller system, mostly load our DB of controller config mappings + */ +int +SDL_GameControllerInit(void) +{ + int i = 0; + const char *pMappingString = NULL; + s_pSupportedControllers = NULL; + pMappingString = s_ControllerMappings[i]; + while ( pMappingString ) + { + SDL_GameControllerAddMapping( pMappingString ); - if ( pchNewLine ) - pUserMappings = pchNewLine + 1; - else - pUserMappings = NULL; - } - } + i++; + pMappingString = s_ControllerMappings[i]; } + // load in any user supplied config + SDL_GameControllerLoadHints(); + /* watch for joy events and fire controller ones if needed */ SDL_AddEventWatch( SDL_GameControllerEventWatcher, NULL ); + return (0); } @@ -788,10 +891,9 @@ SDL_GameControllerOpen(int device_index) gamecontrollerlist = gamecontrollerlist->next; } - // Find a Controller Mapping + // Find a controller mapping pSupportedController = SDL_PrivateGetControllerMapping(device_index); - if ( !pSupportedController ) - { + if ( !pSupportedController ) { SDL_SetError("Couldn't find mapping for device (%d)", device_index ); return (NULL); } @@ -823,12 +925,22 @@ SDL_GameControllerOpen(int device_index) return (gamecontroller); } +/* + * Manually pump for controller updates. + */ +void +SDL_GameControllerUpdate(void) +{ + /* Just for API completeness; the joystick API does all the work. */ + SDL_JoystickUpdate(); +} + /* * Get the current state of an axis control on a controller */ Sint16 -SDL_GameControllerGetAxis(SDL_GameController * gamecontroller, SDL_CONTROLLER_AXIS axis) +SDL_GameControllerGetAxis(SDL_GameController * gamecontroller, SDL_GameControllerAxis axis) { if ( !gamecontroller ) return 0; @@ -853,7 +965,7 @@ SDL_GameControllerGetAxis(SDL_GameController * gamecontroller, SDL_CONTROLLER_AX * Get the current state of a button on a controller */ Uint8 -SDL_GameControllerGetButton(SDL_GameController * gamecontroller, SDL_CONTROLLER_BUTTON button) +SDL_GameControllerGetButton(SDL_GameController * gamecontroller, SDL_GameControllerButton button) { if ( !gamecontroller ) return 0; @@ -924,7 +1036,7 @@ SDL_Joystick *SDL_GameControllerGetJoystick(SDL_GameController * gamecontroller) /** * get the sdl joystick layer binding for this controller axi mapping */ -SDL_GameControllerButtonBind SDL_GameControllerGetBindForAxis( SDL_GameController * gamecontroller, SDL_CONTROLLER_AXIS axis ) +SDL_GameControllerButtonBind SDL_GameControllerGetBindForAxis(SDL_GameController * gamecontroller, SDL_GameControllerAxis axis) { SDL_GameControllerButtonBind bind; SDL_memset( &bind, 0x0, sizeof(bind) ); @@ -934,13 +1046,13 @@ SDL_GameControllerButtonBind SDL_GameControllerGetBindForAxis( SDL_GameControlle if (gamecontroller->mapping.axes[axis] >= 0 ) { - bind.m_eBindType = SDL_CONTROLLER_BINDTYPE_AXIS; - bind.button = gamecontroller->mapping.axes[axis]; + bind.bindType = SDL_CONTROLLER_BINDTYPE_AXIS; + bind.value.button = gamecontroller->mapping.axes[axis]; } else if (gamecontroller->mapping.buttonasaxis[axis] >= 0 ) { - bind.m_eBindType = SDL_CONTROLLER_BINDTYPE_BUTTON; - bind.button = gamecontroller->mapping.buttonasaxis[axis]; + bind.bindType = SDL_CONTROLLER_BINDTYPE_BUTTON; + bind.value.button = gamecontroller->mapping.buttonasaxis[axis]; } return bind; @@ -950,7 +1062,7 @@ SDL_GameControllerButtonBind SDL_GameControllerGetBindForAxis( SDL_GameControlle /** * get the sdl joystick layer binding for this controller button mapping */ -SDL_GameControllerButtonBind SDL_GameControllerGetBindForButton( SDL_GameController * gamecontroller, SDL_CONTROLLER_BUTTON button ) +SDL_GameControllerButtonBind SDL_GameControllerGetBindForButton(SDL_GameController * gamecontroller, SDL_GameControllerButton button) { SDL_GameControllerButtonBind bind; SDL_memset( &bind, 0x0, sizeof(bind) ); @@ -960,19 +1072,19 @@ SDL_GameControllerButtonBind SDL_GameControllerGetBindForButton( SDL_GameControl if ( gamecontroller->mapping.buttons[button] >= 0 ) { - bind.m_eBindType = SDL_CONTROLLER_BINDTYPE_BUTTON; - bind.button = gamecontroller->mapping.buttons[button]; + bind.bindType = SDL_CONTROLLER_BINDTYPE_BUTTON; + bind.value.button = gamecontroller->mapping.buttons[button]; } else if ( gamecontroller->mapping.axesasbutton[button] >= 0 ) { - bind.m_eBindType = SDL_CONTROLLER_BINDTYPE_AXIS; - bind.axis = gamecontroller->mapping.axesasbutton[button]; + bind.bindType = SDL_CONTROLLER_BINDTYPE_AXIS; + bind.value.axis = gamecontroller->mapping.axesasbutton[button]; } else if ( gamecontroller->mapping.hatasbutton[button].hat >= 0 ) { - bind.m_eBindType = SDL_CONTROLLER_BINDTYPE_HAT; - bind.hat.hat = gamecontroller->mapping.hatasbutton[button].hat; - bind.hat.hat_mask = gamecontroller->mapping.hatasbutton[button].mask; + bind.bindType = SDL_CONTROLLER_BINDTYPE_HAT; + bind.value.hat.hat = gamecontroller->mapping.hatasbutton[button].hat; + bind.value.hat.hat_mask = gamecontroller->mapping.hatasbutton[button].mask; } return bind; @@ -1052,7 +1164,7 @@ SDL_GameControllerQuit(void) * Event filter to transform joystick events into appropriate game controller ones */ int -SDL_PrivateGameControllerAxis(SDL_GameController * gamecontroller, SDL_CONTROLLER_AXIS axis, Sint16 value) +SDL_PrivateGameControllerAxis(SDL_GameController * gamecontroller, SDL_GameControllerAxis axis, Sint16 value) { int posted; @@ -1076,7 +1188,7 @@ SDL_PrivateGameControllerAxis(SDL_GameController * gamecontroller, SDL_CONTROLLE * Event filter to transform joystick events into appropriate game controller ones */ int -SDL_PrivateGameControllerButton(SDL_GameController * gamecontroller, SDL_CONTROLLER_BUTTON button, Uint8 state) +SDL_PrivateGameControllerButton(SDL_GameController * gamecontroller, SDL_GameControllerButton button, Uint8 state) { int posted; #if !SDL_EVENTS_DISABLED @@ -1122,7 +1234,7 @@ SDL_GameControllerEventState(int state) #else const Uint32 event_list[] = { SDL_CONTROLLERAXISMOTION, SDL_CONTROLLERBUTTONDOWN, SDL_CONTROLLERBUTTONUP, - SDL_CONTROLLERDEVICEADDED, SDL_CONTROLLERDEVICEREMOVED, + SDL_CONTROLLERDEVICEADDED, SDL_CONTROLLERDEVICEREMOVED, SDL_CONTROLLERDEVICEREMAPPED, }; unsigned int i; diff --git a/src/joystick/SDL_joystick.c b/src/joystick/SDL_joystick.c index e925363665..6099ed1769 100644 --- a/src/joystick/SDL_joystick.c +++ b/src/joystick/SDL_joystick.c @@ -303,8 +303,7 @@ SDL_JoystickGetBall(SDL_Joystick * joystick, int ball, int *dx, int *dy) joystick->balls[ball].dx = 0; joystick->balls[ball].dy = 0; } else { - SDL_SetError("Joystick only has %d balls", joystick->nballs); - retval = -1; + return SDL_SetError("Joystick only has %d balls", joystick->nballs); } return (retval); } diff --git a/src/joystick/SDL_sysjoystick.h b/src/joystick/SDL_sysjoystick.h index b20ac23a9f..4a5019e739 100644 --- a/src/joystick/SDL_sysjoystick.h +++ b/src/joystick/SDL_sysjoystick.h @@ -28,8 +28,8 @@ /* The SDL joystick structure */ struct _SDL_Joystick { - int instance_id; /* Device instance, monotonically increasing from 0 */ - char *name; /* Joystick name - system dependent */ + SDL_JoystickID instance_id; /* Device instance, monotonically increasing from 0 */ + char *name; /* Joystick name - system dependent */ int naxes; /* Number of axis controls on the joystick */ Sint16 *axes; /* Current axis states */ @@ -38,8 +38,7 @@ struct _SDL_Joystick Uint8 *hats; /* Current hat states */ int nballs; /* Number of trackballs on the joystick */ - struct balldelta - { + struct balldelta { int dx; int dy; } *balls; /* Current ball motion deltas */ @@ -50,10 +49,10 @@ struct _SDL_Joystick struct joystick_hwdata *hwdata; /* Driver dependent information */ int ref_count; /* Reference count for multiple opens */ - - Uint8 closed; /* 1 if this device is no longer valid */ - Uint8 uncentered; /* 1 if this device needs to have its state reset to 0 */ - struct _SDL_Joystick *next; /* pointer to next joystick we have allocated */ + + Uint8 closed; /* 1 if this device is no longer valid */ + Uint8 uncentered; /* 1 if this device needs to have its state reset to 0 */ + struct _SDL_Joystick *next; /* pointer to next joystick we have allocated */ }; /* Function to scan the system for joysticks. diff --git a/src/joystick/beos/SDL_bejoystick.cc b/src/joystick/beos/SDL_bejoystick.cc index 5d41e58e34..f8a7f14a01 100644 --- a/src/joystick/beos/SDL_bejoystick.cc +++ b/src/joystick/beos/SDL_bejoystick.cc @@ -125,8 +125,7 @@ extern "C" joystick->hwdata = (struct joystick_hwdata *) SDL_malloc(sizeof(*joystick->hwdata)); if (joystick->hwdata == NULL) { - SDL_OutOfMemory(); - return (-1); + return SDL_OutOfMemory(); } SDL_memset(joystick->hwdata, 0, sizeof(*joystick->hwdata)); stick = new BJoystick; @@ -134,9 +133,8 @@ extern "C" /* Open the requested joystick for use */ if (stick->Open(SDL_joyport[device_index]) == B_ERROR) { - SDL_SetError("Unable to open joystick"); SDL_SYS_JoystickClose(joystick); - return (-1); + return SDL_SetError("Unable to open joystick"); } /* Set the joystick to calibrated mode */ @@ -152,9 +150,8 @@ extern "C" joystick->hwdata->new_hats = (uint8 *) SDL_malloc(joystick->nhats * sizeof(uint8)); if (!joystick->hwdata->new_hats || !joystick->hwdata->new_axes) { - SDL_OutOfMemory(); SDL_SYS_JoystickClose(joystick); - return (-1); + return SDL_OutOfMemory(); } /* We're done! */ diff --git a/src/joystick/bsd/SDL_sysjoystick.c b/src/joystick/bsd/SDL_sysjoystick.c index f29d94dd20..bbdae328c5 100644 --- a/src/joystick/bsd/SDL_sysjoystick.c +++ b/src/joystick/bsd/SDL_sysjoystick.c @@ -83,7 +83,9 @@ struct report { -#if defined(__FREEBSD__) && (__FreeBSD_kernel_version > 800063) +#if defined(__FREEBSD__) && (__FreeBSD_kernel_version > 900000) + void *buf; /* Buffer */ +#elif defined(__FREEBSD__) && (__FreeBSD_kernel_version > 800063) struct usb_gen_descriptor *buf; /* Buffer */ #else struct usb_ctl_report *buf; /* Buffer */ @@ -149,8 +151,10 @@ static char *joydevnames[MAX_JOYS]; static int report_alloc(struct report *, struct report_desc *, int); static void report_free(struct report *); -#if defined(USBHID_UCR_DATA) +#if defined(USBHID_UCR_DATA) || (defined(__FreeBSD_kernel__) && __FreeBSD_kernel_version <= 800063) #define REP_BUF_DATA(rep) ((rep)->buf->ucr_data) +#elif (defined(__FREEBSD__) && (__FreeBSD_kernel_version > 900000)) +#define REP_BUF_DATA(rep) ((rep)->buf) #elif (defined(__FREEBSD__) && (__FreeBSD_kernel_version > 800063)) #define REP_BUF_DATA(rep) ((rep)->buf->ugd_data) #else @@ -293,17 +297,15 @@ SDL_SYS_JoystickOpen(SDL_Joystick * joy, int device_index) fd = open(path, O_RDONLY); if (fd == -1) { - SDL_SetError("%s: %s", path, strerror(errno)); - return (-1); + return SDL_SetError("%s: %s", path, strerror(errno)); } joy->instance_id = device_index; hw = (struct joystick_hwdata *) SDL_malloc(sizeof(struct joystick_hwdata)); if (hw == NULL) { - SDL_OutOfMemory(); close(fd); - return (-1); + return SDL_OutOfMemory(); } joy->hwdata = hw; hw->fd = fd; @@ -630,24 +632,26 @@ report_alloc(struct report *r, struct report_desc *rd, int repind) #endif if (len < 0) { - SDL_SetError("Negative HID report size"); - return (-1); + return SDL_SetError("Negative HID report size"); } r->size = len; if (r->size > 0) { +#if defined(__FREEBSD__) && (__FreeBSD_kernel_version > 900000) + r->buf = SDL_malloc(r->size); +#else r->buf = SDL_malloc(sizeof(*r->buf) - sizeof(REP_BUF_DATA(r)) + r->size); +#endif if (r->buf == NULL) { - SDL_OutOfMemory(); - return (-1); + return SDL_OutOfMemory(); } } else { r->buf = NULL; } r->status = SREPORT_CLEAN; - return (0); + return 0; } static void diff --git a/src/joystick/darwin/SDL_sysjoystick.c b/src/joystick/darwin/SDL_sysjoystick.c index dbdd6d5680..ee16028b24 100644 --- a/src/joystick/darwin/SDL_sysjoystick.c +++ b/src/joystick/darwin/SDL_sysjoystick.c @@ -169,7 +169,7 @@ HIDCreateOpenDeviceInterface(io_object_t hidDevice, recDevice * pDevice) &(pDevice->interface)); if (S_OK != plugInResult) HIDReportErrorNum - ("CouldnÕt query HID class device interface from plugInInterface", + ("Couldn't query HID class device interface from plugInInterface", plugInResult); (*ppPlugInInterface)->Release(ppPlugInInterface); } else @@ -463,98 +463,92 @@ HIDGetDeviceInfo(io_object_t hidDevice, CFMutableDictionaryRef hidProperties, /* Mac OS X currently is not mirroring all USB properties to HID page so need to look at USB device page also * get dictionary for usb properties: step up two levels and get CF dictionary for USB properties */ - if ((KERN_SUCCESS == - IORegistryEntryGetParentEntry(hidDevice, kIOServicePlane, &parent1)) - && (KERN_SUCCESS == - IORegistryEntryGetParentEntry(parent1, kIOServicePlane, &parent2)) - && (KERN_SUCCESS == - IORegistryEntryCreateCFProperties(parent2, &usbProperties, - kCFAllocatorDefault, - kNilOptions))) { + if ((KERN_SUCCESS == IORegistryEntryGetParentEntry(hidDevice, kIOServicePlane, &parent1)) + && (KERN_SUCCESS == IORegistryEntryGetParentEntry(parent1, kIOServicePlane, &parent2)) + && (KERN_SUCCESS == IORegistryEntryCreateCFProperties(parent2, &usbProperties, kCFAllocatorDefault, kNilOptions))) { if (usbProperties) { CFTypeRef refCF = 0; /* get device info * try hid dictionary first, if fail then go to usb dictionary */ - /* get product name */ - refCF = - CFDictionaryGetValue(hidProperties, CFSTR(kIOHIDProductKey)); - if (!refCF) - refCF = - CFDictionaryGetValue(usbProperties, - CFSTR("USB Product Name")); + refCF = CFDictionaryGetValue(hidProperties, CFSTR(kIOHIDProductKey)); + if (!refCF) { + refCF = CFDictionaryGetValue(usbProperties, CFSTR("USB Product Name")); + } if (refCF) { - if (!CFStringGetCString - (refCF, pDevice->product, 256, - CFStringGetSystemEncoding())) - SDL_SetError - ("CFStringGetCString error retrieving pDevice->product."); + if (!CFStringGetCString(refCF, pDevice->product, 256, CFStringGetSystemEncoding())) { + SDL_SetError("CFStringGetCString error retrieving pDevice->product."); + } } /* get usage page and usage */ - refCF = - CFDictionaryGetValue(hidProperties, - CFSTR(kIOHIDPrimaryUsagePageKey)); + refCF = CFDictionaryGetValue(hidProperties, CFSTR(kIOHIDPrimaryUsagePageKey)); if (refCF) { - if (!CFNumberGetValue - (refCF, kCFNumberLongType, &pDevice->usagePage)) - SDL_SetError - ("CFNumberGetValue error retrieving pDevice->usagePage."); - refCF = - CFDictionaryGetValue(hidProperties, - CFSTR(kIOHIDPrimaryUsageKey)); - if (refCF) - if (!CFNumberGetValue - (refCF, kCFNumberLongType, &pDevice->usage)) - SDL_SetError - ("CFNumberGetValue error retrieving pDevice->usage."); + if (!CFNumberGetValue (refCF, kCFNumberLongType, &pDevice->usagePage)) { + SDL_SetError("CFNumberGetValue error retrieving pDevice->usagePage."); + } + + refCF = CFDictionaryGetValue(hidProperties, CFSTR(kIOHIDPrimaryUsageKey)); + if (refCF) { + if (!CFNumberGetValue (refCF, kCFNumberLongType, &pDevice->usage)) { + SDL_SetError("CFNumberGetValue error retrieving pDevice->usage."); + } + } } - refCF = - CFDictionaryGetValue(hidProperties, - CFSTR(kIOHIDVendorIDKey)); + refCF = CFDictionaryGetValue(hidProperties, CFSTR(kIOHIDVendorIDKey)); if (refCF) { - if (!CFNumberGetValue - (refCF, kCFNumberLongType, &pDevice->guid.data[0])) - SDL_SetError - ("CFNumberGetValue error retrieving pDevice->guid."); + if (!CFNumberGetValue(refCF, kCFNumberLongType, &pDevice->guid.data[0])) { + SDL_SetError("CFNumberGetValue error retrieving pDevice->guid[0]"); + } } - refCF = - CFDictionaryGetValue(hidProperties, - CFSTR(kIOHIDProductIDKey)); + + refCF = CFDictionaryGetValue(hidProperties, CFSTR(kIOHIDProductIDKey)); if (refCF) { - if (!CFNumberGetValue - (refCF, kCFNumberLongType, &pDevice->guid.data[8])) - SDL_SetError - ("CFNumberGetValue error retrieving pDevice->guid[8]."); + if (!CFNumberGetValue(refCF, kCFNumberLongType, &pDevice->guid.data[8])) { + SDL_SetError("CFNumberGetValue error retrieving pDevice->guid[8]"); + } } - - if (NULL == refCF) { /* get top level element HID usage page or usage */ + /* Check to make sure we have a vendor and product ID + If we don't, use the same algorithm as the Linux code for Bluetooth devices */ + { + Uint32 *guid32 = (Uint32*)pDevice->guid.data; + if (!guid32[0] && !guid32[1]) { + const Uint16 BUS_BLUETOOTH = 0x05; + Uint16 *guid16 = (Uint16 *)guid32; + *guid16++ = BUS_BLUETOOTH; + *guid16++ = 0; + SDL_strlcpy((char*)guid16, pDevice->product, sizeof(pDevice->guid.data) - 4); + } + } + + /* If we don't have a vendor and product ID this is probably a Bluetooth device */ + + if (NULL == refCF) { /* get top level element HID usage page or usage */ /* use top level element instead */ CFTypeRef refCFTopElement = 0; - refCFTopElement = - CFDictionaryGetValue(hidProperties, - CFSTR(kIOHIDElementKey)); + refCFTopElement = CFDictionaryGetValue(hidProperties, CFSTR(kIOHIDElementKey)); { /* refCFTopElement points to an array of element dictionaries */ CFRange range = { 0, CFArrayGetCount(refCFTopElement) }; - CFArrayApplyFunction(refCFTopElement, range, - HIDTopLevelElementHandler, pDevice); + CFArrayApplyFunction(refCFTopElement, range, HIDTopLevelElementHandler, pDevice); } } CFRelease(usbProperties); - } else - SDL_SetError - ("IORegistryEntryCreateCFProperties failed to create usbProperties."); + } else { + SDL_SetError("IORegistryEntryCreateCFProperties failed to create usbProperties."); + } - if (kIOReturnSuccess != IOObjectRelease(parent2)) - SDL_SetError("IOObjectRelease error with parent2."); - if (kIOReturnSuccess != IOObjectRelease(parent1)) - SDL_SetError("IOObjectRelease error with parent1."); + if (kIOReturnSuccess != IOObjectRelease(parent2)) { + SDL_SetError("IOObjectRelease error with parent2"); + } + if (kIOReturnSuccess != IOObjectRelease(parent1)) { + SDL_SetError("IOObjectRelease error with parent1"); + } } } @@ -730,14 +724,12 @@ SDL_SYS_JoystickInit(void) io_iterator_t portIterator = 0; if (gpDeviceList) { - SDL_SetError("Joystick: Device list already inited."); - return -1; + return SDL_SetError("Joystick: Device list already inited."); } result = IOMasterPort(bootstrap_port, &masterPort); if (kIOReturnSuccess != result) { - SDL_SetError("Joystick: IOMasterPort error with bootstrap_port."); - return -1; + return SDL_SetError("Joystick: IOMasterPort error with bootstrap_port."); } /* Set up a matching dictionary to search I/O Registry by class name for all HID class devices. */ @@ -756,9 +748,8 @@ SDL_SYS_JoystickInit(void) CFDictionarySetValue (hidMatchDictionary, CFSTR (kIOHIDPrimaryUsagePageKey), refUsagePage); */ } else { - SDL_SetError + return SDL_SetError ("Joystick: Failed to get HID CFMutableDictionaryRef via IOServiceMatching."); - return -1; } /*/ Now search I/O Registry for matching devices. */ @@ -767,8 +758,7 @@ SDL_SYS_JoystickInit(void) &hidObjectIterator); /* Check for errors */ if (kIOReturnSuccess != result) { - SDL_SetError("Joystick: Couldn't create a HID object iterator."); - return -1; + return SDL_SetError("Joystick: Couldn't create a HID object iterator."); } if (!hidObjectIterator) { /* there are no joysticks */ gpDeviceList = NULL; @@ -1100,4 +1090,5 @@ SDL_JoystickGUID SDL_SYS_JoystickGetGUID(SDL_Joystick *joystick) } #endif /* SDL_JOYSTICK_IOKIT */ + /* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/joystick/dummy/SDL_sysjoystick.c b/src/joystick/dummy/SDL_sysjoystick.c index e20f38e9e8..2f03e39c37 100644 --- a/src/joystick/dummy/SDL_sysjoystick.c +++ b/src/joystick/dummy/SDL_sysjoystick.c @@ -73,8 +73,7 @@ SDL_JoystickID SDL_SYS_GetInstanceIdOfDeviceIndex(int device_index) int SDL_SYS_JoystickOpen(SDL_Joystick * joystick, int device_index) { - SDL_SetError("Logic error: No joysticks available"); - return (-1); + return SDL_SetError("Logic error: No joysticks available"); } /* Function to determine is this joystick is attached to the system right now */ diff --git a/src/joystick/iphoneos/SDL_sysjoystick.m b/src/joystick/iphoneos/SDL_sysjoystick.m index a275732f9b..e930025765 100644 --- a/src/joystick/iphoneos/SDL_sysjoystick.m +++ b/src/joystick/iphoneos/SDL_sysjoystick.m @@ -122,15 +122,12 @@ SDL_SYS_JoystickClose(SDL_Joystick * joystick) [[SDLUIAccelerationDelegate sharedDelegate] shutdown]; } SDL_SetError("No joystick open with that index"); - - return; } /* Function to perform any system-specific joystick related cleanup */ void SDL_SYS_JoystickQuit(void) { - return; } SDL_JoystickGUID SDL_SYS_JoystickGetDeviceGUID( int device_index ) diff --git a/src/joystick/linux/SDL_sysjoystick.c b/src/joystick/linux/SDL_sysjoystick.c index c402a625b7..98e6c0ec00 100644 --- a/src/joystick/linux/SDL_sysjoystick.c +++ b/src/joystick/linux/SDL_sysjoystick.c @@ -47,6 +47,11 @@ #include "../../events/SDL_events_c.h" #endif +/* This isn't defined in older Linux kernel headers */ +#ifndef SYN_DROPPED +#define SYN_DROPPED 3 +#endif + /* * !!! FIXME: move all the udev stuff to src/core/linux, so I can reuse it * !!! FIXME: for audio hardware disconnects. @@ -57,12 +62,6 @@ #include <libudev.h> #include <sys/time.h> #include <sys/types.h> -#include <unistd.h> - -/* This isn't defined in older Linux kernel headers */ -#ifndef SYN_DROPPED -#define SYN_DROPPED 3 -#endif /* we never link directly to libudev. */ /* !!! FIXME: can we generalize this? ALSA, etc, do the same things. */ @@ -388,8 +387,7 @@ JoystickInitWithUdev(void) SDL_assert(udev == NULL); udev = UDEV_udev_new(); if (udev == NULL) { - SDL_SetError("udev_new() failed"); - return -1; + return SDL_SetError("udev_new() failed"); } udev_mon = UDEV_udev_monitor_new_from_netlink(udev, "udev"); @@ -401,8 +399,7 @@ JoystickInitWithUdev(void) enumerate = UDEV_udev_enumerate_new(udev); if (enumerate == NULL) { - SDL_SetError("udev_enumerate_new() failed"); - return -1; + return SDL_SetError("udev_enumerate_new() failed"); } UDEV_udev_enumerate_add_match_subsystem(enumerate, "input"); @@ -726,15 +723,13 @@ SDL_SYS_JoystickOpen(SDL_Joystick * joystick, int device_index) int fd = -1; if (item == NULL) { - SDL_SetError("No such device"); - return -1; + return SDL_SetError("No such device"); } fname = item->path; fd = open(fname, O_RDONLY, 0); if (fd < 0) { - SDL_SetError("Unable to open %s", fname); - return -1; + return SDL_SetError("Unable to open %s", fname); } joystick->instance_id = item->device_instance; @@ -742,8 +737,7 @@ SDL_SYS_JoystickOpen(SDL_Joystick * joystick, int device_index) SDL_malloc(sizeof(*joystick->hwdata)); if (joystick->hwdata == NULL) { close(fd); - SDL_OutOfMemory(); - return (-1); + return SDL_OutOfMemory(); } SDL_memset(joystick->hwdata, 0, sizeof(*joystick->hwdata)); joystick->hwdata->item = item; @@ -754,8 +748,7 @@ SDL_SYS_JoystickOpen(SDL_Joystick * joystick, int device_index) SDL_free(joystick->hwdata); joystick->hwdata = NULL; close(fd); - SDL_OutOfMemory(); - return (-1); + return SDL_OutOfMemory(); } SDL_assert(item->hwdata == NULL); diff --git a/src/joystick/nds/SDL_sysjoystick.c b/src/joystick/nds/SDL_sysjoystick.c deleted file mode 100644 index a4ac182331..0000000000 --- a/src/joystick/nds/SDL_sysjoystick.c +++ /dev/null @@ -1,209 +0,0 @@ -/* - Simple DirectMedia Layer - Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org> - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. -*/ - -#include "SDL_config.h" - -#ifdef SDL_JOYSTICK_NDS - -/* This is the system specific header for the SDL joystick API */ -#include <nds.h> -#include <stdio.h> /* For the definition of NULL */ - -#include "SDL_error.h" -#include "SDL_events.h" -#include "SDL_joystick.h" -#include "../SDL_sysjoystick.h" -#include "../SDL_joystick_c.h" - -#include "../../video/nds/SDL_ndsevents_c.h" - -/* Function to scan the system for joysticks. - */ -int -SDL_SYS_JoystickInit(void) -{ - return (1); -} - -int SDL_SYS_NumJoysticks() -{ - return 1; -} - -void SDL_SYS_JoystickDetect() -{ -} - -SDL_bool SDL_SYS_JoystickNeedsPolling() -{ - return SDL_FALSE; -} - -/* Function to get the device-dependent name of a joystick */ -const char * -SDL_SYS_JoystickNameForDeviceIndex(int device_index) -{ - return "NDS builtin joypad"; -} - -/* Function to perform the mapping from device index to the instance id for this index */ -SDL_JoystickID SDL_SYS_GetInstanceIdOfDeviceIndex(int device_index) -{ - return device_index; -} - -/* Function to open a joystick for use. - The joystick to open is specified by the index field of the joystick. - This should fill the nbuttons and naxes fields of the joystick structure. - It returns 0, or -1 if there is an error. - */ -int -SDL_SYS_JoystickOpen(SDL_Joystick * joystick, int device_index) -{ - joystick->nbuttons = 8; - joystick->nhats = 0; - joystick->nballs = 0; - joystick->naxes = 2; - return 0; -} - -/* Function to determine is this joystick is attached to the system right now */ -SDL_bool SDL_SYS_JoystickAttached(SDL_Joystick *joystick) -{ - return SDL_TRUE; -} - -/* Function to update the state of a joystick - called as a device poll. - * This function shouldn't update the joystick structure directly, - * but instead should call SDL_PrivateJoystick*() to deliver events - * and update joystick device state. - */ - void -SDL_SYS_JoystickUpdate(SDL_Joystick * joystick) -{ - u32 keysd, keysu; - int magnitude = 16384; - - /*scanKeys(); - this is done in PumpEvents, because touch uses it too */ - keysd = keysDown(); - keysu = keysUp(); - - if ((keysd & KEY_UP)) { - SDL_PrivateJoystickAxis(joystick, 1, -magnitude); - } - if ((keysd & KEY_DOWN)) { - SDL_PrivateJoystickAxis(joystick, 1, magnitude); - } - if ((keysd & KEY_LEFT)) { - SDL_PrivateJoystickAxis(joystick, 0, -magnitude); - } - if ((keysd & KEY_RIGHT)) { - SDL_PrivateJoystickAxis(joystick, 0, magnitude); - } - if ((keysu & (KEY_UP | KEY_DOWN))) { - SDL_PrivateJoystickAxis(joystick, 1, 0); - } - if ((keysu & (KEY_LEFT | KEY_RIGHT))) { - SDL_PrivateJoystickAxis(joystick, 0, 0); - } - if ((keysd & KEY_A)) { - SDL_PrivateJoystickButton(joystick, 0, SDL_PRESSED); - } - if ((keysd & KEY_B)) { - SDL_PrivateJoystickButton(joystick, 1, SDL_PRESSED); - } - if ((keysd & KEY_X)) { - SDL_PrivateJoystickButton(joystick, 2, SDL_PRESSED); - } - if ((keysd & KEY_Y)) { - SDL_PrivateJoystickButton(joystick, 3, SDL_PRESSED); - } - if ((keysd & KEY_L)) { - SDL_PrivateJoystickButton(joystick, 4, SDL_PRESSED); - } - if ((keysd & KEY_R)) { - SDL_PrivateJoystickButton(joystick, 5, SDL_PRESSED); - } - if ((keysd & KEY_SELECT)) { - SDL_PrivateJoystickButton(joystick, 6, SDL_PRESSED); - } - if ((keysd & KEY_START)) { - SDL_PrivateJoystickButton(joystick, 7, SDL_PRESSED); - } - if ((keysu & KEY_A)) { - SDL_PrivateJoystickButton(joystick, 0, SDL_RELEASED); - } - if ((keysu & KEY_B)) { - SDL_PrivateJoystickButton(joystick, 1, SDL_RELEASED); - } - if ((keysu & KEY_X)) { - SDL_PrivateJoystickButton(joystick, 2, SDL_RELEASED); - } - if ((keysu & KEY_Y)) { - SDL_PrivateJoystickButton(joystick, 3, SDL_RELEASED); - } - if ((keysu & KEY_L)) { - SDL_PrivateJoystickButton(joystick, 4, SDL_RELEASED); - } - if ((keysu & KEY_R)) { - SDL_PrivateJoystickButton(joystick, 5, SDL_RELEASED); - } - if ((keysu & KEY_SELECT)) { - SDL_PrivateJoystickButton(joystick, 6, SDL_RELEASED); - } - if ((keysu & KEY_START)) { - SDL_PrivateJoystickButton(joystick, 7, SDL_RELEASED); - } -} - -/* Function to close a joystick after use */ -void -SDL_SYS_JoystickClose(SDL_Joystick * joystick) -{ -} - -/* Function to perform any system-specific joystick related cleanup */ -void -SDL_SYS_JoystickQuit(void) -{ -} - -SDL_JoystickGUID SDL_SYS_JoystickGetDeviceGUID( int device_index ) -{ - SDL_JoystickGUID guid; - // the GUID is just the first 16 chars of the name for now - const char *name = SDL_SYS_JoystickNameForDeviceIndex( device_index ); - SDL_zero( guid ); - SDL_memcpy( &guid, name, SDL_min( sizeof(guid), SDL_strlen( name ) ) ); - return guid; -} - -SDL_JoystickGUID SDL_SYS_JoystickGetGUID(SDL_Joystick * joystick) -{ - SDL_JoystickGUID guid; - // the GUID is just the first 16 chars of the name for now - const char *name = joystick->name; - SDL_zero( guid ); - SDL_memcpy( &guid, name, SDL_min( sizeof(guid), SDL_strlen( name ) ) ); - return guid; -} - -#endif /* SDL_JOYSTICK_NDS */ diff --git a/src/joystick/psp/SDL_sysjoystick.c b/src/joystick/psp/SDL_sysjoystick.c new file mode 100644 index 0000000000..a2c51a2851 --- /dev/null +++ b/src/joystick/psp/SDL_sysjoystick.c @@ -0,0 +1,274 @@ +/* + Simple DirectMedia Layer + Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org> + + This software is provided 'as-is', without any express or implied + warranty. In no event will the authors be held liable for any damages + arising from the use of this software. + + Permission is granted to anyone to use this software for any purpose, + including commercial applications, and to alter it and redistribute it + freely, subject to the following restrictions: + + 1. The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original software. + 3. This notice may not be removed or altered from any source distribution. +*/ + +/* This is the system specific header for the SDL joystick API */ +#include <pspctrl.h> +#include <pspkernel.h> + +#include <stdio.h> /* For the definition of NULL */ +#include <stdlib.h> + +#include "../SDL_sysjoystick.h" +#include "../SDL_joystick_c.h" + +#include "SDL_events.h" +#include "SDL_error.h" +#include "SDL_thread.h" +#include "SDL_mutex.h" +#include "SDL_timer.h" + +/* Current pad state */ +static SceCtrlData pad = { .Lx = 0, .Ly = 0, .Buttons = 0 }; +static SDL_sem *pad_sem = NULL; +static SDL_Thread *thread = NULL; +static int running = 0; +static const enum PspCtrlButtons button_map[] = { + PSP_CTRL_TRIANGLE, PSP_CTRL_CIRCLE, PSP_CTRL_CROSS, PSP_CTRL_SQUARE, + PSP_CTRL_LTRIGGER, PSP_CTRL_RTRIGGER, + PSP_CTRL_DOWN, PSP_CTRL_LEFT, PSP_CTRL_UP, PSP_CTRL_RIGHT, + PSP_CTRL_SELECT, PSP_CTRL_START, PSP_CTRL_HOME, PSP_CTRL_HOLD }; +static int analog_map[256]; /* Map analog inputs to -32768 -> 32767 */ + +typedef struct +{ + int x; + int y; +} point; + +// 4 points define the bezier-curve. +static point a = { 0, 0 }; +static point b = { 50, 0 }; +static point c = { 78, 32767 }; +static point d = { 128, 32767 }; + +// simple linear interpolation between two points +static __inline__ void lerp (point *dest, point *a, point *b, float t) +{ + dest->x = a->x + (b->x - a->x)*t; + dest->y = a->y + (b->y - a->y)*t; +} + +// evaluate a point on a bezier-curve. t goes from 0 to 1.0 +static int calc_bezier_y(float t) +{ + point ab, bc, cd, abbc, bccd, dest; + lerp (&ab, &a, &b, t); // point between a and b + lerp (&bc, &b, &c, t); // point between b and c + lerp (&cd, &c, &d, t); // point between c and d + lerp (&abbc, &ab, &bc, t); // point between ab and bc + lerp (&bccd, &bc, &cd, t); // point between bc and cd + lerp (&dest, &abbc, &bccd, t); // point on the bezier-curve + return dest.y; +} + +/* + * Collect pad data about once per frame + */ +int JoystickUpdate(void *data) +{ + while (running) { + SDL_SemWait(pad_sem); + sceCtrlPeekBufferPositive(&pad, 1); + SDL_SemPost(pad_sem); + /* Delay 1/60th of a second */ + sceKernelDelayThread(1000000 / 60); + } + return 0; +} + + + +/* Function to scan the system for joysticks. + * This function should set SDL_numjoysticks to the number of available + * joysticks. Joystick 0 should be the system default joystick. + * It should return number of joysticks, or -1 on an unrecoverable fatal error. + */ +int SDL_SYS_JoystickInit(void) +{ + int i; + +// SDL_numjoysticks = 1; + + /* Setup input */ + sceCtrlSetSamplingCycle(0); + sceCtrlSetSamplingMode(PSP_CTRL_MODE_ANALOG); + + /* Start thread to read data */ + if((pad_sem = SDL_CreateSemaphore(1)) == NULL) { + return SDL_SetError("Can't create input semaphore"); + } + running = 1; + if((thread = SDL_CreateThread(JoystickUpdate, "JoySitckThread",NULL)) == NULL) { + return SDL_SetError("Can't create input thread"); + } + + /* Create an accurate map from analog inputs (0 to 255) + to SDL joystick positions (-32768 to 32767) */ + for (i = 0; i < 128; i++) + { + float t = (float)i/127.0f; + analog_map[i+128] = calc_bezier_y(t); + analog_map[127-i] = -1 * analog_map[i+128]; + } + + return 1; +} + +int SDL_SYS_NumJoysticks() +{ + return 1; +} + +void SDL_SYS_JoystickDetect() +{ +} + +SDL_bool SDL_SYS_JoystickNeedsPolling() +{ + return SDL_FALSE; +} + +/* Function to get the device-dependent name of a joystick */ +const char * SDL_SYS_JoystickNameForDeviceIndex(int device_index) +{ + return "PSP builtin joypad"; +} + +/* Function to perform the mapping from device index to the instance id for this index */ +SDL_JoystickID SDL_SYS_GetInstanceIdOfDeviceIndex(int device_index) +{ + return device_index; +} + +/* Function to get the device-dependent name of a joystick */ +const char *SDL_SYS_JoystickName(int index) +{ + if (index == 0) + return "PSP controller"; + + SDL_SetError("No joystick available with that index"); + return(NULL); +} + +/* Function to open a joystick for use. + The joystick to open is specified by the index field of the joystick. + This should fill the nbuttons and naxes fields of the joystick structure. + It returns 0, or -1 if there is an error. + */ +int SDL_SYS_JoystickOpen(SDL_Joystick *joystick, int device_index) +{ + joystick->nbuttons = 14; + joystick->naxes = 2; + joystick->nhats = 0; + + return 0; +} + +/* Function to determine is this joystick is attached to the system right now */ +SDL_bool SDL_SYS_JoystickAttached(SDL_Joystick *joystick) +{ + return SDL_TRUE; +} +/* Function to update the state of a joystick - called as a device poll. + * This function shouldn't update the joystick structure directly, + * but instead should call SDL_PrivateJoystick*() to deliver events + * and update joystick device state. + */ + +void SDL_SYS_JoystickUpdate(SDL_Joystick *joystick) +{ + int i; + enum PspCtrlButtons buttons; + enum PspCtrlButtons changed; + unsigned char x, y; + static enum PspCtrlButtons old_buttons = 0; + static unsigned char old_x = 0, old_y = 0; + + SDL_SemWait(pad_sem); + buttons = pad.Buttons; + x = pad.Lx; + y = pad.Ly; + SDL_SemPost(pad_sem); + + /* Axes */ + if(old_x != x) { + SDL_PrivateJoystickAxis(joystick, 0, analog_map[x]); + old_x = x; + } + if(old_y != y) { + SDL_PrivateJoystickAxis(joystick, 1, analog_map[y]); + old_y = y; + } + + /* Buttons */ + changed = old_buttons ^ buttons; + old_buttons = buttons; + if(changed) { + for(i=0; i<sizeof(button_map)/sizeof(button_map[0]); i++) { + if(changed & button_map[i]) { + SDL_PrivateJoystickButton( + joystick, i, + (buttons & button_map[i]) ? + SDL_PRESSED : SDL_RELEASED); + } + } + } + + sceKernelDelayThread(0); +} + +/* Function to close a joystick after use */ +void SDL_SYS_JoystickClose(SDL_Joystick *joystick) +{ + /* Do nothing. */ +} + +/* Function to perform any system-specific joystick related cleanup */ +void SDL_SYS_JoystickQuit(void) +{ + /* Cleanup Threads and Semaphore. */ + running = 0; + SDL_WaitThread(thread, NULL); + SDL_DestroySemaphore(pad_sem); +} + +SDL_JoystickGUID SDL_SYS_JoystickGetDeviceGUID( int device_index ) +{ + SDL_JoystickGUID guid; + // the GUID is just the first 16 chars of the name for now + const char *name = SDL_SYS_JoystickNameForDeviceIndex( device_index ); + SDL_zero( guid ); + SDL_memcpy( &guid, name, SDL_min( sizeof(guid), SDL_strlen( name ) ) ); + return guid; +} + +SDL_JoystickGUID SDL_SYS_JoystickGetGUID(SDL_Joystick * joystick) +{ + SDL_JoystickGUID guid; + // the GUID is just the first 16 chars of the name for now + const char *name = joystick->name; + SDL_zero( guid ); + SDL_memcpy( &guid, name, SDL_min( sizeof(guid), SDL_strlen( name ) ) ); + return guid; +} + +/* vim: ts=4 sw=4 + */ diff --git a/src/joystick/windows/SDL_dxjoystick.c b/src/joystick/windows/SDL_dxjoystick.c index ba13f971c2..6ac7f338df 100644 --- a/src/joystick/windows/SDL_dxjoystick.c +++ b/src/joystick/windows/SDL_dxjoystick.c @@ -33,6 +33,7 @@ * let it return 0 events. */ #include "SDL_error.h" +#include "SDL_assert.h" #include "SDL_events.h" #include "SDL_joystick.h" #include "../SDL_sysjoystick.h" @@ -42,6 +43,7 @@ #include "SDL_timer.h" #include "SDL_mutex.h" #include "SDL_events.h" +#include "SDL_hints.h" #if !SDL_EVENTS_DISABLED #include "../../events/SDL_events_c.h" #endif @@ -66,13 +68,76 @@ static SDL_bool coinitialized = SDL_FALSE; static LPDIRECTINPUT8 dinput = NULL; static SDL_bool s_bDeviceAdded = SDL_FALSE; static SDL_bool s_bDeviceRemoved = SDL_FALSE; -static int s_nInstanceID = -1; +static SDL_JoystickID s_nInstanceID = -1; static GUID *s_pKnownJoystickGUIDs = NULL; static SDL_cond *s_condJoystickThread = NULL; static SDL_mutex *s_mutexJoyStickEnum = NULL; static SDL_Thread *s_threadJoystick = NULL; static SDL_bool s_bJoystickThreadQuit = SDL_FALSE; +static SDL_bool s_bXInputEnabled = SDL_TRUE; + +XInputGetState_t SDL_XInputGetState = NULL; +XInputSetState_t SDL_XInputSetState = NULL; +XInputGetCapabilities_t SDL_XInputGetCapabilities = NULL; +DWORD SDL_XInputVersion = 0; + static HANDLE s_pXInputDLL = 0; +static int s_XInputDLLRefCount = 0; + +int +WIN_LoadXInputDLL(void) +{ + DWORD version = 0; + + if (s_pXInputDLL) { + SDL_assert(s_XInputDLLRefCount > 0); + s_XInputDLLRefCount++; + return 0; /* already loaded */ + } + + version = (1 << 16) | 4; + s_pXInputDLL = LoadLibrary( L"XInput1_4.dll" ); // 1.4 Ships with Windows 8. + if (!s_pXInputDLL) { + version = (1 << 16) | 3; + s_pXInputDLL = LoadLibrary( L"XInput1_3.dll" ); // 1.3 Ships with Vista and Win7, can be installed as a restributable component. + } + if (!s_pXInputDLL) { + s_pXInputDLL = LoadLibrary( L"bin\\XInput1_3.dll" ); + } + if (!s_pXInputDLL) { + return -1; + } + + SDL_assert(s_XInputDLLRefCount == 0); + SDL_XInputVersion = version; + s_XInputDLLRefCount = 1; + + /* 100 is the ordinal for _XInputGetStateEx, which returns the same struct as XinputGetState, but with extra data in wButtons for the guide button, we think... */ + SDL_XInputGetState = (XInputGetState_t)GetProcAddress( (HMODULE)s_pXInputDLL, (LPCSTR)100 ); + SDL_XInputSetState = (XInputSetState_t)GetProcAddress( (HMODULE)s_pXInputDLL, "XInputSetState" ); + SDL_XInputGetCapabilities = (XInputGetCapabilities_t)GetProcAddress( (HMODULE)s_pXInputDLL, "XInputGetCapabilities" ); + if ( !SDL_XInputGetState || !SDL_XInputSetState || !SDL_XInputGetCapabilities ) { + WIN_UnloadXInputDLL(); + return -1; + } + + return 0; +} + +void +WIN_UnloadXInputDLL(void) +{ + if ( s_pXInputDLL ) { + SDL_assert(s_XInputDLLRefCount > 0); + if (--s_XInputDLLRefCount == 0) { + FreeLibrary( s_pXInputDLL ); + s_pXInputDLL = NULL; + } + } else { + SDL_assert(s_XInputDLLRefCount == 0); + } +} + extern HRESULT(WINAPI * DInputCreate) (HINSTANCE hinst, DWORD dwVersion, LPDIRECTINPUT * ppDI, @@ -83,48 +148,18 @@ struct JoyStick_DeviceData_ DIDEVICEINSTANCE dxdevice; char *joystickname; Uint8 send_add_event; - int nInstanceID; + SDL_JoystickID nInstanceID; SDL_bool bXInputDevice; Uint8 XInputUserId; struct JoyStick_DeviceData_ *pNext; }; - -/* Forward decl's for XInput API's we load dynamically and use if available */ -typedef DWORD (WINAPI *XInputGetState_t) - ( - DWORD dwUserIndex, // [in] Index of the gamer associated with the device - XINPUT_STATE_EX* pState // [out] Receives the current state - ); - -typedef DWORD (WINAPI *XInputSetState_t) - ( - DWORD dwUserIndex, // [in] Index of the gamer associated with the device - XINPUT_VIBRATION* pVibration // [in, out] The vibration information to send to the controller - ); - -typedef DWORD (WINAPI *XInputGetCapabilities_t) - ( - DWORD dwUserIndex, // [in] Index of the gamer associated with the device - DWORD dwFlags, // [in] Input flags that identify the device type - XINPUT_CAPABILITIES* pCapabilities // [out] Receives the capabilities - ); - -XInputGetState_t PC_XInputGetState; -XInputSetState_t PC_XInputSetState; -XInputGetCapabilities_t PC_XInputGetCapabilities; - -#define XINPUTGETSTATE PC_XInputGetState -#define XINPUTSETSTATE PC_XInputSetState -#define XINPUTGETCAPABILITIES PC_XInputGetCapabilities -#define INVALID_XINPUT_USERID 255 - typedef struct JoyStick_DeviceData_ JoyStick_DeviceData; static JoyStick_DeviceData *SYS_Joystick; /* array to hold joystick ID values */ /* local prototypes */ -static void SetDIerror(const char *function, HRESULT code); +static int SetDIerror(const char *function, HRESULT code); static BOOL CALLBACK EnumJoysticksCallback(const DIDEVICEINSTANCE * pdidInstance, VOID * pContext); static BOOL CALLBACK EnumDevObjectsCallback(LPCDIDEVICEOBJECTINSTANCE dev, @@ -317,14 +352,14 @@ const DIDATAFORMAT c_dfDIJoystick2 = { /* Convert a DirectInput return code to a text message */ -static void +static int SetDIerror(const char *function, HRESULT code) { /* - SDL_SetError("%s() [%s]: %s", function, + return SDL_SetError("%s() [%s]: %s", function, DXGetErrorString9A(code), DXGetErrorDescription9A(code)); */ - SDL_SetError("%s() DirectX error %d", function, code); + return SDL_SetError("%s() DirectX error %d", function, code); } @@ -364,6 +399,11 @@ BOOL IsXInputDevice( const GUID* pGuidProductFromDirectInput ) HRESULT hr; DWORD bCleanupCOM; + if (!s_bXInputEnabled) + { + return SDL_FALSE; + } + SDL_memset( pDevices, 0x0, sizeof(pDevices) ); // CoInit if needed @@ -525,17 +565,13 @@ SDL_JoystickThread(void *_data) if (!RegisterClassEx (&wincl)) { - SDL_SetError("Failed to create register class for joystick autodetect.", - GetLastError()); - return -1; + return SDL_SetError("Failed to create register class for joystick autodetect.", GetLastError()); } messageWindow = (HWND)CreateWindowEx( 0, L"Message", NULL, 0, 0, 0, 0, 0, HWND_MESSAGE, NULL, NULL, NULL ); if ( !messageWindow ) { - SDL_SetError("Failed to create message window for joystick autodetect.", - GetLastError()); - return -1; + return SDL_SetError("Failed to create message window for joystick autodetect.", GetLastError()); } SDL_memset(&dbh, 0x0, sizeof(dbh)); @@ -547,9 +583,7 @@ SDL_JoystickThread(void *_data) hNotify = RegisterDeviceNotification( messageWindow, &dbh, DEVICE_NOTIFY_WINDOW_HANDLE ); if ( !hNotify ) { - SDL_SetError("Failed to create notify device for joystick autodetect.", - GetLastError()); - return -1; + return SDL_SetError("Failed to create notify device for joystick autodetect.", GetLastError()); } SDL_LockMutex( s_mutexJoyStickEnum ); @@ -569,7 +603,7 @@ SDL_JoystickThread(void *_data) } } - if ( XINPUTGETCAPABILITIES ) + if ( s_bXInputEnabled && XINPUTGETCAPABILITIES ) { // scan for any change in XInput devices for ( userId = 0; userId < 4; userId++ ) @@ -627,11 +661,14 @@ SDL_SYS_JoystickInit(void) { HRESULT result; HINSTANCE instance; + const char *env = SDL_GetHint(SDL_HINT_XINPUT_ENABLED); + if (env && !SDL_atoi(env)) { + s_bXInputEnabled = SDL_FALSE; + } result = WIN_CoInitialize(); if (FAILED(result)) { - SetDIerror("CoInitialize", result); - return (-1); + return SetDIerror("CoInitialize", result); } coinitialized = SDL_TRUE; @@ -641,49 +678,30 @@ SDL_SYS_JoystickInit(void) if (FAILED(result)) { SDL_SYS_JoystickQuit(); - SetDIerror("CoCreateInstance", result); - return (-1); + return SetDIerror("CoCreateInstance", result); } /* Because we used CoCreateInstance, we need to Initialize it, first. */ instance = GetModuleHandle(NULL); if (instance == NULL) { SDL_SYS_JoystickQuit(); - SDL_SetError("GetModuleHandle() failed with error code %d.", - GetLastError()); - return (-1); + return SDL_SetError("GetModuleHandle() failed with error code %d.", GetLastError()); } result = IDirectInput8_Initialize(dinput, instance, DIRECTINPUT_VERSION); if (FAILED(result)) { SDL_SYS_JoystickQuit(); - SetDIerror("IDirectInput::Initialize", result); - return (-1); + return SetDIerror("IDirectInput::Initialize", result); } - s_mutexJoyStickEnum = SDL_CreateMutex(); - s_condJoystickThread = SDL_CreateCond(); - s_bDeviceAdded = SDL_TRUE; // force a scan of the system for joysticks this first time - SDL_SYS_JoystickDetect(); - - // try to load XInput support if available - s_pXInputDLL = LoadLibrary( L"XInput1_3.dll" ); - if ( !s_pXInputDLL ) - s_pXInputDLL = LoadLibrary( L"bin\\XInput1_3.dll" ); - if ( s_pXInputDLL ) - { - // 100 is the ordinal for _XInputGetStateEx, which returns the same struct as XinputGetState, but with extra data in wButtons for the guide button, we think... - PC_XInputGetState = (XInputGetState_t)GetProcAddress( (HMODULE)s_pXInputDLL, (LPCSTR)100 ); - PC_XInputSetState = (XInputSetState_t)GetProcAddress( (HMODULE)s_pXInputDLL, "XInputSetState" ); - PC_XInputGetCapabilities = (XInputGetCapabilities_t)GetProcAddress( (HMODULE)s_pXInputDLL, "XInputGetCapabilities" ); - if ( !PC_XInputGetState || !PC_XInputSetState || !PC_XInputGetCapabilities ) - { - SDL_SYS_JoystickQuit(); - SDL_SetError("GetProcAddress() failed when loading XInput.", GetLastError()); - return (-1); - } - } + s_mutexJoyStickEnum = SDL_CreateMutex(); + s_condJoystickThread = SDL_CreateCond(); + s_bDeviceAdded = SDL_TRUE; // force a scan of the system for joysticks this first time + SDL_SYS_JoystickDetect(); + if ((s_bXInputEnabled) && (WIN_LoadXInputDLL() == -1)) { + s_bXInputEnabled = SDL_FALSE; /* oh well. */ + } if ( !s_threadJoystick ) { @@ -806,7 +824,7 @@ void SDL_SYS_JoystickDetect() pCurList = SYS_Joystick; SYS_Joystick = NULL; s_iNewGUID = 0; - SDL_mutexP( s_mutexJoyStickEnum ); + SDL_LockMutex( s_mutexJoyStickEnum ); if ( !s_pKnownJoystickGUIDs ) s_pKnownJoystickGUIDs = SDL_malloc( sizeof(GUID)*MAX_JOYSTICKS ); @@ -819,7 +837,7 @@ void SDL_SYS_JoystickDetect() EnumJoysticksCallback, &pCurList, DIEDFL_ATTACHEDONLY); - SDL_mutexV( s_mutexJoyStickEnum ); + SDL_UnlockMutex( s_mutexJoyStickEnum ); } if ( pCurList ) @@ -934,11 +952,11 @@ SDL_SYS_JoystickOpen(SDL_Joystick * joystick, int device_index) /* allocate memory for system specific hardware data */ joystick->instance_id = joystickdevice->nInstanceID; + joystick->closed = 0; joystick->hwdata = (struct joystick_hwdata *) SDL_malloc(sizeof(struct joystick_hwdata)); if (joystick->hwdata == NULL) { - SDL_OutOfMemory(); - return (-1); + return SDL_OutOfMemory(); } SDL_memset(joystick->hwdata, 0, sizeof(struct joystick_hwdata)); joystick->hwdata->buffered = 1; @@ -959,11 +977,12 @@ SDL_SYS_JoystickOpen(SDL_Joystick * joystick, int device_index) userId++; } - if ( XINPUTGETCAPABILITIES ) + if ( s_bXInputEnabled && XINPUTGETCAPABILITIES ) { result = XINPUTGETCAPABILITIES( userId, XINPUT_FLAG_GAMEPAD, &capabilities ); if ( result == ERROR_SUCCESS ) { + const SDL_bool bIs14OrLater = (SDL_XInputVersion >= ((1<<16)|4)); SDL_bool bIsSupported = SDL_FALSE; // Current version of XInput mistakenly returns 0 as the Type. Ignore it and ensure the subtype is a gamepad. bIsSupported = ( capabilities.SubType == XINPUT_DEVSUBTYPE_GAMEPAD ); @@ -976,6 +995,9 @@ SDL_SYS_JoystickOpen(SDL_Joystick * joystick, int device_index) { // valid joystick->hwdata->bXInputDevice = SDL_TRUE; + if ((!bIs14OrLater) || (capabilities.Flags & XINPUT_CAPS_FFB_SUPPORTED)) { + joystick->hwdata->bXInputHaptic = SDL_TRUE; + } SDL_memset( joystick->hwdata->XInputState, 0x0, sizeof(joystick->hwdata->XInputState) ); joystickdevice->XInputUserId = userId; joystick->hwdata->userid = userId; @@ -1006,8 +1028,7 @@ SDL_SYS_JoystickOpen(SDL_Joystick * joystick, int device_index) IDirectInput8_CreateDevice(dinput, &(joystickdevice->dxdevice.guidInstance), &device, NULL); if (FAILED(result)) { - SetDIerror("IDirectInput::CreateDevice", result); - return (-1); + return SetDIerror("IDirectInput::CreateDevice", result); } /* Now get the IDirectInputDevice8 interface, instead. */ @@ -1019,8 +1040,7 @@ SDL_SYS_JoystickOpen(SDL_Joystick * joystick, int device_index) IDirectInputDevice8_Release(device); if (FAILED(result)) { - SetDIerror("IDirectInputDevice8::QueryInterface", result); - return (-1); + return SetDIerror("IDirectInputDevice8::QueryInterface", result); } /* Aquire shared access. Exclusive access is required for forces, @@ -1031,8 +1051,7 @@ SDL_SYS_JoystickOpen(SDL_Joystick * joystick, int device_index) DISCL_NONEXCLUSIVE | DISCL_BACKGROUND); if (FAILED(result)) { - SetDIerror("IDirectInputDevice8::SetCooperativeLevel", result); - return (-1); + return SetDIerror("IDirectInputDevice8::SetCooperativeLevel", result); } /* Use the extended data structure: DIJOYSTATE2. */ @@ -1040,8 +1059,7 @@ SDL_SYS_JoystickOpen(SDL_Joystick * joystick, int device_index) IDirectInputDevice8_SetDataFormat(joystick->hwdata->InputDevice, &c_dfDIJoystick2); if (FAILED(result)) { - SetDIerror("IDirectInputDevice8::SetDataFormat", result); - return (-1); + return SetDIerror("IDirectInputDevice8::SetDataFormat", result); } /* Get device capabilities */ @@ -1050,8 +1068,7 @@ SDL_SYS_JoystickOpen(SDL_Joystick * joystick, int device_index) &joystick->hwdata->Capabilities); if (FAILED(result)) { - SetDIerror("IDirectInputDevice8::GetCapabilities", result); - return (-1); + return SetDIerror("IDirectInputDevice8::GetCapabilities", result); } /* Force capable? */ @@ -1060,8 +1077,7 @@ SDL_SYS_JoystickOpen(SDL_Joystick * joystick, int device_index) result = IDirectInputDevice8_Acquire(joystick->hwdata->InputDevice); if (FAILED(result)) { - SetDIerror("IDirectInputDevice8::Acquire", result); - return (-1); + return SetDIerror("IDirectInputDevice8::Acquire", result); } /* reset all accuators. */ @@ -1072,17 +1088,14 @@ SDL_SYS_JoystickOpen(SDL_Joystick * joystick, int device_index) /* Not necessarily supported, ignore if not supported. if (FAILED(result)) { - SetDIerror("IDirectInputDevice8::SendForceFeedbackCommand", - result); - return (-1); + return SetDIerror("IDirectInputDevice8::SendForceFeedbackCommand", result); } */ result = IDirectInputDevice8_Unacquire(joystick->hwdata->InputDevice); if (FAILED(result)) { - SetDIerror("IDirectInputDevice8::Unacquire", result); - return (-1); + return SetDIerror("IDirectInputDevice8::Unacquire", result); } /* Turn on auto-centering for a ForceFeedback device (until told @@ -1097,8 +1110,7 @@ SDL_SYS_JoystickOpen(SDL_Joystick * joystick, int device_index) /* Not necessarily supported, ignore if not supported. if (FAILED(result)) { - SetDIerror("IDirectInputDevice8::SetProperty", result); - return (-1); + return SetDIerror("IDirectInputDevice8::SetProperty", result); } */ } @@ -1126,8 +1138,7 @@ SDL_SYS_JoystickOpen(SDL_Joystick * joystick, int device_index) * to use less reliable polling. */ joystick->hwdata->buffered = 0; } else if (FAILED(result)) { - SetDIerror("IDirectInputDevice8::SetProperty", result); - return (-1); + return SetDIerror("IDirectInputDevice8::SetProperty", result); } } return (0); @@ -1669,11 +1680,9 @@ SDL_SYS_JoystickQuit(void) s_pKnownJoystickGUIDs = NULL; } - if ( s_pXInputDLL ) - { - FreeLibrary( s_pXInputDLL ); - s_pXInputDLL = NULL; - } + if (s_bXInputEnabled) { + WIN_UnloadXInputDLL(); + } } diff --git a/src/joystick/windows/SDL_dxjoystick_c.h b/src/joystick/windows/SDL_dxjoystick_c.h index 631bab7452..13d0d451a8 100644 --- a/src/joystick/windows/SDL_dxjoystick_c.h +++ b/src/joystick/windows/SDL_dxjoystick_c.h @@ -42,6 +42,65 @@ #include <xinput.h> #include <devguid.h> #include <dbt.h> +#include <xinput.h> + +/* typedef's for XInput structs we use */ +typedef struct +{ + WORD wButtons; + BYTE bLeftTrigger; + BYTE bRightTrigger; + SHORT sThumbLX; + SHORT sThumbLY; + SHORT sThumbRX; + SHORT sThumbRY; + DWORD dwPaddingReserved; +} XINPUT_GAMEPAD_EX; + +typedef struct +{ + DWORD dwPacketNumber; + XINPUT_GAMEPAD_EX Gamepad; +} XINPUT_STATE_EX; + +/* Forward decl's for XInput API's we load dynamically and use if available */ +typedef DWORD (WINAPI *XInputGetState_t) + ( + DWORD dwUserIndex, // [in] Index of the gamer associated with the device + XINPUT_STATE_EX* pState // [out] Receives the current state + ); + +typedef DWORD (WINAPI *XInputSetState_t) + ( + DWORD dwUserIndex, // [in] Index of the gamer associated with the device + XINPUT_VIBRATION* pVibration // [in, out] The vibration information to send to the controller + ); + +typedef DWORD (WINAPI *XInputGetCapabilities_t) + ( + DWORD dwUserIndex, // [in] Index of the gamer associated with the device + DWORD dwFlags, // [in] Input flags that identify the device type + XINPUT_CAPABILITIES* pCapabilities // [out] Receives the capabilities + ); + +extern int WIN_LoadXInputDLL(void); +extern void WIN_UnloadXInputDLL(void); + +extern XInputGetState_t SDL_XInputGetState; +extern XInputSetState_t SDL_XInputSetState; +extern XInputGetCapabilities_t SDL_XInputGetCapabilities; +extern DWORD SDL_XInputVersion; // ((major << 16) & 0xFF00) | (minor & 0xFF) + +#define XINPUTGETSTATE SDL_XInputGetState +#define XINPUTSETSTATE SDL_XInputSetState +#define XINPUTGETCAPABILITIES SDL_XInputGetCapabilities +#define INVALID_XINPUT_USERID 255 +#define SDL_XINPUT_MAX_DEVICES 4 + +#ifndef XINPUT_CAPS_FFB_SUPPORTED +#define XINPUT_CAPS_FFB_SUPPORTED 0x0001 +#endif + #define MAX_INPUTS 256 /* each joystick can have up to 256 inputs */ @@ -62,25 +121,6 @@ typedef struct input_t Uint8 num; } input_t; -/* typedef's for XInput structs we use */ -typedef struct -{ - WORD wButtons; - BYTE bLeftTrigger; - BYTE bRightTrigger; - SHORT sThumbLX; - SHORT sThumbLY; - SHORT sThumbRX; - SHORT sThumbRY; - DWORD dwPaddingReserved; -} XINPUT_GAMEPAD_EX; - -typedef struct -{ - DWORD dwPacketNumber; - XINPUT_GAMEPAD_EX Gamepad; -} XINPUT_STATE_EX; - /* The private structure used to keep track of a joystick */ struct joystick_hwdata { @@ -95,6 +135,7 @@ struct joystick_hwdata Uint8 removed; Uint8 send_remove_event; Uint8 bXInputDevice; // 1 if this device supports using the xinput API rather than DirectInput + Uint8 bXInputHaptic; // Supports force feedback via XInput. Uint8 userid; // XInput userid index for this joystick Uint8 currentXInputSlot; // the current position to write to in XInputState below, used so we can compare old and new values XINPUT_STATE_EX XInputState[2]; diff --git a/src/joystick/windows/SDL_mmjoystick.c b/src/joystick/windows/SDL_mmjoystick.c index bf67c9579b..73ad7fb955 100644 --- a/src/joystick/windows/SDL_mmjoystick.c +++ b/src/joystick/windows/SDL_mmjoystick.c @@ -244,8 +244,7 @@ SDL_SYS_JoystickOpen(SDL_Joystick * joystick, int device_index) joystick->hwdata = (struct joystick_hwdata *) SDL_malloc(sizeof(*joystick->hwdata)); if (joystick->hwdata == NULL) { - SDL_OutOfMemory(); - return (-1); + return SDL_OutOfMemory(); } SDL_memset(joystick->hwdata, 0, sizeof(*joystick->hwdata)); diff --git a/src/main/beos/SDL_BApp.h b/src/main/beos/SDL_BApp.h index 5ac2855514..5bde94c183 100644 --- a/src/main/beos/SDL_BApp.h +++ b/src/main/beos/SDL_BApp.h @@ -221,7 +221,7 @@ private: return; } win = GetSDLWindow(winID); - SDL_SendMouseMotion(win, 0, x, y); + SDL_SendMouseMotion(win, 0, 0, x, y); /* Tell the application that the mouse passed over, redraw needed */ BE_UpdateWindowFramebuffer(NULL,win,NULL,-1); @@ -239,7 +239,7 @@ private: return; } win = GetSDLWindow(winID); - SDL_SendMouseButton(win, state, button); + SDL_SendMouseButton(win, 0, state, button); } void _HandleMouseWheel(BMessage *msg) { @@ -254,7 +254,7 @@ private: return; } win = GetSDLWindow(winID); - SDL_SendMouseWheel(win, xTicks, yTicks); + SDL_SendMouseWheel(win, 0, xTicks, yTicks); } void _HandleKey(BMessage *msg) { diff --git a/src/main/beos/SDL_BeApp.cc b/src/main/beos/SDL_BeApp.cc index ae5e9ad1c0..fb622ab1dd 100644 --- a/src/main/beos/SDL_BeApp.cc +++ b/src/main/beos/SDL_BeApp.cc @@ -20,7 +20,7 @@ */ #include "SDL_config.h" -#ifdef __BEOS__ +#if defined(__BEOS__) || defined(__HAIKU__) /* Handle the BeApp specific portions of the application */ @@ -64,8 +64,7 @@ SDL_InitBeApp(void) if (SDL_BeAppActive <= 0) { SDL_AppThread = SDL_CreateThread(StartBeApp, "SDLApplication", NULL); if (SDL_AppThread == NULL) { - SDL_SetError("Couldn't create BApplication thread"); - return (-1); + return SDL_SetError("Couldn't create BApplication thread"); } /* Change working to directory to that of executable */ diff --git a/src/main/psp/SDL_psp_main.c b/src/main/psp/SDL_psp_main.c new file mode 100644 index 0000000000..0286eadecd --- /dev/null +++ b/src/main/psp/SDL_psp_main.c @@ -0,0 +1,80 @@ +/* + Simple DirectMedia Layer + Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org> + + This software is provided 'as-is', without any express or implied + warranty. In no event will the authors be held liable for any damages + arising from the use of this software. + + Permission is granted to anyone to use this software for any purpose, + including commercial applications, and to alter it and redistribute it + freely, subject to the following restrictions: + + 1. The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original software. + 3. This notice may not be removed or altered from any source distribution. +*/ + +#include "SDL_main.h" +#include <pspkernel.h> +#include <pspdebug.h> +#include <pspsdk.h> +#include <pspthreadman.h> +#include <stdlib.h> +#include <stdio.h> + +/* If application's main() is redefined as SDL_main, and libSDLmain is + linked, then this file will create the standard exit callback, + define the PSP_MODULE_INFO macro, and exit back to the browser when + the program is finished. + + You can still override other parameters in your own code if you + desire, such as PSP_HEAP_SIZE_KB, PSP_MAIN_THREAD_ATTR, + PSP_MAIN_THREAD_STACK_SIZE, etc. +*/ + +extern int SDL_main(int argc, char *argv[]); + +PSP_MODULE_INFO("SDL App", 0, 1, 1); + +int sdl_psp_exit_callback(int arg1, int arg2, void *common) +{ + exit(0); + return 0; +} + +int sdl_psp_callback_thread(SceSize args, void *argp) +{ + int cbid; + cbid = sceKernelCreateCallback("Exit Callback", + sdl_psp_exit_callback, NULL); + sceKernelRegisterExitCallback(cbid); + sceKernelSleepThreadCB(); + return 0; +} + +int sdl_psp_setup_callbacks(void) +{ + int thid = 0; + thid = sceKernelCreateThread("update_thread", + sdl_psp_callback_thread, 0x11, 0xFA0, 0, 0); + if(thid >= 0) + sceKernelStartThread(thid, 0, 0); + return thid; +} + +int main(int argc, char *argv[]) +{ + pspDebugScreenInit(); + sdl_psp_setup_callbacks(); + + /* Register sceKernelExitGame() to be called when we exit */ + atexit(sceKernelExitGame); + + (void)SDL_main(argc, argv); + return 0; +} diff --git a/src/power/SDL_power.c b/src/power/SDL_power.c index b8ad3657d6..b8f3ae40fc 100644 --- a/src/power/SDL_power.c +++ b/src/power/SDL_power.c @@ -34,9 +34,9 @@ SDL_bool SDL_GetPowerInfo_Linux_proc_apm(SDL_PowerState *, int *, int *); SDL_bool SDL_GetPowerInfo_Windows(SDL_PowerState *, int *, int *); SDL_bool SDL_GetPowerInfo_MacOSX(SDL_PowerState *, int *, int *); SDL_bool SDL_GetPowerInfo_BeOS(SDL_PowerState *, int *, int *); -SDL_bool SDL_GetPowerInfo_NintendoDS(SDL_PowerState *, int *, int *); SDL_bool SDL_GetPowerInfo_UIKit(SDL_PowerState *, int *, int *); SDL_bool SDL_GetPowerInfo_Android(SDL_PowerState *, int *, int *); +SDL_bool SDL_GetPowerInfo_PSP(SDL_PowerState *, int *, int *); #ifndef SDL_POWER_DISABLED #ifdef SDL_POWER_HARDWIRED @@ -68,15 +68,16 @@ static SDL_GetPowerInfo_Impl implementations[] = { #ifdef SDL_POWER_MACOSX /* handles Mac OS X, Darwin. */ SDL_GetPowerInfo_MacOSX, #endif -#ifdef SDL_POWER_NINTENDODS /* handles Nintendo DS. */ - SDL_GetPowerInfo_NintendoDS, -#endif #ifdef SDL_POWER_BEOS /* handles BeOS, Zeta, with euc.jp apm driver. */ SDL_GetPowerInfo_BeOS, #endif #ifdef SDL_POWER_ANDROID /* handles Android. */ SDL_GetPowerInfo_Android, #endif +#ifdef SDL_POWER_PSP /* handles PSP. */ + SDL_GetPowerInfo_PSP, +#endif + #ifdef SDL_POWER_HARDWIRED SDL_GetPowerInfo_Hardwired, #endif diff --git a/src/power/nds/SDL_syspower.c b/src/power/psp/SDL_syspower.c index 0a1a01ce2a..363c952d00 100644 --- a/src/power/nds/SDL_syspower.c +++ b/src/power/psp/SDL_syspower.c @@ -18,27 +18,51 @@ misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ + #include "SDL_config.h" #ifndef SDL_POWER_DISABLED -#if SDL_POWER_NINTENDODS +#if SDL_POWER_PSP #include "SDL_power.h" +#include <psppower.h> + SDL_bool -SDL_GetPowerInfo_NintendoDS(SDL_PowerState * state, int *seconds, +SDL_GetPowerInfo_PSP(SDL_PowerState * state, int *seconds, int *percent) { - /* !!! FIXME: write me. */ + int battery = scePowerIsBatteryExist(); + int plugged = scePowerIsPowerOnline(); + int charging = scePowerIsBatteryCharging(); *state = SDL_POWERSTATE_UNKNOWN; - *percent = -1; - *seconds = -1; + *seconds = -1; + *percent = -1; + + if (!battery) { + *state = SDL_POWERSTATE_NO_BATTERY; + *seconds = -1; + *percent = -1; + } else if (charging) { + *state = SDL_POWERSTATE_CHARGING; + *percent = scePowerGetBatteryLifePercent(); + *seconds = scePowerGetBatteryLifeTime()*60; + } else if (plugged) { + *state = SDL_POWERSTATE_CHARGED; + *percent = scePowerGetBatteryLifePercent(); + *seconds = scePowerGetBatteryLifeTime()*60; + } else { + *state = SDL_POWERSTATE_ON_BATTERY; + *percent = scePowerGetBatteryLifePercent(); + *seconds = scePowerGetBatteryLifeTime()*60; + } - return SDL_TRUE; /* always the definitive answer on Nintendo DS. */ + + return SDL_TRUE; /* always the definitive answer on PSP. */ } -#endif /* SDL_POWER_NINTENDODS */ +#endif /* SDL_POWER_PSP */ #endif /* SDL_POWER_DISABLED */ /* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/render/SDL_render.c b/src/render/SDL_render.c index da2511ee8a..0009606fb5 100644 --- a/src/render/SDL_render.c +++ b/src/render/SDL_render.c @@ -64,8 +64,8 @@ static const SDL_RenderDriver *render_drivers[] = { #if SDL_VIDEO_RENDER_DIRECTFB &DirectFB_RenderDriver, #endif -#if SDL_VIDEO_RENDER_NDS - &NDS_RenderDriver, +#if SDL_VIDEO_RENDER_PSP + &PSP_RenderDriver, #endif &SW_RenderDriver, #if SDL_VIDEO_RENDER_D3D11 @@ -89,9 +89,8 @@ int SDL_GetRenderDriverInfo(int index, SDL_RendererInfo * info) { if (index < 0 || index >= SDL_GetNumRenderDrivers()) { - SDL_SetError("index must be in the range of 0 - %d", - SDL_GetNumRenderDrivers() - 1); - return -1; + return SDL_SetError("index must be in the range of 0 - %d", + SDL_GetNumRenderDrivers() - 1); } *info = render_drivers[index]->info; return 0; @@ -702,8 +701,7 @@ SDL_UpdateTextureYUV(SDL_Texture * texture, const SDL_Rect * rect, temp_pitch = (((rect->w * SDL_BYTESPERPIXEL(native->format)) + 3) & ~3); temp_pixels = SDL_malloc(rect->h * temp_pitch); if (!temp_pixels) { - SDL_OutOfMemory(); - return -1; + return SDL_OutOfMemory(); } SDL_SW_CopyYUVToRGB(texture->yuv, rect, native->format, rect->w, rect->h, temp_pixels, temp_pitch); @@ -739,8 +737,7 @@ SDL_UpdateTextureNative(SDL_Texture * texture, const SDL_Rect * rect, temp_pitch = (((rect->w * SDL_BYTESPERPIXEL(native->format)) + 3) & ~3); temp_pixels = SDL_malloc(rect->h * temp_pitch); if (!temp_pixels) { - SDL_OutOfMemory(); - return -1; + return SDL_OutOfMemory(); } SDL_ConvertPixels(rect->w, rect->h, texture->format, pixels, pitch, @@ -807,8 +804,7 @@ SDL_LockTexture(SDL_Texture * texture, const SDL_Rect * rect, CHECK_TEXTURE_MAGIC(texture, -1); if (texture->access != SDL_TEXTUREACCESS_STREAMING) { - SDL_SetError("SDL_LockTexture(): texture must be streaming"); - return -1; + return SDL_SetError("SDL_LockTexture(): texture must be streaming"); } if (!rect) { @@ -904,8 +900,7 @@ int SDL_SetRenderTarget(SDL_Renderer *renderer, SDL_Texture *texture) { if (!SDL_RenderTargetSupported(renderer)) { - SDL_Unsupported(); - return -1; + return SDL_Unsupported(); } if (texture == renderer->target) { /* Nothing to do! */ @@ -916,12 +911,10 @@ SDL_SetRenderTarget(SDL_Renderer *renderer, SDL_Texture *texture) if (texture) { CHECK_TEXTURE_MAGIC(texture, -1); if (renderer != texture->renderer) { - SDL_SetError("Texture was not created with this renderer"); - return -1; + return SDL_SetError("Texture was not created with this renderer"); } if (texture->access != SDL_TEXTUREACCESS_TARGET) { - SDL_SetError("Texture not created with SDL_TEXTUREACCESS_TARGET"); - return -1; + return SDL_SetError("Texture not created with SDL_TEXTUREACCESS_TARGET"); } if (texture->native) { /* Always render to the native texture */ @@ -986,8 +979,7 @@ UpdateLogicalSize(SDL_Renderer *renderer) SDL_GetWindowSize(renderer->window, &w, &h); } else { /* FIXME */ - SDL_SetError("Internal error: No way to get output resolution"); - return -1; + return SDL_SetError("Internal error: No way to get output resolution"); } want_aspect = (float)renderer->logical_w / renderer->logical_h; @@ -1205,8 +1197,7 @@ RenderDrawPointsWithRects(SDL_Renderer * renderer, frects = SDL_stack_alloc(SDL_FRect, count); if (!frects) { - SDL_OutOfMemory(); - return -1; + return SDL_OutOfMemory(); } for (i = 0; i < count; ++i) { frects[i].x = points[i].x * renderer->scale.x; @@ -1233,8 +1224,7 @@ SDL_RenderDrawPoints(SDL_Renderer * renderer, CHECK_RENDERER_MAGIC(renderer, -1); if (!points) { - SDL_SetError("SDL_RenderDrawPoints(): Passed NULL points"); - return -1; + return SDL_SetError("SDL_RenderDrawPoints(): Passed NULL points"); } if (count < 1) { return 0; @@ -1250,8 +1240,7 @@ SDL_RenderDrawPoints(SDL_Renderer * renderer, fpoints = SDL_stack_alloc(SDL_FPoint, count); if (!fpoints) { - SDL_OutOfMemory(); - return -1; + return SDL_OutOfMemory(); } for (i = 0; i < count; ++i) { fpoints[i].x = points[i].x * renderer->scale.x; @@ -1289,8 +1278,7 @@ RenderDrawLinesWithRects(SDL_Renderer * renderer, frects = SDL_stack_alloc(SDL_FRect, count-1); if (!frects) { - SDL_OutOfMemory(); - return -1; + return SDL_OutOfMemory(); } status = 0; @@ -1345,8 +1333,7 @@ SDL_RenderDrawLines(SDL_Renderer * renderer, CHECK_RENDERER_MAGIC(renderer, -1); if (!points) { - SDL_SetError("SDL_RenderDrawLines(): Passed NULL points"); - return -1; + return SDL_SetError("SDL_RenderDrawLines(): Passed NULL points"); } if (count < 2) { return 0; @@ -1362,8 +1349,7 @@ SDL_RenderDrawLines(SDL_Renderer * renderer, fpoints = SDL_stack_alloc(SDL_FPoint, count); if (!fpoints) { - SDL_OutOfMemory(); - return -1; + return SDL_OutOfMemory(); } for (i = 0; i < count; ++i) { fpoints[i].x = points[i].x * renderer->scale.x; @@ -1415,8 +1401,7 @@ SDL_RenderDrawRects(SDL_Renderer * renderer, CHECK_RENDERER_MAGIC(renderer, -1); if (!rects) { - SDL_SetError("SDL_RenderDrawRects(): Passed NULL rects"); - return -1; + return SDL_SetError("SDL_RenderDrawRects(): Passed NULL rects"); } if (count < 1) { return 0; @@ -1462,8 +1447,7 @@ SDL_RenderFillRects(SDL_Renderer * renderer, CHECK_RENDERER_MAGIC(renderer, -1); if (!rects) { - SDL_SetError("SDL_RenderFillRects(): Passed NULL rects"); - return -1; + return SDL_SetError("SDL_RenderFillRects(): Passed NULL rects"); } if (count < 1) { return 0; @@ -1475,8 +1459,7 @@ SDL_RenderFillRects(SDL_Renderer * renderer, frects = SDL_stack_alloc(SDL_FRect, count); if (!frects) { - SDL_OutOfMemory(); - return -1; + return SDL_OutOfMemory(); } for (i = 0; i < count; ++i) { frects[i].x = rects[i].x * renderer->scale.x; @@ -1504,8 +1487,7 @@ SDL_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture, CHECK_TEXTURE_MAGIC(texture, -1); if (renderer != texture->renderer) { - SDL_SetError("Texture was not created with this renderer"); - return -1; + return SDL_SetError("Texture was not created with this renderer"); } real_srcrect.x = 0; @@ -1573,12 +1555,10 @@ SDL_RenderCopyEx(SDL_Renderer * renderer, SDL_Texture * texture, CHECK_TEXTURE_MAGIC(texture, -1); if (renderer != texture->renderer) { - SDL_SetError("Texture was not created with this renderer"); - return -1; + return SDL_SetError("Texture was not created with this renderer"); } if (!renderer->RenderCopyEx) { - SDL_SetError("Renderer does not support RenderCopyEx"); - return -1; + return SDL_SetError("Renderer does not support RenderCopyEx"); } real_srcrect.x = 0; @@ -1630,8 +1610,7 @@ SDL_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect, CHECK_RENDERER_MAGIC(renderer, -1); if (!renderer->RenderReadPixels) { - SDL_Unsupported(); - return -1; + return SDL_Unsupported(); } if (!format) { @@ -1736,8 +1715,7 @@ int SDL_GL_BindTexture(SDL_Texture *texture, float *texw, float *texh) return renderer->GL_BindTexture(renderer, texture, texw, texh); } - SDL_Unsupported(); - return -1; + return SDL_Unsupported(); } int SDL_GL_UnbindTexture(SDL_Texture *texture) @@ -1750,8 +1728,7 @@ int SDL_GL_UnbindTexture(SDL_Texture *texture) return renderer->GL_UnbindTexture(renderer, texture); } - SDL_Unsupported(); - return -1; + return SDL_Unsupported(); } /* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/render/SDL_sysrender.h b/src/render/SDL_sysrender.h index 5929f11b62..83673c18b6 100644 --- a/src/render/SDL_sysrender.h +++ b/src/render/SDL_sysrender.h @@ -176,8 +176,8 @@ extern SDL_RenderDriver GLES_RenderDriver; #if SDL_VIDEO_RENDER_DIRECTFB extern SDL_RenderDriver DirectFB_RenderDriver; #endif -#if SDL_VIDEO_RENDER_NDS -extern SDL_RenderDriver NDS_RenderDriver; +#if SDL_VIDEO_RENDER_PSP +extern SDL_RenderDriver PSP_RenderDriver; #endif extern SDL_RenderDriver SW_RenderDriver; diff --git a/src/render/SDL_yuv_sw.c b/src/render/SDL_yuv_sw.c index 47de2aff20..9f04c21ca3 100644 --- a/src/render/SDL_yuv_sw.c +++ b/src/render/SDL_yuv_sw.c @@ -896,8 +896,7 @@ SDL_SW_SetupYUVDisplay(SDL_SW_YUVTexture * swdata, Uint32 target_format) if (!SDL_PixelFormatEnumToMasks (target_format, &bpp, &Rmask, &Gmask, &Bmask, &Amask) || bpp < 15) { - SDL_SetError("Unsupported YUV destination format"); - return -1; + return SDL_SetError("Unsupported YUV destination format"); } swdata->target_format = target_format; @@ -1057,8 +1056,8 @@ SDL_SW_CreateYUVTexture(Uint32 format, int w, int h) swdata->colortab = (int *) SDL_malloc(4 * 256 * sizeof(int)); swdata->rgb_2_pix = (Uint32 *) SDL_malloc(3 * 768 * sizeof(Uint32)); if (!swdata->pixels || !swdata->colortab || !swdata->rgb_2_pix) { - SDL_OutOfMemory(); SDL_SW_DestroyYUVTexture(swdata); + SDL_OutOfMemory(); return NULL; } @@ -1197,9 +1196,8 @@ SDL_SW_LockYUVTexture(SDL_SW_YUVTexture * swdata, const SDL_Rect * rect, if (rect && (rect->x != 0 || rect->y != 0 || rect->w != swdata->w || rect->h != swdata->h)) { - SDL_SetError + return SDL_SetError ("YV12 and IYUV textures only support full surface locks"); - return -1; } break; } @@ -1309,8 +1307,7 @@ SDL_SW_CopyYUVToRGB(SDL_SW_YUVTexture * swdata, const SDL_Rect * srcrect, Cb = lum + 3; break; default: - SDL_SetError("Unsupported YUV format in copy"); - return (-1); + return SDL_SetError("Unsupported YUV format in copy"); } mod = (pitch / SDL_BYTESPERPIXEL(target_format)); diff --git a/src/render/direct3d/SDL_render_d3d.c b/src/render/direct3d/SDL_render_d3d.c index a183413c41..f75d3a98e4 100644 --- a/src/render/direct3d/SDL_render_d3d.c +++ b/src/render/direct3d/SDL_render_d3d.c @@ -246,7 +246,7 @@ typedef struct float u, v; } Vertex; -static void +static int D3D_SetError(const char *prefix, HRESULT result) { const char *error; @@ -322,7 +322,7 @@ D3D_SetError(const char *prefix, HRESULT result) error = "UNKNOWN"; break; } - SDL_SetError("%s: %s", prefix, error); + return SDL_SetError("%s: %s", prefix, error); } static D3DFORMAT @@ -373,8 +373,7 @@ D3D_Reset(SDL_Renderer * renderer) /* Don't worry about it, we'll reset later... */ return 0; } else { - D3D_SetError("Reset()", result); - return -1; + return D3D_SetError("Reset()", result); } } IDirect3DDevice9_SetVertexShader(data->device, NULL); @@ -422,8 +421,7 @@ D3D_ActivateRenderer(SDL_Renderer * renderer) result = IDirect3DDevice9_BeginScene(data->device); } if (FAILED(result)) { - D3D_SetError("BeginScene()", result); - return -1; + return D3D_SetError("BeginScene()", result); } data->beginScene = SDL_FALSE; } @@ -476,8 +474,11 @@ D3D_CreateRenderer(SDL_Window * window, Uint32 flags) } for (d3dxVersion=50;d3dxVersion>0;d3dxVersion--) { - SDL_snprintf(d3dxDLLFile, 49, "D3DX9_%02d.dll", d3dxVersion); - data->d3dxDLL = SDL_LoadObject(d3dxDLLFile); + LPTSTR dllName; + SDL_snprintf(d3dxDLLFile, sizeof(d3dxDLLFile), "D3DX9_%02d.dll", d3dxVersion); + dllName = WIN_UTF8ToString(d3dxDLLFile); + data->d3dxDLL = (void *)LoadLibrary(dllName); /* not using SDL_LoadObject() as we want silently fail - no error message */ + SDL_free(dllName); if (data->d3dxDLL) { HRESULT (WINAPI *D3DXCreateMatrixStack) (DWORD Flags, LPD3DXMATRIXSTACK* ppStack); D3DXCreateMatrixStack = (HRESULT (WINAPI *) (DWORD, LPD3DXMATRIXSTACK*)) SDL_LoadFunction(data->d3dxDLL, "D3DXCreateMatrixStack"); @@ -701,8 +702,7 @@ D3D_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture) data = (D3D_TextureData *) SDL_calloc(1, sizeof(*data)); if (!data) { - SDL_OutOfMemory(); - return -1; + return SDL_OutOfMemory(); } data->scaleMode = GetScaleQuality(); @@ -729,8 +729,7 @@ D3D_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture) PixelFormatToD3DFMT(texture->format), pool, &data->texture, NULL); if (FAILED(result)) { - D3D_SetError("CreateTexture()", result); - return -1; + return D3D_SetError("CreateTexture()", result); } return 0; @@ -764,8 +763,7 @@ D3D_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture, } if (FAILED(result)) { - D3D_SetError("LockRect()", result); - return -1; + return D3D_SetError("LockRect()", result); } src = pixels; @@ -801,8 +799,7 @@ D3D_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture, result = IDirect3DTexture9_LockRect(data->texture, 0, &locked, &d3drect, 0); if (FAILED(result)) { - D3D_SetError("LockRect()", result); - return -1; + return D3D_SetError("LockRect()", result); } *pixels = locked.pBits; *pitch = locked.Pitch; @@ -878,13 +875,11 @@ D3D_SetRenderTarget(SDL_Renderer * renderer, SDL_Texture * texture) texturedata = (D3D_TextureData *) texture->driverdata; result = IDirect3DTexture9_GetSurfaceLevel(texturedata->texture, 0, &data->currentRenderTarget); if(FAILED(result)) { - D3D_SetError("GetSurfaceLevel()", result); - return -1; + return D3D_SetError("GetSurfaceLevel()", result); } result = IDirect3DDevice9_SetRenderTarget(data->device, 0, data->currentRenderTarget); if(FAILED(result)) { - D3D_SetError("SetRenderTarget()", result); - return -1; + return D3D_SetError("SetRenderTarget()", result); } return 0; @@ -933,8 +928,7 @@ D3D_RenderClear(SDL_Renderer * renderer) } if (FAILED(result)) { - D3D_SetError("Clear()", result); - return -1; + return D3D_SetError("Clear()", result); } return 0; } @@ -994,8 +988,7 @@ D3D_RenderDrawPoints(SDL_Renderer * renderer, const SDL_FPoint * points, IDirect3DDevice9_SetTexture(data->device, 0, (IDirect3DBaseTexture9 *) 0); if (FAILED(result)) { - D3D_SetError("SetTexture()", result); - return -1; + return D3D_SetError("SetTexture()", result); } color = D3DCOLOR_ARGB(renderer->a, renderer->r, renderer->g, renderer->b); @@ -1014,8 +1007,7 @@ D3D_RenderDrawPoints(SDL_Renderer * renderer, const SDL_FPoint * points, vertices, sizeof(*vertices)); SDL_stack_free(vertices); if (FAILED(result)) { - D3D_SetError("DrawPrimitiveUP()", result); - return -1; + return D3D_SetError("DrawPrimitiveUP()", result); } return 0; } @@ -1040,8 +1032,7 @@ D3D_RenderDrawLines(SDL_Renderer * renderer, const SDL_FPoint * points, IDirect3DDevice9_SetTexture(data->device, 0, (IDirect3DBaseTexture9 *) 0); if (FAILED(result)) { - D3D_SetError("SetTexture()", result); - return -1; + return D3D_SetError("SetTexture()", result); } color = D3DCOLOR_ARGB(renderer->a, renderer->r, renderer->g, renderer->b); @@ -1070,8 +1061,7 @@ D3D_RenderDrawLines(SDL_Renderer * renderer, const SDL_FPoint * points, SDL_stack_free(vertices); if (FAILED(result)) { - D3D_SetError("DrawPrimitiveUP()", result); - return -1; + return D3D_SetError("DrawPrimitiveUP()", result); } return 0; } @@ -1097,8 +1087,7 @@ D3D_RenderFillRects(SDL_Renderer * renderer, const SDL_FRect * rects, IDirect3DDevice9_SetTexture(data->device, 0, (IDirect3DBaseTexture9 *) 0); if (FAILED(result)) { - D3D_SetError("SetTexture()", result); - return -1; + return D3D_SetError("SetTexture()", result); } color = D3DCOLOR_ARGB(renderer->a, renderer->r, renderer->g, renderer->b); @@ -1143,8 +1132,7 @@ D3D_RenderFillRects(SDL_Renderer * renderer, const SDL_FRect * rects, IDirect3DDevice9_DrawPrimitiveUP(data->device, D3DPT_TRIANGLEFAN, 2, vertices, sizeof(*vertices)); if (FAILED(result)) { - D3D_SetError("DrawPrimitiveUP()", result); - return -1; + return D3D_SetError("DrawPrimitiveUP()", result); } } return 0; @@ -1221,28 +1209,24 @@ D3D_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture, IDirect3DDevice9_SetTexture(data->device, 0, (IDirect3DBaseTexture9 *) texturedata->texture); if (FAILED(result)) { - D3D_SetError("SetTexture()", result); - return -1; + return D3D_SetError("SetTexture()", result); } if (shader) { result = IDirect3DDevice9_SetPixelShader(data->device, shader); if (FAILED(result)) { - D3D_SetError("SetShader()", result); - return -1; + return D3D_SetError("SetShader()", result); } } result = IDirect3DDevice9_DrawPrimitiveUP(data->device, D3DPT_TRIANGLEFAN, 2, vertices, sizeof(*vertices)); if (FAILED(result)) { - D3D_SetError("DrawPrimitiveUP()", result); - return -1; + return D3D_SetError("DrawPrimitiveUP()", result); } if (shader) { result = IDirect3DDevice9_SetPixelShader(data->device, NULL); if (FAILED(result)) { - D3D_SetError("SetShader()", result); - return -1; + return D3D_SetError("SetShader()", result); } } return 0; @@ -1345,28 +1329,24 @@ D3D_RenderCopyEx(SDL_Renderer * renderer, SDL_Texture * texture, IDirect3DDevice9_SetTexture(data->device, 0, (IDirect3DBaseTexture9 *) texturedata->texture); if (FAILED(result)) { - D3D_SetError("SetTexture()", result); - return -1; + return D3D_SetError("SetTexture()", result); } if (shader) { result = IDirect3DDevice9_SetPixelShader(data->device, shader); if (FAILED(result)) { - D3D_SetError("SetShader()", result); - return -1; + return D3D_SetError("SetShader()", result); } } result = IDirect3DDevice9_DrawPrimitiveUP(data->device, D3DPT_TRIANGLEFAN, 2, vertices, sizeof(*vertices)); if (FAILED(result)) { - D3D_SetError("DrawPrimitiveUP()", result); - return -1; + return D3D_SetError("DrawPrimitiveUP()", result); } if (shader) { result = IDirect3DDevice9_SetPixelShader(data->device, NULL); if (FAILED(result)) { - D3D_SetError("SetShader()", result); - return -1; + return D3D_SetError("SetShader()", result); } } ID3DXMatrixStack_Pop(data->matrixStack); @@ -1391,30 +1371,26 @@ D3D_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect, result = IDirect3DDevice9_GetBackBuffer(data->device, 0, 0, D3DBACKBUFFER_TYPE_MONO, &backBuffer); if (FAILED(result)) { - D3D_SetError("GetBackBuffer()", result); - return -1; + return D3D_SetError("GetBackBuffer()", result); } result = IDirect3DSurface9_GetDesc(backBuffer, &desc); if (FAILED(result)) { - D3D_SetError("GetDesc()", result); IDirect3DSurface9_Release(backBuffer); - return -1; + return D3D_SetError("GetDesc()", result); } result = IDirect3DDevice9_CreateOffscreenPlainSurface(data->device, desc.Width, desc.Height, desc.Format, D3DPOOL_SYSTEMMEM, &surface, NULL); if (FAILED(result)) { - D3D_SetError("CreateOffscreenPlainSurface()", result); IDirect3DSurface9_Release(backBuffer); - return -1; + return D3D_SetError("CreateOffscreenPlainSurface()", result); } result = IDirect3DDevice9_GetRenderTargetData(data->device, backBuffer, surface); if (FAILED(result)) { - D3D_SetError("GetRenderTargetData()", result); IDirect3DSurface9_Release(surface); IDirect3DSurface9_Release(backBuffer); - return -1; + return D3D_SetError("GetRenderTargetData()", result); } d3drect.left = rect->x; @@ -1424,10 +1400,9 @@ D3D_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect, result = IDirect3DSurface9_LockRect(surface, &locked, &d3drect, D3DLOCK_READONLY); if (FAILED(result)) { - D3D_SetError("LockRect()", result); IDirect3DSurface9_Release(surface); IDirect3DSurface9_Release(backBuffer); - return -1; + return D3D_SetError("LockRect()", result); } SDL_ConvertPixels(rect->w, rect->h, diff --git a/src/render/nds/SDL_libgl2D.c b/src/render/nds/SDL_libgl2D.c deleted file mode 100644 index 7ba9be0722..0000000000 --- a/src/render/nds/SDL_libgl2D.c +++ /dev/null @@ -1,315 +0,0 @@ -/* - * Note: The Nintendo DS port to SDL uses excerpts from the libGL2D, - * with permission of the original author. The following is mostly his - * code/comments. - * - * - * Easy GL2D - * - * Relminator 2010 - * Richard Eric M. Lope BSN RN - * - * http://rel.betterwebber.com - * - * A very small and simple DS rendering lib using the 3d core to render 2D stuff - */ -#include "SDL_config.h" - -#if SDL_VIDEO_RENDER_NDS - -#include "SDL_libgl2D.h" - -/* - * Our static global variable used for Depth values since we cannot - * disable depth testing in the DS hardware This value is incremented - * for every draw call. */ -v16 g_depth; -int gCurrentTexture; - -/* - * !!! PRIVATE !!! Set orthographic projection at 1:1 correspondence - * to screen coords glOrtho expects f32 values but if we use the - * standard f32 values, we need to rescale either every vert or the - * modelview matrix by the same amount to make it work. That's gonna - * give us lots of overflows and headaches. So we "scale down" and - * use an all integer value. - */ -void SetOrtho(void) -{ - glMatrixMode(GL_PROJECTION); // set matrixmode to projection - glLoadIdentity(); // reset - glOrthof32(0, SCREEN_WIDTH, SCREEN_HEIGHT, 0, -1 << 12, 1 << 12); // downscale projection matrix -} - -/* - * Initializes GL in 2D mode Also initializes GL in 3d mode so that we - * could combine 2D and 3D later Almost a direct copy from the DS - * example files - */ -void glScreen2D(void) -{ - // initialize gl - glInit(); - - // enable textures - glEnable(GL_TEXTURE_2D); - - // enable antialiasing - glEnable(GL_ANTIALIAS); - - // setup the rear plane - glClearColor(0, 0, 0, 31); // BG must be opaque for AA to work - glClearPolyID(63); // BG must have a unique polygon ID for AA to work - - glClearDepth(GL_MAX_DEPTH); - - // this should work the same as the normal gl call - glViewport(0,0,255,191); - - // any floating point gl call is being converted to fixed prior to being implemented - glMatrixMode(GL_PROJECTION); - glLoadIdentity(); - gluPerspective(70, 256.0 / 192.0, 1, 200); - - gluLookAt( 0.0, 0.0, 1.0, //camera possition - 0.0, 0.0, 0.0, //look at - 0.0, 1.0, 0.0); //up - - glMaterialf(GL_AMBIENT, RGB15(31,31,31)); - glMaterialf(GL_DIFFUSE, RGB15(31,31,31)); - glMaterialf(GL_SPECULAR, BIT(15) | RGB15(31,31,31)); - glMaterialf(GL_EMISSION, RGB15(31,31,31)); - - // ds uses a table for shinyness..this generates a half-ass one - glMaterialShinyness(); - - // not a real gl function and will likely change - glPolyFmt(POLY_ALPHA(31) | POLY_CULL_BACK); -} - -/* - * Sets up OpenGL for 2d rendering Call this before drawing any of - * GL2D's drawing or sprite functions. - */ -void glBegin2D(void) -{ - // save 3d perpective projection matrix - glMatrixMode(GL_PROJECTION); - glPushMatrix(); - - // save 3d modelview matrix for safety - glMatrixMode(GL_MODELVIEW); - glPushMatrix(); - - - // what?!! No glDisable(GL_DEPTH_TEST)?!!!!!! - glEnable(GL_BLEND); - glEnable(GL_TEXTURE_2D); - glDisable(GL_ANTIALIAS); // disable AA - glDisable(GL_OUTLINE); // disable edge-marking - - glColor(0x7FFF); // max color - - glPolyFmt(POLY_ALPHA(31) | POLY_CULL_NONE); // no culling - - SetOrtho(); - - glMatrixMode(GL_TEXTURE); // reset texture matrix just in case we did some funky stuff with it - glLoadIdentity(); - - glMatrixMode(GL_MODELVIEW); // reset modelview matrix. No need to scale up by << 12 - glLoadIdentity(); - - gCurrentTexture = 0; // set current texture to 0 - g_depth = 0; // set depth to 0. We need this var since we cannot disable depth testing -} - -/* - * Issue this after drawing 2d so that we don't mess the matrix stack. - * The complement of glBegin2D. - */ -void glEnd2D(void) -{ - // restore 3d matrices and set current matrix to modelview - glMatrixMode(GL_PROJECTION); - glPopMatrix(1); - glMatrixMode(GL_MODELVIEW); - glPopMatrix(1); -} - -/* - * Draws a pixel - * Parameters: - * x,y -> First coordinate of the line - * color -> RGB15/ARGB16 color - */ -void glPutPixel(int x, int y, int color) -{ - glBindTexture(0, 0); - glColor(color); - glBegin(GL_TRIANGLES); - gxVertex3i(x, y, g_depth); - gxVertex2i(x, y); - gxVertex2i(x, y); - glEnd(); - glColor(0x7FFF); - g_depth++; - gCurrentTexture = 0; -} - -/* - * Draws a line - * Parameters: - * x1,y1 -> First coordinate of the line - * x2,y2 -> Second coordinate of the line - * color -> RGB15/ARGB16 color - */ -void glLine(int x1, int y1, int x2, int y2, int color) -{ - x2++; - y2++; - - glBindTexture(0, 0); - glColor(color); - glBegin(GL_TRIANGLES); - gxVertex3i(x1, y1, g_depth); - gxVertex2i(x2, y2); - gxVertex2i(x2, y2); - glEnd(); - glColor(0x7FFF); - g_depth++; - gCurrentTexture = 0; -} - -/* - * Draws a Filled Box - * Parameters: - * x1,y1 -> Top-left corner of the box - * x2,y2 -> Bottom-Right corner of the box - * color -> RGB15/ARGB16 color -*/ -void glBoxFilled(int x1, int y1, int x2, int y2, int color) -{ - x2++; - y2++; - - glBindTexture(0, 0); - glColor(color); - glBegin(GL_QUADS); - gxVertex3i(x1, y1, g_depth); // use 3i for first vertex so that we increment HW depth - gxVertex2i(x1, y2); // no need for 3 vertices as 2i would share last depth call - gxVertex2i(x2, y2); - gxVertex2i(x2, y1); - glEnd(); - glColor(0x7FFF); - g_depth++; - gCurrentTexture = 0; -} - -/* - * - * Create a tile. - * Very rigid and prone to human error. - * - * Parameters: - * *sprite -> pointer to a glImage - * texture_width -> width/height of the texture; - * texture_height -> valid sizes are enumerated in GL_TEXTURE_TYPE_ENUM (see glTexImage2d) - * sprite_width - * sprite_height -> width/height of the picture in the texture. - * type -> The format of the texture (see glTexImage2d) - * param -> parameters for the texture (see glTexImage2d) - */ -int glLoadTile(glImage *sprite, - int texture_width, - int texture_height, - int sprite_width, - int sprite_height, - GL_TEXTURE_TYPE_ENUM type, - int param, - int pallette_width, - const u16 *palette, - const uint8 *texture) -{ - int textureID; - - glGenTextures(1, &textureID); - glBindTexture(0, textureID); - glTexImage2D(0, 0, type, texture_width, texture_height, 0, param, texture); - glColorTableEXT(0, 0, pallette_width, 0, 0, palette); - - sprite->width = sprite_width; - sprite->height = sprite_height; - sprite->textureID = textureID; - - return textureID; -} - -/* - * I made this since the scale wrappers are either the vectorized mode - * or does not permit you to scale only the axis you want to - * scale. Needed for sprite scaling. - */ -static inline void gxScalef32(s32 x, s32 y, s32 z) -{ - MATRIX_SCALE = x; - MATRIX_SCALE = y; - MATRIX_SCALE = z; -} - -/* - * I this made for future naming conflicts. - */ -static inline void gxTranslate3f32(int32 x, int32 y, int32 z) -{ - MATRIX_TRANSLATE = x; - MATRIX_TRANSLATE = y; - MATRIX_TRANSLATE = z; -} - -/* - * Draws an axis exclusive scaled sprite - * Parameters: - * x -> x position of the sprite - * y -> y position of the sprite - * scaleX -> 20.12 FP X axis scale value (1 << 12 is normal) - * scaleY -> 20.12 FP Y axis scale value (1 << 12 is normal) - * flipmode -> mode for flipping (see GL_FLIP_MODE enum) - * *spr -> pointer to a glImage - */ -void glSpriteScaleXY(int x, int y, s32 scaleX, s32 scaleY, int flipmode, const glImage *spr) -{ - const int x1 = 0; - const int y1 = 0; - const int x2 = spr->width; - const int y2 = spr->height; - const int u1 = ((flipmode & GL_FLIP_H) ? spr->width-1 : 0); - const int u2 = ((flipmode & GL_FLIP_H) ? 0 : spr->width-1); - const int v1 = ((flipmode & GL_FLIP_V) ? spr->height-1 : 0); - const int v2 = ((flipmode & GL_FLIP_V) ? 0 : spr->height-1); - - if (spr->textureID != gCurrentTexture) - { - glBindTexture(GL_TEXTURE_2D, spr->textureID); - gCurrentTexture = spr->textureID; - } - - glPushMatrix(); - - gxTranslate3f32(x, y, 0); - gxScalef32(scaleX, scaleY, 1 << 12); - - glBegin(GL_QUADS); - - gxTexcoord2i(u1, v1); gxVertex3i(x1, y1, g_depth); - gxTexcoord2i(u1, v2); gxVertex2i(x1, y2); - gxTexcoord2i(u2, v2); gxVertex2i(x2, y2); - gxTexcoord2i(u2, v1); gxVertex2i(x2, y1); - - glEnd(); - - glPopMatrix(1); - g_depth++; -} - -#endif /* SDL_VIDEO_RENDER_NDS */ diff --git a/src/render/nds/SDL_libgl2D.h b/src/render/nds/SDL_libgl2D.h deleted file mode 100644 index 4d56f0e896..0000000000 --- a/src/render/nds/SDL_libgl2D.h +++ /dev/null @@ -1,154 +0,0 @@ -/* - * Note: The Nintendo DS port to SDL uses excerpts from the libGL2D, - * with permission of the original author. The following is mostly his - * code/comments. - * - * - * Easy GL2D - * - * Relminator 2010 - * Richard Eric M. Lope BSN RN - * - * http://rel.betterwebber.com - * - * A very small and simple DS rendering lib using the 3d core to render 2D stuff - */ -#include "SDL_config.h" - -#if SDL_VIDEO_RENDER_NDS - -#include <nds/arm9/videoGL.h> - -/* LibGL extension(s) */ -static inline void gxTexcoord2i(t16 u, t16 v) -{ - GFX_TEX_COORD = (v << 20) | ((u << 4) & 0xFFFF); -} - -static inline void gxVertex3i(v16 x, v16 y, v16 z) -{ - GFX_VERTEX16 = (y << 16) | (x & 0xFFFF); - GFX_VERTEX16 = ((uint32)(uint16)z); -} - -static inline void gxVertex2i(v16 x, v16 y) -{ - GFX_VERTEX_XY = (y << 16) | (x & 0xFFFF); -} - -/* - * Enums selecting flipping mode. - * - * These enums are bits for flipping the sprites. - * You can "|" (or) GL_FLIP_V and GL_FLIP_H to flip - * both ways. - */ -typedef enum -{ - GL_FLIP_NONE = (1 << 0), /* No flipping */ - GL_FLIP_V = (1 << 1), /* Sprite is rendered vertically flipped */ - GL_FLIP_H = (1 << 2), /* Sprite is rendered horizontally flipped */ -} GL_FLIP_MODE; - -/* Struct for out GL-Based Images. */ -typedef struct -{ - int width; /* Width of the Sprite */ - int height; /* Height of the Sprite */ - int textureID; /* Texture handle (used in glDeleteTextures()) - The texture handle in VRAM (returned by glGenTextures()) - ie. This references the actual texture stored in VRAM. */ -} glImage; - -extern v16 g_depth; -extern int gCurrentTexture; - -/* - * Draws an Axis Exclusive Scaled Sprite - * Parameters: - * x X position of the sprite. - * y Y position of the sprite. - * scaleX 20.12 fixed-point X-Axis scale value (1 << 12 is normal). - * scaleY 20.12 fixed-point Y-Axis scale value (1 << 12 is normal). - * flipmode mode for flipping (see GL_FLIP_MODE enum). - * *spr pointer to a glImage. -*/ -void glSpriteScaleXY(int x, int y, s32 scaleX, s32 scaleY, int flipmode, const glImage *spr); - -/* Initializes our Tileset (like glInitSpriteset()) but without the use of Texture Packer auto-generated files. - * Can only be used when tiles in a tilset are of the same dimensions. - * Parameters: - * *sprite Pointer to an array of glImage. - * tile_wid Width of each tile in the texture. - * tile_hei Height of each tile in the texture. - * bmp_wid Width of of the texture or tileset. - * bmp_hei height of of the texture or tileset. - * type The format of the texture (see glTexImage2d()). - * sizeX The horizontal size of the texture; valid sizes are enumerated in GL_TEXTURE_TYPE_ENUM (see glTexImage2d()). - * sizeY The vertical size of the texture; valid sizes are enumerated in GL_TEXTURE_TYPE_ENUM (see glTexImage2d()). - * param parameters for the texture (see glTexImage2d()). - * pallette_width Length of the palette. Valid values are <b>4, 16, 32, 256</b> (if <b>0</b>, then palette is removed from currently bound texture). - * *palette Pointer to the palette data to load (if NULL, then palette is removed from currently bound texture). - * *texture Pointer to the texture data to load. -*/ -int glLoadTile(glImage *sprite, - int texture_width, - int texture_height, - int sprite_width, - int sprite_height, - GL_TEXTURE_TYPE_ENUM type, - int param, - int pallette_width, - const u16 *palette, - const uint8 *texture); - -/* Initializes GL in 2D mode */ -void glScreen2D(void); - -/* - * Sets up OpenGL for 2d rendering. - * - * Call this before drawing any of GL2D's drawing or sprite functions. - */ -void glBegin2D(void); - -/* - * Issue this after drawing 2d so that we don't mess the matrix stack. - * - * The complement of glBegin2D(). - */ -void glEnd2D(void); - -/* - * Draws a Pixel - * x X position of the pixel. - * y Y position of the pixel. - * color RGB15/ARGB16 color. - */ -void glPutPixel(int x, int y, int color); - -/* - * Draws a Line - * x1,y1 Top-Left coordinate of the line. - * x2,y2 Bottom-Right coordinate of the line. - * color RGB15/ARGB16 color. - */ -void glLine(int x1, int y1, int x2, int y2, int color); - -/* - * Draws a Box - * x1,y1 Top-Left coordinate of the box. - * x2,y2 Bottom-Right coordinate of the box. - * color RGB15/ARGB16 color. -*/ -void glBox(int x1, int y1, int x2, int y2, int color); - -/* - * Draws a Filled Box - * x1,y1 Top-Left coordinate of the box. - * x2,y2 Bottom-Right coordinate of the box. - * color RGB15/ARGB16 color. - */ -void glBoxFilled(int x1, int y1, int x2, int y2, int color); - -#endif /* SDL_VIDEO_RENDER_NDS */ diff --git a/src/render/nds/SDL_ndsrender.c b/src/render/nds/SDL_ndsrender.c deleted file mode 100644 index b888f0aa83..0000000000 --- a/src/render/nds/SDL_ndsrender.c +++ /dev/null @@ -1,418 +0,0 @@ -/* - Simple DirectMedia Layer - Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org> - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. -*/ -#include "SDL_config.h" - -#if SDL_VIDEO_RENDER_NDS - -#include <stdio.h> -#include <stdlib.h> -#include <nds.h> - -#include "SDL_libgl2D.h" - -#include "SDL_video.h" -#include "../../video/SDL_sysvideo.h" -#include "SDL_render.h" -#include "../SDL_sysrender.h" -#include "SDL_log.h" - -/* Draws a partial sprite. Based on glSprite. */ -static void glSpritePartial(const SDL_Rect * srcrect, int x, int y, int flipmode, const glImage *spr) -{ - int x1 = x; - int y1 = y; - int x2 = x + srcrect->w; - int y2 = y + srcrect->h; - - int u1 = srcrect->x + ((flipmode & GL_FLIP_H) ? spr->width-1 : 0); - int u2 = srcrect->x + ((flipmode & GL_FLIP_H) ? 0 : srcrect->h); - int v1 = srcrect->y + ((flipmode & GL_FLIP_V) ? spr->height-1 : 0); - int v2 = srcrect->y + ((flipmode & GL_FLIP_V) ? 0 : srcrect->h); - - if (spr->textureID != gCurrentTexture) { - glBindTexture(GL_TEXTURE_2D, spr->textureID); - gCurrentTexture = spr->textureID; - } - - glBegin(GL_QUADS); - - gxTexcoord2i(u1, v1); gxVertex3i(x1, y1, g_depth); - gxTexcoord2i(u1, v2); gxVertex2i(x1, y2); - gxTexcoord2i(u2, v2); gxVertex2i(x2, y2); - gxTexcoord2i(u2, v1); gxVertex2i(x2, y1); - - glEnd(); - - g_depth++; -} - -/* SDL NDS renderer implementation */ - -extern SDL_RenderDriver NDS_RenderDriver; - -typedef struct -{ - /* Whether current 3D engine is on the main or sub screen. */ - int is_sub; -} NDS_RenderData; - -typedef struct -{ - glImage image[1]; -} NDS_TextureData; - -static int NDS_UpdateViewport(SDL_Renderer *renderer) -{ - /* Nothing to do. */ - return 0; -} - -static int -NDS_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture, - const SDL_Rect * srcrect, const SDL_Rect * dstrect) -{ - NDS_RenderData *data = (NDS_RenderData *) renderer->driverdata; - NDS_TextureData *txdat = (NDS_TextureData *) texture->driverdata; - int dest_y; - - if (data->is_sub) { - dest_y = dstrect->y; - } else { - dest_y = dstrect->y-SCREEN_HEIGHT; - } - - if (srcrect->w == dstrect->w && srcrect->h == dstrect->h) { - /* No scaling */ - glSpritePartial(srcrect, dstrect->x, dest_y, GL_FLIP_NONE, txdat->image); - } else { - /* Convert the scaling proportion into a 20.12 value. */ - s32 scale_w = divf32(dstrect->w << 12, texture->w << 12); - s32 scale_h = divf32(dstrect->h << 12, texture->h << 12); - - glSpriteScaleXY(dstrect->x, dest_y, scale_w, scale_h, GL_FLIP_NONE, txdat->image); - } - - return 0; -} - -static int NDS_CreateTexture(SDL_Renderer *renderer, SDL_Texture *texture) -{ - NDS_TextureData *txdat = NULL; - int i; - - SDL_Log("NDS_CreateTexture: NDS_CreateTexture.\n"); - - /* Sanity checks. */ - for (i=0; i<NDS_RenderDriver.info.num_texture_formats; i++) { - if (texture->format == NDS_RenderDriver.info.texture_formats[i]) - break; - } - if (i == NDS_RenderDriver.info.num_texture_formats) { - SDL_SetError("Unsupported texture format (%x)", texture->format); - return -1; - } - - if (texture->w > NDS_RenderDriver.info.max_texture_width) { - SDL_SetError("Texture too large (%d)", texture->w); - return -1; - } - - if (texture->h > NDS_RenderDriver.info.max_texture_height) { - SDL_SetError("Texture too tall (%d)", texture->h); - return -1; - } - - texture->driverdata = SDL_calloc(1, sizeof(NDS_TextureData)); - txdat = (NDS_TextureData *) texture->driverdata; - if (!txdat) { - SDL_OutOfMemory(); - return -1; - } - - return 0; -} - -static void -NDS_DestroyTexture(SDL_Renderer * renderer, SDL_Texture * texture) -{ - NDS_TextureData *txdat = texture->driverdata; - - /* free anything else allocated for texture */ - SDL_free(txdat); -} - -/* size is no more than 512. */ -static int get_gltexture_size(unsigned int size) -{ - if (size > 256) - return TEXTURE_SIZE_512; - else if (size > 128) - return TEXTURE_SIZE_256; - else if (size > 64) - return TEXTURE_SIZE_128; - else if (size > 32) - return TEXTURE_SIZE_64; - else if (size > 16) - return TEXTURE_SIZE_32; - else if (size > 8) - return TEXTURE_SIZE_16; - else - return TEXTURE_SIZE_8; -} - -static int NDS_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture, - const SDL_Rect * rect, const void *pixels, int pitch) -{ - NDS_TextureData *txdat = (NDS_TextureData *) texture->driverdata; - char *new_pixels = NULL; - const int gl_w = get_gltexture_size(rect->w); - const int gl_h = get_gltexture_size(rect->h); - const int w = 1 << (3+gl_w); /* Texture sizes must be a power of 2. */ - const int h = 1 << (3+gl_h); /* Texture sizes must be a power of 2. */ - - if (w != rect->w || h != rect->h) { - /* Allocate a temporary surface and copy pixels into it while - * enlarging the pitch. */ - const char *src; - char *dst; - int new_pitch = 2 * w; - int i; - - new_pixels = malloc(2 * w * h); - if (!new_pixels) - return SDL_ENOMEM; - - src = pixels; - dst = new_pixels; - for (i=0; i<rect->h; i++) { - memcpy(dst, src, pitch); - src += pitch; - dst += new_pitch; - } - } - - glLoadTile(txdat->image, - gl_w, gl_h, - rect->w, rect->h, - texture->format == SDL_PIXELFORMAT_ABGR1555 ? GL_RGBA : GL_RGB, - TEXGEN_OFF, 0, NULL, - new_pixels? new_pixels : pixels); - - if (new_pixels) - free(new_pixels); - - return 0; -} - -static int NDS_LockTexture(SDL_Renderer *renderer, SDL_Texture *texture, - const SDL_Rect *rect, void **pixels, int *pitch) -{ - SDL_Log("enter %s (todo)\n", __func__); - - return 0; -} - -static void NDS_UnlockTexture(SDL_Renderer *renderer, SDL_Texture *texture) -{ - SDL_Log("enter %s\n", __func__); - /* stub! */ -} - -static int NDS_RenderClear(SDL_Renderer *renderer) -{ - glClearColor(renderer->r >> 3, - renderer->g >> 3, - renderer->b >> 3, - renderer->a >> 3); - - return 0; -} - -static void NDS_RenderPresent(SDL_Renderer * renderer) -{ - NDS_RenderData *data = (NDS_RenderData *) renderer->driverdata; - - glEnd2D(); - - glFlush(0); - - swiWaitForVBlank(); - - /* wait for capture unit to be ready */ - while(REG_DISPCAPCNT & DCAP_ENABLE); - - /* 3D engine can only work on one screen at a time. */ - data->is_sub = !data->is_sub; - if (data->is_sub) { - lcdMainOnBottom(); - vramSetBankC(VRAM_C_LCD); - vramSetBankD(VRAM_D_SUB_SPRITE); - REG_DISPCAPCNT = DCAP_BANK(2) | DCAP_ENABLE | DCAP_SIZE(3); - } else { - lcdMainOnTop(); - vramSetBankD(VRAM_D_LCD); - vramSetBankC(VRAM_C_SUB_BG); - REG_DISPCAPCNT = DCAP_BANK(3) | DCAP_ENABLE | DCAP_SIZE(3); - } - - glBegin2D(); -} - -static int NDS_RenderDrawPoints(SDL_Renderer *renderer, const SDL_Point *points, - int count) -{ - NDS_RenderData *data = (NDS_RenderData *) renderer->driverdata; - int i; - int color = RGB15(renderer->r >> 3, - renderer->g >> 3, - renderer->b >> 3); - - for (i=0; i < count; i++) { - if (data->is_sub) { - glPutPixel(points[i].x, points[i].y, color); - } else { - glPutPixel(points[i].x, points[i].y - SCREEN_HEIGHT, color); - } - } - - return 0; -} - -static int NDS_RenderDrawLines(SDL_Renderer *renderer, const SDL_Point *points, - int count) -{ - NDS_RenderData *data = (NDS_RenderData *) renderer->driverdata; - int i; - int color = RGB15(renderer->r >> 3, - renderer->g >> 3, - renderer->b >> 3); - - for (i=0; i < count-1; i++) { - if (data->is_sub) { - glLine(points[i].x, points[i].y, points[i+1].x, points[i+1].y, color); - } else { - glLine(points[i].x, points[i].y - SCREEN_HEIGHT, - points[i+1].x, points[i+1].y - SCREEN_HEIGHT, color); - } - } - - return 0; -} - -static int NDS_RenderFillRects(SDL_Renderer *renderer, const SDL_Rect *rects, - int count) -{ - NDS_RenderData *data = (NDS_RenderData *) renderer->driverdata; - int i; - int color = RGB15(renderer->r >> 3, - renderer->g >> 3, - renderer->b >> 3); - - for (i=0; i<count; i++) { - if (data->is_sub) { - glBoxFilled(rects[i].x, rects[i].y, - rects[i].x + rects[i].w, - rects[i].y + rects[i].h, color); - } else { - glBoxFilled(rects[i].x, rects[i].y - SCREEN_HEIGHT, - rects[i].x + rects[i].w, - rects[i].y + rects[i].h - SCREEN_HEIGHT, - color); - } - } - - return 0; -} - -static SDL_Renderer * -NDS_CreateRenderer(SDL_Window * window, Uint32 flags) -{ - SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window); - SDL_DisplayMode *displayMode = &display->current_mode; - SDL_Renderer *renderer; - NDS_RenderData *data; - int bpp; - Uint32 Rmask, Gmask, Bmask, Amask; - - if (displayMode->format != SDL_PIXELFORMAT_ABGR1555) { - SDL_SetError("Unsupported pixel format (%x)", displayMode->format); - return NULL; - } - - if (!SDL_PixelFormatEnumToMasks(displayMode->format, &bpp, - &Rmask, &Gmask, &Bmask, &Amask)) { - SDL_SetError("Unknown display format"); - return NULL; - } - - renderer = (SDL_Renderer *) SDL_calloc(1, sizeof(*renderer)); - if (!renderer) { - SDL_OutOfMemory(); - return NULL; - } - - data = (NDS_RenderData *) SDL_calloc(1, sizeof(*data)); - if (!data) { - SDL_free(renderer); - SDL_OutOfMemory(); - return NULL; - } - - renderer->info = NDS_RenderDriver.info; - renderer->info.flags = SDL_RENDERER_ACCELERATED; - - renderer->CreateTexture = NDS_CreateTexture; - renderer->UpdateTexture = NDS_UpdateTexture; - renderer->LockTexture = NDS_LockTexture; - renderer->UnlockTexture = NDS_UnlockTexture; - renderer->UpdateViewport = NDS_UpdateViewport; - renderer->RenderClear = NDS_RenderClear; - renderer->RenderDrawPoints = NDS_RenderDrawPoints; - renderer->RenderDrawLines = NDS_RenderDrawLines; - renderer->RenderFillRects = NDS_RenderFillRects; - renderer->RenderCopy = NDS_RenderCopy; - /* renderer->RenderReadPixels = NDS_RenderReadPixels; - todo ? */ - renderer->RenderPresent = NDS_RenderPresent; - renderer->DestroyTexture = NDS_DestroyTexture; - /* renderer->DestroyRenderer = NDS_DestroyRenderer; - todo ? */ - - renderer->driverdata = data; - - return renderer; -} - -SDL_RenderDriver NDS_RenderDriver = { - .CreateRenderer = NDS_CreateRenderer, - .info = { - .name = "nds", - .flags = SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC, - .num_texture_formats = 2, - .texture_formats = { [0] = SDL_PIXELFORMAT_ABGR1555, - [1] = SDL_PIXELFORMAT_BGR555, - }, - .max_texture_width = 512, - .max_texture_height = 512, - } -}; - -#endif /* SDL_VIDEO_RENDER_NDS */ - -/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/render/opengl/SDL_render_gl.c b/src/render/opengl/SDL_render_gl.c index 5a0d72fb56..30d0716bbf 100644 --- a/src/render/opengl/SDL_render_gl.c +++ b/src/render/opengl/SDL_render_gl.c @@ -208,8 +208,7 @@ GL_LoadFunctions(GL_RenderData * data) do { \ data->func = SDL_GL_GetProcAddress(#func); \ if ( ! data->func ) { \ - SDL_SetError("Couldn't load GL function %s: %s\n", #func, SDL_GetError()); \ - return -1; \ + return SDL_SetError("Couldn't load GL function %s: %s\n", #func, SDL_GetError()); \ } \ } while ( 0 ); #endif /* __SDL_NOGETPROCADDR__ */ @@ -500,15 +499,13 @@ GL_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture) if (!convert_format(renderdata, texture->format, &internalFormat, &format, &type)) { - SDL_SetError("Texture format %s not supported by OpenGL", - SDL_GetPixelFormatName(texture->format)); - return -1; + return SDL_SetError("Texture format %s not supported by OpenGL", + SDL_GetPixelFormatName(texture->format)); } data = (GL_TextureData *) SDL_calloc(1, sizeof(*data)); if (!data) { - SDL_OutOfMemory(); - return -1; + return SDL_OutOfMemory(); } if (texture->access == SDL_TEXTUREACCESS_STREAMING) { @@ -522,9 +519,8 @@ GL_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture) } data->pixels = SDL_calloc(1, size); if (!data->pixels) { - SDL_OutOfMemory(); SDL_free(data); - return -1; + return SDL_OutOfMemory(); } } @@ -746,8 +742,7 @@ GL_SetRenderTarget(SDL_Renderer * renderer, SDL_Texture * texture) /* Check FBO status */ status = data->glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT); if (status != GL_FRAMEBUFFER_COMPLETE_EXT) { - SDL_SetError("glFramebufferTexture2DEXT() failed"); - return -1; + return SDL_SetError("glFramebufferTexture2DEXT() failed"); } return 0; } @@ -1157,8 +1152,7 @@ GL_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect, temp_pitch = rect->w * SDL_BYTESPERPIXEL(temp_format); temp_pixels = SDL_malloc(rect->h * temp_pitch); if (!temp_pixels) { - SDL_OutOfMemory(); - return -1; + return SDL_OutOfMemory(); } convert_format(data, temp_format, &internalFormat, &format, &type); diff --git a/src/render/opengles/SDL_render_gles.c b/src/render/opengles/SDL_render_gles.c index 7000675631..62b547b2c7 100644 --- a/src/render/opengles/SDL_render_gles.c +++ b/src/render/opengles/SDL_render_gles.c @@ -135,7 +135,7 @@ typedef struct GLES_FBOList *fbo; } GLES_TextureData; -static void +static int GLES_SetError(const char *prefix, GLenum result) { const char *error; @@ -166,7 +166,7 @@ GLES_SetError(const char *prefix, GLenum result) error = "UNKNOWN"; break; } - SDL_SetError("%s: %s", prefix, error); + return SDL_SetError("%s: %s", prefix, error); } static int GLES_LoadFunctions(GLES_RenderData * data) @@ -186,8 +186,7 @@ static int GLES_LoadFunctions(GLES_RenderData * data) do { \ data->func = SDL_GL_GetProcAddress(#func); \ if ( ! data->func ) { \ - SDL_SetError("Couldn't load GLES function %s: %s\n", #func, SDL_GetError()); \ - return -1; \ + return SDL_SetError("Couldn't load GLES function %s: %s\n", #func, SDL_GetError()); \ } \ } while ( 0 ); #endif /* _SDL_NOGETPROCADDR_ */ @@ -442,23 +441,20 @@ GLES_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture) type = GL_UNSIGNED_BYTE; break; default: - SDL_SetError("Texture format not supported"); - return -1; + return SDL_SetError("Texture format not supported"); } data = (GLES_TextureData *) SDL_calloc(1, sizeof(*data)); if (!data) { - SDL_OutOfMemory(); - return -1; + return SDL_OutOfMemory(); } if (texture->access == SDL_TEXTUREACCESS_STREAMING) { data->pitch = texture->w * SDL_BYTESPERPIXEL(texture->format); data->pixels = SDL_calloc(1, texture->h * data->pitch); if (!data->pixels) { - SDL_OutOfMemory(); SDL_free(data); - return -1; + return SDL_OutOfMemory(); } } @@ -495,8 +491,7 @@ GLES_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture) result = renderdata->glGetError(); if (result != GL_NO_ERROR) { - GLES_SetError("glTexImage2D()", result); - return -1; + return GLES_SetError("glTexImage2D()", result); } return 0; } @@ -521,17 +516,13 @@ GLES_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture, /* Reformat the texture data into a tightly packed array */ srcPitch = rect->w * SDL_BYTESPERPIXEL(texture->format); src = (Uint8 *)pixels; - if (pitch != srcPitch) - { + if (pitch != srcPitch) { blob = (Uint8 *)SDL_malloc(srcPitch * rect->h); - if (!blob) - { - SDL_OutOfMemory(); - return -1; + if (!blob) { + return SDL_OutOfMemory(); } src = blob; - for (y = 0; y < rect->h; ++y) - { + for (y = 0; y < rect->h; ++y) { SDL_memcpy(src, pixels, srcPitch); src += srcPitch; pixels = (Uint8 *)pixels + pitch; @@ -559,8 +550,7 @@ GLES_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture, if (renderdata->glGetError() != GL_NO_ERROR) { - SDL_SetError("Failed to update texture"); - return -1; + return SDL_SetError("Failed to update texture"); } return 0; } @@ -613,8 +603,7 @@ GLES_SetRenderTarget(SDL_Renderer * renderer, SDL_Texture * texture) /* Check FBO status */ status = data->glCheckFramebufferStatusOES(GL_FRAMEBUFFER_OES); if (status != GL_FRAMEBUFFER_COMPLETE_OES) { - SDL_SetError("glFramebufferTexture2DOES() failed"); - return -1; + return SDL_SetError("glFramebufferTexture2DOES() failed"); } return 0; } @@ -804,7 +793,6 @@ static int GLES_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture, const SDL_Rect * srcrect, const SDL_FRect * dstrect) { - GLES_RenderData *data = (GLES_RenderData *) renderer->driverdata; GLES_TextureData *texturedata = (GLES_TextureData *) texture->driverdata; GLfloat minx, miny, maxx, maxy; @@ -1007,8 +995,7 @@ GLES_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect, temp_pitch = rect->w * SDL_BYTESPERPIXEL(temp_format); temp_pixels = SDL_malloc(rect->h * temp_pitch); if (!temp_pixels) { - SDL_OutOfMemory(); - return -1; + return SDL_OutOfMemory(); } SDL_GetWindowSize(window, &w, &h); @@ -1091,7 +1078,8 @@ GLES_DestroyRenderer(SDL_Renderer * renderer) SDL_free(renderer); } -static int GLES_BindTexture (SDL_Renderer * renderer, SDL_Texture *texture, float *texw, float *texh) { +static int GLES_BindTexture (SDL_Renderer * renderer, SDL_Texture *texture, float *texw, float *texh) +{ GLES_RenderData *data = (GLES_RenderData *) renderer->driverdata; GLES_TextureData *texturedata = (GLES_TextureData *) texture->driverdata; GLES_ActivateRenderer(renderer); @@ -1105,7 +1093,8 @@ static int GLES_BindTexture (SDL_Renderer * renderer, SDL_Texture *texture, floa return 0; } -static int GLES_UnbindTexture (SDL_Renderer * renderer, SDL_Texture *texture) { +static int GLES_UnbindTexture (SDL_Renderer * renderer, SDL_Texture *texture) +{ GLES_RenderData *data = (GLES_RenderData *) renderer->driverdata; GLES_TextureData *texturedata = (GLES_TextureData *) texture->driverdata; GLES_ActivateRenderer(renderer); @@ -1114,7 +1103,6 @@ static int GLES_UnbindTexture (SDL_Renderer * renderer, SDL_Texture *texture) { return 0; } - #endif /* SDL_VIDEO_RENDER_OGL_ES && !SDL_RENDER_DISABLED */ /* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/render/opengles2/SDL_render_gles2.c b/src/render/opengles2/SDL_render_gles2.c index 457bfc87d9..2877ef63f9 100644 --- a/src/render/opengles2/SDL_render_gles2.c +++ b/src/render/opengles2/SDL_render_gles2.c @@ -189,8 +189,7 @@ static int GLES2_LoadFunctions(GLES2_DriverContext * data) do { \ data->func = SDL_GL_GetProcAddress(#func); \ if ( ! data->func ) { \ - SDL_SetError("Couldn't load GLES2 function %s: %s\n", #func, SDL_GetError()); \ - return -1; \ + return SDL_SetError("Couldn't load GLES2 function %s: %s\n", #func, SDL_GetError()); \ } \ } while ( 0 ); #endif /* _SDL_NOGETPROCADDR_ */ @@ -372,16 +371,13 @@ GLES2_CreateTexture(SDL_Renderer *renderer, SDL_Texture *texture) type = GL_UNSIGNED_BYTE; break; default: - SDL_SetError("Texture format not supported"); - return -1; + return SDL_SetError("Texture format not supported"); } /* Allocate a texture struct */ tdata = (GLES2_TextureData *)SDL_calloc(1, sizeof(GLES2_TextureData)); - if (!tdata) - { - SDL_OutOfMemory(); - return -1; + if (!tdata) { + return SDL_OutOfMemory(); } tdata->texture = 0; tdata->texture_type = GL_TEXTURE_2D; @@ -390,15 +386,12 @@ GLES2_CreateTexture(SDL_Renderer *renderer, SDL_Texture *texture) scaleMode = GetScaleQuality(); /* Allocate a blob for image data */ - if (texture->access == SDL_TEXTUREACCESS_STREAMING) - { + if (texture->access == SDL_TEXTUREACCESS_STREAMING) { tdata->pitch = texture->w * SDL_BYTESPERPIXEL(texture->format); tdata->pixel_data = SDL_calloc(1, tdata->pitch * texture->h); - if (!tdata->pixel_data) - { - SDL_OutOfMemory(); + if (!tdata->pixel_data) { SDL_free(tdata); - return -1; + return SDL_OutOfMemory(); } } @@ -414,10 +407,9 @@ GLES2_CreateTexture(SDL_Renderer *renderer, SDL_Texture *texture) rdata->glTexImage2D(tdata->texture_type, 0, format, texture->w, texture->h, 0, format, type, NULL); if (rdata->glGetError() != GL_NO_ERROR) { - SDL_SetError("Texture creation failed"); rdata->glDeleteTextures(1, &tdata->texture); SDL_free(tdata); - return -1; + return SDL_SetError("Texture creation failed"); } texture->driverdata = tdata; @@ -497,13 +489,10 @@ GLES2_UpdateTexture(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_Rect /* Reformat the texture data into a tightly packed array */ srcPitch = rect->w * SDL_BYTESPERPIXEL(texture->format); src = (Uint8 *)pixels; - if (pitch != srcPitch) - { + if (pitch != srcPitch) { blob = (Uint8 *)SDL_malloc(srcPitch * rect->h); - if (!blob) - { - SDL_OutOfMemory(); - return -1; + if (!blob) { + return SDL_OutOfMemory(); } src = blob; for (y = 0; y < rect->h; ++y) @@ -533,10 +522,8 @@ GLES2_UpdateTexture(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_Rect SDL_free(blob); } - if (rdata->glGetError() != GL_NO_ERROR) - { - SDL_SetError("Failed to update texture"); - return -1; + if (rdata->glGetError() != GL_NO_ERROR) { + return SDL_SetError("Failed to update texture"); } return 0; } @@ -558,8 +545,7 @@ GLES2_SetRenderTarget(SDL_Renderer * renderer, SDL_Texture * texture) /* Check FBO status */ status = data->glCheckFramebufferStatus(GL_FRAMEBUFFER); if (status != GL_FRAMEBUFFER_COMPLETE) { - SDL_SetError("glFramebufferTexture2D() failed"); - return -1; + return SDL_SetError("glFramebufferTexture2D() failed"); } } return 0; @@ -636,9 +622,9 @@ GLES2_CacheProgram(SDL_Renderer *renderer, GLES2_ShaderCacheEntry *vertex, rdata->glGetProgramiv(entry->id, GL_LINK_STATUS, &linkSuccessful); if (rdata->glGetError() != GL_NO_ERROR || !linkSuccessful) { - SDL_SetError("Failed to link shader program"); rdata->glDeleteProgram(entry->id); SDL_free(entry); + SDL_SetError("Failed to link shader program"); return NULL; } @@ -930,10 +916,8 @@ GLES2_SetOrthographicProjection(SDL_Renderer *renderer) locProjection = rdata->current_program->uniform_locations[GLES2_UNIFORM_PROJECTION]; rdata->glGetError(); rdata->glUniformMatrix4fv(locProjection, 1, GL_FALSE, (GLfloat *)projection); - if (rdata->glGetError() != GL_NO_ERROR) - { - SDL_SetError("Failed to set orthographic projection"); - return -1; + if (rdata->glGetError() != GL_NO_ERROR) { + return SDL_SetError("Failed to set orthographic projection"); } return 0; } @@ -1066,8 +1050,7 @@ GLES2_RenderDrawPoints(SDL_Renderer *renderer, const SDL_FPoint *points, int cou /* Emit the specified vertices as points */ vertices = SDL_stack_alloc(GLfloat, count * 2); - for (idx = 0; idx < count; ++idx) - { + for (idx = 0; idx < count; ++idx) { GLfloat x = points[idx].x + 0.5f; GLfloat y = points[idx].y + 0.5f; @@ -1078,10 +1061,8 @@ GLES2_RenderDrawPoints(SDL_Renderer *renderer, const SDL_FPoint *points, int cou rdata->glVertexAttribPointer(GLES2_ATTRIBUTE_POSITION, 2, GL_FLOAT, GL_FALSE, 0, vertices); rdata->glDrawArrays(GL_POINTS, 0, count); SDL_stack_free(vertices); - if (rdata->glGetError() != GL_NO_ERROR) - { - SDL_SetError("Failed to render lines"); - return -1; + if (rdata->glGetError() != GL_NO_ERROR) { + return SDL_SetError("Failed to render lines"); } return 0; } @@ -1099,8 +1080,7 @@ GLES2_RenderDrawLines(SDL_Renderer *renderer, const SDL_FPoint *points, int coun /* Emit a line strip including the specified vertices */ vertices = SDL_stack_alloc(GLfloat, count * 2); - for (idx = 0; idx < count; ++idx) - { + for (idx = 0; idx < count; ++idx) { GLfloat x = points[idx].x + 0.5f; GLfloat y = points[idx].y + 0.5f; @@ -1117,10 +1097,8 @@ GLES2_RenderDrawLines(SDL_Renderer *renderer, const SDL_FPoint *points, int coun rdata->glDrawArrays(GL_POINTS, count-1, 1); } SDL_stack_free(vertices); - if (rdata->glGetError() != GL_NO_ERROR) - { - SDL_SetError("Failed to render lines"); - return -1; + if (rdata->glGetError() != GL_NO_ERROR) { + return SDL_SetError("Failed to render lines"); } return 0; } @@ -1157,10 +1135,8 @@ GLES2_RenderFillRects(SDL_Renderer *renderer, const SDL_FRect *rects, int count) rdata->glVertexAttribPointer(GLES2_ATTRIBUTE_POSITION, 2, GL_FLOAT, GL_FALSE, 0, vertices); rdata->glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); } - if (rdata->glGetError() != GL_NO_ERROR) - { - SDL_SetError("Failed to render lines"); - return -1; + if (rdata->glGetError() != GL_NO_ERROR) { + return SDL_SetError("Failed to render lines"); } return 0; } @@ -1258,6 +1234,8 @@ GLES2_RenderCopy(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_Rect *s case SDL_PIXELFORMAT_RGB888: sourceType = GLES2_IMAGESOURCE_TEXTURE_RGB; break; + default: + return -1; } } if (GLES2_SelectProgram(renderer, sourceType, blendMode) < 0) @@ -1313,10 +1291,8 @@ GLES2_RenderCopy(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_Rect *s texCoords[7] = (srcrect->y + srcrect->h) / (GLfloat)texture->h; rdata->glVertexAttribPointer(GLES2_ATTRIBUTE_TEXCOORD, 2, GL_FLOAT, GL_FALSE, 0, texCoords); rdata->glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); - if (rdata->glGetError() != GL_NO_ERROR) - { - SDL_SetError("Failed to render texture"); - return -1; + if (rdata->glGetError() != GL_NO_ERROR) { + return SDL_SetError("Failed to render texture"); } return 0; } @@ -1424,6 +1400,8 @@ GLES2_RenderCopyEx(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_Rect case SDL_PIXELFORMAT_RGB888: sourceType = GLES2_IMAGESOURCE_TEXTURE_RGB; break; + default: + return -1; } } if (GLES2_SelectProgram(renderer, sourceType, blendMode) < 0) @@ -1495,10 +1473,8 @@ GLES2_RenderCopyEx(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_Rect rdata->glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); rdata->glDisableVertexAttribArray(GLES2_ATTRIBUTE_CENTER); rdata->glDisableVertexAttribArray(GLES2_ATTRIBUTE_ANGLE); - if (rdata->glGetError() != GL_NO_ERROR) - { - SDL_SetError("Failed to render texture"); - return -1; + if (rdata->glGetError() != GL_NO_ERROR) { + return SDL_SetError("Failed to render texture"); } return 0; } @@ -1521,8 +1497,7 @@ GLES2_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect, temp_pitch = rect->w * SDL_BYTESPERPIXEL(temp_format); temp_pixels = SDL_malloc(rect->h * temp_pitch); if (!temp_pixels) { - SDL_OutOfMemory(); - return -1; + return SDL_OutOfMemory(); } SDL_GetWindowSize(window, &w, &h); @@ -1576,7 +1551,6 @@ static int GLES2_BindTexture (SDL_Renderer * renderer, SDL_Texture *texture, flo GLES2_TextureData *texturedata = (GLES2_TextureData *)texture->driverdata; GLES2_ActivateRenderer(renderer); - data->glActiveTexture(GL_TEXTURE0); data->glBindTexture(texturedata->texture_type, texturedata->texture); if(texw) *texw = 1.0; diff --git a/src/render/psp/SDL_render_psp.c b/src/render/psp/SDL_render_psp.c new file mode 100644 index 0000000000..3bcd87965e --- /dev/null +++ b/src/render/psp/SDL_render_psp.c @@ -0,0 +1,1023 @@ +/* + Simple DirectMedia Layer + Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org> + + This software is provided 'as-is', without any express or implied + warranty. In no event will the authors be held liable for any damages + arising from the use of this software. + + Permission is granted to anyone to use this software for any purpose, + including commercial applications, and to alter it and redistribute it + freely, subject to the following restrictions: + + 1. The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original software. + 3. This notice may not be removed or altered from any source distribution. +*/ +#include "SDL_config.h" + +#if SDL_VIDEO_RENDER_PSP + +#include "SDL_hints.h" +#include "../SDL_sysrender.h" + +#include <pspkernel.h> +#include <pspdisplay.h> +#include <pspgu.h> +#include <pspgum.h> +#include <stdio.h> +#include <string.h> +#include <math.h> +#include <pspge.h> +#include <stdarg.h> +#include <stdlib.h> +#include <vram.h> + + + + +/* PSP renderer implementation, based on the PGE */ + + +extern int SDL_RecreateWindow(SDL_Window * window, Uint32 flags); + + +static SDL_Renderer *PSP_CreateRenderer(SDL_Window * window, Uint32 flags); +static void PSP_WindowEvent(SDL_Renderer * renderer, + const SDL_WindowEvent *event); +static int PSP_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture); +static int PSP_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture, + const SDL_Rect * rect, const void *pixels, + int pitch); +static int PSP_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture, + const SDL_Rect * rect, void **pixels, int *pitch); +static void PSP_UnlockTexture(SDL_Renderer * renderer, + SDL_Texture * texture); +static int PSP_SetRenderTarget(SDL_Renderer * renderer, + SDL_Texture * texture); +static int PSP_UpdateViewport(SDL_Renderer * renderer); +static int PSP_RenderClear(SDL_Renderer * renderer); +static int PSP_RenderDrawPoints(SDL_Renderer * renderer, + const SDL_FPoint * points, int count); +static int PSP_RenderDrawLines(SDL_Renderer * renderer, + const SDL_FPoint * points, int count); +static int PSP_RenderFillRects(SDL_Renderer * renderer, + const SDL_FRect * rects, int count); +static int PSP_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture, + const SDL_Rect * srcrect, + const SDL_FRect * dstrect); +static int PSP_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect, + Uint32 pixel_format, void * pixels, int pitch); +static int PSP_RenderCopyEx(SDL_Renderer * renderer, SDL_Texture * texture, + const SDL_Rect * srcrect, const SDL_FRect * dstrect, + const double angle, const SDL_FPoint *center, const SDL_RendererFlip flip); +static void PSP_RenderPresent(SDL_Renderer * renderer); +static void PSP_DestroyTexture(SDL_Renderer * renderer, + SDL_Texture * texture); +static void PSP_DestroyRenderer(SDL_Renderer * renderer); + +/* +SDL_RenderDriver PSP_RenderDriver = { + PSP_CreateRenderer, + { + "PSP", + (SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC | SDL_RENDERER_TARGETTEXTURE), + 1, + {SDL_PIXELFORMAT_ABGR8888}, + 0, + 0} +}; +*/ +SDL_RenderDriver PSP_RenderDriver = { + .CreateRenderer = PSP_CreateRenderer, + .info = { + .name = "PSP", + .flags = SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC | SDL_RENDERER_TARGETTEXTURE, + .num_texture_formats = 4, + .texture_formats = { [0] = SDL_PIXELFORMAT_BGR565, + [1] = SDL_PIXELFORMAT_ABGR1555, + [2] = SDL_PIXELFORMAT_ABGR4444, + [3] = SDL_PIXELFORMAT_ABGR8888, + }, + .max_texture_width = 512, + .max_texture_height = 512, + } +}; + +#define PSP_SCREEN_WIDTH 480 +#define PSP_SCREEN_HEIGHT 272 + +#define PSP_FRAME_BUFFER_WIDTH 512 +#define PSP_FRAME_BUFFER_SIZE (PSP_FRAME_BUFFER_WIDTH*PSP_SCREEN_HEIGHT) + +static unsigned int __attribute__((aligned(16))) DisplayList[262144]; + + +#define COL5650(r,g,b,a) ((r>>3) | ((g>>2)<<5) | ((b>>3)<<11)) +#define COL5551(r,g,b,a) ((r>>3) | ((g>>3)<<5) | ((b>>3)<<10) | (a>0?0x7000:0)) +#define COL4444(r,g,b,a) ((r>>4) | ((g>>4)<<4) | ((b>>4)<<8) | ((a>>4)<<12)) +#define COL8888(r,g,b,a) ((r) | ((g)<<8) | ((b)<<16) | ((a)<<24)) + + +typedef struct +{ + void* frontbuffer ; + void* backbuffer ; + SDL_bool initialized ; + SDL_bool displayListAvail ; + unsigned int psm ; + unsigned int bpp ; + + SDL_bool vsync; + unsigned int currentColor; + int currentBlendMode; + +} PSP_RenderData; + + +typedef struct +{ + void *data; /**< Image data. */ + unsigned int size; /**< Size of data in bytes. */ + unsigned int width; /**< Image width. */ + unsigned int height; /**< Image height. */ + unsigned int textureWidth; /**< Texture width (power of two). */ + unsigned int textureHeight; /**< Texture height (power of two). */ + unsigned int bits; /**< Image bits per pixel. */ + unsigned int format; /**< Image format - one of ::pgePixelFormat. */ + unsigned int pitch; + SDL_bool swizzled; /**< Is image swizzled. */ + +} PSP_TextureData; + +typedef struct +{ + float x, y, z; +} VertV; + + +typedef struct +{ + float u, v; + float x, y, z; + +} VertTV; + + +// Return next power of 2 +static int +TextureNextPow2(unsigned int w) +{ + if(w == 0) + return 0; + + unsigned int n = 2; + + while(w > n) + n <<= 1; + + return n; +} + + +static int +GetScaleQuality(void) +{ + const char *hint = SDL_GetHint(SDL_HINT_RENDER_SCALE_QUALITY); + + if (!hint || *hint == '0' || SDL_strcasecmp(hint, "nearest") == 0) { + return GU_NEAREST; // GU_NEAREST good for tile-map + } else { + return GU_LINEAR; // GU_LINEAR good for scaling + } +} + +static int +PixelFormatToPSPFMT(Uint32 format) +{ + switch (format) { + case SDL_PIXELFORMAT_BGR565: + return GU_PSM_5650; + case SDL_PIXELFORMAT_ABGR1555: + return GU_PSM_5551; + case SDL_PIXELFORMAT_ABGR4444: + return GU_PSM_4444; + case SDL_PIXELFORMAT_ABGR8888: + return GU_PSM_8888; + default: + return GU_PSM_8888; + } +} + +void +StartDrawing(SDL_Renderer * renderer) +{ + PSP_RenderData *data = (PSP_RenderData *) renderer->driverdata; + if(data->displayListAvail) + return; + + sceGuStart(GU_DIRECT, DisplayList); + data->displayListAvail = SDL_TRUE; +} + + +int +TextureSwizzle(PSP_TextureData *psp_texture) +{ + if(psp_texture->swizzled) + return 1; + + int bytewidth = psp_texture->textureWidth*(psp_texture->bits>>3); + int height = psp_texture->size / bytewidth; + + int rowblocks = (bytewidth>>4); + int rowblocksadd = (rowblocks-1)<<7; + unsigned int blockaddress = 0; + unsigned int *src = (unsigned int*) psp_texture->data; + + unsigned char *data = NULL; + data = malloc(psp_texture->size); + + int j; + + for(j = 0; j < height; j++, blockaddress += 16) + { + unsigned int *block; + + block = (unsigned int*)&data[blockaddress]; + + int i; + + for(i = 0; i < rowblocks; i++) + { + *block++ = *src++; + *block++ = *src++; + *block++ = *src++; + *block++ = *src++; + block += 28; + } + + if((j & 0x7) == 0x7) + blockaddress += rowblocksadd; + } + + free(psp_texture->data); + psp_texture->data = data; + psp_texture->swizzled = SDL_TRUE; + + return 1; +} +int TextureUnswizzle(PSP_TextureData *psp_texture) +{ + if(!psp_texture->swizzled) + return 1; + + int blockx, blocky; + + int bytewidth = psp_texture->textureWidth*(psp_texture->bits>>3); + int height = psp_texture->size / bytewidth; + + int widthblocks = bytewidth/16; + int heightblocks = height/8; + + int dstpitch = (bytewidth - 16)/4; + int dstrow = bytewidth * 8; + + unsigned int *src = (unsigned int*) psp_texture->data; + + unsigned char *data = NULL; + + data = malloc(psp_texture->size); + + if(!data) + return 0; + + sceKernelDcacheWritebackAll(); + + int j; + + unsigned char *ydst = (unsigned char *)data; + + for(blocky = 0; blocky < heightblocks; ++blocky) + { + unsigned char *xdst = ydst; + + for(blockx = 0; blockx < widthblocks; ++blockx) + { + unsigned int *block; + + block = (unsigned int*)xdst; + + for(j = 0; j < 8; ++j) + { + *(block++) = *(src++); + *(block++) = *(src++); + *(block++) = *(src++); + *(block++) = *(src++); + block += dstpitch; + } + + xdst += 16; + } + + ydst += dstrow; + } + + free(psp_texture->data); + + psp_texture->data = data; + + psp_texture->swizzled = SDL_FALSE; + + return 1; +} + +SDL_Renderer * +PSP_CreateRenderer(SDL_Window * window, Uint32 flags) +{ + + SDL_Renderer *renderer; + PSP_RenderData *data; + int pixelformat; + renderer = (SDL_Renderer *) SDL_calloc(1, sizeof(*renderer)); + if (!renderer) { + SDL_OutOfMemory(); + return NULL; + } + + data = (PSP_RenderData *) SDL_calloc(1, sizeof(*data)); + if (!data) { + PSP_DestroyRenderer(renderer); + SDL_OutOfMemory(); + return NULL; + } + + + renderer->WindowEvent = PSP_WindowEvent; + renderer->CreateTexture = PSP_CreateTexture; + renderer->UpdateTexture = PSP_UpdateTexture; + renderer->LockTexture = PSP_LockTexture; + renderer->UnlockTexture = PSP_UnlockTexture; + renderer->SetRenderTarget = PSP_SetRenderTarget; + renderer->UpdateViewport = PSP_UpdateViewport; + renderer->RenderClear = PSP_RenderClear; + renderer->RenderDrawPoints = PSP_RenderDrawPoints; + renderer->RenderDrawLines = PSP_RenderDrawLines; + renderer->RenderFillRects = PSP_RenderFillRects; + renderer->RenderCopy = PSP_RenderCopy; + renderer->RenderReadPixels = PSP_RenderReadPixels; + renderer->RenderCopyEx = PSP_RenderCopyEx; + renderer->RenderPresent = PSP_RenderPresent; + renderer->DestroyTexture = PSP_DestroyTexture; + renderer->DestroyRenderer = PSP_DestroyRenderer; + renderer->info = PSP_RenderDriver.info; + renderer->info.flags = SDL_RENDERER_ACCELERATED; + renderer->driverdata = data; + renderer->window = window; + + if (data->initialized != SDL_FALSE) + return 0; + data->initialized = SDL_TRUE; + + if (flags & SDL_RENDERER_PRESENTVSYNC) { + data->vsync = SDL_TRUE; + } else { + data->vsync = SDL_FALSE; + } + + pixelformat=PixelFormatToPSPFMT(SDL_GetWindowPixelFormat(window)); + switch(pixelformat) + { + case GU_PSM_4444: + case GU_PSM_5650: + case GU_PSM_5551: + data->frontbuffer = (unsigned int *)(PSP_FRAME_BUFFER_SIZE<<1); + data->backbuffer = (unsigned int *)(0); + data->bpp = 2; + data->psm = pixelformat; + break; + default: + data->frontbuffer = (unsigned int *)(PSP_FRAME_BUFFER_SIZE<<2); + data->backbuffer = (unsigned int *)(0); + data->bpp = 4; + data->psm = GU_PSM_8888; + break; + } + + sceGuInit(); + // setup GU + sceGuStart(GU_DIRECT, DisplayList); + sceGuDrawBuffer(data->psm, data->frontbuffer, PSP_FRAME_BUFFER_WIDTH); + sceGuDispBuffer(PSP_SCREEN_WIDTH, PSP_SCREEN_HEIGHT, data->backbuffer, PSP_FRAME_BUFFER_WIDTH); + + + sceGuOffset(2048 - (PSP_SCREEN_WIDTH>>1), 2048 - (PSP_SCREEN_HEIGHT>>1)); + sceGuViewport(2048, 2048, PSP_SCREEN_WIDTH, PSP_SCREEN_HEIGHT); + + data->frontbuffer = vabsptr(data->frontbuffer); + data->backbuffer = vabsptr(data->backbuffer); + + // Scissoring + sceGuScissor(0, 0, PSP_SCREEN_WIDTH, PSP_SCREEN_HEIGHT); + sceGuEnable(GU_SCISSOR_TEST); + + // Backface culling + sceGuFrontFace(GU_CCW); + sceGuEnable(GU_CULL_FACE); + + // Texturing + sceGuEnable(GU_TEXTURE_2D); + sceGuShadeModel(GU_SMOOTH); + sceGuTexWrap(GU_REPEAT, GU_REPEAT); + + // Blending + sceGuEnable(GU_BLEND); + sceGuBlendFunc(GU_ADD, GU_SRC_ALPHA, GU_ONE_MINUS_SRC_ALPHA, 0, 0); + + sceGuTexFilter(GU_LINEAR,GU_LINEAR); + + sceGuFinish(); + sceGuSync(0,0); + sceDisplayWaitVblankStartCB(); + sceGuDisplay(GU_TRUE); + + return renderer; +} + +static void +PSP_WindowEvent(SDL_Renderer * renderer, const SDL_WindowEvent *event) +{ + +} + + +static int +PSP_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture) +{ +// PSP_RenderData *renderdata = (PSP_RenderData *) renderer->driverdata; + PSP_TextureData* psp_texture = (PSP_TextureData*) SDL_calloc(1, sizeof(*psp_texture));; + + if(!psp_texture) + return -1; + + psp_texture->swizzled = SDL_FALSE; + psp_texture->width = texture->w; + psp_texture->height = texture->h; + psp_texture->textureHeight = TextureNextPow2(texture->h); + psp_texture->textureWidth = TextureNextPow2(texture->w); + psp_texture->format = PixelFormatToPSPFMT(texture->format); + + switch(psp_texture->format) + { + case GU_PSM_5650: + case GU_PSM_5551: + case GU_PSM_4444: + psp_texture->bits = 16; + break; + + case GU_PSM_8888: + psp_texture->bits = 32; + break; + + default: + return -1; + } + + psp_texture->pitch = psp_texture->textureWidth * SDL_BYTESPERPIXEL(texture->format); + psp_texture->size = psp_texture->textureHeight*psp_texture->pitch; + psp_texture->data = SDL_calloc(1, psp_texture->size); + + if(!psp_texture->data) + { + SDL_free(psp_texture); + return SDL_OutOfMemory(); + } + texture->driverdata = psp_texture; + + return 0; +} + + +void +TextureActivate(SDL_Texture * texture) +{ + PSP_TextureData *psp_texture = (PSP_TextureData *) texture->driverdata; + int scaleMode = GetScaleQuality(); + + // Swizzling is useless with small textures. + if (texture->w >= 16 || texture->h >= 16) + { + TextureSwizzle(psp_texture); + } + + sceGuEnable(GU_TEXTURE_2D); + sceGuTexWrap(GU_REPEAT, GU_REPEAT); + sceGuTexMode(psp_texture->format, 0, 0, psp_texture->swizzled); + sceGuTexFilter(scaleMode, scaleMode); // GU_NEAREST good for tile-map + // GU_LINEAR good for scaling + sceGuTexImage(0, psp_texture->textureWidth, psp_texture->textureHeight, psp_texture->textureWidth, psp_texture->data); + sceGuTexFunc(GU_TFX_REPLACE, GU_TCC_RGBA); +} + + +static int +PSP_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture, + const SDL_Rect * rect, const void *pixels, int pitch) +{ +// PSP_TextureData *psp_texture = (PSP_TextureData *) texture->driverdata; + const Uint8 *src; + Uint8 *dst; + int row, length,dpitch; + src = pixels; + + PSP_LockTexture(renderer, texture,rect,(void **)&dst, &dpitch); + length = rect->w * SDL_BYTESPERPIXEL(texture->format); + if (length == pitch && length == dpitch) { + SDL_memcpy(dst, src, length*rect->h); + } else { + for (row = 0; row < rect->h; ++row) { + SDL_memcpy(dst, src, length); + src += pitch; + dst += dpitch; + } + } + + sceKernelDcacheWritebackAll(); + return 0; +} + +static int +PSP_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture, + const SDL_Rect * rect, void **pixels, int *pitch) +{ + PSP_TextureData *psp_texture = (PSP_TextureData *) texture->driverdata; + + *pixels = + (void *) ((Uint8 *) psp_texture->data + rect->y * psp_texture->pitch + + rect->x * SDL_BYTESPERPIXEL(texture->format)); + *pitch = psp_texture->pitch; + return 0; +} + +static void +PSP_UnlockTexture(SDL_Renderer * renderer, SDL_Texture * texture) +{ + PSP_TextureData *psp_texture = (PSP_TextureData *) texture->driverdata; + SDL_Rect rect; + + /* We do whole texture updates, at least for now */ + rect.x = 0; + rect.y = 0; + rect.w = texture->w; + rect.h = texture->h; + PSP_UpdateTexture(renderer, texture, &rect, psp_texture->data, psp_texture->pitch); +} + +static int +PSP_SetRenderTarget(SDL_Renderer * renderer, SDL_Texture * texture) +{ + + return 0; +} + +static int +PSP_UpdateViewport(SDL_Renderer * renderer) +{ + + return 0; +} + + +static void +PSP_SetBlendMode(SDL_Renderer * renderer, int blendMode) +{ + PSP_RenderData *data = (PSP_RenderData *) renderer->driverdata; + if (blendMode != data-> currentBlendMode) { + switch (blendMode) { + case SDL_BLENDMODE_NONE: + sceGuTexFunc(GU_TFX_REPLACE, GU_TCC_RGBA); + sceGuDisable(GU_BLEND); + break; + case SDL_BLENDMODE_BLEND: + sceGuTexFunc(GU_TFX_MODULATE , GU_TCC_RGBA); + sceGuEnable(GU_BLEND); + sceGuBlendFunc(GU_ADD, GU_SRC_ALPHA, GU_ONE_MINUS_SRC_ALPHA, 0, 0 ); + break; + case SDL_BLENDMODE_ADD: + sceGuTexFunc(GU_TFX_MODULATE , GU_TCC_RGBA); + sceGuEnable(GU_BLEND); + sceGuBlendFunc(GU_ADD, GU_SRC_ALPHA, GU_FIX, 0, 0x00FFFFFF ); + break; + case SDL_BLENDMODE_MOD: + sceGuTexFunc(GU_TFX_MODULATE , GU_TCC_RGBA); + sceGuEnable(GU_BLEND); + sceGuBlendFunc( GU_ADD, GU_FIX, GU_SRC_COLOR, 0, 0); + break; + } + data->currentBlendMode = blendMode; + } +} + + + +static int +PSP_RenderClear(SDL_Renderer * renderer) +{ + //start list + StartDrawing(renderer); + int color = renderer->a << 24 | renderer->b << 16 | renderer->g << 8 | renderer->r; + sceGuClearColor(color); + sceGuClearDepth(0); + sceGuClear(GU_COLOR_BUFFER_BIT|GU_DEPTH_BUFFER_BIT|GU_FAST_CLEAR_BIT); + + return 0; +} + +static int +PSP_RenderDrawPoints(SDL_Renderer * renderer, const SDL_FPoint * points, + int count) +{ + int color = renderer->a << 24 | renderer->b << 16 | renderer->g << 8 | renderer->r; + int i; + StartDrawing(renderer); + VertV* vertices = (VertV*)sceGuGetMemory(count*sizeof(VertV)); + + for (i = 0; i < count; ++i) { + vertices[i].x = points[i].x; + vertices[i].y = points[i].y; + vertices[i].z = 0.0f; + } + sceGuDisable(GU_TEXTURE_2D); + sceGuColor(color); + sceGuShadeModel(GU_FLAT); + sceGuDrawArray(GU_POINTS, GU_VERTEX_32BITF|GU_TRANSFORM_2D, count, 0, vertices); + sceGuShadeModel(GU_SMOOTH); + sceGuEnable(GU_TEXTURE_2D); + + return 0; +} + +static int +PSP_RenderDrawLines(SDL_Renderer * renderer, const SDL_FPoint * points, + int count) +{ + int color = renderer->a << 24 | renderer->b << 16 | renderer->g << 8 | renderer->r; + int i; + StartDrawing(renderer); + VertV* vertices = (VertV*)sceGuGetMemory(count*sizeof(VertV)); + + for (i = 0; i < count; ++i) { + vertices[i].x = points[i].x; + vertices[i].y = points[i].y; + vertices[i].z = 0.0f; + } + + sceGuDisable(GU_TEXTURE_2D); + sceGuColor(color); + sceGuShadeModel(GU_FLAT); + sceGuDrawArray(GU_LINE_STRIP, GU_VERTEX_32BITF|GU_TRANSFORM_2D, count, 0, vertices); + sceGuShadeModel(GU_SMOOTH); + sceGuEnable(GU_TEXTURE_2D); + + return 0; +} + +static int +PSP_RenderFillRects(SDL_Renderer * renderer, const SDL_FRect * rects, + int count) +{ + int color = renderer->a << 24 | renderer->b << 16 | renderer->g << 8 | renderer->r; + int i; + StartDrawing(renderer); + + for (i = 0; i < count; ++i) { + const SDL_FRect *rect = &rects[i]; + VertV* vertices = (VertV*)sceGuGetMemory((sizeof(VertV)<<1)); + vertices[0].x = rect->x; + vertices[0].y = rect->y; + vertices[0].z = 0.0f; + + vertices[1].x = rect->x + rect->w; + vertices[1].y = rect->y + rect->h; + vertices[1].z = 0.0f; + + sceGuDisable(GU_TEXTURE_2D); + sceGuColor(color); + sceGuShadeModel(GU_FLAT); + sceGuDrawArray(GU_SPRITES, GU_VERTEX_32BITF|GU_TRANSFORM_2D, 2, 0, vertices); + sceGuShadeModel(GU_SMOOTH); + sceGuEnable(GU_TEXTURE_2D); + } + + return 0; +} + + +#define PI 3.14159265358979f + +#define radToDeg(x) ((x)*180.f/PI) +#define degToRad(x) ((x)*PI/180.f) + +float MathAbs(float x) +{ + float result; + + __asm__ volatile ( + "mtv %1, S000\n" + "vabs.s S000, S000\n" + "mfv %0, S000\n" + : "=r"(result) : "r"(x)); + + return result; +} + +void MathSincos(float r, float *s, float *c) +{ + __asm__ volatile ( + "mtv %2, S002\n" + "vcst.s S003, VFPU_2_PI\n" + "vmul.s S002, S002, S003\n" + "vrot.p C000, S002, [s, c]\n" + "mfv %0, S000\n" + "mfv %1, S001\n" + : "=r"(*s), "=r"(*c): "r"(r)); +} + +void Swap(float *a, float *b) +{ + float n=*a; + *a = *b; + *b = n; +} + +static int +PSP_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture, + const SDL_Rect * srcrect, const SDL_FRect * dstrect) +{ + float x, y, width, height; + float u0, v0, u1, v1; + unsigned char alpha; + + x = dstrect->x; + y = dstrect->y; + width = dstrect->w; + height = dstrect->h; + + u0 = srcrect->x; + v0 = srcrect->y; + u1 = srcrect->x + srcrect->w; + v1 = srcrect->y + srcrect->h; + + alpha = texture->a; + + StartDrawing(renderer); + TextureActivate(texture); + PSP_SetBlendMode(renderer, renderer->blendMode); + + if(alpha != 255) + { + sceGuTexFunc(GU_TFX_MODULATE, GU_TCC_RGBA); + sceGuColor(GU_RGBA(255, 255, 255, alpha)); + }else{ + sceGuTexFunc(GU_TFX_REPLACE, GU_TCC_RGBA); + sceGuColor(0xFFFFFFFF); + } + + if((MathAbs(u1) - MathAbs(u0)) < 64.0f) + { + VertTV* vertices = (VertTV*)sceGuGetMemory((sizeof(VertTV))<<1); + + vertices[0].u = u0; + vertices[0].v = v0; + vertices[0].x = x; + vertices[0].y = y; + vertices[0].z = 0; + + vertices[1].u = u1; + vertices[1].v = v1; + vertices[1].x = x + width; + vertices[1].y = y + height; + vertices[1].z = 0; + + sceGuDrawArray(GU_SPRITES, GU_TEXTURE_32BITF|GU_VERTEX_32BITF|GU_TRANSFORM_2D, 2, 0, vertices); + } + else + { + float start, end; + float curU = u0; + float curX = x; + float endX = x + width; + float slice = 64.0f; + float ustep = (u1 - u0)/width * slice; + + if(ustep < 0.0f) + ustep = -ustep; + + for(start = 0, end = width; start < end; start += slice) + { + VertTV* vertices = (VertTV*)sceGuGetMemory((sizeof(VertTV))<<1); + + float polyWidth = ((curX + slice) > endX) ? (endX - curX) : slice; + float sourceWidth = ((curU + ustep) > u1) ? (u1 - curU) : ustep; + + vertices[0].u = curU; + vertices[0].v = v0; + vertices[0].x = curX; + vertices[0].y = y; + vertices[0].z = 0; + + curU += sourceWidth; + curX += polyWidth; + + vertices[1].u = curU; + vertices[1].v = v1; + vertices[1].x = curX; + vertices[1].y = (y + height); + vertices[1].z = 0; + + sceGuDrawArray(GU_SPRITES, GU_TEXTURE_32BITF|GU_VERTEX_32BITF|GU_TRANSFORM_2D, 2, 0, vertices); + } + } + + if(alpha != 255) + sceGuTexFunc(GU_TFX_REPLACE, GU_TCC_RGBA); + return 0; +} + +static int +PSP_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect, + Uint32 pixel_format, void * pixels, int pitch) + +{ + return 0; +} + + +static int +PSP_RenderCopyEx(SDL_Renderer * renderer, SDL_Texture * texture, + const SDL_Rect * srcrect, const SDL_FRect * dstrect, + const double angle, const SDL_FPoint *center, const SDL_RendererFlip flip) +{ + float x, y, width, height; + float u0, v0, u1, v1; + unsigned char alpha; + float centerx, centery; + + x = dstrect->x; + y = dstrect->y; + width = dstrect->w; + height = dstrect->h; + + u0 = srcrect->x; + v0 = srcrect->y; + u1 = srcrect->x + srcrect->w; + v1 = srcrect->y + srcrect->h; + + centerx = center->x; + centery = center->y; + + alpha = texture->a; + + StartDrawing(renderer); + TextureActivate(texture); + PSP_SetBlendMode(renderer, renderer->blendMode); + + if(alpha != 255) + { + sceGuTexFunc(GU_TFX_MODULATE, GU_TCC_RGBA); + sceGuColor(GU_RGBA(255, 255, 255, alpha)); + }else{ + sceGuTexFunc(GU_TFX_REPLACE, GU_TCC_RGBA); + sceGuColor(0xFFFFFFFF); + } + +// x += width * 0.5f; +// y += height * 0.5f; + x += centerx; + y += centery; + + float c, s; + + MathSincos(degToRad(angle), &s, &c); + +// width *= 0.5f; +// height *= 0.5f; + width -= centerx; + height -= centery; + + + float cw = c*width; + float sw = s*width; + float ch = c*height; + float sh = s*height; + + VertTV* vertices = (VertTV*)sceGuGetMemory(sizeof(VertTV)<<2); + + vertices[0].u = u0; + vertices[0].v = v0; + vertices[0].x = x - cw + sh; + vertices[0].y = y - sw - ch; + vertices[0].z = 0; + + vertices[1].u = u0; + vertices[1].v = v1; + vertices[1].x = x - cw - sh; + vertices[1].y = y - sw + ch; + vertices[1].z = 0; + + vertices[2].u = u1; + vertices[2].v = v1; + vertices[2].x = x + cw - sh; + vertices[2].y = y + sw + ch; + vertices[2].z = 0; + + vertices[3].u = u1; + vertices[3].v = v0; + vertices[3].x = x + cw + sh; + vertices[3].y = y + sw - ch; + vertices[3].z = 0; + + if (flip & SDL_FLIP_HORIZONTAL) { + Swap(&vertices[0].v, &vertices[2].v); + Swap(&vertices[1].v, &vertices[3].v); + } + if (flip & SDL_FLIP_VERTICAL) { + Swap(&vertices[0].u, &vertices[2].u); + Swap(&vertices[1].u, &vertices[3].u); + } + + sceGuDrawArray(GU_TRIANGLE_FAN, GU_TEXTURE_32BITF|GU_VERTEX_32BITF|GU_TRANSFORM_2D, 4, 0, vertices); + + if(alpha != 255) + sceGuTexFunc(GU_TFX_REPLACE, GU_TCC_RGBA); + return 0; +} + +static void +PSP_RenderPresent(SDL_Renderer * renderer) +{ + PSP_RenderData *data = (PSP_RenderData *) renderer->driverdata; + if(!data->displayListAvail) + return; + + data->displayListAvail = SDL_FALSE; + sceGuFinish(); + sceGuSync(0,0); + +// if(data->vsync) + sceDisplayWaitVblankStart(); + + data->backbuffer = data->frontbuffer; + data->frontbuffer = vabsptr(sceGuSwapBuffers()); + +} + +static void +PSP_DestroyTexture(SDL_Renderer * renderer, SDL_Texture * texture) +{ + PSP_RenderData *renderdata = (PSP_RenderData *) renderer->driverdata; + PSP_TextureData *psp_texture = (PSP_TextureData *) texture->driverdata; + + if (renderdata == 0) + return; + + if(psp_texture == 0) + return; + + if(psp_texture->data != 0) + { + free(psp_texture->data); + } + free(texture); + texture->driverdata = NULL; +} + +static void +PSP_DestroyRenderer(SDL_Renderer * renderer) +{ + PSP_RenderData *data = (PSP_RenderData *) renderer->driverdata; + if (data) { + if (!data->initialized) + return; + + StartDrawing(renderer); + + sceGuTerm(); +// vfree(data->backbuffer); +// vfree(data->frontbuffer); + + data->initialized = SDL_FALSE; + data->displayListAvail = SDL_FALSE; + SDL_free(data); + } + SDL_free(renderer); +} + +#endif /* SDL_VIDEO_RENDER_PSP */ + +/* vi: set ts=4 sw=4 expandtab: */ + diff --git a/src/render/software/SDL_blendfillrect.c b/src/render/software/SDL_blendfillrect.c index 7d11724869..ea05ea64b5 100644 --- a/src/render/software/SDL_blendfillrect.c +++ b/src/render/software/SDL_blendfillrect.c @@ -159,8 +159,7 @@ SDL_BlendFillRect_RGB(SDL_Surface * dst, const SDL_Rect * rect, } return 0; default: - SDL_Unsupported(); - return -1; + return SDL_Unsupported(); } } @@ -189,8 +188,7 @@ SDL_BlendFillRect_RGBA(SDL_Surface * dst, const SDL_Rect * rect, } return 0; default: - SDL_Unsupported(); - return -1; + return SDL_Unsupported(); } } @@ -201,14 +199,12 @@ SDL_BlendFillRect(SDL_Surface * dst, const SDL_Rect * rect, SDL_Rect clipped; if (!dst) { - SDL_SetError("Passed NULL destination surface"); - return -1; + return SDL_SetError("Passed NULL destination surface"); } /* This function doesn't work on surfaces < 8 bpp */ if (dst->format->BitsPerPixel < 8) { - SDL_SetError("SDL_BlendFillRect(): Unsupported surface format"); - return -1; + return SDL_SetError("SDL_BlendFillRect(): Unsupported surface format"); } /* If 'rect' == NULL, then fill the whole surface */ @@ -274,14 +270,12 @@ SDL_BlendFillRects(SDL_Surface * dst, const SDL_Rect * rects, int count, int status = 0; if (!dst) { - SDL_SetError("Passed NULL destination surface"); - return -1; + return SDL_SetError("Passed NULL destination surface"); } /* This function doesn't work on surfaces < 8 bpp */ if (dst->format->BitsPerPixel < 8) { - SDL_SetError("SDL_BlendFillRects(): Unsupported surface format"); - return -1; + return SDL_SetError("SDL_BlendFillRects(): Unsupported surface format"); } if (blendMode == SDL_BLENDMODE_BLEND || blendMode == SDL_BLENDMODE_ADD) { diff --git a/src/render/software/SDL_blendline.c b/src/render/software/SDL_blendline.c index f34e098de2..2ab0231b5d 100644 --- a/src/render/software/SDL_blendline.c +++ b/src/render/software/SDL_blendline.c @@ -711,14 +711,12 @@ SDL_BlendLine(SDL_Surface * dst, int x1, int y1, int x2, int y2, BlendLineFunc func; if (!dst) { - SDL_SetError("SDL_BlendLine(): Passed NULL destination surface"); - return -1; + return SDL_SetError("SDL_BlendLine(): Passed NULL destination surface"); } func = SDL_CalculateBlendLineFunc(dst->format); if (!func) { - SDL_SetError("SDL_BlendLine(): Unsupported surface format"); - return -1; + return SDL_SetError("SDL_BlendLine(): Unsupported surface format"); } /* Perform clipping */ @@ -742,14 +740,12 @@ SDL_BlendLines(SDL_Surface * dst, const SDL_Point * points, int count, BlendLineFunc func; if (!dst) { - SDL_SetError("SDL_BlendLines(): Passed NULL destination surface"); - return -1; + return SDL_SetError("SDL_BlendLines(): Passed NULL destination surface"); } func = SDL_CalculateBlendLineFunc(dst->format); if (!func) { - SDL_SetError("SDL_BlendLines(): Unsupported surface format"); - return -1; + return SDL_SetError("SDL_BlendLines(): Unsupported surface format"); } for (i = 1; i < count; ++i) { diff --git a/src/render/software/SDL_blendpoint.c b/src/render/software/SDL_blendpoint.c index 772a8efa89..e2fa66fd80 100644 --- a/src/render/software/SDL_blendpoint.c +++ b/src/render/software/SDL_blendpoint.c @@ -159,8 +159,7 @@ SDL_BlendPoint_RGB(SDL_Surface * dst, int x, int y, SDL_BlendMode blendMode, Uin } return 0; default: - SDL_Unsupported(); - return -1; + return SDL_Unsupported(); } } @@ -189,8 +188,7 @@ SDL_BlendPoint_RGBA(SDL_Surface * dst, int x, int y, SDL_BlendMode blendMode, Ui } return 0; default: - SDL_Unsupported(); - return -1; + return SDL_Unsupported(); } } @@ -199,14 +197,12 @@ SDL_BlendPoint(SDL_Surface * dst, int x, int y, SDL_BlendMode blendMode, Uint8 r Uint8 g, Uint8 b, Uint8 a) { if (!dst) { - SDL_SetError("Passed NULL destination surface"); - return -1; + return SDL_SetError("Passed NULL destination surface"); } /* This function doesn't work on surfaces < 8 bpp */ if (dst->format->BitsPerPixel < 8) { - SDL_SetError("SDL_BlendPoint(): Unsupported surface format"); - return -1; + return SDL_SetError("SDL_BlendPoint(): Unsupported surface format"); } /* Perform clipping */ @@ -272,14 +268,12 @@ SDL_BlendPoints(SDL_Surface * dst, const SDL_Point * points, int count, int status = 0; if (!dst) { - SDL_SetError("Passed NULL destination surface"); - return -1; + return SDL_SetError("Passed NULL destination surface"); } /* This function doesn't work on surfaces < 8 bpp */ if (dst->format->BitsPerPixel < 8) { - SDL_SetError("SDL_BlendPoints(): Unsupported surface format"); - return (-1); + return SDL_SetError("SDL_BlendPoints(): Unsupported surface format"); } if (blendMode == SDL_BLENDMODE_BLEND || blendMode == SDL_BLENDMODE_ADD) { diff --git a/src/render/software/SDL_drawline.c b/src/render/software/SDL_drawline.c index 510e7ffb5d..9f5da0ab64 100644 --- a/src/render/software/SDL_drawline.c +++ b/src/render/software/SDL_drawline.c @@ -145,14 +145,12 @@ SDL_DrawLine(SDL_Surface * dst, int x1, int y1, int x2, int y2, Uint32 color) DrawLineFunc func; if (!dst) { - SDL_SetError("SDL_DrawLine(): Passed NULL destination surface"); - return -1; + return SDL_SetError("SDL_DrawLine(): Passed NULL destination surface"); } func = SDL_CalculateDrawLineFunc(dst->format); if (!func) { - SDL_SetError("SDL_DrawLine(): Unsupported surface format"); - return -1; + return SDL_SetError("SDL_DrawLine(): Unsupported surface format"); } /* Perform clipping */ @@ -176,14 +174,12 @@ SDL_DrawLines(SDL_Surface * dst, const SDL_Point * points, int count, DrawLineFunc func; if (!dst) { - SDL_SetError("SDL_DrawLines(): Passed NULL destination surface"); - return -1; + return SDL_SetError("SDL_DrawLines(): Passed NULL destination surface"); } func = SDL_CalculateDrawLineFunc(dst->format); if (!func) { - SDL_SetError("SDL_DrawLines(): Unsupported surface format"); - return -1; + return SDL_SetError("SDL_DrawLines(): Unsupported surface format"); } for (i = 1; i < count; ++i) { diff --git a/src/render/software/SDL_drawpoint.c b/src/render/software/SDL_drawpoint.c index a570deae82..1ae8419c1c 100644 --- a/src/render/software/SDL_drawpoint.c +++ b/src/render/software/SDL_drawpoint.c @@ -30,14 +30,12 @@ int SDL_DrawPoint(SDL_Surface * dst, int x, int y, Uint32 color) { if (!dst) { - SDL_SetError("Passed NULL destination surface"); - return -1; + return SDL_SetError("Passed NULL destination surface"); } /* This function doesn't work on surfaces < 8 bpp */ if (dst->format->BitsPerPixel < 8) { - SDL_SetError("SDL_DrawPoint(): Unsupported surface format"); - return -1; + return SDL_SetError("SDL_DrawPoint(): Unsupported surface format"); } /* Perform clipping */ @@ -55,8 +53,7 @@ SDL_DrawPoint(SDL_Surface * dst, int x, int y, Uint32 color) DRAW_FASTSETPIXELXY2(x, y); break; case 3: - SDL_Unsupported(); - return -1; + return SDL_Unsupported(); case 4: DRAW_FASTSETPIXELXY4(x, y); break; @@ -74,14 +71,12 @@ SDL_DrawPoints(SDL_Surface * dst, const SDL_Point * points, int count, int x, y; if (!dst) { - SDL_SetError("Passed NULL destination surface"); - return -1; + return SDL_SetError("Passed NULL destination surface"); } /* This function doesn't work on surfaces < 8 bpp */ if (dst->format->BitsPerPixel < 8) { - SDL_SetError("SDL_DrawPoints(): Unsupported surface format"); - return -1; + return SDL_SetError("SDL_DrawPoints(): Unsupported surface format"); } minx = dst->clip_rect.x; @@ -105,8 +100,7 @@ SDL_DrawPoints(SDL_Surface * dst, const SDL_Point * points, int count, DRAW_FASTSETPIXELXY2(x, y); break; case 3: - SDL_Unsupported(); - return -1; + return SDL_Unsupported(); case 4: DRAW_FASTSETPIXELXY4(x, y); break; diff --git a/src/render/software/SDL_render_sw.c b/src/render/software/SDL_render_sw.c index bf9606ebda..21ff1a9aef 100644 --- a/src/render/software/SDL_render_sw.c +++ b/src/render/software/SDL_render_sw.c @@ -200,8 +200,7 @@ SW_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture) if (!SDL_PixelFormatEnumToMasks (texture->format, &bpp, &Rmask, &Gmask, &Bmask, &Amask)) { - SDL_SetError("Unknown texture format"); - return -1; + return SDL_SetError("Unknown texture format"); } texture->driverdata = @@ -357,8 +356,7 @@ SW_RenderDrawPoints(SDL_Renderer * renderer, const SDL_FPoint * points, final_points = SDL_stack_alloc(SDL_Point, count); if (!final_points) { - SDL_OutOfMemory(); - return -1; + return SDL_OutOfMemory(); } if (renderer->viewport.x || renderer->viewport.y) { int x = renderer->viewport.x; @@ -407,8 +405,7 @@ SW_RenderDrawLines(SDL_Renderer * renderer, const SDL_FPoint * points, final_points = SDL_stack_alloc(SDL_Point, count); if (!final_points) { - SDL_OutOfMemory(); - return -1; + return SDL_OutOfMemory(); } if (renderer->viewport.x || renderer->viewport.y) { int x = renderer->viewport.x; @@ -456,8 +453,7 @@ SW_RenderFillRects(SDL_Renderer * renderer, const SDL_FRect * rects, int count) final_rects = SDL_stack_alloc(SDL_Rect, count); if (!final_rects) { - SDL_OutOfMemory(); - return -1; + return SDL_OutOfMemory(); } if (renderer->viewport.x || renderer->viewport.y) { int x = renderer->viewport.x; @@ -647,8 +643,7 @@ SW_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect, if (rect->x < 0 || rect->x+rect->w > surface->w || rect->y < 0 || rect->y+rect->h > surface->h) { - SDL_SetError("Tried to read outside of surface bounds"); - return -1; + return SDL_SetError("Tried to read outside of surface bounds"); } src_format = surface->format->format; diff --git a/src/stdlib/SDL_getenv.c b/src/stdlib/SDL_getenv.c index 161003004f..9079387cd7 100644 --- a/src/stdlib/SDL_getenv.c +++ b/src/stdlib/SDL_getenv.c @@ -22,18 +22,19 @@ #include "SDL_stdinc.h" -#ifndef HAVE_GETENV - -#if defined(__WIN32__) - +#if !defined(SDL_setenv) && defined(__WIN32__) #include "../core/windows/SDL_windows.h" - /* Note this isn't thread-safe! */ - static char *SDL_envmem = NULL; /* Ugh, memory leak */ static size_t SDL_envmemlen = 0; +#endif + /* Put a variable into the environment */ +#ifdef SDL_setenv +#undef SDL_setenv +int SDL_setenv(const char *name, const char *value, int overwrite) { return SDL_setenv_inline(name, value, overwrite); } +#elif defined(__WIN32__) int SDL_setenv(const char *name, const char *value, int overwrite) { @@ -49,35 +50,34 @@ SDL_setenv(const char *name, const char *value, int overwrite) } return 0; } - -/* Retrieve a variable named "name" from the environment */ -char * -SDL_getenv(const char *name) +/* We have a real environment table, but no real setenv? Fake it w/ putenv. */ +#elif (defined(HAVE_GETENV) && defined(HAVE_PUTENV) && !defined(HAVE_SETENV)) +int +SDL_setenv(const char *name, const char *value, int overwrite) { - size_t bufferlen; + size_t len; + char *new_variable; - bufferlen = - GetEnvironmentVariableA(name, SDL_envmem, (DWORD) SDL_envmemlen); - if (bufferlen == 0) { - return NULL; - } - if (bufferlen > SDL_envmemlen) { - char *newmem = (char *) SDL_realloc(SDL_envmem, bufferlen); - if (newmem == NULL) { - return NULL; + if (getenv(name) != NULL) { + if (overwrite) { + unsetenv(name); + } else { + return 0; /* leave the existing one there. */ } - SDL_envmem = newmem; - SDL_envmemlen = bufferlen; - GetEnvironmentVariableA(name, SDL_envmem, (DWORD) SDL_envmemlen); } - return SDL_envmem; -} -#else /* roll our own */ + /* This leaks. Sorry. Get a better OS so we don't have to do this. */ + len = SDL_strlen(name) + SDL_strlen(value) + 2; + new_variable = (char *) SDL_malloc(len); + if (!new_variable) { + return (-1); + } + SDL_snprintf(new_variable, len, "%s=%s", name, value); + return putenv(new_variable); +} +#else /* roll our own */ static char **SDL_env = (char **) 0; - -/* Put a variable into the environment */ int SDL_setenv(const char *name, const char *value, int overwrite) { @@ -140,8 +140,35 @@ SDL_setenv(const char *name, const char *value, int overwrite) } return (added ? 0 : -1); } +#endif /* Retrieve a variable named "name" from the environment */ +#ifdef SDL_getenv +#undef SDL_getenv +char *SDL_getenv(const char *name) { return SDL_getenv_inline(name); } +#elif defined(__WIN32__) +char * +SDL_getenv(const char *name) +{ + size_t bufferlen; + + bufferlen = + GetEnvironmentVariableA(name, SDL_envmem, (DWORD) SDL_envmemlen); + if (bufferlen == 0) { + return NULL; + } + if (bufferlen > SDL_envmemlen) { + char *newmem = (char *) SDL_realloc(SDL_envmem, bufferlen); + if (newmem == NULL) { + return NULL; + } + SDL_envmem = newmem; + SDL_envmemlen = bufferlen; + GetEnvironmentVariableA(name, SDL_envmem, (DWORD) SDL_envmemlen); + } + return SDL_envmem; +} +#else char * SDL_getenv(const char *name) { @@ -160,38 +187,6 @@ SDL_getenv(const char *name) } return value; } - -#endif /* __WIN32__ */ - -#endif /* !HAVE_GETENV */ - - -/* We have a real environment table, but no real setenv? Fake it w/ putenv. */ -#if (defined(HAVE_GETENV) && defined(HAVE_PUTENV) && !defined(HAVE_SETENV)) -int -SDL_setenv(const char *name, const char *value, int overwrite) -{ - size_t len; - char *new_variable; - - if (getenv(name) != NULL) { - if (overwrite) { - unsetenv(name); - } else { - return 0; /* leave the existing one there. */ - } - } - - /* This leaks. Sorry. Get a better OS so we don't have to do this. */ - len = SDL_strlen(name) + SDL_strlen(value) + 2; - new_variable = (char *) SDL_malloc(len); - if (!new_variable) { - return (-1); - } - - SDL_snprintf(new_variable, len, "%s=%s", name, value); - return putenv(new_variable); -} #endif diff --git a/src/stdlib/SDL_iconv.c b/src/stdlib/SDL_iconv.c index 8d2f2c034d..4e5e51d871 100644 --- a/src/stdlib/SDL_iconv.c +++ b/src/stdlib/SDL_iconv.c @@ -38,6 +38,20 @@ #include <errno.h> +SDL_COMPILE_TIME_ASSERT(iconv_t, sizeof (iconv_t) <= sizeof (SDL_iconv_t)); + +SDL_iconv_t +SDL_iconv_open(const char *tocode, const char *fromcode) +{ + return (SDL_iconv_t) ((size_t) iconv_open(tocode, fromcode)); +} + +int +SDL_iconv_close(SDL_iconv_t cd) +{ + return iconv_close((iconv_t) ((size_t) cd)); +} + size_t SDL_iconv(SDL_iconv_t cd, const char **inbuf, size_t * inbytesleft, @@ -45,9 +59,9 @@ SDL_iconv(SDL_iconv_t cd, { size_t retCode; #ifdef ICONV_INBUF_NONCONST - retCode = iconv(cd, (char **) inbuf, inbytesleft, outbuf, outbytesleft); + retCode = iconv((iconv_t) ((size_t) cd), (char **) inbuf, inbytesleft, outbuf, outbytesleft); #else - retCode = iconv(cd, inbuf, inbytesleft, outbuf, outbytesleft); + retCode = iconv((iconv_t) ((size_t) cd), inbuf, inbytesleft, outbuf, outbytesleft); #endif if (retCode == (size_t) - 1) { switch (errno) { diff --git a/src/stdlib/SDL_malloc.c b/src/stdlib/SDL_malloc.c index 6533f0b972..65d1e1d168 100644 --- a/src/stdlib/SDL_malloc.c +++ b/src/stdlib/SDL_malloc.c @@ -24,7 +24,18 @@ #include "SDL_stdinc.h" -#ifndef HAVE_MALLOC +#ifdef SDL_malloc +/* expose the symbol, but use what we figured out elsewhere. */ +#undef SDL_malloc +#undef SDL_calloc +#undef SDL_realloc +#undef SDL_free +void *SDL_malloc(size_t size) { return SDL_malloc_inline(size); } +void *SDL_calloc(size_t nmemb, size_t size) { return SDL_calloc_inline(nmemb, size); } +void *SDL_realloc(void *ptr, size_t size) { return SDL_realloc_inline(ptr, size); } +void SDL_free(void *ptr) { SDL_free_inline(ptr); } + +#else /* the rest of this is a LOT of tapdancing to implement malloc. :) */ #define LACKS_SYS_TYPES_H #define LACKS_STDIO_H diff --git a/src/stdlib/SDL_qsort.c b/src/stdlib/SDL_qsort.c index 6d56c67588..8c73419c9b 100644 --- a/src/stdlib/SDL_qsort.c +++ b/src/stdlib/SDL_qsort.c @@ -51,6 +51,15 @@ #include "SDL_stdinc.h" #include "SDL_assert.h" +#ifdef SDL_qsort +#undef SDL_qsort +void +SDL_qsort(void *base, size_t nmemb, size_t size, int (*compare) (const void *, const void *)) +{ + SDL_qsort_inline(base, nmemb, size, compare); +} +#else + #ifdef assert #undef assert #endif @@ -76,9 +85,6 @@ #endif #define qsort SDL_qsort - -#ifndef HAVE_QSORT - static const char _ID[] = "<qsort.c gjm 1.12 1998-03-19>"; /* How many bytes are there per word? (Must be a power of 2, @@ -466,5 +472,6 @@ qsort(void *base, size_t nmemb, size_t size, qsort_words(base, nmemb, compare); } -#endif /* !HAVE_QSORT */ +#endif /* !SDL_qsort */ + /* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/stdlib/SDL_stdlib.c b/src/stdlib/SDL_stdlib.c index 496b99e1f1..1c19ab72f3 100644 --- a/src/stdlib/SDL_stdlib.c +++ b/src/stdlib/SDL_stdlib.c @@ -24,6 +24,25 @@ #include "SDL_stdinc.h" +/* these are always #defined, make them real symbol in the library, too... */ +#undef SDL_ceil +#undef SDL_abs +#undef SDL_sinf +#undef SDL_cosf +#undef SDL_isdigit +#undef SDL_isspace +#undef SDL_toupper +#undef SDL_tolower +double SDL_ceil(double x) { return SDL_ceil_inline(x); } +float SDL_cosf(float x) { return SDL_cosf_inline(x); } +float SDL_sinf(float x) { return SDL_sinf_inline(x); } +int SDL_abs(int x) { return SDL_abs_inline(x); } +int SDL_isdigit(int x) { return SDL_isdigit_inline(x); } +int SDL_isspace(int x) { return SDL_isspace_inline(x); } +int SDL_toupper(int x) { return SDL_toupper_inline(x); } +int SDL_tolower(int x) { return SDL_tolower_inline(x); } + + #ifndef HAVE_LIBC /* These are some C runtime intrinsics that need to be defined */ diff --git a/src/stdlib/SDL_string.c b/src/stdlib/SDL_string.c index 89c14d9580..da02d8b097 100644 --- a/src/stdlib/SDL_string.c +++ b/src/stdlib/SDL_string.c @@ -24,6 +24,17 @@ #include "SDL_stdinc.h" +/* these are always #defined, make them real symbol in the library, too... */ +#undef SDL_itoa +#undef SDL_uitoa +#undef SDL_atoi +#undef SDL_atof +char *SDL_itoa(int value, char *str, int radix) { return SDL_itoa_inline(value, str, radix); } +char *SDL_uitoa(unsigned int value, char *str, int radix) { return SDL_uitoa_inline(value, str, radix); } +int SDL_atoi(const char *str) { return SDL_atoi_inline(str); } +double SDL_atof(const char *str) { return SDL_atof_inline(str); } + + #define SDL_isupperhex(X) (((X) >= 'A') && ((X) <= 'F')) #define SDL_islowerhex(X) (((X) >= 'a') && ((X) <= 'f')) @@ -43,7 +54,7 @@ static int UTF8_TrailingBytes(unsigned char c) return 0; } -#if !defined(HAVE_SSCANF) || !defined(HAVE_STRTOL) +#if !defined(SDL_sscanf) || !defined(SDL_strtol) static size_t SDL_ScanLong(const char *text, int radix, long *valuep) { @@ -84,7 +95,7 @@ SDL_ScanLong(const char *text, int radix, long *valuep) } #endif -#if !defined(HAVE_SSCANF) || !defined(HAVE_STRTOUL) || !defined(HAVE_STRTOD) +#if !defined(SDL_sscanf) || !defined(SDL_strtoul) || !defined(SDL_strtod) static size_t SDL_ScanUnsignedLong(const char *text, int radix, unsigned long *valuep) { @@ -116,7 +127,7 @@ SDL_ScanUnsignedLong(const char *text, int radix, unsigned long *valuep) } #endif -#ifndef HAVE_SSCANF +#ifndef SDL_sscanf static size_t SDL_ScanUintPtrT(const char *text, int radix, uintptr_t * valuep) { @@ -148,7 +159,7 @@ SDL_ScanUintPtrT(const char *text, int radix, uintptr_t * valuep) } #endif -#if !defined(HAVE_SSCANF) || !defined(HAVE_STRTOLL) +#if !defined(SDL_sscanf) || !defined(SDL_strtoll) static size_t SDL_ScanLongLong(const char *text, int radix, Sint64 * valuep) { @@ -189,7 +200,7 @@ SDL_ScanLongLong(const char *text, int radix, Sint64 * valuep) } #endif -#if !defined(HAVE_SSCANF) || !defined(HAVE_STRTOULL) +#if !defined(SDL_sscanf) || !defined(SDL_strtoull) static size_t SDL_ScanUnsignedLongLong(const char *text, int radix, Uint64 * valuep) { @@ -221,7 +232,7 @@ SDL_ScanUnsignedLongLong(const char *text, int radix, Uint64 * valuep) } #endif -#if !defined(HAVE_SSCANF) || !defined(HAVE_STRTOD) +#if !defined(SDL_sscanf) || !defined(SDL_strtod) static size_t SDL_ScanFloat(const char *text, double *valuep) { @@ -257,7 +268,11 @@ SDL_ScanFloat(const char *text, double *valuep) } #endif -#ifndef SDL_memset + +#ifdef SDL_memset +#undef SDL_memset +void *SDL_memset(void *dst, int c, size_t len) { return SDL_memset_inline(dst, c, len); } +#else void * SDL_memset(void *dst, int c, size_t len) { @@ -287,7 +302,11 @@ SDL_memset(void *dst, int c, size_t len) } #endif -#ifndef SDL_memcpy + +#ifdef SDL_memcpy +#undef SDL_memcpy +void *SDL_memcpy(void *dst, const void *src, size_t len) { return SDL_memcpy_inline(dst, src, len); } +#else void * SDL_memcpy(void *dst, const void *src, size_t len) { @@ -317,7 +336,11 @@ SDL_memcpy(void *dst, const void *src, size_t len) } #endif -#ifndef SDL_memmove + +#ifdef SDL_memmove +#undef SDL_memmove +void *SDL_memmove(void *dst, const void *src, size_t len) { return SDL_memmove_inline(dst, src, len); } +#else void * SDL_memmove(void *dst, const void *src, size_t len) { @@ -339,7 +362,10 @@ SDL_memmove(void *dst, const void *src, size_t len) } #endif -#ifndef SDL_memcmp +#ifdef SDL_memcmp +#undef SDL_memcmp +int SDL_memcmp(const void *s1, const void *s2, size_t len) { return SDL_memcmp_inline(s1, s2, len); } +#else int SDL_memcmp(const void *s1, const void *s2, size_t len) { @@ -356,7 +382,10 @@ SDL_memcmp(const void *s1, const void *s2, size_t len) } #endif -#ifndef HAVE_STRLEN +#ifdef SDL_strlen +#undef SDL_strlen +size_t SDL_strlen(const char *string) { return SDL_strlen_inline(string); } +#else size_t SDL_strlen(const char *string) { @@ -368,7 +397,10 @@ SDL_strlen(const char *string) } #endif -#ifndef HAVE_WCSLEN +#ifdef SDL_wcslen +#undef SDL_wcslen +size_t SDL_wcslen(const wchar_t * string) { return SDL_wcslen_inline(string); } +#else size_t SDL_wcslen(const wchar_t * string) { @@ -380,7 +412,10 @@ SDL_wcslen(const wchar_t * string) } #endif -#ifndef HAVE_WCSLCPY +#ifdef SDL_wcslcpy +#undef SDL_wcslcpy +size_t SDL_wcslcpy(wchar_t *dst, const wchar_t *src, size_t maxlen) { return SDL_wcslcpy_inline(dst, src, maxlen); } +#else size_t SDL_wcslcpy(wchar_t *dst, const wchar_t *src, size_t maxlen) { @@ -394,7 +429,10 @@ SDL_wcslcpy(wchar_t *dst, const wchar_t *src, size_t maxlen) } #endif -#ifndef HAVE_WCSLCAT +#ifdef SDL_wcslcat +#undef SDL_wcslcat +size_t SDL_wcslcat(wchar_t *dst, const wchar_t *src, size_t maxlen) { return SDL_wcslcat_inline(dst, src, maxlen); } +#else size_t SDL_wcslcat(wchar_t *dst, const wchar_t *src, size_t maxlen) { @@ -407,7 +445,10 @@ SDL_wcslcat(wchar_t *dst, const wchar_t *src, size_t maxlen) } #endif -#ifndef HAVE_STRLCPY +#ifdef SDL_strlcpy +#undef SDL_strlcpy +size_t SDL_strlcpy(char *dst, const char *src, size_t maxlen) { return SDL_strlcpy_inline(dst, src, maxlen); } +#else size_t SDL_strlcpy(char *dst, const char *src, size_t maxlen) { @@ -453,7 +494,10 @@ size_t SDL_utf8strlcpy(char *dst, const char *src, size_t dst_bytes) return bytes; } -#ifndef HAVE_STRLCAT +#ifdef SDL_strlcat +#undef SDL_strlcat +size_t SDL_strlcat(char *dst, const char *src, size_t maxlen) { return SDL_strlcat_inline(dst, src, maxlen); } +#else size_t SDL_strlcat(char *dst, const char *src, size_t maxlen) { @@ -466,7 +510,10 @@ SDL_strlcat(char *dst, const char *src, size_t maxlen) } #endif -#ifndef HAVE_STRDUP +#ifdef SDL_strdup +#undef SDL_strdup +char *SDL_strdup(const char *string) { return SDL_strdup_inline(string); } +#else char * SDL_strdup(const char *string) { @@ -479,7 +526,10 @@ SDL_strdup(const char *string) } #endif -#ifndef HAVE__STRREV +#ifdef SDL_strrev +#undef SDL_strrev +char *SDL_strrev(char *string) { return SDL_strrev_inline(string); } +#else char * SDL_strrev(char *string) { @@ -496,7 +546,10 @@ SDL_strrev(char *string) } #endif -#ifndef HAVE__STRUPR +#ifdef SDL_strupr +#undef SDL_strupr +char *SDL_strupr(char *string) { return SDL_strupr_inline(string); } +#else char * SDL_strupr(char *string) { @@ -509,7 +562,10 @@ SDL_strupr(char *string) } #endif -#ifndef HAVE__STRLWR +#ifdef SDL_strlwr +#undef SDL_strlwr +char *SDL_strlwr(char *string) { return SDL_strlwr_inline(string); } +#else char * SDL_strlwr(char *string) { @@ -522,7 +578,10 @@ SDL_strlwr(char *string) } #endif -#ifndef HAVE_STRCHR +#ifdef SDL_strchr +#undef SDL_strchr +char *SDL_strchr(const char *string, int c) { return SDL_strchr_inline(string, c); } +#else char * SDL_strchr(const char *string, int c) { @@ -536,7 +595,10 @@ SDL_strchr(const char *string, int c) } #endif -#ifndef HAVE_STRRCHR +#ifdef SDL_strrchr +#undef SDL_strrchr +char *SDL_strrchr(const char *string, int c) { return SDL_strrchr_inline(string, c); } +#else char * SDL_strrchr(const char *string, int c) { @@ -551,7 +613,10 @@ SDL_strrchr(const char *string, int c) } #endif -#ifndef HAVE_STRSTR +#ifdef SDL_strstr +#undef SDL_strstr +char *SDL_strstr(const char *haystack, const char *needle) { return SDL_strstr_inline(haystack, needle); } +#else char * SDL_strstr(const char *haystack, const char *needle) { @@ -566,8 +631,8 @@ SDL_strstr(const char *haystack, const char *needle) } #endif -#if !defined(HAVE__LTOA) || !defined(HAVE__I64TOA) || \ - !defined(HAVE__ULTOA) || !defined(HAVE__UI64TOA) +#if !defined(SDL_ltoa) || !defined(SDL_lltoa) || \ + !defined(SDL_ultoa) || !defined(SDL_ulltoa) static const char ntoa_table[] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', @@ -576,7 +641,10 @@ static const char ntoa_table[] = { }; #endif /* ntoa() conversion table */ -#ifndef HAVE__LTOA +#ifdef SDL_ltoa +#undef SDL_ltoa +char *SDL_ltoa(long value, char *string, int radix) { return SDL_ltoa_inline(value, string, radix); } +#else char * SDL_ltoa(long value, char *string, int radix) { @@ -607,7 +675,10 @@ SDL_ltoa(long value, char *string, int radix) } #endif -#ifndef HAVE__ULTOA +#ifdef SDL_ultoa +#undef SDL_ultoa +char *SDL_ultoa(unsigned long value, char *string, int radix) { return SDL_ultoa_inline(value, string, radix); } +#else char * SDL_ultoa(unsigned long value, char *string, int radix) { @@ -630,7 +701,10 @@ SDL_ultoa(unsigned long value, char *string, int radix) } #endif -#ifndef HAVE_STRTOL +#ifdef SDL_strtol +#undef SDL_strtol +long SDL_strtol(const char *string, char **endp, int base) { return SDL_strtol_inline(string, endp, base); } +#else long SDL_strtol(const char *string, char **endp, int base) { @@ -653,7 +727,10 @@ SDL_strtol(const char *string, char **endp, int base) } #endif -#ifndef HAVE_STRTOUL +#ifdef SDL_strtoul +#undef SDL_strtoul +unsigned long SDL_strtoul(const char *string, char **endp, int base) { return SDL_strtoul_inline(string, endp, base); } +#else unsigned long SDL_strtoul(const char *string, char **endp, int base) { @@ -676,7 +753,10 @@ SDL_strtoul(const char *string, char **endp, int base) } #endif -#ifndef HAVE__I64TOA +#ifdef SDL_lltoa +#undef SDL_lltoa +char *SDL_lltoa(Sint64 value, char *string, int radix) { return SDL_lltoa_inline(value, string, radix); } +#else char * SDL_lltoa(Sint64 value, char *string, int radix) { @@ -707,7 +787,10 @@ SDL_lltoa(Sint64 value, char *string, int radix) } #endif -#ifndef HAVE__UI64TOA +#ifdef SDL_ulltoa +#undef SDL_ulltoa +char *SDL_ulltoa(Uint64 value, char *string, int radix) { return SDL_ulltoa_inline(value, string, radix); } +#else char * SDL_ulltoa(Uint64 value, char *string, int radix) { @@ -730,7 +813,10 @@ SDL_ulltoa(Uint64 value, char *string, int radix) } #endif -#ifndef HAVE_STRTOLL +#ifdef SDL_strtoll +#undef SDL_strtoll +Sint64 SDL_strtoll(const char *string, char **endp, int base) { return SDL_strtoll_inline(string, endp, base); } +#else Sint64 SDL_strtoll(const char *string, char **endp, int base) { @@ -753,7 +839,10 @@ SDL_strtoll(const char *string, char **endp, int base) } #endif -#ifndef HAVE_STRTOULL +#ifdef SDL_strtoull +#undef SDL_strtoull +Uint64 SDL_strtoull(const char *string, char **endp, int base) { return SDL_strtoull_inline(string, endp, base); } +#else Uint64 SDL_strtoull(const char *string, char **endp, int base) { @@ -776,7 +865,10 @@ SDL_strtoull(const char *string, char **endp, int base) } #endif -#ifndef HAVE_STRTOD +#ifdef SDL_strtod +#undef SDL_strtod +double SDL_strtod(const char *string, char **endp) { return SDL_strtod_inline(string, endp); } +#else double SDL_strtod(const char *string, char **endp) { @@ -791,7 +883,10 @@ SDL_strtod(const char *string, char **endp) } #endif -#ifndef HAVE_STRCMP +#ifdef SDL_strcmp +#undef SDL_strcmp +int SDL_strcmp(const char *str1, const char *str2) { return SDL_strcmp_inline(str1, str2); } +#else int SDL_strcmp(const char *str1, const char *str2) { @@ -805,7 +900,10 @@ SDL_strcmp(const char *str1, const char *str2) } #endif -#ifndef HAVE_STRNCMP +#ifdef SDL_strncmp +#undef SDL_strncmp +int SDL_strncmp(const char *str1, const char *str2, size_t maxlen) { return SDL_strncmp_inline(str1, str2, maxlen); } +#else int SDL_strncmp(const char *str1, const char *str2, size_t maxlen) { @@ -823,7 +921,10 @@ SDL_strncmp(const char *str1, const char *str2, size_t maxlen) } #endif -#if !defined(HAVE_STRCASECMP) && !defined(HAVE__STRICMP) +#ifdef SDL_strcasecmp +#undef SDL_strcasecmp +int SDL_strcasecmp(const char *str1, const char *str2) { return SDL_strcasecmp_inline(str1, str2); } +#else int SDL_strcasecmp(const char *str1, const char *str2) { @@ -843,7 +944,10 @@ SDL_strcasecmp(const char *str1, const char *str2) } #endif -#if !defined(HAVE_STRNCASECMP) && !defined(HAVE__STRNICMP) +#ifdef SDL_strncasecmp +#undef SDL_strncasecmp +int SDL_strncasecmp(const char *str1, const char *str2, size_t maxlen) { return SDL_strncasecmp_inline(str1, str2, maxlen); } +#else int SDL_strncasecmp(const char *str1, const char *str2, size_t maxlen) { @@ -868,7 +972,19 @@ SDL_strncasecmp(const char *str1, const char *str2, size_t maxlen) } #endif -#ifndef HAVE_SSCANF +#ifdef SDL_sscanf +#undef SDL_sscanf +int +SDL_sscanf(const char *text, const char *fmt, ...) +{ + int rc; + va_list ap; + va_start(ap, fmt); + rc = vsscanf(text, fmt, ap); + va_end(ap); + return rc; +} +#else int SDL_sscanf(const char *text, const char *fmt, ...) { @@ -1136,7 +1252,10 @@ SDL_sscanf(const char *text, const char *fmt, ...) } #endif -#ifndef HAVE_SNPRINTF +/* just undef; the headers only define this to snprintf because of varargs. */ +#ifdef SDL_snprintf +#undef SDL_snprintf +#endif int SDL_snprintf(char *text, size_t maxlen, const char *fmt, ...) { @@ -1149,9 +1268,11 @@ SDL_snprintf(char *text, size_t maxlen, const char *fmt, ...) return retval; } -#endif -#ifndef HAVE_VSNPRINTF +#ifdef SDL_vsnprintf +#undef SDL_vsnprintf +int SDL_vsnprintf(char *text, size_t maxlen, const char *fmt, va_list ap) { return SDL_vsnprintf_inline(text, maxlen, fmt, ap); } +#else static size_t SDL_PrintLong(char *text, long value, int radix, size_t maxlen) { @@ -1414,4 +1535,5 @@ SDL_vsnprintf(char *text, size_t maxlen, const char *fmt, va_list ap) return (int)(text - textstart); } #endif + /* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/test/SDL_test_common.c b/src/test/SDL_test_common.c index 9f8bff8781..e050de7351 100644 --- a/src/test/SDL_test_common.c +++ b/src/test/SDL_test_common.c @@ -44,11 +44,7 @@ SDLTest_CommonCreateState(char **argv, Uint32 flags) /* Initialize some defaults */ state->argv = argv; state->flags = flags; -#ifdef __NDS__ - state->window_title = ""; -#else state->window_title = argv[0]; -#endif state->window_flags = 0; state->window_x = SDL_WINDOWPOS_UNDEFINED; state->window_y = SDL_WINDOWPOS_UNDEFINED; @@ -87,10 +83,6 @@ SDLTest_CommonArg(SDLTest_CommonState * state, int index) { char **argv = state->argv; -#ifdef __NDS__ - return 0; -#endif - if (SDL_strcasecmp(argv[index], "--video") == 0) { ++index; if (!argv[index]) { diff --git a/src/test/SDL_test_fuzzer.c b/src/test/SDL_test_fuzzer.c index 8857063555..89b669157c 100644 --- a/src/test/SDL_test_fuzzer.c +++ b/src/test/SDL_test_fuzzer.c @@ -251,7 +251,7 @@ SDLTest_GenerateUnsignedBoundaryValues(const Uint64 maxValue, Uint64 boundary1, if (index == 0) { /* There are no valid boundaries */ - SDL_Error(SDL_UNSUPPORTED); + SDL_Unsupported(); return 0; } @@ -379,7 +379,7 @@ SDLTest_GenerateSignedBoundaryValues(const Sint64 minValue, const Sint64 maxValu if (index == 0) { /* There are no valid boundaries */ - SDL_Error(SDL_UNSUPPORTED); + SDL_Unsupported(); return minValue; } diff --git a/src/thread/SDL_thread.c b/src/thread/SDL_thread.c index 99258a4cdb..e20f672ffb 100644 --- a/src/thread/SDL_thread.c +++ b/src/thread/SDL_thread.c @@ -85,7 +85,7 @@ SDL_AddThread(SDL_Thread * thread) return; } } - SDL_mutexP(thread_lock); + SDL_LockMutex(thread_lock); /* Expand the list of threads, if necessary */ #ifdef DEBUG_THREADS @@ -118,7 +118,7 @@ SDL_DelThread(SDL_Thread * thread) if (!thread_lock) { return; } - SDL_mutexP(thread_lock); + SDL_LockMutex(thread_lock); for (i = 0; i < SDL_numthreads; ++i) { if (thread == SDL_Threads[i]) { break; @@ -164,7 +164,7 @@ SDL_GetErrBuf(void) SDL_threadID this_thread; this_thread = SDL_ThreadID(); - SDL_mutexP(thread_lock); + SDL_LockMutex(thread_lock); for (i = 0; i < SDL_numthreads; ++i) { if (this_thread == SDL_Threads[i]->threadid) { errbuf = &SDL_Threads[i]->errbuf; diff --git a/src/thread/SDL_thread_c.h b/src/thread/SDL_thread_c.h index 7510a99397..4bb519eecb 100644 --- a/src/thread/SDL_thread_c.h +++ b/src/thread/SDL_thread_c.h @@ -34,8 +34,8 @@ #include "pthread/SDL_systhread_c.h" #elif SDL_THREAD_WINDOWS #include "windows/SDL_systhread_c.h" -#elif SDL_THREAD_NDS -#include "nds/SDL_systhread_c.h" +#elif SDL_THREAD_PSP +#include "psp/SDL_systhread_c.h" #elif SDL_THREAD_STDCPP #include "stdcpp/SDL_systhread_c.h" #else diff --git a/src/thread/beos/SDL_syssem.c b/src/thread/beos/SDL_syssem.c index 393e81d557..9661f90121 100644 --- a/src/thread/beos/SDL_syssem.c +++ b/src/thread/beos/SDL_syssem.c @@ -73,8 +73,7 @@ SDL_SemWaitTimeout(SDL_sem * sem, Uint32 timeout) int retval; if (!sem) { - SDL_SetError("Passed a NULL semaphore"); - return -1; + return SDL_SetError("Passed a NULL semaphore"); } tryagain: @@ -97,8 +96,7 @@ SDL_SemWaitTimeout(SDL_sem * sem, Uint32 timeout) retval = SDL_MUTEX_TIMEDOUT; break; default: - SDL_SetError("acquire_sem() failed"); - retval = -1; + retval = SDL_SetError("acquire_sem() failed"); break; } @@ -139,13 +137,11 @@ int SDL_SemPost(SDL_sem * sem) { if (!sem) { - SDL_SetError("Passed a NULL semaphore"); - return -1; + return SDL_SetError("Passed a NULL semaphore"); } if (release_sem(sem->id) != B_NO_ERROR) { - SDL_SetError("release_sem() failed"); - return -1; + return SDL_SetError("release_sem() failed"); } return 0; } diff --git a/src/thread/beos/SDL_systhread.c b/src/thread/beos/SDL_systhread.c index 4c61bd3029..11646f9749 100644 --- a/src/thread/beos/SDL_systhread.c +++ b/src/thread/beos/SDL_systhread.c @@ -77,8 +77,7 @@ SDL_SYS_CreateThread(SDL_Thread * thread, void *args) thread->handle = spawn_thread(RunThread, name, B_NORMAL_PRIORITY, args); if ((thread->handle == B_NO_MORE_THREADS) || (thread->handle == B_NO_MEMORY)) { - SDL_SetError("Not enough resources to create thread"); - return (-1); + return SDL_SetError("Not enough resources to create thread"); } resume_thread(thread->handle); return (0); diff --git a/src/thread/generic/SDL_syscond.c b/src/thread/generic/SDL_syscond.c index ca281521ef..f540cddb6d 100644 --- a/src/thread/generic/SDL_syscond.c +++ b/src/thread/generic/SDL_syscond.c @@ -82,8 +82,7 @@ int SDL_CondSignal(SDL_cond * cond) { if (!cond) { - SDL_SetError("Passed a NULL condition variable"); - return -1; + return SDL_SetError("Passed a NULL condition variable"); } /* If there are waiting threads not already signalled, then @@ -107,8 +106,7 @@ int SDL_CondBroadcast(SDL_cond * cond) { if (!cond) { - SDL_SetError("Passed a NULL condition variable"); - return -1; + return SDL_SetError("Passed a NULL condition variable"); } /* If there are waiting threads not already signalled, then @@ -164,8 +162,7 @@ SDL_CondWaitTimeout(SDL_cond * cond, SDL_mutex * mutex, Uint32 ms) int retval; if (!cond) { - SDL_SetError("Passed a NULL condition variable"); - return -1; + return SDL_SetError("Passed a NULL condition variable"); } /* Obtain the protection mutex, and increment the number of waiters. diff --git a/src/thread/generic/SDL_sysmutex.c b/src/thread/generic/SDL_sysmutex.c index a68f238c7c..3e3c1fea90 100644 --- a/src/thread/generic/SDL_sysmutex.c +++ b/src/thread/generic/SDL_sysmutex.c @@ -68,9 +68,9 @@ SDL_DestroyMutex(SDL_mutex * mutex) } } -/* Lock the semaphore */ +/* Lock the mutex */ int -SDL_mutexP(SDL_mutex * mutex) +SDL_LockMutex(SDL_mutex * mutex) { #if SDL_THREADS_DISABLED return 0; @@ -78,8 +78,7 @@ SDL_mutexP(SDL_mutex * mutex) SDL_threadID this_thread; if (mutex == NULL) { - SDL_SetError("Passed a NULL mutex"); - return -1; + return SDL_SetError("Passed a NULL mutex"); } this_thread = SDL_ThreadID(); @@ -99,6 +98,39 @@ SDL_mutexP(SDL_mutex * mutex) #endif /* SDL_THREADS_DISABLED */ } +/* try Lock the mutex */ +int +SDL_TryLockMutex(SDL_mutex * mutex) +{ +#if SDL_THREADS_DISABLED + return 0; +#else + int retval = 0; + SDL_threadID this_thread; + + if (mutex == NULL) { + return SDL_SetError("Passed a NULL mutex"); + } + + this_thread = SDL_ThreadID(); + if (mutex->owner == this_thread) { + ++mutex->recursive; + } else { + /* The order of operations is important. + We set the locking thread id after we obtain the lock + so unlocks from other threads will fail. + */ + retval = SDL_SemWait(mutex->sem); + if (retval == 0) { + mutex->owner = this_thread; + mutex->recursive = 0; + } + } + + return retval; +#endif /* SDL_THREADS_DISABLED */ +} + /* Unlock the mutex */ int SDL_mutexV(SDL_mutex * mutex) @@ -107,14 +139,12 @@ SDL_mutexV(SDL_mutex * mutex) return 0; #else if (mutex == NULL) { - SDL_SetError("Passed a NULL mutex"); - return -1; + return SDL_SetError("Passed a NULL mutex"); } /* If we don't own the mutex, we can't unlock it */ if (SDL_ThreadID() != mutex->owner) { - SDL_SetError("mutex not owned by this thread"); - return -1; + return SDL_SetError("mutex not owned by this thread"); } if (mutex->recursive) { diff --git a/src/thread/generic/SDL_syssem.c b/src/thread/generic/SDL_syssem.c index 365c7872c7..fc4e1fcc75 100644 --- a/src/thread/generic/SDL_syssem.c +++ b/src/thread/generic/SDL_syssem.c @@ -39,28 +39,24 @@ SDL_CreateSemaphore(Uint32 initial_value) void SDL_DestroySemaphore(SDL_sem * sem) { - return; } int SDL_SemTryWait(SDL_sem * sem) { - SDL_SetError("SDL not configured with thread support"); - return -1; + return SDL_SetError("SDL not configured with thread support"); } int SDL_SemWaitTimeout(SDL_sem * sem, Uint32 timeout) { - SDL_SetError("SDL not configured with thread support"); - return -1; + return SDL_SetError("SDL not configured with thread support"); } int SDL_SemWait(SDL_sem * sem) { - SDL_SetError("SDL not configured with thread support"); - return -1; + return SDL_SetError("SDL not configured with thread support"); } Uint32 @@ -72,8 +68,7 @@ SDL_SemValue(SDL_sem * sem) int SDL_SemPost(SDL_sem * sem) { - SDL_SetError("SDL not configured with thread support"); - return -1; + return SDL_SetError("SDL not configured with thread support"); } #else @@ -123,8 +118,8 @@ SDL_DestroySemaphore(SDL_sem * sem) } SDL_DestroyCond(sem->count_nonzero); if (sem->count_lock) { - SDL_mutexP(sem->count_lock); - SDL_mutexV(sem->count_lock); + SDL_LockMutex(sem->count_lock); + SDL_UnlockMutex(sem->count_lock); SDL_DestroyMutex(sem->count_lock); } SDL_free(sem); @@ -137,8 +132,7 @@ SDL_SemTryWait(SDL_sem * sem) int retval; if (!sem) { - SDL_SetError("Passed a NULL semaphore"); - return -1; + return SDL_SetError("Passed a NULL semaphore"); } retval = SDL_MUTEX_TIMEDOUT; @@ -158,8 +152,7 @@ SDL_SemWaitTimeout(SDL_sem * sem, Uint32 timeout) int retval; if (!sem) { - SDL_SetError("Passed a NULL semaphore"); - return -1; + return SDL_SetError("Passed a NULL semaphore"); } /* A timeout of 0 is an easy case */ @@ -207,8 +200,7 @@ int SDL_SemPost(SDL_sem * sem) { if (!sem) { - SDL_SetError("Passed a NULL semaphore"); - return -1; + return SDL_SetError("Passed a NULL semaphore"); } SDL_LockMutex(sem->count_lock); diff --git a/src/thread/generic/SDL_systhread.c b/src/thread/generic/SDL_systhread.c index d41643007e..deebc64fb8 100644 --- a/src/thread/generic/SDL_systhread.c +++ b/src/thread/generic/SDL_systhread.c @@ -28,8 +28,7 @@ int SDL_SYS_CreateThread(SDL_Thread * thread, void *args) { - SDL_SetError("Threads are not supported on this platform"); - return (-1); + return SDL_SetError("Threads are not supported on this platform"); } void diff --git a/src/thread/nds/SDL_syscond_c.h b/src/thread/nds/SDL_syscond_c.h deleted file mode 100644 index d842d59293..0000000000 --- a/src/thread/nds/SDL_syscond_c.h +++ /dev/null @@ -1,25 +0,0 @@ -/* - Simple DirectMedia Layer - Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org> - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. -*/ - -#ifdef SAVE_RCSID -static char rcsid = - "@(#) $Id: SDL_syscond_c.h,v 1.2 2001/04/26 16:50:18 hercules Exp $"; -#endif diff --git a/src/thread/nds/SDL_syssem.c b/src/thread/nds/SDL_syssem.c deleted file mode 100644 index 015f9c9d81..0000000000 --- a/src/thread/nds/SDL_syssem.c +++ /dev/null @@ -1,229 +0,0 @@ -/* - Simple DirectMedia Layer - Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org> - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. -*/ - -#ifdef SAVE_RCSID -static char rcsid = - "@(#) $Id: SDL_syssem.c,v 1.2 2001/04/26 16:50:18 hercules Exp $"; -#endif - -/* An implementation of semaphores using mutexes and condition variables */ - -#include <stdlib.h> - -#include "SDL_error.h" -#include "SDL_timer.h" -#include "SDL_thread.h" -#include "SDL_systhread_c.h" - - -#ifdef DISABLE_THREADS - -SDL_sem * -SDL_CreateSemaphore(Uint32 initial_value) -{ - SDL_SetError("SDL not configured with thread support"); - return (SDL_sem *) 0; -} - -void -SDL_DestroySemaphore(SDL_sem * sem) -{ - return; -} - -int -SDL_SemTryWait(SDL_sem * sem) -{ - SDL_SetError("SDL not configured with thread support"); - return -1; -} - -int -SDL_SemWaitTimeout(SDL_sem * sem, Uint32 timeout) -{ - SDL_SetError("SDL not configured with thread support"); - return -1; -} - -int -SDL_SemWait(SDL_sem * sem) -{ - SDL_SetError("SDL not configured with thread support"); - return -1; -} - -Uint32 -SDL_SemValue(SDL_sem * sem) -{ - return 0; -} - -int -SDL_SemPost(SDL_sem * sem) -{ - SDL_SetError("SDL not configured with thread support"); - return -1; -} - -#else - -struct SDL_semaphore -{ - Uint32 count; - Uint32 waiters_count; - SDL_mutex *count_lock; - SDL_cond *count_nonzero; -}; - -SDL_sem * -SDL_CreateSemaphore(Uint32 initial_value) -{ - SDL_sem *sem; - - sem = (SDL_sem *) malloc(sizeof(*sem)); - if (!sem) { - SDL_OutOfMemory(); - return (0); - } - sem->count = initial_value; - sem->waiters_count = 0; - - sem->count_lock = SDL_CreateMutex(); - sem->count_nonzero = SDL_CreateCond(); - if (!sem->count_lock || !sem->count_nonzero) { - SDL_DestroySemaphore(sem); - return (0); - } - - return (sem); -} - -/* WARNING: - You cannot call this function when another thread is using the semaphore. -*/ -void -SDL_DestroySemaphore(SDL_sem * sem) -{ - if (sem) { - sem->count = 0xFFFFFFFF; - while (sem->waiters_count > 0) { - SDL_CondSignal(sem->count_nonzero); - SDL_Delay(10); - } - SDL_DestroyCond(sem->count_nonzero); - SDL_mutexP(sem->count_lock); - SDL_mutexV(sem->count_lock); - SDL_DestroyMutex(sem->count_lock); - free(sem); - } -} - -int -SDL_SemTryWait(SDL_sem * sem) -{ - int retval; - - if (!sem) { - SDL_SetError("Passed a NULL semaphore"); - return -1; - } - - retval = SDL_MUTEX_TIMEDOUT; - SDL_LockMutex(sem->count_lock); - if (sem->count > 0) { - --sem->count; - retval = 0; - } - SDL_UnlockMutex(sem->count_lock); - - return retval; -} - -int -SDL_SemWaitTimeout(SDL_sem * sem, Uint32 timeout) -{ - int retval; - - if (!sem) { - SDL_SetError("Passed a NULL semaphore"); - return -1; - } - - /* A timeout of 0 is an easy case */ - if (timeout == 0) { - return SDL_SemTryWait(sem); - } - - SDL_LockMutex(sem->count_lock); - ++sem->waiters_count; - retval = 0; - while ((sem->count == 0) && (retval != SDL_MUTEX_TIMEDOUT)) { - retval = SDL_CondWaitTimeout(sem->count_nonzero, - sem->count_lock, timeout); - } - --sem->waiters_count; - --sem->count; - SDL_UnlockMutex(sem->count_lock); - - return retval; -} - -int -SDL_SemWait(SDL_sem * sem) -{ - return SDL_SemWaitTimeout(sem, SDL_MUTEX_MAXWAIT); -} - -Uint32 -SDL_SemValue(SDL_sem * sem) -{ - Uint32 value; - - value = 0; - if (sem) { - SDL_LockMutex(sem->count_lock); - value = sem->count; - SDL_UnlockMutex(sem->count_lock); - } - return value; -} - -int -SDL_SemPost(SDL_sem * sem) -{ - if (!sem) { - SDL_SetError("Passed a NULL semaphore"); - return -1; - } - - SDL_LockMutex(sem->count_lock); - if (sem->waiters_count > 0) { - SDL_CondSignal(sem->count_nonzero); - } - ++sem->count; - SDL_UnlockMutex(sem->count_lock); - - return 0; -} - -#endif /* DISABLE_THREADS */ - -/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/thread/nds/SDL_syscond.c b/src/thread/psp/SDL_syscond.c index 6f41eaa5ba..f540cddb6d 100644 --- a/src/thread/nds/SDL_syscond.c +++ b/src/thread/psp/SDL_syscond.c @@ -18,11 +18,7 @@ misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ - -#ifdef SAVE_RCSID -static char rcsid = - "@(#) $Id: SDL_syscond.c,v 1.2 2001/04/26 16:50:18 hercules Exp $"; -#endif +#include "SDL_config.h" /* An implementation of condition variables using semaphores and mutexes */ /* @@ -30,10 +26,6 @@ static char rcsid = implementation, written by Christopher Tate and Owen Smith. Thanks! */ -#include <stdio.h> -#include <stdlib.h> - -#include "SDL_error.h" #include "SDL_thread.h" struct SDL_cond @@ -51,7 +43,7 @@ SDL_CreateCond(void) { SDL_cond *cond; - cond = (SDL_cond *) malloc(sizeof(SDL_cond)); + cond = (SDL_cond *) SDL_malloc(sizeof(SDL_cond)); if (cond) { cond->lock = SDL_CreateMutex(); cond->wait_sem = SDL_CreateSemaphore(0); @@ -81,7 +73,7 @@ SDL_DestroyCond(SDL_cond * cond) if (cond->lock) { SDL_DestroyMutex(cond->lock); } - free(cond); + SDL_free(cond); } } @@ -90,8 +82,7 @@ int SDL_CondSignal(SDL_cond * cond) { if (!cond) { - SDL_SetError("Passed a NULL condition variable"); - return -1; + return SDL_SetError("Passed a NULL condition variable"); } /* If there are waiting threads not already signalled, then @@ -115,8 +106,7 @@ int SDL_CondBroadcast(SDL_cond * cond) { if (!cond) { - SDL_SetError("Passed a NULL condition variable"); - return -1; + return SDL_SetError("Passed a NULL condition variable"); } /* If there are waiting threads not already signalled, then @@ -152,18 +142,19 @@ SDL_CondBroadcast(SDL_cond * cond) Typical use: Thread A: - SDL_LockMutex(lock); - while ( ! condition ) { - SDL_CondWait(cond); - } - SDL_UnlockMutex(lock); + SDL_LockMutex(lock); + while ( ! condition ) { + SDL_CondWait(cond, lock); + } + SDL_UnlockMutex(lock); Thread B: - SDL_LockMutex(lock); - ... - condition = true; - ... - SDL_UnlockMutex(lock); + SDL_LockMutex(lock); + ... + condition = true; + ... + SDL_CondSignal(cond); + SDL_UnlockMutex(lock); */ int SDL_CondWaitTimeout(SDL_cond * cond, SDL_mutex * mutex, Uint32 ms) @@ -171,8 +162,7 @@ SDL_CondWaitTimeout(SDL_cond * cond, SDL_mutex * mutex, Uint32 ms) int retval; if (!cond) { - SDL_SetError("Passed a NULL condition variable"); - return -1; + return SDL_SetError("Passed a NULL condition variable"); } /* Obtain the protection mutex, and increment the number of waiters. diff --git a/src/thread/nds/SDL_sysmutex.c b/src/thread/psp/SDL_sysmutex.c index 6b662c99f1..6bb68a23d1 100644 --- a/src/thread/nds/SDL_sysmutex.c +++ b/src/thread/psp/SDL_sysmutex.c @@ -18,18 +18,10 @@ misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ - -#ifdef SAVE_RCSID -static char rcsid = - "@(#) $Id: SDL_sysmutex.c,v 1.2 2001/04/26 16:50:18 hercules Exp $"; -#endif +#include "SDL_config.h" /* An implementation of mutexes using semaphores */ -#include <stdio.h> -#include <stdlib.h> - -#include "SDL_error.h" #include "SDL_thread.h" #include "SDL_systhread_c.h" @@ -48,14 +40,14 @@ SDL_CreateMutex(void) SDL_mutex *mutex; /* Allocate mutex memory */ - mutex = (SDL_mutex *) malloc(sizeof(*mutex)); + mutex = (SDL_mutex *) SDL_malloc(sizeof(*mutex)); if (mutex) { /* Create the mutex semaphore, with initial value 1 */ mutex->sem = SDL_CreateSemaphore(1); mutex->recursive = 0; mutex->owner = 0; if (!mutex->sem) { - free(mutex); + SDL_free(mutex); mutex = NULL; } } else { @@ -72,7 +64,7 @@ SDL_DestroyMutex(SDL_mutex * mutex) if (mutex->sem) { SDL_DestroySemaphore(mutex->sem); } - free(mutex); + SDL_free(mutex); } } @@ -80,14 +72,13 @@ SDL_DestroyMutex(SDL_mutex * mutex) int SDL_mutexP(SDL_mutex * mutex) { -#ifdef DISABLE_THREADS +#if SDL_THREADS_DISABLED return 0; #else SDL_threadID this_thread; if (mutex == NULL) { - SDL_SetError("Passed a NULL mutex"); - return -1; + return SDL_SetError("Passed a NULL mutex"); } this_thread = SDL_ThreadID(); @@ -104,25 +95,23 @@ SDL_mutexP(SDL_mutex * mutex) } return 0; -#endif /* DISABLE_THREADS */ +#endif /* SDL_THREADS_DISABLED */ } /* Unlock the mutex */ int SDL_mutexV(SDL_mutex * mutex) { -#ifdef DISABLE_THREADS +#if SDL_THREADS_DISABLED return 0; #else if (mutex == NULL) { - SDL_SetError("Passed a NULL mutex"); - return -1; + return SDL_SetError("Passed a NULL mutex"); } /* If we don't own the mutex, we can't unlock it */ if (SDL_ThreadID() != mutex->owner) { - SDL_SetError("mutex not owned by this thread"); - return -1; + return SDL_SetError("mutex not owned by this thread"); } if (mutex->recursive) { @@ -137,7 +126,7 @@ SDL_mutexV(SDL_mutex * mutex) SDL_SemPost(mutex->sem); } return 0; -#endif /* DISABLE_THREADS */ +#endif /* SDL_THREADS_DISABLED */ } /* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/thread/nds/SDL_sysmutex_c.h b/src/thread/psp/SDL_sysmutex_c.h index d310519afb..8d6dbdc2be 100644 --- a/src/thread/nds/SDL_sysmutex_c.h +++ b/src/thread/psp/SDL_sysmutex_c.h @@ -18,8 +18,5 @@ misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ - -#ifdef SAVE_RCSID -static char rcsid = - "@(#) $Id: SDL_sysmutex_c.h,v 1.2 2001/04/26 16:50:18 hercules Exp $"; -#endif +#include "SDL_config.h" +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/thread/psp/SDL_syssem.c b/src/thread/psp/SDL_syssem.c new file mode 100644 index 0000000000..22ecc5f6b9 --- /dev/null +++ b/src/thread/psp/SDL_syssem.c @@ -0,0 +1,156 @@ +/* + Simple DirectMedia Layer + Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org> + + This software is provided 'as-is', without any express or implied + warranty. In no event will the authors be held liable for any damages + arising from the use of this software. + + Permission is granted to anyone to use this software for any purpose, + including commercial applications, and to alter it and redistribute it + freely, subject to the following restrictions: + + 1. The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original software. + 3. This notice may not be removed or altered from any source distribution. +*/ + +/* Semaphore functions for the PSP. */ + +#include <stdio.h> +#include <stdlib.h> + +#include "SDL_error.h" +#include "SDL_thread.h" + +#include <pspthreadman.h> +#include <pspkerror.h> + +struct SDL_semaphore { + SceUID semid; +}; + + +/* Create a semaphore */ +SDL_sem *SDL_CreateSemaphore(Uint32 initial_value) +{ + SDL_sem *sem; + + sem = (SDL_sem *) malloc(sizeof(*sem)); + if (sem != NULL) { + /* TODO: Figure out the limit on the maximum value. */ + sem->semid = sceKernelCreateSema("SDL sema", 0, initial_value, 255, NULL); + if (sem->semid < 0) { + SDL_SetError("Couldn't create semaphore"); + free(sem); + sem = NULL; + } + } else { + SDL_OutOfMemory(); + } + + return sem; +} + +/* Free the semaphore */ +void SDL_DestroySemaphore(SDL_sem *sem) +{ + if (sem != NULL) { + if (sem->semid > 0) { + sceKernelDeleteSema(sem->semid); + sem->semid = 0; + } + + free(sem); + } +} + +/* TODO: This routine is a bit overloaded. + * If the timeout is 0 then just poll the semaphore; if it's SDL_MUTEX_MAXWAIT, pass + * NULL to sceKernelWaitSema() so that it waits indefinitely; and if the timeout + * is specified, convert it to microseconds. */ +int SDL_SemWaitTimeout(SDL_sem *sem, Uint32 timeout) +{ + Uint32 *pTimeout; + unsigned int res; + + if (sem == NULL) { + SDL_SetError("Passed a NULL sem"); + return 0; + } + + if (timeout == 0) { + res = sceKernelPollSema(sem->semid, 1); + if (res < 0) { + return SDL_MUTEX_TIMEDOUT; + } + return 0; + } + + if (timeout == SDL_MUTEX_MAXWAIT) { + pTimeout = NULL; + } else { + timeout *= 1000; /* Convert to microseconds. */ + pTimeout = &timeout; + } + + res = sceKernelWaitSema(sem->semid, 1, pTimeout); + switch (res) { + case SCE_KERNEL_ERROR_OK: + return 0; + case SCE_KERNEL_ERROR_WAIT_TIMEOUT: + return SDL_MUTEX_TIMEDOUT; + default: + return SDL_SetError("WaitForSingleObject() failed"); + } +} + +int SDL_SemTryWait(SDL_sem *sem) +{ + return SDL_SemWaitTimeout(sem, 0); +} + +int SDL_SemWait(SDL_sem *sem) +{ + return SDL_SemWaitTimeout(sem, SDL_MUTEX_MAXWAIT); +} + +/* Returns the current count of the semaphore */ +Uint32 SDL_SemValue(SDL_sem *sem) +{ + SceKernelSemaInfo info; + + if (sem == NULL) { + SDL_SetError("Passed a NULL sem"); + return 0; + } + + if (sceKernelReferSemaStatus(sem->semid, &info) >= 0) { + return info.currentCount; + } + + return 0; +} + +int SDL_SemPost(SDL_sem *sem) +{ + int res; + + if (sem == NULL) { + return SDL_SetError("Passed a NULL sem"); + } + + res = sceKernelSignalSema(sem->semid, 1); + if (res < 0) { + return SDL_SetError("sceKernelSignalSema() failed"); + } + + return 0; +} + +/* vim: ts=4 sw=4 + */ diff --git a/src/thread/psp/SDL_systhread.c b/src/thread/psp/SDL_systhread.c new file mode 100644 index 0000000000..57b932084e --- /dev/null +++ b/src/thread/psp/SDL_systhread.c @@ -0,0 +1,102 @@ +/* + Simple DirectMedia Layer + Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org> + + This software is provided 'as-is', without any express or implied + warranty. In no event will the authors be held liable for any damages + arising from the use of this software. + + Permission is granted to anyone to use this software for any purpose, + including commercial applications, and to alter it and redistribute it + freely, subject to the following restrictions: + + 1. The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original software. + 3. This notice may not be removed or altered from any source distribution. +*/ + + +/* PSP thread management routines for SDL */ + +#include <stdio.h> +#include <stdlib.h> + +#include "SDL_error.h" +#include "SDL_thread.h" +#include "../SDL_systhread.h" +#include "../SDL_thread_c.h" +#include <pspkerneltypes.h> +#include <pspthreadman.h> + + +static int ThreadEntry(SceSize args, void *argp) +{ + SDL_RunThread(*(void **) argp); + return 0; +} + +int SDL_SYS_CreateThread(SDL_Thread *thread, void *args) +{ + SceKernelThreadInfo status; + int priority = 32; + + /* Set priority of new thread to the same as the current thread */ + status.size = sizeof(SceKernelThreadInfo); + if (sceKernelReferThreadStatus(sceKernelGetThreadId(), &status) == 0) { + priority = status.currentPriority; + } + + thread->handle = sceKernelCreateThread("SDL thread", ThreadEntry, + priority, 0x8000, + PSP_THREAD_ATTR_VFPU, NULL); + if (thread->handle < 0) { + return SDL_SetError("sceKernelCreateThread() failed"); + } + + sceKernelStartThread(thread->handle, 4, &args); + return 0; +} + +void SDL_SYS_SetupThread(const char *name) +{ + /* Do nothing. */ +} + +SDL_threadID SDL_ThreadID(void) +{ + return (SDL_threadID) sceKernelGetThreadId(); +} + +void SDL_SYS_WaitThread(SDL_Thread *thread) +{ + sceKernelWaitThreadEnd(thread->handle, NULL); + sceKernelDeleteThread(thread->handle); +} + +void SDL_SYS_KillThread(SDL_Thread *thread) +{ + sceKernelTerminateDeleteThread(thread->handle); +} + +int SDL_SYS_SetThreadPriority(SDL_ThreadPriority priority) +{ + int value; + + if (priority == SDL_THREAD_PRIORITY_LOW) { + value = 19; + } else if (priority == SDL_THREAD_PRIORITY_HIGH) { + value = -20; + } else { + value = 0; + } + + return sceKernelChangeThreadPriority(sceKernelGetThreadId(),value); + +} + +/* vim: ts=4 sw=4 + */ diff --git a/src/thread/nds/SDL_systhread_c.h b/src/thread/psp/SDL_systhread_c.h index 8aaf10d9d4..a806edec9b 100644 --- a/src/thread/nds/SDL_systhread_c.h +++ b/src/thread/psp/SDL_systhread_c.h @@ -19,9 +19,6 @@ 3. This notice may not be removed or altered from any source distribution. */ -/* Stub until we implement threads on this platform */ -typedef int SYS_ThreadHandle; +#include <pspkerneltypes.h> -#ifndef DISABLE_THREADS -#define DISABLE_THREADS -#endif +typedef SceUID SYS_ThreadHandle; diff --git a/src/thread/pthread/SDL_syscond.c b/src/thread/pthread/SDL_syscond.c index f07cdb20e4..1eb4f29f98 100644 --- a/src/thread/pthread/SDL_syscond.c +++ b/src/thread/pthread/SDL_syscond.c @@ -67,14 +67,12 @@ SDL_CondSignal(SDL_cond * cond) int retval; if (!cond) { - SDL_SetError("Passed a NULL condition variable"); - return -1; + return SDL_SetError("Passed a NULL condition variable"); } retval = 0; if (pthread_cond_signal(&cond->cond) != 0) { - SDL_SetError("pthread_cond_signal() failed"); - retval = -1; + return SDL_SetError("pthread_cond_signal() failed"); } return retval; } @@ -86,14 +84,12 @@ SDL_CondBroadcast(SDL_cond * cond) int retval; if (!cond) { - SDL_SetError("Passed a NULL condition variable"); - return -1; + return SDL_SetError("Passed a NULL condition variable"); } retval = 0; if (pthread_cond_broadcast(&cond->cond) != 0) { - SDL_SetError("pthread_cond_broadcast() failed"); - retval = -1; + return SDL_SetError("pthread_cond_broadcast() failed"); } return retval; } @@ -106,8 +102,7 @@ SDL_CondWaitTimeout(SDL_cond * cond, SDL_mutex * mutex, Uint32 ms) struct timespec abstime; if (!cond) { - SDL_SetError("Passed a NULL condition variable"); - return -1; + return SDL_SetError("Passed a NULL condition variable"); } gettimeofday(&delta, NULL); @@ -131,9 +126,7 @@ SDL_CondWaitTimeout(SDL_cond * cond, SDL_mutex * mutex, Uint32 ms) case 0: break; default: - SDL_SetError("pthread_cond_timedwait() failed"); - retval = -1; - break; + retval = SDL_SetError("pthread_cond_timedwait() failed"); } return retval; } @@ -144,19 +137,12 @@ SDL_CondWaitTimeout(SDL_cond * cond, SDL_mutex * mutex, Uint32 ms) int SDL_CondWait(SDL_cond * cond, SDL_mutex * mutex) { - int retval; - if (!cond) { - SDL_SetError("Passed a NULL condition variable"); - return -1; + return SDL_SetError("Passed a NULL condition variable"); + } else if (pthread_cond_wait(&cond->cond, &mutex->id) != 0) { + return SDL_SetError("pthread_cond_wait() failed"); } - - retval = 0; - if (pthread_cond_wait(&cond->cond, &mutex->id) != 0) { - SDL_SetError("pthread_cond_wait() failed"); - retval = -1; - } - return retval; + return 0; } /* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/thread/pthread/SDL_sysmutex.c b/src/thread/pthread/SDL_sysmutex.c index ce611c082f..bd238da367 100644 --- a/src/thread/pthread/SDL_sysmutex.c +++ b/src/thread/pthread/SDL_sysmutex.c @@ -22,6 +22,7 @@ #define _GNU_SOURCE #include <pthread.h> +#include <errno.h> #include "SDL_thread.h" @@ -78,19 +79,16 @@ SDL_DestroyMutex(SDL_mutex * mutex) /* Lock the mutex */ int -SDL_mutexP(SDL_mutex * mutex) +SDL_LockMutex(SDL_mutex * mutex) { - int retval; #if FAKE_RECURSIVE_MUTEX pthread_t this_thread; #endif if (mutex == NULL) { - SDL_SetError("Passed a NULL mutex"); - return -1; + return SDL_SetError("Passed a NULL mutex"); } - retval = 0; #if FAKE_RECURSIVE_MUTEX this_thread = pthread_self(); if (mutex->owner == this_thread) { @@ -104,31 +102,68 @@ SDL_mutexP(SDL_mutex * mutex) mutex->owner = this_thread; mutex->recursive = 0; } else { - SDL_SetError("pthread_mutex_lock() failed"); - retval = -1; + return SDL_SetError("pthread_mutex_lock() failed"); } } #else if (pthread_mutex_lock(&mutex->id) < 0) { - SDL_SetError("pthread_mutex_lock() failed"); - retval = -1; + return SDL_SetError("pthread_mutex_lock() failed"); } #endif - return retval; + return 0; } int -SDL_mutexV(SDL_mutex * mutex) +SDL_TryLockMutex(SDL_mutex * mutex) { int retval; +#if FAKE_RECURSIVE_MUTEX + pthread_t this_thread; +#endif if (mutex == NULL) { - SDL_SetError("Passed a NULL mutex"); - return -1; + return SDL_SetError("Passed a NULL mutex"); } retval = 0; #if FAKE_RECURSIVE_MUTEX + this_thread = pthread_self(); + if (mutex->owner == this_thread) { + ++mutex->recursive; + } else { + /* The order of operations is important. + We set the locking thread id after we obtain the lock + so unlocks from other threads will fail. + */ + if (pthread_mutex_lock(&mutex->id) == 0) { + mutex->owner = this_thread; + mutex->recursive = 0; + } else if (errno == EBUSY) { + retval = SDL_MUTEX_TIMEDOUT; + } else { + retval = SDL_SetError("pthread_mutex_trylock() failed"); + } + } +#else + if (pthread_mutex_trylock(&mutex->id) != 0) { + if (errno == EBUSY) { + retval = SDL_MUTEX_TIMEDOUT; + } else { + retval = SDL_SetError("pthread_mutex_trylock() failed"); + } + } +#endif + return retval; +} + +int +SDL_UnlockMutex(SDL_mutex * mutex) +{ + if (mutex == NULL) { + return SDL_SetError("Passed a NULL mutex"); + } + +#if FAKE_RECURSIVE_MUTEX /* We can only unlock the mutex if we own it */ if (pthread_self() == mutex->owner) { if (mutex->recursive) { @@ -143,18 +178,16 @@ SDL_mutexV(SDL_mutex * mutex) pthread_mutex_unlock(&mutex->id); } } else { - SDL_SetError("mutex not owned by this thread"); - retval = -1; + return SDL_SetError("mutex not owned by this thread"); } #else if (pthread_mutex_unlock(&mutex->id) < 0) { - SDL_SetError("pthread_mutex_unlock() failed"); - retval = -1; + return SDL_SetError("pthread_mutex_unlock() failed"); } #endif /* FAKE_RECURSIVE_MUTEX */ - return retval; + return 0; } /* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/thread/pthread/SDL_syssem.c b/src/thread/pthread/SDL_syssem.c index 5e461a7fc7..4acd6bfb52 100644 --- a/src/thread/pthread/SDL_syssem.c +++ b/src/thread/pthread/SDL_syssem.c @@ -72,8 +72,7 @@ SDL_SemTryWait(SDL_sem * sem) int retval; if (!sem) { - SDL_SetError("Passed a NULL semaphore"); - return -1; + return SDL_SetError("Passed a NULL semaphore"); } retval = SDL_MUTEX_TIMEDOUT; if (sem_trywait(&sem->sem) == 0) { @@ -88,13 +87,12 @@ SDL_SemWait(SDL_sem * sem) int retval; if (!sem) { - SDL_SetError("Passed a NULL semaphore"); - return -1; + return SDL_SetError("Passed a NULL semaphore"); } retval = sem_wait(&sem->sem); if (retval < 0) { - SDL_SetError("sem_wait() failed"); + retval = SDL_SetError("sem_wait() failed"); } return retval; } @@ -111,8 +109,7 @@ SDL_SemWaitTimeout(SDL_sem * sem, Uint32 timeout) #endif if (!sem) { - SDL_SetError("Passed a NULL semaphore"); - return -1; + return SDL_SetError("Passed a NULL semaphore"); } /* Try the easy cases first */ @@ -188,8 +185,7 @@ SDL_SemPost(SDL_sem * sem) int retval; if (!sem) { - SDL_SetError("Passed a NULL semaphore"); - return -1; + return SDL_SetError("Passed a NULL semaphore"); } retval = sem_post(&sem->sem); diff --git a/src/thread/pthread/SDL_systhread.c b/src/thread/pthread/SDL_systhread.c index e83e1f6c31..62436936ef 100644 --- a/src/thread/pthread/SDL_systhread.c +++ b/src/thread/pthread/SDL_systhread.c @@ -97,18 +97,16 @@ SDL_SYS_CreateThread(SDL_Thread * thread, void *args) /* Set the thread attributes */ if (pthread_attr_init(&type) != 0) { - SDL_SetError("Couldn't initialize pthread attributes"); - return (-1); + return SDL_SetError("Couldn't initialize pthread attributes"); } pthread_attr_setdetachstate(&type, PTHREAD_CREATE_JOINABLE); /* Create the thread and go! */ if (pthread_create(&thread->handle, &type, RunThread, args) != 0) { - SDL_SetError("Not enough resources to create thread"); - return (-1); + return SDL_SetError("Not enough resources to create thread"); } - return (0); + return 0; } void @@ -173,8 +171,7 @@ SDL_SYS_SetThreadPriority(SDL_ThreadPriority priority) /* Note that this fails if you're trying to set high priority and you don't have root permission. BUT DON'T RUN AS ROOT! */ - SDL_SetError("setpriority() failed"); - return -1; + return SDL_SetError("setpriority() failed"); } return 0; #else @@ -183,8 +180,7 @@ SDL_SYS_SetThreadPriority(SDL_ThreadPriority priority) pthread_t thread = pthread_self(); if (pthread_getschedparam(thread, &policy, &sched) < 0) { - SDL_SetError("pthread_getschedparam() failed"); - return -1; + return SDL_SetError("pthread_getschedparam() failed"); } if (priority == SDL_THREAD_PRIORITY_LOW) { sched.sched_priority = sched_get_priority_min(policy); @@ -196,8 +192,7 @@ SDL_SYS_SetThreadPriority(SDL_ThreadPriority priority) sched.sched_priority = (min_priority + (max_priority - min_priority) / 2); } if (pthread_setschedparam(thread, policy, &sched) < 0) { - SDL_SetError("pthread_setschedparam() failed"); - return -1; + return SDL_SetError("pthread_setschedparam() failed"); } return 0; #endif /* linux */ diff --git a/src/thread/windows/SDL_sysmutex.c b/src/thread/windows/SDL_sysmutex.c index 7d88c79a2c..60e9c6c87a 100644 --- a/src/thread/windows/SDL_sysmutex.c +++ b/src/thread/windows/SDL_sysmutex.c @@ -64,24 +64,37 @@ SDL_DestroyMutex(SDL_mutex * mutex) /* Lock the mutex */ int -SDL_mutexP(SDL_mutex * mutex) +SDL_LockMutex(SDL_mutex * mutex) { if (mutex == NULL) { - SDL_SetError("Passed a NULL mutex"); - return -1; + return SDL_SetError("Passed a NULL mutex"); } EnterCriticalSection(&mutex->cs); return (0); } +/* TryLock the mutex */ +int +SDL_TryLockMutex(SDL_mutex * mutex) +{ + int retval = 0; + if (mutex == NULL) { + return SDL_SetError("Passed a NULL mutex"); + } + + if (TryEnterCriticalSection(&mutex->cs) == 0) { + retval = SDL_MUTEX_TIMEDOUT; + } + return retval; +} + /* Unlock the mutex */ int -SDL_mutexV(SDL_mutex * mutex) +SDL_UnlockMutex(SDL_mutex * mutex) { if (mutex == NULL) { - SDL_SetError("Passed a NULL mutex"); - return -1; + return SDL_SetError("Passed a NULL mutex"); } LeaveCriticalSection(&mutex->cs); diff --git a/src/thread/windows/SDL_syssem.c b/src/thread/windows/SDL_syssem.c index 8c45e38273..8dc72bcb94 100644 --- a/src/thread/windows/SDL_syssem.c +++ b/src/thread/windows/SDL_syssem.c @@ -78,8 +78,7 @@ SDL_SemWaitTimeout(SDL_sem * sem, Uint32 timeout) DWORD dwMilliseconds; if (!sem) { - SDL_SetError("Passed a NULL sem"); - return -1; + return SDL_SetError("Passed a NULL sem"); } if (timeout == SDL_MUTEX_MAXWAIT) { @@ -96,8 +95,7 @@ SDL_SemWaitTimeout(SDL_sem * sem, Uint32 timeout) retval = SDL_MUTEX_TIMEDOUT; break; default: - SDL_SetError("WaitForSingleObject() failed"); - retval = -1; + retval = SDL_SetError("WaitForSingleObject() failed"); break; } return retval; @@ -130,8 +128,7 @@ int SDL_SemPost(SDL_sem * sem) { if (!sem) { - SDL_SetError("Passed a NULL sem"); - return -1; + return SDL_SetError("Passed a NULL sem"); } /* Increase the counter in the first place, because * after a successful release the semaphore may @@ -141,8 +138,7 @@ SDL_SemPost(SDL_sem * sem) InterlockedIncrement(&sem->count); if (ReleaseSemaphore(sem->id, 1, NULL) == FALSE) { InterlockedDecrement(&sem->count); /* restore */ - SDL_SetError("ReleaseSemaphore() failed"); - return -1; + return SDL_SetError("ReleaseSemaphore() failed"); } return 0; } diff --git a/src/thread/windows/SDL_systhread.c b/src/thread/windows/SDL_systhread.c index 1a898e1a38..6ae9cdb8f6 100644 --- a/src/thread/windows/SDL_systhread.c +++ b/src/thread/windows/SDL_systhread.c @@ -116,8 +116,7 @@ SDL_SYS_CreateThread(SDL_Thread * thread, void *args) pThreadStartParms pThreadParms = (pThreadStartParms) SDL_malloc(sizeof(tThreadStartParms)); if (!pThreadParms) { - SDL_OutOfMemory(); - return (-1); + return SDL_OutOfMemory(); } // Save the function which we will have to call to clear the RTL of calling app! pThreadParms->pfnCurrentEndThread = pfnEndThread; @@ -135,10 +134,9 @@ SDL_SYS_CreateThread(SDL_Thread * thread, void *args) pThreadParms, 0, &threadid); } if (thread->handle == NULL) { - SDL_SetError("Not enough resources to create thread"); - return (-1); + return SDL_SetError("Not enough resources to create thread"); } - return (0); + return 0; } #ifdef _MSC_VER @@ -198,8 +196,7 @@ SDL_SYS_SetThreadPriority(SDL_ThreadPriority priority) value = THREAD_PRIORITY_NORMAL; } if (!SetThreadPriority(GetCurrentThread(), value)) { - WIN_SetError("SetThreadPriority()"); - return -1; + return WIN_SetError("SetThreadPriority()"); } return 0; } diff --git a/src/timer/SDL_timer.c b/src/timer/SDL_timer.c index f30410aa18..60b3bdb124 100644 --- a/src/timer/SDL_timer.c +++ b/src/timer/SDL_timer.c @@ -334,10 +334,10 @@ SDL_AddTimer(Uint32 interval, SDL_TimerCallback callback, void *param) entry->timer = timer; entry->timerID = timer->timerID; - SDL_mutexP(data->timermap_lock); + SDL_LockMutex(data->timermap_lock); entry->next = data->timermap; data->timermap = entry; - SDL_mutexV(data->timermap_lock); + SDL_UnlockMutex(data->timermap_lock); /* Add the timer to the pending list for the timer thread */ SDL_AtomicLock(&data->lock); @@ -359,7 +359,7 @@ SDL_RemoveTimer(SDL_TimerID id) SDL_bool canceled = SDL_FALSE; /* Find the timer */ - SDL_mutexP(data->timermap_lock); + SDL_LockMutex(data->timermap_lock); prev = NULL; for (entry = data->timermap; entry; prev = entry, entry = entry->next) { if (entry->timerID == id) { @@ -371,7 +371,7 @@ SDL_RemoveTimer(SDL_TimerID id) break; } } - SDL_mutexV(data->timermap_lock); + SDL_UnlockMutex(data->timermap_lock); if (entry) { if (!entry->timer->canceled) { diff --git a/src/timer/nds/SDL_systimer.c b/src/timer/psp/SDL_systimer.c index a44695593e..cfb0aeb252 100644 --- a/src/timer/nds/SDL_systimer.c +++ b/src/timer/psp/SDL_systimer.c @@ -18,37 +18,31 @@ misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ -#include "SDL_config.h" - -#ifdef SDL_TIMER_NDS - -#include <nds.h> -#include <nds/timers.h> +#include "SDL_thread.h" #include "SDL_timer.h" +#include "SDL_error.h" +#include "../SDL_timer_c.h" +#include <stdlib.h> +#include <time.h> +#include <sys/time.h> +#include <pspthreadman.h> -/* Will wrap after 49 days. Shouldn't be an issue. */ -static volatile Uint32 timer_ticks; +static struct timeval start; -static void -NDS_TimerInterrupt(void) +void SDL_StartTicks(void) { - timer_ticks++; + gettimeofday(&start, NULL); } -void -SDL_StartTicks(void) +Uint32 SDL_GetTicks(void) { - timer_ticks = 0; - - /* Set timer 2 to fire every ms. */ - timerStart(2, ClockDivider_1024, TIMER_FREQ_1024(1000), NDS_TimerInterrupt); -} + struct timeval now; + Uint32 ticks; -Uint32 -SDL_GetTicks(void) -{ - return timer_ticks; + gettimeofday(&now, NULL); + ticks=(now.tv_sec-start.tv_sec)*1000+(now.tv_usec-start.tv_usec)/1000; + return(ticks); } Uint64 @@ -63,16 +57,13 @@ SDL_GetPerformanceFrequency(void) return 1000; } -void -SDL_Delay(Uint32 ms) +void SDL_Delay(Uint32 ms) { - Uint32 start = SDL_GetTicks(); - while (1) { - if ((SDL_GetTicks() - start) >= ms) - break; - } + const Uint32 max_delay = 0xffffffffUL / 1000; + if(ms > max_delay) + ms = max_delay; + sceKernelDelayThreadCB(ms * 1000); } -#endif /* SDL_TIMER_NDS */ - -/* vi: set ts=4 sw=4 expandtab: */ +/* vim: ts=4 sw=4 + */ diff --git a/src/video/SDL_RLEaccel.c b/src/video/SDL_RLEaccel.c index 07f5fd3c05..de61ccd47e 100644 --- a/src/video/SDL_RLEaccel.c +++ b/src/video/SDL_RLEaccel.c @@ -1087,8 +1087,7 @@ RLEAlphaSurface(SDL_Surface * surface) maxsize += sizeof(RLEDestFormat); rlebuf = (Uint8 *) SDL_malloc(maxsize); if (!rlebuf) { - SDL_OutOfMemory(); - return -1; + return SDL_OutOfMemory(); } { /* save the destination format so we can undo the encoding later */ @@ -1299,8 +1298,7 @@ RLEColorkeySurface(SDL_Surface * surface) rlebuf = (Uint8 *) SDL_malloc(maxsize); if (rlebuf == NULL) { - SDL_OutOfMemory(); - return (-1); + return SDL_OutOfMemory(); } /* Set up the conversion */ diff --git a/src/video/SDL_blit.c b/src/video/SDL_blit.c index ed546c5264..d7c258d4c5 100644 --- a/src/video/SDL_blit.c +++ b/src/video/SDL_blit.c @@ -270,11 +270,10 @@ SDL_CalculateBlit(SDL_Surface * surface) /* Make sure we have a blit function */ if (blit == NULL) { SDL_InvalidateMap(map); - SDL_SetError("Blit combination not supported"); - return (-1); + return SDL_SetError("Blit combination not supported"); } - return (0); + return 0; } /* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/video/SDL_blit_0.c b/src/video/SDL_blit_0.c index 54e6b8061f..12cf8607bf 100644 --- a/src/video/SDL_blit_0.c +++ b/src/video/SDL_blit_0.c @@ -443,11 +443,11 @@ BlitBtoNAlphaKey(SDL_BlitInfo * info) } static const SDL_BlitFunc bitmap_blit[] = { - NULL, BlitBto1, BlitBto2, BlitBto3, BlitBto4 + (SDL_BlitFunc) NULL, BlitBto1, BlitBto2, BlitBto3, BlitBto4 }; static const SDL_BlitFunc colorkey_blit[] = { - NULL, BlitBto1Key, BlitBto2Key, BlitBto3Key, BlitBto4Key + (SDL_BlitFunc) NULL, BlitBto1Key, BlitBto2Key, BlitBto3Key, BlitBto4Key }; SDL_BlitFunc @@ -457,7 +457,7 @@ SDL_CalculateBlit0(SDL_Surface * surface) if (surface->format->BitsPerPixel != 1) { /* We don't support sub 8-bit packed pixel modes */ - return NULL; + return (SDL_BlitFunc) NULL; } if (surface->map->dst->format->BitsPerPixel < 8) { which = 0; @@ -472,12 +472,12 @@ SDL_CalculateBlit0(SDL_Surface * surface) return colorkey_blit[which]; case SDL_COPY_MODULATE_ALPHA | SDL_COPY_BLEND: - return which >= 2 ? BlitBtoNAlpha : NULL; + return which >= 2 ? BlitBtoNAlpha : (SDL_BlitFunc) NULL; case SDL_COPY_COLORKEY | SDL_COPY_MODULATE_ALPHA | SDL_COPY_BLEND: - return which >= 2 ? BlitBtoNAlphaKey : NULL; + return which >= 2 ? BlitBtoNAlphaKey : (SDL_BlitFunc) NULL; } - return NULL; + return (SDL_BlitFunc) NULL; } /* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/video/SDL_blit_1.c b/src/video/SDL_blit_1.c index 0956604897..514edab016 100644 --- a/src/video/SDL_blit_1.c +++ b/src/video/SDL_blit_1.c @@ -511,11 +511,11 @@ Blit1toNAlphaKey(SDL_BlitInfo * info) } static const SDL_BlitFunc one_blit[] = { - NULL, Blit1to1, Blit1to2, Blit1to3, Blit1to4 + (SDL_BlitFunc) NULL, Blit1to1, Blit1to2, Blit1to3, Blit1to4 }; static const SDL_BlitFunc one_blitkey[] = { - NULL, Blit1to1Key, Blit1to2Key, Blit1to3Key, Blit1to4Key + (SDL_BlitFunc) NULL, Blit1to1Key, Blit1to2Key, Blit1to3Key, Blit1to4Key }; SDL_BlitFunc @@ -541,12 +541,12 @@ SDL_CalculateBlit1(SDL_Surface * surface) /* Supporting 8bpp->8bpp alpha is doable but requires lots of tables which consume space and takes time to precompute, so is better left to the user */ - return which >= 2 ? Blit1toNAlpha : NULL; + return which >= 2 ? Blit1toNAlpha : (SDL_BlitFunc) NULL; case SDL_COPY_COLORKEY | SDL_COPY_MODULATE_ALPHA | SDL_COPY_BLEND: - return which >= 2 ? Blit1toNAlphaKey : NULL; + return which >= 2 ? Blit1toNAlphaKey : (SDL_BlitFunc) NULL; } - return NULL; + return (SDL_BlitFunc) NULL; } /* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/video/SDL_bmp.c b/src/video/SDL_bmp.c index bb69af6cdc..a6341f4c8e 100644 --- a/src/video/SDL_bmp.c +++ b/src/video/SDL_bmp.c @@ -252,14 +252,14 @@ SDL_LoadBMP_RW(SDL_RWops * src, int freesrc) SDL_RWread(src, &palette->colors[i].b, 1, 1); SDL_RWread(src, &palette->colors[i].g, 1, 1); SDL_RWread(src, &palette->colors[i].r, 1, 1); - palette->colors[i].unused = SDL_ALPHA_OPAQUE; + palette->colors[i].a = SDL_ALPHA_OPAQUE; } } else { for (i = 0; i < (int) biClrUsed; ++i) { SDL_RWread(src, &palette->colors[i].b, 1, 1); SDL_RWread(src, &palette->colors[i].g, 1, 1); SDL_RWread(src, &palette->colors[i].r, 1, 1); - SDL_RWread(src, &palette->colors[i].unused, 1, 1); + SDL_RWread(src, &palette->colors[i].a, 1, 1); } } } @@ -510,7 +510,7 @@ SDL_SaveBMP_RW(SDL_Surface * saveme, SDL_RWops * dst, int freedst) SDL_RWwrite(dst, &colors[i].b, 1, 1); SDL_RWwrite(dst, &colors[i].g, 1, 1); SDL_RWwrite(dst, &colors[i].r, 1, 1); - SDL_RWwrite(dst, &colors[i].unused, 1, 1); + SDL_RWwrite(dst, &colors[i].a, 1, 1); } } diff --git a/src/video/SDL_fillrect.c b/src/video/SDL_fillrect.c index 91f3feccf8..a99371e056 100644 --- a/src/video/SDL_fillrect.c +++ b/src/video/SDL_fillrect.c @@ -315,14 +315,12 @@ SDL_FillRect(SDL_Surface * dst, const SDL_Rect * rect, Uint32 color) Uint8 *pixels; if (!dst) { - SDL_SetError("Passed NULL destination surface"); - return -1; + return SDL_SetError("Passed NULL destination surface"); } /* This function doesn't work on surfaces < 8 bpp */ if (dst->format->BitsPerPixel < 8) { - SDL_SetError("SDL_FillRect(): Unsupported surface format"); - return -1; + return SDL_SetError("SDL_FillRect(): Unsupported surface format"); } /* If 'rect' == NULL, then fill the whole surface */ @@ -338,8 +336,7 @@ SDL_FillRect(SDL_Surface * dst, const SDL_Rect * rect, Uint32 color) /* Perform software fill */ if (!dst->pixels) { - SDL_SetError("SDL_FillRect(): You must lock the surface"); - return (-1); + return SDL_SetError("SDL_FillRect(): You must lock the surface"); } pixels = (Uint8 *) dst->pixels + rect->y * dst->pitch + @@ -423,8 +420,7 @@ SDL_FillRects(SDL_Surface * dst, const SDL_Rect * rects, int count, int status = 0; if (!rects) { - SDL_SetError("SDL_FillRects() passed NULL rects"); - return -1; + return SDL_SetError("SDL_FillRects() passed NULL rects"); } for (i = 0; i < count; ++i) { diff --git a/src/video/SDL_pixels.c b/src/video/SDL_pixels.c index 47843b034a..84a75b8eba 100644 --- a/src/video/SDL_pixels.c +++ b/src/video/SDL_pixels.c @@ -638,13 +638,11 @@ int SDL_SetPixelFormatPalette(SDL_PixelFormat * format, SDL_Palette *palette) { if (!format) { - SDL_SetError("SDL_SetPixelFormatPalette() passed NULL format"); - return -1; + return SDL_SetError("SDL_SetPixelFormatPalette() passed NULL format"); } if (palette && palette->ncolors != (1 << format->BitsPerPixel)) { - SDL_SetError("SDL_SetPixelFormatPalette() passed a palette that doesn't match the format"); - return -1; + return SDL_SetError("SDL_SetPixelFormatPalette() passed a palette that doesn't match the format"); } if (format->palette == palette) { @@ -730,7 +728,7 @@ SDL_DitherColors(SDL_Color * colors, int bpp) b |= b << 2; b |= b << 4; colors[i].b = b; - colors[i].unused = SDL_ALPHA_OPAQUE; + colors[i].a = SDL_ALPHA_OPAQUE; } } @@ -762,12 +760,12 @@ SDL_CalculatePitch(SDL_Surface * surface) * Match an RGB value to a particular palette index */ Uint8 -SDL_FindColor(SDL_Palette * pal, Uint8 r, Uint8 g, Uint8 b) +SDL_FindColor(SDL_Palette * pal, Uint8 r, Uint8 g, Uint8 b, Uint8 a) { /* Do colorspace distance matching */ unsigned int smallest; unsigned int distance; - int rd, gd, bd; + int rd, gd, bd, ad; int i; Uint8 pixel = 0; @@ -776,7 +774,8 @@ SDL_FindColor(SDL_Palette * pal, Uint8 r, Uint8 g, Uint8 b) rd = pal->colors[i].r - r; gd = pal->colors[i].g - g; bd = pal->colors[i].b - b; - distance = (rd * rd) + (gd * gd) + (bd * bd); + ad = pal->colors[i].a - a; + distance = (rd * rd) + (gd * gd) + (bd * bd) + (ad * ad); if (distance < smallest) { pixel = i; if (distance == 0) { /* Perfect match! */ @@ -797,7 +796,7 @@ SDL_MapRGB(const SDL_PixelFormat * format, Uint8 r, Uint8 g, Uint8 b) | (g >> format->Gloss) << format->Gshift | (b >> format->Bloss) << format->Bshift | format->Amask; } else { - return SDL_FindColor(format->palette, r, g, b); + return SDL_FindColor(format->palette, r, g, b, SDL_ALPHA_OPAQUE); } } @@ -812,7 +811,7 @@ SDL_MapRGBA(const SDL_PixelFormat * format, Uint8 r, Uint8 g, Uint8 b, | (b >> format->Bloss) << format->Bshift | ((a >> format->Aloss) << format->Ashift & format->Amask); } else { - return SDL_FindColor(format->palette, r, g, b); + return SDL_FindColor(format->palette, r, g, b, a); } } @@ -858,7 +857,7 @@ SDL_GetRGBA(Uint32 pixel, const SDL_PixelFormat * format, *r = format->palette->colors[pixel].r; *g = format->palette->colors[pixel].g; *b = format->palette->colors[pixel].b; - *a = SDL_ALPHA_OPAQUE; + *a = format->palette->colors[pixel].a; } else { *r = *g = *b = *a = 0; } @@ -894,7 +893,7 @@ Map1to1(SDL_Palette * src, SDL_Palette * dst, int *identical) for (i = 0; i < src->ncolors; ++i) { map[i] = SDL_FindColor(dst, src->colors[i].r, src->colors[i].g, - src->colors[i].b); + src->colors[i].b, src->colors[i].a); } return (map); } @@ -918,10 +917,10 @@ Map1toN(SDL_PixelFormat * src, Uint8 Rmod, Uint8 Gmod, Uint8 Bmod, Uint8 Amod, /* We memory copy to the pixel map so the endianness is preserved */ for (i = 0; i < pal->ncolors; ++i) { - Uint8 A = Amod; Uint8 R = (Uint8) ((pal->colors[i].r * Rmod) / 255); Uint8 G = (Uint8) ((pal->colors[i].g * Gmod) / 255); Uint8 B = (Uint8) ((pal->colors[i].b * Bmod) / 255); + Uint8 A = (Uint8) ((pal->colors[i].a * Amod) / 255); ASSEMBLE_RGBA(&map[i * bpp], dst->BytesPerPixel, dst, R, G, B, A); } return (map); diff --git a/src/video/SDL_pixels_c.h b/src/video/SDL_pixels_c.h index 46b086c45d..0b5d9a0064 100644 --- a/src/video/SDL_pixels_c.h +++ b/src/video/SDL_pixels_c.h @@ -36,6 +36,6 @@ extern void SDL_FreeBlitMap(SDL_BlitMap * map); /* Miscellaneous functions */ extern int SDL_CalculatePitch(SDL_Surface * surface); extern void SDL_DitherColors(SDL_Color * colors, int bpp); -extern Uint8 SDL_FindColor(SDL_Palette * pal, Uint8 r, Uint8 g, Uint8 b); +extern Uint8 SDL_FindColor(SDL_Palette * pal, Uint8 r, Uint8 g, Uint8 b, Uint8 a); /* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/video/SDL_rect.c b/src/video/SDL_rect.c index e573812367..23894dc3d4 100644 --- a/src/video/SDL_rect.c +++ b/src/video/SDL_rect.c @@ -412,7 +412,7 @@ SDL_IntersectRectAndLine(const SDL_Rect * rect, int *X1, int *Y1, int *X2, SDL_bool SDL_GetSpanEnclosingRect(int width, int height, - int numrects, SDL_Rect * rects, SDL_Rect *span) + int numrects, const SDL_Rect * rects, SDL_Rect *span) { int i; int span_y1, span_y2; diff --git a/src/video/SDL_rect_c.h b/src/video/SDL_rect_c.h index b360a54c26..a7fd49cf8e 100644 --- a/src/video/SDL_rect_c.h +++ b/src/video/SDL_rect_c.h @@ -20,6 +20,6 @@ */ #include "SDL_config.h" -extern SDL_bool SDL_GetSpanEnclosingRect(int width, int height, int numrects, SDL_Rect * rects, SDL_Rect *span); +extern SDL_bool SDL_GetSpanEnclosingRect(int width, int height, int numrects, const SDL_Rect * rects, SDL_Rect *span); /* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/video/SDL_stretch.c b/src/video/SDL_stretch.c index 9d6588af92..e976d10f08 100644 --- a/src/video/SDL_stretch.c +++ b/src/video/SDL_stretch.c @@ -102,14 +102,12 @@ generate_rowbytes(int src_w, int dst_w, int bpp) store = STORE_WORD; break; default: - SDL_SetError("ASM stretch of %d bytes isn't supported\n", bpp); - return (-1); + return SDL_SetError("ASM stretch of %d bytes isn't supported\n", bpp); } #ifdef HAVE_MPROTECT /* Make the code writeable */ if (mprotect(copy_row, sizeof(copy_row), PROT_READ | PROT_WRITE) < 0) { - SDL_SetError("Couldn't make copy buffer writeable"); - return (-1); + return SDL_SetError("Couldn't make copy buffer writeable"); } #endif pos = 0x10000; @@ -141,8 +139,7 @@ generate_rowbytes(int src_w, int dst_w, int bpp) #ifdef HAVE_MPROTECT /* Make the code executable but not writeable */ if (mprotect(copy_row, sizeof(copy_row), PROT_READ | PROT_EXEC) < 0) { - SDL_SetError("Couldn't make copy buffer executable"); - return (-1); + return SDL_SetError("Couldn't make copy buffer executable"); } #endif last.status = 0; @@ -224,8 +221,7 @@ SDL_SoftStretch(SDL_Surface * src, const SDL_Rect * srcrect, const int bpp = dst->format->BytesPerPixel; if (src->format->BitsPerPixel != dst->format->BitsPerPixel) { - SDL_SetError("Only works with same format surfaces"); - return (-1); + return SDL_SetError("Only works with same format surfaces"); } /* Verify the blit rectangles */ @@ -233,8 +229,7 @@ SDL_SoftStretch(SDL_Surface * src, const SDL_Rect * srcrect, if ((srcrect->x < 0) || (srcrect->y < 0) || ((srcrect->x + srcrect->w) > src->w) || ((srcrect->y + srcrect->h) > src->h)) { - SDL_SetError("Invalid source blit rectangle"); - return (-1); + return SDL_SetError("Invalid source blit rectangle"); } } else { full_src.x = 0; @@ -247,8 +242,7 @@ SDL_SoftStretch(SDL_Surface * src, const SDL_Rect * srcrect, if ((dstrect->x < 0) || (dstrect->y < 0) || ((dstrect->x + dstrect->w) > dst->w) || ((dstrect->y + dstrect->h) > dst->h)) { - SDL_SetError("Invalid destination blit rectangle"); - return (-1); + return SDL_SetError("Invalid destination blit rectangle"); } } else { full_dst.x = 0; @@ -262,8 +256,7 @@ SDL_SoftStretch(SDL_Surface * src, const SDL_Rect * srcrect, dst_locked = 0; if (SDL_MUSTLOCK(dst)) { if (SDL_LockSurface(dst) < 0) { - SDL_SetError("Unable to lock destination surface"); - return (-1); + return SDL_SetError("Unable to lock destination surface"); } dst_locked = 1; } @@ -274,8 +267,7 @@ SDL_SoftStretch(SDL_Surface * src, const SDL_Rect * srcrect, if (dst_locked) { SDL_UnlockSurface(dst); } - SDL_SetError("Unable to lock source surface"); - return (-1); + return SDL_SetError("Unable to lock source surface"); } src_locked = 1; } diff --git a/src/video/SDL_surface.c b/src/video/SDL_surface.c index c866f47532..94ce6eacc4 100644 --- a/src/video/SDL_surface.c +++ b/src/video/SDL_surface.c @@ -143,8 +143,7 @@ int SDL_SetSurfacePalette(SDL_Surface * surface, SDL_Palette * palette) { if (!surface) { - SDL_SetError("SDL_SetSurfacePalette() passed a NULL surface"); - return -1; + return SDL_SetError("SDL_SetSurfacePalette() passed a NULL surface"); } return SDL_SetPixelFormatPalette(surface->format, palette); } @@ -187,7 +186,21 @@ SDL_SetColorKey(SDL_Surface * surface, int flag, Uint32 key) if (flag) { surface->map->info.flags |= SDL_COPY_COLORKEY; surface->map->info.colorkey = key; + if (surface->format->palette) { + surface->format->palette->colors[surface->map->info.colorkey].a = SDL_ALPHA_TRANSPARENT; + ++surface->format->palette->version; + if (!surface->format->palette->version) { + surface->format->palette->version = 1; + } + } } else { + if (surface->format->palette) { + surface->format->palette->colors[surface->map->info.colorkey].a = SDL_ALPHA_OPAQUE; + ++surface->format->palette->version; + if (!surface->format->palette->version) { + surface->format->palette->version = 1; + } + } surface->map->info.flags &= ~SDL_COPY_COLORKEY; } if (surface->map->info.flags != flags) { @@ -388,8 +401,7 @@ SDL_SetSurfaceBlendMode(SDL_Surface * surface, SDL_BlendMode blendMode) surface->map->info.flags |= SDL_COPY_MOD; break; default: - SDL_Unsupported(); - status = -1; + status = SDL_Unsupported(); break; } @@ -504,12 +516,10 @@ SDL_UpperBlit(SDL_Surface * src, const SDL_Rect * srcrect, /* Make sure the surfaces aren't locked */ if (!src || !dst) { - SDL_SetError("SDL_UpperBlit: passed a NULL surface"); - return (-1); + return SDL_SetError("SDL_UpperBlit: passed a NULL surface"); } if (src->locked || dst->locked) { - SDL_SetError("Surfaces must not be locked during blit"); - return (-1); + return SDL_SetError("Surfaces must not be locked during blit"); } /* If the destination rectangle is NULL, use the entire dest surface */ @@ -596,12 +606,10 @@ SDL_UpperBlitScaled(SDL_Surface * src, const SDL_Rect * srcrect, /* Make sure the surfaces aren't locked */ if (!src || !dst) { - SDL_SetError("SDL_UpperBlitScaled: passed a NULL surface"); - return (-1); + return SDL_SetError("SDL_UpperBlitScaled: passed a NULL surface"); } if (src->locked || dst->locked) { - SDL_SetError("Surfaces must not be locked during blit"); - return (-1); + return SDL_SetError("Surfaces must not be locked during blit"); } /* If the destination rectangle is NULL, use the entire dest surface */ @@ -843,14 +851,35 @@ SDL_ConvertSurface(SDL_Surface * surface, SDL_PixelFormat * format, SDL_COPY_RLE_ALPHAKEY)); surface->map->info.flags = copy_flags; if (copy_flags & SDL_COPY_COLORKEY) { - Uint8 keyR, keyG, keyB, keyA; + SDL_bool set_colorkey_by_color = SDL_FALSE; + + if (surface->format->palette) { + if (format->palette && + surface->format->palette->ncolors <= format->palette->ncolors && + (SDL_memcmp(surface->format->palette->colors, format->palette->colors, + surface->format->palette->ncolors * sizeof(SDL_Color)) == 0)) { + /* The palette is identical, just set the same colorkey */ + SDL_SetColorKey(convert, 1, surface->map->info.colorkey); + } else if (format->Amask) { + /* The alpha was set in the destination from the palette */ + } else { + set_colorkey_by_color = SDL_TRUE; + } + } else { + set_colorkey_by_color = SDL_TRUE; + } + + if (set_colorkey_by_color) { + /* Set the colorkey by color, which needs to be unique */ + Uint8 keyR, keyG, keyB, keyA; - SDL_GetRGBA(surface->map->info.colorkey, surface->format, &keyR, - &keyG, &keyB, &keyA); - SDL_SetColorKey(convert, 1, - SDL_MapRGBA(convert->format, keyR, keyG, keyB, keyA)); - /* This is needed when converting for 3D texture upload */ - SDL_ConvertColorkeyToAlpha(convert); + SDL_GetRGBA(surface->map->info.colorkey, surface->format, &keyR, + &keyG, &keyB, &keyA); + SDL_SetColorKey(convert, 1, + SDL_MapRGBA(convert->format, keyR, keyG, keyB, keyA)); + /* This is needed when converting for 3D texture upload */ + SDL_ConvertColorkeyToAlpha(convert); + } } SDL_SetClipRect(convert, &surface->clip_rect); @@ -935,6 +964,14 @@ int SDL_ConvertPixels(int width, int height, SDL_Rect rect; void *nonconst_src = (void *) src; + /* Check to make sure we are bliting somewhere, so we don't crash */ + if (!dst) { + return SDL_InvalidParamError("dst"); + } + if (!dst_pitch) { + return SDL_InvalidParamError("dst_pitch"); + } + /* Fast path for same format copy */ if (src_format == dst_format) { int bpp; @@ -949,8 +986,7 @@ int SDL_ConvertPixels(int width, int height, bpp = 2; break; default: - SDL_SetError("Unknown FOURCC pixel format"); - return -1; + return SDL_SetError("Unknown FOURCC pixel format"); } } else { bpp = SDL_BYTESPERPIXEL(src_format); diff --git a/src/video/SDL_sysvideo.h b/src/video/SDL_sysvideo.h index 373ae4879d..eae165d3b1 100644 --- a/src/video/SDL_sysvideo.h +++ b/src/video/SDL_sysvideo.h @@ -199,7 +199,7 @@ struct SDL_VideoDevice void (*SetWindowGrab) (_THIS, SDL_Window * window, SDL_bool grabbed); void (*DestroyWindow) (_THIS, SDL_Window * window); int (*CreateWindowFramebuffer) (_THIS, SDL_Window * window, Uint32 * format, void ** pixels, int *pitch); - int (*UpdateWindowFramebuffer) (_THIS, SDL_Window * window, SDL_Rect * rects, int numrects); + int (*UpdateWindowFramebuffer) (_THIS, SDL_Window * window, const SDL_Rect * rects, int numrects); void (*DestroyWindowFramebuffer) (_THIS, SDL_Window * window); /* * * */ @@ -344,15 +344,15 @@ extern VideoBootStrap BWINDOW_bootstrap; #if SDL_VIDEO_DRIVER_PANDORA extern VideoBootStrap PND_bootstrap; #endif -#if SDL_VIDEO_DRIVER_NDS -extern VideoBootStrap NDS_bootstrap; -#endif #if SDL_VIDEO_DRIVER_UIKIT extern VideoBootStrap UIKIT_bootstrap; #endif #if SDL_VIDEO_DRIVER_ANDROID extern VideoBootStrap Android_bootstrap; #endif +#if SDL_VIDEO_DRIVER_PSP +extern VideoBootStrap PSP_bootstrap; +#endif #if SDL_VIDEO_DRIVER_DUMMY extern VideoBootStrap DUMMY_bootstrap; #endif diff --git a/src/video/SDL_video.c b/src/video/SDL_video.c index cb98329a91..15d49794fb 100644 --- a/src/video/SDL_video.c +++ b/src/video/SDL_video.c @@ -72,15 +72,15 @@ static VideoBootStrap *bootstrap[] = { #if SDL_VIDEO_DRIVER_PANDORA &PND_bootstrap, #endif -#if SDL_VIDEO_DRIVER_NDS - &NDS_bootstrap, -#endif #if SDL_VIDEO_DRIVER_UIKIT &UIKIT_bootstrap, #endif #if SDL_VIDEO_DRIVER_ANDROID &Android_bootstrap, #endif +#if SDL_VIDEO_DRIVER_PSP + &PSP_bootstrap, +#endif #if SDL_VIDEO_DRIVER_DUMMY &DUMMY_bootstrap, #endif @@ -245,16 +245,14 @@ SDL_CreateWindowTexture(_THIS, SDL_Window * window, Uint32 * format, void ** pix } } if (!renderer) { - SDL_SetError("No hardware accelerated renderers available"); - return -1; + return SDL_SetError("No hardware accelerated renderers available"); } /* Create the data after we successfully create the renderer (bug #1116) */ data = (SDL_WindowTextureData *)SDL_calloc(1, sizeof(*data)); if (!data) { SDL_DestroyRenderer(renderer); - SDL_OutOfMemory(); - return -1; + return SDL_OutOfMemory(); } SDL_SetWindowData(window, SDL_WINDOWTEXTUREDATA, data); @@ -297,8 +295,7 @@ SDL_CreateWindowTexture(_THIS, SDL_Window * window, Uint32 * format, void ** pix data->pitch = (((window->w * data->bytes_per_pixel) + 3) & ~3); data->pixels = SDL_malloc(window->h * data->pitch); if (!data->pixels) { - SDL_OutOfMemory(); - return -1; + return SDL_OutOfMemory(); } *pixels = data->pixels; @@ -311,7 +308,7 @@ SDL_CreateWindowTexture(_THIS, SDL_Window * window, Uint32 * format, void ** pix } static int -SDL_UpdateWindowTexture(_THIS, SDL_Window * window, SDL_Rect * rects, int numrects) +SDL_UpdateWindowTexture(_THIS, SDL_Window * window, const SDL_Rect * rects, int numrects) { SDL_WindowTextureData *data; SDL_Rect rect; @@ -319,8 +316,7 @@ SDL_UpdateWindowTexture(_THIS, SDL_Window * window, SDL_Rect * rects, int numrec data = SDL_GetWindowData(window, SDL_WINDOWTEXTUREDATA); if (!data || !data->texture) { - SDL_SetError("No window texture data"); - return -1; + return SDL_SetError("No window texture data"); } /* Update a single rect that contains subrects for best DMA performance */ @@ -387,10 +383,10 @@ cmpmodes(const void *A, const void *B) return 0; } -static void +static int SDL_UninitializedVideo() { - SDL_SetError("Video subsystem has not been initialized"); + return SDL_SetError("Video subsystem has not been initialized"); } int @@ -457,11 +453,9 @@ SDL_VideoInit(const char *driver_name) } if (video == NULL) { if (driver_name) { - SDL_SetError("%s not available", driver_name); - } else { - SDL_SetError("No available video device"); + return SDL_SetError("%s not available", driver_name); } - return -1; + return SDL_SetError("No available video device"); } _this = video; _this->name = bootstrap[i]->name; @@ -513,9 +507,8 @@ SDL_VideoInit(const char *driver_name) /* Make sure some displays were added */ if (_this->num_displays == 0) { - SDL_SetError("The video driver did not add any displays"); SDL_VideoQuit(); - return (-1); + return SDL_SetError("The video driver did not add any displays"); } /* Add the renderer framebuffer emulation if desired */ @@ -724,9 +717,8 @@ SDL_GetDisplayMode(int displayIndex, int index, SDL_DisplayMode * mode) display = &_this->displays[displayIndex]; if (index < 0 || index >= SDL_GetNumDisplayModesForDisplay(display)) { - SDL_SetError("index must be in the range of 0 - %d", - SDL_GetNumDisplayModesForDisplay(display) - 1); - return -1; + return SDL_SetError("index must be in the range of 0 - %d", + SDL_GetNumDisplayModesForDisplay(display) - 1); } if (mode) { *mode = display->display_modes[index]; @@ -907,9 +899,8 @@ SDL_SetDisplayModeForDisplay(SDL_VideoDisplay * display, const SDL_DisplayMode * /* Get a good video mode, the closest one possible */ if (!SDL_GetClosestDisplayModeForDisplay(display, &display_mode, &display_mode)) { - SDL_SetError("No video mode large enough for %dx%d", - display_mode.w, display_mode.h); - return -1; + return SDL_SetError("No video mode large enough for %dx%d", + display_mode.w, display_mode.h); } } else { display_mode = display->desktop_mode; @@ -923,8 +914,7 @@ SDL_SetDisplayModeForDisplay(SDL_VideoDisplay * display, const SDL_DisplayMode * /* Actually change the display mode */ if (!_this->SetDisplayMode) { - SDL_SetError("Video driver doesn't support changing display mode"); - return -1; + return SDL_SetError("Video driver doesn't support changing display mode"); } if (_this->SetDisplayMode(_this, display, &display_mode) < 0) { return -1; @@ -1023,6 +1013,10 @@ SDL_GetWindowDisplayMode(SDL_Window * window, SDL_DisplayMode * mode) SDL_DisplayMode fullscreen_mode; SDL_VideoDisplay *display; + if (!mode) { + return SDL_InvalidParamError("mode"); + } + CHECK_WINDOW_MAGIC(window, -1); fullscreen_mode = window->fullscreen_mode; @@ -1043,8 +1037,7 @@ SDL_GetWindowDisplayMode(SDL_Window * window, SDL_DisplayMode * mode) else if (!SDL_GetClosestDisplayModeForDisplay(SDL_GetDisplayForWindow(window), &fullscreen_mode, &fullscreen_mode)) { - SDL_SetError("Couldn't find display mode match"); - return -1; + return SDL_SetError("Couldn't find display mode match"); } if (mode) { @@ -1297,8 +1290,7 @@ SDL_RecreateWindow(SDL_Window * window, Uint32 flags) char *title = window->title; if ((flags & SDL_WINDOW_OPENGL) && !_this->GL_CreateContext) { - SDL_SetError("No OpenGL support in video driver"); - return -1; + return SDL_SetError("No OpenGL support in video driver"); } if (window->flags & SDL_WINDOW_FOREIGN) { @@ -1436,11 +1428,17 @@ SDL_SetWindowData(SDL_Window * window, const char *name, void *userdata) SDL_WindowUserData *prev, *data; CHECK_WINDOW_MAGIC(window, NULL); + + /* Input validation */ + if (name == NULL || SDL_strlen(name) == 0) { + SDL_InvalidParamError("name"); + return NULL; + } /* See if the named data already exists */ prev = NULL; for (data = window->data; data; prev = data, data = data->next) { - if (SDL_strcmp(data->name, name) == 0) { + if (data->name && SDL_strcmp(data->name, name) == 0) { void *last_value = data->data; if (userdata) { @@ -1478,8 +1476,14 @@ SDL_GetWindowData(SDL_Window * window, const char *name) CHECK_WINDOW_MAGIC(window, NULL); + /* Input validation */ + if (name == NULL || SDL_strlen(name) == 0) { + SDL_InvalidParamError("name"); + return NULL; + } + for (data = window->data; data; data = data->next) { - if (SDL_strcmp(data->name, name) == 0) { + if (data->name && SDL_strcmp(data->name, name) == 0) { return data->data; } } @@ -1522,18 +1526,16 @@ SDL_SetWindowPosition(SDL_Window * window, int x, int y) void SDL_GetWindowPosition(SDL_Window * window, int *x, int *y) { - /* Clear the values */ - if (x) { - *x = 0; - } - if (y) { - *y = 0; - } - CHECK_WINDOW_MAGIC(window, ); /* Fullscreen windows are always at their display's origin */ if (window->flags & SDL_WINDOW_FULLSCREEN) { + if (x) { + *x = 0; + } + if (y) { + *y = 0; + } } else { if (x) { *x = window->x; @@ -1566,6 +1568,14 @@ void SDL_SetWindowSize(SDL_Window * window, int w, int h) { CHECK_WINDOW_MAGIC(window, ); + if (w <= 0) { + SDL_InvalidParamError("w"); + return; + } + if (h <= 0) { + SDL_InvalidParamError("h"); + return; + } /* FIXME: Should this change fullscreen modes? */ if (!(window->flags & SDL_WINDOW_FULLSCREEN)) { @@ -1584,30 +1594,27 @@ SDL_SetWindowSize(SDL_Window * window, int w, int h) void SDL_GetWindowSize(SDL_Window * window, int *w, int *h) { - int dummy; - - if (!w) { - w = &dummy; - } - if (!h) { - h = &dummy; - } - - *w = 0; - *h = 0; - CHECK_WINDOW_MAGIC(window, ); - - if (_this && window && window->magic == &_this->window_magic) { + if (w) { *w = window->w; - *h = window->h; } + if (h) { + *h = window->h; + } } void SDL_SetWindowMinimumSize(SDL_Window * window, int min_w, int min_h) { CHECK_WINDOW_MAGIC(window, ); + if (min_w <= 0) { + SDL_InvalidParamError("min_w"); + return; + } + if (min_h <= 0) { + SDL_InvalidParamError("min_h"); + return; + } if (!(window->flags & SDL_WINDOW_FULLSCREEN)) { window->min_w = min_w; @@ -1623,22 +1630,11 @@ SDL_SetWindowMinimumSize(SDL_Window * window, int min_w, int min_h) void SDL_GetWindowMinimumSize(SDL_Window * window, int *min_w, int *min_h) { - int dummy; - - if (!min_w) { - min_w = &dummy; - } - if (!min_h) { - min_h = &dummy; - } - - *min_w = 0; - *min_h = 0; - CHECK_WINDOW_MAGIC(window, ); - - if (_this && window && window->magic == &_this->window_magic) { + if (min_w) { *min_w = window->min_w; + } + if (min_h) { *min_h = window->min_h; } } @@ -1647,6 +1643,14 @@ void SDL_SetWindowMaximumSize(SDL_Window * window, int max_w, int max_h) { CHECK_WINDOW_MAGIC(window, ); + if (max_w <= 0) { + SDL_InvalidParamError("max_w"); + return; + } + if (max_h <= 0) { + SDL_InvalidParamError("max_h"); + return; + } if (!(window->flags & SDL_WINDOW_FULLSCREEN)) { window->max_w = max_w; @@ -1662,22 +1666,11 @@ SDL_SetWindowMaximumSize(SDL_Window * window, int max_w, int max_h) void SDL_GetWindowMaximumSize(SDL_Window * window, int *max_w, int *max_h) { - int dummy; - - if (!max_w) { - max_w = &dummy; - } - if (!max_h) { - max_h = &dummy; - } - - *max_w = 0; - *max_h = 0; - CHECK_WINDOW_MAGIC(window, ); - - if (_this && window && window->magic == &_this->window_magic) { + if (max_w) { *max_w = window->max_w; + } + if (max_h) { *max_h = window->max_h; } } @@ -1850,14 +1843,13 @@ SDL_UpdateWindowSurface(SDL_Window * window) } int -SDL_UpdateWindowSurfaceRects(SDL_Window * window, SDL_Rect * rects, +SDL_UpdateWindowSurfaceRects(SDL_Window * window, const SDL_Rect * rects, int numrects) { CHECK_WINDOW_MAGIC(window, -1); if (!window->surface_valid) { - SDL_SetError("Window surface is invalid, please call SDL_GetWindowSurface() to get a new surface"); - return -1; + return SDL_SetError("Window surface is invalid, please call SDL_GetWindowSurface() to get a new surface"); } return _this->UpdateWindowFramebuffer(_this, window, rects, numrects); @@ -1895,8 +1887,7 @@ SDL_SetWindowGammaRamp(SDL_Window * window, const Uint16 * red, CHECK_WINDOW_MAGIC(window, -1); if (!_this->SetWindowGammaRamp) { - SDL_Unsupported(); - return -1; + return SDL_Unsupported(); } if (!window->gamma) { @@ -1933,8 +1924,7 @@ SDL_GetWindowGammaRamp(SDL_Window * window, Uint16 * red, window->gamma = (Uint16 *)SDL_malloc(256*6*sizeof(Uint16)); if (!window->gamma) { - SDL_OutOfMemory(); - return -1; + return SDL_OutOfMemory(); } window->saved_gamma = window->gamma + 3*256; @@ -2275,19 +2265,16 @@ SDL_GL_LoadLibrary(const char *path) int retval; if (!_this) { - SDL_UninitializedVideo(); - return -1; + return SDL_UninitializedVideo(); } if (_this->gl_config.driver_loaded) { if (path && SDL_strcmp(path, _this->gl_config.driver_path) != 0) { - SDL_SetError("OpenGL library already loaded"); - return -1; + return SDL_SetError("OpenGL library already loaded"); } retval = 0; } else { if (!_this->GL_LoadLibrary) { - SDL_SetError("No dynamic GL support in video driver"); - return -1; + return SDL_SetError("No dynamic GL support in video driver"); } retval = _this->GL_LoadLibrary(_this, path); } @@ -2397,8 +2384,7 @@ SDL_GL_SetAttribute(SDL_GLattr attr, int value) int retval; if (!_this) { - SDL_UninitializedVideo(); - return -1; + return SDL_UninitializedVideo(); } retval = 0; switch (attr) { @@ -2467,8 +2453,7 @@ SDL_GL_SetAttribute(SDL_GLattr attr, int value) SDL_GL_CONTEXT_FORWARD_COMPATIBLE_FLAG | SDL_GL_CONTEXT_ROBUST_ACCESS_FLAG | SDL_GL_CONTEXT_RESET_ISOLATION_FLAG) ) { - SDL_SetError("Unknown OpenGL context flag %d", value); - retval = -1; + retval = SDL_SetError("Unknown OpenGL context flag %d", value); break; } _this->gl_config.flags = value; @@ -2478,8 +2463,7 @@ SDL_GL_SetAttribute(SDL_GLattr attr, int value) value != SDL_GL_CONTEXT_PROFILE_CORE && value != SDL_GL_CONTEXT_PROFILE_COMPATIBILITY && value != SDL_GL_CONTEXT_PROFILE_ES ) { - SDL_SetError("Unknown OpenGL context profile %d", value); - retval = -1; + retval = SDL_SetError("Unknown OpenGL context profile %d", value); break; } _this->gl_config.profile_mask = value; @@ -2488,14 +2472,12 @@ SDL_GL_SetAttribute(SDL_GLattr attr, int value) _this->gl_config.share_with_current_context = value; break; default: - SDL_SetError("Unknown OpenGL attribute"); - retval = -1; + retval = SDL_SetError("Unknown OpenGL attribute"); break; } return retval; #else - SDL_Unsupported(); - return -1; + return SDL_Unsupported(); #endif /* SDL_VIDEO_OPENGL */ } @@ -2654,36 +2636,22 @@ SDL_GL_GetAttribute(SDL_GLattr attr, int *value) return 0; } default: - SDL_SetError("Unknown OpenGL attribute"); - return -1; + return SDL_SetError("Unknown OpenGL attribute"); } glGetIntegervFunc(attrib, (GLint *) value); error = glGetErrorFunc(); if (error != GL_NO_ERROR) { - switch (error) { - case GL_INVALID_ENUM: - { - SDL_SetError("OpenGL error: GL_INVALID_ENUM"); - } - break; - case GL_INVALID_VALUE: - { - SDL_SetError("OpenGL error: GL_INVALID_VALUE"); - } - break; - default: - { - SDL_SetError("OpenGL error: %08X", error); - } - break; + if (error == GL_INVALID_ENUM) { + return SDL_SetError("OpenGL error: GL_INVALID_ENUM"); + } else if (error == GL_INVALID_VALUE) { + return SDL_SetError("OpenGL error: GL_INVALID_VALUE"); } - return -1; + return SDL_SetError("OpenGL error: %08X", error); } return 0; #else - SDL_Unsupported(); - return -1; + return SDL_Unsupported(); #endif /* SDL_VIDEO_OPENGL */ } @@ -2715,8 +2683,7 @@ SDL_GL_MakeCurrent(SDL_Window * window, SDL_GLContext ctx) CHECK_WINDOW_MAGIC(window, -1); if (!(window->flags & SDL_WINDOW_OPENGL)) { - SDL_SetError("The specified window isn't an OpenGL window"); - return -1; + return SDL_SetError("The specified window isn't an OpenGL window"); } if (!ctx) { window = NULL; @@ -2739,16 +2706,13 @@ int SDL_GL_SetSwapInterval(int interval) { if (!_this) { - SDL_UninitializedVideo(); - return -1; + return SDL_UninitializedVideo(); } else if (_this->current_glctx == NULL) { - SDL_SetError("No OpenGL context has been made current"); - return -1; + return SDL_SetError("No OpenGL context has been made current"); } else if (_this->GL_SetSwapInterval) { return _this->GL_SetSwapInterval(_this, interval); } else { - SDL_SetError("Setting the swap interval is not supported"); - return -1; + return SDL_SetError("Setting the swap interval is not supported"); } } @@ -3034,8 +2998,7 @@ SDL_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonid) SDL_ShowCursor( show_cursor_prev ); SDL_SetRelativeMouseMode( relative_mode ); - if(retval == -1) - { + if(retval == -1) { SDL_SetError("No message system available"); } return retval; diff --git a/src/video/android/SDL_androidgl.c b/src/video/android/SDL_androidgl.c index 8cdaa46d61..1382b88786 100644 --- a/src/video/android/SDL_androidgl.c +++ b/src/video/android/SDL_androidgl.c @@ -42,8 +42,7 @@ Android_GL_LoadLibrary(_THIS, const char *path) if (!Android_GLHandle) { Android_GLHandle = dlopen("libGLESv1_CM.so",RTLD_GLOBAL); if (!Android_GLHandle) { - SDL_SetError("Could not initialize GL ES library\n"); - return -1; + return SDL_SetError("Could not initialize GL ES library\n"); } } return 0; diff --git a/src/video/android/SDL_androidtouch.c b/src/video/android/SDL_androidtouch.c index 67e3f94268..c8d5ae6d55 100644 --- a/src/video/android/SDL_androidtouch.c +++ b/src/video/android/SDL_androidtouch.c @@ -63,22 +63,8 @@ void Android_OnTouch(int touch_device_id_in, int pointer_finger_id_in, int actio } touchDeviceId = (SDL_TouchID)touch_device_id_in; - if (!SDL_GetTouch(touchDeviceId)) { - SDL_Touch touch; - memset( &touch, 0, sizeof(touch) ); - touch.id = touchDeviceId; - touch.x_min = 0.0f; - touch.x_max = 1.0f; - touch.native_xres = touch.x_max - touch.x_min; - touch.y_min = 0.0f; - touch.y_max = 1.0f; - touch.native_yres = touch.y_max - touch.y_min; - touch.pressure_min = 0.0f; - touch.pressure_max = 1.0f; - touch.native_pressureres = touch.pressure_max - touch.pressure_min; - if (SDL_AddTouch(&touch, "") < 0) { - SDL_Log("error: can't add touch %s, %d", __FILE__, __LINE__); - } + if (SDL_AddTouch(touchDeviceId, "") < 0) { + SDL_Log("error: can't add touch %s, %d", __FILE__, __LINE__); } fingerId = (SDL_FingerID)pointer_finger_id_in; @@ -89,32 +75,32 @@ void Android_OnTouch(int touch_device_id_in, int pointer_finger_id_in, int actio Android_GetWindowCoordinates(x, y, &window_x, &window_y); /* send moved event */ - SDL_SendMouseMotion(NULL, 0, window_x, window_y); + SDL_SendMouseMotion(NULL, SDL_TOUCH_MOUSEID, 0, window_x, window_y); /* send mouse down event */ - SDL_SendMouseButton(NULL, SDL_PRESSED, SDL_BUTTON_LEFT); + SDL_SendMouseButton(NULL, SDL_TOUCH_MOUSEID, SDL_PRESSED, SDL_BUTTON_LEFT); leftFingerDown = fingerId; } - SDL_SendFingerDown(touchDeviceId, fingerId, SDL_TRUE, x, y, p); + SDL_SendTouch(touchDeviceId, fingerId, SDL_TRUE, x, y, p); break; case ACTION_MOVE: if (!leftFingerDown) { Android_GetWindowCoordinates(x, y, &window_x, &window_y); /* send moved event */ - SDL_SendMouseMotion(NULL, 0, window_x, window_y); + SDL_SendMouseMotion(NULL, SDL_TOUCH_MOUSEID, 0, window_x, window_y); } - SDL_SendTouchMotion(touchDeviceId, fingerId, SDL_FALSE, x, y, p); + SDL_SendTouchMotion(touchDeviceId, fingerId, x, y, p); break; case ACTION_UP: case ACTION_POINTER_1_UP: if (fingerId == leftFingerDown) { /* send mouse up */ - SDL_SendMouseButton(NULL, SDL_RELEASED, SDL_BUTTON_LEFT); + SDL_SendMouseButton(NULL, SDL_TOUCH_MOUSEID, SDL_RELEASED, SDL_BUTTON_LEFT); leftFingerDown = 0; } - SDL_SendFingerDown(touchDeviceId, fingerId, SDL_FALSE, x, y, p); + SDL_SendTouch(touchDeviceId, fingerId, SDL_FALSE, x, y, p); break; default: break; diff --git a/src/video/android/SDL_androidwindow.c b/src/video/android/SDL_androidwindow.c index 88b124a01b..7d13a26d31 100644 --- a/src/video/android/SDL_androidwindow.c +++ b/src/video/android/SDL_androidwindow.c @@ -31,8 +31,7 @@ int Android_CreateWindow(_THIS, SDL_Window * window) { if (Android_Window) { - SDL_SetError("Android only supports one window"); - return -1; + return SDL_SetError("Android only supports one window"); } Android_Window = window; Android_PauseSem = SDL_CreateSemaphore(0); diff --git a/src/video/bwindow/SDL_bframebuffer.cc b/src/video/bwindow/SDL_bframebuffer.cc index 28bb842a46..6e7f8c3f24 100644 --- a/src/video/bwindow/SDL_bframebuffer.cc +++ b/src/video/bwindow/SDL_bframebuffer.cc @@ -76,8 +76,7 @@ int BE_CreateWindowFramebuffer(_THIS, SDL_Window * window, true); /* Contiguous memory required */ if(bitmap->InitCheck() != B_OK) { - SDL_SetError("Could not initialize back buffer!\n"); - return -1; + return SDL_SetError("Could not initialize back buffer!\n"); } @@ -98,7 +97,7 @@ int BE_CreateWindowFramebuffer(_THIS, SDL_Window * window, int BE_UpdateWindowFramebuffer(_THIS, SDL_Window * window, - SDL_Rect * rects, int numrects) { + const SDL_Rect * rects, int numrects) { if(!window) return 0; diff --git a/src/video/bwindow/SDL_bframebuffer.h b/src/video/bwindow/SDL_bframebuffer.h index 76d054b701..935f0e95a3 100644 --- a/src/video/bwindow/SDL_bframebuffer.h +++ b/src/video/bwindow/SDL_bframebuffer.h @@ -34,7 +34,7 @@ extern int BE_CreateWindowFramebuffer(_THIS, SDL_Window * window, Uint32 * format, void ** pixels, int *pitch); extern int BE_UpdateWindowFramebuffer(_THIS, SDL_Window * window, - SDL_Rect * rects, int numrects); + const SDL_Rect * rects, int numrects); extern void BE_DestroyWindowFramebuffer(_THIS, SDL_Window * window); extern int32 BE_DrawThread(void *data); diff --git a/src/video/bwindow/SDL_bmodes.cc b/src/video/bwindow/SDL_bmodes.cc index 5abdf8ddef..2e8f4b577c 100644 --- a/src/video/bwindow/SDL_bmodes.cc +++ b/src/video/bwindow/SDL_bmodes.cc @@ -310,8 +310,7 @@ int BE_SetDisplayMode(_THIS, SDL_VideoDisplay *display, SDL_DisplayMode *mode){ } if(bscreen.SetMode(bmode) != B_OK) { - SDL_SetError("Bad video mode\n"); - return -1; + return SDL_SetError("Bad video mode\n"); } free(bmode_list); diff --git a/src/video/cocoa/SDL_cocoamodes.m b/src/video/cocoa/SDL_cocoamodes.m index 4f6cf6555f..563226c2ab 100644 --- a/src/video/cocoa/SDL_cocoamodes.m +++ b/src/video/cocoa/SDL_cocoamodes.m @@ -84,7 +84,7 @@ IS_SNOW_LEOPARD_OR_LATER(_THIS) #endif } -static void +static int CG_SetError(const char *prefix, CGDisplayErr result) { const char *error; @@ -124,7 +124,7 @@ CG_SetError(const char *prefix, CGDisplayErr result) error = "Unknown Error"; break; } - SDL_SetError("%s: %s", prefix, error); + return SDL_SetError("%s: %s", prefix, error); } static SDL_bool diff --git a/src/video/cocoa/SDL_cocoamouse.m b/src/video/cocoa/SDL_cocoamouse.m index 158fa17cdf..a12bde8ddc 100644 --- a/src/video/cocoa/SDL_cocoamouse.m +++ b/src/video/cocoa/SDL_cocoamouse.m @@ -190,8 +190,7 @@ Cocoa_SetRelativeMouseMode(SDL_bool enabled) result = CGAssociateMouseAndMouseCursorPosition(YES); } if (result != kCGErrorSuccess) { - SDL_SetError("CGAssociateMouseAndMouseCursorPosition() failed"); - return -1; + return SDL_SetError("CGAssociateMouseAndMouseCursorPosition() failed"); } return 0; } @@ -223,13 +222,15 @@ Cocoa_HandleMouseEvent(_THIS, NSEvent *event) [event type] == NSOtherMouseDragged)) { float x = [event deltaX]; float y = [event deltaY]; - SDL_SendMouseMotion(mouse->focus, 1, (int)x, (int)y); + SDL_SendMouseMotion(mouse->focus, mouse->mouseID, 1, (int)x, (int)y); } } void Cocoa_HandleMouseWheel(SDL_Window *window, NSEvent *event) { + SDL_Mouse *mouse = SDL_GetMouse(); + float x = [event deltaX]; float y = [event deltaY]; @@ -243,7 +244,7 @@ Cocoa_HandleMouseWheel(SDL_Window *window, NSEvent *event) } else if (y < 0) { y -= 0.9f; } - SDL_SendMouseWheel(window, (int)x, (int)y); + SDL_SendMouseWheel(window, mouse->mouseID, (int)x, (int)y); } void diff --git a/src/video/cocoa/SDL_cocoaopengl.m b/src/video/cocoa/SDL_cocoaopengl.m index 20cc35b19c..a1686219ba 100644 --- a/src/video/cocoa/SDL_cocoaopengl.m +++ b/src/video/cocoa/SDL_cocoaopengl.m @@ -35,9 +35,13 @@ #define DEFAULT_OPENGL "/System/Library/Frameworks/OpenGL.framework/Libraries/libGL.dylib" -#if MAC_OS_X_VERSION_MAX_ALLOWED < 1070 +#ifndef kCGLPFAOpenGLProfile #define kCGLPFAOpenGLProfile 99 +#endif +#ifndef kCGLOGLPVersion_Legacy #define kCGLOGLPVersion_Legacy 0x1000 +#endif +#ifndef kCGLOGLPVersion_3_2_Core #define kCGLOGLPVersion_3_2_Core 0x3200 #endif @@ -270,8 +274,7 @@ Cocoa_GL_SetSwapInterval(_THIS, int interval) [nscontext setValues:&value forParameter:NSOpenGLCPSwapInterval]; status = 0; } else { - SDL_SetError("No current OpenGL context"); - status = -1; + status = SDL_SetError("No current OpenGL context"); } [pool release]; diff --git a/src/video/cocoa/SDL_cocoawindow.m b/src/video/cocoa/SDL_cocoawindow.m index 5c9fd082d4..f2803dad34 100644 --- a/src/video/cocoa/SDL_cocoawindow.m +++ b/src/video/cocoa/SDL_cocoawindow.m @@ -200,7 +200,7 @@ static __inline__ void ConvertNSRect(NSRect *r) y = (int)(window->h - point.y); if (x >= 0 && x < window->w && y >= 0 && y < window->h) { - SDL_SendMouseMotion(window, 0, x, y); + SDL_SendMouseMotion(window, 0, 0, x, y); SDL_SetCursor(NULL); } } @@ -263,7 +263,7 @@ static __inline__ void ConvertNSRect(NSRect *r) button = [theEvent buttonNumber] + 1; break; } - SDL_SendMouseButton(_data->window, SDL_PRESSED, button); + SDL_SendMouseButton(_data->window, 0, SDL_PRESSED, button); } - (void)rightMouseDown:(NSEvent *)theEvent @@ -294,7 +294,7 @@ static __inline__ void ConvertNSRect(NSRect *r) button = [theEvent buttonNumber] + 1; break; } - SDL_SendMouseButton(_data->window, SDL_RELEASED, button); + SDL_SendMouseButton(_data->window, 0, SDL_RELEASED, button); } - (void)rightMouseUp:(NSEvent *)theEvent @@ -342,7 +342,7 @@ static __inline__ void ConvertNSRect(NSRect *r) CGDisplayMoveCursorToPoint(kCGDirectMainDisplay, cgpoint); } } - SDL_SendMouseMotion(window, 0, x, y); + SDL_SendMouseMotion(window, 0, 0, x, y); } - (void)mouseDragged:(NSEvent *)theEvent @@ -408,27 +408,14 @@ static __inline__ void ConvertNSRect(NSRect *r) enumerator = [touches objectEnumerator]; touch = (NSTouch*)[enumerator nextObject]; while (touch) { - const SDL_TouchID touchId = (SDL_TouchID) ((size_t) [touch device]); + const SDL_TouchID touchId = (SDL_TouchID)(intptr_t)[touch device]; if (!SDL_GetTouch(touchId)) { - SDL_Touch touch; - - touch.id = touchId; - touch.x_min = 0; - touch.x_max = 1; - touch.native_xres = touch.x_max - touch.x_min; - touch.y_min = 0; - touch.y_max = 1; - touch.native_yres = touch.y_max - touch.y_min; - touch.pressure_min = 0; - touch.pressure_max = 1; - touch.native_pressureres = touch.pressure_max - touch.pressure_min; - - if (SDL_AddTouch(&touch, "") < 0) { + if (SDL_AddTouch(touchId, "") < 0) { return; } } - const SDL_FingerID fingerId = (SDL_FingerID) ((size_t) [touch identity]); + const SDL_FingerID fingerId = (SDL_FingerID)(intptr_t)[touch identity]; float x = [touch normalizedPosition].x; float y = [touch normalizedPosition].y; /* Make the origin the upper left instead of the lower left */ @@ -436,17 +423,17 @@ static __inline__ void ConvertNSRect(NSRect *r) switch (type) { case COCOA_TOUCH_DOWN: - SDL_SendFingerDown(touchId, fingerId, SDL_TRUE, x, y, 1); + SDL_SendTouch(touchId, fingerId, SDL_TRUE, x, y, 1.0f); break; case COCOA_TOUCH_UP: case COCOA_TOUCH_CANCELLED: - SDL_SendFingerDown(touchId, fingerId, SDL_FALSE, x, y, 1); + SDL_SendTouch(touchId, fingerId, SDL_FALSE, x, y, 1.0f); break; case COCOA_TOUCH_MOVE: - SDL_SendTouchMotion(touchId, fingerId, SDL_FALSE, x, y, 1); + SDL_SendTouchMotion(touchId, fingerId, x, y, 1.0f); break; } - + touch = (NSTouch*)[enumerator nextObject]; } #endif /* MAC_OS_X_VERSION_MAX_ALLOWED >= 1060 */ @@ -514,8 +501,7 @@ SetupWindowData(_THIS, SDL_Window * window, NSWindow *nswindow, SDL_bool created /* Allocate the window data */ data = (SDL_WindowData *) SDL_calloc(1, sizeof(*data)); if (!data) { - SDL_OutOfMemory(); - return -1; + return SDL_OutOfMemory(); } data->window = window; data->nswindow = nswindow; @@ -967,8 +953,7 @@ Cocoa_SetWindowGammaRamp(_THIS, SDL_Window * window, const Uint16 * ramp) if (CGSetDisplayTransferByTable(display_id, tableSize, redTable, greenTable, blueTable) != CGDisplayNoErr) { - SDL_SetError("CGSetDisplayTransferByTable()"); - return -1; + return SDL_SetError("CGSetDisplayTransferByTable()"); } return 0; } @@ -986,8 +971,7 @@ Cocoa_GetWindowGammaRamp(_THIS, SDL_Window * window, Uint16 * ramp) if (CGGetDisplayTransferByTable(display_id, tableSize, redTable, greenTable, blueTable, &tableCopied) != CGDisplayNoErr) { - SDL_SetError("CGGetDisplayTransferByTable()"); - return -1; + return SDL_SetError("CGGetDisplayTransferByTable()"); } for (i = 0; i < tableCopied; i++) { diff --git a/src/video/directfb/SDL_DirectFB_events.c b/src/video/directfb/SDL_DirectFB_events.c index c04eed499e..8ee0b90859 100644 --- a/src/video/directfb/SDL_DirectFB_events.c +++ b/src/video/directfb/SDL_DirectFB_events.c @@ -40,13 +40,13 @@ #include "SDL_DirectFB_events.h" #if USE_MULTI_API -#define SDL_SendMouseMotion_ex(w, id, relative, x, y, p) SDL_SendMouseMotion(id, relative, x, y, p) -#define SDL_SendMouseButton_ex(w, id, state, button) SDL_SendMouseButton(id, state, button) +#define SDL_SendMouseMotion_ex(w, id, relative, x, y, p) SDL_SendMouseMotion(w, id, relative, x, y, p) +#define SDL_SendMouseButton_ex(w, id, state, button) SDL_SendMouseButton(w, id, state, button) #define SDL_SendKeyboardKey_ex(id, state, scancode) SDL_SendKeyboardKey(id, state, scancode) #define SDL_SendKeyboardText_ex(id, text) SDL_SendKeyboardText(id, text) #else -#define SDL_SendMouseMotion_ex(w, id, relative, x, y, p) SDL_SendMouseMotion(w, relative, x, y) -#define SDL_SendMouseButton_ex(w, id, state, button) SDL_SendMouseButton(w, state, button) +#define SDL_SendMouseMotion_ex(w, id, relative, x, y, p) SDL_SendMouseMotion(w, id, relative, x, y) +#define SDL_SendMouseButton_ex(w, id, state, button) SDL_SendMouseButton(w, id, state, button) #define SDL_SendKeyboardKey_ex(id, state, scancode) SDL_SendKeyboardKey(state, scancode) #define SDL_SendKeyboardText_ex(id, text) SDL_SendKeyboardText(text) #endif diff --git a/src/video/directfb/SDL_DirectFB_opengl.c b/src/video/directfb/SDL_DirectFB_opengl.c index 09a3bddc22..c325f42316 100644 --- a/src/video/directfb/SDL_DirectFB_opengl.c +++ b/src/video/directfb/SDL_DirectFB_opengl.c @@ -72,8 +72,7 @@ DirectFB_GL_Initialize(_THIS) sizeof(struct SDL_GLDriverData)); if (!_this->gl_data) { - SDL_OutOfMemory(); - return -1; + return SDL_OutOfMemory(); } _this->gl_data->initialized = 0; @@ -115,8 +114,7 @@ DirectFB_GL_LoadLibrary(_THIS, const char *path) SDL_DFB_DEBUG("Loadlibrary : %s\n", path); if (_this->gl_data->gl_active) { - SDL_SetError("OpenGL context already created"); - return -1; + return SDL_SetError("OpenGL context already created"); } @@ -243,8 +241,7 @@ DirectFB_GL_MakeCurrent(_THIS, SDL_Window * window, SDL_GLContext context) int DirectFB_GL_SetSwapInterval(_THIS, int interval) { - SDL_Unsupported(); - return -1; + return SDL_Unsupported(); } int diff --git a/src/video/directfb/SDL_DirectFB_render.c b/src/video/directfb/SDL_DirectFB_render.c index da81104276..db69a5c442 100644 --- a/src/video/directfb/SDL_DirectFB_render.c +++ b/src/video/directfb/SDL_DirectFB_render.c @@ -35,21 +35,21 @@ #ifndef DFB_VERSION_ATLEAST -#define DFB_VERSIONNUM(X, Y, Z) \ - ((X)*1000 + (Y)*100 + (Z)) +#define DFB_VERSIONNUM(X, Y, Z) \ + ((X)*1000 + (Y)*100 + (Z)) #define DFB_COMPILEDVERSION \ - DFB_VERSIONNUM(DIRECTFB_MAJOR_VERSION, DIRECTFB_MINOR_VERSION, DIRECTFB_MICRO_VERSION) + DFB_VERSIONNUM(DIRECTFB_MAJOR_VERSION, DIRECTFB_MINOR_VERSION, DIRECTFB_MICRO_VERSION) #define DFB_VERSION_ATLEAST(X, Y, Z) \ - (DFB_COMPILEDVERSION >= DFB_VERSIONNUM(X, Y, Z)) + (DFB_COMPILEDVERSION >= DFB_VERSIONNUM(X, Y, Z)) -#define SDL_DFB_CHECK(x) x +#define SDL_DFB_CHECK(x) x #endif /* the following is not yet tested ... */ -#define USE_DISPLAY_PALETTE (0) +#define USE_DISPLAY_PALETTE (0) #define SDL_DFB_RENDERERDATA(rend) DirectFB_RenderData *renddata = ((rend) ? (DirectFB_RenderData *) (rend)->driverdata : NULL) @@ -96,17 +96,17 @@ static void DirectFB_DirtyTexture(SDL_Renderer * renderer, const SDL_Rect * rects); static int DirectFB_SetDrawBlendMode(SDL_Renderer * renderer); static int DirectFB_RenderDrawPoints(SDL_Renderer * renderer, - const SDL_Point * points, int count); + const SDL_FPoint * points, int count); static int DirectFB_RenderDrawLines(SDL_Renderer * renderer, - const SDL_Point * points, int count); + const SDL_FPoint * points, int count); static int DirectFB_RenderDrawRects(SDL_Renderer * renderer, - const SDL_Rect ** rects, int count); + const SDL_Rect ** rects, int count); static int DirectFB_RenderFillRects(SDL_Renderer * renderer, - const SDL_Rect * rects, int count); + const SDL_FRect * rects, int count); static int DirectFB_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture, const SDL_Rect * srcrect, - const SDL_Rect * dstrect); + const SDL_FRect * dstrect); static void DirectFB_RenderPresent(SDL_Renderer * renderer); static void DirectFB_DestroyTexture(SDL_Renderer * renderer, SDL_Texture * texture); @@ -116,6 +116,7 @@ static int DirectFB_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * r static int DirectFB_RenderWritePixels(SDL_Renderer * renderer, const SDL_Rect * rect, Uint32 format, const void * pixels, int pitch); static int DirectFB_UpdateViewport(SDL_Renderer * renderer); +static int DirectFB_SetRenderTarget(SDL_Renderer * renderer, SDL_Texture * texture); static int PrepareDraw(SDL_Renderer * renderer); @@ -135,7 +136,7 @@ SDL_RenderDriver DirectFB_RenderDriver = { SDL_SCALEMODE_SLOW | SDL_SCALEMODE_BEST),*/ 0, { - /* formats filled in later */ + /* formats filled in later */ }, 0, 0} @@ -149,6 +150,7 @@ typedef struct int lastBlendMode; DFBSurfaceBlittingFlags blitFlags; DFBSurfaceDrawingFlags drawFlags; + IDirectFBSurface* target; } DirectFB_RenderData; typedef struct @@ -175,6 +177,14 @@ SDLtoDFBRect(const SDL_Rect * sr, DFBRectangle * dr) dr->h = sr->h; dr->w = sr->w; } +static __inline__ void +SDLtoDFBRect_Float(const SDL_FRect * sr, DFBRectangle * dr) +{ + dr->x = sr->x; + dr->y = sr->y; + dr->h = sr->h; + dr->w = sr->w; +} static int @@ -183,7 +193,7 @@ TextureHasAlpha(DirectFB_TextureData * data) /* Drawing primitive ? */ if (!data) return 0; - + return (DFB_PIXELFORMAT_HAS_ALPHA(DirectFB_SDLToDFBPixelFormat(data->format)) ? 1 : 0); #if 0 switch (data->format) { @@ -205,27 +215,31 @@ TextureHasAlpha(DirectFB_TextureData * data) static inline IDirectFBSurface *get_dfb_surface(SDL_Window *window) { - SDL_SysWMinfo wm_info; - SDL_VERSION(&wm_info.version); - SDL_GetWindowWMInfo(window, &wm_info); + SDL_SysWMinfo wm_info; + SDL_memset(&wm_info, 0, sizeof(SDL_SysWMinfo)); + + SDL_VERSION(&wm_info.version); + SDL_GetWindowWMInfo(window, &wm_info); - return wm_info.info.dfb.surface; + return wm_info.info.dfb.surface; } static inline IDirectFBWindow *get_dfb_window(SDL_Window *window) { - SDL_SysWMinfo wm_info; - SDL_VERSION(&wm_info.version); - SDL_GetWindowWMInfo(window, &wm_info); + SDL_SysWMinfo wm_info; + SDL_memset(&wm_info, 0, sizeof(SDL_SysWMinfo)); - return wm_info.info.dfb.window; + SDL_VERSION(&wm_info.version); + SDL_GetWindowWMInfo(window, &wm_info); + + return wm_info.info.dfb.window; } static void SetBlendMode(DirectFB_RenderData * data, int blendMode, DirectFB_TextureData * source) { - IDirectFBSurface *destsurf = get_dfb_surface(data->window); + IDirectFBSurface *destsurf = data->target; //FIXME: check for format change if (1 || data->lastBlendMode != blendMode) { @@ -256,7 +270,7 @@ SetBlendMode(DirectFB_RenderData * data, int blendMode, data->drawFlags = DSDRAW_BLEND; // FIXME: SRCALPHA kills performance on radeon ... // It will be cheaper to copy the surface to - // a temporay surface and premultiply + // a temporay surface and premultiply if (source && TextureHasAlpha(source)) SDL_DFB_CHECK(destsurf->SetSrcBlendFunction(destsurf, DSBF_SRCALPHA)); else @@ -327,7 +341,7 @@ int DirectFB_RenderClear(SDL_Renderer * renderer) { DirectFB_RenderData *data = (DirectFB_RenderData *) renderer->driverdata; - IDirectFBSurface *destsurf = get_dfb_surface(data->window); + IDirectFBSurface *destsurf = data->target; DirectFB_ActivateRenderer(renderer); @@ -342,7 +356,7 @@ DirectFB_RenderClear(SDL_Renderer * renderer) SDL_Renderer * DirectFB_CreateRenderer(SDL_Window * window, Uint32 flags) { - IDirectFBSurface *winsurf = get_dfb_surface(window); + IDirectFBSurface *winsurf = get_dfb_surface(window); SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window); SDL_Renderer *renderer = NULL; DirectFB_RenderData *data = NULL; @@ -370,14 +384,15 @@ DirectFB_CreateRenderer(SDL_Window * window, Uint32 flags) /* RenderFillEllipse - no reference implementation yet */ renderer->RenderCopy = DirectFB_RenderCopy; renderer->RenderPresent = DirectFB_RenderPresent; - + /* FIXME: Yet to be tested */ renderer->RenderReadPixels = DirectFB_RenderReadPixels; //renderer->RenderWritePixels = DirectFB_RenderWritePixels; - + renderer->DestroyTexture = DirectFB_DestroyTexture; renderer->DestroyRenderer = DirectFB_DestroyRenderer; renderer->UpdateViewport = DirectFB_UpdateViewport; + renderer->SetRenderTarget = DirectFB_SetRenderTarget; #if 0 renderer->QueryTexturePixels = DirectFB_QueryTexturePixels; @@ -394,9 +409,10 @@ DirectFB_CreateRenderer(SDL_Window * window, Uint32 flags) renderer->driverdata = data; renderer->info.flags = - SDL_RENDERER_ACCELERATED; + SDL_RENDERER_ACCELERATED | SDL_RENDERER_TARGETTEXTURE; data->window = window; + data->target = winsurf; data->flipflags = DSFLIP_PIPELINE | DSFLIP_BLIT; @@ -437,14 +453,13 @@ DirectFB_CreateRenderer(SDL_Window * window, Uint32 flags) static void DirectFB_ActivateRenderer(SDL_Renderer * renderer) { - SDL_DFB_RENDERERDATA(renderer); SDL_Window *window = renderer->window; SDL_DFB_WINDOWDATA(window); if (renddata->size_changed /*|| windata->wm_needs_redraw*/) { //DirectFB_AdjustWindowSurface(window); - renddata->size_changed = SDL_FALSE; + renddata->size_changed = SDL_FALSE; } } @@ -568,13 +583,13 @@ DirectFB_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture) SDL_DFB_CHECKERR(data->surface->GetPalette(data->surface, &data->palette)); #else /* DFB has issues with blitting LUT8 surfaces. - * Creating a new palette does not help. - */ - DFBPaletteDescription pal_desc; - pal_desc.flags = DPDESC_SIZE; // | DPDESC_ENTRIES - pal_desc.size = 256; - SDL_DFB_CHECKERR(devdata->dfb->CreatePalette(devdata->dfb, &pal_desc,&data->palette)); - SDL_DFB_CHECKERR(data->surface->SetPalette(data->surface, data->palette)); + * Creating a new palette does not help. + */ + DFBPaletteDescription pal_desc; + pal_desc.flags = DPDESC_SIZE; // | DPDESC_ENTRIES + pal_desc.size = 256; + SDL_DFB_CHECKERR(devdata->dfb->CreatePalette(devdata->dfb, &pal_desc,&data->palette)); + SDL_DFB_CHECKERR(data->surface->SetPalette(data->surface, data->palette)); #endif } @@ -630,7 +645,7 @@ DirectFB_SetTexturePalette(SDL_Renderer * renderer, int i; if (ncolors > 256) - ncolors = 256; + ncolors = 256; for (i = 0; i < ncolors; ++i) { entries[i].r = colors[i].r; @@ -642,8 +657,7 @@ DirectFB_SetTexturePalette(SDL_Renderer * renderer, palette->SetEntries(data->palette, entries, ncolors, firstcolor)); return 0; } else { - SDL_SetError("YUV textures don't have a palette"); - return -1; + return SDL_SetError("YUV textures don't have a palette"); } error: return -1; @@ -669,12 +683,11 @@ DirectFB_GetTexturePalette(SDL_Renderer * renderer, colors[i].r = entries[i].r; colors[i].g = entries[i].g; colors[i].b = entries[i].b; - colors->unused = SDL_ALPHA_OPAQUE; + colors[i].unused = SDL_ALPHA_OPAQUE; } return 0; } else { - SDL_SetError("YUV textures don't have a palette"); - return -1; + return SDL_SetError("YUV textures don't have a palette"); } error: return -1; @@ -703,9 +716,8 @@ DirectFB_SetTextureBlendMode(SDL_Renderer * renderer, SDL_Texture * texture) case SDL_BLENDMODE_MOD: return 0; default: - SDL_Unsupported(); texture->blendMode = SDL_BLENDMODE_NONE; - return -1; + return SDL_Unsupported(); } } @@ -720,9 +732,8 @@ DirectFB_SetDrawBlendMode(SDL_Renderer * renderer) case SDL_BLENDMODE_MOD: return 0; default: - SDL_Unsupported(); renderer->blendMode = SDL_BLENDMODE_NONE; - return -1; + return SDL_Unsupported(); } } @@ -747,10 +758,9 @@ DirectFB_SetTextureScaleMode(SDL_Renderer * renderer, SDL_Texture * texture) DSRO_SMOOTH_UPSCALE | DSRO_SMOOTH_DOWNSCALE | DSRO_ANTIALIAS; break; default: - SDL_Unsupported(); data->render_options = DSRO_NONE; texture->scaleMode = SDL_SCALEMODE_NONE; - return -1; + return SDL_Unsupported(); } #endif return 0; @@ -776,7 +786,7 @@ DirectFB_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture, (texture->format == SDL_PIXELFORMAT_IYUV)) { bpp = 1; } - + SDL_DFB_CHECKERR(data->surface->Lock(data->surface, DSLF_WRITE | DSLF_READ, ((void **) &dpixels), &dpitch)); @@ -880,11 +890,28 @@ DirectFB_DirtyTexture(SDL_Renderer * renderer, SDL_Texture * texture, } #endif +static int DirectFB_SetRenderTarget(SDL_Renderer * renderer, SDL_Texture * texture) +{ + DirectFB_RenderData *data = (DirectFB_RenderData *) renderer->driverdata; + DirectFB_TextureData *tex_data = NULL; + + DirectFB_ActivateRenderer(renderer); + if (texture) { + tex_data = (DirectFB_TextureData *) texture->driverdata; + data->target = tex_data->surface; + } else { + data->target = get_dfb_surface(data->window); + } + data->lastBlendMode = 0; + return 0; +} + + static int PrepareDraw(SDL_Renderer * renderer) { DirectFB_RenderData *data = (DirectFB_RenderData *) renderer->driverdata; - IDirectFBSurface *destsurf = get_dfb_surface(data->window); + IDirectFBSurface *destsurf = data->target; Uint8 r, g, b, a; @@ -917,27 +944,33 @@ PrepareDraw(SDL_Renderer * renderer) } static int DirectFB_RenderDrawPoints(SDL_Renderer * renderer, - const SDL_Point * points, int count) + const SDL_FPoint * points, int count) { DirectFB_RenderData *data = (DirectFB_RenderData *) renderer->driverdata; - IDirectFBSurface *destsurf = get_dfb_surface(data->window); + IDirectFBSurface *destsurf = data->target; + DFBRegion clip_region; int i; DirectFB_ActivateRenderer(renderer); PrepareDraw(renderer); - for (i=0; i < count; i++) - SDL_DFB_CHECKERR(destsurf->DrawLine(destsurf, points[i].x, points[i].y, points[i].x, points[i].y)); + destsurf->GetClip(destsurf, &clip_region); + for (i=0; i < count; i++) { + int x = points[i].x + clip_region.x1; + int y = points[i].y + clip_region.y1; + SDL_DFB_CHECKERR(destsurf->DrawLine(destsurf, x, y, x, y)); + } return 0; error: return -1; } static int DirectFB_RenderDrawLines(SDL_Renderer * renderer, - const SDL_Point * points, int count) + const SDL_FPoint * points, int count) { DirectFB_RenderData *data = (DirectFB_RenderData *) renderer->driverdata; - IDirectFBSurface *destsurf = get_dfb_surface(data->window); + IDirectFBSurface *destsurf = data->target; + DFBRegion clip_region; int i; DirectFB_ActivateRenderer(renderer); @@ -948,8 +981,14 @@ static int DirectFB_RenderDrawLines(SDL_Renderer * renderer, SDL_DFB_CHECKERR(destsurf->SetRenderOptions(destsurf, DSRO_ANTIALIAS)); #endif - for (i=0; i < count - 1; i++) - SDL_DFB_CHECKERR(destsurf->DrawLine(destsurf, points[i].x, points[i].y, points[i+1].x, points[i+1].y)); + destsurf->GetClip(destsurf, &clip_region); + for (i=0; i < count - 1; i++) { + int x1 = points[i].x + clip_region.x1; + int y1 = points[i].y + clip_region.y1; + int x2 = points[i + 1].x + clip_region.x1; + int y2 = points[i + 1].y + clip_region.y1; + SDL_DFB_CHECKERR(destsurf->DrawLine(destsurf, x1, y1, x2, y2)); + } return 0; error: @@ -960,16 +999,22 @@ static int DirectFB_RenderDrawRects(SDL_Renderer * renderer, const SDL_Rect ** rects, int count) { DirectFB_RenderData *data = (DirectFB_RenderData *) renderer->driverdata; - IDirectFBSurface *destsurf = get_dfb_surface(data->window); + IDirectFBSurface *destsurf = data->target; + DFBRegion clip_region; int i; DirectFB_ActivateRenderer(renderer); PrepareDraw(renderer); - for (i=0; i<count; i++) - SDL_DFB_CHECKERR(destsurf->DrawRectangle(destsurf, rects[i]->x, rects[i]->y, - rects[i]->w, rects[i]->h)); + destsurf->GetClip(destsurf, &clip_region); + for (i=0; i<count; i++) { + SDL_Rect dst = {rects[i]->x, rects[i]->y, rects[i]->w, rects[i]->h}; + dst.x += clip_region.x1; + dst.y += clip_region.y1; + SDL_DFB_CHECKERR(destsurf->DrawRectangle(destsurf, dst.x, dst.y, + dst.w, dst.h)); + } return 0; error: @@ -977,19 +1022,25 @@ DirectFB_RenderDrawRects(SDL_Renderer * renderer, const SDL_Rect ** rects, int c } static int -DirectFB_RenderFillRects(SDL_Renderer * renderer, const SDL_Rect * rects, int count) +DirectFB_RenderFillRects(SDL_Renderer * renderer, const SDL_FRect * rects, int count) { DirectFB_RenderData *data = (DirectFB_RenderData *) renderer->driverdata; - IDirectFBSurface *destsurf = get_dfb_surface(data->window); + IDirectFBSurface *destsurf = data->target; + DFBRegion clip_region; int i; DirectFB_ActivateRenderer(renderer); PrepareDraw(renderer); - for (i=0; i<count; i++) - SDL_DFB_CHECKERR(destsurf->FillRectangle(destsurf, rects[i].x, rects[i].y, - rects[i].w, rects[i].h)); + destsurf->GetClip(destsurf, &clip_region); + for (i=0; i<count; i++) { + SDL_Rect dst = {rects[i].x, rects[i].y, rects[i].w, rects[i].h}; + dst.x += clip_region.x1; + dst.y += clip_region.y1; + SDL_DFB_CHECKERR(destsurf->FillRectangle(destsurf, dst.x, dst.y, + dst.w, dst.h)); + } return 0; error: @@ -998,40 +1049,46 @@ DirectFB_RenderFillRects(SDL_Renderer * renderer, const SDL_Rect * rects, int co static int DirectFB_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture, - const SDL_Rect * srcrect, const SDL_Rect * dstrect) + const SDL_Rect * srcrect, const SDL_FRect * dstrect) { DirectFB_RenderData *data = (DirectFB_RenderData *) renderer->driverdata; - IDirectFBSurface *destsurf = get_dfb_surface(data->window); + IDirectFBSurface *destsurf = data->target; DirectFB_TextureData *texturedata = (DirectFB_TextureData *) texture->driverdata; Uint8 alpha, r, g, b; + DFBRegion clip_region; + DFBRectangle sr, dr; DirectFB_ActivateRenderer(renderer); + SDLtoDFBRect(srcrect, &sr); + SDLtoDFBRect_Float(dstrect, &dr); + + destsurf->GetClip(destsurf, &clip_region); + dr.x += clip_region.x1; + dr.y += clip_region.y1; + if (texturedata->display) { int px, py; SDL_Window *window = renderer->window; - IDirectFBWindow *dfbwin = get_dfb_window(window); + IDirectFBWindow *dfbwin = get_dfb_window(window); SDL_DFB_WINDOWDATA(window); SDL_VideoDisplay *display = texturedata->display; DFB_DisplayData *dispdata = (DFB_DisplayData *) display->driverdata; SDL_DFB_CHECKERR(dispdata-> vidlayer->SetSourceRectangle(dispdata->vidlayer, - srcrect->x, srcrect->y, - srcrect->w, - srcrect->h)); + sr.x, sr.y, sr.w, sr.h)); dfbwin->GetPosition(dfbwin, &px, &py); px += windata->client.x; py += windata->client.y; SDL_DFB_CHECKERR(dispdata-> vidlayer->SetScreenRectangle(dispdata->vidlayer, - px + dstrect->x, - py + dstrect->y, - dstrect->w, - dstrect->h)); + px + dr.x, + py + dr.y, + dr.w, + dr.h)); } else { - DFBRectangle sr, dr; DFBSurfaceBlittingFlags flags = 0; #if 0 @@ -1065,14 +1122,11 @@ DirectFB_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture, DirectFB_UpdateTexture(renderer, texture, &rect, texturedata->pixels, texturedata->pitch); } - SDLtoDFBRect(srcrect, &sr); - SDLtoDFBRect(dstrect, &dr); - alpha = r = g = b = 0xff; - if (texture->modMode & SDL_TEXTUREMODULATE_ALPHA){ - alpha = texture->a; - flags |= DSBLIT_BLEND_COLORALPHA; - } + if (texture->modMode & SDL_TEXTUREMODULATE_ALPHA){ + alpha = texture->a; + flags |= DSBLIT_BLEND_COLORALPHA; + } if (texture->modMode & SDL_TEXTUREMODULATE_COLOR) { r = texture->r; @@ -1176,7 +1230,6 @@ DirectFB_DestroyRenderer(SDL_Renderer * renderer) { DirectFB_RenderData *data = (DirectFB_RenderData *) renderer->driverdata; SDL_VideoDisplay *display = SDL_GetDisplayForWindow(data->window); - #if 0 if (display->palette) { SDL_DelPaletteWatch(display->palette, DisplayPaletteChanged, data); @@ -1192,15 +1245,16 @@ DirectFB_DestroyRenderer(SDL_Renderer * renderer) static int DirectFB_UpdateViewport(SDL_Renderer * renderer) { - IDirectFBSurface *winsurf = get_dfb_surface(renderer->window); - DFBRegion dreg; + DirectFB_RenderData *data = (DirectFB_RenderData *) renderer->driverdata; + IDirectFBSurface *winsurf = data->target; + DFBRegion dreg; - dreg.x1 = renderer->viewport.x; - dreg.y1 = renderer->viewport.y; - dreg.x2 = dreg.x1 + renderer->viewport.w - 1; - dreg.y2 = dreg.y1 + renderer->viewport.h - 1; + dreg.x1 = renderer->viewport.x; + dreg.y1 = renderer->viewport.y; + dreg.x2 = dreg.x1 + renderer->viewport.w - 1; + dreg.y2 = dreg.y1 + renderer->viewport.h - 1; - winsurf->SetClip(winsurf, &dreg); + winsurf->SetClip(winsurf, &dreg); return 0; } @@ -1209,24 +1263,25 @@ DirectFB_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect, Uint32 format, void * pixels, int pitch) { Uint32 sdl_format; - void * laypixels; - int laypitch; - DFBSurfacePixelFormat dfb_format; - IDirectFBSurface *winsurf = get_dfb_surface(renderer->window); + void * laypixels; + int laypitch; + DFBSurfacePixelFormat dfb_format; + DirectFB_RenderData *data = (DirectFB_RenderData *) renderer->driverdata; + IDirectFBSurface *winsurf = data->target; DirectFB_ActivateRenderer(renderer); winsurf->GetPixelFormat(winsurf, &dfb_format); sdl_format = DirectFB_DFBToSDLPixelFormat(dfb_format); winsurf->Lock(winsurf, DSLF_READ, (void **) &laypixels, &laypitch); - + laypixels += (rect->y * laypitch + rect->x * SDL_BYTESPERPIXEL(sdl_format) ); SDL_ConvertPixels(rect->w, rect->h, sdl_format, laypixels, laypitch, format, pixels, pitch); winsurf->Unlock(winsurf); - + return 0; } @@ -1238,15 +1293,15 @@ DirectFB_RenderWritePixels(SDL_Renderer * renderer, const SDL_Rect * rect, SDL_Window *window = renderer->window; SDL_DFB_WINDOWDATA(window); Uint32 sdl_format; - void * laypixels; - int laypitch; - DFBSurfacePixelFormat dfb_format; + void * laypixels; + int laypitch; + DFBSurfacePixelFormat dfb_format; SDL_DFB_CHECK(windata->surface->GetPixelFormat(windata->surface, &dfb_format)); sdl_format = DirectFB_DFBToSDLPixelFormat(dfb_format); SDL_DFB_CHECK(windata->surface->Lock(windata->surface, DSLF_WRITE, (void **) &laypixels, &laypitch)); - + laypixels += (rect->y * laypitch + rect->x * SDL_BYTESPERPIXEL(sdl_format) ); SDL_ConvertPixels(rect->w, rect->h, format, pixels, pitch, diff --git a/src/video/directfb/SDL_DirectFB_video.c b/src/video/directfb/SDL_DirectFB_video.c index 71f014b06c..3f9bba2ba5 100644 --- a/src/video/directfb/SDL_DirectFB_video.c +++ b/src/video/directfb/SDL_DirectFB_video.c @@ -102,8 +102,9 @@ DirectFB_CreateDevice(int devindex) { SDL_VideoDevice *device; - if (!SDL_DirectFB_LoadLibrary()) + if (!SDL_DirectFB_LoadLibrary()) { return NULL; + } /* Initialize all variables that we clean on shutdown */ SDL_DFB_ALLOC_CLEAR(device, sizeof(SDL_VideoDevice)); diff --git a/src/video/directfb/SDL_DirectFB_video.h b/src/video/directfb/SDL_DirectFB_video.h index 1923eadefe..4980f7a5c8 100644 --- a/src/video/directfb/SDL_DirectFB_video.h +++ b/src/video/directfb/SDL_DirectFB_video.h @@ -31,6 +31,8 @@ #include "SDL_scancode.h" #include "SDL_render.h" +#include "SDL_log.h" + #define DFB_VERSIONNUM(X, Y, Z) \ ((X)*1000 + (Y)*100 + (Z)) @@ -66,7 +68,6 @@ #endif #define DIRECTFB_DEBUG 1 -#define LOG_CHANNEL stdout #define DFBENV_USE_YUV_UNDERLAY "SDL_DIRECTFB_YUV_UNDERLAY" /* Default: off */ #define DFBENV_USE_YUV_DIRECT "SDL_DIRECTFB_YUV_DIRECT" /* Default: off */ @@ -80,23 +81,12 @@ #define SDL_DFB_CONTEXT "SDL_DirectFB" -#define SDL_DFB_ERR(x...) \ - do { \ - fprintf(LOG_CHANNEL, "%s: %s <%d>:\n\t", \ - SDL_DFB_CONTEXT, __FILE__, __LINE__ ); \ - fprintf(LOG_CHANNEL, x ); \ - } while (0) +#define SDL_DFB_ERR(x...) SDL_LogError(SDL_LOG_CATEGORY_ERROR, x) #if (DIRECTFB_DEBUG) +#define SDL_DFB_LOG(x...) SDL_LogInfo(SDL_LOG_CATEGORY_VIDEO, x) -#define SDL_DFB_LOG(x...) \ - do { \ - fprintf(LOG_CHANNEL, "%s: ", SDL_DFB_CONTEXT); \ - fprintf(LOG_CHANNEL, x ); \ - fprintf(LOG_CHANNEL, "\n"); \ - } while (0) - -#define SDL_DFB_DEBUG(x...) SDL_DFB_ERR( x ) +#define SDL_DFB_DEBUG(x...) SDL_LogDebug(SDL_LOG_CATEGORY_VIDEO, x) static inline DFBResult sdl_dfb_check(DFBResult ret, const char *src_file, int src_line) { if (ret != DFB_OK) { diff --git a/src/video/directfb/SDL_DirectFB_window.c b/src/video/directfb/SDL_DirectFB_window.c index 4fc712cfe4..1ba4cfe601 100644 --- a/src/video/directfb/SDL_DirectFB_window.c +++ b/src/video/directfb/SDL_DirectFB_window.c @@ -47,6 +47,7 @@ DirectFB_CreateWindow(_THIS, SDL_Window * window) int bshaped = 0; SDL_DFB_ALLOC_CLEAR(window->driverdata, sizeof(DFB_WindowData)); + SDL_memset(&desc, 0, sizeof(DFBWindowDescription)); windata = (DFB_WindowData *) window->driverdata; windata->is_managed = devdata->has_own_wm; @@ -89,7 +90,12 @@ DirectFB_CreateWindow(_THIS, SDL_Window * window) desc.height = windata->size.h; desc.pixelformat = dispdata->pixelformat; desc.surface_caps = DSCAPS_PREMULTIPLIED; - +#if DIRECTFB_MAJOR_VERSION == 1 && DIRECTFB_MINOR_VERSION >= 4 + if (window->flags & SDL_WINDOW_OPENGL) { + desc.surface_caps |= DSCAPS_GL; + } +#endif + /* Create the window. */ SDL_DFB_CHECKERR(dispdata->layer->CreateWindow(dispdata->layer, &desc, &windata->dfbwin)); @@ -170,8 +176,7 @@ DirectFB_CreateWindow(_THIS, SDL_Window * window) int DirectFB_CreateWindowFrom(_THIS, SDL_Window * window, const void *data) { - SDL_Unsupported(); - return -1; + return SDL_Unsupported(); } void @@ -182,8 +187,9 @@ DirectFB_SetWindowTitle(_THIS, SDL_Window * window) if (windata->is_managed) { windata->wm_needs_redraw = 1; DirectFB_WM_RedrawLayout(_this, window); - } else + } else { SDL_Unsupported(); + } } void @@ -378,7 +384,7 @@ DirectFB_RestoreWindow(_THIS, SDL_Window * window) } void -DirectFB_SetWindowGrab(_THIS, SDL_Window * window) +DirectFB_SetWindowGrab(_THIS, SDL_Window * window, SDL_bool grabbed) { SDL_DFB_DEVICEDATA(_this); SDL_DFB_WINDOWDATA(window); diff --git a/src/video/directfb/SDL_DirectFB_window.h b/src/video/directfb/SDL_DirectFB_window.h index 4cbbdc0d7b..43a08d3087 100644 --- a/src/video/directfb/SDL_DirectFB_window.h +++ b/src/video/directfb/SDL_DirectFB_window.h @@ -69,7 +69,7 @@ extern void DirectFB_RaiseWindow(_THIS, SDL_Window * window); extern void DirectFB_MaximizeWindow(_THIS, SDL_Window * window); extern void DirectFB_MinimizeWindow(_THIS, SDL_Window * window); extern void DirectFB_RestoreWindow(_THIS, SDL_Window * window); -extern void DirectFB_SetWindowGrab(_THIS, SDL_Window * window); +extern void DirectFB_SetWindowGrab(_THIS, SDL_Window * window, SDL_bool grabbed); extern void DirectFB_DestroyWindow(_THIS, SDL_Window * window); extern SDL_bool DirectFB_GetWindowWMInfo(_THIS, SDL_Window * window, struct SDL_SysWMinfo *info); diff --git a/src/video/dummy/SDL_nullframebuffer.c b/src/video/dummy/SDL_nullframebuffer.c index afcdfb807b..f3904918a8 100644 --- a/src/video/dummy/SDL_nullframebuffer.c +++ b/src/video/dummy/SDL_nullframebuffer.c @@ -58,15 +58,14 @@ int SDL_DUMMY_CreateWindowFramebuffer(_THIS, SDL_Window * window, Uint32 * forma return 0; } -int SDL_DUMMY_UpdateWindowFramebuffer(_THIS, SDL_Window * window, SDL_Rect * rects, int numrects) +int SDL_DUMMY_UpdateWindowFramebuffer(_THIS, SDL_Window * window, const SDL_Rect * rects, int numrects) { static int frame_number; SDL_Surface *surface; surface = (SDL_Surface *) SDL_GetWindowData(window, DUMMY_SURFACE); if (!surface) { - SDL_SetError("Couldn't find dummy surface for window"); - return -1; + return SDL_SetError("Couldn't find dummy surface for window"); } /* Send the data to the display */ diff --git a/src/video/dummy/SDL_nullframebuffer_c.h b/src/video/dummy/SDL_nullframebuffer_c.h index a7a2a1c160..57dd2adbc9 100644 --- a/src/video/dummy/SDL_nullframebuffer_c.h +++ b/src/video/dummy/SDL_nullframebuffer_c.h @@ -21,7 +21,7 @@ #include "SDL_config.h" extern int SDL_DUMMY_CreateWindowFramebuffer(_THIS, SDL_Window * window, Uint32 * format, void ** pixels, int *pitch); -extern int SDL_DUMMY_UpdateWindowFramebuffer(_THIS, SDL_Window * window, SDL_Rect * rects, int numrects); +extern int SDL_DUMMY_UpdateWindowFramebuffer(_THIS, SDL_Window * window, const SDL_Rect * rects, int numrects); extern void SDL_DUMMY_DestroyWindowFramebuffer(_THIS, SDL_Window * window); /* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/video/nds/SDL_ndsevents.c b/src/video/nds/SDL_ndsevents.c deleted file mode 100644 index 8132aae23b..0000000000 --- a/src/video/nds/SDL_ndsevents.c +++ /dev/null @@ -1,54 +0,0 @@ -/* - Simple DirectMedia Layer - Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org> - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. -*/ -#include "SDL_config.h" - -#if SDL_VIDEO_DRIVER_NDS - -#include <stdio.h> -#include <stdlib.h> -#include <nds.h> - -#include "../../events/SDL_events_c.h" - -#include "SDL_ndsvideo.h" -#include "SDL_ndsevents_c.h" - -void -NDS_PumpEvents(_THIS) -{ - scanKeys(); - /* TODO: defer click-age */ - if (keysDown() & KEY_TOUCH) { - SDL_SendMouseButton(0, SDL_PRESSED, 0); - } else if (keysUp() & KEY_TOUCH) { - SDL_SendMouseButton(0, SDL_RELEASED, 0); - } - if (keysHeld() & KEY_TOUCH) { - touchPosition t; - - touchRead(&t); - SDL_SendMouseMotion(0, 0, t.px, t.py); - } -} - -#endif /* SDL_VIDEO_DRIVER_NDS */ - -/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/video/nds/SDL_ndsvideo.c b/src/video/nds/SDL_ndsvideo.c deleted file mode 100644 index 9fd412442d..0000000000 --- a/src/video/nds/SDL_ndsvideo.c +++ /dev/null @@ -1,401 +0,0 @@ -/* - Simple DirectMedia Layer - Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org> - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. -*/ -#include "SDL_config.h" - -#if SDL_VIDEO_DRIVER_NDS - -/* SDL Nintendo DS video driver implementation */ - -#include <stdio.h> -#include <stdlib.h> -#include <nds.h> -#include <fat.h> - -#include "SDL_video.h" -#include "SDL_ndsvideo.h" -#include "SDL_ndsevents_c.h" -#include "../../render/SDL_sysrender.h" -#include "../../render/nds/SDL_libgl2D.h" -#include "SDL_log.h" - -#define NDSVID_DRIVER_NAME "nds" - -static SDL_DisplayMode display_modes[] = -{ - /* Only one screen */ - { - .format = SDL_PIXELFORMAT_ABGR1555, - .w = SCREEN_WIDTH, - .h = SCREEN_HEIGHT, - .refresh_rate = 60, - }, - - /* Aggregated display (two screens) with no gap. */ - { - .format = SDL_PIXELFORMAT_ABGR1555, - .w = SCREEN_WIDTH, - .h = 2*SCREEN_HEIGHT+SCREEN_GAP, - .refresh_rate = 60, - }, - - /* Aggregated display (two screens) with a gap. */ - { - .format = SDL_PIXELFORMAT_ABGR1555, - .w = SCREEN_WIDTH, - .h = 2*SCREEN_HEIGHT, - .refresh_rate = 60, - }, - - /* Last entry */ - { - .w = 0, - } -}; - -/* This function must not be optimized nor inlined, else the pointer - * to the message will be in the wrong register, and the emulator won't - * find the string. */ -__attribute__ ((noinline, optimize (0))) -static void NDS_DebugOutput2(const char* message) -{ -#ifdef __thumb__ - asm volatile ("swi #0xfc"); -#else - asm volatile ("swi #0xfc0000"); -#endif -} - -static void NDS_DebugOutput(void *userdata, int category, SDL_LogPriority priority, const char *message) -{ - NDS_DebugOutput2(message); -} - -/* SDL NDS driver bootstrap functions */ -static int NDS_Available(void) -{ - return 1; /* always here */ -} - -#ifndef USE_HW_RENDERER -static int NDS_CreateWindowFramebuffer(_THIS, SDL_Window *window, - Uint32 *format, void **pixels, - int *pitch) -{ - struct NDS_WindowData *wdata; - int bpp; - Uint32 Rmask, Gmask, Bmask, Amask; - const SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window); - const SDL_DisplayMode *mode = display->driverdata; - const Uint32 fmt = mode->format; - - if (fmt != SDL_PIXELFORMAT_ABGR1555) { - SDL_SetError("Unsupported pixel format (%x)", fmt); - return -1; - } - - if (!SDL_PixelFormatEnumToMasks - (fmt, &bpp, &Rmask, &Gmask, &Bmask, &Amask)) { - SDL_SetError("Unknown texture format"); - return -1; - } - - wdata = SDL_calloc(1, sizeof(struct NDS_WindowData)); - if (!wdata) { - SDL_OutOfMemory(); - return -1; - } - - if (bpp == 8) { - wdata->pixels_length = (SCREEN_HEIGHT+SCREEN_GAP+SCREEN_HEIGHT)*SCREEN_WIDTH; - } else { - wdata->pixels_length = (SCREEN_HEIGHT+SCREEN_GAP+SCREEN_HEIGHT)*SCREEN_WIDTH*2; - } - wdata->pixels = SDL_calloc(1, wdata->pixels_length); - if (!wdata->pixels) { - SDL_free(wdata); - SDL_SetError("Not enough memory"); - return -1; - } - - if (bpp == 8) { - wdata->main.bg_id = bgInit(2, BgType_Bmp8, BgSize_B8_256x256, 0, 0); - wdata->sub.bg_id = bgInitSub(3, BgType_Bmp8, BgSize_B8_256x256, 0, 0); - - wdata->main.length = SCREEN_HEIGHT*SCREEN_WIDTH; - wdata->main.pixels = wdata->pixels; - - wdata->sub.length = SCREEN_HEIGHT*SCREEN_WIDTH; - wdata->sub.pixels = (u8 *)wdata->pixels + wdata->main.length; /* or ...+SCREEN_GAP */ - - } else { - wdata->main.bg_id = bgInit(2, BgType_Bmp16, BgSize_B16_256x256, 0, 0); - wdata->sub.bg_id = bgInitSub(3, BgType_Bmp16, BgSize_B16_256x256, 0, 0); - - wdata->main.length = SCREEN_HEIGHT*SCREEN_WIDTH*2; - wdata->main.pixels = wdata->pixels; - - wdata->sub.length = SCREEN_HEIGHT*SCREEN_WIDTH*2; - wdata->sub.pixels = (u8 *)wdata->pixels + wdata->main.length; /* or ...+SCREEN_GAP */ - } - - wdata->pitch = (window->w) * ((bpp+1) / 8); - wdata->bpp = bpp; - wdata->rotate = 0; - wdata->scale.x = 0x100; - wdata->scale.y = 0x100; - wdata->scroll.x = 0; - wdata->scroll.y = 0; - - wdata->main.vram_pixels = bgGetGfxPtr(wdata->main.bg_id); - wdata->sub.vram_pixels = bgGetGfxPtr(wdata->sub.bg_id); - -#if 0 - bgSetCenter(wdata->main.bg_id, 0, 0); - bgSetRotateScale(wdata->main.bg_id, wdata->rotate, wdata->scale.x, - wdata->scale.y); - bgSetScroll(wdata->main.bg_id, wdata->scroll.x, wdata->scroll.y); -#endif - -#if 0 - bgSetCenter(wdata->sub.bg_id, 0, 0); - bgSetRotateScale(wdata->sub.bg_id, wdata->rotate, wdata->scale.x, - wdata->scale.y); - bgSetScroll(wdata->sub.bg_id, wdata->scroll.x, wdata->scroll.y); -#endif - - bgUpdate(); - - *format = fmt; - *pixels = wdata->pixels; - *pitch = wdata->pitch; - - window->driverdata = wdata; - - return 0; -} - -static int NDS_UpdateWindowFramebuffer(_THIS, SDL_Window * window, - SDL_Rect * rects, int numrects) -{ - struct NDS_WindowData *wdata = window->driverdata; - - /* Copy everything. TODO: use rects/numrects. */ - DC_FlushRange(wdata->pixels, wdata->pixels_length); - - swiWaitForVBlank(); - - dmaCopy(wdata->main.pixels, wdata->main.vram_pixels, wdata->main.length); - dmaCopy(wdata->sub.pixels, wdata->sub.vram_pixels, wdata->sub.length); - - return 0; -} - -static void NDS_DestroyWindowFramebuffer(_THIS, SDL_Window *window) -{ - struct NDS_WindowData *wdata = window->driverdata; - - SDL_free(wdata->pixels); - SDL_free(wdata); -} -#endif - -#ifdef USE_HW_RENDERER -/* Set up a 2D layer construced of bitmap sprites. This holds the - * image when rendering to the top screen. From libnds example. - */ -static void initSubSprites(void) -{ - oamInit(&oamSub, SpriteMapping_Bmp_2D_256, false); - - int x = 0; - int y = 0; - - int id = 0; - - //set up a 4x3 grid of 64x64 sprites to cover the screen - for(y = 0; y < 3; y++) - for(x = 0; x < 4; x++) - { - oamSub.oamMemory[id].attribute[0] = ATTR0_BMP | ATTR0_SQUARE | (64 * y); - oamSub.oamMemory[id].attribute[1] = ATTR1_SIZE_64 | (64 * x); - oamSub.oamMemory[id].attribute[2] = ATTR2_ALPHA(1) | (8 * 32 * y) | (8 * x); - id++; - } - - swiWaitForVBlank(); - - oamUpdate(&oamSub); -} -#endif - -static int NDS_SetDisplayMode(_THIS, SDL_VideoDisplay *display, SDL_DisplayMode *mode) -{ - display->driverdata = mode->driverdata; - - powerOn(POWER_ALL_2D); - -#ifdef USE_HW_RENDERER - - videoSetMode(MODE_5_3D); - videoSetModeSub(MODE_5_2D); - - /* initialize gl2d */ - glScreen2D(); - glBegin2D(); - - vramSetBankA(VRAM_A_TEXTURE); - vramSetBankB(VRAM_B_TEXTURE ); - vramSetBankC(VRAM_C_SUB_BG_0x06200000); - vramSetBankE(VRAM_E_TEX_PALETTE); - - // sub sprites hold the bottom image when 3D directed to top - initSubSprites(); - - // sub background holds the top image when 3D directed to bottom - bgInitSub(3, BgType_Bmp16, BgSize_B16_256x256, 0, 0); -#else - - /* Select mode 5 for both screens. Can do Extended Rotation - * Background on both (BG 2 and 3). */ - videoSetMode(MODE_5_2D); - videoSetModeSub(MODE_5_2D); - - vramSetBankA(VRAM_A_MAIN_BG_0x06000000); - vramSetBankB(VRAM_B_TEXTURE ); - vramSetBankC(VRAM_C_SUB_BG_0x06200000); - vramSetBankE(VRAM_E_TEX_PALETTE); - -#endif - - return 0; -} - -void NDS_GetDisplayModes(_THIS, SDL_VideoDisplay * display) -{ - SDL_DisplayMode *mode; - - for (mode = display_modes; mode->w; mode++) { - mode->driverdata = mode; /* point back to self */ - SDL_AddDisplayMode(display, mode); - } -} - -static int NDS_VideoInit(_THIS) -{ - SDL_VideoDisplay display; - SDL_DisplayMode mode; - - SDL_zero(mode); - - mode.format = SDL_PIXELFORMAT_UNKNOWN; // should be SDL_PIXELFORMAT_ABGR1555; - mode.w = SCREEN_WIDTH; - mode.h = 2*SCREEN_HEIGHT+SCREEN_GAP; - mode.refresh_rate = 60; - - SDL_zero(display); - - display.desktop_mode = mode; - - SDL_AddVideoDisplay(&display); - - return 0; -} - -static void NDS_VideoQuit(_THIS) -{ - videoSetMode(DISPLAY_SCREEN_OFF); - videoSetModeSub(DISPLAY_SCREEN_OFF); - vramSetBankA(VRAM_A_LCD); - vramSetBankB(VRAM_B_LCD); - vramSetBankC(VRAM_C_LCD); - vramSetBankD(VRAM_D_LCD); - vramSetBankE(VRAM_E_LCD); - vramSetBankF(VRAM_F_LCD); - vramSetBankG(VRAM_G_LCD); - vramSetBankH(VRAM_H_LCD); - vramSetBankI(VRAM_I_LCD); -} - -static void NDS_DeleteDevice(SDL_VideoDevice * device) -{ - SDL_free(device); -} - -static SDL_VideoDevice *NDS_CreateDevice(int devindex) -{ - SDL_VideoDevice *device; - - fatInitDefault(); - - /* Initialize all variables that we clean on shutdown */ - device = SDL_calloc(1, sizeof(SDL_VideoDevice)); - if (!device) { - SDL_OutOfMemory(); - return NULL; - } - - device->driverdata = SDL_calloc(1, sizeof(SDL_VideoDevice)); - if (!device) { - SDL_free(device); - SDL_OutOfMemory(); - return NULL; - } - - /* Set the function pointers */ - device->VideoInit = NDS_VideoInit; - device->VideoQuit = NDS_VideoQuit; - device->GetDisplayModes = NDS_GetDisplayModes; - device->SetDisplayMode = NDS_SetDisplayMode; - device->CreateWindow = NDS_CreateWindow; -#ifndef USE_HW_RENDERER - device->CreateWindowFramebuffer = NDS_CreateWindowFramebuffer; - device->UpdateWindowFramebuffer = NDS_UpdateWindowFramebuffer; - device->DestroyWindowFramebuffer = NDS_DestroyWindowFramebuffer; -#endif - device->PumpEvents = NDS_PumpEvents; - device->free = NDS_DeleteDevice; - - /* Set the debug output. Use only under an emulator. Will crash the DS. */ -#if 0 - SDL_LogSetOutputFunction(NDS_DebugOutput, NULL); -#endif - - return device; -} - -VideoBootStrap NDS_bootstrap = { - NDSVID_DRIVER_NAME, "SDL NDS video driver", - NDS_Available, NDS_CreateDevice -}; - -double SDLCALL SDL_pow(double x, double y) -{ - static int once = 1; - if (once) { - SDL_Log("SDL_pow called but not supported on this platform"); - once = 0; - } - return 0; -} - -#endif /* SDL_VIDEO_DRIVER_NDS */ - -/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/video/nds/SDL_ndsvideo.h b/src/video/nds/SDL_ndsvideo.h deleted file mode 100644 index d0795c064b..0000000000 --- a/src/video/nds/SDL_ndsvideo.h +++ /dev/null @@ -1,59 +0,0 @@ -/* - Simple DirectMedia Layer - Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org> - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. -*/ -#include "SDL_config.h" - -#ifndef _SDL_ndsvideo_h -#define _SDL_ndsvideo_h - -#include "../SDL_sysvideo.h" - -#include "SDL_ndswindow.h" - -#define SCREEN_GAP 92 /* line-equivalent gap between the 2 screens */ - -/* Per Window information. */ -struct NDS_WindowData { - struct { - int bg_id; - void *vram_pixels; /* where the pixel data is stored (a pointer into VRAM) */ - void *pixels; /* area in user frame buffer */ - int length; - } main, sub; - - int pitch, bpp; /* useful information about the texture */ - struct { - int x, y; - } scale; /* x/y stretch (24.8 fixed point) */ - - struct { - int x, y; - } scroll; /* x/y offset */ - int rotate; /* -32768 to 32767, texture rotation */ - - /* user frame buffer - todo: better way to do double buffering */ - void *pixels; - int pixels_length; -}; - - -#endif /* _SDL_ndsvideo_h */ - -/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/video/nds/SDL_ndswindow.c b/src/video/nds/SDL_ndswindow.c deleted file mode 100644 index a76c08f05e..0000000000 --- a/src/video/nds/SDL_ndswindow.c +++ /dev/null @@ -1,37 +0,0 @@ -/* - Simple DirectMedia Layer - Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org> - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. -*/ -#include "SDL_config.h" - -#if SDL_VIDEO_DRIVER_NDS - -#include "SDL_ndsvideo.h" - - -int NDS_CreateWindow(_THIS, SDL_Window * window) -{ - /* Nintendo DS windows are always fullscreen */ - window->flags |= SDL_WINDOW_FULLSCREEN; - return 0; -} - -#endif /* SDL_VIDEO_DRIVER_NDS */ - -/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/video/pandora/SDL_pandora.c b/src/video/pandora/SDL_pandora.c index 660648beb3..77d12b79cb 100644 --- a/src/video/pandora/SDL_pandora.c +++ b/src/video/pandora/SDL_pandora.c @@ -211,8 +211,7 @@ PND_createwindow(_THIS, SDL_Window * window) /* Allocate window internal data */ wdata = (SDL_WindowData *) SDL_calloc(1, sizeof(SDL_WindowData)); if (wdata == NULL) { - SDL_OutOfMemory(); - return -1; + return SDL_OutOfMemory(); } /* Setup driver data for this window */ @@ -230,14 +229,12 @@ PND_createwindow(_THIS, SDL_Window * window) if (phdata->egl_display == EGL_NO_DISPLAY) { phdata->egl_display = eglGetDisplay((NativeDisplayType) 0); if (phdata->egl_display == EGL_NO_DISPLAY) { - SDL_SetError("PND: Can't get connection to OpenGL ES"); - return -1; + return SDL_SetError("PND: Can't get connection to OpenGL ES"); } initstatus = eglInitialize(phdata->egl_display, NULL, NULL); if (initstatus != EGL_TRUE) { - SDL_SetError("PND: Can't init OpenGL ES library"); - return -1; + return SDL_SetError("PND: Can't init OpenGL ES library"); } } @@ -356,8 +353,7 @@ PND_gl_loadlibrary(_THIS, const char *path) _this->gl_config.dll_handle = SDL_LoadObject(path); if (!_this->gl_config.dll_handle) { /* Failed to load new GL ES library */ - SDL_SetError("PND: Failed to locate OpenGL ES library"); - return -1; + return SDL_SetError("PND: Failed to locate OpenGL ES library"); } /* Store OpenGL ES library path and name */ @@ -726,8 +722,7 @@ PND_gl_makecurrent(_THIS, SDL_Window * window, SDL_GLContext context) EGLBoolean status; if (phdata->egl_initialized != SDL_TRUE) { - SDL_SetError("PND: GF initialization failed, no OpenGL ES support"); - return -1; + return SDL_SetError("PND: GF initialization failed, no OpenGL ES support"); } if ((window == NULL) && (context == NULL)) { @@ -736,33 +731,28 @@ PND_gl_makecurrent(_THIS, SDL_Window * window, SDL_GLContext context) EGL_NO_SURFACE, EGL_NO_CONTEXT); if (status != EGL_TRUE) { /* Failed to set current GL ES context */ - SDL_SetError("PND: Can't set OpenGL ES context"); - return -1; + return SDL_SetError("PND: Can't set OpenGL ES context"); } } else { wdata = (SDL_WindowData *) window->driverdata; if (wdata->gles_surface == EGL_NO_SURFACE) { - SDL_SetError + return SDL_SetError ("PND: OpenGL ES surface is not initialized for this window"); - return -1; } if (wdata->gles_context == EGL_NO_CONTEXT) { - SDL_SetError + return SDL_SetError ("PND: OpenGL ES context is not initialized for this window"); - return -1; } if (wdata->gles_context != context) { - SDL_SetError + return SDL_SetError ("PND: OpenGL ES context is not belong to this window"); - return -1; } status = eglMakeCurrent(phdata->egl_display, wdata->gles_surface, wdata->gles_surface, wdata->gles_context); if (status != EGL_TRUE) { /* Failed to set current GL ES context */ - SDL_SetError("PND: Can't set OpenGL ES context"); - return -1; + return SDL_SetError("PND: Can't set OpenGL ES context"); } } return 0; @@ -775,8 +765,7 @@ PND_gl_setswapinterval(_THIS, int interval) EGLBoolean status; if (phdata->egl_initialized != SDL_TRUE) { - SDL_SetError("PND: EGL initialization failed, no OpenGL ES support"); - return -1; + return SDL_SetError("PND: EGL initialization failed, no OpenGL ES support"); } /* Check if OpenGL ES connection has been initialized */ @@ -791,8 +780,7 @@ PND_gl_setswapinterval(_THIS, int interval) } /* Failed to set swap interval */ - SDL_SetError("PND: Cannot set swap interval"); - return -1; + return SDL_SetError("PND: Cannot set swap interval"); } int diff --git a/src/video/psp/SDL_pspevents.c b/src/video/psp/SDL_pspevents.c new file mode 100644 index 0000000000..e418daae28 --- /dev/null +++ b/src/video/psp/SDL_pspevents.c @@ -0,0 +1,284 @@ +/* + Simple DirectMedia Layer + Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org> + + This software is provided 'as-is', without any express or implied + warranty. In no event will the authors be held liable for any damages + arising from the use of this software. + + Permission is granted to anyone to use this software for any purpose, + including commercial applications, and to alter it and redistribute it + freely, subject to the following restrictions: + + 1. The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original software. + 3. This notice may not be removed or altered from any source distribution. +*/ + +/* Being a null driver, there's no event stream. We just define stubs for + most of the API. */ + +#include "SDL.h" +#include "../../events/SDL_sysevents.h" +#include "../../events/SDL_events_c.h" +#include "../../events/SDL_keyboard_c.h" +#include "SDL_pspvideo.h" +#include "SDL_pspevents_c.h" +#include "SDL_thread.h" +#include "SDL_keyboard.h" +#include <psphprm.h> + +#ifdef PSPIRKEYB +#include <pspirkeyb.h> +#include <pspirkeyb_rawkeys.h> + +#define IRKBD_CONFIG_FILE NULL /* this will take ms0:/seplugins/pspirkeyb.ini */ + +static int irkbd_ready = 0; +static SDLKey keymap[256]; +#endif + +static enum PspHprmKeys hprm = 0; +static SDL_sem *event_sem = NULL; +static SDL_Thread *thread = NULL; +static int running = 0; +static struct { + enum PspHprmKeys id; + SDL_Keycode sym; +} keymap_psp[] = { + { PSP_HPRM_PLAYPAUSE, SDLK_F10 }, + { PSP_HPRM_FORWARD, SDLK_F11 }, + { PSP_HPRM_BACK, SDLK_F12 }, + { PSP_HPRM_VOL_UP, SDLK_F13 }, + { PSP_HPRM_VOL_DOWN, SDLK_F14 }, + { PSP_HPRM_HOLD, SDLK_F15 } +}; + +int EventUpdate(void *data) +{ + while (running) { + SDL_SemWait(event_sem); + sceHprmPeekCurrentKey(&hprm); + SDL_SemPost(event_sem); + /* Delay 1/60th of a second */ + sceKernelDelayThread(1000000 / 60); + } + return 0; +} + +void PSP_PumpEvents(_THIS) +{ + int i; + enum PspHprmKeys keys; + enum PspHprmKeys changed; + static enum PspHprmKeys old_keys = 0; + SDL_Keysym sym; + + SDL_SemWait(event_sem); + keys = hprm; + SDL_SemPost(event_sem); + + /* HPRM Keyboard */ + changed = old_keys ^ keys; + old_keys = keys; + if(changed) { + for(i=0; i<sizeof(keymap_psp)/sizeof(keymap_psp[0]); i++) { + if(changed & keymap_psp[i].id) { + sym.scancode = keymap_psp[i].id; + sym.sym = keymap_psp[i].sym; + + /* out of date + SDL_PrivateKeyboard((keys & keymap_psp[i].id) ? + SDL_PRESSED : SDL_RELEASED, + &sym); + */ + SDL_SendKeyboardKey((keys & keymap_psp[i].id) ? + SDL_PRESSED : SDL_RELEASED, SDL_GetScancodeFromKey(keymap_psp[i].sym)); + } + } + } + +#ifdef PSPIRKEYB + if (irkbd_ready) { + unsigned char buffer[255]; + int i, length, count; + SIrKeybScanCodeData *scanData; + + if(pspIrKeybReadinput(buffer, &length) >= 0) { + if((length % sizeof(SIrKeybScanCodeData)) == 0){ + count = length / sizeof(SIrKeybScanCodeData); + for( i=0; i < count; i++ ) { + unsigned char raw, pressed; + scanData=(SIrKeybScanCodeData*) buffer+i; + raw = scanData->raw; + pressed = scanData->pressed; + sym.scancode = raw; + sym.sym = keymap[raw]; + /* not tested*/ + //SDL_PrivateKeyboard(pressed?SDL_PRESSED:SDL_RELEASED, &sym); + SDL_SendKeyboardKey((keys & keymap_psp[i].id) ? + SDL_PRESSED : SDL_RELEASED, SDL_GetScancodeFromKey(keymap[raw]); + + } + } + } + } +#endif + sceKernelDelayThread(0); + + return; +} + +void PSP_InitOSKeymap(_THIS) +{ +#ifdef PSPIRKEYB + int i; + for (i=0; i<SDL_TABLESIZE(keymap); ++i) + keymap[i] = SDLK_UNKNOWN; + + keymap[KEY_ESC] = SDLK_ESCAPE; + + keymap[KEY_F1] = SDLK_F1; + keymap[KEY_F2] = SDLK_F2; + keymap[KEY_F3] = SDLK_F3; + keymap[KEY_F4] = SDLK_F4; + keymap[KEY_F5] = SDLK_F5; + keymap[KEY_F6] = SDLK_F6; + keymap[KEY_F7] = SDLK_F7; + keymap[KEY_F8] = SDLK_F8; + keymap[KEY_F9] = SDLK_F9; + keymap[KEY_F10] = SDLK_F10; + keymap[KEY_F11] = SDLK_F11; + keymap[KEY_F12] = SDLK_F12; + keymap[KEY_F13] = SDLK_PRINT; + keymap[KEY_F14] = SDLK_PAUSE; + + keymap[KEY_GRAVE] = SDLK_BACKQUOTE; + keymap[KEY_1] = SDLK_1; + keymap[KEY_2] = SDLK_2; + keymap[KEY_3] = SDLK_3; + keymap[KEY_4] = SDLK_4; + keymap[KEY_5] = SDLK_5; + keymap[KEY_6] = SDLK_6; + keymap[KEY_7] = SDLK_7; + keymap[KEY_8] = SDLK_8; + keymap[KEY_9] = SDLK_9; + keymap[KEY_0] = SDLK_0; + keymap[KEY_MINUS] = SDLK_MINUS; + keymap[KEY_EQUAL] = SDLK_EQUALS; + keymap[KEY_BACKSPACE] = SDLK_BACKSPACE; + + keymap[KEY_TAB] = SDLK_TAB; + keymap[KEY_Q] = SDLK_q; + keymap[KEY_W] = SDLK_w; + keymap[KEY_E] = SDLK_e; + keymap[KEY_R] = SDLK_r; + keymap[KEY_T] = SDLK_t; + keymap[KEY_Y] = SDLK_y; + keymap[KEY_U] = SDLK_u; + keymap[KEY_I] = SDLK_i; + keymap[KEY_O] = SDLK_o; + keymap[KEY_P] = SDLK_p; + keymap[KEY_LEFTBRACE] = SDLK_LEFTBRACKET; + keymap[KEY_RIGHTBRACE] = SDLK_RIGHTBRACKET; + keymap[KEY_ENTER] = SDLK_RETURN; + + keymap[KEY_CAPSLOCK] = SDLK_CAPSLOCK; + keymap[KEY_A] = SDLK_a; + keymap[KEY_S] = SDLK_s; + keymap[KEY_D] = SDLK_d; + keymap[KEY_F] = SDLK_f; + keymap[KEY_G] = SDLK_g; + keymap[KEY_H] = SDLK_h; + keymap[KEY_J] = SDLK_j; + keymap[KEY_K] = SDLK_k; + keymap[KEY_L] = SDLK_l; + keymap[KEY_SEMICOLON] = SDLK_SEMICOLON; + keymap[KEY_APOSTROPHE] = SDLK_QUOTE; + keymap[KEY_BACKSLASH] = SDLK_BACKSLASH; + + keymap[KEY_Z] = SDLK_z; + keymap[KEY_X] = SDLK_x; + keymap[KEY_C] = SDLK_c; + keymap[KEY_V] = SDLK_v; + keymap[KEY_B] = SDLK_b; + keymap[KEY_N] = SDLK_n; + keymap[KEY_M] = SDLK_m; + keymap[KEY_COMMA] = SDLK_COMMA; + keymap[KEY_DOT] = SDLK_PERIOD; + keymap[KEY_SLASH] = SDLK_SLASH; + + keymap[KEY_SPACE] = SDLK_SPACE; + + keymap[KEY_UP] = SDLK_UP; + keymap[KEY_DOWN] = SDLK_DOWN; + keymap[KEY_LEFT] = SDLK_LEFT; + keymap[KEY_RIGHT] = SDLK_RIGHT; + + keymap[KEY_HOME] = SDLK_HOME; + keymap[KEY_END] = SDLK_END; + keymap[KEY_INSERT] = SDLK_INSERT; + keymap[KEY_DELETE] = SDLK_DELETE; + + keymap[KEY_NUMLOCK] = SDLK_NUMLOCK; + keymap[KEY_LEFTMETA] = SDLK_LSUPER; + + keymap[KEY_KPSLASH] = SDLK_KP_DIVIDE; + keymap[KEY_KPASTERISK] = SDLK_KP_MULTIPLY; + keymap[KEY_KPMINUS] = SDLK_KP_MINUS; + keymap[KEY_KPPLUS] = SDLK_KP_PLUS; + keymap[KEY_KPDOT] = SDLK_KP_PERIOD; + keymap[KEY_KPEQUAL] = SDLK_KP_EQUALS; + + keymap[KEY_LEFTCTRL] = SDLK_LCTRL; + keymap[KEY_RIGHTCTRL] = SDLK_RCTRL; + keymap[KEY_LEFTALT] = SDLK_LALT; + keymap[KEY_RIGHTALT] = SDLK_RALT; + keymap[KEY_LEFTSHIFT] = SDLK_LSHIFT; + keymap[KEY_RIGHTSHIFT] = SDLK_RSHIFT; +#endif +} + +void PSP_EventInit(_THIS) +{ +#ifdef PSPIRKEYB + int outputmode = PSP_IRKBD_OUTPUT_MODE_SCANCODE; + int ret = pspIrKeybInit(IRKBD_CONFIG_FILE, 0); + if (ret == PSP_IRKBD_RESULT_OK) { + pspIrKeybOutputMode(outputmode); + irkbd_ready = 1; + } else { + irkbd_ready = 0; + } +#endif + /* Start thread to read data */ + if((event_sem = SDL_CreateSemaphore(1)) == NULL) { + SDL_SetError("Can't create input semaphore\n"); + return; + } + running = 1; + if((thread = SDL_CreateThread(EventUpdate, "PSPInputThread",NULL)) == NULL) { + SDL_SetError("Can't create input thread\n"); + return; + } +} + +void PSP_EventQuit(_THIS) +{ + running = 0; + SDL_WaitThread(thread, NULL); + SDL_DestroySemaphore(event_sem); +#ifdef PSPIRKEYB + if (irkbd_ready) { + pspIrKeybFinish(); + irkbd_ready = 0; + } +#endif +} + +/* end of SDL_pspevents.c ... */ + diff --git a/src/video/nds/SDL_ndsevents_c.h b/src/video/psp/SDL_pspevents_c.h index 5c222a5989..c930487112 100644 --- a/src/video/nds/SDL_ndsevents_c.h +++ b/src/video/psp/SDL_pspevents_c.h @@ -18,10 +18,14 @@ misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ -#include "SDL_config.h" -#include "SDL_ndsvideo.h" +#include "SDL_pspvideo.h" -extern void NDS_PumpEvents(_THIS); +/* Variables and functions exported by SDL_sysevents.c to other parts + of the native video subsystem (SDL_sysvideo.c) +*/ +extern void PSP_InitOSKeymap(_THIS); +extern void PSP_PumpEvents(_THIS); + +/* end of SDL_pspevents_c.h ... */ -/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/video/psp/SDL_pspgl.c b/src/video/psp/SDL_pspgl.c new file mode 100644 index 0000000000..247496d969 --- /dev/null +++ b/src/video/psp/SDL_pspgl.c @@ -0,0 +1,205 @@ +/* + Simple DirectMedia Layer + Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org> + + This software is provided 'as-is', without any express or implied + warranty. In no event will the authors be held liable for any damages + arising from the use of this software. + + Permission is granted to anyone to use this software for any purpose, + including commercial applications, and to alter it and redistribute it + freely, subject to the following restrictions: + + 1. The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original software. + 3. This notice may not be removed or altered from any source distribution. +*/ + +#include <stdlib.h> +#include <string.h> + +#include "SDL_error.h" +#include "SDL_pspvideo.h" +#include "SDL_pspgl_c.h" + +/*****************************************************************************/ +/* SDL OpenGL/OpenGL ES functions */ +/*****************************************************************************/ +#define EGLCHK(stmt) \ + do { \ + EGLint err; \ + \ + stmt; \ + err = eglGetError(); \ + if (err != EGL_SUCCESS) { \ + SDL_SetError("EGL error %d", err); \ + return 0; \ + } \ + } while (0) + +int +PSP_GL_LoadLibrary(_THIS, const char *path) +{ + if (!_this->gl_config.driver_loaded) { + _this->gl_config.driver_loaded = 1; + } + + return 0; +} + +/* pspgl doesn't provide this call, so stub it out since SDL requires it. +#define GLSTUB(func,params) void func params {} + +GLSTUB(glOrtho,(GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, + GLdouble zNear, GLdouble zFar)) +*/ +void * +PSP_GL_GetProcAddress(_THIS, const char *proc) +{ + return eglGetProcAddress(proc); +} + +void +PSP_GL_UnloadLibrary(_THIS) +{ + eglTerminate(_this->gl_data->display); +} + +static EGLint width = 480; +static EGLint height = 272; + +SDL_GLContext +PSP_GL_CreateContext(_THIS, SDL_Window * window) +{ + + SDL_WindowData *wdata = (SDL_WindowData *) window->driverdata; + + EGLint attribs[32]; + EGLDisplay display; + EGLContext context; + EGLSurface surface; + EGLConfig config; + EGLint num_configs; + int i; + + + /* EGL init taken from glutCreateWindow() in PSPGL's glut.c. */ + EGLCHK(display = eglGetDisplay(0)); + EGLCHK(eglInitialize(display, NULL, NULL)); + wdata->uses_gles = SDL_TRUE; + window->flags |= SDL_WINDOW_FULLSCREEN; + + /* Setup the config based on SDL's current values. */ + i = 0; + attribs[i++] = EGL_RED_SIZE; + attribs[i++] = _this->gl_config.red_size; + attribs[i++] = EGL_GREEN_SIZE; + attribs[i++] = _this->gl_config.green_size; + attribs[i++] = EGL_BLUE_SIZE; + attribs[i++] = _this->gl_config.blue_size; + attribs[i++] = EGL_DEPTH_SIZE; + attribs[i++] = _this->gl_config.depth_size; + + if (_this->gl_config.alpha_size) + { + attribs[i++] = EGL_ALPHA_SIZE; + attribs[i++] = _this->gl_config.alpha_size; + } + if (_this->gl_config.stencil_size) + { + attribs[i++] = EGL_STENCIL_SIZE; + attribs[i++] = _this->gl_config.stencil_size; + } + + attribs[i++] = EGL_NONE; + + EGLCHK(eglChooseConfig(display, attribs, &config, 1, &num_configs)); + + if (num_configs == 0) + { + SDL_SetError("No valid EGL configs for requested mode"); + return 0; + } + + EGLCHK(eglGetConfigAttrib(display, config, EGL_WIDTH, &width)); + EGLCHK(eglGetConfigAttrib(display, config, EGL_HEIGHT, &height)); + + EGLCHK(context = eglCreateContext(display, config, NULL, NULL)); + EGLCHK(surface = eglCreateWindowSurface(display, config, 0, NULL)); + EGLCHK(eglMakeCurrent(display, surface, surface, context)); + + _this->gl_data->display = display; + _this->gl_data->context = context; + _this->gl_data->surface = surface; + + + return context; +} + +int +PSP_GL_MakeCurrent(_THIS, SDL_Window * window, SDL_GLContext context) +{ + if (!eglMakeCurrent(_this->gl_data->display, _this->gl_data->surface, + _this->gl_data->surface, _this->gl_data->context)) + { + return SDL_SetError("Unable to make EGL context current"); + } + return 0; +} + +int +PSP_GL_SetSwapInterval(_THIS, int interval) +{ + EGLBoolean status; + status = eglSwapInterval(_this->gl_data->display, interval); + if (status == EGL_TRUE) { + /* Return success to upper level */ + _this->gl_data->swapinterval = interval; + return 0; + } + /* Failed to set swap interval */ + return SDL_SetError("Unable to set the EGL swap interval"); +} + +int +PSP_GL_GetSwapInterval(_THIS) +{ + return _this->gl_data->swapinterval; +} + +void +PSP_GL_SwapWindow(_THIS, SDL_Window * window) +{ + eglSwapBuffers(_this->gl_data->display, _this->gl_data->surface); +} + +void +PSP_GL_DeleteContext(_THIS, SDL_GLContext context) +{ + SDL_VideoData *phdata = (SDL_VideoData *) _this->driverdata; + EGLBoolean status; + + if (phdata->egl_initialized != SDL_TRUE) { + SDL_SetError("PSP: GLES initialization failed, no OpenGL ES support"); + return; + } + + /* Check if OpenGL ES connection has been initialized */ + if (_this->gl_data->display != EGL_NO_DISPLAY) { + if (context != EGL_NO_CONTEXT) { + status = eglDestroyContext(_this->gl_data->display, context); + if (status != EGL_TRUE) { + /* Error during OpenGL ES context destroying */ + SDL_SetError("PSP: OpenGL ES context destroy error"); + return; + } + } + } + + return; +} + diff --git a/src/thread/nds/SDL_systhread.c b/src/video/psp/SDL_pspgl_c.h index e94dcd7743..73235ef684 100644 --- a/src/thread/nds/SDL_systhread.c +++ b/src/video/psp/SDL_pspgl_c.h @@ -19,46 +19,34 @@ 3. This notice may not be removed or altered from any source distribution. */ -#ifdef SAVE_RCSID -static char rcsid = - "@(#) $Id: SDL_systhread.c,v 1.2 2001/04/26 16:50:18 hercules Exp $"; -#endif +#ifndef _SDL_pspgl_c_h +#define _SDL_pspgl_c_h -/* Thread management routines for SDL */ -#include "SDL_error.h" -#include "SDL_thread.h" -#include "../SDL_systhread.h" +#include <GLES/egl.h> +#include <GLES/gl.h> -int -SDL_SYS_CreateThread(SDL_Thread * thread, void *args) -{ - SDL_SetError("Threads are not supported on this platform"); - return (-1); -} +#include "SDL_pspvideo.h" -void -SDL_SYS_SetupThread(const char *name) -{ - return; -} -SDL_threadID -SDL_ThreadID(void) -{ - return (0); -} +typedef struct SDL_GLDriverData { + EGLDisplay display; + EGLContext context; + EGLSurface surface; + uint32_t swapinterval; +}SDL_GLDriverData; -void -SDL_SYS_WaitThread(SDL_Thread * thread) -{ - return; -} +extern void * PSP_GL_GetProcAddress(_THIS, const char *proc); +extern int PSP_GL_MakeCurrent(_THIS,SDL_Window * window, SDL_GLContext context); +extern void PSP_GL_SwapBuffers(_THIS); -int -SDL_SYS_SetThreadPriority(SDL_ThreadPriority priority) -{ - return (0); -} +extern void PSP_GL_SwapWindow(_THIS, SDL_Window * window); +extern SDL_GLContext PSP_GL_CreateContext(_THIS, SDL_Window * window); -/* vi: set ts=4 sw=4 expandtab: */ +extern int PSP_GL_LoadLibrary(_THIS, const char *path); +extern void PSP_GL_UnloadLibrary(_THIS); +extern int PSP_GL_SetSwapInterval(_THIS, int interval); +extern int PSP_GL_GetSwapInterval(_THIS); + + +#endif /* _SDL_pspgl_c_h */ diff --git a/src/video/nds/SDL_ndswindow.h b/src/video/psp/SDL_pspmouse.c index 19bd492907..8f0ffdc7dc 100644 --- a/src/video/nds/SDL_ndswindow.h +++ b/src/video/psp/SDL_pspmouse.c @@ -18,13 +18,18 @@ misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ -#include "SDL_config.h" -#ifndef _SDL_ndswindow_h -#define _SDL_ndswindow_h -extern int NDS_CreateWindow(_THIS, SDL_Window * window); +#include <stdio.h> -#endif /* _SDL_ndswindow_h */ +#include "SDL_error.h" +#include "SDL_mouse.h" +#include "../../events/SDL_events_c.h" -/* vi: set ts=4 sw=4 expandtab: */ +#include "SDL_pspmouse_c.h" + + +/* The implementation dependent data for the window manager cursor */ +struct WMcursor { + int unused; +}; diff --git a/src/thread/nds/SDL_syssem_c.h b/src/video/psp/SDL_pspmouse_c.h index b12f9ce6d9..a0836a30a2 100644 --- a/src/thread/nds/SDL_syssem_c.h +++ b/src/video/psp/SDL_pspmouse_c.h @@ -19,7 +19,6 @@ 3. This notice may not be removed or altered from any source distribution. */ -#ifdef SAVE_RCSID -static char rcsid = - "@(#) $Id: SDL_syssem_c.h,v 1.2 2001/04/26 16:50:18 hercules Exp $"; -#endif +#include "SDL_pspvideo.h" + +/* Functions to be exported */ diff --git a/src/video/psp/SDL_pspvideo.c b/src/video/psp/SDL_pspvideo.c new file mode 100644 index 0000000000..8ed6375516 --- /dev/null +++ b/src/video/psp/SDL_pspvideo.c @@ -0,0 +1,333 @@ +/* + Simple DirectMedia Layer + Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org> + + This software is provided 'as-is', without any express or implied + warranty. In no event will the authors be held liable for any damages + arising from the use of this software. + + Permission is granted to anyone to use this software for any purpose, + including commercial applications, and to alter it and redistribute it + freely, subject to the following restrictions: + + 1. The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original software. + 3. This notice may not be removed or altered from any source distribution. +*/ + +#include "SDL_config.h" + +#if SDL_VIDEO_DRIVER_PSP + +/* SDL internals */ +#include "../SDL_sysvideo.h" +#include "SDL_version.h" +#include "SDL_syswm.h" +#include "SDL_loadso.h" +#include "SDL_events.h" +#include "../../events/SDL_mouse_c.h" +#include "../../events/SDL_keyboard_c.h" + + + +/* PSP declarations */ +#include "SDL_pspvideo.h" +#include "SDL_pspevents_c.h" +#include "SDL_pspgl_c.h" + +/* unused +static SDL_bool PSP_initialized = SDL_FALSE; +*/ +static int +PSP_Available(void) +{ + return 1; +} + +static void +PSP_Destroy(SDL_VideoDevice * device) +{ +// SDL_VideoData *phdata = (SDL_VideoData *) device->driverdata; + + if (device->driverdata != NULL) { + device->driverdata = NULL; + } +} + +static SDL_VideoDevice * +PSP_Create() +{ + SDL_VideoDevice *device; + SDL_VideoData *phdata; + SDL_GLDriverData *gldata; + int status; + + /* Check if pandora could be initialized */ + status = PSP_Available(); + if (status == 0) { + /* PSP could not be used */ + return NULL; + } + + /* Initialize SDL_VideoDevice structure */ + device = (SDL_VideoDevice *) SDL_calloc(1, sizeof(SDL_VideoDevice)); + if (device == NULL) { + SDL_OutOfMemory(); + return NULL; + } + + /* Initialize internal Pandora specific data */ + phdata = (SDL_VideoData *) SDL_calloc(1, sizeof(SDL_VideoData)); + if (phdata == NULL) { + SDL_OutOfMemory(); + SDL_free(device); + return NULL; + } + + gldata = (SDL_GLDriverData *) SDL_calloc(1, sizeof(SDL_GLDriverData)); + if (gldata == NULL) { + SDL_OutOfMemory(); + SDL_free(device); + return NULL; + } + device->gl_data = gldata; + + device->driverdata = phdata; + + phdata->egl_initialized = SDL_TRUE; + + + /* Setup amount of available displays and current display */ + device->num_displays = 0; + + /* Set device free function */ + device->free = PSP_Destroy; + + /* Setup all functions which we can handle */ + device->VideoInit = PSP_VideoInit; + device->VideoQuit = PSP_VideoQuit; + device->GetDisplayModes = PSP_GetDisplayModes; + device->SetDisplayMode = PSP_SetDisplayMode; + device->CreateWindow = PSP_CreateWindow; + device->CreateWindowFrom = PSP_CreateWindowFrom; + device->SetWindowTitle = PSP_SetWindowTitle; + device->SetWindowIcon = PSP_SetWindowIcon; + device->SetWindowPosition = PSP_SetWindowPosition; + device->SetWindowSize = PSP_SetWindowSize; + device->ShowWindow = PSP_ShowWindow; + device->HideWindow = PSP_HideWindow; + device->RaiseWindow = PSP_RaiseWindow; + device->MaximizeWindow = PSP_MaximizeWindow; + device->MinimizeWindow = PSP_MinimizeWindow; + device->RestoreWindow = PSP_RestoreWindow; + device->SetWindowGrab = PSP_SetWindowGrab; + device->DestroyWindow = PSP_DestroyWindow; + device->GetWindowWMInfo = PSP_GetWindowWMInfo; + device->GL_LoadLibrary = PSP_GL_LoadLibrary; + device->GL_GetProcAddress = PSP_GL_GetProcAddress; + device->GL_UnloadLibrary = PSP_GL_UnloadLibrary; + device->GL_CreateContext = PSP_GL_CreateContext; + device->GL_MakeCurrent = PSP_GL_MakeCurrent; + device->GL_SetSwapInterval = PSP_GL_SetSwapInterval; + device->GL_GetSwapInterval = PSP_GL_GetSwapInterval; + device->GL_SwapWindow = PSP_GL_SwapWindow; + device->GL_DeleteContext = PSP_GL_DeleteContext; + device->SDL_HasScreenKeyboardSupport = PSP_SDL_HasScreenKeyboardSupport; + device->SDL_ShowScreenKeyboard = PSP_SDL_ShowScreenKeyboard; + device->SDL_HideScreenKeyboard = PSP_SDL_HideScreenKeyboard; + device->SDL_IsScreenKeyboardShown = PSP_SDL_IsScreenKeyboardShown; + + device->PumpEvents = PSP_PumpEvents; + + return device; +} + +VideoBootStrap PSP_bootstrap = { + "PSP", + "PSP Video Driver", + PSP_Available, + PSP_Create +}; + +/*****************************************************************************/ +/* SDL Video and Display initialization/handling functions */ +/*****************************************************************************/ +int +PSP_VideoInit(_THIS) +{ + SDL_VideoDisplay display; + SDL_DisplayMode current_mode; + + SDL_zero(current_mode); + + current_mode.w = 480; + current_mode.h = 272; + + current_mode.refresh_rate = 60; + // 32 bpp for default + // current_mode.format = SDL_PIXELFORMAT_RGBA8888; + current_mode.format = SDL_PIXELFORMAT_ABGR8888; + + current_mode.driverdata = NULL; + + SDL_zero(display); + display.desktop_mode = current_mode; + display.current_mode = current_mode; + display.driverdata = NULL; + + SDL_AddVideoDisplay(&display); + + return 1; +} + +void +PSP_VideoQuit(_THIS) +{ + +} + +void +PSP_GetDisplayModes(_THIS, SDL_VideoDisplay * display) +{ + +} + +int +PSP_SetDisplayMode(_THIS, SDL_VideoDisplay * display, SDL_DisplayMode * mode) +{ + return 0; +} +#define EGLCHK(stmt) \ + do { \ + EGLint err; \ + \ + stmt; \ + err = eglGetError(); \ + if (err != EGL_SUCCESS) { \ + SDL_SetError("EGL error %d", err); \ + return 0; \ + } \ + } while (0) + +int +PSP_CreateWindow(_THIS, SDL_Window * window) +{ +// SDL_VideoData *phdata = (SDL_VideoData *) _this->driverdata; + + SDL_WindowData *wdata; + + /* Allocate window internal data */ + wdata = (SDL_WindowData *) SDL_calloc(1, sizeof(SDL_WindowData)); + if (wdata == NULL) { + return SDL_OutOfMemory(); + } + + /* Setup driver data for this window */ + window->driverdata = wdata; + + + /* Window has been successfully created */ + return 0; +} + +int +PSP_CreateWindowFrom(_THIS, SDL_Window * window, const void *data) +{ + return -1; +} + +void +PSP_SetWindowTitle(_THIS, SDL_Window * window) +{ +} +void +PSP_SetWindowIcon(_THIS, SDL_Window * window, SDL_Surface * icon) +{ +} +void +PSP_SetWindowPosition(_THIS, SDL_Window * window) +{ +} +void +PSP_SetWindowSize(_THIS, SDL_Window * window) +{ +} +void +PSP_ShowWindow(_THIS, SDL_Window * window) +{ +} +void +PSP_HideWindow(_THIS, SDL_Window * window) +{ +} +void +PSP_RaiseWindow(_THIS, SDL_Window * window) +{ +} +void +PSP_MaximizeWindow(_THIS, SDL_Window * window) +{ +} +void +PSP_MinimizeWindow(_THIS, SDL_Window * window) +{ +} +void +PSP_RestoreWindow(_THIS, SDL_Window * window) +{ +} +void +PSP_SetWindowGrab(_THIS, SDL_Window * window, SDL_bool grabbed) +{ + +} +void +PSP_DestroyWindow(_THIS, SDL_Window * window) +{ + +// eglTerminate(_this->gl_data->display); +} + +/*****************************************************************************/ +/* SDL Window Manager function */ +/*****************************************************************************/ +SDL_bool +PSP_GetWindowWMInfo(_THIS, SDL_Window * window, struct SDL_SysWMinfo *info) +{ + if (info->version.major <= SDL_MAJOR_VERSION) { + return SDL_TRUE; + } else { + SDL_SetError("application not compiled with SDL %d.%d\n", + SDL_MAJOR_VERSION, SDL_MINOR_VERSION); + return SDL_FALSE; + } + + /* Failed to get window manager information */ + return SDL_FALSE; +} + + +/* TO Write Me*/ +SDL_bool PSP_SDL_HasScreenKeyboardSupport(_THIS) +{ + return SDL_TRUE; +} +void PSP_SDL_ShowScreenKeyboard(_THIS, SDL_Window *window) +{ +} +void PSP_SDL_HideScreenKeyboard(_THIS, SDL_Window *window) +{ +} +SDL_bool PSP_SDL_IsScreenKeyboardShown(_THIS, SDL_Window *window) +{ + return SDL_FALSE; +} + + +#endif /* SDL_VIDEO_DRIVER_PSP */ + +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/video/psp/SDL_pspvideo.h b/src/video/psp/SDL_pspvideo.h new file mode 100644 index 0000000000..7209cb1565 --- /dev/null +++ b/src/video/psp/SDL_pspvideo.h @@ -0,0 +1,102 @@ +/* + Simple DirectMedia Layer + Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org> + + This software is provided 'as-is', without any express or implied + warranty. In no event will the authors be held liable for any damages + arising from the use of this software. + + Permission is granted to anyone to use this software for any purpose, + including commercial applications, and to alter it and redistribute it + freely, subject to the following restrictions: + + 1. The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original software. + 3. This notice may not be removed or altered from any source distribution. +*/ + +#ifndef __SDL_PANDORA_H__ +#define __SDL_PANDORA_H__ + +#include <GLES/egl.h> + +#include "SDL_config.h" +#include "../SDL_sysvideo.h" + +typedef struct SDL_VideoData +{ + SDL_bool egl_initialized; /* OpenGL ES device initialization status */ + uint32_t egl_refcount; /* OpenGL ES reference count */ + + + +} SDL_VideoData; + + +typedef struct SDL_DisplayData +{ + +} SDL_DisplayData; + + +typedef struct SDL_WindowData +{ + SDL_bool uses_gles; /* if true window must support OpenGL ES */ + +} SDL_WindowData; + + + + +/****************************************************************************/ +/* SDL_VideoDevice functions declaration */ +/****************************************************************************/ + +/* Display and window functions */ +int PSP_VideoInit(_THIS); +void PSP_VideoQuit(_THIS); +void PSP_GetDisplayModes(_THIS, SDL_VideoDisplay * display); +int PSP_SetDisplayMode(_THIS, SDL_VideoDisplay * display, SDL_DisplayMode * mode); +int PSP_CreateWindow(_THIS, SDL_Window * window); +int PSP_CreateWindowFrom(_THIS, SDL_Window * window, const void *data); +void PSP_SetWindowTitle(_THIS, SDL_Window * window); +void PSP_SetWindowIcon(_THIS, SDL_Window * window, SDL_Surface * icon); +void PSP_SetWindowPosition(_THIS, SDL_Window * window); +void PSP_SetWindowSize(_THIS, SDL_Window * window); +void PSP_ShowWindow(_THIS, SDL_Window * window); +void PSP_HideWindow(_THIS, SDL_Window * window); +void PSP_RaiseWindow(_THIS, SDL_Window * window); +void PSP_MaximizeWindow(_THIS, SDL_Window * window); +void PSP_MinimizeWindow(_THIS, SDL_Window * window); +void PSP_RestoreWindow(_THIS, SDL_Window * window); +void PSP_SetWindowGrab(_THIS, SDL_Window * window, SDL_bool grabbed); +void PSP_DestroyWindow(_THIS, SDL_Window * window); + +/* Window manager function */ +SDL_bool PSP_GetWindowWMInfo(_THIS, SDL_Window * window, + struct SDL_SysWMinfo *info); + +/* OpenGL/OpenGL ES functions */ +int PSP_GL_LoadLibrary(_THIS, const char *path); +void *PSP_GL_GetProcAddress(_THIS, const char *proc); +void PSP_GL_UnloadLibrary(_THIS); +SDL_GLContext PSP_GL_CreateContext(_THIS, SDL_Window * window); +int PSP_GL_MakeCurrent(_THIS, SDL_Window * window, SDL_GLContext context); +int PSP_GL_SetSwapInterval(_THIS, int interval); +int PSP_GL_GetSwapInterval(_THIS); +void PSP_GL_SwapWindow(_THIS, SDL_Window * window); +void PSP_GL_DeleteContext(_THIS, SDL_GLContext context); + +/*PSP on screen keyboard */ +SDL_bool PSP_SDL_HasScreenKeyboardSupport(_THIS); +void PSP_SDL_ShowScreenKeyboard(_THIS, SDL_Window *window); +void PSP_SDL_HideScreenKeyboard(_THIS, SDL_Window *window); +SDL_bool PSP_SDL_IsScreenKeyboardShown(_THIS, SDL_Window *window); + +#endif /* __SDL_PANDORA_H__ */ + +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/video/uikit/SDL_uikitmodes.m b/src/video/uikit/SDL_uikitmodes.m index 1f6b810253..87c3cc1e5b 100644 --- a/src/video/uikit/SDL_uikitmodes.m +++ b/src/video/uikit/SDL_uikitmodes.m @@ -39,8 +39,7 @@ UIKit_AllocateDisplayModeData(SDL_DisplayMode * mode, /* Allocate the display mode data */ data = (SDL_DisplayModeData *) SDL_malloc(sizeof(*data)); if (!data) { - SDL_OutOfMemory(); - return -1; + return SDL_OutOfMemory(); } data->uiscreenmode = uiscreenmode; @@ -160,9 +159,8 @@ UIKit_AddDisplay(UIScreen *uiscreen) /* Allocate the display data */ SDL_DisplayData *data = (SDL_DisplayData *) SDL_malloc(sizeof(*data)); if (!data) { - SDL_OutOfMemory(); UIKit_FreeDisplayModeData(&display.desktop_mode); - return -1; + return SDL_OutOfMemory(); } [uiscreen retain]; diff --git a/src/video/uikit/SDL_uikitopengles.m b/src/video/uikit/SDL_uikitopengles.m index 63d8dbb7b4..f3efab2a7a 100644 --- a/src/video/uikit/SDL_uikitopengles.m +++ b/src/video/uikit/SDL_uikitopengles.m @@ -72,8 +72,7 @@ UIKit_GL_LoadLibrary(_THIS, const char *path) and because the SDK forbids loading an external SO */ if (path != NULL) { - SDL_SetError("iPhone GL Load Library just here for compatibility"); - return -1; + return SDL_SetError("iPhone GL Load Library just here for compatibility"); } return 0; } diff --git a/src/video/uikit/SDL_uikitvideo.m b/src/video/uikit/SDL_uikitvideo.m index 12ceb1a113..ff025067ba 100644 --- a/src/video/uikit/SDL_uikitvideo.m +++ b/src/video/uikit/SDL_uikitvideo.m @@ -63,10 +63,10 @@ UIKit_CreateDevice(int devindex) /* Initialize all variables that we clean on shutdown */ device = (SDL_VideoDevice *) SDL_calloc(1, sizeof(SDL_VideoDevice)); if (!device) { - SDL_OutOfMemory(); if (device) { SDL_free(device); } + SDL_OutOfMemory(); return (0); } diff --git a/src/video/uikit/SDL_uikitview.h b/src/video/uikit/SDL_uikitview.h index cd5aec4504..ff8a7d2cfd 100644 --- a/src/video/uikit/SDL_uikitview.h +++ b/src/video/uikit/SDL_uikitview.h @@ -37,7 +37,7 @@ #endif SDL_TouchID touchId; - SDL_FingerID leftFingerDown; + UITouch *leftFingerDown; #ifndef IPHONE_TOUCH_EFFICIENT_DANGEROUS UITouch *finger[MAX_SIMULTANEOUS_TOUCHES]; #endif diff --git a/src/video/uikit/SDL_uikitview.m b/src/video/uikit/SDL_uikitview.m index ddbfe8f5e7..82cce3cbf0 100644 --- a/src/video/uikit/SDL_uikitview.m +++ b/src/video/uikit/SDL_uikitview.m @@ -52,23 +52,8 @@ self.multipleTouchEnabled = YES; - SDL_Touch touch; - touch.id = 0; //TODO: Should be -1? - - //touch.driverdata = SDL_malloc(sizeof(EventTouchData)); - //EventTouchData* data = (EventTouchData*)(touch.driverdata); - - touch.x_min = 0; - touch.x_max = 1; - touch.native_xres = touch.x_max - touch.x_min; - touch.y_min = 0; - touch.y_max = 1; - touch.native_yres = touch.y_max - touch.y_min; - touch.pressure_min = 0; - touch.pressure_max = 1; - touch.native_pressureres = touch.pressure_max - touch.pressure_min; - - touchId = SDL_AddTouch(&touch, "IPHONE SCREEN"); + touchId = 1; + SDL_AddTouch(touchId, ""); return self; @@ -104,12 +89,12 @@ CGPoint locationInView = [self touchLocation:touch shouldNormalize:NO]; /* send moved event */ - SDL_SendMouseMotion(NULL, 0, locationInView.x, locationInView.y); + SDL_SendMouseMotion(NULL, SDL_TOUCH_MOUSEID, 0, locationInView.x, locationInView.y); /* send mouse down event */ - SDL_SendMouseButton(NULL, SDL_PRESSED, SDL_BUTTON_LEFT); + SDL_SendMouseButton(NULL, SDL_TOUCH_MOUSEID, SDL_PRESSED, SDL_BUTTON_LEFT); - leftFingerDown = (SDL_FingerID)touch; + leftFingerDown = touch; } CGPoint locationInView = [self touchLocation:touch shouldNormalize:YES]; @@ -117,17 +102,15 @@ // FIXME: TODO: Using touch as the fingerId is potentially dangerous // It is also much more efficient than storing the UITouch pointer // and comparing it to the incoming event. - SDL_SendFingerDown(touchId, (SDL_FingerID)touch, - SDL_TRUE, locationInView.x, locationInView.y, - 1); + SDL_SendTouch(touchId, (SDL_FingerID)((size_t)touch), + SDL_TRUE, locationInView.x, locationInView.y, 1.0f); #else int i; for(i = 0; i < MAX_SIMULTANEOUS_TOUCHES; i++) { if (finger[i] == NULL) { finger[i] = touch; - SDL_SendFingerDown(touchId, i, - SDL_TRUE, locationInView.x, locationInView.y, - 1); + SDL_SendTouch(touchId, i, + SDL_TRUE, locationInView.x, locationInView.y, 1.0f); break; } } @@ -142,24 +125,22 @@ UITouch *touch = (UITouch*)[enumerator nextObject]; while(touch) { - if ((SDL_FingerID)touch == leftFingerDown) { + if (touch == leftFingerDown) { /* send mouse up */ - SDL_SendMouseButton(NULL, SDL_RELEASED, SDL_BUTTON_LEFT); - leftFingerDown = 0; + SDL_SendMouseButton(NULL, SDL_TOUCH_MOUSEID, SDL_RELEASED, SDL_BUTTON_LEFT); + leftFingerDown = nil; } CGPoint locationInView = [self touchLocation:touch shouldNormalize:YES]; #ifdef IPHONE_TOUCH_EFFICIENT_DANGEROUS - SDL_SendFingerDown(touchId, (long)touch, - SDL_FALSE, locationInView.x, locationInView.y, - 1); + SDL_SendTouch(touchId, (long)touch, + SDL_FALSE, locationInView.x, locationInView.y, 1.0f); #else int i; for (i = 0; i < MAX_SIMULTANEOUS_TOUCHES; i++) { if (finger[i] == touch) { - SDL_SendFingerDown(touchId, i, - SDL_FALSE, locationInView.x, locationInView.y, - 1); + SDL_SendTouch(touchId, i, + SDL_FALSE, locationInView.x, locationInView.y, 1.0f); finger[i] = NULL; break; } @@ -185,25 +166,23 @@ UITouch *touch = (UITouch*)[enumerator nextObject]; while (touch) { - if ((SDL_FingerID)touch == leftFingerDown) { + if (touch == leftFingerDown) { CGPoint locationInView = [self touchLocation:touch shouldNormalize:NO]; /* send moved event */ - SDL_SendMouseMotion(NULL, 0, locationInView.x, locationInView.y); + SDL_SendMouseMotion(NULL, SDL_TOUCH_MOUSEID, 0, locationInView.x, locationInView.y); } CGPoint locationInView = [self touchLocation:touch shouldNormalize:YES]; #ifdef IPHONE_TOUCH_EFFICIENT_DANGEROUS SDL_SendTouchMotion(touchId, (long)touch, - SDL_FALSE, locationInView.x, locationInView.y, - 1); + locationInView.x, locationInView.y, 1.0f); #else int i; for (i = 0; i < MAX_SIMULTANEOUS_TOUCHES; i++) { if (finger[i] == touch) { SDL_SendTouchMotion(touchId, i, - SDL_FALSE, locationInView.x, locationInView.y, - 1); + locationInView.x, locationInView.y, 1.0f); break; } } diff --git a/src/video/uikit/SDL_uikitwindow.m b/src/video/uikit/SDL_uikitwindow.m index b9c1e3e6d7..e18065fa45 100644 --- a/src/video/uikit/SDL_uikitwindow.m +++ b/src/video/uikit/SDL_uikitwindow.m @@ -54,8 +54,7 @@ static int SetupWindowData(_THIS, SDL_Window *window, UIWindow *uiwindow, SDL_bo /* Allocate the window data */ data = (SDL_WindowData *)SDL_malloc(sizeof(*data)); if (!data) { - SDL_OutOfMemory(); - return -1; + return SDL_OutOfMemory(); } data->uiwindow = uiwindow; data->viewcontroller = nil; @@ -133,8 +132,7 @@ UIKit_CreateWindow(_THIS, SDL_Window *window) /* We currently only handle a single window per display on iOS */ if (window->next != NULL) { - SDL_SetError("Only one window allowed per display."); - return -1; + return SDL_SetError("Only one window allowed per display."); } // If monitor has a resolution of 0x0 (hasn't been explicitly set by the @@ -317,8 +315,7 @@ SDL_iPhoneSetAnimationCallback(SDL_Window * window, int interval, void (*callbac SDL_WindowData *data = window ? (SDL_WindowData *)window->driverdata : NULL; if (!data || !data->view) { - SDL_SetError("Invalid window or view not set"); - return -1; + return SDL_SetError("Invalid window or view not set"); } [data->view setAnimationCallback:interval callback:callback callbackParam:callbackParam]; diff --git a/src/video/windows/SDL_windowsclipboard.c b/src/video/windows/SDL_windowsclipboard.c index 5c1bf11fd1..4f0c87a817 100644 --- a/src/video/windows/SDL_windowsclipboard.c +++ b/src/video/windows/SDL_windowsclipboard.c @@ -89,8 +89,7 @@ WIN_SetClipboardText(_THIS, const char *text) EmptyClipboard(); if (!SetClipboardData(TEXT_FORMAT, hMem)) { - WIN_SetError("Couldn't set clipboard data"); - result = -1; + result = WIN_SetError("Couldn't set clipboard data"); } data->clipboard_count = GetClipboardSequenceNumber(); } @@ -98,8 +97,7 @@ WIN_SetClipboardText(_THIS, const char *text) CloseClipboard(); } else { - WIN_SetError("Couldn't open clipboard"); - result = -1; + result = WIN_SetError("Couldn't open clipboard"); } return result; } diff --git a/src/video/windows/SDL_windowsevents.c b/src/video/windows/SDL_windowsevents.c index 863daf7ec2..fc85e44932 100644 --- a/src/video/windows/SDL_windowsevents.c +++ b/src/video/windows/SDL_windowsevents.c @@ -28,13 +28,12 @@ #include "SDL_vkeys.h" #include "../../events/SDL_events_c.h" #include "../../events/SDL_touch_c.h" +#include "../../events/scancodes_windows.h" /* Dropfile support */ #include <shellapi.h> - - /*#define WMMSG_DEBUG*/ #ifdef WMMSG_DEBUG #include <stdio.h> @@ -46,6 +45,9 @@ #define EXTENDED_KEYMASK (1<<24) #define VK_ENTER 10 /* Keypad Enter ... no VKEY defined? */ +#ifndef VK_OEM_NEC_EQUAL +#define VK_OEM_NEC_EQUAL 0x92 +#endif /* Make sure XBUTTON stuff is defined that isn't in older Platform SDKs... */ #ifndef WM_XBUTTONDOWN @@ -64,45 +66,192 @@ #define WM_TOUCH 0x0240 #endif +static SDL_Scancode +WindowsScanCodeToSDLScanCode( LPARAM lParam, WPARAM wParam ) +{ + SDL_Scancode code; + char bIsExtended; + int nScanCode = ( lParam >> 16 ) & 0xFF; + + /* 0x45 here to work around both pause and numlock sharing the same scancode, so use the VK key to tell them apart */ + if ( nScanCode == 0 || nScanCode == 0x45 ) + { + switch( wParam ) + { + case VK_CLEAR: return SDL_SCANCODE_CLEAR; + case VK_MODECHANGE: return SDL_SCANCODE_MODE; + case VK_SELECT: return SDL_SCANCODE_SELECT; + case VK_EXECUTE: return SDL_SCANCODE_EXECUTE; + case VK_HELP: return SDL_SCANCODE_HELP; + case VK_PAUSE: return SDL_SCANCODE_PAUSE; + case VK_NUMLOCK: return SDL_SCANCODE_NUMLOCKCLEAR; + + case VK_F13: return SDL_SCANCODE_F13; + case VK_F14: return SDL_SCANCODE_F14; + case VK_F15: return SDL_SCANCODE_F15; + case VK_F16: return SDL_SCANCODE_F16; + case VK_F17: return SDL_SCANCODE_F17; + case VK_F18: return SDL_SCANCODE_F18; + case VK_F19: return SDL_SCANCODE_F19; + case VK_F20: return SDL_SCANCODE_F20; + case VK_F21: return SDL_SCANCODE_F21; + case VK_F22: return SDL_SCANCODE_F22; + case VK_F23: return SDL_SCANCODE_F23; + case VK_F24: return SDL_SCANCODE_F24; + + case VK_OEM_NEC_EQUAL: return SDL_SCANCODE_KP_EQUALS; + case VK_BROWSER_BACK: return SDL_SCANCODE_AC_BACK; + case VK_BROWSER_FORWARD: return SDL_SCANCODE_AC_FORWARD; + case VK_BROWSER_REFRESH: return SDL_SCANCODE_AC_REFRESH; + case VK_BROWSER_STOP: return SDL_SCANCODE_AC_STOP; + case VK_BROWSER_SEARCH: return SDL_SCANCODE_AC_SEARCH; + case VK_BROWSER_FAVORITES: return SDL_SCANCODE_AC_BOOKMARKS; + case VK_BROWSER_HOME: return SDL_SCANCODE_AC_HOME; + case VK_VOLUME_MUTE: return SDL_SCANCODE_AUDIOMUTE; + case VK_VOLUME_DOWN: return SDL_SCANCODE_VOLUMEDOWN; + case VK_VOLUME_UP: return SDL_SCANCODE_VOLUMEUP; + + case VK_MEDIA_NEXT_TRACK: return SDL_SCANCODE_AUDIONEXT; + case VK_MEDIA_PREV_TRACK: return SDL_SCANCODE_AUDIOPREV; + case VK_MEDIA_STOP: return SDL_SCANCODE_AUDIOSTOP; + case VK_MEDIA_PLAY_PAUSE: return SDL_SCANCODE_AUDIOPLAY; + case VK_LAUNCH_MAIL: return SDL_SCANCODE_MAIL; + case VK_LAUNCH_MEDIA_SELECT: return SDL_SCANCODE_MEDIASELECT; + + case VK_OEM_102: return SDL_SCANCODE_NONUSBACKSLASH; + + case VK_ATTN: return SDL_SCANCODE_SYSREQ; + case VK_CRSEL: return SDL_SCANCODE_CRSEL; + case VK_EXSEL: return SDL_SCANCODE_EXSEL; + case VK_OEM_CLEAR: return SDL_SCANCODE_CLEAR; + + case VK_LAUNCH_APP1: return SDL_SCANCODE_APP1; + case VK_LAUNCH_APP2: return SDL_SCANCODE_APP2; + + default: return SDL_SCANCODE_UNKNOWN; + } + } + + if ( nScanCode > 127 ) + return SDL_SCANCODE_UNKNOWN; + + code = windows_scancode_table[nScanCode]; + + bIsExtended = ( lParam & ( 1 << 24 ) ) != 0; + if ( !bIsExtended ) + { + switch ( code ) + { + case SDL_SCANCODE_HOME: + return SDL_SCANCODE_KP_7; + case SDL_SCANCODE_UP: + return SDL_SCANCODE_KP_8; + case SDL_SCANCODE_PAGEUP: + return SDL_SCANCODE_KP_9; + case SDL_SCANCODE_LEFT: + return SDL_SCANCODE_KP_4; + case SDL_SCANCODE_RIGHT: + return SDL_SCANCODE_KP_6; + case SDL_SCANCODE_END: + return SDL_SCANCODE_KP_1; + case SDL_SCANCODE_DOWN: + return SDL_SCANCODE_KP_2; + case SDL_SCANCODE_PAGEDOWN: + return SDL_SCANCODE_KP_3; + case SDL_SCANCODE_INSERT: + return SDL_SCANCODE_KP_0; + case SDL_SCANCODE_DELETE: + return SDL_SCANCODE_KP_PERIOD; + case SDL_SCANCODE_PRINTSCREEN: + return SDL_SCANCODE_KP_MULTIPLY; + default: + break; + } + } + else + { + switch ( code ) + { + case SDL_SCANCODE_RETURN: + return SDL_SCANCODE_KP_ENTER; + case SDL_SCANCODE_LALT: + return SDL_SCANCODE_RALT; + case SDL_SCANCODE_LCTRL: + return SDL_SCANCODE_RCTRL; + case SDL_SCANCODE_SLASH: + return SDL_SCANCODE_KP_DIVIDE; + case SDL_SCANCODE_CAPSLOCK: + return SDL_SCANCODE_KP_PLUS; + default: + break; + } + } + + return code; +} + -static WPARAM -RemapVKEY(WPARAM wParam, LPARAM lParam) +void +WIN_CheckWParamMouseButton( SDL_bool bwParamMousePressed, SDL_bool bSDLMousePressed, SDL_WindowData *data, Uint8 button ) { - int i; - BYTE scancode = (BYTE) ((lParam >> 16) & 0xFF); - - /* Windows remaps alphabetic keys based on current layout. - We try to provide USB scancodes, so undo this mapping. - */ - if (wParam >= 'A' && wParam <= 'Z') { - if (scancode != alpha_scancodes[wParam - 'A']) { - for (i = 0; i < SDL_arraysize(alpha_scancodes); ++i) { - if (scancode == alpha_scancodes[i]) { - wParam = 'A' + i; - break; - } - } - } - } + if ( bwParamMousePressed && !bSDLMousePressed ) + { + SDL_SendMouseButton(data->window, 0, SDL_PRESSED, button); + } + else if ( !bwParamMousePressed && bSDLMousePressed ) + { + SDL_SendMouseButton(data->window, 0, SDL_RELEASED, button); + } +} - /* Keypad keys are a little trickier, we always scan for them. - Keypad arrow keys have the same scancode as normal arrow keys, - except they don't have the extended bit (0x1000000) set. - */ - if (!(lParam & 0x1000000)) { - if (wParam == VK_DELETE) { - wParam = VK_DECIMAL; - } else { - for (i = 0; i < SDL_arraysize(keypad_scancodes); ++i) { - if (scancode == keypad_scancodes[i]) { - wParam = VK_NUMPAD0 + i; - break; - } - } - } - } +/* +* Some windows systems fail to send a WM_LBUTTONDOWN sometimes, but each mouse move contains the current button state also +* so this funciton reconciles our view of the world with the current buttons reported by windows +*/ +void +WIN_CheckWParamMouseButtons( WPARAM wParam, SDL_WindowData *data ) +{ + if ( wParam != data->mouse_button_flags ) + { + Uint32 mouseFlags = SDL_GetMouseState( NULL, NULL ); + WIN_CheckWParamMouseButton( (wParam & MK_LBUTTON), (mouseFlags & SDL_BUTTON_LMASK), data, SDL_BUTTON_LEFT ); + WIN_CheckWParamMouseButton( (wParam & MK_MBUTTON), (mouseFlags & SDL_BUTTON_MMASK), data, SDL_BUTTON_MIDDLE ); + WIN_CheckWParamMouseButton( (wParam & MK_RBUTTON), (mouseFlags & SDL_BUTTON_RMASK), data, SDL_BUTTON_RIGHT ); + WIN_CheckWParamMouseButton( (wParam & MK_XBUTTON1), (mouseFlags & SDL_BUTTON_X1MASK), data, SDL_BUTTON_X1 ); + WIN_CheckWParamMouseButton( (wParam & MK_XBUTTON2), (mouseFlags & SDL_BUTTON_X2MASK), data, SDL_BUTTON_X2 ); + data->mouse_button_flags = wParam; + } +} - return wParam; + +void +WIN_CheckRawMouseButtons( ULONG rawButtons, SDL_WindowData *data ) +{ + if ( rawButtons != data->mouse_button_flags ) + { + Uint32 mouseFlags = SDL_GetMouseState( NULL, NULL ); + if ( (rawButtons & RI_MOUSE_BUTTON_1_DOWN) ) + WIN_CheckWParamMouseButton( (rawButtons & RI_MOUSE_BUTTON_1_DOWN), (mouseFlags & SDL_BUTTON_LMASK), data, SDL_BUTTON_LEFT ); + if ( (rawButtons & RI_MOUSE_BUTTON_1_UP) ) + WIN_CheckWParamMouseButton( !(rawButtons & RI_MOUSE_BUTTON_1_UP), (mouseFlags & SDL_BUTTON_LMASK), data, SDL_BUTTON_LEFT ); + if ( (rawButtons & RI_MOUSE_BUTTON_2_DOWN) ) + WIN_CheckWParamMouseButton( (rawButtons & RI_MOUSE_BUTTON_2_DOWN), (mouseFlags & SDL_BUTTON_RMASK), data, SDL_BUTTON_RIGHT ); + if ( (rawButtons & RI_MOUSE_BUTTON_2_UP) ) + WIN_CheckWParamMouseButton( !(rawButtons & RI_MOUSE_BUTTON_2_UP), (mouseFlags & SDL_BUTTON_RMASK), data, SDL_BUTTON_RIGHT ); + if ( (rawButtons & RI_MOUSE_BUTTON_3_DOWN) ) + WIN_CheckWParamMouseButton( (rawButtons & RI_MOUSE_BUTTON_3_DOWN), (mouseFlags & SDL_BUTTON_MMASK), data, SDL_BUTTON_MIDDLE ); + if ( (rawButtons & RI_MOUSE_BUTTON_3_UP) ) + WIN_CheckWParamMouseButton( !(rawButtons & RI_MOUSE_BUTTON_3_UP), (mouseFlags & SDL_BUTTON_MMASK), data, SDL_BUTTON_MIDDLE ); + if ( (rawButtons & RI_MOUSE_BUTTON_4_DOWN) ) + WIN_CheckWParamMouseButton( (rawButtons & RI_MOUSE_BUTTON_4_DOWN), (mouseFlags & SDL_BUTTON_X1MASK), data, SDL_BUTTON_X1 ); + if ( (rawButtons & RI_MOUSE_BUTTON_4_UP) ) + WIN_CheckWParamMouseButton( !(rawButtons & RI_MOUSE_BUTTON_4_UP), (mouseFlags & SDL_BUTTON_X1MASK), data, SDL_BUTTON_X1 ); + if ( (rawButtons & RI_MOUSE_BUTTON_5_DOWN) ) + WIN_CheckWParamMouseButton( (rawButtons & RI_MOUSE_BUTTON_5_DOWN), (mouseFlags & SDL_BUTTON_X2MASK), data, SDL_BUTTON_X2 ); + if ( (rawButtons & RI_MOUSE_BUTTON_5_UP) ) + WIN_CheckWParamMouseButton( !(rawButtons & RI_MOUSE_BUTTON_5_UP), (mouseFlags & SDL_BUTTON_X2MASK), data, SDL_BUTTON_X2 ); + data->mouse_button_flags = rawButtons; + } } LRESULT CALLBACK @@ -165,6 +314,9 @@ WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) minimized = HIWORD(wParam); if (!minimized && (LOWORD(wParam) != WA_INACTIVE)) { + Uint32 mouseFlags; + SHORT keyState; + SDL_SendWindowEvent(data->window, SDL_WINDOWEVENT_SHOWN, 0, 0); SDL_SendWindowEvent(data->window, SDL_WINDOWEVENT_RESTORED, 0, 0); @@ -175,6 +327,23 @@ WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) if (SDL_GetKeyboardFocus() != data->window) { SDL_SetKeyboardFocus(data->window); } + /* mouse buttons may have changed state here, we need + to resync them, but we will get a WM_MOUSEMOVE right away which will fix + things up if in non raw mode also + */ + mouseFlags = SDL_GetMouseState( NULL, NULL ); + + keyState = GetAsyncKeyState( VK_LBUTTON ); + WIN_CheckWParamMouseButton( ( keyState & 0x8000 ), (mouseFlags & SDL_BUTTON_LMASK), data, SDL_BUTTON_LEFT ); + keyState = GetAsyncKeyState( VK_RBUTTON ); + WIN_CheckWParamMouseButton( ( keyState & 0x8000 ), (mouseFlags & SDL_BUTTON_RMASK), data, SDL_BUTTON_RIGHT ); + keyState = GetAsyncKeyState( VK_MBUTTON ); + WIN_CheckWParamMouseButton( ( keyState & 0x8000 ), (mouseFlags & SDL_BUTTON_MMASK), data, SDL_BUTTON_MIDDLE ); + keyState = GetAsyncKeyState( VK_XBUTTON1 ); + WIN_CheckWParamMouseButton( ( keyState & 0x8000 ), (mouseFlags & SDL_BUTTON_X1MASK), data, SDL_BUTTON_X1 ); + keyState = GetAsyncKeyState( VK_XBUTTON2 ); + WIN_CheckWParamMouseButton( ( keyState & 0x8000 ), (mouseFlags & SDL_BUTTON_X2MASK), data, SDL_BUTTON_X2 ); + data->mouse_button_flags = 0; if(SDL_GetMouse()->relative_mode) { LONG cx, cy; @@ -211,10 +380,20 @@ WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) break; case WM_MOUSEMOVE: - if(SDL_GetMouse()->relative_mode) - break; - SDL_SendMouseMotion(data->window, 0, LOWORD(lParam), HIWORD(lParam)); - break; + if( !SDL_GetMouse()->relative_mode ) + SDL_SendMouseMotion(data->window, 0, 0, LOWORD(lParam), HIWORD(lParam)); + /* don't break here, fall through to check the wParam like the button presses */ + case WM_LBUTTONUP: + case WM_RBUTTONUP: + case WM_MBUTTONUP: + case WM_XBUTTONUP: + case WM_LBUTTONDOWN: + case WM_RBUTTONDOWN: + case WM_MBUTTONDOWN: + case WM_XBUTTONDOWN: + if( !SDL_GetMouse()->relative_mode ) + WIN_CheckWParamMouseButtons( wParam, data ); + break; case WM_INPUT: { @@ -234,7 +413,7 @@ WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) if((mouse->usFlags & 0x01) == MOUSE_MOVE_RELATIVE) { - SDL_SendMouseMotion(data->window, 1, (int)mouse->lLastX, (int)mouse->lLastY); + SDL_SendMouseMotion(data->window, 0, 1, (int)mouse->lLastX, (int)mouse->lLastY); } else { @@ -246,55 +425,22 @@ WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) initialMousePoint.y = mouse->lLastY; } - SDL_SendMouseMotion(data->window, 1, (int)(mouse->lLastX-initialMousePoint.x), (int)(mouse->lLastY-initialMousePoint.y) ); + SDL_SendMouseMotion(data->window, 0, 1, (int)(mouse->lLastX-initialMousePoint.x), (int)(mouse->lLastY-initialMousePoint.y) ); initialMousePoint.x = mouse->lLastX; initialMousePoint.y = mouse->lLastY; } + WIN_CheckRawMouseButtons( mouse->usButtonFlags, data ); } break; } - case WM_LBUTTONDOWN: - SDL_SendMouseButton(data->window, SDL_PRESSED, SDL_BUTTON_LEFT); - break; - - case WM_LBUTTONUP: - SDL_SendMouseButton(data->window, SDL_RELEASED, SDL_BUTTON_LEFT); - break; - - case WM_RBUTTONDOWN: - SDL_SendMouseButton(data->window, SDL_PRESSED, SDL_BUTTON_RIGHT); - break; - - case WM_RBUTTONUP: - SDL_SendMouseButton(data->window, SDL_RELEASED, SDL_BUTTON_RIGHT); - break; - - case WM_MBUTTONDOWN: - SDL_SendMouseButton(data->window, SDL_PRESSED, SDL_BUTTON_MIDDLE); - break; - - case WM_MBUTTONUP: - SDL_SendMouseButton(data->window, SDL_RELEASED, SDL_BUTTON_MIDDLE); - break; - - case WM_XBUTTONDOWN: - SDL_SendMouseButton(data->window, SDL_PRESSED, SDL_BUTTON_X1 + GET_XBUTTON_WPARAM(wParam) - 1); - returnCode = TRUE; - break; - - case WM_XBUTTONUP: - SDL_SendMouseButton(data->window, SDL_RELEASED, SDL_BUTTON_X1 + GET_XBUTTON_WPARAM(wParam) - 1); - returnCode = TRUE; - break; - case WM_MOUSEWHEEL: { // FIXME: This may need to accumulate deltas up to WHEEL_DELTA short motion = GET_WHEEL_DELTA_WPARAM(wParam) / WHEEL_DELTA; - SDL_SendMouseWheel(data->window, 0, motion); + SDL_SendMouseWheel(data->window, 0, 0, motion); break; } @@ -311,44 +457,9 @@ WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) case WM_SYSKEYDOWN: case WM_KEYDOWN: { - wParam = RemapVKEY(wParam, lParam); - switch (wParam) { - case VK_CONTROL: - if (lParam & EXTENDED_KEYMASK) - wParam = VK_RCONTROL; - else - wParam = VK_LCONTROL; - break; - case VK_SHIFT: - /* EXTENDED trick doesn't work here */ - { - Uint8 *state = SDL_GetKeyboardState(NULL); - if (state[SDL_SCANCODE_LSHIFT] == SDL_RELEASED - && (GetKeyState(VK_LSHIFT) & 0x8000)) { - wParam = VK_LSHIFT; - } else if (state[SDL_SCANCODE_RSHIFT] == SDL_RELEASED - && (GetKeyState(VK_RSHIFT) & 0x8000)) { - wParam = VK_RSHIFT; - } else { - /* Probably a key repeat */ - wParam = 256; - } - } - break; - case VK_MENU: - if (lParam & EXTENDED_KEYMASK) - wParam = VK_RMENU; - else - wParam = VK_LMENU; - break; - case VK_RETURN: - if (lParam & EXTENDED_KEYMASK) - wParam = VK_ENTER; - break; - } - if (wParam < 256) { - SDL_SendKeyboardKey(SDL_PRESSED, - data->videodata->key_layout[wParam]); + SDL_Scancode code = WindowsScanCodeToSDLScanCode( lParam, wParam ); + if ( code != SDL_SCANCODE_UNKNOWN ) { + SDL_SendKeyboardKey(SDL_PRESSED, code ); } } returnCode = 0; @@ -357,52 +468,13 @@ WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) case WM_SYSKEYUP: case WM_KEYUP: { - wParam = RemapVKEY(wParam, lParam); - switch (wParam) { - case VK_CONTROL: - if (lParam & EXTENDED_KEYMASK) - wParam = VK_RCONTROL; - else - wParam = VK_LCONTROL; - break; - case VK_SHIFT: - /* EXTENDED trick doesn't work here */ - { - Uint8 *state = SDL_GetKeyboardState(NULL); - if (state[SDL_SCANCODE_LSHIFT] == SDL_PRESSED - && !(GetKeyState(VK_LSHIFT) & 0x8000)) { - wParam = VK_LSHIFT; - } else if (state[SDL_SCANCODE_RSHIFT] == SDL_PRESSED - && !(GetKeyState(VK_RSHIFT) & 0x8000)) { - wParam = VK_RSHIFT; - } else { - /* Probably a key repeat */ - wParam = 256; - } + SDL_Scancode code = WindowsScanCodeToSDLScanCode( lParam, wParam ); + if ( code != SDL_SCANCODE_UNKNOWN ) { + if (code == SDL_SCANCODE_PRINTSCREEN && + SDL_GetKeyboardState(NULL)[code] == SDL_RELEASED) { + SDL_SendKeyboardKey(SDL_PRESSED, code); } - break; - case VK_MENU: - if (lParam & EXTENDED_KEYMASK) - wParam = VK_RMENU; - else - wParam = VK_LMENU; - break; - case VK_RETURN: - if (lParam & EXTENDED_KEYMASK) - wParam = VK_ENTER; - break; - } - - /* Windows only reports keyup for print screen */ - if (wParam == VK_SNAPSHOT - && SDL_GetKeyboardState(NULL)[SDL_SCANCODE_PRINTSCREEN] == - SDL_RELEASED) { - SDL_SendKeyboardKey(SDL_PRESSED, - data->videodata->key_layout[wParam]); - } - if (wParam < 256) { - SDL_SendKeyboardKey(SDL_RELEASED, - data->videodata->key_layout[wParam]); + SDL_SendKeyboardKey(SDL_RELEASED, code); } } returnCode = 0; @@ -624,23 +696,9 @@ WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) for (i = 0; i < num_inputs; ++i) { PTOUCHINPUT input = &inputs[i]; - const SDL_TouchID touchId = (SDL_TouchID) - ((size_t)input->hSource); + const SDL_TouchID touchId = (SDL_TouchID)input->hSource; if (!SDL_GetTouch(touchId)) { - SDL_Touch touch; - - touch.id = touchId; - touch.x_min = 0; - touch.x_max = 1; - touch.native_xres = touch.x_max - touch.x_min; - touch.y_min = 0; - touch.y_max = 1; - touch.native_yres = touch.y_max - touch.y_min; - touch.pressure_min = 0; - touch.pressure_max = 1; - touch.native_pressureres = touch.pressure_max - touch.pressure_min; - - if (SDL_AddTouch(&touch, "") < 0) { + if (SDL_AddTouch(touchId, "") < 0) { continue; } } @@ -650,13 +708,13 @@ WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) y = (float)(input->y - rect.top)/(rect.bottom - rect.top); if (input->dwFlags & TOUCHEVENTF_DOWN) { - SDL_SendFingerDown(touchId, input->dwID, SDL_TRUE, x, y, 1); + SDL_SendTouch(touchId, input->dwID, SDL_TRUE, x, y, 1.0f); } if (input->dwFlags & TOUCHEVENTF_MOVE) { - SDL_SendTouchMotion(touchId, input->dwID, SDL_FALSE, x, y, 1); + SDL_SendTouchMotion(touchId, input->dwID, x, y, 1.0f); } if (input->dwFlags & TOUCHEVENTF_UP) { - SDL_SendFingerDown(touchId, input->dwID, SDL_FALSE, x, y, 1); + SDL_SendTouch(touchId, input->dwID, SDL_FALSE, x, y, 1.0f); } } } @@ -754,12 +812,11 @@ SDL_RegisterApp(char *name, Uint32 style, void *hInst) class.cbWndExtra = 0; class.cbClsExtra = 0; if (!RegisterClass(&class)) { - SDL_SetError("Couldn't register application class"); - return (-1); + return SDL_SetError("Couldn't register application class"); } app_registered = 1; - return (0); + return 0; } /* Unregisters the windowclass registered in SDL_RegisterApp above. */ diff --git a/src/video/windows/SDL_windowsframebuffer.c b/src/video/windows/SDL_windowsframebuffer.c index 8f2ad057cf..5a2a9ef003 100644 --- a/src/video/windows/SDL_windowsframebuffer.c +++ b/src/video/windows/SDL_windowsframebuffer.c @@ -85,15 +85,14 @@ int WIN_CreateWindowFramebuffer(_THIS, SDL_Window * window, Uint32 * format, voi SDL_stack_free(info); if (!data->hbm) { - WIN_SetError("Unable to create DIB"); - return -1; + return WIN_SetError("Unable to create DIB"); } SelectObject(data->mdc, data->hbm); return 0; } -int WIN_UpdateWindowFramebuffer(_THIS, SDL_Window * window, SDL_Rect * rects, int numrects) +int WIN_UpdateWindowFramebuffer(_THIS, SDL_Window * window, const SDL_Rect * rects, int numrects) { SDL_WindowData *data = (SDL_WindowData *) window->driverdata; diff --git a/src/video/windows/SDL_windowsframebuffer.h b/src/video/windows/SDL_windowsframebuffer.h index ebd7d7a9b5..4d7a2ba0d8 100644 --- a/src/video/windows/SDL_windowsframebuffer.h +++ b/src/video/windows/SDL_windowsframebuffer.h @@ -21,7 +21,7 @@ #include "SDL_config.h" extern int WIN_CreateWindowFramebuffer(_THIS, SDL_Window * window, Uint32 * format, void ** pixels, int *pitch); -extern int WIN_UpdateWindowFramebuffer(_THIS, SDL_Window * window, SDL_Rect * rects, int numrects); +extern int WIN_UpdateWindowFramebuffer(_THIS, SDL_Window * window, const SDL_Rect * rects, int numrects); extern void WIN_DestroyWindowFramebuffer(_THIS, SDL_Window * window); /* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/video/windows/SDL_windowskeyboard.c b/src/video/windows/SDL_windowskeyboard.c index dcdd78455b..74f078f865 100644 --- a/src/video/windows/SDL_windowskeyboard.c +++ b/src/video/windows/SDL_windowskeyboard.c @@ -48,49 +48,10 @@ static void IME_Quit(SDL_VideoData *videodata); #endif /* Alphabetic scancodes for PC keyboards */ -BYTE alpha_scancodes[26] = { - 30, 48, 46, 32, 18, 33, 34, 35, 23, 36, 37, 38, 50, 49, 24, - 25, 16, 19, 31, 20, 22, 47, 17, 45, 21, 44 -}; - -BYTE keypad_scancodes[10] = { - 82, 79, 80, 81, 75, 76, 77, 71, 72, 73 -}; - void WIN_InitKeyboard(_THIS) { SDL_VideoData *data = (SDL_VideoData *) _this->driverdata; - int i; - - /* Make sure the alpha scancodes are correct. T isn't usually remapped */ - if (MapVirtualKey('T', MAPVK_VK_TO_VSC) != alpha_scancodes['T' - 'A']) { -#if 0 - printf - ("Fixing alpha scancode map, assuming US QWERTY layout!\nPlease send the following 26 lines of output to the SDL mailing list <sdl@libsdl.org>, including a description of your keyboard hardware.\n"); -#endif - for (i = 0; i < SDL_arraysize(alpha_scancodes); ++i) { - alpha_scancodes[i] = MapVirtualKey('A' + i, MAPVK_VK_TO_VSC); -#if 0 - printf("%d = %d\n", i, alpha_scancodes[i]); -#endif - } - } - if (MapVirtualKey(VK_NUMPAD0, MAPVK_VK_TO_VSC) != keypad_scancodes[0]) { -#if 0 - printf - ("Fixing keypad scancode map!\nPlease send the following 10 lines of output to the SDL mailing list <sdl@libsdl.org>, including a description of your keyboard hardware.\n"); -#endif - for (i = 0; i < SDL_arraysize(keypad_scancodes); ++i) { - keypad_scancodes[i] = - MapVirtualKey(VK_NUMPAD0 + i, MAPVK_VK_TO_VSC); -#if 0 - printf("%d = %d\n", i, keypad_scancodes[i]); -#endif - } - } - - data->key_layout = windows_scancode_table; data->ime_com_initialized = SDL_FALSE; data->ime_threadmgr = 0; @@ -153,21 +114,35 @@ WIN_UpdateKeymap() SDL_GetDefaultKeymap(keymap); for (i = 0; i < SDL_arraysize(windows_scancode_table); i++) { - + int vk; /* Make sure this scancode is a valid character scancode */ scancode = windows_scancode_table[i]; - if (scancode == SDL_SCANCODE_UNKNOWN || keymap[scancode] >= 127) { + if (scancode == SDL_SCANCODE_UNKNOWN ) { continue; } - /* Alphabetic keys are handled specially, since Windows remaps them */ - if (i >= 'A' && i <= 'Z') { - BYTE vsc = alpha_scancodes[i - 'A']; - keymap[scancode] = MapVirtualKey(vsc, MAPVK_VSC_TO_VK) + 0x20; - } else { - keymap[scancode] = (MapVirtualKey(i, MAPVK_VK_TO_CHAR) & 0x7FFF); + /* If this key is one of the non-mappable keys, ignore it */ + /* Don't allow the number keys right above the qwerty row to translate or the top left key (grave/backquote) */ + /* Not mapping numbers fixes the French layout, giving numeric keycodes for the number keys, which is the expected behavior */ + if ((keymap[scancode] & SDLK_SCANCODE_MASK) || + scancode == SDL_SCANCODE_GRAVE || + (scancode >= SDL_SCANCODE_1 && scancode <= SDL_SCANCODE_0) ) { + continue; + } + + vk = MapVirtualKey(i, MAPVK_VSC_TO_VK); + if ( vk ) { + int ch = (MapVirtualKey( vk, MAPVK_VK_TO_CHAR ) & 0x7FFF); + if ( ch ) { + if ( ch >= 'A' && ch <= 'Z' ) { + keymap[scancode] = SDLK_a + ( ch - 'A' ); + } else { + keymap[scancode] = ch; + } + } } } + SDL_SetKeymap(0, keymap, SDL_NUM_SCANCODES); } diff --git a/src/video/windows/SDL_windowskeyboard.h b/src/video/windows/SDL_windowskeyboard.h index abe8a63e9b..c79d1d0ff1 100644 --- a/src/video/windows/SDL_windowskeyboard.h +++ b/src/video/windows/SDL_windowskeyboard.h @@ -23,9 +23,6 @@ #ifndef _SDL_windowskeyboard_h #define _SDL_windowskeyboard_h -extern BYTE alpha_scancodes[26]; -extern BYTE keypad_scancodes[10]; - extern void WIN_InitKeyboard(_THIS); extern void WIN_UpdateKeymap(void); extern void WIN_QuitKeyboard(_THIS); diff --git a/src/video/windows/SDL_windowsmessagebox.c b/src/video/windows/SDL_windowsmessagebox.c index 867b468b73..18504cb3c5 100644 --- a/src/video/windows/SDL_windowsmessagebox.c +++ b/src/video/windows/SDL_windowsmessagebox.c @@ -26,11 +26,45 @@ #include "SDL_windowsvideo.h" +#ifndef SS_EDITCONTROL +#define SS_EDITCONTROL 0x2000 +#endif + /* Display a Windows message box */ +#pragma pack(push, 1) + +typedef struct +{ + WORD dlgVer; + WORD signature; + DWORD helpID; + DWORD exStyle; + DWORD style; + WORD cDlgItems; + short x; + short y; + short cx; + short cy; +} DLGTEMPLATEEX; + typedef struct { - LPDLGTEMPLATE lpDialog; + DWORD helpID; + DWORD exStyle; + DWORD style; + short x; + short y; + short cx; + short cy; + DWORD id; +} DLGITEMTEMPLATEEX; + +#pragma pack(pop) + +typedef struct +{ + DLGTEMPLATEEX* lpDialog; Uint8 *data; size_t size; size_t used; @@ -70,7 +104,7 @@ static SDL_bool ExpandDialogSpace(WIN_DialogData *dialog, size_t space) } dialog->data = data; dialog->size = size; - dialog->lpDialog = (LPDLGTEMPLATE)dialog->data; + dialog->lpDialog = (DLGTEMPLATEEX*)dialog->data; } return SDL_TRUE; } @@ -128,21 +162,35 @@ static SDL_bool AddDialogString(WIN_DialogData *dialog, const char *string) return status; } +static int s_BaseUnitsX; +static int s_BaseUnitsY; +static void Vec2ToDLU(short *x, short *y) +{ + SDL_assert(s_BaseUnitsX != 0); // we init in WIN_ShowMessageBox(), which is the only public function... + + *x = MulDiv(*x, 4, s_BaseUnitsX); + *y = MulDiv(*y, 8, s_BaseUnitsY); +} + + static SDL_bool AddDialogControl(WIN_DialogData *dialog, WORD type, DWORD style, DWORD exStyle, int x, int y, int w, int h, int id, const char *caption) { - DLGITEMTEMPLATE item; + DLGITEMTEMPLATEEX item; WORD marker = 0xFFFF; WORD extraData = 0; SDL_zero(item); item.style = style; - item.dwExtendedStyle = exStyle; + item.exStyle = exStyle; item.x = x; item.y = y; item.cx = w; item.cy = h; item.id = id; + Vec2ToDLU(&item.x, &item.y); + Vec2ToDLU(&item.cx, &item.cy); + if (!AlignDialogData(dialog, sizeof(DWORD))) { return SDL_FALSE; } @@ -161,14 +209,14 @@ static SDL_bool AddDialogControl(WIN_DialogData *dialog, WORD type, DWORD style, if (!AddDialogData(dialog, &extraData, sizeof(extraData))) { return SDL_FALSE; } - ++dialog->lpDialog->cdit; + ++dialog->lpDialog->cDlgItems; return SDL_TRUE; } static SDL_bool AddDialogStatic(WIN_DialogData *dialog, int x, int y, int w, int h, const char *text) { - DWORD style = WS_VISIBLE | WS_CHILD | SS_LEFT | SS_NOPREFIX; + DWORD style = WS_VISIBLE | WS_CHILD | SS_LEFT | SS_NOPREFIX | SS_EDITCONTROL; return AddDialogControl(dialog, 0x0082, style, 0, x, y, w, h, -1, text); } @@ -194,14 +242,18 @@ static void FreeDialogData(WIN_DialogData *dialog) static WIN_DialogData *CreateDialogData(int w, int h, const char *caption) { WIN_DialogData *dialog; - DLGTEMPLATE dialogTemplate; + DLGTEMPLATEEX dialogTemplate; + WORD WordToPass; SDL_zero(dialogTemplate); - dialogTemplate.style = (WS_CAPTION | DS_CENTER); + dialogTemplate.dlgVer = 1; + dialogTemplate.signature = 0xffff; + dialogTemplate.style = (WS_CAPTION | DS_CENTER | DS_SHELLFONT); dialogTemplate.x = 0; dialogTemplate.y = 0; dialogTemplate.cx = w; dialogTemplate.cy = h; + Vec2ToDLU(&dialogTemplate.cx, &dialogTemplate.cy); dialog = (WIN_DialogData *)SDL_calloc(1, sizeof(*dialog)); if (!dialog) { @@ -213,17 +265,76 @@ static WIN_DialogData *CreateDialogData(int w, int h, const char *caption) return NULL; } - /* There is no menu or special class */ - if (!AddDialogString(dialog, "") || !AddDialogString(dialog, "")) { + // No menu + WordToPass = 0; + if (!AddDialogData(dialog, &WordToPass, 2)) { FreeDialogData(dialog); return NULL; } + // No custom class + if (!AddDialogData(dialog, &WordToPass, 2)) { + FreeDialogData(dialog); + return NULL; + } + + // title if (!AddDialogString(dialog, caption)) { FreeDialogData(dialog); return NULL; } + // Font stuff + { + // + // We want to use the system messagebox font. + // + BYTE ToPass; + + NONCLIENTMETRICSA NCM; + NCM.cbSize = sizeof(NCM); + SystemParametersInfoA(SPI_GETNONCLIENTMETRICS, 0, &NCM, 0); + + // Font size - convert to logical font size for dialog parameter. + { + HDC ScreenDC = GetDC(0); + WordToPass = (WORD)(-72 * NCM.lfMessageFont.lfHeight / GetDeviceCaps(ScreenDC, LOGPIXELSY)); + ReleaseDC(0, ScreenDC); + } + + if (!AddDialogData(dialog, &WordToPass, 2)) { + FreeDialogData(dialog); + return NULL; + } + + // Font weight + WordToPass = (WORD)NCM.lfMessageFont.lfWeight; + if (!AddDialogData(dialog, &WordToPass, 2)) { + FreeDialogData(dialog); + return NULL; + } + + // italic? + ToPass = NCM.lfMessageFont.lfItalic; + if (!AddDialogData(dialog, &ToPass, 1)) { + FreeDialogData(dialog); + return NULL; + } + + // charset? + ToPass = NCM.lfMessageFont.lfCharSet; + if (!AddDialogData(dialog, &ToPass, 1)) { + FreeDialogData(dialog); + return NULL; + } + + // font typeface. + if (!AddDialogString(dialog, NCM.lfMessageFont.lfFaceName)) { + FreeDialogData(dialog); + return NULL; + } + } + return dialog; } @@ -231,29 +342,114 @@ int WIN_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonid) { WIN_DialogData *dialog; - int i, x, y, w, h, gap, which; + int i, x, y, which; const SDL_MessageBoxButtonData *buttons = messageboxdata->buttons; + HFONT DialogFont; + SIZE Size; + RECT TextSize; + wchar_t* wmessage; + TEXTMETRIC TM; + + + const int ButtonWidth = 88; + const int ButtonHeight = 26; + const int TextMargin = 16; + const int ButtonMargin = 12; - /* FIXME: Need a better algorithm for laying out the message box */ - dialog = CreateDialogData(570, 260, messageboxdata->title); + // Jan 25th, 2013 - dant@fleetsa.com + // + // + // I've tried to make this more reasonable, but I've run in to a lot + // of nonsense. + // + // The original issue is the code was written in pixels and not + // dialog units (DLUs). All DialogBox functions use DLUs, which + // vary based on the selected font (yay). + // + // According to MSDN, the most reliable way to convert is via + // MapDialogUnits, which requires an HWND, which we don't have + // at time of template creation. + // + // We do however have: + // The system font (DLU width 8 for me) + // The font we select for the dialog (DLU width 6 for me) + // + // Based on experimentation, *neither* of these return the value + // actually used. Stepping in to MapDialogUnits(), the conversion + // is fairly clear, and uses 7 for me. + // + // As a result, some of this is hacky to ensure the sizing is + // somewhat correct. + // + // Honestly, a long term solution is to use CreateWindow, not CreateDialog. + // + + // + // In order to get text dimensions we need to have a DC with the desired font. + // I'm assuming a dialog box in SDL is rare enough we can to the create. + // + HDC FontDC = CreateCompatibleDC(0); + + { + // Create a duplicate of the font used in system message boxes. + LOGFONT lf; + NONCLIENTMETRICS NCM; + NCM.cbSize = sizeof(NCM); + SystemParametersInfo(SPI_GETNONCLIENTMETRICS, 0, &NCM, 0); + lf = NCM.lfMessageFont; + DialogFont = CreateFontIndirect(&lf); + } + + // Select the font in to our DC + SelectObject(FontDC, DialogFont); + + { + // Get the metrics to try and figure our DLU conversion. + GetTextMetrics(FontDC, &TM); + s_BaseUnitsX = TM.tmAveCharWidth + 1; + s_BaseUnitsY = TM.tmHeight; + } + + // Measure the *pixel* size of the string. + wmessage = WIN_UTF8ToString(messageboxdata->message); + SDL_zero(TextSize); + Size.cx = DrawText(FontDC, wmessage, -1, &TextSize, DT_CALCRECT); + + // Add some padding for hangs, etc. + TextSize.right += 2; + TextSize.bottom += 2; + + // Done with the DC, and the string + DeleteDC(FontDC); + SDL_free(wmessage); + + // Increase the size of the dialog by some border spacing around the text. + Size.cx = TextSize.right - TextSize.left; + Size.cy = TextSize.bottom - TextSize.top; + Size.cx += TextMargin * 2; + Size.cy += TextMargin * 2; + + // Ensure the size is wide enough for all of the buttons. + if (Size.cx < messageboxdata->numbuttons * (ButtonWidth + ButtonMargin) + ButtonMargin) + Size.cx = messageboxdata->numbuttons * (ButtonWidth + ButtonMargin) + ButtonMargin; + + // Add vertical space for the buttons and border. + Size.cy += ButtonHeight + TextMargin; + + dialog = CreateDialogData(Size.cx, Size.cy, messageboxdata->title); if (!dialog) { return -1; } - w = 100; - h = 25; - gap = 10; - x = gap; - y = 50; - - if (!AddDialogStatic(dialog, x, y, 550, 100, messageboxdata->message)) { + if (!AddDialogStatic(dialog, TextMargin, TextMargin, TextSize.right - TextSize.left, TextSize.bottom - TextSize.top, messageboxdata->message)) { FreeDialogData(dialog); return -1; } - y += 110; - + // Align the buttons to the right/bottom. + x = Size.cx - ButtonWidth - ButtonMargin; + y = Size.cy - ButtonHeight - ButtonMargin; for (i = 0; i < messageboxdata->numbuttons; ++i) { SDL_bool isDefault; @@ -262,15 +458,15 @@ WIN_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonid) } else { isDefault = SDL_FALSE; } - if (!AddDialogButton(dialog, x, y, w, h, buttons[i].text, i, isDefault)) { + if (!AddDialogButton(dialog, x, y, ButtonWidth, ButtonHeight, buttons[i].text, i, isDefault)) { FreeDialogData(dialog); return -1; } - x += w + gap; + x -= ButtonWidth + ButtonMargin; } /* FIXME: If we have a parent window, get the Instance and HWND for them */ - which = DialogBoxIndirect(NULL, dialog->lpDialog, NULL, (DLGPROC)MessageBoxDialogProc); + which = DialogBoxIndirect(NULL, (DLGTEMPLATE*)dialog->lpDialog, NULL, (DLGPROC)MessageBoxDialogProc); *buttonid = buttons[which].buttonid; FreeDialogData(dialog); diff --git a/src/video/windows/SDL_windowsmodes.c b/src/video/windows/SDL_windowsmodes.c index 30922c8035..97ddc736d8 100644 --- a/src/video/windows/SDL_windowsmodes.c +++ b/src/video/windows/SDL_windowsmodes.c @@ -214,8 +214,7 @@ WIN_InitModes(_THIS) } } if (_this->num_displays == 0) { - SDL_SetError("No displays available"); - return -1; + return SDL_SetError("No displays available"); } return 0; } @@ -282,8 +281,7 @@ WIN_SetDisplayMode(_THIS, SDL_VideoDisplay * display, SDL_DisplayMode * mode) reason = "DISP_CHANGE_FAILED"; break; } - SDL_SetError("ChangeDisplaySettingsEx() failed: %s", reason); - return -1; + return SDL_SetError("ChangeDisplaySettingsEx() failed: %s", reason); } EnumDisplaySettings(displaydata->DeviceName, ENUM_CURRENT_SETTINGS, &data->DeviceMode); return 0; diff --git a/src/video/windows/SDL_windowsmouse.c b/src/video/windows/SDL_windowsmouse.c index 8306f67090..23f288b190 100644 --- a/src/video/windows/SDL_windowsmouse.c +++ b/src/video/windows/SDL_windowsmouse.c @@ -196,8 +196,7 @@ WIN_SetRelativeMouseMode(SDL_bool enabled) /* Only return an error when registering. If we unregister and fail, then it's probably that we unregistered twice. That's OK. */ if(enabled) { - SDL_Unsupported(); - return -1; + return SDL_Unsupported(); } } diff --git a/src/video/windows/SDL_windowsopengl.c b/src/video/windows/SDL_windowsopengl.c index e77b923e7d..97cbaffc42 100644 --- a/src/video/windows/SDL_windowsopengl.c +++ b/src/video/windows/SDL_windowsopengl.c @@ -91,8 +91,7 @@ WIN_GL_LoadLibrary(_THIS, const char *path) char message[1024]; SDL_snprintf(message, SDL_arraysize(message), "LoadLibrary(\"%s\")", path); - WIN_SetError(message); - return -1; + return WIN_SetError(message); } SDL_strlcpy(_this->gl_config.driver_path, path, SDL_arraysize(_this->gl_config.driver_path)); @@ -103,8 +102,7 @@ WIN_GL_LoadLibrary(_THIS, const char *path) sizeof(struct SDL_GLDriverData)); if (!_this->gl_data) { - SDL_OutOfMemory(); - return -1; + return SDL_OutOfMemory(); } /* Load function pointers */ @@ -124,9 +122,8 @@ WIN_GL_LoadLibrary(_THIS, const char *path) !_this->gl_data->wglCreateContext || !_this->gl_data->wglDeleteContext || !_this->gl_data->wglMakeCurrent) { - SDL_SetError("Could not retrieve OpenGL functions"); SDL_UnloadObject(handle); - return -1; + return SDL_SetError("Could not retrieve OpenGL functions"); } return 0; @@ -512,12 +509,10 @@ WIN_GL_SetupWindow(_THIS, SDL_Window * window) pixel_format = WIN_GL_ChoosePixelFormat(hdc, &pfd); } if (!pixel_format) { - SDL_SetError("No matching GL pixel format available"); - return -1; + return SDL_SetError("No matching GL pixel format available"); } if (!SetPixelFormat(hdc, pixel_format, &pfd)) { - WIN_SetError("SetPixelFormat()"); - return (-1); + return WIN_SetError("SetPixelFormat()"); } return 0; } @@ -611,11 +606,9 @@ int WIN_GL_MakeCurrent(_THIS, SDL_Window * window, SDL_GLContext context) { HDC hdc; - int status; if (!_this->gl_data) { - SDL_SetError("OpenGL not initialized"); - return -1; + return SDL_SetError("OpenGL not initialized"); } if (window) { @@ -624,30 +617,24 @@ WIN_GL_MakeCurrent(_THIS, SDL_Window * window, SDL_GLContext context) hdc = NULL; } if (!_this->gl_data->wglMakeCurrent(hdc, (HGLRC) context)) { - WIN_SetError("wglMakeCurrent()"); - status = -1; - } else { - status = 0; + return WIN_SetError("wglMakeCurrent()"); } - return status; + return 0; } int WIN_GL_SetSwapInterval(_THIS, int interval) { - int retval = -1; if ((interval < 0) && (!_this->gl_data->HAS_WGL_EXT_swap_control_tear)) { - SDL_SetError("Negative swap interval unsupported in this GL"); + return SDL_SetError("Negative swap interval unsupported in this GL"); } else if (_this->gl_data->wglSwapIntervalEXT) { - if (_this->gl_data->wglSwapIntervalEXT(interval) == TRUE) { - retval = 0; - } else { - WIN_SetError("wglSwapIntervalEXT()"); + if (_this->gl_data->wglSwapIntervalEXT(interval) != TRUE) { + return WIN_SetError("wglSwapIntervalEXT()"); } } else { - SDL_Unsupported(); + return SDL_Unsupported(); } - return retval; + return 0; } int diff --git a/src/video/windows/SDL_windowsvideo.c b/src/video/windows/SDL_windowsvideo.c index 5d016e7c3a..c64749f4f0 100644 --- a/src/video/windows/SDL_windowsvideo.c +++ b/src/video/windows/SDL_windowsvideo.c @@ -75,10 +75,10 @@ WIN_CreateDevice(int devindex) data = NULL; } if (!data) { - SDL_OutOfMemory(); if (device) { SDL_free(device); } + SDL_OutOfMemory(); return NULL; } device->driverdata = data; diff --git a/src/video/windows/SDL_windowsvideo.h b/src/video/windows/SDL_windowsvideo.h index 8a3c737ed5..199a8ba8f1 100644 --- a/src/video/windows/SDL_windowsvideo.h +++ b/src/video/windows/SDL_windowsvideo.h @@ -115,7 +115,6 @@ typedef struct SDL_VideoData { int render; - const SDL_Scancode *key_layout; DWORD clipboard_count; /* Touch input functions */ diff --git a/src/video/windows/SDL_windowswindow.c b/src/video/windows/SDL_windowswindow.c index b6c46c34ec..8003492357 100644 --- a/src/video/windows/SDL_windowswindow.c +++ b/src/video/windows/SDL_windowswindow.c @@ -82,14 +82,13 @@ SetupWindowData(_THIS, SDL_Window * window, HWND hwnd, SDL_bool created) /* Allocate the window data */ data = (SDL_WindowData *) SDL_malloc(sizeof(*data)); if (!data) { - SDL_OutOfMemory(); - return -1; + return SDL_OutOfMemory(); } data->window = window; data->hwnd = hwnd; data->hdc = GetDC(hwnd); data->created = created; - data->mouse_pressed = SDL_FALSE; + data->mouse_button_flags = 0; data->videodata = videodata; window->driverdata = data; @@ -98,8 +97,7 @@ SetupWindowData(_THIS, SDL_Window * window, HWND hwnd, SDL_bool created) if (!SetProp(hwnd, TEXT("SDL_WindowData"), data)) { ReleaseDC(hwnd, data->hdc); SDL_free(data); - WIN_SetError("SetProp() failed"); - return -1; + return WIN_SetError("SetProp() failed"); } /* Set up the window proc function */ @@ -221,8 +219,7 @@ WIN_CreateWindow(_THIS, SDL_Window * window) CreateWindow(SDL_Appname, TEXT(""), style, x, y, w, h, NULL, NULL, SDL_Instance, NULL); if (!hwnd) { - WIN_SetError("Couldn't create window"); - return -1; + return WIN_SetError("Couldn't create window"); } WIN_PumpEvents(_this); @@ -635,8 +632,7 @@ SDL_HelperWindowCreate(void) /* Register the class. */ SDL_HelperWindowClass = RegisterClass(&wce); if (SDL_HelperWindowClass == 0) { - WIN_SetError("Unable to create Helper Window Class"); - return -1; + return WIN_SetError("Unable to create Helper Window Class"); } /* Create the window. */ @@ -648,8 +644,7 @@ SDL_HelperWindowCreate(void) hInstance, NULL); if (SDL_HelperWindow == NULL) { UnregisterClass(SDL_HelperWindowClassName, hInstance); - WIN_SetError("Unable to create Helper Window"); - return -1; + return WIN_SetError("Unable to create Helper Window"); } return 0; diff --git a/src/video/windows/SDL_windowswindow.h b/src/video/windows/SDL_windowswindow.h index f4002558f5..7339d78128 100644 --- a/src/video/windows/SDL_windowswindow.h +++ b/src/video/windows/SDL_windowswindow.h @@ -32,7 +32,7 @@ typedef struct HBITMAP hbm; WNDPROC wndproc; SDL_bool created; - int mouse_pressed; + WPARAM mouse_button_flags; struct SDL_VideoData *videodata; } SDL_WindowData; diff --git a/src/video/windowsrt/SDL_WinRTApp.cpp b/src/video/windowsrt/SDL_WinRTApp.cpp index f8e9b444a1..a7461e3b2c 100644 --- a/src/video/windowsrt/SDL_WinRTApp.cpp +++ b/src/video/windowsrt/SDL_WinRTApp.cpp @@ -407,7 +407,7 @@ void SDL_WinRTApp::OnPointerPressed(CoreWindow^ sender, PointerEventArgs^ args) if (m_sdlWindowData) {
Uint8 button = WINRT_GetSDLButtonForPointerPoint(args->CurrentPoint);
if (button) {
- SDL_SendMouseButton(m_sdlWindowData->sdlWindow, SDL_PRESSED, button);
+ SDL_SendMouseButton(m_sdlWindowData->sdlWindow, 0, SDL_PRESSED, button);
}
}
}
@@ -421,7 +421,7 @@ void SDL_WinRTApp::OnPointerReleased(CoreWindow^ sender, PointerEventArgs^ args) if (m_sdlWindowData) {
Uint8 button = WINRT_GetSDLButtonForPointerPoint(args->CurrentPoint);
if (button) {
- SDL_SendMouseButton(m_sdlWindowData->sdlWindow, SDL_RELEASED, button);
+ SDL_SendMouseButton(m_sdlWindowData->sdlWindow, 0, SDL_RELEASED, button);
}
}
}
@@ -435,7 +435,7 @@ void SDL_WinRTApp::OnPointerWheelChanged(CoreWindow^ sender, PointerEventArgs^ a if (m_sdlWindowData) {
// FIXME: This may need to accumulate deltas up to WHEEL_DELTA
short motion = args->CurrentPoint->Properties->MouseWheelDelta / WHEEL_DELTA;
- SDL_SendMouseWheel(m_sdlWindowData->sdlWindow, 0, motion);
+ SDL_SendMouseWheel(m_sdlWindowData->sdlWindow, 0, 0, motion);
}
}
@@ -510,6 +510,7 @@ void SDL_WinRTApp::OnMouseMoved(MouseDevice^ mouseDevice, MouseEventArgs^ args) const Point mouseDeltaInSDLWindowCoords = TransformCursor(mouseDeltaInDIPs);
SDL_SendMouseMotion(
m_sdlWindowData->sdlWindow,
+ 0,
1,
_lround(mouseDeltaInSDLWindowCoords.X),
_lround(mouseDeltaInSDLWindowCoords.Y));
@@ -534,7 +535,7 @@ void SDL_WinRTApp::OnPointerMoved(CoreWindow^ sender, PointerEventArgs^ args) if (m_sdlWindowData && ! m_useRelativeMouseMode)
{
Point transformedPoint = TransformCursor(args->CurrentPoint->Position);
- SDL_SendMouseMotion(m_sdlWindowData->sdlWindow, 0, (int)transformedPoint.X, (int)transformedPoint.Y);
+ SDL_SendMouseMotion(m_sdlWindowData->sdlWindow, 0, 0, (int)transformedPoint.X, (int)transformedPoint.Y);
}
}
diff --git a/src/video/x11/SDL_x11clipboard.c b/src/video/x11/SDL_x11clipboard.c index 4ab18576b1..0c3b000e03 100644 --- a/src/video/x11/SDL_x11clipboard.c +++ b/src/video/x11/SDL_x11clipboard.c @@ -59,8 +59,7 @@ X11_SetClipboardText(_THIS, const char *text) /* Get the SDL window that will own the selection */ window = GetWindow(_this); if (window == None) { - SDL_SetError("Couldn't find a window to own the selection"); - return -1; + return SDL_SetError("Couldn't find a window to own the selection"); } /* Save the selection on the root window */ diff --git a/src/video/x11/SDL_x11events.c b/src/video/x11/SDL_x11events.c index a377d4cec4..6c54e9dc93 100644 --- a/src/video/x11/SDL_x11events.c +++ b/src/video/x11/SDL_x11events.c @@ -41,12 +41,62 @@ #include <stdio.h> -#ifdef SDL_INPUT_LINUXEV -/* Touch Input/event* includes */ -#include <linux/input.h> -#include <fcntl.h> -#endif +typedef struct { + unsigned char *data; + int format, count; + Atom type; +} SDL_x11Prop; + +/* Reads property + Must call XFree on results + */ +static void X11_ReadProperty(SDL_x11Prop *p, Display *disp, Window w, Atom prop) +{ + unsigned char *ret=NULL; + Atom type; + int fmt; + unsigned long count; + unsigned long bytes_left; + int bytes_fetch = 0; + + do { + if (ret != 0) XFree(ret); + XGetWindowProperty(disp, w, prop, 0, bytes_fetch, False, AnyPropertyType, &type, &fmt, &count, &bytes_left, &ret); + bytes_fetch += bytes_left; + } while (bytes_left != 0); + + p->data=ret; + p->format=fmt; + p->count=count; + p->type=type; +} + +/* Find text-uri-list in a list of targets and return it's atom + if available, else return None */ +static Atom X11_PickTarget(Display *disp, Atom list[], int list_count) +{ + Atom request = None; + char *name; + int i; + for (i=0; i < list_count && request == None; i++) { + name = XGetAtomName(disp, list[i]); + if (strcmp("text/uri-list", name)==0) request = list[i]; + XFree(name); + } + return request; +} +/* Wrapper for X11_PickTarget for a maximum of three targets, a special + case in the Xdnd protocol */ +static Atom X11_PickTargetFromAtoms(Display *disp, Atom a0, Atom a1, Atom a2) +{ + int count=0; + Atom atom[3]; + if (a0 != None) atom[count++] = a0; + if (a1 != None) atom[count++] = a1; + if (a2 != None) atom[count++] = a2; + return X11_PickTarget(disp, atom, count); +} /*#define DEBUG_XEVENTS*/ /* Check to see if this is a repeated key. @@ -98,6 +148,41 @@ static SDL_bool X11_IsWheelEvent(Display * display,XEvent * event,int * ticks) return SDL_FALSE; } +/* Convert URI to local filename + return filename if possible, else NULL +*/ +static char* X11_URIToLocal(char* uri) { + char *file = NULL; + + if (memcmp(uri,"file:/",6) == 0) uri += 6; /* local file? */ + else if (strstr(uri,":/") != NULL) return file; /* wrong scheme */ + + SDL_bool local = uri[0] != '/' || ( uri[0] != '\0' && uri[1] == '/' ); + + /* got a hostname? */ + if ( !local && uri[0] == '/' && uri[2] != '/' ) { + char* hostname_end = strchr( uri+1, '/' ); + if ( hostname_end != NULL ) { + char hostname[ 257 ]; + if ( gethostname( hostname, 255 ) == 0 ) { + hostname[ 256 ] = '\0'; + if ( memcmp( uri+1, hostname, hostname_end - ( uri+1 )) == 0 ) { + uri = hostname_end + 1; + local = SDL_TRUE; + } + } + } + } + if ( local ) { + file = uri; + if ( uri[1] == '/' ) { + file++; + } else { + file--; + } + } + return file; +} #if SDL_VIDEO_DRIVER_X11_SUPPORTS_GENERIC_EVENTS static void X11_HandleGenericEvent(SDL_VideoData *videodata,XEvent event) @@ -406,7 +491,68 @@ X11_DispatchEvent(_THIS) /* Have we been requested to quit (or another client message?) */ case ClientMessage:{ - if ((xevent.xclient.message_type == videodata->WM_PROTOCOLS) && + + int xdnd_version=0; + + if (xevent.xclient.message_type == videodata->XdndEnter) { + SDL_bool use_list = xevent.xclient.data.l[1] & 1; + data->xdnd_source = xevent.xclient.data.l[0]; + xdnd_version = ( xevent.xclient.data.l[1] >> 24); + if (use_list) { + /* fetch conversion targets */ + SDL_x11Prop p; + X11_ReadProperty(&p, display, data->xdnd_source, videodata->XdndTypeList); + /* pick one */ + data->xdnd_req = X11_PickTarget(display, (Atom*)p.data, p.count); + XFree(p.data); + } else { + /* pick from list of three */ + data->xdnd_req = X11_PickTargetFromAtoms(display, xevent.xclient.data.l[2], xevent.xclient.data.l[3], xevent.xclient.data.l[4]); + } + } + else if (xevent.xclient.message_type == videodata->XdndPosition) { + + /* reply with status */ + XClientMessageEvent m; + memset(&m, 0, sizeof(XClientMessageEvent)); + m.type = ClientMessage; + m.display = xevent.xclient.display; + m.window = xevent.xclient.data.l[0]; + m.message_type = videodata->XdndStatus; + m.format=32; + m.data.l[0] = data->xwindow; + m.data.l[1] = (data->xdnd_req != None); + m.data.l[2] = 0; /* specify an empty rectangle */ + m.data.l[3] = 0; + m.data.l[4] = videodata->XdndActionCopy; /* we only accept copying anyway */ + + XSendEvent(display, xevent.xclient.data.l[0], False, NoEventMask, (XEvent*)&m); + XFlush(display); + } + else if(xevent.xclient.message_type == videodata->XdndDrop) { + if (data->xdnd_req == None) { + /* say again - not interested! */ + XClientMessageEvent m; + memset(&m, 0, sizeof(XClientMessageEvent)); + m.type = ClientMessage; + m.display = xevent.xclient.display; + m.window = xevent.xclient.data.l[0]; + m.message_type = videodata->XdndFinished; + m.format=32; + m.data.l[0] = data->xwindow; + m.data.l[1] = 0; + m.data.l[2] = None; /* fail! */ + XSendEvent(display, xevent.xclient.data.l[0], False, NoEventMask, (XEvent*)&m); + } else { + /* convert */ + if(xdnd_version >= 1) { + XConvertSelection(display, videodata->XdndSelection, data->xdnd_req, videodata->PRIMARY, data->xwindow, xevent.xclient.data.l[2]); + } else { + XConvertSelection(display, videodata->XdndSelection, data->xdnd_req, videodata->PRIMARY, data->xwindow, CurrentTime); + } + } + } + else if ((xevent.xclient.message_type == videodata->WM_PROTOCOLS) && (xevent.xclient.format == 32) && (xevent.xclient.data.l[0] == videodata->_NET_WM_PING)) { Window root = DefaultRootWindow(display); @@ -448,24 +594,23 @@ X11_DispatchEvent(_THIS) printf("window %p: X11 motion: %d,%d\n", xevent.xmotion.x, xevent.xmotion.y); #endif - SDL_SendMouseMotion(data->window, 0, xevent.xmotion.x, xevent.xmotion.y); + SDL_SendMouseMotion(data->window, 0, 0, xevent.xmotion.x, xevent.xmotion.y); } } break; case ButtonPress:{ int ticks = 0; - if (X11_IsWheelEvent(display,&xevent,&ticks) == SDL_TRUE) { - SDL_SendMouseWheel(data->window, 0, ticks); - } - else { - SDL_SendMouseButton(data->window, SDL_PRESSED, xevent.xbutton.button); + if (X11_IsWheelEvent(display,&xevent,&ticks)) { + SDL_SendMouseWheel(data->window, 0, 0, ticks); + } else { + SDL_SendMouseButton(data->window, 0, SDL_PRESSED, xevent.xbutton.button); } } break; case ButtonRelease:{ - SDL_SendMouseButton(data->window, SDL_RELEASED, xevent.xbutton.button); + SDL_SendMouseButton(data->window, 0, SDL_RELEASED, xevent.xbutton.button); } break; @@ -590,11 +735,19 @@ X11_DispatchEvent(_THIS) XA_CUT_BUFFER0, 0, INT_MAX/4, False, req->target, &sevent.xselection.target, &seln_format, &nbytes, &overflow, &seln_data) == Success) { + Atom XA_TARGETS = XInternAtom(display, "TARGETS", 0); if (sevent.xselection.target == req->target) { XChangeProperty(display, req->requestor, req->property, sevent.xselection.target, seln_format, PropModeReplace, seln_data, nbytes); sevent.xselection.property = req->property; + } else if (XA_TARGETS == req->target) { + Atom SupportedFormats[] = { sevent.xselection.target, XA_TARGETS }; + XChangeProperty(display, req->requestor, req->property, + XA_ATOM, 32, PropModeReplace, + (unsigned char*)SupportedFormats, + sizeof(SupportedFormats)/sizeof(*SupportedFormats)); + sevent.xselection.property = req->property; } XFree(seln_data); } @@ -608,7 +761,66 @@ X11_DispatchEvent(_THIS) printf("window %p: SelectionNotify (requestor = %ld, target = %ld)\n", data, xevent.xselection.requestor, xevent.xselection.target); #endif - videodata->selection_waiting = SDL_FALSE; + Atom target = xevent.xselection.target; + if (target == data->xdnd_req) { + + /* read data */ + SDL_x11Prop p; + X11_ReadProperty(&p, display, data->xwindow, videodata->PRIMARY); + + if(p.format==8) { + SDL_bool expect_lf = SDL_FALSE; + char *start = NULL; + char *scan = (char*)p.data; + char *fn; + char *uri; + int length = 0; + while (p.count--) { + if (!expect_lf) { + if (*scan==0x0D) { + expect_lf = SDL_TRUE; + } else if(start == NULL) { + start = scan; + length = 0; + } + length++; + } else { + if (*scan==0x0A && length>0) { + uri = malloc(length--); + memcpy(uri, start, length); + uri[length] = 0; + fn = X11_URIToLocal(uri); + if (fn) SDL_SendDropFile(fn); + free(uri); + } + expect_lf = SDL_FALSE; + start = NULL; + } + scan++; + } + } + + XFree(p.data); + + /* send reply */ + XClientMessageEvent m; + memset(&m, 0, sizeof(XClientMessageEvent)); + m.type = ClientMessage; + m.display = display; + m.window = data->xdnd_source; + m.message_type = videodata->XdndFinished; + m.format=32; + m.data.l[0] = data->xwindow; + m.data.l[1] = 1; + m.data.l[2] = videodata->XdndActionCopy; + XSendEvent(display, data->xdnd_source, False, NoEventMask, (XEvent*)&m); + + XSync(display, False); + + } else { + videodata->selection_waiting = SDL_FALSE; + } + } break; @@ -704,90 +916,6 @@ X11_PumpEvents(_THIS) /* FIXME: Only need to do this when there are pending focus changes */ X11_HandleFocusChanges(_this); - - /*Dont process evtouch events if XInput2 multitouch is supported*/ - if(X11_Xinput2IsMultitouchSupported()) { - return; - } - -#ifdef SDL_INPUT_LINUXEV - /* Process Touch events*/ - int i = 0,rd; - struct input_event ev[64]; - int size = sizeof (struct input_event); - -/* !!! FIXME: clean the tabstops out of here. */ - for(i = 0;i < SDL_GetNumTouch();++i) { - SDL_Touch* touch = SDL_GetTouchIndex(i); - if(!touch) printf("Touch %i/%i DNE\n",i,SDL_GetNumTouch()); - EventTouchData* data; - data = (EventTouchData*)(touch->driverdata); - if(data == NULL) { - printf("No driver data\n"); - continue; - } - if(data->eventStream <= 0) - printf("Error: Couldn't open stream\n"); - rd = read(data->eventStream, ev, size * 64); - if(rd >= size) { - for (i = 0; i < rd / sizeof(struct input_event); i++) { - switch (ev[i].type) { - case EV_ABS: - switch (ev[i].code) { - case ABS_X: - data->x = ev[i].value; - break; - case ABS_Y: - data->y = ev[i].value; - break; - case ABS_PRESSURE: - data->pressure = ev[i].value; - if(data->pressure < 0) data->pressure = 0; - break; - case ABS_MISC: - if(ev[i].value == 0) - data->up = SDL_TRUE; - break; - } - break; - case EV_MSC: - if(ev[i].code == MSC_SERIAL) - data->finger = ev[i].value; - break; - case EV_KEY: - if(ev[i].code == BTN_TOUCH) - if(ev[i].value == 0) - data->up = SDL_TRUE; - break; - case EV_SYN: - if(!data->down) { - data->down = SDL_TRUE; - SDL_SendFingerDown(touch->id,data->finger, - data->down, data->x, data->y, - data->pressure); - } - else if(!data->up) - SDL_SendTouchMotion(touch->id,data->finger, - SDL_FALSE, data->x,data->y, - data->pressure); - else - { - data->down = SDL_FALSE; - SDL_SendFingerDown(touch->id,data->finger, - data->down, data->x,data->y, - data->pressure); - data->x = -1; - data->y = -1; - data->pressure = -1; - data->finger = 0; - data->up = SDL_FALSE; - } - break; - } - } - } - } -#endif } diff --git a/src/video/x11/SDL_x11framebuffer.c b/src/video/x11/SDL_x11framebuffer.c index f7717416d4..0c8febe4af 100644 --- a/src/video/x11/SDL_x11framebuffer.c +++ b/src/video/x11/SDL_x11framebuffer.c @@ -68,20 +68,17 @@ X11_CreateWindowFramebuffer(_THIS, SDL_Window * window, Uint32 * format, gcv.graphics_exposures = False; data->gc = XCreateGC(display, data->xwindow, GCGraphicsExposures, &gcv); if (!data->gc) { - SDL_SetError("Couldn't create graphics context"); - return -1; + return SDL_SetError("Couldn't create graphics context"); } /* Find out the pixel format and depth */ if (X11_GetVisualInfoFromVisual(display, data->visual, &vinfo) < 0) { - SDL_SetError("Couldn't get window visual information"); - return -1; + return SDL_SetError("Couldn't get window visual information"); } *format = X11_GetPixelFormatFromVisualInfo(display, &vinfo); if (*format == SDL_PIXELFORMAT_UNKNOWN) { - SDL_SetError("Unknown window pixel format"); - return -1; + return SDL_SetError("Unknown window pixel format"); } /* Calculate pitch */ @@ -132,8 +129,7 @@ X11_CreateWindowFramebuffer(_THIS, SDL_Window * window, Uint32 * format, *pixels = SDL_malloc(window->h*(*pitch)); if (*pixels == NULL) { - SDL_OutOfMemory(); - return -1; + return SDL_OutOfMemory(); } data->ximage = XCreateImage(display, data->visual, @@ -141,14 +137,13 @@ X11_CreateWindowFramebuffer(_THIS, SDL_Window * window, Uint32 * format, window->w, window->h, 32, 0); if (!data->ximage) { SDL_free(*pixels); - SDL_SetError("Couldn't create XImage"); - return -1; + return SDL_SetError("Couldn't create XImage"); } return 0; } int -X11_UpdateWindowFramebuffer(_THIS, SDL_Window * window, SDL_Rect * rects, +X11_UpdateWindowFramebuffer(_THIS, SDL_Window * window, const SDL_Rect * rects, int numrects) { SDL_WindowData *data = (SDL_WindowData *) window->driverdata; diff --git a/src/video/x11/SDL_x11framebuffer.h b/src/video/x11/SDL_x11framebuffer.h index a538ef9560..8e4c21ae75 100644 --- a/src/video/x11/SDL_x11framebuffer.h +++ b/src/video/x11/SDL_x11framebuffer.h @@ -25,7 +25,7 @@ extern int X11_CreateWindowFramebuffer(_THIS, SDL_Window * window, Uint32 * format, void ** pixels, int *pitch); extern int X11_UpdateWindowFramebuffer(_THIS, SDL_Window * window, - SDL_Rect * rects, int numrects); + const SDL_Rect * rects, int numrects); extern void X11_DestroyWindowFramebuffer(_THIS, SDL_Window * window); /* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/video/x11/SDL_x11messagebox.c b/src/video/x11/SDL_x11messagebox.c index 620194c6b2..47cac1c664 100644 --- a/src/video/x11/SDL_x11messagebox.c +++ b/src/video/x11/SDL_x11messagebox.c @@ -168,8 +168,7 @@ X11_MessageBoxInit( SDL_MessageBoxDataX11 *data, const SDL_MessageBoxData * mess const SDL_MessageBoxColor *colorhints; if ( numbuttons > MAX_BUTTONS ) { - SDL_SetError("Too many buttons (%d max allowed)", MAX_BUTTONS); - return -1; + return SDL_SetError("Too many buttons (%d max allowed)", MAX_BUTTONS); } data->dialog_width = MIN_DIALOG_WIDTH; @@ -181,8 +180,7 @@ X11_MessageBoxInit( SDL_MessageBoxDataX11 *data, const SDL_MessageBoxData * mess data->display = XOpenDisplay( NULL ); if ( !data->display ) { - SDL_SetError("Couldn't open X11 display"); - return -1; + return SDL_SetError("Couldn't open X11 display"); } if (SDL_X11_HAVE_UTF8) { @@ -194,14 +192,12 @@ X11_MessageBoxInit( SDL_MessageBoxDataX11 *data, const SDL_MessageBoxData * mess XFreeStringList(missing); } if ( data->font_set == NULL ) { - SDL_SetError("Couldn't load font %s", g_MessageBoxFont); - return -1; + return SDL_SetError("Couldn't load font %s", g_MessageBoxFont); } } else { data->font_struct = XLoadQueryFont( data->display, g_MessageBoxFontLatin1 ); if ( data->font_struct == NULL ) { - SDL_SetError("Couldn't load font %s", g_MessageBoxFontLatin1); - return -1; + return SDL_SetError("Couldn't load font %s", g_MessageBoxFontLatin1); } } @@ -388,8 +384,7 @@ X11_MessageBoxCreateWindow( SDL_MessageBoxDataX11 *data ) 0, CopyFromParent, InputOutput, CopyFromParent, CWEventMask, &wnd_attr ); if ( data->window == None ) { - SDL_SetError("Couldn't create X window"); - return -1; + return SDL_SetError("Couldn't create X window"); } if ( windowdata ) { @@ -520,8 +515,7 @@ X11_MessageBoxLoop( SDL_MessageBoxDataX11 *data ) ctx = XCreateGC( data->display, data->window, gcflags, &ctx_vals ); if ( ctx == None ) { - SDL_SetError("Couldn't create graphics context"); - return -1; + return SDL_SetError("Couldn't create graphics context"); } data->button_press_index = -1; /* Reset what button is currently depressed. */ @@ -660,8 +654,7 @@ X11_ShowMessageBoxImpl(const SDL_MessageBoxData *messageboxdata, int *buttonid) if (origlocale != NULL) { origlocale = SDL_strdup(origlocale); if (origlocale == NULL) { - SDL_OutOfMemory(); - return -1; + return SDL_OutOfMemory(); } setlocale(LC_ALL, ""); } @@ -739,8 +732,7 @@ X11_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonid) SDL_assert(rc == pid); /* not sure what to do if this fails. */ if ((rc == -1) || (!WIFEXITED(status)) || (WEXITSTATUS(status) != 0)) { - SDL_SetError("msgbox child process failed"); - return -1; + return SDL_SetError("msgbox child process failed"); } if (read(fds[0], &status, sizeof (int)) != sizeof (int)) diff --git a/src/video/x11/SDL_x11modes.c b/src/video/x11/SDL_x11modes.c index e7822f0576..60363b4919 100644 --- a/src/video/x11/SDL_x11modes.c +++ b/src/video/x11/SDL_x11modes.c @@ -576,26 +576,31 @@ X11_InitModes(_THIS) int actual_format; unsigned long nitems, bytes_after; Atom actual_type; - + if (props[i] == EDID) { - XRRGetOutputProperty(data->display, res->outputs[output], props[i], - 0, 100, False, False, - AnyPropertyType, - &actual_type, &actual_format, - &nitems, &bytes_after, &prop); - - MonitorInfo *info = decode_edid(prop); - if (info) { -#ifdef X11MODES_DEBUG - printf("Found EDID data for %s\n", output_info->name); - dump_monitor_info(info); -#endif - SDL_strlcpy(display_name, info->dsc_product_name, sizeof(display_name)); - free(info); + if (XRRGetOutputProperty(data->display, + res->outputs[output], props[i], + 0, 100, False, False, + AnyPropertyType, + &actual_type, &actual_format, + &nitems, &bytes_after, &prop) == Success ) { + MonitorInfo *info = decode_edid(prop); + if (info) { + #ifdef X11MODES_DEBUG + printf("Found EDID data for %s\n", output_info->name); + dump_monitor_info(info); + #endif + SDL_strlcpy(display_name, info->dsc_product_name, sizeof(display_name)); + free(info); + } + XFree(prop); } break; } } + if (props) { + XFree(props); + } if (*display_name && inches) { size_t len = SDL_strlen(display_name); @@ -651,8 +656,7 @@ X11_InitModes(_THIS) #endif if (_this->num_displays == 0) { - SDL_SetError("No available displays"); - return -1; + return SDL_SetError("No available displays"); } return 0; } @@ -793,23 +797,20 @@ X11_SetDisplayMode(_THIS, SDL_VideoDisplay * sdl_display, SDL_DisplayMode * mode res = XRRGetScreenResources (display, RootWindow(display, data->screen)); if (!res) { - SDL_SetError("Couldn't get XRandR screen resources"); - return -1; + return SDL_SetError("Couldn't get XRandR screen resources"); } output_info = XRRGetOutputInfo(display, res, data->xrandr_output); if (!output_info || output_info->connection == RR_Disconnected) { - SDL_SetError("Couldn't get XRandR output info"); XRRFreeScreenResources(res); - return -1; + return SDL_SetError("Couldn't get XRandR output info"); } crtc = XRRGetCrtcInfo(display, res, output_info->crtc); if (!crtc) { - SDL_SetError("Couldn't get XRandR crtc info"); XRRFreeOutputInfo(output_info); XRRFreeScreenResources(res); - return -1; + return SDL_SetError("Couldn't get XRandR crtc info"); } status = XRRSetCrtcConfig (display, res, output_info->crtc, CurrentTime, @@ -821,8 +822,7 @@ X11_SetDisplayMode(_THIS, SDL_VideoDisplay * sdl_display, SDL_DisplayMode * mode XRRFreeScreenResources(res); if (status != Success) { - SDL_SetError("XRRSetCrtcConfig failed"); - return -1; + return SDL_SetError("XRRSetCrtcConfig failed"); } } #endif /* SDL_VIDEO_DRIVER_X11_XRANDR */ diff --git a/src/video/x11/SDL_x11opengl.c b/src/video/x11/SDL_x11opengl.c index 0c3ab50659..8e6614bef8 100644 --- a/src/video/x11/SDL_x11opengl.c +++ b/src/video/x11/SDL_x11opengl.c @@ -136,8 +136,7 @@ X11_GL_LoadLibrary(_THIS, const char *path) void *handle; if (_this->gl_data) { - SDL_SetError("OpenGL context already created"); - return -1; + return SDL_SetError("OpenGL context already created"); } /* If SDL_GL_CONTEXT_EGL has been changed to 1, switch over to X11_GLES functions */ @@ -154,8 +153,7 @@ X11_GL_LoadLibrary(_THIS, const char *path) _this->GL_DeleteContext = X11_GLES_DeleteContext; return X11_GLES_LoadLibrary(_this, path); #else - SDL_SetError("SDL not configured with OpenGL ES/EGL support"); - return -1; + return SDL_SetError("SDL not configured with OpenGL ES/EGL support"); #endif } @@ -183,8 +181,7 @@ X11_GL_LoadLibrary(_THIS, const char *path) sizeof(struct SDL_GLDriverData)); if (!_this->gl_data) { - SDL_OutOfMemory(); - return -1; + return SDL_OutOfMemory(); } /* Load function pointers */ @@ -216,8 +213,7 @@ X11_GL_LoadLibrary(_THIS, const char *path) !_this->gl_data->glXDestroyContext || !_this->gl_data->glXMakeCurrent || !_this->gl_data->glXSwapBuffers) { - SDL_SetError("Could not retrieve OpenGL functions"); - return -1; + return SDL_SetError("Could not retrieve OpenGL functions"); } /* Initialize extensions */ @@ -496,6 +492,33 @@ X11_GL_GetVisual(_THIS, Display * display, int screen) return vinfo; } +#ifndef GLXBadContext +#define GLXBadContext 0 +#endif +#ifndef GLXBadFBConfig +#define GLXBadFBConfig 9 +#endif +#ifndef GLXBadProfileARB +#define GLXBadProfileARB 13 +#endif +static int (*handler) (Display *, XErrorEvent *) = NULL; +static int +X11_GL_CreateContextErrorHandler(Display * d, XErrorEvent * e) +{ + switch (e->error_code) { + case GLXBadContext: + case GLXBadFBConfig: + case GLXBadProfileARB: + case BadRequest: + case BadMatch: + case BadValue: + case BadAlloc: + return (0); + default: + return (handler(d, e)); + } +} + SDL_GLContext X11_GL_CreateContext(_THIS, SDL_Window * window) { @@ -516,6 +539,7 @@ X11_GL_CreateContext(_THIS, SDL_Window * window) /* We do this to create a clean separation between X and GLX errors. */ XSync(display, False); + handler = XSetErrorHandler(X11_GL_CreateContextErrorHandler); XGetWindowAttributes(display, data->xwindow, &xattr); v.screen = screen; v.visualid = XVisualIDFromVisual(xattr.visual); @@ -532,10 +556,7 @@ X11_GL_CreateContext(_THIS, SDL_Window * window) context to grab the new context creation function */ GLXContext temp_context = _this->gl_data->glXCreateContext(display, vinfo, NULL, True); - if (!temp_context) { - SDL_SetError("Could not create GL context"); - return NULL; - } else { + if (temp_context) { /* max 8 attributes plus terminator */ int attribs[9] = { GLX_CONTEXT_MAJOR_VERSION_ARB, @@ -609,7 +630,8 @@ X11_GL_CreateContext(_THIS, SDL_Window * window) XFree(vinfo); } XSync(display, False); - + XSetErrorHandler(handler); + if (!context) { SDL_SetError("Could not create GL context"); return NULL; @@ -630,21 +652,16 @@ X11_GL_MakeCurrent(_THIS, SDL_Window * window, SDL_GLContext context) Window drawable = (context ? ((SDL_WindowData *) window->driverdata)->xwindow : None); GLXContext glx_context = (GLXContext) context; - int status; if (!_this->gl_data) { - SDL_SetError("OpenGL not initialized"); - return -1; + return SDL_SetError("OpenGL not initialized"); } - status = 0; if (!_this->gl_data->glXMakeCurrent(display, drawable, glx_context)) { - SDL_SetError("Unable to make GL context current"); - status = -1; + return SDL_SetError("Unable to make GL context current"); } - XSync(display, False); - return (status); + return 0; } /* diff --git a/src/video/x11/SDL_x11opengles.c b/src/video/x11/SDL_x11opengles.c index 3b8a97a949..279c58c348 100644 --- a/src/video/x11/SDL_x11opengles.c +++ b/src/video/x11/SDL_x11opengles.c @@ -35,8 +35,7 @@ *((void**)&_this->gles_data->NAME) = dlsym(handle, #NAME); \ if (!_this->gles_data->NAME) \ { \ - SDL_SetError("Could not retrieve EGL function " #NAME); \ - return -1; \ + return SDL_SetError("Could not retrieve EGL function " #NAME); \ } /* GLES implementation of SDL OpenGL support */ @@ -95,8 +94,7 @@ X11_GLES_LoadLibrary(_THIS, const char *path) SDL_VideoData *data = (SDL_VideoData *) _this->driverdata; if (_this->gles_data) { - SDL_SetError("OpenGL ES context already created"); - return -1; + return SDL_SetError("OpenGL ES context already created"); } /* If SDL_GL_CONTEXT_EGL has been changed to 0, switch over to X11_GL functions */ @@ -113,8 +111,7 @@ X11_GLES_LoadLibrary(_THIS, const char *path) _this->GL_DeleteContext = X11_GL_DeleteContext; return X11_GL_LoadLibrary(_this, path); #else - SDL_SetError("SDL not configured with OpenGL/GLX support"); - return -1; + return SDL_SetError("SDL not configured with OpenGL/GLX support"); #endif } @@ -136,8 +133,7 @@ X11_GLES_LoadLibrary(_THIS, const char *path) } if (handle == NULL) { - SDL_SetError("Could not load OpenGL ES/EGL library"); - return -1; + return SDL_SetError("Could not load OpenGL ES/EGL library"); } /* Unload the old driver and reset the pointers */ @@ -145,8 +141,7 @@ X11_GLES_LoadLibrary(_THIS, const char *path) _this->gles_data = (struct SDL_PrivateGLESData *) SDL_calloc(1, sizeof(SDL_PrivateGLESData)); if (!_this->gles_data) { - SDL_OutOfMemory(); - return -1; + return SDL_OutOfMemory(); } /* Load new function pointers */ @@ -168,15 +163,13 @@ X11_GLES_LoadLibrary(_THIS, const char *path) _this->gles_data->eglGetDisplay((NativeDisplayType) data->display); if (!_this->gles_data->egl_display) { - SDL_SetError("Could not get EGL display"); - return -1; + return SDL_SetError("Could not get EGL display"); } if (_this->gles_data-> eglInitialize(_this->gles_data->egl_display, NULL, NULL) != EGL_TRUE) { - SDL_SetError("Could not initialize EGL"); - return -1; + return SDL_SetError("Could not initialize EGL"); } _this->gles_data->egl_dll_handle = handle; @@ -198,8 +191,7 @@ X11_GLES_LoadLibrary(_THIS, const char *path) } if (handle == NULL) { - SDL_SetError("Could not initialize OpenGL ES library"); - return -1; + return SDL_SetError("Could not initialize OpenGL ES library"); } _this->gl_config.dll_handle = handle; @@ -353,40 +345,34 @@ X11_GLES_CreateContext(_THIS, SDL_Window * window) int X11_GLES_MakeCurrent(_THIS, SDL_Window * window, SDL_GLContext context) { - int retval; - /* SDL_WindowData *data = (SDL_WindowData *) window->driverdata; Display *display = data->videodata->display; */ if (!_this->gles_data) { - SDL_SetError("OpenGL not initialized"); - return -1; + return SDL_SetError("OpenGL not initialized"); } - retval = 1; if (!_this->gles_data->eglMakeCurrent(_this->gles_data->egl_display, _this->gles_data->egl_surface, _this->gles_data->egl_surface, _this->gles_data->egl_context)) { - SDL_SetError("Unable to make EGL context current"); - retval = -1; + return SDL_SetError("Unable to make EGL context current"); } /* XSync(display, False); */ - return (retval); + return 1; } int X11_GLES_SetSwapInterval(_THIS, int interval) { if (_this->gles_data) { - SDL_SetError("OpenGL ES context not active"); - return -1; + return SDL_SetError("OpenGL ES context not active"); } EGLBoolean status; @@ -396,16 +382,14 @@ X11_GLES_SetSwapInterval(_THIS, int interval) return 0; } - SDL_SetError("Unable to set the EGL swap interval"); - return -1; + return SDL_SetError("Unable to set the EGL swap interval"); } int X11_GLES_GetSwapInterval(_THIS) { if (_this->gles_data) { - SDL_SetError("OpenGL ES context not active"); - return -1; + return SDL_SetError("OpenGL ES context not active"); } return _this->gles_data->egl_swapinterval; diff --git a/src/video/x11/SDL_x11shape.c b/src/video/x11/SDL_x11shape.c index 40cccc6adb..e1e68934e1 100644 --- a/src/video/x11/SDL_x11shape.c +++ b/src/video/x11/SDL_x11shape.c @@ -72,8 +72,7 @@ X11_ResizeWindowShape(SDL_Window* window) { free(data->bitmap); data->bitmap = malloc(data->bitmapsize); if(data->bitmap == NULL) { - SDL_SetError("Could not allocate memory for shaped-window bitmap."); - return -1; + return SDL_SetError("Could not allocate memory for shaped-window bitmap."); } } memset(data->bitmap,0,data->bitmapsize); diff --git a/src/video/x11/SDL_x11touch.c b/src/video/x11/SDL_x11touch.c index 76ad784006..a6ce981605 100644 --- a/src/video/x11/SDL_x11touch.c +++ b/src/video/x11/SDL_x11touch.c @@ -28,97 +28,12 @@ #include "../../events/SDL_touch_c.h" -#ifdef SDL_INPUT_LINUXEV -#include <linux/input.h> -#include <fcntl.h> -#endif - void X11_InitTouch(_THIS) { - /*Initilized Xinput2 multitouch - * and return in order to not initialize - * evtouch also*/ - if(X11_Xinput2IsMultitouchSupported()) { + if (X11_Xinput2IsMultitouchSupported()) { X11_InitXinput2Multitouch(_this); - return; - } -#ifdef SDL_INPUT_LINUXEV - FILE *fd; - fd = fopen("/proc/bus/input/devices","r"); - if (!fd) return; - - int i = 0; - int tsfd; - char line[256]; - char tstr[256]; - int vendor = -1,product = -1,event = -1; - while(!feof(fd)) { - if(fgets(line,256,fd) <=0) continue; - if(line[0] == '\n') { - if(vendor == 1386 || vendor==1) { - sprintf(tstr,"/dev/input/event%i",event); - - tsfd = open( tstr, O_RDONLY | O_NONBLOCK ); - if ( tsfd == -1 ) - continue; /* Maybe not enough permissions ? */ - - SDL_Touch touch; - touch.pressure_max = 0; - touch.pressure_min = 0; - touch.id = event; - - touch.driverdata = SDL_malloc(sizeof(EventTouchData)); - EventTouchData* data = (EventTouchData*)(touch.driverdata); - - data->x = -1; - data->y = -1; - data->pressure = -1; - data->finger = 0; - data->up = SDL_FALSE; - data->down = SDL_FALSE; - - data->eventStream = tsfd; - ioctl (data->eventStream, EVIOCGNAME (sizeof (tstr)), tstr); - - int abs[5]; - ioctl(data->eventStream,EVIOCGABS(0),abs); - touch.x_min = abs[1]; - touch.x_max = abs[2]; - touch.native_xres = touch.x_max - touch.x_min; - ioctl(data->eventStream,EVIOCGABS(ABS_Y),abs); - touch.y_min = abs[1]; - touch.y_max = abs[2]; - touch.native_yres = touch.y_max - touch.y_min; - ioctl(data->eventStream,EVIOCGABS(ABS_PRESSURE),abs); - touch.pressure_min = abs[1]; - touch.pressure_max = abs[2]; - touch.native_pressureres = touch.pressure_max - touch.pressure_min; - - SDL_AddTouch(&touch, tstr); - } - vendor = -1; - product = -1; - event = -1; - } - else if(line[0] == 'I') { - i = 1; - while(line[i]) { - sscanf(&line[i],"Vendor=%x",&vendor); - sscanf(&line[i],"Product=%x",&product); - i++; - } - } - else if(line[0] == 'H') { - i = 1; - while(line[i]) { - sscanf(&line[i],"event%d",&event); - i++; - } - } } - fclose(fd); -#endif } void diff --git a/src/video/x11/SDL_x11touch.h b/src/video/x11/SDL_x11touch.h index 350ac669f9..ac451a8578 100644 --- a/src/video/x11/SDL_x11touch.h +++ b/src/video/x11/SDL_x11touch.h @@ -23,16 +23,6 @@ #ifndef _SDL_x11touch_h #define _SDL_x11touch_h -#ifdef SDL_INPUT_LINUXEV -typedef struct EventTouchData -{ - int x,y,pressure,finger; /* Temporary Variables until sync */ - int eventStream; - SDL_bool up; - SDL_bool down; -} EventTouchData; -#endif - extern void X11_InitTouch(_THIS); extern void X11_QuitTouch(_THIS); diff --git a/src/video/x11/SDL_x11video.c b/src/video/x11/SDL_x11video.c index 150b660128..4794241e9a 100644 --- a/src/video/x11/SDL_x11video.c +++ b/src/video/x11/SDL_x11video.c @@ -305,8 +305,8 @@ X11_CreateDevice(int devindex) } data = (struct SDL_VideoData *) SDL_calloc(1, sizeof(SDL_VideoData)); if (!data) { - SDL_OutOfMemory(); SDL_free(device); + SDL_OutOfMemory(); return NULL; } device->driverdata = data; @@ -522,7 +522,17 @@ X11_VideoInit(_THIS) GET_ATOM(_NET_WM_ICON_NAME); GET_ATOM(_NET_WM_ICON); GET_ATOM(_NET_WM_PING); + GET_ATOM(_NET_ACTIVE_WINDOW); GET_ATOM(UTF8_STRING); + GET_ATOM(PRIMARY); + GET_ATOM(XdndEnter); + GET_ATOM(XdndPosition); + GET_ATOM(XdndStatus); + GET_ATOM(XdndTypeList); + GET_ATOM(XdndActionCopy); + GET_ATOM(XdndDrop); + GET_ATOM(XdndFinished); + GET_ATOM(XdndSelection); /* Detect the window manager */ X11_CheckWindowManager(_this); diff --git a/src/video/x11/SDL_x11video.h b/src/video/x11/SDL_x11video.h index 738cf73beb..9411b7b7e1 100644 --- a/src/video/x11/SDL_x11video.h +++ b/src/video/x11/SDL_x11video.h @@ -99,8 +99,18 @@ typedef struct SDL_VideoData Atom _NET_WM_ICON_NAME; Atom _NET_WM_ICON; Atom _NET_WM_PING; + Atom _NET_ACTIVE_WINDOW; Atom UTF8_STRING; - + Atom PRIMARY; + Atom XdndEnter; + Atom XdndPosition; + Atom XdndStatus; + Atom XdndTypeList; + Atom XdndActionCopy; + Atom XdndDrop; + Atom XdndFinished; + Atom XdndSelection; + SDL_Scancode key_layout[256]; SDL_bool selection_waiting; diff --git a/src/video/x11/SDL_x11window.c b/src/video/x11/SDL_x11window.c index 4f935fc3c8..6403ac4b43 100644 --- a/src/video/x11/SDL_x11window.c +++ b/src/video/x11/SDL_x11window.c @@ -214,13 +214,12 @@ SetupWindowData(_THIS, SDL_Window * window, Window w, BOOL created) /* Allocate the window data */ data = (SDL_WindowData *) SDL_calloc(1, sizeof(*data)); if (!data) { - SDL_OutOfMemory(); - return -1; + return SDL_OutOfMemory(); } data->window = window; data->xwindow = w; #ifdef X_HAVE_UTF8_STRING - if (SDL_X11_HAVE_UTF8) { + if (SDL_X11_HAVE_UTF8 && videodata->im) { data->ic = pXCreateIC(videodata->im, XNClientWindow, w, XNFocusWindow, w, XNInputStyle, XIMPreeditNothing | XIMStatusNothing, @@ -242,9 +241,8 @@ SetupWindowData(_THIS, SDL_Window * window, Window w, BOOL created) (numwindows + 1) * sizeof(*windowlist)); if (!windowlist) { - SDL_OutOfMemory(); SDL_free(data); - return -1; + return SDL_OutOfMemory(); } windowlist[numwindows] = data; videodata->numwindows++; @@ -344,6 +342,7 @@ X11_CreateWindow(_THIS, SDL_Window * window) Atom _NET_WM_WINDOW_TYPE; Atom _NET_WM_WINDOW_TYPE_NORMAL; Atom _NET_WM_PID; + Atom XdndAware, xdnd_version = 5; Uint32 fevent = 0; #if SDL_VIDEO_OPENGL_GLX || SDL_VIDEO_OPENGL_ES || SDL_VIDEO_OPENGL_ES2 @@ -391,15 +390,13 @@ X11_CreateWindow(_THIS, SDL_Window * window) /* If we can't create a colormap, then we must die */ if (!xattr.colormap) { - SDL_SetError("Could not create writable colormap"); - return -1; + return SDL_SetError("Could not create writable colormap"); } /* OK, we got a colormap, now fill it in as best as we can */ colorcells = SDL_malloc(visual->map_entries * sizeof(XColor)); if (!colorcells) { - SDL_OutOfMemory(); - return -1; + return SDL_OutOfMemory(); } ncolors = visual->map_entries; rmax = 0xffff; @@ -464,8 +461,7 @@ X11_CreateWindow(_THIS, SDL_Window * window) (CWOverrideRedirect | CWBackPixel | CWBorderPixel | CWColormap), &xattr); if (!w) { - SDL_SetError("Couldn't create window"); - return -1; + return SDL_SetError("Couldn't create window"); } #if SDL_VIDEO_OPENGL_ES || SDL_VIDEO_OPENGL_ES2 if ((window->flags & SDL_WINDOW_OPENGL) && (_this->gl_config.use_egl == 1)) { @@ -482,9 +478,8 @@ X11_CreateWindow(_THIS, SDL_Window * window) (NativeWindowType) w, NULL); if (_this->gles_data->egl_surface == EGL_NO_SURFACE) { - SDL_SetError("Could not create GLES window surface"); XDestroyWindow(display, w); - return -1; + return SDL_SetError("Could not create GLES window surface"); } } #endif @@ -567,6 +562,11 @@ X11_CreateWindow(_THIS, SDL_Window * window) PropertyChangeMask | StructureNotifyMask | KeymapStateMask | fevent)); + XdndAware = XInternAtom(display, "XdndAware", False); + XChangeProperty(display, w, XdndAware, XA_ATOM, 32, + PropModeReplace, + (unsigned char*)&xdnd_version, 1); + XFlush(display); return 0; @@ -927,10 +927,39 @@ X11_MinimizeWindow(_THIS, SDL_Window * window) XFlush(display); } +static void +SetWindowActive(_THIS, SDL_Window * window) +{ + SDL_WindowData *data = (SDL_WindowData *) window->driverdata; + SDL_DisplayData *displaydata = + (SDL_DisplayData *) SDL_GetDisplayForWindow(window)->driverdata; + Display *display = data->videodata->display; + Atom _NET_ACTIVE_WINDOW = data->videodata->_NET_ACTIVE_WINDOW; + + if (X11_IsWindowMapped(_this, window)) { + XEvent e; + + SDL_zero(e); + e.xany.type = ClientMessage; + e.xclient.message_type = _NET_ACTIVE_WINDOW; + e.xclient.format = 32; + e.xclient.window = data->xwindow; + e.xclient.data.l[0] = 1; /* source indication. 1 = application */ + e.xclient.data.l[1] = CurrentTime; + e.xclient.data.l[2] = 0; + + XSendEvent(display, RootWindow(display, displaydata->screen), 0, + SubstructureNotifyMask | SubstructureRedirectMask, &e); + + XFlush(display); + } +} + void X11_RestoreWindow(_THIS, SDL_Window * window) { SetWindowMaximized(_this, window, SDL_FALSE); + SetWindowActive(_this, window); X11_ShowWindow(_this, window); } @@ -1174,15 +1203,13 @@ X11_SetWindowGammaRamp(_THIS, SDL_Window * window, const Uint16 * ramp) int i; if (visual->class != DirectColor) { - SDL_SetError("Window doesn't have DirectColor visual"); - return -1; + return SDL_SetError("Window doesn't have DirectColor visual"); } ncolors = visual->map_entries; colorcells = SDL_malloc(ncolors * sizeof(XColor)); if (!colorcells) { - SDL_OutOfMemory(); - return -1; + return SDL_OutOfMemory(); } rshift = 0; diff --git a/src/video/x11/SDL_x11window.h b/src/video/x11/SDL_x11window.h index 76e20549ca..b9cb750b6e 100644 --- a/src/video/x11/SDL_x11window.h +++ b/src/video/x11/SDL_x11window.h @@ -57,6 +57,8 @@ typedef struct Uint32 pending_focus_time; XConfigureEvent last_xconfigure; struct SDL_VideoData *videodata; + Atom xdnd_req; + Window xdnd_source; } SDL_WindowData; extern void X11_SetNetWMState(_THIS, Window xwindow, Uint32 flags); diff --git a/src/video/x11/SDL_x11xinput2.c b/src/video/x11/SDL_x11xinput2.c index 9a1b6e9aaa..2bd466a540 100644 --- a/src/video/x11/SDL_x11xinput2.c +++ b/src/video/x11/SDL_x11xinput2.c @@ -121,8 +121,6 @@ X11_InitXinput2(_THIS) #endif } - - int X11_HandleXinput2Event(SDL_VideoData *videodata,XGenericEventCookie *cookie) { @@ -142,32 +140,29 @@ X11_HandleXinput2Event(SDL_VideoData *videodata,XGenericEventCookie *cookie) parse_valuators(rawev->raw_values,rawev->valuators.mask, rawev->valuators.mask_len,relative_cords,2); - SDL_SendMouseMotion(mouse->focus,1,(int)relative_cords[0],(int)relative_cords[1]); + SDL_SendMouseMotion(mouse->focus,mouse->mouseID,1,(int)relative_cords[0],(int)relative_cords[1]); return 1; } break; #if SDL_VIDEO_DRIVER_X11_XINPUT2_SUPPORTS_MULTITOUCH case XI_TouchBegin: { const XIDeviceEvent *xev = (const XIDeviceEvent *) cookie->data; - SDL_SendFingerDown(xev->sourceid,xev->detail, - SDL_TRUE, (int)xev->event_x, (int)xev->event_y, - 1.0); + SDL_SendTouch(xev->sourceid,xev->detail, + SDL_TRUE, xev->event_x, xev->event_y, 1.0); return 1; } break; case XI_TouchEnd: { const XIDeviceEvent *xev = (const XIDeviceEvent *) cookie->data; - SDL_SendFingerDown(xev->sourceid,xev->detail, - SDL_FALSE, (int)xev->event_x, (int)xev->event_y, - 1.0); + SDL_SendTouch(xev->sourceid,xev->detail, + SDL_FALSE, xev->event_x, xev->event_y, 1.0); return 1; } break; case XI_TouchUpdate: { const XIDeviceEvent *xev = (const XIDeviceEvent *) cookie->data; SDL_SendTouchMotion(xev->sourceid,xev->detail, - SDL_FALSE, (int)xev->event_x, (int)xev->event_y, - 1.0); + xev->event_x, xev->event_y, 1.0); return 1; } break; @@ -198,22 +193,8 @@ X11_InitXinput2Multitouch(_THIS) continue; touchId = t->sourceid; - /*Add the touch*/ if (!SDL_GetTouch(touchId)) { - SDL_Touch touch; - - touch.id = touchId; - touch.x_min = 0; - touch.x_max = 1; - touch.native_xres = touch.x_max - touch.x_min; - touch.y_min = 0; - touch.y_max = 1; - touch.native_yres = touch.y_max - touch.y_min; - touch.pressure_min = 0; - touch.pressure_max = 1; - touch.native_pressureres = touch.pressure_max - touch.pressure_min; - - SDL_AddTouch(&touch,dev->name); + SDL_AddTouch(touchId, dev->name); } } } diff --git a/src/video/x11/edid-parse.c b/src/video/x11/edid-parse.c index 97831aadd2..67e17e167d 100644 --- a/src/video/x11/edid-parse.c +++ b/src/video/x11/edid-parse.c @@ -333,7 +333,7 @@ decode_standard_timings (const uchar *edid, MonitorInfo *info) if (first != 0x01 && second != 0x01) { int w = 8 * (first + 31); - int h; + int h = 0; switch (get_bits (second, 6, 7)) { diff --git a/src/video/x11/edid.h b/src/video/x11/edid.h index c0c14e8f0f..8c217eba2b 100644 --- a/src/video/x11/edid.h +++ b/src/video/x11/edid.h @@ -39,10 +39,6 @@ struct Timing int frequency; }; -struct DisplayDescriptor -{ -}; - struct DetailedTiming { int pixel_clock; diff --git a/test/automated/common/common.h b/test/automated/common/common.h index d80d8186e2..25e7ecf745 100644 --- a/test/automated/common/common.h +++ b/test/automated/common/common.h @@ -22,7 +22,7 @@ typedef struct SurfaceImage_s { int width; int height; unsigned int bytes_per_pixel; /* 3:RGB, 4:RGBA */ - const unsigned char pixel_data[]; + const char *pixel_data; } SurfaceImage_t; #define ALLOWABLE_ERROR_OPAQUE 0 diff --git a/test/checkkeys.c b/test/checkkeys.c index fdbce60dd2..49dc277b22 100644 --- a/test/checkkeys.c +++ b/test/checkkeys.c @@ -105,7 +105,7 @@ PrintKey(SDL_Keysym * sym, SDL_bool pressed, SDL_bool repeat) "Unknown Key (scancode %d = %s) %s ", sym->scancode, SDL_GetScancodeName(sym->scancode), - pressed ? "pressed" : "released"); + pressed ? "pressed " : "released"); } /* Print the translated character, if one exists */ @@ -129,13 +129,13 @@ PrintKey(SDL_Keysym * sym, SDL_bool pressed, SDL_bool repeat) if (repeat) { print_string(&spot, &left, " (repeat)"); } - SDL_Log("%s", message); + SDL_Log("%s\n", message); } static void PrintText(char *text) { - SDL_Log("Text: %s", text); + SDL_Log("Text: %s\n", text); } int diff --git a/test/nds-test-progs/Makefile b/test/nds-test-progs/Makefile deleted file mode 100644 index ab7725a674..0000000000 --- a/test/nds-test-progs/Makefile +++ /dev/null @@ -1,7 +0,0 @@ -SUBDIRS:= $(shell ls | egrep -v '^(CVS)$$') - -all: - for i in $(SUBDIRS); do if test -e $$i/Makefile ; then $(MAKE) -C $$i || { exit 1;} fi; done; - -clean: - for i in $(SUBDIRS); do if test -e $$i/Makefile ; then $(MAKE) -C $$i clean || { exit 1;} fi; done; diff --git a/test/nds-test-progs/general/Makefile b/test/nds-test-progs/general/Makefile deleted file mode 100755 index 0dcaac884f..0000000000 --- a/test/nds-test-progs/general/Makefile +++ /dev/null @@ -1,131 +0,0 @@ -#--------------------------------------------------------------------------------- -.SUFFIXES: -#--------------------------------------------------------------------------------- - -ifeq ($(strip $(DEVKITARM)),) -$(error "Please set DEVKITARM in your environment. export DEVKITARM=<path to>devkitARM") -endif - -include $(DEVKITARM)/ds_rules - -#--------------------------------------------------------------------------------- -# TARGET is the name of the output -# BUILD is the directory where object files & intermediate files will be placed -# SOURCES is a list of directories containing source code -# INCLUDES is a list of directories containing extra header files -#--------------------------------------------------------------------------------- -TARGET := $(shell basename $(CURDIR)) -BUILD := build -SOURCES := source -DATA := data -INCLUDES := include - -#--------------------------------------------------------------------------------- -# options for code generation -#--------------------------------------------------------------------------------- -ARCH := -mthumb -mthumb-interwork - -# note: arm9tdmi isn't the correct CPU arch, but anything newer and LD -# *insists* it has a FPU or VFP, and it won't take no for an answer! -CFLAGS := -save-temps -g -Wall -O0\ - -mcpu=arm9tdmi -mtune=arm9tdmi \ - $(ARCH) - -CFLAGS += $(INCLUDE) -DARM9 -D__NDS__ -CXXFLAGS := $(CFLAGS) -fno-rtti -fno-exceptions -fno-exceptions -fno-rtti - -ASFLAGS := -g $(ARCH) -LDFLAGS = -specs=ds_arm9.specs -g $(ARCH) -mno-fpu -Wl,-Map,$(notdir $*.map) - -#--------------------------------------------------------------------------------- -# any extra libraries we wish to link with the project -#--------------------------------------------------------------------------------- -LIBS := -lSDL -lfat -lnds9 - - -#--------------------------------------------------------------------------------- -# list of directories containing libraries, this must be the top level containing -# include and lib -#--------------------------------------------------------------------------------- -LIBDIRS := $(LIBNDS) $(PORTLIBS) - -#--------------------------------------------------------------------------------- -# no real need to edit anything past this point unless you need to add additional -# rules for different file extensions -#--------------------------------------------------------------------------------- -ifneq ($(BUILD),$(notdir $(CURDIR))) -#--------------------------------------------------------------------------------- - -export OUTPUT := $(CURDIR)/$(TARGET) - -export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \ - $(foreach dir,$(DATA),$(CURDIR)/$(dir)) - -export DEPSDIR := $(CURDIR)/$(BUILD) - -CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c))) -CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp))) -SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s))) -BINFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*))) - -#--------------------------------------------------------------------------------- -# use CXX for linking C++ projects, CC for standard C -#--------------------------------------------------------------------------------- -ifeq ($(strip $(CPPFILES)),) -#--------------------------------------------------------------------------------- - export LD := $(CC) -#--------------------------------------------------------------------------------- -else -#--------------------------------------------------------------------------------- - export LD := $(CXX) -#--------------------------------------------------------------------------------- -endif -#--------------------------------------------------------------------------------- - -export OFILES := $(addsuffix .o,$(BINFILES)) \ - $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(SFILES:.s=.o) - -export INCLUDE := $(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \ - $(foreach dir,$(LIBDIRS),-I$(dir)/include) \ - -I$(CURDIR)/$(BUILD) - -export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib) - -.PHONY: $(BUILD) clean - -#--------------------------------------------------------------------------------- -$(BUILD): - @[ -d $@ ] || mkdir -p $@ - @make --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile - -#--------------------------------------------------------------------------------- -clean: - @echo clean ... - @rm -fr $(BUILD) $(TARGET).elf $(TARGET).nds $(TARGET).arm9 $(TARGET).ds.gba - - -#--------------------------------------------------------------------------------- -else - -DEPENDS := $(OFILES:.o=.d) - -#--------------------------------------------------------------------------------- -# main targets -#--------------------------------------------------------------------------------- -$(OUTPUT).ds.gba : $(OUTPUT).nds -$(OUTPUT).nds : $(OUTPUT).arm9 -$(OUTPUT).arm9 : $(OUTPUT).elf -$(OUTPUT).elf : $(OFILES) - -#--------------------------------------------------------------------------------- -%.pcx.o : %.pcx -#--------------------------------------------------------------------------------- - @echo $(notdir $<) - @$(bin2o) - - --include $(DEPENDS) - -#--------------------------------------------------------------------------------------- -endif -#--------------------------------------------------------------------------------------- diff --git a/test/nds-test-progs/general/source/main.c b/test/nds-test-progs/general/source/main.c deleted file mode 100644 index 087dc4da1c..0000000000 --- a/test/nds-test-progs/general/source/main.c +++ /dev/null @@ -1,89 +0,0 @@ -/* - * Really basic sample for the NDS. - * - * Fills a rectangle increasingly smaller of random color every time a - * button (a, b, x, y) is pressed. - * - * The behaviour whether SDL is compiled with HW support or not (see - * USE_HW_RENDERER in Makefile.ds). - * - * In framebuffer mode, the old rectangles stay because the screen has - * not been cleared. - * - * In accelerated mode, old the last rectangle is visible. - * - * No text is displayed. - */ - -#include <SDL/SDL.h> -#if defined(NDS) || defined(__NDS__) || defined (__NDS) -#include <nds.h> -#include <fat.h> -#else -#define consoleDemoInit() -#define fatInitDefault() -#define RGB15(r,g,b) SDL_MapRGB(screen->format,((r)<<3),((g)<<3),((b)<<3)) -#endif - -int main(void) -{ - SDL_Window *window; - SDL_Renderer *renderer; - SDL_Joystick *stick; - SDL_Event event; - SDL_Rect rect = { 0, 0, 256, 192 }; - int i; - - consoleDemoInit(); - puts("Hello world! Initializing FAT..."); - - if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_JOYSTICK) < 0) { - puts("# error initializing SDL"); - puts(SDL_GetError()); - return 1; - } - puts("* initialized SDL"); - - if (SDL_CreateWindowAndRenderer(256, 192, SDL_RENDERER_ACCELERATED, &window, &renderer) < 0 && - SDL_CreateWindowAndRenderer(256, 192, SDL_RENDERER_SOFTWARE, &window, &renderer) < 0) { - exit(1); - } - - stick = SDL_JoystickOpen(0); - if (stick == NULL) { - puts("# error opening joystick"); - puts(SDL_GetError()); - } - puts("* opened joystick"); - - SDL_SetRenderDrawColor(renderer, 0, 0, 0, SDL_ALPHA_OPAQUE); - SDL_RenderFillRect(renderer, &rect); - SDL_RenderPresent(renderer); - - while (1) - while (SDL_PollEvent(&event)) - switch (event.type) { - case SDL_JOYBUTTONDOWN: - - SDL_SetRenderDrawColor(renderer, rand(), rand(), rand(), SDL_ALPHA_OPAQUE); - SDL_RenderFillRect(renderer, &rect); - SDL_RenderPresent(renderer); - if (rect.w > 8) { - rect.x += 4; - rect.y += 3; - rect.w -= 8; - rect.h -= 6; - } - /* - printf("button %d pressed at %d ticks\n", - event.jbutton.button, SDL_GetTicks()); - */ - break; - case SDL_QUIT: - SDL_Quit(); - return 0; - default: - break; - } - return 0; -} diff --git a/test/nds-test-progs/testscale/Makefile b/test/nds-test-progs/testscale/Makefile deleted file mode 100644 index 31a123220c..0000000000 --- a/test/nds-test-progs/testscale/Makefile +++ /dev/null @@ -1,147 +0,0 @@ -#--------------------------------------------------------------------------------- -.SUFFIXES: -#--------------------------------------------------------------------------------- - -ifeq ($(strip $(DEVKITARM)),) -$(error "Please set DEVKITARM in your environment. export DEVKITARM=<path to>devkitARM") -endif - -include $(DEVKITARM)/ds_rules - -#--------------------------------------------------------------------------------- -# TARGET is the name of the output -# BUILD is the directory where object files & intermediate files will be placed -# SOURCES is a list of directories containing source code -# INCLUDES is a list of directories containing extra header files -# DATA is a list of directories containing binary files embedded using bin2o -# GRAPHICS is a list of directories containing image files to be converted with grit -#--------------------------------------------------------------------------------- -TARGET := $(shell basename $(CURDIR)) -BUILD := build -SOURCES := source -INCLUDES := include ../.. -DATA := data -GRAPHICS := gfx - -#--------------------------------------------------------------------------------- -# options for code generation -#--------------------------------------------------------------------------------- -ARCH := -mthumb -mthumb-interwork -march=armv5te -mtune=arm946e-s - -CFLAGS := -g -Wall -O2\ - -fomit-frame-pointer\ - -ffast-math \ - $(ARCH) - -CFLAGS += $(INCLUDE) -DARM9 -D__NDS__ -CXXFLAGS := $(CFLAGS) -fno-rtti -fno-exceptions - -ASFLAGS := -g $(ARCH) -LDFLAGS = -specs=ds_arm9.specs -g $(ARCH) -Wl,-Map,$(notdir $*.map) - -#--------------------------------------------------------------------------------- -# any extra libraries we wish to link with the project (order is important) -#--------------------------------------------------------------------------------- -LIBS := -lSDL -lfat -lnds9 - - -#--------------------------------------------------------------------------------- -# list of directories containing libraries, this must be the top level containing -# include and lib -#--------------------------------------------------------------------------------- -LIBDIRS := $(LIBNDS) $(PORTLIBS) - -#--------------------------------------------------------------------------------- -# no real need to edit anything past this point unless you need to add additional -# rules for different file extensions -#--------------------------------------------------------------------------------- -ifneq ($(BUILD),$(notdir $(CURDIR))) -#--------------------------------------------------------------------------------- - -export OUTPUT := $(CURDIR)/$(TARGET) - -export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \ - $(foreach dir,$(DATA),$(CURDIR)/$(dir)) \ - $(foreach dir,$(GRAPHICS),$(CURDIR)/$(dir)) - -export DEPSDIR := $(CURDIR)/$(BUILD) - -CFILES := ../../../common.c ../../../testscale.c - -#--------------------------------------------------------------------------------- -# use CXX for linking C++ projects, CC for standard C -#--------------------------------------------------------------------------------- -ifeq ($(strip $(CPPFILES)),) -#--------------------------------------------------------------------------------- - export LD := $(CC) -#--------------------------------------------------------------------------------- -else -#--------------------------------------------------------------------------------- - export LD := $(CXX) -#--------------------------------------------------------------------------------- -endif -#--------------------------------------------------------------------------------- - -export OFILES := $(addsuffix .o,$(BINFILES)) \ - $(PNGFILES:.png=.o) \ - $(BMPFILES:.bmp=.o) \ - $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(SFILES:.s=.o) - -export INCLUDE := $(foreach dir,$(INCLUDES),-iquote $(CURDIR)/$(dir)) \ - $(foreach dir,$(LIBDIRS),-I$(dir)/include) \ - -I$(CURDIR)/$(BUILD) \ - -I$(PORTLIBS)/include/SDL - -export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib) - -.PHONY: $(BUILD) clean - -#--------------------------------------------------------------------------------- -$(BUILD): - @[ -d $@ ] || mkdir -p $@ - @make --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile - -#--------------------------------------------------------------------------------- -clean: - @echo clean ... - @rm -fr $(BUILD) $(TARGET).elf $(TARGET).nds - -#--------------------------------------------------------------------------------- -else - -DEPENDS := $(OFILES:.o=.d) - -#--------------------------------------------------------------------------------- -# main targets -#--------------------------------------------------------------------------------- -$(OUTPUT).nds : $(OUTPUT).elf -$(OUTPUT).elf : $(OFILES) - -#--------------------------------------------------------------------------------- -%.bin.o : %.bin -#--------------------------------------------------------------------------------- - @echo $(notdir $<) - $(bin2o) - -#--------------------------------------------------------------------------------- -# This rule creates assembly source files using grit -# grit takes an image file and a .grit describing how the file is to be processed -# add additional rules like this for each image extension -# you use in the graphics folders -#--------------------------------------------------------------------------------- -%.s %.h : %.bmp %.grit -#--------------------------------------------------------------------------------- - grit $< -fts -o$* - - -#--------------------------------------------------------------------------------- -%.s %.h : %.png %.grit -#--------------------------------------------------------------------------------- - grit $< -fts -o$* - - --include $(DEPENDS) - -#--------------------------------------------------------------------------------------- -endif -#--------------------------------------------------------------------------------------- diff --git a/test/nds-test-progs/testsprite2/Makefile b/test/nds-test-progs/testsprite2/Makefile deleted file mode 100644 index b765e6c841..0000000000 --- a/test/nds-test-progs/testsprite2/Makefile +++ /dev/null @@ -1,152 +0,0 @@ -#--------------------------------------------------------------------------------- -.SUFFIXES: -#--------------------------------------------------------------------------------- - -ifeq ($(strip $(DEVKITARM)),) -$(error "Please set DEVKITARM in your environment. export DEVKITARM=<path to>devkitARM") -endif - -include $(DEVKITARM)/ds_rules - -#--------------------------------------------------------------------------------- -# TARGET is the name of the output -# BUILD is the directory where object files & intermediate files will be placed -# SOURCES is a list of directories containing source code -# INCLUDES is a list of directories containing extra header files -# DATA is a list of directories containing binary files embedded using bin2o -# GRAPHICS is a list of directories containing image files to be converted with grit -#--------------------------------------------------------------------------------- -TARGET := $(shell basename $(CURDIR)) -BUILD := build -SOURCES := source -INCLUDES := include ../.. -DATA := data -GRAPHICS := gfx - -#--------------------------------------------------------------------------------- -# options for code generation -#--------------------------------------------------------------------------------- -ARCH := -mthumb -mthumb-interwork -march=armv5te -mtune=arm946e-s - -CFLAGS := -g -Wall -O2\ - -fomit-frame-pointer\ - -ffast-math \ - $(ARCH) - -CFLAGS += $(INCLUDE) -DARM9 -D__NDS__ -CXXFLAGS := $(CFLAGS) -fno-rtti -fno-exceptions - -ASFLAGS := -g $(ARCH) -LDFLAGS = -specs=ds_arm9.specs -g $(ARCH) -Wl,-Map,$(notdir $*.map) - -#--------------------------------------------------------------------------------- -# any extra libraries we wish to link with the project (order is important) -#--------------------------------------------------------------------------------- -LIBS := -lSDL -lfat -lnds9 - - -#--------------------------------------------------------------------------------- -# list of directories containing libraries, this must be the top level containing -# include and lib -#--------------------------------------------------------------------------------- -LIBDIRS := $(LIBNDS) $(PORTLIBS) - -#--------------------------------------------------------------------------------- -# no real need to edit anything past this point unless you need to add additional -# rules for different file extensions -#--------------------------------------------------------------------------------- -ifneq ($(BUILD),$(notdir $(CURDIR))) -#--------------------------------------------------------------------------------- - -export OUTPUT := $(CURDIR)/$(TARGET) - -export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \ - $(foreach dir,$(DATA),$(CURDIR)/$(dir)) \ - $(foreach dir,$(GRAPHICS),$(CURDIR)/$(dir)) - -export DEPSDIR := $(CURDIR)/$(BUILD) - -CFILES := ../../../common.c ../../../testsprite2.c -CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp))) -SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s))) -PNGFILES := $(foreach dir,$(GRAPHICS),$(notdir $(wildcard $(dir)/*.png))) -BMPFILES := $(foreach dir,$(GRAPHICS),$(notdir $(wildcard $(dir)/*.bmp))) -BINFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*))) - -#--------------------------------------------------------------------------------- -# use CXX for linking C++ projects, CC for standard C -#--------------------------------------------------------------------------------- -ifeq ($(strip $(CPPFILES)),) -#--------------------------------------------------------------------------------- - export LD := $(CC) -#--------------------------------------------------------------------------------- -else -#--------------------------------------------------------------------------------- - export LD := $(CXX) -#--------------------------------------------------------------------------------- -endif -#--------------------------------------------------------------------------------- - -export OFILES := $(addsuffix .o,$(BINFILES)) \ - $(PNGFILES:.png=.o) \ - $(BMPFILES:.bmp=.o) \ - $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(SFILES:.s=.o) - -export INCLUDE := $(foreach dir,$(INCLUDES),-iquote $(CURDIR)/$(dir)) \ - $(foreach dir,$(LIBDIRS),-I$(dir)/include) \ - -I$(CURDIR)/$(BUILD) \ - -I$(PORTLIBS)/include/SDL - -export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib) - -.PHONY: $(BUILD) clean - -#--------------------------------------------------------------------------------- -$(BUILD): - @[ -d $@ ] || mkdir -p $@ - @make --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile - -#--------------------------------------------------------------------------------- -clean: - @echo clean ... - @rm -fr $(BUILD) $(TARGET).elf $(TARGET).nds - -#--------------------------------------------------------------------------------- -else - -DEPENDS := $(OFILES:.o=.d) - -#--------------------------------------------------------------------------------- -# main targets -#--------------------------------------------------------------------------------- -$(OUTPUT).nds : $(OUTPUT).elf -$(OUTPUT).elf : $(OFILES) - -#--------------------------------------------------------------------------------- -%.bin.o : %.bin -#--------------------------------------------------------------------------------- - @echo $(notdir $<) - $(bin2o) - -#--------------------------------------------------------------------------------- -# This rule creates assembly source files using grit -# grit takes an image file and a .grit describing how the file is to be processed -# add additional rules like this for each image extension -# you use in the graphics folders -#--------------------------------------------------------------------------------- -%.s %.h : %.bmp %.grit -#--------------------------------------------------------------------------------- - grit $< -fts -o$* - - -#--------------------------------------------------------------------------------- -%.s %.h : %.png %.grit -#--------------------------------------------------------------------------------- - grit $< -fts -o$* - - --include $(DEPENDS) - -#--------------------------------------------------------------------------------------- -endif -#--------------------------------------------------------------------------------------- diff --git a/test/nds-test-progs/testspriteminimal/Makefile b/test/nds-test-progs/testspriteminimal/Makefile deleted file mode 100644 index e54101f9eb..0000000000 --- a/test/nds-test-progs/testspriteminimal/Makefile +++ /dev/null @@ -1,147 +0,0 @@ -#--------------------------------------------------------------------------------- -.SUFFIXES: -#--------------------------------------------------------------------------------- - -ifeq ($(strip $(DEVKITARM)),) -$(error "Please set DEVKITARM in your environment. export DEVKITARM=<path to>devkitARM") -endif - -include $(DEVKITARM)/ds_rules - -#--------------------------------------------------------------------------------- -# TARGET is the name of the output -# BUILD is the directory where object files & intermediate files will be placed -# SOURCES is a list of directories containing source code -# INCLUDES is a list of directories containing extra header files -# DATA is a list of directories containing binary files embedded using bin2o -# GRAPHICS is a list of directories containing image files to be converted with grit -#--------------------------------------------------------------------------------- -TARGET := $(shell basename $(CURDIR)) -BUILD := build -SOURCES := source -INCLUDES := include -DATA := data -GRAPHICS := gfx - -#--------------------------------------------------------------------------------- -# options for code generation -#--------------------------------------------------------------------------------- -ARCH := -mthumb -mthumb-interwork -march=armv5te -mtune=arm946e-s - -CFLAGS := -g -Wall -O2\ - -fomit-frame-pointer\ - -ffast-math \ - $(ARCH) - -CFLAGS += $(INCLUDE) -DARM9 -D__NDS__ -CXXFLAGS := $(CFLAGS) -fno-rtti -fno-exceptions - -ASFLAGS := -g $(ARCH) -LDFLAGS = -specs=ds_arm9.specs -g $(ARCH) -Wl,-Map,$(notdir $*.map) - -#--------------------------------------------------------------------------------- -# any extra libraries we wish to link with the project (order is important) -#--------------------------------------------------------------------------------- -LIBS := -lSDL -lfat -lnds9 - - -#--------------------------------------------------------------------------------- -# list of directories containing libraries, this must be the top level containing -# include and lib -#--------------------------------------------------------------------------------- -LIBDIRS := $(LIBNDS) $(PORTLIBS) - -#--------------------------------------------------------------------------------- -# no real need to edit anything past this point unless you need to add additional -# rules for different file extensions -#--------------------------------------------------------------------------------- -ifneq ($(BUILD),$(notdir $(CURDIR))) -#--------------------------------------------------------------------------------- - -export OUTPUT := $(CURDIR)/$(TARGET) - -export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \ - $(foreach dir,$(DATA),$(CURDIR)/$(dir)) \ - $(foreach dir,$(GRAPHICS),$(CURDIR)/$(dir)) - -export DEPSDIR := $(CURDIR)/$(BUILD) - -CFILES := ../../../testspriteminimal.c - -#--------------------------------------------------------------------------------- -# use CXX for linking C++ projects, CC for standard C -#--------------------------------------------------------------------------------- -ifeq ($(strip $(CPPFILES)),) -#--------------------------------------------------------------------------------- - export LD := $(CC) -#--------------------------------------------------------------------------------- -else -#--------------------------------------------------------------------------------- - export LD := $(CXX) -#--------------------------------------------------------------------------------- -endif -#--------------------------------------------------------------------------------- - -export OFILES := $(addsuffix .o,$(BINFILES)) \ - $(PNGFILES:.png=.o) \ - $(BMPFILES:.bmp=.o) \ - $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(SFILES:.s=.o) - -export INCLUDE := $(foreach dir,$(INCLUDES),-iquote $(CURDIR)/$(dir)) \ - $(foreach dir,$(LIBDIRS),-I$(dir)/include) \ - -I$(CURDIR)/$(BUILD) \ - -I$(PORTLIBS)/include/SDL - -export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib) - -.PHONY: $(BUILD) clean - -#--------------------------------------------------------------------------------- -$(BUILD): - @[ -d $@ ] || mkdir -p $@ - @make --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile - -#--------------------------------------------------------------------------------- -clean: - @echo clean ... - @rm -fr $(BUILD) $(TARGET).elf $(TARGET).nds - -#--------------------------------------------------------------------------------- -else - -DEPENDS := $(OFILES:.o=.d) - -#--------------------------------------------------------------------------------- -# main targets -#--------------------------------------------------------------------------------- -$(OUTPUT).nds : $(OUTPUT).elf -$(OUTPUT).elf : $(OFILES) - -#--------------------------------------------------------------------------------- -%.bin.o : %.bin -#--------------------------------------------------------------------------------- - @echo $(notdir $<) - $(bin2o) - -#--------------------------------------------------------------------------------- -# This rule creates assembly source files using grit -# grit takes an image file and a .grit describing how the file is to be processed -# add additional rules like this for each image extension -# you use in the graphics folders -#--------------------------------------------------------------------------------- -%.s %.h : %.bmp %.grit -#--------------------------------------------------------------------------------- - grit $< -fts -o$* - - -#--------------------------------------------------------------------------------- -%.s %.h : %.png %.grit -#--------------------------------------------------------------------------------- - grit $< -fts -o$* - - --include $(DEPENDS) - -#--------------------------------------------------------------------------------------- -endif -#--------------------------------------------------------------------------------------- diff --git a/test/testatomic.c b/test/testatomic.c index a05834080b..7bcceb5596 100644 --- a/test/testatomic.c +++ b/test/testatomic.c @@ -412,7 +412,7 @@ static SDL_bool EnqueueEvent_Mutex(SDL_EventQueue *queue, const SDL_Event *event int delta; SDL_bool status = SDL_FALSE; - SDL_mutexP(queue->mutex); + SDL_LockMutex(queue->mutex); queue_pos = (unsigned)queue->enqueue_pos.value; entry = &queue->entries[queue_pos & WRAP_MASK]; @@ -432,7 +432,7 @@ static SDL_bool EnqueueEvent_Mutex(SDL_EventQueue *queue, const SDL_Event *event printf("ERROR: mutex failed!\n"); } - SDL_mutexV(queue->mutex); + SDL_UnlockMutex(queue->mutex); return status; } @@ -445,7 +445,7 @@ static SDL_bool DequeueEvent_Mutex(SDL_EventQueue *queue, SDL_Event *event) int delta; SDL_bool status = SDL_FALSE; - SDL_mutexP(queue->mutex); + SDL_LockMutex(queue->mutex); queue_pos = (unsigned)queue->dequeue_pos.value; entry = &queue->entries[queue_pos & WRAP_MASK]; @@ -465,7 +465,7 @@ static SDL_bool DequeueEvent_Mutex(SDL_EventQueue *queue, SDL_Event *event) printf("ERROR: mutex failed!\n"); } - SDL_mutexV(queue->mutex); + SDL_UnlockMutex(queue->mutex); return status; } diff --git a/test/testaudioinfo.c b/test/testaudioinfo.c index ac3191a525..ff7c25b7f1 100644 --- a/test/testaudioinfo.c +++ b/test/testaudioinfo.c @@ -36,6 +36,8 @@ print_devices(int iscapture) int main(int argc, char **argv) { + int n; + /* Load the SDL library */ if (SDL_Init(SDL_INIT_AUDIO) < 0) { fprintf(stderr, "Couldn't initialize SDL: %s\n", SDL_GetError()); @@ -43,7 +45,7 @@ main(int argc, char **argv) } /* Print available audio drivers */ - int n = SDL_GetNumAudioDrivers(); + n = SDL_GetNumAudioDrivers(); if (n == 0) { printf("No built-in audio drivers\n\n"); } else { diff --git a/test/testautomation_keyboard.c b/test/testautomation_keyboard.c index 588b1c235b..ca6d2e3550 100644 --- a/test/testautomation_keyboard.c +++ b/test/testautomation_keyboard.c @@ -3,6 +3,7 @@ */ #include <stdio.h> +#include <limits.h> #include "SDL_config.h" #include "SDL.h" @@ -103,6 +104,25 @@ keyboard_getKeyFromName(void *arg) return TEST_COMPLETED; } +/* + * Local helper to check for the invalid scancode error message + */ +void +_checkInvalidScancodeError() +{ + const char *expectedError = "Parameter 'scancode' is invalid"; + const char *error; + error = SDL_GetError(); + SDLTest_AssertPass("Call to SDL_GetError()"); + SDLTest_AssertCheck(error != NULL, "Validate that error message was not NULL"); + if (error != NULL) { + SDLTest_AssertCheck(SDL_strcmp(error, expectedError) == 0, + "Validate error message, expected: '%s', got: '%s'", expectedError, error); + SDL_ClearError(); + SDLTest_AssertPass("Call to SDL_ClearError()"); + } +} + /** * @brief Check call to SDL_GetKeyFromScancode * @@ -111,8 +131,6 @@ keyboard_getKeyFromName(void *arg) int keyboard_getKeyFromScancode(void *arg) { - const char *expectedError = "Parameter 'scancode' is invalid"; - const char *error; SDL_Keycode result; /* Case where input is valid */ @@ -125,6 +143,7 @@ keyboard_getKeyFromScancode(void *arg) SDLTest_AssertPass("Call to SDL_GetKeyFromScancode(0)"); SDLTest_AssertCheck(result == SDLK_UNKNOWN, "Verify result from call is UNKNOWN, expected: %i, got: %i", SDLK_UNKNOWN, result); + /* Clear error message */ SDL_ClearError(); SDLTest_AssertPass("Call to SDL_ClearError()"); @@ -132,31 +151,13 @@ keyboard_getKeyFromScancode(void *arg) result = SDL_GetKeyFromScancode(-999); SDLTest_AssertPass("Call to SDL_GetKeyFromScancode(-999)"); SDLTest_AssertCheck(result == SDLK_UNKNOWN, "Verify result from call is UNKNOWN, expected: %i, got: %i", SDLK_UNKNOWN, result); - error = SDL_GetError(); - SDLTest_AssertPass("Call to SDL_GetError()"); - SDLTest_AssertCheck(error != NULL, "Validate that error message was not NULL"); - if (error != NULL) { - SDLTest_AssertCheck(SDL_strcmp(error, expectedError) == 0, - "Validate error message, expected: '%s', got: '%s'", expectedError, error); - } - - SDL_ClearError(); - SDLTest_AssertPass("Call to SDL_ClearError()"); + _checkInvalidScancodeError(); /* Case where input is invalid (too big) */ result = SDL_GetKeyFromScancode(999); SDLTest_AssertPass("Call to SDL_GetKeyFromScancode(999)"); SDLTest_AssertCheck(result == SDLK_UNKNOWN, "Verify result from call is UNKNOWN, expected: %i, got: %i", SDLK_UNKNOWN, result); - error = SDL_GetError(); - SDLTest_AssertPass("Call to SDL_GetError()"); - SDLTest_AssertCheck(error != NULL, "Validate that error message was not NULL"); - if (error != NULL) { - SDLTest_AssertCheck(SDL_strcmp(error, expectedError) == 0, - "Validate error message, expected: '%s', got: '%s'", expectedError, error); - } - - SDL_ClearError(); - SDLTest_AssertPass("Call to SDL_ClearError()"); + _checkInvalidScancodeError(); return TEST_COMPLETED; } @@ -218,6 +219,78 @@ keyboard_getKeyName(void *arg) } /** + * @brief SDL_GetScancodeName negative cases + * + * @sa http://wiki.libsdl.org/moin.cgi/SDL_GetScancodeName + */ +int +keyboard_getScancodeNameNegative(void *arg) +{ + SDL_Scancode scancode; + char *result; + char *expected = ""; + + /* Clear error message */ + SDL_ClearError(); + SDLTest_AssertPass("Call to SDL_ClearError()"); + + /* Negative scancode */ + scancode = (SDL_Scancode)SDLTest_RandomIntegerInRange(LONG_MIN, -1); + result = (char *)SDL_GetScancodeName(scancode); + SDLTest_AssertPass("Call to SDL_GetScancodeName(%d/negative)", scancode); + SDLTest_AssertCheck(result != NULL, "Verify result from call is not NULL"); + SDLTest_AssertCheck(SDL_strcmp(result, expected) == 0, "Verify result from call is valid, expected: '%s', got: '%s'", expected, result); + _checkInvalidScancodeError(); + + /* Large scancode */ + scancode = (SDL_Scancode)SDLTest_RandomIntegerInRange(SDL_NUM_SCANCODES, LONG_MAX); + result = (char *)SDL_GetScancodeName(scancode); + SDLTest_AssertPass("Call to SDL_GetScancodeName(%d/large)", scancode); + SDLTest_AssertCheck(result != NULL, "Verify result from call is not NULL"); + SDLTest_AssertCheck(SDL_strcmp(result, expected) == 0, "Verify result from call is valid, expected: '%s', got: '%s'", expected, result); + _checkInvalidScancodeError(); + + return TEST_COMPLETED; +} + +/** + * @brief SDL_GetKeyName negative cases + * + * @sa http://wiki.libsdl.org/moin.cgi/SDL_GetKeyName + */ +int +keyboard_getKeyNameNegative(void *arg) +{ + SDL_Keycode keycode; + char *result; + char *expected = ""; + + /* Unknown keycode */ + keycode = SDLK_UNKNOWN; + result = (char *)SDL_GetKeyName(keycode); + SDLTest_AssertPass("Call to SDL_GetKeyName(%d/unknown)", keycode); + SDLTest_AssertCheck(result != NULL, "Verify result from call is not NULL"); + SDLTest_AssertCheck(SDL_strcmp(result, expected) == 0, "Verify result from call is valid, expected: '%s', got: '%s'", expected, result); + + /* Clear error message */ + SDL_ClearError(); + SDLTest_AssertPass("Call to SDL_ClearError()"); + + /* Negative keycode */ + keycode = (SDL_Keycode)SDLTest_RandomIntegerInRange(-255, -1); + result = (char *)SDL_GetKeyName(keycode); + SDLTest_AssertPass("Call to SDL_GetKeyName(%d/negative)", keycode); + SDLTest_AssertCheck(result != NULL, "Verify result from call is not NULL"); + SDLTest_AssertCheck(SDL_strcmp(result, expected) == 0, "Verify result from call is valid, expected: '%s', got: '%s'", expected, result); + _checkInvalidScancodeError(); + + SDL_ClearError(); + SDLTest_AssertPass("Call to SDL_ClearError()"); + + return TEST_COMPLETED; +} + +/** * @brief Check call to SDL_GetModState and SDL_SetModState * * @sa http://wiki.libsdl.org/moin.cgi/SDL_GetModState @@ -521,6 +594,25 @@ keyboard_getScancodeFromName(void *arg) return TEST_COMPLETED; } +/* + * Local helper to check for the invalid scancode error message + */ +void +_checkInvalidNameError() +{ + const char *expectedError = "Parameter 'name' is invalid"; + const char *error; + error = SDL_GetError(); + SDLTest_AssertPass("Call to SDL_GetError()"); + SDLTest_AssertCheck(error != NULL, "Validate that error message was not NULL"); + if (error != NULL) { + SDLTest_AssertCheck(SDL_strcmp(error, expectedError) == 0, + "Validate error message, expected: '%s', got: '%s'", expectedError, error); + SDL_ClearError(); + SDLTest_AssertPass("Call to SDL_ClearError()"); + } +} + /** * @brief Check call to SDL_GetScancodeFromName with invalid data * @@ -532,9 +624,8 @@ keyboard_getScancodeFromNameNegative(void *arg) { char *name; SDL_Scancode scancode; - const char *expectedError = "Parameter 'name' is invalid"; - const char *error; + /* Clear error message */ SDL_ClearError(); SDLTest_AssertPass("Call to SDL_ClearError()"); @@ -548,48 +639,21 @@ keyboard_getScancodeFromNameNegative(void *arg) SDLTest_AssertPass("Call to SDL_GetScancodeFromName('%s')", name); SDL_free(name); SDLTest_AssertCheck(scancode == SDL_SCANCODE_UNKNOWN, "Validate return value from SDL_GetScancodeFromName, expected: %i, got: %i", SDL_SCANCODE_UNKNOWN, scancode); - error = SDL_GetError(); - SDLTest_AssertPass("Call to SDL_GetError()"); - SDLTest_AssertCheck(error != NULL, "Validate that error message was not NULL"); - if (error != NULL) { - SDLTest_AssertCheck(SDL_strcmp(error, expectedError) == 0, - "Validate error message, expected: '%s', got: '%s'", expectedError, error); - } - - SDL_ClearError(); - SDLTest_AssertPass("Call to SDL_ClearError()"); + _checkInvalidNameError(); /* Zero length string input */ name = ""; scancode = SDL_GetScancodeFromName((const char *)name); SDLTest_AssertPass("Call to SDL_GetScancodeFromName(NULL)"); SDLTest_AssertCheck(scancode == SDL_SCANCODE_UNKNOWN, "Validate return value from SDL_GetScancodeFromName, expected: %i, got: %i", SDL_SCANCODE_UNKNOWN, scancode); - error = SDL_GetError(); - SDLTest_AssertPass("Call to SDL_GetError()"); - SDLTest_AssertCheck(error != NULL, "Validate that error message was not NULL"); - if (error != NULL) { - SDLTest_AssertCheck(SDL_strcmp(error, expectedError) == 0, - "Validate error message, expected: '%s', got: '%s'", expectedError, error); - } - - SDL_ClearError(); - SDLTest_AssertPass("Call to SDL_ClearError()"); + _checkInvalidNameError(); /* NULL input */ name = NULL; scancode = SDL_GetScancodeFromName((const char *)name); SDLTest_AssertPass("Call to SDL_GetScancodeFromName(NULL)"); SDLTest_AssertCheck(scancode == SDL_SCANCODE_UNKNOWN, "Validate return value from SDL_GetScancodeFromName, expected: %i, got: %i", SDL_SCANCODE_UNKNOWN, scancode); - error = SDL_GetError(); - SDLTest_AssertPass("Call to SDL_GetError()"); - SDLTest_AssertCheck(error != NULL, "Validate that error message was not NULL"); - if (error != NULL) { - SDLTest_AssertCheck(SDL_strcmp(error, expectedError) == 0, - "Validate error message, expected: '%s', got: '%s'", expectedError, error); - } - - SDL_ClearError(); - SDLTest_AssertPass("Call to SDL_ClearError()"); + _checkInvalidNameError(); return TEST_COMPLETED; } @@ -635,10 +699,17 @@ static const SDLTest_TestCaseReference keyboardTest11 = static const SDLTest_TestCaseReference keyboardTest12 = { (SDLTest_TestCaseFp)keyboard_getScancodeFromNameNegative, "keyboard_getScancodeFromNameNegative", "Check call to SDL_GetScancodeFromName with invalid data", TEST_ENABLED }; +static const SDLTest_TestCaseReference keyboardTest13 = + { (SDLTest_TestCaseFp)keyboard_getKeyNameNegative, "keyboard_getKeyNameNegative", "Check call to SDL_GetKeyName with invalid data", TEST_ENABLED }; + +static const SDLTest_TestCaseReference keyboardTest14 = + { (SDLTest_TestCaseFp)keyboard_getScancodeNameNegative, "keyboard_getScancodeNameNegative", "Check call to SDL_GetScancodeName with invalid data", TEST_ENABLED }; + /* Sequence of Keyboard test cases */ static const SDLTest_TestCaseReference *keyboardTests[] = { &keyboardTest1, &keyboardTest2, &keyboardTest3, &keyboardTest4, &keyboardTest5, &keyboardTest6, - &keyboardTest7, &keyboardTest8, &keyboardTest9, &keyboardTest10, &keyboardTest11, &keyboardTest12, NULL + &keyboardTest7, &keyboardTest8, &keyboardTest9, &keyboardTest10, &keyboardTest11, &keyboardTest12, + &keyboardTest13, &keyboardTest14, NULL }; /* Keyboard test suite (global) */ diff --git a/test/testautomation_mouse.c b/test/testautomation_mouse.c index f236f70958..69d82dd094 100644 --- a/test/testautomation_mouse.c +++ b/test/testautomation_mouse.c @@ -413,13 +413,13 @@ mouse_getSetRelativeMouseMode(void *arg) #define MOUSE_TESTWINDOW_HEIGHT 200 /** - * Create s test window + * Creates a test window */ -SDL_Window *_createTestWindow() +SDL_Window *_createMouseSuiteTestWindow() { int posX = 100, posY = 100, width = MOUSE_TESTWINDOW_WIDTH, height = MOUSE_TESTWINDOW_HEIGHT; SDL_Window *window; - window = SDL_CreateWindow("mouse_createTestWindow", posX, posY, width, height, 0); + window = SDL_CreateWindow("mouse_createMouseSuiteTestWindow", posX, posY, width, height, 0); SDLTest_AssertPass("SDL_CreateWindow()"); SDLTest_AssertCheck(window != NULL, "Check SDL_CreateWindow result"); return window; @@ -428,12 +428,12 @@ SDL_Window *_createTestWindow() /* * Destroy test window */ -void _destroyTestWindow(SDL_Window *window) +void _destroyMouseSuiteTestWindow(SDL_Window *window) { if (window != NULL) { SDL_DestroyWindow(window); window = NULL; - SDLTest_AssertPass("SDL_DestroyWindow"); + SDLTest_AssertPass("SDL_DestroyWindow()"); } } @@ -453,7 +453,7 @@ mouse_warpMouseInWindow(void *arg) SDL_Window *window; /* Create test window */ - window = _createTestWindow(); + window = _createMouseSuiteTestWindow(); if (window == NULL) return TEST_ABORTED; /* Mouse to random position inside window */ @@ -482,7 +482,7 @@ mouse_warpMouseInWindow(void *arg) /* Clean up test window */ - _destroyTestWindow(window); + _destroyMouseSuiteTestWindow(window); return TEST_COMPLETED; } @@ -505,7 +505,7 @@ mouse_getMouseFocus(void *arg) SDLTest_AssertPass("SDL_GetMouseFocus()"); /* Create test window */ - window = _createTestWindow(); + window = _createMouseSuiteTestWindow(); if (window == NULL) return TEST_ABORTED; /* Mouse to random position inside window */ @@ -531,7 +531,7 @@ mouse_getMouseFocus(void *arg) SDLTest_AssertPass("SDL_WarpMouseInWindow(...,%i,%i)", x, y); /* Clean up test window */ - _destroyTestWindow(window); + _destroyMouseSuiteTestWindow(window); /* Pump events to update focus state */ SDL_PumpEvents(); diff --git a/test/testautomation_rwops.c b/test/testautomation_rwops.c index 6c12b28e1a..be93809db2 100644 --- a/test/testautomation_rwops.c +++ b/test/testautomation_rwops.c @@ -21,16 +21,18 @@ const char* RWopsReadTestFilename = "rwops_read"; const char* RWopsWriteTestFilename = "rwops_write"; +const char* RWopsAlphabetFilename = "rwops_alphabet"; static const char RWopsHelloWorldTestString[] = "Hello World!"; static const char RWopsHelloWorldCompString[] = "Hello World!"; +static const char RWopsAlphabetString[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; /* Fixture */ void RWopsSetUp(void *arg) { - int fileLen = SDL_strlen(RWopsHelloWorldTestString); + int fileLen; FILE *handle; int writtenLen; int result; @@ -38,18 +40,32 @@ RWopsSetUp(void *arg) /* Clean up from previous runs (if any); ignore errors */ remove(RWopsReadTestFilename); remove(RWopsWriteTestFilename); + remove(RWopsAlphabetFilename); /* Create a test file */ handle = fopen(RWopsReadTestFilename, "w"); SDLTest_AssertCheck(handle != NULL, "Verify creation of file '%s' returned non NULL handle", RWopsReadTestFilename); if (handle == NULL) return; - /* Write some known test into it */ + /* 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); result = fclose(handle); SDLTest_AssertCheck(result == 0, "Verify result from fclose, expected 0, got %i", result); + /* Create a second test file */ + handle = fopen(RWopsAlphabetFilename, "w"); + SDLTest_AssertCheck(handle != NULL, "Verify creation of file '%s' returned non NULL handle", RWopsAlphabetFilename); + if (handle == NULL) return; + + /* 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); + result = fclose(handle); + SDLTest_AssertCheck(result == 0, "Verify result from fclose, expected 0, got %i", result); + SDLTest_AssertPass("Creation of test file completed"); } @@ -62,6 +78,8 @@ RWopsTearDown(void *arg) result = remove(RWopsReadTestFilename); SDLTest_AssertCheck(result == 0, "Verify result from remove(%s), expected 0, got %i", RWopsReadTestFilename, result); remove(RWopsWriteTestFilename); + result = remove(RWopsAlphabetFilename); + SDLTest_AssertCheck(result == 0, "Verify result from remove(%s), expected 0, got %i", RWopsAlphabetFilename, result); SDLTest_AssertPass("Cleanup of test files completed"); } @@ -78,6 +96,7 @@ _testGenericRWopsValidations(SDL_RWops *rw, int write) { char buf[sizeof(RWopsHelloWorldTestString)]; Sint64 i; + size_t s; int seekPos = SDLTest_RandomIntegerInRange(4, 8); /* Clear buffer */ @@ -89,13 +108,13 @@ _testGenericRWopsValidations(SDL_RWops *rw, int write) SDLTest_AssertCheck(i == (Sint64)0, "Verify seek to 0 with SDL_RWseek (RW_SEEK_SET), expected 0, got %i", i); /* Test write. */ - i = SDL_RWwrite(rw, RWopsHelloWorldTestString, sizeof(RWopsHelloWorldTestString)-1, 1); + s = SDL_RWwrite(rw, RWopsHelloWorldTestString, sizeof(RWopsHelloWorldTestString)-1, 1); SDLTest_AssertPass("Call to SDL_RWwrite succeeded"); if (write) { - SDLTest_AssertCheck(i == (Sint64)1, "Verify result of writing one byte with SDL_RWwrite, expected 1, got %i", i); + SDLTest_AssertCheck(s == (size_t)1, "Verify result of writing one byte with SDL_RWwrite, expected 1, got %i", s); } else { - SDLTest_AssertCheck(i != (Sint64)1, "Verify result of writing with SDL_RWwrite, expected !=1, got %i", i); + SDLTest_AssertCheck(s == (size_t)0, "Verify result of writing with SDL_RWwrite, expected: 0, got %i", s); } /* Test seek to random position */ @@ -109,13 +128,13 @@ _testGenericRWopsValidations(SDL_RWops *rw, int write) SDLTest_AssertCheck(i == (Sint64)0, "Verify seek to 0 with SDL_RWseek (RW_SEEK_SET), expected 0, got %i", i); /* Test read */ - i = SDL_RWread( rw, buf, 1, sizeof(RWopsHelloWorldTestString)-1 ); + s = SDL_RWread( rw, buf, 1, sizeof(RWopsHelloWorldTestString)-1 ); SDLTest_AssertPass("Call to SDL_RWread succeeded"); SDLTest_AssertCheck( - i == (Sint64)(sizeof(RWopsHelloWorldTestString)-1), + s == (size_t)(sizeof(RWopsHelloWorldTestString)-1), "Verify result from SDL_RWread, expected %i, got %i", sizeof(RWopsHelloWorldTestString)-1, - i); + s); SDLTest_AssertCheck( SDL_memcmp(buf, RWopsHelloWorldTestString, sizeof(RWopsHelloWorldTestString)-1 ) == 0, "Verify read bytes match expected string, expected '%s', got '%s'", RWopsHelloWorldTestString, buf); @@ -136,6 +155,14 @@ _testGenericRWopsValidations(SDL_RWops *rw, int write) "Verify seek to -1 with SDL_RWseek (RW_SEEK_END), expected %i, got %i", sizeof(RWopsHelloWorldTestString)-2, 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 %i", + i); } /*! @@ -170,6 +197,18 @@ rwops_testParamNegative (void) SDLTest_AssertPass("Call to SDL_RWFromFile(\"something\", NULL) succeeded"); SDLTest_AssertCheck(rwops == NULL, "Verify SDL_RWFromFile(\"something\", NULL) returns NULL"); + rwops = SDL_RWFromMem((void *)NULL, 10); + SDLTest_AssertPass("Call to SDL_RWFromMem(NULL, 10) succeeded"); + SDLTest_AssertCheck(rwops == NULL, "Verify SDL_RWFromMem(NULL, 10) returns NULL"); + + rwops = SDL_RWFromMem((void *)RWopsAlphabetString, 0); + SDLTest_AssertPass("Call to SDL_RWFromMem(data, 0) succeeded"); + SDLTest_AssertCheck(rwops == NULL, "Verify SDL_RWFromMem(data, 0) returns NULL"); + + rwops = SDL_RWFromConstMem((const void *)RWopsAlphabetString, 0); + SDLTest_AssertPass("Call to SDL_RWFromConstMem(data, 0) succeeded"); + SDLTest_AssertCheck(rwops == NULL, "Verify SDL_RWFromConstMem(data, 0) returns NULL"); + return TEST_COMPLETED; } @@ -177,13 +216,14 @@ rwops_testParamNegative (void) * @brief Tests opening from memory. * * \sa http://wiki.libsdl.org/moin.cgi/SDL_RWFromMem - * http://wiki.libsdl.org/moin.cgi/SDL_RWClose + * \sa http://wiki.libsdl.org/moin.cgi/SDL_RWClose */ int rwops_testMem (void) { char mem[sizeof(RWopsHelloWorldTestString)]; SDL_RWops *rw; + int result; /* Clear buffer */ SDL_zero(mem); @@ -196,12 +236,16 @@ rwops_testMem (void) /* Bail out if NULL */ if (rw == NULL) return TEST_ABORTED; + /* Check type */ + SDLTest_AssertCheck(rw->type == SDL_RWOPS_MEMORY, "Verify RWops type is SDL_RWOPS_MEMORY; expected: %d, got: %d", SDL_RWOPS_MEMORY, rw->type); + /* Run generic tests */ _testGenericRWopsValidations(rw, 1); /* Close */ - SDL_RWclose(rw); + result = SDL_RWclose(rw); SDLTest_AssertPass("Call to SDL_RWclose() succeeded"); + SDLTest_AssertCheck(result == 0, "Verify result value is 0; got: %d", result); return TEST_COMPLETED; } @@ -218,6 +262,7 @@ int rwops_testConstMem (void) { SDL_RWops *rw; + int result; /* Open handle */ rw = SDL_RWFromConstMem( RWopsHelloWorldCompString, sizeof(RWopsHelloWorldCompString)-1 ); @@ -227,12 +272,16 @@ rwops_testConstMem (void) /* Bail out if NULL */ if (rw == NULL) return TEST_ABORTED; + /* Check type */ + SDLTest_AssertCheck(rw->type == SDL_RWOPS_MEMORY_RO, "Verify RWops type is SDL_RWOPS_MEMORY_RO; expected: %d, got: %d", SDL_RWOPS_MEMORY_RO, rw->type); + /* Run generic tests */ _testGenericRWopsValidations( rw, 0 ); /* Close handle */ - SDL_RWclose(rw); + result = SDL_RWclose(rw); SDLTest_AssertPass("Call to SDL_RWclose() succeeded"); + SDLTest_AssertCheck(result == 0, "Verify result value is 0; got: %d", result); return TEST_COMPLETED; } @@ -249,6 +298,7 @@ int rwops_testFileRead(void) { SDL_RWops *rw; + int result; /* Read test. */ rw = SDL_RWFromFile(RWopsReadTestFilename, "r"); @@ -258,12 +308,28 @@ rwops_testFileRead(void) // Bail out if NULL if (rw == NULL) return TEST_ABORTED; + /* Check type */ +#if defined(ANDROID) + SDLTest_AssertCheck( + rw->type == SDL_RWOPS_STDFILE || rw->type == SDL_RWOPS_JNIFILE, + "Verify RWops type is SDL_RWOPS_STDFILE or SDL_RWOPS_JNIFILE; expected: %d|%d, got: %d", SDL_RWOPS_STDFILE, SDL_RWOPS_JNIFILE, rw->type); +#elif defined(__WIN32__) + SDLTest_AssertCheck( + rw->type == SDL_RWOPS_WINFILE, + "Verify RWops type is SDL_RWOPS_WINFILE; expected: %d, got: %d", SDL_RWOPS_WINFILE, rw->type); +#else + SDLTest_AssertCheck( + rw->type == SDL_RWOPS_STDFILE, + "Verify RWops type is SDL_RWOPS_STDFILE; expected: %d, got: %d", SDL_RWOPS_STDFILE, rw->type); +#endif + /* Run generic tests */ _testGenericRWopsValidations( rw, 0 ); /* Close handle */ - SDL_RWclose(rw); + result = SDL_RWclose(rw); SDLTest_AssertPass("Call to SDL_RWclose() succeeded"); + SDLTest_AssertCheck(result == 0, "Verify result value is 0; got: %d", result); return TEST_COMPLETED; } @@ -279,6 +345,7 @@ int rwops_testFileWrite(void) { SDL_RWops *rw; + int result; /* Write test. */ rw = SDL_RWFromFile(RWopsWriteTestFilename, "w+"); @@ -288,12 +355,28 @@ rwops_testFileWrite(void) // Bail out if NULL if (rw == NULL) return TEST_ABORTED; + /* Check type */ +#if defined(ANDROID) + SDLTest_AssertCheck( + rw->type == SDL_RWOPS_STDFILE || rw->type == SDL_RWOPS_JNIFILE, + "Verify RWops type is SDL_RWOPS_STDFILE or SDL_RWOPS_JNIFILE; expected: %d|%d, got: %d", SDL_RWOPS_STDFILE, SDL_RWOPS_JNIFILE, rw->type); +#elif defined(__WIN32__) + SDLTest_AssertCheck( + rw->type == SDL_RWOPS_WINFILE, + "Verify RWops type is SDL_RWOPS_WINFILE; expected: %d, got: %d", SDL_RWOPS_WINFILE, rw->type); +#else + SDLTest_AssertCheck( + rw->type == SDL_RWOPS_STDFILE, + "Verify RWops type is SDL_RWOPS_STDFILE; expected: %d, got: %d", SDL_RWOPS_STDFILE, rw->type); +#endif + /* Run generic tests */ _testGenericRWopsValidations( rw, 1 ); /* Close handle */ - SDL_RWclose(rw); + result = SDL_RWclose(rw); SDLTest_AssertPass("Call to SDL_RWclose() succeeded"); + SDLTest_AssertCheck(result == 0, "Verify result value is 0; got: %d", result); return TEST_COMPLETED; } @@ -312,6 +395,7 @@ rwops_testFPRead(void) { FILE *fp; SDL_RWops *rw; + int result; /* Run read tests. */ fp = fopen(RWopsReadTestFilename, "r"); @@ -331,12 +415,18 @@ rwops_testFPRead(void) return TEST_ABORTED; } + /* Check type */ + SDLTest_AssertCheck( + rw->type == SDL_RWOPS_STDFILE, + "Verify RWops type is SDL_RWOPS_STDFILE; expected: %d, got: %d", SDL_RWOPS_STDFILE, rw->type); + /* Run generic tests */ _testGenericRWopsValidations( rw, 0 ); /* Close handle - does fclose() */ - SDL_RWclose(rw); + result = SDL_RWclose(rw); SDLTest_AssertPass("Call to SDL_RWclose() succeeded"); + SDLTest_AssertCheck(result == 0, "Verify result value is 0; got: %d", result); return TEST_COMPLETED; } @@ -355,6 +445,7 @@ rwops_testFPWrite(void) { FILE *fp; SDL_RWops *rw; + int result; /* Run write tests. */ fp = fopen(RWopsWriteTestFilename, "w+"); @@ -374,12 +465,18 @@ rwops_testFPWrite(void) return TEST_ABORTED; } + /* Check type */ + SDLTest_AssertCheck( + rw->type == SDL_RWOPS_STDFILE, + "Verify RWops type is SDL_RWOPS_STDFILE; expected: %d, got: %d", SDL_RWOPS_STDFILE, rw->type); + /* Run generic tests */ _testGenericRWopsValidations( rw, 1 ); /* Close handle - does fclose() */ - SDL_RWclose(rw); + result = SDL_RWclose(rw); SDLTest_AssertPass("Call to SDL_RWclose() succeeded"); + SDLTest_AssertCheck(result == 0, "Verify result value is 0; got: %d", result); return TEST_COMPLETED; } @@ -398,6 +495,11 @@ rwops_testAllocFree (void) SDLTest_AssertPass("Call to SDL_AllocRW() succeeded"); SDLTest_AssertCheck(rw != NULL, "Validate result from SDL_AllocRW() is not NULL"); if (rw==NULL) return TEST_ABORTED; + + /* Check type */ + SDLTest_AssertCheck( + rw->type == SDL_RWOPS_UNKNOWN, + "Verify RWops type is SDL_RWOPS_UNKNOWN; expected: %d, got: %d", SDL_RWOPS_UNKNOWN, rw->type); /* Free context again */ SDL_FreeRW(rw); @@ -407,6 +509,72 @@ rwops_testAllocFree (void) } /** + * @brief Compare memory and file reads + * + * \sa http://wiki.libsdl.org/moin.cgi/SDL_RWFromMem + * \sa http://wiki.libsdl.org/moin.cgi/SDL_RWFromFile + */ +int +rwops_testCompareRWFromMemWithRWFromFile(void) +{ + int slen = 26; + char buffer_file[27]; + char buffer_mem[27]; + size_t rv_file; + size_t rv_mem; + Uint64 sv_file; + Uint64 sv_mem; + SDL_RWops* rwops_file; + SDL_RWops* rwops_mem; + int size; + int result; + + + for (size=5; size<10; size++) + { + /* Terminate buffer */ + buffer_file[slen] = 0; + buffer_mem[slen] = 0; + + /* Read/seek from memory */ + rwops_mem = SDL_RWFromMem((void *)RWopsAlphabetString, slen); + SDLTest_AssertPass("Call to SDL_RWFromMem()"); + rv_mem = SDL_RWread(rwops_mem, buffer_mem, size, 6); + SDLTest_AssertPass("Call to SDL_RWread(mem, size=%d)", size); + sv_mem = SDL_RWseek(rwops_mem, 0, SEEK_END); + SDLTest_AssertPass("Call to SDL_RWseek(mem,SEEK_END)"); + result = SDL_RWclose(rwops_mem); + SDLTest_AssertPass("Call to SDL_RWclose(mem)"); + SDLTest_AssertCheck(result == 0, "Verify result value is 0; got: %d", result); + + /* Read/see from file */ + rwops_file = SDL_RWFromFile(RWopsAlphabetFilename, "r"); + SDLTest_AssertPass("Call to SDL_RWFromFile()"); + rv_file = SDL_RWread(rwops_file, buffer_file, size, 6); + SDLTest_AssertPass("Call to SDL_RWread(file, size=%d)", size); + sv_file = SDL_RWseek(rwops_file, 0, SEEK_END); + SDLTest_AssertPass("Call to SDL_RWseek(file,SEEK_END)"); + result = SDL_RWclose(rwops_file); + SDLTest_AssertPass("Call to SDL_RWclose(file)"); + 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=%llu sv_file=%llu", sv_mem, 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( + SDL_strncmp(buffer_mem, RWopsAlphabetString, slen) == 0, + "Verify mem buffer contain alphabet string; expected: %s, got: %s", RWopsAlphabetString, buffer_mem); + SDLTest_AssertCheck( + SDL_strncmp(buffer_file, RWopsAlphabetString, slen) == 0, + "Verify file buffer contain alphabet string; expected: %s, got: %s", RWopsAlphabetString, buffer_file); + } + + return TEST_COMPLETED; +} + +/** * @brief Tests writing and reading from file using endian aware functions. * * \sa @@ -434,6 +602,7 @@ rwops_testFileWriteReadEndian(void) Uint16 LE16test; Uint32 LE32test; Uint64 LE64test; + int cresult; for (mode = 0; mode < 3; mode++) { @@ -522,9 +691,9 @@ rwops_testFileWriteReadEndian(void) SDLTest_AssertCheck(LE64test == LE64value, "Validate return value from SDL_ReadLE64, expected: %llu, got: %llu", LE64value, LE64test); /* Close handle */ - SDL_RWclose(rw); + cresult = SDL_RWclose(rw); SDLTest_AssertPass("Call to SDL_RWclose() succeeded"); - + SDLTest_AssertCheck(cresult == 0, "Verify result value is 0; got: %d", cresult); } return TEST_COMPLETED; @@ -561,10 +730,13 @@ static const SDLTest_TestCaseReference rwopsTest8 = static const SDLTest_TestCaseReference rwopsTest9 = { (SDLTest_TestCaseFp)rwops_testFileWriteReadEndian, "rwops_testFileWriteReadEndian", "Test writing and reading via the Endian aware functions", TEST_ENABLED }; +static const SDLTest_TestCaseReference rwopsTest10 = + { (SDLTest_TestCaseFp)rwops_testCompareRWFromMemWithRWFromFile, "rwops_testCompareRWFromMemWithRWFromFile", "Compare RWFromMem and RWFromFile RWops for read and seek", TEST_ENABLED }; + /* Sequence of RWops test cases */ static const SDLTest_TestCaseReference *rwopsTests[] = { &rwopsTest1, &rwopsTest2, &rwopsTest3, &rwopsTest4, &rwopsTest5, &rwopsTest6, - &rwopsTest7, &rwopsTest8, &rwopsTest9, NULL + &rwopsTest7, &rwopsTest8, &rwopsTest9, &rwopsTest10, NULL }; /* RWops test suite (global) */ diff --git a/test/testautomation_video.c b/test/testautomation_video.c index 49c7f4c9f1..1c0dac6c23 100644 --- a/test/testautomation_video.c +++ b/test/testautomation_video.c @@ -4,9 +4,56 @@ #include <stdio.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 +#else +#include <stdint.h> +#endif + #include "SDL.h" #include "SDL_test.h" +/* Private helpers */ + +/* + * Create a test window + */ +SDL_Window *_createVideoSuiteTestWindow(const char *title) +{ + SDL_Window* window; + int x, y, w, h; + SDL_WindowFlags flags; + + /* Standard window */ + x = SDLTest_RandomIntegerInRange(1, 100); + y = SDLTest_RandomIntegerInRange(1, 100); + w = SDLTest_RandomIntegerInRange(320, 1024); + h = SDLTest_RandomIntegerInRange(320, 768); + flags = SDL_WINDOW_SHOWN | SDL_WINDOW_RESIZABLE | SDL_WINDOW_BORDERLESS; + + window = SDL_CreateWindow(title, x, y, w, h, flags); + SDLTest_AssertPass("Call to SDL_CreateWindow('Title',%d,%d,%d,%d,%d)", x, y, w, h, flags); + SDLTest_AssertCheck(window != NULL, "Validate that returned window struct is not NULL"); + + return window; +} + +/* + * Destroy test window + */ +void _destroyVideoSuiteTestWindow(SDL_Window *window) +{ + if (window != NULL) { + SDL_DestroyWindow(window); + window = NULL; + SDLTest_AssertPass("Call to SDL_DestroyWindow"); + } +} + /* Test case functions */ /** @@ -133,10 +180,9 @@ video_createWindowVariousPositions(void *arg) window = SDL_CreateWindow(title, x, y, w, h, SDL_WINDOW_SHOWN); SDLTest_AssertPass("Call to SDL_CreateWindow('Title',%d,%d,%d,%d,SHOWN)", x, y, w, h); SDLTest_AssertCheck(window != NULL, "Validate that returned window struct is not NULL"); - if (window != NULL) { - SDL_DestroyWindow(window); - SDLTest_AssertPass("Call to SDL_DestroyWindow"); - } + + /* Clean up */ + _destroyVideoSuiteTestWindow(window); } } @@ -191,10 +237,9 @@ video_createWindowVariousSizes(void *arg) window = SDL_CreateWindow(title, x, y, w, h, SDL_WINDOW_SHOWN); SDLTest_AssertPass("Call to SDL_CreateWindow('Title',%d,%d,%d,%d,SHOWN)", x, y, w, h); SDLTest_AssertCheck(window != NULL, "Validate that returned window struct is not NULL"); - if (window != NULL) { - SDL_DestroyWindow(window); - SDLTest_AssertPass("Call to SDL_DestroyWindow"); - } + + /* Clean up */ + _destroyVideoSuiteTestWindow(window); } } @@ -269,15 +314,15 @@ video_createWindowVariousFlags(void *arg) window = SDL_CreateWindow(title, x, y, w, h, flags); SDLTest_AssertPass("Call to SDL_CreateWindow('Title',%d,%d,%d,%d,%d)", x, y, w, h, flags); SDLTest_AssertCheck(window != NULL, "Validate that returned window struct is not NULL"); - if (window != NULL) { - SDL_DestroyWindow(window); - SDLTest_AssertPass("Call to SDL_DestroyWindow"); - } + + /* Clean up */ + _destroyVideoSuiteTestWindow(window); } return TEST_COMPLETED; } + /** * @brief Tests the functionality of the SDL_GetWindowFlags function */ @@ -286,33 +331,1378 @@ video_getWindowFlags(void *arg) { SDL_Window* window; const char* title = "video_getWindowFlags Test Window"; - int x, y, w, h; SDL_WindowFlags flags; Uint32 actualFlags; - /* Standard window */ - x = SDLTest_RandomIntegerInRange(1, 100); - y = SDLTest_RandomIntegerInRange(1, 100); - w = SDLTest_RandomIntegerInRange(320, 1024); - h = SDLTest_RandomIntegerInRange(320, 768); - - /* Reliable flag */ + /* Reliable flag set always set in test window */ flags = SDL_WINDOW_SHOWN; - window = SDL_CreateWindow(title, x, y, w, h, flags); - SDLTest_AssertPass("Call to SDL_CreateWindow('Title',%d,%d,%d,%d,%d)", x, y, w, h, flags); - SDLTest_AssertCheck(window != NULL, "Validate that returned window struct is not NULL"); + /* Call against new test window */ + window = _createVideoSuiteTestWindow(title); if (window != NULL) { actualFlags = SDL_GetWindowFlags(window); SDLTest_AssertPass("Call to SDL_GetWindowFlags"); SDLTest_AssertCheck((flags & actualFlags) == flags, "Verify returned value has flags %d set, got: %d", flags, actualFlags); - SDL_DestroyWindow(window); - SDLTest_AssertPass("Call to SDL_DestroyWindow"); } + /* Clean up */ + _destroyVideoSuiteTestWindow(window); + + return TEST_COMPLETED; +} + +/** + * @brief Tests the functionality of the SDL_GetNumDisplayModes function + */ +int +video_getNumDisplayModes(void *arg) +{ + int result; + int displayNum; + int i; + + /* Get number of displays */ + displayNum = SDL_GetNumVideoDisplays(); + SDLTest_AssertPass("Call to SDL_GetNumVideoDisplays"); + + /* Make call for each display */ + for (i=0; i<displayNum; i++) { + result = SDL_GetNumDisplayModes(i); + SDLTest_AssertPass("Call to SDL_GetNumDisplayModes(%d)", i); + SDLTest_AssertCheck(result >= 1, "Validate returned value from function; expected: >=1; got: %d", result); + } + + return TEST_COMPLETED; +} + +/** + * @brief Tests negative call to SDL_GetNumDisplayModes function + */ +int +video_getNumDisplayModesNegative(void *arg) +{ + int result; + int displayNum; + int displayIndex; + + /* Get number of displays */ + displayNum = SDL_GetNumVideoDisplays(); + SDLTest_AssertPass("Call to SDL_GetNumVideoDisplays"); + + /* Invalid boundary values */ + displayIndex = SDLTest_RandomSint32BoundaryValue(0, displayNum, SDL_FALSE); + result = SDL_GetNumDisplayModes(displayIndex); + SDLTest_AssertPass("Call to SDL_GetNumDisplayModes(%d=out-of-bounds/boundary)", displayIndex); + SDLTest_AssertCheck(result < 0, "Validate returned value from function; expected: <0; got: %d", result); + + /* Large (out-of-bounds) display index */ + displayIndex = SDLTest_RandomIntegerInRange(-2000, -1000); + result = SDL_GetNumDisplayModes(displayIndex); + SDLTest_AssertPass("Call to SDL_GetNumDisplayModes(%d=out-of-bounds/large negative)", displayIndex); + SDLTest_AssertCheck(result < 0, "Validate returned value from function; expected: <0; got: %d", result); + + displayIndex = SDLTest_RandomIntegerInRange(1000, 2000); + result = SDL_GetNumDisplayModes(displayIndex); + SDLTest_AssertPass("Call to SDL_GetNumDisplayModes(%d=out-of-bounds/large positive)", displayIndex); + SDLTest_AssertCheck(result < 0, "Validate returned value from function; expected: <0; got: %d", result); + + return TEST_COMPLETED; +} + +/** + * @brief Tests the functionality of the SDL_GetClosestDisplayMode function against current resolution + */ +int +video_getClosestDisplayModeCurrentResolution(void *arg) +{ + int result; + SDL_DisplayMode current; + SDL_DisplayMode target; + SDL_DisplayMode closest; + SDL_DisplayMode* dResult; + int displayNum; + int i; + int variation; + + /* Get number of displays */ + displayNum = SDL_GetNumVideoDisplays(); + SDLTest_AssertPass("Call to SDL_GetNumVideoDisplays"); + + /* Make calls for each display */ + for (i=0; i<displayNum; i++) { + SDLTest_Log("Testing against display: %d", i); + + /* Get first display mode to get a sane resolution; this should always work */ + result = SDL_GetDisplayMode(i, 0, ¤t); + SDLTest_AssertPass("Call to SDL_GetDisplayMode"); + SDLTest_AssertCheck(result == 0, "Verify return value, expected: 0, got: %d", result); + if (result != 0) { + return TEST_ABORTED; + } + + /* Set the desired resolution equals to current resolution */ + target.w = current.w; + target.h = current.h; + for (variation = 0; variation < 8; variation ++) { + /* Vary constraints on other query parameters */ + target.format = (variation & 1) ? current.format : 0; + target.refresh_rate = (variation & 2) ? current.refresh_rate : 0; + target.driverdata = (variation & 4) ? current.driverdata : 0; + + /* Make call */ + dResult = SDL_GetClosestDisplayMode(i, &target, &closest); + SDLTest_AssertPass("Call to SDL_GetClosestDisplayMode(target=current/variation%d)", variation); + SDLTest_AssertCheck(dResult != NULL, "Verify returned value is not NULL"); + + /* Check that one gets the current resolution back again */ + SDLTest_AssertCheck(closest.w == current.w, "Verify returned width matches current width; expected: %d, got: %d", current.w, closest.w); + SDLTest_AssertCheck(closest.h == current.h, "Verify returned height matches current height; expected: %d, got: %d", current.h, closest.h); + SDLTest_AssertCheck(closest.w == dResult->w, "Verify return value matches assigned value; expected: %d, got: %d", closest.w, dResult->w); + SDLTest_AssertCheck(closest.h == dResult->h, "Verify return value matches assigned value; expected: %d, got: %d", closest.h, dResult->h); + } + } + + return TEST_COMPLETED; +} + +/** + * @brief Tests the functionality of the SDL_GetClosestDisplayMode function against random resolution + */ +int +video_getClosestDisplayModeRandomResolution(void *arg) +{ + SDL_DisplayMode target; + SDL_DisplayMode closest; + SDL_DisplayMode* dResult; + int displayNum; + int i; + int variation; + + /* Get number of displays */ + displayNum = SDL_GetNumVideoDisplays(); + SDLTest_AssertPass("Call to SDL_GetNumVideoDisplays"); + + /* Make calls for each display */ + for (i=0; i<displayNum; i++) { + SDLTest_Log("Testing against display: %d", i); + + for (variation = 0; variation < 16; variation ++) { + + /* Set random constraints */ + target.w = (variation & 1) ? SDLTest_RandomIntegerInRange(1, 4096) : 0; + target.h = (variation & 2) ? SDLTest_RandomIntegerInRange(1, 4096) : 0; + target.format = (variation & 4) ? SDLTest_RandomIntegerInRange(1, 10) : 0; + target.refresh_rate = (variation & 8) ? SDLTest_RandomIntegerInRange(25, 120) : 0; + target.driverdata = 0; + + /* Make call; may or may not find anything, so don't validate any further */ + dResult = SDL_GetClosestDisplayMode(i, &target, &closest); + SDLTest_AssertPass("Call to SDL_GetClosestDisplayMode(target=random/variation%d)", variation); + } + } + + return TEST_COMPLETED; +} + +/** + * @brief Tests call to SDL_GetWindowBrightness + * +* @sa http://wiki.libsdl.org/moin.fcg/SDL_GetWindowBrightness + */ +int +video_getWindowBrightness(void *arg) +{ + SDL_Window* window; + const char* title = "video_getWindowBrightness Test Window"; + float result; + + /* Call against new test window */ + window = _createVideoSuiteTestWindow(title); + if (window != NULL) { + result = SDL_GetWindowBrightness(window); + SDLTest_AssertPass("Call to SDL_GetWindowBrightness"); + SDLTest_AssertCheck(result >= 0.0 && result <= 1.0, "Validate range of result value; expected: [0.0, 1.0], got: %f", result); + } + + /* Clean up */ + _destroyVideoSuiteTestWindow(window); + + return TEST_COMPLETED; +} + +/** + * @brief Tests call to SDL_GetWindowBrightness with invalid input + * +* @sa http://wiki.libsdl.org/moin.fcg/SDL_GetWindowBrightness + */ +int +video_getWindowBrightnessNegative(void *arg) +{ + const char *invalidWindowError = "Invalid window"; + char *lastError; + const char* title = "video_getWindowBrightnessNegative Test Window"; + float result; + + /* Call against invalid window */ + result = SDL_GetWindowBrightness(NULL); + SDLTest_AssertPass("Call to SDL_GetWindowBrightness(window=NULL)"); + SDLTest_AssertCheck(result == 1.0, "Validate result value; expected: 1.0, got: %f", result); + lastError = (char *)SDL_GetError(); + SDLTest_AssertPass("SDL_GetError()"); + SDLTest_AssertCheck(lastError != NULL, "Verify error message is not NULL"); + if (lastError != NULL) { + SDLTest_AssertCheck(SDL_strcmp(lastError, invalidWindowError) == 0, + "SDL_GetError(): expected message '%s', was message: '%s'", + invalidWindowError, + lastError); + } + + return TEST_COMPLETED; +} + +/** + * @brief Tests call to SDL_GetWindowDisplayMode + * + * @sa http://wiki.libsdl.org/moin.fcg/SDL_GetWindowDisplayMode + */ +int +video_getWindowDisplayMode(void *arg) +{ + SDL_Window* window; + const char* title = "video_getWindowDisplayMode Test Window"; + SDL_DisplayMode mode; + int result; + + /* Invalidate part of the mode content so we can check values later */ + mode.w = -1; + mode.h = -1; + mode.refresh_rate = -1; + + /* Call against new test window */ + window = _createVideoSuiteTestWindow(title); + if (window != NULL) { + result = SDL_GetWindowDisplayMode(window, &mode); + SDLTest_AssertPass("Call to SDL_GetWindowDisplayMode"); + SDLTest_AssertCheck(result == 0, "Validate result value; expected: 0, got: %d", result); + SDLTest_AssertCheck(mode.w > 0, "Validate mode.w content; expected: >0, got: %d", mode.w); + SDLTest_AssertCheck(mode.h > 0, "Validate mode.h content; expected: >0, got: %d", mode.h); + SDLTest_AssertCheck(mode.refresh_rate > 0, "Validate mode.refresh_rate content; expected: >0, got: %d", mode.refresh_rate); + } + + /* Clean up */ + _destroyVideoSuiteTestWindow(window); + + return TEST_COMPLETED; +} + +/* Helper function that checks for an 'Invalid window' error */ +void _checkInvalidWindowError() +{ + const char *invalidWindowError = "Invalid window"; + char *lastError; + + lastError = (char *)SDL_GetError(); + SDLTest_AssertPass("SDL_GetError()"); + SDLTest_AssertCheck(lastError != NULL, "Verify error message is not NULL"); + if (lastError != NULL) { + SDLTest_AssertCheck(SDL_strcmp(lastError, invalidWindowError) == 0, + "SDL_GetError(): expected message '%s', was message: '%s'", + invalidWindowError, + lastError); + SDL_ClearError(); + SDLTest_AssertPass("Call to SDL_ClearError()"); + } +} + +/** + * @brief Tests call to SDL_GetWindowDisplayMode with invalid input + * + * @sa http://wiki.libsdl.org/moin.fcg/SDL_GetWindowDisplayMode + */ +int +video_getWindowDisplayModeNegative(void *arg) +{ + const char *expectedError = "Parameter 'mode' is invalid"; + char *lastError; + SDL_Window* window; + const char* title = "video_getWindowDisplayModeNegative Test Window"; + SDL_DisplayMode mode; + int result; + + /* Call against new test window */ + window = _createVideoSuiteTestWindow(title); + if (window != NULL) { + result = SDL_GetWindowDisplayMode(window, NULL); + SDLTest_AssertPass("Call to SDL_GetWindowDisplayMode(...,mode=NULL)"); + SDLTest_AssertCheck(result == -1, "Validate result value; expected: -1, got: %d", result); + lastError = (char *)SDL_GetError(); + SDLTest_AssertPass("SDL_GetError()"); + SDLTest_AssertCheck(lastError != NULL, "Verify error message is not NULL"); + if (lastError != NULL) { + SDLTest_AssertCheck(SDL_strcmp(lastError, expectedError) == 0, + "SDL_GetError(): expected message '%s', was message: '%s'", + expectedError, + lastError); + } + } + + /* Clean up */ + _destroyVideoSuiteTestWindow(window); + + /* Call against invalid window */ + result = SDL_GetWindowDisplayMode(NULL, &mode); + SDLTest_AssertPass("Call to SDL_GetWindowDisplayMode(window=NULL,...)"); + SDLTest_AssertCheck(result == -1, "Validate result value; expected: -1, got: %d", result); + _checkInvalidWindowError(); + + return TEST_COMPLETED; +} + +/** + * @brief Tests call to SDL_GetWindowGammaRamp + * + * @sa http://wiki.libsdl.org/moin.fcg/SDL_GetWindowGammaRamp + */ +int +video_getWindowGammaRamp(void *arg) +{ + SDL_Window* window; + const char* title = "video_getWindowGammaRamp Test Window"; + Uint16 red[256]; + Uint16 green[256]; + Uint16 blue[256]; + int result; + + /* Call against new test window */ + window = _createVideoSuiteTestWindow(title); + if (window == NULL) return TEST_ABORTED; + + /* Retrieve no channel */ + result = SDL_GetWindowGammaRamp(window, NULL, NULL, NULL); + SDLTest_AssertPass("Call to SDL_GetWindowGammaRamp(all NULL)"); + SDLTest_AssertCheck(result == 0, "Validate result value; expected: 0, got: %d", result); + + /* Retrieve single channel */ + result = SDL_GetWindowGammaRamp(window, red, NULL, NULL); + SDLTest_AssertPass("Call to SDL_GetWindowGammaRamp(r)"); + SDLTest_AssertCheck(result == 0, "Validate result value; expected: 0, got: %d", result); + + result = SDL_GetWindowGammaRamp(window, NULL, green, NULL); + SDLTest_AssertPass("Call to SDL_GetWindowGammaRamp(g)"); + SDLTest_AssertCheck(result == 0, "Validate result value; expected: 0, got: %d", result); + + result = SDL_GetWindowGammaRamp(window, NULL, NULL, blue); + SDLTest_AssertPass("Call to SDL_GetWindowGammaRamp(b)"); + SDLTest_AssertCheck(result == 0, "Validate result value; expected: 0, got: %d", result); + + /* Retrieve two channels */ + result = SDL_GetWindowGammaRamp(window, red, green, NULL); + SDLTest_AssertPass("Call to SDL_GetWindowGammaRamp(r, g)"); + SDLTest_AssertCheck(result == 0, "Validate result value; expected: 0, got: %d", result); + + result = SDL_GetWindowGammaRamp(window, NULL, green, blue); + SDLTest_AssertPass("Call to SDL_GetWindowGammaRamp(g,b)"); + SDLTest_AssertCheck(result == 0, "Validate result value; expected: 0, got: %d", result); + + result = SDL_GetWindowGammaRamp(window, red, NULL, blue); + SDLTest_AssertPass("Call to SDL_GetWindowGammaRamp(r,b)"); + SDLTest_AssertCheck(result == 0, "Validate result value; expected: 0, got: %d", result); + + /* Retrieve all channels */ + result = SDL_GetWindowGammaRamp(window, red, green, blue); + SDLTest_AssertPass("Call to SDL_GetWindowGammaRamp(r,g,b)"); + SDLTest_AssertCheck(result == 0, "Validate result value; expected: 0, got: %d", result); + + /* Clean up */ + _destroyVideoSuiteTestWindow(window); + + return TEST_COMPLETED; +} + +/** + * @brief Tests call to SDL_GetWindowGammaRamp with invalid input + * +* @sa http://wiki.libsdl.org/moin.fcg/SDL_GetWindowGammaRamp + */ +int +video_getWindowGammaRampNegative(void *arg) +{ + const char* title = "video_getWindowGammaRampNegative Test Window"; + Uint16 red[256]; + Uint16 green[256]; + Uint16 blue[256]; + int result; + + SDL_ClearError(); + SDLTest_AssertPass("Call to SDL_ClearError()"); + + /* Call against invalid window */ + result = SDL_GetWindowGammaRamp(NULL, red, green, blue); + SDLTest_AssertPass("Call to SDL_GetWindowGammaRamp(window=NULL,r,g,b)"); + SDLTest_AssertCheck(result == -1, "Validate result value; expected: -1, got: %f", result); + _checkInvalidWindowError(); + + return TEST_COMPLETED; +} + +/* Helper for setting and checking the window grab state */ +void +_setAndCheckWindowGrabState(SDL_Window* window, SDL_bool desiredState) +{ + SDL_bool currentState; + + /* Set state */ + SDL_SetWindowGrab(window, desiredState); + SDLTest_AssertPass("Call to SDL_SetWindowGrab(%s)", (desiredState == SDL_FALSE) ? "SDL_FALSE" : "SDL_TRUE"); + + /* Get and check state */ + currentState = SDL_GetWindowGrab(window); + SDLTest_AssertPass("Call to SDL_GetWindowGrab()"); + SDLTest_AssertCheck( + currentState == desiredState, + "Validate returned state; expected: %s, got: %s", + (desiredState == SDL_FALSE) ? "SDL_FALSE" : "SDL_TRUE", + (currentState == SDL_FALSE) ? "SDL_FALSE" : "SDL_TRUE"); +} + +/** + * @brief Tests call to SDL_GetWindowGrab and SDL_SetWindowGrab + * + * @sa http://wiki.libsdl.org/moin.fcg/SDL_GetWindowGrab + * @sa http://wiki.libsdl.org/moin.fcg/SDL_SetWindowGrab + */ +int +video_getSetWindowGrab(void *arg) +{ + const char* title = "video_getSetWindowGrab Test Window"; + SDL_Window* window; + SDL_bool originalState, dummyState, currentState, desiredState; + + /* Call against new test window */ + window = _createVideoSuiteTestWindow(title); + if (window == NULL) return TEST_ABORTED; + + /* Get state */ + originalState = SDL_GetWindowGrab(window); + SDLTest_AssertPass("Call to SDL_GetWindowGrab()"); + + /* F */ + _setAndCheckWindowGrabState(window, SDL_FALSE); + + /* F --> F */ + _setAndCheckWindowGrabState(window, SDL_FALSE); + + /* F --> T */ + _setAndCheckWindowGrabState(window, SDL_TRUE); + + /* T --> T */ + _setAndCheckWindowGrabState(window, SDL_TRUE); + + /* T --> F */ + _setAndCheckWindowGrabState(window, SDL_FALSE); + + /* Negative tests */ + dummyState = SDL_GetWindowGrab(NULL); + SDLTest_AssertPass("Call to SDL_GetWindowGrab(window=NULL)"); + _checkInvalidWindowError(); + + SDL_SetWindowGrab(NULL, SDL_FALSE); + SDLTest_AssertPass("Call to SDL_SetWindowGrab(window=NULL,SDL_FALSE)"); + _checkInvalidWindowError(); + + SDL_SetWindowGrab(NULL, SDL_TRUE); + SDLTest_AssertPass("Call to SDL_SetWindowGrab(window=NULL,SDL_FALSE)"); + _checkInvalidWindowError(); + + /* State should still be F */ + desiredState = SDL_FALSE; + currentState = SDL_GetWindowGrab(window); + SDLTest_AssertPass("Call to SDL_GetWindowGrab()"); + SDLTest_AssertCheck( + currentState == desiredState, + "Validate returned state; expected: %s, got: %s", + (desiredState == SDL_FALSE) ? "SDL_FALSE" : "SDL_TRUE", + (currentState == SDL_FALSE) ? "SDL_FALSE" : "SDL_TRUE"); + + /* Restore state */ + _setAndCheckWindowGrabState(window, originalState); + + /* Clean up */ + _destroyVideoSuiteTestWindow(window); + + return TEST_COMPLETED; +} + + +/** + * @brief Tests call to SDL_GetWindowID and SDL_GetWindowFromID + * + * @sa http://wiki.libsdl.org/moin.fcg/SDL_GetWindowID + * @sa http://wiki.libsdl.org/moin.fcg/SDL_SetWindowFromID + */ +int +video_getWindowId(void *arg) +{ + const char* title = "video_getWindowId Test Window"; + SDL_Window* window; + SDL_Window* result; + Uint32 id, randomId; + + /* Call against new test window */ + window = _createVideoSuiteTestWindow(title); + if (window == NULL) return TEST_ABORTED; + + /* Get ID */ + id = SDL_GetWindowID(window); + SDLTest_AssertPass("Call to SDL_GetWindowID()"); + + /* Get window from ID */ + result = SDL_GetWindowFromID(id); + SDLTest_AssertPass("Call to SDL_GetWindowID(%d)", id); + SDLTest_AssertCheck(result == window, "Verify result matches window pointer"); + + /* Get window from random large ID, no result check */ + randomId = SDLTest_RandomIntegerInRange(UINT8_MAX,UINT16_MAX); + result = SDL_GetWindowFromID(randomId); + SDLTest_AssertPass("Call to SDL_GetWindowID(%d/random_large)", randomId); + + /* Get window from 0 and Uint32 max ID, no result check */ + result = SDL_GetWindowFromID(0); + SDLTest_AssertPass("Call to SDL_GetWindowID(0)"); + result = SDL_GetWindowFromID(UINT32_MAX); + SDLTest_AssertPass("Call to SDL_GetWindowID(UINT32_MAX)"); + + /* Clean up */ + _destroyVideoSuiteTestWindow(window); + + /* Get window from ID for closed window*/ + result = SDL_GetWindowFromID(id); + SDLTest_AssertPass("Call to SDL_GetWindowID(%d/closed_window)", id); + SDLTest_AssertCheck(result == NULL, "Verify result is NULL"); + + /* Negative test */ + SDL_ClearError(); + SDLTest_AssertPass("Call to SDL_ClearError()"); + id = SDL_GetWindowID(NULL); + SDLTest_AssertPass("Call to SDL_GetWindowID(window=NULL)"); + _checkInvalidWindowError(); + + return TEST_COMPLETED; +} + +/** + * @brief Tests call to SDL_GetWindowPixelFormat + * + * @sa http://wiki.libsdl.org/moin.fcg/SDL_GetWindowPixelFormat + */ +int +video_getWindowPixelFormat(void *arg) +{ + const char* title = "video_getWindowPixelFormat Test Window"; + SDL_Window* window; + Uint32 format; + + /* Call against new test window */ + window = _createVideoSuiteTestWindow(title); + if (window == NULL) return TEST_ABORTED; + + /* Get format */ + format = SDL_GetWindowPixelFormat(window); + SDLTest_AssertPass("Call to SDL_GetWindowPixelFormat()"); + SDLTest_AssertCheck(format != SDL_PIXELFORMAT_UNKNOWN, "Verify that returned format is valid; expected: != %d, got: %d", SDL_PIXELFORMAT_UNKNOWN, format); + + /* Clean up */ + _destroyVideoSuiteTestWindow(window); + + /* Negative test */ + SDL_ClearError(); + SDLTest_AssertPass("Call to SDL_ClearError()"); + format = SDL_GetWindowPixelFormat(NULL); + SDLTest_AssertPass("Call to SDL_GetWindowPixelFormat(window=NULL)"); + _checkInvalidWindowError(); + return TEST_COMPLETED; } +/** + * @brief Tests call to SDL_GetWindowPosition and SDL_SetWindowPosition + * + * @sa http://wiki.libsdl.org/moin.fcg/SDL_GetWindowPosition + * @sa http://wiki.libsdl.org/moin.fcg/SDL_SetWindowPosition + */ +int +video_getSetWindowPosition(void *arg) +{ + const char* title = "video_getSetWindowPosition Test Window"; + SDL_Window* window; + int xVariation, yVariation; + int referenceX, referenceY; + int currentX, currentY; + int desiredX, desiredY; + + /* Call against new test window */ + window = _createVideoSuiteTestWindow(title); + if (window == NULL) return TEST_ABORTED; + + for (xVariation = 0; xVariation < 4; xVariation++) { + for (yVariation = 0; yVariation < 4; yVariation++) { + switch(xVariation) { + case 0: + /* Zero X Position */ + desiredX = 0; + break; + case 1: + /* Random X position inside screen */ + desiredX = SDLTest_RandomIntegerInRange(1, 100); + break; + case 2: + /* Random X position outside screen (positive) */ + desiredX = SDLTest_RandomIntegerInRange(10000, 11000); + break; + case 3: + /* Random X position outside screen (negative) */ + desiredX = SDLTest_RandomIntegerInRange(-1000, -100); + break; + } + + switch(yVariation) { + case 0: + /* Zero X Position */ + desiredY = 0; + break; + case 1: + /* Random X position inside screen */ + desiredY = SDLTest_RandomIntegerInRange(1, 100); + break; + case 2: + /* Random X position outside screen (positive) */ + desiredY = SDLTest_RandomIntegerInRange(10000, 11000); + break; + case 3: + /* Random Y position outside screen (negative) */ + desiredY = SDLTest_RandomIntegerInRange(-1000, -100); + break; + } + + /* Set position */ + SDL_SetWindowPosition(window, desiredX, desiredY); + SDLTest_AssertPass("Call to SDL_SetWindowPosition(...,%d,%d)", desiredX, desiredY); + + /* Get position */ + currentX = desiredX + 1; + currentY = desiredY + 1; + SDL_GetWindowPosition(window, ¤tX, ¤tY); + SDLTest_AssertPass("Call to SDL_GetWindowPosition()"); + SDLTest_AssertCheck(desiredX == currentX, "Verify returned X position; expected: %d, got: %d", desiredX, currentX); + SDLTest_AssertCheck(desiredY == currentY, "Verify returned Y position; expected: %d, got: %d", desiredY, currentY); + + /* Get position X */ + currentX = desiredX + 1; + SDL_GetWindowPosition(window, ¤tX, NULL); + SDLTest_AssertPass("Call to SDL_GetWindowPosition(&y=NULL)"); + SDLTest_AssertCheck(desiredX == currentX, "Verify returned X position; expected: %d, got: %d", desiredX, currentX); + + /* Get position Y */ + currentY = desiredY + 1; + SDL_GetWindowPosition(window, NULL, ¤tY); + SDLTest_AssertPass("Call to SDL_GetWindowPosition(&x=NULL)"); + SDLTest_AssertCheck(desiredY == currentY, "Verify returned Y position; expected: %d, got: %d", desiredY, currentY); + } + } + + /* Dummy call with both pointers NULL */ + SDL_GetWindowPosition(window, NULL, NULL); + SDLTest_AssertPass("Call to SDL_GetWindowPosition(&x=NULL,&y=NULL)"); + + /* Clean up */ + _destroyVideoSuiteTestWindow(window); + + /* Set some 'magic' value for later check that nothing was changed */ + referenceX = SDLTest_RandomSint32(); + referenceY = SDLTest_RandomSint32(); + currentX = referenceX; + currentY = referenceY; + desiredX = SDLTest_RandomSint32(); + desiredY = SDLTest_RandomSint32(); + + /* Negative tests */ + SDL_ClearError(); + SDLTest_AssertPass("Call to SDL_ClearError()"); + SDL_GetWindowPosition(NULL, ¤tX, ¤tY); + SDLTest_AssertPass("Call to SDL_GetWindowPosition(window=NULL)"); + SDLTest_AssertCheck( + currentX == referenceX && currentY == referenceY, + "Verify that content of X and Y pointers has not been modified; expected: %d,%d; got: %d,%d", + referenceX, referenceY, + currentX, currentY); + _checkInvalidWindowError(); + + SDL_GetWindowPosition(NULL, NULL, NULL); + SDLTest_AssertPass("Call to SDL_GetWindowPosition(NULL, NULL, NULL)"); + _checkInvalidWindowError(); + + SDL_SetWindowPosition(NULL, desiredX, desiredY); + SDLTest_AssertPass("Call to SDL_SetWindowPosition(window=NULL)"); + _checkInvalidWindowError(); + + return TEST_COMPLETED; +} + +/* Helper function that checks for an 'Invalid parameter' error */ +void _checkInvalidParameterError() +{ + const char *invalidParameterError = "Parameter"; + char *lastError; + + lastError = (char *)SDL_GetError(); + SDLTest_AssertPass("SDL_GetError()"); + SDLTest_AssertCheck(lastError != NULL, "Verify error message is not NULL"); + if (lastError != NULL) { + SDLTest_AssertCheck(SDL_strncmp(lastError, invalidParameterError, SDL_strlen(invalidParameterError)) == 0, + "SDL_GetError(): expected message starts with '%s', was message: '%s'", + invalidParameterError, + lastError); + SDL_ClearError(); + SDLTest_AssertPass("Call to SDL_ClearError()"); + } +} + +/** + * @brief Tests call to SDL_GetWindowSize and SDL_SetWindowSize + * + * @sa http://wiki.libsdl.org/moin.fcg/SDL_GetWindowSize + * @sa http://wiki.libsdl.org/moin.fcg/SDL_SetWindowSize + */ +int +video_getSetWindowSize(void *arg) +{ + const char* title = "video_getSetWindowSize Test Window"; + SDL_Window* window; + int result; + SDL_Rect display; + int wVariation, hVariation; + int referenceW, referenceH; + int currentW, currentH; + int desiredW, desiredH; + + /* Get display bounds for size range */ + result = SDL_GetDisplayBounds(0, &display); + SDLTest_AssertPass("SDL_GetDisplayBounds()"); + SDLTest_AssertCheck(result == 0, "Verify return value; expected: 0, got: %d", result); + if (result != 0) return TEST_ABORTED; + + /* Call against new test window */ + window = _createVideoSuiteTestWindow(title); + if (window == NULL) return TEST_ABORTED; + + for (wVariation = 0; wVariation < 4; wVariation++) { + for (hVariation = 0; hVariation < 4; hVariation++) { + switch(wVariation) { + case 0: + /* 1 Pixel Wide */ + desiredW = 1; + break; + case 1: + /* Random width inside screen */ + desiredW = SDLTest_RandomIntegerInRange(1, 100); + break; + case 2: + /* Width at screen size */ + desiredW = display.w; + break; + case 3: + /* Width 1 pixel larger than screen */ + desiredW = display.w + 1; + break; + } + + switch(hVariation) { + case 0: + /* 1 Pixel High */ + desiredH = 1; + break; + case 1: + /* Random height inside screen */ + desiredH = SDLTest_RandomIntegerInRange(1, 100); + break; + case 2: + /* Height at screen size */ + desiredH = display.h; + break; + case 3: + /* Height 1 pixel larger than screen */ + desiredH = display.h + 1; + break; + } + + /* Set size */ + SDL_SetWindowSize(window, desiredW, desiredH); + SDLTest_AssertPass("Call to SDL_SetWindowSize(...,%d,%d)", desiredW, desiredH); + + /* Get size */ + currentW = desiredW + 1; + currentH = desiredH + 1; + SDL_GetWindowSize(window, ¤tW, ¤tH); + SDLTest_AssertPass("Call to SDL_GetWindowSize()"); + SDLTest_AssertCheck(desiredW == currentW, "Verify returned width; expected: %d, got: %d", desiredW, currentW); + SDLTest_AssertCheck(desiredH == currentH, "Verify returned height; expected: %d, got: %d", desiredH, currentH); + + /* Get just width */ + currentW = desiredW + 1; + SDL_GetWindowSize(window, ¤tW, NULL); + SDLTest_AssertPass("Call to SDL_GetWindowSize(&h=NULL)"); + SDLTest_AssertCheck(desiredW == currentW, "Verify returned width; expected: %d, got: %d", desiredW, currentH); + + /* Get just height */ + currentH = desiredH + 1; + SDL_GetWindowSize(window, NULL, ¤tH); + SDLTest_AssertPass("Call to SDL_GetWindowSize(&w=NULL)"); + SDLTest_AssertCheck(desiredH == currentH, "Verify returned height; expected: %d, got: %d", desiredW, currentH); + } + } + + /* Dummy call with both pointers NULL */ + SDL_GetWindowSize(window, NULL, NULL); + SDLTest_AssertPass("Call to SDL_GetWindowSize(&w=NULL,&h=NULL)"); + + /* Negative tests for parameter input */ + SDL_ClearError(); + SDLTest_AssertPass("Call to SDL_ClearError()"); + for (desiredH = -2; desiredH < 2; desiredH++) { + for (desiredW = -2; desiredW < 2; desiredW++) { + if (desiredW <= 0 || desiredH <= 0) { + SDL_SetWindowSize(window, desiredW, desiredH); + SDLTest_AssertPass("Call to SDL_SetWindowSize(...,%d,%d)", desiredW, desiredH); + _checkInvalidParameterError(); + } + } + } + + /* Clean up */ + _destroyVideoSuiteTestWindow(window); + + /* Set some 'magic' value for later check that nothing was changed */ + referenceW = SDLTest_RandomSint32(); + referenceH = SDLTest_RandomSint32(); + currentW = referenceW; + currentH = referenceH; + desiredW = SDLTest_RandomSint32(); + desiredH = SDLTest_RandomSint32(); + + /* Negative tests for window input */ + SDL_ClearError(); + SDLTest_AssertPass("Call to SDL_ClearError()"); + SDL_GetWindowSize(NULL, ¤tW, ¤tH); + SDLTest_AssertPass("Call to SDL_GetWindowSize(window=NULL)"); + SDLTest_AssertCheck( + currentW == referenceW && currentH == referenceH, + "Verify that content of W and H pointers has not been modified; expected: %d,%d; got: %d,%d", + referenceW, referenceH, + currentW, currentH); + _checkInvalidWindowError(); + + SDL_GetWindowSize(NULL, NULL, NULL); + SDLTest_AssertPass("Call to SDL_GetWindowSize(NULL, NULL, NULL)"); + _checkInvalidWindowError(); + + SDL_SetWindowSize(NULL, desiredW, desiredH); + SDLTest_AssertPass("Call to SDL_SetWindowSize(window=NULL)"); + _checkInvalidWindowError(); + + return TEST_COMPLETED; +} + +/** + * @brief Tests call to SDL_GetWindowMinimumSize and SDL_SetWindowMinimumSize + * + */ +int +video_getSetWindowMinimumSize(void *arg) +{ + const char* title = "video_getSetWindowMinimumSize Test Window"; + SDL_Window* window; + int result; + SDL_Rect display; + int wVariation, hVariation; + int referenceW, referenceH; + int currentW, currentH; + int desiredW, desiredH; + + /* Get display bounds for size range */ + result = SDL_GetDisplayBounds(0, &display); + SDLTest_AssertPass("SDL_GetDisplayBounds()"); + SDLTest_AssertCheck(result == 0, "Verify return value; expected: 0, got: %d", result); + if (result != 0) return TEST_ABORTED; + + /* Call against new test window */ + window = _createVideoSuiteTestWindow(title); + if (window == NULL) return TEST_ABORTED; + + for (wVariation = 0; wVariation < 5; wVariation++) { + for (hVariation = 0; hVariation < 5; hVariation++) { + switch(wVariation) { + case 0: + /* 1 Pixel Wide */ + desiredW = 1; + break; + case 1: + /* Random width inside screen */ + desiredW = SDLTest_RandomIntegerInRange(2, display.w - 1); + break; + case 2: + /* Width at screen size */ + desiredW = display.w; + break; + } + + switch(hVariation) { + case 0: + /* 1 Pixel High */ + desiredH = 1; + break; + case 1: + /* Random height inside screen */ + desiredH = SDLTest_RandomIntegerInRange(2, display.h - 1); + break; + case 2: + /* Height at screen size */ + desiredH = display.h; + break; + case 4: + /* Height 1 pixel larger than screen */ + desiredH = display.h + 1; + break; + } + + /* Set size */ + SDL_SetWindowMinimumSize(window, desiredW, desiredH); + SDLTest_AssertPass("Call to SDL_SetWindowMinimumSize(...,%d,%d)", desiredW, desiredH); + + /* Get size */ + currentW = desiredW + 1; + currentH = desiredH + 1; + SDL_GetWindowMinimumSize(window, ¤tW, ¤tH); + SDLTest_AssertPass("Call to SDL_GetWindowMinimumSize()"); + SDLTest_AssertCheck(desiredW == currentW, "Verify returned width; expected: %d, got: %d", desiredW, currentW); + SDLTest_AssertCheck(desiredH == currentH, "Verify returned height; expected: %d, got: %d", desiredH, currentH); + + /* Get just width */ + currentW = desiredW + 1; + SDL_GetWindowMinimumSize(window, ¤tW, NULL); + SDLTest_AssertPass("Call to SDL_GetWindowMinimumSize(&h=NULL)"); + SDLTest_AssertCheck(desiredW == currentW, "Verify returned width; expected: %d, got: %d", desiredW, currentH); + + /* Get just height */ + currentH = desiredH + 1; + SDL_GetWindowMinimumSize(window, NULL, ¤tH); + SDLTest_AssertPass("Call to SDL_GetWindowMinimumSize(&w=NULL)"); + SDLTest_AssertCheck(desiredH == currentH, "Verify returned height; expected: %d, got: %d", desiredW, currentH); + } + } + + /* Dummy call with both pointers NULL */ + SDL_GetWindowMinimumSize(window, NULL, NULL); + SDLTest_AssertPass("Call to SDL_GetWindowMinimumSize(&w=NULL,&h=NULL)"); + + /* Negative tests for parameter input */ + SDL_ClearError(); + SDLTest_AssertPass("Call to SDL_ClearError()"); + for (desiredH = -2; desiredH < 2; desiredH++) { + for (desiredW = -2; desiredW < 2; desiredW++) { + if (desiredW <= 0 || desiredH <= 0) { + SDL_SetWindowMinimumSize(window, desiredW, desiredH); + SDLTest_AssertPass("Call to SDL_SetWindowMinimumSize(...,%d,%d)", desiredW, desiredH); + _checkInvalidParameterError(); + } + } + } + + /* Clean up */ + _destroyVideoSuiteTestWindow(window); + + /* Set some 'magic' value for later check that nothing was changed */ + referenceW = SDLTest_RandomSint32(); + referenceH = SDLTest_RandomSint32(); + currentW = referenceW; + currentH = referenceH; + desiredW = SDLTest_RandomSint32(); + desiredH = SDLTest_RandomSint32(); + + /* Negative tests for window input */ + SDL_ClearError(); + SDLTest_AssertPass("Call to SDL_ClearError()"); + SDL_GetWindowMinimumSize(NULL, ¤tW, ¤tH); + SDLTest_AssertPass("Call to SDL_GetWindowMinimumSize(window=NULL)"); + SDLTest_AssertCheck( + currentW == referenceW && currentH == referenceH, + "Verify that content of W and H pointers has not been modified; expected: %d,%d; got: %d,%d", + referenceW, referenceH, + currentW, currentH); + _checkInvalidWindowError(); + + SDL_GetWindowMinimumSize(NULL, NULL, NULL); + SDLTest_AssertPass("Call to SDL_GetWindowMinimumSize(NULL, NULL, NULL)"); + _checkInvalidWindowError(); + + SDL_SetWindowMinimumSize(NULL, desiredW, desiredH); + SDLTest_AssertPass("Call to SDL_SetWindowMinimumSize(window=NULL)"); + _checkInvalidWindowError(); + + return TEST_COMPLETED; +} + +/** + * @brief Tests call to SDL_GetWindowMaximumSize and SDL_SetWindowMaximumSize + * + */ +int +video_getSetWindowMaximumSize(void *arg) +{ + const char* title = "video_getSetWindowMaximumSize Test Window"; + SDL_Window* window; + int result; + SDL_Rect display; + int wVariation, hVariation; + int referenceW, referenceH; + int currentW, currentH; + int desiredW, desiredH; + + /* Get display bounds for size range */ + result = SDL_GetDisplayBounds(0, &display); + SDLTest_AssertPass("SDL_GetDisplayBounds()"); + SDLTest_AssertCheck(result == 0, "Verify return value; expected: 0, got: %d", result); + if (result != 0) return TEST_ABORTED; + + /* Call against new test window */ + window = _createVideoSuiteTestWindow(title); + if (window == NULL) return TEST_ABORTED; + + for (wVariation = 0; wVariation < 3; wVariation++) { + for (hVariation = 0; hVariation < 3; hVariation++) { + switch(wVariation) { + case 0: + /* 1 Pixel Wide */ + desiredW = 1; + break; + case 1: + /* Random width inside screen */ + desiredW = SDLTest_RandomIntegerInRange(2, display.w - 1); + break; + case 2: + /* Width at screen size */ + desiredW = display.w; + break; + } + + switch(hVariation) { + case 0: + /* 1 Pixel High */ + desiredH = 1; + break; + case 1: + /* Random height inside screen */ + desiredH = SDLTest_RandomIntegerInRange(2, display.h - 1); + break; + case 2: + /* Height at screen size */ + desiredH = display.h; + break; + } + + /* Set size */ + SDL_SetWindowMaximumSize(window, desiredW, desiredH); + SDLTest_AssertPass("Call to SDL_SetWindowMaximumSize(...,%d,%d)", desiredW, desiredH); + + /* Get size */ + currentW = desiredW + 1; + currentH = desiredH + 1; + SDL_GetWindowMaximumSize(window, ¤tW, ¤tH); + SDLTest_AssertPass("Call to SDL_GetWindowMaximumSize()"); + SDLTest_AssertCheck(desiredW == currentW, "Verify returned width; expected: %d, got: %d", desiredW, currentW); + SDLTest_AssertCheck(desiredH == currentH, "Verify returned height; expected: %d, got: %d", desiredH, currentH); + + /* Get just width */ + currentW = desiredW + 1; + SDL_GetWindowMaximumSize(window, ¤tW, NULL); + SDLTest_AssertPass("Call to SDL_GetWindowMaximumSize(&h=NULL)"); + SDLTest_AssertCheck(desiredW == currentW, "Verify returned width; expected: %d, got: %d", desiredW, currentH); + + /* Get just height */ + currentH = desiredH + 1; + SDL_GetWindowMaximumSize(window, NULL, ¤tH); + SDLTest_AssertPass("Call to SDL_GetWindowMaximumSize(&w=NULL)"); + SDLTest_AssertCheck(desiredH == currentH, "Verify returned height; expected: %d, got: %d", desiredW, currentH); + } + } + + /* Dummy call with both pointers NULL */ + SDL_GetWindowMaximumSize(window, NULL, NULL); + SDLTest_AssertPass("Call to SDL_GetWindowMaximumSize(&w=NULL,&h=NULL)"); + + /* Negative tests for parameter input */ + SDL_ClearError(); + SDLTest_AssertPass("Call to SDL_ClearError()"); + for (desiredH = -2; desiredH < 2; desiredH++) { + for (desiredW = -2; desiredW < 2; desiredW++) { + if (desiredW <= 0 || desiredH <= 0) { + SDL_SetWindowMaximumSize(window, desiredW, desiredH); + SDLTest_AssertPass("Call to SDL_SetWindowMaximumSize(...,%d,%d)", desiredW, desiredH); + _checkInvalidParameterError(); + } + } + } + + /* Clean up */ + _destroyVideoSuiteTestWindow(window); + + /* Set some 'magic' value for later check that nothing was changed */ + referenceW = SDLTest_RandomSint32(); + referenceH = SDLTest_RandomSint32(); + currentW = referenceW; + currentH = referenceH; + desiredW = SDLTest_RandomSint32(); + desiredH = SDLTest_RandomSint32(); + + /* Negative tests */ + SDL_ClearError(); + SDLTest_AssertPass("Call to SDL_ClearError()"); + SDL_GetWindowMaximumSize(NULL, ¤tW, ¤tH); + SDLTest_AssertPass("Call to SDL_GetWindowMaximumSize(window=NULL)"); + SDLTest_AssertCheck( + currentW == referenceW && currentH == referenceH, + "Verify that content of W and H pointers has not been modified; expected: %d,%d; got: %d,%d", + referenceW, referenceH, + currentW, currentH); + _checkInvalidWindowError(); + + SDL_GetWindowMaximumSize(NULL, NULL, NULL); + SDLTest_AssertPass("Call to SDL_GetWindowMaximumSize(NULL, NULL, NULL)"); + _checkInvalidWindowError(); + + SDL_SetWindowMaximumSize(NULL, desiredW, desiredH); + SDLTest_AssertPass("Call to SDL_SetWindowMaximumSize(window=NULL)"); + _checkInvalidWindowError(); + + return TEST_COMPLETED; +} + + +/** + * @brief Tests call to SDL_SetWindowData and SDL_GetWindowData + * + * @sa http://wiki.libsdl.org/moin.fcg/SDL_SetWindowData + * @sa http://wiki.libsdl.org/moin.fcg/SDL_GetWindowData + */ +int +video_getSetWindowData(void *arg) +{ + int returnValue = TEST_COMPLETED; + const char* title = "video_setGetWindowData Test Window"; + SDL_Window* window; + const char *referenceName = "TestName"; + const char *name = "TestName"; + const char *referenceName2 = "TestName2"; + const char *name2 = "TestName2"; + int datasize; + char *referenceUserdata; + char *userdata; + char *referenceUserdata2; + char *userdata2; + char *result; + int iteration; + + /* Call against new test window */ + window = _createVideoSuiteTestWindow(title); + if (window == NULL) return TEST_ABORTED; + + /* Create testdata */ + datasize = SDLTest_RandomIntegerInRange(1, 32); + referenceUserdata = SDLTest_RandomAsciiStringOfSize(datasize); + if (referenceUserdata == NULL) { + returnValue = TEST_ABORTED; + goto cleanup; + } + userdata = (char *)strdup(referenceUserdata); + if (userdata == NULL) { + returnValue = TEST_ABORTED; + goto cleanup; + } + datasize = SDLTest_RandomIntegerInRange(1, 32); + referenceUserdata2 = SDLTest_RandomAsciiStringOfSize(datasize); + if (referenceUserdata2 == NULL) { + returnValue = TEST_ABORTED; + goto cleanup; + } + userdata2 = (char *)strdup(referenceUserdata2); + if (userdata2 == NULL) { + returnValue = TEST_ABORTED; + goto cleanup; + } + + /* Get non-existent data */ + result = (char *)SDL_GetWindowData(window, name); + SDLTest_AssertPass("Call to SDL_GetWindowData(..,%s)", name); + SDLTest_AssertCheck(result == NULL, "Validate that result is NULL"); + SDLTest_AssertCheck(SDL_strcmp(referenceName, name) == 0, "Validate that name was not changed, expected: %s, got: %s", referenceName, name); + + /* Set data */ + result = SDL_SetWindowData(window, name, userdata); + SDLTest_AssertPass("Call to SDL_SetWindowData(...%s,%s)", name, userdata); + SDLTest_AssertCheck(result == NULL, "Validate that result is NULL"); + SDLTest_AssertCheck(SDL_strcmp(referenceName, name) == 0, "Validate that name was not changed, expected: %s, got: %s", referenceName, name); + SDLTest_AssertCheck(SDL_strcmp(referenceUserdata, userdata) == 0, "Validate that userdata was not changed, expected: %s, got: %s", referenceUserdata, userdata); + + /* Get data (twice) */ + for (iteration = 1; iteration <= 2; iteration++) { + result = (char *)SDL_GetWindowData(window, name); + SDLTest_AssertPass("Call to SDL_GetWindowData(..,%s) [iteration %d]", name, iteration); + SDLTest_AssertCheck(SDL_strcmp(referenceUserdata, result) == 0, "Validate that correct result was returned; expected: %s, got: %s", referenceUserdata, result); + SDLTest_AssertCheck(SDL_strcmp(referenceName, name) == 0, "Validate that name was not changed, expected: %s, got: %s", referenceName, name); + } + + /* Set data again twice */ + for (iteration = 1; iteration <= 2; iteration++) { + result = SDL_SetWindowData(window, name, userdata); + SDLTest_AssertPass("Call to SDL_SetWindowData(...%s,%s) [iteration %d]", name, userdata, iteration); + SDLTest_AssertCheck(SDL_strcmp(referenceUserdata, result) == 0, "Validate that correct result was returned; expected: %s, got: %s", referenceUserdata, result); + SDLTest_AssertCheck(SDL_strcmp(referenceName, name) == 0, "Validate that name was not changed, expected: %s, got: %s", referenceName, name); + SDLTest_AssertCheck(SDL_strcmp(referenceUserdata, userdata) == 0, "Validate that userdata was not changed, expected: %s, got: %s", referenceUserdata, userdata); + } + + /* Get data again */ + result = (char *)SDL_GetWindowData(window, name); + SDLTest_AssertPass("Call to SDL_GetWindowData(..,%s) [again]", name); + SDLTest_AssertCheck(SDL_strcmp(referenceUserdata, result) == 0, "Validate that correct result was returned; expected: %s, got: %s", referenceUserdata, result); + SDLTest_AssertCheck(SDL_strcmp(referenceName, name) == 0, "Validate that name was not changed, expected: %s, got: %s", referenceName, name); + + /* Set data with new data */ + result = SDL_SetWindowData(window, name, userdata2); + SDLTest_AssertPass("Call to SDL_SetWindowData(...%s,%s) [new userdata]", name, userdata2); + SDLTest_AssertCheck(SDL_strcmp(referenceUserdata, result) == 0, "Validate that correct result was returned; expected: %s, got: %s", referenceUserdata, result); + SDLTest_AssertCheck(SDL_strcmp(referenceName, name) == 0, "Validate that name was not changed, expected: %s, got: %s", referenceName, name); + SDLTest_AssertCheck(SDL_strcmp(referenceUserdata, userdata) == 0, "Validate that userdata was not changed, expected: %s, got: %s", referenceUserdata, userdata); + SDLTest_AssertCheck(SDL_strcmp(referenceUserdata2, userdata2) == 0, "Validate that userdata2 was not changed, expected: %s, got: %s", referenceUserdata2, userdata2); + + /* Set data with new data again */ + result = SDL_SetWindowData(window, name, userdata2); + SDLTest_AssertPass("Call to SDL_SetWindowData(...%s,%s) [new userdata again]", name, userdata2); + SDLTest_AssertCheck(SDL_strcmp(referenceUserdata2, result) == 0, "Validate that correct result was returned; expected: %s, got: %s", referenceUserdata2, result); + SDLTest_AssertCheck(SDL_strcmp(referenceName, name) == 0, "Validate that name was not changed, expected: %s, got: %s", referenceName, name); + SDLTest_AssertCheck(SDL_strcmp(referenceUserdata, userdata) == 0, "Validate that userdata was not changed, expected: %s, got: %s", referenceUserdata, userdata); + SDLTest_AssertCheck(SDL_strcmp(referenceUserdata2, userdata2) == 0, "Validate that userdata2 was not changed, expected: %s, got: %s", referenceUserdata2, userdata2); + + /* Get new data */ + result = (char *)SDL_GetWindowData(window, name); + SDLTest_AssertPass("Call to SDL_GetWindowData(..,%s)", name); + SDLTest_AssertCheck(SDL_strcmp(referenceUserdata2, result) == 0, "Validate that correct result was returned; expected: %s, got: %s", referenceUserdata2, result); + SDLTest_AssertCheck(SDL_strcmp(referenceName, name) == 0, "Validate that name was not changed, expected: %s, got: %s", referenceName, name); + + /* Set data with NULL to clear */ + result = SDL_SetWindowData(window, name, NULL); + SDLTest_AssertPass("Call to SDL_SetWindowData(...%s,NULL)", name, userdata); + SDLTest_AssertCheck(SDL_strcmp(referenceUserdata2, result) == 0, "Validate that correct result was returned; expected: %s, got: %s", referenceUserdata2, result); + SDLTest_AssertCheck(SDL_strcmp(referenceName, name) == 0, "Validate that name was not changed, expected: %s, got: %s", referenceName, name); + SDLTest_AssertCheck(SDL_strcmp(referenceUserdata, userdata) == 0, "Validate that userdata was not changed, expected: %s, got: %s", referenceUserdata, userdata); + SDLTest_AssertCheck(SDL_strcmp(referenceUserdata2, userdata2) == 0, "Validate that userdata2 was not changed, expected: %s, got: %s", referenceUserdata2, userdata2); + + /* Set data with NULL to clear again */ + result = SDL_SetWindowData(window, name, NULL); + SDLTest_AssertPass("Call to SDL_SetWindowData(...%s,NULL) [again]", name, userdata); + SDLTest_AssertCheck(result == NULL, "Validate that result is NULL"); + SDLTest_AssertCheck(SDL_strcmp(referenceName, name) == 0, "Validate that name was not changed, expected: %s, got: %s", referenceName, name); + SDLTest_AssertCheck(SDL_strcmp(referenceUserdata, userdata) == 0, "Validate that userdata was not changed, expected: %s, got: %s", referenceUserdata, userdata); + SDLTest_AssertCheck(SDL_strcmp(referenceUserdata2, userdata2) == 0, "Validate that userdata2 was not changed, expected: %s, got: %s", referenceUserdata2, userdata2); + + /* Get non-existent data */ + result = (char *)SDL_GetWindowData(window, name); + SDLTest_AssertPass("Call to SDL_GetWindowData(..,%s)", name); + SDLTest_AssertCheck(result == NULL, "Validate that result is NULL"); + SDLTest_AssertCheck(SDL_strcmp(referenceName, name) == 0, "Validate that name was not changed, expected: %s, got: %s", referenceName, name); + + /* Get non-existent data new name */ + result = (char *)SDL_GetWindowData(window, name2); + SDLTest_AssertPass("Call to SDL_GetWindowData(..,%s)", name2); + SDLTest_AssertCheck(result == NULL, "Validate that result is NULL"); + SDLTest_AssertCheck(SDL_strcmp(referenceName2, name2) == 0, "Validate that name2 was not changed, expected: %s, got: %s", referenceName2, name2); + + /* Set data (again) */ + result = SDL_SetWindowData(window, name, userdata); + SDLTest_AssertPass("Call to SDL_SetWindowData(...%s,%s) [again, after clear]", name, userdata); + SDLTest_AssertCheck(result == NULL, "Validate that result is NULL"); + SDLTest_AssertCheck(SDL_strcmp(referenceName, name) == 0, "Validate that name was not changed, expected: %s, got: %s", referenceName, name); + SDLTest_AssertCheck(SDL_strcmp(referenceUserdata, userdata) == 0, "Validate that userdata was not changed, expected: %s, got: %s", referenceUserdata, userdata); + + /* Get data (again) */ + result = (char *)SDL_GetWindowData(window, name); + SDLTest_AssertPass("Call to SDL_GetWindowData(..,%s) [again, after clear]", name); + SDLTest_AssertCheck(SDL_strcmp(referenceUserdata, result) == 0, "Validate that correct result was returned; expected: %s, got: %s", referenceUserdata, result); + SDLTest_AssertCheck(SDL_strcmp(referenceName, name) == 0, "Validate that name was not changed, expected: %s, got: %s", referenceName, name); + + /* Negative test */ + SDL_ClearError(); + SDLTest_AssertPass("Call to SDL_ClearError()"); + + /* Set with invalid window */ + result = SDL_SetWindowData(NULL, name, userdata); + SDLTest_AssertPass("Call to SDL_SetWindowData(window=NULL)"); + SDLTest_AssertCheck(result == NULL, "Validate that result is NULL"); + _checkInvalidWindowError(); + + /* Set data with NULL name, valid userdata */ + result = SDL_SetWindowData(window, NULL, userdata); + SDLTest_AssertPass("Call to SDL_SetWindowData(name=NULL)"); + SDLTest_AssertCheck(result == NULL, "Validate that result is NULL"); + _checkInvalidParameterError(); + + /* Set data with empty name, valid userdata */ + result = SDL_SetWindowData(window, "", userdata); + SDLTest_AssertPass("Call to SDL_SetWindowData(name='')"); + SDLTest_AssertCheck(result == NULL, "Validate that result is NULL"); + _checkInvalidParameterError(); + + /* Set data with NULL name, NULL userdata */ + result = SDL_SetWindowData(window, NULL, NULL); + SDLTest_AssertPass("Call to SDL_SetWindowData(name=NULL,userdata=NULL)"); + SDLTest_AssertCheck(result == NULL, "Validate that result is NULL"); + _checkInvalidParameterError(); + + /* Set data with empty name, NULL userdata */ + result = SDL_SetWindowData(window, "", NULL); + SDLTest_AssertPass("Call to SDL_SetWindowData(name='',userdata=NULL)"); + SDLTest_AssertCheck(result == NULL, "Validate that result is NULL"); + _checkInvalidParameterError(); + + /* Get with invalid window */ + result = SDL_GetWindowData(NULL, name); + SDLTest_AssertPass("Call to SDL_GetWindowData(window=NULL)"); + SDLTest_AssertCheck(result == NULL, "Validate that result is NULL"); + _checkInvalidWindowError(); + + /* Get data with NULL name */ + result = SDL_GetWindowData(window, NULL); + SDLTest_AssertPass("Call to SDL_GetWindowData(name=NULL)"); + SDLTest_AssertCheck(result == NULL, "Validate that result is NULL"); + _checkInvalidParameterError(); + + /* Get data with empty name */ + result = SDL_GetWindowData(window, ""); + SDLTest_AssertPass("Call to SDL_GetWindowData(name='')"); + SDLTest_AssertCheck(result == NULL, "Validate that result is NULL"); + _checkInvalidParameterError(); + + /* Clean up */ + _destroyVideoSuiteTestWindow(window); + + cleanup: + if (referenceUserdata != NULL) SDL_free(referenceUserdata); + if (referenceUserdata2 != NULL) SDL_free(referenceUserdata2); + if (userdata != NULL) SDL_free(userdata); + if (userdata != NULL) SDL_free(userdata); + + return returnValue; +} + + /* ================= Test References ================== */ /* Video test cases */ @@ -329,11 +1719,69 @@ static const SDLTest_TestCaseReference videoTest4 = { (SDLTest_TestCaseFp)video_createWindowVariousFlags, "video_createWindowVariousFlags", "Create windows using various flags", TEST_ENABLED }; static const SDLTest_TestCaseReference videoTest5 = - { (SDLTest_TestCaseFp)video_getWindowFlags, "video_getWindowFlags", "Set and get window flags", TEST_ENABLED }; + { (SDLTest_TestCaseFp)video_getWindowFlags, "video_getWindowFlags", "Get window flags set during SDL_CreateWindow", TEST_ENABLED }; + +static const SDLTest_TestCaseReference videoTest6 = + { (SDLTest_TestCaseFp)video_getNumDisplayModes, "video_getNumDisplayModes", "Use SDL_GetNumDisplayModes function to get number of display modes", TEST_ENABLED }; + +static const SDLTest_TestCaseReference videoTest7 = + { (SDLTest_TestCaseFp)video_getNumDisplayModesNegative, "video_getNumDisplayModesNegative", "Negative tests for SDL_GetNumDisplayModes", TEST_ENABLED }; + +static const SDLTest_TestCaseReference videoTest8 = + { (SDLTest_TestCaseFp)video_getClosestDisplayModeCurrentResolution, "video_getClosestDisplayModeCurrentResolution", "Use function to get closes match to requested display mode for current resolution", TEST_ENABLED }; + +static const SDLTest_TestCaseReference videoTest9 = + { (SDLTest_TestCaseFp)video_getClosestDisplayModeRandomResolution, "video_getClosestDisplayModeRandomResolution", "Use function to get closes match to requested display mode for random resolution", TEST_ENABLED }; + +static const SDLTest_TestCaseReference videoTest10 = + { (SDLTest_TestCaseFp)video_getWindowBrightness, "video_getWindowBrightness", "Get window brightness", TEST_ENABLED }; + +static const SDLTest_TestCaseReference videoTest11 = + { (SDLTest_TestCaseFp)video_getWindowBrightnessNegative, "video_getWindowBrightnessNegative", "Get window brightness with invalid input", TEST_ENABLED }; + +static const SDLTest_TestCaseReference videoTest12 = + { (SDLTest_TestCaseFp)video_getWindowDisplayMode, "video_getWindowDisplayMode", "Get window display mode", TEST_ENABLED }; + +static const SDLTest_TestCaseReference videoTest13 = + { (SDLTest_TestCaseFp)video_getWindowDisplayModeNegative, "video_getWindowDisplayModeNegative", "Get window display mode with invalid input", TEST_ENABLED }; + +static const SDLTest_TestCaseReference videoTest14 = + { (SDLTest_TestCaseFp)video_getWindowGammaRamp, "video_getWindowGammaRamp", "Get window gamma ramp", TEST_ENABLED }; + +static const SDLTest_TestCaseReference videoTest15 = + { (SDLTest_TestCaseFp)video_getWindowGammaRampNegative, "video_getWindowGammaRampNegative", "Get window gamma ramp against invalid input", TEST_ENABLED }; + +static const SDLTest_TestCaseReference videoTest16 = + { (SDLTest_TestCaseFp)video_getSetWindowGrab, "video_getSetWindowGrab", "Checks SDL_GetWindowGrab and SDL_SetWindowGrab positive and negative cases", TEST_ENABLED }; + +static const SDLTest_TestCaseReference videoTest17 = + { (SDLTest_TestCaseFp)video_getWindowId, "video_getWindowId", "Checks SDL_GetWindowID and SDL_GetWindowFromID", TEST_ENABLED }; + +static const SDLTest_TestCaseReference videoTest18 = + { (SDLTest_TestCaseFp)video_getWindowPixelFormat, "video_getWindowPixelFormat", "Checks SDL_GetWindowPixelFormat", TEST_ENABLED }; + +static const SDLTest_TestCaseReference videoTest19 = + { (SDLTest_TestCaseFp)video_getSetWindowPosition, "video_getSetWindowPosition", "Checks SDL_GetWindowPosition and SDL_SetWindowPosition positive and negative cases", TEST_ENABLED }; + +static const SDLTest_TestCaseReference videoTest20 = + { (SDLTest_TestCaseFp)video_getSetWindowSize, "video_getSetWindowSize", "Checks SDL_GetWindowSize and SDL_SetWindowSize positive and negative cases", TEST_ENABLED }; + +static const SDLTest_TestCaseReference videoTest21 = + { (SDLTest_TestCaseFp)video_getSetWindowMinimumSize, "video_getSetWindowMinimumSize", "Checks SDL_GetWindowMinimumSize and SDL_SetWindowMinimumSize positive and negative cases", TEST_ENABLED }; + +static const SDLTest_TestCaseReference videoTest22 = + { (SDLTest_TestCaseFp)video_getSetWindowMaximumSize, "video_getSetWindowMaximumSize", "Checks SDL_GetWindowMaximumSize and SDL_SetWindowMaximumSize positive and negative cases", TEST_ENABLED }; + +static const SDLTest_TestCaseReference videoTest23 = + { (SDLTest_TestCaseFp)video_getSetWindowData, "video_getSetWindowData", "Checks SDL_SetWindowData and SDL_GetWindowData positive and negative cases", TEST_ENABLED }; /* Sequence of Video test cases */ static const SDLTest_TestCaseReference *videoTests[] = { - &videoTest1, &videoTest2, &videoTest3, &videoTest4, &videoTest5, NULL + &videoTest1, &videoTest2, &videoTest3, &videoTest4, &videoTest5, &videoTest6, + &videoTest7, &videoTest8, &videoTest9, &videoTest10, &videoTest11, &videoTest12, + &videoTest13, &videoTest14, &videoTest15, &videoTest16, &videoTest17, + &videoTest18, &videoTest19, &videoTest20, &videoTest21, &videoTest22, + &videoTest23, NULL }; /* Video test suite (global) */ diff --git a/test/testgamecontroller.c b/test/testgamecontroller.c index 7c1d9bcc25..2e9d98ad59 100644 --- a/test/testgamecontroller.c +++ b/test/testgamecontroller.c @@ -21,11 +21,11 @@ #ifndef SDL_JOYSTICK_DISABLED #ifdef __IPHONEOS__ -#define SCREEN_WIDTH 320 -#define SCREEN_HEIGHT 480 +#define SCREEN_WIDTH 320 +#define SCREEN_HEIGHT 480 #else -#define SCREEN_WIDTH 640 -#define SCREEN_HEIGHT 480 +#define SCREEN_WIDTH 640 +#define SCREEN_HEIGHT 480 #endif #define MAX_NUM_AXES 6 @@ -40,18 +40,70 @@ DrawRect(SDL_Renderer *r, const int x, const int y, const int w, const int h) SDL_RenderFillRect(r, &area); } +static const char * +ControllerAxisName(const SDL_GameControllerAxis axis) +{ + switch (axis) + { + #define AXIS_CASE(ax) case SDL_CONTROLLER_AXIS_##ax: return #ax + AXIS_CASE(INVALID); + AXIS_CASE(LEFTX); + AXIS_CASE(LEFTY); + AXIS_CASE(RIGHTX); + AXIS_CASE(RIGHTY); + AXIS_CASE(TRIGGERLEFT); + AXIS_CASE(TRIGGERRIGHT); + #undef AXIS_CASE + default: return "???"; + } +} + +static const char * +ControllerButtonName(const SDL_GameControllerButton button) +{ + switch (button) + { + #define BUTTON_CASE(btn) case SDL_CONTROLLER_BUTTON_##btn: return #btn + BUTTON_CASE(INVALID); + BUTTON_CASE(A); + BUTTON_CASE(B); + BUTTON_CASE(X); + BUTTON_CASE(Y); + BUTTON_CASE(BACK); + BUTTON_CASE(GUIDE); + BUTTON_CASE(START); + BUTTON_CASE(LEFTSTICK); + BUTTON_CASE(RIGHTSTICK); + BUTTON_CASE(LEFTSHOULDER); + BUTTON_CASE(RIGHTSHOULDER); + BUTTON_CASE(DPAD_UP); + BUTTON_CASE(DPAD_DOWN); + BUTTON_CASE(DPAD_LEFT); + BUTTON_CASE(DPAD_RIGHT); + #undef BUTTON_CASE + default: return "???"; + } +} + void WatchGameController(SDL_GameController * gamecontroller) { + const char *name = SDL_GameControllerName(gamecontroller); + const char *basetitle = "Game Controller Test: "; + const size_t titlelen = SDL_strlen(basetitle) + SDL_strlen(name) + 1; + char *title = SDL_malloc(titlelen); SDL_Window *window = NULL; SDL_Renderer *screen = NULL; - const char *name = NULL; int done = 0; SDL_Event event; int i; + if (title) { + SDL_snprintf(title, titlelen, "%s%s", basetitle, name); + } + /* Create a window to display controller axis position */ - window = SDL_CreateWindow("Game Controller Test", SDL_WINDOWPOS_CENTERED, + window = SDL_CreateWindow(title, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, SCREEN_WIDTH, SCREEN_HEIGHT, SDL_WINDOW_SHOWN); if (window == NULL) { @@ -69,10 +121,9 @@ WatchGameController(SDL_GameController * gamecontroller) SDL_SetRenderDrawColor(screen, 0x00, 0x00, 0x00, SDL_ALPHA_OPAQUE); SDL_RenderClear(screen); SDL_RenderPresent(screen); - SDL_RaiseWindow(window); + SDL_RaiseWindow(window); /* Print info about the controller we are watching */ - name = SDL_GameControllerName(gamecontroller); printf("Watching controller %s\n", name ? name : "Unknown Controller"); /* Loop, getting controller events! */ @@ -84,17 +135,21 @@ WatchGameController(SDL_GameController * gamecontroller) while (SDL_PollEvent(&event)) { switch (event.type) { case SDL_CONTROLLERAXISMOTION: - printf("Controller %d axis %d value: %d\n", + printf("Controller %d axis %d ('%s') value: %d\n", event.caxis.which, - event.caxis.axis, event.caxis.value); + event.caxis.axis, + ControllerAxisName(event.caxis.axis), + event.caxis.value); break; case SDL_CONTROLLERBUTTONDOWN: - printf("Controller %d button %d down\n", - event.cbutton.which, event.cbutton.button); + printf("Controller %d button %d ('%s') down\n", + event.cbutton.which, event.cbutton.button, + ControllerButtonName(event.cbutton.button)); break; case SDL_CONTROLLERBUTTONUP: - printf("Controller %d button %d up\n", - event.cbutton.which, event.cbutton.button); + printf("Controller %d button %d ('%s') up\n", + event.cbutton.which, event.cbutton.button, + ControllerButtonName(event.cbutton.button)); break; case SDL_KEYDOWN: if (event.key.keysym.sym != SDLK_ESCAPE) { @@ -103,7 +158,7 @@ WatchGameController(SDL_GameController * gamecontroller) /* Fall through to signal quit */ case SDL_QUIT: done = 1; - s_ForceQuit = SDL_TRUE; + s_ForceQuit = SDL_TRUE; break; default: break; @@ -144,9 +199,9 @@ WatchGameController(SDL_GameController * gamecontroller) SDL_SetRenderDrawColor(screen, 0x00, 0x00, 0xFF, SDL_ALPHA_OPAQUE); SDL_RenderPresent(screen); - - if ( !done ) - done = SDL_GameControllerGetAttached( gamecontroller ) == 0; + + if ( !done ) + done = SDL_GameControllerGetAttached( gamecontroller ) == 0; } SDL_DestroyRenderer(screen); @@ -156,54 +211,60 @@ WatchGameController(SDL_GameController * gamecontroller) int main(int argc, char *argv[]) { - const char *name; int i; - int nController = 0; + int nController = 0; + int retcode = 0; + char guid[64]; SDL_GameController *gamecontroller; - SDL_SetHint( SDL_HINT_GAMECONTROLLERCONFIG, "341a3608000000000000504944564944,Aferglow PS3 Controller,a:b1,b:b2,y:b3,x:b0,start:b9,guide:b12,back:b8,dpup:h0.1,dpleft:h0.8,dpdown:h0.4,dpright:h0.2,leftshoulder:b4,rightshoulder:b5,leftstick:b10,rightstick:b11,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:b6,righttrigger:b7" ); /* Initialize SDL (Note: video is required to start event loop) */ if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_JOYSTICK | SDL_INIT_GAMECONTROLLER ) < 0) { fprintf(stderr, "Couldn't initialize SDL: %s\n", SDL_GetError()); - exit(1); + return 1; } /* Print information about the controller */ for (i = 0; i < SDL_NumJoysticks(); ++i) { - if ( SDL_IsGameController(i) ) - { - nController++; - name = SDL_GameControllerNameForIndex(i); - printf("Game Controller %d: %s\n", i, name ? name : "Unknown Controller"); - } + const char *name; + const char *description = "Joystick (not recognized as game controller)"; + + SDL_JoystickGetGUIDString(SDL_JoystickGetDeviceGUID(i), + guid, sizeof (guid)); + + if ( SDL_IsGameController(i) ) + { + nController++; + name = SDL_GameControllerNameForIndex(i); + } else { + name = SDL_JoystickNameForIndex(i); + } + printf("%s %d: %s (guid %s)\n", description, i, name ? name : "Unknown", guid); } - printf("There are %d game controllers attached\n", nController); + printf("There are %d game controller(s) attached (%d joystick(s))\n", nController, SDL_NumJoysticks()); if (argv[1]) { - int nreportederror = 0; - SDL_Event event; - gamecontroller = SDL_GameControllerOpen(atoi(argv[1])); - while ( s_ForceQuit == SDL_FALSE ) { - if (gamecontroller == NULL) { - if ( nreportederror == 0 ) { - printf("Couldn't open joystick %d: %s\n", atoi(argv[1]), SDL_GetError()); - nreportederror = 1; - } - } else { - nreportederror = 0; - WatchGameController(gamecontroller); - SDL_GameControllerClose(gamecontroller); - } - - gamecontroller = NULL; - SDL_WaitEvent( &event ); - if ( event.type == SDL_JOYDEVICEADDED ) - gamecontroller = SDL_GameControllerOpen(atoi(argv[1])); - } - } - SDL_QuitSubSystem(SDL_INIT_VIDEO | SDL_INIT_JOYSTICK | SDL_INIT_GAMECONTROLLER ); - - return (0); + int device = atoi(argv[1]); + if (device >= SDL_NumJoysticks()) { + printf("%i is an invalid joystick index.\n", device); + retcode = 1; + } else { + SDL_JoystickGetGUIDString(SDL_JoystickGetDeviceGUID(device), + guid, sizeof (guid)); + printf("Attempting to open device %i, guid %s\n", device, guid); + gamecontroller = SDL_GameControllerOpen(device); + if (gamecontroller == NULL) { + printf("Couldn't open joystick %d: %s\n", device, SDL_GetError()); + retcode = 1; + } else { + WatchGameController(gamecontroller); + SDL_GameControllerClose(gamecontroller); + } + } + } + + SDL_QuitSubSystem(SDL_INIT_VIDEO | SDL_INIT_JOYSTICK | SDL_INIT_GAMECONTROLLER); + + return retcode; } #else diff --git a/test/testgesture.c b/test/testgesture.c index 04c0e176b0..53e7e8a554 100644 --- a/test/testgesture.c +++ b/test/testgesture.c @@ -167,11 +167,8 @@ void DrawScreen(SDL_Surface* screen) if(event->type == SDL_FINGERMOTION || event->type == SDL_FINGERDOWN || event->type == SDL_FINGERUP) { - SDL_Touch* inTouch = SDL_GetTouch(event->tfinger.touchId); - if(inTouch == NULL) continue; - - x = ((float)event->tfinger.x)/inTouch->xres; - y = ((float)event->tfinger.y)/inTouch->yres; + x = event->tfinger.x; + y = event->tfinger.y; //draw the touch: c = colors[event->tfinger.fingerId%7]; @@ -269,10 +266,6 @@ int main(int argc, char* argv[]) SDL_Log("Finger: %i,x: %i, y: %i",event.tfinger.fingerId, event.tfinger.x,event.tfinger.y); #endif - { - SDL_Touch* inTouch = SDL_GetTouch(event.tfinger.touchId); - SDL_Finger* inFinger = SDL_GetFinger(inTouch,event.tfinger.fingerId); - } break; case SDL_FINGERDOWN: #if VERBOSE diff --git a/test/testjoystick.c b/test/testjoystick.c index af990ad9aa..df94631f13 100644 --- a/test/testjoystick.c +++ b/test/testjoystick.c @@ -28,9 +28,6 @@ #define SCREEN_HEIGHT 480 #endif -#define MAX_NUM_AXES 6 -#define MAX_NUM_HATS 2 - static void DrawRect(SDL_Renderer *r, const int x, const int y, const int w, const int h) @@ -121,10 +118,13 @@ WatchJoystick(SDL_Joystick * joystick) event.jbutton.which, event.jbutton.button); break; case SDL_KEYDOWN: - if (event.key.keysym.sym != SDLK_ESCAPE) { + if ((event.key.keysym.sym != SDLK_ESCAPE) && + (event.key.keysym.sym != SDLK_AC_BACK)) { break; } /* Fall through to signal quit */ + case SDL_FINGERDOWN: + case SDL_MOUSEBUTTONDOWN: case SDL_QUIT: done = SDL_TRUE; break; @@ -136,15 +136,15 @@ WatchJoystick(SDL_Joystick * joystick) SDL_SetRenderDrawColor(screen, 0x00, 0xFF, 0x00, SDL_ALPHA_OPAQUE); for (i = 0; i < SDL_JoystickNumButtons(joystick); ++i) { if (SDL_JoystickGetButton(joystick, i) == SDL_PRESSED) { - DrawRect(screen, i * 34, SCREEN_HEIGHT - 34, 32, 32); + DrawRect(screen, (i%20) * 34, SCREEN_HEIGHT - 68 + (i/20) * 34, 32, 32); } } SDL_SetRenderDrawColor(screen, 0xFF, 0x00, 0x00, SDL_ALPHA_OPAQUE); - for (i = 0; i < SDL_JoystickNumAxes(joystick) / 2; ++i) { + for (i = 0; i < SDL_JoystickNumAxes(joystick); ++i) { /* Draw the X/Y axis */ int x, y; - x = (((int) SDL_JoystickGetAxis(joystick, i * 2 + 0)) + 32768); + x = (((int) SDL_JoystickGetAxis(joystick, i)) + 32768); x *= SCREEN_WIDTH; x /= 65535; if (x < 0) { @@ -152,7 +152,12 @@ WatchJoystick(SDL_Joystick * joystick) } else if (x > (SCREEN_WIDTH - 16)) { x = SCREEN_WIDTH - 16; } - y = (((int) SDL_JoystickGetAxis(joystick, i * 2 + 1)) + 32768); + ++i; + if (i < SDL_JoystickNumAxes(joystick)) { + y = (((int) SDL_JoystickGetAxis(joystick, i)) + 32768); + } else { + y = 32768; + } y *= SCREEN_HEIGHT; y /= 65535; if (y < 0) { @@ -235,11 +240,19 @@ main(int argc, char *argv[]) } } +#ifdef ANDROID + if (SDL_NumJoysticks() > 0) { +#else if (argv[1]) { +#endif SDL_bool reportederror = SDL_FALSE; SDL_bool keepGoing = SDL_TRUE; SDL_Event event; +#ifdef ANDROID + joystick = SDL_JoystickOpen(0); +#else joystick = SDL_JoystickOpen(atoi(argv[1])); +#endif while ( keepGoing ) { if (joystick == NULL) { if ( !reportederror ) { @@ -259,7 +272,8 @@ main(int argc, char *argv[]) } while (keepGoing) { SDL_WaitEvent(&event); - if (event.type == SDL_QUIT) { + 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(atoi(argv[1])); @@ -270,7 +284,11 @@ main(int argc, char *argv[]) } SDL_QuitSubSystem(SDL_INIT_VIDEO | SDL_INIT_JOYSTICK); +#ifdef ANDROID + exit(0); +#else return 0; +#endif } #else diff --git a/test/testlock.c b/test/testlock.c index 362d687cf3..04abf3d7f3 100644 --- a/test/testlock.c +++ b/test/testlock.c @@ -69,14 +69,14 @@ Run(void *data) signal(SIGTERM, closemutex); while (!doterminate) { printf("Process %lu ready to work\n", SDL_ThreadID()); - if (SDL_mutexP(mutex) < 0) { + if (SDL_LockMutex(mutex) < 0) { fprintf(stderr, "Couldn't lock mutex: %s", SDL_GetError()); exit(1); } printf("Process %lu, working!\n", SDL_ThreadID()); SDL_Delay(1 * 1000); printf("Process %lu, done!\n", SDL_ThreadID()); - if (SDL_mutexV(mutex) < 0) { + if (SDL_UnlockMutex(mutex) < 0) { fprintf(stderr, "Couldn't unlock mutex: %s", SDL_GetError()); exit(1); } diff --git a/test/testrendercopyex.c b/test/testrendercopyex.c index 3d9ee9f476..dca3ee1720 100644 --- a/test/testrendercopyex.c +++ b/test/testrendercopyex.c @@ -17,8 +17,6 @@ #include "SDL_test_common.h" -#define WINDOW_WIDTH 640 -#define WINDOW_HEIGHT 480 static SDLTest_CommonState *state; diff --git a/test/testrendertarget.c b/test/testrendertarget.c index c43d14ff9f..b7fd11c88c 100644 --- a/test/testrendertarget.c +++ b/test/testrendertarget.c @@ -17,8 +17,6 @@ #include "SDL_test_common.h" -#define WINDOW_WIDTH 640 -#define WINDOW_HEIGHT 480 static SDLTest_CommonState *state; diff --git a/test/testspriteminimal.c b/test/testspriteminimal.c index 48e996c016..76244c282b 100644 --- a/test/testspriteminimal.c +++ b/test/testspriteminimal.c @@ -17,13 +17,8 @@ #include "SDL.h" -#ifdef __NDS__ -#define WINDOW_WIDTH 256 -#define WINDOW_HEIGHT (2*192) -#else #define WINDOW_WIDTH 640 #define WINDOW_HEIGHT 480 -#endif #define NUM_SPRITES 100 #define MAX_SPEED 1 diff --git a/test/testwm2.c b/test/testwm2.c index 8f18974038..bdc484ec38 100644 --- a/test/testwm2.c +++ b/test/testwm2.c @@ -42,13 +42,14 @@ main(int argc, char *argv[]) "NO", "hand", }; - SDL_assert(SDL_arraysize(cursorNames) == SDL_NUM_SYSTEM_CURSORS); int i, done; SDL_Event event; int system_cursor = -1; SDL_Cursor *cursor = NULL; + SDL_assert(SDL_arraysize(cursorNames) == SDL_NUM_SYSTEM_CURSORS); + /* Initialize test framework */ state = SDLTest_CommonCreateState(argv, SDL_INIT_VIDEO); if (!state) { |