|
1 /* |
|
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: This class implements MMMADisplayWindow functionality |
|
15 * for Camera viewfinder usage. |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 #ifndef CMMACAMERAWINDOW_H |
|
21 #define CMMACAMERAWINDOW_H |
|
22 |
|
23 // INCLUDES |
|
24 #include <ecam.h> |
|
25 #include <reflcdui.h> |
|
26 #include <w32std.h> |
|
27 #include "mmmadisplaywindow.h" |
|
28 #include "mmmadisplay.h" |
|
29 // CONSTANTS |
|
30 |
|
31 // FORWARD DECLARATIONS |
|
32 class CFbsBitmap; |
|
33 class RWsSession; |
|
34 class CWsScreenDevice; |
|
35 class RWindowBase; |
|
36 class MMMADisplay; |
|
37 |
|
38 // CLASS DECLARATION |
|
39 /** |
|
40 * This class implements MMMADisplayWindow functionality |
|
41 * to use with CMMACameraPlayer. |
|
42 * It duplicates its camera instance within the UI thread |
|
43 * and displays the viewfinder using the UI |
|
44 * DirectScreenAccess resources. |
|
45 * |
|
46 * @since S60 v5.0 |
|
47 */ |
|
48 |
|
49 |
|
50 NONSHARABLE_CLASS(CMMACameraWindow): public CBase, |
|
51 public MMMADisplayWindow, |
|
52 public MCameraObserver2, |
|
53 public MUiEventConsumer, |
|
54 public MDirectScreenAccess |
|
55 { |
|
56 public: |
|
57 enum TUiCallbackType |
|
58 { |
|
59 EDeleteViewFinder = 1, |
|
60 EHideViewFinder, |
|
61 EShowViewFinder, |
|
62 EResetViewFinder, |
|
63 EDestroyWindow |
|
64 }; |
|
65 |
|
66 /** |
|
67 * Two-phased constructor. |
|
68 * |
|
69 * @param aCameraHandle A handle to existing CCamera instance. |
|
70 */ |
|
71 static CMMACameraWindow* NewL(TInt aCameraHandle); |
|
72 |
|
73 |
|
74 /** |
|
75 * Destructor. |
|
76 */ |
|
77 ~CMMACameraWindow(); |
|
78 |
|
79 /** |
|
80 * Gets an information if the DirectViewFinder is started |
|
81 * |
|
82 * @since S60 v5.0 |
|
83 * @return ETrue if DirectViewFinder is active |
|
84 */ |
|
85 TBool ViewFinderActive(); |
|
86 |
|
87 /** |
|
88 * Notifies window about Started state change |
|
89 * |
|
90 * @since S60 v5.0 |
|
91 * @param aStarted Indicates that camera player is in started state |
|
92 */ |
|
93 void SetStarted(TBool aStarted); |
|
94 |
|
95 /** |
|
96 * Sets iDisplay |
|
97 * Used to invoke callbacks in UI thread |
|
98 * |
|
99 * @since S60 v5.0 |
|
100 * @param "aDisplay" A Display to be used for callbacks. |
|
101 * When set, the duplicated CCamera is created in UI thread |
|
102 * and the necessary DSA resources are got. |
|
103 * When replacing an old Display (set earlier) |
|
104 * all the old resources are deleted. |
|
105 * NULL deletes all allocated UI resources. |
|
106 */ |
|
107 void SetDisplay(MMMADisplay *aDisplay); |
|
108 |
|
109 |
|
110 // from base class MMMADisplayWindow |
|
111 void SetDestinationBitmapL(CFbsBitmap* aBitmap); |
|
112 void DrawFrameL(const CFbsBitmap* aBitmap); |
|
113 void SetDrawRect(const TRect& aRect); |
|
114 void SetDrawRectThread(const TRect& aRect); |
|
115 const TRect& DrawRect(); |
|
116 TSize WindowSize(); |
|
117 void SetPosition(const TPoint& aPosition); |
|
118 void SetVisible(TBool aVisible, TBool aUseEventServer = ETrue); |
|
119 void SetWindowRect(const TRect& aRect,MMMADisplay::TThreadType aThreadType); |
|
120 void SetRWindowRect(const TRect& aRect, MMMADisplay::TThreadType aThreadType); |
|
121 const TRect& WindowRect(); |
|
122 TDisplayWindowType GetDisplayWindowType() const; |
|
123 TBool IsVisible() const; |
|
124 void ContainerSet(); |
|
125 void ContainerDestroyed(); |
|
126 |
|
127 |
|
128 // from base class MCameraObserver2 |
|
129 void HandleEvent(const TECAMEvent& aEvent); |
|
130 void ViewFinderReady(MCameraBuffer& aCameraBuffer,TInt aError); |
|
131 void ImageBufferReady(MCameraBuffer& aCameraBuffer,TInt aError); |
|
132 void VideoBufferReady(MCameraBuffer& aCameraBuffer,TInt aError); |
|
133 |
|
134 |
|
135 // from base class MUiEventConsumer |
|
136 void MdcDSAResourcesCallback( |
|
137 RWsSession &aWs, |
|
138 CWsScreenDevice &aScreenDevice, |
|
139 RWindowBase &aWindow); |
|
140 void MdcUICallback(TInt aCallbackId); |
|
141 |
|
142 |
|
143 // from base class MDirectScreenAccess |
|
144 void AbortNow(RDirectScreenAccess::TTerminationReasons aReasons); |
|
145 void Restart(RDirectScreenAccess::TTerminationReasons aReasons); |
|
146 |
|
147 |
|
148 private: |
|
149 /** |
|
150 * Constructor. |
|
151 * @see CMMACameraWindow::NewL() |
|
152 */ |
|
153 CMMACameraWindow(TInt aCameraIndex); |
|
154 |
|
155 /** |
|
156 * Creates UI Camera - |
|
157 * a new CCamera instance (duplicated from handle |
|
158 * given to the constructor) |
|
159 * Have to be called from the thread which UI Camera |
|
160 * will be controlled from |
|
161 * |
|
162 * @since S60 v5.0 |
|
163 * @param "aWs" WS session from the last MdcDSAResourcesCallback |
|
164 * @param "aScreenDevice" Screen from the last MdcDSAResourcesCallback |
|
165 * @param "aWindow" Window from the last MdcDSAResourcesCallback |
|
166 */ |
|
167 void UIStartViewFinder(RWsSession &aWs, CWsScreenDevice &aScreenDevice, RWindowBase &aWindow); |
|
168 |
|
169 /** |
|
170 * If UI Camera have been created |
|
171 * it starts/hides the DirectViewFinder |
|
172 * Have to be called from UI thread in which UI Camera |
|
173 * have been created! |
|
174 * |
|
175 * @since S60 v5.0 |
|
176 * @param "aVisible" If true DirectViewFinder is started, else stopped |
|
177 */ |
|
178 void SetViewFinderVisibility(TBool aVisible); |
|
179 |
|
180 /** |
|
181 * Stops the DirectViewFinder and deletes UI Camera instance |
|
182 * Have to be called from UI thread in which UI Camera |
|
183 * have been created before the CMMACameraWindow instance |
|
184 * is deleted! |
|
185 * |
|
186 * @since S60 v5.0 |
|
187 */ |
|
188 void ReleaseUiResources(); |
|
189 |
|
190 /** |
|
191 * The callback method invoked by starter timer |
|
192 * |
|
193 * @since S60 v5.0 |
|
194 * @param aThis An instance of CMMACameraWindow |
|
195 * @return Always returns EFalse |
|
196 */ |
|
197 static TInt StarterTimerCallback(TAny* aThis); |
|
198 |
|
199 /** |
|
200 * Starts viewfinder. |
|
201 * |
|
202 * @since S60 v5.0 |
|
203 */ |
|
204 void StartViewFinder(); |
|
205 |
|
206 /** |
|
207 * Resets (stops and starts) viewfinder |
|
208 * |
|
209 * @since S60 v5.0 |
|
210 */ |
|
211 void ResetViewFinder(); |
|
212 |
|
213 /** |
|
214 * Draws the error message to specified area. |
|
215 * Used in cases when viewfinder is unable to start |
|
216 * |
|
217 * @since S60 v5.0 |
|
218 * @param aError Viewfinder error id |
|
219 * @param aDrawRect Area to draw to |
|
220 */ |
|
221 void DrawViewFinderErrorL(const TInt aError, const TRect& aDrawRect); |
|
222 |
|
223 /** |
|
224 * Deletes this object. |
|
225 * |
|
226 * @since S60 v5.0 |
|
227 */ |
|
228 void Destroy(); |
|
229 |
|
230 private: // data |
|
231 /** |
|
232 * Indicates the window visibility. |
|
233 */ |
|
234 TBool iVisible; |
|
235 |
|
236 /** |
|
237 * Indicated that owning player is in Started state. |
|
238 */ |
|
239 TBool iStarted; |
|
240 |
|
241 /** |
|
242 * Indicates that Direct viewfinder is displayed on screen. |
|
243 */ |
|
244 TBool iViewFinderVisible; |
|
245 |
|
246 /** |
|
247 * Indicates that duplicated camera (iUICamera) is powered on. |
|
248 */ |
|
249 TBool iCameraPowerOn; |
|
250 |
|
251 /** |
|
252 * Rectangle to display viewfinder on (Window coordinates). |
|
253 */ |
|
254 TRect iDrawRect; |
|
255 |
|
256 /** |
|
257 * The area of the window. |
|
258 */ |
|
259 TRect iClientRect; |
|
260 |
|
261 /** |
|
262 * The handle of original camera instance. |
|
263 */ |
|
264 TInt iCameraHandle; |
|
265 |
|
266 /** |
|
267 * UI Camera instance |
|
268 * Duplicated from iCameraHandle. |
|
269 * Adjustable and usable from UI thread only. |
|
270 * Own. |
|
271 */ |
|
272 CCamera* iUICamera; |
|
273 |
|
274 /** |
|
275 * Display instance used to invoke UI callbacks. |
|
276 * Not owned. |
|
277 */ |
|
278 MMMADisplay* iDisplay; |
|
279 |
|
280 /** |
|
281 * Window server session used by UI thread. |
|
282 * Adjustable and usable from UI thread only. |
|
283 * Not owned. |
|
284 */ |
|
285 RWsSession* iWs; |
|
286 |
|
287 /** |
|
288 * Screen device used by UI thread. |
|
289 * Adjustable and usable from UI thread only. |
|
290 * Not owned. |
|
291 */ |
|
292 CWsScreenDevice* iScreenDevice; |
|
293 |
|
294 /** |
|
295 * Window to draw viewfinder on. |
|
296 * Adjustable and usable from UI thread only. |
|
297 * From UI thread. |
|
298 * Not owned. |
|
299 */ |
|
300 RWindowBase* iWindow; |
|
301 |
|
302 /** |
|
303 * The timer to delay viewfinder start |
|
304 * to avoid many showing/hidding request |
|
305 * (for instance when scrolling the viewfinder) |
|
306 * Adjustable and usable from UI thread only. |
|
307 * Own. |
|
308 */ |
|
309 CPeriodic* iStarterTimer; |
|
310 |
|
311 /** |
|
312 * Direct screen access used to draw the error message. |
|
313 * Adjustable and usable from UI thread only. |
|
314 * Own. |
|
315 */ |
|
316 CDirectScreenAccess* iDirectAccess; |
|
317 |
|
318 /** |
|
319 * Count of remaining allowed DSA restarts. |
|
320 * In some cases (like screen orientation change) |
|
321 * the DSA fails to start for some time. |
|
322 * Therefore the start is tried more times. |
|
323 */ |
|
324 TUint iRemainingDSAStartAttempts; |
|
325 |
|
326 /** |
|
327 * An icon used to display instead of viewfinder. |
|
328 * in case that viewfinder start fails. |
|
329 * Own. |
|
330 */ |
|
331 CFbsBitmap* iErrorIconBitmap; |
|
332 |
|
333 /** |
|
334 * Bitmap mask of iErrorIconBitmap. |
|
335 * Own. |
|
336 */ |
|
337 CFbsBitmap* iErrorIconMaskBitmap; |
|
338 |
|
339 /** |
|
340 * Symbian RWindow rect |
|
341 */ |
|
342 TRect iRWindowRect; |
|
343 }; |
|
344 |
|
345 #endif // CMMACAMERAWINDOW_H |