comparison src/video/epoc/SDL_epocvideo.cpp @ 173:83018110dce8

Added initial support for EPOC/Symbian OS (thanks Hannu!)
author Sam Lantinga <slouken@libsdl.org>
date Tue, 11 Sep 2001 20:38:49 +0000
parents
children e8157fcb3114
comparison
equal deleted inserted replaced
172:37e3ca9254c7 173:83018110dce8
1 /*
2 SDL - Simple DirectMedia Layer
3 Copyright (C) 1997, 1998, 1999, 2000, 2001 Sam Lantinga
4
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.
9
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.
14
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
18
19 Sam Lantinga
20 slouken@devolution.com
21 */
22
23 /*
24 SDL_epocvideo.cpp
25 Epoc based SDL video driver implementation
26
27 Epoc version by Hannu Viitala (hannu.j.viitala@mbnet.fi)
28 */
29
30
31
32 #include <stdlib.h>
33 #include <stdio.h>
34 #include <string.h>
35
36 extern "C" {
37 #include "SDL_error.h"
38 #include "SDL_timer.h"
39 #include "SDL_video.h"
40 #undef NULL
41 #include "SDL_pixels_c.h"
42 };
43
44 #include "SDL_epocvideo.h"
45 #include "SDL_epocevents_c.h"
46
47 #include <hal.h>
48 #include <coedef.h>
49
50 /* For debugging */
51
52 void RDebug_Print_b(char* error_str, void* param)
53 {
54 TBuf8<128> error8((TUint8*)error_str);
55 TBuf<128> error;
56 error.Copy(error8);
57 if (param) //!! Do not work if the parameter is really 0!!
58 RDebug::Print(error, param);
59 else
60 RDebug::Print(error);
61 }
62
63 extern "C" void RDebug_Print(char* error_str, void* param)
64 {
65 RDebug_Print_b(error_str, param);
66 }
67
68
69 int Debug_AvailMem2()
70 {
71 //User::CompressAllHeaps();
72 TMemoryInfoV1Buf membuf;
73 User::LeaveIfError(UserHal::MemoryInfo(membuf));
74 TMemoryInfoV1 minfo = membuf();
75 return(minfo.iFreeRamInBytes);
76 }
77
78 extern "C" int Debug_AvailMem()
79 {
80 return(Debug_AvailMem2());
81 }
82
83
84 extern "C" {
85
86 /* Initialization/Query functions */
87
88 static int EPOC_VideoInit(_THIS, SDL_PixelFormat *vformat);
89 static SDL_Rect **EPOC_ListModes(_THIS, SDL_PixelFormat *format, Uint32 flags);
90 static SDL_Surface *EPOC_SetVideoMode(_THIS, SDL_Surface *current, int width, int height, int bpp, Uint32 flags);
91 static int EPOC_SetColors(_THIS, int firstcolor, int ncolors,
92 SDL_Color *colors);
93 static void EPOC_VideoQuit(_THIS);
94
95 /* Hardware surface functions */
96
97 static int EPOC_AllocHWSurface(_THIS, SDL_Surface *surface);
98 static int EPOC_LockHWSurface(_THIS, SDL_Surface *surface);
99 static int EPOC_FlipHWSurface(_THIS, SDL_Surface *surface);
100 static void EPOC_UnlockHWSurface(_THIS, SDL_Surface *surface);
101 static void EPOC_FreeHWSurface(_THIS, SDL_Surface *surface);
102 static void EPOC_DirectUpdate(_THIS, int numrects, SDL_Rect *rects);
103
104 static int EPOC_Available(void);
105 static SDL_VideoDevice *EPOC_CreateDevice(int devindex);
106
107 /* Mouse functions */
108
109 static WMcursor *EPOC_CreateWMCursor(_THIS, Uint8 *data, Uint8 *mask, int w, int h, int hot_x, int hot_y);
110 static void EPOC_FreeWMCursor(_THIS, WMcursor *cursor);
111 static int EPOC_ShowWMCursor(_THIS, WMcursor *cursor);
112
113
114
115 /* !! Table for fast conversion from 8 bit to 12 bit */
116 static TUint16 EPOC_HWPalette_256_to_4k[256];
117
118 VideoBootStrap EPOC_bootstrap = {
119 "epoc", "EPOC system",
120 EPOC_Available, EPOC_CreateDevice
121 };
122
123 const TUint32 WindowClientHandle = 9210; //!!
124
125 /* Epoc video driver bootstrap functions */
126
127 static int EPOC_Available(void)
128 {
129 return 1; /* Always available */
130 }
131
132 static void EPOC_DeleteDevice(SDL_VideoDevice *device)
133 {
134 free(device->hidden);
135 free(device);
136 }
137
138 static SDL_VideoDevice *EPOC_CreateDevice(int devindex)
139 {
140 SDL_VideoDevice *device;
141
142 /* Allocate all variables that we free on delete */
143 device = (SDL_VideoDevice *)malloc(sizeof(SDL_VideoDevice));
144 if ( device ) {
145 memset(device, 0, (sizeof *device));
146 device->hidden = (struct SDL_PrivateVideoData *)
147 malloc((sizeof *device->hidden));
148 }
149 if ( (device == NULL) || (device->hidden == NULL) ) {
150 SDL_OutOfMemory();
151 if ( device ) {
152 free(device);
153 }
154 return(0);
155 }
156 memset(device->hidden, 0, (sizeof *device->hidden));
157
158 /* Set the function pointers */
159 device->VideoInit = EPOC_VideoInit;
160 device->ListModes = EPOC_ListModes;
161 device->SetVideoMode = EPOC_SetVideoMode;
162 device->SetColors = EPOC_SetColors;
163 device->UpdateRects = NULL;
164 device->VideoQuit = EPOC_VideoQuit;
165 device->AllocHWSurface = EPOC_AllocHWSurface;
166 device->CheckHWBlit = NULL;
167 device->FillHWRect = NULL;
168 device->SetHWColorKey = NULL;
169 device->SetHWAlpha = NULL;
170 device->LockHWSurface = EPOC_LockHWSurface;
171 device->UnlockHWSurface = EPOC_UnlockHWSurface;
172 device->FlipHWSurface = EPOC_FlipHWSurface;
173 device->FreeHWSurface = EPOC_FreeHWSurface;
174 device->SetIcon = NULL;
175 device->SetCaption = NULL;
176 device->GetWMInfo = NULL;
177 device->FreeWMCursor = EPOC_FreeWMCursor;
178 device->CreateWMCursor = EPOC_CreateWMCursor;
179 device->ShowWMCursor = EPOC_ShowWMCursor;
180 device->WarpWMCursor = NULL;
181 device->InitOSKeymap = EPOC_InitOSKeymap;
182 device->PumpEvents = EPOC_PumpEvents;
183 device->free = EPOC_DeleteDevice;
184
185 return device;
186 }
187
188
189 int GetBpp(TDisplayMode displaymode)
190 {
191 TInt numColors = TDisplayModeUtils::NumDisplayModeColors(displaymode);
192 TInt bitsPerPixel = 1;
193 for (TInt32 i = 2; i < numColors; i <<= 1, bitsPerPixel++);
194 return bitsPerPixel;
195 }
196
197 void ConstructWindowL(_THIS)
198 {
199 TInt error;
200
201 error = Private->EPOC_WsSession.Connect();
202 User::LeaveIfError(error);
203 Private->EPOC_WsScreen=new(ELeave) CWsScreenDevice(Private->EPOC_WsSession);
204 User::LeaveIfError(Private->EPOC_WsScreen->Construct());
205 User::LeaveIfError(Private->EPOC_WsScreen->CreateContext(Private->EPOC_WindowGc));
206
207 Private->EPOC_WsWindowGroup=RWindowGroup(Private->EPOC_WsSession);
208 User::LeaveIfError(Private->EPOC_WsWindowGroup.Construct(WindowClientHandle));
209 Private->EPOC_WsWindowGroup.SetOrdinalPosition(0);
210
211 //!!
212 TBuf<32> winGroupName;
213 winGroupName.Append(0);
214 winGroupName.Append(0);
215 winGroupName.Append(0);// uid
216 winGroupName.Append(0);
217 winGroupName.Append(_L("SDL")); // caption
218 winGroupName.Append(0);
219 winGroupName.Append(0); //doc name
220 Private->EPOC_WsWindowGroup.SetName(winGroupName); //!!
221
222 Private->EPOC_WsWindow=RWindow(Private->EPOC_WsSession);
223 User::LeaveIfError(Private->EPOC_WsWindow.Construct(Private->EPOC_WsWindowGroup,WindowClientHandle));
224 Private->EPOC_WsWindow.SetBackgroundColor(KRgbWhite);
225 Private->EPOC_WsWindow.Activate();
226 Private->EPOC_WsWindow.SetSize(Private->EPOC_WsScreen->SizeInPixels());
227 Private->EPOC_WsWindow.SetVisible(ETrue);
228
229 Private->EPOC_WsWindowGroupID = Private->EPOC_WsWindowGroup.Identifier();
230 Private->EPOC_IsWindowFocused = EFalse;
231 }
232
233
234 int EPOC_VideoInit(_THIS, SDL_PixelFormat *vformat)
235 {
236 // !!TODO:handle leave functions!
237
238 int i;
239
240 /* Initialize all variables that we clean on shutdown */
241
242 for ( i=0; i<SDL_NUMMODES; ++i ) {
243 Private->SDL_modelist[i] = (SDL_Rect *)malloc(sizeof(SDL_Rect));
244 Private->SDL_modelist[i]->x = Private->SDL_modelist[i]->y = 0;
245 }
246 /* Modes sorted largest to smallest !!TODO:sorting order??*/
247 Private->SDL_modelist[0]->w = 640; Private->SDL_modelist[0]->h = 200;
248 Private->SDL_modelist[1]->w = 320; Private->SDL_modelist[1]->h = 200;
249 Private->SDL_modelist[2]->w = 640; Private->SDL_modelist[2]->h = 400;
250 Private->SDL_modelist[3]->w = 640; Private->SDL_modelist[3]->h = 480;
251 Private->SDL_modelist[4] = NULL;
252
253 /* Construct Epoc window */
254
255 ConstructWindowL(_this);
256
257 /* Initialise Epoc frame buffer */
258
259 TDisplayMode displayMode = Private->EPOC_WsScreen->DisplayMode();
260
261 #ifndef __WINS__
262
263 TScreenInfoV01 screenInfo;
264 TPckg<TScreenInfoV01> sInfo(screenInfo);
265 UserSvr::ScreenInfo(sInfo);
266
267 Private->EPOC_ScreenSize = screenInfo.iScreenSize;
268 Private->EPOC_DisplayMode = displayMode;
269 Private->EPOC_HasFrameBuffer = screenInfo.iScreenAddressValid;
270 Private->EPOC_FrameBuffer = Private->EPOC_HasFrameBuffer ? (TUint8*) screenInfo.iScreenAddress : NULL;
271 Private->EPOC_BytesPerPixel = ((GetBpp(displayMode)-1) / 8) + 1;
272 Private->EPOC_BytesPerScanLine = screenInfo.iScreenSize.iWidth * Private->EPOC_BytesPerPixel;
273
274 /* It seems that in SA1100 machines for 8bpp displays there is a 512 palette table at the
275 * beginning of the frame buffer. E.g. Series 7 and Netbook.
276 * In 12 bpp machines the table has 16 entries.
277 */
278 if (Private->EPOC_HasFrameBuffer && GetBpp(displayMode) == 8)
279 Private->EPOC_FrameBuffer += 512;
280 if (Private->EPOC_HasFrameBuffer && GetBpp(displayMode) == 12)
281 Private->EPOC_FrameBuffer += 16 * 2;
282
283 #else /* defined __WINS__ */
284
285 /* Create bitmap, device and context for screen drawing */
286 Private->EPOC_ScreenSize = Private->EPOC_WsScreen->SizeInPixels();
287
288 Private->EPOC_Bitmap = new (ELeave) CWsBitmap(Private->EPOC_WsSession);
289 Private->EPOC_Bitmap->Create(Private->EPOC_ScreenSize, displayMode);
290
291 Private->EPOC_DisplayMode = displayMode;
292 Private->EPOC_HasFrameBuffer = ETrue;
293 Private->EPOC_FrameBuffer = NULL; /* Private->EPOC_Bitmap->DataAddress() can change any time */
294 Private->EPOC_BytesPerPixel = ((GetBpp(displayMode)-1) / 8) + 1;
295 Private->EPOC_BytesPerScanLine = Private->EPOC_WsScreen->SizeInPixels().iWidth * Private->EPOC_BytesPerPixel;
296
297 #endif /* __WINS__ */
298
299 /* The "best" video format should be returned to caller. */
300
301 vformat->BitsPerPixel = /*!!GetBpp(displayMode) */ 8;
302 vformat->BytesPerPixel = /*!!Private->EPOC_BytesPerPixel*/ 1;
303
304 /* Activate events for me */
305
306 Private->EPOC_WsEventStatus = KRequestPending;
307 Private->EPOC_WsSession.EventReady(&Private->EPOC_WsEventStatus);
308 Private->EPOC_RedrawEventStatus = KRequestPending;
309 Private->EPOC_WsSession.RedrawReady(&Private->EPOC_RedrawEventStatus);
310 Private->EPOC_WsWindow.PointerFilter(EPointerFilterDrag, 0);
311
312 Private->EPOC_ScreenOffset = 0;
313
314 //!! TODO: error handling
315 //if (ret != KErrNone)
316 // return(-1);
317 //else
318 return(0);
319 }
320
321
322 SDL_Rect **EPOC_ListModes(_THIS, SDL_PixelFormat *format, Uint32 flags)
323 {
324 if (format->BitsPerPixel == 12 || format->BitsPerPixel == 8)
325 return Private->SDL_modelist;
326 return NULL;
327 }
328
329 int EPOC_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color *colors)
330 {
331 for(int i = firstcolor; i < ncolors; i++) {
332 // 4k value: 000rgb
333 TUint16 color4K = 0;
334 color4K |= (colors[i].r & 0x0000f0) << 4;
335 color4K |= (colors[i].g & 0x0000f0);
336 color4K |= (colors[i].b & 0x0000f0) >> 4;
337 EPOC_HWPalette_256_to_4k[i] = color4K;
338 }
339 return(0);
340 }
341
342
343 SDL_Surface *EPOC_SetVideoMode(_THIS, SDL_Surface *current,
344 int width, int height, int bpp, Uint32 flags)
345 {
346 /* Check parameters */
347 if (!((width == 640 && height == 200 && bpp == 12) ||
348 (width == 640 && height == 400 && bpp == 12) ||
349 (width == 640 && height == 480 && bpp == 12) ||
350 (width == 320 && height == 200 && bpp == 12) ||
351 (width == 640 && height == 200 && bpp == 8) ||
352 (width == 640 && height == 400 && bpp == 8) ||
353 (width == 640 && height == 480 && bpp == 8) ||
354 (width == 320 && height == 200 && bpp == 8))) {
355 SDL_SetError("Requested video mode is not supported");
356 return NULL;
357 }
358
359 if (current && current->pixels) {
360 free(current->pixels);
361 current->pixels = NULL;
362 }
363 if ( ! SDL_ReallocFormat(current, bpp, 0, 0, 0, 0) ) {
364 return(NULL);
365 }
366
367 /* Set up the new mode framebuffer */
368 if (bpp == 8)
369 current->flags = (SDL_FULLSCREEN|SDL_SWSURFACE|SDL_PREALLOC|SDL_HWPALETTE);
370 else // 12 bpp
371 current->flags = (SDL_FULLSCREEN|SDL_SWSURFACE|SDL_PREALLOC);
372 current->w = width;
373 current->h = height;
374 int numBytesPerPixel = ((bpp-1)>>3) + 1;
375 current->pitch = numBytesPerPixel * width; // Number of bytes in scanline
376 current->pixels = malloc(width * height * numBytesPerPixel);
377 memset(current->pixels, 0, width * height * numBytesPerPixel);
378
379 /* Set the blit function */
380 _this->UpdateRects = EPOC_DirectUpdate;
381
382 /* Must buffer height be shrinked to screen by 2 ? */
383 if (current->h >= 400)
384 Private->EPOC_ShrinkedHeight = ETrue;
385
386 /* Centralize game window on device screen */
387 Private->EPOC_ScreenOffset = (Private->EPOC_ScreenSize.iWidth - current->w) / 2;
388
389 /* We're done */
390 return(current);
391 }
392
393 void RedrawWindowL(_THIS)
394 {
395 SDL_Rect fullScreen;
396 fullScreen.x = 0;
397 fullScreen.y = 0;
398 fullScreen.w = _this->screen->w;
399 fullScreen.h = _this->screen->h;
400
401 #ifdef __WINS__
402 TBitmapUtil lock(Private->EPOC_Bitmap);
403 lock.Begin(TPoint(0,0)); // Lock bitmap heap
404 Private->EPOC_WindowGc->Activate(Private->EPOC_WsWindow);
405 #endif
406
407 if (fullScreen.w < Private->EPOC_ScreenSize.iWidth
408 && fullScreen.w < Private->EPOC_ScreenSize.iWidth) {
409 /* Draw blue stripes background */
410 #ifdef __WINS__
411 TUint16* screenBuffer = (TUint16*)Private->EPOC_Bitmap->DataAddress();
412 #else
413 TUint16* screenBuffer = (TUint16*)Private->EPOC_FrameBuffer;
414 #endif
415 for (int y=0; y < Private->EPOC_ScreenSize.iHeight; y++) {
416 for (int x=0; x < Private->EPOC_ScreenSize.iWidth; x++) {
417 TUint16 color = ((x+y)>>1) & 0xf; /* Draw pattern */
418 *screenBuffer++ = color;
419 }
420 }
421 }
422
423
424 /* Tell the system that something has been drawn */
425 TRect rect = TRect(Private->EPOC_WsWindow.Size());
426 Private->EPOC_WsWindow.Invalidate(rect);
427
428 #ifdef __WINS__
429 Private->EPOC_WsWindow.BeginRedraw(rect);
430 Private->EPOC_WindowGc->BitBlt(TPoint(), Private->EPOC_Bitmap);
431 Private->EPOC_WsWindow.EndRedraw();
432 Private->EPOC_WindowGc->Deactivate();
433 lock.End(); // Unlock bitmap heap
434 Private->EPOC_WsSession.Flush();
435 #endif
436
437 /* Draw current buffer */
438 EPOC_DirectUpdate(_this, 1, &fullScreen);
439 }
440
441
442 /* We don't actually allow hardware surfaces other than the main one */
443 static int EPOC_AllocHWSurface(_THIS, SDL_Surface *surface)
444 {
445 return(-1);
446 }
447 static void EPOC_FreeHWSurface(_THIS, SDL_Surface *surface)
448 {
449 return;
450 }
451
452 static int EPOC_LockHWSurface(_THIS, SDL_Surface *surface)
453 {
454 return(0);
455 }
456 static void EPOC_UnlockHWSurface(_THIS, SDL_Surface *surface)
457 {
458 return;
459 }
460
461 static int EPOC_FlipHWSurface(_THIS, SDL_Surface *surface)
462 {
463 return(0);
464 }
465
466 static void EPOC_DirectUpdate(_THIS, int numrects, SDL_Rect *rects)
467 {
468 TInt focusWindowGroupId = Private->EPOC_WsSession.GetFocusWindowGroup();
469 if (focusWindowGroupId != Private->EPOC_WsWindowGroupID) {
470
471 /* Force focus window to redraw again for cleaning away SDL screen graphics */
472
473
474 TInt pos = Private->EPOC_WsWindowGroup.OrdinalPosition();
475 Private->EPOC_WsWindowGroup.SetOrdinalPosition(0, KMaxTInt);
476 TRect rect = TRect(Private->EPOC_WsWindow.Size());
477 Private->EPOC_WsWindow.Invalidate(rect);
478 Private->EPOC_WsWindowGroup.SetOrdinalPosition(pos, ECoeWinPriorityNormal);
479
480 /* If this is not the topmost window, wait here! Sleep for 1 second to give cpu to
481 multitasking and poll for being the topmost window.
482 */
483 while (Private->EPOC_WsSession.GetFocusWindowGroup() != Private->EPOC_WsWindowGroupID)
484 SDL_Delay(1000);
485
486 RedrawWindowL(_this);
487 }
488
489 TInt i;
490 TInt sourceNumBytesPerPixel = ((_this->screen->format->BitsPerPixel-1)>>3) + 1;
491 TInt targetNumBytesPerPixel = Private->EPOC_BytesPerPixel;
492 TInt fixedOffset = Private->EPOC_ScreenOffset;
493 TInt screenW = _this->screen->w;
494 TInt screenH = _this->screen->h;
495 TInt sourceScanlineLength = screenW;
496 if (Private->EPOC_ShrinkedHeight) { /* simulate 400 pixel height in 200 pixel screen */
497 sourceScanlineLength <<= 1;
498 screenH >>= 1;
499 }
500 TInt targetScanlineLength = Private->EPOC_ScreenSize.iWidth;
501 #ifdef __WINS__
502 TBitmapUtil lock(Private->EPOC_Bitmap);
503 lock.Begin(TPoint(0,0)); // Lock bitmap heap
504 Private->EPOC_WindowGc->Activate(Private->EPOC_WsWindow);
505 TUint16* screenBuffer = (TUint16*)Private->EPOC_Bitmap->DataAddress();
506 #else
507 TUint16* screenBuffer = (TUint16*)Private->EPOC_FrameBuffer;
508 #endif
509
510
511 /* Render the rectangles in the list */
512
513 for ( i=0; i < numrects; ++i ) {
514 SDL_Rect rect2;
515 const SDL_Rect& currentRect = rects[i];
516 rect2.x = currentRect.x;
517 rect2.y = currentRect.y;
518 rect2.w = currentRect.w;
519 rect2.h = currentRect.h;
520
521 if (rect2.w <= 0 || rect2.h <= 0) /* sanity check */
522 continue;
523
524 if (Private->EPOC_ShrinkedHeight) { /* simulate 400 pixel height in 200 pixel screen */
525 rect2.y >>= 1;
526 if (!(rect2.h >>= 1))
527 rect2.h = 1; // always at least 1 pixel height!
528 }
529
530 /* All variables are measured in pixels */
531
532 /* Check rects validity, i.e. upper and lower bounds */
533 TInt maxX = Min(screenW - 1, rect2.x + rect2.w - 1);
534 TInt maxY = Min(screenH - 1, rect2.y + rect2.h - 1);
535 if (maxX < 0 || maxY < 0) /* sanity check */
536 continue;
537 maxY = Min(maxY, 199);
538
539 TInt sourceRectWidth = maxX - rect2.x + 1;
540 TInt sourceRectWidthInBytes = sourceRectWidth * sourceNumBytesPerPixel;
541 TInt sourceRectHeight = maxY - rect2.y + 1;
542 TInt sourceStartOffset = rect2.x + rect2.y * sourceScanlineLength;
543 TInt targetStartOffset = fixedOffset + rect2.x + rect2.y * targetScanlineLength;
544
545 // !! Nokia9210 native mode: 12 bpp --> 12 bpp
546 if (_this->screen->format->BitsPerPixel == 12) {
547 TUint16* bitmapLine = (TUint16*)_this->screen->pixels + sourceStartOffset;
548 TUint16* screenMemory = screenBuffer + targetStartOffset;
549 for(TInt y = 0 ; y < sourceRectHeight ; y++) {
550 __ASSERT_DEBUG(screenMemory < (screenBuffer
551 + Private->EPOC_ScreenSize.iWidth * Private->EPOC_ScreenSize.iHeight),
552 User::Panic(_L("SDL"), KErrCorrupt));
553 __ASSERT_DEBUG(screenMemory >= screenBuffer,
554 User::Panic(_L("SDL"), KErrCorrupt));
555 __ASSERT_DEBUG(bitmapLine < ((TUint16*)_this->screen->pixels +
556 + (_this->screen->w * _this->screen->h)),
557 User::Panic(_L("SDL"), KErrCorrupt));
558 __ASSERT_DEBUG(bitmapLine >= (TUint16*)_this->screen->pixels,
559 User::Panic(_L("SDL"), KErrCorrupt));
560 Mem::Copy(screenMemory, bitmapLine, sourceRectWidthInBytes);
561 bitmapLine += sourceScanlineLength;
562 screenMemory += targetScanlineLength;
563 }
564 }
565 // !! 256 color paletted mode: 8 bpp --> 12 bpp
566 else {
567 TUint8* bitmapLine = (TUint8*)_this->screen->pixels + sourceStartOffset;
568 TUint16* screenMemory = screenBuffer + targetStartOffset;
569 for(TInt y = 0 ; y < sourceRectHeight ; y++) {
570 TUint8* bitmapPos = bitmapLine; /* 1 byte per pixel */
571 TUint16* screenMemoryLinePos = screenMemory; /* 2 bytes per pixel */
572 /* Convert each pixel from 256 palette to 4k color values */
573 for(TInt x = 0 ; x < sourceRectWidth ; x++) {
574 __ASSERT_DEBUG(screenMemoryLinePos < (screenBuffer
575 + (Private->EPOC_ScreenSize.iWidth * Private->EPOC_ScreenSize.iHeight)),
576 User::Panic(_L("SDL"), KErrCorrupt));
577 __ASSERT_DEBUG(screenMemoryLinePos >= screenBuffer,
578 User::Panic(_L("SDL"), KErrCorrupt));
579 __ASSERT_DEBUG(bitmapPos < ((TUint8*)_this->screen->pixels +
580 + (_this->screen->w * _this->screen->h)),
581 User::Panic(_L("SDL"), KErrCorrupt));
582 __ASSERT_DEBUG(bitmapPos >= (TUint8*)_this->screen->pixels,
583 User::Panic(_L("SDL"), KErrCorrupt));
584 *screenMemoryLinePos = EPOC_HWPalette_256_to_4k[*bitmapPos];
585 bitmapPos++;
586 screenMemoryLinePos++;
587 }
588 bitmapLine += sourceScanlineLength;
589 screenMemory += targetScanlineLength;
590 }
591 }
592
593 }
594
595 #ifdef __WINS__
596
597 TRect rect = TRect(Private->EPOC_WsWindow.Size());
598 Private->EPOC_WsWindow.Invalidate(rect);
599 Private->EPOC_WsWindow.BeginRedraw(rect);
600 Private->EPOC_WindowGc->BitBlt(TPoint(), Private->EPOC_Bitmap);
601 Private->EPOC_WsWindow.EndRedraw();
602 Private->EPOC_WindowGc->Deactivate();
603 lock.End(); // Unlock bitmap heap
604 Private->EPOC_WsSession.Flush();
605
606 #endif
607
608 /* Update virtual cursor */
609 //!!Private->EPOC_WsSession.SetPointerCursorPosition(Private->EPOC_WsSession.PointerCursorPosition());
610
611 return;
612 }
613
614
615 /* Note: If we are terminated, this could be called in the middle of
616 another SDL video routine -- notably UpdateRects.
617 */
618 void EPOC_VideoQuit(_THIS)
619 {
620 int i;
621
622 /* Free video mode lists */
623 for ( i=0; i<SDL_NUMMODES; ++i ) {
624 if ( Private->SDL_modelist[i] != NULL ) {
625 free(Private->SDL_modelist[i]);
626 Private->SDL_modelist[i] = NULL;
627 }
628 }
629
630 if ( _this->screen && (_this->screen->flags & SDL_HWSURFACE) ) {
631 /* Direct screen access, no memory buffer */
632 _this->screen->pixels = NULL;
633 }
634
635 if (_this->screen && _this->screen->pixels) {
636 free(_this->screen->pixels);
637 _this->screen->pixels = NULL;
638 }
639
640 /* Free Epoc resources */
641
642 /* Disable events for me */
643 if (Private->EPOC_WsEventStatus != KRequestPending)
644 Private->EPOC_WsSession.EventReadyCancel();
645 if (Private->EPOC_RedrawEventStatus != KRequestPending)
646 Private->EPOC_WsSession.RedrawReadyCancel();
647
648 #ifdef __WINS__
649 delete Private->EPOC_Bitmap;
650 Private->EPOC_Bitmap = NULL;
651 #endif
652
653 if (Private->EPOC_WsWindow.WsHandle())
654 Private->EPOC_WsWindow.Close();
655
656 if (Private->EPOC_WsWindowGroup.WsHandle())
657 Private->EPOC_WsWindowGroup.Close();
658
659 delete Private->EPOC_WindowGc;
660 Private->EPOC_WindowGc = NULL;
661
662 delete Private->EPOC_WsScreen;
663 Private->EPOC_WsScreen = NULL;
664
665 if (Private->EPOC_WsSession.WsHandle())
666 Private->EPOC_WsSession.Close();
667 }
668
669
670 WMcursor *EPOC_CreateWMCursor(_THIS, Uint8 *data, Uint8 *mask, int w, int h, int hot_x, int hot_y)
671 {
672 return (WMcursor *) 9210; // it's ok to return something unuseful but true
673 }
674
675 void EPOC_FreeWMCursor(_THIS, WMcursor *cursor)
676 {
677 /* Disable virtual cursor */
678 HAL::Set(HAL::EMouseState, HAL::EMouseState_Invisible);
679 Private->EPOC_WsSession.SetPointerCursorMode(EPointerCursorNone);
680 }
681
682 int EPOC_ShowWMCursor(_THIS, WMcursor *cursor)
683 {
684
685 if (cursor == (WMcursor *)9210) {
686 /* Enable virtual cursor */
687 HAL::Set(HAL::EMouseState, HAL::EMouseState_Visible);
688 Private->EPOC_WsSession.SetPointerCursorMode(EPointerCursorNormal);
689 }
690 else {
691 /* Disable virtual cursor */
692 HAL::Set(HAL::EMouseState, HAL::EMouseState_Invisible);
693 Private->EPOC_WsSession.SetPointerCursorMode(EPointerCursorNone);
694 }
695
696 return(1);
697 }
698
699 }; // extern "C"
700