Mercurial > sdl-ios-xcode
view src/video/symbian/EKA2/SDL_epocvideo.cpp @ 4157:baf615f9f2a0 SDL-1.2
Date: Thu, 16 Oct 2008 20:27:34 +0400
From: "Ilya Kasnacheev" <ilya.kasnacheev@gmail.com>
To: sdl@lists.libsdl.org
Subject: [SDL] SDL for Windows CE: a few GAPI patches
Hi *!
I've just ported a POWDER roguelike ( http://www.zincland.com/powder/ ) to
Windows CE (PDAs, Windows Mobile/Pocket PC). To do that, I had to get libsdl
working. Thanks for the awesome project files, it built without a hitch.
Nevertheless, I've found quite a few bugs in Windows CE (GAPI) SDL
implementation, which I've solved and now present as a serie of patches.
I'll try carefully annotate them. Please annotate them so I can work
toward accepting
them into the main source tree since without them SDL isn't really working on
Windows CE (I wonder why nobody fixed them before, btw: why isn't SDL popular as
a way to develop Windows CE games? Where are no ports?)
These changes can't be considered flawless, but they can be considered working
because I've yet to hear complains about things I fixed and POWDER build for
Windows CE is now considered stable.
Note: my comments start with !!, delete them before applying.
diff -bru SDL-1.2.13/src/video/gapi/SDL_gapivideo.c
SDL-1.2.13-new/src/video/gapi/SDL_gapivideo.c
--- SDL-1.2.13/src/video/gapi/SDL_gapivideo.c 2007-12-31
07:48:00.000000000 +0300
+++ SDL-1.2.13-new/src/video/gapi/SDL_gapivideo.c 2008-10-16
20:02:11.000000000 +0400
@@ -643,6 +643,7 @@
}
gapi->userOrientation = SDL_ORIENTATION_UP;
+ gapi->systemOrientation = SDL_ORIENTATION_UP;
video->flags = SDL_FULLSCREEN; /* Clear flags, GAPI supports
fullscreen only */
/* GAPI or VGA? */
@@ -661,18 +662,21 @@
}
/* detect user landscape mode */
- if( (width > height) && (GetSystemMetrics(SM_CXSCREEN) <
GetSystemMetrics(SM_CYSCREEN)))
+ if( (width > height) && (gapi->gxProperties.cxWidth <
gapi->gxProperties.cyHeight))
gapi->userOrientation = SDL_ORIENTATION_RIGHT;
+ if(GetSystemMetrics(SM_CYSCREEN) < GetSystemMetrics(SM_CXSCREEN))
+ gapi->systemOrientation = SDL_ORIENTATION_RIGHT;
+
/* shall we apply hires fix? for example when we do not use
hires resource */
gapi->hiresFix = 0;
- if( gapi->userOrientation == SDL_ORIENTATION_RIGHT )
+ if( gapi->systemOrientation == gapi->userOrientation )
{
- if( (width > GetSystemMetrics(SM_CYSCREEN)) || (height
> GetSystemMetrics(SM_CXSCREEN)))
+ if( (width > GetSystemMetrics(SM_CXSCREEN)) || (height
> GetSystemMetrics(SM_CYSCREEN)))
gapi->hiresFix = 1;
} else
- if( (width > GetSystemMetrics(SM_CXSCREEN)) || (height
> GetSystemMetrics(SM_CYSCREEN)))
- if( !((width == GetSystemMetrics(SM_CYSCREEN))
&& (height == GetSystemMetrics(SM_CXSCREEN)))) // user portrait,
device landscape
+ if( (width > GetSystemMetrics(SM_CYSCREEN)) || (height
> GetSystemMetrics(SM_CXSCREEN)))
+// if( !((width == gapi->gxProperties.cyHeight)
&& (height == gapi->gxProperties.cxWidth))) // user portrait, device
landscape
gapi->hiresFix = 1;
switch( gapi->userOrientation )
!! It used to query system metrics which return dimensions according to screen
!! orientation, which can really be portrait, left landscape or right landscape.
!! This is presumably incorrect because we couldn't care less about user mode
!! dimensions - all we want are the GAPI framebuffer dimensions, which
only match
!! user dimensions in one of possible orientations.
!! There's a fair dose of cargo cult programming involved in this fix, but it
!! used to work only in one orientation (portrait for PDAs, where frame-buffer
!! have same orientation as user screen), and now it works on all orientations.
@@ -742,21 +746,30 @@
WIN_FlushMessageQueue();
/* Open GAPI display */
- if( !gapi->useVga && this->hidden->useGXOpenDisplay )
+ if( !gapi->useVga && this->hidden->useGXOpenDisplay &&
!this->hidden->alreadyGXOpened )
+ {
+ this->hidden->alreadyGXOpened = 1;
if( !gapi->gxFunc.GXOpenDisplay(SDL_Window, GX_FULLSCREEN) )
{
SDL_SetError("Couldn't initialize GAPI");
return(NULL);
}
+ }
#if REPORT_VIDEO_INFO
printf("Video properties:\n");
printf("display bpp: %d\n", gapi->gxProperties.cBPP);
printf("display width: %d\n", gapi->gxProperties.cxWidth);
printf("display height: %d\n", gapi->gxProperties.cyHeight);
+ printf("system display width: %d\n", GetSystemMetrics(SM_CXSCREEN));
+ printf("system display height: %d\n", GetSystemMetrics(SM_CYSCREEN));
printf("x pitch: %d\n", gapi->gxProperties.cbxPitch);
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("gapi orientation: %d\n", gapi->gapiOrientation);
+
if( !gapi->useVga && this->hidden->useGXOpenDisplay && gapi->needUpdate)
{
!! Previous version used to call gapi->gxFunc.GXOpenDisplay each time the video
!! mode would be changed. You shouldn't, because this call has a
meaning "Lock the
!! GAPI framebuffer, designate it as busy", so the second call will fail (it is
!! already locked/busy).
!! Testing might not find that because most programs set up the video mode only
!! once, but POWDER does this once in a while, so it crashed when in
320x240 mode
!! (640x480 mode doesn't use that code, it worked fine).
diff -bru SDL-1.2.13/src/video/gapi/SDL_gapivideo.h
SDL-1.2.13-new/src/video/gapi/SDL_gapivideo.h
--- SDL-1.2.13/src/video/gapi/SDL_gapivideo.h 2007-12-31
07:48:00.000000000 +0300
+++ SDL-1.2.13-new/src/video/gapi/SDL_gapivideo.h 2008-10-16
20:02:11.000000000 +0400
@@ -132,12 +132,17 @@
#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
enum SDL_ScreenOrientation userOrientation;
int invert;
char hiresFix; // using hires mode without defining hires resource
// --------------
int useGXOpenDisplay; /* use GXOpenDispplay */
+ int alreadyGXOpened;
int w, h;
+ // The orientation of GAPI framebuffer.
+ // Never changes on the same device.
enum SDL_ScreenOrientation gapiOrientation;
void *buffer; // may be 8, 16, 24, 32 bpp
@@ -153,6 +158,10 @@
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;
};
!! This is a flag variable, see the previous comment
!! And yet another orientation: now we have to keep three of them in mind.
diff -bru SDL-1.2.13/src/video/wincommon/SDL_sysevents.c
SDL-1.2.13-new/src/video/wincommon/SDL_sysevents.c
--- SDL-1.2.13/src/video/wincommon/SDL_sysevents.c 2007-12-31
07:48:02.000000000 +0300
+++ SDL-1.2.13-new/src/video/wincommon/SDL_sysevents.c 2008-10-16
20:02:12.000000000 +0400
@@ -160,10 +160,22 @@
#endif */
}
break;
+ // FIXME: Older version used just SDL_VideoSurface->(w, h)
+ // w and h are "clipped" while x and y are "raw", which caused
+ // x in former and y in latter case to be clipped in a
wrong direction,
+ // thus offsetting the coordinate on 2 x clip pixels
+ // (like, 128 for 640 -> 512 clipping).
+ // We will now try to extract and use raw values.
+ // The way to do that RIGHT is do
(orientation-dependent) clipping before
+ // doing this transform, but it's hardly possible.
+
+ // SEE SDL_mouse.c /ClipOffset to understand these calculations.
case SDL_ORIENTATION_RIGHT:
if (!SDL_VideoSurface)
break;
- rotatedX = SDL_VideoSurface->w - *y;
+ rotatedX = (2 *
((SDL_VideoSurface->offset%SDL_VideoSurface->pitch)/
+ SDL_VideoSurface->format->BytesPerPixel))
+ + SDL_VideoSurface->w - *y;
rotatedY = *x;
*x = rotatedX;
*y = rotatedY;
@@ -172,7 +184,8 @@
if (!SDL_VideoSurface)
break;
rotatedX = *y;
- rotatedY = SDL_VideoSurface->h - *x;
+ rotatedY = (2 *
(SDL_VideoSurface->offset/SDL_VideoSurface->pitch))
+ + SDL_VideoSurface->h - *x;
*x = rotatedX;
*y = rotatedY;
break;
!! That's the trickest part, hence the long comment.
!! GAPI would really support only 320x240 or 640x480 mode, if application
!! requested the different screen size (as POWDER did, wishing
256x192), then SDL
!! is going to grab the first mode that fits the requested, and pad the screen
!! with black bars (as they do with wide-screen films).
!! It would also get, say, 240x320 mode, and to turn it into 256x192 it would
!! need to rotate mouse clicks.
!! It worked, but one bug slipped through: it would receive mouse clicks
!! unpadded, then rotate them, and then pad the black bars. The
problem is: rotate
!! is done by GAPI driver while padding is done by SDL core. SDL core
doesn't know
!! anything about rotating, so it would pad one of dimensions incorrectly.
I understand that some of my claims (or code) might seem unbacked, but you can
always grab the POWDER binary, compile your own libsdl with one or more of
those fixes turned off, and see how weird it would misbehave. I can even supply
you with those custom builds of libsdl if you don't want to set up the build
environment for windows ce, you'll just need a PDA or a smartphone with it.
I plan to take care of SDL on Windows CE as long as I maintain the POWDER port.
POWDER is good for that because it:
Employs both padded (with centered image, black bars) and unpadded
(image occupies full screen) graphics; initializes video more than
once; uses both 320x240 and 640x480 video; uses both stylus and
buttons.
There's still a list of unresolved issues which I'm planning to fix:
1) Arrow buttons on PDA return weird scancodes compared to PC, this
caused the game to misbehave before I've fixed that. You can see it on
those diagrams:
http://wrar.name/upload/powder-htc.png
http://wrar.name/upload/powder-pda.png
2) SDL (or underlying windows) doesn't care to rotate arrow presses
when we're in a low-res GAPI mode, but it will rotate them in VGA mode
(because of different screen orientations, the same arrow buttons can
suddently mean different directions). Solution: we should stick to
GAPI user orientation (the orientation the program supposedly wants)
and rotate the keys on our own.
_______________________________________________
SDL mailing list
SDL@lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Fri, 07 Nov 2008 04:15:36 +0000 |
parents | e85e65aec22f |
children | a1b03ba2fcd0 |
line wrap: on
line source
/* SDL - Simple DirectMedia Layer Copyright (C) 1997, 1998, 1999, 2000, 2001 Sam Lantinga This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 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 Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; if not, write to the Free Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Sam Lantinga slouken@devolution.com */ /* SDL_epocvideo.cpp Epoc based SDL video driver implementation Markus Mertama */ #include "epoc_sdl.h" #include <stdlib.h> #include <stdio.h> #include <string.h> extern "C" { #include "SDL_error.h" #include "SDL_timer.h" #include "SDL_video.h" #undef NULL #include "SDL_pixels_c.h" #include "SDL.h" #include "SDL_mouse.h" } #include "SDL_epocvideo.h" #include "SDL_epocevents_c.h" #include <coedef.h> #include <flogger.h> #include <eikenv.h> #include <eikappui.h> #include <eikapp.h> #include "sdlepocapi.h" //////////////////////////////////////////////////////////////// _LIT(KLibName, "SDL"); void RDebug_Print_b(char* error_str, void* param) { TBuf8<128> error8((TUint8*)error_str); TBuf<128> error; error.Copy(error8); #ifndef TRACE_TO_FILE if (param) //!! Do not work if the parameter is really 0!! RDebug::Print(error, param); else RDebug::Print(error); #else if (param) //!! Do not work if the parameter is really 0!! RFileLogger::WriteFormat(KLibName, _L("SDL.txt"), EFileLoggingModeAppend, error, param); else RFileLogger::Write(KLibName, _L("SDL.txt"), EFileLoggingModeAppend, error); #endif } extern "C" void RDebug_Print(char* error_str, void* param) { RDebug_Print_b(error_str, param); } /* int Debug_AvailMem2() { //User::CompressAllHeaps(); TMemoryInfoV1Buf membuf; User::LeaveIfError(UserHal::MemoryInfo(membuf)); TMemoryInfoV1 minfo = membuf(); return(minfo.iFreeRamInBytes); } extern "C" int Debug_AvailMem() { return(Debug_AvailMem2()); } */ extern "C" { /* Initialization/Query functions */ static int EPOC_VideoInit(_THIS, SDL_PixelFormat *vformat); static SDL_Rect **EPOC_ListModes(_THIS, SDL_PixelFormat *format, Uint32 flags); static SDL_Surface *EPOC_SetVideoMode(_THIS, SDL_Surface *current, int width, int height, int bpp, Uint32 flags); static int EPOC_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color *colors); static void EPOC_VideoQuit(_THIS); /* Hardware surface functions */ static int EPOC_AllocHWSurface(_THIS, SDL_Surface *surface); static int EPOC_LockHWSurface(_THIS, SDL_Surface *surface); static int EPOC_FlipHWSurface(_THIS, SDL_Surface *surface); static void EPOC_UnlockHWSurface(_THIS, SDL_Surface *surface); static void EPOC_FreeHWSurface(_THIS, SDL_Surface *surface); static void EPOC_DirectUpdate(_THIS, int numrects, SDL_Rect *rects); static int EPOC_Available(void); static SDL_VideoDevice *EPOC_CreateDevice(int devindex); void DrawBackground(_THIS); void DirectDraw(_THIS, int numrects, SDL_Rect *rects, TUint16* screenBuffer); void DirectDrawRotated(_THIS, int numrects, SDL_Rect *rects, TUint16* screenBuffer); /* Mouse functions */ static WMcursor *EPOC_CreateWMCursor(_THIS, Uint8 *data, Uint8 *mask, int w, int h, int hot_x, int hot_y); static void EPOC_FreeWMCursor(_THIS, WMcursor *cursor); static int EPOC_ShowWMCursor(_THIS, WMcursor *cursor); } extern "C" { struct WMcursor { }; } /* Epoc video driver bootstrap functions */ static int EPOC_Available(void) { return 1; /* Always available */ } static void EPOC_DeleteDevice(SDL_VideoDevice *device) { User::Free(device->hidden); User::Free(device); } static SDL_VideoDevice *EPOC_CreateDevice(int /*devindex*/) { SDL_VideoDevice *device; SDL_TRACE("SDL:EPOC_CreateDevice"); /* Allocate all variables that we free on delete */ device = static_cast<SDL_VideoDevice*>(User::Alloc(sizeof(SDL_VideoDevice))); if ( device ) { Mem::FillZ(device, (sizeof *device)); device->hidden = static_cast<struct SDL_PrivateVideoData*> (User::Alloc((sizeof *device->hidden))); } if ( (device == NULL) || (device->hidden == NULL) ) { SDL_OutOfMemory(); if ( device ) { User::Free(device); } return(0); } Mem::FillZ(device->hidden, (sizeof *device->hidden)); /* Set the function pointers */ device->VideoInit = EPOC_VideoInit; device->ListModes = EPOC_ListModes; device->SetVideoMode = EPOC_SetVideoMode; device->SetColors = EPOC_SetColors; device->UpdateRects = NULL; device->VideoQuit = EPOC_VideoQuit; device->AllocHWSurface = EPOC_AllocHWSurface; device->CheckHWBlit = NULL; device->FillHWRect = NULL; device->SetHWColorKey = NULL; device->SetHWAlpha = NULL; device->LockHWSurface = EPOC_LockHWSurface; device->UnlockHWSurface = EPOC_UnlockHWSurface; device->FlipHWSurface = EPOC_FlipHWSurface; device->FreeHWSurface = EPOC_FreeHWSurface; device->SetIcon = NULL; device->SetCaption = NULL; device->GetWMInfo = NULL; device->FreeWMCursor = EPOC_FreeWMCursor; device->CreateWMCursor = EPOC_CreateWMCursor; device->ShowWMCursor = EPOC_ShowWMCursor; device->WarpWMCursor = NULL; device->InitOSKeymap = EPOC_InitOSKeymap; device->PumpEvents = EPOC_PumpEvents; device->free = EPOC_DeleteDevice; return device; } VideoBootStrap EPOC_bootstrap = { "epoc\0\0\0", "EPOC system", EPOC_Available, EPOC_CreateDevice }; void DisableKeyBlocking(_THIS) { EpocSdlEnv::Request(EpocSdlEnv::EDisableKeyBlocking); } void ConstructWindowL(_THIS) { SDL_TRACE("SDL:ConstructWindowL"); DisableKeyBlocking(_this); //disable key blocking } int EPOC_VideoInit(_THIS, SDL_PixelFormat *vformat) { /* Construct Epoc window */ ConstructWindowL(_this); /* Initialise Epoc frame buffer */ const TDisplayMode displayMode = EpocSdlEnv::DisplayMode(); /* The "best" video format should be returned to caller. */ vformat->BitsPerPixel = TDisplayModeUtils::NumDisplayModeBitsPerPixel(displayMode); vformat->BytesPerPixel = TDisplayModeUtils::NumDisplayModeBitsPerPixel(displayMode) / 8; //?? Private->iWindow->PointerFilter(EPointerFilterDrag, 0); Private->iScreenPos = TPoint(0, 0); Private->iRect.x = Private->iScreenPos.iX; Private->iRect.y = Private->iScreenPos.iY; const TSize sz = EpocSdlEnv::WindowSize(); Private->iRect.w = sz.iWidth; Private->iRect.h = sz.iHeight; Private->iRectPtr = &Private->iRect; return(0); } SDL_Rect **EPOC_ListModes(_THIS, SDL_PixelFormat *format, Uint32 flags) { if(flags & SDL_HWSURFACE) { if(format->BytesPerPixel != 4) //in HW only full color is supported return NULL; } if(flags & SDL_FULLSCREEN) { return &Private->iRectPtr; } return (SDL_Rect **)(-1); //everythingisok, unless too small shoes } int EPOC_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color *colors) { if ((firstcolor+ncolors) > 256) return -1; TUint32 palette[256]; const TDisplayMode mode = EpocSdlEnv::DisplayMode(); if(TDisplayModeUtils::NumDisplayModeColors(mode) == 4096) { // Set 12 bit palette for(int i = firstcolor; i < ncolors; i++) { // 4k value: 0000 rrrr gggg bbbb TUint32 color4K = (colors[i].r & 0x0000f0) << 4; color4K |= (colors[i].g & 0x0000f0); color4K |= (colors[i].b & 0x0000f0) >> 4; palette[i] = color4K; } } else if(TDisplayModeUtils::NumDisplayModeColors(mode) == 65536) { for(int i = firstcolor; i < ncolors; i++) { // 64k-colour displays effectively support RGB values // with 5 bits allocated to red, 6 to green and 5 to blue // 64k value: rrrr rggg gggb bbbb TUint32 color64K = (colors[i].r & 0x0000f8) << 8; color64K |= (colors[i].g & 0x0000fc) << 3; color64K |= (colors[i].b & 0x0000f8) >> 3; palette[i] = color64K; } } else if(TDisplayModeUtils::NumDisplayModeColors(mode) == 16777216) { for(int i = firstcolor; i < ncolors; i++) { // 16M-colour //0000 0000 rrrr rrrr gggg gggg bbbb bbbb TUint32 color16M = colors[i].r << 16; color16M |= colors[i].g << 8; color16M |= colors[i].b; palette[i] = color16M; } } else { return -2; } if(EpocSdlEnv::SetPalette(firstcolor, ncolors, palette) == KErrNone) return 0; return -1; } /* void AllocHWSurfaceL(CFbsBitmap*& aBitmap, const TDisplayMode& aMode, const TSize& aSize) { aBitmap = new (ELeave) CFbsBitmap(); if(KErrNone != aBitmap->CreateHardwareBitmap(aSize, aMode, EpocSdlEnv::EikonEnv().EikAppUi()->Application()->AppDllUid())) //...if it fails - should we use wsbitmaps??? {//the good reason to use hw bitmaps is that they wont need lock heap PANIC_IF_ERROR(aBitmap->Create(aSize, aMode)); } } int CreateSurfaceL(_THIS, SDL_Surface* surface) { __ASSERT_ALWAYS(Private->iFrame == NULL, PANIC(KErrAlreadyExists)); ; TInt dmode = EColorLast; TDisplayMode displayMode; EpocSdlEnv::GetDiplayMode(displayMode); if( TDisplayModeUtils::NumDisplayModeBitsPerPixel(displayMode) == surface->format->BitsPerPixel) { dmode = displayMode; } else { --dmode; while(TDisplayModeUtils::IsDisplayModeColor(TDisplayMode(dmode)) && TDisplayModeUtils::NumDisplayModeBitsPerPixel(TDisplayMode(dmode)) != surface->format->BitsPerPixel) --dmode; } __ASSERT_ALWAYS(TDisplayModeUtils::IsDisplayModeColor(TDisplayMode(dmode)), PANIC(KErrNotSupported)); TRAPD(err, AllocHWSurfaceL(Private->iFrame, TDisplayMode(dmode), TSize(surface->w, surface->h))); return err == KErrNone ? 0 : -1; } */ TDisplayMode GetDisplayMode(TInt aBitsPerPixel) { const TDisplayMode displayMode = EpocSdlEnv::DisplayMode(); TInt dmode = EColorLast; if( TDisplayModeUtils::NumDisplayModeBitsPerPixel(displayMode) == aBitsPerPixel) { dmode = displayMode; } else { --dmode; while(TDisplayModeUtils::IsDisplayModeColor(TDisplayMode(dmode)) && TDisplayModeUtils::NumDisplayModeBitsPerPixel(TDisplayMode(dmode)) != aBitsPerPixel) --dmode; } return TDisplayMode(dmode); } SDL_Surface *EPOC_SetVideoMode(_THIS, SDL_Surface *current, int width, int height, int bpp, Uint32 flags) { const TSize screenSize = EpocSdlEnv::WindowSize(TSize(width, height)); if(width > screenSize.iWidth || height > screenSize.iHeight) { if(flags & SDL_FULLSCREEN) { width = screenSize.iWidth; height = screenSize.iHeight; } else return NULL; } if(current && current->pixels) { // free(current->pixels); current->pixels = NULL; } if(!SDL_ReallocFormat(current, bpp, 0, 0, 0, 0)) { return(NULL); } current->flags = 0; if(width == screenSize.iWidth && height == screenSize.iHeight) current->flags |= SDL_FULLSCREEN; const int numBytesPerPixel = ((bpp-1)>>3) + 1; current->pitch = numBytesPerPixel * width; // Number of bytes in scanline /* Set up the new mode framebuffer */ current->flags |= SDL_PREALLOC; if(bpp <= 8) current->flags |= SDL_HWPALETTE; User::Free(Private->iSwSurface); current->pixels = NULL; Private->iSwSurface = NULL; if(flags & SDL_HWSURFACE) { current->flags |= SDL_HWSURFACE; // current->pixels = NULL; // Private->iSwSurface = NULL; } else { current->flags |= SDL_SWSURFACE; const TInt surfacesize = width * height * numBytesPerPixel; Private->iSwSurfaceSize = TSize(width, height); delete Private->iSwSurface; Private->iSwSurface = NULL; current->pixels = (TUint8*) User::AllocL(surfacesize); Private->iSwSurface = (TUint8*) current->pixels; const TInt err = EpocSdlEnv::AllocSwSurface (TSize(width, height), GetDisplayMode(current->format->BitsPerPixel)); if(err != KErrNone) return NULL; } current->w = width; current->h = height; /* Set the blit function */ _this->UpdateRects = EPOC_DirectUpdate; /* * Logic for getting suitable screen dimensions, offset, scaling and orientation */ /* Centralize game window on device screen */ Private->iScreenPos.iX = Max(0, (screenSize.iWidth - width) / 2); Private->iScreenPos.iY = Max(0, (screenSize.iHeight - height) / 2); // delete (Private->iFrame); // Private->iFrame = NULL; // TRAPD(err, CreateSurfaceL(_this, current)); // PANIC_IF_ERROR(err); SDL_TRACE1("View width %d", width); SDL_TRACE1("View height %d", height); SDL_TRACE1("View bmode %d", bpp); SDL_TRACE1("View x %d", Private->iScreenPos.iX); SDL_TRACE1("View y %d", Private->iScreenPos.iY); EpocSdlEnv::LockPalette(EFalse); /* We're done */ return(current); } static int EPOC_AllocHWSurface(_THIS, SDL_Surface* surface) { return KErrNone == EpocSdlEnv::AllocHwSurface(TSize(surface->w, surface->h), GetDisplayMode(surface->format->BitsPerPixel)); } static void EPOC_FreeHWSurface(_THIS, SDL_Surface* /*surface*/) { } static int EPOC_LockHWSurface(_THIS, SDL_Surface* surface) { if(EpocSdlEnv::IsDsaAvailable()) { TUint8* address = EpocSdlEnv::LockHwSurface(); if(address != NULL) { surface->pixels = address; return 1; } } return 0; } static void EPOC_UnlockHWSurface(_THIS, SDL_Surface* /*surface*/) { EpocSdlEnv::UnlockHwSurface(); } static int EPOC_FlipHWSurface(_THIS, SDL_Surface* /*surface*/) { return(0); } static void EPOC_DirectUpdate(_THIS, int numrects, SDL_Rect *rects) { if(EpocSdlEnv::IsDsaAvailable()) { if(Private->iSwSurface) { const TRect target(Private->iScreenPos, Private->iSwSurfaceSize); for(TInt i = 0; i < numrects ;i++) { const TRect rect(TPoint(rects[i].x, rects[i].y), TSize(rects[i].w, rects[i].h)); if(!EpocSdlEnv::AddUpdateRect(Private->iSwSurface, rect, target)) return; //not succesful } EpocSdlEnv::UpdateSwSurface(); } SDL_PauseAudio(0); } else { SDL_PauseAudio(1); EpocSdlEnv::WaitDsaAvailable(); } } /* Note: If we are terminated, this could be called in the middle of another SDL video routine -- notably UpdateRects. */ void EPOC_VideoQuit(_THIS) { // delete Private->iFrame; // Private->iFrame = NULL; User::Free(Private->iSwSurface); Private->iSwSurface = NULL; EpocSdlEnv::FreeSurface(); } WMcursor *EPOC_CreateWMCursor(_THIS, Uint8* /*data*/, Uint8* /*mask*/, int /*w*/, int /*h*/, int /*hot_x*/, int /*hot_y*/) { return (WMcursor*) 1; //hii! prevents SDL to view a std cursor } void EPOC_FreeWMCursor(_THIS, WMcursor* /*cursor*/) { } int EPOC_ShowWMCursor(_THIS, WMcursor *cursor) { return true; }