Mercurial > sdl-ios-xcode
changeset 4800:6d4be626225f
Same place as before, but optimizing a bit to try to isolate the spot in the program that locks things up.
author | Eli Gottlieb <eligottlieb@gmail.com> |
---|---|
date | Sun, 18 Jul 2010 22:17:52 -0400 |
parents | a0e096916474 |
children | 506a9165491b |
files | test/testshape.c |
diffstat | 1 files changed, 24 insertions(+), 17 deletions(-) [+] |
line wrap: on
line diff
--- a/test/testshape.c Sun Jul 18 21:31:22 2010 -0400 +++ b/test/testshape.c Sun Jul 18 22:17:52 2010 -0400 @@ -40,7 +40,9 @@ } //THIS CONVERSION ROUTINE IS FRAGILE! It relies in the fact that only certain portions of the format structure must be filled in to use it. SDL_PixelFormat format = {NULL,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; - SDL_PixelFormatEnumToMasks(SDL_PIXELFORMAT_RGBA8888,&format.BitsPerPixel,&format.Rmask,&format.Gmask,&format.Bmask,&format.Amask); + int bpp = 0; + SDL_PixelFormatEnumToMasks(SDL_PIXELFORMAT_RGBA8888,&bpp,&format.Rmask,&format.Gmask,&format.Bmask,&format.Amask); + format.BitsPerPixel = bpp; format.BytesPerPixel = format.BitsPerPixel / 8 + (format.BitsPerPixel % 8 > 0 ? 1 : 0); pictures[i] = SDL_ConvertSurface(original,&format,0); //We have no more need of the original now that we have our desired format. @@ -64,11 +66,11 @@ int y =0,x = 0; for(y=0;y<pictures[i]->h;y++) for(x=0;x<pictures[i]->w;x++) { - Uint32* pixel = pixels+y*pitch+x*pictures[i]->format->BytesPerPixel; + Uint32* pixel = pixels + y * pitch + x * pictures[i]->format->BytesPerPixel; Uint8 r = 0,g = 0,b = 0; SDL_GetRGB(*pixel,pictures[i]->format,&r,&g,&b); - if(r == g == b == 0x00) - *pixel = SDL_MapRGBA(pictures[i]->format,r,g,b,0); + //if(r == g == b == 0xff) + // *pixel = SDL_MapRGBA(pictures[i]->format,r,g,b,0); } if(SDL_MUSTLOCK(pictures[i])) @@ -117,7 +119,7 @@ } SDL_Event event; - int event_pending = 0; + int event_pending = 0,should_exit = 0; event_pending = SDL_PollEvent(&event); unsigned int current_picture = 0; SDL_WindowShapeMode mode = {ShapeModeDefault,1}; @@ -127,17 +129,23 @@ SDL_Rect texture_dimensions = {0,0,0,0}; SDL_QueryTexture(textures[current_picture],&format,&access,&texture_dimensions.w,&texture_dimensions.h); SDL_SetWindowSize(window,texture_dimensions.w,texture_dimensions.h); - while(event.type != SDL_QUIT) { - if(event.type == SDL_MOUSEBUTTONDOWN) - mouse_down = 1; - if(mouse_down && event.type == SDL_MOUSEBUTTONUP) { - mouse_down = 0; - current_picture += 1; - if(current_picture >= num_pictures) - current_picture = 0; - SDL_QueryTexture(textures[current_picture],&format,&access,&texture_dimensions.w,&texture_dimensions.h); - SDL_SetWindowSize(window,texture_dimensions.w,texture_dimensions.h); - SDL_SetWindowShape(window,pictures[current_picture],&mode); + while(should_exit == 0) { + event_pending = SDL_PollEvent(&event); + if(event_pending == 1) { + if(event.type == SDL_MOUSEBUTTONDOWN) + mouse_down = 1; + if(mouse_down && event.type == SDL_MOUSEBUTTONUP) { + mouse_down = 0; + current_picture += 1; + if(current_picture >= num_pictures) + current_picture = 0; + SDL_QueryTexture(textures[current_picture],&format,&access,&texture_dimensions.w,&texture_dimensions.h); + SDL_SetWindowSize(window,texture_dimensions.w,texture_dimensions.h); + SDL_SetWindowShape(window,pictures[current_picture],&mode); + } + if(event.type == SDL_QUIT) + should_exit = 1; + event_pending = 0; } SDL_SelectRenderer(window); @@ -150,7 +158,6 @@ SDL_RenderCopy(textures[current_picture],&texture_dimensions,&texture_dimensions); SDL_RenderPresent(); - event_pending = SDL_PollEvent(&event); } //Free the textures.