os/mm/mmplugins/cameraplugins/source/mmcameraclientplugin/mmcameraclientsession/src/mmdirectviewfinder.cpp
Update contrib.
1 // Copyright (c) 2008-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.
21 #include "mmdirectviewfinder.h"
23 #include <graphics/surfaceconfiguration.h>
25 #ifdef SYMBIAN_ENABLE_SPLIT_HEADERS
29 CMMDirectViewFinder* CMMDirectViewFinder::NewL(CMMCameraClientSession& aOwner)
31 CMMDirectViewFinder* self = new (ELeave) CMMDirectViewFinder(aOwner);
32 CleanupStack::PushL(self);
34 CleanupStack::Pop(self);
38 void CMMDirectViewFinder::ConstructL()
42 CMMDirectViewFinder::CMMDirectViewFinder(CMMCameraClientSession& aOwner)
43 : iOwner(aOwner), iDirectViewFinderObserver(NULL), iPrepareCompleted(EFalse)
48 CMMDirectViewFinder::~CMMDirectViewFinder()
52 void CMMDirectViewFinder::Release(CCamera::CCameraV2DirectViewFinder* aDirectViewFinderHandle)
54 THashMapIter<TInt, CCamera::CCameraV2DirectViewFinder*> iter(iOwner.iHashMap);
55 for (CCamera::CCameraV2DirectViewFinder* const* vF = iter.NextValue(); vF; vF = iter.NextValue())
57 if (*vF == aDirectViewFinderHandle)
59 iOwner.iHashMap.Remove(*iter.CurrentKey());
65 void CMMDirectViewFinder::CreateHistogramImplFactoryL(MImplementationFactory*& /*aImplFactoryPtr*/) const
67 User::Leave(KErrNotSupported);
70 void CMMDirectViewFinder::GetImageProcessingImplFactoryL(MImplementationFactory*& /*aImplFactoryPtr*/) const
72 User::Leave(KErrNotSupported);
75 TAny* CMMDirectViewFinder::GetDirectSnapshotImpl(TUid /*aInterface*/) const
80 void CMMDirectViewFinder::SetDirectViewFinderObserver(MDirectViewFinderObserver& aDirectViewFinderObserver)
82 iDirectViewFinderObserver = &aDirectViewFinderObserver;
85 void CMMDirectViewFinder::SetDirectViewFinderHandle(CCamera::CCameraV2DirectViewFinder* aDirectViewFinderHandle)
87 TInt position = iOwner.iHashMap.Count();
88 iDirectViewFinderHandle = aDirectViewFinderHandle;
89 iOwner.iHashMap.Insert(position, iDirectViewFinderHandle);
92 void CMMDirectViewFinder::StartViewFinderDirectL(RWsSession& aWs, CWsScreenDevice& aScreenDevice, RWindowBase& aWindow, TRect& aScreenRect)
98 StartViewFinderDirectL(aWs, aScreenDevice, aWindow, aScreenRect, clip);
101 void CMMDirectViewFinder::StartViewFinderDirectL(RWsSession& /*aWs*/, CWsScreenDevice& aScreenDevice,
102 RWindowBase& aWindow, TRect& aScreenRect, TRect& aClipRect)
104 // Make sure device is powered up (implies it has been reserved)
105 if (!iOwner.iPoweredUp)
107 User::Leave(KErrNotReady);
110 // Ensure start is not called twice
111 CCamera::CCameraV2DirectViewFinder::TViewFinderState state;
112 GetViewFinderStateL(state);
113 if (state != CCamera::CCameraV2DirectViewFinder::EViewFinderInActive)
115 User::Leave(KErrNotReady);
118 TInt error = KErrNone;
119 if (!iPrepareCompleted)
121 TDirectViewFinderInfo directViewFinderInfo;
122 // Retrieve screen number from the screen device
123 directViewFinderInfo.iScreenNum = aScreenDevice.GetScreenNumber();
124 directViewFinderInfo.iScreenRect = aScreenRect;
125 directViewFinderInfo.iClipRect = aClipRect;
126 TDirectViewFinderInfoPckg directViewFinderInfoPckg(directViewFinderInfo);
128 // Prepare viewfinder for playback and retrieve the surface id from the graphics sink
129 error = iOwner.iCameraSession.SendMessage(ECamPrepareDirectViewFinder, directViewFinderInfoPckg);
130 if (error == KErrNone)
132 TSurfaceConfiguration surfaceConfig;
133 directViewFinderInfo = directViewFinderInfoPckg();
135 error = surfaceConfig.SetSurfaceId(directViewFinderInfo.iSurfaceId);
136 if (error == KErrNone)
138 // User::LeaveIfError(surfaceConfig.SetOrientation(CFbsBitGc::EGraphicsOrientationRotated90));
139 error = surfaceConfig.SetExtent(aScreenRect);
140 if (error == KErrNone)
142 // User::LeaveIfError(aWindow.SetRequiredDisplayMode(EColor64K));
143 error = aWindow.SetBackgroundSurface(surfaceConfig, ETrue);
144 if (error == KErrNone)
146 iPrepareCompleted = ETrue;
153 if (error != KErrNone)
158 // Start the viewfinder
159 error = iOwner.iCameraSession.SendMessage(ECamStartDirectViewFinder);
160 if (error != KErrNone)
165 // HACK!!! HACK!!! HACK!!! HACK!!! HACK!!! HACK!!! HACK!!! HACK!!!
166 // TODO: Here to let tests run. Will be removed once foundation provide event registration/notification APIs
167 iDirectViewFinderObserver->DirectViewFinderFirstFrameDisplayed(*iDirectViewFinderHandle, KErrNone);
170 void CMMDirectViewFinder::GetDirectViewFinderPropertiesL(TInt& aScreenNumber, TRect& aScreenRect, TRect& aClipRect) const
172 if (!iPrepareCompleted)
174 User::Leave(KErrNotReady);
177 TDirectViewFinderInfo info;
178 TDirectViewFinderInfoPckg pckg(info);
180 iOwner.iCameraSession.SendRxMessage(ECamDirectViewFinderProperties, pckg);
182 aScreenNumber = info.iScreenNum;
183 aScreenRect = info.iScreenRect;
184 aClipRect = info.iClipRect;
187 void CMMDirectViewFinder::PauseViewFinderDirect()
189 iOwner.iCameraSession.SendMessage(ECamPauseDirectViewFinder);
192 void CMMDirectViewFinder::ResumeViewFinderDirect()
194 iOwner.iCameraSession.SendMessage(ECamResumeDirectViewFinder);
195 // HACK!!! HACK!!! HACK!!! HACK!!! HACK!!! HACK!!! HACK!!! HACK!!!
196 // TODO: Here to let tests run. Will be removed once foundation provide event registration/notification APIs
197 iDirectViewFinderObserver->DirectViewFinderFirstFrameDisplayed(*iDirectViewFinderHandle, KErrNone);
200 void CMMDirectViewFinder::GetViewFinderStateL(CCamera::CCameraV2DirectViewFinder::TViewFinderState& aViewFinderState) const
202 TDirectViewFinderState state;
203 TDirectViewFinderStatePckg pckg(state);
205 User::LeaveIfError(iOwner.iCameraSession.SendRxMessage(ECamDirectViewFinderState, pckg));
208 aViewFinderState = state.iState;
211 void CMMDirectViewFinder::StopDirectViewFinder()
213 iOwner.iCameraSession.SendMessage(ECamStopDirectViewFinder);
216 void CMMDirectViewFinder::Release()
219 if (iReferenceCount == 0)
225 void CMMDirectViewFinder::GetViewFinderFadingCapabilitiesL(CCameraViewFinder::TViewFinderFadingCapabilities& /*aVFFadingCapabilities*/) const
227 User::Leave(KErrNotSupported);
230 void CMMDirectViewFinder::GetViewFinderFadingEffectL(CCameraViewFinder::TViewFinderFadingEffect& /*aCurrentVFFadingEffect*/) const
232 User::Leave(KErrNotSupported);
235 void CMMDirectViewFinder::SetViewFinderFadingEffect(const CCameraViewFinder::TViewFinderFadingEffect& /*aVFFadingEffect*/)
237 TECAMEvent event(KUidECamEvent2ViewFinderFadingEffect, KErrNotSupported);
238 iOwner.iCameraObserver2->HandleEvent(event);
241 void CMMDirectViewFinder::GetViewFinderHandleL(TInt& aVFHandle) const
243 THashMapIter<TInt, CCamera::CCameraV2DirectViewFinder*> iter(iOwner.iHashMap);
244 for (CCamera::CCameraV2DirectViewFinder* const* vF = iter.NextValue(); vF; vF = iter.NextValue())
246 if (*vF == iDirectViewFinderHandle)
248 // Handle returned is position within the hash table + 100 (arbitrary value to show uniquenness of handle)
249 aVFHandle = *iter.CurrentKey() + 100;
253 User::Leave(KErrNotFound);