2 SDL - Simple DirectMedia Layer
3 Copyright (C) 1997-2009 Sam Lantinga
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
15 You should have received a copy of the GNU Library General Public
16 License along with this library; if not, write to the Free
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 slouken@devolution.com
25 Epoc based SDL video driver implementation
27 Thanks to Peter van Sebille, the author of EMame. It is a great example of
28 low level graphics coding in Epoc.
30 Epoc version by Hannu Viitala (hannu.j.viitala@mbnet.fi)
31 Assembler routines by Kimmo Kinnunen
41 #include "SDL_error.h"
42 #include "SDL_timer.h"
43 #include "SDL_video.h"
45 #include "SDL_pixels_c.h"
49 #include "SDL_epocvideo.h"
50 #include "SDL_epocevents_c.h"
52 #include "sdl_epocruntime.h"
59 SDL_VideoDevice* _thisDevice;
62 _LIT(KLibName, "SDL");
66 //if old SOS, from 7.x this is public!
67 class CLockable : public CFbsBitmap
70 static CLockable* Lockable(CFbsBitmap* aBmp) {return static_cast<CLockable*>(aBmp);}
71 void Lock() {LockHeap();}
72 void Unlock() {UnlockHeap();}
74 #define LockHeap(x) CLockable::Lockable(x)->Lock()
75 #define UnlockHeap(x) CLockable::Lockable(x)->Unlock()
77 void RDebug_Print_b(char* error_str, void* param)
79 TBuf8<128> error8((TUint8*)error_str);
84 if (param) //!! Do not work if the parameter is really 0!!
85 RDebug::Print(error, param);
89 if (param) //!! Do not work if the parameter is really 0!!
90 RFileLogger::WriteFormat(KLibName, _L("SDL.txt"), EFileLoggingModeAppend, error, param);
92 RFileLogger::Write(KLibName, _L("SDL.txt"), EFileLoggingModeAppend, error);
97 extern "C" void RDebug_Print(char* error_str, void* param)
99 RDebug_Print_b(error_str, param);
103 int Debug_AvailMem2()
105 //User::CompressAllHeaps();
106 TMemoryInfoV1Buf membuf;
107 User::LeaveIfError(UserHal::MemoryInfo(membuf));
108 TMemoryInfoV1 minfo = membuf();
109 return(minfo.iFreeRamInBytes);
112 extern "C" int Debug_AvailMem()
114 return(Debug_AvailMem2());
120 /* Initialization/Query functions */
122 static int EPOC_VideoInit(_THIS, SDL_PixelFormat *vformat);
123 static SDL_Rect **EPOC_ListModes(_THIS, SDL_PixelFormat *format, Uint32 flags);
124 static SDL_Surface *EPOC_SetVideoMode(_THIS, SDL_Surface *current, int width, int height, int bpp, Uint32 flags);
125 static int EPOC_SetColors(_THIS, int firstcolor, int ncolors,
127 static void EPOC_VideoQuit(_THIS);
129 /* Hardware surface functions */
131 static int EPOC_AllocHWSurface(_THIS, SDL_Surface *surface);
132 static int EPOC_LockHWSurface(_THIS, SDL_Surface *surface);
133 static int EPOC_FlipHWSurface(_THIS, SDL_Surface *surface);
134 static void EPOC_UnlockHWSurface(_THIS, SDL_Surface *surface);
135 static void EPOC_FreeHWSurface(_THIS, SDL_Surface *surface);
136 static void EPOC_DirectUpdate(_THIS, int numrects, SDL_Rect *rects);
138 static int EPOC_Available(void);
139 static SDL_VideoDevice *EPOC_CreateDevice(int devindex);
141 void DrawBackground(_THIS);
142 void DirectDraw(_THIS, int numrects, SDL_Rect *rects, TUint16* screenBuffer);
143 void DirectDrawRotated(_THIS, int numrects, SDL_Rect *rects, TUint16* screenBuffer);
145 /* Mouse functions */
147 static WMcursor *EPOC_CreateWMCursor(_THIS, Uint8 *data, Uint8 *mask, int w, int h, int hot_x, int hot_y);
148 static void EPOC_FreeWMCursor(_THIS, WMcursor *cursor);
149 static int EPOC_ShowWMCursor(_THIS, WMcursor *cursor);
153 /* !!For 12 bit screen HW. Table for fast conversion from 8 bit to 12 bit */
154 // TUint16 is enough, but using TUint32 so we can use better instruction selection on ARMI
155 static TUint32 EPOC_HWPalette_256_to_Screen[256];
157 VideoBootStrap EPOC_bootstrap = {
158 "epoc", "EPOC system",
159 EPOC_Available, EPOC_CreateDevice
162 const TUint32 WindowClientHandle = 9210; //!! const
164 /* Epoc video driver bootstrap functions */
166 static int EPOC_Available(void)
168 return 1; /* Always available */
171 static void EPOC_DeleteDevice(SDL_VideoDevice *device)
173 free(device->hidden);
177 static SDL_VideoDevice *EPOC_CreateDevice(int /*devindex*/)
179 SDL_VideoDevice *device;
181 SDL_TRACE("SDL:EPOC_CreateDevice");
183 /* Allocate all variables that we free on delete */
184 device = (SDL_VideoDevice *)malloc(sizeof(SDL_VideoDevice));
186 memset(device, 0, (sizeof *device));
187 device->hidden = (struct SDL_PrivateVideoData *)
188 malloc((sizeof *device->hidden));
190 if ( (device == NULL) || (device->hidden == NULL) ) {
197 memset(device->hidden, 0, (sizeof *device->hidden));
199 /* Set the function pointers */
200 device->VideoInit = EPOC_VideoInit;
201 device->ListModes = EPOC_ListModes;
202 device->SetVideoMode = EPOC_SetVideoMode;
203 device->SetColors = EPOC_SetColors;
204 device->UpdateRects = NULL;
205 device->VideoQuit = EPOC_VideoQuit;
206 device->AllocHWSurface = EPOC_AllocHWSurface;
207 device->CheckHWBlit = NULL;
208 device->FillHWRect = NULL;
209 device->SetHWColorKey = NULL;
210 device->SetHWAlpha = NULL;
211 device->LockHWSurface = EPOC_LockHWSurface;
212 device->UnlockHWSurface = EPOC_UnlockHWSurface;
213 device->FlipHWSurface = EPOC_FlipHWSurface;
214 device->FreeHWSurface = EPOC_FreeHWSurface;
215 device->SetIcon = NULL;
216 device->SetCaption = NULL;
217 device->GetWMInfo = NULL;
218 device->FreeWMCursor = EPOC_FreeWMCursor;
219 device->CreateWMCursor = EPOC_CreateWMCursor;
220 device->ShowWMCursor = EPOC_ShowWMCursor;
221 device->WarpWMCursor = NULL;
222 device->InitOSKeymap = EPOC_InitOSKeymap;
223 device->PumpEvents = EPOC_PumpEvents;
224 device->free = EPOC_DeleteDevice;
230 int GetBpp(TDisplayMode displaymode)
232 /*TInt numColors = TDisplayModeUtils::NumDisplayModeColors(displaymode);
233 TInt bitsPerPixel = 1;
234 for (TInt32 i = 2; i < numColors; i <<= 1, bitsPerPixel++);
235 return bitsPerPixel;*/
236 return TDisplayModeUtils::NumDisplayModeBitsPerPixel(displaymode);
240 void DisableKeyBlocking(_THIS)
242 // Disable key blocking
244 event.Set((TRawEvent::TType)/*EDisableKeyBlock*/51); // !!EDisableKeyBlock not found in epoc32\include!
245 Private->EPOC_WsSession.SimulateRawEvent(event);
248 void ConstructWindowL(_THIS)
252 SDL_TRACE("SDL:ConstructWindowL");
253 error = Private->EPOC_WsSession.Connect();
254 User::LeaveIfError(error);
255 Private->EPOC_WsScreen=new(ELeave) CWsScreenDevice(Private->EPOC_WsSession);
256 User::LeaveIfError(Private->EPOC_WsScreen->Construct());
257 User::LeaveIfError(Private->EPOC_WsScreen->CreateContext(Private->EPOC_WindowGc));
259 Private->EPOC_WsWindowGroup=RWindowGroup(Private->EPOC_WsSession);
260 User::LeaveIfError(Private->EPOC_WsWindowGroup.Construct(WindowClientHandle));
261 Private->EPOC_WsWindowGroup.SetOrdinalPosition(0);
263 // Set window group name (the same as process name)) !!Gives always "EPOC" in WINS
264 RProcess thisProcess;
266 exeName.Set(thisProcess.FileName(), NULL, NULL);
267 TBuf<32> winGroupName;
268 winGroupName.Append(0);
269 winGroupName.Append(0);
270 winGroupName.Append(0);// uid
271 winGroupName.Append(0);
272 winGroupName.Append(exeName.Name()); // caption
273 winGroupName.Append(0);
274 winGroupName.Append(0); //doc name
275 Private->EPOC_WsWindowGroup.SetName(winGroupName);
277 Private->EPOC_WsWindow=RWindow(Private->EPOC_WsSession);
279 // User::LeaveIfError(Private->EPOC_WsWindow.Construct(Private->EPOC_WsWindowGroup,WindowClientHandle ));
280 // but SOS 7.0s debug does not accept same window handle twice
281 User::LeaveIfError(Private->EPOC_WsWindow.Construct(Private->EPOC_WsWindowGroup,WindowClientHandle - 1));
282 Private->EPOC_WsWindow.SetBackgroundColor(KRgbWhite);
283 Private->EPOC_WsWindow.Activate();
284 Private->EPOC_WsWindow.SetSize(Private->EPOC_WsScreen->SizeInPixels());
285 Private->EPOC_WsWindow.SetVisible(ETrue);
287 Private->EPOC_WsWindowGroupID = Private->EPOC_WsWindowGroup.Identifier();
288 Private->EPOC_IsWindowFocused = EFalse;
290 DisableKeyBlocking(_this); //disable key blocking
293 int EPOC_VideoInit(_THIS, SDL_PixelFormat *vformat)
295 // !!TODO:handle leave functions!
299 SDL_TRACE("SDL:EPOC_VideoInit");
301 /* Initialize all variables that we clean on shutdown */
303 for ( i=0; i<SDL_NUMMODES; ++i ) {
304 Private->SDL_modelist[i] = (SDL_Rect *)malloc(sizeof(SDL_Rect));
305 Private->SDL_modelist[i]->x = Private->SDL_modelist[i]->y = 0;
308 /* Modes sorted largest to smallest */
309 Private->SDL_modelist[0]->w = 800; Private->SDL_modelist[0]->h = 250;
310 Private->SDL_modelist[1]->w = 640; Private->SDL_modelist[1]->h = 480;
311 Private->SDL_modelist[2]->w = 480; Private->SDL_modelist[2]->h = 600;
312 Private->SDL_modelist[3]->w = 640; Private->SDL_modelist[3]->h = 400;
313 Private->SDL_modelist[4]->w = 352; Private->SDL_modelist[4]->h = 416;
314 Private->SDL_modelist[5]->w = 416; Private->SDL_modelist[5]->h = 352;
315 Private->SDL_modelist[6]->w = 416; Private->SDL_modelist[6]->h = 312;
316 Private->SDL_modelist[7]->w = 352; Private->SDL_modelist[7]->h = 264;
317 Private->SDL_modelist[8]->w = 800; Private->SDL_modelist[8]->h = 240; //for doom all these..
318 Private->SDL_modelist[9]->w = 640; Private->SDL_modelist[9]->h = 240;
319 Private->SDL_modelist[10]->w = 480; Private->SDL_modelist[10]->h = 240;
320 Private->SDL_modelist[11]->w = 640; Private->SDL_modelist[11]->h = 240;
321 Private->SDL_modelist[12]->w = 352; Private->SDL_modelist[12]->h = 240;
322 Private->SDL_modelist[13]->w = 416; Private->SDL_modelist[13]->h = 240;
323 Private->SDL_modelist[14]->w = 416; Private->SDL_modelist[14]->h = 240;
324 Private->SDL_modelist[15]->w = 352; Private->SDL_modelist[15]->h = 240;
325 Private->SDL_modelist[16]->w = 640; Private->SDL_modelist[16]->h = 200;
326 Private->SDL_modelist[17]->w = 320; Private->SDL_modelist[17]->h = 240; //...for doom, currently engine renders no-higher windows :-(, propably should get fixed
327 Private->SDL_modelist[18]->w = 320; Private->SDL_modelist[18]->h = 200;
328 Private->SDL_modelist[19]->w = 256; Private->SDL_modelist[19]->h = 192;
329 Private->SDL_modelist[20]->w = 176; Private->SDL_modelist[20]->h = 208;
330 Private->SDL_modelist[21]->w = 208; Private->SDL_modelist[21]->h = 176; // Rotated
331 Private->SDL_modelist[22]->w = 160; Private->SDL_modelist[22]->h = 144;
333 Private->SDL_modelist[23]->w = 640; Private->SDL_modelist[2]->h = 200; //s80 some new modes
334 Private->SDL_modelist[24]->w = 640; Private->SDL_modelist[2]->h = 320; //s90 modes are added
335 Private->SDL_modelist[25]->w = 640; Private->SDL_modelist[2]->h = 240; //here
336 Private->SDL_modelist[26]->w = 640; Private->SDL_modelist[4]->h = 200; //now
338 Private->SDL_modelist[27] = NULL;
340 /* Construct Epoc window */
342 ConstructWindowL(_this);
344 /* Initialise Epoc frame buffer */
346 TDisplayMode displayMode = Private->EPOC_WsScreen->DisplayMode();
348 #if !defined(__WINS__) && !defined(TEST_BM_DRAW)
350 TScreenInfoV01 screenInfo;
351 TPckg<TScreenInfoV01> sInfo(screenInfo);
352 UserSvr::ScreenInfo(sInfo);
354 Private->EPOC_ScreenSize = screenInfo.iScreenSize;
355 Private->EPOC_DisplayMode = displayMode;
356 Private->EPOC_HasFrameBuffer = screenInfo.iScreenAddressValid;
357 Private->EPOC_FrameBuffer = Private->EPOC_HasFrameBuffer ? (TUint8*) screenInfo.iScreenAddress : NULL;
358 Private->EPOC_BytesPerPixel = ((GetBpp(displayMode)-1) / 8) + 1;
360 Private->EPOC_BytesPerScanLine = screenInfo.iScreenSize.iWidth * Private->EPOC_BytesPerPixel;
361 Private->EPOC_BytesPerScreen = Private->EPOC_BytesPerScanLine * Private->EPOC_ScreenSize.iHeight;
363 SDL_TRACE1("Screen width %d", screenInfo.iScreenSize.iWidth);
364 SDL_TRACE1("Screen height %d", screenInfo.iScreenSize.iHeight);
365 SDL_TRACE1("Screen dmode %d", displayMode);
366 SDL_TRACE1("Screen valid %d", screenInfo.iScreenAddressValid);
368 SDL_TRACE1("bpp %d", Private->EPOC_BytesPerPixel);
369 SDL_TRACE1("bpsl %d", Private->EPOC_BytesPerScanLine);
370 SDL_TRACE1("bps %d", Private->EPOC_BytesPerScreen);
373 /* It seems that in SA1100 machines for 8bpp displays there is a 512 palette table at the
374 * beginning of the frame buffer. E.g. Series 7 and Netbook.
375 * In 12 bpp machines the table has 16 entries.
377 if (Private->EPOC_HasFrameBuffer && GetBpp(displayMode) == 8)
379 Private->EPOC_FrameBuffer += 512;
383 Private->EPOC_FrameBuffer += 32;
385 /*if (Private->EPOC_HasFrameBuffer && GetBpp(displayMode) == 12)
386 Private->EPOC_FrameBuffer += 16 * 2;
387 if (Private->EPOC_HasFrameBuffer && GetBpp(displayMode) == 16)
388 Private->EPOC_FrameBuffer += 16 * 2;
390 #else /* defined __WINS__ */
392 /* Create bitmap, device and context for screen drawing */
393 Private->EPOC_ScreenSize = Private->EPOC_WsScreen->SizeInPixels();
395 Private->EPOC_Bitmap = new (ELeave) CWsBitmap(Private->EPOC_WsSession);
396 Private->EPOC_Bitmap->Create(Private->EPOC_ScreenSize, displayMode);
398 Private->EPOC_DisplayMode = displayMode;
399 Private->EPOC_HasFrameBuffer = ETrue;
400 Private->EPOC_FrameBuffer = NULL; /* Private->EPOC_Bitmap->DataAddress() can change any time */
401 Private->EPOC_BytesPerPixel = ((GetBpp(displayMode)-1) / 8) + 1;
402 Private->EPOC_BytesPerScanLine = Private->EPOC_WsScreen->SizeInPixels().iWidth * Private->EPOC_BytesPerPixel;
404 #endif /* __WINS__ */
406 #ifndef SYMBIAN_CRYSTAL
407 // Get draw device for updating the screen
408 TScreenInfoV01 screenInfo2;
410 Epoc_Runtime::GetScreenInfo(screenInfo2);
412 TRAPD(status, Private->EPOC_DrawDevice = CFbsDrawDevice::NewScreenDeviceL(screenInfo2, displayMode));
413 User::LeaveIfError(status);
416 /* The "best" video format should be returned to caller. */
418 vformat->BitsPerPixel = /*!!GetBpp(displayMode) */ 8;
419 vformat->BytesPerPixel = /*!!Private->EPOC_BytesPerPixel*/ 1;
421 /* Activate events for me */
423 Private->EPOC_WsEventStatus = KRequestPending;
424 Private->EPOC_WsSession.EventReady(&Private->EPOC_WsEventStatus);
426 SDL_TRACE("SDL:WsEventStatus");
427 User::WaitForRequest(Private->EPOC_WsEventStatus); //Markus: I added this and ...
429 Private->EPOC_RedrawEventStatus = KRequestPending;
430 Private->EPOC_WsSession.RedrawReady(&Private->EPOC_RedrawEventStatus);
432 SDL_TRACE("SDL:RedrawEventStatus");
433 User::WaitForRequest(Private->EPOC_RedrawEventStatus); //...this, if not catches a stray event is risen
434 //if there are active objects used, or confucing
435 //actions with User::WaitForAnyRequest
436 Private->EPOC_WsWindow.PointerFilter(EPointerFilterDrag, 0);
438 Private->EPOC_ScreenOffset = TPoint(0, 0);
440 #if defined(__WINS__) || defined(TEST_BM_DRAW)
441 LockHeap(Private->EPOC_Bitmap); // Lock bitmap heap
444 SDL_TRACE("SDL:DrawBackground");
445 DrawBackground(_this); // Clear screen
447 #if defined(__WINS__) || defined(TEST_BM_DRAW)
448 UnlockHeap(Private->EPOC_Bitmap); // Unlock bitmap heap
450 //!! TODO: error handling
451 //if (ret != KErrNone)
458 SDL_Rect **EPOC_ListModes(_THIS, SDL_PixelFormat *format, Uint32 /*flags*/)
460 if (format->BitsPerPixel == 12 || format->BitsPerPixel == 8)
461 return Private->SDL_modelist;
465 int EPOC_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color *colors)
467 if ((firstcolor+ncolors) > 256)
469 // SDL_TRACE1("colors %d", (TDisplayModeUtils::NumDisplayModeColors(Private->EPOC_DisplayMode)));
470 if(TDisplayModeUtils::NumDisplayModeColors(Private->EPOC_DisplayMode) == 4096)
472 // Set 12 bit palette
473 for(int i = firstcolor; i < ncolors; i++)
475 // 4k value: 0000 rrrr gggg bbbb
476 TUint32 color4K = (colors[i].r & 0x0000f0) << 4;
477 color4K |= (colors[i].g & 0x0000f0);
478 color4K |= (colors[i].b & 0x0000f0) >> 4;
479 EPOC_HWPalette_256_to_Screen[i] = color4K;
482 else if(TDisplayModeUtils::NumDisplayModeColors(Private->EPOC_DisplayMode) == 65536)
484 for(int i = firstcolor; i < ncolors; i++)
486 // 64k-colour displays effectively support RGB values
487 // with 5 bits allocated to red, 6 to green and 5 to blue
488 // 64k value: rrrr rggg gggb bbbb
489 TUint32 color64K = (colors[i].r & 0x0000f8) << 8;
490 color64K |= (colors[i].g & 0x0000fc) << 3;
491 color64K |= (colors[i].b & 0x0000f8) >> 3;
492 EPOC_HWPalette_256_to_Screen[i] = color64K;
495 else if(TDisplayModeUtils::NumDisplayModeColors(Private->EPOC_DisplayMode) == 16777216)
497 for(int i = firstcolor; i < ncolors; i++)
500 //0000 0000 rrrr rrrr gggg gggg bbbb bbbb
501 TUint32 color16M = colors[i].r << 16;
502 color16M |= colors[i].g << 8;
503 color16M |= colors[i].b;
504 EPOC_HWPalette_256_to_Screen[i] = color16M;
515 SDL_Surface *EPOC_SetVideoMode(_THIS, SDL_Surface *current,
516 int width, int height, int bpp, Uint32 /*flags*/)
518 SDL_TRACE("SDL:EPOC_SetVideoMode");
519 /* Check parameters */
520 #ifdef SYMBIAN_CRYSTAL
521 if (! (bpp == 8 || bpp == 12 || bpp == 16) &&
523 (width == 640 && height == 200) ||
524 (width == 640 && height == 400) ||
525 (width == 640 && height == 480) ||
526 (width == 320 && height == 200) ||
527 (width == 320 && height == 240)
529 SDL_SetError("Requested video mode is not supported");
532 #else // SYMBIAN_SERIES60
533 if (! (bpp == 8 || bpp == 12 || bpp == 16) &&
535 (width == 320 && height == 200) ||
536 (width == 320 && height == 240) ||
537 (width == 256 && height == 192) ||
538 (width == 176 && height == 208) ||
539 (width == 208 && height == 176) || // Rotated
540 (width == 160 && height == 144)
542 SDL_SetError("Requested video mode is not supported");
547 if (current && current->pixels) {
548 free(current->pixels);
549 current->pixels = NULL;
551 if ( ! SDL_ReallocFormat(current, bpp, 0, 0, 0, 0) ) {
555 /* Set up the new mode framebuffer */
557 current->flags = (SDL_FULLSCREEN|SDL_SWSURFACE|SDL_PREALLOC|SDL_HWPALETTE);
558 else // 12 bpp, 16 bpp
559 current->flags = (SDL_FULLSCREEN|SDL_SWSURFACE|SDL_PREALLOC);
562 int numBytesPerPixel = ((bpp-1)>>3) + 1;
563 current->pitch = numBytesPerPixel * width; // Number of bytes in scanline
564 current->pixels = malloc(width * height * numBytesPerPixel);
565 memset(current->pixels, 0, width * height * numBytesPerPixel);
567 /* Set the blit function */
568 _this->UpdateRects = EPOC_DirectUpdate;
571 * Logic for getting suitable screen dimensions, offset, scaling and orientation
577 // Rotate, if the screen does not fit horizontally and it is landscape screen
579 if ((width>Private->EPOC_ScreenSize.iWidth) && (width>height)) {
580 Private->EPOC_ScreenOrientation = CFbsBitGc::EGraphicsOrientationRotated270;
585 // Get nearest stepwise scale values for width and height. The smallest supported scaled screen is 1/2.
587 Private->EPOC_ScreenXScaleValue = 1;
588 Private->EPOC_ScreenYScaleValue = 1;
589 if (w > Private->EPOC_ScreenSize.iWidth) {
590 // Find the biggest scale value that result the width that fits in the screen HW
591 for (scaleValue = 2; scaleValue++;) {
592 TInt scaledWidth = (w * (scaleValue-1))/scaleValue;
593 if (scaledWidth > Private->EPOC_ScreenSize.iWidth)
596 Private->EPOC_ScreenXScaleValue = Max(2, scaleValue - 1);
597 w = (w * (Private->EPOC_ScreenXScaleValue-1))/Private->EPOC_ScreenXScaleValue;
599 if (h > Private->EPOC_ScreenSize.iHeight) {
600 // Find the biggest scale value that result the height that fits in the screen HW
601 for (scaleValue = 2; scaleValue++;) {
602 TInt scaledHeight = (h * (scaleValue-1))/scaleValue;
603 if (scaledHeight > Private->EPOC_ScreenSize.iHeight)
606 Private->EPOC_ScreenYScaleValue = Max(2, scaleValue - 1);
607 h = (h * (Private->EPOC_ScreenYScaleValue-1))/Private->EPOC_ScreenYScaleValue;
610 /* Centralize game window on device screen */
611 Private->EPOC_ScreenOffset.iX = (Private->EPOC_ScreenSize.iWidth - w) / 2;
612 if (Private->EPOC_ScreenOffset.iX < 0)
613 Private->EPOC_ScreenOffset.iX = 0;
614 Private->EPOC_ScreenOffset.iY = (Private->EPOC_ScreenSize.iHeight - h) / 2;
615 if (Private->EPOC_ScreenOffset.iY < 0)
616 Private->EPOC_ScreenOffset.iY = 0;
619 SDL_TRACE1("View width %d", w);
620 SDL_TRACE1("View height %d", h);
621 SDL_TRACE1("View bmode %d", bpp);
622 SDL_TRACE1("View s %d", scaleValue);
623 SDL_TRACE1("View x %d", Private->EPOC_ScreenOffset.iX);
624 SDL_TRACE1("View y %d", Private->EPOC_ScreenOffset.iY);
631 void RedrawWindowL(_THIS)
634 #if defined(__WINS__) || defined(TEST_BM_DRAW)
635 LockHeap(Private->EPOC_Bitmap); // Lock bitmap heap
636 Private->EPOC_WindowGc->Activate(Private->EPOC_WsWindow);
639 int w = _this->screen->w;
640 int h = _this->screen->h;
641 if (Private->EPOC_ScreenOrientation == CFbsBitGc::EGraphicsOrientationRotated270) {
642 w = _this->screen->h;
643 h = _this->screen->w;
645 if ((w < Private->EPOC_ScreenSize.iWidth)
646 || (h < Private->EPOC_ScreenSize.iHeight)) {
647 DrawBackground(_this);
650 /* Tell the system that something has been drawn */
651 TRect rect = TRect(Private->EPOC_WsWindow.Size());
652 Private->EPOC_WsWindow.Invalidate(rect);
654 #if defined(__WINS__) || defined(TEST_BM_DRAW)
655 Private->EPOC_WsWindow.BeginRedraw(rect);
656 Private->EPOC_WindowGc->BitBlt(TPoint(), Private->EPOC_Bitmap);
657 Private->EPOC_WsWindow.EndRedraw();
658 Private->EPOC_WindowGc->Deactivate();
659 UnlockHeap(Private->EPOC_Bitmap);; // Unlock bitmap heap
660 Private->EPOC_WsSession.Flush();
663 /* Draw current buffer */
667 fullScreen.w = _this->screen->w;
668 fullScreen.h = _this->screen->h;
669 EPOC_DirectUpdate(_this, 1, &fullScreen);
673 void DrawBackground(_THIS)
675 /* Draw background */
676 #if defined(__WINS__) || defined(TEST_BM_DRAW)
677 //warning heap is not locked! - a function calling must ensure that it's ok
678 TUint16* screenBuffer = (TUint16*)Private->EPOC_Bitmap->DataAddress();
680 TUint16* screenBuffer = (TUint16*)Private->EPOC_FrameBuffer;
682 // Draw black background
683 Mem::FillZ(screenBuffer, Private->EPOC_BytesPerScreen);
686 for (int y = 0; y < Private->EPOC_ScreenSize.iHeight; y++) {
687 for (int x = 0; x < Private->EPOC_ScreenSize.iWidth; x++) {
688 #ifdef SYMBIAN_CRYSTAL
689 const TUint16 color = 0; // ((x+y)>>1) & 0xf; /* Draw blue stripes pattern, because in e.g. 320x200 mode there is a big background area*/
690 #else // SYMBIAN_SERIES60
691 const TUint16 color = 0; /* Draw black background */
693 *screenBuffer++ = color;
700 /* We don't actually allow hardware surfaces other than the main one */
701 static int EPOC_AllocHWSurface(_THIS, SDL_Surface* /*surface*/)
705 static void EPOC_FreeHWSurface(_THIS, SDL_Surface* /*surface*/)
710 static int EPOC_LockHWSurface(_THIS, SDL_Surface* /*surface*/)
714 static void EPOC_UnlockHWSurface(_THIS, SDL_Surface* /*surface*/)
719 static int EPOC_FlipHWSurface(_THIS, SDL_Surface* /*surface*/)
724 static void EPOC_DirectUpdate(_THIS, int numrects, SDL_Rect *rects)
726 //TInt focusWindowGroupId = Private->EPOC_WsSession.GetFocusWindowGroup();//these are async services
727 // if (focusWindowGroupId != Private->EPOC_WsWindowGroupID) { //for that cannot be called from
729 if (!Private->EPOC_IsWindowFocused)
731 /* Force focus window to redraw again for cleaning away SDL screen graphics */
733 TInt pos = Private->EPOC_WsWindowGroup.OrdinalPosition();
734 Private->EPOC_WsWindowGroup.SetOrdinalPosition(0, KMaxTInt);
735 TRect rect = TRect(Private->EPOC_WsWindow.Size());
736 Private->EPOC_WsWindow.Invalidate(rect);
737 Private->EPOC_WsWindowGroup.SetOrdinalPosition(pos, ECoeWinPriorityNormal);
738 */ /* If this is not the topmost window, wait here! Sleep for 1 second to give cpu time to
739 multitasking and poll for being the topmost window.
741 // if (Private->EPOC_WsSession.GetFocusWindowGroup() != Private->EPOC_WsWindowGroupID) {
743 /* !!TODO: Could call GetRedraw() etc. for WsSession and redraw the screen if needed. That might be
744 needed if a small dialog comes in front of Game screen.
746 // while (Private->EPOC_WsSession.GetFocusWindowGroup() != Private->EPOC_WsWindowGroupID)
753 // RedrawWindowL(_this);
758 // if we are not focused, do not draw
759 // if (!Private->EPOC_IsWindowFocused)
761 #if defined(__WINS__) || defined(TEST_BM_DRAW)
762 TBitmapUtil lock(Private->EPOC_Bitmap);
763 lock.Begin(TPoint(0,0)); // Lock bitmap heap
764 Private->EPOC_WindowGc->Activate(Private->EPOC_WsWindow);
765 TUint16* screenBuffer = (TUint16*)Private->EPOC_Bitmap->DataAddress();
767 TUint16* screenBuffer = (TUint16*)Private->EPOC_FrameBuffer;
770 if (Private->EPOC_ScreenOrientation == CFbsBitGc::EGraphicsOrientationRotated270)
771 DirectDrawRotated(_this, numrects, rects, screenBuffer);
773 DirectDraw(_this, numrects, rects, screenBuffer);
776 #if defined(__WINS__) || defined(TEST_BM_DRAW)
778 TRect rect = TRect(Private->EPOC_WsWindow.Size());
779 Private->EPOC_WsWindow.Invalidate(rect);
780 Private->EPOC_WsWindow.BeginRedraw(rect);
781 Private->EPOC_WindowGc->BitBlt(TPoint(), Private->EPOC_Bitmap);
782 Private->EPOC_WsWindow.EndRedraw();
783 Private->EPOC_WindowGc->Deactivate();
784 lock.End(); // Unlock bitmap heap
785 Private->EPOC_WsSession.Flush();
787 #ifndef SYMBIAN_CRYSTAL
788 // This is not needed in Crystal. What is the performance penalty in SERIES60?
789 TRect rect2 = TRect(Private->EPOC_WsWindow.Size());
791 Private->EPOC_DrawDevice->UpdateRegion(rect2); // Should we update rects parameter area only??
792 Private->EPOC_DrawDevice->Update();
796 /* Update virtual cursor. !!Do not yet work properly
797 Private->EPOC_WsSession.SetPointerCursorPosition(Private->EPOC_WsSession.PointerCursorPosition());
800 /*static int foo = 1;
802 for ( int i=0; i < numrects; ++i ) {
803 const SDL_Rect& currentRect = rects[i];
805 rect2.x = currentRect.x;
806 rect2.y = currentRect.y;
807 rect2.w = currentRect.w;
808 rect2.h = currentRect.h;
810 if (rect2.w <= 0 || rect2.h <= 0)
817 SDL_TRACE1("foo %d", foo);
818 CFbsBitmap* b = new (ELeave) CFbsBitmap;
819 SDL_TRACE1("bee %d", (int)b);
820 int e = b->Create(TSize(currentRect.w, currentRect.h), Private->EPOC_DisplayMode);
822 SDL_TRACE1("err %d", e);
824 User::Panic(_L("damn"), e);
827 u.Begin(TPoint(0, 0));
828 TUint32* d = b->DataAddress();
830 SDL_TRACE1("addr %d", (int)d);
832 for(TInt o = 0; o < currentRect.h; o++)
833 for(TInt p = 0; p < currentRect.w; p++)
835 u.SetPos(TPoint(p, o));
839 SDL_TRACE1("w %d", (int)currentRect.w);
840 SDL_TRACE1("h %d", (int)currentRect.h);
842 SDL_TRACE1("addr %d", (int)Private->EPOC_DisplayMode);
845 const TUint f = (TUint)Private->EPOC_FrameBuffer;
846 const TUint y = (TUint)Private->EPOC_BytesPerScreen;
849 SDL_TRACE1("frame %u", f);
850 SDL_TRACE1("bytes %u", y);
852 Mem::Copy(d, Private->EPOC_FrameBuffer, Private->EPOC_BytesPerScreen);
858 name.Format(_L("C:\\nokia\\images\\doom%d.mbm"), (foo / 200));
861 User::Panic(_L("damned"), e);
867 void DirectDraw(_THIS, int numrects, SDL_Rect *rects, TUint16* screenBuffer)
871 const TInt sourceNumBytesPerPixel = ((_this->screen->format->BitsPerPixel-1)>>3) + 1;
872 const TPoint fixedOffset = Private->EPOC_ScreenOffset;
873 const TInt screenW = _this->screen->w;
874 const TInt screenH = _this->screen->h;
875 const TInt sourceScanlineLength = screenW;
876 const TInt targetScanlineLength = Private->EPOC_ScreenSize.iWidth;
878 /* Render the rectangles in the list */
880 for ( i=0; i < numrects; ++i ) {
881 const SDL_Rect& currentRect = rects[i];
883 rect2.x = currentRect.x;
884 rect2.y = currentRect.y;
885 rect2.w = currentRect.w;
886 rect2.h = currentRect.h;
888 if (rect2.w <= 0 || rect2.h <= 0) /* sanity check */
891 /* All variables are measured in pixels */
893 /* Check rects validity, i.e. upper and lower bounds */
894 TInt maxX = Min(screenW - 1, rect2.x + rect2.w - 1);
895 TInt maxY = Min(screenH - 1, rect2.y + rect2.h - 1);
896 if (maxX < 0 || maxY < 0) /* sanity check */
898 /* Clip from bottom */
899 maxY = Min(maxY, Private->EPOC_ScreenSize.iHeight-1);
900 /* TODO: Clip from the right side */
902 const TInt sourceRectWidth = maxX - rect2.x + 1;
903 const TInt sourceRectWidthInBytes = sourceRectWidth * sourceNumBytesPerPixel;
904 const TInt sourceRectHeight = maxY - rect2.y + 1;
905 const TInt sourceStartOffset = rect2.x + rect2.y * sourceScanlineLength;
906 const TUint skipValue = 1; // no skip
908 TInt targetStartOffset = fixedOffset.iX + rect2.x + (fixedOffset.iY +rect2.y) * targetScanlineLength;
910 // Nokia7650 native mode: 12 bpp --> 12 bpp
913 switch (_this->screen->format->BitsPerPixel)
917 TUint16* bitmapLine = (TUint16*)_this->screen->pixels + sourceStartOffset;
918 TUint16* screenMemory = screenBuffer + targetStartOffset;
921 for(TInt y = 0 ; y < sourceRectHeight ; y++)
923 Mem::Copy(screenMemory, bitmapLine, sourceRectWidthInBytes);
925 bitmapLine += sourceScanlineLength;
926 screenMemory += targetScanlineLength;
930 for(TInt y = 0 ; y < sourceRectHeight ; y++)
932 //TODO: optimize: separate loops for 1, 2 and n skip. Mem::Copy() can be used in unscaled case.
933 TUint16* bitmapPos = bitmapLine; /* 2 bytes per pixel */
934 TUint16* screenMemoryLinePos = screenMemory; /* 2 bytes per pixel */
935 for(TInt x = 0 ; x < sourceRectWidth ; x++)
937 __ASSERT_DEBUG(screenMemory < (screenBuffer + Private->EPOC_ScreenSize.iWidth * Private->EPOC_ScreenSize.iHeight), User::Panic(_L("SDL"), KErrCorrupt));
938 __ASSERT_DEBUG(screenMemory >= screenBuffer, User::Panic(_L("SDL"), KErrCorrupt));
939 __ASSERT_DEBUG(bitmapLine < ((TUint16*)_this->screen->pixels + (_this->screen->w * _this->screen->h)), User::Panic(_L("SDL"), KErrCorrupt));
940 __ASSERT_DEBUG(bitmapLine >= (TUint16*)_this->screen->pixels, User::Panic(_L("SDL"), KErrCorrupt));
942 *screenMemoryLinePos++ = *bitmapPos;
943 bitmapPos+=skipValue;
945 bitmapLine += sourceScanlineLength;
946 screenMemory += targetScanlineLength;
951 // 256 color paletted mode: 8 bpp --> 12 bpp
955 if(Private->EPOC_BytesPerPixel <= 2)
957 TUint8* bitmapLine = (TUint8*)_this->screen->pixels + sourceStartOffset;
958 TUint16* screenMemory = screenBuffer + targetStartOffset;
959 for(TInt y = 0 ; y < sourceRectHeight ; y++)
961 TUint8* bitmapPos = bitmapLine; /* 1 byte per pixel */
962 TUint16* screenMemoryLinePos = screenMemory; /* 2 bytes per pixel */
963 /* Convert each pixel from 256 palette to 4k color values */
964 for(TInt x = 0 ; x < sourceRectWidth ; x++)
966 __ASSERT_DEBUG(screenMemoryLinePos < (screenBuffer + (Private->EPOC_ScreenSize.iWidth * Private->EPOC_ScreenSize.iHeight)), User::Panic(_L("SDL"), KErrCorrupt));
967 __ASSERT_DEBUG(screenMemoryLinePos >= screenBuffer, User::Panic(_L("SDL"), KErrCorrupt));
968 __ASSERT_DEBUG(bitmapPos < ((TUint8*)_this->screen->pixels + (_this->screen->w * _this->screen->h)), User::Panic(_L("SDL"), KErrCorrupt));
969 __ASSERT_DEBUG(bitmapPos >= (TUint8*)_this->screen->pixels, User::Panic(_L("SDL"), KErrCorrupt));
970 *screenMemoryLinePos++ = EPOC_HWPalette_256_to_Screen[*bitmapPos++];
971 // bitmapPos+=skipValue; //TODO: optimize: separate loops for 1, 2 and n skip
973 bitmapLine += sourceScanlineLength;
974 screenMemory += targetScanlineLength;
979 TUint8* bitmapLine = (TUint8*)_this->screen->pixels + sourceStartOffset;
980 TUint32* screenMemory = reinterpret_cast<TUint32*>(screenBuffer + targetStartOffset);
981 for(TInt y = 0 ; y < sourceRectHeight ; y++)
983 TUint8* bitmapPos = bitmapLine; /* 1 byte per pixel */
984 TUint32* screenMemoryLinePos = screenMemory; /* 2 bytes per pixel */
985 /* Convert each pixel from 256 palette to 4k color values */
986 for(TInt x = 0 ; x < sourceRectWidth ; x++)
988 __ASSERT_DEBUG(screenMemoryLinePos < (reinterpret_cast<TUint32*>(screenBuffer) + (Private->EPOC_ScreenSize.iWidth * Private->EPOC_ScreenSize.iHeight)), User::Panic(_L("SDL"), KErrCorrupt));
989 __ASSERT_DEBUG(screenMemoryLinePos >= reinterpret_cast<TUint32*>(screenBuffer), User::Panic(_L("SDL"), KErrCorrupt));
990 __ASSERT_DEBUG(bitmapPos < ((TUint8*)_this->screen->pixels + (_this->screen->w * _this->screen->h)), User::Panic(_L("SDL"), KErrCorrupt));
991 __ASSERT_DEBUG(bitmapPos >= (TUint8*)_this->screen->pixels, User::Panic(_L("SDL"), KErrCorrupt));
992 *screenMemoryLinePos++ = EPOC_HWPalette_256_to_Screen[*bitmapPos++];
993 // bitmapPos+=skipValue; //TODO: optimize: separate loops for 1, 2 and n skip
995 bitmapLine += sourceScanlineLength;
996 screenMemory += targetScanlineLength;
1005 void DirectDraw(_THIS, int numrects, SDL_Rect *rects, TUint16* screenBuffer)
1008 const TInt sourceNumBytesPerPixel = ((_this->screen->format->BitsPerPixel-1)>>3) + 1;
1009 const TPoint fixedOffset = Private->EPOC_ScreenOffset;
1010 const TInt screenW = _this->screen->w;
1011 const TInt screenH = _this->screen->h;
1012 const TInt sourceScanlineLength = screenW;
1013 const TInt targetScanlineLength = Private->EPOC_ScreenSize.iWidth;
1015 /* Render the rectangles in the list */
1017 /* for ( i=0; i < numrects; ++i ) {
1018 const SDL_Rect& currentRect = rects[i];
1020 rect2.x = currentRect.x;
1021 rect2.y = currentRect.y;
1022 rect2.w = currentRect.w;
1023 rect2.h = currentRect.h;
1025 if (rect2.w <= 0 || rect2.h <= 0) /* sanity check */
1028 /* All variables are measured in pixels */
1030 /* Check rects validity, i.e. upper and lower bounds */
1031 /* TInt maxX = Min(screenW - 1, rect2.x + rect2.w - 1);
1032 TInt maxY = Min(screenH - 1, rect2.y + rect2.h - 1);
1033 if (maxX < 0 || maxY < 0) /* sanity check */
1035 /* Clip from bottom */
1036 /* maxY = Min(maxY, Private->EPOC_ScreenSize.iHeight-1);
1037 /* TODO: Clip from the right side */
1039 /* TInt sourceRectWidth = maxX - rect2.x + 1;
1040 const TInt sourceRectWidthInBytes = sourceRectWidth * sourceNumBytesPerPixel;
1041 const TInt sourceRectHeight = maxY - rect2.y + 1;
1042 const TInt sourceStartOffset = rect2.x + rect2.y * sourceScanlineLength;
1043 const TUint skipValue = Private->EPOC_ScreenXScaleValue; //1; // no skip
1045 const TInt targetStartOffset = // = (fixedOffset.iX + (rect2.x / skipValue) + (fixedOffset.iY + rect2.y) * targetScanlineLength ) ;
1047 (fixedOffset.iX + (rect2.x / skipValue) + (fixedOffset.iY + rect2.y) * targetScanlineLength ) :
1048 (fixedOffset.iX + rect2.x + (fixedOffset.iY + rect2.y) * targetScanlineLength ));
1050 __ASSERT_DEBUG(skipValue >= 1, User::Panic(KLibName, KErrArgument));
1052 // Nokia7650 native mode: 12 bpp --> 12 bpp
1054 switch (_this->screen->format->BitsPerPixel)
1058 TUint16* bitmapLine = (TUint16*)_this->screen->pixels + sourceStartOffset;
1059 TUint16* screenMemory = screenBuffer + targetStartOffset;
1062 for(TInt y = 0 ; y < sourceRectHeight ; y++)
1064 Mem::Copy(screenMemory, bitmapLine, sourceRectWidthInBytes);
1066 bitmapLine += sourceScanlineLength;
1067 screenMemory += targetScanlineLength;
1071 for(TInt y = 0 ; y < sourceRectHeight ; y++)
1073 //TODO: optimize: separate loops for 1, 2 and n skip. Mem::Copy() can be used in unscaled case.
1074 TUint16* bitmapPos = bitmapLine; /* 2 bytes per pixel */
1075 /* TUint16* screenMemoryLinePos = screenMemory; /* 2 bytes per pixel */
1076 /* for(TInt x = 0 ; x < sourceRectWidth ; x++)
1078 __ASSERT_DEBUG(screenMemory < (screenBuffer + Private->EPOC_ScreenSize.iWidth * Private->EPOC_ScreenSize.iHeight), User::Panic(KLibName, KErrCorrupt));
1079 __ASSERT_DEBUG(screenMemory >= screenBuffer, User::Panic(KLibName, KErrCorrupt));
1080 __ASSERT_DEBUG(bitmapLine < ((TUint16*)_this->screen->pixels + (_this->screen->w * _this->screen->h)), User::Panic(KLibName, KErrCorrupt));
1081 __ASSERT_DEBUG(bitmapLine >= (TUint16*)_this->screen->pixels, User::Panic(KLibName, KErrCorrupt));
1083 *screenMemoryLinePos++ = *bitmapPos;
1084 bitmapPos+=skipValue;
1086 bitmapLine += sourceScanlineLength;
1087 screenMemory += targetScanlineLength;
1092 // 256 color paletted mode: 8 bpp --> 12 bpp
1096 TUint8* bitmapLine = (TUint8*)_this->screen->pixels + sourceStartOffset;
1097 TUint16* screenMemory = screenBuffer + targetStartOffset;
1099 sourceRectWidth /= skipValue;
1100 #if defined __MARM_ARMI__
1102 mov %4, %4, lsl #1 @ targetScanLineLength is in pixels, we need it in bytes
1104 mov r6, %0 @ bitmapLine
1105 mov r7, %2 @ screenMemory
1106 mov r8, %6 @ sourceRectWidth
1108 ldrb r4, [%0], %7 @ r4 = *bitmapPos; bitmapPos += skipValue
1109 ldr r5, [%1, r4, lsl #2] @ only 16 lower bits actually used
1110 subs r8, r8, #1 @ x--
1111 strh r5, [%2], #2 @ *screenMemoryLinePos++ = r4
1114 add %0, r6, %3 @ bitmapLine += sourceScanlineLength
1115 add %2, r7, %4 @ screenMemory += targetScanlineLength
1116 subs %5, %5, #1 @ sourceRectHeight--
1120 // %0 %1 %2 %3 %4 %5 %6 %7
1121 : "r" (bitmapLine), "r" (&EPOC_HWPalette_256_to_Screen[0]), "r" (screenMemory), "r" (sourceScanlineLength), "r" (targetScanlineLength), "r" (sourceRectHeight), "r" (sourceRectWidth), "r" (skipValue)
1122 : "r4", "r5", "r6", "r7", "r8"
1125 for(TInt y = 0 ; y < sourceRectHeight ; y++)
1127 TUint8* bitmapPos = bitmapLine; /* 1 byte per pixel */
1128 /* TUint16* screenMemoryLinePos = screenMemory; /* 2 bytes per pixel */
1129 /* Convert each pixel from 256 palette to 4k color values */
1130 /* for (TInt x = 0 ; x < sourceRectWidth ; x++)
1132 //__ASSERT_DEBUG(screenMemoryLinePos < (screenBuffer + (Private->EPOC_ScreenSize.iWidth * Private->EPOC_ScreenSize.iHeight)), User::Panic(KLibName, KErrCorrupt));
1133 //__ASSERT_DEBUG(screenMemoryLinePos >= screenBuffer, User::Panic(KLibName, KErrCorrupt));
1134 //__ASSERT_DEBUG(bitmapPos < ((TUint8*)_this->screen->pixels + (_this->screen->w * _this->screen->h)), User::Panic(KLibName, KErrCorrupt));
1135 //__ASSERT_DEBUG(bitmapPos >= (TUint8*)_this->screen->pixels, User::Panic(KLibName, KErrCorrupt));
1137 *screenMemoryLinePos++ = EPOC_HWPalette_256_to_Screen[*bitmapPos];
1138 bitmapPos += skipValue;
1140 bitmapLine += sourceScanlineLength;
1141 screenMemory += targetScanlineLength;
1150 void DirectDrawRotated(_THIS, int numrects, SDL_Rect *rects, TUint16* screenBuffer)
1153 // TInt sourceNumBytesPerPixel = ((_this->screen->format->BitsPerPixel-1)>>3) + 1;
1154 TPoint fixedScreenOffset = Private->EPOC_ScreenOffset;
1155 TInt bufferW = _this->screen->w;
1156 TInt bufferH = _this->screen->h;
1157 TInt ScreenW = Private->EPOC_ScreenSize.iWidth;
1158 // TInt ScreenH = Private->EPOC_ScreenSize.iWidth;
1159 TInt sourceW = bufferW;
1160 TInt sourceH = bufferH;
1161 TInt targetW = ScreenW - fixedScreenOffset.iX * 2;
1162 // TInt targetH = ScreenH - fixedScreenOffset.iY * 2;
1163 TInt sourceScanlineLength = bufferW;
1164 TInt targetScanlineLength = Private->EPOC_ScreenSize.iWidth;
1166 /* Render the rectangles in the list */
1168 for ( i=0; i < numrects; ++i ) {
1170 const SDL_Rect& currentRect = rects[i];
1171 rect2.x = currentRect.x;
1172 rect2.y = currentRect.y;
1173 rect2.w = currentRect.w;
1174 rect2.h = currentRect.h;
1176 if (rect2.w <= 0 || rect2.h <= 0) /* sanity check */
1179 /* All variables are measured in pixels */
1181 /* Check rects validity, i.e. upper and lower bounds */
1182 TInt maxX = Min(sourceW - 1, rect2.x + rect2.w - 1);
1183 TInt maxY = Min(sourceH - 1, rect2.y + rect2.h - 1);
1184 if (maxX < 0 || maxY < 0) /* sanity check */
1186 /* Clip from bottom */
1187 //maxX = Min(maxX, Private->EPOC_ScreenSize.iHeight-1);
1188 /* TODO: Clip from the right side */
1190 TInt sourceRectWidth = maxX - rect2.x + 1;
1191 // TInt sourceRectWidthInBytes = sourceRectWidth * sourceNumBytesPerPixel;
1192 TInt sourceRectHeight = maxY - rect2.y + 1;
1193 TInt sourceStartOffset = rect2.x + rect2.y * sourceScanlineLength;
1194 TInt targetStartOffset = fixedScreenOffset.iX + (targetW-1 - rect2.y) + (fixedScreenOffset.iY +rect2.x) * targetScanlineLength;
1196 // Nokia7650 native mode: 12 bpp --> 12 bpp
1197 if (_this->screen->format->BitsPerPixel == 12) {
1199 /* !!TODO: not yet implemented
1201 TUint16* bitmapLine = (TUint16*)_this->screen->pixels + sourceStartOffset;
1202 TUint16* screenMemory = screenBuffer + targetStartOffset;
1203 for(TInt y = 0 ; y < sourceRectHeight ; y++) {
1204 //TODO: optimize: separate loops for 1, 2 and n skip
1205 //Mem::Copy(screenMemory, bitmapLine, sourceRectWidthInBytes);
1206 TUint16* bitmapPos = bitmapLine; // 2 bytes per pixel
1207 TUint16* screenMemoryLinePos = screenMemory; // 2 bytes per pixel
1208 for(TInt x = 0 ; x < sourceRectWidth ; x++) {
1210 __ASSERT_DEBUG(screenMemory < (screenBuffer + Private->EPOC_ScreenSize.iWidth * Private->EPOC_ScreenSize.iHeight), User::Panic(KLibName, KErrCorrupt));
1211 __ASSERT_DEBUG(screenMemory >= screenBuffer, User::Panic(KLibName, KErrCorrupt));
1212 __ASSERT_DEBUG(bitmapLine < ((TUint16*)_this->screen->pixels + (_this->screen->w * _this->screen->h)), User::Panic(KLibName, KErrCorrupt));
1213 __ASSERT_DEBUG(bitmapLine >= (TUint16*)_this->screen->pixels, User::Panic(KLibName, KErrCorrupt));
1215 *screenMemoryLinePos = *bitmapPos;
1217 screenMemoryLinePos += targetScanlineLength;
1219 bitmapLine += sourceScanlineLength;
1225 // 256 color paletted mode: 8 bpp --> 12 bpp
1227 TUint8* bitmapLine = (TUint8*)_this->screen->pixels + sourceStartOffset;
1228 TUint16* screenMemory = screenBuffer + targetStartOffset;
1229 TInt screenXScaleValue = Private->EPOC_ScreenXScaleValue;
1230 TInt debug_ycount=0;
1231 for(TInt y = 0 ; y < sourceRectHeight ; y++) {
1232 if(--screenXScaleValue) {
1233 TUint8* bitmapPos = bitmapLine; /* 1 byte per pixel */
1234 TUint16* screenMemoryLinePos = screenMemory; /* 2 bytes per pixel */
1235 TInt screenYScaleValue = Private->EPOC_ScreenYScaleValue;
1236 TInt debug_xcount=0;
1237 /* Convert each pixel from 256 palette to 4k color values */
1238 for(TInt x = 0 ; x < sourceRectWidth ; x++) {
1239 if(--screenYScaleValue) {
1241 __ASSERT_DEBUG(screenMemoryLinePos < (screenBuffer + (Private->EPOC_ScreenSize.iWidth * Private->EPOC_ScreenSize.iHeight)), User::Panic(KLibName, KErrCorrupt));
1242 __ASSERT_DEBUG(screenMemoryLinePos >= screenBuffer, User::Panic(KLibName, KErrCorrupt));
1243 __ASSERT_DEBUG(bitmapPos < ((TUint8*)_this->screen->pixels + (_this->screen->w * _this->screen->h)), User::Panic(KLibName, KErrCorrupt));
1244 __ASSERT_DEBUG(bitmapPos >= (TUint8*)_this->screen->pixels, User::Panic(KLibName, KErrCorrupt));
1246 *screenMemoryLinePos = TUint16(EPOC_HWPalette_256_to_Screen[*bitmapPos]);
1247 screenMemoryLinePos += targetScanlineLength; debug_xcount++;
1250 screenYScaleValue = Private->EPOC_ScreenYScaleValue;
1253 screenMemory--; debug_ycount++;
1256 screenXScaleValue = Private->EPOC_ScreenXScaleValue;
1257 bitmapLine += sourceScanlineLength;
1264 /* Note: If we are terminated, this could be called in the middle of
1265 another SDL video routine -- notably UpdateRects.
1267 void EPOC_VideoQuit(_THIS)
1271 /* Free video mode lists */
1272 for ( i=0; i<SDL_NUMMODES; ++i ) {
1273 if ( Private->SDL_modelist[i] != NULL ) {
1274 free(Private->SDL_modelist[i]);
1275 Private->SDL_modelist[i] = NULL;
1279 if ( _this->screen && (_this->screen->flags & SDL_HWSURFACE) ) {
1280 /* Direct screen access, no memory buffer */
1281 _this->screen->pixels = NULL;
1284 if (_this->screen && _this->screen->pixels) {
1285 free(_this->screen->pixels);
1286 _this->screen->pixels = NULL;
1289 /* Free Epoc resources */
1291 /* Disable events for me */
1292 if (Private->EPOC_WsEventStatus != KRequestPending)
1293 Private->EPOC_WsSession.EventReadyCancel();
1294 if (Private->EPOC_RedrawEventStatus != KRequestPending)
1295 Private->EPOC_WsSession.RedrawReadyCancel();
1297 #if defined(__WINS__) || defined(TEST_BM_DRAW)
1298 delete Private->EPOC_Bitmap;
1299 Private->EPOC_Bitmap = NULL;
1303 #ifndef SYMBIAN_CRYSTAL
1304 free(Private->EPOC_DrawDevice);
1307 if (Private->EPOC_WsWindow.WsHandle())
1308 Private->EPOC_WsWindow.Close();
1310 if (Private->EPOC_WsWindowGroup.WsHandle())
1311 Private->EPOC_WsWindowGroup.Close();
1313 delete Private->EPOC_WindowGc;
1314 Private->EPOC_WindowGc = NULL;
1316 delete Private->EPOC_WsScreen;
1317 Private->EPOC_WsScreen = NULL;
1319 if (Private->EPOC_WsSession.WsHandle())
1320 Private->EPOC_WsSession.Close();
1324 WMcursor *EPOC_CreateWMCursor(_THIS, Uint8* /*data*/, Uint8* /*mask*/, int /*w*/, int /*h*/, int /*hot_x*/, int /*hot_y*/)
1326 return (WMcursor *) 9210; // it's ok to return something unuseful but true
1329 void EPOC_FreeWMCursor(_THIS, WMcursor* /*cursor*/)
1331 /* Disable virtual cursor */
1332 HAL::Set(HAL::EMouseState, HAL::EMouseState_Invisible);
1333 Private->EPOC_WsSession.SetPointerCursorMode(EPointerCursorNone);
1336 int EPOC_ShowWMCursor(_THIS, WMcursor *cursor)
1339 if (cursor == (WMcursor *)9210) {
1340 /* Enable virtual cursor */
1341 Private->EPOC_WsSession.SetPointerCursorMode(EPointerCursorNormal);
1342 if (isCursorVisible)
1343 HAL::Set(HAL::EMouseState, HAL::EMouseState_Visible);
1345 Private->EPOC_WsSession.SetPointerCursorMode(EPointerCursorNone);
1348 /* Disable virtual cursor */
1349 HAL::Set(HAL::EMouseState, HAL::EMouseState_Invisible);
1350 Private->EPOC_WsSession.SetPointerCursorMode(EPointerCursorNone);