sl@0: // Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // sl@0: sl@0: /** sl@0: @file sl@0: @internalComponent sl@0: */ sl@0: sl@0: #ifndef SGDRIVERIMPL_H sl@0: #define SGDRIVERIMPL_H sl@0: sl@0: #include "sgresourceadapter.h" sl@0: #include sl@0: sl@0: sl@0: /** sl@0: @internalComponent sl@0: sl@0: The category name of the panics raised by Graphics Resource Adapter. sl@0: */ sl@0: _LIT(KSgResourceAdapterPanicCategory, "SGRES-ADAPTER"); sl@0: sl@0: sl@0: /** sl@0: The reason numbers of the panics raised by Graphics Resource Adapter. sl@0: */ sl@0: enum TSgResourceAdapterPanicReason sl@0: { sl@0: /** sl@0: @internalComponent sl@0: sl@0: SGRES-ADAPTER 1 In debug builds, an instance of TSgImageInfo is invalid. sl@0: */ sl@0: ESgPanicBadImageInfo = 1, sl@0: /** sl@0: @internalComponent sl@0: sl@0: SGRES-ADAPTER 2 In debug builds, the reference count of an object is invalid. sl@0: */ sl@0: ESgPanicBadReferenceCount = 2, sl@0: /** sl@0: @internalComponent sl@0: sl@0: SGRES-ADAPTER 3 In debug builds, an internal function in the Graphics Resource sl@0: driver has been called without proper inter-thread synchronisation. sl@0: */ sl@0: ESgPanicMutexNotHeld = 3, sl@0: /** sl@0: @internalTechnology sl@0: @prototype sl@0: sl@0: SGRES-ADAPTER 4 In debug builds, an image has not been prepared for CPU access sl@0: to its pixel data. sl@0: */ sl@0: ESgPanicNoCpuAccess = 4, sl@0: /** sl@0: @internalComponent sl@0: sl@0: SGRES-ADAPTER 5 In debug builds, an internal function has failed unexpectedly. sl@0: */ sl@0: ESgPanicResourceAdapterGeneral = 5 sl@0: }; sl@0: sl@0: sl@0: /** sl@0: @internalComponent sl@0: sl@0: Panics the current thread specifying a panic reason from Graphics Resource Adapter. sl@0: */ sl@0: inline void Panic(TSgResourceAdapterPanicReason aReason); sl@0: sl@0: sl@0: /** sl@0: @internalComponent sl@0: sl@0: Calculates the minimum number of bytes between rows of pixel data for a given sl@0: pixel width and pixel format, regardless of alignment. sl@0: */ sl@0: TInt SgMinDataStride(TInt aWidth, TUidPixelFormat aPixelFormat); sl@0: sl@0: sl@0: /** sl@0: @internalComponent sl@0: sl@0: Calculates the number of bytes between rows of pixel data given the width in sl@0: pixels and the pixel format, taking into consideration the alignment sl@0: requirements of the hardware platform. sl@0: */ sl@0: TInt SgAlignedDataStride(TInt aWidthInPixels, TUidPixelFormat aPixelFormat); sl@0: sl@0: sl@0: /** sl@0: @internalComponent sl@0: sl@0: Calculates the offset in bytes from the base of the underlying memory chunk to sl@0: the first buffer of a surface used to store images. sl@0: */ sl@0: TInt SgOffsetToFirstBuffer(TInt aMetaDataSize); sl@0: sl@0: sl@0: /** sl@0: @internalComponent sl@0: sl@0: Calculates the size in bytes of a buffer able to store an image with the given sl@0: row size in bytes and number of rows. sl@0: */ sl@0: TInt SgOffsetBetweenBuffers(TInt aDataStride, TInt aScanLineCount); sl@0: sl@0: sl@0: /** sl@0: @internalComponent sl@0: sl@0: Tests whether an instance of TSgImageInfo is valid. sl@0: */ sl@0: TBool SgIsValidImageInfo(const TSgImageInfo& aInfo); sl@0: sl@0: sl@0: /** sl@0: @internalComponent sl@0: sl@0: Tests whether an instance of TSgImageInfo specifies mutable images. sl@0: */ sl@0: TBool SgIsMutableImage(const TSgImageInfo& aInfo); sl@0: sl@0: sl@0: /** sl@0: @internalComponent sl@0: sl@0: Tests whether an instance of TSgImageInfo specifies CPU-cached images. sl@0: */ sl@0: TBool SgIsCachedImage(const TSgImageInfo& aInfo); sl@0: sl@0: sl@0: class XSgDriverImpl; sl@0: sl@0: /** sl@0: @internalComponent sl@0: sl@0: Base class for all reference-counted classes to be instantiated on the heap for sl@0: adapter objects. Instances of derived classes must be allocated on the heap first sl@0: and then initialised using the placement new operator. sl@0: sl@0: This class provides: sl@0: - Initialisation of instances of derived classes to binary zeroes through a sl@0: specialised placement new operator. sl@0: - A virtual destructor and a Delete() function that allow instances of derived sl@0: classes to be properly destroyed and deallocated through a pointer to this class. sl@0: - A reference count. sl@0: */ sl@0: class XSgBase sl@0: { sl@0: public: sl@0: virtual ~XSgBase(); sl@0: void Delete(); sl@0: inline void IncRefCount(); sl@0: inline TInt DecRefCount(); sl@0: inline TInt RefCount() const; sl@0: inline TAny* operator new(TUint aSize, TAny* aBase); sl@0: protected: sl@0: inline XSgBase(XSgDriverImpl& aDriverImpl); sl@0: private: sl@0: XSgBase(const XSgBase&); sl@0: const XSgBase& operator =(const XSgBase&); sl@0: TAny* operator new(TUint); sl@0: protected: sl@0: XSgDriverImpl& iDriverImpl; sl@0: private: sl@0: TInt iRefCount; sl@0: }; sl@0: sl@0: sl@0: /** sl@0: @internalComponent sl@0: sl@0: An entry in the pixel format support table. sl@0: */ sl@0: class TSgPixelFormatTableEntry sl@0: { sl@0: public: sl@0: TBool IsMatch(const TSgImageInfo& aInfo) const; sl@0: TBool IsMatchIgnoringPixelFormat(const TSgImageInfo& aInfo) const; sl@0: TBool IsMatchIgnoringUsage(const TSgImageInfo& aInfo) const; sl@0: public: sl@0: /** sl@0: The supported pixel format. sl@0: */ sl@0: TUidPixelFormat iPixelFormat; sl@0: /** sl@0: The supported usages. sl@0: */ sl@0: TUint32 iUsage; sl@0: /** sl@0: The supported CPU access. sl@0: */ sl@0: TSgCpuAccess iCpuAccess; sl@0: /** sl@0: The supported screens. A value of -1 is interpreted as meaning that all screens sl@0: are supported. Zero and positive values are interpreted as meaning that only sl@0: the specified screen is supported. sl@0: */ sl@0: TInt iScreenId; sl@0: }; sl@0: sl@0: sl@0: class XSgImageImplBase; sl@0: class XSgImageCollectionImpl; sl@0: sl@0: /** sl@0: @internalComponent sl@0: sl@0: The Graphics Resource Adapter singleton class. The initialisation of the Graphics sl@0: Resource Adapter singleton consists of the following steps: sl@0: - The heap for adapter objects is created. sl@0: - An instance of the singleton class is allocated on the heap for adapter objects. sl@0: - The C++ constructor is called using the placement new operator and ownership sl@0: of the heap for adapter objects is transferred to the singleton. sl@0: - The second-phase constructor is called to complete construction of the singleton. sl@0: sl@0: This class owns a single mutex and provides Wait() and Signal() functions to synchronise sl@0: access to all the adapter objects. An alternative could be for each adapter object to sl@0: have an associated mutex, but the possible improvement in concurrency does not justify sl@0: the costs in systems with only one CPU. sl@0: */ sl@0: class XSgDriverImpl: public MSgDriverAdapter sl@0: { sl@0: public: sl@0: inline XSgDriverImpl(RHeap* aHeap); sl@0: TInt Construct(); sl@0: ~XSgDriverImpl(); sl@0: inline TAny* operator new(TUint aSize, TAny* aBase); sl@0: inline void Wait(); sl@0: inline void Signal(); sl@0: inline TBool IsMutexHeld() const; sl@0: inline TAny* Alloc(TInt aSize); sl@0: inline void Free(TAny* aCell); sl@0: inline TInt CreateSurface(const RSurfaceManager::TSurfaceCreationAttributesBuf& aReqs, TSurfaceId& aSurfaceId); sl@0: inline TInt CreateSurface(const RSurfaceManager::TSurfaceCreationAttributesBuf& aReqs, TSurfaceId& aSurfaceId, const RChunk& aChunk); sl@0: inline TInt OpenSurface(const TSurfaceId& aSurfaceId); sl@0: inline TInt CloseSurface(const TSurfaceId& aSurfaceId); sl@0: TInt MapSurface(const TSurfaceId& aSurfaceId, RChunk& aChunk); sl@0: inline TInt SurfaceInfo(const TSurfaceId& aSurfaceId, RSurfaceManager::TInfoBuf& aInfo); sl@0: inline TInt SynchronizeCache(const TSurfaceId& aSurfaceId, TInt aBuffer, RSurfaceManager::TSyncOperation aOperation); sl@0: inline TInt GetSurfaceHint(const TSurfaceId& aSurfaceId, RSurfaceManager::THintPair& aHint); sl@0: TArray PixelFormatTable() const; sl@0: TInt CanCreateImage(const TSgImageInfo& aInfo) const; sl@0: TInt OpenImage(const TSgDrawableId& aId, TUint32 aMode, MSgDrawableAdapter*& aResult); sl@0: void DeleteImage(XSgImageImplBase* aImage); sl@0: void DeleteImageCollection(XSgImageCollectionImpl* aImageCollection); sl@0: // From MSgDriverAdapter sl@0: void Delete(); sl@0: TInt GetPixelFormats(const TSgImageInfo& aInfo, TUidPixelFormat* aPixelFormats, TInt& aCount); sl@0: TInt CreateImage(const TSgImageInfo& aInfo, const TAny* aDataAddress, TInt aDataStride, MSgDrawableAdapter*& aResult); sl@0: TInt CreateImage(const TSgImageInfo& aInfo, MSgImageAdapter* aImage, MSgDrawableAdapter*& aResult); sl@0: TInt CreateImageCollection(const TSgImageInfo& aInfo, TInt aImageCount, MSgImageCollectionAdapter*& aResult); sl@0: TInt CreateImageCollections(const TSgImageInfo aInfos[], TInt aImageCount, sl@0: MSgImageCollectionAdapter* aCollections[], TInt aCollectionCount); sl@0: TInt OpenDrawable(const TSgDrawableId& aId, TUint32 aMode, TUid aHandleType, MSgDrawableAdapter*& aResult); sl@0: TBool CheckDrawable(const MSgResourceAdapter& aDrawable) const; sl@0: TBool CheckImage(const MSgResourceAdapter& aImage) const; sl@0: TBool CheckImageCollection(const MSgResourceAdapter& aImageCollection) const; sl@0: TInt ResourceCount() const; sl@0: void AllocMarkStart(); sl@0: void AllocMarkEnd(TInt aCount); sl@0: void SetAllocFail(RAllocator::TAllocFail aType, TInt aRate); sl@0: TInt GetBufferOffset(const TSurfaceId& aSurfaceID, TInt aBuffer, TInt &aOffset); sl@0: TInt GetSurfaceManagerAttrib(RSurfaceManager::TSurfaceManagerAttrib aAttrib, TInt& aValue); sl@0: private: sl@0: XSgDriverImpl(const XSgDriverImpl&); sl@0: TInt ConstructPixelFormatTable(); sl@0: const XSgDriverImpl& operator =(const XSgDriverImpl&); sl@0: TAny* operator new(TUint); sl@0: private: sl@0: /** Handle to the mutex used to synchronize access to the adapter objects. */ sl@0: mutable RMutex iMutex; sl@0: /** Heap on which the adapter objects are allocated. */ sl@0: RHeap* iHeap; sl@0: /** Handle to the surface manager. */ sl@0: RSurfaceManager iSurfaceManager; sl@0: /** Pixel format support table. */ sl@0: RArray iPixelFormatTable; sl@0: /** Image adapter objects ordered by identifier. */ sl@0: RPointerArray iImages; sl@0: /** Image collection adapter objects ordered by address. */ sl@0: RPointerArray iImageCollections; sl@0: /** Size in pixels passed in the last call to GetPixelFormats(). */ sl@0: TSize iLastSizeInPixels; sl@0: /** Usage passed in the last call to GetPixelFormats(). */ sl@0: TUint32 iLastUsage; sl@0: /** CPU access passed in the last call to GetPixelFormats(). */ sl@0: TSgCpuAccess iLastCpuAccess; sl@0: /** Screen identifier passed in the last call to GetPixelFormats(). */ sl@0: TInt iLastScreenId; sl@0: /** Results of the last call to GetPixelFormats(). */ sl@0: RArray iLastPixelFormats; sl@0: }; sl@0: sl@0: sl@0: #include "sgdriverimpl.inl" sl@0: sl@0: sl@0: #endif // SGDRIVERIMPL_H