Fixed lots of little bugs in Win32 shaping and in SDL_CalculateShapeTree(). Still not actually showing anything on Windows, though there's no crashes and everything compiles fine. Bugger.
authoregottlieb
Fri, 06 Aug 2010 20:22:14 -0400
changeset 48372e446923c9fb
parent 4836 7eb8ca721a5b
child 4839 05d172e92b52
Fixed lots of little bugs in Win32 shaping and in SDL_CalculateShapeTree(). Still not actually showing anything on Windows, though there's no crashes and everything compiles fine. Bugger.
src/video/SDL_shape.c
src/video/SDL_shape_internals.h
src/video/win32/SDL_win32shape.c
test/testshape.c
     1.1 --- a/src/video/SDL_shape.c	Fri Aug 06 13:52:38 2010 -0400
     1.2 +++ b/src/video/SDL_shape.c	Fri Aug 06 20:22:14 2010 -0400
     1.3 @@ -111,18 +111,18 @@
     1.4  		SDL_UnlockSurface(shape);
     1.5  }
     1.6  
     1.7 -SDL_ShapeTree* RecursivelyCalculateShapeTree(SDL_WindowShapeMode mode,SDL_Surface* mask,SDL_bool invert,SDL_Rect dimensions) {
     1.8 +SDL_ShapeTree* RecursivelyCalculateShapeTree(SDL_WindowShapeMode mode,SDL_Surface* mask,SDL_Rect dimensions) {
     1.9  	int x = 0,y = 0;
    1.10  	Uint8* pixel = NULL;
    1.11  	Uint32 pixel_value = 0;
    1.12  	Uint8 r = 0,g = 0,b = 0,a = 0;
    1.13 -	SDL_bool pixel_transparent = SDL_FALSE;
    1.14 -	int last_transparent = -1;
    1.15 +	SDL_bool pixel_opaque = SDL_FALSE;
    1.16 +	int last_opaque = -1;
    1.17  	SDL_Color key;
    1.18  	SDL_ShapeTree* result = (SDL_ShapeTree*)SDL_malloc(sizeof(SDL_ShapeTree));
    1.19  	SDL_Rect next = {0,0,0,0};
    1.20 -	for(y=dimensions.y;y<dimensions.h;y++)
    1.21 -		for(x=dimensions.x;x<dimensions.w;x++) {
    1.22 +	for(y=dimensions.y;y<dimensions.y + dimensions.h;y++)
    1.23 +		for(x=dimensions.x;x<dimensions.x + dimensions.w;x++) {
    1.24  			pixel_value = 0;
    1.25  			pixel = (Uint8 *)(mask->pixels) + (y*mask->pitch) + (x*mask->format->BytesPerPixel);
    1.26  			switch(mask->format->BytesPerPixel) {
    1.27 @@ -142,24 +142,22 @@
    1.28  			SDL_GetRGBA(pixel_value,mask->format,&r,&g,&b,&a);
    1.29  			switch(mode.mode) {
    1.30  				case(ShapeModeDefault):
    1.31 -					pixel_transparent = (SDL_bool)(a >= 1 ? !invert : invert);
    1.32 +					pixel_opaque = (a >= 1 ? SDL_TRUE : SDL_FALSE);
    1.33  					break;
    1.34  				case(ShapeModeBinarizeAlpha):
    1.35 -					pixel_transparent = (SDL_bool)(a >= mode.parameters.binarizationCutoff ? !invert : invert);
    1.36 +					pixel_opaque = (a >= mode.parameters.binarizationCutoff ? SDL_TRUE : SDL_FALSE);
    1.37  					break;
    1.38  				case(ShapeModeReverseBinarizeAlpha):
    1.39 -					pixel_transparent = (SDL_bool)(a <= mode.parameters.binarizationCutoff ? !invert : invert);
    1.40 +					pixel_opaque = (a <= mode.parameters.binarizationCutoff ? SDL_TRUE : SDL_FALSE);
    1.41  					break;
    1.42  				case(ShapeModeColorKey):
    1.43  					key = mode.parameters.colorKey;
    1.44 -					pixel_transparent = (SDL_bool)((key.r == r && key.g == g && key.b == b) ? !invert : invert);
    1.45 +					pixel_opaque = ((key.r == r && key.g == g && key.b == b) ? SDL_TRUE : SDL_FALSE);
    1.46  					break;
    1.47  			}
    1.48 -			if(last_transparent == -1) {
    1.49 -				last_transparent = pixel_transparent;
    1.50 -				break;
    1.51 -			}
    1.52 -			if(last_transparent != pixel_transparent) {
    1.53 +			if(last_opaque == -1)
    1.54 +				last_opaque = pixel_opaque;
    1.55 +			if(last_opaque != pixel_opaque) {
    1.56  				result->kind = QuadShape;
    1.57  				//These will stay the same.
    1.58  				next.w = dimensions.w / 2;
    1.59 @@ -167,31 +165,31 @@
    1.60  				//These will change from recursion to recursion.
    1.61  				next.x = dimensions.x;
    1.62  				next.y = dimensions.y;
    1.63 -				result->data.children.upleft = (struct SDL_ShapeTree *)RecursivelyCalculateShapeTree(mode,mask,invert,next);
    1.64 +				result->data.children.upleft = (struct SDL_ShapeTree *)RecursivelyCalculateShapeTree(mode,mask,next);
    1.65  				next.x = dimensions.w / 2;
    1.66  				//Unneeded: next.y = dimensions.y;
    1.67 -				result->data.children.upright = (struct SDL_ShapeTree *)RecursivelyCalculateShapeTree(mode,mask,invert,next);
    1.68 +				result->data.children.upright = (struct SDL_ShapeTree *)RecursivelyCalculateShapeTree(mode,mask,next);
    1.69  				next.x = dimensions.x;
    1.70  				next.y = dimensions.h / 2;
    1.71 -				result->data.children.downleft = (struct SDL_ShapeTree *)RecursivelyCalculateShapeTree(mode,mask,invert,next);
    1.72 +				result->data.children.downleft = (struct SDL_ShapeTree *)RecursivelyCalculateShapeTree(mode,mask,next);
    1.73  				next.x = dimensions.w / 2;
    1.74  				//Unneeded: next.y = dimensions.h / 2 + 1;
    1.75 -				result->data.children.downright = (struct SDL_ShapeTree *)RecursivelyCalculateShapeTree(mode,mask,invert,next);
    1.76 +				result->data.children.downright = (struct SDL_ShapeTree *)RecursivelyCalculateShapeTree(mode,mask,next);
    1.77  				return result;
    1.78  			}
    1.79  		}
    1.80  	//If we never recursed, all the pixels in this quadrant have the same "value".
    1.81 -	result->kind = (last_transparent == SDL_FALSE ? OpaqueShape : TransparentShape);
    1.82 +	result->kind = (last_opaque == SDL_TRUE ? OpaqueShape : TransparentShape);
    1.83  	result->data.shape = dimensions;
    1.84  	return result;
    1.85  }
    1.86  
    1.87 -SDL_ShapeTree* SDL_CalculateShapeTree(SDL_WindowShapeMode mode,SDL_Surface* shape,SDL_bool invert) {
    1.88 +SDL_ShapeTree* SDL_CalculateShapeTree(SDL_WindowShapeMode mode,SDL_Surface* shape) {
    1.89  	SDL_Rect dimensions = {0,0,shape->w,shape->h};
    1.90  	SDL_ShapeTree* result = NULL;
    1.91  	if(SDL_MUSTLOCK(shape))
    1.92  		SDL_LockSurface(shape);
    1.93 -	result = RecursivelyCalculateShapeTree(mode,shape,invert,dimensions);
    1.94 +	result = RecursivelyCalculateShapeTree(mode,shape,dimensions);
    1.95  	if(SDL_MUSTLOCK(shape))
    1.96  		SDL_UnlockSurface(shape);
    1.97  	return result;
     2.1 --- a/src/video/SDL_shape_internals.h	Fri Aug 06 13:52:38 2010 -0400
     2.2 +++ b/src/video/SDL_shape_internals.h	Fri Aug 06 20:22:14 2010 -0400
     2.3 @@ -55,7 +55,7 @@
     2.4  typedef void(*SDL_TraversalFunction)(SDL_ShapeTree*,void*);
     2.5  
     2.6  extern void SDL_CalculateShapeBitmap(SDL_WindowShapeMode mode,SDL_Surface *shape,Uint8* bitmap,Uint8 ppb);
     2.7 -extern SDL_ShapeTree* SDL_CalculateShapeTree(SDL_WindowShapeMode mode,SDL_Surface* shape,SDL_bool invert);
     2.8 +extern SDL_ShapeTree* SDL_CalculateShapeTree(SDL_WindowShapeMode mode,SDL_Surface* shape);
     2.9  extern void SDL_TraverseShapeTree(SDL_ShapeTree *tree,SDL_TraversalFunction function,void* closure);
    2.10  extern void SDL_FreeShapeTree(SDL_ShapeTree** shapeTree);
    2.11  
     3.1 --- a/src/video/win32/SDL_win32shape.c	Fri Aug 06 13:52:38 2010 -0400
     3.2 +++ b/src/video/win32/SDL_win32shape.c	Fri Aug 06 20:22:14 2010 -0400
     3.3 @@ -20,6 +20,7 @@
     3.4      eligottlieb@gmail.com
     3.5  */
     3.6  
     3.7 +#include "SDL_assert.h"
     3.8  #include "SDL_win32shape.h"
     3.9  #include "SDL_win32video.h"
    3.10  
    3.11 @@ -43,9 +44,12 @@
    3.12  
    3.13  void CombineRectRegions(SDL_ShapeTree* node, void* closure) {
    3.14  	HRGN* mask_region = (HRGN *)closure;
    3.15 +	int combined = -1;
    3.16  	if(node->kind == OpaqueShape) {
    3.17  		HRGN temp_region = CreateRectRgn(node->data.shape.x,node->data.shape.y,node->data.shape.w,node->data.shape.h);
    3.18 -		CombineRgn(*mask_region,*mask_region,temp_region, RGN_OR);
    3.19 +		SDL_assert(temp_region != NULL);
    3.20 +		combined = CombineRgn(*mask_region,*mask_region,temp_region, RGN_OR);
    3.21 +		SDL_assert(combined == SIMPLEREGION || combined == COMPLEXREGION);
    3.22  		DeleteObject(temp_region);
    3.23  	}
    3.24  }
    3.25 @@ -64,7 +68,7 @@
    3.26  	data = (SDL_ShapeData*)shaper->driverdata;
    3.27  	if(data->mask_tree != NULL)
    3.28  		SDL_FreeShapeTree(&data->mask_tree);
    3.29 -	data->mask_tree = SDL_CalculateShapeTree(*shapeMode,shape,SDL_FALSE);
    3.30 +	data->mask_tree = SDL_CalculateShapeTree(*shapeMode,shape);
    3.31  	
    3.32  	/*
    3.33  	 * Start with empty region 
    3.34 @@ -78,7 +82,7 @@
    3.35  	 */
    3.36  	windowdata=(SDL_WindowData *)(shaper->window->driverdata);
    3.37  	hwnd = windowdata->hwnd;
    3.38 -	SetWindowRgn(hwnd, mask_region, TRUE);
    3.39 +	SDL_assert(SetWindowRgn(hwnd, mask_region, TRUE) != 0);
    3.40  	
    3.41  	return 0;
    3.42  }
     4.1 --- a/test/testshape.c	Fri Aug 06 13:52:38 2010 -0400
     4.2 +++ b/test/testshape.c	Fri Aug 06 20:22:14 2010 -0400
     4.3 @@ -44,7 +44,6 @@
     4.4  	LoadedPicture* pictures;
     4.5  	int i, j;
     4.6  	SDL_PixelFormat* format = NULL;
     4.7 -	Uint32 format_enum;
     4.8  	SDL_Window *window;
     4.9  	SDL_Color black = {0,0,0,0xff};
    4.10  	SDL_Event event;