graphicscomposition/openwftest/inc/surfaceutility.h
changeset 121 d72fc2aace31
equal deleted inserted replaced
103:2717213c588a 121:d72fc2aace31
       
     1 // Copyright (c) 2010 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 */
       
    19 
       
    20 #ifndef __SURFACE_UTILITY__
       
    21 #define __SURFACE_UTILITY__
       
    22 
       
    23 #include <e32base.h>
       
    24 #include <graphics/surface.h>
       
    25 #include <graphics/surfacemanager.h>
       
    26 #include <graphics/surfaceupdateclient.h>
       
    27 #include <graphics/symbianstream.h>
       
    28 #include <WF/wfc.h>
       
    29 
       
    30 //#define ENABLE_TEST_LOGGING
       
    31 #if defined(ENABLE_TEST_LOGGING)
       
    32 #define LOG(X)	RDebug::Printf X
       
    33 #define LOGL(X)	RDebug::Print X
       
    34 #else
       
    35 #define LOG(X)
       
    36 #define LOGL(X)
       
    37 #endif
       
    38 
       
    39 class TRgb;
       
    40 class CFbsBitmap;
       
    41 
       
    42 class CSurfaceUtility : public CBase
       
    43 	{
       
    44 public:
       
    45     CSurfaceUtility();
       
    46 	static CSurfaceUtility* NewL();
       
    47 	virtual ~CSurfaceUtility();
       
    48 	TSize SurfaceSize(const TSurfaceId& aSurface);
       
    49 	TSurfaceId CreateSurfaceL(const TSize& aSize, TUidPixelFormat aPixelFormat, TInt aStride, TBool aContiguous, TInt aBuffers);
       
    50 	TInt BytesPerPixelL(TUidPixelFormat aPixelFormat);
       
    51 	void FillSurfaceL(TSurfaceId& aSurface, const TRgb& aColor);
       
    52 	void FillSurfaceL(TSurfaceId& aSurface, TInt aBuffer, const TRgb& aColor);
       
    53 	void DestroySurface(TSurfaceId& aSurface);
       
    54 	TBool DestroyAll();
       
    55     TBool CheckRectColor(const TSurfaceId& aSurface, TRect& aRect, TInt aNumOfBuffer, const TRgb& aExpectedColor, TInt aTolerance);
       
    56     TBool SaveResultImageTGAL(const TSurfaceId& aOnscreenSurface, TInt aBufferNumber, TDesC& aDestination);
       
    57     TInt SubmitUpdate(const TSurfaceId& aSurface, TInt aBufferNumber, const TRegion* aRegion = NULL);
       
    58     void NotifyWhenDisplayed(TRequestStatus& aStatusDisplayed, TTimeStamp& aTimeStamp);
       
    59     void NotifyWhenDisplayedXTimes(TInt aCount, TRequestStatus& aStatusDisplayedX);
       
    60     void NotifyWhenAvailable(TRequestStatus& aStatusAvailable);	
       
    61 	RSurfaceManager& Manager()	{return iManager;}
       
    62 	RSurfaceUpdateSession& Session()	{return iSurfaceUpdateSession;}
       
    63 	SymbianStreamType GetOnScreenStream(WFCDevice aDev, WFCContext aContext);
       
    64 	TBool CreateImagePath(TDesC& aDir);
       
    65 
       
    66 private:
       
    67 	void ConstructL();
       
    68     TInt GetHeader(const TSurfaceId& aSurface, RSurfaceManager::TInfoBuf& aInfo);
       
    69     TUint8* GetBufferPointerL(const TSurfaceId& aSurface, TInt aNumOfBuffer, RChunk& aChunk);
       
    70     TRgb GetPixelL(RSurfaceManager::TInfoBuf& aInfo, TAny* aPixelData, TPoint aPosition);
       
    71 
       
    72 private:
       
    73 	RSurfaceManager iManager;
       
    74 	RSurfaceUpdateSession iSurfaceUpdateSession;
       
    75 
       
    76 	//This local object wraps the array operations in a heap switch
       
    77 	//The reason for providing this wrapper is to allow threads to share the surface manager surface ID list.
       
    78 	//In particular, the next test can attempt to release the previous test's surfaces if it paniced. 
       
    79 	//Note that the presumption is that the owning thread will be paused, 
       
    80 	//so there will be no thread interlock issues with it's heap manager.
       
    81 	class RHeapSurfaceArray
       
    82 		{
       
    83 		public:
       
    84 		typedef RArray<TSurfaceId>	Array;
       
    85 		RHeapSurfaceArray(RHeapSurfaceArray* aUseExternalArray=NULL);
       
    86 
       
    87 		//Emulation of RArray entrypoints. Add more stub methods if required...
       
    88 		TSurfaceId& operator[](TUint aIndex);
       
    89 		void Close();
       
    90 		TInt Count() const;
       
    91 		inline void Reset();
       
    92 		void AppendL(const TSurfaceId &anEntry);
       
    93 		TInt Find(const TSurfaceId &anEntry) const;
       
    94 		void Remove(TInt anIndex);
       
    95 		
       
    96 		private:
       
    97 		static void PopHeap(void* mainheap);
       
    98 		
       
    99 		Array iLocalArray;
       
   100 		Array* iUseArray;
       
   101 		RHeap &iExternalHeapRef;
       
   102 		}	iSurfaces;
       
   103 	};
       
   104 
       
   105 #endif // __SURFACE_UTILITY__
       
   106