📄 sdl_main.cpp
字号:
TSize EpocSdlEnv::WindowSize(const TSize& aRequestedSize) { __ASSERT_DEBUG(gEpocEnv != NULL, PANIC(KErrNotReady)); if(EpocSdlEnv::Flags(CSDL::EAllowImageResize) && gEpocEnv->iDsa->WindowSize() != aRequestedSize) { TRAP_IGNORE(gEpocEnv->iDsa->CreateZoomerL(aRequestedSize)); } return gEpocEnv->iDsa->WindowSize(); } TSize EpocSdlEnv::WindowSize() { __ASSERT_DEBUG(gEpocEnv != NULL, PANIC(KErrNotReady)); return gEpocEnv->iDsa->WindowSize(); } TDisplayMode EpocSdlEnv::DisplayMode() { return gEpocEnv->iDsa->DisplayMode(); } TPointerCursorMode EpocSdlEnv::PointerMode() { return static_cast<TPointerCursorMode> (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); 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->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<TInt>(&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) { iDsa->Free(); return; } __ASSERT_ALWAYS(iArgv == NULL || CheckSdl(), PANIC(KErrNotReady)); for(TInt i = 0; i < iArgc; i++) User::Free( iArgv[i] ); User::Free(iArgv); delete iEventQueue; if(iDsa != NULL) iDsa->Free(); delete iDsa; delete iAppSrv; }_LIT(KSDLMain, "SDLMain");LOCAL_C int MainL() { gEpocEnv->iCleanupItems = new (ELeave) CArrayFixFlat<TSdlCleanupItem>(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*/) { CTrapCleanup* cleanup = CTrapCleanup::New(); TBool fbsconnected = EFalse; if(RFbsSession::GetSession() == NULL) { PANIC_IF_ERROR(RFbsSession::Connect()); fbsconnected = ETrue; } gEpocEnv->iAppSrv->Init(); #ifdef SYMBIANC // Create stdlib _REENT;#endif // Call stdlib main int ret = 0; //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 #ifdef SYMBIANC _cleanup(); //this is normally called at exit, I call it here#endif if(fbsconnected) RFbsSession::Disconnect(); #ifdef SYMBIANC CloseSTDLIB();#endif // delete as; delete cleanup; return err == KErrNone ? ret : err;; } EXPORT_C CSDL::~CSDL() { gEpocEnv->Free(); User::Free(gEpocEnv); gEpocEnv->iSdl = 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 = CEventQueue::NewL(); gEpocEnv->iAppSrv = new (ELeave) CSdlAppServ(); gEpocEnv->iAppSrv->ConstructL(); 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); } 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; gEpocEnv->iArgc = aArg->Count() + 1; gEpocEnv->iArgv = (char**) User::AllocL(sizeof(char*) * (gEpocEnv->iArgc + 1)); 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[gEpocEnv->iArgc] = NULL; 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(); 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) { gEpocEnv->iDsa->SetOrientation(aMode); } EXPORT_C TInt CSDL::SetSDLCode(TInt aScanCode, TInt aSDLCode) { const TInt current = GetSDLCode(aScanCode); if(aScanCode >= 0 && aScanCode < MAX_SCANCODE) KeyMap()[aScanCode] = static_cast<SDLKey>(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() { 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) { return gEpocEnv->iDsa->RedrawRequest(); } 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; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -