Update contrib.
1 // Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies).
2 // All rights reserved.
3 // This component and the accompanying materials are made available
4 // under the terms of "Eclipse Public License v1.0"
5 // which accompanies this distribution, and is available
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
16 #include "offscreenbitmap.h"
23 #if defined(__WINS__) && defined(_DEBUG)
24 #include "../../debuglog/osbwin.h"
27 GLREF_D TDisplayMode ParseDisplayMode(const TDesC& aModeName);
29 CWsOffScreenBitmap* CWsOffScreenBitmap::NewL(CScreen* aScreen)
31 CWsOffScreenBitmap* self=new(ELeave) CWsOffScreenBitmap(aScreen);
32 CleanupStack::PushL(self);
34 CleanupStack::Pop(self);
38 inline CWsOffScreenBitmap::CWsOffScreenBitmap(CScreen* aScreen) :iScreen(aScreen)
41 CWsOffScreenBitmap::~CWsOffScreenBitmap()
46 #if defined(__WINS__) && defined(_DEBUG)
53 LOCAL_C inline void Swap(T& aLeft, T& aRight)
54 { T temp=aLeft;aLeft=aRight;aRight=temp;}
56 LOCAL_C inline TBool SwapIfLeftIsBigger(T& aLeft, T& aRight)
57 {if (aLeft>aRight) { ::Swap(aLeft, aRight); return (aRight>aLeft);} return (aLeft>aRight);}
59 void CWsOffScreenBitmap::ConstructL()
61 _LIT(KFlickerBufferMode,"FLICKERBUFFERMODE");
62 TPtrC flickerBufferModeName;
63 TDisplayMode displayMode = ENone;
64 if (WsIniFile->FindVar(iScreen->ScreenNumber(), KFlickerBufferMode, flickerBufferModeName))
65 displayMode = ParseDisplayMode(flickerBufferModeName);
66 if (displayMode == ENone)
67 displayMode = iScreen->DisplayMode();
69 WS_ASSERT_DEBUG(displayMode!=ENone, EWsPanicNoDisplayModeFound);
70 iBitmap=new(ELeave) CFbsBitmap;
71 TSize screenSize=iScreen->ScreenDevice()->SizeInPixels();
72 TBool haveSwapped=SwapIfLeftIsBigger(screenSize.iWidth, screenSize.iHeight);
73 User::LeaveIfError(iBitmap->Create(screenSize,displayMode));
76 iBitmap->SwapWidthAndHeight();
78 User::LeaveIfError(iBitmap->SetDisplayMode(iScreen->DisplayMode()));
79 iBitmapDevice=CFbsBitmapDevice::NewL(iBitmap);
80 User::LeaveIfError(iBitmapDevice->CreateContext(iBitmapGc));
82 TSizeMode sizeMode = iScreen->ScreenSizeModeData(iScreen->ScreenSizeMode());
83 TSize osbSize(iBitmap->SizeInPixels());
84 TSize osbTwips(sizeMode.iScreenTwipsSize);
85 if (osbSize!=sizeMode.iScreenSize)
87 // The specified screen twips size is for the specified screen pixel size, however the OSB
88 // is potentially larger as it needs to hold the maximum possible screen size, so we need
89 // to scale the twips size up correspondingly.
90 osbTwips.iWidth=sizeMode.iScreenTwipsSize.iWidth*osbSize.iWidth/sizeMode.iScreenSize.iWidth;
91 osbTwips.iHeight=sizeMode.iScreenTwipsSize.iHeight*osbSize.iHeight/sizeMode.iScreenSize.iHeight;
93 iBitmap->SetSizeInTwips(osbTwips);
95 # if defined(__WINS__) && defined(_DEBUG)
96 _LIT(KDebugOsb,"DEBUGOSB");
97 if (WsIniFile->FindVar(iScreen->ScreenNumber(),KDebugOsb))
99 _LIT(KDebugOsbTitleFormat, "Screen %d, offscreen bitmap");
101 title.Format(KDebugOsbTitleFormat, iScreen->ScreenNumber());
102 iOsbWin = CDebugOsbWin::NewL(title, iBitmap->SizeInPixels());
107 TInt CWsOffScreenBitmap::DisplayModeChanged(TBool aSwapWidthAndHeight)
110 if (aSwapWidthAndHeight)
112 err=iBitmapDevice->SwapWidthAndHeight();
113 WS_ASSERT_DEBUG(err==KErrNone, EWsCreatedOffScreenBitmapInWrongDimensions);
114 iBitmapGc->Activate(iBitmapDevice);
119 void CWsOffScreenBitmap::SetObserver(MWsFlickerFreeBufferObserver* aObserver)
121 iObserver = aObserver;
124 MWsFlickerFreeBufferObserver * CWsOffScreenBitmap::Observer()
129 CFbsBitmap* CWsOffScreenBitmap::Bitmap()
131 CFbsBitmap* bmp = iRedirectBuffer? iRedirectBuffer->GetBitmap() : iBitmap;
132 WS_ASSERT_DEBUG(bmp!=NULL, EWsPanicTemp);
136 CFbsDevice* CWsOffScreenBitmap::BitmapDevice()
138 CFbsDevice* device = static_cast<CFbsDevice*>(GetBitGcCurrent()->Device());
139 WS_ASSERT_DEBUG(device!=NULL, EWsPanicNullDeviceHandle);
143 // This function updates the OffScreenBitmap and TransparencyManager's device and GC
144 // Note: Here the OffScreenBitmap's scale is not considered.
145 void CWsOffScreenBitmap::UpdateGc(const TBool aSwapWidthAndHeight)
147 if (aSwapWidthAndHeight)
149 iBitmapDevice->SwapWidthAndHeight();
151 iBitmapDevice->SetScalingFactor(iScreen->CurrentScreenModeScaledOrigin(),1,1,1,1);
152 iBitmapGc->Activate(iBitmapDevice);
155 #if defined(__WINS__) && defined(_DEBUG)
156 void CWsOffScreenBitmap::Update()
161 iOsbWin->Refresh(iBitmap->SizeInPixels(), iBitmap->DisplayMode(), iBitmap->DataAddress());
162 iBitmap->UnlockHeap();
168 Implementing MWsBackBuffer interface
170 CFbsBitmap* CWsOffScreenBitmap::GetBitmap()
175 CFbsBitGc* CWsOffScreenBitmap::GetBitGc()
180 CFbsBitGc* CWsOffScreenBitmap::GetBitGcCurrent()
182 CFbsBitGc* gc = iRedirectGc? iRedirectGc : (iRedirectBuffer? iRedirectBuffer->GetBitGc() : iBitmapGc);
183 WS_ASSERT_DEBUG(gc!=NULL, EWsPanicTemp);
187 TInt CWsOffScreenBitmap::SetBitGc(CFbsBitGc* aBitGc)
192 if (aBitGc && (aBitGc==iBitmapGc || aBitGc==iRedirectGc))
193 return KErrAlreadyExists;
195 if (aBitGc && !aBitGc->Device())
198 iRedirectGc = aBitGc;
202 TInt CWsOffScreenBitmap::RedirectTo(MWsBackBuffer* aTarget)
207 if (aTarget && aTarget==iRedirectBuffer)
208 return KErrAlreadyExists;
210 if ( aTarget && iScreen->HasVisibleDirectOnQueue() )
214 !aTarget->GetBitmap()||
215 !aTarget->GetBitGc() ||
216 (aTarget->GetBitGc() && !aTarget->GetBitGc()->Device())
221 iRedirectBuffer = aTarget;
225 TAny* CWsOffScreenBitmap::ResolveObjectInterface(TUint aTypeId)
229 case MWsBackBuffer::EWsObjectInterfaceId:
230 return static_cast<MWsBackBuffer *>(this);