Minor bugfixes. testshape now draws a shaped window with bizarre, pixellated gashes of transparency across it, and in doing so seems to hog a system resource and slow the rest of the video system down.
authorEli Gottlieb <eligottlieb@gmail.com>
Sun, 18 Jul 2010 23:05:40 -0400
changeset 4802f14a8c05f5bb
parent 4801 506a9165491b
child 4803 a4c1df880690
Minor bugfixes. testshape now draws a shaped window with bizarre, pixellated gashes of transparency across it, and in doing so seems to hog a system resource and slow the rest of the video system down.
src/video/SDL_shape.c
src/video/win32/SDL_win32shape.c
src/video/x11/SDL_x11shape.c
test/testshape.c
     1.1 --- a/src/video/SDL_shape.c	Sun Jul 18 22:24:52 2010 -0400
     1.2 +++ b/src/video/SDL_shape.c	Sun Jul 18 23:05:40 2010 -0400
     1.3 @@ -59,19 +59,30 @@
     1.4  	int x = 0;
     1.5  	int y = 0;
     1.6  	Uint8 r = 0,g = 0,b = 0,alpha = 0;
     1.7 -	Uint8* pixel;
     1.8 -	Uint32 bitmap_pixel;
     1.9 +	Uint8* pixel = NULL;
    1.10 +	Uint32 bitmap_pixel,pixel_value = 0;
    1.11  	if(SDL_MUSTLOCK(shape))
    1.12  		SDL_LockSurface(shape);
    1.13  	pixel = (Uint8*)shape->pixels;
    1.14  	for(y = 0;y<shape->h;y++) {
    1.15 -		pixel = (Uint8 *)(shape->pixels) + y * shape->pitch;
    1.16  		for(x=0;x<shape->w;x++) {
    1.17  			alpha = 0;
    1.18 -			SDL_GetRGBA(*(Uint32*)pixel,shape->format,&r,&g,&b,&alpha);
    1.19 +			pixel_value = 0;
    1.20 +			pixel = shape->pixels + y * shape->pitch + x * shape->format->BytesPerPixel;
    1.21 +			switch(shape->format->BytesPerPixel) {
    1.22 +				case(1):
    1.23 +					pixel_value = *(Uint8*)pixel;
    1.24 +					break;
    1.25 +				case(2):
    1.26 +					pixel_value = *(Uint16*)pixel;
    1.27 +					break;
    1.28 +				case(4):
    1.29 +					pixel_value = *(Uint32*)pixel;
    1.30 +					break;
    1.31 +			}
    1.32 +			SDL_GetRGBA(pixel_value,shape->format,&r,&g,&b,&alpha);
    1.33  			bitmap_pixel = y*shape->w + x;
    1.34  			bitmap[bitmap_pixel / ppb] |= (alpha >= alphacutoff ? value : 0) << ((ppb - 1) - (bitmap_pixel % ppb));
    1.35 -			pixel += shape->format->BytesPerPixel;
    1.36  		}
    1.37  	}
    1.38  	if(SDL_MUSTLOCK(shape))
    1.39 @@ -99,7 +110,7 @@
    1.40  			}
    1.41  		}
    1.42  	}
    1.43 -	//TODO: Platform-specific implementations of SetWindowShape.  X11 is finished.  Win32 is in progress.
    1.44 +	//TODO: Platform-specific implementations of SetWindowShape.  X11 is finished.  Win32 is finished.  Debugging is in progress on both.
    1.45  	result = window->display->device->shape_driver.SetWindowShape(window->shaper,shape,shapeMode);
    1.46  	window->shaper->hasshape = SDL_TRUE;
    1.47  	if((window->shaper->usershownflag & SDL_WINDOW_SHOWN) == SDL_WINDOW_SHOWN) {
     2.1 --- a/src/video/win32/SDL_win32shape.c	Sun Jul 18 22:24:52 2010 -0400
     2.2 +++ b/src/video/win32/SDL_win32shape.c	Sun Jul 18 23:05:40 2010 -0400
     2.3 @@ -339,7 +339,7 @@
     2.4  		}
     2.5  	}
     2.6  	
     2.7 -	window->shaper->usershownflag = window->flags & SDL_WINDOW_SHOWN;
     2.8 +	window->shaper->usershownflag |= window->flags & SDL_WINDOW_SHOWN;
     2.9  	
    2.10  	return 0;
    2.11  }
     3.1 --- a/src/video/x11/SDL_x11shape.c	Sun Jul 18 22:24:52 2010 -0400
     3.2 +++ b/src/video/x11/SDL_x11shape.c	Sun Jul 18 23:05:40 2010 -0400
     3.3 @@ -66,7 +66,7 @@
     3.4  		}
     3.5  	}
     3.6  	
     3.7 -	window->shaper->usershownflag = window->flags & SDL_WINDOW_SHOWN;
     3.8 +	window->shaper->usershownflag |= window->flags & SDL_WINDOW_SHOWN;
     3.9  	
    3.10  	return 0;
    3.11  }
     4.1 --- a/test/testshape.c	Sun Jul 18 22:24:52 2010 -0400
     4.2 +++ b/test/testshape.c	Sun Jul 18 23:05:40 2010 -0400
     4.3 @@ -27,8 +27,8 @@
     4.4  	for(i=0;i<num_pictures;i++)
     4.5  		pictures[i] = NULL;
     4.6  	for(i=0;i<num_pictures;i++) {
     4.7 -		SDL_Surface *original = SDL_LoadBMP(argv[i+1]);
     4.8 -		if(original == NULL) {
     4.9 +		pictures[i] = SDL_LoadBMP(argv[i+1]);
    4.10 +		if(pictures[i] == NULL) {
    4.11  			int j = 0;
    4.12  			for(j=0;j<num_pictures;j++)
    4.13  				if(pictures[j] != NULL)
    4.14 @@ -38,43 +38,6 @@
    4.15  			printf("Could not load surface from named bitmap file.\n");
    4.16  			exit(-3);
    4.17  		}
    4.18 -		//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.
    4.19 -		SDL_PixelFormat format = {NULL,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
    4.20 -		int bpp = 0;
    4.21 -		SDL_PixelFormatEnumToMasks(SDL_PIXELFORMAT_RGBA8888,&bpp,&format.Rmask,&format.Gmask,&format.Bmask,&format.Amask);
    4.22 -		format.BitsPerPixel = bpp;
    4.23 -		format.BytesPerPixel = format.BitsPerPixel / 8 + (format.BitsPerPixel % 8 > 0 ? 1 : 0);
    4.24 -		pictures[i] = SDL_ConvertSurface(original,&format,0);
    4.25 -		//We have no more need of the original now that we have our desired format.
    4.26 -		SDL_FreeSurface(original);
    4.27 -		if(pictures[i] == NULL) {
    4.28 -			int j = 0;
    4.29 -			for(j=0;j<num_pictures;j++)
    4.30 -				if(pictures[j] != NULL)
    4.31 -					SDL_FreeSurface(pictures[j]);
    4.32 -			free(pictures);
    4.33 -			SDL_VideoQuit();
    4.34 -			printf("Could not convert bitmap surface to desired format.\n");
    4.35 -			exit(-3);
    4.36 -		}
    4.37 -		
    4.38 -		if(SDL_MUSTLOCK(pictures[i]))
    4.39 -			SDL_LockSurface(pictures[i]);
    4.40 -			
    4.41 -		void* pixels = pictures[i]->pixels;
    4.42 -		unsigned int pitch = pictures[i]->pitch;
    4.43 -		int y =0,x = 0;
    4.44 -		for(y=0;y<pictures[i]->h;y++)
    4.45 -			for(x=0;x<pictures[i]->w;x++) {
    4.46 -				Uint32* pixel = pixels + y * pitch + x * pictures[i]->format->BytesPerPixel;
    4.47 -				Uint8 r = 0,g = 0,b = 0;
    4.48 -				SDL_GetRGB(*pixel,pictures[i]->format,&r,&g,&b);
    4.49 -				//if(r == g == b == 0xff)
    4.50 -				//	*pixel = SDL_MapRGBA(pictures[i]->format,r,g,b,0);
    4.51 -			}
    4.52 -			
    4.53 -		if(SDL_MUSTLOCK(pictures[i]))
    4.54 -			SDL_UnlockSurface(pictures[i]);
    4.55  	}
    4.56  	
    4.57  	SDL_Window *window = SDL_CreateShapedWindow("SDL_Shape test",SHAPED_WINDOW_X,SHAPED_WINDOW_Y,SHAPED_WINDOW_DIMENSION,SHAPED_WINDOW_DIMENSION,SDL_WINDOW_RESIZABLE | SDL_WINDOW_SHOWN);
    4.58 @@ -123,12 +86,12 @@
    4.59  	event_pending = SDL_PollEvent(&event);
    4.60  	unsigned int current_picture = 0;
    4.61  	SDL_WindowShapeMode mode = {ShapeModeDefault,1};
    4.62 -	SDL_SetWindowShape(window,pictures[current_picture],&mode);
    4.63  	int mouse_down = 0;
    4.64 -	Uint32 format,access;
    4.65 +	Uint32 format = 0,access = 0;
    4.66  	SDL_Rect texture_dimensions = {0,0,0,0};
    4.67  	SDL_QueryTexture(textures[current_picture],&format,&access,&texture_dimensions.w,&texture_dimensions.h);
    4.68  	SDL_SetWindowSize(window,texture_dimensions.w,texture_dimensions.h);
    4.69 +	SDL_SetWindowShape(window,pictures[current_picture],&mode);
    4.70  	while(should_exit == 0) {
    4.71  		event_pending = SDL_PollEvent(&event);
    4.72  		if(event_pending == 1) {