graphicsdeviceinterface/directgdiadaptation/hwsrc/glyphimagecache.h
changeset 0 5d03bc08d59c
equal deleted inserted replaced
-1:000000000000 0:5d03bc08d59c
       
     1 // Copyright (c) 2007-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 //
       
    15 
       
    16 #ifndef GLYPHIMAGECACHE_H_
       
    17 #define GLYPHIMAGECACHE_H_
       
    18 
       
    19 /**
       
    20 @file
       
    21 @internalComponent
       
    22 */
       
    23 
       
    24 #include <e32base.h>
       
    25 #include <gdi.h>
       
    26 #include <s32btree.h>
       
    27 #include <VG/openvg.h>
       
    28 #include <graphics/directgdiextensioninterfaces.h>
       
    29 
       
    30 
       
    31 /**
       
    32 Data structure which holds OpenVG images for monochrome and anti-aliased fonts
       
    33 */
       
    34 class TGlyphEntry
       
    35 	{
       
    36 public:
       
    37 	TChar iGlyphCode; 		//unique code, used as an index in a tree
       
    38 	VGImage	iForeground; 	//blend using a brush colour
       
    39 	};
       
    40 
       
    41 /**
       
    42 Data structure which holds OpenVG images for compound fonts.
       
    43 These fonts are specified by four components:
       
    44 	-foreground
       
    45 	-background  
       
    46 	-shadow
       
    47 	-outline
       
    48 */
       
    49 class TGlyphEntryCompound : public TGlyphEntry
       
    50 	{
       
    51 public:
       
    52 	VGImage iOutline; //blend using a pen colour
       
    53 	VGImage iShadow; //blend using a shadow colour
       
    54 	};
       
    55 
       
    56 /**
       
    57 This class represents the concrete implementation of the CFontGlyphImageStorage.
       
    58 It holds all entries in the form of a binary tree and provides functionality for image creation and searching.
       
    59 */
       
    60 NONSHARABLE_CLASS(CFontGlyphTree) : public CBase
       
    61 	{
       
    62 public:
       
    63 	static CFontGlyphTree* NewL(TUint32 aFontId, TGlyphBitmapType aGlyphType);
       
    64 	~CFontGlyphTree();
       
    65 template <class K>
       
    66 	void GlyphImageEntryL(TChar aGlyphCode, const TUint8* aGlyphImage, const TSize& aGlyphImageSize, K& aEntry, TUint8* aDataForeground);
       
    67 	inline TUint32 FontId() const;
       
    68 	inline TUint CacheSize() const;
       
    69 	void DestroyAllVGImagesL();
       
    70 	//do not add to the tree. For OOM conditions
       
    71 template <class K>
       
    72 	static void GlyphImageEntryOOML(TGlyphBitmapType aGlyphType, const TUint8* aGlyphImage, const TSize& aGlyphImageSize, K& aEntry, TUint8* aData, TUint8* aDataOutline, TUint8* aDataShadow);
       
    73 private:
       
    74 	CFontGlyphTree(TUint32 aFontId, TGlyphBitmapType aGlyphType);
       
    75 	void ConstructL();
       
    76 	static void DestroyVGImage(VGImage* aForeground, VGImage* aOutline = NULL, VGImage* aShadow = NULL);
       
    77 	//for monochrome and antialiased fonts
       
    78 	static void CreateVGImageL(const TUint8* aGlyphImage, const TSize& aGlyphImageSize, TDisplayMode aDisplayMode, VGImage& aForeground, TUint8* aPreAllocForeground);
       
    79 	//for four colours fonts
       
    80 	static void CreateVGImageL(const TUint8* aGlyphImage, const TSize& aGlyphImageSize, VGImage& aForeground, VGImage& aOutline, VGImage& aShadow, TUint8* aPreAllocForeground, TUint8* aPreAllocOutline, TUint8* aPreAllocShadow);
       
    81 	static void DecodeBinaryData(const TSize& aDataSize, const TUint8* aData, TUint32* aBinaryData);
       
    82 	static void DecodeBinaryDataExLarge(const TSize& aDataSize, const TUint8* aData, TInt aStride, TUint32* aBinaryData);
       
    83 
       
    84 	inline static TInt16 Load16(const TUint8* aPtr);
       
    85 	static void CopyCharLine(TUint32*& aBinaryDataPtr,TInt aBufferWords,const TUint8* aData,TInt aBitShift,TInt aCharWidth, TInt16 aRepeatCount);
       
    86 private:
       
    87 	/**
       
    88 	Binary tree with fixed size. One of following will be used:
       
    89 	TBtreeFix<TGlyphEntry, TChar> or TBtreeFix<TGlyphEntryCompound, TChar>
       
    90 	*/
       
    91 	TBtree* iGlyphTree;
       
    92 
       
    93 	CMemPagePool* iPagePool; /**< Non persistent pool for pages.*/
       
    94 	TBtreeKey iKey; /**< Tree key.*/
       
    95 	TUint32 iFontId; /**< Unique font id.*/
       
    96 	TGlyphBitmapType iGlyphType; /**< Glyph bitmap type.*/
       
    97 	TUint iCacheSize; /**< Number of bytes allocated by all elements in the tree.*/
       
    98 	};
       
    99 
       
   100 /**
       
   101 @return The unique id of the font
       
   102 */
       
   103 inline TUint32 CFontGlyphTree::FontId() const
       
   104 	{
       
   105 	return iFontId;
       
   106 	}
       
   107 
       
   108 /**
       
   109 @return The total size of the cache
       
   110 */
       
   111 inline TUint CFontGlyphTree::CacheSize() const
       
   112 	{
       
   113 	return iCacheSize;
       
   114 	}
       
   115 
       
   116 /**
       
   117 @param aPtr A pointer to a source buffer of 2 8-bit unsigned integers.
       
   118 @return The two 8-bit integers combined into a 16-bit integer.
       
   119 */
       
   120 inline TInt16 CFontGlyphTree::Load16(const TUint8* aPtr) 
       
   121 	{
       
   122 	return TInt16(aPtr[0]+(aPtr[1]<<8)); 
       
   123 	}
       
   124 
       
   125 /**
       
   126 The class provides an interface for handling image caching and will be maintained by the DirectGDI driver at adaptation level.
       
   127 Any instance of this class cannot be shared between threads.
       
   128 */
       
   129 NONSHARABLE_CLASS(CFontGlyphImageStorage) : public CBase, 
       
   130 								public MFontGlyphImageStorage
       
   131 {
       
   132 public:
       
   133 	CFontGlyphImageStorage(TInt aMaxCacheSize);
       
   134 	TInt PreAllocateImages();
       
   135 	~CFontGlyphImageStorage();
       
   136 
       
   137 	// from MFontGlyphImageStorage
       
   138 	TInt GlyphImage(TUint32 aFontId, TChar aGlyphCode, TGlyphBitmapType aGlyphBitmapType, 
       
   139 						const TUint8* aGlyphImage, const TSize& aGlyphImageSize, 
       
   140 						TAny* aImageForeground, TAny* aImageShadow, TAny* aImageOutline);	/**< @internalTechnology*/
       
   141 	void CleanGlyphImageCache();	/**< @internalTechnology*/
       
   142 	TInt GlyphCacheSize() const;	/**< @internalTechnology*/
       
   143 	TInt MaxGlyphCacheSize() const;	/**< @internalTechnology*/
       
   144 	TInt FontIdInOrder(RArray<TUint32> & aFontListId) const;	/**< @internalTechnology*/
       
   145 	void EnforceOOMFailure(TBool aEnforce);	/**< @internalTechnology*/
       
   146 	TInt SetMaxGlyphCacheSize(TInt aMaxCacheSize);	/**< @internalTechnology*/
       
   147 private:
       
   148 	void DeletePreAllocatedImages();
       
   149 	void CleanCacheIfRequired();
       
   150 private:
       
   151 	RPointerArray<CFontGlyphTree> iFontTreeList;	/**< Array of all image trees in the cache.*/
       
   152 	TInt iMaxCacheSize;	/**< Maximum cache size the class can hold.*/
       
   153 	TInt iCacheSize;	/**< Current total cache size which amounts to cache sizes of all trees in the list .*/
       
   154 	TGlyphEntry iEntry;	/**< Work member, which will be filled when user requests glyph image.*/
       
   155 	TGlyphEntryCompound iEntryCompound;	/**< Work member, which will be filled when user requests glyph image.*/
       
   156 	//for OOM conditions
       
   157 	TUint8* iForegroundData;
       
   158 	TUint8* iShadowData;
       
   159 	TUint8* iOutlineData;
       
   160 	VGImage iImageForeground;	/**< Pre-allocated image for OOM conditions.*/
       
   161 	VGImage iImageShadow;	/**< Pre-allocated image for OOM conditions.*/
       
   162 	VGImage iImageOutline;	/**< Pre-allocated image for OOM conditions.*/
       
   163 	TSize iImageSize;	/**< Pre-defined image size.*/
       
   164 	TBool iImagesPreAllocated;	/**< True if all OOM variables were created successfully.*/
       
   165 #ifdef _DEBUG
       
   166 	TBool iEnforceOOM;	/**< If true will always try to use pre-allocated images.*/
       
   167 #endif
       
   168 };
       
   169 
       
   170 
       
   171 #endif