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