diff --git a/alienblaster/project/sdl/sdl-1.2/src/video/SDL_pixels.c b/alienblaster/project/sdl/sdl-1.2/src/video/SDL_pixels.c index 47bbd7f9b..5c9800f54 100644 --- a/alienblaster/project/sdl/sdl-1.2/src/video/SDL_pixels.c +++ b/alienblaster/project/sdl/sdl-1.2/src/video/SDL_pixels.c @@ -304,7 +304,11 @@ Uint16 SDL_CalculatePitch(SDL_Surface *surface) default: break; } +// 4-byte aligning adds extra memcpy() with OpenGL ES renderer +// TODO: check if we really can disable that for Android +//#ifndef ANDROID pitch = (pitch + 3) & ~3; /* 4-byte aligning */ +//#endif return(pitch); } /* diff --git a/alienblaster/project/sdl/sdl-1.2/src/video/android/SDL_androidvideo-1.2.c b/alienblaster/project/sdl/sdl-1.2/src/video/android/SDL_androidvideo-1.2.c index 3ca618232..250069fb3 100644 --- a/alienblaster/project/sdl/sdl-1.2/src/video/android/SDL_androidvideo-1.2.c +++ b/alienblaster/project/sdl/sdl-1.2/src/video/android/SDL_androidvideo-1.2.c @@ -28,6 +28,9 @@ #include "../SDL_sysvideo.h" #include "../SDL_pixels_c.h" +#include "SDL_pixels.h" +#include "SDL_video-1.3.h" +#include "SDL_surface.h" #include "SDL_androidvideo.h" #include @@ -57,6 +60,10 @@ static void ANDROID_FreeHWSurface(_THIS, SDL_Surface *surface); static int ANDROID_FlipHWSurface(_THIS, SDL_Surface *surface); static void ANDROID_GL_SwapBuffers(_THIS); static void ANDROID_PumpEvents(_THIS); +static int ANDROID_CheckHWBlit(_THIS, SDL_Surface *src, SDL_Surface *dst); +static int ANDROID_FillHWRect(_THIS, SDL_Surface *dst, SDL_Rect *rect, Uint32 color); +static int ANDROID_SetHWColorKey(_THIS, SDL_Surface *surface, Uint32 key); +static int ANDROID_SetHWAlpha(_THIS, SDL_Surface *surface, Uint8 value); // Stubs to get rid of crashing in OpenGL mode // The implementation dependent data for the window manager cursor @@ -91,25 +98,19 @@ static void ANDROID_UpdateRects(_THIS, int numrects, SDL_Rect *rects); /* Private display data */ #define SDL_NUMMODES 4 -struct SDL_PrivateVideoData { - SDL_Rect *SDL_modelist[SDL_NUMMODES+1]; -}; +static SDL_Rect *SDL_modelist[SDL_NUMMODES+1]; -#define SDL_modelist (this->hidden->SDL_modelist) +//#define SDL_modelist (this->hidden->SDL_modelist) +enum { ANDROID_BYTESPERPIXEL = 2, ANDROID_BITSPERPIXEL = 16 }; +typedef struct SDL_Texture private_hwdata; // Pointer to in-memory video surface -static int memX = 0; -static int memY = 0; int SDL_ANDROID_sFakeWindowWidth = 640; int SDL_ANDROID_sFakeWindowHeight = 480; -// In-memory surfaces -static void * memBuffer1 = NULL; -static void * memBuffer2 = NULL; -static void * memBuffer = NULL; static int sdl_opengl = 0; -// Some wicked GLES stuff -static GLuint texture = 0; +static SDL_Window *SDL_VideoWindow = NULL; +static SDL_Surface *SDL_CurrentVideoSurface = NULL; static void SdlGlRenderInit(); @@ -136,17 +137,10 @@ static SDL_VideoDevice *ANDROID_CreateDevice(int devindex) device = (SDL_VideoDevice *)SDL_malloc(sizeof(SDL_VideoDevice)); if ( device ) { SDL_memset(device, 0, (sizeof *device)); - device->hidden = (struct SDL_PrivateVideoData *) - SDL_malloc((sizeof *device->hidden)); - } - if ( (device == NULL) || (device->hidden == NULL) ) { + } else { SDL_OutOfMemory(); - if ( device ) { - SDL_free(device); - } return(0); } - SDL_memset(device->hidden, 0, (sizeof *device->hidden)); /* Set the function pointers */ device->VideoInit = ANDROID_VideoInit; @@ -157,10 +151,10 @@ static SDL_VideoDevice *ANDROID_CreateDevice(int devindex) device->UpdateRects = ANDROID_UpdateRects; device->VideoQuit = ANDROID_VideoQuit; device->AllocHWSurface = ANDROID_AllocHWSurface; - device->CheckHWBlit = NULL; - device->FillHWRect = NULL; - device->SetHWColorKey = NULL; - device->SetHWAlpha = NULL; + device->CheckHWBlit = ANDROID_CheckHWBlit; + device->FillHWRect = ANDROID_FillHWRect; + device->SetHWColorKey = ANDROID_SetHWColorKey; + device->SetHWAlpha = ANDROID_SetHWAlpha; device->LockHWSurface = ANDROID_LockHWSurface; device->UnlockHWSurface = ANDROID_UnlockHWSurface; device->FlipHWSurface = ANDROID_FlipHWSurface; @@ -181,6 +175,15 @@ static SDL_VideoDevice *ANDROID_CreateDevice(int devindex) device->ShowWMCursor = ANDROID_ShowWMCursor; device->WarpWMCursor = ANDROID_WarpWMCursor; device->MoveWMCursor = ANDROID_MoveWMCursor; + + device->info.hw_available = 1; + device->info.blit_hw = 1; + device->info.blit_hw_CC = 1; + device->info.blit_hw_A = 1; + device->info.blit_fill = 1; + device->info.video_mem = 128 * 1024; + device->info.current_w = SDL_ANDROID_sWindowWidth; + device->info.current_h = SDL_ANDROID_sWindowHeight; return device; } @@ -190,14 +193,26 @@ VideoBootStrap ANDROID_bootstrap = { ANDROID_Available, ANDROID_CreateDevice }; - int ANDROID_VideoInit(_THIS, SDL_PixelFormat *vformat) { int i; + static SDL_PixelFormat alphaFormat; + /* Determine the screen depth (use default 16-bit depth) */ /* we change this during the SDL_SetVideoMode implementation... */ - vformat->BitsPerPixel = 16; - vformat->BytesPerPixel = 2; + if( vformat ) { + vformat->BitsPerPixel = ANDROID_BITSPERPIXEL; + vformat->BytesPerPixel = ANDROID_BYTESPERPIXEL; + } + + int bpp; + SDL_zero(alphaFormat); + SDL_PixelFormatEnumToMasks( SDL_PIXELFORMAT_RGBA4444, &bpp, + &alphaFormat.Rmask, &alphaFormat.Gmask, + &alphaFormat.Bmask, &alphaFormat.Amask ); + alphaFormat.BitsPerPixel = ANDROID_BITSPERPIXEL; + alphaFormat.BytesPerPixel = ANDROID_BYTESPERPIXEL; + this->displayformatalphapixel = &alphaFormat; for ( i=0; iw = 320; SDL_modelist[2]->h = 240; // Always available on any screen and any orientation SDL_modelist[3]->w = 320; SDL_modelist[3]->h = 200; // Always available on any screen and any orientation SDL_modelist[4] = NULL; + + SDL_VideoInit_1_3(NULL, 0); /* We're done! */ return(0); @@ -216,7 +233,7 @@ int ANDROID_VideoInit(_THIS, SDL_PixelFormat *vformat) SDL_Rect **ANDROID_ListModes(_THIS, SDL_PixelFormat *format, Uint32 flags) { - if(format->BitsPerPixel != 16) + if(format->BitsPerPixel != ANDROID_BITSPERPIXEL) return NULL; return SDL_modelist; } @@ -224,64 +241,69 @@ SDL_Rect **ANDROID_ListModes(_THIS, SDL_PixelFormat *format, Uint32 flags) SDL_Surface *ANDROID_SetVideoMode(_THIS, SDL_Surface *current, int width, int height, int bpp, Uint32 flags) { - __android_log_print(ANDROID_LOG_INFO, "libSDL", "SDL_SetVideoMode(): application requested mode %dx%d", width, height); - - if ( memBuffer1 ) - SDL_free( memBuffer1 ); - if ( memBuffer2 ) - SDL_free( memBuffer2 ); - - memBuffer = memBuffer1 = memBuffer2 = NULL; + void * memBuffer = NULL; + SDL_PixelFormat format; + int bpp1; + + __android_log_print(ANDROID_LOG_INFO, "libSDL", "SDL_SetVideoMode(): application requested mode %dx%d", width, height); sdl_opengl = (flags & SDL_OPENGL) ? 1 : 0; - memX = width; - memY = height; SDL_ANDROID_sFakeWindowWidth = width; SDL_ANDROID_sFakeWindowHeight = height; if( ! sdl_opengl ) { - memBuffer1 = SDL_malloc(memX * memY * (bpp / 8)); - if ( ! memBuffer1 ) { + SDL_DisplayMode mode; + SDL_RendererInfo SDL_VideoRendererInfo; + + SDL_SelectVideoDisplay(0); + SDL_VideoWindow = SDL_CreateWindow("", 0, 0, width, height, SDL_WINDOW_SHOWN | SDL_WINDOW_BORDERLESS | SDL_WINDOW_OPENGL); + + SDL_zero(mode); + mode.format = SDL_PIXELFORMAT_RGB565; + SDL_SetWindowDisplayMode(SDL_VideoWindow, &mode); + + if (SDL_CreateRenderer(SDL_VideoWindow, -1, 0) < 0) { + __android_log_print(ANDROID_LOG_INFO, "libSDL", "SDL_SetVideoMode(): Error creating renderer"); + return NULL; + } + SDL_GetRendererInfo(&SDL_VideoRendererInfo); + + // We're not allowing locking videosurface yet + /* + memBuffer = SDL_malloc(memX * memY * ANDROID_BYTESPERPIXEL); + if ( ! memBuffer ) { __android_log_print(ANDROID_LOG_INFO, "libSDL", "Couldn't allocate buffer for requested mode"); SDL_SetError("Couldn't allocate buffer for requested mode"); return(NULL); } - SDL_memset(memBuffer1, 0, memX * memY * (bpp / 8)); - - if( flags & SDL_DOUBLEBUF ) - { - memBuffer2 = SDL_malloc(memX * memY * (bpp / 8)); - if ( ! memBuffer2 ) { - __android_log_print(ANDROID_LOG_INFO, "libSDL", "Couldn't allocate buffer for requested mode"); - SDL_SetError("Couldn't allocate buffer for requested mode"); - return(NULL); - } - SDL_memset(memBuffer2, 0, memX * memY * (bpp / 8)); - } - memBuffer = memBuffer1; + SDL_memset(memBuffer, 0, memX * memY * ANDROID_BYTESPERPIXEL); + */ } /* Allocate the new pixel format for the screen */ - if ( ! SDL_ReallocFormat(current, bpp, 0, 0, 0, 0) ) { - if(memBuffer) - SDL_free(memBuffer); - memBuffer = NULL; + SDL_zero(format); + SDL_PixelFormatEnumToMasks( SDL_PIXELFORMAT_RGB565, &bpp1, + &format.Rmask, &format.Gmask, + &format.Bmask, &format.Amask ); + format.BitsPerPixel = bpp1; + format.BytesPerPixel = ANDROID_BYTESPERPIXEL; + + if ( ! SDL_ReallocFormat(current, ANDROID_BITSPERPIXEL, format.Rmask, format.Gmask, format.Bmask, format.Amask) ) { __android_log_print(ANDROID_LOG_INFO, "libSDL", "Couldn't allocate new pixel format for requested mode"); SDL_SetError("Couldn't allocate new pixel format for requested mode"); return(NULL); } /* Set up the new mode framebuffer */ - current->flags = (flags & SDL_FULLSCREEN) | (flags & SDL_DOUBLEBUF) | (flags & SDL_OPENGL); + current->flags = (flags & SDL_FULLSCREEN) | (flags & SDL_OPENGL) | SDL_DOUBLEBUF | SDL_HWSURFACE; current->w = width; current->h = height; - current->pitch = memX * (bpp / 8); + current->pitch = SDL_ANDROID_sFakeWindowWidth * ANDROID_BYTESPERPIXEL; current->pixels = memBuffer; + SDL_CurrentVideoSurface = current; - SdlGlRenderInit(); - /* We're done */ return(current); } @@ -293,19 +315,11 @@ void ANDROID_VideoQuit(_THIS) { if( ! sdl_opengl ) { - glDisableClientState(GL_TEXTURE_COORD_ARRAY); - glDisableClientState(GL_VERTEX_ARRAY); - glDeleteTextures(1, &texture); + SDL_CurrentVideoSurface = NULL; } - memX = 0; - memY = 0; - memBuffer = NULL; - SDL_free( memBuffer1 ); - memBuffer1 = NULL; - if( memBuffer2 ) - SDL_free( memBuffer2 ); - memBuffer2 = NULL; + SDL_ANDROID_sFakeWindowWidth = 0; + SDL_ANDROID_sFakeWindowWidth = 0; int i; @@ -327,53 +341,196 @@ void ANDROID_PumpEvents(_THIS) { } -/* We don't actually allow hardware surfaces other than the main one */ -// TODO: use OpenGL textures here static int ANDROID_AllocHWSurface(_THIS, SDL_Surface *surface) { - return(-1); -} -static void ANDROID_FreeHWSurface(_THIS, SDL_Surface *surface) -{ - return; + if ( ! (surface->w && surface->h) ) + return(-1); + + Uint32 format = SDL_PIXELFORMAT_RGBA5551; // 1-bit alpha for color key, every surface will have colorkey so it's easier for us + if( surface->format->Amask ) + { + SDL_PixelFormat format1; + int bpp; + format = SDL_PIXELFORMAT_RGBA4444; + SDL_zero(format1); + SDL_PixelFormatEnumToMasks( format, &bpp, + &format1.Rmask, &format1.Gmask, + &format1.Bmask, &format1.Amask ); + if( surface->format->BitsPerPixel != bpp || + surface->format->Rmask != format1.Rmask || + surface->format->Gmask != format1.Gmask || + surface->format->Bmask != format1.Bmask || + surface->format->Amask != format1.Amask ) + return(-1); // Do not allow alpha-surfaces with format other than RGBA4444 (it will be pain to lock/copy them) + } + + surface->pitch = surface->w * surface->format->BytesPerPixel; + surface->pixels = SDL_malloc(surface->h * surface->w * surface->format->BytesPerPixel); + if ( surface->pixels == NULL ) { + SDL_OutOfMemory(); + return(-1); + } + SDL_memset(surface->pixels, 0, surface->h*surface->pitch); + + surface->hwdata = (struct private_hwdata *)SDL_CreateTexture(format, SDL_TEXTUREACCESS_STATIC, surface->w, surface->h); + if( !surface->hwdata ) { + SDL_free(surface->pixels); + surface->pixels = NULL; + SDL_OutOfMemory(); + return(-1); + } + + return 0; +} + +static void ANDROID_FreeHWSurface(_THIS, SDL_Surface *surface) +{ + if( !surface->hwdata ) + return; + SDL_DestroyTexture((struct SDL_Texture *)surface->hwdata); } -/* We need to wait for vertical retrace on page flipped displays */ static int ANDROID_LockHWSurface(_THIS, SDL_Surface *surface) { + if( surface == SDL_CurrentVideoSurface ) + { + return -1; // Do not allow that, we're HW accelerated + } + + if( !surface->hwdata ) + return(-1); + return(0); } static void ANDROID_UnlockHWSurface(_THIS, SDL_Surface *surface) { - return; + SDL_PixelFormat format; + Uint32 hwformat = SDL_PIXELFORMAT_RGBA5551; + int bpp; + SDL_Surface * converted = NULL; + + if( !surface->hwdata ) + return; + + if( surface->format->Amask ) + hwformat = SDL_PIXELFORMAT_RGBA4444; + + /* Allocate the new pixel format for the screen */ + SDL_zero(format); + SDL_PixelFormatEnumToMasks( hwformat, &bpp, + &format.Rmask, &format.Gmask, + &format.Bmask, &format.Amask ); + format.BytesPerPixel = ANDROID_BYTESPERPIXEL; + format.BitsPerPixel = bpp; + + if( format.BitsPerPixel == surface->format->BitsPerPixel && + format.Rmask == surface->format->Rmask && + format.Gmask == surface->format->Gmask && + format.Bmask == surface->format->Bmask && + format.Amask == surface->format->Amask ) + { + converted = surface; + } + else + { + Uint8 oldAlpha = surface->format->alpha; + converted = SDL_CreateRGBSurface(SDL_SWSURFACE, surface->w, surface->h, format.BitsPerPixel, + format.Rmask, format.Gmask, format.Bmask, format.Amask); + if( !converted ) { + SDL_OutOfMemory(); + return; + } + SDL_FillRect( converted, NULL, 0 ); // Fill with transparency + surface->format->alpha = SDL_ALPHA_OPAQUE; + SDL_LowerBlit( surface, NULL, converted, NULL ); // Should take into account colorkey + surface->format->alpha = oldAlpha; + } + + SDL_Rect rect; + rect.x = 0; + rect.y = 0; + rect.w = surface->w; + rect.h = surface->h; + SDL_UpdateTexture((struct SDL_Texture *)surface->hwdata, &rect, converted->pixels, converted->pitch); + + if( converted != surface ) + SDL_FreeSurface(converted); } +// We're only blitting HW surface to screen, no other options provided (and if you need them your app designed wrong) +int ANDROID_HWBlit(SDL_Surface* src, SDL_Rect* srcrect, SDL_Surface* dst, SDL_Rect* dstrect) +{ + if( dst != SDL_CurrentVideoSurface || ! src->hwdata ) + { + return(src->map->sw_blit(src, srcrect, dst, dstrect)); + } + + return SDL_RenderCopy((struct SDL_Texture *)src->hwdata, srcrect, dstrect); +}; + +static int ANDROID_CheckHWBlit(_THIS, SDL_Surface *src, SDL_Surface *dst) +{ + // This part is ignored by SDL (though it should not be) + /* + if( dst != SDL_CurrentVideoSurface || ! src->hwdata ) + return(-1); + */ + src->map->hw_blit = ANDROID_HWBlit; + return(0); +}; + +static int ANDROID_FillHWRect(_THIS, SDL_Surface *dst, SDL_Rect *rect, Uint32 color) +{ + Uint8 r, g, b, a; + if( dst != SDL_CurrentVideoSurface ) + { + // TODO: hack + current_video->info.blit_fill = 0; + SDL_FillRect( dst, rect, color ); + current_video->info.blit_fill = 1; + return(0); + } + SDL_GetRGBA(color, dst->format, &r, &g, &b, &a); + SDL_SetRenderDrawColor( r, g, b, a ); + SDL_RenderFillRect(rect); +}; + +static int ANDROID_SetHWColorKey(_THIS, SDL_Surface *surface, Uint32 key) +{ + SDL_PixelFormat format; + SDL_Surface * converted = NULL; + + if( !surface->hwdata ) + return(-1); + if( surface->format->Amask ) + return(-1); + + ANDROID_UnlockHWSurface(this, surface); // Convert surface using colorkey + return 0; +}; + +static int ANDROID_SetHWAlpha(_THIS, SDL_Surface *surface, Uint8 value) +{ + if( !surface->hwdata ) + return(-1); + + if( value == SDL_ALPHA_OPAQUE ) + SDL_SetTextureBlendMode((struct SDL_Texture *)surface->hwdata, SDL_BLENDMODE_NONE); + else + SDL_SetTextureBlendMode((struct SDL_Texture *)surface->hwdata, SDL_BLENDMODE_BLEND); + + return SDL_SetTextureAlphaMod((struct SDL_Texture *)surface->hwdata, value); +}; + static void ANDROID_UpdateRects(_THIS, int numrects, SDL_Rect *rects) { - ANDROID_FlipHWSurface(this, SDL_VideoSurface); + // Used only in single-buffer mode + ANDROID_FlipHWSurface(this, SDL_CurrentVideoSurface); } static int ANDROID_FlipHWSurface(_THIS, SDL_Surface *surface) { - if( ! sdl_opengl ) - { - glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, memX, memY, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, memBuffer); -#if SDL_VIDEO_RENDER_RESIZE - glDrawTexiOES(0, 0, 1, SDL_ANDROID_sWindowWidth, SDL_ANDROID_sWindowHeight); // Stretch to screen -#else - glDrawTexiOES(0, SDL_ANDROID_sWindowHeight - SDL_ANDROID_sFakeWindowHeight, 1, SDL_ANDROID_sFakeWindowWidth, SDL_ANDROID_sFakeWindowHeight); // Do not stretch -#endif - - if( surface->flags & SDL_DOUBLEBUF ) - { - if( memBuffer == memBuffer1 ) - memBuffer = memBuffer2; - else - memBuffer = memBuffer1; - surface->pixels = memBuffer; - } - } SDL_ANDROID_CallJavaSwapBuffers(); @@ -390,116 +547,3 @@ int ANDROID_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color *colors) return(1); } -void SdlGlRenderInit() -{ - // Set up an array of values to use as the sprite vertices. - static GLfloat vertices[] = - { - 0, 0, - 1, 0, - 0, 1, - 1, 1, - }; - - // Set up an array of values for the texture coordinates. - static GLfloat texcoords[] = - { - 0, 0, - 1, 0, - 0, 1, - 1, 1, - }; - - static GLint texcoordsCrop[] = - { - 0, 0, 0, 0, - }; - - static float clearColor = 0.0f; - static int clearColorDir = 1; - int textX, textY; - void * memBufferTemp; - - if( !sdl_opengl && memBuffer ) - { - // Texture sizes should be 2^n - textX = memX; - textY = memY; - - if( textX <= 256 ) - textX = 256; - else if( textX <= 512 ) - textX = 512; - else - textX = 1024; - - if( textY <= 256 ) - textY = 256; - else if( textY <= 512 ) - textY = 512; - else - textY = 1024; - - glViewport(0, 0, textX, textY); - - glClearColor(0,0,0,0); - // Set projection - glMatrixMode( GL_PROJECTION ); - glLoadIdentity(); - #if defined(GL_VERSION_ES_CM_1_0) - #define glOrtho glOrthof - #endif - glOrtho( 0.0f, 1.0f, 1.0f, 0.0f, 0.0f, 1.0f ); - - // Now Initialize modelview matrix - glMatrixMode( GL_MODELVIEW ); - glLoadIdentity(); - - glDisable(GL_DEPTH_TEST); - glDisable(GL_CULL_FACE); - glDisable(GL_DITHER); - glDisable(GL_MULTISAMPLE); - - glEnable(GL_TEXTURE_2D); - - glGenTextures(1, &texture); - - glBindTexture(GL_TEXTURE_2D, texture); - - glPixelStorei(GL_UNPACK_ALIGNMENT, 1); - - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); - - glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST); - glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST); - - glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); - - void * textBuffer = SDL_malloc( textX*textY*2 ); - SDL_memset( textBuffer, 0, textX*textY*2 ); - - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, textX, textY, 0, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, textBuffer); - - glColor4f(1.0f, 1.0f, 1.0f, 1.0f); - - glEnableClientState(GL_VERTEX_ARRAY); - glEnableClientState(GL_TEXTURE_COORD_ARRAY); - - glVertexPointer(2, GL_FLOAT, 0, vertices); - glTexCoordPointer(2, GL_FLOAT, 0, texcoords); - - glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); - - texcoordsCrop[0] = 0; - texcoordsCrop[1] = memY; - texcoordsCrop[2] = memX; - texcoordsCrop[3] = -memY; - - glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_CROP_RECT_OES, texcoordsCrop); - - glFinish(); - - SDL_free( textBuffer ); - } -} diff --git a/alienblaster/project/sdl/sdl-1.2/src/video/android/SDL_androidvideo-1.3-stub.c b/alienblaster/project/sdl/sdl-1.2/src/video/android/SDL_androidvideo-1.3-stub.c new file mode 100644 index 000000000..4cdbdfe15 --- /dev/null +++ b/alienblaster/project/sdl/sdl-1.2/src/video/android/SDL_androidvideo-1.3-stub.c @@ -0,0 +1,150 @@ +/* + SDL - Simple DirectMedia Layer + Copyright (C) 1997-2009 Sam Lantinga + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + + Sam Lantinga + slouken@libsdl.org +*/ +#include "SDL_config.h" + +#include "SDL_pixels.h" +#include "SDL_video-1.3.h" +#include "SDL_sysvideo-1.3.h" +#include "SDL_androidvideo.h" + +#include +#include // for memset() + +static int ANDROID_VideoInit(_THIS); +static int ANDROID_GetDisplayBounds(_THIS, SDL_VideoDisplay * display, SDL_Rect * rect); +static void ANDROID_GetDisplayModes(_THIS, SDL_VideoDisplay * display); +static int ANDROID_SetDisplayMode(_THIS, SDL_VideoDisplay * display, SDL_DisplayMode * mode); +static void ANDROID_VideoQuit(_THIS); + +static void ANDROID_GL_SwapBuffers(_THIS, SDL_Window * window); +// Stubs +static SDL_GLContext ANDROID_GL_CreateContext(_THIS, SDL_Window * window); +static int ANDROID_GL_MakeCurrent (_THIS, SDL_Window * window, SDL_GLContext context); +static void ANDROID_GL_DeleteContext (_THIS, SDL_GLContext context); +static void ANDROID_PumpEvents(_THIS); + +static void ANDROID_DeleteDevice(SDL_VideoDevice *device) +{ + SDL_free(device); +} + +SDL_VideoDevice *ANDROID_CreateDevice_1_3(int devindex) +{ + SDL_VideoDevice *device; + + /* Initialize all variables that we clean on shutdown */ + device = (SDL_VideoDevice *)SDL_malloc(sizeof(SDL_VideoDevice)); + if ( device ) { + SDL_memset(device, 0, sizeof (*device)); + } + if ( (device == NULL) ) { + SDL_OutOfMemory(); + if ( device ) { + SDL_free(device); + } + return(0); + } + + /* Set the function pointers */ + device->VideoInit = ANDROID_VideoInit; + device->GetDisplayBounds = ANDROID_GetDisplayBounds; + device->GetDisplayModes = ANDROID_GetDisplayModes; + device->PumpEvents = ANDROID_PumpEvents; + device->VideoQuit = ANDROID_VideoQuit; + device->free = ANDROID_DeleteDevice; + + device->GL_SwapWindow = ANDROID_GL_SwapBuffers; + device->GL_CreateContext = ANDROID_GL_CreateContext; + device->GL_MakeCurrent = ANDROID_GL_MakeCurrent; + device->GL_DeleteContext = ANDROID_GL_DeleteContext; + + return device; +} + +int ANDROID_VideoInit(_THIS) +{ + SDL_VideoDisplay display; + SDL_DisplayMode mode; + + mode.w = SDL_ANDROID_sWindowWidth; + mode.h = SDL_ANDROID_sWindowHeight; + mode.refresh_rate = 0; + mode.format = SDL_PIXELFORMAT_RGB565; + mode.driverdata = NULL; + + SDL_zero(display); + display.desktop_mode = mode; + display.current_mode = mode; + display.driverdata = NULL; + SDL_AddVideoDisplay(&display); + + return 0; +} + +void ANDROID_GetDisplayModes(_THIS, SDL_VideoDisplay * display) +{ + SDL_DisplayMode mode; + mode.w = SDL_ANDROID_sWindowWidth; + mode.h = SDL_ANDROID_sWindowHeight; + mode.refresh_rate = 0; + mode.format = SDL_PIXELFORMAT_RGB565; + mode.driverdata = NULL; + SDL_AddDisplayMode(display, &mode); +} + +int ANDROID_GetDisplayBounds(_THIS, SDL_VideoDisplay * display, SDL_Rect * rect) +{ + rect->w = SDL_ANDROID_sWindowWidth; + rect->h = SDL_ANDROID_sWindowHeight; + return 1; +}; + +int ANDROID_SetDisplayMode(_THIS, SDL_VideoDisplay * display, SDL_DisplayMode * mode) +{ + return 1; +}; + +void ANDROID_VideoQuit(_THIS) +{ +} + +void ANDROID_PumpEvents(_THIS) +{ +} + +void ANDROID_GL_SwapBuffers(_THIS, SDL_Window * window) +{ + //SDL_ANDROID_CallJavaSwapBuffers(); +}; + +SDL_GLContext ANDROID_GL_CreateContext(_THIS, SDL_Window * window) +{ + return (SDL_GLContext)1; +}; +int ANDROID_GL_MakeCurrent (_THIS, SDL_Window * window, SDL_GLContext context) +{ + return 1; +}; +void ANDROID_GL_DeleteContext (_THIS, SDL_GLContext context) +{ +}; + diff --git a/alienblaster/project/sdl/sdl-1.3/include/SDL_video.h b/alienblaster/project/sdl/sdl-1.3/include/SDL_video.h index 10cf9ad33..2f0f1fe19 100644 --- a/alienblaster/project/sdl/sdl-1.3/include/SDL_video.h +++ b/alienblaster/project/sdl/sdl-1.3/include/SDL_video.h @@ -323,8 +323,13 @@ extern DECLSPEC const char *SDLCALL SDL_GetVideoDriver(int index); * * \sa SDL_VideoQuit() */ -extern DECLSPEC int SDLCALL SDL_VideoInit(const char *driver_name, - Uint32 flags); +extern DECLSPEC int SDLCALL +#if SDL_VERSION_ATLEAST(1,3,0) +SDL_VideoInit +#else +SDL_VideoInit_1_3 +#endif +(const char *driver_name, Uint32 flags); /** * \brief Shuts down the video subsystem. diff --git a/alienblaster/project/sdl/sdl-1.3/src/video/SDL_video.c b/alienblaster/project/sdl/sdl-1.3/src/video/SDL_video.c index eecfedf1a..19e4dadcb 100644 --- a/alienblaster/project/sdl/sdl-1.3/src/video/SDL_video.c +++ b/alienblaster/project/sdl/sdl-1.3/src/video/SDL_video.c @@ -31,6 +31,7 @@ #else #include "SDL_video-1.3.h" #include "SDL_sysvideo-1.3.h" +#include "SDL_androidvideo.h" #endif #include "SDL_blit.h" #include "SDL_pixels_c.h" @@ -190,11 +191,10 @@ SDL_GetVideoDriver(int index) /* * Initialize the video and event subsystems -- determine native pixel format */ -int #if SDL_VERSION_ATLEAST(1,3,0) -SDL_VideoInit +int SDL_VideoInit #else -SDL_VideoInit_1_3 +int SDL_VideoInit_1_3 #endif (const char *driver_name, Uint32 flags) { @@ -207,6 +207,7 @@ SDL_VideoInit_1_3 SDL_VideoQuit(); } +#if SDL_VERSION_ATLEAST(1,3,0) /* Toggle the event thread flags, based on OS requirements */ #if defined(MUST_THREAD_EVENTS) flags |= SDL_INIT_EVENTTHREAD; @@ -221,10 +222,11 @@ SDL_VideoInit_1_3 if (SDL_StartEventLoop(flags) < 0) { return -1; } - +#endif /* Select the proper video driver */ index = 0; video = NULL; +#if SDL_VERSION_ATLEAST(1,3,0) if (driver_name == NULL) { driver_name = SDL_getenv("SDL_VIDEODRIVER"); } @@ -253,8 +255,14 @@ SDL_VideoInit_1_3 } return -1; } + _this = video; _this->name = bootstrap[i]->name; +#else + video = ANDROID_CreateDevice_1_3(0); + _this = video; + _this->name = "android"; +#endif _this->next_object_id = 1; @@ -900,6 +908,8 @@ SDL_GetDisplayPalette(SDL_Color * colors, int firstcolor, int ncolors) return SDL_GetPaletteForDisplay(SDL_CurrentDisplay, colors, firstcolor, ncolors); } +#endif + SDL_Window * SDL_CreateWindow(const char *title, int x, int y, int w, int h, Uint32 flags) { @@ -911,6 +921,7 @@ SDL_CreateWindow(const char *title, int x, int y, int w, int h, Uint32 flags) SDL_VideoDisplay *display; SDL_Window *window; +#if SDL_VERSION_ATLEAST(1,3,0) if (!_this) { /* Initialize the video system if needed */ if (SDL_VideoInit(NULL, 0) < 0) { @@ -924,6 +935,8 @@ SDL_CreateWindow(const char *title, int x, int y, int w, int h, Uint32 flags) } SDL_GL_LoadLibrary(NULL); } +#endif + display = SDL_CurrentDisplay; window = (SDL_Window *)SDL_calloc(1, sizeof(*window)); window->magic = &_this->window_magic; @@ -940,6 +953,7 @@ SDL_CreateWindow(const char *title, int x, int y, int w, int h, Uint32 flags) } display->windows = window; +#if SDL_VERSION_ATLEAST(1,3,0) if (_this->CreateWindow && _this->CreateWindow(_this, window) < 0) { SDL_DestroyWindow(window); return NULL; @@ -958,10 +972,13 @@ SDL_CreateWindow(const char *title, int x, int y, int w, int h, Uint32 flags) SDL_ShowWindow(window); } SDL_UpdateWindowGrab(window); +#endif return window; } +#if SDL_VERSION_ATLEAST(1,3,0) + SDL_Window * SDL_CreateWindowFrom(const void *data) { @@ -1558,6 +1575,7 @@ SDL_CreateRenderer(SDL_Window * window, int index, Uint32 flags) /* Free any existing renderer */ SDL_DestroyRenderer(window); +#if SDL_VERSION_ATLEAST(1,3,0) if (index < 0) { char *override = SDL_getenv("SDL_VIDEO_RENDERER"); int n = SDL_GetNumRenderDrivers(); @@ -1611,6 +1629,9 @@ SDL_CreateRenderer(SDL_Window * window, int index, Uint32 flags) /* Create a new renderer instance */ window->renderer = SDL_CurrentDisplay->render_drivers[index].CreateRenderer(window, flags); } +#else + window->renderer = GL_ES_RenderDriver.CreateRenderer(window, flags); +#endif if (window->renderer == NULL) { /* Assuming renderer set its error */ diff --git a/alienblaster/project/sdl/sdl-1.3/src/video/android/SDL_androidvideo-1.3.c b/alienblaster/project/sdl/sdl-1.3/src/video/android/SDL_androidvideo-1.3.c index 58cc913d8..c5ffe1f68 100644 --- a/alienblaster/project/sdl/sdl-1.3/src/video/android/SDL_androidvideo-1.3.c +++ b/alienblaster/project/sdl/sdl-1.3/src/video/android/SDL_androidvideo-1.3.c @@ -59,11 +59,6 @@ static void ANDROID_PumpEvents(_THIS); /* ANDROID driver bootstrap functions */ -static int ANDROID_Available(void) -{ - return 1; -} - static void ANDROID_DeleteDevice(SDL_VideoDevice *device) { SDL_free(device); diff --git a/alienblaster/project/sdl/sdl-1.3/src/video/android/SDL_androidvideo.h b/alienblaster/project/sdl/sdl-1.3/src/video/android/SDL_androidvideo.h index 7221daaed..b95af6cf8 100644 --- a/alienblaster/project/sdl/sdl-1.3/src/video/android/SDL_androidvideo.h +++ b/alienblaster/project/sdl/sdl-1.3/src/video/android/SDL_androidvideo.h @@ -24,8 +24,6 @@ #ifndef _SDL_androidvideo_h #define _SDL_androidvideo_h -#include "../SDL_sysvideo.h" - extern void ANDROID_InitOSKeymap(); extern int SDL_ANDROID_sWindowWidth; @@ -33,7 +31,8 @@ extern int SDL_ANDROID_sWindowHeight; extern int SDL_ANDROID_sFakeWindowWidth; // SDL 1.2 only extern int SDL_ANDROID_sFakeWindowHeight; // SDL 1.2 only extern int SDL_ANDROID_CallJavaSwapBuffers(); - +// typedef struct SDL_VideoDevice SDL_VideoDevice; +extern SDL_VideoDevice *ANDROID_CreateDevice_1_3(int devindex); // Keycodes ripped from Java SDK enum KEYCODES_ANDROID