src/video/epoc/SDL_epocvideo.cpp
changeset 2126 9c9c49b18693
parent 2125 fab12febc0f9
child 2127 3bcc26b74e42
     1.1 --- a/src/video/epoc/SDL_epocvideo.cpp	Fri Jun 15 12:27:43 2007 +0000
     1.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.3 @@ -1,697 +0,0 @@
     1.4 -/*
     1.5 -    SDL - Simple DirectMedia Layer
     1.6 -    Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002  Sam Lantinga
     1.7 -
     1.8 -    This library is free software; you can redistribute it and/or
     1.9 -    modify it under the terms of the GNU Library General Public
    1.10 -    License as published by the Free Software Foundation; either
    1.11 -    version 2 of the License, or (at your option) any later version.
    1.12 -
    1.13 -    This library is distributed in the hope that it will be useful,
    1.14 -    but WITHOUT ANY WARRANTY; without even the implied warranty of
    1.15 -    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    1.16 -    Library General Public License for more details.
    1.17 -
    1.18 -    You should have received a copy of the GNU Library General Public
    1.19 -    License along with this library; if not, write to the Free
    1.20 -    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    1.21 -
    1.22 -    Sam Lantinga
    1.23 -    slouken@libsdl.org
    1.24 -*/
    1.25 -#include "SDL_config.h"
    1.26 -
    1.27 -/*
    1.28 -    SDL_epocvideo.cpp
    1.29 -    Epoc based SDL video driver implementation
    1.30 -
    1.31 -    Epoc version by Hannu Viitala (hannu.j.viitala@mbnet.fi)
    1.32 -*/
    1.33 -
    1.34 -extern "C" {
    1.35 -#include "SDL_timer.h"
    1.36 -#include "SDL_video.h"
    1.37 -#undef NULL
    1.38 -#include "../SDL_pixels_c.h"
    1.39 -};
    1.40 -
    1.41 -#include "SDL_epocvideo.h"
    1.42 -#include "SDL_epocevents_c.h"
    1.43 -
    1.44 -#include <hal.h>
    1.45 -#include <coedef.h>
    1.46 -
    1.47 -/* For debugging */
    1.48 -
    1.49 -void RDebug_Print_b(char* error_str, void* param)
    1.50 -    {
    1.51 -    TBuf8<128> error8((TUint8*)error_str);
    1.52 -    TBuf<128> error;
    1.53 -    error.Copy(error8);
    1.54 -    if (param) //!! Do not work if the parameter is really 0!!
    1.55 -        RDebug::Print(error, param);
    1.56 -    else 
    1.57 -        RDebug::Print(error);
    1.58 -    }
    1.59 -
    1.60 -extern "C" void RDebug_Print(char* error_str, void* param)
    1.61 -    {
    1.62 -    RDebug_Print_b(error_str, param);
    1.63 -    }
    1.64 -
    1.65 -
    1.66 -int Debug_AvailMem2()
    1.67 -    {
    1.68 -    //User::CompressAllHeaps();
    1.69 -    TMemoryInfoV1Buf membuf; 
    1.70 -    User::LeaveIfError(UserHal::MemoryInfo(membuf));
    1.71 -    TMemoryInfoV1 minfo = membuf();
    1.72 -	return(minfo.iFreeRamInBytes);
    1.73 -    }
    1.74 -
    1.75 -extern "C" int Debug_AvailMem()
    1.76 -    {
    1.77 -    return(Debug_AvailMem2());
    1.78 -    }
    1.79 -
    1.80 -
    1.81 -extern "C" {
    1.82 -
    1.83 -/* Initialization/Query functions */
    1.84 -
    1.85 -static int EPOC_VideoInit(_THIS, SDL_PixelFormat *vformat);
    1.86 -static SDL_Rect **EPOC_ListModes(_THIS, SDL_PixelFormat *format, Uint32 flags);
    1.87 -static SDL_Surface *EPOC_SetVideoMode(_THIS, SDL_Surface *current, int width, int height, int bpp, Uint32 flags);
    1.88 -static int EPOC_SetColors(_THIS, int firstcolor, int ncolors,
    1.89 -			  SDL_Color *colors);
    1.90 -static void EPOC_VideoQuit(_THIS);
    1.91 -
    1.92 -/* Hardware surface functions */
    1.93 -
    1.94 -static int EPOC_AllocHWSurface(_THIS, SDL_Surface *surface);
    1.95 -static int EPOC_LockHWSurface(_THIS, SDL_Surface *surface);
    1.96 -static int EPOC_FlipHWSurface(_THIS, SDL_Surface *surface);
    1.97 -static void EPOC_UnlockHWSurface(_THIS, SDL_Surface *surface);
    1.98 -static void EPOC_FreeHWSurface(_THIS, SDL_Surface *surface);
    1.99 -static void EPOC_DirectUpdate(_THIS, int numrects, SDL_Rect *rects);
   1.100 -
   1.101 -static int EPOC_Available(void);
   1.102 -static SDL_VideoDevice *EPOC_CreateDevice(int devindex);
   1.103 -
   1.104 -/* Mouse functions */
   1.105 -
   1.106 -static WMcursor *EPOC_CreateWMCursor(_THIS, Uint8 *data, Uint8 *mask, int w, int h, int hot_x, int hot_y);
   1.107 -static void EPOC_FreeWMCursor(_THIS, WMcursor *cursor);
   1.108 -static int EPOC_ShowWMCursor(_THIS, WMcursor *cursor);
   1.109 -
   1.110 -
   1.111 -
   1.112 -/* !! Table for fast conversion from 8 bit to 12 bit */
   1.113 -static TUint16 EPOC_HWPalette_256_to_4k[256];
   1.114 -
   1.115 -VideoBootStrap EPOC_bootstrap = {
   1.116 -	"epoc", "EPOC system",
   1.117 -    EPOC_Available, EPOC_CreateDevice
   1.118 -};
   1.119 -
   1.120 -const TUint32 WindowClientHandle = 9210; //!!
   1.121 -
   1.122 -/* Epoc video driver bootstrap functions */
   1.123 -
   1.124 -static int EPOC_Available(void)
   1.125 -{
   1.126 -    return 1; /* Always available */
   1.127 -}
   1.128 -
   1.129 -static void EPOC_DeleteDevice(SDL_VideoDevice *device)
   1.130 -{
   1.131 -	SDL_free(device->hidden);
   1.132 -	SDL_free(device);
   1.133 -}
   1.134 -
   1.135 -static SDL_VideoDevice *EPOC_CreateDevice(int devindex)
   1.136 -{
   1.137 -	SDL_VideoDevice *device;
   1.138 -
   1.139 -	/* Allocate all variables that we free on delete */
   1.140 -	device = (SDL_VideoDevice *)SDL_malloc(sizeof(SDL_VideoDevice));
   1.141 -	if ( device ) {
   1.142 -		SDL_memset(device, 0, (sizeof *device));
   1.143 -		device->hidden = (struct SDL_PrivateVideoData *)
   1.144 -				SDL_malloc((sizeof *device->hidden));
   1.145 -	}
   1.146 -	if ( (device == NULL) || (device->hidden == NULL) ) {
   1.147 -		SDL_OutOfMemory();
   1.148 -		if ( device ) {
   1.149 -			SDL_free(device);
   1.150 -		}
   1.151 -		return(0);
   1.152 -	}
   1.153 -	SDL_memset(device->hidden, 0, (sizeof *device->hidden));
   1.154 -
   1.155 -	/* Set the function pointers */
   1.156 -	device->VideoInit = EPOC_VideoInit;
   1.157 -	device->ListModes = EPOC_ListModes;
   1.158 -	device->SetVideoMode = EPOC_SetVideoMode;
   1.159 -	device->SetColors = EPOC_SetColors;
   1.160 -	device->UpdateRects = NULL;
   1.161 -	device->VideoQuit = EPOC_VideoQuit;
   1.162 -	device->AllocHWSurface = EPOC_AllocHWSurface;
   1.163 -	device->CheckHWBlit = NULL;
   1.164 -	device->FillHWRect = NULL;
   1.165 -	device->SetHWColorKey = NULL;
   1.166 -	device->SetHWAlpha = NULL;
   1.167 -	device->LockHWSurface = EPOC_LockHWSurface;
   1.168 -	device->UnlockHWSurface = EPOC_UnlockHWSurface;
   1.169 -	device->FlipHWSurface = EPOC_FlipHWSurface;
   1.170 -	device->FreeHWSurface = EPOC_FreeHWSurface;
   1.171 -	device->SetIcon = NULL;
   1.172 -	device->SetCaption = NULL;
   1.173 -	device->GetWMInfo = NULL;
   1.174 -	device->FreeWMCursor = EPOC_FreeWMCursor;
   1.175 -	device->CreateWMCursor = EPOC_CreateWMCursor;
   1.176 -	device->ShowWMCursor = EPOC_ShowWMCursor;
   1.177 -	device->WarpWMCursor = NULL;
   1.178 -	device->InitOSKeymap = EPOC_InitOSKeymap;
   1.179 -	device->PumpEvents = EPOC_PumpEvents;
   1.180 -	device->free = EPOC_DeleteDevice;
   1.181 -
   1.182 -	return device;
   1.183 -}
   1.184 -
   1.185 -
   1.186 -int GetBpp(TDisplayMode displaymode)
   1.187 -{
   1.188 -    TInt numColors = TDisplayModeUtils::NumDisplayModeColors(displaymode);
   1.189 -    TInt bitsPerPixel = 1;
   1.190 -    for (TInt32 i = 2; i < numColors; i <<= 1, bitsPerPixel++);
   1.191 -    return bitsPerPixel;    
   1.192 -}
   1.193 -
   1.194 -void ConstructWindowL(_THIS)
   1.195 -{
   1.196 -	TInt	error;
   1.197 -
   1.198 -	error = Private->EPOC_WsSession.Connect();
   1.199 -	User::LeaveIfError(error);
   1.200 -	Private->EPOC_WsScreen=new(ELeave) CWsScreenDevice(Private->EPOC_WsSession);
   1.201 -	User::LeaveIfError(Private->EPOC_WsScreen->Construct());
   1.202 -	User::LeaveIfError(Private->EPOC_WsScreen->CreateContext(Private->EPOC_WindowGc));
   1.203 -
   1.204 -	Private->EPOC_WsWindowGroup=RWindowGroup(Private->EPOC_WsSession);
   1.205 -	User::LeaveIfError(Private->EPOC_WsWindowGroup.Construct(WindowClientHandle));
   1.206 -	Private->EPOC_WsWindowGroup.SetOrdinalPosition(0);
   1.207 -
   1.208 -    //!!
   1.209 -    TBuf<32> winGroupName;
   1.210 -    winGroupName.Append(0);
   1.211 -    winGroupName.Append(0);
   1.212 -    winGroupName.Append(0);// uid
   1.213 -    winGroupName.Append(0);
   1.214 -    winGroupName.Append(_L("SDL")); // caption
   1.215 -    winGroupName.Append(0);
   1.216 -    winGroupName.Append(0); //doc name
   1.217 -	Private->EPOC_WsWindowGroup.SetName(winGroupName); //!!
   1.218 -
   1.219 -	Private->EPOC_WsWindow=RWindow(Private->EPOC_WsSession);
   1.220 -	User::LeaveIfError(Private->EPOC_WsWindow.Construct(Private->EPOC_WsWindowGroup,WindowClientHandle));
   1.221 -	Private->EPOC_WsWindow.SetBackgroundColor(KRgbWhite);
   1.222 -    Private->EPOC_WsWindow.Activate();
   1.223 -	Private->EPOC_WsWindow.SetSize(Private->EPOC_WsScreen->SizeInPixels()); 
   1.224 -	Private->EPOC_WsWindow.SetVisible(ETrue);
   1.225 -
   1.226 -    Private->EPOC_WsWindowGroupID = Private->EPOC_WsWindowGroup.Identifier();
   1.227 -    Private->EPOC_IsWindowFocused = EFalse;
   1.228 -}
   1.229 -
   1.230 -
   1.231 -int EPOC_VideoInit(_THIS, SDL_PixelFormat *vformat)
   1.232 -{
   1.233 -    // !!TODO:handle leave functions!
   1.234 -
   1.235 -    int i;
   1.236 -
   1.237 -	/* Initialize all variables that we clean on shutdown */   
   1.238 -
   1.239 -	for ( i=0; i<SDL_NUMMODES; ++i ) {
   1.240 -		Private->SDL_modelist[i] = (SDL_Rect *)SDL_malloc(sizeof(SDL_Rect));
   1.241 -		Private->SDL_modelist[i]->x = Private->SDL_modelist[i]->y = 0;
   1.242 -	}
   1.243 -	/* Modes sorted largest to smallest !!TODO:sorting order??*/
   1.244 -	Private->SDL_modelist[0]->w = 640; Private->SDL_modelist[0]->h = 200; 
   1.245 -	Private->SDL_modelist[1]->w = 320; Private->SDL_modelist[1]->h = 200;
   1.246 -	Private->SDL_modelist[2]->w = 640; Private->SDL_modelist[2]->h = 400; 
   1.247 -	Private->SDL_modelist[3]->w = 640; Private->SDL_modelist[3]->h = 480;
   1.248 -	Private->SDL_modelist[4] = NULL;
   1.249 -
   1.250 -    /* Construct Epoc window */
   1.251 -
   1.252 -    ConstructWindowL(_this);
   1.253 -
   1.254 -    /* Initialise Epoc frame buffer */
   1.255 -
   1.256 -    TDisplayMode displayMode = Private->EPOC_WsScreen->DisplayMode();
   1.257 -
   1.258 -    #ifndef __WINS__
   1.259 -
   1.260 -    TScreenInfoV01 screenInfo;
   1.261 -	TPckg<TScreenInfoV01> sInfo(screenInfo);
   1.262 -	UserSvr::ScreenInfo(sInfo);
   1.263 -
   1.264 -	Private->EPOC_ScreenSize		= screenInfo.iScreenSize; 
   1.265 -	Private->EPOC_DisplayMode		= displayMode;
   1.266 -    Private->EPOC_HasFrameBuffer	= screenInfo.iScreenAddressValid;
   1.267 -	Private->EPOC_FrameBuffer		= Private->EPOC_HasFrameBuffer ? (TUint8*) screenInfo.iScreenAddress : NULL;
   1.268 -	Private->EPOC_BytesPerPixel	    = ((GetBpp(displayMode)-1) / 8) + 1;
   1.269 -	Private->EPOC_BytesPerScanLine	= screenInfo.iScreenSize.iWidth * Private->EPOC_BytesPerPixel;
   1.270 -
   1.271 -    /* It seems that in SA1100 machines for 8bpp displays there is a 512 palette table at the 
   1.272 -     * beginning of the frame buffer. E.g. Series 7 and Netbook.
   1.273 -     * In 12 bpp machines the table has 16 entries.
   1.274 -	 */
   1.275 -	if (Private->EPOC_HasFrameBuffer && GetBpp(displayMode) == 8)
   1.276 -		Private->EPOC_FrameBuffer += 512;
   1.277 -	if (Private->EPOC_HasFrameBuffer && GetBpp(displayMode) == 12)
   1.278 -		Private->EPOC_FrameBuffer += 16 * 2;
   1.279 -
   1.280 -    #else /* defined __WINS__ */
   1.281 -    
   1.282 -    /* Create bitmap, device and context for screen drawing */
   1.283 -    Private->EPOC_ScreenSize        = Private->EPOC_WsScreen->SizeInPixels();
   1.284 -
   1.285 -	Private->EPOC_Bitmap = new (ELeave) CWsBitmap(Private->EPOC_WsSession);
   1.286 -	Private->EPOC_Bitmap->Create(Private->EPOC_ScreenSize, displayMode);
   1.287 -
   1.288 -	Private->EPOC_DisplayMode	    = displayMode;
   1.289 -    Private->EPOC_HasFrameBuffer    = ETrue;
   1.290 -    Private->EPOC_FrameBuffer       = NULL; /* Private->EPOC_Bitmap->DataAddress() can change any time */
   1.291 -	Private->EPOC_BytesPerPixel	    = ((GetBpp(displayMode)-1) / 8) + 1;
   1.292 -	Private->EPOC_BytesPerScanLine  = Private->EPOC_WsScreen->SizeInPixels().iWidth * Private->EPOC_BytesPerPixel;
   1.293 -
   1.294 -    #endif /* __WINS__ */
   1.295 -
   1.296 -    _this->info.current_w = Private->EPOC_ScreenSize.iWidth;
   1.297 -    _this->info.current_h = Private->EPOC_ScreenSize.iHeight;
   1.298 -
   1.299 -    /* The "best" video format should be returned to caller. */
   1.300 -
   1.301 -    vformat->BitsPerPixel       = /*!!GetBpp(displayMode) */ 8;
   1.302 -    vformat->BytesPerPixel      = /*!!Private->EPOC_BytesPerPixel*/ 1;
   1.303 -
   1.304 -    /* Activate events for me */
   1.305 -
   1.306 -	Private->EPOC_WsEventStatus = KRequestPending;
   1.307 -	Private->EPOC_WsSession.EventReady(&Private->EPOC_WsEventStatus);
   1.308 -	Private->EPOC_RedrawEventStatus = KRequestPending;
   1.309 -	Private->EPOC_WsSession.RedrawReady(&Private->EPOC_RedrawEventStatus);
   1.310 -    Private->EPOC_WsWindow.PointerFilter(EPointerFilterDrag, 0); 
   1.311 -
   1.312 -    Private->EPOC_ScreenOffset = 0;
   1.313 -
   1.314 -    //!! TODO: error handling
   1.315 -    //if (ret != KErrNone)
   1.316 -    //    return(-1);
   1.317 -    //else
   1.318 -	    return(0);
   1.319 -}
   1.320 -
   1.321 -
   1.322 -SDL_Rect **EPOC_ListModes(_THIS, SDL_PixelFormat *format, Uint32 flags)
   1.323 -{
   1.324 -    if (format->BitsPerPixel == 12 || format->BitsPerPixel == 8)
   1.325 -        return Private->SDL_modelist;
   1.326 -    return NULL;
   1.327 -}
   1.328 -
   1.329 -int EPOC_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color *colors)
   1.330 -{
   1.331 -    for(int i = firstcolor; i < ncolors; i++) {
   1.332 -	    // 4k value: 000rgb
   1.333 -	    TUint16 color4K = 0;
   1.334 -        color4K |= (colors[i].r & 0x0000f0) << 4; 
   1.335 -	    color4K |= (colors[i].g & 0x0000f0);      
   1.336 -	    color4K |= (colors[i].b & 0x0000f0) >> 4;
   1.337 -        EPOC_HWPalette_256_to_4k[i] = color4K;
   1.338 -    }
   1.339 -	return(0);
   1.340 -}
   1.341 -
   1.342 -
   1.343 -SDL_Surface *EPOC_SetVideoMode(_THIS, SDL_Surface *current,
   1.344 -				int width, int height, int bpp, Uint32 flags)
   1.345 -{
   1.346 -    /* Check parameters */
   1.347 -    if (!((width == 640 && height == 200 && bpp == 12) ||
   1.348 -          (width == 640 && height == 400 && bpp == 12) || 
   1.349 -          (width == 640 && height == 480 && bpp == 12) || 
   1.350 -          (width == 320 && height == 200 && bpp == 12) || 
   1.351 -          (width == 640 && height == 200 && bpp == 8) ||
   1.352 -          (width == 640 && height == 400 && bpp == 8) || 
   1.353 -          (width == 640 && height == 480 && bpp == 8) || 
   1.354 -          (width == 320 && height == 200 && bpp == 8))) {
   1.355 -		SDL_SetError("Requested video mode is not supported");
   1.356 -        return NULL;
   1.357 -    }
   1.358 -
   1.359 -    if (current && current->pixels) {
   1.360 -        SDL_free(current->pixels);
   1.361 -        current->pixels = NULL;
   1.362 -    }
   1.363 -	if ( ! SDL_ReallocFormat(current, bpp, 0, 0, 0, 0) ) {
   1.364 -		return(NULL);
   1.365 -	}
   1.366 -
   1.367 -    /* Set up the new mode framebuffer */
   1.368 -    if (bpp == 8) 
   1.369 -	    current->flags = (SDL_FULLSCREEN|SDL_SWSURFACE|SDL_PREALLOC|SDL_HWPALETTE); 
   1.370 -    else // 12 bpp
   1.371 -	    current->flags = (SDL_FULLSCREEN|SDL_SWSURFACE|SDL_PREALLOC); 
   1.372 -	current->w = width;
   1.373 -	current->h = height;
   1.374 -    int numBytesPerPixel = ((bpp-1)>>3) + 1;   
   1.375 -	current->pitch = numBytesPerPixel * width; // Number of bytes in scanline 
   1.376 -	current->pixels = SDL_malloc(width * height * numBytesPerPixel);
   1.377 -	SDL_memset(current->pixels, 0, width * height * numBytesPerPixel);
   1.378 -
   1.379 -	/* Set the blit function */
   1.380 -	_this->UpdateRects = EPOC_DirectUpdate;
   1.381 -
   1.382 -    /* Must buffer height be shrinked to screen by 2 ? */
   1.383 -    if (current->h >= 400)
   1.384 -        Private->EPOC_ShrinkedHeight = ETrue;
   1.385 -
   1.386 -    /* Centralize game window on device screen  */
   1.387 -    Private->EPOC_ScreenOffset = (Private->EPOC_ScreenSize.iWidth - current->w) / 2;
   1.388 -
   1.389 -	/* We're done */
   1.390 -	return(current);
   1.391 -}
   1.392 -
   1.393 -void RedrawWindowL(_THIS)
   1.394 -{
   1.395 -    SDL_Rect fullScreen;
   1.396 -    fullScreen.x = 0;
   1.397 -    fullScreen.y = 0;
   1.398 -    fullScreen.w = _this->screen->w;
   1.399 -    fullScreen.h = _this->screen->h;
   1.400 -
   1.401 -#ifdef __WINS__
   1.402 -	    TBitmapUtil lock(Private->EPOC_Bitmap);	
   1.403 -        lock.Begin(TPoint(0,0)); // Lock bitmap heap
   1.404 -	    Private->EPOC_WindowGc->Activate(Private->EPOC_WsWindow);
   1.405 -#endif
   1.406 -
   1.407 -    if (fullScreen.w < Private->EPOC_ScreenSize.iWidth
   1.408 -        && fullScreen.w < Private->EPOC_ScreenSize.iWidth) {
   1.409 -        /* Draw blue stripes background */
   1.410 -#ifdef __WINS__
   1.411 -        TUint16* screenBuffer = (TUint16*)Private->EPOC_Bitmap->DataAddress();
   1.412 -#else
   1.413 -        TUint16* screenBuffer = (TUint16*)Private->EPOC_FrameBuffer;
   1.414 -#endif
   1.415 -        for (int y=0; y < Private->EPOC_ScreenSize.iHeight; y++) {
   1.416 -            for (int x=0; x < Private->EPOC_ScreenSize.iWidth; x++) {
   1.417 -                TUint16 color = ((x+y)>>1) & 0xf; /* Draw pattern */
   1.418 -                *screenBuffer++ = color;
   1.419 -            }
   1.420 -        }
   1.421 -    }
   1.422 -
   1.423 -
   1.424 -    /* Tell the system that something has been drawn */
   1.425 -	TRect  rect = TRect(Private->EPOC_WsWindow.Size());
   1.426 -  	Private->EPOC_WsWindow.Invalidate(rect);
   1.427 -
   1.428 -#ifdef __WINS__
   1.429 -	Private->EPOC_WsWindow.BeginRedraw(rect);
   1.430 -	Private->EPOC_WindowGc->BitBlt(TPoint(), Private->EPOC_Bitmap);
   1.431 -	Private->EPOC_WsWindow.EndRedraw();
   1.432 -	Private->EPOC_WindowGc->Deactivate();
   1.433 -    lock.End(); // Unlock bitmap heap
   1.434 -	Private->EPOC_WsSession.Flush();
   1.435 -#endif
   1.436 -
   1.437 -    /* Draw current buffer */
   1.438 -    EPOC_DirectUpdate(_this, 1, &fullScreen);
   1.439 -}
   1.440 -
   1.441 -
   1.442 -/* We don't actually allow hardware surfaces other than the main one */
   1.443 -static int EPOC_AllocHWSurface(_THIS, SDL_Surface *surface)
   1.444 -{
   1.445 -	return(-1);
   1.446 -}
   1.447 -static void EPOC_FreeHWSurface(_THIS, SDL_Surface *surface)
   1.448 -{
   1.449 -	return;
   1.450 -}
   1.451 -
   1.452 -static int EPOC_LockHWSurface(_THIS, SDL_Surface *surface)
   1.453 -{
   1.454 -	return(0);
   1.455 -}
   1.456 -static void EPOC_UnlockHWSurface(_THIS, SDL_Surface *surface)
   1.457 -{
   1.458 -	return;
   1.459 -}
   1.460 -
   1.461 -static int EPOC_FlipHWSurface(_THIS, SDL_Surface *surface)
   1.462 -{
   1.463 -	return(0);
   1.464 -}
   1.465 -
   1.466 -static void EPOC_DirectUpdate(_THIS, int numrects, SDL_Rect *rects)
   1.467 -{
   1.468 -    TInt focusWindowGroupId = Private->EPOC_WsSession.GetFocusWindowGroup();
   1.469 -    if (focusWindowGroupId != Private->EPOC_WsWindowGroupID) {
   1.470 -
   1.471 -        /* Force focus window to redraw again for cleaning away SDL screen graphics */
   1.472 -
   1.473 -  
   1.474 -        TInt pos = Private->EPOC_WsWindowGroup.OrdinalPosition();
   1.475 -        Private->EPOC_WsWindowGroup.SetOrdinalPosition(0, KMaxTInt);
   1.476 -       	TRect  rect = TRect(Private->EPOC_WsWindow.Size());
   1.477 -        Private->EPOC_WsWindow.Invalidate(rect);
   1.478 -        Private->EPOC_WsWindowGroup.SetOrdinalPosition(pos, ECoeWinPriorityNormal);
   1.479 -        
   1.480 -        /* If this is not the topmost window, wait here! Sleep for 1 second to give cpu to 
   1.481 -           multitasking and poll for being the topmost window.
   1.482 -        */
   1.483 -        while (Private->EPOC_WsSession.GetFocusWindowGroup() != Private->EPOC_WsWindowGroupID)
   1.484 -            SDL_Delay(1000);
   1.485 -
   1.486 -        RedrawWindowL(_this);  
   1.487 -    }
   1.488 -
   1.489 -	TInt i;
   1.490 -    TInt sourceNumBytesPerPixel = ((_this->screen->format->BitsPerPixel-1)>>3) + 1;   
   1.491 -    TInt targetNumBytesPerPixel = Private->EPOC_BytesPerPixel;   
   1.492 -    TInt fixedOffset = Private->EPOC_ScreenOffset;   
   1.493 -    TInt screenW = _this->screen->w;
   1.494 -    TInt screenH = _this->screen->h;
   1.495 -    TInt sourceScanlineLength = screenW;
   1.496 -    if (Private->EPOC_ShrinkedHeight) {  /* simulate 400 pixel height in 200 pixel screen */  
   1.497 -        sourceScanlineLength <<= 1; 
   1.498 -        screenH >>= 1;
   1.499 -    }
   1.500 -    TInt targetScanlineLength = Private->EPOC_ScreenSize.iWidth;
   1.501 -#ifdef __WINS__
   1.502 -	TBitmapUtil lock(Private->EPOC_Bitmap);	
   1.503 -    lock.Begin(TPoint(0,0)); // Lock bitmap heap
   1.504 -	Private->EPOC_WindowGc->Activate(Private->EPOC_WsWindow);
   1.505 -    TUint16* screenBuffer = (TUint16*)Private->EPOC_Bitmap->DataAddress();
   1.506 -#else
   1.507 -    TUint16* screenBuffer = (TUint16*)Private->EPOC_FrameBuffer;
   1.508 -#endif
   1.509 -
   1.510 -
   1.511 -	/* Render the rectangles in the list */
   1.512 -
   1.513 -	for ( i=0; i < numrects; ++i ) {
   1.514 -        SDL_Rect rect2;
   1.515 -        const SDL_Rect& currentRect = rects[i];
   1.516 -        rect2.x = currentRect.x;
   1.517 -        rect2.y = currentRect.y;
   1.518 -        rect2.w = currentRect.w;
   1.519 -        rect2.h = currentRect.h;
   1.520 -
   1.521 -        if (rect2.w <= 0 || rect2.h <= 0) /* sanity check */
   1.522 -            continue;
   1.523 -
   1.524 -        if (Private->EPOC_ShrinkedHeight) {  /* simulate 400 pixel height in 200 pixel screen */        
   1.525 -            rect2.y >>= 1;
   1.526 -            if (!(rect2.h >>= 1)) 
   1.527 -                rect2.h = 1; // always at least 1 pixel height!
   1.528 -        }
   1.529 -
   1.530 -        /* All variables are measured in pixels */
   1.531 -
   1.532 -        /* Check rects validity, i.e. upper and lower bounds */
   1.533 -        TInt maxX = Min(screenW - 1, rect2.x + rect2.w - 1);
   1.534 -        TInt maxY = Min(screenH - 1, rect2.y + rect2.h - 1);
   1.535 -        if (maxX < 0 || maxY < 0) /* sanity check */
   1.536 -            continue;
   1.537 -        maxY = Min(maxY, 199); 
   1.538 -
   1.539 -        TInt sourceRectWidth = maxX - rect2.x + 1;
   1.540 -        TInt sourceRectWidthInBytes = sourceRectWidth * sourceNumBytesPerPixel;
   1.541 -        TInt sourceRectHeight = maxY - rect2.y + 1;
   1.542 -        TInt sourceStartOffset = rect2.x + rect2.y * sourceScanlineLength;
   1.543 -        TInt targetStartOffset = fixedOffset + rect2.x + rect2.y * targetScanlineLength;   
   1.544 -        
   1.545 -        // !! Nokia9210 native mode: 12 bpp --> 12 bpp
   1.546 -        if (_this->screen->format->BitsPerPixel == 12) { 
   1.547 -	        TUint16* bitmapLine = (TUint16*)_this->screen->pixels + sourceStartOffset;
   1.548 -            TUint16* screenMemory = screenBuffer + targetStartOffset;
   1.549 -            for(TInt y = 0 ; y < sourceRectHeight ; y++) {
   1.550 -                __ASSERT_DEBUG(screenMemory < (screenBuffer 
   1.551 -                    + Private->EPOC_ScreenSize.iWidth * Private->EPOC_ScreenSize.iHeight), 
   1.552 -                    User::Panic(_L("SDL"), KErrCorrupt));
   1.553 -                __ASSERT_DEBUG(screenMemory >= screenBuffer, 
   1.554 -                    User::Panic(_L("SDL"), KErrCorrupt));
   1.555 -                __ASSERT_DEBUG(bitmapLine < ((TUint16*)_this->screen->pixels + 
   1.556 -                    + (_this->screen->w * _this->screen->h)), 
   1.557 -                    User::Panic(_L("SDL"), KErrCorrupt));
   1.558 -                __ASSERT_DEBUG(bitmapLine >=  (TUint16*)_this->screen->pixels, 
   1.559 -                    User::Panic(_L("SDL"), KErrCorrupt));
   1.560 -		        Mem::Copy(screenMemory, bitmapLine, sourceRectWidthInBytes);
   1.561 -		        bitmapLine += sourceScanlineLength;
   1.562 -		        screenMemory += targetScanlineLength;
   1.563 -            }
   1.564 -        }
   1.565 -        // !! 256 color paletted mode: 8 bpp  --> 12 bpp
   1.566 -        else { 
   1.567 -	        TUint8* bitmapLine = (TUint8*)_this->screen->pixels + sourceStartOffset;
   1.568 -            TUint16* screenMemory = screenBuffer + targetStartOffset;
   1.569 -            for(TInt y = 0 ; y < sourceRectHeight ; y++) {
   1.570 -                TUint8* bitmapPos = bitmapLine; /* 1 byte per pixel */
   1.571 -                TUint16* screenMemoryLinePos = screenMemory; /* 2 bytes per pixel */
   1.572 -                /* Convert each pixel from 256 palette to 4k color values */
   1.573 -                for(TInt x = 0 ; x < sourceRectWidth ; x++) {
   1.574 -                    __ASSERT_DEBUG(screenMemoryLinePos < (screenBuffer 
   1.575 -                        + (Private->EPOC_ScreenSize.iWidth * Private->EPOC_ScreenSize.iHeight)), 
   1.576 -                        User::Panic(_L("SDL"), KErrCorrupt));
   1.577 -                    __ASSERT_DEBUG(screenMemoryLinePos >= screenBuffer, 
   1.578 -                        User::Panic(_L("SDL"), KErrCorrupt));
   1.579 -                    __ASSERT_DEBUG(bitmapPos < ((TUint8*)_this->screen->pixels + 
   1.580 -                        + (_this->screen->w * _this->screen->h)), 
   1.581 -                        User::Panic(_L("SDL"), KErrCorrupt));
   1.582 -                    __ASSERT_DEBUG(bitmapPos >= (TUint8*)_this->screen->pixels, 
   1.583 -                        User::Panic(_L("SDL"), KErrCorrupt));
   1.584 -                    *screenMemoryLinePos = EPOC_HWPalette_256_to_4k[*bitmapPos];
   1.585 -                    bitmapPos++;
   1.586 -                    screenMemoryLinePos++;
   1.587 -                }
   1.588 -		        bitmapLine += sourceScanlineLength;
   1.589 -		        screenMemory += targetScanlineLength;
   1.590 -            }
   1.591 -	    }
   1.592 -
   1.593 -    }    
   1.594 -    
   1.595 -#ifdef __WINS__
   1.596 -
   1.597 -	TRect  rect = TRect(Private->EPOC_WsWindow.Size());
   1.598 -	Private->EPOC_WsWindow.Invalidate(rect);
   1.599 -	Private->EPOC_WsWindow.BeginRedraw(rect);
   1.600 -	Private->EPOC_WindowGc->BitBlt(TPoint(), Private->EPOC_Bitmap);
   1.601 -	Private->EPOC_WsWindow.EndRedraw();
   1.602 -	Private->EPOC_WindowGc->Deactivate();
   1.603 -    lock.End(); // Unlock bitmap heap
   1.604 -	Private->EPOC_WsSession.Flush();
   1.605 -
   1.606 -#endif
   1.607 -
   1.608 -    /* Update virtual cursor */
   1.609 -    //!!Private->EPOC_WsSession.SetPointerCursorPosition(Private->EPOC_WsSession.PointerCursorPosition());
   1.610 -
   1.611 -    return;
   1.612 -}
   1.613 -
   1.614 -
   1.615 -/* Note:  If we are terminated, this could be called in the middle of
   1.616 -   another SDL video routine -- notably UpdateRects.
   1.617 -*/
   1.618 -void EPOC_VideoQuit(_THIS)
   1.619 -{
   1.620 -	int i;
   1.621 -
   1.622 -	/* Free video mode lists */
   1.623 -	for ( i=0; i<SDL_NUMMODES; ++i ) {
   1.624 -		if ( Private->SDL_modelist[i] != NULL ) {
   1.625 -			SDL_free(Private->SDL_modelist[i]);
   1.626 -			Private->SDL_modelist[i] = NULL;
   1.627 -		}
   1.628 -	}
   1.629 -	
   1.630 -    if ( _this->screen && (_this->screen->flags & SDL_HWSURFACE) ) {
   1.631 -		/* Direct screen access, no memory buffer */
   1.632 -		_this->screen->pixels = NULL;
   1.633 -	}
   1.634 -
   1.635 -    if (_this->screen && _this->screen->pixels) {
   1.636 -        SDL_free(_this->screen->pixels);
   1.637 -        _this->screen->pixels = NULL;
   1.638 -    }
   1.639 -
   1.640 -    /* Free Epoc resources */
   1.641 -
   1.642 -    /* Disable events for me */
   1.643 -	if (Private->EPOC_WsEventStatus != KRequestPending)
   1.644 -		Private->EPOC_WsSession.EventReadyCancel();
   1.645 -	if (Private->EPOC_RedrawEventStatus != KRequestPending)
   1.646 -		Private->EPOC_WsSession.RedrawReadyCancel();
   1.647 -
   1.648 -    #ifdef __WINS__
   1.649 -	delete Private->EPOC_Bitmap;
   1.650 -	Private->EPOC_Bitmap = NULL;
   1.651 -    #endif
   1.652 -
   1.653 -	if (Private->EPOC_WsWindow.WsHandle())
   1.654 -		Private->EPOC_WsWindow.Close();
   1.655 -
   1.656 -	if (Private->EPOC_WsWindowGroup.WsHandle())
   1.657 -		Private->EPOC_WsWindowGroup.Close();
   1.658 -
   1.659 -	delete Private->EPOC_WindowGc;
   1.660 -	Private->EPOC_WindowGc = NULL;
   1.661 -
   1.662 -	delete Private->EPOC_WsScreen;
   1.663 -	Private->EPOC_WsScreen = NULL;
   1.664 -
   1.665 -	if (Private->EPOC_WsSession.WsHandle())
   1.666 -		Private->EPOC_WsSession.Close();
   1.667 -}
   1.668 -
   1.669 -
   1.670 -WMcursor *EPOC_CreateWMCursor(_THIS, Uint8 *data, Uint8 *mask, int w, int h, int hot_x, int hot_y)
   1.671 -{
   1.672 -	return (WMcursor *) 9210; // it's ok to return something unuseful but true
   1.673 -}
   1.674 -
   1.675 -void EPOC_FreeWMCursor(_THIS, WMcursor *cursor)
   1.676 -{
   1.677 -    /* Disable virtual cursor */
   1.678 -    HAL::Set(HAL::EMouseState, HAL::EMouseState_Invisible);
   1.679 -    Private->EPOC_WsSession.SetPointerCursorMode(EPointerCursorNone);
   1.680 -}
   1.681 -
   1.682 -int EPOC_ShowWMCursor(_THIS, WMcursor *cursor)
   1.683 -{
   1.684 -
   1.685 -    if (cursor ==  (WMcursor *)9210) {
   1.686 -        /* Enable virtual cursor */
   1.687 -	    HAL::Set(HAL::EMouseState, HAL::EMouseState_Visible);
   1.688 -	    Private->EPOC_WsSession.SetPointerCursorMode(EPointerCursorNormal);
   1.689 -    }
   1.690 -    else {
   1.691 -        /* Disable virtual cursor */
   1.692 -        HAL::Set(HAL::EMouseState, HAL::EMouseState_Invisible);
   1.693 -        Private->EPOC_WsSession.SetPointerCursorMode(EPointerCursorNone);
   1.694 -    }
   1.695 -
   1.696 -	return(1);
   1.697 -}
   1.698 -
   1.699 -}; // extern "C"
   1.700 -