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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
22 #ifndef __SURFACEMANAGER_DEV_H__
23 #define __SURFACEMANAGER_DEV_H__
25 #include <graphics/surface.h>
26 #include "surfacemanagerdriver.h"
34 /** Maximum number of HintPairs per surface */
35 const TInt KMaxHintsPerSurface = 16;
37 /** Maximum number of elements in the table. This value must be a power of 2 */
41 Logical Device (factory class) for Surface manager
43 class DSurfaceManagerFactory : public DLogicalDevice
46 DSurfaceManagerFactory();
48 void GetCaps(TDes8& aDes) const;
49 TInt Create(DLogicalChannelBase*& aChannel);
54 Logical Channel class for SurfaceManager
56 class DSurfaceManagerChannel : public DLogicalChannelBase
59 DSurfaceManagerChannel();
60 ~DSurfaceManagerChannel();
62 // Inherited from DLogicalChannelBase
63 TInt DoCreate(TInt aUnit, const TDesC8* aInfo, const TVersion& aVer);
64 TInt Request(TInt aReqNo, TAny* a1, TAny* a2);
66 // Implementation for the different kinds of messages sent through RBusLogicalChannel
67 TInt DoControl(TInt aFunction, TAny* a1, TAny* a2);
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.
80 class TProcessListItem
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
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.
95 class TSurface //one of these per surface
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
115 TProcessListItem* ProcessOwnerInfo(const DProcess* aProcess);
122 Surface manager extension object.
123 There is one static instance of this in the kernel extension.
126 class DSurfaceManager : public DBase
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);
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;
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