|
1 // Copyright (c) 2010 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 |
|
17 /** |
|
18 @file |
|
19 @publishedPartner |
|
20 @prototype |
|
21 */ |
|
22 |
|
23 |
|
24 #include "eglwindow.h" |
|
25 #include <e32base.h> |
|
26 #include <w32std.h> |
|
27 |
|
28 |
|
29 //REglWindowBase----------------------------------------------------- |
|
30 |
|
31 REglWindowBase::REglWindowBase() : |
|
32 iIsRWindow(0xFFFFFFFF) |
|
33 { |
|
34 //Check that BC is not broken between RWindow and REglWindowBase. |
|
35 __ASSERT_COMPILE(sizeof(MWsClientClass) == sizeof(REglWindowBase)); |
|
36 } |
|
37 |
|
38 |
|
39 TBool REglWindowBase::IsRWindow() const |
|
40 { |
|
41 //REglWindowBase works out whether it is really an RWindow or a class |
|
42 //derived from REglWindowBase by checking the location where iWsBuffer |
|
43 //would be in an RWindow (iIsRWindow in this class). If this is |
|
44 //0xFFFFFFFF, it is not an RWindow. |
|
45 return (iIsRWindow != 0xFFFFFFFF); |
|
46 } |
|
47 |
|
48 //------------------------------------------------------------------- |
|
49 |
|
50 |
|
51 //Static function used to copy one configuration to another. |
|
52 static void CopySurfaceConfiguration(const TSurfaceConfiguration& aSrc, TSurfaceConfiguration& aDest) |
|
53 { |
|
54 TRect extent; |
|
55 TRect viewport; |
|
56 TSurfaceId surface; |
|
57 aSrc.GetExtent(extent); |
|
58 aDest.SetExtent(extent); |
|
59 aSrc.GetSurfaceId(surface); |
|
60 aDest.SetSurfaceId(surface); |
|
61 aSrc.GetViewport(viewport); |
|
62 aDest.SetViewport(viewport); |
|
63 aDest.SetFlip(aSrc.Flip()); |
|
64 aDest.SetOrientation(aSrc.Orientation()); |
|
65 } |
|
66 |
|
67 |
|
68 //REglStandAloneWindow----------------------------------------------- |
|
69 |
|
70 //Class used to hold surface window data to prevent the |
|
71 //possibility of binary break if TSurfaceConfiguration grows. |
|
72 NONSHARABLE_CLASS(REglStandAloneWindow::TEglStandAloneWindowData) |
|
73 { |
|
74 public: |
|
75 TEglStandAloneWindowData(const TSize& aSizeInPixels, const TSize& aSizeInTwips, TInt aScreenNumber, MEglStandAloneWindowObserver& aObserver); |
|
76 MEglStandAloneWindowObserver& iObserver; |
|
77 TSize iSizeInPixels; |
|
78 TSize iSizeInTwips; |
|
79 TInt iScreenNumber; |
|
80 TRgb iBackgroundColor; |
|
81 TSurfaceConfiguration iSurfaceConfig; |
|
82 }; |
|
83 |
|
84 |
|
85 REglStandAloneWindow::TEglStandAloneWindowData::TEglStandAloneWindowData(const TSize& aSizeInPixels, const TSize& aSizeInTwips, TInt aScreenNumber, MEglStandAloneWindowObserver& aObserver) : |
|
86 iObserver(aObserver), |
|
87 iSizeInPixels(aSizeInPixels), |
|
88 iSizeInTwips(aSizeInTwips), |
|
89 iScreenNumber(aScreenNumber), |
|
90 iBackgroundColor(0,0,0,0) //Transparent Black. |
|
91 { |
|
92 CopySurfaceConfiguration(TSurfaceConfiguration(), iSurfaceConfig); |
|
93 } |
|
94 |
|
95 |
|
96 EXPORT_C REglStandAloneWindow::REglStandAloneWindow() : |
|
97 iData(NULL) |
|
98 { |
|
99 } |
|
100 |
|
101 |
|
102 EXPORT_C TInt REglStandAloneWindow::Create(const TSize& aSizeInPixels, const TSize& aSizeInTwips, TInt aScreenNumber, MEglStandAloneWindowObserver& aObserver) |
|
103 { |
|
104 if(iData) |
|
105 { |
|
106 return KErrAlreadyExists; |
|
107 } |
|
108 |
|
109 EGL_WINDOW_ASSERT_DEBUG(aSizeInPixels.iWidth >= 0, EEglWindowPanicSizeInPixelsIsNegative); |
|
110 EGL_WINDOW_ASSERT_DEBUG(aSizeInPixels.iHeight >= 0, EEglWindowPanicSizeInPixelsIsNegative); |
|
111 EGL_WINDOW_ASSERT_DEBUG(aSizeInTwips.iWidth >= 0, EEglWindowPanicSizeInTwipsIsNegative); |
|
112 EGL_WINDOW_ASSERT_DEBUG(aSizeInTwips.iHeight >= 0, EEglWindowPanicSizeInTwipsIsNegative); |
|
113 EGL_WINDOW_ASSERT_DEBUG(aScreenNumber >= 0 || aScreenNumber == KAllScreens, EEglWindowPanicInvalidScreenNumber); |
|
114 |
|
115 //Allocate and initialize data. |
|
116 iData = new TEglStandAloneWindowData(aSizeInPixels, aSizeInTwips, aScreenNumber, aObserver); |
|
117 if(!iData) |
|
118 { |
|
119 return KErrNoMemory; |
|
120 } |
|
121 |
|
122 return KErrNone; |
|
123 } |
|
124 |
|
125 |
|
126 EXPORT_C void REglStandAloneWindow::Close() |
|
127 { |
|
128 if(!iData) |
|
129 { |
|
130 return; |
|
131 } |
|
132 |
|
133 //Remove background surface with a forced redraw so that |
|
134 //the contents immediately disappear from the screen. |
|
135 RemoveBackgroundSurface(ETrue); |
|
136 delete iData; |
|
137 iData = NULL; |
|
138 } |
|
139 |
|
140 |
|
141 EXPORT_C void REglStandAloneWindow::SetSizeInPixels(const TSize& aSize) |
|
142 { |
|
143 EGL_WINDOW_ASSERT_ALWAYS(iData, EEglWindowPanicREglStandAloneWindowNotCreated); |
|
144 EGL_WINDOW_ASSERT_DEBUG(aSize.iWidth >= 0, EEglWindowPanicSizeInPixelsIsNegative); |
|
145 EGL_WINDOW_ASSERT_DEBUG(aSize.iHeight >= 0, EEglWindowPanicSizeInPixelsIsNegative); |
|
146 iData->iSizeInPixels = aSize; |
|
147 } |
|
148 |
|
149 |
|
150 EXPORT_C void REglStandAloneWindow::SetSizeInTwips(const TSize& aSize) |
|
151 { |
|
152 EGL_WINDOW_ASSERT_ALWAYS(iData, EEglWindowPanicREglStandAloneWindowNotCreated); |
|
153 EGL_WINDOW_ASSERT_DEBUG(aSize.iWidth >= 0, EEglWindowPanicSizeInTwipsIsNegative); |
|
154 EGL_WINDOW_ASSERT_DEBUG(aSize.iHeight >= 0, EEglWindowPanicSizeInTwipsIsNegative); |
|
155 iData->iSizeInTwips = aSize; |
|
156 } |
|
157 |
|
158 |
|
159 EXPORT_C TRgb REglStandAloneWindow::BackgroundColor() const |
|
160 { |
|
161 EGL_WINDOW_ASSERT_ALWAYS(iData, EEglWindowPanicREglStandAloneWindowNotCreated); |
|
162 return iData->iBackgroundColor; |
|
163 } |
|
164 |
|
165 |
|
166 EXPORT_C TBool REglStandAloneWindow::GetBackgroundSurface(TSurfaceConfiguration& aConfiguration) const |
|
167 { |
|
168 EGL_WINDOW_ASSERT_ALWAYS(iData, EEglWindowPanicREglStandAloneWindowNotCreated); |
|
169 |
|
170 TSurfaceId surface; |
|
171 iData->iSurfaceConfig.GetSurfaceId(surface); |
|
172 if(surface.IsNull()) |
|
173 { |
|
174 return EFalse; |
|
175 } |
|
176 |
|
177 CopySurfaceConfiguration(iData->iSurfaceConfig, aConfiguration); |
|
178 return ETrue; |
|
179 } |
|
180 |
|
181 |
|
182 EXPORT_C TBool REglStandAloneWindow::IsValid() const |
|
183 { |
|
184 return iData != NULL; |
|
185 } |
|
186 |
|
187 |
|
188 EXPORT_C TSize REglStandAloneWindow::SizeInPixels() const |
|
189 { |
|
190 EGL_WINDOW_ASSERT_ALWAYS(iData, EEglWindowPanicREglStandAloneWindowNotCreated); |
|
191 return iData->iSizeInPixels; |
|
192 } |
|
193 |
|
194 |
|
195 EXPORT_C TSize REglStandAloneWindow::SizeInTwips() const |
|
196 { |
|
197 EGL_WINDOW_ASSERT_ALWAYS(iData, EEglWindowPanicREglStandAloneWindowNotCreated); |
|
198 return iData->iSizeInTwips; |
|
199 } |
|
200 |
|
201 |
|
202 EXPORT_C TInt REglStandAloneWindow::ScreenNumber() const |
|
203 { |
|
204 EGL_WINDOW_ASSERT_ALWAYS(iData, EEglWindowPanicREglStandAloneWindowNotCreated); |
|
205 return iData->iScreenNumber; |
|
206 } |
|
207 |
|
208 |
|
209 EXPORT_C void REglStandAloneWindow::SetBackgroundColor(TRgb aColor, TBool aTriggerRedraw) |
|
210 { |
|
211 EGL_WINDOW_ASSERT_ALWAYS(iData, EEglWindowPanicREglStandAloneWindowNotCreated); |
|
212 iData->iBackgroundColor = aColor; |
|
213 iData->iObserver.ColorWasSetForWindow(*this, aTriggerRedraw); |
|
214 } |
|
215 |
|
216 |
|
217 EXPORT_C TInt REglStandAloneWindow::SetBackgroundSurface(const TSurfaceConfiguration& aConfiguration, TBool aTriggerRedraw) |
|
218 { |
|
219 EGL_WINDOW_ASSERT_ALWAYS(iData, EEglWindowPanicREglStandAloneWindowNotCreated); |
|
220 |
|
221 #ifdef _DEBUG |
|
222 //Assert that the surface is not null. |
|
223 TSurfaceId surface; |
|
224 aConfiguration.GetSurfaceId(surface); |
|
225 EGL_WINDOW_ASSERT_DEBUG(!surface.IsNull(), EEglWindowPanicInvalidSurface); |
|
226 #endif |
|
227 |
|
228 //Remove the old surface if one exists. |
|
229 RemoveBackgroundSurface(EFalse); |
|
230 |
|
231 //Save the new configuration and alert the observer that a new surface was set. |
|
232 TInt err = KErrNone; |
|
233 CopySurfaceConfiguration(aConfiguration, iData->iSurfaceConfig); |
|
234 err = iData->iObserver.SurfaceWasSetForWindow(*this, aTriggerRedraw); |
|
235 |
|
236 return err; |
|
237 } |
|
238 |
|
239 |
|
240 EXPORT_C void REglStandAloneWindow::RemoveBackgroundSurface(TBool aTriggerRedraw) |
|
241 { |
|
242 EGL_WINDOW_ASSERT_ALWAYS(iData, EEglWindowPanicREglStandAloneWindowNotCreated); |
|
243 |
|
244 //If there is a valid config, alert the observer that it will be removed. |
|
245 TSurfaceId surface; |
|
246 iData->iSurfaceConfig.GetSurfaceId(surface); |
|
247 if(!surface.IsNull()) |
|
248 { |
|
249 iData->iObserver.SurfaceWillBeRemovedForWindow(*this, aTriggerRedraw); |
|
250 } |
|
251 |
|
252 //Zero the configuration. |
|
253 CopySurfaceConfiguration(TSurfaceConfiguration(), iData->iSurfaceConfig); |
|
254 } |
|
255 |
|
256 //------------------------------------------------------------------- |