sl@0: /* sl@0: * Copyright (c) 2006 Nokia Corporation and/or its subsidiary(-ies). sl@0: * All rights reserved. sl@0: * This component and the accompanying materials are made available sl@0: * under the terms of "Eclipse Public License v1.0" sl@0: * which accompanies this distribution, and is available sl@0: * at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: * sl@0: * Initial Contributors: sl@0: * Nokia Corporation - initial contribution. sl@0: * sl@0: * Contributors: sl@0: * sl@0: * Description: sl@0: * sl@0: */ sl@0: sl@0: sl@0: #include sl@0: #include //RSurfaceUpdateSession sl@0: #include //RSurfaceManager sl@0: #include //KAllScreens sl@0: sl@0: #include "NGAPostProcSessionManager.h" sl@0: #include "NGAPostProcSessionManagerObserver.h" sl@0: #include "MdfRDebug.h" sl@0: #include "NGAPostProcNotifier.h" sl@0: sl@0: // --- Constants --- sl@0: const TInt KMessageSlots = 4; sl@0: sl@0: //************************************************** sl@0: sl@0: CNGAPostProcSessionManager* CNGAPostProcSessionManager::NewL() sl@0: { sl@0: PP_DEBUG(_L("CNGAPostProcSessionManager:NewL() ++")); sl@0: sl@0: CNGAPostProcSessionManager* self = new (ELeave) CNGAPostProcSessionManager; sl@0: CleanupStack::PushL(self); sl@0: self->ConstructL(); sl@0: CleanupStack::Pop(); sl@0: sl@0: PP_DEBUG(_L("CNGAPostProcSessionManager:NewL() --")); sl@0: return self; sl@0: } sl@0: sl@0: CNGAPostProcSessionManager::CNGAPostProcSessionManager() sl@0: :iSurfaceUpdateSession(NULL), sl@0: iObserver(NULL) sl@0: sl@0: { sl@0: } sl@0: sl@0: void CNGAPostProcSessionManager::ConstructL() sl@0: { sl@0: PP_DEBUG(_L("CNGAPostProcSessionManager[%x]:ConstructL() ++"), this); sl@0: sl@0: iSurfaceUpdateSession = new (ELeave) RSurfaceUpdateSession(); sl@0: User::LeaveIfError(iSurfaceUpdateSession->Connect(KMessageSlots)); sl@0: sl@0: PP_DEBUG(_L("CNGAPostProcSessionManager[%x]:ConstructL() --"), this); sl@0: } sl@0: sl@0: void CNGAPostProcSessionManager::CreateNotifierL(TInt aNumSurfaceBuffers) sl@0: { sl@0: PP_DEBUG(_L("CNGAPostProcSessionManager[%x]:CreateNotifierL() ++"), this); sl@0: sl@0: CNGAPostProcNotifier* notifier; sl@0: for(TInt index = 0; index < aNumSurfaceBuffers; ++index) sl@0: { sl@0: notifier = CNGAPostProcNotifier::NewL(*this); sl@0: CleanupStack::PushL(notifier); sl@0: sl@0: iAOList.AppendL(notifier); sl@0: sl@0: CleanupStack::Pop(); sl@0: } sl@0: PP_DEBUG(_L("CNGAPostProcSessionManager[%x]:CreateNotifierL() --"), this); sl@0: } sl@0: sl@0: CNGAPostProcSessionManager::~CNGAPostProcSessionManager() sl@0: { sl@0: PP_DEBUG(_L("CNGAPostProcSessionManager[%x]:~() ++"), this); sl@0: //Its safer to destry notifiers before surfaceupdatesession object since notifiers sl@0: //guarantee synchronous cancellation. sl@0: iAOList.ResetAndDestroy(); sl@0: sl@0: if(iSurfaceUpdateSession) sl@0: { sl@0: CancelUpdate(); sl@0: iSurfaceUpdateSession->Close(); sl@0: delete iSurfaceUpdateSession; sl@0: iSurfaceUpdateSession = NULL; sl@0: } sl@0: sl@0: sl@0: PP_DEBUG(_L("CNGAPostProcSessionManager[%x]:~() --"), this); sl@0: } sl@0: sl@0: TInt CNGAPostProcSessionManager::PostPicture(const TSurfaceId& aSurfaceId, sl@0: TInt aBufId, TBool aNotifyRequired) sl@0: { sl@0: PP_DEBUG(_L("CNGAPostProcSessionManager[%x]:PostPicture() ++"), this); sl@0: TInt err = KErrNone; sl@0: if(aNotifyRequired) sl@0: { sl@0: CNGAPostProcNotifier* notifier = NULL; sl@0: for(TInt j=0; j < iAOList.Count(); j++) sl@0: { sl@0: //notifier = iAOList[j]; sl@0: if(!iAOList[j]->IsActive()) sl@0: { sl@0: notifier = iAOList[j]; sl@0: iAOList.Remove(j); sl@0: //iAOList.Compress(); //why this is required? may create fragmentation. sl@0: break; sl@0: } sl@0: } sl@0: if(!notifier) sl@0: { sl@0: sl@0: return KErrInUse; sl@0: sl@0: } sl@0: sl@0: notifier->SetBufferId(aBufId); sl@0: notifier->Activate(); sl@0: iSurfaceUpdateSession->NotifyWhenAvailable(notifier->iStatus); sl@0: iAOList.Append(notifier); sl@0: sl@0: sl@0: } sl@0: err = iSurfaceUpdateSession->SubmitUpdate(KAllScreens, aSurfaceId, aBufId); sl@0: sl@0: PP_DEBUG(_L("CNGAPostProcSessionManager[%x]:PostPicture() -- err = %d"), this, err); sl@0: return err; sl@0: } sl@0: sl@0: void CNGAPostProcSessionManager::CancelUpdate() sl@0: { sl@0: PP_DEBUG(_L("CNGAPostProcSessionManager[%x]:CancelUpdate() ++"), this); sl@0: iSurfaceUpdateSession->CancelAllUpdateNotifications(); sl@0: PP_DEBUG(_L("CNGAPostProcSessionManager[%x]:CancelUpdate() --"), this); sl@0: } sl@0: sl@0: void CNGAPostProcSessionManager::CancelNotifiers() sl@0: { sl@0: sl@0: PP_DEBUG(_L("CNGAPostProcSessionManager[%x]:CancelNotifiers() ++"), this); sl@0: TInt notifierCount = iAOList.Count(); sl@0: for (TInt i = notifierCount - 1; i >= 0; --i) //reverse loop since the active notifier is appended to the list sl@0: { sl@0: if (iAOList[i]->IsActive()) sl@0: { sl@0: iAOList[i]->Cancel(); sl@0: } sl@0: else sl@0: { sl@0: break; sl@0: } sl@0: } sl@0: sl@0: sl@0: sl@0: PP_DEBUG(_L("CNGAPostProcSessionManager[%x]:CancelNotifiers() --"), this); sl@0: sl@0: sl@0: sl@0: } sl@0: sl@0: void CNGAPostProcSessionManager::HandleBufferRelease(TInt aBufId, TInt aStatus) sl@0: { sl@0: PP_DEBUG(_L("CNGAPostProcSessionManager[%x]:HandleBufferRelease() ++"), this); sl@0: if(iObserver) sl@0: { sl@0: iObserver->BufferAvailable(aBufId, aStatus); sl@0: } sl@0: PP_DEBUG(_L("CNGAPostProcSessionManager[%x]:HandleBufferRelease() --"), this); sl@0: } sl@0: sl@0: void CNGAPostProcSessionManager::SetObserver(MNGAPostProcSessionManagerObserver& aObserver) sl@0: { sl@0: PP_DEBUG(_L("CNGAPostProcSessionManager[%x]:SetClockSource() ++"), this); sl@0: iObserver = &aObserver; sl@0: PP_DEBUG(_L("CNGAPostProcSessionManager[%x]:SetClockSource() --"), this); sl@0: } sl@0: