os/mm/mmplugins/cameraplugins/source/mmcameraclientplugin/mmcameraclientsession/src/mmdirectviewfinder.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/mm/mmplugins/cameraplugins/source/mmcameraclientplugin/mmcameraclientsession/src/mmdirectviewfinder.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,254 @@
     1.4 +// Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.5 +// All rights reserved.
     1.6 +// This component and the accompanying materials are made available
     1.7 +// under the terms of "Eclipse Public License v1.0"
     1.8 +// which accompanies this distribution, and is available
     1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.10 +//
    1.11 +// Initial Contributors:
    1.12 +// Nokia Corporation - initial contribution.
    1.13 +//
    1.14 +// Contributors:
    1.15 +//
    1.16 +// Description:
    1.17 +//
    1.18 +
    1.19 +/**
    1.20 + @file
    1.21 + @internalComponent
    1.22 +*/
    1.23 +
    1.24 +#include "mmdirectviewfinder.h"
    1.25 +
    1.26 +#include <graphics/surfaceconfiguration.h>
    1.27 +#include "w32std.h"
    1.28 +#ifdef SYMBIAN_ENABLE_SPLIT_HEADERS
    1.29 +#include <ecamdef.h>
    1.30 +#endif
    1.31 +
    1.32 +CMMDirectViewFinder* CMMDirectViewFinder::NewL(CMMCameraClientSession& aOwner)
    1.33 +	{
    1.34 +	CMMDirectViewFinder* self = new (ELeave) CMMDirectViewFinder(aOwner);
    1.35 +	CleanupStack::PushL(self);
    1.36 +	self->ConstructL();
    1.37 +	CleanupStack::Pop(self);
    1.38 +	return self;
    1.39 +	}
    1.40 +
    1.41 +void CMMDirectViewFinder::ConstructL()
    1.42 +	{
    1.43 +	}
    1.44 +
    1.45 +CMMDirectViewFinder::CMMDirectViewFinder(CMMCameraClientSession& aOwner)
    1.46 +	: iOwner(aOwner), iDirectViewFinderObserver(NULL), iPrepareCompleted(EFalse)
    1.47 +	{
    1.48 +	iReferenceCount++;
    1.49 +	}
    1.50 +
    1.51 +CMMDirectViewFinder::~CMMDirectViewFinder()
    1.52 +	{
    1.53 +	}
    1.54 +
    1.55 +void CMMDirectViewFinder::Release(CCamera::CCameraV2DirectViewFinder* aDirectViewFinderHandle)
    1.56 +	{
    1.57 +	THashMapIter<TInt, CCamera::CCameraV2DirectViewFinder*> iter(iOwner.iHashMap);
    1.58 +	for (CCamera::CCameraV2DirectViewFinder* const* vF = iter.NextValue(); vF; vF = iter.NextValue())
    1.59 +		{
    1.60 +		if (*vF == aDirectViewFinderHandle)
    1.61 +			{
    1.62 +			iOwner.iHashMap.Remove(*iter.CurrentKey());
    1.63 +			break;
    1.64 +			}
    1.65 +		}
    1.66 +	}
    1.67 +
    1.68 +void CMMDirectViewFinder::CreateHistogramImplFactoryL(MImplementationFactory*& /*aImplFactoryPtr*/) const
    1.69 +	{
    1.70 +	User::Leave(KErrNotSupported);
    1.71 +	}
    1.72 +
    1.73 +void CMMDirectViewFinder::GetImageProcessingImplFactoryL(MImplementationFactory*& /*aImplFactoryPtr*/) const
    1.74 +	{
    1.75 +	User::Leave(KErrNotSupported);
    1.76 +	}
    1.77 +
    1.78 +TAny* CMMDirectViewFinder::GetDirectSnapshotImpl(TUid /*aInterface*/) const
    1.79 +	{
    1.80 +	return NULL;
    1.81 +	}
    1.82 +
    1.83 +void CMMDirectViewFinder::SetDirectViewFinderObserver(MDirectViewFinderObserver& aDirectViewFinderObserver)
    1.84 +	{
    1.85 +	iDirectViewFinderObserver = &aDirectViewFinderObserver;
    1.86 +	}
    1.87 +
    1.88 +void CMMDirectViewFinder::SetDirectViewFinderHandle(CCamera::CCameraV2DirectViewFinder* aDirectViewFinderHandle)
    1.89 +	{
    1.90 +	TInt position = iOwner.iHashMap.Count();
    1.91 +	iDirectViewFinderHandle = aDirectViewFinderHandle;
    1.92 +	iOwner.iHashMap.Insert(position, iDirectViewFinderHandle);
    1.93 +	}
    1.94 +
    1.95 +void CMMDirectViewFinder::StartViewFinderDirectL(RWsSession& aWs, CWsScreenDevice& aScreenDevice, RWindowBase& aWindow, TRect& aScreenRect)
    1.96 +	{
    1.97 +	TRect clip;
    1.98 +	clip.SetWidth(0);
    1.99 +	clip.SetHeight(0);
   1.100 +
   1.101 +	StartViewFinderDirectL(aWs, aScreenDevice, aWindow, aScreenRect, clip);
   1.102 +	}
   1.103 +
   1.104 +void CMMDirectViewFinder::StartViewFinderDirectL(RWsSession& /*aWs*/, CWsScreenDevice& aScreenDevice,
   1.105 +											RWindowBase& aWindow, TRect& aScreenRect, TRect& aClipRect)
   1.106 +	{
   1.107 +	// Make sure device is powered up (implies it has been reserved)
   1.108 +	if (!iOwner.iPoweredUp)
   1.109 +		{
   1.110 +		User::Leave(KErrNotReady);
   1.111 +		}
   1.112 +
   1.113 +	// Ensure start is not called twice
   1.114 +	CCamera::CCameraV2DirectViewFinder::TViewFinderState state;
   1.115 +	GetViewFinderStateL(state);
   1.116 +	if (state != CCamera::CCameraV2DirectViewFinder::EViewFinderInActive)
   1.117 +		{
   1.118 +		User::Leave(KErrNotReady);
   1.119 +		}
   1.120 +
   1.121 +	TInt error = KErrNone;
   1.122 +	if (!iPrepareCompleted)
   1.123 +		{
   1.124 +		TDirectViewFinderInfo directViewFinderInfo;
   1.125 +		// Retrieve screen number from the screen device
   1.126 +		directViewFinderInfo.iScreenNum = aScreenDevice.GetScreenNumber();
   1.127 +		directViewFinderInfo.iScreenRect = aScreenRect;
   1.128 +		directViewFinderInfo.iClipRect = aClipRect;
   1.129 +		TDirectViewFinderInfoPckg directViewFinderInfoPckg(directViewFinderInfo);
   1.130 +
   1.131 +		// Prepare viewfinder for playback and retrieve the surface id from the graphics sink
   1.132 +		error = iOwner.iCameraSession.SendMessage(ECamPrepareDirectViewFinder, directViewFinderInfoPckg);
   1.133 +		if (error == KErrNone)
   1.134 +			{
   1.135 +			TSurfaceConfiguration surfaceConfig;
   1.136 +			directViewFinderInfo = directViewFinderInfoPckg();
   1.137 +
   1.138 +			error = surfaceConfig.SetSurfaceId(directViewFinderInfo.iSurfaceId);
   1.139 +			if (error == KErrNone)
   1.140 +				{
   1.141 +				//	User::LeaveIfError(surfaceConfig.SetOrientation(CFbsBitGc::EGraphicsOrientationRotated90));
   1.142 +				error = surfaceConfig.SetExtent(aScreenRect);
   1.143 +				if (error == KErrNone)
   1.144 +					{
   1.145 +					//	User::LeaveIfError(aWindow.SetRequiredDisplayMode(EColor64K));
   1.146 +					error = aWindow.SetBackgroundSurface(surfaceConfig, ETrue);
   1.147 +					if (error == KErrNone)
   1.148 +						{
   1.149 +						iPrepareCompleted = ETrue;
   1.150 +						}
   1.151 +					}
   1.152 +				}
   1.153 +			}
   1.154 +		}
   1.155 +
   1.156 +	if (error != KErrNone)
   1.157 +		{
   1.158 +		User::Leave(error);
   1.159 +		}
   1.160 +
   1.161 +	// Start the viewfinder
   1.162 +	error = iOwner.iCameraSession.SendMessage(ECamStartDirectViewFinder);
   1.163 +	if (error != KErrNone)
   1.164 +		{
   1.165 +		User::Leave(error);
   1.166 +		}
   1.167 +
   1.168 +	// HACK!!! HACK!!! HACK!!! HACK!!! HACK!!! HACK!!! HACK!!! HACK!!!
   1.169 +	// TODO: Here to let tests run. Will be removed once foundation provide event registration/notification APIs
   1.170 +	iDirectViewFinderObserver->DirectViewFinderFirstFrameDisplayed(*iDirectViewFinderHandle, KErrNone);
   1.171 +	}
   1.172 +
   1.173 +void CMMDirectViewFinder::GetDirectViewFinderPropertiesL(TInt& aScreenNumber, TRect& aScreenRect, TRect& aClipRect) const
   1.174 +	{
   1.175 +	if (!iPrepareCompleted)
   1.176 +		{
   1.177 +		User::Leave(KErrNotReady);
   1.178 +		}
   1.179 +
   1.180 +	TDirectViewFinderInfo info;
   1.181 +	TDirectViewFinderInfoPckg pckg(info);
   1.182 +
   1.183 +	iOwner.iCameraSession.SendRxMessage(ECamDirectViewFinderProperties, pckg);
   1.184 +	info = pckg();
   1.185 +	aScreenNumber = info.iScreenNum;
   1.186 +	aScreenRect = info.iScreenRect;
   1.187 +	aClipRect = info.iClipRect;
   1.188 +	}
   1.189 +
   1.190 +void CMMDirectViewFinder::PauseViewFinderDirect()
   1.191 +	{
   1.192 +	iOwner.iCameraSession.SendMessage(ECamPauseDirectViewFinder);
   1.193 +	}
   1.194 +
   1.195 +void CMMDirectViewFinder::ResumeViewFinderDirect()
   1.196 +	{
   1.197 +	iOwner.iCameraSession.SendMessage(ECamResumeDirectViewFinder);
   1.198 +	// HACK!!! HACK!!! HACK!!! HACK!!! HACK!!! HACK!!! HACK!!! HACK!!!
   1.199 +	// TODO: Here to let tests run. Will be removed once foundation provide event registration/notification APIs
   1.200 +	iDirectViewFinderObserver->DirectViewFinderFirstFrameDisplayed(*iDirectViewFinderHandle, KErrNone);	
   1.201 +	}
   1.202 +
   1.203 +void CMMDirectViewFinder::GetViewFinderStateL(CCamera::CCameraV2DirectViewFinder::TViewFinderState& aViewFinderState) const
   1.204 +	{
   1.205 +	TDirectViewFinderState state;
   1.206 +	TDirectViewFinderStatePckg pckg(state);
   1.207 +
   1.208 +	User::LeaveIfError(iOwner.iCameraSession.SendRxMessage(ECamDirectViewFinderState, pckg));
   1.209 +
   1.210 +	state = pckg();
   1.211 +	aViewFinderState = state.iState;
   1.212 +	}
   1.213 +
   1.214 +void CMMDirectViewFinder::StopDirectViewFinder()
   1.215 +	{
   1.216 +	iOwner.iCameraSession.SendMessage(ECamStopDirectViewFinder);
   1.217 +	}
   1.218 +
   1.219 +void CMMDirectViewFinder::Release()
   1.220 +	{
   1.221 +	iReferenceCount--;
   1.222 +	if (iReferenceCount == 0)
   1.223 +		{
   1.224 +		delete this;
   1.225 +		}
   1.226 +	}
   1.227 +
   1.228 +void CMMDirectViewFinder::GetViewFinderFadingCapabilitiesL(CCameraViewFinder::TViewFinderFadingCapabilities& /*aVFFadingCapabilities*/) const
   1.229 +	{
   1.230 +	User::Leave(KErrNotSupported);
   1.231 +	}
   1.232 +
   1.233 +void CMMDirectViewFinder::GetViewFinderFadingEffectL(CCameraViewFinder::TViewFinderFadingEffect& /*aCurrentVFFadingEffect*/) const
   1.234 +	{
   1.235 +	User::Leave(KErrNotSupported);
   1.236 +	}
   1.237 +
   1.238 +void CMMDirectViewFinder::SetViewFinderFadingEffect(const CCameraViewFinder::TViewFinderFadingEffect& /*aVFFadingEffect*/)
   1.239 +	{
   1.240 +	TECAMEvent event(KUidECamEvent2ViewFinderFadingEffect, KErrNotSupported);
   1.241 +	iOwner.iCameraObserver2->HandleEvent(event);
   1.242 +	}
   1.243 +
   1.244 +void CMMDirectViewFinder::GetViewFinderHandleL(TInt& aVFHandle) const
   1.245 +	{
   1.246 +	THashMapIter<TInt, CCamera::CCameraV2DirectViewFinder*> iter(iOwner.iHashMap);
   1.247 +	for (CCamera::CCameraV2DirectViewFinder* const* vF = iter.NextValue(); vF; vF = iter.NextValue())
   1.248 +		{
   1.249 +		if (*vF == iDirectViewFinderHandle)
   1.250 +			{
   1.251 +			// Handle returned is position within the hash table + 100 (arbitrary value to show uniquenness of handle)
   1.252 +			aVFHandle = *iter.CurrentKey() + 100;
   1.253 +			return;
   1.254 +			}
   1.255 +		}
   1.256 +	User::Leave(KErrNotFound);
   1.257 +	}