示例#1
0
void SDL_WarpMouse (Uint16 x, Uint16 y)
{
 SDL_VideoDevice *video = current_video;
 SDL_VideoDevice *this  = current_video;

 if ( !video || !SDL_PublicSurface ) {
   SDL_SetError("A video mode must be set before warping mouse");
   return;
 }

 /* If we have an offset video mode, offset the mouse coordinates */
 if (this->screen->pitch == 0) {
   x += this->screen->offset / this->screen->format->BytesPerPixel;
   y += this->screen->offset;
 } else {
   x += (this->screen->offset % this->screen->pitch) /
         this->screen->format->BytesPerPixel;
   y += (this->screen->offset / this->screen->pitch);
 }

 /* This generates a mouse motion event */
 if ( video->WarpWMCursor ) {
   video->WarpWMCursor(this, x, y);
 } else {
   SDL_PrivateMouseMotion(0, 0, x, y);
 }
}
示例#2
0
void SDL_FreeCursor (SDL_Cursor *cursor)
{
 if ( cursor ) {
   if ( cursor == SDL_cursor ) {
     SDL_SetCursor(SDL_defcursor);
   }
   if ( cursor != SDL_defcursor ) {
     SDL_VideoDevice *video = current_video;
     SDL_VideoDevice *this  = current_video;

     if ( cursor->data ) {
       SDL_free(cursor->data);
     }
     if ( cursor->save[0] ) {
       SDL_free(cursor->save[0]);
     }
     if ( video && cursor->wm_cursor ) {
       if ( video->FreeWMCursor ) {
         video->FreeWMCursor(this, cursor->wm_cursor);
       }
     }
     SDL_free(cursor);
   }
 }
}
示例#3
0
int SDL_ShowCursor (int toggle)
{
 int showing;

 showing = (SDL_cursorstate & CURSOR_VISIBLE);
 if ( toggle >= 0 ) {
   SDL_LockCursor();
   if ( toggle ) {
     SDL_cursorstate |= CURSOR_VISIBLE;
   } else {
     SDL_cursorstate &= ~CURSOR_VISIBLE;
   }
   SDL_UnlockCursor();
   if ( (SDL_cursorstate & CURSOR_VISIBLE) != showing ) {
     SDL_VideoDevice *video = current_video;
     SDL_VideoDevice *this  = current_video;

     SDL_SetCursor(NULL);
     if ( video && video->CheckMouseMode ) {
       video->CheckMouseMode(this);
     }
   }
 } else {
   /* Query current state */ ;
 }
 return(showing ? 1 : 0);
}
示例#4
0
SDL_Overlay *SDL_CreateYUVOverlay(int w, int h, Uint32 format,
                                  SDL_Surface *display)
{
	SDL_VideoDevice *video = current_video;
	SDL_VideoDevice *this  = current_video;
	const char *yuv_hwaccel;
	SDL_Overlay *overlay;

	overlay = NULL;

	/* Display directly on video surface, if possible */
#if 0
	if ( (display == SDL_PublicSurface) &&
	     ((SDL_VideoSurface->format->BytesPerPixel == 2) ||
	      (SDL_VideoSurface->format->BytesPerPixel == 4)) ) {
		display = SDL_VideoSurface;
	}
#endif
        yuv_hwaccel = getenv("SDL_VIDEO_YUV_HWACCEL");
	if ( ((display == SDL_VideoSurface) && video->CreateYUVOverlay) &&
	     (!yuv_hwaccel || (atoi(yuv_hwaccel) > 0)) ) {
		overlay = video->CreateYUVOverlay(this, w, h, format, display);
	}
	/* If hardware YUV overlay failed ... */
	if ( overlay == NULL ) {
		overlay = SDL_CreateYUV_SW(this, w, h, format, display);
	}
	return overlay;
}
示例#5
0
文件: SDL_yuv.c 项目: 0-14N/NDroid
SDL_Overlay *SDL_CreateYUVOverlay(int w, int h, Uint32 format,
                                  SDL_Surface *display)
{
	SDL_VideoDevice *video = current_video;
	SDL_VideoDevice *this  = current_video;
	const char *yuv_hwaccel;
	SDL_Overlay *overlay;

	if ( (display->flags & SDL_OPENGL) == SDL_OPENGL ) {
		SDL_SetError("YUV overlays are not supported in OpenGL mode");
		return NULL;
	}

	/* Display directly on video surface, if possible */
	if ( SDL_getenv("SDL_VIDEO_YUV_DIRECT") ) {
		if ( (display == SDL_PublicSurface) &&
		     ((SDL_VideoSurface->format->BytesPerPixel == 2) ||
		      (SDL_VideoSurface->format->BytesPerPixel == 4)) ) {
			display = SDL_VideoSurface;
		}
	}
	overlay = NULL;
        yuv_hwaccel = SDL_getenv("SDL_VIDEO_YUV_HWACCEL");
	if ( ((display == SDL_VideoSurface) && video->CreateYUVOverlay) &&
	     (!yuv_hwaccel || (SDL_atoi(yuv_hwaccel) > 0)) ) {
		overlay = video->CreateYUVOverlay(this, w, h, format, display);
	}
	/* If hardware YUV overlay failed ... */
	if ( overlay == NULL ) {
		overlay = SDL_CreateYUV_SW(this, w, h, format, display);
	}
	return overlay;
}
示例#6
0
int SDL_SetGamma(float red, float green, float blue)
{
	int succeeded;
	SDL_VideoDevice *video = current_video;
	SDL_VideoDevice *this  = current_video;	

	succeeded = -1;
#ifdef USE_MATH_H
	/* Prefer using SetGammaRamp(), as it's more flexible */
	{
		Uint16 ramp[3][256];

		CalculateGammaRamp(red, ramp[0]);
		CalculateGammaRamp(green, ramp[1]);
		CalculateGammaRamp(blue, ramp[2]);
		succeeded = SDL_SetGammaRamp(ramp[0], ramp[1], ramp[2]);
	}
#else
	SDL_SetError("Gamma correction not supported");
#endif
	if ( (succeeded < 0) && video->SetGamma ) {
		SDL_ClearError();
		succeeded = video->SetGamma(this, red, green, blue);
	}
	return succeeded;
}
示例#7
0
/* SDL_SetCursor(NULL) can be used to force the cursor redraw,
   if this is desired for any reason.  This is used when setting
   the video mode and when the SDL window gains the mouse focus.
 */
void SDL_SetCursor (SDL_Cursor *cursor)
{
	SDL_VideoDevice *video = current_video;
	SDL_VideoDevice *this  = current_video;

	/* Make sure that the video subsystem has been initialized */
	if ( ! video ) {
		return;
	}

	/* Prevent the event thread from moving the mouse */
	SDL_LockCursor();

	/* Set the new cursor */
	if ( cursor && (cursor != SDL_cursor) ) {
		/* Erase the current mouse position */
		if ( SHOULD_DRAWCURSOR(SDL_cursorstate) ) {
			SDL_EraseCursor(SDL_VideoSurface);
		} else if ( video->MoveWMCursor ) {
			/* If the video driver is moving the cursor directly,
			   it needs to hide the old cursor before (possibly)
			   showing the new one.  (But don't erase NULL cursor)
			 */
			if ( SDL_cursor ) {
				video->ShowWMCursor(this, NULL);
			}
		}
		SDL_cursor = cursor;
	}

	/* Draw the new mouse cursor */
	if ( SDL_cursor && (SDL_cursorstate&CURSOR_VISIBLE) ) {
		/* Use window manager cursor if possible */
		if ( SDL_cursor->wm_cursor && 
	             video->ShowWMCursor(this, SDL_cursor->wm_cursor) )
			SDL_cursorstate &= ~CURSOR_USINGSW;
		else {
			SDL_cursorstate |= CURSOR_USINGSW;
			if ( video->ShowWMCursor ) {
				video->ShowWMCursor(this, NULL);
			}
			{ int x, y;
				SDL_GetMouseState(&x, &y);
				SDL_cursor->area.x = (x - SDL_cursor->hot_x);
				SDL_cursor->area.y = (y - SDL_cursor->hot_y);
			}
			SDL_DrawCursor(SDL_VideoSurface);
		}
	} else {
		/* Erase window manager mouse (cursor not visible) */
		if ( SDL_cursor && (SDL_cursorstate & CURSOR_USINGSW) ) {
			SDL_EraseCursor(SDL_VideoSurface);
		} else {
			if ( video ) {
				video->ShowWMCursor(this, NULL);
			}
		}
	}
	SDL_UnlockCursor();
}
示例#8
0
/* This function sets the alpha channel of a surface */
int SDL_SetAlpha (SDL_Surface *surface, Uint32 flag, Uint8 value)
{
	Uint32 oldflags = surface->flags;
	Uint32 oldalpha = surface->format->alpha;

	/* Sanity check the flag as it gets passed in */
	if ( flag & SDL_SRCALPHA ) {
		if ( flag & (SDL_RLEACCEL|SDL_RLEACCELOK) ) {
			flag = (SDL_SRCALPHA | SDL_RLEACCELOK);
		} else {
			flag = SDL_SRCALPHA;
		}
	} else {
		flag = 0;
	}

	/* Optimize away operations that don't change anything */
	if ( (flag == (surface->flags & (SDL_SRCALPHA|SDL_RLEACCELOK))) &&
	     (!flag || value == oldalpha) ) {
		return(0);
	}

	if(!(flag & SDL_RLEACCELOK) && (surface->flags & SDL_RLEACCEL))
		SDL_UnRLESurface(surface, 1);

	if ( flag ) {
		SDL_VideoDevice *video = current_video;
		SDL_VideoDevice *this  = current_video;

		surface->flags |= SDL_SRCALPHA;
		surface->format->alpha = value;
		if ( (surface->flags & SDL_HWACCEL) == SDL_HWACCEL ) {
			if ( (video->SetHWAlpha == NULL) ||
			     (video->SetHWAlpha(this, surface, value) < 0) ) {
				surface->flags &= ~SDL_HWACCEL;
			}
		}
		if ( flag & SDL_RLEACCELOK ) {
		        surface->flags |= SDL_RLEACCELOK;
		} else {
		        surface->flags &= ~SDL_RLEACCELOK;
		}
	} else {
		surface->flags &= ~SDL_SRCALPHA;
		surface->format->alpha = SDL_ALPHA_OPAQUE;
	}
	/*
	 * The representation for software surfaces is independent of
	 * per-surface alpha, so no need to invalidate the blit mapping
	 * if just the alpha value was changed. (If either is 255, we still
	 * need to invalidate.)
	 */
	if((surface->flags & SDL_HWACCEL) == SDL_HWACCEL
	   || oldflags != surface->flags
	   || (((oldalpha + 1) ^ (value + 1)) & 0x100))
		SDL_InvalidateMap(surface->map);
	return(0);
}
示例#9
0
/* Software cursor drawing support */
SDL_Cursor * SDL_CreateCursor (Uint8 *data, Uint8 *mask,
         int w, int h, int hot_x, int hot_y)
{
 SDL_VideoDevice *video = current_video;
 int savelen;
 int i;
 SDL_Cursor *cursor;

 /* Make sure the width is a multiple of 8 */
 w = ((w+7)&~7);

 /* Sanity check the hot spot */
 if ( (hot_x < 0) || (hot_y < 0) || (hot_x >= w) || (hot_y >= h) ) {
   SDL_SetError("Cursor hot spot doesn't lie within cursor");
   return(NULL);
 }

 /* Allocate memory for the cursor */
 cursor = (SDL_Cursor *)SDL_malloc(sizeof *cursor);
 if ( cursor == NULL ) {
   SDL_OutOfMemory();
   return(NULL);
 }
 savelen = (w*4)*h;
 cursor->area.x = 0;
 cursor->area.y = 0;
 cursor->area.w = w;
 cursor->area.h = h;
 cursor->hot_x = hot_x;
 cursor->hot_y = hot_y;
 cursor->data = (Uint8 *)SDL_malloc((w/8)*h*2);
 cursor->mask = cursor->data+((w/8)*h);
 cursor->save[0] = (Uint8 *)SDL_malloc(savelen*2);
 cursor->save[1] = cursor->save[0] + savelen;
 cursor->wm_cursor = NULL;
 if ( ! cursor->data || ! cursor->save[0] ) {
   SDL_FreeCursor(cursor);
   SDL_OutOfMemory();
   return(NULL);
 }
 for ( i=((w/8)*h)-1; i>=0; --i ) {
   cursor->data[i] = data[i];
   cursor->mask[i] = mask[i] | data[i];
 }
 SDL_memset(cursor->save[0], 0, savelen*2);

 /* If the window manager gives us a good cursor, we're done! */
 if ( video->CreateWMCursor ) {
   cursor->wm_cursor = video->CreateWMCursor(video, data, mask,
             w, h, hot_x, hot_y);
 } else {
   cursor->wm_cursor = NULL;
 }
 return(cursor);
}
示例#10
0
static int SDLCALL SDL_GobbleEvents(void *unused)
{
	event_thread = SDL_ThreadID();

#ifdef __OS2__
#ifdef USE_DOSSETPRIORITY
	/* Increase thread priority, so it will process events in time for sure! */
	DosSetPriority(PRTYS_THREAD, PRTYC_REGULAR, +16, 0);
#endif
#endif

	while ( SDL_EventQ.active ) {
		SDL_VideoDevice *video = current_video;
		SDL_VideoDevice *this  = current_video;

		/* Get events from the video subsystem */
		if ( video ) {
			video->PumpEvents(this);
		}

		/* Queue pending key-repeat events */
		SDL_CheckKeyRepeat();

#if !SDL_JOYSTICK_DISABLED
		/* Check for joystick state change */
		if ( SDL_numjoysticks && (SDL_eventstate & SDL_JOYEVENTMASK) ) {
			SDL_JoystickUpdate();
		}
#endif

		/* Give up the CPU for the rest of our timeslice */
		SDL_EventLock.safe = 1;
		if ( SDL_timer_running ) {
			SDL_ThreadedTimerCheck();
		}
		SDL_Delay(1);

		/* Check for event locking.
		   On the P of the lock mutex, if the lock is held, this thread
		   will wait until the lock is released before continuing.  The
		   safe flag will be set, meaning that the other thread can go
		   about it's business.  The safe flag is reset before the V,
		   so as soon as the mutex is free, other threads can see that
		   it's not safe to interfere with the event thread.
		 */
		SDL_mutexP(SDL_EventLock.lock);
		SDL_EventLock.safe = 0;
		SDL_mutexV(SDL_EventLock.lock);
	}
	SDL_SetTimerThreaded(0);
	event_thread = 0;
	return(0);
}
示例#11
0
int SDL_SetGammaRamp(const Uint16 *red, const Uint16 *green, const Uint16 *blue)
{
	int succeeded;
	SDL_VideoDevice *video = current_video;
	SDL_VideoDevice *this  = current_video;	
	SDL_Surface *screen = SDL_PublicSurface;

	/* Verify the screen parameter */
	if ( !screen ) {
		SDL_SetError("No video mode has been set");
		return -1;
	}

	/* Lazily allocate the gamma tables */
	if ( ! video->gamma ) {
		SDL_GetGammaRamp(0, 0, 0);
	}

	/* Fill the gamma table with the new values */
	if ( red ) {
		SDL_memcpy(&video->gamma[0*256], red, 256*sizeof(*video->gamma));
	}
	if ( green ) {
		SDL_memcpy(&video->gamma[1*256], green, 256*sizeof(*video->gamma));
	}
	if ( blue ) {
		SDL_memcpy(&video->gamma[2*256], blue, 256*sizeof(*video->gamma));
	}

	/* Gamma correction always possible on split palettes */
	if ( (screen->flags & SDL_HWPALETTE) == SDL_HWPALETTE ) {
		SDL_Palette *pal = screen->format->palette;

		/* If physical palette has been set independently, use it */
		if(video->physpal)
		        pal = video->physpal;
		      
		SDL_SetPalette(screen, SDL_PHYSPAL,
			       pal->colors, 0, pal->ncolors);
		return 0;
	}

	/* Try to set the gamma ramp in the driver */
	succeeded = -1;
	if ( video->SetGammaRamp ) {
		succeeded = video->SetGammaRamp(this, video->gamma);
	} else {
		SDL_SetError("Gamma ramp manipulation not supported");
	}
	return succeeded;
}
示例#12
0
/*
 * Set the color key in a blittable surface
 */
int SDL_SetColorKey (SDL_Surface *surface, Uint32 flag, Uint32 key)
{
	/* Sanity check the flag as it gets passed in */
	if ( flag & SDL_SRCCOLORKEY ) {
		if ( flag & (SDL_RLEACCEL|SDL_RLEACCELOK) ) {
			flag = (SDL_SRCCOLORKEY | SDL_RLEACCELOK);
		} else {
			flag = SDL_SRCCOLORKEY;
		}
	} else {
		flag = 0;
	}

	/* Optimize away operations that don't change anything */
	if ( (flag == (surface->flags & (SDL_SRCCOLORKEY|SDL_RLEACCELOK))) &&
	     (key == surface->format->colorkey) ) {
		return(0);
	}

	/* UnRLE surfaces before we change the colorkey */
	if ( surface->flags & SDL_RLEACCEL ) {
	        SDL_UnRLESurface(surface, 1);
	}

	if ( flag ) {
		SDL_VideoDevice *video = current_video;
		SDL_VideoDevice *this  = current_video;


		surface->flags |= SDL_SRCCOLORKEY;
		surface->format->colorkey = key;
		if ( (surface->flags & SDL_HWACCEL) == SDL_HWACCEL ) {
			if ( (video->SetHWColorKey == NULL) ||
			     (video->SetHWColorKey(this, surface, key) < 0) ) {
				surface->flags &= ~SDL_HWACCEL;
			}
		}
		if ( flag & SDL_RLEACCELOK ) {
			surface->flags |= SDL_RLEACCELOK;
		} else {
			surface->flags &= ~SDL_RLEACCELOK;
		}
	} else {
		surface->flags &= ~(SDL_SRCCOLORKEY|SDL_RLEACCELOK);
		surface->format->colorkey = 0;
	}
	SDL_InvalidateMap(surface->map);
	return(0);
}
示例#13
0
void SDL_MoveCursor(int x, int y)
{
 SDL_VideoDevice *video = current_video;

 /* Erase and update the current mouse position */
 if ( SHOULD_DRAWCURSOR(SDL_cursorstate) ) {
   /* Erase and redraw mouse cursor in new position */
   SDL_LockCursor();
   SDL_EraseCursor(SDL_VideoSurface);
   SDL_cursor->area.x = (x - SDL_cursor->hot_x);
   SDL_cursor->area.y = (y - SDL_cursor->hot_y);
   SDL_DrawCursor(SDL_VideoSurface);
   SDL_UnlockCursor();
 } else if ( video->MoveWMCursor ) {
   video->MoveWMCursor(video, x, y);
 }
}
示例#14
0
static int SDLCALL SDL_GobbleEvents(void *unused)
{
	event_thread = SDL_ThreadID();

#ifdef __OS2__
#ifdef USE_DOSSETPRIORITY
	
	DosSetPriority(PRTYS_THREAD, PRTYC_REGULAR, +16, 0);
#endif
#endif

	while ( SDL_EventQ.active ) {
		SDL_VideoDevice *video = current_video;
		SDL_VideoDevice *this  = current_video;

		
		if ( video ) {
			video->PumpEvents(this);
		}

		
		SDL_CheckKeyRepeat();

#if !SDL_JOYSTICK_DISABLED
		
		if ( SDL_numjoysticks && (SDL_eventstate & SDL_JOYEVENTMASK) ) {
			SDL_JoystickUpdate();
		}
#endif

		
		SDL_EventLock.safe = 1;
		if ( SDL_timer_running ) {
			SDL_ThreadedTimerCheck();
		}
		SDL_Delay(1);

		SDL_mutexP(SDL_EventLock.lock);
		SDL_EventLock.safe = 0;
		SDL_mutexV(SDL_EventLock.lock);
	}
	SDL_SetTimerThreaded(0);
	event_thread = 0;
	return(0);
}
示例#15
0
int SDL_SetGamma(float red, float green, float blue)
{
	int succeeded;
	SDL_VideoDevice *video = current_video;
	SDL_VideoDevice *this  = current_video;	

	succeeded = -1;
	/* Prefer using SetGammaRamp(), as it's more flexible */
	{
		Uint16 ramp[3][256];

		CalculateGammaRamp(red, ramp[0]);
		CalculateGammaRamp(green, ramp[1]);
		CalculateGammaRamp(blue, ramp[2]);
		succeeded = SDL_SetGammaRamp(ramp[0], ramp[1], ramp[2]);
	}
	if ( (succeeded < 0) && video->SetGamma ) {
		SDL_ClearError();
		succeeded = video->SetGamma(this, red, green, blue);
	}
	return succeeded;
}
示例#16
0
/* Run the system dependent event loops */
void SDL_PumpEvents(void)
{
	if ( !SDL_EventThread ) {
		SDL_VideoDevice *video = current_video;
		SDL_VideoDevice *this  = current_video;

		/* Get events from the video subsystem */
		if ( video ) {
			video->PumpEvents(this);
		}

		/* Queue pending key-repeat events */
		SDL_CheckKeyRepeat();

#if !SDL_JOYSTICK_DISABLED
		/* Check for joystick state change */
		if ( SDL_numjoysticks && (SDL_eventstate & SDL_JOYEVENTMASK) ) {
			SDL_JoystickUpdate();
		}
#endif
	}
}
示例#17
0
void SDL_PumpEvents(void)
{
	if ( !SDL_EventThread ) {
		SDL_VideoDevice *video = current_video;
		SDL_VideoDevice *this  = current_video;

		
		if ( video ) {
			video->PumpEvents(this);
		}

		
		SDL_CheckKeyRepeat();

#if !SDL_JOYSTICK_DISABLED
		
		if ( SDL_numjoysticks && (SDL_eventstate & SDL_JOYEVENTMASK) ) {
			SDL_JoystickUpdate();
		}
#endif
	}
}
示例#18
0
/* 
 * This function performs a fast fill of the given rectangle with 'color'
 */
int SDL_FillRect(SDL_Surface *dst, SDL_Rect *dstrect, Uint32 color)
{
	SDL_VideoDevice *video = current_video;
	SDL_VideoDevice *this  = current_video;
	int x, y;
	Uint8 *row;

	/* If 'dstrect' == NULL, then fill the whole surface */
	if ( dstrect ) {
		/* Perform clipping */
		if ( !SDL_IntersectRect(dstrect, &dst->clip_rect, dstrect) ) {
			return(0);
		}
	} else {
		dstrect = &dst->clip_rect;
	}

	/* Check for hardware acceleration */
	if ( ((dst->flags & SDL_HWSURFACE) == SDL_HWSURFACE) &&
					video->info.blit_fill ) {
		return(video->FillHWRect(this, dst, dstrect, color));
	}

	/* Perform software fill */
	if ( SDL_LockSurface(dst) != 0 ) {
		return(-1);
	}
	row = (Uint8 *)dst->pixels+dstrect->y*dst->pitch+
			dstrect->x*dst->format->BytesPerPixel;
	if ( dst->format->palette || (color == 0) ) {
		x = dstrect->w*dst->format->BytesPerPixel;
		if ( !color && !((long)row&3) && !(x&3) && !(dst->pitch&3) ) {
			int n = x >> 2;
			for ( y=dstrect->h; y; --y ) {
				SDL_memset4(row, 0, n);
				row += dst->pitch;
			}
		} else {
示例#19
0
int SDL_GetGammaRamp(Uint16 *red, Uint16 *green, Uint16 *blue)
{
	SDL_VideoDevice *video = current_video;
	SDL_VideoDevice *this  = current_video;	

	/* Lazily allocate the gamma table */
	if ( ! video->gamma ) {
		video->gamma = SDL_malloc(3*256*sizeof(*video->gamma));
		if ( ! video->gamma ) {
			SDL_OutOfMemory();
			return -1;
		}
		if ( video->GetGammaRamp ) {
			/* Get the real hardware gamma */
			video->GetGammaRamp(this, video->gamma);
		} else {
			/* Assume an identity gamma */
			int i;
			for ( i=0; i<256; ++i ) {
				video->gamma[0*256+i] = (i << 8) | i;
				video->gamma[1*256+i] = (i << 8) | i;
				video->gamma[2*256+i] = (i << 8) | i;
			}
		}
	}

	/* Just copy from our internal table */
	if ( red ) {
		SDL_memcpy(red, &video->gamma[0*256], 256*sizeof(*red));
	}
	if ( green ) {
		SDL_memcpy(green, &video->gamma[1*256], 256*sizeof(*green));
	}
	if ( blue ) {
		SDL_memcpy(blue, &video->gamma[2*256], 256*sizeof(*blue));
	}
	return 0;
}
示例#20
0
void ZL_SetFullscreen(bool toFullscreen)
{
	#if 0 //#ifndef ZL_USE_EXTERNAL_SDL
	SDL_VideoDevice *device = SDL_GetVideoDevice();
	SDL_VideoDisplay *display = SDL_GetDisplayForWindow(ZL_SDL_Window);
	if (toFullscreen)
	{
		ZL_SDL_Window->flags |= SDL_WINDOW_FULLSCREEN;
		ZL_SDL_Window->x = 0;
		ZL_SDL_Window->y = 0;
		ZL_SDL_Window->w = display->desktop_mode.w;
		ZL_SDL_Window->h = display->desktop_mode.h;
		device->SetWindowSize(device, ZL_SDL_Window);
	}
	else
	{
		ZL_SDL_Window->flags &= ~SDL_WINDOW_FULLSCREEN;
		ZL_SDL_Window->x = ZL_SDL_Window->windowed.x;
		ZL_SDL_Window->y = ZL_SDL_Window->windowed.y;
		ZL_SDL_Window->w = ZL_SDL_Window->windowed.w;
		ZL_SDL_Window->h = ZL_SDL_Window->windowed.h;
	}
	device->SetWindowFullscreen(device, ZL_SDL_Window, display, (SDL_bool)toFullscreen);
	if(toFullscreen) SDL_OnWindowResized(ZL_SDL_Window);
	else SDL_SetWindowSize(ZL_SDL_Window, ZL_SDL_Window->windowed.w, ZL_SDL_Window->windowed.h);
	#else
	if (toFullscreen)
	{
		SDL_SetWindowFullscreen(ZL_SDL_Window, SDL_WINDOW_FULLSCREEN_DESKTOP);
	}
	else
	{
		SDL_SetWindowFullscreen(ZL_SDL_Window, 0);
		SDL_SetWindowSize(ZL_SDL_Window, ZL_SDL_Window->windowed.w, ZL_SDL_Window->windowed.h);
	}
	#endif
}
示例#21
0
/* 
 * This function performs a fast fill of the given rectangle with 'color'
 */
int SDL_FillRect(SDL_Surface *dst, SDL_Rect *dstrect, Uint32 color)
{
	SDL_VideoDevice *video = current_video;
	SDL_VideoDevice *this  = current_video;
	int x, y;
	Uint8 *row;

	/* This function doesn't work on surfaces < 8 bpp */
	if ( dst->format->BitsPerPixel < 8 ) {
		switch(dst->format->BitsPerPixel) {
		    case 1:
			return SDL_FillRect1(dst, dstrect, color);
			break;
		    case 4:
			return SDL_FillRect4(dst, dstrect, color);
			break;
		    default:
			SDL_SetError("Fill rect on unsupported surface format");
			return(-1);
			break;
		}
	}

	/* If 'dstrect' == NULL, then fill the whole surface */
	if ( dstrect ) {
		/* Perform clipping */
		if ( !SDL_IntersectRect(dstrect, &dst->clip_rect, dstrect) ) {
			return(0);
		}
	} else {
		dstrect = &dst->clip_rect;
	}

	/* Check for hardware acceleration */
	if ( ((dst->flags & SDL_HWSURFACE) == SDL_HWSURFACE) &&
					video->info.blit_fill ) {
		SDL_Rect hw_rect;
		if ( dst == SDL_VideoSurface ) {
			hw_rect = *dstrect;
			hw_rect.x += current_video->offset_x;
			hw_rect.y += current_video->offset_y;
			dstrect = &hw_rect;
		}
		return(video->FillHWRect(this, dst, dstrect, color));
	}

	/* Perform software fill */
	if ( SDL_LockSurface(dst) != 0 ) {
		return(-1);
	}
	row = (Uint8 *)dst->pixels+dstrect->y*dst->pitch+
			dstrect->x*dst->format->BytesPerPixel;
	if ( dst->format->palette || (color == 0) ) {
		x = dstrect->w*dst->format->BytesPerPixel;
		if ( !color && !((int)row&3) && !(x&3) && !(dst->pitch&3) ) {
			int n = x >> 2;
			for ( y=dstrect->h; y; --y ) {
				SDL_memset4(row, 0, n);
				row += dst->pitch;
			}
		} else {
示例#22
0
/*
 * Create an empty RGB surface of the appropriate depth
 */
SDL_Surface * SDL_CreateRGBSurface (Uint32 flags,
			int width, int height, int depth,
			Uint32 Rmask, Uint32 Gmask, Uint32 Bmask, Uint32 Amask)
{
	SDL_VideoDevice *video = current_video;
	SDL_VideoDevice *this  = current_video;
	SDL_Surface *screen;
	SDL_Surface *surface;

	/* Make sure the size requested doesn't overflow our datatypes */
	/* Next time I write a library like SDL, I'll use int for size. :) */
	if ( width > 16384 || height > 16384 ) {
		SDL_SetError("Width or height is too large");
		return(NULL);
	}

	/* Check to see if we desire the surface in video memory */
	if ( video ) {
		screen = SDL_PublicSurface;
	} else {
		screen = NULL;
	}
	if ( screen && ((screen->flags&SDL_HWSURFACE) == SDL_HWSURFACE) ) {
		if ( (flags&(SDL_SRCCOLORKEY|SDL_SRCALPHA)) != 0 ) {
			flags |= SDL_HWSURFACE;
		}
		if ( (flags & SDL_SRCCOLORKEY) == SDL_SRCCOLORKEY ) {
			if ( ! current_video->info.blit_hw_CC ) {
				flags &= ~SDL_HWSURFACE;
			}
		}
		if ( (flags & SDL_SRCALPHA) == SDL_SRCALPHA ) {
			if ( ! current_video->info.blit_hw_A ) {
				flags &= ~SDL_HWSURFACE;
			}
		}
	} else {
		flags &= ~SDL_HWSURFACE;
	}

	/* Allocate the surface */
	surface = (SDL_Surface *)malloc(sizeof(*surface));
	if ( surface == NULL ) {
		SDL_OutOfMemory();
		return(NULL);
	}
	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;
	}
	surface->format = SDL_AllocFormat(depth, Rmask, Gmask, Bmask, Amask);
	if ( surface->format == NULL ) {
		free(surface);
		return(NULL);
	}
	if ( Amask ) {
		surface->flags |= SDL_SRCALPHA;
	}
	surface->w = width;
	surface->h = height;
	surface->pitch = SDL_CalculatePitch(surface);
	surface->pixels = NULL;
	surface->offset = 0;
	surface->hwdata = NULL;
	surface->locked = 0;
	surface->map = NULL;
	surface->unused1 = 0;
	SDL_SetClipRect(surface, NULL);
	SDL_FormatChanged(surface);

	/* Get the pixels */
	if ( ((flags&SDL_HWSURFACE) == SDL_SWSURFACE) || 
				(video->AllocHWSurface(this, surface) < 0) ) {
		if ( surface->w && surface->h ) {
			surface->pixels = malloc(surface->h*surface->pitch);
			if ( surface->pixels == NULL ) {
				SDL_FreeSurface(surface);
				SDL_OutOfMemory();
				return(NULL);
			}
			/* This is important for bitmaps */
			memset(surface->pixels, 0, surface->h*surface->pitch);
		}
	}

	/* Allocate an empty mapping */
	surface->map = SDL_AllocBlitMap();
	if ( surface->map == NULL ) {
		SDL_FreeSurface(surface);
		return(NULL);
	}

	/* The surface is ready to go */
	surface->refcount = 1;
#ifdef CHECK_LEAKS
	++surfaces_allocated;
#endif
	return(surface);
}
示例#23
0
/* The general purpose software blit routine */
static int SDL_SoftBlit(SDL_Surface *src, SDL_Rect *srcrect,
			SDL_Surface *dst, SDL_Rect *dstrect)
{
	int okay;
	int src_locked;
	int dst_locked;

	/* Everything is okay at the beginning...  */
	okay = 1;

	/* Lock the destination if it's in hardware */
	dst_locked = 0;
	if ( dst->flags & (SDL_HWSURFACE|SDL_ASYNCBLIT) ) {
		SDL_VideoDevice *video = current_video;
		SDL_VideoDevice *this  = current_video;
		if ( video->LockHWSurface(this, dst) < 0 ) {
			okay = 0;
		} else {
			dst_locked = 1;
		}
	}
	/* Lock the source if it's in hardware */
	src_locked = 0;
	if ( src->flags & (SDL_HWSURFACE|SDL_ASYNCBLIT) ) {
		SDL_VideoDevice *video = current_video;
		SDL_VideoDevice *this  = current_video;
		if ( video->LockHWSurface(this, src) < 0 ) {
			okay = 0;
		} else {
			src_locked = 1;
		}
	}

	/* Unencode the destination if it's RLE encoded */
	if ( dst->flags & SDL_RLEACCEL ) {
		SDL_UnRLESurface(dst, 1);
		dst->flags |= SDL_RLEACCEL;	/* save accel'd state */
	}

	/* Set up source and destination buffer pointers, and BLIT! */
	if ( okay  && srcrect->w && srcrect->h ) {
		SDL_BlitInfo info;
		SDL_loblit RunBlit;

		/* Set up the blit information */
		info.s_pixels = (Uint8 *)src->pixels + src->offset +
				(Uint16)srcrect->y*src->pitch +
				(Uint16)srcrect->x*src->format->BytesPerPixel;
		info.s_width = srcrect->w;
		info.s_height = srcrect->h;
		info.s_skip=src->pitch-info.s_width*src->format->BytesPerPixel;
		info.d_pixels = (Uint8 *)dst->pixels + dst->offset +
				(Uint16)dstrect->y*dst->pitch +
				(Uint16)dstrect->x*dst->format->BytesPerPixel;
		info.d_width = dstrect->w;
		info.d_height = dstrect->h;
		info.d_skip=dst->pitch-info.d_width*dst->format->BytesPerPixel;
		info.aux_data = src->map->sw_data->aux_data;
		info.src = src->format;
		info.table = src->map->table;
		info.dst = dst->format;
		RunBlit = src->map->sw_data->blit;

		/* Run the actual software blit */
		RunBlit(&info);
	}

	/* Re-encode the destination if it's RLE encoded */
	if ( dst->flags & SDL_RLEACCEL ) {
	        dst->flags &= ~SDL_RLEACCEL; /* stop lying */
		SDL_RLESurface(dst);
	}

	/* We need to unlock the surfaces if they're locked */
	if ( dst_locked ) {
		SDL_VideoDevice *video = current_video;
		SDL_VideoDevice *this  = current_video;
		video->UnlockHWSurface(this, dst);
	} else
	if ( src_locked ) {
		SDL_VideoDevice *video = current_video;
		SDL_VideoDevice *this  = current_video;
		video->UnlockHWSurface(this, src);
	}
	/* Blit is done! */
	return(okay ? 0 : -1);
}
示例#24
0
/* Public functions */
int SDL_KeyboardInit(void)
{
	const char* env;
	SDL_VideoDevice *video = current_video;
	SDL_VideoDevice *this  = current_video;

	/* Set default mode of UNICODE translation */
	SDL_EnableUNICODE(DEFAULT_UNICODE_TRANSLATION);

	/* Initialize the tables */
	SDL_ModState = KMOD_NONE;
	SDL_memset((void*)keynames, 0, sizeof(keynames));
	SDL_memset(SDL_KeyState, 0, sizeof(SDL_KeyState));
	video->InitOSKeymap(this);

	SDL_EnableKeyRepeat(0, 0);

	/* Allow environment override to disable special lock-key behavior */
	SDL_NoLockKeys = 0;
	env = SDL_getenv("SDL_DISABLE_LOCK_KEYS");
	if (env) {
		switch (SDL_atoi(env)) {
			case 1:
				SDL_NoLockKeys = SDL_NLK_CAPS | SDL_NLK_NUM;
				break;
			case 2:
				SDL_NoLockKeys = SDL_NLK_CAPS;
				break;
			case 3:
				SDL_NoLockKeys = SDL_NLK_NUM;
				break;
			default:
				break;
		}
	}

	/* Fill in the blanks in keynames */
	keynames[SDLK_BACKSPACE] = "backspace";
	keynames[SDLK_TAB] = "tab";
	keynames[SDLK_CLEAR] = "clear";
	keynames[SDLK_RETURN] = "return";
	keynames[SDLK_PAUSE] = "pause";
	keynames[SDLK_ESCAPE] = "escape";
	keynames[SDLK_SPACE] = "space";
	keynames[SDLK_EXCLAIM]  = "!";
	keynames[SDLK_QUOTEDBL]  = "\"";
	keynames[SDLK_HASH]  = "#";
	keynames[SDLK_DOLLAR]  = "$";
	keynames[SDLK_AMPERSAND]  = "&";
	keynames[SDLK_QUOTE] = "'";
	keynames[SDLK_LEFTPAREN] = "(";
	keynames[SDLK_RIGHTPAREN] = ")";
	keynames[SDLK_ASTERISK] = "*";
	keynames[SDLK_PLUS] = "+";
	keynames[SDLK_COMMA] = ",";
	keynames[SDLK_MINUS] = "-";
	keynames[SDLK_PERIOD] = ".";
	keynames[SDLK_SLASH] = "/";
	keynames[SDLK_0] = "0";
	keynames[SDLK_1] = "1";
	keynames[SDLK_2] = "2";
	keynames[SDLK_3] = "3";
	keynames[SDLK_4] = "4";
	keynames[SDLK_5] = "5";
	keynames[SDLK_6] = "6";
	keynames[SDLK_7] = "7";
	keynames[SDLK_8] = "8";
	keynames[SDLK_9] = "9";
	keynames[SDLK_COLON] = ":";
	keynames[SDLK_SEMICOLON] = ";";
	keynames[SDLK_LESS] = "<";
	keynames[SDLK_EQUALS] = "=";
	keynames[SDLK_GREATER] = ">";
	keynames[SDLK_QUESTION] = "?";
	keynames[SDLK_AT] = "@";
	keynames[SDLK_LEFTBRACKET] = "[";
	keynames[SDLK_BACKSLASH] = "\\";
	keynames[SDLK_RIGHTBRACKET] = "]";
	keynames[SDLK_CARET] = "^";
	keynames[SDLK_UNDERSCORE] = "_";
	keynames[SDLK_BACKQUOTE] = "`";
	keynames[SDLK_a] = "a";
	keynames[SDLK_b] = "b";
	keynames[SDLK_c] = "c";
	keynames[SDLK_d] = "d";
	keynames[SDLK_e] = "e";
	keynames[SDLK_f] = "f";
	keynames[SDLK_g] = "g";
	keynames[SDLK_h] = "h";
	keynames[SDLK_i] = "i";
	keynames[SDLK_j] = "j";
	keynames[SDLK_k] = "k";
	keynames[SDLK_l] = "l";
	keynames[SDLK_m] = "m";
	keynames[SDLK_n] = "n";
	keynames[SDLK_o] = "o";
	keynames[SDLK_p] = "p";
	keynames[SDLK_q] = "q";
	keynames[SDLK_r] = "r";
	keynames[SDLK_s] = "s";
	keynames[SDLK_t] = "t";
	keynames[SDLK_u] = "u";
	keynames[SDLK_v] = "v";
	keynames[SDLK_w] = "w";
	keynames[SDLK_x] = "x";
	keynames[SDLK_y] = "y";
	keynames[SDLK_z] = "z";
	keynames[SDLK_DELETE] = "delete";

	keynames[SDLK_WORLD_0] = "world 0";
	keynames[SDLK_WORLD_1] = "world 1";
	keynames[SDLK_WORLD_2] = "world 2";
	keynames[SDLK_WORLD_3] = "world 3";
	keynames[SDLK_WORLD_4] = "world 4";
	keynames[SDLK_WORLD_5] = "world 5";
	keynames[SDLK_WORLD_6] = "world 6";
	keynames[SDLK_WORLD_7] = "world 7";
	keynames[SDLK_WORLD_8] = "world 8";
	keynames[SDLK_WORLD_9] = "world 9";
	keynames[SDLK_WORLD_10] = "world 10";
	keynames[SDLK_WORLD_11] = "world 11";
	keynames[SDLK_WORLD_12] = "world 12";
	keynames[SDLK_WORLD_13] = "world 13";
	keynames[SDLK_WORLD_14] = "world 14";
	keynames[SDLK_WORLD_15] = "world 15";
	keynames[SDLK_WORLD_16] = "world 16";
	keynames[SDLK_WORLD_17] = "world 17";
	keynames[SDLK_WORLD_18] = "world 18";
	keynames[SDLK_WORLD_19] = "world 19";
	keynames[SDLK_WORLD_20] = "world 20";
	keynames[SDLK_WORLD_21] = "world 21";
	keynames[SDLK_WORLD_22] = "world 22";
	keynames[SDLK_WORLD_23] = "world 23";
	keynames[SDLK_WORLD_24] = "world 24";
	keynames[SDLK_WORLD_25] = "world 25";
	keynames[SDLK_WORLD_26] = "world 26";
	keynames[SDLK_WORLD_27] = "world 27";
	keynames[SDLK_WORLD_28] = "world 28";
	keynames[SDLK_WORLD_29] = "world 29";
	keynames[SDLK_WORLD_30] = "world 30";
	keynames[SDLK_WORLD_31] = "world 31";
	keynames[SDLK_WORLD_32] = "world 32";
	keynames[SDLK_WORLD_33] = "world 33";
	keynames[SDLK_WORLD_34] = "world 34";
	keynames[SDLK_WORLD_35] = "world 35";
	keynames[SDLK_WORLD_36] = "world 36";
	keynames[SDLK_WORLD_37] = "world 37";
	keynames[SDLK_WORLD_38] = "world 38";
	keynames[SDLK_WORLD_39] = "world 39";
	keynames[SDLK_WORLD_40] = "world 40";
	keynames[SDLK_WORLD_41] = "world 41";
	keynames[SDLK_WORLD_42] = "world 42";
	keynames[SDLK_WORLD_43] = "world 43";
	keynames[SDLK_WORLD_44] = "world 44";
	keynames[SDLK_WORLD_45] = "world 45";
	keynames[SDLK_WORLD_46] = "world 46";
	keynames[SDLK_WORLD_47] = "world 47";
	keynames[SDLK_WORLD_48] = "world 48";
	keynames[SDLK_WORLD_49] = "world 49";
	keynames[SDLK_WORLD_50] = "world 50";
	keynames[SDLK_WORLD_51] = "world 51";
	keynames[SDLK_WORLD_52] = "world 52";
	keynames[SDLK_WORLD_53] = "world 53";
	keynames[SDLK_WORLD_54] = "world 54";
	keynames[SDLK_WORLD_55] = "world 55";
	keynames[SDLK_WORLD_56] = "world 56";
	keynames[SDLK_WORLD_57] = "world 57";
	keynames[SDLK_WORLD_58] = "world 58";
	keynames[SDLK_WORLD_59] = "world 59";
	keynames[SDLK_WORLD_60] = "world 60";
	keynames[SDLK_WORLD_61] = "world 61";
	keynames[SDLK_WORLD_62] = "world 62";
	keynames[SDLK_WORLD_63] = "world 63";
	keynames[SDLK_WORLD_64] = "world 64";
	keynames[SDLK_WORLD_65] = "world 65";
	keynames[SDLK_WORLD_66] = "world 66";
	keynames[SDLK_WORLD_67] = "world 67";
	keynames[SDLK_WORLD_68] = "world 68";
	keynames[SDLK_WORLD_69] = "world 69";
	keynames[SDLK_WORLD_70] = "world 70";
	keynames[SDLK_WORLD_71] = "world 71";
	keynames[SDLK_WORLD_72] = "world 72";
	keynames[SDLK_WORLD_73] = "world 73";
	keynames[SDLK_WORLD_74] = "world 74";
	keynames[SDLK_WORLD_75] = "world 75";
	keynames[SDLK_WORLD_76] = "world 76";
	keynames[SDLK_WORLD_77] = "world 77";
	keynames[SDLK_WORLD_78] = "world 78";
	keynames[SDLK_WORLD_79] = "world 79";
	keynames[SDLK_WORLD_80] = "world 80";
	keynames[SDLK_WORLD_81] = "world 81";
	keynames[SDLK_WORLD_82] = "world 82";
	keynames[SDLK_WORLD_83] = "world 83";
	keynames[SDLK_WORLD_84] = "world 84";
	keynames[SDLK_WORLD_85] = "world 85";
	keynames[SDLK_WORLD_86] = "world 86";
	keynames[SDLK_WORLD_87] = "world 87";
	keynames[SDLK_WORLD_88] = "world 88";
	keynames[SDLK_WORLD_89] = "world 89";
	keynames[SDLK_WORLD_90] = "world 90";
	keynames[SDLK_WORLD_91] = "world 91";
	keynames[SDLK_WORLD_92] = "world 92";
	keynames[SDLK_WORLD_93] = "world 93";
	keynames[SDLK_WORLD_94] = "world 94";
	keynames[SDLK_WORLD_95] = "world 95";

	keynames[SDLK_KP0] = "[0]";
	keynames[SDLK_KP1] = "[1]";
	keynames[SDLK_KP2] = "[2]";
	keynames[SDLK_KP3] = "[3]";
	keynames[SDLK_KP4] = "[4]";
	keynames[SDLK_KP5] = "[5]";
	keynames[SDLK_KP6] = "[6]";
	keynames[SDLK_KP7] = "[7]";
	keynames[SDLK_KP8] = "[8]";
	keynames[SDLK_KP9] = "[9]";
	keynames[SDLK_KP_PERIOD] = "[.]";
	keynames[SDLK_KP_DIVIDE] = "[/]";
	keynames[SDLK_KP_MULTIPLY] = "[*]";
	keynames[SDLK_KP_MINUS] = "[-]";
	keynames[SDLK_KP_PLUS] = "[+]";
	keynames[SDLK_KP_ENTER] = "enter";
	keynames[SDLK_KP_EQUALS] = "equals";

	keynames[SDLK_UP] = "up";
	keynames[SDLK_DOWN] = "down";
	keynames[SDLK_RIGHT] = "right";
	keynames[SDLK_LEFT] = "left";
	keynames[SDLK_DOWN] = "down";
	keynames[SDLK_INSERT] = "insert";
	keynames[SDLK_HOME] = "home";
	keynames[SDLK_END] = "end";
	keynames[SDLK_PAGEUP] = "page up";
	keynames[SDLK_PAGEDOWN] = "page down";

	keynames[SDLK_F1] = "f1";
	keynames[SDLK_F2] = "f2";
	keynames[SDLK_F3] = "f3";
	keynames[SDLK_F4] = "f4";
	keynames[SDLK_F5] = "f5";
	keynames[SDLK_F6] = "f6";
	keynames[SDLK_F7] = "f7";
	keynames[SDLK_F8] = "f8";
	keynames[SDLK_F9] = "f9";
	keynames[SDLK_F10] = "f10";
	keynames[SDLK_F11] = "f11";
	keynames[SDLK_F12] = "f12";
	keynames[SDLK_F13] = "f13";
	keynames[SDLK_F14] = "f14";
	keynames[SDLK_F15] = "f15";

	keynames[SDLK_NUMLOCK] = "numlock";
	keynames[SDLK_CAPSLOCK] = "caps lock";
	keynames[SDLK_SCROLLOCK] = "scroll lock";
	keynames[SDLK_RSHIFT] = "right shift";
	keynames[SDLK_LSHIFT] = "left shift";
	keynames[SDLK_RCTRL] = "right ctrl";
	keynames[SDLK_LCTRL] = "left ctrl";
	keynames[SDLK_RALT] = "right alt";
	keynames[SDLK_LALT] = "left alt";
	keynames[SDLK_RMETA] = "right meta";
	keynames[SDLK_LMETA] = "left meta";
	keynames[SDLK_LSUPER] = "left super";	/* "Windows" keys */
	keynames[SDLK_RSUPER] = "right super";	
	keynames[SDLK_MODE] = "alt gr";
	keynames[SDLK_COMPOSE] = "compose";

	keynames[SDLK_HELP] = "help";
	keynames[SDLK_PRINT] = "print screen";
	keynames[SDLK_SYSREQ] = "sys req";
	keynames[SDLK_BREAK] = "break";
	keynames[SDLK_MENU] = "menu";
	keynames[SDLK_POWER] = "power";
	keynames[SDLK_EURO] = "euro";
	keynames[SDLK_UNDO] = "undo";

	/* Done.  Whew. */
	return(0);
}
示例#25
0
文件: SDL_blit.c 项目: fluxer/warmux
/* Figure out which of many blit routines to set up on a surface */
int SDL_CalculateBlit(SDL_Surface *surface)
{
	int blit_index;

	/* Clean everything out to start */
	if ( (surface->flags & SDL_RLEACCEL) == SDL_RLEACCEL ) {
		SDL_UnRLESurface(surface, 1);
	}
	surface->map->sw_blit = NULL;

	/* 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;

		if ( (surface->flags & SDL_HWSURFACE) == SDL_HWSURFACE ) {
			/* We only support accelerated blitting to hardware */
			if ( surface->map->dst->flags & SDL_HWSURFACE ) {
				hw_blit_ok = current_video->info.blit_hw;
			} else {
				hw_blit_ok = 0;
			}
			if (hw_blit_ok && (surface->flags & SDL_SRCCOLORKEY)) {
				hw_blit_ok = current_video->info.blit_hw_CC;
			}
			if ( hw_blit_ok && (surface->flags & SDL_SRCALPHA) ) {
				hw_blit_ok = current_video->info.blit_hw_A;
			}
		} else {
			/* We only support accelerated blitting to hardware */
			if ( surface->map->dst->flags & SDL_HWSURFACE ) {
				hw_blit_ok = current_video->info.blit_sw;
			} else {
				hw_blit_ok = 0;
			}
			if (hw_blit_ok && (surface->flags & SDL_SRCCOLORKEY)) {
				hw_blit_ok = current_video->info.blit_sw_CC;
			}
			if ( hw_blit_ok && (surface->flags & SDL_SRCALPHA) ) {
				hw_blit_ok = current_video->info.blit_sw_A;
			}
		}
		if ( hw_blit_ok ) {
			SDL_VideoDevice *video = current_video;
			SDL_VideoDevice *this  = current_video;
			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 } */
	blit_index = 0;
	blit_index |= (!!(surface->flags & SDL_SRCCOLORKEY))      << 0;
	if ( surface->flags & SDL_SRCALPHA
	     && (surface->format->alpha != SDL_ALPHA_OPAQUE
		 || surface->format->Amask) ) {
	        blit_index |= 2;
	}

	/* Check for special "identity" case -- copy blit */
	if ( surface->map->identity && blit_index == 0 ) {
	        surface->map->sw_data->blit = SDL_BlitCopy;

		/* Handle overlapping blits on the same surface */
		if ( surface == surface->map->dst ) {
		        surface->map->sw_data->blit = SDL_BlitCopyOverlap;
		}
	} else {
		if ( surface->format->BitsPerPixel < 8 ) {
			surface->map->sw_data->blit =
			    SDL_CalculateBlit0(surface, blit_index);
		} else {
			switch ( surface->format->BytesPerPixel ) {
			    case 1:
				surface->map->sw_data->blit =
				    SDL_CalculateBlit1(surface, blit_index);
				break;
			    case 2:
			    case 3:
			    case 4:
				surface->map->sw_data->blit =
				    SDL_CalculateBlitN(surface, blit_index);
				break;
			    default:
				surface->map->sw_data->blit = NULL;
				break;
			}
		}
	}
	/* Make sure we have a blit function */
	if ( surface->map->sw_data->blit == NULL ) {
		SDL_InvalidateMap(surface->map);
		SDL_SetError("Blit combination not supported");
		return(-1);
	}

	/* Choose software blitting function */
	if(surface->flags & SDL_RLEACCELOK
	   && (surface->flags & SDL_HWACCEL) != SDL_HWACCEL) {

	        if(surface->map->identity
		   && (blit_index == 1
		       || (blit_index == 3 && !surface->format->Amask))) {
		        if ( SDL_RLESurface(surface) == 0 )
			        surface->map->sw_blit = SDL_RLEBlit;
		} else if(blit_index == 2 && surface->format->Amask) {
		        if ( SDL_RLESurface(surface) == 0 )
			        surface->map->sw_blit = SDL_RLEAlphaBlit;
		}
	}
	
	if ( surface->map->sw_blit == NULL ) {
		surface->map->sw_blit = SDL_SoftBlit;
	}
	return(0);
}