os/mm/mdfdevvideoextensions/nga_mdf_postprocessor_shai/src/NGAPostProcSessionManager.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/mm/mdfdevvideoextensions/nga_mdf_postprocessor_shai/src/NGAPostProcSessionManager.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,187 @@
     1.4 +/*
     1.5 +* Copyright (c) 2006 Nokia Corporation and/or its subsidiary(-ies).
     1.6 +* All rights reserved.
     1.7 +* This component and the accompanying materials are made available
     1.8 +* under the terms of "Eclipse Public License v1.0"
     1.9 +* which accompanies this distribution, and is available
    1.10 +* at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.11 +*
    1.12 +* Initial Contributors:
    1.13 +* Nokia Corporation - initial contribution.
    1.14 +*
    1.15 +* Contributors:
    1.16 +*
    1.17 +* Description:
    1.18 +*
    1.19 +*/
    1.20 +
    1.21 +
    1.22 +#include <e32base.h>
    1.23 +#include <graphics/surfaceupdateclient.h> //RSurfaceUpdateSession
    1.24 +#include <graphics/surfacemanager.h> //RSurfaceManager
    1.25 +#include <graphics/suerror.h> //KAllScreens
    1.26 + 
    1.27 +#include "NGAPostProcSessionManager.h" 
    1.28 +#include "NGAPostProcSessionManagerObserver.h"
    1.29 +#include "MdfRDebug.h"
    1.30 +#include "NGAPostProcNotifier.h"
    1.31 +
    1.32 +// --- Constants ---
    1.33 +const TInt KMessageSlots      = 4; 
    1.34 +
    1.35 +//**************************************************
    1.36 +
    1.37 +CNGAPostProcSessionManager* CNGAPostProcSessionManager::NewL() 
    1.38 +{ 
    1.39 +   PP_DEBUG(_L("CNGAPostProcSessionManager:NewL() ++"));
    1.40 +
    1.41 +    CNGAPostProcSessionManager* self = new (ELeave) CNGAPostProcSessionManager; 
    1.42 +    CleanupStack::PushL(self);
    1.43 +    self->ConstructL(); 
    1.44 +    CleanupStack::Pop();
    1.45 +
    1.46 +   PP_DEBUG(_L("CNGAPostProcSessionManager:NewL() --"));
    1.47 +    return self; 
    1.48 +}
    1.49 +
    1.50 +CNGAPostProcSessionManager::CNGAPostProcSessionManager() 
    1.51 +:iSurfaceUpdateSession(NULL),
    1.52 + iObserver(NULL)
    1.53 + 
    1.54 +{
    1.55 +}
    1.56 +
    1.57 +void CNGAPostProcSessionManager::ConstructL() 
    1.58 +{ 
    1.59 +   PP_DEBUG(_L("CNGAPostProcSessionManager[%x]:ConstructL() ++"), this);
    1.60 +    
    1.61 +    iSurfaceUpdateSession = new (ELeave) RSurfaceUpdateSession();
    1.62 +    User::LeaveIfError(iSurfaceUpdateSession->Connect(KMessageSlots));
    1.63 +    
    1.64 +   PP_DEBUG(_L("CNGAPostProcSessionManager[%x]:ConstructL() --"), this);
    1.65 +}
    1.66 +
    1.67 +void CNGAPostProcSessionManager::CreateNotifierL(TInt aNumSurfaceBuffers)
    1.68 +    {
    1.69 +    PP_DEBUG(_L("CNGAPostProcSessionManager[%x]:CreateNotifierL() ++"), this);
    1.70 +    
    1.71 +    CNGAPostProcNotifier* notifier;
    1.72 +    for(TInt index = 0; index < aNumSurfaceBuffers; ++index)
    1.73 +        {
    1.74 +        notifier = CNGAPostProcNotifier::NewL(*this);
    1.75 +        CleanupStack::PushL(notifier);
    1.76 +        
    1.77 +        iAOList.AppendL(notifier); 
    1.78 +        
    1.79 +        CleanupStack::Pop();
    1.80 +        }   
    1.81 +    PP_DEBUG(_L("CNGAPostProcSessionManager[%x]:CreateNotifierL() --"), this);
    1.82 +    }
    1.83 +
    1.84 +CNGAPostProcSessionManager::~CNGAPostProcSessionManager()
    1.85 +{
    1.86 +   PP_DEBUG(_L("CNGAPostProcSessionManager[%x]:~() ++"), this);
    1.87 +   //Its safer to destry notifiers before surfaceupdatesession object since notifiers
    1.88 +   //guarantee synchronous cancellation.
    1.89 +   iAOList.ResetAndDestroy();
    1.90 +   
    1.91 +    if(iSurfaceUpdateSession)
    1.92 +    {
    1.93 +    	CancelUpdate();
    1.94 +    	iSurfaceUpdateSession->Close();
    1.95 +    	delete iSurfaceUpdateSession;
    1.96 +    	iSurfaceUpdateSession = NULL;
    1.97 +	}
    1.98 +    
    1.99 +    
   1.100 +   PP_DEBUG(_L("CNGAPostProcSessionManager[%x]:~() --"), this);
   1.101 +}
   1.102 +
   1.103 +TInt CNGAPostProcSessionManager::PostPicture(const TSurfaceId& aSurfaceId,
   1.104 +								TInt aBufId, TBool aNotifyRequired) 
   1.105 +{ 
   1.106 +   PP_DEBUG(_L("CNGAPostProcSessionManager[%x]:PostPicture() ++"), this);
   1.107 +   TInt err = KErrNone;
   1.108 +	if(aNotifyRequired)
   1.109 +	{
   1.110 +	    CNGAPostProcNotifier* notifier = NULL;
   1.111 +		for(TInt j=0; j < iAOList.Count(); j++)
   1.112 +		{
   1.113 +            //notifier = iAOList[j];
   1.114 +            if(!iAOList[j]->IsActive())
   1.115 +            {
   1.116 +                notifier = iAOList[j];
   1.117 +                iAOList.Remove(j);
   1.118 +                //iAOList.Compress(); //why this is required? may create fragmentation.
   1.119 +                break;
   1.120 +            }
   1.121 +		}
   1.122 +		if(!notifier)
   1.123 +		{
   1.124 +			
   1.125 +			return KErrInUse;
   1.126 +	        
   1.127 +		}
   1.128 +		
   1.129 +		notifier->SetBufferId(aBufId);
   1.130 +		notifier->Activate();
   1.131 +		iSurfaceUpdateSession->NotifyWhenAvailable(notifier->iStatus);
   1.132 +		iAOList.Append(notifier);
   1.133 +		
   1.134 +		
   1.135 +	}
   1.136 +	err = iSurfaceUpdateSession->SubmitUpdate(KAllScreens, aSurfaceId, aBufId);
   1.137 +
   1.138 +   PP_DEBUG(_L("CNGAPostProcSessionManager[%x]:PostPicture() -- err = %d"), this, err);
   1.139 +   return err;
   1.140 +}
   1.141 +
   1.142 +void CNGAPostProcSessionManager::CancelUpdate() 
   1.143 +{ 
   1.144 +   PP_DEBUG(_L("CNGAPostProcSessionManager[%x]:CancelUpdate() ++"), this);
   1.145 +	iSurfaceUpdateSession->CancelAllUpdateNotifications();
   1.146 +   PP_DEBUG(_L("CNGAPostProcSessionManager[%x]:CancelUpdate() --"), this);
   1.147 +}
   1.148 +
   1.149 +void CNGAPostProcSessionManager::CancelNotifiers() 
   1.150 +{ 
   1.151 +    
   1.152 +   PP_DEBUG(_L("CNGAPostProcSessionManager[%x]:CancelNotifiers() ++"), this);
   1.153 +   TInt notifierCount = iAOList.Count();
   1.154 +   for (TInt i = notifierCount - 1; i >= 0; --i) //reverse loop since the active notifier is appended to the list
   1.155 +   {
   1.156 +       if (iAOList[i]->IsActive())
   1.157 +       {
   1.158 +           iAOList[i]->Cancel();
   1.159 +       }
   1.160 +       else
   1.161 +       {
   1.162 +           break;
   1.163 +       }
   1.164 +   }
   1.165 +   
   1.166 +
   1.167 +   
   1.168 +   PP_DEBUG(_L("CNGAPostProcSessionManager[%x]:CancelNotifiers() --"), this);
   1.169 +
   1.170 +	
   1.171 +	
   1.172 +}
   1.173 +
   1.174 +void CNGAPostProcSessionManager::HandleBufferRelease(TInt aBufId, TInt aStatus) 
   1.175 +{ 
   1.176 +   PP_DEBUG(_L("CNGAPostProcSessionManager[%x]:HandleBufferRelease() ++"), this);
   1.177 +    if(iObserver)
   1.178 +    {
   1.179 +		iObserver->BufferAvailable(aBufId, aStatus);
   1.180 +	}
   1.181 +   PP_DEBUG(_L("CNGAPostProcSessionManager[%x]:HandleBufferRelease() --"), this);
   1.182 +}
   1.183 +
   1.184 +void CNGAPostProcSessionManager::SetObserver(MNGAPostProcSessionManagerObserver& aObserver) 
   1.185 +{ 
   1.186 +   PP_DEBUG(_L("CNGAPostProcSessionManager[%x]:SetClockSource() ++"), this);
   1.187 +	iObserver = &aObserver;
   1.188 +   PP_DEBUG(_L("CNGAPostProcSessionManager[%x]:SetClockSource() --"), this);
   1.189 +}
   1.190 +