Some work on using accelerated alpha blits with hardware surfaces.
authorRyan C. Gordon <icculus@icculus.org>
Sun, 17 Apr 2005 10:40:41 +0000
changeset 1052 68f607298ca9
parent 1051 091350827e08
child 1053 f596fa4f17a6
Some work on using accelerated alpha blits with hardware surfaces. From Stephane Marchesin's fork, don't know who originally wrote it.
src/video/SDL_blit.c
src/video/SDL_surface.c
src/video/SDL_sysvideo.h
src/video/SDL_video.c
--- a/src/video/SDL_blit.c	Sun Apr 17 10:36:03 2005 +0000
+++ b/src/video/SDL_blit.c	Sun Apr 17 10:40:41 2005 +0000
@@ -280,6 +280,17 @@
 			video->CheckHWBlit(this, surface, surface->map->dst);
 		}
 	}
+	
+	/* if an alpha pixel format is specified, we can accelerate alpha blits */
+	if (((surface->flags & SDL_HWSURFACE) == SDL_HWSURFACE )&&(current_video->displayformatalphapixel)) 
+	{
+		if ( (surface->flags & SDL_SRCALPHA) ) 
+			if ( current_video->info.blit_hw_A ) {
+				SDL_VideoDevice *video = current_video;
+				SDL_VideoDevice *this  = current_video;
+				video->CheckHWBlit(this, surface, surface->map->dst);
+			}
+	}
 
 	/* Get the blit function index, based on surface mode */
 	/* { 0 = nothing, 1 = colorkey, 2 = alpha, 3 = colorkey+alpha } */
--- a/src/video/SDL_surface.c	Sun Apr 17 10:36:03 2005 +0000
+++ b/src/video/SDL_surface.c	Sun Apr 17 10:40:41 2005 +0000
@@ -91,11 +91,22 @@
 	}
 	surface->flags = SDL_SWSURFACE;
 	if ( (flags & SDL_HWSURFACE) == SDL_HWSURFACE ) {
-		depth = screen->format->BitsPerPixel;
-		Rmask = screen->format->Rmask;
-		Gmask = screen->format->Gmask;
-		Bmask = screen->format->Bmask;
-		Amask = screen->format->Amask;
+		if ((Amask) && (video->displayformatalphapixel))
+		{
+			depth = video->displayformatalphapixel->BitsPerPixel;
+			Rmask = video->displayformatalphapixel->Rmask;
+			Gmask = video->displayformatalphapixel->Gmask;
+			Bmask = video->displayformatalphapixel->Bmask;
+			Amask = video->displayformatalphapixel->Amask;
+		}
+		else
+		{
+			depth = screen->format->BitsPerPixel;
+			Rmask = screen->format->Rmask;
+			Gmask = screen->format->Gmask;
+			Bmask = screen->format->Bmask;
+			Amask = screen->format->Amask;
+		}
 	}
 	surface->format = SDL_AllocFormat(depth, Rmask, Gmask, Bmask, Amask);
 	if ( surface->format == NULL ) {
--- a/src/video/SDL_sysvideo.h	Sun Apr 17 10:36:03 2005 +0000
+++ b/src/video/SDL_sysvideo.h	Sun Apr 17 10:40:41 2005 +0000
@@ -134,6 +134,9 @@
 	/* Information about the video hardware */
 	SDL_VideoInfo info;
 
+	/* The pixel format used when SDL_CreateRGBSurface creates SDL_HWSURFACEs with alpha */
+	SDL_PixelFormat* displayformatalphapixel;
+	
 	/* Allocates a surface in video memory */
 	int (*AllocHWSurface)(_THIS, SDL_Surface *surface);
 
--- a/src/video/SDL_video.c	Sun Apr 17 10:36:03 2005 +0000
+++ b/src/video/SDL_video.c	Sun Apr 17 10:40:41 2005 +0000
@@ -212,6 +212,8 @@
 	video->offset_x = 0;
 	video->offset_y = 0;
 	memset(&video->info, 0, (sizeof video->info));
+	
+	video->displayformatalphapixel = NULL;
 
 	/* Set some very sane GL defaults */
 	video->gl_config.driver_loaded = 0;