From 5864c0c8e8f87cd237ee31c6fe5edccafb380d8f Mon Sep 17 00:00:00 2001 From: Bartosz Taudul Date: Sun, 13 Jul 2008 15:23:32 +0200 Subject: [PATCH] Big cleanup part 1. Big cleanup of the mess these sources are: - Indentified sources using vim's indentation. - Removed small and big chunks of commented-out code. - Removed #ifdef'd code which purpose is not known to anyone. - Some extraneous access modifiers has been removed. - ... --- src/audio/symbian/SDL_epocaudio.cpp | 509 +++----- src/audio/symbian/SDL_epocaudio.h | 67 +- src/audio/symbian/streamplayer.cpp | 305 ++--- src/audio/symbian/streamplayer.h | 73 +- src/main/symbian/SDL_env.cpp | 42 +- src/main/symbian/SDL_main.cpp | 2346 ++++++++++++++++------------------ src/main/symbian/sdlexe.cpp | 1247 +++++++----------- src/main/symbian/vectorbuffer.cpp | 111 +- src/main/symbian/vectorbuffer.h | 442 +++---- src/thread/symbian/SDL_sysmutex.cpp | 246 ++-- src/thread/symbian/SDL_syssem.cpp | 367 +++--- src/thread/symbian/SDL_systhread.cpp | 279 ++-- src/thread/symbian/SDL_systhread_c.h | 60 +- src/timer/symbian/SDL_systimer.cpp | 222 ++-- src/video/symbian/SDL_epocevents.cpp | 896 ++++++------- src/video/symbian/SDL_epocevents_c.h | 111 +- src/video/symbian/SDL_epocvideo.cpp | 905 ++++++------- src/video/symbian/SDL_epocvideo.h | 134 +- src/video/symbian/dsa.cpp | 1663 +++++++++++------------- 19 files changed, 4352 insertions(+), 5673 deletions(-) rewrite src/audio/symbian/SDL_epocaudio.h (88%) rewrite src/main/symbian/SDL_main.cpp (62%) rewrite src/main/symbian/vectorbuffer.cpp (76%) rewrite src/main/symbian/vectorbuffer.h (77%) rewrite src/thread/symbian/SDL_sysmutex.cpp (66%) rewrite src/thread/symbian/SDL_syssem.cpp (70%) rewrite src/thread/symbian/SDL_systhread.cpp (66%) rewrite src/thread/symbian/SDL_systhread_c.h (95%) rewrite src/timer/symbian/SDL_systimer.cpp (87%) rewrite src/video/symbian/SDL_epocevents.cpp (78%) rewrite src/video/symbian/SDL_epocevents_c.h (77%) rewrite src/video/symbian/SDL_epocvideo.h (71%) diff --git a/src/audio/symbian/SDL_epocaudio.cpp b/src/audio/symbian/SDL_epocaudio.cpp index 6c36671..80c790c 100644 --- a/src/audio/symbian/SDL_epocaudio.cpp +++ b/src/audio/symbian/SDL_epocaudio.cpp @@ -1,37 +1,31 @@ /* - SDL - Simple DirectMedia Layer - Copyright (C) 1997, 1998, 1999, 2000, 2001 Sam Lantinga + SDL - Simple DirectMedia Layer + Copyright (C) 1997, 1998, 1999, 2000, 2001 Sam Lantinga - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. - You should have received a copy of the GNU Library General Public - License along with this library; if not, write to the Free - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + You should have received a copy of the GNU Library General Public + License along with this library; if not, write to the Free + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - Sam Lantinga - slouken@devolution.com -*/ + Sam Lantinga + slouken@devolution.com + */ /* - SDL_epocaudio.cpp - Epoc based SDL audio driver implementation - - Markus Mertama -*/ - -#ifdef SAVE_RCSID -static char rcsid = - "@(#) $Id: SDL_epocaudio.c,v 0.0.0.0 2001/06/19 17:19:56 hercules Exp $"; -#endif + SDL_epocaudio.cpp + Epoc based SDL audio driver implementation + Markus Mertama + */ #include #include @@ -62,10 +56,6 @@ extern "C" { #include "streamplayer.h" - -//#define DEBUG_AUDIO - - /* Audio driver functions */ static int EPOC_OpenAudio(SDL_AudioDevice *thisdevice, SDL_AudioSpec *spec); @@ -79,241 +69,163 @@ static int Audio_Available(void); static SDL_AudioDevice *Audio_CreateDevice(int devindex); static void Audio_DeleteDevice(SDL_AudioDevice *device); - -//void sos_adump(SDL_AudioDevice* thisdevice, void* data, int len); - -#ifdef __WINS__ -#define DODUMP -#endif - -#ifdef DODUMP -NONSHARABLE_CLASS(TDump) - { - public: - TInt Open(); - void Close(); - void Dump(const TDesC8& aDes); - private: - RFile iFile; - RFs iFs; - }; - -TInt TDump::Open() - { - TInt err = iFs.Connect(); - if(err == KErrNone) - { -#ifdef __WINS__ -_LIT(target, "C:\\sdlau.raw"); -#else -_LIT(target, "E:\\sdlau.raw"); -#endif - err = iFile.Replace(iFs, target, EFileWrite); - } - return err; - } -void TDump::Close() - { - iFile.Close(); - iFs.Close(); - } -void TDump::Dump(const TDesC8& aDes) - { - iFile.Write(aDes); - } -#endif - - NONSHARABLE_CLASS(CSimpleWait) : public CTimer - { +{ public: void Wait(TTimeIntervalMicroSeconds32 aWait); static CSimpleWait* NewL(); private: CSimpleWait(); void RunL(); - }; - +}; CSimpleWait* CSimpleWait::NewL() - { +{ CSimpleWait* wait = new (ELeave) CSimpleWait(); CleanupStack::PushL(wait); wait->ConstructL(); CleanupStack::Pop(); return wait; - } +} void CSimpleWait::Wait(TTimeIntervalMicroSeconds32 aWait) - { +{ After(aWait); CActiveScheduler::Start(); - } - +} + CSimpleWait::CSimpleWait() : CTimer(CActive::EPriorityStandard) - { +{ CActiveScheduler::Add(this); - } +} void CSimpleWait::RunL() - { +{ CActiveScheduler::Stop(); - } +} const TInt KAudioBuffers(2); - + NONSHARABLE_CLASS(CEpocAudio) : public CBase, public MStreamObs, public MStreamProvider - { - public: - static void* NewL(TInt BufferSize, TInt aFill); - inline static CEpocAudio& Current(SDL_AudioDevice* thisdevice); - - static void Free(SDL_AudioDevice* thisdevice); - - void Wait(); - void Play(); - // void SetBuffer(const TDesC8& aBuffer); - void ThreadInitL(TAny* aDevice); - void Open(TInt iRate, TInt iChannels, TUint32 aType, TInt aBytes); - ~CEpocAudio(); - TUint8* Buffer(); - TBool SetPause(TBool aPause); - #ifdef DODUMP - void Dump(const TDesC8& aBuf) {iDump.Dump(aBuf);} - #endif - private: - CEpocAudio(TInt aBufferSize); - void Complete(TInt aState, TInt aError); - TPtrC8 Data(); - void ConstructL(TInt aFill); - private: - TInt iBufferSize; - CStreamPlayer* iPlayer; - TInt iBufferRate; - TInt iRate; - TInt iChannels; - TUint32 iType; - TInt iPosition; - TThreadId iTid; - TUint8* iAudioPtr; - TUint8* iBuffer; - // TTimeIntervalMicroSeconds iStart; - TTime iStart; - TInt iTune; - CSimpleWait* iWait; - #ifdef DODUMP - TDump iDump; - #endif - }; +{ + public: + static void* NewL(TInt BufferSize, TInt aFill); + inline static CEpocAudio& Current(SDL_AudioDevice* thisdevice); + + static void Free(SDL_AudioDevice* thisdevice); + + void Wait(); + void Play(); + void ThreadInitL(TAny* aDevice); + void Open(TInt iRate, TInt iChannels, TUint32 aType, TInt aBytes); + ~CEpocAudio(); + TUint8* Buffer(); + TBool SetPause(TBool aPause); + + private: + CEpocAudio(TInt aBufferSize); + void Complete(TInt aState, TInt aError); + TPtrC8 Data(); + void ConstructL(TInt aFill); + TInt iBufferSize; + CStreamPlayer* iPlayer; + TInt iBufferRate; + TInt iRate; + TInt iChannels; + TUint32 iType; + TInt iPosition; + TThreadId iTid; + TUint8* iAudioPtr; + TUint8* iBuffer; + TTime iStart; + TInt iTune; + CSimpleWait* iWait; +}; inline CEpocAudio& CEpocAudio::Current(SDL_AudioDevice* thisdevice) - { +{ return *static_cast((void*)thisdevice->hidden); - } - -/* +} -TBool EndSc(TAny*) - { - CActiveScheduler::Stop(); - } - -LOCAL_C void CleanScL() - { - CIdle* d = CIdle::NewLC(CActive:::EPriorityIdle); - d->Start(TCallBack(EndSc)); - CActiveScheduler::Start(); - - } -*/ - void CEpocAudio::Free(SDL_AudioDevice* thisdevice) +{ + CEpocAudio* ea = static_cast((void*)thisdevice->hidden); + if(ea) { - CEpocAudio* ea = static_cast((void*)thisdevice->hidden); - if(ea) - { ASSERT(ea->iTid == RThread().Id()); - delete ea; - thisdevice->hidden = NULL; - - CActiveScheduler* as = CActiveScheduler::Current(); - ASSERT(as->StackDepth() == 0); - delete as; - CActiveScheduler::Install(NULL); - } - ASSERT(thisdevice->hidden == NULL); + delete ea; + thisdevice->hidden = NULL; + + CActiveScheduler* as = CActiveScheduler::Current(); + ASSERT(as->StackDepth() == 0); + delete as; + CActiveScheduler::Install(NULL); } - + ASSERT(thisdevice->hidden == NULL); +} + CEpocAudio::CEpocAudio(TInt aBufferSize) : iBufferSize(aBufferSize), iPosition(-1) - { - } +{ +} void* CEpocAudio::NewL(TInt aBufferSize, TInt aFill) - { +{ CEpocAudio* eAudioLib = new (ELeave) CEpocAudio(aBufferSize); CleanupStack::PushL(eAudioLib); eAudioLib->ConstructL(aFill); CleanupStack::Pop(); return eAudioLib; - } - +} + void CEpocAudio::ConstructL(TInt aFill) - { +{ iBuffer = (TUint8*) User::AllocL(KAudioBuffers * iBufferSize); memset(iBuffer, aFill, KAudioBuffers * iBufferSize); iAudioPtr = iBuffer; - } +} TBool CEpocAudio::SetPause(TBool aPause) - { +{ if(aPause && iPosition >= 0) - { + { iPosition = -1; if(iPlayer != NULL) iPlayer->Stop(); - } + } if(!aPause && iPosition < 0) - { + { iPosition = 0; if(iPlayer != NULL) iPlayer->Start(); - } - return iPosition < 0; } - + return iPosition < 0; +} + void CEpocAudio::ThreadInitL(TAny* aDevice) - { +{ iTid = RThread().Id(); CActiveScheduler* as = new (ELeave) CActiveScheduler(); - CActiveScheduler::Install(as); - - EpocSdlEnv::AppendCleanupItem(TSdlCleanupItem((TSdlCleanupOperation)EPOC_CloseAudio, aDevice)); - - iWait = CSimpleWait::NewL(); - - iPlayer = new (ELeave) CStreamPlayer(*this, *this); - iPlayer->ConstructL(); - iPlayer->OpenStream(iRate, iChannels, iType); - - #ifdef DODUMP - User::LeaveIfError(iDump.Open()); - #endif - } - - - + CActiveScheduler::Install(as); + + EpocSdlEnv::AppendCleanupItem(TSdlCleanupItem((TSdlCleanupOperation)EPOC_CloseAudio, aDevice)); + + iWait = CSimpleWait::NewL(); + + iPlayer = new (ELeave) CStreamPlayer(*this, *this); + iPlayer->ConstructL(); + iPlayer->OpenStream(iRate, iChannels, iType); +} + TUint8* CEpocAudio::Buffer() - { +{ iStart.UniversalTime(); -// iStart = iPlayer->Position(); return iAudioPtr; +} - } - CEpocAudio::~CEpocAudio() - { +{ if(iWait != NULL) iWait->Cancel(); delete iWait; @@ -321,122 +233,93 @@ CEpocAudio::~CEpocAudio() iPlayer->Close(); delete iPlayer; delete iBuffer; - } - +} + void CEpocAudio::Complete(TInt aState, TInt aError) - { +{ if(aState == MStreamObs::EClose) - { - } + { + } if(iPlayer->Closed()) return; switch(aError) - { + { case KErrUnderflow: case KErrInUse: iPlayer->Start(); break; case KErrAbort: iPlayer->Open(); - } } - +} -void sos_adump(SDL_AudioDevice* thisdevice, void* data, int len) - { -#ifdef DODUMP - const TPtrC8 buf((TUint8*)data, len); - CEpocAudio::Current(thisdevice).Dump(buf); -#endif - } const TInt KClip(256); - + TPtrC8 CEpocAudio::Data() - { +{ if(iPosition < 0) return KNullDesC8(); - + TPtrC8 data(iAudioPtr + iPosition, KClip); - -#ifdef DODUMP - iDump.Dump(data); -#endif - + iPosition += KClip; if(iPosition >= iBufferSize) - { - -/* if(iAudioPtr == iBuffer) - iAudioPtr = iBuffer + iBufferSize; - else - iAudioPtr = iBuffer; -*/ + { iAudioPtr += iBufferSize; - + if((iAudioPtr - iBuffer) >= KAudioBuffers * iBufferSize) iAudioPtr = iBuffer; - + iPosition = -1; if(iWait->IsActive()) - { + { iWait->Cancel(); CActiveScheduler::Stop(); - } } - return data; } - - + return data; +} - void CEpocAudio::Play() - { +{ iPosition = 0; - } +} void CEpocAudio::Wait() +{ + if(iPosition >= 0) { - if(iPosition >= 0 /*&& iPlayer->Playing()*/) - { const TInt64 bufMs = TInt64(iBufferSize - KClip) * TInt64(1000000); const TInt64 specTime = bufMs / TInt64(iRate * iChannels * 2); iWait->After(specTime); - + CActiveScheduler::Start(); TTime end; end.UniversalTime(); const TTimeIntervalMicroSeconds delta = end.MicroSecondsFrom(iStart); - - -// const TTimeIntervalMicroSeconds end = iPlayer->Position(); - - - - + const TInt diff = specTime - delta.Int64(); - + if(diff > 0 && diff < 200000) - { + { User::After(diff); - } - } - else - { - User::After(10000); -// iWait->Wait(10000); //just give some time... - } + } - -void CEpocAudio::Open(TInt aRate, TInt aChannels, TUint32 aType, TInt aBytes) + else { + User::After(10000); + } +} + +void CEpocAudio::Open(TInt aRate, TInt aChannels, TUint32 aType, TInt aBytes) +{ iRate = aRate; iChannels = aChannels; iType = aType; - iBufferRate = iRate * iChannels * aBytes; //1/x - } - + iBufferRate = iRate * iChannels * aBytes; //1/x +} /* Audio driver bootstrap functions */ @@ -456,17 +339,15 @@ static SDL_AudioDevice *Audio_CreateDevice(int /*devindex*/) thisdevice = (SDL_AudioDevice *)malloc(sizeof(SDL_AudioDevice)); if ( thisdevice ) { memset(thisdevice, 0, (sizeof *thisdevice)); - thisdevice->hidden = NULL; /*(struct SDL_PrivateAudioData *) - malloc((sizeof thisdevice->hidden)); */ + thisdevice->hidden = NULL; } - if ( (thisdevice == NULL) /*|| (thisdevice->hidden == NULL) */) { + if ( (thisdevice == NULL) ) { SDL_OutOfMemory(); if ( thisdevice ) { free(thisdevice); } return(0); } -// memset(thisdevice->hidden, 0, (sizeof *thisdevice->hidden)); /* Set the function pointers */ thisdevice->OpenAudio = EPOC_OpenAudio; @@ -474,7 +355,7 @@ static SDL_AudioDevice *Audio_CreateDevice(int /*devindex*/) thisdevice->PlayAudio = EPOC_PlayAudio; thisdevice->GetAudioBuf = EPOC_GetAudioBuf; thisdevice->CloseAudio = EPOC_CloseAudio; - thisdevice->ThreadInit = EPOC_ThreadInit; + thisdevice->ThreadInit = EPOC_ThreadInit; thisdevice->free = Audio_DeleteDevice; return thisdevice; @@ -482,10 +363,9 @@ static SDL_AudioDevice *Audio_CreateDevice(int /*devindex*/) static void Audio_DeleteDevice(SDL_AudioDevice *device) - { - //free(device->hidden); +{ free(device); - } +} static int Audio_Available(void) { @@ -495,14 +375,11 @@ static int Audio_Available(void) static int EPOC_OpenAudio(SDL_AudioDevice *thisdevice, SDL_AudioSpec *spec) { - SDL_TRACE("SDL:EPOC_OpenAudio"); - - TUint32 type = KMMFFourCCCodePCM16; TInt bytes = 2; - + switch(spec->format) - { + { case AUDIO_U16LSB: type = KMMFFourCCCodePCMU16; break; @@ -520,95 +397,57 @@ static int EPOC_OpenAudio(SDL_AudioDevice *thisdevice, SDL_AudioSpec *spec) case AUDIO_S8: default: spec->format = AUDIO_S16LSB; - }; - + }; - if(spec->channels > 2) spec->channels = 2; - + spec->freq = CStreamPlayer::ClosestSupportedRate(spec->freq); - /* Allocate mixing buffer */ const TInt buflen = spec->size;// * bytes * spec->channels; -// audiobuf = NULL; - - TRAPD(err, thisdevice->hidden = static_cast(CEpocAudio::NewL(buflen, spec->silence))); - if(err != KErrNone) - return -1; + + TRAPD(err, thisdevice->hidden = static_cast(CEpocAudio::NewL(buflen, spec->silence))); + if(err != KErrNone) + return -1; CEpocAudio::Current(thisdevice).Open(spec->freq, spec->channels, type, bytes); - + CEpocAudio::Current(thisdevice).SetPause(ETrue); - - // isSDLAudioPaused = 1; - thisdevice->enabled = 0; /* enable only after audio engine has been initialized!*/ + thisdevice->enabled = 0; /* enable only after audio engine has been initialized!*/ /* We're ready to rock and roll. :-) */ return(0); } - static void EPOC_CloseAudio(SDL_AudioDevice* thisdevice) - { -#ifdef DEBUG_AUDIO - SDL_TRACE("Close audio\n"); -#endif - +{ CEpocAudio::Free(thisdevice); - } - +} static void EPOC_ThreadInit(SDL_AudioDevice *thisdevice) - { - SDL_TRACE("SDL:EPOC_ThreadInit"); - CEpocAudio::Current(thisdevice).ThreadInitL(thisdevice); - RThread().SetPriority(EPriorityMore); - thisdevice->enabled = 1; - } +{ + CEpocAudio::Current(thisdevice).ThreadInitL(thisdevice); + RThread().SetPriority(EPriorityMore); + thisdevice->enabled = 1; +} /* This function waits until it is possible to write a full sound buffer */ static void EPOC_WaitAudio(SDL_AudioDevice* thisdevice) { -#ifdef DEBUG_AUDIO - SDL_TRACE1("wait %d audio\n", CEpocAudio::AudioLib().StreamPlayer(KSfxChannel).SyncTime()); - TInt tics = User::TickCount(); -#endif - CEpocAudio::Current(thisdevice).Wait(); - -#ifdef DEBUG_AUDIO - TInt ntics = User::TickCount() - tics; - SDL_TRACE1("audio waited %d\n", ntics); - SDL_TRACE1("audio at %d\n", tics); -#endif } - - static void EPOC_PlayAudio(SDL_AudioDevice* thisdevice) - { - if(CEpocAudio::Current(thisdevice).SetPause(SDL_GetAudioStatus() == SDL_AUDIO_PAUSED)) - SDL_Delay(500); //hold on the busy loop - else - CEpocAudio::Current(thisdevice).Play(); - -#ifdef DEBUG_AUDIO - SDL_TRACE("buffer has audio data\n"); -#endif - - -#ifdef DEBUG_AUDIO - SDL_TRACE1("Wrote %d bytes of audio data\n", buflen); -#endif +{ + if(CEpocAudio::Current(thisdevice).SetPause(SDL_GetAudioStatus() == SDL_AUDIO_PAUSED)) + SDL_Delay(500); //hold on the busy loop + else + CEpocAudio::Current(thisdevice).Play(); } static Uint8 *EPOC_GetAudioBuf(SDL_AudioDevice* thisdevice) - { +{ return CEpocAudio::Current(thisdevice).Buffer(); - } - - - +} diff --git a/src/audio/symbian/SDL_epocaudio.h b/src/audio/symbian/SDL_epocaudio.h dissimilarity index 88% index d08c4c2..61dd608 100644 --- a/src/audio/symbian/SDL_epocaudio.h +++ b/src/audio/symbian/SDL_epocaudio.h @@ -1,37 +1,30 @@ -/* - SDL - Simple DirectMedia Layer - Copyright (C) 1997, 1998, 1999, 2000, 2001 Sam Lantinga - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with this library; if not, write to the Free - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - - Sam Lantinga - slouken@devolution.com -*/ - - -#ifdef SAVE_RCSID -static char rcsid = - "@(#) $Id: SDL_epocaudio.h,v 1.1.2.2 2001/02/10 07:20:03 hercules Exp $"; -#endif - -#ifndef _SDL_EPOCAUDIO_H -#define _SDL_EPOCAUDIO_H - -extern "C" { -#include "SDL_sysaudio.h" -} - - -#endif /* _SDL_EPOCAUDIO_H */ +/* + SDL - Simple DirectMedia Layer + Copyright (C) 1997, 1998, 1999, 2000, 2001 Sam Lantinga + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; if not, write to the Free + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + Sam Lantinga + slouken@devolution.com + */ + +#ifndef _SDL_EPOCAUDIO_H +#define _SDL_EPOCAUDIO_H + +extern "C" { +#include "SDL_sysaudio.h" +} + +#endif /* _SDL_EPOCAUDIO_H */ diff --git a/src/audio/symbian/streamplayer.cpp b/src/audio/symbian/streamplayer.cpp index dd733a1..a7a30ca 100644 --- a/src/audio/symbian/streamplayer.cpp +++ b/src/audio/symbian/streamplayer.cpp @@ -1,279 +1,258 @@ #include "streamplayer.h" -#include - - +#include const TInt KMaxVolume(256); LOCAL_C TInt GetSampleRate(TInt aRate) - { - switch(aRate) - { - case 8000: return TMdaAudioDataSettings::ESampleRate8000Hz; - case 11025: return TMdaAudioDataSettings::ESampleRate11025Hz; - case 12000: return TMdaAudioDataSettings::ESampleRate12000Hz; - case 16000: return TMdaAudioDataSettings::ESampleRate16000Hz; - case 22050: return TMdaAudioDataSettings::ESampleRate22050Hz; - case 24000: return TMdaAudioDataSettings::ESampleRate24000Hz; - case 32000: return TMdaAudioDataSettings::ESampleRate32000Hz; - case 44100: return TMdaAudioDataSettings::ESampleRate44100Hz; - case 48000: return TMdaAudioDataSettings::ESampleRate48000Hz; - case 96000: return TMdaAudioDataSettings::ESampleRate96000Hz; - case 64000: return TMdaAudioDataSettings::ESampleRate64000Hz; - } - return KErrNotFound; - } +{ + switch(aRate) + { + case 8000: return TMdaAudioDataSettings::ESampleRate8000Hz; + case 11025: return TMdaAudioDataSettings::ESampleRate11025Hz; + case 12000: return TMdaAudioDataSettings::ESampleRate12000Hz; + case 16000: return TMdaAudioDataSettings::ESampleRate16000Hz; + case 22050: return TMdaAudioDataSettings::ESampleRate22050Hz; + case 24000: return TMdaAudioDataSettings::ESampleRate24000Hz; + case 32000: return TMdaAudioDataSettings::ESampleRate32000Hz; + case 44100: return TMdaAudioDataSettings::ESampleRate44100Hz; + case 48000: return TMdaAudioDataSettings::ESampleRate48000Hz; + case 96000: return TMdaAudioDataSettings::ESampleRate96000Hz; + case 64000: return TMdaAudioDataSettings::ESampleRate64000Hz; + } + return KErrNotFound; +} LOCAL_C TInt GetChannels(TInt aChannels) - { - switch(aChannels) - { - case 1: return TMdaAudioDataSettings::EChannelsMono; - case 2: return TMdaAudioDataSettings::EChannelsStereo; - } - return KErrNotFound; - } - -TInt CStreamPlayer::ClosestSupportedRate(TInt aRate) +{ + switch(aChannels) { + case 1: return TMdaAudioDataSettings::EChannelsMono; + case 2: return TMdaAudioDataSettings::EChannelsStereo; + } + return KErrNotFound; +} + +TInt CStreamPlayer::ClosestSupportedRate(TInt aRate) +{ if(aRate > 96000) return 96000; TInt rate = aRate; while(GetSampleRate(rate) == KErrNotFound) - { + { ++rate; - } - return rate; } + return rate; +} CStreamPlayer::CStreamPlayer(MStreamProvider& aProvider, MStreamObs& aObs) : - iProvider(aProvider), iObs(aObs), iVolume(KMaxVolume) - { - } - + iProvider(aProvider), iObs(aObs), iVolume(KMaxVolume) +{ +} + CStreamPlayer::~CStreamPlayer() - { +{ iState |= EDied; if(iState & EInited) Close(); User::After(100000); //wait buffer to be flushed ASSERT(iPtr.Length() == 0); delete iStream; - } - - +} + + void CStreamPlayer::ConstructL() - { +{ iStream = CMdaAudioOutputStream::NewL(*this, EMdaPriorityMax); iSilence.SetMax(); iSilence.FillZ(); - } - +} + TInt CStreamPlayer::OpenStream(TInt aRate, TInt aChannels, TUint32 aType) - { +{ Close(); - + iType = aType; - + iRate = GetSampleRate(aRate); if(iRate == KErrNotFound) return KErrNotSupported; - + iChannels = GetChannels(aChannels); if(iChannels == KErrNotFound) return KErrNotSupported; - + Open(); - - return KErrNone; - } + + return KErrNone; +} TInt CStreamPlayer::MaxVolume() const - { +{ return KMaxVolume; - } +} void CStreamPlayer::SetVolume(TInt aNew) - { - - const TInt maxi = MaxVolume(); - if(aNew > maxi) +{ + + const TInt maxi = MaxVolume(); + if(aNew > maxi) + return; + if(aNew < 0) return; - if(aNew < 0) - return; - - iVolume = aNew; - - iState |= EVolumeChange; - } - - TInt CStreamPlayer::Volume() const - { + + iVolume = aNew; + + iState |= EVolumeChange; +} + +TInt CStreamPlayer::Volume() const +{ return iVolume; - } +} void CStreamPlayer::Open() - { +{ TMdaAudioDataSettings audioSettings; audioSettings.Query(); - audioSettings.iCaps = TMdaAudioDataSettings::ERealTime | - TMdaAudioDataSettings::ESampleRateFixed; - audioSettings.iSampleRate = iRate; - audioSettings.iChannels = iChannels; + audioSettings.iCaps = TMdaAudioDataSettings::ERealTime | + TMdaAudioDataSettings::ESampleRateFixed; + audioSettings.iSampleRate = iRate; + audioSettings.iChannels = iChannels; audioSettings.iFlags = TMdaAudioDataSettings::ENoNetworkRouting; audioSettings.iVolume = 0; - + iState &= ~EStopped; - iStream->Open(&audioSettings); - } - + iStream->Open(&audioSettings); +} + void CStreamPlayer::Stop() - { +{ if(iState & (EStarted | EInited)) - { + { Close(); iState |= EStopped; - } } - +} + void CStreamPlayer::Start() - { +{ if(iPtr.Length() == 0) - { + { iState |= EStarted; if(iState & EInited) - { + { Request(); - } + } else if(iState & EStopped) - { + { Open(); - } } } +} void CStreamPlayer::Close() - { +{ iState &= ~EInited; iStream->Stop(); iState &= ~EStarted; - } - +} + void CStreamPlayer::Request() - { +{ if(iState & EInited) - { + { iPtr.Set(KNullDesC8); - + if(iState & EVolumeChange) - { - const TReal newVol = iVolume; - const TReal newMax = MaxVolume(); - const TInt maxVol = iStream->MaxVolume(); - const TReal max = static_cast(maxVol); - const TReal newvolume = (newVol * max) / newMax; - const TInt vol = static_cast(newvolume); - iStream->SetVolume(vol); + { + const TReal newVol = iVolume; + const TReal newMax = MaxVolume(); + const TInt maxVol = iStream->MaxVolume(); + const TReal max = static_cast(maxVol); + const TReal newvolume = (newVol * max) / newMax; + const TInt vol = static_cast(newvolume); + iStream->SetVolume(vol); iState &= ~EVolumeChange; - } - + } + if(iState & EStarted) - { - iPtr.Set(iProvider.Data()); - } + { + iPtr.Set(iProvider.Data()); + } if(iPtr.Length() == 0) - { + { iPtr.Set(iSilence); - } + } TRAPD(err, iStream->WriteL(iPtr)); if(err != KErrNone) - { + { iObs.Complete(MStreamObs::EWrite, err); - } - /* else - { - iProvider.Written(iPtr.Length()); - }*/ } } - +} + void CStreamPlayer::SetCapsL() - { +{ iStream->SetDataTypeL(iType); iStream->SetAudioPropertiesL(iRate, iChannels); - } +} void CStreamPlayer::MaoscOpenComplete(TInt aError) - { +{ if(aError == KErrNone) - { + { TRAPD(err, SetCapsL()); - if(err == KErrNone) - { - iStream->SetPriority(EPriorityNormal, EMdaPriorityPreferenceTime); - iState |= EInited; - - - SetVolume(Volume()); - - if(iState & EStarted) - { - Request(); - } - + if(err == KErrNone) + { + iStream->SetPriority(EPriorityNormal, EMdaPriorityPreferenceTime); + iState |= EInited; + + + SetVolume(Volume()); + + if(iState & EStarted) + { + Request(); } - aError = err; + } + aError = err; + } if(!(iState & EDied)) iObs.Complete(MStreamObs::EInit, aError); - } - +} + void CStreamPlayer::MaoscBufferCopied(TInt aError, const TDesC8& /*aBuffer*/) - { +{ iPtr.Set(KNullDesC8); if(aError == KErrNone) - { + { if(iState & EInited) Request(); else iStream->Stop(); - } + } else if(!(iState & EDied)) iObs.Complete(MStreamObs::EPlay, aError); - } - +} + void CStreamPlayer::MaoscPlayComplete(TInt aError) - { +{ iPtr.Set(KNullDesC8); iState &= ~EStarted; if(!(iState & EDied)) iObs.Complete(MStreamObs::EClose, aError); - } - +} + TBool CStreamPlayer::Playing() const - { +{ return (iState & EInited) && (iState & EStarted); - } +} TBool CStreamPlayer::Closed() const - { +{ return !(iState & EInited) && !(iState & EDied); - } - - /* -void CStreamPlayer::Request() - { - SetActive(); - TRequestStatus* s = &iStatus; - User::RequestComplete(s, KErrNone); - } - // iTimer.After(0); - */ - - - - - +} diff --git a/src/audio/symbian/streamplayer.h b/src/audio/symbian/streamplayer.h index bfdba92..4083fec 100644 --- a/src/audio/symbian/streamplayer.h +++ b/src/audio/symbian/streamplayer.h @@ -6,84 +6,79 @@ const TInt KSilenceBuffer = 256; class MStreamObs - { - public: - enum - { - EInit, - EPlay, - EWrite, - EClose, - }; - virtual void Complete(TInt aState, TInt aError) = 0; - }; +{ + public: + enum + { + EInit, + EPlay, + EWrite, + EClose, + }; + virtual void Complete(TInt aState, TInt aError) = 0; +}; class MStreamProvider - { +{ public: virtual TPtrC8 Data() = 0; - }; +}; NONSHARABLE_CLASS(CStreamPlayer) : public CBase, public MMdaAudioOutputStreamCallback - { +{ public: CStreamPlayer(MStreamProvider& aProvider, MStreamObs& aObs); ~CStreamPlayer(); void ConstructL(); - + static TInt ClosestSupportedRate(TInt aRate); - + TInt OpenStream(TInt aRate, TInt aChannels, TUint32 aType = KMMFFourCCCodePCM16); - + void SetVolume(TInt aNew); TInt Volume() const; TInt MaxVolume() const; - + void Stop(); void Start(); void Open(); void Close(); - + TBool Playing() const; TBool Closed() const; - + private: void MaoscOpenComplete(TInt aError) ; void MaoscBufferCopied(TInt aError, const TDesC8& aBuffer); void MaoscPlayComplete(TInt aError); - - private: + void Request(); void SetCapsL(); - private: MStreamProvider& iProvider; MStreamObs& iObs; TInt iVolume; - + CMdaAudioOutputStream* iStream; - + TInt iRate; TInt iChannels; TUint32 iType; - + enum - { - ENone = 0, - EInited = 0x1, - EStarted = 0x2, - EStopped = 0x4, - EVolumeChange = 0x8, - EDied = 0x10 - }; - + { + ENone = 0, + EInited = 0x1, + EStarted = 0x2, + EStopped = 0x4, + EVolumeChange = 0x8, + EDied = 0x10 + }; + TInt iState; TBuf8 iSilence; TPtrC8 iPtr; - - }; - +}; #endif - diff --git a/src/main/symbian/SDL_env.cpp b/src/main/symbian/SDL_env.cpp index c791736..be43c4c 100644 --- a/src/main/symbian/SDL_env.cpp +++ b/src/main/symbian/SDL_env.cpp @@ -1,8 +1,7 @@ #include - void* SDL_LoadObject(const char *sofile) - { +{ RLibrary* lib = new RLibrary(); if(lib == NULL) return NULL; @@ -12,42 +11,25 @@ void* SDL_LoadObject(const char *sofile) return lib; delete lib; return NULL; - } +} + - -void* SDL_LoadFunction(void *handle, const char *name) - { +void* SDL_LoadFunction(void *handle, const char *name) +{ TLex8 v((const TUint8*)(name)); TInt ord; - + if(KErrNone != v.Val(ord)) return NULL; - + const RLibrary* lib = reinterpret_cast(handle); TLibraryFunction f = lib->Lookup(ord); return (void*)(f); -/* - int i = 0; - TPtrC8 functionName((const TUint8*)(name)); - for(;;) - { - const TInt ord = _Ordinals[i].iOrd; - if(ord < 0) - return NULL; - if(functionName.Compare( - TPtrC8((const TUint8*)(_Ordinals[i].iName))) == 0) - { - const RLibrary* lib = reinterpret_cast(handle); - TLibraryFunction f = lib->Lookup(ord); - return (void*)(f); - } - ++i; - }*/ - } - -void SDL_UnloadObject(void *handle) - { +} + +void SDL_UnloadObject(void *handle) +{ RLibrary* lib = reinterpret_cast(handle); lib->Close(); delete lib; - } +} diff --git a/src/main/symbian/SDL_main.cpp b/src/main/symbian/SDL_main.cpp dissimilarity index 62% index 65b5495..a7f73aa 100644 --- a/src/main/symbian/SDL_main.cpp +++ b/src/main/symbian/SDL_main.cpp @@ -1,1235 +1,1111 @@ -/* - SDL_Main.cpp - Symbian OS services for SDL - - Markus Mertama -*/ - - -#include "epoc_sdl.h" - -#include"sdlepocapi.h" -#include -#include -#include -#include - -#include "vectorbuffer.h" -#include -#include -#include -#include "SDL_epocevents_c.h" -#include "SDL_keysym.h" -#include "dsa.h" -#include "SDL_loadso.h" - -//Markus Mertama - - -extern SDLKey* KeyMap(); -extern void ResetKeyMap(); - -class CCurrentAppUi; - -//const TUid KSDLUid = { 0xF01F3D69 }; - -class CEikonEnv; -class CSdlAppServ; -class CEventQueue; - - -NONSHARABLE_CLASS(EpocSdlEnvData) - { - public: - void Free(); - void Delete(); - CEventQueue* iEventQueue; - TMainFunc iMain; - TInt iEpocEnvFlags; - int iArgc; - char** iArgv; - CDsa* iDsa; - CSdlAppServ* iAppSrv; - TThreadId iId; - CArrayFix* iCleanupItems; - CEikAppUi* iAppUi; - CSDL* iSdl; - CIdle* iCaller; - TRequestStatus* iCallerStatus; - }; - - -EpocSdlEnvData* gEpocEnv; - - - - -NONSHARABLE_CLASS(EnvUtils) - { - public: - static inline TBool IsOwnThreaded(); - static void DisableKeyBlocking(); - static TBool Rendezvous(RThread& aThread, TRequestStatus& aStatus); - static void RunSingleThread(); - }; - -inline TBool EnvUtils::IsOwnThreaded() - { - return gEpocEnv->iEpocEnvFlags & CSDL::EOwnThread; - } - - -/*LOCAL_C TInt DoNothing(TAny*) - { - return 0; - } -*/ -void EnvUtils::RunSingleThread() - { - if(!EnvUtils::IsOwnThreaded()) - { - TInt count = RThread().RequestCount(); - if(count > 0) - { - TInt err; - if(CActiveScheduler::RunIfReady(err, CActive::EPriorityIdle)) - { - CActiveScheduler::Current()->WaitForAnyRequest(); - } - } - /* else - { - gEpocEnv->iCaller->Start(TCallBack(DoNothing)); - } */ - } - } - -TInt Panic(TInt aErr, TInt aLine) - { - TBuf<64> b; - b.Format(_L("Main at %d"), aLine); - User::Panic(b, aErr); - return 0; - } - - -NONSHARABLE_CLASS(CCurrentAppUi) : public CAknAppUi - { - public: - static CCurrentAppUi* Cast(CEikAppUi* aUi); - void DisableKeyBlocking(); - }; - - -CCurrentAppUi* CCurrentAppUi::Cast(CEikAppUi* aUi) - { - return static_cast(aUi); - } - -void CCurrentAppUi::DisableKeyBlocking() - { - SetKeyBlockMode(ENoKeyBlock); - } - - -class CEventQueue : public CBase, public MEventQueue - { - public: - void ConstructL(); - ~CEventQueue(); - public: - TInt Append(const TWsEvent& aEvent); - const TWsEvent& Shift(); - void Lock(); - void Unlock(); - TBool HasData(); - private: - TVector iVector; - RCriticalSection iCS; - }; - -void CEventQueue::ConstructL() - { - if(EnvUtils::IsOwnThreaded()) - User::LeaveIfError(iCS.CreateLocal()); - } - -CEventQueue::~CEventQueue() - { - iCS.Close(); - } - -TInt CEventQueue::Append(const TWsEvent& aEvent) - { - Lock(); - const TInt err = iVector.Append(aEvent); - Unlock(); - return err; - } - - -TBool CEventQueue::HasData() - { - EnvUtils::RunSingleThread(); - return iVector.Size() > 0; - } - - - - -void CEventQueue::Lock() - { - if(EnvUtils::IsOwnThreaded()) - iCS.Wait(); - } - -void CEventQueue::Unlock() - { - if(EnvUtils::IsOwnThreaded()) - iCS.Signal(); - } - -const TWsEvent& CEventQueue::Shift() - { - const TWsEvent& event = iVector.Shift(); - return event; - } - - -TSdlCleanupItem::TSdlCleanupItem(TSdlCleanupOperation aOperation, TAny* aItem) : -iOperation(aOperation), iItem(aItem), iThread(RThread().Id()) - { - } - - -#define MAINFUNC(x) EXPORT_C TMainFunc::TMainFunc(mainfunc##x aFunc){Mem::FillZ(iMainFunc, sizeof(iMainFunc)); iMainFunc[x - 1] = (void*) aFunc;} - -MAINFUNC(1) -MAINFUNC(2) -MAINFUNC(3) -MAINFUNC(4) -MAINFUNC(5) -MAINFUNC(6) - -EXPORT_C TMainFunc::TMainFunc() - { - Mem::FillZ(iMainFunc, sizeof(iMainFunc)); - } - - -const void* TMainFunc::operator[](TInt aIndex) const - { - return iMainFunc[aIndex]; - } - - -NONSHARABLE_CLASS(CSdlAppServ) : public CActive - { - public: - enum - { - EAppSrvNoop = CDsa::ELastDsaRequest, - EAppSrvWindowWidth, - EAppSrvWindowHeight, - EAppSrvWindowDisplayMode, - EAppSrvWindowPointerCursorMode, - EAppSrvDsaStatus, - EAppSrvStopThread, - EAppSrvWaitDsa - }; - CSdlAppServ(); - void ConstructL(); - ~CSdlAppServ(); - TInt Request(TInt aService); - TInt RequestValue(TInt aService); - void Init(); - void PanicMain(TInt aReason); - void PanicMain(const TDesC& aInfo, TInt aReason); - void SetObserver(MSDLObserver* aObserver); - TInt ObserverEvent(TInt aEvent, TInt aParam); - void SetParam(TInt aParam); - void HandleObserverValue(TInt aService, TInt aReturnValue, TBool aMainThread); - MSDLObserver* Observer(); - private: - void RunL(); - void DoCancel(); - private: - const TThreadId iMainId; - RThread iAppThread; - TInt iService; - TInt iReturnValue; - RSemaphore iSema; - MSDLObserver* iObserver; - TRequestStatus* iStatusPtr; - }; - -CSdlAppServ::CSdlAppServ() : CActive(CActive::EPriorityHigh), iMainId(RThread().Id()) - { - } - - - -MSDLObserver* CSdlAppServ::Observer() - { - return iObserver; - } - - -void CSdlAppServ::SetObserver(MSDLObserver* aObserver) - { - iObserver = aObserver; - } - -TInt CSdlAppServ::ObserverEvent(TInt aEvent, TInt aParam) - { - if(iObserver != NULL) - { - if(RThread().Id() == gEpocEnv->iId && EnvUtils::IsOwnThreaded()) - { - return iObserver->SdlThreadEvent(aEvent, aParam); - } - else if(RThread().Id() == iMainId) - { - return iObserver->SdlEvent(aEvent, aParam); - } - PANIC(KErrNotSupported); - } - return 0; - } - -void CSdlAppServ::PanicMain(TInt aReason) - { - iAppThread.Panic(RThread().Name(), aReason); - } - -void CSdlAppServ::PanicMain(const TDesC& aInfo, TInt aReason) - { - iAppThread.Panic(aInfo, aReason); - } - -void CSdlAppServ::ConstructL() - { - CActiveScheduler::Add(this); - if(EnvUtils::IsOwnThreaded()) - User::LeaveIfError(iSema.CreateLocal(1)); - iStatus = KRequestPending; - iStatusPtr = &iStatus; - SetActive(); - } - - CSdlAppServ::~CSdlAppServ() - { - Cancel(); - if(iSema.Handle() != NULL) - iSema.Signal(); - iSema.Close(); - iAppThread.Close(); - } - -TInt CSdlAppServ::Request(TInt aService) - { - if(EnvUtils::IsOwnThreaded()) - { - if(RThread().Id() == iAppThread.Id()) - return KErrBadHandle; - iSema.Wait(); - } - EnvUtils::RunSingleThread(); - iService = aService; - iAppThread.RequestComplete(iStatusPtr, KErrNone); - return KErrNone; - } - -TInt CSdlAppServ::RequestValue(TInt aService) - { - Request(aService); - Request(EAppSrvNoop); - return iReturnValue; - } - -void CSdlAppServ::Init() - { - PANIC_IF_ERROR(iAppThread.Open(iMainId)); - } - -void CSdlAppServ::SetParam(TInt aParam) - { - iReturnValue = aParam; - } - -void CSdlAppServ::HandleObserverValue(TInt aService, TInt aReturnValue, TBool aMainThread) - { - if(iObserver != NULL && aMainThread) - { - switch(aService) - { - case MSDLObserver::EEventScreenSizeChanged: - if(aReturnValue == MSDLObserver::EScreenSizeChangedDefaultPalette) - EpocSdlEnv::LockPalette(EFalse); - break; - } - } - if(!aMainThread && aService == MSDLObserver::EEventSuspend) - { - if(iObserver == NULL || - (gEpocEnv->iDsa != NULL && gEpocEnv->iDsa->Stopped() && aReturnValue != MSDLObserver::ESuspendNoSuspend)) - { - EpocSdlEnv::Suspend(); - } - } - } - -void CSdlAppServ::RunL() - { - if(iStatus == KErrNone) - { - switch(iService) - { - case CSdlAppServ::EAppSrvWaitDsa: - EpocSdlEnv::SetWaitDsa(); - iReturnValue = EpocSdlEnv::IsDsaAvailable(); - break; - case CSdlAppServ::EAppSrvStopThread: - if(gEpocEnv->iDsa != NULL) - gEpocEnv->iDsa->SetSuspend(); - break; - case EpocSdlEnv::EDisableKeyBlocking: - EnvUtils::DisableKeyBlocking(); - break; - - case EAppSrvWindowPointerCursorMode: - iReturnValue = gEpocEnv->iDsa != NULL ? - gEpocEnv->iDsa->Session().PointerCursorMode() : KErrNotReady; - break; - case EAppSrvDsaStatus: - if(gEpocEnv->iDsa != NULL) - gEpocEnv->iDsa->Stop(); - iReturnValue = KErrNone; - break; - case CDsa::ERequestUpdate: - gEpocEnv->iDsa->UnlockHWSurfaceRequestComplete(); - break; - case EAppSrvNoop: - break; - case MSDLObserver::EEventResume: - case MSDLObserver::EEventSuspend: - case MSDLObserver::EEventScreenSizeChanged: - case MSDLObserver::EEventWindowReserved: - case MSDLObserver::EEventKeyMapInit: - case MSDLObserver::EEventWindowNotAvailable: - case MSDLObserver::EEventMainExit: - iReturnValue = ObserverEvent(iService, iReturnValue); - HandleObserverValue(iService, iReturnValue, ETrue); - break; - default: - PANIC(KErrNotSupported); - } - iStatus = KRequestPending; - iStatusPtr = &iStatus; - SetActive(); - } - if(EnvUtils::IsOwnThreaded()) - iSema.Signal(); - } - -void CSdlAppServ::DoCancel() - { - if(EnvUtils::IsOwnThreaded()) - iSema.Wait(); - TRequestStatus* s = &iStatus; - iAppThread.RequestComplete(s, KErrCancel); - } - - - -MEventQueue& EpocSdlEnv::EventQueue() - { - __ASSERT_DEBUG(gEpocEnv != NULL, PANIC(KErrNotReady)); - return *gEpocEnv->iEventQueue; - } - - -TBool EpocSdlEnv::Flags(TInt aFlag) - { - const TInt flag = gEpocEnv->iEpocEnvFlags & aFlag; - return flag == aFlag; - } - -TInt EpocSdlEnv::Argc() - { - __ASSERT_DEBUG(gEpocEnv != NULL, PANIC(KErrNotReady)); - return gEpocEnv->iArgc; - } - - -char** EpocSdlEnv::Argv() - { - __ASSERT_DEBUG(gEpocEnv != NULL, PANIC(KErrNotReady)); - return gEpocEnv->iArgv; - } - - -TBool EpocSdlEnv::IsDsaAvailable() - { - __ASSERT_DEBUG(gEpocEnv != NULL, PANIC(KErrNotReady)); - return gEpocEnv->iDsa != NULL && gEpocEnv->iDsa->IsDsaAvailable(); - } - - -void EpocSdlEnv::WaitDsaAvailable() - { - EpocSdlEnv::ObserverEvent(MSDLObserver::EEventWindowNotAvailable, 0); - gEpocEnv->iAppSrv->Request(CSdlAppServ::EAppSrvStopThread); - if(EpocSdlEnv::Flags(CSDL::EEnableFocusStop)) - { - EpocSdlEnv::ObserverEvent(MSDLObserver::EEventSuspend, 0); - } - } - -void EpocSdlEnv::Suspend() - { - if(gEpocEnv->iDsa != NULL && (gEpocEnv->iDsa->Stopped() || EpocSdlEnv::Flags(CSDL::EEnableFocusStop))) - { - gEpocEnv->iDsa->SetSuspend(); - if(EnvUtils::IsOwnThreaded()) - { - RThread().Suspend(); - EpocSdlEnv::ObserverEvent(MSDLObserver::EEventResume, 0); - } - } - } - -void EpocSdlEnv::SetWaitDsa() - { - if(!IsDsaAvailable()) - { - if(EnvUtils::IsOwnThreaded()) - { - RThread th; - th.Open(gEpocEnv->iId); - th.Suspend(); - th.Close(); - } - if(gEpocEnv->iDsa != NULL) - gEpocEnv->iDsa->SetSuspend(); - } - } - -void EpocSdlEnv::Resume() - { - if(gEpocEnv->iDsa != NULL) - { - gEpocEnv->iDsa->Resume(); - } - if(EnvUtils::IsOwnThreaded()) - { - RThread th; - th.Open(gEpocEnv->iId); - th.Resume(); - th.Close(); - } - const TInt value = gEpocEnv->iAppSrv->ObserverEvent(MSDLObserver::EEventResume, 0); - gEpocEnv->iAppSrv->HandleObserverValue(MSDLObserver::EEventResume, value, ETrue); - } - - -TInt EpocSdlEnv::AllocSwSurface(const TSize& aSize, TDisplayMode aMode) - { - return gEpocEnv->iDsa->AllocSurface(EFalse, aSize, aMode); - } - -TInt EpocSdlEnv::AllocHwSurface(const TSize& aSize, TDisplayMode aMode) - { - return gEpocEnv->iDsa->AllocSurface(ETrue, aSize, aMode); - } - - -void EpocSdlEnv::UnlockHwSurface() - { - gEpocEnv->iDsa->UnlockHwSurface(); - } - -TUint8* EpocSdlEnv::LockHwSurface() - { - return gEpocEnv->iDsa->LockHwSurface(); - } - - -void EpocSdlEnv::UpdateSwSurface() - { - gEpocEnv->iDsa->UpdateSwSurface(); - } - -TBool EpocSdlEnv::AddUpdateRect(TUint8* aAddress, const TRect& aUpdateRect, const TRect& aRect) - { - return gEpocEnv->iDsa->AddUpdateRect(aAddress, aUpdateRect, aRect); - } - -void EpocSdlEnv::Request(TInt aService) - { - __ASSERT_DEBUG(gEpocEnv != NULL, PANIC(KErrNotReady)); - gEpocEnv->iAppSrv->Request(aService); - } - - -TSize EpocSdlEnv::WindowSize(const TSize& aRequestedSize) - { - __ASSERT_DEBUG(gEpocEnv != NULL, PANIC(KErrNotReady)); - if(gEpocEnv->iDsa != NULL && EpocSdlEnv::Flags(CSDL::EAllowImageResize) && gEpocEnv->iDsa->WindowSize() != aRequestedSize) - { - TRAP_IGNORE(gEpocEnv->iDsa->CreateZoomerL(aRequestedSize)); - } - return gEpocEnv->iDsa == NULL ? TSize(0, 0) : gEpocEnv->iDsa->WindowSize(); - } - - TSize EpocSdlEnv::WindowSize() - { - __ASSERT_DEBUG(gEpocEnv != NULL, PANIC(KErrNotReady)); - return gEpocEnv->iDsa == NULL ? TSize(0, 0) : gEpocEnv->iDsa->WindowSize(); - } - -TDisplayMode EpocSdlEnv::DisplayMode() - { - return gEpocEnv->iDsa == NULL ? ENone : gEpocEnv->iDsa->DisplayMode(); - } - -TPointerCursorMode EpocSdlEnv::PointerMode() - { - return static_cast - (gEpocEnv->iAppSrv->RequestValue(CSdlAppServ::EAppSrvWindowPointerCursorMode)); - } - -TInt EpocSdlEnv::SetPalette(TInt aFirstcolor, TInt aColorCount, TUint32* aPalette) - { - return gEpocEnv->iDsa->SetPalette(aFirstcolor, aColorCount, aPalette); - } - -void EpocSdlEnv::PanicMain(TInt aErr) - { - gEpocEnv->iAppSrv->PanicMain(aErr); - } - - -TInt EpocSdlEnv::AppendCleanupItem(const TSdlCleanupItem& aItem) - { - TRAPD(err, gEpocEnv->iCleanupItems->AppendL(aItem)); - return err; - } - -void EpocSdlEnv::RemoveCleanupItem(TAny* aItem) - { - for(TInt i = 0; i < gEpocEnv->iCleanupItems->Count(); i++) - { - if(gEpocEnv->iCleanupItems->At(i).iItem == aItem) - gEpocEnv->iCleanupItems->Delete(i); - } - } - -void EpocSdlEnv::CleanupItems() - { - const TThreadId id = RThread().Id(); - TInt last = gEpocEnv->iCleanupItems->Count() - 1; - TInt i; - for(i = last; i >= 0 ; i--) - { - TSdlCleanupItem& item = gEpocEnv->iCleanupItems->At(i); - if(item.iThread == id) - { - item.iThread = TThreadId(0); - item.iOperation(item.iItem); - } - } - last = gEpocEnv->iCleanupItems->Count() - 1; - for(i = last; i >= 0 ; i--) - { - TSdlCleanupItem& item = gEpocEnv->iCleanupItems->At(i); - if(item.iThread == TThreadId(0)) - { - gEpocEnv->iCleanupItems->Delete(i); - } - } - } - -void EpocSdlEnv::FreeSurface() - { - Request(CSdlAppServ::EAppSrvDsaStatus); - if(gEpocEnv->iDsa != NULL) - gEpocEnv->iDsa->Free(); - } - -void EpocSdlEnv::LockPalette(TBool aLock) - { - gEpocEnv->iDsa->LockPalette(aLock); - } - -void EpocSdlEnv::ObserverEvent(TInt aService, TInt aParam) - { - const TBool sdlThread = RThread().Id() == gEpocEnv->iId; - const TInt valuea = gEpocEnv->iAppSrv->ObserverEvent(aService, aParam); - gEpocEnv->iAppSrv->HandleObserverValue(aService, valuea, !sdlThread); - if(sdlThread) - { - gEpocEnv->iAppSrv->SetParam(aParam); - const TInt valuet = gEpocEnv->iAppSrv->RequestValue(aService); - gEpocEnv->iAppSrv->HandleObserverValue(aService, valuet, EFalse); - } - } - - -TPoint EpocSdlEnv::WindowCoordinates(const TPoint& aPoint) - { - return gEpocEnv->iDsa == NULL ? aPoint : - gEpocEnv->iDsa->WindowCoordinates(aPoint); - } - -void EpocSdlEnv::PanicMain(const TDesC& aInfo, TInt aErr) - { - gEpocEnv->iAppSrv->PanicMain(aInfo, aErr); - } -//Dsa is a low priority ao, it has to wait if its pending event, but ws -//event has been prioritized before it -//this is not called from app thread! -void EpocSdlEnv::WaitDeviceChange() - { - LockPalette(ETrue); - gEpocEnv->iAppSrv->RequestValue(CSdlAppServ::EAppSrvWaitDsa); - const TSize sz = WindowSize(); - const TInt param = reinterpret_cast(&sz); - ObserverEvent(MSDLObserver::EEventScreenSizeChanged, param); - - // RThread().Suspend(); - } - -LOCAL_C TBool CheckSdl() - { - TInt isExit = ETrue; - RThread sdl; - if(sdl.Open(gEpocEnv->iId) == KErrNone) - { - if(sdl.ExitType() == EExitPending) - { - isExit = EFalse; - } - sdl.Close(); - } - return isExit; - } - -void EpocSdlEnvData::Free() - { - - if(RThread().Id() == gEpocEnv->iId) - { - if(iDsa != NULL) - iDsa->Free(); - return; - } - - __ASSERT_ALWAYS(iArgv == NULL || CheckSdl(), PANIC(KErrNotReady)); - } - - void EpocSdlEnvData::Delete() - { - - for(TInt i = 0; i <= iArgc; i++) - { - if(iArgv != NULL) - User::Free( iArgv[i] ); - } - - User::Free(iArgv); - - iArgv = NULL; - iArgc = 0; - - delete iEventQueue; - - if(iDsa != NULL) - iDsa->Free(); - - delete iDsa; - delete iAppSrv; - - delete gEpocEnv->iCaller; - } - -_LIT(KSDLMain, "SDLMain"); - -LOCAL_C int MainL() - { - gEpocEnv->iCleanupItems = new (ELeave) CArrayFixFlat(8); - - char** envp=0; - /* !! process exits here if there is "exit()" in main! */ - int ret = 0; - for(TInt i = 0; i < 6; i++) - { - void* f = (void*) gEpocEnv->iMain[i]; - if(f != NULL) - { - switch(i) - { - case 0: - ret = ((mainfunc1)f)(); - return ret; - case 3: - ((mainfunc1)f)(); - return ret; - case 1: - ret = ((mainfunc2)f)(EpocSdlEnv::Argc(), EpocSdlEnv::Argv()); - return ret; - case 4: - ((mainfunc2)f)(EpocSdlEnv::Argc(), EpocSdlEnv::Argv()); - return ret; - case 2: - ret = ((mainfunc3)f)(EpocSdlEnv::Argc(), EpocSdlEnv::Argv(), envp); - return ret; - case 5: - ((mainfunc3)f)(EpocSdlEnv::Argc(), EpocSdlEnv::Argv(), envp); - return ret; - } - } - } - PANIC(KErrNotFound); - return 0; - } - -LOCAL_C TInt DoMain(TAny* /*aParam*/) - { - TBool fbsconnected = EFalse; - CTrapCleanup* cleanup = NULL; - if(EnvUtils::IsOwnThreaded()) - { - cleanup = CTrapCleanup::New(); - - - if(RFbsSession::GetSession() == NULL) - { - PANIC_IF_ERROR(RFbsSession::Connect()); - fbsconnected = ETrue; - } - } - gEpocEnv->iAppSrv->Init(); - - // Call stdlib main - int ret = 0; - if(EnvUtils::IsOwnThreaded()) - { - //completes waiting rendesvous - RThread::Rendezvous(KErrNone); - } - - TRAPD(err, err = MainL()); - - EpocSdlEnv::ObserverEvent(MSDLObserver::EEventMainExit, err); - - // Free resources and return - - EpocSdlEnv::CleanupItems(); - - gEpocEnv->iCleanupItems->Reset(); - delete gEpocEnv->iCleanupItems; - gEpocEnv->iCleanupItems = NULL; - - gEpocEnv->Free(); //free up in thread resources - - if(fbsconnected) - RFbsSession::Disconnect(); - - // delete as; - delete cleanup; - - if(gEpocEnv->iCallerStatus != NULL) - { - User::RequestComplete(gEpocEnv->iCallerStatus, err); - return 0; - } - else - { - return err == KErrNone ? ret : err; - } - } - - - -EXPORT_C CSDL::~CSDL() - { - gEpocEnv->Free(); - gEpocEnv->Delete(); - - User::Free(gEpocEnv); - gEpocEnv = NULL; - } - -EXPORT_C CSDL* CSDL::NewL(TInt aFlags) - { - __ASSERT_ALWAYS(gEpocEnv == NULL, PANIC(KErrAlreadyExists)); - gEpocEnv = (EpocSdlEnvData*) User::AllocL(sizeof(EpocSdlEnvData)); - Mem::FillZ(gEpocEnv, sizeof(EpocSdlEnvData)); - - gEpocEnv->iEpocEnvFlags = aFlags; - gEpocEnv->iEventQueue = new (ELeave) CEventQueue(); - gEpocEnv->iAppSrv = new (ELeave) CSdlAppServ(); - - - CSDL* sdl = new (ELeave) CSDL(); - - gEpocEnv->iSdl = sdl; - - return sdl; - } - - /* -EXPORT_C void CSDL::ReInitL(TFlags aFlags) - { - const TFlags prevFlags = gEpocEnv->iEpocEnvFlags; - gEpocEnv->iEpocEnvFlags = aFlags; - TInt err = KErrNone; - if(((prevFlags & EDrawModeDSB) != (aFlags & EDrawModeDSB)) && gEpocEnv->iDsa) - { - delete gEpocEnv->iDsa; - gEpocEnv->iDsa = NULL; - gEpocEnv->iDsa = CDsa::RecreateL(EpocSdlEnv::Flags(CSDL::EDrawModeDSB)); - } - } - */ - - -EXPORT_C void CSDL::SetContainerWindowL(RWindow& aWindow, RWsSession& aSession, CWsScreenDevice& aDevice) - { - if(gEpocEnv->iDsa == NULL) - gEpocEnv->iDsa = CDsa::CreateL(aSession); - gEpocEnv->iDsa->ConstructL(aWindow, aDevice); - } - - TInt EpocSdlEnv::ApplyGlesDsa() - { - CDsa* dsa = NULL; - TRAPD(err, dsa = gEpocEnv->iDsa->CreateGlesDsaL()); - gEpocEnv->iDsa = dsa; - return err; - } - - RWindow* EpocSdlEnv::Window() - { - return gEpocEnv->iDsa->Window(); - } - -/* -TInt DoLegacyComplete(TAny* aThis) - { - if(aThis != NULL) - { - RThread t; - if(KErrNone == t.Open(((TInt*) aThis)[0])) - { - TRequestStatus* s = (TRequestStatus*)(((TInt*) aThis)[1]); - t.RequestComplete(s, KErrNone); - } - t.Close(); - } - return KErrNone; - } -*/ - -EXPORT_C TThreadId CSDL::CallMainL(const TMainFunc& aFunc, TRequestStatus* const aStatus, const CDesC8Array* const aArg, TInt aFlags, TInt aStackSize) - { - ASSERT(gEpocEnv != NULL); - gEpocEnv->iMain = aFunc; - const TBool args = aArg != NULL; - - if(gEpocEnv->iArgv != NULL) - User::Leave(KErrAlreadyExists); - - gEpocEnv->iArgc = args ? aArg->Count() + 1 : 0; - gEpocEnv->iArgv = (char**) User::AllocL(sizeof(char*) * (gEpocEnv->iArgc + 2)); - - TInt k = 0; - const TFileName processName = RProcess().FileName(); - const TInt len = processName.Length(); - gEpocEnv->iArgv[k] = (char*) User::AllocL(len + 1); - Mem::Copy(gEpocEnv->iArgv[k], processName.Ptr(), len); - gEpocEnv->iArgv[k][len] = 0; - - for(TInt i = 0; args && (i < aArg->Count()); i++) - { - k++; - const TInt len = aArg->MdcaPoint(i).Length(); - gEpocEnv->iArgv[k] = (char*) User::AllocL(len + 1); - Mem::Copy(gEpocEnv->iArgv[k], aArg->MdcaPoint(i).Ptr(), len); - gEpocEnv->iArgv[k][len] = 0; - } - - gEpocEnv->iArgv[k + 1] = NULL; - - //For legacy, set to be threaded if resume is requested - if(aFlags & CSDL::ERequestResume) - { //unless explicitly told not to - if(!(gEpocEnv->iEpocEnvFlags & EMainThread)) - { - gEpocEnv->iEpocEnvFlags |= EOwnThread; - } - } - - gEpocEnv->iEventQueue->ConstructL(); - gEpocEnv->iAppSrv->ConstructL(); - - - - if(EnvUtils::IsOwnThreaded()) - { - RThread thread; - User::LeaveIfError(thread.Create(KSDLMain, DoMain, aStackSize, NULL, NULL)); - - if(aStatus != NULL) - { - thread.Logon(*aStatus); - } - - gEpocEnv->iId = thread.Id(); - thread.SetPriority(EPriorityLess); - if((aFlags & CSDL::ERequestResume) == 0) - { - thread.Resume(); - } - thread.Close(); - } - else - { - gEpocEnv->iCaller = CIdle::NewL(CActive::EPriorityIdle); - gEpocEnv->iCaller->Start(TCallBack(DoMain)); - gEpocEnv->iCallerStatus = aStatus; - if(aStatus != NULL) - *aStatus = KRequestPending; - gEpocEnv->iId = RThread().Id(); - RThread().SetPriority(EPriorityLess); - - /* if(aFlags & CSDL::ERequestResume) - { - RThread re; - User::LeaveIfError(re.Create(KSDLMain, DoLegacyComplete, KDefaultStackSize, NULL, NULL)); - const TThreadId tid = re.Id(); - re.Close(); - return tid; - } */ - - } - return gEpocEnv->iId; - } - -EXPORT_C TInt CSDL::AppendWsEvent(const TWsEvent& aEvent) - { - return EpocSdlEnv::EventQueue().Append(aEvent); - } - -EXPORT_C void CSDL::SDLPanic(const TDesC& aInfo, TInt aErr) - { - EpocSdlEnv::PanicMain(aInfo, aErr); - } - -EXPORT_C TInt CSDL::GetSDLCode(TInt aScanCode) - { - if(aScanCode < 0) - return MAX_SCANCODE; - if(aScanCode >= MAX_SCANCODE) - return -1; - return KeyMap()[aScanCode]; - } - -EXPORT_C TInt CSDL::SDLCodesCount() const - { - return MAX_SCANCODE; - } - -EXPORT_C void CSDL::ResetSDLCodes() - { - ResetKeyMap(); - } - -EXPORT_C void CSDL::SetOrientation(TOrientationMode aMode) - { - CDsa::TOrientationMode mode = CDsa::EViewOrientation0; - switch(aMode) - { - case EOrientation0: mode = CDsa::EViewOrientation0; break; - case EOrientation90: mode = CDsa::EViewOrientation90; break; - case EOrientation180: mode = CDsa::EViewOrientation180; break; - case EOrientation270: mode = CDsa::EViewOrientation270; break; - } - gEpocEnv->iDsa->SetOrientation(mode); - } - -EXPORT_C TInt CSDL::SetSDLCode(TInt aScanCode, TInt aSDLCode) - { - const TInt current = GetSDLCode(aScanCode); - if(aScanCode >= 0 && aScanCode < MAX_SCANCODE) - KeyMap()[aScanCode] = static_cast(aSDLCode); - return current; - } - - -EXPORT_C MSDLObserver* CSDL::Observer() - { - return gEpocEnv->iAppSrv->Observer(); - } - -EXPORT_C void CSDL::SetObserver(MSDLObserver* aObserver) - { - gEpocEnv->iAppSrv->SetObserver(aObserver); - } - -EXPORT_C void CSDL::Resume() - { - EpocSdlEnv::Resume(); - } - -EXPORT_C void CSDL::Suspend() - { - if(gEpocEnv->iDsa != NULL) - gEpocEnv->iDsa->DoStop(); - } - -EXPORT_C CSDL::CSDL() - { - } - -EXPORT_C void CSDL::DisableKeyBlocking(CAknAppUi& aAppUi) const - { - gEpocEnv->iAppUi = &aAppUi; - EnvUtils::DisableKeyBlocking(); - } - -EXPORT_C TInt CSDL::SetBlitter(MBlitter* aBlitter) - { - if(gEpocEnv && gEpocEnv->iDsa) - { - gEpocEnv->iDsa->SetBlitter(aBlitter); - return KErrNone; - } - return KErrNotReady; - } - - -EXPORT_C TInt CSDL::AppendOverlay(MOverlay& aOverlay, TInt aPriority) - { - if(gEpocEnv && gEpocEnv->iDsa) - { - return gEpocEnv->iDsa->AppendOverlay(aOverlay, aPriority); - } - return KErrNotReady; - } - -EXPORT_C TInt CSDL::RemoveOverlay(MOverlay& aOverlay) - { - if(gEpocEnv && gEpocEnv->iDsa) - { - return gEpocEnv->iDsa->RemoveOverlay(aOverlay); - } - return KErrNotReady; - } - -EXPORT_C TInt CSDL::RedrawRequest() - { - if(gEpocEnv && gEpocEnv->iDsa) - { - const TInt err = gEpocEnv->iDsa->RedrawRequest(); - EnvUtils::RunSingleThread(); - return err; - } - return KErrNotReady; - } - -/* -EXPORT_C CSDL* CSDL::Current() - { - return gEpocEnv != NULL ? gEpocEnv->iSdl : NULL; - } - - -EXPORT_C TInt CSDL::SetVolume(TInt aVolume) - { - return EpocSdlEnv::SetVolume(aVolume); - } - -EXPORT_C TInt CSDL::Volume() const - { - return EpocSdlEnv::Volume(); - } - -EXPORT_C TInt CSDL::MaxVolume() const - { - return EpocSdlEnv::MaxVolume(); - } -*/ - -void EnvUtils::DisableKeyBlocking() - { - if(gEpocEnv->iAppUi != NULL) - return CCurrentAppUi::Cast(gEpocEnv->iAppUi)->DisableKeyBlocking(); - } - -TBool EnvUtils::Rendezvous(RThread& aThread, TRequestStatus& aStatus) - { - if(gEpocEnv->iId != TThreadId(0) && - aThread.Open(gEpocEnv->iId) && - aThread.ExitType() == EExitPending) - { - aThread.Rendezvous(aStatus); - return ETrue; - } - return EFalse; - } - - - -void* SDL_LoadObject(const char *sofile) - { - RLibrary* lib = new RLibrary(); - if(lib == NULL) - return NULL; - TFileName name; - name.Copy(TPtrC8((const TUint8*)sofile)); - if(KErrNone == lib->Load(name)) - return lib; - delete lib; - return NULL; - } - - -void* SDL_LoadFunction(void *handle, const char *name) - { - TLex8 v((const TUint8*)(name)); - TInt ord; - - if(KErrNone != v.Val(ord)) - return NULL; - - const RLibrary* lib = reinterpret_cast(handle); - TLibraryFunction f = lib->Lookup(ord); - return (void*)(f); -/* - int i = 0; - TPtrC8 functionName((const TUint8*)(name)); - for(;;) - { - const TInt ord = _Ordinals[i].iOrd; - if(ord < 0) - return NULL; - if(functionName.Compare( - TPtrC8((const TUint8*)(_Ordinals[i].iName))) == 0) - { - const RLibrary* lib = reinterpret_cast(handle); - TLibraryFunction f = lib->Lookup(ord); - return (void*)(f); - } - ++i; - }*/ - } - -void SDL_UnloadObject(void *handle) - { - RLibrary* lib = reinterpret_cast(handle); - lib->Close(); - delete lib; - } - +/* + SDL_Main.cpp + Symbian OS services for SDL + + Markus Mertama + */ + +#include "epoc_sdl.h" +#include "sdlepocapi.h" +#include +#include +#include +#include +#include "vectorbuffer.h" +#include +#include +#include +#include "SDL_epocevents_c.h" +#include "SDL_keysym.h" +#include "dsa.h" +#include "SDL_loadso.h" + +extern SDLKey* KeyMap(); +extern void ResetKeyMap(); + +class CCurrentAppUi; +class CEikonEnv; +class CSdlAppServ; +class CEventQueue; + +NONSHARABLE_CLASS(EpocSdlEnvData) +{ + public: + void Free(); + void Delete(); + CEventQueue* iEventQueue; + TMainFunc iMain; + TInt iEpocEnvFlags; + int iArgc; + char** iArgv; + CDsa* iDsa; + CSdlAppServ* iAppSrv; + TThreadId iId; + CArrayFix* iCleanupItems; + CEikAppUi* iAppUi; + CSDL* iSdl; + CIdle* iCaller; + TRequestStatus* iCallerStatus; +}; + +EpocSdlEnvData* gEpocEnv; + +NONSHARABLE_CLASS(EnvUtils) +{ + public: + static inline TBool IsOwnThreaded(); + static void DisableKeyBlocking(); + static TBool Rendezvous(RThread& aThread, TRequestStatus& aStatus); + static void RunSingleThread(); +}; + +inline TBool EnvUtils::IsOwnThreaded() +{ + return gEpocEnv->iEpocEnvFlags & CSDL::EOwnThread; +} + +void EnvUtils::RunSingleThread() +{ + if(!EnvUtils::IsOwnThreaded()) + { + TInt count = RThread().RequestCount(); + if(count > 0) + { + TInt err; + if(CActiveScheduler::RunIfReady(err, CActive::EPriorityIdle)) + { + CActiveScheduler::Current()->WaitForAnyRequest(); + } + } + } +} + +TInt Panic(TInt aErr, TInt aLine) +{ + TBuf<64> b; + b.Format(_L("Main at %d"), aLine); + User::Panic(b, aErr); + return 0; +} + + +NONSHARABLE_CLASS(CCurrentAppUi) : public CAknAppUi +{ + public: + static CCurrentAppUi* Cast(CEikAppUi* aUi); + void DisableKeyBlocking(); +}; + + +CCurrentAppUi* CCurrentAppUi::Cast(CEikAppUi* aUi) +{ + return static_cast(aUi); +} + +void CCurrentAppUi::DisableKeyBlocking() +{ + SetKeyBlockMode(ENoKeyBlock); +} + + +class CEventQueue : public CBase, public MEventQueue +{ + public: + void ConstructL(); + ~CEventQueue(); + TInt Append(const TWsEvent& aEvent); + const TWsEvent& Shift(); + void Lock(); + void Unlock(); + TBool HasData(); + + private: + TVector iVector; + RCriticalSection iCS; +}; + +void CEventQueue::ConstructL() +{ + if(EnvUtils::IsOwnThreaded()) + User::LeaveIfError(iCS.CreateLocal()); +} + +CEventQueue::~CEventQueue() +{ + iCS.Close(); +} + +TInt CEventQueue::Append(const TWsEvent& aEvent) +{ + Lock(); + const TInt err = iVector.Append(aEvent); + Unlock(); + return err; +} + + +TBool CEventQueue::HasData() +{ + EnvUtils::RunSingleThread(); + return iVector.Size() > 0; +} + +void CEventQueue::Lock() +{ + if(EnvUtils::IsOwnThreaded()) + iCS.Wait(); +} + +void CEventQueue::Unlock() +{ + if(EnvUtils::IsOwnThreaded()) + iCS.Signal(); +} + +const TWsEvent& CEventQueue::Shift() +{ + const TWsEvent& event = iVector.Shift(); + return event; +} + + +TSdlCleanupItem::TSdlCleanupItem(TSdlCleanupOperation aOperation, TAny* aItem) : + iOperation(aOperation), iItem(aItem), iThread(RThread().Id()) +{} + +#define MAINFUNC(x) EXPORT_C TMainFunc::TMainFunc(mainfunc##x aFunc){Mem::FillZ(iMainFunc, sizeof(iMainFunc)); iMainFunc[x - 1] = (void*) aFunc;} + + MAINFUNC(1) + MAINFUNC(2) + MAINFUNC(3) + MAINFUNC(4) + MAINFUNC(5) +MAINFUNC(6) + +EXPORT_C TMainFunc::TMainFunc() +{ + Mem::FillZ(iMainFunc, sizeof(iMainFunc)); +} + + +const void* TMainFunc::operator[](TInt aIndex) const +{ + return iMainFunc[aIndex]; +} + + +NONSHARABLE_CLASS(CSdlAppServ) : public CActive +{ + public: + enum + { + EAppSrvNoop = CDsa::ELastDsaRequest, + EAppSrvWindowWidth, + EAppSrvWindowHeight, + EAppSrvWindowDisplayMode, + EAppSrvWindowPointerCursorMode, + EAppSrvDsaStatus, + EAppSrvStopThread, + EAppSrvWaitDsa + }; + CSdlAppServ(); + void ConstructL(); + ~CSdlAppServ(); + TInt Request(TInt aService); + TInt RequestValue(TInt aService); + void Init(); + void PanicMain(TInt aReason); + void PanicMain(const TDesC& aInfo, TInt aReason); + void SetObserver(MSDLObserver* aObserver); + TInt ObserverEvent(TInt aEvent, TInt aParam); + void SetParam(TInt aParam); + void HandleObserverValue(TInt aService, TInt aReturnValue, TBool aMainThread); + MSDLObserver* Observer(); + + private: + void RunL(); + void DoCancel(); + const TThreadId iMainId; + RThread iAppThread; + TInt iService; + TInt iReturnValue; + RSemaphore iSema; + MSDLObserver* iObserver; + TRequestStatus* iStatusPtr; +}; + +CSdlAppServ::CSdlAppServ() : CActive(CActive::EPriorityHigh), iMainId(RThread().Id()) +{} + + +MSDLObserver* CSdlAppServ::Observer() +{ + return iObserver; +} + +void CSdlAppServ::SetObserver(MSDLObserver* aObserver) +{ + iObserver = aObserver; +} + +TInt CSdlAppServ::ObserverEvent(TInt aEvent, TInt aParam) +{ + if(iObserver != NULL) + { + if(RThread().Id() == gEpocEnv->iId && EnvUtils::IsOwnThreaded()) + { + return iObserver->SdlThreadEvent(aEvent, aParam); + } + else if(RThread().Id() == iMainId) + { + return iObserver->SdlEvent(aEvent, aParam); + } + PANIC(KErrNotSupported); + } + return 0; +} + +void CSdlAppServ::PanicMain(TInt aReason) +{ + iAppThread.Panic(RThread().Name(), aReason); +} + +void CSdlAppServ::PanicMain(const TDesC& aInfo, TInt aReason) +{ + iAppThread.Panic(aInfo, aReason); +} + +void CSdlAppServ::ConstructL() +{ + CActiveScheduler::Add(this); + if(EnvUtils::IsOwnThreaded()) + User::LeaveIfError(iSema.CreateLocal(1)); + iStatus = KRequestPending; + iStatusPtr = &iStatus; + SetActive(); +} + +CSdlAppServ::~CSdlAppServ() +{ + Cancel(); + if(iSema.Handle() != NULL) + iSema.Signal(); + iSema.Close(); + iAppThread.Close(); +} + +TInt CSdlAppServ::Request(TInt aService) +{ + if(EnvUtils::IsOwnThreaded()) + { + if(RThread().Id() == iAppThread.Id()) + return KErrBadHandle; + iSema.Wait(); + } + EnvUtils::RunSingleThread(); + iService = aService; + iAppThread.RequestComplete(iStatusPtr, KErrNone); + return KErrNone; +} + +TInt CSdlAppServ::RequestValue(TInt aService) +{ + Request(aService); + Request(EAppSrvNoop); + return iReturnValue; +} + +void CSdlAppServ::Init() +{ + PANIC_IF_ERROR(iAppThread.Open(iMainId)); +} + +void CSdlAppServ::SetParam(TInt aParam) +{ + iReturnValue = aParam; +} + +void CSdlAppServ::HandleObserverValue(TInt aService, TInt aReturnValue, TBool aMainThread) +{ + if(iObserver != NULL && aMainThread) + { + switch(aService) + { + case MSDLObserver::EEventScreenSizeChanged: + if(aReturnValue == MSDLObserver::EScreenSizeChangedDefaultPalette) + EpocSdlEnv::LockPalette(EFalse); + break; + } + } + if(!aMainThread && aService == MSDLObserver::EEventSuspend) + { + if(iObserver == NULL || (gEpocEnv->iDsa != NULL && gEpocEnv->iDsa->Stopped() && aReturnValue != MSDLObserver::ESuspendNoSuspend)) + { + EpocSdlEnv::Suspend(); + } + } +} + +void CSdlAppServ::RunL() +{ + if(iStatus == KErrNone) + { + switch(iService) + { + case CSdlAppServ::EAppSrvWaitDsa: + EpocSdlEnv::SetWaitDsa(); + iReturnValue = EpocSdlEnv::IsDsaAvailable(); + break; + + case CSdlAppServ::EAppSrvStopThread: + if(gEpocEnv->iDsa != NULL) + gEpocEnv->iDsa->SetSuspend(); + break; + + case EpocSdlEnv::EDisableKeyBlocking: + EnvUtils::DisableKeyBlocking(); + break; + + case EAppSrvWindowPointerCursorMode: + iReturnValue = gEpocEnv->iDsa != NULL ? gEpocEnv->iDsa->Session().PointerCursorMode() : KErrNotReady; + break; + + case EAppSrvDsaStatus: + if(gEpocEnv->iDsa != NULL) + gEpocEnv->iDsa->Stop(); + iReturnValue = KErrNone; + break; + + case CDsa::ERequestUpdate: + gEpocEnv->iDsa->UnlockHWSurfaceRequestComplete(); + break; + + case EAppSrvNoop: + break; + + case MSDLObserver::EEventResume: + case MSDLObserver::EEventSuspend: + case MSDLObserver::EEventScreenSizeChanged: + case MSDLObserver::EEventWindowReserved: + case MSDLObserver::EEventKeyMapInit: + case MSDLObserver::EEventWindowNotAvailable: + case MSDLObserver::EEventMainExit: + iReturnValue = ObserverEvent(iService, iReturnValue); + HandleObserverValue(iService, iReturnValue, ETrue); + break; + + default: + PANIC(KErrNotSupported); + break; + } + + iStatus = KRequestPending; + iStatusPtr = &iStatus; + SetActive(); + } + + if(EnvUtils::IsOwnThreaded()) + iSema.Signal(); +} + +void CSdlAppServ::DoCancel() +{ + if(EnvUtils::IsOwnThreaded()) + iSema.Wait(); + TRequestStatus* s = &iStatus; + iAppThread.RequestComplete(s, KErrCancel); +} + +MEventQueue& EpocSdlEnv::EventQueue() +{ + __ASSERT_DEBUG(gEpocEnv != NULL, PANIC(KErrNotReady)); + return *gEpocEnv->iEventQueue; +} + + +TBool EpocSdlEnv::Flags(TInt aFlag) +{ + const TInt flag = gEpocEnv->iEpocEnvFlags & aFlag; + return flag == aFlag; +} + +TInt EpocSdlEnv::Argc() +{ + __ASSERT_DEBUG(gEpocEnv != NULL, PANIC(KErrNotReady)); + return gEpocEnv->iArgc; +} + +char** EpocSdlEnv::Argv() +{ + __ASSERT_DEBUG(gEpocEnv != NULL, PANIC(KErrNotReady)); + return gEpocEnv->iArgv; +} + +TBool EpocSdlEnv::IsDsaAvailable() +{ + __ASSERT_DEBUG(gEpocEnv != NULL, PANIC(KErrNotReady)); + return gEpocEnv->iDsa != NULL && gEpocEnv->iDsa->IsDsaAvailable(); +} + +void EpocSdlEnv::WaitDsaAvailable() +{ + EpocSdlEnv::ObserverEvent(MSDLObserver::EEventWindowNotAvailable, 0); + gEpocEnv->iAppSrv->Request(CSdlAppServ::EAppSrvStopThread); + if(EpocSdlEnv::Flags(CSDL::EEnableFocusStop)) + { + EpocSdlEnv::ObserverEvent(MSDLObserver::EEventSuspend, 0); + } +} + +void EpocSdlEnv::Suspend() +{ + if(gEpocEnv->iDsa != NULL && (gEpocEnv->iDsa->Stopped() || EpocSdlEnv::Flags(CSDL::EEnableFocusStop))) + { + gEpocEnv->iDsa->SetSuspend(); + if(EnvUtils::IsOwnThreaded()) + { + RThread().Suspend(); + EpocSdlEnv::ObserverEvent(MSDLObserver::EEventResume, 0); + } + } +} + +void EpocSdlEnv::SetWaitDsa() +{ + if(!IsDsaAvailable()) + { + if(EnvUtils::IsOwnThreaded()) + { + RThread th; + th.Open(gEpocEnv->iId); + th.Suspend(); + th.Close(); + } + if(gEpocEnv->iDsa != NULL) + gEpocEnv->iDsa->SetSuspend(); + } +} + +void EpocSdlEnv::Resume() +{ + if(gEpocEnv->iDsa != NULL) + { + gEpocEnv->iDsa->Resume(); + } + if(EnvUtils::IsOwnThreaded()) + { + RThread th; + th.Open(gEpocEnv->iId); + th.Resume(); + th.Close(); + } + const TInt value = gEpocEnv->iAppSrv->ObserverEvent(MSDLObserver::EEventResume, 0); + gEpocEnv->iAppSrv->HandleObserverValue(MSDLObserver::EEventResume, value, ETrue); +} + + +TInt EpocSdlEnv::AllocSwSurface(const TSize& aSize, TDisplayMode aMode) +{ + return gEpocEnv->iDsa->AllocSurface(EFalse, aSize, aMode); +} + +TInt EpocSdlEnv::AllocHwSurface(const TSize& aSize, TDisplayMode aMode) +{ + return gEpocEnv->iDsa->AllocSurface(ETrue, aSize, aMode); +} + +void EpocSdlEnv::UnlockHwSurface() +{ + gEpocEnv->iDsa->UnlockHwSurface(); +} + +TUint8* EpocSdlEnv::LockHwSurface() +{ + return gEpocEnv->iDsa->LockHwSurface(); +} + +void EpocSdlEnv::UpdateSwSurface() +{ + gEpocEnv->iDsa->UpdateSwSurface(); +} + +TBool EpocSdlEnv::AddUpdateRect(TUint8* aAddress, const TRect& aUpdateRect, const TRect& aRect) +{ + return gEpocEnv->iDsa->AddUpdateRect(aAddress, aUpdateRect, aRect); +} + +void EpocSdlEnv::Request(TInt aService) +{ + __ASSERT_DEBUG(gEpocEnv != NULL, PANIC(KErrNotReady)); + gEpocEnv->iAppSrv->Request(aService); +} + +TSize EpocSdlEnv::WindowSize(const TSize& aRequestedSize) +{ + __ASSERT_DEBUG(gEpocEnv != NULL, PANIC(KErrNotReady)); + if(gEpocEnv->iDsa != NULL && EpocSdlEnv::Flags(CSDL::EAllowImageResize) && gEpocEnv->iDsa->WindowSize() != aRequestedSize) + { + TRAP_IGNORE(gEpocEnv->iDsa->CreateZoomerL(aRequestedSize)); + } + return gEpocEnv->iDsa == NULL ? TSize(0, 0) : gEpocEnv->iDsa->WindowSize(); +} + +TSize EpocSdlEnv::WindowSize() +{ + __ASSERT_DEBUG(gEpocEnv != NULL, PANIC(KErrNotReady)); + return gEpocEnv->iDsa == NULL ? TSize(0, 0) : gEpocEnv->iDsa->WindowSize(); +} + +TDisplayMode EpocSdlEnv::DisplayMode() +{ + return gEpocEnv->iDsa == NULL ? ENone : gEpocEnv->iDsa->DisplayMode(); +} + +TPointerCursorMode EpocSdlEnv::PointerMode() +{ + return static_cast(gEpocEnv->iAppSrv->RequestValue(CSdlAppServ::EAppSrvWindowPointerCursorMode)); +} + +TInt EpocSdlEnv::SetPalette(TInt aFirstcolor, TInt aColorCount, TUint32* aPalette) +{ + return gEpocEnv->iDsa->SetPalette(aFirstcolor, aColorCount, aPalette); +} + +void EpocSdlEnv::PanicMain(TInt aErr) +{ + gEpocEnv->iAppSrv->PanicMain(aErr); +} + + +TInt EpocSdlEnv::AppendCleanupItem(const TSdlCleanupItem& aItem) +{ + TRAPD(err, gEpocEnv->iCleanupItems->AppendL(aItem)); + return err; +} + +void EpocSdlEnv::RemoveCleanupItem(TAny* aItem) +{ + for(TInt i = 0; i < gEpocEnv->iCleanupItems->Count(); i++) + { + if(gEpocEnv->iCleanupItems->At(i).iItem == aItem) + gEpocEnv->iCleanupItems->Delete(i); + } +} + +void EpocSdlEnv::CleanupItems() +{ + const TThreadId id = RThread().Id(); + TInt last = gEpocEnv->iCleanupItems->Count() - 1; + TInt i; + + for(i = last; i >= 0 ; i--) + { + TSdlCleanupItem& item = gEpocEnv->iCleanupItems->At(i); + if(item.iThread == id) + { + item.iThread = TThreadId(0); + item.iOperation(item.iItem); + } + } + + last = gEpocEnv->iCleanupItems->Count() - 1; + + for(i = last; i >= 0 ; i--) + { + TSdlCleanupItem& item = gEpocEnv->iCleanupItems->At(i); + if(item.iThread == TThreadId(0)) + { + gEpocEnv->iCleanupItems->Delete(i); + } + } +} + +void EpocSdlEnv::FreeSurface() +{ + Request(CSdlAppServ::EAppSrvDsaStatus); + if(gEpocEnv->iDsa != NULL) + gEpocEnv->iDsa->Free(); +} + +void EpocSdlEnv::LockPalette(TBool aLock) +{ + gEpocEnv->iDsa->LockPalette(aLock); +} + +void EpocSdlEnv::ObserverEvent(TInt aService, TInt aParam) +{ + const TBool sdlThread = RThread().Id() == gEpocEnv->iId; + const TInt valuea = gEpocEnv->iAppSrv->ObserverEvent(aService, aParam); + gEpocEnv->iAppSrv->HandleObserverValue(aService, valuea, !sdlThread); + if(sdlThread) + { + gEpocEnv->iAppSrv->SetParam(aParam); + const TInt valuet = gEpocEnv->iAppSrv->RequestValue(aService); + gEpocEnv->iAppSrv->HandleObserverValue(aService, valuet, EFalse); + } +} + +TPoint EpocSdlEnv::WindowCoordinates(const TPoint& aPoint) +{ + return gEpocEnv->iDsa == NULL ? aPoint : gEpocEnv->iDsa->WindowCoordinates(aPoint); +} + +void EpocSdlEnv::PanicMain(const TDesC& aInfo, TInt aErr) +{ + gEpocEnv->iAppSrv->PanicMain(aInfo, aErr); +} + +//Dsa is a low priority ao, it has to wait if its pending event, but ws +//event has been prioritized before it +//this is not called from app thread! +void EpocSdlEnv::WaitDeviceChange() +{ + LockPalette(ETrue); + gEpocEnv->iAppSrv->RequestValue(CSdlAppServ::EAppSrvWaitDsa); + const TSize sz = WindowSize(); + const TInt param = reinterpret_cast(&sz); + ObserverEvent(MSDLObserver::EEventScreenSizeChanged, param); +} + +LOCAL_C TBool CheckSdl() +{ + TInt isExit = ETrue; + RThread sdl; + if(sdl.Open(gEpocEnv->iId) == KErrNone) + { + if(sdl.ExitType() == EExitPending) + { + isExit = EFalse; + } + sdl.Close(); + } + return isExit; +} + +void EpocSdlEnvData::Free() +{ + if(RThread().Id() == gEpocEnv->iId) + { + if(iDsa != NULL) + iDsa->Free(); + return; + } + + __ASSERT_ALWAYS(iArgv == NULL || CheckSdl(), PANIC(KErrNotReady)); +} + +void EpocSdlEnvData::Delete() +{ + for(TInt i = 0; i <= iArgc; i++) + { + if(iArgv != NULL) + User::Free( iArgv[i] ); + } + + User::Free(iArgv); + + iArgv = NULL; + iArgc = 0; + + delete iEventQueue; + + if(iDsa != NULL) + iDsa->Free(); + + delete iDsa; + delete iAppSrv; + + delete gEpocEnv->iCaller; +} + +_LIT(KSDLMain, "SDLMain"); + +LOCAL_C int MainL() +{ + gEpocEnv->iCleanupItems = new (ELeave) CArrayFixFlat(8); + + char** envp=0; + /* !! process exits here if there is "exit()" in main! */ + int ret = 0; + for(TInt i = 0; i < 6; i++) + { + void* f = (void*) gEpocEnv->iMain[i]; + if(f != NULL) + { + switch(i) + { + case 0: + ret = ((mainfunc1)f)(); + return ret; + + case 3: + ((mainfunc1)f)(); + return ret; + + case 1: + ret = ((mainfunc2)f)(EpocSdlEnv::Argc(), EpocSdlEnv::Argv()); + return ret; + + case 4: + ((mainfunc2)f)(EpocSdlEnv::Argc(), EpocSdlEnv::Argv()); + return ret; + + case 2: + ret = ((mainfunc3)f)(EpocSdlEnv::Argc(), EpocSdlEnv::Argv(), envp); + return ret; + + case 5: + ((mainfunc3)f)(EpocSdlEnv::Argc(), EpocSdlEnv::Argv(), envp); + return ret; + } + } + } + PANIC(KErrNotFound); + return 0; +} + +LOCAL_C TInt DoMain(TAny* /*aParam*/) +{ + TBool fbsconnected = EFalse; + CTrapCleanup* cleanup = NULL; + + if(EnvUtils::IsOwnThreaded()) + { + cleanup = CTrapCleanup::New(); + + if(RFbsSession::GetSession() == NULL) + { + PANIC_IF_ERROR(RFbsSession::Connect()); + fbsconnected = ETrue; + } + } + gEpocEnv->iAppSrv->Init(); + + // Call stdlib main + int ret = 0; + if(EnvUtils::IsOwnThreaded()) + { + //completes waiting rendesvous + RThread::Rendezvous(KErrNone); + } + + TRAPD(err, err = MainL()); + + EpocSdlEnv::ObserverEvent(MSDLObserver::EEventMainExit, err); + + // Free resources and return + EpocSdlEnv::CleanupItems(); + + gEpocEnv->iCleanupItems->Reset(); + delete gEpocEnv->iCleanupItems; + gEpocEnv->iCleanupItems = NULL; + + gEpocEnv->Free(); //free up in thread resources + + if(fbsconnected) + RFbsSession::Disconnect(); + + delete cleanup; + + if(gEpocEnv->iCallerStatus != NULL) + { + User::RequestComplete(gEpocEnv->iCallerStatus, err); + return 0; + } + else + { + return err == KErrNone ? ret : err; + } +} + +EXPORT_C CSDL::~CSDL() +{ + gEpocEnv->Free(); + gEpocEnv->Delete(); + + User::Free(gEpocEnv); + gEpocEnv = NULL; +} + +EXPORT_C CSDL* CSDL::NewL(TInt aFlags) +{ + __ASSERT_ALWAYS(gEpocEnv == NULL, PANIC(KErrAlreadyExists)); + gEpocEnv = (EpocSdlEnvData*) User::AllocL(sizeof(EpocSdlEnvData)); + Mem::FillZ(gEpocEnv, sizeof(EpocSdlEnvData)); + + gEpocEnv->iEpocEnvFlags = aFlags; + gEpocEnv->iEventQueue = new (ELeave) CEventQueue(); + gEpocEnv->iAppSrv = new (ELeave) CSdlAppServ(); + + CSDL* sdl = new (ELeave) CSDL(); + + gEpocEnv->iSdl = sdl; + + return sdl; +} + +EXPORT_C void CSDL::SetContainerWindowL(RWindow& aWindow, RWsSession& aSession, CWsScreenDevice& aDevice) +{ + if(gEpocEnv->iDsa == NULL) + gEpocEnv->iDsa = CDsa::CreateL(aSession); + gEpocEnv->iDsa->ConstructL(aWindow, aDevice); +} + +TInt EpocSdlEnv::ApplyGlesDsa() +{ + CDsa* dsa = NULL; + TRAPD(err, dsa = gEpocEnv->iDsa->CreateGlesDsaL()); + gEpocEnv->iDsa = dsa; + return err; +} + +RWindow* EpocSdlEnv::Window() +{ + return gEpocEnv->iDsa->Window(); +} + +EXPORT_C TThreadId CSDL::CallMainL(const TMainFunc& aFunc, TRequestStatus* const aStatus, const CDesC8Array* const aArg, TInt aFlags, TInt aStackSize) +{ + ASSERT(gEpocEnv != NULL); + gEpocEnv->iMain = aFunc; + const TBool args = aArg != NULL; + + if(gEpocEnv->iArgv != NULL) + User::Leave(KErrAlreadyExists); + + gEpocEnv->iArgc = args ? aArg->Count() + 1 : 0; + gEpocEnv->iArgv = (char**) User::AllocL(sizeof(char*) * (gEpocEnv->iArgc + 2)); + + TInt k = 0; + const TFileName processName = RProcess().FileName(); + const TInt len = processName.Length(); + gEpocEnv->iArgv[k] = (char*) User::AllocL(len + 1); + Mem::Copy(gEpocEnv->iArgv[k], processName.Ptr(), len); + gEpocEnv->iArgv[k][len] = 0; + + for(TInt i = 0; args && (i < aArg->Count()); i++) + { + k++; + const TInt len = aArg->MdcaPoint(i).Length(); + gEpocEnv->iArgv[k] = (char*) User::AllocL(len + 1); + Mem::Copy(gEpocEnv->iArgv[k], aArg->MdcaPoint(i).Ptr(), len); + gEpocEnv->iArgv[k][len] = 0; + } + + gEpocEnv->iArgv[k + 1] = NULL; + + //For legacy, set to be threaded if resume is requested + if(aFlags & CSDL::ERequestResume) + { //unless explicitly told not to + if(!(gEpocEnv->iEpocEnvFlags & EMainThread)) + { + gEpocEnv->iEpocEnvFlags |= EOwnThread; + } + } + + gEpocEnv->iEventQueue->ConstructL(); + gEpocEnv->iAppSrv->ConstructL(); + + if(EnvUtils::IsOwnThreaded()) + { + RThread thread; + User::LeaveIfError(thread.Create(KSDLMain, DoMain, aStackSize, NULL, NULL)); + + if(aStatus != NULL) + { + thread.Logon(*aStatus); + } + + gEpocEnv->iId = thread.Id(); + thread.SetPriority(EPriorityLess); + if((aFlags & CSDL::ERequestResume) == 0) + { + thread.Resume(); + } + thread.Close(); + } + else + { + gEpocEnv->iCaller = CIdle::NewL(CActive::EPriorityIdle); + gEpocEnv->iCaller->Start(TCallBack(DoMain)); + gEpocEnv->iCallerStatus = aStatus; + if(aStatus != NULL) + *aStatus = KRequestPending; + gEpocEnv->iId = RThread().Id(); + RThread().SetPriority(EPriorityLess); + } + + return gEpocEnv->iId; +} + +EXPORT_C TInt CSDL::AppendWsEvent(const TWsEvent& aEvent) +{ + return EpocSdlEnv::EventQueue().Append(aEvent); +} + +EXPORT_C void CSDL::SDLPanic(const TDesC& aInfo, TInt aErr) +{ + EpocSdlEnv::PanicMain(aInfo, aErr); +} + +EXPORT_C TInt CSDL::GetSDLCode(TInt aScanCode) +{ + if(aScanCode < 0) + return MAX_SCANCODE; + if(aScanCode >= MAX_SCANCODE) + return -1; + return KeyMap()[aScanCode]; +} + +EXPORT_C TInt CSDL::SDLCodesCount() const +{ + return MAX_SCANCODE; +} + +EXPORT_C void CSDL::ResetSDLCodes() +{ + ResetKeyMap(); +} + +EXPORT_C void CSDL::SetOrientation(TOrientationMode aMode) +{ + CDsa::TOrientationMode mode = CDsa::EViewOrientation0; + switch(aMode) + { + case EOrientation0: mode = CDsa::EViewOrientation0; break; + case EOrientation90: mode = CDsa::EViewOrientation90; break; + case EOrientation180: mode = CDsa::EViewOrientation180; break; + case EOrientation270: mode = CDsa::EViewOrientation270; break; + } + gEpocEnv->iDsa->SetOrientation(mode); +} + +EXPORT_C TInt CSDL::SetSDLCode(TInt aScanCode, TInt aSDLCode) +{ + const TInt current = GetSDLCode(aScanCode); + if(aScanCode >= 0 && aScanCode < MAX_SCANCODE) + KeyMap()[aScanCode] = static_cast(aSDLCode); + return current; +} + + +EXPORT_C MSDLObserver* CSDL::Observer() +{ + return gEpocEnv->iAppSrv->Observer(); +} + +EXPORT_C void CSDL::SetObserver(MSDLObserver* aObserver) +{ + gEpocEnv->iAppSrv->SetObserver(aObserver); +} + +EXPORT_C void CSDL::Resume() +{ + EpocSdlEnv::Resume(); +} + +EXPORT_C void CSDL::Suspend() +{ + if(gEpocEnv->iDsa != NULL) + gEpocEnv->iDsa->DoStop(); +} + +EXPORT_C CSDL::CSDL() +{} + +EXPORT_C void CSDL::DisableKeyBlocking(CAknAppUi& aAppUi) const +{ + gEpocEnv->iAppUi = &aAppUi; + EnvUtils::DisableKeyBlocking(); +} + +EXPORT_C TInt CSDL::SetBlitter(MBlitter* aBlitter) +{ + if(gEpocEnv && gEpocEnv->iDsa) + { + gEpocEnv->iDsa->SetBlitter(aBlitter); + return KErrNone; + } + return KErrNotReady; +} + + +EXPORT_C TInt CSDL::AppendOverlay(MOverlay& aOverlay, TInt aPriority) +{ + if(gEpocEnv && gEpocEnv->iDsa) + { + return gEpocEnv->iDsa->AppendOverlay(aOverlay, aPriority); + } + return KErrNotReady; +} + +EXPORT_C TInt CSDL::RemoveOverlay(MOverlay& aOverlay) +{ + if(gEpocEnv && gEpocEnv->iDsa) + { + return gEpocEnv->iDsa->RemoveOverlay(aOverlay); + } + return KErrNotReady; +} + +EXPORT_C TInt CSDL::RedrawRequest() +{ + if(gEpocEnv && gEpocEnv->iDsa) + { + const TInt err = gEpocEnv->iDsa->RedrawRequest(); + EnvUtils::RunSingleThread(); + return err; + } + return KErrNotReady; +} + +void EnvUtils::DisableKeyBlocking() +{ + if(gEpocEnv->iAppUi != NULL) + return CCurrentAppUi::Cast(gEpocEnv->iAppUi)->DisableKeyBlocking(); +} + +TBool EnvUtils::Rendezvous(RThread& aThread, TRequestStatus& aStatus) +{ + if(gEpocEnv->iId != TThreadId(0) && + aThread.Open(gEpocEnv->iId) && + aThread.ExitType() == EExitPending) + { + aThread.Rendezvous(aStatus); + return ETrue; + } + return EFalse; +} + +void* SDL_LoadObject(const char *sofile) +{ + RLibrary* lib = new RLibrary(); + if(lib == NULL) + return NULL; + TFileName name; + name.Copy(TPtrC8((const TUint8*)sofile)); + if(KErrNone == lib->Load(name)) + return lib; + delete lib; + return NULL; +} + +void* SDL_LoadFunction(void *handle, const char *name) +{ + TLex8 v((const TUint8*)(name)); + TInt ord; + + if(KErrNone != v.Val(ord)) + return NULL; + + const RLibrary* lib = reinterpret_cast(handle); + TLibraryFunction f = lib->Lookup(ord); + return (void*)(f); +} + +void SDL_UnloadObject(void *handle) +{ + RLibrary* lib = reinterpret_cast(handle); + lib->Close(); + delete lib; +} diff --git a/src/main/symbian/sdlexe.cpp b/src/main/symbian/sdlexe.cpp index e51a4ba..5eff270 100644 --- a/src/main/symbian/sdlexe.cpp +++ b/src/main/symbian/sdlexe.cpp @@ -25,418 +25,56 @@ class CApaDocument; //const TUid KSDLUID = { 0xF01F605E }; LOCAL_C void MakeCCmdLineL(const TDesC8& aParam, CDesC8Array& aArray) - { - - const TChar dq('\"'); - - TLex8 lex(aParam); - TBool in = EFalse; - - lex.SkipSpaceAndMark(); - - while(!lex.Eos()) - { - TPtrC8 ptr; - if(in) - { - const TPtrC8 rem = lex.RemainderFromMark(); - const TInt pos = rem.Locate(dq); - if(pos > 0) - { - lex.Inc(pos); - ptr.Set(lex.MarkedToken()); - lex.SkipAndMark(1); - } - else - { - ptr.Set(rem); - } - in = EFalse; - } - else - { - ptr.Set(lex.NextToken()); - const TInt pos = ptr.Locate(dq); - if(pos == 0) - { - lex.UnGetToMark(); - lex.SkipAndMark(1); - in = ETrue; - continue; // back to in brace - } - else - lex.SkipSpaceAndMark(); - } - - aArray.AppendL(ptr); - - } - } - /* -LOCAL_C void DrawScanLineFilter(TUint16* aTarget, const TUint32* aSource, - TInt aTargetLen, TInt aScale, TInt aSrcPitch, TInt aSteps) - { - TInt delta = aScale; - TInt sourcePos = 0; - TInt len = aTargetLen; - TInt srcIndex = 0; - +{ - for(TInt i = 0; i < len; i++) - { - TInt steps = 0; - - sourcePos += delta; - - while(sourcePos >> 16 > 0) - { - ++steps; - ++srcIndex; - sourcePos -= 1 << 16; - }; - - TUint32 px; - TUint32 r = 0; - TUint32 g = 0; - TUint32 b = 0; - - TInt multip = 1; - - if(steps > 1) - { - px = aSource[srcIndex - 1]; - r += ((px & 0xF80000) >> 19); - g += ((px & 0xFC00) >> 10); - b += ((px & 0xF8) >> 3); - - px = aSource[srcIndex + 1]; - r += ((px & 0xF80000) >> 19); - g += ((px & 0xFC00) >> 10); - b += ((px & 0xF8) >> 3); - - multip = 2; - } - - if(aSteps > 1) - { - px = aSource[srcIndex - aSrcPitch]; - r += ((px & 0xF80000) >> 19); - g += ((px & 0xFC00) >> 10); - b += ((px & 0xF8) >> 3); - - px = aSource[srcIndex + aSrcPitch]; - r += ((px & 0xF80000) >> 19); - g += ((px & 0xFC00) >> 10); - b += ((px & 0xF8) >> 3); - - multip <<= 1; - } - - px = aSource[srcIndex]; - - TUint32 r0 = ((px & 0xF80000) >> 19); - TUint32 g0 = ((px & 0xFC00) >> 10); - TUint32 b0 = ((px & 0xF8) >> 3); - - - switch(multip) - { - case 1: - break; - case 2: - r0 <<= 1; - g0 <<= 1; - b0 <<= 1; - r0 += r; - g0 += g; - b0 += b; - r0 >>= 2; - g0 >>= 2; - b0 >>= 2; - break; - case 4: - r0 <<= 2; - g0 <<= 2; - b0 <<= 2; - r0 += r; - g0 += g; - b0 += b; - r0 >>= 3; - g0 >>= 3; - b0 >>= 3; - break; - } - - px = r0 << 11 | g0 << 5 | b0; - - aTarget[i] = px; - } - } + const TChar dq('\"'); -LOCAL_C void DrawBitmapFilter(TUint16* aTarget, const TUint32* aSrc, - const TSize& aTargetSize, const TSize& aSrcSize, - TInt aTargetStride, TInt aSrcStride) - { - TInt i; - - TInt sourcePos = 0; - - - ASSERT(aTargetSize.iHeight > 0); - ASSERT(aTargetSize.iWidth > 0); - - ASSERT(aSrcSize.iHeight > 1); - ASSERT(aSrcSize.iWidth > 1); - - - const TUint32* source = aSrc; - const TInt sourcePitch = aSrcStride >> 2; - - - TUint16* target = aTarget; - const TInt targetPitch = aTargetStride >> 1; - - const TInt sh = ((aSrcSize.iHeight - 1) << 16) / aTargetSize.iHeight; - const TInt sw = ((aSrcSize.iWidth - 1) << 16) /aTargetSize.iWidth; - - const TInt sourceDelta = sh; - - for(i = 0; i < aTargetSize.iHeight ; i++) - { - TInt steps = 0; - - sourcePos += sourceDelta; - - while(sourcePos >> 16 > 0) //this does source sampling - { - ++steps; - source += sourcePitch; - sourcePos -= 1 << 16; //jump remainder - } - - DrawScanLineFilter(target, source, aTargetSize.iWidth, sw, sourcePitch, steps); - - target += targetPitch; + TLex8 lex(aParam); + TBool in = EFalse; - } - - } -/* -LOCAL_C void DrawScanLineFilter(TUint32* aTarget, const TUint32* aSource, - TInt aTargetLen, TInt aScale, TInt aSrcPitch, TInt aSteps) - { - TInt delta = aScale; - TInt sourcePos = 0; - TInt len = aTargetLen; - TInt srcIndex = 0; - + lex.SkipSpaceAndMark(); - for(TInt i = 0; i < len; i++) + while(!lex.Eos()) + { + TPtrC8 ptr; + if(in) { - TInt steps = 0; - - sourcePos += delta; - - while(sourcePos >> 16 > 0) - { - ++steps; - ++srcIndex; - sourcePos -= 1 << 16; - }; - - TUint32 px; - TUint32 r = 0; - TUint32 g = 0; - TUint32 b = 0; - - TInt multip = 1; - - if(steps > 1) + const TPtrC8 rem = lex.RemainderFromMark(); + const TInt pos = rem.Locate(dq); + if(pos > 0) { - px = aSource[srcIndex - 1]; - r += ((px & 0xF80000) >> 19); - g += ((px & 0xFC00) >> 10); - b += ((px & 0xF8) >> 3); - - px = aSource[srcIndex + 1]; - r += ((px & 0xF80000) >> 19); - g += ((px & 0xFC00) >> 10); - b += ((px & 0xF8) >> 3); - - multip = 2; + lex.Inc(pos); + ptr.Set(lex.MarkedToken()); + lex.SkipAndMark(1); } - - if(aSteps > 1) + else { - px = aSource[srcIndex - aSrcPitch]; - r += ((px & 0xF80000) >> 19); - g += ((px & 0xFC00) >> 10); - b += ((px & 0xF8) >> 3); - - px = aSource[srcIndex + aSrcPitch]; - r += ((px & 0xF80000) >> 19); - g += ((px & 0xFC00) >> 10); - b += ((px & 0xF8) >> 3); - - multip <<= 1; + ptr.Set(rem); } - - px = aSource[srcIndex]; - - TUint32 r0 = ((px & 0xF80000) >> 19); - TUint32 g0 = ((px & 0xFC00) >> 10); - TUint32 b0 = ((px & 0xF8) >> 3); - - - switch(multip) + in = EFalse; + } + else + { + ptr.Set(lex.NextToken()); + const TInt pos = ptr.Locate(dq); + if(pos == 0) { - case 1: - break; - case 2: - r0 <<= 1; - g0 <<= 1; - b0 <<= 1; - r0 += r; - g0 += g; - b0 += b; - r0 >>= 2; - g0 >>= 2; - b0 >>= 2; - break; - case 4: - r0 <<= 2; - g0 <<= 2; - b0 <<= 2; - r0 += r; - g0 += g; - b0 += b; - r0 >>= 3; - g0 >>= 3; - b0 >>= 3; - break; + lex.UnGetToMark(); + lex.SkipAndMark(1); + in = ETrue; + continue; // back to in brace } - - px = r0 << 11 | g0 << 5 | b0; - - aTarget[i] = px; + else + lex.SkipSpaceAndMark(); } - } -LOCAL_C void DrawBitmapFilter(TUint32* aTarget, const TUint32* aSrc, - const TSize& aTargetSize, const TSize& aSrcSize, - TInt aTargetStride, TInt aSrcStride) - { - TInt i; - - TInt sourcePos = 0; - - - ASSERT(aTargetSize.iHeight > 0); - ASSERT(aTargetSize.iWidth > 0); - - ASSERT(aSrcSize.iHeight > 1); - ASSERT(aSrcSize.iWidth > 1); - - - const TUint32* source = aSrc; - const TInt sourcePitch = aSrcStride >> 2; - - - TUint32* target = aTarget; - const TInt targetPitch = aTargetStride >> 2; - - const TInt sh = ((aSrcSize.iHeight - 1) << 16) / aTargetSize.iHeight; - const TInt sw = ((aSrcSize.iWidth - 1) << 16) /aTargetSize.iWidth; - - const TInt sourceDelta = sh; - - for(i = 0; i < aTargetSize.iHeight ; i++) - { - TInt steps = 0; - - sourcePos += sourceDelta; - - while(sourcePos >> 16 > 0) //this does source sampling - { - ++steps; - source += sourcePitch; - sourcePos -= 1 << 16; //jump remainder - } - - DrawScanLineFilter(target, source, aTargetSize.iWidth, sw, sourcePitch, steps); - - target += targetPitch; + aArray.AppendL(ptr); - } - - } -*/ -/* -NONSHARABLE_CLASS(CBlitter) : public CBase, public MBlitter - { - public: - static CBlitter* NewL(); - ~CBlitter(); - TBool BitBlt(CBitmapContext& aGc, - CFbsBitmap& aBmp, - const TRect& aTargetRect, - const TSize& aSize); - private: - CFbsBitmap* iBitmap; - }; - -CBlitter::~CBlitter() - { - delete iBitmap; } - - -CBlitter* CBlitter::NewL() - { - CBlitter* b = new (ELeave) CBlitter(); - CleanupStack::PushL(b); - b->iBitmap = new (ELeave) CFbsBitmap(); - CleanupStack::Pop(); - return b; - } - -TBool CBlitter::BitBlt(CBitmapContext& aGc, - CFbsBitmap& aBmp, - const TRect& aTargetRect, - const TSize& aSize) - { - if(0 == iBitmap->Handle() || - iBitmap->SizeInPixels() != aTargetRect.Size()) - { - iBitmap->Reset(); - if(KErrNone != iBitmap->Create(aTargetRect.Size(), EColor64K)) - return EFalse; - } - - const TDisplayMode mode = aBmp.DisplayMode(); - - switch(mode) - { - case EColor16MA: - case EColor16MU: - case EColor16MAP: - break; - default: - return EFalse; - } - - aBmp.LockHeap(ETrue); - const TUint32* source = aBmp.DataAddress(); - TUint16* target = (TUint16*) iBitmap->DataAddress(); - DrawBitmapFilter(target, source, aTargetRect.Size(), aSize, aTargetRect.Size().iWidth * 2, aSize.iWidth * 4); - aBmp.UnlockHeap(); - aGc.BitBlt(TPoint(0, 0), iBitmap); - return ETrue; - } -*/ - +} + NONSHARABLE_CLASS(TVirtualCursor) : public MOverlay - { +{ public: TVirtualCursor(); void Set(const TRect& aRect, CFbsBitmap* aBmp, CFbsBitmap* aAlpha); @@ -445,7 +83,7 @@ NONSHARABLE_CLASS(TVirtualCursor) : public MOverlay void Toggle(); TBool IsOn() const; private: - void Draw(CBitmapContext& aGc, const TRect& aTargetRect, const TSize& aSize); + void Draw(CBitmapContext& aGc, const TRect& aTargetRect, const TSize& aSize); private: TRect iRect; TPoint iInc; @@ -453,93 +91,93 @@ NONSHARABLE_CLASS(TVirtualCursor) : public MOverlay TBool iIsOn; CFbsBitmap* iCBmp; CFbsBitmap* iAlpha; - }; - - +}; + + TVirtualCursor::TVirtualCursor() : iInc(0, 0), iIsOn(EFalse), iCBmp(NULL) - { - } - +{ +} + const TInt KMaxMove = 10; void TVirtualCursor::Move(TInt aX, TInt aY) - { +{ if(aX > 0 && iInc.iX > 0) - ++iInc.iX; + ++iInc.iX; else if(aX < 0 && iInc.iX < 0) - --iInc.iX; + --iInc.iX; else iInc.iX = aX; if(aY > 0 && iInc.iY > 0) - ++iInc.iY; + ++iInc.iY; else if(aY < 0 && iInc.iY < 0) - --iInc.iY; + --iInc.iY; else - iInc.iY = aY; - + iInc.iY = aY; + iInc.iX = Min(KMaxMove, iInc.iX); - + iInc.iX = Max(-KMaxMove, iInc.iX); - + iInc.iY = Min(KMaxMove, iInc.iY); - + iInc.iY =Max(-KMaxMove, iInc.iY); - + const TPoint pos = iPos + iInc; if(iRect.Contains(pos)) - { + { iPos = pos; - } + } else - { + { iInc = TPoint(0, 0); - } } - - +} + + void TVirtualCursor::Toggle() - { +{ iIsOn = !iIsOn; - } - - +} + + TBool TVirtualCursor::IsOn() const - { +{ return iIsOn; - } - +} + void TVirtualCursor::Set(const TRect& aRect, CFbsBitmap* aBmp, CFbsBitmap* aAlpha) - { +{ iRect = aRect; iCBmp = aBmp; iAlpha = aAlpha; - } - - +} + + void TVirtualCursor::MakeEvent(TWsEvent& aEvent, const TPoint& aBasePos) const - { - aEvent.SetType(EEventPointer), - aEvent.SetTimeNow(); +{ + aEvent.SetType(EEventPointer), + aEvent.SetTimeNow(); TPointerEvent& pointer = *aEvent.Pointer(); pointer.iType = TPointerEvent::EButton1Down; pointer.iPosition = iPos; pointer.iParentPosition = aBasePos; - } - - +} + + void TVirtualCursor::Draw(CBitmapContext& aGc, const TRect& /*aTargetRect*/, const TSize& /*aSize*/) - { +{ if(iIsOn && iCBmp != NULL) - { + { const TRect rect(TPoint(0, 0), iCBmp->SizeInPixels()); aGc.AlphaBlendBitmaps(iPos, iCBmp, rect, iAlpha, TPoint(0, 0)); - } - - } + } + +} NONSHARABLE_CLASS(TSdlClass) - { +{ public: TSdlClass(); void SetMain(const TMainFunc& aFunc, TInt aFlags, MSDLMainObs* aObs, TInt aExeFlags); @@ -553,106 +191,106 @@ NONSHARABLE_CLASS(TSdlClass) TInt iSdlFlags; TInt iExeFlags; MSDLMainObs* iObs; - }; - - +}; + + void TSdlClass::AppFlags(TInt aFlags) - { +{ iExeFlags |= aFlags; - } - +} + void TSdlClass::SendEvent(TInt aEvent, TInt aParam, CSDL* aSDL) - { +{ if(iObs != NULL) iObs->SDLMainEvent(aEvent, aParam, aSDL); - } - +} + TInt TSdlClass::AppFlags() const - { +{ return iExeFlags; - } - +} + void TSdlClass::SetMain(const TMainFunc& aFunc, TInt aFlags, MSDLMainObs* aObs, TInt aExeFlags) - { +{ iFunc = aFunc; iSdlFlags = aFlags; iExeFlags = aExeFlags; iObs = aObs; - } - +} + const TMainFunc& TSdlClass::Main() const - { +{ return iFunc; - } - - - TInt TSdlClass::SdlFlags() const - { - return iSdlFlags; - } - - - +} + + +TInt TSdlClass::SdlFlags() const +{ + return iSdlFlags; +} + + + TSdlClass::TSdlClass() - { +{ Mem::FillZ(this, sizeof(this)); - } - +} + TSdlClass gSDLClass; - - + + //////////////////////////////////////////////////////////////// NONSHARABLE_CLASS(CSDLApplication) : public CAknApplication - { - public: - CSDLApplication(); - private: - CApaDocument* CreateDocumentL(); - TFileName ResourceFileName() const; - TUid AppDllUid() const; - void FindMeL(); - TUid iUid; - }; - +{ + public: + CSDLApplication(); + private: + CApaDocument* CreateDocumentL(); + TFileName ResourceFileName() const; + TUid AppDllUid() const; + void FindMeL(); + TUid iUid; +}; + NONSHARABLE_CLASS(CSDLDocument) : public CEikDocument - { - public: - CSDLDocument(CEikApplication& aApp); - private: - CEikAppUi* CreateAppUiL(); - - }; - - //////////////////////////////////////////////////////////////////// - - +{ + public: + CSDLDocument(CEikApplication& aApp); + private: + CEikAppUi* CreateAppUiL(); + +}; + +//////////////////////////////////////////////////////////////////// + + NONSHARABLE_CLASS(MExitWait) - { - public: - virtual void DoExit(TInt aErr) = 0; - }; - +{ + public: + virtual void DoExit(TInt aErr) = 0; +}; + ///////////////////////////////////////////////////////////////////////// - + NONSHARABLE_CLASS(CExitWait) : public CActive - { - public: - CExitWait(MExitWait& aWait); - ~CExitWait(); - private: - void RunL(); - void DoCancel(); - private: - MExitWait& iWait; - TRequestStatus* iStatusPtr; - }; - +{ + public: + CExitWait(MExitWait& aWait); + ~CExitWait(); + private: + void RunL(); + void DoCancel(); + private: + MExitWait& iWait; + TRequestStatus* iStatusPtr; +}; + //////////////////////////////////////////////////////////////////////// - + NONSHARABLE_CLASS(CSDLWin) : public CCoeControl - { +{ public: void ConstructL(const TRect& aRect); RWindow& GetWindow() const; @@ -661,43 +299,43 @@ NONSHARABLE_CLASS(CSDLWin) : public CCoeControl void Draw(const TRect& aRect) const; private: TBool iNoDraw; - }; - +}; + //////////////////////////////////////////////////////////////////////////// - + NONSHARABLE_CLASS(CSDLAppUi) : public CAknAppUi, public MExitWait, public MSDLObserver - { +{ public: ~CSDLAppUi(); - private: // New functions - void ConstructL(); - void HandleCommandL(TInt aCommand); - void HandleWsEventL(const TWsEvent& aEvent, CCoeControl* aDestination); - void HandleResourceChangeL(TInt aType); - - void DoExit(TInt aErr); - - TInt SdlEvent(TInt aEvent, TInt aParam); - TInt SdlThreadEvent(TInt aEvent, TInt aParam); - - void StartL(); - static TBool StartL(TAny* aThis); - - TBool ParamEditorL(TDes& aCheat); - - TBool ProcessCommandParametersL(CApaCommandLine &aCommandLine); - - void PrepareToExit(); - void HandleConsoleWindowL(); - void HandleConsoleWindow(); - void HandleForegroundEventL(TBool aForeground); - - static TBool IdleRequestL(TAny* aThis); - - TBool HandleKeyL(const TWsEvent& aEvent); - - + private: // New functions + void ConstructL(); + void HandleCommandL(TInt aCommand); + void HandleWsEventL(const TWsEvent& aEvent, CCoeControl* aDestination); + void HandleResourceChangeL(TInt aType); + + void DoExit(TInt aErr); + + TInt SdlEvent(TInt aEvent, TInt aParam); + TInt SdlThreadEvent(TInt aEvent, TInt aParam); + + void StartL(); + static TBool StartL(TAny* aThis); + + TBool ParamEditorL(TDes& aCheat); + + TBool ProcessCommandParametersL(CApaCommandLine &aCommandLine); + + void PrepareToExit(); + void HandleConsoleWindowL(); + void HandleConsoleWindow(); + void HandleForegroundEventL(TBool aForeground); + + static TBool IdleRequestL(TAny* aThis); + + TBool HandleKeyL(const TWsEvent& aEvent); + + private: CExitWait* iWait; CSDLWin* iSDLWin; @@ -711,32 +349,29 @@ NONSHARABLE_CLASS(CSDLAppUi) : public CAknAppUi, public MExitWait, public MSDLOb TVirtualCursor iCursor; CFbsBitmap* iCBmp; CFbsBitmap* iAlpha; - // CBlitter* iBlitter; - // TTime iLastPress; - // CSDL::TOrientationMode iOrientation; - }; - +}; + ////////////////////////////////////////////////////////////////////////////////////////7 CApaDocument* CSDLApplication::CreateDocumentL() - { +{ return new (ELeave) CSDLDocument(*this); - } - +} + TUid CSDLApplication::AppDllUid() const - { +{ return iUid; - } - - +} + + CSDLApplication::CSDLApplication() - { +{ TRAPD(err, FindMeL()); ASSERT(err == KErrNone); - } - +} + void CSDLApplication::FindMeL() - { +{ RApaLsSession apa; User::LeaveIfError(apa.Connect()); CleanupClosePushL(apa); @@ -744,96 +379,96 @@ void CSDLApplication::FindMeL() TFileName name = RProcess().FileName(); TApaAppInfo info; while(apa.GetNextApp(info) == KErrNone) - { + { if(info.iFullName.CompareF(name) == 0) - { + { iUid = info.iUid; break; - } } - CleanupStack::PopAndDestroy(); } - + CleanupStack::PopAndDestroy(); +} + TFileName CSDLApplication::ResourceFileName() const - { +{ return KNullDesC(); - } - +} + /////////////////////////////////////////////////////////////////////////////////////////// CExitWait::CExitWait(MExitWait& aWait) : CActive(CActive::EPriorityStandard), iWait(aWait) - { +{ CActiveScheduler::Add(this); SetActive(); iStatusPtr = &iStatus; - } - +} + CExitWait::~CExitWait() - { +{ Cancel(); - } - +} + void CExitWait::RunL() - { +{ if(iStatusPtr != NULL ) iWait.DoExit(iStatus.Int()); - } - +} + void CExitWait::DoCancel() - { +{ if(iStatusPtr != NULL ) User::RequestComplete(iStatusPtr , KErrCancel); - } - +} + ////////////////////////////////////////////////////////////////////////////////////////////// CSDLDocument::CSDLDocument(CEikApplication& aApp) : CEikDocument(aApp) - {} - +{} + CEikAppUi* CSDLDocument::CreateAppUiL() - { +{ return new (ELeave) CSDLAppUi; - } - +} + /////////////////////////////////////////////////////////////////////////// - + void CSDLWin:: ConstructL(const TRect& aRect) - { +{ CreateWindowL(); SetRect(aRect); ActivateL(); - } - - +} + + RWindow& CSDLWin::GetWindow() const - { +{ return Window(); - } - +} + void CSDLWin::Draw(const TRect& /*aRect*/) const - { +{ if(!iNoDraw) - { + { CWindowGc& gc = SystemGc(); gc.SetPenStyle(CGraphicsContext::ESolidPen); gc.SetPenColor(KRgbGray); gc.SetBrushStyle(CGraphicsContext::ESolidBrush); - gc.SetBrushColor(0xaaaaaa); + gc.SetBrushColor(0x000000); gc.DrawRect(Rect()); - } - } - + } +} + void CSDLWin::SetNoDraw() - { +{ iNoDraw = ETrue; - } +} ///////////////////////////////////////////////////////////////////////// - + CSDLAppUi::~CSDLAppUi() - { +{ if(iIdle) iIdle->Cancel(); delete iIdle; @@ -846,170 +481,165 @@ CSDLAppUi::~CSDLAppUi() delete iParams; delete iCBmp; delete iAlpha; -// delete iBlitter; - } - - +} + + void CSDLAppUi::ConstructL() - { - BaseConstructL(ENoAppResourceFile | ENoScreenFurniture); - - - RLibrary lib; - User::LeaveIfError(lib.Load(_L("sdlexe.dll"))); - TFileName name = lib.FileName(); - lib.Close(); - name.Replace(3, name.Length() - 3, _L("resource\\apps\\sdlexe.rsc")); - BaflUtils::NearestLanguageFile(iEikonEnv->FsSession(), name); - iResOffset = iCoeEnv->AddResourceFileL(name); - - name.Replace(name.Length() - 3, 3, _L("mbm")); - +{ + BaseConstructL(ENoAppResourceFile | ENoScreenFurniture); + + + RLibrary lib; + User::LeaveIfError(lib.Load(_L("sdlexe.dll"))); + TFileName name = lib.FileName(); + lib.Close(); + name.Replace(3, name.Length() - 3, _L("resource\\apps\\sdlexe.rsc")); + BaflUtils::NearestLanguageFile(iEikonEnv->FsSession(), name); + iResOffset = iCoeEnv->AddResourceFileL(name); + + name.Replace(name.Length() - 3, 3, _L("mbm")); + TEntry e; const TInt err = iEikonEnv->FsSession().Entry(name, e); - + iCBmp = iEikonEnv->CreateBitmapL(name, 0); iAlpha = iEikonEnv->CreateBitmapL(name, 1); - - iIdle = CIdle::NewL(CActive::EPriorityIdle); - - iSDLWin = new (ELeave) CSDLWin; - iSDLWin->ConstructL(ApplicationRect()); - - iSdl = CSDL::NewL(gSDLClass.SdlFlags()); - - gSDLClass.SendEvent(MSDLMainObs::ESDLCreated, 0, iSdl); - - iSdl->SetObserver(this); - iSdl->DisableKeyBlocking(*this); - iSdl->SetContainerWindowL( - iSDLWin->GetWindow(), - iEikonEnv->WsSession(), - *iEikonEnv->ScreenDevice()); - iSdl->AppendOverlay(iCursor, 0); - - // iBlitter = CBlitter::NewL(); - - // iSdl->SetBlitter(iBlitter); - - iCursor.Set(TRect(TPoint(0, 0), iSDLWin->Size()), iCBmp, iAlpha); - - iStarter = CIdle::NewL(CActive::EPriorityLow); - iStarter->Start(TCallBack(StartL, this)); - - - } - + + iIdle = CIdle::NewL(CActive::EPriorityIdle); + + iSDLWin = new (ELeave) CSDLWin; + iSDLWin->ConstructL(ApplicationRect()); + + iSdl = CSDL::NewL(gSDLClass.SdlFlags()); + + gSDLClass.SendEvent(MSDLMainObs::ESDLCreated, 0, iSdl); + + iSdl->SetObserver(this); + iSdl->DisableKeyBlocking(*this); + iSdl->SetContainerWindowL( + iSDLWin->GetWindow(), + iEikonEnv->WsSession(), + *iEikonEnv->ScreenDevice()); + iSdl->AppendOverlay(iCursor, 0); + + iCursor.Set(TRect(TPoint(0, 0), iSDLWin->Size()), iCBmp, iAlpha); + + iStarter = CIdle::NewL(CActive::EPriorityLow); + iStarter->Start(TCallBack(StartL, this)); + + +} + TBool CSDLAppUi::StartL(TAny* aThis) - { +{ static_cast(aThis)->StartL(); return EFalse; - } - - +} + + void CSDLAppUi::PrepareToExit() - { +{ CAknAppUiBase::PrepareToExit(); //aknappu::PrepareToExit crashes iCoeEnv->DeleteResourceFile(iResOffset); - } - +} + TBool CSDLAppUi::ProcessCommandParametersL(CApaCommandLine &aCommandLine) - { +{ const TPtrC8 cmdLine = aCommandLine.TailEnd(); iParams = new (ELeave) CDesC8ArrayFlat(8); MakeCCmdLineL(cmdLine, *iParams); return EFalse; - } - - - TBool CSDLAppUi::ParamEditorL(TDes& aCheat) - { +} + + +TBool CSDLAppUi::ParamEditorL(TDes& aCheat) +{ CAknTextQueryDialog* query = CAknTextQueryDialog::NewL(aCheat); CleanupStack::PushL(query); query->SetPromptL(_L("Enter parameters")); CleanupStack::Pop(); return query->ExecuteLD(R_PARAMEDITOR); +} + +void CSDLAppUi::StartL() +{ + if(gSDLClass.AppFlags() & SDLEnv::EParamQuery) + { + TBuf8<256> cmd; + RFile file; + TInt err = file.Open(iEikonEnv->FsSession(), _L("sdl_param.txt"),EFileRead); + if(err == KErrNone) + { + file.Read(cmd); + file.Close(); + MakeCCmdLineL(cmd, *iParams); + } + if(err != KErrNone || gSDLClass.AppFlags() & (SDLEnv::EParamQueryDialog ^ SDLEnv::EParamQuery)) + { + TBuf<256> buffer; + if(ParamEditorL(buffer)) + { + cmd.Copy(buffer); + MakeCCmdLineL(cmd, *iParams); + } + } } - - void CSDLAppUi::StartL() - { - if(gSDLClass.AppFlags() & SDLEnv::EParamQuery) - { - TBuf8<256> cmd; - RFile file; - TInt err = file.Open(iEikonEnv->FsSession(), _L("sdl_param.txt"),EFileRead); - if(err == KErrNone) - { - file.Read(cmd); - file.Close(); - MakeCCmdLineL(cmd, *iParams); - } - if(err != KErrNone || gSDLClass.AppFlags() & (SDLEnv::EParamQueryDialog ^ SDLEnv::EParamQuery)) - { - TBuf<256> buffer; - if(ParamEditorL(buffer)) - { - cmd.Copy(buffer); - MakeCCmdLineL(cmd, *iParams); - } - } - } - iWait = new (ELeave) CExitWait(*this); - iSdl->CallMainL(gSDLClass.Main(), &iWait->iStatus, iParams, CSDL::ENoParamFlags, 0xA000); - } - + iWait = new (ELeave) CExitWait(*this); + iSdl->CallMainL(gSDLClass.Main(), &iWait->iStatus, iParams, CSDL::ENoParamFlags, 0xA000); +} + void CSDLAppUi::HandleCommandL(TInt aCommand) - { +{ switch(aCommand) - { + { case EAknSoftkeyBack: - case EAknSoftkeyExit: + case EAknSoftkeyExit: case EAknCmdExit: case EEikCmdExit: gSDLClass.AppFlags(SDLEnv::EAllowConsoleView); - if(iWait == NULL || !iWait->IsActive() || iSdl == NULL) - { - Exit(); - } - else if(!iExitRequest) - { - TWsEvent event; - event.SetType(EEventSwitchOff), - event.SetTimeNow(); - iSdl->AppendWsEvent(event); - User::After(1000000); - iExitRequest = ETrue; //trick how SDL can be closed! - iSdl->Suspend(); - } + if(iWait == NULL || !iWait->IsActive() || iSdl == NULL) + { + Exit(); + } + else if(!iExitRequest) + { + TWsEvent event; + event.SetType(EEventSwitchOff), + event.SetTimeNow(); + iSdl->AppendWsEvent(event); + User::After(1000000); + iExitRequest = ETrue; //trick how SDL can be closed! + iSdl->Suspend(); + } break; - } } - +} + + - TBool CSDLAppUi::HandleKeyL(const TWsEvent& aEvent) - { +{ const TInt type = aEvent.Type(); if(!(type == EEventKey || type == EEventKeyUp || type == EEventKeyDown)) - { - return ETrue; - } - const TKeyEvent& key = *aEvent.Key(); + { + return ETrue; + } + const TKeyEvent& key = *aEvent.Key(); if((key.iScanCode == EStdKeyYes) && (gSDLClass.AppFlags() & SDLEnv::EVirtualMouse)) - { - if(type == EEventKeyUp) - { - iCursor.Toggle(); - iSdl->RedrawRequest(); - } - return EFalse; + { + if(type == EEventKeyUp) + { + iCursor.Toggle(); + iSdl->RedrawRequest(); } + return EFalse; + } if(iCursor.IsOn()) - { + { switch(key.iScanCode) - { + { case EStdKeyUpArrow: iCursor.Move(0, -1); break; @@ -1024,53 +654,53 @@ TBool CSDLAppUi::HandleKeyL(const TWsEvent& aEvent) break; case EStdKeyDevice3: if(type == EEventKeyUp) - { + { TWsEvent event; iCursor.MakeEvent(event, iSDLWin->Position()); iSdl->AppendWsEvent(event); - } + } return EFalse; default: return ETrue; - } + } iSdl->RedrawRequest(); return EFalse; - } + } return ETrue; +} + +void CSDLAppUi::HandleWsEventL(const TWsEvent& aEvent, CCoeControl* aDestination) +{ + if(iSdl && iWait && HandleKeyL(aEvent)) + iSdl->AppendWsEvent(aEvent); + CAknAppUi::HandleWsEventL(aEvent, aDestination); +} + +void CSDLAppUi::HandleResourceChangeL(TInt aType) +{ + CAknAppUi::HandleResourceChangeL(aType); + if(aType == KEikDynamicLayoutVariantSwitch) + { + iSDLWin->SetRect(ApplicationRect()); + iSdl->SetContainerWindowL( + iSDLWin->GetWindow(), + iEikonEnv->WsSession(), + *iEikonEnv->ScreenDevice()); } - - void CSDLAppUi::HandleWsEventL(const TWsEvent& aEvent, CCoeControl* aDestination) - { - if(iSdl && iWait && HandleKeyL(aEvent)) - iSdl->AppendWsEvent(aEvent); - CAknAppUi::HandleWsEventL(aEvent, aDestination); - } - - void CSDLAppUi::HandleResourceChangeL(TInt aType) - { - CAknAppUi::HandleResourceChangeL(aType); - if(aType == KEikDynamicLayoutVariantSwitch) - { - iSDLWin->SetRect(ApplicationRect()); - iSdl->SetContainerWindowL( - iSDLWin->GetWindow(), - iEikonEnv->WsSession(), - *iEikonEnv->ScreenDevice()); - } - } - - +} + + void CSDLAppUi::DoExit(TInt/*Err*/) - { - iExitRequest = ETrue; - Exit(); - } +{ + iExitRequest = ETrue; + Exit(); +} - - TInt CSDLAppUi::SdlThreadEvent(TInt aEvent, TInt /*aParam*/) - { + +TInt CSDLAppUi::SdlThreadEvent(TInt aEvent, TInt /*aParam*/) +{ switch(aEvent) - { + { case MSDLObserver::EEventResume: break; case MSDLObserver::EEventSuspend: @@ -1082,15 +712,15 @@ void CSDLAppUi::DoExit(TInt/*Err*/) case MSDLObserver::EEventWindowNotAvailable: break; case MSDLObserver::EEventScreenSizeChanged: - break; - } - return MSDLObserver::EParameterNone; + break; } - + return MSDLObserver::EParameterNone; +} + TInt CSDLAppUi::SdlEvent(TInt aEvent, TInt /*aParam*/) - { +{ switch(aEvent) - { + { case MSDLObserver::EEventResume: break; case MSDLObserver::EEventSuspend: @@ -1101,85 +731,82 @@ TInt CSDLAppUi::SdlEvent(TInt aEvent, TInt /*aParam*/) break; case MSDLObserver::EEventWindowNotAvailable: { - TRAP_IGNORE(HandleConsoleWindowL()); + TRAP_IGNORE(HandleConsoleWindowL()); } break; case MSDLObserver::EEventScreenSizeChanged: - break; + break; case MSDLObserver::EEventKeyMapInit: break; case MSDLObserver::EEventMainExit: if(iStdOut != 0) - { + { gSDLClass.AppFlags(SDLEnv::EAllowConsoleView); iEikonEnv->WsSession().SetWindowGroupOrdinalPosition(iStdOut, 0); - } + } break; - } - return MSDLObserver::EParameterNone; } - + return MSDLObserver::EParameterNone; +} + void CSDLAppUi::HandleForegroundEventL(TBool aForeground) - { +{ CAknAppUi::HandleForegroundEventL(aForeground); if(!aForeground) HandleConsoleWindow(); - } - +} + void CSDLAppUi::HandleConsoleWindow() - { +{ if(!iIdle->IsActive()) iIdle->Start(TCallBack(IdleRequestL, this)); - } - +} + TBool CSDLAppUi::IdleRequestL(TAny* aThis) - { +{ static_cast(aThis)->HandleConsoleWindowL(); return EFalse; - } +} void CSDLAppUi::HandleConsoleWindowL() - { +{ if(gSDLClass.AppFlags() & SDLEnv::EAllowConsoleView) - { + { return; - } + } RWsSession& ses = iEikonEnv->WsSession(); const TInt focus = ses.GetFocusWindowGroup(); CApaWindowGroupName* name = CApaWindowGroupName::NewLC(ses, focus); const TPtrC caption = name->Caption(); if(0 == caption.CompareF(_L("STDOUT"))) - { + { iStdOut = focus; ses.SetWindowGroupOrdinalPosition(iEikonEnv->RootWin().Identifier(), 0); - } - CleanupStack::PopAndDestroy(); //name } - - - - + CleanupStack::PopAndDestroy(); //name +} + + + + //////////////////////////////////////////////////////////////////////// CApaApplication* NewApplication() - { - return new CSDLApplication(); - } +{ + return new CSDLApplication(); +} + - EXPORT_C TInt SDLEnv::SetMain(const TMainFunc& aFunc, TInt aSdlFlags, MSDLMainObs* aObs, TInt aSdlExeFlags) - { +{ gSDLClass.SetMain(aFunc, aSdlFlags, aObs, aSdlExeFlags); - return EikStart::RunApplication(NewApplication); - } - + return EikStart::RunApplication(NewApplication); +} + ////////////////////////////////////////////////////////////////////// TInt SDLUiPrint(const TDesC8& /*aInfo*/) - { - return KErrNotFound; - } - - - +{ + return KErrNotFound; +} diff --git a/src/main/symbian/vectorbuffer.cpp b/src/main/symbian/vectorbuffer.cpp dissimilarity index 76% index f301dbd..1969f5e 100644 --- a/src/main/symbian/vectorbuffer.cpp +++ b/src/main/symbian/vectorbuffer.cpp @@ -1,59 +1,52 @@ -/* - vectorbuffer.cpp - yet another circle buffer - - Markus Mertama -*/ - -#include"vectorbuffer.h" - - - -void VectorPanic(TInt aErr, TInt aLine) - { - TBuf<64> b; - b.Format(_L("vector buffer at % d "), aLine); - User::Panic(b, aErr); - } - -void TNodeBuffer::TNode::Terminator(TNodeBuffer::TNode* aNode) - { - Mem::Copy(iSucc, &aNode, sizeof(TNode*)); - } - -TInt TNodeBuffer::TNode::Size() const - { - return reinterpret_cast(iSucc) - Ptr(); - } - -const TUint8* TNodeBuffer::TNode::Ptr() const - { - return reinterpret_cast(this) + sizeof(TNode); - } - -TNodeBuffer::TNode* TNodeBuffer::TNode::Empty(TUint8* aBuffer) - { - TNode* node = reinterpret_cast(aBuffer); - node->iSucc = node + 1; - return node; - } - - TNodeBuffer::TNode* TNodeBuffer::TNode::New(TNode* aPred, const TDesC8& aData) - { - TNode* node = aPred->Size() == 0 ? aPred : aPred->iSucc; - - - TUint8* start = reinterpret_cast(node) + sizeof(TNode); - node->iSucc = reinterpret_cast(start + aData.Size()); - node->iSucc->iSucc = NULL; //terminator - - __ASSERT_DEBUG(node->Size() == aData.Size(), VECPANIC(KErrCorrupt)); - - Mem::Copy(start, aData.Ptr(), aData.Size()); - return node; - } - - - - - +/* + vectorbuffer.cpp + yet another circle buffer + + Markus Mertama + */ + +#include"vectorbuffer.h" + +void VectorPanic(TInt aErr, TInt aLine) +{ + TBuf<64> b; + b.Format(_L("vector buffer at % d "), aLine); + User::Panic(b, aErr); +} + +void TNodeBuffer::TNode::Terminator(TNodeBuffer::TNode* aNode) +{ + Mem::Copy(iSucc, &aNode, sizeof(TNode*)); +} + +TInt TNodeBuffer::TNode::Size() const +{ + return reinterpret_cast(iSucc) - Ptr(); +} + +const TUint8* TNodeBuffer::TNode::Ptr() const +{ + return reinterpret_cast(this) + sizeof(TNode); +} + +TNodeBuffer::TNode* TNodeBuffer::TNode::Empty(TUint8* aBuffer) +{ + TNode* node = reinterpret_cast(aBuffer); + node->iSucc = node + 1; + return node; +} + +TNodeBuffer::TNode* TNodeBuffer::TNode::New(TNode* aPred, const TDesC8& aData) +{ + TNode* node = aPred->Size() == 0 ? aPred : aPred->iSucc; + + + TUint8* start = reinterpret_cast(node) + sizeof(TNode); + node->iSucc = reinterpret_cast(start + aData.Size()); + node->iSucc->iSucc = NULL; //terminator + + __ASSERT_DEBUG(node->Size() == aData.Size(), VECPANIC(KErrCorrupt)); + + Mem::Copy(start, aData.Ptr(), aData.Size()); + return node; +} diff --git a/src/main/symbian/vectorbuffer.h b/src/main/symbian/vectorbuffer.h dissimilarity index 77% index 08eec18..8a12055 100644 --- a/src/main/symbian/vectorbuffer.h +++ b/src/main/symbian/vectorbuffer.h @@ -1,221 +1,221 @@ -/* - vectorbuffer.cpp - yet another circle buffer - - Markus Mertama -*/ - -#ifndef __VECTORBUFFER_H__ -#define __VECTORBUFFER_H__ - -#include -#define VECPANIC(x) VectorPanic(x, __LINE__) -void VectorPanic(TInt, TInt); - - -//Internal - -NONSHARABLE_CLASS(TNodeBuffer) - { - public: - protected: - NONSHARABLE_CLASS(TNode) - { - public: - static TNode* Empty(TUint8* iBuffer); - static TNode* New(TNode* aPrev, const TDesC8& aData); - const TUint8* Ptr() const; - TInt Size() const; - inline TNode* Succ(); - static void SetSucc(TNode*& aNode); - void Terminator(TNode* aNode); - private: - TNode* iSucc; - }; - }; - -inline TNodeBuffer::TNode* TNodeBuffer::TNode::Succ() - { - return iSucc; - } - - -//Vector buffer for variable length data - -template -NONSHARABLE_CLASS(TVectorBuffer) : public TNodeBuffer - { - public: - TVectorBuffer(); - TInt Append(const TDesC8& aData); - TPtrC8 Shift(); - TPtrC8 operator[](TInt aIndex) const; - TInt Size() const; - private: - TInt GetRoom(TInt aSize) const; - TInt Unreserved() const; - private: - TNode* iTop; - TNode* iBottom; - TInt iSize; - TUint8 iBuffer[C]; - }; - -template -TVectorBuffer::TVectorBuffer() : iSize(0) - { - Mem::FillZ(iBuffer, C); - iTop = TNode::Empty(iBuffer); //these points to buffer - iBottom = TNode::Empty(iBuffer); - } - -template -TInt TVectorBuffer::Unreserved() const - { - __ASSERT_DEBUG(iBottom < iBottom->Succ(), VECPANIC(KErrCorrupt)); - const TInt bytesbetween = - reinterpret_cast(iBottom->Succ()) - - reinterpret_cast(iTop); - const TInt topsize = sizeof(TNode); - if(bytesbetween > 0) //bytesbetween is room between bottom and top - { //therefore free room is subracted from free space - - const TInt room = C - bytesbetween - topsize; - return room; - } - if(bytesbetween == 0) - { - - if(Size() > 0) - return 0; - else - return C - topsize; - } - const TInt room = -bytesbetween - topsize; //free is space between pointers - return room; - } - -template -TInt TVectorBuffer::GetRoom(TInt aSize) const - { - const TInt bytesnew = sizeof(TNode) + aSize; - const TInt room = Unreserved() - bytesnew; - return room; - } - -template -TInt TVectorBuffer::Append(const TDesC8& aData) - { - const TInt len = aData.Length(); - if(GetRoom(len) < 0) - { - return KErrOverflow; - } - if(iBottom->Succ()->Ptr() - iBuffer > (C - (len + TInt(sizeof(TNode))))) - { - - TNode* p = TNode::Empty(iBuffer); - iBottom->Terminator(p); - iBottom = p; - return Append(aData); - } - - - iBottom = TNode::New(iBottom, aData); - - iSize += len; - return KErrNone; - } - -template -TPtrC8 TVectorBuffer::Shift() - { - __ASSERT_ALWAYS(iTop->Succ() != NULL, VECPANIC(KErrUnderflow)); //can never pass-by bottom - TNode* node = iTop; - iTop = iTop->Succ(); - if(iTop > node) - { - iSize -= node->Size(); - return TPtrC8(node->Ptr(), node->Size()); - } - else - { - return Shift(); //this happens when buffer is terminated, and data lies in next - } - } - -template -TInt TVectorBuffer::Size() const - { - return iSize; - } - -template -TPtrC8 TVectorBuffer::operator[](TInt aIndex) const - { - TInt index = 0; - TNode* t = iTop->Size() > 0 ? iTop : iTop->Succ(); //eliminate terminator - while(index < aIndex) - { - TNode* nt = t->Succ(); - if(nt < t) - { - nt = nt->Succ(); - } - t = nt; - if(t->Size() > 0) - index++; - __ASSERT_ALWAYS(t->Succ() != NULL, VECPANIC(KErrUnderflow)); //can never pass-by bottom - } - return t->Ptr(); - } - -//Vector buffer for fixed length data - -template -NONSHARABLE_CLASS(TVector) : public TVectorBuffer - { - public: - TVector(); - TInt Append(const T& aData); - const T& Shift(); - TInt Size() const; - const T& operator[](TInt aIndex) const; - }; - -template -TVector::TVector() : TVectorBuffer() - { - } - -template -TInt TVector::Append(const T& aData) - { - const TPckgC data(aData); - return TVectorBuffer::Append(data); - } - -template -const T& TVector::Shift() - { - const TPtrC8 ptr = TVectorBuffer::Shift(); - return *(reinterpret_cast(ptr.Ptr())); - } - - -template -TInt TVector::Size() const - { - return TVectorBuffer::Size() / sizeof(T); - } - -template -const T& TVector::operator[](TInt aIndex) const - { - const TPtrC8 ptr = TVectorBuffer::operator[](aIndex); - return *(reinterpret_cast(ptr.Ptr())); - } - -#endif - - +/* + vectorbuffer.cpp + yet another circle buffer + + Markus Mertama + */ + +#ifndef __VECTORBUFFER_H__ +#define __VECTORBUFFER_H__ + +#include +#define VECPANIC(x) VectorPanic(x, __LINE__) +void VectorPanic(TInt, TInt); + + +//Internal + +NONSHARABLE_CLASS(TNodeBuffer) +{ + public: + protected: + NONSHARABLE_CLASS(TNode) + { + public: + static TNode* Empty(TUint8* iBuffer); + static TNode* New(TNode* aPrev, const TDesC8& aData); + const TUint8* Ptr() const; + TInt Size() const; + inline TNode* Succ(); + static void SetSucc(TNode*& aNode); + void Terminator(TNode* aNode); + private: + TNode* iSucc; + }; +}; + +inline TNodeBuffer::TNode* TNodeBuffer::TNode::Succ() +{ + return iSucc; +} + + +//Vector buffer for variable length data + +template +NONSHARABLE_CLASS(TVectorBuffer) : public TNodeBuffer +{ + public: + TVectorBuffer(); + TInt Append(const TDesC8& aData); + TPtrC8 Shift(); + TPtrC8 operator[](TInt aIndex) const; + TInt Size() const; + private: + TInt GetRoom(TInt aSize) const; + TInt Unreserved() const; + private: + TNode* iTop; + TNode* iBottom; + TInt iSize; + TUint8 iBuffer[C]; +}; + + template +TVectorBuffer::TVectorBuffer() : iSize(0) +{ + Mem::FillZ(iBuffer, C); + iTop = TNode::Empty(iBuffer); //these points to buffer + iBottom = TNode::Empty(iBuffer); +} + +template +TInt TVectorBuffer::Unreserved() const +{ + __ASSERT_DEBUG(iBottom < iBottom->Succ(), VECPANIC(KErrCorrupt)); + const TInt bytesbetween = + reinterpret_cast(iBottom->Succ()) - + reinterpret_cast(iTop); + const TInt topsize = sizeof(TNode); + if(bytesbetween > 0) //bytesbetween is room between bottom and top + { //therefore free room is subracted from free space + + const TInt room = C - bytesbetween - topsize; + return room; + } + if(bytesbetween == 0) + { + + if(Size() > 0) + return 0; + else + return C - topsize; + } + const TInt room = -bytesbetween - topsize; //free is space between pointers + return room; +} + +template +TInt TVectorBuffer::GetRoom(TInt aSize) const +{ + const TInt bytesnew = sizeof(TNode) + aSize; + const TInt room = Unreserved() - bytesnew; + return room; +} + + template +TInt TVectorBuffer::Append(const TDesC8& aData) +{ + const TInt len = aData.Length(); + if(GetRoom(len) < 0) + { + return KErrOverflow; + } + if(iBottom->Succ()->Ptr() - iBuffer > (C - (len + TInt(sizeof(TNode))))) + { + + TNode* p = TNode::Empty(iBuffer); + iBottom->Terminator(p); + iBottom = p; + return Append(aData); + } + + + iBottom = TNode::New(iBottom, aData); + + iSize += len; + return KErrNone; +} + + template +TPtrC8 TVectorBuffer::Shift() +{ + __ASSERT_ALWAYS(iTop->Succ() != NULL, VECPANIC(KErrUnderflow)); //can never pass-by bottom + TNode* node = iTop; + iTop = iTop->Succ(); + if(iTop > node) + { + iSize -= node->Size(); + return TPtrC8(node->Ptr(), node->Size()); + } + else + { + return Shift(); //this happens when buffer is terminated, and data lies in next + } +} + +template +TInt TVectorBuffer::Size() const +{ + return iSize; +} + +template +TPtrC8 TVectorBuffer::operator[](TInt aIndex) const +{ + TInt index = 0; + TNode* t = iTop->Size() > 0 ? iTop : iTop->Succ(); //eliminate terminator + while(index < aIndex) + { + TNode* nt = t->Succ(); + if(nt < t) + { + nt = nt->Succ(); + } + t = nt; + if(t->Size() > 0) + index++; + __ASSERT_ALWAYS(t->Succ() != NULL, VECPANIC(KErrUnderflow)); //can never pass-by bottom + } + return t->Ptr(); +} + +//Vector buffer for fixed length data + +template +NONSHARABLE_CLASS(TVector) : public TVectorBuffer +{ + public: + TVector(); + TInt Append(const T& aData); + const T& Shift(); + TInt Size() const; + const T& operator[](TInt aIndex) const; +}; + + template +TVector::TVector() : TVectorBuffer() +{ +} + + template +TInt TVector::Append(const T& aData) +{ + const TPckgC data(aData); + return TVectorBuffer::Append(data); +} + + template +const T& TVector::Shift() +{ + const TPtrC8 ptr = TVectorBuffer::Shift(); + return *(reinterpret_cast(ptr.Ptr())); +} + + +template +TInt TVector::Size() const +{ + return TVectorBuffer::Size() / sizeof(T); +} + +template +const T& TVector::operator[](TInt aIndex) const +{ + const TPtrC8 ptr = TVectorBuffer::operator[](aIndex); + return *(reinterpret_cast(ptr.Ptr())); +} + +#endif + + diff --git a/src/thread/symbian/SDL_sysmutex.cpp b/src/thread/symbian/SDL_sysmutex.cpp dissimilarity index 66% index ac20744..4ddef4c 100644 --- a/src/thread/symbian/SDL_sysmutex.cpp +++ b/src/thread/symbian/SDL_sysmutex.cpp @@ -1,130 +1,116 @@ -/* - SDL - Simple DirectMedia Layer - Copyright (C) 1997, 1998, 1999, 2000 Sam Lantinga - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with this library; if not, write to the Free - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - - Sam Lantinga - slouken@devolution.com -*/ - -/* - SDL_sysmutex.cpp - - Epoc version by Markus Mertama (w@iki.fi) -*/ - - -#ifdef SAVE_RCSID -static char rcsid = - "@(#) $Id: SDL_sysmutex.c,v 1.1.2.3 2000/06/22 15:25:23 hercules Exp $"; -#endif - -/* Mutex functions using the Win32 API */ - -//#include -//#include - -#include - -#include "epoc_sdl.h" - -#include "SDL_error.h" -#include "SDL_mutex.h" - - -#ifdef EKA2 //??? -struct SDL_mutex - { - TInt handle; - }; -#else -struct _SDL_mutex - { - TInt handle; - }; -#endif - -extern TInt CreateUnique(TInt (*aFunc)(const TDesC& aName, TAny*, TAny*), TAny*, TAny*); - -TInt NewMutex(const TDesC& aName, TAny* aPtr1, TAny*) - { - return ((RMutex*)aPtr1)->CreateGlobal(aName); - } - -void DeleteMutex(TAny* aMutex) - { - SDL_DestroyMutex ((SDL_mutex*) aMutex); - } - -/* Create a mutex */ -SDL_mutex *SDL_CreateMutex(void) -{ - RMutex rmutex; - - TInt status = CreateUnique(NewMutex, &rmutex, NULL); - if(status != KErrNone) - { - SDL_SetError("Couldn't create mutex"); - } - SDL_mutex* mutex = new /*(ELeave)*/ SDL_mutex; - mutex->handle = rmutex.Handle(); - EpocSdlEnv::AppendCleanupItem(TSdlCleanupItem(DeleteMutex, mutex)); - return(mutex); -} - -/* Free the mutex */ -void SDL_DestroyMutex(SDL_mutex *mutex) -{ - if ( mutex ) - { - RMutex rmutex; - rmutex.SetHandle(mutex->handle); - if(rmutex.IsHeld()) - { - rmutex.Signal(); - } - rmutex.Close(); - EpocSdlEnv::RemoveCleanupItem(mutex); - delete(mutex); - mutex = NULL; - } -} - -/* Lock the mutex */ -int SDL_mutexP(SDL_mutex *mutex) -{ - if ( mutex == NULL ) { - SDL_SetError("Passed a NULL mutex"); - return -1; - } - RMutex rmutex; - rmutex.SetHandle(mutex->handle); - rmutex.Wait(); - return(0); -} - -/* Unlock the mutex */ -int SDL_mutexV(SDL_mutex *mutex) -{ - if ( mutex == NULL ) { - SDL_SetError("Passed a NULL mutex"); - return -1; - } - RMutex rmutex; - rmutex.SetHandle(mutex->handle); - rmutex.Signal(); - return(0); -} +/* + SDL - Simple DirectMedia Layer + Copyright (C) 1997, 1998, 1999, 2000 Sam Lantinga + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; if not, write to the Free + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + Sam Lantinga + slouken@devolution.com + */ + +/* + SDL_sysmutex.cpp + + Epoc version by Markus Mertama (w@iki.fi) + */ + +/* Mutex functions using the Win32 API */ + +//#include +//#include + +#include + +#include "epoc_sdl.h" + +#include "SDL_error.h" +#include "SDL_mutex.h" + +struct SDL_mutex +{ + TInt handle; +}; + +extern TInt CreateUnique(TInt (*aFunc)(const TDesC& aName, TAny*, TAny*), TAny*, TAny*); + +TInt NewMutex(const TDesC& aName, TAny* aPtr1, TAny*) +{ + return ((RMutex*)aPtr1)->CreateGlobal(aName); +} + +void DeleteMutex(TAny* aMutex) +{ + SDL_DestroyMutex ((SDL_mutex*) aMutex); +} + +/* Create a mutex */ +SDL_mutex *SDL_CreateMutex(void) +{ + RMutex rmutex; + + TInt status = CreateUnique(NewMutex, &rmutex, NULL); + if(status != KErrNone) + { + SDL_SetError("Couldn't create mutex"); + } + SDL_mutex* mutex = new SDL_mutex; + mutex->handle = rmutex.Handle(); + EpocSdlEnv::AppendCleanupItem(TSdlCleanupItem(DeleteMutex, mutex)); + return(mutex); +} + +/* Free the mutex */ +void SDL_DestroyMutex(SDL_mutex *mutex) +{ + if ( mutex ) + { + RMutex rmutex; + rmutex.SetHandle(mutex->handle); + if(rmutex.IsHeld()) + { + rmutex.Signal(); + } + rmutex.Close(); + EpocSdlEnv::RemoveCleanupItem(mutex); + delete(mutex); + mutex = NULL; + } +} + +/* Lock the mutex */ +int SDL_mutexP(SDL_mutex *mutex) +{ + if ( mutex == NULL ) { + SDL_SetError("Passed a NULL mutex"); + return -1; + } + RMutex rmutex; + rmutex.SetHandle(mutex->handle); + rmutex.Wait(); + return(0); +} + +/* Unlock the mutex */ +int SDL_mutexV(SDL_mutex *mutex) +{ + if ( mutex == NULL ) { + SDL_SetError("Passed a NULL mutex"); + return -1; + } + RMutex rmutex; + rmutex.SetHandle(mutex->handle); + rmutex.Signal(); + return(0); +} diff --git a/src/thread/symbian/SDL_syssem.cpp b/src/thread/symbian/SDL_syssem.cpp dissimilarity index 70% index 5503695..dde85bd 100644 --- a/src/thread/symbian/SDL_syssem.cpp +++ b/src/thread/symbian/SDL_syssem.cpp @@ -1,214 +1,153 @@ -/* - SDL - Simple DirectMedia Layer - Copyright (C) 1997, 1998, 1999, 2000 Sam Lantinga - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with this library; if not, write to the Free - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - - Sam Lantinga - slouken@devolution.com -*/ - -/* - SDL_syssem.cpp - - Epoc version by Markus Mertama (w@iki.fi) -*/ - -#ifdef SAVE_RCSID -static char rcsid = - "@(#) $Id: SDL_syssem.c,v 1.1.2.4 2000/06/22 15:24:48 hercules Exp $"; -#endif - -/* Semaphore functions using the Win32 API */ - -//#include -//#include -#include - -#include "SDL_error.h" -#include "SDL_thread.h" - - -#define SDL_MUTEX_TIMEOUT -2 - -struct SDL_semaphore - { - TInt handle; - TInt count; - }; - - -extern TInt CreateUnique(TInt (*aFunc)(const TDesC& aName, TAny*, TAny*), TAny*, TAny*); -#ifndef EKA2 -extern TInt NewThread(const TDesC& aName, TAny* aPtr1, TAny* aPtr2); -#endif - -TInt NewSema(const TDesC& aName, TAny* aPtr1, TAny* aPtr2) - { - TInt value = *((TInt*) aPtr2); - return ((RSemaphore*)aPtr1)->CreateGlobal(aName, value); - } - -/* Create a semaphore */ -SDL_sem *SDL_CreateSemaphore(Uint32 initial_value) -{ - RSemaphore s; - TInt status = CreateUnique(NewSema, &s, &initial_value); - if(status != KErrNone) - { - SDL_SetError("Couldn't create semaphore"); - } - SDL_semaphore* sem = new /*(ELeave)*/ SDL_semaphore; - sem->handle = s.Handle(); - sem->count = initial_value; - return(sem); -} - -/* Free the semaphore */ -void SDL_DestroySemaphore(SDL_sem *sem) -{ - if ( sem ) - { - RSemaphore sema; - sema.SetHandle(sem->handle); - while(--sem->count) - sema.Signal(); - sema.Close(); - delete sem; - sem = NULL; - } -} - -#ifndef EKA2 - - struct TInfo - { - TInfo(TInt aTime, TInt aHandle) : - iTime(aTime), iHandle(aHandle), iVal(0) {} - TInt iTime; - TInt iHandle; - TInt iVal; - }; - - - -TBool ThreadRun(TAny* aInfo) - { - TInfo* info = STATIC_CAST(TInfo*, aInfo); - User::After(info->iTime); - RSemaphore sema; - sema.SetHandle(info->iHandle); - sema.Signal(); - info->iVal = SDL_MUTEX_TIMEOUT; - return 0; - } - -#endif - - -void _WaitAll(SDL_sem *sem) - { - //since SemTryWait may changed the counter. - //this may not be atomic, but hopes it works. - RSemaphore sema; - sema.SetHandle(sem->handle); - sema.Wait(); - while(sem->count < 0) - { - sema.Wait(); - } - } - -int SDL_SemWaitTimeout(SDL_sem *sem, Uint32 timeout) -{ - if ( ! sem ) { - SDL_SetError("Passed a NULL sem"); - return -1; - } - - if ( timeout == SDL_MUTEX_MAXWAIT ) - { - _WaitAll(sem); - return SDL_MUTEX_MAXWAIT; - } - -#ifdef EKA2 - - RSemaphore sema; - sema.SetHandle(sem->handle); - if(KErrNone == sema.Wait(timeout)) - return 0; - return -1; -#else - RThread thread; - - TInfo* info = new (ELeave)TInfo(timeout, sem->handle); - - TInt status = CreateUnique(NewThread, &thread, info); - - if(status != KErrNone) - return status; - - thread.Resume(); - - _WaitAll(sem); - - if(thread.ExitType() == EExitPending) - { - thread.Kill(SDL_MUTEX_TIMEOUT); - } - - thread.Close(); - - return info->iVal; -#endif -} - -int SDL_SemTryWait(SDL_sem *sem) -{ - if(sem->count > 0) - { - sem->count--; - } - return SDL_MUTEX_TIMEOUT; -} - -int SDL_SemWait(SDL_sem *sem) -{ - return SDL_SemWaitTimeout(sem, SDL_MUTEX_MAXWAIT); -} - -/* Returns the current count of the semaphore */ -Uint32 SDL_SemValue(SDL_sem *sem) -{ - if ( ! sem ) { - SDL_SetError("Passed a NULL sem"); - return 0; - } - return sem->count; -} - -int SDL_SemPost(SDL_sem *sem) -{ - if ( ! sem ) { - SDL_SetError("Passed a NULL sem"); - return -1; - } - sem->count++; - RSemaphore sema; - sema.SetHandle(sem->handle); - sema.Signal(); - return 0; -} +/* + SDL - Simple DirectMedia Layer + Copyright (C) 1997, 1998, 1999, 2000 Sam Lantinga + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; if not, write to the Free + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + Sam Lantinga + slouken@devolution.com + */ + +/* + SDL_syssem.cpp + + Epoc version by Markus Mertama (w@iki.fi) + */ + +/* Semaphore functions using the Win32 API */ + +//#include +//#include +#include + +#include "SDL_error.h" +#include "SDL_thread.h" + +#define SDL_MUTEX_TIMEOUT -2 + +struct SDL_semaphore +{ + TInt handle; + TInt count; +}; + + +extern TInt CreateUnique(TInt (*aFunc)(const TDesC& aName, TAny*, TAny*), TAny*, TAny*); + +TInt NewSema(const TDesC& aName, TAny* aPtr1, TAny* aPtr2) +{ + TInt value = *((TInt*) aPtr2); + return ((RSemaphore*)aPtr1)->CreateGlobal(aName, value); +} + +/* Create a semaphore */ +SDL_sem *SDL_CreateSemaphore(Uint32 initial_value) +{ + RSemaphore s; + TInt status = CreateUnique(NewSema, &s, &initial_value); + if(status != KErrNone) + { + SDL_SetError("Couldn't create semaphore"); + } + SDL_semaphore* sem = new /*(ELeave)*/ SDL_semaphore; + sem->handle = s.Handle(); + sem->count = initial_value; + return(sem); +} + +/* Free the semaphore */ +void SDL_DestroySemaphore(SDL_sem *sem) +{ + if ( sem ) + { + RSemaphore sema; + sema.SetHandle(sem->handle); + while(--sem->count) + sema.Signal(); + sema.Close(); + delete sem; + sem = NULL; + } +} + +void _WaitAll(SDL_sem *sem) +{ + //since SemTryWait may changed the counter. + //this may not be atomic, but hopes it works. + RSemaphore sema; + sema.SetHandle(sem->handle); + sema.Wait(); + while(sem->count < 0) + { + sema.Wait(); + } +} + +int SDL_SemWaitTimeout(SDL_sem *sem, Uint32 timeout) +{ + if ( ! sem ) { + SDL_SetError("Passed a NULL sem"); + return -1; + } + + if ( timeout == SDL_MUTEX_MAXWAIT ) + { + _WaitAll(sem); + return SDL_MUTEX_MAXWAIT; + } + + RSemaphore sema; + sema.SetHandle(sem->handle); + if(KErrNone == sema.Wait(timeout)) + return 0; + return -1; +} + +int SDL_SemTryWait(SDL_sem *sem) +{ + if(sem->count > 0) + { + sem->count--; + } + return SDL_MUTEX_TIMEOUT; +} + +int SDL_SemWait(SDL_sem *sem) +{ + return SDL_SemWaitTimeout(sem, SDL_MUTEX_MAXWAIT); +} + +/* Returns the current count of the semaphore */ +Uint32 SDL_SemValue(SDL_sem *sem) +{ + if ( ! sem ) { + SDL_SetError("Passed a NULL sem"); + return 0; + } + return sem->count; +} + +int SDL_SemPost(SDL_sem *sem) +{ + if ( ! sem ) { + SDL_SetError("Passed a NULL sem"); + return -1; + } + sem->count++; + RSemaphore sema; + sema.SetHandle(sem->handle); + sema.Signal(); + return 0; +} diff --git a/src/thread/symbian/SDL_systhread.cpp b/src/thread/symbian/SDL_systhread.cpp dissimilarity index 66% index 1803918..0e42bb1 100644 --- a/src/thread/symbian/SDL_systhread.cpp +++ b/src/thread/symbian/SDL_systhread.cpp @@ -1,146 +1,133 @@ -/* - SDL - Simple DirectMedia Layer - Copyright (C) 1997, 1998, 1999, 2000 Sam Lantinga - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with this library; if not, write to the Free - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - - Sam Lantinga - slouken@devolution.com -*/ - -/* - SDL_systhread.cpp - Epoc thread management routines for SDL - - Epoc version by Markus Mertama (w@iki.fi) -*/ - -#include "epoc_sdl.h" - -//#include -//#include - - - -extern "C" { -#undef NULL -#include "SDL_error.h" -#include "SDL_thread.h" -#include "SDL_systhread.h" -#include "SDL_thread_c.h" - } - -#include -#include "epoc_sdl.h" - - -static int object_count; - -int RunThread(TAny* data) -{ - CTrapCleanup* cleanup = CTrapCleanup::New(); - TRAPD(err, SDL_RunThread(data)); - EpocSdlEnv::CleanupItems(); - delete cleanup; - return(err); -} - - -TInt NewThread(const TDesC& aName, TAny* aPtr1, TAny* aPtr2) - { - return ((RThread*)(aPtr1))->Create(aName, - RunThread, - KDefaultStackSize, - NULL, - aPtr2); - } - -int CreateUnique(TInt (*aFunc)(const TDesC& aName, TAny*, TAny*), TAny* aPtr1, TAny* aPtr2) - { - TBuf<16> name; - TInt status = KErrNone; - do - { - object_count++; - name.Format(_L("SDL_%x"), object_count); - status = aFunc(name, aPtr1, aPtr2); - } - while(status == KErrAlreadyExists); - return status; - } - - -int SDL_SYS_CreateThread(SDL_Thread *thread, void *args) -{ - RThread rthread; - - const TInt status = CreateUnique(NewThread, &rthread, args); - if (status != KErrNone) - { - delete(((RThread*)(thread->handle))); - thread->handle = NULL; - SDL_SetError("Not enough resources to create thread"); - return(-1); - } - rthread.Resume(); - thread->handle = rthread.Handle(); - return(0); -} - -void SDL_SYS_SetupThread(void) -{ - return; -} - -Uint32 SDL_ThreadID(void) -{ - RThread current; - const TThreadId id = current.Id(); - return id; -} - -void SDL_SYS_WaitThread(SDL_Thread *thread) -{ - SDL_TRACE1("Close thread", thread); - RThread t; - const TInt err = t.Open(thread->threadid); - if(err == KErrNone && t.ExitType() == EExitPending) - { - TRequestStatus status; - t.Logon(status); - User::WaitForRequest(status); - } - t.Close(); - - /* RUndertaker taker; - taker.Create(); - TRequestStatus status; - taker.Logon(status, thread->handle); - User::WaitForRequest(status); - taker.Close();*/ - SDL_TRACE1("Closed thread", thread); -} - -/* WARNING: This function is really a last resort. - * Threads should be signaled and then exit by themselves. - * TerminateThread() doesn't perform stack and DLL cleanup. - */ -void SDL_SYS_KillThread(SDL_Thread *thread) -{ - RThread rthread; - rthread.SetHandle(thread->handle); - rthread.Kill(0); - rthread.Close(); -} +/* + SDL - Simple DirectMedia Layer + Copyright (C) 1997, 1998, 1999, 2000 Sam Lantinga + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; if not, write to the Free + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + Sam Lantinga + slouken@devolution.com + */ + +/* + SDL_systhread.cpp + Epoc thread management routines for SDL + + Epoc version by Markus Mertama (w@iki.fi) + */ + +#include "epoc_sdl.h" + +//#include +//#include + +extern "C" { +#undef NULL +#include "SDL_error.h" +#include "SDL_thread.h" +#include "SDL_systhread.h" +#include "SDL_thread_c.h" +} + +#include +#include "epoc_sdl.h" + + +static int object_count; + +int RunThread(TAny* data) +{ + CTrapCleanup* cleanup = CTrapCleanup::New(); + TRAPD(err, SDL_RunThread(data)); + EpocSdlEnv::CleanupItems(); + delete cleanup; + return(err); +} + +TInt NewThread(const TDesC& aName, TAny* aPtr1, TAny* aPtr2) +{ + return ((RThread*)(aPtr1))->Create(aName, + RunThread, + KDefaultStackSize, + NULL, + aPtr2); +} + +int CreateUnique(TInt (*aFunc)(const TDesC& aName, TAny*, TAny*), TAny* aPtr1, TAny* aPtr2) +{ + TBuf<16> name; + TInt status = KErrNone; + do + { + object_count++; + name.Format(_L("SDL_%x"), object_count); + status = aFunc(name, aPtr1, aPtr2); + } + while(status == KErrAlreadyExists); + return status; +} + +int SDL_SYS_CreateThread(SDL_Thread *thread, void *args) +{ + RThread rthread; + + const TInt status = CreateUnique(NewThread, &rthread, args); + if (status != KErrNone) + { + delete(((RThread*)(thread->handle))); + thread->handle = NULL; + SDL_SetError("Not enough resources to create thread"); + return(-1); + } + rthread.Resume(); + thread->handle = rthread.Handle(); + return(0); +} + +void SDL_SYS_SetupThread(void) +{ + return; +} + +Uint32 SDL_ThreadID(void) +{ + RThread current; + const TThreadId id = current.Id(); + return id; +} + +void SDL_SYS_WaitThread(SDL_Thread *thread) +{ + RThread t; + const TInt err = t.Open(thread->threadid); + if(err == KErrNone && t.ExitType() == EExitPending) + { + TRequestStatus status; + t.Logon(status); + User::WaitForRequest(status); + } + t.Close(); +} + +/* WARNING: This function is really a last resort. + * Threads should be signaled and then exit by themselves. + * TerminateThread() doesn't perform stack and DLL cleanup. + */ +void SDL_SYS_KillThread(SDL_Thread *thread) +{ + RThread rthread; + rthread.SetHandle(thread->handle); + rthread.Kill(0); + rthread.Close(); +} diff --git a/src/thread/symbian/SDL_systhread_c.h b/src/thread/symbian/SDL_systhread_c.h dissimilarity index 95% index be8b164..a42d695 100644 --- a/src/thread/symbian/SDL_systhread_c.h +++ b/src/thread/symbian/SDL_systhread_c.h @@ -1,30 +1,30 @@ -/* - SDL - Simple DirectMedia Layer - Copyright (C) 1997, 1998, 1999, 2000 Sam Lantinga - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with this library; if not, write to the Free - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - - Sam Lantinga - slouken@devolution.com -*/ - -/* - SDL_systhread_c.h - - Epoc version by Markus Mertama (w@iki.fi) -*/ - -typedef int SYS_ThreadHandle; - +/* + SDL - Simple DirectMedia Layer + Copyright (C) 1997, 1998, 1999, 2000 Sam Lantinga + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; if not, write to the Free + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + Sam Lantinga + slouken@devolution.com + */ + +/* + SDL_systhread_c.h + + Epoc version by Markus Mertama (w@iki.fi) + */ + +typedef int SYS_ThreadHandle; + diff --git a/src/timer/symbian/SDL_systimer.cpp b/src/timer/symbian/SDL_systimer.cpp dissimilarity index 87% index f564288..3e6e0ff 100644 --- a/src/timer/symbian/SDL_systimer.cpp +++ b/src/timer/symbian/SDL_systimer.cpp @@ -1,111 +1,111 @@ -/* - SDL - Simple DirectMedia Layer - Copyright (C) 1997, 1998, 1999, 2000, 2001 Sam Lantinga - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with this library; if not, write to the Free - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - - Sam Lantinga - slouken@devolution.com -*/ - -/* - SDL_systimer.cpp - - Epoc version by Hannu Viitala (hannu.j.viitala@mbnet.fi) - Markus Mertama -*/ - -#include -#include -#include - -extern "C" { -#include "SDL_error.h" -#include "SDL_thread.h" -#include "SDL_timer.h" -#include "SDL_timer_c.h" - -static TUint32 start = 0; -static TInt tickPeriodMicroSeconds = 0; - -void SDL_StartTicks(void) - { - /* Set first ticks value */ - start = User::NTickCount(); - HAL::Get(HAL::ENanoTickPeriod, tickPeriodMicroSeconds); - } - -Uint32 SDL_GetTicks(void) - { - const TUint32 deltaTics = User::NTickCount() - start; - return (deltaTics * tickPeriodMicroSeconds) / 1000; - } - -void SDL_Delay(Uint32 ms) - { - User::After(TTimeIntervalMicroSeconds32(ms*1000)); - } - -/* Data to handle a single periodic alarm */ -static int timer_alive = 0; -static SDL_Thread *timer = NULL; - -static int RunTimer(void *unused) - { - while ( timer_alive ) - { - if (SDL_timer_running) - { - SDL_ThreadedTimerCheck(); - } - SDL_Delay(10); - } - return(0); - } - -/* This is only called if the event thread is not running */ -int SDL_SYS_TimerInit(void) - { - if(timer != NULL) - return (-1); - timer_alive = 1; - timer = SDL_CreateThread(RunTimer, NULL); - if ( timer == NULL ) - return(-1); - return(SDL_SetTimerThreaded(1)); - } - -void SDL_SYS_TimerQuit(void) - { - timer_alive = 0; - if ( timer ) - { - SDL_WaitThread(timer, NULL); - timer = NULL; - } - } - -int SDL_SYS_StartTimer(void) - { - SDL_SetError("Internal logic error: Epoc uses threaded timer"); - return(-1); - } - -void SDL_SYS_StopTimer(void) - { - return; - } - -} // extern "C" +/* + SDL - Simple DirectMedia Layer + Copyright (C) 1997, 1998, 1999, 2000, 2001 Sam Lantinga + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; if not, write to the Free + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + Sam Lantinga + slouken@devolution.com + */ + +/* + SDL_systimer.cpp + + Epoc version by Hannu Viitala (hannu.j.viitala@mbnet.fi) + Markus Mertama + */ + +#include +#include +#include + +extern "C" { +#include "SDL_error.h" +#include "SDL_thread.h" +#include "SDL_timer.h" +#include "SDL_timer_c.h" + + static TUint32 start = 0; + static TInt tickPeriodMicroSeconds = 0; + + void SDL_StartTicks(void) + { + /* Set first ticks value */ + start = User::NTickCount(); + HAL::Get(HAL::ENanoTickPeriod, tickPeriodMicroSeconds); + } + + Uint32 SDL_GetTicks(void) + { + const TUint32 deltaTics = User::NTickCount() - start; + return (deltaTics * tickPeriodMicroSeconds) / 1000; + } + + void SDL_Delay(Uint32 ms) + { + User::After(TTimeIntervalMicroSeconds32(ms*1000)); + } + + /* Data to handle a single periodic alarm */ + static int timer_alive = 0; + static SDL_Thread *timer = NULL; + + static int RunTimer(void *unused) + { + while ( timer_alive ) + { + if (SDL_timer_running) + { + SDL_ThreadedTimerCheck(); + } + SDL_Delay(10); + } + return(0); + } + + /* This is only called if the event thread is not running */ + int SDL_SYS_TimerInit(void) + { + if(timer != NULL) + return (-1); + timer_alive = 1; + timer = SDL_CreateThread(RunTimer, NULL); + if ( timer == NULL ) + return(-1); + return(SDL_SetTimerThreaded(1)); + } + + void SDL_SYS_TimerQuit(void) + { + timer_alive = 0; + if ( timer ) + { + SDL_WaitThread(timer, NULL); + timer = NULL; + } + } + + int SDL_SYS_StartTimer(void) + { + SDL_SetError("Internal logic error: Epoc uses threaded timer"); + return(-1); + } + + void SDL_SYS_StopTimer(void) + { + return; + } + +} // extern "C" diff --git a/src/video/symbian/SDL_epocevents.cpp b/src/video/symbian/SDL_epocevents.cpp dissimilarity index 78% index ba2bd22..f5ac924 100644 --- a/src/video/symbian/SDL_epocevents.cpp +++ b/src/video/symbian/SDL_epocevents.cpp @@ -1,525 +1,371 @@ -#include "epoc_sdl.h" - -#include -#undef NULL -extern "C" { -#include "SDL_error.h" -#include "SDL_video.h" -#include "SDL_keysym.h" -#include "SDL_keyboard.h" -#include "SDL_events_c.h" -#include "SDL_timer.h" -} /* extern "C" */ - -#include "SDL_epocvideo.h" -#include "SDL_epocevents_c.h" - -#include "sdlepocapi.h" - -#include - -#include - - -extern "C" - { - static SDL_keysym *TranslateKey(_THIS, int scancode, SDL_keysym *keysym); - } - -//extern "C" { -/* The translation tables from a console scancode to a SDL keysym */ -static SDLKey keymap[MAX_SCANCODE]; -static SDL_keysym *TranslateKey(_THIS, int scancode, SDL_keysym *keysym); -void DisableKeyBlocking(_THIS); -//} /* extern "C" */ - -SDLKey* KeyMap() - { - return keymap; - } - -TBool isCursorVisible = EFalse; - -void ResetKeyMap() - { - int i; - - /* Initialize the key translation table */ - for ( i=0; i array; - TRAPD(err, ReadL(fs, array)); - if(err == KErrNone && array.Count() > 0) - { - - SDLKey temp[MAX_SCANCODE]; - Mem::Copy(temp, keymap, MAX_SCANCODE * sizeof(SDLKey)); - - for(TInt k = 0; k < array.Count(); k+= 2) - { - const TInt oldval = array[k]; - const TInt newval = array[k + 1]; - if(oldval >= 0 && oldval < MAX_SCANCODE && newval >= 0 && newval < MAX_SCANCODE) - { - keymap[oldval] = temp[newval]; - } - } - } - array.Close(); - } - - fs.Close();*/ - /////////////////////////////////////////////////////////// - - - keymap[EStdKeyNumLock] = SDLK_NUMLOCK; - keymap[EStdKeyScrollLock] = SDLK_SCROLLOCK; - - keymap[EStdKeyNkpForwardSlash] = SDLK_KP_DIVIDE; - keymap[EStdKeyNkpAsterisk] = SDLK_KP_MULTIPLY; - keymap[EStdKeyNkpMinus] = SDLK_KP_MINUS; - keymap[EStdKeyNkpPlus] = SDLK_KP_PLUS; - keymap[EStdKeyNkpEnter] = SDLK_KP_ENTER; - keymap[EStdKeyNkp1] = SDLK_KP1; - keymap[EStdKeyNkp2] = SDLK_KP2; - keymap[EStdKeyNkp3] = SDLK_KP3; - keymap[EStdKeyNkp4] = SDLK_KP4; - keymap[EStdKeyNkp5] = SDLK_KP5; - keymap[EStdKeyNkp6] = SDLK_KP6; - keymap[EStdKeyNkp7] = SDLK_KP7; - keymap[EStdKeyNkp8] = SDLK_KP8; - keymap[EStdKeyNkp9] = SDLK_KP9; - keymap[EStdKeyNkp0] = SDLK_KP0; - keymap[EStdKeyNkpFullStop] = SDLK_KP_PERIOD; - /* - keymap[EStdKeyMenu] = SDLK_MENU; should be, but not yet - keymap[EStdKeyBacklightOn] = - keymap[EStdKeyBacklightOff] = - keymap[EStdKeyBacklightToggle] = - keymap[EStdKeyIncContrast] = - keymap[EStdKeyDecContrast] = - keymap[EStdKeySliderDown] = - keymap[EStdKeySliderUp] = - keymap[EStdKeyDictaphonePlay] = - keymap[EStdKeyDictaphoneStop] = - keymap[EStdKeyDictaphoneRecord] = - keymap[EStdKeyHelp] = - keymap[EStdKeyOff] = - keymap[EStdKeyDial] = - keymap[EStdKeyIncVolume] = - keymap[EStdKeyDecVolume] = - keymap[EStdKeyDevice0] = - keymap[EStdKeyDevice1] = - keymap[EStdKeyDevice2] = - keymap[EStdKeyDevice3] = - keymap[EStdKeyDevice4] = - keymap[EStdKeyDevice5] = - keymap[EStdKeyDevice6] = - keymap[EStdKeyDevice7] = - keymap[EStdKeyDevice8] = - keymap[EStdKeyDevice9] = - keymap[EStdKeyDeviceA] = - keymap[EStdKeyDeviceB] = - keymap[EStdKeyDeviceC] = - keymap[EStdKeyDeviceD] = - keymap[EStdKeyDeviceE] = - keymap[EStdKeyDeviceF] = - keymap[EStdKeyApplication0] = - keymap[EStdKeyApplication1] = - keymap[EStdKeyApplication2] = - keymap[EStdKeyApplication3] = - keymap[EStdKeyApplication4] = - keymap[EStdKeyApplication5] = - keymap[EStdKeyApplication6] = - keymap[EStdKeyApplication7] = - keymap[EStdKeyApplication8] = - keymap[EStdKeyApplication9] = - keymap[EStdKeyApplicationA] = - keymap[EStdKeyApplicationB] = - keymap[EStdKeyApplicationC] = - keymap[EStdKeyApplicationD] = - keymap[EStdKeyApplicationE] = - keymap[EStdKeyApplicationF] = - keymap[EStdKeyYes] = - keymap[EStdKeyNo] = - keymap[EStdKeyIncBrightness] = - keymap[EStdKeyDecBrightness] = - keymap[EStdKeyCaseOpen] = - keymap[EStdKeyCaseClose] = */ - - - -} - - -int EPOC_HandleWsEvent(_THIS, const TWsEvent& aWsEvent) -{ - int posted = 0; - SDL_keysym keysym; - -// SDL_TRACE1("hws %d", aWsEvent.Type()); - - switch (aWsEvent.Type()) - { - case EEventSwitchOff: - SDL_PrivateQuit(); - break; - - case EEventPointer: /* Mouse pointer events */ - { -/* const TPointerCursorMode mode = EpocSdlEnv::PointerMode(); - - - if(mode == EPointerCursorNone) - { - return 0; //TODO: Find out why events are get despite of cursor should be off - } -*/ - const TPointerEvent* pointerEvent = aWsEvent.Pointer(); - const TPoint mousePos = EpocSdlEnv::WindowCoordinates(pointerEvent->iPosition); - - /*!! TODO Pointer do not yet work properly - //SDL_TRACE1("SDL: EPOC_HandleWsEvent, pointerEvent->iType=%d", pointerEvent->iType); //!! - - if (Private->EPOC_ShrinkedHeight) { - mousePos.iY <<= 1; // Scale y coordinate to shrinked screen height - } - if (Private->EPOC_ShrinkedWidth) { - mousePos.iX <<= 1; // Scale x coordinate to shrinked screen width - } - */ - - posted += SDL_PrivateMouseMotion(0, 0, mousePos.iX, mousePos.iY); /* Absolute position on screen */ - - switch (pointerEvent->iType) - { - case TPointerEvent::EButton1Down: - posted += SDL_PrivateMouseButton(SDL_PRESSED, SDL_BUTTON_LEFT, 0, 0); - break; - case TPointerEvent::EButton1Up: - posted += SDL_PrivateMouseButton(SDL_RELEASED, SDL_BUTTON_LEFT, 0, 0); - break; - case TPointerEvent::EButton2Down: - posted += SDL_PrivateMouseButton(SDL_PRESSED, SDL_BUTTON_RIGHT, 0, 0); - break; - case TPointerEvent::EButton2Up: - posted += SDL_PrivateMouseButton(SDL_RELEASED, SDL_BUTTON_RIGHT, 0, 0); - break; - case TPointerEvent::EButton3Down: - posted += SDL_PrivateMouseButton(SDL_PRESSED, SDL_BUTTON_MIDDLE, 0, 0); - break; - case TPointerEvent::EButton3Up: - posted += SDL_PrivateMouseButton(SDL_RELEASED, SDL_BUTTON_MIDDLE, 0, 0); - break; - } // switch - break; - } - - case EEventKeyDown: /* Key events */ - { -#ifdef SYMBIAN_CRYSTAL - // special case: 9300/9500 rocker down, simulate left mouse button - if (aWsEvent.Key()->iScanCode == EStdKeyDeviceA) - { - const TPointerCursorMode mode = Private->EPOC_WsSession.PointerCursorMode(); - if(mode != EPointerCursorNone) - posted += SDL_PrivateMouseButton(SDL_PRESSED, SDL_BUTTON_LEFT, 0, 0); - } -#endif - (void*)TranslateKey(_this, aWsEvent.Key()->iScanCode, &keysym); - -#ifndef DISABLE_JOYSTICK - /* Special handling */ - switch((int)keysym.sym) { - case SDLK_CAPSLOCK: - if (!isCursorVisible) { - /* Enable virtual cursor */ - HAL::Set(HAL::EMouseState, HAL::EMouseState_Visible); - } - else { - /* Disable virtual cursor */ - HAL::Set(HAL::EMouseState, HAL::EMouseState_Invisible); - } - isCursorVisible = !isCursorVisible; - break; - } -#endif - posted += SDL_PrivateKeyboard(SDL_PRESSED, &keysym); - break; - } - - case EEventKeyUp: /* Key events */ - { -#ifdef SYMBIAN_CRYSTAL - // special case: 9300/9500 rocker up, simulate left mouse button - if (aWsEvent.Key()->iScanCode == EStdKeyDeviceA) - { - posted += SDL_PrivateMouseButton(SDL_RELEASED, SDL_BUTTON_LEFT, 0, 0); - } -#endif - posted += SDL_PrivateKeyboard(SDL_RELEASED, TranslateKey(_this, aWsEvent.Key()->iScanCode, &keysym)); - break; - } - - case EEventFocusGained: /* SDL window got focus */ - { - Private->iIsWindowFocused = ETrue; - posted += SDL_PrivateAppActive(1, SDL_APPINPUTFOCUS|SDL_APPMOUSEFOCUS); - /* Draw window background and screen buffer */ - DisableKeyBlocking(_this); //Markus: guess why:-) - - //RedrawWindowL(_this); - break; - } - - case EEventFocusLost: /* SDL window lost focus */ - { - - Private->iIsWindowFocused = EFalse; - - posted += SDL_PrivateAppActive(0, SDL_APPINPUTFOCUS|SDL_APPMOUSEFOCUS); - - - break; - } - - case EEventModifiersChanged: - { - TModifiersChangedEvent* modEvent = aWsEvent.ModifiersChanged(); - TUint modstate = KMOD_NONE; - if (modEvent->iModifiers == EModifierLeftShift) - modstate |= KMOD_LSHIFT; - if (modEvent->iModifiers == EModifierRightShift) - modstate |= KMOD_RSHIFT; - if (modEvent->iModifiers == EModifierLeftCtrl) - modstate |= KMOD_LCTRL; - if (modEvent->iModifiers == EModifierRightCtrl) - modstate |= KMOD_RCTRL; - if (modEvent->iModifiers == EModifierLeftAlt) - modstate |= KMOD_LALT; - if (modEvent->iModifiers == EModifierRightAlt) - modstate |= KMOD_RALT; - if (modEvent->iModifiers == EModifierLeftFunc) - modstate |= KMOD_LMETA; - if (modEvent->iModifiers == EModifierRightFunc) - modstate |= KMOD_RMETA; - if (modEvent->iModifiers == EModifierCapsLock) - modstate |= KMOD_CAPS; - SDL_SetModState(STATIC_CAST(SDLMod,(modstate | KMOD_LSHIFT))); - break; - } - case EEventScreenDeviceChanged: - { - EpocSdlEnv::WaitDeviceChange(); - } - break; - default: - break; - } - - return posted; -} - -extern "C" { - -void EPOC_PumpEvents(_THIS) - { - MEventQueue& events = EpocSdlEnv::EventQueue(); - while(events.HasData()) - { - events.Lock(); - - //there have to be a copy, so we can release - //lock immediately. HandleWsEvent may cause - //deadlock otherwise. - - const TWsEvent event = events.Shift(); - events.Unlock(); -// const TWsEvent& event = events.Top(); - EPOC_HandleWsEvent(_this, event); -// events.Shift(); - } - } - - - -void EPOC_InitOSKeymap(_THIS) - { - ResetKeyMap(); - EpocSdlEnv::ObserverEvent(MSDLObserver::EEventKeyMapInit ,0); - } - -static SDL_keysym *TranslateKey(_THIS, int scancode, SDL_keysym *keysym) -{ -// char debug[256]; - //SDL_TRACE1("SDL: TranslateKey, scancode=%d", scancode); //!! - - /* Set the keysym information */ - - keysym->scancode = scancode; - - if ((scancode >= MAX_SCANCODE) && - ((scancode - ENonCharacterKeyBase + 0x0081) >= MAX_SCANCODE)) { - SDL_SetError("Too big scancode"); - keysym->scancode = SDLK_UNKNOWN; - keysym->mod = KMOD_NONE; - return keysym; - } - - keysym->mod = SDL_GetModState(); - - /* Handle function keys: F1, F2, F3 ... */ - if (keysym->mod & KMOD_META) { - if (scancode >= 'A' && scancode < ('A' + 24)) { /* first 32 alphabet keys */ - switch(scancode) { - case 'Q': scancode = EStdKeyF1; break; - case 'W': scancode = EStdKeyF2; break; - case 'E': scancode = EStdKeyF3; break; - case 'R': scancode = EStdKeyF4; break; - case 'T': scancode = EStdKeyF5; break; - case 'Y': scancode = EStdKeyF6; break; - case 'U': scancode = EStdKeyF7; break; - case 'I': scancode = EStdKeyF8; break; - case 'A': scancode = EStdKeyF9; break; - case 'S': scancode = EStdKeyF10; break; - case 'D': scancode = EStdKeyF11; break; - case 'F': scancode = EStdKeyF12; break; - } - keysym->sym = keymap[scancode]; - } - } - - if (scancode >= ENonCharacterKeyBase) { - // Non character keys - keysym->sym = keymap[scancode - - ENonCharacterKeyBase + 0x0081]; // !!hard coded - } else { - keysym->sym = keymap[scancode]; - } - - /* Remap the arrow keys if the device is rotated */ -/* - if (Private->EPOC_ScreenOrientation == CFbsBitGc::EGraphicsOrientationRotated270) { - switch(keysym->sym) { - case SDLK_UP: keysym->sym = SDLK_LEFT; break; - case SDLK_DOWN: keysym->sym = SDLK_RIGHT; break; - case SDLK_LEFT: keysym->sym = SDLK_DOWN; break; - case SDLK_RIGHT:keysym->sym = SDLK_UP; break; - } - } -*/ - /* If UNICODE is on, get the UNICODE value for the key */ - keysym->unicode = 0; - -#if 0 // !!TODO:unicode - - if ( SDL_TranslateUNICODE ) - { - /* Populate the unicode field with the ASCII value */ - keysym->unicode = scancode; - } -#endif - - //!! - //sprintf(debug, "SDL: TranslateKey: keysym->scancode=%d, keysym->sym=%d, keysym->mod=%d", - // keysym->scancode, keysym->sym, keysym->mod); - //SDL_TRACE(debug); //!! - - return(keysym); -} - -} /* extern "C" */ - - - +#include "epoc_sdl.h" + +#include +#undef NULL +extern "C" { +#include "SDL_error.h" +#include "SDL_video.h" +#include "SDL_keysym.h" +#include "SDL_keyboard.h" +#include "SDL_events_c.h" +#include "SDL_timer.h" +} /* extern "C" */ + +#include "SDL_epocvideo.h" +#include "SDL_epocevents_c.h" + +#include "sdlepocapi.h" + +#include + +#include + + +extern "C" +{ + static SDL_keysym *TranslateKey(_THIS, int scancode, SDL_keysym *keysym); +} + +/* The translation tables from a console scancode to a SDL keysym */ +static SDLKey keymap[MAX_SCANCODE]; +static SDL_keysym *TranslateKey(_THIS, int scancode, SDL_keysym *keysym); +void DisableKeyBlocking(_THIS); + +SDLKey* KeyMap() +{ + return keymap; +} + +TBool isCursorVisible = EFalse; + +void ResetKeyMap() +{ + int i; + + /* Initialize the key translation table */ + for ( i=0; iiPosition); + + posted += SDL_PrivateMouseMotion(0, 0, mousePos.iX, mousePos.iY); /* Absolute position on screen */ + + switch (pointerEvent->iType) + { + case TPointerEvent::EButton1Down: + posted += SDL_PrivateMouseButton(SDL_PRESSED, SDL_BUTTON_LEFT, 0, 0); + break; + case TPointerEvent::EButton1Up: + posted += SDL_PrivateMouseButton(SDL_RELEASED, SDL_BUTTON_LEFT, 0, 0); + break; + case TPointerEvent::EButton2Down: + posted += SDL_PrivateMouseButton(SDL_PRESSED, SDL_BUTTON_RIGHT, 0, 0); + break; + case TPointerEvent::EButton2Up: + posted += SDL_PrivateMouseButton(SDL_RELEASED, SDL_BUTTON_RIGHT, 0, 0); + break; + case TPointerEvent::EButton3Down: + posted += SDL_PrivateMouseButton(SDL_PRESSED, SDL_BUTTON_MIDDLE, 0, 0); + break; + case TPointerEvent::EButton3Up: + posted += SDL_PrivateMouseButton(SDL_RELEASED, SDL_BUTTON_MIDDLE, 0, 0); + break; + } // switch + break; + } + + case EEventKeyDown: /* Key events */ + { + (void*)TranslateKey(_this, aWsEvent.Key()->iScanCode, &keysym); + +#ifndef DISABLE_JOYSTICK + /* Special handling */ + switch((int)keysym.sym) { + case SDLK_CAPSLOCK: + if (!isCursorVisible) { + /* Enable virtual cursor */ + HAL::Set(HAL::EMouseState, HAL::EMouseState_Visible); + } + else { + /* Disable virtual cursor */ + HAL::Set(HAL::EMouseState, HAL::EMouseState_Invisible); + } + isCursorVisible = !isCursorVisible; + break; + } +#endif + posted += SDL_PrivateKeyboard(SDL_PRESSED, &keysym); + break; + } + + case EEventKeyUp: /* Key events */ + { + posted += SDL_PrivateKeyboard(SDL_RELEASED, TranslateKey(_this, aWsEvent.Key()->iScanCode, &keysym)); + break; + } + + case EEventFocusGained: /* SDL window got focus */ + { + Private->iIsWindowFocused = ETrue; + posted += SDL_PrivateAppActive(1, SDL_APPINPUTFOCUS|SDL_APPMOUSEFOCUS); + /* Draw window background and screen buffer */ + DisableKeyBlocking(_this); //Markus: guess why:-) + + //RedrawWindowL(_this); + break; + } + + case EEventFocusLost: /* SDL window lost focus */ + { + + Private->iIsWindowFocused = EFalse; + + posted += SDL_PrivateAppActive(0, SDL_APPINPUTFOCUS|SDL_APPMOUSEFOCUS); + + + break; + } + + case EEventModifiersChanged: + { + TModifiersChangedEvent* modEvent = aWsEvent.ModifiersChanged(); + TUint modstate = KMOD_NONE; + if (modEvent->iModifiers == EModifierLeftShift) + modstate |= KMOD_LSHIFT; + if (modEvent->iModifiers == EModifierRightShift) + modstate |= KMOD_RSHIFT; + if (modEvent->iModifiers == EModifierLeftCtrl) + modstate |= KMOD_LCTRL; + if (modEvent->iModifiers == EModifierRightCtrl) + modstate |= KMOD_RCTRL; + if (modEvent->iModifiers == EModifierLeftAlt) + modstate |= KMOD_LALT; + if (modEvent->iModifiers == EModifierRightAlt) + modstate |= KMOD_RALT; + if (modEvent->iModifiers == EModifierLeftFunc) + modstate |= KMOD_LMETA; + if (modEvent->iModifiers == EModifierRightFunc) + modstate |= KMOD_RMETA; + if (modEvent->iModifiers == EModifierCapsLock) + modstate |= KMOD_CAPS; + SDL_SetModState(STATIC_CAST(SDLMod,(modstate | KMOD_LSHIFT))); + break; + } + case EEventScreenDeviceChanged: + { + EpocSdlEnv::WaitDeviceChange(); + } + break; + default: + break; + } + + return posted; +} + +extern "C" { + + void EPOC_PumpEvents(_THIS) + { + MEventQueue& events = EpocSdlEnv::EventQueue(); + while(events.HasData()) + { + events.Lock(); + + //there have to be a copy, so we can release + //lock immediately. HandleWsEvent may cause + //deadlock otherwise. + + const TWsEvent event = events.Shift(); + events.Unlock(); + EPOC_HandleWsEvent(_this, event); + } + } + + + + void EPOC_InitOSKeymap(_THIS) + { + ResetKeyMap(); + EpocSdlEnv::ObserverEvent(MSDLObserver::EEventKeyMapInit ,0); + } + + static SDL_keysym *TranslateKey(_THIS, int scancode, SDL_keysym *keysym) + { + /* Set the keysym information */ + + keysym->scancode = scancode; + + if ((scancode >= MAX_SCANCODE) && + ((scancode - ENonCharacterKeyBase + 0x0081) >= MAX_SCANCODE)) { + SDL_SetError("Too big scancode"); + keysym->scancode = SDLK_UNKNOWN; + keysym->mod = KMOD_NONE; + return keysym; + } + + keysym->mod = SDL_GetModState(); + + /* Handle function keys: F1, F2, F3 ... */ + if (keysym->mod & KMOD_META) { + if (scancode >= 'A' && scancode < ('A' + 24)) { /* first 32 alphabet keys */ + switch(scancode) { + case 'Q': scancode = EStdKeyF1; break; + case 'W': scancode = EStdKeyF2; break; + case 'E': scancode = EStdKeyF3; break; + case 'R': scancode = EStdKeyF4; break; + case 'T': scancode = EStdKeyF5; break; + case 'Y': scancode = EStdKeyF6; break; + case 'U': scancode = EStdKeyF7; break; + case 'I': scancode = EStdKeyF8; break; + case 'A': scancode = EStdKeyF9; break; + case 'S': scancode = EStdKeyF10; break; + case 'D': scancode = EStdKeyF11; break; + case 'F': scancode = EStdKeyF12; break; + } + keysym->sym = keymap[scancode]; + } + } + + if (scancode >= ENonCharacterKeyBase) { + // Non character keys + keysym->sym = keymap[scancode - + ENonCharacterKeyBase + 0x0081]; // !!hard coded + } else { + keysym->sym = keymap[scancode]; + } + + /* Remap the arrow keys if the device is rotated */ + /* + if (Private->EPOC_ScreenOrientation == CFbsBitGc::EGraphicsOrientationRotated270) { + switch(keysym->sym) { + case SDLK_UP: keysym->sym = SDLK_LEFT; break; + case SDLK_DOWN: keysym->sym = SDLK_RIGHT; break; + case SDLK_LEFT: keysym->sym = SDLK_DOWN; break; + case SDLK_RIGHT:keysym->sym = SDLK_UP; break; + } + } + */ + /* If UNICODE is on, get the UNICODE value for the key */ + keysym->unicode = 0; + + return(keysym); + } + +} /* extern "C" */ diff --git a/src/video/symbian/SDL_epocevents_c.h b/src/video/symbian/SDL_epocevents_c.h dissimilarity index 77% index 8dd76f6..9f250dc 100644 --- a/src/video/symbian/SDL_epocevents_c.h +++ b/src/video/symbian/SDL_epocevents_c.h @@ -1,60 +1,51 @@ -/* - SDL - Simple DirectMedia Layer - Copyright (C) 1997, 1998, 1999, 2000, 2001 Sam Lantinga - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with this library; if not, write to the Free - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - - Sam Lantinga - slouken@devolution.com -*/ - -/* - SDL_epocevents_c.h - Handle the event stream, converting Epoc events into SDL events - - Epoc version by Hannu Viitala (hannu.j.viitala@mbnet.fi) and Markus Mertama - -*/ - - -#ifdef SAVE_RCSID -static char rcsid = - "@(#) $Id: SDL_aaevents_c.h,v 1.1.2.2 2000/03/16 15:20:39 hercules Exp $"; -#endif - -extern "C" { -#include "SDL_sysvideo.h" -//#include "SDL_epocvideo.h" -} - - - -#define MAX_SCANCODE 255 - -/* Variables and functions exported by SDL_sysevents.c to other parts - of the native video subsystem (SDL_sysvideo.c) -*/ - -/* Hidden "this" pointer for the video functions */ -#define _THIS SDL_VideoDevice *_this -#define Private _this->hidden - -extern "C" { -extern void EPOC_InitOSKeymap(_THIS); -extern void EPOC_PumpEvents(_THIS); -} - -extern TBool isCursorVisible; - +/* + SDL - Simple DirectMedia Layer + Copyright (C) 1997, 1998, 1999, 2000, 2001 Sam Lantinga + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; if not, write to the Free + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + Sam Lantinga + slouken@devolution.com + */ + +/* + SDL_epocevents_c.h + Handle the event stream, converting Epoc events into SDL events + + Epoc version by Hannu Viitala (hannu.j.viitala@mbnet.fi) and Markus Mertama + +*/ + +extern "C" { +#include "SDL_sysvideo.h" +} + +#define MAX_SCANCODE 255 + +/* Variables and functions exported by SDL_sysevents.c to other parts + of the native video subsystem (SDL_sysvideo.c) + */ + +/* Hidden "this" pointer for the video functions */ +#define _THIS SDL_VideoDevice *_this +#define Private _this->hidden + +extern "C" { + extern void EPOC_InitOSKeymap(_THIS); + extern void EPOC_PumpEvents(_THIS); +} + +extern TBool isCursorVisible; + diff --git a/src/video/symbian/SDL_epocvideo.cpp b/src/video/symbian/SDL_epocvideo.cpp index d2dbb23..1b108f8 100644 --- a/src/video/symbian/SDL_epocvideo.cpp +++ b/src/video/symbian/SDL_epocvideo.cpp @@ -1,33 +1,31 @@ /* - SDL - Simple DirectMedia Layer - Copyright (C) 1997, 1998, 1999, 2000, 2001 Sam Lantinga + SDL - Simple DirectMedia Layer + Copyright (C) 1997, 1998, 1999, 2000, 2001 Sam Lantinga - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. - You should have received a copy of the GNU Library General Public - License along with this library; if not, write to the Free - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + You should have received a copy of the GNU Library General Public + License along with this library; if not, write to the Free + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - Sam Lantinga - slouken@devolution.com -*/ + Sam Lantinga + slouken@devolution.com + */ /* - SDL_epocvideo.cpp - Epoc based SDL video driver implementation - - Markus Mertama -*/ - + SDL_epocvideo.cpp + Epoc based SDL video driver implementation + Markus Mertama + */ #include "epoc_sdl.h" @@ -48,11 +46,8 @@ extern "C" { #include "SDL_epocvideo.h" #include "SDL_epocevents_c.h" - - #include #include - #include #include #include @@ -60,159 +55,102 @@ extern "C" { #include #include -#ifdef WINS -#include "gles_wincw_def.h" -#else #include "gles_armv5_def.h" -#endif - - -//////////////////////////////////////////////////////////////// - _LIT(KLibName, "SDL"); -#ifdef DEBUG_TRACE_ENABLED - -void RDebug_Print_b(char* error_str, void* param) - { - TBuf8<128> error8((TUint8*)error_str); - TBuf<128> error; - error.Copy(error8); - -#ifndef TRACE_TO_FILE - if (param) //!! Do not work if the parameter is really 0!! - RDebug::Print(error, param); - else - RDebug::Print(error); -#else - if (param) //!! Do not work if the parameter is really 0!! - RFileLogger::WriteFormat(KLibName, _L("SDL.txt"), EFileLoggingModeAppend, error, param); - else - RFileLogger::Write(KLibName, _L("SDL.txt"), EFileLoggingModeAppend, error); -#endif - - } - -extern "C" void RDebug_Print(char* error_str, void* param) - { - RDebug_Print_b(error_str, param); - } - -#endif //DEBUG_TRACE_ENABLED - -/* -int Debug_AvailMem2() - { - //User::CompressAllHeaps(); - TMemoryInfoV1Buf membuf; - User::LeaveIfError(UserHal::MemoryInfo(membuf)); - TMemoryInfoV1 minfo = membuf(); - return(minfo.iFreeRamInBytes); - } - -extern "C" int Debug_AvailMem() - { - return(Debug_AvailMem2()); - } - -*/ - extern "C" { -/* Initialization/Query functions */ + /* Initialization/Query functions */ -static int S60_VideoInit(_THIS, SDL_PixelFormat *vformat); -static SDL_Rect **S60_ListModes(_THIS, SDL_PixelFormat *format, Uint32 flags); -static SDL_Surface *S60_SetVideoMode(_THIS, SDL_Surface *current, int width, int height, int bpp, Uint32 flags); -static int S60_SetColors(_THIS, int firstcolor, int ncolors, - SDL_Color *colors); -static void S60_VideoQuit(_THIS); + static int S60_VideoInit(_THIS, SDL_PixelFormat *vformat); + static SDL_Rect **S60_ListModes(_THIS, SDL_PixelFormat *format, Uint32 flags); + static SDL_Surface *S60_SetVideoMode(_THIS, SDL_Surface *current, int width, int height, int bpp, Uint32 flags); + static int S60_SetColors(_THIS, int firstcolor, int ncolors, + SDL_Color *colors); + static void S60_VideoQuit(_THIS); -/* Hardware surface functions */ + /* Hardware surface functions */ -static int S60_AllocHWSurface(_THIS, SDL_Surface *surface); -static int S60_LockHWSurface(_THIS, SDL_Surface *surface); -static int S60_FlipHWSurface(_THIS, SDL_Surface *surface); -static void S60_UnlockHWSurface(_THIS, SDL_Surface *surface); -static void S60_FreeHWSurface(_THIS, SDL_Surface *surface); -static void S60_DirectUpdate(_THIS, int numrects, SDL_Rect *rects); + static int S60_AllocHWSurface(_THIS, SDL_Surface *surface); + static int S60_LockHWSurface(_THIS, SDL_Surface *surface); + static int S60_FlipHWSurface(_THIS, SDL_Surface *surface); + static void S60_UnlockHWSurface(_THIS, SDL_Surface *surface); + static void S60_FreeHWSurface(_THIS, SDL_Surface *surface); + static void S60_DirectUpdate(_THIS, int numrects, SDL_Rect *rects); -static int S60_Available(void); -static SDL_VideoDevice *S60_CreateDevice(int devindex); + static int S60_Available(void); + static SDL_VideoDevice *S60_CreateDevice(int devindex); -void DrawBackground(_THIS); -void DirectDraw(_THIS, int numrects, SDL_Rect *rects, TUint16* screenBuffer); -void DirectDrawRotated(_THIS, int numrects, SDL_Rect *rects, TUint16* screenBuffer); + void DrawBackground(_THIS); + void DirectDraw(_THIS, int numrects, SDL_Rect *rects, TUint16* screenBuffer); + void DirectDrawRotated(_THIS, int numrects, SDL_Rect *rects, TUint16* screenBuffer); -/* Mouse functions */ + /* Mouse functions */ -static WMcursor *S60_CreateWMCursor(_THIS, Uint8 *data, Uint8 *mask, int w, int h, int hot_x, int hot_y); -static void S60_FreeWMCursor(_THIS, WMcursor *cursor); -static int S60_ShowWMCursor(_THIS, WMcursor *cursor); + static WMcursor *S60_CreateWMCursor(_THIS, Uint8 *data, Uint8 *mask, int w, int h, int hot_x, int hot_y); + static void S60_FreeWMCursor(_THIS, WMcursor *cursor); + static int S60_ShowWMCursor(_THIS, WMcursor *cursor); -/*GL Functions*/ -static int S60_GlesLoadLibrary(_THIS, const char* path); -static void* S60_GlesGetProcAddress(_THIS, const char *proc); -static int S60_GlesGetAttribute(_THIS, SDL_GLattr attrib, int* value); -static int S60_GlesMakeCurrent(_THIS); -static void S60_GlesSwapBuffers(_THIS); + /*GL Functions*/ + static int S60_GlesLoadLibrary(_THIS, const char* path); + static void* S60_GlesGetProcAddress(_THIS, const char *proc); + static int S60_GlesGetAttribute(_THIS, SDL_GLattr attrib, int* value); + static int S60_GlesMakeCurrent(_THIS); + static void S60_GlesSwapBuffers(_THIS); } extern "C" - { +{ struct WMcursor - { - }; - } + { + }; +} /* Epoc video driver bootstrap functions */ - static int S60_Available(void) - { - return 1; /* Always available */ - } +{ + return 1; /* Always available */ +} static void S60_DeleteDevice(SDL_VideoDevice *device) - { - User::Free(device->gl_data); +{ + User::Free(device->gl_data); User::Free(device->hidden); User::Free(device); - } +} static SDL_VideoDevice *S60_CreateDevice(int /*devindex*/) - { +{ SDL_VideoDevice *device; - SDL_TRACE("SDL:S60_CreateDevice"); - /* Allocate all variables that we free on delete */ device = static_cast(User::Alloc(sizeof(SDL_VideoDevice))); if (device) - { + { Mem::FillZ(device, (sizeof *device)); device->hidden = static_cast - (User::Alloc((sizeof *device->hidden))); + (User::Alloc((sizeof *device->hidden))); device->gl_data = static_cast - (User::Alloc((sizeof (SDL_PrivateGLData)))); - } - else - { - SDL_OutOfMemory(); - return 0; - } + (User::Alloc((sizeof (SDL_PrivateGLData)))); + } + else + { + SDL_OutOfMemory(); + return 0; + } if((device->hidden == NULL) || (device->gl_data == NULL)) - { + { SDL_OutOfMemory(); User::Free(device->hidden); User::Free(device->gl_data); User::Free(device); return(0); - } - + } + Mem::FillZ(device->hidden, (sizeof *device->hidden)); /* Set the function pointers */ @@ -241,15 +179,15 @@ static SDL_VideoDevice *S60_CreateDevice(int /*devindex*/) device->InitOSKeymap = EPOC_InitOSKeymap; device->PumpEvents = EPOC_PumpEvents; device->free = S60_DeleteDevice; - + /*gles funtions*/ - + device->GL_LoadLibrary = S60_GlesLoadLibrary; - device->GL_GetProcAddress = S60_GlesGetProcAddress; - device->GL_GetAttribute = S60_GlesGetAttribute; - device->GL_MakeCurrent = S60_GlesMakeCurrent; - device->GL_SwapBuffers = S60_GlesSwapBuffers; - + device->GL_GetProcAddress = S60_GlesGetProcAddress; + device->GL_GetAttribute = S60_GlesGetAttribute; + device->GL_MakeCurrent = S60_GlesMakeCurrent; + device->GL_SwapBuffers = S60_GlesSwapBuffers; + device->gl_data->iLibrary.SetHandle(0); return device; @@ -258,193 +196,135 @@ static SDL_VideoDevice *S60_CreateDevice(int /*devindex*/) VideoBootStrap EPOC_bootstrap = { "epoc\0\0\0", "EPOC system", - S60_Available, S60_CreateDevice + S60_Available, S60_CreateDevice }; void DisableKeyBlocking(_THIS) - { - EpocSdlEnv::Request(EpocSdlEnv::EDisableKeyBlocking); - } +{ + EpocSdlEnv::Request(EpocSdlEnv::EDisableKeyBlocking); +} + +int S60_VideoInit(_THIS, SDL_PixelFormat *vformat) +{ + /* Initialise Epoc frame buffer */ -/*void ConstructWindowL(_THIS) - { - SDL_TRACE("SDL:ConstructWindowL"); DisableKeyBlocking(_this); //disable key blocking - } -*/ -int S60_VideoInit(_THIS, SDL_PixelFormat *vformat) - { - /* Construct Epoc window */ + const TDisplayMode displayMode = EpocSdlEnv::DisplayMode(); - // ConstructWindowL(_this); + /* The "best" video format should be returned to caller. */ - /* Initialise Epoc frame buffer */ + vformat->BitsPerPixel = TDisplayModeUtils::NumDisplayModeBitsPerPixel(displayMode); + vformat->BytesPerPixel = TDisplayModeUtils::NumDisplayModeBitsPerPixel(displayMode) / 8; - DisableKeyBlocking(_this); //disable key blocking - - const TDisplayMode displayMode = EpocSdlEnv::DisplayMode(); - - /* The "best" video format should be returned to caller. */ - - vformat->BitsPerPixel = TDisplayModeUtils::NumDisplayModeBitsPerPixel(displayMode); - vformat->BytesPerPixel = TDisplayModeUtils::NumDisplayModeBitsPerPixel(displayMode) / 8; - - - //?? Private->iWindow->PointerFilter(EPointerFilterDrag, 0); - - Private->iScreenPos = TPoint(0, 0); - - Private->iRect.x = Private->iScreenPos.iX; - Private->iRect.y = Private->iScreenPos.iY; - - const TSize sz = EpocSdlEnv::WindowSize(); - - Private->iRect.w = sz.iWidth; - Private->iRect.h = sz.iHeight; + Private->iScreenPos = TPoint(0, 0); + + Private->iRect.x = Private->iScreenPos.iX; + Private->iRect.y = Private->iScreenPos.iY; + + const TSize sz = EpocSdlEnv::WindowSize(); + + Private->iRect.w = sz.iWidth; + Private->iRect.h = sz.iHeight; Private->iRectPtr = &Private->iRect; return(0); - } +} SDL_Rect **S60_ListModes(_THIS, SDL_PixelFormat *format, Uint32 flags) - { +{ if(flags & SDL_HWSURFACE) - { + { if(format->BytesPerPixel != 4) //in HW only full color is supported return NULL; - } + } if(flags & SDL_FULLSCREEN) - { + { return &Private->iRectPtr; - } - - return (SDL_Rect **)(-1); //everythingisok, but too small shoes } + return (SDL_Rect **)(-1); //everythingisok, but too small shoes +} + int S60_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color *colors) - { +{ if ((firstcolor+ncolors) > 256) return -1; TUint32 palette[256]; const TDisplayMode mode = EpocSdlEnv::DisplayMode(); - if(TDisplayModeUtils::NumDisplayModeColors(mode) == 4096) - { - // Set 12 bit palette - for(int i = firstcolor; i < ncolors; i++) - { - // 4k value: 0000 rrrr gggg bbbb - TUint32 color4K = (colors[i].r & 0x0000f0) << 4; - color4K |= (colors[i].g & 0x0000f0); - color4K |= (colors[i].b & 0x0000f0) >> 4; - palette[i] = color4K; - } - } - else if(TDisplayModeUtils::NumDisplayModeColors(mode) == 65536) - { - for(int i = firstcolor; i < ncolors; i++) - { + if(TDisplayModeUtils::NumDisplayModeColors(mode) == 4096) + { + // Set 12 bit palette + for(int i = firstcolor; i < ncolors; i++) + { + // 4k value: 0000 rrrr gggg bbbb + TUint32 color4K = (colors[i].r & 0x0000f0) << 4; + color4K |= (colors[i].g & 0x0000f0); + color4K |= (colors[i].b & 0x0000f0) >> 4; + palette[i] = color4K; + } + } + else if(TDisplayModeUtils::NumDisplayModeColors(mode) == 65536) + { + for(int i = firstcolor; i < ncolors; i++) + { // 64k-colour displays effectively support RGB values // with 5 bits allocated to red, 6 to green and 5 to blue // 64k value: rrrr rggg gggb bbbb - TUint32 color64K = (colors[i].r & 0x0000f8) << 8; - color64K |= (colors[i].g & 0x0000fc) << 3; - color64K |= (colors[i].b & 0x0000f8) >> 3; - palette[i] = color64K; - } - } - else if(TDisplayModeUtils::NumDisplayModeColors(mode) == 16777216) - { - for(int i = firstcolor; i < ncolors; i++) - { - // 16M-colour - //0000 0000 rrrr rrrr gggg gggg bbbb bbbb - TUint32 color16M = colors[i].r << 16; - color16M |= colors[i].g << 8; - color16M |= colors[i].b; - palette[i] = color16M; - } - } - else - { - return -2; - } - if(EpocSdlEnv::SetPalette(firstcolor, ncolors, palette) == KErrNone) - return 0; - return -1; - } - - -/* -void AllocHWSurfaceL(CFbsBitmap*& aBitmap, const TDisplayMode& aMode, const TSize& aSize) - { - aBitmap = new (ELeave) CFbsBitmap(); - if(KErrNone != aBitmap->CreateHardwareBitmap(aSize, aMode, - EpocSdlEnv::EikonEnv().EikAppUi()->Application()->AppDllUid())) - //...if it fails - should we use wsbitmaps??? - {//the good reason to use hw bitmaps is that they wont need lock heap - PANIC_IF_ERROR(aBitmap->Create(aSize, aMode)); + TUint32 color64K = (colors[i].r & 0x0000f8) << 8; + color64K |= (colors[i].g & 0x0000fc) << 3; + color64K |= (colors[i].b & 0x0000f8) >> 3; + palette[i] = color64K; } } - -int CreateSurfaceL(_THIS, SDL_Surface* surface) - { - __ASSERT_ALWAYS(Private->iFrame == NULL, PANIC(KErrAlreadyExists)); -; - TInt dmode = EColorLast; - - TDisplayMode displayMode; - EpocSdlEnv::GetDiplayMode(displayMode); - - if( - TDisplayModeUtils::NumDisplayModeBitsPerPixel(displayMode) - == surface->format->BitsPerPixel) + else if(TDisplayModeUtils::NumDisplayModeColors(mode) == 16777216) + { + for(int i = firstcolor; i < ncolors; i++) { - dmode = displayMode; + // 16M-colour + //0000 0000 rrrr rrrr gggg gggg bbbb bbbb + TUint32 color16M = colors[i].r << 16; + color16M |= colors[i].g << 8; + color16M |= colors[i].b; + palette[i] = color16M; } + } else - { - --dmode; - while(TDisplayModeUtils::IsDisplayModeColor(TDisplayMode(dmode)) && - TDisplayModeUtils::NumDisplayModeBitsPerPixel(TDisplayMode(dmode)) != - surface->format->BitsPerPixel) - --dmode; - } - - __ASSERT_ALWAYS(TDisplayModeUtils::IsDisplayModeColor(TDisplayMode(dmode)), PANIC(KErrNotSupported)); - TRAPD(err, AllocHWSurfaceL(Private->iFrame, TDisplayMode(dmode), TSize(surface->w, surface->h))); - return err == KErrNone ? 0 : -1; - } -*/ - + { + return -2; + } + if(EpocSdlEnv::SetPalette(firstcolor, ncolors, palette) == KErrNone) + return 0; + return -1; +} int S60_GlesLoadLibrary(SDL_VideoDevice* _this, const char* path) - { +{ if(_this->gl_data->iLibrary.Handle() != 0) return KErrAlreadyExists; //already loaded const char* const gles_lib[] = {"libgles_cm.dll", "libSWGLES.dll"}; TInt err = KErrNotFound; for(TInt i = 0; i < 2 && err != KErrNone; i++) - { + { const char* name8 = path == NULL ? gles_lib[i] : path; TFileName lib; lib.Copy(TPtrC8((unsigned char*)name8)); err = _this->gl_data->iLibrary.Load(lib); - } + } if(err == KErrNone) _this->gl_config.driver_loaded = 1; return err; - } - +} + typedef TInt (*Ftp)(...); #define DC(x) ((Ftp) S60_GlesGetProcAddress(_this, #x)) const char* const OpenGL[] = //these funtions are in gl, but not in gles, at least in all in all versions... - { +{ "glBegin", "glEnd", "glOrtho", @@ -455,430 +335,397 @@ const char* const OpenGL[] = //these funtions are in gl, but not in gles, at lea "glTexCoord2f", "glVertex2i", "glTexParameteri" - }; - +}; + TInt NotSupported() - { +{ User::Panic(_L("SDL, Gles"), KErrNotSupported); return 0; - } - +} + void* S60_GlesGetProcAddress(_THIS, const char *proc) - { +{ if(_this->gl_data->iLibrary.Handle() == 0) return NULL; //not loaded TLibraryFunction f = NULL; for(TInt i = 0; i < G_ordinals_count; i++) - { + { if(strcmp(G_ordinals[i].name, proc) == 0) - { + { f = _this->gl_data->iLibrary.Lookup(G_ordinals[i].ord); break; - } } - + } + if(f != NULL) /*Lookup may fail*/ return (void*) f; - + for(TInt i = 0; i < sizeof(OpenGL) / sizeof(char*); i++) - { + { if(strcmp(OpenGL[i], proc) == 0) return (void*) NotSupported; - } - - return NULL; } - - + + return NULL; +} + + int S60_GlesGetAttribute(_THIS, SDL_GLattr aAttrib, int* aValue) - { +{ EGLint attrib; switch(aAttrib) - { + { /*todo*/ case SDL_GL_RED_SIZE: attrib = EGL_RED_SIZE; break; - case SDL_GL_GREEN_SIZE: attrib = EGL_GREEN_SIZE; break; - case SDL_GL_BLUE_SIZE:attrib = EGL_BLUE_SIZE; break; - case SDL_GL_ALPHA_SIZE: attrib = EGL_ALPHA_SIZE; break; - case SDL_GL_BUFFER_SIZE: attrib = EGL_BUFFER_SIZE; break; - case SDL_GL_DOUBLEBUFFER: *aValue = 1; return 0; //always - case SDL_GL_DEPTH_SIZE: attrib = EGL_DEPTH_SIZE; break; - case SDL_GL_STENCIL_SIZE: attrib = EGL_STENCIL_SIZE; break; - case SDL_GL_ACCUM_RED_SIZE: - case SDL_GL_ACCUM_GREEN_SIZE: - case SDL_GL_ACCUM_BLUE_SIZE: - case SDL_GL_ACCUM_ALPHA_SIZE: - case SDL_GL_STEREO: - case SDL_GL_MULTISAMPLEBUFFERS: - case SDL_GL_MULTISAMPLESAMPLES: - case SDL_GL_ACCELERATED_VISUAL: - case SDL_GL_SWAP_CONTROL: - *aValue = 0; - return -1; - } + case SDL_GL_GREEN_SIZE: attrib = EGL_GREEN_SIZE; break; + case SDL_GL_BLUE_SIZE:attrib = EGL_BLUE_SIZE; break; + case SDL_GL_ALPHA_SIZE: attrib = EGL_ALPHA_SIZE; break; + case SDL_GL_BUFFER_SIZE: attrib = EGL_BUFFER_SIZE; break; + case SDL_GL_DOUBLEBUFFER: *aValue = 1; return 0; //always + case SDL_GL_DEPTH_SIZE: attrib = EGL_DEPTH_SIZE; break; + case SDL_GL_STENCIL_SIZE: attrib = EGL_STENCIL_SIZE; break; + case SDL_GL_ACCUM_RED_SIZE: + case SDL_GL_ACCUM_GREEN_SIZE: + case SDL_GL_ACCUM_BLUE_SIZE: + case SDL_GL_ACCUM_ALPHA_SIZE: + case SDL_GL_STEREO: + case SDL_GL_MULTISAMPLEBUFFERS: + case SDL_GL_MULTISAMPLESAMPLES: + case SDL_GL_ACCELERATED_VISUAL: + case SDL_GL_SWAP_CONTROL: + *aValue = 0; + return -1; + } const int success = DC(eglGetConfigAttrib) ( - _this->gl_data->iDisplay, - _this->gl_data->iConfig, - attrib, - aValue); + _this->gl_data->iDisplay, + _this->gl_data->iConfig, + attrib, + aValue); return success == EGL_FALSE ? -1 : 0; - } - +} + int S60_GlesMakeCurrent(_THIS) - { +{ DC(eglMakeCurrent) - (_this->gl_data->iDisplay, - _this->gl_data->iSurface, - _this->gl_data->iSurface, - _this->gl_data->iContext); + (_this->gl_data->iDisplay, + _this->gl_data->iSurface, + _this->gl_data->iSurface, + _this->gl_data->iContext); return DC(eglGetError)(); - } +} void S60_GlesSwapBuffers(_THIS) - { +{ DC(eglSwapBuffers)( - _this->gl_data->iDisplay, - _this->gl_data->iSurface); - } + _this->gl_data->iDisplay, + _this->gl_data->iSurface); +} TDisplayMode GetDisplayMode(TInt aBitsPerPixel) - { +{ const TDisplayMode displayMode = EpocSdlEnv::DisplayMode(); TInt dmode = EColorLast; if( - TDisplayModeUtils::NumDisplayModeBitsPerPixel(displayMode) - == aBitsPerPixel) - { + TDisplayModeUtils::NumDisplayModeBitsPerPixel(displayMode) + == aBitsPerPixel) + { dmode = displayMode; - } + } else - { + { --dmode; while(TDisplayModeUtils::IsDisplayModeColor(TDisplayMode(dmode)) && - TDisplayModeUtils::NumDisplayModeBitsPerPixel(TDisplayMode(dmode)) != - aBitsPerPixel) + TDisplayModeUtils::NumDisplayModeBitsPerPixel(TDisplayMode(dmode)) != + aBitsPerPixel) --dmode; - } - return TDisplayMode(dmode); } - + return TDisplayMode(dmode); +} + LOCAL_C void glAssert(_THIS) - { +{ const EGLint err = DC(eglGetError)(); if(err != EGL_SUCCESS) - { + { User::Leave(err); - } } +} LOCAL_C void CreateGles(_THIS, RWindow& aWindow, int bpp, SDL_PrivateGLData& aData) - { +{ SDL_GL_LoadLibrary(NULL); //just if its not already loaded aData.iDisplay = DC(eglGetDisplay)(EGL_DEFAULT_DISPLAY); DC(eglInitialize)(aData.iDisplay, NULL, NULL); - + glAssert(_this); - + int configs = 0; EGLConfig* configList = NULL; int configSz = 0; DC(eglGetConfigs)(aData.iDisplay, configList, configSz, &configs); configSz = configs; - + glAssert(_this); - + configList = (EGLConfig*) User::Alloc(sizeof(EGLConfig) * configSz); -#ifdef __WIN32__ - const TDisplayMode mode = aWindow.DisplayMode(); - const TInt sz = TDisplayModeUtils::NumDisplayModeBitsPerPixel(mode); -#else TInt red, green, blue; if(bpp == 16) - { + { red = 5; green = 6; blue = 5; - } + } else - { + { red = 8; green = 8; blue = 8; - } -#endif - + } + const EGLint attribList[] = - { + { EGL_SURFACE_TYPE, EGL_WINDOW_BIT, -#ifdef __WIN32__ - EGL_BUFFER_SIZE, sz, -#else EGL_RED_SIZE, red, EGL_GREEN_SIZE, green, EGL_BLUE_SIZE, blue, EGL_BUFFER_SIZE, EGL_DONT_CARE, -#endif EGL_DEPTH_SIZE, 8, - // EGL_ALPHA_SIZE, 0, EGL_NONE - }; - + }; + DC(eglChooseConfig)(aData.iDisplay, - attribList, - configList, - configSz, - &configs); - - + attribList, + configList, + configSz, + &configs); + + glAssert(_this); - + __ASSERT_ALWAYS(configs > 0, User::Invariant()); - + aData.iConfig = configList[0]; - + User::Free(configList); - + aData.iContext = DC(eglCreateContext)(aData.iDisplay, - aData.iConfig, - EGL_NO_CONTEXT, - NULL); - + aData.iConfig, + EGL_NO_CONTEXT, + NULL); + glAssert(_this); - + aData.iSurface = DC(eglCreateWindowSurface)(aData.iDisplay, - aData.iConfig, - &aWindow, - NULL); - + aData.iConfig, + &aWindow, + NULL); + glAssert(_this); - - } - + +} + LOCAL_C void DestroyGles(_THIS) - { +{ if( _this->gl_config.driver_loaded) - { + { DC(eglMakeCurrent)(_this->gl_data->iDisplay, - EGL_NO_SURFACE, - EGL_NO_SURFACE, - EGL_NO_CONTEXT); + EGL_NO_SURFACE, + EGL_NO_SURFACE, + EGL_NO_CONTEXT); DC(eglDestroySurface)(_this->gl_data->iDisplay, _this->gl_data->iSurface); DC(eglDestroyContext)(_this->gl_data->iDisplay, _this->gl_data->iContext); DC(eglTerminate)(_this->gl_data->iDisplay); _this->gl_data->iLibrary.Close(); _this->gl_config.driver_loaded = 0; - } } +} SDL_Surface *S60_SetVideoMode(_THIS, SDL_Surface *current, - int width, int height, int bpp, Uint32 flags) + int width, int height, int bpp, Uint32 flags) +{ + if(flags & SDL_OPENGL) { - if(flags & SDL_OPENGL) - { - current->flags |= SDL_OPENGL; - current->w = width; - current->h = height; - + current->flags |= SDL_OPENGL; + current->w = width; + current->h = height; + RWindow* win = EpocSdlEnv::Window(); EpocSdlEnv::ApplyGlesDsa(); - + CreateGles(_this, *win, bpp, *_this->gl_data); - - return current; - } + + return current; + } const TSize screenSize = EpocSdlEnv::WindowSize(TSize(width, height)); if(width > screenSize.iWidth || height > screenSize.iHeight) - { - if(flags & SDL_FULLSCREEN) - { - width = screenSize.iWidth; - height = screenSize.iHeight; - } - else - return NULL; - } - - if(current && current->pixels) - { - // free(current->pixels); - current->pixels = NULL; - } - + { + if(flags & SDL_FULLSCREEN) + { + width = screenSize.iWidth; + height = screenSize.iHeight; + } + else + return NULL; + } + + if(current && current->pixels) + { + current->pixels = NULL; + } + if(!SDL_ReallocFormat(current, bpp, 0, 0, 0, 0)) - { + { return(NULL); - } + } current->flags = 0; if(width == screenSize.iWidth && height == screenSize.iHeight) current->flags |= SDL_FULLSCREEN; - + const int numBytesPerPixel = ((bpp-1)>>3) + 1; current->pitch = numBytesPerPixel * width; // Number of bytes in scanline - /* Set up the new mode framebuffer */ - current->flags |= SDL_PREALLOC; - - if(bpp <= 8) - current->flags |= SDL_HWPALETTE; - - User::Free(Private->iSwSurface); - current->pixels = NULL; - Private->iSwSurface = NULL; - - if(flags & SDL_HWSURFACE) - { - current->flags |= SDL_HWSURFACE; - // current->pixels = NULL; - // Private->iSwSurface = NULL; - } - else - { - current->flags |= SDL_SWSURFACE; - const TInt surfacesize = width * height * numBytesPerPixel; - Private->iSwSurfaceSize = TSize(width, height); - delete Private->iSwSurface; - Private->iSwSurface = NULL; - current->pixels = (TUint8*) User::Alloc(surfacesize); - Private->iSwSurface = (TUint8*) current->pixels; - const TInt err = EpocSdlEnv::AllocSwSurface - (TSize(width, height), GetDisplayMode(current->format->BitsPerPixel)); - if(err != KErrNone || current->pixels == NULL) - return NULL; - } - + /* Set up the new mode framebuffer */ + current->flags |= SDL_PREALLOC; + + if(bpp <= 8) + current->flags |= SDL_HWPALETTE; + + User::Free(Private->iSwSurface); + current->pixels = NULL; + Private->iSwSurface = NULL; + + if(flags & SDL_HWSURFACE) + { + current->flags |= SDL_HWSURFACE; + } + else + { + current->flags |= SDL_SWSURFACE; + const TInt surfacesize = width * height * numBytesPerPixel; + Private->iSwSurfaceSize = TSize(width, height); + delete Private->iSwSurface; + Private->iSwSurface = NULL; + current->pixels = (TUint8*) User::Alloc(surfacesize); + Private->iSwSurface = (TUint8*) current->pixels; + const TInt err = EpocSdlEnv::AllocSwSurface + (TSize(width, height), GetDisplayMode(current->format->BitsPerPixel)); + if(err != KErrNone || current->pixels == NULL) + return NULL; + } + current->w = width; current->h = height; - - - + /* Set the blit function */ _this->UpdateRects = S60_DirectUpdate; - /* - * Logic for getting suitable screen dimensions, offset, scaling and orientation - */ - - - /* Centralize game window on device screen */ - - - Private->iScreenPos.iX = Max(0, (screenSize.iWidth - width) / 2); - Private->iScreenPos.iY = Max(0, (screenSize.iHeight - height) / 2); - - // delete (Private->iFrame); -// Private->iFrame = NULL; - - // TRAPD(err, CreateSurfaceL(_this, current)); - // PANIC_IF_ERROR(err); - - SDL_TRACE1("View width %d", width); - SDL_TRACE1("View height %d", height); - SDL_TRACE1("View bmode %d", bpp); - SDL_TRACE1("View x %d", Private->iScreenPos.iX); - SDL_TRACE1("View y %d", Private->iScreenPos.iY); + /* + * Logic for getting suitable screen dimensions, offset, scaling and orientation + */ + + + /* Centralize game window on device screen */ + + + Private->iScreenPos.iX = Max(0, (screenSize.iWidth - width) / 2); + Private->iScreenPos.iY = Max(0, (screenSize.iHeight - height) / 2); EpocSdlEnv::LockPalette(EFalse); /* We're done */ return(current); } - - static int S60_AllocHWSurface(_THIS, SDL_Surface* surface) - { +{ return KErrNone == EpocSdlEnv::AllocHwSurface(TSize(surface->w, surface->h), GetDisplayMode(surface->format->BitsPerPixel)); - } - +} + static void S60_FreeHWSurface(_THIS, SDL_Surface* /*surface*/) - { - } +{ +} static int S60_LockHWSurface(_THIS, SDL_Surface* surface) - { +{ if(EpocSdlEnv::IsDsaAvailable()) - { + { TUint8* address = EpocSdlEnv::LockHwSurface(); if(address != NULL) - { + { surface->pixels = address; return 1; - } } - return 0; } + return 0; +} static void S60_UnlockHWSurface(_THIS, SDL_Surface* /*surface*/) - { +{ EpocSdlEnv::UnlockHwSurface(); - } +} static int S60_FlipHWSurface(_THIS, SDL_Surface* /*surface*/) - { +{ return(0); - } +} static void S60_DirectUpdate(_THIS, int numrects, SDL_Rect *rects) - { +{ if(EpocSdlEnv::IsDsaAvailable()) - { + { if(Private->iSwSurface) - { - const TRect target(Private->iScreenPos, Private->iSwSurfaceSize); - for(TInt i = 0; i < numrects ;i++) - { - const TRect rect(TPoint(rects[i].x, rects[i].y), - TSize(rects[i].w, rects[i].h)); - if(!EpocSdlEnv::AddUpdateRect(Private->iSwSurface, rect, target)) - return; //not succesful - } - EpocSdlEnv::UpdateSwSurface(); - } - SDL_PauseAudio(0); - } - else - { - SDL_PauseAudio(1); - EpocSdlEnv::WaitDsaAvailable(); + { + const TRect target(Private->iScreenPos, Private->iSwSurfaceSize); + for(TInt i = 0; i < numrects ;i++) + { + const TRect rect(TPoint(rects[i].x, rects[i].y), + TSize(rects[i].w, rects[i].h)); + if(!EpocSdlEnv::AddUpdateRect(Private->iSwSurface, rect, target)) + return; //not succesful + } + EpocSdlEnv::UpdateSwSurface(); } + SDL_PauseAudio(0); } - + else + { + SDL_PauseAudio(1); + EpocSdlEnv::WaitDsaAvailable(); + } +} /* Note: If we are terminated, this could be called in the middle of another SDL video routine -- notably UpdateRects. -*/ + */ void S60_VideoQuit(_THIS) - { -// delete Private->iFrame; -// Private->iFrame = NULL; - +{ if(_this->gl_data) DestroyGles(_this); - + User::Free(Private->iSwSurface); Private->iSwSurface = NULL; EpocSdlEnv::FreeSurface(); - } - +} + WMcursor *S60_CreateWMCursor(_THIS, Uint8* /*data*/, Uint8* /*mask*/, int /*w*/, int /*h*/, int /*hot_x*/, int /*hot_y*/) - { - return (WMcursor*) 1; //hii! prevents SDL to view a std cursor - } +{ + return (WMcursor*) 1; //hii! prevents SDL to view a std cursor +} void S60_FreeWMCursor(_THIS, WMcursor* /*cursor*/) - { - } +{ +} int S60_ShowWMCursor(_THIS, WMcursor *cursor) - { - return true; - } +{ + return true; +} /*FOR GL comp*/ diff --git a/src/video/symbian/SDL_epocvideo.h b/src/video/symbian/SDL_epocvideo.h dissimilarity index 71% index af7d265..26d5c6f 100644 --- a/src/video/symbian/SDL_epocvideo.h +++ b/src/video/symbian/SDL_epocvideo.h @@ -1,67 +1,67 @@ -/* - SDL - Simple DirectMedia Layer - Copyright (C) 1997, 1998, 1999, 2000, 2001 Sam Lantinga - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with this library; if not, write to the Free - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - - Sam Lantinga - slouken@devolution.com -*/ - -/* - S60 Adaptation Markus Mertama - 2003 - 2008 -*/ - -#ifndef EPOCVIDEO_H -#define EPOCVIDEO_H - -#include -#include - -/* Hidden "this" pointer for the video functions */ -#define _THIS SDL_VideoDevice *_this -#define Private _this->hidden - -class CFbsBitmap; - -struct SDL_VideoDevice; -void DisableKeyBlocking(SDL_VideoDevice*); - -struct SDL_PrivateVideoData - { - TPoint iScreenPos; - TBool iIsWindowFocused; - TSize iSwSurfaceSize; - TUint8* iSwSurface; - SDL_Rect iRect; //same info in SDL format - SDL_Rect* iRectPtr; - int null; //terminator - }; - -struct SDL_PrivateGLData - { - EGLDisplay iDisplay; - EGLConfig iConfig; - EGLSurface iContext; - EGLSurface iSurface; - RLibrary iLibrary; - }; - -#endif - - - - +/* + SDL - Simple DirectMedia Layer + Copyright (C) 1997, 1998, 1999, 2000, 2001 Sam Lantinga + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; if not, write to the Free + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + Sam Lantinga + slouken@devolution.com + */ + +/* + S60 Adaptation Markus Mertama + 2003 - 2008 + */ + +#ifndef EPOCVIDEO_H +#define EPOCVIDEO_H + +#include +#include + +/* Hidden "this" pointer for the video functions */ +#define _THIS SDL_VideoDevice *_this +#define Private _this->hidden + +class CFbsBitmap; + +struct SDL_VideoDevice; +void DisableKeyBlocking(SDL_VideoDevice*); + +struct SDL_PrivateVideoData +{ + TPoint iScreenPos; + TBool iIsWindowFocused; + TSize iSwSurfaceSize; + TUint8* iSwSurface; + SDL_Rect iRect; //same info in SDL format + SDL_Rect* iRectPtr; + int null; //terminator +}; + +struct SDL_PrivateGLData +{ + EGLDisplay iDisplay; + EGLConfig iConfig; + EGLSurface iContext; + EGLSurface iSurface; + RLibrary iLibrary; +}; + +#endif + + + + diff --git a/src/video/symbian/dsa.cpp b/src/video/symbian/dsa.cpp index 185249a..eb328ab 100644 --- a/src/video/symbian/dsa.cpp +++ b/src/video/symbian/dsa.cpp @@ -4,123 +4,119 @@ #include LOCAL_C TInt BytesPerPixel(TDisplayMode aMode) - { +{ return ((TDisplayModeUtils::NumDisplayModeBitsPerPixel(aMode) - 1) >> 3) + 1; - } - - - +} template NONSHARABLE_CLASS(CBitmapSurface) : public T - { -public: - CBitmapSurface(RWsSession& aSession); -private: - void ConstructL(RWindow& aWindow, CWsScreenDevice& aDevice); - ~CBitmapSurface(); - TUint8* LockSurface(); - void UnlockHwSurface(); - void CreateSurfaceL(); - void Wipe(TInt aLength); - void Free(); - void Update(CFbsBitmap& aBmp); - TInt ExternalUpdate(); -private: - CFbsBitmap* iBmp; - CFbsBitmap* iCopyBmp; - }; - +{ + public: + CBitmapSurface(RWsSession& aSession); -template + private: + void ConstructL(RWindow& aWindow, CWsScreenDevice& aDevice); + ~CBitmapSurface(); + TUint8* LockSurface(); + void UnlockHwSurface(); + void CreateSurfaceL(); + void Wipe(TInt aLength); + void Free(); + void Update(CFbsBitmap& aBmp); + TInt ExternalUpdate(); + CFbsBitmap* iBmp; + CFbsBitmap* iCopyBmp; +}; + + template void CBitmapSurface::ConstructL(RWindow& aWindow, CWsScreenDevice& aDevice) - { +{ delete iCopyBmp; iCopyBmp = NULL; iCopyBmp = new (ELeave) CFbsBitmap(); T::ConstructL(aWindow, aDevice); - } - -template +} + + template CBitmapSurface::CBitmapSurface(RWsSession& aSession) : T(aSession) - { - } - -template +{ +} + + template void CBitmapSurface::Free() - { +{ delete iBmp; iBmp = NULL; T::Free(); - } +} -template + template CBitmapSurface::~CBitmapSurface() - { +{ __ASSERT_DEBUG(iBmp == NULL, PANIC(KErrNotReady)); delete iCopyBmp; - } - -template +} + + template TUint8* CBitmapSurface::LockSurface() - { +{ iBmp->LockHeap(); return reinterpret_cast(iBmp->DataAddress()); - } +} -template + template void CBitmapSurface::UnlockHwSurface() - { +{ iBmp->UnlockHeap(); T::SetUpdating(EFalse); Update(*iBmp); - } +} - -template + + template void CBitmapSurface::Update(CFbsBitmap& aBmp) - { +{ T::DoBlt(aBmp); T::DrawOverlays(); T::CompleteUpdate(); - } - -template +} + + template void CBitmapSurface::CreateSurfaceL() - { +{ Free(); iBmp = new (ELeave) CFbsBitmap(); User::LeaveIfError(iBmp->Create(T::SwSize(), T::DisplayMode())); T::CreateSurfaceL(*iBmp); - } +} -template + template void CBitmapSurface::Wipe(TInt aLength) //dont call in drawing - { +{ iBmp->LockHeap(); Mem::FillZ(iBmp->DataAddress(), aLength); iBmp->UnlockHeap(); - } +} -template + template TInt CBitmapSurface::ExternalUpdate() - { +{ if(iCopyBmp->Handle() == 0) - { + { const TInt err = iCopyBmp->Duplicate(iBmp->Handle()); if(err != KErrNone) return err; - } + } Update(*iCopyBmp); return KErrNone; - } +} ////////////////////////////////////////////////////////////////////// NONSHARABLE_CLASS(CDsaGles) : public CDsa - { +{ public: CDsaGles(RWsSession& aSession); private: @@ -132,290 +128,287 @@ NONSHARABLE_CLASS(CDsaGles) : public CDsa void Wipe(TInt aLength); TInt ExternalUpdate(); CBitmapContext* Gc(); - }; +}; CDsaGles::CDsaGles(RWsSession& aSession) : CDsa(aSession) - { - } +{ +} TUint8* CDsaGles::LockSurface() - { - return NULL; - } - +{ + return NULL; +} + void CDsaGles::UnlockHWSurfaceRequestComplete() - { - } - +{ +} + void CDsaGles::UnlockHwSurface() - { - } - +{ +} + void CDsaGles::Resume() - { - } - +{ +} + void CDsaGles::CreateSurfaceL() - { - } - +{ +} + void CDsaGles::Wipe(TInt aLength) - { - } - +{ +} + TInt CDsaGles::ExternalUpdate() - { +{ return KErrNotSupported; - } - +} + CBitmapContext* CDsaGles::Gc() - { +{ return NULL; - } +} ////////////////////////////////////////////////////////////////////// NONSHARABLE_CLASS(CDsaBitgdi) : public CDsa - { -public: - CDsaBitgdi(RWsSession& aSession); -protected: - void ConstructL(RWindow& aWindow, CWsScreenDevice& aDevice); - CBitmapContext* Gc(); - void CompleteUpdate(); - ~CDsaBitgdi(); - void CreateSurfaceL(CFbsBitmap& aBmp); - void Free(); - void UnlockHWSurfaceRequestComplete(); -private: - void Resume(); - - CFbsBitGc* iGc; - CFbsDevice* iDevice; - CFbsBitmap* iBitGdiBmp; - CWindowGc* iWinGc; - RWindow* iWindow; - TInt iHandle; - }; +{ + public: + CDsaBitgdi(RWsSession& aSession); + protected: + void ConstructL(RWindow& aWindow, CWsScreenDevice& aDevice); + CBitmapContext* Gc(); + void CompleteUpdate(); + ~CDsaBitgdi(); + void CreateSurfaceL(CFbsBitmap& aBmp); + void Free(); + void UnlockHWSurfaceRequestComplete(); + private: + void Resume(); + + CFbsBitGc* iGc; + CFbsDevice* iDevice; + CFbsBitmap* iBitGdiBmp; + CWindowGc* iWinGc; + RWindow* iWindow; + TInt iHandle; +}; CDsaBitgdi::CDsaBitgdi(RWsSession& aSession) : CDsa(aSession) - { - } +{ +} CDsaBitgdi::~CDsaBitgdi() - { +{ delete iWinGc; delete iBitGdiBmp; - } +} void CDsaBitgdi::CompleteUpdate() - { +{ EpocSdlEnv::Request(CDsa::ERequestUpdate); - } +} + - void CDsaBitgdi::UnlockHWSurfaceRequestComplete() - { +{ if(iHandle == 0) return; - + if(iBitGdiBmp == NULL) - { + { iBitGdiBmp = new CFbsBitmap(); if(iBitGdiBmp == NULL) return; iBitGdiBmp->Duplicate(iHandle); - } - + } + iWindow->Invalidate(); - + iWindow->BeginRedraw(); iWinGc->Activate(*iWindow); - + if(!Blitter(*iBitGdiBmp)) - { + { if(SwSize() == HwRect().Size()) iWinGc->BitBlt(HwRect().iTl, iBitGdiBmp); else iWinGc->DrawBitmap(HwRect(), iBitGdiBmp); - } + } iWinGc->Deactivate(); iWindow->EndRedraw(); - } - +} + void CDsaBitgdi::Resume() - { +{ Start(); - } - +} + CBitmapContext* CDsaBitgdi::Gc() - { - return iWinGc; - } - - void CDsaBitgdi::ConstructL(RWindow& aWindow, CWsScreenDevice& aDevice) - { - - delete iBitGdiBmp; - iBitGdiBmp = NULL; - delete iWinGc; - iWinGc = NULL; - iHandle = 0; - - iWindow = &aWindow; - User::LeaveIfError(aDevice.CreateContext(iWinGc)); - CDsa::ConstructL(aWindow, aDevice); - Start(); - } - +{ + return iWinGc; +} + +void CDsaBitgdi::ConstructL(RWindow& aWindow, CWsScreenDevice& aDevice) +{ + + delete iBitGdiBmp; + iBitGdiBmp = NULL; + delete iWinGc; + iWinGc = NULL; + iHandle = 0; + + iWindow = &aWindow; + User::LeaveIfError(aDevice.CreateContext(iWinGc)); + CDsa::ConstructL(aWindow, aDevice); + Start(); +} + void CDsaBitgdi::CreateSurfaceL(CFbsBitmap& aBmp) - { +{ iDevice = CFbsBitmapDevice::NewL(&aBmp); User::LeaveIfError(iDevice->CreateContext(iGc)); iHandle = aBmp.Handle(); - } - +} + void CDsaBitgdi::Free() - { +{ delete iGc; iGc = NULL; delete iDevice; iDevice = NULL; - } - -//////////////////////////////////////////////////////////////////////// +} + /////////////////////////////////////////////////////////////////////// NONSHARABLE_CLASS(CDsaBase) : public CDsa, public MDirectScreenAccess - { -protected: - inline CDirectScreenAccess& Dsa() const; - CDsaBase(RWsSession& aSession); - ~CDsaBase(); - void ConstructL(RWindow& aWindow, CWsScreenDevice& aDevice); - void Stop(); - void Resume(); - CBitmapContext* Gc(); -protected: - CDirectScreenAccess* iDsa; -private: - void AbortNow(RDirectScreenAccess::TTerminationReasons aReason); - void Restart(RDirectScreenAccess::TTerminationReasons aReason); -private: - void RestartL(); - }; +{ + protected: + inline CDirectScreenAccess& Dsa() const; + CDsaBase(RWsSession& aSession); + ~CDsaBase(); + void ConstructL(RWindow& aWindow, CWsScreenDevice& aDevice); + void Stop(); + void Resume(); + CBitmapContext* Gc(); + protected: + CDirectScreenAccess* iDsa; + private: + void AbortNow(RDirectScreenAccess::TTerminationReasons aReason); + void Restart(RDirectScreenAccess::TTerminationReasons aReason); + private: + void RestartL(); +}; inline CDirectScreenAccess& CDsaBase::Dsa() const - { +{ return *iDsa; - } - +} + CDsaBase::CDsaBase(RWsSession& aSession) : CDsa(aSession) - { - } - +{ +} + CBitmapContext* CDsaBase::Gc() - { +{ return Dsa().Gc(); - } - +} + void CDsaBase::ConstructL(RWindow& aWindow, CWsScreenDevice& aDevice) - { - CDsa::ConstructL(aWindow, aDevice); - if(iDsa != NULL) - { - iDsa->Cancel(); - delete iDsa; - iDsa = NULL; - } - - iDsa = CDirectScreenAccess::NewL( - Session(), - aDevice, - aWindow, - *this); - RestartL(); - } - -void CDsaBase::Resume() +{ + CDsa::ConstructL(aWindow, aDevice); + if(iDsa != NULL) { + iDsa->Cancel(); + delete iDsa; + iDsa = NULL; + } + + iDsa = CDirectScreenAccess::NewL( + Session(), + aDevice, + aWindow, + *this); + RestartL(); +} + +void CDsaBase::Resume() +{ if(Stopped()) Restart(RDirectScreenAccess::ETerminateRegion); - } - +} + CDsaBase::~CDsaBase() - { +{ if(iDsa != NULL) - { - iDsa->Cancel(); - } - delete iDsa; + { + iDsa->Cancel(); } - - + delete iDsa; +} + + void CDsaBase::RestartL() - { - - - iDsa->StartL(); - - const RRegion* r = iDsa->DrawingRegion(); - const TRect rect = r->BoundingRect(); - iDsa->Gc()->SetClippingRegion(r); - - if(rect != ScreenRect()) - { - return ; - } - - - SetTargetRect(); +{ + + + iDsa->StartL(); + + const RRegion* r = iDsa->DrawingRegion(); + const TRect rect = r->BoundingRect(); + iDsa->Gc()->SetClippingRegion(r); + + if(rect != ScreenRect()) + { + return ; + } + + + SetTargetRect(); RecreateL(); - + Start(); - - - } + + +} void CDsaBase::AbortNow(RDirectScreenAccess::TTerminationReasons /*aReason*/) - { +{ Stop(); - } - +} + void CDsaBase::Restart(RDirectScreenAccess::TTerminationReasons aReason) - { +{ if(aReason == RDirectScreenAccess::ETerminateRegion) //auto restart - { + { TRAPD(err, RestartL()); if(err == KLeaveExit) - { + { Stop(); - } + } else - { + { PANIC_IF_ERROR(err); - } } } - - +} + + void CDsaBase::Stop() - { +{ CDsa::Stop(); iDsa->Cancel(); - } - - - /////////////////////////////////////////////////////////////////////// - /////////////////////////////////////////////////////////////////////// +} + +/////////////////////////////////////////////////////////////////////// NONSHARABLE_CLASS(TDsa) - { +{ public: inline TDsa(const CDsa& aDsa); inline TBool IsFlip() const; @@ -424,94 +417,91 @@ NONSHARABLE_CLASS(TDsa) inline void Copy(TUint32* aTarget, const TUint8* aSrc, TInt aBytes, TInt aHeight) const; private: const CDsa& iDsa; - }; - - - +}; inline TDsa::TDsa(const CDsa& aDsa) : iDsa(aDsa) - { - } +{ +} inline TBool TDsa::IsTurn() const - { +{ return iDsa.iStateFlags & CDsa::EOrientation90; - } - +} + inline TBool TDsa::IsFlip() const - { +{ return iDsa.iStateFlags & CDsa::EOrientation180; - } - +} + inline const TSize& TDsa::SwSize() const - { +{ return iDsa.SwSize(); - } - +} + inline void TDsa::Copy(TUint32* aTarget, const TUint8* aSrc, TInt aBytes, TInt aHeight) const - { +{ iDsa.iCopyFunction(iDsa, aTarget, aSrc, aBytes, aHeight); - } - -template +} + + template void ClipCopy(const TDsa& iDsa, TUint8* aTarget, - const TUint8* aSource, - const TRect& aUpdateRect, - const TRect& aSourceRect) - { + const TUint8* aSource, + const TRect& aUpdateRect, + const TRect& aSourceRect) +{ const S* source = reinterpret_cast(aSource); const TInt lineWidth = aSourceRect.Width(); - + source += (aUpdateRect.iTl.iY * lineWidth); const TInt sourceStartOffset = aUpdateRect.iTl.iX; source += sourceStartOffset; - + T* targetPtr = reinterpret_cast(aTarget); - + const TInt scanLineWidth = iDsa.SwSize().iWidth; - + targetPtr += (aSourceRect.iTl.iY + aUpdateRect.iTl.iY ) * scanLineWidth; const TInt targetStartOffset = (aUpdateRect.iTl.iX + aSourceRect.iTl.iX); - + targetPtr += targetStartOffset; - - + + const TInt height = aUpdateRect.Height(); - + const TInt lineMove = iDsa.IsTurn() ? 1 : lineWidth; const TInt copyLen = aUpdateRect.Width(); - - + + if(iDsa.IsFlip()) - { - + { + targetPtr += scanLineWidth * (height - 1); - + for(TInt i = 0; i < height; i++) //source is always smaller - { + { iDsa.Copy(reinterpret_cast(targetPtr), reinterpret_cast(source), copyLen, height); source += lineMove; targetPtr -= scanLineWidth; - } } + } else - { - - + { + + for(TInt i = 0; i < height; i++) //source is always smaller - { + { iDsa.Copy(reinterpret_cast(targetPtr), reinterpret_cast(source), copyLen, height); source += lineMove; targetPtr += scanLineWidth; // >> 2; - } } - } - - +} + + + NONSHARABLE_CLASS(CDsaA) : public CDsaBase - { +{ public: CDsaA(RWsSession& aSession); protected: @@ -521,130 +511,61 @@ NONSHARABLE_CLASS(CDsaA) : public CDsaBase void Free(); void UnlockHWSurfaceRequestComplete(); void DoBlt(CFbsBitmap& aBmp); - }; - - +}; + + CDsaA::CDsaA(RWsSession& aSession) : CDsaBase(aSession) - { - } - +{ +} + void CDsaA::ConstructL(RWindow& aWindow, CWsScreenDevice& aDevice) - { +{ CDsaBase::ConstructL(aWindow, aDevice); - } - +} + void CDsaA::CompleteUpdate() - { +{ iDsa->ScreenDevice()->Update(); - } - +} + void CDsaA::CreateSurfaceL(CFbsBitmap& /*aBmp*/) - { - } - +{ +} + void CDsaA::Free() - { - } - +{ +} + void CDsaA::DoBlt(CFbsBitmap& aBmp) - { +{ if(!Blitter(aBmp)) - { + { if(SwSize() == HwRect().Size()) Gc()->BitBlt(HwRect().iTl, &aBmp); else Gc()->DrawBitmap(HwRect(), &aBmp); - } } - +} + void CDsaA::UnlockHWSurfaceRequestComplete() - { +{ PANIC(KErrNotSupported); - } - - - +} + + + ////////////////////////////////////////////////////////////////////////////////////////////////////////////////// NONSHARABLE_CLASS(MDsbObs) - { +{ public: virtual void SurfaceReady() = 0; virtual CDirectScreenBitmap& Dsb() = 0; - }; - -/*NONSHARABLE_CLASS(MDsbSurface) - { - public: - virtual TUint8* Address() = 0; - virtual void Complete() = 0; - virtual void Unlock() = 0; - virtual ~MDsbSurface() = 0; - }; - -MDsbSurface::~MDsbSurface() - { - } - -NONSHARABLE_CLASS(CDsbSyncSurface) : public CBase, public MDsbSurface - { - public: - CDsbSyncSurface(MDsbObs& aDsb); - TUint8* Address(); - void Unlock(); - void Complete(); - ~CDsbSyncSurface(); - private: - MDsbObs& iDsb; - TUint8* iAddress; - TRequestStatus iStatus; - }; - -CDsbSyncSurface::CDsbSyncSurface(MDsbObs& aDsb) : iDsb(aDsb) - { - } - -TUint8* CDsbSyncSurface::Address() - { - if(iAddress == NULL) - { - // if(iStatus == KRequestPending) - // User::WaitForRequest(iStatus); - TAcceleratedBitmapInfo info; - if(KErrNone == iDsb.Dsb().BeginUpdate(info)) - iAddress = info.iAddress; - } - return iAddress; - } - -void CDsbSyncSurface::Unlock() - { - if(iAddress != NULL) - { - iAddress = NULL; - TRequestStatus status; - iDsb.Dsb().EndUpdate(status); - User::WaitForRequest(status); - } - } - -CDsbSyncSurface::~CDsbSyncSurface() - { - if(iStatus == KRequestPending) - User::WaitForRequest(iStatus); - } - - -void CDsbSyncSurface::Complete() - { - ASSERT(0); - } -*/ - +}; NONSHARABLE_CLASS(CDsbSurface) : public CActive - { +{ public: CDsbSurface(MDsbObs& aDsb); virtual TUint8* Address() = 0; @@ -657,33 +578,30 @@ NONSHARABLE_CLASS(CDsbSurface) : public CActive protected: MDsbObs& iDsb; TUint8* iAddress; - }; +}; CDsbSurface::CDsbSurface(MDsbObs& aDsb) : CActive(CActive::EPriorityHigh) , iDsb(aDsb) - { +{ CActiveScheduler::Add(this); - } - - +} CDsbSurface::~CDsbSurface() - { +{ Cancel(); - } - +} + void CDsbSurface::RunL() - { +{ iDsb.SurfaceReady(); - } +} void CDsbSurface::DoCancel() - { +{ //empty - } - +} NONSHARABLE_CLASS(CDsbSyncSurface) : public CDsbSurface - { +{ public: TUint8* Address(); CDsbSyncSurface(MDsbObs& aDsb); @@ -693,102 +611,99 @@ NONSHARABLE_CLASS(CDsbSyncSurface) : public CDsbSurface RSemaphore iSema; private: void RunL(); - }; - +}; + CDsbSyncSurface::CDsbSyncSurface(MDsbObs& aDsb) : CDsbSurface(aDsb) - { +{ iSema.CreateLocal(1); - } - +} TUint8* CDsbSyncSurface::Address() - { +{ if(IsActive()) iSema.Wait(); TAcceleratedBitmapInfo info; if(KErrNone == iDsb.Dsb().BeginUpdate(info)) iAddress = info.iAddress; return iAddress; - } - +} + void CDsbSyncSurface::Unlock() - { +{ EpocSdlEnv::Request(CDsa::ERequestUpdate); - } +} void CDsbSyncSurface::RunL() - { +{ CDsbSurface::RunL(); iSema.Signal(); - } - +} + CDsbSyncSurface::~CDsbSyncSurface() - { +{ iSema.Signal(); iSema.Close(); - } - +} void CDsbSyncSurface::Complete() - { +{ if(iAddress != NULL && !IsActive()) - { + { iAddress = NULL; SetActive(); iDsb.Dsb().EndUpdate(iStatus); - } + } else iSema.Signal(); - } +} NONSHARABLE_CLASS(CDsbAsyncSurface) : public CDsbSurface - { +{ public: TUint8* Address(); CDsbAsyncSurface(MDsbObs& aDsb); void Complete(); void Unlock(); ~CDsbAsyncSurface(); - }; +}; TUint8* CDsbAsyncSurface::Address() - { +{ if(iAddress == NULL && !IsActive()) - { + { TAcceleratedBitmapInfo info; if(KErrNone == iDsb.Dsb().BeginUpdate(info)) iAddress = info.iAddress; - } - return iAddress; } - + return iAddress; +} + CDsbAsyncSurface::CDsbAsyncSurface(MDsbObs& aDsb) : CDsbSurface(aDsb) - { - } +{ +} CDsbAsyncSurface::~CDsbAsyncSurface() - { - } - +{ +} + void CDsbAsyncSurface::Unlock() - { +{ EpocSdlEnv::Request(CDsa::ERequestUpdate); - } - +} + void CDsbAsyncSurface::Complete() - { +{ if(iAddress != NULL && !IsActive()) - { + { iAddress = NULL; SetActive(); iDsb.Dsb().EndUpdate(iStatus); - } } - - +} + NONSHARABLE_CLASS(CDsaB) : public CDsaBase, - public MDsbObs - { + public MDsbObs +{ public: enum {EDrawModeDSBAsync = 0x1000}; CDsaB(RWsSession& aSession, TInt aFlags); @@ -808,129 +723,100 @@ NONSHARABLE_CLASS(CDsaB) : public CDsaBase, CDsbSurface* iSurface1; CDirectScreenBitmap* iDsb; TInt iType; -#ifdef TWO_DSB_SURFACES //The second surface like this may be a invalid implementation, - //however it works with some platforms, with some platforms it crashes - //so double buffer flags should work always with a single surface - CDsbSurface* iSurface2; -#endif - }; +}; CDsaB::CDsaB(RWsSession& aSession, TInt aFlags) : CDsaBase(aSession), iType(aFlags) - { - } +{ +} + - void CDsaB::UnlockHWSurfaceRequestComplete() - { +{ iSurface1->Complete(); -#ifdef TWO_DSB_SURFACES - if(iSurface2 != NULL) - iSurface2->Complete(); -#endif - } +} void CDsaB::CreateSurfaceL() - { +{ __ASSERT_ALWAYS(SwSize() == HwRect().Size(), PANIC(KErrNotSupported)); - } - +} + void CDsaB::Wipe(TInt aLength) //dont call in drawing - { +{ TUint8* addr = LockSurface(); if(addr != NULL) - { + { Mem::FillZ(addr, aLength); UnlockHwSurface(); - } } - +} + void CDsaB::UnlockHwSurface() - { +{ iSurface1->Unlock(); - } - +} + TUint8* CDsaB::LockSurface() - { +{ TUint8* addr = iSurface1->Address(); -#ifdef TWO_DSB_SURFACES - if(addr == NULL && iSurface2 != NULL) - addr = iSurface2->Address(); -#endif SetUpdating(addr == NULL); return addr; - } - +} + void CDsaB::SurfaceReady() - { +{ SetUpdating(EFalse); - } +} CDirectScreenBitmap& CDsaB::Dsb() - { +{ return *iDsb; - } - +} + void CDsaB::ConstructL(RWindow& aWindow, CWsScreenDevice& aDevice) - { +{ if(iDsb == NULL) iDsb = CDirectScreenBitmap::NewL(); CDsaBase::ConstructL(aWindow, aDevice); if(iSurface1 == NULL) - { + { if( (iType & CDsaB::EDrawModeDSBAsync)) iSurface1 = new (ELeave) CDsbAsyncSurface(*this); else iSurface1 = new (ELeave) CDsbSyncSurface(*this); - } - -#ifdef TWO_DSB_SURFACES - if(iSurface2 == NULL && (iType & CDirectScreenBitmap::EDoubleBuffer)) - { - if( (iType & CDsaB::EDrawModeDSBAsync)) - iSurface2 = new (ELeave) CDsbAsyncSurface(*this); - else - iSurface2 = new (ELeave) CDsbSyncSurface(*this); - } -#endif } - +} + CDsaB::~CDsaB() - { +{ delete iSurface1; -#ifdef TWO_DSB_SURFACES - delete iSurface2; -#endif delete iDsb; - } +} void CDsaB::RecreateL() - { - iDsb->Close(); - CDirectScreenBitmap::TSettingsFlags flags = CDirectScreenBitmap::TSettingsFlags(iType & 0xFF); - iDsb->Create(HwRect(), flags); - } - +{ + iDsb->Close(); + CDirectScreenBitmap::TSettingsFlags flags = CDirectScreenBitmap::TSettingsFlags(iType & 0xFF); + iDsb->Create(HwRect(), flags); +} + TInt CDsaB::ExternalUpdate() - { +{ if(LockSurface()) - { + { UnlockHWSurfaceRequestComplete(); return KErrNone; - } - return KErrNotReady; } - + return KErrNotReady; +} ///////////////////////////////////////////////////////////////////////////////////////////////////// - - CDsa* CDsa::CreateL(RWsSession& aSession) - { +{ if(EpocSdlEnv::Flags(CSDL::EDrawModeDSB)) - { + { TInt flags = CDirectScreenBitmap::ENone; if(EpocSdlEnv::Flags(CSDL::EDrawModeDSBDoubleBuffer)) flags |= CDirectScreenBitmap::EDoubleBuffer; @@ -939,63 +825,63 @@ CDsa* CDsa::CreateL(RWsSession& aSession) if(EpocSdlEnv::Flags(CSDL::EDrawModeDSBAsync)) flags |= CDsaB::EDrawModeDSBAsync; return new (ELeave) CDsaB(aSession, flags); - } + } else if(EpocSdlEnv::Flags(CSDL::EDrawModeGdi)) - { + { return new (ELeave) CBitmapSurface(aSession); - } - else - { - return new (ELeave) CBitmapSurface(aSession); - } } - - -void CDsa::RecreateL() + else { + return new (ELeave) CBitmapSurface(aSession); } +} + + +void CDsa::RecreateL() +{ +} void CDsa::Free() - { - } - +{ +} + TSize CDsa::WindowSize() const - { +{ TSize size = iSwSize; if(iStateFlags & EOrientation90) - { + { const TInt tmp = size.iWidth; size.iWidth = size.iHeight; size.iHeight = tmp; - } - return size; } - + return size; +} + void CDsa::SetSuspend() - { +{ iStateFlags |= ESdlThreadSuspend; - } +} void CDsa::SetUpdating(TBool aUpdate) - { +{ if(aUpdate) iStateFlags |= EUpdating; else iStateFlags &= ~EUpdating; - } +} TBool CDsa::Stopped() const - { +{ return (iStateFlags & ESdlThreadExplicitStop); - } +} void CDsa::SetOrientation(CDsa::TOrientationMode aOrientation) - { +{ TInt flags = 0; switch(aOrientation) - { + { case CDsa::EViewOrientation90: flags = EOrientation90; break; @@ -1008,22 +894,22 @@ void CDsa::SetOrientation(CDsa::TOrientationMode aOrientation) case CDsa::EViewOrientation0: flags = 0; break; - } + } if(flags != (iStateFlags & EOrientationFlags)) - { + { iStateFlags |= EOrientationChanged; iNewFlags = flags; //cannot be set during drawing... - } } +} CDsa::~CDsa() - { - iOverlays.Close(); - User::Free(iLut256); - } - +{ + iOverlays.Close(); + User::Free(iLut256); +} + void CDsa::ConstructL(RWindow& aWindow, CWsScreenDevice& /*aDevice*/) - { +{ if(iLut256 == NULL) iLut256 = (TUint32*) User::AllocL(256 * sizeof(TUint32)); iTargetMode = aWindow.DisplayMode(); @@ -1031,51 +917,51 @@ void CDsa::ConstructL(RWindow& aWindow, CWsScreenDevice& /*aDevice*/) iScreenRect = TRect(aWindow.Position(), aWindow.Size()); SetTargetRect(); iWindow = &aWindow; - } - - +} + + void CDsa::DrawOverlays() - { +{ const TInt last = iOverlays.Count() - 1; for(TInt i = last; i >= 0 ; i--) iOverlays[i].iOverlay->Draw(*Gc(), HwRect(), SwSize()); - } +} void CDsa::DoBlt(CFbsBitmap& /*aBmp*/) - { - } +{ +} TInt CDsa::AppendOverlay(MOverlay& aOverlay, TInt aPriority) - { +{ TInt i; for(i = 0; i < iOverlays.Count() && iOverlays[i].iPriority < aPriority; i++) - {} + {} const TOverlay overlay = {&aOverlay, aPriority}; return iOverlays.Insert(overlay, i); - } - +} + TInt CDsa::RemoveOverlay(MOverlay& aOverlay) - { +{ for(TInt i = 0; i < iOverlays.Count(); i++) - { + { if(iOverlays[i].iOverlay == &aOverlay) - { + { iOverlays.Remove(i); return KErrNone; - } } - return KErrNotFound; } + return KErrNotFound; +} void CDsa::LockPalette(TBool aLock) - { +{ if(aLock) iStateFlags |= EPaletteLocked; else iStateFlags &= ~EPaletteLocked; - } +} TInt CDsa::SetPalette(TInt aFirst, TInt aCount, TUint32* aPalette) - { +{ if(iLut256 == NULL) return KErrNotFound; const TInt count = aCount - aFirst; @@ -1084,186 +970,119 @@ TInt CDsa::SetPalette(TInt aFirst, TInt aCount, TUint32* aPalette) if(iStateFlags & EPaletteLocked) return KErrNone; for(TInt i = aFirst; i < count; i++) //not so busy here:-) - { + { iLut256[i] = aPalette[i]; - } - return KErrNone; } - - - + return KErrNone; +} - CDsa::CDsa(RWsSession& aSession) : - iStateFlags(0), - iSession(aSession) - - { -// CActiveScheduler::Add(this); + iStateFlags(0), + iSession(aSession) + +{ iCFTable[0] = CopyMem; iCFTable[1] = CopyMemFlipReversed; iCFTable[2] = CopyMemReversed; iCFTable[3] = CopyMemFlip; - + iCFTable[4] = Copy256; iCFTable[5] = Copy256FlipReversed; iCFTable[6] = Copy256Reversed; iCFTable[7] = Copy256Flip; - - + + iCFTable[8] = CopySlow; iCFTable[9] = CopySlowFlipReversed; iCFTable[10] = CopySlowReversed; iCFTable[11] = CopySlowFlip; - } - +} + RWsSession& CDsa::Session() - { +{ return iSession; - } +} TInt CDsa::RedrawRequest() - { +{ if(!(iStateFlags & (EUpdating) && (iStateFlags & ERunning))) - { - return ExternalUpdate(); - } - return KErrNotReady; - } - -TUint8* CDsa::LockHwSurface() { - if((iStateFlags & EUpdating) == 0) //else frame is skipped - { - return LockSurface(); - } - return NULL; - } - -/* -void CDsa::RunL() - { - iStateFlags &= ~EUpdating; + return ExternalUpdate(); } - - -void CDsa::DoCancel() + return KErrNotReady; +} + +TUint8* CDsa::LockHwSurface() +{ + if((iStateFlags & EUpdating) == 0) //else frame is skipped { - iStateFlags &= ~EUpdating; - //nothing can do, just wait? + return LockSurface(); } -*/ + return NULL; +} - TInt CDsa::AllocSurface(TBool aHwSurface, const TSize& aSize, TDisplayMode aMode) - { +{ if(aHwSurface && aMode != DisplayMode()) return KErrArgument; - + iSourceMode = aMode; - + iSourceBpp = BytesPerPixel(aMode); - + const TSize size = WindowSize(); if(aSize.iWidth > size.iWidth) return KErrTooBig; if(aSize.iHeight > size.iHeight) return KErrTooBig; - + TRAPD(err, CreateSurfaceL()); if(err != KErrNone) return err; SetCopyFunction(); - + return KErrNone; - } - +} + void CDsa::CreateZoomerL(const TSize& aSize) - { +{ iSwSize = aSize; iStateFlags |= EResizeRequest; CreateSurfaceL(); SetTargetRect(); - } - - -/* -void SaveBmp(const TDesC& aName, const TAny* aData, TInt aLength, const TSize& aSz, TDisplayMode aMode) - { - CFbsBitmap* s = new CFbsBitmap(); - s->Create(aSz, aMode); - s->LockHeap(); - TUint32* addr = s->DataAddress(); - Mem::Copy(addr, aData, aLength); - s->UnlockHeap(); - s->Save(aName); - s->Reset(); - delete s; - } - -void SaveBmp(const TDesC& aName, const TUint32* aData, const TSize& aSz) - { - CFbsBitmap* s = new CFbsBitmap(); - s->Create(aSz, EColor64K); - TBitmapUtil bmp(s); - bmp.Begin(TPoint(0, 0)); - for(TInt j = 0; j < aSz.iHeight; j++) - { - bmp.SetPos(TPoint(0, j)); - for(TInt i = 0; i < aSz.iWidth; i++) - { - bmp.SetPixel(*aData); - aData++; - bmp.IncXPos(); - } - } - bmp.End(); - s->Save(aName); - s->Reset(); - delete s; - } - -TBuf<16> FooName(TInt aFoo) - { - TBuf<16> b; - b.Format(_L("C:\\pic%d.mbm"), aFoo); - return b; - } - -*/ - +} void CDsa::ClipCopy(TUint8* aTarget, - const TUint8* aSource, - const TRect& aUpdateRect, - const TRect& aSourceRect) const - { - const TDsa dsa(*this); - switch(iSourceBpp) - { - case 1: - ::ClipCopy(dsa, aTarget, aSource, aUpdateRect, aSourceRect); - break; - case 2: - ::ClipCopy(dsa, aTarget, aSource, aUpdateRect, aSourceRect); - break; - case 4: - ::ClipCopy(dsa, aTarget, aSource, aUpdateRect, aSourceRect); - break; - } - } + const TUint8* aSource, + const TRect& aUpdateRect, + const TRect& aSourceRect) const +{ + const TDsa dsa(*this); + switch(iSourceBpp) + { + case 1: + ::ClipCopy(dsa, aTarget, aSource, aUpdateRect, aSourceRect); + break; + case 2: + ::ClipCopy(dsa, aTarget, aSource, aUpdateRect, aSourceRect); + break; + case 4: + ::ClipCopy(dsa, aTarget, aSource, aUpdateRect, aSourceRect); + break; + } +} void CDsa::Wipe() //dont call in drawing - { +{ if(IsDsaAvailable()) Wipe(iTargetBpp * SwSize().iWidth * SwSize().iHeight); - } - +} + void CDsa::SetCopyFunction() - { +{ //calculate offset to correct function in iCFTable according to given parameters TInt function = 0; const TInt KCopyFunctions = 4; @@ -1272,156 +1091,145 @@ void CDsa::SetCopyFunction() const TInt KOffsetToOtherModes = KOffsetTo256 + KCopyFunctions; const TInt KOffsetTo90Functions = 1; const TInt KOffsetTo180Functions = 2; - + if(iSourceMode == DisplayMode()) function = KOffsetToNative; //0 else if(iSourceMode == EColor256) function = KOffsetTo256; //4 else function = KOffsetToOtherModes; //8 - + if(iStateFlags & EOrientation90) function += KOffsetTo90Functions; // + 1 if(iStateFlags & EOrientation180) function += KOffsetTo180Functions; //+ 2 - + iCopyFunction = iCFTable[function]; - + Wipe(); - } - +} + inline void Rotate(TRect& aRect) - { +{ const TInt dx = aRect.iBr.iX - aRect.iTl.iX; const TInt dy = aRect.iBr.iY - aRect.iTl.iY; aRect.iBr.iX = aRect.iTl.iX + dy; aRect.iBr.iY = aRect.iTl.iY + dx; - + const TInt tmp = aRect.iTl.iX; aRect.iTl.iX = aRect.iTl.iY; aRect.iTl.iY = tmp; - } - -/* -int bar = 0; -*/ +} TBool CDsa::AddUpdateRect(const TUint8* aBits, const TRect& aUpdateRect, const TRect& aRect) - { +{ if(iStateFlags & EOrientationChanged) - { + { iStateFlags &= ~EOrientationFlags; iStateFlags |= iNewFlags; SetCopyFunction(); iStateFlags &= ~EOrientationChanged; - EpocSdlEnv::WaitDeviceChange(); - return EFalse; //skip this frame as data is may be changed - } + EpocSdlEnv::WaitDeviceChange(); + return EFalse; //skip this frame as data is may be changed + } if(iTargetAddr == NULL) - { + { iTargetAddr = LockHwSurface(); - } - + } + TUint8* target = iTargetAddr; if(target == NULL) return EFalse; - - + + TRect targetRect = TRect(TPoint(0, 0), SwSize()); - + TRect sourceRect = aRect; TRect updateRect = aUpdateRect; - -// TPoint move(0, 0); - - + if(iStateFlags & EOrientation90) - { + { Rotate(sourceRect); Rotate(updateRect); - } - + } + if(iSourceMode != DisplayMode() || targetRect != sourceRect || targetRect != updateRect || ((iStateFlags & EOrientationFlags) != 0)) - { + { sourceRect.Intersection(targetRect); //so source always smaller or equal than target - //updateRect.Intersection(targetRect); ClipCopy(target, aBits, updateRect, sourceRect); - } + } else - { + { const TInt byteCount = aRect.Width() * aRect.Height() * iSourceBpp; //this could be stored Mem::Copy(target, aBits, byteCount); - } + } return ETrue; - } - - +} + + void CDsa::UpdateSwSurface() - { +{ iTargetAddr = NULL; UnlockHwSurface(); //could be faster if does not use AO, but only check status before redraw, then no context switch needed - } - +} - - void CDsa::DoStop() - { +{ if(IsDsaAvailable()) iStateFlags |= ESdlThreadExplicitStop; Stop(); - } +} + - void CDsa::Stop() - { +{ iStateFlags &= ~ERunning; - } - +} + void CDsa::Start() - { - iStateFlags |= ERunning; - +{ + iStateFlags |= ERunning; + iStateFlags &= ~ESdlThreadExplicitStop; - - if(iStateFlags & ESdlThreadSuspend) - { - EpocSdlEnv::Resume(); - iStateFlags &= ~ ESdlThreadSuspend; - } - EpocSdlEnv::ObserverEvent(MSDLObserver::EEventWindowReserved); - } + + if(iStateFlags & ESdlThreadSuspend) + { + EpocSdlEnv::Resume(); + iStateFlags &= ~ ESdlThreadSuspend; + } + EpocSdlEnv::ObserverEvent(MSDLObserver::EEventWindowReserved); +} TBool CDsa::Blitter(CFbsBitmap& aBmp) - { +{ return iBlitter && iBlitter->BitBlt(*Gc(), aBmp, HwRect(), SwSize()); - } - +} + void CDsa::SetBlitter(MBlitter* aBlitter) - { +{ iBlitter = aBlitter; - } - - +} + + TPoint CDsa::WindowCoordinates(const TPoint& aPoint) const - { +{ TPoint pos = aPoint - iScreenRect.iTl; const TSize asz = iScreenRect.Size(); if(iStateFlags & EOrientation180) - { + { pos.iX = asz.iWidth - pos.iX; pos.iY = asz.iHeight - pos.iY; - } + } if(iStateFlags & EOrientation90) - { + { pos.iX = aPoint.iY; pos.iY = aPoint.iX; - } + } pos.iX <<= 16; pos.iY <<= 16; pos.iX /= asz.iWidth; @@ -1431,196 +1239,189 @@ TPoint CDsa::WindowCoordinates(const TPoint& aPoint) const pos.iX >>= 16; pos.iY >>= 16; return pos; - } - +} + void CDsa::SetTargetRect() - { +{ iTargetRect = iScreenRect; if(iStateFlags & EResizeRequest && EpocSdlEnv::Flags(CSDL::EAllowImageResizeKeepRatio)) - { + { const TSize asz = iScreenRect.Size(); const TSize sz = iSwSize; - + TRect rect; - + const TInt dh = (sz.iHeight << 16) / sz.iWidth; if((asz.iWidth * dh ) >> 16 <= asz.iHeight) - { + { rect.SetRect(TPoint(0, 0), TSize(asz.iWidth, (asz.iWidth * dh) >> 16)); - } + } else - { + { const TInt dw = (sz.iWidth << 16) / sz.iHeight; - rect.SetRect(TPoint(0, 0), TSize((asz.iHeight * dw) >> 16, asz.iHeight)); - } + rect.SetRect(TPoint(0, 0), TSize((asz.iHeight * dw) >> 16, asz.iHeight)); + } rect.Move((asz.iWidth - rect.Size().iWidth) >> 1, (asz.iHeight - rect.Size().iHeight) >> 1); - + iTargetRect = rect; iTargetRect.Move(iScreenRect.iTl); - } + } if(!(iStateFlags & EResizeRequest)) iSwSize = iScreenRect.Size(); - } - +} + RWindow* CDsa::Window() - { +{ return iWindow; - } - +} + CDsa* CDsa::CreateGlesDsaL() - { +{ CDsa* dsa = new (ELeave) CDsaGles(Session()); CWsScreenDevice* dummy = NULL; dsa->ConstructL(*Window(), *dummy); Free(); delete this; return dsa; - } - +} + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////// void CDsa::Copy256(const CDsa& aDsa, TUint32* aTarget, const TUint8* aSource, TInt aBytes, TInt) - { +{ TUint32* target = aTarget; const TUint32* endt = target + aBytes; const TUint8* source = aSource; while(target < endt) - { + { *target++ = aDsa.iLut256[*source++]; - } } - +} + void CDsa::Copy256Reversed(const CDsa& aDsa, TUint32* aTarget, const TUint8* aSource, TInt aBytes, TInt) - { +{ const TUint32* target = aTarget; TUint32* endt = aTarget + aBytes; const TUint8* source = aSource; while(target < endt) - { + { *(--endt) = aDsa.iLut256[*source++]; - } - } - + } +} + void CDsa::Copy256Flip(const CDsa& aDsa, TUint32* aTarget, const TUint8* aSource, TInt aBytes, TInt aLineLen) - { +{ TUint32* target = aTarget; const TUint32* endt = target + aBytes; const TUint8* column = aSource; while(target < endt) - { + { *target++ = aDsa.iLut256[*column]; column += aLineLen; - } } - +} + void CDsa::Copy256FlipReversed(const CDsa& aDsa, TUint32* aTarget, const TUint8* aSource, TInt aBytes, TInt aLineLen) - { +{ const TUint32* target = aTarget; TUint32* endt = aTarget + aBytes; const TUint8* column = aSource; while(target < endt) - { + { *(--endt) = aDsa.iLut256[*column]; column += aLineLen; - } - } + } +} void CDsa::CopyMem(const CDsa& /*aDsa*/, TUint32* aTarget, const TUint8* aSource, TInt aBytes, TInt) - { +{ const TUint32* src = reinterpret_cast(aSource); Mem::Copy(aTarget, src, aBytes << 2); - } - +} + void CDsa::CopyMemFlip(const CDsa& /*aDsa*/, TUint32* aTarget, const TUint8* aSource, TInt aBytes, TInt aLineLen) - { +{ TUint32* target = aTarget; const TUint32* endt = target + aBytes; const TUint32* column = reinterpret_cast(aSource); while(target < endt) - { + { *target++ = *column; column += aLineLen; - } } - +} + void CDsa::CopyMemReversed(const CDsa& /*aDsa*/, TUint32* aTarget, const TUint8* aSource, TInt aBytes, TInt) - { +{ const TUint32* target = aTarget; TUint32* endt = aTarget + aBytes; const TUint32* source = reinterpret_cast(aSource); while(target < endt) - { + { *(--endt) = *source++; - } - } - - + } +} + + void CDsa::CopyMemFlipReversed(const CDsa& /*aDsa*/, TUint32* aTarget, const TUint8* aSource, TInt aBytes, TInt aLineLen) - { +{ const TUint32* target = aTarget; TUint32* endt = aTarget + aBytes; const TUint32* column = reinterpret_cast(aSource); while(target < endt) - { + { *(--endt) = *column; column += aLineLen; - } } - -/* +} -LOCAL_C TRgb rgb16MA(TInt aValue) - { - return TRgb::Color16MA(aValue); - } -*/ NONSHARABLE_CLASS(MRgbCopy) - { +{ public: - virtual void Copy(TUint32* aTarget, const TUint8* aSource, TInt aBytes, TBool aReversed) = 0; - virtual void FlipCopy(TUint32* aTarget, const TUint8* aSource, TInt aBytes, TInt aLineLen, TBool aReversed) = 0; - }; - + virtual void Copy(TUint32* aTarget, const TUint8* aSource, TInt aBytes, TBool aReversed) = 0; + virtual void FlipCopy(TUint32* aTarget, const TUint8* aSource, TInt aBytes, TInt aLineLen, TBool aReversed) = 0; +}; + template NONSHARABLE_CLASS(TRgbCopy) : public MRgbCopy - { +{ public: - TRgbCopy(TDisplayMode aMode); - void* operator new(TUint aBytes, TAny* aMem); - void Copy(TUint32* aTarget, const TUint8* aSource, TInt aBytes, TBool aReversed); - void FlipCopy(TUint32* aTarget, const TUint8* aSource, TInt aBytes, TInt aLineLen, TBool aReversed); - static TUint32 Gray256(const TUint8& aPixel); - static TUint32 Color256(const TUint8& aPixel); - static TUint32 Color4K(const TUint16& aPixel); - static TUint32 Color64K(const TUint16& aPixel); - static TUint32 Color16M(const TUint32& aPixel); - static TUint32 Color16MU(const TUint32& aPixel); - static TUint32 Color16MA(const TUint32& aPixel); + TRgbCopy(TDisplayMode aMode); + void* operator new(TUint aBytes, TAny* aMem); + void Copy(TUint32* aTarget, const TUint8* aSource, TInt aBytes, TBool aReversed); + void FlipCopy(TUint32* aTarget, const TUint8* aSource, TInt aBytes, TInt aLineLen, TBool aReversed); + static TUint32 Gray256(const TUint8& aPixel); + static TUint32 Color256(const TUint8& aPixel); + static TUint32 Color4K(const TUint16& aPixel); + static TUint32 Color64K(const TUint16& aPixel); + static TUint32 Color16M(const TUint32& aPixel); + static TUint32 Color16MU(const TUint32& aPixel); + static TUint32 Color16MA(const TUint32& aPixel); private: typedef TUint32 (*TRgbFunc) (const T& aValue); TRgbFunc iFunc; - }; - - -template +}; + + + template void* TRgbCopy::operator new(TUint /*aBytes*/, TAny* aMem) - { +{ return aMem; - } - -template +} + + template TRgbCopy::TRgbCopy(TDisplayMode aMode) - { +{ switch(aMode) - { + { case EGray256 : iFunc = (TRgbFunc) Gray256; break; case EColor256 : iFunc = (TRgbFunc) Color256; break; case EColor4K : iFunc = (TRgbFunc) Color4K; break; @@ -1629,157 +1430,155 @@ TRgbCopy::TRgbCopy(TDisplayMode aMode) case EColor16MU : iFunc = (TRgbFunc) Color16MU; break; case EColor16MA : iFunc = (TRgbFunc) Color16MA; break; default: - PANIC(KErrNotSupported); - } + PANIC(KErrNotSupported); } - -template +} + + template void TRgbCopy::Copy(TUint32* aTarget, const TUint8* aSource, TInt aBytes, TBool aReversed) - { +{ const T* source = reinterpret_cast(aSource); TUint32* target = aTarget; TUint32* endt = target + aBytes; - + if(aReversed) - { + { while(target < endt) - { + { const T value = *source++; - *(--endt) = iFunc(value);//iFunc(value).Value(); - } + *(--endt) = iFunc(value); } + } else - { + { while(target < endt) - { + { const T value = *source++; - *target++ = iFunc(value);//iFunc(value).Value(); - } + *target++ = iFunc(value); } } - -template +} + + template void TRgbCopy::FlipCopy(TUint32* aTarget, const TUint8* aSource, TInt aBytes, TInt aLineLen, TBool aReversed) - { +{ const T* column = reinterpret_cast(aSource); TUint32* target = aTarget; TUint32* endt = target + aBytes; - + if(aReversed) - { + { while(target < endt) - { + { *(--endt) = iFunc(*column); column += aLineLen; - } } + } else - { + { while(target < endt) - { + { *target++ = iFunc(*column); column += aLineLen; - } } - } - + } +} + template TUint32 TRgbCopy::Gray256(const TUint8& aPixel) - { +{ const TUint32 px = aPixel << 16 | aPixel << 8 | aPixel; return px; - } - +} + template TUint32 TRgbCopy::Color256(const TUint8& aPixel) - { +{ return TRgb::Color256(aPixel).Value(); - } - +} + template TUint32 TRgbCopy::Color4K(const TUint16& aPixel) - { +{ TUint32 col = (aPixel & 0xF00) << 12; col |= (aPixel & 0xF00) << 8; - + col |= (aPixel & 0x0F0) << 8; col |= (aPixel & 0x0F0); - + col |= (aPixel & 0x00F) << 4; col |= (aPixel & 0x00F); - + return col; - } - +} + template TUint32 TRgbCopy::Color64K(const TUint16& aPixel) - { +{ TUint32 col = (aPixel & 0xF800)<< 8; col |= (aPixel & 0xE000) << 3; - + col |= (aPixel & 0x07E0) << 5; col |= (aPixel & 0xC0) >> 1; - + col |= (aPixel & 0x07E0) << 3; col |= (aPixel & 0x1C) >> 2; - + return col; - } - +} + template TUint32 TRgbCopy::Color16M(const TUint32& aPixel) - { +{ return TRgb::Color16M(aPixel).Value(); - } - +} + template TUint32 TRgbCopy::Color16MU(const TUint32& aPixel) - { +{ return TRgb::Color16MU(aPixel).Value(); - } - +} + template TUint32 TRgbCopy::Color16MA(const TUint32& aPixel) - { +{ return TRgb::Color16MA(aPixel).Value(); - } +} typedef TUint64 TStackMem; LOCAL_C MRgbCopy* GetCopy(TAny* mem, TDisplayMode aMode) - { +{ if(aMode == EColor256 || aMode == EGray256) - { + { return new (mem) TRgbCopy(aMode); - } + } if(aMode == EColor4K || aMode == EColor64K) - { + { return new (mem) TRgbCopy(aMode); - } + } if(aMode == EColor16M || aMode == EColor16MU || aMode == EColor16MA) - { + { return new (mem) TRgbCopy(aMode); - } + } PANIC(KErrNotSupported); return NULL; - } - +} + void CDsa::CopySlowFlipReversed(const CDsa& aDsa, TUint32* aTarget, const TUint8* aSource, TInt aBytes, TInt aLineLen) - { +{ TStackMem mem = 0; GetCopy(&mem, aDsa.iSourceMode)->FlipCopy(aTarget, aSource, aBytes, aLineLen, ETrue); - } - +} + void CDsa::CopySlowFlip(const CDsa& aDsa, TUint32* aTarget, const TUint8* aSource, TInt aBytes, TInt aLineLen) - { +{ TStackMem mem = 0; GetCopy(&mem, aDsa.iSourceMode)->FlipCopy(aTarget, aSource, aBytes, aLineLen, EFalse); - } - +} + void CDsa::CopySlow(const CDsa& aDsa, TUint32* aTarget, const TUint8* aSource, TInt aBytes, TInt) - { +{ TStackMem mem = 0; GetCopy(&mem, aDsa.iSourceMode)->Copy(aTarget, aSource, aBytes, EFalse); - } +} void CDsa::CopySlowReversed(const CDsa& aDsa, TUint32* aTarget, const TUint8* aSource, TInt aBytes, TInt) - { +{ TStackMem mem = 0; GetCopy(&mem, aDsa.iSourceMode)->Copy(aTarget, aSource, aBytes, ETrue); - } - -////////////////////////////////////////////////////////////////////////////////////////////////////////////////7 +} -- 2.11.4.GIT