Commit 008ece6f authored by Sam Lantinga's avatar Sam Lantinga

GAPI fixes from Stefan Klug

--HG--
branch : SDL-1.2
extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/branches/SDL-1.2%403531
parent 10fcf368
......@@ -73,7 +73,7 @@ int SDL_KeyboardInit(void)
SDL_EnableKeyRepeat(0, 0);
/* Allow environment override to disable special lock-key behavior */
env = getenv("SDL_NO_LOCK_KEYS");
env = SDL_getenv("SDL_NO_LOCK_KEYS");
SDL_NoLockKeys = 0;
if (env) {
switch (SDL_atoi(env)) {
......
......@@ -52,8 +52,11 @@ Inspired by http://arisme.free.fr/ports/SDL.php
#include "../wincommon/SDL_sysmouse_c.h"
#include "../windib/SDL_dibevents_c.h"
#include "../windib/SDL_gapidibvideo.h"
#include "SDL_gapivideo.h"
#define gapi this->hidden->gapiInfo
#define GAPIVID_DRIVER_NAME "gapi"
#if defined(DEBUG) || defined (_DEBUG) || defined(NDEBUG)
......@@ -98,6 +101,7 @@ static void GAPI_UnlockHWSurface(_THIS, SDL_Surface *surface);
static void GAPI_FreeHWSurface(_THIS, SDL_Surface *surface);
/* Windows message handling functions, will not be processed */
static void GAPI_Activate(_THIS, BOOL active, BOOL minimized);
static void GAPI_RealizePalette(_THIS);
static void GAPI_PaletteChanged(_THIS, HWND window);
static void GAPI_WinPAINT(_THIS, HDC hdc);
......@@ -160,6 +164,11 @@ static int GAPI_Available(void)
ReleaseDC(NULL, hdc);
g_bRawBufferAvailable = result > 0;
//My Asus MyPAL 696 reports the RAWFRAMEBUFFER as available, but with a size of 0 x 0
if(g_RawFrameBufferInfo.cxPixels <= 0 || g_RawFrameBufferInfo.cyPixels <= 0){
g_bRawBufferAvailable = 0;
}
#if WITHOUT_GAPI
return g_bRawBufferAvailable;
#endif
......@@ -247,6 +256,7 @@ static void GAPI_DeleteDevice(SDL_VideoDevice *device)
FreeLibrary(g_hGapiLib);
g_hGapiLib = 0;
}
SDL_free(device->hidden->gapiInfo);
SDL_free(device->hidden);
SDL_free(device);
}
......@@ -270,6 +280,15 @@ static SDL_VideoDevice *GAPI_CreateDevice(int devindex)
SDL_memset(device, 0, (sizeof *device));
device->hidden = (struct SDL_PrivateVideoData *)
SDL_malloc((sizeof *device->hidden));
if(device->hidden){
SDL_memset(device->hidden, 0, (sizeof *device->hidden));
device->hidden->gapiInfo = (GapiInfo *)SDL_malloc((sizeof(GapiInfo)));
if(device->hidden->gapiInfo == NULL)
{
SDL_free(device->hidden);
device->hidden = NULL;
}
}
}
if ( (device == NULL) || (device->hidden == NULL) ) {
SDL_OutOfMemory();
......@@ -278,7 +297,7 @@ static SDL_VideoDevice *GAPI_CreateDevice(int devindex)
}
return(0);
}
SDL_memset(device->hidden, 0, (sizeof *device->hidden));
SDL_memset(device->hidden->gapiInfo, 0, (sizeof *device->hidden->gapiInfo));
/* Set the function pointers */
device->VideoInit = GAPI_VideoInit;
......@@ -312,6 +331,7 @@ static SDL_VideoDevice *GAPI_CreateDevice(int devindex)
device->PumpEvents = DIB_PumpEvents;
/* Set up the windows message handling functions */
WIN_Activate = GAPI_Activate;
WIN_RealizePalette = GAPI_RealizePalette;
WIN_PaletteChanged = GAPI_PaletteChanged;
WIN_WinPAINT = GAPI_WinPAINT;
......@@ -320,7 +340,7 @@ static SDL_VideoDevice *GAPI_CreateDevice(int devindex)
device->free = GAPI_DeleteDevice;
/* Load gapi library */
#define gx device->hidden->gxFunc
#define gx device->hidden->gapiInfo->gxFunc
LINK( GXOpenDisplay, gx.GXOpenDisplay, "?GXOpenDisplay@@YAHPAUHWND__@@K@Z" )
LINK( GXCloseDisplay, gx.GXCloseDisplay, "?GXCloseDisplay@@YAHXZ" )
......@@ -369,23 +389,23 @@ static void FillStructs(_THIS, BOOL useVga)
if( !useVga )
{
this->hidden->gxProperties = this->hidden->gxFunc.GXGetDisplayProperties();
this->hidden->needUpdate = 1;
this->hidden->hiresFix = 0;
this->hidden->useVga = 0;
this->hidden->useGXOpenDisplay = 1;
gapi->gxProperties = gapi->gxFunc.GXGetDisplayProperties();
gapi->needUpdate = 1;
gapi->hiresFix = 0;
gapi->useVga = 0;
gapi->useGXOpenDisplay = 1;
#ifdef _ARM_
/* check some devices and extract addition info */
SystemParametersInfo( SPI_GETOEMINFO, sizeof( oemstr ), oemstr, 0 );
// buggy iPaq38xx
if ((oemstr[12] == 'H') && (oemstr[13] == '3') && (oemstr[14] == '8') && (this->hidden->gxProperties.cbxPitch > 0))
if ((oemstr[12] == 'H') && (oemstr[13] == '3') && (oemstr[14] == '8') && (gapi->gxProperties.cbxPitch > 0))
{
this->hidden->videoMem = (PIXEL*)0xac0755a0;
this->hidden->gxProperties.cbxPitch = -640;
this->hidden->gxProperties.cbyPitch = 2;
this->hidden->needUpdate = 0;
gapi->videoMem = (PIXEL*)0xac0755a0;
gapi->gxProperties.cbxPitch = -640;
gapi->gxProperties.cbyPitch = 2;
gapi->needUpdate = 0;
}
#if (EMULATE_AXIM_X30 == 0)
// buggy Dell Axim X30
......@@ -400,36 +420,36 @@ static void FillStructs(_THIS, BOOL useVga)
result = ExtEscape(hdc, GETGXINFO, 0, NULL, sizeof(gxInfo), (char *)&gxInfo);
if( result > 0 )
{
this->hidden->useGXOpenDisplay = 0;
this->hidden->videoMem = gxInfo.pvFrameBuffer;
this->hidden->needUpdate = 0;
this->hidden->gxProperties.cbxPitch = 2;
this->hidden->gxProperties.cbyPitch = 480;
this->hidden->gxProperties.cxWidth = gxInfo.cxWidth;
this->hidden->gxProperties.cyHeight = gxInfo.cyHeight;
this->hidden->gxProperties.ffFormat = gxInfo.ffFormat;
gapi->useGXOpenDisplay = 0;
gapi->videoMem = gxInfo.pvFrameBuffer;
gapi->needUpdate = 0;
gapi->gxProperties.cbxPitch = 2;
gapi->gxProperties.cbyPitch = 480;
gapi->gxProperties.cxWidth = gxInfo.cxWidth;
gapi->gxProperties.cyHeight = gxInfo.cyHeight;
gapi->gxProperties.ffFormat = gxInfo.ffFormat;
}
}
#endif
} else
{
this->hidden->needUpdate = 0;
this->hidden->hiresFix = 0;
this->hidden->gxProperties.cBPP = g_RawFrameBufferInfo.wBPP;
this->hidden->gxProperties.cbxPitch = g_RawFrameBufferInfo.cxStride;
this->hidden->gxProperties.cbyPitch = g_RawFrameBufferInfo.cyStride;
this->hidden->gxProperties.cxWidth = g_RawFrameBufferInfo.cxPixels;
this->hidden->gxProperties.cyHeight = g_RawFrameBufferInfo.cyPixels;
this->hidden->videoMem = g_RawFrameBufferInfo.pFramePointer;
this->hidden->useVga = 1;
gapi->needUpdate = 0;
gapi->hiresFix = 0;
gapi->gxProperties.cBPP = g_RawFrameBufferInfo.wBPP;
gapi->gxProperties.cbxPitch = g_RawFrameBufferInfo.cxStride;
gapi->gxProperties.cbyPitch = g_RawFrameBufferInfo.cyStride;
gapi->gxProperties.cxWidth = g_RawFrameBufferInfo.cxPixels;
gapi->gxProperties.cyHeight = g_RawFrameBufferInfo.cyPixels;
gapi->videoMem = g_RawFrameBufferInfo.pFramePointer;
gapi->useVga = 1;
switch( g_RawFrameBufferInfo.wFormat )
{
case FORMAT_565:
this->hidden->gxProperties.ffFormat = kfDirect565;
gapi->gxProperties.ffFormat = kfDirect565;
break;
case FORMAT_555:
this->hidden->gxProperties.ffFormat = kfDirect555;
gapi->gxProperties.ffFormat = kfDirect555;
break;
default:
/* unknown pixel format, try define by BPP! */
......@@ -437,31 +457,31 @@ static void FillStructs(_THIS, BOOL useVga)
{
case 4:
case 8:
this->hidden->gxProperties.ffFormat = kfDirect;
gapi->gxProperties.ffFormat = kfDirect;
case 16:
this->hidden->gxProperties.ffFormat = kfDirect565;
gapi->gxProperties.ffFormat = kfDirect565;
default:
this->hidden->gxProperties.ffFormat = kfDirect;
gapi->gxProperties.ffFormat = kfDirect;
break;
}
}
}
if( this->hidden->gxProperties.cBPP != 16 )
if( gapi->gxProperties.cBPP != 16 )
{
this->hidden->gapiOrientation = SDL_ORIENTATION_UP;
gapi->gapiOrientation = SDL_ORIENTATION_UP;
} else
if( (this->hidden->gxProperties.cbxPitch > 0) && (this->hidden->gxProperties.cbyPitch > 0 ))
if( (gapi->gxProperties.cbxPitch > 0) && (gapi->gxProperties.cbyPitch > 0 ))
{
this->hidden->gapiOrientation = SDL_ORIENTATION_UP;
gapi->gapiOrientation = SDL_ORIENTATION_UP;
} else
if( (this->hidden->gxProperties.cbxPitch > 0) && (this->hidden->gxProperties.cbyPitch < 0 ))
if( (gapi->gxProperties.cbxPitch > 0) && (gapi->gxProperties.cbyPitch < 0 ))
{
this->hidden->gapiOrientation = SDL_ORIENTATION_RIGHT; // ipaq 3660
gapi->gapiOrientation = SDL_ORIENTATION_RIGHT; // ipaq 3660
} else
if( (this->hidden->gxProperties.cbxPitch < 0) && (this->hidden->gxProperties.cbyPitch > 0 ))
if( (gapi->gxProperties.cbxPitch < 0) && (gapi->gxProperties.cbyPitch > 0 ))
{
this->hidden->gapiOrientation = SDL_ORIENTATION_LEFT; // ipaq 3800
gapi->gapiOrientation = SDL_ORIENTATION_LEFT; // ipaq 3800
}
}
......@@ -537,9 +557,11 @@ int GAPI_VideoInit(_THIS, SDL_PixelFormat *vformat)
GAPI_AddMode(this, bpp, gapi->gxProperties.cxWidth, gapi->gxProperties.cyHeight);
}
/* Determine the current screen size */
this->info.current_w = gapi->gxProperties.cxWidth;
this->info.current_h = gapi->gxProperties.cyHeight;
/* Determine the current screen size.
* This is NOT necessarily the size of the Framebuffer or GAPI, as they return
* the displaysize in ORIENTATION_UP */
this->info.current_w = GetSystemMetrics(SM_CXSCREEN);
this->info.current_h = GetSystemMetrics(SM_CYSCREEN);
/* Sort the mode lists */
for ( i=0; i<NUM_MODELISTS; ++i ) {
......@@ -548,39 +570,39 @@ int GAPI_VideoInit(_THIS, SDL_PixelFormat *vformat)
}
}
vformat->BitsPerPixel = this->hidden->gxProperties.cBPP < 8 ? 16 : (unsigned char)this->hidden->gxProperties.cBPP;
vformat->BitsPerPixel = gapi->gxProperties.cBPP < 8 ? 16 : (unsigned char)gapi->gxProperties.cBPP;
// Get color mask
if (this->hidden->gxProperties.ffFormat & kfDirect565) {
if (gapi->gxProperties.ffFormat & kfDirect565) {
vformat->BitsPerPixel = 16;
vformat->Rmask = 0x0000f800;
vformat->Gmask = 0x000007e0;
vformat->Bmask = 0x0000001f;
this->hidden->videoMode = GAPI_DIRECT_565;
gapi->videoMode = GAPI_DIRECT_565;
}
else
if (this->hidden->gxProperties.ffFormat & kfDirect555) {
if (gapi->gxProperties.ffFormat & kfDirect555) {
vformat->BitsPerPixel = 16;
vformat->Rmask = 0x00007c00;
vformat->Gmask = 0x000003e0;
vformat->Bmask = 0x0000001f;
this->hidden->videoMode = GAPI_DIRECT_555;
gapi->videoMode = GAPI_DIRECT_555;
}
else
if ((this->hidden->gxProperties.ffFormat & kfDirect) && (this->hidden->gxProperties.cBPP < 8)) {
if ((gapi->gxProperties.ffFormat & kfDirect) && (gapi->gxProperties.cBPP < 8)) {
// We'll perform the conversion
vformat->BitsPerPixel = 16;
vformat->Rmask = 0x0000f800; // 16 bit 565
vformat->Gmask = 0x000007e0;
vformat->Bmask = 0x0000001f;
if (this->hidden->gxProperties.ffFormat & kfDirectInverted)
this->hidden->invert = (1 << this->hidden->gxProperties.cBPP) - 1;
this->hidden->colorscale = this->hidden->gxProperties.cBPP < 8 ? 8 - this->hidden->gxProperties.cBPP : 0;
this->hidden->videoMode = GAPI_MONO;
if (gapi->gxProperties.ffFormat & kfDirectInverted)
gapi->invert = (1 << gapi->gxProperties.cBPP) - 1;
gapi->colorscale = gapi->gxProperties.cBPP < 8 ? 8 - gapi->gxProperties.cBPP : 0;
gapi->videoMode = GAPI_MONO;
}
else
if (this->hidden->gxProperties.ffFormat & kfPalette) {
this->hidden->videoMode = GAPI_PALETTE;
if (gapi->gxProperties.ffFormat & kfPalette) {
gapi->videoMode = GAPI_PALETTE;
}
/* We're done! */
......@@ -589,7 +611,7 @@ int GAPI_VideoInit(_THIS, SDL_PixelFormat *vformat)
SDL_Rect **GAPI_ListModes(_THIS, SDL_PixelFormat *format, Uint32 flags)
{
return(this->hidden->SDL_modelist[((format->BitsPerPixel+7)/8)-1]);
return(gapi->SDL_modelist[((format->BitsPerPixel+7)/8)-1]);
// return (SDL_Rect **) -1;
}
......@@ -600,6 +622,7 @@ SDL_Surface *GAPI_SetVideoMode(_THIS, SDL_Surface *current,
Uint32 Rmask, Gmask, Bmask;
DWORD style;
SDL_Rect allScreen;
SDL_ScreenOrientation systemOrientation;
if( bpp < 4 )
{
......@@ -621,7 +644,7 @@ SDL_Surface *GAPI_SetVideoMode(_THIS, SDL_Surface *current,
case 15:
case 16:
/* Default is 565 unless the display is specifically 555 */
if (this->hidden->gxProperties.ffFormat & kfDirect555) {
if (gapi->gxProperties.ffFormat & kfDirect555) {
Rmask = 0x00007c00;
Gmask = 0x000003e0;
Bmask = 0x0000001f;
......@@ -651,7 +674,7 @@ SDL_Surface *GAPI_SetVideoMode(_THIS, SDL_Surface *current,
}
gapi->userOrientation = SDL_ORIENTATION_UP;
gapi->systemOrientation = SDL_ORIENTATION_UP;
systemOrientation = SDL_ORIENTATION_UP;
video->flags = SDL_FULLSCREEN; /* Clear flags, GAPI supports fullscreen only */
/* GAPI or VGA? */
......@@ -664,7 +687,7 @@ SDL_Surface *GAPI_SetVideoMode(_THIS, SDL_Surface *current,
} else
FillStructs(this, 1);
if ( !this->hidden->needUpdate && !this->hidden->videoMem) {
if ( !gapi->needUpdate && !gapi->videoMem) {
SDL_SetError("Couldn't get address of video memory, may be unsupported device or bug");
return(NULL);
}
......@@ -674,11 +697,11 @@ SDL_Surface *GAPI_SetVideoMode(_THIS, SDL_Surface *current,
gapi->userOrientation = SDL_ORIENTATION_RIGHT;
if(GetSystemMetrics(SM_CYSCREEN) < GetSystemMetrics(SM_CXSCREEN))
gapi->systemOrientation = SDL_ORIENTATION_RIGHT;
systemOrientation = SDL_ORIENTATION_RIGHT;
/* shall we apply hires fix? for example when we do not use hires resource */
gapi->hiresFix = 0;
if( gapi->systemOrientation == gapi->userOrientation )
if( systemOrientation == gapi->userOrientation )
{
if( (width > GetSystemMetrics(SM_CXSCREEN)) || (height > GetSystemMetrics(SM_CYSCREEN)))
gapi->hiresFix = 1;
......@@ -700,7 +723,7 @@ SDL_Surface *GAPI_SetVideoMode(_THIS, SDL_Surface *current,
case SDL_ORIENTATION_UP:
case SDL_ORIENTATION_RIGHT:
case SDL_ORIENTATION_LEFT:
if( (this->hidden->videoMode == GAPI_MONO) )
if( (gapi->videoMode == GAPI_MONO) )
gapi->startOffset = -gapi->gxProperties.cbxPitch + 1; // monochrome mode
else
gapi->startOffset = gapi->gxProperties.cbyPitch * (gapi->gxProperties.cyHeight - 1);
......@@ -711,8 +734,8 @@ SDL_Surface *GAPI_SetVideoMode(_THIS, SDL_Surface *current,
}
}
video->w = this->hidden->w = width;
video->h = this->hidden->h = height;
video->w = gapi->w = width;
video->h = gapi->h = height;
video->pitch = SDL_CalculatePitch(video);
/* Small fix for WinCE/Win32 - when activating window
......@@ -729,20 +752,20 @@ SDL_Surface *GAPI_SetVideoMode(_THIS, SDL_Surface *current,
SetWindowLong(SDL_Window, GWL_STYLE, style);
/* Allocate bitmap */
if(gapiBuffer)
if( gapi->buffer )
{
SDL_free(gapiBuffer);
gapiBuffer = NULL;
SDL_free( gapi->buffer );
gapi->buffer = NULL;
}
gapiBuffer = SDL_malloc(video->h * video->pitch);
video->pixels = gapiBuffer;
gapi->buffer = SDL_malloc(video->h * video->pitch);
video->pixels = gapi->buffer;
if ( ! this->hidden->buffer ) {
if ( ! gapi->buffer ) {
SDL_SetError("Couldn't allocate buffer for requested mode");
return(NULL);
}
SDL_memset(gapiBuffer, 255, video->h * video->pitch);
SDL_memset(gapi->buffer, 255, video->h * video->pitch);
MoveWindow(SDL_Window, 0, 0, GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN), FALSE);
ShowWindow(SDL_Window, SW_SHOW);
SetForegroundWindow(SDL_Window);
......@@ -754,9 +777,9 @@ SDL_Surface *GAPI_SetVideoMode(_THIS, SDL_Surface *current,
WIN_FlushMessageQueue();
/* Open GAPI display */
if( !gapi->useVga && this->hidden->useGXOpenDisplay && !this->hidden->alreadyGXOpened )
if( !gapi->useVga && gapi->useGXOpenDisplay && !gapi->alreadyGXOpened )
{
this->hidden->alreadyGXOpened = 1;
gapi->alreadyGXOpened = 1;
if( !gapi->gxFunc.GXOpenDisplay(SDL_Window, GX_FULLSCREEN) )
{
SDL_SetError("Couldn't initialize GAPI");
......@@ -764,6 +787,11 @@ SDL_Surface *GAPI_SetVideoMode(_THIS, SDL_Surface *current,
}
}
if(gapi->useVga)
gapi->coordinateTransform = (4 - systemOrientation + gapi->userOrientation) % 4;
else
gapi->coordinateTransform = gapi->userOrientation;
#if REPORT_VIDEO_INFO
printf("Video properties:\n");
printf("display bpp: %d\n", gapi->gxProperties.cBPP);
......@@ -775,11 +803,11 @@ SDL_Surface *GAPI_SetVideoMode(_THIS, SDL_Surface *current,
printf("y pitch: %d\n", gapi->gxProperties.cbyPitch);
printf("gapi flags: 0x%x\n", gapi->gxProperties.ffFormat);
printf("user orientation: %d\n", gapi->userOrientation);
printf("system orientation: %d\n", gapi->userOrientation);
printf("system orientation: %d\n", systemOrientation);
printf("gapi orientation: %d\n", gapi->gapiOrientation);
if( !gapi->useVga && this->hidden->useGXOpenDisplay && gapi->needUpdate)
if( !gapi->useVga && gapi->useGXOpenDisplay && gapi->needUpdate)
{
gapi->videoMem = gapi->gxFunc.GXBeginDraw();
gapi->gxFunc.GXEndDraw();
......@@ -793,6 +821,7 @@ SDL_Surface *GAPI_SetVideoMode(_THIS, SDL_Surface *current,
printf("video surface bpp: %d\n", video->format->BitsPerPixel);
printf("video surface width: %d\n", video->w);
printf("video surface height: %d\n", video->h);
printf("mouse/arrows transformation angle: %d\n", gapi->coordinateTransform);
#endif
......@@ -1143,8 +1172,8 @@ void GAPI_VideoQuit(_THIS)
/* Destroy the window and everything associated with it */
if ( SDL_Window )
{
if ((g_hGapiLib != 0) && this && this->hidden && this->hidden->gxFunc.GXCloseDisplay && !this->hidden->useVga)
this->hidden->gxFunc.GXCloseDisplay();
if ((g_hGapiLib != 0) && this && gapi && gapi->gxFunc.GXCloseDisplay && !gapi->useVga)
gapi->gxFunc.GXCloseDisplay();
if (this->screen->pixels != NULL)
{
......@@ -1184,6 +1213,11 @@ void GAPI_VideoQuit(_THIS)
}
static void GAPI_Activate(_THIS, BOOL active, BOOL minimized)
{
//Nothing to do here (as far as I know)
}
static void GAPI_RealizePalette(_THIS)
{
OutputDebugString(TEXT("GAPI_RealizePalette NOT IMPLEMENTED !\r\n"));
......@@ -1215,12 +1249,12 @@ static void GAPI_WinPAINT(_THIS, HDC hdc)
// DIB Header
pHeader->biSize = sizeof(BITMAPINFOHEADER);
pHeader->biWidth = this->hidden->w;
pHeader->biHeight = -this->hidden->h;
pHeader->biWidth = gapi->w;
pHeader->biHeight = -gapi->h;
pHeader->biPlanes = 1;
pHeader->biBitCount = bpp;
pHeader->biCompression = BI_RGB;
pHeader->biSizeImage = (this->hidden->w * this->hidden->h * bpp) / 8;
pHeader->biSizeImage = (gapi->w * gapi->h * bpp) / 8;
// Color masks
if( bpp == 16 )
......@@ -1235,11 +1269,11 @@ static void GAPI_WinPAINT(_THIS, HDC hdc)
// copy data
// FIXME: prevent misalignment, but I've never seen non aligned width of screen
memcpy(bitmapData, this->hidden->buffer, pHeader->biSizeImage);
memcpy(bitmapData, gapi->buffer, pHeader->biSizeImage);
srcDC = CreateCompatibleDC(hdc);
prevObject = SelectObject(srcDC, hb);
BitBlt(hdc, 0, 0, this->hidden->w, this->hidden->h, srcDC, 0, 0, SRCCOPY);
BitBlt(hdc, 0, 0, gapi->w, gapi->h, srcDC, 0, 0, SRCCOPY);
SelectObject(srcDC, prevObject);
DeleteObject(hb);
......
......@@ -27,6 +27,7 @@
#include "SDL_mouse.h"
#include "SDL_mutex.h"
#include "../SDL_sysvideo.h"
#include "../windib/SDL_gapidibvideo.h"
/* From gx.h, since it's not really C compliant */
......@@ -100,13 +101,6 @@ struct GapiFunc
#define GX_NORMALKEYS 0x02
#define GX_LANDSCAPEKEYS 0x03
typedef enum
{
SDL_ORIENTATION_UP,
SDL_ORIENTATION_DOWN,
SDL_ORIENTATION_LEFT,
SDL_ORIENTATION_RIGHT
} SDL_ScreenOrientation;
/* GAPI video mode */
typedef enum {
......@@ -117,26 +111,26 @@ typedef enum {
GAPI_PALETTE
} GAPIVideoMode;
/* Hidden "this" pointer for the video functions */
#define _THIS SDL_VideoDevice *this
typedef unsigned short PIXEL;
/* Private display data
begin with DIB private structure to allow DIB events code sharing
*/
struct SDL_PrivateVideoData {
HBITMAP screen_bmp;
HPALETTE screen_pal;
struct GapiInfo {
/* Rotation which has to be applied to the key (arrow keys) and mouse events measured in quarters of a circle
* counter clockwise */
int coordinateTransform;
char hiresFix; /* using hires mode without defining hires resource */
int invert; //TODO this is only written but never read, so it should be removed
#define NUM_MODELISTS 4 /* 8, 16, 24, and 32 bits-per-pixel */
int SDL_nummodes[NUM_MODELISTS];
SDL_Rect **SDL_modelist[NUM_MODELISTS];
// The orientation of the video mode user wants to get
// Probably restricted to UP and RIGHT
SDL_ScreenOrientation userOrientation;
int invert;
char hiresFix; // using hires mode without defining hires resource
// --------------
int useGXOpenDisplay; /* use GXOpenDispplay */
int alreadyGXOpened;
......@@ -158,14 +152,8 @@ struct SDL_PrivateVideoData {
int startOffset; // in bytes
int useVga;
int suspended; // do not pu anything into video memory
// The orientation of the system, as defined by SM_CXSCREEN and SM_CYSCREEN
// User can change it by using 'screen layout' in system options
// Restricted to UP or RIGHT
enum SDL_ScreenOrientation systemOrientation;
};
#define gapiBuffer this->hidden->buffer
#define gapi this->hidden
#endif /* _SDL_gapivideo_h */
......@@ -50,9 +50,13 @@
#include "wmmsg.h"
#endif
#ifdef _WIN32_WCE
#include "../windib/SDL_gapidibvideo.h"
#ifdef SDL_VIDEO_DRIVER_GAPI
#include "../gapi/SDL_gapivideo.h"
#endif
#ifdef _WIN32_WCE
#define IsZoomed(HWND) 1
#define NO_GETKEYBOARDSTATE
#if _WIN32_WCE < 420
......@@ -103,6 +107,9 @@ ToUnicodeFN SDL_ToUnicode = ToUnicode9xME;
#if defined(_WIN32_WCE)
//AdjustWindowRect is not available under WinCE 2003
#define AdjustWindowRect(a,b,c) (AdjustWindowRectEx((a),(b),(c),0))
// dynamically load aygshell dll because we want SDL to work on HPC and be300
HINSTANCE aygshell = NULL;
BOOL (WINAPI *SHFullScreen)(HWND hwndRequester, DWORD dwState) = 0;
......@@ -211,15 +218,19 @@ void WIN_FlushMessageQueue()
static void SDL_RestoreGameMode(void)
{
#ifdef _WIN32_WCE
#ifdef _WIN32_WCE //Under ce we don't minimize, therefore no restore
#ifdef SDL_VIDEO_DRIVER_GAPI
SDL_VideoDevice *this = current_video;
if(SDL_strcmp(this->name, "gapi") == 0)
{
if( this->hidden->suspended )
if( this->hidden->gapiInfo->suspended )
{
this->hidden->suspended = 0;
this->hidden->gapiInfo->suspended = 0;
}
}
#endif
#else
ShowWindow(SDL_Window, SW_RESTORE);
#endif
......@@ -234,14 +245,18 @@ static void SDL_RestoreDesktopMode(void)
{
#ifdef _WIN32_WCE
#ifdef SDL_VIDEO_DRIVER_GAPI
SDL_VideoDevice *this = current_video;
if(SDL_strcmp(this->name, "gapi") == 0)
{
if( !this->hidden->suspended )
if( !this->hidden->gapiInfo->suspended )
{
this->hidden->suspended = 1;
this->hidden->gapiInfo->suspended = 1;
}
}
#endif
#else
/* WinCE does not have a taskbar, so minimizing is not convenient */
ShowWindow(SDL_Window, SW_MINIMIZE);
......@@ -459,9 +474,9 @@ LRESULT CALLBACK WinMessage(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
posted = SDL_PrivateMouseMotion(0, 1, x, y);
}
} else {
#ifdef _WIN32_WCE
if (SDL_VideoSurface)
GapiTransform(this->hidden->userOrientation, this->hidden->hiresFix, &x, &y);
#ifdef SDL_VIDEO_DRIVER_GAPI
if (SDL_VideoSurface && this->hidden->gapiInfo)
GapiTransform(this->hidden->gapiInfo->coordinateTransform, this->hidden->gapiInfo->hiresFix, &x, &y);
#endif
posted = SDL_PrivateMouseMotion(0, 0, x, y);
}
......@@ -564,9 +579,9 @@ LRESULT CALLBACK WinMessage(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
} else {
x = (Sint16)LOWORD(lParam);
y = (Sint16)HIWORD(lParam);
#ifdef _WIN32_WCE
if (SDL_VideoSurface)
GapiTransform(this->hidden->userOrientation, this->hidden->hiresFix, &x, &y);
#ifdef SDL_VIDEO_DRIVER_GAPI
if (SDL_VideoSurface && this->hidden->gapiInfo)
GapiTransform(this->hidden->gapiInfo->coordinateTransform, this->hidden->gapiInfo->hiresFix, &x, &y);
#endif
}
posted = SDL_PrivateMouseButton(
......
......@@ -30,9 +30,17 @@
#include "../../events/SDL_sysevents.h"
#include "../../events/SDL_events_c.h"
#include "../wincommon/SDL_lowvideo.h"
#include "SDL_dibvideo.h"
#include "SDL_gapidibvideo.h"
#include "SDL_vkeys.h"
#ifdef SDL_VIDEO_DRIVER_GAPI
#include "../gapi/SDL_gapivideo.h"
#endif
#ifdef SDL_VIDEO_DRIVER_WINDIB
#include "SDL_dibvideo.h"
#endif
#ifndef WM_APP
#define WM_APP 0x8000
#endif
......@@ -44,6 +52,7 @@
/* The translation table from a Microsoft VK keysym to a SDL keysym */
static SDLKey VK_keymap[SDLK_LAST];
static SDL_keysym *TranslateKey(WPARAM vkey, UINT scancode, SDL_keysym *keysym, int pressed);
static SDLKey Arrows_keymap[4];
/* Masks for processing the windows KEYDOWN and KEYUP messages */
#define REPEATED_KEYMASK (1<<30)
......@@ -59,22 +68,21 @@ static SDL_keysym *TranslateKey(WPARAM vkey, UINT scancode, SDL_keysym *keysym,
static WNDPROCTYPE userWindowProc = NULL;
#ifdef _WIN32_WCE
#ifdef SDL_VIDEO_DRIVER_GAPI
WPARAM rotateKey(WPARAM key,SDL_ScreenOrientation direction)
WPARAM rotateKey(WPARAM key,int direction)
{
if (direction != SDL_ORIENTATION_LEFT)
return key;
if(direction ==0 ) return key;
switch (key) {
case 0x26: /* up */
return 0x27;
return Arrows_keymap[(2 + direction) % 4];
case 0x27: /* right */
return 0x28;
return Arrows_keymap[(1 + direction) % 4];
case 0x28: /* down */
return 0x25;
return Arrows_keymap[direction % 4];
case 0x25: /* left */
return 0x26;
return Arrows_keymap[(3 + direction) % 4];
}
return key;
......@@ -93,14 +101,15 @@ LRESULT DIB_HandleMessage(_THIS, HWND hwnd, UINT msg, WPARAM wParam, LPARAM lPar
case WM_KEYDOWN: {
SDL_keysym keysym;
#ifdef _WIN32_WCE
// Drop GAPI artefacts
if (wParam == 0x84 || wParam == 0x5B)
return 0;
#ifdef SDL_VIDEO_DRIVER_GAPI
if(this->hidden->gapiInfo)
{
// Drop GAPI artefacts
if (wParam == 0x84 || wParam == 0x5B)
return 0;
// Rotate key if necessary
if (this->hidden->orientation != SDL_ORIENTATION_UP)
wParam = rotateKey(wParam, this->hidden->orientation);
wParam = rotateKey(wParam, this->hidden->gapiInfo->coordinateTransform);
}
#endif
/* Ignore repeated keys */
if ( lParam&REPEATED_KEYMASK ) {
......@@ -167,14 +176,15 @@ LRESULT DIB_HandleMessage(_THIS, HWND hwnd, UINT msg, WPARAM wParam, LPARAM lPar
case WM_KEYUP: {
SDL_keysym keysym;
#ifdef _WIN32_WCE
// Drop GAPI artifacts
if (wParam == 0x84 || wParam == 0x5B)
return 0;
// Rotate key if necessary
if (this->hidden->orientation != SDL_ORIENTATION_UP)
wParam = rotateKey(wParam, this->hidden->orientation);
#ifdef SDL_VIDEO_DRIVER_GAPI
if(this->hidden->gapiInfo)
{
// Drop GAPI artifacts
if (wParam == 0x84 || wParam == 0x5B)
return 0;
wParam = rotateKey(wParam, this->hidden->gapiInfo->coordinateTransform);
}
#endif
switch (wParam) {
......@@ -222,12 +232,11 @@ LRESULT DIB_HandleMessage(_THIS, HWND hwnd, UINT msg, WPARAM wParam, LPARAM lPar
TranslateKey(wParam,HIWORD(lParam),&keysym,0));
}
return(0);
#if defined(SC_SCREENSAVE) && defined(SC_MONITORPOWER)
case WM_SYSCOMMAND: {
const DWORD val = (DWORD) (wParam & 0xFFF0);
if ((val == SC_SCREENSAVE) || (val == SC_MONITORPOWER)) {
if (!allow_screensaver) {
if (this->hidden->dibInfo && !allow_screensaver) {
/* Note that this doesn't stop anything on Vista
if the screensaver has a password. */
return(0);
......@@ -430,6 +439,11 @@ void DIB_InitOSKeymap(_THIS)
VK_keymap[VK_SNAPSHOT] = SDLK_PRINT;
VK_keymap[VK_CANCEL] = SDLK_BREAK;
VK_keymap[VK_APPS] = SDLK_MENU;
Arrows_keymap[3] = 0x25;
Arrows_keymap[2] = 0x26;
Arrows_keymap[1] = 0x27;
Arrows_keymap[0] = 0x28;
}
#define EXTKEYPAD(keypad) ((scancode & 0x100)?(mvke):(keypad))
......@@ -485,9 +499,19 @@ static SDL_keysym *TranslateKey(WPARAM vkey, UINT scancode, SDL_keysym *keysym,
keysym->scancode = (unsigned char) scancode;
keysym->mod = KMOD_NONE;
keysym->unicode = 0;
if ((vkey == VK_RETURN) && (scancode & 0x100)) {
/* No VK_ code for the keypad enter key */
keysym->sym = SDLK_KP_ENTER;
}
else {
keysym->sym = VK_keymap[SDL_MapVirtualKey(scancode, vkey)];
}
if ( pressed && SDL_TranslateUNICODE ) {
#ifdef NO_GETKEYBOARDSTATE
/* Uh oh, better hope the vkey is close enough.. */
if((keysym->sym == vkey) || (vkey > 0x7f))
keysym->unicode = vkey;
#else
BYTE keystate[256];
......@@ -501,14 +525,6 @@ static SDL_keysym *TranslateKey(WPARAM vkey, UINT scancode, SDL_keysym *keysym,
#endif /* NO_GETKEYBOARDSTATE */
}
if ((vkey == VK_RETURN) && (scancode & 0x100)) {
/* No VK_ code for the keypad enter key */
keysym->sym = SDLK_KP_ENTER;
}
else {
keysym->sym = VK_keymap[SDL_MapVirtualKey(scancode, vkey)];
}
#if 0
{
HKL hLayoutCurrent = GetKeyboardLayout(0);
......
......@@ -34,6 +34,7 @@
#include "../SDL_pixels_c.h"
#include "../../events/SDL_sysevents.h"
#include "../../events/SDL_events_c.h"
#include "SDL_gapidibvideo.h"
#include "SDL_dibvideo.h"
#include "../wincommon/SDL_syswm_c.h"
#include "../wincommon/SDL_sysmouse_c.h"
......@@ -128,6 +129,9 @@ static void DIB_DeleteDevice(SDL_VideoDevice *device)
{
if ( device ) {
if ( device->hidden ) {
if ( device->hidden->dibInfo ) {
SDL_free( device->hidden->dibInfo );
}
SDL_free(device->hidden);
}
if ( device->gl_data ) {
......@@ -147,6 +151,16 @@ static SDL_VideoDevice *DIB_CreateDevice(int devindex)
SDL_memset(device, 0, (sizeof *device));
device->hidden = (struct SDL_PrivateVideoData *)
SDL_malloc((sizeof *device->hidden));
if(device->hidden){
SDL_memset(device->hidden, 0, (sizeof *device->hidden));
device->hidden->dibInfo = (DibInfo *)SDL_malloc((sizeof(DibInfo)));
if(device->hidden->dibInfo == NULL)
{
SDL_free(device->hidden);
device->hidden = NULL;
}
}
device->gl_data = (struct SDL_PrivateGLData *)
SDL_malloc((sizeof *device->gl_data));
}
......@@ -156,7 +170,7 @@ static SDL_VideoDevice *DIB_CreateDevice(int devindex)
DIB_DeleteDevice(device);
return(NULL);
}
SDL_memset(device->hidden, 0, (sizeof *device->hidden));
SDL_memset(device->hidden->dibInfo, 0, (sizeof *device->hidden->dibInfo));
SDL_memset(device->gl_data, 0, (sizeof *device->gl_data));
/* Set the function pointers */
......@@ -347,6 +361,8 @@ int DIB_VideoInit(_THIS, SDL_PixelFormat *vformat)
this->hidden->supportRotation = ChangeDisplaySettingsEx(NULL, &settings, NULL, CDS_TEST, NULL) == DISP_CHANGE_SUCCESSFUL;
#endif
/* Query for the desktop resolution */
SDL_desktop_mode.dmSize = sizeof(SDL_desktop_mode);
SDL_desktop_mode.dmDriverExtra = 0;
EnumDisplaySettings(NULL, ENUM_CURRENT_SETTINGS, &SDL_desktop_mode);
this->info.current_w = SDL_desktop_mode.dmPelsWidth;
this->info.current_h = SDL_desktop_mode.dmPelsHeight;
......@@ -744,7 +760,7 @@ SDL_Surface *DIB_SetVideoMode(_THIS, SDL_Surface *current,
video->flags |= SDL_RESIZABLE;
}
}
#if WS_MAXIMIZE
#if WS_MAXIMIZE && !defined(_WIN32_WCE)
if (IsZoomed(SDL_Window)) style |= WS_MAXIMIZE;
#endif
}
......@@ -1006,7 +1022,7 @@ int DIB_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color *colors)
entry->peBlue = colors[i].b;
entry->peFlags = PC_NOCOLLAPSE;
}
#ifdef SYSPAL_NOSTATIC
#if defined(SYSPAL_NOSTATIC) && !defined(_WIN32_WCE)
/* Check to make sure black and white are in position */
if ( GetSystemPaletteUse(hdc) != SYSPAL_NOSTATIC256 ) {
moved_entries += CheckPaletteEntry(screen_logpal, 0, 0x00, 0x00, 0x00);
......@@ -1227,7 +1243,7 @@ void DIB_VideoQuit(_THIS)
/* Exported for the windows message loop only */
static void DIB_GrabStaticColors(HWND window)
{
#ifdef SYSPAL_NOSTATIC
#if defined(SYSPAL_NOSTATIC) && !defined(_WIN32_WCE)
HDC hdc;
hdc = GetDC(window);
......@@ -1240,7 +1256,7 @@ static void DIB_GrabStaticColors(HWND window)
}
static void DIB_ReleaseStaticColors(HWND window)
{
#ifdef SYSPAL_NOSTATIC
#if defined(SYSPAL_NOSTATIC) && !defined(_WIN32_WCE)
HDC hdc;
hdc = GetDC(window);
......
......@@ -27,18 +27,10 @@
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
/* for PDA */
typedef enum
{
SDL_ORIENTATION_UP,
SDL_ORIENTATION_DOWN,
SDL_ORIENTATION_LEFT,
SDL_ORIENTATION_RIGHT
} SDL_ScreenOrientation;
/* Private display data */
struct SDL_PrivateVideoData {
HBITMAP screen_bmp;
struct DibInfo {
HBITMAP screen_bmp;
HPALETTE screen_pal;
LOGPALETTE *screen_logpal;
BOOL grab_palette;
......@@ -46,11 +38,8 @@ struct SDL_PrivateVideoData {
#define NUM_MODELISTS 4 /* 8, 16, 24, and 32 bits-per-pixel */
int SDL_nummodes[NUM_MODELISTS];
SDL_Rect **SDL_modelist[NUM_MODELISTS];
SDL_ScreenOrientation orientation;
#ifdef _WIN32_WCE
int invert; /* do to remove, used by GAPI driver! */
char hiresFix; /* using hires mode without defining hires resource */
int supportRotation; /* for Pocket PC devices */
DWORD origRotation; /* for Pocket PC devices */
#endif
......@@ -59,12 +48,12 @@ struct SDL_PrivateVideoData {
int allow_screensaver;
};
/* Old variable names */
#define screen_bmp (this->hidden->screen_bmp)
#define screen_pal (this->hidden->screen_pal)
#define screen_logpal (this->hidden->screen_logpal)
#define grab_palette (this->hidden->grab_palette)
#define SDL_nummodes (this->hidden->SDL_nummodes)
#define SDL_modelist (this->hidden->SDL_modelist)
#define allow_screensaver (this->hidden->allow_screensaver)
#define screen_bmp (this->hidden->dibInfo->screen_bmp)
#define screen_pal (this->hidden->dibInfo->screen_pal)
#define screen_logpal (this->hidden->dibInfo->screen_logpal)
#define grab_palette (this->hidden->dibInfo->grab_palette)
#define SDL_nummodes (this->hidden->dibInfo->SDL_nummodes)
#define SDL_modelist (this->hidden->dibInfo->SDL_modelist)
#define allow_screensaver (this->hidden->dibInfo->allow_screensaver)
#endif /* _SDL_dibvideo_h */
/*
SDL - Simple DirectMedia Layer
Copyright (C) 1997-2009 Sam Lantinga
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Sam Lantinga
slouken@libsdl.org
*/
#include "SDL_config.h"
#ifndef _SDL_gapidibvideo_h
#define _SDL_gapidibvideo_h
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
/* Hidden "this" pointer for the video functions */
#define _THIS SDL_VideoDevice *this
/* typedef these to be able to define pointers, but still force everybody who
* wants to access them to include the corresponding header */
typedef struct GapiInfo GapiInfo;
typedef struct DibInfo DibInfo;
/* for PDA */
typedef enum
{
SDL_ORIENTATION_UP,
SDL_ORIENTATION_DOWN,
SDL_ORIENTATION_LEFT,
SDL_ORIENTATION_RIGHT
} SDL_ScreenOrientation;
/* Private display data shared by gapi and windib*/
struct SDL_PrivateVideoData {
int supportRotation; /* for Pocket PC devices */
DWORD origRotation; /* for Pocket PC devices */
GapiInfo* gapiInfo;
DibInfo* dibInfo;
};
#endif
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment