os/graphics/fbs/fontandbitmapserver/tfbs/tfbsglyphdata.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.
     1 // Copyright (c) 2009-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 #ifndef TFBSGLYPHDATA_H
    17 #define TFBSGLYPHDATA_H
    18 
    19 #include <EGL/eglext.h>
    20 #include <VG/openvg.h>
    21 #include <sgresource/sgresource.h>
    22 #include "test/TGraphicsHarness.h"
    23 class RSgImage;
    24 class CEGLHelper;
    25 
    26 //#define SAVEGLYPHSTOMBMDURINGCOMPARISON // Enable saving of glyphs in the CompareSgImages()function
    27 //#define SAVEGLYPHSTOMBMDEBUGFUNCTION //  Enable compilation of the member function SaveRSgImagesAsMbms(). Occasionally useful.
    28 
    29 typedef EGLBoolean (*TvgCreateEGLImageTargetKHRTypefPtr) (VGeglImageKHR image);
    30 
    31 /**
    32 Multi-thread test enum.
    33  */
    34 enum EGlyphDataMultithreadTest
    35 	{
    36 	EGlyphDataMultiSessionTestShareGlyphs,
    37 	EGlyphDataMultiSessionTestStressAtlas
    38 	};
    39 
    40 /**
    41 Struct passed to multi-thread test functions.
    42  */
    43 struct TGlyphDataMultithreadParams
    44 	{
    45 	TFontSpec iFontSpec;
    46 	TUint* iGlyphCodes;
    47 	TInt iGlyphCodesCount;
    48 	CEGLHelper* iEGL;
    49 	};
    50 
    51 /**
    52 Struct used to define the mutlithreaded test to run when launching a new thread.
    53  */
    54 struct TGlyphDataThreadInfo
    55 	{
    56 	EGlyphDataMultithreadTest iTest;
    57 	TGlyphDataMultithreadParams iParams;
    58 	TInt iThreadNum;
    59 	CTestStep* iStep;
    60 	};
    61 
    62 
    63 /**
    64  *
    65  * Class to provide a dummy font for test purposes
    66  * See CTFbsGlyphData::TestGlyphDataIteratorNotSupportedFontL()
    67  */
    68 class CTestFont : public CFont
    69 	{
    70 public:
    71 	TUid DoTypeUid() const {return TUid::Uid(12345);}
    72 	TInt DoHeightInPixels() const {return 12;}
    73 	TInt DoAscentInPixels() const {return 10;}
    74 	TInt DoCharWidthInPixels(TChar /*aChar*/) const  {return 0;}
    75 	TInt DoTextWidthInPixels(const TDesC& /*aText*/) const {return 0;}
    76 	TInt DoBaselineOffsetInPixels() const {return 0;}
    77 	TInt DoTextCount(const TDesC& /*aText*/,TInt /*aWidthInPixels*/) const {return 0;}
    78 	TInt DoTextCount(const TDesC& /*aText*/,TInt /*aWidthInPixels*/,TInt& /*aExcessWidthInPixels*/) const {return 0;}
    79 	TInt DoMaxCharWidthInPixels() const  {return 0;}
    80 	TInt DoMaxNormalCharWidthInPixels() const  {return 0;}
    81 	TFontSpec DoFontSpecInTwips() const  {return TFontSpec();}
    82 	};
    83 
    84 /**
    85 Created by each process/thread that needs to do RSgImage image comparison.
    86 The class can be shared in a process between threads and handles synchronisation
    87 with EGL itself.
    88  */
    89 class CEGLHelper : public CBase
    90 	{
    91 public:
    92 	~CEGLHelper();
    93 	static CEGLHelper* NewL();
    94 		
    95 	TInt GetSgImageData(const RSgImage& aSgImage, const TRect& aRect, TUint8*& aBuf);
    96 	
    97 private:
    98 	CEGLHelper();
    99 	void ConstructL();
   100 
   101 private:
   102 	RMutex iMutex;
   103 	RSgDriver iSgDriver;
   104 	EGLDisplay iDisplay;
   105 	EGLContext iContext;
   106 	EGLSurface iSurface;
   107 	// Function pointer for creation and destruction of EGLImages, and the creation
   108 	// of VGImages from EGLImages.
   109 	TvgCreateEGLImageTargetKHRTypefPtr vgCreateImageTargetKHR;
   110 	PFNEGLCREATEIMAGEKHRPROC eglCreateImageKHR;
   111 	PFNEGLDESTROYIMAGEKHRPROC eglDestroyImageKHR;
   112 	};
   113 
   114 /**
   115 Test class for the glyph data extensions RFbsGlyphDataIterator and 
   116 RFbsGlyphMetricsArray. Positive and negative tests
   117 */
   118 class CTFbsGlyphData : public CTGraphicsBase
   119 	{
   120 public:
   121 	CTFbsGlyphData(CTestStep* aStep);
   122 	~CTFbsGlyphData();
   123 protected:
   124 //from 	CTGraphicsBase
   125 	virtual void RunTestCaseL(TInt aCurTestCase);
   126 	void ConstructL();
   127 	
   128 private:
   129 	// Test Cases
   130 	void TestConsistencyWithGetCharacterData();
   131 	void TestInvalidGlyphCode();
   132 	void TestGlyphMetricsArrayParameters();
   133 	void TestGlyphMetricsArrayReuse();
   134 	void TestGlyphDataIteratorClose();
   135 	void TestGlyphDataIteratorSequence();
   136 	void TestGlyphDataIteratorMultipleUsesOnMultipleFonts();
   137 	void TestGlyphDataIteratorImageValidity();
   138 	void TestGlyphDataIteratorOpenInvalidCode();
   139 	void TestGlyphDataIteratorOpenTwice();
   140 	void TestGlyphDataIteratorOpenTwiceWithDifferentFonts();
   141 	void TestGlyphDataIteratorOpenTooBigFont();
   142 	void TestGlyphDataIteratorOpenWithWrongArgument();
   143 	void TestGlyphDataIteratorImageMemoryLeak();
   144 	void TestGlyphDataIteratorLargeFontStress();
   145 	void TestGlyphDataIteratorManyFontsStressL();
   146 	void TestGlyphDataIteratorNoGraphicsMemory();
   147 	void TestGlyphDataIteratorNextIsAtomic();
   148 	void TestGlyphDataIteratorManyArraySizes();
   149 	void TestBitmapFontSupport();
   150 	// White-Box Test Cases
   151 	void TestGlyphDataIteratorSameGlyphCodes();
   152 	void TestMultithreadShareSingleFont();
   153 	void TestMultithreadStressAtlas();
   154 	// Out-of-system-memory tests
   155 	void TestGlyphMetricsArrayHeapOOML();
   156 	void TestGlyphDataIteratorHeapOOML();
   157 	// Multithread funtions
   158 	static void ThreadShareGlyphsL(TInt aThreadNum, TGlyphDataMultithreadParams& aParam, CTestStep* aStep);
   159 	static void ThreadStressAtlasL(TInt aThreadNum, TGlyphDataMultithreadParams& aParam, CTestStep* aStep);	
   160 
   161 	// Utility functions for the test cases.
   162 	static TInt ThreadFunction(TAny* aParam); 
   163 	TInt GetImageDataFromSgImage(const RSgImage& aSgImage, const TRect& aRect, TUint8*& aBuf);
   164 	TUint32 CompareMetrics(const TOpenFontCharMetrics& aMetrics1, const TOpenFontCharMetrics& aMetrics2);
   165 	static TInt CompareSgImages(CEGLHelper* aEGL, const RSgImage& aImageA, const TRect& aRectA, const RSgImage& aImageB, const TRect& aRectB, TBool& aMatch);
   166 	static TInt CompareSgImages(CEGLHelper* aEGL, const RSgImage& aImageA, const TRect& aRectA, TUint8* aBufferA, const RSgImage& aImageB, const TRect& aRectB, TUint8* aBufferB, TBool& aMatch);
   167 #ifdef SAVEGLYPHSTOMBMDEBUGFUNCTION
   168 	void SaveRSgImagesAsMbms( CEGLHelper* aEGL, const RSgImage& aImageA, const TRect& aRectA, const RSgImage& aImageB, const TRect& aRectB );
   169 #endif // SAVEGLYPHSTOMBMDEBUGFUNCTION
   170 	void InfoPrintFontSpec(const CFont& aFont);
   171 	void SetupEglL();
   172 	
   173 private:
   174 	RFbsSession* iFbs;
   175 	CFbsTypefaceStore* iTs;
   176 	TUint* iGlyphCodesLatin;
   177 	
   178 	CFbsFont* iFont;
   179 	CFbsFont* iFont2;
   180 
   181 	TUint8* iTempBuf1;
   182 	TUint8* iTempBuf2;
   183 	RSgDriver iSgDriver;
   184 	CEGLHelper* iEGL;
   185 	};
   186 
   187 
   188 class CTFbsGlyphDataStep : public CTGraphicsStep
   189 	{
   190 public:
   191 	CTFbsGlyphDataStep();
   192 protected:	
   193 	//from CTGraphicsStep
   194 	virtual CTGraphicsBase* CreateTestL();
   195 	};
   196 
   197 _LIT(KTFbsGlyphDataStep,"TFbsGlyphData");
   198 
   199 #endif /* TFBSGLYPHDATA_H */