|
1 // Copyright (c) 1997-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". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // |
|
15 |
|
16 #include <hal.h> |
|
17 #include "_WININC.H" |
|
18 #include <bitdrawinterfaceid.h> |
|
19 |
|
20 #if defined(SYMBIAN_GRAPHICS_GCE) |
|
21 #include <surface.h> |
|
22 #endif //SYMBIAN_GRAPHICS_GCE |
|
23 |
|
24 template <class T> CScreenDevice<T>::~CScreenDevice() |
|
25 { |
|
26 iUpdateRegion.Close(); |
|
27 iWindowInUse.Close(); |
|
28 RWindows::ReleaseWindow(iScreenNo); |
|
29 } |
|
30 |
|
31 /** |
|
32 Constructs the CScreenDevice<T> object. |
|
33 @param aScreenNo Screen number. It will be used in HAL::Get() calls. |
|
34 @param aHwnd Windows OS - window handle. |
|
35 @param aSize Screen size |
|
36 @return System-wide error codes, KErrNone if the construction was successfull. |
|
37 */ |
|
38 template <class T> TInt CScreenDevice<T>::ConstructScreen(TInt aScreenNo, TAny* aHwnd,const TSize& aSize) |
|
39 { |
|
40 iScreenNo = aScreenNo; |
|
41 TInt ret = Construct(aSize); |
|
42 if (ret != KErrNone) |
|
43 return ret; |
|
44 |
|
45 if (aSize.iWidth < aSize.iHeight) |
|
46 { |
|
47 TInt bpp = BitsPerPixel(iDispMode); |
|
48 delete[] iScanLineBuffer; |
|
49 TInt scanLineWords = ((iSize.iHeight * bpp) + 31) / 32; |
|
50 iScanLineBuffer = (TUint32*)(User::Heap().Alloc(scanLineWords * 4)); |
|
51 if (!iScanLineBuffer) |
|
52 return KErrNoMemory; |
|
53 } |
|
54 |
|
55 iWindow = RWindows::GetWindow(iScreenNo, aHwnd,aSize); |
|
56 if (iWindow == NULL) |
|
57 return KErrNoMemory; |
|
58 |
|
59 SetBits(iWindow->EpocBitmapBits()); |
|
60 //Some explanations about iWindowInUse semaphore. |
|
61 //On the Emulator, a single Windows OS window can be shared between many Symbian OS |
|
62 //screen devices. iWindowInUse semaphore is used to help to determine the moment, |
|
63 //when the related Windows OS window can be destroyed safely. Because it is a named |
|
64 //semaphore, it will be created once by the first client (Symbian OS screen device) |
|
65 //and opened (reference counted) by the every next client (Symbian OS screen device). |
|
66 //In the CScreenDevice<T>'s deastructor iWindowInUse semaphore will be closed |
|
67 //(its reference counter gets decremented). When its value reaches zero, the Symbian OS |
|
68 //will destroy the semaphore. This action will be detected by the RWindows::ReleaseWindow()'s |
|
69 //implementation and the related Windows OS window will be destroyed. |
|
70 TBuf<32> screenSemaphoreName; |
|
71 ::CreateScreenSemaphoreName(iScreenNo, screenSemaphoreName); |
|
72 ret = iWindowInUse.CreateGlobal(screenSemaphoreName,0,EOwnerThread); |
|
73 if (ret == KErrAlreadyExists) |
|
74 { |
|
75 iWindowInUse.OpenGlobal(screenSemaphoreName,EOwnerThread); |
|
76 } |
|
77 return KErrNone; |
|
78 } |
|
79 |
|
80 template <class T> TInt CScreenDevice<T>::HorzTwipsPerThousandPixels() const |
|
81 { |
|
82 if (iSize.iWidth==0) |
|
83 return(0); |
|
84 TInt twips = 0; |
|
85 HAL::Get(iScreenNo, HALData::EDisplayXTwips,twips); |
|
86 return twips * 1000 / iSize.iWidth; |
|
87 } |
|
88 |
|
89 template <class T> TInt CScreenDevice<T>::VertTwipsPerThousandPixels() const |
|
90 { |
|
91 if (iSize.iHeight==0) |
|
92 return(0); |
|
93 TInt twips = 0; |
|
94 HAL::Get(iScreenNo, HALData::EDisplayYTwips,twips); |
|
95 return twips * 1000 / iSize.iHeight; |
|
96 } |
|
97 |
|
98 template <class T> void CScreenDevice<T>::OrientationsAvailable(TBool aOrientation[4]) |
|
99 { |
|
100 aOrientation[EOrientationNormal] = ETrue; |
|
101 aOrientation[EOrientationRotated90] = ETrue; |
|
102 aOrientation[EOrientationRotated180] = ETrue; |
|
103 aOrientation[EOrientationRotated270] = ETrue; |
|
104 } |
|
105 |
|
106 template <class T> void CScreenDevice<T>::SetDisplayMode(CFbsDrawDevice* aDrawDevice) |
|
107 { |
|
108 iUpdateRegion.Clear(); |
|
109 SetOrientation(static_cast<CFbsDrawDevice::TOrientation>(iWindow->Orientation())); |
|
110 CopyOldSettings(aDrawDevice); |
|
111 InitScreen(); |
|
112 } |
|
113 |
|
114 template <class T> void CScreenDevice<T>::SetAutoUpdate(TBool aAutoUpdate) |
|
115 { |
|
116 iAutoUpdate = aAutoUpdate; |
|
117 } |
|
118 |
|
119 template <class T> void CScreenDevice<T>::SetScreenOrientation(TInt aOrientation) |
|
120 { |
|
121 Update(); |
|
122 |
|
123 TEmulatorFlip flip = EEmulatorFlipRestore; |
|
124 switch (aOrientation) |
|
125 { |
|
126 case 0: // Already set |
|
127 break; |
|
128 case 1: |
|
129 flip = EEmulatorFlipLeft; |
|
130 break; |
|
131 case 2: |
|
132 flip = EEmulatorFlipInvert; |
|
133 break; |
|
134 case 3: |
|
135 flip = EEmulatorFlipRight; |
|
136 break; |
|
137 default: |
|
138 ASSERT(0); |
|
139 break; |
|
140 } |
|
141 EmulatorFlip(flip, iScreenNo); |
|
142 iWindow->SetOrientation(aOrientation); |
|
143 } |
|
144 |
|
145 // |
|
146 // Update the screen with the update region. |
|
147 // |
|
148 template <class T> void CScreenDevice<T>::Update() |
|
149 { |
|
150 if (iUpdateRegion.IsEmpty()) |
|
151 return; |
|
152 UpdateScreen(iUpdateRegion); |
|
153 iUpdateRegion.Clear(); |
|
154 } |
|
155 |
|
156 // |
|
157 // Update the screen with the union of the update and specified regions. |
|
158 // aRegion - logical coordinates |
|
159 template <class T> void CScreenDevice<T>::Update(const TRegion& aRegion) |
|
160 { |
|
161 if(!aRegion.IsEmpty() && !aRegion.CheckError()) |
|
162 { |
|
163 if(iScalingOff && iOriginIsZero) |
|
164 { |
|
165 iUpdateRegion.Union(aRegion); |
|
166 } |
|
167 else |
|
168 { |
|
169 register TInt rcCnt = aRegion.Count(); |
|
170 RRegion physRegion(rcCnt); |
|
171 register TInt originX = iOrigin.iX; |
|
172 register TInt originY = iOrigin.iY; |
|
173 register TInt factorX = iScalingSettings.iFactorX; |
|
174 register TInt factorY = iScalingSettings.iFactorY; |
|
175 for(register TInt i=0;i<rcCnt;++i) |
|
176 { |
|
177 const TRect& logRect = aRegion[i]; |
|
178 TRect physRect; |
|
179 physRect.iTl.iX = ::Log2Phys(logRect.iTl.iX, originX, factorX, iSize.iWidth); |
|
180 physRect.iTl.iY = ::Log2Phys(logRect.iTl.iY, originY, factorY, iSize.iHeight); |
|
181 physRect.iBr.iX = ::RBtmLog2Phys(logRect.iBr.iX, originX, factorX, iSize.iWidth); |
|
182 physRect.iBr.iY = ::RBtmLog2Phys(logRect.iBr.iY, originY, factorY, iSize.iHeight); |
|
183 //The next statement sometimes have to allocate a block of memory and may |
|
184 //fail setting RRegion's internal error flag. But there is nothing we can do. |
|
185 physRegion.AddRect(physRect); |
|
186 } |
|
187 iUpdateRegion.Union(physRegion); |
|
188 physRegion.Close(); |
|
189 } |
|
190 } |
|
191 Update(); |
|
192 } |
|
193 |
|
194 // |
|
195 // Update the update region. |
|
196 // aRect - logical coordinates |
|
197 template <class T> void CScreenDevice<T>::UpdateRegion(const TRect& aRect) |
|
198 { |
|
199 register TInt originX = iOrigin.iX; |
|
200 register TInt originY = iOrigin.iY; |
|
201 register TInt factorX = iScalingSettings.iFactorX; |
|
202 register TInt factorY = iScalingSettings.iFactorY; |
|
203 TRect physRect; |
|
204 physRect.iTl.iX = ::Log2Phys(aRect.iTl.iX, originX, factorX, iSize.iWidth); |
|
205 physRect.iTl.iY = ::Log2Phys(aRect.iTl.iY, originY, factorY, iSize.iHeight); |
|
206 physRect.iBr.iX = ::RBtmLog2Phys(aRect.iBr.iX, originX, factorX, iSize.iWidth); |
|
207 physRect.iBr.iY = ::RBtmLog2Phys(aRect.iBr.iY, originY, factorY, iSize.iHeight); |
|
208 physRect.Normalize(); |
|
209 iUpdateRegion.AddRect(physRect); |
|
210 if(iUpdateRegion.Count() >= 10) |
|
211 { |
|
212 iUpdateRegion.AddRect(iUpdateRegion.BoundingRect()); |
|
213 } |
|
214 if(iAutoUpdate) |
|
215 { |
|
216 Update(); |
|
217 } |
|
218 } |
|
219 |
|
220 template <class T> void CScreenDevice<T>::UpdateScreen(const TRegion& aRegion) |
|
221 { |
|
222 if (aRegion.CheckError()) |
|
223 UpdateRect(iSize); |
|
224 else |
|
225 for(TInt count = 0; count < aRegion.Count(); count++) |
|
226 UpdateRect(aRegion[count]); |
|
227 |
|
228 iWindow->Update(aRegion,iSize); |
|
229 } |
|
230 |
|
231 template <class T> TUint8* CScreenDevice<T>::WinPixelAddress(TInt aX,TInt aY) const |
|
232 { |
|
233 return iWindow->PixelAddress(aX,aY); |
|
234 } |
|
235 |