os/mm/mdfdevvideoextensions/nga_mdf_postprocessor_shai/src/NGAPostProcSessionManager.cpp
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200 (2012-06-15)
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
sl@0
     1
/*
sl@0
     2
* Copyright (c) 2006 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     3
* All rights reserved.
sl@0
     4
* This component and the accompanying materials are made available
sl@0
     5
* under the terms of "Eclipse Public License v1.0"
sl@0
     6
* which accompanies this distribution, and is available
sl@0
     7
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     8
*
sl@0
     9
* Initial Contributors:
sl@0
    10
* Nokia Corporation - initial contribution.
sl@0
    11
*
sl@0
    12
* Contributors:
sl@0
    13
*
sl@0
    14
* Description:
sl@0
    15
*
sl@0
    16
*/
sl@0
    17
sl@0
    18
sl@0
    19
#include <e32base.h>
sl@0
    20
#include <graphics/surfaceupdateclient.h> //RSurfaceUpdateSession
sl@0
    21
#include <graphics/surfacemanager.h> //RSurfaceManager
sl@0
    22
#include <graphics/suerror.h> //KAllScreens
sl@0
    23
 
sl@0
    24
#include "NGAPostProcSessionManager.h" 
sl@0
    25
#include "NGAPostProcSessionManagerObserver.h"
sl@0
    26
#include "MdfRDebug.h"
sl@0
    27
#include "NGAPostProcNotifier.h"
sl@0
    28
sl@0
    29
// --- Constants ---
sl@0
    30
const TInt KMessageSlots      = 4; 
sl@0
    31
sl@0
    32
//**************************************************
sl@0
    33
sl@0
    34
CNGAPostProcSessionManager* CNGAPostProcSessionManager::NewL() 
sl@0
    35
{ 
sl@0
    36
   PP_DEBUG(_L("CNGAPostProcSessionManager:NewL() ++"));
sl@0
    37
sl@0
    38
    CNGAPostProcSessionManager* self = new (ELeave) CNGAPostProcSessionManager; 
sl@0
    39
    CleanupStack::PushL(self);
sl@0
    40
    self->ConstructL(); 
sl@0
    41
    CleanupStack::Pop();
sl@0
    42
sl@0
    43
   PP_DEBUG(_L("CNGAPostProcSessionManager:NewL() --"));
sl@0
    44
    return self; 
sl@0
    45
}
sl@0
    46
sl@0
    47
CNGAPostProcSessionManager::CNGAPostProcSessionManager() 
sl@0
    48
:iSurfaceUpdateSession(NULL),
sl@0
    49
 iObserver(NULL)
sl@0
    50
 
sl@0
    51
{
sl@0
    52
}
sl@0
    53
sl@0
    54
void CNGAPostProcSessionManager::ConstructL() 
sl@0
    55
{ 
sl@0
    56
   PP_DEBUG(_L("CNGAPostProcSessionManager[%x]:ConstructL() ++"), this);
sl@0
    57
    
sl@0
    58
    iSurfaceUpdateSession = new (ELeave) RSurfaceUpdateSession();
sl@0
    59
    User::LeaveIfError(iSurfaceUpdateSession->Connect(KMessageSlots));
sl@0
    60
    
sl@0
    61
   PP_DEBUG(_L("CNGAPostProcSessionManager[%x]:ConstructL() --"), this);
sl@0
    62
}
sl@0
    63
sl@0
    64
void CNGAPostProcSessionManager::CreateNotifierL(TInt aNumSurfaceBuffers)
sl@0
    65
    {
sl@0
    66
    PP_DEBUG(_L("CNGAPostProcSessionManager[%x]:CreateNotifierL() ++"), this);
sl@0
    67
    
sl@0
    68
    CNGAPostProcNotifier* notifier;
sl@0
    69
    for(TInt index = 0; index < aNumSurfaceBuffers; ++index)
sl@0
    70
        {
sl@0
    71
        notifier = CNGAPostProcNotifier::NewL(*this);
sl@0
    72
        CleanupStack::PushL(notifier);
sl@0
    73
        
sl@0
    74
        iAOList.AppendL(notifier); 
sl@0
    75
        
sl@0
    76
        CleanupStack::Pop();
sl@0
    77
        }   
sl@0
    78
    PP_DEBUG(_L("CNGAPostProcSessionManager[%x]:CreateNotifierL() --"), this);
sl@0
    79
    }
sl@0
    80
sl@0
    81
CNGAPostProcSessionManager::~CNGAPostProcSessionManager()
sl@0
    82
{
sl@0
    83
   PP_DEBUG(_L("CNGAPostProcSessionManager[%x]:~() ++"), this);
sl@0
    84
   //Its safer to destry notifiers before surfaceupdatesession object since notifiers
sl@0
    85
   //guarantee synchronous cancellation.
sl@0
    86
   iAOList.ResetAndDestroy();
sl@0
    87
   
sl@0
    88
    if(iSurfaceUpdateSession)
sl@0
    89
    {
sl@0
    90
    	CancelUpdate();
sl@0
    91
    	iSurfaceUpdateSession->Close();
sl@0
    92
    	delete iSurfaceUpdateSession;
sl@0
    93
    	iSurfaceUpdateSession = NULL;
sl@0
    94
	}
sl@0
    95
    
sl@0
    96
    
sl@0
    97
   PP_DEBUG(_L("CNGAPostProcSessionManager[%x]:~() --"), this);
sl@0
    98
}
sl@0
    99
sl@0
   100
TInt CNGAPostProcSessionManager::PostPicture(const TSurfaceId& aSurfaceId,
sl@0
   101
								TInt aBufId, TBool aNotifyRequired) 
sl@0
   102
{ 
sl@0
   103
   PP_DEBUG(_L("CNGAPostProcSessionManager[%x]:PostPicture() ++"), this);
sl@0
   104
   TInt err = KErrNone;
sl@0
   105
	if(aNotifyRequired)
sl@0
   106
	{
sl@0
   107
	    CNGAPostProcNotifier* notifier = NULL;
sl@0
   108
		for(TInt j=0; j < iAOList.Count(); j++)
sl@0
   109
		{
sl@0
   110
            //notifier = iAOList[j];
sl@0
   111
            if(!iAOList[j]->IsActive())
sl@0
   112
            {
sl@0
   113
                notifier = iAOList[j];
sl@0
   114
                iAOList.Remove(j);
sl@0
   115
                //iAOList.Compress(); //why this is required? may create fragmentation.
sl@0
   116
                break;
sl@0
   117
            }
sl@0
   118
		}
sl@0
   119
		if(!notifier)
sl@0
   120
		{
sl@0
   121
			
sl@0
   122
			return KErrInUse;
sl@0
   123
	        
sl@0
   124
		}
sl@0
   125
		
sl@0
   126
		notifier->SetBufferId(aBufId);
sl@0
   127
		notifier->Activate();
sl@0
   128
		iSurfaceUpdateSession->NotifyWhenAvailable(notifier->iStatus);
sl@0
   129
		iAOList.Append(notifier);
sl@0
   130
		
sl@0
   131
		
sl@0
   132
	}
sl@0
   133
	err = iSurfaceUpdateSession->SubmitUpdate(KAllScreens, aSurfaceId, aBufId);
sl@0
   134
sl@0
   135
   PP_DEBUG(_L("CNGAPostProcSessionManager[%x]:PostPicture() -- err = %d"), this, err);
sl@0
   136
   return err;
sl@0
   137
}
sl@0
   138
sl@0
   139
void CNGAPostProcSessionManager::CancelUpdate() 
sl@0
   140
{ 
sl@0
   141
   PP_DEBUG(_L("CNGAPostProcSessionManager[%x]:CancelUpdate() ++"), this);
sl@0
   142
	iSurfaceUpdateSession->CancelAllUpdateNotifications();
sl@0
   143
   PP_DEBUG(_L("CNGAPostProcSessionManager[%x]:CancelUpdate() --"), this);
sl@0
   144
}
sl@0
   145
sl@0
   146
void CNGAPostProcSessionManager::CancelNotifiers() 
sl@0
   147
{ 
sl@0
   148
    
sl@0
   149
   PP_DEBUG(_L("CNGAPostProcSessionManager[%x]:CancelNotifiers() ++"), this);
sl@0
   150
   TInt notifierCount = iAOList.Count();
sl@0
   151
   for (TInt i = notifierCount - 1; i >= 0; --i) //reverse loop since the active notifier is appended to the list
sl@0
   152
   {
sl@0
   153
       if (iAOList[i]->IsActive())
sl@0
   154
       {
sl@0
   155
           iAOList[i]->Cancel();
sl@0
   156
       }
sl@0
   157
       else
sl@0
   158
       {
sl@0
   159
           break;
sl@0
   160
       }
sl@0
   161
   }
sl@0
   162
   
sl@0
   163
sl@0
   164
   
sl@0
   165
   PP_DEBUG(_L("CNGAPostProcSessionManager[%x]:CancelNotifiers() --"), this);
sl@0
   166
sl@0
   167
	
sl@0
   168
	
sl@0
   169
}
sl@0
   170
sl@0
   171
void CNGAPostProcSessionManager::HandleBufferRelease(TInt aBufId, TInt aStatus) 
sl@0
   172
{ 
sl@0
   173
   PP_DEBUG(_L("CNGAPostProcSessionManager[%x]:HandleBufferRelease() ++"), this);
sl@0
   174
    if(iObserver)
sl@0
   175
    {
sl@0
   176
		iObserver->BufferAvailable(aBufId, aStatus);
sl@0
   177
	}
sl@0
   178
   PP_DEBUG(_L("CNGAPostProcSessionManager[%x]:HandleBufferRelease() --"), this);
sl@0
   179
}
sl@0
   180
sl@0
   181
void CNGAPostProcSessionManager::SetObserver(MNGAPostProcSessionManagerObserver& aObserver) 
sl@0
   182
{ 
sl@0
   183
   PP_DEBUG(_L("CNGAPostProcSessionManager[%x]:SetClockSource() ++"), this);
sl@0
   184
	iObserver = &aObserver;
sl@0
   185
   PP_DEBUG(_L("CNGAPostProcSessionManager[%x]:SetClockSource() --"), this);
sl@0
   186
}
sl@0
   187