graphicscompositionref/surfacemgrcommon/src/extension.cpp
author Gareth Stockwell <gareth.stockwell@accenture.com>
Fri, 24 Sep 2010 13:54:59 +0100
branchbug235_bringup_0
changeset 2 47632b7dfb88
parent 0 91fe342bd9c4
permissions -rwxr-xr-x
Refactoring of frame buffer references to surface buffer
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
     1
// Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
     2
// All rights reserved.
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
     3
// This component and the accompanying materials are made available
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
     4
// under the terms of "Eclipse Public License v1.0"
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
     5
// which accompanies this distribution, and is available
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
     6
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
     7
//
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
     8
// Initial Contributors:
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
     9
// Nokia Corporation - initial contribution.
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
    10
//
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
    11
// Contributors:
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
    12
//
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
    13
// Description:
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
    14
//
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
    15
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
    16
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
    17
#include <kernel/kern_priv.h>
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
    18
#include <kernel/cache.h>
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
    19
#include <graphics/surface.h>
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
    20
#include <graphics/surfacetypes.h>
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
    21
#include <graphics/surfacemanager.h>
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
    22
#include "surfacemanager_dev.h"
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
    23
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
    24
/**
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
    25
Convert the surface Id to an index of the array 
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
    26
based on the least significant 4 bits of the first word of the ID
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
    27
@param	aSurfaceId  Const reference to the surface Id
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
    28
@internalTechnology
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
    29
*/
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
    30
static TInt SurfaceIdToIndex(const TSurfaceId& aSurfaceId)
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
    31
	{
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
    32
	return static_cast<TInt>(aSurfaceId.iInternal[0]&(KMaxLists-1));
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
    33
	}
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
    34
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
    35
/**
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
    36
Removes an item from a linked list
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
    37
@param	aList  Pointer to the head of a linked list of type T
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
    38
@param	aOwner  Pointer to the object to be removed
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
    39
@internalTechnology
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
    40
*/
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
    41
template<class T>
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
    42
static void UnlinkListItem(T** aList, const T* aItem)
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
    43
	{
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
    44
	TRACE(Kern::Printf("SM UnlinkListItem list %08x  object %08x \n", aList, aItem);)
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
    45
	
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
    46
	__ASSERT_DEBUG(aItem != NULL, Kern::Fault("Surface Manager", __LINE__));
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
    47
	__ASSERT_DEBUG(*aList != NULL, Kern::Fault("Surface Manager", __LINE__));
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
    48
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
    49
	if (*aList == aItem)	//one we want is at the head of the list
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
    50
		{
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
    51
		*aList = aItem->iNext;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
    52
		return;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
    53
		}
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
    54
	
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
    55
	T* p = *aList;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
    56
	T* q = (*aList)->iNext;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
    57
	while (q)
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
    58
		{
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
    59
		if (q == aItem)
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
    60
			{
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
    61
			p->iNext = q->iNext;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
    62
			return;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
    63
			}
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
    64
		p = q;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
    65
		q = q->iNext;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
    66
		}
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
    67
	}
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
    68
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
    69
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
    70
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
    71
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
    72
/**
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
    73
Returns a pointer to the surface owner object for the specified process, for this surface.
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
    74
@param	aProcess  Pointer to the process object
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
    75
@return pointer to the surface owner object if found, else NULL
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
    76
@internalTechnology
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
    77
*/
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
    78
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
    79
TProcessListItem* TSurface::ProcessOwnerInfo(const DProcess* aProcess)
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
    80
	{
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
    81
	TProcessListItem* so = iOwners;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
    82
	while(so)
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
    83
		{
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
    84
		if (aProcess == so->iOwningProcess)
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
    85
			{
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
    86
			break;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
    87
			}
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
    88
		so = so->iNext;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
    89
		}
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
    90
	return so;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
    91
	}
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
    92
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
    93
/**
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
    94
Creates a shared chunk surface.
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
    95
@param aParams  Package buffer containing the surface creation parameters.  
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
    96
@param aId  Will be set to the surface id of the newly created surface.
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
    97
@return KErrNone if successful, KErrArgument if the creation attributes were incorrect,
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
    98
otherwise one of the other system wide error codes.
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
    99
@see RSurfaceManager::TSurfaceCreationAttributes
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   100
@internalTechnology
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   101
*/
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   102
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   103
TInt DSurfaceManager::CreateSurface(const TDesC8* aParams, TSurfaceId* aId)
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   104
	{
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   105
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   106
	RSurfaceManager::TSurfaceCreationAttributesBuf buf;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   107
	RSurfaceManager::TSurfaceCreationAttributes& attribs = buf();
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   108
	
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   109
	Kern::KUDesGet(buf, *aParams);		//fetch input parameters
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   110
	if( (attribs.iHintCount > KMaxHintsPerSurface) || (attribs.iHintCount<0) )
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   111
		{
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   112
		return KErrArgument;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   113
		}	
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   114
	
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   115
	RSurfaceManager::THintPair tempSurfaceHints[KMaxHintsPerSurface];
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   116
	if( (attribs.iHintCount>0) && attribs.iSurfaceHints)
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   117
		{
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   118
		kumemget(tempSurfaceHints, attribs.iSurfaceHints, attribs.iHintCount*sizeof(RSurfaceManager::THintPair));		
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   119
		attribs.iSurfaceHints = tempSurfaceHints;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   120
		}
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   121
	else
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   122
		{
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   123
		attribs.iSurfaceHints=NULL;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   124
		}
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   125
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   126
	//validate input parameters and calculate chunk size
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   127
	TInt roundedBufferSize = attribs.iOffsetBetweenBuffers;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   128
	TUint dummyActualSize = 0;	
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   129
	
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   130
	TInt chunkSize = ValidateAndCalculateChunkSize(attribs, roundedBufferSize, dummyActualSize, ETrue);
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   131
	if (chunkSize == 0)
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   132
		{
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   133
		return KErrArgument;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   134
		}	
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   135
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   136
	TSurfaceId sid;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   137
	TInt r = KErrNone;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   138
	TSurface* surface = NULL;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   139
	do		//in the unlikely event that we generate a duplicate surface id, try again.
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   140
		{
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   141
		GenerateSurfaceId(sid);
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   142
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   143
		NKern::FMWait(&iMutex);
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   144
		surface = FindSurfaceById(sid);
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   145
		NKern::FMSignal(&iMutex);
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   146
		}
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   147
	while (surface);
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   148
	
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   149
	//create a shared chunk for the surface memory
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   150
	TChunkCreateInfo info;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   151
	info.iType = TChunkCreateInfo::ESharedKernelMultiple;	//multi process mappable
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   152
	info.iMaxSize = chunkSize;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   153
	info.iOwnsMemory = ETrue;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   154
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   155
//iMapAttr is valid only for hardware devices and will not make any effect in wins	
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   156
#ifndef __WINS__
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   157
	info.iMapAttr = (attribs.iCacheAttrib == RSurfaceManager::ECached) ? EMapAttrCachedMax : EMapAttrL1Uncached;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   158
#else
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   159
	info.iMapAttr = 0;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   160
#endif
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   161
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   162
#ifdef GRAPHICS_SURFACEMANAGER_SYBORG
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   163
	// ChunkCommitPhysical method may only be used if the chunk was
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   164
	// created with TChunkCreateInfo::iOwnsMemory set to false.
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   165
    info.iMapAttr = EMapAttrFullyBlocking;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   166
    info.iOwnsMemory = EFalse;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   167
#endif
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   168
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   169
	TLinAddr kernAddr;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   170
	TUint32 mapAttr;	
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   171
	
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   172
	NKern::ThreadEnterCS();
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   173
	DChunk* chunk;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   174
	r = Kern::ChunkCreate(info, chunk, kernAddr, mapAttr);
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   175
	if (KErrNone != r)
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   176
		{
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   177
		NKern::ThreadLeaveCS();
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   178
		return r;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   179
		}
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   180
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   181
	//commit the memory
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   182
	TUint32 paddr;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   183
#ifdef GRAPHICS_SURFACEMANAGER_SYBORG 
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   184
    Kern::Printf("DSurfaceManager::CreateSurface: Allocate ");
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   185
    if( iVHWMemoryManager != NULL )
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   186
		{
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   187
	    paddr = iVHWMemoryManager->Allocate(chunkSize);
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   188
		}
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   189
	else
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   190
		{
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   191
		CreateMemory();
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   192
	    paddr = iVHWMemoryManager->Allocate(chunkSize);
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   193
		}
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   194
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   195
    
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   196
    if ( paddr )
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   197
        {
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   198
        r = Kern::ChunkCommitPhysical( chunk, 0, chunkSize, paddr );
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   199
	    Kern::Printf("DSurfaceManager::CreateSurface: Commit %d from: 0x%08x success: %d",chunkSize, paddr, r );
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   200
        }
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   201
    else
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   202
        {
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   203
        r = KErrNoMemory;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   204
        }
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   205
#else // GRAPHICS_SURFACEMANAGER_SYBORG
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   206
	if (attribs.iContiguous)
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   207
		{
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   208
		r = Kern::ChunkCommitContiguous(chunk, 0, chunkSize, paddr);
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   209
		}
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   210
	else
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   211
		{
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   212
		r = Kern::ChunkCommit(chunk, 0, chunkSize);
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   213
		}
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   214
#endif // GRAPHICS_SURFACEMANAGER_SYBORG
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   215
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   216
	if (KErrNone != r)
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   217
		{
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   218
		//problem committing the memory,
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   219
		//destroy the chunk and cleanup
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   220
		Kern::ChunkClose(chunk);
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   221
		NKern::ThreadLeaveCS();
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   222
		return r;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   223
		}
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   224
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   225
	//create a surface structure for the new surface
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   226
	surface = new TSurface;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   227
	TRACE(Kern::Printf("SM A %08x TSurface CreateSurface",surface);)
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   228
	if (!surface)
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   229
		{
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   230
		//destroy the chunk and cleanup, out of memory
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   231
		Kern::ChunkClose(chunk);
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   232
		NKern::ThreadLeaveCS();
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   233
		return KErrNoMemory;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   234
		}
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   235
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   236
	surface->iId = sid;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   237
	surface->iSize = attribs.iSize;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   238
	surface->iBuffers = attribs.iBuffers;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   239
	surface->iPixelFormat = attribs.iPixelFormat;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   240
	surface->iStride = attribs.iStride;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   241
	surface->iOffsetToFirstBuffer = attribs.iOffsetToFirstBuffer;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   242
	surface->iAlignment = attribs.iAlignment;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   243
	surface->iContiguous = attribs.iContiguous;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   244
	surface->iChunk = chunk;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   245
	surface->iOffsetBetweenBuffers = roundedBufferSize;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   246
	surface->iCacheAttrib = attribs.iCacheAttrib;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   247
	surface->iMappable = attribs.iMappable;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   248
	if(attribs.iHintCount>0)
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   249
		{
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   250
		memcpy(surface->iSurfaceHints,tempSurfaceHints,attribs.iHintCount*sizeof(RSurfaceManager::THintPair));
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   251
		}
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   252
	memclr(surface->iSurfaceHints+attribs.iHintCount, (KMaxHintsPerSurface-attribs.iHintCount)*sizeof(RSurfaceManager::THintPair));
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   253
	
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   254
	//create a surface owner for this surface
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   255
	TProcessListItem* owner = new TProcessListItem;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   256
	TRACE(Kern::Printf("SM A %08x TProcessListItem CreateSurface",owner);)
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   257
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   258
	if (!owner)
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   259
		{
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   260
		//destroy the chunk and cleanup, out of memory
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   261
		Kern::ChunkClose(chunk);
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   262
		delete(surface);
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   263
		TRACE(Kern::Printf("SM D %08x TSurface CreateSurface",surface);)
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   264
		NKern::ThreadLeaveCS();
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   265
		return KErrNoMemory;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   266
		}
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   267
	
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   268
	owner->iCount = 1;		//mark it as open in this process
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   269
	owner->iOwningProcess =  &Kern::CurrentProcess();
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   270
	owner->iNext = NULL;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   271
		
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   272
	surface->iOwners = owner;	//only 1 owner at creation time
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   273
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   274
	//at this point we have a fully constructed TSurface
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   275
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   276
	//add surface to head of surfaces list
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   277
	NKern::FMWait(&iMutex);
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   278
	//Mask off the bottom log2(KMaxLists) bits of the first word of the surfaceID as an index
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   279
	//add the new surface to the beginning of the list 
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   280
	TInt index = SurfaceIdToIndex(sid);
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   281
	surface->iNext = iSurfacesIndex[index];
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   282
	iSurfacesIndex[index] = surface;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   283
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   284
	NKern::FMSignal(&iMutex);		
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   285
	NKern::ThreadLeaveCS();
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   286
	
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   287
	//write surface id back to user side
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   288
	kumemput(aId, &sid, sizeof (TSurfaceId));
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   289
	return KErrNone;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   290
	}
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   291
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   292
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   293
/**
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   294
Validate that a chunk contains physical memory for the used areas.
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   295
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   296
This function should be called in Critical Section in order to be completed even if the thread 
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   297
or process is killed and so be able to free the memory allocated  (TUint32[pageList])
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   298
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   299
@param aChunk  Chunk that the user supplied.   
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   300
@param aAttribs  Surface Creation Attributes.
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   301
@param aBuffersize  Calculated size of each buffer.
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   302
@param aMapAttr  Filled in with the mapping attributes of the memory.
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   303
@param aIsContiguous  Lets the caller know if the surface is physically contiguous or not. 
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   304
@return KErrNone if successful, KErrArgument if the creation attributes were incorrect,
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   305
KErrBadHandle if aChunkHandle is of an invalid shared chunk memory,
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   306
otherwise one of the other system wide error codes.
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   307
@see RSurfaceManager::TSurfaceCreationAttributes
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   308
@internalTechnology
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   309
*/
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   310
TInt DSurfaceManager::ValidatePhysicalMemory(DChunk* aChunk, const RSurfaceManager::TSurfaceCreationAttributes& aAttribs, 
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   311
								   TUint aBuffersize, TUint32& aMapAttr, TBool &aIsContiguous) 
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   312
	{
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   313
	TLinAddr kernAddr;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   314
	TUint32 physAddr;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   315
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   316
	//Get the physical address for a region in a shared chunk
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   317
	TInt pageSize = Kern::RoundToPageSize(1);
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   318
	TInt pageList = 1 + (aChunk->iSize + pageSize - 2) / pageSize;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   319
	TUint32* physAddr2 = new TUint32[pageList];
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   320
	if(!physAddr2)
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   321
		{
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   322
		return KErrNoMemory;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   323
		}
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   324
	
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   325
	// Unless proven otherwise, the memory is not contiguous. 
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   326
	aIsContiguous = EFalse;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   327
	TInt r = Kern::ChunkPhysicalAddress(aChunk, 0, aChunk->iSize, kernAddr, aMapAttr, physAddr, physAddr2);
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   328
	if (KErrNone == r)
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   329
		{
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   330
		aIsContiguous = ETrue;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   331
		}
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   332
	
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   333
	
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   334
	TRACE(Kern::Printf("SM CreateSurface ChunkPhysicalAddress r %d chunk %08x chunk size %d", r, aChunk, aChunk->iSize);)
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   335
	TRACE(Kern::Printf("SM CreateSurface kernAddr %08x", kernAddr);)
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   336
	TRACE(Kern::Printf("SM CreateSurface mapAttr %08x", aMapAttr);)
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   337
	TRACE(Kern::Printf("SM CreateSurface physAddr %08x", physAddr);)
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   338
	TRACE(Kern::Printf("SM CreateSurface physAddr2 %08x", physAddr2);)
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   339
	
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   340
	if(r < KErrNone)
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   341
		{
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   342
		// Error means that there isn't memory in the whole chunk - so check the
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   343
		// relevant areas - it is allowed to have gaps between the buffers, but not 
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   344
		// within the actual regions that are used for buffers. 
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   345
		
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   346
		// So, we first check the area before first buffer up to "offsettofirstbuffer", which all should be valid
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   347
		if (aAttribs.iOffsetToFirstBuffer != 0)
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   348
			{
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   349
			r = Kern::ChunkPhysicalAddress(aChunk, 0, aAttribs.iOffsetToFirstBuffer, 
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   350
					kernAddr, aMapAttr, physAddr, physAddr2);
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   351
			}
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   352
		else
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   353
			{
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   354
			r = KErrNone;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   355
			}
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   356
		
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   357
		// If that's a pass, loop through and check the actual buffers (leave loop if it fails).
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   358
		for(TInt i = 0; i < aAttribs.iBuffers && KErrNone <= r; i++)
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   359
			{
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   360
			r = Kern::ChunkPhysicalAddress(aChunk, 
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   361
					aAttribs.iOffsetToFirstBuffer + aAttribs.iOffsetBetweenBuffers * i, 
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   362
					aBuffersize, kernAddr, aMapAttr, physAddr, physAddr2);
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   363
			}
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   364
		}
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   365
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   366
	// Fix up weird ChunkPhysicalAddress behaviour - it returns 1 to indicate that memory is non-contiguous. 
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   367
	if (1 == r)
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   368
		{
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   369
		r = KErrNone;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   370
		}
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   371
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   372
	delete[] physAddr2;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   373
	return r;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   374
	}
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   375
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   376
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   377
/**
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   378
Creates a surface in an existing shared chunk.
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   379
@param aParam  Package buf containing the surface creation parameters and id to be set to the surface id of the newly created surface.  
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   380
@param aChunkHandle  Existing valid shared chunk handle.
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   381
@return KErrNone if successful, KErrArgument if the creation attributes were incorrect,
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   382
KErrBadHandle if aChunkHandle is of an invalid shared chunk memory,
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   383
otherwise one of the other system wide error codes.
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   384
@see RSurfaceManager::TSurfaceCreationAttributes
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   385
@internalTechnology
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   386
*/
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   387
TInt DSurfaceManager::CreateSurface(RSurfaceManagerDriver::TDeviceParam* aParam, TInt aChunkHandle)
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   388
	{
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   389
	RSurfaceManager::TSurfaceCreationAttributesBuf buf;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   390
	RSurfaceManager::TSurfaceCreationAttributes& attribs = buf();
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   391
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   392
	//Get the input parameters
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   393
	RSurfaceManagerDriver::TDeviceParam param;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   394
	kumemget(&param, aParam, sizeof(RSurfaceManagerDriver::TDeviceParam));
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   395
	Kern::KUDesGet(buf, *(reinterpret_cast<const TDesC8*>(param.iBuffer)));
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   396
	if( (attribs.iHintCount > KMaxHintsPerSurface) || (attribs.iHintCount<0) )
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   397
		{
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   398
		return KErrArgument;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   399
		}	
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   400
	
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   401
	RSurfaceManager::THintPair tempSurfaceHints[KMaxHintsPerSurface];
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   402
	if( (attribs.iHintCount>0) && attribs.iSurfaceHints)
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   403
		{
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   404
		kumemget(tempSurfaceHints, attribs.iSurfaceHints, attribs.iHintCount*sizeof(RSurfaceManager::THintPair));		
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   405
		attribs.iSurfaceHints = tempSurfaceHints;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   406
		}
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   407
	else
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   408
		{
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   409
		attribs.iSurfaceHints=NULL;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   410
		}
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   411
		
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   412
	//validate input parameters and calc size
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   413
	TInt roundedBufferSize = attribs.iOffsetBetweenBuffers;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   414
	TUint actualBufferSize = 0;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   415
	TInt chunkSize = ValidateAndCalculateChunkSize(attribs, roundedBufferSize, actualBufferSize);
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   416
	if (chunkSize == 0)
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   417
		{
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   418
		return KErrArgument;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   419
		}
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   420
	
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   421
	NKern::ThreadEnterCS();
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   422
	
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   423
	//Open an existing shared chunk
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   424
	DChunk* chunk = Kern::OpenSharedChunk(NULL, aChunkHandle, EFalse);
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   425
	if(chunk == NULL)
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   426
		{
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   427
		NKern::ThreadLeaveCS();
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   428
		return KErrBadHandle;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   429
		}
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   430
	
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   431
	//Check for chunk type as kernel multiple
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   432
	if(chunk->iChunkType != ESharedKernelMultiple)
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   433
		{
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   434
		Kern::ChunkClose(chunk);
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   435
		NKern::ThreadLeaveCS();
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   436
		return KErrBadHandle;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   437
		}
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   438
	
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   439
	//Check for enough chunk size to create surface for requested attributes
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   440
	if (chunk->iSize < attribs.iOffsetToFirstBuffer + attribs.iBuffers * actualBufferSize)
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   441
		{
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   442
		Kern::ChunkClose(chunk);
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   443
		NKern::ThreadLeaveCS();
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   444
		return KErrArgument;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   445
		}
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   446
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   447
	TSurfaceId sid;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   448
	TSurface* surface = NULL;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   449
	do		//in the unlikely event that we generate a duplicate surface id, try again.
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   450
		{
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   451
		GenerateSurfaceId(sid);
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   452
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   453
		NKern::FMWait(&iMutex);
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   454
		surface = FindSurfaceById(sid);
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   455
		NKern::FMSignal(&iMutex);
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   456
		}
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   457
	while (surface);
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   458
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   459
	//create a surface structure for the new surface
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   460
	surface = new TSurface;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   461
	TRACE(Kern::Printf("SM A %08x TSurface CreateSurface",surface);)
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   462
	if (!surface)
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   463
		{
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   464
		//destroy the chunk and cleanup, out of memory
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   465
		Kern::ChunkClose(chunk);
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   466
		NKern::ThreadLeaveCS();
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   467
		return KErrNoMemory;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   468
		}
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   469
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   470
	TUint32 mapAttr = 0;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   471
	TBool isContiguous;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   472
	TInt r = ValidatePhysicalMemory(chunk, attribs, actualBufferSize, mapAttr, isContiguous);
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   473
	if (r != KErrNone)
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   474
		{
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   475
		//destroy the surface and close the chunk
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   476
		delete(surface);
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   477
		Kern::ChunkClose(chunk);
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   478
		NKern::ThreadLeaveCS();
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   479
		if (r != KErrNoMemory)
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   480
			{
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   481
			r = KErrArgument;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   482
			}
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   483
		return r;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   484
		}
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   485
	
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   486
	surface->iId = sid;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   487
	surface->iSize = attribs.iSize;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   488
	surface->iBuffers = attribs.iBuffers;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   489
	surface->iPixelFormat = attribs.iPixelFormat;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   490
	surface->iStride = attribs.iStride;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   491
	surface->iOffsetToFirstBuffer = attribs.iOffsetToFirstBuffer;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   492
	surface->iAlignment = attribs.iAlignment;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   493
	surface->iContiguous = isContiguous;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   494
	surface->iChunk = chunk;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   495
	surface->iOffsetBetweenBuffers = (attribs.iOffsetBetweenBuffers) ? attribs.iOffsetBetweenBuffers : roundedBufferSize;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   496
	surface->iMappable = attribs.iMappable;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   497
#ifndef __WINS__	//Creation attribute field will not considered for iCacheAttrib
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   498
	TUint32 level1Info = mapAttr & EMapAttrL1CacheMask;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   499
	TUint32 level2Info = mapAttr & EMapAttrL2CacheMask;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   500
	TBool chunkIsNotcached =  ((level2Info == EMapAttrL2Uncached) && 
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   501
	    ((level1Info == EMapAttrFullyBlocking) || (level1Info == EMapAttrBufferedNC) ||
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   502
	     (level1Info == EMapAttrBufferedC) || (level1Info == EMapAttrL1Uncached)));
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   503
	surface->iCacheAttrib = (chunkIsNotcached) ? RSurfaceManager::ENotCached : RSurfaceManager::ECached;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   504
#else
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   505
	surface->iCacheAttrib = RSurfaceManager::ENotCached;	
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   506
#endif
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   507
	
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   508
	if(attribs.iHintCount>0)
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   509
		{
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   510
		memcpy(surface->iSurfaceHints,tempSurfaceHints,attribs.iHintCount*sizeof(RSurfaceManager::THintPair));
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   511
		}
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   512
	memclr(surface->iSurfaceHints+attribs.iHintCount, (KMaxHintsPerSurface-attribs.iHintCount)*sizeof(RSurfaceManager::THintPair));
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   513
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   514
	//create a surface owner for this surface
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   515
	TProcessListItem* owner = new TProcessListItem;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   516
	TRACE(Kern::Printf("SM A %08x TProcessListItem CreateSurface",owner);)
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   517
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   518
	if (!owner)
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   519
		{
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   520
		//destroy the chunk and cleanup, out of memory
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   521
		Kern::ChunkClose(chunk);
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   522
		delete(surface);
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   523
		TRACE(Kern::Printf("SM D %08x TSurface CreateSurface",surface);)
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   524
		NKern::ThreadLeaveCS();
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   525
		return KErrNoMemory;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   526
		}
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   527
	
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   528
	owner->iCount = 1;		//mark it as open in this process
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   529
	owner->iOwningProcess =  &Kern::CurrentProcess();
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   530
	owner->iNext = NULL;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   531
		
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   532
	surface->iOwners = owner;	//only 1 owner at creation time
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   533
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   534
	NKern::FMWait(&iMutex);
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   535
	//at this point we have a fully constructed TSurface
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   536
	//add surface to head of surfaces list
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   537
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   538
	//Mask off the bottom log2(KMaxLists) bits of the first word of the surfaceID as an index
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   539
	//add the new surface to the beginning of the list 
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   540
	TInt index = SurfaceIdToIndex(sid);
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   541
	surface->iNext = iSurfacesIndex[index];
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   542
	iSurfacesIndex[index] = surface;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   543
	NKern::FMSignal(&iMutex);		
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   544
	NKern::ThreadLeaveCS();
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   545
	
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   546
	//write surface id back to user side
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   547
	kumemput(reinterpret_cast<TSurfaceId*>(param.iSurfaceId), &sid, sizeof (TSurfaceId));
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   548
	return KErrNone;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   549
	}
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   550
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   551
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   552
/**
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   553
Opens a surface.  If the current process already is in the owners list, its usage count is
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   554
incremented.  If this is an open from a different process, a new surface owner object is added
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   555
to the surface's list of owners and its usage count is set to 1.
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   556
@param aId  The surface id of the surface to be opened.
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   557
@return KErrNone if successful, otherwise a system error code
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   558
@internalTechnology
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   559
*/
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   560
TInt DSurfaceManager::OpenSurface(const TSurfaceId* aId)
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   561
	{
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   562
	TSurfaceId sid;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   563
	//fetch surface id from user memory
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   564
	kumemget(&sid, aId, sizeof (TSurfaceId));
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   565
	NKern::ThreadEnterCS();
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   566
	TProcessListItem* owner = new TProcessListItem;  //speculative creation
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   567
	TRACE(Kern::Printf("SM A %08x TProcessListItem OpenSurface", owner);)
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   568
	
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   569
	NKern::FMWait(&iMutex);
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   570
	//look it up
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   571
	TSurface* surface = FindSurfaceById(sid);
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   572
	if (!surface)	
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   573
		{
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   574
		NKern::FMSignal(&iMutex);
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   575
		delete owner;		//free the memory just allocated
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   576
		TRACE(Kern::Printf("SM D %08x TProcessListItem OpenSurface", owner);)
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   577
		NKern::ThreadLeaveCS();
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   578
		return KErrArgument;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   579
		}
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   580
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   581
	//find the owner
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   582
	TProcessListItem* so = surface->ProcessOwnerInfo(&Kern::CurrentProcess());
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   583
	if (so)
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   584
		{
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   585
		//already an owner so inc the ref count
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   586
		++so->iCount;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   587
		}
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   588
	else
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   589
		{
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   590
		//new process trying to open it
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   591
		if (!owner)
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   592
			{
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   593
			//the creation of the owner information object failed, out of memory
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   594
			NKern::FMSignal(&iMutex);
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   595
			NKern::ThreadLeaveCS();
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   596
			return KErrNoMemory;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   597
			}
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   598
			
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   599
		owner->iCount = 1;		//mark it open in this process
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   600
		owner->iOwningProcess =  &Kern::CurrentProcess();
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   601
		
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   602
		//add the owner to the list of owners
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   603
		owner->iNext = surface->iOwners;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   604
		surface->iOwners = owner;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   605
		owner = NULL;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   606
		}
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   607
	NKern::FMSignal(&iMutex);
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   608
	delete owner;		//free if not used.
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   609
	TRACE(Kern::Printf("SM D %08x TProcessListItem OpenSurface", owner);)
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   610
	NKern::ThreadLeaveCS();
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   611
	return KErrNone;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   612
	}
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   613
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   614
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   615
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   616
/**
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   617
Closes a surface.  Decrements the usage count in the surface owner object
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   618
if the usage count is then zero, removes this surface owner from the surface.
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   619
If this results in a surface with no owners, the surface is deleted and the 
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   620
surface shared chunk is closed.
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   621
@param aId  The id of the surface to be closed
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   622
@return KErrNone if successful, KErrArgument if the surface ID does not refer to a surface,
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   623
KErrAccessDenied if the surface is not open in the current process, otherwise a system wide
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   624
error code.
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   625
@internalTechnology
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   626
*/
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   627
TInt DSurfaceManager::CloseSurface(const TSurfaceId* aId)
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   628
	{
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   629
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   630
	TSurfaceId sid;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   631
	kumemget(&sid, aId, sizeof (TSurfaceId));	//fetch surface id from user memory
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   632
	//look it up
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   633
	NKern::ThreadEnterCS();
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   634
	NKern::FMWait(&iMutex);
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   635
	TSurface* surface = FindSurfaceById(sid);
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   636
	if (!surface)	
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   637
		{
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   638
		NKern::FMSignal(&iMutex);
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   639
		NKern::ThreadLeaveCS();
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   640
		return KErrArgument;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   641
		}
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   642
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   643
	//find the owner
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   644
	TProcessListItem* so = surface->ProcessOwnerInfo(&Kern::CurrentProcess());
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   645
	if (!so)
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   646
		{
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   647
		NKern::FMSignal(&iMutex);
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   648
		NKern::ThreadLeaveCS();
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   649
		return KErrAccessDenied;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   650
		}
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   651
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   652
	//current process is a surface owner so decrement the open count
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   653
	TSurface* surfaceToDelete = NULL;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   654
	TProcessListItem* ownerToDelete = NULL;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   655
	DChunk* chunkToClose = NULL;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   656
	if (--so->iCount == 0)
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   657
		{
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   658
		//if count is now zero remove the owner
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   659
		//surface->RemoveOwner(so);
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   660
		UnlinkListItem(&surface->iOwners, so);
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   661
		ownerToDelete = so;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   662
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   663
		//check to see if the surface has any owners
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   664
		if (!surface->iOwners)
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   665
			{
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   666
			//no more owners of the surface
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   667
			chunkToClose = surface->iChunk;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   668
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   669
			//remove the surface from the list
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   670
			UnlinkListItem(&(iSurfacesIndex[SurfaceIdToIndex(surface->iId)]), surface);
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   671
			surfaceToDelete = surface;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   672
			}
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   673
		}
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   674
	
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   675
	NKern::FMSignal(&iMutex);
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   676
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   677
	if (chunkToClose)
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   678
		{
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   679
#ifdef GRAPHICS_SURFACEMANAGER_SYBORG
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   680
        TLinAddr kernelAddress;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   681
        TUint32 mapAttr;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   682
        TUint32 physicalAddress(0);
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   683
        if (KErrNone == Kern::ChunkPhysicalAddress(chunkToClose, 0, chunkToClose->Size(), kernelAddress, mapAttr, physicalAddress))
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   684
            {
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   685
            Kern::Printf("Closing chunk: deallocate %u",physicalAddress);
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   686
            iVHWMemoryManager->Deallocate(physicalAddress);
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   687
            }
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   688
#endif // GRAPHICS_SURFACEMANAGER_SYBORG
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   689
		//surface has no more owners so close the chunk
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   690
		Kern::ChunkClose(chunkToClose);
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   691
		}
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   692
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   693
	delete surfaceToDelete;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   694
	TRACE(Kern::Printf("SM D %08x TSurface CloseSurface",surfaceToDelete);)
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   695
	delete ownerToDelete;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   696
	TRACE(Kern::Printf("SM D %08x TProcessListItem CloseSurface",ownerToDelete);)
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   697
	NKern::ThreadLeaveCS();
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   698
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   699
	return KErrNone;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   700
	}
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   701
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   702
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   703
/**
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   704
Maps the surface memory into the process of the calling thread. This will fail if
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   705
the surface is not open in this process, or if the handle to the chunk cannot be created.
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   706
@param aId  The id of the surface to be mapped in.
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   707
@return KErrNone if successful, KErrArgument if the surface ID does not refer to a
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   708
surface, KErrAccessDenied if the surface is not open in the current process,
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   709
KErrNotSupported if the surface is not mappable, KErrOverflow if the chunk limit has been
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   710
exceeded in the moving memory model, otherwise a system wide error code.
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   711
@internalTechnology
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   712
*/
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   713
TInt DSurfaceManager::MapSurface(const TSurfaceId* aId)
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   714
	{
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   715
	TSurfaceId sid;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   716
	kumemget(&sid, aId, sizeof (TSurfaceId));	//fetch surface id from user memory
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   717
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   718
	//look it up
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   719
	NKern::ThreadEnterCS();
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   720
	NKern::FMWait(&iMutex);
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   721
	TSurface* surface = FindSurfaceById(sid);
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   722
	if (!surface)	
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   723
		{
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   724
		NKern::FMSignal(&iMutex);
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   725
		NKern::ThreadLeaveCS();
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   726
		return KErrArgument;	//surface id is not valid or in the list of surfaces
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   727
		}
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   728
	if(!surface->iMappable)
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   729
		{
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   730
		NKern::FMSignal(&iMutex);
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   731
		NKern::ThreadLeaveCS();		
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   732
		return KErrNotSupported;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   733
		}
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   734
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   735
	//find the owner
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   736
	TProcessListItem* so = surface->ProcessOwnerInfo(&Kern::CurrentProcess());
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   737
	if (!so)
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   738
		{
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   739
		NKern::FMSignal(&iMutex);
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   740
		NKern::ThreadLeaveCS();
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   741
		return KErrAccessDenied;	//can't map it in, it's not open in this process
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   742
		}
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   743
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   744
	DChunk* chunk = surface->iChunk;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   745
	TInt r = chunk->Open();
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   746
	NKern::FMSignal(&iMutex);
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   747
	TRACE(Kern::Printf("SM MapSurface chunk open r %d\n",r);)
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   748
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   749
	if (r == KErrGeneral)
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   750
		{
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   751
		NKern::ThreadLeaveCS();
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   752
		return KErrAccessDenied;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   753
		}
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   754
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   755
	//if we are here, got the surface and we are the owner.
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   756
	//if we are the owner we must have it open at least once
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   757
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   758
	r = Kern::MakeHandleAndOpen(NULL, chunk);
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   759
	chunk->Close(NULL);
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   760
	TRACE(Kern::Printf("SM MapSurface handle open r: %d\n",r);)
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   761
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   762
	NKern::ThreadLeaveCS();
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   763
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   764
	return r;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   765
	}
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   766
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   767
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   768
/**
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   769
Record a new connection to the driver.
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   770
Adds an element to the reference counted list of connected processes if the connection
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   771
is from a new process, otherwise it increments the reference count.
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   772
@param aProcess  The process which has opened a driver channel.
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   773
@internalTechnology
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   774
*/
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   775
TInt DSurfaceManager::AddConnection(const DProcess* aProcess)
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   776
	{
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   777
	TRACE(Kern::Printf("SM AddConnection process %08x\n", aProcess);)
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   778
	NKern::ThreadEnterCS();
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   779
	TProcessListItem* connectedProcess = new TProcessListItem;  //speculative creation
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   780
	TRACE(Kern::Printf("SM A %08x TProcessListItem AddConnection", connectedProcess);)
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   781
	NKern::FMWait(&iMutex);
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   782
	TProcessListItem* p = FindConnectedProcess(aProcess);
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   783
	if (p)	//already connected, found the process
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   784
		{
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   785
		++p->iCount;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   786
		}
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   787
	else
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   788
		{
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   789
		//add a new connected process
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   790
		if (!connectedProcess)
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   791
			{
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   792
			//the creation of the owner information object failed, out of memory
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   793
			NKern::FMSignal(&iMutex);
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   794
			NKern::ThreadLeaveCS();
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   795
			return KErrNoMemory;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   796
			}
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   797
		connectedProcess->iOwningProcess = (DProcess*)aProcess;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   798
		connectedProcess->iCount=1;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   799
		
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   800
		connectedProcess->iNext = iConnectedProcesses;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   801
		iConnectedProcesses = connectedProcess;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   802
		connectedProcess = NULL;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   803
		}
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   804
	NKern::FMSignal(&iMutex);
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   805
	delete connectedProcess;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   806
	TRACE(Kern::Printf("SM D %08x TProcessListItem AddConnection", connectedProcess);)
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   807
	NKern::ThreadLeaveCS();
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   808
	return KErrNone;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   809
	}
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   810
	
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   811
	
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   812
	
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   813
/**
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   814
Called when the driver channel is closed.
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   815
Decrements the reference count for the connected process, if the last connection
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   816
for this process is closed (reference count reaches 0) it removes the process from the list.
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   817
@param aProcess  The process which has closed the driver channel.
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   818
@internalTechnology
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   819
*/
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   820
void DSurfaceManager::RemoveConnection(const DProcess* aProcess)
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   821
	{
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   822
	TRACE(Kern::Printf("SM RemoveConnection process %08x\n", aProcess);)
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   823
	NKern::ThreadEnterCS();
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   824
	NKern::FMWait(&iMutex);
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   825
	TProcessListItem* p =FindConnectedProcess(aProcess);
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   826
	TProcessListItem* toDelete = NULL;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   827
	if (p)	//already connected, found the process
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   828
		{
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   829
		if (--p->iCount == 0) //last connection in process has disconnected
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   830
			{
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   831
			//remove the process from the list and cleanup
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   832
			UnlinkListItem(&iConnectedProcesses, p);
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   833
			toDelete = p;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   834
			}
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   835
		}
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   836
	NKern::FMSignal(&iMutex);
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   837
	delete toDelete;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   838
	TRACE(Kern::Printf("SM D %08x TProcessListItem RemoveConnection ", toDelete);)
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   839
	
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   840
	
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   841
	if (toDelete)	// if a process has closed its last channel, remove process from the surface owners.
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   842
		{
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   843
		CloseSurfaceHandlesForProcess(aProcess);
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   844
		}
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   845
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   846
	NKern::ThreadLeaveCS();
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   847
	}
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   848
	
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   849
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   850
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   851
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   852
/**
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   853
Closes all the surfaces belonging to the process which has just terminated.
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   854
If this is the only owner of a surface, delete the surface.
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   855
@param aProcess  The process which has terminated.
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   856
@pre must be called in critical section
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   857
@internalTechnology
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   858
*/
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   859
void DSurfaceManager::CloseSurfaceHandlesForProcess(const DProcess* aProcess)
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   860
	{
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   861
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   862
	NKern::FMWait(&iMutex);
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   863
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   864
	TSurface* p = NULL;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   865
	TSurface* surfacesTodelete = NULL;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   866
	TProcessListItem* ownersTodelete = NULL;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   867
	TProcessListItem* so;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   868
	// There are 16 doubly linked lists managed by Surface Manager
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   869
	for (TInt index = 0; index < KMaxLists; index++)
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   870
		{
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   871
		p = iSurfacesIndex[index];
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   872
		while(p)
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   873
			{
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   874
			//see if the process which has just died is an owner of any surfaces
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   875
			TSurface* surface = p;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   876
			p=p->iNext;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   877
			so = surface->ProcessOwnerInfo(aProcess);
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   878
			if (so)
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   879
				{
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   880
				UnlinkListItem(&surface->iOwners, so);
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   881
				so->iNext = ownersTodelete;	//add the owner to the list of owner objects to remove
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   882
				ownersTodelete = so;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   883
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   884
				if (!surface->iOwners)	//if the surface hasn't any owners
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   885
					{
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   886
					//remove the surface from the list
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   887
					UnlinkListItem(&iSurfacesIndex[index], surface);
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   888
					surface->iNext = surfacesTodelete;	//add the surface to the list of surfaces to remove
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   889
					surfacesTodelete = surface;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   890
					}
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   891
				}
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   892
			}
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   893
		}
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   894
	NKern::FMSignal(&iMutex);
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   895
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   896
	while(surfacesTodelete)
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   897
		{
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   898
		p = surfacesTodelete->iNext;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   899
		Kern::ChunkClose(surfacesTodelete->iChunk);
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   900
		TRACE(Kern::Printf("SM Close chunk %08x CloseSurfaceHandlesForProcess",surfacesTodelete->iChunk);)
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   901
		delete surfacesTodelete;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   902
		TRACE(Kern::Printf("SM D %08x TSurface CloseSurfaceHandlesForProcess",surfacesTodelete);)
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   903
		surfacesTodelete = p;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   904
		}
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   905
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   906
	while(ownersTodelete)
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   907
		{
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   908
		so = ownersTodelete->iNext;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   909
		delete ownersTodelete;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   910
		TRACE(Kern::Printf("SM D %08x TProcessListItem CloseSurfaceHandlesForProcess",ownersTodelete);)
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   911
		ownersTodelete = so;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   912
		}
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   913
	}
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   914
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   915
	
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   916
/**
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   917
Returns the metadata information about the specified surface.
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   918
@param aId  The id of the surface.
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   919
@param aInfo  Pointer to user side descriptor to receive the information.
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   920
@return KErrNone if successful, KErrArgument if the surface ID does not refer to a surface,
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   921
KErrAccessDenied if the surface is not open in the current process, otherwise a system wide
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   922
error code.
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   923
@internalTechnology
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   924
*/	
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   925
TInt DSurfaceManager::SurfaceInfo(const TSurfaceId* aId, TDes8* aInfo)
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   926
	{
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   927
	TSurfaceId sid;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   928
	//fetch surface id from user memory
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   929
	kumemget(&sid, aId, sizeof (TSurfaceId));
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   930
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   931
	RSurfaceManager::TInfoBuf buf;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   932
	RSurfaceManager::TSurfaceInfoV01& info = buf();
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   933
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   934
	NKern::FMWait(&iMutex);
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   935
	//look it up
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   936
	TSurface* surface = FindSurfaceById(sid);
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   937
	if (!surface)	
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   938
		{
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   939
		NKern::FMSignal(&iMutex);
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   940
		return KErrArgument;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   941
		}
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   942
	
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   943
	//find the owner
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   944
	TProcessListItem* so = surface->ProcessOwnerInfo(&Kern::CurrentProcess());
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   945
	if (!so)
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   946
		{
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   947
		NKern::FMSignal(&iMutex);
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   948
		return KErrAccessDenied;	//can do this, not open
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   949
		}
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   950
	
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   951
	//at this point, we have a surface, we are the owner and it's mapped in
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   952
	info.iSize = surface->iSize; 									// Visible width/height in pixels
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   953
	info.iBuffers = surface->iBuffers;								// Number of Buffers
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   954
	info.iPixelFormat = surface->iPixelFormat;	      				// pixel format
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   955
	info.iStride = surface->iStride;								// Number of bytes between start of one line and start of next
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   956
	info.iContiguous = surface->iContiguous;						// is it physically contiguous
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   957
	info.iCacheAttrib = surface->iCacheAttrib;						// Underlying chunk is CPU cached or not
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   958
	info.iMappable = surface->iMappable;							// Is the surface Mappable
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   959
	NKern::FMSignal(&iMutex);
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   960
	
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   961
	//copy it back to user side
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   962
	Kern::InfoCopy(*aInfo, buf);
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   963
	return KErrNone;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   964
	}
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   965
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   966
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   967
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   968
/**
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   969
Generates a unique surface id
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   970
@param aId  Surface id reference to receive the generated id.
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   971
@internalTechnology
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   972
*/	
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   973
void DSurfaceManager::GenerateSurfaceId(TSurfaceId& aId)
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   974
	{
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   975
	TSurfaceId id;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   976
	
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   977
	for (TInt x = 0; x < 4; ++x)
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   978
		{
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   979
		id.iInternal[x] = Kern::Random();
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   980
		};
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   981
	
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   982
	//package up the handle,
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   983
	//set the type identifier
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   984
	id.iInternal[3] &= 0x00FFFFFF;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   985
	id.iInternal[3] |= TSurfaceTypes::ESurfaceManagerSurface << 24;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   986
	aId = id;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   987
	TRACE(Kern::Printf("SM GenerateSurfaceId id = %u %u %u %u\n",id.iInternal[0],id.iInternal[1],id.iInternal[2],id.iInternal[3]);)
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   988
	};
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   989
	
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   990
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   991
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   992
/**
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   993
Validates the surface creation attributes and calculates the size of the chunk required.
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   994
@param aAttribs  The surface creation attributes used to specify the surface requirements.
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   995
@param aOffset  Set to the offset between buffers on successfull return.
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   996
@param aNewChunk  If this is true, surface is created in a new chunk otherwise the surface is created in an existing chunk
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   997
@return The size of chunk required.  A size of 0 indicates a problem.
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   998
*/	
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   999
TInt DSurfaceManager::ValidateAndCalculateChunkSize(RSurfaceManager::TSurfaceCreationAttributes& aAttribs, 
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1000
			TInt& aOffset, TUint &aActualBufferSize, const TBool aNewChunk)
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1001
	{
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1002
/*	
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1003
	TRACE(Kern::Printf("SM width = %d  height = %d\n", aAttribs.iSize.iWidth, aAttribs.iSize.iHeight);)
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1004
	TRACE(Kern::Printf("SM buffers = %d\n", aAttribs.iBuffers);)
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1005
	TRACE(Kern::Printf("SM format = %d\n", aAttribs.iPixelFormat);)
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1006
	TRACE(Kern::Printf("SM stride = %d\n", aAttribs.iStride);)
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1007
	TRACE(Kern::Printf("SM offset to first buffer = %d\n", aAttribs.iOffsetToFirstBuffer);)
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1008
	TRACE(Kern::Printf("SM offset between buffer = %d\n", aOffset);)
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1009
	TRACE(Kern::Printf("SM alignment = %d\n", aAttribs.iAlignment);)
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1010
	TRACE(Kern::Printf("SM contiguous = %d\n\n", aAttribs.iContiguous);)
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1011
	TRACE(Kern::Printf("SM cacheAttrib = %d\n\n", aAttribs.iCacheAttrib);)
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1012
*/
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1013
	//check for negative values
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1014
	if(aAttribs.iOffsetToFirstBuffer < 0 || aOffset < 0 )
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1015
		{
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1016
		TRACE(Kern::Printf("SM Validate offset for negative value");)
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1017
		return 0;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1018
		}
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1019
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1020
	//check aligment is sensible
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1021
	TInt alignmentMask = 0;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1022
	switch(aAttribs.iAlignment)
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1023
		{
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1024
		case 1:	
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1025
		case 2:	
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1026
		case 4: 
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1027
		case 8: 
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1028
		case 16: 
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1029
		case 32: 
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1030
			alignmentMask = 31; 
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1031
			break;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1032
		case 64: 
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1033
			alignmentMask = 63; 
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1034
			break;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1035
		case RSurfaceManager::EPageAligned:
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1036
			break;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1037
		default:
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1038
			TRACE(Kern::Printf("SM Validate alignment");)
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1039
			return 0;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1040
		}
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1041
	
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1042
	//check alignment issues.
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1043
	if(aAttribs.iAlignment != RSurfaceManager::EPageAligned)
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1044
		{
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1045
		if(aNewChunk)	
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1046
			{
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1047
			if(aAttribs.iCacheAttrib == RSurfaceManager::ECached)	// Surface is CPU cached, so the alignment will be based on either 32 or 64 byte 
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1048
				{
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1049
				//offset to first buffer needs to fit alignment
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1050
				aAttribs.iOffsetToFirstBuffer = aAttribs.iOffsetToFirstBuffer + alignmentMask & ~alignmentMask;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1051
				//alignment with respect to offsetbetweenbuffers
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1052
				aOffset = aOffset + alignmentMask & ~alignmentMask;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1053
				}
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1054
			else	// Surface is NOT CPU cached, so the alignment will be based on surface attribute alignment
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1055
				{
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1056
				TUint alignMask = aAttribs.iAlignment-1;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1057
				//offset to first buffer needs to fit alignment
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1058
				aAttribs.iOffsetToFirstBuffer = aAttribs.iOffsetToFirstBuffer + alignMask & ~alignMask;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1059
				//alignment with respect to offsetbetweenbuffers
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1060
				aOffset = aOffset + alignMask & ~alignMask;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1061
				}
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1062
			}
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1063
		else	// existing chunk
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1064
			{
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1065
			TUint alignMask = aAttribs.iAlignment-1;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1066
			//check alignment issues.  offset to first buffer needs to fit alignment
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1067
			if (aAttribs.iOffsetToFirstBuffer & alignMask)
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1068
				{
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1069
				TRACE(Kern::Printf("SM Validate offset to first pixel misaligned");)
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1070
				return 0;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1071
				}
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1072
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1073
			//check alignment for offsetbetweenbuffers.  offset between buffer needs to fit alignment for existing chunks
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1074
			if (aOffset & alignMask)
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1075
				{
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1076
				TRACE(Kern::Printf("SM Validate offset between buffers misaligned");)
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1077
				return 0;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1078
				}
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1079
			}
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1080
		}
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1081
	else	//page aligned
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1082
		{
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1083
		if(aNewChunk)// if its a new chunks and doesn't match exact alignment then do the rounding
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1084
			{
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1085
			TUint32 pageSize = Kern::RoundToPageSize(1);
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1086
			//offset to first buffer needs to fit alignment
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1087
			aAttribs.iOffsetToFirstBuffer = (aAttribs.iOffsetToFirstBuffer + (pageSize - 1)) & ~(pageSize - 1);
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1088
			//alignment with respect to offsetbetweenbuffers
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1089
			aOffset = (aOffset + (pageSize - 1)) & ~((pageSize - 1));
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1090
			}
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1091
		else	// for existing chunks don't do any rounding operation
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1092
			{
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1093
			TUint32 pageSize = Kern::RoundToPageSize(1);
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1094
			TUint alignmask = aAttribs.iOffsetToFirstBuffer & (pageSize - 1);
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1095
			if (alignmask)
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1096
				{
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1097
				TRACE(Kern::Printf("SM Validate offset to first pixel misaligned");)
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1098
				return 0;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1099
				}
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1100
			
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1101
			alignmask = aOffset & (pageSize - 1);
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1102
			if (alignmask)
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1103
				{
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1104
				TRACE(Kern::Printf("SM Validate offset between buffers misaligned");)
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1105
				return 0;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1106
				}
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1107
			}
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1108
		}
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1109
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1110
	//check width and height
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1111
	if(aAttribs.iSize.iWidth <= 0 || aAttribs.iSize.iHeight <= 0)
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1112
		{
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1113
		TRACE(Kern::Printf("SM Validate width/height");)
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1114
		return 0;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1115
		}
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1116
	
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1117
	
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1118
	//check there is at least 1 buffer
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1119
	if (aAttribs.iBuffers <= 0)
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1120
		{
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1121
		TRACE(Kern::Printf("SM Validate buffers");)
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1122
		return 0;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1123
		}
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1124
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1125
	//Sort the array and also check for duplication
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1126
	if (!SortHints(aAttribs.iSurfaceHints,aAttribs.iHintCount)) 
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1127
		{
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1128
		TRACE(Kern::Printf("SM Validate Duplicate hint key");)
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1129
		return 0;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1130
		}
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1131
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1132
	TUint size = 0;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1133
	//calculate buffer size and round it to alignment or to page size
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1134
	TInt64 bufferSize = aAttribs.iStride;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1135
	bufferSize  *= aAttribs.iSize.iHeight;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1136
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1137
	if (I64HIGH(bufferSize) > 0) //too big
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1138
		{
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1139
		TRACE(Kern::Printf("SM Validate chunk buffer size is out of range");)
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1140
		return 0;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1141
		}
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1142
	
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1143
	TUint bsize = I64LOW(bufferSize);
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1144
	if (bsize > KMaxTInt)
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1145
		{
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1146
		TRACE(Kern::Printf("SM Validate buffer size is out of range for TInt");)
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1147
		return 0;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1148
		}
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1149
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1150
	if(aAttribs.iAlignment == RSurfaceManager::EPageAligned)
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1151
		{
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1152
		bsize = Kern::RoundToPageSize(bsize);	//page alignment
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1153
		}
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1154
	else if(aAttribs.iCacheAttrib == RSurfaceManager::ECached)
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1155
		{
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1156
		bsize = bsize + alignmentMask & ~alignmentMask;	//CPU cached byte alignment, for minimum of the specified alignment(32 or 64)
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1157
		}
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1158
	else
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1159
		{
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1160
		bsize = bsize + (aAttribs.iAlignment-1) & ~(aAttribs.iAlignment-1);	//NON CPU cached byte alignment for 1, 2, 4, 8, 16, 32 and 64
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1161
		}
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1162
	
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1163
	bufferSize = bsize;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1164
	// Remember the actual size. 
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1165
	aActualBufferSize = bsize;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1166
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1167
	//if offset between buffers is zero, then assign the calculated value as offset between buffers
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1168
	if(aOffset == 0)
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1169
		{
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1170
		//buffer size rounded to alignment as offset between buffers
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1171
		aOffset = I64INT(bufferSize);
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1172
		}
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1173
	else if(aOffset < I64INT(bufferSize))
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1174
		{
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1175
		TRACE(Kern::Printf("SM Offset between the buffer is less than the required size");)
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1176
		return 0;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1177
		}
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1178
	else
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1179
		{
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1180
		//use the buffer size specified
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1181
		bufferSize = aOffset;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1182
		}
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1183
	
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1184
	
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1185
	TInt64 totalSize = aAttribs.iOffsetToFirstBuffer + (aAttribs.iBuffers * bufferSize);
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1186
	
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1187
	if (I64HIGH(totalSize) > 0) //too big
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1188
		{
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1189
		TRACE(Kern::Printf("SM Validate chunk size is out of range for RoundToPageSize");)
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1190
		return 0;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1191
		}
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1192
		
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1193
	size = I64LOW(totalSize);
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1194
	if (size > KMaxTInt)
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1195
		{
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1196
		TRACE(Kern::Printf("SM Validate size is out of range for TInt");)
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1197
		return 0;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1198
		}
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1199
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1200
	size = Kern::RoundToPageSize(size);
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1201
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1202
	//check the size isn't greater than will fit in a TInt
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1203
	if (size > KMaxTInt)
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1204
		{
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1205
		TRACE(Kern::Printf("SM Rounded size is out of range for TInt");)
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1206
		return 0;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1207
		}
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1208
	
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1209
	TRACE(Kern::Printf("SM After validate - offset to first buffer = %d\n", aAttribs.iOffsetToFirstBuffer);)
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1210
	TRACE(Kern::Printf("SM After validate - offset between buffer = %d\n", aOffset);)
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1211
	TRACE(Kern::Printf("SM CalculateChunkSize size = %d\n", size);)
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1212
	return size;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1213
	}
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1214
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1215
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1216
/**
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1217
Find the surface in the list.   
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1218
@param aId  The surface id of the surface to find in the surface list
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1219
@return pointer to the surface object
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1220
@internalTechnology
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1221
*/
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1222
TSurface* DSurfaceManager::FindSurfaceById(const TSurfaceId& aId)
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1223
	{
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1224
	TSurface *p = iSurfacesIndex[SurfaceIdToIndex(aId)];
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1225
	while (p)
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1226
		{
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1227
		if (aId == p->iId)
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1228
			{
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1229
			//found it
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1230
			return p;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1231
			}
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1232
	
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1233
		p = p->iNext;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1234
		}
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1235
	return NULL;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1236
	}
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1237
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1238
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1239
/**
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1240
Find the index of the hint key from the surface list using binary search.   
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1241
@param aHintsArray  Pointer to the first element in the array of surface hints
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1242
@param aKey  The surface hint key uid value to search in the surface list
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1243
@return index of the hint pair key in the surface list, KErrNotFound if key not found
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1244
@internalTechnology
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1245
*/
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1246
TInt DSurfaceManager::FindHintKey(const RSurfaceManager::THintPair* aHintsArray, TUint32 aKey) const
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1247
	{
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1248
	__ASSERT_DEBUG(aHintsArray != NULL, Kern::Fault("Surface Manager", __LINE__));
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1249
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1250
	TInt bottom = 0;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1251
	TInt top = KMaxHintsPerSurface - 1;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1252
	TInt mid;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1253
	while (bottom <= top)
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1254
		{
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1255
	    mid = (bottom + top) / 2;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1256
	    if((TUint) aHintsArray[mid].iKey.iUid == aKey)
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1257
	    	{
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1258
	    	return mid;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1259
	    	} 
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1260
	    else if ((TUint)aHintsArray[mid].iKey.iUid < aKey) 
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1261
	    	{
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1262
	    	top = mid - 1;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1263
	    	}
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1264
	    else
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1265
	    	{
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1266
	    	bottom = mid + 1;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1267
	    	}
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1268
	  }
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1269
	return KErrNotFound;	//Hint key not found
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1270
    }
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1271
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1272
TProcessListItem* DSurfaceManager::FindConnectedProcess(const DProcess* aProcess)
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1273
	{
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1274
	TProcessListItem * p = iConnectedProcesses;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1275
	while (p)
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1276
		{
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1277
		if (aProcess == p->iOwningProcess)
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1278
			{
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1279
			//found it
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1280
			return p;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1281
			}
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1282
		
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1283
		p = p->iNext;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1284
		}
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1285
	return NULL;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1286
	}
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1287
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1288
/**
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1289
Searches for a right place to insert the new hint pair in a sorted array.
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1290
@param aHintsArray  Pointer to the first element in the sorted array
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1291
@param aKey  The surface hint key uid value to search in the surface list
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1292
@pre, there is at least one empty place in the array
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1293
@return KErrNone if a new hint pair key inserted in the surface list, KErrAlreadyExists if duplicated
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1294
@internalTechnology
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1295
*/
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1296
TInt DSurfaceManager::InsertHintKey(RSurfaceManager::THintPair* aHintsArray, const RSurfaceManager::THintPair& aHintPair) const
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1297
	{
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1298
	__ASSERT_DEBUG(aHintsArray != NULL, Kern::Fault("Surface Manager", __LINE__));
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1299
	__ASSERT_DEBUG(aHintsArray[KMaxHintsPerSurface-1].iKey.iUid == NULL, Kern::Fault("Surface Manager", __LINE__));
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1300
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1301
	TInt pos = 0;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1302
	if (aHintsArray[pos].iKey.iUid != 0)
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1303
		{
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1304
		while((TUint)aHintsArray[pos].iKey.iUid>(TUint)aHintPair.iKey.iUid && pos < KMaxHintsPerSurface-1)
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1305
			{// find the right place to insert
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1306
			++pos;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1307
			}
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1308
	
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1309
		if((TUint)aHintsArray[pos].iKey.iUid==(TUint)aHintPair.iKey.iUid)
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1310
			{
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1311
			//Duplicate key 
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1312
			return KErrAlreadyExists;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1313
			}
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1314
		else
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1315
			{
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1316
			// Shift right
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1317
			memmove(aHintsArray+pos+1, aHintsArray+pos, (KMaxHintsPerSurface-pos-1)*sizeof(RSurfaceManager::THintPair));		
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1318
			}	
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1319
		}
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1320
	aHintsArray[pos] = aHintPair;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1321
	return KErrNone;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1322
	}
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1323
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1324
/**
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1325
Sort the surface hint array in descending order.
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1326
@param aHintsArray  The surface hintpair in the surface list
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1327
@param aNumberOfHints The number of hints
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1328
@return ETrue if sorting is finished or it is an empty array, EFalse if key duplicated
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1329
@internalTechnology
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1330
*/
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1331
TBool DSurfaceManager::SortHints(RSurfaceManager::THintPair* aHintsArray, TInt aNumberOfHints) const
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1332
	{
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1333
	TInt in = 0;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1334
	TInt out = 0;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1335
	RSurfaceManager::THintPair temp;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1336
	if(!aHintsArray)
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1337
		{
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1338
		return ETrue;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1339
		}
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1340
	for(out = 0; out < aNumberOfHints; ++out) 
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1341
		{
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1342
		if(aHintsArray[out].iKey.iUid != 0)
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1343
			{
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1344
			temp = aHintsArray[out];   
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1345
			in = out;          // start shifting at out
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1346
			while(in > 0 && (TUint)aHintsArray[in-1].iKey.iUid <= (TUint)temp.iKey.iUid)
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1347
				{
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1348
				if ((TUint)aHintsArray[in-1].iKey.iUid == (TUint)temp.iKey.iUid)
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1349
					{
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1350
					return EFalse;		//duplicate hint keys are not allowed
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1351
					}
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1352
				aHintsArray[in] = aHintsArray[in-1];     // shift item to the right
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1353
				--in;          // go left one position
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1354
				}
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1355
			aHintsArray[in] = temp;        // insert marked item
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1356
			}
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1357
		}
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1358
	return ETrue;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1359
	}
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1360
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1361
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1362
/**
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1363
Ensures the memory is updated consistently before/after triggering non CPU hardware access. 
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1364
@param aParam  The suface id and buffer number (0 based).
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1365
@param aOperation  The type of the synchronize operation. 
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1366
@return KErrNone if successful, KErrArgument if the surface ID is invalid or
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1367
buffer number is invalid, KErrAccessDenied if the surface is not open in this
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1368
process, otherwise a system wide error code.
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1369
@see RSurfaceManager::TSyncOperation
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1370
@internalTechnology
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1371
*/	
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1372
TInt DSurfaceManager::SynchronizeCache(RSurfaceManagerDriver::TDeviceParam* aParam, RSurfaceManager::TSyncOperation aOperation)
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1373
	{
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1374
	//Parse the parameters
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1375
	RSurfaceManagerDriver::TDeviceParam param;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1376
	kumemget(&param, aParam, sizeof(RSurfaceManagerDriver::TDeviceParam));
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1377
	TSurfaceId sid;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1378
	kumemget(&sid, param.iSurfaceId, sizeof(TSurfaceId));
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1379
	TInt buffer = (TInt)param.iBuffer;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1380
	
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1381
	NKern::ThreadEnterCS();
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1382
	NKern::FMWait(&iMutex);
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1383
	//look it up
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1384
	TSurface* surface = FindSurfaceById(sid);
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1385
	if (!surface)	
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1386
		{
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1387
		NKern::FMSignal(&iMutex);
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1388
		NKern::ThreadLeaveCS();
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1389
		return KErrArgument;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1390
		}
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1391
	
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1392
	//find the owner
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1393
	TProcessListItem* so = surface->ProcessOwnerInfo(&Kern::CurrentProcess());
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1394
	if (!so)
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1395
		{
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1396
		NKern::FMSignal(&iMutex);
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1397
		NKern::ThreadLeaveCS();
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1398
		return KErrAccessDenied;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1399
		}
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1400
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1401
	// surfaces have to have at least one buffer
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1402
	__ASSERT_DEBUG(surface->iBuffers > 0, Kern::Fault("Surface Manager", __LINE__));
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1403
	
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1404
	//Validate the buffer number is within range
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1405
	if((buffer >= surface->iBuffers) || (buffer < 0))
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1406
		{
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1407
		NKern::FMSignal(&iMutex);
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1408
		NKern::ThreadLeaveCS();
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1409
		return KErrArgument;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1410
		}
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1411
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1412
	DChunk* chunk = surface->iChunk;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1413
	TInt offsetBetweenBuffers = surface->iOffsetBetweenBuffers;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1414
	NKern::FMSignal(&iMutex);
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1415
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1416
	TUint32 kernAddr;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1417
	TUint32 mapAttr;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1418
	TUint32 physAddr;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1419
	TInt pageList = chunk->iSize / Kern::RoundToPageSize(1) + 1;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1420
	TUint32* physAddr2 = new TUint32[pageList];
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1421
	if(!physAddr2)
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1422
		{
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1423
		NKern::ThreadLeaveCS();
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1424
		return KErrNoMemory;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1425
		}
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1426
	
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1427
	TRACE(Kern::Printf("SM %08x DChunk SynchronizeCache", chunk);)
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1428
	
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1429
	//Retrieve the kernel address and mapping attribute from the chunk
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1430
	TInt err = Kern::ChunkPhysicalAddress(chunk, surface->iOffsetToFirstBuffer + (buffer * offsetBetweenBuffers), offsetBetweenBuffers, kernAddr, mapAttr, physAddr, physAddr2);
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1431
	delete[] physAddr2;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1432
	if(err >= KErrNone)
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1433
		{
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1434
		TRACE(Kern::Printf("SM %08x kernAddr SynchronizeCache", kernAddr);)
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1435
		TRACE(Kern::Printf("SM %08x mapAttr SynchronizeCache", mapAttr);)
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1436
		err = KErrNone;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1437
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1438
		// Do the sync operation
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1439
		switch(aOperation)
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1440
			{
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1441
			case RSurfaceManager::ESyncBeforeNonCPURead:
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1442
				Cache::SyncMemoryBeforeDmaWrite(kernAddr, offsetBetweenBuffers, mapAttr);
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1443
				break;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1444
			case RSurfaceManager::ESyncBeforeNonCPUWrite:
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1445
				Cache::SyncMemoryBeforeDmaRead(kernAddr, offsetBetweenBuffers, mapAttr);
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1446
				break;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1447
			case RSurfaceManager::ESyncAfterNonCPUWrite:
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1448
				Cache::SyncMemoryAfterDmaRead(kernAddr, offsetBetweenBuffers);
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1449
				break;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1450
			default: 
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1451
				err = KErrArgument;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1452
				break;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1453
			}			
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1454
		}
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1455
	NKern::ThreadLeaveCS();
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1456
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1457
	return err;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1458
	}
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1459
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1460
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1461
/**
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1462
Get the surface hint value for the given surface ID and hint pair key.
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1463
@param aSurfaceId  The surface identifier originally returned when the surface was created.
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1464
@param aHintPair  The hint value for the requested hint pair key.
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1465
@return KErrNone if successful, KErrArgument if the surface ID is invalid or
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1466
invalid hint pair key used, KErrAccessDenied if the surface is not open in the
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1467
current process, otherwise a system wide error code.
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1468
@internalTechnology
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1469
*/ 
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1470
TInt DSurfaceManager::GetSurfaceHint(const TSurfaceId* aSurfaceId, RSurfaceManager::THintPair* aHintPair)
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1471
	{
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1472
	RSurfaceManager::THintPair hintPair;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1473
	kumemget(&hintPair, aHintPair, sizeof(RSurfaceManager::THintPair));
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1474
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1475
	if (hintPair.iKey.iUid == 0)
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1476
		{
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1477
		TRACE(Kern::Printf("SM GetSurfaceHint Hint key is invalid");)
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1478
		return KErrArgument;	//Invalid Hint key
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1479
		}
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1480
	
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1481
	TSurfaceId sid;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1482
	//fetch surface id from user memory
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1483
	kumemget(&sid, aSurfaceId, sizeof (TSurfaceId));
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1484
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1485
	NKern::FMWait(&iMutex);
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1486
	//look it up
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1487
	TSurface* surface = FindSurfaceById(sid);
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1488
	if (!surface)	
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1489
		{
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1490
		NKern::FMSignal(&iMutex);
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1491
		return KErrArgument;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1492
		}
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1493
	
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1494
	//find the owner
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1495
	TProcessListItem* so = surface->ProcessOwnerInfo(&Kern::CurrentProcess());
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1496
	if (!so)
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1497
		{
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1498
		NKern::FMSignal(&iMutex);
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1499
		return KErrAccessDenied;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1500
		}
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1501
	
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1502
	//at this point, we have a surface, we have to find the hint value based on the hint pair key
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1503
	TInt index = FindHintKey(surface->iSurfaceHints, hintPair.iKey.iUid);
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1504
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1505
	if (index == KErrNotFound)
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1506
		{
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1507
		TRACE(Kern::Printf("SM GetSurfaceHint Hint key not found");)
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1508
		NKern::FMSignal(&iMutex);
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1509
		return KErrArgument;	//Hint key not found
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1510
		}
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1511
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1512
	RSurfaceManager::THintPair hint = surface->iSurfaceHints[index];
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1513
	NKern::FMSignal(&iMutex);
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1514
		
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1515
	TRACE(Kern::Printf("SM GetSurfaceHint Hint value %d", hint.iValue);)
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1516
	//write it back to user side
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1517
	kumemput(aHintPair, &hint, sizeof(RSurfaceManager::THintPair));
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1518
	return KErrNone;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1519
	}
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1520
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1521
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1522
/**
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1523
Set the surface hint value for an existing surface hint key of the surface Id.
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1524
@param aSurfaceId  The surface identifier originally returned when the surface was created.
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1525
@param aHintPair  The value of the hint pair to set.
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1526
@return KErrNone if successful, KErrArgument if the surface ID is invalid or if invalid
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1527
hint key used, KErrAccessDenied if the hint pair is immutable or the surface is not open
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1528
in the current process, otherwise a system wide error code.
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1529
@internalTechnology
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1530
*/ 
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1531
TInt DSurfaceManager::SetSurfaceHint(const TSurfaceId* aSurfaceId, const RSurfaceManager::THintPair* aHintPair)
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1532
	{
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1533
	RSurfaceManager::THintPair hintPair;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1534
	kumemget(&hintPair, aHintPair, sizeof(RSurfaceManager::THintPair));
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1535
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1536
	//Check for valid hint key
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1537
	if (!hintPair.iKey.iUid)
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1538
		{
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1539
		TRACE(Kern::Printf("SM SetSurfaceHint Hint key is invalid");)
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1540
		return KErrArgument;	//Invalid Hint key
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1541
		}
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1542
	
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1543
	TSurfaceId sid;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1544
	//fetch surface id from user memory
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1545
	kumemget(&sid, aSurfaceId, sizeof (TSurfaceId));
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1546
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1547
	NKern::ThreadEnterCS();
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1548
	NKern::FMWait(&iMutex);
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1549
	//look it up
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1550
	TSurface* surface = FindSurfaceById(sid);
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1551
	if (!surface)	
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1552
		{
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1553
		NKern::FMSignal(&iMutex);
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1554
		NKern::ThreadLeaveCS();
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1555
		return KErrArgument;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1556
		}
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1557
	
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1558
	//find the owner
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1559
	TProcessListItem* so = surface->ProcessOwnerInfo(&Kern::CurrentProcess());
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1560
	if (!so)
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1561
		{
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1562
		NKern::FMSignal(&iMutex);
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1563
		NKern::ThreadLeaveCS();
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1564
		return KErrAccessDenied;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1565
		}
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1566
	
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1567
	//at this point, we have a surface, we have to find the hint value based on the hint pair key
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1568
	TInt index = FindHintKey(surface->iSurfaceHints, hintPair.iKey.iUid);
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1569
	if (index == KErrNotFound)
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1570
		{
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1571
		TRACE(Kern::Printf("SM SetSurfaceHint Hint key not found or invalid");)
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1572
		NKern::FMSignal(&iMutex);
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1573
		NKern::ThreadLeaveCS();
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1574
		return KErrArgument;	//Hint key not found or invalid
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1575
		}
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1576
	
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1577
	//Check for mutability
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1578
	if(!surface->iSurfaceHints[index].iMutable)
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1579
		{
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1580
		TRACE(Kern::Printf("SM SetSurfaceHint Hint is immutable");)
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1581
		NKern::FMSignal(&iMutex);
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1582
		NKern::ThreadLeaveCS();
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1583
		return KErrAccessDenied;	//Hint pair is immutable
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1584
		}
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1585
	TRACE(Kern::Printf("SM SetSurfaceHint Hint key found and updated its value %d for the surface %08x \n", aHintPair->iValue, &sid);)
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1586
	
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1587
	//set the hint pair value now
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1588
	memcpy(&surface->iSurfaceHints[index], &hintPair, sizeof(RSurfaceManager::THintPair));
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1589
	NKern::FMSignal(&iMutex);
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1590
	NKern::ThreadLeaveCS();
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1591
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1592
	return KErrNone;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1593
	}
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1594
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1595
/**
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1596
Add a new surface hint value for the surface Id.
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1597
@param aSurfaceId  The surface identifier originally returned when the surface was created.
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1598
@param aHintPair  The value of the hint pair to Add.
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1599
@return Returns KErrNone if successful, KErrArgument if the surface ID is invalid or the
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1600
hint pair has invalid key UID, KErrAccessDenied if the surface is not open in the current
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1601
process, KErrAlreadyExists if duplicate hint key used, KErrOverflow if no space to add new
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1602
pair, otherwise a system wide error code.
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1603
@internalTechnology
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1604
*/ 
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1605
TInt DSurfaceManager::AddSurfaceHint(const TSurfaceId* aSurfaceId, const RSurfaceManager::THintPair* aHintPair)
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1606
	{
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1607
	RSurfaceManager::THintPair hintPair;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1608
	kumemget(&hintPair, aHintPair, sizeof(RSurfaceManager::THintPair));
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1609
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1610
	//Check for valid hint key
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1611
	if (hintPair.iKey.iUid == 0)
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1612
		{
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1613
		TRACE(Kern::Printf("SM AddSurfaceHint Hint key is invalid");)
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1614
		return KErrArgument;	//Invalid Hint key
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1615
		}
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1616
	
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1617
	TSurfaceId sid;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1618
	//fetch surface id from user memory
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1619
	kumemget(&sid, aSurfaceId, sizeof (TSurfaceId));
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1620
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1621
	NKern::ThreadEnterCS();
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1622
	NKern::FMWait(&iMutex);
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1623
	//look it up
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1624
	TSurface* surface = FindSurfaceById(sid);
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1625
	if (!surface)	
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1626
		{
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1627
		NKern::FMSignal(&iMutex);
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1628
		NKern::ThreadLeaveCS();
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1629
		return KErrArgument;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1630
		}
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1631
	
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1632
	//find the owner
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1633
	TProcessListItem* so = surface->ProcessOwnerInfo(&Kern::CurrentProcess());
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1634
	if (!so)
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1635
		{
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1636
		NKern::FMSignal(&iMutex);
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1637
		NKern::ThreadLeaveCS();
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1638
		return KErrAccessDenied;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1639
		}
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1640
	
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1641
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1642
	//Check for empty hint pair
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1643
	if(surface->iSurfaceHints[KMaxHintsPerSurface - 1].iKey.iUid != 0)//at least end of sorted hint array should be 0 to add a new hint
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1644
		{
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1645
		TRACE(Kern::Printf("SM AddSurfaceHint there is no room to add the hint");)
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1646
		NKern::FMSignal(&iMutex);
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1647
		NKern::ThreadLeaveCS();
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1648
		return KErrOverflow;	//No room for new hint
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1649
		}
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1650
	//We found room for a new hint pair, so insert it in the array
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1651
	// Meanwhile, we check for duplication, if it is, return KErrAlreadyExists
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1652
	TInt err = InsertHintKey(surface->iSurfaceHints,hintPair);
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1653
	NKern::FMSignal(&iMutex);
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1654
	TRACE(Kern::Printf("SM AddSurfaceHint Added new key ");)
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1655
	NKern::ThreadLeaveCS();
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1656
	return err;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1657
	}
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1658
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1659
/**
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1660
Get the offset of the specified buffer from the base address of the underlying
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1661
chunk.
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1662
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1663
To obtain the address of the buffer, the offset returned must be added onto the
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1664
base address of the RChunk returned in a call to MapSurface(). Note that
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1665
buffer offsets are immutable during the lifetime of the surface.
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1666
@param aParam The input parameters including the surface ID and buffer index.
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1667
@pre The surface is open in the calling process.
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1668
@return KErrNone if successful, KErrArgument if aSurfaceId or aBuffer are invalid,
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1669
KErrAccessDenied if the surface is not open in the current process, KErrNotSupported if
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1670
the surface is not mappable, otherwise a system wide error code.
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1671
*/
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1672
TInt DSurfaceManager::GetBufferOffset(RSurfaceManagerDriver::TDeviceParam* aParam,TUint* aOffset)
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1673
	{
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1674
	//Get the input parameters
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1675
	RSurfaceManagerDriver::TDeviceParam param;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1676
	kumemget(&param, aParam, sizeof(RSurfaceManagerDriver::TDeviceParam));
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1677
	TSurfaceId sid;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1678
	//fetch surface id from user memory
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1679
	kumemget(&sid, param.iSurfaceId, sizeof(TSurfaceId));
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1680
	//(TAny*)iBuffer holds the buffer number in its value
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1681
	TInt bufferNumber = (TInt) param.iBuffer;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1682
	
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1683
	TSurface* surface = NULL;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1684
	NKern::FMWait(&iMutex);
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1685
	surface = FindSurfaceById(sid);
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1686
	if(NULL == surface || (bufferNumber >= surface->iBuffers))
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1687
		{
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1688
		NKern::FMSignal(&iMutex);
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1689
		return KErrArgument;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1690
		}
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1691
	if(!surface->iMappable)
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1692
		{
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1693
		NKern::FMSignal(&iMutex);
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1694
		return KErrNotSupported;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1695
		}
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1696
	//find the owner
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1697
	TProcessListItem* so = surface->ProcessOwnerInfo(&Kern::CurrentProcess());
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1698
	if (!so)
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1699
		{
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1700
		NKern::FMSignal(&iMutex);
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1701
		return KErrAccessDenied;		
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1702
		}
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1703
	TInt bufferOffset = surface->iOffsetToFirstBuffer + bufferNumber*surface->iOffsetBetweenBuffers;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1704
	NKern::FMSignal(&iMutex);
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1705
	
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1706
	kumemput(aOffset, &bufferOffset, sizeof (TInt));
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1707
	return KErrNone;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1708
	}
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1709
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1710
/**
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1711
Returns information specific to the Surface Manager implementation.
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1712
@param aAttrib: Attribute to retrieve
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1713
@param aValue : Output parameter where we write the value for the specified attribute
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1714
@return KErrNone if successful or KErrArgument if the attribute UID is not recognized
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1715
@internalTechnology
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1716
*/
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1717
TInt DSurfaceManager::GetSurfaceManagerAttrib(RSurfaceManager::TSurfaceManagerAttrib* aAttrib,TInt* aValue)
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1718
	{
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1719
	RSurfaceManager::TSurfaceManagerAttrib attrib;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1720
	kumemget(&attrib, aAttrib, sizeof(RSurfaceManager::TSurfaceManagerAttrib));
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1721
	
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1722
	TInt out=KErrNone;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1723
	TInt value;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1724
	switch (attrib)
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1725
		{
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1726
		case RSurfaceManager::EMaxNumberOfHints:
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1727
			value=KMaxHintsPerSurface;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1728
			break;		
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1729
		
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1730
		default:
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1731
			out=KErrArgument;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1732
			break;			
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1733
		};
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1734
	
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1735
	if (out==KErrNone)
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1736
		{
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1737
		kumemput(aValue, &value, sizeof (TInt));
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1738
		}	
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1739
	return out;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1740
	}
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1741
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1742
#ifdef GRAPHICS_SURFACEMANAGER_SYBORG
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1743
TInt DSurfaceManager::CreateMemory()
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1744
	{
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1745
	Kern::Printf("DSurfaceManager::CreateMemory()>");
2
47632b7dfb88 Refactoring of frame buffer references to surface buffer
Gareth Stockwell <gareth.stockwell@accenture.com>
parents: 0
diff changeset
  1746
	TUint32 physicalAddress = DVirtualVideoHwInterface::GetSurfaceBufferBase();
0
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1747
	Kern::Printf("DSurfaceManager::CreateMemory: 0x%08x",physicalAddress);
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1748
	if( physicalAddress != 0 )
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1749
		{
2
47632b7dfb88 Refactoring of frame buffer references to surface buffer
Gareth Stockwell <gareth.stockwell@accenture.com>
parents: 0
diff changeset
  1750
		iVHWMemoryManager = new DVirtualHWMemoryManager( physicalAddress, VVI_SURFACEBUFFER_MEMORY_SIZE );
0
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1751
		Kern::Printf("DSurfaceManager::CreateMemory: iVHWMemoryManager: 0x%08x",iVHWMemoryManager);
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1752
		}
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1753
	else
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1754
		{
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1755
		iVHWMemoryManager = NULL;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1756
		}
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1757
	return 0;
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1758
	}
91fe342bd9c4 Provide code to deliver both syborg and reference implementations of surface manager.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
  1759
#endif // GRAPHICS_SURFACEMANAGER_SYBORG