Added S60 port. SDL-1.2
authorRyan C. Gordon <icculus@icculus.org>
Sun, 24 Jun 2007 18:26:35 +0000
branchSDL-1.2
changeset 3975e85e65aec22f
parent 3974 42578e98a295
child 3976 8582c6a5ca16
Added S60 port.
README.Symbian
docs.html
include/SDL_config.h.default
include/SDL_config.h.in
include/SDL_config_symbian.h
include/SDL_stdinc.h
include/SDL_thread.h
include/begin_code.h
src/SDL.c
src/audio/SDL_audio.c
src/audio/SDL_sysaudio.h
src/audio/symbian/SDL_epocaudio.cpp
src/audio/symbian/SDL_epocaudio.h
src/audio/symbian/streamplayer.cpp
src/audio/symbian/streamplayer.h
src/events/SDL_events.c
src/file/SDL_rwops.c
src/main/symbian/EKA1/SDL_main.cpp
src/main/symbian/EKA2/SDL_main.cpp
src/main/symbian/EKA2/sdlexe.cpp
src/main/symbian/EKA2/sdllib.cpp
src/main/symbian/EKA2/vectorbuffer.cpp
src/main/symbian/EKA2/vectorbuffer.h
src/stdlib/SDL_getenv.c
src/thread/SDL_thread_c.h
src/thread/symbian/SDL_sysmutex.cpp
src/thread/symbian/SDL_syssem.cpp
src/thread/symbian/SDL_systhread.cpp
src/thread/symbian/SDL_systhread_c.h
src/timer/symbian/SDL_systimer.cpp
src/video/symbian/EKA1/SDL_epocevents.cpp
src/video/symbian/EKA1/SDL_epocvideo.cpp
src/video/symbian/EKA1/SDL_epocvideo.h
src/video/symbian/EKA2/SDL_epocevents.cpp
src/video/symbian/EKA2/SDL_epocvideo.cpp
src/video/symbian/EKA2/SDL_epocvideo.h
src/video/symbian/EKA2/dsa.cpp
src/video/symbian/EKA2/dsa_new.cpp
src/video/symbian/EKA2/dsa_old.cpp
src/video/symbian/SDL_epocevents_c.h
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/README.Symbian	Sun Jun 24 18:26:35 2007 +0000
     1.3 @@ -0,0 +1,32 @@
     1.4 +==============================================================================
     1.5 +Using the Simple DirectMedia Layer with S60 3.x / Symbian 9.x
     1.6 +==============================================================================
     1.7 +
     1.8 +These instuctions are for people developing for S60 3.x. S60 3.x
     1.9 +uses Symbian OS so you need S60 SDK.
    1.10 +
    1.11 +extract "symbian.zip" into this folder.
    1.12 +
    1.13 +go to symbian folder
    1.14 +
    1.15 +bldmake bldfiles
    1.16 +abld build
    1.17 +
    1.18 +That produces WINSCW and ARMV5 versions of sdl.dll runtime library 
    1.19 +and sdl.lib for development. 
    1.20 +
    1.21 +Eaudiolib.lib and dll are generated as well, and must be delivered
    1.22 +along SDL as it uses it for audio.
    1.23 +
    1.24 +There are certain problems with GCC compiler when building for
    1.25 +target, it may compile or binaries are buggy - please use RVCT
    1.26 +compiler as it works and produces far more effient code.
    1.27 +
    1.28 +Its likely that SDL application should be integrated into S60 
    1.29 +work and behave well there. So there is CSDL class (sdlepocapi.h)
    1.30 +to make this easy. If you do porting from other system, then 
    1.31 +implement a S60 application and use CSDL class, they you may
    1.32 +not need to modify original SDL code at all!
    1.33 +
    1.34 +
    1.35 +
     2.1 --- a/docs.html	Thu Jun 21 18:48:13 2007 +0000
     2.2 +++ b/docs.html	Sun Jun 24 18:26:35 2007 +0000
     2.3 @@ -46,6 +46,9 @@
     2.4  <P>
     2.5  	Support for Nokia 9210 "EPOC" driver has been removed from the main SDL code.
     2.6  </P>
     2.7 +<P>
     2.8 +	Unofficial support for the S60/SymbianOS platform has been added.
     2.9 +</P>
    2.10  </BLOCKQUOTE>
    2.11  
    2.12  <H3> Unix Notes </H3>
     3.1 --- a/include/SDL_config.h.default	Thu Jun 21 18:48:13 2007 +0000
     3.2 +++ b/include/SDL_config.h.default	Sun Jun 24 18:26:35 2007 +0000
     3.3 @@ -32,6 +32,8 @@
     3.4  #include "SDL_config_macos.h"
     3.5  #elif defined(__MACOSX__)
     3.6  #include "SDL_config_macosx.h"
     3.7 +#elif defined(__SYMBIAN32__)
     3.8 +#include "SDL_config_symbian.h"  /* must be before win32! */
     3.9  #elif defined(__WIN32__)
    3.10  #include "SDL_config_win32.h"
    3.11  #elif defined(__OS2__)
     4.1 --- a/include/SDL_config.h.in	Thu Jun 21 18:48:13 2007 +0000
     4.2 +++ b/include/SDL_config.h.in	Sun Jun 24 18:26:35 2007 +0000
     4.3 @@ -224,7 +224,6 @@
     4.4  /* Enable various threading systems */
     4.5  #undef SDL_THREAD_BEOS
     4.6  #undef SDL_THREAD_DC
     4.7 -#undef SDL_THREAD_EPOC
     4.8  #undef SDL_THREAD_OS2
     4.9  #undef SDL_THREAD_PTH
    4.10  #undef SDL_THREAD_PTHREAD
    4.11 @@ -237,7 +236,6 @@
    4.12  #undef SDL_TIMER_BEOS
    4.13  #undef SDL_TIMER_DC
    4.14  #undef SDL_TIMER_DUMMY
    4.15 -#undef SDL_TIMER_EPOC
    4.16  #undef SDL_TIMER_MACOS
    4.17  #undef SDL_TIMER_MINT
    4.18  #undef SDL_TIMER_OS2
    4.19 @@ -255,7 +253,6 @@
    4.20  #undef SDL_VIDEO_DRIVER_DIRECTFB
    4.21  #undef SDL_VIDEO_DRIVER_DRAWSPROCKET
    4.22  #undef SDL_VIDEO_DRIVER_DUMMY
    4.23 -#undef SDL_VIDEO_DRIVER_EPOC
    4.24  #undef SDL_VIDEO_DRIVER_FBCON
    4.25  #undef SDL_VIDEO_DRIVER_GAPI
    4.26  #undef SDL_VIDEO_DRIVER_GEM
     5.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.2 +++ b/include/SDL_config_symbian.h	Sun Jun 24 18:26:35 2007 +0000
     5.3 @@ -0,0 +1,146 @@
     5.4 +/*
     5.5 +    SDL - Simple DirectMedia Layer
     5.6 +    Copyright (C) 1997-2006 Sam Lantinga
     5.7 +
     5.8 +    This library is free software; you can redistribute it and/or
     5.9 +    modify it under the terms of the GNU Lesser General Public
    5.10 +    License as published by the Free Software Foundation; either
    5.11 +    version 2.1 of the License, or (at your option) any later version.
    5.12 +
    5.13 +    This library is distributed in the hope that it will be useful,
    5.14 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
    5.15 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    5.16 +    Lesser General Public License for more details.
    5.17 +
    5.18 +    You should have received a copy of the GNU Lesser General Public
    5.19 +    License along with this library; if not, write to the Free Software
    5.20 +    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
    5.21 +
    5.22 +    Sam Lantinga
    5.23 +    slouken@libsdl.org
    5.24 +*/
    5.25 +
    5.26 +/*
    5.27 +
    5.28 +Symbian version Markus Mertama
    5.29 +
    5.30 +*/
    5.31 +
    5.32 +
    5.33 +#ifndef _SDL_CONFIG_SYMBIAN_H
    5.34 +#define _SDL_CONFIG_SYMBIAN_H
    5.35 +
    5.36 +#include "SDL_platform.h"
    5.37 +
    5.38 +/* This is the minimal configuration that can be used to build SDL */
    5.39 +
    5.40 +
    5.41 +#include <stdarg.h>
    5.42 +#include <stddef.h>
    5.43 +
    5.44 +
    5.45 +#ifdef __GCCE__
    5.46 +#define SYMBIAN32_GCCE
    5.47 +#endif
    5.48 +
    5.49 +#ifndef _SIZE_T_DEFINED
    5.50 +typedef unsigned int size_t;
    5.51 +#endif
    5.52 +
    5.53 +#ifndef _INTPTR_T_DECLARED
    5.54 +typedef unsigned int uintptr_t;
    5.55 +#endif 
    5.56 +
    5.57 +#ifndef _INT8_T_DECLARED
    5.58 +typedef signed char int8_t;
    5.59 +#endif 
    5.60 +
    5.61 +#ifndef _UINT8_T_DECLARED
    5.62 +typedef unsigned char uint8_t;
    5.63 +#endif
    5.64 +
    5.65 +#ifndef _INT16_T_DECLARED
    5.66 +typedef signed short int16_t;
    5.67 +#endif
    5.68 +
    5.69 +#ifndef _UINT16_T_DECLARED
    5.70 +typedef unsigned short uint16_t;
    5.71 +#endif
    5.72 +
    5.73 +#ifndef _INT32_T_DECLARED
    5.74 +typedef signed int int32_t;
    5.75 +#endif
    5.76 +
    5.77 +#ifndef _UINT32_T_DECLARED
    5.78 +typedef unsigned int uint32_t;
    5.79 +#endif
    5.80 +
    5.81 +#ifndef _INT64_T_DECLARED
    5.82 +typedef signed long long int64_t;
    5.83 +#endif
    5.84 +
    5.85 +#ifndef _UINT64_T_DECLARED
    5.86 +typedef unsigned long long uint64_t;
    5.87 +#endif
    5.88 +
    5.89 +#define SDL_AUDIO_DRIVER_EPOCAUDIO	1
    5.90 +
    5.91 +
    5.92 +/* Enable the stub cdrom driver (src/cdrom/dummy/\*.c) */
    5.93 +#define SDL_CDROM_DISABLED	1
    5.94 +
    5.95 +/* Enable the stub joystick driver (src/joystick/dummy/\*.c) */
    5.96 +#define SDL_JOYSTICK_DISABLED	1
    5.97 +
    5.98 +/* Enable the stub shared object loader (src/loadso/dummy/\*.c) */
    5.99 +#define SDL_LOADSO_DISABLED	1
   5.100 +
   5.101 +#define SDL_THREAD_SYMBIAN 1
   5.102 +
   5.103 +#define SDL_VIDEO_DRIVER_EPOC    1
   5.104 +
   5.105 +#define SDL_VIDEO_OPENGL 0
   5.106 +
   5.107 +#define SDL_HAS_64BIT_TYPE	1
   5.108 +
   5.109 +#define HAVE_LIBC	1
   5.110 +#define HAVE_STDIO_H 1
   5.111 +#define STDC_HEADERS 1
   5.112 +#define HAVE_STRING_H 1
   5.113 +#define HAVE_CTYPE_H 1
   5.114 +#define HAVE_MATH_H 1
   5.115 +
   5.116 +#define HAVE_MALLOC 1
   5.117 +#define HAVE_CALLOC 1
   5.118 +#define HAVE_REALLOC 1
   5.119 +#define HAVE_FREE 1
   5.120 +//#define HAVE_ALLOCA 1
   5.121 +#define HAVE_QSORT 1
   5.122 +#define HAVE_ABS 1
   5.123 +#define HAVE_MEMSET 1
   5.124 +#define HAVE_MEMCPY 1
   5.125 +#define HAVE_MEMMOVE 1
   5.126 +#define HAVE_MEMCMP 1
   5.127 +#define HAVE_STRLEN 1
   5.128 +#define HAVE__STRUPR 1
   5.129 +#define HAVE_STRCHR 1
   5.130 +#define HAVE_STRRCHR 1
   5.131 +#define HAVE_STRSTR 1
   5.132 +#define HAVE_ITOA 1
   5.133 +#define HAVE_STRTOL 1
   5.134 +#define HAVE_STRTOUL 1
   5.135 +#define HAVE_STRTOLL 1
   5.136 +#define HAVE_STRTOD 1
   5.137 +#define HAVE_ATOI 1
   5.138 +#define HAVE_ATOF 1
   5.139 +#define HAVE_STRCMP 1
   5.140 +#define HAVE_STRNCMP 1
   5.141 +#define HAVE__STRICMP 1
   5.142 +#define HAVE__STRNICMP 1
   5.143 +#define HAVE_SSCANF 1
   5.144 +#define HAVE_STDARG_H	1
   5.145 +#define HAVE_STDDEF_H	1
   5.146 +
   5.147 +
   5.148 +
   5.149 +#endif /* _SDL_CONFIG_SYMBIAN_H */
     6.1 --- a/include/SDL_stdinc.h	Thu Jun 21 18:48:13 2007 +0000
     6.2 +++ b/include/SDL_stdinc.h	Sun Jun 24 18:26:35 2007 +0000
     6.3 @@ -91,7 +91,9 @@
     6.4  
     6.5  #ifdef SDL_HAS_64BIT_TYPE
     6.6  typedef int64_t		Sint64;
     6.7 +#ifndef SYMBIAN32_GCCE
     6.8  typedef uint64_t	Uint64;
     6.9 +#endif
    6.10  #else
    6.11  /* This is really just a hack to prevent the compiler from complaining */
    6.12  typedef struct {
     7.1 --- a/include/SDL_thread.h	Thu Jun 21 18:48:13 2007 +0000
     7.2 +++ b/include/SDL_thread.h	Sun Jun 24 18:26:35 2007 +0000
     7.3 @@ -45,7 +45,7 @@
     7.4  typedef struct SDL_Thread SDL_Thread;
     7.5  
     7.6  /* Create a thread */
     7.7 -#if (defined(__WIN32__) && !defined(HAVE_LIBC)) || defined(__OS2__)
     7.8 +#if ((defined(__WIN32__) && !defined(HAVE_LIBC)) || defined(__OS2__)) &&  !defined(__SYMBIAN32__)
     7.9  /*
    7.10     We compile SDL into a DLL on OS/2. This means, that it's the DLL which
    7.11     creates a new thread for the calling process with the SDL_CreateThread()
     8.1 --- a/include/begin_code.h	Thu Jun 21 18:48:13 2007 +0000
     8.2 +++ b/include/begin_code.h	Sun Jun 24 18:26:35 2007 +0000
     8.3 @@ -83,11 +83,15 @@
     8.4  #endif
     8.5  #endif /* SDLCALL */
     8.6  
     8.7 -/* Removed DECLSPEC on Symbian OS because SDL cannot be a DLL in EPOC */
     8.8  #ifdef __SYMBIAN32__ 
     8.9 +#ifndef EKA2 
    8.10  #undef DECLSPEC
    8.11  #define DECLSPEC
    8.12 -#endif /* __SYMBIAN32__ */
    8.13 +#elif !defined(__WINS__)
    8.14 +#undef DECLSPEC
    8.15 +#define DECLSPEC __declspec(dllexport)
    8.16 +#endif //EKA2
    8.17 +#endif //__SYMBIAN32__
    8.18  
    8.19  /* Force structure packing at 4 byte alignment.
    8.20     This is necessary if the header is included in code which has structure
    8.21 @@ -116,7 +120,7 @@
    8.22  #if defined(_MSC_VER) || defined(__BORLANDC__) || \
    8.23      defined(__DMC__) || defined(__SC__) || \
    8.24      defined(__WATCOMC__) || defined(__LCC__) || \
    8.25 -    defined(__DECC)
    8.26 +    defined(__DECC) || defined(__EABI__)
    8.27  #ifndef __inline__
    8.28  #define __inline__	__inline
    8.29  #endif
     9.1 --- a/src/SDL.c	Thu Jun 21 18:48:13 2007 +0000
     9.2 +++ b/src/SDL.c	Sun Jun 24 18:26:35 2007 +0000
     9.3 @@ -323,7 +323,7 @@
     9.4  }
     9.5  #endif /* __WATCOMC__ */
     9.6  
     9.7 -#elif defined(__WIN32__)
     9.8 +#elif defined(__WIN32__)  && !defined(__SYMBIAN32__)
     9.9  
    9.10  #if !defined(HAVE_LIBC) || (defined(__WATCOMC__) && defined(BUILD_DLL))
    9.11  /* Need to include DllMain() on Watcom C for some reason.. */
    10.1 --- a/src/audio/SDL_audio.c	Thu Jun 21 18:48:13 2007 +0000
    10.2 +++ b/src/audio/SDL_audio.c	Sun Jun 24 18:26:35 2007 +0000
    10.3 @@ -107,6 +107,9 @@
    10.4  #if SDL_AUDIO_DRIVER_DART
    10.5  	&DART_bootstrap,
    10.6  #endif
    10.7 +#if SDL_AUDIO_DRIVER_EPOCAUDIO
    10.8 +	&EPOCAudio_bootstrap,
    10.9 +#endif
   10.10  	NULL
   10.11  };
   10.12  SDL_AudioDevice *current_audio = NULL;
   10.13 @@ -545,7 +548,7 @@
   10.14  	switch (audio->opened) {
   10.15  		case  1:
   10.16  			/* Start the audio thread */
   10.17 -#if (defined(__WIN32__) && !defined(_WIN32_WCE)) && !defined(HAVE_LIBC)
   10.18 +#if (defined(__WIN32__) && !defined(_WIN32_WCE)) && !defined(HAVE_LIBC) && !defined(__SYMBIAN32__)
   10.19  #undef SDL_CreateThread
   10.20  			audio->thread = SDL_CreateThread(SDL_RunAudio, audio, NULL, NULL);
   10.21  #else
    11.1 --- a/src/audio/SDL_sysaudio.h	Thu Jun 21 18:48:13 2007 +0000
    11.2 +++ b/src/audio/SDL_sysaudio.h	Sun Jun 24 18:26:35 2007 +0000
    11.3 @@ -171,6 +171,9 @@
    11.4  #if SDL_AUDIO_DRIVER_DART
    11.5  extern AudioBootStrap DART_bootstrap;
    11.6  #endif
    11.7 +#if SDL_AUDIO_DRIVER_EPOCAUDIO
    11.8 +extern AudioBootStrap EPOCAudio_bootstrap; 
    11.9 +#endif
   11.10  
   11.11  /* This is the current audio device */
   11.12  extern SDL_AudioDevice *current_audio;
    12.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    12.2 +++ b/src/audio/symbian/SDL_epocaudio.cpp	Sun Jun 24 18:26:35 2007 +0000
    12.3 @@ -0,0 +1,614 @@
    12.4 +/*
    12.5 +    SDL - Simple DirectMedia Layer
    12.6 +    Copyright (C) 1997, 1998, 1999, 2000, 2001  Sam Lantinga
    12.7 +
    12.8 +    This library is free software; you can redistribute it and/or
    12.9 +    modify it under the terms of the GNU Library General Public
   12.10 +    License as published by the Free Software Foundation; either
   12.11 +    version 2 of the License, or (at your option) any later version.
   12.12 +
   12.13 +    This library is distributed in the hope that it will be useful,
   12.14 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
   12.15 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   12.16 +    Library General Public License for more details.
   12.17 +
   12.18 +    You should have received a copy of the GNU Library General Public
   12.19 +    License along with this library; if not, write to the Free
   12.20 +    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   12.21 +
   12.22 +    Sam Lantinga
   12.23 +    slouken@devolution.com
   12.24 +*/
   12.25 +
   12.26 +/*
   12.27 +    SDL_epocaudio.cpp
   12.28 +    Epoc based SDL audio driver implementation
   12.29 +    
   12.30 +    Markus Mertama
   12.31 +*/
   12.32 +
   12.33 +#ifdef SAVE_RCSID
   12.34 +static char rcsid =
   12.35 + "@(#) $Id: SDL_epocaudio.c,v 0.0.0.0 2001/06/19 17:19:56 hercules Exp $";
   12.36 +#endif
   12.37 +
   12.38 +
   12.39 +#include <stdlib.h>
   12.40 +#include <stdio.h>
   12.41 +#include <string.h>
   12.42 +#include <errno.h>
   12.43 +#include <unistd.h>
   12.44 +#include <fcntl.h>
   12.45 +#include <signal.h>
   12.46 +#include <sys/time.h>
   12.47 +#include <sys/ioctl.h>
   12.48 +#include <sys/stat.h>
   12.49 +
   12.50 +#include "epoc_sdl.h"
   12.51 +
   12.52 +#include <e32hal.h>
   12.53 +
   12.54 +
   12.55 +extern "C" {
   12.56 +#include "SDL_audio.h"
   12.57 +#include "SDL_error.h"
   12.58 +#include "SDL_audiomem.h"
   12.59 +#include "SDL_audio_c.h"
   12.60 +#include "SDL_timer.h"
   12.61 +#include "SDL_audiodev_c.h"
   12.62 +}
   12.63 +
   12.64 +#include "SDL_epocaudio.h"
   12.65 +
   12.66 +#include "streamplayer.h"
   12.67 +
   12.68 +
   12.69 +//#define DEBUG_AUDIO
   12.70 +
   12.71 +
   12.72 +/* Audio driver functions */
   12.73 +
   12.74 +static int EPOC_OpenAudio(SDL_AudioDevice *thisdevice, SDL_AudioSpec *spec);
   12.75 +static void EPOC_WaitAudio(SDL_AudioDevice *thisdevice);
   12.76 +static void EPOC_PlayAudio(SDL_AudioDevice *thisdevice);
   12.77 +static Uint8 *EPOC_GetAudioBuf(SDL_AudioDevice *thisdevice);
   12.78 +static void EPOC_CloseAudio(SDL_AudioDevice *thisdevice);
   12.79 +static void EPOC_ThreadInit(SDL_AudioDevice *thisdevice);
   12.80 +
   12.81 +static int Audio_Available(void);
   12.82 +static SDL_AudioDevice *Audio_CreateDevice(int devindex);
   12.83 +static void Audio_DeleteDevice(SDL_AudioDevice *device);
   12.84 +
   12.85 +
   12.86 +//void sos_adump(SDL_AudioDevice* thisdevice, void* data, int len);
   12.87 +
   12.88 +#ifdef __WINS__
   12.89 +#define DODUMP
   12.90 +#endif
   12.91 +
   12.92 +#ifdef DODUMP
   12.93 +NONSHARABLE_CLASS(TDump)
   12.94 +	{
   12.95 +	public:
   12.96 +	TInt Open();
   12.97 +	void Close();
   12.98 +	void Dump(const TDesC8& aDes);
   12.99 +	private:
  12.100 +		RFile iFile;
  12.101 +    	RFs iFs; 
  12.102 +	};
  12.103 +	
  12.104 +TInt TDump::Open()
  12.105 +	{
  12.106 +	TInt err = iFs.Connect();
  12.107 +	if(err == KErrNone)
  12.108 +		{
  12.109 +#ifdef __WINS__
  12.110 +_LIT(target, "C:\\sdlau.raw");
  12.111 +#else
  12.112 +_LIT(target, "E:\\sdlau.raw");
  12.113 +#endif 
  12.114 +		err = iFile.Replace(iFs, target, EFileWrite);
  12.115 +		}
  12.116 +	return err;
  12.117 +	}
  12.118 +void TDump::Close()
  12.119 +	{
  12.120 +	iFile.Close();
  12.121 +	iFs.Close();
  12.122 +	}
  12.123 +void TDump::Dump(const TDesC8& aDes)
  12.124 +	{
  12.125 +	iFile.Write(aDes);
  12.126 +	}
  12.127 +#endif
  12.128 +
  12.129 +
  12.130 +NONSHARABLE_CLASS(CSimpleWait) : public CTimer
  12.131 +	{
  12.132 +	public:
  12.133 +		void Wait(TTimeIntervalMicroSeconds32 aWait);
  12.134 +		static CSimpleWait* NewL();
  12.135 +	private:
  12.136 +		CSimpleWait();
  12.137 +		void RunL();
  12.138 +	};
  12.139 +
  12.140 +
  12.141 +CSimpleWait* CSimpleWait::NewL()
  12.142 +	{
  12.143 +	CSimpleWait* wait = new (ELeave) CSimpleWait();
  12.144 +	CleanupStack::PushL(wait);
  12.145 +	wait->ConstructL();
  12.146 +	CleanupStack::Pop();
  12.147 +	return wait;
  12.148 +	}
  12.149 +
  12.150 +void CSimpleWait::Wait(TTimeIntervalMicroSeconds32 aWait)
  12.151 +	{
  12.152 +	After(aWait);
  12.153 +	CActiveScheduler::Start();
  12.154 +	}
  12.155 +	
  12.156 +CSimpleWait::CSimpleWait() : CTimer(CActive::EPriorityStandard)	
  12.157 +	{
  12.158 +	CActiveScheduler::Add(this);
  12.159 +	}
  12.160 +
  12.161 +void CSimpleWait::RunL()
  12.162 +	{
  12.163 +	CActiveScheduler::Stop();
  12.164 +	}
  12.165 +
  12.166 +const TInt KAudioBuffers(2);
  12.167 +	
  12.168 +
  12.169 +NONSHARABLE_CLASS(CEpocAudio) : public CBase, public MStreamObs, public MStreamProvider
  12.170 +    {
  12.171 +    public:
  12.172 +    	static void* NewL(TInt BufferSize, TInt aFill);
  12.173 +    	inline static CEpocAudio& Current(SDL_AudioDevice* thisdevice);
  12.174 +    	
  12.175 +    	static void Free(SDL_AudioDevice* thisdevice);
  12.176 + 		
  12.177 +    	void Wait();
  12.178 +    	void Play();
  12.179 +    //	void SetBuffer(const TDesC8& aBuffer);
  12.180 +    	void ThreadInitL(TAny* aDevice);
  12.181 +    	void Open(TInt iRate, TInt iChannels, TUint32 aType, TInt aBytes);
  12.182 +    	~CEpocAudio();
  12.183 +    	TUint8* Buffer();
  12.184 +    	TBool SetPause(TBool aPause);
  12.185 +    #ifdef DODUMP
  12.186 +    	void Dump(const TDesC8& aBuf) {iDump.Dump(aBuf);}
  12.187 +    #endif
  12.188 +    private:
  12.189 +    	CEpocAudio(TInt aBufferSize);
  12.190 +    	void Complete(TInt aState, TInt aError);
  12.191 +    	TPtrC8 Data();
  12.192 +    	void ConstructL(TInt aFill);
  12.193 +    private:
  12.194 +    	TInt iBufferSize;
  12.195 +    	CStreamPlayer* iPlayer;
  12.196 +    	TInt iBufferRate;
  12.197 +    	TInt iRate;
  12.198 +    	TInt iChannels;
  12.199 +    	TUint32 iType;
  12.200 +    	TInt iPosition;
  12.201 +    	TThreadId iTid;
  12.202 +    	TUint8* iAudioPtr;
  12.203 +    	TUint8* iBuffer;
  12.204 +    //	TTimeIntervalMicroSeconds iStart;
  12.205 +    	TTime iStart;
  12.206 +    	TInt iTune;
  12.207 +    	CSimpleWait* iWait;
  12.208 +    #ifdef DODUMP
  12.209 +    	TDump iDump;
  12.210 +    #endif
  12.211 +    };
  12.212 +
  12.213 +inline CEpocAudio& CEpocAudio::Current(SDL_AudioDevice* thisdevice)
  12.214 +	{
  12.215 +	return *static_cast<CEpocAudio*>((void*)thisdevice->hidden);
  12.216 +	}
  12.217 +	
  12.218 +/*
  12.219 +
  12.220 +TBool EndSc(TAny*)
  12.221 +	{	
  12.222 +	CActiveScheduler::Stop();
  12.223 +	}
  12.224 +	
  12.225 +LOCAL_C void CleanScL()
  12.226 +	{
  12.227 +	CIdle* d = CIdle::NewLC(CActive:::EPriorityIdle);
  12.228 +	d->Start(TCallBack(EndSc));
  12.229 +	CActiveScheduler::Start();
  12.230 +	
  12.231 +	}
  12.232 +*/
  12.233 +	
  12.234 +void CEpocAudio::Free(SDL_AudioDevice* thisdevice)
  12.235 +	{
  12.236 +    CEpocAudio* ea = static_cast<CEpocAudio*>((void*)thisdevice->hidden);
  12.237 +    if(ea)
  12.238 +    	{
  12.239 +		ASSERT(ea->iTid == RThread().Id());
  12.240 +    	delete ea;
  12.241 +    	thisdevice->hidden = NULL;	
  12.242 +   
  12.243 +    	CActiveScheduler* as =  CActiveScheduler::Current();
  12.244 +    	ASSERT(as->StackDepth() == 0);    	
  12.245 +    	delete as;
  12.246 +    	CActiveScheduler::Install(NULL);
  12.247 +    	}
  12.248 +    ASSERT(thisdevice->hidden == NULL);
  12.249 +	}
  12.250 +	
  12.251 +CEpocAudio::CEpocAudio(TInt aBufferSize) : iBufferSize(aBufferSize), iPosition(-1) 
  12.252 +	{
  12.253 +	}
  12.254 +
  12.255 +void* CEpocAudio::NewL(TInt aBufferSize, TInt aFill)
  12.256 +	{
  12.257 +	CEpocAudio* eAudioLib = new (ELeave) CEpocAudio(aBufferSize);
  12.258 +	CleanupStack::PushL(eAudioLib);
  12.259 +	eAudioLib->ConstructL(aFill);
  12.260 +	CleanupStack::Pop();
  12.261 +	return eAudioLib;
  12.262 +	}
  12.263 +	
  12.264 +void CEpocAudio::ConstructL(TInt aFill)
  12.265 +	{
  12.266 +	iBuffer = (TUint8*) User::AllocL(KAudioBuffers * iBufferSize);
  12.267 +	memset(iBuffer, aFill, KAudioBuffers * iBufferSize);
  12.268 +	iAudioPtr = iBuffer;
  12.269 +	}
  12.270 +
  12.271 +
  12.272 +TBool CEpocAudio::SetPause(TBool aPause)
  12.273 +	{
  12.274 +	if(aPause && iPosition >= 0)
  12.275 +		{
  12.276 +		iPosition = -1;
  12.277 +		if(iPlayer != NULL)
  12.278 +			iPlayer->Stop();
  12.279 +		}
  12.280 +	if(!aPause && iPosition < 0)
  12.281 +		{
  12.282 +		iPosition = 0;
  12.283 +		if(iPlayer != NULL)
  12.284 +			iPlayer->Start();
  12.285 +		}
  12.286 +	return iPosition < 0;
  12.287 +	}
  12.288 +	
  12.289 +void CEpocAudio::ThreadInitL(TAny* aDevice)
  12.290 +	{
  12.291 +	iTid = RThread().Id(); 
  12.292 +	CActiveScheduler* as =  new (ELeave) CActiveScheduler();
  12.293 +    CActiveScheduler::Install(as);
  12.294 +    
  12.295 +    EpocSdlEnv::AppendCleanupItem(TSdlCleanupItem((TSdlCleanupOperation)EPOC_CloseAudio, aDevice));
  12.296 +   
  12.297 +    iWait = CSimpleWait::NewL();
  12.298 +   
  12.299 +    iPlayer = new (ELeave) CStreamPlayer(*this, *this);
  12.300 +    iPlayer->ConstructL();	
  12.301 +    iPlayer->OpenStream(iRate, iChannels, iType);
  12.302 +    
  12.303 +    #ifdef DODUMP
  12.304 +    User::LeaveIfError(iDump.Open());
  12.305 +    #endif
  12.306 +	}
  12.307 +	
  12.308 +	
  12.309 +	
  12.310 +TUint8* CEpocAudio::Buffer()
  12.311 +	{
  12.312 +	iStart.UniversalTime();
  12.313 +//	iStart = iPlayer->Position();		
  12.314 +	return iAudioPtr;
  12.315 +
  12.316 +	}
  12.317 +	
  12.318 +CEpocAudio::~CEpocAudio()
  12.319 +	{
  12.320 +	if(iWait != NULL)
  12.321 +		iWait->Cancel();
  12.322 +	delete iWait; 
  12.323 +	if(iPlayer != NULL)
  12.324 +		iPlayer->Close();
  12.325 +	delete iPlayer;
  12.326 +	delete iBuffer;
  12.327 +	}
  12.328 +	
  12.329 +void CEpocAudio::Complete(TInt aState, TInt aError)
  12.330 +	{
  12.331 +	if(aState == MStreamObs::EClose)
  12.332 +		{
  12.333 +		}
  12.334 +	if(iPlayer->Closed())
  12.335 +		return;
  12.336 +	switch(aError)
  12.337 +		{
  12.338 +		case KErrUnderflow:
  12.339 +		case KErrInUse:
  12.340 +			iPlayer->Start();
  12.341 +			break;
  12.342 +		case KErrAbort:
  12.343 +			iPlayer->Open();
  12.344 +		}
  12.345 +	}
  12.346 +	
  12.347 +
  12.348 +void sos_adump(SDL_AudioDevice* thisdevice, void* data, int len)
  12.349 +	{
  12.350 +#ifdef DODUMP
  12.351 +	const TPtrC8 buf((TUint8*)data, len);
  12.352 +	CEpocAudio::Current(thisdevice).Dump(buf);
  12.353 +#endif
  12.354 +	}
  12.355 +
  12.356 +const TInt KClip(256);
  12.357 +	
  12.358 +TPtrC8 CEpocAudio::Data()
  12.359 +	{
  12.360 +	if(iPosition < 0)
  12.361 +		return KNullDesC8();
  12.362 +	
  12.363 +	TPtrC8 data(iAudioPtr + iPosition, KClip);
  12.364 +	
  12.365 +#ifdef DODUMP
  12.366 +	iDump.Dump(data);
  12.367 +#endif
  12.368 +	
  12.369 +	iPosition += KClip;
  12.370 +	if(iPosition >= iBufferSize) 
  12.371 +		{
  12.372 +		
  12.373 +/*		if(iAudioPtr == iBuffer)
  12.374 +			iAudioPtr = iBuffer + iBufferSize;
  12.375 +		else
  12.376 +			iAudioPtr = iBuffer;
  12.377 +*/		
  12.378 +		iAudioPtr += iBufferSize;
  12.379 +		
  12.380 +		if((iAudioPtr - iBuffer) >= KAudioBuffers * iBufferSize)
  12.381 +			iAudioPtr = iBuffer;
  12.382 +		
  12.383 +		iPosition = -1;
  12.384 +		if(iWait->IsActive())
  12.385 +			{
  12.386 +			iWait->Cancel();
  12.387 +			CActiveScheduler::Stop();
  12.388 +			}
  12.389 +		}
  12.390 +	return data;
  12.391 +	}
  12.392 +		
  12.393 +
  12.394 +
  12.395 +	
  12.396 +void CEpocAudio::Play()
  12.397 +	{
  12.398 +	iPosition = 0;
  12.399 +	}
  12.400 +
  12.401 +void CEpocAudio::Wait()
  12.402 +	{
  12.403 +	if(iPosition >= 0 /*&& iPlayer->Playing()*/)
  12.404 +		{
  12.405 +		const TInt64 bufMs = TInt64(iBufferSize - KClip) * TInt64(1000000);
  12.406 +		const TInt64 specTime =  bufMs / TInt64(iRate * iChannels * 2);
  12.407 +		iWait->After(specTime);
  12.408 +		
  12.409 +		CActiveScheduler::Start();
  12.410 +		TTime end;
  12.411 +		end.UniversalTime();
  12.412 +		const TTimeIntervalMicroSeconds delta = end.MicroSecondsFrom(iStart);
  12.413 +	
  12.414 +	
  12.415 +//		const TTimeIntervalMicroSeconds end = iPlayer->Position();
  12.416 +		
  12.417 +		
  12.418 +	
  12.419 +		
  12.420 +		const TInt diff = specTime - delta.Int64();
  12.421 +		
  12.422 +		if(diff > 0 && diff < 200000)
  12.423 +			{
  12.424 +			User::After(diff);
  12.425 +			}
  12.426 +		
  12.427 +		}
  12.428 +	else
  12.429 +		{
  12.430 +	User::After(10000); 
  12.431 +//	iWait->Wait(10000); //just give some time...	
  12.432 +		}	
  12.433 +	}
  12.434 +	
  12.435 +void CEpocAudio::Open(TInt aRate, TInt aChannels, TUint32 aType, TInt aBytes)	
  12.436 +	{
  12.437 +	iRate = aRate;
  12.438 +	iChannels = aChannels;
  12.439 +	iType = aType;
  12.440 +    iBufferRate = iRate * iChannels * aBytes; //1/x
  12.441 +	}
  12.442 +	
  12.443 +
  12.444 +/* Audio driver bootstrap functions */
  12.445 +
  12.446 +AudioBootStrap EPOCAudio_bootstrap = {
  12.447 +	"epoc\0\0\0",
  12.448 +	"EPOC streaming audio\0\0\0",
  12.449 +	Audio_Available,
  12.450 +	Audio_CreateDevice
  12.451 +};
  12.452 +
  12.453 +
  12.454 +static SDL_AudioDevice *Audio_CreateDevice(int /*devindex*/)
  12.455 +{
  12.456 +	SDL_AudioDevice *thisdevice;
  12.457 +
  12.458 +	/* Initialize all variables that we clean on shutdown */
  12.459 +	thisdevice = (SDL_AudioDevice *)malloc(sizeof(SDL_AudioDevice));
  12.460 +	if ( thisdevice ) {
  12.461 +		memset(thisdevice, 0, (sizeof *thisdevice));
  12.462 +		thisdevice->hidden = NULL; /*(struct SDL_PrivateAudioData *)
  12.463 +			 malloc((sizeof thisdevice->hidden)); */
  12.464 +	}
  12.465 +	if ( (thisdevice == NULL) /*|| (thisdevice->hidden == NULL) */) {
  12.466 +		SDL_OutOfMemory();
  12.467 +		if ( thisdevice ) {
  12.468 +			free(thisdevice);
  12.469 +		}
  12.470 +		return(0);
  12.471 +	}
  12.472 +//	memset(thisdevice->hidden, 0, (sizeof *thisdevice->hidden));
  12.473 +
  12.474 +	/* Set the function pointers */
  12.475 +	thisdevice->OpenAudio = EPOC_OpenAudio;
  12.476 +	thisdevice->WaitAudio = EPOC_WaitAudio;
  12.477 +	thisdevice->PlayAudio = EPOC_PlayAudio;
  12.478 +	thisdevice->GetAudioBuf = EPOC_GetAudioBuf;
  12.479 +	thisdevice->CloseAudio = EPOC_CloseAudio;
  12.480 +    thisdevice->ThreadInit = EPOC_ThreadInit;
  12.481 +	thisdevice->free = Audio_DeleteDevice;
  12.482 +
  12.483 +	return thisdevice;
  12.484 +}
  12.485 +
  12.486 +
  12.487 +static void Audio_DeleteDevice(SDL_AudioDevice *device)
  12.488 +    {
  12.489 +	//free(device->hidden);
  12.490 +	free(device);
  12.491 +    }
  12.492 +
  12.493 +static int Audio_Available(void)
  12.494 +{
  12.495 +	return(1); // Audio stream modules should be always there!
  12.496 +}
  12.497 +
  12.498 +
  12.499 +static int EPOC_OpenAudio(SDL_AudioDevice *thisdevice, SDL_AudioSpec *spec)
  12.500 +{
  12.501 +	SDL_TRACE("SDL:EPOC_OpenAudio");
  12.502 +
  12.503 +	
  12.504 +	TUint32 type = KMMFFourCCCodePCM16;
  12.505 +	TInt bytes = 2;
  12.506 +	
  12.507 +	switch(spec->format)
  12.508 +		{
  12.509 +		case AUDIO_U16LSB: 
  12.510 +			type = KMMFFourCCCodePCMU16; 
  12.511 +			break;
  12.512 +		case AUDIO_S16LSB: 
  12.513 +			type = KMMFFourCCCodePCM16; 
  12.514 +			break;
  12.515 +		case AUDIO_U16MSB: 
  12.516 +			type = KMMFFourCCCodePCMU16B; 
  12.517 +			break;
  12.518 +		case AUDIO_S16MSB: 
  12.519 +			type = KMMFFourCCCodePCM16B; 
  12.520 +			break; 
  12.521 +			//8 bit not supported!
  12.522 +		case AUDIO_U8: 
  12.523 +		case AUDIO_S8:
  12.524 +		default:
  12.525 +			spec->format = AUDIO_S16LSB;
  12.526 +		};
  12.527 +	
  12.528 +
  12.529 +	
  12.530 +	if(spec->channels > 2)
  12.531 +		spec->channels = 2;
  12.532 +	
  12.533 +	spec->freq = CStreamPlayer::ClosestSupportedRate(spec->freq);
  12.534 +	
  12.535 +
  12.536 +	/* Allocate mixing buffer */
  12.537 +	const TInt buflen = spec->size;// * bytes * spec->channels;
  12.538 +//	audiobuf = NULL;
  12.539 +    
  12.540 +    TRAPD(err, thisdevice->hidden = static_cast<SDL_PrivateAudioData*>(CEpocAudio::NewL(buflen, spec->silence)));
  12.541 +    if(err != KErrNone)
  12.542 +        return -1;
  12.543 +
  12.544 +	CEpocAudio::Current(thisdevice).Open(spec->freq, spec->channels, type, bytes);
  12.545 +	
  12.546 +	CEpocAudio::Current(thisdevice).SetPause(ETrue);
  12.547 +	
  12.548 +   // isSDLAudioPaused = 1;
  12.549 +
  12.550 +    thisdevice->enabled = 0; /* enable only after audio engine has been initialized!*/
  12.551 +
  12.552 +	/* We're ready to rock and roll. :-) */
  12.553 +	return(0);
  12.554 +}
  12.555 +
  12.556 +
  12.557 +static void EPOC_CloseAudio(SDL_AudioDevice* thisdevice)
  12.558 +    {
  12.559 +#ifdef DEBUG_AUDIO
  12.560 +    SDL_TRACE("Close audio\n");
  12.561 +#endif
  12.562 +
  12.563 +	CEpocAudio::Free(thisdevice);
  12.564 +	}
  12.565 +
  12.566 +
  12.567 +static void EPOC_ThreadInit(SDL_AudioDevice *thisdevice)
  12.568 +    {
  12.569 +	SDL_TRACE("SDL:EPOC_ThreadInit");
  12.570 +    CEpocAudio::Current(thisdevice).ThreadInitL(thisdevice);
  12.571 +    RThread().SetPriority(EPriorityMore);
  12.572 +    thisdevice->enabled = 1;
  12.573 +    }
  12.574 +
  12.575 +/* This function waits until it is possible to write a full sound buffer */
  12.576 +static void EPOC_WaitAudio(SDL_AudioDevice* thisdevice)
  12.577 +{
  12.578 +#ifdef DEBUG_AUDIO
  12.579 +    SDL_TRACE1("wait %d audio\n", CEpocAudio::AudioLib().StreamPlayer(KSfxChannel).SyncTime());
  12.580 +    TInt tics = User::TickCount();
  12.581 +#endif
  12.582 +
  12.583 +	CEpocAudio::Current(thisdevice).Wait();
  12.584 +
  12.585 +#ifdef DEBUG_AUDIO
  12.586 +    TInt ntics =  User::TickCount() - tics;
  12.587 +    SDL_TRACE1("audio waited %d\n", ntics);
  12.588 +    SDL_TRACE1("audio at %d\n", tics);
  12.589 +#endif
  12.590 +}
  12.591 +
  12.592 +
  12.593 + 
  12.594 +static void EPOC_PlayAudio(SDL_AudioDevice* thisdevice)
  12.595 +	{
  12.596 + 	if(CEpocAudio::Current(thisdevice).SetPause(SDL_GetAudioStatus() == SDL_AUDIO_PAUSED))
  12.597 + 		SDL_Delay(500); //hold on the busy loop
  12.598 + 	else
  12.599 + 		CEpocAudio::Current(thisdevice).Play();
  12.600 +
  12.601 +#ifdef DEBUG_AUDIO
  12.602 +    SDL_TRACE("buffer has audio data\n");
  12.603 +#endif
  12.604 +
  12.605 +	
  12.606 +#ifdef DEBUG_AUDIO
  12.607 +	SDL_TRACE1("Wrote %d bytes of audio data\n", buflen);
  12.608 +#endif
  12.609 +}
  12.610 +
  12.611 +static Uint8 *EPOC_GetAudioBuf(SDL_AudioDevice* thisdevice)
  12.612 +	{
  12.613 +	return CEpocAudio::Current(thisdevice).Buffer();
  12.614 +	}
  12.615 +
  12.616 +
  12.617 +
    13.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    13.2 +++ b/src/audio/symbian/SDL_epocaudio.h	Sun Jun 24 18:26:35 2007 +0000
    13.3 @@ -0,0 +1,37 @@
    13.4 +/*
    13.5 +    SDL - Simple DirectMedia Layer
    13.6 +    Copyright (C) 1997, 1998, 1999, 2000, 2001  Sam Lantinga
    13.7 +
    13.8 +    This library is free software; you can redistribute it and/or
    13.9 +    modify it under the terms of the GNU Library General Public
   13.10 +    License as published by the Free Software Foundation; either
   13.11 +    version 2 of the License, or (at your option) any later version.
   13.12 +
   13.13 +    This library is distributed in the hope that it will be useful,
   13.14 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
   13.15 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   13.16 +    Library General Public License for more details.
   13.17 +
   13.18 +    You should have received a copy of the GNU Library General Public
   13.19 +    License along with this library; if not, write to the Free
   13.20 +    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   13.21 +
   13.22 +    Sam Lantinga
   13.23 +    slouken@devolution.com
   13.24 +*/
   13.25 +
   13.26 +
   13.27 +#ifdef SAVE_RCSID
   13.28 +static char rcsid =
   13.29 + "@(#) $Id: SDL_epocaudio.h,v 1.1.2.2 2001/02/10 07:20:03 hercules Exp $";
   13.30 +#endif
   13.31 +
   13.32 +#ifndef _SDL_EPOCAUDIO_H
   13.33 +#define _SDL_EPOCAUDIO_H
   13.34 +
   13.35 +extern "C" {
   13.36 +#include "SDL_sysaudio.h"
   13.37 +}
   13.38 +
   13.39 +
   13.40 +#endif /* _SDL_EPOCAUDIO_H */
    14.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    14.2 +++ b/src/audio/symbian/streamplayer.cpp	Sun Jun 24 18:26:35 2007 +0000
    14.3 @@ -0,0 +1,279 @@
    14.4 +#include "streamplayer.h"
    14.5 +#include<mda/common/audio.h>
    14.6 +
    14.7 +
    14.8 +
    14.9 +const TInt KMaxVolume(256);
   14.10 +
   14.11 +LOCAL_C TInt GetSampleRate(TInt aRate)
   14.12 +    {
   14.13 +    switch(aRate)
   14.14 +        {
   14.15 +        case 8000: return TMdaAudioDataSettings::ESampleRate8000Hz;
   14.16 +        case 11025: return TMdaAudioDataSettings::ESampleRate11025Hz;
   14.17 +        case 12000: return TMdaAudioDataSettings::ESampleRate12000Hz;
   14.18 +        case 16000: return TMdaAudioDataSettings::ESampleRate16000Hz;
   14.19 +        case 22050: return TMdaAudioDataSettings::ESampleRate22050Hz;
   14.20 +        case 24000: return TMdaAudioDataSettings::ESampleRate24000Hz;
   14.21 +        case 32000: return TMdaAudioDataSettings::ESampleRate32000Hz;
   14.22 +        case 44100: return TMdaAudioDataSettings::ESampleRate44100Hz;
   14.23 +        case 48000: return TMdaAudioDataSettings::ESampleRate48000Hz;
   14.24 +        case 96000: return TMdaAudioDataSettings::ESampleRate96000Hz;
   14.25 +        case 64000: return TMdaAudioDataSettings::ESampleRate64000Hz;
   14.26 +        }
   14.27 +    return KErrNotFound;
   14.28 +    }
   14.29 +
   14.30 +LOCAL_C TInt GetChannels(TInt aChannels)
   14.31 +    {
   14.32 +    switch(aChannels)
   14.33 +        {
   14.34 +        case 1: return TMdaAudioDataSettings::EChannelsMono;
   14.35 +        case 2: return TMdaAudioDataSettings::EChannelsStereo;
   14.36 +        }
   14.37 +    return KErrNotFound;
   14.38 +    }
   14.39 +    
   14.40 +TInt CStreamPlayer::ClosestSupportedRate(TInt aRate)
   14.41 +	{
   14.42 +	if(aRate > 96000)
   14.43 +		return 96000;
   14.44 +	TInt rate = aRate;
   14.45 +	while(GetSampleRate(rate) == KErrNotFound)
   14.46 +		{
   14.47 +		++rate;
   14.48 +		}
   14.49 +	return rate;
   14.50 +	}
   14.51 +
   14.52 +CStreamPlayer::CStreamPlayer(MStreamProvider& aProvider,  MStreamObs& aObs) :
   14.53 + iProvider(aProvider), iObs(aObs), iVolume(KMaxVolume)
   14.54 +	{	
   14.55 +	}
   14.56 +		
   14.57 +CStreamPlayer::~CStreamPlayer()
   14.58 +	{
   14.59 +	iState |= EDied;
   14.60 +	if(iState & EInited)
   14.61 +		Close();
   14.62 +	User::After(100000); //wait buffer to be flushed
   14.63 +	ASSERT(iPtr.Length() == 0);
   14.64 +	delete iStream;
   14.65 +	}
   14.66 +		
   14.67 +		
   14.68 +void CStreamPlayer::ConstructL()
   14.69 +	{
   14.70 +	iStream = CMdaAudioOutputStream::NewL(*this, EMdaPriorityMax);
   14.71 +	iSilence.SetMax();
   14.72 +	iSilence.FillZ();
   14.73 +	}
   14.74 +		
   14.75 +
   14.76 +TInt CStreamPlayer::OpenStream(TInt aRate, TInt aChannels, TUint32 aType)
   14.77 +	{
   14.78 +	Close();
   14.79 +	
   14.80 +	iType = aType;
   14.81 +	
   14.82 +	iRate = GetSampleRate(aRate);
   14.83 +	if(iRate == KErrNotFound)
   14.84 +		return KErrNotSupported;
   14.85 +	
   14.86 +	iChannels = GetChannels(aChannels);
   14.87 +	if(iChannels == KErrNotFound)
   14.88 +		return KErrNotSupported;
   14.89 +	
   14.90 +	Open();
   14.91 +    
   14.92 +    return KErrNone;
   14.93 +	}
   14.94 +
   14.95 +
   14.96 +TInt CStreamPlayer::MaxVolume() const
   14.97 +	{
   14.98 +	return KMaxVolume;
   14.99 +	}
  14.100 +
  14.101 +void CStreamPlayer::SetVolume(TInt aNew)
  14.102 +    {
  14.103 +    
  14.104 +    const TInt maxi = MaxVolume();
  14.105 +    if(aNew > maxi)
  14.106 +		return;
  14.107 +    if(aNew < 0)
  14.108 +    	return;
  14.109 +    
  14.110 +    iVolume = aNew;
  14.111 +    
  14.112 +    iState |= EVolumeChange;
  14.113 +    }
  14.114 +    
  14.115 + TInt CStreamPlayer::Volume() const
  14.116 +    {
  14.117 +	return iVolume;
  14.118 +    }
  14.119 +
  14.120 +void CStreamPlayer::Open()
  14.121 +	{
  14.122 +	TMdaAudioDataSettings audioSettings;
  14.123 +	audioSettings.Query();
  14.124 +    audioSettings.iCaps = TMdaAudioDataSettings::ERealTime |
  14.125 +     	TMdaAudioDataSettings::ESampleRateFixed; 
  14.126 +    audioSettings.iSampleRate = iRate; 
  14.127 +    audioSettings.iChannels = iChannels;
  14.128 +	audioSettings.iFlags = TMdaAudioDataSettings::ENoNetworkRouting;
  14.129 +	audioSettings.iVolume = 0;
  14.130 +	
  14.131 +	iState &= ~EStopped;
  14.132 +    iStream->Open(&audioSettings);    
  14.133 +	}
  14.134 +	
  14.135 +void CStreamPlayer::Stop()
  14.136 +	{
  14.137 +	if(iState & (EStarted | EInited))
  14.138 +		{
  14.139 +		Close();
  14.140 +		iState |= EStopped;
  14.141 +		}
  14.142 +	}
  14.143 +	
  14.144 +void CStreamPlayer::Start()
  14.145 +	{
  14.146 +	if(iPtr.Length() == 0)
  14.147 +		{
  14.148 +		iState |= EStarted;
  14.149 +		if(iState & EInited)
  14.150 +			{
  14.151 +			Request();
  14.152 +			}
  14.153 +		else if(iState & EStopped)
  14.154 +			{
  14.155 +			Open();
  14.156 +			}
  14.157 +		}
  14.158 +	}
  14.159 +
  14.160 +void CStreamPlayer::Close()
  14.161 +	{
  14.162 +	iState &= ~EInited;
  14.163 +	iStream->Stop();
  14.164 +	iState &= ~EStarted;
  14.165 +	}
  14.166 +	
  14.167 +void CStreamPlayer::Request()
  14.168 +	{
  14.169 +	if(iState & EInited)
  14.170 +		{
  14.171 +		iPtr.Set(KNullDesC8);
  14.172 +		
  14.173 +		if(iState & EVolumeChange)
  14.174 +			{
  14.175 +       		const TReal newVol = iVolume;
  14.176 +       		const TReal newMax = MaxVolume();
  14.177 +       		const TInt maxVol = iStream->MaxVolume();
  14.178 +       		const TReal max = static_cast<TReal>(maxVol);
  14.179 +       		const TReal newvolume = (newVol * max) / newMax;
  14.180 +       		const TInt vol = static_cast<TReal>(newvolume);
  14.181 +       		iStream->SetVolume(vol);
  14.182 +			iState &= ~EVolumeChange;
  14.183 +			}
  14.184 +			
  14.185 +		if(iState & EStarted)
  14.186 +			{
  14.187 +	 		iPtr.Set(iProvider.Data());
  14.188 +			}
  14.189 +		if(iPtr.Length() == 0)
  14.190 +			{
  14.191 +			iPtr.Set(iSilence);
  14.192 +			}
  14.193 +		TRAPD(err, iStream->WriteL(iPtr));
  14.194 +		if(err != KErrNone)
  14.195 +			{
  14.196 +			iObs.Complete(MStreamObs::EWrite, err);	
  14.197 +			}
  14.198 +	/*	else
  14.199 +			{
  14.200 +			iProvider.Written(iPtr.Length());
  14.201 +			}*/
  14.202 +		}
  14.203 +	}
  14.204 +	
  14.205 +
  14.206 +void CStreamPlayer::SetCapsL()
  14.207 +	{
  14.208 +	iStream->SetDataTypeL(iType);
  14.209 +	iStream->SetAudioPropertiesL(iRate, iChannels);
  14.210 +	}
  14.211 +
  14.212 +void CStreamPlayer::MaoscOpenComplete(TInt aError) 
  14.213 +	{
  14.214 +	if(aError == KErrNone)
  14.215 +		{
  14.216 +		TRAPD(err, SetCapsL());
  14.217 +    	if(err == KErrNone)
  14.218 +    		{
  14.219 +    		iStream->SetPriority(EPriorityNormal, EMdaPriorityPreferenceTime);
  14.220 +    		iState |= EInited;
  14.221 +    		
  14.222 +    		
  14.223 +        	SetVolume(Volume());	
  14.224 +    		
  14.225 +    		if(iState & EStarted)
  14.226 +    			{
  14.227 +    			Request();
  14.228 +    			}
  14.229 +    			
  14.230 +			}
  14.231 +		aError = err;
  14.232 +		}
  14.233 +	if(!(iState & EDied))
  14.234 +		iObs.Complete(MStreamObs::EInit, aError);
  14.235 +	}
  14.236 +	
  14.237 +void CStreamPlayer::MaoscBufferCopied(TInt aError, const TDesC8& /*aBuffer*/)
  14.238 +	{
  14.239 +	iPtr.Set(KNullDesC8);
  14.240 +	if(aError == KErrNone)
  14.241 +		{
  14.242 +		if(iState & EInited)
  14.243 +			Request();
  14.244 +		else
  14.245 +			iStream->Stop();
  14.246 +		}
  14.247 +	else if(!(iState & EDied))
  14.248 +		iObs.Complete(MStreamObs::EPlay, aError);
  14.249 +	}
  14.250 +	
  14.251 +void CStreamPlayer::MaoscPlayComplete(TInt aError)
  14.252 +	{	
  14.253 +	iPtr.Set(KNullDesC8);
  14.254 +	iState &= ~EStarted;
  14.255 +	if(!(iState & EDied))
  14.256 +		iObs.Complete(MStreamObs::EClose, aError);
  14.257 +	}
  14.258 +	
  14.259 +TBool CStreamPlayer::Playing() const
  14.260 +	{
  14.261 +	return (iState & EInited) && (iState & EStarted);
  14.262 +	}
  14.263 +
  14.264 +TBool CStreamPlayer::Closed() const
  14.265 +	{
  14.266 +	return !(iState & EInited) && !(iState & EDied);
  14.267 +	}
  14.268 +	
  14.269 +	/*
  14.270 +void CStreamPlayer::Request()
  14.271 +	{
  14.272 +	SetActive();
  14.273 +	TRequestStatus* s = &iStatus;
  14.274 +	User::RequestComplete(s, KErrNone);
  14.275 +	}
  14.276 +	//		iTimer.After(0);
  14.277 +	*/
  14.278 +	
  14.279 +
  14.280 +
  14.281 +
  14.282 +
    15.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    15.2 +++ b/src/audio/symbian/streamplayer.h	Sun Jun 24 18:26:35 2007 +0000
    15.3 @@ -0,0 +1,89 @@
    15.4 +#ifndef STREAMPLAYER_H
    15.5 +#define STREAMPLAYER_H
    15.6 +
    15.7 +#include<MdaAudioOutputStream.h>
    15.8 +
    15.9 +const TInt KSilenceBuffer = 256;
   15.10 +
   15.11 +class MStreamObs
   15.12 +    {
   15.13 +    public:
   15.14 +    	enum 
   15.15 +    	{
   15.16 +    	EInit, 
   15.17 +    	EPlay,
   15.18 +    	EWrite,
   15.19 +    	EClose,	
   15.20 +    	};
   15.21 +        virtual void Complete(TInt aState, TInt aError) = 0;
   15.22 +    };
   15.23 +
   15.24 +class MStreamProvider
   15.25 +	{
   15.26 +	public:
   15.27 +		virtual TPtrC8 Data() = 0;	
   15.28 +	};
   15.29 +
   15.30 +NONSHARABLE_CLASS(CStreamPlayer) : public CBase, public MMdaAudioOutputStreamCallback
   15.31 +	{
   15.32 +	public:
   15.33 +		CStreamPlayer(MStreamProvider& aProvider, MStreamObs& aObs);
   15.34 +		~CStreamPlayer();
   15.35 +		void ConstructL();
   15.36 +		
   15.37 +		static TInt ClosestSupportedRate(TInt aRate);
   15.38 +		
   15.39 +		TInt OpenStream(TInt aRate, TInt aChannels, TUint32 aType = KMMFFourCCCodePCM16);
   15.40 +		
   15.41 +		void SetVolume(TInt aNew);
   15.42 +		TInt Volume() const;
   15.43 +		TInt MaxVolume() const;
   15.44 +		
   15.45 +		void Stop();
   15.46 +		void Start();
   15.47 +		void Open();
   15.48 +		void Close();
   15.49 +		
   15.50 +		TBool Playing() const;
   15.51 +		TBool Closed() const;
   15.52 +		
   15.53 +	private:
   15.54 +
   15.55 +		void MaoscOpenComplete(TInt aError) ;
   15.56 +		void MaoscBufferCopied(TInt aError, const TDesC8& aBuffer);
   15.57 +		void MaoscPlayComplete(TInt aError);
   15.58 +	
   15.59 +	private:
   15.60 +		void Request();
   15.61 +		void SetCapsL();
   15.62 +
   15.63 +	private:
   15.64 +		MStreamProvider& iProvider;
   15.65 +		MStreamObs& iObs;	
   15.66 +		TInt iVolume;
   15.67 +	
   15.68 +		CMdaAudioOutputStream* iStream;
   15.69 +	
   15.70 +		TInt iRate;
   15.71 +		TInt iChannels;
   15.72 +		TUint32 iType;
   15.73 +		
   15.74 +		enum 
   15.75 +			{
   15.76 +				ENone = 0,
   15.77 +				EInited = 0x1,
   15.78 +				EStarted = 0x2,
   15.79 +				EStopped = 0x4,
   15.80 +				EVolumeChange = 0x8,
   15.81 +				EDied		  = 0x10
   15.82 +			};
   15.83 +		
   15.84 +		TInt iState;
   15.85 +		TBuf8<KSilenceBuffer> iSilence;
   15.86 +		TPtrC8 iPtr;
   15.87 +	
   15.88 +	};
   15.89 +
   15.90 +
   15.91 +#endif
   15.92 +
    16.1 --- a/src/events/SDL_events.c	Thu Jun 21 18:48:13 2007 +0000
    16.2 +++ b/src/events/SDL_events.c	Sun Jun 24 18:26:35 2007 +0000
    16.3 @@ -169,7 +169,7 @@
    16.4  
    16.5  		/* The event thread will handle timers too */
    16.6  		SDL_SetTimerThreaded(2);
    16.7 -#if (defined(__WIN32__) && !defined(_WIN32_WCE)) && !defined(HAVE_LIBC)
    16.8 +#if (defined(__WIN32__) && !defined(_WIN32_WCE)) && !defined(HAVE_LIBC) && !defined(__SYMBIAN32__)
    16.9  #undef SDL_CreateThread
   16.10  		SDL_EventThread = SDL_CreateThread(SDL_GobbleEvents, NULL, NULL, NULL);
   16.11  #else
    17.1 --- a/src/file/SDL_rwops.c	Thu Jun 21 18:48:13 2007 +0000
    17.2 +++ b/src/file/SDL_rwops.c	Sun Jun 24 18:26:35 2007 +0000
    17.3 @@ -29,7 +29,7 @@
    17.4  #include "SDL_rwops.h"
    17.5  
    17.6  
    17.7 -#if defined(__WIN32__)
    17.8 +#if defined(__WIN32__) && !defined(__SYMBIAN32__)
    17.9  
   17.10  /* Functions to read/write Win32 API file pointers */
   17.11  /* Will not use it on WinCE because stdio is buffered, it means
   17.12 @@ -372,7 +372,7 @@
   17.13  		return NULL;
   17.14  	}
   17.15  
   17.16 -#if defined(__WIN32__)
   17.17 +#if defined(__WIN32__) && !defined(__SYMBIAN32__)
   17.18  	rwops = SDL_AllocRW();
   17.19  	if (!rwops)
   17.20  		return NULL; /* SDL_SetError already setup by SDL_AllocRW() */
    18.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    18.2 +++ b/src/main/symbian/EKA1/SDL_main.cpp	Sun Jun 24 18:26:35 2007 +0000
    18.3 @@ -0,0 +1,152 @@
    18.4 +/*
    18.5 +    SDL - Simple DirectMedia Layer
    18.6 +    Copyright (C) 1997, 1998, 1999, 2000, 2001  Sam Lantinga
    18.7 +
    18.8 +    This library is free software; you can redistribute it and/or
    18.9 +    modify it under the terms of the GNU Library General Public
   18.10 +    License as published by the Free Software Foundation; either
   18.11 +    version 2 of the License, or (at your option) any later version.
   18.12 +
   18.13 +    This library is distributed in the hope that it will be useful,
   18.14 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
   18.15 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   18.16 +    Library General Public License for more details.
   18.17 +
   18.18 +    You should have received a copy of the GNU Library General Public
   18.19 +    License along with this library; if not, write to the Free
   18.20 +    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   18.21 +
   18.22 +    Sam Lantinga
   18.23 +    slouken@devolution.com
   18.24 +*/
   18.25 +
   18.26 +/*
   18.27 +    SDL_main.cpp
   18.28 +    The Epoc executable startup functions 
   18.29 +
   18.30 +    Epoc version by Hannu Viitala (hannu.j.viitala@mbnet.fi)
   18.31 +*/
   18.32 +
   18.33 +#include <e32std.h>
   18.34 +#include <e32def.h>
   18.35 +#include <e32svr.h>
   18.36 +#include <e32base.h>
   18.37 +#include <estlib.h>
   18.38 +#include <stdlib.h>
   18.39 +#include <stdio.h>
   18.40 +#include <w32std.h>
   18.41 +#include <apgtask.h>
   18.42 +
   18.43 +#include "SDL_error.h"
   18.44 +
   18.45 +#if defined(__WINS__)
   18.46 +#include <estw32.h>
   18.47 +IMPORT_C void RegisterWsExe(const TDesC &aName);
   18.48 +#endif
   18.49 +
   18.50 +/* The prototype for the application's main() function */
   18.51 +#define main	SDL_main
   18.52 +extern "C" int main (int argc, char *argv[], char *envp[]);
   18.53 +extern "C" void exit (int ret);
   18.54 +
   18.55 +
   18.56 +/* Epoc main function */
   18.57 +
   18.58 +#ifdef __WINS__
   18.59 +
   18.60 +
   18.61 +void GetCmdLine(int& aArgc, char**& aArgv)
   18.62 +    {
   18.63 +    RChunk chunk;
   18.64 +
   18.65 +    if(chunk.OpenGlobal(RThread().Name(), ETrue) != KErrNone)
   18.66 +        return;
   18.67 +
   18.68 +    TUint* ptr = (TUint*) chunk.Base();
   18.69 +    if(ptr != NULL)
   18.70 +        {
   18.71 +        aArgc = (int)    *(ptr); // count
   18.72 +        aArgv = (char**) *(ptr + 1);
   18.73 +        }
   18.74 +    chunk.Close();
   18.75 +    }
   18.76 +
   18.77 +#endif
   18.78 +
   18.79 +
   18.80 +TInt E32Main()
   18.81 +    {
   18.82 +    /*  Get the clean-up stack */
   18.83 +	CTrapCleanup* cleanup = CTrapCleanup::New();
   18.84 +
   18.85 +    /* Arrange for multi-threaded operation */
   18.86 +	SpawnPosixServerThread();	
   18.87 +
   18.88 +    /* Get args and environment */
   18.89 +	int argc=0;
   18.90 +	char** argv=0;
   18.91 +	char** envp=0;
   18.92 +
   18.93 +#ifndef __WINS__
   18.94 +	__crt0(argc,argv,envp);	
   18.95 +#else
   18.96 +    GetCmdLine(argc, argv);
   18.97 +#endif
   18.98 +    /* Start the application! */
   18.99 +
  18.100 +    /* Create stdlib */
  18.101 +    _REENT;
  18.102 +
  18.103 +    /* Set process and thread priority and name */
  18.104 +
  18.105 +    RThread currentThread;
  18.106 +	RProcess thisProcess;
  18.107 +	TParse exeName;
  18.108 +	exeName.Set(thisProcess.FileName(), NULL, NULL);
  18.109 +    currentThread.Rename(exeName.Name());
  18.110 +    currentThread.SetProcessPriority(EPriorityLow);
  18.111 +    currentThread.SetPriority(EPriorityMuchLess);
  18.112 +
  18.113 +     /* Call stdlib main */
  18.114 +    int ret = main(argc, argv, envp); /* !! process exits here if there is "exit()" in main! */	
  18.115 +    
  18.116 +    /* Call exit */
  18.117 +    //exit(ret); /* !! process exits here! */	
  18.118 +    //Markus: I do not understand above
  18.119 +    //I commented it at let this function
  18.120 +    //to return ret value - was it purpose
  18.121 +    //that cleanup below is not called at all - why?
  18.122 +
  18.123 +    /* Free resources and return */
  18.124 +    
  18.125 +    _cleanup(); //this is normally called at exit, I call it here, Markus 
  18.126 +
  18.127 +    CloseSTDLIB();
  18.128 +   	delete cleanup;	
  18.129 +#ifdef __WINS__
  18.130 +//    User::Panic(_L("exit"), ret);
  18.131 +  //  RThread().Kill(ret); //Markus  get rid of this thread
  18.132 +  //  RThread().RaiseException(EExcKill);
  18.133 +#endif
  18.134 +    return ret;//Markus, or exit(ret); ??
  18.135 +  //return(KErrNone);
  18.136 +    }
  18.137 +
  18.138 +
  18.139 +#ifdef __WINS__
  18.140 +EXPORT_C TInt WinsMain()
  18.141 +    {
  18.142 +    return E32Main();
  18.143 + //   return WinsMain(0, 0, 0);
  18.144 +    }
  18.145 +#endif
  18.146 +
  18.147 +/* Epoc dll entry point */
  18.148 +#if defined(__WINS__)
  18.149 +GLDEF_C TInt E32Dll(TDllReason)
  18.150 +	{
  18.151 +	return(KErrNone);
  18.152 +	}
  18.153 +#endif
  18.154 +
  18.155 +
    19.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    19.2 +++ b/src/main/symbian/EKA2/SDL_main.cpp	Sun Jun 24 18:26:35 2007 +0000
    19.3 @@ -0,0 +1,1035 @@
    19.4 +/*
    19.5 +    SDL_Main.cpp
    19.6 +    Symbian OS services for SDL
    19.7 +
    19.8 +    Markus Mertama
    19.9 +*/
   19.10 +
   19.11 +
   19.12 +#include "epoc_sdl.h"
   19.13 +
   19.14 +#include"sdlepocapi.h"
   19.15 +#include <e32base.h>
   19.16 +#include <estlib.h>
   19.17 +#include <stdio.h>
   19.18 +#include <badesca.h>
   19.19 +
   19.20 +#include "vectorbuffer.h"
   19.21 +#include <w32std.h>
   19.22 +#include <aknappui.h>
   19.23 +#include <aknapp.h>
   19.24 +#include "SDL_epocevents_c.h"
   19.25 +#include "SDL_keysym.h"
   19.26 +#include "dsa.h"
   19.27 +
   19.28 +
   19.29 +#ifdef SYMBIANC
   19.30 +#include <reent.h>
   19.31 +#endif
   19.32 +
   19.33 +//Markus Mertama
   19.34 +
   19.35 +
   19.36 +extern SDLKey* KeyMap();
   19.37 +extern void ResetKeyMap();
   19.38 +
   19.39 +class CCurrentAppUi;
   19.40 +
   19.41 +//const TUid KSDLUid =  { 0xF01F3D69 };
   19.42 +
   19.43 +NONSHARABLE_CLASS(EnvUtils)
   19.44 +	{
   19.45 +	public:
   19.46 +	static void DisableKeyBlocking();
   19.47 +	static TBool Rendezvous(RThread& aThread, TRequestStatus& aStatus);
   19.48 +	};
   19.49 +
   19.50 +TInt Panic(TInt aErr, TInt aLine)
   19.51 +	{
   19.52 +	TBuf<64> b;
   19.53 +	b.Format(_L("Main at %d"), aLine);
   19.54 +	User::Panic(b, aErr);
   19.55 +	return 0;	
   19.56 +	}
   19.57 +	
   19.58 +
   19.59 +NONSHARABLE_CLASS(CCurrentAppUi) : public CAknAppUi
   19.60 +	{
   19.61 +	public:
   19.62 +	static CCurrentAppUi* Cast(CEikAppUi* aUi);
   19.63 +	void DisableKeyBlocking();
   19.64 +	};
   19.65 +	
   19.66 +	
   19.67 +CCurrentAppUi* CCurrentAppUi::Cast(CEikAppUi* aUi)
   19.68 +	{
   19.69 +	return static_cast<CCurrentAppUi*>(aUi);	
   19.70 +	}
   19.71 +	
   19.72 +void CCurrentAppUi::DisableKeyBlocking()	
   19.73 +	{
   19.74 +	SetKeyBlockMode(ENoKeyBlock);	
   19.75 +	}
   19.76 +
   19.77 +
   19.78 +class CEventQueue : public CBase, public MEventQueue
   19.79 +    {
   19.80 +    public:
   19.81 +        static CEventQueue* NewL();
   19.82 +        ~CEventQueue();
   19.83 +    public:
   19.84 +        TInt Append(const TWsEvent& aEvent);
   19.85 +       	const TWsEvent& Shift();
   19.86 +       	void Lock();
   19.87 +       	void Unlock();
   19.88 +        TBool HasData();
   19.89 +    private:
   19.90 +        TVector<TWsEvent, 64> iVector;
   19.91 +        RCriticalSection iCS;
   19.92 +    };
   19.93 +    
   19.94 + CEventQueue* CEventQueue::NewL()
   19.95 +    {
   19.96 +    CEventQueue* q = new (ELeave) CEventQueue();
   19.97 +    CleanupStack::PushL(q);
   19.98 +    User::LeaveIfError(q->iCS.CreateLocal());
   19.99 +    CleanupStack::Pop();
  19.100 +    return q;
  19.101 +    }
  19.102 +    
  19.103 +CEventQueue::~CEventQueue()
  19.104 +    {
  19.105 +    iCS.Close();
  19.106 +    }
  19.107 +    
  19.108 +TInt CEventQueue::Append(const TWsEvent& aEvent)
  19.109 +    {
  19.110 +    iCS.Wait();
  19.111 +   	const TInt err = iVector.Append(aEvent);
  19.112 +    iCS.Signal();
  19.113 +    return err;
  19.114 +    }
  19.115 +    
  19.116 +    
  19.117 +TBool CEventQueue::HasData()
  19.118 +    {
  19.119 +    return iVector.Size() > 0;
  19.120 +    }
  19.121 +
  19.122 +
  19.123 +void CEventQueue::Lock()
  19.124 +	{
  19.125 +    iCS.Wait();
  19.126 +	}
  19.127 +	
  19.128 +void CEventQueue::Unlock()
  19.129 +	{
  19.130 +	iCS.Signal();
  19.131 +	}
  19.132 +
  19.133 +const TWsEvent& CEventQueue::Shift()
  19.134 +    {
  19.135 +    const TWsEvent& event =  iVector.Shift();
  19.136 +    return event;
  19.137 +    }
  19.138 +
  19.139 +
  19.140 +TSdlCleanupItem::TSdlCleanupItem(TSdlCleanupOperation aOperation, TAny* aItem) :
  19.141 +iOperation(aOperation), iItem(aItem), iThread(RThread().Id())
  19.142 +    {
  19.143 +    }
  19.144 +
  19.145 +class CEikonEnv;
  19.146 +class CSdlAppServ;
  19.147 +
  19.148 +    
  19.149 +NONSHARABLE_CLASS(EpocSdlEnvData)
  19.150 +    {
  19.151 +    public:
  19.152 +    void Free();
  19.153 +    CEventQueue*            iEventQueue;
  19.154 +    TMainFunc				iMain;
  19.155 +    TInt            		iEpocEnvFlags;
  19.156 +    int                     iArgc;
  19.157 +    char**                  iArgv;
  19.158 +    CDsa*                   iDsa;
  19.159 +    CSdlAppServ*            iAppSrv;
  19.160 +    TThreadId               iId;
  19.161 +    CArrayFix<TSdlCleanupItem>* iCleanupItems; 
  19.162 +    CEikAppUi*				iAppUi;
  19.163 +    CSDL*					iSdl;
  19.164 +    };
  19.165 +  
  19.166 +   
  19.167 +EpocSdlEnvData* gEpocEnv;
  19.168 +
  19.169 +#define MAINFUNC(x) EXPORT_C TMainFunc::TMainFunc(mainfunc##x aFunc){Mem::FillZ(iMainFunc, sizeof(iMainFunc)); iMainFunc[x - 1] = (void*) aFunc;}
  19.170 +    
  19.171 +MAINFUNC(1)
  19.172 +MAINFUNC(2)
  19.173 +MAINFUNC(3)
  19.174 +MAINFUNC(4)
  19.175 +MAINFUNC(5)
  19.176 +MAINFUNC(6)
  19.177 +
  19.178 +EXPORT_C TMainFunc::TMainFunc() 
  19.179 +	{
  19.180 +	Mem::FillZ(iMainFunc, sizeof(iMainFunc));
  19.181 +	}
  19.182 +	
  19.183 +
  19.184 +const void* TMainFunc::operator[](TInt aIndex) const
  19.185 +	{
  19.186 +	return iMainFunc[aIndex];
  19.187 +	}
  19.188 +
  19.189 +
  19.190 +NONSHARABLE_CLASS(CSdlAppServ) : public CActive
  19.191 +    {
  19.192 +    public:
  19.193 +        enum
  19.194 +            {
  19.195 +            EAppSrvNoop = CDsa::ELastDsaRequest,
  19.196 +            EAppSrvWindowWidth,
  19.197 +            EAppSrvWindowHeight,
  19.198 +            EAppSrvWindowDisplayMode,
  19.199 +            EAppSrvWindowPointerCursorMode,
  19.200 +            EAppSrvDsaStatus,
  19.201 +            EAppSrvStopThread,
  19.202 +            EAppSrvWaitDsa
  19.203 +            };
  19.204 +        CSdlAppServ();
  19.205 +        void ConstructL();
  19.206 +        ~CSdlAppServ();
  19.207 +        TInt Request(TInt aService);
  19.208 +        TInt RequestValue(TInt aService);
  19.209 +        void Init(); 
  19.210 +        void PanicMain(TInt aReason);
  19.211 +        void PanicMain(const TDesC& aInfo, TInt aReason);
  19.212 +        void SetObserver(MSDLObserver* aObserver);
  19.213 +        TInt ObserverEvent(TInt aEvent, TInt aParam);
  19.214 +        void SetParam(TInt aParam);
  19.215 +        void HandleObserverValue(TInt aService, TInt aReturnValue, TBool aMainThread);
  19.216 +        MSDLObserver* Observer();
  19.217 +    private:
  19.218 +        void RunL();
  19.219 +        void DoCancel();
  19.220 +    private:
  19.221 +        const TThreadId iMainId;
  19.222 +        RThread iAppThread;
  19.223 +        TInt iService;
  19.224 +        TInt iReturnValue;
  19.225 +        RSemaphore iSema;
  19.226 +        MSDLObserver* iObserver;
  19.227 +        TRequestStatus* iStatusPtr;
  19.228 +    };
  19.229 +    
  19.230 +CSdlAppServ::CSdlAppServ() : CActive(CActive::EPriorityHigh), iMainId(RThread().Id())
  19.231 +    {
  19.232 +    }
  19.233 +    
  19.234 +    
  19.235 +    
  19.236 +MSDLObserver* CSdlAppServ::Observer()
  19.237 +	{
  19.238 +	return iObserver;
  19.239 +	}
  19.240 +	
  19.241 +	
  19.242 +void CSdlAppServ::SetObserver(MSDLObserver* aObserver)
  19.243 +	{
  19.244 +	iObserver = aObserver;
  19.245 +	}	
  19.246 +	
  19.247 +TInt CSdlAppServ::ObserverEvent(TInt aEvent, TInt aParam)
  19.248 +	{
  19.249 +	if(iObserver != NULL)
  19.250 +		{
  19.251 +		if(RThread().Id() == gEpocEnv->iId)
  19.252 +			{
  19.253 +			return iObserver->SdlThreadEvent(aEvent, aParam);
  19.254 +			}
  19.255 +		else if(RThread().Id() == iMainId)
  19.256 +			{
  19.257 +			return iObserver->SdlEvent(aEvent, aParam);
  19.258 +			}
  19.259 +		PANIC(KErrNotSupported);
  19.260 +		}
  19.261 +	return 0;
  19.262 +	}
  19.263 +	
  19.264 +void CSdlAppServ::PanicMain(TInt aReason)    
  19.265 +    {
  19.266 +    iAppThread.Panic(RThread().Name(), aReason);
  19.267 +    }
  19.268 +    
  19.269 +void CSdlAppServ::PanicMain(const TDesC& aInfo, TInt aReason)    
  19.270 +    {
  19.271 +    iAppThread.Panic(aInfo, aReason);
  19.272 +    }    
  19.273 +    
  19.274 +void CSdlAppServ::ConstructL()
  19.275 +    {
  19.276 +    CActiveScheduler::Add(this);
  19.277 +    User::LeaveIfError(iSema.CreateLocal(1));
  19.278 +    iStatus = KRequestPending;
  19.279 +    iStatusPtr = &iStatus;
  19.280 +    SetActive();
  19.281 +    }
  19.282 +        
  19.283 + CSdlAppServ::~CSdlAppServ()
  19.284 +    {
  19.285 +    Cancel();
  19.286 +    if(iSema.Handle() != NULL)
  19.287 +        iSema.Signal();
  19.288 +    iSema.Close();
  19.289 +    iAppThread.Close();
  19.290 +    }
  19.291 +    
  19.292 +TInt CSdlAppServ::Request(TInt aService)
  19.293 +    {
  19.294 +    if(RThread().Id() != iAppThread.Id())
  19.295 +    	{
  19.296 +    	iSema.Wait();
  19.297 +    	iService = aService;
  19.298 +    	iAppThread.RequestComplete(iStatusPtr, KErrNone); 
  19.299 +    	return KErrNone;
  19.300 +    	}
  19.301 +    return KErrBadHandle;
  19.302 +    }
  19.303 +    
  19.304 +TInt CSdlAppServ::RequestValue(TInt aService)
  19.305 +    {
  19.306 +    Request(aService);
  19.307 +    Request(EAppSrvNoop);
  19.308 +    return iReturnValue;
  19.309 +    }
  19.310 +   
  19.311 +void CSdlAppServ::Init()
  19.312 +    {
  19.313 +    PANIC_IF_ERROR(iAppThread.Open(iMainId));
  19.314 +    }
  19.315 +
  19.316 +void CSdlAppServ::SetParam(TInt aParam)
  19.317 +	{
  19.318 +	iReturnValue = aParam;
  19.319 +	}
  19.320 +	
  19.321 +void CSdlAppServ::HandleObserverValue(TInt aService, TInt aReturnValue, TBool aMainThread)
  19.322 +	{
  19.323 +	if(iObserver != NULL && aMainThread)
  19.324 +		{
  19.325 +		switch(aService)
  19.326 +			{
  19.327 +			case MSDLObserver::EEventScreenSizeChanged:
  19.328 +			if(aReturnValue == MSDLObserver::EScreenSizeChangedDefaultPalette)
  19.329 +				EpocSdlEnv::LockPalette(EFalse);
  19.330 +			break;
  19.331 +			}
  19.332 +		}
  19.333 +	if(!aMainThread && aService == MSDLObserver::EEventSuspend)
  19.334 +		{
  19.335 +		if(iObserver == NULL || 
  19.336 +		(gEpocEnv->iDsa->Stopped() && aReturnValue != MSDLObserver::ESuspendNoSuspend))
  19.337 +			{
  19.338 +			EpocSdlEnv::Suspend();
  19.339 +			}
  19.340 +		}
  19.341 +	}
  19.342 +
  19.343 +void CSdlAppServ::RunL()
  19.344 +    {
  19.345 +    if(iStatus == KErrNone)
  19.346 +        {
  19.347 +        switch(iService)
  19.348 +            {
  19.349 +            case CSdlAppServ::EAppSrvWaitDsa:
  19.350 +            	EpocSdlEnv::SetWaitDsa();
  19.351 +            	iReturnValue = EpocSdlEnv::IsDsaAvailable();
  19.352 +            //		}
  19.353 +            //	gEpocEnv->iDsa->Stop();
  19.354 +            //	gEpocEnv->iDsa->RestartL();
  19.355 +            	break;
  19.356 +           	 case CSdlAppServ::EAppSrvStopThread:
  19.357 +            	gEpocEnv->iDsa->SetSuspend();
  19.358 +            	break;
  19.359 +            case EpocSdlEnv::EDisableKeyBlocking:
  19.360 +                EnvUtils::DisableKeyBlocking();
  19.361 +                break;
  19.362 +          
  19.363 +            case EAppSrvWindowPointerCursorMode:
  19.364 +                iReturnValue = gEpocEnv->iDsa != NULL ?
  19.365 +                 gEpocEnv->iDsa->Session().PointerCursorMode() : KErrNotReady; 
  19.366 +                break;
  19.367 +            case EAppSrvDsaStatus:
  19.368 +            	gEpocEnv->iDsa->Stop();
  19.369 +                iReturnValue = KErrNone;
  19.370 +                break;
  19.371 +            case CDsa::ERequestUpdate:
  19.372 +            	gEpocEnv->iDsa->UnlockHWSurfaceRequestComplete();
  19.373 +            	break;
  19.374 +            case EAppSrvNoop:
  19.375 +                break;
  19.376 +            case MSDLObserver::EEventResume:
  19.377 +            case MSDLObserver::EEventSuspend:
  19.378 +            case MSDLObserver::EEventScreenSizeChanged:
  19.379 +            case MSDLObserver::EEventWindowReserved:
  19.380 +            case MSDLObserver::EEventKeyMapInit:
  19.381 +            case MSDLObserver::EEventWindowNotAvailable:
  19.382 +            case MSDLObserver::EEventMainExit:
  19.383 +            	iReturnValue = ObserverEvent(iService, iReturnValue);
  19.384 +            	HandleObserverValue(iService, iReturnValue, ETrue);
  19.385 +            	break;
  19.386 +            default:
  19.387 +                PANIC(KErrNotSupported);
  19.388 +            }
  19.389 +        iStatus = KRequestPending;
  19.390 +        iStatusPtr = &iStatus;
  19.391 +        SetActive();
  19.392 +        }
  19.393 +    iSema.Signal();
  19.394 +    }
  19.395 +    
  19.396 +void CSdlAppServ::DoCancel()
  19.397 +    {
  19.398 +    iSema.Wait();
  19.399 +    TRequestStatus* s = &iStatus;
  19.400 +    iAppThread.RequestComplete(s, KErrCancel); 
  19.401 +    }
  19.402 + 
  19.403 +
  19.404 +
  19.405 +MEventQueue& EpocSdlEnv::EventQueue()
  19.406 +    {
  19.407 +    __ASSERT_DEBUG(gEpocEnv != NULL, PANIC(KErrNotReady));
  19.408 +    return *gEpocEnv->iEventQueue;
  19.409 +    }
  19.410 +
  19.411 +
  19.412 +TBool EpocSdlEnv::Flags(TInt aFlag)
  19.413 +    {
  19.414 +	const TInt flag = gEpocEnv->iEpocEnvFlags & aFlag;
  19.415 +	return flag == aFlag;
  19.416 +    }
  19.417 +
  19.418 +TInt EpocSdlEnv::Argc()
  19.419 +    {
  19.420 +    __ASSERT_DEBUG(gEpocEnv != NULL, PANIC(KErrNotReady));
  19.421 +    return gEpocEnv->iArgc;
  19.422 +    }
  19.423 +    
  19.424 +    
  19.425 +char** EpocSdlEnv::Argv()
  19.426 +    {
  19.427 +    __ASSERT_DEBUG(gEpocEnv != NULL, PANIC(KErrNotReady));
  19.428 +    return gEpocEnv->iArgv;
  19.429 +    }
  19.430 +    
  19.431 +    
  19.432 +TBool EpocSdlEnv::IsDsaAvailable()
  19.433 +    {
  19.434 +    __ASSERT_DEBUG(gEpocEnv != NULL, PANIC(KErrNotReady));
  19.435 +    return gEpocEnv->iDsa != NULL && gEpocEnv->iDsa->IsDsaAvailable();
  19.436 +    }
  19.437 +
  19.438 +  
  19.439 +void EpocSdlEnv::WaitDsaAvailable()
  19.440 +	{
  19.441 +	EpocSdlEnv::ObserverEvent(MSDLObserver::EEventWindowNotAvailable, 0);
  19.442 +	gEpocEnv->iAppSrv->Request(CSdlAppServ::EAppSrvStopThread);
  19.443 +	if(EpocSdlEnv::Flags(CSDL::EEnableFocusStop))
  19.444 +		{
  19.445 +		EpocSdlEnv::ObserverEvent(MSDLObserver::EEventSuspend, 0);
  19.446 +		}
  19.447 +	}
  19.448 +	
  19.449 +void EpocSdlEnv::Suspend()
  19.450 +	{
  19.451 +	if(gEpocEnv->iDsa->Stopped() || EpocSdlEnv::Flags(CSDL::EEnableFocusStop))
  19.452 +		{
  19.453 +	//	gEpocEnv->iDsa->ReleaseStop(); 
  19.454 +		gEpocEnv->iDsa->SetSuspend(); 
  19.455 +		RThread().Suspend();
  19.456 +		EpocSdlEnv::ObserverEvent(MSDLObserver::EEventResume, 0);
  19.457 +		}
  19.458 +	}
  19.459 +	
  19.460 +void EpocSdlEnv::SetWaitDsa()
  19.461 +	{
  19.462 +	if(!IsDsaAvailable())
  19.463 +		{
  19.464 +		RThread th;
  19.465 +		th.Open(gEpocEnv->iId);
  19.466 +		th.Suspend();
  19.467 +		th.Close();
  19.468 +		gEpocEnv->iDsa->SetSuspend(); 
  19.469 +		}
  19.470 +	}
  19.471 +	
  19.472 +void EpocSdlEnv::Resume()
  19.473 +	{
  19.474 +	gEpocEnv->iDsa->Resume();
  19.475 +	RThread th;
  19.476 +	th.Open(gEpocEnv->iId);
  19.477 +	th.Resume();
  19.478 +	th.Close();
  19.479 +	
  19.480 +	const TInt value = gEpocEnv->iAppSrv->ObserverEvent(MSDLObserver::EEventResume, 0);
  19.481 +	gEpocEnv->iAppSrv->HandleObserverValue(MSDLObserver::EEventResume, value, ETrue);
  19.482 +	}
  19.483 +    
  19.484 +
  19.485 +TInt EpocSdlEnv::AllocSwSurface(const TSize& aSize, TDisplayMode aMode)
  19.486 +	{
  19.487 +	return gEpocEnv->iDsa->AllocSurface(EFalse, aSize, aMode);
  19.488 +	}
  19.489 +	
  19.490 +TInt EpocSdlEnv::AllocHwSurface(const TSize& aSize, TDisplayMode aMode)
  19.491 +	{
  19.492 +	return gEpocEnv->iDsa->AllocSurface(ETrue, aSize, aMode);
  19.493 +	}
  19.494 +		
  19.495 +	
  19.496 +void EpocSdlEnv::UnlockHwSurface()
  19.497 +	{
  19.498 +	gEpocEnv->iDsa->UnlockHwSurface();
  19.499 +	}
  19.500 +	
  19.501 +TUint8* EpocSdlEnv::LockHwSurface()
  19.502 +	{
  19.503 +	return gEpocEnv->iDsa->LockHwSurface();
  19.504 +	}
  19.505 +
  19.506 +
  19.507 +void EpocSdlEnv::UpdateSwSurface()
  19.508 +	{
  19.509 +	gEpocEnv->iDsa->UpdateSwSurface();
  19.510 +	}
  19.511 +	
  19.512 +TBool EpocSdlEnv::AddUpdateRect(TUint8* aAddress, const TRect& aUpdateRect, const TRect& aRect)
  19.513 +	{
  19.514 +	return gEpocEnv->iDsa->AddUpdateRect(aAddress, aUpdateRect, aRect);
  19.515 +	}
  19.516 +	
  19.517 +void EpocSdlEnv::Request(TInt aService)
  19.518 +    {
  19.519 +    __ASSERT_DEBUG(gEpocEnv != NULL, PANIC(KErrNotReady));
  19.520 +    gEpocEnv->iAppSrv->Request(aService);
  19.521 +    }
  19.522 +    
  19.523 +    
  19.524 +TSize EpocSdlEnv::WindowSize(const TSize& aRequestedSize)
  19.525 +    { 
  19.526 +    __ASSERT_DEBUG(gEpocEnv != NULL, PANIC(KErrNotReady));
  19.527 +    if(EpocSdlEnv::Flags(CSDL::EAllowImageResize) && gEpocEnv->iDsa->WindowSize() != aRequestedSize)
  19.528 +    	{
  19.529 +    	TRAP_IGNORE(gEpocEnv->iDsa->CreateZoomerL(aRequestedSize));
  19.530 +    	}
  19.531 +    return gEpocEnv->iDsa->WindowSize();
  19.532 +    }
  19.533 +    
  19.534 + TSize EpocSdlEnv::WindowSize()
  19.535 +    { 
  19.536 +    __ASSERT_DEBUG(gEpocEnv != NULL, PANIC(KErrNotReady));
  19.537 +    return gEpocEnv->iDsa->WindowSize();
  19.538 +    }   
  19.539 +    
  19.540 +TDisplayMode EpocSdlEnv::DisplayMode()
  19.541 +    {
  19.542 +    return gEpocEnv->iDsa->DisplayMode();
  19.543 +    }
  19.544 +    
  19.545 +TPointerCursorMode EpocSdlEnv::PointerMode()
  19.546 +    {
  19.547 +    return static_cast<TPointerCursorMode>
  19.548 +    (gEpocEnv->iAppSrv->RequestValue(CSdlAppServ::EAppSrvWindowPointerCursorMode));
  19.549 +    }
  19.550 +    
  19.551 +TInt EpocSdlEnv::SetPalette(TInt aFirstcolor, TInt aColorCount, TUint32* aPalette)  
  19.552 +	{
  19.553 +	return 	gEpocEnv->iDsa->SetPalette(aFirstcolor, aColorCount, aPalette);
  19.554 +	}
  19.555 +
  19.556 +void EpocSdlEnv::PanicMain(TInt aErr)
  19.557 +    {
  19.558 +    gEpocEnv->iAppSrv->PanicMain(aErr);
  19.559 +    }
  19.560 +    
  19.561 +    
  19.562 +TInt EpocSdlEnv::AppendCleanupItem(const TSdlCleanupItem& aItem)
  19.563 +    {
  19.564 +    TRAPD(err, gEpocEnv->iCleanupItems->AppendL(aItem));
  19.565 +    return err;
  19.566 +    }
  19.567 +    
  19.568 +void EpocSdlEnv::RemoveCleanupItem(TAny* aItem)
  19.569 +    {
  19.570 +    for(TInt i = 0; i < gEpocEnv->iCleanupItems->Count(); i++)
  19.571 +        {
  19.572 +        if(gEpocEnv->iCleanupItems->At(i).iItem == aItem)
  19.573 +            gEpocEnv->iCleanupItems->Delete(i);
  19.574 +        }
  19.575 +    }
  19.576 +    
  19.577 +void EpocSdlEnv::CleanupItems()     
  19.578 +	{
  19.579 +	const TThreadId id = RThread().Id();
  19.580 +	TInt last = gEpocEnv->iCleanupItems->Count() - 1;
  19.581 +	TInt i;
  19.582 +	for(i = last; i >= 0 ; i--)
  19.583 +        {
  19.584 +        TSdlCleanupItem& item = gEpocEnv->iCleanupItems->At(i);
  19.585 +        if(item.iThread == id)
  19.586 +        	{
  19.587 +        	item.iThread = TThreadId(0); 
  19.588 +        	item.iOperation(item.iItem);
  19.589 +        	}
  19.590 +        }
  19.591 +    last = gEpocEnv->iCleanupItems->Count() - 1;
  19.592 +	for(i = last; i >= 0 ; i--)
  19.593 +        {
  19.594 +        TSdlCleanupItem& item = gEpocEnv->iCleanupItems->At(i);
  19.595 +        if(item.iThread == TThreadId(0))
  19.596 +        	{
  19.597 +        	gEpocEnv->iCleanupItems->Delete(i);
  19.598 +        	}
  19.599 +        }
  19.600 +	}
  19.601 +	
  19.602 +void EpocSdlEnv::FreeSurface()
  19.603 +	{
  19.604 +	Request(CSdlAppServ::EAppSrvDsaStatus);
  19.605 +	gEpocEnv->iDsa->Free();
  19.606 +	}
  19.607 +  
  19.608 +void EpocSdlEnv::LockPalette(TBool aLock)
  19.609 +	{
  19.610 +	gEpocEnv->iDsa->LockPalette(aLock);
  19.611 +	}
  19.612 +    
  19.613 +void EpocSdlEnv::ObserverEvent(TInt aService, TInt aParam)
  19.614 +	{
  19.615 +	const TBool sdlThread = RThread().Id() == gEpocEnv->iId;
  19.616 +	const TInt valuea = gEpocEnv->iAppSrv->ObserverEvent(aService, aParam);
  19.617 +	gEpocEnv->iAppSrv->HandleObserverValue(aService, valuea, !sdlThread);
  19.618 +	if(sdlThread)
  19.619 +		{
  19.620 +		gEpocEnv->iAppSrv->SetParam(aParam);
  19.621 +		const TInt valuet = gEpocEnv->iAppSrv->RequestValue(aService);
  19.622 +		gEpocEnv->iAppSrv->HandleObserverValue(aService, valuet, EFalse);	
  19.623 +		}
  19.624 +	}
  19.625 +			
  19.626 +    
  19.627 +TPoint EpocSdlEnv::WindowCoordinates(const TPoint& aPoint)    
  19.628 +    {
  19.629 +    return gEpocEnv->iDsa->WindowCoordinates(aPoint);	
  19.630 +    }
  19.631 +    
  19.632 +void EpocSdlEnv::PanicMain(const TDesC& aInfo, TInt aErr)
  19.633 +    {
  19.634 +    gEpocEnv->iAppSrv->PanicMain(aInfo, aErr);
  19.635 +    }
  19.636 +//Dsa is a low priority ao, it has to wait if its pending event, but ws
  19.637 +//event has been prioritized before it
  19.638 +//this is not called from app thread!
  19.639 +void EpocSdlEnv::WaitDeviceChange() 
  19.640 +    {
  19.641 +  	LockPalette(ETrue);
  19.642 +    gEpocEnv->iAppSrv->RequestValue(CSdlAppServ::EAppSrvWaitDsa);
  19.643 +    const TSize sz = WindowSize();
  19.644 +    const TInt param = reinterpret_cast<TInt>(&sz);
  19.645 +    ObserverEvent(MSDLObserver::EEventScreenSizeChanged, param);
  19.646 +    	
  19.647 +   // RThread().Suspend();
  19.648 +    }  
  19.649 +    
  19.650 +LOCAL_C TBool CheckSdl() 
  19.651 +    {
  19.652 +    TInt isExit = ETrue;
  19.653 +    RThread sdl;
  19.654 +    if(sdl.Open(gEpocEnv->iId) == KErrNone)
  19.655 +        {
  19.656 +        if(sdl.ExitType() == EExitPending)
  19.657 +            {
  19.658 +            isExit = EFalse;
  19.659 +            }
  19.660 +        sdl.Close();
  19.661 +        }
  19.662 +    return isExit;
  19.663 +    }
  19.664 +    
  19.665 +void EpocSdlEnvData::Free()
  19.666 +    {
  19.667 +    if(RThread().Id() == gEpocEnv->iId)
  19.668 +    	{
  19.669 +    	iDsa->Free();
  19.670 +    	return;
  19.671 +    	}
  19.672 +   
  19.673 +    __ASSERT_ALWAYS(iArgv == NULL || CheckSdl(), PANIC(KErrNotReady));
  19.674 +        
  19.675 +    for(TInt i = 0; i < iArgc; i++)
  19.676 +        User::Free( iArgv[i] );
  19.677 +        
  19.678 +    User::Free(iArgv);	
  19.679 +     
  19.680 +    
  19.681 +    delete iEventQueue;
  19.682 +    
  19.683 +    if(iDsa != NULL)
  19.684 +    	iDsa->Free();
  19.685 +    
  19.686 +	delete iDsa;
  19.687 +	delete iAppSrv;
  19.688 +    }
  19.689 +
  19.690 +_LIT(KSDLMain, "SDLMain");
  19.691 +
  19.692 +LOCAL_C int MainL()
  19.693 +    {
  19.694 +    gEpocEnv->iCleanupItems = new (ELeave) CArrayFixFlat<TSdlCleanupItem>(8);
  19.695 +    
  19.696 +    char** envp=0;
  19.697 +     /* !! process exits here if there is "exit()" in main! */
  19.698 +    int ret = 0;
  19.699 +    for(TInt i = 0; i  < 6; i++)
  19.700 +        {
  19.701 +        void* f = (void*) gEpocEnv->iMain[i];
  19.702 +        if(f != NULL)
  19.703 +            {
  19.704 +            switch(i)
  19.705 +                {
  19.706 +                case 0:
  19.707 +                    ret = ((mainfunc1)f)(); 
  19.708 +                    return ret;
  19.709 +                case 3:
  19.710 +                    ((mainfunc1)f)(); 
  19.711 +                    return ret;
  19.712 +                case 1:
  19.713 +                    ret = ((mainfunc2)f)(EpocSdlEnv::Argc(), EpocSdlEnv::Argv());
  19.714 +                    return ret;
  19.715 +                case 4:
  19.716 +                    ((mainfunc2)f)(EpocSdlEnv::Argc(), EpocSdlEnv::Argv());
  19.717 +                    return ret;
  19.718 +                case 2:
  19.719 +                    ret = ((mainfunc3)f)(EpocSdlEnv::Argc(), EpocSdlEnv::Argv(), envp);
  19.720 +                    return ret;
  19.721 +                case 5:
  19.722 +                    ((mainfunc3)f)(EpocSdlEnv::Argc(), EpocSdlEnv::Argv(), envp);
  19.723 +                    return ret;
  19.724 +                }
  19.725 +            }
  19.726 +        }
  19.727 +    PANIC(KErrNotFound);
  19.728 +    return 0;
  19.729 +    }
  19.730 +
  19.731 +LOCAL_C TInt DoMain(TAny* /*aParam*/)
  19.732 +    {
  19.733 +    
  19.734 +    
  19.735 +    CTrapCleanup* cleanup = CTrapCleanup::New();
  19.736 +      	
  19.737 +	TBool fbsconnected = EFalse;
  19.738 +	if(RFbsSession::GetSession() == NULL)
  19.739 +	    {
  19.740 +	    PANIC_IF_ERROR(RFbsSession::Connect());
  19.741 +	    fbsconnected = ETrue;
  19.742 +	    }
  19.743 +	
  19.744 + 	gEpocEnv->iAppSrv->Init();	
  19.745 +
  19.746 +#ifdef SYMBIANC 
  19.747 +    // Create stdlib 
  19.748 +    _REENT;
  19.749 +#endif
  19.750 +
  19.751 +    // Call stdlib main
  19.752 +    int ret = 0;
  19.753 +    
  19.754 +    //completes waiting rendesvous
  19.755 +    RThread::Rendezvous(KErrNone);
  19.756 +    
  19.757 +    TRAPD(err, err = MainL());
  19.758 +    
  19.759 +    EpocSdlEnv::ObserverEvent(MSDLObserver::EEventMainExit, err);
  19.760 +   
  19.761 +    // Free resources and return
  19.762 +    
  19.763 +  	EpocSdlEnv::CleanupItems();
  19.764 +        
  19.765 +    gEpocEnv->iCleanupItems->Reset();
  19.766 +    delete gEpocEnv->iCleanupItems;
  19.767 +    gEpocEnv->iCleanupItems = NULL;
  19.768 +    
  19.769 +    gEpocEnv->Free(); //free up in thread resources 
  19.770 +    
  19.771 +#ifdef SYMBIANC    
  19.772 +    _cleanup(); //this is normally called at exit, I call it here
  19.773 +#endif
  19.774 +
  19.775 +    if(fbsconnected)
  19.776 +        RFbsSession::Disconnect();
  19.777 +    
  19.778 +#ifdef SYMBIANC     
  19.779 +    CloseSTDLIB();
  19.780 +#endif
  19.781 +       
  19.782 + //   delete as;
  19.783 +   	delete cleanup;	
  19.784 +
  19.785 +    return err == KErrNone ? ret : err;;
  19.786 +    }
  19.787 +    
  19.788 +
  19.789 +    
  19.790 +EXPORT_C CSDL::~CSDL()
  19.791 +    {
  19.792 +   	gEpocEnv->Free();
  19.793 +    User::Free(gEpocEnv);
  19.794 +    gEpocEnv->iSdl = NULL;
  19.795 +    }
  19.796 +
  19.797 +EXPORT_C CSDL* CSDL::NewL(TInt aFlags)
  19.798 +    {
  19.799 +    __ASSERT_ALWAYS(gEpocEnv == NULL, PANIC(KErrAlreadyExists));
  19.800 +    gEpocEnv = (EpocSdlEnvData*) User::AllocL(sizeof(EpocSdlEnvData));
  19.801 +    Mem::FillZ(gEpocEnv, sizeof(EpocSdlEnvData));
  19.802 +   
  19.803 +    gEpocEnv->iEpocEnvFlags = aFlags;
  19.804 +    gEpocEnv->iEventQueue = CEventQueue::NewL();
  19.805 +   
  19.806 +    gEpocEnv->iAppSrv = new (ELeave) CSdlAppServ();
  19.807 +    gEpocEnv->iAppSrv->ConstructL();
  19.808 +    
  19.809 +    CSDL* sdl = new (ELeave) CSDL();
  19.810 +    
  19.811 +    gEpocEnv->iSdl = sdl;
  19.812 +    
  19.813 +    return sdl;
  19.814 +    }
  19.815 +    
  19.816 +  /*  
  19.817 +EXPORT_C void CSDL::ReInitL(TFlags aFlags)
  19.818 +	{
  19.819 +	const TFlags prevFlags = gEpocEnv->iEpocEnvFlags;
  19.820 +	gEpocEnv->iEpocEnvFlags = aFlags;
  19.821 +	TInt err = KErrNone;
  19.822 +	if(((prevFlags & EDrawModeDSB) != (aFlags & EDrawModeDSB)) && gEpocEnv->iDsa)
  19.823 +		{
  19.824 +		delete gEpocEnv->iDsa;
  19.825 +		gEpocEnv->iDsa = NULL;
  19.826 +		gEpocEnv->iDsa = CDsa::RecreateL(EpocSdlEnv::Flags(CSDL::EDrawModeDSB));
  19.827 +		}
  19.828 +	}
  19.829 + */
  19.830 +
  19.831 +
  19.832 +EXPORT_C void CSDL::SetContainerWindowL(RWindow& aWindow, RWsSession& aSession, CWsScreenDevice& aDevice)
  19.833 +    {
  19.834 +    if(gEpocEnv->iDsa == NULL)
  19.835 +    	gEpocEnv->iDsa = CDsa::CreateL(aSession);
  19.836 +    gEpocEnv->iDsa->ConstructL(aWindow, aDevice);
  19.837 +    }
  19.838 +        
  19.839 +   
  19.840 +EXPORT_C TThreadId CSDL::CallMainL(const TMainFunc& aFunc, TRequestStatus* const aStatus, const CDesC8Array* const aArg, TInt aFlags, TInt aStackSize)
  19.841 +    {
  19.842 +    ASSERT(gEpocEnv != NULL);
  19.843 +    gEpocEnv->iMain = aFunc;
  19.844 +    const TBool args = aArg != NULL;
  19.845 +    
  19.846 +    gEpocEnv->iArgc = aArg->Count() + 1;
  19.847 +    gEpocEnv->iArgv = (char**) User::AllocL(sizeof(char*) * (gEpocEnv->iArgc + 1));  
  19.848 +      
  19.849 +    TInt k = 0;
  19.850 +    const TFileName processName = RProcess().FileName();
  19.851 +    const TInt len = processName.Length();
  19.852 +    gEpocEnv->iArgv[k] = (char*) User::AllocL(len + 1);
  19.853 +    Mem::Copy(gEpocEnv->iArgv[k], processName.Ptr(), len);
  19.854 +    gEpocEnv->iArgv[k][len] = 0;
  19.855 +      
  19.856 +    for(TInt i =  0; args && (i < aArg->Count()); i++)
  19.857 +        {
  19.858 +        k++;
  19.859 +        const TInt len = aArg->MdcaPoint(i).Length();
  19.860 +        gEpocEnv->iArgv[k] = (char*) User::AllocL(len + 1);
  19.861 +        Mem::Copy(gEpocEnv->iArgv[k], aArg->MdcaPoint(i).Ptr(), len);
  19.862 +        gEpocEnv->iArgv[k][len] = 0;
  19.863 +        }
  19.864 +        
  19.865 +    gEpocEnv->iArgv[gEpocEnv->iArgc] = NULL;
  19.866 +         
  19.867 +    RThread thread;
  19.868 +    User::LeaveIfError(thread.Create(KSDLMain, DoMain, aStackSize, NULL, NULL));
  19.869 +    
  19.870 +    if(aStatus != NULL)
  19.871 +    	{
  19.872 +    	thread.Logon(*aStatus);
  19.873 +    	}
  19.874 +    	
  19.875 +    gEpocEnv->iId = thread.Id();
  19.876 +    thread.SetPriority(EPriorityLess);
  19.877 +    if((aFlags & CSDL::ERequestResume) == 0)
  19.878 +        {
  19.879 +        thread.Resume();
  19.880 +        }
  19.881 +    thread.Close();
  19.882 +    return gEpocEnv->iId;
  19.883 +    }
  19.884 +    
  19.885 +EXPORT_C TInt CSDL::AppendWsEvent(const TWsEvent& aEvent)
  19.886 +    {
  19.887 +    return EpocSdlEnv::EventQueue().Append(aEvent);
  19.888 +    }
  19.889 +    
  19.890 +EXPORT_C void CSDL::SDLPanic(const TDesC& aInfo, TInt aErr)
  19.891 +    {
  19.892 +    EpocSdlEnv::PanicMain(aInfo, aErr);
  19.893 +    }
  19.894 +    
  19.895 +EXPORT_C TInt CSDL::GetSDLCode(TInt aScanCode)
  19.896 +    {
  19.897 +    if(aScanCode < 0)
  19.898 +        return MAX_SCANCODE;
  19.899 +    if(aScanCode >= MAX_SCANCODE)
  19.900 +        return -1;
  19.901 +    return KeyMap()[aScanCode];
  19.902 +    }
  19.903 +    
  19.904 +EXPORT_C TInt CSDL::SDLCodesCount() const
  19.905 +	{
  19.906 +	return MAX_SCANCODE;
  19.907 +	}
  19.908 +	
  19.909 +EXPORT_C void CSDL::ResetSDLCodes()
  19.910 +	{
  19.911 +	ResetKeyMap();
  19.912 +	}
  19.913 +    
  19.914 +EXPORT_C void CSDL::SetOrientation(TOrientationMode aMode)
  19.915 +	{
  19.916 +	gEpocEnv->iDsa->SetOrientation(aMode);
  19.917 +	}
  19.918 +    
  19.919 +EXPORT_C TInt CSDL::SetSDLCode(TInt aScanCode, TInt aSDLCode)
  19.920 +    {
  19.921 +    const TInt current = GetSDLCode(aScanCode);
  19.922 +    if(aScanCode >= 0 && aScanCode < MAX_SCANCODE)
  19.923 +        KeyMap()[aScanCode] = static_cast<SDLKey>(aSDLCode);
  19.924 +    return current;
  19.925 +    }
  19.926 +
  19.927 +
  19.928 +EXPORT_C MSDLObserver* CSDL::Observer()
  19.929 +	{
  19.930 +	return gEpocEnv->iAppSrv->Observer();
  19.931 +	}    
  19.932 +    
  19.933 +EXPORT_C void CSDL::SetObserver(MSDLObserver* aObserver)
  19.934 +	{
  19.935 +	gEpocEnv->iAppSrv->SetObserver(aObserver);
  19.936 +	}
  19.937 +	
  19.938 +EXPORT_C void CSDL::Resume()
  19.939 +	{
  19.940 +	EpocSdlEnv::Resume();
  19.941 +	}
  19.942 +	
  19.943 +EXPORT_C void CSDL::Suspend()
  19.944 +	{
  19.945 +	gEpocEnv->iDsa->DoStop();
  19.946 +	}
  19.947 +	
  19.948 +EXPORT_C CSDL::CSDL()
  19.949 +    {
  19.950 +    }
  19.951 +
  19.952 +EXPORT_C void CSDL::DisableKeyBlocking(CAknAppUi& aAppUi) const
  19.953 +	{
  19.954 +	gEpocEnv->iAppUi = &aAppUi;
  19.955 +	EnvUtils::DisableKeyBlocking();
  19.956 +	}
  19.957 +
  19.958 +EXPORT_C TInt CSDL::SetBlitter(MBlitter* aBlitter)
  19.959 +	{
  19.960 +	if(gEpocEnv && gEpocEnv->iDsa)
  19.961 +		{
  19.962 +		gEpocEnv->iDsa->SetBlitter(aBlitter);
  19.963 +		return KErrNone;
  19.964 +		}
  19.965 +	return KErrNotReady;
  19.966 +	}
  19.967 +		
  19.968 +	
  19.969 +EXPORT_C TInt CSDL::AppendOverlay(MOverlay& aOverlay, TInt aPriority)
  19.970 +	{
  19.971 +	if(gEpocEnv && gEpocEnv->iDsa)
  19.972 +		{
  19.973 +		return gEpocEnv->iDsa->AppendOverlay(aOverlay, aPriority);
  19.974 +		}
  19.975 +	return KErrNotReady;
  19.976 +	}
  19.977 +
  19.978 +EXPORT_C TInt CSDL::RemoveOverlay(MOverlay& aOverlay)	
  19.979 +	{
  19.980 +	if(gEpocEnv && gEpocEnv->iDsa)
  19.981 +		{
  19.982 +		return gEpocEnv->iDsa->RemoveOverlay(aOverlay);
  19.983 +		}
  19.984 +	return KErrNotReady;
  19.985 +	}
  19.986 +
  19.987 +EXPORT_C TInt CSDL::RedrawRequest()
  19.988 +	{
  19.989 +	if(gEpocEnv && gEpocEnv->iDsa)
  19.990 +		{
  19.991 +		return gEpocEnv->iDsa->RedrawRequest();
  19.992 +		}
  19.993 +	return KErrNotReady;
  19.994 +	}
  19.995 +	
  19.996 +/*
  19.997 +EXPORT_C CSDL* CSDL::Current()
  19.998 +    {
  19.999 +    return gEpocEnv != NULL ? gEpocEnv->iSdl : NULL;
 19.1000 +    }
 19.1001 +
 19.1002 +    
 19.1003 +EXPORT_C TInt CSDL::SetVolume(TInt aVolume)
 19.1004 +    {
 19.1005 +    return EpocSdlEnv::SetVolume(aVolume);
 19.1006 +    } 
 19.1007 +    
 19.1008 +EXPORT_C TInt CSDL::Volume() const
 19.1009 +    {
 19.1010 +    return EpocSdlEnv::Volume();
 19.1011 +    }     
 19.1012 +	
 19.1013 +EXPORT_C TInt CSDL::MaxVolume() const
 19.1014 +    {
 19.1015 +    return EpocSdlEnv::MaxVolume();
 19.1016 +    } 	
 19.1017 +*/
 19.1018 +			
 19.1019 +void EnvUtils::DisableKeyBlocking()
 19.1020 +	{
 19.1021 +	if(gEpocEnv->iAppUi != NULL)
 19.1022 +		return CCurrentAppUi::Cast(gEpocEnv->iAppUi)->DisableKeyBlocking();
 19.1023 +	}
 19.1024 +	
 19.1025 +TBool EnvUtils::Rendezvous(RThread& aThread, TRequestStatus& aStatus)
 19.1026 +	{
 19.1027 +	if(gEpocEnv->iId != TThreadId(0) &&
 19.1028 +    		 	aThread.Open(gEpocEnv->iId) &&
 19.1029 +    		  	aThread.ExitType() == EExitPending)
 19.1030 +    			{
 19.1031 +    			aThread.Rendezvous(aStatus);
 19.1032 +    			return ETrue;
 19.1033 +    			}
 19.1034 +    return EFalse;
 19.1035 +	}
 19.1036 +	
 19.1037 +	
 19.1038 +
    20.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    20.2 +++ b/src/main/symbian/EKA2/sdlexe.cpp	Sun Jun 24 18:26:35 2007 +0000
    20.3 @@ -0,0 +1,809 @@
    20.4 +//  INCLUDES
    20.5 +#include <aknapp.h>
    20.6 +#include <aknappui.h>
    20.7 +#include <eikdoc.h>
    20.8 +#include <sdlepocapi.h>
    20.9 +#include <bautils.h>
   20.10 +#include <eikstart.h>
   20.11 +#include <badesca.h>
   20.12 +#include <bautils.h>
   20.13 +#include <apgcli.h>
   20.14 +#include <sdlmain.h>
   20.15 +#include <eikedwin.h>
   20.16 +#include <eiklabel.h>
   20.17 +#include <sdlexe.rsg>
   20.18 +#include <aknglobalmsgquery.h>
   20.19 +#include <apgwgnam.h> 
   20.20 +
   20.21 +
   20.22 +
   20.23 +//  FORWARD DECLARATIONS
   20.24 +class CApaDocument;
   20.25 +
   20.26 +
   20.27 +//const TUid KSDLUID = { 0xF01F605E };
   20.28 +
   20.29 +LOCAL_C void MakeCCmdLineL(const TDesC8& aParam, CDesC8Array& aArray)
   20.30 +    { 
   20.31 +    
   20.32 +    const TChar dq('\"');
   20.33 +
   20.34 +    TLex8 lex(aParam);
   20.35 +    TBool in = EFalse;
   20.36 +
   20.37 +    lex.SkipSpaceAndMark();
   20.38 +
   20.39 +    while(!lex.Eos())
   20.40 +        {
   20.41 +        TPtrC8 ptr;
   20.42 +        if(in)
   20.43 +            {
   20.44 +            const TPtrC8 rem = lex.RemainderFromMark();
   20.45 +            const TInt pos = rem.Locate(dq);
   20.46 +            if(pos > 0)
   20.47 +                {
   20.48 +                lex.Inc(pos);
   20.49 +                ptr.Set(lex.MarkedToken());
   20.50 +                lex.SkipAndMark(1);
   20.51 +                }
   20.52 +            else
   20.53 +                {
   20.54 +                ptr.Set(rem);
   20.55 +                }
   20.56 +            in = EFalse;
   20.57 +            }
   20.58 +        else
   20.59 +            {
   20.60 +            ptr.Set(lex.NextToken());
   20.61 +            const TInt pos = ptr.Locate(dq);
   20.62 +            if(pos == 0)
   20.63 +                {
   20.64 +                lex.UnGetToMark();
   20.65 +                lex.SkipAndMark(1);
   20.66 +                in = ETrue;
   20.67 +                continue; // back to in brace
   20.68 +                }
   20.69 +            else
   20.70 +                lex.SkipSpaceAndMark();
   20.71 +            }
   20.72 +        
   20.73 +        aArray.AppendL(ptr);
   20.74 +
   20.75 +        }
   20.76 +    }  
   20.77 +    
   20.78 +NONSHARABLE_CLASS(TVirtualCursor) : public MOverlay
   20.79 +	{
   20.80 +	public:
   20.81 +		TVirtualCursor();
   20.82 +		void Set(const TRect& aRect, CFbsBitmap* aBmp, CFbsBitmap* aAlpha);
   20.83 +		void Move(TInt aX, TInt aY);
   20.84 +		void MakeEvent(TWsEvent& aEvent, const TPoint& aBasePos) const;
   20.85 +		void Toggle();
   20.86 +		TBool IsOn() const;
   20.87 +	private:
   20.88 +    	void Draw(CBitmapContext& aGc, const TRect& aTargetRect, const TSize& aSize);
   20.89 +	private:
   20.90 +		TRect iRect;
   20.91 +		TPoint iInc;
   20.92 +		TPoint iPos;
   20.93 +		TBool iIsOn;
   20.94 +		CFbsBitmap* iCBmp;
   20.95 +		CFbsBitmap* iAlpha;
   20.96 +	};
   20.97 +	
   20.98 +	
   20.99 +TVirtualCursor::TVirtualCursor() :  iInc(0, 0), iIsOn(EFalse), iCBmp(NULL)
  20.100 +	{	
  20.101 +	}
  20.102 +	
  20.103 +const TInt KMaxMove = 10;	
  20.104 +
  20.105 +void TVirtualCursor::Move(TInt aX, TInt aY)
  20.106 +	{
  20.107 +	if(aX > 0 && iInc.iX > 0)
  20.108 +			++iInc.iX;
  20.109 +	else if(aX < 0 && iInc.iX < 0)
  20.110 +			--iInc.iX;
  20.111 +	else
  20.112 +		iInc.iX = aX;
  20.113 +
  20.114 +	if(aY > 0 && iInc.iY > 0)
  20.115 +			++iInc.iY;
  20.116 +	else if(aY < 0 && iInc.iY < 0)
  20.117 +			--iInc.iY;
  20.118 +	else
  20.119 +			iInc.iY = aY;
  20.120 +	
  20.121 +	iInc.iX = Min(KMaxMove, iInc.iX); 
  20.122 +	
  20.123 +	iInc.iX = Max(-KMaxMove, iInc.iX);
  20.124 +	
  20.125 +	iInc.iY = Min(KMaxMove, iInc.iY);
  20.126 +	
  20.127 +	iInc.iY =Max(-KMaxMove, iInc.iY);
  20.128 +	
  20.129 +	const TPoint pos = iPos + iInc;
  20.130 +	if(iRect.Contains(pos))
  20.131 +		{
  20.132 +		iPos = pos;
  20.133 +		}
  20.134 +	else
  20.135 +		{
  20.136 +		iInc = TPoint(0, 0);	
  20.137 +		}
  20.138 +	}
  20.139 +	
  20.140 +	
  20.141 +void TVirtualCursor::Toggle()
  20.142 +	{
  20.143 +	iIsOn = !iIsOn;
  20.144 +	}
  20.145 +	
  20.146 +	
  20.147 +TBool TVirtualCursor::IsOn() const
  20.148 +	{
  20.149 +	return iIsOn;
  20.150 +	}
  20.151 +	
  20.152 +void TVirtualCursor::Set(const TRect& aRect, CFbsBitmap* aBmp, CFbsBitmap* aAlpha)
  20.153 +	{
  20.154 +	iRect = aRect;
  20.155 +	iCBmp = aBmp;
  20.156 +	iAlpha = aAlpha;
  20.157 +	}
  20.158 +	
  20.159 +		
  20.160 +void TVirtualCursor::MakeEvent(TWsEvent& aEvent, const TPoint& aBasePos) const
  20.161 +	{
  20.162 + 	aEvent.SetType(EEventPointer),
  20.163 +	aEvent.SetTimeNow();
  20.164 +	TPointerEvent& pointer = *aEvent.Pointer();	
  20.165 +	pointer.iType = TPointerEvent::EButton1Down;
  20.166 +	pointer.iPosition = iPos;
  20.167 +	pointer.iParentPosition = aBasePos;
  20.168 +	}
  20.169 +	
  20.170 +	
  20.171 +void TVirtualCursor::Draw(CBitmapContext& aGc, const TRect& /*aTargetRect*/, const TSize& /*aSize*/)
  20.172 +	{
  20.173 +	if(iIsOn && iCBmp != NULL)
  20.174 +		{
  20.175 +		const TRect rect(TPoint(0, 0), iCBmp->SizeInPixels());
  20.176 +		aGc.AlphaBlendBitmaps(iPos, iCBmp, rect, iAlpha, TPoint(0, 0));
  20.177 +		}
  20.178 +	
  20.179 +	}	
  20.180 +
  20.181 +NONSHARABLE_CLASS(TSdlClass)
  20.182 +	{
  20.183 +	public:
  20.184 +		TSdlClass();
  20.185 +		void SetMain(const TMainFunc& aFunc, TInt aFlags, MSDLMainObs* aObs, TInt aExeFlags);
  20.186 +		TInt SdlFlags() const;
  20.187 +		const TMainFunc& Main() const;
  20.188 +		void SendEvent(TInt aEvent, TInt aParam, CSDL* aSDL);
  20.189 +		TInt AppFlags() const; 
  20.190 +		void AppFlags(TInt aFlags); 
  20.191 +	private:
  20.192 +		TMainFunc iFunc;
  20.193 +		TInt iSdlFlags;
  20.194 +		TInt iExeFlags;
  20.195 +		MSDLMainObs* iObs;
  20.196 +	};
  20.197 +	
  20.198 +	
  20.199 +void TSdlClass::AppFlags(TInt aFlags)
  20.200 +	{
  20.201 +	iExeFlags |= aFlags;
  20.202 +	}
  20.203 +	
  20.204 +void TSdlClass::SendEvent(TInt aEvent, TInt aParam, CSDL* aSDL)
  20.205 +	{
  20.206 +	if(iObs != NULL)
  20.207 +		iObs->SDLMainEvent(aEvent, aParam, aSDL);
  20.208 +	}
  20.209 +	
  20.210 +TInt TSdlClass::AppFlags() const
  20.211 +	{
  20.212 +	return iExeFlags;
  20.213 +	}
  20.214 +	
  20.215 +void TSdlClass::SetMain(const TMainFunc& aFunc, TInt aFlags, MSDLMainObs* aObs, TInt aExeFlags)
  20.216 +	{	
  20.217 +	iFunc = aFunc;
  20.218 +	iSdlFlags = aFlags;
  20.219 +	iExeFlags = aExeFlags;
  20.220 +	iObs = aObs;
  20.221 +	}
  20.222 +	
  20.223 +const TMainFunc& TSdlClass::Main() const
  20.224 +	{
  20.225 +	return iFunc;
  20.226 +	}
  20.227 +	
  20.228 + 
  20.229 + TInt TSdlClass::SdlFlags() const
  20.230 + 	{
  20.231 + 	return iSdlFlags;
  20.232 + 	}
  20.233 + 	
  20.234 +
  20.235 + 	
  20.236 +TSdlClass::TSdlClass()
  20.237 +	{
  20.238 +	Mem::FillZ(this, sizeof(this));
  20.239 +	}
  20.240 + 
  20.241 +TSdlClass gSDLClass;    
  20.242 +    
  20.243 +	     
  20.244 +////////////////////////////////////////////////////////////////    
  20.245 +
  20.246 +NONSHARABLE_CLASS(CSDLApplication) : public CAknApplication
  20.247 +    {
  20.248 +    public:
  20.249 +    	CSDLApplication();
  20.250 +    private:
  20.251 +        CApaDocument* CreateDocumentL(); 
  20.252 +        TFileName ResourceFileName() const;
  20.253 +        TUid AppDllUid() const; 
  20.254 +      		void FindMeL();
  20.255 +     		TUid iUid;
  20.256 +    };
  20.257 +    
  20.258 +NONSHARABLE_CLASS(CSDLDocument)  : public CEikDocument
  20.259 +    {
  20.260 +    public:
  20.261 +        CSDLDocument(CEikApplication& aApp);
  20.262 +     private:
  20.263 +     	CEikAppUi* CreateAppUiL();
  20.264 +     
  20.265 +     };
  20.266 +     
  20.267 + ////////////////////////////////////////////////////////////////////
  20.268 + 
  20.269 +     
  20.270 +NONSHARABLE_CLASS(MExitWait)
  20.271 + 	{
  20.272 + 	public:
  20.273 + 		virtual void DoExit(TInt aErr) = 0;
  20.274 + 	};   
  20.275 + 
  20.276 +///////////////////////////////////////////////////////////////////////// 
  20.277 + 	
  20.278 +NONSHARABLE_CLASS(CExitWait) : public CActive
  20.279 + 	{
  20.280 + 	public:
  20.281 + 		CExitWait(MExitWait& aWait);
  20.282 + 		~CExitWait();
  20.283 + 	private:
  20.284 + 		void RunL();
  20.285 + 		void DoCancel();
  20.286 + 	private:
  20.287 + 		MExitWait& iWait;
  20.288 + 		TRequestStatus* iStatusPtr;
  20.289 + 	};
  20.290 + 	
  20.291 +//////////////////////////////////////////////////////////////////////// 
  20.292 +
  20.293 + 	
  20.294 +NONSHARABLE_CLASS(CSDLWin) : public CCoeControl
  20.295 +	{
  20.296 +	public:
  20.297 +		void ConstructL(const TRect& aRect);
  20.298 +		RWindow& GetWindow() const;
  20.299 +		void SetNoDraw();
  20.300 +	private:
  20.301 +		void Draw(const TRect& aRect) const;
  20.302 +	private:
  20.303 +		TBool iNoDraw;
  20.304 +	}; 	
  20.305 +	
  20.306 +
  20.307 +////////////////////////////////////////////////////////////////////////////	
  20.308 +     
  20.309 +NONSHARABLE_CLASS(CSDLAppUi) : public CAknAppUi, public MExitWait, MSDLObserver
  20.310 +	{
  20.311 +	public:
  20.312 +		~CSDLAppUi();
  20.313 +   	private: // New functions
  20.314 + 		void ConstructL(); 
  20.315 +   	void HandleCommandL(TInt aCommand);
  20.316 + 		void HandleWsEventL(const TWsEvent& aEvent, CCoeControl* aDestination);
  20.317 + 		void HandleResourceChangeL(TInt aType);
  20.318 +        
  20.319 +   		void DoExit(TInt aErr);
  20.320 +   	
  20.321 +   		TInt SdlEvent(TInt aEvent, TInt aParam);
  20.322 +    	TInt SdlThreadEvent(TInt aEvent, TInt aParam);
  20.323 +    
  20.324 +    	void StartL();
  20.325 +    	static TBool StartL(TAny* aThis);
  20.326 +    	
  20.327 +    	TBool ParamEditorL(TDes& aCheat);
  20.328 +    	
  20.329 +    	TBool ProcessCommandParametersL(CApaCommandLine &aCommandLine);
  20.330 +    	
  20.331 +    	void PrepareToExit();
  20.332 +    	void HandleConsoleWindowL();
  20.333 +    	void HandleConsoleWindow();
  20.334 +    	void HandleForegroundEventL(TBool aForeground);
  20.335 +    	
  20.336 +    	static TBool IdleRequestL(TAny* aThis);
  20.337 +    	
  20.338 +    	TBool HandleKeyL(const TWsEvent& aEvent);
  20.339 +    
  20.340 +    	
  20.341 +	private:
  20.342 +		CExitWait* iWait;
  20.343 +		CSDLWin* iSDLWin;
  20.344 +		CSDL* iSdl;
  20.345 +		CIdle* iStarter;
  20.346 +		TBool iExitRequest;
  20.347 +		CDesC8Array* iParams;
  20.348 +		TInt iResOffset;
  20.349 +		CIdle* iIdle;
  20.350 +		TInt iStdOut;
  20.351 +		TVirtualCursor iCursor;
  20.352 +		CFbsBitmap*	iCBmp;
  20.353 +		CFbsBitmap*	iAlpha;
  20.354 +	//	TTime iLastPress;
  20.355 +	//	CSDL::TOrientationMode iOrientation;
  20.356 +	};
  20.357 +	
  20.358 +////////////////////////////////////////////////////////////////////////////////////////7
  20.359 +
  20.360 +CApaDocument* CSDLApplication::CreateDocumentL()
  20.361 +	{
  20.362 +	return new (ELeave) CSDLDocument(*this);
  20.363 +	}
  20.364 +	
  20.365 +TUid CSDLApplication::AppDllUid() const
  20.366 +	{
  20.367 +	return iUid;
  20.368 +	}
  20.369 +	
  20.370 +	
  20.371 +CSDLApplication::CSDLApplication()
  20.372 +	{
  20.373 +	TRAPD(err, FindMeL());
  20.374 +	ASSERT(err == KErrNone);
  20.375 +	}	
  20.376 +	
  20.377 +void CSDLApplication::FindMeL()
  20.378 +	{
  20.379 +	RApaLsSession apa;
  20.380 +	User::LeaveIfError(apa.Connect());
  20.381 +	CleanupClosePushL(apa);
  20.382 +	User::LeaveIfError(apa.GetAllApps());
  20.383 +	TFileName name = RProcess().FileName();
  20.384 +	TApaAppInfo info;
  20.385 +	while(apa.GetNextApp(info) == KErrNone)
  20.386 +		{
  20.387 +		if(info.iFullName.CompareF(name) == 0)
  20.388 +			{
  20.389 +			iUid = info.iUid;
  20.390 +			break;
  20.391 +			}
  20.392 +		}
  20.393 +	CleanupStack::PopAndDestroy();
  20.394 +	}
  20.395 +	
  20.396 +TFileName CSDLApplication::ResourceFileName() const
  20.397 +	{
  20.398 +	return KNullDesC();
  20.399 +	}
  20.400 +	
  20.401 +///////////////////////////////////////////////////////////////////////////////////////////
  20.402 +
  20.403 +CExitWait::CExitWait(MExitWait& aWait) : CActive(CActive::EPriorityStandard), iWait(aWait)
  20.404 +	{
  20.405 +	CActiveScheduler::Add(this);
  20.406 +	SetActive();
  20.407 +	iStatusPtr = &iStatus;
  20.408 +	}
  20.409 +	
  20.410 +CExitWait::~CExitWait()
  20.411 +	{
  20.412 +	Cancel();
  20.413 +	}
  20.414 + 
  20.415 +void CExitWait::RunL()
  20.416 +	{
  20.417 +	if(iStatusPtr != NULL )
  20.418 +		iWait.DoExit(iStatus.Int());
  20.419 +	}
  20.420 +	
  20.421 +void CExitWait::DoCancel()
  20.422 +	{
  20.423 +	if(iStatusPtr != NULL )
  20.424 +		User::RequestComplete(iStatusPtr , KErrCancel);
  20.425 +	}
  20.426 +	
  20.427 +
  20.428 +//////////////////////////////////////////////////////////////////////////////////////////////
  20.429 +
  20.430 +CSDLDocument::CSDLDocument(CEikApplication& aApp) : CEikDocument(aApp)
  20.431 +	{}
  20.432 +    
  20.433 +CEikAppUi* CSDLDocument::CreateAppUiL()
  20.434 +	{
  20.435 +	return new (ELeave) CSDLAppUi;
  20.436 +	}
  20.437 +	
  20.438 +///////////////////////////////////////////////////////////////////////////	
  20.439 +	
  20.440 +void CSDLWin:: ConstructL(const TRect& aRect)	
  20.441 +	{
  20.442 +	CreateWindowL();
  20.443 +	SetRect(aRect);
  20.444 +	ActivateL();
  20.445 +	}
  20.446 +	
  20.447 +	
  20.448 +RWindow& CSDLWin::GetWindow() const
  20.449 +	{
  20.450 +	return Window();
  20.451 +	}
  20.452 +	
  20.453 +
  20.454 +void CSDLWin::Draw(const TRect& /*aRect*/) const
  20.455 +	{
  20.456 +	if(!iNoDraw)
  20.457 +		{
  20.458 +		CWindowGc& gc = SystemGc();
  20.459 +		gc.SetPenStyle(CGraphicsContext::ESolidPen);
  20.460 +		gc.SetPenColor(KRgbGray);
  20.461 +		gc.SetBrushStyle(CGraphicsContext::ESolidBrush);
  20.462 +		gc.SetBrushColor(0xaaaaaa);
  20.463 +		gc.DrawRect(Rect());
  20.464 +		}
  20.465 +	}	
  20.466 +	
  20.467 +void CSDLWin::SetNoDraw()
  20.468 +	{
  20.469 +	iNoDraw = ETrue;
  20.470 +	}
  20.471 +
  20.472 +/////////////////////////////////////////////////////////////////////////			
  20.473 +	
  20.474 +CSDLAppUi::~CSDLAppUi()
  20.475 +	{
  20.476 +	if(iIdle)
  20.477 +		iIdle->Cancel();
  20.478 +	delete iIdle;
  20.479 +	if(iStarter != NULL)
  20.480 +		iStarter->Cancel();
  20.481 +	delete iStarter;
  20.482 +	delete iWait;
  20.483 +	delete iSdl;
  20.484 +	delete iSDLWin;
  20.485 +	delete iParams;
  20.486 +	delete iCBmp;
  20.487 +	delete iAlpha;
  20.488 +	}
  20.489 +	
  20.490 +		
  20.491 +void CSDLAppUi::ConstructL()
  20.492 + 	{
  20.493 + 	BaseConstructL(ENoAppResourceFile | ENoScreenFurniture);
  20.494 + 	
  20.495 + 	
  20.496 + 	RLibrary lib;
  20.497 + 	User::LeaveIfError(lib.Load(_L("sdlexe.dll")));
  20.498 + 	TFileName name = lib.FileName();
  20.499 + 	lib.Close();
  20.500 + 	name.Replace(3, name.Length() - 3, _L("resource\\apps\\sdlexe.rsc"));
  20.501 + 	BaflUtils::NearestLanguageFile(iEikonEnv->FsSession(), name);
  20.502 + 	iResOffset = iCoeEnv->AddResourceFileL(name);
  20.503 + 	
  20.504 + 	name.Replace(name.Length() - 3, 3, _L("mbm"));
  20.505 +	
  20.506 +	TEntry e;
  20.507 +	const TInt err = iEikonEnv->FsSession().Entry(name, e);
  20.508 +	
  20.509 +	iCBmp = iEikonEnv->CreateBitmapL(name, 0);
  20.510 +	iAlpha = iEikonEnv->CreateBitmapL(name, 1);	
  20.511 + 	
  20.512 + 	iIdle = CIdle::NewL(CActive::EPriorityIdle);
  20.513 + 	
  20.514 + 	iSDLWin = new (ELeave) CSDLWin;
  20.515 + 	iSDLWin->ConstructL(ApplicationRect());
  20.516 + 	
  20.517 + 	iSdl = CSDL::NewL(gSDLClass.SdlFlags());
  20.518 + 	
  20.519 + 	gSDLClass.SendEvent(MSDLMainObs::ESDLCreated, 0, iSdl);
  20.520 + 	
  20.521 + 	iSdl->SetObserver(this);
  20.522 + 	iSdl->DisableKeyBlocking(*this);
  20.523 + 	iSdl->SetContainerWindowL(
  20.524 + 					iSDLWin->GetWindow(), 
  20.525 +        			iEikonEnv->WsSession(),
  20.526 +        			*iEikonEnv->ScreenDevice());
  20.527 +    iSdl->AppendOverlay(iCursor, 0);
  20.528 +    
  20.529 +    iCursor.Set(TRect(TPoint(0, 0), iSDLWin->Size()), iCBmp, iAlpha);
  20.530 +        			
  20.531 +    iStarter = CIdle::NewL(CActive::EPriorityLow);   
  20.532 +    iStarter->Start(TCallBack(StartL, this));
  20.533 +    
  20.534 +    
  20.535 + 	}
  20.536 + 	
  20.537 +
  20.538 +
  20.539 +TBool CSDLAppUi::StartL(TAny* aThis)
  20.540 +	{
  20.541 +	static_cast<CSDLAppUi*>(aThis)->StartL();
  20.542 +	return EFalse;
  20.543 +	}
  20.544 +	
  20.545 +	
  20.546 +void CSDLAppUi::PrepareToExit()
  20.547 +	{
  20.548 +	CAknAppUiBase::PrepareToExit(); //aknappu::PrepareToExit crashes
  20.549 +	iCoeEnv->DeleteResourceFile(iResOffset);
  20.550 +	}
  20.551 +	
  20.552 +TBool CSDLAppUi::ProcessCommandParametersL(CApaCommandLine &aCommandLine)
  20.553 +	{
  20.554 +	const TPtrC8 cmdLine = aCommandLine.TailEnd();
  20.555 +	iParams = new (ELeave) CDesC8ArrayFlat(8);
  20.556 +	MakeCCmdLineL(cmdLine, *iParams);
  20.557 +	return EFalse;
  20.558 +	}
  20.559 + 	
  20.560 + 
  20.561 + TBool CSDLAppUi::ParamEditorL(TDes& aCheat)
  20.562 +	{
  20.563 +	CAknTextQueryDialog* query = CAknTextQueryDialog::NewL(aCheat);
  20.564 +	CleanupStack::PushL(query);
  20.565 +	query->SetPromptL(_L("Enter parameters"));
  20.566 +	CleanupStack::Pop();
  20.567 +	return query->ExecuteLD(R_PARAMEDITOR);
  20.568 +	}
  20.569 + 	
  20.570 + void CSDLAppUi::StartL()	
  20.571 + 	{ 		
  20.572 + 	if(gSDLClass.AppFlags() & SDLEnv::EParamQuery)
  20.573 + 		{
  20.574 + 		TBuf8<256> cmd;
  20.575 + 		RFile file;
  20.576 + 		TInt err = file.Open(iEikonEnv->FsSession(), _L("sdl_param.txt"),EFileRead);
  20.577 + 		if(err == KErrNone)
  20.578 + 			{
  20.579 + 			file.Read(cmd);
  20.580 + 			file.Close();	
  20.581 + 			MakeCCmdLineL(cmd, *iParams);
  20.582 + 			}
  20.583 + 		if(err != KErrNone || gSDLClass.AppFlags() & (SDLEnv::EParamQueryDialog ^ SDLEnv::EParamQuery))
  20.584 + 			{
  20.585 + 			TBuf<256> buffer;
  20.586 + 			if(ParamEditorL(buffer))
  20.587 + 				{
  20.588 + 				cmd.Copy(buffer);
  20.589 + 				MakeCCmdLineL(cmd, *iParams);
  20.590 + 				}	
  20.591 + 			}
  20.592 + 		}
  20.593 + 	iWait = new (ELeave) CExitWait(*this);
  20.594 + 	iSdl->CallMainL(gSDLClass.Main(), &iWait->iStatus, iParams, CSDL::ENoParamFlags, 0xA000);
  20.595 + 	}
  20.596 + 	
  20.597 +void CSDLAppUi::HandleCommandL(TInt aCommand)
  20.598 +	{
  20.599 +	switch(aCommand)
  20.600 +		{
  20.601 +		case EAknSoftkeyBack:
  20.602 + 		case EAknSoftkeyExit:
  20.603 +		case EAknCmdExit:
  20.604 +		case EEikCmdExit:
  20.605 +			gSDLClass.AppFlags(SDLEnv::EAllowConsoleView); 
  20.606 +		    if(iWait == NULL || !iWait->IsActive() || iSdl == NULL)
  20.607 +		    	{
  20.608 +		    	Exit();
  20.609 +		    	}	
  20.610 +			  else if(!iExitRequest)
  20.611 +			  	{
  20.612 +			  	iExitRequest = ETrue; //trick how SDL can be closed!
  20.613 +			  	iSdl->Suspend();
  20.614 +			  	} 
  20.615 +			break;
  20.616 +		}
  20.617 +	}
  20.618 +	
  20.619 +
  20.620 +	
  20.621 +TBool CSDLAppUi::HandleKeyL(const TWsEvent& aEvent)
  20.622 +	{
  20.623 +	const TInt type = aEvent.Type();
  20.624 +	if(!(type == EEventKey || type == EEventKeyUp || type == EEventKeyDown))
  20.625 + 			{
  20.626 + 			return ETrue;
  20.627 + 			}
  20.628 + 	const TKeyEvent& key = *aEvent.Key();
  20.629 +	if((key.iScanCode == EStdKeyYes) && (gSDLClass.AppFlags() & SDLEnv::EVirtualMouse))
  20.630 + 		{
  20.631 + 		if(type == EEventKeyUp)
  20.632 + 			{
  20.633 + 			iCursor.Toggle();
  20.634 + 			iSdl->RedrawRequest();	
  20.635 + 			}
  20.636 + 		return EFalse;
  20.637 +		}
  20.638 +	if(iCursor.IsOn())
  20.639 +		{
  20.640 +		switch(key.iScanCode)
  20.641 +			{
  20.642 +			case EStdKeyUpArrow:
  20.643 +				iCursor.Move(0, -1);
  20.644 +				break;
  20.645 +			case EStdKeyDownArrow:
  20.646 +				iCursor.Move(0, 1);
  20.647 +				break;
  20.648 +			case EStdKeyLeftArrow:
  20.649 +				iCursor.Move(-1, 0);
  20.650 +				break;
  20.651 +			case EStdKeyRightArrow:
  20.652 +				iCursor.Move(1, 0);
  20.653 +				break; 
  20.654 +			case EStdKeyDevice3:
  20.655 +				if(type == EEventKeyUp)
  20.656 +					{
  20.657 +					TWsEvent event;
  20.658 +					iCursor.MakeEvent(event, iSDLWin->Position());
  20.659 +					iSdl->AppendWsEvent(event);
  20.660 +					}
  20.661 +				return EFalse;
  20.662 +			default:
  20.663 +				return ETrue;
  20.664 +			}
  20.665 +		iSdl->RedrawRequest();	
  20.666 +		return EFalse;
  20.667 +		}
  20.668 +	return ETrue;
  20.669 +	}
  20.670 + 		
  20.671 + void CSDLAppUi::HandleWsEventL(const TWsEvent& aEvent, CCoeControl* aDestination)
  20.672 + 	{
  20.673 + 	if(iSdl && iWait && HandleKeyL(aEvent))
  20.674 + 		iSdl->AppendWsEvent(aEvent);
  20.675 + 	CAknAppUi::HandleWsEventL(aEvent, aDestination);
  20.676 + 	}
  20.677 + 	
  20.678 + void CSDLAppUi::HandleResourceChangeL(TInt aType)
  20.679 + 	{
  20.680 +    CAknAppUi::HandleResourceChangeL(aType);
  20.681 +    if(aType == KEikDynamicLayoutVariantSwitch)
  20.682 +        {  	
  20.683 +        iSDLWin->SetRect(ApplicationRect());
  20.684 +      	iSdl->SetContainerWindowL(
  20.685 +      				iSDLWin->GetWindow(),
  20.686 +        			iEikonEnv->WsSession(),
  20.687 +        			*iEikonEnv->ScreenDevice());
  20.688 +        }
  20.689 + 	}
  20.690 + 	
  20.691 + 	
  20.692 +void CSDLAppUi::DoExit(TInt/*Err*/)
  20.693 +   	{
  20.694 +   	iExitRequest = ETrue;
  20.695 +   	Exit();
  20.696 +   	}
  20.697 +
  20.698 +    
  20.699 + TInt CSDLAppUi::SdlThreadEvent(TInt aEvent, TInt /*aParam*/)    
  20.700 +	{
  20.701 +	switch(aEvent)
  20.702 +		{
  20.703 +		case MSDLObserver::EEventResume:
  20.704 +			break;
  20.705 +		case MSDLObserver::EEventSuspend:
  20.706 +			if(iExitRequest)
  20.707 +				return MSDLObserver::ESuspendNoSuspend;
  20.708 +			break;
  20.709 +		case MSDLObserver::EEventWindowReserved:
  20.710 +			break;
  20.711 +		case MSDLObserver::EEventWindowNotAvailable:
  20.712 +			break;
  20.713 +		case MSDLObserver::EEventScreenSizeChanged:
  20.714 +            break;
  20.715 +		}
  20.716 +	return MSDLObserver::EParameterNone;	
  20.717 +	}
  20.718 +	    
  20.719 +TInt CSDLAppUi::SdlEvent(TInt aEvent, TInt /*aParam*/)    
  20.720 +	{
  20.721 +	switch(aEvent)
  20.722 +		{
  20.723 +		case MSDLObserver::EEventResume:
  20.724 +			break;
  20.725 +		case MSDLObserver::EEventSuspend:
  20.726 +			if(iExitRequest)
  20.727 +				return MSDLObserver::ESuspendNoSuspend;
  20.728 +			break;
  20.729 +		case MSDLObserver::EEventWindowReserved:
  20.730 +			break;
  20.731 +		case MSDLObserver::EEventWindowNotAvailable:
  20.732 +			{
  20.733 +			TRAP_IGNORE(HandleConsoleWindowL());
  20.734 +			}
  20.735 +			break;
  20.736 +		case MSDLObserver::EEventScreenSizeChanged:
  20.737 +     		break;
  20.738 +		case MSDLObserver::EEventKeyMapInit:
  20.739 +			break;
  20.740 +		case MSDLObserver::EEventMainExit:
  20.741 +			if(iStdOut != 0)
  20.742 +				{
  20.743 +				gSDLClass.AppFlags(SDLEnv::EAllowConsoleView); 
  20.744 +				iEikonEnv->WsSession().SetWindowGroupOrdinalPosition(iStdOut, 0);
  20.745 +				}
  20.746 +			break;
  20.747 +		}
  20.748 +	return MSDLObserver::EParameterNone;
  20.749 +	}
  20.750 +	
  20.751 +void CSDLAppUi::HandleForegroundEventL(TBool aForeground)
  20.752 +	{
  20.753 +	CAknAppUi::HandleForegroundEventL(aForeground);	
  20.754 +	if(!aForeground)
  20.755 +		HandleConsoleWindow();
  20.756 +	}
  20.757 +	
  20.758 +void CSDLAppUi::HandleConsoleWindow()
  20.759 +	{
  20.760 +	if(!iIdle->IsActive())
  20.761 +		iIdle->Start(TCallBack(IdleRequestL, this));
  20.762 +	}
  20.763 +	
  20.764 +TBool CSDLAppUi::IdleRequestL(TAny* aThis)
  20.765 +	{
  20.766 +	static_cast<CSDLAppUi*>(aThis)->HandleConsoleWindowL();
  20.767 +	return EFalse;
  20.768 +	}
  20.769 +
  20.770 +void CSDLAppUi::HandleConsoleWindowL()
  20.771 +	{
  20.772 +	if(gSDLClass.AppFlags() & SDLEnv::EAllowConsoleView)
  20.773 +		{
  20.774 +		return;
  20.775 +		}
  20.776 +	RWsSession& ses = iEikonEnv->WsSession();
  20.777 +	const TInt focus = ses.GetFocusWindowGroup();
  20.778 +	CApaWindowGroupName* name = CApaWindowGroupName::NewLC(ses, focus);
  20.779 +	const TPtrC caption = name->Caption();
  20.780 +	if(0 == caption.CompareF(_L("STDOUT")))
  20.781 +		{
  20.782 +		iStdOut = focus;
  20.783 +		ses.SetWindowGroupOrdinalPosition(iEikonEnv->RootWin().Identifier(), 0);
  20.784 +		}
  20.785 +	CleanupStack::PopAndDestroy(); //name
  20.786 +	}
  20.787 +	
  20.788 +	
  20.789 +////////////////////////////////////////////////////////////////////////
  20.790 +
  20.791 +
  20.792 +CApaApplication* NewApplication()
  20.793 +    {
  20.794 +    return new CSDLApplication();
  20.795 +    }
  20.796 +
  20.797 +	
  20.798 +EXPORT_C TInt SDLEnv::SetMain(const TMainFunc& aFunc, TInt aSdlFlags, MSDLMainObs* aObs, TInt aSdlExeFlags)
  20.799 +	{
  20.800 +	gSDLClass.SetMain(aFunc, aSdlFlags, aObs, aSdlExeFlags);
  20.801 +  	return EikStart::RunApplication(NewApplication);
  20.802 +	}	
  20.803 +	
  20.804 +//////////////////////////////////////////////////////////////////////
  20.805 +
  20.806 +TInt SDLUiPrint(const TDesC8& /*aInfo*/)
  20.807 +    {
  20.808 +    return KErrNotFound;
  20.809 +    }    
  20.810 +
  20.811 +
  20.812 +
    21.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    21.2 +++ b/src/main/symbian/EKA2/sdllib.cpp	Sun Jun 24 18:26:35 2007 +0000
    21.3 @@ -0,0 +1,12 @@
    21.4 +#include<eikstart.h>
    21.5 +#include<sdlmain.h>
    21.6 +#include<sdlepocapi.h>
    21.7 +
    21.8 +
    21.9 +GLREF_C TInt E32Main()
   21.10 +    {
   21.11 +    return SDLEnv::SetMain(SDL_main, CSDL::EEnableFocusStop | CSDL::EAllowImageResize,
   21.12 +     NULL, SDLEnv::EParamQuery | SDLEnv::EVirtualMouse);
   21.13 +    }
   21.14 +    
   21.15 +    
   21.16 \ No newline at end of file
    22.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    22.2 +++ b/src/main/symbian/EKA2/vectorbuffer.cpp	Sun Jun 24 18:26:35 2007 +0000
    22.3 @@ -0,0 +1,62 @@
    22.4 +/*
    22.5 +    vectorbuffer.cpp
    22.6 +    yet another circle buffer
    22.7 +
    22.8 +    Markus Mertama
    22.9 +*/
   22.10 +
   22.11 +#include"vectorbuffer.h"
   22.12 +
   22.13 +
   22.14 +
   22.15 +void VectorPanic(TInt aErr, TInt aLine)
   22.16 +    {
   22.17 +    TBuf<64> b;
   22.18 +    b.Format(_L("vector buffer at % d "), aLine);
   22.19 +    User::Panic(b, aErr);
   22.20 +    }
   22.21 +
   22.22 +void TNodeBuffer::TNode::Terminator(TNodeBuffer::TNode* aNode)
   22.23 +    {
   22.24 +    Mem::Copy(iSucc, &aNode, sizeof(TNode*));
   22.25 +    }
   22.26 +
   22.27 +TInt TNodeBuffer::TNode::Size() const
   22.28 +    {
   22.29 +    return reinterpret_cast<const TUint8*>(iSucc) - Ptr();
   22.30 +    }
   22.31 +
   22.32 +const TUint8*  TNodeBuffer::TNode::Ptr() const
   22.33 +    {
   22.34 +    return reinterpret_cast<const TUint8*>(this) + sizeof(TNode);
   22.35 +    }
   22.36 +
   22.37 +TNodeBuffer::TNode*  TNodeBuffer::TNode::Empty(TUint8* aBuffer)
   22.38 +    {
   22.39 +    TNode* node = reinterpret_cast<TNode*>(aBuffer);
   22.40 +    node->iSucc = node + 1;
   22.41 +    return node;
   22.42 +    }
   22.43 +
   22.44 + TNodeBuffer::TNode*  TNodeBuffer::TNode::New(TNode* aPred, const TDesC8& aData)
   22.45 +    {
   22.46 +    TNode* node = aPred->Size() == 0 ? aPred : aPred->iSucc;
   22.47 +
   22.48 +    
   22.49 +    TUint8* start = reinterpret_cast<TUint8*>(node) + sizeof(TNode);
   22.50 +    node->iSucc = reinterpret_cast<TNode*>(start + aData.Size());
   22.51 +    node->iSucc->iSucc = NULL; //terminator
   22.52 +
   22.53 +    __ASSERT_DEBUG(node->Size() == aData.Size(), VECPANIC(KErrCorrupt));
   22.54 +
   22.55 +    Mem::Copy(start, aData.Ptr(), aData.Size());
   22.56 +    return node;
   22.57 +    }
   22.58 +    
   22.59 +
   22.60 +
   22.61 +
   22.62 +
   22.63 +
   22.64 +
   22.65 +    
   22.66 \ No newline at end of file
    23.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    23.2 +++ b/src/main/symbian/EKA2/vectorbuffer.h	Sun Jun 24 18:26:35 2007 +0000
    23.3 @@ -0,0 +1,240 @@
    23.4 +/*
    23.5 +    vectorbuffer.cpp
    23.6 +    yet another circle buffer
    23.7 +
    23.8 +    Markus Mertama
    23.9 +*/
   23.10 +
   23.11 +#ifndef __VECTORBUFFER_H__
   23.12 +#define __VECTORBUFFER_H__
   23.13 +
   23.14 +#include<e32std.h>
   23.15 +#define VLOG(x)
   23.16 +#define VECPANIC(x) VectorPanic(x, __LINE__)
   23.17 +void VectorPanic(TInt, TInt);
   23.18 +
   23.19 +
   23.20 +//int DEBUG_INT;
   23.21 +
   23.22 +NONSHARABLE_CLASS(TNodeBuffer)
   23.23 +    {
   23.24 +    public:
   23.25 +    protected:
   23.26 +        NONSHARABLE_CLASS(TNode)
   23.27 +            {
   23.28 +            public:
   23.29 +                static  TNode* Empty(TUint8* iBuffer);
   23.30 +                static  TNode* New(TNode* aPrev,  const TDesC8& aData);
   23.31 +                const TUint8* Ptr() const;
   23.32 +                TInt Size() const;
   23.33 +                inline TNode* Succ();
   23.34 +                static void SetSucc(TNode*& aNode);
   23.35 +                void Terminator(TNode* aNode);
   23.36 +            private:
   23.37 +                TNode* iSucc;
   23.38 +            };
   23.39 +    };
   23.40 +
   23.41 +inline TNodeBuffer::TNode* TNodeBuffer::TNode::Succ()
   23.42 +    {
   23.43 +    return iSucc;
   23.44 +    }
   23.45 +
   23.46 +template <TInt C>
   23.47 +NONSHARABLE_CLASS(TVectorBuffer) : public TNodeBuffer
   23.48 +    {
   23.49 +    public:
   23.50 +        TVectorBuffer();
   23.51 +        TInt Append(const TDesC8& aData);
   23.52 +     //   TInt AppendOverwrite(const TDesC8& aData);
   23.53 +        TPtrC8 Shift();
   23.54 +        TPtrC8 operator[](TInt aIndex) const;
   23.55 +        TInt Size() const;
   23.56 +    private:
   23.57 +        TInt GetRoom(TInt aSize) const;
   23.58 +        TInt Unreserved() const;
   23.59 +    private:
   23.60 +        TNode* iTop;
   23.61 +        TNode* iBottom;
   23.62 +        TInt iSize;
   23.63 +        TUint8 iBuffer[C];
   23.64 +    };
   23.65 +
   23.66 +template <TInt C>
   23.67 +TVectorBuffer<C>::TVectorBuffer() : iSize(0)
   23.68 +    {
   23.69 +    Mem::FillZ(iBuffer, C);
   23.70 +    iTop = TNode::Empty(iBuffer); //these points to buffer
   23.71 +    iBottom = TNode::Empty(iBuffer);
   23.72 +    }
   23.73 +
   23.74 +template<TInt C >
   23.75 +TInt TVectorBuffer<C>::Unreserved() const
   23.76 +    {
   23.77 +    __ASSERT_DEBUG(iBottom < iBottom->Succ(), VECPANIC(KErrCorrupt));
   23.78 +    const TInt bytesbetween =
   23.79 +        reinterpret_cast<const TUint8*>(iBottom->Succ()) -
   23.80 +        reinterpret_cast<const TUint8*>(iTop);
   23.81 +    const TInt topsize = sizeof(TNode);
   23.82 +    if(bytesbetween > 0)            //bytesbetween is room between bottom and top 
   23.83 +        {                           //therefore free room is subracted from free space 
   23.84 +                    
   23.85 +        const TInt room = C - bytesbetween - topsize; 
   23.86 +        return room;
   23.87 +        }
   23.88 +    if(bytesbetween == 0)           
   23.89 +        {
   23.90 +        
   23.91 +        if(Size() > 0)              
   23.92 +            return 0;               
   23.93 +        else
   23.94 +            return C - topsize;
   23.95 +        }
   23.96 +    const TInt room = -bytesbetween - topsize; //free is space between pointers
   23.97 +    return room;                     
   23.98 +    }
   23.99 +
  23.100 +template <TInt C>
  23.101 +TInt TVectorBuffer<C>::GetRoom(TInt aSize) const
  23.102 +    {
  23.103 +    const TInt bytesnew = sizeof(TNode) + aSize;
  23.104 +    const TInt room = Unreserved() - bytesnew;
  23.105 +    return room;
  23.106 +    }
  23.107 +
  23.108 +template <TInt C>
  23.109 +TInt TVectorBuffer<C>::Append(const TDesC8& aData) //ei ole ok!
  23.110 +    {
  23.111 +    const TInt len = aData.Length();
  23.112 +    if(GetRoom(len) < 0)
  23.113 +        {
  23.114 +        return KErrOverflow;
  23.115 +        }
  23.116 +    if(iBottom->Succ()->Ptr() - iBuffer > (C - (len + TInt(sizeof(TNode)))))
  23.117 +        {
  23.118 +        VLOG("rc");
  23.119 +       // RDebug::Print(_L("vector: append"));
  23.120 +        TNode* p = TNode::Empty(iBuffer);
  23.121 +        iBottom->Terminator(p);
  23.122 +      	iBottom = p;
  23.123 +      	return Append(aData);
  23.124 +     //	Append();
  23.125 +     //	iBottom = TNode::New(p, aData); //just append something into end
  23.126 +        } 
  23.127 +    
  23.128 +    //DEBUG_INT++;
  23.129 +         
  23.130 +    iBottom = TNode::New(iBottom, aData);
  23.131 +
  23.132 +    iSize += len;
  23.133 +    return KErrNone;
  23.134 +    }
  23.135 +
  23.136 +/*
  23.137 +template <TInt C>
  23.138 +TInt TVectorBuffer<C>::AppendOverwrite(const TDesC8& aData) //ei ole ok!
  23.139 +    {
  23.140 +    while(Append(aData) == KErrOverflow)
  23.141 +        {
  23.142 +        if(iTop->Succ() == NULL)
  23.143 +            {
  23.144 +            return KErrUnderflow;
  23.145 +            }
  23.146 +        //Shift(); //data is lost
  23.147 +        }
  23.148 +    return KErrNone;
  23.149 +    }
  23.150 +*/
  23.151 +template <TInt C>
  23.152 +TPtrC8 TVectorBuffer<C>::Shift()
  23.153 +    {
  23.154 +    __ASSERT_ALWAYS(iTop->Succ() != NULL, VECPANIC(KErrUnderflow)); //can never pass-by bottom
  23.155 +    TNode* node = iTop;
  23.156 +    iTop = iTop->Succ();
  23.157 +    if(iTop > node)
  23.158 +        {
  23.159 +      //  DEBUG_INT--;
  23.160 +        iSize -= node->Size();
  23.161 +        return TPtrC8(node->Ptr(), node->Size());
  23.162 +        }
  23.163 +    else
  23.164 +        {
  23.165 +      //  RDebug::Print(_L("vector: shift"));
  23.166 +        return Shift(); //this happens when buffer is terminated, and data lies in next 
  23.167 +        }
  23.168 +    }
  23.169 +
  23.170 +template <TInt C>
  23.171 +TInt TVectorBuffer<C>::Size() const
  23.172 +    {
  23.173 +    return iSize;
  23.174 +    }
  23.175 +
  23.176 +template <TInt C>
  23.177 +TPtrC8 TVectorBuffer<C>::operator[](TInt aIndex) const
  23.178 +    {
  23.179 +    TInt index = 0;
  23.180 +    TNode* t = iTop->Size() > 0 ? iTop : iTop->Succ(); //eliminate terminator
  23.181 +    while(index < aIndex)
  23.182 +        {
  23.183 +        TNode* nt = t->Succ();
  23.184 +        if(nt < t)
  23.185 +            {
  23.186 +            nt = nt->Succ();
  23.187 +            }
  23.188 +        t = nt;
  23.189 +        if(t->Size() > 0)
  23.190 +        	index++;
  23.191 +        __ASSERT_ALWAYS(t->Succ() != NULL, VECPANIC(KErrUnderflow)); //can never pass-by bottom
  23.192 +        }
  23.193 +    return t->Ptr();
  23.194 +    }
  23.195 +
  23.196 +
  23.197 +template <class T, TInt C>
  23.198 +NONSHARABLE_CLASS(TVector) : public TVectorBuffer<C * sizeof(T)>
  23.199 +    {
  23.200 +    public:
  23.201 +        TVector();
  23.202 +        TInt Append(const T& aData);
  23.203 +        const T& Shift();
  23.204 +        TInt Size() const;
  23.205 +        const T& operator[](TInt aIndex) const;
  23.206 +    };
  23.207 +
  23.208 +template <class T, TInt C>
  23.209 +TVector<T, C>::TVector() : TVectorBuffer<C * sizeof(T)>()
  23.210 +    {
  23.211 +    }
  23.212 +
  23.213 +template <class T, TInt C>
  23.214 +TInt TVector<T, C>::Append(const T& aData)
  23.215 +    {
  23.216 +    const TPckgC<T> data(aData);
  23.217 +    return TVectorBuffer<C * sizeof(T)>::Append(data);
  23.218 +    }
  23.219 +
  23.220 +template <class T, TInt C>
  23.221 +const T& TVector<T, C>::Shift()
  23.222 +    {
  23.223 +    const TPtrC8 ptr = TVectorBuffer<C * sizeof(T)>::Shift();
  23.224 +    return *(reinterpret_cast<const T*>(ptr.Ptr()));
  23.225 +    }
  23.226 +
  23.227 +
  23.228 +template <class T, TInt C>
  23.229 +TInt TVector<T, C>::Size() const
  23.230 +    {
  23.231 +    return TVectorBuffer<C * sizeof(T)>::Size() / sizeof(T);
  23.232 +    }
  23.233 +
  23.234 +template <class T, TInt C>
  23.235 +const T& TVector<T, C>::operator[](TInt aIndex) const
  23.236 +    {
  23.237 +    const TPtrC8 ptr = TVectorBuffer<C * sizeof(T)>::operator[](aIndex);
  23.238 +    return *(reinterpret_cast<const T*>(ptr.Ptr()));
  23.239 +    }
  23.240 +
  23.241 +#endif
  23.242 +
  23.243 +
    24.1 --- a/src/stdlib/SDL_getenv.c	Thu Jun 21 18:48:13 2007 +0000
    24.2 +++ b/src/stdlib/SDL_getenv.c	Sun Jun 24 18:26:35 2007 +0000
    24.3 @@ -25,7 +25,7 @@
    24.4  
    24.5  #ifndef HAVE_GETENV
    24.6  
    24.7 -#if defined(__WIN32__) && !defined(_WIN32_WCE)
    24.8 +#if defined(__WIN32__) && !defined(_WIN32_WCE) && !defined(__SYMBIAN32__)
    24.9  
   24.10  #define WIN32_LEAN_AND_MEAN
   24.11  #include <windows.h>
    25.1 --- a/src/thread/SDL_thread_c.h	Thu Jun 21 18:48:13 2007 +0000
    25.2 +++ b/src/thread/SDL_thread_c.h	Sun Jun 24 18:26:35 2007 +0000
    25.3 @@ -31,8 +31,6 @@
    25.4  #include "beos/SDL_systhread_c.h"
    25.5  #elif SDL_THREAD_DC
    25.6  #include "dc/SDL_systhread_c.h"
    25.7 -#elif SDL_THREAD_EPOC
    25.8 -#include "epoc/SDL_systhread_c.h"
    25.9  #elif SDL_THREAD_OS2
   25.10  #include "os2/SDL_systhread_c.h"
   25.11  #elif SDL_THREAD_PTH
   25.12 @@ -43,6 +41,8 @@
   25.13  #include "irix/SDL_systhread_c.h"
   25.14  #elif SDL_THREAD_WIN32
   25.15  #include "win32/SDL_systhread_c.h"
   25.16 +#elif SDL_THREAD_SYMBIAN
   25.17 +#include "symbian/SDL_systhread_c.h"
   25.18  #else
   25.19  #error Need thread implementation for this platform
   25.20  #include "generic/SDL_systhread_c.h"
    26.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    26.2 +++ b/src/thread/symbian/SDL_sysmutex.cpp	Sun Jun 24 18:26:35 2007 +0000
    26.3 @@ -0,0 +1,130 @@
    26.4 +/*
    26.5 +    SDL - Simple DirectMedia Layer
    26.6 +    Copyright (C) 1997, 1998, 1999, 2000  Sam Lantinga
    26.7 +
    26.8 +    This library is free software; you can redistribute it and/or
    26.9 +    modify it under the terms of the GNU Library General Public
   26.10 +    License as published by the Free Software Foundation; either
   26.11 +    version 2 of the License, or (at your option) any later version.
   26.12 +
   26.13 +    This library is distributed in the hope that it will be useful,
   26.14 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
   26.15 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   26.16 +    Library General Public License for more details.
   26.17 +
   26.18 +    You should have received a copy of the GNU Library General Public
   26.19 +    License along with this library; if not, write to the Free
   26.20 +    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   26.21 +
   26.22 +    Sam Lantinga
   26.23 +    slouken@devolution.com
   26.24 +*/
   26.25 +
   26.26 +/*
   26.27 +    SDL_sysmutex.cpp
   26.28 +
   26.29 +    Epoc version by Markus Mertama (w@iki.fi)
   26.30 +*/
   26.31 +
   26.32 +
   26.33 +#ifdef SAVE_RCSID
   26.34 +static char rcsid =
   26.35 + "@(#) $Id: SDL_sysmutex.c,v 1.1.2.3 2000/06/22 15:25:23 hercules Exp $";
   26.36 +#endif
   26.37 +
   26.38 +/* Mutex functions using the Win32 API */
   26.39 +
   26.40 +//#include <stdio.h>
   26.41 +//#include <stdlib.h>
   26.42 +
   26.43 +#include <e32std.h>
   26.44 +
   26.45 +#include "epoc_sdl.h"
   26.46 +
   26.47 +#include "SDL_error.h"
   26.48 +#include "SDL_mutex.h"
   26.49 +
   26.50 +
   26.51 +#ifdef EKA2 //???
   26.52 +struct SDL_mutex
   26.53 +    {
   26.54 +    TInt handle;
   26.55 +    };
   26.56 +#else
   26.57 +struct _SDL_mutex
   26.58 +    {
   26.59 +    TInt handle;
   26.60 +    };
   26.61 +#endif
   26.62 +
   26.63 +extern TInt CreateUnique(TInt (*aFunc)(const TDesC& aName, TAny*, TAny*), TAny*, TAny*);
   26.64 +
   26.65 +TInt NewMutex(const TDesC& aName, TAny* aPtr1, TAny*)
   26.66 +    {
   26.67 +    return ((RMutex*)aPtr1)->CreateGlobal(aName);
   26.68 +    }
   26.69 +    
   26.70 +void DeleteMutex(TAny* aMutex)
   26.71 +    {
   26.72 +    SDL_DestroyMutex ((SDL_mutex*) aMutex);
   26.73 +    }
   26.74 +
   26.75 +/* Create a mutex */
   26.76 +SDL_mutex *SDL_CreateMutex(void)
   26.77 +{
   26.78 +    RMutex rmutex;
   26.79 +
   26.80 +    TInt status = CreateUnique(NewMutex, &rmutex, NULL);
   26.81 +	if(status != KErrNone)
   26.82 +	    {
   26.83 +			SDL_SetError("Couldn't create mutex");
   26.84 +		}
   26.85 +    SDL_mutex* mutex = new /*(ELeave)*/ SDL_mutex;
   26.86 +    mutex->handle = rmutex.Handle();
   26.87 +    EpocSdlEnv::AppendCleanupItem(TSdlCleanupItem(DeleteMutex, mutex));
   26.88 +	return(mutex);
   26.89 +}
   26.90 +
   26.91 +/* Free the mutex */
   26.92 +void SDL_DestroyMutex(SDL_mutex *mutex)
   26.93 +{
   26.94 +	if ( mutex ) 
   26.95 +	{
   26.96 +    RMutex rmutex;
   26.97 +    rmutex.SetHandle(mutex->handle);
   26.98 +    if(rmutex.IsHeld())
   26.99 +        {
  26.100 +	    rmutex.Signal();
  26.101 +        }
  26.102 +	rmutex.Close();
  26.103 +	EpocSdlEnv::RemoveCleanupItem(mutex);
  26.104 +	delete(mutex);
  26.105 +    mutex = NULL;
  26.106 +	}
  26.107 +}
  26.108 +
  26.109 +/* Lock the mutex */
  26.110 +int SDL_mutexP(SDL_mutex *mutex)
  26.111 +{
  26.112 +	if ( mutex == NULL ) {
  26.113 +		SDL_SetError("Passed a NULL mutex");
  26.114 +		return -1;
  26.115 +	}
  26.116 +    RMutex rmutex;
  26.117 +    rmutex.SetHandle(mutex->handle);
  26.118 +	rmutex.Wait(); 
  26.119 +	return(0);
  26.120 +}
  26.121 +
  26.122 +/* Unlock the mutex */
  26.123 +int SDL_mutexV(SDL_mutex *mutex)
  26.124 +{
  26.125 +	if ( mutex == NULL ) {
  26.126 +		SDL_SetError("Passed a NULL mutex");
  26.127 +		return -1;
  26.128 +	}
  26.129 +	RMutex rmutex;
  26.130 +    rmutex.SetHandle(mutex->handle);
  26.131 +	rmutex.Signal();
  26.132 +	return(0);
  26.133 +}
    27.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    27.2 +++ b/src/thread/symbian/SDL_syssem.cpp	Sun Jun 24 18:26:35 2007 +0000
    27.3 @@ -0,0 +1,214 @@
    27.4 +/*
    27.5 +    SDL - Simple DirectMedia Layer
    27.6 +    Copyright (C) 1997, 1998, 1999, 2000  Sam Lantinga
    27.7 +
    27.8 +    This library is free software; you can redistribute it and/or
    27.9 +    modify it under the terms of the GNU Library General Public
   27.10 +    License as published by the Free Software Foundation; either
   27.11 +    version 2 of the License, or (at your option) any later version.
   27.12 +
   27.13 +    This library is distributed in the hope that it will be useful,
   27.14 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
   27.15 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   27.16 +    Library General Public License for more details.
   27.17 +
   27.18 +    You should have received a copy of the GNU Library General Public
   27.19 +    License along with this library; if not, write to the Free
   27.20 +    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   27.21 +
   27.22 +    Sam Lantinga
   27.23 +    slouken@devolution.com
   27.24 +*/
   27.25 +
   27.26 +/*
   27.27 +    SDL_syssem.cpp
   27.28 +
   27.29 +    Epoc version by Markus Mertama  (w@iki.fi)
   27.30 +*/
   27.31 +
   27.32 +#ifdef SAVE_RCSID
   27.33 +static char rcsid =
   27.34 + "@(#) $Id: SDL_syssem.c,v 1.1.2.4 2000/06/22 15:24:48 hercules Exp $";
   27.35 +#endif
   27.36 +
   27.37 +/* Semaphore functions using the Win32 API */
   27.38 +
   27.39 +//#include <stdio.h>
   27.40 +//#include <stdlib.h>
   27.41 +#include <e32std.h>
   27.42 +
   27.43 +#include "SDL_error.h"
   27.44 +#include "SDL_thread.h"
   27.45 +
   27.46 +
   27.47 +#define SDL_MUTEX_TIMEOUT -2
   27.48 +
   27.49 +struct SDL_semaphore
   27.50 + {
   27.51 + TInt handle;
   27.52 + TInt count;
   27.53 + };
   27.54 +
   27.55 +
   27.56 +extern TInt CreateUnique(TInt (*aFunc)(const TDesC& aName, TAny*, TAny*), TAny*, TAny*);
   27.57 +#ifndef EKA2
   27.58 +extern TInt NewThread(const TDesC& aName, TAny* aPtr1, TAny* aPtr2);
   27.59 +#endif
   27.60 +
   27.61 +TInt NewSema(const TDesC& aName, TAny* aPtr1, TAny* aPtr2) 
   27.62 +    {
   27.63 +    TInt value = *((TInt*) aPtr2);
   27.64 +    return ((RSemaphore*)aPtr1)->CreateGlobal(aName, value);
   27.65 +    }
   27.66 +
   27.67 +/* Create a semaphore */
   27.68 +SDL_sem *SDL_CreateSemaphore(Uint32 initial_value)
   27.69 +{
   27.70 +   RSemaphore s;
   27.71 +   TInt status = CreateUnique(NewSema, &s, &initial_value);
   27.72 +   if(status != KErrNone)
   27.73 +	 {
   27.74 +			SDL_SetError("Couldn't create semaphore");
   27.75 +	}
   27.76 +    SDL_semaphore* sem = new /*(ELeave)*/ SDL_semaphore;  
   27.77 +    sem->handle = s.Handle();
   27.78 +	sem->count = initial_value;
   27.79 +	return(sem);
   27.80 +}
   27.81 +
   27.82 +/* Free the semaphore */
   27.83 +void SDL_DestroySemaphore(SDL_sem *sem)
   27.84 +{
   27.85 +	if ( sem ) 
   27.86 +	{
   27.87 +    RSemaphore sema;
   27.88 +    sema.SetHandle(sem->handle);
   27.89 +	while(--sem->count)
   27.90 +	    sema.Signal();
   27.91 +    sema.Close();
   27.92 +    delete sem;
   27.93 +	sem = NULL;
   27.94 +	}
   27.95 +}
   27.96 +
   27.97 +#ifndef EKA2
   27.98 +
   27.99 +  struct TInfo
  27.100 +    {
  27.101 +        TInfo(TInt aTime, TInt aHandle) : 
  27.102 +        iTime(aTime), iHandle(aHandle), iVal(0) {}
  27.103 +        TInt iTime;
  27.104 +        TInt iHandle;
  27.105 +        TInt iVal; 
  27.106 +    };
  27.107 +
  27.108 +
  27.109 +
  27.110 +TBool ThreadRun(TAny* aInfo)
  27.111 +    {
  27.112 +        TInfo* info = STATIC_CAST(TInfo*, aInfo);
  27.113 +        User::After(info->iTime);
  27.114 +        RSemaphore sema;
  27.115 +        sema.SetHandle(info->iHandle);
  27.116 +        sema.Signal();
  27.117 +        info->iVal = SDL_MUTEX_TIMEOUT;
  27.118 +        return 0;
  27.119 +    }
  27.120 +    
  27.121 +#endif 
  27.122 +    
  27.123 +    
  27.124 +void _WaitAll(SDL_sem *sem)
  27.125 +    {
  27.126 +       //since SemTryWait may changed the counter.
  27.127 +       //this may not be atomic, but hopes it works.
  27.128 +    RSemaphore sema;
  27.129 +    sema.SetHandle(sem->handle);
  27.130 +    sema.Wait();
  27.131 +    while(sem->count < 0)
  27.132 +        {
  27.133 +        sema.Wait();
  27.134 +        }    
  27.135 +    }
  27.136 +
  27.137 +int SDL_SemWaitTimeout(SDL_sem *sem, Uint32 timeout)
  27.138 +{
  27.139 +	if ( ! sem ) {
  27.140 +		SDL_SetError("Passed a NULL sem");
  27.141 +		return -1;
  27.142 +	}
  27.143 +
  27.144 +	if ( timeout == SDL_MUTEX_MAXWAIT )
  27.145 +	    {
  27.146 +	    _WaitAll(sem);
  27.147 +		return SDL_MUTEX_MAXWAIT;
  27.148 +	    } 
  27.149 +	
  27.150 +#ifdef EKA2
  27.151 +
  27.152 +    RSemaphore sema;
  27.153 +    sema.SetHandle(sem->handle);
  27.154 +    if(KErrNone == sema.Wait(timeout))
  27.155 +    	return 0;
  27.156 +    return -1;
  27.157 +#else
  27.158 +	RThread thread;
  27.159 +	
  27.160 +	TInfo* info = new (ELeave)TInfo(timeout, sem->handle);
  27.161 +	
  27.162 +    TInt status = CreateUnique(NewThread, &thread, info);
  27.163 +  
  27.164 +	if(status != KErrNone)
  27.165 +	    return status;
  27.166 +	
  27.167 +	thread.Resume();
  27.168 +	
  27.169 +	_WaitAll(sem);
  27.170 +	
  27.171 +	if(thread.ExitType() == EExitPending)
  27.172 +	    {
  27.173 +	        thread.Kill(SDL_MUTEX_TIMEOUT);
  27.174 +	    }
  27.175 +	
  27.176 +	thread.Close();
  27.177 +	
  27.178 +	return info->iVal;
  27.179 +#endif
  27.180 +}
  27.181 +
  27.182 +int SDL_SemTryWait(SDL_sem *sem)
  27.183 +{
  27.184 +    if(sem->count > 0)
  27.185 +        {
  27.186 +        sem->count--;
  27.187 +        }
  27.188 +    return SDL_MUTEX_TIMEOUT;
  27.189 +}
  27.190 +
  27.191 +int SDL_SemWait(SDL_sem *sem) 
  27.192 +{
  27.193 +	return SDL_SemWaitTimeout(sem, SDL_MUTEX_MAXWAIT);
  27.194 +}
  27.195 +
  27.196 +/* Returns the current count of the semaphore */
  27.197 +Uint32 SDL_SemValue(SDL_sem *sem)
  27.198 +{
  27.199 +	if ( ! sem ) {
  27.200 +		SDL_SetError("Passed a NULL sem");
  27.201 +		return 0;
  27.202 +	}
  27.203 +	return sem->count;
  27.204 +}
  27.205 +
  27.206 +int SDL_SemPost(SDL_sem *sem)
  27.207 +{
  27.208 +	if ( ! sem ) {
  27.209 +		SDL_SetError("Passed a NULL sem");
  27.210 +		return -1;
  27.211 +	}
  27.212 +	sem->count++;
  27.213 +    RSemaphore sema;
  27.214 +    sema.SetHandle(sem->handle);
  27.215 +	sema.Signal();
  27.216 +	return 0;
  27.217 +}
    28.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    28.2 +++ b/src/thread/symbian/SDL_systhread.cpp	Sun Jun 24 18:26:35 2007 +0000
    28.3 @@ -0,0 +1,146 @@
    28.4 +/*
    28.5 +    SDL - Simple DirectMedia Layer
    28.6 +    Copyright (C) 1997, 1998, 1999, 2000  Sam Lantinga
    28.7 +
    28.8 +    This library is free software; you can redistribute it and/or
    28.9 +    modify it under the terms of the GNU Library General Public
   28.10 +    License as published by the Free Software Foundation; either
   28.11 +    version 2 of the License, or (at your option) any later version.
   28.12 +
   28.13 +    This library is distributed in the hope that it will be useful,
   28.14 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
   28.15 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   28.16 +    Library General Public License for more details.
   28.17 +
   28.18 +    You should have received a copy of the GNU Library General Public
   28.19 +    License along with this library; if not, write to the Free
   28.20 +    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   28.21 +
   28.22 +    Sam Lantinga
   28.23 +    slouken@devolution.com
   28.24 +*/
   28.25 +
   28.26 +/*
   28.27 +    SDL_systhread.cpp
   28.28 +    Epoc thread management routines for SDL
   28.29 +
   28.30 +    Epoc version by Markus Mertama  (w@iki.fi)
   28.31 +*/
   28.32 +
   28.33 +#include "epoc_sdl.h"
   28.34 +
   28.35 +//#include <stdlib.h>
   28.36 +//#include <stdio.h>
   28.37 +
   28.38 +
   28.39 +
   28.40 +extern "C" {
   28.41 +#undef NULL
   28.42 +#include "SDL_error.h"
   28.43 +#include "SDL_thread.h"
   28.44 +#include "SDL_systhread.h"
   28.45 +#include "SDL_thread_c.h"
   28.46 +    }
   28.47 +
   28.48 +#include <e32std.h>
   28.49 +#include "epoc_sdl.h"
   28.50 +
   28.51 +
   28.52 +static int object_count;
   28.53 +
   28.54 +int RunThread(TAny* data)
   28.55 +{
   28.56 +	CTrapCleanup* cleanup = CTrapCleanup::New();
   28.57 +	TRAPD(err, SDL_RunThread(data));
   28.58 +	EpocSdlEnv::CleanupItems();
   28.59 +	delete cleanup;
   28.60 +	return(err);
   28.61 +}
   28.62 +
   28.63 +
   28.64 +TInt NewThread(const TDesC& aName, TAny* aPtr1, TAny* aPtr2)
   28.65 +    {
   28.66 +    return ((RThread*)(aPtr1))->Create(aName,
   28.67 +            RunThread,
   28.68 +            KDefaultStackSize,
   28.69 +            NULL,
   28.70 +            aPtr2);
   28.71 +    }
   28.72 +
   28.73 +int CreateUnique(TInt (*aFunc)(const TDesC& aName, TAny*, TAny*), TAny* aPtr1, TAny* aPtr2)
   28.74 +    {
   28.75 +    TBuf<16> name;
   28.76 +    TInt status = KErrNone;
   28.77 +    do
   28.78 +        {
   28.79 +        object_count++;
   28.80 +        name.Format(_L("SDL_%x"), object_count);
   28.81 +        status = aFunc(name, aPtr1, aPtr2);
   28.82 +        }
   28.83 +        while(status == KErrAlreadyExists);
   28.84 +    return status;
   28.85 +    }
   28.86 +
   28.87 +
   28.88 +int SDL_SYS_CreateThread(SDL_Thread *thread, void *args)
   28.89 +{
   28.90 +    RThread rthread;
   28.91 +   
   28.92 +    const TInt status = CreateUnique(NewThread, &rthread, args);
   28.93 +    if (status != KErrNone) 
   28.94 +    {
   28.95 +        delete(((RThread*)(thread->handle)));
   28.96 +        thread->handle = NULL;
   28.97 +		SDL_SetError("Not enough resources to create thread");
   28.98 +		return(-1);
   28.99 +	}
  28.100 +	rthread.Resume();
  28.101 +    thread->handle = rthread.Handle();
  28.102 +	return(0);
  28.103 +}
  28.104 +
  28.105 +void SDL_SYS_SetupThread(void)
  28.106 +{
  28.107 +	return;
  28.108 +}
  28.109 +
  28.110 +Uint32 SDL_ThreadID(void)
  28.111 +{
  28.112 +    RThread current;
  28.113 +    const TThreadId id = current.Id();
  28.114 +	return id;
  28.115 +}
  28.116 +
  28.117 +void SDL_SYS_WaitThread(SDL_Thread *thread)
  28.118 +{
  28.119 +    SDL_TRACE1("Close thread", thread);
  28.120 +    RThread t;
  28.121 +    const TInt err = t.Open(thread->threadid);
  28.122 +    if(err == KErrNone && t.ExitType() == EExitPending)
  28.123 +        {
  28.124 +        TRequestStatus status;
  28.125 +        t.Logon(status);
  28.126 +        User::WaitForRequest(status);
  28.127 +        }
  28.128 +    t.Close();
  28.129 +    
  28.130 +  /*  RUndertaker taker;
  28.131 +    taker.Create();
  28.132 +    TRequestStatus status;
  28.133 +    taker.Logon(status, thread->handle);
  28.134 +    User::WaitForRequest(status);
  28.135 +    taker.Close();*/
  28.136 +    SDL_TRACE1("Closed thread", thread);
  28.137 +}
  28.138 +
  28.139 +/* WARNING: This function is really a last resort.
  28.140 + * Threads should be signaled and then exit by themselves.
  28.141 + * TerminateThread() doesn't perform stack and DLL cleanup.
  28.142 + */
  28.143 +void SDL_SYS_KillThread(SDL_Thread *thread)
  28.144 +{
  28.145 +    RThread rthread;
  28.146 +    rthread.SetHandle(thread->handle);
  28.147 +	rthread.Kill(0);
  28.148 +	rthread.Close();
  28.149 +}
    29.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    29.2 +++ b/src/thread/symbian/SDL_systhread_c.h	Sun Jun 24 18:26:35 2007 +0000
    29.3 @@ -0,0 +1,30 @@
    29.4 +/*
    29.5 +    SDL - Simple DirectMedia Layer
    29.6 +    Copyright (C) 1997, 1998, 1999, 2000  Sam Lantinga
    29.7 +
    29.8 +    This library is free software; you can redistribute it and/or
    29.9 +    modify it under the terms of the GNU Library General Public
   29.10 +    License as published by the Free Software Foundation; either
   29.11 +    version 2 of the License, or (at your option) any later version.
   29.12 +
   29.13 +    This library is distributed in the hope that it will be useful,
   29.14 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
   29.15 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   29.16 +    Library General Public License for more details.
   29.17 +
   29.18 +    You should have received a copy of the GNU Library General Public
   29.19 +    License along with this library; if not, write to the Free
   29.20 +    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   29.21 +
   29.22 +    Sam Lantinga
   29.23 +    slouken@devolution.com
   29.24 +*/
   29.25 +
   29.26 +/*
   29.27 +    SDL_systhread_c.h
   29.28 +
   29.29 +    Epoc version by Markus Mertama (w@iki.fi)
   29.30 +*/
   29.31 +
   29.32 +typedef int SYS_ThreadHandle;
   29.33 +
    30.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    30.2 +++ b/src/timer/symbian/SDL_systimer.cpp	Sun Jun 24 18:26:35 2007 +0000
    30.3 @@ -0,0 +1,114 @@
    30.4 +/*
    30.5 +    SDL - Simple DirectMedia Layer
    30.6 +    Copyright (C) 1997, 1998, 1999, 2000, 2001  Sam Lantinga
    30.7 +
    30.8 +    This library is free software; you can redistribute it and/or
    30.9 +    modify it under the terms of the GNU Library General Public
   30.10 +    License as published by the Free Software Foundation; either
   30.11 +    version 2 of the License, or (at your option) any later version.
   30.12 +
   30.13 +    This library is distributed in the hope that it will be useful,
   30.14 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
   30.15 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   30.16 +    Library General Public License for more details.
   30.17 +
   30.18 +    You should have received a copy of the GNU Library General Public
   30.19 +    License along with this library; if not, write to the Free
   30.20 +    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   30.21 +
   30.22 +    Sam Lantinga
   30.23 +    slouken@devolution.com
   30.24 +*/
   30.25 +
   30.26 +/*
   30.27 +    SDL_systimer.cpp
   30.28 +
   30.29 +    Epoc version by Hannu Viitala (hannu.j.viitala@mbnet.fi) 
   30.30 +    Markus Mertama
   30.31 +*/
   30.32 +
   30.33 +#include <e32std.h>
   30.34 +#include <e32hal.h>
   30.35 +
   30.36 +extern "C" {
   30.37 +#include "SDL_error.h"
   30.38 +#include "SDL_thread.h"
   30.39 +#include "SDL_timer.h"
   30.40 +#include "SDL_timer_c.h"
   30.41 +
   30.42 +static TUint start = 0;
   30.43 +static TInt tickPeriodMilliSeconds;
   30.44 +
   30.45 +
   30.46 +void SDL_StartTicks(void)
   30.47 +	{
   30.48 +	/* Set first ticks value */
   30.49 +    start = User::TickCount();
   30.50 +
   30.51 +    TTimeIntervalMicroSeconds32 period;
   30.52 +	TInt tmp = UserHal::TickPeriod(period);
   30.53 +    tickPeriodMilliSeconds = period.Int() / 1000;
   30.54 +	}
   30.55 +
   30.56 +Uint32 SDL_GetTicks(void)
   30.57 +	{
   30.58 +    TUint deltaTics = User::TickCount() - start;
   30.59 +	return(deltaTics * tickPeriodMilliSeconds); 
   30.60 +	}
   30.61 +
   30.62 +void SDL_Delay(Uint32 ms)
   30.63 +	{     
   30.64 +    User::After(TTimeIntervalMicroSeconds32(ms*1000));
   30.65 +	}
   30.66 +
   30.67 +/* Data to handle a single periodic alarm */
   30.68 +static int timer_alive = 0;
   30.69 +static SDL_Thread *timer = NULL;
   30.70 +
   30.71 +static int RunTimer(void *unused)
   30.72 +	{
   30.73 +	while ( timer_alive )
   30.74 +		{
   30.75 +		if (SDL_timer_running)
   30.76 +			{
   30.77 +			SDL_ThreadedTimerCheck();
   30.78 +			}
   30.79 +		SDL_Delay(10);
   30.80 +		}
   30.81 +	return(0);
   30.82 +	}
   30.83 +
   30.84 +/* This is only called if the event thread is not running */
   30.85 +int SDL_SYS_TimerInit(void)
   30.86 +	{
   30.87 +	if(timer != NULL)
   30.88 +		return (-1);
   30.89 +	timer_alive = 1;
   30.90 +	timer = SDL_CreateThread(RunTimer, NULL);
   30.91 +	if ( timer == NULL )
   30.92 +		return(-1);
   30.93 +	return(SDL_SetTimerThreaded(1));
   30.94 +	}
   30.95 +
   30.96 +void SDL_SYS_TimerQuit(void)
   30.97 +	{
   30.98 +	timer_alive = 0;
   30.99 +	if ( timer ) 
  30.100 +		{
  30.101 +		SDL_WaitThread(timer, NULL);
  30.102 +		timer = NULL;
  30.103 +		}
  30.104 +	}
  30.105 +
  30.106 +int SDL_SYS_StartTimer(void)
  30.107 +	{
  30.108 +	SDL_SetError("Internal logic error: Epoc uses threaded timer");
  30.109 +	return(-1);
  30.110 +	}
  30.111 +
  30.112 +void SDL_SYS_StopTimer(void)
  30.113 +	{
  30.114 +	return;
  30.115 +	}
  30.116 +
  30.117 +} // extern "C"
    31.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    31.2 +++ b/src/video/symbian/EKA1/SDL_epocevents.cpp	Sun Jun 24 18:26:35 2007 +0000
    31.3 @@ -0,0 +1,626 @@
    31.4 +/*
    31.5 +    SDL - Simple DirectMedia Layer
    31.6 +    Copyright (C) 1997, 1998, 1999, 2000, 2001  Sam Lantinga
    31.7 +
    31.8 +    This library is free software; you can redistribute it and/or
    31.9 +    modify it under the terms of the GNU Library General Public
   31.10 +    License as published by the Free Software Foundation; either
   31.11 +    version 2 of the License, or (at your option) any later version.
   31.12 +
   31.13 +    This library is distributed in the hope that it will be useful,
   31.14 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
   31.15 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   31.16 +    Library General Public License for more details.
   31.17 +
   31.18 +    You should have received a copy of the GNU Library General Public
   31.19 +    License along with this library; if not, write to the Free
   31.20 +    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   31.21 +
   31.22 +    Sam Lantinga
   31.23 +    slouken@devolution.com
   31.24 +*/
   31.25 +
   31.26 +/*
   31.27 +    SDL_epocevents.cpp
   31.28 +    Handle the event stream, converting Epoc events into SDL events
   31.29 +
   31.30 +    Epoc version by Hannu Viitala (hannu.j.viitala@mbnet.fi)
   31.31 +*/
   31.32 +
   31.33 +
   31.34 +#include <stdio.h>
   31.35 +#undef NULL
   31.36 +extern "C" {
   31.37 +//#define DEBUG_TRACE_ENABLED
   31.38 +#include "SDL_error.h"
   31.39 +#include "SDL_video.h"
   31.40 +#include "SDL_keysym.h"
   31.41 +#include "SDL_keyboard.h"
   31.42 +#include "SDL_events_c.h"
   31.43 +#include "SDL_timer.h"
   31.44 +}; /* extern "C" */
   31.45 +
   31.46 +#include "SDL_epocvideo.h"
   31.47 +#include "SDL_epocevents_c.h"
   31.48 +
   31.49 +#include<linereader.h>
   31.50 +#include<bautils.h>
   31.51 +
   31.52 +
   31.53 +#include <hal.h>
   31.54 +
   31.55 +extern "C" {
   31.56 +/* The translation tables from a console scancode to a SDL keysym */
   31.57 +static SDLKey keymap[MAX_SCANCODE];
   31.58 +static SDL_keysym *TranslateKey(_THIS, int scancode, SDL_keysym *keysym);
   31.59 +void DisableKeyBlocking(_THIS);
   31.60 +}; /* extern "C" */
   31.61 +
   31.62 +TBool isCursorVisible = EFalse;
   31.63 +
   31.64 +int EPOC_HandleWsEvent(_THIS, const TWsEvent& aWsEvent)
   31.65 +{
   31.66 +    int posted = 0;
   31.67 +    SDL_keysym keysym;
   31.68 +    
   31.69 +//    SDL_TRACE1("hws %d", aWsEvent.Type());
   31.70 +
   31.71 +    switch (aWsEvent.Type())
   31.72 +		{    
   31.73 +    case EEventPointer: /* Mouse pointer events */
   31.74 +		{
   31.75 +
   31.76 +        const TPointerCursorMode mode =  Private->EPOC_WsSession.PointerCursorMode();
   31.77 +
   31.78 +        if(mode == EPointerCursorNone) 
   31.79 +            {
   31.80 +            return 0; //TODO: Find out why events are get despite of cursor should be off
   31.81 +            }
   31.82 +
   31.83 +        const TPointerEvent* pointerEvent = aWsEvent.Pointer();
   31.84 +        TPoint mousePos = pointerEvent->iPosition;
   31.85 +
   31.86 +        /*!! TODO Pointer do not yet work properly
   31.87 +        //SDL_TRACE1("SDL: EPOC_HandleWsEvent, pointerEvent->iType=%d", pointerEvent->iType); //!!
   31.88 +
   31.89 +        if (Private->EPOC_ShrinkedHeight) {
   31.90 +            mousePos.iY <<= 1; // Scale y coordinate to shrinked screen height
   31.91 +        }
   31.92 +        if (Private->EPOC_ShrinkedWidth) {
   31.93 +            mousePos.iX <<= 1; // Scale x coordinate to shrinked screen width
   31.94 +        }
   31.95 +        */
   31.96 +
   31.97 +		posted += SDL_PrivateMouseMotion(0, 0, mousePos.iX, mousePos.iY); /* Absolute position on screen */
   31.98 +
   31.99 +		switch (pointerEvent->iType)
  31.100 +			{
  31.101 +        case TPointerEvent::EButton1Down:
  31.102 +            posted += SDL_PrivateMouseButton(SDL_PRESSED, SDL_BUTTON_LEFT, 0, 0);
  31.103 +			break;
  31.104 +        case TPointerEvent::EButton1Up:
  31.105 +			posted += SDL_PrivateMouseButton(SDL_RELEASED, SDL_BUTTON_LEFT, 0, 0);
  31.106 +			break;
  31.107 +        case TPointerEvent::EButton2Down:
  31.108 +            posted += SDL_PrivateMouseButton(SDL_PRESSED, SDL_BUTTON_RIGHT, 0, 0);
  31.109 +			break;
  31.110 +		case TPointerEvent::EButton2Up:
  31.111 +			posted += SDL_PrivateMouseButton(SDL_RELEASED, SDL_BUTTON_RIGHT, 0, 0);
  31.112 +			break;
  31.113 +        case TPointerEvent::EButton3Down:
  31.114 +            posted += SDL_PrivateMouseButton(SDL_PRESSED, SDL_BUTTON_MIDDLE, 0, 0);
  31.115 +			break;
  31.116 +        case TPointerEvent::EButton3Up:
  31.117 +			posted += SDL_PrivateMouseButton(SDL_RELEASED, SDL_BUTTON_MIDDLE, 0, 0);
  31.118 +			break;
  31.119 +			} // switch
  31.120 +        break;
  31.121 +	    }
  31.122 +    
  31.123 +    case EEventKeyDown: /* Key events */
  31.124 +    {
  31.125 +#ifdef SYMBIAN_CRYSTAL
  31.126 +		// special case: 9300/9500 rocker down, simulate left mouse button
  31.127 +		if (aWsEvent.Key()->iScanCode == EStdKeyDeviceA)
  31.128 +			{
  31.129 +            const TPointerCursorMode mode =  Private->EPOC_WsSession.PointerCursorMode();
  31.130 +            if(mode != EPointerCursorNone) 
  31.131 +                posted += SDL_PrivateMouseButton(SDL_PRESSED, SDL_BUTTON_LEFT, 0, 0);
  31.132 +			}
  31.133 +#endif
  31.134 +       (void*)TranslateKey(_this, aWsEvent.Key()->iScanCode, &keysym);
  31.135 +            
  31.136 +#ifndef DISABLE_JOYSTICK
  31.137 +        /* Special handling */
  31.138 +        switch((int)keysym.sym) {
  31.139 +        case SDLK_CAPSLOCK:
  31.140 +            if (!isCursorVisible) {
  31.141 +                /* Enable virtual cursor */
  31.142 +	            HAL::Set(HAL::EMouseState, HAL::EMouseState_Visible);
  31.143 +            }
  31.144 +            else {
  31.145 +                /* Disable virtual cursor */
  31.146 +                HAL::Set(HAL::EMouseState, HAL::EMouseState_Invisible);
  31.147 +            }
  31.148 +            isCursorVisible = !isCursorVisible;
  31.149 +            break;
  31.150 +        }
  31.151 +#endif        
  31.152 +	    posted += SDL_PrivateKeyboard(SDL_PRESSED, &keysym);
  31.153 +        break;
  31.154 +	} 
  31.155 +
  31.156 +    case EEventKeyUp: /* Key events */
  31.157 +		{
  31.158 +#ifdef SYMBIAN_CRYSTAL
  31.159 +		// special case: 9300/9500 rocker up, simulate left mouse button
  31.160 +		if (aWsEvent.Key()->iScanCode == EStdKeyDeviceA)
  31.161 +			{
  31.162 +            posted += SDL_PrivateMouseButton(SDL_RELEASED, SDL_BUTTON_LEFT, 0, 0);
  31.163 +			}
  31.164 +#endif
  31.165 +	    posted += SDL_PrivateKeyboard(SDL_RELEASED, TranslateKey(_this, aWsEvent.Key()->iScanCode, &keysym));
  31.166 +        break;
  31.167 +		}
  31.168 +    
  31.169 +    case EEventFocusGained: /* SDL window got focus */
  31.170 +	    {
  31.171 +        Private->EPOC_IsWindowFocused = ETrue;
  31.172 +		posted += SDL_PrivateAppActive(1, SDL_APPINPUTFOCUS|SDL_APPMOUSEFOCUS);
  31.173 +        /* Draw window background and screen buffer */
  31.174 +        DisableKeyBlocking(_this);  //Markus: guess why:-)
  31.175 + 
  31.176 +        RedrawWindowL(_this);  
  31.177 +        break;
  31.178 +	    }
  31.179 +
  31.180 +    case EEventFocusLost: /* SDL window lost focus */
  31.181 +		{
  31.182 +/*        
  31.183 +        CFbsBitmap* bmp = new (ELeave) CFbsBitmap();
  31.184 +        bmp->Create(Private->EPOC_ScreenSize, Private->EPOC_DisplayMode);
  31.185 +        Private->EPOC_WsScreen->CopyScreenToBitmap(bmp);
  31.186 +        Private->EPOC_WindowGc->Activate(Private->EPOC_WsWindow);
  31.187 +        Private->EPOC_WsWindow.BeginRedraw(TRect(Private->EPOC_WsWindow.Size()));
  31.188 +	    Private->EPOC_WindowGc->BitBlt(TPoint(0, 0), bmp);
  31.189 +	    Private->EPOC_WsWindow.EndRedraw();
  31.190 +	    Private->EPOC_WindowGc->Deactivate();
  31.191 +        bmp->Save(_L("C:\\scr.mbm"));
  31.192 +        delete bmp;
  31.193 +*/       
  31.194 +
  31.195 +		Private->EPOC_IsWindowFocused = EFalse;
  31.196 +
  31.197 +		posted += SDL_PrivateAppActive(0, SDL_APPINPUTFOCUS|SDL_APPMOUSEFOCUS);
  31.198 +
  31.199 +        RWsSession s;
  31.200 +        s.Connect();
  31.201 +        RWindowGroup g(s);
  31.202 +        g.Construct(TUint32(&g), EFalse);
  31.203 +        g.EnableReceiptOfFocus(EFalse);
  31.204 +        RWindow w(s);
  31.205 +        w.Construct(g, TUint32(&w));
  31.206 +        w.SetExtent(TPoint(0, 0), Private->EPOC_WsWindow.Size());
  31.207 +        w.SetOrdinalPosition(0);
  31.208 +        w.Activate();
  31.209 +        w.Close();
  31.210 +        g.Close();
  31.211 +        s.Close();
  31.212 +
  31.213 +/*
  31.214 +        Private->EPOC_WsSession.SetWindowGroupOrdinalPosition(Private->EPOC_WsWindowGroupID, -1);
  31.215 +
  31.216 +            
  31.217 +        SDL_Delay(500);
  31.218 +        TInt focus = -1;
  31.219 +        while(focus < 0)
  31.220 +            {
  31.221 +            const TInt curr = Private->EPOC_WsSession.GetFocusWindowGroup();
  31.222 +            if(curr != Private->EPOC_WsWindowGroupID)
  31.223 +                focus = curr;
  31.224 +            else
  31.225 +                SDL_Delay(500);
  31.226 +            }
  31.227 +
  31.228 +        if(1 < Private->EPOC_WsSession.GetWindowGroupOrdinalPriority(Private->EPOC_WsWindowGroupID))
  31.229 +            {
  31.230 +            Private->EPOC_WsSession.SetWindowGroupOrdinalPosition(focus, -1);
  31.231 +            SDL_Delay(500);
  31.232 +            Private->EPOC_WsSession.SetWindowGroupOrdinalPosition(focus, 0);
  31.233 +            }
  31.234 +*/
  31.235 +        /*//and the request redraw
  31.236 +        TRawEvent redrawEvent;
  31.237 +        redrawEvent.Set(TRawEvent::ERedraw);
  31.238 +        Private->EPOC_WsSession.SimulateRawEvent(redrawEvent);
  31.239 +        Private->EPOC_WsSession.Flush();*/
  31.240 +#if 0
  31.241 +        //!! Not used
  31.242 +        // Wait and eat events until focus is gained again
  31.243 +	    while (ETrue) {
  31.244 +            Private->EPOC_WsSession.EventReady(&Private->EPOC_WsEventStatus);
  31.245 +            User::WaitForRequest(Private->EPOC_WsEventStatus);
  31.246 +		    Private->EPOC_WsSession.GetEvent(Private->EPOC_WsEvent);
  31.247 +            TInt eventType = Private->EPOC_WsEvent.Type();
  31.248 +		    Private->EPOC_WsEventStatus = KRequestPending;
  31.249 +		    //Private->EPOC_WsSession.EventReady(&Private->EPOC_WsEventStatus);
  31.250 +            if (eventType == EEventFocusGained) {
  31.251 +                RedrawWindowL(_this);
  31.252 +                break;
  31.253 +            }
  31.254 +	    }
  31.255 +#endif
  31.256 +        break;
  31.257 +	    }
  31.258 +
  31.259 +    case EEventModifiersChanged: 
  31.260 +    {
  31.261 +	    TModifiersChangedEvent* modEvent = aWsEvent.ModifiersChanged();
  31.262 +        TUint modstate = KMOD_NONE;
  31.263 +        if (modEvent->iModifiers == EModifierLeftShift)
  31.264 +            modstate |= KMOD_LSHIFT;
  31.265 +        if (modEvent->iModifiers == EModifierRightShift)
  31.266 +            modstate |= KMOD_RSHIFT;
  31.267 +        if (modEvent->iModifiers == EModifierLeftCtrl)
  31.268 +            modstate |= KMOD_LCTRL;
  31.269 +        if (modEvent->iModifiers == EModifierRightCtrl)
  31.270 +            modstate |= KMOD_RCTRL;
  31.271 +        if (modEvent->iModifiers == EModifierLeftAlt)
  31.272 +            modstate |= KMOD_LALT;
  31.273 +        if (modEvent->iModifiers == EModifierRightAlt)
  31.274 +            modstate |= KMOD_RALT;
  31.275 +        if (modEvent->iModifiers == EModifierLeftFunc)
  31.276 +            modstate |= KMOD_LMETA;
  31.277 +        if (modEvent->iModifiers == EModifierRightFunc)
  31.278 +            modstate |= KMOD_RMETA;
  31.279 +        if (modEvent->iModifiers == EModifierCapsLock)
  31.280 +            modstate |= KMOD_CAPS;
  31.281 +        SDL_SetModState(STATIC_CAST(SDLMod,(modstate | KMOD_LSHIFT)));
  31.282 +        break;
  31.283 +    }
  31.284 +    default:            
  31.285 +        break;
  31.286 +	} 
  31.287 +	
  31.288 +    return posted;
  31.289 +}
  31.290 +
  31.291 +extern "C" {
  31.292 +
  31.293 +void EPOC_PumpEvents(_THIS)
  31.294 +{
  31.295 +    int posted = 0; // !! Do we need this?
  31.296 +    //Private->EPOC_WsSession.EventReady(&Private->EPOC_WsEventStatus);
  31.297 +	while (Private->EPOC_WsEventStatus != KRequestPending) {
  31.298 +
  31.299 +		Private->EPOC_WsSession.GetEvent(Private->EPOC_WsEvent);
  31.300 +		posted = EPOC_HandleWsEvent(_this, Private->EPOC_WsEvent);
  31.301 +		Private->EPOC_WsEventStatus = KRequestPending;
  31.302 +		Private->EPOC_WsSession.EventReady(&Private->EPOC_WsEventStatus);
  31.303 +	}
  31.304 +}
  31.305 +
  31.306 +
  31.307 +_LIT(KMapFileName, "C:\\sdl_info\\sdlkeymap.cfg");
  31.308 +LOCAL_C void ReadL(RFs& aFs, RArray<TInt>& aArray)
  31.309 +    {
  31.310 +    TInt drive = -1;
  31.311 +    TFileName name(KMapFileName);
  31.312 +    for(TInt i = 'z'; drive < 0 && i >= 'a'; i--)
  31.313 +        {
  31.314 +        name[0] = (TUint16)i;
  31.315 +        if(BaflUtils::FileExists(aFs, name))
  31.316 +            drive = i;
  31.317 +        }
  31.318 +    if(drive < 0)
  31.319 +        return;
  31.320 +    CLineReader* reader = CLineReader::NewLC(aFs, name);
  31.321 +    while(reader->NextL())
  31.322 +        {
  31.323 +        TPtrC ln = reader->Current();
  31.324 +        TLex line(ln);
  31.325 +        TInt n = 0;
  31.326 +        for(;;)
  31.327 +            {
  31.328 +            const TPtrC token = line.NextToken();
  31.329 +            if(token.Length() == 0)
  31.330 +                break;
  31.331 +            if((n & 1) != 0)
  31.332 +                {
  31.333 +                TInt value;
  31.334 +                TLex lex(token);
  31.335 +                User::LeaveIfError(lex.Val(value));
  31.336 +                User::LeaveIfError(aArray.Append(value));
  31.337 +                }
  31.338 +            n++;
  31.339 +            }
  31.340 +        }
  31.341 +    CleanupStack::PopAndDestroy();
  31.342 +    }
  31.343 +
  31.344 +
  31.345 +void EPOC_InitOSKeymap(_THIS)
  31.346 +{
  31.347 +	int i;
  31.348 +
  31.349 +	/* Initialize the key translation table */
  31.350 +	for ( i=0; i<SDL_TABLESIZE(keymap); ++i )
  31.351 +		keymap[i] = SDLK_UNKNOWN;
  31.352 +
  31.353 +
  31.354 +	/* Numbers */
  31.355 +	for ( i = 0; i<32; ++i ){
  31.356 +		keymap[' ' + i] = (SDLKey)(SDLK_SPACE+i);
  31.357 +	}
  31.358 +	/* e.g. Alphabet keys */
  31.359 +	for ( i = 0; i<32; ++i ){
  31.360 +		keymap['A' + i] = (SDLKey)(SDLK_a+i);
  31.361 +	}
  31.362 +
  31.363 +	keymap[EStdKeyBackspace]    = SDLK_BACKSPACE;
  31.364 +	keymap[EStdKeyTab]          = SDLK_TAB;
  31.365 +	keymap[EStdKeyEnter]        = SDLK_RETURN;
  31.366 +	keymap[EStdKeyEscape]       = SDLK_ESCAPE;
  31.367 +   	keymap[EStdKeySpace]        = SDLK_SPACE;
  31.368 +   	keymap[EStdKeyPause]        = SDLK_PAUSE;
  31.369 +   	keymap[EStdKeyHome]         = SDLK_HOME;
  31.370 +   	keymap[EStdKeyEnd]          = SDLK_END;
  31.371 +   	keymap[EStdKeyPageUp]       = SDLK_PAGEUP;
  31.372 +   	keymap[EStdKeyPageDown]     = SDLK_PAGEDOWN;
  31.373 +	keymap[EStdKeyDelete]       = SDLK_DELETE;
  31.374 +	keymap[EStdKeyUpArrow]      = SDLK_UP;
  31.375 +	keymap[EStdKeyDownArrow]    = SDLK_DOWN;
  31.376 +	keymap[EStdKeyLeftArrow]    = SDLK_LEFT;
  31.377 +	keymap[EStdKeyRightArrow]   = SDLK_RIGHT;
  31.378 +	keymap[EStdKeyCapsLock]     = SDLK_CAPSLOCK;
  31.379 +	keymap[EStdKeyLeftShift]    = SDLK_LSHIFT;
  31.380 +	keymap[EStdKeyRightShift]   = SDLK_RSHIFT;
  31.381 +	keymap[EStdKeyLeftAlt]      = SDLK_LALT;
  31.382 +	keymap[EStdKeyRightAlt]     = SDLK_RALT;
  31.383 +	keymap[EStdKeyLeftCtrl]     = SDLK_LCTRL;
  31.384 +	keymap[EStdKeyRightCtrl]    = SDLK_RCTRL;
  31.385 +	keymap[EStdKeyLeftFunc]     = SDLK_LMETA;
  31.386 +	keymap[EStdKeyRightFunc]    = SDLK_RMETA;
  31.387 +	keymap[EStdKeyInsert]       = SDLK_INSERT;
  31.388 +	keymap[EStdKeyComma]        = SDLK_COMMA;
  31.389 +	keymap[EStdKeyFullStop]     = SDLK_PERIOD;
  31.390 +	keymap[EStdKeyForwardSlash] = SDLK_SLASH;
  31.391 +	keymap[EStdKeyBackSlash]    = SDLK_BACKSLASH;
  31.392 +	keymap[EStdKeySemiColon]    = SDLK_SEMICOLON;
  31.393 +	keymap[EStdKeySingleQuote]  = SDLK_QUOTE;
  31.394 +	keymap[EStdKeyHash]         = SDLK_HASH;
  31.395 +	keymap[EStdKeySquareBracketLeft]    = SDLK_LEFTBRACKET;
  31.396 +	keymap[EStdKeySquareBracketRight]   = SDLK_RIGHTBRACKET;
  31.397 +	keymap[EStdKeyMinus]        = SDLK_MINUS;
  31.398 +	keymap[EStdKeyEquals]       = SDLK_EQUALS;
  31.399 +
  31.400 +   	keymap[EStdKeyF1]          = SDLK_F1;  /* chr + q */
  31.401 +   	keymap[EStdKeyF2]          = SDLK_F2;  /* chr + w */
  31.402 +   	keymap[EStdKeyF3]          = SDLK_F3;  /* chr + e */
  31.403 +   	keymap[EStdKeyF4]          = SDLK_F4;  /* chr + r */
  31.404 +   	keymap[EStdKeyF5]          = SDLK_F5;  /* chr + t */
  31.405 +   	keymap[EStdKeyF6]          = SDLK_F6;  /* chr + y */
  31.406 +   	keymap[EStdKeyF7]          = SDLK_F7;  /* chr + i */
  31.407 +   	keymap[EStdKeyF8]          = SDLK_F8;  /* chr + o */
  31.408 +
  31.409 +   	keymap[EStdKeyF9]          = SDLK_F9;  /* chr + a */
  31.410 +   	keymap[EStdKeyF10]         = SDLK_F10; /* chr + s */
  31.411 +   	keymap[EStdKeyF11]         = SDLK_F11; /* chr + d */
  31.412 +   	keymap[EStdKeyF12]         = SDLK_F12; /* chr + f */
  31.413 +
  31.414 +	#ifndef SYMBIAN_CRYSTAL 
  31.415 +	//!!7650 additions
  31.416 +    #ifdef __WINS__
  31.417 +   	keymap[EStdKeyXXX]         = SDLK_RETURN;	/* "fire" key */
  31.418 +	#else
  31.419 +   	keymap[EStdKeyDevice3]     = SDLK_RETURN;	/* "fire" key */
  31.420 +	#endif
  31.421 +   	keymap[EStdKeyNkpAsterisk] = SDLK_ASTERISK; 
  31.422 +   	keymap[EStdKeyYes]         = SDLK_HOME;		/* "call" key */
  31.423 +   	keymap[EStdKeyNo]		   = SDLK_END;		/* "end call" key */
  31.424 +   	keymap[EStdKeyDevice0]     = SDLK_SPACE;	/* right menu key */
  31.425 +   	keymap[EStdKeyDevice1]     = SDLK_ESCAPE;	/* left menu key */
  31.426 +   	keymap[EStdKeyDevice2]     = SDLK_POWER;	/* power key */
  31.427 +	#endif
  31.428 +
  31.429 + #ifdef SYMBIAN_CRYSTAL 
  31.430 +    keymap[EStdKeyMenu]        = SDLK_ESCAPE;   // menu key
  31.431 +    keymap[EStdKeyDevice6]     = SDLK_LEFT;     // Rocker (joystick) left
  31.432 +    keymap[EStdKeyDevice7]     = SDLK_RIGHT;    // Rocker (joystick) right
  31.433 +    keymap[EStdKeyDevice8]     = SDLK_UP;       // Rocker (joystick) up
  31.434 +    keymap[EStdKeyDevice9]     = SDLK_DOWN;     // Rocker (joystick) down
  31.435 +    keymap[EStdKeyLeftFunc]     = SDLK_LALT;    //chr?
  31.436 +	keymap[EStdKeyRightFunc]    = SDLK_RALT;
  31.437 +    keymap[EStdKeyDeviceA]      = SDLK_RETURN;	/* "fire" key */
  31.438 +#endif
  31.439 +
  31.440 +    ///////////////////////////////////////////////////////////
  31.441 +
  31.442 +    RFs fs;
  31.443 +    if(KErrNone == fs.Connect())
  31.444 +        {
  31.445 +        RArray<TInt> array;
  31.446 +        TRAPD(err, ReadL(fs, array));
  31.447 +        if(err == KErrNone && array.Count() > 0)
  31.448 +            {
  31.449 +            
  31.450 +            SDLKey temp[MAX_SCANCODE];
  31.451 +            Mem::Copy(temp, keymap, MAX_SCANCODE * sizeof(SDLKey));
  31.452 +
  31.453 +            for(TInt k = 0; k < array.Count(); k+= 2)
  31.454 +                {
  31.455 +                const TInt oldval = array[k]; 
  31.456 +                const TInt newval = array[k + 1]; 
  31.457 +                if(oldval >=  0 && oldval < MAX_SCANCODE && newval >=  0 && newval < MAX_SCANCODE)
  31.458 +                    {
  31.459 +                    keymap[oldval] = temp[newval];
  31.460 +                    }
  31.461 +                }
  31.462 +            }
  31.463 +        array.Close();
  31.464 +        }
  31.465 +
  31.466 +    fs.Close();
  31.467 +    ///////////////////////////////////////////////////////////
  31.468 +
  31.469 +    /* !!TODO
  31.470 +	EStdKeyNumLock=0x1b,
  31.471 +	EStdKeyScrollLock=0x1c,
  31.472 +
  31.473 +	EStdKeyNkpForwardSlash=0x84,
  31.474 +	EStdKeyNkpAsterisk=0x85,
  31.475 +	EStdKeyNkpMinus=0x86,
  31.476 +	EStdKeyNkpPlus=0x87,
  31.477 +	EStdKeyNkpEnter=0x88,
  31.478 +	EStdKeyNkp1=0x89,
  31.479 +	EStdKeyNkp2=0x8a,
  31.480 +	EStdKeyNkp3=0x8b,
  31.481 +	EStdKeyNkp4=0x8c,
  31.482 +	EStdKeyNkp5=0x8d,
  31.483 +	EStdKeyNkp6=0x8e,
  31.484 +	EStdKeyNkp7=0x8f,
  31.485 +	EStdKeyNkp8=0x90,
  31.486 +	EStdKeyNkp9=0x91,
  31.487 +	EStdKeyNkp0=0x92,
  31.488 +	EStdKeyNkpFullStop=0x93,
  31.489 +    EStdKeyMenu=0x94,
  31.490 +    EStdKeyBacklightOn=0x95,
  31.491 +    EStdKeyBacklightOff=0x96,
  31.492 +    EStdKeyBacklightToggle=0x97,
  31.493 +    EStdKeyIncContrast=0x98,
  31.494 +    EStdKeyDecContrast=0x99,
  31.495 +    EStdKeySliderDown=0x9a,
  31.496 +    EStdKeySliderUp=0x9b,
  31.497 +    EStdKeyDictaphonePlay=0x9c,
  31.498 +    EStdKeyDictaphoneStop=0x9d,
  31.499 +    EStdKeyDictaphoneRecord=0x9e,
  31.500 +    EStdKeyHelp=0x9f,
  31.501 +    EStdKeyOff=0xa0,
  31.502 +    EStdKeyDial=0xa1,
  31.503 +    EStdKeyIncVolume=0xa2,
  31.504 +    EStdKeyDecVolume=0xa3,
  31.505 +    EStdKeyDevice0=0xa4,
  31.506 +    EStdKeyDevice1=0xa5,
  31.507 +    EStdKeyDevice2=0xa6,
  31.508 +    EStdKeyDevice3=0xa7,
  31.509 +    EStdKeyDevice4=0xa8,
  31.510 +    EStdKeyDevice5=0xa9,
  31.511 +    EStdKeyDevice6=0xaa,
  31.512 +    EStdKeyDevice7=0xab,
  31.513 +    EStdKeyDevice8=0xac,
  31.514 +    EStdKeyDevice9=0xad,
  31.515 +    EStdKeyDeviceA=0xae,
  31.516 +    EStdKeyDeviceB=0xaf,
  31.517 +    EStdKeyDeviceC=0xb0,
  31.518 +    EStdKeyDeviceD=0xb1,
  31.519 +    EStdKeyDeviceE=0xb2,
  31.520 +    EStdKeyDeviceF=0xb3,
  31.521 +    EStdKeyApplication0=0xb4,
  31.522 +    EStdKeyApplication1=0xb5,
  31.523 +    EStdKeyApplication2=0xb6,
  31.524 +    EStdKeyApplication3=0xb7,
  31.525 +    EStdKeyApplication4=0xb8,
  31.526 +    EStdKeyApplication5=0xb9,
  31.527 +    EStdKeyApplication6=0xba,
  31.528 +    EStdKeyApplication7=0xbb,
  31.529 +    EStdKeyApplication8=0xbc,
  31.530 +    EStdKeyApplication9=0xbd,
  31.531 +    EStdKeyApplicationA=0xbe,
  31.532 +    EStdKeyApplicationB=0xbf,
  31.533 +    EStdKeyApplicationC=0xc0,
  31.534 +    EStdKeyApplicationD=0xc1,
  31.535 +    EStdKeyApplicationE=0xc2,
  31.536 +    EStdKeyApplicationF=0xc3,
  31.537 +    EStdKeyYes=0xc4,
  31.538 +    EStdKeyNo=0xc5,
  31.539 +    EStdKeyIncBrightness=0xc6,
  31.540 +    EStdKeyDecBrightness=0xc7, 
  31.541 +    EStdKeyCaseOpen=0xc8,
  31.542 +    EStdKeyCaseClose=0xc9
  31.543 +    */
  31.544 +
  31.545 +}
  31.546 +
  31.547 +
  31.548 +
  31.549 +static SDL_keysym *TranslateKey(_THIS, int scancode, SDL_keysym *keysym)
  31.550 +{
  31.551 +//    char debug[256];
  31.552 +    //SDL_TRACE1("SDL: TranslateKey, scancode=%d", scancode); //!!
  31.553 +
  31.554 +	/* Set the keysym information */ 
  31.555 +
  31.556 +	keysym->scancode = scancode;
  31.557 +
  31.558 +    if ((scancode >= MAX_SCANCODE) && 
  31.559 +        ((scancode - ENonCharacterKeyBase + 0x0081) >= MAX_SCANCODE)) {
  31.560 +        SDL_SetError("Too big scancode");
  31.561 +        keysym->scancode = SDLK_UNKNOWN;
  31.562 +	    keysym->mod = KMOD_NONE; 
  31.563 +        return keysym;
  31.564 +    }
  31.565 +
  31.566 +	keysym->mod = SDL_GetModState();
  31.567 +
  31.568 +    /* Handle function keys: F1, F2, F3 ... */
  31.569 +    if (keysym->mod & KMOD_META) {
  31.570 +        if (scancode >= 'A' && scancode < ('A' + 24)) { /* first 32 alphabet keys */
  31.571 +            switch(scancode) {
  31.572 +                case 'Q': scancode = EStdKeyF1; break;
  31.573 +                case 'W': scancode = EStdKeyF2; break;
  31.574 +                case 'E': scancode = EStdKeyF3; break;
  31.575 +                case 'R': scancode = EStdKeyF4; break;
  31.576 +                case 'T': scancode = EStdKeyF5; break;
  31.577 +                case 'Y': scancode = EStdKeyF6; break;
  31.578 +                case 'U': scancode = EStdKeyF7; break;
  31.579 +                case 'I': scancode = EStdKeyF8; break;
  31.580 +                case 'A': scancode = EStdKeyF9; break;
  31.581 +                case 'S': scancode = EStdKeyF10; break;
  31.582 +                case 'D': scancode = EStdKeyF11; break;
  31.583 +                case 'F': scancode = EStdKeyF12; break;
  31.584 +            }
  31.585 +            keysym->sym = keymap[scancode];
  31.586 +        }
  31.587 +    }
  31.588 +
  31.589 +    if (scancode >= ENonCharacterKeyBase) {
  31.590 +        // Non character keys
  31.591 +	    keysym->sym = keymap[scancode - 
  31.592 +            ENonCharacterKeyBase + 0x0081]; // !!hard coded
  31.593 +    } else {
  31.594 +	    keysym->sym = keymap[scancode];
  31.595 +    }
  31.596 +
  31.597 +	/* Remap the arrow keys if the device is rotated */
  31.598 +	if (Private->EPOC_ScreenOrientation == CFbsBitGc::EGraphicsOrientationRotated270) {
  31.599 +		switch(keysym->sym) {
  31.600 +			case SDLK_UP:	keysym->sym = SDLK_LEFT;  break;
  31.601 +			case SDLK_DOWN: keysym->sym = SDLK_RIGHT; break;
  31.602 +			case SDLK_LEFT: keysym->sym = SDLK_DOWN;  break;
  31.603 +			case SDLK_RIGHT:keysym->sym = SDLK_UP;    break;
  31.604 +		}
  31.605 +	}
  31.606 +
  31.607 +	/* If UNICODE is on, get the UNICODE value for the key */
  31.608 +	keysym->unicode = 0;
  31.609 +
  31.610 +#if 0 // !!TODO:unicode
  31.611 +
  31.612 +	if ( SDL_TranslateUNICODE ) 
  31.613 +    {
  31.614 +		/* Populate the unicode field with the ASCII value */
  31.615 +		keysym->unicode = scancode;
  31.616 +	}
  31.617 +#endif
  31.618 +
  31.619 +    //!!
  31.620 +    //sprintf(debug, "SDL: TranslateKey: keysym->scancode=%d, keysym->sym=%d, keysym->mod=%d",
  31.621 +    //    keysym->scancode, keysym->sym, keysym->mod);
  31.622 +    //SDL_TRACE(debug); //!!
  31.623 +
  31.624 +	return(keysym);
  31.625 +}
  31.626 +
  31.627 +}; /* extern "C" */
  31.628 +
  31.629 +
    32.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    32.2 +++ b/src/video/symbian/EKA1/SDL_epocvideo.cpp	Sun Jun 24 18:26:35 2007 +0000
    32.3 @@ -0,0 +1,1356 @@
    32.4 +/*
    32.5 +    SDL - Simple DirectMedia Layer
    32.6 +    Copyright (C) 1997, 1998, 1999, 2000, 2001  Sam Lantinga
    32.7 +
    32.8 +    This library is free software; you can redistribute it and/or
    32.9 +    modify it under the terms of the GNU Library General Public
   32.10 +    License as published by the Free Software Foundation; either
   32.11 +    version 2 of the License, or (at your option) any later version.
   32.12 +
   32.13 +    This library is distributed in the hope that it will be useful,
   32.14 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
   32.15 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   32.16 +    Library General Public License for more details.
   32.17 +
   32.18 +    You should have received a copy of the GNU Library General Public
   32.19 +    License along with this library; if not, write to the Free
   32.20 +    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   32.21 +
   32.22 +    Sam Lantinga
   32.23 +    slouken@devolution.com
   32.24 +*/
   32.25 +
   32.26 +/*
   32.27 +    SDL_epocvideo.cpp
   32.28 +    Epoc based SDL video driver implementation
   32.29 +
   32.30 +    Thanks to Peter van Sebille, the author of EMame. It is a great example of 
   32.31 +    low level graphics coding in Epoc.
   32.32 +
   32.33 +    Epoc version by Hannu Viitala (hannu.j.viitala@mbnet.fi)
   32.34 +	Assembler routines by Kimmo Kinnunen
   32.35 +*/
   32.36 +
   32.37 +
   32.38 +
   32.39 +#include <stdlib.h>
   32.40 +#include <stdio.h>
   32.41 +#include <string.h>
   32.42 +
   32.43 +extern "C" {
   32.44 +#include "SDL_error.h"
   32.45 +#include "SDL_timer.h"
   32.46 +#include "SDL_video.h"
   32.47 +#undef NULL
   32.48 +#include "SDL_pixels_c.h"
   32.49 +#include "SDL.h"
   32.50 +};
   32.51 +
   32.52 +#include "SDL_epocvideo.h"
   32.53 +#include "SDL_epocevents_c.h"
   32.54 +
   32.55 +#include "sdl_epocruntime.h"
   32.56 +
   32.57 +#include <hal.h>
   32.58 +#include <coedef.h>
   32.59 +#include <flogger.h>
   32.60 +
   32.61 +#ifdef SYMBIAN_QUARTZ
   32.62 +SDL_VideoDevice* _thisDevice;
   32.63 +#endif
   32.64 +
   32.65 +_LIT(KLibName, "SDL");
   32.66 +
   32.67 +/* For debugging */
   32.68 +
   32.69 +//if old SOS, from 7.x this is public!
   32.70 +class CLockable : public CFbsBitmap
   32.71 +    {
   32.72 +    public:
   32.73 +        static  CLockable* Lockable(CFbsBitmap* aBmp) {return static_cast<CLockable*>(aBmp);}
   32.74 +        void Lock() {LockHeap();}
   32.75 +        void Unlock() {UnlockHeap();}
   32.76 +    };
   32.77 +#define LockHeap(x) CLockable::Lockable(x)->Lock()
   32.78 +#define UnlockHeap(x) CLockable::Lockable(x)->Unlock()
   32.79 +
   32.80 +void RDebug_Print_b(char* error_str, void* param)
   32.81 +    {
   32.82 +    TBuf8<128> error8((TUint8*)error_str);
   32.83 +    TBuf<128> error;
   32.84 +    error.Copy(error8);
   32.85 +
   32.86 +#ifndef TRACE_TO_FILE
   32.87 +    if (param) //!! Do not work if the parameter is really 0!!
   32.88 +        RDebug::Print(error, param);
   32.89 +    else 
   32.90 +        RDebug::Print(error);
   32.91 +#else
   32.92 +    if (param) //!! Do not work if the parameter is really 0!!
   32.93 +        RFileLogger::WriteFormat(KLibName, _L("SDL.txt"), EFileLoggingModeAppend, error, param);
   32.94 +    else 
   32.95 +        RFileLogger::Write(KLibName, _L("SDL.txt"), EFileLoggingModeAppend, error);
   32.96 +#endif
   32.97 +
   32.98 +    }
   32.99 +
  32.100 +extern "C" void RDebug_Print(char* error_str, void* param)
  32.101 +    {
  32.102 +    RDebug_Print_b(error_str, param);
  32.103 +    }
  32.104 +
  32.105 +
  32.106 +int Debug_AvailMem2()
  32.107 +    {
  32.108 +    //User::CompressAllHeaps();
  32.109 +    TMemoryInfoV1Buf membuf; 
  32.110 +    User::LeaveIfError(UserHal::MemoryInfo(membuf));
  32.111 +    TMemoryInfoV1 minfo = membuf();
  32.112 +	return(minfo.iFreeRamInBytes);
  32.113 +    }
  32.114 +
  32.115 +extern "C" int Debug_AvailMem()
  32.116 +    {
  32.117 +    return(Debug_AvailMem2());
  32.118 +    }
  32.119 +
  32.120 +
  32.121 +extern "C" {
  32.122 +
  32.123 +/* Initialization/Query functions */
  32.124 +
  32.125 +static int EPOC_VideoInit(_THIS, SDL_PixelFormat *vformat);
  32.126 +static SDL_Rect **EPOC_ListModes(_THIS, SDL_PixelFormat *format, Uint32 flags);
  32.127 +static SDL_Surface *EPOC_SetVideoMode(_THIS, SDL_Surface *current, int width, int height, int bpp, Uint32 flags);
  32.128 +static int EPOC_SetColors(_THIS, int firstcolor, int ncolors,
  32.129 +			  SDL_Color *colors);
  32.130 +static void EPOC_VideoQuit(_THIS);
  32.131 +
  32.132 +/* Hardware surface functions */
  32.133 +
  32.134 +static int EPOC_AllocHWSurface(_THIS, SDL_Surface *surface);
  32.135 +static int EPOC_LockHWSurface(_THIS, SDL_Surface *surface);
  32.136 +static int EPOC_FlipHWSurface(_THIS, SDL_Surface *surface);
  32.137 +static void EPOC_UnlockHWSurface(_THIS, SDL_Surface *surface);
  32.138 +static void EPOC_FreeHWSurface(_THIS, SDL_Surface *surface);
  32.139 +static void EPOC_DirectUpdate(_THIS, int numrects, SDL_Rect *rects);
  32.140 +
  32.141 +static int EPOC_Available(void);
  32.142 +static SDL_VideoDevice *EPOC_CreateDevice(int devindex);
  32.143 +
  32.144 +void DrawBackground(_THIS);
  32.145 +void DirectDraw(_THIS, int numrects, SDL_Rect *rects, TUint16* screenBuffer);
  32.146 +void DirectDrawRotated(_THIS, int numrects, SDL_Rect *rects, TUint16* screenBuffer);
  32.147 +
  32.148 +/* Mouse functions */
  32.149 +
  32.150 +static WMcursor *EPOC_CreateWMCursor(_THIS, Uint8 *data, Uint8 *mask, int w, int h, int hot_x, int hot_y);
  32.151 +static void EPOC_FreeWMCursor(_THIS, WMcursor *cursor);
  32.152 +static int EPOC_ShowWMCursor(_THIS, WMcursor *cursor);
  32.153 +
  32.154 +
  32.155 +
  32.156 +/* !!For 12 bit screen HW. Table for fast conversion from 8 bit to 12 bit */
  32.157 +// TUint16 is enough, but using TUint32 so we can use better instruction selection on ARMI
  32.158 +static TUint32 EPOC_HWPalette_256_to_Screen[256];
  32.159 +
  32.160 +VideoBootStrap EPOC_bootstrap = {
  32.161 +	"epoc", "EPOC system",
  32.162 +    EPOC_Available, EPOC_CreateDevice
  32.163 +};
  32.164 +
  32.165 +const TUint32 WindowClientHandle = 9210; //!! const
  32.166 +
  32.167 +/* Epoc video driver bootstrap functions */
  32.168 +
  32.169 +static int EPOC_Available(void)
  32.170 +{
  32.171 +    return 1; /* Always available */
  32.172 +}
  32.173 +
  32.174 +static void EPOC_DeleteDevice(SDL_VideoDevice *device)
  32.175 +{
  32.176 +	free(device->hidden);
  32.177 +	free(device);
  32.178 +}
  32.179 +
  32.180 +static SDL_VideoDevice *EPOC_CreateDevice(int /*devindex*/)
  32.181 +{
  32.182 +	SDL_VideoDevice *device;
  32.183 +
  32.184 +	SDL_TRACE("SDL:EPOC_CreateDevice");
  32.185 +
  32.186 +	/* Allocate all variables that we free on delete */
  32.187 +	device = (SDL_VideoDevice *)malloc(sizeof(SDL_VideoDevice));
  32.188 +	if ( device ) {
  32.189 +		memset(device, 0, (sizeof *device));
  32.190 +		device->hidden = (struct SDL_PrivateVideoData *)
  32.191 +				malloc((sizeof *device->hidden));
  32.192 +	}
  32.193 +	if ( (device == NULL) || (device->hidden == NULL) ) {
  32.194 +		SDL_OutOfMemory();
  32.195 +		if ( device ) {
  32.196 +			free(device);
  32.197 +		}
  32.198 +		return(0);
  32.199 +	}
  32.200 +	memset(device->hidden, 0, (sizeof *device->hidden));
  32.201 +
  32.202 +	/* Set the function pointers */
  32.203 +	device->VideoInit = EPOC_VideoInit;
  32.204 +	device->ListModes = EPOC_ListModes;
  32.205 +	device->SetVideoMode = EPOC_SetVideoMode;
  32.206 +	device->SetColors = EPOC_SetColors;
  32.207 +	device->UpdateRects = NULL;
  32.208 +	device->VideoQuit = EPOC_VideoQuit;
  32.209 +	device->AllocHWSurface = EPOC_AllocHWSurface;
  32.210 +	device->CheckHWBlit = NULL;
  32.211 +	device->FillHWRect = NULL;
  32.212 +	device->SetHWColorKey = NULL;
  32.213 +	device->SetHWAlpha = NULL;
  32.214 +	device->LockHWSurface = EPOC_LockHWSurface;
  32.215 +	device->UnlockHWSurface = EPOC_UnlockHWSurface;
  32.216 +	device->FlipHWSurface = EPOC_FlipHWSurface;
  32.217 +	device->FreeHWSurface = EPOC_FreeHWSurface;
  32.218 +	device->SetIcon = NULL;
  32.219 +	device->SetCaption = NULL;
  32.220 +	device->GetWMInfo = NULL;
  32.221 +	device->FreeWMCursor = EPOC_FreeWMCursor;
  32.222 +	device->CreateWMCursor = EPOC_CreateWMCursor;
  32.223 +	device->ShowWMCursor = EPOC_ShowWMCursor;
  32.224 +	device->WarpWMCursor = NULL;
  32.225 +	device->InitOSKeymap = EPOC_InitOSKeymap;
  32.226 +	device->PumpEvents = EPOC_PumpEvents;
  32.227 +	device->free = EPOC_DeleteDevice;
  32.228 +
  32.229 +	return device;
  32.230 +}
  32.231 +
  32.232 +
  32.233 +int GetBpp(TDisplayMode displaymode)
  32.234 +{
  32.235 +    /*TInt numColors = TDisplayModeUtils::NumDisplayModeColors(displaymode);
  32.236 +    TInt bitsPerPixel = 1;
  32.237 +    for (TInt32 i = 2; i < numColors; i <<= 1, bitsPerPixel++);
  32.238 +    return bitsPerPixel;*/
  32.239 +    return  TDisplayModeUtils::NumDisplayModeBitsPerPixel(displaymode);   
  32.240 +}
  32.241 +
  32.242 +
  32.243 +void DisableKeyBlocking(_THIS)
  32.244 +    {
  32.245 +    // Disable key blocking
  32.246 +    TRawEvent event;
  32.247 +    event.Set((TRawEvent::TType)/*EDisableKeyBlock*/51); // !!EDisableKeyBlock not found in epoc32\include!
  32.248 +    Private->EPOC_WsSession.SimulateRawEvent(event);
  32.249 +    }
  32.250 +
  32.251 +void ConstructWindowL(_THIS)
  32.252 +{
  32.253 +	TInt	error;
  32.254 +
  32.255 +	SDL_TRACE("SDL:ConstructWindowL");
  32.256 +	error = Private->EPOC_WsSession.Connect();
  32.257 +	User::LeaveIfError(error);
  32.258 +	Private->EPOC_WsScreen=new(ELeave) CWsScreenDevice(Private->EPOC_WsSession);
  32.259 +	User::LeaveIfError(Private->EPOC_WsScreen->Construct());
  32.260 +	User::LeaveIfError(Private->EPOC_WsScreen->CreateContext(Private->EPOC_WindowGc));
  32.261 +
  32.262 +	Private->EPOC_WsWindowGroup=RWindowGroup(Private->EPOC_WsSession);
  32.263 +	User::LeaveIfError(Private->EPOC_WsWindowGroup.Construct(WindowClientHandle));
  32.264 +	Private->EPOC_WsWindowGroup.SetOrdinalPosition(0);
  32.265 +
  32.266 +	// Set window group name (the same as process name)) !!Gives always "EPOC" in WINS
  32.267 +	RProcess thisProcess;
  32.268 +	TParse exeName;
  32.269 +	exeName.Set(thisProcess.FileName(), NULL, NULL);
  32.270 +    TBuf<32> winGroupName;
  32.271 +    winGroupName.Append(0);
  32.272 +    winGroupName.Append(0);
  32.273 +    winGroupName.Append(0);// uid
  32.274 +    winGroupName.Append(0);
  32.275 +    winGroupName.Append(exeName.Name()); // caption
  32.276 +    winGroupName.Append(0);
  32.277 +    winGroupName.Append(0); //doc name
  32.278 +	Private->EPOC_WsWindowGroup.SetName(winGroupName); 
  32.279 +
  32.280 +	Private->EPOC_WsWindow=RWindow(Private->EPOC_WsSession);
  32.281 +  // Markus, it was:
  32.282 +  // User::LeaveIfError(Private->EPOC_WsWindow.Construct(Private->EPOC_WsWindowGroup,WindowClientHandle ));
  32.283 +  // but SOS 7.0s debug does not accept same window handle twice
  32.284 +	User::LeaveIfError(Private->EPOC_WsWindow.Construct(Private->EPOC_WsWindowGroup,WindowClientHandle - 1));
  32.285 +	Private->EPOC_WsWindow.SetBackgroundColor(KRgbWhite);
  32.286 +    Private->EPOC_WsWindow.Activate();
  32.287 +	Private->EPOC_WsWindow.SetSize(Private->EPOC_WsScreen->SizeInPixels()); 
  32.288 +	Private->EPOC_WsWindow.SetVisible(ETrue);
  32.289 +
  32.290 +    Private->EPOC_WsWindowGroupID = Private->EPOC_WsWindowGroup.Identifier();
  32.291 +    Private->EPOC_IsWindowFocused = EFalse;
  32.292 +
  32.293 +    DisableKeyBlocking(_this); //disable key blocking
  32.294 +}
  32.295 +
  32.296 +int EPOC_VideoInit(_THIS, SDL_PixelFormat *vformat)
  32.297 +{
  32.298 +    // !!TODO:handle leave functions!
  32.299 +
  32.300 +    int i;
  32.301 +
  32.302 +	SDL_TRACE("SDL:EPOC_VideoInit");
  32.303 +
  32.304 +	/* Initialize all variables that we clean on shutdown */   
  32.305 +
  32.306 +	for ( i=0; i<SDL_NUMMODES; ++i ) {
  32.307 +		Private->SDL_modelist[i] = (SDL_Rect *)malloc(sizeof(SDL_Rect));
  32.308 +		Private->SDL_modelist[i]->x = Private->SDL_modelist[i]->y = 0;
  32.309 +	}
  32.310 +
  32.311 +	/* Modes sorted largest to smallest */
  32.312 +	Private->SDL_modelist[0]->w = 800; Private->SDL_modelist[0]->h = 250;
  32.313 +	Private->SDL_modelist[1]->w = 640; Private->SDL_modelist[1]->h = 480;
  32.314 +	Private->SDL_modelist[2]->w = 480; Private->SDL_modelist[2]->h = 600;
  32.315 +	Private->SDL_modelist[3]->w = 640; Private->SDL_modelist[3]->h = 400;
  32.316 +	Private->SDL_modelist[4]->w = 352; Private->SDL_modelist[4]->h = 416;
  32.317 +	Private->SDL_modelist[5]->w = 416; Private->SDL_modelist[5]->h = 352;
  32.318 +	Private->SDL_modelist[6]->w = 416; Private->SDL_modelist[6]->h = 312;
  32.319 +	Private->SDL_modelist[7]->w = 352; Private->SDL_modelist[7]->h = 264;
  32.320 +	Private->SDL_modelist[8]->w = 800; Private->SDL_modelist[8]->h = 240; //for doom all these..
  32.321 +	Private->SDL_modelist[9]->w = 640; Private->SDL_modelist[9]->h = 240; 
  32.322 +	Private->SDL_modelist[10]->w = 480; Private->SDL_modelist[10]->h = 240; 
  32.323 +	Private->SDL_modelist[11]->w = 640; Private->SDL_modelist[11]->h = 240; 
  32.324 +	Private->SDL_modelist[12]->w = 352; Private->SDL_modelist[12]->h = 240; 
  32.325 +	Private->SDL_modelist[13]->w = 416; Private->SDL_modelist[13]->h = 240; 
  32.326 +	Private->SDL_modelist[14]->w = 416; Private->SDL_modelist[14]->h = 240; 
  32.327 +	Private->SDL_modelist[15]->w = 352; Private->SDL_modelist[15]->h = 240; 
  32.328 +    Private->SDL_modelist[16]->w = 640; Private->SDL_modelist[16]->h = 200; 
  32.329 +	Private->SDL_modelist[17]->w = 320; Private->SDL_modelist[17]->h = 240; //...for doom, currently engine renders no-higher windows :-(, propably should get fixed 
  32.330 +	Private->SDL_modelist[18]->w = 320; Private->SDL_modelist[18]->h = 200;
  32.331 +	Private->SDL_modelist[19]->w = 256; Private->SDL_modelist[19]->h = 192;
  32.332 +	Private->SDL_modelist[20]->w = 176; Private->SDL_modelist[20]->h = 208;
  32.333 +	Private->SDL_modelist[21]->w = 208; Private->SDL_modelist[21]->h = 176; // Rotated
  32.334 +	Private->SDL_modelist[22]->w = 160; Private->SDL_modelist[22]->h = 144; 
  32.335 +
  32.336 +    Private->SDL_modelist[23]->w = 640; Private->SDL_modelist[2]->h = 200;  //s80 some new modes 
  32.337 +    Private->SDL_modelist[24]->w = 640; Private->SDL_modelist[2]->h = 320;  //s90 modes are added
  32.338 +    Private->SDL_modelist[25]->w = 640; Private->SDL_modelist[2]->h = 240;  //here
  32.339 +	Private->SDL_modelist[26]->w = 640; Private->SDL_modelist[4]->h = 200;  //now
  32.340 +
  32.341 +	Private->SDL_modelist[27] = NULL;
  32.342 +
  32.343 +    /* Construct Epoc window */
  32.344 +
  32.345 +    ConstructWindowL(_this);
  32.346 +
  32.347 +    /* Initialise Epoc frame buffer */
  32.348 +
  32.349 +    TDisplayMode displayMode = Private->EPOC_WsScreen->DisplayMode();
  32.350 +
  32.351 +#if !defined(__WINS__) && !defined(TEST_BM_DRAW)
  32.352 +
  32.353 +    TScreenInfoV01 screenInfo;
  32.354 +	TPckg<TScreenInfoV01> sInfo(screenInfo);
  32.355 +	UserSvr::ScreenInfo(sInfo);
  32.356 +
  32.357 +	Private->EPOC_ScreenSize		= screenInfo.iScreenSize; 
  32.358 +	Private->EPOC_DisplayMode		= displayMode;
  32.359 +    Private->EPOC_HasFrameBuffer	= screenInfo.iScreenAddressValid;
  32.360 +	Private->EPOC_FrameBuffer		= Private->EPOC_HasFrameBuffer ? (TUint8*) screenInfo.iScreenAddress : NULL;
  32.361 +	Private->EPOC_BytesPerPixel	    = ((GetBpp(displayMode)-1) / 8) + 1;
  32.362 +	
  32.363 +    Private->EPOC_BytesPerScanLine	= screenInfo.iScreenSize.iWidth * Private->EPOC_BytesPerPixel;
  32.364 +	Private->EPOC_BytesPerScreen	= Private->EPOC_BytesPerScanLine * Private->EPOC_ScreenSize.iHeight;
  32.365 +
  32.366 +    SDL_TRACE1("Screen width %d", screenInfo.iScreenSize.iWidth);
  32.367 +    SDL_TRACE1("Screen height %d", screenInfo.iScreenSize.iHeight);
  32.368 +    SDL_TRACE1("Screen dmode %d", displayMode);
  32.369 +    SDL_TRACE1("Screen valid %d", screenInfo.iScreenAddressValid);
  32.370 +
  32.371 +    SDL_TRACE1("bpp %d", Private->EPOC_BytesPerPixel);
  32.372 +    SDL_TRACE1("bpsl %d", Private->EPOC_BytesPerScanLine);
  32.373 +    SDL_TRACE1("bps %d", Private->EPOC_BytesPerScreen);
  32.374 +
  32.375 +
  32.376 +    /* It seems that in SA1100 machines for 8bpp displays there is a 512 palette table at the 
  32.377 +     * beginning of the frame buffer. E.g. Series 7 and Netbook.
  32.378 +     * In 12 bpp machines the table has 16 entries.
  32.379 +	 */
  32.380 +	if (Private->EPOC_HasFrameBuffer && GetBpp(displayMode) == 8)
  32.381 +        {
  32.382 +		Private->EPOC_FrameBuffer += 512;
  32.383 +        }
  32.384 +	else
  32.385 +        {
  32.386 +        Private->EPOC_FrameBuffer += 32;
  32.387 +        }
  32.388 +        /*if (Private->EPOC_HasFrameBuffer && GetBpp(displayMode) == 12)
  32.389 +		Private->EPOC_FrameBuffer += 16 * 2;
  32.390 +    if (Private->EPOC_HasFrameBuffer && GetBpp(displayMode) == 16)
  32.391 +		Private->EPOC_FrameBuffer += 16 * 2;
  32.392 +    */
  32.393 +#else /* defined __WINS__ */
  32.394 +    
  32.395 +    /* Create bitmap, device and context for screen drawing */
  32.396 +    Private->EPOC_ScreenSize        = Private->EPOC_WsScreen->SizeInPixels();
  32.397 +
  32.398 +	Private->EPOC_Bitmap = new (ELeave) CWsBitmap(Private->EPOC_WsSession);
  32.399 +	Private->EPOC_Bitmap->Create(Private->EPOC_ScreenSize, displayMode);
  32.400 +
  32.401 +	Private->EPOC_DisplayMode	    = displayMode;
  32.402 +    Private->EPOC_HasFrameBuffer    = ETrue;
  32.403 +    Private->EPOC_FrameBuffer       = NULL; /* Private->EPOC_Bitmap->DataAddress() can change any time */
  32.404 +	Private->EPOC_BytesPerPixel	    = ((GetBpp(displayMode)-1) / 8) + 1;
  32.405 +	Private->EPOC_BytesPerScanLine  = Private->EPOC_WsScreen->SizeInPixels().iWidth * Private->EPOC_BytesPerPixel;
  32.406 +
  32.407 +#endif /* __WINS__ */
  32.408 +
  32.409 +#ifndef SYMBIAN_CRYSTAL
  32.410 +	// Get draw device for updating the screen
  32.411 +	TScreenInfoV01 screenInfo2;
  32.412 +    
  32.413 +    Epoc_Runtime::GetScreenInfo(screenInfo2);
  32.414 +
  32.415 +	TRAPD(status, Private->EPOC_DrawDevice = CFbsDrawDevice::NewScreenDeviceL(screenInfo2, displayMode));
  32.416 +	User::LeaveIfError(status);
  32.417 +#endif
  32.418 +
  32.419 +    /* The "best" video format should be returned to caller. */
  32.420 +
  32.421 +    vformat->BitsPerPixel       = /*!!GetBpp(displayMode) */ 8;
  32.422 +    vformat->BytesPerPixel      = /*!!Private->EPOC_BytesPerPixel*/ 1;
  32.423 +
  32.424 +    /* Activate events for me */
  32.425 +
  32.426 +	Private->EPOC_WsEventStatus = KRequestPending;
  32.427 +	Private->EPOC_WsSession.EventReady(&Private->EPOC_WsEventStatus);
  32.428 +
  32.429 +    SDL_TRACE("SDL:WsEventStatus");
  32.430 +    User::WaitForRequest(Private->EPOC_WsEventStatus); //Markus: I added this and ...
  32.431 +
  32.432 +	Private->EPOC_RedrawEventStatus = KRequestPending;
  32.433 +	Private->EPOC_WsSession.RedrawReady(&Private->EPOC_RedrawEventStatus);
  32.434 +    
  32.435 +    SDL_TRACE("SDL:RedrawEventStatus");
  32.436 +    User::WaitForRequest(Private->EPOC_RedrawEventStatus); //...this, if not catches a stray event is risen
  32.437 +                                                           //if there are active objects used, or confucing
  32.438 +                                                           //actions with User::WaitForAnyRequest
  32.439 +    Private->EPOC_WsWindow.PointerFilter(EPointerFilterDrag, 0); 
  32.440 +
  32.441 +    Private->EPOC_ScreenOffset = TPoint(0, 0);
  32.442 +
  32.443 +#if defined(__WINS__) || defined(TEST_BM_DRAW)
  32.444 +	LockHeap(Private->EPOC_Bitmap); // Lock bitmap heap
  32.445 +#endif
  32.446 +
  32.447 +    SDL_TRACE("SDL:DrawBackground");
  32.448 +	DrawBackground(_this); // Clear screen
  32.449 +
  32.450 +#if defined(__WINS__) || defined(TEST_BM_DRAW)
  32.451 +	UnlockHeap(Private->EPOC_Bitmap); // Unlock bitmap heap
  32.452 +#endif
  32.453 +    //!! TODO: error handling
  32.454 +    //if (ret != KErrNone)
  32.455 +    //    return(-1);
  32.456 +    //else
  32.457 +	    return(0);
  32.458 +}
  32.459 +
  32.460 +
  32.461 +SDL_Rect **EPOC_ListModes(_THIS, SDL_PixelFormat *format, Uint32 /*flags*/)
  32.462 +{
  32.463 +    if (format->BitsPerPixel == 12 || format->BitsPerPixel == 8)
  32.464 +        return Private->SDL_modelist;
  32.465 +    return NULL;
  32.466 +}
  32.467 +
  32.468 +int EPOC_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color *colors)
  32.469 +{
  32.470 +	if ((firstcolor+ncolors) > 256)
  32.471 +		return -1;
  32.472 +//    SDL_TRACE1("colors %d", (TDisplayModeUtils::NumDisplayModeColors(Private->EPOC_DisplayMode)));
  32.473 +    if(TDisplayModeUtils::NumDisplayModeColors(Private->EPOC_DisplayMode) == 4096)
  32.474 +        {
  32.475 +	// Set 12 bit palette
  32.476 +        for(int i = firstcolor; i < ncolors; i++)
  32.477 +            {
  32.478 +	        // 4k value: 0000 rrrr gggg bbbb
  32.479 +	        TUint32 color4K	 = (colors[i].r & 0x0000f0) << 4;
  32.480 +	        color4K			|= (colors[i].g & 0x0000f0);      
  32.481 +	        color4K			|= (colors[i].b & 0x0000f0) >> 4;
  32.482 +            EPOC_HWPalette_256_to_Screen[i] = color4K;
  32.483 +            }
  32.484 +        }
  32.485 +    else if(TDisplayModeUtils::NumDisplayModeColors(Private->EPOC_DisplayMode) == 65536)
  32.486 +        {
  32.487 +        for(int i = firstcolor; i < ncolors; i++)
  32.488 +            {
  32.489 +			// 64k-colour displays effectively support RGB values
  32.490 +			// with 5 bits allocated to red, 6 to green and 5 to blue
  32.491 +			// 64k value: rrrr rggg gggb bbbb
  32.492 +	        TUint32 color64K = (colors[i].r & 0x0000f8) << 8;
  32.493 +	        color64K		|= (colors[i].g & 0x0000fc) << 3;
  32.494 +	        color64K		|= (colors[i].b & 0x0000f8) >> 3;
  32.495 +            EPOC_HWPalette_256_to_Screen[i] = color64K;
  32.496 +            }
  32.497 +        }
  32.498 +    else if(TDisplayModeUtils::NumDisplayModeColors(Private->EPOC_DisplayMode) == 16777216)
  32.499 +        {
  32.500 +        for(int i = firstcolor; i < ncolors; i++)
  32.501 +            {
  32.502 +			// 16M-colour
  32.503 +            //0000 0000 rrrr rrrr gggg gggg bbbb bbbb
  32.504 +	        TUint32 color16M = colors[i].r << 16;
  32.505 +	        color16M		|= colors[i].g << 8;
  32.506 +	        color16M		|= colors[i].b;
  32.507 +            EPOC_HWPalette_256_to_Screen[i] = color16M;
  32.508 +            }
  32.509 +        }
  32.510 +    else
  32.511 +        {
  32.512 +        return -2;
  32.513 +        }
  32.514 +	return(0);
  32.515 +}
  32.516 +
  32.517 +
  32.518 +SDL_Surface *EPOC_SetVideoMode(_THIS, SDL_Surface *current,
  32.519 +				int width, int height, int bpp, Uint32 /*flags*/)
  32.520 +{
  32.521 +	SDL_TRACE("SDL:EPOC_SetVideoMode");
  32.522 +    /* Check parameters */
  32.523 +#ifdef SYMBIAN_CRYSTAL
  32.524 +   if (! (bpp == 8 || bpp == 12 || bpp == 16) &&
  32.525 +		 (
  32.526 +		  (width == 640 && height == 200) ||
  32.527 +          (width == 640 && height == 400) || 
  32.528 +          (width == 640 && height == 480) || 
  32.529 +          (width == 320 && height == 200) || 
  32.530 +          (width == 320 && height == 240)
  32.531 +		 )) {
  32.532 +		SDL_SetError("Requested video mode is not supported");
  32.533 +        return NULL;
  32.534 +    }
  32.535 +#else // SYMBIAN_SERIES60
  32.536 +   if (! (bpp == 8 || bpp == 12 || bpp == 16) &&
  32.537 +		 (
  32.538 +		  (width == 320 && height == 200) || 
  32.539 +          (width == 320 && height == 240) ||
  32.540 +		  (width == 256 && height == 192) ||  
  32.541 +		  (width == 176 && height == 208) || 
  32.542 +		  (width == 208 && height == 176) || // Rotated
  32.543 +		  (width == 160 && height == 144)    
  32.544 +		 )) {
  32.545 +		SDL_SetError("Requested video mode is not supported");
  32.546 +        return NULL;
  32.547 +    }
  32.548 +#endif
  32.549 +
  32.550 +    if (current && current->pixels) {
  32.551 +        free(current->pixels);
  32.552 +        current->pixels = NULL;
  32.553 +    }
  32.554 +	if ( ! SDL_ReallocFormat(current, bpp, 0, 0, 0, 0) ) {
  32.555 +		return(NULL);
  32.556 +	}
  32.557 +
  32.558 +    /* Set up the new mode framebuffer */
  32.559 +    if (bpp == 8) 
  32.560 +	    current->flags = (SDL_FULLSCREEN|SDL_SWSURFACE|SDL_PREALLOC|SDL_HWPALETTE); 
  32.561 +    else // 12 bpp, 16 bpp
  32.562 +	    current->flags = (SDL_FULLSCREEN|SDL_SWSURFACE|SDL_PREALLOC); 
  32.563 +	current->w = width;
  32.564 +	current->h = height;
  32.565 +    int numBytesPerPixel = ((bpp-1)>>3) + 1;   
  32.566 +	current->pitch = numBytesPerPixel * width; // Number of bytes in scanline 
  32.567 +	current->pixels = malloc(width * height * numBytesPerPixel);
  32.568 +	memset(current->pixels, 0, width * height * numBytesPerPixel);
  32.569 +
  32.570 +	/* Set the blit function */
  32.571 +	_this->UpdateRects = EPOC_DirectUpdate;
  32.572 +
  32.573 +    /*
  32.574 +     *  Logic for getting suitable screen dimensions, offset, scaling and orientation
  32.575 +     */
  32.576 +
  32.577 +	int w = current->w;
  32.578 +	int h = current->h;
  32.579 +	
  32.580 +	// Rotate, if the screen does not fit horizontally and it is landscape screen
  32.581 +/*
  32.582 +	if ((width>Private->EPOC_ScreenSize.iWidth) &&  (width>height)) {
  32.583 +		Private->EPOC_ScreenOrientation = CFbsBitGc::EGraphicsOrientationRotated270;
  32.584 +		w = current->h; 
  32.585 +		h = current->w; 
  32.586 +	}
  32.587 +*/
  32.588 +	// Get nearest stepwise scale values for width and height. The smallest supported scaled screen is 1/2.
  32.589 +	TInt scaleValue = 0;
  32.590 +	Private->EPOC_ScreenXScaleValue = 1;
  32.591 +	Private->EPOC_ScreenYScaleValue = 1;
  32.592 +	if (w > Private->EPOC_ScreenSize.iWidth) {
  32.593 +		// Find the biggest scale value that result the width that fits in the screen HW
  32.594 +		for (scaleValue = 2; scaleValue++;) {
  32.595 +			TInt scaledWidth = (w * (scaleValue-1))/scaleValue;
  32.596 +			if (scaledWidth > Private->EPOC_ScreenSize.iWidth)
  32.597 +				break;
  32.598 +		}
  32.599 +		Private->EPOC_ScreenXScaleValue = Max(2, scaleValue - 1);
  32.600 +		w = (w * (Private->EPOC_ScreenXScaleValue-1))/Private->EPOC_ScreenXScaleValue;
  32.601 +	}
  32.602 +	if (h > Private->EPOC_ScreenSize.iHeight) {
  32.603 +		// Find the biggest scale value that result the height that fits in the screen HW
  32.604 +		for (scaleValue = 2; scaleValue++;) {
  32.605 +			TInt scaledHeight = (h * (scaleValue-1))/scaleValue;
  32.606 +			if (scaledHeight > Private->EPOC_ScreenSize.iHeight)
  32.607 +				break;
  32.608 +		}
  32.609 +		Private->EPOC_ScreenYScaleValue = Max(2, scaleValue - 1);
  32.610 +		h = (h * (Private->EPOC_ScreenYScaleValue-1))/Private->EPOC_ScreenYScaleValue;
  32.611 +	}
  32.612 +
  32.613 +    /* Centralize game window on device screen  */
  32.614 +    Private->EPOC_ScreenOffset.iX = (Private->EPOC_ScreenSize.iWidth - w) / 2;
  32.615 +	if (Private->EPOC_ScreenOffset.iX < 0)
  32.616 +		Private->EPOC_ScreenOffset.iX = 0;
  32.617 +    Private->EPOC_ScreenOffset.iY = (Private->EPOC_ScreenSize.iHeight - h) / 2;
  32.618 +	if (Private->EPOC_ScreenOffset.iY < 0)
  32.619 +		Private->EPOC_ScreenOffset.iY = 0;
  32.620 +
  32.621 +
  32.622 +    SDL_TRACE1("View width %d", w);
  32.623 +    SDL_TRACE1("View height %d", h);
  32.624 +    SDL_TRACE1("View bmode %d", bpp);
  32.625 +    SDL_TRACE1("View s %d", scaleValue);
  32.626 +    SDL_TRACE1("View x %d", Private->EPOC_ScreenOffset.iX);
  32.627 +    SDL_TRACE1("View y %d", Private->EPOC_ScreenOffset.iY);
  32.628 +
  32.629 +	/* We're done */
  32.630 +	return(current);
  32.631 +}
  32.632 +
  32.633 +
  32.634 +void RedrawWindowL(_THIS)
  32.635 +{
  32.636 +
  32.637 +#if defined(__WINS__) || defined(TEST_BM_DRAW)
  32.638 +	    LockHeap(Private->EPOC_Bitmap); // Lock bitmap heap
  32.639 +	    Private->EPOC_WindowGc->Activate(Private->EPOC_WsWindow);
  32.640 +#endif
  32.641 +
  32.642 +    int w = _this->screen->w;
  32.643 +    int h = _this->screen->h;
  32.644 +	if (Private->EPOC_ScreenOrientation == CFbsBitGc::EGraphicsOrientationRotated270) {
  32.645 +		w = _this->screen->h;
  32.646 +		h = _this->screen->w;
  32.647 +	}
  32.648 +    if ((w < Private->EPOC_ScreenSize.iWidth)
  32.649 +        || (h < Private->EPOC_ScreenSize.iHeight)) {
  32.650 +		DrawBackground(_this);
  32.651 +    }
  32.652 +
  32.653 +    /* Tell the system that something has been drawn */
  32.654 +	TRect  rect = TRect(Private->EPOC_WsWindow.Size());
  32.655 +  	Private->EPOC_WsWindow.Invalidate(rect);
  32.656 +
  32.657 +#if defined(__WINS__) || defined(TEST_BM_DRAW)
  32.658 +	Private->EPOC_WsWindow.BeginRedraw(rect);
  32.659 +	Private->EPOC_WindowGc->BitBlt(TPoint(), Private->EPOC_Bitmap);
  32.660 +	Private->EPOC_WsWindow.EndRedraw();
  32.661 +	Private->EPOC_WindowGc->Deactivate();
  32.662 +    UnlockHeap(Private->EPOC_Bitmap);; // Unlock bitmap heap
  32.663 +	Private->EPOC_WsSession.Flush();
  32.664 +#endif
  32.665 +
  32.666 +    /* Draw current buffer */
  32.667 +    SDL_Rect fullScreen;
  32.668 +    fullScreen.x = 0;
  32.669 +    fullScreen.y = 0;
  32.670 +    fullScreen.w = _this->screen->w;
  32.671 +    fullScreen.h = _this->screen->h;
  32.672 +    EPOC_DirectUpdate(_this, 1, &fullScreen);
  32.673 +}
  32.674 +
  32.675 +
  32.676 +void DrawBackground(_THIS)
  32.677 +{
  32.678 +	/* Draw background */
  32.679 +#if defined(__WINS__) || defined(TEST_BM_DRAW)
  32.680 +	//warning heap is not locked! - a function calling must ensure that it's ok
  32.681 +    TUint16* screenBuffer = (TUint16*)Private->EPOC_Bitmap->DataAddress();
  32.682 +#else
  32.683 +    TUint16* screenBuffer = (TUint16*)Private->EPOC_FrameBuffer;
  32.684 +#endif
  32.685 +	// Draw black background
  32.686 +	Mem::FillZ(screenBuffer, Private->EPOC_BytesPerScreen);
  32.687 +
  32.688 +#if 0
  32.689 +    for (int y = 0; y < Private->EPOC_ScreenSize.iHeight; y++) {
  32.690 +		for (int x = 0; x < Private->EPOC_ScreenSize.iWidth; x++) {
  32.691 +#ifdef SYMBIAN_CRYSTAL
  32.692 +			const TUint16 color = 0; // ((x+y)>>1) & 0xf; /* Draw blue stripes pattern, because in e.g. 320x200 mode there is a big background area*/
  32.693 +#else // SYMBIAN_SERIES60
  32.694 +            const TUint16 color = 0; /* Draw black background */
  32.695 +#endif
  32.696 +            *screenBuffer++ = color;
  32.697 +		}
  32.698 +	}
  32.699 +#endif
  32.700 +}
  32.701 +
  32.702 +
  32.703 +/* We don't actually allow hardware surfaces other than the main one */
  32.704 +static int EPOC_AllocHWSurface(_THIS, SDL_Surface* /*surface*/)
  32.705 +{
  32.706 +	return(-1);
  32.707 +}
  32.708 +static void EPOC_FreeHWSurface(_THIS, SDL_Surface* /*surface*/)
  32.709 +{
  32.710 +	return;
  32.711 +}
  32.712 +
  32.713 +static int EPOC_LockHWSurface(_THIS, SDL_Surface* /*surface*/)
  32.714 +{
  32.715 +	return(0);
  32.716 +}
  32.717 +static void EPOC_UnlockHWSurface(_THIS, SDL_Surface* /*surface*/)
  32.718 +{
  32.719 +	return;
  32.720 +}
  32.721 +
  32.722 +static int EPOC_FlipHWSurface(_THIS, SDL_Surface* /*surface*/)
  32.723 +{
  32.724 +	return(0);
  32.725 +}
  32.726 +
  32.727 +static void EPOC_DirectUpdate(_THIS, int numrects, SDL_Rect *rects)
  32.728 +{
  32.729 +    //TInt focusWindowGroupId = Private->EPOC_WsSession.GetFocusWindowGroup();//these are async services
  32.730 +   // if (focusWindowGroupId != Private->EPOC_WsWindowGroupID) {              //for that cannot be called from
  32.731 +                                                                            //SDL threads ???
  32.732 +    if (!Private->EPOC_IsWindowFocused)
  32.733 +        {
  32.734 +        /* Force focus window to redraw again for cleaning away SDL screen graphics */
  32.735 +/*
  32.736 +        TInt pos = Private->EPOC_WsWindowGroup.OrdinalPosition();
  32.737 +        Private->EPOC_WsWindowGroup.SetOrdinalPosition(0, KMaxTInt);
  32.738 +       	TRect  rect = TRect(Private->EPOC_WsWindow.Size());
  32.739 +        Private->EPOC_WsWindow.Invalidate(rect);
  32.740 +        Private->EPOC_WsWindowGroup.SetOrdinalPosition(pos, ECoeWinPriorityNormal);
  32.741 +       */ /* If this is not the topmost window, wait here! Sleep for 1 second to give cpu time to 
  32.742 +           multitasking and poll for being the topmost window.
  32.743 +        */
  32.744 +    //    if (Private->EPOC_WsSession.GetFocusWindowGroup() != Private->EPOC_WsWindowGroupID) {
  32.745 +           
  32.746 +		   /* !!TODO: Could call GetRedraw() etc. for WsSession and redraw the screen if needed. That might be 
  32.747 +		      needed if a small dialog comes in front of Game screen.
  32.748 +		   */
  32.749 +           // while (Private->EPOC_WsSession.GetFocusWindowGroup() != Private->EPOC_WsWindowGroupID)
  32.750 +        
  32.751 +        SDL_PauseAudio(1);
  32.752 +        SDL_Delay(1000);
  32.753 +        return;
  32.754 +      //  }
  32.755 +
  32.756 +    //    RedrawWindowL(_this);  
  32.757 +    }
  32.758 +
  32.759 +    SDL_PauseAudio(0);
  32.760 +
  32.761 +	// if we are not focused, do not draw
  32.762 +//	if (!Private->EPOC_IsWindowFocused)
  32.763 +//		return;
  32.764 +#if defined(__WINS__) || defined(TEST_BM_DRAW)
  32.765 +	TBitmapUtil lock(Private->EPOC_Bitmap);	
  32.766 +    lock.Begin(TPoint(0,0)); // Lock bitmap heap
  32.767 +	Private->EPOC_WindowGc->Activate(Private->EPOC_WsWindow);
  32.768 +    TUint16* screenBuffer = (TUint16*)Private->EPOC_Bitmap->DataAddress();
  32.769 +#else
  32.770 +    TUint16* screenBuffer = (TUint16*)Private->EPOC_FrameBuffer;
  32.771 +#endif
  32.772 +
  32.773 +	if (Private->EPOC_ScreenOrientation == CFbsBitGc::EGraphicsOrientationRotated270)
  32.774 +		DirectDrawRotated(_this, numrects, rects, screenBuffer);
  32.775 +	else
  32.776 +		DirectDraw(_this, numrects, rects, screenBuffer);
  32.777 +    
  32.778 +   
  32.779 +#if defined(__WINS__) || defined(TEST_BM_DRAW)
  32.780 +
  32.781 +	TRect  rect = TRect(Private->EPOC_WsWindow.Size());
  32.782 +	Private->EPOC_WsWindow.Invalidate(rect);
  32.783 +	Private->EPOC_WsWindow.BeginRedraw(rect);
  32.784 +	Private->EPOC_WindowGc->BitBlt(TPoint(), Private->EPOC_Bitmap);
  32.785 +	Private->EPOC_WsWindow.EndRedraw();
  32.786 +	Private->EPOC_WindowGc->Deactivate();
  32.787 +    lock.End(); // Unlock bitmap heap
  32.788 +	Private->EPOC_WsSession.Flush();
  32.789 +#else
  32.790 +#ifndef SYMBIAN_CRYSTAL
  32.791 +	// This is not needed in Crystal. What is the performance penalty in SERIES60?
  32.792 +    TRect  rect2 = TRect(Private->EPOC_WsWindow.Size());
  32.793 +    
  32.794 +    Private->EPOC_DrawDevice->UpdateRegion(rect2); // Should we update rects parameter area only??
  32.795 +    Private->EPOC_DrawDevice->Update();
  32.796 +#endif
  32.797 +#endif
  32.798 +
  32.799 +    /* Update virtual cursor. !!Do not yet work properly
  32.800 +    Private->EPOC_WsSession.SetPointerCursorPosition(Private->EPOC_WsSession.PointerCursorPosition());
  32.801 +    */
  32.802 +
  32.803 +    /*static int foo = 1;
  32.804 +
  32.805 +    	for ( int i=0; i < numrects; ++i ) {
  32.806 +        const SDL_Rect& currentRect = rects[i];
  32.807 +        SDL_Rect rect2;
  32.808 +        rect2.x = currentRect.x;
  32.809 +        rect2.y = currentRect.y;
  32.810 +        rect2.w = currentRect.w;
  32.811 +        rect2.h = currentRect.h;
  32.812 +
  32.813 +        if (rect2.w <= 0 || rect2.h <= 0) 
  32.814 +            continue;
  32.815 +
  32.816 +    
  32.817 +    foo++;
  32.818 +    if((foo % 200) == 0)
  32.819 +        {
  32.820 +        SDL_TRACE1("foo %d", foo);
  32.821 +        CFbsBitmap* b = new (ELeave) CFbsBitmap;
  32.822 +        SDL_TRACE1("bee %d", (int)b);
  32.823 +        int e = b->Create(TSize(currentRect.w, currentRect.h), Private->EPOC_DisplayMode);
  32.824 +        
  32.825 +        SDL_TRACE1("err %d", e);
  32.826 +        if(e != KErrNone)
  32.827 +            User::Panic(_L("damn"), e);
  32.828 +
  32.829 +        TBitmapUtil u(b);
  32.830 +        u.Begin(TPoint(0, 0));
  32.831 +        TUint32* d = b->DataAddress();
  32.832 +        
  32.833 +        SDL_TRACE1("addr %d", (int)d);
  32.834 +
  32.835 +        for(TInt o = 0; o < currentRect.h; o++)
  32.836 +            for(TInt p = 0; p < currentRect.w; p++)
  32.837 +                {
  32.838 +                u.SetPos(TPoint(p, o));
  32.839 +                u.SetPixel(0xFFFF);
  32.840 +                }
  32.841 +
  32.842 +        SDL_TRACE1("w %d", (int)currentRect.w);
  32.843 +        SDL_TRACE1("h %d", (int)currentRect.h);
  32.844 +
  32.845 +        SDL_TRACE1("addr %d", (int)Private->EPOC_DisplayMode);
  32.846 +
  32.847 +        
  32.848 +        const TUint f = (TUint)Private->EPOC_FrameBuffer;
  32.849 +        const TUint y = (TUint)Private->EPOC_BytesPerScreen;
  32.850 +
  32.851 +        
  32.852 +        SDL_TRACE1("frame %u", f);
  32.853 +        SDL_TRACE1("bytes %u", y);
  32.854 +
  32.855 +        Mem::Copy(d, Private->EPOC_FrameBuffer, Private->EPOC_BytesPerScreen);
  32.856 +
  32.857 +        SDL_TRACE("kopied");
  32.858 +
  32.859 +        u.End();
  32.860 +        TBuf<32> name;
  32.861 +        name.Format(_L("C:\\nokia\\images\\doom%d.mbm"), (foo / 200));
  32.862 +        e= b->Save(name);
  32.863 +        if(e != KErrNone)
  32.864 +            User::Panic(_L("damned"), e);
  32.865 +        delete b;
  32.866 +            }}*/
  32.867 +}
  32.868 +
  32.869 +
  32.870 +void DirectDraw(_THIS, int numrects, SDL_Rect *rects, TUint16* screenBuffer)
  32.871 +{
  32.872 +	TInt i;
  32.873 +
  32.874 +    const TInt sourceNumBytesPerPixel = ((_this->screen->format->BitsPerPixel-1)>>3) + 1;   
  32.875 +    const TPoint fixedOffset = Private->EPOC_ScreenOffset;   
  32.876 +    const TInt screenW = _this->screen->w;
  32.877 +    const TInt screenH = _this->screen->h;
  32.878 +    const TInt sourceScanlineLength = screenW;
  32.879 +    const TInt targetScanlineLength = Private->EPOC_ScreenSize.iWidth;
  32.880 +
  32.881 +	/* Render the rectangles in the list */
  32.882 +
  32.883 +	for ( i=0; i < numrects; ++i ) {
  32.884 +        const SDL_Rect& currentRect = rects[i];
  32.885 +        SDL_Rect rect2;
  32.886 +        rect2.x = currentRect.x;
  32.887 +        rect2.y = currentRect.y;
  32.888 +        rect2.w = currentRect.w;
  32.889 +        rect2.h = currentRect.h;
  32.890 +
  32.891 +        if (rect2.w <= 0 || rect2.h <= 0) /* sanity check */
  32.892 +            continue;
  32.893 +
  32.894 +        /* All variables are measured in pixels */
  32.895 +
  32.896 +        /* Check rects validity, i.e. upper and lower bounds */
  32.897 +        TInt maxX = Min(screenW - 1, rect2.x + rect2.w - 1);
  32.898 +        TInt maxY = Min(screenH - 1, rect2.y + rect2.h - 1);
  32.899 +        if (maxX < 0 || maxY < 0) /* sanity check */
  32.900 +            continue;
  32.901 +		/* Clip from bottom */
  32.902 +        maxY = Min(maxY, Private->EPOC_ScreenSize.iHeight-1); 
  32.903 +		/* TODO: Clip from the right side */
  32.904 +
  32.905 +        const TInt sourceRectWidth = maxX - rect2.x + 1;
  32.906 +        const TInt sourceRectWidthInBytes = sourceRectWidth * sourceNumBytesPerPixel;
  32.907 +        const TInt sourceRectHeight = maxY - rect2.y + 1;
  32.908 +        const TInt sourceStartOffset = rect2.x + rect2.y * sourceScanlineLength;
  32.909 +		const TUint skipValue = 1; // no skip
  32.910 +
  32.911 +        TInt targetStartOffset = fixedOffset.iX + rect2.x + (fixedOffset.iY +rect2.y) * targetScanlineLength;   
  32.912 +        
  32.913 +        // Nokia7650 native mode: 12 bpp --> 12 bpp
  32.914 +        //
  32.915 +
  32.916 +        switch (_this->screen->format->BitsPerPixel)
  32.917 +			{
  32.918 +		case 12:
  32.919 +			{
  32.920 +			TUint16* bitmapLine = (TUint16*)_this->screen->pixels + sourceStartOffset;
  32.921 +			TUint16* screenMemory = screenBuffer + targetStartOffset;
  32.922 +			if (skipValue == 1)
  32.923 +				{
  32.924 +				for(TInt y = 0 ; y < sourceRectHeight ; y++)
  32.925 +					{
  32.926 +					Mem::Copy(screenMemory, bitmapLine, sourceRectWidthInBytes);
  32.927 +					}
  32.928 +					bitmapLine += sourceScanlineLength;
  32.929 +					screenMemory += targetScanlineLength;
  32.930 +				}
  32.931 +			else
  32.932 +				{
  32.933 +				for(TInt y = 0 ; y < sourceRectHeight ; y++)
  32.934 +					{
  32.935 +					//TODO: optimize: separate loops for 1, 2 and n skip. Mem::Copy() can be used in unscaled case.
  32.936 +					TUint16* bitmapPos = bitmapLine; /* 2 bytes per pixel */
  32.937 +					TUint16* screenMemoryLinePos = screenMemory; /* 2 bytes per pixel */
  32.938 +					for(TInt x = 0 ; x < sourceRectWidth ; x++)
  32.939 +						{					
  32.940 +						__ASSERT_DEBUG(screenMemory < (screenBuffer + Private->EPOC_ScreenSize.iWidth * Private->EPOC_ScreenSize.iHeight), User::Panic(_L("SDL"), KErrCorrupt));
  32.941 +						__ASSERT_DEBUG(screenMemory >= screenBuffer, User::Panic(_L("SDL"), KErrCorrupt));
  32.942 +						__ASSERT_DEBUG(bitmapLine < ((TUint16*)_this->screen->pixels + (_this->screen->w * _this->screen->h)), User::Panic(_L("SDL"), KErrCorrupt));
  32.943 +						__ASSERT_DEBUG(bitmapLine >=  (TUint16*)_this->screen->pixels, User::Panic(_L("SDL"), KErrCorrupt));
  32.944 +                    
  32.945 +						*screenMemoryLinePos++ = *bitmapPos;
  32.946 +						bitmapPos+=skipValue;
  32.947 +						}
  32.948 +					bitmapLine += sourceScanlineLength;
  32.949 +					screenMemory += targetScanlineLength;
  32.950 +					}
  32.951 +				}
  32.952 +			}
  32.953 +			break;
  32.954 +        // 256 color paletted mode: 8 bpp  --> 12 bpp
  32.955 +        //
  32.956 +		default:
  32.957 +			{
  32.958 +            if(Private->EPOC_BytesPerPixel <= 2)
  32.959 +                {
  32.960 +			    TUint8* bitmapLine = (TUint8*)_this->screen->pixels + sourceStartOffset;
  32.961 +                TUint16* screenMemory = screenBuffer + targetStartOffset;
  32.962 +				    for(TInt y = 0 ; y < sourceRectHeight ; y++)
  32.963 +					    {
  32.964 +					    TUint8* bitmapPos = bitmapLine; /* 1 byte per pixel */
  32.965 +					    TUint16* screenMemoryLinePos = screenMemory; /* 2 bytes per pixel */
  32.966 +					    /* Convert each pixel from 256 palette to 4k color values */
  32.967 +					    for(TInt x = 0 ; x < sourceRectWidth ; x++)
  32.968 +						    {
  32.969 +						    __ASSERT_DEBUG(screenMemoryLinePos < (screenBuffer + (Private->EPOC_ScreenSize.iWidth * Private->EPOC_ScreenSize.iHeight)), User::Panic(_L("SDL"), KErrCorrupt));
  32.970 +						    __ASSERT_DEBUG(screenMemoryLinePos >= screenBuffer, User::Panic(_L("SDL"), KErrCorrupt));
  32.971 +						    __ASSERT_DEBUG(bitmapPos < ((TUint8*)_this->screen->pixels + (_this->screen->w * _this->screen->h)), User::Panic(_L("SDL"), KErrCorrupt));
  32.972 +						    __ASSERT_DEBUG(bitmapPos >= (TUint8*)_this->screen->pixels, User::Panic(_L("SDL"), KErrCorrupt));               
  32.973 +						    *screenMemoryLinePos++ = EPOC_HWPalette_256_to_Screen[*bitmapPos++];
  32.974 +    //						bitmapPos+=skipValue; //TODO: optimize: separate loops for 1, 2 and n skip
  32.975 +						    }
  32.976 +					    bitmapLine += sourceScanlineLength;
  32.977 +					    screenMemory += targetScanlineLength;
  32.978 +					    }
  32.979 +                }
  32.980 +            else
  32.981 +                {
  32.982 +                TUint8* bitmapLine = (TUint8*)_this->screen->pixels + sourceStartOffset;
  32.983 +                TUint32* screenMemory = reinterpret_cast<TUint32*>(screenBuffer + targetStartOffset);
  32.984 +				    for(TInt y = 0 ; y < sourceRectHeight ; y++)
  32.985 +					    {
  32.986 +					    TUint8* bitmapPos = bitmapLine; /* 1 byte per pixel */
  32.987 +					    TUint32* screenMemoryLinePos = screenMemory; /* 2 bytes per pixel */
  32.988 +					    /* Convert each pixel from 256 palette to 4k color values */
  32.989 +					    for(TInt x = 0 ; x < sourceRectWidth ; x++)
  32.990 +						    {
  32.991 +						    __ASSERT_DEBUG(screenMemoryLinePos < (reinterpret_cast<TUint32*>(screenBuffer) + (Private->EPOC_ScreenSize.iWidth * Private->EPOC_ScreenSize.iHeight)), User::Panic(_L("SDL"), KErrCorrupt));
  32.992 +						    __ASSERT_DEBUG(screenMemoryLinePos >= reinterpret_cast<TUint32*>(screenBuffer), User::Panic(_L("SDL"), KErrCorrupt));
  32.993 +						    __ASSERT_DEBUG(bitmapPos < ((TUint8*)_this->screen->pixels + (_this->screen->w * _this->screen->h)), User::Panic(_L("SDL"), KErrCorrupt));
  32.994 +						    __ASSERT_DEBUG(bitmapPos >= (TUint8*)_this->screen->pixels, User::Panic(_L("SDL"), KErrCorrupt));               
  32.995 +						    *screenMemoryLinePos++ = EPOC_HWPalette_256_to_Screen[*bitmapPos++];
  32.996 +    //						bitmapPos+=skipValue; //TODO: optimize: separate loops for 1, 2 and n skip
  32.997 +						    }
  32.998 +					    bitmapLine += sourceScanlineLength;
  32.999 +					    screenMemory += targetScanlineLength;
 32.1000 +					    }
 32.1001 +                }
 32.1002 +			}
 32.1003 +		} // switch
 32.1004 +	} // for
 32.1005 +}
 32.1006 +
 32.1007 +/*
 32.1008 +void DirectDraw(_THIS, int numrects, SDL_Rect *rects, TUint16* screenBuffer)
 32.1009 +{
 32.1010 +	TInt i;
 32.1011 +    const TInt sourceNumBytesPerPixel = ((_this->screen->format->BitsPerPixel-1)>>3) + 1;   
 32.1012 +    const TPoint fixedOffset = Private->EPOC_ScreenOffset;   
 32.1013 +    const TInt screenW = _this->screen->w;
 32.1014 +    const TInt screenH = _this->screen->h;
 32.1015 +    const TInt sourceScanlineLength = screenW;
 32.1016 +    const TInt targetScanlineLength = Private->EPOC_ScreenSize.iWidth;
 32.1017 +
 32.1018 +	/* Render the rectangles in the list */
 32.1019 +
 32.1020 +/*	for ( i=0; i < numrects; ++i ) {
 32.1021 +        const SDL_Rect& currentRect = rects[i];
 32.1022 +        SDL_Rect rect2;
 32.1023 +        rect2.x = currentRect.x;
 32.1024 +        rect2.y = currentRect.y;
 32.1025 +        rect2.w = currentRect.w;
 32.1026 +        rect2.h = currentRect.h;
 32.1027 +
 32.1028 +        if (rect2.w <= 0 || rect2.h <= 0) /* sanity check */
 32.1029 +/*            continue;
 32.1030 +
 32.1031 +        /* All variables are measured in pixels */
 32.1032 +
 32.1033 +        /* Check rects validity, i.e. upper and lower bounds */
 32.1034 +/*        TInt maxX = Min(screenW - 1, rect2.x + rect2.w - 1);
 32.1035 +        TInt maxY = Min(screenH - 1, rect2.y + rect2.h - 1);
 32.1036 +        if (maxX < 0 || maxY < 0) /* sanity check */
 32.1037 +/*            continue;
 32.1038 +		/* Clip from bottom */
 32.1039 +/*        maxY = Min(maxY, Private->EPOC_ScreenSize.iHeight-1); 
 32.1040 +		/* TODO: Clip from the right side */
 32.1041 +
 32.1042 +/*		TInt sourceRectWidth = maxX - rect2.x + 1;
 32.1043 +        const TInt sourceRectWidthInBytes = sourceRectWidth * sourceNumBytesPerPixel;
 32.1044 +        const TInt sourceRectHeight = maxY - rect2.y + 1;
 32.1045 +        const TInt sourceStartOffset = rect2.x + rect2.y * sourceScanlineLength;
 32.1046 +		const TUint skipValue = Private->EPOC_ScreenXScaleValue; //1; // no skip
 32.1047 +
 32.1048 +		const TInt targetStartOffset = // = (fixedOffset.iX + (rect2.x / skipValue) + (fixedOffset.iY + rect2.y) * targetScanlineLength ) ;
 32.1049 +			(skipValue > 1 ? 
 32.1050 +			(fixedOffset.iX + (rect2.x / skipValue) + (fixedOffset.iY + rect2.y) * targetScanlineLength ) : 
 32.1051 +			(fixedOffset.iX +  rect2.x              + (fixedOffset.iY + rect2.y) * targetScanlineLength ));
 32.1052 +
 32.1053 +		__ASSERT_DEBUG(skipValue >= 1, User::Panic(KLibName, KErrArgument));
 32.1054 +
 32.1055 +        // Nokia7650 native mode: 12 bpp --> 12 bpp
 32.1056 +        //
 32.1057 +        switch (_this->screen->format->BitsPerPixel)
 32.1058 +			{
 32.1059 +		case 12:
 32.1060 +			{
 32.1061 +			TUint16* bitmapLine = (TUint16*)_this->screen->pixels + sourceStartOffset;
 32.1062 +			TUint16* screenMemory = screenBuffer + targetStartOffset;
 32.1063 +			if (skipValue == 1)
 32.1064 +				{
 32.1065 +				for(TInt y = 0 ; y < sourceRectHeight ; y++)
 32.1066 +					{
 32.1067 +					Mem::Copy(screenMemory, bitmapLine, sourceRectWidthInBytes);
 32.1068 +					}
 32.1069 +					bitmapLine += sourceScanlineLength;
 32.1070 +					screenMemory += targetScanlineLength;
 32.1071 +				}
 32.1072 +			else
 32.1073 +				{
 32.1074 +				for(TInt y = 0 ; y < sourceRectHeight ; y++)
 32.1075 +					{
 32.1076 +					//TODO: optimize: separate loops for 1, 2 and n skip. Mem::Copy() can be used in unscaled case.
 32.1077 +					TUint16* bitmapPos = bitmapLine; /* 2 bytes per pixel */
 32.1078 +/*					TUint16* screenMemoryLinePos = screenMemory; /* 2 bytes per pixel */
 32.1079 +/*					for(TInt x = 0 ; x < sourceRectWidth ; x++)
 32.1080 +						{					
 32.1081 +						__ASSERT_DEBUG(screenMemory < (screenBuffer + Private->EPOC_ScreenSize.iWidth * Private->EPOC_ScreenSize.iHeight), User::Panic(KLibName, KErrCorrupt));
 32.1082 +						__ASSERT_DEBUG(screenMemory >= screenBuffer, User::Panic(KLibName, KErrCorrupt));
 32.1083 +						__ASSERT_DEBUG(bitmapLine < ((TUint16*)_this->screen->pixels + (_this->screen->w * _this->screen->h)), User::Panic(KLibName, KErrCorrupt));
 32.1084 +						__ASSERT_DEBUG(bitmapLine >=  (TUint16*)_this->screen->pixels, User::Panic(KLibName, KErrCorrupt));
 32.1085 +                    
 32.1086 +						*screenMemoryLinePos++ = *bitmapPos;
 32.1087 +						bitmapPos+=skipValue;
 32.1088 +						}
 32.1089 +					bitmapLine += sourceScanlineLength;
 32.1090 +					screenMemory += targetScanlineLength;
 32.1091 +					}
 32.1092 +				}
 32.1093 +			}
 32.1094 +			break;
 32.1095 +        // 256 color paletted mode: 8 bpp  --> 12 bpp
 32.1096 +        //
 32.1097 +		default:
 32.1098 +			{
 32.1099 +			TUint8* bitmapLine = (TUint8*)_this->screen->pixels + sourceStartOffset;
 32.1100 +            TUint16* screenMemory = screenBuffer + targetStartOffset;
 32.1101 +			if (skipValue > 1)
 32.1102 +				sourceRectWidth /= skipValue;
 32.1103 +#if defined __MARM_ARMI__
 32.1104 +			__asm volatile("
 32.1105 +				mov		%4, %4, lsl #1	@ targetScanLineLength is in pixels, we need it in bytes
 32.1106 +			1:
 32.1107 +				mov		r6, %0			@ bitmapLine
 32.1108 +				mov		r7, %2			@ screenMemory
 32.1109 +				mov		r8, %6			@ sourceRectWidth
 32.1110 +			2:
 32.1111 +				ldrb	r4, [%0], %7			@ r4 = *bitmapPos; bitmapPos += skipValue
 32.1112 +				ldr		r5, [%1, r4, lsl #2]	@ only 16 lower bits actually used
 32.1113 +				subs	r8, r8, #1				@ x--
 32.1114 +				strh	r5, [%2], #2			@ *screenMemoryLinePos++ = r4
 32.1115 +				bne		2b
 32.1116 +
 32.1117 +				add		%0, r6, %3		@ bitmapLine += sourceScanlineLength
 32.1118 +				add		%2, r7, %4		@ screenMemory += targetScanlineLength
 32.1119 +				subs    %5, %5, #1		@ sourceRectHeight--
 32.1120 +				bne		1b
 32.1121 +				"
 32.1122 +				: // no output
 32.1123 +				//		%0								%1							%2						%3							%4						%5							%6					%7
 32.1124 +				: "r" (bitmapLine), "r" (&EPOC_HWPalette_256_to_Screen[0]), "r" (screenMemory), "r" (sourceScanlineLength), "r" (targetScanlineLength), "r" (sourceRectHeight), "r" (sourceRectWidth), "r" (skipValue)
 32.1125 +				: "r4", "r5", "r6", "r7", "r8"
 32.1126 +			);
 32.1127 +#else
 32.1128 +			for(TInt y = 0 ; y < sourceRectHeight ; y++)
 32.1129 +				{
 32.1130 +				TUint8* bitmapPos = bitmapLine; /* 1 byte per pixel */
 32.1131 +/*				TUint16* screenMemoryLinePos = screenMemory; /* 2 bytes per pixel */
 32.1132 +				/* Convert each pixel from 256 palette to 4k color values */
 32.1133 +/*				for (TInt x = 0 ; x < sourceRectWidth ; x++)
 32.1134 +					{
 32.1135 +					//__ASSERT_DEBUG(screenMemoryLinePos < (screenBuffer + (Private->EPOC_ScreenSize.iWidth * Private->EPOC_ScreenSize.iHeight)), User::Panic(KLibName, KErrCorrupt));
 32.1136 +					//__ASSERT_DEBUG(screenMemoryLinePos >= screenBuffer, User::Panic(KLibName, KErrCorrupt));
 32.1137 +					//__ASSERT_DEBUG(bitmapPos < ((TUint8*)_this->screen->pixels + (_this->screen->w * _this->screen->h)), User::Panic(KLibName, KErrCorrupt));
 32.1138 +					//__ASSERT_DEBUG(bitmapPos >= (TUint8*)_this->screen->pixels, User::Panic(KLibName, KErrCorrupt));
 32.1139 +            
 32.1140 +					*screenMemoryLinePos++ = EPOC_HWPalette_256_to_Screen[*bitmapPos];
 32.1141 +					bitmapPos += skipValue;
 32.1142 +					}
 32.1143 +				bitmapLine += sourceScanlineLength;
 32.1144 +				screenMemory += targetScanlineLength;
 32.1145 +				}
 32.1146 +//#endif
 32.1147 +			}
 32.1148 +		} // switch
 32.1149 +	} // for
 32.1150 +}
 32.1151 +*/
 32.1152 +
 32.1153 +void DirectDrawRotated(_THIS, int numrects, SDL_Rect *rects, TUint16* screenBuffer)
 32.1154 +{
 32.1155 +	TInt i;
 32.1156 +//    TInt sourceNumBytesPerPixel = ((_this->screen->format->BitsPerPixel-1)>>3) + 1;   
 32.1157 +    TPoint fixedScreenOffset = Private->EPOC_ScreenOffset;   
 32.1158 +    TInt bufferW = _this->screen->w;
 32.1159 +    TInt bufferH = _this->screen->h;
 32.1160 +    TInt ScreenW = Private->EPOC_ScreenSize.iWidth;
 32.1161 +//    TInt ScreenH = Private->EPOC_ScreenSize.iWidth;
 32.1162 +    TInt sourceW = bufferW;
 32.1163 +    TInt sourceH = bufferH;
 32.1164 +    TInt targetW = ScreenW - fixedScreenOffset.iX * 2;
 32.1165 +//    TInt targetH = ScreenH - fixedScreenOffset.iY * 2;
 32.1166 +	TInt sourceScanlineLength = bufferW;
 32.1167 +    TInt targetScanlineLength = Private->EPOC_ScreenSize.iWidth;
 32.1168 +
 32.1169 +	/* Render the rectangles in the list */
 32.1170 +
 32.1171 +	for ( i=0; i < numrects; ++i ) {
 32.1172 +        SDL_Rect rect2;
 32.1173 +        const SDL_Rect& currentRect = rects[i];
 32.1174 +        rect2.x = currentRect.x;
 32.1175 +        rect2.y = currentRect.y;
 32.1176 +        rect2.w = currentRect.w;
 32.1177 +        rect2.h = currentRect.h;
 32.1178 +
 32.1179 +        if (rect2.w <= 0 || rect2.h <= 0) /* sanity check */
 32.1180 +            continue;
 32.1181 +
 32.1182 +        /* All variables are measured in pixels */
 32.1183 +
 32.1184 +        /* Check rects validity, i.e. upper and lower bounds */
 32.1185 +        TInt maxX = Min(sourceW - 1, rect2.x + rect2.w - 1);
 32.1186 +        TInt maxY = Min(sourceH - 1, rect2.y + rect2.h - 1);
 32.1187 +        if (maxX < 0 || maxY < 0) /* sanity check */
 32.1188 +            continue;
 32.1189 +		/* Clip from bottom */
 32.1190 +        //maxX = Min(maxX, Private->EPOC_ScreenSize.iHeight-1); 
 32.1191 +		/* TODO: Clip from the right side */
 32.1192 +
 32.1193 +        TInt sourceRectWidth = maxX - rect2.x + 1;
 32.1194 +//        TInt sourceRectWidthInBytes = sourceRectWidth * sourceNumBytesPerPixel;
 32.1195 +        TInt sourceRectHeight = maxY - rect2.y + 1;
 32.1196 +        TInt sourceStartOffset = rect2.x + rect2.y * sourceScanlineLength;
 32.1197 +        TInt targetStartOffset = fixedScreenOffset.iX + (targetW-1 - rect2.y) + (fixedScreenOffset.iY +rect2.x) * targetScanlineLength;   
 32.1198 +        
 32.1199 +        // Nokia7650 native mode: 12 bpp --> 12 bpp
 32.1200 +        if (_this->screen->format->BitsPerPixel == 12) { 
 32.1201 +            
 32.1202 +            /* !!TODO: not yet implemented
 32.1203 +
 32.1204 +	        TUint16* bitmapLine = (TUint16*)_this->screen->pixels + sourceStartOffset;
 32.1205 +            TUint16* screenMemory = screenBuffer + targetStartOffset;
 32.1206 +            for(TInt y = 0 ; y < sourceRectHeight ; y++) {
 32.1207 +				//TODO: optimize: separate loops for 1, 2 and n skip
 32.1208 +		        //Mem::Copy(screenMemory, bitmapLine, sourceRectWidthInBytes);
 32.1209 +                TUint16* bitmapPos = bitmapLine; // 2 bytes per pixel 
 32.1210 +                TUint16* screenMemoryLinePos = screenMemory; // 2 bytes per pixel 
 32.1211 +				for(TInt x = 0 ; x < sourceRectWidth ; x++) {
 32.1212 +
 32.1213 +					__ASSERT_DEBUG(screenMemory < (screenBuffer + Private->EPOC_ScreenSize.iWidth * Private->EPOC_ScreenSize.iHeight), User::Panic(KLibName, KErrCorrupt));
 32.1214 +					__ASSERT_DEBUG(screenMemory >= screenBuffer, User::Panic(KLibName, KErrCorrupt));
 32.1215 +					__ASSERT_DEBUG(bitmapLine < ((TUint16*)_this->screen->pixels + (_this->screen->w * _this->screen->h)), User::Panic(KLibName, KErrCorrupt));
 32.1216 +					__ASSERT_DEBUG(bitmapLine >=  (TUint16*)_this->screen->pixels, User::Panic(KLibName, KErrCorrupt));
 32.1217 +                    
 32.1218 +                      *screenMemoryLinePos = *bitmapPos;
 32.1219 +                    bitmapPos++;
 32.1220 +                    screenMemoryLinePos += targetScanlineLength;
 32.1221 +                }
 32.1222 +		        bitmapLine += sourceScanlineLength;
 32.1223 +		        screenMemory--;
 32.1224 +            }
 32.1225 +
 32.1226 +            */
 32.1227 +        }
 32.1228 +        // 256 color paletted mode: 8 bpp  --> 12 bpp
 32.1229 +        else { 
 32.1230 +	        TUint8* bitmapLine = (TUint8*)_this->screen->pixels + sourceStartOffset;
 32.1231 +            TUint16* screenMemory = screenBuffer + targetStartOffset;
 32.1232 +			TInt screenXScaleValue = Private->EPOC_ScreenXScaleValue;
 32.1233 +			TInt debug_ycount=0;
 32.1234 +            for(TInt y = 0 ; y < sourceRectHeight ; y++) {
 32.1235 +				if(--screenXScaleValue) {
 32.1236 +					TUint8* bitmapPos = bitmapLine; /* 1 byte per pixel */
 32.1237 +					TUint16* screenMemoryLinePos = screenMemory; /* 2 bytes per pixel */
 32.1238 +					TInt screenYScaleValue = Private->EPOC_ScreenYScaleValue;
 32.1239 +					TInt debug_xcount=0;
 32.1240 +					/* Convert each pixel from 256 palette to 4k color values */
 32.1241 +					for(TInt x = 0 ; x < sourceRectWidth ; x++) {
 32.1242 +						if(--screenYScaleValue) {
 32.1243 +							
 32.1244 +                            __ASSERT_DEBUG(screenMemoryLinePos < (screenBuffer + (Private->EPOC_ScreenSize.iWidth * Private->EPOC_ScreenSize.iHeight)), User::Panic(KLibName, KErrCorrupt));
 32.1245 +							__ASSERT_DEBUG(screenMemoryLinePos >= screenBuffer, User::Panic(KLibName, KErrCorrupt));
 32.1246 +							__ASSERT_DEBUG(bitmapPos < ((TUint8*)_this->screen->pixels + (_this->screen->w * _this->screen->h)), User::Panic(KLibName, KErrCorrupt));
 32.1247 +							__ASSERT_DEBUG(bitmapPos >= (TUint8*)_this->screen->pixels, User::Panic(KLibName, KErrCorrupt));
 32.1248 +							
 32.1249 +                            *screenMemoryLinePos = TUint16(EPOC_HWPalette_256_to_Screen[*bitmapPos]);
 32.1250 +							screenMemoryLinePos += targetScanlineLength; debug_xcount++;
 32.1251 +						}
 32.1252 +						else
 32.1253 +							screenYScaleValue = Private->EPOC_ScreenYScaleValue;
 32.1254 +						bitmapPos++; 
 32.1255 +					}
 32.1256 +					screenMemory--; debug_ycount++;
 32.1257 +				} // endif
 32.1258 +				else
 32.1259 +					screenXScaleValue = Private->EPOC_ScreenXScaleValue;
 32.1260 +				bitmapLine += sourceScanlineLength;
 32.1261 +             }
 32.1262 +	    }
 32.1263 +    }    
 32.1264 +}
 32.1265 +
 32.1266 +
 32.1267 +/* Note:  If we are terminated, this could be called in the middle of
 32.1268 +   another SDL video routine -- notably UpdateRects.
 32.1269 +*/
 32.1270 +void EPOC_VideoQuit(_THIS)
 32.1271 +{
 32.1272 +	int i;
 32.1273 +
 32.1274 +	/* Free video mode lists */
 32.1275 +	for ( i=0; i<SDL_NUMMODES; ++i ) {
 32.1276 +		if ( Private->SDL_modelist[i] != NULL ) {
 32.1277 +			free(Private->SDL_modelist[i]);
 32.1278 +			Private->SDL_modelist[i] = NULL;
 32.1279 +		}
 32.1280 +	}
 32.1281 +	
 32.1282 +    if ( _this->screen && (_this->screen->flags & SDL_HWSURFACE) ) {
 32.1283 +		/* Direct screen access, no memory buffer */
 32.1284 +		_this->screen->pixels = NULL;
 32.1285 +	}
 32.1286 +
 32.1287 +    if (_this->screen && _this->screen->pixels) {
 32.1288 +        free(_this->screen->pixels);
 32.1289 +        _this->screen->pixels = NULL;
 32.1290 +    }
 32.1291 +
 32.1292 +    /* Free Epoc resources */
 32.1293 +
 32.1294 +    /* Disable events for me */
 32.1295 +	if (Private->EPOC_WsEventStatus != KRequestPending)
 32.1296 +		Private->EPOC_WsSession.EventReadyCancel();
 32.1297 +	if (Private->EPOC_RedrawEventStatus != KRequestPending)
 32.1298 +		Private->EPOC_WsSession.RedrawReadyCancel();
 32.1299 +
 32.1300 +	#if defined(__WINS__) || defined(TEST_BM_DRAW)
 32.1301 +	delete Private->EPOC_Bitmap;
 32.1302 +	Private->EPOC_Bitmap = NULL;
 32.1303 +	#else
 32.1304 +    #endif
 32.1305 +
 32.1306 +#ifndef SYMBIAN_CRYSTAL
 32.1307 +	free(Private->EPOC_DrawDevice);
 32.1308 +#endif
 32.1309 +
 32.1310 +	if (Private->EPOC_WsWindow.WsHandle())
 32.1311 +		Private->EPOC_WsWindow.Close();
 32.1312 +
 32.1313 +	if (Private->EPOC_WsWindowGroup.WsHandle())
 32.1314 +		Private->EPOC_WsWindowGroup.Close();
 32.1315 +
 32.1316 +	delete Private->EPOC_WindowGc;
 32.1317 +	Private->EPOC_WindowGc = NULL;
 32.1318 +
 32.1319 +	delete Private->EPOC_WsScreen;
 32.1320 +	Private->EPOC_WsScreen = NULL;
 32.1321 +
 32.1322 +	if (Private->EPOC_WsSession.WsHandle())
 32.1323 +		Private->EPOC_WsSession.Close();
 32.1324 +}
 32.1325 +
 32.1326 +
 32.1327 +WMcursor *EPOC_CreateWMCursor(_THIS, Uint8* /*data*/, Uint8* /*mask*/, int /*w*/, int /*h*/, int /*hot_x*/, int /*hot_y*/)
 32.1328 +{
 32.1329 +	return (WMcursor *) 9210; // it's ok to return something unuseful but true
 32.1330 +}
 32.1331 +
 32.1332 +void EPOC_FreeWMCursor(_THIS, WMcursor* /*cursor*/)
 32.1333 +{
 32.1334 +    /* Disable virtual cursor */
 32.1335 +    HAL::Set(HAL::EMouseState, HAL::EMouseState_Invisible);
 32.1336 +    Private->EPOC_WsSession.SetPointerCursorMode(EPointerCursorNone);
 32.1337 +}
 32.1338 +
 32.1339 +int EPOC_ShowWMCursor(_THIS, WMcursor *cursor)
 32.1340 +{
 32.1341 +
 32.1342 +    if (cursor ==  (WMcursor *)9210) {
 32.1343 +        /* Enable virtual cursor */
 32.1344 +	    Private->EPOC_WsSession.SetPointerCursorMode(EPointerCursorNormal);
 32.1345 +        if (isCursorVisible)
 32.1346 +	        HAL::Set(HAL::EMouseState, HAL::EMouseState_Visible);
 32.1347 +        else
 32.1348 +            Private->EPOC_WsSession.SetPointerCursorMode(EPointerCursorNone);
 32.1349 +    }
 32.1350 +    else {
 32.1351 +        /* Disable virtual cursor */
 32.1352 +        HAL::Set(HAL::EMouseState, HAL::EMouseState_Invisible);
 32.1353 +        Private->EPOC_WsSession.SetPointerCursorMode(EPointerCursorNone);
 32.1354 +    }
 32.1355 +
 32.1356 +	return(1);
 32.1357 +}
 32.1358 +
 32.1359 +}; // extern "C"
    33.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    33.2 +++ b/src/video/symbian/EKA1/SDL_epocvideo.h	Sun Jun 24 18:26:35 2007 +0000
    33.3 @@ -0,0 +1,34 @@
    33.4 +/*
    33.5 +    SDL - Simple DirectMedia Layer
    33.6 +    Copyright (C) 1997, 1998, 1999, 2000, 2001  Sam Lantinga
    33.7 +
    33.8 +    This library is free software; you can redistribute it and/or
    33.9 +    modify it under the terms of the GNU Library General Public
   33.10 +    License as published by the Free Software Foundation; either
   33.11 +    version 2 of the License, or (at your option) any later version.
   33.12 +
   33.13 +    This library is distributed in the hope that it will be useful,
   33.14 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
   33.15 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   33.16 +    Library General Public License for more details.
   33.17 +
   33.18 +    You should have received a copy of the GNU Library General Public
   33.19 +    License along with this library; if not, write to the Free
   33.20 +    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   33.21 +
   33.22 +    Sam Lantinga
   33.23 +    slouken@devolution.com
   33.24 +*/
   33.25 +
   33.26 +#ifndef _SDL_epocvideo_h
   33.27 +#define _SDL_epocvideo_h
   33.28 +
   33.29 +#ifndef EKA2
   33.30 +#include"SDL_epocvideo_org.h"
   33.31 +#else
   33.32 +#include"SDL_epocvideo2.h"
   33.33 +#endif
   33.34 +
   33.35 +
   33.36 +#endif
   33.37 +
    34.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    34.2 +++ b/src/video/symbian/EKA2/SDL_epocevents.cpp	Sun Jun 24 18:26:35 2007 +0000
    34.3 @@ -0,0 +1,521 @@
    34.4 +#include "epoc_sdl.h"
    34.5 +
    34.6 +#include <stdio.h>
    34.7 +#undef NULL
    34.8 +extern "C" {
    34.9 +//#define DEBUG_TRACE_ENABLED
   34.10 +#include "SDL_error.h"
   34.11 +#include "SDL_video.h"
   34.12 +#include "SDL_keysym.h"
   34.13 +#include "SDL_keyboard.h"
   34.14 +#include "SDL_events_c.h"
   34.15 +#include "SDL_timer.h"
   34.16 +} /* extern "C" */
   34.17 +
   34.18 +#include "SDL_epocvideo.h"
   34.19 +#include "SDL_epocevents_c.h"
   34.20 +
   34.21 +#include "sdlepocapi.h"
   34.22 +
   34.23 +#include <eikenv.h>
   34.24 +
   34.25 +#include<bautils.h>
   34.26 +
   34.27 +
   34.28 +extern "C"
   34.29 +	{
   34.30 +	static SDL_keysym *TranslateKey(_THIS, int scancode, SDL_keysym *keysym);
   34.31 +	}
   34.32 +
   34.33 +//extern "C" {
   34.34 +/* The translation tables from a console scancode to a SDL keysym */
   34.35 +static SDLKey keymap[MAX_SCANCODE];
   34.36 +static SDL_keysym *TranslateKey(_THIS, int scancode, SDL_keysym *keysym);
   34.37 +void DisableKeyBlocking(_THIS);
   34.38 +//} /* extern "C" */
   34.39 +
   34.40 +SDLKey* KeyMap()
   34.41 +	{
   34.42 +	return keymap;
   34.43 +	}
   34.44 +	
   34.45 +TBool isCursorVisible = EFalse;
   34.46 +
   34.47 +void ResetKeyMap()
   34.48 +	{
   34.49 +	int i;
   34.50 +
   34.51 +	/* Initialize the key translation table */
   34.52 +	for ( i=0; i<SDL_TABLESIZE(keymap); ++i )
   34.53 +		keymap[i] = SDLK_UNKNOWN;
   34.54 +
   34.55 +
   34.56 +	/* Numbers */
   34.57 +	for ( i = 0; i<32; ++i ){
   34.58 +		keymap[' ' + i] = (SDLKey)(SDLK_SPACE+i);
   34.59 +	}
   34.60 +	/* e.g. Alphabet keys */
   34.61 +	for ( i = 0; i<32; ++i ){
   34.62 +		keymap['A' + i] = (SDLKey)(SDLK_a+i);
   34.63 +	}
   34.64 +
   34.65 +	keymap[EStdKeyBackspace]    = SDLK_BACKSPACE;
   34.66 +	keymap[EStdKeyTab]          = SDLK_TAB;
   34.67 +	keymap[EStdKeyEnter]        = SDLK_RETURN;
   34.68 +	keymap[EStdKeyEscape]       = SDLK_ESCAPE;
   34.69 +   	keymap[EStdKeySpace]        = SDLK_SPACE;
   34.70 +   	keymap[EStdKeyPause]        = SDLK_PAUSE;
   34.71 +   	keymap[EStdKeyHome]         = SDLK_HOME;
   34.72 +   	keymap[EStdKeyEnd]          = SDLK_END;
   34.73 +   	keymap[EStdKeyPageUp]       = SDLK_PAGEUP;
   34.74 +   	keymap[EStdKeyPageDown]     = SDLK_PAGEDOWN;
   34.75 +	keymap[EStdKeyDelete]       = SDLK_DELETE;
   34.76 +	keymap[EStdKeyUpArrow]      = SDLK_UP;
   34.77 +	keymap[EStdKeyDownArrow]    = SDLK_DOWN;
   34.78 +	keymap[EStdKeyLeftArrow]    = SDLK_LEFT;
   34.79 +	keymap[EStdKeyRightArrow]   = SDLK_RIGHT;
   34.80 +	keymap[EStdKeyCapsLock]     = SDLK_CAPSLOCK;
   34.81 +	keymap[EStdKeyLeftShift]    = SDLK_LSHIFT;
   34.82 +	keymap[EStdKeyRightShift]   = SDLK_RSHIFT;
   34.83 +	keymap[EStdKeyLeftAlt]      = SDLK_LALT;
   34.84 +	keymap[EStdKeyRightAlt]     = SDLK_RALT;
   34.85 +	keymap[EStdKeyLeftCtrl]     = SDLK_LCTRL;
   34.86 +	keymap[EStdKeyRightCtrl]    = SDLK_RCTRL;
   34.87 +	keymap[EStdKeyLeftFunc]     = SDLK_LMETA;
   34.88 +	keymap[EStdKeyRightFunc]    = SDLK_RMETA;
   34.89 +	keymap[EStdKeyInsert]       = SDLK_INSERT;
   34.90 +	keymap[EStdKeyComma]        = SDLK_COMMA;
   34.91 +	keymap[EStdKeyFullStop]     = SDLK_PERIOD;
   34.92 +	keymap[EStdKeyForwardSlash] = SDLK_SLASH;
   34.93 +	keymap[EStdKeyBackSlash]    = SDLK_BACKSLASH;
   34.94 +	keymap[EStdKeySemiColon]    = SDLK_SEMICOLON;
   34.95 +	keymap[EStdKeySingleQuote]  = SDLK_QUOTE;
   34.96 +	keymap[EStdKeyHash]         = SDLK_HASH;
   34.97 +	keymap[EStdKeySquareBracketLeft]    = SDLK_LEFTBRACKET;
   34.98 +	keymap[EStdKeySquareBracketRight]   = SDLK_RIGHTBRACKET;
   34.99 +	keymap[EStdKeyMinus]        = SDLK_MINUS;
  34.100 +	keymap[EStdKeyEquals]       = SDLK_EQUALS;
  34.101 +
  34.102 +   	keymap[EStdKeyF1]          = SDLK_F1;  
  34.103 +   	keymap[EStdKeyF2]          = SDLK_F2;  
  34.104 +   	keymap[EStdKeyF3]          = SDLK_F3;  
  34.105 +   	keymap[EStdKeyF4]          = SDLK_F4; 
  34.106 +   	keymap[EStdKeyF5]          = SDLK_F5;  
  34.107 +   	keymap[EStdKeyF6]          = SDLK_F6;  
  34.108 +   	keymap[EStdKeyF7]          = SDLK_F7;  
  34.109 +   	keymap[EStdKeyF8]          = SDLK_F8;  
  34.110 +
  34.111 +   	keymap[EStdKeyF9]          = SDLK_F9;  
  34.112 +   	keymap[EStdKeyF10]         = SDLK_F10; 
  34.113 +   	keymap[EStdKeyF11]         = SDLK_F11; 
  34.114 +   	keymap[EStdKeyF12]         = SDLK_F12; 
  34.115 +
  34.116 +
  34.117 +   	keymap[EStdKeyXXX]         = SDLK_RETURN;	/* "fire" key */
  34.118 +
  34.119 +   	keymap[EStdKeyDevice3]     = SDLK_RETURN;	/* "fire" key */
  34.120 +   	keymap[EStdKeyNkpAsterisk] = SDLK_ASTERISK; 
  34.121 +   	keymap[EStdKeyYes]         = SDLK_HOME;		/* "call" key */
  34.122 +   	keymap[EStdKeyNo]		   = SDLK_END;		/* "end call" key */
  34.123 +   	keymap[EStdKeyDevice0]     = SDLK_SPACE;	/* right menu key */
  34.124 +   	keymap[EStdKeyDevice1]     = SDLK_ESCAPE;	/* left menu key */
  34.125 +   	keymap[EStdKeyDevice2]     = SDLK_POWER;	/* power key */
  34.126 +
  34.127 +    keymap[EStdKeyMenu]        = SDLK_MENU;   	// menu key
  34.128 +    keymap[EStdKeyDevice6]     = SDLK_LEFT;     // Rocker (joystick) left
  34.129 +    keymap[EStdKeyDevice7]     = SDLK_RIGHT;    // Rocker (joystick) right
  34.130 +    keymap[EStdKeyDevice8]     = SDLK_UP;       // Rocker (joystick) up
  34.131 +    keymap[EStdKeyDevice9]     = SDLK_DOWN;     // Rocker (joystick) down
  34.132 +    keymap[EStdKeyLeftFunc]     = SDLK_LALT;    //chr?
  34.133 +	keymap[EStdKeyRightFunc]    = SDLK_RALT;
  34.134 +    keymap[EStdKeyDeviceA]      = SDLK_RETURN;	/* "fire" key */
  34.135 +    
  34.136 +    
  34.137 +    
  34.138 +
  34.139 +
  34.140 +    ///////////////////////////////////////////////////////////
  34.141 +    /*
  34.142 +    RFs fs;
  34.143 +    if(KErrNone == fs.Connect())
  34.144 +        {
  34.145 +        RArray<TInt> array;
  34.146 +        TRAPD(err, ReadL(fs, array));
  34.147 +        if(err == KErrNone && array.Count() > 0)
  34.148 +            {
  34.149 +            
  34.150 +            SDLKey temp[MAX_SCANCODE];
  34.151 +            Mem::Copy(temp, keymap, MAX_SCANCODE * sizeof(SDLKey));
  34.152 +
  34.153 +            for(TInt k = 0; k < array.Count(); k+= 2)
  34.154 +                {
  34.155 +                const TInt oldval = array[k]; 
  34.156 +                const TInt newval = array[k + 1]; 
  34.157 +                if(oldval >=  0 && oldval < MAX_SCANCODE && newval >=  0 && newval < MAX_SCANCODE)
  34.158 +                    {
  34.159 +                    keymap[oldval] = temp[newval];
  34.160 +                    }
  34.161 +                }
  34.162 +            }
  34.163 +        array.Close();
  34.164 +        }
  34.165 +
  34.166 +    fs.Close();*/
  34.167 +    ///////////////////////////////////////////////////////////
  34.168 +
  34.169 +    
  34.170 +	keymap[EStdKeyNumLock] = SDLK_NUMLOCK;
  34.171 +	keymap[EStdKeyScrollLock] = SDLK_SCROLLOCK;
  34.172 +	
  34.173 +	keymap[EStdKeyNkpForwardSlash] = SDLK_KP_DIVIDE;
  34.174 +	keymap[EStdKeyNkpAsterisk] = SDLK_KP_MULTIPLY;
  34.175 +	keymap[EStdKeyNkpMinus] = SDLK_KP_MINUS;
  34.176 +	keymap[EStdKeyNkpPlus] = SDLK_KP_PLUS;
  34.177 +	keymap[EStdKeyNkpEnter] = SDLK_KP_ENTER;
  34.178 +	keymap[EStdKeyNkp1] = SDLK_KP1;
  34.179 +	keymap[EStdKeyNkp2] = SDLK_KP2;
  34.180 +	keymap[EStdKeyNkp3] = SDLK_KP3;
  34.181 +	keymap[EStdKeyNkp4] = SDLK_KP4;
  34.182 +	keymap[EStdKeyNkp5] = SDLK_KP5;
  34.183 +	keymap[EStdKeyNkp6] = SDLK_KP6;
  34.184 +	keymap[EStdKeyNkp7] = SDLK_KP7;
  34.185 +	keymap[EStdKeyNkp8] = SDLK_KP8;
  34.186 +	keymap[EStdKeyNkp9] = SDLK_KP9;
  34.187 +	keymap[EStdKeyNkp0] = SDLK_KP0;
  34.188 +	keymap[EStdKeyNkpFullStop] = SDLK_KP_PERIOD;
  34.189 +    /*
  34.190 +    keymap[EStdKeyMenu] = SDLK_MENU; should be, but not yet
  34.191 +    keymap[EStdKeyBacklightOn] =
  34.192 +    keymap[EStdKeyBacklightOff] =
  34.193 +    keymap[EStdKeyBacklightToggle] =
  34.194 +    keymap[EStdKeyIncContrast] =
  34.195 +    keymap[EStdKeyDecContrast] =
  34.196 +    keymap[EStdKeySliderDown] =
  34.197 +    keymap[EStdKeySliderUp] =
  34.198 +    keymap[EStdKeyDictaphonePlay] =
  34.199 +    keymap[EStdKeyDictaphoneStop] =
  34.200 +    keymap[EStdKeyDictaphoneRecord] =
  34.201 +    keymap[EStdKeyHelp] =
  34.202 +    keymap[EStdKeyOff] =
  34.203 +    keymap[EStdKeyDial] =
  34.204 +    keymap[EStdKeyIncVolume] =
  34.205 +    keymap[EStdKeyDecVolume] =
  34.206 +    keymap[EStdKeyDevice0] =
  34.207 +    keymap[EStdKeyDevice1] =
  34.208 +    keymap[EStdKeyDevice2] =
  34.209 +    keymap[EStdKeyDevice3] =
  34.210 +    keymap[EStdKeyDevice4] =
  34.211 +    keymap[EStdKeyDevice5] =
  34.212 +    keymap[EStdKeyDevice6] =
  34.213 +    keymap[EStdKeyDevice7] =
  34.214 +    keymap[EStdKeyDevice8] =
  34.215 +    keymap[EStdKeyDevice9] =
  34.216 +    keymap[EStdKeyDeviceA] =
  34.217 +    keymap[EStdKeyDeviceB] =
  34.218 +    keymap[EStdKeyDeviceC] =
  34.219 +    keymap[EStdKeyDeviceD] =
  34.220 +    keymap[EStdKeyDeviceE] =
  34.221 +    keymap[EStdKeyDeviceF] =
  34.222 +    keymap[EStdKeyApplication0] =
  34.223 +    keymap[EStdKeyApplication1] =
  34.224 +    keymap[EStdKeyApplication2] =
  34.225 +    keymap[EStdKeyApplication3] =
  34.226 +    keymap[EStdKeyApplication4] =
  34.227 +    keymap[EStdKeyApplication5] =
  34.228 +    keymap[EStdKeyApplication6] =
  34.229 +    keymap[EStdKeyApplication7] =
  34.230 +    keymap[EStdKeyApplication8] =
  34.231 +    keymap[EStdKeyApplication9] =
  34.232 +    keymap[EStdKeyApplicationA] =
  34.233 +    keymap[EStdKeyApplicationB] =
  34.234 +    keymap[EStdKeyApplicationC] =
  34.235 +    keymap[EStdKeyApplicationD] =
  34.236 +    keymap[EStdKeyApplicationE] =
  34.237 +    keymap[EStdKeyApplicationF] =
  34.238 +    keymap[EStdKeyYes] =
  34.239 +    keymap[EStdKeyNo] =
  34.240 +    keymap[EStdKeyIncBrightness] =
  34.241 +    keymap[EStdKeyDecBrightness] = 
  34.242 +    keymap[EStdKeyCaseOpen] =
  34.243 +    keymap[EStdKeyCaseClose] =  */
  34.244 +    
  34.245 +
  34.246 +
  34.247 +}
  34.248 +
  34.249 +
  34.250 +int EPOC_HandleWsEvent(_THIS, const TWsEvent& aWsEvent)
  34.251 +{
  34.252 +    int posted = 0;
  34.253 +    SDL_keysym keysym;
  34.254 +    
  34.255 +//    SDL_TRACE1("hws %d", aWsEvent.Type());
  34.256 +
  34.257 +    switch (aWsEvent.Type())
  34.258 +		{    
  34.259 +    case EEventPointer: /* Mouse pointer events */
  34.260 +		{
  34.261 +/*        const TPointerCursorMode mode = EpocSdlEnv::PointerMode();
  34.262 +        
  34.263 +
  34.264 +        if(mode == EPointerCursorNone) 
  34.265 +            {
  34.266 +            return 0; //TODO: Find out why events are get despite of cursor should be off
  34.267 +            }
  34.268 +*/
  34.269 +        const TPointerEvent* pointerEvent = aWsEvent.Pointer();
  34.270 +        const TPoint mousePos = EpocSdlEnv::WindowCoordinates(pointerEvent->iPosition);
  34.271 +
  34.272 +        /*!! TODO Pointer do not yet work properly
  34.273 +        //SDL_TRACE1("SDL: EPOC_HandleWsEvent, pointerEvent->iType=%d", pointerEvent->iType); //!!
  34.274 +
  34.275 +        if (Private->EPOC_ShrinkedHeight) {
  34.276 +            mousePos.iY <<= 1; // Scale y coordinate to shrinked screen height
  34.277 +        }
  34.278 +        if (Private->EPOC_ShrinkedWidth) {
  34.279 +            mousePos.iX <<= 1; // Scale x coordinate to shrinked screen width
  34.280 +        }
  34.281 +        */
  34.282 +
  34.283 +		posted += SDL_PrivateMouseMotion(0, 0, mousePos.iX, mousePos.iY); /* Absolute position on screen */
  34.284 +
  34.285 +		switch (pointerEvent->iType)
  34.286 +			{
  34.287 +        case TPointerEvent::EButton1Down:
  34.288 +            posted += SDL_PrivateMouseButton(SDL_PRESSED, SDL_BUTTON_LEFT, 0, 0);
  34.289 +			break;
  34.290 +        case TPointerEvent::EButton1Up:
  34.291 +			posted += SDL_PrivateMouseButton(SDL_RELEASED, SDL_BUTTON_LEFT, 0, 0);
  34.292 +			break;
  34.293 +        case TPointerEvent::EButton2Down:
  34.294 +            posted += SDL_PrivateMouseButton(SDL_PRESSED, SDL_BUTTON_RIGHT, 0, 0);
  34.295 +			break;
  34.296 +		case TPointerEvent::EButton2Up:
  34.297 +			posted += SDL_PrivateMouseButton(SDL_RELEASED, SDL_BUTTON_RIGHT, 0, 0);
  34.298 +			break;
  34.299 +        case TPointerEvent::EButton3Down:
  34.300 +            posted += SDL_PrivateMouseButton(SDL_PRESSED, SDL_BUTTON_MIDDLE, 0, 0);
  34.301 +			break;
  34.302 +        case TPointerEvent::EButton3Up:
  34.303 +			posted += SDL_PrivateMouseButton(SDL_RELEASED, SDL_BUTTON_MIDDLE, 0, 0);
  34.304 +			break;
  34.305 +			} // switch
  34.306 +        break;
  34.307 +	    }
  34.308 +    
  34.309 +    case EEventKeyDown: /* Key events */
  34.310 +    {
  34.311 +#ifdef SYMBIAN_CRYSTAL
  34.312 +		// special case: 9300/9500 rocker down, simulate left mouse button
  34.313 +		if (aWsEvent.Key()->iScanCode == EStdKeyDeviceA)
  34.314 +			{
  34.315 +            const TPointerCursorMode mode =  Private->EPOC_WsSession.PointerCursorMode();
  34.316 +            if(mode != EPointerCursorNone) 
  34.317 +                posted += SDL_PrivateMouseButton(SDL_PRESSED, SDL_BUTTON_LEFT, 0, 0);
  34.318 +			}
  34.319 +#endif
  34.320 +       (void*)TranslateKey(_this, aWsEvent.Key()->iScanCode, &keysym);
  34.321 +            
  34.322 +#ifndef DISABLE_JOYSTICK
  34.323 +        /* Special handling */
  34.324 +        switch((int)keysym.sym) {
  34.325 +        case SDLK_CAPSLOCK:
  34.326 +            if (!isCursorVisible) {
  34.327 +                /* Enable virtual cursor */
  34.328 +	            HAL::Set(HAL::EMouseState, HAL::EMouseState_Visible);
  34.329 +            }
  34.330 +            else {
  34.331 +                /* Disable virtual cursor */
  34.332 +                HAL::Set(HAL::EMouseState, HAL::EMouseState_Invisible);
  34.333 +            }
  34.334 +            isCursorVisible = !isCursorVisible;
  34.335 +            break;
  34.336 +        }
  34.337 +#endif        
  34.338 +	    posted += SDL_PrivateKeyboard(SDL_PRESSED, &keysym);
  34.339 +        break;
  34.340 +	} 
  34.341 +
  34.342 +    case EEventKeyUp: /* Key events */
  34.343 +		{
  34.344 +#ifdef SYMBIAN_CRYSTAL
  34.345 +		// special case: 9300/9500 rocker up, simulate left mouse button
  34.346 +		if (aWsEvent.Key()->iScanCode == EStdKeyDeviceA)
  34.347 +			{
  34.348 +            posted += SDL_PrivateMouseButton(SDL_RELEASED, SDL_BUTTON_LEFT, 0, 0);
  34.349 +			}
  34.350 +#endif
  34.351 +	    posted += SDL_PrivateKeyboard(SDL_RELEASED, TranslateKey(_this, aWsEvent.Key()->iScanCode, &keysym));
  34.352 +        break;
  34.353 +		}
  34.354 +    
  34.355 +    case EEventFocusGained: /* SDL window got focus */
  34.356 +	    {
  34.357 +        Private->iIsWindowFocused = ETrue;
  34.358 +		posted += SDL_PrivateAppActive(1, SDL_APPINPUTFOCUS|SDL_APPMOUSEFOCUS);
  34.359 +        /* Draw window background and screen buffer */
  34.360 +        DisableKeyBlocking(_this);  //Markus: guess why:-)
  34.361 + 
  34.362 +        //RedrawWindowL(_this);  
  34.363 +        break;
  34.364 +	    }
  34.365 +
  34.366 +    case EEventFocusLost: /* SDL window lost focus */
  34.367 +		{
  34.368 +
  34.369 +		Private->iIsWindowFocused = EFalse;
  34.370 +
  34.371 +		posted += SDL_PrivateAppActive(0, SDL_APPINPUTFOCUS|SDL_APPMOUSEFOCUS);
  34.372 +
  34.373 +       
  34.374 +        break;
  34.375 +	    }
  34.376 +
  34.377 +    case EEventModifiersChanged: 
  34.378 +    {
  34.379 +	    TModifiersChangedEvent* modEvent = aWsEvent.ModifiersChanged();
  34.380 +        TUint modstate = KMOD_NONE;
  34.381 +        if (modEvent->iModifiers == EModifierLeftShift)
  34.382 +            modstate |= KMOD_LSHIFT;
  34.383 +        if (modEvent->iModifiers == EModifierRightShift)
  34.384 +            modstate |= KMOD_RSHIFT;
  34.385 +        if (modEvent->iModifiers == EModifierLeftCtrl)
  34.386 +            modstate |= KMOD_LCTRL;
  34.387 +        if (modEvent->iModifiers == EModifierRightCtrl)
  34.388 +            modstate |= KMOD_RCTRL;
  34.389 +        if (modEvent->iModifiers == EModifierLeftAlt)
  34.390 +            modstate |= KMOD_LALT;
  34.391 +        if (modEvent->iModifiers == EModifierRightAlt)
  34.392 +            modstate |= KMOD_RALT;
  34.393 +        if (modEvent->iModifiers == EModifierLeftFunc)
  34.394 +            modstate |= KMOD_LMETA;
  34.395 +        if (modEvent->iModifiers == EModifierRightFunc)
  34.396 +            modstate |= KMOD_RMETA;
  34.397 +        if (modEvent->iModifiers == EModifierCapsLock)
  34.398 +            modstate |= KMOD_CAPS;
  34.399 +        SDL_SetModState(STATIC_CAST(SDLMod,(modstate | KMOD_LSHIFT)));
  34.400 +        break;
  34.401 +    }
  34.402 +	case EEventScreenDeviceChanged:
  34.403 +	        {
  34.404 +	        EpocSdlEnv::WaitDeviceChange();  
  34.405 +	        }
  34.406 +	    break;
  34.407 +    default:            
  34.408 +        break;
  34.409 +	} 
  34.410 +	
  34.411 +    return posted;
  34.412 +}
  34.413 +
  34.414 +extern "C" {
  34.415 +
  34.416 +void EPOC_PumpEvents(_THIS)
  34.417 +    {
  34.418 +    MEventQueue& events = EpocSdlEnv::EventQueue();
  34.419 +    while(events.HasData())
  34.420 +        {
  34.421 +        events.Lock();
  34.422 +       
  34.423 +       //there have to be a copy, so we can release
  34.424 +       //lock immediately. HandleWsEvent may cause
  34.425 +       //deadlock otherwise.
  34.426 +        
  34.427 +        const TWsEvent event = events.Shift();
  34.428 +		events.Unlock();
  34.429 +//        const TWsEvent& event = events.Top();
  34.430 +		EPOC_HandleWsEvent(_this, event);
  34.431 +//		events.Shift();
  34.432 +	    }
  34.433 +    }
  34.434 +
  34.435 +
  34.436 +
  34.437 +void EPOC_InitOSKeymap(_THIS)
  34.438 +	{
  34.439 +	ResetKeyMap();
  34.440 +	EpocSdlEnv::ObserverEvent(MSDLObserver::EEventKeyMapInit ,0);
  34.441 +	}
  34.442 +
  34.443 +static SDL_keysym *TranslateKey(_THIS, int scancode, SDL_keysym *keysym)
  34.444 +{
  34.445 +//    char debug[256];
  34.446 +    //SDL_TRACE1("SDL: TranslateKey, scancode=%d", scancode); //!!
  34.447 +
  34.448 +	/* Set the keysym information */ 
  34.449 +
  34.450 +	keysym->scancode = scancode;
  34.451 +
  34.452 +    if ((scancode >= MAX_SCANCODE) && 
  34.453 +        ((scancode - ENonCharacterKeyBase + 0x0081) >= MAX_SCANCODE)) {
  34.454 +        SDL_SetError("Too big scancode");
  34.455 +        keysym->scancode = SDLK_UNKNOWN;
  34.456 +	    keysym->mod = KMOD_NONE; 
  34.457 +        return keysym;
  34.458 +    }
  34.459 +
  34.460 +	keysym->mod = SDL_GetModState();
  34.461 +
  34.462 +    /* Handle function keys: F1, F2, F3 ... */
  34.463 +    if (keysym->mod & KMOD_META) {
  34.464 +        if (scancode >= 'A' && scancode < ('A' + 24)) { /* first 32 alphabet keys */
  34.465 +            switch(scancode) {
  34.466 +                case 'Q': scancode = EStdKeyF1; break;
  34.467 +                case 'W': scancode = EStdKeyF2; break;
  34.468 +                case 'E': scancode = EStdKeyF3; break;
  34.469 +                case 'R': scancode = EStdKeyF4; break;
  34.470 +                case 'T': scancode = EStdKeyF5; break;
  34.471 +                case 'Y': scancode = EStdKeyF6; break;
  34.472 +                case 'U': scancode = EStdKeyF7; break;
  34.473 +                case 'I': scancode = EStdKeyF8; break;
  34.474 +                case 'A': scancode = EStdKeyF9; break;
  34.475 +                case 'S': scancode = EStdKeyF10; break;
  34.476 +                case 'D': scancode = EStdKeyF11; break;
  34.477 +                case 'F': scancode = EStdKeyF12; break;
  34.478 +            }
  34.479 +            keysym->sym = keymap[scancode];
  34.480 +        }
  34.481 +    }
  34.482 +
  34.483 +    if (scancode >= ENonCharacterKeyBase) {
  34.484 +        // Non character keys
  34.485 +	    keysym->sym = keymap[scancode - 
  34.486 +            ENonCharacterKeyBase + 0x0081]; // !!hard coded
  34.487 +    } else {
  34.488 +	    keysym->sym = keymap[scancode];
  34.489 +    }
  34.490 +
  34.491 +	/* Remap the arrow keys if the device is rotated */
  34.492 +/*
  34.493 +	if (Private->EPOC_ScreenOrientation == CFbsBitGc::EGraphicsOrientationRotated270) {
  34.494 +		switch(keysym->sym) {
  34.495 +			case SDLK_UP:	keysym->sym = SDLK_LEFT;  break;
  34.496 +			case SDLK_DOWN: keysym->sym = SDLK_RIGHT; break;
  34.497 +			case SDLK_LEFT: keysym->sym = SDLK_DOWN;  break;
  34.498 +			case SDLK_RIGHT:keysym->sym = SDLK_UP;    break;
  34.499 +		}
  34.500 +	}
  34.501 +*/
  34.502 +	/* If UNICODE is on, get the UNICODE value for the key */
  34.503 +	keysym->unicode = 0;
  34.504 +
  34.505 +#if 0 // !!TODO:unicode
  34.506 +
  34.507 +	if ( SDL_TranslateUNICODE ) 
  34.508 +    {
  34.509 +		/* Populate the unicode field with the ASCII value */
  34.510 +		keysym->unicode = scancode;
  34.511 +	}
  34.512 +#endif
  34.513 +
  34.514 +    //!!
  34.515 +    //sprintf(debug, "SDL: TranslateKey: keysym->scancode=%d, keysym->sym=%d, keysym->mod=%d",
  34.516 +    //    keysym->scancode, keysym->sym, keysym->mod);
  34.517 +    //SDL_TRACE(debug); //!!
  34.518 +
  34.519 +	return(keysym);
  34.520 +}
  34.521 +
  34.522 +} /* extern "C" */
  34.523 +
  34.524 +
    35.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    35.2 +++ b/src/video/symbian/EKA2/SDL_epocvideo.cpp	Sun Jun 24 18:26:35 2007 +0000
    35.3 @@ -0,0 +1,594 @@
    35.4 +/*
    35.5 +    SDL - Simple DirectMedia Layer
    35.6 +    Copyright (C) 1997, 1998, 1999, 2000, 2001  Sam Lantinga
    35.7 +
    35.8 +    This library is free software; you can redistribute it and/or
    35.9 +    modify it under the terms of the GNU Library General Public
   35.10 +    License as published by the Free Software Foundation; either
   35.11 +    version 2 of the License, or (at your option) any later version.
   35.12 +
   35.13 +    This library is distributed in the hope that it will be useful,
   35.14 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
   35.15 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   35.16 +    Library General Public License for more details.
   35.17 +
   35.18 +    You should have received a copy of the GNU Library General Public
   35.19 +    License along with this library; if not, write to the Free
   35.20 +    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   35.21 +
   35.22 +    Sam Lantinga
   35.23 +    slouken@devolution.com
   35.24 +*/
   35.25 +
   35.26 +/*
   35.27 +    SDL_epocvideo.cpp
   35.28 +    Epoc based SDL video driver implementation
   35.29 +
   35.30 +    Markus Mertama
   35.31 +*/
   35.32 +
   35.33 +
   35.34 +
   35.35 +#include "epoc_sdl.h"
   35.36 +
   35.37 +#include <stdlib.h>
   35.38 +#include <stdio.h>
   35.39 +#include <string.h>
   35.40 +
   35.41 +extern "C" {
   35.42 +#include "SDL_error.h"
   35.43 +#include "SDL_timer.h"
   35.44 +#include "SDL_video.h"
   35.45 +#undef NULL
   35.46 +#include "SDL_pixels_c.h"
   35.47 +#include "SDL.h"
   35.48 +#include "SDL_mouse.h"
   35.49 +}
   35.50 +
   35.51 +#include "SDL_epocvideo.h"
   35.52 +#include "SDL_epocevents_c.h"
   35.53 +
   35.54 +
   35.55 +
   35.56 +#include <coedef.h>
   35.57 +#include <flogger.h>
   35.58 +
   35.59 +#include <eikenv.h>
   35.60 +#include <eikappui.h>
   35.61 +#include <eikapp.h>
   35.62 +#include "sdlepocapi.h"
   35.63 +
   35.64 +
   35.65 +////////////////////////////////////////////////////////////////
   35.66 +
   35.67 +
   35.68 +
   35.69 +
   35.70 +_LIT(KLibName, "SDL");
   35.71 +
   35.72 +void RDebug_Print_b(char* error_str, void* param)
   35.73 +    {
   35.74 +    TBuf8<128> error8((TUint8*)error_str);
   35.75 +    TBuf<128> error;
   35.76 +    error.Copy(error8);
   35.77 +
   35.78 +#ifndef TRACE_TO_FILE
   35.79 +    if (param) //!! Do not work if the parameter is really 0!!
   35.80 +        RDebug::Print(error, param);
   35.81 +    else 
   35.82 +        RDebug::Print(error);
   35.83 +#else
   35.84 +    if (param) //!! Do not work if the parameter is really 0!!
   35.85 +        RFileLogger::WriteFormat(KLibName, _L("SDL.txt"), EFileLoggingModeAppend, error, param);
   35.86 +    else 
   35.87 +        RFileLogger::Write(KLibName, _L("SDL.txt"), EFileLoggingModeAppend, error);
   35.88 +#endif
   35.89 +
   35.90 +    }
   35.91 +
   35.92 +extern "C" void RDebug_Print(char* error_str, void* param)
   35.93 +    {
   35.94 +    RDebug_Print_b(error_str, param);
   35.95 +    }
   35.96 +
   35.97 +/*
   35.98 +int Debug_AvailMem2()
   35.99 +    {
  35.100 +    //User::CompressAllHeaps();
  35.101 +    TMemoryInfoV1Buf membuf; 
  35.102 +    User::LeaveIfError(UserHal::MemoryInfo(membuf));
  35.103 +    TMemoryInfoV1 minfo = membuf();
  35.104 +	return(minfo.iFreeRamInBytes);
  35.105 +    }
  35.106 +
  35.107 +extern "C" int Debug_AvailMem()
  35.108 +    {
  35.109 +    return(Debug_AvailMem2());
  35.110 +    }
  35.111 +    
  35.112 +*/
  35.113 +
  35.114 +extern "C" {
  35.115 +
  35.116 +/* Initialization/Query functions */
  35.117 +
  35.118 +static int EPOC_VideoInit(_THIS, SDL_PixelFormat *vformat);
  35.119 +static SDL_Rect **EPOC_ListModes(_THIS, SDL_PixelFormat *format, Uint32 flags);
  35.120 +static SDL_Surface *EPOC_SetVideoMode(_THIS, SDL_Surface *current, int width, int height, int bpp, Uint32 flags);
  35.121 +static int EPOC_SetColors(_THIS, int firstcolor, int ncolors,
  35.122 +			  SDL_Color *colors);
  35.123 +static void EPOC_VideoQuit(_THIS);
  35.124 +
  35.125 +/* Hardware surface functions */
  35.126 +
  35.127 +static int EPOC_AllocHWSurface(_THIS, SDL_Surface *surface);
  35.128 +static int EPOC_LockHWSurface(_THIS, SDL_Surface *surface);
  35.129 +static int EPOC_FlipHWSurface(_THIS, SDL_Surface *surface);
  35.130 +static void EPOC_UnlockHWSurface(_THIS, SDL_Surface *surface);
  35.131 +static void EPOC_FreeHWSurface(_THIS, SDL_Surface *surface);
  35.132 +static void EPOC_DirectUpdate(_THIS, int numrects, SDL_Rect *rects);
  35.133 +
  35.134 +static int EPOC_Available(void);
  35.135 +static SDL_VideoDevice *EPOC_CreateDevice(int devindex);
  35.136 +
  35.137 +void DrawBackground(_THIS);
  35.138 +void DirectDraw(_THIS, int numrects, SDL_Rect *rects, TUint16* screenBuffer);
  35.139 +void DirectDrawRotated(_THIS, int numrects, SDL_Rect *rects, TUint16* screenBuffer);
  35.140 +
  35.141 +/* Mouse functions */
  35.142 +
  35.143 +static WMcursor *EPOC_CreateWMCursor(_THIS, Uint8 *data, Uint8 *mask, int w, int h, int hot_x, int hot_y);
  35.144 +static void EPOC_FreeWMCursor(_THIS, WMcursor *cursor);
  35.145 +static int EPOC_ShowWMCursor(_THIS, WMcursor *cursor);
  35.146 +}
  35.147 +
  35.148 +
  35.149 +extern "C"
  35.150 +	{
  35.151 +	struct WMcursor
  35.152 +		{
  35.153 +		};
  35.154 +	}
  35.155 +
  35.156 +/* Epoc video driver bootstrap functions */
  35.157 +
  35.158 +
  35.159 +static int EPOC_Available(void)
  35.160 +    {
  35.161 +    return 1; /* Always available */
  35.162 +    }
  35.163 +
  35.164 +static void EPOC_DeleteDevice(SDL_VideoDevice *device)
  35.165 +    {
  35.166 +	User::Free(device->hidden);
  35.167 +	User::Free(device);
  35.168 +    }
  35.169 +
  35.170 +static SDL_VideoDevice *EPOC_CreateDevice(int /*devindex*/)
  35.171 +    {
  35.172 +	SDL_VideoDevice *device;
  35.173 +
  35.174 +	SDL_TRACE("SDL:EPOC_CreateDevice");
  35.175 +
  35.176 +	/* Allocate all variables that we free on delete */
  35.177 +	device = static_cast<SDL_VideoDevice*>(User::Alloc(sizeof(SDL_VideoDevice)));
  35.178 +	if ( device ) 
  35.179 +	    {
  35.180 +		Mem::FillZ(device, (sizeof *device));
  35.181 +		device->hidden = static_cast<struct SDL_PrivateVideoData*>
  35.182 +				(User::Alloc((sizeof *device->hidden)));
  35.183 +	    }
  35.184 +	if ( (device == NULL) || (device->hidden == NULL) )
  35.185 +	    {
  35.186 +		SDL_OutOfMemory();
  35.187 +		if ( device ) {
  35.188 +		User::Free(device);
  35.189 +		}
  35.190 +		return(0);
  35.191 +	}
  35.192 +	Mem::FillZ(device->hidden, (sizeof *device->hidden));
  35.193 +
  35.194 +	/* Set the function pointers */
  35.195 +	device->VideoInit = EPOC_VideoInit;
  35.196 +	device->ListModes = EPOC_ListModes;
  35.197 +	device->SetVideoMode = EPOC_SetVideoMode;
  35.198 +	device->SetColors = EPOC_SetColors;
  35.199 +	device->UpdateRects = NULL;
  35.200 +	device->VideoQuit = EPOC_VideoQuit;
  35.201 +	device->AllocHWSurface = EPOC_AllocHWSurface;
  35.202 +	device->CheckHWBlit = NULL;
  35.203 +	device->FillHWRect = NULL;
  35.204 +	device->SetHWColorKey = NULL;
  35.205 +	device->SetHWAlpha = NULL;
  35.206 +	device->LockHWSurface = EPOC_LockHWSurface;
  35.207 +	device->UnlockHWSurface = EPOC_UnlockHWSurface;
  35.208 +	device->FlipHWSurface = EPOC_FlipHWSurface;
  35.209 +	device->FreeHWSurface = EPOC_FreeHWSurface;
  35.210 +	device->SetIcon = NULL;
  35.211 +	device->SetCaption = NULL;
  35.212 +	device->GetWMInfo = NULL;
  35.213 +	device->FreeWMCursor = EPOC_FreeWMCursor;
  35.214 +	device->CreateWMCursor = EPOC_CreateWMCursor;
  35.215 +	device->ShowWMCursor = EPOC_ShowWMCursor;
  35.216 +	device->WarpWMCursor = NULL;
  35.217 +	device->InitOSKeymap = EPOC_InitOSKeymap;
  35.218 +	device->PumpEvents = EPOC_PumpEvents;
  35.219 +	device->free = EPOC_DeleteDevice;
  35.220 +
  35.221 +	return device;
  35.222 +}
  35.223 +
  35.224 +
  35.225 +VideoBootStrap EPOC_bootstrap = {
  35.226 +	"epoc\0\0\0", "EPOC system",
  35.227 +    EPOC_Available, EPOC_CreateDevice
  35.228 +};
  35.229 +
  35.230 +
  35.231 +
  35.232 +void DisableKeyBlocking(_THIS)
  35.233 +    {
  35.234 +    EpocSdlEnv::Request(EpocSdlEnv::EDisableKeyBlocking);
  35.235 +    }
  35.236 +
  35.237 +void ConstructWindowL(_THIS)
  35.238 +	{
  35.239 +	SDL_TRACE("SDL:ConstructWindowL");
  35.240 +	DisableKeyBlocking(_this); //disable key blocking
  35.241 +	}
  35.242 +		
  35.243 +
  35.244 +int EPOC_VideoInit(_THIS, SDL_PixelFormat *vformat)
  35.245 +	{
  35.246 +    /* Construct Epoc window */
  35.247 +
  35.248 +    ConstructWindowL(_this);
  35.249 +
  35.250 +    /* Initialise Epoc frame buffer */
  35.251 +
  35.252 +  
  35.253 +    const TDisplayMode displayMode = EpocSdlEnv::DisplayMode();
  35.254 +
  35.255 +    /* The "best" video format should be returned to caller. */
  35.256 +
  35.257 +    vformat->BitsPerPixel 	= TDisplayModeUtils::NumDisplayModeBitsPerPixel(displayMode);
  35.258 +    vformat->BytesPerPixel  = TDisplayModeUtils::NumDisplayModeBitsPerPixel(displayMode) / 8;
  35.259 +
  35.260 +    
  35.261 + //??   Private->iWindow->PointerFilter(EPointerFilterDrag, 0); 
  35.262 +
  35.263 +    Private->iScreenPos = TPoint(0, 0);
  35.264 +    
  35.265 +    Private->iRect.x = Private->iScreenPos.iX;
  35.266 +    Private->iRect.y = Private->iScreenPos.iY;
  35.267 +    
  35.268 +    const TSize sz = EpocSdlEnv::WindowSize();
  35.269 +    
  35.270 +    Private->iRect.w = sz.iWidth;
  35.271 +    Private->iRect.h = sz.iHeight;
  35.272 +	Private->iRectPtr = &Private->iRect;
  35.273 +
  35.274 +	return(0);
  35.275 +	}
  35.276 +
  35.277 +
  35.278 +SDL_Rect **EPOC_ListModes(_THIS, SDL_PixelFormat *format, Uint32 flags)
  35.279 +	{
  35.280 +	if(flags & SDL_HWSURFACE)
  35.281 +		{
  35.282 +		if(format->BytesPerPixel != 4) //in HW only full color is supported
  35.283 +			return NULL;
  35.284 +		}
  35.285 +	if(flags & SDL_FULLSCREEN)
  35.286 +		{
  35.287 +		return &Private->iRectPtr;
  35.288 +		}
  35.289 +    return (SDL_Rect **)(-1); //everythingisok, unless too small shoes
  35.290 +	}
  35.291 +
  35.292 +
  35.293 +int EPOC_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color *colors)
  35.294 +	{
  35.295 +	if ((firstcolor+ncolors) > 256)
  35.296 +		return -1;
  35.297 +	TUint32 palette[256];
  35.298 +	const TDisplayMode mode = EpocSdlEnv::DisplayMode();
  35.299 +    if(TDisplayModeUtils::NumDisplayModeColors(mode) == 4096)
  35.300 +        {
  35.301 +	// Set 12 bit palette
  35.302 +        for(int i = firstcolor; i < ncolors; i++)
  35.303 +            {
  35.304 +	        // 4k value: 0000 rrrr gggg bbbb
  35.305 +	        TUint32 color4K	 = (colors[i].r & 0x0000f0) << 4;
  35.306 +	        color4K			|= (colors[i].g & 0x0000f0);      
  35.307 +	        color4K			|= (colors[i].b & 0x0000f0) >> 4;
  35.308 +            palette[i] = color4K;
  35.309 +            }
  35.310 +        }
  35.311 +    else if(TDisplayModeUtils::NumDisplayModeColors(mode) == 65536)
  35.312 +        {
  35.313 +        for(int i = firstcolor; i < ncolors; i++)
  35.314 +            {
  35.315 +			// 64k-colour displays effectively support RGB values
  35.316 +			// with 5 bits allocated to red, 6 to green and 5 to blue
  35.317 +			// 64k value: rrrr rggg gggb bbbb
  35.318 +	        TUint32 color64K = (colors[i].r & 0x0000f8) << 8;
  35.319 +	        color64K		|= (colors[i].g & 0x0000fc) << 3;
  35.320 +	        color64K		|= (colors[i].b & 0x0000f8) >> 3;
  35.321 +            palette[i] = color64K;
  35.322 +            }
  35.323 +        }
  35.324 +    else if(TDisplayModeUtils::NumDisplayModeColors(mode) == 16777216)
  35.325 +        {
  35.326 +        for(int i = firstcolor; i < ncolors; i++)
  35.327 +            {
  35.328 +			// 16M-colour
  35.329 +            //0000 0000 rrrr rrrr gggg gggg bbbb bbbb
  35.330 +	        TUint32 color16M = colors[i].r << 16;
  35.331 +	        color16M		|= colors[i].g << 8;
  35.332 +	        color16M		|= colors[i].b;
  35.333 +            palette[i] = color16M;
  35.334 +            }
  35.335 +        }
  35.336 +    else
  35.337 +        {
  35.338 +        return -2;
  35.339 +        }
  35.340 +    if(EpocSdlEnv::SetPalette(firstcolor, ncolors, palette) == KErrNone)
  35.341 +    	return 0;
  35.342 +	return -1;
  35.343 +	}
  35.344 +
  35.345 +
  35.346 +/*	
  35.347 +void AllocHWSurfaceL(CFbsBitmap*& aBitmap, const TDisplayMode& aMode, const TSize& aSize)
  35.348 +	{
  35.349 +	aBitmap = new (ELeave) CFbsBitmap();	
  35.350 +	if(KErrNone != aBitmap->CreateHardwareBitmap(aSize, aMode,
  35.351 +		EpocSdlEnv::EikonEnv().EikAppUi()->Application()->AppDllUid())) 
  35.352 +	//...if it fails - should we use wsbitmaps???
  35.353 +		{//the good reason to use hw bitmaps is that they wont need lock heap
  35.354 +		PANIC_IF_ERROR(aBitmap->Create(aSize, aMode));
  35.355 +		}
  35.356 +	}
  35.357 +	
  35.358 +int CreateSurfaceL(_THIS, SDL_Surface* surface)
  35.359 +    {
  35.360 +    __ASSERT_ALWAYS(Private->iFrame == NULL, PANIC(KErrAlreadyExists));
  35.361 +;
  35.362 +	TInt dmode = EColorLast;
  35.363 +	
  35.364 +	TDisplayMode displayMode;
  35.365 +	EpocSdlEnv::GetDiplayMode(displayMode);
  35.366 +	
  35.367 +	if(
  35.368 +	TDisplayModeUtils::NumDisplayModeBitsPerPixel(displayMode)
  35.369 +	== surface->format->BitsPerPixel)
  35.370 +		{
  35.371 +		dmode = displayMode;
  35.372 +		}
  35.373 +	else
  35.374 +		{
  35.375 +		--dmode;
  35.376 +		while(TDisplayModeUtils::IsDisplayModeColor(TDisplayMode(dmode)) &&
  35.377 +			TDisplayModeUtils::NumDisplayModeBitsPerPixel(TDisplayMode(dmode)) !=
  35.378 +			surface->format->BitsPerPixel)
  35.379 +			--dmode;
  35.380 +		}
  35.381 +
  35.382 +	__ASSERT_ALWAYS(TDisplayModeUtils::IsDisplayModeColor(TDisplayMode(dmode)), PANIC(KErrNotSupported));
  35.383 +	TRAPD(err, AllocHWSurfaceL(Private->iFrame, TDisplayMode(dmode), TSize(surface->w, surface->h)));
  35.384 +	return err == KErrNone ? 0 : -1;
  35.385 +    }
  35.386 +*/
  35.387 +
  35.388 +TDisplayMode GetDisplayMode(TInt aBitsPerPixel)
  35.389 +	{
  35.390 +	const TDisplayMode displayMode = EpocSdlEnv::DisplayMode();
  35.391 +	TInt dmode = EColorLast;
  35.392 +	if(
  35.393 +	TDisplayModeUtils::NumDisplayModeBitsPerPixel(displayMode)
  35.394 +	== aBitsPerPixel)
  35.395 +		{
  35.396 +		dmode = displayMode;
  35.397 +		}
  35.398 +	else
  35.399 +		{
  35.400 +		--dmode;
  35.401 +		while(TDisplayModeUtils::IsDisplayModeColor(TDisplayMode(dmode)) &&
  35.402 +			TDisplayModeUtils::NumDisplayModeBitsPerPixel(TDisplayMode(dmode)) !=
  35.403 +			aBitsPerPixel)
  35.404 +			--dmode;
  35.405 +		}
  35.406 +	return TDisplayMode(dmode);
  35.407 +	}
  35.408 +
  35.409 +SDL_Surface *EPOC_SetVideoMode(_THIS, SDL_Surface *current,
  35.410 +				int width, int height, int bpp, Uint32 flags)
  35.411 +	{
  35.412 +	const TSize screenSize = EpocSdlEnv::WindowSize(TSize(width, height));
  35.413 +	if(width > screenSize.iWidth || height > screenSize.iHeight)
  35.414 +	    {
  35.415 +	    if(flags & SDL_FULLSCREEN)
  35.416 +	        {
  35.417 +	        width = screenSize.iWidth;
  35.418 +	        height = screenSize.iHeight;
  35.419 +	        }
  35.420 +	    else    
  35.421 +		    return NULL;
  35.422 +	    }
  35.423 +
  35.424 +    if(current && current->pixels)
  35.425 +    	{
  35.426 +      //  free(current->pixels);
  35.427 +        current->pixels = NULL;
  35.428 +    	}
  35.429 +    	
  35.430 +	if(!SDL_ReallocFormat(current, bpp, 0, 0, 0, 0))
  35.431 +	 	{
  35.432 +		return(NULL);
  35.433 +	 	}
  35.434 +
  35.435 +	current->flags = 0;
  35.436 +	if(width == screenSize.iWidth && height == screenSize.iHeight)
  35.437 +		current->flags |= SDL_FULLSCREEN;
  35.438 +	
  35.439 +	const int numBytesPerPixel = ((bpp-1)>>3) + 1;   
  35.440 +	current->pitch = numBytesPerPixel * width; // Number of bytes in scanline 
  35.441 +
  35.442 +    /* Set up the new mode framebuffer */
  35.443 +   	current->flags |= SDL_PREALLOC;
  35.444 +   	
  35.445 +   	if(bpp <= 8)
  35.446 +   		current->flags |= SDL_HWPALETTE;
  35.447 +   	
  35.448 +   	User::Free(Private->iSwSurface);
  35.449 +   	current->pixels = NULL;
  35.450 +   	Private->iSwSurface = NULL;
  35.451 +   	
  35.452 +   	if(flags & SDL_HWSURFACE)
  35.453 +   	    {
  35.454 +   	    current->flags |= SDL_HWSURFACE;
  35.455 +   	   //	current->pixels = NULL;
  35.456 +   	   // 	Private->iSwSurface = NULL;
  35.457 +   	    }
  35.458 +   	else
  35.459 +   	    {
  35.460 +   	    current->flags |= SDL_SWSURFACE;
  35.461 +   	    const TInt surfacesize = width * height * numBytesPerPixel;  
  35.462 +   	   	Private->iSwSurfaceSize = TSize(width, height);
  35.463 +   	   	delete Private->iSwSurface;
  35.464 +   	   	Private->iSwSurface = NULL;
  35.465 +   	  	current->pixels = (TUint8*) User::AllocL(surfacesize);
  35.466 +   	  	Private->iSwSurface = (TUint8*) current->pixels;
  35.467 +   	  	const TInt err = EpocSdlEnv::AllocSwSurface
  35.468 +   	  		(TSize(width, height), GetDisplayMode(current->format->BitsPerPixel));
  35.469 +	    if(err != KErrNone)
  35.470 +	    	return NULL;
  35.471 +	    }
  35.472 +	
  35.473 +	current->w = width;
  35.474 +	current->h = height;
  35.475 +	
  35.476 +  
  35.477 +	
  35.478 +	/* Set the blit function */
  35.479 +	_this->UpdateRects = EPOC_DirectUpdate;
  35.480 +
  35.481 +    /*
  35.482 +     *  Logic for getting suitable screen dimensions, offset, scaling and orientation
  35.483 +     */
  35.484 +
  35.485 +
  35.486 +    /* Centralize game window on device screen  */
  35.487 +   
  35.488 +    
  35.489 +    Private->iScreenPos.iX = Max(0, (screenSize.iWidth  - width)  / 2);
  35.490 +    Private->iScreenPos.iY = Max(0, (screenSize.iHeight - height) / 2);
  35.491 +    
  35.492 + //   delete (Private->iFrame);
  35.493 +//	Private->iFrame = NULL;
  35.494 +	
  35.495 +  //  TRAPD(err, CreateSurfaceL(_this, current));
  35.496 +  //  PANIC_IF_ERROR(err);
  35.497 +    
  35.498 +    SDL_TRACE1("View width %d", width);
  35.499 +    SDL_TRACE1("View height %d", height);
  35.500 +    SDL_TRACE1("View bmode %d", bpp);
  35.501 +    SDL_TRACE1("View x %d", Private->iScreenPos.iX);
  35.502 +    SDL_TRACE1("View y %d", Private->iScreenPos.iY);
  35.503 +
  35.504 +	EpocSdlEnv::LockPalette(EFalse);
  35.505 +	/* We're done */
  35.506 +	return(current);
  35.507 +}
  35.508 +
  35.509 +
  35.510 +
  35.511 +static int EPOC_AllocHWSurface(_THIS, SDL_Surface* surface)
  35.512 +	{
  35.513 +	return KErrNone == EpocSdlEnv::AllocHwSurface(TSize(surface->w, surface->h), GetDisplayMode(surface->format->BitsPerPixel));
  35.514 +	}
  35.515 +	
  35.516 +static void EPOC_FreeHWSurface(_THIS, SDL_Surface* /*surface*/)
  35.517 +	{
  35.518 +	}
  35.519 +
  35.520 +static int EPOC_LockHWSurface(_THIS, SDL_Surface* surface)
  35.521 +	{
  35.522 +	if(EpocSdlEnv::IsDsaAvailable())
  35.523 +		{
  35.524 +		TUint8* address = EpocSdlEnv::LockHwSurface();
  35.525 +		if(address != NULL)
  35.526 +			{
  35.527 +			surface->pixels = address;
  35.528 +			return 1;
  35.529 +			}
  35.530 +		}
  35.531 +	return 0;
  35.532 +	}
  35.533 +static void EPOC_UnlockHWSurface(_THIS, SDL_Surface* /*surface*/)
  35.534 +	{
  35.535 +	EpocSdlEnv::UnlockHwSurface();
  35.536 +	}
  35.537 +
  35.538 +static int EPOC_FlipHWSurface(_THIS, SDL_Surface* /*surface*/)
  35.539 +	{
  35.540 +	return(0);
  35.541 +	}
  35.542 +
  35.543 +static void EPOC_DirectUpdate(_THIS, int numrects, SDL_Rect *rects)
  35.544 +	{
  35.545 +	if(EpocSdlEnv::IsDsaAvailable())
  35.546 +		{
  35.547 +		if(Private->iSwSurface)
  35.548 +		    {
  35.549 +		    const TRect target(Private->iScreenPos, Private->iSwSurfaceSize);
  35.550 +		    for(TInt i = 0; i < numrects ;i++)
  35.551 +		    	{
  35.552 +		    	const TRect rect(TPoint(rects[i].x, rects[i].y),
  35.553 +		    		TSize(rects[i].w, rects[i].h));
  35.554 +		    	if(!EpocSdlEnv::AddUpdateRect(Private->iSwSurface, rect, target))
  35.555 +		    		return; //not succesful
  35.556 +		    	}
  35.557 +		    EpocSdlEnv::UpdateSwSurface();
  35.558 +		    }
  35.559 +		SDL_PauseAudio(0);
  35.560 +		}
  35.561 +    else
  35.562 +    	{                                                      
  35.563 +     	SDL_PauseAudio(1);
  35.564 +    	EpocSdlEnv::WaitDsaAvailable();              
  35.565 +		}
  35.566 +	}
  35.567 +
  35.568 +
  35.569 +/* Note:  If we are terminated, this could be called in the middle of
  35.570 +   another SDL video routine -- notably UpdateRects.
  35.571 +*/
  35.572 +void EPOC_VideoQuit(_THIS)
  35.573 +	{
  35.574 +//	delete Private->iFrame;
  35.575 +//	Private->iFrame = NULL;
  35.576 +	User::Free(Private->iSwSurface);
  35.577 +	Private->iSwSurface = NULL;
  35.578 +	EpocSdlEnv::FreeSurface();
  35.579 +	}
  35.580 +	
  35.581 +	
  35.582 +
  35.583 +
  35.584 +WMcursor *EPOC_CreateWMCursor(_THIS, Uint8* /*data*/, Uint8* /*mask*/, int /*w*/, int /*h*/, int /*hot_x*/, int /*hot_y*/)
  35.585 +    {
  35.586 +    return (WMcursor*) 1; //hii! prevents SDL to view a std cursor
  35.587 +    }
  35.588 +
  35.589 +void EPOC_FreeWMCursor(_THIS, WMcursor* /*cursor*/)
  35.590 +    {
  35.591 +    }
  35.592 +
  35.593 +int EPOC_ShowWMCursor(_THIS, WMcursor *cursor)
  35.594 +    {
  35.595 +    return true;  
  35.596 +    }
  35.597 +
    36.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    36.2 +++ b/src/video/symbian/EKA2/SDL_epocvideo.h	Sun Jun 24 18:26:35 2007 +0000
    36.3 @@ -0,0 +1,51 @@
    36.4 +/*
    36.5 +    SDL - Simple DirectMedia Layer
    36.6 +    Copyright (C) 1997, 1998, 1999, 2000, 2001  Sam Lantinga
    36.7 +
    36.8 +    This library is free software; you can redistribute it and/or
    36.9 +    modify it under the terms of the GNU Library General Public
   36.10 +    License as published by the Free Software Foundation; either
   36.11 +    version 2 of the License, or (at your option) any later version.
   36.12 +
   36.13 +    This library is distributed in the hope that it will be useful,
   36.14 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
   36.15 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   36.16 +    Library General Public License for more details.
   36.17 +
   36.18 +    You should have received a copy of the GNU Library General Public
   36.19 +    License along with this library; if not, write to the Free
   36.20 +    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   36.21 +
   36.22 +    Sam Lantinga
   36.23 +    slouken@devolution.com
   36.24 +*/
   36.25 +
   36.26 +#ifndef EPOCVIDEO_H
   36.27 +#define EPOCVIDEO_H
   36.28 +
   36.29 +#include<w32std.h>
   36.30 +
   36.31 +/* Hidden "this" pointer for the video functions */
   36.32 +#define _THIS	SDL_VideoDevice *_this
   36.33 +#define Private	_this->hidden
   36.34 +
   36.35 +class CFbsBitmap;
   36.36 +
   36.37 +struct SDL_VideoDevice;
   36.38 +void DisableKeyBlocking(SDL_VideoDevice*);
   36.39 +
   36.40 +struct SDL_PrivateVideoData 
   36.41 +    {
   36.42 +    TPoint					iScreenPos;
   36.43 +    TBool                   iIsWindowFocused;
   36.44 +    TSize                   iSwSurfaceSize;
   36.45 +    TUint8*                 iSwSurface;
   36.46 +    SDL_Rect				iRect; //same info in SDL format
   36.47 +    SDL_Rect* 				iRectPtr;
   36.48 +    };
   36.49 +    
   36.50 +#endif    
   36.51 +
   36.52 +
   36.53 +
   36.54 +    
   36.55 \ No newline at end of file
    37.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    37.2 +++ b/src/video/symbian/EKA2/dsa.cpp	Sun Jun 24 18:26:35 2007 +0000
    37.3 @@ -0,0 +1,1504 @@
    37.4 +#include "dsa.h"
    37.5 +#include "sdlepocapi.h"
    37.6 +#include <cdsb.h>
    37.7 +
    37.8 +
    37.9 +LOCAL_C TInt BytesPerPixel(TDisplayMode aMode)
   37.10 +	{
   37.11 +	return ((TDisplayModeUtils::NumDisplayModeBitsPerPixel(aMode) - 1) >> 3) + 1; 
   37.12 +	}
   37.13 +
   37.14 +
   37.15 +
   37.16 +
   37.17 +template<class T>
   37.18 +class CBitmapSurface : public T
   37.19 +	{
   37.20 +public:
   37.21 +	CBitmapSurface(RWsSession& aSession);
   37.22 +private:
   37.23 +	void ConstructL(RWindow& aWindow, CWsScreenDevice& aDevice);
   37.24 +	~CBitmapSurface();
   37.25 +	TUint8* LockSurface();
   37.26 +	void UnlockHwSurface();
   37.27 +	void CreateSurfaceL();
   37.28 +	void Wipe(TInt aLength);
   37.29 +	void Free();
   37.30 +	void Update(CFbsBitmap& aBmp);
   37.31 +	TInt ExternalUpdate();
   37.32 +private:
   37.33 +	CFbsBitmap* iBmp;
   37.34 +	CFbsBitmap* iCopyBmp;
   37.35 +	};
   37.36 +	
   37.37 +
   37.38 +template<class T>
   37.39 +void CBitmapSurface<T>::ConstructL(RWindow& aWindow, CWsScreenDevice& aDevice)		
   37.40 +	{
   37.41 +	delete iCopyBmp;
   37.42 +	iCopyBmp = NULL;
   37.43 +	iCopyBmp = new (ELeave) CFbsBitmap();
   37.44 +	T::ConstructL(aWindow, aDevice);
   37.45 +	}
   37.46 +	
   37.47 +template<class T>
   37.48 +CBitmapSurface<T>::CBitmapSurface(RWsSession& aSession) : T(aSession)
   37.49 +	{
   37.50 +	}
   37.51 +	
   37.52 +template<class T>
   37.53 +void CBitmapSurface<T>::Free()
   37.54 +	{
   37.55 +	delete iBmp;
   37.56 +	iBmp = NULL;
   37.57 +	T::Free();
   37.58 +	}
   37.59 +
   37.60 +template<class T>
   37.61 +CBitmapSurface<T>::~CBitmapSurface()
   37.62 +	{
   37.63 +	__ASSERT_DEBUG(iBmp == NULL, PANIC(KErrNotReady));
   37.64 +	delete iCopyBmp;
   37.65 +	}
   37.66 +	
   37.67 +template<class T>
   37.68 +TUint8* CBitmapSurface<T>::LockSurface()
   37.69 +	{
   37.70 +	iBmp->LockHeap();
   37.71 +	return reinterpret_cast<TUint8*>(iBmp->DataAddress());
   37.72 +	}
   37.73 +
   37.74 +
   37.75 +template<class T>
   37.76 +void CBitmapSurface<T>::UnlockHwSurface()
   37.77 +	{
   37.78 +	iBmp->UnlockHeap();
   37.79 +	T::SetUpdating(EFalse);
   37.80 +	Update(*iBmp);
   37.81 +	}
   37.82 +
   37.83 +	
   37.84 +template<class T>	
   37.85 +void CBitmapSurface<T>::Update(CFbsBitmap& aBmp)
   37.86 +	{
   37.87 +	if(!T::Blitter(aBmp))
   37.88 +		{
   37.89 +		if(T::SwSize() == T::HwRect().Size())
   37.90 +			T::Gc().BitBlt(T::HwRect().iTl, &aBmp);
   37.91 +		else
   37.92 +			T::Gc().DrawBitmap(T::HwRect(), &aBmp);
   37.93 +		}
   37.94 +	T::DrawOverlays();
   37.95 +	T::CompleteUpdate();	
   37.96 +	}
   37.97 +	
   37.98 +template<class T>	
   37.99 +void CBitmapSurface<T>::CreateSurfaceL()
  37.100 +	{
  37.101 +	Free();
  37.102 +	iBmp  = new (ELeave) CFbsBitmap();
  37.103 +	User::LeaveIfError(iBmp->Create(T::SwSize(), T::DisplayMode()));
  37.104 +	T::CreateSurfaceL(*iBmp);
  37.105 +	}
  37.106 +
  37.107 +template<class T>
  37.108 +void CBitmapSurface<T>::Wipe(TInt aLength) //dont call in drawing
  37.109 +	{
  37.110 +	iBmp->LockHeap();
  37.111 +	Mem::FillZ(iBmp->DataAddress(), aLength);
  37.112 +	iBmp->UnlockHeap();
  37.113 +	}
  37.114 +
  37.115 +template<class T>		
  37.116 +TInt CBitmapSurface<T>::ExternalUpdate()
  37.117 +	{
  37.118 +	if(iCopyBmp->Handle() == 0)
  37.119 +		{
  37.120 +		const TInt err = iCopyBmp->Duplicate(iBmp->Handle());
  37.121 +		if(err != KErrNone)
  37.122 +			return err;
  37.123 +		}
  37.124 +	Update(*iCopyBmp);
  37.125 +	return KErrNone;
  37.126 +	}
  37.127 +
  37.128 +
  37.129 +//////////////////////////////////////////////////////////////////////
  37.130 +
  37.131 +
  37.132 +
  37.133 +NONSHARABLE_CLASS(CDsaBitgdi) : public CDsa
  37.134 +	{
  37.135 +public:
  37.136 +	CDsaBitgdi(RWsSession& aSession);
  37.137 +protected:
  37.138 +	 void ConstructL(RWindow& aWindow, CWsScreenDevice& aDevice);
  37.139 +	 CBitmapContext& Gc();
  37.140 +	 void CompleteUpdate();
  37.141 +	 ~CDsaBitgdi();
  37.142 +	 void CreateSurfaceL(CFbsBitmap& aBmp);
  37.143 +	 void Free();
  37.144 +	 void UnlockHWSurfaceRequestComplete();
  37.145 +private:
  37.146 +	 void Resume();
  37.147 +	 
  37.148 +	 CFbsBitGc* iGc;
  37.149 +	 CFbsDevice* iDevice;
  37.150 +	 CFbsBitmap* iBitGdiBmp;
  37.151 +	 CWindowGc* iWinGc;
  37.152 +	 RWindow* iWindow;
  37.153 +	 TInt iHandle;
  37.154 +	 };
  37.155 +
  37.156 +
  37.157 +CDsaBitgdi::CDsaBitgdi(RWsSession& aSession) : CDsa(aSession)
  37.158 +	{
  37.159 +	}
  37.160 +
  37.161 +CDsaBitgdi::~CDsaBitgdi()
  37.162 +	{
  37.163 +	delete iWinGc;
  37.164 +	delete iBitGdiBmp;
  37.165 +	}
  37.166 +
  37.167 +void CDsaBitgdi::CompleteUpdate()
  37.168 +	{
  37.169 +	EpocSdlEnv::Request(CDsa::ERequestUpdate);
  37.170 +	}
  37.171 +
  37.172 +	
  37.173 +void CDsaBitgdi::UnlockHWSurfaceRequestComplete()
  37.174 +	{
  37.175 +	if(iHandle == 0)
  37.176 +		return;
  37.177 +	
  37.178 +	if(iBitGdiBmp == NULL)
  37.179 +		{
  37.180 +		iBitGdiBmp = new CFbsBitmap();
  37.181 +		if(iBitGdiBmp == NULL)
  37.182 +			return;
  37.183 +		iBitGdiBmp->Duplicate(iHandle);
  37.184 +		}
  37.185 +	
  37.186 +	iWindow->Invalidate();
  37.187 +	
  37.188 +	iWindow->BeginRedraw();
  37.189 +	iWinGc->Activate(*iWindow);
  37.190 +	iWinGc->BitBlt(TPoint(0, 0), iBitGdiBmp);
  37.191 +	iWinGc->Deactivate();
  37.192 +	iWindow->EndRedraw();
  37.193 +	}	
  37.194 +	
  37.195 +void CDsaBitgdi::Resume()
  37.196 +	{
  37.197 +	Start();
  37.198 +	}
  37.199 +	
  37.200 +CBitmapContext& CDsaBitgdi::Gc()
  37.201 + 	{
  37.202 + 	return *iGc;
  37.203 + 	}
  37.204 + 	
  37.205 + void CDsaBitgdi::ConstructL(RWindow& aWindow, CWsScreenDevice& aDevice)
  37.206 + 	{
  37.207 + 	
  37.208 + 	delete iBitGdiBmp;
  37.209 + 	iBitGdiBmp = NULL;
  37.210 + 	delete iWinGc;
  37.211 + 	iWinGc = NULL;
  37.212 + 	iHandle = 0;
  37.213 + 	
  37.214 + 	iWindow = &aWindow;
  37.215 + 	User::LeaveIfError(aDevice.CreateContext(iWinGc));
  37.216 + 	CDsa::ConstructL(aWindow, aDevice);
  37.217 + 	Start();
  37.218 + 	}
  37.219 + 	
  37.220 +void CDsaBitgdi::CreateSurfaceL(CFbsBitmap& aBmp)	
  37.221 +	{
  37.222 +	iDevice = CFbsBitmapDevice::NewL(&aBmp);
  37.223 +	User::LeaveIfError(iDevice->CreateContext(iGc));
  37.224 +	iHandle = aBmp.Handle();
  37.225 +	}
  37.226 +	
  37.227 +void CDsaBitgdi::Free()
  37.228 +	{
  37.229 +	delete iGc;
  37.230 +	iGc = NULL;
  37.231 +	delete iDevice;
  37.232 +	iDevice = NULL;
  37.233 +	}
  37.234 +	
  37.235 +////////////////////////////////////////////////////////////////////////
  37.236 +///////////////////////////////////////////////////////////////////////
  37.237 +
  37.238 +NONSHARABLE_CLASS(CDsaBase) : public CDsa, public MDirectScreenAccess
  37.239 +	{
  37.240 +protected:	
  37.241 +	inline CDirectScreenAccess& Dsa() const;
  37.242 +	CDsaBase(RWsSession& aSession);
  37.243 +	~CDsaBase();
  37.244 +	void ConstructL(RWindow& aWindow, CWsScreenDevice& aDevice);
  37.245 +	void Stop();
  37.246 +	void Resume();
  37.247 +	CBitmapContext& Gc();
  37.248 +protected:
  37.249 +    CDirectScreenAccess*  iDsa;
  37.250 +private:
  37.251 +	void AbortNow(RDirectScreenAccess::TTerminationReasons aReason);
  37.252 +	void Restart(RDirectScreenAccess::TTerminationReasons aReason);
  37.253 +private:
  37.254 +	void RestartL();
  37.255 +	};
  37.256 +
  37.257 +
  37.258 +inline CDirectScreenAccess& CDsaBase::Dsa() const
  37.259 +	{
  37.260 +	return *iDsa;
  37.261 +	}
  37.262 +	
  37.263 +
  37.264 +CDsaBase::CDsaBase(RWsSession& aSession) : CDsa(aSession)
  37.265 +	{
  37.266 +	}
  37.267 +	
  37.268 +CBitmapContext& CDsaBase::Gc()
  37.269 +	{
  37.270 +	return *Dsa().Gc();
  37.271 +	}
  37.272 +	
  37.273 +void CDsaBase::ConstructL(RWindow& aWindow, CWsScreenDevice& aDevice)
  37.274 +    {
  37.275 +    CDsa::ConstructL(aWindow, aDevice);
  37.276 +    if(iDsa != NULL)
  37.277 +    	{
  37.278 +    	iDsa->Cancel();
  37.279 +    	delete iDsa;
  37.280 +    	iDsa = NULL;
  37.281 +    	}
  37.282 +    	
  37.283 +    iDsa = CDirectScreenAccess::NewL(
  37.284 +    				Session(),
  37.285 +					aDevice,
  37.286 +					aWindow,
  37.287 +					*this);				
  37.288 +    RestartL();
  37.289 +    }	
  37.290 +	
  37.291 +void CDsaBase::Resume()	
  37.292 +	{
  37.293 +	if(Stopped())
  37.294 +		Restart(RDirectScreenAccess::ETerminateRegion);
  37.295 +	}	
  37.296 +	
  37.297 +CDsaBase::~CDsaBase()
  37.298 +	{
  37.299 +	if(iDsa != NULL)
  37.300 +        {
  37.301 +        iDsa->Cancel();
  37.302 +        }
  37.303 +    delete iDsa;
  37.304 +	}
  37.305 +	
  37.306 +	
  37.307 +void CDsaBase::RestartL()
  37.308 +    {
  37.309 +   
  37.310 +    
  37.311 +    iDsa->StartL();	
  37.312 +    
  37.313 +    const RRegion* r = iDsa->DrawingRegion();
  37.314 +    const TRect rect = r->BoundingRect();
  37.315 +    iDsa->Gc()->SetClippingRegion(r);	
  37.316 +   
  37.317 +    if(rect != ScreenRect())
  37.318 +    	{
  37.319 +    	return ;	
  37.320 +   	 	}
  37.321 +   	 	
  37.322 +     
  37.323 +   	SetTargetRect();
  37.324 +	RecreateL();
  37.325 +	
  37.326 +	Start();
  37.327 +    
  37.328 +    
  37.329 +    }
  37.330 +
  37.331 +void CDsaBase::AbortNow(RDirectScreenAccess::TTerminationReasons /*aReason*/)
  37.332 +	{
  37.333 +	Stop();
  37.334 +	}
  37.335 +	
  37.336 +void CDsaBase::Restart(RDirectScreenAccess::TTerminationReasons aReason)
  37.337 +	{
  37.338 +	if(aReason == RDirectScreenAccess::ETerminateRegion) //auto restart
  37.339 +		{												
  37.340 +		TRAPD(err, RestartL());
  37.341 +		PANIC_IF_ERROR(err);
  37.342 +		}
  37.343 +	}
  37.344 +	
  37.345 +	
  37.346 +void CDsaBase::Stop()
  37.347 +	{
  37.348 +	CDsa::Stop();
  37.349 +	iDsa->Cancel();
  37.350 +	}
  37.351 +		
  37.352 +    
  37.353 +   ///////////////////////////////////////////////////////////////////////
  37.354 +   /////////////////////////////////////////////////////////////////////// 
  37.355 +NONSHARABLE_CLASS(TDsa)
  37.356 +	{
  37.357 +	public:
  37.358 +		inline TDsa(const CDsa& aDsa);
  37.359 +		inline TBool IsFlip() const;
  37.360 +		inline TBool IsTurn() const;
  37.361 +		inline const TSize& SwSize() const;
  37.362 +		inline void Copy(TUint32* aTarget, const TUint8* aSrc, TInt aBytes, TInt aHeight) const;
  37.363 +	private:
  37.364 +		const CDsa& iDsa;
  37.365 +	};
  37.366 +
  37.367 +
  37.368 +
  37.369 +
  37.370 +inline TDsa::TDsa(const CDsa& aDsa) : iDsa(aDsa)
  37.371 +	{	
  37.372 +	}
  37.373 +
  37.374 +inline TBool TDsa::IsTurn() const
  37.375 +	{
  37.376 +	return iDsa.iStateFlags & CDsa::EOrientation90;
  37.377 +	}
  37.378 +	
  37.379 +inline TBool TDsa::IsFlip() const
  37.380 +	{
  37.381 +	return iDsa.iStateFlags & CDsa::EOrientation180;
  37.382 +	}	
  37.383 +	
  37.384 +inline const TSize& TDsa::SwSize() const
  37.385 +	{
  37.386 +	return iDsa.SwSize();
  37.387 +	}
  37.388 +		
  37.389 +inline void TDsa::Copy(TUint32* aTarget, const TUint8* aSrc, TInt aBytes, TInt aHeight) const
  37.390 +	{
  37.391 +	iDsa.iCopyFunction(iDsa, aTarget, aSrc, aBytes, aHeight);
  37.392 +	}
  37.393 +	
  37.394 +template<class T, class S>	
  37.395 +void ClipCopy(const TDsa& iDsa, TUint8* aTarget,
  37.396 + 					const TUint8* aSource,
  37.397 + 					const TRect& aUpdateRect,
  37.398 + 					const TRect& aSourceRect)
  37.399 +	{
  37.400 +	const S* source = reinterpret_cast<const S*>(aSource);
  37.401 +	const TInt lineWidth = aSourceRect.Width();
  37.402 +	
  37.403 +	source += (aUpdateRect.iTl.iY * lineWidth); 
  37.404 +	const TInt sourceStartOffset = aUpdateRect.iTl.iX;
  37.405 +	source += sourceStartOffset;
  37.406 +	
  37.407 +	T* targetPtr = reinterpret_cast<T*>(aTarget);
  37.408 +	
  37.409 +	const TInt scanLineWidth = iDsa.SwSize().iWidth;
  37.410 +	
  37.411 +	targetPtr += (aSourceRect.iTl.iY + aUpdateRect.iTl.iY ) * scanLineWidth; 
  37.412 +	const TInt targetStartOffset = (aUpdateRect.iTl.iX + aSourceRect.iTl.iX);
  37.413 +	
  37.414 +	targetPtr += targetStartOffset;
  37.415 +	
  37.416 +	
  37.417 +	const TInt height = aUpdateRect.Height(); 
  37.418 +		
  37.419 +	const TInt lineMove = iDsa.IsTurn() ? 1 : lineWidth;
  37.420 +	const TInt copyLen = aUpdateRect.Width();
  37.421 +	
  37.422 +	
  37.423 +	if(iDsa.IsFlip())
  37.424 +		{
  37.425 +		
  37.426 +		targetPtr += scanLineWidth *  (height - 1);
  37.427 +	
  37.428 +		for(TInt i = 0; i < height; i++) //source is always smaller
  37.429 +			{
  37.430 +			iDsa.Copy(reinterpret_cast<TUint32*>(targetPtr), reinterpret_cast<const TUint8*>(source), copyLen, height);
  37.431 +			source += lineMove;
  37.432 +			targetPtr -= scanLineWidth;
  37.433 +			}
  37.434 +		}
  37.435 +	else
  37.436 +		{
  37.437 +		
  37.438 +		
  37.439 +		for(TInt i = 0; i < height; i++) //source is always smaller
  37.440 +			{
  37.441 +			iDsa.Copy(reinterpret_cast<TUint32*>(targetPtr), reinterpret_cast<const TUint8*>(source), copyLen, height);
  37.442 +			source += lineMove;
  37.443 +			targetPtr += scanLineWidth; // >> 2;
  37.444 +			}
  37.445 +		}
  37.446 +
  37.447 +	}
  37.448 +	
  37.449 +
  37.450 + 
  37.451 +NONSHARABLE_CLASS(CDsaA) : public CDsaBase
  37.452 +	{
  37.453 +	public:
  37.454 +		CDsaA(RWsSession& aSession);
  37.455 +	protected:
  37.456 +		void ConstructL(RWindow& aWindow, CWsScreenDevice& aDevice);
  37.457 +		void CompleteUpdate();
  37.458 +		void CreateSurfaceL(CFbsBitmap& aBmp);
  37.459 +		void Free();
  37.460 +		void UnlockHWSurfaceRequestComplete();	
  37.461 +	};
  37.462 +	
  37.463 +	
  37.464 +CDsaA::CDsaA(RWsSession& aSession) : CDsaBase(aSession)
  37.465 +	{
  37.466 +	}
  37.467 +	
  37.468 +
  37.469 +void CDsaA::ConstructL(RWindow& aWindow, CWsScreenDevice& aDevice)		
  37.470 +	{
  37.471 +	CDsaBase::ConstructL(aWindow, aDevice);
  37.472 +	}
  37.473 +	
  37.474 +void CDsaA::CompleteUpdate()
  37.475 +	{
  37.476 +	iDsa->ScreenDevice()->Update();
  37.477 +	}
  37.478 +	
  37.479 +void CDsaA::CreateSurfaceL(CFbsBitmap& /*aBmp*/)
  37.480 +	{
  37.481 +	}
  37.482 +	
  37.483 +void CDsaA::Free()
  37.484 +	{
  37.485 +	
  37.486 +	}
  37.487 +	
  37.488 +void CDsaA::UnlockHWSurfaceRequestComplete()
  37.489 +	{
  37.490 +	PANIC(KErrNotSupported);
  37.491 +	}	
  37.492 +	
  37.493 +	
  37.494 +	
  37.495 +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  37.496 +
  37.497 +NONSHARABLE_CLASS(MDsbObs)
  37.498 +	{
  37.499 +	public:
  37.500 +		virtual void SurfaceReady() = 0;
  37.501 +		virtual CDirectScreenBitmap& Dsb() = 0;
  37.502 +	};
  37.503 +	
  37.504 +NONSHARABLE_CLASS(CDsbSurface) : public CActive
  37.505 +	{
  37.506 +	public:
  37.507 +		CDsbSurface(MDsbObs& aDsb);
  37.508 +		TUint8* Address();
  37.509 +		void Complete();
  37.510 +		~CDsbSurface();
  37.511 +	private:
  37.512 +		void RunL();
  37.513 +		void DoCancel();
  37.514 +	private:
  37.515 +		MDsbObs& iDsb; 
  37.516 +		TUint8* iAddress;
  37.517 +	};	
  37.518 +
  37.519 +CDsbSurface::CDsbSurface(MDsbObs& aDsb) : CActive(CActive::EPriorityHigh) , iDsb(aDsb)
  37.520 +	{
  37.521 +	CActiveScheduler::Add(this);
  37.522 +	}
  37.523 +
  37.524 +CDsbSurface::~CDsbSurface()
  37.525 +	{
  37.526 +	Cancel();
  37.527 +	}
  37.528 +	
  37.529 +void CDsbSurface::Complete()
  37.530 +	{
  37.531 +	if(iAddress != NULL && !IsActive())
  37.532 +		{
  37.533 +		iAddress = NULL;
  37.534 +		SetActive();
  37.535 +		iDsb.Dsb().EndUpdate(iStatus);
  37.536 +		}
  37.537 +	}
  37.538 +	
  37.539 +TUint8* CDsbSurface::Address()
  37.540 +	{
  37.541 +	if(iAddress == NULL && !IsActive())
  37.542 +		{
  37.543 +		TAcceleratedBitmapInfo info;
  37.544 +		if(KErrNone == iDsb.Dsb().BeginUpdate(info))
  37.545 +			iAddress = info.iAddress;
  37.546 +		}
  37.547 +	return iAddress;
  37.548 +	}
  37.549 +	
  37.550 +void CDsbSurface::RunL()
  37.551 +	{
  37.552 +	iDsb.SurfaceReady();
  37.553 +	}
  37.554 +
  37.555 +void CDsbSurface::DoCancel()
  37.556 +	{
  37.557 +	//empty
  37.558 +	}
  37.559 +		
  37.560 +NONSHARABLE_CLASS(CDsaB) : public CDsaBase,
  37.561 + public MDsbObs
  37.562 +	{
  37.563 +	public:
  37.564 +		CDsaB(RWsSession& aSession, TInt aFlags);
  37.565 +	private:
  37.566 +		~CDsaB();
  37.567 +		TUint8* LockSurface();
  37.568 +		void UnlockHWSurfaceRequestComplete();
  37.569 +		void UnlockHwSurface();
  37.570 +		void CreateSurfaceL();
  37.571 +		void Wipe(TInt aLength);
  37.572 +		void RecreateL();
  37.573 +		void ConstructL(RWindow& aWindow, CWsScreenDevice& aDevice);
  37.574 +		CDirectScreenBitmap& Dsb();
  37.575 +		void SurfaceReady();
  37.576 +		TInt ExternalUpdate();
  37.577 +	private:
  37.578 +		CDsbSurface* iSurface1;
  37.579 +		CDsbSurface* iSurface2;
  37.580 +		CDirectScreenBitmap* iDsb;
  37.581 +		TInt iType;
  37.582 +	};
  37.583 +
  37.584 +CDsaB::CDsaB(RWsSession& aSession, TInt aFlags) : CDsaBase(aSession), iType(aFlags)
  37.585 +	{
  37.586 +	}
  37.587 +
  37.588 +
  37.589 +	
  37.590 +void CDsaB::UnlockHWSurfaceRequestComplete()
  37.591 +	{
  37.592 +	iSurface1->Complete();
  37.593 +	if(iSurface2 != NULL)
  37.594 +		iSurface2->Complete();
  37.595 +	}	
  37.596 +
  37.597 +void CDsaB::CreateSurfaceL()
  37.598 +	{
  37.599 +	__ASSERT_ALWAYS(SwSize() == HwRect().Size(), PANIC(KErrNotSupported));
  37.600 +	}
  37.601 +	
  37.602 +void CDsaB::Wipe(TInt aLength) //dont call in drawing
  37.603 +	{
  37.604 +	TUint8* addr = LockSurface();
  37.605 +	if(addr != NULL) 
  37.606 +		{
  37.607 +		Mem::FillZ(addr, aLength);
  37.608 +		UnlockHwSurface();
  37.609 +		}
  37.610 +	}
  37.611 +	
  37.612 +
  37.613 +void CDsaB::UnlockHwSurface()
  37.614 +	{
  37.615 +	EpocSdlEnv::Request(CDsa::ERequestUpdate);
  37.616 +	}
  37.617 +	
  37.618 +TUint8* CDsaB::LockSurface()
  37.619 +	{
  37.620 +	TUint8* addr =  iSurface1->Address();
  37.621 +	if(addr == NULL && iSurface2 != NULL)
  37.622 +		addr =  iSurface2->Address();
  37.623 +	SetUpdating(addr == NULL);
  37.624 +	return addr;
  37.625 +	}
  37.626 +	
  37.627 +void CDsaB::SurfaceReady()	
  37.628 +	{
  37.629 +	SetUpdating(EFalse);
  37.630 +	}
  37.631 +
  37.632 +CDirectScreenBitmap& CDsaB::Dsb()
  37.633 +	{
  37.634 +	return *iDsb;
  37.635 +	}
  37.636 +	
  37.637 +void CDsaB::ConstructL(RWindow& aWindow, CWsScreenDevice& aDevice)
  37.638 +	{
  37.639 +	if(iDsb == NULL)
  37.640 +		iDsb = CDirectScreenBitmap::NewL();	
  37.641 +	CDsaBase::ConstructL(aWindow, aDevice);
  37.642 +	if(iSurface1 == NULL)	
  37.643 +		iSurface1 = new (ELeave) CDsbSurface(*this);
  37.644 +	if(iSurface2 == NULL && iType & CDirectScreenBitmap::EDoubleBuffer)
  37.645 +		iSurface2 = new (ELeave) CDsbSurface(*this);
  37.646 +	}
  37.647 +	
  37.648 +CDsaB::~CDsaB()
  37.649 +	{
  37.650 +	delete iSurface1;
  37.651 +	delete iSurface2;
  37.652 +	delete iDsb;
  37.653 +	}	
  37.654 +
  37.655 +void CDsaB::RecreateL()
  37.656 +	{
  37.657 +    iDsb->Close();
  37.658 +    iDsb->Create(HwRect(), CDirectScreenBitmap::TSettingsFlags(iType));
  37.659 +	}
  37.660 +	
  37.661 +TInt CDsaB::ExternalUpdate()
  37.662 +	{
  37.663 +	if(LockSurface())
  37.664 +		{
  37.665 +		UnlockHWSurfaceRequestComplete();
  37.666 +		return KErrNone;
  37.667 +		}
  37.668 +	return KErrNotReady;
  37.669 +	}
  37.670 +		
  37.671 +