mmplugins/cameraplugins/source/mmcameraclientplugin/mmcameraclientsession/src/mmdirectviewfinder.cpp
changeset 0 40261b775718
equal deleted inserted replaced
-1:000000000000 0:40261b775718
       
     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".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 /**
       
    17  @file
       
    18  @internalComponent
       
    19 */
       
    20 
       
    21 #include "mmdirectviewfinder.h"
       
    22 
       
    23 #include <graphics/surfaceconfiguration.h>
       
    24 #include "w32std.h"
       
    25 #ifdef SYMBIAN_ENABLE_SPLIT_HEADERS
       
    26 #include <ecamdef.h>
       
    27 #endif
       
    28 
       
    29 CMMDirectViewFinder* CMMDirectViewFinder::NewL(CMMCameraClientSession& aOwner)
       
    30 	{
       
    31 	CMMDirectViewFinder* self = new (ELeave) CMMDirectViewFinder(aOwner);
       
    32 	CleanupStack::PushL(self);
       
    33 	self->ConstructL();
       
    34 	CleanupStack::Pop(self);
       
    35 	return self;
       
    36 	}
       
    37 
       
    38 void CMMDirectViewFinder::ConstructL()
       
    39 	{
       
    40 	}
       
    41 
       
    42 CMMDirectViewFinder::CMMDirectViewFinder(CMMCameraClientSession& aOwner)
       
    43 	: iOwner(aOwner), iDirectViewFinderObserver(NULL), iPrepareCompleted(EFalse)
       
    44 	{
       
    45 	iReferenceCount++;
       
    46 	}
       
    47 
       
    48 CMMDirectViewFinder::~CMMDirectViewFinder()
       
    49 	{
       
    50 	}
       
    51 
       
    52 void CMMDirectViewFinder::Release(CCamera::CCameraV2DirectViewFinder* aDirectViewFinderHandle)
       
    53 	{
       
    54 	THashMapIter<TInt, CCamera::CCameraV2DirectViewFinder*> iter(iOwner.iHashMap);
       
    55 	for (CCamera::CCameraV2DirectViewFinder* const* vF = iter.NextValue(); vF; vF = iter.NextValue())
       
    56 		{
       
    57 		if (*vF == aDirectViewFinderHandle)
       
    58 			{
       
    59 			iOwner.iHashMap.Remove(*iter.CurrentKey());
       
    60 			break;
       
    61 			}
       
    62 		}
       
    63 	}
       
    64 
       
    65 void CMMDirectViewFinder::CreateHistogramImplFactoryL(MImplementationFactory*& /*aImplFactoryPtr*/) const
       
    66 	{
       
    67 	User::Leave(KErrNotSupported);
       
    68 	}
       
    69 
       
    70 void CMMDirectViewFinder::GetImageProcessingImplFactoryL(MImplementationFactory*& /*aImplFactoryPtr*/) const
       
    71 	{
       
    72 	User::Leave(KErrNotSupported);
       
    73 	}
       
    74 
       
    75 TAny* CMMDirectViewFinder::GetDirectSnapshotImpl(TUid /*aInterface*/) const
       
    76 	{
       
    77 	return NULL;
       
    78 	}
       
    79 
       
    80 void CMMDirectViewFinder::SetDirectViewFinderObserver(MDirectViewFinderObserver& aDirectViewFinderObserver)
       
    81 	{
       
    82 	iDirectViewFinderObserver = &aDirectViewFinderObserver;
       
    83 	}
       
    84 
       
    85 void CMMDirectViewFinder::SetDirectViewFinderHandle(CCamera::CCameraV2DirectViewFinder* aDirectViewFinderHandle)
       
    86 	{
       
    87 	TInt position = iOwner.iHashMap.Count();
       
    88 	iDirectViewFinderHandle = aDirectViewFinderHandle;
       
    89 	iOwner.iHashMap.Insert(position, iDirectViewFinderHandle);
       
    90 	}
       
    91 
       
    92 void CMMDirectViewFinder::StartViewFinderDirectL(RWsSession& aWs, CWsScreenDevice& aScreenDevice, RWindowBase& aWindow, TRect& aScreenRect)
       
    93 	{
       
    94 	TRect clip;
       
    95 	clip.SetWidth(0);
       
    96 	clip.SetHeight(0);
       
    97 
       
    98 	StartViewFinderDirectL(aWs, aScreenDevice, aWindow, aScreenRect, clip);
       
    99 	}
       
   100 
       
   101 void CMMDirectViewFinder::StartViewFinderDirectL(RWsSession& /*aWs*/, CWsScreenDevice& aScreenDevice,
       
   102 											RWindowBase& aWindow, TRect& aScreenRect, TRect& aClipRect)
       
   103 	{
       
   104 	// Make sure device is powered up (implies it has been reserved)
       
   105 	if (!iOwner.iPoweredUp)
       
   106 		{
       
   107 		User::Leave(KErrNotReady);
       
   108 		}
       
   109 
       
   110 	// Ensure start is not called twice
       
   111 	CCamera::CCameraV2DirectViewFinder::TViewFinderState state;
       
   112 	GetViewFinderStateL(state);
       
   113 	if (state != CCamera::CCameraV2DirectViewFinder::EViewFinderInActive)
       
   114 		{
       
   115 		User::Leave(KErrNotReady);
       
   116 		}
       
   117 
       
   118 	TInt error = KErrNone;
       
   119 	if (!iPrepareCompleted)
       
   120 		{
       
   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);
       
   127 
       
   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)
       
   131 			{
       
   132 			TSurfaceConfiguration surfaceConfig;
       
   133 			directViewFinderInfo = directViewFinderInfoPckg();
       
   134 
       
   135 			error = surfaceConfig.SetSurfaceId(directViewFinderInfo.iSurfaceId);
       
   136 			if (error == KErrNone)
       
   137 				{
       
   138 				//	User::LeaveIfError(surfaceConfig.SetOrientation(CFbsBitGc::EGraphicsOrientationRotated90));
       
   139 				error = surfaceConfig.SetExtent(aScreenRect);
       
   140 				if (error == KErrNone)
       
   141 					{
       
   142 					//	User::LeaveIfError(aWindow.SetRequiredDisplayMode(EColor64K));
       
   143 					error = aWindow.SetBackgroundSurface(surfaceConfig, ETrue);
       
   144 					if (error == KErrNone)
       
   145 						{
       
   146 						iPrepareCompleted = ETrue;
       
   147 						}
       
   148 					}
       
   149 				}
       
   150 			}
       
   151 		}
       
   152 
       
   153 	if (error != KErrNone)
       
   154 		{
       
   155 		User::Leave(error);
       
   156 		}
       
   157 
       
   158 	// Start the viewfinder
       
   159 	error = iOwner.iCameraSession.SendMessage(ECamStartDirectViewFinder);
       
   160 	if (error != KErrNone)
       
   161 		{
       
   162 		User::Leave(error);
       
   163 		}
       
   164 
       
   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);
       
   168 	}
       
   169 
       
   170 void CMMDirectViewFinder::GetDirectViewFinderPropertiesL(TInt& aScreenNumber, TRect& aScreenRect, TRect& aClipRect) const
       
   171 	{
       
   172 	if (!iPrepareCompleted)
       
   173 		{
       
   174 		User::Leave(KErrNotReady);
       
   175 		}
       
   176 
       
   177 	TDirectViewFinderInfo info;
       
   178 	TDirectViewFinderInfoPckg pckg(info);
       
   179 
       
   180 	iOwner.iCameraSession.SendRxMessage(ECamDirectViewFinderProperties, pckg);
       
   181 	info = pckg();
       
   182 	aScreenNumber = info.iScreenNum;
       
   183 	aScreenRect = info.iScreenRect;
       
   184 	aClipRect = info.iClipRect;
       
   185 	}
       
   186 
       
   187 void CMMDirectViewFinder::PauseViewFinderDirect()
       
   188 	{
       
   189 	iOwner.iCameraSession.SendMessage(ECamPauseDirectViewFinder);
       
   190 	}
       
   191 
       
   192 void CMMDirectViewFinder::ResumeViewFinderDirect()
       
   193 	{
       
   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);	
       
   198 	}
       
   199 
       
   200 void CMMDirectViewFinder::GetViewFinderStateL(CCamera::CCameraV2DirectViewFinder::TViewFinderState& aViewFinderState) const
       
   201 	{
       
   202 	TDirectViewFinderState state;
       
   203 	TDirectViewFinderStatePckg pckg(state);
       
   204 
       
   205 	User::LeaveIfError(iOwner.iCameraSession.SendRxMessage(ECamDirectViewFinderState, pckg));
       
   206 
       
   207 	state = pckg();
       
   208 	aViewFinderState = state.iState;
       
   209 	}
       
   210 
       
   211 void CMMDirectViewFinder::StopDirectViewFinder()
       
   212 	{
       
   213 	iOwner.iCameraSession.SendMessage(ECamStopDirectViewFinder);
       
   214 	}
       
   215 
       
   216 void CMMDirectViewFinder::Release()
       
   217 	{
       
   218 	iReferenceCount--;
       
   219 	if (iReferenceCount == 0)
       
   220 		{
       
   221 		delete this;
       
   222 		}
       
   223 	}
       
   224 
       
   225 void CMMDirectViewFinder::GetViewFinderFadingCapabilitiesL(CCameraViewFinder::TViewFinderFadingCapabilities& /*aVFFadingCapabilities*/) const
       
   226 	{
       
   227 	User::Leave(KErrNotSupported);
       
   228 	}
       
   229 
       
   230 void CMMDirectViewFinder::GetViewFinderFadingEffectL(CCameraViewFinder::TViewFinderFadingEffect& /*aCurrentVFFadingEffect*/) const
       
   231 	{
       
   232 	User::Leave(KErrNotSupported);
       
   233 	}
       
   234 
       
   235 void CMMDirectViewFinder::SetViewFinderFadingEffect(const CCameraViewFinder::TViewFinderFadingEffect& /*aVFFadingEffect*/)
       
   236 	{
       
   237 	TECAMEvent event(KUidECamEvent2ViewFinderFadingEffect, KErrNotSupported);
       
   238 	iOwner.iCameraObserver2->HandleEvent(event);
       
   239 	}
       
   240 
       
   241 void CMMDirectViewFinder::GetViewFinderHandleL(TInt& aVFHandle) const
       
   242 	{
       
   243 	THashMapIter<TInt, CCamera::CCameraV2DirectViewFinder*> iter(iOwner.iHashMap);
       
   244 	for (CCamera::CCameraV2DirectViewFinder* const* vF = iter.NextValue(); vF; vF = iter.NextValue())
       
   245 		{
       
   246 		if (*vF == iDirectViewFinderHandle)
       
   247 			{
       
   248 			// Handle returned is position within the hash table + 100 (arbitrary value to show uniquenness of handle)
       
   249 			aVFHandle = *iter.CurrentKey() + 100;
       
   250 			return;
       
   251 			}
       
   252 		}
       
   253 	User::Leave(KErrNotFound);
       
   254 	}