From 1a7f0b08ca94631e934dbf66efaf7200ad77ba6c Mon Sep 17 00:00:00 2001 From: Bartosz Taudul Date: Sat, 26 Jul 2008 23:51:54 +0200 Subject: [PATCH] Add manual orientation switching support. Manual support for orientation switching added, by comparing the required screen resolution to phone's display resolution in portrait and landscape orientations. It doesn't work correctly right now, but it's step in good direction. --- src/main/symbian/SDL_main.cpp | 26 +++++++++++++++++++++++--- src/video/symbian/SDL_epocvideo.cpp | 22 +++++++++++++++++----- symbian/include/internal/epoc_sdl.h | 23 +++++++---------------- 3 files changed, 47 insertions(+), 24 deletions(-) diff --git a/src/main/symbian/SDL_main.cpp b/src/main/symbian/SDL_main.cpp index f59ebbb..96f7298 100644 --- a/src/main/symbian/SDL_main.cpp +++ b/src/main/symbian/SDL_main.cpp @@ -40,6 +40,10 @@ NONSHARABLE_CLASS(EpocSdlEnvData) CArrayFix* iCleanupItems; CSDL* iSdl; TRequestStatus* iCallerStatus; + bool iWaitingForOrientationChange; + + TSize iSize; + TDisplayMode iMode; }; EpocSdlEnvData* gEpocEnv; @@ -829,6 +833,15 @@ bool EpocSdlEnv::GetUpdateWholeScreen() return gEpocEnv->iDsa->m_updateWholeScreen; } +void EpocSdlEnv::SetOrientation(CAknAppUi::TAppUiOrientation orientation, const TSize& aSize, TDisplayMode aMode) +{ + gEpocEnv->iWaitingForOrientationChange = true; + gEpocEnv->iSize = aSize; + gEpocEnv->iMode = aMode; + + TRAPD(err, static_cast(CEikonEnv::Static()->EikAppUi())->SetOrientationL(orientation)); +} + EXPORT_C TThreadId CSDL::CallMainL(const TMainFunc& aFunc, TRequestStatus* const aStatus, const CDesC8Array* const aArg, int aStackSize) { ASSERT(gEpocEnv != NULL); @@ -953,9 +966,16 @@ EXPORT_C void CSDL::Suspend() EXPORT_C void CSDL::Resize() { - TSize size = gEpocEnv->iDsa->Window()->Size(); - - SDL_PrivateResize(size.iWidth, size.iHeight); + if(gEpocEnv->iWaitingForOrientationChange) + { + EpocSdlEnv::AllocSurface(gEpocEnv->iSize, gEpocEnv->iMode); + gEpocEnv->iWaitingForOrientationChange = false; + } + else + { + TSize size = gEpocEnv->iDsa->Window()->Size(); + SDL_PrivateResize(size.iWidth, size.iHeight); + } } EXPORT_C CSDL::CSDL() diff --git a/src/video/symbian/SDL_epocvideo.cpp b/src/video/symbian/SDL_epocvideo.cpp index 4961c3e..bee4ca4 100644 --- a/src/video/symbian/SDL_epocvideo.cpp +++ b/src/video/symbian/SDL_epocvideo.cpp @@ -568,12 +568,14 @@ SDL_Surface *S60_SetVideoMode(_THIS, SDL_Surface *current, int width, int height const TSize screenSize = EpocSdlEnv::WindowSize(TSize(width, height)); - // check resolution validity + // check orientation and resolution validity bool resValid = false; + Orientation orientation = CAknAppUi::EAppUiOrientationUnspecified; for(int i=0; i<2; i++) { if(width <= Private->iRect[i]->w && height <= Private->iRect[i]->h) { + orientation = Private->iOrientation[i]; resValid = true; break; } @@ -582,9 +584,7 @@ SDL_Surface *S60_SetVideoMode(_THIS, SDL_Surface *current, int width, int height return NULL; if(!SDL_ReallocFormat(current, bpp, 0, 0, 0, 0)) - { return NULL; - } const int numBytesPerPixel = ((bpp-1)>>3) + 1; current->pitch = numBytesPerPixel * width; @@ -609,10 +609,22 @@ SDL_Surface *S60_SetVideoMode(_THIS, SDL_Surface *current, int width, int height current->pixels = new TUint8[surfacesize]; Private->iSwSurface = (TUint8*) current->pixels; - const int err = EpocSdlEnv::AllocSurface(TSize(width, height), GetDisplayMode(current->format->BitsPerPixel)); - if(err != KErrNone || current->pixels == NULL) + if(current->pixels == NULL) return NULL; + const TSize sz = EpocSdlEnv::WindowSize(); + if((sz.iWidth < sz.iHeight && orientation != CAknAppUi::EAppUiOrientationPortrait) || + (sz.iWidth > sz.iHeight && orientation != CAknAppUi::EAppUiOrientationLandscape)) + { + EpocSdlEnv::SetOrientation(orientation, TSize(width, height), GetDisplayMode(current->format->BitsPerPixel)); + } + else + { + const int err = EpocSdlEnv::AllocSurface(TSize(width, height), GetDisplayMode(current->format->BitsPerPixel)); + if(err != KErrNone) + return NULL; + } + // Set the blit function _this->UpdateRects = S60_DirectUpdate; diff --git a/symbian/include/internal/epoc_sdl.h b/symbian/include/internal/epoc_sdl.h index a4c0f6e..bbb74c6 100644 --- a/symbian/include/internal/epoc_sdl.h +++ b/symbian/include/internal/epoc_sdl.h @@ -1,13 +1,12 @@ #ifndef EPOCSDL_H #define EPOCSDL_H - -#include - -#include -#include -#include -#include"SDL_config_symbian.h" +#include +#include +#include +#include +#include +#include "SDL_config_symbian.h" @@ -34,7 +33,6 @@ extern "C" TInt Panic(TInt aErr, TInt aLine); - NONSHARABLE_CLASS(MEventQueue) { public: @@ -47,9 +45,6 @@ NONSHARABLE_CLASS(MEventQueue) virtual void Unlock() = 0; }; - -//class CEikonEnv; - typedef void (*TSdlCleanupOperation) (TAny* aThis); NONSHARABLE_CLASS(TSdlCleanupItem) @@ -61,7 +56,6 @@ NONSHARABLE_CLASS(TSdlCleanupItem) TThreadId iThread; }; - NONSHARABLE_CLASS(EpocSdlEnv) { public: @@ -76,7 +70,6 @@ NONSHARABLE_CLASS(EpocSdlEnv) static TInt Argc(); static char** Argv(); static TBool IsDsaAvailable(); - // static void Dsa(const TPoint& aPoint, const CFbsBitmap& aBmp); static TInt AllocSurface(const TSize& aSize, TDisplayMode aMode); static void UnlockHwSurface(); static TUint8* LockHwSurface(); @@ -101,9 +94,7 @@ NONSHARABLE_CLASS(EpocSdlEnv) static RWindow* Window(); static void UpdateWholeScreen(bool val); static bool GetUpdateWholeScreen(); - // static TInt SetVolume(TInt aVolume); - // static TInt Volume(); - // static TInt MaxVolume(); + static void SetOrientation(CAknAppUi::TAppUiOrientation orientation, const TSize& aSize, TDisplayMode aMode); }; #endif -- 2.11.4.GIT