diff --git a/CMakeLists.txt b/CMakeLists.txt index b146434db..a9b690a15 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -109,13 +109,10 @@ if(ANDROID) src/SDL-mobile/src/cpuinfo/*.c src/SDL-mobile/src/events/*.c src/SDL-mobile/src/file/*.c - src/SDL-mobile/src/haptic/*.c - src/SDL-mobile/src/haptic/dummy/*.c src/SDL-mobile/src/joystick/*.c src/SDL-mobile/src/joystick/android/*.c src/SDL-mobile/src/loadso/dlopen/*.c src/SDL-mobile/src/render/*.c - src/SDL-mobile/src/render/*/*.c src/SDL-mobile/src/stdlib/*.c src/SDL-mobile/src/thread/*.c src/SDL-mobile/src/thread/pthread/*.c diff --git a/src/SDL-mobile/include/SDL_config.h.orig b/src/SDL-mobile/include/SDL_config.h.orig deleted file mode 100644 index 0caca9ff2..000000000 --- a/src/SDL-mobile/include/SDL_config.h.orig +++ /dev/null @@ -1,326 +0,0 @@ -/* include/SDL_config.h. Generated from SDL_config.h.in by configure. */ -/* - Simple DirectMedia Layer - Copyright (C) 1997-2011 Sam Lantinga - - 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_config_h -#define _SDL_config_h - -/** - * \file SDL_config.h.in - * - * This is a set of defines to configure the SDL features - */ - -/* General platform specific identifiers */ -#include "SDL_platform.h" - -<<<<<<< local -/* Make sure that this isn't included by Visual C++ */ -#ifdef _MSC_VER -#error You should run hg revert SDL_config.h -#endif - -/* C language features */ -/* #undef const */ -/* #undef inline */ -/* #undef volatile */ - -/* C datatypes */ -#define SIZEOF_VOIDP 8 -#define HAVE_GCC_ATOMICS 1 -/* #undef HAVE_GCC_SYNC_LOCK_TEST_AND_SET */ -/* #undef HAVE_PTHREAD_SPINLOCK */ - -/* Comment this if you want to build without any C library requirements */ -#define HAVE_LIBC 1 -#if HAVE_LIBC - -/* Useful headers */ -#define HAVE_ALLOCA_H 1 -#define HAVE_SYS_TYPES_H 1 -#define HAVE_STDIO_H 1 -#define STDC_HEADERS 1 -#define HAVE_STDLIB_H 1 -#define HAVE_STDARG_H 1 -#define HAVE_MALLOC_H 1 -#define HAVE_MEMORY_H 1 -#define HAVE_STRING_H 1 -#define HAVE_STRINGS_H 1 -#define HAVE_INTTYPES_H 1 -#define HAVE_STDINT_H 1 -#define HAVE_CTYPE_H 1 -#define HAVE_MATH_H 1 -#define HAVE_ICONV_H 1 -#define HAVE_SIGNAL_H 1 -/* #undef HAVE_ALTIVEC_H */ - -/* C library functions */ -#define HAVE_MALLOC 1 -#define HAVE_CALLOC 1 -#define HAVE_REALLOC 1 -#define HAVE_FREE 1 -#define HAVE_ALLOCA 1 -#ifndef __WIN32__ /* Don't use C runtime versions of these on Windows */ -#define HAVE_GETENV 1 -#define HAVE_SETENV 1 -#define HAVE_PUTENV 1 -#define HAVE_UNSETENV 1 -#endif -#define HAVE_QSORT 1 -#define HAVE_ABS 1 -#define HAVE_BCOPY 1 -#define HAVE_MEMSET 1 -#define HAVE_MEMCPY 1 -#define HAVE_MEMMOVE 1 -#define HAVE_MEMCMP 1 -#define HAVE_STRLEN 1 -/* #undef HAVE_STRLCPY */ -/* #undef HAVE_STRLCAT */ -#define HAVE_STRDUP 1 -/* #undef HAVE__STRREV */ -/* #undef HAVE__STRUPR */ -/* #undef HAVE__STRLWR */ -/* #undef HAVE_INDEX */ -/* #undef HAVE_RINDEX */ -#define HAVE_STRCHR 1 -#define HAVE_STRRCHR 1 -#define HAVE_STRSTR 1 -/* #undef HAVE_ITOA */ -/* #undef HAVE__LTOA */ -/* #undef HAVE__UITOA */ -/* #undef HAVE__ULTOA */ -#define HAVE_STRTOL 1 -#define HAVE_STRTOUL 1 -/* #undef HAVE__I64TOA */ -/* #undef HAVE__UI64TOA */ -#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 -/* #undef HAVE__STRICMP */ -#define HAVE_STRCASECMP 1 -/* #undef HAVE__STRNICMP */ -#define HAVE_STRNCASECMP 1 -#define HAVE_SSCANF 1 -#define HAVE_SNPRINTF 1 -#define HAVE_VSNPRINTF 1 -#define HAVE_M_PI -#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_SIGACTION 1 -#define HAVE_SA_SIGACTION 1 -#define HAVE_SETJMP 1 -#define HAVE_NANOSLEEP 1 -#define HAVE_SYSCONF 1 -/* #undef HAVE_SYSCTLBYNAME */ -/* #undef HAVE_CLOCK_GETTIME */ -/* #undef HAVE_GETPAGESIZE */ -#define HAVE_MPROTECT 1 -#define HAVE_ICONV 1 - -======= -/** - * \file SDL_config.h - */ - -/* Add any platform that doesn't build using the configure system. */ -#if defined(__WIN32__) -#include "SDL_config_windows.h" -#elif defined(__MACOSX__) -#include "SDL_config_macosx.h" -#elif defined(__IPHONEOS__) -#include "SDL_config_iphoneos.h" -#elif defined(__ANDROID__) -#include "SDL_config_android.h" -#elif defined(__NINTENDODS__) -#include "SDL_config_nintendods.h" ->>>>>>> other -#else -<<<<<<< local -/* We may need some replacement for stdarg.h here */ -#include -#endif /* HAVE_LIBC */ - -/* SDL internal assertion support */ -/* #undef SDL_DEFAULT_ASSERT_LEVEL */ - -/* Allow disabling of core subsystems */ -/* #undef SDL_ATOMIC_DISABLED */ -/* #undef SDL_AUDIO_DISABLED */ -/* #undef SDL_CPUINFO_DISABLED */ -/* #undef SDL_EVENTS_DISABLED */ -/* #undef SDL_FILE_DISABLED */ -/* #undef SDL_JOYSTICK_DISABLED */ -/* #undef SDL_HAPTIC_DISABLED */ -/* #undef SDL_LOADSO_DISABLED */ -/* #undef SDL_RENDER_DISABLED */ -/* #undef SDL_THREADS_DISABLED */ -/* #undef SDL_TIMERS_DISABLED */ -/* #undef SDL_VIDEO_DISABLED */ -/* #undef SDL_POWER_DISABLED */ - -/* Enable various audio drivers */ -#define SDL_AUDIO_DRIVER_ALSA 1 -#define SDL_AUDIO_DRIVER_ALSA_DYNAMIC "libasound.so.2" -/* #undef SDL_AUDIO_DRIVER_ARTS */ -/* #undef SDL_AUDIO_DRIVER_ARTS_DYNAMIC */ -#define SDL_AUDIO_DRIVER_PULSEAUDIO 1 -#define SDL_AUDIO_DRIVER_PULSEAUDIO_DYNAMIC "libpulse-simple.so.0" -/* #undef SDL_AUDIO_DRIVER_BEOSAUDIO */ -/* #undef SDL_AUDIO_DRIVER_BSD */ -/* #undef SDL_AUDIO_DRIVER_COREAUDIO */ -#define SDL_AUDIO_DRIVER_DISK 1 -#define SDL_AUDIO_DRIVER_DUMMY 1 -/* #undef SDL_AUDIO_DRIVER_XAUDIO2 */ -/* #undef SDL_AUDIO_DRIVER_DSOUND */ -/* #undef SDL_AUDIO_DRIVER_ESD */ -/* #undef SDL_AUDIO_DRIVER_ESD_DYNAMIC */ -/* #undef SDL_AUDIO_DRIVER_NAS */ -/* #undef SDL_AUDIO_DRIVER_NAS_DYNAMIC */ -/* #undef SDL_AUDIO_DRIVER_NDS */ -#define SDL_AUDIO_DRIVER_OSS 1 -/* #undef SDL_AUDIO_DRIVER_OSS_SOUNDCARD_H */ -/* #undef SDL_AUDIO_DRIVER_PAUDIO */ -/* #undef SDL_AUDIO_DRIVER_QSA */ -/* #undef SDL_AUDIO_DRIVER_SUNAUDIO */ -/* #undef SDL_AUDIO_DRIVER_WINMM */ -/* #undef SDL_AUDIO_DRIVER_FUSIONSOUND */ -/* #undef SDL_AUDIO_DRIVER_FUSIONSOUND_DYNAMIC */ - -/* Enable various input drivers */ -#define SDL_INPUT_LINUXEV 1 -/* #undef SDL_INPUT_TSLIB */ -/* #undef SDL_JOYSTICK_BEOS */ -/* #undef SDL_JOYSTICK_DINPUT */ -/* #undef SDL_JOYSTICK_DUMMY */ -/* #undef SDL_JOYSTICK_IOKIT */ -#define SDL_JOYSTICK_LINUX 1 -/* #undef SDL_JOYSTICK_NDS */ -/* #undef SDL_JOYSTICK_WINMM */ -/* #undef SDL_JOYSTICK_USBHID */ -/* #undef SDL_JOYSTICK_USBHID_MACHINE_JOYSTICK_H */ -/* #undef SDL_HAPTIC_DUMMY */ -#define SDL_HAPTIC_LINUX 1 -/* #undef SDL_HAPTIC_IOKIT */ -/* #undef SDL_HAPTIC_DINPUT */ - -/* Enable various shared object loading systems */ -/* #undef SDL_LOADSO_BEOS */ -/* #undef SDL_LOADSO_DLCOMPAT */ -#define SDL_LOADSO_DLOPEN 1 -/* #undef SDL_LOADSO_DUMMY */ -/* #undef SDL_LOADSO_LDG */ -/* #undef SDL_LOADSO_WINDOWS */ - -/* Enable various threading systems */ -/* #undef SDL_THREAD_BEOS */ -/* #undef SDL_THREAD_NDS */ -#define SDL_THREAD_PTHREAD 1 -#define SDL_THREAD_PTHREAD_RECURSIVE_MUTEX 1 -/* #undef SDL_THREAD_PTHREAD_RECURSIVE_MUTEX_NP */ -/* #undef SDL_THREAD_SPROC */ -/* #undef SDL_THREAD_WINDOWS */ - -/* Enable various timer systems */ -/* #undef SDL_TIMER_BEOS */ -/* #undef SDL_TIMER_DUMMY */ -/* #undef SDL_TIMER_NDS */ -#define SDL_TIMER_UNIX 1 -/* #undef SDL_TIMER_WINDOWS */ -/* #undef SDL_TIMER_WINCE */ - -/* Enable various video drivers */ -/* #undef SDL_VIDEO_DRIVER_BWINDOW */ -/* #undef SDL_VIDEO_DRIVER_COCOA */ -/* #undef SDL_VIDEO_DRIVER_DIRECTFB */ -/* #undef SDL_VIDEO_DRIVER_DIRECTFB_DYNAMIC */ -#define SDL_VIDEO_DRIVER_DUMMY 1 -/* #undef SDL_VIDEO_DRIVER_NDS */ -/* #undef SDL_VIDEO_DRIVER_WINDOWS */ -#define SDL_VIDEO_DRIVER_X11 1 -#define SDL_VIDEO_DRIVER_X11_DYNAMIC "libX11.so.6" -#define SDL_VIDEO_DRIVER_X11_DYNAMIC_XEXT "libXext.so.6" -#define SDL_VIDEO_DRIVER_X11_DYNAMIC_XCURSOR "libXcursor.so.1" -#define SDL_VIDEO_DRIVER_X11_DYNAMIC_XINERAMA "libXinerama.so.1" -#define SDL_VIDEO_DRIVER_X11_DYNAMIC_XINPUT "libXi.so.6" -#define SDL_VIDEO_DRIVER_X11_DYNAMIC_XRANDR "libXrandr.so.2" -/* #undef SDL_VIDEO_DRIVER_X11_DYNAMIC_XSS */ -#define SDL_VIDEO_DRIVER_X11_DYNAMIC_XVIDMODE "libXxf86vm.so.1" -#define SDL_VIDEO_DRIVER_X11_XCURSOR 1 -#define SDL_VIDEO_DRIVER_X11_XINERAMA 1 -#define SDL_VIDEO_DRIVER_X11_XINPUT 1 -#define SDL_VIDEO_DRIVER_X11_XRANDR 1 -/* #undef SDL_VIDEO_DRIVER_X11_XSCRNSAVER */ -#define SDL_VIDEO_DRIVER_X11_XSHAPE 1 -#define SDL_VIDEO_DRIVER_X11_XVIDMODE 1 - -/* #undef SDL_VIDEO_RENDER_D3D */ -#define SDL_VIDEO_RENDER_OGL 1 -/* #undef SDL_VIDEO_RENDER_OGL_ES */ -/* #undef SDL_VIDEO_RENDER_DIRECTFB */ - -/* Enable OpenGL support */ -#define SDL_VIDEO_OPENGL 1 -/* #undef SDL_VIDEO_OPENGL_ES */ -/* #undef SDL_VIDEO_OPENGL_BGL */ -/* #undef SDL_VIDEO_OPENGL_CGL */ -#define SDL_VIDEO_OPENGL_GLX 1 -/* #undef SDL_VIDEO_OPENGL_WGL */ -/* #undef SDL_VIDEO_OPENGL_OSMESA */ -/* #undef SDL_VIDEO_OPENGL_OSMESA_DYNAMIC */ - -/* Enable system power support */ -#define SDL_POWER_LINUX 1 -/* #undef SDL_POWER_WINDOWS */ -/* #undef SDL_POWER_MACOSX */ -/* #undef SDL_POWER_BEOS */ -/* #undef SDL_POWER_NINTENDODS */ -/* #undef SDL_POWER_HARDWIRED */ - -/* Enable assembly routines */ -#define SDL_ASSEMBLY_ROUTINES 1 -/* #undef SDL_ALTIVEC_BLITTERS */ -======= -/* This is a minimal configuration just to get SDL running on new platforms */ -#include "SDL_config_minimal.h" -#endif /* platform config */ ->>>>>>> other - -#ifdef USING_GENERATED_CONFIG_H -#error Wrong SDL_config.h, check your include path? -#endif - -#endif /* _SDL_config_h */ diff --git a/src/SDL-mobile/include/SDL_config_android.h b/src/SDL-mobile/include/SDL_config_android.h index c5f4f2088..79d9c6fd2 100644 --- a/src/SDL-mobile/include/SDL_config_android.h +++ b/src/SDL-mobile/include/SDL_config_android.h @@ -32,7 +32,6 @@ #include -#define HAVE_ALLOCA_H 1 #define HAVE_SYS_TYPES_H 1 #define HAVE_STDIO_H 1 #define STDC_HEADERS 1 @@ -44,60 +43,7 @@ #define HAVE_SIGNAL_H 1 /* C library functions */ -#define HAVE_MALLOC 1 -#define HAVE_CALLOC 1 -#define HAVE_REALLOC 1 -#define HAVE_FREE 1 -#define HAVE_ALLOCA 1 -#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 -#define HAVE_MEMSET 1 -#define HAVE_MEMCPY 1 -#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_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_STRCASECMP 1 -#define HAVE_STRNCASECMP 1 -#define HAVE_SSCANF 1 -#define HAVE_SNPRINTF 1 -#define HAVE_VSNPRINTF 1 -#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_SIGACTION 1 + #define HAVE_SETJMP 1 #define HAVE_NANOSLEEP 1 #define HAVE_SYSCONF 1 @@ -110,7 +56,6 @@ /* Enable various input drivers */ #define SDL_JOYSTICK_ANDROID 1 -#define SDL_HAPTIC_DUMMY 1 /* Enable various shared object loading systems */ #define SDL_LOADSO_DLOPEN 1 @@ -130,4 +75,6 @@ #define SDL_VIDEO_RENDER_OGL_ES 1 #define SDL_VIDEO_RENDER_OGL_ES2 1 +#define SDL_RENDER_DISABLED 1 + #endif /* _SDL_config_android_h */ diff --git a/src/SDL-mobile/include/SDL_haptic.h b/src/SDL-mobile/include/SDL_haptic.h deleted file mode 100644 index e0267007b..000000000 --- a/src/SDL-mobile/include/SDL_haptic.h +++ /dev/null @@ -1,1200 +0,0 @@ -/* - Simple DirectMedia Layer - Copyright (C) 1997-2012 Sam Lantinga - - 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. -*/ - -/** - * \file SDL_haptic.h - * - * \brief The SDL Haptic subsystem allows you to control haptic (force feedback) - * devices. - * - * The basic usage is as follows: - * - Initialize the Subsystem (::SDL_INIT_HAPTIC). - * - Open a Haptic Device. - * - SDL_HapticOpen() to open from index. - * - SDL_HapticOpenFromJoystick() to open from an existing joystick. - * - Create an effect (::SDL_HapticEffect). - * - Upload the effect with SDL_HapticNewEffect(). - * - Run the effect with SDL_HapticRunEffect(). - * - (optional) Free the effect with SDL_HapticDestroyEffect(). - * - Close the haptic device with SDL_HapticClose(). - * - * \par Simple rumble example: - * \code - * SDL_Haptic *haptic; - * - * // Open the device - * haptic = SDL_HapticOpen( 0 ); - * if (haptic == NULL) - * return -1; - * - * // Initialize simple rumble - * if (SDL_HapticRumbleInit( haptic ) != 0) - * return -1; - * - * // Play effect at 50% strength for 2 seconds - * if (SDL_HapticRumblePlay( haptic, 0.5, 2000 ) != 0) - * return -1; - * SDL_Delay( 2000 ); - * - * // Clean up - * SDL_HapticClose( haptic ); - * \endcode - * - * \par Complete example: - * \code - * int test_haptic( SDL_Joystick * joystick ) { - * SDL_Haptic *haptic; - * SDL_HapticEffect effect; - * int effect_id; - * - * // Open the device - * haptic = SDL_HapticOpenFromJoystick( joystick ); - * if (haptic == NULL) return -1; // Most likely joystick isn't haptic - * - * // See if it can do sine waves - * if ((SDL_HapticQuery(haptic) & SDL_HAPTIC_SINE)==0) { - * SDL_HapticClose(haptic); // No sine effect - * return -1; - * } - * - * // Create the effect - * memset( &effect, 0, sizeof(SDL_HapticEffect) ); // 0 is safe default - * effect.type = SDL_HAPTIC_SINE; - * effect.periodic.direction.type = SDL_HAPTIC_POLAR; // Polar coordinates - * effect.periodic.direction.dir[0] = 18000; // Force comes from south - * effect.periodic.period = 1000; // 1000 ms - * effect.periodic.magnitude = 20000; // 20000/32767 strength - * effect.periodic.length = 5000; // 5 seconds long - * effect.periodic.attack_length = 1000; // Takes 1 second to get max strength - * effect.periodic.fade_length = 1000; // Takes 1 second to fade away - * - * // Upload the effect - * effect_id = SDL_HapticNewEffect( haptic, &effect ); - * - * // Test the effect - * SDL_HapticRunEffect( haptic, effect_id, 1 ); - * SDL_Delay( 5000); // Wait for the effect to finish - * - * // We destroy the effect, although closing the device also does this - * SDL_HapticDestroyEffect( haptic, effect_id ); - * - * // Close the device - * SDL_HapticClose(haptic); - * - * return 0; // Success - * } - * \endcode - * - * You can also find out more information on my blog: - * http://bobbens.dyndns.org/journal/2010/sdl_haptic/ - * - * \author Edgar Simo Serra - */ - -#ifndef _SDL_haptic_h -#define _SDL_haptic_h - -#include "SDL_stdinc.h" -#include "SDL_error.h" -#include "SDL_joystick.h" - -#include "begin_code.h" -/* Set up for C function definitions, even when using C++ */ -#ifdef __cplusplus -/* *INDENT-OFF* */ -extern "C" { - /* *INDENT-ON* */ -#endif /* __cplusplus */ - -/** - * \typedef SDL_Haptic - * - * \brief The haptic structure used to identify an SDL haptic. - * - * \sa SDL_HapticOpen - * \sa SDL_HapticOpenFromJoystick - * \sa SDL_HapticClose - */ -struct _SDL_Haptic; -typedef struct _SDL_Haptic SDL_Haptic; - - -/** - * \name Haptic features - * - * Different haptic features a device can have. - */ -/*@{*/ - -/** - * \name Haptic effects - */ -/*@{*/ - -/** - * \brief Constant effect supported. - * - * Constant haptic effect. - * - * \sa SDL_HapticCondition - */ -#define SDL_HAPTIC_CONSTANT (1<<0) - -/** - * \brief Sine wave effect supported. - * - * Periodic haptic effect that simulates sine waves. - * - * \sa SDL_HapticPeriodic - */ -#define SDL_HAPTIC_SINE (1<<1) - -/** - * \brief Square wave effect supported. - * - * Periodic haptic effect that simulates square waves. - * - * \sa SDL_HapticPeriodic - */ -#define SDL_HAPTIC_SQUARE (1<<2) - -/** - * \brief Triangle wave effect supported. - * - * Periodic haptic effect that simulates triangular waves. - * - * \sa SDL_HapticPeriodic - */ -#define SDL_HAPTIC_TRIANGLE (1<<3) - -/** - * \brief Sawtoothup wave effect supported. - * - * Periodic haptic effect that simulates saw tooth up waves. - * - * \sa SDL_HapticPeriodic - */ -#define SDL_HAPTIC_SAWTOOTHUP (1<<4) - -/** - * \brief Sawtoothdown wave effect supported. - * - * Periodic haptic effect that simulates saw tooth down waves. - * - * \sa SDL_HapticPeriodic - */ -#define SDL_HAPTIC_SAWTOOTHDOWN (1<<5) - -/** - * \brief Ramp effect supported. - * - * Ramp haptic effect. - * - * \sa SDL_HapticRamp - */ -#define SDL_HAPTIC_RAMP (1<<6) - -/** - * \brief Spring effect supported - uses axes position. - * - * Condition haptic effect that simulates a spring. Effect is based on the - * axes position. - * - * \sa SDL_HapticCondition - */ -#define SDL_HAPTIC_SPRING (1<<7) - -/** - * \brief Damper effect supported - uses axes velocity. - * - * Condition haptic effect that simulates dampening. Effect is based on the - * axes velocity. - * - * \sa SDL_HapticCondition - */ -#define SDL_HAPTIC_DAMPER (1<<8) - -/** - * \brief Inertia effect supported - uses axes acceleration. - * - * Condition haptic effect that simulates inertia. Effect is based on the axes - * acceleration. - * - * \sa SDL_HapticCondition - */ -#define SDL_HAPTIC_INERTIA (1<<9) - -/** - * \brief Friction effect supported - uses axes movement. - * - * Condition haptic effect that simulates friction. Effect is based on the - * axes movement. - * - * \sa SDL_HapticCondition - */ -#define SDL_HAPTIC_FRICTION (1<<10) - -/** - * \brief Custom effect is supported. - * - * User defined custom haptic effect. - */ -#define SDL_HAPTIC_CUSTOM (1<<11) - -/*@}*//*Haptic effects*/ - -/* These last few are features the device has, not effects */ - -/** - * \brief Device can set global gain. - * - * Device supports setting the global gain. - * - * \sa SDL_HapticSetGain - */ -#define SDL_HAPTIC_GAIN (1<<12) - -/** - * \brief Device can set autocenter. - * - * Device supports setting autocenter. - * - * \sa SDL_HapticSetAutocenter - */ -#define SDL_HAPTIC_AUTOCENTER (1<<13) - -/** - * \brief Device can be queried for effect status. - * - * Device can be queried for effect status. - * - * \sa SDL_HapticGetEffectStatus - */ -#define SDL_HAPTIC_STATUS (1<<14) - -/** - * \brief Device can be paused. - * - * \sa SDL_HapticPause - * \sa SDL_HapticUnpause - */ -#define SDL_HAPTIC_PAUSE (1<<15) - - -/** - * \name Direction encodings - */ -/*@{*/ - -/** - * \brief Uses polar coordinates for the direction. - * - * \sa SDL_HapticDirection - */ -#define SDL_HAPTIC_POLAR 0 - -/** - * \brief Uses cartesian coordinates for the direction. - * - * \sa SDL_HapticDirection - */ -#define SDL_HAPTIC_CARTESIAN 1 - -/** - * \brief Uses spherical coordinates for the direction. - * - * \sa SDL_HapticDirection - */ -#define SDL_HAPTIC_SPHERICAL 2 - -/*@}*//*Direction encodings*/ - -/*@}*//*Haptic features*/ - -/* - * Misc defines. - */ - -/** - * \brief Used to play a device an infinite number of times. - * - * \sa SDL_HapticRunEffect - */ -#define SDL_HAPTIC_INFINITY 4294967295U - - -/** - * \brief Structure that represents a haptic direction. - * - * Directions can be specified by: - * - ::SDL_HAPTIC_POLAR : Specified by polar coordinates. - * - ::SDL_HAPTIC_CARTESIAN : Specified by cartesian coordinates. - * - ::SDL_HAPTIC_SPHERICAL : Specified by spherical coordinates. - * - * Cardinal directions of the haptic device are relative to the positioning - * of the device. North is considered to be away from the user. - * - * The following diagram represents the cardinal directions: - * \verbatim - .--. - |__| .-------. - |=.| |.-----.| - |--| || || - | | |'-----'| - |__|~')_____(' - [ COMPUTER ] - - - North (0,-1) - ^ - | - | - (1,0) West <----[ HAPTIC ]----> East (-1,0) - | - | - v - South (0,1) - - - [ USER ] - \|||/ - (o o) - ---ooO-(_)-Ooo--- - \endverbatim - * - * If type is ::SDL_HAPTIC_POLAR, direction is encoded by hundredths of a - * degree starting north and turning clockwise. ::SDL_HAPTIC_POLAR only uses - * the first \c dir parameter. The cardinal directions would be: - * - North: 0 (0 degrees) - * - East: 9000 (90 degrees) - * - South: 18000 (180 degrees) - * - West: 27000 (270 degrees) - * - * If type is ::SDL_HAPTIC_CARTESIAN, direction is encoded by three positions - * (X axis, Y axis and Z axis (with 3 axes)). ::SDL_HAPTIC_CARTESIAN uses - * the first three \c dir parameters. The cardinal directions would be: - * - North: 0,-1, 0 - * - East: -1, 0, 0 - * - South: 0, 1, 0 - * - West: 1, 0, 0 - * - * The Z axis represents the height of the effect if supported, otherwise - * it's unused. In cartesian encoding (1, 2) would be the same as (2, 4), you - * can use any multiple you want, only the direction matters. - * - * If type is ::SDL_HAPTIC_SPHERICAL, direction is encoded by two rotations. - * The first two \c dir parameters are used. The \c dir parameters are as - * follows (all values are in hundredths of degrees): - * - Degrees from (1, 0) rotated towards (0, 1). - * - Degrees towards (0, 0, 1) (device needs at least 3 axes). - * - * - * Example of force coming from the south with all encodings (force coming - * from the south means the user will have to pull the stick to counteract): - * \code - * SDL_HapticDirection direction; - * - * // Cartesian directions - * direction.type = SDL_HAPTIC_CARTESIAN; // Using cartesian direction encoding. - * direction.dir[0] = 0; // X position - * direction.dir[1] = 1; // Y position - * // Assuming the device has 2 axes, we don't need to specify third parameter. - * - * // Polar directions - * direction.type = SDL_HAPTIC_POLAR; // We'll be using polar direction encoding. - * direction.dir[0] = 18000; // Polar only uses first parameter - * - * // Spherical coordinates - * direction.type = SDL_HAPTIC_SPHERICAL; // Spherical encoding - * direction.dir[0] = 9000; // Since we only have two axes we don't need more parameters. - * \endcode - * - * \sa SDL_HAPTIC_POLAR - * \sa SDL_HAPTIC_CARTESIAN - * \sa SDL_HAPTIC_SPHERICAL - * \sa SDL_HapticEffect - * \sa SDL_HapticNumAxes - */ -typedef struct SDL_HapticDirection -{ - Uint8 type; /**< The type of encoding. */ - Sint32 dir[3]; /**< The encoded direction. */ -} SDL_HapticDirection; - - -/** - * \brief A structure containing a template for a Constant effect. - * - * The struct is exclusive to the ::SDL_HAPTIC_CONSTANT effect. - * - * A constant effect applies a constant force in the specified direction - * to the joystick. - * - * \sa SDL_HAPTIC_CONSTANT - * \sa SDL_HapticEffect - */ -typedef struct SDL_HapticConstant -{ - /* Header */ - Uint16 type; /**< ::SDL_HAPTIC_CONSTANT */ - SDL_HapticDirection direction; /**< Direction of the effect. */ - - /* Replay */ - Uint32 length; /**< Duration of the effect. */ - Uint16 delay; /**< Delay before starting the effect. */ - - /* Trigger */ - Uint16 button; /**< Button that triggers the effect. */ - Uint16 interval; /**< How soon it can be triggered again after button. */ - - /* Constant */ - Sint16 level; /**< Strength of the constant effect. */ - - /* Envelope */ - Uint16 attack_length; /**< Duration of the attack. */ - Uint16 attack_level; /**< Level at the start of the attack. */ - Uint16 fade_length; /**< Duration of the fade. */ - Uint16 fade_level; /**< Level at the end of the fade. */ -} SDL_HapticConstant; - -/** - * \brief A structure containing a template for a Periodic effect. - * - * The struct handles the following effects: - * - ::SDL_HAPTIC_SINE - * - ::SDL_HAPTIC_SQUARE - * - ::SDL_HAPTIC_TRIANGLE - * - ::SDL_HAPTIC_SAWTOOTHUP - * - ::SDL_HAPTIC_SAWTOOTHDOWN - * - * A periodic effect consists in a wave-shaped effect that repeats itself - * over time. The type determines the shape of the wave and the parameters - * determine the dimensions of the wave. - * - * Phase is given by hundredth of a cyle meaning that giving the phase a value - * of 9000 will displace it 25% of it's period. Here are sample values: - * - 0: No phase displacement. - * - 9000: Displaced 25% of it's period. - * - 18000: Displaced 50% of it's period. - * - 27000: Displaced 75% of it's period. - * - 36000: Displaced 100% of it's period, same as 0, but 0 is preffered. - * - * Examples: - * \verbatim - SDL_HAPTIC_SINE - __ __ __ __ - / \ / \ / \ / - / \__/ \__/ \__/ - - SDL_HAPTIC_SQUARE - __ __ __ __ __ - | | | | | | | | | | - | |__| |__| |__| |__| | - - SDL_HAPTIC_TRIANGLE - /\ /\ /\ /\ /\ - / \ / \ / \ / \ / - / \/ \/ \/ \/ - - SDL_HAPTIC_SAWTOOTHUP - /| /| /| /| /| /| /| - / | / | / | / | / | / | / | - / |/ |/ |/ |/ |/ |/ | - - SDL_HAPTIC_SAWTOOTHDOWN - \ |\ |\ |\ |\ |\ |\ | - \ | \ | \ | \ | \ | \ | \ | - \| \| \| \| \| \| \| - \endverbatim - * - * \sa SDL_HAPTIC_SINE - * \sa SDL_HAPTIC_SQUARE - * \sa SDL_HAPTIC_TRIANGLE - * \sa SDL_HAPTIC_SAWTOOTHUP - * \sa SDL_HAPTIC_SAWTOOTHDOWN - * \sa SDL_HapticEffect - */ -typedef struct SDL_HapticPeriodic -{ - /* Header */ - Uint16 type; /**< ::SDL_HAPTIC_SINE, ::SDL_HAPTIC_SQUARE, - ::SDL_HAPTIC_TRIANGLE, ::SDL_HAPTIC_SAWTOOTHUP or - ::SDL_HAPTIC_SAWTOOTHDOWN */ - SDL_HapticDirection direction; /**< Direction of the effect. */ - - /* Replay */ - Uint32 length; /**< Duration of the effect. */ - Uint16 delay; /**< Delay before starting the effect. */ - - /* Trigger */ - Uint16 button; /**< Button that triggers the effect. */ - Uint16 interval; /**< How soon it can be triggered again after button. */ - - /* Periodic */ - Uint16 period; /**< Period of the wave. */ - Sint16 magnitude; /**< Peak value. */ - Sint16 offset; /**< Mean value of the wave. */ - Uint16 phase; /**< Horizontal shift given by hundredth of a cycle. */ - - /* Envelope */ - Uint16 attack_length; /**< Duration of the attack. */ - Uint16 attack_level; /**< Level at the start of the attack. */ - Uint16 fade_length; /**< Duration of the fade. */ - Uint16 fade_level; /**< Level at the end of the fade. */ -} SDL_HapticPeriodic; - -/** - * \brief A structure containing a template for a Condition effect. - * - * The struct handles the following effects: - * - ::SDL_HAPTIC_SPRING: Effect based on axes position. - * - ::SDL_HAPTIC_DAMPER: Effect based on axes velocity. - * - ::SDL_HAPTIC_INERTIA: Effect based on axes acceleration. - * - ::SDL_HAPTIC_FRICTION: Effect based on axes movement. - * - * Direction is handled by condition internals instead of a direction member. - * The condition effect specific members have three parameters. The first - * refers to the X axis, the second refers to the Y axis and the third - * refers to the Z axis. The right terms refer to the positive side of the - * axis and the left terms refer to the negative side of the axis. Please - * refer to the ::SDL_HapticDirection diagram for which side is positive and - * which is negative. - * - * \sa SDL_HapticDirection - * \sa SDL_HAPTIC_SPRING - * \sa SDL_HAPTIC_DAMPER - * \sa SDL_HAPTIC_INERTIA - * \sa SDL_HAPTIC_FRICTION - * \sa SDL_HapticEffect - */ -typedef struct SDL_HapticCondition -{ - /* Header */ - Uint16 type; /**< ::SDL_HAPTIC_SPRING, ::SDL_HAPTIC_DAMPER, - ::SDL_HAPTIC_INERTIA or ::SDL_HAPTIC_FRICTION */ - SDL_HapticDirection direction; /**< Direction of the effect - Not used ATM. */ - - /* Replay */ - Uint32 length; /**< Duration of the effect. */ - Uint16 delay; /**< Delay before starting the effect. */ - - /* Trigger */ - Uint16 button; /**< Button that triggers the effect. */ - Uint16 interval; /**< How soon it can be triggered again after button. */ - - /* Condition */ - Uint16 right_sat[3]; /**< Level when joystick is to the positive side. */ - Uint16 left_sat[3]; /**< Level when joystick is to the negative side. */ - Sint16 right_coeff[3]; /**< How fast to increase the force towards the positive side. */ - Sint16 left_coeff[3]; /**< How fast to increase the force towards the negative side. */ - Uint16 deadband[3]; /**< Size of the dead zone. */ - Sint16 center[3]; /**< Position of the dead zone. */ -} SDL_HapticCondition; - -/** - * \brief A structure containing a template for a Ramp effect. - * - * This struct is exclusively for the ::SDL_HAPTIC_RAMP effect. - * - * The ramp effect starts at start strength and ends at end strength. - * It augments in linear fashion. If you use attack and fade with a ramp - * they effects get added to the ramp effect making the effect become - * quadratic instead of linear. - * - * \sa SDL_HAPTIC_RAMP - * \sa SDL_HapticEffect - */ -typedef struct SDL_HapticRamp -{ - /* Header */ - Uint16 type; /**< ::SDL_HAPTIC_RAMP */ - SDL_HapticDirection direction; /**< Direction of the effect. */ - - /* Replay */ - Uint32 length; /**< Duration of the effect. */ - Uint16 delay; /**< Delay before starting the effect. */ - - /* Trigger */ - Uint16 button; /**< Button that triggers the effect. */ - Uint16 interval; /**< How soon it can be triggered again after button. */ - - /* Ramp */ - Sint16 start; /**< Beginning strength level. */ - Sint16 end; /**< Ending strength level. */ - - /* Envelope */ - Uint16 attack_length; /**< Duration of the attack. */ - Uint16 attack_level; /**< Level at the start of the attack. */ - Uint16 fade_length; /**< Duration of the fade. */ - Uint16 fade_level; /**< Level at the end of the fade. */ -} SDL_HapticRamp; - -/** - * \brief A structure containing a template for the ::SDL_HAPTIC_CUSTOM effect. - * - * A custom force feedback effect is much like a periodic effect, where the - * application can define it's exact shape. You will have to allocate the - * data yourself. Data should consist of channels * samples Uint16 samples. - * - * If channels is one, the effect is rotated using the defined direction. - * Otherwise it uses the samples in data for the different axes. - * - * \sa SDL_HAPTIC_CUSTOM - * \sa SDL_HapticEffect - */ -typedef struct SDL_HapticCustom -{ - /* Header */ - Uint16 type; /**< ::SDL_HAPTIC_CUSTOM */ - SDL_HapticDirection direction; /**< Direction of the effect. */ - - /* Replay */ - Uint32 length; /**< Duration of the effect. */ - Uint16 delay; /**< Delay before starting the effect. */ - - /* Trigger */ - Uint16 button; /**< Button that triggers the effect. */ - Uint16 interval; /**< How soon it can be triggered again after button. */ - - /* Custom */ - Uint8 channels; /**< Axes to use, minimum of one. */ - Uint16 period; /**< Sample periods. */ - Uint16 samples; /**< Amount of samples. */ - Uint16 *data; /**< Should contain channels*samples items. */ - - /* Envelope */ - Uint16 attack_length; /**< Duration of the attack. */ - Uint16 attack_level; /**< Level at the start of the attack. */ - Uint16 fade_length; /**< Duration of the fade. */ - Uint16 fade_level; /**< Level at the end of the fade. */ -} SDL_HapticCustom; - -/** - * \brief The generic template for any haptic effect. - * - * All values max at 32767 (0x7FFF). Signed values also can be negative. - * Time values unless specified otherwise are in milliseconds. - * - * You can also pass ::SDL_HAPTIC_INFINITY to length instead of a 0-32767 - * value. Neither delay, interval, attack_length nor fade_length support - * ::SDL_HAPTIC_INFINITY. Fade will also not be used since effect never ends. - * - * Additionally, the ::SDL_HAPTIC_RAMP effect does not support a duration of - * ::SDL_HAPTIC_INFINITY. - * - * Button triggers may not be supported on all devices, it is advised to not - * use them if possible. Buttons start at index 1 instead of index 0 like - * they joystick. - * - * If both attack_length and fade_level are 0, the envelope is not used, - * otherwise both values are used. - * - * Common parts: - * \code - * // Replay - All effects have this - * Uint32 length; // Duration of effect (ms). - * Uint16 delay; // Delay before starting effect. - * - * // Trigger - All effects have this - * Uint16 button; // Button that triggers effect. - * Uint16 interval; // How soon before effect can be triggered again. - * - * // Envelope - All effects except condition effects have this - * Uint16 attack_length; // Duration of the attack (ms). - * Uint16 attack_level; // Level at the start of the attack. - * Uint16 fade_length; // Duration of the fade out (ms). - * Uint16 fade_level; // Level at the end of the fade. - * \endcode - * - * - * Here we have an example of a constant effect evolution in time: - * \verbatim - Strength - ^ - | - | effect level --> _________________ - | / \ - | / \ - | / \ - | / \ - | attack_level --> | \ - | | | <--- fade_level - | - +--------------------------------------------------> Time - [--] [---] - attack_length fade_length - - [------------------][-----------------------] - delay length - \endverbatim - * - * Note either the attack_level or the fade_level may be above the actual - * effect level. - * - * \sa SDL_HapticConstant - * \sa SDL_HapticPeriodic - * \sa SDL_HapticCondition - * \sa SDL_HapticRamp - * \sa SDL_HapticCustom - */ -typedef union SDL_HapticEffect -{ - /* Common for all force feedback effects */ - Uint16 type; /**< Effect type. */ - SDL_HapticConstant constant; /**< Constant effect. */ - SDL_HapticPeriodic periodic; /**< Periodic effect. */ - SDL_HapticCondition condition; /**< Condition effect. */ - SDL_HapticRamp ramp; /**< Ramp effect. */ - SDL_HapticCustom custom; /**< Custom effect. */ -} SDL_HapticEffect; - - -/* Function prototypes */ -/** - * \brief Count the number of joysticks attached to the system. - * - * \return Number of haptic devices detected on the system. - */ -extern DECLSPEC int SDLCALL SDL_NumHaptics(void); - -/** - * \brief Get the implementation dependent name of a Haptic device. - * - * This can be called before any joysticks are opened. - * If no name can be found, this function returns NULL. - * - * \param device_index Index of the device to get it's name. - * \return Name of the device or NULL on error. - * - * \sa SDL_NumHaptics - */ -extern DECLSPEC const char *SDLCALL SDL_HapticName(int device_index); - -/** - * \brief Opens a Haptic device for usage. - * - * The index passed as an argument refers to the N'th Haptic device on this - * system. - * - * When opening a haptic device, it's gain will be set to maximum and - * autocenter will be disabled. To modify these values use - * SDL_HapticSetGain() and SDL_HapticSetAutocenter(). - * - * \param device_index Index of the device to open. - * \return Device identifier or NULL on error. - * - * \sa SDL_HapticIndex - * \sa SDL_HapticOpenFromMouse - * \sa SDL_HapticOpenFromJoystick - * \sa SDL_HapticClose - * \sa SDL_HapticSetGain - * \sa SDL_HapticSetAutocenter - * \sa SDL_HapticPause - * \sa SDL_HapticStopAll - */ -extern DECLSPEC SDL_Haptic *SDLCALL SDL_HapticOpen(int device_index); - -/** - * \brief Checks if the haptic device at index has been opened. - * - * \param device_index Index to check to see if it has been opened. - * \return 1 if it has been opened or 0 if it hasn't. - * - * \sa SDL_HapticOpen - * \sa SDL_HapticIndex - */ -extern DECLSPEC int SDLCALL SDL_HapticOpened(int device_index); - -/** - * \brief Gets the index of a haptic device. - * - * \param haptic Haptic device to get the index of. - * \return The index of the haptic device or -1 on error. - * - * \sa SDL_HapticOpen - * \sa SDL_HapticOpened - */ -extern DECLSPEC int SDLCALL SDL_HapticIndex(SDL_Haptic * haptic); - -/** - * \brief Gets whether or not the current mouse has haptic capabilities. - * - * \return SDL_TRUE if the mouse is haptic, SDL_FALSE if it isn't. - * - * \sa SDL_HapticOpenFromMouse - */ -extern DECLSPEC int SDLCALL SDL_MouseIsHaptic(void); - -/** - * \brief Tries to open a haptic device from the current mouse. - * - * \return The haptic device identifier or NULL on error. - * - * \sa SDL_MouseIsHaptic - * \sa SDL_HapticOpen - */ -extern DECLSPEC SDL_Haptic *SDLCALL SDL_HapticOpenFromMouse(void); - -/** - * \brief Checks to see if a joystick has haptic features. - * - * \param joystick Joystick to test for haptic capabilities. - * \return 1 if the joystick is haptic, 0 if it isn't - * or -1 if an error ocurred. - * - * \sa SDL_HapticOpenFromJoystick - */ -extern DECLSPEC int SDLCALL SDL_JoystickIsHaptic(SDL_Joystick * joystick); - -/** - * \brief Opens a Haptic device for usage from a Joystick device. - * - * You must still close the haptic device seperately. It will not be closed - * with the joystick. - * - * When opening from a joystick you should first close the haptic device before - * closing the joystick device. If not, on some implementations the haptic - * device will also get unallocated and you'll be unable to use force feedback - * on that device. - * - * \param joystick Joystick to create a haptic device from. - * \return A valid haptic device identifier on success or NULL on error. - * - * \sa SDL_HapticOpen - * \sa SDL_HapticClose - */ -extern DECLSPEC SDL_Haptic *SDLCALL SDL_HapticOpenFromJoystick(SDL_Joystick * - joystick); - -/** - * \brief Closes a Haptic device previously opened with SDL_HapticOpen(). - * - * \param haptic Haptic device to close. - */ -extern DECLSPEC void SDLCALL SDL_HapticClose(SDL_Haptic * haptic); - -/** - * \brief Returns the number of effects a haptic device can store. - * - * On some platforms this isn't fully supported, and therefore is an - * aproximation. Always check to see if your created effect was actually - * created and do not rely solely on SDL_HapticNumEffects(). - * - * \param haptic The haptic device to query effect max. - * \return The number of effects the haptic device can store or - * -1 on error. - * - * \sa SDL_HapticNumEffectsPlaying - * \sa SDL_HapticQuery - */ -extern DECLSPEC int SDLCALL SDL_HapticNumEffects(SDL_Haptic * haptic); - -/** - * \brief Returns the number of effects a haptic device can play at the same - * time. - * - * This is not supported on all platforms, but will always return a value. - * Added here for the sake of completness. - * - * \param haptic The haptic device to query maximum playing effects. - * \return The number of effects the haptic device can play at the same time - * or -1 on error. - * - * \sa SDL_HapticNumEffects - * \sa SDL_HapticQuery - */ -extern DECLSPEC int SDLCALL SDL_HapticNumEffectsPlaying(SDL_Haptic * haptic); - -/** - * \brief Gets the haptic devices supported features in bitwise matter. - * - * Example: - * \code - * if (SDL_HapticQueryEffects(haptic) & SDL_HAPTIC_CONSTANT) { - * printf("We have constant haptic effect!"); - * } - * \endcode - * - * \param haptic The haptic device to query. - * \return Haptic features in bitwise manner (OR'd). - * - * \sa SDL_HapticNumEffects - * \sa SDL_HapticEffectSupported - */ -extern DECLSPEC unsigned int SDLCALL SDL_HapticQuery(SDL_Haptic * haptic); - - -/** - * \brief Gets the number of haptic axes the device has. - * - * \sa SDL_HapticDirection - */ -extern DECLSPEC int SDLCALL SDL_HapticNumAxes(SDL_Haptic * haptic); - -/** - * \brief Checks to see if effect is supported by haptic. - * - * \param haptic Haptic device to check on. - * \param effect Effect to check to see if it is supported. - * \return SDL_TRUE if effect is supported, SDL_FALSE if it isn't or -1 on error. - * - * \sa SDL_HapticQuery - * \sa SDL_HapticNewEffect - */ -extern DECLSPEC int SDLCALL SDL_HapticEffectSupported(SDL_Haptic * haptic, - SDL_HapticEffect * - effect); - -/** - * \brief Creates a new haptic effect on the device. - * - * \param haptic Haptic device to create the effect on. - * \param effect Properties of the effect to create. - * \return The id of the effect on success or -1 on error. - * - * \sa SDL_HapticUpdateEffect - * \sa SDL_HapticRunEffect - * \sa SDL_HapticDestroyEffect - */ -extern DECLSPEC int SDLCALL SDL_HapticNewEffect(SDL_Haptic * haptic, - SDL_HapticEffect * effect); - -/** - * \brief Updates the properties of an effect. - * - * Can be used dynamically, although behaviour when dynamically changing - * direction may be strange. Specifically the effect may reupload itself - * and start playing from the start. You cannot change the type either when - * running SDL_HapticUpdateEffect(). - * - * \param haptic Haptic device that has the effect. - * \param effect Effect to update. - * \param data New effect properties to use. - * \return The id of the effect on success or -1 on error. - * - * \sa SDL_HapticNewEffect - * \sa SDL_HapticRunEffect - * \sa SDL_HapticDestroyEffect - */ -extern DECLSPEC int SDLCALL SDL_HapticUpdateEffect(SDL_Haptic * haptic, - int effect, - SDL_HapticEffect * data); - -/** - * \brief Runs the haptic effect on it's assosciated haptic device. - * - * If iterations are ::SDL_HAPTIC_INFINITY, it'll run the effect over and over - * repeating the envelope (attack and fade) every time. If you only want the - * effect to last forever, set ::SDL_HAPTIC_INFINITY in the effect's length - * parameter. - * - * \param haptic Haptic device to run the effect on. - * \param effect Identifier of the haptic effect to run. - * \param iterations Number of iterations to run the effect. Use - * ::SDL_HAPTIC_INFINITY for infinity. - * \return 0 on success or -1 on error. - * - * \sa SDL_HapticStopEffect - * \sa SDL_HapticDestroyEffect - * \sa SDL_HapticGetEffectStatus - */ -extern DECLSPEC int SDLCALL SDL_HapticRunEffect(SDL_Haptic * haptic, - int effect, - Uint32 iterations); - -/** - * \brief Stops the haptic effect on it's assosciated haptic device. - * - * \param haptic Haptic device to stop the effect on. - * \param effect Identifier of the effect to stop. - * \return 0 on success or -1 on error. - * - * \sa SDL_HapticRunEffect - * \sa SDL_HapticDestroyEffect - */ -extern DECLSPEC int SDLCALL SDL_HapticStopEffect(SDL_Haptic * haptic, - int effect); - -/** - * \brief Destroys a haptic effect on the device. - * - * This will stop the effect if it's running. Effects are automatically - * destroyed when the device is closed. - * - * \param haptic Device to destroy the effect on. - * \param effect Identifier of the effect to destroy. - * - * \sa SDL_HapticNewEffect - */ -extern DECLSPEC void SDLCALL SDL_HapticDestroyEffect(SDL_Haptic * haptic, - int effect); - -/** - * \brief Gets the status of the current effect on the haptic device. - * - * Device must support the ::SDL_HAPTIC_STATUS feature. - * - * \param haptic Haptic device to query the effect status on. - * \param effect Identifier of the effect to query it's status. - * \return 0 if it isn't playing, ::SDL_HAPTIC_PLAYING if it is playing - * or -1 on error. - * - * \sa SDL_HapticRunEffect - * \sa SDL_HapticStopEffect - */ -extern DECLSPEC int SDLCALL SDL_HapticGetEffectStatus(SDL_Haptic * haptic, - int effect); - -/** - * \brief Sets the global gain of the device. - * - * Device must support the ::SDL_HAPTIC_GAIN feature. - * - * The user may specify the maxmimum gain by setting the environment variable - * ::SDL_HAPTIC_GAIN_MAX which should be between 0 and 100. All calls to - * SDL_HapticSetGain() will scale linearly using ::SDL_HAPTIC_GAIN_MAX as the - * maximum. - * - * \param haptic Haptic device to set the gain on. - * \param gain Value to set the gain to, should be between 0 and 100. - * \return 0 on success or -1 on error. - * - * \sa SDL_HapticQuery - */ -extern DECLSPEC int SDLCALL SDL_HapticSetGain(SDL_Haptic * haptic, int gain); - -/** - * \brief Sets the global autocenter of the device. - * - * Autocenter should be between 0 and 100. Setting it to 0 will disable - * autocentering. - * - * Device must support the ::SDL_HAPTIC_AUTOCENTER feature. - * - * \param haptic Haptic device to set autocentering on. - * \param autocenter Value to set autocenter to, 0 disables autocentering. - * \return 0 on success or -1 on error. - * - * \sa SDL_HapticQuery - */ -extern DECLSPEC int SDLCALL SDL_HapticSetAutocenter(SDL_Haptic * haptic, - int autocenter); - -/** - * \brief Pauses a haptic device. - * - * Device must support the ::SDL_HAPTIC_PAUSE feature. Call - * SDL_HapticUnpause() to resume playback. - * - * Do not modify the effects nor add new ones while the device is paused. - * That can cause all sorts of weird errors. - * - * \param haptic Haptic device to pause. - * \return 0 on success or -1 on error. - * - * \sa SDL_HapticUnpause - */ -extern DECLSPEC int SDLCALL SDL_HapticPause(SDL_Haptic * haptic); - -/** - * \brief Unpauses a haptic device. - * - * Call to unpause after SDL_HapticPause(). - * - * \param haptic Haptic device to pause. - * \return 0 on success or -1 on error. - * - * \sa SDL_HapticPause - */ -extern DECLSPEC int SDLCALL SDL_HapticUnpause(SDL_Haptic * haptic); - -/** - * \brief Stops all the currently playing effects on a haptic device. - * - * \param haptic Haptic device to stop. - * \return 0 on success or -1 on error. - */ -extern DECLSPEC int SDLCALL SDL_HapticStopAll(SDL_Haptic * haptic); - -/** - * \brief Checks to see if rumble is supported on a haptic device.. - * - * \param haptic Haptic device to check to see if it supports rumble. - * \return SDL_TRUE if effect is supported, SDL_FALSE if it isn't or -1 on error. - * - * \sa SDL_HapticRumbleInit - * \sa SDL_HapticRumblePlay - * \sa SDL_HapticRumbleStop - */ -extern DECLSPEC int SDLCALL SDL_HapticRumbleSupported(SDL_Haptic * haptic); - -/** - * \brief Initializes the haptic device for simple rumble playback. - * - * \param haptic Haptic device to initialize for simple rumble playback. - * \return 0 on success or -1 on error. - * - * \sa SDL_HapticOpen - * \sa SDL_HapticRumbleSupported - * \sa SDL_HapticRumblePlay - * \sa SDL_HapticRumbleStop - */ -extern DECLSPEC int SDLCALL SDL_HapticRumbleInit(SDL_Haptic * haptic); - -/** - * \brief Runs simple rumble on a haptic device - * - * \param haptic Haptic device to play rumble effect on. - * \param strength Strength of the rumble to play as a 0-1 float value. - * \param length Length of the rumble to play in miliseconds. - * \return 0 on success or -1 on error. - * - * \sa SDL_HapticRumbleSupported - * \sa SDL_HapticRumbleInit - * \sa SDL_HapticRumbleStop - */ -extern DECLSPEC int SDLCALL SDL_HapticRumblePlay(SDL_Haptic * haptic, float strength, Uint32 length ); - -/** - * \brief Stops the simple rumble on a haptic device. - * - * \param haptic Haptic to stop the rumble on. - * \return 0 on success or -1 on error. - * - * \sa SDL_HapticRumbleSupported - * \sa SDL_HapticRumbleInit - * \sa SDL_HapticRumblePlay - */ -extern DECLSPEC int SDLCALL SDL_HapticRumbleStop(SDL_Haptic * haptic); - - - -/* Ends C function definitions when using C++ */ -#ifdef __cplusplus -/* *INDENT-OFF* */ -} -/* *INDENT-ON* */ -#endif -#include "close_code.h" - -#endif /* _SDL_haptic_h */ - -/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/SDL-mobile/include/SDL_stdinc.h b/src/SDL-mobile/include/SDL_stdinc.h index 74b7913a0..7717d6d12 100644 --- a/src/SDL-mobile/include/SDL_stdinc.h +++ b/src/SDL-mobile/include/SDL_stdinc.h @@ -21,7 +21,7 @@ /** * \file SDL_stdinc.h - * + * * This is a general header that includes C language support. */ @@ -85,7 +85,7 @@ /** * \name Cast operators - * + * * Use proper C++ casts when compiled as C++ to be compatible with the option * -Wold-style-cast of GCC (and -Werror=old-style-cast in GCC 4.2 and above). */ @@ -181,7 +181,7 @@ SDL_COMPILE_TIME_ASSERT(sint64, sizeof(Sint64) == 8); /** \cond */ #ifndef DOXYGEN_SHOULD_IGNORE_THIS -#if !defined(__NINTENDODS__) && !defined(__ANDROID__) +#if !defined(__NINTENDODS__) && !defined(__ANDROID__) /* TODO: include/SDL_stdinc.h:174: error: size of array 'SDL_dummy_enum' is negative */ typedef enum { @@ -201,124 +201,33 @@ 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 -# elif defined(__GNUC__) -# define alloca __builtin_alloca -# elif defined(_MSC_VER) -# include -# define alloca _alloca -# elif defined(__WATCOMC__) -# include -# elif defined(__BORLANDC__) -# include -# elif defined(__DMC__) -# include -# elif defined(__AIX__) -#pragma alloca -# elif defined(__MRC__) -void *alloca(unsigned); -# else -char *alloca(); -# endif -#endif -#ifdef HAVE_ALLOCA +#include #define SDL_stack_alloc(type, count) (type*)alloca(sizeof(type)*(count)) #define SDL_stack_free(data) -#else -#define SDL_stack_alloc(type, count) (type*)SDL_malloc(sizeof(type)*(count)) -#define SDL_stack_free(data) SDL_free(data) -#endif -#ifdef HAVE_GETENV #define SDL_getenv getenv -#else -extern DECLSPEC char *SDLCALL SDL_getenv(const char *name); -#endif - -/* SDL_putenv() has moved to SDL_compat. */ -#ifdef HAVE_SETENV #define SDL_setenv setenv -#else -extern DECLSPEC int SDLCALL SDL_setenv(const char *name, const char *value, - int overwrite); -#endif - -#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 *)); -#endif - -#ifdef HAVE_ABS #define SDL_abs abs -#else -#define SDL_abs(X) ((X) < 0 ? -(X) : (X)) -#endif #define SDL_min(x, y) (((x) < (y)) ? (x) : (y)) #define SDL_max(x, y) (((x) > (y)) ? (x) : (y)) -#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) -#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)) -#endif -#ifdef HAVE_MEMSET #define SDL_memset memset -#else -extern DECLSPEC void *SDLCALL SDL_memset(void *dst, int c, size_t len); -#endif + #define SDL_zero(x) SDL_memset(&(x), 0, sizeof((x))) #define SDL_zerop(x) SDL_memset((x), 0, sizeof(*(x))) -#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); \ @@ -334,390 +243,50 @@ do { \ } while ( --_n ); \ } \ } while(0) -#endif -/* We can count on memcpy existing on Mac OS X and being well-tuned. */ -#if defined(__MACOSX__) -#define SDL_memcpy memcpy -#elif defined(__GNUC__) && defined(i386) -#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 -#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) -#endif - -#ifdef HAVE_MEMMOVE #define SDL_memmove memmove -#else -extern DECLSPEC void *SDLCALL SDL_memmove(void *dst, const void *src, - size_t len); -#endif - -#ifdef HAVE_MEMCMP #define SDL_memcmp memcmp -#else -extern DECLSPEC int SDLCALL SDL_memcmp(const void *s1, const void *s2, - size_t len); -#endif - -#ifdef HAVE_STRLEN #define SDL_strlen strlen -#else -extern DECLSPEC size_t SDLCALL SDL_strlen(const char *string); -#endif - -#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); -#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); -#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); -#endif - - -#ifdef HAVE_STRLCPY #define SDL_strlcpy strlcpy -#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); -#ifdef HAVE_STRLCAT #define SDL_strlcat strlcat -#else -extern DECLSPEC size_t SDLCALL SDL_strlcat(char *dst, const char *src, - size_t maxlen); -#endif - -#ifdef HAVE_STRDUP #define SDL_strdup strdup -#else -extern DECLSPEC char *SDLCALL SDL_strdup(const char *string); -#endif - -#ifdef HAVE__STRREV -#define SDL_strrev _strrev -#else -extern DECLSPEC char *SDLCALL SDL_strrev(char *string); -#endif - -#ifdef HAVE__STRUPR -#define SDL_strupr _strupr -#else -extern DECLSPEC char *SDLCALL SDL_strupr(char *string); -#endif - -#ifdef HAVE__STRLWR -#define SDL_strlwr _strlwr -#else -extern DECLSPEC char *SDLCALL SDL_strlwr(char *string); -#endif - -#ifdef HAVE_STRCHR #define SDL_strchr strchr -#elif defined(HAVE_INDEX) -#define SDL_strchr index -#else -extern DECLSPEC char *SDLCALL SDL_strchr(const char *string, int c); -#endif - -#ifdef HAVE_STRRCHR #define SDL_strrchr strrchr -#elif defined(HAVE_RINDEX) -#define SDL_strrchr rindex -#else -extern DECLSPEC char *SDLCALL SDL_strrchr(const char *string, int c); -#endif - -#ifdef HAVE_STRSTR #define SDL_strstr strstr -#else -extern DECLSPEC char *SDLCALL SDL_strstr(const char *haystack, - const char *needle); -#endif - -#ifdef HAVE_ITOA -#define SDL_itoa itoa -#else -#define SDL_itoa(value, string, radix) SDL_ltoa((long)value, string, radix) -#endif - -#ifdef HAVE__LTOA -#define SDL_ltoa _ltoa -#else -extern DECLSPEC char *SDLCALL SDL_ltoa(long value, char *string, int radix); -#endif - -#ifdef HAVE__UITOA -#define SDL_uitoa _uitoa -#else -#define SDL_uitoa(value, string, radix) SDL_ultoa((long)value, string, radix) -#endif - -#ifdef HAVE__ULTOA -#define SDL_ultoa _ultoa -#else -extern DECLSPEC char *SDLCALL SDL_ultoa(unsigned long value, char *string, - int radix); -#endif - -#ifdef HAVE_STRTOL #define SDL_strtol strtol -#else -extern DECLSPEC long SDLCALL SDL_strtol(const char *string, char **endp, - int base); -#endif - -#ifdef HAVE_STRTOUL #define SDL_strtoul strtoul -#else -extern DECLSPEC unsigned long SDLCALL SDL_strtoul(const char *string, - char **endp, int base); -#endif - -#ifdef HAVE__I64TOA -#define SDL_lltoa _i64toa -#else -extern DECLSPEC char *SDLCALL SDL_lltoa(Sint64 value, char *string, - int radix); -#endif - -#ifdef HAVE__UI64TOA -#define SDL_ulltoa _ui64toa -#else -extern DECLSPEC char *SDLCALL SDL_ulltoa(Uint64 value, char *string, - int radix); -#endif - -#ifdef HAVE_STRTOLL #define SDL_strtoll strtoll -#else -extern DECLSPEC Sint64 SDLCALL SDL_strtoll(const char *string, char **endp, - int base); -#endif - -#ifdef HAVE_STRTOULL #define SDL_strtoull strtoull -#else -extern DECLSPEC Uint64 SDLCALL SDL_strtoull(const char *string, char **endp, - int base); -#endif - -#ifdef HAVE_STRTOD #define SDL_strtod strtod -#else -extern DECLSPEC double SDLCALL SDL_strtod(const char *string, char **endp); -#endif - -#ifdef HAVE_ATOI #define SDL_atoi atoi -#else -#define SDL_atoi(X) SDL_strtol(X, NULL, 0) -#endif - -#ifdef HAVE_ATOF #define SDL_atof atof -#else -#define SDL_atof(X) SDL_strtod(X, NULL) -#endif - -#ifdef HAVE_STRCMP #define SDL_strcmp strcmp -#else -extern DECLSPEC int SDLCALL SDL_strcmp(const char *str1, const char *str2); -#endif - -#ifdef HAVE_STRNCMP #define SDL_strncmp strncmp -#else -extern DECLSPEC int SDLCALL SDL_strncmp(const char *str1, const char *str2, - size_t maxlen); -#endif - -#ifdef HAVE_STRCASECMP #define SDL_strcasecmp strcasecmp -#elif defined(HAVE__STRICMP) -#define SDL_strcasecmp _stricmp -#else -extern DECLSPEC int SDLCALL SDL_strcasecmp(const char *str1, - const char *str2); -#endif - -#ifdef HAVE_STRNCASECMP #define SDL_strncasecmp strncasecmp -#elif defined(HAVE__STRNICMP) -#define SDL_strncasecmp _strnicmp -#else -extern DECLSPEC int SDLCALL SDL_strncasecmp(const char *str1, - const char *str2, size_t maxlen); -#endif - -#ifdef HAVE_SSCANF #define SDL_sscanf sscanf -#else -extern DECLSPEC int SDLCALL SDL_sscanf(const char *text, const char *fmt, - ...); -#endif - -#ifdef HAVE_SNPRINTF #define SDL_snprintf snprintf -#else -extern DECLSPEC int SDLCALL SDL_snprintf(char *text, size_t maxlen, - const char *fmt, ...); -#endif - -#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); -#endif - -#ifndef HAVE_M_PI -#define M_PI 3.14159265358979323846264338327950288 /* pi */ -#endif - -#ifdef HAVE_ATAN #define SDL_atan atan -#else -extern DECLSPEC double SDLCALL SDL_atan(double x); -#endif - -#ifdef HAVE_ATAN2 #define SDL_atan2 atan2 -#else -extern DECLSPEC double SDLCALL SDL_atan2(double y, double x); -#endif - -#ifdef HAVE_CEIL #define SDL_ceil ceil -#else -#define SDL_ceil(x) ((double)(int)((x)+0.5)) -#endif - -#ifdef HAVE_COPYSIGN #define SDL_copysign copysign -#else -extern DECLSPEC double SDLCALL SDL_copysign(double x, double y); -#endif - -#ifdef HAVE_COS #define SDL_cos cos -#else -extern DECLSPEC double SDLCALL SDL_cos(double x); -#endif - -#ifdef HAVE_COSF #define SDL_cosf cosf -#else -#define SDL_cosf(x) (float)SDL_cos((double)x) -#endif - -#ifdef HAVE_FABS #define SDL_fabs fabs -#else -extern DECLSPEC double SDLCALL SDL_fabs(double x); -#endif - -#ifdef HAVE_FLOOR #define SDL_floor floor -#else -extern DECLSPEC double SDLCALL SDL_floor(double x); -#endif - -#ifdef HAVE_LOG #define SDL_log log -#else -extern DECLSPEC double SDLCALL SDL_log(double x); -#endif - -#ifdef HAVE_POW #define SDL_pow pow -#else -extern DECLSPEC double SDLCALL SDL_pow(double x, double y); -#endif - -#ifdef HAVE_SCALBN #define SDL_scalbn scalbn -#else -extern DECLSPEC double SDLCALL SDL_scalbn(double x, int n); -#endif - -#ifdef HAVE_SIN #define SDL_sin sin -#else -extern DECLSPEC double SDLCALL SDL_sin(double x); -#endif - -#ifdef HAVE_SINF #define SDL_sinf sinf -#else -#define SDL_sinf(x) (float)SDL_sin((double)x) -#endif - -#ifdef HAVE_SQRT #define SDL_sqrt sqrt -#else -extern DECLSPEC double SDLCALL SDL_sqrt(double x); -#endif /* The SDL implementation of iconv() returns these error codes */ #define SDL_ICONV_ERROR (size_t)-1 diff --git a/src/SDL-mobile/src/SDL.c b/src/SDL-mobile/src/SDL.c index 236cb5cb8..49a8d3928 100644 --- a/src/SDL-mobile/src/SDL.c +++ b/src/SDL-mobile/src/SDL.c @@ -26,7 +26,6 @@ #include "SDL_revision.h" #include "SDL_fatal.h" #include "SDL_assert_c.h" -#include "haptic/SDL_haptic_c.h" #include "joystick/SDL_joystick_c.h" /* Initialization/Cleanup routines */ @@ -113,20 +112,6 @@ SDL_InitSubSystem(Uint32 flags) } #endif -#if !SDL_HAPTIC_DISABLED - /* Initialize the haptic subsystem */ - if ((flags & SDL_INIT_HAPTIC) && !(SDL_initialized & SDL_INIT_HAPTIC)) { - if (SDL_HapticInit() < 0) { - return (-1); - } - SDL_initialized |= SDL_INIT_HAPTIC; - } -#else - if (flags & SDL_INIT_HAPTIC) { - SDL_SetError("SDL not built with haptic (force feedback) support"); - return (-1); - } -#endif return (0); } @@ -169,12 +154,6 @@ SDL_QuitSubSystem(Uint32 flags) SDL_initialized &= ~SDL_INIT_JOYSTICK; } #endif -#if !SDL_HAPTIC_DISABLED - if ((flags & SDL_initialized & SDL_INIT_HAPTIC)) { - SDL_HapticQuit(); - SDL_initialized &= ~SDL_INIT_HAPTIC; - } -#endif #if !SDL_AUDIO_DISABLED if ((flags & SDL_initialized & SDL_INIT_AUDIO)) { SDL_AudioQuit(); diff --git a/src/SDL-mobile/src/SDL_fatal.c b/src/SDL-mobile/src/SDL_fatal.c index f68787e68..24142e7cb 100644 --- a/src/SDL-mobile/src/SDL_fatal.c +++ b/src/SDL-mobile/src/SDL_fatal.c @@ -61,7 +61,7 @@ SDL_InstallParachute(void) { /* Set a handler for any fatal signal not already handled */ int i; -#ifdef HAVE_SIGACTION + struct sigaction action; for (i = 0; SDL_fatal_signals[i]; ++i) { @@ -79,16 +79,7 @@ SDL_InstallParachute(void) sigaction(SIGALRM, &action, NULL); } #endif -#else - void (*ohandler) (int); - for (i = 0; SDL_fatal_signals[i]; ++i) { - ohandler = signal(SDL_fatal_signals[i], SDL_Parachute); - if (ohandler != SIG_DFL) { - signal(SDL_fatal_signals[i], ohandler); - } - } -#endif /* HAVE_SIGACTION */ return; } @@ -97,7 +88,7 @@ SDL_UninstallParachute(void) { /* Remove a handler for any fatal signal handled */ int i; -#ifdef HAVE_SIGACTION + struct sigaction action; for (i = 0; SDL_fatal_signals[i]; ++i) { @@ -107,16 +98,6 @@ SDL_UninstallParachute(void) sigaction(SDL_fatal_signals[i], &action, NULL); } } -#else - void (*ohandler) (int); - - for (i = 0; SDL_fatal_signals[i]; ++i) { - ohandler = signal(SDL_fatal_signals[i], SIG_DFL); - if (ohandler != SDL_Parachute) { - signal(SDL_fatal_signals[i], ohandler); - } - } -#endif /* HAVE_SIGACTION */ } #else diff --git a/src/SDL-mobile/src/events/SDL_quit.c b/src/SDL-mobile/src/events/SDL_quit.c index f65f69c1a..bad19af43 100644 --- a/src/SDL-mobile/src/events/SDL_quit.c +++ b/src/SDL-mobile/src/events/SDL_quit.c @@ -46,7 +46,6 @@ SDL_HandleSIG(int sig) int SDL_QuitInit(void) { -#ifdef HAVE_SIGACTION struct sigaction action; sigaction(SIGINT, NULL, &action); #ifdef HAVE_SA_SIGACTION @@ -67,17 +66,6 @@ SDL_QuitInit(void) action.sa_handler = SDL_HandleSIG; sigaction(SIGTERM, &action, NULL); } -#elif HAVE_SIGNAL_H - void (*ohandler) (int); - - /* Both SIGINT and SIGTERM are translated into quit interrupts */ - ohandler = signal(SIGINT, SDL_HandleSIG); - if (ohandler != SIG_DFL) - signal(SIGINT, ohandler); - ohandler = signal(SIGTERM, SDL_HandleSIG); - if (ohandler != SIG_DFL) - signal(SIGTERM, ohandler); -#endif /* HAVE_SIGNAL_H */ /* That's it! */ return (0); @@ -86,7 +74,6 @@ SDL_QuitInit(void) void SDL_QuitQuit(void) { -#ifdef HAVE_SIGACTION struct sigaction action; sigaction(SIGINT, NULL, &action); if ( action.sa_handler == SDL_HandleSIG ) { @@ -98,16 +85,6 @@ SDL_QuitQuit(void) action.sa_handler = SIG_DFL; sigaction(SIGTERM, &action, NULL); } -#elif HAVE_SIGNAL_H - void (*ohandler) (int); - - ohandler = signal(SIGINT, SIG_DFL); - if (ohandler != SDL_HandleSIG) - signal(SIGINT, ohandler); - ohandler = signal(SIGTERM, SIG_DFL); - if (ohandler != SDL_HandleSIG) - signal(SIGTERM, ohandler); -#endif /* HAVE_SIGNAL_H */ } /* This function returns 1 if it's okay to close the application window */ diff --git a/src/SDL-mobile/src/haptic/SDL_haptic.c b/src/SDL-mobile/src/haptic/SDL_haptic.c deleted file mode 100644 index ae2ccebfa..000000000 --- a/src/SDL-mobile/src/haptic/SDL_haptic.c +++ /dev/null @@ -1,815 +0,0 @@ -/* - Simple DirectMedia Layer - Copyright (C) 1997-2012 Sam Lantinga - - 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" - -#include "SDL_syshaptic.h" -#include "SDL_haptic_c.h" -#include "../joystick/SDL_joystick_c.h" /* For SDL_PrivateJoystickValid */ - - -Uint8 SDL_numhaptics = 0; -SDL_Haptic **SDL_haptics = NULL; - - -/* - * Initializes the Haptic devices. - */ -int -SDL_HapticInit(void) -{ - int arraylen; - int status; - - SDL_numhaptics = 0; - status = SDL_SYS_HapticInit(); - if (status >= 0) { - arraylen = (status + 1) * sizeof(*SDL_haptics); - SDL_haptics = (SDL_Haptic **) SDL_malloc(arraylen); - if (SDL_haptics == NULL) { /* Out of memory. */ - SDL_numhaptics = 0; - } else { - SDL_memset(SDL_haptics, 0, arraylen); - SDL_numhaptics = status; - } - status = 0; - } - - return status; -} - - -/* - * Checks to see if the haptic device is valid - */ -static int -ValidHaptic(SDL_Haptic * haptic) -{ - int i; - int valid; - - valid = 0; - if (haptic != NULL) { - for (i = 0; i < SDL_numhaptics; i++) { - if (SDL_haptics[i] == haptic) { - valid = 1; - break; - } - } - } - - /* Create the error here. */ - if (valid == 0) { - SDL_SetError("Haptic: Invalid haptic device identifier"); - } - - return valid; -} - - -/* - * Returns the number of available devices. - */ -int -SDL_NumHaptics(void) -{ - return SDL_numhaptics; -} - - -/* - * Gets the name of a Haptic device by index. - */ -const char * -SDL_HapticName(int device_index) -{ - if ((device_index < 0) || (device_index >= SDL_numhaptics)) { - SDL_SetError("Haptic: There are %d haptic devices available", - SDL_numhaptics); - return NULL; - } - return SDL_SYS_HapticName(device_index); -} - - -/* - * Opens a Haptic device. - */ -SDL_Haptic * -SDL_HapticOpen(int device_index) -{ - int i; - SDL_Haptic *haptic; - - if ((device_index < 0) || (device_index >= SDL_numhaptics)) { - SDL_SetError("Haptic: There are %d haptic devices available", - SDL_numhaptics); - return NULL; - } - - /* If the haptic is already open, return it */ - for (i = 0; SDL_haptics[i]; i++) { - if (device_index == SDL_haptics[i]->index) { - haptic = SDL_haptics[i]; - ++haptic->ref_count; - return haptic; - } - } - - /* Create the haptic device */ - haptic = (SDL_Haptic *) SDL_malloc((sizeof *haptic)); - if (haptic == NULL) { - SDL_OutOfMemory(); - return NULL; - } - - /* Initialize the haptic device */ - SDL_memset(haptic, 0, (sizeof *haptic)); - haptic->rumble_id = -1; - haptic->index = device_index; - if (SDL_SYS_HapticOpen(haptic) < 0) { - SDL_free(haptic); - return NULL; - } - - /* Disable autocenter and set gain to max. */ - if (haptic->supported & SDL_HAPTIC_GAIN) - SDL_HapticSetGain(haptic, 100); - if (haptic->supported & SDL_HAPTIC_AUTOCENTER) - SDL_HapticSetAutocenter(haptic, 0); - - /* Add haptic to list */ - ++haptic->ref_count; - for (i = 0; SDL_haptics[i]; i++) - /* Skip to next haptic */ ; - SDL_haptics[i] = haptic; - - return haptic; -} - - -/* - * Returns 1 if the device has been opened. - */ -int -SDL_HapticOpened(int device_index) -{ - int i, opened; - - opened = 0; - for (i = 0; SDL_haptics[i]; i++) { - if (SDL_haptics[i]->index == (Uint8) device_index) { - opened = 1; - break; - } - } - return opened; -} - - -/* - * Returns the index to a haptic device. - */ -int -SDL_HapticIndex(SDL_Haptic * haptic) -{ - if (!ValidHaptic(haptic)) { - return -1; - } - - return haptic->index; -} - - -/* - * Returns SDL_TRUE if mouse is haptic, SDL_FALSE if it isn't. - */ -int -SDL_MouseIsHaptic(void) -{ - if (SDL_SYS_HapticMouse() < 0) - return SDL_FALSE; - return SDL_TRUE; -} - - -/* - * Returns the haptic device if mouse is haptic or NULL elsewise. - */ -SDL_Haptic * -SDL_HapticOpenFromMouse(void) -{ - int device_index; - - device_index = SDL_SYS_HapticMouse(); - - if (device_index < 0) { - SDL_SetError("Haptic: Mouse isn't a haptic device."); - return NULL; - } - - return SDL_HapticOpen(device_index); -} - - -/* - * Returns SDL_TRUE if joystick has haptic features. - */ -int -SDL_JoystickIsHaptic(SDL_Joystick * joystick) -{ - int ret; - - /* Must be a valid joystick */ - if (!SDL_PrivateJoystickValid(&joystick)) { - return -1; - } - - ret = SDL_SYS_JoystickIsHaptic(joystick); - - if (ret > 0) - return SDL_TRUE; - else if (ret == 0) - return SDL_FALSE; - else - return -1; -} - - -/* - * Opens a haptic device from a joystick. - */ -SDL_Haptic * -SDL_HapticOpenFromJoystick(SDL_Joystick * joystick) -{ - int i; - SDL_Haptic *haptic; - - /* Must be a valid joystick */ - if (!SDL_PrivateJoystickValid(&joystick)) { - SDL_SetError("Haptic: Joystick isn't valid."); - return NULL; - } - - /* Joystick must be haptic */ - if (SDL_SYS_JoystickIsHaptic(joystick) <= 0) { - SDL_SetError("Haptic: Joystick isn't a haptic device."); - return NULL; - } - - /* Check to see if joystick's haptic is already open */ - for (i = 0; SDL_haptics[i]; i++) { - if (SDL_SYS_JoystickSameHaptic(SDL_haptics[i], joystick)) { - haptic = SDL_haptics[i]; - ++haptic->ref_count; - return haptic; - } - } - - /* Create the haptic device */ - haptic = (SDL_Haptic *) SDL_malloc((sizeof *haptic)); - if (haptic == NULL) { - SDL_OutOfMemory(); - return NULL; - } - - /* Initialize the haptic device */ - SDL_memset(haptic, 0, sizeof(SDL_Haptic)); - haptic->rumble_id = -1; - if (SDL_SYS_HapticOpenFromJoystick(haptic, joystick) < 0) { - SDL_free(haptic); - return NULL; - } - - /* Add haptic to list */ - ++haptic->ref_count; - for (i = 0; SDL_haptics[i]; i++) - /* Skip to next haptic */ ; - SDL_haptics[i] = haptic; - - return haptic; -} - - -/* - * Closes a SDL_Haptic device. - */ -void -SDL_HapticClose(SDL_Haptic * haptic) -{ - int i; - - /* Must be valid */ - if (!ValidHaptic(haptic)) { - return; - } - - /* Check if it's still in use */ - if (--haptic->ref_count < 0) { - return; - } - - /* Close it, properly removing effects if needed */ - for (i = 0; i < haptic->neffects; i++) { - if (haptic->effects[i].hweffect != NULL) { - SDL_HapticDestroyEffect(haptic, i); - } - } - SDL_SYS_HapticClose(haptic); - - /* Remove from the list */ - for (i = 0; SDL_haptics[i]; ++i) { - if (haptic == SDL_haptics[i]) { - SDL_haptics[i] = NULL; - SDL_memcpy(&SDL_haptics[i], &SDL_haptics[i + 1], - (SDL_numhaptics - i) * sizeof(haptic)); - break; - } - } - - /* Free */ - SDL_free(haptic); -} - -/* - * Cleans up after the subsystem. - */ -void -SDL_HapticQuit(void) -{ - SDL_SYS_HapticQuit(); - if (SDL_haptics != NULL) { - SDL_free(SDL_haptics); - SDL_haptics = NULL; - } - SDL_numhaptics = 0; -} - -/* - * Returns the number of effects a haptic device has. - */ -int -SDL_HapticNumEffects(SDL_Haptic * haptic) -{ - if (!ValidHaptic(haptic)) { - return -1; - } - - return haptic->neffects; -} - - -/* - * Returns the number of effects a haptic device can play. - */ -int -SDL_HapticNumEffectsPlaying(SDL_Haptic * haptic) -{ - if (!ValidHaptic(haptic)) { - return -1; - } - - return haptic->nplaying; -} - - -/* - * Returns supported effects by the device. - */ -unsigned int -SDL_HapticQuery(SDL_Haptic * haptic) -{ - if (!ValidHaptic(haptic)) { - return -1; - } - - return haptic->supported; -} - - -/* - * Returns the number of axis on the device. - */ -int -SDL_HapticNumAxes(SDL_Haptic * haptic) -{ - if (!ValidHaptic(haptic)) { - return -1; - } - - return haptic->naxes; -} - -/* - * Checks to see if the device can support the effect. - */ -int -SDL_HapticEffectSupported(SDL_Haptic * haptic, SDL_HapticEffect * effect) -{ - if (!ValidHaptic(haptic)) { - return -1; - } - - if ((haptic->supported & effect->type) != 0) - return SDL_TRUE; - return SDL_FALSE; -} - -/* - * Creates a new haptic effect. - */ -int -SDL_HapticNewEffect(SDL_Haptic * haptic, SDL_HapticEffect * effect) -{ - int i; - - /* Check for device validity. */ - if (!ValidHaptic(haptic)) { - return -1; - } - - /* 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; - } - - /* See if there's a free slot */ - for (i = 0; i < haptic->neffects; i++) { - if (haptic->effects[i].hweffect == NULL) { - - /* Now let the backend create the real effect */ - if (SDL_SYS_HapticNewEffect(haptic, &haptic->effects[i], effect) - != 0) { - return -1; /* Backend failed to create effect */ - } - - SDL_memcpy(&haptic->effects[i].effect, effect, - sizeof(SDL_HapticEffect)); - return i; - } - } - - SDL_SetError("Haptic: Device has no free space left."); - return -1; -} - -/* - * Checks to see if an effect is valid. - */ -static int -ValidEffect(SDL_Haptic * haptic, int effect) -{ - if ((effect < 0) || (effect >= haptic->neffects)) { - SDL_SetError("Haptic: Invalid effect identifier."); - return 0; - } - return 1; -} - -/* - * Updates an effect. - */ -int -SDL_HapticUpdateEffect(SDL_Haptic * haptic, int effect, - SDL_HapticEffect * data) -{ - if (!ValidHaptic(haptic) || !ValidEffect(haptic, effect)) { - return -1; - } - - /* Can't change type dynamically. */ - if (data->type != haptic->effects[effect].effect.type) { - SDL_SetError("Haptic: Updating effect type is illegal."); - return -1; - } - - /* Updates the effect */ - if (SDL_SYS_HapticUpdateEffect(haptic, &haptic->effects[effect], data) < - 0) { - return -1; - } - - SDL_memcpy(&haptic->effects[effect].effect, data, - sizeof(SDL_HapticEffect)); - return 0; -} - - -/* - * Runs the haptic effect on the device. - */ -int -SDL_HapticRunEffect(SDL_Haptic * haptic, int effect, Uint32 iterations) -{ - if (!ValidHaptic(haptic) || !ValidEffect(haptic, effect)) { - return -1; - } - - /* Run the effect */ - if (SDL_SYS_HapticRunEffect(haptic, &haptic->effects[effect], iterations) - < 0) { - return -1; - } - - return 0; -} - -/* - * Stops the haptic effect on the device. - */ -int -SDL_HapticStopEffect(SDL_Haptic * haptic, int effect) -{ - if (!ValidHaptic(haptic) || !ValidEffect(haptic, effect)) { - return -1; - } - - /* Stop the effect */ - if (SDL_SYS_HapticStopEffect(haptic, &haptic->effects[effect]) < 0) { - return -1; - } - - return 0; -} - -/* - * Gets rid of a haptic effect. - */ -void -SDL_HapticDestroyEffect(SDL_Haptic * haptic, int effect) -{ - if (!ValidHaptic(haptic) || !ValidEffect(haptic, effect)) { - return; - } - - /* Not allocated */ - if (haptic->effects[effect].hweffect == NULL) { - return; - } - - SDL_SYS_HapticDestroyEffect(haptic, &haptic->effects[effect]); -} - -/* - * Gets the status of a haptic effect. - */ -int -SDL_HapticGetEffectStatus(SDL_Haptic * haptic, int effect) -{ - if (!ValidHaptic(haptic) || !ValidEffect(haptic, effect)) { - return -1; - } - - if ((haptic->supported & SDL_HAPTIC_STATUS) == 0) { - SDL_SetError("Haptic: Device does not support status queries."); - return -1; - } - - return SDL_SYS_HapticGetEffectStatus(haptic, &haptic->effects[effect]); -} - -/* - * Sets the global gain of the device. - */ -int -SDL_HapticSetGain(SDL_Haptic * haptic, int gain) -{ - const char *env; - int real_gain, max_gain; - - if (!ValidHaptic(haptic)) { - return -1; - } - - if ((haptic->supported & SDL_HAPTIC_GAIN) == 0) { - SDL_SetError("Haptic: Device does not support setting gain."); - return -1; - } - - if ((gain < 0) || (gain > 100)) { - SDL_SetError("Haptic: Gain must be between 0 and 100."); - return -1; - } - - /* We use the envvar to get the maximum gain. */ - env = SDL_getenv("SDL_HAPTIC_GAIN_MAX"); - if (env != NULL) { - max_gain = SDL_atoi(env); - - /* Check for sanity. */ - if (max_gain < 0) - max_gain = 0; - else if (max_gain > 100) - max_gain = 100; - - /* We'll scale it linearly with SDL_HAPTIC_GAIN_MAX */ - real_gain = (gain * max_gain) / 100; - } else { - real_gain = gain; - } - - if (SDL_SYS_HapticSetGain(haptic, real_gain) < 0) { - return -1; - } - - return 0; -} - -/* - * Makes the device autocenter, 0 disables. - */ -int -SDL_HapticSetAutocenter(SDL_Haptic * haptic, int autocenter) -{ - if (!ValidHaptic(haptic)) { - return -1; - } - - if ((haptic->supported & SDL_HAPTIC_AUTOCENTER) == 0) { - SDL_SetError("Haptic: Device does not support setting autocenter."); - return -1; - } - - if ((autocenter < 0) || (autocenter > 100)) { - SDL_SetError("Haptic: Autocenter must be between 0 and 100."); - return -1; - } - - if (SDL_SYS_HapticSetAutocenter(haptic, autocenter) < 0) { - return -1; - } - - return 0; -} - -/* - * Pauses the haptic device. - */ -int -SDL_HapticPause(SDL_Haptic * haptic) -{ - if (!ValidHaptic(haptic)) { - return -1; - } - - if ((haptic->supported & SDL_HAPTIC_PAUSE) == 0) { - SDL_SetError("Haptic: Device does not support setting pausing."); - return -1; - } - - return SDL_SYS_HapticPause(haptic); -} - -/* - * Unpauses the haptic device. - */ -int -SDL_HapticUnpause(SDL_Haptic * haptic) -{ - if (!ValidHaptic(haptic)) { - return -1; - } - - if ((haptic->supported & SDL_HAPTIC_PAUSE) == 0) { - return 0; /* Not going to be paused, so we pretend it's unpaused. */ - } - - return SDL_SYS_HapticUnpause(haptic); -} - -/* - * Stops all the currently playing effects. - */ -int -SDL_HapticStopAll(SDL_Haptic * haptic) -{ - if (!ValidHaptic(haptic)) { - return -1; - } - - return SDL_SYS_HapticStopAll(haptic); -} - -static void -SDL_HapticRumbleCreate(SDL_HapticEffect * efx) -{ - SDL_memset(efx, 0, sizeof(SDL_HapticEffect)); - efx->type = SDL_HAPTIC_SINE; - efx->periodic.period = 1000; - efx->periodic.magnitude = 0x4000; - efx->periodic.length = 5000; - efx->periodic.attack_length = 0; - efx->periodic.fade_length = 0; -} - -/* - * Checks to see if rumble is supported. - */ -int -SDL_HapticRumbleSupported(SDL_Haptic * haptic) -{ - SDL_HapticEffect efx; - - if (!ValidHaptic(haptic)) { - return -1; - } - - SDL_HapticRumbleCreate(&efx); - return SDL_HapticEffectSupported(haptic, &efx); -} - -/* - * Initializes the haptic device for simple rumble playback. - */ -int -SDL_HapticRumbleInit(SDL_Haptic * haptic) -{ - if (!ValidHaptic(haptic)) { - return -1; - } - - /* Already allocated. */ - if (haptic->rumble_id >= 0) { - return 0; - } - - /* Copy over. */ - SDL_HapticRumbleCreate(&haptic->rumble_effect); - haptic->rumble_id = SDL_HapticNewEffect(haptic, &haptic->rumble_effect); - if (haptic->rumble_id >= 0) { - return 0; - } - return -1; -} - -/* - * Runs simple rumble on a haptic device - */ -int -SDL_HapticRumblePlay(SDL_Haptic * haptic, float strength, Uint32 length) -{ - SDL_HapticPeriodic *efx; - - if (!ValidHaptic(haptic)) { - return -1; - } - - if (haptic->rumble_id < 0) { - SDL_SetError("Haptic: Rumble effect not initialized on haptic device"); - return -1; - } - - /* Clamp strength. */ - if (strength > 1.0f) { - strength = 1.0f; - } - else if (strength < 0.0f) { - strength = 0.0f; - } - - /* New effect. */ - efx = &haptic->rumble_effect.periodic; - efx->magnitude = (Sint16)(32767.0f*strength); - efx->length = length; - SDL_HapticUpdateEffect(haptic, haptic->rumble_id, &haptic->rumble_effect); - - return SDL_HapticRunEffect(haptic, haptic->rumble_id, 1); -} - -/* - * Stops the simple rumble on a haptic device. - */ -int -SDL_HapticRumbleStop(SDL_Haptic * haptic) -{ - if (!ValidHaptic(haptic)) { - return -1; - } - - if (haptic->rumble_id < 0) { - SDL_SetError("Haptic: Rumble effect not initialized on haptic device"); - return -1; - } - - return SDL_HapticStopEffect(haptic, haptic->rumble_id); -} - - diff --git a/src/SDL-mobile/src/haptic/SDL_haptic_c.h b/src/SDL-mobile/src/haptic/SDL_haptic_c.h deleted file mode 100644 index b937a2c9a..000000000 --- a/src/SDL-mobile/src/haptic/SDL_haptic_c.h +++ /dev/null @@ -1,25 +0,0 @@ -/* - Simple DirectMedia Layer - Copyright (C) 1997-2012 Sam Lantinga - - 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. -*/ - -extern int SDL_HapticInit(void); -extern void SDL_HapticQuit(void); - -/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/SDL-mobile/src/haptic/SDL_syshaptic.h b/src/SDL-mobile/src/haptic/SDL_syshaptic.h deleted file mode 100644 index 53871928f..000000000 --- a/src/SDL-mobile/src/haptic/SDL_syshaptic.h +++ /dev/null @@ -1,203 +0,0 @@ -/* - Simple DirectMedia Layer - Copyright (C) 1997-2012 Sam Lantinga - - 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" - -#include "SDL_haptic.h" - - -/* - * Number of haptic devices on the system. - */ -extern Uint8 SDL_numhaptics; - - -struct haptic_effect -{ - SDL_HapticEffect effect; /* The current event */ - struct haptic_hweffect *hweffect; /* The hardware behind the event */ -}; - -/* - * The real SDL_Haptic struct. - */ -struct _SDL_Haptic -{ - Uint8 index; /* Stores index it is attached to */ - - struct haptic_effect *effects; /* Allocated effects */ - int neffects; /* Maximum amount of effects */ - int nplaying; /* Maximum amount of effects to play at the same time */ - unsigned int supported; /* Supported effects */ - int naxes; /* Number of axes on the device. */ - - struct haptic_hwdata *hwdata; /* Driver dependent */ - int ref_count; /* Count for multiple opens */ - - int rumble_id; /* ID of rumble effect for simple rumble API. */ - SDL_HapticEffect rumble_effect; /* Rumble effect. */ -}; - -/* - * Scans the system for haptic devices. - * - * Returns 0 on success, -1 on error. - */ -extern int SDL_SYS_HapticInit(void); - -/* - * Gets the device dependent name of the haptic device - */ -extern const char *SDL_SYS_HapticName(int index); - -/* - * Opens the haptic device for usage. The haptic device should have - * the index value set previously. - * - * Returns 0 on success, -1 on error. - */ -extern int SDL_SYS_HapticOpen(SDL_Haptic * haptic); - -/* - * Returns the index of the haptic core pointer or -1 if none is found. - */ -int SDL_SYS_HapticMouse(void); - -/* - * Checks to see if the joystick has haptic capabilities. - * - * Returns >0 if haptic capabilities are detected, 0 if haptic - * capabilities aren't detected and -1 on error. - */ -extern int SDL_SYS_JoystickIsHaptic(SDL_Joystick * joystick); - -/* - * Opens the haptic device for usage using the same device as - * the joystick. - * - * Returns 0 on success, -1 on error. - */ -extern int SDL_SYS_HapticOpenFromJoystick(SDL_Haptic * haptic, - SDL_Joystick * joystick); -/* - * Checks to see if haptic device and joystick device are the same. - * - * Returns 1 if they are the same, 0 if they aren't. - */ -extern int SDL_SYS_JoystickSameHaptic(SDL_Haptic * haptic, - SDL_Joystick * joystick); - -/* - * Closes a haptic device after usage. - */ -extern void SDL_SYS_HapticClose(SDL_Haptic * haptic); - -/* - * Performs a cleanup on the haptic subsystem. - */ -extern void SDL_SYS_HapticQuit(void); - -/* - * Creates a new haptic effect on the haptic device using base - * as a template for the effect. - * - * Returns 0 on success, -1 on error. - */ -extern int SDL_SYS_HapticNewEffect(SDL_Haptic * haptic, - struct haptic_effect *effect, - SDL_HapticEffect * base); - -/* - * Updates the haptic effect on the haptic device using data - * as a template. - * - * Returns 0 on success, -1 on error. - */ -extern int SDL_SYS_HapticUpdateEffect(SDL_Haptic * haptic, - struct haptic_effect *effect, - SDL_HapticEffect * data); - -/* - * Runs the effect on the haptic device. - * - * Returns 0 on success, -1 on error. - */ -extern int SDL_SYS_HapticRunEffect(SDL_Haptic * haptic, - struct haptic_effect *effect, - Uint32 iterations); - -/* - * Stops the effect on the haptic device. - * - * Returns 0 on success, -1 on error. - */ -extern int SDL_SYS_HapticStopEffect(SDL_Haptic * haptic, - struct haptic_effect *effect); - -/* - * Cleanups up the effect on the haptic device. - */ -extern void SDL_SYS_HapticDestroyEffect(SDL_Haptic * haptic, - struct haptic_effect *effect); - -/* - * Queries the device for the status of effect. - * - * Returns 0 if device is stopped, >0 if device is playing and - * -1 on error. - */ -extern int SDL_SYS_HapticGetEffectStatus(SDL_Haptic * haptic, - struct haptic_effect *effect); - -/* - * Sets the global gain of the haptic device. - * - * Returns 0 on success, -1 on error. - */ -extern int SDL_SYS_HapticSetGain(SDL_Haptic * haptic, int gain); - -/* - * Sets the autocenter feature of the haptic device. - * - * Returns 0 on success, -1 on error. - */ -extern int SDL_SYS_HapticSetAutocenter(SDL_Haptic * haptic, int autocenter); - -/* - * Pauses the haptic device. - * - * Returns 0 on success, -1 on error. - */ -extern int SDL_SYS_HapticPause(SDL_Haptic * haptic); - -/* - * Unpauses the haptic device. - * - * Returns 0 on success, -1 on error. - */ -extern int SDL_SYS_HapticUnpause(SDL_Haptic * haptic); - -/* - * Stops all the currently playing haptic effects on the device. - * - * Returns 0 on success, -1 on error. - */ -extern int SDL_SYS_HapticStopAll(SDL_Haptic * haptic); diff --git a/src/SDL-mobile/src/haptic/dummy/SDL_syshaptic.c b/src/SDL-mobile/src/haptic/dummy/SDL_syshaptic.c deleted file mode 100644 index 1d6eade16..000000000 --- a/src/SDL-mobile/src/haptic/dummy/SDL_syshaptic.c +++ /dev/null @@ -1,194 +0,0 @@ -/* - Simple DirectMedia Layer - Copyright (C) 1997-2012 Sam Lantinga - - 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 defined(SDL_HAPTIC_DUMMY) || defined(SDL_HAPTIC_DISABLED) - -#include "SDL_haptic.h" -#include "../SDL_syshaptic.h" - - -static int -SDL_SYS_LogicError(void) -{ - SDL_SetError("Logic error: No haptic devices available."); - return 0; -} - - -int -SDL_SYS_HapticInit(void) -{ - return 0; -} - - -const char * -SDL_SYS_HapticName(int index) -{ - SDL_SYS_LogicError(); - return NULL; -} - - -int -SDL_SYS_HapticOpen(SDL_Haptic * haptic) -{ - SDL_SYS_LogicError(); - return -1; -} - - -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_DUMMY || SDL_HAPTIC_DISABLED */ diff --git a/src/SDL-mobile/src/render/SDL_render.c b/src/SDL-mobile/src/render/SDL_render.c index c810e967f..56ce95b50 100644 --- a/src/SDL-mobile/src/render/SDL_render.c +++ b/src/SDL-mobile/src/render/SDL_render.c @@ -26,7 +26,6 @@ #include "SDL_log.h" #include "SDL_render.h" #include "SDL_sysrender.h" -#include "software/SDL_render_sw_c.h" #define SDL_WINDOWRENDERDATA "_SDL_WindowRenderData" @@ -45,27 +44,7 @@ static const SDL_RenderDriver *render_drivers[] = { -#if !SDL_RENDER_DISABLED -#if SDL_VIDEO_RENDER_D3D - &D3D_RenderDriver, -#endif -#if SDL_VIDEO_RENDER_OGL - &GL_RenderDriver, -#endif -#if SDL_VIDEO_RENDER_OGL_ES2 - &GLES2_RenderDriver, -#endif -#if SDL_VIDEO_RENDER_OGL_ES - &GLES_RenderDriver, -#endif -#if SDL_VIDEO_RENDER_DIRECTFB - &DirectFB_RenderDriver, -#endif -#if SDL_VIDEO_RENDER_NDS - &NDS_RenderDriver, -#endif - &SW_RenderDriver -#endif /* !SDL_RENDER_DISABLED */ + }; static char renderer_magic; static char texture_magic; @@ -394,11 +373,7 @@ SDL_CreateTexture(SDL_Renderer * renderer, Uint32 format, int access, int w, int } if (SDL_ISPIXELFORMAT_FOURCC(texture->format)) { - texture->yuv = SDL_SW_CreateYUVTexture(format, w, h); - if (!texture->yuv) { - SDL_DestroyTexture(texture); - return NULL; - } + return NULL; } else if (access == SDL_TEXTUREACCESS_STREAMING) { /* The pitch is 4 byte aligned */ texture->pitch = (((w * SDL_BYTESPERPIXEL(format)) + 3) & ~3); @@ -623,53 +598,6 @@ SDL_GetTextureBlendMode(SDL_Texture * texture, SDL_BlendMode *blendMode) return 0; } -static int -SDL_UpdateTextureYUV(SDL_Texture * texture, const SDL_Rect * rect, - const void *pixels, int pitch) -{ - SDL_Texture *native = texture->native; - SDL_Rect full_rect; - - if (SDL_SW_UpdateYUVTexture(texture->yuv, rect, pixels, pitch) < 0) { - return -1; - } - - full_rect.x = 0; - full_rect.y = 0; - full_rect.w = texture->w; - full_rect.h = texture->h; - rect = &full_rect; - - if (texture->access == SDL_TEXTUREACCESS_STREAMING) { - /* We can lock the texture and copy to it */ - void *native_pixels; - int native_pitch; - - if (SDL_LockTexture(native, rect, &native_pixels, &native_pitch) < 0) { - return -1; - } - SDL_SW_CopyYUVToRGB(texture->yuv, rect, native->format, - rect->w, rect->h, native_pixels, native_pitch); - SDL_UnlockTexture(native); - } else { - /* Use a temporary buffer for updating */ - void *temp_pixels; - int temp_pitch; - - 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; - } - SDL_SW_CopyYUVToRGB(texture->yuv, rect, native->format, - rect->w, rect->h, temp_pixels, temp_pitch); - SDL_UpdateTexture(native, rect, temp_pixels, temp_pitch); - SDL_free(temp_pixels); - } - return 0; -} - static int SDL_UpdateTextureNative(SDL_Texture * texture, const SDL_Rect * rect, const void *pixels, int pitch) @@ -725,9 +653,7 @@ SDL_UpdateTexture(SDL_Texture * texture, const SDL_Rect * rect, rect = &full_rect; } - if (texture->yuv) { - return SDL_UpdateTextureYUV(texture, rect, pixels, pitch); - } else if (texture->native) { + if (texture->native) { return SDL_UpdateTextureNative(texture, rect, pixels, pitch); } else { renderer = texture->renderer; @@ -735,13 +661,6 @@ SDL_UpdateTexture(SDL_Texture * texture, const SDL_Rect * rect, } } -static int -SDL_LockTextureYUV(SDL_Texture * texture, const SDL_Rect * rect, - void **pixels, int *pitch) -{ - return SDL_SW_LockYUVTexture(texture->yuv, rect, pixels, pitch); -} - static int SDL_LockTextureNative(SDL_Texture * texture, const SDL_Rect * rect, void **pixels, int *pitch) @@ -776,9 +695,7 @@ SDL_LockTexture(SDL_Texture * texture, const SDL_Rect * rect, rect = &full_rect; } - if (texture->yuv) { - return SDL_LockTextureYUV(texture, rect, pixels, pitch); - } else if (texture->native) { + if (texture->native) { return SDL_LockTextureNative(texture, rect, pixels, pitch); } else { renderer = texture->renderer; @@ -786,26 +703,6 @@ SDL_LockTexture(SDL_Texture * texture, const SDL_Rect * rect, } } -static void -SDL_UnlockTextureYUV(SDL_Texture * texture) -{ - SDL_Texture *native = texture->native; - void *native_pixels; - int native_pitch; - SDL_Rect rect; - - rect.x = 0; - rect.y = 0; - rect.w = texture->w; - rect.h = texture->h; - - if (SDL_LockTexture(native, &rect, &native_pixels, &native_pitch) < 0) { - return; - } - SDL_SW_CopyYUVToRGB(texture->yuv, &rect, native->format, - rect.w, rect.h, native_pixels, native_pitch); - SDL_UnlockTexture(native); -} static void SDL_UnlockTextureNative(SDL_Texture * texture) @@ -838,9 +735,8 @@ SDL_UnlockTexture(SDL_Texture * texture) if (texture->access != SDL_TEXTUREACCESS_STREAMING) { return; } - if (texture->yuv) { - SDL_UnlockTextureYUV(texture); - } else if (texture->native) { + + if (texture->native) { SDL_UnlockTextureNative(texture); } else { renderer = texture->renderer; @@ -1246,7 +1142,7 @@ SDL_RenderCopyEx(SDL_Renderer * renderer, SDL_Texture * texture, SDL_SetError("Renderer does not support RenderCopyEx"); return -1; } - + real_srcrect.x = 0; real_srcrect.y = 0; real_srcrect.w = texture->w; @@ -1350,9 +1246,7 @@ SDL_DestroyTexture(SDL_Texture * texture) if (texture->native) { SDL_DestroyTexture(texture->native); } - if (texture->yuv) { - SDL_SW_DestroyYUVTexture(texture->yuv); - } + if (texture->pixels) { SDL_free(texture->pixels); } diff --git a/src/SDL-mobile/src/render/SDL_sysrender.h b/src/SDL-mobile/src/render/SDL_sysrender.h index 78a026261..ef6a33cdf 100644 --- a/src/SDL-mobile/src/render/SDL_sysrender.h +++ b/src/SDL-mobile/src/render/SDL_sysrender.h @@ -25,7 +25,6 @@ #include "SDL_render.h" #include "SDL_events.h" -#include "SDL_yuv_sw_c.h" /* The SDL 2D rendering system */ @@ -47,7 +46,6 @@ struct SDL_Texture /* Support for formats not supported directly by the renderer */ SDL_Texture *native; - SDL_SW_YUVTexture *yuv; void *pixels; int pitch; SDL_Rect locked_rect; diff --git a/src/SDL-mobile/src/render/SDL_yuv_mmx.c b/src/SDL-mobile/src/render/SDL_yuv_mmx.c deleted file mode 100644 index 9d50dd6af..000000000 --- a/src/SDL-mobile/src/render/SDL_yuv_mmx.c +++ /dev/null @@ -1,431 +0,0 @@ -/* - Simple DirectMedia Layer - Copyright (C) 1997-2012 Sam Lantinga - - 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 (__GNUC__ > 2) && defined(__i386__) && __OPTIMIZE__ && SDL_ASSEMBLY_ROUTINES - -#include "SDL_stdinc.h" - -#include "mmx.h" - -/* *INDENT-OFF* */ - -static mmx_t MMX_0080w = { .ud = {0x00800080, 0x00800080} }; -static mmx_t MMX_00FFw = { .ud = {0x00ff00ff, 0x00ff00ff} }; -static mmx_t MMX_FF00w = { .ud = {0xff00ff00, 0xff00ff00} }; - -static mmx_t MMX_Ycoeff = { .uw = {0x004a, 0x004a, 0x004a, 0x004a} }; - -static mmx_t MMX_UbluRGB = { .uw = {0x0072, 0x0072, 0x0072, 0x0072} }; -static mmx_t MMX_VredRGB = { .uw = {0x0059, 0x0059, 0x0059, 0x0059} }; -static mmx_t MMX_UgrnRGB = { .uw = {0xffea, 0xffea, 0xffea, 0xffea} }; -static mmx_t MMX_VgrnRGB = { .uw = {0xffd2, 0xffd2, 0xffd2, 0xffd2} }; - -static mmx_t MMX_Ublu5x5 = { .uw = {0x0081, 0x0081, 0x0081, 0x0081} }; -static mmx_t MMX_Vred5x5 = { .uw = {0x0066, 0x0066, 0x0066, 0x0066} }; -static mmx_t MMX_Ugrn565 = { .uw = {0xffe8, 0xffe8, 0xffe8, 0xffe8} }; -static mmx_t MMX_Vgrn565 = { .uw = {0xffcd, 0xffcd, 0xffcd, 0xffcd} }; - -static mmx_t MMX_red565 = { .uw = {0xf800, 0xf800, 0xf800, 0xf800} }; -static mmx_t MMX_grn565 = { .uw = {0x07e0, 0x07e0, 0x07e0, 0x07e0} }; - -/** - This MMX assembler is my first assembler/MMX program ever. - Thus it maybe buggy. - Send patches to: - mvogt@rhrk.uni-kl.de - - After it worked fine I have "obfuscated" the code a bit to have - more parallism in the MMX units. This means I moved - initilisation around and delayed other instruction. - Performance measurement did not show that this brought any advantage - but in theory it _should_ be faster this way. - - The overall performanve gain to the C based dither was 30%-40%. - The MMX routine calculates 256bit=8RGB values in each cycle - (4 for row1 & 4 for row2) - - The red/green/blue.. coefficents are taken from the mpeg_play - player. They look nice, but I dont know if you can have - better values, to avoid integer rounding errors. - - - IMPORTANT: - ========== - - It is a requirement that the cr/cb/lum are 8 byte aligned and - the out are 16byte aligned or you will/may get segfaults - -*/ - -void ColorRGBDitherYV12MMX1X( int *colortab, Uint32 *rgb_2_pix, - unsigned char *lum, unsigned char *cr, - unsigned char *cb, unsigned char *out, - int rows, int cols, int mod ) -{ - Uint32 *row1; - Uint32 *row2; - - unsigned char* y = lum +cols*rows; // Pointer to the end - int x = 0; - row1 = (Uint32 *)out; // 32 bit target - row2 = (Uint32 *)out+cols+mod; // start of second row - mod = (mod+cols+mod)*4; // increment for row1 in byte - - __asm__ __volatile__ ( - // tap dance to workaround the inability to use %%ebx at will... - // move one thing to the stack... - "pushl $0\n" // save a slot on the stack. - "pushl %%ebx\n" // save %%ebx. - "movl %0, %%ebx\n" // put the thing in ebx. - "movl %%ebx,4(%%esp)\n" // put the thing in the stack slot. - "popl %%ebx\n" // get back %%ebx (the PIC register). - - ".align 8\n" - "1:\n" - - // create Cr (result in mm1) - "pushl %%ebx\n" - "movl 4(%%esp),%%ebx\n" - "movd (%%ebx),%%mm1\n" // 0 0 0 0 v3 v2 v1 v0 - "popl %%ebx\n" - "pxor %%mm7,%%mm7\n" // 00 00 00 00 00 00 00 00 - "movd (%2), %%mm2\n" // 0 0 0 0 l3 l2 l1 l0 - "punpcklbw %%mm7,%%mm1\n" // 0 v3 0 v2 00 v1 00 v0 - "punpckldq %%mm1,%%mm1\n" // 00 v1 00 v0 00 v1 00 v0 - "psubw %9,%%mm1\n" // mm1-128:r1 r1 r0 r0 r1 r1 r0 r0 - - // create Cr_g (result in mm0) - "movq %%mm1,%%mm0\n" // r1 r1 r0 r0 r1 r1 r0 r0 - "pmullw %10,%%mm0\n" // red*-46dec=0.7136*64 - "pmullw %11,%%mm1\n" // red*89dec=1.4013*64 - "psraw $6, %%mm0\n" // red=red/64 - "psraw $6, %%mm1\n" // red=red/64 - - // create L1 L2 (result in mm2,mm4) - // L2=lum+cols - "movq (%2,%4),%%mm3\n" // 0 0 0 0 L3 L2 L1 L0 - "punpckldq %%mm3,%%mm2\n" // L3 L2 L1 L0 l3 l2 l1 l0 - "movq %%mm2,%%mm4\n" // L3 L2 L1 L0 l3 l2 l1 l0 - "pand %12,%%mm2\n" // L3 0 L1 0 l3 0 l1 0 - "pand %13,%%mm4\n" // 0 L2 0 L0 0 l2 0 l0 - "psrlw $8,%%mm2\n" // 0 L3 0 L1 0 l3 0 l1 - - // create R (result in mm6) - "movq %%mm2,%%mm5\n" // 0 L3 0 L1 0 l3 0 l1 - "movq %%mm4,%%mm6\n" // 0 L2 0 L0 0 l2 0 l0 - "paddsw %%mm1, %%mm5\n" // lum1+red:x R3 x R1 x r3 x r1 - "paddsw %%mm1, %%mm6\n" // lum1+red:x R2 x R0 x r2 x r0 - "packuswb %%mm5,%%mm5\n" // R3 R1 r3 r1 R3 R1 r3 r1 - "packuswb %%mm6,%%mm6\n" // R2 R0 r2 r0 R2 R0 r2 r0 - "pxor %%mm7,%%mm7\n" // 00 00 00 00 00 00 00 00 - "punpcklbw %%mm5,%%mm6\n" // R3 R2 R1 R0 r3 r2 r1 r0 - - // create Cb (result in mm1) - "movd (%1), %%mm1\n" // 0 0 0 0 u3 u2 u1 u0 - "punpcklbw %%mm7,%%mm1\n" // 0 u3 0 u2 00 u1 00 u0 - "punpckldq %%mm1,%%mm1\n" // 00 u1 00 u0 00 u1 00 u0 - "psubw %9,%%mm1\n" // mm1-128:u1 u1 u0 u0 u1 u1 u0 u0 - - // create Cb_g (result in mm5) - "movq %%mm1,%%mm5\n" // u1 u1 u0 u0 u1 u1 u0 u0 - "pmullw %14,%%mm5\n" // blue*-109dec=1.7129*64 - "pmullw %15,%%mm1\n" // blue*114dec=1.78125*64 - "psraw $6, %%mm5\n" // blue=red/64 - "psraw $6, %%mm1\n" // blue=blue/64 - - // create G (result in mm7) - "movq %%mm2,%%mm3\n" // 0 L3 0 L1 0 l3 0 l1 - "movq %%mm4,%%mm7\n" // 0 L2 0 L0 0 l2 0 l1 - "paddsw %%mm5, %%mm3\n" // lum1+Cb_g:x G3t x G1t x g3t x g1t - "paddsw %%mm5, %%mm7\n" // lum1+Cb_g:x G2t x G0t x g2t x g0t - "paddsw %%mm0, %%mm3\n" // lum1+Cr_g:x G3 x G1 x g3 x g1 - "paddsw %%mm0, %%mm7\n" // lum1+blue:x G2 x G0 x g2 x g0 - "packuswb %%mm3,%%mm3\n" // G3 G1 g3 g1 G3 G1 g3 g1 - "packuswb %%mm7,%%mm7\n" // G2 G0 g2 g0 G2 G0 g2 g0 - "punpcklbw %%mm3,%%mm7\n" // G3 G2 G1 G0 g3 g2 g1 g0 - - // create B (result in mm5) - "movq %%mm2,%%mm3\n" // 0 L3 0 L1 0 l3 0 l1 - "movq %%mm4,%%mm5\n" // 0 L2 0 L0 0 l2 0 l1 - "paddsw %%mm1, %%mm3\n" // lum1+blue:x B3 x B1 x b3 x b1 - "paddsw %%mm1, %%mm5\n" // lum1+blue:x B2 x B0 x b2 x b0 - "packuswb %%mm3,%%mm3\n" // B3 B1 b3 b1 B3 B1 b3 b1 - "packuswb %%mm5,%%mm5\n" // B2 B0 b2 b0 B2 B0 b2 b0 - "punpcklbw %%mm3,%%mm5\n" // B3 B2 B1 B0 b3 b2 b1 b0 - - // fill destination row1 (needed are mm6=Rr,mm7=Gg,mm5=Bb) - - "pxor %%mm2,%%mm2\n" // 0 0 0 0 0 0 0 0 - "pxor %%mm4,%%mm4\n" // 0 0 0 0 0 0 0 0 - "movq %%mm6,%%mm1\n" // R3 R2 R1 R0 r3 r2 r1 r0 - "movq %%mm5,%%mm3\n" // B3 B2 B1 B0 b3 b2 b1 b0 - - // process lower lum - "punpcklbw %%mm4,%%mm1\n" // 0 r3 0 r2 0 r1 0 r0 - "punpcklbw %%mm4,%%mm3\n" // 0 b3 0 b2 0 b1 0 b0 - "movq %%mm1,%%mm2\n" // 0 r3 0 r2 0 r1 0 r0 - "movq %%mm3,%%mm0\n" // 0 b3 0 b2 0 b1 0 b0 - "punpcklwd %%mm1,%%mm3\n" // 0 r1 0 b1 0 r0 0 b0 - "punpckhwd %%mm2,%%mm0\n" // 0 r3 0 b3 0 r2 0 b2 - - "pxor %%mm2,%%mm2\n" // 0 0 0 0 0 0 0 0 - "movq %%mm7,%%mm1\n" // G3 G2 G1 G0 g3 g2 g1 g0 - "punpcklbw %%mm1,%%mm2\n" // g3 0 g2 0 g1 0 g0 0 - "punpcklwd %%mm4,%%mm2\n" // 0 0 g1 0 0 0 g0 0 - "por %%mm3, %%mm2\n" // 0 r1 g1 b1 0 r0 g0 b0 - "movq %%mm2,(%3)\n" // wrote out ! row1 - - "pxor %%mm2,%%mm2\n" // 0 0 0 0 0 0 0 0 - "punpcklbw %%mm1,%%mm4\n" // g3 0 g2 0 g1 0 g0 0 - "punpckhwd %%mm2,%%mm4\n" // 0 0 g3 0 0 0 g2 0 - "por %%mm0, %%mm4\n" // 0 r3 g3 b3 0 r2 g2 b2 - "movq %%mm4,8(%3)\n" // wrote out ! row1 - - // fill destination row2 (needed are mm6=Rr,mm7=Gg,mm5=Bb) - // this can be done "destructive" - "pxor %%mm2,%%mm2\n" // 0 0 0 0 0 0 0 0 - "punpckhbw %%mm2,%%mm6\n" // 0 R3 0 R2 0 R1 0 R0 - "punpckhbw %%mm1,%%mm5\n" // G3 B3 G2 B2 G1 B1 G0 B0 - "movq %%mm5,%%mm1\n" // G3 B3 G2 B2 G1 B1 G0 B0 - "punpcklwd %%mm6,%%mm1\n" // 0 R1 G1 B1 0 R0 G0 B0 - "movq %%mm1,(%5)\n" // wrote out ! row2 - "punpckhwd %%mm6,%%mm5\n" // 0 R3 G3 B3 0 R2 G2 B2 - "movq %%mm5,8(%5)\n" // wrote out ! row2 - - "addl $4,%2\n" // lum+4 - "leal 16(%3),%3\n" // row1+16 - "leal 16(%5),%5\n" // row2+16 - "addl $2,(%%esp)\n" // cr+2 - "addl $2,%1\n" // cb+2 - - "addl $4,%6\n" // x+4 - "cmpl %4,%6\n" - - "jl 1b\n" - "addl %4,%2\n" // lum += cols - "addl %8,%3\n" // row1+= mod - "addl %8,%5\n" // row2+= mod - "movl $0,%6\n" // x=0 - "cmpl %7,%2\n" - "jl 1b\n" - - "addl $4,%%esp\n" // get rid of the stack slot we reserved. - "emms\n" // reset MMX registers. - : - : "m" (cr), "r"(cb),"r"(lum), - "r"(row1),"r"(cols),"r"(row2),"m"(x),"m"(y),"m"(mod), - "m"(MMX_0080w),"m"(MMX_VgrnRGB),"m"(MMX_VredRGB), - "m"(MMX_FF00w),"m"(MMX_00FFw),"m"(MMX_UgrnRGB), - "m"(MMX_UbluRGB) - ); -} - -void Color565DitherYV12MMX1X( int *colortab, Uint32 *rgb_2_pix, - unsigned char *lum, unsigned char *cr, - unsigned char *cb, unsigned char *out, - int rows, int cols, int mod ) -{ - Uint16 *row1; - Uint16 *row2; - - unsigned char* y = lum +cols*rows; /* Pointer to the end */ - int x = 0; - row1 = (Uint16 *)out; /* 16 bit target */ - row2 = (Uint16 *)out+cols+mod; /* start of second row */ - mod = (mod+cols+mod)*2; /* increment for row1 in byte */ - - __asm__ __volatile__( - // tap dance to workaround the inability to use %%ebx at will... - // move one thing to the stack... - "pushl $0\n" // save a slot on the stack. - "pushl %%ebx\n" // save %%ebx. - "movl %0, %%ebx\n" // put the thing in ebx. - "movl %%ebx, 4(%%esp)\n" // put the thing in the stack slot. - "popl %%ebx\n" // get back %%ebx (the PIC register). - - ".align 8\n" - "1:\n" - - "movd (%1), %%mm0\n" // 4 Cb 0 0 0 0 u3 u2 u1 u0 - "pxor %%mm7, %%mm7\n" - "pushl %%ebx\n" - "movl 4(%%esp), %%ebx\n" - "movd (%%ebx), %%mm1\n" // 4 Cr 0 0 0 0 v3 v2 v1 v0 - "popl %%ebx\n" - - "punpcklbw %%mm7, %%mm0\n" // 4 W cb 0 u3 0 u2 0 u1 0 u0 - "punpcklbw %%mm7, %%mm1\n" // 4 W cr 0 v3 0 v2 0 v1 0 v0 - "psubw %9, %%mm0\n" - "psubw %9, %%mm1\n" - "movq %%mm0, %%mm2\n" // Cb 0 u3 0 u2 0 u1 0 u0 - "movq %%mm1, %%mm3\n" // Cr - "pmullw %10, %%mm2\n" // Cb2green 0 R3 0 R2 0 R1 0 R0 - "movq (%2), %%mm6\n" // L1 l7 L6 L5 L4 L3 L2 L1 L0 - "pmullw %11, %%mm0\n" // Cb2blue - "pand %12, %%mm6\n" // L1 00 L6 00 L4 00 L2 00 L0 - "pmullw %13, %%mm3\n" // Cr2green - "movq (%2), %%mm7\n" // L2 - "pmullw %14, %%mm1\n" // Cr2red - "psrlw $8, %%mm7\n" // L2 00 L7 00 L5 00 L3 00 L1 - "pmullw %15, %%mm6\n" // lum1 - "paddw %%mm3, %%mm2\n" // Cb2green + Cr2green == green - "pmullw %15, %%mm7\n" // lum2 - - "movq %%mm6, %%mm4\n" // lum1 - "paddw %%mm0, %%mm6\n" // lum1 +blue 00 B6 00 B4 00 B2 00 B0 - "movq %%mm4, %%mm5\n" // lum1 - "paddw %%mm1, %%mm4\n" // lum1 +red 00 R6 00 R4 00 R2 00 R0 - "paddw %%mm2, %%mm5\n" // lum1 +green 00 G6 00 G4 00 G2 00 G0 - "psraw $6, %%mm4\n" // R1 0 .. 64 - "movq %%mm7, %%mm3\n" // lum2 00 L7 00 L5 00 L3 00 L1 - "psraw $6, %%mm5\n" // G1 - .. + - "paddw %%mm0, %%mm7\n" // Lum2 +blue 00 B7 00 B5 00 B3 00 B1 - "psraw $6, %%mm6\n" // B1 0 .. 64 - "packuswb %%mm4, %%mm4\n" // R1 R1 - "packuswb %%mm5, %%mm5\n" // G1 G1 - "packuswb %%mm6, %%mm6\n" // B1 B1 - "punpcklbw %%mm4, %%mm4\n" - "punpcklbw %%mm5, %%mm5\n" - - "pand %16, %%mm4\n" - "psllw $3, %%mm5\n" // GREEN 1 - "punpcklbw %%mm6, %%mm6\n" - "pand %17, %%mm5\n" - "pand %16, %%mm6\n" - "por %%mm5, %%mm4\n" // - "psrlw $11, %%mm6\n" // BLUE 1 - "movq %%mm3, %%mm5\n" // lum2 - "paddw %%mm1, %%mm3\n" // lum2 +red 00 R7 00 R5 00 R3 00 R1 - "paddw %%mm2, %%mm5\n" // lum2 +green 00 G7 00 G5 00 G3 00 G1 - "psraw $6, %%mm3\n" // R2 - "por %%mm6, %%mm4\n" // MM4 - "psraw $6, %%mm5\n" // G2 - "movq (%2, %4), %%mm6\n" // L3 load lum2 - "psraw $6, %%mm7\n" - "packuswb %%mm3, %%mm3\n" - "packuswb %%mm5, %%mm5\n" - "packuswb %%mm7, %%mm7\n" - "pand %12, %%mm6\n" // L3 - "punpcklbw %%mm3, %%mm3\n" - "punpcklbw %%mm5, %%mm5\n" - "pmullw %15, %%mm6\n" // lum3 - "punpcklbw %%mm7, %%mm7\n" - "psllw $3, %%mm5\n" // GREEN 2 - "pand %16, %%mm7\n" - "pand %16, %%mm3\n" - "psrlw $11, %%mm7\n" // BLUE 2 - "pand %17, %%mm5\n" - "por %%mm7, %%mm3\n" - "movq (%2,%4), %%mm7\n" // L4 load lum2 - "por %%mm5, %%mm3\n" // - "psrlw $8, %%mm7\n" // L4 - "movq %%mm4, %%mm5\n" - "punpcklwd %%mm3, %%mm4\n" - "pmullw %15, %%mm7\n" // lum4 - "punpckhwd %%mm3, %%mm5\n" - - "movq %%mm4, (%3)\n" // write row1 - "movq %%mm5, 8(%3)\n" // write row1 - - "movq %%mm6, %%mm4\n" // Lum3 - "paddw %%mm0, %%mm6\n" // Lum3 +blue - - "movq %%mm4, %%mm5\n" // Lum3 - "paddw %%mm1, %%mm4\n" // Lum3 +red - "paddw %%mm2, %%mm5\n" // Lum3 +green - "psraw $6, %%mm4\n" - "movq %%mm7, %%mm3\n" // Lum4 - "psraw $6, %%mm5\n" - "paddw %%mm0, %%mm7\n" // Lum4 +blue - "psraw $6, %%mm6\n" // Lum3 +blue - "movq %%mm3, %%mm0\n" // Lum4 - "packuswb %%mm4, %%mm4\n" - "paddw %%mm1, %%mm3\n" // Lum4 +red - "packuswb %%mm5, %%mm5\n" - "paddw %%mm2, %%mm0\n" // Lum4 +green - "packuswb %%mm6, %%mm6\n" - "punpcklbw %%mm4, %%mm4\n" - "punpcklbw %%mm5, %%mm5\n" - "punpcklbw %%mm6, %%mm6\n" - "psllw $3, %%mm5\n" // GREEN 3 - "pand %16, %%mm4\n" - "psraw $6, %%mm3\n" // psr 6 - "psraw $6, %%mm0\n" - "pand %16, %%mm6\n" // BLUE - "pand %17, %%mm5\n" - "psrlw $11, %%mm6\n" // BLUE 3 - "por %%mm5, %%mm4\n" - "psraw $6, %%mm7\n" - "por %%mm6, %%mm4\n" - "packuswb %%mm3, %%mm3\n" - "packuswb %%mm0, %%mm0\n" - "packuswb %%mm7, %%mm7\n" - "punpcklbw %%mm3, %%mm3\n" - "punpcklbw %%mm0, %%mm0\n" - "punpcklbw %%mm7, %%mm7\n" - "pand %16, %%mm3\n" - "pand %16, %%mm7\n" // BLUE - "psllw $3, %%mm0\n" // GREEN 4 - "psrlw $11, %%mm7\n" - "pand %17, %%mm0\n" - "por %%mm7, %%mm3\n" - "por %%mm0, %%mm3\n" - - "movq %%mm4, %%mm5\n" - - "punpcklwd %%mm3, %%mm4\n" - "punpckhwd %%mm3, %%mm5\n" - - "movq %%mm4, (%5)\n" - "movq %%mm5, 8(%5)\n" - - "addl $8, %6\n" - "addl $8, %2\n" - "addl $4, (%%esp)\n" - "addl $4, %1\n" - "cmpl %4, %6\n" - "leal 16(%3), %3\n" - "leal 16(%5),%5\n" // row2+16 - - "jl 1b\n" - "addl %4, %2\n" // lum += cols - "addl %8, %3\n" // row1+= mod - "addl %8, %5\n" // row2+= mod - "movl $0, %6\n" // x=0 - "cmpl %7, %2\n" - "jl 1b\n" - "addl $4, %%esp\n" // get rid of the stack slot we reserved. - "emms\n" - : - : "m" (cr), "r"(cb),"r"(lum), - "r"(row1),"r"(cols),"r"(row2),"m"(x),"m"(y),"m"(mod), - "m"(MMX_0080w),"m"(MMX_Ugrn565),"m"(MMX_Ublu5x5), - "m"(MMX_00FFw),"m"(MMX_Vgrn565),"m"(MMX_Vred5x5), - "m"(MMX_Ycoeff),"m"(MMX_red565),"m"(MMX_grn565) - ); -} - -/* *INDENT-ON* */ - -#endif /* GCC3 i386 inline assembly */ - -/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/SDL-mobile/src/render/SDL_yuv_sw.c b/src/SDL-mobile/src/render/SDL_yuv_sw.c deleted file mode 100644 index 2f8172d13..000000000 --- a/src/SDL-mobile/src/render/SDL_yuv_sw.c +++ /dev/null @@ -1,1355 +0,0 @@ -/* - Simple DirectMedia Layer - Copyright (C) 1997-2012 Sam Lantinga - - 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" - -/* This is the software implementation of the YUV texture support */ - -/* This code was derived from code carrying the following copyright notices: - - * Copyright (c) 1995 The Regents of the University of California. - * All rights reserved. - * - * Permission to use, copy, modify, and distribute this software and its - * documentation for any purpose, without fee, and without written agreement is - * hereby granted, provided that the above copyright notice and the following - * two paragraphs appear in all copies of this software. - * - * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR - * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT - * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF - * CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY - * AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS - * ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO - * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. - - * Copyright (c) 1995 Erik Corry - * All rights reserved. - * - * Permission to use, copy, modify, and distribute this software and its - * documentation for any purpose, without fee, and without written agreement is - * hereby granted, provided that the above copyright notice and the following - * two paragraphs appear in all copies of this software. - * - * IN NO EVENT SHALL ERIK CORRY BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, - * SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OF - * THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF ERIK CORRY HAS BEEN ADVISED - * OF THE POSSIBILITY OF SUCH DAMAGE. - * - * ERIK CORRY SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A - * PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS ON AN "AS IS" - * BASIS, AND ERIK CORRY HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, - * UPDATES, ENHANCEMENTS, OR MODIFICATIONS. - - * Portions of this software Copyright (c) 1995 Brown University. - * All rights reserved. - * - * Permission to use, copy, modify, and distribute this software and its - * documentation for any purpose, without fee, and without written agreement - * is hereby granted, provided that the above copyright notice and the - * following two paragraphs appear in all copies of this software. - * - * IN NO EVENT SHALL BROWN UNIVERSITY BE LIABLE TO ANY PARTY FOR - * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT - * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF BROWN - * UNIVERSITY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - * BROWN UNIVERSITY SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A - * PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS ON AN "AS IS" - * BASIS, AND BROWN UNIVERSITY HAS NO OBLIGATION TO PROVIDE MAINTENANCE, - * SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. - */ - -#include "SDL_video.h" -#include "SDL_cpuinfo.h" -#include "SDL_yuv_sw_c.h" - - -/* The colorspace conversion functions */ - -#if (__GNUC__ > 2) && defined(__i386__) && __OPTIMIZE__ && SDL_ASSEMBLY_ROUTINES -extern void Color565DitherYV12MMX1X(int *colortab, Uint32 * rgb_2_pix, - unsigned char *lum, unsigned char *cr, - unsigned char *cb, unsigned char *out, - int rows, int cols, int mod); -extern void ColorRGBDitherYV12MMX1X(int *colortab, Uint32 * rgb_2_pix, - unsigned char *lum, unsigned char *cr, - unsigned char *cb, unsigned char *out, - int rows, int cols, int mod); -#endif - -static void -Color16DitherYV12Mod1X(int *colortab, Uint32 * rgb_2_pix, - unsigned char *lum, unsigned char *cr, - unsigned char *cb, unsigned char *out, - int rows, int cols, int mod) -{ - unsigned short *row1; - unsigned short *row2; - unsigned char *lum2; - int x, y; - int cr_r; - int crb_g; - int cb_b; - int cols_2 = cols / 2; - - row1 = (unsigned short *) out; - row2 = row1 + cols + mod; - lum2 = lum + cols; - - mod += cols + mod; - - y = rows / 2; - while (y--) { - x = cols_2; - while (x--) { - register int L; - - cr_r = 0 * 768 + 256 + colortab[*cr + 0 * 256]; - crb_g = 1 * 768 + 256 + colortab[*cr + 1 * 256] - + colortab[*cb + 2 * 256]; - cb_b = 2 * 768 + 256 + colortab[*cb + 3 * 256]; - ++cr; - ++cb; - - L = *lum++; - *row1++ = (unsigned short) (rgb_2_pix[L + cr_r] | - rgb_2_pix[L + crb_g] | - rgb_2_pix[L + cb_b]); - - L = *lum++; - *row1++ = (unsigned short) (rgb_2_pix[L + cr_r] | - rgb_2_pix[L + crb_g] | - rgb_2_pix[L + cb_b]); - - - /* Now, do second row. */ - - L = *lum2++; - *row2++ = (unsigned short) (rgb_2_pix[L + cr_r] | - rgb_2_pix[L + crb_g] | - rgb_2_pix[L + cb_b]); - - L = *lum2++; - *row2++ = (unsigned short) (rgb_2_pix[L + cr_r] | - rgb_2_pix[L + crb_g] | - rgb_2_pix[L + cb_b]); - } - - /* - * These values are at the start of the next line, (due - * to the ++'s above),but they need to be at the start - * of the line after that. - */ - lum += cols; - lum2 += cols; - row1 += mod; - row2 += mod; - } -} - -static void -Color24DitherYV12Mod1X(int *colortab, Uint32 * rgb_2_pix, - unsigned char *lum, unsigned char *cr, - unsigned char *cb, unsigned char *out, - int rows, int cols, int mod) -{ - unsigned int value; - unsigned char *row1; - unsigned char *row2; - unsigned char *lum2; - int x, y; - int cr_r; - int crb_g; - int cb_b; - int cols_2 = cols / 2; - - row1 = out; - row2 = row1 + cols * 3 + mod * 3; - lum2 = lum + cols; - - mod += cols + mod; - mod *= 3; - - y = rows / 2; - while (y--) { - x = cols_2; - while (x--) { - register int L; - - cr_r = 0 * 768 + 256 + colortab[*cr + 0 * 256]; - crb_g = 1 * 768 + 256 + colortab[*cr + 1 * 256] - + colortab[*cb + 2 * 256]; - cb_b = 2 * 768 + 256 + colortab[*cb + 3 * 256]; - ++cr; - ++cb; - - L = *lum++; - value = (rgb_2_pix[L + cr_r] | - rgb_2_pix[L + crb_g] | rgb_2_pix[L + cb_b]); - *row1++ = (value) & 0xFF; - *row1++ = (value >> 8) & 0xFF; - *row1++ = (value >> 16) & 0xFF; - - L = *lum++; - value = (rgb_2_pix[L + cr_r] | - rgb_2_pix[L + crb_g] | rgb_2_pix[L + cb_b]); - *row1++ = (value) & 0xFF; - *row1++ = (value >> 8) & 0xFF; - *row1++ = (value >> 16) & 0xFF; - - - /* Now, do second row. */ - - L = *lum2++; - value = (rgb_2_pix[L + cr_r] | - rgb_2_pix[L + crb_g] | rgb_2_pix[L + cb_b]); - *row2++ = (value) & 0xFF; - *row2++ = (value >> 8) & 0xFF; - *row2++ = (value >> 16) & 0xFF; - - L = *lum2++; - value = (rgb_2_pix[L + cr_r] | - rgb_2_pix[L + crb_g] | rgb_2_pix[L + cb_b]); - *row2++ = (value) & 0xFF; - *row2++ = (value >> 8) & 0xFF; - *row2++ = (value >> 16) & 0xFF; - } - - /* - * These values are at the start of the next line, (due - * to the ++'s above),but they need to be at the start - * of the line after that. - */ - lum += cols; - lum2 += cols; - row1 += mod; - row2 += mod; - } -} - -static void -Color32DitherYV12Mod1X(int *colortab, Uint32 * rgb_2_pix, - unsigned char *lum, unsigned char *cr, - unsigned char *cb, unsigned char *out, - int rows, int cols, int mod) -{ - unsigned int *row1; - unsigned int *row2; - unsigned char *lum2; - int x, y; - int cr_r; - int crb_g; - int cb_b; - int cols_2 = cols / 2; - - row1 = (unsigned int *) out; - row2 = row1 + cols + mod; - lum2 = lum + cols; - - mod += cols + mod; - - y = rows / 2; - while (y--) { - x = cols_2; - while (x--) { - register int L; - - cr_r = 0 * 768 + 256 + colortab[*cr + 0 * 256]; - crb_g = 1 * 768 + 256 + colortab[*cr + 1 * 256] - + colortab[*cb + 2 * 256]; - cb_b = 2 * 768 + 256 + colortab[*cb + 3 * 256]; - ++cr; - ++cb; - - L = *lum++; - *row1++ = (rgb_2_pix[L + cr_r] | - rgb_2_pix[L + crb_g] | rgb_2_pix[L + cb_b]); - - L = *lum++; - *row1++ = (rgb_2_pix[L + cr_r] | - rgb_2_pix[L + crb_g] | rgb_2_pix[L + cb_b]); - - - /* Now, do second row. */ - - L = *lum2++; - *row2++ = (rgb_2_pix[L + cr_r] | - rgb_2_pix[L + crb_g] | rgb_2_pix[L + cb_b]); - - L = *lum2++; - *row2++ = (rgb_2_pix[L + cr_r] | - rgb_2_pix[L + crb_g] | rgb_2_pix[L + cb_b]); - } - - /* - * These values are at the start of the next line, (due - * to the ++'s above),but they need to be at the start - * of the line after that. - */ - lum += cols; - lum2 += cols; - row1 += mod; - row2 += mod; - } -} - -/* - * In this function I make use of a nasty trick. The tables have the lower - * 16 bits replicated in the upper 16. This means I can write ints and get - * the horisontal doubling for free (almost). - */ -static void -Color16DitherYV12Mod2X(int *colortab, Uint32 * rgb_2_pix, - unsigned char *lum, unsigned char *cr, - unsigned char *cb, unsigned char *out, - int rows, int cols, int mod) -{ - unsigned int *row1 = (unsigned int *) out; - const int next_row = cols + (mod / 2); - unsigned int *row2 = row1 + 2 * next_row; - unsigned char *lum2; - int x, y; - int cr_r; - int crb_g; - int cb_b; - int cols_2 = cols / 2; - - lum2 = lum + cols; - - mod = (next_row * 3) + (mod / 2); - - y = rows / 2; - while (y--) { - x = cols_2; - while (x--) { - register int L; - - cr_r = 0 * 768 + 256 + colortab[*cr + 0 * 256]; - crb_g = 1 * 768 + 256 + colortab[*cr + 1 * 256] - + colortab[*cb + 2 * 256]; - cb_b = 2 * 768 + 256 + colortab[*cb + 3 * 256]; - ++cr; - ++cb; - - L = *lum++; - row1[0] = row1[next_row] = (rgb_2_pix[L + cr_r] | - rgb_2_pix[L + crb_g] | - rgb_2_pix[L + cb_b]); - row1++; - - L = *lum++; - row1[0] = row1[next_row] = (rgb_2_pix[L + cr_r] | - rgb_2_pix[L + crb_g] | - rgb_2_pix[L + cb_b]); - row1++; - - - /* Now, do second row. */ - - L = *lum2++; - row2[0] = row2[next_row] = (rgb_2_pix[L + cr_r] | - rgb_2_pix[L + crb_g] | - rgb_2_pix[L + cb_b]); - row2++; - - L = *lum2++; - row2[0] = row2[next_row] = (rgb_2_pix[L + cr_r] | - rgb_2_pix[L + crb_g] | - rgb_2_pix[L + cb_b]); - row2++; - } - - /* - * These values are at the start of the next line, (due - * to the ++'s above),but they need to be at the start - * of the line after that. - */ - lum += cols; - lum2 += cols; - row1 += mod; - row2 += mod; - } -} - -static void -Color24DitherYV12Mod2X(int *colortab, Uint32 * rgb_2_pix, - unsigned char *lum, unsigned char *cr, - unsigned char *cb, unsigned char *out, - int rows, int cols, int mod) -{ - unsigned int value; - unsigned char *row1 = out; - const int next_row = (cols * 2 + mod) * 3; - unsigned char *row2 = row1 + 2 * next_row; - unsigned char *lum2; - int x, y; - int cr_r; - int crb_g; - int cb_b; - int cols_2 = cols / 2; - - lum2 = lum + cols; - - mod = next_row * 3 + mod * 3; - - y = rows / 2; - while (y--) { - x = cols_2; - while (x--) { - register int L; - - cr_r = 0 * 768 + 256 + colortab[*cr + 0 * 256]; - crb_g = 1 * 768 + 256 + colortab[*cr + 1 * 256] - + colortab[*cb + 2 * 256]; - cb_b = 2 * 768 + 256 + colortab[*cb + 3 * 256]; - ++cr; - ++cb; - - L = *lum++; - value = (rgb_2_pix[L + cr_r] | - rgb_2_pix[L + crb_g] | rgb_2_pix[L + cb_b]); - row1[0 + 0] = row1[3 + 0] = row1[next_row + 0] = - row1[next_row + 3 + 0] = (value) & 0xFF; - row1[0 + 1] = row1[3 + 1] = row1[next_row + 1] = - row1[next_row + 3 + 1] = (value >> 8) & 0xFF; - row1[0 + 2] = row1[3 + 2] = row1[next_row + 2] = - row1[next_row + 3 + 2] = (value >> 16) & 0xFF; - row1 += 2 * 3; - - L = *lum++; - value = (rgb_2_pix[L + cr_r] | - rgb_2_pix[L + crb_g] | rgb_2_pix[L + cb_b]); - row1[0 + 0] = row1[3 + 0] = row1[next_row + 0] = - row1[next_row + 3 + 0] = (value) & 0xFF; - row1[0 + 1] = row1[3 + 1] = row1[next_row + 1] = - row1[next_row + 3 + 1] = (value >> 8) & 0xFF; - row1[0 + 2] = row1[3 + 2] = row1[next_row + 2] = - row1[next_row + 3 + 2] = (value >> 16) & 0xFF; - row1 += 2 * 3; - - - /* Now, do second row. */ - - L = *lum2++; - value = (rgb_2_pix[L + cr_r] | - rgb_2_pix[L + crb_g] | rgb_2_pix[L + cb_b]); - row2[0 + 0] = row2[3 + 0] = row2[next_row + 0] = - row2[next_row + 3 + 0] = (value) & 0xFF; - row2[0 + 1] = row2[3 + 1] = row2[next_row + 1] = - row2[next_row + 3 + 1] = (value >> 8) & 0xFF; - row2[0 + 2] = row2[3 + 2] = row2[next_row + 2] = - row2[next_row + 3 + 2] = (value >> 16) & 0xFF; - row2 += 2 * 3; - - L = *lum2++; - value = (rgb_2_pix[L + cr_r] | - rgb_2_pix[L + crb_g] | rgb_2_pix[L + cb_b]); - row2[0 + 0] = row2[3 + 0] = row2[next_row + 0] = - row2[next_row + 3 + 0] = (value) & 0xFF; - row2[0 + 1] = row2[3 + 1] = row2[next_row + 1] = - row2[next_row + 3 + 1] = (value >> 8) & 0xFF; - row2[0 + 2] = row2[3 + 2] = row2[next_row + 2] = - row2[next_row + 3 + 2] = (value >> 16) & 0xFF; - row2 += 2 * 3; - } - - /* - * These values are at the start of the next line, (due - * to the ++'s above),but they need to be at the start - * of the line after that. - */ - lum += cols; - lum2 += cols; - row1 += mod; - row2 += mod; - } -} - -static void -Color32DitherYV12Mod2X(int *colortab, Uint32 * rgb_2_pix, - unsigned char *lum, unsigned char *cr, - unsigned char *cb, unsigned char *out, - int rows, int cols, int mod) -{ - unsigned int *row1 = (unsigned int *) out; - const int next_row = cols * 2 + mod; - unsigned int *row2 = row1 + 2 * next_row; - unsigned char *lum2; - int x, y; - int cr_r; - int crb_g; - int cb_b; - int cols_2 = cols / 2; - - lum2 = lum + cols; - - mod = (next_row * 3) + mod; - - y = rows / 2; - while (y--) { - x = cols_2; - while (x--) { - register int L; - - cr_r = 0 * 768 + 256 + colortab[*cr + 0 * 256]; - crb_g = 1 * 768 + 256 + colortab[*cr + 1 * 256] - + colortab[*cb + 2 * 256]; - cb_b = 2 * 768 + 256 + colortab[*cb + 3 * 256]; - ++cr; - ++cb; - - L = *lum++; - row1[0] = row1[1] = row1[next_row] = row1[next_row + 1] = - (rgb_2_pix[L + cr_r] | - rgb_2_pix[L + crb_g] | rgb_2_pix[L + cb_b]); - row1 += 2; - - L = *lum++; - row1[0] = row1[1] = row1[next_row] = row1[next_row + 1] = - (rgb_2_pix[L + cr_r] | - rgb_2_pix[L + crb_g] | rgb_2_pix[L + cb_b]); - row1 += 2; - - - /* Now, do second row. */ - - L = *lum2++; - row2[0] = row2[1] = row2[next_row] = row2[next_row + 1] = - (rgb_2_pix[L + cr_r] | - rgb_2_pix[L + crb_g] | rgb_2_pix[L + cb_b]); - row2 += 2; - - L = *lum2++; - row2[0] = row2[1] = row2[next_row] = row2[next_row + 1] = - (rgb_2_pix[L + cr_r] | - rgb_2_pix[L + crb_g] | rgb_2_pix[L + cb_b]); - row2 += 2; - } - - /* - * These values are at the start of the next line, (due - * to the ++'s above),but they need to be at the start - * of the line after that. - */ - lum += cols; - lum2 += cols; - row1 += mod; - row2 += mod; - } -} - -static void -Color16DitherYUY2Mod1X(int *colortab, Uint32 * rgb_2_pix, - unsigned char *lum, unsigned char *cr, - unsigned char *cb, unsigned char *out, - int rows, int cols, int mod) -{ - unsigned short *row; - int x, y; - int cr_r; - int crb_g; - int cb_b; - int cols_2 = cols / 2; - - row = (unsigned short *) out; - - y = rows; - while (y--) { - x = cols_2; - while (x--) { - register int L; - - cr_r = 0 * 768 + 256 + colortab[*cr + 0 * 256]; - crb_g = 1 * 768 + 256 + colortab[*cr + 1 * 256] - + colortab[*cb + 2 * 256]; - cb_b = 2 * 768 + 256 + colortab[*cb + 3 * 256]; - cr += 4; - cb += 4; - - L = *lum; - lum += 2; - *row++ = (unsigned short) (rgb_2_pix[L + cr_r] | - rgb_2_pix[L + crb_g] | - rgb_2_pix[L + cb_b]); - - L = *lum; - lum += 2; - *row++ = (unsigned short) (rgb_2_pix[L + cr_r] | - rgb_2_pix[L + crb_g] | - rgb_2_pix[L + cb_b]); - - } - - row += mod; - } -} - -static void -Color24DitherYUY2Mod1X(int *colortab, Uint32 * rgb_2_pix, - unsigned char *lum, unsigned char *cr, - unsigned char *cb, unsigned char *out, - int rows, int cols, int mod) -{ - unsigned int value; - unsigned char *row; - int x, y; - int cr_r; - int crb_g; - int cb_b; - int cols_2 = cols / 2; - - row = (unsigned char *) out; - mod *= 3; - y = rows; - while (y--) { - x = cols_2; - while (x--) { - register int L; - - cr_r = 0 * 768 + 256 + colortab[*cr + 0 * 256]; - crb_g = 1 * 768 + 256 + colortab[*cr + 1 * 256] - + colortab[*cb + 2 * 256]; - cb_b = 2 * 768 + 256 + colortab[*cb + 3 * 256]; - cr += 4; - cb += 4; - - L = *lum; - lum += 2; - value = (rgb_2_pix[L + cr_r] | - rgb_2_pix[L + crb_g] | rgb_2_pix[L + cb_b]); - *row++ = (value) & 0xFF; - *row++ = (value >> 8) & 0xFF; - *row++ = (value >> 16) & 0xFF; - - L = *lum; - lum += 2; - value = (rgb_2_pix[L + cr_r] | - rgb_2_pix[L + crb_g] | rgb_2_pix[L + cb_b]); - *row++ = (value) & 0xFF; - *row++ = (value >> 8) & 0xFF; - *row++ = (value >> 16) & 0xFF; - - } - row += mod; - } -} - -static void -Color32DitherYUY2Mod1X(int *colortab, Uint32 * rgb_2_pix, - unsigned char *lum, unsigned char *cr, - unsigned char *cb, unsigned char *out, - int rows, int cols, int mod) -{ - unsigned int *row; - int x, y; - int cr_r; - int crb_g; - int cb_b; - int cols_2 = cols / 2; - - row = (unsigned int *) out; - y = rows; - while (y--) { - x = cols_2; - while (x--) { - register int L; - - cr_r = 0 * 768 + 256 + colortab[*cr + 0 * 256]; - crb_g = 1 * 768 + 256 + colortab[*cr + 1 * 256] - + colortab[*cb + 2 * 256]; - cb_b = 2 * 768 + 256 + colortab[*cb + 3 * 256]; - cr += 4; - cb += 4; - - L = *lum; - lum += 2; - *row++ = (rgb_2_pix[L + cr_r] | - rgb_2_pix[L + crb_g] | rgb_2_pix[L + cb_b]); - - L = *lum; - lum += 2; - *row++ = (rgb_2_pix[L + cr_r] | - rgb_2_pix[L + crb_g] | rgb_2_pix[L + cb_b]); - - - } - row += mod; - } -} - -/* - * In this function I make use of a nasty trick. The tables have the lower - * 16 bits replicated in the upper 16. This means I can write ints and get - * the horisontal doubling for free (almost). - */ -static void -Color16DitherYUY2Mod2X(int *colortab, Uint32 * rgb_2_pix, - unsigned char *lum, unsigned char *cr, - unsigned char *cb, unsigned char *out, - int rows, int cols, int mod) -{ - unsigned int *row = (unsigned int *) out; - const int next_row = cols + (mod / 2); - int x, y; - int cr_r; - int crb_g; - int cb_b; - int cols_2 = cols / 2; - - y = rows; - while (y--) { - x = cols_2; - while (x--) { - register int L; - - cr_r = 0 * 768 + 256 + colortab[*cr + 0 * 256]; - crb_g = 1 * 768 + 256 + colortab[*cr + 1 * 256] - + colortab[*cb + 2 * 256]; - cb_b = 2 * 768 + 256 + colortab[*cb + 3 * 256]; - cr += 4; - cb += 4; - - L = *lum; - lum += 2; - row[0] = row[next_row] = (rgb_2_pix[L + cr_r] | - rgb_2_pix[L + crb_g] | - rgb_2_pix[L + cb_b]); - row++; - - L = *lum; - lum += 2; - row[0] = row[next_row] = (rgb_2_pix[L + cr_r] | - rgb_2_pix[L + crb_g] | - rgb_2_pix[L + cb_b]); - row++; - - } - row += next_row; - } -} - -static void -Color24DitherYUY2Mod2X(int *colortab, Uint32 * rgb_2_pix, - unsigned char *lum, unsigned char *cr, - unsigned char *cb, unsigned char *out, - int rows, int cols, int mod) -{ - unsigned int value; - unsigned char *row = out; - const int next_row = (cols * 2 + mod) * 3; - int x, y; - int cr_r; - int crb_g; - int cb_b; - int cols_2 = cols / 2; - y = rows; - while (y--) { - x = cols_2; - while (x--) { - register int L; - - cr_r = 0 * 768 + 256 + colortab[*cr + 0 * 256]; - crb_g = 1 * 768 + 256 + colortab[*cr + 1 * 256] - + colortab[*cb + 2 * 256]; - cb_b = 2 * 768 + 256 + colortab[*cb + 3 * 256]; - cr += 4; - cb += 4; - - L = *lum; - lum += 2; - value = (rgb_2_pix[L + cr_r] | - rgb_2_pix[L + crb_g] | rgb_2_pix[L + cb_b]); - row[0 + 0] = row[3 + 0] = row[next_row + 0] = - row[next_row + 3 + 0] = (value) & 0xFF; - row[0 + 1] = row[3 + 1] = row[next_row + 1] = - row[next_row + 3 + 1] = (value >> 8) & 0xFF; - row[0 + 2] = row[3 + 2] = row[next_row + 2] = - row[next_row + 3 + 2] = (value >> 16) & 0xFF; - row += 2 * 3; - - L = *lum; - lum += 2; - value = (rgb_2_pix[L + cr_r] | - rgb_2_pix[L + crb_g] | rgb_2_pix[L + cb_b]); - row[0 + 0] = row[3 + 0] = row[next_row + 0] = - row[next_row + 3 + 0] = (value) & 0xFF; - row[0 + 1] = row[3 + 1] = row[next_row + 1] = - row[next_row + 3 + 1] = (value >> 8) & 0xFF; - row[0 + 2] = row[3 + 2] = row[next_row + 2] = - row[next_row + 3 + 2] = (value >> 16) & 0xFF; - row += 2 * 3; - - } - row += next_row; - } -} - -static void -Color32DitherYUY2Mod2X(int *colortab, Uint32 * rgb_2_pix, - unsigned char *lum, unsigned char *cr, - unsigned char *cb, unsigned char *out, - int rows, int cols, int mod) -{ - unsigned int *row = (unsigned int *) out; - const int next_row = cols * 2 + mod; - int x, y; - int cr_r; - int crb_g; - int cb_b; - int cols_2 = cols / 2; - mod += mod; - y = rows; - while (y--) { - x = cols_2; - while (x--) { - register int L; - - cr_r = 0 * 768 + 256 + colortab[*cr + 0 * 256]; - crb_g = 1 * 768 + 256 + colortab[*cr + 1 * 256] - + colortab[*cb + 2 * 256]; - cb_b = 2 * 768 + 256 + colortab[*cb + 3 * 256]; - cr += 4; - cb += 4; - - L = *lum; - lum += 2; - row[0] = row[1] = row[next_row] = row[next_row + 1] = - (rgb_2_pix[L + cr_r] | - rgb_2_pix[L + crb_g] | rgb_2_pix[L + cb_b]); - row += 2; - - L = *lum; - lum += 2; - row[0] = row[1] = row[next_row] = row[next_row + 1] = - (rgb_2_pix[L + cr_r] | - rgb_2_pix[L + crb_g] | rgb_2_pix[L + cb_b]); - row += 2; - - - } - - row += next_row; - } -} - -/* - * How many 1 bits are there in the Uint32. - * Low performance, do not call often. - */ -static int -number_of_bits_set(Uint32 a) -{ - if (!a) - return 0; - if (a & 1) - return 1 + number_of_bits_set(a >> 1); - return (number_of_bits_set(a >> 1)); -} - -/* - * How many 0 bits are there at least significant end of Uint32. - * Low performance, do not call often. - */ -static int -free_bits_at_bottom(Uint32 a) -{ - /* assume char is 8 bits */ - if (!a) - return sizeof(Uint32) * 8; - if (((Sint32) a) & 1l) - return 0; - return 1 + free_bits_at_bottom(a >> 1); -} - -static int -SDL_SW_SetupYUVDisplay(SDL_SW_YUVTexture * swdata, Uint32 target_format) -{ - Uint32 *r_2_pix_alloc; - Uint32 *g_2_pix_alloc; - Uint32 *b_2_pix_alloc; - int i; - int bpp; - Uint32 Rmask, Gmask, Bmask, Amask; - - if (!SDL_PixelFormatEnumToMasks - (target_format, &bpp, &Rmask, &Gmask, &Bmask, &Amask) || bpp < 15) { - SDL_SetError("Unsupported YUV destination format"); - return -1; - } - - swdata->target_format = target_format; - r_2_pix_alloc = &swdata->rgb_2_pix[0 * 768]; - g_2_pix_alloc = &swdata->rgb_2_pix[1 * 768]; - b_2_pix_alloc = &swdata->rgb_2_pix[2 * 768]; - - /* - * Set up entries 0-255 in rgb-to-pixel value tables. - */ - for (i = 0; i < 256; ++i) { - r_2_pix_alloc[i + 256] = i >> (8 - number_of_bits_set(Rmask)); - r_2_pix_alloc[i + 256] <<= free_bits_at_bottom(Rmask); - r_2_pix_alloc[i + 256] |= Amask; - g_2_pix_alloc[i + 256] = i >> (8 - number_of_bits_set(Gmask)); - g_2_pix_alloc[i + 256] <<= free_bits_at_bottom(Gmask); - g_2_pix_alloc[i + 256] |= Amask; - b_2_pix_alloc[i + 256] = i >> (8 - number_of_bits_set(Bmask)); - b_2_pix_alloc[i + 256] <<= free_bits_at_bottom(Bmask); - b_2_pix_alloc[i + 256] |= Amask; - } - - /* - * If we have 16-bit output depth, then we double the value - * in the top word. This means that we can write out both - * pixels in the pixel doubling mode with one op. It is - * harmless in the normal case as storing a 32-bit value - * through a short pointer will lose the top bits anyway. - */ - if (SDL_BYTESPERPIXEL(target_format) == 2) { - for (i = 0; i < 256; ++i) { - r_2_pix_alloc[i + 256] |= (r_2_pix_alloc[i + 256]) << 16; - g_2_pix_alloc[i + 256] |= (g_2_pix_alloc[i + 256]) << 16; - b_2_pix_alloc[i + 256] |= (b_2_pix_alloc[i + 256]) << 16; - } - } - - /* - * Spread out the values we have to the rest of the array so that - * we do not need to check for overflow. - */ - for (i = 0; i < 256; ++i) { - r_2_pix_alloc[i] = r_2_pix_alloc[256]; - r_2_pix_alloc[i + 512] = r_2_pix_alloc[511]; - g_2_pix_alloc[i] = g_2_pix_alloc[256]; - g_2_pix_alloc[i + 512] = g_2_pix_alloc[511]; - b_2_pix_alloc[i] = b_2_pix_alloc[256]; - b_2_pix_alloc[i + 512] = b_2_pix_alloc[511]; - } - - /* You have chosen wisely... */ - switch (swdata->format) { - case SDL_PIXELFORMAT_YV12: - case SDL_PIXELFORMAT_IYUV: - if (SDL_BYTESPERPIXEL(target_format) == 2) { -#if (__GNUC__ > 2) && defined(__i386__) && __OPTIMIZE__ && SDL_ASSEMBLY_ROUTINES - /* inline assembly functions */ - if (SDL_HasMMX() && (Rmask == 0xF800) && - (Gmask == 0x07E0) && (Bmask == 0x001F) - && (swdata->w & 15) == 0) { -/*printf("Using MMX 16-bit 565 dither\n");*/ - swdata->Display1X = Color565DitherYV12MMX1X; - } else { -/*printf("Using C 16-bit dither\n");*/ - swdata->Display1X = Color16DitherYV12Mod1X; - } -#else - swdata->Display1X = Color16DitherYV12Mod1X; -#endif - swdata->Display2X = Color16DitherYV12Mod2X; - } - if (SDL_BYTESPERPIXEL(target_format) == 3) { - swdata->Display1X = Color24DitherYV12Mod1X; - swdata->Display2X = Color24DitherYV12Mod2X; - } - if (SDL_BYTESPERPIXEL(target_format) == 4) { -#if (__GNUC__ > 2) && defined(__i386__) && __OPTIMIZE__ && SDL_ASSEMBLY_ROUTINES - /* inline assembly functions */ - if (SDL_HasMMX() && (Rmask == 0x00FF0000) && - (Gmask == 0x0000FF00) && - (Bmask == 0x000000FF) && (swdata->w & 15) == 0) { -/*printf("Using MMX 32-bit dither\n");*/ - swdata->Display1X = ColorRGBDitherYV12MMX1X; - } else { -/*printf("Using C 32-bit dither\n");*/ - swdata->Display1X = Color32DitherYV12Mod1X; - } -#else - swdata->Display1X = Color32DitherYV12Mod1X; -#endif - swdata->Display2X = Color32DitherYV12Mod2X; - } - break; - case SDL_PIXELFORMAT_YUY2: - case SDL_PIXELFORMAT_UYVY: - case SDL_PIXELFORMAT_YVYU: - if (SDL_BYTESPERPIXEL(target_format) == 2) { - swdata->Display1X = Color16DitherYUY2Mod1X; - swdata->Display2X = Color16DitherYUY2Mod2X; - } - if (SDL_BYTESPERPIXEL(target_format) == 3) { - swdata->Display1X = Color24DitherYUY2Mod1X; - swdata->Display2X = Color24DitherYUY2Mod2X; - } - if (SDL_BYTESPERPIXEL(target_format) == 4) { - swdata->Display1X = Color32DitherYUY2Mod1X; - swdata->Display2X = Color32DitherYUY2Mod2X; - } - break; - default: - /* We should never get here (caught above) */ - break; - } - - if (swdata->display) { - SDL_FreeSurface(swdata->display); - swdata->display = NULL; - } - return 0; -} - -SDL_SW_YUVTexture * -SDL_SW_CreateYUVTexture(Uint32 format, int w, int h) -{ - SDL_SW_YUVTexture *swdata; - int *Cr_r_tab; - int *Cr_g_tab; - int *Cb_g_tab; - int *Cb_b_tab; - int i; - int CR, CB; - - swdata = (SDL_SW_YUVTexture *) SDL_calloc(1, sizeof(*swdata)); - if (!swdata) { - SDL_OutOfMemory(); - return NULL; - } - - switch (format) { - case SDL_PIXELFORMAT_YV12: - case SDL_PIXELFORMAT_IYUV: - case SDL_PIXELFORMAT_YUY2: - case SDL_PIXELFORMAT_UYVY: - case SDL_PIXELFORMAT_YVYU: - break; - default: - SDL_SetError("Unsupported YUV format"); - return NULL; - } - - swdata->format = format; - swdata->target_format = SDL_PIXELFORMAT_UNKNOWN; - swdata->w = w; - swdata->h = h; - swdata->pixels = (Uint8 *) SDL_malloc(w * h * 2); - 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); - return NULL; - } - - /* Generate the tables for the display surface */ - Cr_r_tab = &swdata->colortab[0 * 256]; - Cr_g_tab = &swdata->colortab[1 * 256]; - Cb_g_tab = &swdata->colortab[2 * 256]; - Cb_b_tab = &swdata->colortab[3 * 256]; - for (i = 0; i < 256; i++) { - /* Gamma correction (luminescence table) and chroma correction - would be done here. See the Berkeley mpeg_play sources. - */ - CB = CR = (i - 128); - Cr_r_tab[i] = (int) ((0.419 / 0.299) * CR); - Cr_g_tab[i] = (int) (-(0.299 / 0.419) * CR); - Cb_g_tab[i] = (int) (-(0.114 / 0.331) * CB); - Cb_b_tab[i] = (int) ((0.587 / 0.331) * CB); - } - - /* Find the pitch and offset values for the overlay */ - switch (format) { - case SDL_PIXELFORMAT_YV12: - case SDL_PIXELFORMAT_IYUV: - swdata->pitches[0] = w; - swdata->pitches[1] = swdata->pitches[0] / 2; - swdata->pitches[2] = swdata->pitches[0] / 2; - swdata->planes[0] = swdata->pixels; - swdata->planes[1] = swdata->planes[0] + swdata->pitches[0] * h; - swdata->planes[2] = swdata->planes[1] + swdata->pitches[1] * h / 2; - break; - case SDL_PIXELFORMAT_YUY2: - case SDL_PIXELFORMAT_UYVY: - case SDL_PIXELFORMAT_YVYU: - swdata->pitches[0] = w * 2; - swdata->planes[0] = swdata->pixels; - break; - default: - /* We should never get here (caught above) */ - break; - } - - /* We're all done.. */ - return (swdata); -} - -int -SDL_SW_QueryYUVTexturePixels(SDL_SW_YUVTexture * swdata, void **pixels, - int *pitch) -{ - *pixels = swdata->planes[0]; - *pitch = swdata->pitches[0]; - return 0; -} - -int -SDL_SW_UpdateYUVTexture(SDL_SW_YUVTexture * swdata, const SDL_Rect * rect, - const void *pixels, int pitch) -{ - switch (swdata->format) { - case SDL_PIXELFORMAT_YV12: - case SDL_PIXELFORMAT_IYUV: - if (rect->x == 0 && rect->y == 0 && - rect->w == swdata->w && rect->h == swdata->h) { - SDL_memcpy(swdata->pixels, pixels, - (swdata->h * swdata->w) + (swdata->h * swdata->w) / 2); - } else { - Uint8 *src, *dst; - int row; - size_t length; - - /* Copy the Y plane */ - src = (Uint8 *) pixels; - dst = swdata->pixels + rect->y * swdata->w + rect->x; - length = rect->w; - for (row = 0; row < rect->h; ++row) { - SDL_memcpy(dst, src, length); - src += pitch; - dst += swdata->w; - } - - /* Copy the next plane */ - src = (Uint8 *) pixels + rect->h * pitch; - dst = swdata->pixels + swdata->h * swdata->w; - dst += rect->y/2 * swdata->w/2 + rect->x/2; - length = rect->w / 2; - for (row = 0; row < rect->h/2; ++row) { - SDL_memcpy(dst, src, length); - src += pitch/2; - dst += swdata->w/2; - } - - /* Copy the next plane */ - src = (Uint8 *) pixels + rect->h * pitch + (rect->h * pitch) / 4; - dst = swdata->pixels + swdata->h * swdata->w + - (swdata->h * swdata->w) / 4; - dst += rect->y/2 * swdata->w/2 + rect->x/2; - length = rect->w / 2; - for (row = 0; row < rect->h/2; ++row) { - SDL_memcpy(dst, src, length); - src += pitch/2; - dst += swdata->w/2; - } - } - break; - case SDL_PIXELFORMAT_YUY2: - case SDL_PIXELFORMAT_UYVY: - case SDL_PIXELFORMAT_YVYU: - { - Uint8 *src, *dst; - int row; - size_t length; - - src = (Uint8 *) pixels; - dst = - swdata->planes[0] + rect->y * swdata->pitches[0] + - rect->x * 2; - length = rect->w * 2; - for (row = 0; row < rect->h; ++row) { - SDL_memcpy(dst, src, length); - src += pitch; - dst += swdata->pitches[0]; - } - } - break; - } - return 0; -} - -int -SDL_SW_LockYUVTexture(SDL_SW_YUVTexture * swdata, const SDL_Rect * rect, - void **pixels, int *pitch) -{ - switch (swdata->format) { - case SDL_PIXELFORMAT_YV12: - case SDL_PIXELFORMAT_IYUV: - if (rect - && (rect->x != 0 || rect->y != 0 || rect->w != swdata->w - || rect->h != swdata->h)) { - SDL_SetError - ("YV12 and IYUV textures only support full surface locks"); - return -1; - } - break; - } - - *pixels = swdata->planes[0] + rect->y * swdata->pitches[0] + rect->x * 2; - *pitch = swdata->pitches[0]; - return 0; -} - -void -SDL_SW_UnlockYUVTexture(SDL_SW_YUVTexture * swdata) -{ -} - -int -SDL_SW_CopyYUVToRGB(SDL_SW_YUVTexture * swdata, const SDL_Rect * srcrect, - Uint32 target_format, int w, int h, void *pixels, - int pitch) -{ - int stretch; - int scale_2x; - Uint8 *lum, *Cr, *Cb; - int mod; - - /* Make sure we're set up to display in the desired format */ - if (target_format != swdata->target_format) { - if (SDL_SW_SetupYUVDisplay(swdata, target_format) < 0) { - return -1; - } - } - - stretch = 0; - scale_2x = 0; - if (srcrect->x || srcrect->y || srcrect->w < swdata->w - || srcrect->h < swdata->h) { - /* The source rectangle has been clipped. - Using a scratch surface is easier than adding clipped - source support to all the blitters, plus that would - slow them down in the general unclipped case. - */ - stretch = 1; - } else if ((srcrect->w != w) || (srcrect->h != h)) { - if ((w == 2 * srcrect->w) && (h == 2 * srcrect->h)) { - scale_2x = 1; - } else { - stretch = 1; - } - } - if (stretch) { - int bpp; - Uint32 Rmask, Gmask, Bmask, Amask; - - if (swdata->display) { - swdata->display->w = w; - swdata->display->h = h; - swdata->display->pixels = pixels; - swdata->display->pitch = pitch; - } else { - /* This must have succeeded in SDL_SW_SetupYUVDisplay() earlier */ - SDL_PixelFormatEnumToMasks(target_format, &bpp, &Rmask, &Gmask, - &Bmask, &Amask); - swdata->display = - SDL_CreateRGBSurfaceFrom(pixels, w, h, bpp, pitch, Rmask, - Gmask, Bmask, Amask); - if (!swdata->display) { - return (-1); - } - } - if (!swdata->stretch) { - /* This must have succeeded in SDL_SW_SetupYUVDisplay() earlier */ - SDL_PixelFormatEnumToMasks(target_format, &bpp, &Rmask, &Gmask, - &Bmask, &Amask); - swdata->stretch = - SDL_CreateRGBSurface(0, swdata->w, swdata->h, bpp, Rmask, - Gmask, Bmask, Amask); - if (!swdata->stretch) { - return (-1); - } - } - pixels = swdata->stretch->pixels; - pitch = swdata->stretch->pitch; - } - switch (swdata->format) { - case SDL_PIXELFORMAT_YV12: - lum = swdata->planes[0]; - Cr = swdata->planes[1]; - Cb = swdata->planes[2]; - break; - case SDL_PIXELFORMAT_IYUV: - lum = swdata->planes[0]; - Cr = swdata->planes[2]; - Cb = swdata->planes[1]; - break; - case SDL_PIXELFORMAT_YUY2: - lum = swdata->planes[0]; - Cr = lum + 3; - Cb = lum + 1; - break; - case SDL_PIXELFORMAT_UYVY: - lum = swdata->planes[0] + 1; - Cr = lum + 1; - Cb = lum - 1; - break; - case SDL_PIXELFORMAT_YVYU: - lum = swdata->planes[0]; - Cr = lum + 1; - Cb = lum + 3; - break; - default: - SDL_SetError("Unsupported YUV format in copy"); - return (-1); - } - mod = (pitch / SDL_BYTESPERPIXEL(target_format)); - - if (scale_2x) { - mod -= (swdata->w * 2); - swdata->Display2X(swdata->colortab, swdata->rgb_2_pix, - lum, Cr, Cb, pixels, swdata->h, swdata->w, mod); - } else { - mod -= swdata->w; - swdata->Display1X(swdata->colortab, swdata->rgb_2_pix, - lum, Cr, Cb, pixels, swdata->h, swdata->w, mod); - } - if (stretch) { - SDL_Rect rect = *srcrect; - SDL_SoftStretch(swdata->stretch, &rect, swdata->display, NULL); - } - return 0; -} - -void -SDL_SW_DestroyYUVTexture(SDL_SW_YUVTexture * swdata) -{ - if (swdata) { - if (swdata->pixels) { - SDL_free(swdata->pixels); - } - if (swdata->colortab) { - SDL_free(swdata->colortab); - } - if (swdata->rgb_2_pix) { - SDL_free(swdata->rgb_2_pix); - } - if (swdata->stretch) { - SDL_FreeSurface(swdata->stretch); - } - if (swdata->display) { - SDL_FreeSurface(swdata->display); - } - SDL_free(swdata); - } -} - -/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/SDL-mobile/src/render/SDL_yuv_sw_c.h b/src/SDL-mobile/src/render/SDL_yuv_sw_c.h deleted file mode 100644 index 28a25514a..000000000 --- a/src/SDL-mobile/src/render/SDL_yuv_sw_c.h +++ /dev/null @@ -1,68 +0,0 @@ -/* - Simple DirectMedia Layer - Copyright (C) 1997-2012 Sam Lantinga - - 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" - -#include "SDL_video.h" - -/* This is the software implementation of the YUV texture support */ - -struct SDL_SW_YUVTexture -{ - Uint32 format; - Uint32 target_format; - int w, h; - Uint8 *pixels; - int *colortab; - Uint32 *rgb_2_pix; - void (*Display1X) (int *colortab, Uint32 * rgb_2_pix, - unsigned char *lum, unsigned char *cr, - unsigned char *cb, unsigned char *out, - int rows, int cols, int mod); - void (*Display2X) (int *colortab, Uint32 * rgb_2_pix, - unsigned char *lum, unsigned char *cr, - unsigned char *cb, unsigned char *out, - int rows, int cols, int mod); - - /* These are just so we don't have to allocate them separately */ - Uint16 pitches[3]; - Uint8 *planes[3]; - - /* This is a temporary surface in case we have to stretch copy */ - SDL_Surface *stretch; - SDL_Surface *display; -}; - -typedef struct SDL_SW_YUVTexture SDL_SW_YUVTexture; - -SDL_SW_YUVTexture *SDL_SW_CreateYUVTexture(Uint32 format, int w, int h); -int SDL_SW_QueryYUVTexturePixels(SDL_SW_YUVTexture * swdata, void **pixels, - int *pitch); -int SDL_SW_UpdateYUVTexture(SDL_SW_YUVTexture * swdata, const SDL_Rect * rect, - const void *pixels, int pitch); -int SDL_SW_LockYUVTexture(SDL_SW_YUVTexture * swdata, const SDL_Rect * rect, - void **pixels, int *pitch); -void SDL_SW_UnlockYUVTexture(SDL_SW_YUVTexture * swdata); -int SDL_SW_CopyYUVToRGB(SDL_SW_YUVTexture * swdata, const SDL_Rect * srcrect, - Uint32 target_format, int w, int h, void *pixels, - int pitch); -void SDL_SW_DestroyYUVTexture(SDL_SW_YUVTexture * swdata); - -/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/SDL-mobile/src/render/mmx.h b/src/SDL-mobile/src/render/mmx.h deleted file mode 100644 index 3bd00ac23..000000000 --- a/src/SDL-mobile/src/render/mmx.h +++ /dev/null @@ -1,642 +0,0 @@ -/* mmx.h - - MultiMedia eXtensions GCC interface library for IA32. - - To use this library, simply include this header file - and compile with GCC. You MUST have inlining enabled - in order for mmx_ok() to work; this can be done by - simply using -O on the GCC command line. - - Compiling with -DMMX_TRACE will cause detailed trace - output to be sent to stderr for each mmx operation. - This adds lots of code, and obviously slows execution to - a crawl, but can be very useful for debugging. - - THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY - EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT - LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY - AND FITNESS FOR ANY PARTICULAR PURPOSE. - - 1997-99 by H. Dietz and R. Fisher - - Notes: - It appears that the latest gas has the pand problem fixed, therefore - I'll undefine BROKEN_PAND by default. -*/ - -#ifndef _MMX_H -#define _MMX_H - - -/* Warning: at this writing, the version of GAS packaged - with most Linux distributions does not handle the - parallel AND operation mnemonic correctly. If the - symbol BROKEN_PAND is defined, a slower alternative - coding will be used. If execution of mmxtest results - in an illegal instruction fault, define this symbol. -*/ -#undef BROKEN_PAND - - -/* The type of an value that fits in an MMX register - (note that long long constant values MUST be suffixed - by LL and unsigned long long values by ULL, lest - they be truncated by the compiler) -*/ -typedef union -{ - long long q; /* Quadword (64-bit) value */ - unsigned long long uq; /* Unsigned Quadword */ - int d[2]; /* 2 Doubleword (32-bit) values */ - unsigned int ud[2]; /* 2 Unsigned Doubleword */ - short w[4]; /* 4 Word (16-bit) values */ - unsigned short uw[4]; /* 4 Unsigned Word */ - char b[8]; /* 8 Byte (8-bit) values */ - unsigned char ub[8]; /* 8 Unsigned Byte */ - float s[2]; /* Single-precision (32-bit) value */ -} __attribute__ ((aligned(8))) mmx_t; /* On an 8-byte (64-bit) boundary */ - - -#if 0 -/* Function to test if multimedia instructions are supported... -*/ -inline extern int -mm_support(void) -{ - /* Returns 1 if MMX instructions are supported, - 3 if Cyrix MMX and Extended MMX instructions are supported - 5 if AMD MMX and 3DNow! instructions are supported - 0 if hardware does not support any of these - */ - register int rval = 0; - - __asm__ __volatile__( - /* See if CPUID instruction is supported ... */ - /* ... Get copies of EFLAGS into eax and ecx */ - "pushf\n\t" - "popl %%eax\n\t" "movl %%eax, %%ecx\n\t" - /* ... Toggle the ID bit in one copy and store */ - /* to the EFLAGS reg */ - "xorl $0x200000, %%eax\n\t" - "push %%eax\n\t" "popf\n\t" - /* ... Get the (hopefully modified) EFLAGS */ - "pushf\n\t" "popl %%eax\n\t" - /* ... Compare and test result */ - "xorl %%eax, %%ecx\n\t" "testl $0x200000, %%ecx\n\t" "jz NotSupported1\n\t" /* CPUID not supported */ - /* Get standard CPUID information, and - go to a specific vendor section */ - "movl $0, %%eax\n\t" "cpuid\n\t" - /* Check for Intel */ - "cmpl $0x756e6547, %%ebx\n\t" - "jne TryAMD\n\t" - "cmpl $0x49656e69, %%edx\n\t" - "jne TryAMD\n\t" - "cmpl $0x6c65746e, %%ecx\n" - "jne TryAMD\n\t" "jmp Intel\n\t" - /* Check for AMD */ - "\nTryAMD:\n\t" - "cmpl $0x68747541, %%ebx\n\t" - "jne TryCyrix\n\t" - "cmpl $0x69746e65, %%edx\n\t" - "jne TryCyrix\n\t" - "cmpl $0x444d4163, %%ecx\n" - "jne TryCyrix\n\t" "jmp AMD\n\t" - /* Check for Cyrix */ - "\nTryCyrix:\n\t" - "cmpl $0x69727943, %%ebx\n\t" - "jne NotSupported2\n\t" - "cmpl $0x736e4978, %%edx\n\t" - "jne NotSupported3\n\t" - "cmpl $0x64616574, %%ecx\n\t" - "jne NotSupported4\n\t" - /* Drop through to Cyrix... */ - /* Cyrix Section */ - /* See if extended CPUID level 80000001 is supported */ - /* The value of CPUID/80000001 for the 6x86MX is undefined - according to the Cyrix CPU Detection Guide (Preliminary - Rev. 1.01 table 1), so we'll check the value of eax for - CPUID/0 to see if standard CPUID level 2 is supported. - According to the table, the only CPU which supports level - 2 is also the only one which supports extended CPUID levels. - */ - "cmpl $0x2, %%eax\n\t" "jne MMXtest\n\t" /* Use standard CPUID instead */ - /* Extended CPUID supported (in theory), so get extended - features */ - "movl $0x80000001, %%eax\n\t" "cpuid\n\t" "testl $0x00800000, %%eax\n\t" /* Test for MMX */ - "jz NotSupported5\n\t" /* MMX not supported */ - "testl $0x01000000, %%eax\n\t" /* Test for Ext'd MMX */ - "jnz EMMXSupported\n\t" "movl $1, %0:\n\n\t" /* MMX Supported */ - "jmp Return\n\n" "EMMXSupported:\n\t" "movl $3, %0:\n\n\t" /* EMMX and MMX Supported */ - "jmp Return\n\t" - /* AMD Section */ - "AMD:\n\t" - /* See if extended CPUID is supported */ - "movl $0x80000000, %%eax\n\t" "cpuid\n\t" "cmpl $0x80000000, %%eax\n\t" "jl MMXtest\n\t" /* Use standard CPUID instead */ - /* Extended CPUID supported, so get extended features */ - "movl $0x80000001, %%eax\n\t" "cpuid\n\t" "testl $0x00800000, %%edx\n\t" /* Test for MMX */ - "jz NotSupported6\n\t" /* MMX not supported */ - "testl $0x80000000, %%edx\n\t" /* Test for 3DNow! */ - "jnz ThreeDNowSupported\n\t" "movl $1, %0:\n\n\t" /* MMX Supported */ - "jmp Return\n\n" "ThreeDNowSupported:\n\t" "movl $5, %0:\n\n\t" /* 3DNow! and MMX Supported */ - "jmp Return\n\t" - /* Intel Section */ - "Intel:\n\t" - /* Check for MMX */ - "MMXtest:\n\t" "movl $1, %%eax\n\t" "cpuid\n\t" "testl $0x00800000, %%edx\n\t" /* Test for MMX */ - "jz NotSupported7\n\t" /* MMX Not supported */ - "movl $1, %0:\n\n\t" /* MMX Supported */ - "jmp Return\n\t" - /* Nothing supported */ - "\nNotSupported1:\n\t" "#movl $101, %0:\n\n\t" "\nNotSupported2:\n\t" "#movl $102, %0:\n\n\t" "\nNotSupported3:\n\t" "#movl $103, %0:\n\n\t" "\nNotSupported4:\n\t" "#movl $104, %0:\n\n\t" "\nNotSupported5:\n\t" "#movl $105, %0:\n\n\t" "\nNotSupported6:\n\t" "#movl $106, %0:\n\n\t" "\nNotSupported7:\n\t" "#movl $107, %0:\n\n\t" "movl $0, %0:\n\n\t" "Return:\n\t":"=a"(rval): /* no input */ - :"eax", "ebx", "ecx", "edx"); - - /* Return */ - return (rval); -} - -/* Function to test if mmx instructions are supported... -*/ -inline extern int -mmx_ok(void) -{ - /* Returns 1 if MMX instructions are supported, 0 otherwise */ - return (mm_support() & 0x1); -} -#endif - -/* Helper functions for the instruction macros that follow... - (note that memory-to-register, m2r, instructions are nearly - as efficient as register-to-register, r2r, instructions; - however, memory-to-memory instructions are really simulated - as a convenience, and are only 1/3 as efficient) -*/ -#ifdef MMX_TRACE - -/* Include the stuff for printing a trace to stderr... -*/ - -#define mmx_i2r(op, imm, reg) \ - { \ - mmx_t mmx_trace; \ - mmx_trace.uq = (imm); \ - printf(#op "_i2r(" #imm "=0x%08x%08x, ", \ - mmx_trace.d[1], mmx_trace.d[0]); \ - __asm__ __volatile__ ("movq %%" #reg ", %0" \ - : "=X" (mmx_trace) \ - : /* nothing */ ); \ - printf(#reg "=0x%08x%08x) => ", \ - mmx_trace.d[1], mmx_trace.d[0]); \ - __asm__ __volatile__ (#op " %0, %%" #reg \ - : /* nothing */ \ - : "X" (imm)); \ - __asm__ __volatile__ ("movq %%" #reg ", %0" \ - : "=X" (mmx_trace) \ - : /* nothing */ ); \ - printf(#reg "=0x%08x%08x\n", \ - mmx_trace.d[1], mmx_trace.d[0]); \ - } - -#define mmx_m2r(op, mem, reg) \ - { \ - mmx_t mmx_trace; \ - mmx_trace = (mem); \ - printf(#op "_m2r(" #mem "=0x%08x%08x, ", \ - mmx_trace.d[1], mmx_trace.d[0]); \ - __asm__ __volatile__ ("movq %%" #reg ", %0" \ - : "=X" (mmx_trace) \ - : /* nothing */ ); \ - printf(#reg "=0x%08x%08x) => ", \ - mmx_trace.d[1], mmx_trace.d[0]); \ - __asm__ __volatile__ (#op " %0, %%" #reg \ - : /* nothing */ \ - : "X" (mem)); \ - __asm__ __volatile__ ("movq %%" #reg ", %0" \ - : "=X" (mmx_trace) \ - : /* nothing */ ); \ - printf(#reg "=0x%08x%08x\n", \ - mmx_trace.d[1], mmx_trace.d[0]); \ - } - -#define mmx_r2m(op, reg, mem) \ - { \ - mmx_t mmx_trace; \ - __asm__ __volatile__ ("movq %%" #reg ", %0" \ - : "=X" (mmx_trace) \ - : /* nothing */ ); \ - printf(#op "_r2m(" #reg "=0x%08x%08x, ", \ - mmx_trace.d[1], mmx_trace.d[0]); \ - mmx_trace = (mem); \ - printf(#mem "=0x%08x%08x) => ", \ - mmx_trace.d[1], mmx_trace.d[0]); \ - __asm__ __volatile__ (#op " %%" #reg ", %0" \ - : "=X" (mem) \ - : /* nothing */ ); \ - mmx_trace = (mem); \ - printf(#mem "=0x%08x%08x\n", \ - mmx_trace.d[1], mmx_trace.d[0]); \ - } - -#define mmx_r2r(op, regs, regd) \ - { \ - mmx_t mmx_trace; \ - __asm__ __volatile__ ("movq %%" #regs ", %0" \ - : "=X" (mmx_trace) \ - : /* nothing */ ); \ - printf(#op "_r2r(" #regs "=0x%08x%08x, ", \ - mmx_trace.d[1], mmx_trace.d[0]); \ - __asm__ __volatile__ ("movq %%" #regd ", %0" \ - : "=X" (mmx_trace) \ - : /* nothing */ ); \ - printf(#regd "=0x%08x%08x) => ", \ - mmx_trace.d[1], mmx_trace.d[0]); \ - __asm__ __volatile__ (#op " %" #regs ", %" #regd); \ - __asm__ __volatile__ ("movq %%" #regd ", %0" \ - : "=X" (mmx_trace) \ - : /* nothing */ ); \ - printf(#regd "=0x%08x%08x\n", \ - mmx_trace.d[1], mmx_trace.d[0]); \ - } - -#define mmx_m2m(op, mems, memd) \ - { \ - mmx_t mmx_trace; \ - mmx_trace = (mems); \ - printf(#op "_m2m(" #mems "=0x%08x%08x, ", \ - mmx_trace.d[1], mmx_trace.d[0]); \ - mmx_trace = (memd); \ - printf(#memd "=0x%08x%08x) => ", \ - mmx_trace.d[1], mmx_trace.d[0]); \ - __asm__ __volatile__ ("movq %0, %%mm0\n\t" \ - #op " %1, %%mm0\n\t" \ - "movq %%mm0, %0" \ - : "=X" (memd) \ - : "X" (mems)); \ - mmx_trace = (memd); \ - printf(#memd "=0x%08x%08x\n", \ - mmx_trace.d[1], mmx_trace.d[0]); \ - } - -#else - -/* These macros are a lot simpler without the tracing... -*/ - -#define mmx_i2r(op, imm, reg) \ - __asm__ __volatile__ (#op " %0, %%" #reg \ - : /* nothing */ \ - : "X" (imm) ) - -#define mmx_m2r(op, mem, reg) \ - __asm__ __volatile__ (#op " %0, %%" #reg \ - : /* nothing */ \ - : "m" (mem)) - -#define mmx_r2m(op, reg, mem) \ - __asm__ __volatile__ (#op " %%" #reg ", %0" \ - : "=m" (mem) \ - : /* nothing */ ) - -#define mmx_r2r(op, regs, regd) \ - __asm__ __volatile__ (#op " %" #regs ", %" #regd) - -#define mmx_m2m(op, mems, memd) \ - __asm__ __volatile__ ("movq %0, %%mm0\n\t" \ - #op " %1, %%mm0\n\t" \ - "movq %%mm0, %0" \ - : "=X" (memd) \ - : "X" (mems)) - -#endif - - -/* 1x64 MOVe Quadword - (this is both a load and a store... - in fact, it is the only way to store) -*/ -#define movq_m2r(var, reg) mmx_m2r(movq, var, reg) -#define movq_r2m(reg, var) mmx_r2m(movq, reg, var) -#define movq_r2r(regs, regd) mmx_r2r(movq, regs, regd) -#define movq(vars, vard) \ - __asm__ __volatile__ ("movq %1, %%mm0\n\t" \ - "movq %%mm0, %0" \ - : "=X" (vard) \ - : "X" (vars)) - - -/* 1x32 MOVe Doubleword - (like movq, this is both load and store... - but is most useful for moving things between - mmx registers and ordinary registers) -*/ -#define movd_m2r(var, reg) mmx_m2r(movd, var, reg) -#define movd_r2m(reg, var) mmx_r2m(movd, reg, var) -#define movd_r2r(regs, regd) mmx_r2r(movd, regs, regd) -#define movd(vars, vard) \ - __asm__ __volatile__ ("movd %1, %%mm0\n\t" \ - "movd %%mm0, %0" \ - : "=X" (vard) \ - : "X" (vars)) - - -/* 2x32, 4x16, and 8x8 Parallel ADDs -*/ -#define paddd_m2r(var, reg) mmx_m2r(paddd, var, reg) -#define paddd_r2r(regs, regd) mmx_r2r(paddd, regs, regd) -#define paddd(vars, vard) mmx_m2m(paddd, vars, vard) - -#define paddw_m2r(var, reg) mmx_m2r(paddw, var, reg) -#define paddw_r2r(regs, regd) mmx_r2r(paddw, regs, regd) -#define paddw(vars, vard) mmx_m2m(paddw, vars, vard) - -#define paddb_m2r(var, reg) mmx_m2r(paddb, var, reg) -#define paddb_r2r(regs, regd) mmx_r2r(paddb, regs, regd) -#define paddb(vars, vard) mmx_m2m(paddb, vars, vard) - - -/* 4x16 and 8x8 Parallel ADDs using Saturation arithmetic -*/ -#define paddsw_m2r(var, reg) mmx_m2r(paddsw, var, reg) -#define paddsw_r2r(regs, regd) mmx_r2r(paddsw, regs, regd) -#define paddsw(vars, vard) mmx_m2m(paddsw, vars, vard) - -#define paddsb_m2r(var, reg) mmx_m2r(paddsb, var, reg) -#define paddsb_r2r(regs, regd) mmx_r2r(paddsb, regs, regd) -#define paddsb(vars, vard) mmx_m2m(paddsb, vars, vard) - - -/* 4x16 and 8x8 Parallel ADDs using Unsigned Saturation arithmetic -*/ -#define paddusw_m2r(var, reg) mmx_m2r(paddusw, var, reg) -#define paddusw_r2r(regs, regd) mmx_r2r(paddusw, regs, regd) -#define paddusw(vars, vard) mmx_m2m(paddusw, vars, vard) - -#define paddusb_m2r(var, reg) mmx_m2r(paddusb, var, reg) -#define paddusb_r2r(regs, regd) mmx_r2r(paddusb, regs, regd) -#define paddusb(vars, vard) mmx_m2m(paddusb, vars, vard) - - -/* 2x32, 4x16, and 8x8 Parallel SUBs -*/ -#define psubd_m2r(var, reg) mmx_m2r(psubd, var, reg) -#define psubd_r2r(regs, regd) mmx_r2r(psubd, regs, regd) -#define psubd(vars, vard) mmx_m2m(psubd, vars, vard) - -#define psubw_m2r(var, reg) mmx_m2r(psubw, var, reg) -#define psubw_r2r(regs, regd) mmx_r2r(psubw, regs, regd) -#define psubw(vars, vard) mmx_m2m(psubw, vars, vard) - -#define psubb_m2r(var, reg) mmx_m2r(psubb, var, reg) -#define psubb_r2r(regs, regd) mmx_r2r(psubb, regs, regd) -#define psubb(vars, vard) mmx_m2m(psubb, vars, vard) - - -/* 4x16 and 8x8 Parallel SUBs using Saturation arithmetic -*/ -#define psubsw_m2r(var, reg) mmx_m2r(psubsw, var, reg) -#define psubsw_r2r(regs, regd) mmx_r2r(psubsw, regs, regd) -#define psubsw(vars, vard) mmx_m2m(psubsw, vars, vard) - -#define psubsb_m2r(var, reg) mmx_m2r(psubsb, var, reg) -#define psubsb_r2r(regs, regd) mmx_r2r(psubsb, regs, regd) -#define psubsb(vars, vard) mmx_m2m(psubsb, vars, vard) - - -/* 4x16 and 8x8 Parallel SUBs using Unsigned Saturation arithmetic -*/ -#define psubusw_m2r(var, reg) mmx_m2r(psubusw, var, reg) -#define psubusw_r2r(regs, regd) mmx_r2r(psubusw, regs, regd) -#define psubusw(vars, vard) mmx_m2m(psubusw, vars, vard) - -#define psubusb_m2r(var, reg) mmx_m2r(psubusb, var, reg) -#define psubusb_r2r(regs, regd) mmx_r2r(psubusb, regs, regd) -#define psubusb(vars, vard) mmx_m2m(psubusb, vars, vard) - - -/* 4x16 Parallel MULs giving Low 4x16 portions of results -*/ -#define pmullw_m2r(var, reg) mmx_m2r(pmullw, var, reg) -#define pmullw_r2r(regs, regd) mmx_r2r(pmullw, regs, regd) -#define pmullw(vars, vard) mmx_m2m(pmullw, vars, vard) - - -/* 4x16 Parallel MULs giving High 4x16 portions of results -*/ -#define pmulhw_m2r(var, reg) mmx_m2r(pmulhw, var, reg) -#define pmulhw_r2r(regs, regd) mmx_r2r(pmulhw, regs, regd) -#define pmulhw(vars, vard) mmx_m2m(pmulhw, vars, vard) - - -/* 4x16->2x32 Parallel Mul-ADD - (muls like pmullw, then adds adjacent 16-bit fields - in the multiply result to make the final 2x32 result) -*/ -#define pmaddwd_m2r(var, reg) mmx_m2r(pmaddwd, var, reg) -#define pmaddwd_r2r(regs, regd) mmx_r2r(pmaddwd, regs, regd) -#define pmaddwd(vars, vard) mmx_m2m(pmaddwd, vars, vard) - - -/* 1x64 bitwise AND -*/ -#ifdef BROKEN_PAND -#define pand_m2r(var, reg) \ - { \ - mmx_m2r(pandn, (mmx_t) -1LL, reg); \ - mmx_m2r(pandn, var, reg); \ - } -#define pand_r2r(regs, regd) \ - { \ - mmx_m2r(pandn, (mmx_t) -1LL, regd); \ - mmx_r2r(pandn, regs, regd) \ - } -#define pand(vars, vard) \ - { \ - movq_m2r(vard, mm0); \ - mmx_m2r(pandn, (mmx_t) -1LL, mm0); \ - mmx_m2r(pandn, vars, mm0); \ - movq_r2m(mm0, vard); \ - } -#else -#define pand_m2r(var, reg) mmx_m2r(pand, var, reg) -#define pand_r2r(regs, regd) mmx_r2r(pand, regs, regd) -#define pand(vars, vard) mmx_m2m(pand, vars, vard) -#endif - - -/* 1x64 bitwise AND with Not the destination -*/ -#define pandn_m2r(var, reg) mmx_m2r(pandn, var, reg) -#define pandn_r2r(regs, regd) mmx_r2r(pandn, regs, regd) -#define pandn(vars, vard) mmx_m2m(pandn, vars, vard) - - -/* 1x64 bitwise OR -*/ -#define por_m2r(var, reg) mmx_m2r(por, var, reg) -#define por_r2r(regs, regd) mmx_r2r(por, regs, regd) -#define por(vars, vard) mmx_m2m(por, vars, vard) - - -/* 1x64 bitwise eXclusive OR -*/ -#define pxor_m2r(var, reg) mmx_m2r(pxor, var, reg) -#define pxor_r2r(regs, regd) mmx_r2r(pxor, regs, regd) -#define pxor(vars, vard) mmx_m2m(pxor, vars, vard) - - -/* 2x32, 4x16, and 8x8 Parallel CoMPare for EQuality - (resulting fields are either 0 or -1) -*/ -#define pcmpeqd_m2r(var, reg) mmx_m2r(pcmpeqd, var, reg) -#define pcmpeqd_r2r(regs, regd) mmx_r2r(pcmpeqd, regs, regd) -#define pcmpeqd(vars, vard) mmx_m2m(pcmpeqd, vars, vard) - -#define pcmpeqw_m2r(var, reg) mmx_m2r(pcmpeqw, var, reg) -#define pcmpeqw_r2r(regs, regd) mmx_r2r(pcmpeqw, regs, regd) -#define pcmpeqw(vars, vard) mmx_m2m(pcmpeqw, vars, vard) - -#define pcmpeqb_m2r(var, reg) mmx_m2r(pcmpeqb, var, reg) -#define pcmpeqb_r2r(regs, regd) mmx_r2r(pcmpeqb, regs, regd) -#define pcmpeqb(vars, vard) mmx_m2m(pcmpeqb, vars, vard) - - -/* 2x32, 4x16, and 8x8 Parallel CoMPare for Greater Than - (resulting fields are either 0 or -1) -*/ -#define pcmpgtd_m2r(var, reg) mmx_m2r(pcmpgtd, var, reg) -#define pcmpgtd_r2r(regs, regd) mmx_r2r(pcmpgtd, regs, regd) -#define pcmpgtd(vars, vard) mmx_m2m(pcmpgtd, vars, vard) - -#define pcmpgtw_m2r(var, reg) mmx_m2r(pcmpgtw, var, reg) -#define pcmpgtw_r2r(regs, regd) mmx_r2r(pcmpgtw, regs, regd) -#define pcmpgtw(vars, vard) mmx_m2m(pcmpgtw, vars, vard) - -#define pcmpgtb_m2r(var, reg) mmx_m2r(pcmpgtb, var, reg) -#define pcmpgtb_r2r(regs, regd) mmx_r2r(pcmpgtb, regs, regd) -#define pcmpgtb(vars, vard) mmx_m2m(pcmpgtb, vars, vard) - - -/* 1x64, 2x32, and 4x16 Parallel Shift Left Logical -*/ -#define psllq_i2r(imm, reg) mmx_i2r(psllq, imm, reg) -#define psllq_m2r(var, reg) mmx_m2r(psllq, var, reg) -#define psllq_r2r(regs, regd) mmx_r2r(psllq, regs, regd) -#define psllq(vars, vard) mmx_m2m(psllq, vars, vard) - -#define pslld_i2r(imm, reg) mmx_i2r(pslld, imm, reg) -#define pslld_m2r(var, reg) mmx_m2r(pslld, var, reg) -#define pslld_r2r(regs, regd) mmx_r2r(pslld, regs, regd) -#define pslld(vars, vard) mmx_m2m(pslld, vars, vard) - -#define psllw_i2r(imm, reg) mmx_i2r(psllw, imm, reg) -#define psllw_m2r(var, reg) mmx_m2r(psllw, var, reg) -#define psllw_r2r(regs, regd) mmx_r2r(psllw, regs, regd) -#define psllw(vars, vard) mmx_m2m(psllw, vars, vard) - - -/* 1x64, 2x32, and 4x16 Parallel Shift Right Logical -*/ -#define psrlq_i2r(imm, reg) mmx_i2r(psrlq, imm, reg) -#define psrlq_m2r(var, reg) mmx_m2r(psrlq, var, reg) -#define psrlq_r2r(regs, regd) mmx_r2r(psrlq, regs, regd) -#define psrlq(vars, vard) mmx_m2m(psrlq, vars, vard) - -#define psrld_i2r(imm, reg) mmx_i2r(psrld, imm, reg) -#define psrld_m2r(var, reg) mmx_m2r(psrld, var, reg) -#define psrld_r2r(regs, regd) mmx_r2r(psrld, regs, regd) -#define psrld(vars, vard) mmx_m2m(psrld, vars, vard) - -#define psrlw_i2r(imm, reg) mmx_i2r(psrlw, imm, reg) -#define psrlw_m2r(var, reg) mmx_m2r(psrlw, var, reg) -#define psrlw_r2r(regs, regd) mmx_r2r(psrlw, regs, regd) -#define psrlw(vars, vard) mmx_m2m(psrlw, vars, vard) - - -/* 2x32 and 4x16 Parallel Shift Right Arithmetic -*/ -#define psrad_i2r(imm, reg) mmx_i2r(psrad, imm, reg) -#define psrad_m2r(var, reg) mmx_m2r(psrad, var, reg) -#define psrad_r2r(regs, regd) mmx_r2r(psrad, regs, regd) -#define psrad(vars, vard) mmx_m2m(psrad, vars, vard) - -#define psraw_i2r(imm, reg) mmx_i2r(psraw, imm, reg) -#define psraw_m2r(var, reg) mmx_m2r(psraw, var, reg) -#define psraw_r2r(regs, regd) mmx_r2r(psraw, regs, regd) -#define psraw(vars, vard) mmx_m2m(psraw, vars, vard) - - -/* 2x32->4x16 and 4x16->8x8 PACK and Signed Saturate - (packs source and dest fields into dest in that order) -*/ -#define packssdw_m2r(var, reg) mmx_m2r(packssdw, var, reg) -#define packssdw_r2r(regs, regd) mmx_r2r(packssdw, regs, regd) -#define packssdw(vars, vard) mmx_m2m(packssdw, vars, vard) - -#define packsswb_m2r(var, reg) mmx_m2r(packsswb, var, reg) -#define packsswb_r2r(regs, regd) mmx_r2r(packsswb, regs, regd) -#define packsswb(vars, vard) mmx_m2m(packsswb, vars, vard) - - -/* 4x16->8x8 PACK and Unsigned Saturate - (packs source and dest fields into dest in that order) -*/ -#define packuswb_m2r(var, reg) mmx_m2r(packuswb, var, reg) -#define packuswb_r2r(regs, regd) mmx_r2r(packuswb, regs, regd) -#define packuswb(vars, vard) mmx_m2m(packuswb, vars, vard) - - -/* 2x32->1x64, 4x16->2x32, and 8x8->4x16 UNPaCK Low - (interleaves low half of dest with low half of source - as padding in each result field) -*/ -#define punpckldq_m2r(var, reg) mmx_m2r(punpckldq, var, reg) -#define punpckldq_r2r(regs, regd) mmx_r2r(punpckldq, regs, regd) -#define punpckldq(vars, vard) mmx_m2m(punpckldq, vars, vard) - -#define punpcklwd_m2r(var, reg) mmx_m2r(punpcklwd, var, reg) -#define punpcklwd_r2r(regs, regd) mmx_r2r(punpcklwd, regs, regd) -#define punpcklwd(vars, vard) mmx_m2m(punpcklwd, vars, vard) - -#define punpcklbw_m2r(var, reg) mmx_m2r(punpcklbw, var, reg) -#define punpcklbw_r2r(regs, regd) mmx_r2r(punpcklbw, regs, regd) -#define punpcklbw(vars, vard) mmx_m2m(punpcklbw, vars, vard) - - -/* 2x32->1x64, 4x16->2x32, and 8x8->4x16 UNPaCK High - (interleaves high half of dest with high half of source - as padding in each result field) -*/ -#define punpckhdq_m2r(var, reg) mmx_m2r(punpckhdq, var, reg) -#define punpckhdq_r2r(regs, regd) mmx_r2r(punpckhdq, regs, regd) -#define punpckhdq(vars, vard) mmx_m2m(punpckhdq, vars, vard) - -#define punpckhwd_m2r(var, reg) mmx_m2r(punpckhwd, var, reg) -#define punpckhwd_r2r(regs, regd) mmx_r2r(punpckhwd, regs, regd) -#define punpckhwd(vars, vard) mmx_m2m(punpckhwd, vars, vard) - -#define punpckhbw_m2r(var, reg) mmx_m2r(punpckhbw, var, reg) -#define punpckhbw_r2r(regs, regd) mmx_r2r(punpckhbw, regs, regd) -#define punpckhbw(vars, vard) mmx_m2m(punpckhbw, vars, vard) - - -/* Empty MMx State - (used to clean-up when going from mmx to float use - of the registers that are shared by both; note that - there is no float-to-mmx operation needed, because - only the float tag word info is corruptible) -*/ -#ifdef MMX_TRACE - -#define emms() \ - { \ - printf("emms()\n"); \ - __asm__ __volatile__ ("emms"); \ - } - -#else - -#define emms() __asm__ __volatile__ ("emms") - -#endif - -#endif -/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/SDL-mobile/src/render/opengl/SDL_glfuncs.h b/src/SDL-mobile/src/render/opengl/SDL_glfuncs.h deleted file mode 100644 index ea3644ac1..000000000 --- a/src/SDL-mobile/src/render/opengl/SDL_glfuncs.h +++ /dev/null @@ -1,455 +0,0 @@ -/* list of OpenGL functions sorted alphabetically - If you need to use a GL function from the SDL video subsystem, - change it's entry from SDL_PROC_UNUSED to SDL_PROC and rebuild. -*/ -#define SDL_PROC_UNUSED(ret,func,params) - -SDL_PROC_UNUSED(void, glAccum, (GLenum, GLfloat)) -SDL_PROC_UNUSED(void, glAlphaFunc, (GLenum, GLclampf)) -SDL_PROC_UNUSED(GLboolean, glAreTexturesResident, - (GLsizei, const GLuint *, GLboolean *)) -SDL_PROC_UNUSED(void, glArrayElement, (GLint)) -SDL_PROC(void, glBegin, (GLenum)) -SDL_PROC(void, glBindTexture, (GLenum, GLuint)) -SDL_PROC_UNUSED(void, glBitmap, - (GLsizei, GLsizei, GLfloat, GLfloat, GLfloat, GLfloat, - const GLubyte *)) -SDL_PROC(void, glBlendFunc, (GLenum, GLenum)) -SDL_PROC_UNUSED(void, glCallList, (GLuint)) -SDL_PROC_UNUSED(void, glCallLists, (GLsizei, GLenum, const GLvoid *)) -SDL_PROC(void, glClear, (GLbitfield)) -SDL_PROC_UNUSED(void, glClearAccum, (GLfloat, GLfloat, GLfloat, GLfloat)) -SDL_PROC(void, glClearColor, (GLclampf, GLclampf, GLclampf, GLclampf)) -SDL_PROC_UNUSED(void, glClearDepth, (GLclampd)) -SDL_PROC_UNUSED(void, glClearIndex, (GLfloat)) -SDL_PROC_UNUSED(void, glClearStencil, (GLint)) -SDL_PROC_UNUSED(void, glClipPlane, (GLenum, const GLdouble *)) -SDL_PROC_UNUSED(void, glColor3b, (GLbyte, GLbyte, GLbyte)) -SDL_PROC_UNUSED(void, glColor3bv, (const GLbyte *)) -SDL_PROC_UNUSED(void, glColor3d, (GLdouble, GLdouble, GLdouble)) -SDL_PROC_UNUSED(void, glColor3dv, (const GLdouble *)) -SDL_PROC_UNUSED(void, glColor3f, (GLfloat, GLfloat, GLfloat)) -SDL_PROC_UNUSED(void, glColor3fv, (const GLfloat *)) -SDL_PROC_UNUSED(void, glColor3i, (GLint, GLint, GLint)) -SDL_PROC_UNUSED(void, glColor3iv, (const GLint *)) -SDL_PROC_UNUSED(void, glColor3s, (GLshort, GLshort, GLshort)) -SDL_PROC_UNUSED(void, glColor3sv, (const GLshort *)) -SDL_PROC_UNUSED(void, glColor3ub, (GLubyte, GLubyte, GLubyte)) -SDL_PROC_UNUSED(void, glColor3ubv, (const GLubyte *)) -SDL_PROC_UNUSED(void, glColor3ui, (GLuint, GLuint, GLuint)) -SDL_PROC_UNUSED(void, glColor3uiv, (const GLuint *)) -SDL_PROC_UNUSED(void, glColor3us, (GLushort, GLushort, GLushort)) -SDL_PROC_UNUSED(void, glColor3usv, (const GLushort *)) -SDL_PROC_UNUSED(void, glColor4b, (GLbyte, GLbyte, GLbyte, GLbyte)) -SDL_PROC_UNUSED(void, glColor4bv, (const GLbyte *)) -SDL_PROC_UNUSED(void, glColor4d, (GLdouble, GLdouble, GLdouble, GLdouble)) -SDL_PROC_UNUSED(void, glColor4dv, (const GLdouble *)) -SDL_PROC(void, glColor4f, (GLfloat, GLfloat, GLfloat, GLfloat)) -SDL_PROC_UNUSED(void, glColor4fv, (const GLfloat *)) -SDL_PROC_UNUSED(void, glColor4i, (GLint, GLint, GLint, GLint)) -SDL_PROC_UNUSED(void, glColor4iv, (const GLint *)) -SDL_PROC_UNUSED(void, glColor4s, (GLshort, GLshort, GLshort, GLshort)) -SDL_PROC_UNUSED(void, glColor4sv, (const GLshort *)) -SDL_PROC_UNUSED(void, glColor4ub, - (GLubyte red, GLubyte green, GLubyte blue, GLubyte alpha)) -SDL_PROC_UNUSED(void, glColor4ubv, (const GLubyte * v)) -SDL_PROC_UNUSED(void, glColor4ui, - (GLuint red, GLuint green, GLuint blue, GLuint alpha)) -SDL_PROC_UNUSED(void, glColor4uiv, (const GLuint * v)) -SDL_PROC_UNUSED(void, glColor4us, - (GLushort red, GLushort green, GLushort blue, GLushort alpha)) -SDL_PROC_UNUSED(void, glColor4usv, (const GLushort * v)) -SDL_PROC_UNUSED(void, glColorMask, - (GLboolean red, GLboolean green, GLboolean blue, - GLboolean alpha)) -SDL_PROC_UNUSED(void, glColorMaterial, (GLenum face, GLenum mode)) -SDL_PROC_UNUSED(void, glColorPointer, - (GLint size, GLenum type, GLsizei stride, - const GLvoid * pointer)) -SDL_PROC_UNUSED(void, glCopyPixels, - (GLint x, GLint y, GLsizei width, GLsizei height, - GLenum type)) -SDL_PROC_UNUSED(void, glCopyTexImage1D, - (GLenum target, GLint level, GLenum internalFormat, GLint x, - GLint y, GLsizei width, GLint border)) -SDL_PROC_UNUSED(void, glCopyTexImage2D, - (GLenum target, GLint level, GLenum internalFormat, GLint x, - GLint y, GLsizei width, GLsizei height, GLint border)) -SDL_PROC_UNUSED(void, glCopyTexSubImage1D, - (GLenum target, GLint level, GLint xoffset, GLint x, GLint y, - GLsizei width)) -SDL_PROC_UNUSED(void, glCopyTexSubImage2D, - (GLenum target, GLint level, GLint xoffset, GLint yoffset, - GLint x, GLint y, GLsizei width, GLsizei height)) -SDL_PROC_UNUSED(void, glCullFace, (GLenum mode)) -SDL_PROC_UNUSED(void, glDeleteLists, (GLuint list, GLsizei range)) -SDL_PROC(void, glDeleteTextures, (GLsizei n, const GLuint * textures)) -SDL_PROC_UNUSED(void, glDepthFunc, (GLenum func)) -SDL_PROC_UNUSED(void, glDepthMask, (GLboolean flag)) -SDL_PROC_UNUSED(void, glDepthRange, (GLclampd zNear, GLclampd zFar)) -SDL_PROC(void, glDisable, (GLenum cap)) -SDL_PROC_UNUSED(void, glDisableClientState, (GLenum array)) -SDL_PROC_UNUSED(void, glDrawArrays, (GLenum mode, GLint first, GLsizei count)) -SDL_PROC_UNUSED(void, glDrawBuffer, (GLenum mode)) -SDL_PROC_UNUSED(void, glDrawElements, - (GLenum mode, GLsizei count, GLenum type, - const GLvoid * indices)) -SDL_PROC(void, glDrawPixels, - (GLsizei width, GLsizei height, GLenum format, GLenum type, - const GLvoid * pixels)) -SDL_PROC_UNUSED(void, glEdgeFlag, (GLboolean flag)) -SDL_PROC_UNUSED(void, glEdgeFlagPointer, - (GLsizei stride, const GLvoid * pointer)) -SDL_PROC_UNUSED(void, glEdgeFlagv, (const GLboolean * flag)) -SDL_PROC(void, glEnable, (GLenum cap)) -SDL_PROC_UNUSED(void, glEnableClientState, (GLenum array)) -SDL_PROC(void, glEnd, (void)) -SDL_PROC_UNUSED(void, glEndList, (void)) -SDL_PROC_UNUSED(void, glEvalCoord1d, (GLdouble u)) -SDL_PROC_UNUSED(void, glEvalCoord1dv, (const GLdouble * u)) -SDL_PROC_UNUSED(void, glEvalCoord1f, (GLfloat u)) -SDL_PROC_UNUSED(void, glEvalCoord1fv, (const GLfloat * u)) -SDL_PROC_UNUSED(void, glEvalCoord2d, (GLdouble u, GLdouble v)) -SDL_PROC_UNUSED(void, glEvalCoord2dv, (const GLdouble * u)) -SDL_PROC_UNUSED(void, glEvalCoord2f, (GLfloat u, GLfloat v)) -SDL_PROC_UNUSED(void, glEvalCoord2fv, (const GLfloat * u)) -SDL_PROC_UNUSED(void, glEvalMesh1, (GLenum mode, GLint i1, GLint i2)) -SDL_PROC_UNUSED(void, glEvalMesh2, - (GLenum mode, GLint i1, GLint i2, GLint j1, GLint j2)) -SDL_PROC_UNUSED(void, glEvalPoint1, (GLint i)) -SDL_PROC_UNUSED(void, glEvalPoint2, (GLint i, GLint j)) -SDL_PROC_UNUSED(void, glFeedbackBuffer, - (GLsizei size, GLenum type, GLfloat * buffer)) -SDL_PROC_UNUSED(void, glFinish, (void)) -SDL_PROC_UNUSED(void, glFlush, (void)) -SDL_PROC_UNUSED(void, glFogf, (GLenum pname, GLfloat param)) -SDL_PROC_UNUSED(void, glFogfv, (GLenum pname, const GLfloat * params)) -SDL_PROC_UNUSED(void, glFogi, (GLenum pname, GLint param)) -SDL_PROC_UNUSED(void, glFogiv, (GLenum pname, const GLint * params)) -SDL_PROC_UNUSED(void, glFrontFace, (GLenum mode)) -SDL_PROC_UNUSED(void, glFrustum, - (GLdouble left, GLdouble right, GLdouble bottom, - GLdouble top, GLdouble zNear, GLdouble zFar)) -SDL_PROC_UNUSED(GLuint, glGenLists, (GLsizei range)) -SDL_PROC(void, glGenTextures, (GLsizei n, GLuint * textures)) -SDL_PROC_UNUSED(void, glGetBooleanv, (GLenum pname, GLboolean * params)) -SDL_PROC_UNUSED(void, glGetClipPlane, (GLenum plane, GLdouble * equation)) -SDL_PROC_UNUSED(void, glGetDoublev, (GLenum pname, GLdouble * params)) -SDL_PROC(GLenum, glGetError, (void)) -SDL_PROC_UNUSED(void, glGetFloatv, (GLenum pname, GLfloat * params)) -SDL_PROC(void, glGetIntegerv, (GLenum pname, GLint * params)) -SDL_PROC_UNUSED(void, glGetLightfv, - (GLenum light, GLenum pname, GLfloat * params)) -SDL_PROC_UNUSED(void, glGetLightiv, - (GLenum light, GLenum pname, GLint * params)) -SDL_PROC_UNUSED(void, glGetMapdv, (GLenum target, GLenum query, GLdouble * v)) -SDL_PROC_UNUSED(void, glGetMapfv, (GLenum target, GLenum query, GLfloat * v)) -SDL_PROC_UNUSED(void, glGetMapiv, (GLenum target, GLenum query, GLint * v)) -SDL_PROC_UNUSED(void, glGetMaterialfv, - (GLenum face, GLenum pname, GLfloat * params)) -SDL_PROC_UNUSED(void, glGetMaterialiv, - (GLenum face, GLenum pname, GLint * params)) -SDL_PROC_UNUSED(void, glGetPixelMapfv, (GLenum map, GLfloat * values)) -SDL_PROC_UNUSED(void, glGetPixelMapuiv, (GLenum map, GLuint * values)) -SDL_PROC_UNUSED(void, glGetPixelMapusv, (GLenum map, GLushort * values)) -SDL_PROC_UNUSED(void, glGetPointerv, (GLenum pname, GLvoid * *params)) -SDL_PROC_UNUSED(void, glGetPolygonStipple, (GLubyte * mask)) -SDL_PROC(const GLubyte *, glGetString, (GLenum name)) -SDL_PROC_UNUSED(void, glGetTexEnvfv, - (GLenum target, GLenum pname, GLfloat * params)) -SDL_PROC_UNUSED(void, glGetTexEnviv, - (GLenum target, GLenum pname, GLint * params)) -SDL_PROC_UNUSED(void, glGetTexGendv, - (GLenum coord, GLenum pname, GLdouble * params)) -SDL_PROC_UNUSED(void, glGetTexGenfv, - (GLenum coord, GLenum pname, GLfloat * params)) -SDL_PROC_UNUSED(void, glGetTexGeniv, - (GLenum coord, GLenum pname, GLint * params)) -SDL_PROC_UNUSED(void, glGetTexImage, - (GLenum target, GLint level, GLenum format, GLenum type, - GLvoid * pixels)) -SDL_PROC_UNUSED(void, glGetTexLevelParameterfv, - (GLenum target, GLint level, GLenum pname, GLfloat * params)) -SDL_PROC_UNUSED(void, glGetTexLevelParameteriv, - (GLenum target, GLint level, GLenum pname, GLint * params)) -SDL_PROC_UNUSED(void, glGetTexParameterfv, - (GLenum target, GLenum pname, GLfloat * params)) -SDL_PROC_UNUSED(void, glGetTexParameteriv, - (GLenum target, GLenum pname, GLint * params)) -SDL_PROC_UNUSED(void, glHint, (GLenum target, GLenum mode)) -SDL_PROC_UNUSED(void, glIndexMask, (GLuint mask)) -SDL_PROC_UNUSED(void, glIndexPointer, - (GLenum type, GLsizei stride, const GLvoid * pointer)) -SDL_PROC_UNUSED(void, glIndexd, (GLdouble c)) -SDL_PROC_UNUSED(void, glIndexdv, (const GLdouble * c)) -SDL_PROC_UNUSED(void, glIndexf, (GLfloat c)) -SDL_PROC_UNUSED(void, glIndexfv, (const GLfloat * c)) -SDL_PROC_UNUSED(void, glIndexi, (GLint c)) -SDL_PROC_UNUSED(void, glIndexiv, (const GLint * c)) -SDL_PROC_UNUSED(void, glIndexs, (GLshort c)) -SDL_PROC_UNUSED(void, glIndexsv, (const GLshort * c)) -SDL_PROC_UNUSED(void, glIndexub, (GLubyte c)) -SDL_PROC_UNUSED(void, glIndexubv, (const GLubyte * c)) -SDL_PROC_UNUSED(void, glInitNames, (void)) -SDL_PROC_UNUSED(void, glInterleavedArrays, - (GLenum format, GLsizei stride, const GLvoid * pointer)) -SDL_PROC_UNUSED(GLboolean, glIsEnabled, (GLenum cap)) -SDL_PROC_UNUSED(GLboolean, glIsList, (GLuint list)) -SDL_PROC_UNUSED(GLboolean, glIsTexture, (GLuint texture)) -SDL_PROC_UNUSED(void, glLightModelf, (GLenum pname, GLfloat param)) -SDL_PROC_UNUSED(void, glLightModelfv, (GLenum pname, const GLfloat * params)) -SDL_PROC_UNUSED(void, glLightModeli, (GLenum pname, GLint param)) -SDL_PROC_UNUSED(void, glLightModeliv, (GLenum pname, const GLint * params)) -SDL_PROC_UNUSED(void, glLightf, (GLenum light, GLenum pname, GLfloat param)) -SDL_PROC_UNUSED(void, glLightfv, - (GLenum light, GLenum pname, const GLfloat * params)) -SDL_PROC_UNUSED(void, glLighti, (GLenum light, GLenum pname, GLint param)) -SDL_PROC_UNUSED(void, glLightiv, - (GLenum light, GLenum pname, const GLint * params)) -SDL_PROC_UNUSED(void, glLineStipple, (GLint factor, GLushort pattern)) -SDL_PROC(void, glLineWidth, (GLfloat width)) -SDL_PROC_UNUSED(void, glListBase, (GLuint base)) -SDL_PROC(void, glLoadIdentity, (void)) -SDL_PROC_UNUSED(void, glLoadMatrixd, (const GLdouble * m)) -SDL_PROC_UNUSED(void, glLoadMatrixf, (const GLfloat * m)) -SDL_PROC_UNUSED(void, glLoadName, (GLuint name)) -SDL_PROC_UNUSED(void, glLogicOp, (GLenum opcode)) -SDL_PROC_UNUSED(void, glMap1d, - (GLenum target, GLdouble u1, GLdouble u2, GLint stride, - GLint order, const GLdouble * points)) -SDL_PROC_UNUSED(void, glMap1f, - (GLenum target, GLfloat u1, GLfloat u2, GLint stride, - GLint order, const GLfloat * points)) -SDL_PROC_UNUSED(void, glMap2d, - (GLenum target, GLdouble u1, GLdouble u2, GLint ustride, - GLint uorder, GLdouble v1, GLdouble v2, GLint vstride, - GLint vorder, const GLdouble * points)) -SDL_PROC_UNUSED(void, glMap2f, - (GLenum target, GLfloat u1, GLfloat u2, GLint ustride, - GLint uorder, GLfloat v1, GLfloat v2, GLint vstride, - GLint vorder, const GLfloat * points)) -SDL_PROC_UNUSED(void, glMapGrid1d, (GLint un, GLdouble u1, GLdouble u2)) -SDL_PROC_UNUSED(void, glMapGrid1f, (GLint un, GLfloat u1, GLfloat u2)) -SDL_PROC_UNUSED(void, glMapGrid2d, - (GLint un, GLdouble u1, GLdouble u2, GLint vn, GLdouble v1, - GLdouble v2)) -SDL_PROC_UNUSED(void, glMapGrid2f, - (GLint un, GLfloat u1, GLfloat u2, GLint vn, GLfloat v1, - GLfloat v2)) -SDL_PROC_UNUSED(void, glMaterialf, (GLenum face, GLenum pname, GLfloat param)) -SDL_PROC_UNUSED(void, glMaterialfv, - (GLenum face, GLenum pname, const GLfloat * params)) -SDL_PROC_UNUSED(void, glMateriali, (GLenum face, GLenum pname, GLint param)) -SDL_PROC_UNUSED(void, glMaterialiv, - (GLenum face, GLenum pname, const GLint * params)) -SDL_PROC(void, glMatrixMode, (GLenum mode)) -SDL_PROC_UNUSED(void, glMultMatrixd, (const GLdouble * m)) -SDL_PROC_UNUSED(void, glMultMatrixf, (const GLfloat * m)) -SDL_PROC_UNUSED(void, glNewList, (GLuint list, GLenum mode)) -SDL_PROC_UNUSED(void, glNormal3b, (GLbyte nx, GLbyte ny, GLbyte nz)) -SDL_PROC_UNUSED(void, glNormal3bv, (const GLbyte * v)) -SDL_PROC_UNUSED(void, glNormal3d, (GLdouble nx, GLdouble ny, GLdouble nz)) -SDL_PROC_UNUSED(void, glNormal3dv, (const GLdouble * v)) -SDL_PROC_UNUSED(void, glNormal3f, (GLfloat nx, GLfloat ny, GLfloat nz)) -SDL_PROC_UNUSED(void, glNormal3fv, (const GLfloat * v)) -SDL_PROC_UNUSED(void, glNormal3i, (GLint nx, GLint ny, GLint nz)) -SDL_PROC_UNUSED(void, glNormal3iv, (const GLint * v)) -SDL_PROC_UNUSED(void, glNormal3s, (GLshort nx, GLshort ny, GLshort nz)) -SDL_PROC_UNUSED(void, glNormal3sv, (const GLshort * v)) -SDL_PROC_UNUSED(void, glNormalPointer, - (GLenum type, GLsizei stride, const GLvoid * pointer)) -SDL_PROC(void, glOrtho, - (GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, - GLdouble zNear, GLdouble zFar)) -SDL_PROC_UNUSED(void, glPassThrough, (GLfloat token)) -SDL_PROC_UNUSED(void, glPixelMapfv, - (GLenum map, GLsizei mapsize, const GLfloat * values)) -SDL_PROC_UNUSED(void, glPixelMapuiv, - (GLenum map, GLsizei mapsize, const GLuint * values)) -SDL_PROC_UNUSED(void, glPixelMapusv, - (GLenum map, GLsizei mapsize, const GLushort * values)) -SDL_PROC_UNUSED(void, glPixelStoref, (GLenum pname, GLfloat param)) -SDL_PROC(void, glPixelStorei, (GLenum pname, GLint param)) -SDL_PROC_UNUSED(void, glPixelTransferf, (GLenum pname, GLfloat param)) -SDL_PROC_UNUSED(void, glPixelTransferi, (GLenum pname, GLint param)) -SDL_PROC_UNUSED(void, glPixelZoom, (GLfloat xfactor, GLfloat yfactor)) -SDL_PROC(void, glPointSize, (GLfloat size)) -SDL_PROC_UNUSED(void, glPolygonMode, (GLenum face, GLenum mode)) -SDL_PROC_UNUSED(void, glPolygonOffset, (GLfloat factor, GLfloat units)) -SDL_PROC_UNUSED(void, glPolygonStipple, (const GLubyte * mask)) -SDL_PROC_UNUSED(void, glPopAttrib, (void)) -SDL_PROC_UNUSED(void, glPopClientAttrib, (void)) -SDL_PROC(void, glPopMatrix, (void)) -SDL_PROC_UNUSED(void, glPopName, (void)) -SDL_PROC_UNUSED(void, glPrioritizeTextures, - (GLsizei n, const GLuint * textures, - const GLclampf * priorities)) -SDL_PROC_UNUSED(void, glPushAttrib, (GLbitfield mask)) -SDL_PROC_UNUSED(void, glPushClientAttrib, (GLbitfield mask)) -SDL_PROC(void, glPushMatrix, (void)) -SDL_PROC_UNUSED(void, glPushName, (GLuint name)) -SDL_PROC_UNUSED(void, glRasterPos2d, (GLdouble x, GLdouble y)) -SDL_PROC_UNUSED(void, glRasterPos2dv, (const GLdouble * v)) -SDL_PROC_UNUSED(void, glRasterPos2f, (GLfloat x, GLfloat y)) -SDL_PROC_UNUSED(void, glRasterPos2fv, (const GLfloat * v)) -SDL_PROC(void, glRasterPos2i, (GLint x, GLint y)) -SDL_PROC_UNUSED(void, glRasterPos2iv, (const GLint * v)) -SDL_PROC_UNUSED(void, glRasterPos2s, (GLshort x, GLshort y)) -SDL_PROC_UNUSED(void, glRasterPos2sv, (const GLshort * v)) -SDL_PROC_UNUSED(void, glRasterPos3d, (GLdouble x, GLdouble y, GLdouble z)) -SDL_PROC_UNUSED(void, glRasterPos3dv, (const GLdouble * v)) -SDL_PROC_UNUSED(void, glRasterPos3f, (GLfloat x, GLfloat y, GLfloat z)) -SDL_PROC_UNUSED(void, glRasterPos3fv, (const GLfloat * v)) -SDL_PROC_UNUSED(void, glRasterPos3i, (GLint x, GLint y, GLint z)) -SDL_PROC_UNUSED(void, glRasterPos3iv, (const GLint * v)) -SDL_PROC_UNUSED(void, glRasterPos3s, (GLshort x, GLshort y, GLshort z)) -SDL_PROC_UNUSED(void, glRasterPos3sv, (const GLshort * v)) -SDL_PROC_UNUSED(void, glRasterPos4d, - (GLdouble x, GLdouble y, GLdouble z, GLdouble w)) -SDL_PROC_UNUSED(void, glRasterPos4dv, (const GLdouble * v)) -SDL_PROC_UNUSED(void, glRasterPos4f, - (GLfloat x, GLfloat y, GLfloat z, GLfloat w)) -SDL_PROC_UNUSED(void, glRasterPos4fv, (const GLfloat * v)) -SDL_PROC_UNUSED(void, glRasterPos4i, (GLint x, GLint y, GLint z, GLint w)) -SDL_PROC_UNUSED(void, glRasterPos4iv, (const GLint * v)) -SDL_PROC_UNUSED(void, glRasterPos4s, - (GLshort x, GLshort y, GLshort z, GLshort w)) -SDL_PROC_UNUSED(void, glRasterPos4sv, (const GLshort * v)) -SDL_PROC(void, glReadBuffer, (GLenum mode)) -SDL_PROC(void, glReadPixels, - (GLint x, GLint y, GLsizei width, GLsizei height, - GLenum format, GLenum type, GLvoid * pixels)) -SDL_PROC_UNUSED(void, glRectd, - (GLdouble x1, GLdouble y1, GLdouble x2, GLdouble y2)) -SDL_PROC_UNUSED(void, glRectdv, (const GLdouble * v1, const GLdouble * v2)) -SDL_PROC_UNUSED(void, glRectf, - (GLfloat x1, GLfloat y1, GLfloat x2, GLfloat y2)) -SDL_PROC_UNUSED(void, glRectfv, (const GLfloat * v1, const GLfloat * v2)) -SDL_PROC(void, glRecti, (GLint x1, GLint y1, GLint x2, GLint y2)) -SDL_PROC_UNUSED(void, glRectiv, (const GLint * v1, const GLint * v2)) -SDL_PROC_UNUSED(void, glRects, - (GLshort x1, GLshort y1, GLshort x2, GLshort y2)) -SDL_PROC_UNUSED(void, glRectsv, (const GLshort * v1, const GLshort * v2)) -SDL_PROC_UNUSED(GLint, glRenderMode, (GLenum mode)) -SDL_PROC(void, glRotated, - (GLdouble angle, GLdouble x, GLdouble y, GLdouble z)) -SDL_PROC_UNUSED(void, glRotatef, - (GLfloat angle, GLfloat x, GLfloat y, GLfloat z)) -SDL_PROC_UNUSED(void, glScaled, (GLdouble x, GLdouble y, GLdouble z)) -SDL_PROC_UNUSED(void, glScalef, (GLfloat x, GLfloat y, GLfloat z)) -SDL_PROC(void, glScissor, (GLint x, GLint y, GLsizei width, GLsizei height)) -SDL_PROC_UNUSED(void, glSelectBuffer, (GLsizei size, GLuint * buffer)) -SDL_PROC_UNUSED(void, glShadeModel, (GLenum mode)) -SDL_PROC_UNUSED(void, glStencilFunc, (GLenum func, GLint ref, GLuint mask)) -SDL_PROC_UNUSED(void, glStencilMask, (GLuint mask)) -SDL_PROC_UNUSED(void, glStencilOp, (GLenum fail, GLenum zfail, GLenum zpass)) -SDL_PROC_UNUSED(void, glTexCoord1d, (GLdouble s)) -SDL_PROC_UNUSED(void, glTexCoord1dv, (const GLdouble * v)) -SDL_PROC_UNUSED(void, glTexCoord1f, (GLfloat s)) -SDL_PROC_UNUSED(void, glTexCoord1fv, (const GLfloat * v)) -SDL_PROC_UNUSED(void, glTexCoord1i, (GLint s)) -SDL_PROC_UNUSED(void, glTexCoord1iv, (const GLint * v)) -SDL_PROC_UNUSED(void, glTexCoord1s, (GLshort s)) -SDL_PROC_UNUSED(void, glTexCoord1sv, (const GLshort * v)) -SDL_PROC_UNUSED(void, glTexCoord2d, (GLdouble s, GLdouble t)) -SDL_PROC_UNUSED(void, glTexCoord2dv, (const GLdouble * v)) -SDL_PROC(void, glTexCoord2f, (GLfloat s, GLfloat t)) -SDL_PROC_UNUSED(void, glTexCoord2fv, (const GLfloat * v)) -SDL_PROC_UNUSED(void, glTexCoord2i, (GLint s, GLint t)) -SDL_PROC_UNUSED(void, glTexCoord2iv, (const GLint * v)) -SDL_PROC_UNUSED(void, glTexCoord2s, (GLshort s, GLshort t)) -SDL_PROC_UNUSED(void, glTexCoord2sv, (const GLshort * v)) -SDL_PROC_UNUSED(void, glTexCoord3d, (GLdouble s, GLdouble t, GLdouble r)) -SDL_PROC_UNUSED(void, glTexCoord3dv, (const GLdouble * v)) -SDL_PROC_UNUSED(void, glTexCoord3f, (GLfloat s, GLfloat t, GLfloat r)) -SDL_PROC_UNUSED(void, glTexCoord3fv, (const GLfloat * v)) -SDL_PROC_UNUSED(void, glTexCoord3i, (GLint s, GLint t, GLint r)) -SDL_PROC_UNUSED(void, glTexCoord3iv, (const GLint * v)) -SDL_PROC_UNUSED(void, glTexCoord3s, (GLshort s, GLshort t, GLshort r)) -SDL_PROC_UNUSED(void, glTexCoord3sv, (const GLshort * v)) -SDL_PROC_UNUSED(void, glTexCoord4d, - (GLdouble s, GLdouble t, GLdouble r, GLdouble q)) -SDL_PROC_UNUSED(void, glTexCoord4dv, (const GLdouble * v)) -SDL_PROC_UNUSED(void, glTexCoord4f, - (GLfloat s, GLfloat t, GLfloat r, GLfloat q)) -SDL_PROC_UNUSED(void, glTexCoord4fv, (const GLfloat * v)) -SDL_PROC_UNUSED(void, glTexCoord4i, (GLint s, GLint t, GLint r, GLint q)) -SDL_PROC_UNUSED(void, glTexCoord4iv, (const GLint * v)) -SDL_PROC_UNUSED(void, glTexCoord4s, - (GLshort s, GLshort t, GLshort r, GLshort q)) -SDL_PROC_UNUSED(void, glTexCoord4sv, (const GLshort * v)) -SDL_PROC_UNUSED(void, glTexCoordPointer, - (GLint size, GLenum type, GLsizei stride, - const GLvoid * pointer)) -SDL_PROC(void, glTexEnvf, (GLenum target, GLenum pname, GLfloat param)) -SDL_PROC_UNUSED(void, glTexEnvfv, - (GLenum target, GLenum pname, const GLfloat * params)) -SDL_PROC_UNUSED(void, glTexEnvi, (GLenum target, GLenum pname, GLint param)) -SDL_PROC_UNUSED(void, glTexEnviv, - (GLenum target, GLenum pname, const GLint * params)) -SDL_PROC_UNUSED(void, glTexGend, (GLenum coord, GLenum pname, GLdouble param)) -SDL_PROC_UNUSED(void, glTexGendv, - (GLenum coord, GLenum pname, const GLdouble * params)) -SDL_PROC_UNUSED(void, glTexGenf, (GLenum coord, GLenum pname, GLfloat param)) -SDL_PROC_UNUSED(void, glTexGenfv, - (GLenum coord, GLenum pname, const GLfloat * params)) -SDL_PROC_UNUSED(void, glTexGeni, (GLenum coord, GLenum pname, GLint param)) -SDL_PROC_UNUSED(void, glTexGeniv, - (GLenum coord, GLenum pname, const GLint * params)) -SDL_PROC_UNUSED(void, glTexImage1D, - (GLenum target, GLint level, GLint internalformat, - GLsizei width, GLint border, GLenum format, GLenum type, - const GLvoid * pixels)) -SDL_PROC(void, glTexImage2D, - (GLenum target, GLint level, GLint internalformat, GLsizei width, - GLsizei height, GLint border, GLenum format, GLenum type, - const GLvoid * pixels)) -SDL_PROC_UNUSED(void, glTexParameterf, - (GLenum target, GLenum pname, GLfloat param)) -SDL_PROC_UNUSED(void, glTexParameterfv, - (GLenum target, GLenum pname, const GLfloat * params)) -SDL_PROC(void, glTexParameteri, (GLenum target, GLenum pname, GLint param)) -SDL_PROC_UNUSED(void, glTexParameteriv, - (GLenum target, GLenum pname, const GLint * params)) -SDL_PROC_UNUSED(void, glTexSubImage1D, - (GLenum target, GLint level, GLint xoffset, GLsizei width, - GLenum format, GLenum type, const GLvoid * pixels)) -SDL_PROC(void, glTexSubImage2D, - (GLenum target, GLint level, GLint xoffset, GLint yoffset, - GLsizei width, GLsizei height, GLenum format, GLenum type, - const GLvoid * pixels)) -SDL_PROC_UNUSED(void, glTranslated, (GLdouble x, GLdouble y, GLdouble z)) -SDL_PROC(void, glTranslatef, (GLfloat x, GLfloat y, GLfloat z)) -SDL_PROC_UNUSED(void, glVertex2d, (GLdouble x, GLdouble y)) -SDL_PROC_UNUSED(void, glVertex2dv, (const GLdouble * v)) -SDL_PROC(void, glVertex2f, (GLfloat x, GLfloat y)) -SDL_PROC_UNUSED(void, glVertex2fv, (const GLfloat * v)) -SDL_PROC_UNUSED(void, glVertex2i, (GLint x, GLint y)) -SDL_PROC_UNUSED(void, glVertex2iv, (const GLint * v)) -SDL_PROC_UNUSED(void, glVertex2s, (GLshort x, GLshort y)) -SDL_PROC_UNUSED(void, glVertex2sv, (const GLshort * v)) -SDL_PROC_UNUSED(void, glVertex3d, (GLdouble x, GLdouble y, GLdouble z)) -SDL_PROC_UNUSED(void, glVertex3dv, (const GLdouble * v)) -SDL_PROC_UNUSED(void, glVertex3f, (GLfloat x, GLfloat y, GLfloat z)) -SDL_PROC_UNUSED(void, glVertex3fv, (const GLfloat * v)) -SDL_PROC_UNUSED(void, glVertex3i, (GLint x, GLint y, GLint z)) -SDL_PROC_UNUSED(void, glVertex3iv, (const GLint * v)) -SDL_PROC_UNUSED(void, glVertex3s, (GLshort x, GLshort y, GLshort z)) -SDL_PROC_UNUSED(void, glVertex3sv, (const GLshort * v)) -SDL_PROC_UNUSED(void, glVertex4d, - (GLdouble x, GLdouble y, GLdouble z, GLdouble w)) -SDL_PROC_UNUSED(void, glVertex4dv, (const GLdouble * v)) -SDL_PROC_UNUSED(void, glVertex4f, - (GLfloat x, GLfloat y, GLfloat z, GLfloat w)) -SDL_PROC_UNUSED(void, glVertex4fv, (const GLfloat * v)) -SDL_PROC_UNUSED(void, glVertex4i, (GLint x, GLint y, GLint z, GLint w)) -SDL_PROC_UNUSED(void, glVertex4iv, (const GLint * v)) -SDL_PROC_UNUSED(void, glVertex4s, - (GLshort x, GLshort y, GLshort z, GLshort w)) -SDL_PROC_UNUSED(void, glVertex4sv, (const GLshort * v)) -SDL_PROC_UNUSED(void, glVertexPointer, - (GLint size, GLenum type, GLsizei stride, - const GLvoid * pointer)) -SDL_PROC(void, glViewport, (GLint x, GLint y, GLsizei width, GLsizei height)) - -/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/SDL-mobile/src/render/opengl/SDL_render_gl.c b/src/SDL-mobile/src/render/opengl/SDL_render_gl.c deleted file mode 100644 index adc1e6ffe..000000000 --- a/src/SDL-mobile/src/render/opengl/SDL_render_gl.c +++ /dev/null @@ -1,1281 +0,0 @@ -/* - Simple DirectMedia Layer - Copyright (C) 1997-2012 Sam Lantinga - - 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_OGL && !SDL_RENDER_DISABLED - -#include "SDL_hints.h" -#include "SDL_log.h" -#include "SDL_opengl.h" -#include "../SDL_sysrender.h" -#include "SDL_shaders_gl.h" - -#ifdef __MACOSX__ -#include -#endif - - -/* OpenGL renderer implementation */ - -/* Details on optimizing the texture path on Mac OS X: - http://developer.apple.com/library/mac/#documentation/GraphicsImaging/Conceptual/OpenGL-MacProgGuide/opengl_texturedata/opengl_texturedata.html -*/ - -/* Used to re-create the window with OpenGL capability */ -extern int SDL_RecreateWindow(SDL_Window * window, Uint32 flags); - -static const float inv255f = 1.0f / 255.0f; - -static SDL_Renderer *GL_CreateRenderer(SDL_Window * window, Uint32 flags); -static void GL_WindowEvent(SDL_Renderer * renderer, - const SDL_WindowEvent *event); -static int GL_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture); -static int GL_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture, - const SDL_Rect * rect, const void *pixels, - int pitch); -static int GL_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture, - const SDL_Rect * rect, void **pixels, int *pitch); -static void GL_UnlockTexture(SDL_Renderer * renderer, SDL_Texture * texture); -static int GL_SetRenderTarget(SDL_Renderer * renderer, SDL_Texture * texture); -static int GL_UpdateViewport(SDL_Renderer * renderer); -static int GL_RenderClear(SDL_Renderer * renderer); -static int GL_RenderDrawPoints(SDL_Renderer * renderer, - const SDL_Point * points, int count); -static int GL_RenderDrawLines(SDL_Renderer * renderer, - const SDL_Point * points, int count); -static int GL_RenderFillRects(SDL_Renderer * renderer, - const SDL_Rect * rects, int count); -static int GL_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture, - const SDL_Rect * srcrect, const SDL_Rect * dstrect); -static int GL_RenderCopyEx(SDL_Renderer * renderer, SDL_Texture * texture, - const SDL_Rect * srcrect, const SDL_Rect * dstrect, - const double angle, const SDL_Point *center, const SDL_RendererFlip flip); -static int GL_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect, - Uint32 pixel_format, void * pixels, int pitch); -static void GL_RenderPresent(SDL_Renderer * renderer); -static void GL_DestroyTexture(SDL_Renderer * renderer, SDL_Texture * texture); -static void GL_DestroyRenderer(SDL_Renderer * renderer); -static int GL_BindTexture (SDL_Renderer * renderer, SDL_Texture *texture, float *texw, float *texh); -static int GL_UnbindTexture (SDL_Renderer * renderer, SDL_Texture *texture); - -SDL_RenderDriver GL_RenderDriver = { - GL_CreateRenderer, - { - "opengl", - (SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC | SDL_RENDERER_TARGETTEXTURE), - 1, - {SDL_PIXELFORMAT_ARGB8888}, - 0, - 0} -}; - -typedef struct GL_FBOList GL_FBOList; - -struct GL_FBOList -{ - Uint32 w, h; - GLuint FBO; - GL_FBOList *next; -}; - -typedef struct -{ - SDL_GLContext context; - SDL_bool GL_ARB_texture_rectangle_supported; - struct { - GL_Shader shader; - Uint32 color; - int blendMode; - } current; - - SDL_bool GL_EXT_framebuffer_object_supported; - GL_FBOList *framebuffers; - - /* OpenGL functions */ -#define SDL_PROC(ret,func,params) ret (APIENTRY *func) params; -#include "SDL_glfuncs.h" -#undef SDL_PROC - - /* Multitexture support */ - SDL_bool GL_ARB_multitexture_supported; - PFNGLACTIVETEXTUREARBPROC glActiveTextureARB; - GLint num_texture_units; - - PFNGLGENFRAMEBUFFERSEXTPROC glGenFramebuffersEXT; - PFNGLDELETEFRAMEBUFFERSEXTPROC glDeleteFramebuffersEXT; - PFNGLFRAMEBUFFERTEXTURE2DEXTPROC glFramebufferTexture2DEXT; - PFNGLBINDFRAMEBUFFEREXTPROC glBindFramebufferEXT; - PFNGLCHECKFRAMEBUFFERSTATUSEXTPROC glCheckFramebufferStatusEXT; - - /* Shader support */ - GL_ShaderContext *shaders; - -} GL_RenderData; - -typedef struct -{ - GLuint texture; - GLenum type; - GLfloat texw; - GLfloat texh; - GLenum format; - GLenum formattype; - void *pixels; - int pitch; - SDL_Rect locked_rect; - - /* YV12 texture support */ - SDL_bool yuv; - GLuint utexture; - GLuint vtexture; - - GL_FBOList *fbo; -} GL_TextureData; - - -static void -GL_SetError(const char *prefix, GLenum result) -{ - const char *error; - - switch (result) { - case GL_NO_ERROR: - error = "GL_NO_ERROR"; - break; - case GL_INVALID_ENUM: - error = "GL_INVALID_ENUM"; - break; - case GL_INVALID_VALUE: - error = "GL_INVALID_VALUE"; - break; - case GL_INVALID_OPERATION: - error = "GL_INVALID_OPERATION"; - break; - case GL_STACK_OVERFLOW: - error = "GL_STACK_OVERFLOW"; - break; - case GL_STACK_UNDERFLOW: - error = "GL_STACK_UNDERFLOW"; - break; - case GL_OUT_OF_MEMORY: - error = "GL_OUT_OF_MEMORY"; - break; - case GL_TABLE_TOO_LARGE: - error = "GL_TABLE_TOO_LARGE"; - break; - default: - error = "UNKNOWN"; - break; - } - SDL_SetError("%s: %s", prefix, error); -} - -static int -GL_LoadFunctions(GL_RenderData * data) -{ -#ifdef __SDL_NOGETPROCADDR__ -#define SDL_PROC(ret,func,params) data->func=func; -#else -#define SDL_PROC(ret,func,params) \ - 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; \ - } \ - } while ( 0 ); -#endif /* __SDL_NOGETPROCADDR__ */ - -#include "SDL_glfuncs.h" -#undef SDL_PROC - return 0; -} - -static SDL_GLContext SDL_CurrentContext = NULL; - -static int -GL_ActivateRenderer(SDL_Renderer * renderer) -{ - GL_RenderData *data = (GL_RenderData *) renderer->driverdata; - - if (SDL_CurrentContext != data->context) { - if (SDL_GL_MakeCurrent(renderer->window, data->context) < 0) { - return -1; - } - SDL_CurrentContext = data->context; - - GL_UpdateViewport(renderer); - } - return 0; -} - -/* This is called if we need to invalidate all of the SDL OpenGL state */ -static void -GL_ResetState(SDL_Renderer *renderer) -{ - GL_RenderData *data = (GL_RenderData *) renderer->driverdata; - - if (SDL_CurrentContext == data->context) { - GL_UpdateViewport(renderer); - } else { - GL_ActivateRenderer(renderer); - } - - data->current.shader = SHADER_NONE; - data->current.color = 0; - data->current.blendMode = -1; - - data->glDisable(GL_DEPTH_TEST); - data->glDisable(GL_CULL_FACE); - /* This ended up causing video discrepancies between OpenGL and Direct3D */ - /*data->glEnable(GL_LINE_SMOOTH);*/ - - data->glMatrixMode(GL_MODELVIEW); - data->glLoadIdentity(); -} - - -GL_FBOList * -GL_GetFBO(GL_RenderData *data, Uint32 w, Uint32 h) -{ - GL_FBOList *result = data->framebuffers; - - while (result && ((result->w != w) || (result->h != h))) { - result = result->next; - } - - if (!result) { - result = SDL_malloc(sizeof(GL_FBOList)); - if (result) { - result->w = w; - result->h = h; - data->glGenFramebuffersEXT(1, &result->FBO); - result->next = data->framebuffers; - data->framebuffers = result; - } - } - return result; -} - -SDL_Renderer * -GL_CreateRenderer(SDL_Window * window, Uint32 flags) -{ - SDL_Renderer *renderer; - GL_RenderData *data; - const char *hint; - GLint value; - Uint32 window_flags; - - window_flags = SDL_GetWindowFlags(window); - if (!(window_flags & SDL_WINDOW_OPENGL)) { - if (SDL_RecreateWindow(window, window_flags | SDL_WINDOW_OPENGL) < 0) { - /* Uh oh, better try to put it back... */ - SDL_RecreateWindow(window, window_flags); - return NULL; - } - } - - renderer = (SDL_Renderer *) SDL_calloc(1, sizeof(*renderer)); - if (!renderer) { - SDL_OutOfMemory(); - return NULL; - } - - data = (GL_RenderData *) SDL_calloc(1, sizeof(*data)); - if (!data) { - GL_DestroyRenderer(renderer); - SDL_OutOfMemory(); - return NULL; - } - - renderer->WindowEvent = GL_WindowEvent; - renderer->CreateTexture = GL_CreateTexture; - renderer->UpdateTexture = GL_UpdateTexture; - renderer->LockTexture = GL_LockTexture; - renderer->UnlockTexture = GL_UnlockTexture; - renderer->SetRenderTarget = GL_SetRenderTarget; - renderer->UpdateViewport = GL_UpdateViewport; - renderer->RenderClear = GL_RenderClear; - renderer->RenderDrawPoints = GL_RenderDrawPoints; - renderer->RenderDrawLines = GL_RenderDrawLines; - renderer->RenderFillRects = GL_RenderFillRects; - renderer->RenderCopy = GL_RenderCopy; - renderer->RenderCopyEx = GL_RenderCopyEx; - renderer->RenderReadPixels = GL_RenderReadPixels; - renderer->RenderPresent = GL_RenderPresent; - renderer->DestroyTexture = GL_DestroyTexture; - renderer->DestroyRenderer = GL_DestroyRenderer; - renderer->GL_BindTexture = GL_BindTexture; - renderer->GL_UnbindTexture = GL_UnbindTexture; - renderer->info = GL_RenderDriver.info; - renderer->info.flags = SDL_RENDERER_ACCELERATED; - renderer->driverdata = data; - renderer->window = window; - - data->context = SDL_GL_CreateContext(window); - if (!data->context) { - GL_DestroyRenderer(renderer); - return NULL; - } - if (SDL_GL_MakeCurrent(window, data->context) < 0) { - GL_DestroyRenderer(renderer); - return NULL; - } - - if (GL_LoadFunctions(data) < 0) { - GL_DestroyRenderer(renderer); - return NULL; - } - -#ifdef __MACOSX__ - /* Enable multi-threaded rendering */ - /* Disabled until Ryan finishes his VBO/PBO code... - CGLEnable(CGLGetCurrentContext(), kCGLCEMPEngine); - */ -#endif - - if (flags & SDL_RENDERER_PRESENTVSYNC) { - SDL_GL_SetSwapInterval(1); - } else { - SDL_GL_SetSwapInterval(0); - } - if (SDL_GL_GetSwapInterval() > 0) { - renderer->info.flags |= SDL_RENDERER_PRESENTVSYNC; - } - - if (SDL_GL_ExtensionSupported("GL_ARB_texture_rectangle") - || SDL_GL_ExtensionSupported("GL_EXT_texture_rectangle")) { - data->GL_ARB_texture_rectangle_supported = SDL_TRUE; - data->glGetIntegerv(GL_MAX_RECTANGLE_TEXTURE_SIZE_ARB, &value); - renderer->info.max_texture_width = value; - renderer->info.max_texture_height = value; - } else { - data->glGetIntegerv(GL_MAX_TEXTURE_SIZE, &value); - renderer->info.max_texture_width = value; - renderer->info.max_texture_height = value; - } - - /* Check for multitexture support */ - if (SDL_GL_ExtensionSupported("GL_ARB_multitexture")) { - data->glActiveTextureARB = (PFNGLACTIVETEXTUREARBPROC) SDL_GL_GetProcAddress("glActiveTextureARB"); - if (data->glActiveTextureARB) { - data->GL_ARB_multitexture_supported = SDL_TRUE; - data->glGetIntegerv(GL_MAX_TEXTURE_UNITS_ARB, &data->num_texture_units); - } - } - - /* Check for shader support */ - hint = SDL_GetHint(SDL_HINT_RENDER_OPENGL_SHADERS); - if (!hint || *hint != '0') { - data->shaders = GL_CreateShaderContext(); - } - SDL_LogInfo(SDL_LOG_CATEGORY_RENDER, "OpenGL shaders: %s", - data->shaders ? "ENABLED" : "DISABLED"); - - /* We support YV12 textures using 3 textures and a shader */ - if (data->shaders && data->num_texture_units >= 3) { - renderer->info.texture_formats[renderer->info.num_texture_formats++] = SDL_PIXELFORMAT_YV12; - renderer->info.texture_formats[renderer->info.num_texture_formats++] = SDL_PIXELFORMAT_IYUV; - } - - if (SDL_GL_ExtensionSupported("GL_EXT_framebuffer_object")) { - data->GL_EXT_framebuffer_object_supported = SDL_TRUE; - data->glGenFramebuffersEXT = (PFNGLGENFRAMEBUFFERSEXTPROC) - SDL_GL_GetProcAddress("glGenFramebuffersEXT"); - data->glDeleteFramebuffersEXT = (PFNGLDELETEFRAMEBUFFERSEXTPROC) - SDL_GL_GetProcAddress("glDeleteFramebuffersEXT"); - data->glFramebufferTexture2DEXT = (PFNGLFRAMEBUFFERTEXTURE2DEXTPROC) - SDL_GL_GetProcAddress("glFramebufferTexture2DEXT"); - data->glBindFramebufferEXT = (PFNGLBINDFRAMEBUFFEREXTPROC) - SDL_GL_GetProcAddress("glBindFramebufferEXT"); - data->glCheckFramebufferStatusEXT = (PFNGLCHECKFRAMEBUFFERSTATUSEXTPROC) - SDL_GL_GetProcAddress("glCheckFramebufferStatusEXT"); - renderer->info.flags |= SDL_RENDERER_TARGETTEXTURE; - } - data->framebuffers = NULL; - - /* Set up parameters for rendering */ - GL_ResetState(renderer); - - return renderer; -} - -static void -GL_WindowEvent(SDL_Renderer * renderer, const SDL_WindowEvent *event) -{ - if (event->event == SDL_WINDOWEVENT_SIZE_CHANGED || - event->event == SDL_WINDOWEVENT_SHOWN || - event->event == SDL_WINDOWEVENT_HIDDEN) { - /* Rebind the context to the window area and update matrices */ - SDL_CurrentContext = NULL; - } -} - -static __inline__ int -power_of_2(int input) -{ - int value = 1; - - while (value < input) { - value <<= 1; - } - return value; -} - -static __inline__ SDL_bool -convert_format(GL_RenderData *renderdata, Uint32 pixel_format, - GLint* internalFormat, GLenum* format, GLenum* type) -{ - switch (pixel_format) { - case SDL_PIXELFORMAT_ARGB8888: - *internalFormat = GL_RGBA8; - *format = GL_BGRA; - *type = GL_UNSIGNED_INT_8_8_8_8_REV; - break; - case SDL_PIXELFORMAT_YV12: - case SDL_PIXELFORMAT_IYUV: - *internalFormat = GL_LUMINANCE; - *format = GL_LUMINANCE; - *type = GL_UNSIGNED_BYTE; - break; - default: - return SDL_FALSE; - } - return SDL_TRUE; -} - -static GLenum -GetScaleQuality(void) -{ - const char *hint = SDL_GetHint(SDL_HINT_RENDER_SCALE_QUALITY); - - if (!hint || *hint == '0' || SDL_strcasecmp(hint, "nearest") == 0) { - return GL_NEAREST; - } else { - return GL_LINEAR; - } -} - -static int -GL_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture) -{ - GL_RenderData *renderdata = (GL_RenderData *) renderer->driverdata; - GL_TextureData *data; - GLint internalFormat; - GLenum format, type; - int texture_w, texture_h; - GLenum scaleMode; - GLenum result; - - GL_ActivateRenderer(renderer); - - if (!convert_format(renderdata, texture->format, &internalFormat, - &format, &type)) { - SDL_SetError("Texture format %s not supported by OpenGL", - SDL_GetPixelFormatName(texture->format)); - return -1; - } - - data = (GL_TextureData *) SDL_calloc(1, sizeof(*data)); - if (!data) { - SDL_OutOfMemory(); - return -1; - } - - if (texture->access == SDL_TEXTUREACCESS_STREAMING) { - size_t size; - data->pitch = texture->w * SDL_BYTESPERPIXEL(texture->format); - size = texture->h * data->pitch; - if (texture->format == SDL_PIXELFORMAT_YV12 || - texture->format == SDL_PIXELFORMAT_IYUV) { - /* Need to add size for the U and V planes */ - size += (2 * (texture->h * data->pitch) / 4); - } - data->pixels = SDL_calloc(1, size); - if (!data->pixels) { - SDL_OutOfMemory(); - SDL_free(data); - return -1; - } - } - - texture->driverdata = data; - - if (texture->access == SDL_TEXTUREACCESS_TARGET) { - data->fbo = GL_GetFBO(renderdata, texture->w, texture->h); - } else { - data->fbo = NULL; - } - - renderdata->glGetError(); - renderdata->glGenTextures(1, &data->texture); - if ((renderdata->GL_ARB_texture_rectangle_supported) - /*&& texture->access != SDL_TEXTUREACCESS_TARGET*/){ - data->type = GL_TEXTURE_RECTANGLE_ARB; - texture_w = texture->w; - texture_h = texture->h; - data->texw = (GLfloat) texture_w; - data->texh = (GLfloat) texture_h; - } else { - data->type = GL_TEXTURE_2D; - texture_w = power_of_2(texture->w); - texture_h = power_of_2(texture->h); - data->texw = (GLfloat) (texture->w) / texture_w; - data->texh = (GLfloat) texture->h / texture_h; - } - - data->format = format; - data->formattype = type; - scaleMode = GetScaleQuality(); - renderdata->glEnable(data->type); - renderdata->glBindTexture(data->type, data->texture); - renderdata->glTexParameteri(data->type, GL_TEXTURE_MIN_FILTER, scaleMode); - renderdata->glTexParameteri(data->type, GL_TEXTURE_MAG_FILTER, scaleMode); - /* According to the spec, CLAMP_TO_EDGE is the default for TEXTURE_RECTANGLE - and setting it causes an INVALID_ENUM error in the latest NVidia drivers. - */ - if (data->type != GL_TEXTURE_RECTANGLE_ARB) { - renderdata->glTexParameteri(data->type, GL_TEXTURE_WRAP_S, - GL_CLAMP_TO_EDGE); - renderdata->glTexParameteri(data->type, GL_TEXTURE_WRAP_T, - GL_CLAMP_TO_EDGE); - } -#ifdef __MACOSX__ -#ifndef GL_TEXTURE_STORAGE_HINT_APPLE -#define GL_TEXTURE_STORAGE_HINT_APPLE 0x85BC -#endif -#ifndef STORAGE_CACHED_APPLE -#define STORAGE_CACHED_APPLE 0x85BE -#endif -#ifndef STORAGE_SHARED_APPLE -#define STORAGE_SHARED_APPLE 0x85BF -#endif - if (texture->access == SDL_TEXTUREACCESS_STREAMING) { - renderdata->glTexParameteri(data->type, GL_TEXTURE_STORAGE_HINT_APPLE, - GL_STORAGE_SHARED_APPLE); - } else { - renderdata->glTexParameteri(data->type, GL_TEXTURE_STORAGE_HINT_APPLE, - GL_STORAGE_CACHED_APPLE); - } - if (texture->access == SDL_TEXTUREACCESS_STREAMING - && texture->format == SDL_PIXELFORMAT_ARGB8888 - && (texture->w % 8) == 0) { - renderdata->glPixelStorei(GL_UNPACK_CLIENT_STORAGE_APPLE, GL_TRUE); - renderdata->glPixelStorei(GL_UNPACK_ALIGNMENT, 1); - renderdata->glPixelStorei(GL_UNPACK_ROW_LENGTH, - (data->pitch / SDL_BYTESPERPIXEL(texture->format))); - renderdata->glTexImage2D(data->type, 0, internalFormat, texture_w, - texture_h, 0, format, type, data->pixels); - renderdata->glPixelStorei(GL_UNPACK_CLIENT_STORAGE_APPLE, GL_FALSE); - } - else -#endif - { - renderdata->glTexImage2D(data->type, 0, internalFormat, texture_w, - texture_h, 0, format, type, NULL); - } - renderdata->glDisable(data->type); - result = renderdata->glGetError(); - if (result != GL_NO_ERROR) { - GL_SetError("glTexImage2D()", result); - return -1; - } - - if (texture->format == SDL_PIXELFORMAT_YV12 || - texture->format == SDL_PIXELFORMAT_IYUV) { - data->yuv = SDL_TRUE; - - renderdata->glGenTextures(1, &data->utexture); - renderdata->glGenTextures(1, &data->vtexture); - renderdata->glEnable(data->type); - - renderdata->glBindTexture(data->type, data->utexture); - renderdata->glTexParameteri(data->type, GL_TEXTURE_MIN_FILTER, - scaleMode); - renderdata->glTexParameteri(data->type, GL_TEXTURE_MAG_FILTER, - scaleMode); - renderdata->glTexParameteri(data->type, GL_TEXTURE_WRAP_S, - GL_CLAMP_TO_EDGE); - renderdata->glTexParameteri(data->type, GL_TEXTURE_WRAP_T, - GL_CLAMP_TO_EDGE); - renderdata->glTexImage2D(data->type, 0, internalFormat, texture_w/2, - texture_h/2, 0, format, type, NULL); - - renderdata->glBindTexture(data->type, data->vtexture); - renderdata->glTexParameteri(data->type, GL_TEXTURE_MIN_FILTER, - scaleMode); - renderdata->glTexParameteri(data->type, GL_TEXTURE_MAG_FILTER, - scaleMode); - renderdata->glTexParameteri(data->type, GL_TEXTURE_WRAP_S, - GL_CLAMP_TO_EDGE); - renderdata->glTexParameteri(data->type, GL_TEXTURE_WRAP_T, - GL_CLAMP_TO_EDGE); - renderdata->glTexImage2D(data->type, 0, internalFormat, texture_w/2, - texture_h/2, 0, format, type, NULL); - - renderdata->glDisable(data->type); - } - return 0; -} - -static int -GL_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture, - const SDL_Rect * rect, const void *pixels, int pitch) -{ - GL_RenderData *renderdata = (GL_RenderData *) renderer->driverdata; - GL_TextureData *data = (GL_TextureData *) texture->driverdata; - GLenum result; - - GL_ActivateRenderer(renderer); - - renderdata->glGetError(); - renderdata->glEnable(data->type); - renderdata->glBindTexture(data->type, data->texture); - renderdata->glPixelStorei(GL_UNPACK_ALIGNMENT, 1); - renderdata->glPixelStorei(GL_UNPACK_ROW_LENGTH, - (pitch / SDL_BYTESPERPIXEL(texture->format))); - renderdata->glTexSubImage2D(data->type, 0, rect->x, rect->y, rect->w, - rect->h, data->format, data->formattype, - pixels); - if (data->yuv) { - renderdata->glPixelStorei(GL_UNPACK_ROW_LENGTH, (pitch / 2)); - - /* Skip to the correct offset into the next texture */ - pixels = (const void*)((const Uint8*)pixels + rect->h * pitch); - if (texture->format == SDL_PIXELFORMAT_YV12) { - renderdata->glBindTexture(data->type, data->vtexture); - } else { - renderdata->glBindTexture(data->type, data->utexture); - } - renderdata->glTexSubImage2D(data->type, 0, rect->x/2, rect->y/2, - rect->w/2, rect->h/2, - data->format, data->formattype, pixels); - - /* Skip to the correct offset into the next texture */ - pixels = (const void*)((const Uint8*)pixels + (rect->h * pitch)/4); - if (texture->format == SDL_PIXELFORMAT_YV12) { - renderdata->glBindTexture(data->type, data->utexture); - } else { - renderdata->glBindTexture(data->type, data->vtexture); - } - renderdata->glTexSubImage2D(data->type, 0, rect->x/2, rect->y/2, - rect->w/2, rect->h/2, - data->format, data->formattype, pixels); - } - renderdata->glDisable(data->type); - result = renderdata->glGetError(); - if (result != GL_NO_ERROR) { - GL_SetError("glTexSubImage2D()", result); - return -1; - } - return 0; -} - -static int -GL_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture, - const SDL_Rect * rect, void **pixels, int *pitch) -{ - GL_TextureData *data = (GL_TextureData *) texture->driverdata; - - data->locked_rect = *rect; - *pixels = - (void *) ((Uint8 *) data->pixels + rect->y * data->pitch + - rect->x * SDL_BYTESPERPIXEL(texture->format)); - *pitch = data->pitch; - return 0; -} - -static void -GL_UnlockTexture(SDL_Renderer * renderer, SDL_Texture * texture) -{ - GL_TextureData *data = (GL_TextureData *) texture->driverdata; - const SDL_Rect *rect; - void *pixels; - - rect = &data->locked_rect; - pixels = - (void *) ((Uint8 *) data->pixels + rect->y * data->pitch + - rect->x * SDL_BYTESPERPIXEL(texture->format)); - GL_UpdateTexture(renderer, texture, rect, pixels, data->pitch); -} - -static int -GL_SetRenderTarget(SDL_Renderer * renderer, SDL_Texture * texture) -{ - GL_RenderData *data = (GL_RenderData *) renderer->driverdata; - GL_TextureData *texturedata; - GLenum status; - - GL_ActivateRenderer(renderer); - - if (texture == NULL) { - data->glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0); - return 0; - } - - texturedata = (GL_TextureData *) texture->driverdata; - data->glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, texturedata->fbo->FBO); - /* TODO: check if texture pixel format allows this operation */ - data->glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, texturedata->type, texturedata->texture, 0); - /* Check FBO status */ - status = data->glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT); - if (status != GL_FRAMEBUFFER_COMPLETE_EXT) { - SDL_SetError("glFramebufferTexture2DEXT() failed"); - return -1; - } - return 0; -} - -static int -GL_UpdateViewport(SDL_Renderer * renderer) -{ - GL_RenderData *data = (GL_RenderData *) renderer->driverdata; - - if (SDL_CurrentContext != data->context) { - /* We'll update the viewport after we rebind the context */ - return 0; - } - - data->glViewport(renderer->viewport.x, renderer->viewport.y, - renderer->viewport.w, renderer->viewport.h); - - data->glMatrixMode(GL_PROJECTION); - data->glLoadIdentity(); - if (renderer->target) { - data->glOrtho((GLdouble) 0, - (GLdouble) renderer->viewport.w, - (GLdouble) 0, - (GLdouble) renderer->viewport.h, - 0.0, 1.0); - } else { - data->glOrtho((GLdouble) 0, - (GLdouble) renderer->viewport.w, - (GLdouble) renderer->viewport.h, - (GLdouble) 0, - 0.0, 1.0); - } - return 0; -} - -static void -GL_SetShader(GL_RenderData * data, GL_Shader shader) -{ - if (data->shaders && shader != data->current.shader) { - GL_SelectShader(data->shaders, shader); - data->current.shader = shader; - } -} - -static void -GL_SetColor(GL_RenderData * data, Uint8 r, Uint8 g, Uint8 b, Uint8 a) -{ - Uint32 color = ((a << 24) | (r << 16) | (g << 8) | b); - - if (color != data->current.color) { - data->glColor4f((GLfloat) r * inv255f, - (GLfloat) g * inv255f, - (GLfloat) b * inv255f, - (GLfloat) a * inv255f); - data->current.color = color; - } -} - -static void -GL_SetBlendMode(GL_RenderData * data, int blendMode) -{ - if (blendMode != data->current.blendMode) { - switch (blendMode) { - case SDL_BLENDMODE_NONE: - data->glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); - data->glDisable(GL_BLEND); - break; - case SDL_BLENDMODE_BLEND: - data->glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); - data->glEnable(GL_BLEND); - data->glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - break; - case SDL_BLENDMODE_ADD: - data->glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); - data->glEnable(GL_BLEND); - data->glBlendFunc(GL_SRC_ALPHA, GL_ONE); - break; - case SDL_BLENDMODE_MOD: - data->glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); - data->glEnable(GL_BLEND); - data->glBlendFunc(GL_ZERO, GL_SRC_COLOR); - break; - } - data->current.blendMode = blendMode; - } -} - -static void -GL_SetDrawingState(SDL_Renderer * renderer) -{ - GL_RenderData *data = (GL_RenderData *) renderer->driverdata; - - GL_ActivateRenderer(renderer); - - GL_SetColor(data, renderer->r, - renderer->g, - renderer->b, - renderer->a); - - GL_SetBlendMode(data, renderer->blendMode); - - GL_SetShader(data, SHADER_SOLID); -} - -static int -GL_RenderClear(SDL_Renderer * renderer) -{ - GL_RenderData *data = (GL_RenderData *) renderer->driverdata; - - GL_ActivateRenderer(renderer); - - data->glClearColor((GLfloat) renderer->r * inv255f, - (GLfloat) renderer->g * inv255f, - (GLfloat) renderer->b * inv255f, - (GLfloat) renderer->a * inv255f); - - data->glClear(GL_COLOR_BUFFER_BIT); - - return 0; -} - -static int -GL_RenderDrawPoints(SDL_Renderer * renderer, const SDL_Point * points, - int count) -{ - GL_RenderData *data = (GL_RenderData *) renderer->driverdata; - int i; - - GL_SetDrawingState(renderer); - - data->glBegin(GL_POINTS); - for (i = 0; i < count; ++i) { - data->glVertex2f(0.5f + points[i].x, 0.5f + points[i].y); - } - data->glEnd(); - - return 0; -} - -static int -GL_RenderDrawLines(SDL_Renderer * renderer, const SDL_Point * points, - int count) -{ - GL_RenderData *data = (GL_RenderData *) renderer->driverdata; - int i; - - GL_SetDrawingState(renderer); - - if (count > 2 && - points[0].x == points[count-1].x && points[0].y == points[count-1].y) { - data->glBegin(GL_LINE_LOOP); - /* GL_LINE_LOOP takes care of the final segment */ - --count; - for (i = 0; i < count; ++i) { - data->glVertex2f(0.5f + points[i].x, 0.5f + points[i].y); - } - data->glEnd(); - } else { -#if defined(__APPLE__) || defined(__WIN32__) -#else - int x1, y1, x2, y2; -#endif - - data->glBegin(GL_LINE_STRIP); - for (i = 0; i < count; ++i) { - data->glVertex2f(0.5f + points[i].x, 0.5f + points[i].y); - } - data->glEnd(); - - /* The line is half open, so we need one more point to complete it. - * http://www.opengl.org/documentation/specs/version1.1/glspec1.1/node47.html - * If we have to, we can use vertical line and horizontal line textures - * for vertical and horizontal lines, and then create custom textures - * for diagonal lines and software render those. It's terrible, but at - * least it would be pixel perfect. - */ - data->glBegin(GL_POINTS); -#if defined(__APPLE__) || defined(__WIN32__) - /* Mac OS X and Windows seem to always leave the second point open */ - data->glVertex2f(0.5f + points[count-1].x, 0.5f + points[count-1].y); -#else - /* Linux seems to leave the right-most or bottom-most point open */ - x1 = points[0].x; - y1 = points[0].y; - x2 = points[count-1].x; - y2 = points[count-1].y; - - if (x1 > x2) { - data->glVertex2f(0.5f + x1, 0.5f + y1); - } else if (x2 > x1) { - data->glVertex2f(0.5f + x2, 0.5f + y2); - } else if (y1 > y2) { - data->glVertex2f(0.5f + x1, 0.5f + y1); - } else if (y2 > y1) { - data->glVertex2f(0.5f + x2, 0.5f + y2); - } -#endif - data->glEnd(); - } - - return 0; -} - -static int -GL_RenderFillRects(SDL_Renderer * renderer, const SDL_Rect * rects, int count) -{ - GL_RenderData *data = (GL_RenderData *) renderer->driverdata; - int i; - - GL_SetDrawingState(renderer); - - for (i = 0; i < count; ++i) { - const SDL_Rect *rect = &rects[i]; - - data->glRecti(rect->x, rect->y, rect->x + rect->w, rect->y + rect->h); - } - - return 0; -} - -static int -GL_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture, - const SDL_Rect * srcrect, const SDL_Rect * dstrect) -{ - GL_RenderData *data = (GL_RenderData *) renderer->driverdata; - GL_TextureData *texturedata = (GL_TextureData *) texture->driverdata; - int minx, miny, maxx, maxy; - GLfloat minu, maxu, minv, maxv; - - GL_ActivateRenderer(renderer); - - data->glEnable(texturedata->type); - if (texturedata->yuv) { - data->glActiveTextureARB(GL_TEXTURE2_ARB); - data->glBindTexture(texturedata->type, texturedata->vtexture); - - data->glActiveTextureARB(GL_TEXTURE1_ARB); - data->glBindTexture(texturedata->type, texturedata->utexture); - - data->glActiveTextureARB(GL_TEXTURE0_ARB); - } - data->glBindTexture(texturedata->type, texturedata->texture); - - if (texture->modMode) { - GL_SetColor(data, texture->r, texture->g, texture->b, texture->a); - } else { - GL_SetColor(data, 255, 255, 255, 255); - } - - GL_SetBlendMode(data, texture->blendMode); - - if (texturedata->yuv) { - GL_SetShader(data, SHADER_YV12); - } else { - GL_SetShader(data, SHADER_RGB); - } - - minx = dstrect->x; - miny = dstrect->y; - maxx = dstrect->x + dstrect->w; - maxy = dstrect->y + dstrect->h; - - minu = (GLfloat) srcrect->x / texture->w; - minu *= texturedata->texw; - maxu = (GLfloat) (srcrect->x + srcrect->w) / texture->w; - maxu *= texturedata->texw; - minv = (GLfloat) srcrect->y / texture->h; - minv *= texturedata->texh; - maxv = (GLfloat) (srcrect->y + srcrect->h) / texture->h; - maxv *= texturedata->texh; - - data->glBegin(GL_TRIANGLE_STRIP); - data->glTexCoord2f(minu, minv); - data->glVertex2f((GLfloat) minx, (GLfloat) miny); - data->glTexCoord2f(maxu, minv); - data->glVertex2f((GLfloat) maxx, (GLfloat) miny); - data->glTexCoord2f(minu, maxv); - data->glVertex2f((GLfloat) minx, (GLfloat) maxy); - data->glTexCoord2f(maxu, maxv); - data->glVertex2f((GLfloat) maxx, (GLfloat) maxy); - data->glEnd(); - - data->glDisable(texturedata->type); - - return 0; -} - -static int -GL_RenderCopyEx(SDL_Renderer * renderer, SDL_Texture * texture, - const SDL_Rect * srcrect, const SDL_Rect * dstrect, - const double angle, const SDL_Point *center, const SDL_RendererFlip flip) -{ - GL_RenderData *data = (GL_RenderData *) renderer->driverdata; - GL_TextureData *texturedata = (GL_TextureData *) texture->driverdata; - GLfloat minx, miny, maxx, maxy; - GLfloat centerx, centery; - GLfloat minu, maxu, minv, maxv; - GL_ActivateRenderer(renderer); - - data->glEnable(texturedata->type); - if (texturedata->yuv) { - data->glActiveTextureARB(GL_TEXTURE2_ARB); - data->glBindTexture(texturedata->type, texturedata->vtexture); - - data->glActiveTextureARB(GL_TEXTURE1_ARB); - data->glBindTexture(texturedata->type, texturedata->utexture); - - data->glActiveTextureARB(GL_TEXTURE0_ARB); - } - data->glBindTexture(texturedata->type, texturedata->texture); - - if (texture->modMode) { - GL_SetColor(data, texture->r, texture->g, texture->b, texture->a); - } else { - GL_SetColor(data, 255, 255, 255, 255); - } - - GL_SetBlendMode(data, texture->blendMode); - - if (texturedata->yuv) { - GL_SetShader(data, SHADER_YV12); - } else { - GL_SetShader(data, SHADER_RGB); - } - - centerx = (GLfloat)center->x; - centery = (GLfloat)center->y; - - if (flip & SDL_FLIP_HORIZONTAL) { - minx = (GLfloat) dstrect->w - centerx; - maxx = -centerx; - } - else { - minx = -centerx; - maxx = (GLfloat) dstrect->w - centerx; - } - - if (flip & SDL_FLIP_VERTICAL) { - miny = (GLfloat) dstrect->h - centery; - maxy = -centery; - } - else { - miny = -centery; - maxy = (GLfloat) dstrect->h - centery; - } - - minu = (GLfloat) srcrect->x / texture->w; - minu *= texturedata->texw; - maxu = (GLfloat) (srcrect->x + srcrect->w) / texture->w; - maxu *= texturedata->texw; - minv = (GLfloat) srcrect->y / texture->h; - minv *= texturedata->texh; - maxv = (GLfloat) (srcrect->y + srcrect->h) / texture->h; - maxv *= texturedata->texh; - - // Translate to flip, rotate, translate to position - data->glPushMatrix(); - data->glTranslatef((GLfloat)dstrect->x + centerx, (GLfloat)dstrect->y + centery, (GLfloat)0.0); - data->glRotated(angle, (GLdouble)0.0, (GLdouble)0.0, (GLdouble)1.0); - - data->glBegin(GL_TRIANGLE_STRIP); - data->glTexCoord2f(minu, minv); - data->glVertex2f(minx, miny); - data->glTexCoord2f(maxu, minv); - data->glVertex2f(maxx, miny); - data->glTexCoord2f(minu, maxv); - data->glVertex2f(minx, maxy); - data->glTexCoord2f(maxu, maxv); - data->glVertex2f(maxx, maxy); - data->glEnd(); - data->glPopMatrix(); - - data->glDisable(texturedata->type); - - return 0; -} - -static int -GL_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect, - Uint32 pixel_format, void * pixels, int pitch) -{ - GL_RenderData *data = (GL_RenderData *) renderer->driverdata; - SDL_Window *window = renderer->window; - Uint32 temp_format = SDL_PIXELFORMAT_ARGB8888; - void *temp_pixels; - int temp_pitch; - GLint internalFormat; - GLenum format, type; - Uint8 *src, *dst, *tmp; - int w, h, length, rows; - int status; - - GL_ActivateRenderer(renderer); - - temp_pitch = rect->w * SDL_BYTESPERPIXEL(temp_format); - temp_pixels = SDL_malloc(rect->h * temp_pitch); - if (!temp_pixels) { - SDL_OutOfMemory(); - return -1; - } - - convert_format(data, temp_format, &internalFormat, &format, &type); - - SDL_GetWindowSize(window, &w, &h); - - data->glPixelStorei(GL_PACK_ALIGNMENT, 1); - data->glPixelStorei(GL_PACK_ROW_LENGTH, - (temp_pitch / SDL_BYTESPERPIXEL(temp_format))); - - data->glReadPixels(rect->x, (h-rect->y)-rect->h, rect->w, rect->h, - format, type, temp_pixels); - - /* Flip the rows to be top-down */ - length = rect->w * SDL_BYTESPERPIXEL(temp_format); - src = (Uint8*)temp_pixels + (rect->h-1)*temp_pitch; - dst = (Uint8*)temp_pixels; - tmp = SDL_stack_alloc(Uint8, length); - rows = rect->h / 2; - while (rows--) { - SDL_memcpy(tmp, dst, length); - SDL_memcpy(dst, src, length); - SDL_memcpy(src, tmp, length); - dst += temp_pitch; - src -= temp_pitch; - } - SDL_stack_free(tmp); - - status = SDL_ConvertPixels(rect->w, rect->h, - temp_format, temp_pixels, temp_pitch, - pixel_format, pixels, pitch); - SDL_free(temp_pixels); - - return status; -} - -static void -GL_RenderPresent(SDL_Renderer * renderer) -{ - GL_ActivateRenderer(renderer); - - SDL_GL_SwapWindow(renderer->window); -} - -static void -GL_DestroyTexture(SDL_Renderer * renderer, SDL_Texture * texture) -{ - GL_RenderData *renderdata = (GL_RenderData *) renderer->driverdata; - GL_TextureData *data = (GL_TextureData *) texture->driverdata; - - GL_ActivateRenderer(renderer); - - if (!data) { - return; - } - if (data->texture) { - renderdata->glDeleteTextures(1, &data->texture); - } - if (data->yuv) { - renderdata->glDeleteTextures(1, &data->utexture); - renderdata->glDeleteTextures(1, &data->vtexture); - } - if (data->pixels) { - SDL_free(data->pixels); - } - SDL_free(data); - texture->driverdata = NULL; -} - -static void -GL_DestroyRenderer(SDL_Renderer * renderer) -{ - GL_RenderData *data = (GL_RenderData *) renderer->driverdata; - - if (data) { - if (data->shaders) { - GL_DestroyShaderContext(data->shaders); - } - if (data->context) { - while (data->framebuffers) { - GL_FBOList *nextnode = data->framebuffers->next; - /* delete the framebuffer object */ - data->glDeleteFramebuffersEXT(1, &data->framebuffers->FBO); - SDL_free(data->framebuffers); - data->framebuffers = nextnode; - } - /* SDL_GL_MakeCurrent(0, NULL); *//* doesn't do anything */ - SDL_GL_DeleteContext(data->context); - } - SDL_free(data); - } - SDL_free(renderer); -} - -static int GL_BindTexture (SDL_Renderer * renderer, SDL_Texture *texture, float *texw, float *texh) { - GL_RenderData *data = (GL_RenderData *) renderer->driverdata; - GL_TextureData *texturedata = (GL_TextureData *) texture->driverdata; - GL_ActivateRenderer(renderer); - - data->glEnable(texturedata->type); - if (texturedata->yuv) { - data->glActiveTextureARB(GL_TEXTURE2_ARB); - data->glBindTexture(texturedata->type, texturedata->vtexture); - - data->glActiveTextureARB(GL_TEXTURE1_ARB); - data->glBindTexture(texturedata->type, texturedata->utexture); - - data->glActiveTextureARB(GL_TEXTURE0_ARB); - } - data->glBindTexture(texturedata->type, texturedata->texture); - - if(texw) *texw = (float)texturedata->texw; - if(texh) *texh = (float)texturedata->texh; - - return 0; -} - -static int GL_UnbindTexture (SDL_Renderer * renderer, SDL_Texture *texture) { - GL_RenderData *data = (GL_RenderData *) renderer->driverdata; - GL_TextureData *texturedata = (GL_TextureData *) texture->driverdata; - GL_ActivateRenderer(renderer); - - if (texturedata->yuv) { - data->glActiveTextureARB(GL_TEXTURE2_ARB); - data->glDisable(texturedata->type); - - data->glActiveTextureARB(GL_TEXTURE1_ARB); - data->glDisable(texturedata->type); - - data->glActiveTextureARB(GL_TEXTURE0_ARB); - } - - data->glDisable(texturedata->type); - - return 0; -} - -#endif /* SDL_VIDEO_RENDER_OGL && !SDL_RENDER_DISABLED */ - -/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/SDL-mobile/src/render/opengl/SDL_shaders_gl.c b/src/SDL-mobile/src/render/opengl/SDL_shaders_gl.c deleted file mode 100644 index 88876c789..000000000 --- a/src/SDL-mobile/src/render/opengl/SDL_shaders_gl.c +++ /dev/null @@ -1,358 +0,0 @@ -/* - Simple DirectMedia Layer - Copyright (C) 1997-2012 Sam Lantinga - - 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_OGL && !SDL_RENDER_DISABLED - -#include "SDL_stdinc.h" -#include "SDL_log.h" -#include "SDL_opengl.h" -#include "SDL_video.h" -#include "SDL_shaders_gl.h" - -/* OpenGL shader implementation */ - -/*#define DEBUG_SHADERS*/ - -typedef struct -{ - GLhandleARB program; - GLhandleARB vert_shader; - GLhandleARB frag_shader; -} GL_ShaderData; - -struct GL_ShaderContext -{ - GLenum (*glGetError)(void); - - PFNGLATTACHOBJECTARBPROC glAttachObjectARB; - PFNGLCOMPILESHADERARBPROC glCompileShaderARB; - PFNGLCREATEPROGRAMOBJECTARBPROC glCreateProgramObjectARB; - PFNGLCREATESHADEROBJECTARBPROC glCreateShaderObjectARB; - PFNGLDELETEOBJECTARBPROC glDeleteObjectARB; - PFNGLGETINFOLOGARBPROC glGetInfoLogARB; - PFNGLGETOBJECTPARAMETERIVARBPROC glGetObjectParameterivARB; - PFNGLGETUNIFORMLOCATIONARBPROC glGetUniformLocationARB; - PFNGLLINKPROGRAMARBPROC glLinkProgramARB; - PFNGLSHADERSOURCEARBPROC glShaderSourceARB; - PFNGLUNIFORM1IARBPROC glUniform1iARB; - PFNGLUNIFORM1FARBPROC glUniform1fARB; - PFNGLUSEPROGRAMOBJECTARBPROC glUseProgramObjectARB; - - SDL_bool GL_ARB_texture_rectangle_supported; - - GL_ShaderData shaders[NUM_SHADERS]; -}; - -/* - * NOTE: Always use sampler2D, etc here. We'll #define them to the - * texture_rectangle versions if we choose to use that extension. - */ -static const char *shader_source[NUM_SHADERS][2] = -{ - /* SHADER_NONE */ - { NULL, NULL }, - - /* SHADER_SOLID */ - { - /* vertex shader */ -"varying vec4 v_color;\n" -"\n" -"void main()\n" -"{\n" -" gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;\n" -" v_color = gl_Color;\n" -"}", - /* fragment shader */ -"varying vec4 v_color;\n" -"\n" -"void main()\n" -"{\n" -" gl_FragColor = v_color;\n" -"}" - }, - - /* SHADER_RGB */ - { - /* vertex shader */ -"varying vec4 v_color;\n" -"varying vec2 v_texCoord;\n" -"\n" -"void main()\n" -"{\n" -" gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;\n" -" v_color = gl_Color;\n" -" v_texCoord = vec2(gl_MultiTexCoord0);\n" -"}", - /* fragment shader */ -"varying vec4 v_color;\n" -"varying vec2 v_texCoord;\n" -"uniform sampler2D tex0;\n" -"\n" -"void main()\n" -"{\n" -" gl_FragColor = texture2D(tex0, v_texCoord) * v_color;\n" -"}" - }, - - /* SHADER_YV12 */ - { - /* vertex shader */ -"varying vec4 v_color;\n" -"varying vec2 v_texCoord;\n" -"\n" -"void main()\n" -"{\n" -" gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;\n" -" v_color = gl_Color;\n" -" v_texCoord = vec2(gl_MultiTexCoord0);\n" -"}", - /* fragment shader */ -"varying vec4 v_color;\n" -"varying vec2 v_texCoord;\n" -"uniform sampler2D tex0; // Y \n" -"uniform sampler2D tex1; // U \n" -"uniform sampler2D tex2; // V \n" -"\n" -"// YUV offset \n" -"const vec3 offset = vec3(-0.0625, -0.5, -0.5);\n" -"\n" -"// RGB coefficients \n" -"const vec3 Rcoeff = vec3(1.164, 0.000, 1.596);\n" -"const vec3 Gcoeff = vec3(1.164, -0.391, -0.813);\n" -"const vec3 Bcoeff = vec3(1.164, 2.018, 0.000);\n" -"\n" -"void main()\n" -"{\n" -" vec2 tcoord;\n" -" vec3 yuv, rgb;\n" -"\n" -" // Get the Y value \n" -" tcoord = v_texCoord;\n" -" yuv.x = texture2D(tex0, tcoord).r;\n" -"\n" -" // Get the U and V values \n" -" tcoord *= 0.5;\n" -" yuv.y = texture2D(tex1, tcoord).r;\n" -" yuv.z = texture2D(tex2, tcoord).r;\n" -"\n" -" // Do the color transform \n" -" yuv += offset;\n" -" rgb.r = dot(yuv, Rcoeff);\n" -" rgb.g = dot(yuv, Gcoeff);\n" -" rgb.b = dot(yuv, Bcoeff);\n" -"\n" -" // That was easy. :) \n" -" gl_FragColor = vec4(rgb, 1.0) * v_color;\n" -"}" - }, -}; - -static SDL_bool -CompileShader(GL_ShaderContext *ctx, GLhandleARB shader, const char *defines, const char *source) -{ - GLint status; - const char *sources[2]; - - sources[0] = defines; - sources[1] = source; - - ctx->glShaderSourceARB(shader, SDL_arraysize(sources), sources, NULL); - ctx->glCompileShaderARB(shader); - ctx->glGetObjectParameterivARB(shader, GL_OBJECT_COMPILE_STATUS_ARB, &status); - if (status == 0) { - GLint length; - char *info; - - ctx->glGetObjectParameterivARB(shader, GL_OBJECT_INFO_LOG_LENGTH_ARB, &length); - info = SDL_stack_alloc(char, length+1); - ctx->glGetInfoLogARB(shader, length, NULL, info); - SDL_LogError(SDL_LOG_CATEGORY_RENDER, - "Failed to compile shader:\n%s%s\n%s", defines, source, info); -#ifdef DEBUG_SHADERS - fprintf(stderr, - "Failed to compile shader:\n%s%s\n%s", defines, source, info); -#endif - SDL_stack_free(info); - - return SDL_FALSE; - } else { - return SDL_TRUE; - } -} - -static SDL_bool -CompileShaderProgram(GL_ShaderContext *ctx, int index, GL_ShaderData *data) -{ - const int num_tmus_bound = 4; - const char *vert_defines = ""; - const char *frag_defines = ""; - int i; - GLint location; - - if (index == SHADER_NONE) { - return SDL_TRUE; - } - - ctx->glGetError(); - - /* Make sure we use the correct sampler type for our texture type */ - if (ctx->GL_ARB_texture_rectangle_supported) { - frag_defines = -"#define sampler2D sampler2DRect\n" -"#define texture2D texture2DRect\n"; - } - - /* Create one program object to rule them all */ - data->program = ctx->glCreateProgramObjectARB(); - - /* Create the vertex shader */ - data->vert_shader = ctx->glCreateShaderObjectARB(GL_VERTEX_SHADER_ARB); - if (!CompileShader(ctx, data->vert_shader, vert_defines, shader_source[index][0])) { - return SDL_FALSE; - } - - /* Create the fragment shader */ - data->frag_shader = ctx->glCreateShaderObjectARB(GL_FRAGMENT_SHADER_ARB); - if (!CompileShader(ctx, data->frag_shader, frag_defines, shader_source[index][1])) { - return SDL_FALSE; - } - - /* ... and in the darkness bind them */ - ctx->glAttachObjectARB(data->program, data->vert_shader); - ctx->glAttachObjectARB(data->program, data->frag_shader); - ctx->glLinkProgramARB(data->program); - - /* Set up some uniform variables */ - ctx->glUseProgramObjectARB(data->program); - for (i = 0; i < num_tmus_bound; ++i) { - char tex_name[5]; - SDL_snprintf(tex_name, SDL_arraysize(tex_name), "tex%d", i); - location = ctx->glGetUniformLocationARB(data->program, tex_name); - if (location >= 0) { - ctx->glUniform1iARB(location, i); - } - } - ctx->glUseProgramObjectARB(0); - - return (ctx->glGetError() == GL_NO_ERROR); -} - -static void -DestroyShaderProgram(GL_ShaderContext *ctx, GL_ShaderData *data) -{ - ctx->glDeleteObjectARB(data->vert_shader); - ctx->glDeleteObjectARB(data->frag_shader); - ctx->glDeleteObjectARB(data->program); -} - -GL_ShaderContext * -GL_CreateShaderContext() -{ - GL_ShaderContext *ctx; - SDL_bool shaders_supported; - int i; - - ctx = (GL_ShaderContext *)SDL_calloc(1, sizeof(*ctx)); - if (!ctx) { - return NULL; - } - - if (SDL_GL_ExtensionSupported("GL_ARB_texture_rectangle") - || SDL_GL_ExtensionSupported("GL_EXT_texture_rectangle")) { - ctx->GL_ARB_texture_rectangle_supported = SDL_TRUE; - } - - /* Check for shader support */ - shaders_supported = SDL_FALSE; - if (SDL_GL_ExtensionSupported("GL_ARB_shader_objects") && - SDL_GL_ExtensionSupported("GL_ARB_shading_language_100") && - SDL_GL_ExtensionSupported("GL_ARB_vertex_shader") && - SDL_GL_ExtensionSupported("GL_ARB_fragment_shader")) { - ctx->glGetError = (GLenum (*)(void)) SDL_GL_GetProcAddress("glGetError"); - ctx->glAttachObjectARB = (PFNGLATTACHOBJECTARBPROC) SDL_GL_GetProcAddress("glAttachObjectARB"); - ctx->glCompileShaderARB = (PFNGLCOMPILESHADERARBPROC) SDL_GL_GetProcAddress("glCompileShaderARB"); - ctx->glCreateProgramObjectARB = (PFNGLCREATEPROGRAMOBJECTARBPROC) SDL_GL_GetProcAddress("glCreateProgramObjectARB"); - ctx->glCreateShaderObjectARB = (PFNGLCREATESHADEROBJECTARBPROC) SDL_GL_GetProcAddress("glCreateShaderObjectARB"); - ctx->glDeleteObjectARB = (PFNGLDELETEOBJECTARBPROC) SDL_GL_GetProcAddress("glDeleteObjectARB"); - ctx->glGetInfoLogARB = (PFNGLGETINFOLOGARBPROC) SDL_GL_GetProcAddress("glGetInfoLogARB"); - ctx->glGetObjectParameterivARB = (PFNGLGETOBJECTPARAMETERIVARBPROC) SDL_GL_GetProcAddress("glGetObjectParameterivARB"); - ctx->glGetUniformLocationARB = (PFNGLGETUNIFORMLOCATIONARBPROC) SDL_GL_GetProcAddress("glGetUniformLocationARB"); - ctx->glLinkProgramARB = (PFNGLLINKPROGRAMARBPROC) SDL_GL_GetProcAddress("glLinkProgramARB"); - ctx->glShaderSourceARB = (PFNGLSHADERSOURCEARBPROC) SDL_GL_GetProcAddress("glShaderSourceARB"); - ctx->glUniform1iARB = (PFNGLUNIFORM1IARBPROC) SDL_GL_GetProcAddress("glUniform1iARB"); - ctx->glUniform1fARB = (PFNGLUNIFORM1FARBPROC) SDL_GL_GetProcAddress("glUniform1fARB"); - ctx->glUseProgramObjectARB = (PFNGLUSEPROGRAMOBJECTARBPROC) SDL_GL_GetProcAddress("glUseProgramObjectARB"); - if (ctx->glGetError && - ctx->glAttachObjectARB && - ctx->glCompileShaderARB && - ctx->glCreateProgramObjectARB && - ctx->glCreateShaderObjectARB && - ctx->glDeleteObjectARB && - ctx->glGetInfoLogARB && - ctx->glGetObjectParameterivARB && - ctx->glGetUniformLocationARB && - ctx->glLinkProgramARB && - ctx->glShaderSourceARB && - ctx->glUniform1iARB && - ctx->glUniform1fARB && - ctx->glUseProgramObjectARB) { - shaders_supported = SDL_TRUE; - } - } - - if (!shaders_supported) { - SDL_free(ctx); - return NULL; - } - - /* Compile all the shaders */ - for (i = 0; i < NUM_SHADERS; ++i) { - if (!CompileShaderProgram(ctx, i, &ctx->shaders[i])) { - GL_DestroyShaderContext(ctx); - return NULL; - } - } - - /* We're done! */ - return ctx; -} - -void -GL_SelectShader(GL_ShaderContext *ctx, GL_Shader shader) -{ - ctx->glUseProgramObjectARB(ctx->shaders[shader].program); -} - -void -GL_DestroyShaderContext(GL_ShaderContext *ctx) -{ - int i; - - for (i = 0; i < NUM_SHADERS; ++i) { - DestroyShaderProgram(ctx, &ctx->shaders[i]); - } - SDL_free(ctx); -} - -#endif /* SDL_VIDEO_RENDER_OGL && !SDL_RENDER_DISABLED */ - -/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/SDL-mobile/src/render/opengl/SDL_shaders_gl.h b/src/SDL-mobile/src/render/opengl/SDL_shaders_gl.h deleted file mode 100644 index 959582ac2..000000000 --- a/src/SDL-mobile/src/render/opengl/SDL_shaders_gl.h +++ /dev/null @@ -1,39 +0,0 @@ -/* - Simple DirectMedia Layer - Copyright (C) 1997-2012 Sam Lantinga - - 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" - -/* OpenGL shader implementation */ - -typedef enum { - SHADER_NONE, - SHADER_SOLID, - SHADER_RGB, - SHADER_YV12, - NUM_SHADERS -} GL_Shader; - -typedef struct GL_ShaderContext GL_ShaderContext; - -extern GL_ShaderContext * GL_CreateShaderContext(); -extern void GL_SelectShader(GL_ShaderContext *ctx, GL_Shader shader); -extern void GL_DestroyShaderContext(GL_ShaderContext *ctx); - -/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/SDL-mobile/src/render/opengles/SDL_glesfuncs.h b/src/SDL-mobile/src/render/opengles/SDL_glesfuncs.h deleted file mode 100644 index aab15a18a..000000000 --- a/src/SDL-mobile/src/render/opengles/SDL_glesfuncs.h +++ /dev/null @@ -1,40 +0,0 @@ -SDL_PROC(void, glBindTexture, (GLenum, GLuint)) -SDL_PROC(void, glBlendFunc, (GLenum, GLenum)) -SDL_PROC(void, glClear, (GLbitfield)) -SDL_PROC(void, glClearColor, (GLclampf, GLclampf, GLclampf, GLclampf)) -SDL_PROC(void, glColor4f, (GLfloat, GLfloat, GLfloat, GLfloat)) -SDL_PROC(void, glDeleteTextures, (GLsizei, const GLuint *)) -SDL_PROC(void, glDisable, (GLenum)) -SDL_PROC(void, glDisableClientState, (GLenum array)) -SDL_PROC(void, glDrawArrays, (GLenum, GLint, GLsizei)) -SDL_PROC(void, glDrawTexiOES, (GLint, GLint, GLint, GLint, GLint)) -SDL_PROC(void, glEnable, (GLenum)) -SDL_PROC(void, glEnableClientState, (GLenum)) -SDL_PROC(void, glFinish, (void)) -SDL_PROC(void, glGenFramebuffersOES, (GLsizei, GLuint *)) -SDL_PROC(void, glGenTextures, (GLsizei, GLuint *)) -SDL_PROC(GLenum, glGetError, (void)) -SDL_PROC(void, glGetIntegerv, (GLenum, GLint *)) -SDL_PROC(void, glLoadIdentity, (void)) -SDL_PROC(void, glMatrixMode, (GLenum)) -SDL_PROC(void, glOrthof, (GLfloat, GLfloat, GLfloat, GLfloat, GLfloat, GLfloat)) -SDL_PROC(void, glPixelStorei, (GLenum, GLint)) -SDL_PROC(void, glReadPixels, (GLint, GLint, GLsizei, GLsizei, GLenum, GLenum, GLvoid*)) -SDL_PROC(void, glTexCoordPointer, (GLint, GLenum, GLsizei, const GLvoid *)) -SDL_PROC(void, glTexEnvf, (GLenum, GLenum, GLfloat)) -SDL_PROC(void, glTexImage2D, (GLenum, GLint, GLint, GLsizei, GLsizei, GLint, GLenum, GLenum, const GLvoid *)) -SDL_PROC(void, glTexParameteri, (GLenum, GLenum, GLint)) -SDL_PROC(void, glTexParameteriv, (GLenum, GLenum, const GLint *)) -SDL_PROC(void, glTexSubImage2D, (GLenum, GLint, GLint, GLint, GLsizei, GLsizei, GLenum, GLenum, const GLvoid *)) -SDL_PROC(void, glVertexPointer, (GLint, GLenum, GLsizei, const GLvoid *)) -SDL_PROC(void, glViewport, (GLint, GLint, GLsizei, GLsizei)) -SDL_PROC(void, glBindFramebufferOES, (GLenum, GLuint)) -SDL_PROC(void, glFramebufferTexture2DOES, (GLenum, GLenum, GLenum, GLuint, GLint)) -SDL_PROC(GLenum, glCheckFramebufferStatusOES, (GLenum)) -SDL_PROC(void, glPushMatrix, (void)) -SDL_PROC(void, glTranslatef, (GLfloat, GLfloat, GLfloat)) -SDL_PROC(void, glRotatef, (GLfloat, GLfloat, GLfloat, GLfloat)) -SDL_PROC(void, glPopMatrix, (void)) -SDL_PROC(void, glDeleteFramebuffersOES, (GLsizei, const GLuint*)) - -/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/SDL-mobile/src/render/opengles/SDL_render_gles.c b/src/SDL-mobile/src/render/opengles/SDL_render_gles.c deleted file mode 100644 index ccd221601..000000000 --- a/src/SDL-mobile/src/render/opengles/SDL_render_gles.c +++ /dev/null @@ -1,1138 +0,0 @@ -/* - Simple DirectMedia Layer - Copyright (C) 1997-2012 Sam Lantinga - - 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_OGL_ES && !SDL_RENDER_DISABLED - -#include "SDL_hints.h" -#include "SDL_opengles.h" -#include "../SDL_sysrender.h" - -#if defined(SDL_VIDEO_DRIVER_PANDORA) - -/* Empty function stub to get OpenGL ES 1.x support without */ -/* OpenGL ES extension GL_OES_draw_texture supported */ -GL_API void GL_APIENTRY -glDrawTexiOES(GLint x, GLint y, GLint z, GLint width, GLint height) -{ - return; -} - -#endif /* PANDORA */ - -/* OpenGL ES 1.1 renderer implementation, based on the OpenGL renderer */ - -/* Used to re-create the window with OpenGL ES capability */ -extern int SDL_RecreateWindow(SDL_Window * window, Uint32 flags); - -static const float inv255f = 1.0f / 255.0f; - -static SDL_Renderer *GLES_CreateRenderer(SDL_Window * window, Uint32 flags); -static void GLES_WindowEvent(SDL_Renderer * renderer, - const SDL_WindowEvent *event); -static int GLES_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture); -static int GLES_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture, - const SDL_Rect * rect, const void *pixels, - int pitch); -static int GLES_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture, - const SDL_Rect * rect, void **pixels, int *pitch); -static void GLES_UnlockTexture(SDL_Renderer * renderer, - SDL_Texture * texture); -static int GLES_SetRenderTarget(SDL_Renderer * renderer, - SDL_Texture * texture); -static int GLES_UpdateViewport(SDL_Renderer * renderer); -static int GLES_RenderClear(SDL_Renderer * renderer); -static int GLES_RenderDrawPoints(SDL_Renderer * renderer, - const SDL_Point * points, int count); -static int GLES_RenderDrawLines(SDL_Renderer * renderer, - const SDL_Point * points, int count); -static int GLES_RenderFillRects(SDL_Renderer * renderer, - const SDL_Rect * rects, int count); -static int GLES_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture, - const SDL_Rect * srcrect, - const SDL_Rect * dstrect); -static int GLES_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect, - Uint32 pixel_format, void * pixels, int pitch); -static int GLES_RenderCopyEx(SDL_Renderer * renderer, SDL_Texture * texture, - const SDL_Rect * srcrect, const SDL_Rect * dstrect, - const double angle, const SDL_Point *center, const SDL_RendererFlip flip); -static void GLES_RenderPresent(SDL_Renderer * renderer); -static void GLES_DestroyTexture(SDL_Renderer * renderer, - SDL_Texture * texture); -static void GLES_DestroyRenderer(SDL_Renderer * renderer); -static int GLES_BindTexture (SDL_Renderer * renderer, SDL_Texture *texture, float *texw, float *texh); -static int GLES_UnbindTexture (SDL_Renderer * renderer, SDL_Texture *texture); - -typedef struct GLES_FBOList GLES_FBOList; - -struct GLES_FBOList -{ - Uint32 w, h; - GLuint FBO; - GLES_FBOList *next; -}; - - -SDL_RenderDriver GLES_RenderDriver = { - GLES_CreateRenderer, - { - "opengles", - (SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC | SDL_RENDERER_TARGETTEXTURE), - 1, - {SDL_PIXELFORMAT_ABGR8888}, - 0, - 0} -}; - -typedef struct -{ - SDL_GLContext context; - struct { - Uint32 color; - int blendMode; - SDL_bool tex_coords; - } current; - -#define SDL_PROC(ret,func,params) ret (APIENTRY *func) params; -#include "SDL_glesfuncs.h" -#undef SDL_PROC - SDL_bool GL_OES_framebuffer_object_supported; - GLES_FBOList *framebuffers; - GLuint window_framebuffer; - - SDL_bool useDrawTexture; - SDL_bool GL_OES_draw_texture_supported; -} GLES_RenderData; - -typedef struct -{ - GLuint texture; - GLenum type; - GLfloat texw; - GLfloat texh; - GLenum format; - GLenum formattype; - void *pixels; - int pitch; - GLES_FBOList *fbo; -} GLES_TextureData; - -static void -GLES_SetError(const char *prefix, GLenum result) -{ - const char *error; - - switch (result) { - case GL_NO_ERROR: - error = "GL_NO_ERROR"; - break; - case GL_INVALID_ENUM: - error = "GL_INVALID_ENUM"; - break; - case GL_INVALID_VALUE: - error = "GL_INVALID_VALUE"; - break; - case GL_INVALID_OPERATION: - error = "GL_INVALID_OPERATION"; - break; - case GL_STACK_OVERFLOW: - error = "GL_STACK_OVERFLOW"; - break; - case GL_STACK_UNDERFLOW: - error = "GL_STACK_UNDERFLOW"; - break; - case GL_OUT_OF_MEMORY: - error = "GL_OUT_OF_MEMORY"; - break; - default: - error = "UNKNOWN"; - break; - } - SDL_SetError("%s: %s", prefix, error); -} - -static int GLES_LoadFunctions(GLES_RenderData * data) -{ -#if SDL_VIDEO_DRIVER_UIKIT -#define __SDL_NOGETPROCADDR__ -#elif SDL_VIDEO_DRIVER_ANDROID -#define __SDL_NOGETPROCADDR__ -#elif SDL_VIDEO_DRIVER_PANDORA -#define __SDL_NOGETPROCADDR__ -#endif - -#ifdef __SDL_NOGETPROCADDR__ -#define SDL_PROC(ret,func,params) data->func=func; -#else -#define SDL_PROC(ret,func,params) \ - 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; \ - } \ - } while ( 0 ); -#endif /* _SDL_NOGETPROCADDR_ */ - -#include "SDL_glesfuncs.h" -#undef SDL_PROC - return 0; -} - -static SDL_GLContext SDL_CurrentContext = NULL; - -GLES_FBOList * -GLES_GetFBO(GLES_RenderData *data, Uint32 w, Uint32 h) -{ - GLES_FBOList *result = data->framebuffers; - while ((result) && ((result->w != w) || (result->h != h)) ) - { - result = result->next; - } - if (result == NULL) - { - result = SDL_malloc(sizeof(GLES_FBOList)); - result->w = w; - result->h = h; - data->glGenFramebuffersOES(1, &result->FBO); - result->next = data->framebuffers; - data->framebuffers = result; - } - return result; -} - - -static int -GLES_ActivateRenderer(SDL_Renderer * renderer) -{ - GLES_RenderData *data = (GLES_RenderData *) renderer->driverdata; - - if (SDL_CurrentContext != data->context) { - if (SDL_GL_MakeCurrent(renderer->window, data->context) < 0) { - return -1; - } - SDL_CurrentContext = data->context; - - GLES_UpdateViewport(renderer); - } - return 0; -} - -/* This is called if we need to invalidate all of the SDL OpenGL state */ -static void -GLES_ResetState(SDL_Renderer *renderer) -{ - GLES_RenderData *data = (GLES_RenderData *) renderer->driverdata; - - if (SDL_CurrentContext == data->context) { - GLES_UpdateViewport(renderer); - } else { - GLES_ActivateRenderer(renderer); - } - - data->current.color = 0; - data->current.blendMode = -1; - data->current.tex_coords = SDL_FALSE; - - data->glDisable(GL_DEPTH_TEST); - data->glDisable(GL_CULL_FACE); - - data->glMatrixMode(GL_MODELVIEW); - data->glLoadIdentity(); - - data->glEnableClientState(GL_VERTEX_ARRAY); - data->glDisableClientState(GL_TEXTURE_COORD_ARRAY); -} - -SDL_Renderer * -GLES_CreateRenderer(SDL_Window * window, Uint32 flags) -{ - - SDL_Renderer *renderer; - GLES_RenderData *data; - GLint value; - Uint32 windowFlags; - - SDL_GL_SetAttribute(SDL_GL_CONTEXT_EGL, 1); - SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 1); - SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 1); - - windowFlags = SDL_GetWindowFlags(window); - if (!(windowFlags & SDL_WINDOW_OPENGL)) { - if (SDL_RecreateWindow(window, windowFlags | SDL_WINDOW_OPENGL) < 0) { - /* Uh oh, better try to put it back... */ - SDL_RecreateWindow(window, windowFlags); - return NULL; - } - } - - renderer = (SDL_Renderer *) SDL_calloc(1, sizeof(*renderer)); - if (!renderer) { - SDL_OutOfMemory(); - return NULL; - } - - data = (GLES_RenderData *) SDL_calloc(1, sizeof(*data)); - if (!data) { - GLES_DestroyRenderer(renderer); - SDL_OutOfMemory(); - return NULL; - } - - renderer->WindowEvent = GLES_WindowEvent; - renderer->CreateTexture = GLES_CreateTexture; - renderer->UpdateTexture = GLES_UpdateTexture; - renderer->LockTexture = GLES_LockTexture; - renderer->UnlockTexture = GLES_UnlockTexture; - renderer->SetRenderTarget = GLES_SetRenderTarget; - renderer->UpdateViewport = GLES_UpdateViewport; - renderer->RenderClear = GLES_RenderClear; - renderer->RenderDrawPoints = GLES_RenderDrawPoints; - renderer->RenderDrawLines = GLES_RenderDrawLines; - renderer->RenderFillRects = GLES_RenderFillRects; - renderer->RenderCopy = GLES_RenderCopy; - renderer->RenderReadPixels = GLES_RenderReadPixels; - renderer->RenderCopyEx = GLES_RenderCopyEx; - renderer->RenderPresent = GLES_RenderPresent; - renderer->DestroyTexture = GLES_DestroyTexture; - renderer->DestroyRenderer = GLES_DestroyRenderer; - renderer->GL_BindTexture = GLES_BindTexture; - renderer->GL_UnbindTexture = GLES_UnbindTexture; - renderer->info = GLES_RenderDriver.info; - renderer->info.flags = SDL_RENDERER_ACCELERATED; - renderer->driverdata = data; - renderer->window = window; - - data->context = SDL_GL_CreateContext(window); - if (!data->context) { - GLES_DestroyRenderer(renderer); - return NULL; - } - if (SDL_GL_MakeCurrent(window, data->context) < 0) { - GLES_DestroyRenderer(renderer); - return NULL; - } - - if (GLES_LoadFunctions(data) < 0) { - GLES_DestroyRenderer(renderer); - return NULL; - } - - if (flags & SDL_RENDERER_PRESENTVSYNC) { - SDL_GL_SetSwapInterval(1); - } else { - SDL_GL_SetSwapInterval(0); - } - if (SDL_GL_GetSwapInterval() > 0) { - renderer->info.flags |= SDL_RENDERER_PRESENTVSYNC; - } - -#if SDL_VIDEO_DRIVER_PANDORA - data->GL_OES_draw_texture_supported = SDL_FALSE; - data->useDrawTexture = SDL_FALSE; -#else - if (SDL_GL_ExtensionSupported("GL_OES_draw_texture")) { - data->GL_OES_draw_texture_supported = SDL_TRUE; - data->useDrawTexture = SDL_TRUE; - } else { - data->GL_OES_draw_texture_supported = SDL_FALSE; - data->useDrawTexture = SDL_FALSE; - } -#endif - - value = 0; - data->glGetIntegerv(GL_MAX_TEXTURE_SIZE, &value); - renderer->info.max_texture_width = value; - value = 0; - data->glGetIntegerv(GL_MAX_TEXTURE_SIZE, &value); - renderer->info.max_texture_height = value; - - if (SDL_GL_ExtensionSupported("GL_OES_framebuffer_object")) { - data->GL_OES_framebuffer_object_supported = SDL_TRUE; - renderer->info.flags |= SDL_RENDERER_TARGETTEXTURE; - - value = 0; - data->glGetIntegerv(GL_FRAMEBUFFER_BINDING_OES, &value); - data->window_framebuffer = (GLuint)value; - } - data->framebuffers = NULL; - - /* Set up parameters for rendering */ - GLES_ResetState(renderer); - - return renderer; -} - -static void -GLES_WindowEvent(SDL_Renderer * renderer, const SDL_WindowEvent *event) -{ - GLES_RenderData *data = (GLES_RenderData *) renderer->driverdata; - - if (event->event == SDL_WINDOWEVENT_SIZE_CHANGED || - event->event == SDL_WINDOWEVENT_SHOWN || - event->event == SDL_WINDOWEVENT_HIDDEN) { - /* Rebind the context to the window area and update matrices */ - SDL_CurrentContext = NULL; - } - - if (event->event == SDL_WINDOWEVENT_MINIMIZED) { - /* According to Apple documentation, we need to finish drawing NOW! */ - data->glFinish(); - } -} - -static __inline__ int -power_of_2(int input) -{ - int value = 1; - - while (value < input) { - value <<= 1; - } - return value; -} - -static GLenum -GetScaleQuality(void) -{ - const char *hint = SDL_GetHint(SDL_HINT_RENDER_SCALE_QUALITY); - - if (!hint || *hint == '0' || SDL_strcasecmp(hint, "nearest") == 0) { - return GL_NEAREST; - } else { - return GL_LINEAR; - } -} - -static int -GLES_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture) -{ - GLES_RenderData *renderdata = (GLES_RenderData *) renderer->driverdata; - GLES_TextureData *data; - GLint internalFormat; - GLenum format, type; - int texture_w, texture_h; - GLenum scaleMode; - GLenum result; - - GLES_ActivateRenderer(renderer); - - switch (texture->format) { - case SDL_PIXELFORMAT_ABGR8888: - internalFormat = GL_RGBA; - format = GL_RGBA; - type = GL_UNSIGNED_BYTE; - break; - default: - SDL_SetError("Texture format not supported"); - return -1; - } - - data = (GLES_TextureData *) SDL_calloc(1, sizeof(*data)); - if (!data) { - SDL_OutOfMemory(); - return -1; - } - - 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; - } - } - - texture->driverdata = data; - if (texture->access == SDL_TEXTUREACCESS_TARGET) { - data->fbo = GLES_GetFBO(renderer->driverdata, texture->w, texture->h); - } else { - data->fbo = NULL; - } - - renderdata->glGetError(); - renderdata->glEnable(GL_TEXTURE_2D); - renderdata->glGenTextures(1, &data->texture); - - data->type = GL_TEXTURE_2D; - /* no NPOV textures allowed in OpenGL ES (yet) */ - texture_w = power_of_2(texture->w); - texture_h = power_of_2(texture->h); - data->texw = (GLfloat) texture->w / texture_w; - data->texh = (GLfloat) texture->h / texture_h; - - data->format = format; - data->formattype = type; - scaleMode = GetScaleQuality(); - renderdata->glBindTexture(data->type, data->texture); - renderdata->glTexParameteri(data->type, GL_TEXTURE_MIN_FILTER, scaleMode); - renderdata->glTexParameteri(data->type, GL_TEXTURE_MAG_FILTER, scaleMode); - renderdata->glTexParameteri(data->type, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); - renderdata->glTexParameteri(data->type, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); - - renderdata->glTexImage2D(data->type, 0, internalFormat, texture_w, - texture_h, 0, format, type, NULL); - renderdata->glDisable(GL_TEXTURE_2D); - - result = renderdata->glGetError(); - if (result != GL_NO_ERROR) { - GLES_SetError("glTexImage2D()", result); - return -1; - } - return 0; -} - -static int -GLES_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture, - const SDL_Rect * rect, const void *pixels, int pitch) -{ - GLES_RenderData *renderdata = (GLES_RenderData *) renderer->driverdata; - GLES_TextureData *data = (GLES_TextureData *) texture->driverdata; - Uint8 *blob = NULL; - Uint8 *src; - int srcPitch; - int y; - - GLES_ActivateRenderer(renderer); - - /* Bail out if we're supposed to update an empty rectangle */ - if (rect->w <= 0 || rect->h <= 0) - return 0; - - /* Reformat the texture data into a tightly packed array */ - srcPitch = rect->w * SDL_BYTESPERPIXEL(texture->format); - src = (Uint8 *)pixels; - if (pitch != srcPitch) - { - blob = (Uint8 *)SDL_malloc(srcPitch * rect->h); - if (!blob) - { - SDL_OutOfMemory(); - return -1; - } - src = blob; - for (y = 0; y < rect->h; ++y) - { - SDL_memcpy(src, pixels, srcPitch); - src += srcPitch; - pixels = (Uint8 *)pixels + pitch; - } - src = blob; - } - - /* Create a texture subimage with the supplied data */ - renderdata->glGetError(); - renderdata->glEnable(data->type); - renderdata->glBindTexture(data->type, data->texture); - renderdata->glPixelStorei(GL_UNPACK_ALIGNMENT, 1); - renderdata->glTexSubImage2D(data->type, - 0, - rect->x, - rect->y, - rect->w, - rect->h, - data->format, - data->formattype, - src); - if (blob) { - SDL_free(blob); - } - - if (renderdata->glGetError() != GL_NO_ERROR) - { - SDL_SetError("Failed to update texture"); - return -1; - } - return 0; -} - -static int -GLES_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture, - const SDL_Rect * rect, void **pixels, int *pitch) -{ - GLES_TextureData *data = (GLES_TextureData *) texture->driverdata; - - *pixels = - (void *) ((Uint8 *) data->pixels + rect->y * data->pitch + - rect->x * SDL_BYTESPERPIXEL(texture->format)); - *pitch = data->pitch; - return 0; -} - -static void -GLES_UnlockTexture(SDL_Renderer * renderer, SDL_Texture * texture) -{ - GLES_TextureData *data = (GLES_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; - GLES_UpdateTexture(renderer, texture, &rect, data->pixels, data->pitch); -} - -static int -GLES_SetRenderTarget(SDL_Renderer * renderer, SDL_Texture * texture) -{ - GLES_RenderData *data = (GLES_RenderData *) renderer->driverdata; - GLES_TextureData *texturedata = NULL; - GLenum status; - - GLES_ActivateRenderer(renderer); - - if (texture == NULL) { - data->glBindFramebufferOES(GL_FRAMEBUFFER_OES, data->window_framebuffer); - return 0; - } - - texturedata = (GLES_TextureData *) texture->driverdata; - data->glBindFramebufferOES(GL_FRAMEBUFFER_OES, texturedata->fbo->FBO); - /* TODO: check if texture pixel format allows this operation */ - data->glFramebufferTexture2DOES(GL_FRAMEBUFFER_OES, GL_COLOR_ATTACHMENT0_OES, texturedata->type, texturedata->texture, 0); - /* Check FBO status */ - status = data->glCheckFramebufferStatusOES(GL_FRAMEBUFFER_OES); - if (status != GL_FRAMEBUFFER_COMPLETE_OES) { - SDL_SetError("glFramebufferTexture2DOES() failed"); - return -1; - } - return 0; -} - -static int -GLES_UpdateViewport(SDL_Renderer * renderer) -{ - GLES_RenderData *data = (GLES_RenderData *) renderer->driverdata; - - if (SDL_CurrentContext != data->context) { - /* We'll update the viewport after we rebind the context */ - return 0; - } - - data->glViewport(renderer->viewport.x, renderer->viewport.y, - renderer->viewport.w, renderer->viewport.h); - - data->glMatrixMode(GL_PROJECTION); - data->glLoadIdentity(); - data->glOrthof((GLfloat) 0, - (GLfloat) renderer->viewport.w, - (GLfloat) renderer->viewport.h, - (GLfloat) 0, 0.0, 1.0); - return 0; -} - -static void -GLES_SetColor(GLES_RenderData * data, Uint8 r, Uint8 g, Uint8 b, Uint8 a) -{ - Uint32 color = ((a << 24) | (r << 16) | (g << 8) | b); - - if (color != data->current.color) { - data->glColor4f((GLfloat) r * inv255f, - (GLfloat) g * inv255f, - (GLfloat) b * inv255f, - (GLfloat) a * inv255f); - data->current.color = color; - } -} - -static void -GLES_SetBlendMode(GLES_RenderData * data, int blendMode) -{ - if (blendMode != data->current.blendMode) { - switch (blendMode) { - case SDL_BLENDMODE_NONE: - data->glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); - data->glDisable(GL_BLEND); - break; - case SDL_BLENDMODE_BLEND: - data->glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); - data->glEnable(GL_BLEND); - data->glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - break; - case SDL_BLENDMODE_ADD: - data->glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); - data->glEnable(GL_BLEND); - data->glBlendFunc(GL_SRC_ALPHA, GL_ONE); - break; - case SDL_BLENDMODE_MOD: - data->glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); - data->glEnable(GL_BLEND); - data->glBlendFunc(GL_ZERO, GL_SRC_COLOR); - break; - } - data->current.blendMode = blendMode; - } -} - -static void -GLES_SetTexCoords(GLES_RenderData * data, SDL_bool enabled) -{ - if (enabled != data->current.tex_coords) { - if (enabled) { - data->glEnableClientState(GL_TEXTURE_COORD_ARRAY); - } else { - data->glDisableClientState(GL_TEXTURE_COORD_ARRAY); - } - data->current.tex_coords = enabled; - } -} - -static void -GLES_SetDrawingState(SDL_Renderer * renderer) -{ - GLES_RenderData *data = (GLES_RenderData *) renderer->driverdata; - - GLES_ActivateRenderer(renderer); - - GLES_SetColor(data, (GLfloat) renderer->r, - (GLfloat) renderer->g, - (GLfloat) renderer->b, - (GLfloat) renderer->a); - - GLES_SetBlendMode(data, renderer->blendMode); - - GLES_SetTexCoords(data, SDL_FALSE); -} - -static int -GLES_RenderClear(SDL_Renderer * renderer) -{ - GLES_RenderData *data = (GLES_RenderData *) renderer->driverdata; - - GLES_ActivateRenderer(renderer); - - data->glClearColor((GLfloat) renderer->r * inv255f, - (GLfloat) renderer->g * inv255f, - (GLfloat) renderer->b * inv255f, - (GLfloat) renderer->a * inv255f); - - data->glClear(GL_COLOR_BUFFER_BIT); - - return 0; -} - -static int -GLES_RenderDrawPoints(SDL_Renderer * renderer, const SDL_Point * points, - int count) -{ - GLES_RenderData *data = (GLES_RenderData *) renderer->driverdata; - int i; - GLshort *vertices; - - GLES_SetDrawingState(renderer); - - vertices = SDL_stack_alloc(GLshort, count*2); - for (i = 0; i < count; ++i) { - vertices[2*i+0] = (GLshort)points[i].x; - vertices[2*i+1] = (GLshort)points[i].y; - } - data->glVertexPointer(2, GL_SHORT, 0, vertices); - data->glDrawArrays(GL_POINTS, 0, count); - SDL_stack_free(vertices); - - return 0; -} - -static int -GLES_RenderDrawLines(SDL_Renderer * renderer, const SDL_Point * points, - int count) -{ - GLES_RenderData *data = (GLES_RenderData *) renderer->driverdata; - int i; - GLshort *vertices; - - GLES_SetDrawingState(renderer); - - vertices = SDL_stack_alloc(GLshort, count*2); - for (i = 0; i < count; ++i) { - vertices[2*i+0] = (GLshort)points[i].x; - vertices[2*i+1] = (GLshort)points[i].y; - } - data->glVertexPointer(2, GL_SHORT, 0, vertices); - if (count > 2 && - points[0].x == points[count-1].x && points[0].y == points[count-1].y) { - /* GL_LINE_LOOP takes care of the final segment */ - --count; - data->glDrawArrays(GL_LINE_LOOP, 0, count); - } else { - data->glDrawArrays(GL_LINE_STRIP, 0, count); - /* We need to close the endpoint of the line */ - data->glDrawArrays(GL_POINTS, count-1, 1); - } - SDL_stack_free(vertices); - - return 0; -} - -static int -GLES_RenderFillRects(SDL_Renderer * renderer, const SDL_Rect * rects, - int count) -{ - GLES_RenderData *data = (GLES_RenderData *) renderer->driverdata; - int i; - - GLES_SetDrawingState(renderer); - - for (i = 0; i < count; ++i) { - const SDL_Rect *rect = &rects[i]; - GLshort minx = rect->x; - GLshort maxx = rect->x + rect->w; - GLshort miny = rect->y; - GLshort maxy = rect->y + rect->h; - GLshort vertices[8]; - vertices[0] = minx; - vertices[1] = miny; - vertices[2] = maxx; - vertices[3] = miny; - vertices[4] = minx; - vertices[5] = maxy; - vertices[6] = maxx; - vertices[7] = maxy; - - data->glVertexPointer(2, GL_SHORT, 0, vertices); - data->glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); - } - - return 0; -} - -static int -GLES_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture, - const SDL_Rect * srcrect, const SDL_Rect * dstrect) -{ - - GLES_RenderData *data = (GLES_RenderData *) renderer->driverdata; - GLES_TextureData *texturedata = (GLES_TextureData *) texture->driverdata; - int minx, miny, maxx, maxy; - GLfloat minu, maxu, minv, maxv; - - GLES_ActivateRenderer(renderer); - - data->glEnable(GL_TEXTURE_2D); - - data->glBindTexture(texturedata->type, texturedata->texture); - - if (texture->modMode) { - GLES_SetColor(data, texture->r, texture->g, texture->b, texture->a); - } else { - GLES_SetColor(data, 255, 255, 255, 255); - } - - GLES_SetBlendMode(data, texture->blendMode); - - GLES_SetTexCoords(data, SDL_TRUE); - - if (data->GL_OES_draw_texture_supported && data->useDrawTexture) { - /* this code is a little funny because the viewport is upside down vs SDL's coordinate system */ - GLint cropRect[4]; - int w, h; - SDL_Window *window = renderer->window; - - SDL_GetWindowSize(window, &w, &h); - if (renderer->target) { - cropRect[0] = srcrect->x; - cropRect[1] = srcrect->y; - cropRect[2] = srcrect->w; - cropRect[3] = srcrect->h; - data->glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_CROP_RECT_OES, - cropRect); - data->glDrawTexiOES(renderer->viewport.x + dstrect->x, renderer->viewport.y + dstrect->y, 0, - dstrect->w, dstrect->h); - } else { - cropRect[0] = srcrect->x; - cropRect[1] = srcrect->y + srcrect->h; - cropRect[2] = srcrect->w; - cropRect[3] = -srcrect->h; - data->glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_CROP_RECT_OES, - cropRect); - data->glDrawTexiOES(renderer->viewport.x + dstrect->x, - h - (renderer->viewport.y + dstrect->y) - dstrect->h, 0, - dstrect->w, dstrect->h); - } - } else { - - minx = dstrect->x; - miny = dstrect->y; - maxx = dstrect->x + dstrect->w; - maxy = dstrect->y + dstrect->h; - - minu = (GLfloat) srcrect->x / texture->w; - minu *= texturedata->texw; - maxu = (GLfloat) (srcrect->x + srcrect->w) / texture->w; - maxu *= texturedata->texw; - minv = (GLfloat) srcrect->y / texture->h; - minv *= texturedata->texh; - maxv = (GLfloat) (srcrect->y + srcrect->h) / texture->h; - maxv *= texturedata->texh; - - GLshort vertices[8]; - GLfloat texCoords[8]; - - vertices[0] = minx; - vertices[1] = miny; - vertices[2] = maxx; - vertices[3] = miny; - vertices[4] = minx; - vertices[5] = maxy; - vertices[6] = maxx; - vertices[7] = maxy; - - texCoords[0] = minu; - texCoords[1] = minv; - texCoords[2] = maxu; - texCoords[3] = minv; - texCoords[4] = minu; - texCoords[5] = maxv; - texCoords[6] = maxu; - texCoords[7] = maxv; - - data->glVertexPointer(2, GL_SHORT, 0, vertices); - data->glTexCoordPointer(2, GL_FLOAT, 0, texCoords); - data->glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); - } - data->glDisable(GL_TEXTURE_2D); - - return 0; -} - -static int -GLES_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect, - Uint32 pixel_format, void * pixels, int pitch) -{ - GLES_RenderData *data = (GLES_RenderData *) renderer->driverdata; - SDL_Window *window = renderer->window; - Uint32 temp_format = SDL_PIXELFORMAT_ABGR8888; - void *temp_pixels; - int temp_pitch; - Uint8 *src, *dst, *tmp; - int w, h, length, rows; - int status; - - GLES_ActivateRenderer(renderer); - - temp_pitch = rect->w * SDL_BYTESPERPIXEL(temp_format); - temp_pixels = SDL_malloc(rect->h * temp_pitch); - if (!temp_pixels) { - SDL_OutOfMemory(); - return -1; - } - - SDL_GetWindowSize(window, &w, &h); - - data->glPixelStorei(GL_PACK_ALIGNMENT, 1); - - data->glReadPixels(rect->x, (h-rect->y)-rect->h, rect->w, rect->h, - GL_RGBA, GL_UNSIGNED_BYTE, temp_pixels); - - /* Flip the rows to be top-down */ - length = rect->w * SDL_BYTESPERPIXEL(temp_format); - src = (Uint8*)temp_pixels + (rect->h-1)*temp_pitch; - dst = (Uint8*)temp_pixels; - tmp = SDL_stack_alloc(Uint8, length); - rows = rect->h / 2; - while (rows--) { - SDL_memcpy(tmp, dst, length); - SDL_memcpy(dst, src, length); - SDL_memcpy(src, tmp, length); - dst += temp_pitch; - src -= temp_pitch; - } - SDL_stack_free(tmp); - - status = SDL_ConvertPixels(rect->w, rect->h, - temp_format, temp_pixels, temp_pitch, - pixel_format, pixels, pitch); - SDL_free(temp_pixels); - - return status; -} - -static int -GLES_RenderCopyEx(SDL_Renderer * renderer, SDL_Texture * texture, - const SDL_Rect * srcrect, const SDL_Rect * dstrect, - const double angle, const SDL_Point *center, const SDL_RendererFlip flip) -{ - - GLES_RenderData *data = (GLES_RenderData *) renderer->driverdata; - GLES_TextureData *texturedata = (GLES_TextureData *) texture->driverdata; - int minx, miny, maxx, maxy; - GLfloat minu, maxu, minv, maxv; - GLfloat centerx, centery; - - GLES_ActivateRenderer(renderer); - - data->glEnable(GL_TEXTURE_2D); - - data->glBindTexture(texturedata->type, texturedata->texture); - - if (texture->modMode) { - GLES_SetColor(data, texture->r, texture->g, texture->b, texture->a); - } else { - GLES_SetColor(data, 255, 255, 255, 255); - } - - GLES_SetBlendMode(data, texture->blendMode); - - GLES_SetTexCoords(data, SDL_TRUE); - - centerx = (GLfloat)center->x; - centery = (GLfloat)center->y; - - // Rotate and translate - data->glPushMatrix(); - data->glTranslatef((GLfloat)dstrect->x + centerx, (GLfloat)dstrect->y + centery, (GLfloat)0.0); - data->glRotatef((GLfloat)angle, (GLfloat)0.0, (GLfloat)0.0, (GLfloat)1.0); - - if (flip & SDL_FLIP_HORIZONTAL) { - minx = (GLfloat) dstrect->w - centerx; - maxx = -centerx; - } - else { - minx = -centerx; - maxx = dstrect->w - centerx; - } - - if (flip & SDL_FLIP_VERTICAL) { - miny = dstrect->h - centery; - maxy = -centery; - } - else { - miny = -centery; - maxy = dstrect->h - centery; - } - - minu = (GLfloat) srcrect->x / texture->w; - minu *= texturedata->texw; - maxu = (GLfloat) (srcrect->x + srcrect->w) / texture->w; - maxu *= texturedata->texw; - minv = (GLfloat) srcrect->y / texture->h; - minv *= texturedata->texh; - maxv = (GLfloat) (srcrect->y + srcrect->h) / texture->h; - maxv *= texturedata->texh; - - GLshort vertices[8]; - GLfloat texCoords[8]; - - vertices[0] = minx; - vertices[1] = miny; - vertices[2] = maxx; - vertices[3] = miny; - vertices[4] = minx; - vertices[5] = maxy; - vertices[6] = maxx; - vertices[7] = maxy; - - texCoords[0] = minu; - texCoords[1] = minv; - texCoords[2] = maxu; - texCoords[3] = minv; - texCoords[4] = minu; - texCoords[5] = maxv; - texCoords[6] = maxu; - texCoords[7] = maxv; - data->glVertexPointer(2, GL_SHORT, 0, vertices); - data->glTexCoordPointer(2, GL_FLOAT, 0, texCoords); - data->glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); - data->glPopMatrix(); - data->glDisable(GL_TEXTURE_2D); - - return 0; -} - -static void -GLES_RenderPresent(SDL_Renderer * renderer) -{ - GLES_ActivateRenderer(renderer); - - SDL_GL_SwapWindow(renderer->window); -} - -static void -GLES_DestroyTexture(SDL_Renderer * renderer, SDL_Texture * texture) -{ - GLES_RenderData *renderdata = (GLES_RenderData *) renderer->driverdata; - - GLES_TextureData *data = (GLES_TextureData *) texture->driverdata; - - GLES_ActivateRenderer(renderer); - - if (!data) { - return; - } - if (data->texture) { - renderdata->glDeleteTextures(1, &data->texture); - } - if (data->pixels) { - SDL_free(data->pixels); - } - SDL_free(data); - texture->driverdata = NULL; -} - -static void -GLES_DestroyRenderer(SDL_Renderer * renderer) -{ - GLES_RenderData *data = (GLES_RenderData *) renderer->driverdata; - - if (data) { - if (data->context) { - while (data->framebuffers) { - GLES_FBOList *nextnode = data->framebuffers->next; - data->glDeleteFramebuffersOES(1, &data->framebuffers->FBO); - SDL_free(data->framebuffers); - data->framebuffers = nextnode; - } - SDL_GL_DeleteContext(data->context); - } - SDL_free(data); - } - SDL_free(renderer); -} - -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); - - data->glEnable(GL_TEXTURE_2D); - data->glBindTexture(texturedata->type, texturedata->texture); - - if(texw) *texw = (float)texturedata->texw; - if(texh) *texh = (float)texturedata->texh; - - return 0; -} - -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); - data->glDisable(texturedata->type); - - return 0; -} - - -#endif /* SDL_VIDEO_RENDER_OGL_ES && !SDL_RENDER_DISABLED */ - -/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/SDL-mobile/src/render/opengles2/SDL_gles2funcs.h b/src/SDL-mobile/src/render/opengles2/SDL_gles2funcs.h deleted file mode 100644 index 7b7d5e17d..000000000 --- a/src/SDL-mobile/src/render/opengles2/SDL_gles2funcs.h +++ /dev/null @@ -1,47 +0,0 @@ -SDL_PROC(void, glActiveTexture, (GLenum)) -SDL_PROC(void, glAttachShader, (GLuint, GLuint)) -SDL_PROC(void, glBindAttribLocation, (GLuint, GLuint, const char *)) -SDL_PROC(void, glBindTexture, (GLenum, GLuint)) -SDL_PROC(void, glBlendFunc, (GLenum, GLenum)) -SDL_PROC(void, glClear, (GLbitfield)) -SDL_PROC(void, glClearColor, (GLclampf, GLclampf, GLclampf, GLclampf)) -SDL_PROC(void, glCompileShader, (GLuint)) -SDL_PROC(GLuint, glCreateProgram, (void)) -SDL_PROC(GLuint, glCreateShader, (GLenum)) -SDL_PROC(void, glDeleteProgram, (GLuint)) -SDL_PROC(void, glDeleteShader, (GLuint)) -SDL_PROC(void, glDeleteTextures, (GLsizei, const GLuint *)) -SDL_PROC(void, glDisable, (GLenum)) -SDL_PROC(void, glDisableVertexAttribArray, (GLuint)) -SDL_PROC(void, glDrawArrays, (GLenum, GLint, GLsizei)) -SDL_PROC(void, glEnable, (GLenum)) -SDL_PROC(void, glEnableVertexAttribArray, (GLuint)) -SDL_PROC(void, glFinish, (void)) -SDL_PROC(void, glGenFramebuffers, (GLsizei, GLuint *)) -SDL_PROC(void, glGenTextures, (GLsizei, GLuint *)) -SDL_PROC(void, glGetBooleanv, (GLenum, GLboolean *)) -SDL_PROC(const GLubyte *, glGetString, (GLenum)) -SDL_PROC(GLenum, glGetError, (void)) -SDL_PROC(void, glGetIntegerv, (GLenum, GLint *)) -SDL_PROC(void, glGetProgramiv, (GLuint, GLenum, GLint *)) -SDL_PROC(void, glGetShaderInfoLog, (GLuint, GLsizei, GLsizei *, char *)) -SDL_PROC(void, glGetShaderiv, (GLuint, GLenum, GLint *)) -SDL_PROC(GLint, glGetUniformLocation, (GLuint, const char *)) -SDL_PROC(void, glLinkProgram, (GLuint)) -SDL_PROC(void, glPixelStorei, (GLenum, GLint)) -SDL_PROC(void, glReadPixels, (GLint, GLint, GLsizei, GLsizei, GLenum, GLenum, GLvoid*)) -SDL_PROC(void, glShaderBinary, (GLsizei, const GLuint *, GLenum, const void *, GLsizei)) -SDL_PROC(void, glShaderSource, (GLuint, GLsizei, const char **, const GLint *)) -SDL_PROC(void, glTexImage2D, (GLenum, GLint, GLint, GLsizei, GLsizei, GLint, GLenum, GLenum, const void *)) -SDL_PROC(void, glTexParameteri, (GLenum, GLenum, GLint)) -SDL_PROC(void, glTexSubImage2D, (GLenum, GLint, GLint, GLint, GLsizei, GLsizei, GLenum, GLenum, const GLvoid *)) -SDL_PROC(void, glUniform1i, (GLint, GLint)) -SDL_PROC(void, glUniform4f, (GLint, GLfloat, GLfloat, GLfloat, GLfloat)) -SDL_PROC(void, glUniformMatrix4fv, (GLint, GLsizei, GLboolean, const GLfloat *)) -SDL_PROC(void, glUseProgram, (GLuint)) -SDL_PROC(void, glVertexAttribPointer, (GLuint, GLint, GLenum, GLboolean, GLsizei, const void *)) -SDL_PROC(void, glViewport, (GLint, GLint, GLsizei, GLsizei)) -SDL_PROC(void, glBindFramebuffer, (GLenum, GLuint)) -SDL_PROC(void, glFramebufferTexture2D, (GLenum, GLenum, GLenum, GLuint, GLint)) -SDL_PROC(GLenum, glCheckFramebufferStatus, (GLenum)) -SDL_PROC(void, glDeleteFramebuffers, (GLsizei, const GLuint *)) diff --git a/src/SDL-mobile/src/render/opengles2/SDL_render_gles2.c b/src/SDL-mobile/src/render/opengles2/SDL_render_gles2.c deleted file mode 100644 index 2bdffa884..000000000 --- a/src/SDL-mobile/src/render/opengles2/SDL_render_gles2.c +++ /dev/null @@ -1,1758 +0,0 @@ -/* - Simple DirectMedia Layer - Copyright (C) 1997-2012 Sam Lantinga - - 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_OGL_ES2 && !SDL_RENDER_DISABLED - -#include "SDL_hints.h" -#include "SDL_opengles2.h" -#include "../SDL_sysrender.h" -#include "SDL_shaders_gles2.h" - -/* Used to re-create the window with OpenGL ES capability */ -extern int SDL_RecreateWindow(SDL_Window * window, Uint32 flags); - -/************************************************************************************************* - * Bootstrap data * - *************************************************************************************************/ - -static SDL_Renderer *GLES2_CreateRenderer(SDL_Window *window, Uint32 flags); - -SDL_RenderDriver GLES2_RenderDriver = { - GLES2_CreateRenderer, - { - "opengles2", - (SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC | SDL_RENDERER_TARGETTEXTURE), - 4, - {SDL_PIXELFORMAT_ABGR8888, - SDL_PIXELFORMAT_ARGB8888, - SDL_PIXELFORMAT_RGB888, - SDL_PIXELFORMAT_BGR888}, - 0, - 0 - } -}; - -/************************************************************************************************* - * Context structures * - *************************************************************************************************/ - -typedef struct GLES2_FBOList GLES2_FBOList; - -struct GLES2_FBOList -{ - Uint32 w, h; - GLuint FBO; - GLES2_FBOList *next; -}; - -typedef struct GLES2_TextureData -{ - GLenum texture; - GLenum texture_type; - GLenum pixel_format; - GLenum pixel_type; - void *pixel_data; - size_t pitch; - GLES2_FBOList *fbo; -} GLES2_TextureData; - -typedef struct GLES2_ShaderCacheEntry -{ - GLuint id; - GLES2_ShaderType type; - const GLES2_ShaderInstance *instance; - int references; - struct GLES2_ShaderCacheEntry *prev; - struct GLES2_ShaderCacheEntry *next; -} GLES2_ShaderCacheEntry; - -typedef struct GLES2_ShaderCache -{ - int count; - GLES2_ShaderCacheEntry *head; -} GLES2_ShaderCache; - -typedef struct GLES2_ProgramCacheEntry -{ - GLuint id; - SDL_BlendMode blend_mode; - GLES2_ShaderCacheEntry *vertex_shader; - GLES2_ShaderCacheEntry *fragment_shader; - GLuint uniform_locations[16]; - struct GLES2_ProgramCacheEntry *prev; - struct GLES2_ProgramCacheEntry *next; -} GLES2_ProgramCacheEntry; - -typedef struct GLES2_ProgramCache -{ - int count; - GLES2_ProgramCacheEntry *head; - GLES2_ProgramCacheEntry *tail; -} GLES2_ProgramCache; - -typedef enum -{ - GLES2_ATTRIBUTE_POSITION = 0, - GLES2_ATTRIBUTE_TEXCOORD = 1, - GLES2_ATTRIBUTE_ANGLE = 2, - GLES2_ATTRIBUTE_CENTER = 3, -} GLES2_Attribute; - -typedef enum -{ - GLES2_UNIFORM_PROJECTION, - GLES2_UNIFORM_TEXTURE, - GLES2_UNIFORM_MODULATION, - GLES2_UNIFORM_COLOR, - GLES2_UNIFORM_COLORTABLE -} GLES2_Uniform; - -typedef enum -{ - GLES2_IMAGESOURCE_SOLID, - GLES2_IMAGESOURCE_TEXTURE_ABGR, - GLES2_IMAGESOURCE_TEXTURE_ARGB, - GLES2_IMAGESOURCE_TEXTURE_RGB, - GLES2_IMAGESOURCE_TEXTURE_BGR -} GLES2_ImageSource; - -typedef struct GLES2_DriverContext -{ - SDL_GLContext *context; - struct { - int blendMode; - SDL_bool tex_coords; - } current; - -#define SDL_PROC(ret,func,params) ret (APIENTRY *func) params; -#include "SDL_gles2funcs.h" -#undef SDL_PROC - GLES2_FBOList *framebuffers; - GLuint window_framebuffer; - - int shader_format_count; - GLenum *shader_formats; - GLES2_ShaderCache shader_cache; - GLES2_ProgramCache program_cache; - GLES2_ProgramCacheEntry *current_program; -} GLES2_DriverContext; - -#define GLES2_MAX_CACHED_PROGRAMS 8 - -/************************************************************************************************* - * Renderer state APIs * - *************************************************************************************************/ - -static int GLES2_ActivateRenderer(SDL_Renderer *renderer); -static void GLES2_WindowEvent(SDL_Renderer * renderer, - const SDL_WindowEvent *event); -static int GLES2_UpdateViewport(SDL_Renderer * renderer); -static void GLES2_DestroyRenderer(SDL_Renderer *renderer); -static int GLES2_SetOrthographicProjection(SDL_Renderer *renderer); - - -static SDL_GLContext SDL_CurrentContext = NULL; - -static int GLES2_LoadFunctions(GLES2_DriverContext * data) -{ -#if SDL_VIDEO_DRIVER_UIKIT -#define __SDL_NOGETPROCADDR__ -#elif SDL_VIDEO_DRIVER_ANDROID -#define __SDL_NOGETPROCADDR__ -#elif SDL_VIDEO_DRIVER_PANDORA -#define __SDL_NOGETPROCADDR__ -#endif - -#if defined __SDL_NOGETPROCADDR__ -#define SDL_PROC(ret,func,params) data->func=func; -#else -#define SDL_PROC(ret,func,params) \ - 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; \ - } \ - } while ( 0 ); -#endif /* _SDL_NOGETPROCADDR_ */ - -#include "SDL_gles2funcs.h" -#undef SDL_PROC - return 0; -} - -GLES2_FBOList * -GLES2_GetFBO(GLES2_DriverContext *data, Uint32 w, Uint32 h) -{ - GLES2_FBOList *result = data->framebuffers; - while ((result) && ((result->w != w) || (result->h != h)) ) - { - result = result->next; - } - if (result == NULL) - { - result = SDL_malloc(sizeof(GLES2_FBOList)); - result->w = w; - result->h = h; - data->glGenFramebuffers(1, &result->FBO); - result->next = data->framebuffers; - data->framebuffers = result; - } - return result; -} - -static int -GLES2_ActivateRenderer(SDL_Renderer * renderer) -{ - GLES2_DriverContext *rdata = (GLES2_DriverContext *)renderer->driverdata; - - if (SDL_CurrentContext != rdata->context) { - /* Null out the current program to ensure we set it again */ - rdata->current_program = NULL; - - if (SDL_GL_MakeCurrent(renderer->window, rdata->context) < 0) { - return -1; - } - SDL_CurrentContext = rdata->context; - - GLES2_UpdateViewport(renderer); - } - return 0; -} - -static void -GLES2_WindowEvent(SDL_Renderer * renderer, const SDL_WindowEvent *event) -{ - GLES2_DriverContext *rdata = (GLES2_DriverContext *)renderer->driverdata; - - if (event->event == SDL_WINDOWEVENT_SIZE_CHANGED || - event->event == SDL_WINDOWEVENT_SHOWN || - event->event == SDL_WINDOWEVENT_HIDDEN) { - /* Rebind the context to the window area */ - SDL_CurrentContext = NULL; - } - - if (event->event == SDL_WINDOWEVENT_MINIMIZED) { - /* According to Apple documentation, we need to finish drawing NOW! */ - rdata->glFinish(); - } -} - -static int -GLES2_UpdateViewport(SDL_Renderer * renderer) -{ - GLES2_DriverContext *rdata = (GLES2_DriverContext *)renderer->driverdata; - - if (SDL_CurrentContext != rdata->context) { - /* We'll update the viewport after we rebind the context */ - return 0; - } - - rdata->glViewport(renderer->viewport.x, renderer->viewport.y, - renderer->viewport.w, renderer->viewport.h); - - if (rdata->current_program) { - GLES2_SetOrthographicProjection(renderer); - } - return 0; -} - -static void -GLES2_DestroyRenderer(SDL_Renderer *renderer) -{ - GLES2_DriverContext *rdata = (GLES2_DriverContext *)renderer->driverdata; - - /* Deallocate everything */ - if (rdata) { - GLES2_ActivateRenderer(renderer); - - { - GLES2_ShaderCacheEntry *entry; - GLES2_ShaderCacheEntry *next; - entry = rdata->shader_cache.head; - while (entry) - { - rdata->glDeleteShader(entry->id); - next = entry->next; - SDL_free(entry); - entry = next; - } - } - { - GLES2_ProgramCacheEntry *entry; - GLES2_ProgramCacheEntry *next; - entry = rdata->program_cache.head; - while (entry) { - rdata->glDeleteProgram(entry->id); - next = entry->next; - SDL_free(entry); - entry = next; - } - } - if (rdata->context) { - while (rdata->framebuffers) { - GLES2_FBOList *nextnode = rdata->framebuffers->next; - rdata->glDeleteFramebuffers(1, &rdata->framebuffers->FBO); - SDL_free(rdata->framebuffers); - rdata->framebuffers = nextnode; - } - SDL_GL_DeleteContext(rdata->context); - } - if (rdata->shader_formats) { - SDL_free(rdata->shader_formats); - } - SDL_free(rdata); - } - SDL_free(renderer); -} - -/************************************************************************************************* - * Texture APIs * - *************************************************************************************************/ - -static int GLES2_CreateTexture(SDL_Renderer *renderer, SDL_Texture *texture); -static void GLES2_DestroyTexture(SDL_Renderer *renderer, SDL_Texture *texture); -static int GLES2_LockTexture(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_Rect *rect, - void **pixels, int *pitch); -static void GLES2_UnlockTexture(SDL_Renderer *renderer, SDL_Texture *texture); -static int GLES2_UpdateTexture(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_Rect *rect, - const void *pixels, int pitch); -static int GLES2_SetRenderTarget(SDL_Renderer * renderer, SDL_Texture * texture); - -static GLenum -GetScaleQuality(void) -{ - const char *hint = SDL_GetHint(SDL_HINT_RENDER_SCALE_QUALITY); - - if (!hint || *hint == '0' || SDL_strcasecmp(hint, "nearest") == 0) { - return GL_NEAREST; - } else { - return GL_LINEAR; - } -} - -static int -GLES2_CreateTexture(SDL_Renderer *renderer, SDL_Texture *texture) -{ - GLES2_DriverContext *rdata = (GLES2_DriverContext *)renderer->driverdata; - GLES2_TextureData *tdata; - GLenum format; - GLenum type; - GLenum scaleMode; - - GLES2_ActivateRenderer(renderer); - - /* Determine the corresponding GLES texture format params */ - switch (texture->format) - { - case SDL_PIXELFORMAT_ABGR8888: - case SDL_PIXELFORMAT_ARGB8888: - case SDL_PIXELFORMAT_BGR888: - case SDL_PIXELFORMAT_RGB888: - format = GL_RGBA; - type = GL_UNSIGNED_BYTE; - break; - default: - SDL_SetError("Texture format not supported"); - return -1; - } - - /* Allocate a texture struct */ - tdata = (GLES2_TextureData *)SDL_calloc(1, sizeof(GLES2_TextureData)); - if (!tdata) - { - SDL_OutOfMemory(); - return -1; - } - tdata->texture = 0; - tdata->texture_type = GL_TEXTURE_2D; - tdata->pixel_format = format; - tdata->pixel_type = type; - scaleMode = GetScaleQuality(); - - /* Allocate a blob for image data */ - 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(); - SDL_free(tdata); - return -1; - } - } - - /* Allocate the texture */ - rdata->glGetError(); - rdata->glGenTextures(1, &tdata->texture); - rdata->glActiveTexture(GL_TEXTURE0); - rdata->glBindTexture(tdata->texture_type, tdata->texture); - rdata->glTexParameteri(tdata->texture_type, GL_TEXTURE_MIN_FILTER, scaleMode); - rdata->glTexParameteri(tdata->texture_type, GL_TEXTURE_MAG_FILTER, scaleMode); - rdata->glTexParameteri(tdata->texture_type, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); - rdata->glTexParameteri(tdata->texture_type, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); - 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; - } - texture->driverdata = tdata; - - if (texture->access == SDL_TEXTUREACCESS_TARGET) { - tdata->fbo = GLES2_GetFBO(renderer->driverdata, texture->w, texture->h); - } else { - tdata->fbo = NULL; - } - - return 0; -} - -static void -GLES2_DestroyTexture(SDL_Renderer *renderer, SDL_Texture *texture) -{ - GLES2_DriverContext *rdata = (GLES2_DriverContext *)renderer->driverdata; - GLES2_TextureData *tdata = (GLES2_TextureData *)texture->driverdata; - - GLES2_ActivateRenderer(renderer); - - /* Destroy the texture */ - if (tdata) - { - rdata->glDeleteTextures(1, &tdata->texture); - SDL_free(tdata->pixel_data); - SDL_free(tdata); - texture->driverdata = NULL; - } -} - -static int -GLES2_LockTexture(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_Rect *rect, - void **pixels, int *pitch) -{ - GLES2_TextureData *tdata = (GLES2_TextureData *)texture->driverdata; - - /* Retrieve the buffer/pitch for the specified region */ - *pixels = (Uint8 *)tdata->pixel_data + - (tdata->pitch * rect->y) + - (rect->x * SDL_BYTESPERPIXEL(texture->format)); - *pitch = tdata->pitch; - - return 0; -} - -static void -GLES2_UnlockTexture(SDL_Renderer *renderer, SDL_Texture *texture) -{ - GLES2_TextureData *tdata = (GLES2_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; - GLES2_UpdateTexture(renderer, texture, &rect, tdata->pixel_data, tdata->pitch); -} - -static int -GLES2_UpdateTexture(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_Rect *rect, - const void *pixels, int pitch) -{ - GLES2_DriverContext *rdata = (GLES2_DriverContext *)renderer->driverdata; - GLES2_TextureData *tdata = (GLES2_TextureData *)texture->driverdata; - Uint8 *blob = NULL; - Uint8 *src; - int srcPitch; - int y; - - GLES2_ActivateRenderer(renderer); - - /* Bail out if we're supposed to update an empty rectangle */ - if (rect->w <= 0 || rect->h <= 0) - return 0; - - /* Reformat the texture data into a tightly packed array */ - srcPitch = rect->w * SDL_BYTESPERPIXEL(texture->format); - src = (Uint8 *)pixels; - if (pitch != srcPitch) - { - blob = (Uint8 *)SDL_malloc(srcPitch * rect->h); - if (!blob) - { - SDL_OutOfMemory(); - return -1; - } - src = blob; - for (y = 0; y < rect->h; ++y) - { - SDL_memcpy(src, pixels, srcPitch); - src += srcPitch; - pixels = (Uint8 *)pixels + pitch; - } - src = blob; - } - - /* Create a texture subimage with the supplied data */ - rdata->glGetError(); - rdata->glActiveTexture(GL_TEXTURE0); - rdata->glBindTexture(tdata->texture_type, tdata->texture); - rdata->glPixelStorei(GL_UNPACK_ALIGNMENT, 1); - rdata->glTexSubImage2D(tdata->texture_type, - 0, - rect->x, - rect->y, - rect->w, - rect->h, - tdata->pixel_format, - tdata->pixel_type, - src); - if (blob) { - SDL_free(blob); - } - - if (rdata->glGetError() != GL_NO_ERROR) - { - SDL_SetError("Failed to update texture"); - return -1; - } - return 0; -} - -static int -GLES2_SetRenderTarget(SDL_Renderer * renderer, SDL_Texture * texture) -{ - GLES2_DriverContext *data = (GLES2_DriverContext *) renderer->driverdata; - GLES2_TextureData *texturedata = NULL; - GLenum status; - - if (texture == NULL) { - data->glBindFramebuffer(GL_FRAMEBUFFER, data->window_framebuffer); - } else { - texturedata = (GLES2_TextureData *) texture->driverdata; - data->glBindFramebuffer(GL_FRAMEBUFFER, texturedata->fbo->FBO); - /* TODO: check if texture pixel format allows this operation */ - data->glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, texturedata->texture_type, texturedata->texture, 0); - /* Check FBO status */ - status = data->glCheckFramebufferStatus(GL_FRAMEBUFFER); - if (status != GL_FRAMEBUFFER_COMPLETE) { - SDL_SetError("glFramebufferTexture2D() failed"); - return -1; - } - } - return 0; -} - -/************************************************************************************************* - * Shader management functions * - *************************************************************************************************/ - -static GLES2_ShaderCacheEntry *GLES2_CacheShader(SDL_Renderer *renderer, GLES2_ShaderType type, - SDL_BlendMode blendMode); -static void GLES2_EvictShader(SDL_Renderer *renderer, GLES2_ShaderCacheEntry *entry); -static GLES2_ProgramCacheEntry *GLES2_CacheProgram(SDL_Renderer *renderer, - GLES2_ShaderCacheEntry *vertex, - GLES2_ShaderCacheEntry *fragment, - SDL_BlendMode blendMode); -static int GLES2_SelectProgram(SDL_Renderer *renderer, GLES2_ImageSource source, - SDL_BlendMode blendMode); - -static GLES2_ProgramCacheEntry * -GLES2_CacheProgram(SDL_Renderer *renderer, GLES2_ShaderCacheEntry *vertex, - GLES2_ShaderCacheEntry *fragment, SDL_BlendMode blendMode) -{ - GLES2_DriverContext *rdata = (GLES2_DriverContext *)renderer->driverdata; - GLES2_ProgramCacheEntry *entry; - GLES2_ShaderCacheEntry *shaderEntry; - GLint linkSuccessful; - - /* Check if we've already cached this program */ - entry = rdata->program_cache.head; - while (entry) - { - if (entry->vertex_shader == vertex && entry->fragment_shader == fragment) - break; - entry = entry->next; - } - if (entry) - { - if (rdata->program_cache.head != entry) - { - if (entry->next) - entry->next->prev = entry->prev; - if (entry->prev) - entry->prev->next = entry->next; - entry->prev = NULL; - entry->next = rdata->program_cache.head; - rdata->program_cache.head->prev = entry; - rdata->program_cache.head = entry; - } - return entry; - } - - /* Create a program cache entry */ - entry = (GLES2_ProgramCacheEntry *)SDL_calloc(1, sizeof(GLES2_ProgramCacheEntry)); - if (!entry) - { - SDL_OutOfMemory(); - return NULL; - } - entry->vertex_shader = vertex; - entry->fragment_shader = fragment; - entry->blend_mode = blendMode; - - /* Create the program and link it */ - rdata->glGetError(); - entry->id = rdata->glCreateProgram(); - rdata->glAttachShader(entry->id, vertex->id); - rdata->glAttachShader(entry->id, fragment->id); - rdata->glBindAttribLocation(entry->id, GLES2_ATTRIBUTE_POSITION, "a_position"); - rdata->glBindAttribLocation(entry->id, GLES2_ATTRIBUTE_TEXCOORD, "a_texCoord"); - rdata->glBindAttribLocation(entry->id, GLES2_ATTRIBUTE_ANGLE, "a_angle"); - rdata->glBindAttribLocation(entry->id, GLES2_ATTRIBUTE_CENTER, "a_center"); - rdata->glLinkProgram(entry->id); - 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); - return NULL; - } - - /* Predetermine locations of uniform variables */ - entry->uniform_locations[GLES2_UNIFORM_PROJECTION] = - rdata->glGetUniformLocation(entry->id, "u_projection"); - entry->uniform_locations[GLES2_UNIFORM_TEXTURE] = - rdata->glGetUniformLocation(entry->id, "u_texture"); - entry->uniform_locations[GLES2_UNIFORM_MODULATION] = - rdata->glGetUniformLocation(entry->id, "u_modulation"); - entry->uniform_locations[GLES2_UNIFORM_COLOR] = - rdata->glGetUniformLocation(entry->id, "u_color"); - entry->uniform_locations[GLES2_UNIFORM_COLORTABLE] = - rdata->glGetUniformLocation(entry->id, "u_colorTable"); - - /* Cache the linked program */ - if (rdata->program_cache.head) - { - entry->next = rdata->program_cache.head; - rdata->program_cache.head->prev = entry; - } - else - { - rdata->program_cache.tail = entry; - } - rdata->program_cache.head = entry; - ++rdata->program_cache.count; - - /* Increment the refcount of the shaders we're using */ - ++vertex->references; - ++fragment->references; - - /* Evict the last entry from the cache if we exceed the limit */ - if (rdata->program_cache.count > GLES2_MAX_CACHED_PROGRAMS) - { - shaderEntry = rdata->program_cache.tail->vertex_shader; - if (--shaderEntry->references <= 0) - GLES2_EvictShader(renderer, shaderEntry); - shaderEntry = rdata->program_cache.tail->fragment_shader; - if (--shaderEntry->references <= 0) - GLES2_EvictShader(renderer, shaderEntry); - rdata->glDeleteProgram(rdata->program_cache.tail->id); - rdata->program_cache.tail = rdata->program_cache.tail->prev; - SDL_free(rdata->program_cache.tail->next); - rdata->program_cache.tail->next = NULL; - --rdata->program_cache.count; - } - return entry; -} - -static GLES2_ShaderCacheEntry * -GLES2_CacheShader(SDL_Renderer *renderer, GLES2_ShaderType type, SDL_BlendMode blendMode) -{ - GLES2_DriverContext *rdata = (GLES2_DriverContext *)renderer->driverdata; - const GLES2_Shader *shader; - const GLES2_ShaderInstance *instance = NULL; - GLES2_ShaderCacheEntry *entry = NULL; - GLint compileSuccessful = GL_FALSE; - int i, j; - - /* Find the corresponding shader */ - shader = GLES2_GetShader(type, blendMode); - if (!shader) - { - SDL_SetError("No shader matching the requested characteristics was found"); - return NULL; - } - - /* Find a matching shader instance that's supported on this hardware */ - for (i = 0; i < shader->instance_count && !instance; ++i) - { - for (j = 0; j < rdata->shader_format_count && !instance; ++j) - { - if (!shader->instances) - continue; - if (!shader->instances[i]) - continue; - if (shader->instances[i]->format != rdata->shader_formats[j]) - continue; - instance = shader->instances[i]; - } - } - if (!instance) - { - SDL_SetError("The specified shader cannot be loaded on the current platform"); - return NULL; - } - - /* Check if we've already cached this shader */ - entry = rdata->shader_cache.head; - while (entry) - { - if (entry->instance == instance) - break; - entry = entry->next; - } - if (entry) - return entry; - - /* Create a shader cache entry */ - entry = (GLES2_ShaderCacheEntry *)SDL_calloc(1, sizeof(GLES2_ShaderCacheEntry)); - if (!entry) - { - SDL_OutOfMemory(); - return NULL; - } - entry->type = type; - entry->instance = instance; - - /* Compile or load the selected shader instance */ - rdata->glGetError(); - entry->id = rdata->glCreateShader(instance->type); - if (instance->format == (GLenum)-1) - { - rdata->glShaderSource(entry->id, 1, (const char **)&instance->data, NULL); - rdata->glCompileShader(entry->id); - rdata->glGetShaderiv(entry->id, GL_COMPILE_STATUS, &compileSuccessful); - } - else - { - rdata->glShaderBinary(1, &entry->id, instance->format, instance->data, instance->length); - compileSuccessful = GL_TRUE; - } - if (rdata->glGetError() != GL_NO_ERROR || !compileSuccessful) - { - char *info = NULL; - int length = 0; - - rdata->glGetShaderiv(entry->id, GL_INFO_LOG_LENGTH, &length); - if (length > 0) { - info = SDL_stack_alloc(char, length); - if (info) { - rdata->glGetShaderInfoLog(entry->id, length, &length, info); - } - } - if (info) { - SDL_SetError("Failed to load the shader: %s", info); - SDL_stack_free(info); - } else { - SDL_SetError("Failed to load the shader"); - } - rdata->glDeleteShader(entry->id); - SDL_free(entry); - return NULL; - } - - /* Link the shader entry in at the front of the cache */ - if (rdata->shader_cache.head) - { - entry->next = rdata->shader_cache.head; - rdata->shader_cache.head->prev = entry; - } - rdata->shader_cache.head = entry; - ++rdata->shader_cache.count; - return entry; -} - -static void -GLES2_EvictShader(SDL_Renderer *renderer, GLES2_ShaderCacheEntry *entry) -{ - GLES2_DriverContext *rdata = (GLES2_DriverContext *)renderer->driverdata; - - /* Unlink the shader from the cache */ - if (entry->next) - entry->next->prev = entry->prev; - if (entry->prev) - entry->prev->next = entry->next; - if (rdata->shader_cache.head == entry) - rdata->shader_cache.head = entry->next; - --rdata->shader_cache.count; - - /* Deallocate the shader */ - rdata->glDeleteShader(entry->id); - SDL_free(entry); -} - -static int -GLES2_SelectProgram(SDL_Renderer *renderer, GLES2_ImageSource source, SDL_BlendMode blendMode) -{ - GLES2_DriverContext *rdata = (GLES2_DriverContext *)renderer->driverdata; - GLES2_ShaderCacheEntry *vertex = NULL; - GLES2_ShaderCacheEntry *fragment = NULL; - GLES2_ShaderType vtype, ftype; - GLES2_ProgramCacheEntry *program; - - /* Select an appropriate shader pair for the specified modes */ - vtype = GLES2_SHADER_VERTEX_DEFAULT; - switch (source) - { - case GLES2_IMAGESOURCE_SOLID: - ftype = GLES2_SHADER_FRAGMENT_SOLID_SRC; - break; - case GLES2_IMAGESOURCE_TEXTURE_ABGR: - ftype = GLES2_SHADER_FRAGMENT_TEXTURE_ABGR_SRC; - break; - case GLES2_IMAGESOURCE_TEXTURE_ARGB: - ftype = GLES2_SHADER_FRAGMENT_TEXTURE_ARGB_SRC; - break; - case GLES2_IMAGESOURCE_TEXTURE_RGB: - ftype = GLES2_SHADER_FRAGMENT_TEXTURE_RGB_SRC; - break; - case GLES2_IMAGESOURCE_TEXTURE_BGR: - ftype = GLES2_SHADER_FRAGMENT_TEXTURE_BGR_SRC; - break; - default: - goto fault; - } - - /* Load the requested shaders */ - vertex = GLES2_CacheShader(renderer, vtype, blendMode); - if (!vertex) - goto fault; - fragment = GLES2_CacheShader(renderer, ftype, blendMode); - if (!fragment) - goto fault; - - /* Check if we need to change programs at all */ - if (rdata->current_program && - rdata->current_program->vertex_shader == vertex && - rdata->current_program->fragment_shader == fragment) - return 0; - - /* Generate a matching program */ - program = GLES2_CacheProgram(renderer, vertex, fragment, blendMode); - if (!program) - goto fault; - - /* Select that program in OpenGL */ - rdata->glGetError(); - rdata->glUseProgram(program->id); - if (rdata->glGetError() != GL_NO_ERROR) - { - SDL_SetError("Failed to select program"); - goto fault; - } - - /* Set the current program */ - rdata->current_program = program; - - /* Activate an orthographic projection */ - if (GLES2_SetOrthographicProjection(renderer) < 0) - goto fault; - - /* Clean up and return */ - return 0; -fault: - if (vertex && vertex->references <= 0) - GLES2_EvictShader(renderer, vertex); - if (fragment && fragment->references <= 0) - GLES2_EvictShader(renderer, fragment); - rdata->current_program = NULL; - return -1; -} - -static int -GLES2_SetOrthographicProjection(SDL_Renderer *renderer) -{ - GLES2_DriverContext *rdata = (GLES2_DriverContext *)renderer->driverdata; - GLfloat projection[4][4]; - GLuint locProjection; - - /* Prepare an orthographic projection */ - projection[0][0] = 2.0f / renderer->viewport.w; - projection[0][1] = 0.0f; - projection[0][2] = 0.0f; - projection[0][3] = 0.0f; - projection[1][0] = 0.0f; - if (renderer->target) { - projection[1][1] = 2.0f / renderer->viewport.h; - } else { - projection[1][1] = -2.0f / renderer->viewport.h; - } - projection[1][2] = 0.0f; - projection[1][3] = 0.0f; - projection[2][0] = 0.0f; - projection[2][1] = 0.0f; - projection[2][2] = 0.0f; - projection[2][3] = 0.0f; - projection[3][0] = -1.0f; - if (renderer->target) { - projection[3][1] = -1.0f; - } else { - projection[3][1] = 1.0f; - } - projection[3][2] = 0.0f; - projection[3][3] = 1.0f; - - /* Set the projection matrix */ - 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; - } - return 0; -} - -/************************************************************************************************* - * Rendering functions * - *************************************************************************************************/ - -static const float inv255f = 1.0f / 255.0f; - -static int GLES2_RenderClear(SDL_Renderer *renderer); -static int GLES2_RenderDrawPoints(SDL_Renderer *renderer, const SDL_Point *points, int count); -static int GLES2_RenderDrawLines(SDL_Renderer *renderer, const SDL_Point *points, int count); -static int GLES2_RenderFillRects(SDL_Renderer *renderer, const SDL_Rect *rects, int count); -static int GLES2_RenderCopy(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_Rect *srcrect, - const SDL_Rect *dstrect); -static int GLES2_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect, - Uint32 pixel_format, void * pixels, int pitch); -static int GLES2_RenderCopyEx(SDL_Renderer * renderer, SDL_Texture * texture, - const SDL_Rect * srcrect, const SDL_Rect * dstrect, - const double angle, const SDL_Point *center, const SDL_RendererFlip flip); -static void GLES2_RenderPresent(SDL_Renderer *renderer); - - -static int -GLES2_RenderClear(SDL_Renderer * renderer) -{ - GLES2_DriverContext *rdata = (GLES2_DriverContext *)renderer->driverdata; - - GLES2_ActivateRenderer(renderer); - - rdata->glClearColor((GLfloat) renderer->r * inv255f, - (GLfloat) renderer->g * inv255f, - (GLfloat) renderer->b * inv255f, - (GLfloat) renderer->a * inv255f); - - rdata->glClear(GL_COLOR_BUFFER_BIT); - - return 0; -} - -static void -GLES2_SetBlendMode(GLES2_DriverContext *rdata, int blendMode) -{ - if (blendMode != rdata->current.blendMode) { - switch (blendMode) { - default: - case SDL_BLENDMODE_NONE: - rdata->glDisable(GL_BLEND); - break; - case SDL_BLENDMODE_BLEND: - rdata->glEnable(GL_BLEND); - rdata->glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - break; - case SDL_BLENDMODE_ADD: - rdata->glEnable(GL_BLEND); - rdata->glBlendFunc(GL_SRC_ALPHA, GL_ONE); - break; - case SDL_BLENDMODE_MOD: - rdata->glEnable(GL_BLEND); - rdata->glBlendFunc(GL_ZERO, GL_SRC_COLOR); - break; - } - rdata->current.blendMode = blendMode; - } -} - -static void -GLES2_SetTexCoords(GLES2_DriverContext * rdata, SDL_bool enabled) -{ - if (enabled != rdata->current.tex_coords) { - if (enabled) { - rdata->glEnableVertexAttribArray(GLES2_ATTRIBUTE_TEXCOORD); - } else { - rdata->glDisableVertexAttribArray(GLES2_ATTRIBUTE_TEXCOORD); - } - rdata->current.tex_coords = enabled; - } -} - -static int -GLES2_SetDrawingState(SDL_Renderer * renderer) -{ - GLES2_DriverContext *rdata = (GLES2_DriverContext *)renderer->driverdata; - int blendMode = renderer->blendMode; - GLuint locColor; - - rdata->glGetError(); - - GLES2_ActivateRenderer(renderer); - - GLES2_SetBlendMode(rdata, blendMode); - - GLES2_SetTexCoords(rdata, SDL_FALSE); - - /* Activate an appropriate shader and set the projection matrix */ - if (GLES2_SelectProgram(renderer, GLES2_IMAGESOURCE_SOLID, blendMode) < 0) - return -1; - - /* Select the color to draw with */ - locColor = rdata->current_program->uniform_locations[GLES2_UNIFORM_COLOR]; - if (renderer->target && - (renderer->target->format == SDL_PIXELFORMAT_ARGB8888 || - renderer->target->format == SDL_PIXELFORMAT_RGB888)) { - rdata->glUniform4f(locColor, - renderer->b * inv255f, - renderer->g * inv255f, - renderer->r * inv255f, - renderer->a * inv255f); - } else { - rdata->glUniform4f(locColor, - renderer->r * inv255f, - renderer->g * inv255f, - renderer->b * inv255f, - renderer->a * inv255f); - } - return 0; -} - -static int -GLES2_RenderDrawPoints(SDL_Renderer *renderer, const SDL_Point *points, int count) -{ - GLES2_DriverContext *rdata = (GLES2_DriverContext *)renderer->driverdata; - GLfloat *vertices; - int idx; - - if (GLES2_SetDrawingState(renderer) < 0) { - return -1; - } - - /* Emit the specified vertices as points */ - vertices = SDL_stack_alloc(GLfloat, count * 2); - for (idx = 0; idx < count; ++idx) - { - GLfloat x = (GLfloat)points[idx].x + 0.5f; - GLfloat y = (GLfloat)points[idx].y + 0.5f; - - vertices[idx * 2] = x; - vertices[(idx * 2) + 1] = y; - } - rdata->glGetError(); - 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; - } - return 0; -} - -static int -GLES2_RenderDrawLines(SDL_Renderer *renderer, const SDL_Point *points, int count) -{ - GLES2_DriverContext *rdata = (GLES2_DriverContext *)renderer->driverdata; - GLfloat *vertices; - int idx; - - if (GLES2_SetDrawingState(renderer) < 0) { - return -1; - } - - /* Emit a line strip including the specified vertices */ - vertices = SDL_stack_alloc(GLfloat, count * 2); - for (idx = 0; idx < count; ++idx) - { - GLfloat x = (GLfloat)points[idx].x + 0.5f; - GLfloat y = (GLfloat)points[idx].y + 0.5f; - - vertices[idx * 2] = x; - vertices[(idx * 2) + 1] = y; - } - rdata->glGetError(); - rdata->glVertexAttribPointer(GLES2_ATTRIBUTE_POSITION, 2, GL_FLOAT, GL_FALSE, 0, vertices); - rdata->glDrawArrays(GL_LINE_STRIP, 0, count); - - /* We need to close the endpoint of the line */ - if (count == 2 || - points[0].x != points[count-1].x || points[0].y != points[count-1].y) { - 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; - } - return 0; -} - -static int -GLES2_RenderFillRects(SDL_Renderer *renderer, const SDL_Rect *rects, int count) -{ - GLES2_DriverContext *rdata = (GLES2_DriverContext *)renderer->driverdata; - GLfloat vertices[8]; - int idx; - - if (GLES2_SetDrawingState(renderer) < 0) { - return -1; - } - - /* Emit a line loop for each rectangle */ - rdata->glGetError(); - for (idx = 0; idx < count; ++idx) { - const SDL_Rect *rect = &rects[idx]; - - GLfloat xMin = (GLfloat)rect->x; - GLfloat xMax = (GLfloat)(rect->x + rect->w); - GLfloat yMin = (GLfloat)rect->y; - GLfloat yMax = (GLfloat)(rect->y + rect->h); - - vertices[0] = xMin; - vertices[1] = yMin; - vertices[2] = xMax; - vertices[3] = yMin; - vertices[4] = xMin; - vertices[5] = yMax; - vertices[6] = xMax; - vertices[7] = yMax; - 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; - } - return 0; -} - -static int -GLES2_RenderCopy(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_Rect *srcrect, - const SDL_Rect *dstrect) -{ - GLES2_DriverContext *rdata = (GLES2_DriverContext *)renderer->driverdata; - GLES2_TextureData *tdata = (GLES2_TextureData *)texture->driverdata; - GLES2_ImageSource sourceType; - SDL_BlendMode blendMode; - GLfloat vertices[8]; - GLfloat texCoords[8]; - GLuint locTexture; - GLuint locModulation; - - GLES2_ActivateRenderer(renderer); - - /* Activate an appropriate shader and set the projection matrix */ - blendMode = texture->blendMode; - if (renderer->target) { - /* Check if we need to do color mapping between the source and render target textures */ - if (renderer->target->format != texture->format) { - switch (texture->format) - { - case SDL_PIXELFORMAT_ABGR8888: - switch (renderer->target->format) - { - case SDL_PIXELFORMAT_ARGB8888: - case SDL_PIXELFORMAT_RGB888: - sourceType = GLES2_IMAGESOURCE_TEXTURE_ARGB; - break; - case SDL_PIXELFORMAT_BGR888: - sourceType = GLES2_IMAGESOURCE_TEXTURE_ABGR; - break; - } - break; - case SDL_PIXELFORMAT_ARGB8888: - switch (renderer->target->format) - { - case SDL_PIXELFORMAT_ABGR8888: - case SDL_PIXELFORMAT_BGR888: - sourceType = GLES2_IMAGESOURCE_TEXTURE_ARGB; - break; - case SDL_PIXELFORMAT_RGB888: - sourceType = GLES2_IMAGESOURCE_TEXTURE_ABGR; - break; - } - break; - case SDL_PIXELFORMAT_BGR888: - switch (renderer->target->format) - { - case SDL_PIXELFORMAT_ABGR8888: - sourceType = GLES2_IMAGESOURCE_TEXTURE_BGR; - break; - case SDL_PIXELFORMAT_ARGB8888: - sourceType = GLES2_IMAGESOURCE_TEXTURE_RGB; - break; - case SDL_PIXELFORMAT_RGB888: - sourceType = GLES2_IMAGESOURCE_TEXTURE_ARGB; - break; - } - break; - case SDL_PIXELFORMAT_RGB888: - switch (renderer->target->format) - { - case SDL_PIXELFORMAT_ABGR8888: - sourceType = GLES2_IMAGESOURCE_TEXTURE_ARGB; - break; - case SDL_PIXELFORMAT_ARGB8888: - sourceType = GLES2_IMAGESOURCE_TEXTURE_BGR; - break; - case SDL_PIXELFORMAT_BGR888: - sourceType = GLES2_IMAGESOURCE_TEXTURE_ARGB; - break; - } - break; - } - } - else sourceType = GLES2_IMAGESOURCE_TEXTURE_ABGR; // Texture formats match, use the non color mapping shader (even if the formats are not ABGR) - } - else { - switch (texture->format) - { - case SDL_PIXELFORMAT_ABGR8888: - sourceType = GLES2_IMAGESOURCE_TEXTURE_ABGR; - break; - case SDL_PIXELFORMAT_ARGB8888: - sourceType = GLES2_IMAGESOURCE_TEXTURE_ARGB; - break; - case SDL_PIXELFORMAT_BGR888: - sourceType = GLES2_IMAGESOURCE_TEXTURE_BGR; - break; - case SDL_PIXELFORMAT_RGB888: - sourceType = GLES2_IMAGESOURCE_TEXTURE_RGB; - break; - } - } - if (GLES2_SelectProgram(renderer, sourceType, blendMode) < 0) - return -1; - - /* Select the target texture */ - locTexture = rdata->current_program->uniform_locations[GLES2_UNIFORM_TEXTURE]; - rdata->glGetError(); - rdata->glActiveTexture(GL_TEXTURE0); - rdata->glBindTexture(tdata->texture_type, tdata->texture); - rdata->glUniform1i(locTexture, 0); - - /* Configure color modulation */ - locModulation = rdata->current_program->uniform_locations[GLES2_UNIFORM_MODULATION]; - if (renderer->target && - (renderer->target->format == SDL_PIXELFORMAT_ARGB8888 || - renderer->target->format == SDL_PIXELFORMAT_RGB888)) { - rdata->glUniform4f(locModulation, - texture->b * inv255f, - texture->g * inv255f, - texture->r * inv255f, - texture->a * inv255f); - } else { - rdata->glUniform4f(locModulation, - texture->r * inv255f, - texture->g * inv255f, - texture->b * inv255f, - texture->a * inv255f); - } - - /* Configure texture blending */ - GLES2_SetBlendMode(rdata, blendMode); - - GLES2_SetTexCoords(rdata, SDL_TRUE); - - /* Emit the textured quad */ - vertices[0] = (GLfloat)dstrect->x; - vertices[1] = (GLfloat)dstrect->y; - vertices[2] = (GLfloat)(dstrect->x + dstrect->w); - vertices[3] = (GLfloat)dstrect->y; - vertices[4] = (GLfloat)dstrect->x; - vertices[5] = (GLfloat)(dstrect->y + dstrect->h); - vertices[6] = (GLfloat)(dstrect->x + dstrect->w); - vertices[7] = (GLfloat)(dstrect->y + dstrect->h); - rdata->glVertexAttribPointer(GLES2_ATTRIBUTE_POSITION, 2, GL_FLOAT, GL_FALSE, 0, vertices); - texCoords[0] = srcrect->x / (GLfloat)texture->w; - texCoords[1] = srcrect->y / (GLfloat)texture->h; - texCoords[2] = (srcrect->x + srcrect->w) / (GLfloat)texture->w; - texCoords[3] = srcrect->y / (GLfloat)texture->h; - texCoords[4] = srcrect->x / (GLfloat)texture->w; - texCoords[5] = (srcrect->y + srcrect->h) / (GLfloat)texture->h; - texCoords[6] = (srcrect->x + srcrect->w) / (GLfloat)texture->w; - 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; - } - return 0; -} - -static int -GLES2_RenderCopyEx(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_Rect *srcrect, - const SDL_Rect *dstrect, const double angle, const SDL_Point *center, const SDL_RendererFlip flip) -{ - GLES2_DriverContext *rdata = (GLES2_DriverContext *)renderer->driverdata; - GLES2_TextureData *tdata = (GLES2_TextureData *)texture->driverdata; - GLES2_ImageSource sourceType; - SDL_BlendMode blendMode; - GLfloat vertices[8]; - GLfloat texCoords[8]; - GLuint locTexture; - GLuint locModulation; - GLfloat translate[8]; - GLfloat fAngle[4]; - GLfloat tmp; - - GLES2_ActivateRenderer(renderer); - - rdata->glEnableVertexAttribArray(GLES2_ATTRIBUTE_CENTER); - rdata->glEnableVertexAttribArray(GLES2_ATTRIBUTE_ANGLE); - fAngle[0] = fAngle[1] = fAngle[2] = fAngle[3] = (GLfloat)angle; - /* Calculate the center of rotation */ - translate[0] = translate[2] = translate[4] = translate[6] = (GLfloat)(center->x + dstrect->x); - translate[1] = translate[3] = translate[5] = translate[7] = (GLfloat)(center->y + dstrect->y); - - /* Activate an appropriate shader and set the projection matrix */ - blendMode = texture->blendMode; - if (renderer->target) { - /* Check if we need to do color mapping between the source and render target textures */ - if (renderer->target->format != texture->format) { - switch (texture->format) - { - case SDL_PIXELFORMAT_ABGR8888: - switch (renderer->target->format) - { - case SDL_PIXELFORMAT_ARGB8888: - case SDL_PIXELFORMAT_RGB888: - sourceType = GLES2_IMAGESOURCE_TEXTURE_ARGB; - break; - case SDL_PIXELFORMAT_BGR888: - sourceType = GLES2_IMAGESOURCE_TEXTURE_ABGR; - break; - } - break; - case SDL_PIXELFORMAT_ARGB8888: - switch (renderer->target->format) - { - case SDL_PIXELFORMAT_ABGR8888: - case SDL_PIXELFORMAT_BGR888: - sourceType = GLES2_IMAGESOURCE_TEXTURE_ARGB; - break; - case SDL_PIXELFORMAT_RGB888: - sourceType = GLES2_IMAGESOURCE_TEXTURE_ABGR; - break; - } - break; - case SDL_PIXELFORMAT_BGR888: - switch (renderer->target->format) - { - case SDL_PIXELFORMAT_ABGR8888: - sourceType = GLES2_IMAGESOURCE_TEXTURE_BGR; - break; - case SDL_PIXELFORMAT_ARGB8888: - sourceType = GLES2_IMAGESOURCE_TEXTURE_RGB; - break; - case SDL_PIXELFORMAT_RGB888: - sourceType = GLES2_IMAGESOURCE_TEXTURE_ARGB; - break; - } - break; - case SDL_PIXELFORMAT_RGB888: - switch (renderer->target->format) - { - case SDL_PIXELFORMAT_ABGR8888: - sourceType = GLES2_IMAGESOURCE_TEXTURE_ARGB; - break; - case SDL_PIXELFORMAT_ARGB8888: - sourceType = GLES2_IMAGESOURCE_TEXTURE_BGR; - break; - case SDL_PIXELFORMAT_BGR888: - sourceType = GLES2_IMAGESOURCE_TEXTURE_ARGB; - break; - } - break; - } - } - else sourceType = GLES2_IMAGESOURCE_TEXTURE_ABGR; // Texture formats match, use the non color mapping shader (even if the formats are not ABGR) - } - else { - switch (texture->format) - { - case SDL_PIXELFORMAT_ABGR8888: - sourceType = GLES2_IMAGESOURCE_TEXTURE_ABGR; - break; - case SDL_PIXELFORMAT_ARGB8888: - sourceType = GLES2_IMAGESOURCE_TEXTURE_ARGB; - break; - case SDL_PIXELFORMAT_BGR888: - sourceType = GLES2_IMAGESOURCE_TEXTURE_BGR; - break; - case SDL_PIXELFORMAT_RGB888: - sourceType = GLES2_IMAGESOURCE_TEXTURE_RGB; - break; - } - } - if (GLES2_SelectProgram(renderer, sourceType, blendMode) < 0) - return -1; - - /* Select the target texture */ - locTexture = rdata->current_program->uniform_locations[GLES2_UNIFORM_TEXTURE]; - rdata->glGetError(); - rdata->glActiveTexture(GL_TEXTURE0); - rdata->glBindTexture(tdata->texture_type, tdata->texture); - rdata->glUniform1i(locTexture, 0); - - /* Configure color modulation */ - locModulation = rdata->current_program->uniform_locations[GLES2_UNIFORM_MODULATION]; - if (renderer->target && - (renderer->target->format == SDL_PIXELFORMAT_ARGB8888 || - renderer->target->format == SDL_PIXELFORMAT_RGB888)) { - rdata->glUniform4f(locModulation, - texture->b * inv255f, - texture->g * inv255f, - texture->r * inv255f, - texture->a * inv255f); - } else { - rdata->glUniform4f(locModulation, - texture->r * inv255f, - texture->g * inv255f, - texture->b * inv255f, - texture->a * inv255f); - } - - /* Configure texture blending */ - GLES2_SetBlendMode(rdata, blendMode); - - GLES2_SetTexCoords(rdata, SDL_TRUE); - - /* Emit the textured quad */ - vertices[0] = (GLfloat)dstrect->x; - vertices[1] = (GLfloat)dstrect->y; - vertices[2] = (GLfloat)(dstrect->x + dstrect->w); - vertices[3] = (GLfloat)dstrect->y; - vertices[4] = (GLfloat)dstrect->x; - vertices[5] = (GLfloat)(dstrect->y + dstrect->h); - vertices[6] = (GLfloat)(dstrect->x + dstrect->w); - vertices[7] = (GLfloat)(dstrect->y + dstrect->h); - if (flip & SDL_FLIP_HORIZONTAL) { - tmp = vertices[0]; - vertices[0] = vertices[4] = vertices[2]; - vertices[2] = vertices[6] = tmp; - } - if (flip & SDL_FLIP_VERTICAL) { - tmp = vertices[1]; - vertices[1] = vertices[3] = vertices[5]; - vertices[5] = vertices[7] = tmp; - } - - rdata->glVertexAttribPointer(GLES2_ATTRIBUTE_ANGLE, 1, GL_FLOAT, GL_FALSE, 0, &fAngle); - rdata->glVertexAttribPointer(GLES2_ATTRIBUTE_CENTER, 2, GL_FLOAT, GL_FALSE, 0, translate); - rdata->glVertexAttribPointer(GLES2_ATTRIBUTE_POSITION, 2, GL_FLOAT, GL_FALSE, 0, vertices); - - texCoords[0] = srcrect->x / (GLfloat)texture->w; - texCoords[1] = srcrect->y / (GLfloat)texture->h; - texCoords[2] = (srcrect->x + srcrect->w) / (GLfloat)texture->w; - texCoords[3] = srcrect->y / (GLfloat)texture->h; - texCoords[4] = srcrect->x / (GLfloat)texture->w; - texCoords[5] = (srcrect->y + srcrect->h) / (GLfloat)texture->h; - texCoords[6] = (srcrect->x + srcrect->w) / (GLfloat)texture->w; - 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); - rdata->glDisableVertexAttribArray(GLES2_ATTRIBUTE_CENTER); - rdata->glDisableVertexAttribArray(GLES2_ATTRIBUTE_ANGLE); - if (rdata->glGetError() != GL_NO_ERROR) - { - SDL_SetError("Failed to render texture"); - return -1; - } - return 0; -} - -static int -GLES2_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect, - Uint32 pixel_format, void * pixels, int pitch) -{ - GLES2_DriverContext *rdata = (GLES2_DriverContext *)renderer->driverdata; - SDL_Window *window = renderer->window; - Uint32 temp_format = SDL_PIXELFORMAT_ABGR8888; - void *temp_pixels; - int temp_pitch; - Uint8 *src, *dst, *tmp; - int w, h, length, rows; - int status; - - GLES2_ActivateRenderer(renderer); - - temp_pitch = rect->w * SDL_BYTESPERPIXEL(temp_format); - temp_pixels = SDL_malloc(rect->h * temp_pitch); - if (!temp_pixels) { - SDL_OutOfMemory(); - return -1; - } - - SDL_GetWindowSize(window, &w, &h); - - rdata->glPixelStorei(GL_PACK_ALIGNMENT, 1); - - rdata->glReadPixels(rect->x, (h-rect->y)-rect->h, rect->w, rect->h, - GL_RGBA, GL_UNSIGNED_BYTE, temp_pixels); - - /* Flip the rows to be top-down */ - length = rect->w * SDL_BYTESPERPIXEL(temp_format); - src = (Uint8*)temp_pixels + (rect->h-1)*temp_pitch; - dst = (Uint8*)temp_pixels; - tmp = SDL_stack_alloc(Uint8, length); - rows = rect->h / 2; - while (rows--) { - SDL_memcpy(tmp, dst, length); - SDL_memcpy(dst, src, length); - SDL_memcpy(src, tmp, length); - dst += temp_pitch; - src -= temp_pitch; - } - SDL_stack_free(tmp); - - status = SDL_ConvertPixels(rect->w, rect->h, - temp_format, temp_pixels, temp_pitch, - pixel_format, pixels, pitch); - SDL_free(temp_pixels); - - return status; -} - -static void -GLES2_RenderPresent(SDL_Renderer *renderer) -{ - GLES2_ActivateRenderer(renderer); - - /* Tell the video driver to swap buffers */ - SDL_GL_SwapWindow(renderer->window); -} - - -/************************************************************************************************* - * Bind/unbinding of textures - *************************************************************************************************/ -static int GLES2_BindTexture (SDL_Renderer * renderer, SDL_Texture *texture, float *texw, float *texh); -static int GLES2_UnbindTexture (SDL_Renderer * renderer, SDL_Texture *texture); - -static int GLES2_BindTexture (SDL_Renderer * renderer, SDL_Texture *texture, float *texw, float *texh) { - GLES2_DriverContext *data = (GLES2_DriverContext *)renderer->driverdata; - 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; - if(texh) *texh = 1.0; - - return 0; -} - -static int GLES2_UnbindTexture (SDL_Renderer * renderer, SDL_Texture *texture) { - GLES2_DriverContext *data = (GLES2_DriverContext *)renderer->driverdata; - GLES2_TextureData *texturedata = (GLES2_TextureData *)texture->driverdata; - GLES2_ActivateRenderer(renderer); - - data->glActiveTexture(GL_TEXTURE0); - data->glDisable(texturedata->texture_type); - - return 0; -} - - -/************************************************************************************************* - * Renderer instantiation * - *************************************************************************************************/ - -#define GL_NVIDIA_PLATFORM_BINARY_NV 0x890B - -static void -GLES2_ResetState(SDL_Renderer *renderer) -{ - GLES2_DriverContext *rdata = (GLES2_DriverContext *) renderer->driverdata; - - if (SDL_CurrentContext == rdata->context) { - GLES2_UpdateViewport(renderer); - } else { - GLES2_ActivateRenderer(renderer); - } - - rdata->current.blendMode = -1; - rdata->current.tex_coords = SDL_FALSE; - - rdata->glEnableVertexAttribArray(GLES2_ATTRIBUTE_POSITION); - rdata->glDisableVertexAttribArray(GLES2_ATTRIBUTE_TEXCOORD); -} - -static SDL_Renderer * -GLES2_CreateRenderer(SDL_Window *window, Uint32 flags) -{ - SDL_Renderer *renderer; - GLES2_DriverContext *rdata; - GLint nFormats; -#ifndef ZUNE_HD - GLboolean hasCompiler; -#endif - Uint32 windowFlags; - GLint window_framebuffer; - - SDL_GL_SetAttribute(SDL_GL_CONTEXT_EGL, 1); - SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 2); - SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 0); - - windowFlags = SDL_GetWindowFlags(window); - if (!(windowFlags & SDL_WINDOW_OPENGL)) { - if (SDL_RecreateWindow(window, windowFlags | SDL_WINDOW_OPENGL) < 0) { - /* Uh oh, better try to put it back... */ - SDL_RecreateWindow(window, windowFlags); - return NULL; - } - } - - /* Create the renderer struct */ - renderer = (SDL_Renderer *)SDL_calloc(1, sizeof(SDL_Renderer)); - if (!renderer) { - SDL_OutOfMemory(); - return NULL; - } - - rdata = (GLES2_DriverContext *)SDL_calloc(1, sizeof(GLES2_DriverContext)); - if (!rdata) { - GLES2_DestroyRenderer(renderer); - SDL_OutOfMemory(); - return NULL; - } - renderer->info = GLES2_RenderDriver.info; - renderer->info.flags = SDL_RENDERER_ACCELERATED | SDL_RENDERER_TARGETTEXTURE; - renderer->driverdata = rdata; - renderer->window = window; - - /* Create an OpenGL ES 2.0 context */ - rdata->context = SDL_GL_CreateContext(window); - if (!rdata->context) - { - GLES2_DestroyRenderer(renderer); - return NULL; - } - if (SDL_GL_MakeCurrent(window, rdata->context) < 0) { - GLES2_DestroyRenderer(renderer); - return NULL; - } - - if (GLES2_LoadFunctions(rdata) < 0) { - GLES2_DestroyRenderer(renderer); - return NULL; - } - - if (flags & SDL_RENDERER_PRESENTVSYNC) { - SDL_GL_SetSwapInterval(1); - } else { - SDL_GL_SetSwapInterval(0); - } - if (SDL_GL_GetSwapInterval() > 0) { - renderer->info.flags |= SDL_RENDERER_PRESENTVSYNC; - } - - /* Determine supported shader formats */ - /* HACK: glGetInteger is broken on the Zune HD's compositor, so we just hardcode this */ - rdata->glGetError(); -#ifdef ZUNE_HD - nFormats = 1; -#else /* !ZUNE_HD */ - rdata->glGetIntegerv(GL_NUM_SHADER_BINARY_FORMATS, &nFormats); - rdata->glGetBooleanv(GL_SHADER_COMPILER, &hasCompiler); - if (hasCompiler) - ++nFormats; -#endif /* ZUNE_HD */ - rdata->shader_formats = (GLenum *)SDL_calloc(nFormats, sizeof(GLenum)); - if (!rdata->shader_formats) - { - GLES2_DestroyRenderer(renderer); - SDL_OutOfMemory(); - return NULL; - } - rdata->shader_format_count = nFormats; -#ifdef ZUNE_HD - rdata->shader_formats[0] = GL_NVIDIA_PLATFORM_BINARY_NV; -#else /* !ZUNE_HD */ - rdata->glGetIntegerv(GL_SHADER_BINARY_FORMATS, (GLint *)rdata->shader_formats); - if (rdata->glGetError() != GL_NO_ERROR) - { - GLES2_DestroyRenderer(renderer); - SDL_SetError("Failed to query supported shader formats"); - return NULL; - } - if (hasCompiler) - rdata->shader_formats[nFormats - 1] = (GLenum)-1; -#endif /* ZUNE_HD */ - - rdata->framebuffers = NULL; - rdata->glGetIntegerv(GL_FRAMEBUFFER_BINDING, &window_framebuffer); - rdata->window_framebuffer = (GLuint)window_framebuffer; - - /* Populate the function pointers for the module */ - renderer->WindowEvent = &GLES2_WindowEvent; - renderer->CreateTexture = &GLES2_CreateTexture; - renderer->UpdateTexture = &GLES2_UpdateTexture; - renderer->LockTexture = &GLES2_LockTexture; - renderer->UnlockTexture = &GLES2_UnlockTexture; - renderer->SetRenderTarget = &GLES2_SetRenderTarget; - renderer->UpdateViewport = &GLES2_UpdateViewport; - renderer->RenderClear = &GLES2_RenderClear; - renderer->RenderDrawPoints = &GLES2_RenderDrawPoints; - renderer->RenderDrawLines = &GLES2_RenderDrawLines; - renderer->RenderFillRects = &GLES2_RenderFillRects; - renderer->RenderCopy = &GLES2_RenderCopy; - renderer->RenderReadPixels = &GLES2_RenderReadPixels; - renderer->RenderCopyEx = &GLES2_RenderCopyEx; - renderer->RenderPresent = &GLES2_RenderPresent; - renderer->DestroyTexture = &GLES2_DestroyTexture; - renderer->DestroyRenderer = &GLES2_DestroyRenderer; - renderer->GL_BindTexture = &GLES2_BindTexture; - renderer->GL_UnbindTexture = &GLES2_UnbindTexture; - - GLES2_ResetState(renderer); - - return renderer; -} - -#endif /* SDL_VIDEO_RENDER_OGL_ES2 && !SDL_RENDER_DISABLED */ - -/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/SDL-mobile/src/render/opengles2/SDL_shaders_gles2.c b/src/SDL-mobile/src/render/opengles2/SDL_shaders_gles2.c deleted file mode 100644 index 423e3b1e2..000000000 --- a/src/SDL-mobile/src/render/opengles2/SDL_shaders_gles2.c +++ /dev/null @@ -1,785 +0,0 @@ -/* - Simple DirectMedia Layer - Copyright (C) 1997-2012 Sam Lantinga - - 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_OGL_ES2 && !SDL_RENDER_DISABLED - -#include "SDL_video.h" -#include "SDL_opengles2.h" -#include "SDL_shaders_gles2.h" -#include "SDL_stdinc.h" - -/************************************************************************************************* - * Vertex/fragment shader source * - *************************************************************************************************/ - -static const Uint8 GLES2_VertexSrc_Default_[] = " \ - uniform mat4 u_projection; \ - attribute vec2 a_position; \ - attribute vec2 a_texCoord; \ - attribute float a_angle; \ - attribute vec2 a_center; \ - varying vec2 v_texCoord; \ - \ - void main() \ - { \ - float angle = radians(a_angle); \ - float c = cos(angle); \ - float s = sin(angle); \ - mat2 rotationMatrix = mat2(c, -s, s, c); \ - vec2 position = rotationMatrix * (a_position - a_center) + a_center; \ - v_texCoord = a_texCoord; \ - gl_Position = u_projection * vec4(position, 0.0, 1.0);\ - gl_PointSize = 1.0; \ - } \ -"; - -static const Uint8 GLES2_FragmentSrc_SolidSrc_[] = " \ - precision mediump float; \ - uniform vec4 u_color; \ - \ - void main() \ - { \ - gl_FragColor = u_color; \ - } \ -"; - -static const Uint8 GLES2_FragmentSrc_TextureABGRSrc_[] = " \ - precision mediump float; \ - uniform sampler2D u_texture; \ - uniform vec4 u_modulation; \ - varying vec2 v_texCoord; \ - \ - void main() \ - { \ - gl_FragColor = texture2D(u_texture, v_texCoord); \ - gl_FragColor *= u_modulation; \ - } \ -"; - -// ARGB to ABGR conversion -static const Uint8 GLES2_FragmentSrc_TextureARGBSrc_[] = " \ - precision mediump float; \ - uniform sampler2D u_texture; \ - uniform vec4 u_modulation; \ - varying vec2 v_texCoord; \ - \ - void main() \ - { \ - vec4 abgr = texture2D(u_texture, v_texCoord); \ - gl_FragColor = abgr; \ - gl_FragColor.r = abgr.b; \ - gl_FragColor.b = abgr.r; \ - gl_FragColor *= u_modulation; \ - } \ -"; - -// RGB to ABGR conversion -static const Uint8 GLES2_FragmentSrc_TextureRGBSrc_[] = " \ - precision mediump float; \ - uniform sampler2D u_texture; \ - uniform vec4 u_modulation; \ - varying vec2 v_texCoord; \ - \ - void main() \ - { \ - vec4 abgr = texture2D(u_texture, v_texCoord); \ - gl_FragColor = abgr; \ - gl_FragColor.r = abgr.b; \ - gl_FragColor.b = abgr.r; \ - gl_FragColor.a = 1.0; \ - gl_FragColor *= u_modulation; \ - } \ -"; - -// BGR to ABGR conversion -static const Uint8 GLES2_FragmentSrc_TextureBGRSrc_[] = " \ - precision mediump float; \ - uniform sampler2D u_texture; \ - uniform vec4 u_modulation; \ - varying vec2 v_texCoord; \ - \ - void main() \ - { \ - vec4 abgr = texture2D(u_texture, v_texCoord); \ - gl_FragColor = abgr; \ - gl_FragColor.a = 1.0; \ - gl_FragColor *= u_modulation; \ - } \ -"; - -static const GLES2_ShaderInstance GLES2_VertexSrc_Default = { - GL_VERTEX_SHADER, - GLES2_SOURCE_SHADER, - sizeof(GLES2_VertexSrc_Default_), - GLES2_VertexSrc_Default_ -}; - -static const GLES2_ShaderInstance GLES2_FragmentSrc_SolidSrc = { - GL_FRAGMENT_SHADER, - GLES2_SOURCE_SHADER, - sizeof(GLES2_FragmentSrc_SolidSrc_), - GLES2_FragmentSrc_SolidSrc_ -}; - -static const GLES2_ShaderInstance GLES2_FragmentSrc_TextureABGRSrc = { - GL_FRAGMENT_SHADER, - GLES2_SOURCE_SHADER, - sizeof(GLES2_FragmentSrc_TextureABGRSrc_), - GLES2_FragmentSrc_TextureABGRSrc_ -}; - -static const GLES2_ShaderInstance GLES2_FragmentSrc_TextureARGBSrc = { - GL_FRAGMENT_SHADER, - GLES2_SOURCE_SHADER, - sizeof(GLES2_FragmentSrc_TextureARGBSrc_), - GLES2_FragmentSrc_TextureARGBSrc_ -}; - -static const GLES2_ShaderInstance GLES2_FragmentSrc_TextureRGBSrc = { - GL_FRAGMENT_SHADER, - GLES2_SOURCE_SHADER, - sizeof(GLES2_FragmentSrc_TextureRGBSrc_), - GLES2_FragmentSrc_TextureRGBSrc_ -}; - -static const GLES2_ShaderInstance GLES2_FragmentSrc_TextureBGRSrc = { - GL_FRAGMENT_SHADER, - GLES2_SOURCE_SHADER, - sizeof(GLES2_FragmentSrc_TextureBGRSrc_), - GLES2_FragmentSrc_TextureBGRSrc_ -}; - -/************************************************************************************************* - * Vertex/fragment shader binaries (NVIDIA Tegra 1/2) * - *************************************************************************************************/ - -#if GLES2_INCLUDE_NVIDIA_SHADERS - -#define GL_NVIDIA_PLATFORM_BINARY_NV 0x890B - -static const Uint8 GLES2_VertexTegra_Default_[] = { - 243, 193, 1, 142, 31, 109, 131, 38, 6, 0, 1, 0, 5, 0, 0, 0, 17, 0, 0, 0, 1, 0, 0, 0, 73, 0, - 0, 0, 46, 0, 0, 0, 48, 0, 0, 0, 2, 0, 0, 0, 85, 0, 0, 0, 2, 0, 0, 0, 24, 0, 0, 0, 3, 0, 0, 0, - 91, 0, 0, 0, 1, 0, 0, 0, 16, 0, 0, 0, 5, 0, 0, 0, 95, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8, 0, 0, 0, 95, 0, 0, 0, 1, 0, 0, 0, 28, 0, 0, 0, - 13, 0, 0, 0, 102, 0, 0, 0, 2, 0, 0, 0, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 16, 0, 0, 0, 104, 0, 0, 0, 1, 0, 0, 0, 32, 0, 0, 0, 17, 0, 0, 0, 112, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 18, 0, 0, 0, 112, 0, 0, 0, 80, 0, 0, 0, 80, 0, 0, 0, 19, 0, 0, 0, 132, 0, - 0, 0, 104, 0, 0, 0, 104, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 109, 97, 110, 70, 73, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 97, - 95, 112, 111, 115, 105, 116, 105, 111, 110, 0, 97, 95, 116, 101, 120, 67, 111, 111, 114, 100, - 0, 118, 95, 116, 101, 120, 67, 111, 111, 114, 100, 0, 117, 95, 112, 114, 111, 106, 101, 99, - 116, 105, 111, 110, 0, 0, 0, 0, 0, 0, 0, 82, 139, 0, 0, 0, 0, 0, 0, 11, 0, 0, 0, 80, 139, 0, - 0, 1, 0, 0, 0, 22, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 33, 0, 0, 0, 92, 139, 0, 0, - 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 240, 0, 0, 0, 0, 0, 0, 1, 0, - 0, 0, 64, 0, 0, 0, 80, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 193, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 128, 63, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 66, 24, 0, 6, 34, 108, 28, - 0, 0, 42, 16, 128, 0, 195, 192, 6, 129, 252, 255, 65, 96, 108, 28, 0, 0, 0, 0, 0, 1, 195, 192, - 6, 1, 252, 255, 33, 96, 108, 156, 31, 64, 8, 1, 64, 0, 131, 192, 6, 1, 156, 159, 65, 96, 108, - 28, 0, 0, 85, 32, 0, 1, 195, 192, 6, 1, 252, 255, 33, 96, 108, 156, 31, 64, 0, 64, 64, 0, 131, - 192, 134, 1, 152, 31, 65, 96, 108, 156, 31, 64, 127, 48, 0, 1, 195, 192, 6, 129, 129, 255, 33, - 96 -}; - -static const Uint8 GLES2_FragmentTegra_None_SolidSrc_[] = { - 155, 191, 159, 1, 47, 109, 131, 38, 6, 0, 1, 0, 5, 0, 0, 0, 17, 0, 0, 0, 1, 0, 0, 0, 73, 0, - 0, 0, 8, 0, 0, 0, 8, 0, 0, 0, 2, 0, 0, 0, 75, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 0, 0, 0, 75, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 0, 0, 0, 75, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 0, 0, 0, - 75, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8, 0, 0, 0, 75, 0, 0, 0, 1, 0, 0, 0, 28, 0, 0, 0, 13, 0, - 0, 0, 82, 0, 0, 0, 2, 0, 0, 0, 8, 0, 0, 0, 14, 0, 0, 0, 84, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 22, 0, 0, 0, 84, 0, 0, 0, 8, 0, 0, 0, 32, 0, 0, 0, 23, 0, 0, 0, 92, 0, 0, 0, 1, 0, 0, 0, 4, - 0, 0, 0, 15, 0, 0, 0, 93, 0, 0, 0, 1, 0, 0, 0, 80, 0, 0, 0, 17, 0, 0, 0, 113, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 18, 0, 0, 0, 113, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 19, 0, 0, 0, 113, 0, 0, - 0, 108, 0, 0, 0, 108, 0, 0, 0, 20, 0, 0, 0, 113, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 21, 0, 0, - 0, 113, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 109, 97, 110, 70, 73, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 117, 95, 99, 111, 108, 111, 114, 0, 0, 0, 0, 0, 82, 139, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 48, 0, 0, 0, 0, 0, 0, 0, 0, 0, 241, 0, 0, 0, 240, 0, 0, - 0, 240, 0, 0, 0, 240, 0, 0, 0, 240, 0, 0, 0, 240, 0, 0, 0, 240, 0, 0, 0, 240, 0, 0, 0, 0, 0, - 0, 0, 0, 1, 0, 0, 0, 7, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 21, 32, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 20, 0, 0, 0, 16, 0, 0, 0, 16, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 65, 82, 50, 48, 45, 66, 73, 78, 1, - 0, 0, 0, 1, 0, 0, 0, 1, 0, 65, 37, 0, 0, 0, 0, 1, 0, 0, 21, 0, 0, 0, 0, 1, 0, 1, 38, 0, 0, 0, - 0, 1, 0, 1, 39, 0, 0, 0, 0, 1, 0, 1, 40, 1, 0, 0, 0, 8, 0, 4, 40, 0, 40, 0, 0, 0, 242, 65, 63, - 192, 200, 0, 0, 0, 242, 65, 63, 128, 168, 0, 0, 0, 242, 65, 63, 64, 72, 0, 0, 0, 242, 65, 63, - 1, 0, 6, 40, 0, 0, 0, 0, 1, 0, 1, 41, 5, 0, 2, 0 -}; - -static const Uint8 GLES2_FragmentTegra_Alpha_SolidSrc_[] = { - 169, 153, 195, 28, 47, 109, 131, 38, 6, 0, 1, 0, 5, 0, 0, 0, 17, 0, 0, 0, 1, 0, 0, 0, 73, 0, - 0, 0, 8, 0, 0, 0, 8, 0, 0, 0, 2, 0, 0, 0, 75, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 0, 0, 0, 75, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 0, 0, 0, 75, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 0, 0, 0, - 75, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8, 0, 0, 0, 75, 0, 0, 0, 1, 0, 0, 0, 28, 0, 0, 0, 13, 0, - 0, 0, 82, 0, 0, 0, 2, 0, 0, 0, 8, 0, 0, 0, 14, 0, 0, 0, 84, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 22, 0, 0, 0, 84, 0, 0, 0, 8, 0, 0, 0, 32, 0, 0, 0, 23, 0, 0, 0, 92, 0, 0, 0, 1, 0, 0, 0, 4, - 0, 0, 0, 15, 0, 0, 0, 93, 0, 0, 0, 1, 0, 0, 0, 80, 0, 0, 0, 17, 0, 0, 0, 113, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 18, 0, 0, 0, 113, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 19, 0, 0, 0, 113, 0, 0, - 0, 220, 0, 0, 0, 220, 0, 0, 0, 20, 0, 0, 0, 113, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 21, 0, 0, - 0, 113, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 109, 97, 110, 70, 73, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 117, 95, 99, 111, 108, 111, 114, 0, 0, 0, 0, 0, 82, 139, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 48, 0, 0, 0, 0, 0, 0, 118, 118, 17, 241, 0, 0, 0, 240, 0, - 0, 0, 240, 0, 0, 0, 240, 0, 0, 0, 240, 0, 0, 0, 240, 0, 0, 0, 240, 0, 0, 0, 240, 0, 0, 0, 0, - 0, 0, 0, 0, 1, 0, 0, 0, 7, 0, 0, 0, 2, 0, 0, 0, 1, 0, 0, 0, 3, 0, 0, 0, 21, 32, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 20, 0, 0, 0, 16, 0, 0, 0, 16, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 65, 82, 50, 48, 45, 66, 73, 78, - 1, 0, 0, 0, 3, 0, 0, 0, 3, 0, 65, 37, 8, 0, 129, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 21, 0, - 0, 0, 0, 3, 0, 1, 38, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, 1, 39, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 3, 0, 1, 40, 1, 0, 0, 0, 5, 0, 0, 0, 9, 0, 0, 0, 24, 0, 4, 40, 232, 231, 15, - 0, 0, 242, 65, 62, 194, 72, 1, 0, 0, 250, 65, 63, 194, 40, 1, 0, 0, 250, 65, 63, 192, 168, 1, - 0, 0, 242, 1, 64, 192, 168, 1, 0, 0, 242, 1, 68, 168, 32, 0, 0, 0, 50, 64, 0, 192, 168, 15, - 0, 0, 242, 1, 66, 168, 64, 0, 16, 0, 242, 65, 1, 232, 231, 15, 0, 0, 242, 65, 62, 168, 160, - 0, 0, 0, 50, 64, 2, 104, 192, 0, 0, 36, 48, 66, 4, 232, 231, 15, 0, 0, 242, 65, 62, 3, 0, 6, - 40, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, 1, 41, 0, 0, 0, 0, 0, 0, 0, 0, 5, 0, 2, 0 -}; - -static const Uint8 GLES2_FragmentTegra_Additive_SolidSrc_[] = { - 59, 71, 42, 17, 47, 109, 131, 38, 6, 0, 1, 0, 5, 0, 0, 0, 17, 0, 0, 0, 1, 0, 0, 0, 73, 0, 0, - 0, 8, 0, 0, 0, 8, 0, 0, 0, 2, 0, 0, 0, 75, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 0, 0, 0, 75, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 0, 0, 0, 75, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 0, 0, 0, - 75, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8, 0, 0, 0, 75, 0, 0, 0, 1, 0, 0, 0, 28, 0, 0, 0, 13, 0, - 0, 0, 82, 0, 0, 0, 2, 0, 0, 0, 8, 0, 0, 0, 14, 0, 0, 0, 84, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 22, 0, 0, 0, 84, 0, 0, 0, 8, 0, 0, 0, 32, 0, 0, 0, 23, 0, 0, 0, 92, 0, 0, 0, 1, 0, 0, 0, 4, - 0, 0, 0, 15, 0, 0, 0, 93, 0, 0, 0, 1, 0, 0, 0, 80, 0, 0, 0, 17, 0, 0, 0, 113, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 18, 0, 0, 0, 113, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 19, 0, 0, 0, 113, 0, 0, - 0, 108, 0, 0, 0, 108, 0, 0, 0, 20, 0, 0, 0, 113, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 21, 0, 0, - 0, 113, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 109, 97, 110, 70, 73, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 117, 95, 99, 111, 108, 111, 114, 0, 0, 0, 0, 0, 82, 139, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 48, 0, 0, 0, 0, 0, 0, 22, 22, 17, 241, 0, 0, 0, 240, 0, - 0, 0, 240, 0, 0, 0, 240, 0, 0, 0, 240, 0, 0, 0, 240, 0, 0, 0, 240, 0, 0, 0, 240, 0, 0, 0, 0, - 0, 0, 0, 0, 1, 0, 0, 0, 7, 0, 0, 0, 2, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 21, 32, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 20, 0, 0, 0, 16, 0, 0, 0, 16, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 65, 82, 50, 48, 45, 66, 73, 78, - 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 65, 37, 8, 0, 129, 0, 1, 0, 0, 21, 0, 0, 0, 0, 1, 0, 1, 38, 0, - 0, 0, 0, 1, 0, 1, 39, 0, 0, 0, 0, 1, 0, 1, 40, 1, 0, 0, 0, 8, 0, 4, 40, 192, 200, 0, 0, 0, 26, - 0, 70, 192, 40, 0, 0, 0, 2, 0, 64, 192, 72, 0, 0, 0, 10, 0, 66, 192, 168, 0, 0, 0, 18, 0, 68, - 1, 0, 6, 40, 0, 0, 0, 0, 1, 0, 1, 41, 5, 0, 2, 0 -}; - -static const Uint8 GLES2_FragmentTegra_Modulated_SolidSrc_[] = { - 37, 191, 49, 17, 47, 109, 131, 38, 6, 0, 1, 0, 5, 0, 0, 0, 17, 0, 0, 0, 1, 0, 0, 0, 73, 0, 0, - 0, 8, 0, 0, 0, 8, 0, 0, 0, 2, 0, 0, 0, 75, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 0, 0, 0, 75, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 0, 0, 0, 75, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 0, 0, 0, - 75, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8, 0, 0, 0, 75, 0, 0, 0, 1, 0, 0, 0, 28, 0, 0, 0, 13, 0, - 0, 0, 82, 0, 0, 0, 2, 0, 0, 0, 8, 0, 0, 0, 14, 0, 0, 0, 84, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 22, 0, 0, 0, 84, 0, 0, 0, 8, 0, 0, 0, 32, 0, 0, 0, 23, 0, 0, 0, 92, 0, 0, 0, 1, 0, 0, 0, 4, - 0, 0, 0, 15, 0, 0, 0, 93, 0, 0, 0, 1, 0, 0, 0, 80, 0, 0, 0, 17, 0, 0, 0, 113, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 18, 0, 0, 0, 113, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 19, 0, 0, 0, 113, 0, 0, - 0, 108, 0, 0, 0, 108, 0, 0, 0, 20, 0, 0, 0, 113, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 21, 0, 0, - 0, 113, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 109, 97, 110, 70, 73, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 117, 95, 99, 111, 108, 111, 114, 0, 0, 0, 0, 0, 82, 139, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 48, 0, 0, 0, 0, 0, 0, 32, 32, 17, 241, 0, 0, 0, 240, 0, - 0, 0, 240, 0, 0, 0, 240, 0, 0, 0, 240, 0, 0, 0, 240, 0, 0, 0, 240, 0, 0, 0, 240, 0, 0, 0, 0, - 0, 0, 0, 0, 1, 0, 0, 0, 7, 0, 0, 0, 2, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 21, 32, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 20, 0, 0, 0, 16, 0, 0, 0, 16, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 65, 82, 50, 48, 45, 66, 73, 78, - 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 65, 37, 8, 0, 129, 0, 1, 0, 0, 21, 0, 0, 0, 0, 1, 0, 1, 38, 0, - 0, 0, 0, 1, 0, 1, 39, 0, 0, 0, 0, 1, 0, 1, 40, 1, 0, 0, 0, 8, 0, 4, 40, 104, 192, 0, 0, 0, 242, - 1, 70, 8, 32, 0, 0, 0, 242, 1, 64, 40, 64, 0, 0, 0, 242, 1, 66, 72, 160, 0, 0, 0, 242, 1, 68, - 1, 0, 6, 40, 0, 0, 0, 0, 1, 0, 1, 41, 5, 0, 2, 0 -}; - -static const Uint8 GLES2_FragmentTegra_None_TextureSrc_[] = { - 220, 217, 41, 211, 47, 109, 131, 38, 6, 0, 1, 0, 5, 0, 0, 0, 17, 0, 0, 0, 1, 0, 0, 0, 73, 0, - 0, 0, 34, 0, 0, 0, 36, 0, 0, 0, 2, 0, 0, 0, 82, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 0, 0, 0, - 82, 0, 0, 0, 1, 0, 0, 0, 20, 0, 0, 0, 6, 0, 0, 0, 87, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 0, - 0, 0, 87, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8, 0, 0, 0, 87, 0, 0, 0, 2, 0, 0, 0, 56, 0, 0, 0, - 13, 0, 0, 0, 101, 0, 0, 0, 4, 0, 0, 0, 16, 0, 0, 0, 14, 0, 0, 0, 105, 0, 0, 0, 1, 0, 0, 0, 4, - 0, 0, 0, 22, 0, 0, 0, 106, 0, 0, 0, 8, 0, 0, 0, 32, 0, 0, 0, 23, 0, 0, 0, 114, 0, 0, 0, 1, 0, - 0, 0, 4, 0, 0, 0, 15, 0, 0, 0, 115, 0, 0, 0, 1, 0, 0, 0, 80, 0, 0, 0, 17, 0, 0, 0, 135, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 18, 0, 0, 0, 135, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 19, 0, 0, 0, 135, - 0, 0, 0, 120, 0, 0, 0, 120, 0, 0, 0, 20, 0, 0, 0, 135, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 21, - 0, 0, 0, 135, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 109, 97, 110, 70, 73, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 118, 95, 116, 101, 120, 67, 111, 111, 114, 100, 0, 117, 95, 109, 111, 100, 117, 108, - 97, 116, 105, 111, 110, 0, 117, 95, 116, 101, 120, 116, 117, 114, 101, 0, 0, 0, 0, 0, 0, 0, - 2, 0, 0, 0, 0, 0, 0, 0, 220, 0, 0, 0, 0, 0, 0, 0, 11, 0, 0, 0, 82, 139, 0, 0, 1, 0, 0, 0, 1, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 24, 0, 0, 0, 94, 139, 0, 0, 1, 0, 0, 0, 1, 0, 0, - 0, 2, 0, 0, 0, 16, 0, 0, 0, 0, 0, 0, 0, 5, 48, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 1, 0, 0, 0, 241, 0, 0, 0, 240, 0, 0, 0, 240, 0, 0, 0, 240, 0, 0, 0, 240, 0, 0, 0, 240, - 0, 0, 0, 240, 0, 0, 0, 240, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 7, 0, 0, 0, 0, 0, 0, 0, 1, 0, - 0, 0, 1, 0, 0, 0, 21, 32, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 24, 0, 0, 0, 16, 0, 0, 0, 16, 0, 0, - 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 65, 82, 50, 48, 45, 66, 73, 78, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 65, 37, 0, 0, 0, 0, 1, 0, - 0, 21, 0, 0, 0, 0, 1, 0, 1, 38, 1, 0, 0, 0, 2, 0, 4, 38, 186, 81, 78, 16, 2, 1, 0, 0, 1, 0, - 1, 39, 0, 4, 0, 0, 1, 0, 1, 40, 1, 0, 0, 0, 8, 0, 4, 40, 104, 192, 0, 0, 0, 242, 1, 70, 8, 32, - 0, 0, 0, 242, 1, 64, 40, 64, 0, 0, 0, 242, 1, 66, 72, 160, 0, 0, 0, 242, 1, 68, 1, 0, 6, 40, - 0, 0, 0, 0, 1, 0, 1, 41, 5, 0, 2, 0 -}; - -static const Uint8 GLES2_FragmentTegra_Alpha_TextureSrc_[] = { - 71, 202, 114, 229, 47, 109, 131, 38, 6, 0, 1, 0, 5, 0, 0, 0, 17, 0, 0, 0, 1, 0, 0, 0, 73, 0, - 0, 0, 34, 0, 0, 0, 36, 0, 0, 0, 2, 0, 0, 0, 82, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 0, 0, 0, - 82, 0, 0, 0, 1, 0, 0, 0, 20, 0, 0, 0, 6, 0, 0, 0, 87, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 0, - 0, 0, 87, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8, 0, 0, 0, 87, 0, 0, 0, 2, 0, 0, 0, 56, 0, 0, 0, - 13, 0, 0, 0, 101, 0, 0, 0, 4, 0, 0, 0, 16, 0, 0, 0, 14, 0, 0, 0, 105, 0, 0, 0, 1, 0, 0, 0, 4, - 0, 0, 0, 22, 0, 0, 0, 106, 0, 0, 0, 8, 0, 0, 0, 32, 0, 0, 0, 23, 0, 0, 0, 114, 0, 0, 0, 1, 0, - 0, 0, 4, 0, 0, 0, 15, 0, 0, 0, 115, 0, 0, 0, 1, 0, 0, 0, 80, 0, 0, 0, 17, 0, 0, 0, 135, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 18, 0, 0, 0, 135, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 19, 0, 0, 0, 135, - 0, 0, 0, 176, 0, 0, 0, 176, 0, 0, 0, 20, 0, 0, 0, 135, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 21, - 0, 0, 0, 135, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 109, 97, 110, 70, 73, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 118, 95, 116, 101, 120, 67, 111, 111, 114, 100, 0, 117, 95, 109, 111, 100, 117, 108, - 97, 116, 105, 111, 110, 0, 117, 95, 116, 101, 120, 116, 117, 114, 101, 0, 0, 0, 0, 0, 0, 0, - 2, 0, 0, 0, 0, 0, 0, 0, 220, 0, 0, 0, 0, 0, 0, 0, 11, 0, 0, 0, 82, 139, 0, 0, 1, 0, 0, 0, 1, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 24, 0, 0, 0, 94, 139, 0, 0, 1, 0, 0, 0, 1, 0, 0, - 0, 2, 0, 0, 0, 16, 0, 0, 0, 0, 0, 0, 0, 5, 48, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 1, 118, 118, 17, 241, 0, 0, 0, 240, 0, 0, 0, 240, 0, 0, 0, 240, 0, 0, 0, 240, 0, 0, 0, - 240, 0, 0, 0, 240, 0, 0, 0, 240, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 7, 0, 0, 0, 2, 0, 0, 0, - 1, 0, 0, 0, 2, 0, 0, 0, 21, 32, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 24, 0, 0, 0, 16, 0, 0, 0, 16, - 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 65, 82, 50, 48, 45, 66, 73, 78, 1, 0, 0, 0, 2, 0, 0, 0, 2, 0, 65, 37, 0, 0, 0, 0, - 8, 0, 129, 0, 1, 0, 0, 21, 0, 0, 0, 0, 2, 0, 1, 38, 1, 0, 0, 0, 0, 0, 0, 0, 2, 0, 4, 38, 186, - 81, 78, 16, 2, 1, 0, 0, 2, 0, 1, 39, 0, 4, 0, 0, 0, 0, 0, 0, 2, 0, 1, 40, 1, 0, 0, 0, 5, 0, - 0, 0, 16, 0, 4, 40, 40, 160, 1, 0, 0, 242, 1, 66, 8, 192, 1, 0, 0, 242, 1, 64, 104, 32, 1, 0, - 0, 242, 1, 70, 72, 64, 1, 0, 0, 242, 1, 68, 154, 192, 0, 0, 37, 34, 64, 3, 8, 32, 0, 0, 5, 58, - 208, 4, 40, 64, 0, 0, 5, 50, 208, 4, 72, 160, 0, 0, 37, 42, 208, 4, 2, 0, 6, 40, 0, 0, 0, 0, - 0, 0, 0, 0, 2, 0, 1, 41, 0, 0, 0, 0, 5, 0, 2, 0 -}; - -static const Uint8 GLES2_FragmentTegra_Additive_TextureSrc_[] = { - 161, 234, 193, 234, 47, 109, 131, 38, 6, 0, 1, 0, 5, 0, 0, 0, 17, 0, 0, 0, 1, 0, 0, 0, 73, 0, - 0, 0, 34, 0, 0, 0, 36, 0, 0, 0, 2, 0, 0, 0, 82, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 0, 0, 0, - 82, 0, 0, 0, 1, 0, 0, 0, 20, 0, 0, 0, 6, 0, 0, 0, 87, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 0, - 0, 0, 87, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8, 0, 0, 0, 87, 0, 0, 0, 2, 0, 0, 0, 56, 0, 0, 0, - 13, 0, 0, 0, 101, 0, 0, 0, 4, 0, 0, 0, 16, 0, 0, 0, 14, 0, 0, 0, 105, 0, 0, 0, 1, 0, 0, 0, 4, - 0, 0, 0, 22, 0, 0, 0, 106, 0, 0, 0, 8, 0, 0, 0, 32, 0, 0, 0, 23, 0, 0, 0, 114, 0, 0, 0, 1, 0, - 0, 0, 4, 0, 0, 0, 15, 0, 0, 0, 115, 0, 0, 0, 1, 0, 0, 0, 80, 0, 0, 0, 17, 0, 0, 0, 135, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 18, 0, 0, 0, 135, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 19, 0, 0, 0, 135, - 0, 0, 0, 176, 0, 0, 0, 176, 0, 0, 0, 20, 0, 0, 0, 135, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 21, - 0, 0, 0, 135, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 109, 97, 110, 70, 73, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 118, 95, 116, 101, 120, 67, 111, 111, 114, 100, 0, 117, 95, 109, 111, 100, 117, 108, - 97, 116, 105, 111, 110, 0, 117, 95, 116, 101, 120, 116, 117, 114, 101, 0, 0, 0, 0, 0, 0, 0, - 2, 0, 0, 0, 0, 0, 0, 0, 220, 0, 0, 0, 0, 0, 0, 0, 11, 0, 0, 0, 82, 139, 0, 0, 1, 0, 0, 0, 1, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 24, 0, 0, 0, 94, 139, 0, 0, 1, 0, 0, 0, 1, 0, 0, - 0, 2, 0, 0, 0, 16, 0, 0, 0, 0, 0, 0, 0, 5, 48, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 1, 22, 22, 17, 241, 0, 0, 0, 240, 0, 0, 0, 240, 0, 0, 0, 240, 0, 0, 0, 240, 0, 0, 0, 240, - 0, 0, 0, 240, 0, 0, 0, 240, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 7, 0, 0, 0, 2, 0, 0, 0, 1, 0, - 0, 0, 2, 0, 0, 0, 21, 32, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 24, 0, 0, 0, 16, 0, 0, 0, 16, 0, 0, - 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 65, 82, 50, 48, 45, 66, 73, 78, 1, 0, 0, 0, 2, 0, 0, 0, 2, 0, 65, 37, 0, 0, 0, 0, 8, 0, - 129, 0, 1, 0, 0, 21, 0, 0, 0, 0, 2, 0, 1, 38, 1, 0, 0, 0, 0, 0, 0, 0, 2, 0, 4, 38, 186, 81, - 78, 16, 2, 1, 0, 0, 2, 0, 1, 39, 0, 4, 0, 0, 0, 0, 0, 0, 2, 0, 1, 40, 1, 0, 0, 0, 5, 0, 0, 0, - 16, 0, 4, 40, 40, 160, 1, 0, 0, 242, 1, 66, 104, 32, 1, 0, 0, 242, 1, 70, 8, 192, 1, 0, 0, 242, - 1, 64, 72, 64, 1, 0, 0, 242, 1, 68, 136, 192, 0, 0, 0, 26, 64, 4, 136, 32, 0, 0, 0, 2, 64, 7, - 136, 64, 0, 0, 0, 10, 64, 6, 136, 160, 0, 0, 0, 18, 64, 5, 2, 0, 6, 40, 0, 0, 0, 0, 0, 0, 0, - 0, 2, 0, 1, 41, 0, 0, 0, 0, 5, 0, 2, 0 -}; - -static const Uint8 GLES2_FragmentTegra_Modulated_TextureSrc_[] = { - 75, 132, 201, 227, 47, 109, 131, 38, 6, 0, 1, 0, 5, 0, 0, 0, 17, 0, 0, 0, 1, 0, 0, 0, 73, 0, - 0, 0, 34, 0, 0, 0, 36, 0, 0, 0, 2, 0, 0, 0, 82, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 0, 0, 0, - 82, 0, 0, 0, 1, 0, 0, 0, 20, 0, 0, 0, 6, 0, 0, 0, 87, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 0, - 0, 0, 87, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8, 0, 0, 0, 87, 0, 0, 0, 2, 0, 0, 0, 56, 0, 0, 0, - 13, 0, 0, 0, 101, 0, 0, 0, 4, 0, 0, 0, 16, 0, 0, 0, 14, 0, 0, 0, 105, 0, 0, 0, 1, 0, 0, 0, 4, - 0, 0, 0, 22, 0, 0, 0, 106, 0, 0, 0, 8, 0, 0, 0, 32, 0, 0, 0, 23, 0, 0, 0, 114, 0, 0, 0, 1, 0, - 0, 0, 4, 0, 0, 0, 15, 0, 0, 0, 115, 0, 0, 0, 1, 0, 0, 0, 80, 0, 0, 0, 17, 0, 0, 0, 135, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 18, 0, 0, 0, 135, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 19, 0, 0, 0, 135, - 0, 0, 0, 176, 0, 0, 0, 176, 0, 0, 0, 20, 0, 0, 0, 135, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 21, - 0, 0, 0, 135, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 109, 97, 110, 70, 73, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 118, 95, 116, 101, 120, 67, 111, 111, 114, 100, 0, 117, 95, 109, 111, 100, 117, 108, - 97, 116, 105, 111, 110, 0, 117, 95, 116, 101, 120, 116, 117, 114, 101, 0, 0, 0, 0, 0, 0, 0, - 2, 0, 0, 0, 0, 0, 0, 0, 220, 0, 0, 0, 0, 0, 0, 0, 11, 0, 0, 0, 82, 139, 0, 0, 1, 0, 0, 0, 1, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 24, 0, 0, 0, 94, 139, 0, 0, 1, 0, 0, 0, 1, 0, 0, - 0, 2, 0, 0, 0, 16, 0, 0, 0, 0, 0, 0, 0, 5, 48, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 1, 32, 32, 17, 241, 0, 0, 0, 240, 0, 0, 0, 240, 0, 0, 0, 240, 0, 0, 0, 240, 0, 0, 0, 240, - 0, 0, 0, 240, 0, 0, 0, 240, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 7, 0, 0, 0, 2, 0, 0, 0, 1, 0, - 0, 0, 2, 0, 0, 0, 21, 32, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 24, 0, 0, 0, 16, 0, 0, 0, 16, 0, 0, - 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 65, 82, 50, 48, 45, 66, 73, 78, 1, 0, 0, 0, 2, 0, 0, 0, 2, 0, 65, 37, 0, 0, 0, 0, 8, 0, - 129, 0, 1, 0, 0, 21, 0, 0, 0, 0, 2, 0, 1, 38, 1, 0, 0, 0, 0, 0, 0, 0, 2, 0, 4, 38, 186, 81, - 78, 16, 2, 1, 0, 0, 2, 0, 1, 39, 0, 4, 0, 0, 0, 0, 0, 0, 2, 0, 1, 40, 1, 0, 0, 0, 5, 0, 0, 0, - 16, 0, 4, 40, 40, 160, 1, 0, 0, 242, 1, 66, 8, 192, 1, 0, 0, 242, 1, 64, 104, 32, 1, 0, 0, 242, - 1, 70, 72, 64, 1, 0, 0, 242, 1, 68, 104, 192, 0, 0, 0, 242, 65, 4, 232, 32, 0, 0, 0, 242, 65, - 0, 40, 64, 0, 0, 0, 242, 65, 6, 72, 160, 0, 0, 0, 242, 65, 5, 2, 0, 6, 40, 0, 0, 0, 0, 0, 0, - 0, 0, 2, 0, 1, 41, 0, 0, 0, 0, 5, 0, 2, 0 -}; - -static const GLES2_ShaderInstance GLES2_VertexTegra_Default = { - GL_VERTEX_SHADER, - GL_NVIDIA_PLATFORM_BINARY_NV, - sizeof(GLES2_VertexTegra_Default_), - GLES2_VertexTegra_Default_ -}; - -static const GLES2_ShaderInstance GLES2_FragmentTegra_None_SolidSrc = { - GL_FRAGMENT_SHADER, - GL_NVIDIA_PLATFORM_BINARY_NV, - sizeof(GLES2_FragmentTegra_None_SolidSrc_), - GLES2_FragmentTegra_None_SolidSrc_ -}; - -static const GLES2_ShaderInstance GLES2_FragmentTegra_Alpha_SolidSrc = { - GL_FRAGMENT_SHADER, - GL_NVIDIA_PLATFORM_BINARY_NV, - sizeof(GLES2_FragmentTegra_Alpha_SolidSrc_), - GLES2_FragmentTegra_Alpha_SolidSrc_ -}; - -static const GLES2_ShaderInstance GLES2_FragmentTegra_Additive_SolidSrc = { - GL_FRAGMENT_SHADER, - GL_NVIDIA_PLATFORM_BINARY_NV, - sizeof(GLES2_FragmentTegra_Additive_SolidSrc_), - GLES2_FragmentTegra_Additive_SolidSrc_ -}; - -static const GLES2_ShaderInstance GLES2_FragmentTegra_Modulated_SolidSrc = { - GL_FRAGMENT_SHADER, - GL_NVIDIA_PLATFORM_BINARY_NV, - sizeof(GLES2_FragmentTegra_Modulated_SolidSrc_), - GLES2_FragmentTegra_Modulated_SolidSrc_ -}; - -static const GLES2_ShaderInstance GLES2_FragmentTegra_None_TextureSrc = { - GL_FRAGMENT_SHADER, - GL_NVIDIA_PLATFORM_BINARY_NV, - sizeof(GLES2_FragmentTegra_None_TextureSrc_), - GLES2_FragmentTegra_None_TextureSrc_ -}; - -static const GLES2_ShaderInstance GLES2_FragmentTegra_Alpha_TextureSrc = { - GL_FRAGMENT_SHADER, - GL_NVIDIA_PLATFORM_BINARY_NV, - sizeof(GLES2_FragmentTegra_Alpha_TextureSrc_), - GLES2_FragmentTegra_Alpha_TextureSrc_ -}; - -static const GLES2_ShaderInstance GLES2_FragmentTegra_Additive_TextureSrc = { - GL_FRAGMENT_SHADER, - GL_NVIDIA_PLATFORM_BINARY_NV, - sizeof(GLES2_FragmentTegra_Additive_TextureSrc_), - GLES2_FragmentTegra_Additive_TextureSrc_ -}; - -static const GLES2_ShaderInstance GLES2_FragmentTegra_Modulated_TextureSrc = { - GL_FRAGMENT_SHADER, - GL_NVIDIA_PLATFORM_BINARY_NV, - sizeof(GLES2_FragmentTegra_Modulated_TextureSrc_), - GLES2_FragmentTegra_Modulated_TextureSrc_ -}; - -#endif /* GLES2_INCLUDE_NVIDIA_SHADERS */ - -/************************************************************************************************* - * Vertex/fragment shader definitions * - *************************************************************************************************/ - -static GLES2_Shader GLES2_VertexShader_Default = { -#if GLES2_INCLUDE_NVIDIA_SHADERS - 2, -#else - 1, -#endif - { -#if GLES2_INCLUDE_NVIDIA_SHADERS - &GLES2_VertexTegra_Default, -#endif - &GLES2_VertexSrc_Default - } -}; - -static GLES2_Shader GLES2_FragmentShader_None_SolidSrc = { -#if GLES2_INCLUDE_NVIDIA_SHADERS - 2, -#else - 1, -#endif - { -#if GLES2_INCLUDE_NVIDIA_SHADERS - &GLES2_FragmentTegra_None_SolidSrc, -#endif - &GLES2_FragmentSrc_SolidSrc - } -}; - -static GLES2_Shader GLES2_FragmentShader_Alpha_SolidSrc = { -#if GLES2_INCLUDE_NVIDIA_SHADERS - 2, -#else - 1, -#endif - { -#if GLES2_INCLUDE_NVIDIA_SHADERS - &GLES2_FragmentTegra_Alpha_SolidSrc, -#endif - &GLES2_FragmentSrc_SolidSrc - } -}; - -static GLES2_Shader GLES2_FragmentShader_Additive_SolidSrc = { -#if GLES2_INCLUDE_NVIDIA_SHADERS - 2, -#else - 1, -#endif - { -#if GLES2_INCLUDE_NVIDIA_SHADERS - &GLES2_FragmentTegra_Additive_SolidSrc, -#endif - &GLES2_FragmentSrc_SolidSrc - } -}; - -static GLES2_Shader GLES2_FragmentShader_Modulated_SolidSrc = { -#if GLES2_INCLUDE_NVIDIA_SHADERS - 2, -#else - 1, -#endif - { -#if GLES2_INCLUDE_NVIDIA_SHADERS - &GLES2_FragmentTegra_Modulated_SolidSrc, -#endif - &GLES2_FragmentSrc_SolidSrc - } -}; - -static GLES2_Shader GLES2_FragmentShader_None_TextureABGRSrc = { -#if GLES2_INCLUDE_NVIDIA_SHADERS - 2, -#else - 1, -#endif - { -#if GLES2_INCLUDE_NVIDIA_SHADERS - &GLES2_FragmentTegra_None_TextureSrc, -#endif - &GLES2_FragmentSrc_TextureABGRSrc - } -}; - -static GLES2_Shader GLES2_FragmentShader_Alpha_TextureABGRSrc = { -#if GLES2_INCLUDE_NVIDIA_SHADERS - 2, -#else - 1, -#endif - { -#if GLES2_INCLUDE_NVIDIA_SHADERS - &GLES2_FragmentTegra_Alpha_TextureSrc, -#endif - &GLES2_FragmentSrc_TextureABGRSrc - } -}; - -static GLES2_Shader GLES2_FragmentShader_Additive_TextureABGRSrc = { -#if GLES2_INCLUDE_NVIDIA_SHADERS - 2, -#else - 1, -#endif - { -#if GLES2_INCLUDE_NVIDIA_SHADERS - &GLES2_FragmentTegra_Additive_TextureSrc, -#endif - &GLES2_FragmentSrc_TextureABGRSrc - } -}; - -static GLES2_Shader GLES2_FragmentShader_Modulated_TextureABGRSrc = { -#if GLES2_INCLUDE_NVIDIA_SHADERS - 2, -#else - 1, -#endif - { -#if GLES2_INCLUDE_NVIDIA_SHADERS - &GLES2_FragmentTegra_Modulated_TextureSrc, -#endif - &GLES2_FragmentSrc_TextureABGRSrc - } -}; - -static GLES2_Shader GLES2_FragmentShader_None_TextureARGBSrc = { - 1, - { - &GLES2_FragmentSrc_TextureARGBSrc - } -}; - -static GLES2_Shader GLES2_FragmentShader_Alpha_TextureARGBSrc = { - 1, - { - &GLES2_FragmentSrc_TextureARGBSrc - } -}; - -static GLES2_Shader GLES2_FragmentShader_Additive_TextureARGBSrc = { - 1, - { - &GLES2_FragmentSrc_TextureARGBSrc - } -}; - -static GLES2_Shader GLES2_FragmentShader_Modulated_TextureARGBSrc = { - 1, - { - &GLES2_FragmentSrc_TextureARGBSrc - } -}; - -static GLES2_Shader GLES2_FragmentShader_None_TextureRGBSrc = { - 1, - { - &GLES2_FragmentSrc_TextureRGBSrc - } -}; - -static GLES2_Shader GLES2_FragmentShader_Alpha_TextureRGBSrc = { - 1, - { - &GLES2_FragmentSrc_TextureRGBSrc - } -}; - -static GLES2_Shader GLES2_FragmentShader_Additive_TextureRGBSrc = { - 1, - { - &GLES2_FragmentSrc_TextureRGBSrc - } -}; - -static GLES2_Shader GLES2_FragmentShader_Modulated_TextureRGBSrc = { - 1, - { - &GLES2_FragmentSrc_TextureRGBSrc - } -}; - -static GLES2_Shader GLES2_FragmentShader_None_TextureBGRSrc = { - 1, - { - &GLES2_FragmentSrc_TextureBGRSrc - } -}; - -static GLES2_Shader GLES2_FragmentShader_Alpha_TextureBGRSrc = { - 1, - { - &GLES2_FragmentSrc_TextureBGRSrc - } -}; - -static GLES2_Shader GLES2_FragmentShader_Additive_TextureBGRSrc = { - 1, - { - &GLES2_FragmentSrc_TextureBGRSrc - } -}; - -static GLES2_Shader GLES2_FragmentShader_Modulated_TextureBGRSrc = { - 1, - { - &GLES2_FragmentSrc_TextureBGRSrc - } -}; - -/************************************************************************************************* - * Shader selector * - *************************************************************************************************/ - -const GLES2_Shader *GLES2_GetShader(GLES2_ShaderType type, SDL_BlendMode blendMode) -{ - switch (type) - { - case GLES2_SHADER_VERTEX_DEFAULT: - return &GLES2_VertexShader_Default; - case GLES2_SHADER_FRAGMENT_SOLID_SRC: - switch (blendMode) - { - case SDL_BLENDMODE_NONE: - return &GLES2_FragmentShader_None_SolidSrc; - case SDL_BLENDMODE_BLEND: - return &GLES2_FragmentShader_Alpha_SolidSrc; - case SDL_BLENDMODE_ADD: - return &GLES2_FragmentShader_Additive_SolidSrc; - case SDL_BLENDMODE_MOD: - return &GLES2_FragmentShader_Modulated_SolidSrc; - default: - return NULL; - } - case GLES2_SHADER_FRAGMENT_TEXTURE_ABGR_SRC: - switch (blendMode) - { - case SDL_BLENDMODE_NONE: - return &GLES2_FragmentShader_None_TextureABGRSrc; - case SDL_BLENDMODE_BLEND: - return &GLES2_FragmentShader_Alpha_TextureABGRSrc; - case SDL_BLENDMODE_ADD: - return &GLES2_FragmentShader_Additive_TextureABGRSrc; - case SDL_BLENDMODE_MOD: - return &GLES2_FragmentShader_Modulated_TextureABGRSrc; - default: - return NULL; - } - case GLES2_SHADER_FRAGMENT_TEXTURE_ARGB_SRC: - switch (blendMode) - { - case SDL_BLENDMODE_NONE: - return &GLES2_FragmentShader_None_TextureARGBSrc; - case SDL_BLENDMODE_BLEND: - return &GLES2_FragmentShader_Alpha_TextureARGBSrc; - case SDL_BLENDMODE_ADD: - return &GLES2_FragmentShader_Additive_TextureARGBSrc; - case SDL_BLENDMODE_MOD: - return &GLES2_FragmentShader_Modulated_TextureARGBSrc; - default: - return NULL; - } - - case GLES2_SHADER_FRAGMENT_TEXTURE_RGB_SRC: - switch (blendMode) - { - case SDL_BLENDMODE_NONE: - return &GLES2_FragmentShader_None_TextureRGBSrc; - case SDL_BLENDMODE_BLEND: - return &GLES2_FragmentShader_Alpha_TextureRGBSrc; - case SDL_BLENDMODE_ADD: - return &GLES2_FragmentShader_Additive_TextureRGBSrc; - case SDL_BLENDMODE_MOD: - return &GLES2_FragmentShader_Modulated_TextureRGBSrc; - default: - return NULL; - } - - case GLES2_SHADER_FRAGMENT_TEXTURE_BGR_SRC: - switch (blendMode) - { - case SDL_BLENDMODE_NONE: - return &GLES2_FragmentShader_None_TextureBGRSrc; - case SDL_BLENDMODE_BLEND: - return &GLES2_FragmentShader_Alpha_TextureBGRSrc; - case SDL_BLENDMODE_ADD: - return &GLES2_FragmentShader_Additive_TextureBGRSrc; - case SDL_BLENDMODE_MOD: - return &GLES2_FragmentShader_Modulated_TextureBGRSrc; - default: - return NULL; - } - - default: - return NULL; - } -} - -#endif /* SDL_VIDEO_RENDER_OGL_ES2 && !SDL_RENDER_DISABLED */ - -/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/SDL-mobile/src/render/opengles2/SDL_shaders_gles2.h b/src/SDL-mobile/src/render/opengles2/SDL_shaders_gles2.h deleted file mode 100644 index 53da41a54..000000000 --- a/src/SDL-mobile/src/render/opengles2/SDL_shaders_gles2.h +++ /dev/null @@ -1,60 +0,0 @@ -/* - Simple DirectMedia Layer - Copyright (C) 1997-2012 Sam Lantinga - - 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_OGL_ES2 - -#ifndef SDL_shaderdata_h_ -#define SDL_shaderdata_h_ - -typedef struct GLES2_ShaderInstance -{ - GLenum type; - GLenum format; - int length; - const void *data; -} GLES2_ShaderInstance; - -typedef struct GLES2_Shader -{ - int instance_count; - const GLES2_ShaderInstance *instances[4]; -} GLES2_Shader; - -typedef enum -{ - GLES2_SHADER_VERTEX_DEFAULT, - GLES2_SHADER_FRAGMENT_SOLID_SRC, - GLES2_SHADER_FRAGMENT_TEXTURE_ABGR_SRC, - GLES2_SHADER_FRAGMENT_TEXTURE_ARGB_SRC, - GLES2_SHADER_FRAGMENT_TEXTURE_BGR_SRC, - GLES2_SHADER_FRAGMENT_TEXTURE_RGB_SRC -} GLES2_ShaderType; - -#define GLES2_SOURCE_SHADER (GLenum)-1 - -const GLES2_Shader *GLES2_GetShader(GLES2_ShaderType type, SDL_BlendMode blendMode); - -#endif /* SDL_shaderdata_h_ */ - -#endif /* SDL_VIDEO_RENDER_OGL_ES2 */ - -/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/SDL-mobile/src/render/software/SDL_blendfillrect.c b/src/SDL-mobile/src/render/software/SDL_blendfillrect.c deleted file mode 100644 index 5b399d1f1..000000000 --- a/src/SDL-mobile/src/render/software/SDL_blendfillrect.c +++ /dev/null @@ -1,342 +0,0 @@ -/* - Simple DirectMedia Layer - Copyright (C) 1997-2012 Sam Lantinga - - 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_RENDER_DISABLED - -#include "SDL_draw.h" -#include "SDL_blendfillrect.h" - - -static int -SDL_BlendFillRect_RGB555(SDL_Surface * dst, const SDL_Rect * rect, - SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a) -{ - unsigned inva = 0xff - a; - - switch (blendMode) { - case SDL_BLENDMODE_BLEND: - FILLRECT(Uint16, DRAW_SETPIXEL_BLEND_RGB555); - break; - case SDL_BLENDMODE_ADD: - FILLRECT(Uint16, DRAW_SETPIXEL_ADD_RGB555); - break; - case SDL_BLENDMODE_MOD: - FILLRECT(Uint16, DRAW_SETPIXEL_MOD_RGB555); - break; - default: - FILLRECT(Uint16, DRAW_SETPIXEL_RGB555); - break; - } - return 0; -} - -static int -SDL_BlendFillRect_RGB565(SDL_Surface * dst, const SDL_Rect * rect, - SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a) -{ - unsigned inva = 0xff - a; - - switch (blendMode) { - case SDL_BLENDMODE_BLEND: - FILLRECT(Uint16, DRAW_SETPIXEL_BLEND_RGB565); - break; - case SDL_BLENDMODE_ADD: - FILLRECT(Uint16, DRAW_SETPIXEL_ADD_RGB565); - break; - case SDL_BLENDMODE_MOD: - FILLRECT(Uint16, DRAW_SETPIXEL_MOD_RGB565); - break; - default: - FILLRECT(Uint16, DRAW_SETPIXEL_RGB565); - break; - } - return 0; -} - -static int -SDL_BlendFillRect_RGB888(SDL_Surface * dst, const SDL_Rect * rect, - SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a) -{ - unsigned inva = 0xff - a; - - switch (blendMode) { - case SDL_BLENDMODE_BLEND: - FILLRECT(Uint32, DRAW_SETPIXEL_BLEND_RGB888); - break; - case SDL_BLENDMODE_ADD: - FILLRECT(Uint32, DRAW_SETPIXEL_ADD_RGB888); - break; - case SDL_BLENDMODE_MOD: - FILLRECT(Uint32, DRAW_SETPIXEL_MOD_RGB888); - break; - default: - FILLRECT(Uint32, DRAW_SETPIXEL_RGB888); - break; - } - return 0; -} - -static int -SDL_BlendFillRect_ARGB8888(SDL_Surface * dst, const SDL_Rect * rect, - SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a) -{ - unsigned inva = 0xff - a; - - switch (blendMode) { - case SDL_BLENDMODE_BLEND: - FILLRECT(Uint32, DRAW_SETPIXEL_BLEND_ARGB8888); - break; - case SDL_BLENDMODE_ADD: - FILLRECT(Uint32, DRAW_SETPIXEL_ADD_ARGB8888); - break; - case SDL_BLENDMODE_MOD: - FILLRECT(Uint32, DRAW_SETPIXEL_MOD_ARGB8888); - break; - default: - FILLRECT(Uint32, DRAW_SETPIXEL_ARGB8888); - break; - } - return 0; -} - -static int -SDL_BlendFillRect_RGB(SDL_Surface * dst, const SDL_Rect * rect, - SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a) -{ - SDL_PixelFormat *fmt = dst->format; - unsigned inva = 0xff - a; - - switch (fmt->BytesPerPixel) { - case 2: - switch (blendMode) { - case SDL_BLENDMODE_BLEND: - FILLRECT(Uint16, DRAW_SETPIXEL_BLEND_RGB); - break; - case SDL_BLENDMODE_ADD: - FILLRECT(Uint16, DRAW_SETPIXEL_ADD_RGB); - break; - case SDL_BLENDMODE_MOD: - FILLRECT(Uint16, DRAW_SETPIXEL_MOD_RGB); - break; - default: - FILLRECT(Uint16, DRAW_SETPIXEL_RGB); - break; - } - return 0; - case 4: - switch (blendMode) { - case SDL_BLENDMODE_BLEND: - FILLRECT(Uint32, DRAW_SETPIXEL_BLEND_RGB); - break; - case SDL_BLENDMODE_ADD: - FILLRECT(Uint32, DRAW_SETPIXEL_ADD_RGB); - break; - case SDL_BLENDMODE_MOD: - FILLRECT(Uint32, DRAW_SETPIXEL_MOD_RGB); - break; - default: - FILLRECT(Uint32, DRAW_SETPIXEL_RGB); - break; - } - return 0; - default: - SDL_Unsupported(); - return -1; - } -} - -static int -SDL_BlendFillRect_RGBA(SDL_Surface * dst, const SDL_Rect * rect, - SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a) -{ - SDL_PixelFormat *fmt = dst->format; - unsigned inva = 0xff - a; - - switch (fmt->BytesPerPixel) { - case 4: - switch (blendMode) { - case SDL_BLENDMODE_BLEND: - FILLRECT(Uint32, DRAW_SETPIXEL_BLEND_RGBA); - break; - case SDL_BLENDMODE_ADD: - FILLRECT(Uint32, DRAW_SETPIXEL_ADD_RGBA); - break; - case SDL_BLENDMODE_MOD: - FILLRECT(Uint32, DRAW_SETPIXEL_MOD_RGBA); - break; - default: - FILLRECT(Uint32, DRAW_SETPIXEL_RGBA); - break; - } - return 0; - default: - SDL_Unsupported(); - return -1; - } -} - -int -SDL_BlendFillRect(SDL_Surface * dst, const SDL_Rect * rect, - SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a) -{ - SDL_Rect clipped; - - if (!dst) { - SDL_SetError("Passed NULL destination surface"); - return -1; - } - - /* This function doesn't work on surfaces < 8 bpp */ - if (dst->format->BitsPerPixel < 8) { - SDL_SetError("SDL_BlendFillRect(): Unsupported surface format"); - return -1; - } - - /* If 'rect' == NULL, then fill the whole surface */ - if (rect) { - /* Perform clipping */ - if (!SDL_IntersectRect(rect, &dst->clip_rect, &clipped)) { - return 0; - } - rect = &clipped; - } else { - rect = &dst->clip_rect; - } - - if (blendMode == SDL_BLENDMODE_BLEND || blendMode == SDL_BLENDMODE_ADD) { - r = DRAW_MUL(r, a); - g = DRAW_MUL(g, a); - b = DRAW_MUL(b, a); - } - - switch (dst->format->BitsPerPixel) { - case 15: - switch (dst->format->Rmask) { - case 0x7C00: - return SDL_BlendFillRect_RGB555(dst, rect, blendMode, r, g, b, a); - } - break; - case 16: - switch (dst->format->Rmask) { - case 0xF800: - return SDL_BlendFillRect_RGB565(dst, rect, blendMode, r, g, b, a); - } - break; - case 32: - switch (dst->format->Rmask) { - case 0x00FF0000: - if (!dst->format->Amask) { - return SDL_BlendFillRect_RGB888(dst, rect, blendMode, r, g, b, a); - } else { - return SDL_BlendFillRect_ARGB8888(dst, rect, blendMode, r, g, b, a); - } - break; - } - break; - default: - break; - } - - if (!dst->format->Amask) { - return SDL_BlendFillRect_RGB(dst, rect, blendMode, r, g, b, a); - } else { - return SDL_BlendFillRect_RGBA(dst, rect, blendMode, r, g, b, a); - } -} - -int -SDL_BlendFillRects(SDL_Surface * dst, const SDL_Rect * rects, int count, - SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a) -{ - SDL_Rect rect; - int i; - int (*func)(SDL_Surface * dst, const SDL_Rect * rect, - SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a) = NULL; - int status = 0; - - if (!dst) { - SDL_SetError("Passed NULL destination surface"); - return -1; - } - - /* This function doesn't work on surfaces < 8 bpp */ - if (dst->format->BitsPerPixel < 8) { - SDL_SetError("SDL_BlendFillRects(): Unsupported surface format"); - return -1; - } - - if (blendMode == SDL_BLENDMODE_BLEND || blendMode == SDL_BLENDMODE_ADD) { - r = DRAW_MUL(r, a); - g = DRAW_MUL(g, a); - b = DRAW_MUL(b, a); - } - - /* FIXME: Does this function pointer slow things down significantly? */ - switch (dst->format->BitsPerPixel) { - case 15: - switch (dst->format->Rmask) { - case 0x7C00: - func = SDL_BlendFillRect_RGB555; - } - break; - case 16: - switch (dst->format->Rmask) { - case 0xF800: - func = SDL_BlendFillRect_RGB565; - } - break; - case 32: - switch (dst->format->Rmask) { - case 0x00FF0000: - if (!dst->format->Amask) { - func = SDL_BlendFillRect_RGB888; - } else { - func = SDL_BlendFillRect_ARGB8888; - } - break; - } - break; - default: - break; - } - - if (!func) { - if (!dst->format->Amask) { - func = SDL_BlendFillRect_RGB; - } else { - func = SDL_BlendFillRect_RGBA; - } - } - - for (i = 0; i < count; ++i) { - /* Perform clipping */ - if (!SDL_IntersectRect(&rects[i], &dst->clip_rect, &rect)) { - continue; - } - status = func(dst, &rect, blendMode, r, g, b, a); - } - return status; -} - -#endif /* !SDL_RENDER_DISABLED */ - -/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/SDL-mobile/src/render/software/SDL_blendfillrect.h b/src/SDL-mobile/src/render/software/SDL_blendfillrect.h deleted file mode 100644 index 6ea88b56a..000000000 --- a/src/SDL-mobile/src/render/software/SDL_blendfillrect.h +++ /dev/null @@ -1,27 +0,0 @@ -/* - Simple DirectMedia Layer - Copyright (C) 1997-2012 Sam Lantinga - - 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" - - -extern int SDL_BlendFillRect(SDL_Surface * dst, const SDL_Rect * rect, SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a); -extern int SDL_BlendFillRects(SDL_Surface * dst, const SDL_Rect * rects, int count, SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a); - -/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/SDL-mobile/src/render/software/SDL_blendline.c b/src/SDL-mobile/src/render/software/SDL_blendline.c deleted file mode 100644 index 3f73a64b6..000000000 --- a/src/SDL-mobile/src/render/software/SDL_blendline.c +++ /dev/null @@ -1,781 +0,0 @@ -/* - Simple DirectMedia Layer - Copyright (C) 1997-2012 Sam Lantinga - - 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_RENDER_DISABLED - -#include "SDL_draw.h" -#include "SDL_blendline.h" -#include "SDL_blendpoint.h" - - -static void -SDL_BlendLine_RGB2(SDL_Surface * dst, int x1, int y1, int x2, int y2, - SDL_BlendMode blendMode, Uint8 _r, Uint8 _g, Uint8 _b, Uint8 _a, - SDL_bool draw_end) -{ - const SDL_PixelFormat *fmt = dst->format; - unsigned r, g, b, a, inva; - - if (blendMode == SDL_BLENDMODE_BLEND || blendMode == SDL_BLENDMODE_ADD) { - r = DRAW_MUL(_r, _a); - g = DRAW_MUL(_g, _a); - b = DRAW_MUL(_b, _a); - a = _a; - } else { - r = _r; - g = _g; - b = _b; - a = _a; - } - inva = (a ^ 0xff); - - if (y1 == y2) { - switch (blendMode) { - case SDL_BLENDMODE_BLEND: - HLINE(Uint16, DRAW_SETPIXEL_BLEND_RGB, draw_end); - break; - case SDL_BLENDMODE_ADD: - HLINE(Uint16, DRAW_SETPIXEL_ADD_RGB, draw_end); - break; - case SDL_BLENDMODE_MOD: - HLINE(Uint16, DRAW_SETPIXEL_MOD_RGB, draw_end); - break; - default: - HLINE(Uint16, DRAW_SETPIXEL_RGB, draw_end); - break; - } - } else if (x1 == x2) { - switch (blendMode) { - case SDL_BLENDMODE_BLEND: - VLINE(Uint16, DRAW_SETPIXEL_BLEND_RGB, draw_end); - break; - case SDL_BLENDMODE_ADD: - VLINE(Uint16, DRAW_SETPIXEL_ADD_RGB, draw_end); - break; - case SDL_BLENDMODE_MOD: - VLINE(Uint16, DRAW_SETPIXEL_MOD_RGB, draw_end); - break; - default: - VLINE(Uint16, DRAW_SETPIXEL_RGB, draw_end); - break; - } - } else if (ABS(x1 - x2) == ABS(y1 - y2)) { - switch (blendMode) { - case SDL_BLENDMODE_BLEND: - DLINE(Uint16, DRAW_SETPIXEL_BLEND_RGB, draw_end); - break; - case SDL_BLENDMODE_ADD: - DLINE(Uint16, DRAW_SETPIXEL_ADD_RGB, draw_end); - break; - case SDL_BLENDMODE_MOD: - DLINE(Uint16, DRAW_SETPIXEL_MOD_RGB, draw_end); - break; - default: - DLINE(Uint16, DRAW_SETPIXEL_RGB, draw_end); - break; - } - } else { - switch (blendMode) { - case SDL_BLENDMODE_BLEND: - AALINE(x1, y1, x2, y2, - DRAW_SETPIXELXY2_BLEND_RGB, DRAW_SETPIXELXY2_BLEND_RGB, - draw_end); - break; - case SDL_BLENDMODE_ADD: - AALINE(x1, y1, x2, y2, - DRAW_SETPIXELXY2_ADD_RGB, DRAW_SETPIXELXY2_ADD_RGB, - draw_end); - break; - case SDL_BLENDMODE_MOD: - AALINE(x1, y1, x2, y2, - DRAW_SETPIXELXY2_MOD_RGB, DRAW_SETPIXELXY2_MOD_RGB, - draw_end); - break; - default: - AALINE(x1, y1, x2, y2, - DRAW_SETPIXELXY2_RGB, DRAW_SETPIXELXY2_BLEND_RGB, - draw_end); - break; - } - } -} - -static void -SDL_BlendLine_RGB555(SDL_Surface * dst, int x1, int y1, int x2, int y2, - SDL_BlendMode blendMode, Uint8 _r, Uint8 _g, Uint8 _b, Uint8 _a, - SDL_bool draw_end) -{ - unsigned r, g, b, a, inva; - - if (blendMode == SDL_BLENDMODE_BLEND || blendMode == SDL_BLENDMODE_ADD) { - r = DRAW_MUL(_r, _a); - g = DRAW_MUL(_g, _a); - b = DRAW_MUL(_b, _a); - a = _a; - } else { - r = _r; - g = _g; - b = _b; - a = _a; - } - inva = (a ^ 0xff); - - if (y1 == y2) { - switch (blendMode) { - case SDL_BLENDMODE_BLEND: - HLINE(Uint16, DRAW_SETPIXEL_BLEND_RGB555, draw_end); - break; - case SDL_BLENDMODE_ADD: - HLINE(Uint16, DRAW_SETPIXEL_ADD_RGB555, draw_end); - break; - case SDL_BLENDMODE_MOD: - HLINE(Uint16, DRAW_SETPIXEL_MOD_RGB555, draw_end); - break; - default: - HLINE(Uint16, DRAW_SETPIXEL_RGB555, draw_end); - break; - } - } else if (x1 == x2) { - switch (blendMode) { - case SDL_BLENDMODE_BLEND: - VLINE(Uint16, DRAW_SETPIXEL_BLEND_RGB555, draw_end); - break; - case SDL_BLENDMODE_ADD: - VLINE(Uint16, DRAW_SETPIXEL_ADD_RGB555, draw_end); - break; - case SDL_BLENDMODE_MOD: - VLINE(Uint16, DRAW_SETPIXEL_MOD_RGB555, draw_end); - break; - default: - VLINE(Uint16, DRAW_SETPIXEL_RGB555, draw_end); - break; - } - } else if (ABS(x1 - x2) == ABS(y1 - y2)) { - switch (blendMode) { - case SDL_BLENDMODE_BLEND: - DLINE(Uint16, DRAW_SETPIXEL_BLEND_RGB555, draw_end); - break; - case SDL_BLENDMODE_ADD: - DLINE(Uint16, DRAW_SETPIXEL_ADD_RGB555, draw_end); - break; - case SDL_BLENDMODE_MOD: - DLINE(Uint16, DRAW_SETPIXEL_MOD_RGB555, draw_end); - break; - default: - DLINE(Uint16, DRAW_SETPIXEL_RGB555, draw_end); - break; - } - } else { - switch (blendMode) { - case SDL_BLENDMODE_BLEND: - AALINE(x1, y1, x2, y2, - DRAW_SETPIXELXY_BLEND_RGB555, DRAW_SETPIXELXY_BLEND_RGB555, - draw_end); - break; - case SDL_BLENDMODE_ADD: - AALINE(x1, y1, x2, y2, - DRAW_SETPIXELXY_ADD_RGB555, DRAW_SETPIXELXY_ADD_RGB555, - draw_end); - break; - case SDL_BLENDMODE_MOD: - AALINE(x1, y1, x2, y2, - DRAW_SETPIXELXY_MOD_RGB555, DRAW_SETPIXELXY_MOD_RGB555, - draw_end); - break; - default: - AALINE(x1, y1, x2, y2, - DRAW_SETPIXELXY_RGB555, DRAW_SETPIXELXY_BLEND_RGB555, - draw_end); - break; - } - } -} - -static void -SDL_BlendLine_RGB565(SDL_Surface * dst, int x1, int y1, int x2, int y2, - SDL_BlendMode blendMode, Uint8 _r, Uint8 _g, Uint8 _b, Uint8 _a, - SDL_bool draw_end) -{ - unsigned r, g, b, a, inva; - - if (blendMode == SDL_BLENDMODE_BLEND || blendMode == SDL_BLENDMODE_ADD) { - r = DRAW_MUL(_r, _a); - g = DRAW_MUL(_g, _a); - b = DRAW_MUL(_b, _a); - a = _a; - } else { - r = _r; - g = _g; - b = _b; - a = _a; - } - inva = (a ^ 0xff); - - if (y1 == y2) { - switch (blendMode) { - case SDL_BLENDMODE_BLEND: - HLINE(Uint16, DRAW_SETPIXEL_BLEND_RGB565, draw_end); - break; - case SDL_BLENDMODE_ADD: - HLINE(Uint16, DRAW_SETPIXEL_ADD_RGB565, draw_end); - break; - case SDL_BLENDMODE_MOD: - HLINE(Uint16, DRAW_SETPIXEL_MOD_RGB565, draw_end); - break; - default: - HLINE(Uint16, DRAW_SETPIXEL_RGB565, draw_end); - break; - } - } else if (x1 == x2) { - switch (blendMode) { - case SDL_BLENDMODE_BLEND: - VLINE(Uint16, DRAW_SETPIXEL_BLEND_RGB565, draw_end); - break; - case SDL_BLENDMODE_ADD: - VLINE(Uint16, DRAW_SETPIXEL_ADD_RGB565, draw_end); - break; - case SDL_BLENDMODE_MOD: - VLINE(Uint16, DRAW_SETPIXEL_MOD_RGB565, draw_end); - break; - default: - VLINE(Uint16, DRAW_SETPIXEL_RGB565, draw_end); - break; - } - } else if (ABS(x1 - x2) == ABS(y1 - y2)) { - switch (blendMode) { - case SDL_BLENDMODE_BLEND: - DLINE(Uint16, DRAW_SETPIXEL_BLEND_RGB565, draw_end); - break; - case SDL_BLENDMODE_ADD: - DLINE(Uint16, DRAW_SETPIXEL_ADD_RGB565, draw_end); - break; - case SDL_BLENDMODE_MOD: - DLINE(Uint16, DRAW_SETPIXEL_MOD_RGB565, draw_end); - break; - default: - DLINE(Uint16, DRAW_SETPIXEL_RGB565, draw_end); - break; - } - } else { - switch (blendMode) { - case SDL_BLENDMODE_BLEND: - AALINE(x1, y1, x2, y2, - DRAW_SETPIXELXY_BLEND_RGB565, DRAW_SETPIXELXY_BLEND_RGB565, - draw_end); - break; - case SDL_BLENDMODE_ADD: - AALINE(x1, y1, x2, y2, - DRAW_SETPIXELXY_ADD_RGB565, DRAW_SETPIXELXY_ADD_RGB565, - draw_end); - break; - case SDL_BLENDMODE_MOD: - AALINE(x1, y1, x2, y2, - DRAW_SETPIXELXY_MOD_RGB565, DRAW_SETPIXELXY_MOD_RGB565, - draw_end); - break; - default: - AALINE(x1, y1, x2, y2, - DRAW_SETPIXELXY_RGB565, DRAW_SETPIXELXY_BLEND_RGB565, - draw_end); - break; - } - } -} - -static void -SDL_BlendLine_RGB4(SDL_Surface * dst, int x1, int y1, int x2, int y2, - SDL_BlendMode blendMode, Uint8 _r, Uint8 _g, Uint8 _b, Uint8 _a, - SDL_bool draw_end) -{ - const SDL_PixelFormat *fmt = dst->format; - unsigned r, g, b, a, inva; - - if (blendMode == SDL_BLENDMODE_BLEND || blendMode == SDL_BLENDMODE_ADD) { - r = DRAW_MUL(_r, _a); - g = DRAW_MUL(_g, _a); - b = DRAW_MUL(_b, _a); - a = _a; - } else { - r = _r; - g = _g; - b = _b; - a = _a; - } - inva = (a ^ 0xff); - - if (y1 == y2) { - switch (blendMode) { - case SDL_BLENDMODE_BLEND: - HLINE(Uint32, DRAW_SETPIXEL_BLEND_RGB, draw_end); - break; - case SDL_BLENDMODE_ADD: - HLINE(Uint32, DRAW_SETPIXEL_ADD_RGB, draw_end); - break; - case SDL_BLENDMODE_MOD: - HLINE(Uint32, DRAW_SETPIXEL_MOD_RGB, draw_end); - break; - default: - HLINE(Uint32, DRAW_SETPIXEL_RGB, draw_end); - break; - } - } else if (x1 == x2) { - switch (blendMode) { - case SDL_BLENDMODE_BLEND: - VLINE(Uint32, DRAW_SETPIXEL_BLEND_RGB, draw_end); - break; - case SDL_BLENDMODE_ADD: - VLINE(Uint32, DRAW_SETPIXEL_ADD_RGB, draw_end); - break; - case SDL_BLENDMODE_MOD: - VLINE(Uint32, DRAW_SETPIXEL_MOD_RGB, draw_end); - break; - default: - VLINE(Uint32, DRAW_SETPIXEL_RGB, draw_end); - break; - } - } else if (ABS(x1 - x2) == ABS(y1 - y2)) { - switch (blendMode) { - case SDL_BLENDMODE_BLEND: - DLINE(Uint32, DRAW_SETPIXEL_BLEND_RGB, draw_end); - break; - case SDL_BLENDMODE_ADD: - DLINE(Uint32, DRAW_SETPIXEL_ADD_RGB, draw_end); - break; - case SDL_BLENDMODE_MOD: - DLINE(Uint32, DRAW_SETPIXEL_MOD_RGB, draw_end); - break; - default: - DLINE(Uint32, DRAW_SETPIXEL_RGB, draw_end); - break; - } - } else { - switch (blendMode) { - case SDL_BLENDMODE_BLEND: - AALINE(x1, y1, x2, y2, - DRAW_SETPIXELXY4_BLEND_RGB, DRAW_SETPIXELXY4_BLEND_RGB, - draw_end); - break; - case SDL_BLENDMODE_ADD: - AALINE(x1, y1, x2, y2, - DRAW_SETPIXELXY4_ADD_RGB, DRAW_SETPIXELXY4_ADD_RGB, - draw_end); - break; - case SDL_BLENDMODE_MOD: - AALINE(x1, y1, x2, y2, - DRAW_SETPIXELXY4_MOD_RGB, DRAW_SETPIXELXY4_MOD_RGB, - draw_end); - break; - default: - AALINE(x1, y1, x2, y2, - DRAW_SETPIXELXY4_RGB, DRAW_SETPIXELXY4_BLEND_RGB, - draw_end); - break; - } - } -} - -static void -SDL_BlendLine_RGBA4(SDL_Surface * dst, int x1, int y1, int x2, int y2, - SDL_BlendMode blendMode, Uint8 _r, Uint8 _g, Uint8 _b, Uint8 _a, - SDL_bool draw_end) -{ - const SDL_PixelFormat *fmt = dst->format; - unsigned r, g, b, a, inva; - - if (blendMode == SDL_BLENDMODE_BLEND || blendMode == SDL_BLENDMODE_ADD) { - r = DRAW_MUL(_r, _a); - g = DRAW_MUL(_g, _a); - b = DRAW_MUL(_b, _a); - a = _a; - } else { - r = _r; - g = _g; - b = _b; - a = _a; - } - inva = (a ^ 0xff); - - if (y1 == y2) { - switch (blendMode) { - case SDL_BLENDMODE_BLEND: - HLINE(Uint32, DRAW_SETPIXEL_BLEND_RGBA, draw_end); - break; - case SDL_BLENDMODE_ADD: - HLINE(Uint32, DRAW_SETPIXEL_ADD_RGBA, draw_end); - break; - case SDL_BLENDMODE_MOD: - HLINE(Uint32, DRAW_SETPIXEL_MOD_RGBA, draw_end); - break; - default: - HLINE(Uint32, DRAW_SETPIXEL_RGBA, draw_end); - break; - } - } else if (x1 == x2) { - switch (blendMode) { - case SDL_BLENDMODE_BLEND: - VLINE(Uint32, DRAW_SETPIXEL_BLEND_RGBA, draw_end); - break; - case SDL_BLENDMODE_ADD: - VLINE(Uint32, DRAW_SETPIXEL_ADD_RGBA, draw_end); - break; - case SDL_BLENDMODE_MOD: - VLINE(Uint32, DRAW_SETPIXEL_MOD_RGBA, draw_end); - break; - default: - VLINE(Uint32, DRAW_SETPIXEL_RGBA, draw_end); - break; - } - } else if (ABS(x1 - x2) == ABS(y1 - y2)) { - switch (blendMode) { - case SDL_BLENDMODE_BLEND: - DLINE(Uint32, DRAW_SETPIXEL_BLEND_RGBA, draw_end); - break; - case SDL_BLENDMODE_ADD: - DLINE(Uint32, DRAW_SETPIXEL_ADD_RGBA, draw_end); - break; - case SDL_BLENDMODE_MOD: - DLINE(Uint32, DRAW_SETPIXEL_MOD_RGBA, draw_end); - break; - default: - DLINE(Uint32, DRAW_SETPIXEL_RGBA, draw_end); - break; - } - } else { - switch (blendMode) { - case SDL_BLENDMODE_BLEND: - AALINE(x1, y1, x2, y2, - DRAW_SETPIXELXY4_BLEND_RGBA, DRAW_SETPIXELXY4_BLEND_RGBA, - draw_end); - break; - case SDL_BLENDMODE_ADD: - AALINE(x1, y1, x2, y2, - DRAW_SETPIXELXY4_ADD_RGBA, DRAW_SETPIXELXY4_ADD_RGBA, - draw_end); - break; - case SDL_BLENDMODE_MOD: - AALINE(x1, y1, x2, y2, - DRAW_SETPIXELXY4_MOD_RGBA, DRAW_SETPIXELXY4_MOD_RGBA, - draw_end); - break; - default: - AALINE(x1, y1, x2, y2, - DRAW_SETPIXELXY4_RGBA, DRAW_SETPIXELXY4_BLEND_RGBA, - draw_end); - break; - } - } -} - -static void -SDL_BlendLine_RGB888(SDL_Surface * dst, int x1, int y1, int x2, int y2, - SDL_BlendMode blendMode, Uint8 _r, Uint8 _g, Uint8 _b, Uint8 _a, - SDL_bool draw_end) -{ - unsigned r, g, b, a, inva; - - if (blendMode == SDL_BLENDMODE_BLEND || blendMode == SDL_BLENDMODE_ADD) { - r = DRAW_MUL(_r, _a); - g = DRAW_MUL(_g, _a); - b = DRAW_MUL(_b, _a); - a = _a; - } else { - r = _r; - g = _g; - b = _b; - a = _a; - } - inva = (a ^ 0xff); - - if (y1 == y2) { - switch (blendMode) { - case SDL_BLENDMODE_BLEND: - HLINE(Uint32, DRAW_SETPIXEL_BLEND_RGB888, draw_end); - break; - case SDL_BLENDMODE_ADD: - HLINE(Uint32, DRAW_SETPIXEL_ADD_RGB888, draw_end); - break; - case SDL_BLENDMODE_MOD: - HLINE(Uint32, DRAW_SETPIXEL_MOD_RGB888, draw_end); - break; - default: - HLINE(Uint32, DRAW_SETPIXEL_RGB888, draw_end); - break; - } - } else if (x1 == x2) { - switch (blendMode) { - case SDL_BLENDMODE_BLEND: - VLINE(Uint32, DRAW_SETPIXEL_BLEND_RGB888, draw_end); - break; - case SDL_BLENDMODE_ADD: - VLINE(Uint32, DRAW_SETPIXEL_ADD_RGB888, draw_end); - break; - case SDL_BLENDMODE_MOD: - VLINE(Uint32, DRAW_SETPIXEL_MOD_RGB888, draw_end); - break; - default: - VLINE(Uint32, DRAW_SETPIXEL_RGB888, draw_end); - break; - } - } else if (ABS(x1 - x2) == ABS(y1 - y2)) { - switch (blendMode) { - case SDL_BLENDMODE_BLEND: - DLINE(Uint32, DRAW_SETPIXEL_BLEND_RGB888, draw_end); - break; - case SDL_BLENDMODE_ADD: - DLINE(Uint32, DRAW_SETPIXEL_ADD_RGB888, draw_end); - break; - case SDL_BLENDMODE_MOD: - DLINE(Uint32, DRAW_SETPIXEL_MOD_RGB888, draw_end); - break; - default: - DLINE(Uint32, DRAW_SETPIXEL_RGB888, draw_end); - break; - } - } else { - switch (blendMode) { - case SDL_BLENDMODE_BLEND: - AALINE(x1, y1, x2, y2, - DRAW_SETPIXELXY_BLEND_RGB888, DRAW_SETPIXELXY_BLEND_RGB888, - draw_end); - break; - case SDL_BLENDMODE_ADD: - AALINE(x1, y1, x2, y2, - DRAW_SETPIXELXY_ADD_RGB888, DRAW_SETPIXELXY_ADD_RGB888, - draw_end); - break; - case SDL_BLENDMODE_MOD: - AALINE(x1, y1, x2, y2, - DRAW_SETPIXELXY_MOD_RGB888, DRAW_SETPIXELXY_MOD_RGB888, - draw_end); - break; - default: - AALINE(x1, y1, x2, y2, - DRAW_SETPIXELXY_RGB888, DRAW_SETPIXELXY_BLEND_RGB888, - draw_end); - break; - } - } -} - -static void -SDL_BlendLine_ARGB8888(SDL_Surface * dst, int x1, int y1, int x2, int y2, - SDL_BlendMode blendMode, Uint8 _r, Uint8 _g, Uint8 _b, Uint8 _a, - SDL_bool draw_end) -{ - unsigned r, g, b, a, inva; - - if (blendMode == SDL_BLENDMODE_BLEND || blendMode == SDL_BLENDMODE_ADD) { - r = DRAW_MUL(_r, _a); - g = DRAW_MUL(_g, _a); - b = DRAW_MUL(_b, _a); - a = _a; - } else { - r = _r; - g = _g; - b = _b; - a = _a; - } - inva = (a ^ 0xff); - - if (y1 == y2) { - switch (blendMode) { - case SDL_BLENDMODE_BLEND: - HLINE(Uint32, DRAW_SETPIXEL_BLEND_ARGB8888, draw_end); - break; - case SDL_BLENDMODE_ADD: - HLINE(Uint32, DRAW_SETPIXEL_ADD_ARGB8888, draw_end); - break; - case SDL_BLENDMODE_MOD: - HLINE(Uint32, DRAW_SETPIXEL_MOD_ARGB8888, draw_end); - break; - default: - HLINE(Uint32, DRAW_SETPIXEL_ARGB8888, draw_end); - break; - } - } else if (x1 == x2) { - switch (blendMode) { - case SDL_BLENDMODE_BLEND: - VLINE(Uint32, DRAW_SETPIXEL_BLEND_ARGB8888, draw_end); - break; - case SDL_BLENDMODE_ADD: - VLINE(Uint32, DRAW_SETPIXEL_ADD_ARGB8888, draw_end); - break; - case SDL_BLENDMODE_MOD: - VLINE(Uint32, DRAW_SETPIXEL_MOD_ARGB8888, draw_end); - break; - default: - VLINE(Uint32, DRAW_SETPIXEL_ARGB8888, draw_end); - break; - } - } else if (ABS(x1 - x2) == ABS(y1 - y2)) { - switch (blendMode) { - case SDL_BLENDMODE_BLEND: - DLINE(Uint32, DRAW_SETPIXEL_BLEND_ARGB8888, draw_end); - break; - case SDL_BLENDMODE_ADD: - DLINE(Uint32, DRAW_SETPIXEL_ADD_ARGB8888, draw_end); - break; - case SDL_BLENDMODE_MOD: - DLINE(Uint32, DRAW_SETPIXEL_MOD_ARGB8888, draw_end); - break; - default: - DLINE(Uint32, DRAW_SETPIXEL_ARGB8888, draw_end); - break; - } - } else { - switch (blendMode) { - case SDL_BLENDMODE_BLEND: - AALINE(x1, y1, x2, y2, - DRAW_SETPIXELXY_BLEND_ARGB8888, DRAW_SETPIXELXY_BLEND_ARGB8888, - draw_end); - break; - case SDL_BLENDMODE_ADD: - AALINE(x1, y1, x2, y2, - DRAW_SETPIXELXY_ADD_ARGB8888, DRAW_SETPIXELXY_ADD_ARGB8888, - draw_end); - break; - case SDL_BLENDMODE_MOD: - AALINE(x1, y1, x2, y2, - DRAW_SETPIXELXY_MOD_ARGB8888, DRAW_SETPIXELXY_MOD_ARGB8888, - draw_end); - break; - default: - AALINE(x1, y1, x2, y2, - DRAW_SETPIXELXY_ARGB8888, DRAW_SETPIXELXY_BLEND_ARGB8888, - draw_end); - break; - } - } -} - -typedef void (*BlendLineFunc) (SDL_Surface * dst, - int x1, int y1, int x2, int y2, - SDL_BlendMode blendMode, - Uint8 r, Uint8 g, Uint8 b, Uint8 a, - SDL_bool draw_end); - -static BlendLineFunc -SDL_CalculateBlendLineFunc(const SDL_PixelFormat * fmt) -{ - switch (fmt->BytesPerPixel) { - case 2: - if (fmt->Rmask == 0x7C00) { - return SDL_BlendLine_RGB555; - } else if (fmt->Rmask == 0xF800) { - return SDL_BlendLine_RGB565; - } else { - return SDL_BlendLine_RGB2; - } - break; - case 4: - if (fmt->Rmask == 0x00FF0000) { - if (fmt->Amask) { - return SDL_BlendLine_ARGB8888; - } else { - return SDL_BlendLine_RGB888; - } - } else { - if (fmt->Amask) { - return SDL_BlendLine_RGBA4; - } else { - return SDL_BlendLine_RGB4; - } - } - } - return NULL; -} - -int -SDL_BlendLine(SDL_Surface * dst, int x1, int y1, int x2, int y2, - SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a) -{ - BlendLineFunc func; - - if (!dst) { - SDL_SetError("SDL_BlendLine(): Passed NULL destination surface"); - return -1; - } - - func = SDL_CalculateBlendLineFunc(dst->format); - if (!func) { - SDL_SetError("SDL_BlendLine(): Unsupported surface format"); - return -1; - } - - /* Perform clipping */ - /* FIXME: We don't actually want to clip, as it may change line slope */ - if (!SDL_IntersectRectAndLine(&dst->clip_rect, &x1, &y1, &x2, &y2)) { - return 0; - } - - func(dst, x1, y1, x2, y2, blendMode, r, g, b, a, SDL_TRUE); - return 0; -} - -int -SDL_BlendLines(SDL_Surface * dst, const SDL_Point * points, int count, - SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a) -{ - int i; - int x1, y1; - int x2, y2; - SDL_bool draw_end; - BlendLineFunc func; - - if (!dst) { - SDL_SetError("SDL_BlendLines(): Passed NULL destination surface"); - return -1; - } - - func = SDL_CalculateBlendLineFunc(dst->format); - if (!func) { - SDL_SetError("SDL_BlendLines(): Unsupported surface format"); - return -1; - } - - for (i = 1; i < count; ++i) { - x1 = points[i-1].x; - y1 = points[i-1].y; - x2 = points[i].x; - y2 = points[i].y; - - /* Perform clipping */ - /* FIXME: We don't actually want to clip, as it may change line slope */ - if (!SDL_IntersectRectAndLine(&dst->clip_rect, &x1, &y1, &x2, &y2)) { - continue; - } - - /* Draw the end if it was clipped */ - draw_end = (x2 != points[i].x || y2 != points[i].y); - - func(dst, x1, y1, x2, y2, blendMode, r, g, b, a, draw_end); - } - if (points[0].x != points[count-1].x || points[0].y != points[count-1].y) { - SDL_BlendPoint(dst, points[count-1].x, points[count-1].y, - blendMode, r, g, b, a); - } - return 0; -} - -#endif /* !SDL_RENDER_DISABLED */ - -/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/SDL-mobile/src/render/software/SDL_blendline.h b/src/SDL-mobile/src/render/software/SDL_blendline.h deleted file mode 100644 index c9da31c97..000000000 --- a/src/SDL-mobile/src/render/software/SDL_blendline.h +++ /dev/null @@ -1,27 +0,0 @@ -/* - Simple DirectMedia Layer - Copyright (C) 1997-2012 Sam Lantinga - - 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" - - -extern int SDL_BlendLine(SDL_Surface * dst, int x1, int y1, int x2, int y2, SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a); -extern int SDL_BlendLines(SDL_Surface * dst, const SDL_Point * points, int count, SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a); - -/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/SDL-mobile/src/render/software/SDL_blendpoint.c b/src/SDL-mobile/src/render/software/SDL_blendpoint.c deleted file mode 100644 index 4d5ac762d..000000000 --- a/src/SDL-mobile/src/render/software/SDL_blendpoint.c +++ /dev/null @@ -1,349 +0,0 @@ -/* - Simple DirectMedia Layer - Copyright (C) 1997-2012 Sam Lantinga - - 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_RENDER_DISABLED - -#include "SDL_draw.h" -#include "SDL_blendpoint.h" - - -static int -SDL_BlendPoint_RGB555(SDL_Surface * dst, int x, int y, SDL_BlendMode blendMode, Uint8 r, - Uint8 g, Uint8 b, Uint8 a) -{ - unsigned inva = 0xff - a; - - switch (blendMode) { - case SDL_BLENDMODE_BLEND: - DRAW_SETPIXELXY_BLEND_RGB555(x, y); - break; - case SDL_BLENDMODE_ADD: - DRAW_SETPIXELXY_ADD_RGB555(x, y); - break; - case SDL_BLENDMODE_MOD: - DRAW_SETPIXELXY_MOD_RGB555(x, y); - break; - default: - DRAW_SETPIXELXY_RGB555(x, y); - break; - } - return 0; -} - -static int -SDL_BlendPoint_RGB565(SDL_Surface * dst, int x, int y, SDL_BlendMode blendMode, Uint8 r, - Uint8 g, Uint8 b, Uint8 a) -{ - unsigned inva = 0xff - a; - - switch (blendMode) { - case SDL_BLENDMODE_BLEND: - DRAW_SETPIXELXY_BLEND_RGB565(x, y); - break; - case SDL_BLENDMODE_ADD: - DRAW_SETPIXELXY_ADD_RGB565(x, y); - break; - case SDL_BLENDMODE_MOD: - DRAW_SETPIXELXY_MOD_RGB565(x, y); - break; - default: - DRAW_SETPIXELXY_RGB565(x, y); - break; - } - return 0; -} - -static int -SDL_BlendPoint_RGB888(SDL_Surface * dst, int x, int y, SDL_BlendMode blendMode, Uint8 r, - Uint8 g, Uint8 b, Uint8 a) -{ - unsigned inva = 0xff - a; - - switch (blendMode) { - case SDL_BLENDMODE_BLEND: - DRAW_SETPIXELXY_BLEND_RGB888(x, y); - break; - case SDL_BLENDMODE_ADD: - DRAW_SETPIXELXY_ADD_RGB888(x, y); - break; - case SDL_BLENDMODE_MOD: - DRAW_SETPIXELXY_MOD_RGB888(x, y); - break; - default: - DRAW_SETPIXELXY_RGB888(x, y); - break; - } - return 0; -} - -static int -SDL_BlendPoint_ARGB8888(SDL_Surface * dst, int x, int y, SDL_BlendMode blendMode, - Uint8 r, Uint8 g, Uint8 b, Uint8 a) -{ - unsigned inva = 0xff - a; - - switch (blendMode) { - case SDL_BLENDMODE_BLEND: - DRAW_SETPIXELXY_BLEND_ARGB8888(x, y); - break; - case SDL_BLENDMODE_ADD: - DRAW_SETPIXELXY_ADD_ARGB8888(x, y); - break; - case SDL_BLENDMODE_MOD: - DRAW_SETPIXELXY_MOD_ARGB8888(x, y); - break; - default: - DRAW_SETPIXELXY_ARGB8888(x, y); - break; - } - return 0; -} - -static int -SDL_BlendPoint_RGB(SDL_Surface * dst, int x, int y, SDL_BlendMode blendMode, Uint8 r, - Uint8 g, Uint8 b, Uint8 a) -{ - SDL_PixelFormat *fmt = dst->format; - unsigned inva = 0xff - a; - - switch (fmt->BytesPerPixel) { - case 2: - switch (blendMode) { - case SDL_BLENDMODE_BLEND: - DRAW_SETPIXELXY2_BLEND_RGB(x, y); - break; - case SDL_BLENDMODE_ADD: - DRAW_SETPIXELXY2_ADD_RGB(x, y); - break; - case SDL_BLENDMODE_MOD: - DRAW_SETPIXELXY2_MOD_RGB(x, y); - break; - default: - DRAW_SETPIXELXY2_RGB(x, y); - break; - } - return 0; - case 4: - switch (blendMode) { - case SDL_BLENDMODE_BLEND: - DRAW_SETPIXELXY4_BLEND_RGB(x, y); - break; - case SDL_BLENDMODE_ADD: - DRAW_SETPIXELXY4_ADD_RGB(x, y); - break; - case SDL_BLENDMODE_MOD: - DRAW_SETPIXELXY4_MOD_RGB(x, y); - break; - default: - DRAW_SETPIXELXY4_RGB(x, y); - break; - } - return 0; - default: - SDL_Unsupported(); - return -1; - } -} - -static int -SDL_BlendPoint_RGBA(SDL_Surface * dst, int x, int y, SDL_BlendMode blendMode, Uint8 r, - Uint8 g, Uint8 b, Uint8 a) -{ - SDL_PixelFormat *fmt = dst->format; - unsigned inva = 0xff - a; - - switch (fmt->BytesPerPixel) { - case 4: - switch (blendMode) { - case SDL_BLENDMODE_BLEND: - DRAW_SETPIXELXY4_BLEND_RGBA(x, y); - break; - case SDL_BLENDMODE_ADD: - DRAW_SETPIXELXY4_ADD_RGBA(x, y); - break; - case SDL_BLENDMODE_MOD: - DRAW_SETPIXELXY4_MOD_RGBA(x, y); - break; - default: - DRAW_SETPIXELXY4_RGBA(x, y); - break; - } - return 0; - default: - SDL_Unsupported(); - return -1; - } -} - -int -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; - } - - /* This function doesn't work on surfaces < 8 bpp */ - if (dst->format->BitsPerPixel < 8) { - SDL_SetError("SDL_BlendPoint(): Unsupported surface format"); - return -1; - } - - /* Perform clipping */ - if (x < dst->clip_rect.x || y < dst->clip_rect.y || - x >= (dst->clip_rect.x + dst->clip_rect.w) || - y >= (dst->clip_rect.y + dst->clip_rect.h)) { - return 0; - } - - if (blendMode == SDL_BLENDMODE_BLEND || blendMode == SDL_BLENDMODE_ADD) { - r = DRAW_MUL(r, a); - g = DRAW_MUL(g, a); - b = DRAW_MUL(b, a); - } - - switch (dst->format->BitsPerPixel) { - case 15: - switch (dst->format->Rmask) { - case 0x7C00: - return SDL_BlendPoint_RGB555(dst, x, y, blendMode, r, g, b, a); - } - break; - case 16: - switch (dst->format->Rmask) { - case 0xF800: - return SDL_BlendPoint_RGB565(dst, x, y, blendMode, r, g, b, a); - } - break; - case 32: - switch (dst->format->Rmask) { - case 0x00FF0000: - if (!dst->format->Amask) { - return SDL_BlendPoint_RGB888(dst, x, y, blendMode, r, g, b, - a); - } else { - return SDL_BlendPoint_ARGB8888(dst, x, y, blendMode, r, g, b, - a); - } - break; - } - break; - default: - break; - } - - if (!dst->format->Amask) { - return SDL_BlendPoint_RGB(dst, x, y, blendMode, r, g, b, a); - } else { - return SDL_BlendPoint_RGBA(dst, x, y, blendMode, r, g, b, a); - } -} - -int -SDL_BlendPoints(SDL_Surface * dst, const SDL_Point * points, int count, - SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a) -{ - int minx, miny; - int maxx, maxy; - int i; - int x, y; - int (*func)(SDL_Surface * dst, int x, int y, - SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a) = NULL; - int status = 0; - - if (!dst) { - SDL_SetError("Passed NULL destination surface"); - return -1; - } - - /* This function doesn't work on surfaces < 8 bpp */ - if (dst->format->BitsPerPixel < 8) { - SDL_SetError("SDL_BlendPoints(): Unsupported surface format"); - return (-1); - } - - if (blendMode == SDL_BLENDMODE_BLEND || blendMode == SDL_BLENDMODE_ADD) { - r = DRAW_MUL(r, a); - g = DRAW_MUL(g, a); - b = DRAW_MUL(b, a); - } - - /* FIXME: Does this function pointer slow things down significantly? */ - switch (dst->format->BitsPerPixel) { - case 15: - switch (dst->format->Rmask) { - case 0x7C00: - func = SDL_BlendPoint_RGB555; - break; - } - break; - case 16: - switch (dst->format->Rmask) { - case 0xF800: - func = SDL_BlendPoint_RGB565; - break; - } - break; - case 32: - switch (dst->format->Rmask) { - case 0x00FF0000: - if (!dst->format->Amask) { - func = SDL_BlendPoint_RGB888; - } else { - func = SDL_BlendPoint_ARGB8888; - } - break; - } - break; - default: - break; - } - - if (!func) { - if (!dst->format->Amask) { - func = SDL_BlendPoint_RGB; - } else { - func = SDL_BlendPoint_RGBA; - } - } - - minx = dst->clip_rect.x; - maxx = dst->clip_rect.x + dst->clip_rect.w - 1; - miny = dst->clip_rect.y; - maxy = dst->clip_rect.y + dst->clip_rect.h - 1; - - for (i = 0; i < count; ++i) { - x = points[i].x; - y = points[i].y; - - if (x < minx || x > maxx || y < miny || y > maxy) { - continue; - } - status = func(dst, x, y, blendMode, r, g, b, a); - } - return status; -} - -#endif /* !SDL_RENDER_DISABLED */ - -/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/SDL-mobile/src/render/software/SDL_blendpoint.h b/src/SDL-mobile/src/render/software/SDL_blendpoint.h deleted file mode 100644 index 4c1e76dc0..000000000 --- a/src/SDL-mobile/src/render/software/SDL_blendpoint.h +++ /dev/null @@ -1,27 +0,0 @@ -/* - Simple DirectMedia Layer - Copyright (C) 1997-2012 Sam Lantinga - - 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" - - -extern int SDL_BlendPoint(SDL_Surface * dst, int x, int y, SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a); -extern int SDL_BlendPoints(SDL_Surface * dst, const SDL_Point * points, int count, SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a); - -/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/SDL-mobile/src/render/software/SDL_draw.h b/src/SDL-mobile/src/render/software/SDL_draw.h deleted file mode 100644 index e262f7d65..000000000 --- a/src/SDL-mobile/src/render/software/SDL_draw.h +++ /dev/null @@ -1,575 +0,0 @@ -/* - Simple DirectMedia Layer - Copyright (C) 1997-2012 Sam Lantinga - - 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" - -#include "../../video/SDL_blit.h" - -/* This code assumes that r, g, b, a are the source color, - * and in the blend and add case, the RGB values are premultiplied by a. - */ - -#define DRAW_MUL(_a, _b) (((unsigned)(_a)*(_b))/255) - -#define DRAW_FASTSETPIXEL(type) \ - *pixel = (type) color - -#define DRAW_FASTSETPIXEL1 DRAW_FASTSETPIXEL(Uint8) -#define DRAW_FASTSETPIXEL2 DRAW_FASTSETPIXEL(Uint16) -#define DRAW_FASTSETPIXEL4 DRAW_FASTSETPIXEL(Uint32) - -#define DRAW_FASTSETPIXELXY(x, y, type, bpp, color) \ - *(type *)((Uint8 *)dst->pixels + (y) * dst->pitch \ - + (x) * bpp) = (type) color - -#define DRAW_FASTSETPIXELXY1(x, y) DRAW_FASTSETPIXELXY(x, y, Uint8, 1, color) -#define DRAW_FASTSETPIXELXY2(x, y) DRAW_FASTSETPIXELXY(x, y, Uint16, 2, color) -#define DRAW_FASTSETPIXELXY4(x, y) DRAW_FASTSETPIXELXY(x, y, Uint32, 4, color) - -#define DRAW_SETPIXEL(setpixel) \ -do { \ - unsigned sr = r, sg = g, sb = b, sa = a; (void) sa; \ - setpixel; \ -} while (0) - -#define DRAW_SETPIXEL_BLEND(getpixel, setpixel) \ -do { \ - unsigned sr, sg, sb, sa; (void) sa; \ - getpixel; \ - sr = DRAW_MUL(inva, sr) + r; \ - sg = DRAW_MUL(inva, sg) + g; \ - sb = DRAW_MUL(inva, sb) + b; \ - setpixel; \ -} while (0) - -#define DRAW_SETPIXEL_ADD(getpixel, setpixel) \ -do { \ - unsigned sr, sg, sb, sa; (void) sa; \ - getpixel; \ - sr += r; if (sr > 0xff) sr = 0xff; \ - sg += g; if (sg > 0xff) sg = 0xff; \ - sb += b; if (sb > 0xff) sb = 0xff; \ - setpixel; \ -} while (0) - -#define DRAW_SETPIXEL_MOD(getpixel, setpixel) \ -do { \ - unsigned sr, sg, sb, sa; (void) sa; \ - getpixel; \ - sr = DRAW_MUL(sr, r); \ - sg = DRAW_MUL(sg, g); \ - sb = DRAW_MUL(sb, b); \ - setpixel; \ -} while (0) - -#define DRAW_SETPIXELXY(x, y, type, bpp, op) \ -do { \ - type *pixel = (type *)((Uint8 *)dst->pixels + (y) * dst->pitch \ - + (x) * bpp); \ - op; \ -} while (0) - -/* - * Define draw operators for RGB555 - */ - -#define DRAW_SETPIXEL_RGB555 \ - DRAW_SETPIXEL(RGB555_FROM_RGB(*pixel, sr, sg, sb)) - -#define DRAW_SETPIXEL_BLEND_RGB555 \ - DRAW_SETPIXEL_BLEND(RGB_FROM_RGB555(*pixel, sr, sg, sb), \ - RGB555_FROM_RGB(*pixel, sr, sg, sb)) - -#define DRAW_SETPIXEL_ADD_RGB555 \ - DRAW_SETPIXEL_ADD(RGB_FROM_RGB555(*pixel, sr, sg, sb), \ - RGB555_FROM_RGB(*pixel, sr, sg, sb)) - -#define DRAW_SETPIXEL_MOD_RGB555 \ - DRAW_SETPIXEL_MOD(RGB_FROM_RGB555(*pixel, sr, sg, sb), \ - RGB555_FROM_RGB(*pixel, sr, sg, sb)) - -#define DRAW_SETPIXELXY_RGB555(x, y) \ - DRAW_SETPIXELXY(x, y, Uint16, 2, DRAW_SETPIXEL_RGB555) - -#define DRAW_SETPIXELXY_BLEND_RGB555(x, y) \ - DRAW_SETPIXELXY(x, y, Uint16, 2, DRAW_SETPIXEL_BLEND_RGB555) - -#define DRAW_SETPIXELXY_ADD_RGB555(x, y) \ - DRAW_SETPIXELXY(x, y, Uint16, 2, DRAW_SETPIXEL_ADD_RGB555) - -#define DRAW_SETPIXELXY_MOD_RGB555(x, y) \ - DRAW_SETPIXELXY(x, y, Uint16, 2, DRAW_SETPIXEL_MOD_RGB555) - -/* - * Define draw operators for RGB565 - */ - -#define DRAW_SETPIXEL_RGB565 \ - DRAW_SETPIXEL(RGB565_FROM_RGB(*pixel, sr, sg, sb)) - -#define DRAW_SETPIXEL_BLEND_RGB565 \ - DRAW_SETPIXEL_BLEND(RGB_FROM_RGB565(*pixel, sr, sg, sb), \ - RGB565_FROM_RGB(*pixel, sr, sg, sb)) - -#define DRAW_SETPIXEL_ADD_RGB565 \ - DRAW_SETPIXEL_ADD(RGB_FROM_RGB565(*pixel, sr, sg, sb), \ - RGB565_FROM_RGB(*pixel, sr, sg, sb)) - -#define DRAW_SETPIXEL_MOD_RGB565 \ - DRAW_SETPIXEL_MOD(RGB_FROM_RGB565(*pixel, sr, sg, sb), \ - RGB565_FROM_RGB(*pixel, sr, sg, sb)) - -#define DRAW_SETPIXELXY_RGB565(x, y) \ - DRAW_SETPIXELXY(x, y, Uint16, 2, DRAW_SETPIXEL_RGB565) - -#define DRAW_SETPIXELXY_BLEND_RGB565(x, y) \ - DRAW_SETPIXELXY(x, y, Uint16, 2, DRAW_SETPIXEL_BLEND_RGB565) - -#define DRAW_SETPIXELXY_ADD_RGB565(x, y) \ - DRAW_SETPIXELXY(x, y, Uint16, 2, DRAW_SETPIXEL_ADD_RGB565) - -#define DRAW_SETPIXELXY_MOD_RGB565(x, y) \ - DRAW_SETPIXELXY(x, y, Uint16, 2, DRAW_SETPIXEL_MOD_RGB565) - -/* - * Define draw operators for RGB888 - */ - -#define DRAW_SETPIXEL_RGB888 \ - DRAW_SETPIXEL(RGB888_FROM_RGB(*pixel, sr, sg, sb)) - -#define DRAW_SETPIXEL_BLEND_RGB888 \ - DRAW_SETPIXEL_BLEND(RGB_FROM_RGB888(*pixel, sr, sg, sb), \ - RGB888_FROM_RGB(*pixel, sr, sg, sb)) - -#define DRAW_SETPIXEL_ADD_RGB888 \ - DRAW_SETPIXEL_ADD(RGB_FROM_RGB888(*pixel, sr, sg, sb), \ - RGB888_FROM_RGB(*pixel, sr, sg, sb)) - -#define DRAW_SETPIXEL_MOD_RGB888 \ - DRAW_SETPIXEL_MOD(RGB_FROM_RGB888(*pixel, sr, sg, sb), \ - RGB888_FROM_RGB(*pixel, sr, sg, sb)) - -#define DRAW_SETPIXELXY_RGB888(x, y) \ - DRAW_SETPIXELXY(x, y, Uint32, 4, DRAW_SETPIXEL_RGB888) - -#define DRAW_SETPIXELXY_BLEND_RGB888(x, y) \ - DRAW_SETPIXELXY(x, y, Uint32, 4, DRAW_SETPIXEL_BLEND_RGB888) - -#define DRAW_SETPIXELXY_ADD_RGB888(x, y) \ - DRAW_SETPIXELXY(x, y, Uint32, 4, DRAW_SETPIXEL_ADD_RGB888) - -#define DRAW_SETPIXELXY_MOD_RGB888(x, y) \ - DRAW_SETPIXELXY(x, y, Uint32, 4, DRAW_SETPIXEL_MOD_RGB888) - -/* - * Define draw operators for ARGB8888 - */ - -#define DRAW_SETPIXEL_ARGB8888 \ - DRAW_SETPIXEL(ARGB8888_FROM_RGBA(*pixel, sr, sg, sb, sa)) - -#define DRAW_SETPIXEL_BLEND_ARGB8888 \ - DRAW_SETPIXEL_BLEND(RGBA_FROM_ARGB8888(*pixel, sr, sg, sb, sa), \ - ARGB8888_FROM_RGBA(*pixel, sr, sg, sb, sa)) - -#define DRAW_SETPIXEL_ADD_ARGB8888 \ - DRAW_SETPIXEL_ADD(RGBA_FROM_ARGB8888(*pixel, sr, sg, sb, sa), \ - ARGB8888_FROM_RGBA(*pixel, sr, sg, sb, sa)) - -#define DRAW_SETPIXEL_MOD_ARGB8888 \ - DRAW_SETPIXEL_MOD(RGBA_FROM_ARGB8888(*pixel, sr, sg, sb, sa), \ - ARGB8888_FROM_RGBA(*pixel, sr, sg, sb, sa)) - -#define DRAW_SETPIXELXY_ARGB8888(x, y) \ - DRAW_SETPIXELXY(x, y, Uint32, 4, DRAW_SETPIXEL_ARGB8888) - -#define DRAW_SETPIXELXY_BLEND_ARGB8888(x, y) \ - DRAW_SETPIXELXY(x, y, Uint32, 4, DRAW_SETPIXEL_BLEND_ARGB8888) - -#define DRAW_SETPIXELXY_ADD_ARGB8888(x, y) \ - DRAW_SETPIXELXY(x, y, Uint32, 4, DRAW_SETPIXEL_ADD_ARGB8888) - -#define DRAW_SETPIXELXY_MOD_ARGB8888(x, y) \ - DRAW_SETPIXELXY(x, y, Uint32, 4, DRAW_SETPIXEL_MOD_ARGB8888) - -/* - * Define draw operators for general RGB - */ - -#define DRAW_SETPIXEL_RGB \ - DRAW_SETPIXEL(PIXEL_FROM_RGB(*pixel, fmt, sr, sg, sb)) - -#define DRAW_SETPIXEL_BLEND_RGB \ - DRAW_SETPIXEL_BLEND(RGB_FROM_PIXEL(*pixel, fmt, sr, sg, sb), \ - PIXEL_FROM_RGB(*pixel, fmt, sr, sg, sb)) - -#define DRAW_SETPIXEL_ADD_RGB \ - DRAW_SETPIXEL_ADD(RGB_FROM_PIXEL(*pixel, fmt, sr, sg, sb), \ - PIXEL_FROM_RGB(*pixel, fmt, sr, sg, sb)) - -#define DRAW_SETPIXEL_MOD_RGB \ - DRAW_SETPIXEL_MOD(RGB_FROM_PIXEL(*pixel, fmt, sr, sg, sb), \ - PIXEL_FROM_RGB(*pixel, fmt, sr, sg, sb)) - -#define DRAW_SETPIXELXY2_RGB(x, y) \ - DRAW_SETPIXELXY(x, y, Uint16, 2, DRAW_SETPIXEL_RGB) - -#define DRAW_SETPIXELXY4_RGB(x, y) \ - DRAW_SETPIXELXY(x, y, Uint32, 4, DRAW_SETPIXEL_RGB) - -#define DRAW_SETPIXELXY2_BLEND_RGB(x, y) \ - DRAW_SETPIXELXY(x, y, Uint16, 2, DRAW_SETPIXEL_BLEND_RGB) - -#define DRAW_SETPIXELXY4_BLEND_RGB(x, y) \ - DRAW_SETPIXELXY(x, y, Uint32, 4, DRAW_SETPIXEL_BLEND_RGB) - -#define DRAW_SETPIXELXY2_ADD_RGB(x, y) \ - DRAW_SETPIXELXY(x, y, Uint16, 2, DRAW_SETPIXEL_ADD_RGB) - -#define DRAW_SETPIXELXY4_ADD_RGB(x, y) \ - DRAW_SETPIXELXY(x, y, Uint32, 4, DRAW_SETPIXEL_ADD_RGB) - -#define DRAW_SETPIXELXY2_MOD_RGB(x, y) \ - DRAW_SETPIXELXY(x, y, Uint16, 2, DRAW_SETPIXEL_MOD_RGB) - -#define DRAW_SETPIXELXY4_MOD_RGB(x, y) \ - DRAW_SETPIXELXY(x, y, Uint32, 4, DRAW_SETPIXEL_MOD_RGB) - - -/* - * Define draw operators for general RGBA - */ - -#define DRAW_SETPIXEL_RGBA \ - DRAW_SETPIXEL(PIXEL_FROM_RGBA(*pixel, fmt, sr, sg, sb, sa)) - -#define DRAW_SETPIXEL_BLEND_RGBA \ - DRAW_SETPIXEL_BLEND(RGBA_FROM_PIXEL(*pixel, fmt, sr, sg, sb, sa), \ - PIXEL_FROM_RGBA(*pixel, fmt, sr, sg, sb, sa)) - -#define DRAW_SETPIXEL_ADD_RGBA \ - DRAW_SETPIXEL_ADD(RGBA_FROM_PIXEL(*pixel, fmt, sr, sg, sb, sa), \ - PIXEL_FROM_RGBA(*pixel, fmt, sr, sg, sb, sa)) - -#define DRAW_SETPIXEL_MOD_RGBA \ - DRAW_SETPIXEL_MOD(RGBA_FROM_PIXEL(*pixel, fmt, sr, sg, sb, sa), \ - PIXEL_FROM_RGBA(*pixel, fmt, sr, sg, sb, sa)) - -#define DRAW_SETPIXELXY4_RGBA(x, y) \ - DRAW_SETPIXELXY(x, y, Uint32, 4, DRAW_SETPIXEL_RGBA) - -#define DRAW_SETPIXELXY4_BLEND_RGBA(x, y) \ - DRAW_SETPIXELXY(x, y, Uint32, 4, DRAW_SETPIXEL_BLEND_RGBA) - -#define DRAW_SETPIXELXY4_ADD_RGBA(x, y) \ - DRAW_SETPIXELXY(x, y, Uint32, 4, DRAW_SETPIXEL_ADD_RGBA) - -#define DRAW_SETPIXELXY4_MOD_RGBA(x, y) \ - DRAW_SETPIXELXY(x, y, Uint32, 4, DRAW_SETPIXEL_MOD_RGBA) - -/* - * Define line drawing macro - */ - -#define ABS(_x) ((_x) < 0 ? -(_x) : (_x)) - -/* Horizontal line */ -#define HLINE(type, op, draw_end) \ -{ \ - int length; \ - int pitch = (dst->pitch / dst->format->BytesPerPixel); \ - type *pixel; \ - if (x1 <= x2) { \ - pixel = (type *)dst->pixels + y1 * pitch + x1; \ - length = draw_end ? (x2-x1+1) : (x2-x1); \ - } else { \ - pixel = (type *)dst->pixels + y1 * pitch + x2; \ - if (!draw_end) { \ - ++pixel; \ - } \ - length = draw_end ? (x1-x2+1) : (x1-x2); \ - } \ - while (length--) { \ - op; \ - ++pixel; \ - } \ -} - -/* Vertical line */ -#define VLINE(type, op, draw_end) \ -{ \ - int length; \ - int pitch = (dst->pitch / dst->format->BytesPerPixel); \ - type *pixel; \ - if (y1 <= y2) { \ - pixel = (type *)dst->pixels + y1 * pitch + x1; \ - length = draw_end ? (y2-y1+1) : (y2-y1); \ - } else { \ - pixel = (type *)dst->pixels + y2 * pitch + x1; \ - if (!draw_end) { \ - pixel += pitch; \ - } \ - length = draw_end ? (y1-y2+1) : (y1-y2); \ - } \ - while (length--) { \ - op; \ - pixel += pitch; \ - } \ -} - -/* Diagonal line */ -#define DLINE(type, op, draw_end) \ -{ \ - int length; \ - int pitch = (dst->pitch / dst->format->BytesPerPixel); \ - type *pixel; \ - if (y1 <= y2) { \ - pixel = (type *)dst->pixels + y1 * pitch + x1; \ - if (x1 <= x2) { \ - ++pitch; \ - } else { \ - --pitch; \ - } \ - length = (y2-y1); \ - } else { \ - pixel = (type *)dst->pixels + y2 * pitch + x2; \ - if (x2 <= x1) { \ - ++pitch; \ - } else { \ - --pitch; \ - } \ - if (!draw_end) { \ - pixel += pitch; \ - } \ - length = (y1-y2); \ - } \ - if (draw_end) { \ - ++length; \ - } \ - while (length--) { \ - op; \ - pixel += pitch; \ - } \ -} - -/* Bresenham's line algorithm */ -#define BLINE(x1, y1, x2, y2, op, draw_end) \ -{ \ - int i, deltax, deltay, numpixels; \ - int d, dinc1, dinc2; \ - int x, xinc1, xinc2; \ - int y, yinc1, yinc2; \ - \ - deltax = ABS(x2 - x1); \ - deltay = ABS(y2 - y1); \ - \ - if (deltax >= deltay) { \ - numpixels = deltax + 1; \ - d = (2 * deltay) - deltax; \ - dinc1 = deltay * 2; \ - dinc2 = (deltay - deltax) * 2; \ - xinc1 = 1; \ - xinc2 = 1; \ - yinc1 = 0; \ - yinc2 = 1; \ - } else { \ - numpixels = deltay + 1; \ - d = (2 * deltax) - deltay; \ - dinc1 = deltax * 2; \ - dinc2 = (deltax - deltay) * 2; \ - xinc1 = 0; \ - xinc2 = 1; \ - yinc1 = 1; \ - yinc2 = 1; \ - } \ - \ - if (x1 > x2) { \ - xinc1 = -xinc1; \ - xinc2 = -xinc2; \ - } \ - if (y1 > y2) { \ - yinc1 = -yinc1; \ - yinc2 = -yinc2; \ - } \ - \ - x = x1; \ - y = y1; \ - \ - if (!draw_end) { \ - --numpixels; \ - } \ - for (i = 0; i < numpixels; ++i) { \ - op(x, y); \ - if (d < 0) { \ - d += dinc1; \ - x += xinc1; \ - y += yinc1; \ - } else { \ - d += dinc2; \ - x += xinc2; \ - y += yinc2; \ - } \ - } \ -} - -/* Xiaolin Wu's line algorithm, based on Michael Abrash's implementation */ -#define WULINE(x1, y1, x2, y2, opaque_op, blend_op, draw_end) \ -{ \ - Uint16 ErrorAdj, ErrorAcc; \ - Uint16 ErrorAccTemp, Weighting; \ - int DeltaX, DeltaY, Temp, XDir; \ - unsigned r, g, b, a, inva; \ - \ - /* Draw the initial pixel, which is always exactly intersected by \ - the line and so needs no weighting */ \ - opaque_op(x1, y1); \ - \ - /* Draw the final pixel, which is always exactly intersected by the line \ - and so needs no weighting */ \ - if (draw_end) { \ - opaque_op(x2, y2); \ - } \ - \ - /* Make sure the line runs top to bottom */ \ - if (y1 > y2) { \ - Temp = y1; y1 = y2; y2 = Temp; \ - Temp = x1; x1 = x2; x2 = Temp; \ - } \ - DeltaY = y2 - y1; \ - \ - if ((DeltaX = x2 - x1) >= 0) { \ - XDir = 1; \ - } else { \ - XDir = -1; \ - DeltaX = -DeltaX; /* make DeltaX positive */ \ - } \ - \ - /* line is not horizontal, diagonal, or vertical */ \ - ErrorAcc = 0; /* initialize the line error accumulator to 0 */ \ - \ - /* Is this an X-major or Y-major line? */ \ - if (DeltaY > DeltaX) { \ - /* Y-major line; calculate 16-bit fixed-point fractional part of a \ - pixel that X advances each time Y advances 1 pixel, truncating the \ - result so that we won't overrun the endpoint along the X axis */ \ - ErrorAdj = ((unsigned long) DeltaX << 16) / (unsigned long) DeltaY; \ - /* Draw all pixels other than the first and last */ \ - while (--DeltaY) { \ - ErrorAccTemp = ErrorAcc; /* remember currrent accumulated error */ \ - ErrorAcc += ErrorAdj; /* calculate error for next pixel */ \ - if (ErrorAcc <= ErrorAccTemp) { \ - /* The error accumulator turned over, so advance the X coord */ \ - x1 += XDir; \ - } \ - y1++; /* Y-major, so always advance Y */ \ - /* The IntensityBits most significant bits of ErrorAcc give us the \ - intensity weighting for this pixel, and the complement of the \ - weighting for the paired pixel */ \ - Weighting = ErrorAcc >> 8; \ - { \ - a = DRAW_MUL(_a, (Weighting ^ 255)); \ - r = DRAW_MUL(_r, a); \ - g = DRAW_MUL(_g, a); \ - b = DRAW_MUL(_b, a); \ - inva = (a ^ 0xFF); \ - blend_op(x1, y1); \ - } \ - { \ - a = DRAW_MUL(_a, Weighting); \ - r = DRAW_MUL(_r, a); \ - g = DRAW_MUL(_g, a); \ - b = DRAW_MUL(_b, a); \ - inva = (a ^ 0xFF); \ - blend_op(x1 + XDir, y1); \ - } \ - } \ - } else { \ - /* X-major line; calculate 16-bit fixed-point fractional part of a \ - pixel that Y advances each time X advances 1 pixel, truncating the \ - result to avoid overrunning the endpoint along the X axis */ \ - ErrorAdj = ((unsigned long) DeltaY << 16) / (unsigned long) DeltaX; \ - /* Draw all pixels other than the first and last */ \ - while (--DeltaX) { \ - ErrorAccTemp = ErrorAcc; /* remember currrent accumulated error */ \ - ErrorAcc += ErrorAdj; /* calculate error for next pixel */ \ - if (ErrorAcc <= ErrorAccTemp) { \ - /* The error accumulator turned over, so advance the Y coord */ \ - y1++; \ - } \ - x1 += XDir; /* X-major, so always advance X */ \ - /* The IntensityBits most significant bits of ErrorAcc give us the \ - intensity weighting for this pixel, and the complement of the \ - weighting for the paired pixel */ \ - Weighting = ErrorAcc >> 8; \ - { \ - a = DRAW_MUL(_a, (Weighting ^ 255)); \ - r = DRAW_MUL(_r, a); \ - g = DRAW_MUL(_g, a); \ - b = DRAW_MUL(_b, a); \ - inva = (a ^ 0xFF); \ - blend_op(x1, y1); \ - } \ - { \ - a = DRAW_MUL(_a, Weighting); \ - r = DRAW_MUL(_r, a); \ - g = DRAW_MUL(_g, a); \ - b = DRAW_MUL(_b, a); \ - inva = (a ^ 0xFF); \ - blend_op(x1, y1 + 1); \ - } \ - } \ - } \ -} - -#ifdef AA_LINES -#define AALINE(x1, y1, x2, y2, opaque_op, blend_op, draw_end) \ - WULINE(x1, y1, x2, y2, opaque_op, blend_op, draw_end) -#else -#define AALINE(x1, y1, x2, y2, opaque_op, blend_op, draw_end) \ - BLINE(x1, y1, x2, y2, opaque_op, draw_end) -#endif - -/* - * Define fill rect macro - */ - -#define FILLRECT(type, op) \ -do { \ - int width = rect->w; \ - int height = rect->h; \ - int pitch = (dst->pitch / dst->format->BytesPerPixel); \ - int skip = pitch - width; \ - type *pixel = (type *)dst->pixels + rect->y * pitch + rect->x; \ - while (height--) { \ - { int n = (width+3)/4; \ - switch (width & 3) { \ - case 0: do { op; pixel++; \ - case 3: op; pixel++; \ - case 2: op; pixel++; \ - case 1: op; pixel++; \ - } while ( --n > 0 ); \ - } \ - } \ - pixel += skip; \ - } \ -} while (0) - -/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/SDL-mobile/src/render/software/SDL_drawline.c b/src/SDL-mobile/src/render/software/SDL_drawline.c deleted file mode 100644 index f48767784..000000000 --- a/src/SDL-mobile/src/render/software/SDL_drawline.c +++ /dev/null @@ -1,214 +0,0 @@ -/* - Simple DirectMedia Layer - Copyright (C) 1997-2012 Sam Lantinga - - 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_RENDER_DISABLED - -#include "SDL_draw.h" -#include "SDL_drawline.h" -#include "SDL_drawpoint.h" - - -static void -SDL_DrawLine1(SDL_Surface * dst, int x1, int y1, int x2, int y2, Uint32 color, - SDL_bool draw_end) -{ - if (y1 == y2) { - //HLINE(Uint8, DRAW_FASTSETPIXEL1, draw_end); - int length; - int pitch = (dst->pitch / dst->format->BytesPerPixel); - Uint8 *pixel; - if (x1 <= x2) { - pixel = (Uint8 *)dst->pixels + y1 * pitch + x1; - length = draw_end ? (x2-x1+1) : (x2-x1); - } else { - pixel = (Uint8 *)dst->pixels + y1 * pitch + x2; - if (!draw_end) { - ++pixel; - } - length = draw_end ? (x1-x2+1) : (x1-x2); - } - SDL_memset(pixel, color, length); - } else if (x1 == x2) { - VLINE(Uint8, DRAW_FASTSETPIXEL1, draw_end); - } else if (ABS(x1 - x2) == ABS(y1 - y2)) { - DLINE(Uint8, DRAW_FASTSETPIXEL1, draw_end); - } else { - BLINE(x1, y1, x2, y2, DRAW_FASTSETPIXELXY1, draw_end); - } -} - -static void -SDL_DrawLine2(SDL_Surface * dst, int x1, int y1, int x2, int y2, Uint32 color, - SDL_bool draw_end) -{ - if (y1 == y2) { - HLINE(Uint16, DRAW_FASTSETPIXEL2, draw_end); - } else if (x1 == x2) { - VLINE(Uint16, DRAW_FASTSETPIXEL2, draw_end); - } else if (ABS(x1 - x2) == ABS(y1 - y2)) { - DLINE(Uint16, DRAW_FASTSETPIXEL2, draw_end); - } else { - Uint8 _r, _g, _b, _a; - const SDL_PixelFormat * fmt = dst->format; - SDL_GetRGBA(color, fmt, &_r, &_g, &_b, &_a); - if (fmt->Rmask == 0x7C00) { - AALINE(x1, y1, x2, y2, - DRAW_FASTSETPIXELXY2, DRAW_SETPIXELXY_BLEND_RGB555, - draw_end); - } else if (fmt->Rmask == 0xF800) { - AALINE(x1, y1, x2, y2, - DRAW_FASTSETPIXELXY2, DRAW_SETPIXELXY_BLEND_RGB565, - draw_end); - } else { - AALINE(x1, y1, x2, y2, - DRAW_FASTSETPIXELXY2, DRAW_SETPIXELXY2_BLEND_RGB, - draw_end); - } - } -} - -static void -SDL_DrawLine4(SDL_Surface * dst, int x1, int y1, int x2, int y2, Uint32 color, - SDL_bool draw_end) -{ - if (y1 == y2) { - HLINE(Uint32, DRAW_FASTSETPIXEL4, draw_end); - } else if (x1 == x2) { - VLINE(Uint32, DRAW_FASTSETPIXEL4, draw_end); - } else if (ABS(x1 - x2) == ABS(y1 - y2)) { - DLINE(Uint32, DRAW_FASTSETPIXEL4, draw_end); - } else { - Uint8 _r, _g, _b, _a; - const SDL_PixelFormat * fmt = dst->format; - SDL_GetRGBA(color, fmt, &_r, &_g, &_b, &_a); - if (fmt->Rmask == 0x00FF0000) { - if (!fmt->Amask) { - AALINE(x1, y1, x2, y2, - DRAW_FASTSETPIXELXY4, DRAW_SETPIXELXY_BLEND_RGB888, - draw_end); - } else { - AALINE(x1, y1, x2, y2, - DRAW_FASTSETPIXELXY4, DRAW_SETPIXELXY_BLEND_ARGB8888, - draw_end); - } - } else { - AALINE(x1, y1, x2, y2, - DRAW_FASTSETPIXELXY4, DRAW_SETPIXELXY4_BLEND_RGB, - draw_end); - } - } -} - -typedef void (*DrawLineFunc) (SDL_Surface * dst, - int x1, int y1, int x2, int y2, - Uint32 color, SDL_bool draw_end); - -static DrawLineFunc -SDL_CalculateDrawLineFunc(const SDL_PixelFormat * fmt) -{ - switch (fmt->BytesPerPixel) { - case 1: - if (fmt->BitsPerPixel < 8) { - break; - } - return SDL_DrawLine1; - case 2: - return SDL_DrawLine2; - case 4: - return SDL_DrawLine4; - } - return NULL; -} - -int -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; - } - - func = SDL_CalculateDrawLineFunc(dst->format); - if (!func) { - SDL_SetError("SDL_DrawLine(): Unsupported surface format"); - return -1; - } - - /* Perform clipping */ - /* FIXME: We don't actually want to clip, as it may change line slope */ - if (!SDL_IntersectRectAndLine(&dst->clip_rect, &x1, &y1, &x2, &y2)) { - return 0; - } - - func(dst, x1, y1, x2, y2, color, SDL_TRUE); - return 0; -} - -int -SDL_DrawLines(SDL_Surface * dst, const SDL_Point * points, int count, - Uint32 color) -{ - int i; - int x1, y1; - int x2, y2; - SDL_bool draw_end; - DrawLineFunc func; - - if (!dst) { - SDL_SetError("SDL_DrawLines(): Passed NULL destination surface"); - return -1; - } - - func = SDL_CalculateDrawLineFunc(dst->format); - if (!func) { - SDL_SetError("SDL_DrawLines(): Unsupported surface format"); - return -1; - } - - for (i = 1; i < count; ++i) { - x1 = points[i-1].x; - y1 = points[i-1].y; - x2 = points[i].x; - y2 = points[i].y; - - /* Perform clipping */ - /* FIXME: We don't actually want to clip, as it may change line slope */ - if (!SDL_IntersectRectAndLine(&dst->clip_rect, &x1, &y1, &x2, &y2)) { - continue; - } - - /* Draw the end if it was clipped */ - draw_end = (x2 != points[i].x || y2 != points[i].y); - - func(dst, x1, y1, x2, y2, color, draw_end); - } - if (points[0].x != points[count-1].x || points[0].y != points[count-1].y) { - SDL_DrawPoint(dst, points[count-1].x, points[count-1].y, color); - } - return 0; -} - -#endif /* !SDL_RENDER_DISABLED */ - -/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/SDL-mobile/src/render/software/SDL_drawline.h b/src/SDL-mobile/src/render/software/SDL_drawline.h deleted file mode 100644 index 9d8a5a4ee..000000000 --- a/src/SDL-mobile/src/render/software/SDL_drawline.h +++ /dev/null @@ -1,27 +0,0 @@ -/* - Simple DirectMedia Layer - Copyright (C) 1997-2012 Sam Lantinga - - 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" - - -extern int SDL_DrawLine(SDL_Surface * dst, int x1, int y1, int x2, int y2, Uint32 color); -extern int SDL_DrawLines(SDL_Surface * dst, const SDL_Point * points, int count, Uint32 color); - -/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/SDL-mobile/src/render/software/SDL_drawpoint.c b/src/SDL-mobile/src/render/software/SDL_drawpoint.c deleted file mode 100644 index 8c19c618b..000000000 --- a/src/SDL-mobile/src/render/software/SDL_drawpoint.c +++ /dev/null @@ -1,120 +0,0 @@ -/* - Simple DirectMedia Layer - Copyright (C) 1997-2012 Sam Lantinga - - 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_RENDER_DISABLED - -#include "SDL_draw.h" -#include "SDL_drawpoint.h" - - -int -SDL_DrawPoint(SDL_Surface * dst, int x, int y, Uint32 color) -{ - if (!dst) { - SDL_SetError("Passed NULL destination surface"); - return -1; - } - - /* This function doesn't work on surfaces < 8 bpp */ - if (dst->format->BitsPerPixel < 8) { - SDL_SetError("SDL_DrawPoint(): Unsupported surface format"); - return -1; - } - - /* Perform clipping */ - if (x < dst->clip_rect.x || y < dst->clip_rect.y || - x >= (dst->clip_rect.x + dst->clip_rect.w) || - y >= (dst->clip_rect.y + dst->clip_rect.h)) { - return 0; - } - - switch (dst->format->BytesPerPixel) { - case 1: - DRAW_FASTSETPIXELXY1(x, y); - break; - case 2: - DRAW_FASTSETPIXELXY2(x, y); - break; - case 3: - SDL_Unsupported(); - return -1; - case 4: - DRAW_FASTSETPIXELXY4(x, y); - break; - } - return 0; -} - -int -SDL_DrawPoints(SDL_Surface * dst, const SDL_Point * points, int count, - Uint32 color) -{ - int minx, miny; - int maxx, maxy; - int i; - int x, y; - - if (!dst) { - SDL_SetError("Passed NULL destination surface"); - return -1; - } - - /* This function doesn't work on surfaces < 8 bpp */ - if (dst->format->BitsPerPixel < 8) { - SDL_SetError("SDL_DrawPoints(): Unsupported surface format"); - return -1; - } - - minx = dst->clip_rect.x; - maxx = dst->clip_rect.x + dst->clip_rect.w - 1; - miny = dst->clip_rect.y; - maxy = dst->clip_rect.y + dst->clip_rect.h - 1; - - for (i = 0; i < count; ++i) { - x = points[i].x; - y = points[i].y; - - if (x < minx || x > maxx || y < miny || y > maxy) { - continue; - } - - switch (dst->format->BytesPerPixel) { - case 1: - DRAW_FASTSETPIXELXY1(x, y); - break; - case 2: - DRAW_FASTSETPIXELXY2(x, y); - break; - case 3: - SDL_Unsupported(); - return -1; - case 4: - DRAW_FASTSETPIXELXY4(x, y); - break; - } - } - return 0; -} - -#endif /* !SDL_RENDER_DISABLED */ - -/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/SDL-mobile/src/render/software/SDL_drawpoint.h b/src/SDL-mobile/src/render/software/SDL_drawpoint.h deleted file mode 100644 index 56f857538..000000000 --- a/src/SDL-mobile/src/render/software/SDL_drawpoint.h +++ /dev/null @@ -1,27 +0,0 @@ -/* - Simple DirectMedia Layer - Copyright (C) 1997-2012 Sam Lantinga - - 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" - - -extern int SDL_DrawPoint(SDL_Surface * dst, int x, int y, Uint32 color); -extern int SDL_DrawPoints(SDL_Surface * dst, const SDL_Point * points, int count, Uint32 color); - -/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/SDL-mobile/src/render/software/SDL_render_sw.c b/src/SDL-mobile/src/render/software/SDL_render_sw.c deleted file mode 100644 index 4f4d38fb5..000000000 --- a/src/SDL-mobile/src/render/software/SDL_render_sw.c +++ /dev/null @@ -1,666 +0,0 @@ -/* - Simple DirectMedia Layer - Copyright (C) 1997-2012 Sam Lantinga - - 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_RENDER_DISABLED - -#include "../SDL_sysrender.h" -#include "SDL_render_sw_c.h" -#include "SDL_hints.h" - -#include "SDL_draw.h" -#include "SDL_blendfillrect.h" -#include "SDL_blendline.h" -#include "SDL_blendpoint.h" -#include "SDL_drawline.h" -#include "SDL_drawpoint.h" -#include "SDL_rotate.h" - -/* SDL surface based renderer implementation */ - -static SDL_Renderer *SW_CreateRenderer(SDL_Window * window, Uint32 flags); -static void SW_WindowEvent(SDL_Renderer * renderer, - const SDL_WindowEvent *event); -static int SW_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture); -static int SW_SetTextureColorMod(SDL_Renderer * renderer, - SDL_Texture * texture); -static int SW_SetTextureAlphaMod(SDL_Renderer * renderer, - SDL_Texture * texture); -static int SW_SetTextureBlendMode(SDL_Renderer * renderer, - SDL_Texture * texture); -static int SW_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture, - const SDL_Rect * rect, const void *pixels, - int pitch); -static int SW_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture, - const SDL_Rect * rect, void **pixels, int *pitch); -static void SW_UnlockTexture(SDL_Renderer * renderer, SDL_Texture * texture); -static int SW_SetRenderTarget(SDL_Renderer * renderer, SDL_Texture * texture); -static int SW_UpdateViewport(SDL_Renderer * renderer); -static int SW_RenderClear(SDL_Renderer * renderer); -static int SW_RenderDrawPoints(SDL_Renderer * renderer, - const SDL_Point * points, int count); -static int SW_RenderDrawLines(SDL_Renderer * renderer, - const SDL_Point * points, int count); -static int SW_RenderFillRects(SDL_Renderer * renderer, - const SDL_Rect * rects, int count); -static int SW_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture, - const SDL_Rect * srcrect, const SDL_Rect * dstrect); -static int SW_RenderCopyEx(SDL_Renderer * renderer, SDL_Texture * texture, - const SDL_Rect * srcrect, const SDL_Rect * dstrect, - const double angle, const SDL_Point * center, const SDL_RendererFlip flip); -static int SW_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect, - Uint32 format, void * pixels, int pitch); -static void SW_RenderPresent(SDL_Renderer * renderer); -static void SW_DestroyTexture(SDL_Renderer * renderer, SDL_Texture * texture); -static void SW_DestroyRenderer(SDL_Renderer * renderer); - - -SDL_RenderDriver SW_RenderDriver = { - SW_CreateRenderer, - { - "software", - SDL_RENDERER_SOFTWARE | SDL_RENDERER_TARGETTEXTURE, - 8, - { - SDL_PIXELFORMAT_RGB555, - SDL_PIXELFORMAT_RGB565, - SDL_PIXELFORMAT_RGB888, - SDL_PIXELFORMAT_BGR888, - SDL_PIXELFORMAT_ARGB8888, - SDL_PIXELFORMAT_RGBA8888, - SDL_PIXELFORMAT_ABGR8888, - SDL_PIXELFORMAT_BGRA8888 - }, - 0, - 0} -}; - -typedef struct -{ - SDL_Surface *surface; - SDL_Surface *window; -} SW_RenderData; - - -static SDL_Surface * -SW_ActivateRenderer(SDL_Renderer * renderer) -{ - SW_RenderData *data = (SW_RenderData *) renderer->driverdata; - - if (!data->surface) { - data->surface = data->window; - } - if (!data->surface) { - data->surface = data->window = SDL_GetWindowSurface(renderer->window); - - SW_UpdateViewport(renderer); - } - return data->surface; -} - -SDL_Renderer * -SW_CreateRendererForSurface(SDL_Surface * surface) -{ - SDL_Renderer *renderer; - SW_RenderData *data; - - if (!surface) { - SDL_SetError("Can't create renderer for NULL surface"); - return NULL; - } - - renderer = (SDL_Renderer *) SDL_calloc(1, sizeof(*renderer)); - if (!renderer) { - SDL_OutOfMemory(); - return NULL; - } - - data = (SW_RenderData *) SDL_calloc(1, sizeof(*data)); - if (!data) { - SW_DestroyRenderer(renderer); - SDL_OutOfMemory(); - return NULL; - } - data->surface = surface; - - renderer->WindowEvent = SW_WindowEvent; - renderer->CreateTexture = SW_CreateTexture; - renderer->SetTextureColorMod = SW_SetTextureColorMod; - renderer->SetTextureAlphaMod = SW_SetTextureAlphaMod; - renderer->SetTextureBlendMode = SW_SetTextureBlendMode; - renderer->UpdateTexture = SW_UpdateTexture; - renderer->LockTexture = SW_LockTexture; - renderer->UnlockTexture = SW_UnlockTexture; - renderer->SetRenderTarget = SW_SetRenderTarget; - renderer->UpdateViewport = SW_UpdateViewport; - renderer->RenderClear = SW_RenderClear; - renderer->RenderDrawPoints = SW_RenderDrawPoints; - renderer->RenderDrawLines = SW_RenderDrawLines; - renderer->RenderFillRects = SW_RenderFillRects; - renderer->RenderCopy = SW_RenderCopy; - renderer->RenderCopyEx = SW_RenderCopyEx; - renderer->RenderReadPixels = SW_RenderReadPixels; - renderer->RenderPresent = SW_RenderPresent; - renderer->DestroyTexture = SW_DestroyTexture; - renderer->DestroyRenderer = SW_DestroyRenderer; - renderer->info = SW_RenderDriver.info; - renderer->driverdata = data; - - SW_ActivateRenderer(renderer); - - return renderer; -} - -SDL_Renderer * -SW_CreateRenderer(SDL_Window * window, Uint32 flags) -{ - SDL_Surface *surface; - - surface = SDL_GetWindowSurface(window); - if (!surface) { - return NULL; - } - return SW_CreateRendererForSurface(surface); -} - -static void -SW_WindowEvent(SDL_Renderer * renderer, const SDL_WindowEvent *event) -{ - SW_RenderData *data = (SW_RenderData *) renderer->driverdata; - - if (event->event == SDL_WINDOWEVENT_SIZE_CHANGED) { - data->surface = NULL; - data->window = NULL; - } -} - -static int -SW_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture) -{ - int bpp; - Uint32 Rmask, Gmask, Bmask, Amask; - - if (!SDL_PixelFormatEnumToMasks - (texture->format, &bpp, &Rmask, &Gmask, &Bmask, &Amask)) { - SDL_SetError("Unknown texture format"); - return -1; - } - - texture->driverdata = - SDL_CreateRGBSurface(0, texture->w, texture->h, bpp, Rmask, Gmask, - Bmask, Amask); - SDL_SetSurfaceColorMod(texture->driverdata, texture->r, texture->g, - texture->b); - SDL_SetSurfaceAlphaMod(texture->driverdata, texture->a); - SDL_SetSurfaceBlendMode(texture->driverdata, texture->blendMode); - - if (texture->access == SDL_TEXTUREACCESS_STATIC) { - SDL_SetSurfaceRLE(texture->driverdata, 1); - } - - if (!texture->driverdata) { - return -1; - } - return 0; -} - -static int -SW_SetTextureColorMod(SDL_Renderer * renderer, SDL_Texture * texture) -{ - SDL_Surface *surface = (SDL_Surface *) texture->driverdata; - return SDL_SetSurfaceColorMod(surface, texture->r, texture->g, - texture->b); -} - -static int -SW_SetTextureAlphaMod(SDL_Renderer * renderer, SDL_Texture * texture) -{ - SDL_Surface *surface = (SDL_Surface *) texture->driverdata; - return SDL_SetSurfaceAlphaMod(surface, texture->a); -} - -static int -SW_SetTextureBlendMode(SDL_Renderer * renderer, SDL_Texture * texture) -{ - SDL_Surface *surface = (SDL_Surface *) texture->driverdata; - return SDL_SetSurfaceBlendMode(surface, texture->blendMode); -} - -static int -SW_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture, - const SDL_Rect * rect, const void *pixels, int pitch) -{ - SDL_Surface *surface = (SDL_Surface *) texture->driverdata; - Uint8 *src, *dst; - int row; - size_t length; - - if(SDL_MUSTLOCK(surface)) - SDL_LockSurface(surface); - src = (Uint8 *) pixels; - dst = (Uint8 *) surface->pixels + - rect->y * surface->pitch + - rect->x * surface->format->BytesPerPixel; - length = rect->w * surface->format->BytesPerPixel; - for (row = 0; row < rect->h; ++row) { - SDL_memcpy(dst, src, length); - src += pitch; - dst += surface->pitch; - } - if(SDL_MUSTLOCK(surface)) - SDL_UnlockSurface(surface); - return 0; -} - -static int -SW_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture, - const SDL_Rect * rect, void **pixels, int *pitch) -{ - SDL_Surface *surface = (SDL_Surface *) texture->driverdata; - - *pixels = - (void *) ((Uint8 *) surface->pixels + rect->y * surface->pitch + - rect->x * surface->format->BytesPerPixel); - *pitch = surface->pitch; - return 0; -} - -static void -SW_UnlockTexture(SDL_Renderer * renderer, SDL_Texture * texture) -{ -} - -static int -SW_SetRenderTarget(SDL_Renderer * renderer, SDL_Texture * texture) -{ - SW_RenderData *data = (SW_RenderData *) renderer->driverdata; - - if (texture ) { - data->surface = (SDL_Surface *) texture->driverdata; - } else { - data->surface = data->window; - } - return 0; -} - -static int -SW_UpdateViewport(SDL_Renderer * renderer) -{ - SW_RenderData *data = (SW_RenderData *) renderer->driverdata; - SDL_Surface *surface = data->surface; - - if (!surface) { - /* We'll update the viewport after we recreate the surface */ - return 0; - } - - if (!renderer->viewport.w && !renderer->viewport.h) { - /* There may be no window, so update the viewport directly */ - renderer->viewport.w = surface->w; - renderer->viewport.h = surface->h; - } - SDL_SetClipRect(data->surface, &renderer->viewport); - return 0; -} - -static int -SW_RenderClear(SDL_Renderer * renderer) -{ - SDL_Surface *surface = SW_ActivateRenderer(renderer); - Uint32 color; - SDL_Rect clip_rect; - - if (!surface) { - return -1; - } - - color = SDL_MapRGBA(surface->format, - renderer->r, renderer->g, renderer->b, renderer->a); - - /* By definition the clear ignores the clip rect */ - clip_rect = surface->clip_rect; - SDL_SetClipRect(surface, NULL); - SDL_FillRect(surface, NULL, color); - SDL_SetClipRect(surface, &clip_rect); - return 0; -} - -static int -SW_RenderDrawPoints(SDL_Renderer * renderer, const SDL_Point * points, - int count) -{ - SDL_Surface *surface = SW_ActivateRenderer(renderer); - SDL_Point *temp = NULL; - int status; - - if (!surface) { - return -1; - } - - if (renderer->viewport.x || renderer->viewport.y) { - int i; - int x = renderer->viewport.x; - int y = renderer->viewport.y; - - temp = SDL_stack_alloc(SDL_Point, count); - for (i = 0; i < count; ++i) { - temp[i].x = x + points[i].x; - temp[i].y = y + points[i].x; - } - points = temp; - } - - /* Draw the points! */ - if (renderer->blendMode == SDL_BLENDMODE_NONE) { - Uint32 color = SDL_MapRGBA(surface->format, - renderer->r, renderer->g, renderer->b, - renderer->a); - - status = SDL_DrawPoints(surface, points, count, color); - } else { - status = SDL_BlendPoints(surface, points, count, - renderer->blendMode, - renderer->r, renderer->g, renderer->b, - renderer->a); - } - - if (temp) { - SDL_stack_free(temp); - } - return status; -} - -static int -SW_RenderDrawLines(SDL_Renderer * renderer, const SDL_Point * points, - int count) -{ - SDL_Surface *surface = SW_ActivateRenderer(renderer); - SDL_Point *temp = NULL; - int status; - - if (!surface) { - return -1; - } - - if (renderer->viewport.x || renderer->viewport.y) { - int i; - int x = renderer->viewport.x; - int y = renderer->viewport.y; - - temp = SDL_stack_alloc(SDL_Point, count); - for (i = 0; i < count; ++i) { - temp[i].x = x + points[i].x; - temp[i].y = y + points[i].y; - } - points = temp; - } - - /* Draw the lines! */ - if (renderer->blendMode == SDL_BLENDMODE_NONE) { - Uint32 color = SDL_MapRGBA(surface->format, - renderer->r, renderer->g, renderer->b, - renderer->a); - - status = SDL_DrawLines(surface, points, count, color); - } else { - status = SDL_BlendLines(surface, points, count, - renderer->blendMode, - renderer->r, renderer->g, renderer->b, - renderer->a); - } - - if (temp) { - SDL_stack_free(temp); - } - return status; -} - -static int -SW_RenderFillRects(SDL_Renderer * renderer, const SDL_Rect * rects, int count) -{ - SDL_Surface *surface = SW_ActivateRenderer(renderer); - SDL_Rect *temp = NULL; - int status; - - if (!surface) { - return -1; - } - - if (renderer->viewport.x || renderer->viewport.y) { - int i; - int x = renderer->viewport.x; - int y = renderer->viewport.y; - - temp = SDL_stack_alloc(SDL_Rect, count); - for (i = 0; i < count; ++i) { - temp[i].x = x + rects[i].x; - temp[i].y = y + rects[i].y; - temp[i].w = rects[i].w; - temp[i].h = rects[i].h; - } - rects = temp; - } - - if (renderer->blendMode == SDL_BLENDMODE_NONE) { - Uint32 color = SDL_MapRGBA(surface->format, - renderer->r, renderer->g, renderer->b, - renderer->a); - status = SDL_FillRects(surface, rects, count, color); - } else { - status = SDL_BlendFillRects(surface, rects, count, - renderer->blendMode, - renderer->r, renderer->g, renderer->b, - renderer->a); - } - - if (temp) { - SDL_stack_free(temp); - } - return status; -} - -static int -SW_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture, - const SDL_Rect * srcrect, const SDL_Rect * dstrect) -{ - SDL_Surface *surface = SW_ActivateRenderer(renderer); - SDL_Surface *src = (SDL_Surface *) texture->driverdata; - SDL_Rect final_rect = *dstrect; - - if (!surface) { - return -1; - } - - if (renderer->viewport.x || renderer->viewport.y) { - final_rect.x += renderer->viewport.x; - final_rect.y += renderer->viewport.y; - } - if ( srcrect->w == final_rect.w && srcrect->h == final_rect.h ) { - return SDL_BlitSurface(src, srcrect, surface, &final_rect); - } else { - return SDL_BlitScaled(src, srcrect, surface, &final_rect); - } -} - -static int -GetScaleQuality(void) -{ - const char *hint = SDL_GetHint(SDL_HINT_RENDER_SCALE_QUALITY); - - if (!hint || *hint == '0' || SDL_strcasecmp(hint, "nearest") == 0) { - return 0; - } else { - return 1; - } -} - -static int -SW_RenderCopyEx(SDL_Renderer * renderer, SDL_Texture * texture, - const SDL_Rect * srcrect, const SDL_Rect * dstrect, - const double angle, const SDL_Point * center, const SDL_RendererFlip flip) -{ - SDL_Surface *surface = SW_ActivateRenderer(renderer); - SDL_Surface *src = (SDL_Surface *) texture->driverdata; - SDL_Rect final_rect = *dstrect, tmp_rect; - SDL_Surface *surface_rotated, *surface_scaled; - Uint32 colorkey; - int retval, dstwidth, dstheight, abscenterx, abscentery; - double cangle, sangle, px, py, p1x, p1y, p2x, p2y, p3x, p3y, p4x, p4y; - - if (!surface) { - return -1; - } - - if (renderer->viewport.x || renderer->viewport.y) { - final_rect.x += renderer->viewport.x; - final_rect.y += renderer->viewport.y; - } - - surface_scaled = SDL_CreateRGBSurface(SDL_SWSURFACE, final_rect.w, final_rect.h, src->format->BitsPerPixel, - src->format->Rmask, src->format->Gmask, - src->format->Bmask, src->format->Amask ); - SDL_GetColorKey(src, &colorkey); - SDL_SetColorKey(surface_scaled, SDL_TRUE, colorkey); - tmp_rect = final_rect; - tmp_rect.x = 0; - tmp_rect.y = 0; - if (surface_scaled) { - retval = SDL_BlitScaled(src, srcrect, surface_scaled, &tmp_rect); - if (!retval) { - _rotozoomSurfaceSizeTrig(tmp_rect.w, tmp_rect.h, -angle, &dstwidth, &dstheight, &cangle, &sangle); - surface_rotated = _rotateSurface(surface_scaled, -angle, dstwidth/2, dstheight/2, GetScaleQuality(), flip & SDL_FLIP_HORIZONTAL, flip & SDL_FLIP_VERTICAL, dstwidth, dstheight, cangle, sangle); - if(surface_rotated) { - /* Find out where the new origin is by rotating the four final_rect points around the center and then taking the extremes */ - abscenterx = final_rect.x + center->x; - abscentery = final_rect.y + center->y; - /* Compensate the angle inversion to match the behaviour of the other backends */ - sangle = -sangle; - - /* Top Left */ - px = final_rect.x - abscenterx; - py = final_rect.y - abscentery; - p1x = px * cangle - py * sangle + abscenterx; - p1y = px * sangle + py * cangle + abscentery; - - /* Top Right */ - px = final_rect.x + final_rect.w - abscenterx; - py = final_rect.y - abscentery; - p2x = px * cangle - py * sangle + abscenterx; - p2y = px * sangle + py * cangle + abscentery; - - /* Bottom Left */ - px = final_rect.x - abscenterx; - py = final_rect.y + final_rect.h - abscentery; - p3x = px * cangle - py * sangle + abscenterx; - p3y = px * sangle + py * cangle + abscentery; - - /* Bottom Right */ - px = final_rect.x + final_rect.w - abscenterx; - py = final_rect.y + final_rect.h - abscentery; - p4x = px * cangle - py * sangle + abscenterx; - p4y = px * sangle + py * cangle + abscentery; - - tmp_rect.x = (int)MIN(MIN(p1x, p2x), MIN(p3x, p4x)); - tmp_rect.y = (int)MIN(MIN(p1y, p2y), MIN(p3y, p4y)); - tmp_rect.w = dstwidth; - tmp_rect.h = dstheight; - - retval = SDL_BlitSurface(surface_rotated, NULL, surface, &tmp_rect); - SDL_FreeSurface(surface_scaled); - SDL_FreeSurface(surface_rotated); - return retval; - } - } - return retval; - } - - return -1; -} - -static int -SW_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect, - Uint32 format, void * pixels, int pitch) -{ - SDL_Surface *surface = SW_ActivateRenderer(renderer); - Uint32 src_format; - void *src_pixels; - SDL_Rect final_rect; - - if (!surface) { - return -1; - } - - if (renderer->viewport.x || renderer->viewport.y) { - final_rect.x = renderer->viewport.x + rect->x; - final_rect.y = renderer->viewport.y + rect->y; - final_rect.w = rect->w; - final_rect.h = rect->h; - rect = &final_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; - } - - src_format = surface->format->format; - src_pixels = (void*)((Uint8 *) surface->pixels + - rect->y * surface->pitch + - rect->x * surface->format->BytesPerPixel); - - return SDL_ConvertPixels(rect->w, rect->h, - src_format, src_pixels, surface->pitch, - format, pixels, pitch); -} - -static void -SW_RenderPresent(SDL_Renderer * renderer) -{ - SDL_Window *window = renderer->window; - - if (window) { - SDL_UpdateWindowSurface(window); - } -} - -static void -SW_DestroyTexture(SDL_Renderer * renderer, SDL_Texture * texture) -{ - SDL_Surface *surface = (SDL_Surface *) texture->driverdata; - - SDL_FreeSurface(surface); -} - -static void -SW_DestroyRenderer(SDL_Renderer * renderer) -{ - SW_RenderData *data = (SW_RenderData *) renderer->driverdata; - - if (data) { - SDL_free(data); - } - SDL_free(renderer); -} - -#endif /* !SDL_RENDER_DISABLED */ - -/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/SDL-mobile/src/render/software/SDL_render_sw_c.h b/src/SDL-mobile/src/render/software/SDL_render_sw_c.h deleted file mode 100644 index e6218eeda..000000000 --- a/src/SDL-mobile/src/render/software/SDL_render_sw_c.h +++ /dev/null @@ -1,24 +0,0 @@ -/* - Simple DirectMedia Layer - Copyright (C) 1997-2012 Sam Lantinga - - 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. -*/ - -extern SDL_Renderer * SW_CreateRendererForSurface(SDL_Surface * surface); - -/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/SDL-mobile/src/render/software/SDL_rotate.c b/src/SDL-mobile/src/render/software/SDL_rotate.c deleted file mode 100644 index 2eae0393f..000000000 --- a/src/SDL-mobile/src/render/software/SDL_rotate.c +++ /dev/null @@ -1,499 +0,0 @@ -/* - -SDL_rotate.c: rotates 32bit or 8bit surfaces - -Shamelessly stolen from SDL_gfx by Andreas Schiffler. Original copyright follows: - -Copyright (C) 2001-2011 Andreas Schiffler - -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. - -Andreas Schiffler -- aschiffler at ferzkopp dot net - -*/ -#include "SDL_config.h" - -#ifdef WIN32 -#include -#endif - -#include -#include - -#include "SDL.h" -#include "SDL_rotate.h" - -/* ---- Internally used structures */ - -/*! -\brief A 32 bit RGBA pixel. -*/ -typedef struct tColorRGBA { - Uint8 r; - Uint8 g; - Uint8 b; - Uint8 a; -} tColorRGBA; - -/*! -\brief A 8bit Y/palette pixel. -*/ -typedef struct tColorY { - Uint8 y; -} tColorY; - -/*! -\brief Returns maximum of two numbers a and b. -*/ -#define MAX(a,b) (((a) > (b)) ? (a) : (b)) - -/*! -\brief Number of guard rows added to destination surfaces. - -This is a simple but effective workaround for observed issues. -These rows allocate extra memory and are then hidden from the surface. -Rows are added to the end of destination surfaces when they are allocated. -This catches any potential overflows which seem to happen with -just the right src image dimensions and scale/rotation and can lead -to a situation where the program can segfault. -*/ -#define GUARD_ROWS (2) - -/*! -\brief Lower limit of absolute zoom factor or rotation degrees. -*/ -#define VALUE_LIMIT 0.001 - -/*! -\brief Returns colorkey info for a surface -*/ -Uint32 _colorkey(SDL_Surface *src) -{ - Uint32 key = 0; - SDL_GetColorKey(src, &key); - return key; -} - - -/*! -\brief Internal target surface sizing function for rotations with trig result return. - -\param width The source surface width. -\param height The source surface height. -\param angle The angle to rotate in degrees. -\param dstwidth The calculated width of the destination surface. -\param dstheight The calculated height of the destination surface. -\param cangle The sine of the angle -\param sangle The cosine of the angle - -*/ -void _rotozoomSurfaceSizeTrig(int width, int height, double angle, - int *dstwidth, int *dstheight, - double *cangle, double *sangle) -{ - double x, y, cx, cy, sx, sy; - double radangle; - int dstwidthhalf, dstheighthalf; - - /* - * Determine destination width and height by rotating a centered source box - */ - radangle = angle * (M_PI / 180.0); - *sangle = SDL_sin(radangle); - *cangle = SDL_cos(radangle); - x = (double)(width / 2); - y = (double)(height / 2); - cx = *cangle * x; - cy = *cangle * y; - sx = *sangle * x; - sy = *sangle * y; - - dstwidthhalf = MAX((int) - SDL_ceil(MAX(MAX(MAX(SDL_fabs(cx + sy), SDL_fabs(cx - sy)), SDL_fabs(-cx + sy)), SDL_fabs(-cx - sy))), 1); - dstheighthalf = MAX((int) - SDL_ceil(MAX(MAX(MAX(SDL_fabs(sx + cy), SDL_fabs(sx - cy)), SDL_fabs(-sx + cy)), SDL_fabs(-sx - cy))), 1); - *dstwidth = 2 * dstwidthhalf; - *dstheight = 2 * dstheighthalf; -} - - -/*! -\brief Internal 32 bit rotozoomer with optional anti-aliasing. - -Rotates and zooms 32 bit RGBA/ABGR 'src' surface to 'dst' surface based on the control -parameters by scanning the destination surface and applying optionally anti-aliasing -by bilinear interpolation. -Assumes src and dst surfaces are of 32 bit depth. -Assumes dst surface was allocated with the correct dimensions. - -\param src Source surface. -\param dst Destination surface. -\param cx Horizontal center coordinate. -\param cy Vertical center coordinate. -\param isin Integer version of sine of angle. -\param icos Integer version of cosine of angle. -\param flipx Flag indicating horizontal mirroring should be applied. -\param flipy Flag indicating vertical mirroring should be applied. -\param smooth Flag indicating anti-aliasing should be used. -*/ -void _transformSurfaceRGBA(SDL_Surface * src, SDL_Surface * dst, int cx, int cy, int isin, int icos, int flipx, int flipy, int smooth) -{ - int x, y, t1, t2, dx, dy, xd, yd, sdx, sdy, ax, ay, ex, ey, sw, sh; - tColorRGBA c00, c01, c10, c11, cswap; - tColorRGBA *pc, *sp; - int gap; - - /* - * Variable setup - */ - xd = ((src->w - dst->w) << 15); - yd = ((src->h - dst->h) << 15); - ax = (cx << 16) - (icos * cx); - ay = (cy << 16) - (isin * cx); - sw = src->w - 1; - sh = src->h - 1; - pc = (tColorRGBA*) dst->pixels; - gap = dst->pitch - dst->w * 4; - - /* - * Switch between interpolating and non-interpolating code - */ - if (smooth) { - for (y = 0; y < dst->h; y++) { - dy = cy - y; - sdx = (ax + (isin * dy)) + xd; - sdy = (ay - (icos * dy)) + yd; - for (x = 0; x < dst->w; x++) { - dx = (sdx >> 16); - dy = (sdy >> 16); - if (flipx) dx = sw - dx; - if (flipy) dy = sh - dy; - if ((dx > -1) && (dy > -1) && (dx < (src->w-1)) && (dy < (src->h-1))) { - sp = (tColorRGBA *)src->pixels;; - sp += ((src->pitch/4) * dy); - sp += dx; - c00 = *sp; - sp += 1; - c01 = *sp; - sp += (src->pitch/4); - c11 = *sp; - sp -= 1; - c10 = *sp; - if (flipx) { - cswap = c00; c00=c01; c01=cswap; - cswap = c10; c10=c11; c11=cswap; - } - if (flipy) { - cswap = c00; c00=c10; c10=cswap; - cswap = c01; c01=c11; c11=cswap; - } - /* - * Interpolate colors - */ - ex = (sdx & 0xffff); - ey = (sdy & 0xffff); - t1 = ((((c01.r - c00.r) * ex) >> 16) + c00.r) & 0xff; - t2 = ((((c11.r - c10.r) * ex) >> 16) + c10.r) & 0xff; - pc->r = (((t2 - t1) * ey) >> 16) + t1; - t1 = ((((c01.g - c00.g) * ex) >> 16) + c00.g) & 0xff; - t2 = ((((c11.g - c10.g) * ex) >> 16) + c10.g) & 0xff; - pc->g = (((t2 - t1) * ey) >> 16) + t1; - t1 = ((((c01.b - c00.b) * ex) >> 16) + c00.b) & 0xff; - t2 = ((((c11.b - c10.b) * ex) >> 16) + c10.b) & 0xff; - pc->b = (((t2 - t1) * ey) >> 16) + t1; - t1 = ((((c01.a - c00.a) * ex) >> 16) + c00.a) & 0xff; - t2 = ((((c11.a - c10.a) * ex) >> 16) + c10.a) & 0xff; - pc->a = (((t2 - t1) * ey) >> 16) + t1; - } - sdx += icos; - sdy += isin; - pc++; - } - pc = (tColorRGBA *) ((Uint8 *) pc + gap); - } - } else { - for (y = 0; y < dst->h; y++) { - dy = cy - y; - sdx = (ax + (isin * dy)) + xd; - sdy = (ay - (icos * dy)) + yd; - for (x = 0; x < dst->w; x++) { - dx = (short) (sdx >> 16); - dy = (short) (sdy >> 16); - if (flipx) dx = (src->w-1)-dx; - if (flipy) dy = (src->h-1)-dy; - if ((dx >= 0) && (dy >= 0) && (dx < src->w) && (dy < src->h)) { - sp = (tColorRGBA *) ((Uint8 *) src->pixels + src->pitch * dy); - sp += dx; - *pc = *sp; - } - sdx += icos; - sdy += isin; - pc++; - } - pc = (tColorRGBA *) ((Uint8 *) pc + gap); - } - } -} - -/*! - -\brief Rotates and zooms 8 bit palette/Y 'src' surface to 'dst' surface without smoothing. - -Rotates and zooms 8 bit RGBA/ABGR 'src' surface to 'dst' surface based on the control -parameters by scanning the destination surface. -Assumes src and dst surfaces are of 8 bit depth. -Assumes dst surface was allocated with the correct dimensions. - -\param src Source surface. -\param dst Destination surface. -\param cx Horizontal center coordinate. -\param cy Vertical center coordinate. -\param isin Integer version of sine of angle. -\param icos Integer version of cosine of angle. -\param flipx Flag indicating horizontal mirroring should be applied. -\param flipy Flag indicating vertical mirroring should be applied. -*/ -void transformSurfaceY(SDL_Surface * src, SDL_Surface * dst, int cx, int cy, int isin, int icos, int flipx, int flipy) -{ - int x, y, dx, dy, xd, yd, sdx, sdy, ax, ay; - tColorY *pc, *sp; - int gap; - - /* - * Variable setup - */ - xd = ((src->w - dst->w) << 15); - yd = ((src->h - dst->h) << 15); - ax = (cx << 16) - (icos * cx); - ay = (cy << 16) - (isin * cx); - pc = (tColorY*) dst->pixels; - gap = dst->pitch - dst->w; - /* - * Clear surface to colorkey - */ - SDL_memset(pc, (int)(_colorkey(src) & 0xff), dst->pitch * dst->h); - /* - * Iterate through destination surface - */ - for (y = 0; y < dst->h; y++) { - dy = cy - y; - sdx = (ax + (isin * dy)) + xd; - sdy = (ay - (icos * dy)) + yd; - for (x = 0; x < dst->w; x++) { - dx = (short) (sdx >> 16); - dy = (short) (sdy >> 16); - if (flipx) dx = (src->w-1)-dx; - if (flipy) dy = (src->h-1)-dy; - if ((dx >= 0) && (dy >= 0) && (dx < src->w) && (dy < src->h)) { - sp = (tColorY *) (src->pixels); - sp += (src->pitch * dy + dx); - *pc = *sp; - } - sdx += icos; - sdy += isin; - pc++; - } - pc += gap; - } -} - - - - -/*! -\brief Rotates and zooms a surface with different horizontal and vertival scaling factors and optional anti-aliasing. - -Rotates a 32bit or 8bit 'src' surface to newly created 'dst' surface. -'angle' is the rotation in degrees, 'centerx' and 'centery' the rotation center. If 'smooth' is set -then the destination 32bit surface is anti-aliased. If the surface is not 8bit -or 32bit RGBA/ABGR it will be converted into a 32bit RGBA format on the fly. - -\param src The surface to rotozoom. -\param angle The angle to rotate in degrees. -\param centerx The horizontal coordinate of the center of rotation -\param zoomy The vertical coordinate of the center of rotation -\param smooth Antialiasing flag; set to SMOOTHING_ON to enable. -\param flipx Set to 1 to flip the image horizontally -\param flipy Set to 1 to flip the image vertically -\param dstwidth The destination surface width -\param dstheight The destination surface height -\param cangle The angle cosine -\param sangle The angle sine -\return The new rotated surface. - -*/ - -SDL_Surface *_rotateSurface(SDL_Surface * src, double angle, int centerx, int centery, int smooth, int flipx, int flipy, int dstwidth, int dstheight, double cangle, double sangle) -{ - SDL_Surface *rz_src; - SDL_Surface *rz_dst; - int is32bit; - int i, src_converted; - Uint8 r,g,b; - Uint32 colorkey = 0; - int colorKeyAvailable = 0; - double sangleinv, cangleinv; - - /* - * Sanity check - */ - if (src == NULL) - return (NULL); - - if (src->flags & SDL_TRUE/*SDL_SRCCOLORKEY*/) - { - colorkey = _colorkey(src); - SDL_GetRGB(colorkey, src->format, &r, &g, &b); - colorKeyAvailable = 1; - } - /* - * Determine if source surface is 32bit or 8bit - */ - is32bit = (src->format->BitsPerPixel == 32); - if ((is32bit) || (src->format->BitsPerPixel == 8)) { - /* - * Use source surface 'as is' - */ - rz_src = src; - src_converted = 0; - } else { - /* - * New source surface is 32bit with a defined RGBA ordering - */ - rz_src = - SDL_CreateRGBSurface(SDL_SWSURFACE, src->w, src->h, 32, -#if SDL_BYTEORDER == SDL_LIL_ENDIAN - 0x000000ff, 0x0000ff00, 0x00ff0000, 0xff000000 -#else - 0xff000000, 0x00ff0000, 0x0000ff00, 0x000000ff -#endif - ); - if(colorKeyAvailable) - SDL_SetColorKey(src, 0, 0); - - SDL_BlitSurface(src, NULL, rz_src, NULL); - - if(colorKeyAvailable) - SDL_SetColorKey(src, SDL_TRUE /*SDL_SRCCOLORKEY*/, colorkey); - src_converted = 1; - is32bit = 1; - } - - - /* Determine target size */ - //_rotozoomSurfaceSizeTrig(rz_src->w, rz_src->h, angle, &dstwidth, &dstheight, &cangle, &sangle); - - /* - * Calculate target factors from sin/cos and zoom - */ - sangleinv = sangle*65536.0; - cangleinv = cangle*65536.0; - - /* - * Alloc space to completely contain the rotated surface - */ - rz_dst = NULL; - if (is32bit) { - /* - * Target surface is 32bit with source RGBA/ABGR ordering - */ - rz_dst = - SDL_CreateRGBSurface(SDL_SWSURFACE, dstwidth, dstheight + GUARD_ROWS, 32, - rz_src->format->Rmask, rz_src->format->Gmask, - rz_src->format->Bmask, rz_src->format->Amask); - } else { - /* - * Target surface is 8bit - */ - rz_dst = SDL_CreateRGBSurface(SDL_SWSURFACE, dstwidth, dstheight + GUARD_ROWS, 8, 0, 0, 0, 0); - } - - /* Check target */ - if (rz_dst == NULL) - return NULL; - - /* Adjust for guard rows */ - rz_dst->h = dstheight; - - if (colorKeyAvailable == 1){ - colorkey = SDL_MapRGB(rz_dst->format, r, g, b); - - SDL_FillRect(rz_dst, NULL, colorkey ); - } - - /* - * Lock source surface - */ - if (SDL_MUSTLOCK(rz_src)) { - SDL_LockSurface(rz_src); - } - - /* - * Check which kind of surface we have - */ - if (is32bit) { - /* - * Call the 32bit transformation routine to do the rotation (using alpha) - */ - _transformSurfaceRGBA(rz_src, rz_dst, centerx, centery, - (int) (sangleinv), (int) (cangleinv), - flipx, flipy, - smooth); - /* - * Turn on source-alpha support - */ - //SDL_SetAlpha(rz_dst, SDL_SRCALPHA, 255); - SDL_SetColorKey(rz_dst, /*SDL_SRCCOLORKEY*/ SDL_TRUE | SDL_RLEACCEL, _colorkey(rz_src)); - } else { - /* - * Copy palette and colorkey info - */ - for (i = 0; i < rz_src->format->palette->ncolors; i++) { - rz_dst->format->palette->colors[i] = rz_src->format->palette->colors[i]; - } - rz_dst->format->palette->ncolors = rz_src->format->palette->ncolors; - /* - * Call the 8bit transformation routine to do the rotation - */ - transformSurfaceY(rz_src, rz_dst, centerx, centery, - (int) (sangleinv), (int) (cangleinv), - flipx, flipy); - SDL_SetColorKey(rz_dst, /*SDL_SRCCOLORKEY*/ SDL_TRUE | SDL_RLEACCEL, _colorkey(rz_src)); - } - /* - * Unlock source surface - */ - if (SDL_MUSTLOCK(rz_src)) { - SDL_UnlockSurface(rz_src); - } - - /* - * Cleanup temp surface - */ - if (src_converted) { - SDL_FreeSurface(rz_src); - } - - /* - * Return destination surface - */ - return (rz_dst); -} - diff --git a/src/SDL-mobile/src/render/software/SDL_rotate.h b/src/SDL-mobile/src/render/software/SDL_rotate.h deleted file mode 100644 index 26bb8ad1c..000000000 --- a/src/SDL-mobile/src/render/software/SDL_rotate.h +++ /dev/null @@ -1,7 +0,0 @@ -#ifndef MIN -#define MIN(a,b) (((a) < (b)) ? (a) : (b)) -#endif - -extern SDL_Surface *_rotateSurface(SDL_Surface * src, double angle, int centerx, int centery, int smooth, int flipx, int flipy, int dstwidth, int dstheight, double cangle, double sangle); -extern void _rotozoomSurfaceSizeTrig(int width, int height, double angle, int *dstwidth, int *dstheight, double *cangle, double *sangle); - diff --git a/src/SDL-mobile/src/stdlib/SDL_getenv.c b/src/SDL-mobile/src/stdlib/SDL_getenv.c deleted file mode 100644 index 6e6477bde..000000000 --- a/src/SDL-mobile/src/stdlib/SDL_getenv.c +++ /dev/null @@ -1,269 +0,0 @@ -/* - Simple DirectMedia Layer - Copyright (C) 1997-2012 Sam Lantinga - - 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" - -#include "SDL_stdinc.h" - -#ifndef HAVE_GETENV - -#if 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; - -/* Put a variable into the environment */ -int -SDL_setenv(const char *name, const char *value, int overwrite) -{ - if (!overwrite) { - char ch = 0; - const size_t len = GetEnvironmentVariableA(name, &ch, sizeof (ch)); - if (len > 0) { - return 0; /* asked not to overwrite existing value. */ - } - } - if (!SetEnvironmentVariableA(name, *value ? value : NULL)) { - return -1; - } - return 0; -} - -/* Retrieve a variable named "name" from the environment */ -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 /* 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) -{ - int added; - int len, i; - char **new_env; - char *new_variable; - - /* A little error checking */ - if (!name || !value) { - return (-1); - } - - /* See if it already exists */ - if (!overwrite && SDL_getenv(name)) { - return 0; - } - - /* Allocate memory for the variable */ - 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); - value = new_variable + SDL_strlen(name) + 1; - name = new_variable; - - /* Actually put it into the environment */ - added = 0; - i = 0; - if (SDL_env) { - /* Check to see if it's already there... */ - len = (value - name); - for (; SDL_env[i]; ++i) { - if (SDL_strncmp(SDL_env[i], name, len) == 0) { - break; - } - } - /* If we found it, just replace the entry */ - if (SDL_env[i]) { - SDL_free(SDL_env[i]); - SDL_env[i] = new_variable; - added = 1; - } - } - - /* Didn't find it in the environment, expand and add */ - if (!added) { - new_env = SDL_realloc(SDL_env, (i + 2) * sizeof(char *)); - if (new_env) { - SDL_env = new_env; - SDL_env[i++] = new_variable; - SDL_env[i++] = (char *) 0; - added = 1; - } else { - SDL_free(new_variable); - } - } - return (added ? 0 : -1); -} - -/* Retrieve a variable named "name" from the environment */ -char * -SDL_getenv(const char *name) -{ - int len, i; - char *value; - - value = (char *) 0; - if (SDL_env) { - len = SDL_strlen(name); - for (i = 0; SDL_env[i] && !value; ++i) { - if ((SDL_strncmp(SDL_env[i], name, len) == 0) && - (SDL_env[i][len] == '=')) { - value = &SDL_env[i][len + 1]; - } - } - } - 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 - - -#ifdef TEST_MAIN -#include - -int -main(int argc, char *argv[]) -{ - char *value; - - printf("Checking for non-existent variable... "); - fflush(stdout); - if (!SDL_getenv("EXISTS")) { - printf("okay\n"); - } else { - printf("failed\n"); - } - printf("Setting FIRST=VALUE1 in the environment... "); - fflush(stdout); - if (SDL_setenv("FIRST", "VALUE1", 0) == 0) { - printf("okay\n"); - } else { - printf("failed\n"); - } - printf("Getting FIRST from the environment... "); - fflush(stdout); - value = SDL_getenv("FIRST"); - if (value && (SDL_strcmp(value, "VALUE1") == 0)) { - printf("okay\n"); - } else { - printf("failed\n"); - } - printf("Setting SECOND=VALUE2 in the environment... "); - fflush(stdout); - if (SDL_setenv("SECOND", "VALUE2", 0) == 0) { - printf("okay\n"); - } else { - printf("failed\n"); - } - printf("Getting SECOND from the environment... "); - fflush(stdout); - value = SDL_getenv("SECOND"); - if (value && (SDL_strcmp(value, "VALUE2") == 0)) { - printf("okay\n"); - } else { - printf("failed\n"); - } - printf("Setting FIRST=NOVALUE in the environment... "); - fflush(stdout); - if (SDL_setenv("FIRST", "NOVALUE", 1) == 0) { - printf("okay\n"); - } else { - printf("failed\n"); - } - printf("Getting FIRST from the environment... "); - fflush(stdout); - value = SDL_getenv("FIRST"); - if (value && (SDL_strcmp(value, "NOVALUE") == 0)) { - printf("okay\n"); - } else { - printf("failed\n"); - } - printf("Checking for non-existent variable... "); - fflush(stdout); - if (!SDL_getenv("EXISTS")) { - printf("okay\n"); - } else { - printf("failed\n"); - } - return (0); -} -#endif /* TEST_MAIN */ - -/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/SDL-mobile/src/stdlib/SDL_iconv.c b/src/SDL-mobile/src/stdlib/SDL_iconv.c index e67be619b..b422e4a3e 100644 --- a/src/SDL-mobile/src/stdlib/SDL_iconv.c +++ b/src/SDL-mobile/src/stdlib/SDL_iconv.c @@ -25,46 +25,6 @@ #include "SDL_stdinc.h" #include "SDL_endian.h" -#ifdef HAVE_ICONV - -/* Depending on which standard the iconv() was implemented with, - iconv() may or may not use const char ** for the inbuf param. - If we get this wrong, it's just a warning, so no big deal. -*/ -#if defined(_XGP6) || defined(__APPLE__) || \ - (defined(__GLIBC__) && ((__GLIBC__ > 2) || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 2))) -#define ICONV_INBUF_NONCONST -#endif - -#include - -size_t -SDL_iconv(SDL_iconv_t cd, - const char **inbuf, size_t * inbytesleft, - char **outbuf, size_t * outbytesleft) -{ - size_t retCode; -#ifdef ICONV_INBUF_NONCONST - retCode = iconv(cd, (char **) inbuf, inbytesleft, outbuf, outbytesleft); -#else - retCode = iconv(cd, inbuf, inbytesleft, outbuf, outbytesleft); -#endif - if (retCode == (size_t) - 1) { - switch (errno) { - case E2BIG: - return SDL_ICONV_E2BIG; - case EILSEQ: - return SDL_ICONV_EILSEQ; - case EINVAL: - return SDL_ICONV_EINVAL; - default: - return SDL_ICONV_ERROR; - } - } - return retCode; -} - -#else /* Lots of useful information on Unicode at: http://www.cl.cam.ac.uk/~mgk25/unicode.html @@ -811,8 +771,6 @@ SDL_iconv_close(SDL_iconv_t cd) return 0; } -#endif /* !HAVE_ICONV */ - char * SDL_iconv_string(const char *tocode, const char *fromcode, const char *inbuf, size_t inbytesleft) diff --git a/src/SDL-mobile/src/stdlib/SDL_malloc.c b/src/SDL-mobile/src/stdlib/SDL_malloc.c deleted file mode 100644 index 142e5f59a..000000000 --- a/src/SDL-mobile/src/stdlib/SDL_malloc.c +++ /dev/null @@ -1,5236 +0,0 @@ -/* - Simple DirectMedia Layer - Copyright (C) 1997-2012 Sam Lantinga - - 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" - -/* This file contains portable memory management functions for SDL */ - -#include "SDL_stdinc.h" - -#ifndef HAVE_MALLOC - -#define LACKS_SYS_TYPES_H -#define LACKS_STDIO_H -#define LACKS_STRINGS_H -#define LACKS_STRING_H -#define LACKS_STDLIB_H -#define ABORT - -/* - This is a version (aka dlmalloc) of malloc/free/realloc written by - Doug Lea and released to the public domain, as explained at - http://creativecommons.org/licenses/publicdomain. Send questions, - comments, complaints, performance data, etc to dl@cs.oswego.edu - -* Version 2.8.3 Thu Sep 22 11:16:15 2005 Doug Lea (dl at gee) - - Note: There may be an updated version of this malloc obtainable at - ftp://gee.cs.oswego.edu/pub/misc/malloc.c - Check before installing! - -* Quickstart - - This library is all in one file to simplify the most common usage: - ftp it, compile it (-O3), and link it into another program. All of - the compile-time options default to reasonable values for use on - most platforms. You might later want to step through various - compile-time and dynamic tuning options. - - For convenience, an include file for code using this malloc is at: - ftp://gee.cs.oswego.edu/pub/misc/malloc-2.8.3.h - You don't really need this .h file unless you call functions not - defined in your system include files. The .h file contains only the - excerpts from this file needed for using this malloc on ANSI C/C++ - systems, so long as you haven't changed compile-time options about - naming and tuning parameters. If you do, then you can create your - own malloc.h that does include all settings by cutting at the point - indicated below. Note that you may already by default be using a C - library containing a malloc that is based on some version of this - malloc (for example in linux). You might still want to use the one - in this file to customize settings or to avoid overheads associated - with library versions. - -* Vital statistics: - - Supported pointer/size_t representation: 4 or 8 bytes - size_t MUST be an unsigned type of the same width as - pointers. (If you are using an ancient system that declares - size_t as a signed type, or need it to be a different width - than pointers, you can use a previous release of this malloc - (e.g. 2.7.2) supporting these.) - - Alignment: 8 bytes (default) - This suffices for nearly all current machines and C compilers. - However, you can define MALLOC_ALIGNMENT to be wider than this - if necessary (up to 128bytes), at the expense of using more space. - - Minimum overhead per allocated chunk: 4 or 8 bytes (if 4byte sizes) - 8 or 16 bytes (if 8byte sizes) - Each malloced chunk has a hidden word of overhead holding size - and status information, and additional cross-check word - if FOOTERS is defined. - - Minimum allocated size: 4-byte ptrs: 16 bytes (including overhead) - 8-byte ptrs: 32 bytes (including overhead) - - Even a request for zero bytes (i.e., malloc(0)) returns a - pointer to something of the minimum allocatable size. - The maximum overhead wastage (i.e., number of extra bytes - allocated than were requested in malloc) is less than or equal - to the minimum size, except for requests >= mmap_threshold that - are serviced via mmap(), where the worst case wastage is about - 32 bytes plus the remainder from a system page (the minimal - mmap unit); typically 4096 or 8192 bytes. - - Security: static-safe; optionally more or less - The "security" of malloc refers to the ability of malicious - code to accentuate the effects of errors (for example, freeing - space that is not currently malloc'ed or overwriting past the - ends of chunks) in code that calls malloc. This malloc - guarantees not to modify any memory locations below the base of - heap, i.e., static variables, even in the presence of usage - errors. The routines additionally detect most improper frees - and reallocs. All this holds as long as the static bookkeeping - for malloc itself is not corrupted by some other means. This - is only one aspect of security -- these checks do not, and - cannot, detect all possible programming errors. - - If FOOTERS is defined nonzero, then each allocated chunk - carries an additional check word to verify that it was malloced - from its space. These check words are the same within each - execution of a program using malloc, but differ across - executions, so externally crafted fake chunks cannot be - freed. This improves security by rejecting frees/reallocs that - could corrupt heap memory, in addition to the checks preventing - writes to statics that are always on. This may further improve - security at the expense of time and space overhead. (Note that - FOOTERS may also be worth using with MSPACES.) - - By default detected errors cause the program to abort (calling - "abort()"). You can override this to instead proceed past - errors by defining PROCEED_ON_ERROR. In this case, a bad free - has no effect, and a malloc that encounters a bad address - caused by user overwrites will ignore the bad address by - dropping pointers and indices to all known memory. This may - be appropriate for programs that should continue if at all - possible in the face of programming errors, although they may - run out of memory because dropped memory is never reclaimed. - - If you don't like either of these options, you can define - CORRUPTION_ERROR_ACTION and USAGE_ERROR_ACTION to do anything - else. And if if you are sure that your program using malloc has - no errors or vulnerabilities, you can define INSECURE to 1, - which might (or might not) provide a small performance improvement. - - Thread-safety: NOT thread-safe unless USE_LOCKS defined - When USE_LOCKS is defined, each public call to malloc, free, - etc is surrounded with either a pthread mutex or a win32 - spinlock (depending on WIN32). This is not especially fast, and - can be a major bottleneck. It is designed only to provide - minimal protection in concurrent environments, and to provide a - basis for extensions. If you are using malloc in a concurrent - program, consider instead using ptmalloc, which is derived from - a version of this malloc. (See http://www.malloc.de). - - System requirements: Any combination of MORECORE and/or MMAP/MUNMAP - This malloc can use unix sbrk or any emulation (invoked using - the CALL_MORECORE macro) and/or mmap/munmap or any emulation - (invoked using CALL_MMAP/CALL_MUNMAP) to get and release system - memory. On most unix systems, it tends to work best if both - MORECORE and MMAP are enabled. On Win32, it uses emulations - based on VirtualAlloc. It also uses common C library functions - like memset. - - Compliance: I believe it is compliant with the Single Unix Specification - (See http://www.unix.org). Also SVID/XPG, ANSI C, and probably - others as well. - -* Overview of algorithms - - This is not the fastest, most space-conserving, most portable, or - most tunable malloc ever written. However it is among the fastest - while also being among the most space-conserving, portable and - tunable. Consistent balance across these factors results in a good - general-purpose allocator for malloc-intensive programs. - - In most ways, this malloc is a best-fit allocator. Generally, it - chooses the best-fitting existing chunk for a request, with ties - broken in approximately least-recently-used order. (This strategy - normally maintains low fragmentation.) However, for requests less - than 256bytes, it deviates from best-fit when there is not an - exactly fitting available chunk by preferring to use space adjacent - to that used for the previous small request, as well as by breaking - ties in approximately most-recently-used order. (These enhance - locality of series of small allocations.) And for very large requests - (>= 256Kb by default), it relies on system memory mapping - facilities, if supported. (This helps avoid carrying around and - possibly fragmenting memory used only for large chunks.) - - All operations (except malloc_stats and mallinfo) have execution - times that are bounded by a constant factor of the number of bits in - a size_t, not counting any clearing in calloc or copying in realloc, - or actions surrounding MORECORE and MMAP that have times - proportional to the number of non-contiguous regions returned by - system allocation routines, which is often just 1. - - The implementation is not very modular and seriously overuses - macros. Perhaps someday all C compilers will do as good a job - inlining modular code as can now be done by brute-force expansion, - but now, enough of them seem not to. - - Some compilers issue a lot of warnings about code that is - dead/unreachable only on some platforms, and also about intentional - uses of negation on unsigned types. All known cases of each can be - ignored. - - For a longer but out of date high-level description, see - http://gee.cs.oswego.edu/dl/html/malloc.html - -* MSPACES - If MSPACES is defined, then in addition to malloc, free, etc., - this file also defines mspace_malloc, mspace_free, etc. These - are versions of malloc routines that take an "mspace" argument - obtained using create_mspace, to control all internal bookkeeping. - If ONLY_MSPACES is defined, only these versions are compiled. - So if you would like to use this allocator for only some allocations, - and your system malloc for others, you can compile with - ONLY_MSPACES and then do something like... - static mspace mymspace = create_mspace(0,0); // for example - #define mymalloc(bytes) mspace_malloc(mymspace, bytes) - - (Note: If you only need one instance of an mspace, you can instead - use "USE_DL_PREFIX" to relabel the global malloc.) - - You can similarly create thread-local allocators by storing - mspaces as thread-locals. For example: - static __thread mspace tlms = 0; - void* tlmalloc(size_t bytes) { - if (tlms == 0) tlms = create_mspace(0, 0); - return mspace_malloc(tlms, bytes); - } - void tlfree(void* mem) { mspace_free(tlms, mem); } - - Unless FOOTERS is defined, each mspace is completely independent. - You cannot allocate from one and free to another (although - conformance is only weakly checked, so usage errors are not always - caught). If FOOTERS is defined, then each chunk carries around a tag - indicating its originating mspace, and frees are directed to their - originating spaces. - - ------------------------- Compile-time options --------------------------- - -Be careful in setting #define values for numerical constants of type -size_t. On some systems, literal values are not automatically extended -to size_t precision unless they are explicitly casted. - -WIN32 default: defined if _WIN32 defined - Defining WIN32 sets up defaults for MS environment and compilers. - Otherwise defaults are for unix. - -MALLOC_ALIGNMENT default: (size_t)8 - Controls the minimum alignment for malloc'ed chunks. It must be a - power of two and at least 8, even on machines for which smaller - alignments would suffice. It may be defined as larger than this - though. Note however that code and data structures are optimized for - the case of 8-byte alignment. - -MSPACES default: 0 (false) - If true, compile in support for independent allocation spaces. - This is only supported if HAVE_MMAP is true. - -ONLY_MSPACES default: 0 (false) - If true, only compile in mspace versions, not regular versions. - -USE_LOCKS default: 0 (false) - Causes each call to each public routine to be surrounded with - pthread or WIN32 mutex lock/unlock. (If set true, this can be - overridden on a per-mspace basis for mspace versions.) - -FOOTERS default: 0 - If true, provide extra checking and dispatching by placing - information in the footers of allocated chunks. This adds - space and time overhead. - -INSECURE default: 0 - If true, omit checks for usage errors and heap space overwrites. - -USE_DL_PREFIX default: NOT defined - Causes compiler to prefix all public routines with the string 'dl'. - This can be useful when you only want to use this malloc in one part - of a program, using your regular system malloc elsewhere. - -ABORT default: defined as abort() - Defines how to abort on failed checks. On most systems, a failed - check cannot die with an "assert" or even print an informative - message, because the underlying print routines in turn call malloc, - which will fail again. Generally, the best policy is to simply call - abort(). It's not very useful to do more than this because many - errors due to overwriting will show up as address faults (null, odd - addresses etc) rather than malloc-triggered checks, so will also - abort. Also, most compilers know that abort() does not return, so - can better optimize code conditionally calling it. - -PROCEED_ON_ERROR default: defined as 0 (false) - Controls whether detected bad addresses cause them to bypassed - rather than aborting. If set, detected bad arguments to free and - realloc are ignored. And all bookkeeping information is zeroed out - upon a detected overwrite of freed heap space, thus losing the - ability to ever return it from malloc again, but enabling the - application to proceed. If PROCEED_ON_ERROR is defined, the - static variable malloc_corruption_error_count is compiled in - and can be examined to see if errors have occurred. This option - generates slower code than the default abort policy. - -DEBUG default: NOT defined - The DEBUG setting is mainly intended for people trying to modify - this code or diagnose problems when porting to new platforms. - However, it may also be able to better isolate user errors than just - using runtime checks. The assertions in the check routines spell - out in more detail the assumptions and invariants underlying the - algorithms. The checking is fairly extensive, and will slow down - execution noticeably. Calling malloc_stats or mallinfo with DEBUG - set will attempt to check every non-mmapped allocated and free chunk - in the course of computing the summaries. - -ABORT_ON_ASSERT_FAILURE default: defined as 1 (true) - Debugging assertion failures can be nearly impossible if your - version of the assert macro causes malloc to be called, which will - lead to a cascade of further failures, blowing the runtime stack. - ABORT_ON_ASSERT_FAILURE cause assertions failures to call abort(), - which will usually make debugging easier. - -MALLOC_FAILURE_ACTION default: sets errno to ENOMEM, or no-op on win32 - The action to take before "return 0" when malloc fails to be able to - return memory because there is none available. - -HAVE_MORECORE default: 1 (true) unless win32 or ONLY_MSPACES - True if this system supports sbrk or an emulation of it. - -MORECORE default: sbrk - The name of the sbrk-style system routine to call to obtain more - memory. See below for guidance on writing custom MORECORE - functions. The type of the argument to sbrk/MORECORE varies across - systems. It cannot be size_t, because it supports negative - arguments, so it is normally the signed type of the same width as - size_t (sometimes declared as "intptr_t"). It doesn't much matter - though. Internally, we only call it with arguments less than half - the max value of a size_t, which should work across all reasonable - possibilities, although sometimes generating compiler warnings. See - near the end of this file for guidelines for creating a custom - version of MORECORE. - -MORECORE_CONTIGUOUS default: 1 (true) - If true, take advantage of fact that consecutive calls to MORECORE - with positive arguments always return contiguous increasing - addresses. This is true of unix sbrk. It does not hurt too much to - set it true anyway, since malloc copes with non-contiguities. - Setting it false when definitely non-contiguous saves time - and possibly wasted space it would take to discover this though. - -MORECORE_CANNOT_TRIM default: NOT defined - True if MORECORE cannot release space back to the system when given - negative arguments. This is generally necessary only if you are - using a hand-crafted MORECORE function that cannot handle negative - arguments. - -HAVE_MMAP default: 1 (true) - True if this system supports mmap or an emulation of it. If so, and - HAVE_MORECORE is not true, MMAP is used for all system - allocation. If set and HAVE_MORECORE is true as well, MMAP is - primarily used to directly allocate very large blocks. It is also - used as a backup strategy in cases where MORECORE fails to provide - space from system. Note: A single call to MUNMAP is assumed to be - able to unmap memory that may have be allocated using multiple calls - to MMAP, so long as they are adjacent. - -HAVE_MREMAP default: 1 on linux, else 0 - If true realloc() uses mremap() to re-allocate large blocks and - extend or shrink allocation spaces. - -MMAP_CLEARS default: 1 on unix - True if mmap clears memory so calloc doesn't need to. This is true - for standard unix mmap using /dev/zero. - -USE_BUILTIN_FFS default: 0 (i.e., not used) - Causes malloc to use the builtin ffs() function to compute indices. - Some compilers may recognize and intrinsify ffs to be faster than the - supplied C version. Also, the case of x86 using gcc is special-cased - to an asm instruction, so is already as fast as it can be, and so - this setting has no effect. (On most x86s, the asm version is only - slightly faster than the C version.) - -malloc_getpagesize default: derive from system includes, or 4096. - The system page size. To the extent possible, this malloc manages - memory from the system in page-size units. This may be (and - usually is) a function rather than a constant. This is ignored - if WIN32, where page size is determined using getSystemInfo during - initialization. - -USE_DEV_RANDOM default: 0 (i.e., not used) - Causes malloc to use /dev/random to initialize secure magic seed for - stamping footers. Otherwise, the current time is used. - -NO_MALLINFO default: 0 - If defined, don't compile "mallinfo". This can be a simple way - of dealing with mismatches between system declarations and - those in this file. - -MALLINFO_FIELD_TYPE default: size_t - The type of the fields in the mallinfo struct. This was originally - defined as "int" in SVID etc, but is more usefully defined as - size_t. The value is used only if HAVE_USR_INCLUDE_MALLOC_H is not set - -REALLOC_ZERO_BYTES_FREES default: not defined - This should be set if a call to realloc with zero bytes should - be the same as a call to free. Some people think it should. Otherwise, - since this malloc returns a unique pointer for malloc(0), so does - realloc(p, 0). - -LACKS_UNISTD_H, LACKS_FCNTL_H, LACKS_SYS_PARAM_H, LACKS_SYS_MMAN_H -LACKS_STRINGS_H, LACKS_STRING_H, LACKS_SYS_TYPES_H, LACKS_ERRNO_H -LACKS_STDLIB_H default: NOT defined unless on WIN32 - Define these if your system does not have these header files. - You might need to manually insert some of the declarations they provide. - -DEFAULT_GRANULARITY default: page size if MORECORE_CONTIGUOUS, - system_info.dwAllocationGranularity in WIN32, - otherwise 64K. - Also settable using mallopt(M_GRANULARITY, x) - The unit for allocating and deallocating memory from the system. On - most systems with contiguous MORECORE, there is no reason to - make this more than a page. However, systems with MMAP tend to - either require or encourage larger granularities. You can increase - this value to prevent system allocation functions to be called so - often, especially if they are slow. The value must be at least one - page and must be a power of two. Setting to 0 causes initialization - to either page size or win32 region size. (Note: In previous - versions of malloc, the equivalent of this option was called - "TOP_PAD") - -DEFAULT_TRIM_THRESHOLD default: 2MB - Also settable using mallopt(M_TRIM_THRESHOLD, x) - The maximum amount of unused top-most memory to keep before - releasing via malloc_trim in free(). Automatic trimming is mainly - useful in long-lived programs using contiguous MORECORE. Because - trimming via sbrk can be slow on some systems, and can sometimes be - wasteful (in cases where programs immediately afterward allocate - more large chunks) the value should be high enough so that your - overall system performance would improve by releasing this much - memory. As a rough guide, you might set to a value close to the - average size of a process (program) running on your system. - Releasing this much memory would allow such a process to run in - memory. Generally, it is worth tuning trim thresholds when a - program undergoes phases where several large chunks are allocated - and released in ways that can reuse each other's storage, perhaps - mixed with phases where there are no such chunks at all. The trim - value must be greater than page size to have any useful effect. To - disable trimming completely, you can set to MAX_SIZE_T. Note that the trick - some people use of mallocing a huge space and then freeing it at - program startup, in an attempt to reserve system memory, doesn't - have the intended effect under automatic trimming, since that memory - will immediately be returned to the system. - -DEFAULT_MMAP_THRESHOLD default: 256K - Also settable using mallopt(M_MMAP_THRESHOLD, x) - The request size threshold for using MMAP to directly service a - request. Requests of at least this size that cannot be allocated - using already-existing space will be serviced via mmap. (If enough - normal freed space already exists it is used instead.) Using mmap - segregates relatively large chunks of memory so that they can be - individually obtained and released from the host system. A request - serviced through mmap is never reused by any other request (at least - not directly; the system may just so happen to remap successive - requests to the same locations). Segregating space in this way has - the benefits that: Mmapped space can always be individually released - back to the system, which helps keep the system level memory demands - of a long-lived program low. Also, mapped memory doesn't become - `locked' between other chunks, as can happen with normally allocated - chunks, which means that even trimming via malloc_trim would not - release them. However, it has the disadvantage that the space - cannot be reclaimed, consolidated, and then used to service later - requests, as happens with normal chunks. The advantages of mmap - nearly always outweigh disadvantages for "large" chunks, but the - value of "large" may vary across systems. The default is an - empirically derived value that works well in most systems. You can - disable mmap by setting to MAX_SIZE_T. - -*/ - -#ifndef WIN32 -#ifdef _WIN32 -#define WIN32 1 -#endif /* _WIN32 */ -#endif /* WIN32 */ -#ifdef WIN32 -#define WIN32_LEAN_AND_MEAN -#include -#define HAVE_MMAP 1 -#define HAVE_MORECORE 0 -#define LACKS_UNISTD_H -#define LACKS_SYS_PARAM_H -#define LACKS_SYS_MMAN_H -#define LACKS_STRING_H -#define LACKS_STRINGS_H -#define LACKS_SYS_TYPES_H -#define LACKS_ERRNO_H -#define LACKS_FCNTL_H -#define MALLOC_FAILURE_ACTION -#define MMAP_CLEARS 0 /* WINCE and some others apparently don't clear */ -#endif /* WIN32 */ - -#if defined(DARWIN) || defined(_DARWIN) -/* Mac OSX docs advise not to use sbrk; it seems better to use mmap */ -#ifndef HAVE_MORECORE -#define HAVE_MORECORE 0 -#define HAVE_MMAP 1 -#endif /* HAVE_MORECORE */ -#endif /* DARWIN */ - -#ifndef LACKS_SYS_TYPES_H -#include /* For size_t */ -#endif /* LACKS_SYS_TYPES_H */ - -/* The maximum possible size_t value has all bits set */ -#define MAX_SIZE_T (~(size_t)0) - -#ifndef ONLY_MSPACES -#define ONLY_MSPACES 0 -#endif /* ONLY_MSPACES */ -#ifndef MSPACES -#if ONLY_MSPACES -#define MSPACES 1 -#else /* ONLY_MSPACES */ -#define MSPACES 0 -#endif /* ONLY_MSPACES */ -#endif /* MSPACES */ -#ifndef MALLOC_ALIGNMENT -#define MALLOC_ALIGNMENT ((size_t)8U) -#endif /* MALLOC_ALIGNMENT */ -#ifndef FOOTERS -#define FOOTERS 0 -#endif /* FOOTERS */ -#ifndef ABORT -#define ABORT abort() -#endif /* ABORT */ -#ifndef ABORT_ON_ASSERT_FAILURE -#define ABORT_ON_ASSERT_FAILURE 1 -#endif /* ABORT_ON_ASSERT_FAILURE */ -#ifndef PROCEED_ON_ERROR -#define PROCEED_ON_ERROR 0 -#endif /* PROCEED_ON_ERROR */ -#ifndef USE_LOCKS -#define USE_LOCKS 0 -#endif /* USE_LOCKS */ -#ifndef INSECURE -#define INSECURE 0 -#endif /* INSECURE */ -#ifndef HAVE_MMAP -#define HAVE_MMAP 1 -#endif /* HAVE_MMAP */ -#ifndef MMAP_CLEARS -#define MMAP_CLEARS 1 -#endif /* MMAP_CLEARS */ -#ifndef HAVE_MREMAP -#ifdef linux -#define HAVE_MREMAP 1 -#else /* linux */ -#define HAVE_MREMAP 0 -#endif /* linux */ -#endif /* HAVE_MREMAP */ -#ifndef MALLOC_FAILURE_ACTION -#define MALLOC_FAILURE_ACTION errno = ENOMEM; -#endif /* MALLOC_FAILURE_ACTION */ -#ifndef HAVE_MORECORE -#if ONLY_MSPACES -#define HAVE_MORECORE 0 -#else /* ONLY_MSPACES */ -#define HAVE_MORECORE 1 -#endif /* ONLY_MSPACES */ -#endif /* HAVE_MORECORE */ -#if !HAVE_MORECORE -#define MORECORE_CONTIGUOUS 0 -#else /* !HAVE_MORECORE */ -#ifndef MORECORE -#define MORECORE sbrk -#endif /* MORECORE */ -#ifndef MORECORE_CONTIGUOUS -#define MORECORE_CONTIGUOUS 1 -#endif /* MORECORE_CONTIGUOUS */ -#endif /* HAVE_MORECORE */ -#ifndef DEFAULT_GRANULARITY -#if MORECORE_CONTIGUOUS -#define DEFAULT_GRANULARITY (0) /* 0 means to compute in init_mparams */ -#else /* MORECORE_CONTIGUOUS */ -#define DEFAULT_GRANULARITY ((size_t)64U * (size_t)1024U) -#endif /* MORECORE_CONTIGUOUS */ -#endif /* DEFAULT_GRANULARITY */ -#ifndef DEFAULT_TRIM_THRESHOLD -#ifndef MORECORE_CANNOT_TRIM -#define DEFAULT_TRIM_THRESHOLD ((size_t)2U * (size_t)1024U * (size_t)1024U) -#else /* MORECORE_CANNOT_TRIM */ -#define DEFAULT_TRIM_THRESHOLD MAX_SIZE_T -#endif /* MORECORE_CANNOT_TRIM */ -#endif /* DEFAULT_TRIM_THRESHOLD */ -#ifndef DEFAULT_MMAP_THRESHOLD -#if HAVE_MMAP -#define DEFAULT_MMAP_THRESHOLD ((size_t)256U * (size_t)1024U) -#else /* HAVE_MMAP */ -#define DEFAULT_MMAP_THRESHOLD MAX_SIZE_T -#endif /* HAVE_MMAP */ -#endif /* DEFAULT_MMAP_THRESHOLD */ -#ifndef USE_BUILTIN_FFS -#define USE_BUILTIN_FFS 0 -#endif /* USE_BUILTIN_FFS */ -#ifndef USE_DEV_RANDOM -#define USE_DEV_RANDOM 0 -#endif /* USE_DEV_RANDOM */ -#ifndef NO_MALLINFO -#define NO_MALLINFO 0 -#endif /* NO_MALLINFO */ -#ifndef MALLINFO_FIELD_TYPE -#define MALLINFO_FIELD_TYPE size_t -#endif /* MALLINFO_FIELD_TYPE */ - -#define memset SDL_memset -#define memcpy SDL_memcpy -#define malloc SDL_malloc -#define calloc SDL_calloc -#define realloc SDL_realloc -#define free SDL_free - -/* - mallopt tuning options. SVID/XPG defines four standard parameter - numbers for mallopt, normally defined in malloc.h. None of these - are used in this malloc, so setting them has no effect. But this - malloc does support the following options. -*/ - -#define M_TRIM_THRESHOLD (-1) -#define M_GRANULARITY (-2) -#define M_MMAP_THRESHOLD (-3) - -/* ------------------------ Mallinfo declarations ------------------------ */ - -#if !NO_MALLINFO -/* - This version of malloc supports the standard SVID/XPG mallinfo - routine that returns a struct containing usage properties and - statistics. It should work on any system that has a - /usr/include/malloc.h defining struct mallinfo. The main - declaration needed is the mallinfo struct that is returned (by-copy) - by mallinfo(). The malloinfo struct contains a bunch of fields that - are not even meaningful in this version of malloc. These fields are - are instead filled by mallinfo() with other numbers that might be of - interest. - - HAVE_USR_INCLUDE_MALLOC_H should be set if you have a - /usr/include/malloc.h file that includes a declaration of struct - mallinfo. If so, it is included; else a compliant version is - declared below. These must be precisely the same for mallinfo() to - work. The original SVID version of this struct, defined on most - systems with mallinfo, declares all fields as ints. But some others - define as unsigned long. If your system defines the fields using a - type of different width than listed here, you MUST #include your - system version and #define HAVE_USR_INCLUDE_MALLOC_H. -*/ - -/* #define HAVE_USR_INCLUDE_MALLOC_H */ - -#ifdef HAVE_USR_INCLUDE_MALLOC_H -#include "/usr/include/malloc.h" -#else /* HAVE_USR_INCLUDE_MALLOC_H */ - -struct mallinfo -{ - MALLINFO_FIELD_TYPE arena; /* non-mmapped space allocated from system */ - MALLINFO_FIELD_TYPE ordblks; /* number of free chunks */ - MALLINFO_FIELD_TYPE smblks; /* always 0 */ - MALLINFO_FIELD_TYPE hblks; /* always 0 */ - MALLINFO_FIELD_TYPE hblkhd; /* space in mmapped regions */ - MALLINFO_FIELD_TYPE usmblks; /* maximum total allocated space */ - MALLINFO_FIELD_TYPE fsmblks; /* always 0 */ - MALLINFO_FIELD_TYPE uordblks; /* total allocated space */ - MALLINFO_FIELD_TYPE fordblks; /* total free space */ - MALLINFO_FIELD_TYPE keepcost; /* releasable (via malloc_trim) space */ -}; - -#endif /* HAVE_USR_INCLUDE_MALLOC_H */ -#endif /* NO_MALLINFO */ - -#ifdef __cplusplus -extern "C" -{ -#endif /* __cplusplus */ - -#if !ONLY_MSPACES - -/* ------------------- Declarations of public routines ------------------- */ - -#ifndef USE_DL_PREFIX -#define dlcalloc calloc -#define dlfree free -#define dlmalloc malloc -#define dlmemalign memalign -#define dlrealloc realloc -#define dlvalloc valloc -#define dlpvalloc pvalloc -#define dlmallinfo mallinfo -#define dlmallopt mallopt -#define dlmalloc_trim malloc_trim -#define dlmalloc_stats malloc_stats -#define dlmalloc_usable_size malloc_usable_size -#define dlmalloc_footprint malloc_footprint -#define dlmalloc_max_footprint malloc_max_footprint -#define dlindependent_calloc independent_calloc -#define dlindependent_comalloc independent_comalloc -#endif /* USE_DL_PREFIX */ - - -/* - malloc(size_t n) - Returns a pointer to a newly allocated chunk of at least n bytes, or - null if no space is available, in which case errno is set to ENOMEM - on ANSI C systems. - - If n is zero, malloc returns a minimum-sized chunk. (The minimum - size is 16 bytes on most 32bit systems, and 32 bytes on 64bit - systems.) Note that size_t is an unsigned type, so calls with - arguments that would be negative if signed are interpreted as - requests for huge amounts of space, which will often fail. The - maximum supported value of n differs across systems, but is in all - cases less than the maximum representable value of a size_t. -*/ - void *dlmalloc(size_t); - -/* - free(void* p) - Releases the chunk of memory pointed to by p, that had been previously - allocated using malloc or a related routine such as realloc. - It has no effect if p is null. If p was not malloced or already - freed, free(p) will by default cause the current program to abort. -*/ - void dlfree(void *); - -/* - calloc(size_t n_elements, size_t element_size); - Returns a pointer to n_elements * element_size bytes, with all locations - set to zero. -*/ - void *dlcalloc(size_t, size_t); - -/* - realloc(void* p, size_t n) - Returns a pointer to a chunk of size n that contains the same data - as does chunk p up to the minimum of (n, p's size) bytes, or null - if no space is available. - - The returned pointer may or may not be the same as p. The algorithm - prefers extending p in most cases when possible, otherwise it - employs the equivalent of a malloc-copy-free sequence. - - If p is null, realloc is equivalent to malloc. - - If space is not available, realloc returns null, errno is set (if on - ANSI) and p is NOT freed. - - if n is for fewer bytes than already held by p, the newly unused - space is lopped off and freed if possible. realloc with a size - argument of zero (re)allocates a minimum-sized chunk. - - The old unix realloc convention of allowing the last-free'd chunk - to be used as an argument to realloc is not supported. -*/ - - void *dlrealloc(void *, size_t); - -/* - memalign(size_t alignment, size_t n); - Returns a pointer to a newly allocated chunk of n bytes, aligned - in accord with the alignment argument. - - The alignment argument should be a power of two. If the argument is - not a power of two, the nearest greater power is used. - 8-byte alignment is guaranteed by normal malloc calls, so don't - bother calling memalign with an argument of 8 or less. - - Overreliance on memalign is a sure way to fragment space. -*/ - void *dlmemalign(size_t, size_t); - -/* - valloc(size_t n); - Equivalent to memalign(pagesize, n), where pagesize is the page - size of the system. If the pagesize is unknown, 4096 is used. -*/ - void *dlvalloc(size_t); - -/* - mallopt(int parameter_number, int parameter_value) - Sets tunable parameters The format is to provide a - (parameter-number, parameter-value) pair. mallopt then sets the - corresponding parameter to the argument value if it can (i.e., so - long as the value is meaningful), and returns 1 if successful else - 0. SVID/XPG/ANSI defines four standard param numbers for mallopt, - normally defined in malloc.h. None of these are use in this malloc, - so setting them has no effect. But this malloc also supports other - options in mallopt. See below for details. Briefly, supported - parameters are as follows (listed defaults are for "typical" - configurations). - - Symbol param # default allowed param values - M_TRIM_THRESHOLD -1 2*1024*1024 any (MAX_SIZE_T disables) - M_GRANULARITY -2 page size any power of 2 >= page size - M_MMAP_THRESHOLD -3 256*1024 any (or 0 if no MMAP support) -*/ - int dlmallopt(int, int); - -/* - malloc_footprint(); - Returns the number of bytes obtained from the system. The total - number of bytes allocated by malloc, realloc etc., is less than this - value. Unlike mallinfo, this function returns only a precomputed - result, so can be called frequently to monitor memory consumption. - Even if locks are otherwise defined, this function does not use them, - so results might not be up to date. -*/ - size_t dlmalloc_footprint(void); - -/* - malloc_max_footprint(); - Returns the maximum number of bytes obtained from the system. This - value will be greater than current footprint if deallocated space - has been reclaimed by the system. The peak number of bytes allocated - by malloc, realloc etc., is less than this value. Unlike mallinfo, - this function returns only a precomputed result, so can be called - frequently to monitor memory consumption. Even if locks are - otherwise defined, this function does not use them, so results might - not be up to date. -*/ - size_t dlmalloc_max_footprint(void); - -#if !NO_MALLINFO -/* - mallinfo() - Returns (by copy) a struct containing various summary statistics: - - arena: current total non-mmapped bytes allocated from system - ordblks: the number of free chunks - smblks: always zero. - hblks: current number of mmapped regions - hblkhd: total bytes held in mmapped regions - usmblks: the maximum total allocated space. This will be greater - than current total if trimming has occurred. - fsmblks: always zero - uordblks: current total allocated space (normal or mmapped) - fordblks: total free space - keepcost: the maximum number of bytes that could ideally be released - back to system via malloc_trim. ("ideally" means that - it ignores page restrictions etc.) - - Because these fields are ints, but internal bookkeeping may - be kept as longs, the reported values may wrap around zero and - thus be inaccurate. -*/ - struct mallinfo dlmallinfo(void); -#endif /* NO_MALLINFO */ - -/* - independent_calloc(size_t n_elements, size_t element_size, void* chunks[]); - - independent_calloc is similar to calloc, but instead of returning a - single cleared space, it returns an array of pointers to n_elements - independent elements that can hold contents of size elem_size, each - of which starts out cleared, and can be independently freed, - realloc'ed etc. The elements are guaranteed to be adjacently - allocated (this is not guaranteed to occur with multiple callocs or - mallocs), which may also improve cache locality in some - applications. - - The "chunks" argument is optional (i.e., may be null, which is - probably the most typical usage). If it is null, the returned array - is itself dynamically allocated and should also be freed when it is - no longer needed. Otherwise, the chunks array must be of at least - n_elements in length. It is filled in with the pointers to the - chunks. - - In either case, independent_calloc returns this pointer array, or - null if the allocation failed. If n_elements is zero and "chunks" - is null, it returns a chunk representing an array with zero elements - (which should be freed if not wanted). - - Each element must be individually freed when it is no longer - needed. If you'd like to instead be able to free all at once, you - should instead use regular calloc and assign pointers into this - space to represent elements. (In this case though, you cannot - independently free elements.) - - independent_calloc simplifies and speeds up implementations of many - kinds of pools. It may also be useful when constructing large data - structures that initially have a fixed number of fixed-sized nodes, - but the number is not known at compile time, and some of the nodes - may later need to be freed. For example: - - struct Node { int item; struct Node* next; }; - - struct Node* build_list() { - struct Node** pool; - int n = read_number_of_nodes_needed(); - if (n <= 0) return 0; - pool = (struct Node**)(independent_calloc(n, sizeof(struct Node), 0); - if (pool == 0) die(); - // organize into a linked list... - struct Node* first = pool[0]; - for (i = 0; i < n-1; ++i) - pool[i]->next = pool[i+1]; - free(pool); // Can now free the array (or not, if it is needed later) - return first; - } -*/ - void **dlindependent_calloc(size_t, size_t, void **); - -/* - independent_comalloc(size_t n_elements, size_t sizes[], void* chunks[]); - - independent_comalloc allocates, all at once, a set of n_elements - chunks with sizes indicated in the "sizes" array. It returns - an array of pointers to these elements, each of which can be - independently freed, realloc'ed etc. The elements are guaranteed to - be adjacently allocated (this is not guaranteed to occur with - multiple callocs or mallocs), which may also improve cache locality - in some applications. - - The "chunks" argument is optional (i.e., may be null). If it is null - the returned array is itself dynamically allocated and should also - be freed when it is no longer needed. Otherwise, the chunks array - must be of at least n_elements in length. It is filled in with the - pointers to the chunks. - - In either case, independent_comalloc returns this pointer array, or - null if the allocation failed. If n_elements is zero and chunks is - null, it returns a chunk representing an array with zero elements - (which should be freed if not wanted). - - Each element must be individually freed when it is no longer - needed. If you'd like to instead be able to free all at once, you - should instead use a single regular malloc, and assign pointers at - particular offsets in the aggregate space. (In this case though, you - cannot independently free elements.) - - independent_comallac differs from independent_calloc in that each - element may have a different size, and also that it does not - automatically clear elements. - - independent_comalloc can be used to speed up allocation in cases - where several structs or objects must always be allocated at the - same time. For example: - - struct Head { ... } - struct Foot { ... } - - void send_message(char* msg) { - int msglen = strlen(msg); - size_t sizes[3] = { sizeof(struct Head), msglen, sizeof(struct Foot) }; - void* chunks[3]; - if (independent_comalloc(3, sizes, chunks) == 0) - die(); - struct Head* head = (struct Head*)(chunks[0]); - char* body = (char*)(chunks[1]); - struct Foot* foot = (struct Foot*)(chunks[2]); - // ... - } - - In general though, independent_comalloc is worth using only for - larger values of n_elements. For small values, you probably won't - detect enough difference from series of malloc calls to bother. - - Overuse of independent_comalloc can increase overall memory usage, - since it cannot reuse existing noncontiguous small chunks that - might be available for some of the elements. -*/ - void **dlindependent_comalloc(size_t, size_t *, void **); - - -/* - pvalloc(size_t n); - Equivalent to valloc(minimum-page-that-holds(n)), that is, - round up n to nearest pagesize. - */ - void *dlpvalloc(size_t); - -/* - malloc_trim(size_t pad); - - If possible, gives memory back to the system (via negative arguments - to sbrk) if there is unused memory at the `high' end of the malloc - pool or in unused MMAP segments. You can call this after freeing - large blocks of memory to potentially reduce the system-level memory - requirements of a program. However, it cannot guarantee to reduce - memory. Under some allocation patterns, some large free blocks of - memory will be locked between two used chunks, so they cannot be - given back to the system. - - The `pad' argument to malloc_trim represents the amount of free - trailing space to leave untrimmed. If this argument is zero, only - the minimum amount of memory to maintain internal data structures - will be left. Non-zero arguments can be supplied to maintain enough - trailing space to service future expected allocations without having - to re-obtain memory from the system. - - Malloc_trim returns 1 if it actually released any memory, else 0. -*/ - int dlmalloc_trim(size_t); - -/* - malloc_usable_size(void* p); - - Returns the number of bytes you can actually use in - an allocated chunk, which may be more than you requested (although - often not) due to alignment and minimum size constraints. - You can use this many bytes without worrying about - overwriting other allocated objects. This is not a particularly great - programming practice. malloc_usable_size can be more useful in - debugging and assertions, for example: - - p = malloc(n); - assert(malloc_usable_size(p) >= 256); -*/ - size_t dlmalloc_usable_size(void *); - -/* - malloc_stats(); - Prints on stderr the amount of space obtained from the system (both - via sbrk and mmap), the maximum amount (which may be more than - current if malloc_trim and/or munmap got called), and the current - number of bytes allocated via malloc (or realloc, etc) but not yet - freed. Note that this is the number of bytes allocated, not the - number requested. It will be larger than the number requested - because of alignment and bookkeeping overhead. Because it includes - alignment wastage as being in use, this figure may be greater than - zero even when no user-level chunks are allocated. - - The reported current and maximum system memory can be inaccurate if - a program makes other calls to system memory allocation functions - (normally sbrk) outside of malloc. - - malloc_stats prints only the most commonly interesting statistics. - More information can be obtained by calling mallinfo. -*/ - void dlmalloc_stats(void); - -#endif /* ONLY_MSPACES */ - -#if MSPACES - -/* - mspace is an opaque type representing an independent - region of space that supports mspace_malloc, etc. -*/ - typedef void *mspace; - -/* - create_mspace creates and returns a new independent space with the - given initial capacity, or, if 0, the default granularity size. It - returns null if there is no system memory available to create the - space. If argument locked is non-zero, the space uses a separate - lock to control access. The capacity of the space will grow - dynamically as needed to service mspace_malloc requests. You can - control the sizes of incremental increases of this space by - compiling with a different DEFAULT_GRANULARITY or dynamically - setting with mallopt(M_GRANULARITY, value). -*/ - mspace create_mspace(size_t capacity, int locked); - -/* - destroy_mspace destroys the given space, and attempts to return all - of its memory back to the system, returning the total number of - bytes freed. After destruction, the results of access to all memory - used by the space become undefined. -*/ - size_t destroy_mspace(mspace msp); - -/* - create_mspace_with_base uses the memory supplied as the initial base - of a new mspace. Part (less than 128*sizeof(size_t) bytes) of this - space is used for bookkeeping, so the capacity must be at least this - large. (Otherwise 0 is returned.) When this initial space is - exhausted, additional memory will be obtained from the system. - Destroying this space will deallocate all additionally allocated - space (if possible) but not the initial base. -*/ - mspace create_mspace_with_base(void *base, size_t capacity, int locked); - -/* - mspace_malloc behaves as malloc, but operates within - the given space. -*/ - void *mspace_malloc(mspace msp, size_t bytes); - -/* - mspace_free behaves as free, but operates within - the given space. - - If compiled with FOOTERS==1, mspace_free is not actually needed. - free may be called instead of mspace_free because freed chunks from - any space are handled by their originating spaces. -*/ - void mspace_free(mspace msp, void *mem); - -/* - mspace_realloc behaves as realloc, but operates within - the given space. - - If compiled with FOOTERS==1, mspace_realloc is not actually - needed. realloc may be called instead of mspace_realloc because - realloced chunks from any space are handled by their originating - spaces. -*/ - void *mspace_realloc(mspace msp, void *mem, size_t newsize); - -/* - mspace_calloc behaves as calloc, but operates within - the given space. -*/ - void *mspace_calloc(mspace msp, size_t n_elements, size_t elem_size); - -/* - mspace_memalign behaves as memalign, but operates within - the given space. -*/ - void *mspace_memalign(mspace msp, size_t alignment, size_t bytes); - -/* - mspace_independent_calloc behaves as independent_calloc, but - operates within the given space. -*/ - void **mspace_independent_calloc(mspace msp, size_t n_elements, - size_t elem_size, void *chunks[]); - -/* - mspace_independent_comalloc behaves as independent_comalloc, but - operates within the given space. -*/ - void **mspace_independent_comalloc(mspace msp, size_t n_elements, - size_t sizes[], void *chunks[]); - -/* - mspace_footprint() returns the number of bytes obtained from the - system for this space. -*/ - size_t mspace_footprint(mspace msp); - -/* - mspace_max_footprint() returns the peak number of bytes obtained from the - system for this space. -*/ - size_t mspace_max_footprint(mspace msp); - - -#if !NO_MALLINFO -/* - mspace_mallinfo behaves as mallinfo, but reports properties of - the given space. -*/ - struct mallinfo mspace_mallinfo(mspace msp); -#endif /* NO_MALLINFO */ - -/* - mspace_malloc_stats behaves as malloc_stats, but reports - properties of the given space. -*/ - void mspace_malloc_stats(mspace msp); - -/* - mspace_trim behaves as malloc_trim, but - operates within the given space. -*/ - int mspace_trim(mspace msp, size_t pad); - -/* - An alias for mallopt. -*/ - int mspace_mallopt(int, int); - -#endif /* MSPACES */ - -#ifdef __cplusplus -}; /* end of extern "C" */ -#endif /* __cplusplus */ - -/* - ======================================================================== - To make a fully customizable malloc.h header file, cut everything - above this line, put into file malloc.h, edit to suit, and #include it - on the next line, as well as in programs that use this malloc. - ======================================================================== -*/ - -/* #include "malloc.h" */ - -/*------------------------------ internal #includes ---------------------- */ - -#ifdef _MSC_VER -#pragma warning( disable : 4146 ) /* no "unsigned" warnings */ -#endif /* _MSC_VER */ - -#ifndef LACKS_STDIO_H -#include /* for printing in malloc_stats */ -#endif - -#ifndef LACKS_ERRNO_H -#include /* for MALLOC_FAILURE_ACTION */ -#endif /* LACKS_ERRNO_H */ -#if FOOTERS -#include /* for magic initialization */ -#endif /* FOOTERS */ -#ifndef LACKS_STDLIB_H -#include /* for abort() */ -#endif /* LACKS_STDLIB_H */ -#ifdef DEBUG -#if ABORT_ON_ASSERT_FAILURE -#define assert(x) if(!(x)) ABORT -#else /* ABORT_ON_ASSERT_FAILURE */ -#include -#endif /* ABORT_ON_ASSERT_FAILURE */ -#else /* DEBUG */ -#define assert(x) -#endif /* DEBUG */ -#ifndef LACKS_STRING_H -#include /* for memset etc */ -#endif /* LACKS_STRING_H */ -#if USE_BUILTIN_FFS -#ifndef LACKS_STRINGS_H -#include /* for ffs */ -#endif /* LACKS_STRINGS_H */ -#endif /* USE_BUILTIN_FFS */ -#if HAVE_MMAP -#ifndef LACKS_SYS_MMAN_H -#include /* for mmap */ -#endif /* LACKS_SYS_MMAN_H */ -#ifndef LACKS_FCNTL_H -#include -#endif /* LACKS_FCNTL_H */ -#endif /* HAVE_MMAP */ -#if HAVE_MORECORE -#ifndef LACKS_UNISTD_H -#include /* for sbrk */ -#else /* LACKS_UNISTD_H */ -#if !defined(__FreeBSD__) && !defined(__OpenBSD__) && !defined(__NetBSD__) -extern void *sbrk(ptrdiff_t); -#endif /* FreeBSD etc */ -#endif /* LACKS_UNISTD_H */ -#endif /* HAVE_MMAP */ - -#ifndef WIN32 -#ifndef malloc_getpagesize -# ifdef _SC_PAGESIZE /* some SVR4 systems omit an underscore */ -# ifndef _SC_PAGE_SIZE -# define _SC_PAGE_SIZE _SC_PAGESIZE -# endif -# endif -# ifdef _SC_PAGE_SIZE -# define malloc_getpagesize sysconf(_SC_PAGE_SIZE) -# else -# if defined(BSD) || defined(DGUX) || defined(HAVE_GETPAGESIZE) -extern size_t getpagesize(); -# define malloc_getpagesize getpagesize() -# else -# ifdef WIN32 /* use supplied emulation of getpagesize */ -# define malloc_getpagesize getpagesize() -# else -# ifndef LACKS_SYS_PARAM_H -# include -# endif -# ifdef EXEC_PAGESIZE -# define malloc_getpagesize EXEC_PAGESIZE -# else -# ifdef NBPG -# ifndef CLSIZE -# define malloc_getpagesize NBPG -# else -# define malloc_getpagesize (NBPG * CLSIZE) -# endif -# else -# ifdef NBPC -# define malloc_getpagesize NBPC -# else -# ifdef PAGESIZE -# define malloc_getpagesize PAGESIZE -# else /* just guess */ -# define malloc_getpagesize ((size_t)4096U) -# endif -# endif -# endif -# endif -# endif -# endif -# endif -#endif -#endif - -/* ------------------- size_t and alignment properties -------------------- */ - -/* The byte and bit size of a size_t */ -#define SIZE_T_SIZE (sizeof(size_t)) -#define SIZE_T_BITSIZE (sizeof(size_t) << 3) - -/* Some constants coerced to size_t */ -/* Annoying but necessary to avoid errors on some plaftorms */ -#define SIZE_T_ZERO ((size_t)0) -#define SIZE_T_ONE ((size_t)1) -#define SIZE_T_TWO ((size_t)2) -#define TWO_SIZE_T_SIZES (SIZE_T_SIZE<<1) -#define FOUR_SIZE_T_SIZES (SIZE_T_SIZE<<2) -#define SIX_SIZE_T_SIZES (FOUR_SIZE_T_SIZES+TWO_SIZE_T_SIZES) -#define HALF_MAX_SIZE_T (MAX_SIZE_T / 2U) - -/* The bit mask value corresponding to MALLOC_ALIGNMENT */ -#define CHUNK_ALIGN_MASK (MALLOC_ALIGNMENT - SIZE_T_ONE) - -/* True if address a has acceptable alignment */ -#define is_aligned(A) (((size_t)((A)) & (CHUNK_ALIGN_MASK)) == 0) - -/* the number of bytes to offset an address to align it */ -#define align_offset(A)\ - ((((size_t)(A) & CHUNK_ALIGN_MASK) == 0)? 0 :\ - ((MALLOC_ALIGNMENT - ((size_t)(A) & CHUNK_ALIGN_MASK)) & CHUNK_ALIGN_MASK)) - -/* -------------------------- MMAP preliminaries ------------------------- */ - -/* - If HAVE_MORECORE or HAVE_MMAP are false, we just define calls and - checks to fail so compiler optimizer can delete code rather than - using so many "#if"s. -*/ - - -/* MORECORE and MMAP must return MFAIL on failure */ -#define MFAIL ((void*)(MAX_SIZE_T)) -#define CMFAIL ((char*)(MFAIL)) /* defined for convenience */ - -#if !HAVE_MMAP -#define IS_MMAPPED_BIT (SIZE_T_ZERO) -#define USE_MMAP_BIT (SIZE_T_ZERO) -#define CALL_MMAP(s) MFAIL -#define CALL_MUNMAP(a, s) (-1) -#define DIRECT_MMAP(s) MFAIL - -#else /* HAVE_MMAP */ -#define IS_MMAPPED_BIT (SIZE_T_ONE) -#define USE_MMAP_BIT (SIZE_T_ONE) - -#ifndef WIN32 -#define CALL_MUNMAP(a, s) munmap((a), (s)) -#define MMAP_PROT (PROT_READ|PROT_WRITE) -#if !defined(MAP_ANONYMOUS) && defined(MAP_ANON) -#define MAP_ANONYMOUS MAP_ANON -#endif /* MAP_ANON */ -#ifdef MAP_ANONYMOUS -#define MMAP_FLAGS (MAP_PRIVATE|MAP_ANONYMOUS) -#define CALL_MMAP(s) mmap(0, (s), MMAP_PROT, MMAP_FLAGS, -1, 0) -#else /* MAP_ANONYMOUS */ -/* - Nearly all versions of mmap support MAP_ANONYMOUS, so the following - is unlikely to be needed, but is supplied just in case. -*/ -#define MMAP_FLAGS (MAP_PRIVATE) -static int dev_zero_fd = -1; /* Cached file descriptor for /dev/zero. */ -#define CALL_MMAP(s) ((dev_zero_fd < 0) ? \ - (dev_zero_fd = open("/dev/zero", O_RDWR), \ - mmap(0, (s), MMAP_PROT, MMAP_FLAGS, dev_zero_fd, 0)) : \ - mmap(0, (s), MMAP_PROT, MMAP_FLAGS, dev_zero_fd, 0)) -#endif /* MAP_ANONYMOUS */ - -#define DIRECT_MMAP(s) CALL_MMAP(s) -#else /* WIN32 */ - -/* Win32 MMAP via VirtualAlloc */ -static void * -win32mmap(size_t size) -{ - void *ptr = - VirtualAlloc(0, size, MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE); - return (ptr != 0) ? ptr : MFAIL; -} - -/* For direct MMAP, use MEM_TOP_DOWN to minimize interference */ -static void * -win32direct_mmap(size_t size) -{ - void *ptr = VirtualAlloc(0, size, MEM_RESERVE | MEM_COMMIT | MEM_TOP_DOWN, - PAGE_READWRITE); - return (ptr != 0) ? ptr : MFAIL; -} - -/* This function supports releasing coalesed segments */ -static int -win32munmap(void *ptr, size_t size) -{ - MEMORY_BASIC_INFORMATION minfo; - char *cptr = ptr; - while (size) { - if (VirtualQuery(cptr, &minfo, sizeof(minfo)) == 0) - return -1; - if (minfo.BaseAddress != cptr || minfo.AllocationBase != cptr || - minfo.State != MEM_COMMIT || minfo.RegionSize > size) - return -1; - if (VirtualFree(cptr, 0, MEM_RELEASE) == 0) - return -1; - cptr += minfo.RegionSize; - size -= minfo.RegionSize; - } - return 0; -} - -#define CALL_MMAP(s) win32mmap(s) -#define CALL_MUNMAP(a, s) win32munmap((a), (s)) -#define DIRECT_MMAP(s) win32direct_mmap(s) -#endif /* WIN32 */ -#endif /* HAVE_MMAP */ - -#if HAVE_MMAP && HAVE_MREMAP -#define CALL_MREMAP(addr, osz, nsz, mv) mremap((addr), (osz), (nsz), (mv)) -#else /* HAVE_MMAP && HAVE_MREMAP */ -#define CALL_MREMAP(addr, osz, nsz, mv) MFAIL -#endif /* HAVE_MMAP && HAVE_MREMAP */ - -#if HAVE_MORECORE -#define CALL_MORECORE(S) MORECORE(S) -#else /* HAVE_MORECORE */ -#define CALL_MORECORE(S) MFAIL -#endif /* HAVE_MORECORE */ - -/* mstate bit set if continguous morecore disabled or failed */ -#define USE_NONCONTIGUOUS_BIT (4U) - -/* segment bit set in create_mspace_with_base */ -#define EXTERN_BIT (8U) - - -/* --------------------------- Lock preliminaries ------------------------ */ - -#if USE_LOCKS - -/* - When locks are defined, there are up to two global locks: - - * If HAVE_MORECORE, morecore_mutex protects sequences of calls to - MORECORE. In many cases sys_alloc requires two calls, that should - not be interleaved with calls by other threads. This does not - protect against direct calls to MORECORE by other threads not - using this lock, so there is still code to cope the best we can on - interference. - - * magic_init_mutex ensures that mparams.magic and other - unique mparams values are initialized only once. -*/ - -#ifndef WIN32 -/* By default use posix locks */ -#include -#define MLOCK_T pthread_mutex_t -#define INITIAL_LOCK(l) pthread_mutex_init(l, NULL) -#define ACQUIRE_LOCK(l) pthread_mutex_lock(l) -#define RELEASE_LOCK(l) pthread_mutex_unlock(l) - -#if HAVE_MORECORE -static MLOCK_T morecore_mutex = PTHREAD_MUTEX_INITIALIZER; -#endif /* HAVE_MORECORE */ - -static MLOCK_T magic_init_mutex = PTHREAD_MUTEX_INITIALIZER; - -#else /* WIN32 */ -/* - Because lock-protected regions have bounded times, and there - are no recursive lock calls, we can use simple spinlocks. -*/ - -#define MLOCK_T long -static int -win32_acquire_lock(MLOCK_T * sl) -{ - for (;;) { -#ifdef InterlockedCompareExchangePointer - if (!InterlockedCompareExchange(sl, 1, 0)) - return 0; -#else /* Use older void* version */ - if (!InterlockedCompareExchange((void **) sl, (void *) 1, (void *) 0)) - return 0; -#endif /* InterlockedCompareExchangePointer */ - Sleep(0); - } -} - -static void -win32_release_lock(MLOCK_T * sl) -{ - InterlockedExchange(sl, 0); -} - -#define INITIAL_LOCK(l) *(l)=0 -#define ACQUIRE_LOCK(l) win32_acquire_lock(l) -#define RELEASE_LOCK(l) win32_release_lock(l) -#if HAVE_MORECORE -static MLOCK_T morecore_mutex; -#endif /* HAVE_MORECORE */ -static MLOCK_T magic_init_mutex; -#endif /* WIN32 */ - -#define USE_LOCK_BIT (2U) -#else /* USE_LOCKS */ -#define USE_LOCK_BIT (0U) -#define INITIAL_LOCK(l) -#endif /* USE_LOCKS */ - -#if USE_LOCKS && HAVE_MORECORE -#define ACQUIRE_MORECORE_LOCK() ACQUIRE_LOCK(&morecore_mutex); -#define RELEASE_MORECORE_LOCK() RELEASE_LOCK(&morecore_mutex); -#else /* USE_LOCKS && HAVE_MORECORE */ -#define ACQUIRE_MORECORE_LOCK() -#define RELEASE_MORECORE_LOCK() -#endif /* USE_LOCKS && HAVE_MORECORE */ - -#if USE_LOCKS -#define ACQUIRE_MAGIC_INIT_LOCK() ACQUIRE_LOCK(&magic_init_mutex); -#define RELEASE_MAGIC_INIT_LOCK() RELEASE_LOCK(&magic_init_mutex); -#else /* USE_LOCKS */ -#define ACQUIRE_MAGIC_INIT_LOCK() -#define RELEASE_MAGIC_INIT_LOCK() -#endif /* USE_LOCKS */ - - -/* ----------------------- Chunk representations ------------------------ */ - -/* - (The following includes lightly edited explanations by Colin Plumb.) - - The malloc_chunk declaration below is misleading (but accurate and - necessary). It declares a "view" into memory allowing access to - necessary fields at known offsets from a given base. - - Chunks of memory are maintained using a `boundary tag' method as - originally described by Knuth. (See the paper by Paul Wilson - ftp://ftp.cs.utexas.edu/pub/garbage/allocsrv.ps for a survey of such - techniques.) Sizes of free chunks are stored both in the front of - each chunk and at the end. This makes consolidating fragmented - chunks into bigger chunks fast. The head fields also hold bits - representing whether chunks are free or in use. - - Here are some pictures to make it clearer. They are "exploded" to - show that the state of a chunk can be thought of as extending from - the high 31 bits of the head field of its header through the - prev_foot and PINUSE_BIT bit of the following chunk header. - - A chunk that's in use looks like: - - chunk-> +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | Size of previous chunk (if P = 1) | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |P| - | Size of this chunk 1| +-+ - mem-> +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | | - +- -+ - | | - +- -+ - | : - +- size - sizeof(size_t) available payload bytes -+ - : | - chunk-> +- -+ - | | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |1| - | Size of next chunk (may or may not be in use) | +-+ - mem-> +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - - And if it's free, it looks like this: - - chunk-> +- -+ - | User payload (must be in use, or we would have merged!) | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |P| - | Size of this chunk 0| +-+ - mem-> +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | Next pointer | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | Prev pointer | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | : - +- size - sizeof(struct chunk) unused bytes -+ - : | - chunk-> +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | Size of this chunk | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |0| - | Size of next chunk (must be in use, or we would have merged)| +-+ - mem-> +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | : - +- User payload -+ - : | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - |0| - +-+ - Note that since we always merge adjacent free chunks, the chunks - adjacent to a free chunk must be in use. - - Given a pointer to a chunk (which can be derived trivially from the - payload pointer) we can, in O(1) time, find out whether the adjacent - chunks are free, and if so, unlink them from the lists that they - are on and merge them with the current chunk. - - Chunks always begin on even word boundaries, so the mem portion - (which is returned to the user) is also on an even word boundary, and - thus at least double-word aligned. - - The P (PINUSE_BIT) bit, stored in the unused low-order bit of the - chunk size (which is always a multiple of two words), is an in-use - bit for the *previous* chunk. If that bit is *clear*, then the - word before the current chunk size contains the previous chunk - size, and can be used to find the front of the previous chunk. - The very first chunk allocated always has this bit set, preventing - access to non-existent (or non-owned) memory. If pinuse is set for - any given chunk, then you CANNOT determine the size of the - previous chunk, and might even get a memory addressing fault when - trying to do so. - - The C (CINUSE_BIT) bit, stored in the unused second-lowest bit of - the chunk size redundantly records whether the current chunk is - inuse. This redundancy enables usage checks within free and realloc, - and reduces indirection when freeing and consolidating chunks. - - Each freshly allocated chunk must have both cinuse and pinuse set. - That is, each allocated chunk borders either a previously allocated - and still in-use chunk, or the base of its memory arena. This is - ensured by making all allocations from the the `lowest' part of any - found chunk. Further, no free chunk physically borders another one, - so each free chunk is known to be preceded and followed by either - inuse chunks or the ends of memory. - - Note that the `foot' of the current chunk is actually represented - as the prev_foot of the NEXT chunk. This makes it easier to - deal with alignments etc but can be very confusing when trying - to extend or adapt this code. - - The exceptions to all this are - - 1. The special chunk `top' is the top-most available chunk (i.e., - the one bordering the end of available memory). It is treated - specially. Top is never included in any bin, is used only if - no other chunk is available, and is released back to the - system if it is very large (see M_TRIM_THRESHOLD). In effect, - the top chunk is treated as larger (and thus less well - fitting) than any other available chunk. The top chunk - doesn't update its trailing size field since there is no next - contiguous chunk that would have to index off it. However, - space is still allocated for it (TOP_FOOT_SIZE) to enable - separation or merging when space is extended. - - 3. Chunks allocated via mmap, which have the lowest-order bit - (IS_MMAPPED_BIT) set in their prev_foot fields, and do not set - PINUSE_BIT in their head fields. Because they are allocated - one-by-one, each must carry its own prev_foot field, which is - also used to hold the offset this chunk has within its mmapped - region, which is needed to preserve alignment. Each mmapped - chunk is trailed by the first two fields of a fake next-chunk - for sake of usage checks. - -*/ - -struct malloc_chunk -{ - size_t prev_foot; /* Size of previous chunk (if free). */ - size_t head; /* Size and inuse bits. */ - struct malloc_chunk *fd; /* double links -- used only if free. */ - struct malloc_chunk *bk; -}; - -typedef struct malloc_chunk mchunk; -typedef struct malloc_chunk *mchunkptr; -typedef struct malloc_chunk *sbinptr; /* The type of bins of chunks */ -typedef size_t bindex_t; /* Described below */ -typedef unsigned int binmap_t; /* Described below */ -typedef unsigned int flag_t; /* The type of various bit flag sets */ - -/* ------------------- Chunks sizes and alignments ----------------------- */ - -#define MCHUNK_SIZE (sizeof(mchunk)) - -#if FOOTERS -#define CHUNK_OVERHEAD (TWO_SIZE_T_SIZES) -#else /* FOOTERS */ -#define CHUNK_OVERHEAD (SIZE_T_SIZE) -#endif /* FOOTERS */ - -/* MMapped chunks need a second word of overhead ... */ -#define MMAP_CHUNK_OVERHEAD (TWO_SIZE_T_SIZES) -/* ... and additional padding for fake next-chunk at foot */ -#define MMAP_FOOT_PAD (FOUR_SIZE_T_SIZES) - -/* The smallest size we can malloc is an aligned minimal chunk */ -#define MIN_CHUNK_SIZE\ - ((MCHUNK_SIZE + CHUNK_ALIGN_MASK) & ~CHUNK_ALIGN_MASK) - -/* conversion from malloc headers to user pointers, and back */ -#define chunk2mem(p) ((void*)((char*)(p) + TWO_SIZE_T_SIZES)) -#define mem2chunk(mem) ((mchunkptr)((char*)(mem) - TWO_SIZE_T_SIZES)) -/* chunk associated with aligned address A */ -#define align_as_chunk(A) (mchunkptr)((A) + align_offset(chunk2mem(A))) - -/* Bounds on request (not chunk) sizes. */ -#define MAX_REQUEST ((-MIN_CHUNK_SIZE) << 2) -#define MIN_REQUEST (MIN_CHUNK_SIZE - CHUNK_OVERHEAD - SIZE_T_ONE) - -/* pad request bytes into a usable size */ -#define pad_request(req) \ - (((req) + CHUNK_OVERHEAD + CHUNK_ALIGN_MASK) & ~CHUNK_ALIGN_MASK) - -/* pad request, checking for minimum (but not maximum) */ -#define request2size(req) \ - (((req) < MIN_REQUEST)? MIN_CHUNK_SIZE : pad_request(req)) - - -/* ------------------ Operations on head and foot fields ----------------- */ - -/* - The head field of a chunk is or'ed with PINUSE_BIT when previous - adjacent chunk in use, and or'ed with CINUSE_BIT if this chunk is in - use. If the chunk was obtained with mmap, the prev_foot field has - IS_MMAPPED_BIT set, otherwise holding the offset of the base of the - mmapped region to the base of the chunk. -*/ - -#define PINUSE_BIT (SIZE_T_ONE) -#define CINUSE_BIT (SIZE_T_TWO) -#define INUSE_BITS (PINUSE_BIT|CINUSE_BIT) - -/* Head value for fenceposts */ -#define FENCEPOST_HEAD (INUSE_BITS|SIZE_T_SIZE) - -/* extraction of fields from head words */ -#define cinuse(p) ((p)->head & CINUSE_BIT) -#define pinuse(p) ((p)->head & PINUSE_BIT) -#define chunksize(p) ((p)->head & ~(INUSE_BITS)) - -#define clear_pinuse(p) ((p)->head &= ~PINUSE_BIT) -#define clear_cinuse(p) ((p)->head &= ~CINUSE_BIT) - -/* Treat space at ptr +/- offset as a chunk */ -#define chunk_plus_offset(p, s) ((mchunkptr)(((char*)(p)) + (s))) -#define chunk_minus_offset(p, s) ((mchunkptr)(((char*)(p)) - (s))) - -/* Ptr to next or previous physical malloc_chunk. */ -#define next_chunk(p) ((mchunkptr)( ((char*)(p)) + ((p)->head & ~INUSE_BITS))) -#define prev_chunk(p) ((mchunkptr)( ((char*)(p)) - ((p)->prev_foot) )) - -/* extract next chunk's pinuse bit */ -#define next_pinuse(p) ((next_chunk(p)->head) & PINUSE_BIT) - -/* Get/set size at footer */ -#define get_foot(p, s) (((mchunkptr)((char*)(p) + (s)))->prev_foot) -#define set_foot(p, s) (((mchunkptr)((char*)(p) + (s)))->prev_foot = (s)) - -/* Set size, pinuse bit, and foot */ -#define set_size_and_pinuse_of_free_chunk(p, s)\ - ((p)->head = (s|PINUSE_BIT), set_foot(p, s)) - -/* Set size, pinuse bit, foot, and clear next pinuse */ -#define set_free_with_pinuse(p, s, n)\ - (clear_pinuse(n), set_size_and_pinuse_of_free_chunk(p, s)) - -#define is_mmapped(p)\ - (!((p)->head & PINUSE_BIT) && ((p)->prev_foot & IS_MMAPPED_BIT)) - -/* Get the internal overhead associated with chunk p */ -#define overhead_for(p)\ - (is_mmapped(p)? MMAP_CHUNK_OVERHEAD : CHUNK_OVERHEAD) - -/* Return true if malloced space is not necessarily cleared */ -#if MMAP_CLEARS -#define calloc_must_clear(p) (!is_mmapped(p)) -#else /* MMAP_CLEARS */ -#define calloc_must_clear(p) (1) -#endif /* MMAP_CLEARS */ - -/* ---------------------- Overlaid data structures ----------------------- */ - -/* - When chunks are not in use, they are treated as nodes of either - lists or trees. - - "Small" chunks are stored in circular doubly-linked lists, and look - like this: - - chunk-> +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | Size of previous chunk | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - `head:' | Size of chunk, in bytes |P| - mem-> +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | Forward pointer to next chunk in list | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | Back pointer to previous chunk in list | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | Unused space (may be 0 bytes long) . - . . - . | -nextchunk-> +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - `foot:' | Size of chunk, in bytes | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - - Larger chunks are kept in a form of bitwise digital trees (aka - tries) keyed on chunksizes. Because malloc_tree_chunks are only for - free chunks greater than 256 bytes, their size doesn't impose any - constraints on user chunk sizes. Each node looks like: - - chunk-> +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | Size of previous chunk | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - `head:' | Size of chunk, in bytes |P| - mem-> +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | Forward pointer to next chunk of same size | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | Back pointer to previous chunk of same size | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | Pointer to left child (child[0]) | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | Pointer to right child (child[1]) | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | Pointer to parent | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | bin index of this chunk | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | Unused space . - . | -nextchunk-> +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - `foot:' | Size of chunk, in bytes | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - - Each tree holding treenodes is a tree of unique chunk sizes. Chunks - of the same size are arranged in a circularly-linked list, with only - the oldest chunk (the next to be used, in our FIFO ordering) - actually in the tree. (Tree members are distinguished by a non-null - parent pointer.) If a chunk with the same size an an existing node - is inserted, it is linked off the existing node using pointers that - work in the same way as fd/bk pointers of small chunks. - - Each tree contains a power of 2 sized range of chunk sizes (the - smallest is 0x100 <= x < 0x180), which is is divided in half at each - tree level, with the chunks in the smaller half of the range (0x100 - <= x < 0x140 for the top nose) in the left subtree and the larger - half (0x140 <= x < 0x180) in the right subtree. This is, of course, - done by inspecting individual bits. - - Using these rules, each node's left subtree contains all smaller - sizes than its right subtree. However, the node at the root of each - subtree has no particular ordering relationship to either. (The - dividing line between the subtree sizes is based on trie relation.) - If we remove the last chunk of a given size from the interior of the - tree, we need to replace it with a leaf node. The tree ordering - rules permit a node to be replaced by any leaf below it. - - The smallest chunk in a tree (a common operation in a best-fit - allocator) can be found by walking a path to the leftmost leaf in - the tree. Unlike a usual binary tree, where we follow left child - pointers until we reach a null, here we follow the right child - pointer any time the left one is null, until we reach a leaf with - both child pointers null. The smallest chunk in the tree will be - somewhere along that path. - - The worst case number of steps to add, find, or remove a node is - bounded by the number of bits differentiating chunks within - bins. Under current bin calculations, this ranges from 6 up to 21 - (for 32 bit sizes) or up to 53 (for 64 bit sizes). The typical case - is of course much better. -*/ - -struct malloc_tree_chunk -{ - /* The first four fields must be compatible with malloc_chunk */ - size_t prev_foot; - size_t head; - struct malloc_tree_chunk *fd; - struct malloc_tree_chunk *bk; - - struct malloc_tree_chunk *child[2]; - struct malloc_tree_chunk *parent; - bindex_t index; -}; - -typedef struct malloc_tree_chunk tchunk; -typedef struct malloc_tree_chunk *tchunkptr; -typedef struct malloc_tree_chunk *tbinptr; /* The type of bins of trees */ - -/* A little helper macro for trees */ -#define leftmost_child(t) ((t)->child[0] != 0? (t)->child[0] : (t)->child[1]) - -/* ----------------------------- Segments -------------------------------- */ - -/* - Each malloc space may include non-contiguous segments, held in a - list headed by an embedded malloc_segment record representing the - top-most space. Segments also include flags holding properties of - the space. Large chunks that are directly allocated by mmap are not - included in this list. They are instead independently created and - destroyed without otherwise keeping track of them. - - Segment management mainly comes into play for spaces allocated by - MMAP. Any call to MMAP might or might not return memory that is - adjacent to an existing segment. MORECORE normally contiguously - extends the current space, so this space is almost always adjacent, - which is simpler and faster to deal with. (This is why MORECORE is - used preferentially to MMAP when both are available -- see - sys_alloc.) When allocating using MMAP, we don't use any of the - hinting mechanisms (inconsistently) supported in various - implementations of unix mmap, or distinguish reserving from - committing memory. Instead, we just ask for space, and exploit - contiguity when we get it. It is probably possible to do - better than this on some systems, but no general scheme seems - to be significantly better. - - Management entails a simpler variant of the consolidation scheme - used for chunks to reduce fragmentation -- new adjacent memory is - normally prepended or appended to an existing segment. However, - there are limitations compared to chunk consolidation that mostly - reflect the fact that segment processing is relatively infrequent - (occurring only when getting memory from system) and that we - don't expect to have huge numbers of segments: - - * Segments are not indexed, so traversal requires linear scans. (It - would be possible to index these, but is not worth the extra - overhead and complexity for most programs on most platforms.) - * New segments are only appended to old ones when holding top-most - memory; if they cannot be prepended to others, they are held in - different segments. - - Except for the top-most segment of an mstate, each segment record - is kept at the tail of its segment. Segments are added by pushing - segment records onto the list headed by &mstate.seg for the - containing mstate. - - Segment flags control allocation/merge/deallocation policies: - * If EXTERN_BIT set, then we did not allocate this segment, - and so should not try to deallocate or merge with others. - (This currently holds only for the initial segment passed - into create_mspace_with_base.) - * If IS_MMAPPED_BIT set, the segment may be merged with - other surrounding mmapped segments and trimmed/de-allocated - using munmap. - * If neither bit is set, then the segment was obtained using - MORECORE so can be merged with surrounding MORECORE'd segments - and deallocated/trimmed using MORECORE with negative arguments. -*/ - -struct malloc_segment -{ - char *base; /* base address */ - size_t size; /* allocated size */ - struct malloc_segment *next; /* ptr to next segment */ - flag_t sflags; /* mmap and extern flag */ -}; - -#define is_mmapped_segment(S) ((S)->sflags & IS_MMAPPED_BIT) -#define is_extern_segment(S) ((S)->sflags & EXTERN_BIT) - -typedef struct malloc_segment msegment; -typedef struct malloc_segment *msegmentptr; - -/* ---------------------------- malloc_state ----------------------------- */ - -/* - A malloc_state holds all of the bookkeeping for a space. - The main fields are: - - Top - The topmost chunk of the currently active segment. Its size is - cached in topsize. The actual size of topmost space is - topsize+TOP_FOOT_SIZE, which includes space reserved for adding - fenceposts and segment records if necessary when getting more - space from the system. The size at which to autotrim top is - cached from mparams in trim_check, except that it is disabled if - an autotrim fails. - - Designated victim (dv) - This is the preferred chunk for servicing small requests that - don't have exact fits. It is normally the chunk split off most - recently to service another small request. Its size is cached in - dvsize. The link fields of this chunk are not maintained since it - is not kept in a bin. - - SmallBins - An array of bin headers for free chunks. These bins hold chunks - with sizes less than MIN_LARGE_SIZE bytes. Each bin contains - chunks of all the same size, spaced 8 bytes apart. To simplify - use in double-linked lists, each bin header acts as a malloc_chunk - pointing to the real first node, if it exists (else pointing to - itself). This avoids special-casing for headers. But to avoid - waste, we allocate only the fd/bk pointers of bins, and then use - repositioning tricks to treat these as the fields of a chunk. - - TreeBins - Treebins are pointers to the roots of trees holding a range of - sizes. There are 2 equally spaced treebins for each power of two - from TREE_SHIFT to TREE_SHIFT+16. The last bin holds anything - larger. - - Bin maps - There is one bit map for small bins ("smallmap") and one for - treebins ("treemap). Each bin sets its bit when non-empty, and - clears the bit when empty. Bit operations are then used to avoid - bin-by-bin searching -- nearly all "search" is done without ever - looking at bins that won't be selected. The bit maps - conservatively use 32 bits per map word, even if on 64bit system. - For a good description of some of the bit-based techniques used - here, see Henry S. Warren Jr's book "Hacker's Delight" (and - supplement at http://hackersdelight.org/). Many of these are - intended to reduce the branchiness of paths through malloc etc, as - well as to reduce the number of memory locations read or written. - - Segments - A list of segments headed by an embedded malloc_segment record - representing the initial space. - - Address check support - The least_addr field is the least address ever obtained from - MORECORE or MMAP. Attempted frees and reallocs of any address less - than this are trapped (unless INSECURE is defined). - - Magic tag - A cross-check field that should always hold same value as mparams.magic. - - Flags - Bits recording whether to use MMAP, locks, or contiguous MORECORE - - Statistics - Each space keeps track of current and maximum system memory - obtained via MORECORE or MMAP. - - Locking - If USE_LOCKS is defined, the "mutex" lock is acquired and released - around every public call using this mspace. -*/ - -/* Bin types, widths and sizes */ -#define NSMALLBINS (32U) -#define NTREEBINS (32U) -#define SMALLBIN_SHIFT (3U) -#define SMALLBIN_WIDTH (SIZE_T_ONE << SMALLBIN_SHIFT) -#define TREEBIN_SHIFT (8U) -#define MIN_LARGE_SIZE (SIZE_T_ONE << TREEBIN_SHIFT) -#define MAX_SMALL_SIZE (MIN_LARGE_SIZE - SIZE_T_ONE) -#define MAX_SMALL_REQUEST (MAX_SMALL_SIZE - CHUNK_ALIGN_MASK - CHUNK_OVERHEAD) - -struct malloc_state -{ - binmap_t smallmap; - binmap_t treemap; - size_t dvsize; - size_t topsize; - char *least_addr; - mchunkptr dv; - mchunkptr top; - size_t trim_check; - size_t magic; - mchunkptr smallbins[(NSMALLBINS + 1) * 2]; - tbinptr treebins[NTREEBINS]; - size_t footprint; - size_t max_footprint; - flag_t mflags; -#if USE_LOCKS - MLOCK_T mutex; /* locate lock among fields that rarely change */ -#endif /* USE_LOCKS */ - msegment seg; -}; - -typedef struct malloc_state *mstate; - -/* ------------- Global malloc_state and malloc_params ------------------- */ - -/* - malloc_params holds global properties, including those that can be - dynamically set using mallopt. There is a single instance, mparams, - initialized in init_mparams. -*/ - -struct malloc_params -{ - size_t magic; - size_t page_size; - size_t granularity; - size_t mmap_threshold; - size_t trim_threshold; - flag_t default_mflags; -}; - -static struct malloc_params mparams; - -/* The global malloc_state used for all non-"mspace" calls */ -static struct malloc_state _gm_; -#define gm (&_gm_) -#define is_global(M) ((M) == &_gm_) -#define is_initialized(M) ((M)->top != 0) - -/* -------------------------- system alloc setup ------------------------- */ - -/* Operations on mflags */ - -#define use_lock(M) ((M)->mflags & USE_LOCK_BIT) -#define enable_lock(M) ((M)->mflags |= USE_LOCK_BIT) -#define disable_lock(M) ((M)->mflags &= ~USE_LOCK_BIT) - -#define use_mmap(M) ((M)->mflags & USE_MMAP_BIT) -#define enable_mmap(M) ((M)->mflags |= USE_MMAP_BIT) -#define disable_mmap(M) ((M)->mflags &= ~USE_MMAP_BIT) - -#define use_noncontiguous(M) ((M)->mflags & USE_NONCONTIGUOUS_BIT) -#define disable_contiguous(M) ((M)->mflags |= USE_NONCONTIGUOUS_BIT) - -#define set_lock(M,L)\ - ((M)->mflags = (L)?\ - ((M)->mflags | USE_LOCK_BIT) :\ - ((M)->mflags & ~USE_LOCK_BIT)) - -/* page-align a size */ -#define page_align(S)\ - (((S) + (mparams.page_size)) & ~(mparams.page_size - SIZE_T_ONE)) - -/* granularity-align a size */ -#define granularity_align(S)\ - (((S) + (mparams.granularity)) & ~(mparams.granularity - SIZE_T_ONE)) - -#define is_page_aligned(S)\ - (((size_t)(S) & (mparams.page_size - SIZE_T_ONE)) == 0) -#define is_granularity_aligned(S)\ - (((size_t)(S) & (mparams.granularity - SIZE_T_ONE)) == 0) - -/* True if segment S holds address A */ -#define segment_holds(S, A)\ - ((char*)(A) >= S->base && (char*)(A) < S->base + S->size) - -/* Return segment holding given address */ -static msegmentptr -segment_holding(mstate m, char *addr) -{ - msegmentptr sp = &m->seg; - for (;;) { - if (addr >= sp->base && addr < sp->base + sp->size) - return sp; - if ((sp = sp->next) == 0) - return 0; - } -} - -/* Return true if segment contains a segment link */ -static int -has_segment_link(mstate m, msegmentptr ss) -{ - msegmentptr sp = &m->seg; - for (;;) { - if ((char *) sp >= ss->base && (char *) sp < ss->base + ss->size) - return 1; - if ((sp = sp->next) == 0) - return 0; - } -} - -#ifndef MORECORE_CANNOT_TRIM -#define should_trim(M,s) ((s) > (M)->trim_check) -#else /* MORECORE_CANNOT_TRIM */ -#define should_trim(M,s) (0) -#endif /* MORECORE_CANNOT_TRIM */ - -/* - TOP_FOOT_SIZE is padding at the end of a segment, including space - that may be needed to place segment records and fenceposts when new - noncontiguous segments are added. -*/ -#define TOP_FOOT_SIZE\ - (align_offset(chunk2mem(0))+pad_request(sizeof(struct malloc_segment))+MIN_CHUNK_SIZE) - - -/* ------------------------------- Hooks -------------------------------- */ - -/* - PREACTION should be defined to return 0 on success, and nonzero on - failure. If you are not using locking, you can redefine these to do - anything you like. -*/ - -#if USE_LOCKS - -/* Ensure locks are initialized */ -#define GLOBALLY_INITIALIZE() (mparams.page_size == 0 && init_mparams()) - -#define PREACTION(M) ((GLOBALLY_INITIALIZE() || use_lock(M))? ACQUIRE_LOCK(&(M)->mutex) : 0) -#define POSTACTION(M) { if (use_lock(M)) RELEASE_LOCK(&(M)->mutex); } -#else /* USE_LOCKS */ - -#ifndef PREACTION -#define PREACTION(M) (0) -#endif /* PREACTION */ - -#ifndef POSTACTION -#define POSTACTION(M) -#endif /* POSTACTION */ - -#endif /* USE_LOCKS */ - -/* - CORRUPTION_ERROR_ACTION is triggered upon detected bad addresses. - USAGE_ERROR_ACTION is triggered on detected bad frees and - reallocs. The argument p is an address that might have triggered the - fault. It is ignored by the two predefined actions, but might be - useful in custom actions that try to help diagnose errors. -*/ - -#if PROCEED_ON_ERROR - -/* A count of the number of corruption errors causing resets */ -int malloc_corruption_error_count; - -/* default corruption action */ -static void reset_on_error(mstate m); - -#define CORRUPTION_ERROR_ACTION(m) reset_on_error(m) -#define USAGE_ERROR_ACTION(m, p) - -#else /* PROCEED_ON_ERROR */ - -#ifndef CORRUPTION_ERROR_ACTION -#define CORRUPTION_ERROR_ACTION(m) ABORT -#endif /* CORRUPTION_ERROR_ACTION */ - -#ifndef USAGE_ERROR_ACTION -#define USAGE_ERROR_ACTION(m,p) ABORT -#endif /* USAGE_ERROR_ACTION */ - -#endif /* PROCEED_ON_ERROR */ - -/* -------------------------- Debugging setup ---------------------------- */ - -#if ! DEBUG - -#define check_free_chunk(M,P) -#define check_inuse_chunk(M,P) -#define check_malloced_chunk(M,P,N) -#define check_mmapped_chunk(M,P) -#define check_malloc_state(M) -#define check_top_chunk(M,P) - -#else /* DEBUG */ -#define check_free_chunk(M,P) do_check_free_chunk(M,P) -#define check_inuse_chunk(M,P) do_check_inuse_chunk(M,P) -#define check_top_chunk(M,P) do_check_top_chunk(M,P) -#define check_malloced_chunk(M,P,N) do_check_malloced_chunk(M,P,N) -#define check_mmapped_chunk(M,P) do_check_mmapped_chunk(M,P) -#define check_malloc_state(M) do_check_malloc_state(M) - -static void do_check_any_chunk(mstate m, mchunkptr p); -static void do_check_top_chunk(mstate m, mchunkptr p); -static void do_check_mmapped_chunk(mstate m, mchunkptr p); -static void do_check_inuse_chunk(mstate m, mchunkptr p); -static void do_check_free_chunk(mstate m, mchunkptr p); -static void do_check_malloced_chunk(mstate m, void *mem, size_t s); -static void do_check_tree(mstate m, tchunkptr t); -static void do_check_treebin(mstate m, bindex_t i); -static void do_check_smallbin(mstate m, bindex_t i); -static void do_check_malloc_state(mstate m); -static int bin_find(mstate m, mchunkptr x); -static size_t traverse_and_check(mstate m); -#endif /* DEBUG */ - -/* ---------------------------- Indexing Bins ---------------------------- */ - -#define is_small(s) (((s) >> SMALLBIN_SHIFT) < NSMALLBINS) -#define small_index(s) ((s) >> SMALLBIN_SHIFT) -#define small_index2size(i) ((i) << SMALLBIN_SHIFT) -#define MIN_SMALL_INDEX (small_index(MIN_CHUNK_SIZE)) - -/* addressing by index. See above about smallbin repositioning */ -#define smallbin_at(M, i) ((sbinptr)((char*)&((M)->smallbins[(i)<<1]))) -#define treebin_at(M,i) (&((M)->treebins[i])) - -/* assign tree index for size S to variable I */ -#if defined(__GNUC__) && defined(i386) -#define compute_tree_index(S, I)\ -{\ - size_t X = S >> TREEBIN_SHIFT;\ - if (X == 0)\ - I = 0;\ - else if (X > 0xFFFF)\ - I = NTREEBINS-1;\ - else {\ - unsigned int K;\ - __asm__("bsrl %1,%0\n\t" : "=r" (K) : "rm" (X));\ - I = (bindex_t)((K << 1) + ((S >> (K + (TREEBIN_SHIFT-1)) & 1)));\ - }\ -} -#else /* GNUC */ -#define compute_tree_index(S, I)\ -{\ - size_t X = S >> TREEBIN_SHIFT;\ - if (X == 0)\ - I = 0;\ - else if (X > 0xFFFF)\ - I = NTREEBINS-1;\ - else {\ - unsigned int Y = (unsigned int)X;\ - unsigned int N = ((Y - 0x100) >> 16) & 8;\ - unsigned int K = (((Y <<= N) - 0x1000) >> 16) & 4;\ - N += K;\ - N += K = (((Y <<= K) - 0x4000) >> 16) & 2;\ - K = 14 - N + ((Y <<= K) >> 15);\ - I = (K << 1) + ((S >> (K + (TREEBIN_SHIFT-1)) & 1));\ - }\ -} -#endif /* GNUC */ - -/* Bit representing maximum resolved size in a treebin at i */ -#define bit_for_tree_index(i) \ - (i == NTREEBINS-1)? (SIZE_T_BITSIZE-1) : (((i) >> 1) + TREEBIN_SHIFT - 2) - -/* Shift placing maximum resolved bit in a treebin at i as sign bit */ -#define leftshift_for_tree_index(i) \ - ((i == NTREEBINS-1)? 0 : \ - ((SIZE_T_BITSIZE-SIZE_T_ONE) - (((i) >> 1) + TREEBIN_SHIFT - 2))) - -/* The size of the smallest chunk held in bin with index i */ -#define minsize_for_tree_index(i) \ - ((SIZE_T_ONE << (((i) >> 1) + TREEBIN_SHIFT)) | \ - (((size_t)((i) & SIZE_T_ONE)) << (((i) >> 1) + TREEBIN_SHIFT - 1))) - - -/* ------------------------ Operations on bin maps ----------------------- */ - -/* bit corresponding to given index */ -#define idx2bit(i) ((binmap_t)(1) << (i)) - -/* Mark/Clear bits with given index */ -#define mark_smallmap(M,i) ((M)->smallmap |= idx2bit(i)) -#define clear_smallmap(M,i) ((M)->smallmap &= ~idx2bit(i)) -#define smallmap_is_marked(M,i) ((M)->smallmap & idx2bit(i)) - -#define mark_treemap(M,i) ((M)->treemap |= idx2bit(i)) -#define clear_treemap(M,i) ((M)->treemap &= ~idx2bit(i)) -#define treemap_is_marked(M,i) ((M)->treemap & idx2bit(i)) - -/* index corresponding to given bit */ - -#if defined(__GNUC__) && defined(i386) -#define compute_bit2idx(X, I)\ -{\ - unsigned int J;\ - __asm__("bsfl %1,%0\n\t" : "=r" (J) : "rm" (X));\ - I = (bindex_t)J;\ -} - -#else /* GNUC */ -#if USE_BUILTIN_FFS -#define compute_bit2idx(X, I) I = ffs(X)-1 - -#else /* USE_BUILTIN_FFS */ -#define compute_bit2idx(X, I)\ -{\ - unsigned int Y = X - 1;\ - unsigned int K = Y >> (16-4) & 16;\ - unsigned int N = K; Y >>= K;\ - N += K = Y >> (8-3) & 8; Y >>= K;\ - N += K = Y >> (4-2) & 4; Y >>= K;\ - N += K = Y >> (2-1) & 2; Y >>= K;\ - N += K = Y >> (1-0) & 1; Y >>= K;\ - I = (bindex_t)(N + Y);\ -} -#endif /* USE_BUILTIN_FFS */ -#endif /* GNUC */ - -/* isolate the least set bit of a bitmap */ -#define least_bit(x) ((x) & -(x)) - -/* mask with all bits to left of least bit of x on */ -#define left_bits(x) ((x<<1) | -(x<<1)) - -/* mask with all bits to left of or equal to least bit of x on */ -#define same_or_left_bits(x) ((x) | -(x)) - - -/* ----------------------- Runtime Check Support ------------------------- */ - -/* - For security, the main invariant is that malloc/free/etc never - writes to a static address other than malloc_state, unless static - malloc_state itself has been corrupted, which cannot occur via - malloc (because of these checks). In essence this means that we - believe all pointers, sizes, maps etc held in malloc_state, but - check all of those linked or offsetted from other embedded data - structures. These checks are interspersed with main code in a way - that tends to minimize their run-time cost. - - When FOOTERS is defined, in addition to range checking, we also - verify footer fields of inuse chunks, which can be used guarantee - that the mstate controlling malloc/free is intact. This is a - streamlined version of the approach described by William Robertson - et al in "Run-time Detection of Heap-based Overflows" LISA'03 - http://www.usenix.org/events/lisa03/tech/robertson.html The footer - of an inuse chunk holds the xor of its mstate and a random seed, - that is checked upon calls to free() and realloc(). This is - (probablistically) unguessable from outside the program, but can be - computed by any code successfully malloc'ing any chunk, so does not - itself provide protection against code that has already broken - security through some other means. Unlike Robertson et al, we - always dynamically check addresses of all offset chunks (previous, - next, etc). This turns out to be cheaper than relying on hashes. -*/ - -#if !INSECURE -/* Check if address a is at least as high as any from MORECORE or MMAP */ -#define ok_address(M, a) ((char*)(a) >= (M)->least_addr) -/* Check if address of next chunk n is higher than base chunk p */ -#define ok_next(p, n) ((char*)(p) < (char*)(n)) -/* Check if p has its cinuse bit on */ -#define ok_cinuse(p) cinuse(p) -/* Check if p has its pinuse bit on */ -#define ok_pinuse(p) pinuse(p) - -#else /* !INSECURE */ -#define ok_address(M, a) (1) -#define ok_next(b, n) (1) -#define ok_cinuse(p) (1) -#define ok_pinuse(p) (1) -#endif /* !INSECURE */ - -#if (FOOTERS && !INSECURE) -/* Check if (alleged) mstate m has expected magic field */ -#define ok_magic(M) ((M)->magic == mparams.magic) -#else /* (FOOTERS && !INSECURE) */ -#define ok_magic(M) (1) -#endif /* (FOOTERS && !INSECURE) */ - - -/* In gcc, use __builtin_expect to minimize impact of checks */ -#if !INSECURE -#if defined(__GNUC__) && __GNUC__ >= 3 -#define RTCHECK(e) __builtin_expect(e, 1) -#else /* GNUC */ -#define RTCHECK(e) (e) -#endif /* GNUC */ -#else /* !INSECURE */ -#define RTCHECK(e) (1) -#endif /* !INSECURE */ - -/* macros to set up inuse chunks with or without footers */ - -#if !FOOTERS - -#define mark_inuse_foot(M,p,s) - -/* Set cinuse bit and pinuse bit of next chunk */ -#define set_inuse(M,p,s)\ - ((p)->head = (((p)->head & PINUSE_BIT)|s|CINUSE_BIT),\ - ((mchunkptr)(((char*)(p)) + (s)))->head |= PINUSE_BIT) - -/* Set cinuse and pinuse of this chunk and pinuse of next chunk */ -#define set_inuse_and_pinuse(M,p,s)\ - ((p)->head = (s|PINUSE_BIT|CINUSE_BIT),\ - ((mchunkptr)(((char*)(p)) + (s)))->head |= PINUSE_BIT) - -/* Set size, cinuse and pinuse bit of this chunk */ -#define set_size_and_pinuse_of_inuse_chunk(M, p, s)\ - ((p)->head = (s|PINUSE_BIT|CINUSE_BIT)) - -#else /* FOOTERS */ - -/* Set foot of inuse chunk to be xor of mstate and seed */ -#define mark_inuse_foot(M,p,s)\ - (((mchunkptr)((char*)(p) + (s)))->prev_foot = ((size_t)(M) ^ mparams.magic)) - -#define get_mstate_for(p)\ - ((mstate)(((mchunkptr)((char*)(p) +\ - (chunksize(p))))->prev_foot ^ mparams.magic)) - -#define set_inuse(M,p,s)\ - ((p)->head = (((p)->head & PINUSE_BIT)|s|CINUSE_BIT),\ - (((mchunkptr)(((char*)(p)) + (s)))->head |= PINUSE_BIT), \ - mark_inuse_foot(M,p,s)) - -#define set_inuse_and_pinuse(M,p,s)\ - ((p)->head = (s|PINUSE_BIT|CINUSE_BIT),\ - (((mchunkptr)(((char*)(p)) + (s)))->head |= PINUSE_BIT),\ - mark_inuse_foot(M,p,s)) - -#define set_size_and_pinuse_of_inuse_chunk(M, p, s)\ - ((p)->head = (s|PINUSE_BIT|CINUSE_BIT),\ - mark_inuse_foot(M, p, s)) - -#endif /* !FOOTERS */ - -/* ---------------------------- setting mparams -------------------------- */ - -/* Initialize mparams */ -static int -init_mparams(void) -{ - if (mparams.page_size == 0) { - size_t s; - - mparams.mmap_threshold = DEFAULT_MMAP_THRESHOLD; - mparams.trim_threshold = DEFAULT_TRIM_THRESHOLD; -#if MORECORE_CONTIGUOUS - mparams.default_mflags = USE_LOCK_BIT | USE_MMAP_BIT; -#else /* MORECORE_CONTIGUOUS */ - mparams.default_mflags = - USE_LOCK_BIT | USE_MMAP_BIT | USE_NONCONTIGUOUS_BIT; -#endif /* MORECORE_CONTIGUOUS */ - -#if (FOOTERS && !INSECURE) - { -#if USE_DEV_RANDOM - int fd; - unsigned char buf[sizeof(size_t)]; - /* Try to use /dev/urandom, else fall back on using time */ - if ((fd = open("/dev/urandom", O_RDONLY)) >= 0 && - read(fd, buf, sizeof(buf)) == sizeof(buf)) { - s = *((size_t *) buf); - close(fd); - } else -#endif /* USE_DEV_RANDOM */ - s = (size_t) (time(0) ^ (size_t) 0x55555555U); - - s |= (size_t) 8U; /* ensure nonzero */ - s &= ~(size_t) 7U; /* improve chances of fault for bad values */ - - } -#else /* (FOOTERS && !INSECURE) */ - s = (size_t) 0x58585858U; -#endif /* (FOOTERS && !INSECURE) */ - ACQUIRE_MAGIC_INIT_LOCK(); - if (mparams.magic == 0) { - mparams.magic = s; - /* Set up lock for main malloc area */ - INITIAL_LOCK(&gm->mutex); - gm->mflags = mparams.default_mflags; - } - RELEASE_MAGIC_INIT_LOCK(); - -#ifndef WIN32 - mparams.page_size = malloc_getpagesize; - mparams.granularity = ((DEFAULT_GRANULARITY != 0) ? - DEFAULT_GRANULARITY : mparams.page_size); -#else /* WIN32 */ - { - SYSTEM_INFO system_info; - GetSystemInfo(&system_info); - mparams.page_size = system_info.dwPageSize; - mparams.granularity = system_info.dwAllocationGranularity; - } -#endif /* WIN32 */ - - /* Sanity-check configuration: - size_t must be unsigned and as wide as pointer type. - ints must be at least 4 bytes. - alignment must be at least 8. - Alignment, min chunk size, and page size must all be powers of 2. - */ - if ((sizeof(size_t) != sizeof(char *)) || - (MAX_SIZE_T < MIN_CHUNK_SIZE) || - (sizeof(int) < 4) || - (MALLOC_ALIGNMENT < (size_t) 8U) || - ((MALLOC_ALIGNMENT & (MALLOC_ALIGNMENT - SIZE_T_ONE)) != 0) || - ((MCHUNK_SIZE & (MCHUNK_SIZE - SIZE_T_ONE)) != 0) || - ((mparams.granularity & (mparams.granularity - SIZE_T_ONE)) != 0) - || ((mparams.page_size & (mparams.page_size - SIZE_T_ONE)) != 0)) - ABORT; - } - return 0; -} - -/* support for mallopt */ -static int -change_mparam(int param_number, int value) -{ - size_t val = (size_t) value; - init_mparams(); - switch (param_number) { - case M_TRIM_THRESHOLD: - mparams.trim_threshold = val; - return 1; - case M_GRANULARITY: - if (val >= mparams.page_size && ((val & (val - 1)) == 0)) { - mparams.granularity = val; - return 1; - } else - return 0; - case M_MMAP_THRESHOLD: - mparams.mmap_threshold = val; - return 1; - default: - return 0; - } -} - -#if DEBUG -/* ------------------------- Debugging Support --------------------------- */ - -/* Check properties of any chunk, whether free, inuse, mmapped etc */ -static void -do_check_any_chunk(mstate m, mchunkptr p) -{ - assert((is_aligned(chunk2mem(p))) || (p->head == FENCEPOST_HEAD)); - assert(ok_address(m, p)); -} - -/* Check properties of top chunk */ -static void -do_check_top_chunk(mstate m, mchunkptr p) -{ - msegmentptr sp = segment_holding(m, (char *) p); - size_t sz = chunksize(p); - assert(sp != 0); - assert((is_aligned(chunk2mem(p))) || (p->head == FENCEPOST_HEAD)); - assert(ok_address(m, p)); - assert(sz == m->topsize); - assert(sz > 0); - assert(sz == ((sp->base + sp->size) - (char *) p) - TOP_FOOT_SIZE); - assert(pinuse(p)); - assert(!next_pinuse(p)); -} - -/* Check properties of (inuse) mmapped chunks */ -static void -do_check_mmapped_chunk(mstate m, mchunkptr p) -{ - size_t sz = chunksize(p); - size_t len = (sz + (p->prev_foot & ~IS_MMAPPED_BIT) + MMAP_FOOT_PAD); - assert(is_mmapped(p)); - assert(use_mmap(m)); - assert((is_aligned(chunk2mem(p))) || (p->head == FENCEPOST_HEAD)); - assert(ok_address(m, p)); - assert(!is_small(sz)); - assert((len & (mparams.page_size - SIZE_T_ONE)) == 0); - assert(chunk_plus_offset(p, sz)->head == FENCEPOST_HEAD); - assert(chunk_plus_offset(p, sz + SIZE_T_SIZE)->head == 0); -} - -/* Check properties of inuse chunks */ -static void -do_check_inuse_chunk(mstate m, mchunkptr p) -{ - do_check_any_chunk(m, p); - assert(cinuse(p)); - assert(next_pinuse(p)); - /* If not pinuse and not mmapped, previous chunk has OK offset */ - assert(is_mmapped(p) || pinuse(p) || next_chunk(prev_chunk(p)) == p); - if (is_mmapped(p)) - do_check_mmapped_chunk(m, p); -} - -/* Check properties of free chunks */ -static void -do_check_free_chunk(mstate m, mchunkptr p) -{ - size_t sz = p->head & ~(PINUSE_BIT | CINUSE_BIT); - mchunkptr next = chunk_plus_offset(p, sz); - do_check_any_chunk(m, p); - assert(!cinuse(p)); - assert(!next_pinuse(p)); - assert(!is_mmapped(p)); - if (p != m->dv && p != m->top) { - if (sz >= MIN_CHUNK_SIZE) { - assert((sz & CHUNK_ALIGN_MASK) == 0); - assert(is_aligned(chunk2mem(p))); - assert(next->prev_foot == sz); - assert(pinuse(p)); - assert(next == m->top || cinuse(next)); - assert(p->fd->bk == p); - assert(p->bk->fd == p); - } else /* markers are always of size SIZE_T_SIZE */ - assert(sz == SIZE_T_SIZE); - } -} - -/* Check properties of malloced chunks at the point they are malloced */ -static void -do_check_malloced_chunk(mstate m, void *mem, size_t s) -{ - if (mem != 0) { - mchunkptr p = mem2chunk(mem); - size_t sz = p->head & ~(PINUSE_BIT | CINUSE_BIT); - do_check_inuse_chunk(m, p); - assert((sz & CHUNK_ALIGN_MASK) == 0); - assert(sz >= MIN_CHUNK_SIZE); - assert(sz >= s); - /* unless mmapped, size is less than MIN_CHUNK_SIZE more than request */ - assert(is_mmapped(p) || sz < (s + MIN_CHUNK_SIZE)); - } -} - -/* Check a tree and its subtrees. */ -static void -do_check_tree(mstate m, tchunkptr t) -{ - tchunkptr head = 0; - tchunkptr u = t; - bindex_t tindex = t->index; - size_t tsize = chunksize(t); - bindex_t idx; - compute_tree_index(tsize, idx); - assert(tindex == idx); - assert(tsize >= MIN_LARGE_SIZE); - assert(tsize >= minsize_for_tree_index(idx)); - assert((idx == NTREEBINS - 1) - || (tsize < minsize_for_tree_index((idx + 1)))); - - do { /* traverse through chain of same-sized nodes */ - do_check_any_chunk(m, ((mchunkptr) u)); - assert(u->index == tindex); - assert(chunksize(u) == tsize); - assert(!cinuse(u)); - assert(!next_pinuse(u)); - assert(u->fd->bk == u); - assert(u->bk->fd == u); - if (u->parent == 0) { - assert(u->child[0] == 0); - assert(u->child[1] == 0); - } else { - assert(head == 0); /* only one node on chain has parent */ - head = u; - assert(u->parent != u); - assert(u->parent->child[0] == u || - u->parent->child[1] == u || - *((tbinptr *) (u->parent)) == u); - if (u->child[0] != 0) { - assert(u->child[0]->parent == u); - assert(u->child[0] != u); - do_check_tree(m, u->child[0]); - } - if (u->child[1] != 0) { - assert(u->child[1]->parent == u); - assert(u->child[1] != u); - do_check_tree(m, u->child[1]); - } - if (u->child[0] != 0 && u->child[1] != 0) { - assert(chunksize(u->child[0]) < chunksize(u->child[1])); - } - } - u = u->fd; - } while (u != t); - assert(head != 0); -} - -/* Check all the chunks in a treebin. */ -static void -do_check_treebin(mstate m, bindex_t i) -{ - tbinptr *tb = treebin_at(m, i); - tchunkptr t = *tb; - int empty = (m->treemap & (1U << i)) == 0; - if (t == 0) - assert(empty); - if (!empty) - do_check_tree(m, t); -} - -/* Check all the chunks in a smallbin. */ -static void -do_check_smallbin(mstate m, bindex_t i) -{ - sbinptr b = smallbin_at(m, i); - mchunkptr p = b->bk; - unsigned int empty = (m->smallmap & (1U << i)) == 0; - if (p == b) - assert(empty); - if (!empty) { - for (; p != b; p = p->bk) { - size_t size = chunksize(p); - mchunkptr q; - /* each chunk claims to be free */ - do_check_free_chunk(m, p); - /* chunk belongs in bin */ - assert(small_index(size) == i); - assert(p->bk == b || chunksize(p->bk) == chunksize(p)); - /* chunk is followed by an inuse chunk */ - q = next_chunk(p); - if (q->head != FENCEPOST_HEAD) - do_check_inuse_chunk(m, q); - } - } -} - -/* Find x in a bin. Used in other check functions. */ -static int -bin_find(mstate m, mchunkptr x) -{ - size_t size = chunksize(x); - if (is_small(size)) { - bindex_t sidx = small_index(size); - sbinptr b = smallbin_at(m, sidx); - if (smallmap_is_marked(m, sidx)) { - mchunkptr p = b; - do { - if (p == x) - return 1; - } while ((p = p->fd) != b); - } - } else { - bindex_t tidx; - compute_tree_index(size, tidx); - if (treemap_is_marked(m, tidx)) { - tchunkptr t = *treebin_at(m, tidx); - size_t sizebits = size << leftshift_for_tree_index(tidx); - while (t != 0 && chunksize(t) != size) { - t = t->child[(sizebits >> (SIZE_T_BITSIZE - SIZE_T_ONE)) & 1]; - sizebits <<= 1; - } - if (t != 0) { - tchunkptr u = t; - do { - if (u == (tchunkptr) x) - return 1; - } while ((u = u->fd) != t); - } - } - } - return 0; -} - -/* Traverse each chunk and check it; return total */ -static size_t -traverse_and_check(mstate m) -{ - size_t sum = 0; - if (is_initialized(m)) { - msegmentptr s = &m->seg; - sum += m->topsize + TOP_FOOT_SIZE; - while (s != 0) { - mchunkptr q = align_as_chunk(s->base); - mchunkptr lastq = 0; - assert(pinuse(q)); - while (segment_holds(s, q) && - q != m->top && q->head != FENCEPOST_HEAD) { - sum += chunksize(q); - if (cinuse(q)) { - assert(!bin_find(m, q)); - do_check_inuse_chunk(m, q); - } else { - assert(q == m->dv || bin_find(m, q)); - assert(lastq == 0 || cinuse(lastq)); /* Not 2 consecutive free */ - do_check_free_chunk(m, q); - } - lastq = q; - q = next_chunk(q); - } - s = s->next; - } - } - return sum; -} - -/* Check all properties of malloc_state. */ -static void -do_check_malloc_state(mstate m) -{ - bindex_t i; - size_t total; - /* check bins */ - for (i = 0; i < NSMALLBINS; ++i) - do_check_smallbin(m, i); - for (i = 0; i < NTREEBINS; ++i) - do_check_treebin(m, i); - - if (m->dvsize != 0) { /* check dv chunk */ - do_check_any_chunk(m, m->dv); - assert(m->dvsize == chunksize(m->dv)); - assert(m->dvsize >= MIN_CHUNK_SIZE); - assert(bin_find(m, m->dv) == 0); - } - - if (m->top != 0) { /* check top chunk */ - do_check_top_chunk(m, m->top); - assert(m->topsize == chunksize(m->top)); - assert(m->topsize > 0); - assert(bin_find(m, m->top) == 0); - } - - total = traverse_and_check(m); - assert(total <= m->footprint); - assert(m->footprint <= m->max_footprint); -} -#endif /* DEBUG */ - -/* ----------------------------- statistics ------------------------------ */ - -#if !NO_MALLINFO -static struct mallinfo -internal_mallinfo(mstate m) -{ - struct mallinfo nm = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; - if (!PREACTION(m)) { - check_malloc_state(m); - if (is_initialized(m)) { - size_t nfree = SIZE_T_ONE; /* top always free */ - size_t mfree = m->topsize + TOP_FOOT_SIZE; - size_t sum = mfree; - msegmentptr s = &m->seg; - while (s != 0) { - mchunkptr q = align_as_chunk(s->base); - while (segment_holds(s, q) && - q != m->top && q->head != FENCEPOST_HEAD) { - size_t sz = chunksize(q); - sum += sz; - if (!cinuse(q)) { - mfree += sz; - ++nfree; - } - q = next_chunk(q); - } - s = s->next; - } - - nm.arena = sum; - nm.ordblks = nfree; - nm.hblkhd = m->footprint - sum; - nm.usmblks = m->max_footprint; - nm.uordblks = m->footprint - mfree; - nm.fordblks = mfree; - nm.keepcost = m->topsize; - } - - POSTACTION(m); - } - return nm; -} -#endif /* !NO_MALLINFO */ - -static void -internal_malloc_stats(mstate m) -{ - if (!PREACTION(m)) { - size_t maxfp = 0; - size_t fp = 0; - size_t used = 0; - check_malloc_state(m); - if (is_initialized(m)) { - msegmentptr s = &m->seg; - maxfp = m->max_footprint; - fp = m->footprint; - used = fp - (m->topsize + TOP_FOOT_SIZE); - - while (s != 0) { - mchunkptr q = align_as_chunk(s->base); - while (segment_holds(s, q) && - q != m->top && q->head != FENCEPOST_HEAD) { - if (!cinuse(q)) - used -= chunksize(q); - q = next_chunk(q); - } - s = s->next; - } - } -#ifndef LACKS_STDIO_H - fprintf(stderr, "max system bytes = %10lu\n", - (unsigned long) (maxfp)); - fprintf(stderr, "system bytes = %10lu\n", (unsigned long) (fp)); - fprintf(stderr, "in use bytes = %10lu\n", (unsigned long) (used)); -#endif - - POSTACTION(m); - } -} - -/* ----------------------- Operations on smallbins ----------------------- */ - -/* - Various forms of linking and unlinking are defined as macros. Even - the ones for trees, which are very long but have very short typical - paths. This is ugly but reduces reliance on inlining support of - compilers. -*/ - -/* Link a free chunk into a smallbin */ -#define insert_small_chunk(M, P, S) {\ - bindex_t I = small_index(S);\ - mchunkptr B = smallbin_at(M, I);\ - mchunkptr F = B;\ - assert(S >= MIN_CHUNK_SIZE);\ - if (!smallmap_is_marked(M, I))\ - mark_smallmap(M, I);\ - else if (RTCHECK(ok_address(M, B->fd)))\ - F = B->fd;\ - else {\ - CORRUPTION_ERROR_ACTION(M);\ - }\ - B->fd = P;\ - F->bk = P;\ - P->fd = F;\ - P->bk = B;\ -} - -/* Unlink a chunk from a smallbin */ -#define unlink_small_chunk(M, P, S) {\ - mchunkptr F = P->fd;\ - mchunkptr B = P->bk;\ - bindex_t I = small_index(S);\ - assert(P != B);\ - assert(P != F);\ - assert(chunksize(P) == small_index2size(I));\ - if (F == B)\ - clear_smallmap(M, I);\ - else if (RTCHECK((F == smallbin_at(M,I) || ok_address(M, F)) &&\ - (B == smallbin_at(M,I) || ok_address(M, B)))) {\ - F->bk = B;\ - B->fd = F;\ - }\ - else {\ - CORRUPTION_ERROR_ACTION(M);\ - }\ -} - -/* Unlink the first chunk from a smallbin */ -#define unlink_first_small_chunk(M, B, P, I) {\ - mchunkptr F = P->fd;\ - assert(P != B);\ - assert(P != F);\ - assert(chunksize(P) == small_index2size(I));\ - if (B == F)\ - clear_smallmap(M, I);\ - else if (RTCHECK(ok_address(M, F))) {\ - B->fd = F;\ - F->bk = B;\ - }\ - else {\ - CORRUPTION_ERROR_ACTION(M);\ - }\ -} - -/* Replace dv node, binning the old one */ -/* Used only when dvsize known to be small */ -#define replace_dv(M, P, S) {\ - size_t DVS = M->dvsize;\ - if (DVS != 0) {\ - mchunkptr DV = M->dv;\ - assert(is_small(DVS));\ - insert_small_chunk(M, DV, DVS);\ - }\ - M->dvsize = S;\ - M->dv = P;\ -} - -/* ------------------------- Operations on trees ------------------------- */ - -/* Insert chunk into tree */ -#define insert_large_chunk(M, X, S) {\ - tbinptr* H;\ - bindex_t I;\ - compute_tree_index(S, I);\ - H = treebin_at(M, I);\ - X->index = I;\ - X->child[0] = X->child[1] = 0;\ - if (!treemap_is_marked(M, I)) {\ - mark_treemap(M, I);\ - *H = X;\ - X->parent = (tchunkptr)H;\ - X->fd = X->bk = X;\ - }\ - else {\ - tchunkptr T = *H;\ - size_t K = S << leftshift_for_tree_index(I);\ - for (;;) {\ - if (chunksize(T) != S) {\ - tchunkptr* C = &(T->child[(K >> (SIZE_T_BITSIZE-SIZE_T_ONE)) & 1]);\ - K <<= 1;\ - if (*C != 0)\ - T = *C;\ - else if (RTCHECK(ok_address(M, C))) {\ - *C = X;\ - X->parent = T;\ - X->fd = X->bk = X;\ - break;\ - }\ - else {\ - CORRUPTION_ERROR_ACTION(M);\ - break;\ - }\ - }\ - else {\ - tchunkptr F = T->fd;\ - if (RTCHECK(ok_address(M, T) && ok_address(M, F))) {\ - T->fd = F->bk = X;\ - X->fd = F;\ - X->bk = T;\ - X->parent = 0;\ - break;\ - }\ - else {\ - CORRUPTION_ERROR_ACTION(M);\ - break;\ - }\ - }\ - }\ - }\ -} - -/* - Unlink steps: - - 1. If x is a chained node, unlink it from its same-sized fd/bk links - and choose its bk node as its replacement. - 2. If x was the last node of its size, but not a leaf node, it must - be replaced with a leaf node (not merely one with an open left or - right), to make sure that lefts and rights of descendents - correspond properly to bit masks. We use the rightmost descendent - of x. We could use any other leaf, but this is easy to locate and - tends to counteract removal of leftmosts elsewhere, and so keeps - paths shorter than minimally guaranteed. This doesn't loop much - because on average a node in a tree is near the bottom. - 3. If x is the base of a chain (i.e., has parent links) relink - x's parent and children to x's replacement (or null if none). -*/ - -#define unlink_large_chunk(M, X) {\ - tchunkptr XP = X->parent;\ - tchunkptr R;\ - if (X->bk != X) {\ - tchunkptr F = X->fd;\ - R = X->bk;\ - if (RTCHECK(ok_address(M, F))) {\ - F->bk = R;\ - R->fd = F;\ - }\ - else {\ - CORRUPTION_ERROR_ACTION(M);\ - }\ - }\ - else {\ - tchunkptr* RP;\ - if (((R = *(RP = &(X->child[1]))) != 0) ||\ - ((R = *(RP = &(X->child[0]))) != 0)) {\ - tchunkptr* CP;\ - while ((*(CP = &(R->child[1])) != 0) ||\ - (*(CP = &(R->child[0])) != 0)) {\ - R = *(RP = CP);\ - }\ - if (RTCHECK(ok_address(M, RP)))\ - *RP = 0;\ - else {\ - CORRUPTION_ERROR_ACTION(M);\ - }\ - }\ - }\ - if (XP != 0) {\ - tbinptr* H = treebin_at(M, X->index);\ - if (X == *H) {\ - if ((*H = R) == 0) \ - clear_treemap(M, X->index);\ - }\ - else if (RTCHECK(ok_address(M, XP))) {\ - if (XP->child[0] == X) \ - XP->child[0] = R;\ - else \ - XP->child[1] = R;\ - }\ - else\ - CORRUPTION_ERROR_ACTION(M);\ - if (R != 0) {\ - if (RTCHECK(ok_address(M, R))) {\ - tchunkptr C0, C1;\ - R->parent = XP;\ - if ((C0 = X->child[0]) != 0) {\ - if (RTCHECK(ok_address(M, C0))) {\ - R->child[0] = C0;\ - C0->parent = R;\ - }\ - else\ - CORRUPTION_ERROR_ACTION(M);\ - }\ - if ((C1 = X->child[1]) != 0) {\ - if (RTCHECK(ok_address(M, C1))) {\ - R->child[1] = C1;\ - C1->parent = R;\ - }\ - else\ - CORRUPTION_ERROR_ACTION(M);\ - }\ - }\ - else\ - CORRUPTION_ERROR_ACTION(M);\ - }\ - }\ -} - -/* Relays to large vs small bin operations */ - -#define insert_chunk(M, P, S)\ - if (is_small(S)) insert_small_chunk(M, P, S)\ - else { tchunkptr TP = (tchunkptr)(P); insert_large_chunk(M, TP, S); } - -#define unlink_chunk(M, P, S)\ - if (is_small(S)) unlink_small_chunk(M, P, S)\ - else { tchunkptr TP = (tchunkptr)(P); unlink_large_chunk(M, TP); } - - -/* Relays to internal calls to malloc/free from realloc, memalign etc */ - -#if ONLY_MSPACES -#define internal_malloc(m, b) mspace_malloc(m, b) -#define internal_free(m, mem) mspace_free(m,mem); -#else /* ONLY_MSPACES */ -#if MSPACES -#define internal_malloc(m, b)\ - (m == gm)? dlmalloc(b) : mspace_malloc(m, b) -#define internal_free(m, mem)\ - if (m == gm) dlfree(mem); else mspace_free(m,mem); -#else /* MSPACES */ -#define internal_malloc(m, b) dlmalloc(b) -#define internal_free(m, mem) dlfree(mem) -#endif /* MSPACES */ -#endif /* ONLY_MSPACES */ - -/* ----------------------- Direct-mmapping chunks ----------------------- */ - -/* - Directly mmapped chunks are set up with an offset to the start of - the mmapped region stored in the prev_foot field of the chunk. This - allows reconstruction of the required argument to MUNMAP when freed, - and also allows adjustment of the returned chunk to meet alignment - requirements (especially in memalign). There is also enough space - allocated to hold a fake next chunk of size SIZE_T_SIZE to maintain - the PINUSE bit so frees can be checked. -*/ - -/* Malloc using mmap */ -static void * -mmap_alloc(mstate m, size_t nb) -{ - size_t mmsize = - granularity_align(nb + SIX_SIZE_T_SIZES + CHUNK_ALIGN_MASK); - if (mmsize > nb) { /* Check for wrap around 0 */ - char *mm = (char *) (DIRECT_MMAP(mmsize)); - if (mm != CMFAIL) { - size_t offset = align_offset(chunk2mem(mm)); - size_t psize = mmsize - offset - MMAP_FOOT_PAD; - mchunkptr p = (mchunkptr) (mm + offset); - p->prev_foot = offset | IS_MMAPPED_BIT; - (p)->head = (psize | CINUSE_BIT); - mark_inuse_foot(m, p, psize); - chunk_plus_offset(p, psize)->head = FENCEPOST_HEAD; - chunk_plus_offset(p, psize + SIZE_T_SIZE)->head = 0; - - if (mm < m->least_addr) - m->least_addr = mm; - if ((m->footprint += mmsize) > m->max_footprint) - m->max_footprint = m->footprint; - assert(is_aligned(chunk2mem(p))); - check_mmapped_chunk(m, p); - return chunk2mem(p); - } - } - return 0; -} - -/* Realloc using mmap */ -static mchunkptr -mmap_resize(mstate m, mchunkptr oldp, size_t nb) -{ - size_t oldsize = chunksize(oldp); - if (is_small(nb)) /* Can't shrink mmap regions below small size */ - return 0; - /* Keep old chunk if big enough but not too big */ - if (oldsize >= nb + SIZE_T_SIZE && - (oldsize - nb) <= (mparams.granularity << 1)) - return oldp; - else { - size_t offset = oldp->prev_foot & ~IS_MMAPPED_BIT; - size_t oldmmsize = oldsize + offset + MMAP_FOOT_PAD; - size_t newmmsize = granularity_align(nb + SIX_SIZE_T_SIZES + - CHUNK_ALIGN_MASK); - char *cp = (char *) CALL_MREMAP((char *) oldp - offset, - oldmmsize, newmmsize, 1); - if (cp != CMFAIL) { - mchunkptr newp = (mchunkptr) (cp + offset); - size_t psize = newmmsize - offset - MMAP_FOOT_PAD; - newp->head = (psize | CINUSE_BIT); - mark_inuse_foot(m, newp, psize); - chunk_plus_offset(newp, psize)->head = FENCEPOST_HEAD; - chunk_plus_offset(newp, psize + SIZE_T_SIZE)->head = 0; - - if (cp < m->least_addr) - m->least_addr = cp; - if ((m->footprint += newmmsize - oldmmsize) > m->max_footprint) - m->max_footprint = m->footprint; - check_mmapped_chunk(m, newp); - return newp; - } - } - return 0; -} - -/* -------------------------- mspace management -------------------------- */ - -/* Initialize top chunk and its size */ -static void -init_top(mstate m, mchunkptr p, size_t psize) -{ - /* Ensure alignment */ - size_t offset = align_offset(chunk2mem(p)); - p = (mchunkptr) ((char *) p + offset); - psize -= offset; - - m->top = p; - m->topsize = psize; - p->head = psize | PINUSE_BIT; - /* set size of fake trailing chunk holding overhead space only once */ - chunk_plus_offset(p, psize)->head = TOP_FOOT_SIZE; - m->trim_check = mparams.trim_threshold; /* reset on each update */ -} - -/* Initialize bins for a new mstate that is otherwise zeroed out */ -static void -init_bins(mstate m) -{ - /* Establish circular links for smallbins */ - bindex_t i; - for (i = 0; i < NSMALLBINS; ++i) { - sbinptr bin = smallbin_at(m, i); - bin->fd = bin->bk = bin; - } -} - -#if PROCEED_ON_ERROR - -/* default corruption action */ -static void -reset_on_error(mstate m) -{ - int i; - ++malloc_corruption_error_count; - /* Reinitialize fields to forget about all memory */ - m->smallbins = m->treebins = 0; - m->dvsize = m->topsize = 0; - m->seg.base = 0; - m->seg.size = 0; - m->seg.next = 0; - m->top = m->dv = 0; - for (i = 0; i < NTREEBINS; ++i) - *treebin_at(m, i) = 0; - init_bins(m); -} -#endif /* PROCEED_ON_ERROR */ - -/* Allocate chunk and prepend remainder with chunk in successor base. */ -static void * -prepend_alloc(mstate m, char *newbase, char *oldbase, size_t nb) -{ - mchunkptr p = align_as_chunk(newbase); - mchunkptr oldfirst = align_as_chunk(oldbase); - size_t psize = (char *) oldfirst - (char *) p; - mchunkptr q = chunk_plus_offset(p, nb); - size_t qsize = psize - nb; - set_size_and_pinuse_of_inuse_chunk(m, p, nb); - - assert((char *) oldfirst > (char *) q); - assert(pinuse(oldfirst)); - assert(qsize >= MIN_CHUNK_SIZE); - - /* consolidate remainder with first chunk of old base */ - if (oldfirst == m->top) { - size_t tsize = m->topsize += qsize; - m->top = q; - q->head = tsize | PINUSE_BIT; - check_top_chunk(m, q); - } else if (oldfirst == m->dv) { - size_t dsize = m->dvsize += qsize; - m->dv = q; - set_size_and_pinuse_of_free_chunk(q, dsize); - } else { - if (!cinuse(oldfirst)) { - size_t nsize = chunksize(oldfirst); - unlink_chunk(m, oldfirst, nsize); - oldfirst = chunk_plus_offset(oldfirst, nsize); - qsize += nsize; - } - set_free_with_pinuse(q, qsize, oldfirst); - insert_chunk(m, q, qsize); - check_free_chunk(m, q); - } - - check_malloced_chunk(m, chunk2mem(p), nb); - return chunk2mem(p); -} - - -/* Add a segment to hold a new noncontiguous region */ -static void -add_segment(mstate m, char *tbase, size_t tsize, flag_t mmapped) -{ - /* Determine locations and sizes of segment, fenceposts, old top */ - char *old_top = (char *) m->top; - msegmentptr oldsp = segment_holding(m, old_top); - char *old_end = oldsp->base + oldsp->size; - size_t ssize = pad_request(sizeof(struct malloc_segment)); - char *rawsp = old_end - (ssize + FOUR_SIZE_T_SIZES + CHUNK_ALIGN_MASK); - size_t offset = align_offset(chunk2mem(rawsp)); - char *asp = rawsp + offset; - char *csp = (asp < (old_top + MIN_CHUNK_SIZE)) ? old_top : asp; - mchunkptr sp = (mchunkptr) csp; - msegmentptr ss = (msegmentptr) (chunk2mem(sp)); - mchunkptr tnext = chunk_plus_offset(sp, ssize); - mchunkptr p = tnext; - int nfences = 0; - - /* reset top to new space */ - init_top(m, (mchunkptr) tbase, tsize - TOP_FOOT_SIZE); - - /* Set up segment record */ - assert(is_aligned(ss)); - set_size_and_pinuse_of_inuse_chunk(m, sp, ssize); - *ss = m->seg; /* Push current record */ - m->seg.base = tbase; - m->seg.size = tsize; - m->seg.sflags = mmapped; - m->seg.next = ss; - - /* Insert trailing fenceposts */ - for (;;) { - mchunkptr nextp = chunk_plus_offset(p, SIZE_T_SIZE); - p->head = FENCEPOST_HEAD; - ++nfences; - if ((char *) (&(nextp->head)) < old_end) - p = nextp; - else - break; - } - assert(nfences >= 2); - - /* Insert the rest of old top into a bin as an ordinary free chunk */ - if (csp != old_top) { - mchunkptr q = (mchunkptr) old_top; - size_t psize = csp - old_top; - mchunkptr tn = chunk_plus_offset(q, psize); - set_free_with_pinuse(q, psize, tn); - insert_chunk(m, q, psize); - } - - check_top_chunk(m, m->top); -} - -/* -------------------------- System allocation -------------------------- */ - -/* Get memory from system using MORECORE or MMAP */ -static void * -sys_alloc(mstate m, size_t nb) -{ - char *tbase = CMFAIL; - size_t tsize = 0; - flag_t mmap_flag = 0; - - init_mparams(); - - /* Directly map large chunks */ - if (use_mmap(m) && nb >= mparams.mmap_threshold) { - void *mem = mmap_alloc(m, nb); - if (mem != 0) - return mem; - } - - /* - Try getting memory in any of three ways (in most-preferred to - least-preferred order): - 1. A call to MORECORE that can normally contiguously extend memory. - (disabled if not MORECORE_CONTIGUOUS or not HAVE_MORECORE or - or main space is mmapped or a previous contiguous call failed) - 2. A call to MMAP new space (disabled if not HAVE_MMAP). - Note that under the default settings, if MORECORE is unable to - fulfill a request, and HAVE_MMAP is true, then mmap is - used as a noncontiguous system allocator. This is a useful backup - strategy for systems with holes in address spaces -- in this case - sbrk cannot contiguously expand the heap, but mmap may be able to - find space. - 3. A call to MORECORE that cannot usually contiguously extend memory. - (disabled if not HAVE_MORECORE) - */ - - if (MORECORE_CONTIGUOUS && !use_noncontiguous(m)) { - char *br = CMFAIL; - msegmentptr ss = - (m->top == 0) ? 0 : segment_holding(m, (char *) m->top); - size_t asize = 0; - ACQUIRE_MORECORE_LOCK(); - - if (ss == 0) { /* First time through or recovery */ - char *base = (char *) CALL_MORECORE(0); - if (base != CMFAIL) { - asize = - granularity_align(nb + TOP_FOOT_SIZE + MALLOC_ALIGNMENT + - SIZE_T_ONE); - /* Adjust to end on a page boundary */ - if (!is_page_aligned(base)) - asize += (page_align((size_t) base) - (size_t) base); - /* Can't call MORECORE if size is negative when treated as signed */ - if (asize < HALF_MAX_SIZE_T && - (br = (char *) (CALL_MORECORE(asize))) == base) { - tbase = base; - tsize = asize; - } - } - } else { - /* Subtract out existing available top space from MORECORE request. */ - asize = - granularity_align(nb - m->topsize + TOP_FOOT_SIZE + - MALLOC_ALIGNMENT + SIZE_T_ONE); - /* Use mem here only if it did continuously extend old space */ - if (asize < HALF_MAX_SIZE_T && - (br = - (char *) (CALL_MORECORE(asize))) == ss->base + ss->size) { - tbase = br; - tsize = asize; - } - } - - if (tbase == CMFAIL) { /* Cope with partial failure */ - if (br != CMFAIL) { /* Try to use/extend the space we did get */ - if (asize < HALF_MAX_SIZE_T && - asize < nb + TOP_FOOT_SIZE + SIZE_T_ONE) { - size_t esize = - granularity_align(nb + TOP_FOOT_SIZE + - MALLOC_ALIGNMENT + SIZE_T_ONE - - asize); - if (esize < HALF_MAX_SIZE_T) { - char *end = (char *) CALL_MORECORE(esize); - if (end != CMFAIL) - asize += esize; - else { /* Can't use; try to release */ - end = (char *) CALL_MORECORE(-asize); - br = CMFAIL; - } - } - } - } - if (br != CMFAIL) { /* Use the space we did get */ - tbase = br; - tsize = asize; - } else - disable_contiguous(m); /* Don't try contiguous path in the future */ - } - - RELEASE_MORECORE_LOCK(); - } - - if (HAVE_MMAP && tbase == CMFAIL) { /* Try MMAP */ - size_t req = nb + TOP_FOOT_SIZE + MALLOC_ALIGNMENT + SIZE_T_ONE; - size_t rsize = granularity_align(req); - if (rsize > nb) { /* Fail if wraps around zero */ - char *mp = (char *) (CALL_MMAP(rsize)); - if (mp != CMFAIL) { - tbase = mp; - tsize = rsize; - mmap_flag = IS_MMAPPED_BIT; - } - } - } - - if (HAVE_MORECORE && tbase == CMFAIL) { /* Try noncontiguous MORECORE */ - size_t asize = - granularity_align(nb + TOP_FOOT_SIZE + MALLOC_ALIGNMENT + - SIZE_T_ONE); - if (asize < HALF_MAX_SIZE_T) { - char *br = CMFAIL; - char *end = CMFAIL; - ACQUIRE_MORECORE_LOCK(); - br = (char *) (CALL_MORECORE(asize)); - end = (char *) (CALL_MORECORE(0)); - RELEASE_MORECORE_LOCK(); - if (br != CMFAIL && end != CMFAIL && br < end) { - size_t ssize = end - br; - if (ssize > nb + TOP_FOOT_SIZE) { - tbase = br; - tsize = ssize; - } - } - } - } - - if (tbase != CMFAIL) { - - if ((m->footprint += tsize) > m->max_footprint) - m->max_footprint = m->footprint; - - if (!is_initialized(m)) { /* first-time initialization */ - m->seg.base = m->least_addr = tbase; - m->seg.size = tsize; - m->seg.sflags = mmap_flag; - m->magic = mparams.magic; - init_bins(m); - if (is_global(m)) - init_top(m, (mchunkptr) tbase, tsize - TOP_FOOT_SIZE); - else { - /* Offset top by embedded malloc_state */ - mchunkptr mn = next_chunk(mem2chunk(m)); - init_top(m, mn, - (size_t) ((tbase + tsize) - (char *) mn) - - TOP_FOOT_SIZE); - } - } - - else { - /* Try to merge with an existing segment */ - msegmentptr sp = &m->seg; - while (sp != 0 && tbase != sp->base + sp->size) - sp = sp->next; - if (sp != 0 && !is_extern_segment(sp) && (sp->sflags & IS_MMAPPED_BIT) == mmap_flag && segment_holds(sp, m->top)) { /* append */ - sp->size += tsize; - init_top(m, m->top, m->topsize + tsize); - } else { - if (tbase < m->least_addr) - m->least_addr = tbase; - sp = &m->seg; - while (sp != 0 && sp->base != tbase + tsize) - sp = sp->next; - if (sp != 0 && - !is_extern_segment(sp) && - (sp->sflags & IS_MMAPPED_BIT) == mmap_flag) { - char *oldbase = sp->base; - sp->base = tbase; - sp->size += tsize; - return prepend_alloc(m, tbase, oldbase, nb); - } else - add_segment(m, tbase, tsize, mmap_flag); - } - } - - if (nb < m->topsize) { /* Allocate from new or extended top space */ - size_t rsize = m->topsize -= nb; - mchunkptr p = m->top; - mchunkptr r = m->top = chunk_plus_offset(p, nb); - r->head = rsize | PINUSE_BIT; - set_size_and_pinuse_of_inuse_chunk(m, p, nb); - check_top_chunk(m, m->top); - check_malloced_chunk(m, chunk2mem(p), nb); - return chunk2mem(p); - } - } - - MALLOC_FAILURE_ACTION; - return 0; -} - -/* ----------------------- system deallocation -------------------------- */ - -/* Unmap and unlink any mmapped segments that don't contain used chunks */ -static size_t -release_unused_segments(mstate m) -{ - size_t released = 0; - msegmentptr pred = &m->seg; - msegmentptr sp = pred->next; - while (sp != 0) { - char *base = sp->base; - size_t size = sp->size; - msegmentptr next = sp->next; - if (is_mmapped_segment(sp) && !is_extern_segment(sp)) { - mchunkptr p = align_as_chunk(base); - size_t psize = chunksize(p); - /* Can unmap if first chunk holds entire segment and not pinned */ - if (!cinuse(p) - && (char *) p + psize >= base + size - TOP_FOOT_SIZE) { - tchunkptr tp = (tchunkptr) p; - assert(segment_holds(sp, (char *) sp)); - if (p == m->dv) { - m->dv = 0; - m->dvsize = 0; - } else { - unlink_large_chunk(m, tp); - } - if (CALL_MUNMAP(base, size) == 0) { - released += size; - m->footprint -= size; - /* unlink obsoleted record */ - sp = pred; - sp->next = next; - } else { /* back out if cannot unmap */ - insert_large_chunk(m, tp, psize); - } - } - } - pred = sp; - sp = next; - } - return released; -} - -static int -sys_trim(mstate m, size_t pad) -{ - size_t released = 0; - if (pad < MAX_REQUEST && is_initialized(m)) { - pad += TOP_FOOT_SIZE; /* ensure enough room for segment overhead */ - - if (m->topsize > pad) { - /* Shrink top space in granularity-size units, keeping at least one */ - size_t unit = mparams.granularity; - size_t extra = ((m->topsize - pad + (unit - SIZE_T_ONE)) / unit - - SIZE_T_ONE) * unit; - msegmentptr sp = segment_holding(m, (char *) m->top); - - if (!is_extern_segment(sp)) { - if (is_mmapped_segment(sp)) { - if (HAVE_MMAP && sp->size >= extra && !has_segment_link(m, sp)) { /* can't shrink if pinned */ - size_t newsize = sp->size - extra; - /* Prefer mremap, fall back to munmap */ - if ((CALL_MREMAP(sp->base, sp->size, newsize, 0) != - MFAIL) - || (CALL_MUNMAP(sp->base + newsize, extra) == 0)) { - released = extra; - } - } - } else if (HAVE_MORECORE) { - if (extra >= HALF_MAX_SIZE_T) /* Avoid wrapping negative */ - extra = (HALF_MAX_SIZE_T) + SIZE_T_ONE - unit; - ACQUIRE_MORECORE_LOCK(); - { - /* Make sure end of memory is where we last set it. */ - char *old_br = (char *) (CALL_MORECORE(0)); - if (old_br == sp->base + sp->size) { - char *rel_br = (char *) (CALL_MORECORE(-extra)); - char *new_br = (char *) (CALL_MORECORE(0)); - if (rel_br != CMFAIL && new_br < old_br) - released = old_br - new_br; - } - } - RELEASE_MORECORE_LOCK(); - } - } - - if (released != 0) { - sp->size -= released; - m->footprint -= released; - init_top(m, m->top, m->topsize - released); - check_top_chunk(m, m->top); - } - } - - /* Unmap any unused mmapped segments */ - if (HAVE_MMAP) - released += release_unused_segments(m); - - /* On failure, disable autotrim to avoid repeated failed future calls */ - if (released == 0) - m->trim_check = MAX_SIZE_T; - } - - return (released != 0) ? 1 : 0; -} - -/* ---------------------------- malloc support --------------------------- */ - -/* allocate a large request from the best fitting chunk in a treebin */ -static void * -tmalloc_large(mstate m, size_t nb) -{ - tchunkptr v = 0; - size_t rsize = -nb; /* Unsigned negation */ - tchunkptr t; - bindex_t idx; - compute_tree_index(nb, idx); - - if ((t = *treebin_at(m, idx)) != 0) { - /* Traverse tree for this bin looking for node with size == nb */ - size_t sizebits = nb << leftshift_for_tree_index(idx); - tchunkptr rst = 0; /* The deepest untaken right subtree */ - for (;;) { - tchunkptr rt; - size_t trem = chunksize(t) - nb; - if (trem < rsize) { - v = t; - if ((rsize = trem) == 0) - break; - } - rt = t->child[1]; - t = t->child[(sizebits >> (SIZE_T_BITSIZE - SIZE_T_ONE)) & 1]; - if (rt != 0 && rt != t) - rst = rt; - if (t == 0) { - t = rst; /* set t to least subtree holding sizes > nb */ - break; - } - sizebits <<= 1; - } - } - - if (t == 0 && v == 0) { /* set t to root of next non-empty treebin */ - binmap_t leftbits = left_bits(idx2bit(idx)) & m->treemap; - if (leftbits != 0) { - bindex_t i; - binmap_t leastbit = least_bit(leftbits); - compute_bit2idx(leastbit, i); - t = *treebin_at(m, i); - } - } - - while (t != 0) { /* find smallest of tree or subtree */ - size_t trem = chunksize(t) - nb; - if (trem < rsize) { - rsize = trem; - v = t; - } - t = leftmost_child(t); - } - - /* If dv is a better fit, return 0 so malloc will use it */ - if (v != 0 && rsize < (size_t) (m->dvsize - nb)) { - if (RTCHECK(ok_address(m, v))) { /* split */ - mchunkptr r = chunk_plus_offset(v, nb); - assert(chunksize(v) == rsize + nb); - if (RTCHECK(ok_next(v, r))) { - unlink_large_chunk(m, v); - if (rsize < MIN_CHUNK_SIZE) - set_inuse_and_pinuse(m, v, (rsize + nb)); - else { - set_size_and_pinuse_of_inuse_chunk(m, v, nb); - set_size_and_pinuse_of_free_chunk(r, rsize); - insert_chunk(m, r, rsize); - } - return chunk2mem(v); - } - } - CORRUPTION_ERROR_ACTION(m); - } - return 0; -} - -/* allocate a small request from the best fitting chunk in a treebin */ -static void * -tmalloc_small(mstate m, size_t nb) -{ - tchunkptr t, v; - size_t rsize; - bindex_t i; - binmap_t leastbit = least_bit(m->treemap); - compute_bit2idx(leastbit, i); - - v = t = *treebin_at(m, i); - rsize = chunksize(t) - nb; - - while ((t = leftmost_child(t)) != 0) { - size_t trem = chunksize(t) - nb; - if (trem < rsize) { - rsize = trem; - v = t; - } - } - - if (RTCHECK(ok_address(m, v))) { - mchunkptr r = chunk_plus_offset(v, nb); - assert(chunksize(v) == rsize + nb); - if (RTCHECK(ok_next(v, r))) { - unlink_large_chunk(m, v); - if (rsize < MIN_CHUNK_SIZE) - set_inuse_and_pinuse(m, v, (rsize + nb)); - else { - set_size_and_pinuse_of_inuse_chunk(m, v, nb); - set_size_and_pinuse_of_free_chunk(r, rsize); - replace_dv(m, r, rsize); - } - return chunk2mem(v); - } - } - - CORRUPTION_ERROR_ACTION(m); - return 0; -} - -/* --------------------------- realloc support --------------------------- */ - -static void * -internal_realloc(mstate m, void *oldmem, size_t bytes) -{ - if (bytes >= MAX_REQUEST) { - MALLOC_FAILURE_ACTION; - return 0; - } - if (!PREACTION(m)) { - mchunkptr oldp = mem2chunk(oldmem); - size_t oldsize = chunksize(oldp); - mchunkptr next = chunk_plus_offset(oldp, oldsize); - mchunkptr newp = 0; - void *extra = 0; - - /* Try to either shrink or extend into top. Else malloc-copy-free */ - - if (RTCHECK(ok_address(m, oldp) && ok_cinuse(oldp) && - ok_next(oldp, next) && ok_pinuse(next))) { - size_t nb = request2size(bytes); - if (is_mmapped(oldp)) - newp = mmap_resize(m, oldp, nb); - else if (oldsize >= nb) { /* already big enough */ - size_t rsize = oldsize - nb; - newp = oldp; - if (rsize >= MIN_CHUNK_SIZE) { - mchunkptr remainder = chunk_plus_offset(newp, nb); - set_inuse(m, newp, nb); - set_inuse(m, remainder, rsize); - extra = chunk2mem(remainder); - } - } else if (next == m->top && oldsize + m->topsize > nb) { - /* Expand into top */ - size_t newsize = oldsize + m->topsize; - size_t newtopsize = newsize - nb; - mchunkptr newtop = chunk_plus_offset(oldp, nb); - set_inuse(m, oldp, nb); - newtop->head = newtopsize | PINUSE_BIT; - m->top = newtop; - m->topsize = newtopsize; - newp = oldp; - } - } else { - USAGE_ERROR_ACTION(m, oldmem); - POSTACTION(m); - return 0; - } - - POSTACTION(m); - - if (newp != 0) { - if (extra != 0) { - internal_free(m, extra); - } - check_inuse_chunk(m, newp); - return chunk2mem(newp); - } else { - void *newmem = internal_malloc(m, bytes); - if (newmem != 0) { - size_t oc = oldsize - overhead_for(oldp); - memcpy(newmem, oldmem, (oc < bytes) ? oc : bytes); - internal_free(m, oldmem); - } - return newmem; - } - } - return 0; -} - -/* --------------------------- memalign support -------------------------- */ - -static void * -internal_memalign(mstate m, size_t alignment, size_t bytes) -{ - if (alignment <= MALLOC_ALIGNMENT) /* Can just use malloc */ - return internal_malloc(m, bytes); - if (alignment < MIN_CHUNK_SIZE) /* must be at least a minimum chunk size */ - alignment = MIN_CHUNK_SIZE; - if ((alignment & (alignment - SIZE_T_ONE)) != 0) { /* Ensure a power of 2 */ - size_t a = MALLOC_ALIGNMENT << 1; - while (a < alignment) - a <<= 1; - alignment = a; - } - - if (bytes >= MAX_REQUEST - alignment) { - if (m != 0) { /* Test isn't needed but avoids compiler warning */ - MALLOC_FAILURE_ACTION; - } - } else { - size_t nb = request2size(bytes); - size_t req = nb + alignment + MIN_CHUNK_SIZE - CHUNK_OVERHEAD; - char *mem = (char *) internal_malloc(m, req); - if (mem != 0) { - void *leader = 0; - void *trailer = 0; - mchunkptr p = mem2chunk(mem); - - if (PREACTION(m)) - return 0; - if ((((size_t) (mem)) % alignment) != 0) { /* misaligned */ - /* - Find an aligned spot inside chunk. Since we need to give - back leading space in a chunk of at least MIN_CHUNK_SIZE, if - the first calculation places us at a spot with less than - MIN_CHUNK_SIZE leader, we can move to the next aligned spot. - We've allocated enough total room so that this is always - possible. - */ - char *br = (char *) mem2chunk((size_t) (((size_t) (mem + - alignment - - SIZE_T_ONE)) - & -alignment)); - char *pos = - ((size_t) (br - (char *) (p)) >= - MIN_CHUNK_SIZE) ? br : br + alignment; - mchunkptr newp = (mchunkptr) pos; - size_t leadsize = pos - (char *) (p); - size_t newsize = chunksize(p) - leadsize; - - if (is_mmapped(p)) { /* For mmapped chunks, just adjust offset */ - newp->prev_foot = p->prev_foot + leadsize; - newp->head = (newsize | CINUSE_BIT); - } else { /* Otherwise, give back leader, use the rest */ - set_inuse(m, newp, newsize); - set_inuse(m, p, leadsize); - leader = chunk2mem(p); - } - p = newp; - } - - /* Give back spare room at the end */ - if (!is_mmapped(p)) { - size_t size = chunksize(p); - if (size > nb + MIN_CHUNK_SIZE) { - size_t remainder_size = size - nb; - mchunkptr remainder = chunk_plus_offset(p, nb); - set_inuse(m, p, nb); - set_inuse(m, remainder, remainder_size); - trailer = chunk2mem(remainder); - } - } - - assert(chunksize(p) >= nb); - assert((((size_t) (chunk2mem(p))) % alignment) == 0); - check_inuse_chunk(m, p); - POSTACTION(m); - if (leader != 0) { - internal_free(m, leader); - } - if (trailer != 0) { - internal_free(m, trailer); - } - return chunk2mem(p); - } - } - return 0; -} - -/* ------------------------ comalloc/coalloc support --------------------- */ - -static void ** -ialloc(mstate m, size_t n_elements, size_t * sizes, int opts, void *chunks[]) -{ - /* - This provides common support for independent_X routines, handling - all of the combinations that can result. - - The opts arg has: - bit 0 set if all elements are same size (using sizes[0]) - bit 1 set if elements should be zeroed - */ - - size_t element_size; /* chunksize of each element, if all same */ - size_t contents_size; /* total size of elements */ - size_t array_size; /* request size of pointer array */ - void *mem; /* malloced aggregate space */ - mchunkptr p; /* corresponding chunk */ - size_t remainder_size; /* remaining bytes while splitting */ - void **marray; /* either "chunks" or malloced ptr array */ - mchunkptr array_chunk; /* chunk for malloced ptr array */ - flag_t was_enabled; /* to disable mmap */ - size_t size; - size_t i; - - /* compute array length, if needed */ - if (chunks != 0) { - if (n_elements == 0) - return chunks; /* nothing to do */ - marray = chunks; - array_size = 0; - } else { - /* if empty req, must still return chunk representing empty array */ - if (n_elements == 0) - return (void **) internal_malloc(m, 0); - marray = 0; - array_size = request2size(n_elements * (sizeof(void *))); - } - - /* compute total element size */ - if (opts & 0x1) { /* all-same-size */ - element_size = request2size(*sizes); - contents_size = n_elements * element_size; - } else { /* add up all the sizes */ - element_size = 0; - contents_size = 0; - for (i = 0; i != n_elements; ++i) - contents_size += request2size(sizes[i]); - } - - size = contents_size + array_size; - - /* - Allocate the aggregate chunk. First disable direct-mmapping so - malloc won't use it, since we would not be able to later - free/realloc space internal to a segregated mmap region. - */ - was_enabled = use_mmap(m); - disable_mmap(m); - mem = internal_malloc(m, size - CHUNK_OVERHEAD); - if (was_enabled) - enable_mmap(m); - if (mem == 0) - return 0; - - if (PREACTION(m)) - return 0; - p = mem2chunk(mem); - remainder_size = chunksize(p); - - assert(!is_mmapped(p)); - - if (opts & 0x2) { /* optionally clear the elements */ - memset((size_t *) mem, 0, remainder_size - SIZE_T_SIZE - array_size); - } - - /* If not provided, allocate the pointer array as final part of chunk */ - if (marray == 0) { - size_t array_chunk_size; - array_chunk = chunk_plus_offset(p, contents_size); - array_chunk_size = remainder_size - contents_size; - marray = (void **) (chunk2mem(array_chunk)); - set_size_and_pinuse_of_inuse_chunk(m, array_chunk, array_chunk_size); - remainder_size = contents_size; - } - - /* split out elements */ - for (i = 0;; ++i) { - marray[i] = chunk2mem(p); - if (i != n_elements - 1) { - if (element_size != 0) - size = element_size; - else - size = request2size(sizes[i]); - remainder_size -= size; - set_size_and_pinuse_of_inuse_chunk(m, p, size); - p = chunk_plus_offset(p, size); - } else { /* the final element absorbs any overallocation slop */ - set_size_and_pinuse_of_inuse_chunk(m, p, remainder_size); - break; - } - } - -#if DEBUG - if (marray != chunks) { - /* final element must have exactly exhausted chunk */ - if (element_size != 0) { - assert(remainder_size == element_size); - } else { - assert(remainder_size == request2size(sizes[i])); - } - check_inuse_chunk(m, mem2chunk(marray)); - } - for (i = 0; i != n_elements; ++i) - check_inuse_chunk(m, mem2chunk(marray[i])); - -#endif /* DEBUG */ - - POSTACTION(m); - return marray; -} - - -/* -------------------------- public routines ---------------------------- */ - -#if !ONLY_MSPACES - -void * -dlmalloc(size_t bytes) -{ - /* - Basic algorithm: - If a small request (< 256 bytes minus per-chunk overhead): - 1. If one exists, use a remainderless chunk in associated smallbin. - (Remainderless means that there are too few excess bytes to - represent as a chunk.) - 2. If it is big enough, use the dv chunk, which is normally the - chunk adjacent to the one used for the most recent small request. - 3. If one exists, split the smallest available chunk in a bin, - saving remainder in dv. - 4. If it is big enough, use the top chunk. - 5. If available, get memory from system and use it - Otherwise, for a large request: - 1. Find the smallest available binned chunk that fits, and use it - if it is better fitting than dv chunk, splitting if necessary. - 2. If better fitting than any binned chunk, use the dv chunk. - 3. If it is big enough, use the top chunk. - 4. If request size >= mmap threshold, try to directly mmap this chunk. - 5. If available, get memory from system and use it - - The ugly goto's here ensure that postaction occurs along all paths. - */ - - if (!PREACTION(gm)) { - void *mem; - size_t nb; - if (bytes <= MAX_SMALL_REQUEST) { - bindex_t idx; - binmap_t smallbits; - nb = (bytes < MIN_REQUEST) ? MIN_CHUNK_SIZE : pad_request(bytes); - idx = small_index(nb); - smallbits = gm->smallmap >> idx; - - if ((smallbits & 0x3U) != 0) { /* Remainderless fit to a smallbin. */ - mchunkptr b, p; - idx += ~smallbits & 1; /* Uses next bin if idx empty */ - b = smallbin_at(gm, idx); - p = b->fd; - assert(chunksize(p) == small_index2size(idx)); - unlink_first_small_chunk(gm, b, p, idx); - set_inuse_and_pinuse(gm, p, small_index2size(idx)); - mem = chunk2mem(p); - check_malloced_chunk(gm, mem, nb); - goto postaction; - } - - else if (nb > gm->dvsize) { - if (smallbits != 0) { /* Use chunk in next nonempty smallbin */ - mchunkptr b, p, r; - size_t rsize; - bindex_t i; - binmap_t leftbits = - (smallbits << idx) & left_bits(idx2bit(idx)); - binmap_t leastbit = least_bit(leftbits); - compute_bit2idx(leastbit, i); - b = smallbin_at(gm, i); - p = b->fd; - assert(chunksize(p) == small_index2size(i)); - unlink_first_small_chunk(gm, b, p, i); - rsize = small_index2size(i) - nb; - /* Fit here cannot be remainderless if 4byte sizes */ - if (SIZE_T_SIZE != 4 && rsize < MIN_CHUNK_SIZE) - set_inuse_and_pinuse(gm, p, small_index2size(i)); - else { - set_size_and_pinuse_of_inuse_chunk(gm, p, nb); - r = chunk_plus_offset(p, nb); - set_size_and_pinuse_of_free_chunk(r, rsize); - replace_dv(gm, r, rsize); - } - mem = chunk2mem(p); - check_malloced_chunk(gm, mem, nb); - goto postaction; - } - - else if (gm->treemap != 0 - && (mem = tmalloc_small(gm, nb)) != 0) { - check_malloced_chunk(gm, mem, nb); - goto postaction; - } - } - } else if (bytes >= MAX_REQUEST) - nb = MAX_SIZE_T; /* Too big to allocate. Force failure (in sys alloc) */ - else { - nb = pad_request(bytes); - if (gm->treemap != 0 && (mem = tmalloc_large(gm, nb)) != 0) { - check_malloced_chunk(gm, mem, nb); - goto postaction; - } - } - - if (nb <= gm->dvsize) { - size_t rsize = gm->dvsize - nb; - mchunkptr p = gm->dv; - if (rsize >= MIN_CHUNK_SIZE) { /* split dv */ - mchunkptr r = gm->dv = chunk_plus_offset(p, nb); - gm->dvsize = rsize; - set_size_and_pinuse_of_free_chunk(r, rsize); - set_size_and_pinuse_of_inuse_chunk(gm, p, nb); - } else { /* exhaust dv */ - size_t dvs = gm->dvsize; - gm->dvsize = 0; - gm->dv = 0; - set_inuse_and_pinuse(gm, p, dvs); - } - mem = chunk2mem(p); - check_malloced_chunk(gm, mem, nb); - goto postaction; - } - - else if (nb < gm->topsize) { /* Split top */ - size_t rsize = gm->topsize -= nb; - mchunkptr p = gm->top; - mchunkptr r = gm->top = chunk_plus_offset(p, nb); - r->head = rsize | PINUSE_BIT; - set_size_and_pinuse_of_inuse_chunk(gm, p, nb); - mem = chunk2mem(p); - check_top_chunk(gm, gm->top); - check_malloced_chunk(gm, mem, nb); - goto postaction; - } - - mem = sys_alloc(gm, nb); - - postaction: - POSTACTION(gm); - return mem; - } - - return 0; -} - -void -dlfree(void *mem) -{ - /* - Consolidate freed chunks with preceeding or succeeding bordering - free chunks, if they exist, and then place in a bin. Intermixed - with special cases for top, dv, mmapped chunks, and usage errors. - */ - - if (mem != 0) { - mchunkptr p = mem2chunk(mem); -#if FOOTERS - mstate fm = get_mstate_for(p); - if (!ok_magic(fm)) { - USAGE_ERROR_ACTION(fm, p); - return; - } -#else /* FOOTERS */ -#define fm gm -#endif /* FOOTERS */ - if (!PREACTION(fm)) { - check_inuse_chunk(fm, p); - if (RTCHECK(ok_address(fm, p) && ok_cinuse(p))) { - size_t psize = chunksize(p); - mchunkptr next = chunk_plus_offset(p, psize); - if (!pinuse(p)) { - size_t prevsize = p->prev_foot; - if ((prevsize & IS_MMAPPED_BIT) != 0) { - prevsize &= ~IS_MMAPPED_BIT; - psize += prevsize + MMAP_FOOT_PAD; - if (CALL_MUNMAP((char *) p - prevsize, psize) == 0) - fm->footprint -= psize; - goto postaction; - } else { - mchunkptr prev = chunk_minus_offset(p, prevsize); - psize += prevsize; - p = prev; - if (RTCHECK(ok_address(fm, prev))) { /* consolidate backward */ - if (p != fm->dv) { - unlink_chunk(fm, p, prevsize); - } else if ((next->head & INUSE_BITS) == - INUSE_BITS) { - fm->dvsize = psize; - set_free_with_pinuse(p, psize, next); - goto postaction; - } - } else - goto erroraction; - } - } - - if (RTCHECK(ok_next(p, next) && ok_pinuse(next))) { - if (!cinuse(next)) { /* consolidate forward */ - if (next == fm->top) { - size_t tsize = fm->topsize += psize; - fm->top = p; - p->head = tsize | PINUSE_BIT; - if (p == fm->dv) { - fm->dv = 0; - fm->dvsize = 0; - } - if (should_trim(fm, tsize)) - sys_trim(fm, 0); - goto postaction; - } else if (next == fm->dv) { - size_t dsize = fm->dvsize += psize; - fm->dv = p; - set_size_and_pinuse_of_free_chunk(p, dsize); - goto postaction; - } else { - size_t nsize = chunksize(next); - psize += nsize; - unlink_chunk(fm, next, nsize); - set_size_and_pinuse_of_free_chunk(p, psize); - if (p == fm->dv) { - fm->dvsize = psize; - goto postaction; - } - } - } else - set_free_with_pinuse(p, psize, next); - insert_chunk(fm, p, psize); - check_free_chunk(fm, p); - goto postaction; - } - } - erroraction: - USAGE_ERROR_ACTION(fm, p); - postaction: - POSTACTION(fm); - } - } -#if !FOOTERS -#undef fm -#endif /* FOOTERS */ -} - -void * -dlcalloc(size_t n_elements, size_t elem_size) -{ - void *mem; - size_t req = 0; - if (n_elements != 0) { - req = n_elements * elem_size; - if (((n_elements | elem_size) & ~(size_t) 0xffff) && - (req / n_elements != elem_size)) - req = MAX_SIZE_T; /* force downstream failure on overflow */ - } - mem = dlmalloc(req); - if (mem != 0 && calloc_must_clear(mem2chunk(mem))) - memset(mem, 0, req); - return mem; -} - -void * -dlrealloc(void *oldmem, size_t bytes) -{ - if (oldmem == 0) - return dlmalloc(bytes); -#ifdef REALLOC_ZERO_BYTES_FREES - if (bytes == 0) { - dlfree(oldmem); - return 0; - } -#endif /* REALLOC_ZERO_BYTES_FREES */ - else { -#if ! FOOTERS - mstate m = gm; -#else /* FOOTERS */ - mstate m = get_mstate_for(mem2chunk(oldmem)); - if (!ok_magic(m)) { - USAGE_ERROR_ACTION(m, oldmem); - return 0; - } -#endif /* FOOTERS */ - return internal_realloc(m, oldmem, bytes); - } -} - -void * -dlmemalign(size_t alignment, size_t bytes) -{ - return internal_memalign(gm, alignment, bytes); -} - -void ** -dlindependent_calloc(size_t n_elements, size_t elem_size, void *chunks[]) -{ - size_t sz = elem_size; /* serves as 1-element array */ - return ialloc(gm, n_elements, &sz, 3, chunks); -} - -void ** -dlindependent_comalloc(size_t n_elements, size_t sizes[], void *chunks[]) -{ - return ialloc(gm, n_elements, sizes, 0, chunks); -} - -void * -dlvalloc(size_t bytes) -{ - size_t pagesz; - init_mparams(); - pagesz = mparams.page_size; - return dlmemalign(pagesz, bytes); -} - -void * -dlpvalloc(size_t bytes) -{ - size_t pagesz; - init_mparams(); - pagesz = mparams.page_size; - return dlmemalign(pagesz, - (bytes + pagesz - SIZE_T_ONE) & ~(pagesz - SIZE_T_ONE)); -} - -int -dlmalloc_trim(size_t pad) -{ - int result = 0; - if (!PREACTION(gm)) { - result = sys_trim(gm, pad); - POSTACTION(gm); - } - return result; -} - -size_t -dlmalloc_footprint(void) -{ - return gm->footprint; -} - -size_t -dlmalloc_max_footprint(void) -{ - return gm->max_footprint; -} - -#if !NO_MALLINFO -struct mallinfo -dlmallinfo(void) -{ - return internal_mallinfo(gm); -} -#endif /* NO_MALLINFO */ - -void -dlmalloc_stats() -{ - internal_malloc_stats(gm); -} - -size_t -dlmalloc_usable_size(void *mem) -{ - if (mem != 0) { - mchunkptr p = mem2chunk(mem); - if (cinuse(p)) - return chunksize(p) - overhead_for(p); - } - return 0; -} - -int -dlmallopt(int param_number, int value) -{ - return change_mparam(param_number, value); -} - -#endif /* !ONLY_MSPACES */ - -/* ----------------------------- user mspaces ---------------------------- */ - -#if MSPACES - -static mstate -init_user_mstate(char *tbase, size_t tsize) -{ - size_t msize = pad_request(sizeof(struct malloc_state)); - mchunkptr mn; - mchunkptr msp = align_as_chunk(tbase); - mstate m = (mstate) (chunk2mem(msp)); - memset(m, 0, msize); - INITIAL_LOCK(&m->mutex); - msp->head = (msize | PINUSE_BIT | CINUSE_BIT); - m->seg.base = m->least_addr = tbase; - m->seg.size = m->footprint = m->max_footprint = tsize; - m->magic = mparams.magic; - m->mflags = mparams.default_mflags; - disable_contiguous(m); - init_bins(m); - mn = next_chunk(mem2chunk(m)); - init_top(m, mn, (size_t) ((tbase + tsize) - (char *) mn) - TOP_FOOT_SIZE); - check_top_chunk(m, m->top); - return m; -} - -mspace -create_mspace(size_t capacity, int locked) -{ - mstate m = 0; - size_t msize = pad_request(sizeof(struct malloc_state)); - init_mparams(); /* Ensure pagesize etc initialized */ - - if (capacity < (size_t) - (msize + TOP_FOOT_SIZE + mparams.page_size)) { - size_t rs = ((capacity == 0) ? mparams.granularity : - (capacity + TOP_FOOT_SIZE + msize)); - size_t tsize = granularity_align(rs); - char *tbase = (char *) (CALL_MMAP(tsize)); - if (tbase != CMFAIL) { - m = init_user_mstate(tbase, tsize); - m->seg.sflags = IS_MMAPPED_BIT; - set_lock(m, locked); - } - } - return (mspace) m; -} - -mspace -create_mspace_with_base(void *base, size_t capacity, int locked) -{ - mstate m = 0; - size_t msize = pad_request(sizeof(struct malloc_state)); - init_mparams(); /* Ensure pagesize etc initialized */ - - if (capacity > msize + TOP_FOOT_SIZE && - capacity < (size_t) - (msize + TOP_FOOT_SIZE + mparams.page_size)) { - m = init_user_mstate((char *) base, capacity); - m->seg.sflags = EXTERN_BIT; - set_lock(m, locked); - } - return (mspace) m; -} - -size_t -destroy_mspace(mspace msp) -{ - size_t freed = 0; - mstate ms = (mstate) msp; - if (ok_magic(ms)) { - msegmentptr sp = &ms->seg; - while (sp != 0) { - char *base = sp->base; - size_t size = sp->size; - flag_t flag = sp->sflags; - sp = sp->next; - if ((flag & IS_MMAPPED_BIT) && !(flag & EXTERN_BIT) && - CALL_MUNMAP(base, size) == 0) - freed += size; - } - } else { - USAGE_ERROR_ACTION(ms, ms); - } - return freed; -} - -/* - mspace versions of routines are near-clones of the global - versions. This is not so nice but better than the alternatives. -*/ - - -void * -mspace_malloc(mspace msp, size_t bytes) -{ - mstate ms = (mstate) msp; - if (!ok_magic(ms)) { - USAGE_ERROR_ACTION(ms, ms); - return 0; - } - if (!PREACTION(ms)) { - void *mem; - size_t nb; - if (bytes <= MAX_SMALL_REQUEST) { - bindex_t idx; - binmap_t smallbits; - nb = (bytes < MIN_REQUEST) ? MIN_CHUNK_SIZE : pad_request(bytes); - idx = small_index(nb); - smallbits = ms->smallmap >> idx; - - if ((smallbits & 0x3U) != 0) { /* Remainderless fit to a smallbin. */ - mchunkptr b, p; - idx += ~smallbits & 1; /* Uses next bin if idx empty */ - b = smallbin_at(ms, idx); - p = b->fd; - assert(chunksize(p) == small_index2size(idx)); - unlink_first_small_chunk(ms, b, p, idx); - set_inuse_and_pinuse(ms, p, small_index2size(idx)); - mem = chunk2mem(p); - check_malloced_chunk(ms, mem, nb); - goto postaction; - } - - else if (nb > ms->dvsize) { - if (smallbits != 0) { /* Use chunk in next nonempty smallbin */ - mchunkptr b, p, r; - size_t rsize; - bindex_t i; - binmap_t leftbits = - (smallbits << idx) & left_bits(idx2bit(idx)); - binmap_t leastbit = least_bit(leftbits); - compute_bit2idx(leastbit, i); - b = smallbin_at(ms, i); - p = b->fd; - assert(chunksize(p) == small_index2size(i)); - unlink_first_small_chunk(ms, b, p, i); - rsize = small_index2size(i) - nb; - /* Fit here cannot be remainderless if 4byte sizes */ - if (SIZE_T_SIZE != 4 && rsize < MIN_CHUNK_SIZE) - set_inuse_and_pinuse(ms, p, small_index2size(i)); - else { - set_size_and_pinuse_of_inuse_chunk(ms, p, nb); - r = chunk_plus_offset(p, nb); - set_size_and_pinuse_of_free_chunk(r, rsize); - replace_dv(ms, r, rsize); - } - mem = chunk2mem(p); - check_malloced_chunk(ms, mem, nb); - goto postaction; - } - - else if (ms->treemap != 0 - && (mem = tmalloc_small(ms, nb)) != 0) { - check_malloced_chunk(ms, mem, nb); - goto postaction; - } - } - } else if (bytes >= MAX_REQUEST) - nb = MAX_SIZE_T; /* Too big to allocate. Force failure (in sys alloc) */ - else { - nb = pad_request(bytes); - if (ms->treemap != 0 && (mem = tmalloc_large(ms, nb)) != 0) { - check_malloced_chunk(ms, mem, nb); - goto postaction; - } - } - - if (nb <= ms->dvsize) { - size_t rsize = ms->dvsize - nb; - mchunkptr p = ms->dv; - if (rsize >= MIN_CHUNK_SIZE) { /* split dv */ - mchunkptr r = ms->dv = chunk_plus_offset(p, nb); - ms->dvsize = rsize; - set_size_and_pinuse_of_free_chunk(r, rsize); - set_size_and_pinuse_of_inuse_chunk(ms, p, nb); - } else { /* exhaust dv */ - size_t dvs = ms->dvsize; - ms->dvsize = 0; - ms->dv = 0; - set_inuse_and_pinuse(ms, p, dvs); - } - mem = chunk2mem(p); - check_malloced_chunk(ms, mem, nb); - goto postaction; - } - - else if (nb < ms->topsize) { /* Split top */ - size_t rsize = ms->topsize -= nb; - mchunkptr p = ms->top; - mchunkptr r = ms->top = chunk_plus_offset(p, nb); - r->head = rsize | PINUSE_BIT; - set_size_and_pinuse_of_inuse_chunk(ms, p, nb); - mem = chunk2mem(p); - check_top_chunk(ms, ms->top); - check_malloced_chunk(ms, mem, nb); - goto postaction; - } - - mem = sys_alloc(ms, nb); - - postaction: - POSTACTION(ms); - return mem; - } - - return 0; -} - -void -mspace_free(mspace msp, void *mem) -{ - if (mem != 0) { - mchunkptr p = mem2chunk(mem); -#if FOOTERS - mstate fm = get_mstate_for(p); -#else /* FOOTERS */ - mstate fm = (mstate) msp; -#endif /* FOOTERS */ - if (!ok_magic(fm)) { - USAGE_ERROR_ACTION(fm, p); - return; - } - if (!PREACTION(fm)) { - check_inuse_chunk(fm, p); - if (RTCHECK(ok_address(fm, p) && ok_cinuse(p))) { - size_t psize = chunksize(p); - mchunkptr next = chunk_plus_offset(p, psize); - if (!pinuse(p)) { - size_t prevsize = p->prev_foot; - if ((prevsize & IS_MMAPPED_BIT) != 0) { - prevsize &= ~IS_MMAPPED_BIT; - psize += prevsize + MMAP_FOOT_PAD; - if (CALL_MUNMAP((char *) p - prevsize, psize) == 0) - fm->footprint -= psize; - goto postaction; - } else { - mchunkptr prev = chunk_minus_offset(p, prevsize); - psize += prevsize; - p = prev; - if (RTCHECK(ok_address(fm, prev))) { /* consolidate backward */ - if (p != fm->dv) { - unlink_chunk(fm, p, prevsize); - } else if ((next->head & INUSE_BITS) == - INUSE_BITS) { - fm->dvsize = psize; - set_free_with_pinuse(p, psize, next); - goto postaction; - } - } else - goto erroraction; - } - } - - if (RTCHECK(ok_next(p, next) && ok_pinuse(next))) { - if (!cinuse(next)) { /* consolidate forward */ - if (next == fm->top) { - size_t tsize = fm->topsize += psize; - fm->top = p; - p->head = tsize | PINUSE_BIT; - if (p == fm->dv) { - fm->dv = 0; - fm->dvsize = 0; - } - if (should_trim(fm, tsize)) - sys_trim(fm, 0); - goto postaction; - } else if (next == fm->dv) { - size_t dsize = fm->dvsize += psize; - fm->dv = p; - set_size_and_pinuse_of_free_chunk(p, dsize); - goto postaction; - } else { - size_t nsize = chunksize(next); - psize += nsize; - unlink_chunk(fm, next, nsize); - set_size_and_pinuse_of_free_chunk(p, psize); - if (p == fm->dv) { - fm->dvsize = psize; - goto postaction; - } - } - } else - set_free_with_pinuse(p, psize, next); - insert_chunk(fm, p, psize); - check_free_chunk(fm, p); - goto postaction; - } - } - erroraction: - USAGE_ERROR_ACTION(fm, p); - postaction: - POSTACTION(fm); - } - } -} - -void * -mspace_calloc(mspace msp, size_t n_elements, size_t elem_size) -{ - void *mem; - size_t req = 0; - mstate ms = (mstate) msp; - if (!ok_magic(ms)) { - USAGE_ERROR_ACTION(ms, ms); - return 0; - } - if (n_elements != 0) { - req = n_elements * elem_size; - if (((n_elements | elem_size) & ~(size_t) 0xffff) && - (req / n_elements != elem_size)) - req = MAX_SIZE_T; /* force downstream failure on overflow */ - } - mem = internal_malloc(ms, req); - if (mem != 0 && calloc_must_clear(mem2chunk(mem))) - memset(mem, 0, req); - return mem; -} - -void * -mspace_realloc(mspace msp, void *oldmem, size_t bytes) -{ - if (oldmem == 0) - return mspace_malloc(msp, bytes); -#ifdef REALLOC_ZERO_BYTES_FREES - if (bytes == 0) { - mspace_free(msp, oldmem); - return 0; - } -#endif /* REALLOC_ZERO_BYTES_FREES */ - else { -#if FOOTERS - mchunkptr p = mem2chunk(oldmem); - mstate ms = get_mstate_for(p); -#else /* FOOTERS */ - mstate ms = (mstate) msp; -#endif /* FOOTERS */ - if (!ok_magic(ms)) { - USAGE_ERROR_ACTION(ms, ms); - return 0; - } - return internal_realloc(ms, oldmem, bytes); - } -} - -void * -mspace_memalign(mspace msp, size_t alignment, size_t bytes) -{ - mstate ms = (mstate) msp; - if (!ok_magic(ms)) { - USAGE_ERROR_ACTION(ms, ms); - return 0; - } - return internal_memalign(ms, alignment, bytes); -} - -void ** -mspace_independent_calloc(mspace msp, size_t n_elements, - size_t elem_size, void *chunks[]) -{ - size_t sz = elem_size; /* serves as 1-element array */ - mstate ms = (mstate) msp; - if (!ok_magic(ms)) { - USAGE_ERROR_ACTION(ms, ms); - return 0; - } - return ialloc(ms, n_elements, &sz, 3, chunks); -} - -void ** -mspace_independent_comalloc(mspace msp, size_t n_elements, - size_t sizes[], void *chunks[]) -{ - mstate ms = (mstate) msp; - if (!ok_magic(ms)) { - USAGE_ERROR_ACTION(ms, ms); - return 0; - } - return ialloc(ms, n_elements, sizes, 0, chunks); -} - -int -mspace_trim(mspace msp, size_t pad) -{ - int result = 0; - mstate ms = (mstate) msp; - if (ok_magic(ms)) { - if (!PREACTION(ms)) { - result = sys_trim(ms, pad); - POSTACTION(ms); - } - } else { - USAGE_ERROR_ACTION(ms, ms); - } - return result; -} - -void -mspace_malloc_stats(mspace msp) -{ - mstate ms = (mstate) msp; - if (ok_magic(ms)) { - internal_malloc_stats(ms); - } else { - USAGE_ERROR_ACTION(ms, ms); - } -} - -size_t -mspace_footprint(mspace msp) -{ - size_t result; - mstate ms = (mstate) msp; - if (ok_magic(ms)) { - result = ms->footprint; - } - USAGE_ERROR_ACTION(ms, ms); - return result; -} - - -size_t -mspace_max_footprint(mspace msp) -{ - size_t result; - mstate ms = (mstate) msp; - if (ok_magic(ms)) { - result = ms->max_footprint; - } - USAGE_ERROR_ACTION(ms, ms); - return result; -} - - -#if !NO_MALLINFO -struct mallinfo -mspace_mallinfo(mspace msp) -{ - mstate ms = (mstate) msp; - if (!ok_magic(ms)) { - USAGE_ERROR_ACTION(ms, ms); - } - return internal_mallinfo(ms); -} -#endif /* NO_MALLINFO */ - -int -mspace_mallopt(int param_number, int value) -{ - return change_mparam(param_number, value); -} - -#endif /* MSPACES */ - -/* -------------------- Alternative MORECORE functions ------------------- */ - -/* - Guidelines for creating a custom version of MORECORE: - - * For best performance, MORECORE should allocate in multiples of pagesize. - * MORECORE may allocate more memory than requested. (Or even less, - but this will usually result in a malloc failure.) - * MORECORE must not allocate memory when given argument zero, but - instead return one past the end address of memory from previous - nonzero call. - * For best performance, consecutive calls to MORECORE with positive - arguments should return increasing addresses, indicating that - space has been contiguously extended. - * Even though consecutive calls to MORECORE need not return contiguous - addresses, it must be OK for malloc'ed chunks to span multiple - regions in those cases where they do happen to be contiguous. - * MORECORE need not handle negative arguments -- it may instead - just return MFAIL when given negative arguments. - Negative arguments are always multiples of pagesize. MORECORE - must not misinterpret negative args as large positive unsigned - args. You can suppress all such calls from even occurring by defining - MORECORE_CANNOT_TRIM, - - As an example alternative MORECORE, here is a custom allocator - kindly contributed for pre-OSX macOS. It uses virtually but not - necessarily physically contiguous non-paged memory (locked in, - present and won't get swapped out). You can use it by uncommenting - this section, adding some #includes, and setting up the appropriate - defines above: - - #define MORECORE osMoreCore - - There is also a shutdown routine that should somehow be called for - cleanup upon program exit. - - #define MAX_POOL_ENTRIES 100 - #define MINIMUM_MORECORE_SIZE (64 * 1024U) - static int next_os_pool; - void *our_os_pools[MAX_POOL_ENTRIES]; - - void *osMoreCore(int size) - { - void *ptr = 0; - static void *sbrk_top = 0; - - if (size > 0) - { - if (size < MINIMUM_MORECORE_SIZE) - size = MINIMUM_MORECORE_SIZE; - if (CurrentExecutionLevel() == kTaskLevel) - ptr = PoolAllocateResident(size + RM_PAGE_SIZE, 0); - if (ptr == 0) - { - return (void *) MFAIL; - } - // save ptrs so they can be freed during cleanup - our_os_pools[next_os_pool] = ptr; - next_os_pool++; - ptr = (void *) ((((size_t) ptr) + RM_PAGE_MASK) & ~RM_PAGE_MASK); - sbrk_top = (char *) ptr + size; - return ptr; - } - else if (size < 0) - { - // we don't currently support shrink behavior - return (void *) MFAIL; - } - else - { - return sbrk_top; - } - } - - // cleanup any allocated memory pools - // called as last thing before shutting down driver - - void osCleanupMem(void) - { - void **ptr; - - for (ptr = our_os_pools; ptr < &our_os_pools[MAX_POOL_ENTRIES]; ptr++) - if (*ptr) - { - PoolDeallocate(*ptr); - *ptr = 0; - } - } - -*/ - - -/* ----------------------------------------------------------------------- -History: - V2.8.3 Thu Sep 22 11:16:32 2005 Doug Lea (dl at gee) - * Add max_footprint functions - * Ensure all appropriate literals are size_t - * Fix conditional compilation problem for some #define settings - * Avoid concatenating segments with the one provided - in create_mspace_with_base - * Rename some variables to avoid compiler shadowing warnings - * Use explicit lock initialization. - * Better handling of sbrk interference. - * Simplify and fix segment insertion, trimming and mspace_destroy - * Reinstate REALLOC_ZERO_BYTES_FREES option from 2.7.x - * Thanks especially to Dennis Flanagan for help on these. - - V2.8.2 Sun Jun 12 16:01:10 2005 Doug Lea (dl at gee) - * Fix memalign brace error. - - V2.8.1 Wed Jun 8 16:11:46 2005 Doug Lea (dl at gee) - * Fix improper #endif nesting in C++ - * Add explicit casts needed for C++ - - V2.8.0 Mon May 30 14:09:02 2005 Doug Lea (dl at gee) - * Use trees for large bins - * Support mspaces - * Use segments to unify sbrk-based and mmap-based system allocation, - removing need for emulation on most platforms without sbrk. - * Default safety checks - * Optional footer checks. Thanks to William Robertson for the idea. - * Internal code refactoring - * Incorporate suggestions and platform-specific changes. - Thanks to Dennis Flanagan, Colin Plumb, Niall Douglas, - Aaron Bachmann, Emery Berger, and others. - * Speed up non-fastbin processing enough to remove fastbins. - * Remove useless cfree() to avoid conflicts with other apps. - * Remove internal memcpy, memset. Compilers handle builtins better. - * Remove some options that no one ever used and rename others. - - V2.7.2 Sat Aug 17 09:07:30 2002 Doug Lea (dl at gee) - * Fix malloc_state bitmap array misdeclaration - - V2.7.1 Thu Jul 25 10:58:03 2002 Doug Lea (dl at gee) - * Allow tuning of FIRST_SORTED_BIN_SIZE - * Use PTR_UINT as type for all ptr->int casts. Thanks to John Belmonte. - * Better detection and support for non-contiguousness of MORECORE. - Thanks to Andreas Mueller, Conal Walsh, and Wolfram Gloger - * Bypass most of malloc if no frees. Thanks To Emery Berger. - * Fix freeing of old top non-contiguous chunk im sysmalloc. - * Raised default trim and map thresholds to 256K. - * Fix mmap-related #defines. Thanks to Lubos Lunak. - * Fix copy macros; added LACKS_FCNTL_H. Thanks to Neal Walfield. - * Branch-free bin calculation - * Default trim and mmap thresholds now 256K. - - V2.7.0 Sun Mar 11 14:14:06 2001 Doug Lea (dl at gee) - * Introduce independent_comalloc and independent_calloc. - Thanks to Michael Pachos for motivation and help. - * Make optional .h file available - * Allow > 2GB requests on 32bit systems. - * new WIN32 sbrk, mmap, munmap, lock code from . - Thanks also to Andreas Mueller , - and Anonymous. - * Allow override of MALLOC_ALIGNMENT (Thanks to Ruud Waij for - helping test this.) - * memalign: check alignment arg - * realloc: don't try to shift chunks backwards, since this - leads to more fragmentation in some programs and doesn't - seem to help in any others. - * Collect all cases in malloc requiring system memory into sysmalloc - * Use mmap as backup to sbrk - * Place all internal state in malloc_state - * Introduce fastbins (although similar to 2.5.1) - * Many minor tunings and cosmetic improvements - * Introduce USE_PUBLIC_MALLOC_WRAPPERS, USE_MALLOC_LOCK - * Introduce MALLOC_FAILURE_ACTION, MORECORE_CONTIGUOUS - Thanks to Tony E. Bennett and others. - * Include errno.h to support default failure action. - - V2.6.6 Sun Dec 5 07:42:19 1999 Doug Lea (dl at gee) - * return null for negative arguments - * Added Several WIN32 cleanups from Martin C. Fong - * Add 'LACKS_SYS_PARAM_H' for those systems without 'sys/param.h' - (e.g. WIN32 platforms) - * Cleanup header file inclusion for WIN32 platforms - * Cleanup code to avoid Microsoft Visual C++ compiler complaints - * Add 'USE_DL_PREFIX' to quickly allow co-existence with existing - memory allocation routines - * Set 'malloc_getpagesize' for WIN32 platforms (needs more work) - * Use 'assert' rather than 'ASSERT' in WIN32 code to conform to - usage of 'assert' in non-WIN32 code - * Improve WIN32 'sbrk()' emulation's 'findRegion()' routine to - avoid infinite loop - * Always call 'fREe()' rather than 'free()' - - V2.6.5 Wed Jun 17 15:57:31 1998 Doug Lea (dl at gee) - * Fixed ordering problem with boundary-stamping - - V2.6.3 Sun May 19 08:17:58 1996 Doug Lea (dl at gee) - * Added pvalloc, as recommended by H.J. Liu - * Added 64bit pointer support mainly from Wolfram Gloger - * Added anonymously donated WIN32 sbrk emulation - * Malloc, calloc, getpagesize: add optimizations from Raymond Nijssen - * malloc_extend_top: fix mask error that caused wastage after - foreign sbrks - * Add linux mremap support code from HJ Liu - - V2.6.2 Tue Dec 5 06:52:55 1995 Doug Lea (dl at gee) - * Integrated most documentation with the code. - * Add support for mmap, with help from - Wolfram Gloger (Gloger@lrz.uni-muenchen.de). - * Use last_remainder in more cases. - * Pack bins using idea from colin@nyx10.cs.du.edu - * Use ordered bins instead of best-fit threshhold - * Eliminate block-local decls to simplify tracing and debugging. - * Support another case of realloc via move into top - * Fix error occuring when initial sbrk_base not word-aligned. - * Rely on page size for units instead of SBRK_UNIT to - avoid surprises about sbrk alignment conventions. - * Add mallinfo, mallopt. Thanks to Raymond Nijssen - (raymond@es.ele.tue.nl) for the suggestion. - * Add `pad' argument to malloc_trim and top_pad mallopt parameter. - * More precautions for cases where other routines call sbrk, - courtesy of Wolfram Gloger (Gloger@lrz.uni-muenchen.de). - * Added macros etc., allowing use in linux libc from - H.J. Lu (hjl@gnu.ai.mit.edu) - * Inverted this history list - - V2.6.1 Sat Dec 2 14:10:57 1995 Doug Lea (dl at gee) - * Re-tuned and fixed to behave more nicely with V2.6.0 changes. - * Removed all preallocation code since under current scheme - the work required to undo bad preallocations exceeds - the work saved in good cases for most test programs. - * No longer use return list or unconsolidated bins since - no scheme using them consistently outperforms those that don't - given above changes. - * Use best fit for very large chunks to prevent some worst-cases. - * Added some support for debugging - - V2.6.0 Sat Nov 4 07:05:23 1995 Doug Lea (dl at gee) - * Removed footers when chunks are in use. Thanks to - Paul Wilson (wilson@cs.texas.edu) for the suggestion. - - V2.5.4 Wed Nov 1 07:54:51 1995 Doug Lea (dl at gee) - * Added malloc_trim, with help from Wolfram Gloger - (wmglo@Dent.MED.Uni-Muenchen.DE). - - V2.5.3 Tue Apr 26 10:16:01 1994 Doug Lea (dl at g) - - V2.5.2 Tue Apr 5 16:20:40 1994 Doug Lea (dl at g) - * realloc: try to expand in both directions - * malloc: swap order of clean-bin strategy; - * realloc: only conditionally expand backwards - * Try not to scavenge used bins - * Use bin counts as a guide to preallocation - * Occasionally bin return list chunks in first scan - * Add a few optimizations from colin@nyx10.cs.du.edu - - V2.5.1 Sat Aug 14 15:40:43 1993 Doug Lea (dl at g) - * faster bin computation & slightly different binning - * merged all consolidations to one part of malloc proper - (eliminating old malloc_find_space & malloc_clean_bin) - * Scan 2 returns chunks (not just 1) - * Propagate failure in realloc if malloc returns 0 - * Add stuff to allow compilation on non-ANSI compilers - from kpv@research.att.com - - V2.5 Sat Aug 7 07:41:59 1993 Doug Lea (dl at g.oswego.edu) - * removed potential for odd address access in prev_chunk - * removed dependency on getpagesize.h - * misc cosmetics and a bit more internal documentation - * anticosmetics: mangled names in macros to evade debugger strangeness - * tested on sparc, hp-700, dec-mips, rs6000 - with gcc & native cc (hp, dec only) allowing - Detlefs & Zorn comparison study (in SIGPLAN Notices.) - - Trial version Fri Aug 28 13:14:29 1992 Doug Lea (dl at g.oswego.edu) - * Based loosely on libg++-1.2X malloc. (It retains some of the overall - structure of old version, but most details differ.) - -*/ - -#endif /* !HAVE_MALLOC */ - -/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/SDL-mobile/src/stdlib/SDL_qsort.c b/src/SDL-mobile/src/stdlib/SDL_qsort.c deleted file mode 100644 index 6d56c6758..000000000 --- a/src/SDL-mobile/src/stdlib/SDL_qsort.c +++ /dev/null @@ -1,470 +0,0 @@ -/* qsort.c - * (c) 1998 Gareth McCaughan - * - * This is a drop-in replacement for the C library's |qsort()| routine. - * - * Features: - * - Median-of-three pivoting (and more) - * - Truncation and final polishing by a single insertion sort - * - Early truncation when no swaps needed in pivoting step - * - Explicit recursion, guaranteed not to overflow - * - A few little wrinkles stolen from the GNU |qsort()|. - * - separate code for non-aligned / aligned / word-size objects - * - * This code may be reproduced freely provided - * - this file is retained unaltered apart from minor - * changes for portability and efficiency - * - no changes are made to this comment - * - any changes that *are* made are clearly flagged - * - the _ID string below is altered by inserting, after - * the date, the string " altered" followed at your option - * by other material. (Exceptions: you may change the name - * of the exported routine without changing the ID string. - * You may change the values of the macros TRUNC_* and - * PIVOT_THRESHOLD without changing the ID string, provided - * they remain constants with TRUNC_nonaligned, TRUNC_aligned - * and TRUNC_words/WORD_BYTES between 8 and 24, and - * PIVOT_THRESHOLD between 32 and 200.) - * - * You may use it in anything you like; you may make money - * out of it; you may distribute it in object form or as - * part of an executable without including source code; - * you don't have to credit me. (But it would be nice if - * you did.) - * - * If you find problems with this code, or find ways of - * making it significantly faster, please let me know! - * My e-mail address, valid as of early 1998 and certainly - * OK for at least the next 18 months, is - * gjm11@dpmms.cam.ac.uk - * Thanks! - * - * Gareth McCaughan Peterhouse Cambridge 1998 - */ -#include "SDL_config.h" - -/* -#include -#include -#include -*/ -#include "SDL_stdinc.h" -#include "SDL_assert.h" - -#ifdef assert -#undef assert -#endif -#define assert(X) SDL_assert(X) -#ifdef malloc -#undef malloc -#endif -#define malloc SDL_malloc -#ifdef free -#undef free -#endif -#define free SDL_free -#ifdef memcpy -#undef memcpy -#endif -#define memcpy SDL_memcpy -#ifdef memmove -#undef memmove -#endif -#define memmove SDL_memmove -#ifdef qsort -#undef qsort -#endif -#define qsort SDL_qsort - - -#ifndef HAVE_QSORT - -static const char _ID[] = ""; - -/* How many bytes are there per word? (Must be a power of 2, - * and must in fact equal sizeof(int).) - */ -#define WORD_BYTES sizeof(int) - -/* How big does our stack need to be? Answer: one entry per - * bit in a |size_t|. - */ -#define STACK_SIZE (8*sizeof(size_t)) - -/* Different situations have slightly different requirements, - * and we make life epsilon easier by using different truncation - * points for the three different cases. - * So far, I have tuned TRUNC_words and guessed that the same - * value might work well for the other two cases. Of course - * what works well on my machine might work badly on yours. - */ -#define TRUNC_nonaligned 12 -#define TRUNC_aligned 12 -#define TRUNC_words 12*WORD_BYTES /* nb different meaning */ - -/* We use a simple pivoting algorithm for shortish sub-arrays - * and a more complicated one for larger ones. The threshold - * is PIVOT_THRESHOLD. - */ -#define PIVOT_THRESHOLD 40 - -typedef struct -{ - char *first; - char *last; -} stack_entry; -#define pushLeft {stack[stacktop].first=ffirst;stack[stacktop++].last=last;} -#define pushRight {stack[stacktop].first=first;stack[stacktop++].last=llast;} -#define doLeft {first=ffirst;llast=last;continue;} -#define doRight {ffirst=first;last=llast;continue;} -#define pop {if (--stacktop<0) break;\ - first=ffirst=stack[stacktop].first;\ - last=llast=stack[stacktop].last;\ - continue;} - -/* Some comments on the implementation. - * 1. When we finish partitioning the array into "low" - * and "high", we forget entirely about short subarrays, - * because they'll be done later by insertion sort. - * Doing lots of little insertion sorts might be a win - * on large datasets for locality-of-reference reasons, - * but it makes the code much nastier and increases - * bookkeeping overhead. - * 2. We always save the shorter and get to work on the - * longer. This guarantees that every time we push - * an item onto the stack its size is <= 1/2 of that - * of its parent; so the stack can't need more than - * log_2(max-array-size) entries. - * 3. We choose a pivot by looking at the first, last - * and middle elements. We arrange them into order - * because it's easy to do that in conjunction with - * choosing the pivot, and it makes things a little - * easier in the partitioning step. Anyway, the pivot - * is the middle of these three. It's still possible - * to construct datasets where the algorithm takes - * time of order n^2, but it simply never happens in - * practice. - * 3' Newsflash: On further investigation I find that - * it's easy to construct datasets where median-of-3 - * simply isn't good enough. So on large-ish subarrays - * we do a more sophisticated pivoting: we take three - * sets of 3 elements, find their medians, and then - * take the median of those. - * 4. We copy the pivot element to a separate place - * because that way we can always do our comparisons - * directly against a pointer to that separate place, - * and don't have to wonder "did we move the pivot - * element?". This makes the inner loop better. - * 5. It's possible to make the pivoting even more - * reliable by looking at more candidates when n - * is larger. (Taking this to its logical conclusion - * results in a variant of quicksort that doesn't - * have that n^2 worst case.) However, the overhead - * from the extra bookkeeping means that it's just - * not worth while. - * 6. This is pretty clean and portable code. Here are - * all the potential portability pitfalls and problems - * I know of: - * - In one place (the insertion sort) I construct - * a pointer that points just past the end of the - * supplied array, and assume that (a) it won't - * compare equal to any pointer within the array, - * and (b) it will compare equal to a pointer - * obtained by stepping off the end of the array. - * These might fail on some segmented architectures. - * - I assume that there are 8 bits in a |char| when - * computing the size of stack needed. This would - * fail on machines with 9-bit or 16-bit bytes. - * - I assume that if |((int)base&(sizeof(int)-1))==0| - * and |(size&(sizeof(int)-1))==0| then it's safe to - * get at array elements via |int*|s, and that if - * actually |size==sizeof(int)| as well then it's - * safe to treat the elements as |int|s. This might - * fail on systems that convert pointers to integers - * in non-standard ways. - * - I assume that |8*sizeof(size_t)<=INT_MAX|. This - * would be false on a machine with 8-bit |char|s, - * 16-bit |int|s and 4096-bit |size_t|s. :-) - */ - -/* The recursion logic is the same in each case: */ -#define Recurse(Trunc) \ - { size_t l=last-ffirst,r=llast-first; \ - if (l=Trunc) doRight \ - else pop \ - } \ - else if (l<=r) { pushLeft; doRight } \ - else if (r>=Trunc) { pushRight; doLeft }\ - else doLeft \ - } - -/* and so is the pivoting logic: */ -#define Pivot(swapper,sz) \ - if ((size_t)(last-first)>PIVOT_THRESHOLD*sz) mid=pivot_big(first,mid,last,sz,compare);\ - else { \ - if (compare(first,mid)<0) { \ - if (compare(mid,last)>0) { \ - swapper(mid,last); \ - if (compare(first,mid)>0) swapper(first,mid);\ - } \ - } \ - else { \ - if (compare(mid,last)>0) swapper(first,last)\ - else { \ - swapper(first,mid); \ - if (compare(mid,last)>0) swapper(mid,last);\ - } \ - } \ - first+=sz; last-=sz; \ - } - -#ifdef DEBUG_QSORT -#include -#endif - -/* and so is the partitioning logic: */ -#define Partition(swapper,sz) { \ - int swapped=0; \ - do { \ - while (compare(first,pivot)<0) first+=sz; \ - while (compare(pivot,last)<0) last-=sz; \ - if (firstlimit ? limit : nmemb-1)*sz;\ - while (last!=base) { \ - if (compare(first,last)>0) first=last; \ - last-=sz; } \ - if (first!=base) swapper(first,(char*)base); - -/* and so is the insertion sort, in the first two cases: */ -#define Insertion(swapper) \ - last=((char*)base)+nmemb*size; \ - for (first=((char*)base)+size;first!=last;first+=size) { \ - char *test; \ - /* Find the right place for |first|. \ - * My apologies for var reuse. */ \ - for (test=first-size;compare(test,first)>0;test-=size) ; \ - test+=size; \ - if (test!=first) { \ - /* Shift everything in [test,first) \ - * up by one, and place |first| \ - * where |test| is. */ \ - memcpy(pivot,first,size); \ - memmove(test+size,test,first-test); \ - memcpy(test,pivot,size); \ - } \ - } - -#define SWAP_nonaligned(a,b) { \ - register char *aa=(a),*bb=(b); \ - register size_t sz=size; \ - do { register char t=*aa; *aa++=*bb; *bb++=t; } while (--sz); } - -#define SWAP_aligned(a,b) { \ - register int *aa=(int*)(a),*bb=(int*)(b); \ - register size_t sz=size; \ - do { register int t=*aa;*aa++=*bb; *bb++=t; } while (sz-=WORD_BYTES); } - -#define SWAP_words(a,b) { \ - register int t=*((int*)a); *((int*)a)=*((int*)b); *((int*)b)=t; } - -/* ---------------------------------------------------------------------- */ - -static char * -pivot_big(char *first, char *mid, char *last, size_t size, - int compare(const void *, const void *)) -{ - size_t d = (((last - first) / size) >> 3) * size; - char *m1, *m2, *m3; - { - char *a = first, *b = first + d, *c = first + 2 * d; -#ifdef DEBUG_QSORT - fprintf(stderr, "< %d %d %d\n", *(int *) a, *(int *) b, *(int *) c); -#endif - m1 = compare(a, b) < 0 ? - (compare(b, c) < 0 ? b : (compare(a, c) < 0 ? c : a)) - : (compare(a, c) < 0 ? a : (compare(b, c) < 0 ? c : b)); - } - { - char *a = mid - d, *b = mid, *c = mid + d; -#ifdef DEBUG_QSORT - fprintf(stderr, ". %d %d %d\n", *(int *) a, *(int *) b, *(int *) c); -#endif - m2 = compare(a, b) < 0 ? - (compare(b, c) < 0 ? b : (compare(a, c) < 0 ? c : a)) - : (compare(a, c) < 0 ? a : (compare(b, c) < 0 ? c : b)); - } - { - char *a = last - 2 * d, *b = last - d, *c = last; -#ifdef DEBUG_QSORT - fprintf(stderr, "> %d %d %d\n", *(int *) a, *(int *) b, *(int *) c); -#endif - m3 = compare(a, b) < 0 ? - (compare(b, c) < 0 ? b : (compare(a, c) < 0 ? c : a)) - : (compare(a, c) < 0 ? a : (compare(b, c) < 0 ? c : b)); - } -#ifdef DEBUG_QSORT - fprintf(stderr, "-> %d %d %d\n", *(int *) m1, *(int *) m2, *(int *) m3); -#endif - return compare(m1, m2) < 0 ? - (compare(m2, m3) < 0 ? m2 : (compare(m1, m3) < 0 ? m3 : m1)) - : (compare(m1, m3) < 0 ? m1 : (compare(m2, m3) < 0 ? m3 : m2)); -} - -/* ---------------------------------------------------------------------- */ - -static void -qsort_nonaligned(void *base, size_t nmemb, size_t size, - int (*compare) (const void *, const void *)) -{ - - stack_entry stack[STACK_SIZE]; - int stacktop = 0; - char *first, *last; - char *pivot = malloc(size); - size_t trunc = TRUNC_nonaligned * size; - assert(pivot != 0); - - first = (char *) base; - last = first + (nmemb - 1) * size; - - if ((size_t) (last - first) > trunc) { - char *ffirst = first, *llast = last; - while (1) { - /* Select pivot */ - { - char *mid = first + size * ((last - first) / size >> 1); - Pivot(SWAP_nonaligned, size); - memcpy(pivot, mid, size); - } - /* Partition. */ - Partition(SWAP_nonaligned, size); - /* Prepare to recurse/iterate. */ - Recurse(trunc)} - } - PreInsertion(SWAP_nonaligned, TRUNC_nonaligned, size); - Insertion(SWAP_nonaligned); - free(pivot); -} - -static void -qsort_aligned(void *base, size_t nmemb, size_t size, - int (*compare) (const void *, const void *)) -{ - - stack_entry stack[STACK_SIZE]; - int stacktop = 0; - char *first, *last; - char *pivot = malloc(size); - size_t trunc = TRUNC_aligned * size; - assert(pivot != 0); - - first = (char *) base; - last = first + (nmemb - 1) * size; - - if ((size_t) (last - first) > trunc) { - char *ffirst = first, *llast = last; - while (1) { - /* Select pivot */ - { - char *mid = first + size * ((last - first) / size >> 1); - Pivot(SWAP_aligned, size); - memcpy(pivot, mid, size); - } - /* Partition. */ - Partition(SWAP_aligned, size); - /* Prepare to recurse/iterate. */ - Recurse(trunc)} - } - PreInsertion(SWAP_aligned, TRUNC_aligned, size); - Insertion(SWAP_aligned); - free(pivot); -} - -static void -qsort_words(void *base, size_t nmemb, - int (*compare) (const void *, const void *)) -{ - - stack_entry stack[STACK_SIZE]; - int stacktop = 0; - char *first, *last; - char *pivot = malloc(WORD_BYTES); - assert(pivot != 0); - - first = (char *) base; - last = first + (nmemb - 1) * WORD_BYTES; - - if (last - first > TRUNC_words) { - char *ffirst = first, *llast = last; - while (1) { -#ifdef DEBUG_QSORT - fprintf(stderr, "Doing %d:%d: ", - (first - (char *) base) / WORD_BYTES, - (last - (char *) base) / WORD_BYTES); -#endif - /* Select pivot */ - { - char *mid = - first + WORD_BYTES * ((last - first) / (2 * WORD_BYTES)); - Pivot(SWAP_words, WORD_BYTES); - *(int *) pivot = *(int *) mid; - } -#ifdef DEBUG_QSORT - fprintf(stderr, "pivot=%d\n", *(int *) pivot); -#endif - /* Partition. */ - Partition(SWAP_words, WORD_BYTES); - /* Prepare to recurse/iterate. */ - Recurse(TRUNC_words)} - } - PreInsertion(SWAP_words, (TRUNC_words / WORD_BYTES), WORD_BYTES); - /* Now do insertion sort. */ - last = ((char *) base) + nmemb * WORD_BYTES; - for (first = ((char *) base) + WORD_BYTES; first != last; - first += WORD_BYTES) { - /* Find the right place for |first|. My apologies for var reuse */ - int *pl = (int *) (first - WORD_BYTES), *pr = (int *) first; - *(int *) pivot = *(int *) first; - for (; compare(pl, pivot) > 0; pr = pl, --pl) { - *pr = *pl; - } - if (pr != (int *) first) - *pr = *(int *) pivot; - } - free(pivot); -} - -/* ---------------------------------------------------------------------- */ - -void -qsort(void *base, size_t nmemb, size_t size, - int (*compare) (const void *, const void *)) -{ - - if (nmemb <= 1) - return; - if (((uintptr_t) base | size) & (WORD_BYTES - 1)) - qsort_nonaligned(base, nmemb, size, compare); - else if (size != WORD_BYTES) - qsort_aligned(base, nmemb, size, compare); - else - qsort_words(base, nmemb, compare); -} - -#endif /* !HAVE_QSORT */ -/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/SDL-mobile/src/stdlib/SDL_stdlib.c b/src/SDL-mobile/src/stdlib/SDL_stdlib.c deleted file mode 100644 index 56eb5da4f..000000000 --- a/src/SDL-mobile/src/stdlib/SDL_stdlib.c +++ /dev/null @@ -1,742 +0,0 @@ -/* - Simple DirectMedia Layer - Copyright (C) 1997-2012 Sam Lantinga - - 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" - -/* This file contains portable stdlib functions for SDL */ - -#include "SDL_stdinc.h" - -#ifndef HAVE_LIBC -/* These are some C runtime intrinsics that need to be defined */ - -#if defined(_MSC_VER) - -#ifndef __FLTUSED__ -#define __FLTUSED__ -__declspec(selectany) int _fltused = 1; -#endif - -/* The optimizer on Visual Studio 2010/2012 generates memcpy() calls */ -#if _MSC_VER >= 1600 && defined(_WIN64) && !defined(_DEBUG) -#include - -#pragma function(memcpy) -void * memcpy ( void * destination, const void * source, size_t num ) -{ - const Uint8 *src = (const Uint8 *)source; - Uint8 *dst = (Uint8 *)destination; - size_t i; - - /* All WIN64 architectures have SSE, right? */ - if (!((uintptr_t) src & 15) && !((uintptr_t) dst & 15)) { - __m128 values[4]; - for (i = num / 64; i--;) { - _mm_prefetch(src, _MM_HINT_NTA); - values[0] = *(__m128 *) (src + 0); - values[1] = *(__m128 *) (src + 16); - values[2] = *(__m128 *) (src + 32); - values[3] = *(__m128 *) (src + 48); - _mm_stream_ps((float *) (dst + 0), values[0]); - _mm_stream_ps((float *) (dst + 16), values[1]); - _mm_stream_ps((float *) (dst + 32), values[2]); - _mm_stream_ps((float *) (dst + 48), values[3]); - src += 64; - dst += 64; - } - num &= 63; - } - - while (num--) { - *dst++ = *src++; - } - return destination; -} -#endif /* _MSC_VER == 1600 && defined(_WIN64) && !defined(_DEBUG) */ - -#ifdef _M_IX86 - -void -__declspec(naked) -_chkstk() -{ -} - -/* Float to long */ -void -__declspec(naked) -_ftol() -{ - /* *INDENT-OFF* */ - __asm { - push ebp - mov ebp,esp - sub esp,20h - and esp,0FFFFFFF0h - fld st(0) - fst dword ptr [esp+18h] - fistp qword ptr [esp+10h] - fild qword ptr [esp+10h] - mov edx,dword ptr [esp+18h] - mov eax,dword ptr [esp+10h] - test eax,eax - je integer_QnaN_or_zero -arg_is_not_integer_QnaN: - fsubp st(1),st - test edx,edx - jns positive - fstp dword ptr [esp] - mov ecx,dword ptr [esp] - xor ecx,80000000h - add ecx,7FFFFFFFh - adc eax,0 - mov edx,dword ptr [esp+14h] - adc edx,0 - jmp localexit -positive: - fstp dword ptr [esp] - mov ecx,dword ptr [esp] - add ecx,7FFFFFFFh - sbb eax,0 - mov edx,dword ptr [esp+14h] - sbb edx,0 - jmp localexit -integer_QnaN_or_zero: - mov edx,dword ptr [esp+14h] - test edx,7FFFFFFFh - jne arg_is_not_integer_QnaN - fstp dword ptr [esp+18h] - fstp dword ptr [esp+18h] -localexit: - leave - ret - } - /* *INDENT-ON* */ -} - -void -_ftol2_sse() -{ - _ftol(); -} - -/* 64-bit math operators for 32-bit systems */ -void -__declspec(naked) -_allmul() -{ - /* *INDENT-OFF* */ - __asm { - push ebp - mov ebp,esp - push edi - push esi - push ebx - sub esp,0Ch - mov eax,dword ptr [ebp+10h] - mov edi,dword ptr [ebp+8] - mov ebx,eax - mov esi,eax - sar esi,1Fh - mov eax,dword ptr [ebp+8] - mul ebx - imul edi,esi - mov ecx,edx - mov dword ptr [ebp-18h],eax - mov edx,dword ptr [ebp+0Ch] - add ecx,edi - imul ebx,edx - mov eax,dword ptr [ebp-18h] - lea ebx,[ebx+ecx] - mov dword ptr [ebp-14h],ebx - mov edx,dword ptr [ebp-14h] - add esp,0Ch - pop ebx - pop esi - pop edi - pop ebp - ret - } - /* *INDENT-ON* */ -} - -void -__declspec(naked) -_alldiv() -{ - /* *INDENT-OFF* */ - __asm { - push edi - push esi - push ebx - xor edi,edi - mov eax,dword ptr [esp+14h] - or eax,eax - jge L1 - inc edi - mov edx,dword ptr [esp+10h] - neg eax - neg edx - sbb eax,0 - mov dword ptr [esp+14h],eax - mov dword ptr [esp+10h],edx -L1: - mov eax,dword ptr [esp+1Ch] - or eax,eax - jge L2 - inc edi - mov edx,dword ptr [esp+18h] - neg eax - neg edx - sbb eax,0 - mov dword ptr [esp+1Ch],eax - mov dword ptr [esp+18h],edx -L2: - or eax,eax - jne L3 - mov ecx,dword ptr [esp+18h] - mov eax,dword ptr [esp+14h] - xor edx,edx - div ecx - mov ebx,eax - mov eax,dword ptr [esp+10h] - div ecx - mov edx,ebx - jmp L4 -L3: - mov ebx,eax - mov ecx,dword ptr [esp+18h] - mov edx,dword ptr [esp+14h] - mov eax,dword ptr [esp+10h] -L5: - shr ebx,1 - rcr ecx,1 - shr edx,1 - rcr eax,1 - or ebx,ebx - jne L5 - div ecx - mov esi,eax - mul dword ptr [esp+1Ch] - mov ecx,eax - mov eax,dword ptr [esp+18h] - mul esi - add edx,ecx - jb L6 - cmp edx,dword ptr [esp+14h] - ja L6 - jb L7 - cmp eax,dword ptr [esp+10h] - jbe L7 -L6: - dec esi -L7: - xor edx,edx - mov eax,esi -L4: - dec edi - jne L8 - neg edx - neg eax - sbb edx,0 -L8: - pop ebx - pop esi - pop edi - ret 10h - } - /* *INDENT-ON* */ -} - -void -__declspec(naked) -_aulldiv() -{ - /* *INDENT-OFF* */ - __asm { - push ebx - push esi - mov eax,dword ptr [esp+18h] - or eax,eax - jne L1 - mov ecx,dword ptr [esp+14h] - mov eax,dword ptr [esp+10h] - xor edx,edx - div ecx - mov ebx,eax - mov eax,dword ptr [esp+0Ch] - div ecx - mov edx,ebx - jmp L2 -L1: - mov ecx,eax - mov ebx,dword ptr [esp+14h] - mov edx,dword ptr [esp+10h] - mov eax,dword ptr [esp+0Ch] -L3: - shr ecx,1 - rcr ebx,1 - shr edx,1 - rcr eax,1 - or ecx,ecx - jne L3 - div ebx - mov esi,eax - mul dword ptr [esp+18h] - mov ecx,eax - mov eax,dword ptr [esp+14h] - mul esi - add edx,ecx - jb L4 - cmp edx,dword ptr [esp+10h] - ja L4 - jb L5 - cmp eax,dword ptr [esp+0Ch] - jbe L5 -L4: - dec esi -L5: - xor edx,edx - mov eax,esi -L2: - pop esi - pop ebx - ret 10h - } - /* *INDENT-ON* */ -} - -void -__declspec(naked) -_allrem() -{ - /* *INDENT-OFF* */ - __asm { - push ebx - push edi - xor edi,edi - mov eax,dword ptr [esp+10h] - or eax,eax - jge L1 - inc edi - mov edx,dword ptr [esp+0Ch] - neg eax - neg edx - sbb eax,0 - mov dword ptr [esp+10h],eax - mov dword ptr [esp+0Ch],edx -L1: - mov eax,dword ptr [esp+18h] - or eax,eax - jge L2 - mov edx,dword ptr [esp+14h] - neg eax - neg edx - sbb eax,0 - mov dword ptr [esp+18h],eax - mov dword ptr [esp+14h],edx -L2: - or eax,eax - jne L3 - mov ecx,dword ptr [esp+14h] - mov eax,dword ptr [esp+10h] - xor edx,edx - div ecx - mov eax,dword ptr [esp+0Ch] - div ecx - mov eax,edx - xor edx,edx - dec edi - jns L4 - jmp L8 -L3: - mov ebx,eax - mov ecx,dword ptr [esp+14h] - mov edx,dword ptr [esp+10h] - mov eax,dword ptr [esp+0Ch] -L5: - shr ebx,1 - rcr ecx,1 - shr edx,1 - rcr eax,1 - or ebx,ebx - jne L5 - div ecx - mov ecx,eax - mul dword ptr [esp+18h] - xchg eax,ecx - mul dword ptr [esp+14h] - add edx,ecx - jb L6 - cmp edx,dword ptr [esp+10h] - ja L6 - jb L7 - cmp eax,dword ptr [esp+0Ch] - jbe L7 -L6: - sub eax,dword ptr [esp+14h] - sbb edx,dword ptr [esp+18h] -L7: - sub eax,dword ptr [esp+0Ch] - sbb edx,dword ptr [esp+10h] - dec edi - jns L8 -L4: - neg edx - neg eax - sbb edx,0 -L8: - pop edi - pop ebx - ret 10h - } - /* *INDENT-ON* */ -} - -void -__declspec(naked) -_aullrem() -{ - /* *INDENT-OFF* */ - __asm { - push ebx - mov eax,dword ptr [esp+14h] - or eax,eax - jne L1 - mov ecx,dword ptr [esp+10h] - mov eax,dword ptr [esp+0Ch] - xor edx,edx - div ecx - mov eax,dword ptr [esp+8] - div ecx - mov eax,edx - xor edx,edx - jmp L2 -L1: - mov ecx,eax - mov ebx,dword ptr [esp+10h] - mov edx,dword ptr [esp+0Ch] - mov eax,dword ptr [esp+8] -L3: - shr ecx,1 - rcr ebx,1 - shr edx,1 - rcr eax,1 - or ecx,ecx - jne L3 - div ebx - mov ecx,eax - mul dword ptr [esp+14h] - xchg eax,ecx - mul dword ptr [esp+10h] - add edx,ecx - jb L4 - cmp edx,dword ptr [esp+0Ch] - ja L4 - jb L5 - cmp eax,dword ptr [esp+8] - jbe L5 -L4: - sub eax,dword ptr [esp+10h] - sbb edx,dword ptr [esp+14h] -L5: - sub eax,dword ptr [esp+8] - sbb edx,dword ptr [esp+0Ch] - neg edx - neg eax - sbb edx,0 -L2: - pop ebx - ret 10h - } - /* *INDENT-ON* */ -} - -void -__declspec(naked) -_alldvrm() -{ - /* *INDENT-OFF* */ - __asm { - push edi - push esi - push ebp - xor edi,edi - xor ebp,ebp - mov eax,dword ptr [esp+14h] - or eax,eax - jge L1 - inc edi - inc ebp - mov edx,dword ptr [esp+10h] - neg eax - neg edx - sbb eax,0 - mov dword ptr [esp+14h],eax - mov dword ptr [esp+10h],edx -L1: - mov eax,dword ptr [esp+1Ch] - or eax,eax - jge L2 - inc edi - mov edx,dword ptr [esp+18h] - neg eax - neg edx - sbb eax,0 - mov dword ptr [esp+1Ch],eax - mov dword ptr [esp+18h],edx -L2: - or eax,eax - jne L3 - mov ecx,dword ptr [esp+18h] - mov eax,dword ptr [esp+14h] - xor edx,edx - div ecx - mov ebx,eax - mov eax,dword ptr [esp+10h] - div ecx - mov esi,eax - mov eax,ebx - mul dword ptr [esp+18h] - mov ecx,eax - mov eax,esi - mul dword ptr [esp+18h] - add edx,ecx - jmp L4 -L3: - mov ebx,eax - mov ecx,dword ptr [esp+18h] - mov edx,dword ptr [esp+14h] - mov eax,dword ptr [esp+10h] -L5: - shr ebx,1 - rcr ecx,1 - shr edx,1 - rcr eax,1 - or ebx,ebx - jne L5 - div ecx - mov esi,eax - mul dword ptr [esp+1Ch] - mov ecx,eax - mov eax,dword ptr [esp+18h] - mul esi - add edx,ecx - jb L6 - cmp edx,dword ptr [esp+14h] - ja L6 - jb L7 - cmp eax,dword ptr [esp+10h] - jbe L7 -L6: - dec esi - sub eax,dword ptr [esp+18h] - sbb edx,dword ptr [esp+1Ch] -L7: - xor ebx,ebx -L4: - sub eax,dword ptr [esp+10h] - sbb edx,dword ptr [esp+14h] - dec ebp - jns L9 - neg edx - neg eax - sbb edx,0 -L9: - mov ecx,edx - mov edx,ebx - mov ebx,ecx - mov ecx,eax - mov eax,esi - dec edi - jne L8 - neg edx - neg eax - sbb edx,0 -L8: - pop ebp - pop esi - pop edi - ret 10h - } - /* *INDENT-ON* */ -} - -void -__declspec(naked) -_aulldvrm() -{ - /* *INDENT-OFF* */ - __asm { - push esi - mov eax,dword ptr [esp+14h] - or eax,eax - jne L1 - mov ecx,dword ptr [esp+10h] - mov eax,dword ptr [esp+0Ch] - xor edx,edx - div ecx - mov ebx,eax - mov eax,dword ptr [esp+8] - div ecx - mov esi,eax - mov eax,ebx - mul dword ptr [esp+10h] - mov ecx,eax - mov eax,esi - mul dword ptr [esp+10h] - add edx,ecx - jmp L2 -L1: - mov ecx,eax - mov ebx,dword ptr [esp+10h] - mov edx,dword ptr [esp+0Ch] - mov eax,dword ptr [esp+8] -L3: - shr ecx,1 - rcr ebx,1 - shr edx,1 - rcr eax,1 - or ecx,ecx - jne L3 - div ebx - mov esi,eax - mul dword ptr [esp+14h] - mov ecx,eax - mov eax,dword ptr [esp+10h] - mul esi - add edx,ecx - jb L4 - cmp edx,dword ptr [esp+0Ch] - ja L4 - jb L5 - cmp eax,dword ptr [esp+8] - jbe L5 -L4: - dec esi - sub eax,dword ptr [esp+10h] - sbb edx,dword ptr [esp+14h] -L5: - xor ebx,ebx -L2: - sub eax,dword ptr [esp+8] - sbb edx,dword ptr [esp+0Ch] - neg edx - neg eax - sbb edx,0 - mov ecx,edx - mov edx,ebx - mov ebx,ecx - mov ecx,eax - mov eax,esi - pop esi - ret 10h - } - /* *INDENT-ON* */ -} - -void -__declspec(naked) -_allshl() -{ - /* *INDENT-OFF* */ - __asm { - cmp cl,40h - jae RETZERO - cmp cl,20h - jae MORE32 - shld edx,eax,cl - shl eax,cl - ret -MORE32: - mov edx,eax - xor eax,eax - and cl,1Fh - shl edx,cl - ret -RETZERO: - xor eax,eax - xor edx,edx - ret - } - /* *INDENT-ON* */ -} - -void -__declspec(naked) -_allshr() -{ - /* *INDENT-OFF* */ - __asm { - cmp cl,40h - jae RETZERO - cmp cl,20h - jae MORE32 - shrd eax,edx,cl - sar edx,cl - ret -MORE32: - mov eax,edx - xor edx,edx - and cl,1Fh - sar eax,cl - ret -RETZERO: - xor eax,eax - xor edx,edx - ret - } - /* *INDENT-ON* */ -} - -void -__declspec(naked) -_aullshr() -{ - /* *INDENT-OFF* */ - __asm { - cmp cl,40h - jae RETZERO - cmp cl,20h - jae MORE32 - shrd eax,edx,cl - shr edx,cl - ret -MORE32: - mov eax,edx - xor edx,edx - and cl,1Fh - shr eax,cl - ret -RETZERO: - xor eax,eax - xor edx,edx - ret - } - /* *INDENT-ON* */ -} - -#endif /* _M_IX86 */ - -#endif /* MSC_VER */ - -#endif /* !HAVE_LIBC */ - -/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/SDL-mobile/src/stdlib/SDL_string.c b/src/SDL-mobile/src/stdlib/SDL_string.c index b8536e81e..de133da4d 100644 --- a/src/SDL-mobile/src/stdlib/SDL_string.c +++ b/src/SDL-mobile/src/stdlib/SDL_string.c @@ -43,383 +43,7 @@ static int UTF8_TrailingBytes(unsigned char c) return 0; } -#if !defined(HAVE_SSCANF) || !defined(HAVE_STRTOL) -static size_t -SDL_ScanLong(const char *text, int radix, long *valuep) -{ - const char *textstart = text; - long value = 0; - SDL_bool negative = SDL_FALSE; - - if (*text == '-') { - negative = SDL_TRUE; - ++text; - } - if (radix == 16 && SDL_strncmp(text, "0x", 2) == 0) { - text += 2; - } - for (;;) { - int v; - if (SDL_isdigit((unsigned char) *text)) { - v = *text - '0'; - } else if (radix == 16 && SDL_isupperhex(*text)) { - v = 10 + (*text - 'A'); - } else if (radix == 16 && SDL_islowerhex(*text)) { - v = 10 + (*text - 'a'); - } else { - break; - } - value *= radix; - value += v; - ++text; - } - if (valuep) { - if (negative && value) { - *valuep = -value; - } else { - *valuep = value; - } - } - return (text - textstart); -} -#endif - -#if !defined(HAVE_SSCANF) || !defined(HAVE_STRTOUL) || !defined(HAVE_STRTOD) -static size_t -SDL_ScanUnsignedLong(const char *text, int radix, unsigned long *valuep) -{ - const char *textstart = text; - unsigned long value = 0; - - if (radix == 16 && SDL_strncmp(text, "0x", 2) == 0) { - text += 2; - } - for (;;) { - int v; - if (SDL_isdigit((unsigned char) *text)) { - v = *text - '0'; - } else if (radix == 16 && SDL_isupperhex(*text)) { - v = 10 + (*text - 'A'); - } else if (radix == 16 && SDL_islowerhex(*text)) { - v = 10 + (*text - 'a'); - } else { - break; - } - value *= radix; - value += v; - ++text; - } - if (valuep) { - *valuep = value; - } - return (text - textstart); -} -#endif - -#ifndef HAVE_SSCANF -static size_t -SDL_ScanUintPtrT(const char *text, int radix, uintptr_t * valuep) -{ - const char *textstart = text; - uintptr_t value = 0; - - if (radix == 16 && SDL_strncmp(text, "0x", 2) == 0) { - text += 2; - } - for (;;) { - int v; - if (SDL_isdigit((unsigned char) *text)) { - v = *text - '0'; - } else if (radix == 16 && SDL_isupperhex(*text)) { - v = 10 + (*text - 'A'); - } else if (radix == 16 && SDL_islowerhex(*text)) { - v = 10 + (*text - 'a'); - } else { - break; - } - value *= radix; - value += v; - ++text; - } - if (valuep) { - *valuep = value; - } - return (text - textstart); -} -#endif - -#if !defined(HAVE_SSCANF) || !defined(HAVE_STRTOLL) -static size_t -SDL_ScanLongLong(const char *text, int radix, Sint64 * valuep) -{ - const char *textstart = text; - Sint64 value = 0; - SDL_bool negative = SDL_FALSE; - - if (*text == '-') { - negative = SDL_TRUE; - ++text; - } - if (radix == 16 && SDL_strncmp(text, "0x", 2) == 0) { - text += 2; - } - for (;;) { - int v; - if (SDL_isdigit((unsigned char) *text)) { - v = *text - '0'; - } else if (radix == 16 && SDL_isupperhex(*text)) { - v = 10 + (*text - 'A'); - } else if (radix == 16 && SDL_islowerhex(*text)) { - v = 10 + (*text - 'a'); - } else { - break; - } - value *= radix; - value += v; - ++text; - } - if (valuep) { - if (negative && value) { - *valuep = -value; - } else { - *valuep = value; - } - } - return (text - textstart); -} -#endif - -#if !defined(HAVE_SSCANF) || !defined(HAVE_STRTOULL) -static size_t -SDL_ScanUnsignedLongLong(const char *text, int radix, Uint64 * valuep) -{ - const char *textstart = text; - Uint64 value = 0; - - if (radix == 16 && SDL_strncmp(text, "0x", 2) == 0) { - text += 2; - } - for (;;) { - int v; - if (SDL_isdigit((unsigned char) *text)) { - v = *text - '0'; - } else if (radix == 16 && SDL_isupperhex(*text)) { - v = 10 + (*text - 'A'); - } else if (radix == 16 && SDL_islowerhex(*text)) { - v = 10 + (*text - 'a'); - } else { - break; - } - value *= radix; - value += v; - ++text; - } - if (valuep) { - *valuep = value; - } - return (text - textstart); -} -#endif - -#if !defined(HAVE_SSCANF) || !defined(HAVE_STRTOD) -static size_t -SDL_ScanFloat(const char *text, double *valuep) -{ - const char *textstart = text; - unsigned long lvalue = 0; - double value = 0.0; - SDL_bool negative = SDL_FALSE; - - if (*text == '-') { - negative = SDL_TRUE; - ++text; - } - text += SDL_ScanUnsignedLong(text, 10, &lvalue); - value += lvalue; - if (*text == '.') { - int mult = 10; - ++text; - while (SDL_isdigit((unsigned char) *text)) { - lvalue = *text - '0'; - value += (double) lvalue / mult; - mult *= 10; - ++text; - } - } - if (valuep) { - if (negative && value) { - *valuep = -value; - } else { - *valuep = value; - } - } - return (text - textstart); -} -#endif - -#ifndef SDL_memset -void * -SDL_memset(void *dst, int c, size_t len) -{ - size_t left = (len % 4); - Uint32 *dstp4; - Uint8 *dstp1; - Uint32 value4 = (c | (c << 8) | (c << 16) | (c << 24)); - Uint8 value1 = (Uint8) c; - - dstp4 = (Uint32 *) dst; - len /= 4; - while (len--) { - *dstp4++ = value4; - } - - dstp1 = (Uint8 *) dstp4; - switch (left) { - case 3: - *dstp1++ = value1; - case 2: - *dstp1++ = value1; - case 1: - *dstp1++ = value1; - } - - return dst; -} -#endif - -#ifndef SDL_memcpy -void * -SDL_memcpy(void *dst, const void *src, size_t len) -{ - size_t left = (len % 4); - Uint32 *srcp4, *dstp4; - Uint8 *srcp1, *dstp1; - - srcp4 = (Uint32 *) src; - dstp4 = (Uint32 *) dst; - len /= 4; - while (len--) { - *dstp4++ = *srcp4++; - } - - srcp1 = (Uint8 *) srcp4; - dstp1 = (Uint8 *) dstp4; - switch (left) { - case 3: - *dstp1++ = *srcp1++; - case 2: - *dstp1++ = *srcp1++; - case 1: - *dstp1++ = *srcp1++; - } - - return dst; -} -#endif - -#ifndef SDL_memmove -void * -SDL_memmove(void *dst, const void *src, size_t len) -{ - char *srcp = (char *) src; - char *dstp = (char *) dst; - - if (src < dst) { - srcp += len - 1; - dstp += len - 1; - while (len--) { - *dstp-- = *srcp--; - } - } else { - while (len--) { - *dstp++ = *srcp++; - } - } - return dst; -} -#endif - -#ifndef SDL_memcmp -int -SDL_memcmp(const void *s1, const void *s2, size_t len) -{ - char *s1p = (char *) s1; - char *s2p = (char *) s2; - while (len--) { - if (*s1p != *s2p) { - return (*s1p - *s2p); - } - ++s1p; - ++s2p; - } - return 0; -} -#endif - -#ifndef HAVE_STRLEN -size_t -SDL_strlen(const char *string) -{ - size_t len = 0; - while (*string++) { - ++len; - } - return len; -} -#endif -#ifndef HAVE_WCSLEN -size_t -SDL_wcslen(const wchar_t * string) -{ - size_t len = 0; - while (*string++) { - ++len; - } - return len; -} -#endif - -#ifndef HAVE_WCSLCPY -size_t -SDL_wcslcpy(wchar_t *dst, const wchar_t *src, size_t maxlen) -{ - size_t srclen = SDL_wcslen(src); - if (maxlen > 0) { - size_t len = SDL_min(srclen, maxlen - 1); - SDL_memcpy(dst, src, len * sizeof(wchar_t)); - dst[len] = '\0'; - } - return srclen; -} -#endif - -#ifndef HAVE_WCSLCAT -size_t -SDL_wcslcat(wchar_t *dst, const wchar_t *src, size_t maxlen) -{ - size_t dstlen = SDL_wcslen(dst); - size_t srclen = SDL_wcslen(src); - if (dstlen < maxlen) { - SDL_wcslcpy(dst + dstlen, src, maxlen - dstlen); - } - return dstlen + srclen; -} -#endif - -#ifndef HAVE_STRLCPY -size_t -SDL_strlcpy(char *dst, const char *src, size_t maxlen) -{ - size_t srclen = SDL_strlen(src); - if (maxlen > 0) { - size_t len = SDL_min(srclen, maxlen - 1); - SDL_memcpy(dst, src, len); - dst[len] = '\0'; - } - return srclen; -} -#endif size_t SDL_utf8strlcpy(char *dst, const char *src, size_t dst_bytes) { @@ -452,962 +76,3 @@ size_t SDL_utf8strlcpy(char *dst, const char *src, size_t dst_bytes) dst[bytes] = '\0'; return bytes; } - -#ifndef HAVE_STRLCAT -size_t -SDL_strlcat(char *dst, const char *src, size_t maxlen) -{ - size_t dstlen = SDL_strlen(dst); - size_t srclen = SDL_strlen(src); - if (dstlen < maxlen) { - SDL_strlcpy(dst + dstlen, src, maxlen - dstlen); - } - return dstlen + srclen; -} -#endif - -#ifndef HAVE_STRDUP -char * -SDL_strdup(const char *string) -{ - size_t len = SDL_strlen(string) + 1; - char *newstr = SDL_malloc(len); - if (newstr) { - SDL_strlcpy(newstr, string, len); - } - return newstr; -} -#endif - -#ifndef HAVE__STRREV -char * -SDL_strrev(char *string) -{ - size_t len = SDL_strlen(string); - char *a = &string[0]; - char *b = &string[len - 1]; - len /= 2; - while (len--) { - char c = *a; - *a++ = *b; - *b-- = c; - } - return string; -} -#endif - -#ifndef HAVE__STRUPR -char * -SDL_strupr(char *string) -{ - char *bufp = string; - while (*bufp) { - *bufp = SDL_toupper((unsigned char) *bufp); - ++bufp; - } - return string; -} -#endif - -#ifndef HAVE__STRLWR -char * -SDL_strlwr(char *string) -{ - char *bufp = string; - while (*bufp) { - *bufp = SDL_tolower((unsigned char) *bufp); - ++bufp; - } - return string; -} -#endif - -#ifndef HAVE_STRCHR -char * -SDL_strchr(const char *string, int c) -{ - while (*string) { - if (*string == c) { - return (char *) string; - } - ++string; - } - return NULL; -} -#endif - -#ifndef HAVE_STRRCHR -char * -SDL_strrchr(const char *string, int c) -{ - const char *bufp = string + SDL_strlen(string) - 1; - while (bufp >= string) { - if (*bufp == c) { - return (char *) bufp; - } - --bufp; - } - return NULL; -} -#endif - -#ifndef HAVE_STRSTR -char * -SDL_strstr(const char *haystack, const char *needle) -{ - size_t length = SDL_strlen(needle); - while (*haystack) { - if (SDL_strncmp(haystack, needle, length) == 0) { - return (char *) haystack; - } - ++haystack; - } - return NULL; -} -#endif - -#if !defined(HAVE__LTOA) || !defined(HAVE__I64TOA) || \ - !defined(HAVE__ULTOA) || !defined(HAVE__UI64TOA) -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', - 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', - 'U', 'V', 'W', 'X', 'Y', 'Z' -}; -#endif /* ntoa() conversion table */ - -#ifndef HAVE__LTOA -char * -SDL_ltoa(long value, char *string, int radix) -{ - char *bufp = string; - - if (value < 0) { - *bufp++ = '-'; - value = -value; - } - if (value) { - while (value > 0) { - *bufp++ = ntoa_table[value % radix]; - value /= radix; - } - } else { - *bufp++ = '0'; - } - *bufp = '\0'; - - /* The numbers went into the string backwards. :) */ - if (*string == '-') { - SDL_strrev(string + 1); - } else { - SDL_strrev(string); - } - - return string; -} -#endif - -#ifndef HAVE__ULTOA -char * -SDL_ultoa(unsigned long value, char *string, int radix) -{ - char *bufp = string; - - if (value) { - while (value > 0) { - *bufp++ = ntoa_table[value % radix]; - value /= radix; - } - } else { - *bufp++ = '0'; - } - *bufp = '\0'; - - /* The numbers went into the string backwards. :) */ - SDL_strrev(string); - - return string; -} -#endif - -#ifndef HAVE_STRTOL -long -SDL_strtol(const char *string, char **endp, int base) -{ - size_t len; - long value; - - if (!base) { - if ((SDL_strlen(string) > 2) && (SDL_strncmp(string, "0x", 2) == 0)) { - base = 16; - } else { - base = 10; - } - } - - len = SDL_ScanLong(string, base, &value); - if (endp) { - *endp = (char *) string + len; - } - return value; -} -#endif - -#ifndef HAVE_STRTOUL -unsigned long -SDL_strtoul(const char *string, char **endp, int base) -{ - size_t len; - unsigned long value; - - if (!base) { - if ((SDL_strlen(string) > 2) && (SDL_strncmp(string, "0x", 2) == 0)) { - base = 16; - } else { - base = 10; - } - } - - len = SDL_ScanUnsignedLong(string, base, &value); - if (endp) { - *endp = (char *) string + len; - } - return value; -} -#endif - -#ifndef HAVE__I64TOA -char * -SDL_lltoa(Sint64 value, char *string, int radix) -{ - char *bufp = string; - - if (value < 0) { - *bufp++ = '-'; - value = -value; - } - if (value) { - while (value > 0) { - *bufp++ = ntoa_table[value % radix]; - value /= radix; - } - } else { - *bufp++ = '0'; - } - *bufp = '\0'; - - /* The numbers went into the string backwards. :) */ - if (*string == '-') { - SDL_strrev(string + 1); - } else { - SDL_strrev(string); - } - - return string; -} -#endif - -#ifndef HAVE__UI64TOA -char * -SDL_ulltoa(Uint64 value, char *string, int radix) -{ - char *bufp = string; - - if (value) { - while (value > 0) { - *bufp++ = ntoa_table[value % radix]; - value /= radix; - } - } else { - *bufp++ = '0'; - } - *bufp = '\0'; - - /* The numbers went into the string backwards. :) */ - SDL_strrev(string); - - return string; -} -#endif - -#ifndef HAVE_STRTOLL -Sint64 -SDL_strtoll(const char *string, char **endp, int base) -{ - size_t len; - Sint64 value; - - if (!base) { - if ((SDL_strlen(string) > 2) && (SDL_strncmp(string, "0x", 2) == 0)) { - base = 16; - } else { - base = 10; - } - } - - len = SDL_ScanLongLong(string, base, &value); - if (endp) { - *endp = (char *) string + len; - } - return value; -} -#endif - -#ifndef HAVE_STRTOULL -Uint64 -SDL_strtoull(const char *string, char **endp, int base) -{ - size_t len; - Uint64 value; - - if (!base) { - if ((SDL_strlen(string) > 2) && (SDL_strncmp(string, "0x", 2) == 0)) { - base = 16; - } else { - base = 10; - } - } - - len = SDL_ScanUnsignedLongLong(string, base, &value); - if (endp) { - *endp = (char *) string + len; - } - return value; -} -#endif - -#ifndef HAVE_STRTOD -double -SDL_strtod(const char *string, char **endp) -{ - size_t len; - double value; - - len = SDL_ScanFloat(string, &value); - if (endp) { - *endp = (char *) string + len; - } - return value; -} -#endif - -#ifndef HAVE_STRCMP -int -SDL_strcmp(const char *str1, const char *str2) -{ - while (*str1 && *str2) { - if (*str1 != *str2) - break; - ++str1; - ++str2; - } - return (int) ((unsigned char) *str1 - (unsigned char) *str2); -} -#endif - -#ifndef HAVE_STRNCMP -int -SDL_strncmp(const char *str1, const char *str2, size_t maxlen) -{ - while (*str1 && *str2 && maxlen) { - if (*str1 != *str2) - break; - ++str1; - ++str2; - --maxlen; - } - if (!maxlen) { - return 0; - } - return (int) ((unsigned char) *str1 - (unsigned char) *str2); -} -#endif - -#if !defined(HAVE_STRCASECMP) && !defined(HAVE__STRICMP) -int -SDL_strcasecmp(const char *str1, const char *str2) -{ - char a = 0; - char b = 0; - while (*str1 && *str2) { - a = SDL_tolower((unsigned char) *str1); - b = SDL_tolower((unsigned char) *str2); - if (a != b) - break; - ++str1; - ++str2; - } - a = SDL_tolower(*str1); - b = SDL_tolower(*str2); - return (int) ((unsigned char) a - (unsigned char) b); -} -#endif - -#if !defined(HAVE_STRNCASECMP) && !defined(HAVE__STRNICMP) -int -SDL_strncasecmp(const char *str1, const char *str2, size_t maxlen) -{ - char a = 0; - char b = 0; - while (*str1 && *str2 && maxlen) { - a = SDL_tolower((unsigned char) *str1); - b = SDL_tolower((unsigned char) *str2); - if (a != b) - break; - ++str1; - ++str2; - --maxlen; - } - a = SDL_tolower((unsigned char) *str1); - b = SDL_tolower((unsigned char) *str2); - return (int) ((unsigned char) a - (unsigned char) b); -} -#endif - -#ifndef HAVE_SSCANF -int -SDL_sscanf(const char *text, const char *fmt, ...) -{ - va_list ap; - int retval = 0; - - va_start(ap, fmt); - while (*fmt) { - if (*fmt == ' ') { - while (SDL_isspace((unsigned char) *text)) { - ++text; - } - ++fmt; - continue; - } - if (*fmt == '%') { - SDL_bool done = SDL_FALSE; - long count = 0; - int radix = 10; - enum - { - DO_SHORT, - DO_INT, - DO_LONG, - DO_LONGLONG - } inttype = DO_INT; - SDL_bool suppress = SDL_FALSE; - - ++fmt; - if (*fmt == '%') { - if (*text == '%') { - ++text; - ++fmt; - continue; - } - break; - } - if (*fmt == '*') { - suppress = SDL_TRUE; - ++fmt; - } - fmt += SDL_ScanLong(fmt, 10, &count); - - if (*fmt == 'c') { - if (!count) { - count = 1; - } - if (suppress) { - while (count--) { - ++text; - } - } else { - char *valuep = va_arg(ap, char *); - while (count--) { - *valuep++ = *text++; - } - ++retval; - } - continue; - } - - while (SDL_isspace((unsigned char) *text)) { - ++text; - } - - /* FIXME: implement more of the format specifiers */ - while (!done) { - switch (*fmt) { - case '*': - suppress = SDL_TRUE; - break; - case 'h': - if (inttype > DO_SHORT) { - ++inttype; - } - break; - case 'l': - if (inttype < DO_LONGLONG) { - ++inttype; - } - break; - case 'I': - if (SDL_strncmp(fmt, "I64", 3) == 0) { - fmt += 2; - inttype = DO_LONGLONG; - } - break; - case 'i': - { - int index = 0; - if (text[index] == '-') { - ++index; - } - if (text[index] == '0') { - if (SDL_tolower((unsigned char) text[index + 1]) - == 'x') { - radix = 16; - } else { - radix = 8; - } - } - } - /* Fall through to %d handling */ - case 'd': - if (inttype == DO_LONGLONG) { - Sint64 value; - text += SDL_ScanLongLong(text, radix, &value); - if (!suppress) { - Sint64 *valuep = va_arg(ap, Sint64 *); - *valuep = value; - ++retval; - } - } else { - long value; - text += SDL_ScanLong(text, radix, &value); - if (!suppress) { - switch (inttype) { - case DO_SHORT: - { - short *valuep = va_arg(ap, short *); - *valuep = (short) value; - } - break; - case DO_INT: - { - int *valuep = va_arg(ap, int *); - *valuep = (int) value; - } - break; - case DO_LONG: - { - long *valuep = va_arg(ap, long *); - *valuep = value; - } - break; - case DO_LONGLONG: - /* Handled above */ - break; - } - ++retval; - } - } - done = SDL_TRUE; - break; - case 'o': - if (radix == 10) { - radix = 8; - } - /* Fall through to unsigned handling */ - case 'x': - case 'X': - if (radix == 10) { - radix = 16; - } - /* Fall through to unsigned handling */ - case 'u': - if (inttype == DO_LONGLONG) { - Uint64 value; - text += SDL_ScanUnsignedLongLong(text, radix, &value); - if (!suppress) { - Uint64 *valuep = va_arg(ap, Uint64 *); - *valuep = value; - ++retval; - } - } else { - unsigned long value; - text += SDL_ScanUnsignedLong(text, radix, &value); - if (!suppress) { - switch (inttype) { - case DO_SHORT: - { - short *valuep = va_arg(ap, short *); - *valuep = (short) value; - } - break; - case DO_INT: - { - int *valuep = va_arg(ap, int *); - *valuep = (int) value; - } - break; - case DO_LONG: - { - long *valuep = va_arg(ap, long *); - *valuep = value; - } - break; - case DO_LONGLONG: - /* Handled above */ - break; - } - ++retval; - } - } - done = SDL_TRUE; - break; - case 'p': - { - uintptr_t value; - text += SDL_ScanUintPtrT(text, 16, &value); - if (!suppress) { - void **valuep = va_arg(ap, void **); - *valuep = (void *) value; - ++retval; - } - } - done = SDL_TRUE; - break; - case 'f': - { - double value; - text += SDL_ScanFloat(text, &value); - if (!suppress) { - float *valuep = va_arg(ap, float *); - *valuep = (float) value; - ++retval; - } - } - done = SDL_TRUE; - break; - case 's': - if (suppress) { - while (!SDL_isspace((unsigned char) *text)) { - ++text; - if (count) { - if (--count == 0) { - break; - } - } - } - } else { - char *valuep = va_arg(ap, char *); - while (!SDL_isspace((unsigned char) *text)) { - *valuep++ = *text++; - if (count) { - if (--count == 0) { - break; - } - } - } - *valuep = '\0'; - ++retval; - } - done = SDL_TRUE; - break; - default: - done = SDL_TRUE; - break; - } - ++fmt; - } - continue; - } - if (*text == *fmt) { - ++text; - ++fmt; - continue; - } - /* Text didn't match format specifier */ - break; - } - va_end(ap); - - return retval; -} -#endif - -#ifndef HAVE_SNPRINTF -int -SDL_snprintf(char *text, size_t maxlen, const char *fmt, ...) -{ - va_list ap; - int retval; - - va_start(ap, fmt); - retval = SDL_vsnprintf(text, maxlen, fmt, ap); - va_end(ap); - - return retval; -} -#endif - -#ifndef HAVE_VSNPRINTF -static size_t -SDL_PrintLong(char *text, long value, int radix, size_t maxlen) -{ - char num[130]; - size_t size; - - SDL_ltoa(value, num, radix); - size = SDL_strlen(num); - if (size >= maxlen) { - size = maxlen - 1; - } - SDL_strlcpy(text, num, size + 1); - - return size; -} - -static size_t -SDL_PrintUnsignedLong(char *text, unsigned long value, int radix, - size_t maxlen) -{ - char num[130]; - size_t size; - - SDL_ultoa(value, num, radix); - size = SDL_strlen(num); - if (size >= maxlen) { - size = maxlen - 1; - } - SDL_strlcpy(text, num, size + 1); - - return size; -} - -static size_t -SDL_PrintLongLong(char *text, Sint64 value, int radix, size_t maxlen) -{ - char num[130]; - size_t size; - - SDL_lltoa(value, num, radix); - size = SDL_strlen(num); - if (size >= maxlen) { - size = maxlen - 1; - } - SDL_strlcpy(text, num, size + 1); - - return size; -} - -static size_t -SDL_PrintUnsignedLongLong(char *text, Uint64 value, int radix, size_t maxlen) -{ - char num[130]; - size_t size; - - SDL_ulltoa(value, num, radix); - size = SDL_strlen(num); - if (size >= maxlen) { - size = maxlen - 1; - } - SDL_strlcpy(text, num, size + 1); - - return size; -} - -static size_t -SDL_PrintFloat(char *text, double arg, size_t maxlen) -{ - char *textstart = text; - if (arg) { - /* This isn't especially accurate, but hey, it's easy. :) */ - const double precision = 0.00000001; - size_t len; - unsigned long value; - - if (arg < 0) { - *text++ = '-'; - --maxlen; - arg = -arg; - } - value = (unsigned long) arg; - len = SDL_PrintUnsignedLong(text, value, 10, maxlen); - text += len; - maxlen -= len; - arg -= value; - if (arg > precision && maxlen) { - int mult = 10; - *text++ = '.'; - while ((arg > precision) && maxlen) { - value = (unsigned long) (arg * mult); - len = SDL_PrintUnsignedLong(text, value, 10, maxlen); - text += len; - maxlen -= len; - arg -= (double) value / mult; - mult *= 10; - } - } - } else { - *text++ = '0'; - } - return (text - textstart); -} - -static size_t -SDL_PrintString(char *text, const char *string, size_t maxlen) -{ - char *textstart = text; - while (*string && maxlen--) { - *text++ = *string++; - } - return (text - textstart); -} - -int -SDL_vsnprintf(char *text, size_t maxlen, const char *fmt, va_list ap) -{ - char *textstart = text; - if (maxlen <= 0) { - return 0; - } - --maxlen; /* For the trailing '\0' */ - while (*fmt && maxlen) { - if (*fmt == '%') { - SDL_bool done = SDL_FALSE; - size_t len = 0; - SDL_bool do_lowercase = SDL_FALSE; - int radix = 10; - enum - { - DO_INT, - DO_LONG, - DO_LONGLONG - } inttype = DO_INT; - - ++fmt; - /* FIXME: implement more of the format specifiers */ - while (*fmt == '.' || (*fmt >= '0' && *fmt <= '9')) { - ++fmt; - } - while (!done) { - switch (*fmt) { - case '%': - *text = '%'; - len = 1; - done = SDL_TRUE; - break; - case 'c': - /* char is promoted to int when passed through (...) */ - *text = (char) va_arg(ap, int); - len = 1; - done = SDL_TRUE; - break; - case 'h': - /* short is promoted to int when passed through (...) */ - break; - case 'l': - if (inttype < DO_LONGLONG) { - ++inttype; - } - break; - case 'I': - if (SDL_strncmp(fmt, "I64", 3) == 0) { - fmt += 2; - inttype = DO_LONGLONG; - } - break; - case 'i': - case 'd': - switch (inttype) { - case DO_INT: - len = - SDL_PrintLong(text, - (long) va_arg(ap, int), - radix, maxlen); - break; - case DO_LONG: - len = - SDL_PrintLong(text, va_arg(ap, long), - radix, maxlen); - break; - case DO_LONGLONG: - len = - SDL_PrintLongLong(text, - va_arg(ap, Sint64), - radix, maxlen); - break; - } - done = SDL_TRUE; - break; - case 'p': - case 'x': - do_lowercase = SDL_TRUE; - /* Fall through to 'X' handling */ - case 'X': - if (radix == 10) { - radix = 16; - } - if (*fmt == 'p') { - inttype = DO_LONG; - } - /* Fall through to unsigned handling */ - case 'o': - if (radix == 10) { - radix = 8; - } - /* Fall through to unsigned handling */ - case 'u': - switch (inttype) { - case DO_INT: - len = SDL_PrintUnsignedLong(text, (unsigned long) - va_arg(ap, - unsigned - int), - radix, maxlen); - break; - case DO_LONG: - len = - SDL_PrintUnsignedLong(text, - va_arg(ap, - unsigned - long), - radix, maxlen); - break; - case DO_LONGLONG: - len = - SDL_PrintUnsignedLongLong(text, - va_arg(ap, - Uint64), - radix, maxlen); - break; - } - if (do_lowercase) { - SDL_strlwr(text); - } - done = SDL_TRUE; - break; - case 'f': - len = SDL_PrintFloat(text, va_arg(ap, double), maxlen); - done = SDL_TRUE; - break; - case 's': - len = SDL_PrintString(text, va_arg(ap, char *), maxlen); - done = SDL_TRUE; - break; - default: - done = SDL_TRUE; - break; - } - ++fmt; - } - text += len; - maxlen -= len; - } else { - *text++ = *fmt++; - --maxlen; - } - } - *text = '\0'; - - return (int)(text - textstart); -} -#endif -/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/SDL-mobile/src/timer/unix/SDL_systimer.c b/src/SDL-mobile/src/timer/unix/SDL_systimer.c index f8fb067cf..7626795fe 100644 --- a/src/SDL-mobile/src/timer/unix/SDL_systimer.c +++ b/src/SDL-mobile/src/timer/unix/SDL_systimer.c @@ -34,42 +34,22 @@ for __USE_POSIX199309 Tommi Kyntola (tommi.kyntola@ray.fi) 27/09/2005 */ -#if HAVE_NANOSLEEP || HAVE_CLOCK_GETTIME #include -#endif /* The first ticks value of the application */ -#ifdef HAVE_CLOCK_GETTIME -static struct timespec start; -#else static struct timeval start; -#endif /* HAVE_CLOCK_GETTIME */ void SDL_StartTicks(void) { /* Set first ticks value */ -#if HAVE_CLOCK_GETTIME - clock_gettime(CLOCK_MONOTONIC, &start); -#else gettimeofday(&start, NULL); -#endif } Uint32 SDL_GetTicks(void) { -#if HAVE_CLOCK_GETTIME - Uint32 ticks; - struct timespec now; - - clock_gettime(CLOCK_MONOTONIC, &now); - ticks = - (now.tv_sec - start.tv_sec) * 1000 + (now.tv_nsec - - start.tv_nsec) / 1000000; - return (ticks); -#else Uint32 ticks; struct timeval now; @@ -78,22 +58,11 @@ SDL_GetTicks(void) (now.tv_sec - start.tv_sec) * 1000 + (now.tv_usec - start.tv_usec) / 1000; return (ticks); -#endif } Uint64 SDL_GetPerformanceCounter(void) { -#if HAVE_CLOCK_GETTIME - Uint64 ticks; - struct timespec now; - - clock_gettime(CLOCK_MONOTONIC, &now); - ticks = now.tv_sec; - ticks *= 1000000000; - ticks += now.tv_nsec; - return (ticks); -#else Uint64 ticks; struct timeval now; @@ -102,17 +71,12 @@ SDL_GetPerformanceCounter(void) ticks *= 1000000; ticks += now.tv_usec; return (ticks); -#endif } Uint64 SDL_GetPerformanceFrequency(void) { -#if HAVE_CLOCK_GETTIME - return 1000000000; -#else return 1000000; -#endif } void @@ -120,41 +84,18 @@ SDL_Delay(Uint32 ms) { int was_error; -#if HAVE_NANOSLEEP struct timespec elapsed, tv; -#else - struct timeval tv; - Uint32 then, now, elapsed; -#endif /* Set the timeout interval */ -#if HAVE_NANOSLEEP elapsed.tv_sec = ms / 1000; elapsed.tv_nsec = (ms % 1000) * 1000000; -#else - then = SDL_GetTicks(); -#endif + do { errno = 0; -#if HAVE_NANOSLEEP tv.tv_sec = elapsed.tv_sec; tv.tv_nsec = elapsed.tv_nsec; was_error = nanosleep(&tv, &elapsed); -#else - /* Calculate the time interval left (in case of interrupt) */ - now = SDL_GetTicks(); - elapsed = (now - then); - then = now; - if (elapsed >= ms) { - break; - } - ms -= elapsed; - tv.tv_sec = ms / 1000; - tv.tv_usec = (ms % 1000) * 1000; - - was_error = select(0, NULL, NULL, NULL, &tv); -#endif /* HAVE_NANOSLEEP */ } while (was_error && (errno == EINTR)); } diff --git a/src/SDL-mobile/src/video/SDL_RLEaccel.c b/src/SDL-mobile/src/video/SDL_RLEaccel.c index 8554a5652..b132a403a 100644 --- a/src/SDL-mobile/src/video/SDL_RLEaccel.c +++ b/src/SDL-mobile/src/video/SDL_RLEaccel.c @@ -20,1557 +20,4 @@ */ #include "SDL_config.h" -/* - * RLE encoding for software colorkey and alpha-channel acceleration - * - * Original version by Sam Lantinga - * - * Mattias Engdegård (Yorick): Rewrite. New encoding format, encoder and - * decoder. Added per-surface alpha blitter. Added per-pixel alpha - * format, encoder and blitter. - * - * Many thanks to Xark and johns for hints, benchmarks and useful comments - * leading to this code. - * - * Welcome to Macro Mayhem. - */ - -/* - * The encoding translates the image data to a stream of segments of the form - * - * - * - * where is the number of transparent pixels to skip, - * is the number of opaque pixels to blit, - * and are the pixels themselves. - * - * This basic structure is used both for colorkeyed surfaces, used for simple - * binary transparency and for per-surface alpha blending, and for surfaces - * with per-pixel alpha. The details differ, however: - * - * Encoding of colorkeyed surfaces: - * - * Encoded pixels always have the same format as the target surface. - * and are unsigned 8 bit integers, except for 32 bit depth - * where they are 16 bit. This makes the pixel data aligned at all times. - * Segments never wrap around from one scan line to the next. - * - * The end of the sequence is marked by a zero , pair at the * - * beginning of a line. - * - * Encoding of surfaces with per-pixel alpha: - * - * The sequence begins with a struct RLEDestFormat describing the target - * pixel format, to provide reliable un-encoding. - * - * Each scan line is encoded twice: First all completely opaque pixels, - * encoded in the target format as described above, and then all - * partially transparent (translucent) pixels (where 1 <= alpha <= 254), - * in the following 32-bit format: - * - * For 32-bit targets, each pixel has the target RGB format but with - * the alpha value occupying the highest 8 bits. The and - * counts are 16 bit. - * - * For 16-bit targets, each pixel has the target RGB format, but with - * the middle component (usually green) shifted 16 steps to the left, - * and the hole filled with the 5 most significant bits of the alpha value. - * i.e. if the target has the format rrrrrggggggbbbbb, - * the encoded pixel will be 00000gggggg00000rrrrr0aaaaabbbbb. - * The and counts are 8 bit for the opaque lines, 16 bit - * for the translucent lines. Two padding bytes may be inserted - * before each translucent line to keep them 32-bit aligned. - * - * The end of the sequence is marked by a zero , pair at the - * beginning of an opaque line. - */ - -#include "SDL_video.h" -#include "SDL_sysvideo.h" -#include "SDL_blit.h" -#include "SDL_RLEaccel_c.h" - -#ifndef MAX -#define MAX(a, b) ((a) > (b) ? (a) : (b)) -#endif -#ifndef MIN -#define MIN(a, b) ((a) < (b) ? (a) : (b)) -#endif - -#define PIXEL_COPY(to, from, len, bpp) \ -do { \ - if(bpp == 4) { \ - SDL_memcpy4(to, from, (size_t)(len)); \ - } else { \ - SDL_memcpy(to, from, (size_t)(len) * (bpp)); \ - } \ -} while(0) - -/* - * Various colorkey blit methods, for opaque and per-surface alpha - */ - -#define OPAQUE_BLIT(to, from, length, bpp, alpha) \ - PIXEL_COPY(to, from, length, bpp) - -/* - * For 32bpp pixels on the form 0x00rrggbb: - * If we treat the middle component separately, we can process the two - * remaining in parallel. This is safe to do because of the gap to the left - * of each component, so the bits from the multiplication don't collide. - * This can be used for any RGB permutation of course. - */ -#define ALPHA_BLIT32_888(to, from, length, bpp, alpha) \ - do { \ - int i; \ - Uint32 *src = (Uint32 *)(from); \ - Uint32 *dst = (Uint32 *)(to); \ - for(i = 0; i < (int)(length); i++) { \ - Uint32 s = *src++; \ - Uint32 d = *dst; \ - Uint32 s1 = s & 0xff00ff; \ - Uint32 d1 = d & 0xff00ff; \ - d1 = (d1 + ((s1 - d1) * alpha >> 8)) & 0xff00ff; \ - s &= 0xff00; \ - d &= 0xff00; \ - d = (d + ((s - d) * alpha >> 8)) & 0xff00; \ - *dst++ = d1 | d; \ - } \ - } while(0) - -/* - * For 16bpp pixels we can go a step further: put the middle component - * in the high 16 bits of a 32 bit word, and process all three RGB - * components at the same time. Since the smallest gap is here just - * 5 bits, we have to scale alpha down to 5 bits as well. - */ -#define ALPHA_BLIT16_565(to, from, length, bpp, alpha) \ - do { \ - int i; \ - Uint16 *src = (Uint16 *)(from); \ - Uint16 *dst = (Uint16 *)(to); \ - Uint32 ALPHA = alpha >> 3; \ - for(i = 0; i < (int)(length); i++) { \ - Uint32 s = *src++; \ - Uint32 d = *dst; \ - s = (s | s << 16) & 0x07e0f81f; \ - d = (d | d << 16) & 0x07e0f81f; \ - d += (s - d) * ALPHA >> 5; \ - d &= 0x07e0f81f; \ - *dst++ = (Uint16)(d | d >> 16); \ - } \ - } while(0) - -#define ALPHA_BLIT16_555(to, from, length, bpp, alpha) \ - do { \ - int i; \ - Uint16 *src = (Uint16 *)(from); \ - Uint16 *dst = (Uint16 *)(to); \ - Uint32 ALPHA = alpha >> 3; \ - for(i = 0; i < (int)(length); i++) { \ - Uint32 s = *src++; \ - Uint32 d = *dst; \ - s = (s | s << 16) & 0x03e07c1f; \ - d = (d | d << 16) & 0x03e07c1f; \ - d += (s - d) * ALPHA >> 5; \ - d &= 0x03e07c1f; \ - *dst++ = (Uint16)(d | d >> 16); \ - } \ - } while(0) - -/* - * The general slow catch-all function, for remaining depths and formats - */ -#define ALPHA_BLIT_ANY(to, from, length, bpp, alpha) \ - do { \ - int i; \ - Uint8 *src = from; \ - Uint8 *dst = to; \ - for(i = 0; i < (int)(length); i++) { \ - Uint32 s, d; \ - unsigned rs, gs, bs, rd, gd, bd; \ - switch(bpp) { \ - case 2: \ - s = *(Uint16 *)src; \ - d = *(Uint16 *)dst; \ - break; \ - case 3: \ - if(SDL_BYTEORDER == SDL_BIG_ENDIAN) { \ - s = (src[0] << 16) | (src[1] << 8) | src[2]; \ - d = (dst[0] << 16) | (dst[1] << 8) | dst[2]; \ - } else { \ - s = (src[2] << 16) | (src[1] << 8) | src[0]; \ - d = (dst[2] << 16) | (dst[1] << 8) | dst[0]; \ - } \ - break; \ - case 4: \ - s = *(Uint32 *)src; \ - d = *(Uint32 *)dst; \ - break; \ - } \ - RGB_FROM_PIXEL(s, fmt, rs, gs, bs); \ - RGB_FROM_PIXEL(d, fmt, rd, gd, bd); \ - rd += (rs - rd) * alpha >> 8; \ - gd += (gs - gd) * alpha >> 8; \ - bd += (bs - bd) * alpha >> 8; \ - PIXEL_FROM_RGB(d, fmt, rd, gd, bd); \ - switch(bpp) { \ - case 2: \ - *(Uint16 *)dst = (Uint16)d; \ - break; \ - case 3: \ - if(SDL_BYTEORDER == SDL_BIG_ENDIAN) { \ - dst[0] = (Uint8)(d >> 16); \ - dst[1] = (Uint8)(d >> 8); \ - dst[2] = (Uint8)(d); \ - } else { \ - dst[0] = (Uint8)d; \ - dst[1] = (Uint8)(d >> 8); \ - dst[2] = (Uint8)(d >> 16); \ - } \ - break; \ - case 4: \ - *(Uint32 *)dst = d; \ - break; \ - } \ - src += bpp; \ - dst += bpp; \ - } \ - } while(0) - -/* - * Special case: 50% alpha (alpha=128) - * This is treated specially because it can be optimized very well, and - * since it is good for many cases of semi-translucency. - * The theory is to do all three components at the same time: - * First zero the lowest bit of each component, which gives us room to - * add them. Then shift right and add the sum of the lowest bits. - */ -#define ALPHA_BLIT32_888_50(to, from, length, bpp, alpha) \ - do { \ - int i; \ - Uint32 *src = (Uint32 *)(from); \ - Uint32 *dst = (Uint32 *)(to); \ - for(i = 0; i < (int)(length); i++) { \ - Uint32 s = *src++; \ - Uint32 d = *dst; \ - *dst++ = (((s & 0x00fefefe) + (d & 0x00fefefe)) >> 1) \ - + (s & d & 0x00010101); \ - } \ - } while(0) - -/* - * For 16bpp, we can actually blend two pixels in parallel, if we take - * care to shift before we add, not after. - */ - -/* helper: blend a single 16 bit pixel at 50% */ -#define BLEND16_50(dst, src, mask) \ - do { \ - Uint32 s = *src++; \ - Uint32 d = *dst; \ - *dst++ = (Uint16)((((s & mask) + (d & mask)) >> 1) + \ - (s & d & (~mask & 0xffff))); \ - } while(0) - -/* basic 16bpp blender. mask is the pixels to keep when adding. */ -#define ALPHA_BLIT16_50(to, from, length, bpp, alpha, mask) \ - do { \ - unsigned n = (length); \ - Uint16 *src = (Uint16 *)(from); \ - Uint16 *dst = (Uint16 *)(to); \ - if(((uintptr_t)src ^ (uintptr_t)dst) & 3) { \ - /* source and destination not in phase, blit one by one */ \ - while(n--) \ - BLEND16_50(dst, src, mask); \ - } else { \ - if((uintptr_t)src & 3) { \ - /* first odd pixel */ \ - BLEND16_50(dst, src, mask); \ - n--; \ - } \ - for(; n > 1; n -= 2) { \ - Uint32 s = *(Uint32 *)src; \ - Uint32 d = *(Uint32 *)dst; \ - *(Uint32 *)dst = ((s & (mask | mask << 16)) >> 1) \ - + ((d & (mask | mask << 16)) >> 1) \ - + (s & d & (~(mask | mask << 16))); \ - src += 2; \ - dst += 2; \ - } \ - if(n) \ - BLEND16_50(dst, src, mask); /* last odd pixel */ \ - } \ - } while(0) - -#define ALPHA_BLIT16_565_50(to, from, length, bpp, alpha) \ - ALPHA_BLIT16_50(to, from, length, bpp, alpha, 0xf7de) - -#define ALPHA_BLIT16_555_50(to, from, length, bpp, alpha) \ - ALPHA_BLIT16_50(to, from, length, bpp, alpha, 0xfbde) - -#define CHOOSE_BLIT(blitter, alpha, fmt) \ - do { \ - if(alpha == 255) { \ - switch(fmt->BytesPerPixel) { \ - case 1: blitter(1, Uint8, OPAQUE_BLIT); break; \ - case 2: blitter(2, Uint8, OPAQUE_BLIT); break; \ - case 3: blitter(3, Uint8, OPAQUE_BLIT); break; \ - case 4: blitter(4, Uint16, OPAQUE_BLIT); break; \ - } \ - } else { \ - switch(fmt->BytesPerPixel) { \ - case 1: \ - /* No 8bpp alpha blitting */ \ - break; \ - \ - case 2: \ - switch(fmt->Rmask | fmt->Gmask | fmt->Bmask) { \ - case 0xffff: \ - if(fmt->Gmask == 0x07e0 \ - || fmt->Rmask == 0x07e0 \ - || fmt->Bmask == 0x07e0) { \ - if(alpha == 128) \ - blitter(2, Uint8, ALPHA_BLIT16_565_50); \ - else { \ - blitter(2, Uint8, ALPHA_BLIT16_565); \ - } \ - } else \ - goto general16; \ - break; \ - \ - case 0x7fff: \ - if(fmt->Gmask == 0x03e0 \ - || fmt->Rmask == 0x03e0 \ - || fmt->Bmask == 0x03e0) { \ - if(alpha == 128) \ - blitter(2, Uint8, ALPHA_BLIT16_555_50); \ - else { \ - blitter(2, Uint8, ALPHA_BLIT16_555); \ - } \ - break; \ - } \ - /* fallthrough */ \ - \ - default: \ - general16: \ - blitter(2, Uint8, ALPHA_BLIT_ANY); \ - } \ - break; \ - \ - case 3: \ - blitter(3, Uint8, ALPHA_BLIT_ANY); \ - break; \ - \ - case 4: \ - if((fmt->Rmask | fmt->Gmask | fmt->Bmask) == 0x00ffffff \ - && (fmt->Gmask == 0xff00 || fmt->Rmask == 0xff00 \ - || fmt->Bmask == 0xff00)) { \ - if(alpha == 128) \ - blitter(4, Uint16, ALPHA_BLIT32_888_50); \ - else \ - blitter(4, Uint16, ALPHA_BLIT32_888); \ - } else \ - blitter(4, Uint16, ALPHA_BLIT_ANY); \ - break; \ - } \ - } \ - } while(0) - -/* - * This takes care of the case when the surface is clipped on the left and/or - * right. Top clipping has already been taken care of. - */ -static void -RLEClipBlit(int w, Uint8 * srcbuf, SDL_Surface * dst, - Uint8 * dstbuf, SDL_Rect * srcrect, unsigned alpha) -{ - SDL_PixelFormat *fmt = dst->format; - -#define RLECLIPBLIT(bpp, Type, do_blit) \ - do { \ - int linecount = srcrect->h; \ - int ofs = 0; \ - int left = srcrect->x; \ - int right = left + srcrect->w; \ - dstbuf -= left * bpp; \ - for(;;) { \ - int run; \ - ofs += *(Type *)srcbuf; \ - run = ((Type *)srcbuf)[1]; \ - srcbuf += 2 * sizeof(Type); \ - if(run) { \ - /* clip to left and right borders */ \ - if(ofs < right) { \ - int start = 0; \ - int len = run; \ - int startcol; \ - if(left - ofs > 0) { \ - start = left - ofs; \ - len -= start; \ - if(len <= 0) \ - goto nocopy ## bpp ## do_blit; \ - } \ - startcol = ofs + start; \ - if(len > right - startcol) \ - len = right - startcol; \ - do_blit(dstbuf + startcol * bpp, srcbuf + start * bpp, \ - len, bpp, alpha); \ - } \ - nocopy ## bpp ## do_blit: \ - srcbuf += run * bpp; \ - ofs += run; \ - } else if(!ofs) \ - break; \ - if(ofs == w) { \ - ofs = 0; \ - dstbuf += dst->pitch; \ - if(!--linecount) \ - break; \ - } \ - } \ - } while(0) - - CHOOSE_BLIT(RLECLIPBLIT, alpha, fmt); - -#undef RLECLIPBLIT - -} - - -/* blit a colorkeyed RLE surface */ -int -SDL_RLEBlit(SDL_Surface * src, SDL_Rect * srcrect, - SDL_Surface * dst, SDL_Rect * dstrect) -{ - Uint8 *dstbuf; - Uint8 *srcbuf; - int x, y; - int w = src->w; - unsigned alpha; - - /* Lock the destination if necessary */ - if (SDL_MUSTLOCK(dst)) { - if (SDL_LockSurface(dst) < 0) { - return (-1); - } - } - - /* Set up the source and destination pointers */ - x = dstrect->x; - y = dstrect->y; - dstbuf = (Uint8 *) dst->pixels - + y * dst->pitch + x * src->format->BytesPerPixel; - srcbuf = (Uint8 *) src->map->data; - - { - /* skip lines at the top if neccessary */ - int vskip = srcrect->y; - int ofs = 0; - if (vskip) { - -#define RLESKIP(bpp, Type) \ - for(;;) { \ - int run; \ - ofs += *(Type *)srcbuf; \ - run = ((Type *)srcbuf)[1]; \ - srcbuf += sizeof(Type) * 2; \ - if(run) { \ - srcbuf += run * bpp; \ - ofs += run; \ - } else if(!ofs) \ - goto done; \ - if(ofs == w) { \ - ofs = 0; \ - if(!--vskip) \ - break; \ - } \ - } - - switch (src->format->BytesPerPixel) { - case 1: - RLESKIP(1, Uint8); - break; - case 2: - RLESKIP(2, Uint8); - break; - case 3: - RLESKIP(3, Uint8); - break; - case 4: - RLESKIP(4, Uint16); - break; - } - -#undef RLESKIP - - } - } - - alpha = src->map->info.a; - /* if left or right edge clipping needed, call clip blit */ - if (srcrect->x || srcrect->w != src->w) { - RLEClipBlit(w, srcbuf, dst, dstbuf, srcrect, alpha); - } else { - SDL_PixelFormat *fmt = src->format; - -#define RLEBLIT(bpp, Type, do_blit) \ - do { \ - int linecount = srcrect->h; \ - int ofs = 0; \ - for(;;) { \ - unsigned run; \ - ofs += *(Type *)srcbuf; \ - run = ((Type *)srcbuf)[1]; \ - srcbuf += 2 * sizeof(Type); \ - if(run) { \ - do_blit(dstbuf + ofs * bpp, srcbuf, run, bpp, alpha); \ - srcbuf += run * bpp; \ - ofs += run; \ - } else if(!ofs) \ - break; \ - if(ofs == w) { \ - ofs = 0; \ - dstbuf += dst->pitch; \ - if(!--linecount) \ - break; \ - } \ - } \ - } while(0) - - CHOOSE_BLIT(RLEBLIT, alpha, fmt); - -#undef RLEBLIT - } - - done: - /* Unlock the destination if necessary */ - if (SDL_MUSTLOCK(dst)) { - SDL_UnlockSurface(dst); - } - return (0); -} - -#undef OPAQUE_BLIT - -/* - * Per-pixel blitting macros for translucent pixels: - * These use the same techniques as the per-surface blitting macros - */ - -/* - * For 32bpp pixels, we have made sure the alpha is stored in the top - * 8 bits, so proceed as usual - */ -#define BLIT_TRANSL_888(src, dst) \ - do { \ - Uint32 s = src; \ - Uint32 d = dst; \ - unsigned alpha = s >> 24; \ - Uint32 s1 = s & 0xff00ff; \ - Uint32 d1 = d & 0xff00ff; \ - d1 = (d1 + ((s1 - d1) * alpha >> 8)) & 0xff00ff; \ - s &= 0xff00; \ - d &= 0xff00; \ - d = (d + ((s - d) * alpha >> 8)) & 0xff00; \ - dst = d1 | d | 0xff000000; \ - } while(0) - -/* - * For 16bpp pixels, we have stored the 5 most significant alpha bits in - * bits 5-10. As before, we can process all 3 RGB components at the same time. - */ -#define BLIT_TRANSL_565(src, dst) \ - do { \ - Uint32 s = src; \ - Uint32 d = dst; \ - unsigned alpha = (s & 0x3e0) >> 5; \ - s &= 0x07e0f81f; \ - d = (d | d << 16) & 0x07e0f81f; \ - d += (s - d) * alpha >> 5; \ - d &= 0x07e0f81f; \ - dst = (Uint16)(d | d >> 16); \ - } while(0) - -#define BLIT_TRANSL_555(src, dst) \ - do { \ - Uint32 s = src; \ - Uint32 d = dst; \ - unsigned alpha = (s & 0x3e0) >> 5; \ - s &= 0x03e07c1f; \ - d = (d | d << 16) & 0x03e07c1f; \ - d += (s - d) * alpha >> 5; \ - d &= 0x03e07c1f; \ - dst = (Uint16)(d | d >> 16); \ - } while(0) - -/* used to save the destination format in the encoding. Designed to be - macro-compatible with SDL_PixelFormat but without the unneeded fields */ -typedef struct -{ - Uint8 BytesPerPixel; - Uint8 padding[3]; - Uint32 Rmask; - Uint32 Gmask; - Uint32 Bmask; - Uint32 Amask; - Uint8 Rloss; - Uint8 Gloss; - Uint8 Bloss; - Uint8 Aloss; - Uint8 Rshift; - Uint8 Gshift; - Uint8 Bshift; - Uint8 Ashift; -} RLEDestFormat; - -/* blit a pixel-alpha RLE surface clipped at the right and/or left edges */ -static void -RLEAlphaClipBlit(int w, Uint8 * srcbuf, SDL_Surface * dst, - Uint8 * dstbuf, SDL_Rect * srcrect) -{ - SDL_PixelFormat *df = dst->format; - /* - * clipped blitter: Ptype is the destination pixel type, - * Ctype the translucent count type, and do_blend the macro - * to blend one pixel. - */ -#define RLEALPHACLIPBLIT(Ptype, Ctype, do_blend) \ - do { \ - int linecount = srcrect->h; \ - int left = srcrect->x; \ - int right = left + srcrect->w; \ - dstbuf -= left * sizeof(Ptype); \ - do { \ - int ofs = 0; \ - /* blit opaque pixels on one line */ \ - do { \ - unsigned run; \ - ofs += ((Ctype *)srcbuf)[0]; \ - run = ((Ctype *)srcbuf)[1]; \ - srcbuf += 2 * sizeof(Ctype); \ - if(run) { \ - /* clip to left and right borders */ \ - int cofs = ofs; \ - int crun = run; \ - if(left - cofs > 0) { \ - crun -= left - cofs; \ - cofs = left; \ - } \ - if(crun > right - cofs) \ - crun = right - cofs; \ - if(crun > 0) \ - PIXEL_COPY(dstbuf + cofs * sizeof(Ptype), \ - srcbuf + (cofs - ofs) * sizeof(Ptype), \ - (unsigned)crun, sizeof(Ptype)); \ - srcbuf += run * sizeof(Ptype); \ - ofs += run; \ - } else if(!ofs) \ - return; \ - } while(ofs < w); \ - /* skip padding if necessary */ \ - if(sizeof(Ptype) == 2) \ - srcbuf += (uintptr_t)srcbuf & 2; \ - /* blit translucent pixels on the same line */ \ - ofs = 0; \ - do { \ - unsigned run; \ - ofs += ((Uint16 *)srcbuf)[0]; \ - run = ((Uint16 *)srcbuf)[1]; \ - srcbuf += 4; \ - if(run) { \ - /* clip to left and right borders */ \ - int cofs = ofs; \ - int crun = run; \ - if(left - cofs > 0) { \ - crun -= left - cofs; \ - cofs = left; \ - } \ - if(crun > right - cofs) \ - crun = right - cofs; \ - if(crun > 0) { \ - Ptype *dst = (Ptype *)dstbuf + cofs; \ - Uint32 *src = (Uint32 *)srcbuf + (cofs - ofs); \ - int i; \ - for(i = 0; i < crun; i++) \ - do_blend(src[i], dst[i]); \ - } \ - srcbuf += run * 4; \ - ofs += run; \ - } \ - } while(ofs < w); \ - dstbuf += dst->pitch; \ - } while(--linecount); \ - } while(0) - - switch (df->BytesPerPixel) { - case 2: - if (df->Gmask == 0x07e0 || df->Rmask == 0x07e0 || df->Bmask == 0x07e0) - RLEALPHACLIPBLIT(Uint16, Uint8, BLIT_TRANSL_565); - else - RLEALPHACLIPBLIT(Uint16, Uint8, BLIT_TRANSL_555); - break; - case 4: - RLEALPHACLIPBLIT(Uint32, Uint16, BLIT_TRANSL_888); - break; - } -} - -/* blit a pixel-alpha RLE surface */ -int -SDL_RLEAlphaBlit(SDL_Surface * src, SDL_Rect * srcrect, - SDL_Surface * dst, SDL_Rect * dstrect) -{ - int x, y; - int w = src->w; - Uint8 *srcbuf, *dstbuf; - SDL_PixelFormat *df = dst->format; - - /* Lock the destination if necessary */ - if (SDL_MUSTLOCK(dst)) { - if (SDL_LockSurface(dst) < 0) { - return -1; - } - } - - x = dstrect->x; - y = dstrect->y; - dstbuf = (Uint8 *) dst->pixels + y * dst->pitch + x * df->BytesPerPixel; - srcbuf = (Uint8 *) src->map->data + sizeof(RLEDestFormat); - - { - /* skip lines at the top if necessary */ - int vskip = srcrect->y; - if (vskip) { - int ofs; - if (df->BytesPerPixel == 2) { - /* the 16/32 interleaved format */ - do { - /* skip opaque line */ - ofs = 0; - do { - int run; - ofs += srcbuf[0]; - run = srcbuf[1]; - srcbuf += 2; - if (run) { - srcbuf += 2 * run; - ofs += run; - } else if (!ofs) - goto done; - } while (ofs < w); - - /* skip padding */ - srcbuf += (uintptr_t) srcbuf & 2; - - /* skip translucent line */ - ofs = 0; - do { - int run; - ofs += ((Uint16 *) srcbuf)[0]; - run = ((Uint16 *) srcbuf)[1]; - srcbuf += 4 * (run + 1); - ofs += run; - } while (ofs < w); - } while (--vskip); - } else { - /* the 32/32 interleaved format */ - vskip <<= 1; /* opaque and translucent have same format */ - do { - ofs = 0; - do { - int run; - ofs += ((Uint16 *) srcbuf)[0]; - run = ((Uint16 *) srcbuf)[1]; - srcbuf += 4; - if (run) { - srcbuf += 4 * run; - ofs += run; - } else if (!ofs) - goto done; - } while (ofs < w); - } while (--vskip); - } - } - } - - /* if left or right edge clipping needed, call clip blit */ - if (srcrect->x || srcrect->w != src->w) { - RLEAlphaClipBlit(w, srcbuf, dst, dstbuf, srcrect); - } else { - - /* - * non-clipped blitter. Ptype is the destination pixel type, - * Ctype the translucent count type, and do_blend the - * macro to blend one pixel. - */ -#define RLEALPHABLIT(Ptype, Ctype, do_blend) \ - do { \ - int linecount = srcrect->h; \ - do { \ - int ofs = 0; \ - /* blit opaque pixels on one line */ \ - do { \ - unsigned run; \ - ofs += ((Ctype *)srcbuf)[0]; \ - run = ((Ctype *)srcbuf)[1]; \ - srcbuf += 2 * sizeof(Ctype); \ - if(run) { \ - PIXEL_COPY(dstbuf + ofs * sizeof(Ptype), srcbuf, \ - run, sizeof(Ptype)); \ - srcbuf += run * sizeof(Ptype); \ - ofs += run; \ - } else if(!ofs) \ - goto done; \ - } while(ofs < w); \ - /* skip padding if necessary */ \ - if(sizeof(Ptype) == 2) \ - srcbuf += (uintptr_t)srcbuf & 2; \ - /* blit translucent pixels on the same line */ \ - ofs = 0; \ - do { \ - unsigned run; \ - ofs += ((Uint16 *)srcbuf)[0]; \ - run = ((Uint16 *)srcbuf)[1]; \ - srcbuf += 4; \ - if(run) { \ - Ptype *dst = (Ptype *)dstbuf + ofs; \ - unsigned i; \ - for(i = 0; i < run; i++) { \ - Uint32 src = *(Uint32 *)srcbuf; \ - do_blend(src, *dst); \ - srcbuf += 4; \ - dst++; \ - } \ - ofs += run; \ - } \ - } while(ofs < w); \ - dstbuf += dst->pitch; \ - } while(--linecount); \ - } while(0) - - switch (df->BytesPerPixel) { - case 2: - if (df->Gmask == 0x07e0 || df->Rmask == 0x07e0 - || df->Bmask == 0x07e0) - RLEALPHABLIT(Uint16, Uint8, BLIT_TRANSL_565); - else - RLEALPHABLIT(Uint16, Uint8, BLIT_TRANSL_555); - break; - case 4: - RLEALPHABLIT(Uint32, Uint16, BLIT_TRANSL_888); - break; - } - } - - done: - /* Unlock the destination if necessary */ - if (SDL_MUSTLOCK(dst)) { - SDL_UnlockSurface(dst); - } - return 0; -} - -/* - * Auxiliary functions: - * The encoding functions take 32bpp rgb + a, and - * return the number of bytes copied to the destination. - * The decoding functions copy to 32bpp rgb + a, and - * return the number of bytes copied from the source. - * These are only used in the encoder and un-RLE code and are therefore not - * highly optimised. - */ - -/* encode 32bpp rgb + a into 16bpp rgb, losing alpha */ -static int -copy_opaque_16(void *dst, Uint32 * src, int n, - SDL_PixelFormat * sfmt, SDL_PixelFormat * dfmt) -{ - int i; - Uint16 *d = dst; - for (i = 0; i < n; i++) { - unsigned r, g, b; - RGB_FROM_PIXEL(*src, sfmt, r, g, b); - PIXEL_FROM_RGB(*d, dfmt, r, g, b); - src++; - d++; - } - return n * 2; -} - -/* decode opaque pixels from 16bpp to 32bpp rgb + a */ -static int -uncopy_opaque_16(Uint32 * dst, void *src, int n, - RLEDestFormat * sfmt, SDL_PixelFormat * dfmt) -{ - int i; - Uint16 *s = src; - unsigned alpha = dfmt->Amask ? 255 : 0; - for (i = 0; i < n; i++) { - unsigned r, g, b; - RGB_FROM_PIXEL(*s, sfmt, r, g, b); - PIXEL_FROM_RGBA(*dst, dfmt, r, g, b, alpha); - s++; - dst++; - } - return n * 2; -} - - - -/* encode 32bpp rgb + a into 32bpp G0RAB format for blitting into 565 */ -static int -copy_transl_565(void *dst, Uint32 * src, int n, - SDL_PixelFormat * sfmt, SDL_PixelFormat * dfmt) -{ - int i; - Uint32 *d = dst; - for (i = 0; i < n; i++) { - unsigned r, g, b, a; - Uint16 pix; - RGBA_FROM_8888(*src, sfmt, r, g, b, a); - PIXEL_FROM_RGB(pix, dfmt, r, g, b); - *d = ((pix & 0x7e0) << 16) | (pix & 0xf81f) | ((a << 2) & 0x7e0); - src++; - d++; - } - return n * 4; -} - -/* encode 32bpp rgb + a into 32bpp G0RAB format for blitting into 555 */ -static int -copy_transl_555(void *dst, Uint32 * src, int n, - SDL_PixelFormat * sfmt, SDL_PixelFormat * dfmt) -{ - int i; - Uint32 *d = dst; - for (i = 0; i < n; i++) { - unsigned r, g, b, a; - Uint16 pix; - RGBA_FROM_8888(*src, sfmt, r, g, b, a); - PIXEL_FROM_RGB(pix, dfmt, r, g, b); - *d = ((pix & 0x3e0) << 16) | (pix & 0xfc1f) | ((a << 2) & 0x3e0); - src++; - d++; - } - return n * 4; -} - -/* decode translucent pixels from 32bpp GORAB to 32bpp rgb + a */ -static int -uncopy_transl_16(Uint32 * dst, void *src, int n, - RLEDestFormat * sfmt, SDL_PixelFormat * dfmt) -{ - int i; - Uint32 *s = src; - for (i = 0; i < n; i++) { - unsigned r, g, b, a; - Uint32 pix = *s++; - a = (pix & 0x3e0) >> 2; - pix = (pix & ~0x3e0) | pix >> 16; - RGB_FROM_PIXEL(pix, sfmt, r, g, b); - PIXEL_FROM_RGBA(*dst, dfmt, r, g, b, a); - dst++; - } - return n * 4; -} - -/* encode 32bpp rgba into 32bpp rgba, keeping alpha (dual purpose) */ -static int -copy_32(void *dst, Uint32 * src, int n, - SDL_PixelFormat * sfmt, SDL_PixelFormat * dfmt) -{ - int i; - Uint32 *d = dst; - for (i = 0; i < n; i++) { - unsigned r, g, b, a; - RGBA_FROM_8888(*src, sfmt, r, g, b, a); - PIXEL_FROM_RGBA(*d, dfmt, r, g, b, a); - d++; - src++; - } - return n * 4; -} - -/* decode 32bpp rgba into 32bpp rgba, keeping alpha (dual purpose) */ -static int -uncopy_32(Uint32 * dst, void *src, int n, - RLEDestFormat * sfmt, SDL_PixelFormat * dfmt) -{ - int i; - Uint32 *s = src; - for (i = 0; i < n; i++) { - unsigned r, g, b, a; - Uint32 pixel = *s++; - RGB_FROM_PIXEL(pixel, sfmt, r, g, b); - a = pixel >> 24; - PIXEL_FROM_RGBA(*dst, dfmt, r, g, b, a); - dst++; - } - return n * 4; -} - -#define ISOPAQUE(pixel, fmt) ((((pixel) & fmt->Amask) >> fmt->Ashift) == 255) - -#define ISTRANSL(pixel, fmt) \ - ((unsigned)((((pixel) & fmt->Amask) >> fmt->Ashift) - 1U) < 254U) - -/* convert surface to be quickly alpha-blittable onto dest, if possible */ -static int -RLEAlphaSurface(SDL_Surface * surface) -{ - SDL_Surface *dest; - SDL_PixelFormat *df; - int maxsize = 0; - int max_opaque_run; - int max_transl_run = 65535; - unsigned masksum; - Uint8 *rlebuf, *dst; - int (*copy_opaque) (void *, Uint32 *, int, - SDL_PixelFormat *, SDL_PixelFormat *); - int (*copy_transl) (void *, Uint32 *, int, - SDL_PixelFormat *, SDL_PixelFormat *); - - dest = surface->map->dst; - if (!dest) - return -1; - df = dest->format; - if (surface->format->BitsPerPixel != 32) - return -1; /* only 32bpp source supported */ - - /* find out whether the destination is one we support, - and determine the max size of the encoded result */ - masksum = df->Rmask | df->Gmask | df->Bmask; - switch (df->BytesPerPixel) { - case 2: - /* 16bpp: only support 565 and 555 formats */ - switch (masksum) { - case 0xffff: - if (df->Gmask == 0x07e0 - || df->Rmask == 0x07e0 || df->Bmask == 0x07e0) { - copy_opaque = copy_opaque_16; - copy_transl = copy_transl_565; - } else - return -1; - break; - case 0x7fff: - if (df->Gmask == 0x03e0 - || df->Rmask == 0x03e0 || df->Bmask == 0x03e0) { - copy_opaque = copy_opaque_16; - copy_transl = copy_transl_555; - } else - return -1; - break; - default: - return -1; - } - max_opaque_run = 255; /* runs stored as bytes */ - - /* worst case is alternating opaque and translucent pixels, - with room for alignment padding between lines */ - maxsize = surface->h * (2 + (4 + 2) * (surface->w + 1)) + 2; - break; - case 4: - if (masksum != 0x00ffffff) - return -1; /* requires unused high byte */ - copy_opaque = copy_32; - copy_transl = copy_32; - max_opaque_run = 255; /* runs stored as short ints */ - - /* worst case is alternating opaque and translucent pixels */ - maxsize = surface->h * 2 * 4 * (surface->w + 1) + 4; - break; - default: - return -1; /* anything else unsupported right now */ - } - - maxsize += sizeof(RLEDestFormat); - rlebuf = (Uint8 *) SDL_malloc(maxsize); - if (!rlebuf) { - SDL_OutOfMemory(); - return -1; - } - { - /* save the destination format so we can undo the encoding later */ - RLEDestFormat *r = (RLEDestFormat *) rlebuf; - r->BytesPerPixel = df->BytesPerPixel; - r->Rmask = df->Rmask; - r->Gmask = df->Gmask; - r->Bmask = df->Bmask; - r->Amask = df->Amask; - r->Rloss = df->Rloss; - r->Gloss = df->Gloss; - r->Bloss = df->Bloss; - r->Aloss = df->Aloss; - r->Rshift = df->Rshift; - r->Gshift = df->Gshift; - r->Bshift = df->Bshift; - r->Ashift = df->Ashift; - } - dst = rlebuf + sizeof(RLEDestFormat); - - /* Do the actual encoding */ - { - int x, y; - int h = surface->h, w = surface->w; - SDL_PixelFormat *sf = surface->format; - Uint32 *src = (Uint32 *) surface->pixels; - Uint8 *lastline = dst; /* end of last non-blank line */ - - /* opaque counts are 8 or 16 bits, depending on target depth */ -#define ADD_OPAQUE_COUNTS(n, m) \ - if(df->BytesPerPixel == 4) { \ - ((Uint16 *)dst)[0] = n; \ - ((Uint16 *)dst)[1] = m; \ - dst += 4; \ - } else { \ - dst[0] = n; \ - dst[1] = m; \ - dst += 2; \ - } - - /* translucent counts are always 16 bit */ -#define ADD_TRANSL_COUNTS(n, m) \ - (((Uint16 *)dst)[0] = n, ((Uint16 *)dst)[1] = m, dst += 4) - - for (y = 0; y < h; y++) { - int runstart, skipstart; - int blankline = 0; - /* First encode all opaque pixels of a scan line */ - x = 0; - do { - int run, skip, len; - skipstart = x; - while (x < w && !ISOPAQUE(src[x], sf)) - x++; - runstart = x; - while (x < w && ISOPAQUE(src[x], sf)) - x++; - skip = runstart - skipstart; - if (skip == w) - blankline = 1; - run = x - runstart; - while (skip > max_opaque_run) { - ADD_OPAQUE_COUNTS(max_opaque_run, 0); - skip -= max_opaque_run; - } - len = MIN(run, max_opaque_run); - ADD_OPAQUE_COUNTS(skip, len); - dst += copy_opaque(dst, src + runstart, len, sf, df); - runstart += len; - run -= len; - while (run) { - len = MIN(run, max_opaque_run); - ADD_OPAQUE_COUNTS(0, len); - dst += copy_opaque(dst, src + runstart, len, sf, df); - runstart += len; - run -= len; - } - } while (x < w); - - /* Make sure the next output address is 32-bit aligned */ - dst += (uintptr_t) dst & 2; - - /* Next, encode all translucent pixels of the same scan line */ - x = 0; - do { - int run, skip, len; - skipstart = x; - while (x < w && !ISTRANSL(src[x], sf)) - x++; - runstart = x; - while (x < w && ISTRANSL(src[x], sf)) - x++; - skip = runstart - skipstart; - blankline &= (skip == w); - run = x - runstart; - while (skip > max_transl_run) { - ADD_TRANSL_COUNTS(max_transl_run, 0); - skip -= max_transl_run; - } - len = MIN(run, max_transl_run); - ADD_TRANSL_COUNTS(skip, len); - dst += copy_transl(dst, src + runstart, len, sf, df); - runstart += len; - run -= len; - while (run) { - len = MIN(run, max_transl_run); - ADD_TRANSL_COUNTS(0, len); - dst += copy_transl(dst, src + runstart, len, sf, df); - runstart += len; - run -= len; - } - if (!blankline) - lastline = dst; - } while (x < w); - - src += surface->pitch >> 2; - } - dst = lastline; /* back up past trailing blank lines */ - ADD_OPAQUE_COUNTS(0, 0); - } - -#undef ADD_OPAQUE_COUNTS -#undef ADD_TRANSL_COUNTS - - /* Now that we have it encoded, release the original pixels */ - if (!(surface->flags & SDL_PREALLOC)) { - SDL_free(surface->pixels); - surface->pixels = NULL; - } - - /* realloc the buffer to release unused memory */ - { - Uint8 *p = SDL_realloc(rlebuf, dst - rlebuf); - if (!p) - p = rlebuf; - surface->map->data = p; - } - - return 0; -} - -static Uint32 -getpix_8(Uint8 * srcbuf) -{ - return *srcbuf; -} - -static Uint32 -getpix_16(Uint8 * srcbuf) -{ - return *(Uint16 *) srcbuf; -} - -static Uint32 -getpix_24(Uint8 * srcbuf) -{ -#if SDL_BYTEORDER == SDL_LIL_ENDIAN - return srcbuf[0] + (srcbuf[1] << 8) + (srcbuf[2] << 16); -#else - return (srcbuf[0] << 16) + (srcbuf[1] << 8) + srcbuf[2]; -#endif -} - -static Uint32 -getpix_32(Uint8 * srcbuf) -{ - return *(Uint32 *) srcbuf; -} - -typedef Uint32(*getpix_func) (Uint8 *); - -static const getpix_func getpixes[4] = { - getpix_8, getpix_16, getpix_24, getpix_32 -}; - -static int -RLEColorkeySurface(SDL_Surface * surface) -{ - Uint8 *rlebuf, *dst; - int maxn; - int y; - Uint8 *srcbuf, *lastline; - int maxsize = 0; - int bpp = surface->format->BytesPerPixel; - getpix_func getpix; - Uint32 ckey, rgbmask; - int w, h; - - /* calculate the worst case size for the compressed surface */ - switch (bpp) { - case 1: - /* worst case is alternating opaque and transparent pixels, - starting with an opaque pixel */ - maxsize = surface->h * 3 * (surface->w / 2 + 1) + 2; - break; - case 2: - case 3: - /* worst case is solid runs, at most 255 pixels wide */ - maxsize = surface->h * (2 * (surface->w / 255 + 1) - + surface->w * bpp) + 2; - break; - case 4: - /* worst case is solid runs, at most 65535 pixels wide */ - maxsize = surface->h * (4 * (surface->w / 65535 + 1) - + surface->w * 4) + 4; - break; - } - - rlebuf = (Uint8 *) SDL_malloc(maxsize); - if (rlebuf == NULL) { - SDL_OutOfMemory(); - return (-1); - } - - /* Set up the conversion */ - srcbuf = (Uint8 *) surface->pixels; - maxn = bpp == 4 ? 65535 : 255; - dst = rlebuf; - rgbmask = ~surface->format->Amask; - ckey = surface->map->info.colorkey & rgbmask; - lastline = dst; - getpix = getpixes[bpp - 1]; - w = surface->w; - h = surface->h; - -#define ADD_COUNTS(n, m) \ - if(bpp == 4) { \ - ((Uint16 *)dst)[0] = n; \ - ((Uint16 *)dst)[1] = m; \ - dst += 4; \ - } else { \ - dst[0] = n; \ - dst[1] = m; \ - dst += 2; \ - } - - for (y = 0; y < h; y++) { - int x = 0; - int blankline = 0; - do { - int run, skip, len; - int runstart; - int skipstart = x; - - /* find run of transparent, then opaque pixels */ - while (x < w && (getpix(srcbuf + x * bpp) & rgbmask) == ckey) - x++; - runstart = x; - while (x < w && (getpix(srcbuf + x * bpp) & rgbmask) != ckey) - x++; - skip = runstart - skipstart; - if (skip == w) - blankline = 1; - run = x - runstart; - - /* encode segment */ - while (skip > maxn) { - ADD_COUNTS(maxn, 0); - skip -= maxn; - } - len = MIN(run, maxn); - ADD_COUNTS(skip, len); - SDL_memcpy(dst, srcbuf + runstart * bpp, len * bpp); - dst += len * bpp; - run -= len; - runstart += len; - while (run) { - len = MIN(run, maxn); - ADD_COUNTS(0, len); - SDL_memcpy(dst, srcbuf + runstart * bpp, len * bpp); - dst += len * bpp; - runstart += len; - run -= len; - } - if (!blankline) - lastline = dst; - } while (x < w); - - srcbuf += surface->pitch; - } - dst = lastline; /* back up bast trailing blank lines */ - ADD_COUNTS(0, 0); - -#undef ADD_COUNTS - - /* Now that we have it encoded, release the original pixels */ - if (!(surface->flags & SDL_PREALLOC)) { - SDL_free(surface->pixels); - surface->pixels = NULL; - } - - /* realloc the buffer to release unused memory */ - { - /* If realloc returns NULL, the original block is left intact */ - Uint8 *p = SDL_realloc(rlebuf, dst - rlebuf); - if (!p) - p = rlebuf; - surface->map->data = p; - } - - return (0); -} - -int -SDL_RLESurface(SDL_Surface * surface) -{ - int flags; - - /* Clear any previous RLE conversion */ - if ((surface->flags & SDL_RLEACCEL) == SDL_RLEACCEL) { - SDL_UnRLESurface(surface, 1); - } - - /* We don't support RLE encoding of bitmaps */ - if (surface->format->BitsPerPixel < 8) { - return -1; - } - - /* Make sure the pixels are available */ - if (!surface->pixels) { - return -1; - } - - /* If we don't have colorkey or blending, nothing to do... */ - flags = surface->map->info.flags; - if (!(flags & (SDL_COPY_COLORKEY | SDL_COPY_BLEND))) { - return -1; - } - - /* Pass on combinations not supported */ - if ((flags & SDL_COPY_MODULATE_COLOR) || - ((flags & SDL_COPY_MODULATE_ALPHA) && surface->format->Amask) || - (flags & (SDL_COPY_ADD | SDL_COPY_MOD)) || - (flags & SDL_COPY_NEAREST)) { - return -1; - } - - /* Encode and set up the blit */ - if (!surface->format->Amask || !(flags & SDL_COPY_BLEND)) { - if (!surface->map->identity) { - return -1; - } - if (RLEColorkeySurface(surface) < 0) { - return -1; - } - surface->map->blit = SDL_RLEBlit; - surface->map->info.flags |= SDL_COPY_RLE_COLORKEY; - } else { - if (RLEAlphaSurface(surface) < 0) { - return -1; - } - surface->map->blit = SDL_RLEAlphaBlit; - surface->map->info.flags |= SDL_COPY_RLE_ALPHAKEY; - } - - /* The surface is now accelerated */ - surface->flags |= SDL_RLEACCEL; - - return (0); -} - -/* - * Un-RLE a surface with pixel alpha - * This may not give back exactly the image before RLE-encoding; all - * completely transparent pixels will be lost, and colour and alpha depth - * may have been reduced (when encoding for 16bpp targets). - */ -static SDL_bool -UnRLEAlpha(SDL_Surface * surface) -{ - Uint8 *srcbuf; - Uint32 *dst; - SDL_PixelFormat *sf = surface->format; - RLEDestFormat *df = surface->map->data; - int (*uncopy_opaque) (Uint32 *, void *, int, - RLEDestFormat *, SDL_PixelFormat *); - int (*uncopy_transl) (Uint32 *, void *, int, - RLEDestFormat *, SDL_PixelFormat *); - int w = surface->w; - int bpp = df->BytesPerPixel; - - if (bpp == 2) { - uncopy_opaque = uncopy_opaque_16; - uncopy_transl = uncopy_transl_16; - } else { - uncopy_opaque = uncopy_transl = uncopy_32; - } - - surface->pixels = SDL_malloc(surface->h * surface->pitch); - if (!surface->pixels) { - return (SDL_FALSE); - } - /* fill background with transparent pixels */ - SDL_memset(surface->pixels, 0, surface->h * surface->pitch); - - dst = surface->pixels; - srcbuf = (Uint8 *) (df + 1); - for (;;) { - /* copy opaque pixels */ - int ofs = 0; - do { - unsigned run; - if (bpp == 2) { - ofs += srcbuf[0]; - run = srcbuf[1]; - srcbuf += 2; - } else { - ofs += ((Uint16 *) srcbuf)[0]; - run = ((Uint16 *) srcbuf)[1]; - srcbuf += 4; - } - if (run) { - srcbuf += uncopy_opaque(dst + ofs, srcbuf, run, df, sf); - ofs += run; - } else if (!ofs) - return (SDL_TRUE); - } while (ofs < w); - - /* skip padding if needed */ - if (bpp == 2) - srcbuf += (uintptr_t) srcbuf & 2; - - /* copy translucent pixels */ - ofs = 0; - do { - unsigned run; - ofs += ((Uint16 *) srcbuf)[0]; - run = ((Uint16 *) srcbuf)[1]; - srcbuf += 4; - if (run) { - srcbuf += uncopy_transl(dst + ofs, srcbuf, run, df, sf); - ofs += run; - } - } while (ofs < w); - dst += surface->pitch >> 2; - } - /* Make the compiler happy */ - return (SDL_TRUE); -} - -void -SDL_UnRLESurface(SDL_Surface * surface, int recode) -{ - if (surface->flags & SDL_RLEACCEL) { - surface->flags &= ~SDL_RLEACCEL; - - if (recode && !(surface->flags & SDL_PREALLOC)) { - if (surface->map->info.flags & SDL_COPY_RLE_COLORKEY) { - SDL_Rect full; - - /* re-create the original surface */ - surface->pixels = SDL_malloc(surface->h * surface->pitch); - if (!surface->pixels) { - /* Oh crap... */ - surface->flags |= SDL_RLEACCEL; - return; - } - - /* fill it with the background colour */ - SDL_FillRect(surface, NULL, surface->map->info.colorkey); - - /* now render the encoded surface */ - full.x = full.y = 0; - full.w = surface->w; - full.h = surface->h; - SDL_RLEBlit(surface, &full, surface, &full); - } else { - if (!UnRLEAlpha(surface)) { - /* Oh crap... */ - surface->flags |= SDL_RLEACCEL; - return; - } - } - } - surface->map->info.flags &= - ~(SDL_COPY_RLE_COLORKEY | SDL_COPY_RLE_ALPHAKEY); - - if (surface->map->data) { - SDL_free(surface->map->data); - surface->map->data = NULL; - } - } -} - /* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/SDL-mobile/src/video/SDL_RLEaccel_c.h b/src/SDL-mobile/src/video/SDL_RLEaccel_c.h index 5e9bd30ca..01c52a0b3 100644 --- a/src/SDL-mobile/src/video/SDL_RLEaccel_c.h +++ b/src/SDL-mobile/src/video/SDL_RLEaccel_c.h @@ -19,13 +19,3 @@ 3. This notice may not be removed or altered from any source distribution. */ #include "SDL_config.h" - -/* Useful functions and variables from SDL_RLEaccel.c */ - -extern int SDL_RLESurface(SDL_Surface * surface); -extern int SDL_RLEBlit(SDL_Surface * src, SDL_Rect * srcrect, - SDL_Surface * dst, SDL_Rect * dstrect); -extern int SDL_RLEAlphaBlit(SDL_Surface * src, SDL_Rect * srcrect, - SDL_Surface * dst, SDL_Rect * dstrect); -extern void SDL_UnRLESurface(SDL_Surface * surface, int recode); -/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/SDL-mobile/src/video/SDL_blit.c b/src/SDL-mobile/src/video/SDL_blit.c index f63289ce0..72c45a06a 100644 --- a/src/SDL-mobile/src/video/SDL_blit.c +++ b/src/SDL-mobile/src/video/SDL_blit.c @@ -23,10 +23,8 @@ #include "SDL_video.h" #include "SDL_sysvideo.h" #include "SDL_blit.h" -#include "SDL_blit_auto.h" #include "SDL_blit_copy.h" #include "SDL_blit_slow.h" -#include "SDL_RLEaccel_c.h" #include "SDL_pixels_c.h" /* The general purpose software blit routine */ @@ -99,31 +97,6 @@ SDL_SoftBlit(SDL_Surface * src, SDL_Rect * srcrect, return (okay ? 0 : -1); } -#ifdef __MACOSX__ -#include - -static SDL_bool -SDL_UseAltivecPrefetch() -{ - const char key[] = "hw.l3cachesize"; - u_int64_t result = 0; - size_t typeSize = sizeof(result); - - if (sysctlbyname(key, &result, &typeSize, NULL, 0) == 0 && result > 0) { - return SDL_TRUE; - } else { - return SDL_FALSE; - } -} -#else -static SDL_bool -SDL_UseAltivecPrefetch() -{ - /* Just guess G4 */ - return SDL_TRUE; -} -#endif /* __MACOSX__ */ - static SDL_BlitFunc SDL_ChooseBlitFunc(Uint32 src_format, Uint32 dst_format, int flags, SDL_BlitFuncEntry * entries) @@ -154,11 +127,7 @@ SDL_ChooseBlitFunc(Uint32 src_format, Uint32 dst_format, int flags, features |= SDL_CPU_SSE2; } if (SDL_HasAltiVec()) { - if (SDL_UseAltivecPrefetch()) { - features |= SDL_CPU_ALTIVEC_PREFETCH; - } else { - features |= SDL_CPU_ALTIVEC_NOPREFETCH; - } + features |= SDL_CPU_ALTIVEC_PREFETCH; } } } @@ -220,42 +189,17 @@ SDL_CalculateBlit(SDL_Surface * surface) SDL_Surface *dst = map->dst; /* Clean everything out to start */ - if ((surface->flags & SDL_RLEACCEL) == SDL_RLEACCEL) { - SDL_UnRLESurface(surface, 1); - } map->blit = SDL_SoftBlit; map->info.src_fmt = surface->format; map->info.src_pitch = surface->pitch; map->info.dst_fmt = dst->format; map->info.dst_pitch = dst->pitch; - /* See if we can do RLE acceleration */ - if (map->info.flags & SDL_COPY_RLE_DESIRED) { - if (SDL_RLESurface(surface) == 0) { - return 0; - } - } - /* Choose a standard blit function */ if (map->identity && !(map->info.flags & ~SDL_COPY_RLE_DESIRED)) { blit = SDL_BlitCopy; - } else if (surface->format->BitsPerPixel < 8) { - blit = SDL_CalculateBlit0(surface); - } else if (surface->format->BytesPerPixel == 1) { - blit = SDL_CalculateBlit1(surface); - } else if (map->info.flags & SDL_COPY_BLEND) { - blit = SDL_CalculateBlitA(surface); - } else { - blit = SDL_CalculateBlitN(surface); } - if (blit == NULL) { - Uint32 src_format = surface->format->format; - Uint32 dst_format = dst->format->format; - blit = - SDL_ChooseBlitFunc(src_format, dst_format, map->info.flags, - SDL_GeneratedBlitFuncTable); - } #ifndef TEST_SLOW_BLIT if (blit == NULL) #endif diff --git a/src/SDL-mobile/src/video/SDL_blit_0.c b/src/SDL-mobile/src/video/SDL_blit_0.c deleted file mode 100644 index 5c2735745..000000000 --- a/src/SDL-mobile/src/video/SDL_blit_0.c +++ /dev/null @@ -1,483 +0,0 @@ -/* - Simple DirectMedia Layer - Copyright (C) 1997-2012 Sam Lantinga - - 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" - -#include "SDL_video.h" -#include "SDL_blit.h" - -/* Functions to blit from bitmaps to other surfaces */ - -static void -BlitBto1(SDL_BlitInfo * info) -{ - int c; - int width, height; - Uint8 *src, *map, *dst; - int srcskip, dstskip; - - /* Set up some basic variables */ - width = info->dst_w; - height = info->dst_h; - src = info->src; - srcskip = info->src_skip; - dst = info->dst; - dstskip = info->dst_skip; - map = info->table; - srcskip += width - (width + 7) / 8; - - if (map) { - while (height--) { - Uint8 byte = 0, bit; - for (c = 0; c < width; ++c) { - if ((c & 7) == 0) { - byte = *src++; - } - bit = (byte & 0x80) >> 7; - if (1) { - *dst = map[bit]; - } - dst++; - byte <<= 1; - } - src += srcskip; - dst += dstskip; - } - } else { - while (height--) { - Uint8 byte = 0, bit; - for (c = 0; c < width; ++c) { - if ((c & 7) == 0) { - byte = *src++; - } - bit = (byte & 0x80) >> 7; - if (1) { - *dst = bit; - } - dst++; - byte <<= 1; - } - src += srcskip; - dst += dstskip; - } - } -} - -static void -BlitBto2(SDL_BlitInfo * info) -{ - int c; - int width, height; - Uint8 *src; - Uint16 *map, *dst; - int srcskip, dstskip; - - /* Set up some basic variables */ - width = info->dst_w; - height = info->dst_h; - src = info->src; - srcskip = info->src_skip; - dst = (Uint16 *) info->dst; - dstskip = info->dst_skip / 2; - map = (Uint16 *) info->table; - srcskip += width - (width + 7) / 8; - - while (height--) { - Uint8 byte = 0, bit; - for (c = 0; c < width; ++c) { - if ((c & 7) == 0) { - byte = *src++; - } - bit = (byte & 0x80) >> 7; - if (1) { - *dst = map[bit]; - } - byte <<= 1; - dst++; - } - src += srcskip; - dst += dstskip; - } -} - -static void -BlitBto3(SDL_BlitInfo * info) -{ - int c, o; - int width, height; - Uint8 *src, *map, *dst; - int srcskip, dstskip; - - /* Set up some basic variables */ - width = info->dst_w; - height = info->dst_h; - src = info->src; - srcskip = info->src_skip; - dst = info->dst; - dstskip = info->dst_skip; - map = info->table; - srcskip += width - (width + 7) / 8; - - while (height--) { - Uint8 byte = 0, bit; - for (c = 0; c < width; ++c) { - if ((c & 7) == 0) { - byte = *src++; - } - bit = (byte & 0x80) >> 7; - if (1) { - o = bit * 4; - dst[0] = map[o++]; - dst[1] = map[o++]; - dst[2] = map[o++]; - } - byte <<= 1; - dst += 3; - } - src += srcskip; - dst += dstskip; - } -} - -static void -BlitBto4(SDL_BlitInfo * info) -{ - int width, height; - Uint8 *src; - Uint32 *map, *dst; - int srcskip, dstskip; - int c; - - /* Set up some basic variables */ - width = info->dst_w; - height = info->dst_h; - src = info->src; - srcskip = info->src_skip; - dst = (Uint32 *) info->dst; - dstskip = info->dst_skip / 4; - map = (Uint32 *) info->table; - srcskip += width - (width + 7) / 8; - - while (height--) { - Uint8 byte = 0, bit; - for (c = 0; c < width; ++c) { - if ((c & 7) == 0) { - byte = *src++; - } - bit = (byte & 0x80) >> 7; - if (1) { - *dst = map[bit]; - } - byte <<= 1; - dst++; - } - src += srcskip; - dst += dstskip; - } -} - -static void -BlitBto1Key(SDL_BlitInfo * info) -{ - int width = info->dst_w; - int height = info->dst_h; - Uint8 *src = info->src; - Uint8 *dst = info->dst; - int srcskip = info->src_skip; - int dstskip = info->dst_skip; - Uint32 ckey = info->colorkey; - Uint8 *palmap = info->table; - int c; - - /* Set up some basic variables */ - srcskip += width - (width + 7) / 8; - - if (palmap) { - while (height--) { - Uint8 byte = 0, bit; - for (c = 0; c < width; ++c) { - if ((c & 7) == 0) { - byte = *src++; - } - bit = (byte & 0x80) >> 7; - if (bit != ckey) { - *dst = palmap[bit]; - } - dst++; - byte <<= 1; - } - src += srcskip; - dst += dstskip; - } - } else { - while (height--) { - Uint8 byte = 0, bit; - for (c = 0; c < width; ++c) { - if ((c & 7) == 0) { - byte = *src++; - } - bit = (byte & 0x80) >> 7; - if (bit != ckey) { - *dst = bit; - } - dst++; - byte <<= 1; - } - src += srcskip; - dst += dstskip; - } - } -} - -static void -BlitBto2Key(SDL_BlitInfo * info) -{ - int width = info->dst_w; - int height = info->dst_h; - Uint8 *src = info->src; - Uint16 *dstp = (Uint16 *) info->dst; - int srcskip = info->src_skip; - int dstskip = info->dst_skip; - Uint32 ckey = info->colorkey; - Uint8 *palmap = info->table; - int c; - - /* Set up some basic variables */ - srcskip += width - (width + 7) / 8; - dstskip /= 2; - - while (height--) { - Uint8 byte = 0, bit; - for (c = 0; c < width; ++c) { - if ((c & 7) == 0) { - byte = *src++; - } - bit = (byte & 0x80) >> 7; - if (bit != ckey) { - *dstp = ((Uint16 *) palmap)[bit]; - } - byte <<= 1; - dstp++; - } - src += srcskip; - dstp += dstskip; - } -} - -static void -BlitBto3Key(SDL_BlitInfo * info) -{ - int width = info->dst_w; - int height = info->dst_h; - Uint8 *src = info->src; - Uint8 *dst = info->dst; - int srcskip = info->src_skip; - int dstskip = info->dst_skip; - Uint32 ckey = info->colorkey; - Uint8 *palmap = info->table; - int c; - - /* Set up some basic variables */ - srcskip += width - (width + 7) / 8; - - while (height--) { - Uint8 byte = 0, bit; - for (c = 0; c < width; ++c) { - if ((c & 7) == 0) { - byte = *src++; - } - bit = (byte & 0x80) >> 7; - if (bit != ckey) { - SDL_memcpy(dst, &palmap[bit * 4], 3); - } - byte <<= 1; - dst += 3; - } - src += srcskip; - dst += dstskip; - } -} - -static void -BlitBto4Key(SDL_BlitInfo * info) -{ - int width = info->dst_w; - int height = info->dst_h; - Uint8 *src = info->src; - Uint32 *dstp = (Uint32 *) info->dst; - int srcskip = info->src_skip; - int dstskip = info->dst_skip; - Uint32 ckey = info->colorkey; - Uint8 *palmap = info->table; - int c; - - /* Set up some basic variables */ - srcskip += width - (width + 7) / 8; - dstskip /= 4; - - while (height--) { - Uint8 byte = 0, bit; - for (c = 0; c < width; ++c) { - if ((c & 7) == 0) { - byte = *src++; - } - bit = (byte & 0x80) >> 7; - if (bit != ckey) { - *dstp = ((Uint32 *) palmap)[bit]; - } - byte <<= 1; - dstp++; - } - src += srcskip; - dstp += dstskip; - } -} - -static void -BlitBtoNAlpha(SDL_BlitInfo * info) -{ - int width = info->dst_w; - int height = info->dst_h; - Uint8 *src = info->src; - Uint8 *dst = info->dst; - int srcskip = info->src_skip; - int dstskip = info->dst_skip; - const SDL_Color *srcpal = info->src_fmt->palette->colors; - SDL_PixelFormat *dstfmt = info->dst_fmt; - int dstbpp; - int c; - const int A = info->a; - - /* Set up some basic variables */ - dstbpp = dstfmt->BytesPerPixel; - srcskip += width - (width + 7) / 8; - - while (height--) { - Uint8 byte = 0, bit; - for (c = 0; c < width; ++c) { - if ((c & 7) == 0) { - byte = *src++; - } - bit = (byte & 0x80) >> 7; - if (1) { - Uint32 pixel; - unsigned sR, sG, sB; - unsigned dR, dG, dB; - sR = srcpal[bit].r; - sG = srcpal[bit].g; - sB = srcpal[bit].b; - DISEMBLE_RGB(dst, dstbpp, dstfmt, pixel, dR, dG, dB); - ALPHA_BLEND(sR, sG, sB, A, dR, dG, dB); - ASSEMBLE_RGB(dst, dstbpp, dstfmt, dR, dG, dB); - } - byte <<= 1; - dst += dstbpp; - } - src += srcskip; - dst += dstskip; - } -} - -static void -BlitBtoNAlphaKey(SDL_BlitInfo * info) -{ - int width = info->dst_w; - int height = info->dst_h; - Uint8 *src = info->src; - Uint8 *dst = info->dst; - int srcskip = info->src_skip; - int dstskip = info->dst_skip; - SDL_PixelFormat *srcfmt = info->src_fmt; - SDL_PixelFormat *dstfmt = info->dst_fmt; - const SDL_Color *srcpal = srcfmt->palette->colors; - int dstbpp; - int c; - const int A = info->a; - Uint32 ckey = info->colorkey; - - /* Set up some basic variables */ - dstbpp = dstfmt->BytesPerPixel; - srcskip += width - (width + 7) / 8; - - while (height--) { - Uint8 byte = 0, bit; - for (c = 0; c < width; ++c) { - if ((c & 7) == 0) { - byte = *src++; - } - bit = (byte & 0x80) >> 7; - if (bit != ckey) { - int sR, sG, sB; - int dR, dG, dB; - Uint32 pixel; - sR = srcpal[bit].r; - sG = srcpal[bit].g; - sB = srcpal[bit].b; - DISEMBLE_RGB(dst, dstbpp, dstfmt, pixel, dR, dG, dB); - ALPHA_BLEND(sR, sG, sB, A, dR, dG, dB); - ASSEMBLE_RGB(dst, dstbpp, dstfmt, dR, dG, dB); - } - byte <<= 1; - dst += dstbpp; - } - src += srcskip; - dst += dstskip; - } -} - -static const SDL_BlitFunc bitmap_blit[] = { - NULL, BlitBto1, BlitBto2, BlitBto3, BlitBto4 -}; - -static const SDL_BlitFunc colorkey_blit[] = { - NULL, BlitBto1Key, BlitBto2Key, BlitBto3Key, BlitBto4Key -}; - -SDL_BlitFunc -SDL_CalculateBlit0(SDL_Surface * surface) -{ - int which; - - if (surface->format->BitsPerPixel != 1) { - /* We don't support sub 8-bit packed pixel modes */ - return NULL; - } - if (surface->map->dst->format->BitsPerPixel < 8) { - which = 0; - } else { - which = surface->map->dst->format->BytesPerPixel; - } - switch (surface->map->info.flags & ~SDL_COPY_RLE_MASK) { - case 0: - return bitmap_blit[which]; - - case SDL_COPY_COLORKEY: - return colorkey_blit[which]; - - case SDL_COPY_MODULATE_ALPHA | SDL_COPY_BLEND: - return which >= 2 ? BlitBtoNAlpha : NULL; - - case SDL_COPY_COLORKEY | SDL_COPY_MODULATE_ALPHA | SDL_COPY_BLEND: - return which >= 2 ? BlitBtoNAlphaKey : NULL; - } - return NULL; -} - -/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/SDL-mobile/src/video/SDL_blit_1.c b/src/SDL-mobile/src/video/SDL_blit_1.c deleted file mode 100644 index 9bdda4426..000000000 --- a/src/SDL-mobile/src/video/SDL_blit_1.c +++ /dev/null @@ -1,552 +0,0 @@ -/* - Simple DirectMedia Layer - Copyright (C) 1997-2012 Sam Lantinga - - 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" - -#include "SDL_video.h" -#include "SDL_blit.h" -#include "SDL_sysvideo.h" -#include "SDL_endian.h" - -/* Functions to blit from 8-bit surfaces to other surfaces */ - -static void -Blit1to1(SDL_BlitInfo * info) -{ -#ifndef USE_DUFFS_LOOP - int c; -#endif - int width, height; - Uint8 *src, *map, *dst; - int srcskip, dstskip; - - /* Set up some basic variables */ - width = info->dst_w; - height = info->dst_h; - src = info->src; - srcskip = info->src_skip; - dst = info->dst; - dstskip = info->dst_skip; - map = info->table; - - while (height--) { -#ifdef USE_DUFFS_LOOP - /* *INDENT-OFF* */ - DUFFS_LOOP( - { - *dst = map[*src]; - } - dst++; - src++; - , width); - /* *INDENT-ON* */ -#else - for (c = width; c; --c) { - *dst = map[*src]; - dst++; - src++; - } -#endif - src += srcskip; - dst += dstskip; - } -} - -/* This is now endian dependent */ -#if ( SDL_BYTEORDER == SDL_LIL_ENDIAN ) -#define HI 1 -#define LO 0 -#else /* ( SDL_BYTEORDER == SDL_BIG_ENDIAN ) */ -#define HI 0 -#define LO 1 -#endif -static void -Blit1to2(SDL_BlitInfo * info) -{ -#ifndef USE_DUFFS_LOOP - int c; -#endif - int width, height; - Uint8 *src, *dst; - Uint16 *map; - int srcskip, dstskip; - - /* Set up some basic variables */ - width = info->dst_w; - height = info->dst_h; - src = info->src; - srcskip = info->src_skip; - dst = info->dst; - dstskip = info->dst_skip; - map = (Uint16 *) info->table; - -#ifdef USE_DUFFS_LOOP - while (height--) { - /* *INDENT-OFF* */ - DUFFS_LOOP( - { - *(Uint16 *)dst = map[*src++]; - dst += 2; - }, - width); - /* *INDENT-ON* */ - src += srcskip; - dst += dstskip; - } -#else - /* Memory align at 4-byte boundary, if necessary */ - if ((long) dst & 0x03) { - /* Don't do anything if width is 0 */ - if (width == 0) { - return; - } - --width; - - while (height--) { - /* Perform copy alignment */ - *(Uint16 *) dst = map[*src++]; - dst += 2; - - /* Copy in 4 pixel chunks */ - for (c = width / 4; c; --c) { - *(Uint32 *) dst = (map[src[HI]] << 16) | (map[src[LO]]); - src += 2; - dst += 4; - *(Uint32 *) dst = (map[src[HI]] << 16) | (map[src[LO]]); - src += 2; - dst += 4; - } - /* Get any leftovers */ - switch (width & 3) { - case 3: - *(Uint16 *) dst = map[*src++]; - dst += 2; - case 2: - *(Uint32 *) dst = (map[src[HI]] << 16) | (map[src[LO]]); - src += 2; - dst += 4; - break; - case 1: - *(Uint16 *) dst = map[*src++]; - dst += 2; - break; - } - src += srcskip; - dst += dstskip; - } - } else { - while (height--) { - /* Copy in 4 pixel chunks */ - for (c = width / 4; c; --c) { - *(Uint32 *) dst = (map[src[HI]] << 16) | (map[src[LO]]); - src += 2; - dst += 4; - *(Uint32 *) dst = (map[src[HI]] << 16) | (map[src[LO]]); - src += 2; - dst += 4; - } - /* Get any leftovers */ - switch (width & 3) { - case 3: - *(Uint16 *) dst = map[*src++]; - dst += 2; - case 2: - *(Uint32 *) dst = (map[src[HI]] << 16) | (map[src[LO]]); - src += 2; - dst += 4; - break; - case 1: - *(Uint16 *) dst = map[*src++]; - dst += 2; - break; - } - src += srcskip; - dst += dstskip; - } - } -#endif /* USE_DUFFS_LOOP */ -} - -static void -Blit1to3(SDL_BlitInfo * info) -{ -#ifndef USE_DUFFS_LOOP - int c; -#endif - int o; - int width, height; - Uint8 *src, *map, *dst; - int srcskip, dstskip; - - /* Set up some basic variables */ - width = info->dst_w; - height = info->dst_h; - src = info->src; - srcskip = info->src_skip; - dst = info->dst; - dstskip = info->dst_skip; - map = info->table; - - while (height--) { -#ifdef USE_DUFFS_LOOP - /* *INDENT-OFF* */ - DUFFS_LOOP( - { - o = *src * 4; - dst[0] = map[o++]; - dst[1] = map[o++]; - dst[2] = map[o++]; - } - src++; - dst += 3; - , width); - /* *INDENT-ON* */ -#else - for (c = width; c; --c) { - o = *src * 4; - dst[0] = map[o++]; - dst[1] = map[o++]; - dst[2] = map[o++]; - src++; - dst += 3; - } -#endif /* USE_DUFFS_LOOP */ - src += srcskip; - dst += dstskip; - } -} - -static void -Blit1to4(SDL_BlitInfo * info) -{ -#ifndef USE_DUFFS_LOOP - int c; -#endif - int width, height; - Uint8 *src; - Uint32 *map, *dst; - int srcskip, dstskip; - - /* Set up some basic variables */ - width = info->dst_w; - height = info->dst_h; - src = info->src; - srcskip = info->src_skip; - dst = (Uint32 *) info->dst; - dstskip = info->dst_skip / 4; - map = (Uint32 *) info->table; - - while (height--) { -#ifdef USE_DUFFS_LOOP - /* *INDENT-OFF* */ - DUFFS_LOOP( - *dst++ = map[*src++]; - , width); - /* *INDENT-ON* */ -#else - for (c = width / 4; c; --c) { - *dst++ = map[*src++]; - *dst++ = map[*src++]; - *dst++ = map[*src++]; - *dst++ = map[*src++]; - } - switch (width & 3) { - case 3: - *dst++ = map[*src++]; - case 2: - *dst++ = map[*src++]; - case 1: - *dst++ = map[*src++]; - } -#endif /* USE_DUFFS_LOOP */ - src += srcskip; - dst += dstskip; - } -} - -static void -Blit1to1Key(SDL_BlitInfo * info) -{ - int width = info->dst_w; - int height = info->dst_h; - Uint8 *src = info->src; - int srcskip = info->src_skip; - Uint8 *dst = info->dst; - int dstskip = info->dst_skip; - Uint8 *palmap = info->table; - Uint32 ckey = info->colorkey; - - if (palmap) { - while (height--) { - /* *INDENT-OFF* */ - DUFFS_LOOP( - { - if ( *src != ckey ) { - *dst = palmap[*src]; - } - dst++; - src++; - }, - width); - /* *INDENT-ON* */ - src += srcskip; - dst += dstskip; - } - } else { - while (height--) { - /* *INDENT-OFF* */ - DUFFS_LOOP( - { - if ( *src != ckey ) { - *dst = *src; - } - dst++; - src++; - }, - width); - /* *INDENT-ON* */ - src += srcskip; - dst += dstskip; - } - } -} - -static void -Blit1to2Key(SDL_BlitInfo * info) -{ - int width = info->dst_w; - int height = info->dst_h; - Uint8 *src = info->src; - int srcskip = info->src_skip; - Uint16 *dstp = (Uint16 *) info->dst; - int dstskip = info->dst_skip; - Uint16 *palmap = (Uint16 *) info->table; - Uint32 ckey = info->colorkey; - - /* Set up some basic variables */ - dstskip /= 2; - - while (height--) { - /* *INDENT-OFF* */ - DUFFS_LOOP( - { - if ( *src != ckey ) { - *dstp=palmap[*src]; - } - src++; - dstp++; - }, - width); - /* *INDENT-ON* */ - src += srcskip; - dstp += dstskip; - } -} - -static void -Blit1to3Key(SDL_BlitInfo * info) -{ - int width = info->dst_w; - int height = info->dst_h; - Uint8 *src = info->src; - int srcskip = info->src_skip; - Uint8 *dst = info->dst; - int dstskip = info->dst_skip; - Uint8 *palmap = info->table; - Uint32 ckey = info->colorkey; - int o; - - while (height--) { - /* *INDENT-OFF* */ - DUFFS_LOOP( - { - if ( *src != ckey ) { - o = *src * 4; - dst[0] = palmap[o++]; - dst[1] = palmap[o++]; - dst[2] = palmap[o++]; - } - src++; - dst += 3; - }, - width); - /* *INDENT-ON* */ - src += srcskip; - dst += dstskip; - } -} - -static void -Blit1to4Key(SDL_BlitInfo * info) -{ - int width = info->dst_w; - int height = info->dst_h; - Uint8 *src = info->src; - int srcskip = info->src_skip; - Uint32 *dstp = (Uint32 *) info->dst; - int dstskip = info->dst_skip; - Uint32 *palmap = (Uint32 *) info->table; - Uint32 ckey = info->colorkey; - - /* Set up some basic variables */ - dstskip /= 4; - - while (height--) { - /* *INDENT-OFF* */ - DUFFS_LOOP( - { - if ( *src != ckey ) { - *dstp = palmap[*src]; - } - src++; - dstp++; - }, - width); - /* *INDENT-ON* */ - src += srcskip; - dstp += dstskip; - } -} - -static void -Blit1toNAlpha(SDL_BlitInfo * info) -{ - int width = info->dst_w; - int height = info->dst_h; - Uint8 *src = info->src; - int srcskip = info->src_skip; - Uint8 *dst = info->dst; - int dstskip = info->dst_skip; - SDL_PixelFormat *dstfmt = info->dst_fmt; - const SDL_Color *srcpal = info->src_fmt->palette->colors; - int dstbpp; - const int A = info->a; - - /* Set up some basic variables */ - dstbpp = dstfmt->BytesPerPixel; - - while (height--) { - int sR, sG, sB; - int dR, dG, dB; - /* *INDENT-OFF* */ - DUFFS_LOOP4( - { - Uint32 pixel; - sR = srcpal[*src].r; - sG = srcpal[*src].g; - sB = srcpal[*src].b; - DISEMBLE_RGB(dst, dstbpp, dstfmt, - pixel, dR, dG, dB); - ALPHA_BLEND(sR, sG, sB, A, dR, dG, dB); - ASSEMBLE_RGB(dst, dstbpp, dstfmt, dR, dG, dB); - src++; - dst += dstbpp; - }, - width); - /* *INDENT-ON* */ - src += srcskip; - dst += dstskip; - } -} - -static void -Blit1toNAlphaKey(SDL_BlitInfo * info) -{ - int width = info->dst_w; - int height = info->dst_h; - Uint8 *src = info->src; - int srcskip = info->src_skip; - Uint8 *dst = info->dst; - int dstskip = info->dst_skip; - SDL_PixelFormat *dstfmt = info->dst_fmt; - const SDL_Color *srcpal = info->src_fmt->palette->colors; - Uint32 ckey = info->colorkey; - int dstbpp; - const int A = info->a; - - /* Set up some basic variables */ - dstbpp = dstfmt->BytesPerPixel; - - while (height--) { - int sR, sG, sB; - int dR, dG, dB; - /* *INDENT-OFF* */ - DUFFS_LOOP( - { - if ( *src != ckey ) { - Uint32 pixel; - sR = srcpal[*src].r; - sG = srcpal[*src].g; - sB = srcpal[*src].b; - DISEMBLE_RGB(dst, dstbpp, dstfmt, - pixel, dR, dG, dB); - ALPHA_BLEND(sR, sG, sB, A, dR, dG, dB); - ASSEMBLE_RGB(dst, dstbpp, dstfmt, dR, dG, dB); - } - src++; - dst += dstbpp; - }, - width); - /* *INDENT-ON* */ - src += srcskip; - dst += dstskip; - } -} - -static const SDL_BlitFunc one_blit[] = { - NULL, Blit1to1, Blit1to2, Blit1to3, Blit1to4 -}; - -static const SDL_BlitFunc one_blitkey[] = { - NULL, Blit1to1Key, Blit1to2Key, Blit1to3Key, Blit1to4Key -}; - -SDL_BlitFunc -SDL_CalculateBlit1(SDL_Surface * surface) -{ - int which; - SDL_PixelFormat *dstfmt; - - dstfmt = surface->map->dst->format; - if (dstfmt->BitsPerPixel < 8) { - which = 0; - } else { - which = dstfmt->BytesPerPixel; - } - switch (surface->map->info.flags & ~SDL_COPY_RLE_MASK) { - case 0: - return one_blit[which]; - - case SDL_COPY_COLORKEY: - return one_blitkey[which]; - - case SDL_COPY_MODULATE_ALPHA | SDL_COPY_BLEND: - /* 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; - - case SDL_COPY_COLORKEY | SDL_COPY_MODULATE_ALPHA | SDL_COPY_BLEND: - return which >= 2 ? Blit1toNAlphaKey : NULL; - } - return NULL; -} - -/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/SDL-mobile/src/video/SDL_blit_A.c b/src/SDL-mobile/src/video/SDL_blit_A.c deleted file mode 100644 index d8537ee74..000000000 --- a/src/SDL-mobile/src/video/SDL_blit_A.c +++ /dev/null @@ -1,2263 +0,0 @@ -/* - Simple DirectMedia Layer - Copyright (C) 1997-2012 Sam Lantinga - - 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" - -#include "SDL_video.h" -#include "SDL_blit.h" - -/* Functions to perform alpha blended blitting */ - -/* N->1 blending with per-surface alpha */ -static void -BlitNto1SurfaceAlpha(SDL_BlitInfo * info) -{ - int width = info->dst_w; - int height = info->dst_h; - Uint8 *src = info->src; - int srcskip = info->src_skip; - Uint8 *dst = info->dst; - int dstskip = info->dst_skip; - Uint8 *palmap = info->table; - SDL_PixelFormat *srcfmt = info->src_fmt; - SDL_PixelFormat *dstfmt = info->dst_fmt; - int srcbpp = srcfmt->BytesPerPixel; - - const unsigned A = info->a; - - while (height--) { - /* *INDENT-OFF* */ - DUFFS_LOOP4( - { - Uint32 Pixel; - unsigned sR; - unsigned sG; - unsigned sB; - unsigned dR; - unsigned dG; - unsigned dB; - DISEMBLE_RGB(src, srcbpp, srcfmt, Pixel, sR, sG, sB); - dR = dstfmt->palette->colors[*dst].r; - dG = dstfmt->palette->colors[*dst].g; - dB = dstfmt->palette->colors[*dst].b; - ALPHA_BLEND(sR, sG, sB, A, dR, dG, dB); - dR &= 0xff; - dG &= 0xff; - dB &= 0xff; - /* Pack RGB into 8bit pixel */ - if ( palmap == NULL ) { - *dst =((dR>>5)<<(3+2))| - ((dG>>5)<<(2))| - ((dB>>6)<<(0)); - } else { - *dst = palmap[((dR>>5)<<(3+2))| - ((dG>>5)<<(2)) | - ((dB>>6)<<(0))]; - } - dst++; - src += srcbpp; - }, - width); - /* *INDENT-ON* */ - src += srcskip; - dst += dstskip; - } -} - -/* N->1 blending with pixel alpha */ -static void -BlitNto1PixelAlpha(SDL_BlitInfo * info) -{ - int width = info->dst_w; - int height = info->dst_h; - Uint8 *src = info->src; - int srcskip = info->src_skip; - Uint8 *dst = info->dst; - int dstskip = info->dst_skip; - Uint8 *palmap = info->table; - SDL_PixelFormat *srcfmt = info->src_fmt; - SDL_PixelFormat *dstfmt = info->dst_fmt; - int srcbpp = srcfmt->BytesPerPixel; - - while (height--) { - /* *INDENT-OFF* */ - DUFFS_LOOP4( - { - Uint32 Pixel; - unsigned sR; - unsigned sG; - unsigned sB; - unsigned sA; - unsigned dR; - unsigned dG; - unsigned dB; - DISEMBLE_RGBA(src,srcbpp,srcfmt,Pixel,sR,sG,sB,sA); - dR = dstfmt->palette->colors[*dst].r; - dG = dstfmt->palette->colors[*dst].g; - dB = dstfmt->palette->colors[*dst].b; - ALPHA_BLEND(sR, sG, sB, sA, dR, dG, dB); - dR &= 0xff; - dG &= 0xff; - dB &= 0xff; - /* Pack RGB into 8bit pixel */ - if ( palmap == NULL ) { - *dst =((dR>>5)<<(3+2))| - ((dG>>5)<<(2))| - ((dB>>6)<<(0)); - } else { - *dst = palmap[((dR>>5)<<(3+2))| - ((dG>>5)<<(2)) | - ((dB>>6)<<(0)) ]; - } - dst++; - src += srcbpp; - }, - width); - /* *INDENT-ON* */ - src += srcskip; - dst += dstskip; - } -} - -/* colorkeyed N->1 blending with per-surface alpha */ -static void -BlitNto1SurfaceAlphaKey(SDL_BlitInfo * info) -{ - int width = info->dst_w; - int height = info->dst_h; - Uint8 *src = info->src; - int srcskip = info->src_skip; - Uint8 *dst = info->dst; - int dstskip = info->dst_skip; - Uint8 *palmap = info->table; - SDL_PixelFormat *srcfmt = info->src_fmt; - SDL_PixelFormat *dstfmt = info->dst_fmt; - int srcbpp = srcfmt->BytesPerPixel; - Uint32 ckey = info->colorkey; - - const int A = info->a; - - while (height--) { - /* *INDENT-OFF* */ - DUFFS_LOOP( - { - Uint32 Pixel; - unsigned sR; - unsigned sG; - unsigned sB; - unsigned dR; - unsigned dG; - unsigned dB; - DISEMBLE_RGB(src, srcbpp, srcfmt, Pixel, sR, sG, sB); - if ( Pixel != ckey ) { - dR = dstfmt->palette->colors[*dst].r; - dG = dstfmt->palette->colors[*dst].g; - dB = dstfmt->palette->colors[*dst].b; - ALPHA_BLEND(sR, sG, sB, A, dR, dG, dB); - dR &= 0xff; - dG &= 0xff; - dB &= 0xff; - /* Pack RGB into 8bit pixel */ - if ( palmap == NULL ) { - *dst =((dR>>5)<<(3+2))| - ((dG>>5)<<(2)) | - ((dB>>6)<<(0)); - } else { - *dst = palmap[((dR>>5)<<(3+2))| - ((dG>>5)<<(2)) | - ((dB>>6)<<(0)) ]; - } - } - dst++; - src += srcbpp; - }, - width); - /* *INDENT-ON* */ - src += srcskip; - dst += dstskip; - } -} - -#ifdef __MMX__ - -/* fast RGB888->(A)RGB888 blending with surface alpha=128 special case */ -static void -BlitRGBtoRGBSurfaceAlpha128MMX(SDL_BlitInfo * info) -{ - int width = info->dst_w; - int height = info->dst_h; - Uint32 *srcp = (Uint32 *) info->src; - int srcskip = info->src_skip >> 2; - Uint32 *dstp = (Uint32 *) info->dst; - int dstskip = info->dst_skip >> 2; - Uint32 dalpha = info->dst_fmt->Amask; - - __m64 src1, src2, dst1, dst2, lmask, hmask, dsta; - - hmask = _mm_set_pi32(0x00fefefe, 0x00fefefe); /* alpha128 mask -> hmask */ - lmask = _mm_set_pi32(0x00010101, 0x00010101); /* !alpha128 mask -> lmask */ - dsta = _mm_set_pi32(dalpha, dalpha); /* dst alpha mask -> dsta */ - - while (height--) { - int n = width; - if (n & 1) { - Uint32 s = *srcp++; - Uint32 d = *dstp; - *dstp++ = ((((s & 0x00fefefe) + (d & 0x00fefefe)) >> 1) - + (s & d & 0x00010101)) | dalpha; - n--; - } - - for (n >>= 1; n > 0; --n) { - dst1 = *(__m64 *) dstp; /* 2 x dst -> dst1(ARGBARGB) */ - dst2 = dst1; /* 2 x dst -> dst2(ARGBARGB) */ - - src1 = *(__m64 *) srcp; /* 2 x src -> src1(ARGBARGB) */ - src2 = src1; /* 2 x src -> src2(ARGBARGB) */ - - dst2 = _mm_and_si64(dst2, hmask); /* dst & mask -> dst2 */ - src2 = _mm_and_si64(src2, hmask); /* src & mask -> src2 */ - src2 = _mm_add_pi32(src2, dst2); /* dst2 + src2 -> src2 */ - src2 = _mm_srli_pi32(src2, 1); /* src2 >> 1 -> src2 */ - - dst1 = _mm_and_si64(dst1, src1); /* src & dst -> dst1 */ - dst1 = _mm_and_si64(dst1, lmask); /* dst1 & !mask -> dst1 */ - dst1 = _mm_add_pi32(dst1, src2); /* src2 + dst1 -> dst1 */ - dst1 = _mm_or_si64(dst1, dsta); /* dsta(full alpha) | dst1 -> dst1 */ - - *(__m64 *) dstp = dst1; /* dst1 -> 2 x dst pixels */ - dstp += 2; - srcp += 2; - } - - srcp += srcskip; - dstp += dstskip; - } - _mm_empty(); -} - -/* fast RGB888->(A)RGB888 blending with surface alpha */ -static void -BlitRGBtoRGBSurfaceAlphaMMX(SDL_BlitInfo * info) -{ - SDL_PixelFormat *df = info->dst_fmt; - Uint32 chanmask = df->Rmask | df->Gmask | df->Bmask; - unsigned alpha = info->a; - - if (alpha == 128 && (df->Rmask | df->Gmask | df->Bmask) == 0x00FFFFFF) { - /* only call a128 version when R,G,B occupy lower bits */ - BlitRGBtoRGBSurfaceAlpha128MMX(info); - } else { - int width = info->dst_w; - int height = info->dst_h; - Uint32 *srcp = (Uint32 *) info->src; - int srcskip = info->src_skip >> 2; - Uint32 *dstp = (Uint32 *) info->dst; - int dstskip = info->dst_skip >> 2; - Uint32 dalpha = df->Amask; - Uint32 amult; - - __m64 src1, src2, dst1, dst2, mm_alpha, mm_zero, dsta; - - mm_zero = _mm_setzero_si64(); /* 0 -> mm_zero */ - /* form the alpha mult */ - amult = alpha | (alpha << 8); - amult = amult | (amult << 16); - chanmask = - (0xff << df->Rshift) | (0xff << df-> - Gshift) | (0xff << df->Bshift); - mm_alpha = _mm_set_pi32(0, amult & chanmask); /* 0000AAAA -> mm_alpha, minus 1 chan */ - mm_alpha = _mm_unpacklo_pi8(mm_alpha, mm_zero); /* 0A0A0A0A -> mm_alpha, minus 1 chan */ - /* at this point mm_alpha can be 000A0A0A or 0A0A0A00 or another combo */ - dsta = _mm_set_pi32(dalpha, dalpha); /* dst alpha mask -> dsta */ - - while (height--) { - int n = width; - if (n & 1) { - /* One Pixel Blend */ - src2 = _mm_cvtsi32_si64(*srcp); /* src(ARGB) -> src2 (0000ARGB) */ - src2 = _mm_unpacklo_pi8(src2, mm_zero); /* 0A0R0G0B -> src2 */ - - dst1 = _mm_cvtsi32_si64(*dstp); /* dst(ARGB) -> dst1 (0000ARGB) */ - dst1 = _mm_unpacklo_pi8(dst1, mm_zero); /* 0A0R0G0B -> dst1 */ - - src2 = _mm_sub_pi16(src2, dst1); /* src2 - dst2 -> src2 */ - src2 = _mm_mullo_pi16(src2, mm_alpha); /* src2 * alpha -> src2 */ - src2 = _mm_srli_pi16(src2, 8); /* src2 >> 8 -> src2 */ - dst1 = _mm_add_pi8(src2, dst1); /* src2 + dst1 -> dst1 */ - - dst1 = _mm_packs_pu16(dst1, mm_zero); /* 0000ARGB -> dst1 */ - dst1 = _mm_or_si64(dst1, dsta); /* dsta | dst1 -> dst1 */ - *dstp = _mm_cvtsi64_si32(dst1); /* dst1 -> pixel */ - - ++srcp; - ++dstp; - - n--; - } - - for (n >>= 1; n > 0; --n) { - /* Two Pixels Blend */ - src1 = *(__m64 *) srcp; /* 2 x src -> src1(ARGBARGB) */ - src2 = src1; /* 2 x src -> src2(ARGBARGB) */ - src1 = _mm_unpacklo_pi8(src1, mm_zero); /* low - 0A0R0G0B -> src1 */ - src2 = _mm_unpackhi_pi8(src2, mm_zero); /* high - 0A0R0G0B -> src2 */ - - dst1 = *(__m64 *) dstp; /* 2 x dst -> dst1(ARGBARGB) */ - dst2 = dst1; /* 2 x dst -> dst2(ARGBARGB) */ - dst1 = _mm_unpacklo_pi8(dst1, mm_zero); /* low - 0A0R0G0B -> dst1 */ - dst2 = _mm_unpackhi_pi8(dst2, mm_zero); /* high - 0A0R0G0B -> dst2 */ - - src1 = _mm_sub_pi16(src1, dst1); /* src1 - dst1 -> src1 */ - src1 = _mm_mullo_pi16(src1, mm_alpha); /* src1 * alpha -> src1 */ - src1 = _mm_srli_pi16(src1, 8); /* src1 >> 8 -> src1 */ - dst1 = _mm_add_pi8(src1, dst1); /* src1 + dst1(dst1) -> dst1 */ - - src2 = _mm_sub_pi16(src2, dst2); /* src2 - dst2 -> src2 */ - src2 = _mm_mullo_pi16(src2, mm_alpha); /* src2 * alpha -> src2 */ - src2 = _mm_srli_pi16(src2, 8); /* src2 >> 8 -> src2 */ - dst2 = _mm_add_pi8(src2, dst2); /* src2 + dst2(dst2) -> dst2 */ - - dst1 = _mm_packs_pu16(dst1, dst2); /* 0A0R0G0B(res1), 0A0R0G0B(res2) -> dst1(ARGBARGB) */ - dst1 = _mm_or_si64(dst1, dsta); /* dsta | dst1 -> dst1 */ - - *(__m64 *) dstp = dst1; /* dst1 -> 2 x pixel */ - - srcp += 2; - dstp += 2; - } - srcp += srcskip; - dstp += dstskip; - } - _mm_empty(); - } -} - -/* fast ARGB888->(A)RGB888 blending with pixel alpha */ -static void -BlitRGBtoRGBPixelAlphaMMX(SDL_BlitInfo * info) -{ - int width = info->dst_w; - int height = info->dst_h; - Uint32 *srcp = (Uint32 *) info->src; - int srcskip = info->src_skip >> 2; - Uint32 *dstp = (Uint32 *) info->dst; - int dstskip = info->dst_skip >> 2; - SDL_PixelFormat *sf = info->src_fmt; - Uint32 chanmask = sf->Rmask | sf->Gmask | sf->Bmask; - Uint32 amask = sf->Amask; - Uint32 ashift = sf->Ashift; - Uint64 multmask; - - __m64 src1, dst1, mm_alpha, mm_zero, dmask; - - mm_zero = _mm_setzero_si64(); /* 0 -> mm_zero */ - multmask = 0xFFFF; - multmask <<= (ashift * 2); - multmask = ~multmask; - dmask = *(__m64 *) & multmask; /* dst alpha mask -> dmask */ - - while (height--) { - /* *INDENT-OFF* */ - DUFFS_LOOP4({ - Uint32 alpha = *srcp & amask; - if (alpha == 0) { - /* do nothing */ - } else if (alpha == amask) { - /* opaque alpha -- copy RGB, keep dst alpha */ - *dstp = (*srcp & chanmask) | (*dstp & ~chanmask); - } else { - src1 = _mm_cvtsi32_si64(*srcp); /* src(ARGB) -> src1 (0000ARGB)*/ - src1 = _mm_unpacklo_pi8(src1, mm_zero); /* 0A0R0G0B -> src1 */ - - dst1 = _mm_cvtsi32_si64(*dstp); /* dst(ARGB) -> dst1 (0000ARGB)*/ - dst1 = _mm_unpacklo_pi8(dst1, mm_zero); /* 0A0R0G0B -> dst1 */ - - mm_alpha = _mm_cvtsi32_si64(alpha); /* alpha -> mm_alpha (0000000A) */ - mm_alpha = _mm_srli_si64(mm_alpha, ashift); /* mm_alpha >> ashift -> mm_alpha(0000000A) */ - mm_alpha = _mm_unpacklo_pi16(mm_alpha, mm_alpha); /* 00000A0A -> mm_alpha */ - mm_alpha = _mm_unpacklo_pi32(mm_alpha, mm_alpha); /* 0A0A0A0A -> mm_alpha */ - mm_alpha = _mm_and_si64(mm_alpha, dmask); /* 000A0A0A -> mm_alpha, preserve dst alpha on add */ - - /* blend */ - src1 = _mm_sub_pi16(src1, dst1);/* src1 - dst1 -> src1 */ - src1 = _mm_mullo_pi16(src1, mm_alpha); /* (src1 - dst1) * alpha -> src1 */ - src1 = _mm_srli_pi16(src1, 8); /* src1 >> 8 -> src1(000R0G0B) */ - dst1 = _mm_add_pi8(src1, dst1); /* src1 + dst1 -> dst1(0A0R0G0B) */ - dst1 = _mm_packs_pu16(dst1, mm_zero); /* 0000ARGB -> dst1 */ - - *dstp = _mm_cvtsi64_si32(dst1); /* dst1 -> pixel */ - } - ++srcp; - ++dstp; - }, width); - /* *INDENT-ON* */ - srcp += srcskip; - dstp += dstskip; - } - _mm_empty(); -} - -#endif /* __MMX__ */ - -#if SDL_ALTIVEC_BLITTERS -#if __MWERKS__ -#pragma altivec_model on -#endif -#if HAVE_ALTIVEC_H -#include -#endif - -#if (defined(__MACOSX__) && (__GNUC__ < 4)) -#define VECUINT8_LITERAL(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p) \ - (vector unsigned char) ( a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p ) -#define VECUINT16_LITERAL(a,b,c,d,e,f,g,h) \ - (vector unsigned short) ( a,b,c,d,e,f,g,h ) -#else -#define VECUINT8_LITERAL(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p) \ - (vector unsigned char) { a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p } -#define VECUINT16_LITERAL(a,b,c,d,e,f,g,h) \ - (vector unsigned short) { a,b,c,d,e,f,g,h } -#endif - -#define UNALIGNED_PTR(x) (((size_t) x) & 0x0000000F) -#define VECPRINT(msg, v) do { \ - vector unsigned int tmpvec = (vector unsigned int)(v); \ - unsigned int *vp = (unsigned int *)&tmpvec; \ - printf("%s = %08X %08X %08X %08X\n", msg, vp[0], vp[1], vp[2], vp[3]); \ -} while (0) - -/* the permuation vector that takes the high bytes out of all the appropriate shorts - (vector unsigned char)( - 0x00, 0x10, 0x02, 0x12, - 0x04, 0x14, 0x06, 0x16, - 0x08, 0x18, 0x0A, 0x1A, - 0x0C, 0x1C, 0x0E, 0x1E ); -*/ -#define VEC_MERGE_PERMUTE() (vec_add(vec_lvsl(0, (int*)NULL), (vector unsigned char)vec_splat_u16(0x0F))) -#define VEC_U32_24() (vec_add(vec_splat_u32(12), vec_splat_u32(12))) -#define VEC_ALPHA_MASK() ((vector unsigned char)vec_sl((vector unsigned int)vec_splat_s8(-1), VEC_U32_24())) -#define VEC_ALIGNER(src) ((UNALIGNED_PTR(src)) \ - ? vec_lvsl(0, src) \ - : vec_add(vec_lvsl(8, src), vec_splat_u8(8))) - - -#define VEC_MULTIPLY_ALPHA(vs, vd, valpha, mergePermute, v1_16, v8_16) do { \ - /* vtemp1 contains source AAGGAAGGAAGGAAGG */ \ - vector unsigned short vtemp1 = vec_mule(vs, valpha); \ - /* vtemp2 contains source RRBBRRBBRRBBRRBB */ \ - vector unsigned short vtemp2 = vec_mulo(vs, valpha); \ - /* valpha2 is 255-alpha */ \ - vector unsigned char valpha2 = vec_nor(valpha, valpha); \ - /* vtemp3 contains dest AAGGAAGGAAGGAAGG */ \ - vector unsigned short vtemp3 = vec_mule(vd, valpha2); \ - /* vtemp4 contains dest RRBBRRBBRRBBRRBB */ \ - vector unsigned short vtemp4 = vec_mulo(vd, valpha2); \ - /* add source and dest */ \ - vtemp1 = vec_add(vtemp1, vtemp3); \ - vtemp2 = vec_add(vtemp2, vtemp4); \ - /* vtemp1 = (vtemp1 + 1) + ((vtemp1 + 1) >> 8) */ \ - vtemp1 = vec_add(vtemp1, v1_16); \ - vtemp3 = vec_sr(vtemp1, v8_16); \ - vtemp1 = vec_add(vtemp1, vtemp3); \ - /* vtemp2 = (vtemp2 + 1) + ((vtemp2 + 1) >> 8) */ \ - vtemp2 = vec_add(vtemp2, v1_16); \ - vtemp4 = vec_sr(vtemp2, v8_16); \ - vtemp2 = vec_add(vtemp2, vtemp4); \ - /* (>>8) and get ARGBARGBARGBARGB */ \ - vd = (vector unsigned char)vec_perm(vtemp1, vtemp2, mergePermute); \ -} while (0) - -/* Calculate the permute vector used for 32->32 swizzling */ -static vector unsigned char -calc_swizzle32(const SDL_PixelFormat * srcfmt, const SDL_PixelFormat * dstfmt) -{ - /* - * We have to assume that the bits that aren't used by other - * colors is alpha, and it's one complete byte, since some formats - * leave alpha with a zero mask, but we should still swizzle the bits. - */ - /* ARGB */ - const static struct SDL_PixelFormat default_pixel_format = { - 0, NULL, 0, 0, - {0, 0}, - 0x00FF0000, 0x0000FF00, 0x000000FF, 0xFF000000, - 0, 0, 0, 0, - 16, 8, 0, 24, - 0, NULL - }; - if (!srcfmt) { - srcfmt = &default_pixel_format; - } - if (!dstfmt) { - dstfmt = &default_pixel_format; - } - const vector unsigned char plus = VECUINT8_LITERAL(0x00, 0x00, 0x00, 0x00, - 0x04, 0x04, 0x04, 0x04, - 0x08, 0x08, 0x08, 0x08, - 0x0C, 0x0C, 0x0C, - 0x0C); - vector unsigned char vswiz; - vector unsigned int srcvec; -#define RESHIFT(X) (3 - ((X) >> 3)) - Uint32 rmask = RESHIFT(srcfmt->Rshift) << (dstfmt->Rshift); - Uint32 gmask = RESHIFT(srcfmt->Gshift) << (dstfmt->Gshift); - Uint32 bmask = RESHIFT(srcfmt->Bshift) << (dstfmt->Bshift); - Uint32 amask; - /* Use zero for alpha if either surface doesn't have alpha */ - if (dstfmt->Amask) { - amask = - ((srcfmt->Amask) ? RESHIFT(srcfmt-> - Ashift) : 0x10) << (dstfmt->Ashift); - } else { - amask = - 0x10101010 & ((dstfmt->Rmask | dstfmt->Gmask | dstfmt->Bmask) ^ - 0xFFFFFFFF); - } -#undef RESHIFT - ((unsigned int *) (char *) &srcvec)[0] = (rmask | gmask | bmask | amask); - vswiz = vec_add(plus, (vector unsigned char) vec_splat(srcvec, 0)); - return (vswiz); -} - -static void -Blit32to565PixelAlphaAltivec(SDL_BlitInfo * info) -{ - int height = info->dst_h; - Uint8 *src = (Uint8 *) info->src; - int srcskip = info->src_skip; - Uint8 *dst = (Uint8 *) info->dst; - int dstskip = info->dst_skip; - SDL_PixelFormat *srcfmt = info->src_fmt; - - vector unsigned char v0 = vec_splat_u8(0); - vector unsigned short v8_16 = vec_splat_u16(8); - vector unsigned short v1_16 = vec_splat_u16(1); - vector unsigned short v2_16 = vec_splat_u16(2); - vector unsigned short v3_16 = vec_splat_u16(3); - vector unsigned int v8_32 = vec_splat_u32(8); - vector unsigned int v16_32 = vec_add(v8_32, v8_32); - vector unsigned short v3f = - VECUINT16_LITERAL(0x003f, 0x003f, 0x003f, 0x003f, - 0x003f, 0x003f, 0x003f, 0x003f); - vector unsigned short vfc = - VECUINT16_LITERAL(0x00fc, 0x00fc, 0x00fc, 0x00fc, - 0x00fc, 0x00fc, 0x00fc, 0x00fc); - - /* - 0x10 - 0x1f is the alpha - 0x00 - 0x0e evens are the red - 0x01 - 0x0f odds are zero - */ - vector unsigned char vredalpha1 = VECUINT8_LITERAL(0x10, 0x00, 0x01, 0x01, - 0x10, 0x02, 0x01, 0x01, - 0x10, 0x04, 0x01, 0x01, - 0x10, 0x06, 0x01, - 0x01); - vector unsigned char vredalpha2 = - (vector unsigned char) (vec_add((vector unsigned int) vredalpha1, - vec_sl(v8_32, v16_32)) - ); - /* - 0x00 - 0x0f is ARxx ARxx ARxx ARxx - 0x11 - 0x0f odds are blue - */ - vector unsigned char vblue1 = VECUINT8_LITERAL(0x00, 0x01, 0x02, 0x11, - 0x04, 0x05, 0x06, 0x13, - 0x08, 0x09, 0x0a, 0x15, - 0x0c, 0x0d, 0x0e, 0x17); - vector unsigned char vblue2 = - (vector unsigned char) (vec_add((vector unsigned int) vblue1, v8_32) - ); - /* - 0x00 - 0x0f is ARxB ARxB ARxB ARxB - 0x10 - 0x0e evens are green - */ - vector unsigned char vgreen1 = VECUINT8_LITERAL(0x00, 0x01, 0x10, 0x03, - 0x04, 0x05, 0x12, 0x07, - 0x08, 0x09, 0x14, 0x0b, - 0x0c, 0x0d, 0x16, 0x0f); - vector unsigned char vgreen2 = - (vector unsigned - char) (vec_add((vector unsigned int) vgreen1, vec_sl(v8_32, v8_32)) - ); - vector unsigned char vgmerge = VECUINT8_LITERAL(0x00, 0x02, 0x00, 0x06, - 0x00, 0x0a, 0x00, 0x0e, - 0x00, 0x12, 0x00, 0x16, - 0x00, 0x1a, 0x00, 0x1e); - vector unsigned char mergePermute = VEC_MERGE_PERMUTE(); - vector unsigned char vpermute = calc_swizzle32(srcfmt, NULL); - vector unsigned char valphaPermute = - vec_and(vec_lvsl(0, (int *) NULL), vec_splat_u8(0xC)); - - vector unsigned short vf800 = (vector unsigned short) vec_splat_u8(-7); - vf800 = vec_sl(vf800, vec_splat_u16(8)); - - while (height--) { - int extrawidth; - vector unsigned char valigner; - vector unsigned char vsrc; - vector unsigned char voverflow; - int width = info->dst_w; - -#define ONE_PIXEL_BLEND(condition, widthvar) \ - while (condition) { \ - Uint32 Pixel; \ - unsigned sR, sG, sB, dR, dG, dB, sA; \ - DISEMBLE_RGBA(src, 4, srcfmt, Pixel, sR, sG, sB, sA); \ - if(sA) { \ - unsigned short dstpixel = *((unsigned short *)dst); \ - dR = (dstpixel >> 8) & 0xf8; \ - dG = (dstpixel >> 3) & 0xfc; \ - dB = (dstpixel << 3) & 0xf8; \ - ALPHA_BLEND(sR, sG, sB, sA, dR, dG, dB); \ - *((unsigned short *)dst) = ( \ - ((dR & 0xf8) << 8) | ((dG & 0xfc) << 3) | (dB >> 3) \ - ); \ - } \ - src += 4; \ - dst += 2; \ - widthvar--; \ - } - ONE_PIXEL_BLEND((UNALIGNED_PTR(dst)) && (width), width); - extrawidth = (width % 8); - valigner = VEC_ALIGNER(src); - vsrc = (vector unsigned char) vec_ld(0, src); - width -= extrawidth; - while (width) { - vector unsigned char valpha; - vector unsigned char vsrc1, vsrc2; - vector unsigned char vdst1, vdst2; - vector unsigned short vR, vG, vB; - vector unsigned short vpixel, vrpixel, vgpixel, vbpixel; - - /* Load 8 pixels from src as ARGB */ - voverflow = (vector unsigned char) vec_ld(15, src); - vsrc = vec_perm(vsrc, voverflow, valigner); - vsrc1 = vec_perm(vsrc, vsrc, vpermute); - src += 16; - vsrc = (vector unsigned char) vec_ld(15, src); - voverflow = vec_perm(voverflow, vsrc, valigner); - vsrc2 = vec_perm(voverflow, voverflow, vpermute); - src += 16; - - /* Load 8 pixels from dst as XRGB */ - voverflow = vec_ld(0, dst); - vR = vec_and((vector unsigned short) voverflow, vf800); - vB = vec_sl((vector unsigned short) voverflow, v3_16); - vG = vec_sl(vB, v2_16); - vdst1 = - (vector unsigned char) vec_perm((vector unsigned char) vR, - (vector unsigned char) vR, - vredalpha1); - vdst1 = vec_perm(vdst1, (vector unsigned char) vB, vblue1); - vdst1 = vec_perm(vdst1, (vector unsigned char) vG, vgreen1); - vdst2 = - (vector unsigned char) vec_perm((vector unsigned char) vR, - (vector unsigned char) vR, - vredalpha2); - vdst2 = vec_perm(vdst2, (vector unsigned char) vB, vblue2); - vdst2 = vec_perm(vdst2, (vector unsigned char) vG, vgreen2); - - /* Alpha blend 8 pixels as ARGB */ - valpha = vec_perm(vsrc1, v0, valphaPermute); - VEC_MULTIPLY_ALPHA(vsrc1, vdst1, valpha, mergePermute, v1_16, - v8_16); - valpha = vec_perm(vsrc2, v0, valphaPermute); - VEC_MULTIPLY_ALPHA(vsrc2, vdst2, valpha, mergePermute, v1_16, - v8_16); - - /* Convert 8 pixels to 565 */ - vpixel = (vector unsigned short) vec_packpx((vector unsigned int) - vdst1, - (vector unsigned int) - vdst2); - vgpixel = (vector unsigned short) vec_perm(vdst1, vdst2, vgmerge); - vgpixel = vec_and(vgpixel, vfc); - vgpixel = vec_sl(vgpixel, v3_16); - vrpixel = vec_sl(vpixel, v1_16); - vrpixel = vec_and(vrpixel, vf800); - vbpixel = vec_and(vpixel, v3f); - vdst1 = - vec_or((vector unsigned char) vrpixel, - (vector unsigned char) vgpixel); - vdst1 = vec_or(vdst1, (vector unsigned char) vbpixel); - - /* Store 8 pixels */ - vec_st(vdst1, 0, dst); - - width -= 8; - dst += 16; - } - ONE_PIXEL_BLEND((extrawidth), extrawidth); -#undef ONE_PIXEL_BLEND - src += srcskip; - dst += dstskip; - } -} - -static void -Blit32to32SurfaceAlphaKeyAltivec(SDL_BlitInfo * info) -{ - int height = info->dst_h; - Uint32 *srcp = (Uint32 *) info->src; - int srcskip = info->src_skip >> 2; - Uint32 *dstp = (Uint32 *) info->dst; - int dstskip = info->dst_skip >> 2; - SDL_PixelFormat *srcfmt = info->src_fmt; - SDL_PixelFormat *dstfmt = info->dst_fmt; - unsigned sA = info->a; - unsigned dA = dstfmt->Amask ? SDL_ALPHA_OPAQUE : 0; - Uint32 rgbmask = srcfmt->Rmask | srcfmt->Gmask | srcfmt->Bmask; - Uint32 ckey = info->colorkey; - vector unsigned char mergePermute; - vector unsigned char vsrcPermute; - vector unsigned char vdstPermute; - vector unsigned char vsdstPermute; - vector unsigned char valpha; - vector unsigned char valphamask; - vector unsigned char vbits; - vector unsigned char v0; - vector unsigned short v1; - vector unsigned short v8; - vector unsigned int vckey; - vector unsigned int vrgbmask; - - mergePermute = VEC_MERGE_PERMUTE(); - v0 = vec_splat_u8(0); - v1 = vec_splat_u16(1); - v8 = vec_splat_u16(8); - - /* set the alpha to 255 on the destination surf */ - valphamask = VEC_ALPHA_MASK(); - - vsrcPermute = calc_swizzle32(srcfmt, NULL); - vdstPermute = calc_swizzle32(NULL, dstfmt); - vsdstPermute = calc_swizzle32(dstfmt, NULL); - - /* set a vector full of alpha and 255-alpha */ - ((unsigned char *) &valpha)[0] = sA; - valpha = vec_splat(valpha, 0); - vbits = (vector unsigned char) vec_splat_s8(-1); - - ckey &= rgbmask; - ((unsigned int *) (char *) &vckey)[0] = ckey; - vckey = vec_splat(vckey, 0); - ((unsigned int *) (char *) &vrgbmask)[0] = rgbmask; - vrgbmask = vec_splat(vrgbmask, 0); - - while (height--) { - int width = info->dst_w; -#define ONE_PIXEL_BLEND(condition, widthvar) \ - while (condition) { \ - Uint32 Pixel; \ - unsigned sR, sG, sB, dR, dG, dB; \ - RETRIEVE_RGB_PIXEL(((Uint8 *)srcp), 4, Pixel); \ - if(sA && Pixel != ckey) { \ - RGB_FROM_PIXEL(Pixel, srcfmt, sR, sG, sB); \ - DISEMBLE_RGB(((Uint8 *)dstp), 4, dstfmt, Pixel, dR, dG, dB); \ - ALPHA_BLEND(sR, sG, sB, sA, dR, dG, dB); \ - ASSEMBLE_RGBA(((Uint8 *)dstp), 4, dstfmt, dR, dG, dB, dA); \ - } \ - dstp++; \ - srcp++; \ - widthvar--; \ - } - ONE_PIXEL_BLEND((UNALIGNED_PTR(dstp)) && (width), width); - if (width > 0) { - int extrawidth = (width % 4); - vector unsigned char valigner = VEC_ALIGNER(srcp); - vector unsigned char vs = (vector unsigned char) vec_ld(0, srcp); - width -= extrawidth; - while (width) { - vector unsigned char vsel; - vector unsigned char voverflow; - vector unsigned char vd; - vector unsigned char vd_orig; - - /* s = *srcp */ - voverflow = (vector unsigned char) vec_ld(15, srcp); - vs = vec_perm(vs, voverflow, valigner); - - /* vsel is set for items that match the key */ - vsel = - (vector unsigned char) vec_and((vector unsigned int) vs, - vrgbmask); - vsel = (vector unsigned char) vec_cmpeq((vector unsigned int) - vsel, vckey); - - /* permute to source format */ - vs = vec_perm(vs, valpha, vsrcPermute); - - /* d = *dstp */ - vd = (vector unsigned char) vec_ld(0, dstp); - vd_orig = vd = vec_perm(vd, v0, vsdstPermute); - - VEC_MULTIPLY_ALPHA(vs, vd, valpha, mergePermute, v1, v8); - - /* set the alpha channel to full on */ - vd = vec_or(vd, valphamask); - - /* mask out color key */ - vd = vec_sel(vd, vd_orig, vsel); - - /* permute to dest format */ - vd = vec_perm(vd, vbits, vdstPermute); - - /* *dstp = res */ - vec_st((vector unsigned int) vd, 0, dstp); - - srcp += 4; - dstp += 4; - width -= 4; - vs = voverflow; - } - ONE_PIXEL_BLEND((extrawidth), extrawidth); - } -#undef ONE_PIXEL_BLEND - - srcp += srcskip; - dstp += dstskip; - } -} - - -static void -Blit32to32PixelAlphaAltivec(SDL_BlitInfo * info) -{ - int width = info->dst_w; - int height = info->dst_h; - Uint32 *srcp = (Uint32 *) info->src; - int srcskip = info->src_skip >> 2; - Uint32 *dstp = (Uint32 *) info->dst; - int dstskip = info->dst_skip >> 2; - SDL_PixelFormat *srcfmt = info->src_fmt; - SDL_PixelFormat *dstfmt = info->dst_fmt; - vector unsigned char mergePermute; - vector unsigned char valphaPermute; - vector unsigned char vsrcPermute; - vector unsigned char vdstPermute; - vector unsigned char vsdstPermute; - vector unsigned char valphamask; - vector unsigned char vpixelmask; - vector unsigned char v0; - vector unsigned short v1; - vector unsigned short v8; - - v0 = vec_splat_u8(0); - v1 = vec_splat_u16(1); - v8 = vec_splat_u16(8); - mergePermute = VEC_MERGE_PERMUTE(); - valphamask = VEC_ALPHA_MASK(); - valphaPermute = vec_and(vec_lvsl(0, (int *) NULL), vec_splat_u8(0xC)); - vpixelmask = vec_nor(valphamask, v0); - vsrcPermute = calc_swizzle32(srcfmt, NULL); - vdstPermute = calc_swizzle32(NULL, dstfmt); - vsdstPermute = calc_swizzle32(dstfmt, NULL); - - while (height--) { - width = info->dst_w; -#define ONE_PIXEL_BLEND(condition, widthvar) while ((condition)) { \ - Uint32 Pixel; \ - unsigned sR, sG, sB, dR, dG, dB, sA, dA; \ - DISEMBLE_RGBA((Uint8 *)srcp, 4, srcfmt, Pixel, sR, sG, sB, sA); \ - if(sA) { \ - DISEMBLE_RGBA((Uint8 *)dstp, 4, dstfmt, Pixel, dR, dG, dB, dA); \ - ALPHA_BLEND(sR, sG, sB, sA, dR, dG, dB); \ - ASSEMBLE_RGBA((Uint8 *)dstp, 4, dstfmt, dR, dG, dB, dA); \ - } \ - ++srcp; \ - ++dstp; \ - widthvar--; \ - } - ONE_PIXEL_BLEND((UNALIGNED_PTR(dstp)) && (width), width); - if (width > 0) { - /* vsrcPermute */ - /* vdstPermute */ - int extrawidth = (width % 4); - vector unsigned char valigner = VEC_ALIGNER(srcp); - vector unsigned char vs = (vector unsigned char) vec_ld(0, srcp); - width -= extrawidth; - while (width) { - vector unsigned char voverflow; - vector unsigned char vd; - vector unsigned char valpha; - vector unsigned char vdstalpha; - /* s = *srcp */ - voverflow = (vector unsigned char) vec_ld(15, srcp); - vs = vec_perm(vs, voverflow, valigner); - vs = vec_perm(vs, v0, vsrcPermute); - - valpha = vec_perm(vs, v0, valphaPermute); - - /* d = *dstp */ - vd = (vector unsigned char) vec_ld(0, dstp); - vd = vec_perm(vd, v0, vsdstPermute); - vdstalpha = vec_and(vd, valphamask); - - VEC_MULTIPLY_ALPHA(vs, vd, valpha, mergePermute, v1, v8); - - /* set the alpha to the dest alpha */ - vd = vec_and(vd, vpixelmask); - vd = vec_or(vd, vdstalpha); - vd = vec_perm(vd, v0, vdstPermute); - - /* *dstp = res */ - vec_st((vector unsigned int) vd, 0, dstp); - - srcp += 4; - dstp += 4; - width -= 4; - vs = voverflow; - - } - ONE_PIXEL_BLEND((extrawidth), extrawidth); - } - srcp += srcskip; - dstp += dstskip; -#undef ONE_PIXEL_BLEND - } -} - -/* fast ARGB888->(A)RGB888 blending with pixel alpha */ -static void -BlitRGBtoRGBPixelAlphaAltivec(SDL_BlitInfo * info) -{ - int width = info->dst_w; - int height = info->dst_h; - Uint32 *srcp = (Uint32 *) info->src; - int srcskip = info->src_skip >> 2; - Uint32 *dstp = (Uint32 *) info->dst; - int dstskip = info->dst_skip >> 2; - vector unsigned char mergePermute; - vector unsigned char valphaPermute; - vector unsigned char valphamask; - vector unsigned char vpixelmask; - vector unsigned char v0; - vector unsigned short v1; - vector unsigned short v8; - v0 = vec_splat_u8(0); - v1 = vec_splat_u16(1); - v8 = vec_splat_u16(8); - mergePermute = VEC_MERGE_PERMUTE(); - valphamask = VEC_ALPHA_MASK(); - valphaPermute = vec_and(vec_lvsl(0, (int *) NULL), vec_splat_u8(0xC)); - - - vpixelmask = vec_nor(valphamask, v0); - while (height--) { - width = info->dst_w; -#define ONE_PIXEL_BLEND(condition, widthvar) \ - while ((condition)) { \ - Uint32 dalpha; \ - Uint32 d; \ - Uint32 s1; \ - Uint32 d1; \ - Uint32 s = *srcp; \ - Uint32 alpha = s >> 24; \ - if(alpha) { \ - if(alpha == SDL_ALPHA_OPAQUE) { \ - *dstp = (s & 0x00ffffff) | (*dstp & 0xff000000); \ - } else { \ - d = *dstp; \ - dalpha = d & 0xff000000; \ - s1 = s & 0xff00ff; \ - d1 = d & 0xff00ff; \ - d1 = (d1 + ((s1 - d1) * alpha >> 8)) & 0xff00ff; \ - s &= 0xff00; \ - d &= 0xff00; \ - d = (d + ((s - d) * alpha >> 8)) & 0xff00; \ - *dstp = d1 | d | dalpha; \ - } \ - } \ - ++srcp; \ - ++dstp; \ - widthvar--; \ - } - ONE_PIXEL_BLEND((UNALIGNED_PTR(dstp)) && (width), width); - if (width > 0) { - int extrawidth = (width % 4); - vector unsigned char valigner = VEC_ALIGNER(srcp); - vector unsigned char vs = (vector unsigned char) vec_ld(0, srcp); - width -= extrawidth; - while (width) { - vector unsigned char voverflow; - vector unsigned char vd; - vector unsigned char valpha; - vector unsigned char vdstalpha; - /* s = *srcp */ - voverflow = (vector unsigned char) vec_ld(15, srcp); - vs = vec_perm(vs, voverflow, valigner); - - valpha = vec_perm(vs, v0, valphaPermute); - - /* d = *dstp */ - vd = (vector unsigned char) vec_ld(0, dstp); - vdstalpha = vec_and(vd, valphamask); - - VEC_MULTIPLY_ALPHA(vs, vd, valpha, mergePermute, v1, v8); - - /* set the alpha to the dest alpha */ - vd = vec_and(vd, vpixelmask); - vd = vec_or(vd, vdstalpha); - - /* *dstp = res */ - vec_st((vector unsigned int) vd, 0, dstp); - - srcp += 4; - dstp += 4; - width -= 4; - vs = voverflow; - } - ONE_PIXEL_BLEND((extrawidth), extrawidth); - } - srcp += srcskip; - dstp += dstskip; - } -#undef ONE_PIXEL_BLEND -} - -static void -Blit32to32SurfaceAlphaAltivec(SDL_BlitInfo * info) -{ - /* XXX : 6 */ - int height = info->dst_h; - Uint32 *srcp = (Uint32 *) info->src; - int srcskip = info->src_skip >> 2; - Uint32 *dstp = (Uint32 *) info->dst; - int dstskip = info->dst_skip >> 2; - SDL_PixelFormat *srcfmt = info->src_fmt; - SDL_PixelFormat *dstfmt = info->dst_fmt; - unsigned sA = info->a; - unsigned dA = dstfmt->Amask ? SDL_ALPHA_OPAQUE : 0; - vector unsigned char mergePermute; - vector unsigned char vsrcPermute; - vector unsigned char vdstPermute; - vector unsigned char vsdstPermute; - vector unsigned char valpha; - vector unsigned char valphamask; - vector unsigned char vbits; - vector unsigned short v1; - vector unsigned short v8; - - mergePermute = VEC_MERGE_PERMUTE(); - v1 = vec_splat_u16(1); - v8 = vec_splat_u16(8); - - /* set the alpha to 255 on the destination surf */ - valphamask = VEC_ALPHA_MASK(); - - vsrcPermute = calc_swizzle32(srcfmt, NULL); - vdstPermute = calc_swizzle32(NULL, dstfmt); - vsdstPermute = calc_swizzle32(dstfmt, NULL); - - /* set a vector full of alpha and 255-alpha */ - ((unsigned char *) &valpha)[0] = sA; - valpha = vec_splat(valpha, 0); - vbits = (vector unsigned char) vec_splat_s8(-1); - - while (height--) { - int width = info->dst_w; -#define ONE_PIXEL_BLEND(condition, widthvar) while ((condition)) { \ - Uint32 Pixel; \ - unsigned sR, sG, sB, dR, dG, dB; \ - DISEMBLE_RGB(((Uint8 *)srcp), 4, srcfmt, Pixel, sR, sG, sB); \ - DISEMBLE_RGB(((Uint8 *)dstp), 4, dstfmt, Pixel, dR, dG, dB); \ - ALPHA_BLEND(sR, sG, sB, sA, dR, dG, dB); \ - ASSEMBLE_RGBA(((Uint8 *)dstp), 4, dstfmt, dR, dG, dB, dA); \ - ++srcp; \ - ++dstp; \ - widthvar--; \ - } - ONE_PIXEL_BLEND((UNALIGNED_PTR(dstp)) && (width), width); - if (width > 0) { - int extrawidth = (width % 4); - vector unsigned char valigner = VEC_ALIGNER(srcp); - vector unsigned char vs = (vector unsigned char) vec_ld(0, srcp); - width -= extrawidth; - while (width) { - vector unsigned char voverflow; - vector unsigned char vd; - - /* s = *srcp */ - voverflow = (vector unsigned char) vec_ld(15, srcp); - vs = vec_perm(vs, voverflow, valigner); - vs = vec_perm(vs, valpha, vsrcPermute); - - /* d = *dstp */ - vd = (vector unsigned char) vec_ld(0, dstp); - vd = vec_perm(vd, vd, vsdstPermute); - - VEC_MULTIPLY_ALPHA(vs, vd, valpha, mergePermute, v1, v8); - - /* set the alpha channel to full on */ - vd = vec_or(vd, valphamask); - vd = vec_perm(vd, vbits, vdstPermute); - - /* *dstp = res */ - vec_st((vector unsigned int) vd, 0, dstp); - - srcp += 4; - dstp += 4; - width -= 4; - vs = voverflow; - } - ONE_PIXEL_BLEND((extrawidth), extrawidth); - } -#undef ONE_PIXEL_BLEND - - srcp += srcskip; - dstp += dstskip; - } - -} - - -/* fast RGB888->(A)RGB888 blending */ -static void -BlitRGBtoRGBSurfaceAlphaAltivec(SDL_BlitInfo * info) -{ - unsigned alpha = info->a; - int height = info->dst_h; - Uint32 *srcp = (Uint32 *) info->src; - int srcskip = info->src_skip >> 2; - Uint32 *dstp = (Uint32 *) info->dst; - int dstskip = info->dst_skip >> 2; - vector unsigned char mergePermute; - vector unsigned char valpha; - vector unsigned char valphamask; - vector unsigned short v1; - vector unsigned short v8; - - mergePermute = VEC_MERGE_PERMUTE(); - v1 = vec_splat_u16(1); - v8 = vec_splat_u16(8); - - /* set the alpha to 255 on the destination surf */ - valphamask = VEC_ALPHA_MASK(); - - /* set a vector full of alpha and 255-alpha */ - ((unsigned char *) &valpha)[0] = alpha; - valpha = vec_splat(valpha, 0); - - while (height--) { - int width = info->dst_w; -#define ONE_PIXEL_BLEND(condition, widthvar) while ((condition)) { \ - Uint32 s = *srcp; \ - Uint32 d = *dstp; \ - Uint32 s1 = s & 0xff00ff; \ - Uint32 d1 = d & 0xff00ff; \ - d1 = (d1 + ((s1 - d1) * alpha >> 8)) \ - & 0xff00ff; \ - s &= 0xff00; \ - d &= 0xff00; \ - d = (d + ((s - d) * alpha >> 8)) & 0xff00; \ - *dstp = d1 | d | 0xff000000; \ - ++srcp; \ - ++dstp; \ - widthvar--; \ - } - ONE_PIXEL_BLEND((UNALIGNED_PTR(dstp)) && (width), width); - if (width > 0) { - int extrawidth = (width % 4); - vector unsigned char valigner = VEC_ALIGNER(srcp); - vector unsigned char vs = (vector unsigned char) vec_ld(0, srcp); - width -= extrawidth; - while (width) { - vector unsigned char voverflow; - vector unsigned char vd; - - /* s = *srcp */ - voverflow = (vector unsigned char) vec_ld(15, srcp); - vs = vec_perm(vs, voverflow, valigner); - - /* d = *dstp */ - vd = (vector unsigned char) vec_ld(0, dstp); - - VEC_MULTIPLY_ALPHA(vs, vd, valpha, mergePermute, v1, v8); - - /* set the alpha channel to full on */ - vd = vec_or(vd, valphamask); - - /* *dstp = res */ - vec_st((vector unsigned int) vd, 0, dstp); - - srcp += 4; - dstp += 4; - width -= 4; - vs = voverflow; - } - ONE_PIXEL_BLEND((extrawidth), extrawidth); - } -#undef ONE_PIXEL_BLEND - - srcp += srcskip; - dstp += dstskip; - } -} - -#if __MWERKS__ -#pragma altivec_model off -#endif -#endif /* SDL_ALTIVEC_BLITTERS */ - -/* fast RGB888->(A)RGB888 blending with surface alpha=128 special case */ -static void -BlitRGBtoRGBSurfaceAlpha128(SDL_BlitInfo * info) -{ - int width = info->dst_w; - int height = info->dst_h; - Uint32 *srcp = (Uint32 *) info->src; - int srcskip = info->src_skip >> 2; - Uint32 *dstp = (Uint32 *) info->dst; - int dstskip = info->dst_skip >> 2; - - while (height--) { - /* *INDENT-OFF* */ - DUFFS_LOOP4({ - Uint32 s = *srcp++; - Uint32 d = *dstp; - *dstp++ = ((((s & 0x00fefefe) + (d & 0x00fefefe)) >> 1) - + (s & d & 0x00010101)) | 0xff000000; - }, width); - /* *INDENT-ON* */ - srcp += srcskip; - dstp += dstskip; - } -} - -/* fast RGB888->(A)RGB888 blending with surface alpha */ -static void -BlitRGBtoRGBSurfaceAlpha(SDL_BlitInfo * info) -{ - unsigned alpha = info->a; - if (alpha == 128) { - BlitRGBtoRGBSurfaceAlpha128(info); - } else { - int width = info->dst_w; - int height = info->dst_h; - Uint32 *srcp = (Uint32 *) info->src; - int srcskip = info->src_skip >> 2; - Uint32 *dstp = (Uint32 *) info->dst; - int dstskip = info->dst_skip >> 2; - Uint32 s; - Uint32 d; - Uint32 s1; - Uint32 d1; - - while (height--) { - /* *INDENT-OFF* */ - DUFFS_LOOP4({ - s = *srcp; - d = *dstp; - s1 = s & 0xff00ff; - d1 = d & 0xff00ff; - d1 = (d1 + ((s1 - d1) * alpha >> 8)) - & 0xff00ff; - s &= 0xff00; - d &= 0xff00; - d = (d + ((s - d) * alpha >> 8)) & 0xff00; - *dstp = d1 | d | 0xff000000; - ++srcp; - ++dstp; - }, width); - /* *INDENT-ON* */ - srcp += srcskip; - dstp += dstskip; - } - } -} - -/* fast ARGB888->(A)RGB888 blending with pixel alpha */ -static void -BlitRGBtoRGBPixelAlpha(SDL_BlitInfo * info) -{ - int width = info->dst_w; - int height = info->dst_h; - Uint32 *srcp = (Uint32 *) info->src; - int srcskip = info->src_skip >> 2; - Uint32 *dstp = (Uint32 *) info->dst; - int dstskip = info->dst_skip >> 2; - - while (height--) { - /* *INDENT-OFF* */ - DUFFS_LOOP4({ - Uint32 dalpha; - Uint32 d; - Uint32 s1; - Uint32 d1; - Uint32 s = *srcp; - Uint32 alpha = s >> 24; - /* FIXME: Here we special-case opaque alpha since the - compositioning used (>>8 instead of /255) doesn't handle - it correctly. Also special-case alpha=0 for speed? - Benchmark this! */ - if(alpha) { - if(alpha == SDL_ALPHA_OPAQUE) { - *dstp = (s & 0x00ffffff) | (*dstp & 0xff000000); - } else { - /* - * take out the middle component (green), and process - * the other two in parallel. One multiply less. - */ - d = *dstp; - dalpha = d & 0xff000000; - s1 = s & 0xff00ff; - d1 = d & 0xff00ff; - d1 = (d1 + ((s1 - d1) * alpha >> 8)) & 0xff00ff; - s &= 0xff00; - d &= 0xff00; - d = (d + ((s - d) * alpha >> 8)) & 0xff00; - *dstp = d1 | d | dalpha; - } - } - ++srcp; - ++dstp; - }, width); - /* *INDENT-ON* */ - srcp += srcskip; - dstp += dstskip; - } -} - -#ifdef __3dNOW__ -/* fast (as in MMX with prefetch) ARGB888->(A)RGB888 blending with pixel alpha */ -static void -BlitRGBtoRGBPixelAlphaMMX3DNOW(SDL_BlitInfo * info) -{ - int width = info->dst_w; - int height = info->dst_h; - Uint32 *srcp = (Uint32 *) info->src; - int srcskip = info->src_skip >> 2; - Uint32 *dstp = (Uint32 *) info->dst; - int dstskip = info->dst_skip >> 2; - SDL_PixelFormat *sf = info->src_fmt; - Uint32 chanmask = sf->Rmask | sf->Gmask | sf->Bmask; - Uint32 amask = sf->Amask; - Uint32 ashift = sf->Ashift; - Uint64 multmask; - - __m64 src1, dst1, mm_alpha, mm_zero, dmask; - - mm_zero = _mm_setzero_si64(); /* 0 -> mm_zero */ - multmask = 0xFFFF; - multmask <<= (ashift * 2); - multmask = ~multmask; - dmask = *(__m64 *) & multmask; /* dst alpha mask -> dmask */ - - while (height--) { - /* *INDENT-OFF* */ - DUFFS_LOOP4({ - Uint32 alpha; - - _m_prefetch(srcp + 16); - _m_prefetch(dstp + 16); - - alpha = *srcp & amask; - if (alpha == 0) { - /* do nothing */ - } else if (alpha == amask) { - /* copy RGB, keep dst alpha */ - *dstp = (*srcp & chanmask) | (*dstp & ~chanmask); - } else { - src1 = _mm_cvtsi32_si64(*srcp); /* src(ARGB) -> src1 (0000ARGB)*/ - src1 = _mm_unpacklo_pi8(src1, mm_zero); /* 0A0R0G0B -> src1 */ - - dst1 = _mm_cvtsi32_si64(*dstp); /* dst(ARGB) -> dst1 (0000ARGB)*/ - dst1 = _mm_unpacklo_pi8(dst1, mm_zero); /* 0A0R0G0B -> dst1 */ - - mm_alpha = _mm_cvtsi32_si64(alpha); /* alpha -> mm_alpha (0000000A) */ - mm_alpha = _mm_srli_si64(mm_alpha, ashift); /* mm_alpha >> ashift -> mm_alpha(0000000A) */ - mm_alpha = _mm_unpacklo_pi16(mm_alpha, mm_alpha); /* 00000A0A -> mm_alpha */ - mm_alpha = _mm_unpacklo_pi32(mm_alpha, mm_alpha); /* 0A0A0A0A -> mm_alpha */ - mm_alpha = _mm_and_si64(mm_alpha, dmask); /* 000A0A0A -> mm_alpha, preserve dst alpha on add */ - - /* blend */ - src1 = _mm_sub_pi16(src1, dst1);/* src - dst -> src1 */ - src1 = _mm_mullo_pi16(src1, mm_alpha); /* (src - dst) * alpha -> src1 */ - src1 = _mm_srli_pi16(src1, 8); /* src1 >> 8 -> src1(000R0G0B) */ - dst1 = _mm_add_pi8(src1, dst1); /* src1 + dst1(dst) -> dst1(0A0R0G0B) */ - dst1 = _mm_packs_pu16(dst1, mm_zero); /* 0000ARGB -> dst1 */ - - *dstp = _mm_cvtsi64_si32(dst1); /* dst1 -> pixel */ - } - ++srcp; - ++dstp; - }, width); - /* *INDENT-ON* */ - srcp += srcskip; - dstp += dstskip; - } - _mm_empty(); -} - -#endif /* __MMX__ */ - -/* 16bpp special case for per-surface alpha=50%: blend 2 pixels in parallel */ - -/* blend a single 16 bit pixel at 50% */ -#define BLEND16_50(d, s, mask) \ - ((((s & mask) + (d & mask)) >> 1) + (s & d & (~mask & 0xffff))) - -/* blend two 16 bit pixels at 50% */ -#define BLEND2x16_50(d, s, mask) \ - (((s & (mask | mask << 16)) >> 1) + ((d & (mask | mask << 16)) >> 1) \ - + (s & d & (~(mask | mask << 16)))) - -static void -Blit16to16SurfaceAlpha128(SDL_BlitInfo * info, Uint16 mask) -{ - int width = info->dst_w; - int height = info->dst_h; - Uint16 *srcp = (Uint16 *) info->src; - int srcskip = info->src_skip >> 1; - Uint16 *dstp = (Uint16 *) info->dst; - int dstskip = info->dst_skip >> 1; - - while (height--) { - if (((uintptr_t) srcp ^ (uintptr_t) dstp) & 2) { - /* - * Source and destination not aligned, pipeline it. - * This is mostly a win for big blits but no loss for - * small ones - */ - Uint32 prev_sw; - int w = width; - - /* handle odd destination */ - if ((uintptr_t) dstp & 2) { - Uint16 d = *dstp, s = *srcp; - *dstp = BLEND16_50(d, s, mask); - dstp++; - srcp++; - w--; - } - srcp++; /* srcp is now 32-bit aligned */ - - /* bootstrap pipeline with first halfword */ - prev_sw = ((Uint32 *) srcp)[-1]; - - while (w > 1) { - Uint32 sw, dw, s; - sw = *(Uint32 *) srcp; - dw = *(Uint32 *) dstp; -#if SDL_BYTEORDER == SDL_BIG_ENDIAN - s = (prev_sw << 16) + (sw >> 16); -#else - s = (prev_sw >> 16) + (sw << 16); -#endif - prev_sw = sw; - *(Uint32 *) dstp = BLEND2x16_50(dw, s, mask); - dstp += 2; - srcp += 2; - w -= 2; - } - - /* final pixel if any */ - if (w) { - Uint16 d = *dstp, s; -#if SDL_BYTEORDER == SDL_BIG_ENDIAN - s = (Uint16) prev_sw; -#else - s = (Uint16) (prev_sw >> 16); -#endif - *dstp = BLEND16_50(d, s, mask); - srcp++; - dstp++; - } - srcp += srcskip - 1; - dstp += dstskip; - } else { - /* source and destination are aligned */ - int w = width; - - /* first odd pixel? */ - if ((uintptr_t) srcp & 2) { - Uint16 d = *dstp, s = *srcp; - *dstp = BLEND16_50(d, s, mask); - srcp++; - dstp++; - w--; - } - /* srcp and dstp are now 32-bit aligned */ - - while (w > 1) { - Uint32 sw = *(Uint32 *) srcp; - Uint32 dw = *(Uint32 *) dstp; - *(Uint32 *) dstp = BLEND2x16_50(dw, sw, mask); - srcp += 2; - dstp += 2; - w -= 2; - } - - /* last odd pixel? */ - if (w) { - Uint16 d = *dstp, s = *srcp; - *dstp = BLEND16_50(d, s, mask); - srcp++; - dstp++; - } - srcp += srcskip; - dstp += dstskip; - } - } -} - -#ifdef __MMX__ - -/* fast RGB565->RGB565 blending with surface alpha */ -static void -Blit565to565SurfaceAlphaMMX(SDL_BlitInfo * info) -{ - unsigned alpha = info->a; - if (alpha == 128) { - Blit16to16SurfaceAlpha128(info, 0xf7de); - } else { - int width = info->dst_w; - int height = info->dst_h; - Uint16 *srcp = (Uint16 *) info->src; - int srcskip = info->src_skip >> 1; - Uint16 *dstp = (Uint16 *) info->dst; - int dstskip = info->dst_skip >> 1; - Uint32 s, d; - - __m64 src1, dst1, src2, dst2, gmask, bmask, mm_res, mm_alpha; - - alpha &= ~(1 + 2 + 4); /* cut alpha to get the exact same behaviour */ - mm_alpha = _mm_set_pi32(0, alpha); /* 0000000A -> mm_alpha */ - alpha >>= 3; /* downscale alpha to 5 bits */ - - mm_alpha = _mm_unpacklo_pi16(mm_alpha, mm_alpha); /* 00000A0A -> mm_alpha */ - mm_alpha = _mm_unpacklo_pi32(mm_alpha, mm_alpha); /* 0A0A0A0A -> mm_alpha */ - /* position alpha to allow for mullo and mulhi on diff channels - to reduce the number of operations */ - mm_alpha = _mm_slli_si64(mm_alpha, 3); - - /* Setup the 565 color channel masks */ - gmask = _mm_set_pi32(0x07E007E0, 0x07E007E0); /* MASKGREEN -> gmask */ - bmask = _mm_set_pi32(0x001F001F, 0x001F001F); /* MASKBLUE -> bmask */ - - while (height--) { - /* *INDENT-OFF* */ - DUFFS_LOOP_124( - { - s = *srcp++; - d = *dstp; - /* - * shift out the middle component (green) to - * the high 16 bits, and process all three RGB - * components at the same time. - */ - s = (s | s << 16) & 0x07e0f81f; - d = (d | d << 16) & 0x07e0f81f; - d += (s - d) * alpha >> 5; - d &= 0x07e0f81f; - *dstp++ = (Uint16)(d | d >> 16); - },{ - s = *srcp++; - d = *dstp; - /* - * shift out the middle component (green) to - * the high 16 bits, and process all three RGB - * components at the same time. - */ - s = (s | s << 16) & 0x07e0f81f; - d = (d | d << 16) & 0x07e0f81f; - d += (s - d) * alpha >> 5; - d &= 0x07e0f81f; - *dstp++ = (Uint16)(d | d >> 16); - s = *srcp++; - d = *dstp; - /* - * shift out the middle component (green) to - * the high 16 bits, and process all three RGB - * components at the same time. - */ - s = (s | s << 16) & 0x07e0f81f; - d = (d | d << 16) & 0x07e0f81f; - d += (s - d) * alpha >> 5; - d &= 0x07e0f81f; - *dstp++ = (Uint16)(d | d >> 16); - },{ - src1 = *(__m64*)srcp; /* 4 src pixels -> src1 */ - dst1 = *(__m64*)dstp; /* 4 dst pixels -> dst1 */ - - /* red */ - src2 = src1; - src2 = _mm_srli_pi16(src2, 11); /* src2 >> 11 -> src2 [000r 000r 000r 000r] */ - - dst2 = dst1; - dst2 = _mm_srli_pi16(dst2, 11); /* dst2 >> 11 -> dst2 [000r 000r 000r 000r] */ - - /* blend */ - src2 = _mm_sub_pi16(src2, dst2);/* src - dst -> src2 */ - src2 = _mm_mullo_pi16(src2, mm_alpha); /* src2 * alpha -> src2 */ - src2 = _mm_srli_pi16(src2, 11); /* src2 >> 11 -> src2 */ - dst2 = _mm_add_pi16(src2, dst2); /* src2 + dst2 -> dst2 */ - dst2 = _mm_slli_pi16(dst2, 11); /* dst2 << 11 -> dst2 */ - - mm_res = dst2; /* RED -> mm_res */ - - /* green -- process the bits in place */ - src2 = src1; - src2 = _mm_and_si64(src2, gmask); /* src & MASKGREEN -> src2 */ - - dst2 = dst1; - dst2 = _mm_and_si64(dst2, gmask); /* dst & MASKGREEN -> dst2 */ - - /* blend */ - src2 = _mm_sub_pi16(src2, dst2);/* src - dst -> src2 */ - src2 = _mm_mulhi_pi16(src2, mm_alpha); /* src2 * alpha -> src2 */ - src2 = _mm_slli_pi16(src2, 5); /* src2 << 5 -> src2 */ - dst2 = _mm_add_pi16(src2, dst2); /* src2 + dst2 -> dst2 */ - - mm_res = _mm_or_si64(mm_res, dst2); /* RED | GREEN -> mm_res */ - - /* blue */ - src2 = src1; - src2 = _mm_and_si64(src2, bmask); /* src & MASKBLUE -> src2[000b 000b 000b 000b] */ - - dst2 = dst1; - dst2 = _mm_and_si64(dst2, bmask); /* dst & MASKBLUE -> dst2[000b 000b 000b 000b] */ - - /* blend */ - src2 = _mm_sub_pi16(src2, dst2);/* src - dst -> src2 */ - src2 = _mm_mullo_pi16(src2, mm_alpha); /* src2 * alpha -> src2 */ - src2 = _mm_srli_pi16(src2, 11); /* src2 >> 11 -> src2 */ - dst2 = _mm_add_pi16(src2, dst2); /* src2 + dst2 -> dst2 */ - dst2 = _mm_and_si64(dst2, bmask); /* dst2 & MASKBLUE -> dst2 */ - - mm_res = _mm_or_si64(mm_res, dst2); /* RED | GREEN | BLUE -> mm_res */ - - *(__m64*)dstp = mm_res; /* mm_res -> 4 dst pixels */ - - srcp += 4; - dstp += 4; - }, width); - /* *INDENT-ON* */ - srcp += srcskip; - dstp += dstskip; - } - _mm_empty(); - } -} - -/* fast RGB555->RGB555 blending with surface alpha */ -static void -Blit555to555SurfaceAlphaMMX(SDL_BlitInfo * info) -{ - unsigned alpha = info->a; - if (alpha == 128) { - Blit16to16SurfaceAlpha128(info, 0xfbde); - } else { - int width = info->dst_w; - int height = info->dst_h; - Uint16 *srcp = (Uint16 *) info->src; - int srcskip = info->src_skip >> 1; - Uint16 *dstp = (Uint16 *) info->dst; - int dstskip = info->dst_skip >> 1; - Uint32 s, d; - - __m64 src1, dst1, src2, dst2, rmask, gmask, bmask, mm_res, mm_alpha; - - alpha &= ~(1 + 2 + 4); /* cut alpha to get the exact same behaviour */ - mm_alpha = _mm_set_pi32(0, alpha); /* 0000000A -> mm_alpha */ - alpha >>= 3; /* downscale alpha to 5 bits */ - - mm_alpha = _mm_unpacklo_pi16(mm_alpha, mm_alpha); /* 00000A0A -> mm_alpha */ - mm_alpha = _mm_unpacklo_pi32(mm_alpha, mm_alpha); /* 0A0A0A0A -> mm_alpha */ - /* position alpha to allow for mullo and mulhi on diff channels - to reduce the number of operations */ - mm_alpha = _mm_slli_si64(mm_alpha, 3); - - /* Setup the 555 color channel masks */ - rmask = _mm_set_pi32(0x7C007C00, 0x7C007C00); /* MASKRED -> rmask */ - gmask = _mm_set_pi32(0x03E003E0, 0x03E003E0); /* MASKGREEN -> gmask */ - bmask = _mm_set_pi32(0x001F001F, 0x001F001F); /* MASKBLUE -> bmask */ - - while (height--) { - /* *INDENT-OFF* */ - DUFFS_LOOP_124( - { - s = *srcp++; - d = *dstp; - /* - * shift out the middle component (green) to - * the high 16 bits, and process all three RGB - * components at the same time. - */ - s = (s | s << 16) & 0x03e07c1f; - d = (d | d << 16) & 0x03e07c1f; - d += (s - d) * alpha >> 5; - d &= 0x03e07c1f; - *dstp++ = (Uint16)(d | d >> 16); - },{ - s = *srcp++; - d = *dstp; - /* - * shift out the middle component (green) to - * the high 16 bits, and process all three RGB - * components at the same time. - */ - s = (s | s << 16) & 0x03e07c1f; - d = (d | d << 16) & 0x03e07c1f; - d += (s - d) * alpha >> 5; - d &= 0x03e07c1f; - *dstp++ = (Uint16)(d | d >> 16); - s = *srcp++; - d = *dstp; - /* - * shift out the middle component (green) to - * the high 16 bits, and process all three RGB - * components at the same time. - */ - s = (s | s << 16) & 0x03e07c1f; - d = (d | d << 16) & 0x03e07c1f; - d += (s - d) * alpha >> 5; - d &= 0x03e07c1f; - *dstp++ = (Uint16)(d | d >> 16); - },{ - src1 = *(__m64*)srcp; /* 4 src pixels -> src1 */ - dst1 = *(__m64*)dstp; /* 4 dst pixels -> dst1 */ - - /* red -- process the bits in place */ - src2 = src1; - src2 = _mm_and_si64(src2, rmask); /* src & MASKRED -> src2 */ - - dst2 = dst1; - dst2 = _mm_and_si64(dst2, rmask); /* dst & MASKRED -> dst2 */ - - /* blend */ - src2 = _mm_sub_pi16(src2, dst2);/* src - dst -> src2 */ - src2 = _mm_mulhi_pi16(src2, mm_alpha); /* src2 * alpha -> src2 */ - src2 = _mm_slli_pi16(src2, 5); /* src2 << 5 -> src2 */ - dst2 = _mm_add_pi16(src2, dst2); /* src2 + dst2 -> dst2 */ - dst2 = _mm_and_si64(dst2, rmask); /* dst2 & MASKRED -> dst2 */ - - mm_res = dst2; /* RED -> mm_res */ - - /* green -- process the bits in place */ - src2 = src1; - src2 = _mm_and_si64(src2, gmask); /* src & MASKGREEN -> src2 */ - - dst2 = dst1; - dst2 = _mm_and_si64(dst2, gmask); /* dst & MASKGREEN -> dst2 */ - - /* blend */ - src2 = _mm_sub_pi16(src2, dst2);/* src - dst -> src2 */ - src2 = _mm_mulhi_pi16(src2, mm_alpha); /* src2 * alpha -> src2 */ - src2 = _mm_slli_pi16(src2, 5); /* src2 << 5 -> src2 */ - dst2 = _mm_add_pi16(src2, dst2); /* src2 + dst2 -> dst2 */ - - mm_res = _mm_or_si64(mm_res, dst2); /* RED | GREEN -> mm_res */ - - /* blue */ - src2 = src1; /* src -> src2 */ - src2 = _mm_and_si64(src2, bmask); /* src & MASKBLUE -> src2[000b 000b 000b 000b] */ - - dst2 = dst1; /* dst -> dst2 */ - dst2 = _mm_and_si64(dst2, bmask); /* dst & MASKBLUE -> dst2[000b 000b 000b 000b] */ - - /* blend */ - src2 = _mm_sub_pi16(src2, dst2);/* src - dst -> src2 */ - src2 = _mm_mullo_pi16(src2, mm_alpha); /* src2 * alpha -> src2 */ - src2 = _mm_srli_pi16(src2, 11); /* src2 >> 11 -> src2 */ - dst2 = _mm_add_pi16(src2, dst2); /* src2 + dst2 -> dst2 */ - dst2 = _mm_and_si64(dst2, bmask); /* dst2 & MASKBLUE -> dst2 */ - - mm_res = _mm_or_si64(mm_res, dst2); /* RED | GREEN | BLUE -> mm_res */ - - *(__m64*)dstp = mm_res; /* mm_res -> 4 dst pixels */ - - srcp += 4; - dstp += 4; - }, width); - /* *INDENT-ON* */ - srcp += srcskip; - dstp += dstskip; - } - _mm_empty(); - } -} - -#endif /* __MMX__ */ - -/* fast RGB565->RGB565 blending with surface alpha */ -static void -Blit565to565SurfaceAlpha(SDL_BlitInfo * info) -{ - unsigned alpha = info->a; - if (alpha == 128) { - Blit16to16SurfaceAlpha128(info, 0xf7de); - } else { - int width = info->dst_w; - int height = info->dst_h; - Uint16 *srcp = (Uint16 *) info->src; - int srcskip = info->src_skip >> 1; - Uint16 *dstp = (Uint16 *) info->dst; - int dstskip = info->dst_skip >> 1; - alpha >>= 3; /* downscale alpha to 5 bits */ - - while (height--) { - /* *INDENT-OFF* */ - DUFFS_LOOP4({ - Uint32 s = *srcp++; - Uint32 d = *dstp; - /* - * shift out the middle component (green) to - * the high 16 bits, and process all three RGB - * components at the same time. - */ - s = (s | s << 16) & 0x07e0f81f; - d = (d | d << 16) & 0x07e0f81f; - d += (s - d) * alpha >> 5; - d &= 0x07e0f81f; - *dstp++ = (Uint16)(d | d >> 16); - }, width); - /* *INDENT-ON* */ - srcp += srcskip; - dstp += dstskip; - } - } -} - -/* fast RGB555->RGB555 blending with surface alpha */ -static void -Blit555to555SurfaceAlpha(SDL_BlitInfo * info) -{ - unsigned alpha = info->a; /* downscale alpha to 5 bits */ - if (alpha == 128) { - Blit16to16SurfaceAlpha128(info, 0xfbde); - } else { - int width = info->dst_w; - int height = info->dst_h; - Uint16 *srcp = (Uint16 *) info->src; - int srcskip = info->src_skip >> 1; - Uint16 *dstp = (Uint16 *) info->dst; - int dstskip = info->dst_skip >> 1; - alpha >>= 3; /* downscale alpha to 5 bits */ - - while (height--) { - /* *INDENT-OFF* */ - DUFFS_LOOP4({ - Uint32 s = *srcp++; - Uint32 d = *dstp; - /* - * shift out the middle component (green) to - * the high 16 bits, and process all three RGB - * components at the same time. - */ - s = (s | s << 16) & 0x03e07c1f; - d = (d | d << 16) & 0x03e07c1f; - d += (s - d) * alpha >> 5; - d &= 0x03e07c1f; - *dstp++ = (Uint16)(d | d >> 16); - }, width); - /* *INDENT-ON* */ - srcp += srcskip; - dstp += dstskip; - } - } -} - -/* fast ARGB8888->RGB565 blending with pixel alpha */ -static void -BlitARGBto565PixelAlpha(SDL_BlitInfo * info) -{ - int width = info->dst_w; - int height = info->dst_h; - Uint32 *srcp = (Uint32 *) info->src; - int srcskip = info->src_skip >> 2; - Uint16 *dstp = (Uint16 *) info->dst; - int dstskip = info->dst_skip >> 1; - - while (height--) { - /* *INDENT-OFF* */ - DUFFS_LOOP4({ - Uint32 s = *srcp; - unsigned alpha = s >> 27; /* downscale alpha to 5 bits */ - /* FIXME: Here we special-case opaque alpha since the - compositioning used (>>8 instead of /255) doesn't handle - it correctly. Also special-case alpha=0 for speed? - Benchmark this! */ - if(alpha) { - if(alpha == (SDL_ALPHA_OPAQUE >> 3)) { - *dstp = (Uint16)((s >> 8 & 0xf800) + (s >> 5 & 0x7e0) + (s >> 3 & 0x1f)); - } else { - Uint32 d = *dstp; - /* - * convert source and destination to G0RAB65565 - * and blend all components at the same time - */ - s = ((s & 0xfc00) << 11) + (s >> 8 & 0xf800) - + (s >> 3 & 0x1f); - d = (d | d << 16) & 0x07e0f81f; - d += (s - d) * alpha >> 5; - d &= 0x07e0f81f; - *dstp = (Uint16)(d | d >> 16); - } - } - srcp++; - dstp++; - }, width); - /* *INDENT-ON* */ - srcp += srcskip; - dstp += dstskip; - } -} - -/* fast ARGB8888->RGB555 blending with pixel alpha */ -static void -BlitARGBto555PixelAlpha(SDL_BlitInfo * info) -{ - int width = info->dst_w; - int height = info->dst_h; - Uint32 *srcp = (Uint32 *) info->src; - int srcskip = info->src_skip >> 2; - Uint16 *dstp = (Uint16 *) info->dst; - int dstskip = info->dst_skip >> 1; - - while (height--) { - /* *INDENT-OFF* */ - DUFFS_LOOP4({ - unsigned alpha; - Uint32 s = *srcp; - alpha = s >> 27; /* downscale alpha to 5 bits */ - /* FIXME: Here we special-case opaque alpha since the - compositioning used (>>8 instead of /255) doesn't handle - it correctly. Also special-case alpha=0 for speed? - Benchmark this! */ - if(alpha) { - if(alpha == (SDL_ALPHA_OPAQUE >> 3)) { - *dstp = (Uint16)((s >> 9 & 0x7c00) + (s >> 6 & 0x3e0) + (s >> 3 & 0x1f)); - } else { - Uint32 d = *dstp; - /* - * convert source and destination to G0RAB65565 - * and blend all components at the same time - */ - s = ((s & 0xf800) << 10) + (s >> 9 & 0x7c00) - + (s >> 3 & 0x1f); - d = (d | d << 16) & 0x03e07c1f; - d += (s - d) * alpha >> 5; - d &= 0x03e07c1f; - *dstp = (Uint16)(d | d >> 16); - } - } - srcp++; - dstp++; - }, width); - /* *INDENT-ON* */ - srcp += srcskip; - dstp += dstskip; - } -} - -/* General (slow) N->N blending with per-surface alpha */ -static void -BlitNtoNSurfaceAlpha(SDL_BlitInfo * info) -{ - int width = info->dst_w; - int height = info->dst_h; - Uint8 *src = info->src; - int srcskip = info->src_skip; - Uint8 *dst = info->dst; - int dstskip = info->dst_skip; - SDL_PixelFormat *srcfmt = info->src_fmt; - SDL_PixelFormat *dstfmt = info->dst_fmt; - int srcbpp = srcfmt->BytesPerPixel; - int dstbpp = dstfmt->BytesPerPixel; - unsigned sA = info->a; - unsigned dA = dstfmt->Amask ? SDL_ALPHA_OPAQUE : 0; - - if (sA) { - while (height--) { - /* *INDENT-OFF* */ - DUFFS_LOOP4( - { - Uint32 Pixel; - unsigned sR; - unsigned sG; - unsigned sB; - unsigned dR; - unsigned dG; - unsigned dB; - DISEMBLE_RGB(src, srcbpp, srcfmt, Pixel, sR, sG, sB); - DISEMBLE_RGB(dst, dstbpp, dstfmt, Pixel, dR, dG, dB); - ALPHA_BLEND(sR, sG, sB, sA, dR, dG, dB); - ASSEMBLE_RGBA(dst, dstbpp, dstfmt, dR, dG, dB, dA); - src += srcbpp; - dst += dstbpp; - }, - width); - /* *INDENT-ON* */ - src += srcskip; - dst += dstskip; - } - } -} - -/* General (slow) colorkeyed N->N blending with per-surface alpha */ -static void -BlitNtoNSurfaceAlphaKey(SDL_BlitInfo * info) -{ - int width = info->dst_w; - int height = info->dst_h; - Uint8 *src = info->src; - int srcskip = info->src_skip; - Uint8 *dst = info->dst; - int dstskip = info->dst_skip; - SDL_PixelFormat *srcfmt = info->src_fmt; - SDL_PixelFormat *dstfmt = info->dst_fmt; - Uint32 ckey = info->colorkey; - int srcbpp = srcfmt->BytesPerPixel; - int dstbpp = dstfmt->BytesPerPixel; - unsigned sA = info->a; - unsigned dA = dstfmt->Amask ? SDL_ALPHA_OPAQUE : 0; - - while (height--) { - /* *INDENT-OFF* */ - DUFFS_LOOP4( - { - Uint32 Pixel; - unsigned sR; - unsigned sG; - unsigned sB; - unsigned dR; - unsigned dG; - unsigned dB; - RETRIEVE_RGB_PIXEL(src, srcbpp, Pixel); - if(sA && Pixel != ckey) { - RGB_FROM_PIXEL(Pixel, srcfmt, sR, sG, sB); - DISEMBLE_RGB(dst, dstbpp, dstfmt, Pixel, dR, dG, dB); - ALPHA_BLEND(sR, sG, sB, sA, dR, dG, dB); - ASSEMBLE_RGBA(dst, dstbpp, dstfmt, dR, dG, dB, dA); - } - src += srcbpp; - dst += dstbpp; - }, - width); - /* *INDENT-ON* */ - src += srcskip; - dst += dstskip; - } -} - -/* General (slow) N->N blending with pixel alpha */ -static void -BlitNtoNPixelAlpha(SDL_BlitInfo * info) -{ - int width = info->dst_w; - int height = info->dst_h; - Uint8 *src = info->src; - int srcskip = info->src_skip; - Uint8 *dst = info->dst; - int dstskip = info->dst_skip; - SDL_PixelFormat *srcfmt = info->src_fmt; - SDL_PixelFormat *dstfmt = info->dst_fmt; - - int srcbpp; - int dstbpp; - - /* Set up some basic variables */ - srcbpp = srcfmt->BytesPerPixel; - dstbpp = dstfmt->BytesPerPixel; - - while (height--) { - /* *INDENT-OFF* */ - DUFFS_LOOP4( - { - Uint32 Pixel; - unsigned sR; - unsigned sG; - unsigned sB; - unsigned dR; - unsigned dG; - unsigned dB; - unsigned sA; - unsigned dA; - DISEMBLE_RGBA(src, srcbpp, srcfmt, Pixel, sR, sG, sB, sA); - if(sA) { - DISEMBLE_RGBA(dst, dstbpp, dstfmt, Pixel, dR, dG, dB, dA); - ALPHA_BLEND(sR, sG, sB, sA, dR, dG, dB); - ASSEMBLE_RGBA(dst, dstbpp, dstfmt, dR, dG, dB, dA); - } - src += srcbpp; - dst += dstbpp; - }, - width); - /* *INDENT-ON* */ - src += srcskip; - dst += dstskip; - } -} - - -SDL_BlitFunc -SDL_CalculateBlitA(SDL_Surface * surface) -{ - SDL_PixelFormat *sf = surface->format; - SDL_PixelFormat *df = surface->map->dst->format; - - switch (surface->map->info.flags & ~SDL_COPY_RLE_MASK) { - case SDL_COPY_BLEND: - /* Per-pixel alpha blits */ - switch (df->BytesPerPixel) { - case 1: - return BlitNto1PixelAlpha; - - case 2: -#if SDL_ALTIVEC_BLITTERS - if (sf->BytesPerPixel == 4 - && df->Gmask == 0x7e0 && df->Bmask == 0x1f - && SDL_HasAltiVec()) - return Blit32to565PixelAlphaAltivec; - else -#endif - if (sf->BytesPerPixel == 4 && sf->Amask == 0xff000000 - && sf->Gmask == 0xff00 - && ((sf->Rmask == 0xff && df->Rmask == 0x1f) - || (sf->Bmask == 0xff && df->Bmask == 0x1f))) { - if (df->Gmask == 0x7e0) - return BlitARGBto565PixelAlpha; - else if (df->Gmask == 0x3e0) - return BlitARGBto555PixelAlpha; - } - return BlitNtoNPixelAlpha; - - case 4: - if (sf->Rmask == df->Rmask - && sf->Gmask == df->Gmask - && sf->Bmask == df->Bmask && sf->BytesPerPixel == 4) { -#if defined(__MMX__) || defined(__3dNOW__) - if (sf->Rshift % 8 == 0 - && sf->Gshift % 8 == 0 - && sf->Bshift % 8 == 0 - && sf->Ashift % 8 == 0 && sf->Aloss == 0) { -#ifdef __3dNOW__ - if (SDL_Has3DNow()) - return BlitRGBtoRGBPixelAlphaMMX3DNOW; -#endif -#ifdef __MMX__ - if (SDL_HasMMX()) - return BlitRGBtoRGBPixelAlphaMMX; -#endif - } -#endif /* __MMX__ || __3dNOW__ */ - if (sf->Amask == 0xff000000) { -#if SDL_ALTIVEC_BLITTERS - if (SDL_HasAltiVec()) - return BlitRGBtoRGBPixelAlphaAltivec; -#endif - return BlitRGBtoRGBPixelAlpha; - } - } -#if SDL_ALTIVEC_BLITTERS - if (sf->Amask && sf->BytesPerPixel == 4 && SDL_HasAltiVec()) - return Blit32to32PixelAlphaAltivec; - else -#endif - return BlitNtoNPixelAlpha; - - case 3: - default: - return BlitNtoNPixelAlpha; - } - break; - - case SDL_COPY_MODULATE_ALPHA | SDL_COPY_BLEND: - if (sf->Amask == 0) { - /* Per-surface alpha blits */ - switch (df->BytesPerPixel) { - case 1: - return BlitNto1SurfaceAlpha; - - case 2: - if (surface->map->identity) { - if (df->Gmask == 0x7e0) { -#ifdef __MMX__ - if (SDL_HasMMX()) - return Blit565to565SurfaceAlphaMMX; - else -#endif - return Blit565to565SurfaceAlpha; - } else if (df->Gmask == 0x3e0) { -#ifdef __MMX__ - if (SDL_HasMMX()) - return Blit555to555SurfaceAlphaMMX; - else -#endif - return Blit555to555SurfaceAlpha; - } - } - return BlitNtoNSurfaceAlpha; - - case 4: - if (sf->Rmask == df->Rmask - && sf->Gmask == df->Gmask - && sf->Bmask == df->Bmask && sf->BytesPerPixel == 4) { -#ifdef __MMX__ - if (sf->Rshift % 8 == 0 - && sf->Gshift % 8 == 0 - && sf->Bshift % 8 == 0 && SDL_HasMMX()) - return BlitRGBtoRGBSurfaceAlphaMMX; -#endif - if ((sf->Rmask | sf->Gmask | sf->Bmask) == 0xffffff) { -#if SDL_ALTIVEC_BLITTERS - if (SDL_HasAltiVec()) - return BlitRGBtoRGBSurfaceAlphaAltivec; -#endif - return BlitRGBtoRGBSurfaceAlpha; - } - } -#if SDL_ALTIVEC_BLITTERS - if ((sf->BytesPerPixel == 4) && SDL_HasAltiVec()) - return Blit32to32SurfaceAlphaAltivec; - else -#endif - return BlitNtoNSurfaceAlpha; - - case 3: - default: - return BlitNtoNSurfaceAlpha; - } - } - break; - - case SDL_COPY_COLORKEY | SDL_COPY_MODULATE_ALPHA | SDL_COPY_BLEND: - if (sf->Amask == 0) { - if (df->BytesPerPixel == 1) - return BlitNto1SurfaceAlphaKey; - else -#if SDL_ALTIVEC_BLITTERS - if (sf->BytesPerPixel == 4 && df->BytesPerPixel == 4 && - SDL_HasAltiVec()) - return Blit32to32SurfaceAlphaKeyAltivec; - else -#endif - return BlitNtoNSurfaceAlphaKey; - } - break; - } - - return NULL; -} - -/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/SDL-mobile/src/video/SDL_blit_N.c b/src/SDL-mobile/src/video/SDL_blit_N.c deleted file mode 100644 index 2d7255ada..000000000 --- a/src/SDL-mobile/src/video/SDL_blit_N.c +++ /dev/null @@ -1,2514 +0,0 @@ -/* - Simple DirectMedia Layer - Copyright (C) 1997-2012 Sam Lantinga - - 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" - -#include "SDL_video.h" -#include "SDL_endian.h" -#include "SDL_cpuinfo.h" -#include "SDL_blit.h" - -#include "SDL_assert.h" - -/* Functions to blit from N-bit surfaces to other surfaces */ - -#if SDL_ALTIVEC_BLITTERS -#ifdef HAVE_ALTIVEC_H -#include -#endif -#ifdef __MACOSX__ -#include -static size_t -GetL3CacheSize(void) -{ - const char key[] = "hw.l3cachesize"; - u_int64_t result = 0; - size_t typeSize = sizeof(result); - - - int err = sysctlbyname(key, &result, &typeSize, NULL, 0); - if (0 != err) - return 0; - - return result; -} -#else -static size_t -GetL3CacheSize(void) -{ - /* XXX: Just guess G4 */ - return 2097152; -} -#endif /* __MACOSX__ */ - -#if (defined(__MACOSX__) && (__GNUC__ < 4)) -#define VECUINT8_LITERAL(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p) \ - (vector unsigned char) ( a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p ) -#define VECUINT16_LITERAL(a,b,c,d,e,f,g,h) \ - (vector unsigned short) ( a,b,c,d,e,f,g,h ) -#else -#define VECUINT8_LITERAL(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p) \ - (vector unsigned char) { a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p } -#define VECUINT16_LITERAL(a,b,c,d,e,f,g,h) \ - (vector unsigned short) { a,b,c,d,e,f,g,h } -#endif - -#define UNALIGNED_PTR(x) (((size_t) x) & 0x0000000F) -#define VSWIZZLE32(a,b,c,d) (vector unsigned char) \ - ( 0x00+a, 0x00+b, 0x00+c, 0x00+d, \ - 0x04+a, 0x04+b, 0x04+c, 0x04+d, \ - 0x08+a, 0x08+b, 0x08+c, 0x08+d, \ - 0x0C+a, 0x0C+b, 0x0C+c, 0x0C+d ) - -#define MAKE8888(dstfmt, r, g, b, a) \ - ( ((r<Rshift)&dstfmt->Rmask) | \ - ((g<Gshift)&dstfmt->Gmask) | \ - ((b<Bshift)&dstfmt->Bmask) | \ - ((a<Ashift)&dstfmt->Amask) ) - -/* - * Data Stream Touch...Altivec cache prefetching. - * - * Don't use this on a G5...however, the speed boost is very significant - * on a G4. - */ -#define DST_CHAN_SRC 1 -#define DST_CHAN_DEST 2 - -/* macro to set DST control word value... */ -#define DST_CTRL(size, count, stride) \ - (((size) << 24) | ((count) << 16) | (stride)) - -#define VEC_ALIGNER(src) ((UNALIGNED_PTR(src)) \ - ? vec_lvsl(0, src) \ - : vec_add(vec_lvsl(8, src), vec_splat_u8(8))) - -/* Calculate the permute vector used for 32->32 swizzling */ -static vector unsigned char -calc_swizzle32(const SDL_PixelFormat * srcfmt, const SDL_PixelFormat * dstfmt) -{ - /* - * We have to assume that the bits that aren't used by other - * colors is alpha, and it's one complete byte, since some formats - * leave alpha with a zero mask, but we should still swizzle the bits. - */ - /* ARGB */ - const static const struct SDL_PixelFormat default_pixel_format = { - 0, NULL, 0, 0, - {0, 0}, - 0x00FF0000, 0x0000FF00, 0x000000FF, 0xFF000000, - 0, 0, 0, 0, - 16, 8, 0, 24, - 0, NULL - }; - if (!srcfmt) { - srcfmt = &default_pixel_format; - } - if (!dstfmt) { - dstfmt = &default_pixel_format; - } - const vector unsigned char plus = VECUINT8_LITERAL(0x00, 0x00, 0x00, 0x00, - 0x04, 0x04, 0x04, 0x04, - 0x08, 0x08, 0x08, 0x08, - 0x0C, 0x0C, 0x0C, - 0x0C); - vector unsigned char vswiz; - vector unsigned int srcvec; -#define RESHIFT(X) (3 - ((X) >> 3)) - Uint32 rmask = RESHIFT(srcfmt->Rshift) << (dstfmt->Rshift); - Uint32 gmask = RESHIFT(srcfmt->Gshift) << (dstfmt->Gshift); - Uint32 bmask = RESHIFT(srcfmt->Bshift) << (dstfmt->Bshift); - Uint32 amask; - /* Use zero for alpha if either surface doesn't have alpha */ - if (dstfmt->Amask) { - amask = - ((srcfmt->Amask) ? RESHIFT(srcfmt-> - Ashift) : 0x10) << (dstfmt->Ashift); - } else { - amask = - 0x10101010 & ((dstfmt->Rmask | dstfmt->Gmask | dstfmt->Bmask) ^ - 0xFFFFFFFF); - } -#undef RESHIFT - ((unsigned int *) (char *) &srcvec)[0] = (rmask | gmask | bmask | amask); - vswiz = vec_add(plus, (vector unsigned char) vec_splat(srcvec, 0)); - return (vswiz); -} - -static void Blit_RGB888_RGB565(SDL_BlitInfo * info); -static void -Blit_RGB888_RGB565Altivec(SDL_BlitInfo * info) -{ - int height = info->dst_h; - Uint8 *src = (Uint8 *) info->src; - int srcskip = info->src_skip; - Uint8 *dst = (Uint8 *) info->dst; - int dstskip = info->dst_skip; - SDL_PixelFormat *srcfmt = info->src_fmt; - vector unsigned char valpha = vec_splat_u8(0); - vector unsigned char vpermute = calc_swizzle32(srcfmt, NULL); - vector unsigned char vgmerge = VECUINT8_LITERAL(0x00, 0x02, 0x00, 0x06, - 0x00, 0x0a, 0x00, 0x0e, - 0x00, 0x12, 0x00, 0x16, - 0x00, 0x1a, 0x00, 0x1e); - vector unsigned short v1 = vec_splat_u16(1); - vector unsigned short v3 = vec_splat_u16(3); - vector unsigned short v3f = - VECUINT16_LITERAL(0x003f, 0x003f, 0x003f, 0x003f, - 0x003f, 0x003f, 0x003f, 0x003f); - vector unsigned short vfc = - VECUINT16_LITERAL(0x00fc, 0x00fc, 0x00fc, 0x00fc, - 0x00fc, 0x00fc, 0x00fc, 0x00fc); - vector unsigned short vf800 = (vector unsigned short) vec_splat_u8(-7); - vf800 = vec_sl(vf800, vec_splat_u16(8)); - - while (height--) { - vector unsigned char valigner; - vector unsigned char voverflow; - vector unsigned char vsrc; - - int width = info->dst_w; - int extrawidth; - - /* do scalar until we can align... */ -#define ONE_PIXEL_BLEND(condition, widthvar) \ - while (condition) { \ - Uint32 Pixel; \ - unsigned sR, sG, sB, sA; \ - DISEMBLE_RGBA((Uint8 *)src, 4, srcfmt, Pixel, \ - sR, sG, sB, sA); \ - *(Uint16 *)(dst) = (((sR << 8) & 0x0000F800) | \ - ((sG << 3) & 0x000007E0) | \ - ((sB >> 3) & 0x0000001F)); \ - dst += 2; \ - src += 4; \ - widthvar--; \ - } - - ONE_PIXEL_BLEND(((UNALIGNED_PTR(dst)) && (width)), width); - - /* After all that work, here's the vector part! */ - extrawidth = (width % 8); /* trailing unaligned stores */ - width -= extrawidth; - vsrc = vec_ld(0, src); - valigner = VEC_ALIGNER(src); - - while (width) { - vector unsigned short vpixel, vrpixel, vgpixel, vbpixel; - vector unsigned int vsrc1, vsrc2; - vector unsigned char vdst; - - voverflow = vec_ld(15, src); - vsrc = vec_perm(vsrc, voverflow, valigner); - vsrc1 = (vector unsigned int) vec_perm(vsrc, valpha, vpermute); - src += 16; - vsrc = voverflow; - voverflow = vec_ld(15, src); - vsrc = vec_perm(vsrc, voverflow, valigner); - vsrc2 = (vector unsigned int) vec_perm(vsrc, valpha, vpermute); - /* 1555 */ - vpixel = (vector unsigned short) vec_packpx(vsrc1, vsrc2); - vgpixel = (vector unsigned short) vec_perm(vsrc1, vsrc2, vgmerge); - vgpixel = vec_and(vgpixel, vfc); - vgpixel = vec_sl(vgpixel, v3); - vrpixel = vec_sl(vpixel, v1); - vrpixel = vec_and(vrpixel, vf800); - vbpixel = vec_and(vpixel, v3f); - vdst = - vec_or((vector unsigned char) vrpixel, - (vector unsigned char) vgpixel); - /* 565 */ - vdst = vec_or(vdst, (vector unsigned char) vbpixel); - vec_st(vdst, 0, dst); - - width -= 8; - src += 16; - dst += 16; - vsrc = voverflow; - } - - SDL_assert(width == 0); - - /* do scalar until we can align... */ - ONE_PIXEL_BLEND((extrawidth), extrawidth); -#undef ONE_PIXEL_BLEND - - src += srcskip; /* move to next row, accounting for pitch. */ - dst += dstskip; - } - - -} - -static void -Blit_RGB565_32Altivec(SDL_BlitInfo * info) -{ - int height = info->dst_h; - Uint8 *src = (Uint8 *) info->src; - int srcskip = info->src_skip; - Uint8 *dst = (Uint8 *) info->dst; - int dstskip = info->dst_skip; - SDL_PixelFormat *srcfmt = info->src_fmt; - SDL_PixelFormat *dstfmt = info->dst_fmt; - unsigned alpha; - vector unsigned char valpha; - vector unsigned char vpermute; - vector unsigned short vf800; - vector unsigned int v8 = vec_splat_u32(8); - vector unsigned int v16 = vec_add(v8, v8); - vector unsigned short v2 = vec_splat_u16(2); - vector unsigned short v3 = vec_splat_u16(3); - /* - 0x10 - 0x1f is the alpha - 0x00 - 0x0e evens are the red - 0x01 - 0x0f odds are zero - */ - vector unsigned char vredalpha1 = VECUINT8_LITERAL(0x10, 0x00, 0x01, 0x01, - 0x10, 0x02, 0x01, 0x01, - 0x10, 0x04, 0x01, 0x01, - 0x10, 0x06, 0x01, - 0x01); - vector unsigned char vredalpha2 = - (vector unsigned - char) (vec_add((vector unsigned int) vredalpha1, vec_sl(v8, v16)) - ); - /* - 0x00 - 0x0f is ARxx ARxx ARxx ARxx - 0x11 - 0x0f odds are blue - */ - vector unsigned char vblue1 = VECUINT8_LITERAL(0x00, 0x01, 0x02, 0x11, - 0x04, 0x05, 0x06, 0x13, - 0x08, 0x09, 0x0a, 0x15, - 0x0c, 0x0d, 0x0e, 0x17); - vector unsigned char vblue2 = - (vector unsigned char) (vec_add((vector unsigned int) vblue1, v8) - ); - /* - 0x00 - 0x0f is ARxB ARxB ARxB ARxB - 0x10 - 0x0e evens are green - */ - vector unsigned char vgreen1 = VECUINT8_LITERAL(0x00, 0x01, 0x10, 0x03, - 0x04, 0x05, 0x12, 0x07, - 0x08, 0x09, 0x14, 0x0b, - 0x0c, 0x0d, 0x16, 0x0f); - vector unsigned char vgreen2 = - (vector unsigned - char) (vec_add((vector unsigned int) vgreen1, vec_sl(v8, v8)) - ); - - SDL_assert(srcfmt->BytesPerPixel == 2); - SDL_assert(dstfmt->BytesPerPixel == 4); - - vf800 = (vector unsigned short) vec_splat_u8(-7); - vf800 = vec_sl(vf800, vec_splat_u16(8)); - - if (dstfmt->Amask && info->a) { - ((unsigned char *) &valpha)[0] = alpha = info->a; - valpha = vec_splat(valpha, 0); - } else { - alpha = 0; - valpha = vec_splat_u8(0); - } - - vpermute = calc_swizzle32(NULL, dstfmt); - while (height--) { - vector unsigned char valigner; - vector unsigned char voverflow; - vector unsigned char vsrc; - - int width = info->dst_w; - int extrawidth; - - /* do scalar until we can align... */ -#define ONE_PIXEL_BLEND(condition, widthvar) \ - while (condition) { \ - unsigned sR, sG, sB; \ - unsigned short Pixel = *((unsigned short *)src); \ - sR = (Pixel >> 8) & 0xf8; \ - sG = (Pixel >> 3) & 0xfc; \ - sB = (Pixel << 3) & 0xf8; \ - ASSEMBLE_RGBA(dst, 4, dstfmt, sR, sG, sB, alpha); \ - src += 2; \ - dst += 4; \ - widthvar--; \ - } - ONE_PIXEL_BLEND(((UNALIGNED_PTR(dst)) && (width)), width); - - /* After all that work, here's the vector part! */ - extrawidth = (width % 8); /* trailing unaligned stores */ - width -= extrawidth; - vsrc = vec_ld(0, src); - valigner = VEC_ALIGNER(src); - - while (width) { - vector unsigned short vR, vG, vB; - vector unsigned char vdst1, vdst2; - - voverflow = vec_ld(15, src); - vsrc = vec_perm(vsrc, voverflow, valigner); - - vR = vec_and((vector unsigned short) vsrc, vf800); - vB = vec_sl((vector unsigned short) vsrc, v3); - vG = vec_sl(vB, v2); - - vdst1 = - (vector unsigned char) vec_perm((vector unsigned char) vR, - valpha, vredalpha1); - vdst1 = vec_perm(vdst1, (vector unsigned char) vB, vblue1); - vdst1 = vec_perm(vdst1, (vector unsigned char) vG, vgreen1); - vdst1 = vec_perm(vdst1, valpha, vpermute); - vec_st(vdst1, 0, dst); - - vdst2 = - (vector unsigned char) vec_perm((vector unsigned char) vR, - valpha, vredalpha2); - vdst2 = vec_perm(vdst2, (vector unsigned char) vB, vblue2); - vdst2 = vec_perm(vdst2, (vector unsigned char) vG, vgreen2); - vdst2 = vec_perm(vdst2, valpha, vpermute); - vec_st(vdst2, 16, dst); - - width -= 8; - dst += 32; - src += 16; - vsrc = voverflow; - } - - SDL_assert(width == 0); - - - /* do scalar until we can align... */ - ONE_PIXEL_BLEND((extrawidth), extrawidth); -#undef ONE_PIXEL_BLEND - - src += srcskip; /* move to next row, accounting for pitch. */ - dst += dstskip; - } - -} - - -static void -Blit_RGB555_32Altivec(SDL_BlitInfo * info) -{ - int height = info->dst_h; - Uint8 *src = (Uint8 *) info->src; - int srcskip = info->src_skip; - Uint8 *dst = (Uint8 *) info->dst; - int dstskip = info->dst_skip; - SDL_PixelFormat *srcfmt = info->src_fmt; - SDL_PixelFormat *dstfmt = info->dst_fmt; - unsigned alpha; - vector unsigned char valpha; - vector unsigned char vpermute; - vector unsigned short vf800; - vector unsigned int v8 = vec_splat_u32(8); - vector unsigned int v16 = vec_add(v8, v8); - vector unsigned short v1 = vec_splat_u16(1); - vector unsigned short v3 = vec_splat_u16(3); - /* - 0x10 - 0x1f is the alpha - 0x00 - 0x0e evens are the red - 0x01 - 0x0f odds are zero - */ - vector unsigned char vredalpha1 = VECUINT8_LITERAL(0x10, 0x00, 0x01, 0x01, - 0x10, 0x02, 0x01, 0x01, - 0x10, 0x04, 0x01, 0x01, - 0x10, 0x06, 0x01, - 0x01); - vector unsigned char vredalpha2 = - (vector unsigned - char) (vec_add((vector unsigned int) vredalpha1, vec_sl(v8, v16)) - ); - /* - 0x00 - 0x0f is ARxx ARxx ARxx ARxx - 0x11 - 0x0f odds are blue - */ - vector unsigned char vblue1 = VECUINT8_LITERAL(0x00, 0x01, 0x02, 0x11, - 0x04, 0x05, 0x06, 0x13, - 0x08, 0x09, 0x0a, 0x15, - 0x0c, 0x0d, 0x0e, 0x17); - vector unsigned char vblue2 = - (vector unsigned char) (vec_add((vector unsigned int) vblue1, v8) - ); - /* - 0x00 - 0x0f is ARxB ARxB ARxB ARxB - 0x10 - 0x0e evens are green - */ - vector unsigned char vgreen1 = VECUINT8_LITERAL(0x00, 0x01, 0x10, 0x03, - 0x04, 0x05, 0x12, 0x07, - 0x08, 0x09, 0x14, 0x0b, - 0x0c, 0x0d, 0x16, 0x0f); - vector unsigned char vgreen2 = - (vector unsigned - char) (vec_add((vector unsigned int) vgreen1, vec_sl(v8, v8)) - ); - - SDL_assert(srcfmt->BytesPerPixel == 2); - SDL_assert(dstfmt->BytesPerPixel == 4); - - vf800 = (vector unsigned short) vec_splat_u8(-7); - vf800 = vec_sl(vf800, vec_splat_u16(8)); - - if (dstfmt->Amask && info->a) { - ((unsigned char *) &valpha)[0] = alpha = info->a; - valpha = vec_splat(valpha, 0); - } else { - alpha = 0; - valpha = vec_splat_u8(0); - } - - vpermute = calc_swizzle32(NULL, dstfmt); - while (height--) { - vector unsigned char valigner; - vector unsigned char voverflow; - vector unsigned char vsrc; - - int width = info->dst_w; - int extrawidth; - - /* do scalar until we can align... */ -#define ONE_PIXEL_BLEND(condition, widthvar) \ - while (condition) { \ - unsigned sR, sG, sB; \ - unsigned short Pixel = *((unsigned short *)src); \ - sR = (Pixel >> 7) & 0xf8; \ - sG = (Pixel >> 2) & 0xf8; \ - sB = (Pixel << 3) & 0xf8; \ - ASSEMBLE_RGBA(dst, 4, dstfmt, sR, sG, sB, alpha); \ - src += 2; \ - dst += 4; \ - widthvar--; \ - } - ONE_PIXEL_BLEND(((UNALIGNED_PTR(dst)) && (width)), width); - - /* After all that work, here's the vector part! */ - extrawidth = (width % 8); /* trailing unaligned stores */ - width -= extrawidth; - vsrc = vec_ld(0, src); - valigner = VEC_ALIGNER(src); - - while (width) { - vector unsigned short vR, vG, vB; - vector unsigned char vdst1, vdst2; - - voverflow = vec_ld(15, src); - vsrc = vec_perm(vsrc, voverflow, valigner); - - vR = vec_and(vec_sl((vector unsigned short) vsrc, v1), vf800); - vB = vec_sl((vector unsigned short) vsrc, v3); - vG = vec_sl(vB, v3); - - vdst1 = - (vector unsigned char) vec_perm((vector unsigned char) vR, - valpha, vredalpha1); - vdst1 = vec_perm(vdst1, (vector unsigned char) vB, vblue1); - vdst1 = vec_perm(vdst1, (vector unsigned char) vG, vgreen1); - vdst1 = vec_perm(vdst1, valpha, vpermute); - vec_st(vdst1, 0, dst); - - vdst2 = - (vector unsigned char) vec_perm((vector unsigned char) vR, - valpha, vredalpha2); - vdst2 = vec_perm(vdst2, (vector unsigned char) vB, vblue2); - vdst2 = vec_perm(vdst2, (vector unsigned char) vG, vgreen2); - vdst2 = vec_perm(vdst2, valpha, vpermute); - vec_st(vdst2, 16, dst); - - width -= 8; - dst += 32; - src += 16; - vsrc = voverflow; - } - - SDL_assert(width == 0); - - - /* do scalar until we can align... */ - ONE_PIXEL_BLEND((extrawidth), extrawidth); -#undef ONE_PIXEL_BLEND - - src += srcskip; /* move to next row, accounting for pitch. */ - dst += dstskip; - } - -} - -static void BlitNtoNKey(SDL_BlitInfo * info); -static void BlitNtoNKeyCopyAlpha(SDL_BlitInfo * info); -static void -Blit32to32KeyAltivec(SDL_BlitInfo * info) -{ - int height = info->dst_h; - Uint32 *srcp = (Uint32 *) info->src; - int srcskip = info->src_skip / 4; - Uint32 *dstp = (Uint32 *) info->dst; - int dstskip = info->dst_skip / 4; - SDL_PixelFormat *srcfmt = info->src_fmt; - int srcbpp = srcfmt->BytesPerPixel; - SDL_PixelFormat *dstfmt = info->dst_fmt; - int dstbpp = dstfmt->BytesPerPixel; - int copy_alpha = (srcfmt->Amask && dstfmt->Amask); - unsigned alpha = dstfmt->Amask ? info->a : 0; - Uint32 rgbmask = srcfmt->Rmask | srcfmt->Gmask | srcfmt->Bmask; - Uint32 ckey = info->colorkey; - vector unsigned int valpha; - vector unsigned char vpermute; - vector unsigned char vzero; - vector unsigned int vckey; - vector unsigned int vrgbmask; - vpermute = calc_swizzle32(srcfmt, dstfmt); - if (info->dst_w < 16) { - if (copy_alpha) { - BlitNtoNKeyCopyAlpha(info); - } else { - BlitNtoNKey(info); - } - return; - } - vzero = vec_splat_u8(0); - if (alpha) { - ((unsigned char *) &valpha)[0] = (unsigned char) alpha; - valpha = - (vector unsigned int) vec_splat((vector unsigned char) valpha, 0); - } else { - valpha = (vector unsigned int) vzero; - } - ckey &= rgbmask; - ((unsigned int *) (char *) &vckey)[0] = ckey; - vckey = vec_splat(vckey, 0); - ((unsigned int *) (char *) &vrgbmask)[0] = rgbmask; - vrgbmask = vec_splat(vrgbmask, 0); - - while (height--) { -#define ONE_PIXEL_BLEND(condition, widthvar) \ - if (copy_alpha) { \ - while (condition) { \ - Uint32 Pixel; \ - unsigned sR, sG, sB, sA; \ - DISEMBLE_RGBA((Uint8 *)srcp, srcbpp, srcfmt, Pixel, \ - sR, sG, sB, sA); \ - if ( (Pixel & rgbmask) != ckey ) { \ - ASSEMBLE_RGBA((Uint8 *)dstp, dstbpp, dstfmt, \ - sR, sG, sB, sA); \ - } \ - dstp = (Uint32 *) (((Uint8 *) dstp) + dstbpp); \ - srcp = (Uint32 *) (((Uint8 *) srcp) + srcbpp); \ - widthvar--; \ - } \ - } else { \ - while (condition) { \ - Uint32 Pixel; \ - unsigned sR, sG, sB; \ - RETRIEVE_RGB_PIXEL((Uint8 *)srcp, srcbpp, Pixel); \ - if ( Pixel != ckey ) { \ - RGB_FROM_PIXEL(Pixel, srcfmt, sR, sG, sB); \ - ASSEMBLE_RGBA((Uint8 *)dstp, dstbpp, dstfmt, \ - sR, sG, sB, alpha); \ - } \ - dstp = (Uint32 *) (((Uint8 *)dstp) + dstbpp); \ - srcp = (Uint32 *) (((Uint8 *)srcp) + srcbpp); \ - widthvar--; \ - } \ - } - int width = info->dst_w; - ONE_PIXEL_BLEND((UNALIGNED_PTR(dstp)) && (width), width); - SDL_assert(width > 0); - if (width > 0) { - int extrawidth = (width % 4); - vector unsigned char valigner = VEC_ALIGNER(srcp); - vector unsigned int vs = vec_ld(0, srcp); - width -= extrawidth; - SDL_assert(width >= 4); - while (width) { - vector unsigned char vsel; - vector unsigned int vd; - vector unsigned int voverflow = vec_ld(15, srcp); - /* load the source vec */ - vs = vec_perm(vs, voverflow, valigner); - /* vsel is set for items that match the key */ - vsel = (vector unsigned char) vec_and(vs, vrgbmask); - vsel = (vector unsigned char) vec_cmpeq(vs, vckey); - /* permute the src vec to the dest format */ - vs = vec_perm(vs, valpha, vpermute); - /* load the destination vec */ - vd = vec_ld(0, dstp); - /* select the source and dest into vs */ - vd = (vector unsigned int) vec_sel((vector unsigned char) vs, - (vector unsigned char) vd, - vsel); - - vec_st(vd, 0, dstp); - srcp += 4; - width -= 4; - dstp += 4; - vs = voverflow; - } - ONE_PIXEL_BLEND((extrawidth), extrawidth); -#undef ONE_PIXEL_BLEND - srcp += srcskip; - dstp += dstskip; - } - } -} - -/* Altivec code to swizzle one 32-bit surface to a different 32-bit format. */ -/* Use this on a G5 */ -static void -ConvertAltivec32to32_noprefetch(SDL_BlitInfo * info) -{ - int height = info->dst_h; - Uint32 *src = (Uint32 *) info->src; - int srcskip = info->src_skip / 4; - Uint32 *dst = (Uint32 *) info->dst; - int dstskip = info->dst_skip / 4; - SDL_PixelFormat *srcfmt = info->src_fmt; - SDL_PixelFormat *dstfmt = info->dst_fmt; - vector unsigned int vzero = vec_splat_u32(0); - vector unsigned char vpermute = calc_swizzle32(srcfmt, dstfmt); - if (dstfmt->Amask && !srcfmt->Amask) { - if (info->a) { - vector unsigned char valpha; - ((unsigned char *) &valpha)[0] = info->a; - vzero = (vector unsigned int) vec_splat(valpha, 0); - } - } - - SDL_assert(srcfmt->BytesPerPixel == 4); - SDL_assert(dstfmt->BytesPerPixel == 4); - - while (height--) { - vector unsigned char valigner; - vector unsigned int vbits; - vector unsigned int voverflow; - Uint32 bits; - Uint8 r, g, b, a; - - int width = info->dst_w; - int extrawidth; - - /* do scalar until we can align... */ - while ((UNALIGNED_PTR(dst)) && (width)) { - bits = *(src++); - RGBA_FROM_8888(bits, srcfmt, r, g, b, a); - if(!srcfmt->Amask) - a = info->a; - *(dst++) = MAKE8888(dstfmt, r, g, b, a); - width--; - } - - /* After all that work, here's the vector part! */ - extrawidth = (width % 4); - width -= extrawidth; - valigner = VEC_ALIGNER(src); - vbits = vec_ld(0, src); - - while (width) { - voverflow = vec_ld(15, src); - src += 4; - width -= 4; - vbits = vec_perm(vbits, voverflow, valigner); /* src is ready. */ - vbits = vec_perm(vbits, vzero, vpermute); /* swizzle it. */ - vec_st(vbits, 0, dst); /* store it back out. */ - dst += 4; - vbits = voverflow; - } - - SDL_assert(width == 0); - - /* cover pixels at the end of the row that didn't fit in 16 bytes. */ - while (extrawidth) { - bits = *(src++); /* max 7 pixels, don't bother with prefetch. */ - RGBA_FROM_8888(bits, srcfmt, r, g, b, a); - if(!srcfmt->Amask) - a = info->a; - *(dst++) = MAKE8888(dstfmt, r, g, b, a); - extrawidth--; - } - - src += srcskip; - dst += dstskip; - } - -} - -/* Altivec code to swizzle one 32-bit surface to a different 32-bit format. */ -/* Use this on a G4 */ -static void -ConvertAltivec32to32_prefetch(SDL_BlitInfo * info) -{ - const int scalar_dst_lead = sizeof(Uint32) * 4; - const int vector_dst_lead = sizeof(Uint32) * 16; - - int height = info->dst_h; - Uint32 *src = (Uint32 *) info->src; - int srcskip = info->src_skip / 4; - Uint32 *dst = (Uint32 *) info->dst; - int dstskip = info->dst_skip / 4; - SDL_PixelFormat *srcfmt = info->src_fmt; - SDL_PixelFormat *dstfmt = info->dst_fmt; - vector unsigned int vzero = vec_splat_u32(0); - vector unsigned char vpermute = calc_swizzle32(srcfmt, dstfmt); - if (dstfmt->Amask && !srcfmt->Amask) { - if (info->a) { - vector unsigned char valpha; - ((unsigned char *) &valpha)[0] = info->a; - vzero = (vector unsigned int) vec_splat(valpha, 0); - } - } - - SDL_assert(srcfmt->BytesPerPixel == 4); - SDL_assert(dstfmt->BytesPerPixel == 4); - - while (height--) { - vector unsigned char valigner; - vector unsigned int vbits; - vector unsigned int voverflow; - Uint32 bits; - Uint8 r, g, b, a; - - int width = info->dst_w; - int extrawidth; - - /* do scalar until we can align... */ - while ((UNALIGNED_PTR(dst)) && (width)) { - vec_dstt(src + scalar_dst_lead, DST_CTRL(2, 32, 1024), - DST_CHAN_SRC); - vec_dstst(dst + scalar_dst_lead, DST_CTRL(2, 32, 1024), - DST_CHAN_DEST); - bits = *(src++); - RGBA_FROM_8888(bits, srcfmt, r, g, b, a); - if(!srcfmt->Amask) - a = info->a; - *(dst++) = MAKE8888(dstfmt, r, g, b, a); - width--; - } - - /* After all that work, here's the vector part! */ - extrawidth = (width % 4); - width -= extrawidth; - valigner = VEC_ALIGNER(src); - vbits = vec_ld(0, src); - - while (width) { - vec_dstt(src + vector_dst_lead, DST_CTRL(2, 32, 1024), - DST_CHAN_SRC); - vec_dstst(dst + vector_dst_lead, DST_CTRL(2, 32, 1024), - DST_CHAN_DEST); - voverflow = vec_ld(15, src); - src += 4; - width -= 4; - vbits = vec_perm(vbits, voverflow, valigner); /* src is ready. */ - vbits = vec_perm(vbits, vzero, vpermute); /* swizzle it. */ - vec_st(vbits, 0, dst); /* store it back out. */ - dst += 4; - vbits = voverflow; - } - - SDL_assert(width == 0); - - /* cover pixels at the end of the row that didn't fit in 16 bytes. */ - while (extrawidth) { - bits = *(src++); /* max 7 pixels, don't bother with prefetch. */ - RGBA_FROM_8888(bits, srcfmt, r, g, b, a); - if(!srcfmt->Amask) - a = info->a; - *(dst++) = MAKE8888(dstfmt, r, g, b, a); - extrawidth--; - } - - src += srcskip; - dst += dstskip; - } - - vec_dss(DST_CHAN_SRC); - vec_dss(DST_CHAN_DEST); -} - -static Uint32 -GetBlitFeatures(void) -{ - static Uint32 features = 0xffffffff; - if (features == 0xffffffff) { - /* Provide an override for testing .. */ - char *override = SDL_getenv("SDL_ALTIVEC_BLIT_FEATURES"); - if (override) { - features = 0; - SDL_sscanf(override, "%u", &features); - } else { - features = (0 - /* Feature 1 is has-MMX */ - | ((SDL_HasMMX())? 1 : 0) - /* Feature 2 is has-AltiVec */ - | ((SDL_HasAltiVec())? 2 : 0) - /* Feature 4 is dont-use-prefetch */ - /* !!!! FIXME: Check for G5 or later, not the cache size! Always prefetch on a G4. */ - | ((GetL3CacheSize() == 0) ? 4 : 0) - ); - } - } - return features; -} - -#if __MWERKS__ -#pragma altivec_model off -#endif -#else -/* Feature 1 is has-MMX */ -#define GetBlitFeatures() ((Uint32)(SDL_HasMMX() ? 1 : 0)) -#endif - -/* This is now endian dependent */ -#if SDL_BYTEORDER == SDL_LIL_ENDIAN -#define HI 1 -#define LO 0 -#else /* SDL_BYTEORDER == SDL_BIG_ENDIAN */ -#define HI 0 -#define LO 1 -#endif - -/* Special optimized blit for RGB 8-8-8 --> RGB 3-3-2 */ -#define RGB888_RGB332(dst, src) { \ - dst = (Uint8)((((src)&0x00E00000)>>16)| \ - (((src)&0x0000E000)>>11)| \ - (((src)&0x000000C0)>>6)); \ -} -static void -Blit_RGB888_index8(SDL_BlitInfo * info) -{ -#ifndef USE_DUFFS_LOOP - int c; -#endif - int width, height; - Uint32 *src; - const Uint8 *map; - Uint8 *dst; - int srcskip, dstskip; - - /* Set up some basic variables */ - width = info->dst_w; - height = info->dst_h; - src = (Uint32 *) info->src; - srcskip = info->src_skip / 4; - dst = info->dst; - dstskip = info->dst_skip; - map = info->table; - - if (map == NULL) { - while (height--) { -#ifdef USE_DUFFS_LOOP - /* *INDENT-OFF* */ - DUFFS_LOOP( - RGB888_RGB332(*dst++, *src); - , width); - /* *INDENT-ON* */ -#else - for (c = width / 4; c; --c) { - /* Pack RGB into 8bit pixel */ - ++src; - RGB888_RGB332(*dst++, *src); - ++src; - RGB888_RGB332(*dst++, *src); - ++src; - RGB888_RGB332(*dst++, *src); - ++src; - } - switch (width & 3) { - case 3: - RGB888_RGB332(*dst++, *src); - ++src; - case 2: - RGB888_RGB332(*dst++, *src); - ++src; - case 1: - RGB888_RGB332(*dst++, *src); - ++src; - } -#endif /* USE_DUFFS_LOOP */ - src += srcskip; - dst += dstskip; - } - } else { - int Pixel; - - while (height--) { -#ifdef USE_DUFFS_LOOP - /* *INDENT-OFF* */ - DUFFS_LOOP( - RGB888_RGB332(Pixel, *src); - *dst++ = map[Pixel]; - ++src; - , width); - /* *INDENT-ON* */ -#else - for (c = width / 4; c; --c) { - /* Pack RGB into 8bit pixel */ - RGB888_RGB332(Pixel, *src); - *dst++ = map[Pixel]; - ++src; - RGB888_RGB332(Pixel, *src); - *dst++ = map[Pixel]; - ++src; - RGB888_RGB332(Pixel, *src); - *dst++ = map[Pixel]; - ++src; - RGB888_RGB332(Pixel, *src); - *dst++ = map[Pixel]; - ++src; - } - switch (width & 3) { - case 3: - RGB888_RGB332(Pixel, *src); - *dst++ = map[Pixel]; - ++src; - case 2: - RGB888_RGB332(Pixel, *src); - *dst++ = map[Pixel]; - ++src; - case 1: - RGB888_RGB332(Pixel, *src); - *dst++ = map[Pixel]; - ++src; - } -#endif /* USE_DUFFS_LOOP */ - src += srcskip; - dst += dstskip; - } - } -} - -/* Special optimized blit for RGB 8-8-8 --> RGB 5-5-5 */ -#define RGB888_RGB555(dst, src) { \ - *(Uint16 *)(dst) = (Uint16)((((*src)&0x00F80000)>>9)| \ - (((*src)&0x0000F800)>>6)| \ - (((*src)&0x000000F8)>>3)); \ -} -#define RGB888_RGB555_TWO(dst, src) { \ - *(Uint32 *)(dst) = (((((src[HI])&0x00F80000)>>9)| \ - (((src[HI])&0x0000F800)>>6)| \ - (((src[HI])&0x000000F8)>>3))<<16)| \ - (((src[LO])&0x00F80000)>>9)| \ - (((src[LO])&0x0000F800)>>6)| \ - (((src[LO])&0x000000F8)>>3); \ -} -static void -Blit_RGB888_RGB555(SDL_BlitInfo * info) -{ -#ifndef USE_DUFFS_LOOP - int c; -#endif - int width, height; - Uint32 *src; - Uint16 *dst; - int srcskip, dstskip; - - /* Set up some basic variables */ - width = info->dst_w; - height = info->dst_h; - src = (Uint32 *) info->src; - srcskip = info->src_skip / 4; - dst = (Uint16 *) info->dst; - dstskip = info->dst_skip / 2; - -#ifdef USE_DUFFS_LOOP - while (height--) { - /* *INDENT-OFF* */ - DUFFS_LOOP( - RGB888_RGB555(dst, src); - ++src; - ++dst; - , width); - /* *INDENT-ON* */ - src += srcskip; - dst += dstskip; - } -#else - /* Memory align at 4-byte boundary, if necessary */ - if ((long) dst & 0x03) { - /* Don't do anything if width is 0 */ - if (width == 0) { - return; - } - --width; - - while (height--) { - /* Perform copy alignment */ - RGB888_RGB555(dst, src); - ++src; - ++dst; - - /* Copy in 4 pixel chunks */ - for (c = width / 4; c; --c) { - RGB888_RGB555_TWO(dst, src); - src += 2; - dst += 2; - RGB888_RGB555_TWO(dst, src); - src += 2; - dst += 2; - } - /* Get any leftovers */ - switch (width & 3) { - case 3: - RGB888_RGB555(dst, src); - ++src; - ++dst; - case 2: - RGB888_RGB555_TWO(dst, src); - src += 2; - dst += 2; - break; - case 1: - RGB888_RGB555(dst, src); - ++src; - ++dst; - break; - } - src += srcskip; - dst += dstskip; - } - } else { - while (height--) { - /* Copy in 4 pixel chunks */ - for (c = width / 4; c; --c) { - RGB888_RGB555_TWO(dst, src); - src += 2; - dst += 2; - RGB888_RGB555_TWO(dst, src); - src += 2; - dst += 2; - } - /* Get any leftovers */ - switch (width & 3) { - case 3: - RGB888_RGB555(dst, src); - ++src; - ++dst; - case 2: - RGB888_RGB555_TWO(dst, src); - src += 2; - dst += 2; - break; - case 1: - RGB888_RGB555(dst, src); - ++src; - ++dst; - break; - } - src += srcskip; - dst += dstskip; - } - } -#endif /* USE_DUFFS_LOOP */ -} - -/* Special optimized blit for RGB 8-8-8 --> RGB 5-6-5 */ -#define RGB888_RGB565(dst, src) { \ - *(Uint16 *)(dst) = (Uint16)((((*src)&0x00F80000)>>8)| \ - (((*src)&0x0000FC00)>>5)| \ - (((*src)&0x000000F8)>>3)); \ -} -#define RGB888_RGB565_TWO(dst, src) { \ - *(Uint32 *)(dst) = (((((src[HI])&0x00F80000)>>8)| \ - (((src[HI])&0x0000FC00)>>5)| \ - (((src[HI])&0x000000F8)>>3))<<16)| \ - (((src[LO])&0x00F80000)>>8)| \ - (((src[LO])&0x0000FC00)>>5)| \ - (((src[LO])&0x000000F8)>>3); \ -} -static void -Blit_RGB888_RGB565(SDL_BlitInfo * info) -{ -#ifndef USE_DUFFS_LOOP - int c; -#endif - int width, height; - Uint32 *src; - Uint16 *dst; - int srcskip, dstskip; - - /* Set up some basic variables */ - width = info->dst_w; - height = info->dst_h; - src = (Uint32 *) info->src; - srcskip = info->src_skip / 4; - dst = (Uint16 *) info->dst; - dstskip = info->dst_skip / 2; - -#ifdef USE_DUFFS_LOOP - while (height--) { - /* *INDENT-OFF* */ - DUFFS_LOOP( - RGB888_RGB565(dst, src); - ++src; - ++dst; - , width); - /* *INDENT-ON* */ - src += srcskip; - dst += dstskip; - } -#else - /* Memory align at 4-byte boundary, if necessary */ - if ((long) dst & 0x03) { - /* Don't do anything if width is 0 */ - if (width == 0) { - return; - } - --width; - - while (height--) { - /* Perform copy alignment */ - RGB888_RGB565(dst, src); - ++src; - ++dst; - - /* Copy in 4 pixel chunks */ - for (c = width / 4; c; --c) { - RGB888_RGB565_TWO(dst, src); - src += 2; - dst += 2; - RGB888_RGB565_TWO(dst, src); - src += 2; - dst += 2; - } - /* Get any leftovers */ - switch (width & 3) { - case 3: - RGB888_RGB565(dst, src); - ++src; - ++dst; - case 2: - RGB888_RGB565_TWO(dst, src); - src += 2; - dst += 2; - break; - case 1: - RGB888_RGB565(dst, src); - ++src; - ++dst; - break; - } - src += srcskip; - dst += dstskip; - } - } else { - while (height--) { - /* Copy in 4 pixel chunks */ - for (c = width / 4; c; --c) { - RGB888_RGB565_TWO(dst, src); - src += 2; - dst += 2; - RGB888_RGB565_TWO(dst, src); - src += 2; - dst += 2; - } - /* Get any leftovers */ - switch (width & 3) { - case 3: - RGB888_RGB565(dst, src); - ++src; - ++dst; - case 2: - RGB888_RGB565_TWO(dst, src); - src += 2; - dst += 2; - break; - case 1: - RGB888_RGB565(dst, src); - ++src; - ++dst; - break; - } - src += srcskip; - dst += dstskip; - } - } -#endif /* USE_DUFFS_LOOP */ -} - - -/* Special optimized blit for RGB 5-6-5 --> 32-bit RGB surfaces */ -#define RGB565_32(dst, src, map) (map[src[LO]*2] + map[src[HI]*2+1]) -static void -Blit_RGB565_32(SDL_BlitInfo * info, const Uint32 * map) -{ -#ifndef USE_DUFFS_LOOP - int c; -#endif - int width, height; - Uint8 *src; - Uint32 *dst; - int srcskip, dstskip; - - /* Set up some basic variables */ - width = info->dst_w; - height = info->dst_h; - src = (Uint8 *) info->src; - srcskip = info->src_skip; - dst = (Uint32 *) info->dst; - dstskip = info->dst_skip / 4; - -#ifdef USE_DUFFS_LOOP - while (height--) { - /* *INDENT-OFF* */ - DUFFS_LOOP( - { - *dst++ = RGB565_32(dst, src, map); - src += 2; - }, - width); - /* *INDENT-ON* */ - src += srcskip; - dst += dstskip; - } -#else - while (height--) { - /* Copy in 4 pixel chunks */ - for (c = width / 4; c; --c) { - *dst++ = RGB565_32(dst, src, map); - src += 2; - *dst++ = RGB565_32(dst, src, map); - src += 2; - *dst++ = RGB565_32(dst, src, map); - src += 2; - *dst++ = RGB565_32(dst, src, map); - src += 2; - } - /* Get any leftovers */ - switch (width & 3) { - case 3: - *dst++ = RGB565_32(dst, src, map); - src += 2; - case 2: - *dst++ = RGB565_32(dst, src, map); - src += 2; - case 1: - *dst++ = RGB565_32(dst, src, map); - src += 2; - break; - } - src += srcskip; - dst += dstskip; - } -#endif /* USE_DUFFS_LOOP */ -} - -/* Special optimized blit for RGB 5-6-5 --> ARGB 8-8-8-8 */ -static const Uint32 RGB565_ARGB8888_LUT[512] = { - 0x00000000, 0xff000000, 0x00000008, 0xff002000, - 0x00000010, 0xff004000, 0x00000018, 0xff006100, - 0x00000020, 0xff008100, 0x00000029, 0xff00a100, - 0x00000031, 0xff00c200, 0x00000039, 0xff00e200, - 0x00000041, 0xff080000, 0x0000004a, 0xff082000, - 0x00000052, 0xff084000, 0x0000005a, 0xff086100, - 0x00000062, 0xff088100, 0x0000006a, 0xff08a100, - 0x00000073, 0xff08c200, 0x0000007b, 0xff08e200, - 0x00000083, 0xff100000, 0x0000008b, 0xff102000, - 0x00000094, 0xff104000, 0x0000009c, 0xff106100, - 0x000000a4, 0xff108100, 0x000000ac, 0xff10a100, - 0x000000b4, 0xff10c200, 0x000000bd, 0xff10e200, - 0x000000c5, 0xff180000, 0x000000cd, 0xff182000, - 0x000000d5, 0xff184000, 0x000000de, 0xff186100, - 0x000000e6, 0xff188100, 0x000000ee, 0xff18a100, - 0x000000f6, 0xff18c200, 0x000000ff, 0xff18e200, - 0x00000400, 0xff200000, 0x00000408, 0xff202000, - 0x00000410, 0xff204000, 0x00000418, 0xff206100, - 0x00000420, 0xff208100, 0x00000429, 0xff20a100, - 0x00000431, 0xff20c200, 0x00000439, 0xff20e200, - 0x00000441, 0xff290000, 0x0000044a, 0xff292000, - 0x00000452, 0xff294000, 0x0000045a, 0xff296100, - 0x00000462, 0xff298100, 0x0000046a, 0xff29a100, - 0x00000473, 0xff29c200, 0x0000047b, 0xff29e200, - 0x00000483, 0xff310000, 0x0000048b, 0xff312000, - 0x00000494, 0xff314000, 0x0000049c, 0xff316100, - 0x000004a4, 0xff318100, 0x000004ac, 0xff31a100, - 0x000004b4, 0xff31c200, 0x000004bd, 0xff31e200, - 0x000004c5, 0xff390000, 0x000004cd, 0xff392000, - 0x000004d5, 0xff394000, 0x000004de, 0xff396100, - 0x000004e6, 0xff398100, 0x000004ee, 0xff39a100, - 0x000004f6, 0xff39c200, 0x000004ff, 0xff39e200, - 0x00000800, 0xff410000, 0x00000808, 0xff412000, - 0x00000810, 0xff414000, 0x00000818, 0xff416100, - 0x00000820, 0xff418100, 0x00000829, 0xff41a100, - 0x00000831, 0xff41c200, 0x00000839, 0xff41e200, - 0x00000841, 0xff4a0000, 0x0000084a, 0xff4a2000, - 0x00000852, 0xff4a4000, 0x0000085a, 0xff4a6100, - 0x00000862, 0xff4a8100, 0x0000086a, 0xff4aa100, - 0x00000873, 0xff4ac200, 0x0000087b, 0xff4ae200, - 0x00000883, 0xff520000, 0x0000088b, 0xff522000, - 0x00000894, 0xff524000, 0x0000089c, 0xff526100, - 0x000008a4, 0xff528100, 0x000008ac, 0xff52a100, - 0x000008b4, 0xff52c200, 0x000008bd, 0xff52e200, - 0x000008c5, 0xff5a0000, 0x000008cd, 0xff5a2000, - 0x000008d5, 0xff5a4000, 0x000008de, 0xff5a6100, - 0x000008e6, 0xff5a8100, 0x000008ee, 0xff5aa100, - 0x000008f6, 0xff5ac200, 0x000008ff, 0xff5ae200, - 0x00000c00, 0xff620000, 0x00000c08, 0xff622000, - 0x00000c10, 0xff624000, 0x00000c18, 0xff626100, - 0x00000c20, 0xff628100, 0x00000c29, 0xff62a100, - 0x00000c31, 0xff62c200, 0x00000c39, 0xff62e200, - 0x00000c41, 0xff6a0000, 0x00000c4a, 0xff6a2000, - 0x00000c52, 0xff6a4000, 0x00000c5a, 0xff6a6100, - 0x00000c62, 0xff6a8100, 0x00000c6a, 0xff6aa100, - 0x00000c73, 0xff6ac200, 0x00000c7b, 0xff6ae200, - 0x00000c83, 0xff730000, 0x00000c8b, 0xff732000, - 0x00000c94, 0xff734000, 0x00000c9c, 0xff736100, - 0x00000ca4, 0xff738100, 0x00000cac, 0xff73a100, - 0x00000cb4, 0xff73c200, 0x00000cbd, 0xff73e200, - 0x00000cc5, 0xff7b0000, 0x00000ccd, 0xff7b2000, - 0x00000cd5, 0xff7b4000, 0x00000cde, 0xff7b6100, - 0x00000ce6, 0xff7b8100, 0x00000cee, 0xff7ba100, - 0x00000cf6, 0xff7bc200, 0x00000cff, 0xff7be200, - 0x00001000, 0xff830000, 0x00001008, 0xff832000, - 0x00001010, 0xff834000, 0x00001018, 0xff836100, - 0x00001020, 0xff838100, 0x00001029, 0xff83a100, - 0x00001031, 0xff83c200, 0x00001039, 0xff83e200, - 0x00001041, 0xff8b0000, 0x0000104a, 0xff8b2000, - 0x00001052, 0xff8b4000, 0x0000105a, 0xff8b6100, - 0x00001062, 0xff8b8100, 0x0000106a, 0xff8ba100, - 0x00001073, 0xff8bc200, 0x0000107b, 0xff8be200, - 0x00001083, 0xff940000, 0x0000108b, 0xff942000, - 0x00001094, 0xff944000, 0x0000109c, 0xff946100, - 0x000010a4, 0xff948100, 0x000010ac, 0xff94a100, - 0x000010b4, 0xff94c200, 0x000010bd, 0xff94e200, - 0x000010c5, 0xff9c0000, 0x000010cd, 0xff9c2000, - 0x000010d5, 0xff9c4000, 0x000010de, 0xff9c6100, - 0x000010e6, 0xff9c8100, 0x000010ee, 0xff9ca100, - 0x000010f6, 0xff9cc200, 0x000010ff, 0xff9ce200, - 0x00001400, 0xffa40000, 0x00001408, 0xffa42000, - 0x00001410, 0xffa44000, 0x00001418, 0xffa46100, - 0x00001420, 0xffa48100, 0x00001429, 0xffa4a100, - 0x00001431, 0xffa4c200, 0x00001439, 0xffa4e200, - 0x00001441, 0xffac0000, 0x0000144a, 0xffac2000, - 0x00001452, 0xffac4000, 0x0000145a, 0xffac6100, - 0x00001462, 0xffac8100, 0x0000146a, 0xffaca100, - 0x00001473, 0xffacc200, 0x0000147b, 0xfface200, - 0x00001483, 0xffb40000, 0x0000148b, 0xffb42000, - 0x00001494, 0xffb44000, 0x0000149c, 0xffb46100, - 0x000014a4, 0xffb48100, 0x000014ac, 0xffb4a100, - 0x000014b4, 0xffb4c200, 0x000014bd, 0xffb4e200, - 0x000014c5, 0xffbd0000, 0x000014cd, 0xffbd2000, - 0x000014d5, 0xffbd4000, 0x000014de, 0xffbd6100, - 0x000014e6, 0xffbd8100, 0x000014ee, 0xffbda100, - 0x000014f6, 0xffbdc200, 0x000014ff, 0xffbde200, - 0x00001800, 0xffc50000, 0x00001808, 0xffc52000, - 0x00001810, 0xffc54000, 0x00001818, 0xffc56100, - 0x00001820, 0xffc58100, 0x00001829, 0xffc5a100, - 0x00001831, 0xffc5c200, 0x00001839, 0xffc5e200, - 0x00001841, 0xffcd0000, 0x0000184a, 0xffcd2000, - 0x00001852, 0xffcd4000, 0x0000185a, 0xffcd6100, - 0x00001862, 0xffcd8100, 0x0000186a, 0xffcda100, - 0x00001873, 0xffcdc200, 0x0000187b, 0xffcde200, - 0x00001883, 0xffd50000, 0x0000188b, 0xffd52000, - 0x00001894, 0xffd54000, 0x0000189c, 0xffd56100, - 0x000018a4, 0xffd58100, 0x000018ac, 0xffd5a100, - 0x000018b4, 0xffd5c200, 0x000018bd, 0xffd5e200, - 0x000018c5, 0xffde0000, 0x000018cd, 0xffde2000, - 0x000018d5, 0xffde4000, 0x000018de, 0xffde6100, - 0x000018e6, 0xffde8100, 0x000018ee, 0xffdea100, - 0x000018f6, 0xffdec200, 0x000018ff, 0xffdee200, - 0x00001c00, 0xffe60000, 0x00001c08, 0xffe62000, - 0x00001c10, 0xffe64000, 0x00001c18, 0xffe66100, - 0x00001c20, 0xffe68100, 0x00001c29, 0xffe6a100, - 0x00001c31, 0xffe6c200, 0x00001c39, 0xffe6e200, - 0x00001c41, 0xffee0000, 0x00001c4a, 0xffee2000, - 0x00001c52, 0xffee4000, 0x00001c5a, 0xffee6100, - 0x00001c62, 0xffee8100, 0x00001c6a, 0xffeea100, - 0x00001c73, 0xffeec200, 0x00001c7b, 0xffeee200, - 0x00001c83, 0xfff60000, 0x00001c8b, 0xfff62000, - 0x00001c94, 0xfff64000, 0x00001c9c, 0xfff66100, - 0x00001ca4, 0xfff68100, 0x00001cac, 0xfff6a100, - 0x00001cb4, 0xfff6c200, 0x00001cbd, 0xfff6e200, - 0x00001cc5, 0xffff0000, 0x00001ccd, 0xffff2000, - 0x00001cd5, 0xffff4000, 0x00001cde, 0xffff6100, - 0x00001ce6, 0xffff8100, 0x00001cee, 0xffffa100, - 0x00001cf6, 0xffffc200, 0x00001cff, 0xffffe200 -}; - -static void -Blit_RGB565_ARGB8888(SDL_BlitInfo * info) -{ - Blit_RGB565_32(info, RGB565_ARGB8888_LUT); -} - -/* Special optimized blit for RGB 5-6-5 --> ABGR 8-8-8-8 */ -static const Uint32 RGB565_ABGR8888_LUT[512] = { - 0xff000000, 0x00000000, 0xff080000, 0x00002000, - 0xff100000, 0x00004000, 0xff180000, 0x00006100, - 0xff200000, 0x00008100, 0xff290000, 0x0000a100, - 0xff310000, 0x0000c200, 0xff390000, 0x0000e200, - 0xff410000, 0x00000008, 0xff4a0000, 0x00002008, - 0xff520000, 0x00004008, 0xff5a0000, 0x00006108, - 0xff620000, 0x00008108, 0xff6a0000, 0x0000a108, - 0xff730000, 0x0000c208, 0xff7b0000, 0x0000e208, - 0xff830000, 0x00000010, 0xff8b0000, 0x00002010, - 0xff940000, 0x00004010, 0xff9c0000, 0x00006110, - 0xffa40000, 0x00008110, 0xffac0000, 0x0000a110, - 0xffb40000, 0x0000c210, 0xffbd0000, 0x0000e210, - 0xffc50000, 0x00000018, 0xffcd0000, 0x00002018, - 0xffd50000, 0x00004018, 0xffde0000, 0x00006118, - 0xffe60000, 0x00008118, 0xffee0000, 0x0000a118, - 0xfff60000, 0x0000c218, 0xffff0000, 0x0000e218, - 0xff000400, 0x00000020, 0xff080400, 0x00002020, - 0xff100400, 0x00004020, 0xff180400, 0x00006120, - 0xff200400, 0x00008120, 0xff290400, 0x0000a120, - 0xff310400, 0x0000c220, 0xff390400, 0x0000e220, - 0xff410400, 0x00000029, 0xff4a0400, 0x00002029, - 0xff520400, 0x00004029, 0xff5a0400, 0x00006129, - 0xff620400, 0x00008129, 0xff6a0400, 0x0000a129, - 0xff730400, 0x0000c229, 0xff7b0400, 0x0000e229, - 0xff830400, 0x00000031, 0xff8b0400, 0x00002031, - 0xff940400, 0x00004031, 0xff9c0400, 0x00006131, - 0xffa40400, 0x00008131, 0xffac0400, 0x0000a131, - 0xffb40400, 0x0000c231, 0xffbd0400, 0x0000e231, - 0xffc50400, 0x00000039, 0xffcd0400, 0x00002039, - 0xffd50400, 0x00004039, 0xffde0400, 0x00006139, - 0xffe60400, 0x00008139, 0xffee0400, 0x0000a139, - 0xfff60400, 0x0000c239, 0xffff0400, 0x0000e239, - 0xff000800, 0x00000041, 0xff080800, 0x00002041, - 0xff100800, 0x00004041, 0xff180800, 0x00006141, - 0xff200800, 0x00008141, 0xff290800, 0x0000a141, - 0xff310800, 0x0000c241, 0xff390800, 0x0000e241, - 0xff410800, 0x0000004a, 0xff4a0800, 0x0000204a, - 0xff520800, 0x0000404a, 0xff5a0800, 0x0000614a, - 0xff620800, 0x0000814a, 0xff6a0800, 0x0000a14a, - 0xff730800, 0x0000c24a, 0xff7b0800, 0x0000e24a, - 0xff830800, 0x00000052, 0xff8b0800, 0x00002052, - 0xff940800, 0x00004052, 0xff9c0800, 0x00006152, - 0xffa40800, 0x00008152, 0xffac0800, 0x0000a152, - 0xffb40800, 0x0000c252, 0xffbd0800, 0x0000e252, - 0xffc50800, 0x0000005a, 0xffcd0800, 0x0000205a, - 0xffd50800, 0x0000405a, 0xffde0800, 0x0000615a, - 0xffe60800, 0x0000815a, 0xffee0800, 0x0000a15a, - 0xfff60800, 0x0000c25a, 0xffff0800, 0x0000e25a, - 0xff000c00, 0x00000062, 0xff080c00, 0x00002062, - 0xff100c00, 0x00004062, 0xff180c00, 0x00006162, - 0xff200c00, 0x00008162, 0xff290c00, 0x0000a162, - 0xff310c00, 0x0000c262, 0xff390c00, 0x0000e262, - 0xff410c00, 0x0000006a, 0xff4a0c00, 0x0000206a, - 0xff520c00, 0x0000406a, 0xff5a0c00, 0x0000616a, - 0xff620c00, 0x0000816a, 0xff6a0c00, 0x0000a16a, - 0xff730c00, 0x0000c26a, 0xff7b0c00, 0x0000e26a, - 0xff830c00, 0x00000073, 0xff8b0c00, 0x00002073, - 0xff940c00, 0x00004073, 0xff9c0c00, 0x00006173, - 0xffa40c00, 0x00008173, 0xffac0c00, 0x0000a173, - 0xffb40c00, 0x0000c273, 0xffbd0c00, 0x0000e273, - 0xffc50c00, 0x0000007b, 0xffcd0c00, 0x0000207b, - 0xffd50c00, 0x0000407b, 0xffde0c00, 0x0000617b, - 0xffe60c00, 0x0000817b, 0xffee0c00, 0x0000a17b, - 0xfff60c00, 0x0000c27b, 0xffff0c00, 0x0000e27b, - 0xff001000, 0x00000083, 0xff081000, 0x00002083, - 0xff101000, 0x00004083, 0xff181000, 0x00006183, - 0xff201000, 0x00008183, 0xff291000, 0x0000a183, - 0xff311000, 0x0000c283, 0xff391000, 0x0000e283, - 0xff411000, 0x0000008b, 0xff4a1000, 0x0000208b, - 0xff521000, 0x0000408b, 0xff5a1000, 0x0000618b, - 0xff621000, 0x0000818b, 0xff6a1000, 0x0000a18b, - 0xff731000, 0x0000c28b, 0xff7b1000, 0x0000e28b, - 0xff831000, 0x00000094, 0xff8b1000, 0x00002094, - 0xff941000, 0x00004094, 0xff9c1000, 0x00006194, - 0xffa41000, 0x00008194, 0xffac1000, 0x0000a194, - 0xffb41000, 0x0000c294, 0xffbd1000, 0x0000e294, - 0xffc51000, 0x0000009c, 0xffcd1000, 0x0000209c, - 0xffd51000, 0x0000409c, 0xffde1000, 0x0000619c, - 0xffe61000, 0x0000819c, 0xffee1000, 0x0000a19c, - 0xfff61000, 0x0000c29c, 0xffff1000, 0x0000e29c, - 0xff001400, 0x000000a4, 0xff081400, 0x000020a4, - 0xff101400, 0x000040a4, 0xff181400, 0x000061a4, - 0xff201400, 0x000081a4, 0xff291400, 0x0000a1a4, - 0xff311400, 0x0000c2a4, 0xff391400, 0x0000e2a4, - 0xff411400, 0x000000ac, 0xff4a1400, 0x000020ac, - 0xff521400, 0x000040ac, 0xff5a1400, 0x000061ac, - 0xff621400, 0x000081ac, 0xff6a1400, 0x0000a1ac, - 0xff731400, 0x0000c2ac, 0xff7b1400, 0x0000e2ac, - 0xff831400, 0x000000b4, 0xff8b1400, 0x000020b4, - 0xff941400, 0x000040b4, 0xff9c1400, 0x000061b4, - 0xffa41400, 0x000081b4, 0xffac1400, 0x0000a1b4, - 0xffb41400, 0x0000c2b4, 0xffbd1400, 0x0000e2b4, - 0xffc51400, 0x000000bd, 0xffcd1400, 0x000020bd, - 0xffd51400, 0x000040bd, 0xffde1400, 0x000061bd, - 0xffe61400, 0x000081bd, 0xffee1400, 0x0000a1bd, - 0xfff61400, 0x0000c2bd, 0xffff1400, 0x0000e2bd, - 0xff001800, 0x000000c5, 0xff081800, 0x000020c5, - 0xff101800, 0x000040c5, 0xff181800, 0x000061c5, - 0xff201800, 0x000081c5, 0xff291800, 0x0000a1c5, - 0xff311800, 0x0000c2c5, 0xff391800, 0x0000e2c5, - 0xff411800, 0x000000cd, 0xff4a1800, 0x000020cd, - 0xff521800, 0x000040cd, 0xff5a1800, 0x000061cd, - 0xff621800, 0x000081cd, 0xff6a1800, 0x0000a1cd, - 0xff731800, 0x0000c2cd, 0xff7b1800, 0x0000e2cd, - 0xff831800, 0x000000d5, 0xff8b1800, 0x000020d5, - 0xff941800, 0x000040d5, 0xff9c1800, 0x000061d5, - 0xffa41800, 0x000081d5, 0xffac1800, 0x0000a1d5, - 0xffb41800, 0x0000c2d5, 0xffbd1800, 0x0000e2d5, - 0xffc51800, 0x000000de, 0xffcd1800, 0x000020de, - 0xffd51800, 0x000040de, 0xffde1800, 0x000061de, - 0xffe61800, 0x000081de, 0xffee1800, 0x0000a1de, - 0xfff61800, 0x0000c2de, 0xffff1800, 0x0000e2de, - 0xff001c00, 0x000000e6, 0xff081c00, 0x000020e6, - 0xff101c00, 0x000040e6, 0xff181c00, 0x000061e6, - 0xff201c00, 0x000081e6, 0xff291c00, 0x0000a1e6, - 0xff311c00, 0x0000c2e6, 0xff391c00, 0x0000e2e6, - 0xff411c00, 0x000000ee, 0xff4a1c00, 0x000020ee, - 0xff521c00, 0x000040ee, 0xff5a1c00, 0x000061ee, - 0xff621c00, 0x000081ee, 0xff6a1c00, 0x0000a1ee, - 0xff731c00, 0x0000c2ee, 0xff7b1c00, 0x0000e2ee, - 0xff831c00, 0x000000f6, 0xff8b1c00, 0x000020f6, - 0xff941c00, 0x000040f6, 0xff9c1c00, 0x000061f6, - 0xffa41c00, 0x000081f6, 0xffac1c00, 0x0000a1f6, - 0xffb41c00, 0x0000c2f6, 0xffbd1c00, 0x0000e2f6, - 0xffc51c00, 0x000000ff, 0xffcd1c00, 0x000020ff, - 0xffd51c00, 0x000040ff, 0xffde1c00, 0x000061ff, - 0xffe61c00, 0x000081ff, 0xffee1c00, 0x0000a1ff, - 0xfff61c00, 0x0000c2ff, 0xffff1c00, 0x0000e2ff -}; - -static void -Blit_RGB565_ABGR8888(SDL_BlitInfo * info) -{ - Blit_RGB565_32(info, RGB565_ABGR8888_LUT); -} - -/* Special optimized blit for RGB 5-6-5 --> RGBA 8-8-8-8 */ -static const Uint32 RGB565_RGBA8888_LUT[512] = { - 0x000000ff, 0x00000000, 0x000008ff, 0x00200000, - 0x000010ff, 0x00400000, 0x000018ff, 0x00610000, - 0x000020ff, 0x00810000, 0x000029ff, 0x00a10000, - 0x000031ff, 0x00c20000, 0x000039ff, 0x00e20000, - 0x000041ff, 0x08000000, 0x00004aff, 0x08200000, - 0x000052ff, 0x08400000, 0x00005aff, 0x08610000, - 0x000062ff, 0x08810000, 0x00006aff, 0x08a10000, - 0x000073ff, 0x08c20000, 0x00007bff, 0x08e20000, - 0x000083ff, 0x10000000, 0x00008bff, 0x10200000, - 0x000094ff, 0x10400000, 0x00009cff, 0x10610000, - 0x0000a4ff, 0x10810000, 0x0000acff, 0x10a10000, - 0x0000b4ff, 0x10c20000, 0x0000bdff, 0x10e20000, - 0x0000c5ff, 0x18000000, 0x0000cdff, 0x18200000, - 0x0000d5ff, 0x18400000, 0x0000deff, 0x18610000, - 0x0000e6ff, 0x18810000, 0x0000eeff, 0x18a10000, - 0x0000f6ff, 0x18c20000, 0x0000ffff, 0x18e20000, - 0x000400ff, 0x20000000, 0x000408ff, 0x20200000, - 0x000410ff, 0x20400000, 0x000418ff, 0x20610000, - 0x000420ff, 0x20810000, 0x000429ff, 0x20a10000, - 0x000431ff, 0x20c20000, 0x000439ff, 0x20e20000, - 0x000441ff, 0x29000000, 0x00044aff, 0x29200000, - 0x000452ff, 0x29400000, 0x00045aff, 0x29610000, - 0x000462ff, 0x29810000, 0x00046aff, 0x29a10000, - 0x000473ff, 0x29c20000, 0x00047bff, 0x29e20000, - 0x000483ff, 0x31000000, 0x00048bff, 0x31200000, - 0x000494ff, 0x31400000, 0x00049cff, 0x31610000, - 0x0004a4ff, 0x31810000, 0x0004acff, 0x31a10000, - 0x0004b4ff, 0x31c20000, 0x0004bdff, 0x31e20000, - 0x0004c5ff, 0x39000000, 0x0004cdff, 0x39200000, - 0x0004d5ff, 0x39400000, 0x0004deff, 0x39610000, - 0x0004e6ff, 0x39810000, 0x0004eeff, 0x39a10000, - 0x0004f6ff, 0x39c20000, 0x0004ffff, 0x39e20000, - 0x000800ff, 0x41000000, 0x000808ff, 0x41200000, - 0x000810ff, 0x41400000, 0x000818ff, 0x41610000, - 0x000820ff, 0x41810000, 0x000829ff, 0x41a10000, - 0x000831ff, 0x41c20000, 0x000839ff, 0x41e20000, - 0x000841ff, 0x4a000000, 0x00084aff, 0x4a200000, - 0x000852ff, 0x4a400000, 0x00085aff, 0x4a610000, - 0x000862ff, 0x4a810000, 0x00086aff, 0x4aa10000, - 0x000873ff, 0x4ac20000, 0x00087bff, 0x4ae20000, - 0x000883ff, 0x52000000, 0x00088bff, 0x52200000, - 0x000894ff, 0x52400000, 0x00089cff, 0x52610000, - 0x0008a4ff, 0x52810000, 0x0008acff, 0x52a10000, - 0x0008b4ff, 0x52c20000, 0x0008bdff, 0x52e20000, - 0x0008c5ff, 0x5a000000, 0x0008cdff, 0x5a200000, - 0x0008d5ff, 0x5a400000, 0x0008deff, 0x5a610000, - 0x0008e6ff, 0x5a810000, 0x0008eeff, 0x5aa10000, - 0x0008f6ff, 0x5ac20000, 0x0008ffff, 0x5ae20000, - 0x000c00ff, 0x62000000, 0x000c08ff, 0x62200000, - 0x000c10ff, 0x62400000, 0x000c18ff, 0x62610000, - 0x000c20ff, 0x62810000, 0x000c29ff, 0x62a10000, - 0x000c31ff, 0x62c20000, 0x000c39ff, 0x62e20000, - 0x000c41ff, 0x6a000000, 0x000c4aff, 0x6a200000, - 0x000c52ff, 0x6a400000, 0x000c5aff, 0x6a610000, - 0x000c62ff, 0x6a810000, 0x000c6aff, 0x6aa10000, - 0x000c73ff, 0x6ac20000, 0x000c7bff, 0x6ae20000, - 0x000c83ff, 0x73000000, 0x000c8bff, 0x73200000, - 0x000c94ff, 0x73400000, 0x000c9cff, 0x73610000, - 0x000ca4ff, 0x73810000, 0x000cacff, 0x73a10000, - 0x000cb4ff, 0x73c20000, 0x000cbdff, 0x73e20000, - 0x000cc5ff, 0x7b000000, 0x000ccdff, 0x7b200000, - 0x000cd5ff, 0x7b400000, 0x000cdeff, 0x7b610000, - 0x000ce6ff, 0x7b810000, 0x000ceeff, 0x7ba10000, - 0x000cf6ff, 0x7bc20000, 0x000cffff, 0x7be20000, - 0x001000ff, 0x83000000, 0x001008ff, 0x83200000, - 0x001010ff, 0x83400000, 0x001018ff, 0x83610000, - 0x001020ff, 0x83810000, 0x001029ff, 0x83a10000, - 0x001031ff, 0x83c20000, 0x001039ff, 0x83e20000, - 0x001041ff, 0x8b000000, 0x00104aff, 0x8b200000, - 0x001052ff, 0x8b400000, 0x00105aff, 0x8b610000, - 0x001062ff, 0x8b810000, 0x00106aff, 0x8ba10000, - 0x001073ff, 0x8bc20000, 0x00107bff, 0x8be20000, - 0x001083ff, 0x94000000, 0x00108bff, 0x94200000, - 0x001094ff, 0x94400000, 0x00109cff, 0x94610000, - 0x0010a4ff, 0x94810000, 0x0010acff, 0x94a10000, - 0x0010b4ff, 0x94c20000, 0x0010bdff, 0x94e20000, - 0x0010c5ff, 0x9c000000, 0x0010cdff, 0x9c200000, - 0x0010d5ff, 0x9c400000, 0x0010deff, 0x9c610000, - 0x0010e6ff, 0x9c810000, 0x0010eeff, 0x9ca10000, - 0x0010f6ff, 0x9cc20000, 0x0010ffff, 0x9ce20000, - 0x001400ff, 0xa4000000, 0x001408ff, 0xa4200000, - 0x001410ff, 0xa4400000, 0x001418ff, 0xa4610000, - 0x001420ff, 0xa4810000, 0x001429ff, 0xa4a10000, - 0x001431ff, 0xa4c20000, 0x001439ff, 0xa4e20000, - 0x001441ff, 0xac000000, 0x00144aff, 0xac200000, - 0x001452ff, 0xac400000, 0x00145aff, 0xac610000, - 0x001462ff, 0xac810000, 0x00146aff, 0xaca10000, - 0x001473ff, 0xacc20000, 0x00147bff, 0xace20000, - 0x001483ff, 0xb4000000, 0x00148bff, 0xb4200000, - 0x001494ff, 0xb4400000, 0x00149cff, 0xb4610000, - 0x0014a4ff, 0xb4810000, 0x0014acff, 0xb4a10000, - 0x0014b4ff, 0xb4c20000, 0x0014bdff, 0xb4e20000, - 0x0014c5ff, 0xbd000000, 0x0014cdff, 0xbd200000, - 0x0014d5ff, 0xbd400000, 0x0014deff, 0xbd610000, - 0x0014e6ff, 0xbd810000, 0x0014eeff, 0xbda10000, - 0x0014f6ff, 0xbdc20000, 0x0014ffff, 0xbde20000, - 0x001800ff, 0xc5000000, 0x001808ff, 0xc5200000, - 0x001810ff, 0xc5400000, 0x001818ff, 0xc5610000, - 0x001820ff, 0xc5810000, 0x001829ff, 0xc5a10000, - 0x001831ff, 0xc5c20000, 0x001839ff, 0xc5e20000, - 0x001841ff, 0xcd000000, 0x00184aff, 0xcd200000, - 0x001852ff, 0xcd400000, 0x00185aff, 0xcd610000, - 0x001862ff, 0xcd810000, 0x00186aff, 0xcda10000, - 0x001873ff, 0xcdc20000, 0x00187bff, 0xcde20000, - 0x001883ff, 0xd5000000, 0x00188bff, 0xd5200000, - 0x001894ff, 0xd5400000, 0x00189cff, 0xd5610000, - 0x0018a4ff, 0xd5810000, 0x0018acff, 0xd5a10000, - 0x0018b4ff, 0xd5c20000, 0x0018bdff, 0xd5e20000, - 0x0018c5ff, 0xde000000, 0x0018cdff, 0xde200000, - 0x0018d5ff, 0xde400000, 0x0018deff, 0xde610000, - 0x0018e6ff, 0xde810000, 0x0018eeff, 0xdea10000, - 0x0018f6ff, 0xdec20000, 0x0018ffff, 0xdee20000, - 0x001c00ff, 0xe6000000, 0x001c08ff, 0xe6200000, - 0x001c10ff, 0xe6400000, 0x001c18ff, 0xe6610000, - 0x001c20ff, 0xe6810000, 0x001c29ff, 0xe6a10000, - 0x001c31ff, 0xe6c20000, 0x001c39ff, 0xe6e20000, - 0x001c41ff, 0xee000000, 0x001c4aff, 0xee200000, - 0x001c52ff, 0xee400000, 0x001c5aff, 0xee610000, - 0x001c62ff, 0xee810000, 0x001c6aff, 0xeea10000, - 0x001c73ff, 0xeec20000, 0x001c7bff, 0xeee20000, - 0x001c83ff, 0xf6000000, 0x001c8bff, 0xf6200000, - 0x001c94ff, 0xf6400000, 0x001c9cff, 0xf6610000, - 0x001ca4ff, 0xf6810000, 0x001cacff, 0xf6a10000, - 0x001cb4ff, 0xf6c20000, 0x001cbdff, 0xf6e20000, - 0x001cc5ff, 0xff000000, 0x001ccdff, 0xff200000, - 0x001cd5ff, 0xff400000, 0x001cdeff, 0xff610000, - 0x001ce6ff, 0xff810000, 0x001ceeff, 0xffa10000, - 0x001cf6ff, 0xffc20000, 0x001cffff, 0xffe20000, -}; - -static void -Blit_RGB565_RGBA8888(SDL_BlitInfo * info) -{ - Blit_RGB565_32(info, RGB565_RGBA8888_LUT); -} - -/* Special optimized blit for RGB 5-6-5 --> BGRA 8-8-8-8 */ -static const Uint32 RGB565_BGRA8888_LUT[512] = { - 0x00000000, 0x000000ff, 0x08000000, 0x002000ff, - 0x10000000, 0x004000ff, 0x18000000, 0x006100ff, - 0x20000000, 0x008100ff, 0x29000000, 0x00a100ff, - 0x31000000, 0x00c200ff, 0x39000000, 0x00e200ff, - 0x41000000, 0x000008ff, 0x4a000000, 0x002008ff, - 0x52000000, 0x004008ff, 0x5a000000, 0x006108ff, - 0x62000000, 0x008108ff, 0x6a000000, 0x00a108ff, - 0x73000000, 0x00c208ff, 0x7b000000, 0x00e208ff, - 0x83000000, 0x000010ff, 0x8b000000, 0x002010ff, - 0x94000000, 0x004010ff, 0x9c000000, 0x006110ff, - 0xa4000000, 0x008110ff, 0xac000000, 0x00a110ff, - 0xb4000000, 0x00c210ff, 0xbd000000, 0x00e210ff, - 0xc5000000, 0x000018ff, 0xcd000000, 0x002018ff, - 0xd5000000, 0x004018ff, 0xde000000, 0x006118ff, - 0xe6000000, 0x008118ff, 0xee000000, 0x00a118ff, - 0xf6000000, 0x00c218ff, 0xff000000, 0x00e218ff, - 0x00040000, 0x000020ff, 0x08040000, 0x002020ff, - 0x10040000, 0x004020ff, 0x18040000, 0x006120ff, - 0x20040000, 0x008120ff, 0x29040000, 0x00a120ff, - 0x31040000, 0x00c220ff, 0x39040000, 0x00e220ff, - 0x41040000, 0x000029ff, 0x4a040000, 0x002029ff, - 0x52040000, 0x004029ff, 0x5a040000, 0x006129ff, - 0x62040000, 0x008129ff, 0x6a040000, 0x00a129ff, - 0x73040000, 0x00c229ff, 0x7b040000, 0x00e229ff, - 0x83040000, 0x000031ff, 0x8b040000, 0x002031ff, - 0x94040000, 0x004031ff, 0x9c040000, 0x006131ff, - 0xa4040000, 0x008131ff, 0xac040000, 0x00a131ff, - 0xb4040000, 0x00c231ff, 0xbd040000, 0x00e231ff, - 0xc5040000, 0x000039ff, 0xcd040000, 0x002039ff, - 0xd5040000, 0x004039ff, 0xde040000, 0x006139ff, - 0xe6040000, 0x008139ff, 0xee040000, 0x00a139ff, - 0xf6040000, 0x00c239ff, 0xff040000, 0x00e239ff, - 0x00080000, 0x000041ff, 0x08080000, 0x002041ff, - 0x10080000, 0x004041ff, 0x18080000, 0x006141ff, - 0x20080000, 0x008141ff, 0x29080000, 0x00a141ff, - 0x31080000, 0x00c241ff, 0x39080000, 0x00e241ff, - 0x41080000, 0x00004aff, 0x4a080000, 0x00204aff, - 0x52080000, 0x00404aff, 0x5a080000, 0x00614aff, - 0x62080000, 0x00814aff, 0x6a080000, 0x00a14aff, - 0x73080000, 0x00c24aff, 0x7b080000, 0x00e24aff, - 0x83080000, 0x000052ff, 0x8b080000, 0x002052ff, - 0x94080000, 0x004052ff, 0x9c080000, 0x006152ff, - 0xa4080000, 0x008152ff, 0xac080000, 0x00a152ff, - 0xb4080000, 0x00c252ff, 0xbd080000, 0x00e252ff, - 0xc5080000, 0x00005aff, 0xcd080000, 0x00205aff, - 0xd5080000, 0x00405aff, 0xde080000, 0x00615aff, - 0xe6080000, 0x00815aff, 0xee080000, 0x00a15aff, - 0xf6080000, 0x00c25aff, 0xff080000, 0x00e25aff, - 0x000c0000, 0x000062ff, 0x080c0000, 0x002062ff, - 0x100c0000, 0x004062ff, 0x180c0000, 0x006162ff, - 0x200c0000, 0x008162ff, 0x290c0000, 0x00a162ff, - 0x310c0000, 0x00c262ff, 0x390c0000, 0x00e262ff, - 0x410c0000, 0x00006aff, 0x4a0c0000, 0x00206aff, - 0x520c0000, 0x00406aff, 0x5a0c0000, 0x00616aff, - 0x620c0000, 0x00816aff, 0x6a0c0000, 0x00a16aff, - 0x730c0000, 0x00c26aff, 0x7b0c0000, 0x00e26aff, - 0x830c0000, 0x000073ff, 0x8b0c0000, 0x002073ff, - 0x940c0000, 0x004073ff, 0x9c0c0000, 0x006173ff, - 0xa40c0000, 0x008173ff, 0xac0c0000, 0x00a173ff, - 0xb40c0000, 0x00c273ff, 0xbd0c0000, 0x00e273ff, - 0xc50c0000, 0x00007bff, 0xcd0c0000, 0x00207bff, - 0xd50c0000, 0x00407bff, 0xde0c0000, 0x00617bff, - 0xe60c0000, 0x00817bff, 0xee0c0000, 0x00a17bff, - 0xf60c0000, 0x00c27bff, 0xff0c0000, 0x00e27bff, - 0x00100000, 0x000083ff, 0x08100000, 0x002083ff, - 0x10100000, 0x004083ff, 0x18100000, 0x006183ff, - 0x20100000, 0x008183ff, 0x29100000, 0x00a183ff, - 0x31100000, 0x00c283ff, 0x39100000, 0x00e283ff, - 0x41100000, 0x00008bff, 0x4a100000, 0x00208bff, - 0x52100000, 0x00408bff, 0x5a100000, 0x00618bff, - 0x62100000, 0x00818bff, 0x6a100000, 0x00a18bff, - 0x73100000, 0x00c28bff, 0x7b100000, 0x00e28bff, - 0x83100000, 0x000094ff, 0x8b100000, 0x002094ff, - 0x94100000, 0x004094ff, 0x9c100000, 0x006194ff, - 0xa4100000, 0x008194ff, 0xac100000, 0x00a194ff, - 0xb4100000, 0x00c294ff, 0xbd100000, 0x00e294ff, - 0xc5100000, 0x00009cff, 0xcd100000, 0x00209cff, - 0xd5100000, 0x00409cff, 0xde100000, 0x00619cff, - 0xe6100000, 0x00819cff, 0xee100000, 0x00a19cff, - 0xf6100000, 0x00c29cff, 0xff100000, 0x00e29cff, - 0x00140000, 0x0000a4ff, 0x08140000, 0x0020a4ff, - 0x10140000, 0x0040a4ff, 0x18140000, 0x0061a4ff, - 0x20140000, 0x0081a4ff, 0x29140000, 0x00a1a4ff, - 0x31140000, 0x00c2a4ff, 0x39140000, 0x00e2a4ff, - 0x41140000, 0x0000acff, 0x4a140000, 0x0020acff, - 0x52140000, 0x0040acff, 0x5a140000, 0x0061acff, - 0x62140000, 0x0081acff, 0x6a140000, 0x00a1acff, - 0x73140000, 0x00c2acff, 0x7b140000, 0x00e2acff, - 0x83140000, 0x0000b4ff, 0x8b140000, 0x0020b4ff, - 0x94140000, 0x0040b4ff, 0x9c140000, 0x0061b4ff, - 0xa4140000, 0x0081b4ff, 0xac140000, 0x00a1b4ff, - 0xb4140000, 0x00c2b4ff, 0xbd140000, 0x00e2b4ff, - 0xc5140000, 0x0000bdff, 0xcd140000, 0x0020bdff, - 0xd5140000, 0x0040bdff, 0xde140000, 0x0061bdff, - 0xe6140000, 0x0081bdff, 0xee140000, 0x00a1bdff, - 0xf6140000, 0x00c2bdff, 0xff140000, 0x00e2bdff, - 0x00180000, 0x0000c5ff, 0x08180000, 0x0020c5ff, - 0x10180000, 0x0040c5ff, 0x18180000, 0x0061c5ff, - 0x20180000, 0x0081c5ff, 0x29180000, 0x00a1c5ff, - 0x31180000, 0x00c2c5ff, 0x39180000, 0x00e2c5ff, - 0x41180000, 0x0000cdff, 0x4a180000, 0x0020cdff, - 0x52180000, 0x0040cdff, 0x5a180000, 0x0061cdff, - 0x62180000, 0x0081cdff, 0x6a180000, 0x00a1cdff, - 0x73180000, 0x00c2cdff, 0x7b180000, 0x00e2cdff, - 0x83180000, 0x0000d5ff, 0x8b180000, 0x0020d5ff, - 0x94180000, 0x0040d5ff, 0x9c180000, 0x0061d5ff, - 0xa4180000, 0x0081d5ff, 0xac180000, 0x00a1d5ff, - 0xb4180000, 0x00c2d5ff, 0xbd180000, 0x00e2d5ff, - 0xc5180000, 0x0000deff, 0xcd180000, 0x0020deff, - 0xd5180000, 0x0040deff, 0xde180000, 0x0061deff, - 0xe6180000, 0x0081deff, 0xee180000, 0x00a1deff, - 0xf6180000, 0x00c2deff, 0xff180000, 0x00e2deff, - 0x001c0000, 0x0000e6ff, 0x081c0000, 0x0020e6ff, - 0x101c0000, 0x0040e6ff, 0x181c0000, 0x0061e6ff, - 0x201c0000, 0x0081e6ff, 0x291c0000, 0x00a1e6ff, - 0x311c0000, 0x00c2e6ff, 0x391c0000, 0x00e2e6ff, - 0x411c0000, 0x0000eeff, 0x4a1c0000, 0x0020eeff, - 0x521c0000, 0x0040eeff, 0x5a1c0000, 0x0061eeff, - 0x621c0000, 0x0081eeff, 0x6a1c0000, 0x00a1eeff, - 0x731c0000, 0x00c2eeff, 0x7b1c0000, 0x00e2eeff, - 0x831c0000, 0x0000f6ff, 0x8b1c0000, 0x0020f6ff, - 0x941c0000, 0x0040f6ff, 0x9c1c0000, 0x0061f6ff, - 0xa41c0000, 0x0081f6ff, 0xac1c0000, 0x00a1f6ff, - 0xb41c0000, 0x00c2f6ff, 0xbd1c0000, 0x00e2f6ff, - 0xc51c0000, 0x0000ffff, 0xcd1c0000, 0x0020ffff, - 0xd51c0000, 0x0040ffff, 0xde1c0000, 0x0061ffff, - 0xe61c0000, 0x0081ffff, 0xee1c0000, 0x00a1ffff, - 0xf61c0000, 0x00c2ffff, 0xff1c0000, 0x00e2ffff -}; - -static void -Blit_RGB565_BGRA8888(SDL_BlitInfo * info) -{ - Blit_RGB565_32(info, RGB565_BGRA8888_LUT); -} - -/* Special optimized blit for RGB 8-8-8 --> RGB 3-3-2 */ -#ifndef RGB888_RGB332 -#define RGB888_RGB332(dst, src) { \ - dst = (((src)&0x00E00000)>>16)| \ - (((src)&0x0000E000)>>11)| \ - (((src)&0x000000C0)>>6); \ -} -#endif -static void -Blit_RGB888_index8_map(SDL_BlitInfo * info) -{ -#ifndef USE_DUFFS_LOOP - int c; -#endif - int Pixel; - int width, height; - Uint32 *src; - const Uint8 *map; - Uint8 *dst; - int srcskip, dstskip; - - /* Set up some basic variables */ - width = info->dst_w; - height = info->dst_h; - src = (Uint32 *) info->src; - srcskip = info->src_skip / 4; - dst = info->dst; - dstskip = info->dst_skip; - map = info->table; - -#ifdef USE_DUFFS_LOOP - while (height--) { - /* *INDENT-OFF* */ - DUFFS_LOOP( - RGB888_RGB332(Pixel, *src); - *dst++ = map[Pixel]; - ++src; - , width); - /* *INDENT-ON* */ - src += srcskip; - dst += dstskip; - } -#else - while (height--) { - for (c = width / 4; c; --c) { - /* Pack RGB into 8bit pixel */ - RGB888_RGB332(Pixel, *src); - *dst++ = map[Pixel]; - ++src; - RGB888_RGB332(Pixel, *src); - *dst++ = map[Pixel]; - ++src; - RGB888_RGB332(Pixel, *src); - *dst++ = map[Pixel]; - ++src; - RGB888_RGB332(Pixel, *src); - *dst++ = map[Pixel]; - ++src; - } - switch (width & 3) { - case 3: - RGB888_RGB332(Pixel, *src); - *dst++ = map[Pixel]; - ++src; - case 2: - RGB888_RGB332(Pixel, *src); - *dst++ = map[Pixel]; - ++src; - case 1: - RGB888_RGB332(Pixel, *src); - *dst++ = map[Pixel]; - ++src; - } - src += srcskip; - dst += dstskip; - } -#endif /* USE_DUFFS_LOOP */ -} - -static void -BlitNto1(SDL_BlitInfo * info) -{ -#ifndef USE_DUFFS_LOOP - int c; -#endif - int width, height; - Uint8 *src; - const Uint8 *map; - Uint8 *dst; - int srcskip, dstskip; - int srcbpp; - Uint32 Pixel; - int sR, sG, sB; - SDL_PixelFormat *srcfmt; - - /* Set up some basic variables */ - width = info->dst_w; - height = info->dst_h; - src = info->src; - srcskip = info->src_skip; - dst = info->dst; - dstskip = info->dst_skip; - map = info->table; - srcfmt = info->src_fmt; - srcbpp = srcfmt->BytesPerPixel; - - if (map == NULL) { - while (height--) { -#ifdef USE_DUFFS_LOOP - /* *INDENT-OFF* */ - DUFFS_LOOP( - DISEMBLE_RGB(src, srcbpp, srcfmt, Pixel, - sR, sG, sB); - if ( 1 ) { - /* Pack RGB into 8bit pixel */ - *dst = ((sR>>5)<<(3+2))| - ((sG>>5)<<(2)) | - ((sB>>6)<<(0)) ; - } - dst++; - src += srcbpp; - , width); - /* *INDENT-ON* */ -#else - for (c = width; c; --c) { - DISEMBLE_RGB(src, srcbpp, srcfmt, Pixel, sR, sG, sB); - if (1) { - /* Pack RGB into 8bit pixel */ - *dst = ((sR >> 5) << (3 + 2)) | - ((sG >> 5) << (2)) | ((sB >> 6) << (0)); - } - dst++; - src += srcbpp; - } -#endif - src += srcskip; - dst += dstskip; - } - } else { - while (height--) { -#ifdef USE_DUFFS_LOOP - /* *INDENT-OFF* */ - DUFFS_LOOP( - DISEMBLE_RGB(src, srcbpp, srcfmt, Pixel, - sR, sG, sB); - if ( 1 ) { - /* Pack RGB into 8bit pixel */ - *dst = map[((sR>>5)<<(3+2))| - ((sG>>5)<<(2)) | - ((sB>>6)<<(0)) ]; - } - dst++; - src += srcbpp; - , width); - /* *INDENT-ON* */ -#else - for (c = width; c; --c) { - DISEMBLE_RGB(src, srcbpp, srcfmt, Pixel, sR, sG, sB); - if (1) { - /* Pack RGB into 8bit pixel */ - *dst = map[((sR >> 5) << (3 + 2)) | - ((sG >> 5) << (2)) | ((sB >> 6) << (0))]; - } - dst++; - src += srcbpp; - } -#endif /* USE_DUFFS_LOOP */ - src += srcskip; - dst += dstskip; - } - } -} - -/* blits 32 bit RGB<->RGBA with both surfaces having the same R,G,B fields */ -static void -Blit4to4MaskAlpha(SDL_BlitInfo * info) -{ - int width = info->dst_w; - int height = info->dst_h; - Uint32 *src = (Uint32 *) info->src; - int srcskip = info->src_skip; - Uint32 *dst = (Uint32 *) info->dst; - int dstskip = info->dst_skip; - SDL_PixelFormat *srcfmt = info->src_fmt; - SDL_PixelFormat *dstfmt = info->dst_fmt; - - if (dstfmt->Amask) { - /* RGB->RGBA, SET_ALPHA */ - Uint32 mask = (info->a >> dstfmt->Aloss) << dstfmt->Ashift; - - while (height--) { - /* *INDENT-OFF* */ - DUFFS_LOOP( - { - *dst = *src | mask; - ++dst; - ++src; - }, - width); - /* *INDENT-ON* */ - src = (Uint32 *) ((Uint8 *) src + srcskip); - dst = (Uint32 *) ((Uint8 *) dst + dstskip); - } - } else { - /* RGBA->RGB, NO_ALPHA */ - Uint32 mask = srcfmt->Rmask | srcfmt->Gmask | srcfmt->Bmask; - - while (height--) { - /* *INDENT-OFF* */ - DUFFS_LOOP( - { - *dst = *src & mask; - ++dst; - ++src; - }, - width); - /* *INDENT-ON* */ - src = (Uint32 *) ((Uint8 *) src + srcskip); - dst = (Uint32 *) ((Uint8 *) dst + dstskip); - } - } -} - -static void -BlitNtoN(SDL_BlitInfo * info) -{ - int width = info->dst_w; - int height = info->dst_h; - Uint8 *src = info->src; - int srcskip = info->src_skip; - Uint8 *dst = info->dst; - int dstskip = info->dst_skip; - SDL_PixelFormat *srcfmt = info->src_fmt; - int srcbpp = srcfmt->BytesPerPixel; - SDL_PixelFormat *dstfmt = info->dst_fmt; - int dstbpp = dstfmt->BytesPerPixel; - unsigned alpha = dstfmt->Amask ? info->a : 0; - - while (height--) { - /* *INDENT-OFF* */ - DUFFS_LOOP( - { - Uint32 Pixel; - unsigned sR; - unsigned sG; - unsigned sB; - DISEMBLE_RGB(src, srcbpp, srcfmt, Pixel, sR, sG, sB); - ASSEMBLE_RGBA(dst, dstbpp, dstfmt, sR, sG, sB, alpha); - dst += dstbpp; - src += srcbpp; - }, - width); - /* *INDENT-ON* */ - src += srcskip; - dst += dstskip; - } -} - -static void -BlitNtoNCopyAlpha(SDL_BlitInfo * info) -{ - int width = info->dst_w; - int height = info->dst_h; - Uint8 *src = info->src; - int srcskip = info->src_skip; - Uint8 *dst = info->dst; - int dstskip = info->dst_skip; - SDL_PixelFormat *srcfmt = info->src_fmt; - int srcbpp = srcfmt->BytesPerPixel; - SDL_PixelFormat *dstfmt = info->dst_fmt; - int dstbpp = dstfmt->BytesPerPixel; - int c; - - while (height--) { - for (c = width; c; --c) { - Uint32 Pixel; - unsigned sR, sG, sB, sA; - DISEMBLE_RGBA(src, srcbpp, srcfmt, Pixel, sR, sG, sB, sA); - ASSEMBLE_RGBA(dst, dstbpp, dstfmt, sR, sG, sB, sA); - dst += dstbpp; - src += srcbpp; - } - src += srcskip; - dst += dstskip; - } -} - -static void -BlitNto1Key(SDL_BlitInfo * info) -{ - int width = info->dst_w; - int height = info->dst_h; - Uint8 *src = info->src; - int srcskip = info->src_skip; - Uint8 *dst = info->dst; - int dstskip = info->dst_skip; - SDL_PixelFormat *srcfmt = info->src_fmt; - const Uint8 *palmap = info->table; - Uint32 ckey = info->colorkey; - Uint32 rgbmask = ~srcfmt->Amask; - int srcbpp; - Uint32 Pixel; - unsigned sR, sG, sB; - - /* Set up some basic variables */ - srcbpp = srcfmt->BytesPerPixel; - ckey &= rgbmask; - - if (palmap == NULL) { - while (height--) { - /* *INDENT-OFF* */ - DUFFS_LOOP( - { - DISEMBLE_RGB(src, srcbpp, srcfmt, Pixel, - sR, sG, sB); - if ( (Pixel & rgbmask) != ckey ) { - /* Pack RGB into 8bit pixel */ - *dst = (Uint8)(((sR>>5)<<(3+2))| - ((sG>>5)<<(2)) | - ((sB>>6)<<(0))); - } - dst++; - src += srcbpp; - }, - width); - /* *INDENT-ON* */ - src += srcskip; - dst += dstskip; - } - } else { - while (height--) { - /* *INDENT-OFF* */ - DUFFS_LOOP( - { - DISEMBLE_RGB(src, srcbpp, srcfmt, Pixel, - sR, sG, sB); - if ( (Pixel & rgbmask) != ckey ) { - /* Pack RGB into 8bit pixel */ - *dst = (Uint8)palmap[((sR>>5)<<(3+2))| - ((sG>>5)<<(2)) | - ((sB>>6)<<(0)) ]; - } - dst++; - src += srcbpp; - }, - width); - /* *INDENT-ON* */ - src += srcskip; - dst += dstskip; - } - } -} - -static void -Blit2to2Key(SDL_BlitInfo * info) -{ - int width = info->dst_w; - int height = info->dst_h; - Uint16 *srcp = (Uint16 *) info->src; - int srcskip = info->src_skip; - Uint16 *dstp = (Uint16 *) info->dst; - int dstskip = info->dst_skip; - Uint32 ckey = info->colorkey; - Uint32 rgbmask = ~info->src_fmt->Amask; - - /* Set up some basic variables */ - srcskip /= 2; - dstskip /= 2; - ckey &= rgbmask; - - while (height--) { - /* *INDENT-OFF* */ - DUFFS_LOOP( - { - if ( (*srcp & rgbmask) != ckey ) { - *dstp = *srcp; - } - dstp++; - srcp++; - }, - width); - /* *INDENT-ON* */ - srcp += srcskip; - dstp += dstskip; - } -} - -static void -BlitNtoNKey(SDL_BlitInfo * info) -{ - int width = info->dst_w; - int height = info->dst_h; - Uint8 *src = info->src; - int srcskip = info->src_skip; - Uint8 *dst = info->dst; - int dstskip = info->dst_skip; - Uint32 ckey = info->colorkey; - SDL_PixelFormat *srcfmt = info->src_fmt; - SDL_PixelFormat *dstfmt = info->dst_fmt; - int srcbpp = srcfmt->BytesPerPixel; - int dstbpp = dstfmt->BytesPerPixel; - unsigned alpha = dstfmt->Amask ? info->a : 0; - Uint32 rgbmask = ~srcfmt->Amask; - - /* Set up some basic variables */ - ckey &= rgbmask; - - while (height--) { - /* *INDENT-OFF* */ - DUFFS_LOOP( - { - Uint32 Pixel; - unsigned sR; - unsigned sG; - unsigned sB; - RETRIEVE_RGB_PIXEL(src, srcbpp, Pixel); - if ( (Pixel & rgbmask) != ckey ) { - RGB_FROM_PIXEL(Pixel, srcfmt, sR, sG, sB); - ASSEMBLE_RGBA(dst, dstbpp, dstfmt, sR, sG, sB, alpha); - } - dst += dstbpp; - src += srcbpp; - }, - width); - /* *INDENT-ON* */ - src += srcskip; - dst += dstskip; - } -} - -static void -BlitNtoNKeyCopyAlpha(SDL_BlitInfo * info) -{ - int width = info->dst_w; - int height = info->dst_h; - Uint8 *src = info->src; - int srcskip = info->src_skip; - Uint8 *dst = info->dst; - int dstskip = info->dst_skip; - Uint32 ckey = info->colorkey; - SDL_PixelFormat *srcfmt = info->src_fmt; - SDL_PixelFormat *dstfmt = info->dst_fmt; - Uint32 rgbmask = ~srcfmt->Amask; - - Uint8 srcbpp; - Uint8 dstbpp; - Uint32 Pixel; - unsigned sR, sG, sB, sA; - - /* Set up some basic variables */ - srcbpp = srcfmt->BytesPerPixel; - dstbpp = dstfmt->BytesPerPixel; - ckey &= rgbmask; - - while (height--) { - /* *INDENT-OFF* */ - DUFFS_LOOP( - { - DISEMBLE_RGBA(src, srcbpp, srcfmt, Pixel, sR, sG, sB, sA); - if ( (Pixel & rgbmask) != ckey ) { - ASSEMBLE_RGBA(dst, dstbpp, dstfmt, sR, sG, sB, sA); - } - dst += dstbpp; - src += srcbpp; - }, - width); - /* *INDENT-ON* */ - src += srcskip; - dst += dstskip; - } -} - -/* Normal N to N optimized blitters */ -struct blit_table -{ - Uint32 srcR, srcG, srcB; - int dstbpp; - Uint32 dstR, dstG, dstB; - Uint32 blit_features; - SDL_BlitFunc blitfunc; - enum - { NO_ALPHA = 1, SET_ALPHA = 2, COPY_ALPHA = 4 } alpha; -}; -static const struct blit_table normal_blit_1[] = { - /* Default for 8-bit RGB source, an invalid combination */ - {0, 0, 0, 0, 0, 0, 0, 0, NULL}, -}; - -static const struct blit_table normal_blit_2[] = { -#if SDL_ALTIVEC_BLITTERS - /* has-altivec */ - {0x0000F800, 0x000007E0, 0x0000001F, 4, 0x00000000, 0x00000000, - 0x00000000, - 2, Blit_RGB565_32Altivec, NO_ALPHA | COPY_ALPHA | SET_ALPHA}, - {0x00007C00, 0x000003E0, 0x0000001F, 4, 0x00000000, 0x00000000, - 0x00000000, - 2, Blit_RGB555_32Altivec, NO_ALPHA | COPY_ALPHA | SET_ALPHA}, -#endif - {0x0000F800, 0x000007E0, 0x0000001F, 4, 0x00FF0000, 0x0000FF00, - 0x000000FF, - 0, Blit_RGB565_ARGB8888, NO_ALPHA | COPY_ALPHA | SET_ALPHA}, - {0x0000F800, 0x000007E0, 0x0000001F, 4, 0x000000FF, 0x0000FF00, - 0x00FF0000, - 0, Blit_RGB565_ABGR8888, NO_ALPHA | COPY_ALPHA | SET_ALPHA}, - {0x0000F800, 0x000007E0, 0x0000001F, 4, 0xFF000000, 0x00FF0000, - 0x0000FF00, - 0, Blit_RGB565_RGBA8888, NO_ALPHA | COPY_ALPHA | SET_ALPHA}, - {0x0000F800, 0x000007E0, 0x0000001F, 4, 0x0000FF00, 0x00FF0000, - 0xFF000000, - 0, Blit_RGB565_BGRA8888, NO_ALPHA | COPY_ALPHA | SET_ALPHA}, - - /* Default for 16-bit RGB source, used if no other blitter matches */ - {0, 0, 0, 0, 0, 0, 0, 0, BlitNtoN, 0} -}; - -static const struct blit_table normal_blit_3[] = { - /* Default for 24-bit RGB source, never optimized */ - {0, 0, 0, 0, 0, 0, 0, 0, BlitNtoN, 0} -}; - -static const struct blit_table normal_blit_4[] = { -#if SDL_ALTIVEC_BLITTERS - /* has-altivec | dont-use-prefetch */ - {0x00000000, 0x00000000, 0x00000000, 4, 0x00000000, 0x00000000, - 0x00000000, - 6, ConvertAltivec32to32_noprefetch, - NO_ALPHA | COPY_ALPHA | SET_ALPHA}, - /* has-altivec */ - {0x00000000, 0x00000000, 0x00000000, 4, 0x00000000, 0x00000000, - 0x00000000, - 2, ConvertAltivec32to32_prefetch, - NO_ALPHA | COPY_ALPHA | SET_ALPHA}, - /* has-altivec */ - {0x00000000, 0x00000000, 0x00000000, 2, 0x0000F800, 0x000007E0, - 0x0000001F, - 2, Blit_RGB888_RGB565Altivec, NO_ALPHA}, -#endif - {0x00FF0000, 0x0000FF00, 0x000000FF, 2, 0x0000F800, 0x000007E0, - 0x0000001F, - 0, Blit_RGB888_RGB565, NO_ALPHA}, - {0x00FF0000, 0x0000FF00, 0x000000FF, 2, 0x00007C00, 0x000003E0, - 0x0000001F, - 0, Blit_RGB888_RGB555, NO_ALPHA}, - /* Default for 32-bit RGB source, used if no other blitter matches */ - {0, 0, 0, 0, 0, 0, 0, 0, BlitNtoN, 0} -}; - -static const struct blit_table *const normal_blit[] = { - normal_blit_1, normal_blit_2, normal_blit_3, normal_blit_4 -}; - -/* Mask matches table, or table entry is zero */ -#define MASKOK(x, y) (((x) == (y)) || ((y) == 0x00000000)) - -SDL_BlitFunc -SDL_CalculateBlitN(SDL_Surface * surface) -{ - SDL_PixelFormat *srcfmt; - SDL_PixelFormat *dstfmt; - const struct blit_table *table; - int which; - SDL_BlitFunc blitfun; - - /* Set up data for choosing the blit */ - srcfmt = surface->format; - dstfmt = surface->map->dst->format; - - /* We don't support destinations less than 8-bits */ - if (dstfmt->BitsPerPixel < 8) { - return (NULL); - } - - switch (surface->map->info.flags & ~SDL_COPY_RLE_MASK) { - case 0: - blitfun = NULL; - if (dstfmt->BitsPerPixel == 8) { - /* We assume 8-bit destinations are palettized */ - if ((srcfmt->BytesPerPixel == 4) && - (srcfmt->Rmask == 0x00FF0000) && - (srcfmt->Gmask == 0x0000FF00) && - (srcfmt->Bmask == 0x000000FF)) { - if (surface->map->info.table) { - blitfun = Blit_RGB888_index8_map; - } else { - blitfun = Blit_RGB888_index8; - } - } else { - blitfun = BlitNto1; - } - } else { - /* Now the meat, choose the blitter we want */ - int a_need = NO_ALPHA; - if (dstfmt->Amask) - a_need = srcfmt->Amask ? COPY_ALPHA : SET_ALPHA; - table = normal_blit[srcfmt->BytesPerPixel - 1]; - for (which = 0; table[which].dstbpp; ++which) { - if (MASKOK(srcfmt->Rmask, table[which].srcR) && - MASKOK(srcfmt->Gmask, table[which].srcG) && - MASKOK(srcfmt->Bmask, table[which].srcB) && - MASKOK(dstfmt->Rmask, table[which].dstR) && - MASKOK(dstfmt->Gmask, table[which].dstG) && - MASKOK(dstfmt->Bmask, table[which].dstB) && - dstfmt->BytesPerPixel == table[which].dstbpp && - (a_need & table[which].alpha) == a_need && - ((table[which].blit_features & GetBlitFeatures()) == - table[which].blit_features)) - break; - } - blitfun = table[which].blitfunc; - - if (blitfun == BlitNtoN) { /* default C fallback catch-all. Slow! */ - /* Fastpath C fallback: 32bit RGB<->RGBA blit with matching RGB */ - if (srcfmt->BytesPerPixel == 4 && dstfmt->BytesPerPixel == 4 - && srcfmt->Rmask == dstfmt->Rmask - && srcfmt->Gmask == dstfmt->Gmask - && srcfmt->Bmask == dstfmt->Bmask) { - blitfun = Blit4to4MaskAlpha; - } else if (a_need == COPY_ALPHA) { - blitfun = BlitNtoNCopyAlpha; - } - } - } - return (blitfun); - - case SDL_COPY_COLORKEY: - /* colorkey blit: Here we don't have too many options, mostly - because RLE is the preferred fast way to deal with this. - If a particular case turns out to be useful we'll add it. */ - - if (srcfmt->BytesPerPixel == 2 && surface->map->identity) - return Blit2to2Key; - else if (dstfmt->BytesPerPixel == 1) - return BlitNto1Key; - else { -#if SDL_ALTIVEC_BLITTERS - if ((srcfmt->BytesPerPixel == 4) && (dstfmt->BytesPerPixel == 4) - && SDL_HasAltiVec()) { - return Blit32to32KeyAltivec; - } else -#endif - if (srcfmt->Amask && dstfmt->Amask) { - return BlitNtoNKeyCopyAlpha; - } else { - return BlitNtoNKey; - } - } - } - - return NULL; -} - -/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/SDL-mobile/src/video/SDL_blit_auto.c b/src/SDL-mobile/src/video/SDL_blit_auto.c deleted file mode 100644 index dbe71f94e..000000000 --- a/src/SDL-mobile/src/video/SDL_blit_auto.c +++ /dev/null @@ -1,7491 +0,0 @@ -/* DO NOT EDIT! This file is generated by sdlgenblit.pl */ -/* - Simple DirectMedia Layer - Copyright (C) 1997-2012 Sam Lantinga - - 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" - -/* *INDENT-OFF* */ - -#include "SDL_video.h" -#include "SDL_blit.h" -#include "SDL_blit_auto.h" - -static void SDL_Blit_RGB888_RGB888_Scale(SDL_BlitInfo *info) -{ - int srcy, srcx; - int posy, posx; - int incy, incx; - - srcy = 0; - posy = 0; - incy = (info->src_h << 16) / info->dst_h; - incx = (info->src_w << 16) / info->dst_w; - - while (info->dst_h--) { - Uint32 *src = 0; - Uint32 *dst = (Uint32 *)info->dst; - int n = info->dst_w; - srcx = -1; - posx = 0x10000L; - while (posy >= 0x10000L) { - ++srcy; - posy -= 0x10000L; - } - while (n--) { - if (posx >= 0x10000L) { - while (posx >= 0x10000L) { - ++srcx; - posx -= 0x10000L; - } - src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4)); - } - *dst = *src; - posx += incx; - ++dst; - } - posy += incy; - info->dst += info->dst_pitch; - } -} - -static void SDL_Blit_RGB888_RGB888_Blend(SDL_BlitInfo *info) -{ - const int flags = info->flags; - Uint32 srcpixel; - Uint32 srcR, srcG, srcB, srcA; - Uint32 dstpixel; - Uint32 dstR, dstG, dstB, dstA; - - while (info->dst_h--) { - Uint32 *src = (Uint32 *)info->src; - Uint32 *dst = (Uint32 *)info->dst; - int n = info->dst_w; - while (n--) { - srcpixel = *src; - srcR = (Uint8)(srcpixel >> 16); srcG = (Uint8)(srcpixel >> 8); srcB = (Uint8)srcpixel; srcA = 0xFF; - dstpixel = *dst; - dstR = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstB = (Uint8)dstpixel; dstA = 0xFF; - if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) { - /* This goes away if we ever use premultiplied alpha */ - if (srcA < 255) { - srcR = (srcR * srcA) / 255; - srcG = (srcG * srcA) / 255; - srcB = (srcB * srcA) / 255; - } - } - switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) { - case SDL_COPY_BLEND: - dstR = srcR + ((255 - srcA) * dstR) / 255; - dstG = srcG + ((255 - srcA) * dstG) / 255; - dstB = srcB + ((255 - srcA) * dstB) / 255; - break; - case SDL_COPY_ADD: - dstR = srcR + dstR; if (dstR > 255) dstR = 255; - dstG = srcG + dstG; if (dstG > 255) dstG = 255; - dstB = srcB + dstB; if (dstB > 255) dstB = 255; - break; - case SDL_COPY_MOD: - dstR = (srcR * dstR) / 255; - dstG = (srcG * dstG) / 255; - dstB = (srcB * dstB) / 255; - break; - } - dstpixel = ((Uint32)dstR << 16) | ((Uint32)dstG << 8) | dstB; - *dst = dstpixel; - ++src; - ++dst; - } - info->src += info->src_pitch; - info->dst += info->dst_pitch; - } -} - -static void SDL_Blit_RGB888_RGB888_Blend_Scale(SDL_BlitInfo *info) -{ - const int flags = info->flags; - Uint32 srcpixel; - Uint32 srcR, srcG, srcB, srcA; - Uint32 dstpixel; - Uint32 dstR, dstG, dstB, dstA; - int srcy, srcx; - int posy, posx; - int incy, incx; - - srcy = 0; - posy = 0; - incy = (info->src_h << 16) / info->dst_h; - incx = (info->src_w << 16) / info->dst_w; - - while (info->dst_h--) { - Uint32 *src = 0; - Uint32 *dst = (Uint32 *)info->dst; - int n = info->dst_w; - srcx = -1; - posx = 0x10000L; - while (posy >= 0x10000L) { - ++srcy; - posy -= 0x10000L; - } - while (n--) { - if (posx >= 0x10000L) { - while (posx >= 0x10000L) { - ++srcx; - posx -= 0x10000L; - } - src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4)); - } - srcpixel = *src; - srcR = (Uint8)(srcpixel >> 16); srcG = (Uint8)(srcpixel >> 8); srcB = (Uint8)srcpixel; srcA = 0xFF; - dstpixel = *dst; - dstR = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstB = (Uint8)dstpixel; dstA = 0xFF; - if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) { - /* This goes away if we ever use premultiplied alpha */ - if (srcA < 255) { - srcR = (srcR * srcA) / 255; - srcG = (srcG * srcA) / 255; - srcB = (srcB * srcA) / 255; - } - } - switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) { - case SDL_COPY_BLEND: - dstR = srcR + ((255 - srcA) * dstR) / 255; - dstG = srcG + ((255 - srcA) * dstG) / 255; - dstB = srcB + ((255 - srcA) * dstB) / 255; - break; - case SDL_COPY_ADD: - dstR = srcR + dstR; if (dstR > 255) dstR = 255; - dstG = srcG + dstG; if (dstG > 255) dstG = 255; - dstB = srcB + dstB; if (dstB > 255) dstB = 255; - break; - case SDL_COPY_MOD: - dstR = (srcR * dstR) / 255; - dstG = (srcG * dstG) / 255; - dstB = (srcB * dstB) / 255; - break; - } - dstpixel = ((Uint32)dstR << 16) | ((Uint32)dstG << 8) | dstB; - *dst = dstpixel; - posx += incx; - ++dst; - } - posy += incy; - info->dst += info->dst_pitch; - } -} - -static void SDL_Blit_RGB888_RGB888_Modulate(SDL_BlitInfo *info) -{ - const int flags = info->flags; - const Uint32 modulateR = info->r; - const Uint32 modulateG = info->g; - const Uint32 modulateB = info->b; - const Uint32 modulateA = info->a; - Uint32 pixel; - Uint32 R, G, B, A; - - while (info->dst_h--) { - Uint32 *src = (Uint32 *)info->src; - Uint32 *dst = (Uint32 *)info->dst; - int n = info->dst_w; - while (n--) { - pixel = *src; - R = (Uint8)(pixel >> 16); G = (Uint8)(pixel >> 8); B = (Uint8)pixel; A = 0xFF; - if (flags & SDL_COPY_MODULATE_COLOR) { - R = (R * modulateR) / 255; - G = (G * modulateG) / 255; - B = (B * modulateB) / 255; - } - if (flags & SDL_COPY_MODULATE_ALPHA) { - A = (A * modulateA) / 255; - } - pixel = ((Uint32)R << 16) | ((Uint32)G << 8) | B; - *dst = pixel; - ++src; - ++dst; - } - info->src += info->src_pitch; - info->dst += info->dst_pitch; - } -} - -static void SDL_Blit_RGB888_RGB888_Modulate_Scale(SDL_BlitInfo *info) -{ - const int flags = info->flags; - const Uint32 modulateR = info->r; - const Uint32 modulateG = info->g; - const Uint32 modulateB = info->b; - const Uint32 modulateA = info->a; - Uint32 pixel; - Uint32 R, G, B, A; - int srcy, srcx; - int posy, posx; - int incy, incx; - - srcy = 0; - posy = 0; - incy = (info->src_h << 16) / info->dst_h; - incx = (info->src_w << 16) / info->dst_w; - - while (info->dst_h--) { - Uint32 *src = 0; - Uint32 *dst = (Uint32 *)info->dst; - int n = info->dst_w; - srcx = -1; - posx = 0x10000L; - while (posy >= 0x10000L) { - ++srcy; - posy -= 0x10000L; - } - while (n--) { - if (posx >= 0x10000L) { - while (posx >= 0x10000L) { - ++srcx; - posx -= 0x10000L; - } - src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4)); - } - pixel = *src; - R = (Uint8)(pixel >> 16); G = (Uint8)(pixel >> 8); B = (Uint8)pixel; A = 0xFF; - if (flags & SDL_COPY_MODULATE_COLOR) { - R = (R * modulateR) / 255; - G = (G * modulateG) / 255; - B = (B * modulateB) / 255; - } - if (flags & SDL_COPY_MODULATE_ALPHA) { - A = (A * modulateA) / 255; - } - pixel = ((Uint32)R << 16) | ((Uint32)G << 8) | B; - *dst = pixel; - posx += incx; - ++dst; - } - posy += incy; - info->dst += info->dst_pitch; - } -} - -static void SDL_Blit_RGB888_RGB888_Modulate_Blend(SDL_BlitInfo *info) -{ - const int flags = info->flags; - const Uint32 modulateR = info->r; - const Uint32 modulateG = info->g; - const Uint32 modulateB = info->b; - const Uint32 modulateA = info->a; - Uint32 srcpixel; - Uint32 srcR, srcG, srcB, srcA; - Uint32 dstpixel; - Uint32 dstR, dstG, dstB, dstA; - - while (info->dst_h--) { - Uint32 *src = (Uint32 *)info->src; - Uint32 *dst = (Uint32 *)info->dst; - int n = info->dst_w; - while (n--) { - srcpixel = *src; - srcR = (Uint8)(srcpixel >> 16); srcG = (Uint8)(srcpixel >> 8); srcB = (Uint8)srcpixel; srcA = 0xFF; - dstpixel = *dst; - dstR = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstB = (Uint8)dstpixel; dstA = 0xFF; - if (flags & SDL_COPY_MODULATE_COLOR) { - srcR = (srcR * modulateR) / 255; - srcG = (srcG * modulateG) / 255; - srcB = (srcB * modulateB) / 255; - } - if (flags & SDL_COPY_MODULATE_ALPHA) { - srcA = (srcA * modulateA) / 255; - } - if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) { - /* This goes away if we ever use premultiplied alpha */ - if (srcA < 255) { - srcR = (srcR * srcA) / 255; - srcG = (srcG * srcA) / 255; - srcB = (srcB * srcA) / 255; - } - } - switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) { - case SDL_COPY_BLEND: - dstR = srcR + ((255 - srcA) * dstR) / 255; - dstG = srcG + ((255 - srcA) * dstG) / 255; - dstB = srcB + ((255 - srcA) * dstB) / 255; - break; - case SDL_COPY_ADD: - dstR = srcR + dstR; if (dstR > 255) dstR = 255; - dstG = srcG + dstG; if (dstG > 255) dstG = 255; - dstB = srcB + dstB; if (dstB > 255) dstB = 255; - break; - case SDL_COPY_MOD: - dstR = (srcR * dstR) / 255; - dstG = (srcG * dstG) / 255; - dstB = (srcB * dstB) / 255; - break; - } - dstpixel = ((Uint32)dstR << 16) | ((Uint32)dstG << 8) | dstB; - *dst = dstpixel; - ++src; - ++dst; - } - info->src += info->src_pitch; - info->dst += info->dst_pitch; - } -} - -static void SDL_Blit_RGB888_RGB888_Modulate_Blend_Scale(SDL_BlitInfo *info) -{ - const int flags = info->flags; - const Uint32 modulateR = info->r; - const Uint32 modulateG = info->g; - const Uint32 modulateB = info->b; - const Uint32 modulateA = info->a; - Uint32 srcpixel; - Uint32 srcR, srcG, srcB, srcA; - Uint32 dstpixel; - Uint32 dstR, dstG, dstB, dstA; - int srcy, srcx; - int posy, posx; - int incy, incx; - - srcy = 0; - posy = 0; - incy = (info->src_h << 16) / info->dst_h; - incx = (info->src_w << 16) / info->dst_w; - - while (info->dst_h--) { - Uint32 *src = 0; - Uint32 *dst = (Uint32 *)info->dst; - int n = info->dst_w; - srcx = -1; - posx = 0x10000L; - while (posy >= 0x10000L) { - ++srcy; - posy -= 0x10000L; - } - while (n--) { - if (posx >= 0x10000L) { - while (posx >= 0x10000L) { - ++srcx; - posx -= 0x10000L; - } - src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4)); - } - srcpixel = *src; - srcR = (Uint8)(srcpixel >> 16); srcG = (Uint8)(srcpixel >> 8); srcB = (Uint8)srcpixel; srcA = 0xFF; - dstpixel = *dst; - dstR = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstB = (Uint8)dstpixel; dstA = 0xFF; - if (flags & SDL_COPY_MODULATE_COLOR) { - srcR = (srcR * modulateR) / 255; - srcG = (srcG * modulateG) / 255; - srcB = (srcB * modulateB) / 255; - } - if (flags & SDL_COPY_MODULATE_ALPHA) { - srcA = (srcA * modulateA) / 255; - } - if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) { - /* This goes away if we ever use premultiplied alpha */ - if (srcA < 255) { - srcR = (srcR * srcA) / 255; - srcG = (srcG * srcA) / 255; - srcB = (srcB * srcA) / 255; - } - } - switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) { - case SDL_COPY_BLEND: - dstR = srcR + ((255 - srcA) * dstR) / 255; - dstG = srcG + ((255 - srcA) * dstG) / 255; - dstB = srcB + ((255 - srcA) * dstB) / 255; - break; - case SDL_COPY_ADD: - dstR = srcR + dstR; if (dstR > 255) dstR = 255; - dstG = srcG + dstG; if (dstG > 255) dstG = 255; - dstB = srcB + dstB; if (dstB > 255) dstB = 255; - break; - case SDL_COPY_MOD: - dstR = (srcR * dstR) / 255; - dstG = (srcG * dstG) / 255; - dstB = (srcB * dstB) / 255; - break; - } - dstpixel = ((Uint32)dstR << 16) | ((Uint32)dstG << 8) | dstB; - *dst = dstpixel; - posx += incx; - ++dst; - } - posy += incy; - info->dst += info->dst_pitch; - } -} - -static void SDL_Blit_RGB888_BGR888_Scale(SDL_BlitInfo *info) -{ - Uint32 pixel; - Uint32 R, G, B, A; - int srcy, srcx; - int posy, posx; - int incy, incx; - - srcy = 0; - posy = 0; - incy = (info->src_h << 16) / info->dst_h; - incx = (info->src_w << 16) / info->dst_w; - - while (info->dst_h--) { - Uint32 *src = 0; - Uint32 *dst = (Uint32 *)info->dst; - int n = info->dst_w; - srcx = -1; - posx = 0x10000L; - while (posy >= 0x10000L) { - ++srcy; - posy -= 0x10000L; - } - while (n--) { - if (posx >= 0x10000L) { - while (posx >= 0x10000L) { - ++srcx; - posx -= 0x10000L; - } - src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4)); - } - pixel = *src; - R = (Uint8)(pixel >> 16); G = (Uint8)(pixel >> 8); B = (Uint8)pixel; A = 0xFF; - pixel = ((Uint32)B << 16) | ((Uint32)G << 8) | R; - *dst = pixel; - posx += incx; - ++dst; - } - posy += incy; - info->dst += info->dst_pitch; - } -} - -static void SDL_Blit_RGB888_BGR888_Blend(SDL_BlitInfo *info) -{ - const int flags = info->flags; - Uint32 srcpixel; - Uint32 srcR, srcG, srcB, srcA; - Uint32 dstpixel; - Uint32 dstR, dstG, dstB, dstA; - - while (info->dst_h--) { - Uint32 *src = (Uint32 *)info->src; - Uint32 *dst = (Uint32 *)info->dst; - int n = info->dst_w; - while (n--) { - srcpixel = *src; - srcR = (Uint8)(srcpixel >> 16); srcG = (Uint8)(srcpixel >> 8); srcB = (Uint8)srcpixel; srcA = 0xFF; - dstpixel = *dst; - dstB = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstR = (Uint8)dstpixel; dstA = 0xFF; - if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) { - /* This goes away if we ever use premultiplied alpha */ - if (srcA < 255) { - srcR = (srcR * srcA) / 255; - srcG = (srcG * srcA) / 255; - srcB = (srcB * srcA) / 255; - } - } - switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) { - case SDL_COPY_BLEND: - dstR = srcR + ((255 - srcA) * dstR) / 255; - dstG = srcG + ((255 - srcA) * dstG) / 255; - dstB = srcB + ((255 - srcA) * dstB) / 255; - break; - case SDL_COPY_ADD: - dstR = srcR + dstR; if (dstR > 255) dstR = 255; - dstG = srcG + dstG; if (dstG > 255) dstG = 255; - dstB = srcB + dstB; if (dstB > 255) dstB = 255; - break; - case SDL_COPY_MOD: - dstR = (srcR * dstR) / 255; - dstG = (srcG * dstG) / 255; - dstB = (srcB * dstB) / 255; - break; - } - dstpixel = ((Uint32)dstB << 16) | ((Uint32)dstG << 8) | dstR; - *dst = dstpixel; - ++src; - ++dst; - } - info->src += info->src_pitch; - info->dst += info->dst_pitch; - } -} - -static void SDL_Blit_RGB888_BGR888_Blend_Scale(SDL_BlitInfo *info) -{ - const int flags = info->flags; - Uint32 srcpixel; - Uint32 srcR, srcG, srcB, srcA; - Uint32 dstpixel; - Uint32 dstR, dstG, dstB, dstA; - int srcy, srcx; - int posy, posx; - int incy, incx; - - srcy = 0; - posy = 0; - incy = (info->src_h << 16) / info->dst_h; - incx = (info->src_w << 16) / info->dst_w; - - while (info->dst_h--) { - Uint32 *src = 0; - Uint32 *dst = (Uint32 *)info->dst; - int n = info->dst_w; - srcx = -1; - posx = 0x10000L; - while (posy >= 0x10000L) { - ++srcy; - posy -= 0x10000L; - } - while (n--) { - if (posx >= 0x10000L) { - while (posx >= 0x10000L) { - ++srcx; - posx -= 0x10000L; - } - src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4)); - } - srcpixel = *src; - srcR = (Uint8)(srcpixel >> 16); srcG = (Uint8)(srcpixel >> 8); srcB = (Uint8)srcpixel; srcA = 0xFF; - dstpixel = *dst; - dstB = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstR = (Uint8)dstpixel; dstA = 0xFF; - if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) { - /* This goes away if we ever use premultiplied alpha */ - if (srcA < 255) { - srcR = (srcR * srcA) / 255; - srcG = (srcG * srcA) / 255; - srcB = (srcB * srcA) / 255; - } - } - switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) { - case SDL_COPY_BLEND: - dstR = srcR + ((255 - srcA) * dstR) / 255; - dstG = srcG + ((255 - srcA) * dstG) / 255; - dstB = srcB + ((255 - srcA) * dstB) / 255; - break; - case SDL_COPY_ADD: - dstR = srcR + dstR; if (dstR > 255) dstR = 255; - dstG = srcG + dstG; if (dstG > 255) dstG = 255; - dstB = srcB + dstB; if (dstB > 255) dstB = 255; - break; - case SDL_COPY_MOD: - dstR = (srcR * dstR) / 255; - dstG = (srcG * dstG) / 255; - dstB = (srcB * dstB) / 255; - break; - } - dstpixel = ((Uint32)dstB << 16) | ((Uint32)dstG << 8) | dstR; - *dst = dstpixel; - posx += incx; - ++dst; - } - posy += incy; - info->dst += info->dst_pitch; - } -} - -static void SDL_Blit_RGB888_BGR888_Modulate(SDL_BlitInfo *info) -{ - const int flags = info->flags; - const Uint32 modulateR = info->r; - const Uint32 modulateG = info->g; - const Uint32 modulateB = info->b; - const Uint32 modulateA = info->a; - Uint32 pixel; - Uint32 R, G, B, A; - - while (info->dst_h--) { - Uint32 *src = (Uint32 *)info->src; - Uint32 *dst = (Uint32 *)info->dst; - int n = info->dst_w; - while (n--) { - pixel = *src; - R = (Uint8)(pixel >> 16); G = (Uint8)(pixel >> 8); B = (Uint8)pixel; A = 0xFF; - if (flags & SDL_COPY_MODULATE_COLOR) { - R = (R * modulateR) / 255; - G = (G * modulateG) / 255; - B = (B * modulateB) / 255; - } - if (flags & SDL_COPY_MODULATE_ALPHA) { - A = (A * modulateA) / 255; - } - pixel = ((Uint32)B << 16) | ((Uint32)G << 8) | R; - *dst = pixel; - ++src; - ++dst; - } - info->src += info->src_pitch; - info->dst += info->dst_pitch; - } -} - -static void SDL_Blit_RGB888_BGR888_Modulate_Scale(SDL_BlitInfo *info) -{ - const int flags = info->flags; - const Uint32 modulateR = info->r; - const Uint32 modulateG = info->g; - const Uint32 modulateB = info->b; - const Uint32 modulateA = info->a; - Uint32 pixel; - Uint32 R, G, B, A; - int srcy, srcx; - int posy, posx; - int incy, incx; - - srcy = 0; - posy = 0; - incy = (info->src_h << 16) / info->dst_h; - incx = (info->src_w << 16) / info->dst_w; - - while (info->dst_h--) { - Uint32 *src = 0; - Uint32 *dst = (Uint32 *)info->dst; - int n = info->dst_w; - srcx = -1; - posx = 0x10000L; - while (posy >= 0x10000L) { - ++srcy; - posy -= 0x10000L; - } - while (n--) { - if (posx >= 0x10000L) { - while (posx >= 0x10000L) { - ++srcx; - posx -= 0x10000L; - } - src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4)); - } - pixel = *src; - R = (Uint8)(pixel >> 16); G = (Uint8)(pixel >> 8); B = (Uint8)pixel; A = 0xFF; - if (flags & SDL_COPY_MODULATE_COLOR) { - R = (R * modulateR) / 255; - G = (G * modulateG) / 255; - B = (B * modulateB) / 255; - } - if (flags & SDL_COPY_MODULATE_ALPHA) { - A = (A * modulateA) / 255; - } - pixel = ((Uint32)B << 16) | ((Uint32)G << 8) | R; - *dst = pixel; - posx += incx; - ++dst; - } - posy += incy; - info->dst += info->dst_pitch; - } -} - -static void SDL_Blit_RGB888_BGR888_Modulate_Blend(SDL_BlitInfo *info) -{ - const int flags = info->flags; - const Uint32 modulateR = info->r; - const Uint32 modulateG = info->g; - const Uint32 modulateB = info->b; - const Uint32 modulateA = info->a; - Uint32 srcpixel; - Uint32 srcR, srcG, srcB, srcA; - Uint32 dstpixel; - Uint32 dstR, dstG, dstB, dstA; - - while (info->dst_h--) { - Uint32 *src = (Uint32 *)info->src; - Uint32 *dst = (Uint32 *)info->dst; - int n = info->dst_w; - while (n--) { - srcpixel = *src; - srcR = (Uint8)(srcpixel >> 16); srcG = (Uint8)(srcpixel >> 8); srcB = (Uint8)srcpixel; srcA = 0xFF; - dstpixel = *dst; - dstB = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstR = (Uint8)dstpixel; dstA = 0xFF; - if (flags & SDL_COPY_MODULATE_COLOR) { - srcR = (srcR * modulateR) / 255; - srcG = (srcG * modulateG) / 255; - srcB = (srcB * modulateB) / 255; - } - if (flags & SDL_COPY_MODULATE_ALPHA) { - srcA = (srcA * modulateA) / 255; - } - if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) { - /* This goes away if we ever use premultiplied alpha */ - if (srcA < 255) { - srcR = (srcR * srcA) / 255; - srcG = (srcG * srcA) / 255; - srcB = (srcB * srcA) / 255; - } - } - switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) { - case SDL_COPY_BLEND: - dstR = srcR + ((255 - srcA) * dstR) / 255; - dstG = srcG + ((255 - srcA) * dstG) / 255; - dstB = srcB + ((255 - srcA) * dstB) / 255; - break; - case SDL_COPY_ADD: - dstR = srcR + dstR; if (dstR > 255) dstR = 255; - dstG = srcG + dstG; if (dstG > 255) dstG = 255; - dstB = srcB + dstB; if (dstB > 255) dstB = 255; - break; - case SDL_COPY_MOD: - dstR = (srcR * dstR) / 255; - dstG = (srcG * dstG) / 255; - dstB = (srcB * dstB) / 255; - break; - } - dstpixel = ((Uint32)dstB << 16) | ((Uint32)dstG << 8) | dstR; - *dst = dstpixel; - ++src; - ++dst; - } - info->src += info->src_pitch; - info->dst += info->dst_pitch; - } -} - -static void SDL_Blit_RGB888_BGR888_Modulate_Blend_Scale(SDL_BlitInfo *info) -{ - const int flags = info->flags; - const Uint32 modulateR = info->r; - const Uint32 modulateG = info->g; - const Uint32 modulateB = info->b; - const Uint32 modulateA = info->a; - Uint32 srcpixel; - Uint32 srcR, srcG, srcB, srcA; - Uint32 dstpixel; - Uint32 dstR, dstG, dstB, dstA; - int srcy, srcx; - int posy, posx; - int incy, incx; - - srcy = 0; - posy = 0; - incy = (info->src_h << 16) / info->dst_h; - incx = (info->src_w << 16) / info->dst_w; - - while (info->dst_h--) { - Uint32 *src = 0; - Uint32 *dst = (Uint32 *)info->dst; - int n = info->dst_w; - srcx = -1; - posx = 0x10000L; - while (posy >= 0x10000L) { - ++srcy; - posy -= 0x10000L; - } - while (n--) { - if (posx >= 0x10000L) { - while (posx >= 0x10000L) { - ++srcx; - posx -= 0x10000L; - } - src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4)); - } - srcpixel = *src; - srcR = (Uint8)(srcpixel >> 16); srcG = (Uint8)(srcpixel >> 8); srcB = (Uint8)srcpixel; srcA = 0xFF; - dstpixel = *dst; - dstB = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstR = (Uint8)dstpixel; dstA = 0xFF; - if (flags & SDL_COPY_MODULATE_COLOR) { - srcR = (srcR * modulateR) / 255; - srcG = (srcG * modulateG) / 255; - srcB = (srcB * modulateB) / 255; - } - if (flags & SDL_COPY_MODULATE_ALPHA) { - srcA = (srcA * modulateA) / 255; - } - if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) { - /* This goes away if we ever use premultiplied alpha */ - if (srcA < 255) { - srcR = (srcR * srcA) / 255; - srcG = (srcG * srcA) / 255; - srcB = (srcB * srcA) / 255; - } - } - switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) { - case SDL_COPY_BLEND: - dstR = srcR + ((255 - srcA) * dstR) / 255; - dstG = srcG + ((255 - srcA) * dstG) / 255; - dstB = srcB + ((255 - srcA) * dstB) / 255; - break; - case SDL_COPY_ADD: - dstR = srcR + dstR; if (dstR > 255) dstR = 255; - dstG = srcG + dstG; if (dstG > 255) dstG = 255; - dstB = srcB + dstB; if (dstB > 255) dstB = 255; - break; - case SDL_COPY_MOD: - dstR = (srcR * dstR) / 255; - dstG = (srcG * dstG) / 255; - dstB = (srcB * dstB) / 255; - break; - } - dstpixel = ((Uint32)dstB << 16) | ((Uint32)dstG << 8) | dstR; - *dst = dstpixel; - posx += incx; - ++dst; - } - posy += incy; - info->dst += info->dst_pitch; - } -} - -static void SDL_Blit_RGB888_ARGB8888_Scale(SDL_BlitInfo *info) -{ - Uint32 pixel; - Uint32 R, G, B, A; - int srcy, srcx; - int posy, posx; - int incy, incx; - - srcy = 0; - posy = 0; - incy = (info->src_h << 16) / info->dst_h; - incx = (info->src_w << 16) / info->dst_w; - - while (info->dst_h--) { - Uint32 *src = 0; - Uint32 *dst = (Uint32 *)info->dst; - int n = info->dst_w; - srcx = -1; - posx = 0x10000L; - while (posy >= 0x10000L) { - ++srcy; - posy -= 0x10000L; - } - while (n--) { - if (posx >= 0x10000L) { - while (posx >= 0x10000L) { - ++srcx; - posx -= 0x10000L; - } - src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4)); - } - pixel = *src; - R = (Uint8)(pixel >> 16); G = (Uint8)(pixel >> 8); B = (Uint8)pixel; A = 0xFF; - pixel = ((Uint32)A << 24) | ((Uint32)R << 16) | ((Uint32)G << 8) | B; - *dst = pixel; - posx += incx; - ++dst; - } - posy += incy; - info->dst += info->dst_pitch; - } -} - -static void SDL_Blit_RGB888_ARGB8888_Blend(SDL_BlitInfo *info) -{ - const int flags = info->flags; - Uint32 srcpixel; - Uint32 srcR, srcG, srcB, srcA; - Uint32 dstpixel; - Uint32 dstR, dstG, dstB, dstA; - - while (info->dst_h--) { - Uint32 *src = (Uint32 *)info->src; - Uint32 *dst = (Uint32 *)info->dst; - int n = info->dst_w; - while (n--) { - srcpixel = *src; - srcR = (Uint8)(srcpixel >> 16); srcG = (Uint8)(srcpixel >> 8); srcB = (Uint8)srcpixel; srcA = 0xFF; - dstpixel = *dst; - dstA = (Uint8)(dstpixel >> 24); dstR = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstB = (Uint8)dstpixel; - if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) { - /* This goes away if we ever use premultiplied alpha */ - if (srcA < 255) { - srcR = (srcR * srcA) / 255; - srcG = (srcG * srcA) / 255; - srcB = (srcB * srcA) / 255; - } - } - switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) { - case SDL_COPY_BLEND: - dstR = srcR + ((255 - srcA) * dstR) / 255; - dstG = srcG + ((255 - srcA) * dstG) / 255; - dstB = srcB + ((255 - srcA) * dstB) / 255; - break; - case SDL_COPY_ADD: - dstR = srcR + dstR; if (dstR > 255) dstR = 255; - dstG = srcG + dstG; if (dstG > 255) dstG = 255; - dstB = srcB + dstB; if (dstB > 255) dstB = 255; - break; - case SDL_COPY_MOD: - dstR = (srcR * dstR) / 255; - dstG = (srcG * dstG) / 255; - dstB = (srcB * dstB) / 255; - break; - } - dstpixel = ((Uint32)dstA << 24) | ((Uint32)dstR << 16) | ((Uint32)dstG << 8) | dstB; - *dst = dstpixel; - ++src; - ++dst; - } - info->src += info->src_pitch; - info->dst += info->dst_pitch; - } -} - -static void SDL_Blit_RGB888_ARGB8888_Blend_Scale(SDL_BlitInfo *info) -{ - const int flags = info->flags; - Uint32 srcpixel; - Uint32 srcR, srcG, srcB, srcA; - Uint32 dstpixel; - Uint32 dstR, dstG, dstB, dstA; - int srcy, srcx; - int posy, posx; - int incy, incx; - - srcy = 0; - posy = 0; - incy = (info->src_h << 16) / info->dst_h; - incx = (info->src_w << 16) / info->dst_w; - - while (info->dst_h--) { - Uint32 *src = 0; - Uint32 *dst = (Uint32 *)info->dst; - int n = info->dst_w; - srcx = -1; - posx = 0x10000L; - while (posy >= 0x10000L) { - ++srcy; - posy -= 0x10000L; - } - while (n--) { - if (posx >= 0x10000L) { - while (posx >= 0x10000L) { - ++srcx; - posx -= 0x10000L; - } - src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4)); - } - srcpixel = *src; - srcR = (Uint8)(srcpixel >> 16); srcG = (Uint8)(srcpixel >> 8); srcB = (Uint8)srcpixel; srcA = 0xFF; - dstpixel = *dst; - dstA = (Uint8)(dstpixel >> 24); dstR = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstB = (Uint8)dstpixel; - if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) { - /* This goes away if we ever use premultiplied alpha */ - if (srcA < 255) { - srcR = (srcR * srcA) / 255; - srcG = (srcG * srcA) / 255; - srcB = (srcB * srcA) / 255; - } - } - switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) { - case SDL_COPY_BLEND: - dstR = srcR + ((255 - srcA) * dstR) / 255; - dstG = srcG + ((255 - srcA) * dstG) / 255; - dstB = srcB + ((255 - srcA) * dstB) / 255; - break; - case SDL_COPY_ADD: - dstR = srcR + dstR; if (dstR > 255) dstR = 255; - dstG = srcG + dstG; if (dstG > 255) dstG = 255; - dstB = srcB + dstB; if (dstB > 255) dstB = 255; - break; - case SDL_COPY_MOD: - dstR = (srcR * dstR) / 255; - dstG = (srcG * dstG) / 255; - dstB = (srcB * dstB) / 255; - break; - } - dstpixel = ((Uint32)dstA << 24) | ((Uint32)dstR << 16) | ((Uint32)dstG << 8) | dstB; - *dst = dstpixel; - posx += incx; - ++dst; - } - posy += incy; - info->dst += info->dst_pitch; - } -} - -static void SDL_Blit_RGB888_ARGB8888_Modulate(SDL_BlitInfo *info) -{ - const int flags = info->flags; - const Uint32 modulateR = info->r; - const Uint32 modulateG = info->g; - const Uint32 modulateB = info->b; - const Uint32 modulateA = info->a; - Uint32 pixel; - Uint32 R, G, B, A; - - while (info->dst_h--) { - Uint32 *src = (Uint32 *)info->src; - Uint32 *dst = (Uint32 *)info->dst; - int n = info->dst_w; - while (n--) { - pixel = *src; - R = (Uint8)(pixel >> 16); G = (Uint8)(pixel >> 8); B = (Uint8)pixel; A = 0xFF; - if (flags & SDL_COPY_MODULATE_COLOR) { - R = (R * modulateR) / 255; - G = (G * modulateG) / 255; - B = (B * modulateB) / 255; - } - if (flags & SDL_COPY_MODULATE_ALPHA) { - A = (A * modulateA) / 255; - } - pixel = ((Uint32)A << 24) | ((Uint32)R << 16) | ((Uint32)G << 8) | B; - *dst = pixel; - ++src; - ++dst; - } - info->src += info->src_pitch; - info->dst += info->dst_pitch; - } -} - -static void SDL_Blit_RGB888_ARGB8888_Modulate_Scale(SDL_BlitInfo *info) -{ - const int flags = info->flags; - const Uint32 modulateR = info->r; - const Uint32 modulateG = info->g; - const Uint32 modulateB = info->b; - const Uint32 modulateA = info->a; - Uint32 pixel; - Uint32 R, G, B, A; - int srcy, srcx; - int posy, posx; - int incy, incx; - - srcy = 0; - posy = 0; - incy = (info->src_h << 16) / info->dst_h; - incx = (info->src_w << 16) / info->dst_w; - - while (info->dst_h--) { - Uint32 *src = 0; - Uint32 *dst = (Uint32 *)info->dst; - int n = info->dst_w; - srcx = -1; - posx = 0x10000L; - while (posy >= 0x10000L) { - ++srcy; - posy -= 0x10000L; - } - while (n--) { - if (posx >= 0x10000L) { - while (posx >= 0x10000L) { - ++srcx; - posx -= 0x10000L; - } - src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4)); - } - pixel = *src; - R = (Uint8)(pixel >> 16); G = (Uint8)(pixel >> 8); B = (Uint8)pixel; A = 0xFF; - if (flags & SDL_COPY_MODULATE_COLOR) { - R = (R * modulateR) / 255; - G = (G * modulateG) / 255; - B = (B * modulateB) / 255; - } - if (flags & SDL_COPY_MODULATE_ALPHA) { - A = (A * modulateA) / 255; - } - pixel = ((Uint32)A << 24) | ((Uint32)R << 16) | ((Uint32)G << 8) | B; - *dst = pixel; - posx += incx; - ++dst; - } - posy += incy; - info->dst += info->dst_pitch; - } -} - -static void SDL_Blit_RGB888_ARGB8888_Modulate_Blend(SDL_BlitInfo *info) -{ - const int flags = info->flags; - const Uint32 modulateR = info->r; - const Uint32 modulateG = info->g; - const Uint32 modulateB = info->b; - const Uint32 modulateA = info->a; - Uint32 srcpixel; - Uint32 srcR, srcG, srcB, srcA; - Uint32 dstpixel; - Uint32 dstR, dstG, dstB, dstA; - - while (info->dst_h--) { - Uint32 *src = (Uint32 *)info->src; - Uint32 *dst = (Uint32 *)info->dst; - int n = info->dst_w; - while (n--) { - srcpixel = *src; - srcR = (Uint8)(srcpixel >> 16); srcG = (Uint8)(srcpixel >> 8); srcB = (Uint8)srcpixel; srcA = 0xFF; - dstpixel = *dst; - dstA = (Uint8)(dstpixel >> 24); dstR = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstB = (Uint8)dstpixel; - if (flags & SDL_COPY_MODULATE_COLOR) { - srcR = (srcR * modulateR) / 255; - srcG = (srcG * modulateG) / 255; - srcB = (srcB * modulateB) / 255; - } - if (flags & SDL_COPY_MODULATE_ALPHA) { - srcA = (srcA * modulateA) / 255; - } - if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) { - /* This goes away if we ever use premultiplied alpha */ - if (srcA < 255) { - srcR = (srcR * srcA) / 255; - srcG = (srcG * srcA) / 255; - srcB = (srcB * srcA) / 255; - } - } - switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) { - case SDL_COPY_BLEND: - dstR = srcR + ((255 - srcA) * dstR) / 255; - dstG = srcG + ((255 - srcA) * dstG) / 255; - dstB = srcB + ((255 - srcA) * dstB) / 255; - break; - case SDL_COPY_ADD: - dstR = srcR + dstR; if (dstR > 255) dstR = 255; - dstG = srcG + dstG; if (dstG > 255) dstG = 255; - dstB = srcB + dstB; if (dstB > 255) dstB = 255; - break; - case SDL_COPY_MOD: - dstR = (srcR * dstR) / 255; - dstG = (srcG * dstG) / 255; - dstB = (srcB * dstB) / 255; - break; - } - dstpixel = ((Uint32)dstA << 24) | ((Uint32)dstR << 16) | ((Uint32)dstG << 8) | dstB; - *dst = dstpixel; - ++src; - ++dst; - } - info->src += info->src_pitch; - info->dst += info->dst_pitch; - } -} - -static void SDL_Blit_RGB888_ARGB8888_Modulate_Blend_Scale(SDL_BlitInfo *info) -{ - const int flags = info->flags; - const Uint32 modulateR = info->r; - const Uint32 modulateG = info->g; - const Uint32 modulateB = info->b; - const Uint32 modulateA = info->a; - Uint32 srcpixel; - Uint32 srcR, srcG, srcB, srcA; - Uint32 dstpixel; - Uint32 dstR, dstG, dstB, dstA; - int srcy, srcx; - int posy, posx; - int incy, incx; - - srcy = 0; - posy = 0; - incy = (info->src_h << 16) / info->dst_h; - incx = (info->src_w << 16) / info->dst_w; - - while (info->dst_h--) { - Uint32 *src = 0; - Uint32 *dst = (Uint32 *)info->dst; - int n = info->dst_w; - srcx = -1; - posx = 0x10000L; - while (posy >= 0x10000L) { - ++srcy; - posy -= 0x10000L; - } - while (n--) { - if (posx >= 0x10000L) { - while (posx >= 0x10000L) { - ++srcx; - posx -= 0x10000L; - } - src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4)); - } - srcpixel = *src; - srcR = (Uint8)(srcpixel >> 16); srcG = (Uint8)(srcpixel >> 8); srcB = (Uint8)srcpixel; srcA = 0xFF; - dstpixel = *dst; - dstA = (Uint8)(dstpixel >> 24); dstR = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstB = (Uint8)dstpixel; - if (flags & SDL_COPY_MODULATE_COLOR) { - srcR = (srcR * modulateR) / 255; - srcG = (srcG * modulateG) / 255; - srcB = (srcB * modulateB) / 255; - } - if (flags & SDL_COPY_MODULATE_ALPHA) { - srcA = (srcA * modulateA) / 255; - } - if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) { - /* This goes away if we ever use premultiplied alpha */ - if (srcA < 255) { - srcR = (srcR * srcA) / 255; - srcG = (srcG * srcA) / 255; - srcB = (srcB * srcA) / 255; - } - } - switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) { - case SDL_COPY_BLEND: - dstR = srcR + ((255 - srcA) * dstR) / 255; - dstG = srcG + ((255 - srcA) * dstG) / 255; - dstB = srcB + ((255 - srcA) * dstB) / 255; - break; - case SDL_COPY_ADD: - dstR = srcR + dstR; if (dstR > 255) dstR = 255; - dstG = srcG + dstG; if (dstG > 255) dstG = 255; - dstB = srcB + dstB; if (dstB > 255) dstB = 255; - break; - case SDL_COPY_MOD: - dstR = (srcR * dstR) / 255; - dstG = (srcG * dstG) / 255; - dstB = (srcB * dstB) / 255; - break; - } - dstpixel = ((Uint32)dstA << 24) | ((Uint32)dstR << 16) | ((Uint32)dstG << 8) | dstB; - *dst = dstpixel; - posx += incx; - ++dst; - } - posy += incy; - info->dst += info->dst_pitch; - } -} - -static void SDL_Blit_BGR888_RGB888_Scale(SDL_BlitInfo *info) -{ - Uint32 pixel; - Uint32 R, G, B, A; - int srcy, srcx; - int posy, posx; - int incy, incx; - - srcy = 0; - posy = 0; - incy = (info->src_h << 16) / info->dst_h; - incx = (info->src_w << 16) / info->dst_w; - - while (info->dst_h--) { - Uint32 *src = 0; - Uint32 *dst = (Uint32 *)info->dst; - int n = info->dst_w; - srcx = -1; - posx = 0x10000L; - while (posy >= 0x10000L) { - ++srcy; - posy -= 0x10000L; - } - while (n--) { - if (posx >= 0x10000L) { - while (posx >= 0x10000L) { - ++srcx; - posx -= 0x10000L; - } - src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4)); - } - pixel = *src; - B = (Uint8)(pixel >> 16); G = (Uint8)(pixel >> 8); R = (Uint8)pixel; A = 0xFF; - pixel = ((Uint32)R << 16) | ((Uint32)G << 8) | B; - *dst = pixel; - posx += incx; - ++dst; - } - posy += incy; - info->dst += info->dst_pitch; - } -} - -static void SDL_Blit_BGR888_RGB888_Blend(SDL_BlitInfo *info) -{ - const int flags = info->flags; - Uint32 srcpixel; - Uint32 srcR, srcG, srcB, srcA; - Uint32 dstpixel; - Uint32 dstR, dstG, dstB, dstA; - - while (info->dst_h--) { - Uint32 *src = (Uint32 *)info->src; - Uint32 *dst = (Uint32 *)info->dst; - int n = info->dst_w; - while (n--) { - srcpixel = *src; - srcB = (Uint8)(srcpixel >> 16); srcG = (Uint8)(srcpixel >> 8); srcR = (Uint8)srcpixel; srcA = 0xFF; - dstpixel = *dst; - dstR = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstB = (Uint8)dstpixel; dstA = 0xFF; - if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) { - /* This goes away if we ever use premultiplied alpha */ - if (srcA < 255) { - srcR = (srcR * srcA) / 255; - srcG = (srcG * srcA) / 255; - srcB = (srcB * srcA) / 255; - } - } - switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) { - case SDL_COPY_BLEND: - dstR = srcR + ((255 - srcA) * dstR) / 255; - dstG = srcG + ((255 - srcA) * dstG) / 255; - dstB = srcB + ((255 - srcA) * dstB) / 255; - break; - case SDL_COPY_ADD: - dstR = srcR + dstR; if (dstR > 255) dstR = 255; - dstG = srcG + dstG; if (dstG > 255) dstG = 255; - dstB = srcB + dstB; if (dstB > 255) dstB = 255; - break; - case SDL_COPY_MOD: - dstR = (srcR * dstR) / 255; - dstG = (srcG * dstG) / 255; - dstB = (srcB * dstB) / 255; - break; - } - dstpixel = ((Uint32)dstR << 16) | ((Uint32)dstG << 8) | dstB; - *dst = dstpixel; - ++src; - ++dst; - } - info->src += info->src_pitch; - info->dst += info->dst_pitch; - } -} - -static void SDL_Blit_BGR888_RGB888_Blend_Scale(SDL_BlitInfo *info) -{ - const int flags = info->flags; - Uint32 srcpixel; - Uint32 srcR, srcG, srcB, srcA; - Uint32 dstpixel; - Uint32 dstR, dstG, dstB, dstA; - int srcy, srcx; - int posy, posx; - int incy, incx; - - srcy = 0; - posy = 0; - incy = (info->src_h << 16) / info->dst_h; - incx = (info->src_w << 16) / info->dst_w; - - while (info->dst_h--) { - Uint32 *src = 0; - Uint32 *dst = (Uint32 *)info->dst; - int n = info->dst_w; - srcx = -1; - posx = 0x10000L; - while (posy >= 0x10000L) { - ++srcy; - posy -= 0x10000L; - } - while (n--) { - if (posx >= 0x10000L) { - while (posx >= 0x10000L) { - ++srcx; - posx -= 0x10000L; - } - src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4)); - } - srcpixel = *src; - srcB = (Uint8)(srcpixel >> 16); srcG = (Uint8)(srcpixel >> 8); srcR = (Uint8)srcpixel; srcA = 0xFF; - dstpixel = *dst; - dstR = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstB = (Uint8)dstpixel; dstA = 0xFF; - if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) { - /* This goes away if we ever use premultiplied alpha */ - if (srcA < 255) { - srcR = (srcR * srcA) / 255; - srcG = (srcG * srcA) / 255; - srcB = (srcB * srcA) / 255; - } - } - switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) { - case SDL_COPY_BLEND: - dstR = srcR + ((255 - srcA) * dstR) / 255; - dstG = srcG + ((255 - srcA) * dstG) / 255; - dstB = srcB + ((255 - srcA) * dstB) / 255; - break; - case SDL_COPY_ADD: - dstR = srcR + dstR; if (dstR > 255) dstR = 255; - dstG = srcG + dstG; if (dstG > 255) dstG = 255; - dstB = srcB + dstB; if (dstB > 255) dstB = 255; - break; - case SDL_COPY_MOD: - dstR = (srcR * dstR) / 255; - dstG = (srcG * dstG) / 255; - dstB = (srcB * dstB) / 255; - break; - } - dstpixel = ((Uint32)dstR << 16) | ((Uint32)dstG << 8) | dstB; - *dst = dstpixel; - posx += incx; - ++dst; - } - posy += incy; - info->dst += info->dst_pitch; - } -} - -static void SDL_Blit_BGR888_RGB888_Modulate(SDL_BlitInfo *info) -{ - const int flags = info->flags; - const Uint32 modulateR = info->r; - const Uint32 modulateG = info->g; - const Uint32 modulateB = info->b; - const Uint32 modulateA = info->a; - Uint32 pixel; - Uint32 R, G, B, A; - - while (info->dst_h--) { - Uint32 *src = (Uint32 *)info->src; - Uint32 *dst = (Uint32 *)info->dst; - int n = info->dst_w; - while (n--) { - pixel = *src; - B = (Uint8)(pixel >> 16); G = (Uint8)(pixel >> 8); R = (Uint8)pixel; A = 0xFF; - if (flags & SDL_COPY_MODULATE_COLOR) { - R = (R * modulateR) / 255; - G = (G * modulateG) / 255; - B = (B * modulateB) / 255; - } - if (flags & SDL_COPY_MODULATE_ALPHA) { - A = (A * modulateA) / 255; - } - pixel = ((Uint32)R << 16) | ((Uint32)G << 8) | B; - *dst = pixel; - ++src; - ++dst; - } - info->src += info->src_pitch; - info->dst += info->dst_pitch; - } -} - -static void SDL_Blit_BGR888_RGB888_Modulate_Scale(SDL_BlitInfo *info) -{ - const int flags = info->flags; - const Uint32 modulateR = info->r; - const Uint32 modulateG = info->g; - const Uint32 modulateB = info->b; - const Uint32 modulateA = info->a; - Uint32 pixel; - Uint32 R, G, B, A; - int srcy, srcx; - int posy, posx; - int incy, incx; - - srcy = 0; - posy = 0; - incy = (info->src_h << 16) / info->dst_h; - incx = (info->src_w << 16) / info->dst_w; - - while (info->dst_h--) { - Uint32 *src = 0; - Uint32 *dst = (Uint32 *)info->dst; - int n = info->dst_w; - srcx = -1; - posx = 0x10000L; - while (posy >= 0x10000L) { - ++srcy; - posy -= 0x10000L; - } - while (n--) { - if (posx >= 0x10000L) { - while (posx >= 0x10000L) { - ++srcx; - posx -= 0x10000L; - } - src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4)); - } - pixel = *src; - B = (Uint8)(pixel >> 16); G = (Uint8)(pixel >> 8); R = (Uint8)pixel; A = 0xFF; - if (flags & SDL_COPY_MODULATE_COLOR) { - R = (R * modulateR) / 255; - G = (G * modulateG) / 255; - B = (B * modulateB) / 255; - } - if (flags & SDL_COPY_MODULATE_ALPHA) { - A = (A * modulateA) / 255; - } - pixel = ((Uint32)R << 16) | ((Uint32)G << 8) | B; - *dst = pixel; - posx += incx; - ++dst; - } - posy += incy; - info->dst += info->dst_pitch; - } -} - -static void SDL_Blit_BGR888_RGB888_Modulate_Blend(SDL_BlitInfo *info) -{ - const int flags = info->flags; - const Uint32 modulateR = info->r; - const Uint32 modulateG = info->g; - const Uint32 modulateB = info->b; - const Uint32 modulateA = info->a; - Uint32 srcpixel; - Uint32 srcR, srcG, srcB, srcA; - Uint32 dstpixel; - Uint32 dstR, dstG, dstB, dstA; - - while (info->dst_h--) { - Uint32 *src = (Uint32 *)info->src; - Uint32 *dst = (Uint32 *)info->dst; - int n = info->dst_w; - while (n--) { - srcpixel = *src; - srcB = (Uint8)(srcpixel >> 16); srcG = (Uint8)(srcpixel >> 8); srcR = (Uint8)srcpixel; srcA = 0xFF; - dstpixel = *dst; - dstR = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstB = (Uint8)dstpixel; dstA = 0xFF; - if (flags & SDL_COPY_MODULATE_COLOR) { - srcR = (srcR * modulateR) / 255; - srcG = (srcG * modulateG) / 255; - srcB = (srcB * modulateB) / 255; - } - if (flags & SDL_COPY_MODULATE_ALPHA) { - srcA = (srcA * modulateA) / 255; - } - if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) { - /* This goes away if we ever use premultiplied alpha */ - if (srcA < 255) { - srcR = (srcR * srcA) / 255; - srcG = (srcG * srcA) / 255; - srcB = (srcB * srcA) / 255; - } - } - switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) { - case SDL_COPY_BLEND: - dstR = srcR + ((255 - srcA) * dstR) / 255; - dstG = srcG + ((255 - srcA) * dstG) / 255; - dstB = srcB + ((255 - srcA) * dstB) / 255; - break; - case SDL_COPY_ADD: - dstR = srcR + dstR; if (dstR > 255) dstR = 255; - dstG = srcG + dstG; if (dstG > 255) dstG = 255; - dstB = srcB + dstB; if (dstB > 255) dstB = 255; - break; - case SDL_COPY_MOD: - dstR = (srcR * dstR) / 255; - dstG = (srcG * dstG) / 255; - dstB = (srcB * dstB) / 255; - break; - } - dstpixel = ((Uint32)dstR << 16) | ((Uint32)dstG << 8) | dstB; - *dst = dstpixel; - ++src; - ++dst; - } - info->src += info->src_pitch; - info->dst += info->dst_pitch; - } -} - -static void SDL_Blit_BGR888_RGB888_Modulate_Blend_Scale(SDL_BlitInfo *info) -{ - const int flags = info->flags; - const Uint32 modulateR = info->r; - const Uint32 modulateG = info->g; - const Uint32 modulateB = info->b; - const Uint32 modulateA = info->a; - Uint32 srcpixel; - Uint32 srcR, srcG, srcB, srcA; - Uint32 dstpixel; - Uint32 dstR, dstG, dstB, dstA; - int srcy, srcx; - int posy, posx; - int incy, incx; - - srcy = 0; - posy = 0; - incy = (info->src_h << 16) / info->dst_h; - incx = (info->src_w << 16) / info->dst_w; - - while (info->dst_h--) { - Uint32 *src = 0; - Uint32 *dst = (Uint32 *)info->dst; - int n = info->dst_w; - srcx = -1; - posx = 0x10000L; - while (posy >= 0x10000L) { - ++srcy; - posy -= 0x10000L; - } - while (n--) { - if (posx >= 0x10000L) { - while (posx >= 0x10000L) { - ++srcx; - posx -= 0x10000L; - } - src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4)); - } - srcpixel = *src; - srcB = (Uint8)(srcpixel >> 16); srcG = (Uint8)(srcpixel >> 8); srcR = (Uint8)srcpixel; srcA = 0xFF; - dstpixel = *dst; - dstR = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstB = (Uint8)dstpixel; dstA = 0xFF; - if (flags & SDL_COPY_MODULATE_COLOR) { - srcR = (srcR * modulateR) / 255; - srcG = (srcG * modulateG) / 255; - srcB = (srcB * modulateB) / 255; - } - if (flags & SDL_COPY_MODULATE_ALPHA) { - srcA = (srcA * modulateA) / 255; - } - if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) { - /* This goes away if we ever use premultiplied alpha */ - if (srcA < 255) { - srcR = (srcR * srcA) / 255; - srcG = (srcG * srcA) / 255; - srcB = (srcB * srcA) / 255; - } - } - switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) { - case SDL_COPY_BLEND: - dstR = srcR + ((255 - srcA) * dstR) / 255; - dstG = srcG + ((255 - srcA) * dstG) / 255; - dstB = srcB + ((255 - srcA) * dstB) / 255; - break; - case SDL_COPY_ADD: - dstR = srcR + dstR; if (dstR > 255) dstR = 255; - dstG = srcG + dstG; if (dstG > 255) dstG = 255; - dstB = srcB + dstB; if (dstB > 255) dstB = 255; - break; - case SDL_COPY_MOD: - dstR = (srcR * dstR) / 255; - dstG = (srcG * dstG) / 255; - dstB = (srcB * dstB) / 255; - break; - } - dstpixel = ((Uint32)dstR << 16) | ((Uint32)dstG << 8) | dstB; - *dst = dstpixel; - posx += incx; - ++dst; - } - posy += incy; - info->dst += info->dst_pitch; - } -} - -static void SDL_Blit_BGR888_BGR888_Scale(SDL_BlitInfo *info) -{ - int srcy, srcx; - int posy, posx; - int incy, incx; - - srcy = 0; - posy = 0; - incy = (info->src_h << 16) / info->dst_h; - incx = (info->src_w << 16) / info->dst_w; - - while (info->dst_h--) { - Uint32 *src = 0; - Uint32 *dst = (Uint32 *)info->dst; - int n = info->dst_w; - srcx = -1; - posx = 0x10000L; - while (posy >= 0x10000L) { - ++srcy; - posy -= 0x10000L; - } - while (n--) { - if (posx >= 0x10000L) { - while (posx >= 0x10000L) { - ++srcx; - posx -= 0x10000L; - } - src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4)); - } - *dst = *src; - posx += incx; - ++dst; - } - posy += incy; - info->dst += info->dst_pitch; - } -} - -static void SDL_Blit_BGR888_BGR888_Blend(SDL_BlitInfo *info) -{ - const int flags = info->flags; - Uint32 srcpixel; - Uint32 srcR, srcG, srcB, srcA; - Uint32 dstpixel; - Uint32 dstR, dstG, dstB, dstA; - - while (info->dst_h--) { - Uint32 *src = (Uint32 *)info->src; - Uint32 *dst = (Uint32 *)info->dst; - int n = info->dst_w; - while (n--) { - srcpixel = *src; - srcB = (Uint8)(srcpixel >> 16); srcG = (Uint8)(srcpixel >> 8); srcR = (Uint8)srcpixel; srcA = 0xFF; - dstpixel = *dst; - dstB = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstR = (Uint8)dstpixel; dstA = 0xFF; - if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) { - /* This goes away if we ever use premultiplied alpha */ - if (srcA < 255) { - srcR = (srcR * srcA) / 255; - srcG = (srcG * srcA) / 255; - srcB = (srcB * srcA) / 255; - } - } - switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) { - case SDL_COPY_BLEND: - dstR = srcR + ((255 - srcA) * dstR) / 255; - dstG = srcG + ((255 - srcA) * dstG) / 255; - dstB = srcB + ((255 - srcA) * dstB) / 255; - break; - case SDL_COPY_ADD: - dstR = srcR + dstR; if (dstR > 255) dstR = 255; - dstG = srcG + dstG; if (dstG > 255) dstG = 255; - dstB = srcB + dstB; if (dstB > 255) dstB = 255; - break; - case SDL_COPY_MOD: - dstR = (srcR * dstR) / 255; - dstG = (srcG * dstG) / 255; - dstB = (srcB * dstB) / 255; - break; - } - dstpixel = ((Uint32)dstB << 16) | ((Uint32)dstG << 8) | dstR; - *dst = dstpixel; - ++src; - ++dst; - } - info->src += info->src_pitch; - info->dst += info->dst_pitch; - } -} - -static void SDL_Blit_BGR888_BGR888_Blend_Scale(SDL_BlitInfo *info) -{ - const int flags = info->flags; - Uint32 srcpixel; - Uint32 srcR, srcG, srcB, srcA; - Uint32 dstpixel; - Uint32 dstR, dstG, dstB, dstA; - int srcy, srcx; - int posy, posx; - int incy, incx; - - srcy = 0; - posy = 0; - incy = (info->src_h << 16) / info->dst_h; - incx = (info->src_w << 16) / info->dst_w; - - while (info->dst_h--) { - Uint32 *src = 0; - Uint32 *dst = (Uint32 *)info->dst; - int n = info->dst_w; - srcx = -1; - posx = 0x10000L; - while (posy >= 0x10000L) { - ++srcy; - posy -= 0x10000L; - } - while (n--) { - if (posx >= 0x10000L) { - while (posx >= 0x10000L) { - ++srcx; - posx -= 0x10000L; - } - src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4)); - } - srcpixel = *src; - srcB = (Uint8)(srcpixel >> 16); srcG = (Uint8)(srcpixel >> 8); srcR = (Uint8)srcpixel; srcA = 0xFF; - dstpixel = *dst; - dstB = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstR = (Uint8)dstpixel; dstA = 0xFF; - if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) { - /* This goes away if we ever use premultiplied alpha */ - if (srcA < 255) { - srcR = (srcR * srcA) / 255; - srcG = (srcG * srcA) / 255; - srcB = (srcB * srcA) / 255; - } - } - switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) { - case SDL_COPY_BLEND: - dstR = srcR + ((255 - srcA) * dstR) / 255; - dstG = srcG + ((255 - srcA) * dstG) / 255; - dstB = srcB + ((255 - srcA) * dstB) / 255; - break; - case SDL_COPY_ADD: - dstR = srcR + dstR; if (dstR > 255) dstR = 255; - dstG = srcG + dstG; if (dstG > 255) dstG = 255; - dstB = srcB + dstB; if (dstB > 255) dstB = 255; - break; - case SDL_COPY_MOD: - dstR = (srcR * dstR) / 255; - dstG = (srcG * dstG) / 255; - dstB = (srcB * dstB) / 255; - break; - } - dstpixel = ((Uint32)dstB << 16) | ((Uint32)dstG << 8) | dstR; - *dst = dstpixel; - posx += incx; - ++dst; - } - posy += incy; - info->dst += info->dst_pitch; - } -} - -static void SDL_Blit_BGR888_BGR888_Modulate(SDL_BlitInfo *info) -{ - const int flags = info->flags; - const Uint32 modulateR = info->r; - const Uint32 modulateG = info->g; - const Uint32 modulateB = info->b; - const Uint32 modulateA = info->a; - Uint32 pixel; - Uint32 R, G, B, A; - - while (info->dst_h--) { - Uint32 *src = (Uint32 *)info->src; - Uint32 *dst = (Uint32 *)info->dst; - int n = info->dst_w; - while (n--) { - pixel = *src; - B = (Uint8)(pixel >> 16); G = (Uint8)(pixel >> 8); R = (Uint8)pixel; A = 0xFF; - if (flags & SDL_COPY_MODULATE_COLOR) { - R = (R * modulateR) / 255; - G = (G * modulateG) / 255; - B = (B * modulateB) / 255; - } - if (flags & SDL_COPY_MODULATE_ALPHA) { - A = (A * modulateA) / 255; - } - pixel = ((Uint32)B << 16) | ((Uint32)G << 8) | R; - *dst = pixel; - ++src; - ++dst; - } - info->src += info->src_pitch; - info->dst += info->dst_pitch; - } -} - -static void SDL_Blit_BGR888_BGR888_Modulate_Scale(SDL_BlitInfo *info) -{ - const int flags = info->flags; - const Uint32 modulateR = info->r; - const Uint32 modulateG = info->g; - const Uint32 modulateB = info->b; - const Uint32 modulateA = info->a; - Uint32 pixel; - Uint32 R, G, B, A; - int srcy, srcx; - int posy, posx; - int incy, incx; - - srcy = 0; - posy = 0; - incy = (info->src_h << 16) / info->dst_h; - incx = (info->src_w << 16) / info->dst_w; - - while (info->dst_h--) { - Uint32 *src = 0; - Uint32 *dst = (Uint32 *)info->dst; - int n = info->dst_w; - srcx = -1; - posx = 0x10000L; - while (posy >= 0x10000L) { - ++srcy; - posy -= 0x10000L; - } - while (n--) { - if (posx >= 0x10000L) { - while (posx >= 0x10000L) { - ++srcx; - posx -= 0x10000L; - } - src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4)); - } - pixel = *src; - B = (Uint8)(pixel >> 16); G = (Uint8)(pixel >> 8); R = (Uint8)pixel; A = 0xFF; - if (flags & SDL_COPY_MODULATE_COLOR) { - R = (R * modulateR) / 255; - G = (G * modulateG) / 255; - B = (B * modulateB) / 255; - } - if (flags & SDL_COPY_MODULATE_ALPHA) { - A = (A * modulateA) / 255; - } - pixel = ((Uint32)B << 16) | ((Uint32)G << 8) | R; - *dst = pixel; - posx += incx; - ++dst; - } - posy += incy; - info->dst += info->dst_pitch; - } -} - -static void SDL_Blit_BGR888_BGR888_Modulate_Blend(SDL_BlitInfo *info) -{ - const int flags = info->flags; - const Uint32 modulateR = info->r; - const Uint32 modulateG = info->g; - const Uint32 modulateB = info->b; - const Uint32 modulateA = info->a; - Uint32 srcpixel; - Uint32 srcR, srcG, srcB, srcA; - Uint32 dstpixel; - Uint32 dstR, dstG, dstB, dstA; - - while (info->dst_h--) { - Uint32 *src = (Uint32 *)info->src; - Uint32 *dst = (Uint32 *)info->dst; - int n = info->dst_w; - while (n--) { - srcpixel = *src; - srcB = (Uint8)(srcpixel >> 16); srcG = (Uint8)(srcpixel >> 8); srcR = (Uint8)srcpixel; srcA = 0xFF; - dstpixel = *dst; - dstB = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstR = (Uint8)dstpixel; dstA = 0xFF; - if (flags & SDL_COPY_MODULATE_COLOR) { - srcR = (srcR * modulateR) / 255; - srcG = (srcG * modulateG) / 255; - srcB = (srcB * modulateB) / 255; - } - if (flags & SDL_COPY_MODULATE_ALPHA) { - srcA = (srcA * modulateA) / 255; - } - if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) { - /* This goes away if we ever use premultiplied alpha */ - if (srcA < 255) { - srcR = (srcR * srcA) / 255; - srcG = (srcG * srcA) / 255; - srcB = (srcB * srcA) / 255; - } - } - switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) { - case SDL_COPY_BLEND: - dstR = srcR + ((255 - srcA) * dstR) / 255; - dstG = srcG + ((255 - srcA) * dstG) / 255; - dstB = srcB + ((255 - srcA) * dstB) / 255; - break; - case SDL_COPY_ADD: - dstR = srcR + dstR; if (dstR > 255) dstR = 255; - dstG = srcG + dstG; if (dstG > 255) dstG = 255; - dstB = srcB + dstB; if (dstB > 255) dstB = 255; - break; - case SDL_COPY_MOD: - dstR = (srcR * dstR) / 255; - dstG = (srcG * dstG) / 255; - dstB = (srcB * dstB) / 255; - break; - } - dstpixel = ((Uint32)dstB << 16) | ((Uint32)dstG << 8) | dstR; - *dst = dstpixel; - ++src; - ++dst; - } - info->src += info->src_pitch; - info->dst += info->dst_pitch; - } -} - -static void SDL_Blit_BGR888_BGR888_Modulate_Blend_Scale(SDL_BlitInfo *info) -{ - const int flags = info->flags; - const Uint32 modulateR = info->r; - const Uint32 modulateG = info->g; - const Uint32 modulateB = info->b; - const Uint32 modulateA = info->a; - Uint32 srcpixel; - Uint32 srcR, srcG, srcB, srcA; - Uint32 dstpixel; - Uint32 dstR, dstG, dstB, dstA; - int srcy, srcx; - int posy, posx; - int incy, incx; - - srcy = 0; - posy = 0; - incy = (info->src_h << 16) / info->dst_h; - incx = (info->src_w << 16) / info->dst_w; - - while (info->dst_h--) { - Uint32 *src = 0; - Uint32 *dst = (Uint32 *)info->dst; - int n = info->dst_w; - srcx = -1; - posx = 0x10000L; - while (posy >= 0x10000L) { - ++srcy; - posy -= 0x10000L; - } - while (n--) { - if (posx >= 0x10000L) { - while (posx >= 0x10000L) { - ++srcx; - posx -= 0x10000L; - } - src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4)); - } - srcpixel = *src; - srcB = (Uint8)(srcpixel >> 16); srcG = (Uint8)(srcpixel >> 8); srcR = (Uint8)srcpixel; srcA = 0xFF; - dstpixel = *dst; - dstB = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstR = (Uint8)dstpixel; dstA = 0xFF; - if (flags & SDL_COPY_MODULATE_COLOR) { - srcR = (srcR * modulateR) / 255; - srcG = (srcG * modulateG) / 255; - srcB = (srcB * modulateB) / 255; - } - if (flags & SDL_COPY_MODULATE_ALPHA) { - srcA = (srcA * modulateA) / 255; - } - if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) { - /* This goes away if we ever use premultiplied alpha */ - if (srcA < 255) { - srcR = (srcR * srcA) / 255; - srcG = (srcG * srcA) / 255; - srcB = (srcB * srcA) / 255; - } - } - switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) { - case SDL_COPY_BLEND: - dstR = srcR + ((255 - srcA) * dstR) / 255; - dstG = srcG + ((255 - srcA) * dstG) / 255; - dstB = srcB + ((255 - srcA) * dstB) / 255; - break; - case SDL_COPY_ADD: - dstR = srcR + dstR; if (dstR > 255) dstR = 255; - dstG = srcG + dstG; if (dstG > 255) dstG = 255; - dstB = srcB + dstB; if (dstB > 255) dstB = 255; - break; - case SDL_COPY_MOD: - dstR = (srcR * dstR) / 255; - dstG = (srcG * dstG) / 255; - dstB = (srcB * dstB) / 255; - break; - } - dstpixel = ((Uint32)dstB << 16) | ((Uint32)dstG << 8) | dstR; - *dst = dstpixel; - posx += incx; - ++dst; - } - posy += incy; - info->dst += info->dst_pitch; - } -} - -static void SDL_Blit_BGR888_ARGB8888_Scale(SDL_BlitInfo *info) -{ - Uint32 pixel; - Uint32 R, G, B, A; - int srcy, srcx; - int posy, posx; - int incy, incx; - - srcy = 0; - posy = 0; - incy = (info->src_h << 16) / info->dst_h; - incx = (info->src_w << 16) / info->dst_w; - - while (info->dst_h--) { - Uint32 *src = 0; - Uint32 *dst = (Uint32 *)info->dst; - int n = info->dst_w; - srcx = -1; - posx = 0x10000L; - while (posy >= 0x10000L) { - ++srcy; - posy -= 0x10000L; - } - while (n--) { - if (posx >= 0x10000L) { - while (posx >= 0x10000L) { - ++srcx; - posx -= 0x10000L; - } - src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4)); - } - pixel = *src; - B = (Uint8)(pixel >> 16); G = (Uint8)(pixel >> 8); R = (Uint8)pixel; A = 0xFF; - pixel = ((Uint32)A << 24) | ((Uint32)R << 16) | ((Uint32)G << 8) | B; - *dst = pixel; - posx += incx; - ++dst; - } - posy += incy; - info->dst += info->dst_pitch; - } -} - -static void SDL_Blit_BGR888_ARGB8888_Blend(SDL_BlitInfo *info) -{ - const int flags = info->flags; - Uint32 srcpixel; - Uint32 srcR, srcG, srcB, srcA; - Uint32 dstpixel; - Uint32 dstR, dstG, dstB, dstA; - - while (info->dst_h--) { - Uint32 *src = (Uint32 *)info->src; - Uint32 *dst = (Uint32 *)info->dst; - int n = info->dst_w; - while (n--) { - srcpixel = *src; - srcB = (Uint8)(srcpixel >> 16); srcG = (Uint8)(srcpixel >> 8); srcR = (Uint8)srcpixel; srcA = 0xFF; - dstpixel = *dst; - dstA = (Uint8)(dstpixel >> 24); dstR = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstB = (Uint8)dstpixel; - if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) { - /* This goes away if we ever use premultiplied alpha */ - if (srcA < 255) { - srcR = (srcR * srcA) / 255; - srcG = (srcG * srcA) / 255; - srcB = (srcB * srcA) / 255; - } - } - switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) { - case SDL_COPY_BLEND: - dstR = srcR + ((255 - srcA) * dstR) / 255; - dstG = srcG + ((255 - srcA) * dstG) / 255; - dstB = srcB + ((255 - srcA) * dstB) / 255; - break; - case SDL_COPY_ADD: - dstR = srcR + dstR; if (dstR > 255) dstR = 255; - dstG = srcG + dstG; if (dstG > 255) dstG = 255; - dstB = srcB + dstB; if (dstB > 255) dstB = 255; - break; - case SDL_COPY_MOD: - dstR = (srcR * dstR) / 255; - dstG = (srcG * dstG) / 255; - dstB = (srcB * dstB) / 255; - break; - } - dstpixel = ((Uint32)dstA << 24) | ((Uint32)dstR << 16) | ((Uint32)dstG << 8) | dstB; - *dst = dstpixel; - ++src; - ++dst; - } - info->src += info->src_pitch; - info->dst += info->dst_pitch; - } -} - -static void SDL_Blit_BGR888_ARGB8888_Blend_Scale(SDL_BlitInfo *info) -{ - const int flags = info->flags; - Uint32 srcpixel; - Uint32 srcR, srcG, srcB, srcA; - Uint32 dstpixel; - Uint32 dstR, dstG, dstB, dstA; - int srcy, srcx; - int posy, posx; - int incy, incx; - - srcy = 0; - posy = 0; - incy = (info->src_h << 16) / info->dst_h; - incx = (info->src_w << 16) / info->dst_w; - - while (info->dst_h--) { - Uint32 *src = 0; - Uint32 *dst = (Uint32 *)info->dst; - int n = info->dst_w; - srcx = -1; - posx = 0x10000L; - while (posy >= 0x10000L) { - ++srcy; - posy -= 0x10000L; - } - while (n--) { - if (posx >= 0x10000L) { - while (posx >= 0x10000L) { - ++srcx; - posx -= 0x10000L; - } - src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4)); - } - srcpixel = *src; - srcB = (Uint8)(srcpixel >> 16); srcG = (Uint8)(srcpixel >> 8); srcR = (Uint8)srcpixel; srcA = 0xFF; - dstpixel = *dst; - dstA = (Uint8)(dstpixel >> 24); dstR = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstB = (Uint8)dstpixel; - if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) { - /* This goes away if we ever use premultiplied alpha */ - if (srcA < 255) { - srcR = (srcR * srcA) / 255; - srcG = (srcG * srcA) / 255; - srcB = (srcB * srcA) / 255; - } - } - switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) { - case SDL_COPY_BLEND: - dstR = srcR + ((255 - srcA) * dstR) / 255; - dstG = srcG + ((255 - srcA) * dstG) / 255; - dstB = srcB + ((255 - srcA) * dstB) / 255; - break; - case SDL_COPY_ADD: - dstR = srcR + dstR; if (dstR > 255) dstR = 255; - dstG = srcG + dstG; if (dstG > 255) dstG = 255; - dstB = srcB + dstB; if (dstB > 255) dstB = 255; - break; - case SDL_COPY_MOD: - dstR = (srcR * dstR) / 255; - dstG = (srcG * dstG) / 255; - dstB = (srcB * dstB) / 255; - break; - } - dstpixel = ((Uint32)dstA << 24) | ((Uint32)dstR << 16) | ((Uint32)dstG << 8) | dstB; - *dst = dstpixel; - posx += incx; - ++dst; - } - posy += incy; - info->dst += info->dst_pitch; - } -} - -static void SDL_Blit_BGR888_ARGB8888_Modulate(SDL_BlitInfo *info) -{ - const int flags = info->flags; - const Uint32 modulateR = info->r; - const Uint32 modulateG = info->g; - const Uint32 modulateB = info->b; - const Uint32 modulateA = info->a; - Uint32 pixel; - Uint32 R, G, B, A; - - while (info->dst_h--) { - Uint32 *src = (Uint32 *)info->src; - Uint32 *dst = (Uint32 *)info->dst; - int n = info->dst_w; - while (n--) { - pixel = *src; - B = (Uint8)(pixel >> 16); G = (Uint8)(pixel >> 8); R = (Uint8)pixel; A = 0xFF; - if (flags & SDL_COPY_MODULATE_COLOR) { - R = (R * modulateR) / 255; - G = (G * modulateG) / 255; - B = (B * modulateB) / 255; - } - if (flags & SDL_COPY_MODULATE_ALPHA) { - A = (A * modulateA) / 255; - } - pixel = ((Uint32)A << 24) | ((Uint32)R << 16) | ((Uint32)G << 8) | B; - *dst = pixel; - ++src; - ++dst; - } - info->src += info->src_pitch; - info->dst += info->dst_pitch; - } -} - -static void SDL_Blit_BGR888_ARGB8888_Modulate_Scale(SDL_BlitInfo *info) -{ - const int flags = info->flags; - const Uint32 modulateR = info->r; - const Uint32 modulateG = info->g; - const Uint32 modulateB = info->b; - const Uint32 modulateA = info->a; - Uint32 pixel; - Uint32 R, G, B, A; - int srcy, srcx; - int posy, posx; - int incy, incx; - - srcy = 0; - posy = 0; - incy = (info->src_h << 16) / info->dst_h; - incx = (info->src_w << 16) / info->dst_w; - - while (info->dst_h--) { - Uint32 *src = 0; - Uint32 *dst = (Uint32 *)info->dst; - int n = info->dst_w; - srcx = -1; - posx = 0x10000L; - while (posy >= 0x10000L) { - ++srcy; - posy -= 0x10000L; - } - while (n--) { - if (posx >= 0x10000L) { - while (posx >= 0x10000L) { - ++srcx; - posx -= 0x10000L; - } - src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4)); - } - pixel = *src; - B = (Uint8)(pixel >> 16); G = (Uint8)(pixel >> 8); R = (Uint8)pixel; A = 0xFF; - if (flags & SDL_COPY_MODULATE_COLOR) { - R = (R * modulateR) / 255; - G = (G * modulateG) / 255; - B = (B * modulateB) / 255; - } - if (flags & SDL_COPY_MODULATE_ALPHA) { - A = (A * modulateA) / 255; - } - pixel = ((Uint32)A << 24) | ((Uint32)R << 16) | ((Uint32)G << 8) | B; - *dst = pixel; - posx += incx; - ++dst; - } - posy += incy; - info->dst += info->dst_pitch; - } -} - -static void SDL_Blit_BGR888_ARGB8888_Modulate_Blend(SDL_BlitInfo *info) -{ - const int flags = info->flags; - const Uint32 modulateR = info->r; - const Uint32 modulateG = info->g; - const Uint32 modulateB = info->b; - const Uint32 modulateA = info->a; - Uint32 srcpixel; - Uint32 srcR, srcG, srcB, srcA; - Uint32 dstpixel; - Uint32 dstR, dstG, dstB, dstA; - - while (info->dst_h--) { - Uint32 *src = (Uint32 *)info->src; - Uint32 *dst = (Uint32 *)info->dst; - int n = info->dst_w; - while (n--) { - srcpixel = *src; - srcB = (Uint8)(srcpixel >> 16); srcG = (Uint8)(srcpixel >> 8); srcR = (Uint8)srcpixel; srcA = 0xFF; - dstpixel = *dst; - dstA = (Uint8)(dstpixel >> 24); dstR = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstB = (Uint8)dstpixel; - if (flags & SDL_COPY_MODULATE_COLOR) { - srcR = (srcR * modulateR) / 255; - srcG = (srcG * modulateG) / 255; - srcB = (srcB * modulateB) / 255; - } - if (flags & SDL_COPY_MODULATE_ALPHA) { - srcA = (srcA * modulateA) / 255; - } - if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) { - /* This goes away if we ever use premultiplied alpha */ - if (srcA < 255) { - srcR = (srcR * srcA) / 255; - srcG = (srcG * srcA) / 255; - srcB = (srcB * srcA) / 255; - } - } - switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) { - case SDL_COPY_BLEND: - dstR = srcR + ((255 - srcA) * dstR) / 255; - dstG = srcG + ((255 - srcA) * dstG) / 255; - dstB = srcB + ((255 - srcA) * dstB) / 255; - break; - case SDL_COPY_ADD: - dstR = srcR + dstR; if (dstR > 255) dstR = 255; - dstG = srcG + dstG; if (dstG > 255) dstG = 255; - dstB = srcB + dstB; if (dstB > 255) dstB = 255; - break; - case SDL_COPY_MOD: - dstR = (srcR * dstR) / 255; - dstG = (srcG * dstG) / 255; - dstB = (srcB * dstB) / 255; - break; - } - dstpixel = ((Uint32)dstA << 24) | ((Uint32)dstR << 16) | ((Uint32)dstG << 8) | dstB; - *dst = dstpixel; - ++src; - ++dst; - } - info->src += info->src_pitch; - info->dst += info->dst_pitch; - } -} - -static void SDL_Blit_BGR888_ARGB8888_Modulate_Blend_Scale(SDL_BlitInfo *info) -{ - const int flags = info->flags; - const Uint32 modulateR = info->r; - const Uint32 modulateG = info->g; - const Uint32 modulateB = info->b; - const Uint32 modulateA = info->a; - Uint32 srcpixel; - Uint32 srcR, srcG, srcB, srcA; - Uint32 dstpixel; - Uint32 dstR, dstG, dstB, dstA; - int srcy, srcx; - int posy, posx; - int incy, incx; - - srcy = 0; - posy = 0; - incy = (info->src_h << 16) / info->dst_h; - incx = (info->src_w << 16) / info->dst_w; - - while (info->dst_h--) { - Uint32 *src = 0; - Uint32 *dst = (Uint32 *)info->dst; - int n = info->dst_w; - srcx = -1; - posx = 0x10000L; - while (posy >= 0x10000L) { - ++srcy; - posy -= 0x10000L; - } - while (n--) { - if (posx >= 0x10000L) { - while (posx >= 0x10000L) { - ++srcx; - posx -= 0x10000L; - } - src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4)); - } - srcpixel = *src; - srcB = (Uint8)(srcpixel >> 16); srcG = (Uint8)(srcpixel >> 8); srcR = (Uint8)srcpixel; srcA = 0xFF; - dstpixel = *dst; - dstA = (Uint8)(dstpixel >> 24); dstR = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstB = (Uint8)dstpixel; - if (flags & SDL_COPY_MODULATE_COLOR) { - srcR = (srcR * modulateR) / 255; - srcG = (srcG * modulateG) / 255; - srcB = (srcB * modulateB) / 255; - } - if (flags & SDL_COPY_MODULATE_ALPHA) { - srcA = (srcA * modulateA) / 255; - } - if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) { - /* This goes away if we ever use premultiplied alpha */ - if (srcA < 255) { - srcR = (srcR * srcA) / 255; - srcG = (srcG * srcA) / 255; - srcB = (srcB * srcA) / 255; - } - } - switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) { - case SDL_COPY_BLEND: - dstR = srcR + ((255 - srcA) * dstR) / 255; - dstG = srcG + ((255 - srcA) * dstG) / 255; - dstB = srcB + ((255 - srcA) * dstB) / 255; - break; - case SDL_COPY_ADD: - dstR = srcR + dstR; if (dstR > 255) dstR = 255; - dstG = srcG + dstG; if (dstG > 255) dstG = 255; - dstB = srcB + dstB; if (dstB > 255) dstB = 255; - break; - case SDL_COPY_MOD: - dstR = (srcR * dstR) / 255; - dstG = (srcG * dstG) / 255; - dstB = (srcB * dstB) / 255; - break; - } - dstpixel = ((Uint32)dstA << 24) | ((Uint32)dstR << 16) | ((Uint32)dstG << 8) | dstB; - *dst = dstpixel; - posx += incx; - ++dst; - } - posy += incy; - info->dst += info->dst_pitch; - } -} - -static void SDL_Blit_ARGB8888_RGB888_Scale(SDL_BlitInfo *info) -{ - Uint32 pixel; - Uint32 R, G, B, A; - int srcy, srcx; - int posy, posx; - int incy, incx; - - srcy = 0; - posy = 0; - incy = (info->src_h << 16) / info->dst_h; - incx = (info->src_w << 16) / info->dst_w; - - while (info->dst_h--) { - Uint32 *src = 0; - Uint32 *dst = (Uint32 *)info->dst; - int n = info->dst_w; - srcx = -1; - posx = 0x10000L; - while (posy >= 0x10000L) { - ++srcy; - posy -= 0x10000L; - } - while (n--) { - if (posx >= 0x10000L) { - while (posx >= 0x10000L) { - ++srcx; - posx -= 0x10000L; - } - src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4)); - } - pixel = *src; - A = (Uint8)(pixel >> 24); R = (Uint8)(pixel >> 16); G = (Uint8)(pixel >> 8); B = (Uint8)pixel; - pixel = ((Uint32)R << 16) | ((Uint32)G << 8) | B; - *dst = pixel; - posx += incx; - ++dst; - } - posy += incy; - info->dst += info->dst_pitch; - } -} - -static void SDL_Blit_ARGB8888_RGB888_Blend(SDL_BlitInfo *info) -{ - const int flags = info->flags; - Uint32 srcpixel; - Uint32 srcR, srcG, srcB, srcA; - Uint32 dstpixel; - Uint32 dstR, dstG, dstB, dstA; - - while (info->dst_h--) { - Uint32 *src = (Uint32 *)info->src; - Uint32 *dst = (Uint32 *)info->dst; - int n = info->dst_w; - while (n--) { - srcpixel = *src; - srcA = (Uint8)(srcpixel >> 24); srcR = (Uint8)(srcpixel >> 16); srcG = (Uint8)(srcpixel >> 8); srcB = (Uint8)srcpixel; - dstpixel = *dst; - dstR = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstB = (Uint8)dstpixel; dstA = 0xFF; - if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) { - /* This goes away if we ever use premultiplied alpha */ - if (srcA < 255) { - srcR = (srcR * srcA) / 255; - srcG = (srcG * srcA) / 255; - srcB = (srcB * srcA) / 255; - } - } - switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) { - case SDL_COPY_BLEND: - dstR = srcR + ((255 - srcA) * dstR) / 255; - dstG = srcG + ((255 - srcA) * dstG) / 255; - dstB = srcB + ((255 - srcA) * dstB) / 255; - break; - case SDL_COPY_ADD: - dstR = srcR + dstR; if (dstR > 255) dstR = 255; - dstG = srcG + dstG; if (dstG > 255) dstG = 255; - dstB = srcB + dstB; if (dstB > 255) dstB = 255; - break; - case SDL_COPY_MOD: - dstR = (srcR * dstR) / 255; - dstG = (srcG * dstG) / 255; - dstB = (srcB * dstB) / 255; - break; - } - dstpixel = ((Uint32)dstR << 16) | ((Uint32)dstG << 8) | dstB; - *dst = dstpixel; - ++src; - ++dst; - } - info->src += info->src_pitch; - info->dst += info->dst_pitch; - } -} - -static void SDL_Blit_ARGB8888_RGB888_Blend_Scale(SDL_BlitInfo *info) -{ - const int flags = info->flags; - Uint32 srcpixel; - Uint32 srcR, srcG, srcB, srcA; - Uint32 dstpixel; - Uint32 dstR, dstG, dstB, dstA; - int srcy, srcx; - int posy, posx; - int incy, incx; - - srcy = 0; - posy = 0; - incy = (info->src_h << 16) / info->dst_h; - incx = (info->src_w << 16) / info->dst_w; - - while (info->dst_h--) { - Uint32 *src = 0; - Uint32 *dst = (Uint32 *)info->dst; - int n = info->dst_w; - srcx = -1; - posx = 0x10000L; - while (posy >= 0x10000L) { - ++srcy; - posy -= 0x10000L; - } - while (n--) { - if (posx >= 0x10000L) { - while (posx >= 0x10000L) { - ++srcx; - posx -= 0x10000L; - } - src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4)); - } - srcpixel = *src; - srcA = (Uint8)(srcpixel >> 24); srcR = (Uint8)(srcpixel >> 16); srcG = (Uint8)(srcpixel >> 8); srcB = (Uint8)srcpixel; - dstpixel = *dst; - dstR = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstB = (Uint8)dstpixel; dstA = 0xFF; - if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) { - /* This goes away if we ever use premultiplied alpha */ - if (srcA < 255) { - srcR = (srcR * srcA) / 255; - srcG = (srcG * srcA) / 255; - srcB = (srcB * srcA) / 255; - } - } - switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) { - case SDL_COPY_BLEND: - dstR = srcR + ((255 - srcA) * dstR) / 255; - dstG = srcG + ((255 - srcA) * dstG) / 255; - dstB = srcB + ((255 - srcA) * dstB) / 255; - break; - case SDL_COPY_ADD: - dstR = srcR + dstR; if (dstR > 255) dstR = 255; - dstG = srcG + dstG; if (dstG > 255) dstG = 255; - dstB = srcB + dstB; if (dstB > 255) dstB = 255; - break; - case SDL_COPY_MOD: - dstR = (srcR * dstR) / 255; - dstG = (srcG * dstG) / 255; - dstB = (srcB * dstB) / 255; - break; - } - dstpixel = ((Uint32)dstR << 16) | ((Uint32)dstG << 8) | dstB; - *dst = dstpixel; - posx += incx; - ++dst; - } - posy += incy; - info->dst += info->dst_pitch; - } -} - -static void SDL_Blit_ARGB8888_RGB888_Modulate(SDL_BlitInfo *info) -{ - const int flags = info->flags; - const Uint32 modulateR = info->r; - const Uint32 modulateG = info->g; - const Uint32 modulateB = info->b; - const Uint32 modulateA = info->a; - Uint32 pixel; - Uint32 R, G, B, A; - - while (info->dst_h--) { - Uint32 *src = (Uint32 *)info->src; - Uint32 *dst = (Uint32 *)info->dst; - int n = info->dst_w; - while (n--) { - pixel = *src; - A = (Uint8)(pixel >> 24); R = (Uint8)(pixel >> 16); G = (Uint8)(pixel >> 8); B = (Uint8)pixel; - if (flags & SDL_COPY_MODULATE_COLOR) { - R = (R * modulateR) / 255; - G = (G * modulateG) / 255; - B = (B * modulateB) / 255; - } - if (flags & SDL_COPY_MODULATE_ALPHA) { - A = (A * modulateA) / 255; - } - pixel = ((Uint32)R << 16) | ((Uint32)G << 8) | B; - *dst = pixel; - ++src; - ++dst; - } - info->src += info->src_pitch; - info->dst += info->dst_pitch; - } -} - -static void SDL_Blit_ARGB8888_RGB888_Modulate_Scale(SDL_BlitInfo *info) -{ - const int flags = info->flags; - const Uint32 modulateR = info->r; - const Uint32 modulateG = info->g; - const Uint32 modulateB = info->b; - const Uint32 modulateA = info->a; - Uint32 pixel; - Uint32 R, G, B, A; - int srcy, srcx; - int posy, posx; - int incy, incx; - - srcy = 0; - posy = 0; - incy = (info->src_h << 16) / info->dst_h; - incx = (info->src_w << 16) / info->dst_w; - - while (info->dst_h--) { - Uint32 *src = 0; - Uint32 *dst = (Uint32 *)info->dst; - int n = info->dst_w; - srcx = -1; - posx = 0x10000L; - while (posy >= 0x10000L) { - ++srcy; - posy -= 0x10000L; - } - while (n--) { - if (posx >= 0x10000L) { - while (posx >= 0x10000L) { - ++srcx; - posx -= 0x10000L; - } - src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4)); - } - pixel = *src; - A = (Uint8)(pixel >> 24); R = (Uint8)(pixel >> 16); G = (Uint8)(pixel >> 8); B = (Uint8)pixel; - if (flags & SDL_COPY_MODULATE_COLOR) { - R = (R * modulateR) / 255; - G = (G * modulateG) / 255; - B = (B * modulateB) / 255; - } - if (flags & SDL_COPY_MODULATE_ALPHA) { - A = (A * modulateA) / 255; - } - pixel = ((Uint32)R << 16) | ((Uint32)G << 8) | B; - *dst = pixel; - posx += incx; - ++dst; - } - posy += incy; - info->dst += info->dst_pitch; - } -} - -static void SDL_Blit_ARGB8888_RGB888_Modulate_Blend(SDL_BlitInfo *info) -{ - const int flags = info->flags; - const Uint32 modulateR = info->r; - const Uint32 modulateG = info->g; - const Uint32 modulateB = info->b; - const Uint32 modulateA = info->a; - Uint32 srcpixel; - Uint32 srcR, srcG, srcB, srcA; - Uint32 dstpixel; - Uint32 dstR, dstG, dstB, dstA; - - while (info->dst_h--) { - Uint32 *src = (Uint32 *)info->src; - Uint32 *dst = (Uint32 *)info->dst; - int n = info->dst_w; - while (n--) { - srcpixel = *src; - srcA = (Uint8)(srcpixel >> 24); srcR = (Uint8)(srcpixel >> 16); srcG = (Uint8)(srcpixel >> 8); srcB = (Uint8)srcpixel; - dstpixel = *dst; - dstR = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstB = (Uint8)dstpixel; dstA = 0xFF; - if (flags & SDL_COPY_MODULATE_COLOR) { - srcR = (srcR * modulateR) / 255; - srcG = (srcG * modulateG) / 255; - srcB = (srcB * modulateB) / 255; - } - if (flags & SDL_COPY_MODULATE_ALPHA) { - srcA = (srcA * modulateA) / 255; - } - if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) { - /* This goes away if we ever use premultiplied alpha */ - if (srcA < 255) { - srcR = (srcR * srcA) / 255; - srcG = (srcG * srcA) / 255; - srcB = (srcB * srcA) / 255; - } - } - switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) { - case SDL_COPY_BLEND: - dstR = srcR + ((255 - srcA) * dstR) / 255; - dstG = srcG + ((255 - srcA) * dstG) / 255; - dstB = srcB + ((255 - srcA) * dstB) / 255; - break; - case SDL_COPY_ADD: - dstR = srcR + dstR; if (dstR > 255) dstR = 255; - dstG = srcG + dstG; if (dstG > 255) dstG = 255; - dstB = srcB + dstB; if (dstB > 255) dstB = 255; - break; - case SDL_COPY_MOD: - dstR = (srcR * dstR) / 255; - dstG = (srcG * dstG) / 255; - dstB = (srcB * dstB) / 255; - break; - } - dstpixel = ((Uint32)dstR << 16) | ((Uint32)dstG << 8) | dstB; - *dst = dstpixel; - ++src; - ++dst; - } - info->src += info->src_pitch; - info->dst += info->dst_pitch; - } -} - -static void SDL_Blit_ARGB8888_RGB888_Modulate_Blend_Scale(SDL_BlitInfo *info) -{ - const int flags = info->flags; - const Uint32 modulateR = info->r; - const Uint32 modulateG = info->g; - const Uint32 modulateB = info->b; - const Uint32 modulateA = info->a; - Uint32 srcpixel; - Uint32 srcR, srcG, srcB, srcA; - Uint32 dstpixel; - Uint32 dstR, dstG, dstB, dstA; - int srcy, srcx; - int posy, posx; - int incy, incx; - - srcy = 0; - posy = 0; - incy = (info->src_h << 16) / info->dst_h; - incx = (info->src_w << 16) / info->dst_w; - - while (info->dst_h--) { - Uint32 *src = 0; - Uint32 *dst = (Uint32 *)info->dst; - int n = info->dst_w; - srcx = -1; - posx = 0x10000L; - while (posy >= 0x10000L) { - ++srcy; - posy -= 0x10000L; - } - while (n--) { - if (posx >= 0x10000L) { - while (posx >= 0x10000L) { - ++srcx; - posx -= 0x10000L; - } - src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4)); - } - srcpixel = *src; - srcA = (Uint8)(srcpixel >> 24); srcR = (Uint8)(srcpixel >> 16); srcG = (Uint8)(srcpixel >> 8); srcB = (Uint8)srcpixel; - dstpixel = *dst; - dstR = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstB = (Uint8)dstpixel; dstA = 0xFF; - if (flags & SDL_COPY_MODULATE_COLOR) { - srcR = (srcR * modulateR) / 255; - srcG = (srcG * modulateG) / 255; - srcB = (srcB * modulateB) / 255; - } - if (flags & SDL_COPY_MODULATE_ALPHA) { - srcA = (srcA * modulateA) / 255; - } - if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) { - /* This goes away if we ever use premultiplied alpha */ - if (srcA < 255) { - srcR = (srcR * srcA) / 255; - srcG = (srcG * srcA) / 255; - srcB = (srcB * srcA) / 255; - } - } - switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) { - case SDL_COPY_BLEND: - dstR = srcR + ((255 - srcA) * dstR) / 255; - dstG = srcG + ((255 - srcA) * dstG) / 255; - dstB = srcB + ((255 - srcA) * dstB) / 255; - break; - case SDL_COPY_ADD: - dstR = srcR + dstR; if (dstR > 255) dstR = 255; - dstG = srcG + dstG; if (dstG > 255) dstG = 255; - dstB = srcB + dstB; if (dstB > 255) dstB = 255; - break; - case SDL_COPY_MOD: - dstR = (srcR * dstR) / 255; - dstG = (srcG * dstG) / 255; - dstB = (srcB * dstB) / 255; - break; - } - dstpixel = ((Uint32)dstR << 16) | ((Uint32)dstG << 8) | dstB; - *dst = dstpixel; - posx += incx; - ++dst; - } - posy += incy; - info->dst += info->dst_pitch; - } -} - -static void SDL_Blit_ARGB8888_BGR888_Scale(SDL_BlitInfo *info) -{ - Uint32 pixel; - Uint32 R, G, B, A; - int srcy, srcx; - int posy, posx; - int incy, incx; - - srcy = 0; - posy = 0; - incy = (info->src_h << 16) / info->dst_h; - incx = (info->src_w << 16) / info->dst_w; - - while (info->dst_h--) { - Uint32 *src = 0; - Uint32 *dst = (Uint32 *)info->dst; - int n = info->dst_w; - srcx = -1; - posx = 0x10000L; - while (posy >= 0x10000L) { - ++srcy; - posy -= 0x10000L; - } - while (n--) { - if (posx >= 0x10000L) { - while (posx >= 0x10000L) { - ++srcx; - posx -= 0x10000L; - } - src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4)); - } - pixel = *src; - A = (Uint8)(pixel >> 24); R = (Uint8)(pixel >> 16); G = (Uint8)(pixel >> 8); B = (Uint8)pixel; - pixel = ((Uint32)B << 16) | ((Uint32)G << 8) | R; - *dst = pixel; - posx += incx; - ++dst; - } - posy += incy; - info->dst += info->dst_pitch; - } -} - -static void SDL_Blit_ARGB8888_BGR888_Blend(SDL_BlitInfo *info) -{ - const int flags = info->flags; - Uint32 srcpixel; - Uint32 srcR, srcG, srcB, srcA; - Uint32 dstpixel; - Uint32 dstR, dstG, dstB, dstA; - - while (info->dst_h--) { - Uint32 *src = (Uint32 *)info->src; - Uint32 *dst = (Uint32 *)info->dst; - int n = info->dst_w; - while (n--) { - srcpixel = *src; - srcA = (Uint8)(srcpixel >> 24); srcR = (Uint8)(srcpixel >> 16); srcG = (Uint8)(srcpixel >> 8); srcB = (Uint8)srcpixel; - dstpixel = *dst; - dstB = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstR = (Uint8)dstpixel; dstA = 0xFF; - if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) { - /* This goes away if we ever use premultiplied alpha */ - if (srcA < 255) { - srcR = (srcR * srcA) / 255; - srcG = (srcG * srcA) / 255; - srcB = (srcB * srcA) / 255; - } - } - switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) { - case SDL_COPY_BLEND: - dstR = srcR + ((255 - srcA) * dstR) / 255; - dstG = srcG + ((255 - srcA) * dstG) / 255; - dstB = srcB + ((255 - srcA) * dstB) / 255; - break; - case SDL_COPY_ADD: - dstR = srcR + dstR; if (dstR > 255) dstR = 255; - dstG = srcG + dstG; if (dstG > 255) dstG = 255; - dstB = srcB + dstB; if (dstB > 255) dstB = 255; - break; - case SDL_COPY_MOD: - dstR = (srcR * dstR) / 255; - dstG = (srcG * dstG) / 255; - dstB = (srcB * dstB) / 255; - break; - } - dstpixel = ((Uint32)dstB << 16) | ((Uint32)dstG << 8) | dstR; - *dst = dstpixel; - ++src; - ++dst; - } - info->src += info->src_pitch; - info->dst += info->dst_pitch; - } -} - -static void SDL_Blit_ARGB8888_BGR888_Blend_Scale(SDL_BlitInfo *info) -{ - const int flags = info->flags; - Uint32 srcpixel; - Uint32 srcR, srcG, srcB, srcA; - Uint32 dstpixel; - Uint32 dstR, dstG, dstB, dstA; - int srcy, srcx; - int posy, posx; - int incy, incx; - - srcy = 0; - posy = 0; - incy = (info->src_h << 16) / info->dst_h; - incx = (info->src_w << 16) / info->dst_w; - - while (info->dst_h--) { - Uint32 *src = 0; - Uint32 *dst = (Uint32 *)info->dst; - int n = info->dst_w; - srcx = -1; - posx = 0x10000L; - while (posy >= 0x10000L) { - ++srcy; - posy -= 0x10000L; - } - while (n--) { - if (posx >= 0x10000L) { - while (posx >= 0x10000L) { - ++srcx; - posx -= 0x10000L; - } - src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4)); - } - srcpixel = *src; - srcA = (Uint8)(srcpixel >> 24); srcR = (Uint8)(srcpixel >> 16); srcG = (Uint8)(srcpixel >> 8); srcB = (Uint8)srcpixel; - dstpixel = *dst; - dstB = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstR = (Uint8)dstpixel; dstA = 0xFF; - if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) { - /* This goes away if we ever use premultiplied alpha */ - if (srcA < 255) { - srcR = (srcR * srcA) / 255; - srcG = (srcG * srcA) / 255; - srcB = (srcB * srcA) / 255; - } - } - switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) { - case SDL_COPY_BLEND: - dstR = srcR + ((255 - srcA) * dstR) / 255; - dstG = srcG + ((255 - srcA) * dstG) / 255; - dstB = srcB + ((255 - srcA) * dstB) / 255; - break; - case SDL_COPY_ADD: - dstR = srcR + dstR; if (dstR > 255) dstR = 255; - dstG = srcG + dstG; if (dstG > 255) dstG = 255; - dstB = srcB + dstB; if (dstB > 255) dstB = 255; - break; - case SDL_COPY_MOD: - dstR = (srcR * dstR) / 255; - dstG = (srcG * dstG) / 255; - dstB = (srcB * dstB) / 255; - break; - } - dstpixel = ((Uint32)dstB << 16) | ((Uint32)dstG << 8) | dstR; - *dst = dstpixel; - posx += incx; - ++dst; - } - posy += incy; - info->dst += info->dst_pitch; - } -} - -static void SDL_Blit_ARGB8888_BGR888_Modulate(SDL_BlitInfo *info) -{ - const int flags = info->flags; - const Uint32 modulateR = info->r; - const Uint32 modulateG = info->g; - const Uint32 modulateB = info->b; - const Uint32 modulateA = info->a; - Uint32 pixel; - Uint32 R, G, B, A; - - while (info->dst_h--) { - Uint32 *src = (Uint32 *)info->src; - Uint32 *dst = (Uint32 *)info->dst; - int n = info->dst_w; - while (n--) { - pixel = *src; - A = (Uint8)(pixel >> 24); R = (Uint8)(pixel >> 16); G = (Uint8)(pixel >> 8); B = (Uint8)pixel; - if (flags & SDL_COPY_MODULATE_COLOR) { - R = (R * modulateR) / 255; - G = (G * modulateG) / 255; - B = (B * modulateB) / 255; - } - if (flags & SDL_COPY_MODULATE_ALPHA) { - A = (A * modulateA) / 255; - } - pixel = ((Uint32)B << 16) | ((Uint32)G << 8) | R; - *dst = pixel; - ++src; - ++dst; - } - info->src += info->src_pitch; - info->dst += info->dst_pitch; - } -} - -static void SDL_Blit_ARGB8888_BGR888_Modulate_Scale(SDL_BlitInfo *info) -{ - const int flags = info->flags; - const Uint32 modulateR = info->r; - const Uint32 modulateG = info->g; - const Uint32 modulateB = info->b; - const Uint32 modulateA = info->a; - Uint32 pixel; - Uint32 R, G, B, A; - int srcy, srcx; - int posy, posx; - int incy, incx; - - srcy = 0; - posy = 0; - incy = (info->src_h << 16) / info->dst_h; - incx = (info->src_w << 16) / info->dst_w; - - while (info->dst_h--) { - Uint32 *src = 0; - Uint32 *dst = (Uint32 *)info->dst; - int n = info->dst_w; - srcx = -1; - posx = 0x10000L; - while (posy >= 0x10000L) { - ++srcy; - posy -= 0x10000L; - } - while (n--) { - if (posx >= 0x10000L) { - while (posx >= 0x10000L) { - ++srcx; - posx -= 0x10000L; - } - src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4)); - } - pixel = *src; - A = (Uint8)(pixel >> 24); R = (Uint8)(pixel >> 16); G = (Uint8)(pixel >> 8); B = (Uint8)pixel; - if (flags & SDL_COPY_MODULATE_COLOR) { - R = (R * modulateR) / 255; - G = (G * modulateG) / 255; - B = (B * modulateB) / 255; - } - if (flags & SDL_COPY_MODULATE_ALPHA) { - A = (A * modulateA) / 255; - } - pixel = ((Uint32)B << 16) | ((Uint32)G << 8) | R; - *dst = pixel; - posx += incx; - ++dst; - } - posy += incy; - info->dst += info->dst_pitch; - } -} - -static void SDL_Blit_ARGB8888_BGR888_Modulate_Blend(SDL_BlitInfo *info) -{ - const int flags = info->flags; - const Uint32 modulateR = info->r; - const Uint32 modulateG = info->g; - const Uint32 modulateB = info->b; - const Uint32 modulateA = info->a; - Uint32 srcpixel; - Uint32 srcR, srcG, srcB, srcA; - Uint32 dstpixel; - Uint32 dstR, dstG, dstB, dstA; - - while (info->dst_h--) { - Uint32 *src = (Uint32 *)info->src; - Uint32 *dst = (Uint32 *)info->dst; - int n = info->dst_w; - while (n--) { - srcpixel = *src; - srcA = (Uint8)(srcpixel >> 24); srcR = (Uint8)(srcpixel >> 16); srcG = (Uint8)(srcpixel >> 8); srcB = (Uint8)srcpixel; - dstpixel = *dst; - dstB = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstR = (Uint8)dstpixel; dstA = 0xFF; - if (flags & SDL_COPY_MODULATE_COLOR) { - srcR = (srcR * modulateR) / 255; - srcG = (srcG * modulateG) / 255; - srcB = (srcB * modulateB) / 255; - } - if (flags & SDL_COPY_MODULATE_ALPHA) { - srcA = (srcA * modulateA) / 255; - } - if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) { - /* This goes away if we ever use premultiplied alpha */ - if (srcA < 255) { - srcR = (srcR * srcA) / 255; - srcG = (srcG * srcA) / 255; - srcB = (srcB * srcA) / 255; - } - } - switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) { - case SDL_COPY_BLEND: - dstR = srcR + ((255 - srcA) * dstR) / 255; - dstG = srcG + ((255 - srcA) * dstG) / 255; - dstB = srcB + ((255 - srcA) * dstB) / 255; - break; - case SDL_COPY_ADD: - dstR = srcR + dstR; if (dstR > 255) dstR = 255; - dstG = srcG + dstG; if (dstG > 255) dstG = 255; - dstB = srcB + dstB; if (dstB > 255) dstB = 255; - break; - case SDL_COPY_MOD: - dstR = (srcR * dstR) / 255; - dstG = (srcG * dstG) / 255; - dstB = (srcB * dstB) / 255; - break; - } - dstpixel = ((Uint32)dstB << 16) | ((Uint32)dstG << 8) | dstR; - *dst = dstpixel; - ++src; - ++dst; - } - info->src += info->src_pitch; - info->dst += info->dst_pitch; - } -} - -static void SDL_Blit_ARGB8888_BGR888_Modulate_Blend_Scale(SDL_BlitInfo *info) -{ - const int flags = info->flags; - const Uint32 modulateR = info->r; - const Uint32 modulateG = info->g; - const Uint32 modulateB = info->b; - const Uint32 modulateA = info->a; - Uint32 srcpixel; - Uint32 srcR, srcG, srcB, srcA; - Uint32 dstpixel; - Uint32 dstR, dstG, dstB, dstA; - int srcy, srcx; - int posy, posx; - int incy, incx; - - srcy = 0; - posy = 0; - incy = (info->src_h << 16) / info->dst_h; - incx = (info->src_w << 16) / info->dst_w; - - while (info->dst_h--) { - Uint32 *src = 0; - Uint32 *dst = (Uint32 *)info->dst; - int n = info->dst_w; - srcx = -1; - posx = 0x10000L; - while (posy >= 0x10000L) { - ++srcy; - posy -= 0x10000L; - } - while (n--) { - if (posx >= 0x10000L) { - while (posx >= 0x10000L) { - ++srcx; - posx -= 0x10000L; - } - src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4)); - } - srcpixel = *src; - srcA = (Uint8)(srcpixel >> 24); srcR = (Uint8)(srcpixel >> 16); srcG = (Uint8)(srcpixel >> 8); srcB = (Uint8)srcpixel; - dstpixel = *dst; - dstB = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstR = (Uint8)dstpixel; dstA = 0xFF; - if (flags & SDL_COPY_MODULATE_COLOR) { - srcR = (srcR * modulateR) / 255; - srcG = (srcG * modulateG) / 255; - srcB = (srcB * modulateB) / 255; - } - if (flags & SDL_COPY_MODULATE_ALPHA) { - srcA = (srcA * modulateA) / 255; - } - if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) { - /* This goes away if we ever use premultiplied alpha */ - if (srcA < 255) { - srcR = (srcR * srcA) / 255; - srcG = (srcG * srcA) / 255; - srcB = (srcB * srcA) / 255; - } - } - switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) { - case SDL_COPY_BLEND: - dstR = srcR + ((255 - srcA) * dstR) / 255; - dstG = srcG + ((255 - srcA) * dstG) / 255; - dstB = srcB + ((255 - srcA) * dstB) / 255; - break; - case SDL_COPY_ADD: - dstR = srcR + dstR; if (dstR > 255) dstR = 255; - dstG = srcG + dstG; if (dstG > 255) dstG = 255; - dstB = srcB + dstB; if (dstB > 255) dstB = 255; - break; - case SDL_COPY_MOD: - dstR = (srcR * dstR) / 255; - dstG = (srcG * dstG) / 255; - dstB = (srcB * dstB) / 255; - break; - } - dstpixel = ((Uint32)dstB << 16) | ((Uint32)dstG << 8) | dstR; - *dst = dstpixel; - posx += incx; - ++dst; - } - posy += incy; - info->dst += info->dst_pitch; - } -} - -static void SDL_Blit_ARGB8888_ARGB8888_Scale(SDL_BlitInfo *info) -{ - int srcy, srcx; - int posy, posx; - int incy, incx; - - srcy = 0; - posy = 0; - incy = (info->src_h << 16) / info->dst_h; - incx = (info->src_w << 16) / info->dst_w; - - while (info->dst_h--) { - Uint32 *src = 0; - Uint32 *dst = (Uint32 *)info->dst; - int n = info->dst_w; - srcx = -1; - posx = 0x10000L; - while (posy >= 0x10000L) { - ++srcy; - posy -= 0x10000L; - } - while (n--) { - if (posx >= 0x10000L) { - while (posx >= 0x10000L) { - ++srcx; - posx -= 0x10000L; - } - src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4)); - } - *dst = *src; - posx += incx; - ++dst; - } - posy += incy; - info->dst += info->dst_pitch; - } -} - -static void SDL_Blit_ARGB8888_ARGB8888_Blend(SDL_BlitInfo *info) -{ - const int flags = info->flags; - Uint32 srcpixel; - Uint32 srcR, srcG, srcB, srcA; - Uint32 dstpixel; - Uint32 dstR, dstG, dstB, dstA; - - while (info->dst_h--) { - Uint32 *src = (Uint32 *)info->src; - Uint32 *dst = (Uint32 *)info->dst; - int n = info->dst_w; - while (n--) { - srcpixel = *src; - srcA = (Uint8)(srcpixel >> 24); srcR = (Uint8)(srcpixel >> 16); srcG = (Uint8)(srcpixel >> 8); srcB = (Uint8)srcpixel; - dstpixel = *dst; - dstA = (Uint8)(dstpixel >> 24); dstR = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstB = (Uint8)dstpixel; - if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) { - /* This goes away if we ever use premultiplied alpha */ - if (srcA < 255) { - srcR = (srcR * srcA) / 255; - srcG = (srcG * srcA) / 255; - srcB = (srcB * srcA) / 255; - } - } - switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) { - case SDL_COPY_BLEND: - dstR = srcR + ((255 - srcA) * dstR) / 255; - dstG = srcG + ((255 - srcA) * dstG) / 255; - dstB = srcB + ((255 - srcA) * dstB) / 255; - break; - case SDL_COPY_ADD: - dstR = srcR + dstR; if (dstR > 255) dstR = 255; - dstG = srcG + dstG; if (dstG > 255) dstG = 255; - dstB = srcB + dstB; if (dstB > 255) dstB = 255; - break; - case SDL_COPY_MOD: - dstR = (srcR * dstR) / 255; - dstG = (srcG * dstG) / 255; - dstB = (srcB * dstB) / 255; - break; - } - dstpixel = ((Uint32)dstA << 24) | ((Uint32)dstR << 16) | ((Uint32)dstG << 8) | dstB; - *dst = dstpixel; - ++src; - ++dst; - } - info->src += info->src_pitch; - info->dst += info->dst_pitch; - } -} - -static void SDL_Blit_ARGB8888_ARGB8888_Blend_Scale(SDL_BlitInfo *info) -{ - const int flags = info->flags; - Uint32 srcpixel; - Uint32 srcR, srcG, srcB, srcA; - Uint32 dstpixel; - Uint32 dstR, dstG, dstB, dstA; - int srcy, srcx; - int posy, posx; - int incy, incx; - - srcy = 0; - posy = 0; - incy = (info->src_h << 16) / info->dst_h; - incx = (info->src_w << 16) / info->dst_w; - - while (info->dst_h--) { - Uint32 *src = 0; - Uint32 *dst = (Uint32 *)info->dst; - int n = info->dst_w; - srcx = -1; - posx = 0x10000L; - while (posy >= 0x10000L) { - ++srcy; - posy -= 0x10000L; - } - while (n--) { - if (posx >= 0x10000L) { - while (posx >= 0x10000L) { - ++srcx; - posx -= 0x10000L; - } - src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4)); - } - srcpixel = *src; - srcA = (Uint8)(srcpixel >> 24); srcR = (Uint8)(srcpixel >> 16); srcG = (Uint8)(srcpixel >> 8); srcB = (Uint8)srcpixel; - dstpixel = *dst; - dstA = (Uint8)(dstpixel >> 24); dstR = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstB = (Uint8)dstpixel; - if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) { - /* This goes away if we ever use premultiplied alpha */ - if (srcA < 255) { - srcR = (srcR * srcA) / 255; - srcG = (srcG * srcA) / 255; - srcB = (srcB * srcA) / 255; - } - } - switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) { - case SDL_COPY_BLEND: - dstR = srcR + ((255 - srcA) * dstR) / 255; - dstG = srcG + ((255 - srcA) * dstG) / 255; - dstB = srcB + ((255 - srcA) * dstB) / 255; - break; - case SDL_COPY_ADD: - dstR = srcR + dstR; if (dstR > 255) dstR = 255; - dstG = srcG + dstG; if (dstG > 255) dstG = 255; - dstB = srcB + dstB; if (dstB > 255) dstB = 255; - break; - case SDL_COPY_MOD: - dstR = (srcR * dstR) / 255; - dstG = (srcG * dstG) / 255; - dstB = (srcB * dstB) / 255; - break; - } - dstpixel = ((Uint32)dstA << 24) | ((Uint32)dstR << 16) | ((Uint32)dstG << 8) | dstB; - *dst = dstpixel; - posx += incx; - ++dst; - } - posy += incy; - info->dst += info->dst_pitch; - } -} - -static void SDL_Blit_ARGB8888_ARGB8888_Modulate(SDL_BlitInfo *info) -{ - const int flags = info->flags; - const Uint32 modulateR = info->r; - const Uint32 modulateG = info->g; - const Uint32 modulateB = info->b; - const Uint32 modulateA = info->a; - Uint32 pixel; - Uint32 R, G, B, A; - - while (info->dst_h--) { - Uint32 *src = (Uint32 *)info->src; - Uint32 *dst = (Uint32 *)info->dst; - int n = info->dst_w; - while (n--) { - pixel = *src; - A = (Uint8)(pixel >> 24); R = (Uint8)(pixel >> 16); G = (Uint8)(pixel >> 8); B = (Uint8)pixel; - if (flags & SDL_COPY_MODULATE_COLOR) { - R = (R * modulateR) / 255; - G = (G * modulateG) / 255; - B = (B * modulateB) / 255; - } - if (flags & SDL_COPY_MODULATE_ALPHA) { - A = (A * modulateA) / 255; - } - pixel = ((Uint32)A << 24) | ((Uint32)R << 16) | ((Uint32)G << 8) | B; - *dst = pixel; - ++src; - ++dst; - } - info->src += info->src_pitch; - info->dst += info->dst_pitch; - } -} - -static void SDL_Blit_ARGB8888_ARGB8888_Modulate_Scale(SDL_BlitInfo *info) -{ - const int flags = info->flags; - const Uint32 modulateR = info->r; - const Uint32 modulateG = info->g; - const Uint32 modulateB = info->b; - const Uint32 modulateA = info->a; - Uint32 pixel; - Uint32 R, G, B, A; - int srcy, srcx; - int posy, posx; - int incy, incx; - - srcy = 0; - posy = 0; - incy = (info->src_h << 16) / info->dst_h; - incx = (info->src_w << 16) / info->dst_w; - - while (info->dst_h--) { - Uint32 *src = 0; - Uint32 *dst = (Uint32 *)info->dst; - int n = info->dst_w; - srcx = -1; - posx = 0x10000L; - while (posy >= 0x10000L) { - ++srcy; - posy -= 0x10000L; - } - while (n--) { - if (posx >= 0x10000L) { - while (posx >= 0x10000L) { - ++srcx; - posx -= 0x10000L; - } - src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4)); - } - pixel = *src; - A = (Uint8)(pixel >> 24); R = (Uint8)(pixel >> 16); G = (Uint8)(pixel >> 8); B = (Uint8)pixel; - if (flags & SDL_COPY_MODULATE_COLOR) { - R = (R * modulateR) / 255; - G = (G * modulateG) / 255; - B = (B * modulateB) / 255; - } - if (flags & SDL_COPY_MODULATE_ALPHA) { - A = (A * modulateA) / 255; - } - pixel = ((Uint32)A << 24) | ((Uint32)R << 16) | ((Uint32)G << 8) | B; - *dst = pixel; - posx += incx; - ++dst; - } - posy += incy; - info->dst += info->dst_pitch; - } -} - -static void SDL_Blit_ARGB8888_ARGB8888_Modulate_Blend(SDL_BlitInfo *info) -{ - const int flags = info->flags; - const Uint32 modulateR = info->r; - const Uint32 modulateG = info->g; - const Uint32 modulateB = info->b; - const Uint32 modulateA = info->a; - Uint32 srcpixel; - Uint32 srcR, srcG, srcB, srcA; - Uint32 dstpixel; - Uint32 dstR, dstG, dstB, dstA; - - while (info->dst_h--) { - Uint32 *src = (Uint32 *)info->src; - Uint32 *dst = (Uint32 *)info->dst; - int n = info->dst_w; - while (n--) { - srcpixel = *src; - srcA = (Uint8)(srcpixel >> 24); srcR = (Uint8)(srcpixel >> 16); srcG = (Uint8)(srcpixel >> 8); srcB = (Uint8)srcpixel; - dstpixel = *dst; - dstA = (Uint8)(dstpixel >> 24); dstR = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstB = (Uint8)dstpixel; - if (flags & SDL_COPY_MODULATE_COLOR) { - srcR = (srcR * modulateR) / 255; - srcG = (srcG * modulateG) / 255; - srcB = (srcB * modulateB) / 255; - } - if (flags & SDL_COPY_MODULATE_ALPHA) { - srcA = (srcA * modulateA) / 255; - } - if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) { - /* This goes away if we ever use premultiplied alpha */ - if (srcA < 255) { - srcR = (srcR * srcA) / 255; - srcG = (srcG * srcA) / 255; - srcB = (srcB * srcA) / 255; - } - } - switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) { - case SDL_COPY_BLEND: - dstR = srcR + ((255 - srcA) * dstR) / 255; - dstG = srcG + ((255 - srcA) * dstG) / 255; - dstB = srcB + ((255 - srcA) * dstB) / 255; - break; - case SDL_COPY_ADD: - dstR = srcR + dstR; if (dstR > 255) dstR = 255; - dstG = srcG + dstG; if (dstG > 255) dstG = 255; - dstB = srcB + dstB; if (dstB > 255) dstB = 255; - break; - case SDL_COPY_MOD: - dstR = (srcR * dstR) / 255; - dstG = (srcG * dstG) / 255; - dstB = (srcB * dstB) / 255; - break; - } - dstpixel = ((Uint32)dstA << 24) | ((Uint32)dstR << 16) | ((Uint32)dstG << 8) | dstB; - *dst = dstpixel; - ++src; - ++dst; - } - info->src += info->src_pitch; - info->dst += info->dst_pitch; - } -} - -static void SDL_Blit_ARGB8888_ARGB8888_Modulate_Blend_Scale(SDL_BlitInfo *info) -{ - const int flags = info->flags; - const Uint32 modulateR = info->r; - const Uint32 modulateG = info->g; - const Uint32 modulateB = info->b; - const Uint32 modulateA = info->a; - Uint32 srcpixel; - Uint32 srcR, srcG, srcB, srcA; - Uint32 dstpixel; - Uint32 dstR, dstG, dstB, dstA; - int srcy, srcx; - int posy, posx; - int incy, incx; - - srcy = 0; - posy = 0; - incy = (info->src_h << 16) / info->dst_h; - incx = (info->src_w << 16) / info->dst_w; - - while (info->dst_h--) { - Uint32 *src = 0; - Uint32 *dst = (Uint32 *)info->dst; - int n = info->dst_w; - srcx = -1; - posx = 0x10000L; - while (posy >= 0x10000L) { - ++srcy; - posy -= 0x10000L; - } - while (n--) { - if (posx >= 0x10000L) { - while (posx >= 0x10000L) { - ++srcx; - posx -= 0x10000L; - } - src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4)); - } - srcpixel = *src; - srcA = (Uint8)(srcpixel >> 24); srcR = (Uint8)(srcpixel >> 16); srcG = (Uint8)(srcpixel >> 8); srcB = (Uint8)srcpixel; - dstpixel = *dst; - dstA = (Uint8)(dstpixel >> 24); dstR = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstB = (Uint8)dstpixel; - if (flags & SDL_COPY_MODULATE_COLOR) { - srcR = (srcR * modulateR) / 255; - srcG = (srcG * modulateG) / 255; - srcB = (srcB * modulateB) / 255; - } - if (flags & SDL_COPY_MODULATE_ALPHA) { - srcA = (srcA * modulateA) / 255; - } - if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) { - /* This goes away if we ever use premultiplied alpha */ - if (srcA < 255) { - srcR = (srcR * srcA) / 255; - srcG = (srcG * srcA) / 255; - srcB = (srcB * srcA) / 255; - } - } - switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) { - case SDL_COPY_BLEND: - dstR = srcR + ((255 - srcA) * dstR) / 255; - dstG = srcG + ((255 - srcA) * dstG) / 255; - dstB = srcB + ((255 - srcA) * dstB) / 255; - break; - case SDL_COPY_ADD: - dstR = srcR + dstR; if (dstR > 255) dstR = 255; - dstG = srcG + dstG; if (dstG > 255) dstG = 255; - dstB = srcB + dstB; if (dstB > 255) dstB = 255; - break; - case SDL_COPY_MOD: - dstR = (srcR * dstR) / 255; - dstG = (srcG * dstG) / 255; - dstB = (srcB * dstB) / 255; - break; - } - dstpixel = ((Uint32)dstA << 24) | ((Uint32)dstR << 16) | ((Uint32)dstG << 8) | dstB; - *dst = dstpixel; - posx += incx; - ++dst; - } - posy += incy; - info->dst += info->dst_pitch; - } -} - -static void SDL_Blit_RGBA8888_RGB888_Scale(SDL_BlitInfo *info) -{ - Uint32 pixel; - Uint32 R, G, B, A; - int srcy, srcx; - int posy, posx; - int incy, incx; - - srcy = 0; - posy = 0; - incy = (info->src_h << 16) / info->dst_h; - incx = (info->src_w << 16) / info->dst_w; - - while (info->dst_h--) { - Uint32 *src = 0; - Uint32 *dst = (Uint32 *)info->dst; - int n = info->dst_w; - srcx = -1; - posx = 0x10000L; - while (posy >= 0x10000L) { - ++srcy; - posy -= 0x10000L; - } - while (n--) { - if (posx >= 0x10000L) { - while (posx >= 0x10000L) { - ++srcx; - posx -= 0x10000L; - } - src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4)); - } - pixel = *src; - R = (Uint8)(pixel >> 24); G = (Uint8)(pixel >> 16); B = (Uint8)(pixel >> 8); A = (Uint8)pixel; - pixel = ((Uint32)R << 16) | ((Uint32)G << 8) | B; - *dst = pixel; - posx += incx; - ++dst; - } - posy += incy; - info->dst += info->dst_pitch; - } -} - -static void SDL_Blit_RGBA8888_RGB888_Blend(SDL_BlitInfo *info) -{ - const int flags = info->flags; - Uint32 srcpixel; - Uint32 srcR, srcG, srcB, srcA; - Uint32 dstpixel; - Uint32 dstR, dstG, dstB, dstA; - - while (info->dst_h--) { - Uint32 *src = (Uint32 *)info->src; - Uint32 *dst = (Uint32 *)info->dst; - int n = info->dst_w; - while (n--) { - srcpixel = *src; - srcR = (Uint8)(srcpixel >> 24); srcG = (Uint8)(srcpixel >> 16); srcB = (Uint8)(srcpixel >> 8); srcA = (Uint8)srcpixel; - dstpixel = *dst; - dstR = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstB = (Uint8)dstpixel; dstA = 0xFF; - if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) { - /* This goes away if we ever use premultiplied alpha */ - if (srcA < 255) { - srcR = (srcR * srcA) / 255; - srcG = (srcG * srcA) / 255; - srcB = (srcB * srcA) / 255; - } - } - switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) { - case SDL_COPY_BLEND: - dstR = srcR + ((255 - srcA) * dstR) / 255; - dstG = srcG + ((255 - srcA) * dstG) / 255; - dstB = srcB + ((255 - srcA) * dstB) / 255; - break; - case SDL_COPY_ADD: - dstR = srcR + dstR; if (dstR > 255) dstR = 255; - dstG = srcG + dstG; if (dstG > 255) dstG = 255; - dstB = srcB + dstB; if (dstB > 255) dstB = 255; - break; - case SDL_COPY_MOD: - dstR = (srcR * dstR) / 255; - dstG = (srcG * dstG) / 255; - dstB = (srcB * dstB) / 255; - break; - } - dstpixel = ((Uint32)dstR << 16) | ((Uint32)dstG << 8) | dstB; - *dst = dstpixel; - ++src; - ++dst; - } - info->src += info->src_pitch; - info->dst += info->dst_pitch; - } -} - -static void SDL_Blit_RGBA8888_RGB888_Blend_Scale(SDL_BlitInfo *info) -{ - const int flags = info->flags; - Uint32 srcpixel; - Uint32 srcR, srcG, srcB, srcA; - Uint32 dstpixel; - Uint32 dstR, dstG, dstB, dstA; - int srcy, srcx; - int posy, posx; - int incy, incx; - - srcy = 0; - posy = 0; - incy = (info->src_h << 16) / info->dst_h; - incx = (info->src_w << 16) / info->dst_w; - - while (info->dst_h--) { - Uint32 *src = 0; - Uint32 *dst = (Uint32 *)info->dst; - int n = info->dst_w; - srcx = -1; - posx = 0x10000L; - while (posy >= 0x10000L) { - ++srcy; - posy -= 0x10000L; - } - while (n--) { - if (posx >= 0x10000L) { - while (posx >= 0x10000L) { - ++srcx; - posx -= 0x10000L; - } - src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4)); - } - srcpixel = *src; - srcR = (Uint8)(srcpixel >> 24); srcG = (Uint8)(srcpixel >> 16); srcB = (Uint8)(srcpixel >> 8); srcA = (Uint8)srcpixel; - dstpixel = *dst; - dstR = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstB = (Uint8)dstpixel; dstA = 0xFF; - if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) { - /* This goes away if we ever use premultiplied alpha */ - if (srcA < 255) { - srcR = (srcR * srcA) / 255; - srcG = (srcG * srcA) / 255; - srcB = (srcB * srcA) / 255; - } - } - switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) { - case SDL_COPY_BLEND: - dstR = srcR + ((255 - srcA) * dstR) / 255; - dstG = srcG + ((255 - srcA) * dstG) / 255; - dstB = srcB + ((255 - srcA) * dstB) / 255; - break; - case SDL_COPY_ADD: - dstR = srcR + dstR; if (dstR > 255) dstR = 255; - dstG = srcG + dstG; if (dstG > 255) dstG = 255; - dstB = srcB + dstB; if (dstB > 255) dstB = 255; - break; - case SDL_COPY_MOD: - dstR = (srcR * dstR) / 255; - dstG = (srcG * dstG) / 255; - dstB = (srcB * dstB) / 255; - break; - } - dstpixel = ((Uint32)dstR << 16) | ((Uint32)dstG << 8) | dstB; - *dst = dstpixel; - posx += incx; - ++dst; - } - posy += incy; - info->dst += info->dst_pitch; - } -} - -static void SDL_Blit_RGBA8888_RGB888_Modulate(SDL_BlitInfo *info) -{ - const int flags = info->flags; - const Uint32 modulateR = info->r; - const Uint32 modulateG = info->g; - const Uint32 modulateB = info->b; - const Uint32 modulateA = info->a; - Uint32 pixel; - Uint32 R, G, B, A; - - while (info->dst_h--) { - Uint32 *src = (Uint32 *)info->src; - Uint32 *dst = (Uint32 *)info->dst; - int n = info->dst_w; - while (n--) { - pixel = *src; - R = (Uint8)(pixel >> 24); G = (Uint8)(pixel >> 16); B = (Uint8)(pixel >> 8); A = (Uint8)pixel; - if (flags & SDL_COPY_MODULATE_COLOR) { - R = (R * modulateR) / 255; - G = (G * modulateG) / 255; - B = (B * modulateB) / 255; - } - if (flags & SDL_COPY_MODULATE_ALPHA) { - A = (A * modulateA) / 255; - } - pixel = ((Uint32)R << 16) | ((Uint32)G << 8) | B; - *dst = pixel; - ++src; - ++dst; - } - info->src += info->src_pitch; - info->dst += info->dst_pitch; - } -} - -static void SDL_Blit_RGBA8888_RGB888_Modulate_Scale(SDL_BlitInfo *info) -{ - const int flags = info->flags; - const Uint32 modulateR = info->r; - const Uint32 modulateG = info->g; - const Uint32 modulateB = info->b; - const Uint32 modulateA = info->a; - Uint32 pixel; - Uint32 R, G, B, A; - int srcy, srcx; - int posy, posx; - int incy, incx; - - srcy = 0; - posy = 0; - incy = (info->src_h << 16) / info->dst_h; - incx = (info->src_w << 16) / info->dst_w; - - while (info->dst_h--) { - Uint32 *src = 0; - Uint32 *dst = (Uint32 *)info->dst; - int n = info->dst_w; - srcx = -1; - posx = 0x10000L; - while (posy >= 0x10000L) { - ++srcy; - posy -= 0x10000L; - } - while (n--) { - if (posx >= 0x10000L) { - while (posx >= 0x10000L) { - ++srcx; - posx -= 0x10000L; - } - src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4)); - } - pixel = *src; - R = (Uint8)(pixel >> 24); G = (Uint8)(pixel >> 16); B = (Uint8)(pixel >> 8); A = (Uint8)pixel; - if (flags & SDL_COPY_MODULATE_COLOR) { - R = (R * modulateR) / 255; - G = (G * modulateG) / 255; - B = (B * modulateB) / 255; - } - if (flags & SDL_COPY_MODULATE_ALPHA) { - A = (A * modulateA) / 255; - } - pixel = ((Uint32)R << 16) | ((Uint32)G << 8) | B; - *dst = pixel; - posx += incx; - ++dst; - } - posy += incy; - info->dst += info->dst_pitch; - } -} - -static void SDL_Blit_RGBA8888_RGB888_Modulate_Blend(SDL_BlitInfo *info) -{ - const int flags = info->flags; - const Uint32 modulateR = info->r; - const Uint32 modulateG = info->g; - const Uint32 modulateB = info->b; - const Uint32 modulateA = info->a; - Uint32 srcpixel; - Uint32 srcR, srcG, srcB, srcA; - Uint32 dstpixel; - Uint32 dstR, dstG, dstB, dstA; - - while (info->dst_h--) { - Uint32 *src = (Uint32 *)info->src; - Uint32 *dst = (Uint32 *)info->dst; - int n = info->dst_w; - while (n--) { - srcpixel = *src; - srcR = (Uint8)(srcpixel >> 24); srcG = (Uint8)(srcpixel >> 16); srcB = (Uint8)(srcpixel >> 8); srcA = (Uint8)srcpixel; - dstpixel = *dst; - dstR = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstB = (Uint8)dstpixel; dstA = 0xFF; - if (flags & SDL_COPY_MODULATE_COLOR) { - srcR = (srcR * modulateR) / 255; - srcG = (srcG * modulateG) / 255; - srcB = (srcB * modulateB) / 255; - } - if (flags & SDL_COPY_MODULATE_ALPHA) { - srcA = (srcA * modulateA) / 255; - } - if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) { - /* This goes away if we ever use premultiplied alpha */ - if (srcA < 255) { - srcR = (srcR * srcA) / 255; - srcG = (srcG * srcA) / 255; - srcB = (srcB * srcA) / 255; - } - } - switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) { - case SDL_COPY_BLEND: - dstR = srcR + ((255 - srcA) * dstR) / 255; - dstG = srcG + ((255 - srcA) * dstG) / 255; - dstB = srcB + ((255 - srcA) * dstB) / 255; - break; - case SDL_COPY_ADD: - dstR = srcR + dstR; if (dstR > 255) dstR = 255; - dstG = srcG + dstG; if (dstG > 255) dstG = 255; - dstB = srcB + dstB; if (dstB > 255) dstB = 255; - break; - case SDL_COPY_MOD: - dstR = (srcR * dstR) / 255; - dstG = (srcG * dstG) / 255; - dstB = (srcB * dstB) / 255; - break; - } - dstpixel = ((Uint32)dstR << 16) | ((Uint32)dstG << 8) | dstB; - *dst = dstpixel; - ++src; - ++dst; - } - info->src += info->src_pitch; - info->dst += info->dst_pitch; - } -} - -static void SDL_Blit_RGBA8888_RGB888_Modulate_Blend_Scale(SDL_BlitInfo *info) -{ - const int flags = info->flags; - const Uint32 modulateR = info->r; - const Uint32 modulateG = info->g; - const Uint32 modulateB = info->b; - const Uint32 modulateA = info->a; - Uint32 srcpixel; - Uint32 srcR, srcG, srcB, srcA; - Uint32 dstpixel; - Uint32 dstR, dstG, dstB, dstA; - int srcy, srcx; - int posy, posx; - int incy, incx; - - srcy = 0; - posy = 0; - incy = (info->src_h << 16) / info->dst_h; - incx = (info->src_w << 16) / info->dst_w; - - while (info->dst_h--) { - Uint32 *src = 0; - Uint32 *dst = (Uint32 *)info->dst; - int n = info->dst_w; - srcx = -1; - posx = 0x10000L; - while (posy >= 0x10000L) { - ++srcy; - posy -= 0x10000L; - } - while (n--) { - if (posx >= 0x10000L) { - while (posx >= 0x10000L) { - ++srcx; - posx -= 0x10000L; - } - src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4)); - } - srcpixel = *src; - srcR = (Uint8)(srcpixel >> 24); srcG = (Uint8)(srcpixel >> 16); srcB = (Uint8)(srcpixel >> 8); srcA = (Uint8)srcpixel; - dstpixel = *dst; - dstR = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstB = (Uint8)dstpixel; dstA = 0xFF; - if (flags & SDL_COPY_MODULATE_COLOR) { - srcR = (srcR * modulateR) / 255; - srcG = (srcG * modulateG) / 255; - srcB = (srcB * modulateB) / 255; - } - if (flags & SDL_COPY_MODULATE_ALPHA) { - srcA = (srcA * modulateA) / 255; - } - if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) { - /* This goes away if we ever use premultiplied alpha */ - if (srcA < 255) { - srcR = (srcR * srcA) / 255; - srcG = (srcG * srcA) / 255; - srcB = (srcB * srcA) / 255; - } - } - switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) { - case SDL_COPY_BLEND: - dstR = srcR + ((255 - srcA) * dstR) / 255; - dstG = srcG + ((255 - srcA) * dstG) / 255; - dstB = srcB + ((255 - srcA) * dstB) / 255; - break; - case SDL_COPY_ADD: - dstR = srcR + dstR; if (dstR > 255) dstR = 255; - dstG = srcG + dstG; if (dstG > 255) dstG = 255; - dstB = srcB + dstB; if (dstB > 255) dstB = 255; - break; - case SDL_COPY_MOD: - dstR = (srcR * dstR) / 255; - dstG = (srcG * dstG) / 255; - dstB = (srcB * dstB) / 255; - break; - } - dstpixel = ((Uint32)dstR << 16) | ((Uint32)dstG << 8) | dstB; - *dst = dstpixel; - posx += incx; - ++dst; - } - posy += incy; - info->dst += info->dst_pitch; - } -} - -static void SDL_Blit_RGBA8888_BGR888_Scale(SDL_BlitInfo *info) -{ - Uint32 pixel; - Uint32 R, G, B, A; - int srcy, srcx; - int posy, posx; - int incy, incx; - - srcy = 0; - posy = 0; - incy = (info->src_h << 16) / info->dst_h; - incx = (info->src_w << 16) / info->dst_w; - - while (info->dst_h--) { - Uint32 *src = 0; - Uint32 *dst = (Uint32 *)info->dst; - int n = info->dst_w; - srcx = -1; - posx = 0x10000L; - while (posy >= 0x10000L) { - ++srcy; - posy -= 0x10000L; - } - while (n--) { - if (posx >= 0x10000L) { - while (posx >= 0x10000L) { - ++srcx; - posx -= 0x10000L; - } - src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4)); - } - pixel = *src; - R = (Uint8)(pixel >> 24); G = (Uint8)(pixel >> 16); B = (Uint8)(pixel >> 8); A = (Uint8)pixel; - pixel = ((Uint32)B << 16) | ((Uint32)G << 8) | R; - *dst = pixel; - posx += incx; - ++dst; - } - posy += incy; - info->dst += info->dst_pitch; - } -} - -static void SDL_Blit_RGBA8888_BGR888_Blend(SDL_BlitInfo *info) -{ - const int flags = info->flags; - Uint32 srcpixel; - Uint32 srcR, srcG, srcB, srcA; - Uint32 dstpixel; - Uint32 dstR, dstG, dstB, dstA; - - while (info->dst_h--) { - Uint32 *src = (Uint32 *)info->src; - Uint32 *dst = (Uint32 *)info->dst; - int n = info->dst_w; - while (n--) { - srcpixel = *src; - srcR = (Uint8)(srcpixel >> 24); srcG = (Uint8)(srcpixel >> 16); srcB = (Uint8)(srcpixel >> 8); srcA = (Uint8)srcpixel; - dstpixel = *dst; - dstB = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstR = (Uint8)dstpixel; dstA = 0xFF; - if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) { - /* This goes away if we ever use premultiplied alpha */ - if (srcA < 255) { - srcR = (srcR * srcA) / 255; - srcG = (srcG * srcA) / 255; - srcB = (srcB * srcA) / 255; - } - } - switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) { - case SDL_COPY_BLEND: - dstR = srcR + ((255 - srcA) * dstR) / 255; - dstG = srcG + ((255 - srcA) * dstG) / 255; - dstB = srcB + ((255 - srcA) * dstB) / 255; - break; - case SDL_COPY_ADD: - dstR = srcR + dstR; if (dstR > 255) dstR = 255; - dstG = srcG + dstG; if (dstG > 255) dstG = 255; - dstB = srcB + dstB; if (dstB > 255) dstB = 255; - break; - case SDL_COPY_MOD: - dstR = (srcR * dstR) / 255; - dstG = (srcG * dstG) / 255; - dstB = (srcB * dstB) / 255; - break; - } - dstpixel = ((Uint32)dstB << 16) | ((Uint32)dstG << 8) | dstR; - *dst = dstpixel; - ++src; - ++dst; - } - info->src += info->src_pitch; - info->dst += info->dst_pitch; - } -} - -static void SDL_Blit_RGBA8888_BGR888_Blend_Scale(SDL_BlitInfo *info) -{ - const int flags = info->flags; - Uint32 srcpixel; - Uint32 srcR, srcG, srcB, srcA; - Uint32 dstpixel; - Uint32 dstR, dstG, dstB, dstA; - int srcy, srcx; - int posy, posx; - int incy, incx; - - srcy = 0; - posy = 0; - incy = (info->src_h << 16) / info->dst_h; - incx = (info->src_w << 16) / info->dst_w; - - while (info->dst_h--) { - Uint32 *src = 0; - Uint32 *dst = (Uint32 *)info->dst; - int n = info->dst_w; - srcx = -1; - posx = 0x10000L; - while (posy >= 0x10000L) { - ++srcy; - posy -= 0x10000L; - } - while (n--) { - if (posx >= 0x10000L) { - while (posx >= 0x10000L) { - ++srcx; - posx -= 0x10000L; - } - src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4)); - } - srcpixel = *src; - srcR = (Uint8)(srcpixel >> 24); srcG = (Uint8)(srcpixel >> 16); srcB = (Uint8)(srcpixel >> 8); srcA = (Uint8)srcpixel; - dstpixel = *dst; - dstB = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstR = (Uint8)dstpixel; dstA = 0xFF; - if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) { - /* This goes away if we ever use premultiplied alpha */ - if (srcA < 255) { - srcR = (srcR * srcA) / 255; - srcG = (srcG * srcA) / 255; - srcB = (srcB * srcA) / 255; - } - } - switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) { - case SDL_COPY_BLEND: - dstR = srcR + ((255 - srcA) * dstR) / 255; - dstG = srcG + ((255 - srcA) * dstG) / 255; - dstB = srcB + ((255 - srcA) * dstB) / 255; - break; - case SDL_COPY_ADD: - dstR = srcR + dstR; if (dstR > 255) dstR = 255; - dstG = srcG + dstG; if (dstG > 255) dstG = 255; - dstB = srcB + dstB; if (dstB > 255) dstB = 255; - break; - case SDL_COPY_MOD: - dstR = (srcR * dstR) / 255; - dstG = (srcG * dstG) / 255; - dstB = (srcB * dstB) / 255; - break; - } - dstpixel = ((Uint32)dstB << 16) | ((Uint32)dstG << 8) | dstR; - *dst = dstpixel; - posx += incx; - ++dst; - } - posy += incy; - info->dst += info->dst_pitch; - } -} - -static void SDL_Blit_RGBA8888_BGR888_Modulate(SDL_BlitInfo *info) -{ - const int flags = info->flags; - const Uint32 modulateR = info->r; - const Uint32 modulateG = info->g; - const Uint32 modulateB = info->b; - const Uint32 modulateA = info->a; - Uint32 pixel; - Uint32 R, G, B, A; - - while (info->dst_h--) { - Uint32 *src = (Uint32 *)info->src; - Uint32 *dst = (Uint32 *)info->dst; - int n = info->dst_w; - while (n--) { - pixel = *src; - R = (Uint8)(pixel >> 24); G = (Uint8)(pixel >> 16); B = (Uint8)(pixel >> 8); A = (Uint8)pixel; - if (flags & SDL_COPY_MODULATE_COLOR) { - R = (R * modulateR) / 255; - G = (G * modulateG) / 255; - B = (B * modulateB) / 255; - } - if (flags & SDL_COPY_MODULATE_ALPHA) { - A = (A * modulateA) / 255; - } - pixel = ((Uint32)B << 16) | ((Uint32)G << 8) | R; - *dst = pixel; - ++src; - ++dst; - } - info->src += info->src_pitch; - info->dst += info->dst_pitch; - } -} - -static void SDL_Blit_RGBA8888_BGR888_Modulate_Scale(SDL_BlitInfo *info) -{ - const int flags = info->flags; - const Uint32 modulateR = info->r; - const Uint32 modulateG = info->g; - const Uint32 modulateB = info->b; - const Uint32 modulateA = info->a; - Uint32 pixel; - Uint32 R, G, B, A; - int srcy, srcx; - int posy, posx; - int incy, incx; - - srcy = 0; - posy = 0; - incy = (info->src_h << 16) / info->dst_h; - incx = (info->src_w << 16) / info->dst_w; - - while (info->dst_h--) { - Uint32 *src = 0; - Uint32 *dst = (Uint32 *)info->dst; - int n = info->dst_w; - srcx = -1; - posx = 0x10000L; - while (posy >= 0x10000L) { - ++srcy; - posy -= 0x10000L; - } - while (n--) { - if (posx >= 0x10000L) { - while (posx >= 0x10000L) { - ++srcx; - posx -= 0x10000L; - } - src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4)); - } - pixel = *src; - R = (Uint8)(pixel >> 24); G = (Uint8)(pixel >> 16); B = (Uint8)(pixel >> 8); A = (Uint8)pixel; - if (flags & SDL_COPY_MODULATE_COLOR) { - R = (R * modulateR) / 255; - G = (G * modulateG) / 255; - B = (B * modulateB) / 255; - } - if (flags & SDL_COPY_MODULATE_ALPHA) { - A = (A * modulateA) / 255; - } - pixel = ((Uint32)B << 16) | ((Uint32)G << 8) | R; - *dst = pixel; - posx += incx; - ++dst; - } - posy += incy; - info->dst += info->dst_pitch; - } -} - -static void SDL_Blit_RGBA8888_BGR888_Modulate_Blend(SDL_BlitInfo *info) -{ - const int flags = info->flags; - const Uint32 modulateR = info->r; - const Uint32 modulateG = info->g; - const Uint32 modulateB = info->b; - const Uint32 modulateA = info->a; - Uint32 srcpixel; - Uint32 srcR, srcG, srcB, srcA; - Uint32 dstpixel; - Uint32 dstR, dstG, dstB, dstA; - - while (info->dst_h--) { - Uint32 *src = (Uint32 *)info->src; - Uint32 *dst = (Uint32 *)info->dst; - int n = info->dst_w; - while (n--) { - srcpixel = *src; - srcR = (Uint8)(srcpixel >> 24); srcG = (Uint8)(srcpixel >> 16); srcB = (Uint8)(srcpixel >> 8); srcA = (Uint8)srcpixel; - dstpixel = *dst; - dstB = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstR = (Uint8)dstpixel; dstA = 0xFF; - if (flags & SDL_COPY_MODULATE_COLOR) { - srcR = (srcR * modulateR) / 255; - srcG = (srcG * modulateG) / 255; - srcB = (srcB * modulateB) / 255; - } - if (flags & SDL_COPY_MODULATE_ALPHA) { - srcA = (srcA * modulateA) / 255; - } - if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) { - /* This goes away if we ever use premultiplied alpha */ - if (srcA < 255) { - srcR = (srcR * srcA) / 255; - srcG = (srcG * srcA) / 255; - srcB = (srcB * srcA) / 255; - } - } - switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) { - case SDL_COPY_BLEND: - dstR = srcR + ((255 - srcA) * dstR) / 255; - dstG = srcG + ((255 - srcA) * dstG) / 255; - dstB = srcB + ((255 - srcA) * dstB) / 255; - break; - case SDL_COPY_ADD: - dstR = srcR + dstR; if (dstR > 255) dstR = 255; - dstG = srcG + dstG; if (dstG > 255) dstG = 255; - dstB = srcB + dstB; if (dstB > 255) dstB = 255; - break; - case SDL_COPY_MOD: - dstR = (srcR * dstR) / 255; - dstG = (srcG * dstG) / 255; - dstB = (srcB * dstB) / 255; - break; - } - dstpixel = ((Uint32)dstB << 16) | ((Uint32)dstG << 8) | dstR; - *dst = dstpixel; - ++src; - ++dst; - } - info->src += info->src_pitch; - info->dst += info->dst_pitch; - } -} - -static void SDL_Blit_RGBA8888_BGR888_Modulate_Blend_Scale(SDL_BlitInfo *info) -{ - const int flags = info->flags; - const Uint32 modulateR = info->r; - const Uint32 modulateG = info->g; - const Uint32 modulateB = info->b; - const Uint32 modulateA = info->a; - Uint32 srcpixel; - Uint32 srcR, srcG, srcB, srcA; - Uint32 dstpixel; - Uint32 dstR, dstG, dstB, dstA; - int srcy, srcx; - int posy, posx; - int incy, incx; - - srcy = 0; - posy = 0; - incy = (info->src_h << 16) / info->dst_h; - incx = (info->src_w << 16) / info->dst_w; - - while (info->dst_h--) { - Uint32 *src = 0; - Uint32 *dst = (Uint32 *)info->dst; - int n = info->dst_w; - srcx = -1; - posx = 0x10000L; - while (posy >= 0x10000L) { - ++srcy; - posy -= 0x10000L; - } - while (n--) { - if (posx >= 0x10000L) { - while (posx >= 0x10000L) { - ++srcx; - posx -= 0x10000L; - } - src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4)); - } - srcpixel = *src; - srcR = (Uint8)(srcpixel >> 24); srcG = (Uint8)(srcpixel >> 16); srcB = (Uint8)(srcpixel >> 8); srcA = (Uint8)srcpixel; - dstpixel = *dst; - dstB = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstR = (Uint8)dstpixel; dstA = 0xFF; - if (flags & SDL_COPY_MODULATE_COLOR) { - srcR = (srcR * modulateR) / 255; - srcG = (srcG * modulateG) / 255; - srcB = (srcB * modulateB) / 255; - } - if (flags & SDL_COPY_MODULATE_ALPHA) { - srcA = (srcA * modulateA) / 255; - } - if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) { - /* This goes away if we ever use premultiplied alpha */ - if (srcA < 255) { - srcR = (srcR * srcA) / 255; - srcG = (srcG * srcA) / 255; - srcB = (srcB * srcA) / 255; - } - } - switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) { - case SDL_COPY_BLEND: - dstR = srcR + ((255 - srcA) * dstR) / 255; - dstG = srcG + ((255 - srcA) * dstG) / 255; - dstB = srcB + ((255 - srcA) * dstB) / 255; - break; - case SDL_COPY_ADD: - dstR = srcR + dstR; if (dstR > 255) dstR = 255; - dstG = srcG + dstG; if (dstG > 255) dstG = 255; - dstB = srcB + dstB; if (dstB > 255) dstB = 255; - break; - case SDL_COPY_MOD: - dstR = (srcR * dstR) / 255; - dstG = (srcG * dstG) / 255; - dstB = (srcB * dstB) / 255; - break; - } - dstpixel = ((Uint32)dstB << 16) | ((Uint32)dstG << 8) | dstR; - *dst = dstpixel; - posx += incx; - ++dst; - } - posy += incy; - info->dst += info->dst_pitch; - } -} - -static void SDL_Blit_RGBA8888_ARGB8888_Scale(SDL_BlitInfo *info) -{ - Uint32 pixel; - Uint32 R, G, B, A; - int srcy, srcx; - int posy, posx; - int incy, incx; - - srcy = 0; - posy = 0; - incy = (info->src_h << 16) / info->dst_h; - incx = (info->src_w << 16) / info->dst_w; - - while (info->dst_h--) { - Uint32 *src = 0; - Uint32 *dst = (Uint32 *)info->dst; - int n = info->dst_w; - srcx = -1; - posx = 0x10000L; - while (posy >= 0x10000L) { - ++srcy; - posy -= 0x10000L; - } - while (n--) { - if (posx >= 0x10000L) { - while (posx >= 0x10000L) { - ++srcx; - posx -= 0x10000L; - } - src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4)); - } - pixel = *src; - R = (Uint8)(pixel >> 24); G = (Uint8)(pixel >> 16); B = (Uint8)(pixel >> 8); A = (Uint8)pixel; - pixel = ((Uint32)A << 24) | ((Uint32)R << 16) | ((Uint32)G << 8) | B; - *dst = pixel; - posx += incx; - ++dst; - } - posy += incy; - info->dst += info->dst_pitch; - } -} - -static void SDL_Blit_RGBA8888_ARGB8888_Blend(SDL_BlitInfo *info) -{ - const int flags = info->flags; - Uint32 srcpixel; - Uint32 srcR, srcG, srcB, srcA; - Uint32 dstpixel; - Uint32 dstR, dstG, dstB, dstA; - - while (info->dst_h--) { - Uint32 *src = (Uint32 *)info->src; - Uint32 *dst = (Uint32 *)info->dst; - int n = info->dst_w; - while (n--) { - srcpixel = *src; - srcR = (Uint8)(srcpixel >> 24); srcG = (Uint8)(srcpixel >> 16); srcB = (Uint8)(srcpixel >> 8); srcA = (Uint8)srcpixel; - dstpixel = *dst; - dstA = (Uint8)(dstpixel >> 24); dstR = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstB = (Uint8)dstpixel; - if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) { - /* This goes away if we ever use premultiplied alpha */ - if (srcA < 255) { - srcR = (srcR * srcA) / 255; - srcG = (srcG * srcA) / 255; - srcB = (srcB * srcA) / 255; - } - } - switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) { - case SDL_COPY_BLEND: - dstR = srcR + ((255 - srcA) * dstR) / 255; - dstG = srcG + ((255 - srcA) * dstG) / 255; - dstB = srcB + ((255 - srcA) * dstB) / 255; - break; - case SDL_COPY_ADD: - dstR = srcR + dstR; if (dstR > 255) dstR = 255; - dstG = srcG + dstG; if (dstG > 255) dstG = 255; - dstB = srcB + dstB; if (dstB > 255) dstB = 255; - break; - case SDL_COPY_MOD: - dstR = (srcR * dstR) / 255; - dstG = (srcG * dstG) / 255; - dstB = (srcB * dstB) / 255; - break; - } - dstpixel = ((Uint32)dstA << 24) | ((Uint32)dstR << 16) | ((Uint32)dstG << 8) | dstB; - *dst = dstpixel; - ++src; - ++dst; - } - info->src += info->src_pitch; - info->dst += info->dst_pitch; - } -} - -static void SDL_Blit_RGBA8888_ARGB8888_Blend_Scale(SDL_BlitInfo *info) -{ - const int flags = info->flags; - Uint32 srcpixel; - Uint32 srcR, srcG, srcB, srcA; - Uint32 dstpixel; - Uint32 dstR, dstG, dstB, dstA; - int srcy, srcx; - int posy, posx; - int incy, incx; - - srcy = 0; - posy = 0; - incy = (info->src_h << 16) / info->dst_h; - incx = (info->src_w << 16) / info->dst_w; - - while (info->dst_h--) { - Uint32 *src = 0; - Uint32 *dst = (Uint32 *)info->dst; - int n = info->dst_w; - srcx = -1; - posx = 0x10000L; - while (posy >= 0x10000L) { - ++srcy; - posy -= 0x10000L; - } - while (n--) { - if (posx >= 0x10000L) { - while (posx >= 0x10000L) { - ++srcx; - posx -= 0x10000L; - } - src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4)); - } - srcpixel = *src; - srcR = (Uint8)(srcpixel >> 24); srcG = (Uint8)(srcpixel >> 16); srcB = (Uint8)(srcpixel >> 8); srcA = (Uint8)srcpixel; - dstpixel = *dst; - dstA = (Uint8)(dstpixel >> 24); dstR = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstB = (Uint8)dstpixel; - if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) { - /* This goes away if we ever use premultiplied alpha */ - if (srcA < 255) { - srcR = (srcR * srcA) / 255; - srcG = (srcG * srcA) / 255; - srcB = (srcB * srcA) / 255; - } - } - switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) { - case SDL_COPY_BLEND: - dstR = srcR + ((255 - srcA) * dstR) / 255; - dstG = srcG + ((255 - srcA) * dstG) / 255; - dstB = srcB + ((255 - srcA) * dstB) / 255; - break; - case SDL_COPY_ADD: - dstR = srcR + dstR; if (dstR > 255) dstR = 255; - dstG = srcG + dstG; if (dstG > 255) dstG = 255; - dstB = srcB + dstB; if (dstB > 255) dstB = 255; - break; - case SDL_COPY_MOD: - dstR = (srcR * dstR) / 255; - dstG = (srcG * dstG) / 255; - dstB = (srcB * dstB) / 255; - break; - } - dstpixel = ((Uint32)dstA << 24) | ((Uint32)dstR << 16) | ((Uint32)dstG << 8) | dstB; - *dst = dstpixel; - posx += incx; - ++dst; - } - posy += incy; - info->dst += info->dst_pitch; - } -} - -static void SDL_Blit_RGBA8888_ARGB8888_Modulate(SDL_BlitInfo *info) -{ - const int flags = info->flags; - const Uint32 modulateR = info->r; - const Uint32 modulateG = info->g; - const Uint32 modulateB = info->b; - const Uint32 modulateA = info->a; - Uint32 pixel; - Uint32 R, G, B, A; - - while (info->dst_h--) { - Uint32 *src = (Uint32 *)info->src; - Uint32 *dst = (Uint32 *)info->dst; - int n = info->dst_w; - while (n--) { - pixel = *src; - R = (Uint8)(pixel >> 24); G = (Uint8)(pixel >> 16); B = (Uint8)(pixel >> 8); A = (Uint8)pixel; - if (flags & SDL_COPY_MODULATE_COLOR) { - R = (R * modulateR) / 255; - G = (G * modulateG) / 255; - B = (B * modulateB) / 255; - } - if (flags & SDL_COPY_MODULATE_ALPHA) { - A = (A * modulateA) / 255; - } - pixel = ((Uint32)A << 24) | ((Uint32)R << 16) | ((Uint32)G << 8) | B; - *dst = pixel; - ++src; - ++dst; - } - info->src += info->src_pitch; - info->dst += info->dst_pitch; - } -} - -static void SDL_Blit_RGBA8888_ARGB8888_Modulate_Scale(SDL_BlitInfo *info) -{ - const int flags = info->flags; - const Uint32 modulateR = info->r; - const Uint32 modulateG = info->g; - const Uint32 modulateB = info->b; - const Uint32 modulateA = info->a; - Uint32 pixel; - Uint32 R, G, B, A; - int srcy, srcx; - int posy, posx; - int incy, incx; - - srcy = 0; - posy = 0; - incy = (info->src_h << 16) / info->dst_h; - incx = (info->src_w << 16) / info->dst_w; - - while (info->dst_h--) { - Uint32 *src = 0; - Uint32 *dst = (Uint32 *)info->dst; - int n = info->dst_w; - srcx = -1; - posx = 0x10000L; - while (posy >= 0x10000L) { - ++srcy; - posy -= 0x10000L; - } - while (n--) { - if (posx >= 0x10000L) { - while (posx >= 0x10000L) { - ++srcx; - posx -= 0x10000L; - } - src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4)); - } - pixel = *src; - R = (Uint8)(pixel >> 24); G = (Uint8)(pixel >> 16); B = (Uint8)(pixel >> 8); A = (Uint8)pixel; - if (flags & SDL_COPY_MODULATE_COLOR) { - R = (R * modulateR) / 255; - G = (G * modulateG) / 255; - B = (B * modulateB) / 255; - } - if (flags & SDL_COPY_MODULATE_ALPHA) { - A = (A * modulateA) / 255; - } - pixel = ((Uint32)A << 24) | ((Uint32)R << 16) | ((Uint32)G << 8) | B; - *dst = pixel; - posx += incx; - ++dst; - } - posy += incy; - info->dst += info->dst_pitch; - } -} - -static void SDL_Blit_RGBA8888_ARGB8888_Modulate_Blend(SDL_BlitInfo *info) -{ - const int flags = info->flags; - const Uint32 modulateR = info->r; - const Uint32 modulateG = info->g; - const Uint32 modulateB = info->b; - const Uint32 modulateA = info->a; - Uint32 srcpixel; - Uint32 srcR, srcG, srcB, srcA; - Uint32 dstpixel; - Uint32 dstR, dstG, dstB, dstA; - - while (info->dst_h--) { - Uint32 *src = (Uint32 *)info->src; - Uint32 *dst = (Uint32 *)info->dst; - int n = info->dst_w; - while (n--) { - srcpixel = *src; - srcR = (Uint8)(srcpixel >> 24); srcG = (Uint8)(srcpixel >> 16); srcB = (Uint8)(srcpixel >> 8); srcA = (Uint8)srcpixel; - dstpixel = *dst; - dstA = (Uint8)(dstpixel >> 24); dstR = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstB = (Uint8)dstpixel; - if (flags & SDL_COPY_MODULATE_COLOR) { - srcR = (srcR * modulateR) / 255; - srcG = (srcG * modulateG) / 255; - srcB = (srcB * modulateB) / 255; - } - if (flags & SDL_COPY_MODULATE_ALPHA) { - srcA = (srcA * modulateA) / 255; - } - if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) { - /* This goes away if we ever use premultiplied alpha */ - if (srcA < 255) { - srcR = (srcR * srcA) / 255; - srcG = (srcG * srcA) / 255; - srcB = (srcB * srcA) / 255; - } - } - switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) { - case SDL_COPY_BLEND: - dstR = srcR + ((255 - srcA) * dstR) / 255; - dstG = srcG + ((255 - srcA) * dstG) / 255; - dstB = srcB + ((255 - srcA) * dstB) / 255; - break; - case SDL_COPY_ADD: - dstR = srcR + dstR; if (dstR > 255) dstR = 255; - dstG = srcG + dstG; if (dstG > 255) dstG = 255; - dstB = srcB + dstB; if (dstB > 255) dstB = 255; - break; - case SDL_COPY_MOD: - dstR = (srcR * dstR) / 255; - dstG = (srcG * dstG) / 255; - dstB = (srcB * dstB) / 255; - break; - } - dstpixel = ((Uint32)dstA << 24) | ((Uint32)dstR << 16) | ((Uint32)dstG << 8) | dstB; - *dst = dstpixel; - ++src; - ++dst; - } - info->src += info->src_pitch; - info->dst += info->dst_pitch; - } -} - -static void SDL_Blit_RGBA8888_ARGB8888_Modulate_Blend_Scale(SDL_BlitInfo *info) -{ - const int flags = info->flags; - const Uint32 modulateR = info->r; - const Uint32 modulateG = info->g; - const Uint32 modulateB = info->b; - const Uint32 modulateA = info->a; - Uint32 srcpixel; - Uint32 srcR, srcG, srcB, srcA; - Uint32 dstpixel; - Uint32 dstR, dstG, dstB, dstA; - int srcy, srcx; - int posy, posx; - int incy, incx; - - srcy = 0; - posy = 0; - incy = (info->src_h << 16) / info->dst_h; - incx = (info->src_w << 16) / info->dst_w; - - while (info->dst_h--) { - Uint32 *src = 0; - Uint32 *dst = (Uint32 *)info->dst; - int n = info->dst_w; - srcx = -1; - posx = 0x10000L; - while (posy >= 0x10000L) { - ++srcy; - posy -= 0x10000L; - } - while (n--) { - if (posx >= 0x10000L) { - while (posx >= 0x10000L) { - ++srcx; - posx -= 0x10000L; - } - src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4)); - } - srcpixel = *src; - srcR = (Uint8)(srcpixel >> 24); srcG = (Uint8)(srcpixel >> 16); srcB = (Uint8)(srcpixel >> 8); srcA = (Uint8)srcpixel; - dstpixel = *dst; - dstA = (Uint8)(dstpixel >> 24); dstR = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstB = (Uint8)dstpixel; - if (flags & SDL_COPY_MODULATE_COLOR) { - srcR = (srcR * modulateR) / 255; - srcG = (srcG * modulateG) / 255; - srcB = (srcB * modulateB) / 255; - } - if (flags & SDL_COPY_MODULATE_ALPHA) { - srcA = (srcA * modulateA) / 255; - } - if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) { - /* This goes away if we ever use premultiplied alpha */ - if (srcA < 255) { - srcR = (srcR * srcA) / 255; - srcG = (srcG * srcA) / 255; - srcB = (srcB * srcA) / 255; - } - } - switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) { - case SDL_COPY_BLEND: - dstR = srcR + ((255 - srcA) * dstR) / 255; - dstG = srcG + ((255 - srcA) * dstG) / 255; - dstB = srcB + ((255 - srcA) * dstB) / 255; - break; - case SDL_COPY_ADD: - dstR = srcR + dstR; if (dstR > 255) dstR = 255; - dstG = srcG + dstG; if (dstG > 255) dstG = 255; - dstB = srcB + dstB; if (dstB > 255) dstB = 255; - break; - case SDL_COPY_MOD: - dstR = (srcR * dstR) / 255; - dstG = (srcG * dstG) / 255; - dstB = (srcB * dstB) / 255; - break; - } - dstpixel = ((Uint32)dstA << 24) | ((Uint32)dstR << 16) | ((Uint32)dstG << 8) | dstB; - *dst = dstpixel; - posx += incx; - ++dst; - } - posy += incy; - info->dst += info->dst_pitch; - } -} - -static void SDL_Blit_ABGR8888_RGB888_Scale(SDL_BlitInfo *info) -{ - Uint32 pixel; - Uint32 R, G, B, A; - int srcy, srcx; - int posy, posx; - int incy, incx; - - srcy = 0; - posy = 0; - incy = (info->src_h << 16) / info->dst_h; - incx = (info->src_w << 16) / info->dst_w; - - while (info->dst_h--) { - Uint32 *src = 0; - Uint32 *dst = (Uint32 *)info->dst; - int n = info->dst_w; - srcx = -1; - posx = 0x10000L; - while (posy >= 0x10000L) { - ++srcy; - posy -= 0x10000L; - } - while (n--) { - if (posx >= 0x10000L) { - while (posx >= 0x10000L) { - ++srcx; - posx -= 0x10000L; - } - src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4)); - } - pixel = *src; - A = (Uint8)(pixel >> 24); B = (Uint8)(pixel >> 16); G = (Uint8)(pixel >> 8); R = (Uint8)pixel; - pixel = ((Uint32)R << 16) | ((Uint32)G << 8) | B; - *dst = pixel; - posx += incx; - ++dst; - } - posy += incy; - info->dst += info->dst_pitch; - } -} - -static void SDL_Blit_ABGR8888_RGB888_Blend(SDL_BlitInfo *info) -{ - const int flags = info->flags; - Uint32 srcpixel; - Uint32 srcR, srcG, srcB, srcA; - Uint32 dstpixel; - Uint32 dstR, dstG, dstB, dstA; - - while (info->dst_h--) { - Uint32 *src = (Uint32 *)info->src; - Uint32 *dst = (Uint32 *)info->dst; - int n = info->dst_w; - while (n--) { - srcpixel = *src; - srcA = (Uint8)(srcpixel >> 24); srcB = (Uint8)(srcpixel >> 16); srcG = (Uint8)(srcpixel >> 8); srcR = (Uint8)srcpixel; - dstpixel = *dst; - dstR = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstB = (Uint8)dstpixel; dstA = 0xFF; - if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) { - /* This goes away if we ever use premultiplied alpha */ - if (srcA < 255) { - srcR = (srcR * srcA) / 255; - srcG = (srcG * srcA) / 255; - srcB = (srcB * srcA) / 255; - } - } - switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) { - case SDL_COPY_BLEND: - dstR = srcR + ((255 - srcA) * dstR) / 255; - dstG = srcG + ((255 - srcA) * dstG) / 255; - dstB = srcB + ((255 - srcA) * dstB) / 255; - break; - case SDL_COPY_ADD: - dstR = srcR + dstR; if (dstR > 255) dstR = 255; - dstG = srcG + dstG; if (dstG > 255) dstG = 255; - dstB = srcB + dstB; if (dstB > 255) dstB = 255; - break; - case SDL_COPY_MOD: - dstR = (srcR * dstR) / 255; - dstG = (srcG * dstG) / 255; - dstB = (srcB * dstB) / 255; - break; - } - dstpixel = ((Uint32)dstR << 16) | ((Uint32)dstG << 8) | dstB; - *dst = dstpixel; - ++src; - ++dst; - } - info->src += info->src_pitch; - info->dst += info->dst_pitch; - } -} - -static void SDL_Blit_ABGR8888_RGB888_Blend_Scale(SDL_BlitInfo *info) -{ - const int flags = info->flags; - Uint32 srcpixel; - Uint32 srcR, srcG, srcB, srcA; - Uint32 dstpixel; - Uint32 dstR, dstG, dstB, dstA; - int srcy, srcx; - int posy, posx; - int incy, incx; - - srcy = 0; - posy = 0; - incy = (info->src_h << 16) / info->dst_h; - incx = (info->src_w << 16) / info->dst_w; - - while (info->dst_h--) { - Uint32 *src = 0; - Uint32 *dst = (Uint32 *)info->dst; - int n = info->dst_w; - srcx = -1; - posx = 0x10000L; - while (posy >= 0x10000L) { - ++srcy; - posy -= 0x10000L; - } - while (n--) { - if (posx >= 0x10000L) { - while (posx >= 0x10000L) { - ++srcx; - posx -= 0x10000L; - } - src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4)); - } - srcpixel = *src; - srcA = (Uint8)(srcpixel >> 24); srcB = (Uint8)(srcpixel >> 16); srcG = (Uint8)(srcpixel >> 8); srcR = (Uint8)srcpixel; - dstpixel = *dst; - dstR = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstB = (Uint8)dstpixel; dstA = 0xFF; - if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) { - /* This goes away if we ever use premultiplied alpha */ - if (srcA < 255) { - srcR = (srcR * srcA) / 255; - srcG = (srcG * srcA) / 255; - srcB = (srcB * srcA) / 255; - } - } - switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) { - case SDL_COPY_BLEND: - dstR = srcR + ((255 - srcA) * dstR) / 255; - dstG = srcG + ((255 - srcA) * dstG) / 255; - dstB = srcB + ((255 - srcA) * dstB) / 255; - break; - case SDL_COPY_ADD: - dstR = srcR + dstR; if (dstR > 255) dstR = 255; - dstG = srcG + dstG; if (dstG > 255) dstG = 255; - dstB = srcB + dstB; if (dstB > 255) dstB = 255; - break; - case SDL_COPY_MOD: - dstR = (srcR * dstR) / 255; - dstG = (srcG * dstG) / 255; - dstB = (srcB * dstB) / 255; - break; - } - dstpixel = ((Uint32)dstR << 16) | ((Uint32)dstG << 8) | dstB; - *dst = dstpixel; - posx += incx; - ++dst; - } - posy += incy; - info->dst += info->dst_pitch; - } -} - -static void SDL_Blit_ABGR8888_RGB888_Modulate(SDL_BlitInfo *info) -{ - const int flags = info->flags; - const Uint32 modulateR = info->r; - const Uint32 modulateG = info->g; - const Uint32 modulateB = info->b; - const Uint32 modulateA = info->a; - Uint32 pixel; - Uint32 R, G, B, A; - - while (info->dst_h--) { - Uint32 *src = (Uint32 *)info->src; - Uint32 *dst = (Uint32 *)info->dst; - int n = info->dst_w; - while (n--) { - pixel = *src; - A = (Uint8)(pixel >> 24); B = (Uint8)(pixel >> 16); G = (Uint8)(pixel >> 8); R = (Uint8)pixel; - if (flags & SDL_COPY_MODULATE_COLOR) { - R = (R * modulateR) / 255; - G = (G * modulateG) / 255; - B = (B * modulateB) / 255; - } - if (flags & SDL_COPY_MODULATE_ALPHA) { - A = (A * modulateA) / 255; - } - pixel = ((Uint32)R << 16) | ((Uint32)G << 8) | B; - *dst = pixel; - ++src; - ++dst; - } - info->src += info->src_pitch; - info->dst += info->dst_pitch; - } -} - -static void SDL_Blit_ABGR8888_RGB888_Modulate_Scale(SDL_BlitInfo *info) -{ - const int flags = info->flags; - const Uint32 modulateR = info->r; - const Uint32 modulateG = info->g; - const Uint32 modulateB = info->b; - const Uint32 modulateA = info->a; - Uint32 pixel; - Uint32 R, G, B, A; - int srcy, srcx; - int posy, posx; - int incy, incx; - - srcy = 0; - posy = 0; - incy = (info->src_h << 16) / info->dst_h; - incx = (info->src_w << 16) / info->dst_w; - - while (info->dst_h--) { - Uint32 *src = 0; - Uint32 *dst = (Uint32 *)info->dst; - int n = info->dst_w; - srcx = -1; - posx = 0x10000L; - while (posy >= 0x10000L) { - ++srcy; - posy -= 0x10000L; - } - while (n--) { - if (posx >= 0x10000L) { - while (posx >= 0x10000L) { - ++srcx; - posx -= 0x10000L; - } - src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4)); - } - pixel = *src; - A = (Uint8)(pixel >> 24); B = (Uint8)(pixel >> 16); G = (Uint8)(pixel >> 8); R = (Uint8)pixel; - if (flags & SDL_COPY_MODULATE_COLOR) { - R = (R * modulateR) / 255; - G = (G * modulateG) / 255; - B = (B * modulateB) / 255; - } - if (flags & SDL_COPY_MODULATE_ALPHA) { - A = (A * modulateA) / 255; - } - pixel = ((Uint32)R << 16) | ((Uint32)G << 8) | B; - *dst = pixel; - posx += incx; - ++dst; - } - posy += incy; - info->dst += info->dst_pitch; - } -} - -static void SDL_Blit_ABGR8888_RGB888_Modulate_Blend(SDL_BlitInfo *info) -{ - const int flags = info->flags; - const Uint32 modulateR = info->r; - const Uint32 modulateG = info->g; - const Uint32 modulateB = info->b; - const Uint32 modulateA = info->a; - Uint32 srcpixel; - Uint32 srcR, srcG, srcB, srcA; - Uint32 dstpixel; - Uint32 dstR, dstG, dstB, dstA; - - while (info->dst_h--) { - Uint32 *src = (Uint32 *)info->src; - Uint32 *dst = (Uint32 *)info->dst; - int n = info->dst_w; - while (n--) { - srcpixel = *src; - srcA = (Uint8)(srcpixel >> 24); srcB = (Uint8)(srcpixel >> 16); srcG = (Uint8)(srcpixel >> 8); srcR = (Uint8)srcpixel; - dstpixel = *dst; - dstR = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstB = (Uint8)dstpixel; dstA = 0xFF; - if (flags & SDL_COPY_MODULATE_COLOR) { - srcR = (srcR * modulateR) / 255; - srcG = (srcG * modulateG) / 255; - srcB = (srcB * modulateB) / 255; - } - if (flags & SDL_COPY_MODULATE_ALPHA) { - srcA = (srcA * modulateA) / 255; - } - if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) { - /* This goes away if we ever use premultiplied alpha */ - if (srcA < 255) { - srcR = (srcR * srcA) / 255; - srcG = (srcG * srcA) / 255; - srcB = (srcB * srcA) / 255; - } - } - switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) { - case SDL_COPY_BLEND: - dstR = srcR + ((255 - srcA) * dstR) / 255; - dstG = srcG + ((255 - srcA) * dstG) / 255; - dstB = srcB + ((255 - srcA) * dstB) / 255; - break; - case SDL_COPY_ADD: - dstR = srcR + dstR; if (dstR > 255) dstR = 255; - dstG = srcG + dstG; if (dstG > 255) dstG = 255; - dstB = srcB + dstB; if (dstB > 255) dstB = 255; - break; - case SDL_COPY_MOD: - dstR = (srcR * dstR) / 255; - dstG = (srcG * dstG) / 255; - dstB = (srcB * dstB) / 255; - break; - } - dstpixel = ((Uint32)dstR << 16) | ((Uint32)dstG << 8) | dstB; - *dst = dstpixel; - ++src; - ++dst; - } - info->src += info->src_pitch; - info->dst += info->dst_pitch; - } -} - -static void SDL_Blit_ABGR8888_RGB888_Modulate_Blend_Scale(SDL_BlitInfo *info) -{ - const int flags = info->flags; - const Uint32 modulateR = info->r; - const Uint32 modulateG = info->g; - const Uint32 modulateB = info->b; - const Uint32 modulateA = info->a; - Uint32 srcpixel; - Uint32 srcR, srcG, srcB, srcA; - Uint32 dstpixel; - Uint32 dstR, dstG, dstB, dstA; - int srcy, srcx; - int posy, posx; - int incy, incx; - - srcy = 0; - posy = 0; - incy = (info->src_h << 16) / info->dst_h; - incx = (info->src_w << 16) / info->dst_w; - - while (info->dst_h--) { - Uint32 *src = 0; - Uint32 *dst = (Uint32 *)info->dst; - int n = info->dst_w; - srcx = -1; - posx = 0x10000L; - while (posy >= 0x10000L) { - ++srcy; - posy -= 0x10000L; - } - while (n--) { - if (posx >= 0x10000L) { - while (posx >= 0x10000L) { - ++srcx; - posx -= 0x10000L; - } - src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4)); - } - srcpixel = *src; - srcA = (Uint8)(srcpixel >> 24); srcB = (Uint8)(srcpixel >> 16); srcG = (Uint8)(srcpixel >> 8); srcR = (Uint8)srcpixel; - dstpixel = *dst; - dstR = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstB = (Uint8)dstpixel; dstA = 0xFF; - if (flags & SDL_COPY_MODULATE_COLOR) { - srcR = (srcR * modulateR) / 255; - srcG = (srcG * modulateG) / 255; - srcB = (srcB * modulateB) / 255; - } - if (flags & SDL_COPY_MODULATE_ALPHA) { - srcA = (srcA * modulateA) / 255; - } - if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) { - /* This goes away if we ever use premultiplied alpha */ - if (srcA < 255) { - srcR = (srcR * srcA) / 255; - srcG = (srcG * srcA) / 255; - srcB = (srcB * srcA) / 255; - } - } - switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) { - case SDL_COPY_BLEND: - dstR = srcR + ((255 - srcA) * dstR) / 255; - dstG = srcG + ((255 - srcA) * dstG) / 255; - dstB = srcB + ((255 - srcA) * dstB) / 255; - break; - case SDL_COPY_ADD: - dstR = srcR + dstR; if (dstR > 255) dstR = 255; - dstG = srcG + dstG; if (dstG > 255) dstG = 255; - dstB = srcB + dstB; if (dstB > 255) dstB = 255; - break; - case SDL_COPY_MOD: - dstR = (srcR * dstR) / 255; - dstG = (srcG * dstG) / 255; - dstB = (srcB * dstB) / 255; - break; - } - dstpixel = ((Uint32)dstR << 16) | ((Uint32)dstG << 8) | dstB; - *dst = dstpixel; - posx += incx; - ++dst; - } - posy += incy; - info->dst += info->dst_pitch; - } -} - -static void SDL_Blit_ABGR8888_BGR888_Scale(SDL_BlitInfo *info) -{ - Uint32 pixel; - Uint32 R, G, B, A; - int srcy, srcx; - int posy, posx; - int incy, incx; - - srcy = 0; - posy = 0; - incy = (info->src_h << 16) / info->dst_h; - incx = (info->src_w << 16) / info->dst_w; - - while (info->dst_h--) { - Uint32 *src = 0; - Uint32 *dst = (Uint32 *)info->dst; - int n = info->dst_w; - srcx = -1; - posx = 0x10000L; - while (posy >= 0x10000L) { - ++srcy; - posy -= 0x10000L; - } - while (n--) { - if (posx >= 0x10000L) { - while (posx >= 0x10000L) { - ++srcx; - posx -= 0x10000L; - } - src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4)); - } - pixel = *src; - A = (Uint8)(pixel >> 24); B = (Uint8)(pixel >> 16); G = (Uint8)(pixel >> 8); R = (Uint8)pixel; - pixel = ((Uint32)B << 16) | ((Uint32)G << 8) | R; - *dst = pixel; - posx += incx; - ++dst; - } - posy += incy; - info->dst += info->dst_pitch; - } -} - -static void SDL_Blit_ABGR8888_BGR888_Blend(SDL_BlitInfo *info) -{ - const int flags = info->flags; - Uint32 srcpixel; - Uint32 srcR, srcG, srcB, srcA; - Uint32 dstpixel; - Uint32 dstR, dstG, dstB, dstA; - - while (info->dst_h--) { - Uint32 *src = (Uint32 *)info->src; - Uint32 *dst = (Uint32 *)info->dst; - int n = info->dst_w; - while (n--) { - srcpixel = *src; - srcA = (Uint8)(srcpixel >> 24); srcB = (Uint8)(srcpixel >> 16); srcG = (Uint8)(srcpixel >> 8); srcR = (Uint8)srcpixel; - dstpixel = *dst; - dstB = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstR = (Uint8)dstpixel; dstA = 0xFF; - if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) { - /* This goes away if we ever use premultiplied alpha */ - if (srcA < 255) { - srcR = (srcR * srcA) / 255; - srcG = (srcG * srcA) / 255; - srcB = (srcB * srcA) / 255; - } - } - switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) { - case SDL_COPY_BLEND: - dstR = srcR + ((255 - srcA) * dstR) / 255; - dstG = srcG + ((255 - srcA) * dstG) / 255; - dstB = srcB + ((255 - srcA) * dstB) / 255; - break; - case SDL_COPY_ADD: - dstR = srcR + dstR; if (dstR > 255) dstR = 255; - dstG = srcG + dstG; if (dstG > 255) dstG = 255; - dstB = srcB + dstB; if (dstB > 255) dstB = 255; - break; - case SDL_COPY_MOD: - dstR = (srcR * dstR) / 255; - dstG = (srcG * dstG) / 255; - dstB = (srcB * dstB) / 255; - break; - } - dstpixel = ((Uint32)dstB << 16) | ((Uint32)dstG << 8) | dstR; - *dst = dstpixel; - ++src; - ++dst; - } - info->src += info->src_pitch; - info->dst += info->dst_pitch; - } -} - -static void SDL_Blit_ABGR8888_BGR888_Blend_Scale(SDL_BlitInfo *info) -{ - const int flags = info->flags; - Uint32 srcpixel; - Uint32 srcR, srcG, srcB, srcA; - Uint32 dstpixel; - Uint32 dstR, dstG, dstB, dstA; - int srcy, srcx; - int posy, posx; - int incy, incx; - - srcy = 0; - posy = 0; - incy = (info->src_h << 16) / info->dst_h; - incx = (info->src_w << 16) / info->dst_w; - - while (info->dst_h--) { - Uint32 *src = 0; - Uint32 *dst = (Uint32 *)info->dst; - int n = info->dst_w; - srcx = -1; - posx = 0x10000L; - while (posy >= 0x10000L) { - ++srcy; - posy -= 0x10000L; - } - while (n--) { - if (posx >= 0x10000L) { - while (posx >= 0x10000L) { - ++srcx; - posx -= 0x10000L; - } - src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4)); - } - srcpixel = *src; - srcA = (Uint8)(srcpixel >> 24); srcB = (Uint8)(srcpixel >> 16); srcG = (Uint8)(srcpixel >> 8); srcR = (Uint8)srcpixel; - dstpixel = *dst; - dstB = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstR = (Uint8)dstpixel; dstA = 0xFF; - if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) { - /* This goes away if we ever use premultiplied alpha */ - if (srcA < 255) { - srcR = (srcR * srcA) / 255; - srcG = (srcG * srcA) / 255; - srcB = (srcB * srcA) / 255; - } - } - switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) { - case SDL_COPY_BLEND: - dstR = srcR + ((255 - srcA) * dstR) / 255; - dstG = srcG + ((255 - srcA) * dstG) / 255; - dstB = srcB + ((255 - srcA) * dstB) / 255; - break; - case SDL_COPY_ADD: - dstR = srcR + dstR; if (dstR > 255) dstR = 255; - dstG = srcG + dstG; if (dstG > 255) dstG = 255; - dstB = srcB + dstB; if (dstB > 255) dstB = 255; - break; - case SDL_COPY_MOD: - dstR = (srcR * dstR) / 255; - dstG = (srcG * dstG) / 255; - dstB = (srcB * dstB) / 255; - break; - } - dstpixel = ((Uint32)dstB << 16) | ((Uint32)dstG << 8) | dstR; - *dst = dstpixel; - posx += incx; - ++dst; - } - posy += incy; - info->dst += info->dst_pitch; - } -} - -static void SDL_Blit_ABGR8888_BGR888_Modulate(SDL_BlitInfo *info) -{ - const int flags = info->flags; - const Uint32 modulateR = info->r; - const Uint32 modulateG = info->g; - const Uint32 modulateB = info->b; - const Uint32 modulateA = info->a; - Uint32 pixel; - Uint32 R, G, B, A; - - while (info->dst_h--) { - Uint32 *src = (Uint32 *)info->src; - Uint32 *dst = (Uint32 *)info->dst; - int n = info->dst_w; - while (n--) { - pixel = *src; - A = (Uint8)(pixel >> 24); B = (Uint8)(pixel >> 16); G = (Uint8)(pixel >> 8); R = (Uint8)pixel; - if (flags & SDL_COPY_MODULATE_COLOR) { - R = (R * modulateR) / 255; - G = (G * modulateG) / 255; - B = (B * modulateB) / 255; - } - if (flags & SDL_COPY_MODULATE_ALPHA) { - A = (A * modulateA) / 255; - } - pixel = ((Uint32)B << 16) | ((Uint32)G << 8) | R; - *dst = pixel; - ++src; - ++dst; - } - info->src += info->src_pitch; - info->dst += info->dst_pitch; - } -} - -static void SDL_Blit_ABGR8888_BGR888_Modulate_Scale(SDL_BlitInfo *info) -{ - const int flags = info->flags; - const Uint32 modulateR = info->r; - const Uint32 modulateG = info->g; - const Uint32 modulateB = info->b; - const Uint32 modulateA = info->a; - Uint32 pixel; - Uint32 R, G, B, A; - int srcy, srcx; - int posy, posx; - int incy, incx; - - srcy = 0; - posy = 0; - incy = (info->src_h << 16) / info->dst_h; - incx = (info->src_w << 16) / info->dst_w; - - while (info->dst_h--) { - Uint32 *src = 0; - Uint32 *dst = (Uint32 *)info->dst; - int n = info->dst_w; - srcx = -1; - posx = 0x10000L; - while (posy >= 0x10000L) { - ++srcy; - posy -= 0x10000L; - } - while (n--) { - if (posx >= 0x10000L) { - while (posx >= 0x10000L) { - ++srcx; - posx -= 0x10000L; - } - src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4)); - } - pixel = *src; - A = (Uint8)(pixel >> 24); B = (Uint8)(pixel >> 16); G = (Uint8)(pixel >> 8); R = (Uint8)pixel; - if (flags & SDL_COPY_MODULATE_COLOR) { - R = (R * modulateR) / 255; - G = (G * modulateG) / 255; - B = (B * modulateB) / 255; - } - if (flags & SDL_COPY_MODULATE_ALPHA) { - A = (A * modulateA) / 255; - } - pixel = ((Uint32)B << 16) | ((Uint32)G << 8) | R; - *dst = pixel; - posx += incx; - ++dst; - } - posy += incy; - info->dst += info->dst_pitch; - } -} - -static void SDL_Blit_ABGR8888_BGR888_Modulate_Blend(SDL_BlitInfo *info) -{ - const int flags = info->flags; - const Uint32 modulateR = info->r; - const Uint32 modulateG = info->g; - const Uint32 modulateB = info->b; - const Uint32 modulateA = info->a; - Uint32 srcpixel; - Uint32 srcR, srcG, srcB, srcA; - Uint32 dstpixel; - Uint32 dstR, dstG, dstB, dstA; - - while (info->dst_h--) { - Uint32 *src = (Uint32 *)info->src; - Uint32 *dst = (Uint32 *)info->dst; - int n = info->dst_w; - while (n--) { - srcpixel = *src; - srcA = (Uint8)(srcpixel >> 24); srcB = (Uint8)(srcpixel >> 16); srcG = (Uint8)(srcpixel >> 8); srcR = (Uint8)srcpixel; - dstpixel = *dst; - dstB = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstR = (Uint8)dstpixel; dstA = 0xFF; - if (flags & SDL_COPY_MODULATE_COLOR) { - srcR = (srcR * modulateR) / 255; - srcG = (srcG * modulateG) / 255; - srcB = (srcB * modulateB) / 255; - } - if (flags & SDL_COPY_MODULATE_ALPHA) { - srcA = (srcA * modulateA) / 255; - } - if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) { - /* This goes away if we ever use premultiplied alpha */ - if (srcA < 255) { - srcR = (srcR * srcA) / 255; - srcG = (srcG * srcA) / 255; - srcB = (srcB * srcA) / 255; - } - } - switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) { - case SDL_COPY_BLEND: - dstR = srcR + ((255 - srcA) * dstR) / 255; - dstG = srcG + ((255 - srcA) * dstG) / 255; - dstB = srcB + ((255 - srcA) * dstB) / 255; - break; - case SDL_COPY_ADD: - dstR = srcR + dstR; if (dstR > 255) dstR = 255; - dstG = srcG + dstG; if (dstG > 255) dstG = 255; - dstB = srcB + dstB; if (dstB > 255) dstB = 255; - break; - case SDL_COPY_MOD: - dstR = (srcR * dstR) / 255; - dstG = (srcG * dstG) / 255; - dstB = (srcB * dstB) / 255; - break; - } - dstpixel = ((Uint32)dstB << 16) | ((Uint32)dstG << 8) | dstR; - *dst = dstpixel; - ++src; - ++dst; - } - info->src += info->src_pitch; - info->dst += info->dst_pitch; - } -} - -static void SDL_Blit_ABGR8888_BGR888_Modulate_Blend_Scale(SDL_BlitInfo *info) -{ - const int flags = info->flags; - const Uint32 modulateR = info->r; - const Uint32 modulateG = info->g; - const Uint32 modulateB = info->b; - const Uint32 modulateA = info->a; - Uint32 srcpixel; - Uint32 srcR, srcG, srcB, srcA; - Uint32 dstpixel; - Uint32 dstR, dstG, dstB, dstA; - int srcy, srcx; - int posy, posx; - int incy, incx; - - srcy = 0; - posy = 0; - incy = (info->src_h << 16) / info->dst_h; - incx = (info->src_w << 16) / info->dst_w; - - while (info->dst_h--) { - Uint32 *src = 0; - Uint32 *dst = (Uint32 *)info->dst; - int n = info->dst_w; - srcx = -1; - posx = 0x10000L; - while (posy >= 0x10000L) { - ++srcy; - posy -= 0x10000L; - } - while (n--) { - if (posx >= 0x10000L) { - while (posx >= 0x10000L) { - ++srcx; - posx -= 0x10000L; - } - src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4)); - } - srcpixel = *src; - srcA = (Uint8)(srcpixel >> 24); srcB = (Uint8)(srcpixel >> 16); srcG = (Uint8)(srcpixel >> 8); srcR = (Uint8)srcpixel; - dstpixel = *dst; - dstB = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstR = (Uint8)dstpixel; dstA = 0xFF; - if (flags & SDL_COPY_MODULATE_COLOR) { - srcR = (srcR * modulateR) / 255; - srcG = (srcG * modulateG) / 255; - srcB = (srcB * modulateB) / 255; - } - if (flags & SDL_COPY_MODULATE_ALPHA) { - srcA = (srcA * modulateA) / 255; - } - if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) { - /* This goes away if we ever use premultiplied alpha */ - if (srcA < 255) { - srcR = (srcR * srcA) / 255; - srcG = (srcG * srcA) / 255; - srcB = (srcB * srcA) / 255; - } - } - switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) { - case SDL_COPY_BLEND: - dstR = srcR + ((255 - srcA) * dstR) / 255; - dstG = srcG + ((255 - srcA) * dstG) / 255; - dstB = srcB + ((255 - srcA) * dstB) / 255; - break; - case SDL_COPY_ADD: - dstR = srcR + dstR; if (dstR > 255) dstR = 255; - dstG = srcG + dstG; if (dstG > 255) dstG = 255; - dstB = srcB + dstB; if (dstB > 255) dstB = 255; - break; - case SDL_COPY_MOD: - dstR = (srcR * dstR) / 255; - dstG = (srcG * dstG) / 255; - dstB = (srcB * dstB) / 255; - break; - } - dstpixel = ((Uint32)dstB << 16) | ((Uint32)dstG << 8) | dstR; - *dst = dstpixel; - posx += incx; - ++dst; - } - posy += incy; - info->dst += info->dst_pitch; - } -} - -static void SDL_Blit_ABGR8888_ARGB8888_Scale(SDL_BlitInfo *info) -{ - Uint32 pixel; - Uint32 R, G, B, A; - int srcy, srcx; - int posy, posx; - int incy, incx; - - srcy = 0; - posy = 0; - incy = (info->src_h << 16) / info->dst_h; - incx = (info->src_w << 16) / info->dst_w; - - while (info->dst_h--) { - Uint32 *src = 0; - Uint32 *dst = (Uint32 *)info->dst; - int n = info->dst_w; - srcx = -1; - posx = 0x10000L; - while (posy >= 0x10000L) { - ++srcy; - posy -= 0x10000L; - } - while (n--) { - if (posx >= 0x10000L) { - while (posx >= 0x10000L) { - ++srcx; - posx -= 0x10000L; - } - src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4)); - } - pixel = *src; - A = (Uint8)(pixel >> 24); B = (Uint8)(pixel >> 16); G = (Uint8)(pixel >> 8); R = (Uint8)pixel; - pixel = ((Uint32)A << 24) | ((Uint32)R << 16) | ((Uint32)G << 8) | B; - *dst = pixel; - posx += incx; - ++dst; - } - posy += incy; - info->dst += info->dst_pitch; - } -} - -static void SDL_Blit_ABGR8888_ARGB8888_Blend(SDL_BlitInfo *info) -{ - const int flags = info->flags; - Uint32 srcpixel; - Uint32 srcR, srcG, srcB, srcA; - Uint32 dstpixel; - Uint32 dstR, dstG, dstB, dstA; - - while (info->dst_h--) { - Uint32 *src = (Uint32 *)info->src; - Uint32 *dst = (Uint32 *)info->dst; - int n = info->dst_w; - while (n--) { - srcpixel = *src; - srcA = (Uint8)(srcpixel >> 24); srcB = (Uint8)(srcpixel >> 16); srcG = (Uint8)(srcpixel >> 8); srcR = (Uint8)srcpixel; - dstpixel = *dst; - dstA = (Uint8)(dstpixel >> 24); dstR = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstB = (Uint8)dstpixel; - if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) { - /* This goes away if we ever use premultiplied alpha */ - if (srcA < 255) { - srcR = (srcR * srcA) / 255; - srcG = (srcG * srcA) / 255; - srcB = (srcB * srcA) / 255; - } - } - switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) { - case SDL_COPY_BLEND: - dstR = srcR + ((255 - srcA) * dstR) / 255; - dstG = srcG + ((255 - srcA) * dstG) / 255; - dstB = srcB + ((255 - srcA) * dstB) / 255; - break; - case SDL_COPY_ADD: - dstR = srcR + dstR; if (dstR > 255) dstR = 255; - dstG = srcG + dstG; if (dstG > 255) dstG = 255; - dstB = srcB + dstB; if (dstB > 255) dstB = 255; - break; - case SDL_COPY_MOD: - dstR = (srcR * dstR) / 255; - dstG = (srcG * dstG) / 255; - dstB = (srcB * dstB) / 255; - break; - } - dstpixel = ((Uint32)dstA << 24) | ((Uint32)dstR << 16) | ((Uint32)dstG << 8) | dstB; - *dst = dstpixel; - ++src; - ++dst; - } - info->src += info->src_pitch; - info->dst += info->dst_pitch; - } -} - -static void SDL_Blit_ABGR8888_ARGB8888_Blend_Scale(SDL_BlitInfo *info) -{ - const int flags = info->flags; - Uint32 srcpixel; - Uint32 srcR, srcG, srcB, srcA; - Uint32 dstpixel; - Uint32 dstR, dstG, dstB, dstA; - int srcy, srcx; - int posy, posx; - int incy, incx; - - srcy = 0; - posy = 0; - incy = (info->src_h << 16) / info->dst_h; - incx = (info->src_w << 16) / info->dst_w; - - while (info->dst_h--) { - Uint32 *src = 0; - Uint32 *dst = (Uint32 *)info->dst; - int n = info->dst_w; - srcx = -1; - posx = 0x10000L; - while (posy >= 0x10000L) { - ++srcy; - posy -= 0x10000L; - } - while (n--) { - if (posx >= 0x10000L) { - while (posx >= 0x10000L) { - ++srcx; - posx -= 0x10000L; - } - src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4)); - } - srcpixel = *src; - srcA = (Uint8)(srcpixel >> 24); srcB = (Uint8)(srcpixel >> 16); srcG = (Uint8)(srcpixel >> 8); srcR = (Uint8)srcpixel; - dstpixel = *dst; - dstA = (Uint8)(dstpixel >> 24); dstR = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstB = (Uint8)dstpixel; - if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) { - /* This goes away if we ever use premultiplied alpha */ - if (srcA < 255) { - srcR = (srcR * srcA) / 255; - srcG = (srcG * srcA) / 255; - srcB = (srcB * srcA) / 255; - } - } - switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) { - case SDL_COPY_BLEND: - dstR = srcR + ((255 - srcA) * dstR) / 255; - dstG = srcG + ((255 - srcA) * dstG) / 255; - dstB = srcB + ((255 - srcA) * dstB) / 255; - break; - case SDL_COPY_ADD: - dstR = srcR + dstR; if (dstR > 255) dstR = 255; - dstG = srcG + dstG; if (dstG > 255) dstG = 255; - dstB = srcB + dstB; if (dstB > 255) dstB = 255; - break; - case SDL_COPY_MOD: - dstR = (srcR * dstR) / 255; - dstG = (srcG * dstG) / 255; - dstB = (srcB * dstB) / 255; - break; - } - dstpixel = ((Uint32)dstA << 24) | ((Uint32)dstR << 16) | ((Uint32)dstG << 8) | dstB; - *dst = dstpixel; - posx += incx; - ++dst; - } - posy += incy; - info->dst += info->dst_pitch; - } -} - -static void SDL_Blit_ABGR8888_ARGB8888_Modulate(SDL_BlitInfo *info) -{ - const int flags = info->flags; - const Uint32 modulateR = info->r; - const Uint32 modulateG = info->g; - const Uint32 modulateB = info->b; - const Uint32 modulateA = info->a; - Uint32 pixel; - Uint32 R, G, B, A; - - while (info->dst_h--) { - Uint32 *src = (Uint32 *)info->src; - Uint32 *dst = (Uint32 *)info->dst; - int n = info->dst_w; - while (n--) { - pixel = *src; - A = (Uint8)(pixel >> 24); B = (Uint8)(pixel >> 16); G = (Uint8)(pixel >> 8); R = (Uint8)pixel; - if (flags & SDL_COPY_MODULATE_COLOR) { - R = (R * modulateR) / 255; - G = (G * modulateG) / 255; - B = (B * modulateB) / 255; - } - if (flags & SDL_COPY_MODULATE_ALPHA) { - A = (A * modulateA) / 255; - } - pixel = ((Uint32)A << 24) | ((Uint32)R << 16) | ((Uint32)G << 8) | B; - *dst = pixel; - ++src; - ++dst; - } - info->src += info->src_pitch; - info->dst += info->dst_pitch; - } -} - -static void SDL_Blit_ABGR8888_ARGB8888_Modulate_Scale(SDL_BlitInfo *info) -{ - const int flags = info->flags; - const Uint32 modulateR = info->r; - const Uint32 modulateG = info->g; - const Uint32 modulateB = info->b; - const Uint32 modulateA = info->a; - Uint32 pixel; - Uint32 R, G, B, A; - int srcy, srcx; - int posy, posx; - int incy, incx; - - srcy = 0; - posy = 0; - incy = (info->src_h << 16) / info->dst_h; - incx = (info->src_w << 16) / info->dst_w; - - while (info->dst_h--) { - Uint32 *src = 0; - Uint32 *dst = (Uint32 *)info->dst; - int n = info->dst_w; - srcx = -1; - posx = 0x10000L; - while (posy >= 0x10000L) { - ++srcy; - posy -= 0x10000L; - } - while (n--) { - if (posx >= 0x10000L) { - while (posx >= 0x10000L) { - ++srcx; - posx -= 0x10000L; - } - src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4)); - } - pixel = *src; - A = (Uint8)(pixel >> 24); B = (Uint8)(pixel >> 16); G = (Uint8)(pixel >> 8); R = (Uint8)pixel; - if (flags & SDL_COPY_MODULATE_COLOR) { - R = (R * modulateR) / 255; - G = (G * modulateG) / 255; - B = (B * modulateB) / 255; - } - if (flags & SDL_COPY_MODULATE_ALPHA) { - A = (A * modulateA) / 255; - } - pixel = ((Uint32)A << 24) | ((Uint32)R << 16) | ((Uint32)G << 8) | B; - *dst = pixel; - posx += incx; - ++dst; - } - posy += incy; - info->dst += info->dst_pitch; - } -} - -static void SDL_Blit_ABGR8888_ARGB8888_Modulate_Blend(SDL_BlitInfo *info) -{ - const int flags = info->flags; - const Uint32 modulateR = info->r; - const Uint32 modulateG = info->g; - const Uint32 modulateB = info->b; - const Uint32 modulateA = info->a; - Uint32 srcpixel; - Uint32 srcR, srcG, srcB, srcA; - Uint32 dstpixel; - Uint32 dstR, dstG, dstB, dstA; - - while (info->dst_h--) { - Uint32 *src = (Uint32 *)info->src; - Uint32 *dst = (Uint32 *)info->dst; - int n = info->dst_w; - while (n--) { - srcpixel = *src; - srcA = (Uint8)(srcpixel >> 24); srcB = (Uint8)(srcpixel >> 16); srcG = (Uint8)(srcpixel >> 8); srcR = (Uint8)srcpixel; - dstpixel = *dst; - dstA = (Uint8)(dstpixel >> 24); dstR = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstB = (Uint8)dstpixel; - if (flags & SDL_COPY_MODULATE_COLOR) { - srcR = (srcR * modulateR) / 255; - srcG = (srcG * modulateG) / 255; - srcB = (srcB * modulateB) / 255; - } - if (flags & SDL_COPY_MODULATE_ALPHA) { - srcA = (srcA * modulateA) / 255; - } - if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) { - /* This goes away if we ever use premultiplied alpha */ - if (srcA < 255) { - srcR = (srcR * srcA) / 255; - srcG = (srcG * srcA) / 255; - srcB = (srcB * srcA) / 255; - } - } - switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) { - case SDL_COPY_BLEND: - dstR = srcR + ((255 - srcA) * dstR) / 255; - dstG = srcG + ((255 - srcA) * dstG) / 255; - dstB = srcB + ((255 - srcA) * dstB) / 255; - break; - case SDL_COPY_ADD: - dstR = srcR + dstR; if (dstR > 255) dstR = 255; - dstG = srcG + dstG; if (dstG > 255) dstG = 255; - dstB = srcB + dstB; if (dstB > 255) dstB = 255; - break; - case SDL_COPY_MOD: - dstR = (srcR * dstR) / 255; - dstG = (srcG * dstG) / 255; - dstB = (srcB * dstB) / 255; - break; - } - dstpixel = ((Uint32)dstA << 24) | ((Uint32)dstR << 16) | ((Uint32)dstG << 8) | dstB; - *dst = dstpixel; - ++src; - ++dst; - } - info->src += info->src_pitch; - info->dst += info->dst_pitch; - } -} - -static void SDL_Blit_ABGR8888_ARGB8888_Modulate_Blend_Scale(SDL_BlitInfo *info) -{ - const int flags = info->flags; - const Uint32 modulateR = info->r; - const Uint32 modulateG = info->g; - const Uint32 modulateB = info->b; - const Uint32 modulateA = info->a; - Uint32 srcpixel; - Uint32 srcR, srcG, srcB, srcA; - Uint32 dstpixel; - Uint32 dstR, dstG, dstB, dstA; - int srcy, srcx; - int posy, posx; - int incy, incx; - - srcy = 0; - posy = 0; - incy = (info->src_h << 16) / info->dst_h; - incx = (info->src_w << 16) / info->dst_w; - - while (info->dst_h--) { - Uint32 *src = 0; - Uint32 *dst = (Uint32 *)info->dst; - int n = info->dst_w; - srcx = -1; - posx = 0x10000L; - while (posy >= 0x10000L) { - ++srcy; - posy -= 0x10000L; - } - while (n--) { - if (posx >= 0x10000L) { - while (posx >= 0x10000L) { - ++srcx; - posx -= 0x10000L; - } - src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4)); - } - srcpixel = *src; - srcA = (Uint8)(srcpixel >> 24); srcB = (Uint8)(srcpixel >> 16); srcG = (Uint8)(srcpixel >> 8); srcR = (Uint8)srcpixel; - dstpixel = *dst; - dstA = (Uint8)(dstpixel >> 24); dstR = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstB = (Uint8)dstpixel; - if (flags & SDL_COPY_MODULATE_COLOR) { - srcR = (srcR * modulateR) / 255; - srcG = (srcG * modulateG) / 255; - srcB = (srcB * modulateB) / 255; - } - if (flags & SDL_COPY_MODULATE_ALPHA) { - srcA = (srcA * modulateA) / 255; - } - if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) { - /* This goes away if we ever use premultiplied alpha */ - if (srcA < 255) { - srcR = (srcR * srcA) / 255; - srcG = (srcG * srcA) / 255; - srcB = (srcB * srcA) / 255; - } - } - switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) { - case SDL_COPY_BLEND: - dstR = srcR + ((255 - srcA) * dstR) / 255; - dstG = srcG + ((255 - srcA) * dstG) / 255; - dstB = srcB + ((255 - srcA) * dstB) / 255; - break; - case SDL_COPY_ADD: - dstR = srcR + dstR; if (dstR > 255) dstR = 255; - dstG = srcG + dstG; if (dstG > 255) dstG = 255; - dstB = srcB + dstB; if (dstB > 255) dstB = 255; - break; - case SDL_COPY_MOD: - dstR = (srcR * dstR) / 255; - dstG = (srcG * dstG) / 255; - dstB = (srcB * dstB) / 255; - break; - } - dstpixel = ((Uint32)dstA << 24) | ((Uint32)dstR << 16) | ((Uint32)dstG << 8) | dstB; - *dst = dstpixel; - posx += incx; - ++dst; - } - posy += incy; - info->dst += info->dst_pitch; - } -} - -static void SDL_Blit_BGRA8888_RGB888_Scale(SDL_BlitInfo *info) -{ - Uint32 pixel; - Uint32 R, G, B, A; - int srcy, srcx; - int posy, posx; - int incy, incx; - - srcy = 0; - posy = 0; - incy = (info->src_h << 16) / info->dst_h; - incx = (info->src_w << 16) / info->dst_w; - - while (info->dst_h--) { - Uint32 *src = 0; - Uint32 *dst = (Uint32 *)info->dst; - int n = info->dst_w; - srcx = -1; - posx = 0x10000L; - while (posy >= 0x10000L) { - ++srcy; - posy -= 0x10000L; - } - while (n--) { - if (posx >= 0x10000L) { - while (posx >= 0x10000L) { - ++srcx; - posx -= 0x10000L; - } - src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4)); - } - pixel = *src; - B = (Uint8)(pixel >> 24); G = (Uint8)(pixel >> 16); R = (Uint8)(pixel >> 8); A = (Uint8)pixel; - pixel = ((Uint32)R << 16) | ((Uint32)G << 8) | B; - *dst = pixel; - posx += incx; - ++dst; - } - posy += incy; - info->dst += info->dst_pitch; - } -} - -static void SDL_Blit_BGRA8888_RGB888_Blend(SDL_BlitInfo *info) -{ - const int flags = info->flags; - Uint32 srcpixel; - Uint32 srcR, srcG, srcB, srcA; - Uint32 dstpixel; - Uint32 dstR, dstG, dstB, dstA; - - while (info->dst_h--) { - Uint32 *src = (Uint32 *)info->src; - Uint32 *dst = (Uint32 *)info->dst; - int n = info->dst_w; - while (n--) { - srcpixel = *src; - srcB = (Uint8)(srcpixel >> 24); srcG = (Uint8)(srcpixel >> 16); srcR = (Uint8)(srcpixel >> 8); srcA = (Uint8)srcpixel; - dstpixel = *dst; - dstR = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstB = (Uint8)dstpixel; dstA = 0xFF; - if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) { - /* This goes away if we ever use premultiplied alpha */ - if (srcA < 255) { - srcR = (srcR * srcA) / 255; - srcG = (srcG * srcA) / 255; - srcB = (srcB * srcA) / 255; - } - } - switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) { - case SDL_COPY_BLEND: - dstR = srcR + ((255 - srcA) * dstR) / 255; - dstG = srcG + ((255 - srcA) * dstG) / 255; - dstB = srcB + ((255 - srcA) * dstB) / 255; - break; - case SDL_COPY_ADD: - dstR = srcR + dstR; if (dstR > 255) dstR = 255; - dstG = srcG + dstG; if (dstG > 255) dstG = 255; - dstB = srcB + dstB; if (dstB > 255) dstB = 255; - break; - case SDL_COPY_MOD: - dstR = (srcR * dstR) / 255; - dstG = (srcG * dstG) / 255; - dstB = (srcB * dstB) / 255; - break; - } - dstpixel = ((Uint32)dstR << 16) | ((Uint32)dstG << 8) | dstB; - *dst = dstpixel; - ++src; - ++dst; - } - info->src += info->src_pitch; - info->dst += info->dst_pitch; - } -} - -static void SDL_Blit_BGRA8888_RGB888_Blend_Scale(SDL_BlitInfo *info) -{ - const int flags = info->flags; - Uint32 srcpixel; - Uint32 srcR, srcG, srcB, srcA; - Uint32 dstpixel; - Uint32 dstR, dstG, dstB, dstA; - int srcy, srcx; - int posy, posx; - int incy, incx; - - srcy = 0; - posy = 0; - incy = (info->src_h << 16) / info->dst_h; - incx = (info->src_w << 16) / info->dst_w; - - while (info->dst_h--) { - Uint32 *src = 0; - Uint32 *dst = (Uint32 *)info->dst; - int n = info->dst_w; - srcx = -1; - posx = 0x10000L; - while (posy >= 0x10000L) { - ++srcy; - posy -= 0x10000L; - } - while (n--) { - if (posx >= 0x10000L) { - while (posx >= 0x10000L) { - ++srcx; - posx -= 0x10000L; - } - src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4)); - } - srcpixel = *src; - srcB = (Uint8)(srcpixel >> 24); srcG = (Uint8)(srcpixel >> 16); srcR = (Uint8)(srcpixel >> 8); srcA = (Uint8)srcpixel; - dstpixel = *dst; - dstR = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstB = (Uint8)dstpixel; dstA = 0xFF; - if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) { - /* This goes away if we ever use premultiplied alpha */ - if (srcA < 255) { - srcR = (srcR * srcA) / 255; - srcG = (srcG * srcA) / 255; - srcB = (srcB * srcA) / 255; - } - } - switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) { - case SDL_COPY_BLEND: - dstR = srcR + ((255 - srcA) * dstR) / 255; - dstG = srcG + ((255 - srcA) * dstG) / 255; - dstB = srcB + ((255 - srcA) * dstB) / 255; - break; - case SDL_COPY_ADD: - dstR = srcR + dstR; if (dstR > 255) dstR = 255; - dstG = srcG + dstG; if (dstG > 255) dstG = 255; - dstB = srcB + dstB; if (dstB > 255) dstB = 255; - break; - case SDL_COPY_MOD: - dstR = (srcR * dstR) / 255; - dstG = (srcG * dstG) / 255; - dstB = (srcB * dstB) / 255; - break; - } - dstpixel = ((Uint32)dstR << 16) | ((Uint32)dstG << 8) | dstB; - *dst = dstpixel; - posx += incx; - ++dst; - } - posy += incy; - info->dst += info->dst_pitch; - } -} - -static void SDL_Blit_BGRA8888_RGB888_Modulate(SDL_BlitInfo *info) -{ - const int flags = info->flags; - const Uint32 modulateR = info->r; - const Uint32 modulateG = info->g; - const Uint32 modulateB = info->b; - const Uint32 modulateA = info->a; - Uint32 pixel; - Uint32 R, G, B, A; - - while (info->dst_h--) { - Uint32 *src = (Uint32 *)info->src; - Uint32 *dst = (Uint32 *)info->dst; - int n = info->dst_w; - while (n--) { - pixel = *src; - B = (Uint8)(pixel >> 24); G = (Uint8)(pixel >> 16); R = (Uint8)(pixel >> 8); A = (Uint8)pixel; - if (flags & SDL_COPY_MODULATE_COLOR) { - R = (R * modulateR) / 255; - G = (G * modulateG) / 255; - B = (B * modulateB) / 255; - } - if (flags & SDL_COPY_MODULATE_ALPHA) { - A = (A * modulateA) / 255; - } - pixel = ((Uint32)R << 16) | ((Uint32)G << 8) | B; - *dst = pixel; - ++src; - ++dst; - } - info->src += info->src_pitch; - info->dst += info->dst_pitch; - } -} - -static void SDL_Blit_BGRA8888_RGB888_Modulate_Scale(SDL_BlitInfo *info) -{ - const int flags = info->flags; - const Uint32 modulateR = info->r; - const Uint32 modulateG = info->g; - const Uint32 modulateB = info->b; - const Uint32 modulateA = info->a; - Uint32 pixel; - Uint32 R, G, B, A; - int srcy, srcx; - int posy, posx; - int incy, incx; - - srcy = 0; - posy = 0; - incy = (info->src_h << 16) / info->dst_h; - incx = (info->src_w << 16) / info->dst_w; - - while (info->dst_h--) { - Uint32 *src = 0; - Uint32 *dst = (Uint32 *)info->dst; - int n = info->dst_w; - srcx = -1; - posx = 0x10000L; - while (posy >= 0x10000L) { - ++srcy; - posy -= 0x10000L; - } - while (n--) { - if (posx >= 0x10000L) { - while (posx >= 0x10000L) { - ++srcx; - posx -= 0x10000L; - } - src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4)); - } - pixel = *src; - B = (Uint8)(pixel >> 24); G = (Uint8)(pixel >> 16); R = (Uint8)(pixel >> 8); A = (Uint8)pixel; - if (flags & SDL_COPY_MODULATE_COLOR) { - R = (R * modulateR) / 255; - G = (G * modulateG) / 255; - B = (B * modulateB) / 255; - } - if (flags & SDL_COPY_MODULATE_ALPHA) { - A = (A * modulateA) / 255; - } - pixel = ((Uint32)R << 16) | ((Uint32)G << 8) | B; - *dst = pixel; - posx += incx; - ++dst; - } - posy += incy; - info->dst += info->dst_pitch; - } -} - -static void SDL_Blit_BGRA8888_RGB888_Modulate_Blend(SDL_BlitInfo *info) -{ - const int flags = info->flags; - const Uint32 modulateR = info->r; - const Uint32 modulateG = info->g; - const Uint32 modulateB = info->b; - const Uint32 modulateA = info->a; - Uint32 srcpixel; - Uint32 srcR, srcG, srcB, srcA; - Uint32 dstpixel; - Uint32 dstR, dstG, dstB, dstA; - - while (info->dst_h--) { - Uint32 *src = (Uint32 *)info->src; - Uint32 *dst = (Uint32 *)info->dst; - int n = info->dst_w; - while (n--) { - srcpixel = *src; - srcB = (Uint8)(srcpixel >> 24); srcG = (Uint8)(srcpixel >> 16); srcR = (Uint8)(srcpixel >> 8); srcA = (Uint8)srcpixel; - dstpixel = *dst; - dstR = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstB = (Uint8)dstpixel; dstA = 0xFF; - if (flags & SDL_COPY_MODULATE_COLOR) { - srcR = (srcR * modulateR) / 255; - srcG = (srcG * modulateG) / 255; - srcB = (srcB * modulateB) / 255; - } - if (flags & SDL_COPY_MODULATE_ALPHA) { - srcA = (srcA * modulateA) / 255; - } - if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) { - /* This goes away if we ever use premultiplied alpha */ - if (srcA < 255) { - srcR = (srcR * srcA) / 255; - srcG = (srcG * srcA) / 255; - srcB = (srcB * srcA) / 255; - } - } - switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) { - case SDL_COPY_BLEND: - dstR = srcR + ((255 - srcA) * dstR) / 255; - dstG = srcG + ((255 - srcA) * dstG) / 255; - dstB = srcB + ((255 - srcA) * dstB) / 255; - break; - case SDL_COPY_ADD: - dstR = srcR + dstR; if (dstR > 255) dstR = 255; - dstG = srcG + dstG; if (dstG > 255) dstG = 255; - dstB = srcB + dstB; if (dstB > 255) dstB = 255; - break; - case SDL_COPY_MOD: - dstR = (srcR * dstR) / 255; - dstG = (srcG * dstG) / 255; - dstB = (srcB * dstB) / 255; - break; - } - dstpixel = ((Uint32)dstR << 16) | ((Uint32)dstG << 8) | dstB; - *dst = dstpixel; - ++src; - ++dst; - } - info->src += info->src_pitch; - info->dst += info->dst_pitch; - } -} - -static void SDL_Blit_BGRA8888_RGB888_Modulate_Blend_Scale(SDL_BlitInfo *info) -{ - const int flags = info->flags; - const Uint32 modulateR = info->r; - const Uint32 modulateG = info->g; - const Uint32 modulateB = info->b; - const Uint32 modulateA = info->a; - Uint32 srcpixel; - Uint32 srcR, srcG, srcB, srcA; - Uint32 dstpixel; - Uint32 dstR, dstG, dstB, dstA; - int srcy, srcx; - int posy, posx; - int incy, incx; - - srcy = 0; - posy = 0; - incy = (info->src_h << 16) / info->dst_h; - incx = (info->src_w << 16) / info->dst_w; - - while (info->dst_h--) { - Uint32 *src = 0; - Uint32 *dst = (Uint32 *)info->dst; - int n = info->dst_w; - srcx = -1; - posx = 0x10000L; - while (posy >= 0x10000L) { - ++srcy; - posy -= 0x10000L; - } - while (n--) { - if (posx >= 0x10000L) { - while (posx >= 0x10000L) { - ++srcx; - posx -= 0x10000L; - } - src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4)); - } - srcpixel = *src; - srcB = (Uint8)(srcpixel >> 24); srcG = (Uint8)(srcpixel >> 16); srcR = (Uint8)(srcpixel >> 8); srcA = (Uint8)srcpixel; - dstpixel = *dst; - dstR = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstB = (Uint8)dstpixel; dstA = 0xFF; - if (flags & SDL_COPY_MODULATE_COLOR) { - srcR = (srcR * modulateR) / 255; - srcG = (srcG * modulateG) / 255; - srcB = (srcB * modulateB) / 255; - } - if (flags & SDL_COPY_MODULATE_ALPHA) { - srcA = (srcA * modulateA) / 255; - } - if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) { - /* This goes away if we ever use premultiplied alpha */ - if (srcA < 255) { - srcR = (srcR * srcA) / 255; - srcG = (srcG * srcA) / 255; - srcB = (srcB * srcA) / 255; - } - } - switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) { - case SDL_COPY_BLEND: - dstR = srcR + ((255 - srcA) * dstR) / 255; - dstG = srcG + ((255 - srcA) * dstG) / 255; - dstB = srcB + ((255 - srcA) * dstB) / 255; - break; - case SDL_COPY_ADD: - dstR = srcR + dstR; if (dstR > 255) dstR = 255; - dstG = srcG + dstG; if (dstG > 255) dstG = 255; - dstB = srcB + dstB; if (dstB > 255) dstB = 255; - break; - case SDL_COPY_MOD: - dstR = (srcR * dstR) / 255; - dstG = (srcG * dstG) / 255; - dstB = (srcB * dstB) / 255; - break; - } - dstpixel = ((Uint32)dstR << 16) | ((Uint32)dstG << 8) | dstB; - *dst = dstpixel; - posx += incx; - ++dst; - } - posy += incy; - info->dst += info->dst_pitch; - } -} - -static void SDL_Blit_BGRA8888_BGR888_Scale(SDL_BlitInfo *info) -{ - Uint32 pixel; - Uint32 R, G, B, A; - int srcy, srcx; - int posy, posx; - int incy, incx; - - srcy = 0; - posy = 0; - incy = (info->src_h << 16) / info->dst_h; - incx = (info->src_w << 16) / info->dst_w; - - while (info->dst_h--) { - Uint32 *src = 0; - Uint32 *dst = (Uint32 *)info->dst; - int n = info->dst_w; - srcx = -1; - posx = 0x10000L; - while (posy >= 0x10000L) { - ++srcy; - posy -= 0x10000L; - } - while (n--) { - if (posx >= 0x10000L) { - while (posx >= 0x10000L) { - ++srcx; - posx -= 0x10000L; - } - src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4)); - } - pixel = *src; - B = (Uint8)(pixel >> 24); G = (Uint8)(pixel >> 16); R = (Uint8)(pixel >> 8); A = (Uint8)pixel; - pixel = ((Uint32)B << 16) | ((Uint32)G << 8) | R; - *dst = pixel; - posx += incx; - ++dst; - } - posy += incy; - info->dst += info->dst_pitch; - } -} - -static void SDL_Blit_BGRA8888_BGR888_Blend(SDL_BlitInfo *info) -{ - const int flags = info->flags; - Uint32 srcpixel; - Uint32 srcR, srcG, srcB, srcA; - Uint32 dstpixel; - Uint32 dstR, dstG, dstB, dstA; - - while (info->dst_h--) { - Uint32 *src = (Uint32 *)info->src; - Uint32 *dst = (Uint32 *)info->dst; - int n = info->dst_w; - while (n--) { - srcpixel = *src; - srcB = (Uint8)(srcpixel >> 24); srcG = (Uint8)(srcpixel >> 16); srcR = (Uint8)(srcpixel >> 8); srcA = (Uint8)srcpixel; - dstpixel = *dst; - dstB = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstR = (Uint8)dstpixel; dstA = 0xFF; - if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) { - /* This goes away if we ever use premultiplied alpha */ - if (srcA < 255) { - srcR = (srcR * srcA) / 255; - srcG = (srcG * srcA) / 255; - srcB = (srcB * srcA) / 255; - } - } - switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) { - case SDL_COPY_BLEND: - dstR = srcR + ((255 - srcA) * dstR) / 255; - dstG = srcG + ((255 - srcA) * dstG) / 255; - dstB = srcB + ((255 - srcA) * dstB) / 255; - break; - case SDL_COPY_ADD: - dstR = srcR + dstR; if (dstR > 255) dstR = 255; - dstG = srcG + dstG; if (dstG > 255) dstG = 255; - dstB = srcB + dstB; if (dstB > 255) dstB = 255; - break; - case SDL_COPY_MOD: - dstR = (srcR * dstR) / 255; - dstG = (srcG * dstG) / 255; - dstB = (srcB * dstB) / 255; - break; - } - dstpixel = ((Uint32)dstB << 16) | ((Uint32)dstG << 8) | dstR; - *dst = dstpixel; - ++src; - ++dst; - } - info->src += info->src_pitch; - info->dst += info->dst_pitch; - } -} - -static void SDL_Blit_BGRA8888_BGR888_Blend_Scale(SDL_BlitInfo *info) -{ - const int flags = info->flags; - Uint32 srcpixel; - Uint32 srcR, srcG, srcB, srcA; - Uint32 dstpixel; - Uint32 dstR, dstG, dstB, dstA; - int srcy, srcx; - int posy, posx; - int incy, incx; - - srcy = 0; - posy = 0; - incy = (info->src_h << 16) / info->dst_h; - incx = (info->src_w << 16) / info->dst_w; - - while (info->dst_h--) { - Uint32 *src = 0; - Uint32 *dst = (Uint32 *)info->dst; - int n = info->dst_w; - srcx = -1; - posx = 0x10000L; - while (posy >= 0x10000L) { - ++srcy; - posy -= 0x10000L; - } - while (n--) { - if (posx >= 0x10000L) { - while (posx >= 0x10000L) { - ++srcx; - posx -= 0x10000L; - } - src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4)); - } - srcpixel = *src; - srcB = (Uint8)(srcpixel >> 24); srcG = (Uint8)(srcpixel >> 16); srcR = (Uint8)(srcpixel >> 8); srcA = (Uint8)srcpixel; - dstpixel = *dst; - dstB = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstR = (Uint8)dstpixel; dstA = 0xFF; - if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) { - /* This goes away if we ever use premultiplied alpha */ - if (srcA < 255) { - srcR = (srcR * srcA) / 255; - srcG = (srcG * srcA) / 255; - srcB = (srcB * srcA) / 255; - } - } - switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) { - case SDL_COPY_BLEND: - dstR = srcR + ((255 - srcA) * dstR) / 255; - dstG = srcG + ((255 - srcA) * dstG) / 255; - dstB = srcB + ((255 - srcA) * dstB) / 255; - break; - case SDL_COPY_ADD: - dstR = srcR + dstR; if (dstR > 255) dstR = 255; - dstG = srcG + dstG; if (dstG > 255) dstG = 255; - dstB = srcB + dstB; if (dstB > 255) dstB = 255; - break; - case SDL_COPY_MOD: - dstR = (srcR * dstR) / 255; - dstG = (srcG * dstG) / 255; - dstB = (srcB * dstB) / 255; - break; - } - dstpixel = ((Uint32)dstB << 16) | ((Uint32)dstG << 8) | dstR; - *dst = dstpixel; - posx += incx; - ++dst; - } - posy += incy; - info->dst += info->dst_pitch; - } -} - -static void SDL_Blit_BGRA8888_BGR888_Modulate(SDL_BlitInfo *info) -{ - const int flags = info->flags; - const Uint32 modulateR = info->r; - const Uint32 modulateG = info->g; - const Uint32 modulateB = info->b; - const Uint32 modulateA = info->a; - Uint32 pixel; - Uint32 R, G, B, A; - - while (info->dst_h--) { - Uint32 *src = (Uint32 *)info->src; - Uint32 *dst = (Uint32 *)info->dst; - int n = info->dst_w; - while (n--) { - pixel = *src; - B = (Uint8)(pixel >> 24); G = (Uint8)(pixel >> 16); R = (Uint8)(pixel >> 8); A = (Uint8)pixel; - if (flags & SDL_COPY_MODULATE_COLOR) { - R = (R * modulateR) / 255; - G = (G * modulateG) / 255; - B = (B * modulateB) / 255; - } - if (flags & SDL_COPY_MODULATE_ALPHA) { - A = (A * modulateA) / 255; - } - pixel = ((Uint32)B << 16) | ((Uint32)G << 8) | R; - *dst = pixel; - ++src; - ++dst; - } - info->src += info->src_pitch; - info->dst += info->dst_pitch; - } -} - -static void SDL_Blit_BGRA8888_BGR888_Modulate_Scale(SDL_BlitInfo *info) -{ - const int flags = info->flags; - const Uint32 modulateR = info->r; - const Uint32 modulateG = info->g; - const Uint32 modulateB = info->b; - const Uint32 modulateA = info->a; - Uint32 pixel; - Uint32 R, G, B, A; - int srcy, srcx; - int posy, posx; - int incy, incx; - - srcy = 0; - posy = 0; - incy = (info->src_h << 16) / info->dst_h; - incx = (info->src_w << 16) / info->dst_w; - - while (info->dst_h--) { - Uint32 *src = 0; - Uint32 *dst = (Uint32 *)info->dst; - int n = info->dst_w; - srcx = -1; - posx = 0x10000L; - while (posy >= 0x10000L) { - ++srcy; - posy -= 0x10000L; - } - while (n--) { - if (posx >= 0x10000L) { - while (posx >= 0x10000L) { - ++srcx; - posx -= 0x10000L; - } - src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4)); - } - pixel = *src; - B = (Uint8)(pixel >> 24); G = (Uint8)(pixel >> 16); R = (Uint8)(pixel >> 8); A = (Uint8)pixel; - if (flags & SDL_COPY_MODULATE_COLOR) { - R = (R * modulateR) / 255; - G = (G * modulateG) / 255; - B = (B * modulateB) / 255; - } - if (flags & SDL_COPY_MODULATE_ALPHA) { - A = (A * modulateA) / 255; - } - pixel = ((Uint32)B << 16) | ((Uint32)G << 8) | R; - *dst = pixel; - posx += incx; - ++dst; - } - posy += incy; - info->dst += info->dst_pitch; - } -} - -static void SDL_Blit_BGRA8888_BGR888_Modulate_Blend(SDL_BlitInfo *info) -{ - const int flags = info->flags; - const Uint32 modulateR = info->r; - const Uint32 modulateG = info->g; - const Uint32 modulateB = info->b; - const Uint32 modulateA = info->a; - Uint32 srcpixel; - Uint32 srcR, srcG, srcB, srcA; - Uint32 dstpixel; - Uint32 dstR, dstG, dstB, dstA; - - while (info->dst_h--) { - Uint32 *src = (Uint32 *)info->src; - Uint32 *dst = (Uint32 *)info->dst; - int n = info->dst_w; - while (n--) { - srcpixel = *src; - srcB = (Uint8)(srcpixel >> 24); srcG = (Uint8)(srcpixel >> 16); srcR = (Uint8)(srcpixel >> 8); srcA = (Uint8)srcpixel; - dstpixel = *dst; - dstB = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstR = (Uint8)dstpixel; dstA = 0xFF; - if (flags & SDL_COPY_MODULATE_COLOR) { - srcR = (srcR * modulateR) / 255; - srcG = (srcG * modulateG) / 255; - srcB = (srcB * modulateB) / 255; - } - if (flags & SDL_COPY_MODULATE_ALPHA) { - srcA = (srcA * modulateA) / 255; - } - if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) { - /* This goes away if we ever use premultiplied alpha */ - if (srcA < 255) { - srcR = (srcR * srcA) / 255; - srcG = (srcG * srcA) / 255; - srcB = (srcB * srcA) / 255; - } - } - switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) { - case SDL_COPY_BLEND: - dstR = srcR + ((255 - srcA) * dstR) / 255; - dstG = srcG + ((255 - srcA) * dstG) / 255; - dstB = srcB + ((255 - srcA) * dstB) / 255; - break; - case SDL_COPY_ADD: - dstR = srcR + dstR; if (dstR > 255) dstR = 255; - dstG = srcG + dstG; if (dstG > 255) dstG = 255; - dstB = srcB + dstB; if (dstB > 255) dstB = 255; - break; - case SDL_COPY_MOD: - dstR = (srcR * dstR) / 255; - dstG = (srcG * dstG) / 255; - dstB = (srcB * dstB) / 255; - break; - } - dstpixel = ((Uint32)dstB << 16) | ((Uint32)dstG << 8) | dstR; - *dst = dstpixel; - ++src; - ++dst; - } - info->src += info->src_pitch; - info->dst += info->dst_pitch; - } -} - -static void SDL_Blit_BGRA8888_BGR888_Modulate_Blend_Scale(SDL_BlitInfo *info) -{ - const int flags = info->flags; - const Uint32 modulateR = info->r; - const Uint32 modulateG = info->g; - const Uint32 modulateB = info->b; - const Uint32 modulateA = info->a; - Uint32 srcpixel; - Uint32 srcR, srcG, srcB, srcA; - Uint32 dstpixel; - Uint32 dstR, dstG, dstB, dstA; - int srcy, srcx; - int posy, posx; - int incy, incx; - - srcy = 0; - posy = 0; - incy = (info->src_h << 16) / info->dst_h; - incx = (info->src_w << 16) / info->dst_w; - - while (info->dst_h--) { - Uint32 *src = 0; - Uint32 *dst = (Uint32 *)info->dst; - int n = info->dst_w; - srcx = -1; - posx = 0x10000L; - while (posy >= 0x10000L) { - ++srcy; - posy -= 0x10000L; - } - while (n--) { - if (posx >= 0x10000L) { - while (posx >= 0x10000L) { - ++srcx; - posx -= 0x10000L; - } - src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4)); - } - srcpixel = *src; - srcB = (Uint8)(srcpixel >> 24); srcG = (Uint8)(srcpixel >> 16); srcR = (Uint8)(srcpixel >> 8); srcA = (Uint8)srcpixel; - dstpixel = *dst; - dstB = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstR = (Uint8)dstpixel; dstA = 0xFF; - if (flags & SDL_COPY_MODULATE_COLOR) { - srcR = (srcR * modulateR) / 255; - srcG = (srcG * modulateG) / 255; - srcB = (srcB * modulateB) / 255; - } - if (flags & SDL_COPY_MODULATE_ALPHA) { - srcA = (srcA * modulateA) / 255; - } - if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) { - /* This goes away if we ever use premultiplied alpha */ - if (srcA < 255) { - srcR = (srcR * srcA) / 255; - srcG = (srcG * srcA) / 255; - srcB = (srcB * srcA) / 255; - } - } - switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) { - case SDL_COPY_BLEND: - dstR = srcR + ((255 - srcA) * dstR) / 255; - dstG = srcG + ((255 - srcA) * dstG) / 255; - dstB = srcB + ((255 - srcA) * dstB) / 255; - break; - case SDL_COPY_ADD: - dstR = srcR + dstR; if (dstR > 255) dstR = 255; - dstG = srcG + dstG; if (dstG > 255) dstG = 255; - dstB = srcB + dstB; if (dstB > 255) dstB = 255; - break; - case SDL_COPY_MOD: - dstR = (srcR * dstR) / 255; - dstG = (srcG * dstG) / 255; - dstB = (srcB * dstB) / 255; - break; - } - dstpixel = ((Uint32)dstB << 16) | ((Uint32)dstG << 8) | dstR; - *dst = dstpixel; - posx += incx; - ++dst; - } - posy += incy; - info->dst += info->dst_pitch; - } -} - -static void SDL_Blit_BGRA8888_ARGB8888_Scale(SDL_BlitInfo *info) -{ - Uint32 pixel; - Uint32 R, G, B, A; - int srcy, srcx; - int posy, posx; - int incy, incx; - - srcy = 0; - posy = 0; - incy = (info->src_h << 16) / info->dst_h; - incx = (info->src_w << 16) / info->dst_w; - - while (info->dst_h--) { - Uint32 *src = 0; - Uint32 *dst = (Uint32 *)info->dst; - int n = info->dst_w; - srcx = -1; - posx = 0x10000L; - while (posy >= 0x10000L) { - ++srcy; - posy -= 0x10000L; - } - while (n--) { - if (posx >= 0x10000L) { - while (posx >= 0x10000L) { - ++srcx; - posx -= 0x10000L; - } - src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4)); - } - pixel = *src; - B = (Uint8)(pixel >> 24); G = (Uint8)(pixel >> 16); R = (Uint8)(pixel >> 8); A = (Uint8)pixel; - pixel = ((Uint32)A << 24) | ((Uint32)R << 16) | ((Uint32)G << 8) | B; - *dst = pixel; - posx += incx; - ++dst; - } - posy += incy; - info->dst += info->dst_pitch; - } -} - -static void SDL_Blit_BGRA8888_ARGB8888_Blend(SDL_BlitInfo *info) -{ - const int flags = info->flags; - Uint32 srcpixel; - Uint32 srcR, srcG, srcB, srcA; - Uint32 dstpixel; - Uint32 dstR, dstG, dstB, dstA; - - while (info->dst_h--) { - Uint32 *src = (Uint32 *)info->src; - Uint32 *dst = (Uint32 *)info->dst; - int n = info->dst_w; - while (n--) { - srcpixel = *src; - srcB = (Uint8)(srcpixel >> 24); srcG = (Uint8)(srcpixel >> 16); srcR = (Uint8)(srcpixel >> 8); srcA = (Uint8)srcpixel; - dstpixel = *dst; - dstA = (Uint8)(dstpixel >> 24); dstR = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstB = (Uint8)dstpixel; - if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) { - /* This goes away if we ever use premultiplied alpha */ - if (srcA < 255) { - srcR = (srcR * srcA) / 255; - srcG = (srcG * srcA) / 255; - srcB = (srcB * srcA) / 255; - } - } - switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) { - case SDL_COPY_BLEND: - dstR = srcR + ((255 - srcA) * dstR) / 255; - dstG = srcG + ((255 - srcA) * dstG) / 255; - dstB = srcB + ((255 - srcA) * dstB) / 255; - break; - case SDL_COPY_ADD: - dstR = srcR + dstR; if (dstR > 255) dstR = 255; - dstG = srcG + dstG; if (dstG > 255) dstG = 255; - dstB = srcB + dstB; if (dstB > 255) dstB = 255; - break; - case SDL_COPY_MOD: - dstR = (srcR * dstR) / 255; - dstG = (srcG * dstG) / 255; - dstB = (srcB * dstB) / 255; - break; - } - dstpixel = ((Uint32)dstA << 24) | ((Uint32)dstR << 16) | ((Uint32)dstG << 8) | dstB; - *dst = dstpixel; - ++src; - ++dst; - } - info->src += info->src_pitch; - info->dst += info->dst_pitch; - } -} - -static void SDL_Blit_BGRA8888_ARGB8888_Blend_Scale(SDL_BlitInfo *info) -{ - const int flags = info->flags; - Uint32 srcpixel; - Uint32 srcR, srcG, srcB, srcA; - Uint32 dstpixel; - Uint32 dstR, dstG, dstB, dstA; - int srcy, srcx; - int posy, posx; - int incy, incx; - - srcy = 0; - posy = 0; - incy = (info->src_h << 16) / info->dst_h; - incx = (info->src_w << 16) / info->dst_w; - - while (info->dst_h--) { - Uint32 *src = 0; - Uint32 *dst = (Uint32 *)info->dst; - int n = info->dst_w; - srcx = -1; - posx = 0x10000L; - while (posy >= 0x10000L) { - ++srcy; - posy -= 0x10000L; - } - while (n--) { - if (posx >= 0x10000L) { - while (posx >= 0x10000L) { - ++srcx; - posx -= 0x10000L; - } - src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4)); - } - srcpixel = *src; - srcB = (Uint8)(srcpixel >> 24); srcG = (Uint8)(srcpixel >> 16); srcR = (Uint8)(srcpixel >> 8); srcA = (Uint8)srcpixel; - dstpixel = *dst; - dstA = (Uint8)(dstpixel >> 24); dstR = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstB = (Uint8)dstpixel; - if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) { - /* This goes away if we ever use premultiplied alpha */ - if (srcA < 255) { - srcR = (srcR * srcA) / 255; - srcG = (srcG * srcA) / 255; - srcB = (srcB * srcA) / 255; - } - } - switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) { - case SDL_COPY_BLEND: - dstR = srcR + ((255 - srcA) * dstR) / 255; - dstG = srcG + ((255 - srcA) * dstG) / 255; - dstB = srcB + ((255 - srcA) * dstB) / 255; - break; - case SDL_COPY_ADD: - dstR = srcR + dstR; if (dstR > 255) dstR = 255; - dstG = srcG + dstG; if (dstG > 255) dstG = 255; - dstB = srcB + dstB; if (dstB > 255) dstB = 255; - break; - case SDL_COPY_MOD: - dstR = (srcR * dstR) / 255; - dstG = (srcG * dstG) / 255; - dstB = (srcB * dstB) / 255; - break; - } - dstpixel = ((Uint32)dstA << 24) | ((Uint32)dstR << 16) | ((Uint32)dstG << 8) | dstB; - *dst = dstpixel; - posx += incx; - ++dst; - } - posy += incy; - info->dst += info->dst_pitch; - } -} - -static void SDL_Blit_BGRA8888_ARGB8888_Modulate(SDL_BlitInfo *info) -{ - const int flags = info->flags; - const Uint32 modulateR = info->r; - const Uint32 modulateG = info->g; - const Uint32 modulateB = info->b; - const Uint32 modulateA = info->a; - Uint32 pixel; - Uint32 R, G, B, A; - - while (info->dst_h--) { - Uint32 *src = (Uint32 *)info->src; - Uint32 *dst = (Uint32 *)info->dst; - int n = info->dst_w; - while (n--) { - pixel = *src; - B = (Uint8)(pixel >> 24); G = (Uint8)(pixel >> 16); R = (Uint8)(pixel >> 8); A = (Uint8)pixel; - if (flags & SDL_COPY_MODULATE_COLOR) { - R = (R * modulateR) / 255; - G = (G * modulateG) / 255; - B = (B * modulateB) / 255; - } - if (flags & SDL_COPY_MODULATE_ALPHA) { - A = (A * modulateA) / 255; - } - pixel = ((Uint32)A << 24) | ((Uint32)R << 16) | ((Uint32)G << 8) | B; - *dst = pixel; - ++src; - ++dst; - } - info->src += info->src_pitch; - info->dst += info->dst_pitch; - } -} - -static void SDL_Blit_BGRA8888_ARGB8888_Modulate_Scale(SDL_BlitInfo *info) -{ - const int flags = info->flags; - const Uint32 modulateR = info->r; - const Uint32 modulateG = info->g; - const Uint32 modulateB = info->b; - const Uint32 modulateA = info->a; - Uint32 pixel; - Uint32 R, G, B, A; - int srcy, srcx; - int posy, posx; - int incy, incx; - - srcy = 0; - posy = 0; - incy = (info->src_h << 16) / info->dst_h; - incx = (info->src_w << 16) / info->dst_w; - - while (info->dst_h--) { - Uint32 *src = 0; - Uint32 *dst = (Uint32 *)info->dst; - int n = info->dst_w; - srcx = -1; - posx = 0x10000L; - while (posy >= 0x10000L) { - ++srcy; - posy -= 0x10000L; - } - while (n--) { - if (posx >= 0x10000L) { - while (posx >= 0x10000L) { - ++srcx; - posx -= 0x10000L; - } - src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4)); - } - pixel = *src; - B = (Uint8)(pixel >> 24); G = (Uint8)(pixel >> 16); R = (Uint8)(pixel >> 8); A = (Uint8)pixel; - if (flags & SDL_COPY_MODULATE_COLOR) { - R = (R * modulateR) / 255; - G = (G * modulateG) / 255; - B = (B * modulateB) / 255; - } - if (flags & SDL_COPY_MODULATE_ALPHA) { - A = (A * modulateA) / 255; - } - pixel = ((Uint32)A << 24) | ((Uint32)R << 16) | ((Uint32)G << 8) | B; - *dst = pixel; - posx += incx; - ++dst; - } - posy += incy; - info->dst += info->dst_pitch; - } -} - -static void SDL_Blit_BGRA8888_ARGB8888_Modulate_Blend(SDL_BlitInfo *info) -{ - const int flags = info->flags; - const Uint32 modulateR = info->r; - const Uint32 modulateG = info->g; - const Uint32 modulateB = info->b; - const Uint32 modulateA = info->a; - Uint32 srcpixel; - Uint32 srcR, srcG, srcB, srcA; - Uint32 dstpixel; - Uint32 dstR, dstG, dstB, dstA; - - while (info->dst_h--) { - Uint32 *src = (Uint32 *)info->src; - Uint32 *dst = (Uint32 *)info->dst; - int n = info->dst_w; - while (n--) { - srcpixel = *src; - srcB = (Uint8)(srcpixel >> 24); srcG = (Uint8)(srcpixel >> 16); srcR = (Uint8)(srcpixel >> 8); srcA = (Uint8)srcpixel; - dstpixel = *dst; - dstA = (Uint8)(dstpixel >> 24); dstR = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstB = (Uint8)dstpixel; - if (flags & SDL_COPY_MODULATE_COLOR) { - srcR = (srcR * modulateR) / 255; - srcG = (srcG * modulateG) / 255; - srcB = (srcB * modulateB) / 255; - } - if (flags & SDL_COPY_MODULATE_ALPHA) { - srcA = (srcA * modulateA) / 255; - } - if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) { - /* This goes away if we ever use premultiplied alpha */ - if (srcA < 255) { - srcR = (srcR * srcA) / 255; - srcG = (srcG * srcA) / 255; - srcB = (srcB * srcA) / 255; - } - } - switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) { - case SDL_COPY_BLEND: - dstR = srcR + ((255 - srcA) * dstR) / 255; - dstG = srcG + ((255 - srcA) * dstG) / 255; - dstB = srcB + ((255 - srcA) * dstB) / 255; - break; - case SDL_COPY_ADD: - dstR = srcR + dstR; if (dstR > 255) dstR = 255; - dstG = srcG + dstG; if (dstG > 255) dstG = 255; - dstB = srcB + dstB; if (dstB > 255) dstB = 255; - break; - case SDL_COPY_MOD: - dstR = (srcR * dstR) / 255; - dstG = (srcG * dstG) / 255; - dstB = (srcB * dstB) / 255; - break; - } - dstpixel = ((Uint32)dstA << 24) | ((Uint32)dstR << 16) | ((Uint32)dstG << 8) | dstB; - *dst = dstpixel; - ++src; - ++dst; - } - info->src += info->src_pitch; - info->dst += info->dst_pitch; - } -} - -static void SDL_Blit_BGRA8888_ARGB8888_Modulate_Blend_Scale(SDL_BlitInfo *info) -{ - const int flags = info->flags; - const Uint32 modulateR = info->r; - const Uint32 modulateG = info->g; - const Uint32 modulateB = info->b; - const Uint32 modulateA = info->a; - Uint32 srcpixel; - Uint32 srcR, srcG, srcB, srcA; - Uint32 dstpixel; - Uint32 dstR, dstG, dstB, dstA; - int srcy, srcx; - int posy, posx; - int incy, incx; - - srcy = 0; - posy = 0; - incy = (info->src_h << 16) / info->dst_h; - incx = (info->src_w << 16) / info->dst_w; - - while (info->dst_h--) { - Uint32 *src = 0; - Uint32 *dst = (Uint32 *)info->dst; - int n = info->dst_w; - srcx = -1; - posx = 0x10000L; - while (posy >= 0x10000L) { - ++srcy; - posy -= 0x10000L; - } - while (n--) { - if (posx >= 0x10000L) { - while (posx >= 0x10000L) { - ++srcx; - posx -= 0x10000L; - } - src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4)); - } - srcpixel = *src; - srcB = (Uint8)(srcpixel >> 24); srcG = (Uint8)(srcpixel >> 16); srcR = (Uint8)(srcpixel >> 8); srcA = (Uint8)srcpixel; - dstpixel = *dst; - dstA = (Uint8)(dstpixel >> 24); dstR = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstB = (Uint8)dstpixel; - if (flags & SDL_COPY_MODULATE_COLOR) { - srcR = (srcR * modulateR) / 255; - srcG = (srcG * modulateG) / 255; - srcB = (srcB * modulateB) / 255; - } - if (flags & SDL_COPY_MODULATE_ALPHA) { - srcA = (srcA * modulateA) / 255; - } - if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) { - /* This goes away if we ever use premultiplied alpha */ - if (srcA < 255) { - srcR = (srcR * srcA) / 255; - srcG = (srcG * srcA) / 255; - srcB = (srcB * srcA) / 255; - } - } - switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) { - case SDL_COPY_BLEND: - dstR = srcR + ((255 - srcA) * dstR) / 255; - dstG = srcG + ((255 - srcA) * dstG) / 255; - dstB = srcB + ((255 - srcA) * dstB) / 255; - break; - case SDL_COPY_ADD: - dstR = srcR + dstR; if (dstR > 255) dstR = 255; - dstG = srcG + dstG; if (dstG > 255) dstG = 255; - dstB = srcB + dstB; if (dstB > 255) dstB = 255; - break; - case SDL_COPY_MOD: - dstR = (srcR * dstR) / 255; - dstG = (srcG * dstG) / 255; - dstB = (srcB * dstB) / 255; - break; - } - dstpixel = ((Uint32)dstA << 24) | ((Uint32)dstR << 16) | ((Uint32)dstG << 8) | dstB; - *dst = dstpixel; - posx += incx; - ++dst; - } - posy += incy; - info->dst += info->dst_pitch; - } -} - -SDL_BlitFuncEntry SDL_GeneratedBlitFuncTable[] = { - { SDL_PIXELFORMAT_RGB888, SDL_PIXELFORMAT_RGB888, (SDL_COPY_NEAREST), SDL_CPU_ANY, SDL_Blit_RGB888_RGB888_Scale }, - { SDL_PIXELFORMAT_RGB888, SDL_PIXELFORMAT_RGB888, (SDL_COPY_BLEND | SDL_COPY_ADD | SDL_COPY_MOD), SDL_CPU_ANY, SDL_Blit_RGB888_RGB888_Blend }, - { SDL_PIXELFORMAT_RGB888, SDL_PIXELFORMAT_RGB888, (SDL_COPY_BLEND | SDL_COPY_ADD | SDL_COPY_MOD | SDL_COPY_NEAREST), SDL_CPU_ANY, SDL_Blit_RGB888_RGB888_Blend_Scale }, - { SDL_PIXELFORMAT_RGB888, SDL_PIXELFORMAT_RGB888, (SDL_COPY_MODULATE_COLOR | SDL_COPY_MODULATE_ALPHA), SDL_CPU_ANY, SDL_Blit_RGB888_RGB888_Modulate }, - { SDL_PIXELFORMAT_RGB888, SDL_PIXELFORMAT_RGB888, (SDL_COPY_MODULATE_COLOR | SDL_COPY_MODULATE_ALPHA | SDL_COPY_NEAREST), SDL_CPU_ANY, SDL_Blit_RGB888_RGB888_Modulate_Scale }, - { SDL_PIXELFORMAT_RGB888, SDL_PIXELFORMAT_RGB888, (SDL_COPY_MODULATE_COLOR | SDL_COPY_MODULATE_ALPHA | SDL_COPY_BLEND | SDL_COPY_ADD | SDL_COPY_MOD), SDL_CPU_ANY, SDL_Blit_RGB888_RGB888_Modulate_Blend }, - { SDL_PIXELFORMAT_RGB888, SDL_PIXELFORMAT_RGB888, (SDL_COPY_MODULATE_COLOR | SDL_COPY_MODULATE_ALPHA | SDL_COPY_BLEND | SDL_COPY_ADD | SDL_COPY_MOD | SDL_COPY_NEAREST), SDL_CPU_ANY, SDL_Blit_RGB888_RGB888_Modulate_Blend_Scale }, - { SDL_PIXELFORMAT_RGB888, SDL_PIXELFORMAT_BGR888, (SDL_COPY_NEAREST), SDL_CPU_ANY, SDL_Blit_RGB888_BGR888_Scale }, - { SDL_PIXELFORMAT_RGB888, SDL_PIXELFORMAT_BGR888, (SDL_COPY_BLEND | SDL_COPY_ADD | SDL_COPY_MOD), SDL_CPU_ANY, SDL_Blit_RGB888_BGR888_Blend }, - { SDL_PIXELFORMAT_RGB888, SDL_PIXELFORMAT_BGR888, (SDL_COPY_BLEND | SDL_COPY_ADD | SDL_COPY_MOD | SDL_COPY_NEAREST), SDL_CPU_ANY, SDL_Blit_RGB888_BGR888_Blend_Scale }, - { SDL_PIXELFORMAT_RGB888, SDL_PIXELFORMAT_BGR888, (SDL_COPY_MODULATE_COLOR | SDL_COPY_MODULATE_ALPHA), SDL_CPU_ANY, SDL_Blit_RGB888_BGR888_Modulate }, - { SDL_PIXELFORMAT_RGB888, SDL_PIXELFORMAT_BGR888, (SDL_COPY_MODULATE_COLOR | SDL_COPY_MODULATE_ALPHA | SDL_COPY_NEAREST), SDL_CPU_ANY, SDL_Blit_RGB888_BGR888_Modulate_Scale }, - { SDL_PIXELFORMAT_RGB888, SDL_PIXELFORMAT_BGR888, (SDL_COPY_MODULATE_COLOR | SDL_COPY_MODULATE_ALPHA | SDL_COPY_BLEND | SDL_COPY_ADD | SDL_COPY_MOD), SDL_CPU_ANY, SDL_Blit_RGB888_BGR888_Modulate_Blend }, - { SDL_PIXELFORMAT_RGB888, SDL_PIXELFORMAT_BGR888, (SDL_COPY_MODULATE_COLOR | SDL_COPY_MODULATE_ALPHA | SDL_COPY_BLEND | SDL_COPY_ADD | SDL_COPY_MOD | SDL_COPY_NEAREST), SDL_CPU_ANY, SDL_Blit_RGB888_BGR888_Modulate_Blend_Scale }, - { SDL_PIXELFORMAT_RGB888, SDL_PIXELFORMAT_ARGB8888, (SDL_COPY_NEAREST), SDL_CPU_ANY, SDL_Blit_RGB888_ARGB8888_Scale }, - { SDL_PIXELFORMAT_RGB888, SDL_PIXELFORMAT_ARGB8888, (SDL_COPY_BLEND | SDL_COPY_ADD | SDL_COPY_MOD), SDL_CPU_ANY, SDL_Blit_RGB888_ARGB8888_Blend }, - { SDL_PIXELFORMAT_RGB888, SDL_PIXELFORMAT_ARGB8888, (SDL_COPY_BLEND | SDL_COPY_ADD | SDL_COPY_MOD | SDL_COPY_NEAREST), SDL_CPU_ANY, SDL_Blit_RGB888_ARGB8888_Blend_Scale }, - { SDL_PIXELFORMAT_RGB888, SDL_PIXELFORMAT_ARGB8888, (SDL_COPY_MODULATE_COLOR | SDL_COPY_MODULATE_ALPHA), SDL_CPU_ANY, SDL_Blit_RGB888_ARGB8888_Modulate }, - { SDL_PIXELFORMAT_RGB888, SDL_PIXELFORMAT_ARGB8888, (SDL_COPY_MODULATE_COLOR | SDL_COPY_MODULATE_ALPHA | SDL_COPY_NEAREST), SDL_CPU_ANY, SDL_Blit_RGB888_ARGB8888_Modulate_Scale }, - { SDL_PIXELFORMAT_RGB888, SDL_PIXELFORMAT_ARGB8888, (SDL_COPY_MODULATE_COLOR | SDL_COPY_MODULATE_ALPHA | SDL_COPY_BLEND | SDL_COPY_ADD | SDL_COPY_MOD), SDL_CPU_ANY, SDL_Blit_RGB888_ARGB8888_Modulate_Blend }, - { SDL_PIXELFORMAT_RGB888, SDL_PIXELFORMAT_ARGB8888, (SDL_COPY_MODULATE_COLOR | SDL_COPY_MODULATE_ALPHA | SDL_COPY_BLEND | SDL_COPY_ADD | SDL_COPY_MOD | SDL_COPY_NEAREST), SDL_CPU_ANY, SDL_Blit_RGB888_ARGB8888_Modulate_Blend_Scale }, - { SDL_PIXELFORMAT_BGR888, SDL_PIXELFORMAT_RGB888, (SDL_COPY_NEAREST), SDL_CPU_ANY, SDL_Blit_BGR888_RGB888_Scale }, - { SDL_PIXELFORMAT_BGR888, SDL_PIXELFORMAT_RGB888, (SDL_COPY_BLEND | SDL_COPY_ADD | SDL_COPY_MOD), SDL_CPU_ANY, SDL_Blit_BGR888_RGB888_Blend }, - { SDL_PIXELFORMAT_BGR888, SDL_PIXELFORMAT_RGB888, (SDL_COPY_BLEND | SDL_COPY_ADD | SDL_COPY_MOD | SDL_COPY_NEAREST), SDL_CPU_ANY, SDL_Blit_BGR888_RGB888_Blend_Scale }, - { SDL_PIXELFORMAT_BGR888, SDL_PIXELFORMAT_RGB888, (SDL_COPY_MODULATE_COLOR | SDL_COPY_MODULATE_ALPHA), SDL_CPU_ANY, SDL_Blit_BGR888_RGB888_Modulate }, - { SDL_PIXELFORMAT_BGR888, SDL_PIXELFORMAT_RGB888, (SDL_COPY_MODULATE_COLOR | SDL_COPY_MODULATE_ALPHA | SDL_COPY_NEAREST), SDL_CPU_ANY, SDL_Blit_BGR888_RGB888_Modulate_Scale }, - { SDL_PIXELFORMAT_BGR888, SDL_PIXELFORMAT_RGB888, (SDL_COPY_MODULATE_COLOR | SDL_COPY_MODULATE_ALPHA | SDL_COPY_BLEND | SDL_COPY_ADD | SDL_COPY_MOD), SDL_CPU_ANY, SDL_Blit_BGR888_RGB888_Modulate_Blend }, - { SDL_PIXELFORMAT_BGR888, SDL_PIXELFORMAT_RGB888, (SDL_COPY_MODULATE_COLOR | SDL_COPY_MODULATE_ALPHA | SDL_COPY_BLEND | SDL_COPY_ADD | SDL_COPY_MOD | SDL_COPY_NEAREST), SDL_CPU_ANY, SDL_Blit_BGR888_RGB888_Modulate_Blend_Scale }, - { SDL_PIXELFORMAT_BGR888, SDL_PIXELFORMAT_BGR888, (SDL_COPY_NEAREST), SDL_CPU_ANY, SDL_Blit_BGR888_BGR888_Scale }, - { SDL_PIXELFORMAT_BGR888, SDL_PIXELFORMAT_BGR888, (SDL_COPY_BLEND | SDL_COPY_ADD | SDL_COPY_MOD), SDL_CPU_ANY, SDL_Blit_BGR888_BGR888_Blend }, - { SDL_PIXELFORMAT_BGR888, SDL_PIXELFORMAT_BGR888, (SDL_COPY_BLEND | SDL_COPY_ADD | SDL_COPY_MOD | SDL_COPY_NEAREST), SDL_CPU_ANY, SDL_Blit_BGR888_BGR888_Blend_Scale }, - { SDL_PIXELFORMAT_BGR888, SDL_PIXELFORMAT_BGR888, (SDL_COPY_MODULATE_COLOR | SDL_COPY_MODULATE_ALPHA), SDL_CPU_ANY, SDL_Blit_BGR888_BGR888_Modulate }, - { SDL_PIXELFORMAT_BGR888, SDL_PIXELFORMAT_BGR888, (SDL_COPY_MODULATE_COLOR | SDL_COPY_MODULATE_ALPHA | SDL_COPY_NEAREST), SDL_CPU_ANY, SDL_Blit_BGR888_BGR888_Modulate_Scale }, - { SDL_PIXELFORMAT_BGR888, SDL_PIXELFORMAT_BGR888, (SDL_COPY_MODULATE_COLOR | SDL_COPY_MODULATE_ALPHA | SDL_COPY_BLEND | SDL_COPY_ADD | SDL_COPY_MOD), SDL_CPU_ANY, SDL_Blit_BGR888_BGR888_Modulate_Blend }, - { SDL_PIXELFORMAT_BGR888, SDL_PIXELFORMAT_BGR888, (SDL_COPY_MODULATE_COLOR | SDL_COPY_MODULATE_ALPHA | SDL_COPY_BLEND | SDL_COPY_ADD | SDL_COPY_MOD | SDL_COPY_NEAREST), SDL_CPU_ANY, SDL_Blit_BGR888_BGR888_Modulate_Blend_Scale }, - { SDL_PIXELFORMAT_BGR888, SDL_PIXELFORMAT_ARGB8888, (SDL_COPY_NEAREST), SDL_CPU_ANY, SDL_Blit_BGR888_ARGB8888_Scale }, - { SDL_PIXELFORMAT_BGR888, SDL_PIXELFORMAT_ARGB8888, (SDL_COPY_BLEND | SDL_COPY_ADD | SDL_COPY_MOD), SDL_CPU_ANY, SDL_Blit_BGR888_ARGB8888_Blend }, - { SDL_PIXELFORMAT_BGR888, SDL_PIXELFORMAT_ARGB8888, (SDL_COPY_BLEND | SDL_COPY_ADD | SDL_COPY_MOD | SDL_COPY_NEAREST), SDL_CPU_ANY, SDL_Blit_BGR888_ARGB8888_Blend_Scale }, - { SDL_PIXELFORMAT_BGR888, SDL_PIXELFORMAT_ARGB8888, (SDL_COPY_MODULATE_COLOR | SDL_COPY_MODULATE_ALPHA), SDL_CPU_ANY, SDL_Blit_BGR888_ARGB8888_Modulate }, - { SDL_PIXELFORMAT_BGR888, SDL_PIXELFORMAT_ARGB8888, (SDL_COPY_MODULATE_COLOR | SDL_COPY_MODULATE_ALPHA | SDL_COPY_NEAREST), SDL_CPU_ANY, SDL_Blit_BGR888_ARGB8888_Modulate_Scale }, - { SDL_PIXELFORMAT_BGR888, SDL_PIXELFORMAT_ARGB8888, (SDL_COPY_MODULATE_COLOR | SDL_COPY_MODULATE_ALPHA | SDL_COPY_BLEND | SDL_COPY_ADD | SDL_COPY_MOD), SDL_CPU_ANY, SDL_Blit_BGR888_ARGB8888_Modulate_Blend }, - { SDL_PIXELFORMAT_BGR888, SDL_PIXELFORMAT_ARGB8888, (SDL_COPY_MODULATE_COLOR | SDL_COPY_MODULATE_ALPHA | SDL_COPY_BLEND | SDL_COPY_ADD | SDL_COPY_MOD | SDL_COPY_NEAREST), SDL_CPU_ANY, SDL_Blit_BGR888_ARGB8888_Modulate_Blend_Scale }, - { SDL_PIXELFORMAT_ARGB8888, SDL_PIXELFORMAT_RGB888, (SDL_COPY_NEAREST), SDL_CPU_ANY, SDL_Blit_ARGB8888_RGB888_Scale }, - { SDL_PIXELFORMAT_ARGB8888, SDL_PIXELFORMAT_RGB888, (SDL_COPY_BLEND | SDL_COPY_ADD | SDL_COPY_MOD), SDL_CPU_ANY, SDL_Blit_ARGB8888_RGB888_Blend }, - { SDL_PIXELFORMAT_ARGB8888, SDL_PIXELFORMAT_RGB888, (SDL_COPY_BLEND | SDL_COPY_ADD | SDL_COPY_MOD | SDL_COPY_NEAREST), SDL_CPU_ANY, SDL_Blit_ARGB8888_RGB888_Blend_Scale }, - { SDL_PIXELFORMAT_ARGB8888, SDL_PIXELFORMAT_RGB888, (SDL_COPY_MODULATE_COLOR | SDL_COPY_MODULATE_ALPHA), SDL_CPU_ANY, SDL_Blit_ARGB8888_RGB888_Modulate }, - { SDL_PIXELFORMAT_ARGB8888, SDL_PIXELFORMAT_RGB888, (SDL_COPY_MODULATE_COLOR | SDL_COPY_MODULATE_ALPHA | SDL_COPY_NEAREST), SDL_CPU_ANY, SDL_Blit_ARGB8888_RGB888_Modulate_Scale }, - { SDL_PIXELFORMAT_ARGB8888, SDL_PIXELFORMAT_RGB888, (SDL_COPY_MODULATE_COLOR | SDL_COPY_MODULATE_ALPHA | SDL_COPY_BLEND | SDL_COPY_ADD | SDL_COPY_MOD), SDL_CPU_ANY, SDL_Blit_ARGB8888_RGB888_Modulate_Blend }, - { SDL_PIXELFORMAT_ARGB8888, SDL_PIXELFORMAT_RGB888, (SDL_COPY_MODULATE_COLOR | SDL_COPY_MODULATE_ALPHA | SDL_COPY_BLEND | SDL_COPY_ADD | SDL_COPY_MOD | SDL_COPY_NEAREST), SDL_CPU_ANY, SDL_Blit_ARGB8888_RGB888_Modulate_Blend_Scale }, - { SDL_PIXELFORMAT_ARGB8888, SDL_PIXELFORMAT_BGR888, (SDL_COPY_NEAREST), SDL_CPU_ANY, SDL_Blit_ARGB8888_BGR888_Scale }, - { SDL_PIXELFORMAT_ARGB8888, SDL_PIXELFORMAT_BGR888, (SDL_COPY_BLEND | SDL_COPY_ADD | SDL_COPY_MOD), SDL_CPU_ANY, SDL_Blit_ARGB8888_BGR888_Blend }, - { SDL_PIXELFORMAT_ARGB8888, SDL_PIXELFORMAT_BGR888, (SDL_COPY_BLEND | SDL_COPY_ADD | SDL_COPY_MOD | SDL_COPY_NEAREST), SDL_CPU_ANY, SDL_Blit_ARGB8888_BGR888_Blend_Scale }, - { SDL_PIXELFORMAT_ARGB8888, SDL_PIXELFORMAT_BGR888, (SDL_COPY_MODULATE_COLOR | SDL_COPY_MODULATE_ALPHA), SDL_CPU_ANY, SDL_Blit_ARGB8888_BGR888_Modulate }, - { SDL_PIXELFORMAT_ARGB8888, SDL_PIXELFORMAT_BGR888, (SDL_COPY_MODULATE_COLOR | SDL_COPY_MODULATE_ALPHA | SDL_COPY_NEAREST), SDL_CPU_ANY, SDL_Blit_ARGB8888_BGR888_Modulate_Scale }, - { SDL_PIXELFORMAT_ARGB8888, SDL_PIXELFORMAT_BGR888, (SDL_COPY_MODULATE_COLOR | SDL_COPY_MODULATE_ALPHA | SDL_COPY_BLEND | SDL_COPY_ADD | SDL_COPY_MOD), SDL_CPU_ANY, SDL_Blit_ARGB8888_BGR888_Modulate_Blend }, - { SDL_PIXELFORMAT_ARGB8888, SDL_PIXELFORMAT_BGR888, (SDL_COPY_MODULATE_COLOR | SDL_COPY_MODULATE_ALPHA | SDL_COPY_BLEND | SDL_COPY_ADD | SDL_COPY_MOD | SDL_COPY_NEAREST), SDL_CPU_ANY, SDL_Blit_ARGB8888_BGR888_Modulate_Blend_Scale }, - { SDL_PIXELFORMAT_ARGB8888, SDL_PIXELFORMAT_ARGB8888, (SDL_COPY_NEAREST), SDL_CPU_ANY, SDL_Blit_ARGB8888_ARGB8888_Scale }, - { SDL_PIXELFORMAT_ARGB8888, SDL_PIXELFORMAT_ARGB8888, (SDL_COPY_BLEND | SDL_COPY_ADD | SDL_COPY_MOD), SDL_CPU_ANY, SDL_Blit_ARGB8888_ARGB8888_Blend }, - { SDL_PIXELFORMAT_ARGB8888, SDL_PIXELFORMAT_ARGB8888, (SDL_COPY_BLEND | SDL_COPY_ADD | SDL_COPY_MOD | SDL_COPY_NEAREST), SDL_CPU_ANY, SDL_Blit_ARGB8888_ARGB8888_Blend_Scale }, - { SDL_PIXELFORMAT_ARGB8888, SDL_PIXELFORMAT_ARGB8888, (SDL_COPY_MODULATE_COLOR | SDL_COPY_MODULATE_ALPHA), SDL_CPU_ANY, SDL_Blit_ARGB8888_ARGB8888_Modulate }, - { SDL_PIXELFORMAT_ARGB8888, SDL_PIXELFORMAT_ARGB8888, (SDL_COPY_MODULATE_COLOR | SDL_COPY_MODULATE_ALPHA | SDL_COPY_NEAREST), SDL_CPU_ANY, SDL_Blit_ARGB8888_ARGB8888_Modulate_Scale }, - { SDL_PIXELFORMAT_ARGB8888, SDL_PIXELFORMAT_ARGB8888, (SDL_COPY_MODULATE_COLOR | SDL_COPY_MODULATE_ALPHA | SDL_COPY_BLEND | SDL_COPY_ADD | SDL_COPY_MOD), SDL_CPU_ANY, SDL_Blit_ARGB8888_ARGB8888_Modulate_Blend }, - { SDL_PIXELFORMAT_ARGB8888, SDL_PIXELFORMAT_ARGB8888, (SDL_COPY_MODULATE_COLOR | SDL_COPY_MODULATE_ALPHA | SDL_COPY_BLEND | SDL_COPY_ADD | SDL_COPY_MOD | SDL_COPY_NEAREST), SDL_CPU_ANY, SDL_Blit_ARGB8888_ARGB8888_Modulate_Blend_Scale }, - { SDL_PIXELFORMAT_RGBA8888, SDL_PIXELFORMAT_RGB888, (SDL_COPY_NEAREST), SDL_CPU_ANY, SDL_Blit_RGBA8888_RGB888_Scale }, - { SDL_PIXELFORMAT_RGBA8888, SDL_PIXELFORMAT_RGB888, (SDL_COPY_BLEND | SDL_COPY_ADD | SDL_COPY_MOD), SDL_CPU_ANY, SDL_Blit_RGBA8888_RGB888_Blend }, - { SDL_PIXELFORMAT_RGBA8888, SDL_PIXELFORMAT_RGB888, (SDL_COPY_BLEND | SDL_COPY_ADD | SDL_COPY_MOD | SDL_COPY_NEAREST), SDL_CPU_ANY, SDL_Blit_RGBA8888_RGB888_Blend_Scale }, - { SDL_PIXELFORMAT_RGBA8888, SDL_PIXELFORMAT_RGB888, (SDL_COPY_MODULATE_COLOR | SDL_COPY_MODULATE_ALPHA), SDL_CPU_ANY, SDL_Blit_RGBA8888_RGB888_Modulate }, - { SDL_PIXELFORMAT_RGBA8888, SDL_PIXELFORMAT_RGB888, (SDL_COPY_MODULATE_COLOR | SDL_COPY_MODULATE_ALPHA | SDL_COPY_NEAREST), SDL_CPU_ANY, SDL_Blit_RGBA8888_RGB888_Modulate_Scale }, - { SDL_PIXELFORMAT_RGBA8888, SDL_PIXELFORMAT_RGB888, (SDL_COPY_MODULATE_COLOR | SDL_COPY_MODULATE_ALPHA | SDL_COPY_BLEND | SDL_COPY_ADD | SDL_COPY_MOD), SDL_CPU_ANY, SDL_Blit_RGBA8888_RGB888_Modulate_Blend }, - { SDL_PIXELFORMAT_RGBA8888, SDL_PIXELFORMAT_RGB888, (SDL_COPY_MODULATE_COLOR | SDL_COPY_MODULATE_ALPHA | SDL_COPY_BLEND | SDL_COPY_ADD | SDL_COPY_MOD | SDL_COPY_NEAREST), SDL_CPU_ANY, SDL_Blit_RGBA8888_RGB888_Modulate_Blend_Scale }, - { SDL_PIXELFORMAT_RGBA8888, SDL_PIXELFORMAT_BGR888, (SDL_COPY_NEAREST), SDL_CPU_ANY, SDL_Blit_RGBA8888_BGR888_Scale }, - { SDL_PIXELFORMAT_RGBA8888, SDL_PIXELFORMAT_BGR888, (SDL_COPY_BLEND | SDL_COPY_ADD | SDL_COPY_MOD), SDL_CPU_ANY, SDL_Blit_RGBA8888_BGR888_Blend }, - { SDL_PIXELFORMAT_RGBA8888, SDL_PIXELFORMAT_BGR888, (SDL_COPY_BLEND | SDL_COPY_ADD | SDL_COPY_MOD | SDL_COPY_NEAREST), SDL_CPU_ANY, SDL_Blit_RGBA8888_BGR888_Blend_Scale }, - { SDL_PIXELFORMAT_RGBA8888, SDL_PIXELFORMAT_BGR888, (SDL_COPY_MODULATE_COLOR | SDL_COPY_MODULATE_ALPHA), SDL_CPU_ANY, SDL_Blit_RGBA8888_BGR888_Modulate }, - { SDL_PIXELFORMAT_RGBA8888, SDL_PIXELFORMAT_BGR888, (SDL_COPY_MODULATE_COLOR | SDL_COPY_MODULATE_ALPHA | SDL_COPY_NEAREST), SDL_CPU_ANY, SDL_Blit_RGBA8888_BGR888_Modulate_Scale }, - { SDL_PIXELFORMAT_RGBA8888, SDL_PIXELFORMAT_BGR888, (SDL_COPY_MODULATE_COLOR | SDL_COPY_MODULATE_ALPHA | SDL_COPY_BLEND | SDL_COPY_ADD | SDL_COPY_MOD), SDL_CPU_ANY, SDL_Blit_RGBA8888_BGR888_Modulate_Blend }, - { SDL_PIXELFORMAT_RGBA8888, SDL_PIXELFORMAT_BGR888, (SDL_COPY_MODULATE_COLOR | SDL_COPY_MODULATE_ALPHA | SDL_COPY_BLEND | SDL_COPY_ADD | SDL_COPY_MOD | SDL_COPY_NEAREST), SDL_CPU_ANY, SDL_Blit_RGBA8888_BGR888_Modulate_Blend_Scale }, - { SDL_PIXELFORMAT_RGBA8888, SDL_PIXELFORMAT_ARGB8888, (SDL_COPY_NEAREST), SDL_CPU_ANY, SDL_Blit_RGBA8888_ARGB8888_Scale }, - { SDL_PIXELFORMAT_RGBA8888, SDL_PIXELFORMAT_ARGB8888, (SDL_COPY_BLEND | SDL_COPY_ADD | SDL_COPY_MOD), SDL_CPU_ANY, SDL_Blit_RGBA8888_ARGB8888_Blend }, - { SDL_PIXELFORMAT_RGBA8888, SDL_PIXELFORMAT_ARGB8888, (SDL_COPY_BLEND | SDL_COPY_ADD | SDL_COPY_MOD | SDL_COPY_NEAREST), SDL_CPU_ANY, SDL_Blit_RGBA8888_ARGB8888_Blend_Scale }, - { SDL_PIXELFORMAT_RGBA8888, SDL_PIXELFORMAT_ARGB8888, (SDL_COPY_MODULATE_COLOR | SDL_COPY_MODULATE_ALPHA), SDL_CPU_ANY, SDL_Blit_RGBA8888_ARGB8888_Modulate }, - { SDL_PIXELFORMAT_RGBA8888, SDL_PIXELFORMAT_ARGB8888, (SDL_COPY_MODULATE_COLOR | SDL_COPY_MODULATE_ALPHA | SDL_COPY_NEAREST), SDL_CPU_ANY, SDL_Blit_RGBA8888_ARGB8888_Modulate_Scale }, - { SDL_PIXELFORMAT_RGBA8888, SDL_PIXELFORMAT_ARGB8888, (SDL_COPY_MODULATE_COLOR | SDL_COPY_MODULATE_ALPHA | SDL_COPY_BLEND | SDL_COPY_ADD | SDL_COPY_MOD), SDL_CPU_ANY, SDL_Blit_RGBA8888_ARGB8888_Modulate_Blend }, - { SDL_PIXELFORMAT_RGBA8888, SDL_PIXELFORMAT_ARGB8888, (SDL_COPY_MODULATE_COLOR | SDL_COPY_MODULATE_ALPHA | SDL_COPY_BLEND | SDL_COPY_ADD | SDL_COPY_MOD | SDL_COPY_NEAREST), SDL_CPU_ANY, SDL_Blit_RGBA8888_ARGB8888_Modulate_Blend_Scale }, - { SDL_PIXELFORMAT_ABGR8888, SDL_PIXELFORMAT_RGB888, (SDL_COPY_NEAREST), SDL_CPU_ANY, SDL_Blit_ABGR8888_RGB888_Scale }, - { SDL_PIXELFORMAT_ABGR8888, SDL_PIXELFORMAT_RGB888, (SDL_COPY_BLEND | SDL_COPY_ADD | SDL_COPY_MOD), SDL_CPU_ANY, SDL_Blit_ABGR8888_RGB888_Blend }, - { SDL_PIXELFORMAT_ABGR8888, SDL_PIXELFORMAT_RGB888, (SDL_COPY_BLEND | SDL_COPY_ADD | SDL_COPY_MOD | SDL_COPY_NEAREST), SDL_CPU_ANY, SDL_Blit_ABGR8888_RGB888_Blend_Scale }, - { SDL_PIXELFORMAT_ABGR8888, SDL_PIXELFORMAT_RGB888, (SDL_COPY_MODULATE_COLOR | SDL_COPY_MODULATE_ALPHA), SDL_CPU_ANY, SDL_Blit_ABGR8888_RGB888_Modulate }, - { SDL_PIXELFORMAT_ABGR8888, SDL_PIXELFORMAT_RGB888, (SDL_COPY_MODULATE_COLOR | SDL_COPY_MODULATE_ALPHA | SDL_COPY_NEAREST), SDL_CPU_ANY, SDL_Blit_ABGR8888_RGB888_Modulate_Scale }, - { SDL_PIXELFORMAT_ABGR8888, SDL_PIXELFORMAT_RGB888, (SDL_COPY_MODULATE_COLOR | SDL_COPY_MODULATE_ALPHA | SDL_COPY_BLEND | SDL_COPY_ADD | SDL_COPY_MOD), SDL_CPU_ANY, SDL_Blit_ABGR8888_RGB888_Modulate_Blend }, - { SDL_PIXELFORMAT_ABGR8888, SDL_PIXELFORMAT_RGB888, (SDL_COPY_MODULATE_COLOR | SDL_COPY_MODULATE_ALPHA | SDL_COPY_BLEND | SDL_COPY_ADD | SDL_COPY_MOD | SDL_COPY_NEAREST), SDL_CPU_ANY, SDL_Blit_ABGR8888_RGB888_Modulate_Blend_Scale }, - { SDL_PIXELFORMAT_ABGR8888, SDL_PIXELFORMAT_BGR888, (SDL_COPY_NEAREST), SDL_CPU_ANY, SDL_Blit_ABGR8888_BGR888_Scale }, - { SDL_PIXELFORMAT_ABGR8888, SDL_PIXELFORMAT_BGR888, (SDL_COPY_BLEND | SDL_COPY_ADD | SDL_COPY_MOD), SDL_CPU_ANY, SDL_Blit_ABGR8888_BGR888_Blend }, - { SDL_PIXELFORMAT_ABGR8888, SDL_PIXELFORMAT_BGR888, (SDL_COPY_BLEND | SDL_COPY_ADD | SDL_COPY_MOD | SDL_COPY_NEAREST), SDL_CPU_ANY, SDL_Blit_ABGR8888_BGR888_Blend_Scale }, - { SDL_PIXELFORMAT_ABGR8888, SDL_PIXELFORMAT_BGR888, (SDL_COPY_MODULATE_COLOR | SDL_COPY_MODULATE_ALPHA), SDL_CPU_ANY, SDL_Blit_ABGR8888_BGR888_Modulate }, - { SDL_PIXELFORMAT_ABGR8888, SDL_PIXELFORMAT_BGR888, (SDL_COPY_MODULATE_COLOR | SDL_COPY_MODULATE_ALPHA | SDL_COPY_NEAREST), SDL_CPU_ANY, SDL_Blit_ABGR8888_BGR888_Modulate_Scale }, - { SDL_PIXELFORMAT_ABGR8888, SDL_PIXELFORMAT_BGR888, (SDL_COPY_MODULATE_COLOR | SDL_COPY_MODULATE_ALPHA | SDL_COPY_BLEND | SDL_COPY_ADD | SDL_COPY_MOD), SDL_CPU_ANY, SDL_Blit_ABGR8888_BGR888_Modulate_Blend }, - { SDL_PIXELFORMAT_ABGR8888, SDL_PIXELFORMAT_BGR888, (SDL_COPY_MODULATE_COLOR | SDL_COPY_MODULATE_ALPHA | SDL_COPY_BLEND | SDL_COPY_ADD | SDL_COPY_MOD | SDL_COPY_NEAREST), SDL_CPU_ANY, SDL_Blit_ABGR8888_BGR888_Modulate_Blend_Scale }, - { SDL_PIXELFORMAT_ABGR8888, SDL_PIXELFORMAT_ARGB8888, (SDL_COPY_NEAREST), SDL_CPU_ANY, SDL_Blit_ABGR8888_ARGB8888_Scale }, - { SDL_PIXELFORMAT_ABGR8888, SDL_PIXELFORMAT_ARGB8888, (SDL_COPY_BLEND | SDL_COPY_ADD | SDL_COPY_MOD), SDL_CPU_ANY, SDL_Blit_ABGR8888_ARGB8888_Blend }, - { SDL_PIXELFORMAT_ABGR8888, SDL_PIXELFORMAT_ARGB8888, (SDL_COPY_BLEND | SDL_COPY_ADD | SDL_COPY_MOD | SDL_COPY_NEAREST), SDL_CPU_ANY, SDL_Blit_ABGR8888_ARGB8888_Blend_Scale }, - { SDL_PIXELFORMAT_ABGR8888, SDL_PIXELFORMAT_ARGB8888, (SDL_COPY_MODULATE_COLOR | SDL_COPY_MODULATE_ALPHA), SDL_CPU_ANY, SDL_Blit_ABGR8888_ARGB8888_Modulate }, - { SDL_PIXELFORMAT_ABGR8888, SDL_PIXELFORMAT_ARGB8888, (SDL_COPY_MODULATE_COLOR | SDL_COPY_MODULATE_ALPHA | SDL_COPY_NEAREST), SDL_CPU_ANY, SDL_Blit_ABGR8888_ARGB8888_Modulate_Scale }, - { SDL_PIXELFORMAT_ABGR8888, SDL_PIXELFORMAT_ARGB8888, (SDL_COPY_MODULATE_COLOR | SDL_COPY_MODULATE_ALPHA | SDL_COPY_BLEND | SDL_COPY_ADD | SDL_COPY_MOD), SDL_CPU_ANY, SDL_Blit_ABGR8888_ARGB8888_Modulate_Blend }, - { SDL_PIXELFORMAT_ABGR8888, SDL_PIXELFORMAT_ARGB8888, (SDL_COPY_MODULATE_COLOR | SDL_COPY_MODULATE_ALPHA | SDL_COPY_BLEND | SDL_COPY_ADD | SDL_COPY_MOD | SDL_COPY_NEAREST), SDL_CPU_ANY, SDL_Blit_ABGR8888_ARGB8888_Modulate_Blend_Scale }, - { SDL_PIXELFORMAT_BGRA8888, SDL_PIXELFORMAT_RGB888, (SDL_COPY_NEAREST), SDL_CPU_ANY, SDL_Blit_BGRA8888_RGB888_Scale }, - { SDL_PIXELFORMAT_BGRA8888, SDL_PIXELFORMAT_RGB888, (SDL_COPY_BLEND | SDL_COPY_ADD | SDL_COPY_MOD), SDL_CPU_ANY, SDL_Blit_BGRA8888_RGB888_Blend }, - { SDL_PIXELFORMAT_BGRA8888, SDL_PIXELFORMAT_RGB888, (SDL_COPY_BLEND | SDL_COPY_ADD | SDL_COPY_MOD | SDL_COPY_NEAREST), SDL_CPU_ANY, SDL_Blit_BGRA8888_RGB888_Blend_Scale }, - { SDL_PIXELFORMAT_BGRA8888, SDL_PIXELFORMAT_RGB888, (SDL_COPY_MODULATE_COLOR | SDL_COPY_MODULATE_ALPHA), SDL_CPU_ANY, SDL_Blit_BGRA8888_RGB888_Modulate }, - { SDL_PIXELFORMAT_BGRA8888, SDL_PIXELFORMAT_RGB888, (SDL_COPY_MODULATE_COLOR | SDL_COPY_MODULATE_ALPHA | SDL_COPY_NEAREST), SDL_CPU_ANY, SDL_Blit_BGRA8888_RGB888_Modulate_Scale }, - { SDL_PIXELFORMAT_BGRA8888, SDL_PIXELFORMAT_RGB888, (SDL_COPY_MODULATE_COLOR | SDL_COPY_MODULATE_ALPHA | SDL_COPY_BLEND | SDL_COPY_ADD | SDL_COPY_MOD), SDL_CPU_ANY, SDL_Blit_BGRA8888_RGB888_Modulate_Blend }, - { SDL_PIXELFORMAT_BGRA8888, SDL_PIXELFORMAT_RGB888, (SDL_COPY_MODULATE_COLOR | SDL_COPY_MODULATE_ALPHA | SDL_COPY_BLEND | SDL_COPY_ADD | SDL_COPY_MOD | SDL_COPY_NEAREST), SDL_CPU_ANY, SDL_Blit_BGRA8888_RGB888_Modulate_Blend_Scale }, - { SDL_PIXELFORMAT_BGRA8888, SDL_PIXELFORMAT_BGR888, (SDL_COPY_NEAREST), SDL_CPU_ANY, SDL_Blit_BGRA8888_BGR888_Scale }, - { SDL_PIXELFORMAT_BGRA8888, SDL_PIXELFORMAT_BGR888, (SDL_COPY_BLEND | SDL_COPY_ADD | SDL_COPY_MOD), SDL_CPU_ANY, SDL_Blit_BGRA8888_BGR888_Blend }, - { SDL_PIXELFORMAT_BGRA8888, SDL_PIXELFORMAT_BGR888, (SDL_COPY_BLEND | SDL_COPY_ADD | SDL_COPY_MOD | SDL_COPY_NEAREST), SDL_CPU_ANY, SDL_Blit_BGRA8888_BGR888_Blend_Scale }, - { SDL_PIXELFORMAT_BGRA8888, SDL_PIXELFORMAT_BGR888, (SDL_COPY_MODULATE_COLOR | SDL_COPY_MODULATE_ALPHA), SDL_CPU_ANY, SDL_Blit_BGRA8888_BGR888_Modulate }, - { SDL_PIXELFORMAT_BGRA8888, SDL_PIXELFORMAT_BGR888, (SDL_COPY_MODULATE_COLOR | SDL_COPY_MODULATE_ALPHA | SDL_COPY_NEAREST), SDL_CPU_ANY, SDL_Blit_BGRA8888_BGR888_Modulate_Scale }, - { SDL_PIXELFORMAT_BGRA8888, SDL_PIXELFORMAT_BGR888, (SDL_COPY_MODULATE_COLOR | SDL_COPY_MODULATE_ALPHA | SDL_COPY_BLEND | SDL_COPY_ADD | SDL_COPY_MOD), SDL_CPU_ANY, SDL_Blit_BGRA8888_BGR888_Modulate_Blend }, - { SDL_PIXELFORMAT_BGRA8888, SDL_PIXELFORMAT_BGR888, (SDL_COPY_MODULATE_COLOR | SDL_COPY_MODULATE_ALPHA | SDL_COPY_BLEND | SDL_COPY_ADD | SDL_COPY_MOD | SDL_COPY_NEAREST), SDL_CPU_ANY, SDL_Blit_BGRA8888_BGR888_Modulate_Blend_Scale }, - { SDL_PIXELFORMAT_BGRA8888, SDL_PIXELFORMAT_ARGB8888, (SDL_COPY_NEAREST), SDL_CPU_ANY, SDL_Blit_BGRA8888_ARGB8888_Scale }, - { SDL_PIXELFORMAT_BGRA8888, SDL_PIXELFORMAT_ARGB8888, (SDL_COPY_BLEND | SDL_COPY_ADD | SDL_COPY_MOD), SDL_CPU_ANY, SDL_Blit_BGRA8888_ARGB8888_Blend }, - { SDL_PIXELFORMAT_BGRA8888, SDL_PIXELFORMAT_ARGB8888, (SDL_COPY_BLEND | SDL_COPY_ADD | SDL_COPY_MOD | SDL_COPY_NEAREST), SDL_CPU_ANY, SDL_Blit_BGRA8888_ARGB8888_Blend_Scale }, - { SDL_PIXELFORMAT_BGRA8888, SDL_PIXELFORMAT_ARGB8888, (SDL_COPY_MODULATE_COLOR | SDL_COPY_MODULATE_ALPHA), SDL_CPU_ANY, SDL_Blit_BGRA8888_ARGB8888_Modulate }, - { SDL_PIXELFORMAT_BGRA8888, SDL_PIXELFORMAT_ARGB8888, (SDL_COPY_MODULATE_COLOR | SDL_COPY_MODULATE_ALPHA | SDL_COPY_NEAREST), SDL_CPU_ANY, SDL_Blit_BGRA8888_ARGB8888_Modulate_Scale }, - { SDL_PIXELFORMAT_BGRA8888, SDL_PIXELFORMAT_ARGB8888, (SDL_COPY_MODULATE_COLOR | SDL_COPY_MODULATE_ALPHA | SDL_COPY_BLEND | SDL_COPY_ADD | SDL_COPY_MOD), SDL_CPU_ANY, SDL_Blit_BGRA8888_ARGB8888_Modulate_Blend }, - { SDL_PIXELFORMAT_BGRA8888, SDL_PIXELFORMAT_ARGB8888, (SDL_COPY_MODULATE_COLOR | SDL_COPY_MODULATE_ALPHA | SDL_COPY_BLEND | SDL_COPY_ADD | SDL_COPY_MOD | SDL_COPY_NEAREST), SDL_CPU_ANY, SDL_Blit_BGRA8888_ARGB8888_Modulate_Blend_Scale }, - { 0, 0, 0, 0, NULL } -}; - -/* *INDENT-ON* */ - -/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/SDL-mobile/src/video/SDL_blit_auto.h b/src/SDL-mobile/src/video/SDL_blit_auto.h deleted file mode 100644 index 0fa4f6f61..000000000 --- a/src/SDL-mobile/src/video/SDL_blit_auto.h +++ /dev/null @@ -1,30 +0,0 @@ -/* DO NOT EDIT! This file is generated by sdlgenblit.pl */ -/* - Simple DirectMedia Layer - Copyright (C) 1997-2012 Sam Lantinga - - 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" - -/* *INDENT-OFF* */ - -extern SDL_BlitFuncEntry SDL_GeneratedBlitFuncTable[]; - -/* *INDENT-ON* */ - -/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/SDL-mobile/src/video/SDL_pixels.c b/src/SDL-mobile/src/video/SDL_pixels.c index f6a2c7693..10e041443 100644 --- a/src/SDL-mobile/src/video/SDL_pixels.c +++ b/src/SDL-mobile/src/video/SDL_pixels.c @@ -27,7 +27,6 @@ #include "SDL_sysvideo.h" #include "SDL_blit.h" #include "SDL_pixels_c.h" -#include "SDL_RLEaccel_c.h" /* Lookup tables to expand partial bytes to the full 0..255 range */ @@ -992,9 +991,6 @@ SDL_MapSurface(SDL_Surface * src, SDL_Surface * dst) /* Clear out any previous mapping */ map = src->map; - if ((src->flags & SDL_RLEACCEL) == SDL_RLEACCEL) { - SDL_UnRLESurface(src, 1); - } SDL_InvalidateMap(map); /* Figure out what kind of mapping we're doing */ diff --git a/src/SDL-mobile/src/video/SDL_surface.c b/src/SDL-mobile/src/video/SDL_surface.c index 73aa300ab..1ce0578cd 100644 --- a/src/SDL-mobile/src/video/SDL_surface.c +++ b/src/SDL-mobile/src/video/SDL_surface.c @@ -23,7 +23,6 @@ #include "SDL_video.h" #include "SDL_sysvideo.h" #include "SDL_blit.h" -#include "SDL_RLEaccel_c.h" #include "SDL_pixels_c.h" @@ -179,10 +178,6 @@ SDL_SetColorKey(SDL_Surface * surface, int flag, Uint32 key) return -1; } - if (flag & SDL_RLEACCEL) { - SDL_SetSurfaceRLE(surface, 1); - } - flags = surface->map->info.flags; if (flag) { surface->map->info.flags |= SDL_COPY_COLORKEY; @@ -461,13 +456,13 @@ SDL_GetClipRect(SDL_Surface * surface, SDL_Rect * rect) } } -/* +/* * Set up a blit between two surfaces -- split into three parts: - * The upper part, SDL_UpperBlit(), performs clipping and rectangle + * The upper part, SDL_UpperBlit(), performs clipping and rectangle * verification. The lower part is a pointer to a low level * accelerated blitting function. * - * These parts are separated out and each used internally by this + * These parts are separated out and each used internally by this * library in the optimimum places. They are exported so that if * you know exactly what you are doing, you can optimize your code * by calling the one(s) you need. @@ -723,14 +718,6 @@ SDL_LowerBlitScaled(SDL_Surface * src, SDL_Rect * srcrect, int SDL_LockSurface(SDL_Surface * surface) { - if (!surface->locked) { - /* Perform the lock */ - if (surface->flags & SDL_RLEACCEL) { - SDL_UnRLESurface(surface, 1); - surface->flags |= SDL_RLEACCEL; /* save accel'd state */ - } - } - /* Increment the surface lock count, for recursive locks */ ++surface->locked; @@ -748,15 +735,9 @@ SDL_UnlockSurface(SDL_Surface * surface) if (!surface->locked || (--surface->locked > 0)) { return; } - - /* Update RLE encoded surface with new data */ - if ((surface->flags & SDL_RLEACCEL) == SDL_RLEACCEL) { - surface->flags &= ~SDL_RLEACCEL; /* stop lying */ - SDL_RLESurface(surface); - } } -/* +/* * Convert a surface into the specified pixel format. */ SDL_Surface * @@ -839,9 +820,6 @@ SDL_ConvertSurface(SDL_Surface * surface, SDL_PixelFormat * format, (copy_flags & (SDL_COPY_COLORKEY|SDL_COPY_MODULATE_ALPHA))) { SDL_SetSurfaceBlendMode(convert, SDL_BLENDMODE_BLEND); } - if ((copy_flags & SDL_COPY_RLE_DESIRED) || (flags & SDL_RLEACCEL)) { - SDL_SetSurfaceRLE(convert, SDL_RLEACCEL); - } /* We're ready to go! */ return (convert); @@ -867,7 +845,7 @@ SDL_ConvertSurfaceFormat(SDL_Surface * surface, Uint32 pixel_format, */ static __inline__ SDL_bool SDL_CreateSurfaceOnStack(int width, int height, Uint32 pixel_format, - void * pixels, int pitch, SDL_Surface * surface, + void * pixels, int pitch, SDL_Surface * surface, SDL_PixelFormat * format, SDL_BlitMap * blitmap) { if (SDL_ISPIXELFORMAT_INDEXED(pixel_format)) { @@ -979,9 +957,7 @@ SDL_FreeSurface(SDL_Surface * surface) while (surface->locked > 0) { SDL_UnlockSurface(surface); } - if (surface->flags & SDL_RLEACCEL) { - SDL_UnRLESurface(surface, 0); - } + if (surface->format) { SDL_SetSurfacePalette(surface, NULL); SDL_FreeFormat(surface->format); diff --git a/src/SDL-mobile/src/video/sdlgenblit.pl b/src/SDL-mobile/src/video/sdlgenblit.pl deleted file mode 100644 index d4339dded..000000000 --- a/src/SDL-mobile/src/video/sdlgenblit.pl +++ /dev/null @@ -1,475 +0,0 @@ -#!/usr/bin/perl -w -# -# A script to generate optimized C blitters for Simple DirectMedia Layer -# http://www.libsdl.org/ - -use warnings; -use strict; - -my %file; - -# The formats potentially supported by this script: -# SDL_PIXELFORMAT_RGB332 -# SDL_PIXELFORMAT_RGB444 -# SDL_PIXELFORMAT_RGB555 -# SDL_PIXELFORMAT_ARGB4444 -# SDL_PIXELFORMAT_ARGB1555 -# SDL_PIXELFORMAT_RGB565 -# SDL_PIXELFORMAT_RGB24 -# SDL_PIXELFORMAT_BGR24 -# SDL_PIXELFORMAT_RGB888 -# SDL_PIXELFORMAT_BGR888 -# SDL_PIXELFORMAT_ARGB8888 -# SDL_PIXELFORMAT_RGBA8888 -# SDL_PIXELFORMAT_ABGR8888 -# SDL_PIXELFORMAT_BGRA8888 -# SDL_PIXELFORMAT_ARGB2101010 - -# The formats we're actually creating blitters for: -my @src_formats = ( - "RGB888", - "BGR888", - "ARGB8888", - "RGBA8888", - "ABGR8888", - "BGRA8888", -); -my @dst_formats = ( - "RGB888", - "BGR888", - "ARGB8888", -); - -my %format_size = ( - "RGB888" => 4, - "BGR888" => 4, - "ARGB8888" => 4, - "RGBA8888" => 4, - "ABGR8888" => 4, - "BGRA8888" => 4, -); - -my %format_type = ( - "RGB888" => "Uint32", - "BGR888" => "Uint32", - "ARGB8888" => "Uint32", - "RGBA8888" => "Uint32", - "ABGR8888" => "Uint32", - "BGRA8888" => "Uint32", -); - -my %get_rgba_string = ( - "RGB888" => "_R = (Uint8)(_pixel >> 16); _G = (Uint8)(_pixel >> 8); _B = (Uint8)_pixel; _A = 0xFF;", - "BGR888" => "_B = (Uint8)(_pixel >> 16); _G = (Uint8)(_pixel >> 8); _R = (Uint8)_pixel; _A = 0xFF;", "ARGB8888" => "_A = (Uint8)(_pixel >> 24); _R = (Uint8)(_pixel >> 16); _G = (Uint8)(_pixel >> 8); _B = (Uint8)_pixel;", - "RGBA8888" => "_R = (Uint8)(_pixel >> 24); _G = (Uint8)(_pixel >> 16); _B = (Uint8)(_pixel >> 8); _A = (Uint8)_pixel;", - "ABGR8888" => "_A = (Uint8)(_pixel >> 24); _B = (Uint8)(_pixel >> 16); _G = (Uint8)(_pixel >> 8); _R = (Uint8)_pixel;", - "BGRA8888" => "_B = (Uint8)(_pixel >> 24); _G = (Uint8)(_pixel >> 16); _R = (Uint8)(_pixel >> 8); _A = (Uint8)_pixel;", -); - -my %set_rgba_string = ( - "RGB888" => "_pixel = ((Uint32)_R << 16) | ((Uint32)_G << 8) | _B;", - "BGR888" => "_pixel = ((Uint32)_B << 16) | ((Uint32)_G << 8) | _R;", - "ARGB8888" => "_pixel = ((Uint32)_A << 24) | ((Uint32)_R << 16) | ((Uint32)_G << 8) | _B;", - "RGBA8888" => "_pixel = ((Uint32)_R << 24) | ((Uint32)_G << 16) | ((Uint32)_B << 8) | _A;", - "ABGR8888" => "_pixel = ((Uint32)_A << 24) | ((Uint32)_B << 16) | ((Uint32)_G << 8) | _R;", - "BGRA8888" => "_pixel = ((Uint32)_B << 24) | ((Uint32)_G << 16) | ((Uint32)_R << 8) | _A;", -); - -sub open_file { - my $name = shift; - open(FILE, ">$name.new") || die "Cant' open $name.new: $!"; - print FILE <<__EOF__; -/* DO NOT EDIT! This file is generated by sdlgenblit.pl */ -/* - Simple DirectMedia Layer - Copyright (C) 1997-2012 Sam Lantinga - - 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" - -/* *INDENT-OFF* */ - -__EOF__ -} - -sub close_file { - my $name = shift; - print FILE <<__EOF__; -/* *INDENT-ON* */ - -/* vi: set ts=4 sw=4 expandtab: */ -__EOF__ - close FILE; - if ( ! -f $name || system("cmp -s $name $name.new") != 0 ) { - rename("$name.new", "$name"); - } else { - unlink("$name.new"); - } -} - -sub output_copydefs -{ - print FILE <<__EOF__; -extern SDL_BlitFuncEntry SDL_GeneratedBlitFuncTable[]; -__EOF__ -} - -sub output_copyfuncname -{ - my $prefix = shift; - my $src = shift; - my $dst = shift; - my $modulate = shift; - my $blend = shift; - my $scale = shift; - my $args = shift; - my $suffix = shift; - - print FILE "$prefix SDL_Blit_${src}_${dst}"; - if ( $modulate ) { - print FILE "_Modulate"; - } - if ( $blend ) { - print FILE "_Blend"; - } - if ( $scale ) { - print FILE "_Scale"; - } - if ( $args ) { - print FILE "(SDL_BlitInfo *info)"; - } - print FILE "$suffix"; -} - -sub get_rgba -{ - my $prefix = shift; - my $format = shift; - my $string = $get_rgba_string{$format}; - $string =~ s/_/$prefix/g; - if ( $prefix ne "" ) { - print FILE <<__EOF__; - ${prefix}pixel = *$prefix; -__EOF__ - } else { - print FILE <<__EOF__; - pixel = *src; -__EOF__ - } - print FILE <<__EOF__; - $string -__EOF__ -} - -sub set_rgba -{ - my $prefix = shift; - my $format = shift; - my $string = $set_rgba_string{$format}; - $string =~ s/_/$prefix/g; - print FILE <<__EOF__; - $string - *dst = ${prefix}pixel; -__EOF__ -} - -sub output_copycore -{ - my $src = shift; - my $dst = shift; - my $modulate = shift; - my $blend = shift; - my $s = ""; - my $d = ""; - - # Nice and easy... - if ( $src eq $dst && !$modulate && !$blend ) { - print FILE <<__EOF__; - *dst = *src; -__EOF__ - return; - } - - if ( $blend ) { - get_rgba("src", $src); - get_rgba("dst", $dst); - $s = "src"; - $d = "dst"; - } else { - get_rgba("", $src); - } - - if ( $modulate ) { - print FILE <<__EOF__; - if (flags & SDL_COPY_MODULATE_COLOR) { - ${s}R = (${s}R * modulateR) / 255; - ${s}G = (${s}G * modulateG) / 255; - ${s}B = (${s}B * modulateB) / 255; - } - if (flags & SDL_COPY_MODULATE_ALPHA) { - ${s}A = (${s}A * modulateA) / 255; - } -__EOF__ - } - if ( $blend ) { - print FILE <<__EOF__; - if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) { - /* This goes away if we ever use premultiplied alpha */ - if (${s}A < 255) { - ${s}R = (${s}R * ${s}A) / 255; - ${s}G = (${s}G * ${s}A) / 255; - ${s}B = (${s}B * ${s}A) / 255; - } - } - switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) { - case SDL_COPY_BLEND: - ${d}R = ${s}R + ((255 - ${s}A) * ${d}R) / 255; - ${d}G = ${s}G + ((255 - ${s}A) * ${d}G) / 255; - ${d}B = ${s}B + ((255 - ${s}A) * ${d}B) / 255; - break; - case SDL_COPY_ADD: - ${d}R = ${s}R + ${d}R; if (${d}R > 255) ${d}R = 255; - ${d}G = ${s}G + ${d}G; if (${d}G > 255) ${d}G = 255; - ${d}B = ${s}B + ${d}B; if (${d}B > 255) ${d}B = 255; - break; - case SDL_COPY_MOD: - ${d}R = (${s}R * ${d}R) / 255; - ${d}G = (${s}G * ${d}G) / 255; - ${d}B = (${s}B * ${d}B) / 255; - break; - } -__EOF__ - } - if ( $blend ) { - set_rgba("dst", $dst); - } else { - set_rgba("", $dst); - } -} - -sub output_copyfunc -{ - my $src = shift; - my $dst = shift; - my $modulate = shift; - my $blend = shift; - my $scale = shift; - - output_copyfuncname("static void", $src, $dst, $modulate, $blend, $scale, 1, "\n"); - print FILE <<__EOF__; -{ -__EOF__ - if ( $modulate || $blend ) { - print FILE <<__EOF__; - const int flags = info->flags; -__EOF__ - } - if ( $modulate ) { - print FILE <<__EOF__; - const Uint32 modulateR = info->r; - const Uint32 modulateG = info->g; - const Uint32 modulateB = info->b; - const Uint32 modulateA = info->a; -__EOF__ - } - if ( $blend ) { - print FILE <<__EOF__; - Uint32 srcpixel; - Uint32 srcR, srcG, srcB, srcA; - Uint32 dstpixel; - Uint32 dstR, dstG, dstB, dstA; -__EOF__ - } elsif ( $modulate || $src ne $dst ) { - print FILE <<__EOF__; - Uint32 pixel; - Uint32 R, G, B, A; -__EOF__ - } - if ( $scale ) { - print FILE <<__EOF__; - int srcy, srcx; - int posy, posx; - int incy, incx; - - srcy = 0; - posy = 0; - incy = (info->src_h << 16) / info->dst_h; - incx = (info->src_w << 16) / info->dst_w; - - while (info->dst_h--) { - $format_type{$src} *src = 0; - $format_type{$dst} *dst = ($format_type{$dst} *)info->dst; - int n = info->dst_w; - srcx = -1; - posx = 0x10000L; - while (posy >= 0x10000L) { - ++srcy; - posy -= 0x10000L; - } - while (n--) { - if (posx >= 0x10000L) { - while (posx >= 0x10000L) { - ++srcx; - posx -= 0x10000L; - } - src = ($format_type{$src} *)(info->src + (srcy * info->src_pitch) + (srcx * $format_size{$src})); -__EOF__ - print FILE <<__EOF__; - } -__EOF__ - output_copycore($src, $dst, $modulate, $blend); - print FILE <<__EOF__; - posx += incx; - ++dst; - } - posy += incy; - info->dst += info->dst_pitch; - } -__EOF__ - } else { - print FILE <<__EOF__; - - while (info->dst_h--) { - $format_type{$src} *src = ($format_type{$src} *)info->src; - $format_type{$dst} *dst = ($format_type{$dst} *)info->dst; - int n = info->dst_w; - while (n--) { -__EOF__ - output_copycore($src, $dst, $modulate, $blend); - print FILE <<__EOF__; - ++src; - ++dst; - } - info->src += info->src_pitch; - info->dst += info->dst_pitch; - } -__EOF__ - } - print FILE <<__EOF__; -} - -__EOF__ -} - -sub output_copyfunc_h -{ -} - -sub output_copyinc -{ - print FILE <<__EOF__; -#include "SDL_video.h" -#include "SDL_blit.h" -#include "SDL_blit_auto.h" - -__EOF__ -} - -sub output_copyfunctable -{ - print FILE <<__EOF__; -SDL_BlitFuncEntry SDL_GeneratedBlitFuncTable[] = { -__EOF__ - for (my $i = 0; $i <= $#src_formats; ++$i) { - my $src = $src_formats[$i]; - for (my $j = 0; $j <= $#dst_formats; ++$j) { - my $dst = $dst_formats[$j]; - for (my $modulate = 0; $modulate <= 1; ++$modulate) { - for (my $blend = 0; $blend <= 1; ++$blend) { - for (my $scale = 0; $scale <= 1; ++$scale) { - if ( $modulate || $blend || $scale ) { - print FILE " { SDL_PIXELFORMAT_$src, SDL_PIXELFORMAT_$dst, "; - my $flags = ""; - my $flag = ""; - if ( $modulate ) { - $flag = "SDL_COPY_MODULATE_COLOR | SDL_COPY_MODULATE_ALPHA"; - if ( $flags eq "" ) { - $flags = $flag; - } else { - $flags = "$flags | $flag"; - } - } - if ( $blend ) { - $flag = "SDL_COPY_BLEND | SDL_COPY_ADD | SDL_COPY_MOD"; - if ( $flags eq "" ) { - $flags = $flag; - } else { - $flags = "$flags | $flag"; - } - } - if ( $scale ) { - $flag = "SDL_COPY_NEAREST"; - if ( $flags eq "" ) { - $flags = $flag; - } else { - $flags = "$flags | $flag"; - } - } - if ( $flags eq "" ) { - $flags = "0"; - } - print FILE "($flags), SDL_CPU_ANY,"; - output_copyfuncname("", $src_formats[$i], $dst_formats[$j], $modulate, $blend, $scale, 0, " },\n"); - } - } - } - } - } - } - print FILE <<__EOF__; - { 0, 0, 0, 0, NULL } -}; - -__EOF__ -} - -sub output_copyfunc_c -{ - my $src = shift; - my $dst = shift; - - for (my $modulate = 0; $modulate <= 1; ++$modulate) { - for (my $blend = 0; $blend <= 1; ++$blend) { - for (my $scale = 0; $scale <= 1; ++$scale) { - if ( $modulate || $blend || $scale ) { - output_copyfunc($src, $dst, $modulate, $blend, $scale); - } - } - } - } -} - -open_file("SDL_blit_auto.h"); -output_copydefs(); -for (my $i = 0; $i <= $#src_formats; ++$i) { - for (my $j = 0; $j <= $#dst_formats; ++$j) { - output_copyfunc_h($src_formats[$i], $dst_formats[$j]); - } -} -print FILE "\n"; -close_file("SDL_blit_auto.h"); - -open_file("SDL_blit_auto.c"); -output_copyinc(); -for (my $i = 0; $i <= $#src_formats; ++$i) { - for (my $j = 0; $j <= $#dst_formats; ++$j) { - output_copyfunc_c($src_formats[$i], $dst_formats[$j]); - } -} -output_copyfunctable(); -close_file("SDL_blit_auto.c");