graphicsresourceservices/graphicsresourceadaptation/inc/sgdriverimpl.h
changeset 0 5d03bc08d59c
equal deleted inserted replaced
-1:000000000000 0:5d03bc08d59c
       
     1 // Copyright (c) 2007-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  @internalComponent
       
    19 */
       
    20 
       
    21 #ifndef SGDRIVERIMPL_H
       
    22 #define SGDRIVERIMPL_H
       
    23 
       
    24 #include "sgresourceadapter.h"
       
    25 #include <graphics/surfacemanager.h>
       
    26 
       
    27 
       
    28 /**
       
    29 @internalComponent
       
    30 
       
    31 The category name of the panics raised by Graphics Resource Adapter.
       
    32 */
       
    33 _LIT(KSgResourceAdapterPanicCategory, "SGRES-ADAPTER");
       
    34 
       
    35 
       
    36 /**
       
    37 The reason numbers of the panics raised by Graphics Resource Adapter.
       
    38 */
       
    39 enum TSgResourceAdapterPanicReason
       
    40 	{
       
    41 	/**
       
    42 	@internalComponent
       
    43 
       
    44 	SGRES-ADAPTER 1 In debug builds, an instance of TSgImageInfo is invalid.
       
    45 	*/
       
    46 	ESgPanicBadImageInfo = 1,
       
    47 	/**
       
    48 	@internalComponent
       
    49 
       
    50 	SGRES-ADAPTER 2 In debug builds, the reference count of an object is invalid.
       
    51 	*/
       
    52 	ESgPanicBadReferenceCount = 2,
       
    53 	/**
       
    54 	@internalComponent
       
    55 
       
    56 	SGRES-ADAPTER 3 In debug builds, an internal function in the Graphics Resource
       
    57 	driver has been called without proper inter-thread synchronisation.
       
    58 	*/
       
    59 	ESgPanicMutexNotHeld = 3,
       
    60 	/**
       
    61 	@internalTechnology
       
    62 	@prototype
       
    63 
       
    64 	SGRES-ADAPTER 4 In debug builds, an image has not been prepared for CPU access
       
    65 	to its pixel data.
       
    66 	*/
       
    67 	ESgPanicNoCpuAccess = 4,
       
    68 	/**
       
    69 	@internalComponent
       
    70 
       
    71 	SGRES-ADAPTER 5 In debug builds, an internal function has failed unexpectedly.
       
    72 	*/
       
    73 	ESgPanicResourceAdapterGeneral = 5
       
    74 	};
       
    75 
       
    76 
       
    77 /**
       
    78 @internalComponent
       
    79 
       
    80 Panics the current thread specifying a panic reason from Graphics Resource Adapter.
       
    81 */
       
    82 inline void Panic(TSgResourceAdapterPanicReason aReason);
       
    83 
       
    84 
       
    85 /**
       
    86 @internalComponent
       
    87 
       
    88 Calculates the minimum number of bytes between rows of pixel data for a given
       
    89 pixel width and pixel format, regardless of alignment.
       
    90 */
       
    91 TInt SgMinDataStride(TInt aWidth, TUidPixelFormat aPixelFormat);
       
    92 
       
    93 
       
    94 /**
       
    95 @internalComponent
       
    96 
       
    97 Calculates the number of bytes between rows of pixel data given the width in 
       
    98 pixels and the pixel format, taking into consideration the alignment 
       
    99 requirements of the hardware platform.
       
   100 */
       
   101 TInt SgAlignedDataStride(TInt aWidthInPixels, TUidPixelFormat aPixelFormat);
       
   102 
       
   103 
       
   104 /**
       
   105 @internalComponent
       
   106 
       
   107 Calculates the offset in bytes from the base of the underlying memory chunk to
       
   108 the first buffer of a surface used to store images.
       
   109 */
       
   110 TInt SgOffsetToFirstBuffer(TInt aMetaDataSize);
       
   111 
       
   112 
       
   113 /**
       
   114 @internalComponent
       
   115 
       
   116 Calculates the size in bytes of a buffer able to store an image with the given
       
   117 row size in bytes and number of rows.
       
   118 */
       
   119 TInt SgOffsetBetweenBuffers(TInt aDataStride, TInt aScanLineCount);
       
   120 
       
   121 
       
   122 /**
       
   123 @internalComponent
       
   124 
       
   125 Tests whether an instance of TSgImageInfo is valid.
       
   126 */
       
   127 TBool SgIsValidImageInfo(const TSgImageInfo& aInfo);
       
   128 
       
   129 
       
   130 /**
       
   131 @internalComponent
       
   132 
       
   133 Tests whether an instance of TSgImageInfo specifies mutable images.
       
   134 */
       
   135 TBool SgIsMutableImage(const TSgImageInfo& aInfo);
       
   136 
       
   137 
       
   138 /**
       
   139 @internalComponent
       
   140 
       
   141 Tests whether an instance of TSgImageInfo specifies CPU-cached images.
       
   142 */
       
   143 TBool SgIsCachedImage(const TSgImageInfo& aInfo);
       
   144 
       
   145 
       
   146 class XSgDriverImpl;
       
   147 
       
   148 /**
       
   149 @internalComponent
       
   150 
       
   151 Base class for all reference-counted classes to be instantiated on the heap for
       
   152 adapter objects. Instances of derived classes must be allocated on the heap first
       
   153 and then initialised using the placement new operator.
       
   154 
       
   155 This class provides:
       
   156 	- Initialisation of instances of derived classes to binary zeroes through a
       
   157 	  specialised placement new operator.
       
   158 	- A virtual destructor and a Delete() function that allow instances of derived
       
   159 	  classes to be properly destroyed and deallocated through a pointer to this class.
       
   160 	- A reference count.
       
   161 */
       
   162 class XSgBase
       
   163 	{
       
   164 public:
       
   165 	virtual ~XSgBase();
       
   166 	void Delete();
       
   167 	inline void IncRefCount();
       
   168 	inline TInt DecRefCount();
       
   169 	inline TInt RefCount() const;
       
   170 	inline TAny* operator new(TUint aSize, TAny* aBase);
       
   171 protected:
       
   172 	inline XSgBase(XSgDriverImpl& aDriverImpl);
       
   173 private:
       
   174 	XSgBase(const XSgBase&);
       
   175 	const XSgBase& operator =(const XSgBase&);
       
   176 	TAny* operator new(TUint);
       
   177 protected:
       
   178 	XSgDriverImpl& iDriverImpl;
       
   179 private:
       
   180 	TInt iRefCount;
       
   181 	};
       
   182 
       
   183 
       
   184 /**
       
   185 @internalComponent
       
   186 
       
   187 An entry in the pixel format support table.
       
   188 */
       
   189 class TSgPixelFormatTableEntry
       
   190 	{
       
   191 public:
       
   192 	TBool IsMatch(const TSgImageInfo& aInfo) const;
       
   193 	TBool IsMatchIgnoringPixelFormat(const TSgImageInfo& aInfo) const;
       
   194 	TBool IsMatchIgnoringUsage(const TSgImageInfo& aInfo) const;
       
   195 public:
       
   196 	/**
       
   197 	The supported pixel format.
       
   198 	*/
       
   199 	TUidPixelFormat iPixelFormat;
       
   200 	/**
       
   201 	The supported usages.
       
   202 	*/
       
   203 	TUint32 iUsage;
       
   204 	/**
       
   205 	The supported CPU access.
       
   206 	*/
       
   207 	TSgCpuAccess iCpuAccess;
       
   208 	/**
       
   209 	The supported screens. A value of -1 is interpreted as meaning that all screens
       
   210 	are supported. Zero and positive values are interpreted as meaning that only
       
   211 	the specified screen is supported.
       
   212 	*/
       
   213 	TInt iScreenId;
       
   214 	};
       
   215 
       
   216 
       
   217 class XSgImageImplBase;
       
   218 class XSgImageCollectionImpl;
       
   219 
       
   220 /**
       
   221 @internalComponent
       
   222 
       
   223 The Graphics Resource Adapter singleton class. The initialisation of the Graphics
       
   224 Resource Adapter singleton consists of the following steps:
       
   225 	- The heap for adapter objects is created.
       
   226 	- An instance of the singleton class is allocated on the heap for adapter objects.
       
   227 	- The C++ constructor is called using the placement new operator and ownership
       
   228 	  of the heap for adapter objects is transferred to the singleton.
       
   229 	- The second-phase constructor is called to complete construction of the singleton.
       
   230 
       
   231 This class owns a single mutex and provides Wait() and Signal() functions to synchronise
       
   232 access to all the adapter objects. An alternative could be for each adapter object to
       
   233 have an associated mutex, but the possible improvement in concurrency does not justify
       
   234 the costs in systems with only one CPU.
       
   235 */
       
   236 class XSgDriverImpl: public MSgDriverAdapter
       
   237 	{
       
   238 public:
       
   239 	inline XSgDriverImpl(RHeap* aHeap);
       
   240 	TInt Construct();
       
   241 	~XSgDriverImpl();
       
   242 	inline TAny* operator new(TUint aSize, TAny* aBase);
       
   243 	inline void Wait();
       
   244 	inline void Signal();
       
   245 	inline TBool IsMutexHeld() const;
       
   246 	inline TAny* Alloc(TInt aSize);
       
   247 	inline void Free(TAny* aCell);
       
   248 	inline TInt CreateSurface(const RSurfaceManager::TSurfaceCreationAttributesBuf& aReqs, TSurfaceId& aSurfaceId);
       
   249 	inline TInt CreateSurface(const RSurfaceManager::TSurfaceCreationAttributesBuf& aReqs, TSurfaceId& aSurfaceId, const RChunk& aChunk);
       
   250 	inline TInt OpenSurface(const TSurfaceId& aSurfaceId);
       
   251 	inline TInt CloseSurface(const TSurfaceId& aSurfaceId);
       
   252 	TInt MapSurface(const TSurfaceId& aSurfaceId, RChunk& aChunk);
       
   253 	inline TInt SurfaceInfo(const TSurfaceId& aSurfaceId, RSurfaceManager::TInfoBuf& aInfo);
       
   254 	inline TInt SynchronizeCache(const TSurfaceId& aSurfaceId, TInt aBuffer, RSurfaceManager::TSyncOperation aOperation);
       
   255 	inline TInt GetSurfaceHint(const TSurfaceId& aSurfaceId, RSurfaceManager::THintPair& aHint);
       
   256 	TArray<TSgPixelFormatTableEntry> PixelFormatTable() const;
       
   257 	TInt CanCreateImage(const TSgImageInfo& aInfo) const;
       
   258 	TInt OpenImage(const TSgDrawableId& aId, TUint32 aMode, MSgDrawableAdapter*& aResult);
       
   259 	void DeleteImage(XSgImageImplBase* aImage);
       
   260 	void DeleteImageCollection(XSgImageCollectionImpl* aImageCollection);
       
   261 	// From MSgDriverAdapter
       
   262 	void Delete();
       
   263 	TInt GetPixelFormats(const TSgImageInfo& aInfo, TUidPixelFormat* aPixelFormats, TInt& aCount);
       
   264 	TInt CreateImage(const TSgImageInfo& aInfo, const TAny* aDataAddress, TInt aDataStride, MSgDrawableAdapter*& aResult);
       
   265 	TInt CreateImage(const TSgImageInfo& aInfo, MSgImageAdapter* aImage, MSgDrawableAdapter*& aResult);
       
   266 	TInt CreateImageCollection(const TSgImageInfo& aInfo, TInt aImageCount, MSgImageCollectionAdapter*& aResult);
       
   267 	TInt CreateImageCollections(const TSgImageInfo aInfos[], TInt aImageCount,
       
   268 	                            MSgImageCollectionAdapter* aCollections[], TInt aCollectionCount);
       
   269 	TInt OpenDrawable(const TSgDrawableId& aId, TUint32 aMode, TUid aHandleType, MSgDrawableAdapter*& aResult);
       
   270 	TBool CheckDrawable(const MSgResourceAdapter& aDrawable) const;
       
   271 	TBool CheckImage(const MSgResourceAdapter& aImage) const;
       
   272 	TBool CheckImageCollection(const MSgResourceAdapter& aImageCollection) const;
       
   273 	TInt ResourceCount() const;
       
   274 	void AllocMarkStart();
       
   275 	void AllocMarkEnd(TInt aCount);
       
   276 	void SetAllocFail(RAllocator::TAllocFail aType, TInt aRate);
       
   277 	TInt GetBufferOffset(const TSurfaceId& aSurfaceID, TInt aBuffer, TInt &aOffset);
       
   278 	TInt GetSurfaceManagerAttrib(RSurfaceManager::TSurfaceManagerAttrib aAttrib, TInt& aValue);
       
   279 private:
       
   280 	XSgDriverImpl(const XSgDriverImpl&);
       
   281 	TInt ConstructPixelFormatTable();
       
   282 	const XSgDriverImpl& operator =(const XSgDriverImpl&);
       
   283 	TAny* operator new(TUint);
       
   284 private:
       
   285 	/** Handle to the mutex used to synchronize access to the adapter objects. */
       
   286 	mutable RMutex iMutex;
       
   287 	/** Heap on which the adapter objects are allocated. */
       
   288 	RHeap* iHeap;
       
   289 	/** Handle to the surface manager. */
       
   290 	RSurfaceManager iSurfaceManager;
       
   291 	/** Pixel format support table. */
       
   292 	RArray<TSgPixelFormatTableEntry> iPixelFormatTable;
       
   293 	/** Image adapter objects ordered by identifier. */
       
   294 	RPointerArray<XSgImageImplBase> iImages;
       
   295 	/** Image collection adapter objects ordered by address. */
       
   296 	RPointerArray<XSgImageCollectionImpl> iImageCollections;
       
   297 	/** Size in pixels passed in the last call to GetPixelFormats(). */
       
   298 	TSize iLastSizeInPixels;
       
   299 	/** Usage passed in the last call to GetPixelFormats(). */
       
   300 	TUint32 iLastUsage;
       
   301 	/** CPU access passed in the last call to GetPixelFormats(). */
       
   302 	TSgCpuAccess iLastCpuAccess;
       
   303 	/** Screen identifier passed in the last call to GetPixelFormats(). */
       
   304 	TInt iLastScreenId;
       
   305 	/** Results of the last call to GetPixelFormats(). */
       
   306 	RArray<TUidPixelFormat> iLastPixelFormats;
       
   307 	};
       
   308 
       
   309 
       
   310 #include "sgdriverimpl.inl"
       
   311 
       
   312 
       
   313 #endif // SGDRIVERIMPL_H