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