os/graphics/graphicsresourceservices/graphicsresourceadaptation/inc/sgdriverimpl.h
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/graphics/graphicsresourceservices/graphicsresourceadaptation/inc/sgdriverimpl.h	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,313 @@
     1.4 +// Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.5 +// All rights reserved.
     1.6 +// This component and the accompanying materials are made available
     1.7 +// under the terms of "Eclipse Public License v1.0"
     1.8 +// which accompanies this distribution, and is available
     1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.10 +//
    1.11 +// Initial Contributors:
    1.12 +// Nokia Corporation - initial contribution.
    1.13 +//
    1.14 +// Contributors:
    1.15 +//
    1.16 +// Description:
    1.17 +//
    1.18 +
    1.19 +/**
    1.20 + @file
    1.21 + @internalComponent
    1.22 +*/
    1.23 +
    1.24 +#ifndef SGDRIVERIMPL_H
    1.25 +#define SGDRIVERIMPL_H
    1.26 +
    1.27 +#include "sgresourceadapter.h"
    1.28 +#include <graphics/surfacemanager.h>
    1.29 +
    1.30 +
    1.31 +/**
    1.32 +@internalComponent
    1.33 +
    1.34 +The category name of the panics raised by Graphics Resource Adapter.
    1.35 +*/
    1.36 +_LIT(KSgResourceAdapterPanicCategory, "SGRES-ADAPTER");
    1.37 +
    1.38 +
    1.39 +/**
    1.40 +The reason numbers of the panics raised by Graphics Resource Adapter.
    1.41 +*/
    1.42 +enum TSgResourceAdapterPanicReason
    1.43 +	{
    1.44 +	/**
    1.45 +	@internalComponent
    1.46 +
    1.47 +	SGRES-ADAPTER 1 In debug builds, an instance of TSgImageInfo is invalid.
    1.48 +	*/
    1.49 +	ESgPanicBadImageInfo = 1,
    1.50 +	/**
    1.51 +	@internalComponent
    1.52 +
    1.53 +	SGRES-ADAPTER 2 In debug builds, the reference count of an object is invalid.
    1.54 +	*/
    1.55 +	ESgPanicBadReferenceCount = 2,
    1.56 +	/**
    1.57 +	@internalComponent
    1.58 +
    1.59 +	SGRES-ADAPTER 3 In debug builds, an internal function in the Graphics Resource
    1.60 +	driver has been called without proper inter-thread synchronisation.
    1.61 +	*/
    1.62 +	ESgPanicMutexNotHeld = 3,
    1.63 +	/**
    1.64 +	@internalTechnology
    1.65 +	@prototype
    1.66 +
    1.67 +	SGRES-ADAPTER 4 In debug builds, an image has not been prepared for CPU access
    1.68 +	to its pixel data.
    1.69 +	*/
    1.70 +	ESgPanicNoCpuAccess = 4,
    1.71 +	/**
    1.72 +	@internalComponent
    1.73 +
    1.74 +	SGRES-ADAPTER 5 In debug builds, an internal function has failed unexpectedly.
    1.75 +	*/
    1.76 +	ESgPanicResourceAdapterGeneral = 5
    1.77 +	};
    1.78 +
    1.79 +
    1.80 +/**
    1.81 +@internalComponent
    1.82 +
    1.83 +Panics the current thread specifying a panic reason from Graphics Resource Adapter.
    1.84 +*/
    1.85 +inline void Panic(TSgResourceAdapterPanicReason aReason);
    1.86 +
    1.87 +
    1.88 +/**
    1.89 +@internalComponent
    1.90 +
    1.91 +Calculates the minimum number of bytes between rows of pixel data for a given
    1.92 +pixel width and pixel format, regardless of alignment.
    1.93 +*/
    1.94 +TInt SgMinDataStride(TInt aWidth, TUidPixelFormat aPixelFormat);
    1.95 +
    1.96 +
    1.97 +/**
    1.98 +@internalComponent
    1.99 +
   1.100 +Calculates the number of bytes between rows of pixel data given the width in 
   1.101 +pixels and the pixel format, taking into consideration the alignment 
   1.102 +requirements of the hardware platform.
   1.103 +*/
   1.104 +TInt SgAlignedDataStride(TInt aWidthInPixels, TUidPixelFormat aPixelFormat);
   1.105 +
   1.106 +
   1.107 +/**
   1.108 +@internalComponent
   1.109 +
   1.110 +Calculates the offset in bytes from the base of the underlying memory chunk to
   1.111 +the first buffer of a surface used to store images.
   1.112 +*/
   1.113 +TInt SgOffsetToFirstBuffer(TInt aMetaDataSize);
   1.114 +
   1.115 +
   1.116 +/**
   1.117 +@internalComponent
   1.118 +
   1.119 +Calculates the size in bytes of a buffer able to store an image with the given
   1.120 +row size in bytes and number of rows.
   1.121 +*/
   1.122 +TInt SgOffsetBetweenBuffers(TInt aDataStride, TInt aScanLineCount);
   1.123 +
   1.124 +
   1.125 +/**
   1.126 +@internalComponent
   1.127 +
   1.128 +Tests whether an instance of TSgImageInfo is valid.
   1.129 +*/
   1.130 +TBool SgIsValidImageInfo(const TSgImageInfo& aInfo);
   1.131 +
   1.132 +
   1.133 +/**
   1.134 +@internalComponent
   1.135 +
   1.136 +Tests whether an instance of TSgImageInfo specifies mutable images.
   1.137 +*/
   1.138 +TBool SgIsMutableImage(const TSgImageInfo& aInfo);
   1.139 +
   1.140 +
   1.141 +/**
   1.142 +@internalComponent
   1.143 +
   1.144 +Tests whether an instance of TSgImageInfo specifies CPU-cached images.
   1.145 +*/
   1.146 +TBool SgIsCachedImage(const TSgImageInfo& aInfo);
   1.147 +
   1.148 +
   1.149 +class XSgDriverImpl;
   1.150 +
   1.151 +/**
   1.152 +@internalComponent
   1.153 +
   1.154 +Base class for all reference-counted classes to be instantiated on the heap for
   1.155 +adapter objects. Instances of derived classes must be allocated on the heap first
   1.156 +and then initialised using the placement new operator.
   1.157 +
   1.158 +This class provides:
   1.159 +	- Initialisation of instances of derived classes to binary zeroes through a
   1.160 +	  specialised placement new operator.
   1.161 +	- A virtual destructor and a Delete() function that allow instances of derived
   1.162 +	  classes to be properly destroyed and deallocated through a pointer to this class.
   1.163 +	- A reference count.
   1.164 +*/
   1.165 +class XSgBase
   1.166 +	{
   1.167 +public:
   1.168 +	virtual ~XSgBase();
   1.169 +	void Delete();
   1.170 +	inline void IncRefCount();
   1.171 +	inline TInt DecRefCount();
   1.172 +	inline TInt RefCount() const;
   1.173 +	inline TAny* operator new(TUint aSize, TAny* aBase);
   1.174 +protected:
   1.175 +	inline XSgBase(XSgDriverImpl& aDriverImpl);
   1.176 +private:
   1.177 +	XSgBase(const XSgBase&);
   1.178 +	const XSgBase& operator =(const XSgBase&);
   1.179 +	TAny* operator new(TUint);
   1.180 +protected:
   1.181 +	XSgDriverImpl& iDriverImpl;
   1.182 +private:
   1.183 +	TInt iRefCount;
   1.184 +	};
   1.185 +
   1.186 +
   1.187 +/**
   1.188 +@internalComponent
   1.189 +
   1.190 +An entry in the pixel format support table.
   1.191 +*/
   1.192 +class TSgPixelFormatTableEntry
   1.193 +	{
   1.194 +public:
   1.195 +	TBool IsMatch(const TSgImageInfo& aInfo) const;
   1.196 +	TBool IsMatchIgnoringPixelFormat(const TSgImageInfo& aInfo) const;
   1.197 +	TBool IsMatchIgnoringUsage(const TSgImageInfo& aInfo) const;
   1.198 +public:
   1.199 +	/**
   1.200 +	The supported pixel format.
   1.201 +	*/
   1.202 +	TUidPixelFormat iPixelFormat;
   1.203 +	/**
   1.204 +	The supported usages.
   1.205 +	*/
   1.206 +	TUint32 iUsage;
   1.207 +	/**
   1.208 +	The supported CPU access.
   1.209 +	*/
   1.210 +	TSgCpuAccess iCpuAccess;
   1.211 +	/**
   1.212 +	The supported screens. A value of -1 is interpreted as meaning that all screens
   1.213 +	are supported. Zero and positive values are interpreted as meaning that only
   1.214 +	the specified screen is supported.
   1.215 +	*/
   1.216 +	TInt iScreenId;
   1.217 +	};
   1.218 +
   1.219 +
   1.220 +class XSgImageImplBase;
   1.221 +class XSgImageCollectionImpl;
   1.222 +
   1.223 +/**
   1.224 +@internalComponent
   1.225 +
   1.226 +The Graphics Resource Adapter singleton class. The initialisation of the Graphics
   1.227 +Resource Adapter singleton consists of the following steps:
   1.228 +	- The heap for adapter objects is created.
   1.229 +	- An instance of the singleton class is allocated on the heap for adapter objects.
   1.230 +	- The C++ constructor is called using the placement new operator and ownership
   1.231 +	  of the heap for adapter objects is transferred to the singleton.
   1.232 +	- The second-phase constructor is called to complete construction of the singleton.
   1.233 +
   1.234 +This class owns a single mutex and provides Wait() and Signal() functions to synchronise
   1.235 +access to all the adapter objects. An alternative could be for each adapter object to
   1.236 +have an associated mutex, but the possible improvement in concurrency does not justify
   1.237 +the costs in systems with only one CPU.
   1.238 +*/
   1.239 +class XSgDriverImpl: public MSgDriverAdapter
   1.240 +	{
   1.241 +public:
   1.242 +	inline XSgDriverImpl(RHeap* aHeap);
   1.243 +	TInt Construct();
   1.244 +	~XSgDriverImpl();
   1.245 +	inline TAny* operator new(TUint aSize, TAny* aBase);
   1.246 +	inline void Wait();
   1.247 +	inline void Signal();
   1.248 +	inline TBool IsMutexHeld() const;
   1.249 +	inline TAny* Alloc(TInt aSize);
   1.250 +	inline void Free(TAny* aCell);
   1.251 +	inline TInt CreateSurface(const RSurfaceManager::TSurfaceCreationAttributesBuf& aReqs, TSurfaceId& aSurfaceId);
   1.252 +	inline TInt CreateSurface(const RSurfaceManager::TSurfaceCreationAttributesBuf& aReqs, TSurfaceId& aSurfaceId, const RChunk& aChunk);
   1.253 +	inline TInt OpenSurface(const TSurfaceId& aSurfaceId);
   1.254 +	inline TInt CloseSurface(const TSurfaceId& aSurfaceId);
   1.255 +	TInt MapSurface(const TSurfaceId& aSurfaceId, RChunk& aChunk);
   1.256 +	inline TInt SurfaceInfo(const TSurfaceId& aSurfaceId, RSurfaceManager::TInfoBuf& aInfo);
   1.257 +	inline TInt SynchronizeCache(const TSurfaceId& aSurfaceId, TInt aBuffer, RSurfaceManager::TSyncOperation aOperation);
   1.258 +	inline TInt GetSurfaceHint(const TSurfaceId& aSurfaceId, RSurfaceManager::THintPair& aHint);
   1.259 +	TArray<TSgPixelFormatTableEntry> PixelFormatTable() const;
   1.260 +	TInt CanCreateImage(const TSgImageInfo& aInfo) const;
   1.261 +	TInt OpenImage(const TSgDrawableId& aId, TUint32 aMode, MSgDrawableAdapter*& aResult);
   1.262 +	void DeleteImage(XSgImageImplBase* aImage);
   1.263 +	void DeleteImageCollection(XSgImageCollectionImpl* aImageCollection);
   1.264 +	// From MSgDriverAdapter
   1.265 +	void Delete();
   1.266 +	TInt GetPixelFormats(const TSgImageInfo& aInfo, TUidPixelFormat* aPixelFormats, TInt& aCount);
   1.267 +	TInt CreateImage(const TSgImageInfo& aInfo, const TAny* aDataAddress, TInt aDataStride, MSgDrawableAdapter*& aResult);
   1.268 +	TInt CreateImage(const TSgImageInfo& aInfo, MSgImageAdapter* aImage, MSgDrawableAdapter*& aResult);
   1.269 +	TInt CreateImageCollection(const TSgImageInfo& aInfo, TInt aImageCount, MSgImageCollectionAdapter*& aResult);
   1.270 +	TInt CreateImageCollections(const TSgImageInfo aInfos[], TInt aImageCount,
   1.271 +	                            MSgImageCollectionAdapter* aCollections[], TInt aCollectionCount);
   1.272 +	TInt OpenDrawable(const TSgDrawableId& aId, TUint32 aMode, TUid aHandleType, MSgDrawableAdapter*& aResult);
   1.273 +	TBool CheckDrawable(const MSgResourceAdapter& aDrawable) const;
   1.274 +	TBool CheckImage(const MSgResourceAdapter& aImage) const;
   1.275 +	TBool CheckImageCollection(const MSgResourceAdapter& aImageCollection) const;
   1.276 +	TInt ResourceCount() const;
   1.277 +	void AllocMarkStart();
   1.278 +	void AllocMarkEnd(TInt aCount);
   1.279 +	void SetAllocFail(RAllocator::TAllocFail aType, TInt aRate);
   1.280 +	TInt GetBufferOffset(const TSurfaceId& aSurfaceID, TInt aBuffer, TInt &aOffset);
   1.281 +	TInt GetSurfaceManagerAttrib(RSurfaceManager::TSurfaceManagerAttrib aAttrib, TInt& aValue);
   1.282 +private:
   1.283 +	XSgDriverImpl(const XSgDriverImpl&);
   1.284 +	TInt ConstructPixelFormatTable();
   1.285 +	const XSgDriverImpl& operator =(const XSgDriverImpl&);
   1.286 +	TAny* operator new(TUint);
   1.287 +private:
   1.288 +	/** Handle to the mutex used to synchronize access to the adapter objects. */
   1.289 +	mutable RMutex iMutex;
   1.290 +	/** Heap on which the adapter objects are allocated. */
   1.291 +	RHeap* iHeap;
   1.292 +	/** Handle to the surface manager. */
   1.293 +	RSurfaceManager iSurfaceManager;
   1.294 +	/** Pixel format support table. */
   1.295 +	RArray<TSgPixelFormatTableEntry> iPixelFormatTable;
   1.296 +	/** Image adapter objects ordered by identifier. */
   1.297 +	RPointerArray<XSgImageImplBase> iImages;
   1.298 +	/** Image collection adapter objects ordered by address. */
   1.299 +	RPointerArray<XSgImageCollectionImpl> iImageCollections;
   1.300 +	/** Size in pixels passed in the last call to GetPixelFormats(). */
   1.301 +	TSize iLastSizeInPixels;
   1.302 +	/** Usage passed in the last call to GetPixelFormats(). */
   1.303 +	TUint32 iLastUsage;
   1.304 +	/** CPU access passed in the last call to GetPixelFormats(). */
   1.305 +	TSgCpuAccess iLastCpuAccess;
   1.306 +	/** Screen identifier passed in the last call to GetPixelFormats(). */
   1.307 +	TInt iLastScreenId;
   1.308 +	/** Results of the last call to GetPixelFormats(). */
   1.309 +	RArray<TUidPixelFormat> iLastPixelFormats;
   1.310 +	};
   1.311 +
   1.312 +
   1.313 +#include "sgdriverimpl.inl"
   1.314 +
   1.315 +
   1.316 +#endif // SGDRIVERIMPL_H