diff --git a/project/jni/application/alienblaster/SdlForwardCompat.h b/project/jni/application/alienblaster/SdlForwardCompat.h index ce1ac0782..6fe56dac1 100644 --- a/project/jni/application/alienblaster/SdlForwardCompat.h +++ b/project/jni/application/alienblaster/SdlForwardCompat.h @@ -18,9 +18,7 @@ struct SdlCompat_AcceleratedSurface { SDL_Texture * t; - SDL_Surface * s; int w, h; - int flags; SDL_PixelFormat * format; }; @@ -30,17 +28,16 @@ static inline SdlCompat_AcceleratedSurface * SdlCompat_CreateAcceleratedSurface( // Allocate accelerated surface even if that means loss of color quality Uint32 format; - format = SDL_PIXELFORMAT_RGB565; - - if( surface->flags & SDL_SRCCOLORKEY ) - format = SDL_PIXELFORMAT_RGBA5551; - ret->s = SDL_ConvertSurface( surface, surface->format, 0 ); - ret->t = SDL_CreateTextureFromSurface(format, ret->s); - ret->w = surface->w; ret->h = surface->h; ret->format = new SDL_PixelFormat(); *(ret->format) = *(surface->format); + + format = SDL_PIXELFORMAT_RGB565; + if( surface->flags & SDL_SRCCOLORKEY ) + format = SDL_PIXELFORMAT_RGBA5551; + + ret->t = SDL_CreateTextureFromSurface(format, surface); if( ! ret->t ) { @@ -48,7 +45,6 @@ static inline SdlCompat_AcceleratedSurface * SdlCompat_CreateAcceleratedSurface( return ret; } - ret->flags = surface->flags; if( surface->flags & SDL_SRCALPHA ) { SDL_SetTextureBlendMode( ret->t, SDL_BLENDMODE_BLEND ); @@ -69,7 +65,6 @@ static inline int SDL_BlitSurface( SdlCompat_AcceleratedSurface * src, SDL_Rect static inline void SDL_FreeSurface(SdlCompat_AcceleratedSurface * surface) { SDL_DestroyTexture(surface->t); - SDL_FreeSurface(surface->s); delete surface->format; delete surface; }; @@ -95,7 +90,7 @@ static inline int SDL_SetAlpha(SdlCompat_AcceleratedSurface * surface, Uint32 fl return SDL_SetTextureAlphaMod(surface->t, alpha); }; -static inline void SdlCompat_ReloadSurfaceToVideoMemory(SdlCompat_AcceleratedSurface * surface) +static inline void SdlCompat_ReloadSurfaceToVideoMemory(SdlCompat_AcceleratedSurface * surface, SDL_Surface * src) { SDL_DestroyTexture(surface->t); @@ -103,21 +98,21 @@ static inline void SdlCompat_ReloadSurfaceToVideoMemory(SdlCompat_AcceleratedSur Uint32 format; format = SDL_PIXELFORMAT_RGB565; - if( surface->flags & SDL_SRCCOLORKEY ) + if( src->flags & SDL_SRCCOLORKEY ) format = SDL_PIXELFORMAT_RGBA5551; - surface->t = SDL_CreateTextureFromSurface(format, surface->s); + surface->t = SDL_CreateTextureFromSurface(format, src); if( ! surface->t ) { - SDL_SetError("SdlCompat_CreateAcceleratedSurface: Cannot allocate HW texture, W %d H %d format %x surface->flags %x", surface->w, surface->h, format, surface->flags ); + SDL_SetError("SdlCompat_CreateAcceleratedSurface: Cannot allocate HW texture, W %d H %d format %x surface->flags %x", surface->w, surface->h, format, src->flags ); return; } - if( surface->flags & SDL_SRCALPHA ) + if( src->flags & SDL_SRCALPHA ) { SDL_SetTextureBlendMode( surface->t, SDL_BLENDMODE_BLEND ); Uint8 alpha = 128; - if( SDL_GetSurfaceAlphaMod( surface->s, &alpha ) < 0 ) + if( SDL_GetSurfaceAlphaMod( src, &alpha ) < 0 ) alpha = 128; SDL_SetTextureAlphaMod( surface->t, alpha ); } @@ -132,7 +127,7 @@ static inline SdlCompat_AcceleratedSurface * SdlCompat_CreateAcceleratedSurface( return SDL_ConvertSurface(surface, surface->format, surface->flags | SDL_HWSURFACE); }; -static inline void SdlCompat_ReloadSurfaceToVideoMemory(SDL_Surface * surface) +static inline void SdlCompat_ReloadSurfaceToVideoMemory(SDL_Surface * surface, SDL_Surface * src) { }; diff --git a/project/jni/application/alienblaster/surfaceDB.cpp b/project/jni/application/alienblaster/surfaceDB.cpp index cc71679ba..7ce038b67 100644 --- a/project/jni/application/alienblaster/surfaceDB.cpp +++ b/project/jni/application/alienblaster/surfaceDB.cpp @@ -41,16 +41,30 @@ SurfaceDB::~SurfaceDB() { StringSurfaceMap::iterator pos; // free all surfaces for ( pos = surfaceDB.begin(); pos != surfaceDB.end(); ++pos ) { - SDL_FreeSurface( pos->second ); + SDL_FreeSurface( pos->second.first ); } } SdlCompat_AcceleratedSurface *SurfaceDB::loadSurface( string fn, bool alpha ) { - SdlCompat_AcceleratedSurface *searchResult = getSurface( fn ); if ( searchResult ) { return searchResult; } + + SDL_Surface * newSurface = loadSurfaceInternal(fn, alpha); + + surfaceDB[ fn ] = std::make_pair( SdlCompat_CreateAcceleratedSurface( newSurface ), alpha ); + SDL_FreeSurface(newSurface); + + if ( alpha ) { + SDL_SetAlpha( surfaceDB[ fn ].first, SDL_SRCALPHA, 128 ); + } + + return surfaceDB[ fn ].first; +} + +SDL_Surface *SurfaceDB::loadSurfaceInternal( string fn, bool alpha ) { + __android_log_print(ANDROID_LOG_INFO, "Alien Blaster", (string( "Loading image " ) + fn).c_str() ); string fn1 = fn; @@ -92,15 +106,8 @@ SdlCompat_AcceleratedSurface *SurfaceDB::loadSurface( string fn, bool alpha ) { SDL_FreeSurface(newSurface); newSurface = hwSurface; } - - surfaceDB[ fn ] = SdlCompat_CreateAcceleratedSurface( newSurface ); - SDL_FreeSurface(newSurface); - - if ( alpha ) { - SDL_SetAlpha( surfaceDB[ fn ], SDL_SRCALPHA, 128 ); - } - - return surfaceDB[ fn ]; + + return newSurface; } SdlCompat_AcceleratedSurface *SurfaceDB::getSurface( string fn ) { @@ -111,7 +118,7 @@ SdlCompat_AcceleratedSurface *SurfaceDB::getSurface( string fn ) { if ( pos == surfaceDB.end() ) { return 0; } else { - return pos->second; + return pos->second.first; } } } @@ -120,6 +127,6 @@ void SurfaceDB::reloadAllSurfacesToVideoMemory() { for( StringSurfaceMap::iterator it = surfaceDB.begin(); it != surfaceDB.end(); it++ ) { - SdlCompat_ReloadSurfaceToVideoMemory( it->second ); + SdlCompat_ReloadSurfaceToVideoMemory( it->second.first, loadSurfaceInternal( it->first, it->second.second ) ); } }; diff --git a/project/jni/application/alienblaster/surfaceDB.h b/project/jni/application/alienblaster/surfaceDB.h index c543d7ef6..e7a197fee 100644 --- a/project/jni/application/alienblaster/surfaceDB.h +++ b/project/jni/application/alienblaster/surfaceDB.h @@ -28,7 +28,7 @@ #include #include -typedef std::map > StringSurfaceMap; +typedef std::map, std::greater > StringSurfaceMap; class SurfaceDB; @@ -57,6 +57,8 @@ class SurfaceDB { StringSurfaceMap surfaceDB; Uint8 transR, transG, transB; + SDL_Surface *loadSurfaceInternal( std::string fn, bool alpha ); + SdlCompat_AcceleratedSurface *getSurface( std::string fn ); }; diff --git a/project/sdl/sdl-1.3/src/video/android/SDL_androidvideo.c b/project/sdl/sdl-1.3/src/video/android/SDL_androidvideo.c index c691b5bef..b02860fd0 100644 --- a/project/sdl/sdl-1.3/src/video/android/SDL_androidvideo.c +++ b/project/sdl/sdl-1.3/src/video/android/SDL_androidvideo.c @@ -80,7 +80,7 @@ int SDL_ANDROID_CallJavaSwapBuffers() glContextLost = 0; __android_log_print(ANDROID_LOG_INFO, "libSDL", "OpenGL context recreated, refreshing textures"); SDL_ANDROID_VideoContextRecreated(); - appRestoredCallbackDefault(); + appRestoredCallback(); } } @@ -113,7 +113,7 @@ JAVA_EXPORT_NAME(DemoRenderer_nativeGlContextLost) ( JNIEnv* env, jobject thiz { __android_log_print(ANDROID_LOG_INFO, "libSDL", "OpenGL context lost, waiting for new OpenGL context"); glContextLost = 1; - appPutToBackgroundCallbackDefault(); + appPutToBackgroundCallback(); SDL_ANDROID_VideoContextLost(); }