os/graphics/graphicshwdrivers/surfacemgr/src/surfacemanager_dev.h
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
sl@0
     1
// Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     2
// All rights reserved.
sl@0
     3
// This component and the accompanying materials are made available
sl@0
     4
// under the terms of "Eclipse Public License v1.0"
sl@0
     5
// which accompanies this distribution, and is available
sl@0
     6
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     7
//
sl@0
     8
// Initial Contributors:
sl@0
     9
// Nokia Corporation - initial contribution.
sl@0
    10
//
sl@0
    11
// Contributors:
sl@0
    12
//
sl@0
    13
// Description:
sl@0
    14
//
sl@0
    15
sl@0
    16
/**
sl@0
    17
 @file
sl@0
    18
 @publishedPartner
sl@0
    19
 @prototype
sl@0
    20
*/
sl@0
    21
sl@0
    22
#ifndef __SURFACEMANAGER_DEV_H__
sl@0
    23
#define __SURFACEMANAGER_DEV_H__
sl@0
    24
sl@0
    25
#include <graphics/surface.h>
sl@0
    26
#include "surfacemanagerdriver.h"
sl@0
    27
sl@0
    28
#if 0
sl@0
    29
#define TRACE(x) x
sl@0
    30
#else
sl@0
    31
#define TRACE(x)
sl@0
    32
#endif
sl@0
    33
sl@0
    34
/** Maximum number of HintPairs per surface */
sl@0
    35
const TInt KMaxHintsPerSurface = 16;
sl@0
    36
sl@0
    37
/** Maximum number of elements in the table. This value must be a power of 2 */
sl@0
    38
#define KMaxLists 16
sl@0
    39
sl@0
    40
/**
sl@0
    41
  Logical Device (factory class) for Surface manager
sl@0
    42
*/
sl@0
    43
class DSurfaceManagerFactory : public DLogicalDevice
sl@0
    44
	{
sl@0
    45
public:
sl@0
    46
	DSurfaceManagerFactory();
sl@0
    47
	TInt Install();
sl@0
    48
	void GetCaps(TDes8& aDes) const;
sl@0
    49
	TInt Create(DLogicalChannelBase*& aChannel);
sl@0
    50
	};
sl@0
    51
sl@0
    52
sl@0
    53
/**
sl@0
    54
  Logical Channel class for SurfaceManager
sl@0
    55
*/
sl@0
    56
class DSurfaceManagerChannel : public DLogicalChannelBase
sl@0
    57
	{
sl@0
    58
public:
sl@0
    59
	DSurfaceManagerChannel();
sl@0
    60
	~DSurfaceManagerChannel();
sl@0
    61
sl@0
    62
	// Inherited from DLogicalChannelBase
sl@0
    63
	TInt DoCreate(TInt aUnit, const TDesC8* aInfo, const TVersion& aVer);
sl@0
    64
	TInt Request(TInt aReqNo, TAny* a1, TAny* a2);
sl@0
    65
private:
sl@0
    66
	// Implementation for the different kinds of messages sent through RBusLogicalChannel
sl@0
    67
	TInt DoControl(TInt aFunction, TAny* a1, TAny* a2);
sl@0
    68
sl@0
    69
private:
sl@0
    70
	DProcess* iOwner;
sl@0
    71
	};
sl@0
    72
sl@0
    73
sl@0
    74
/**
sl@0
    75
Class to hold a reference count and process pointer. 
sl@0
    76
Each surface has a linked list of these owning processes.
sl@0
    77
The surface manager has a linked list of these to track connections.
sl@0
    78
@internalTechnology
sl@0
    79
*/
sl@0
    80
class TProcessListItem
sl@0
    81
	{
sl@0
    82
public:
sl@0
    83
	TProcessListItem* iNext;	//pointer to next one in list
sl@0
    84
	DProcess* iOwningProcess;	//pointer to the process object which is being reference counted
sl@0
    85
	TInt iCount;				//reference count
sl@0
    86
	};
sl@0
    87
	
sl@0
    88
sl@0
    89
/**
sl@0
    90
Class to hold the information about a surface.
sl@0
    91
Each surface has a linked list of owners.  The surfaces are arranged in a linked list,
sl@0
    92
with these objects being elements in the list.
sl@0
    93
@internalTechnology
sl@0
    94
*/
sl@0
    95
class TSurface					//one of these per surface
sl@0
    96
	{
sl@0
    97
public:
sl@0
    98
	TSurface* iNext;			//singly linked list, points to next surface
sl@0
    99
	TSurfaceId	iId;			//the surface id
sl@0
   100
	TSize iSize;				//pixel width/height
sl@0
   101
	TInt iBuffers;				//number of buffers
sl@0
   102
	TUidPixelFormat iPixelFormat;			//pixel format
sl@0
   103
	TInt iStride;				//offset from start of one line to the next, in bytes
sl@0
   104
	TInt iOffsetToFirstBuffer;	//offset between the start of the surface memory and the start of the first pixel buffer
sl@0
   105
	TInt iOffsetBetweenBuffers;	//offset between pixel buffers
sl@0
   106
	TInt  iAlignment;			//byte alignment of the pixel buffers
sl@0
   107
	TBool iContiguous;			//if it is in contiguous physical memory
sl@0
   108
	DChunk* iChunk;				//ptr to the shared chunk
sl@0
   109
	RSurfaceManager::TCacheAttribute iCacheAttrib;			//Caching attribute to create chunks memory
sl@0
   110
	RSurfaceManager::THintPair iSurfaceHints[KMaxHintsPerSurface];	//Arbitrary key-value pairs associated with a surface
sl@0
   111
	TBool iMappable;			//Is the Surface Mappable
sl@0
   112
	TProcessListItem* iOwners;	//owner list. Singly linked list, points to next surface owner
sl@0
   113
sl@0
   114
public:	
sl@0
   115
	TProcessListItem* ProcessOwnerInfo(const DProcess* aProcess);
sl@0
   116
	};
sl@0
   117
	
sl@0
   118
sl@0
   119
sl@0
   120
sl@0
   121
/**
sl@0
   122
Surface manager extension object.
sl@0
   123
There is one static instance of this in the kernel extension.
sl@0
   124
@internalTechnology
sl@0
   125
*/
sl@0
   126
class DSurfaceManager : public DBase
sl@0
   127
	{
sl@0
   128
public:
sl@0
   129
	TInt CreateSurface(const TDesC8* aConfig, TSurfaceId* aId);
sl@0
   130
	TInt SurfaceInfo(const TSurfaceId* aId, TDes8* aInfo);
sl@0
   131
	TInt OpenSurface(const TSurfaceId* aId);
sl@0
   132
	TInt CloseSurface(const TSurfaceId* aId);
sl@0
   133
	TInt MapSurface(const TSurfaceId* aId);
sl@0
   134
	TInt AddConnection(const DProcess* iProcess);
sl@0
   135
	void RemoveConnection(const DProcess* iProcess);
sl@0
   136
	TInt CreateSurface(RSurfaceManagerDriver::TDeviceParam* aParam, TInt aChunkHandle);
sl@0
   137
	TInt SynchronizeCache(RSurfaceManagerDriver::TDeviceParam* aId, RSurfaceManager::TSyncOperation aOperation);
sl@0
   138
	TInt GetSurfaceHint(const TSurfaceId* aSurfaceId, RSurfaceManager::THintPair* aHintPair);
sl@0
   139
	TInt SetSurfaceHint(const TSurfaceId* aSurfaceId, const RSurfaceManager::THintPair* aHintPair);
sl@0
   140
	TInt AddSurfaceHint(const TSurfaceId* aSurfaceId, const RSurfaceManager::THintPair* aHintPair);
sl@0
   141
	TInt GetBufferOffset(RSurfaceManagerDriver::TDeviceParam* aParam,TUint* aOffset);
sl@0
   142
	TInt GetSurfaceManagerAttrib(RSurfaceManager::TSurfaceManagerAttrib* aAttrib,TInt* aValue);
sl@0
   143
private:
sl@0
   144
	void GenerateSurfaceId(TSurfaceId& aId);
sl@0
   145
	TInt  CreateSurfaceChunk(const RSurfaceManager::TSurfaceCreationAttributes& attribs);
sl@0
   146
	TInt ValidateAndCalculateChunkSize(RSurfaceManager::TSurfaceCreationAttributes& aAttribs, TInt& aOffset, 
sl@0
   147
			TUint& aActualBufferSize, const TBool aNewChunk = EFalse);
sl@0
   148
	TInt ValidatePhysicalMemory(DChunk* aChunk, const RSurfaceManager::TSurfaceCreationAttributes& aAttribs, 
sl@0
   149
			TUint aBuffersize, TUint32& aMapAttr, TBool &aIsContiguous); 
sl@0
   150
	TSurface* FindSurfaceById(const TSurfaceId& aId);
sl@0
   151
	void CloseSurfaceHandlesForProcess(const DProcess* iProcess);
sl@0
   152
	TProcessListItem* FindConnectedProcess(const DProcess* aProcess);
sl@0
   153
	TInt FindHintKey(const RSurfaceManager::THintPair* aHints, TUint32 aKey) const;
sl@0
   154
	TBool SortHints(RSurfaceManager::THintPair* aHints, TInt aNumberOfHints) const;
sl@0
   155
	TInt InsertHintKey(RSurfaceManager::THintPair* aHints, const RSurfaceManager::THintPair& aHintPair) const;
sl@0
   156
sl@0
   157
private:
sl@0
   158
	TSurface* iSurfacesIndex[KMaxLists]; 			// A table with elements pointing to the head of each singly linked list
sl@0
   159
	NFastMutex iMutex;						// Mutex to protect access to surface lists
sl@0
   160
	TProcessListItem* iConnectedProcesses;	//reference counted list of processes connected to the driver
sl@0
   161
	};
sl@0
   162
sl@0
   163
sl@0
   164
#endif
sl@0
   165
sl@0
   166
sl@0
   167
sl@0
   168
sl@0
   169