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 MCameraObserver, |
|
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 MCameraObserver |
|
129 void ReserveComplete(TInt aError); |
|
130 void PowerOnComplete(TInt aError); |
|
131 void ViewFinderFrameReady(CFbsBitmap& aFrame); |
|
132 |
|
133 void ImageReady(CFbsBitmap* aBitmap, |
|
134 HBufC8* aData, |
|
135 TInt aError); |
|
136 |
|
137 void FrameBufferReady(MFrameBuffer* aFrameBuffer, |
|
138 TInt aError); |
|
139 |
|
140 |
|
141 // from base class MUiEventConsumer |
|
142 void MdcDSAResourcesCallback( |
|
143 RWsSession &aWs, |
|
144 CWsScreenDevice &aScreenDevice, |
|
145 RWindowBase &aWindow); |
|
146 void MdcUICallback(TInt aCallbackId); |
|
147 |
|
148 |
|
149 // from base class MDirectScreenAccess |
|
150 void AbortNow(RDirectScreenAccess::TTerminationReasons aReasons); |
|
151 void Restart(RDirectScreenAccess::TTerminationReasons aReasons); |
|
152 |
|
153 |
|
154 private: |
|
155 /** |
|
156 * Constructor. |
|
157 * @see CMMACameraWindow::NewL() |
|
158 */ |
|
159 CMMACameraWindow(TInt aCameraIndex); |
|
160 |
|
161 /** |
|
162 * Creates UI Camera - |
|
163 * a new CCamera instance (duplicated from handle |
|
164 * given to the constructor) |
|
165 * Have to be called from the thread which UI Camera |
|
166 * will be controlled from |
|
167 * |
|
168 * @since S60 v5.0 |
|
169 * @param "aWs" WS session from the last MdcDSAResourcesCallback |
|
170 * @param "aScreenDevice" Screen from the last MdcDSAResourcesCallback |
|
171 * @param "aWindow" Window from the last MdcDSAResourcesCallback |
|
172 */ |
|
173 void UIStartViewFinder(RWsSession &aWs, CWsScreenDevice &aScreenDevice, RWindowBase &aWindow); |
|
174 |
|
175 /** |
|
176 * If UI Camera have been created |
|
177 * it starts/hides the DirectViewFinder |
|
178 * Have to be called from UI thread in which UI Camera |
|
179 * have been created! |
|
180 * |
|
181 * @since S60 v5.0 |
|
182 * @param "aVisible" If true DirectViewFinder is started, else stopped |
|
183 */ |
|
184 void SetViewFinderVisibility(TBool aVisible); |
|
185 |
|
186 /** |
|
187 * Stops the DirectViewFinder and deletes UI Camera instance |
|
188 * Have to be called from UI thread in which UI Camera |
|
189 * have been created before the CMMACameraWindow instance |
|
190 * is deleted! |
|
191 * |
|
192 * @since S60 v5.0 |
|
193 */ |
|
194 void ReleaseUiResources(); |
|
195 |
|
196 /** |
|
197 * The callback method invoked by starter timer |
|
198 * |
|
199 * @since S60 v5.0 |
|
200 * @param aThis An instance of CMMACameraWindow |
|
201 * @return Always returns EFalse |
|
202 */ |
|
203 static TInt StarterTimerCallback(TAny* aThis); |
|
204 |
|
205 /** |
|
206 * Starts viewfinder. |
|
207 * |
|
208 * @since S60 v5.0 |
|
209 */ |
|
210 void StartViewFinder(); |
|
211 |
|
212 /** |
|
213 * Resets (stops and starts) viewfinder |
|
214 * |
|
215 * @since S60 v5.0 |
|
216 */ |
|
217 void ResetViewFinder(); |
|
218 |
|
219 /** |
|
220 * Draws the error message to specified area. |
|
221 * Used in cases when viewfinder is unable to start |
|
222 * |
|
223 * @since S60 v5.0 |
|
224 * @param aError Viewfinder error id |
|
225 * @param aDrawRect Area to draw to |
|
226 */ |
|
227 void DrawViewFinderErrorL(const TInt aError, const TRect& aDrawRect); |
|
228 |
|
229 /** |
|
230 * Deletes this object. |
|
231 * |
|
232 * @since S60 v5.0 |
|
233 */ |
|
234 void Destroy(); |
|
235 |
|
236 private: // data |
|
237 /** |
|
238 * Indicates the window visibility. |
|
239 */ |
|
240 TBool iVisible; |
|
241 |
|
242 /** |
|
243 * Indicated that owning player is in Started state. |
|
244 */ |
|
245 TBool iStarted; |
|
246 |
|
247 /** |
|
248 * Indicates that Direct viewfinder is displayed on screen. |
|
249 */ |
|
250 TBool iViewFinderVisible; |
|
251 |
|
252 /** |
|
253 * Indicates that duplicated camera (iUICamera) is powered on. |
|
254 */ |
|
255 TBool iCameraPowerOn; |
|
256 |
|
257 /** |
|
258 * Rectangle to display viewfinder on (Window coordinates). |
|
259 */ |
|
260 TRect iDrawRect; |
|
261 |
|
262 /** |
|
263 * The area of the window. |
|
264 */ |
|
265 TRect iClientRect; |
|
266 |
|
267 /** |
|
268 * The handle of original camera instance. |
|
269 */ |
|
270 TInt iCameraHandle; |
|
271 |
|
272 /** |
|
273 * UI Camera instance |
|
274 * Duplicated from iCameraHandle. |
|
275 * Adjustable and usable from UI thread only. |
|
276 * Own. |
|
277 */ |
|
278 CCamera* iUICamera; |
|
279 |
|
280 /** |
|
281 * Display instance used to invoke UI callbacks. |
|
282 * Not owned. |
|
283 */ |
|
284 MMMADisplay* iDisplay; |
|
285 |
|
286 /** |
|
287 * Window server session used by UI thread. |
|
288 * Adjustable and usable from UI thread only. |
|
289 * Not owned. |
|
290 */ |
|
291 RWsSession* iWs; |
|
292 |
|
293 /** |
|
294 * Screen device used by UI thread. |
|
295 * Adjustable and usable from UI thread only. |
|
296 * Not owned. |
|
297 */ |
|
298 CWsScreenDevice* iScreenDevice; |
|
299 |
|
300 /** |
|
301 * Window to draw viewfinder on. |
|
302 * Adjustable and usable from UI thread only. |
|
303 * From UI thread. |
|
304 * Not owned. |
|
305 */ |
|
306 RWindowBase* iWindow; |
|
307 |
|
308 /** |
|
309 * The timer to delay viewfinder start |
|
310 * to avoid many showing/hidding request |
|
311 * (for instance when scrolling the viewfinder) |
|
312 * Adjustable and usable from UI thread only. |
|
313 * Own. |
|
314 */ |
|
315 CPeriodic* iStarterTimer; |
|
316 |
|
317 /** |
|
318 * Direct screen access used to draw the error message. |
|
319 * Adjustable and usable from UI thread only. |
|
320 * Own. |
|
321 */ |
|
322 CDirectScreenAccess* iDirectAccess; |
|
323 |
|
324 /** |
|
325 * Count of remaining allowed DSA restarts. |
|
326 * In some cases (like screen orientation change) |
|
327 * the DSA fails to start for some time. |
|
328 * Therefore the start is tried more times. |
|
329 */ |
|
330 TUint iRemainingDSAStartAttempts; |
|
331 |
|
332 /** |
|
333 * An icon used to display instead of viewfinder. |
|
334 * in case that viewfinder start fails. |
|
335 * Own. |
|
336 */ |
|
337 CFbsBitmap* iErrorIconBitmap; |
|
338 |
|
339 /** |
|
340 * Bitmap mask of iErrorIconBitmap. |
|
341 * Own. |
|
342 */ |
|
343 CFbsBitmap* iErrorIconMaskBitmap; |
|
344 |
|
345 /** |
|
346 * Symbian RWindow rect |
|
347 */ |
|
348 TRect iRWindowRect; |
|
349 }; |
|
350 |
|
351 #endif // CMMACAMERAWINDOW_H |
|