graphicsresourceservices/graphicsresourceimplementation/inc/sgdriver.h
changeset 36 01a6848ebfd7
equal deleted inserted replaced
0:5d03bc08d59c 36:01a6848ebfd7
       
     1 // Copyright (c) 2008-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 // Graphics Resource - internal functionality
       
    15 //
       
    16 
       
    17 #ifndef SGDRIVER_H
       
    18 #define SGDRIVER_H
       
    19 
       
    20 #include <sgresource/sgimage.h>
       
    21 #include <sgresource/sgimage_sw.h>
       
    22 #include <sgresource/sgdriver_test.h>
       
    23 #include <sgresource/sgdriver_profiling.h>
       
    24 #include <pls.h>
       
    25 #include "sgdevice.h"
       
    26 
       
    27 const TUid KSgResourceLibraryUid = {0x102872C5};
       
    28 
       
    29 const TInt KSgUsageAll = ESgUsageBitOpenVgImage | ESgUsageBitOpenGlesTexture2D | ESgUsageBitOpenGles2Texture2D
       
    30                        | ESgUsageBitOpenVgSurface | ESgUsageBitOpenGlesSurface | ESgUsageBitOpenGles2Surface;
       
    31 const TInt KSgUsageAllSurfaceTypes = ESgUsageBitOpenVgSurface | ESgUsageBitOpenGlesSurface | ESgUsageBitOpenGles2Surface;
       
    32 
       
    33 enum TSgResourceImplPanicReason
       
    34 	{
       
    35 	ESgPanicResourceImplGeneral = 1,
       
    36 	ESgPanicBadRefCount = 2,
       
    37 	ESgPanicBadImagePointer = 3
       
    38 	};
       
    39 
       
    40 void Panic(TSgResourceImplPanicReason aReason);
       
    41 
       
    42 NONSHARABLE_CLASS(XSgImage)
       
    43 	: public MSgImage_Sw
       
    44 	{
       
    45 public:
       
    46 	XSgImage(TSgDrawableId aId, TUint32 aAttribs, const TSgImageMetaData& aMetaData, TAny* aDataAddress, TInt aDataStride);
       
    47 	~XSgImage();
       
    48 	TInt Open();
       
    49 	void Close();
       
    50 	TInt RefCount() const;
       
    51 	TSgDrawableId Id() const;
       
    52 	TUid DrawableType() const;
       
    53 	TInt GetInterface(TUid aInterfaceUid, TAny*& aInterfacePtr);
       
    54 	void GetInfo(TSgImageInfo& aInfo) const;
       
    55 	TInt GetAttribute(TUid aUid, TInt& aValue) const;
       
    56 	static TInt Compare(const XSgImage& aImage1, const XSgImage& aImage2);
       
    57 	static TInt Compare(const TSgDrawableId* aId, const XSgImage& aImage);
       
    58 	// From MSgImage_Sw
       
    59 	TAny* DataAddress() const;
       
    60 	TInt DataStride() const;
       
    61 private:
       
    62 	TInt iRefCount;
       
    63 	TSgDrawableId iId;
       
    64 	TSgImageInfo iInfo;
       
    65 	TAny* iDataAddress;
       
    66 	TInt iDataStride;
       
    67 	};
       
    68 
       
    69 NONSHARABLE_CLASS(XSgDriver)
       
    70 	: public MSgDriver_Profiling
       
    71 #ifdef _DEBUG
       
    72 	, public MSgDriver_Test
       
    73 #endif
       
    74 	{
       
    75 public:
       
    76 	XSgDriver(RHeap* aHeap);
       
    77 	~XSgDriver();
       
    78 	TInt Construct();
       
    79 	void Delete();
       
    80 	TInt CreateImage(const TSgImageInfo& aInfo, const TAny* aDataAddress, TInt aDataStride, const TSgAttributeArrayBase* aAttributes, TAny*& aResult);
       
    81 	TInt CreateImage(const TSgImageInfo& aInfo, const XSgImage* aImageImpl, const TSgAttributeArrayBase* aAttributes, TAny*& aResult);
       
    82 	TInt FindAndOpenImage(TSgDrawableId aId, const TSgAttributeArrayBase* aAttributes, TAny*& aResult);
       
    83 	void DeleteImage(XSgImage* aImageImpl);
       
    84 	TUint32 MatchingEglConfigUsage(TUint32 aUsage) const;
       
    85 	TInt CheckImageInfo(const TSgImageInfo& aInfo) const;
       
    86 	TBool CheckImage(const TAny* aImageImpl) const;
       
    87 	TInt GetInterface(TUid aInterfaceUid, TAny*& aInterfacePtr);
       
    88 	// From MSgDriver_Profiling
       
    89 	TInt LocalResourceCount() const;
       
    90 	TInt GlobalResourceCount() const;
       
    91 	TInt LocalGraphicsMemoryUsed() const;
       
    92 	TInt GlobalGraphicsMemoryUsed() const;
       
    93 #ifdef _DEBUG
       
    94 	// From MSgDriver_Test
       
    95 	void AllocMarkStart();
       
    96 	void AllocMarkEnd(TInt aCount);
       
    97 	void SetAllocFail(RAllocator::TAllocFail aType, TInt aRate);
       
    98 #endif
       
    99 private:
       
   100 	RHeap* iHeap;
       
   101 	mutable RMutex iMutex;
       
   102 	mutable RSgDevice iDevice;
       
   103 	RPointerArray<XSgImage> iImagesByAddress;
       
   104 	RPointerArray<XSgImage> iImagesById;
       
   105 	TBool iHasOpenVg;
       
   106 	TBool iHasOpenGles;
       
   107 	TBool iHasOpenGles2;
       
   108 	};
       
   109 
       
   110 NONSHARABLE_CLASS(XSgDriverPls)
       
   111 	{
       
   112 public:
       
   113 	XSgDriverPls();
       
   114 public:
       
   115 	TInt iError;
       
   116 	RMutex iMutex;
       
   117 	TInt iOpenCount;
       
   118 	XSgDriver* iDriver;
       
   119 	};
       
   120 
       
   121 #ifdef __WINS__
       
   122 #define gPls (*Pls<XSgDriverPls>(KSgResourceLibraryUid))
       
   123 #else
       
   124 extern XSgDriverPls gPls;
       
   125 #endif
       
   126 
       
   127 #endif // SGDRIVER_H