Alien Blaster + SDL 1.2 outputs something to screen with HW acceleration, but colorkey is messed up

This commit is contained in:
pelya
2010-07-28 19:08:06 +03:00
parent 61a7428798
commit e2dc681037
5 changed files with 50 additions and 17 deletions

View File

@@ -26,6 +26,7 @@
#include "SDL_blit.h"
#include "SDL_RLEaccel_c.h"
#include "SDL_pixels_c.h"
#include <android/log.h>
#if defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__)) && SDL_ASSEMBLY_ROUTINES
#define MMX_ASMBLIT
@@ -242,6 +243,7 @@ int SDL_CalculateBlit(SDL_Surface *surface)
/* Figure out if an accelerated hardware blit is possible */
surface->flags &= ~SDL_HWACCEL;
//__android_log_print(ANDROID_LOG_INFO, "libSDL", "SDL_CalculateBlit(): identity %d src hw %d dst hw %d video hw %d", (int)surface->map->identity, (int)(surface->flags & SDL_HWSURFACE), (int)(surface->map->dst->flags & SDL_HWSURFACE), (int)(current_video->info.blit_hw));
if ( surface->map->identity ) {
int hw_blit_ok;

View File

@@ -176,15 +176,6 @@ static SDL_VideoDevice *ANDROID_CreateDevice(int devindex)
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;
}
@@ -272,13 +263,13 @@ SDL_Surface *ANDROID_SetVideoMode(_THIS, SDL_Surface *current,
// We're not allowing locking videosurface yet
/*
memBuffer = SDL_malloc(memX * memY * ANDROID_BYTESPERPIXEL);
memBuffer = SDL_malloc(width * height * 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(memBuffer, 0, memX * memY * ANDROID_BYTESPERPIXEL);
SDL_memset(memBuffer, 0, width * height * ANDROID_BYTESPERPIXEL);
*/
}
@@ -297,12 +288,21 @@ SDL_Surface *ANDROID_SetVideoMode(_THIS, SDL_Surface *current,
}
/* Set up the new mode framebuffer */
current->flags = (flags & SDL_FULLSCREEN) | (flags & SDL_OPENGL) | SDL_DOUBLEBUF | SDL_HWSURFACE;
current->flags = (flags & SDL_FULLSCREEN) | (flags & SDL_OPENGL) | SDL_DOUBLEBUF | SDL_HWSURFACE | SDL_HWACCEL;
current->w = width;
current->h = height;
current->pitch = SDL_ANDROID_sFakeWindowWidth * ANDROID_BYTESPERPIXEL;
current->pixels = memBuffer;
SDL_CurrentVideoSurface = current;
this->info.hw_available = 1;
this->info.blit_hw = 1;
this->info.blit_hw_CC = 1;
this->info.blit_hw_A = 1;
this->info.blit_fill = 1;
this->info.video_mem = 128 * 1024;
this->info.current_w = SDL_ANDROID_sWindowWidth;
this->info.current_h = SDL_ANDROID_sWindowHeight;
/* We're done */
return(current);
@@ -316,6 +316,8 @@ void ANDROID_VideoQuit(_THIS)
if( ! sdl_opengl )
{
SDL_CurrentVideoSurface = NULL;
SDL_DestroyWindow(SDL_VideoWindow);
SDL_VideoWindow = NULL;
}
SDL_ANDROID_sFakeWindowWidth = 0;
@@ -346,6 +348,7 @@ static int ANDROID_AllocHWSurface(_THIS, SDL_Surface *surface)
if ( ! (surface->w && surface->h) )
return(-1);
//Uint32 format = SDL_PIXELFORMAT_RGB565;
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 )
{
@@ -380,6 +383,8 @@ static int ANDROID_AllocHWSurface(_THIS, SDL_Surface *surface)
return(-1);
}
surface->flags |= SDL_HWSURFACE | SDL_HWACCEL;
return 0;
}
@@ -406,6 +411,7 @@ static int ANDROID_LockHWSurface(_THIS, SDL_Surface *surface)
static void ANDROID_UnlockHWSurface(_THIS, SDL_Surface *surface)
{
SDL_PixelFormat format;
//Uint32 hwformat = SDL_PIXELFORMAT_RGB565;
Uint32 hwformat = SDL_PIXELFORMAT_RGBA5551;
int bpp;
SDL_Surface * converted = NULL;
@@ -434,6 +440,9 @@ static void ANDROID_UnlockHWSurface(_THIS, SDL_Surface *surface)
}
else
{
converted = surface;
// TODO: crashes here, manual conversion routine necessary?
/*
Uint8 oldAlpha = surface->format->alpha;
converted = SDL_CreateRGBSurface(SDL_SWSURFACE, surface->w, surface->h, format.BitsPerPixel,
format.Rmask, format.Gmask, format.Bmask, format.Amask);
@@ -443,8 +452,13 @@ static void ANDROID_UnlockHWSurface(_THIS, SDL_Surface *surface)
}
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
SDL_Rect src, dst;
src.x = dst.x = src.y = dst.y = 0;
src.w = dst.w = surface->w;
src.h = dst.h = surface->h;
SDL_UpperBlit( surface, &src, converted, &dst ); // Should take into account colorkey
surface->format->alpha = oldAlpha;
*/
}
SDL_Rect rect;
@@ -461,10 +475,12 @@ static void ANDROID_UnlockHWSurface(_THIS, SDL_Surface *surface)
// 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 )
if( dst != SDL_CurrentVideoSurface || (! src->hwdata) )
{
//__android_log_print(ANDROID_LOG_INFO, "libSDL", "ANDROID_HWBlit(): blitting SW");
return(src->map->sw_blit(src, srcrect, dst, dstrect));
}
//__android_log_print(ANDROID_LOG_INFO, "libSDL", "ANDROID_HWBlit(): blitting HW");
return SDL_RenderCopy((struct SDL_Texture *)src->hwdata, srcrect, dstrect);
};
@@ -476,7 +492,9 @@ static int ANDROID_CheckHWBlit(_THIS, SDL_Surface *src, SDL_Surface *dst)
if( dst != SDL_CurrentVideoSurface || ! src->hwdata )
return(-1);
*/
//__android_log_print(ANDROID_LOG_INFO, "libSDL", "ANDROID_CheckHWBlit()");
src->map->hw_blit = ANDROID_HWBlit;
src->flags |= SDL_HWACCEL;
return(0);
};
@@ -525,6 +543,7 @@ static int ANDROID_SetHWAlpha(_THIS, SDL_Surface *surface, Uint8 value)
static void ANDROID_UpdateRects(_THIS, int numrects, SDL_Rect *rects)
{
//__android_log_print(ANDROID_LOG_INFO, "libSDL", "ANDROID_UpdateRects()");
// Used only in single-buffer mode
ANDROID_FlipHWSurface(this, SDL_CurrentVideoSurface);
}
@@ -532,6 +551,8 @@ static void ANDROID_UpdateRects(_THIS, int numrects, SDL_Rect *rects)
static int ANDROID_FlipHWSurface(_THIS, SDL_Surface *surface)
{
//__android_log_print(ANDROID_LOG_INFO, "libSDL", "ANDROID_FlipHWSurface()");
SDL_ANDROID_CallJavaSwapBuffers();
return(0);

View File

@@ -133,7 +133,7 @@ void ANDROID_PumpEvents(_THIS)
void ANDROID_GL_SwapBuffers(_THIS, SDL_Window * window)
{
//SDL_ANDROID_CallJavaSwapBuffers();
SDL_ANDROID_CallJavaSwapBuffers();
};
SDL_GLContext ANDROID_GL_CreateContext(_THIS, SDL_Window * window)

View File

@@ -369,6 +369,7 @@ GLES_ActivateRenderer(SDL_Renderer * renderer)
data->glMatrixMode(GL_MODELVIEW);
data->glLoadIdentity();
#if SDL_VIDEO_RENDER_RESIZE
__android_log_print(ANDROID_LOG_INFO, "libSDL", "GLES_ActivateRenderer(): %dx%d", (int)window->display->desktop_mode.w, (int)window->display->desktop_mode.h);
data->glViewport(0, 0, window->display->desktop_mode.w, window->display->desktop_mode.h);
data->glOrthof(0.0, (GLfloat) window->display->desktop_mode.w, (GLfloat) window->display->desktop_mode.h,
0.0, 0.0, 1.0);
@@ -950,6 +951,11 @@ GLES_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture,
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 */
SDL_Window *window = renderer->window;
__android_log_print(ANDROID_LOG_INFO, "libSDL", "GLES_RenderCopy(): %dx%d+%d+%d -> %dx%d+%d+%d",
(int)srcrect->x, (int)srcrect->y, (int)srcrect->w, (int)srcrect->h,
(int)dstrect->x, (int)dstrect->y, (int)dstrect->w, (int)dstrect->h);
GLint cropRect[4];
cropRect[0] = srcrect->x;
cropRect[1] = srcrect->y + srcrect->h;

View File

@@ -1485,6 +1485,8 @@ SDL_GetFocusWindow(void)
return NULL;
}
#endif
void
SDL_DestroyWindow(SDL_Window * window)
{
@@ -1500,15 +1502,19 @@ SDL_DestroyWindow(SDL_Window * window)
SDL_DestroyRenderer(window);
}
#if SDL_VERSION_ATLEAST(1,3,0)
/* Restore video mode, etc. */
SDL_UpdateFullscreenMode(window, SDL_FALSE);
#endif
if (_this->DestroyWindow) {
_this->DestroyWindow(_this, window);
}
#if SDL_VERSION_ATLEAST(1,3,0)
if (window->flags & SDL_WINDOW_OPENGL) {
SDL_GL_UnloadLibrary();
}
#endif
/* Unlink the window from the list */
display = window->display;
@@ -1524,8 +1530,6 @@ SDL_DestroyWindow(SDL_Window * window)
SDL_free(window);
}
#endif
void
SDL_AddRenderDriver(SDL_VideoDisplay * display, const SDL_RenderDriver * driver)
{