|
1 // Copyright (c) 2008-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 NVGRENDERSTAGE_H |
|
17 #define NVGRENDERSTAGE_H |
|
18 |
|
19 /** |
|
20 @file |
|
21 @test |
|
22 @internalComponent - Internal Symbian test code |
|
23 */ |
|
24 |
|
25 #include <graphics/wsrenderstage.h> |
|
26 #include <graphics/wsgraphicdrawer.h> |
|
27 #include <graphics/wsgraphicscontext.h> |
|
28 #include <nvg.h> |
|
29 #include "vgigraphicsinterface.h" |
|
30 |
|
31 /** Struct to form a simple LRU cache of conversion results |
|
32 */ |
|
33 class TCachedConversion |
|
34 { |
|
35 public: |
|
36 TCachedConversion(); |
|
37 ~TCachedConversion(); |
|
38 inline void Deque(); |
|
39 |
|
40 public: |
|
41 TDblQueLink iLink; |
|
42 TUint32 iBitmapID; |
|
43 TUint32 iDiscriminator; |
|
44 CFbsBitmap* iCachedResult; |
|
45 }; |
|
46 |
|
47 void TCachedConversion::Deque() {iLink.Deque();} |
|
48 |
|
49 /** This is a render stage used for processing NVG Icon bitmaps in the absence of |
|
50 graphics acceleration hardware. The software implementation of OpenVG is used to |
|
51 render the NVG drawing commands onto a normal CFbsBitmap, and a simple LRU cache |
|
52 is used to keep the results for faster redrawing. |
|
53 |
|
54 This render stage implements the MWsGraphicsContext interface so that it can intercept |
|
55 any drawing commands that draw an extended bitmap, any commands that draw a normal |
|
56 bitmap are just passed through to the next renderstage (along with any commands that |
|
57 do not involve bitmaps at all). |
|
58 |
|
59 A CNvgRenderStage object is created by a CNvgRenderStageFactory. |
|
60 */ |
|
61 class CNvgRenderStage : public CWsRenderStage, public MWsGraphicsContext |
|
62 { |
|
63 public: |
|
64 static CNvgRenderStage* NewL(MWsGraphicDrawerEnvironment* aEnv, MWsScreen* aScreen, MWsScreenRedraw* aScreenRedraw, CWsRenderStage* aNextStage); |
|
65 virtual ~CNvgRenderStage(); |
|
66 |
|
67 public: |
|
68 // Implementation of CWsRenderStage |
|
69 TAny* ResolveObjectInterface(TUint aTypeId); |
|
70 virtual void Begin(const TRegion* aRegion); |
|
71 virtual void End(TRequestStatus* aCompositorReady); |
|
72 |
|
73 public: |
|
74 // Implementation of MWsGraphicsContext |
|
75 void BitBlt(const TPoint& aDestPos, const CFbsBitmap& aSourceBitmap); |
|
76 void BitBlt(const TPoint& aDestPos, const CFbsBitmap& aSourceBitmap, const TRect& aSourceRect); |
|
77 void BitBltMasked(const TPoint& aDestPos, const CFbsBitmap& aSourceBitmap, const TRect& aSourceRect, const CFbsBitmap& aMaskBitmap, TBool aInvertMask); |
|
78 void BitBltMasked(const TPoint& aDestPos, const CFbsBitmap& aSourceBitmap, const TRect& aSourceRect, const CFbsBitmap& aMaskBitmap, const TPoint& aMaskPos); |
|
79 void ResetClippingRegion(); |
|
80 void Clear(); |
|
81 void Clear(const TRect& aRect); |
|
82 void ResetBrushPattern(); |
|
83 void ResetFont(); |
|
84 void DrawArc(const TRect& aRect, const TPoint& aStart, const TPoint& aEnd); |
|
85 void DrawPie(const TRect& aRect, const TPoint& aStart, const TPoint& aEnd); |
|
86 void DrawBitmap(const TRect& aDestRect, const CFbsBitmap& aSourceBitmap); |
|
87 void DrawBitmap(const TRect& aDestRect, const CFbsBitmap& aSourceBitmap, const TRect& aSourceRect); |
|
88 void DrawBitmapMasked(const TRect& aDestRect, const CFbsBitmap& aSourceBitmap,const TRect& aSourceRect, const CFbsBitmap& aMaskBitmap, TBool aInvertMask); |
|
89 void DrawRoundRect(const TRect& aRect, const TSize& aEllipse); |
|
90 void DrawPolyLine(const TArray<TPoint>& aPointList); |
|
91 void DrawPolyLineNoEndPoint(const TArray<TPoint>& aPointList); |
|
92 void DrawPolygon(const TArray<TPoint>& aPointList, TFillRule aFillRule=EAlternate); |
|
93 void DrawEllipse(const TRect& aRect); |
|
94 void DrawLine(const TPoint& aStart, const TPoint& aEnd); |
|
95 void DrawLineTo(const TPoint& aPoint); |
|
96 void DrawLineBy(const TPoint& aVector); |
|
97 void DrawRect(const TRect& aRect); |
|
98 void DrawText(const TDesC& aText,const TTextParameters* aParam); |
|
99 void DrawText(const TDesC& aText,const TTextParameters* aParam,const TPoint& aPosition); |
|
100 void DrawText(const TDesC& aText,const TTextParameters* aParam,const TRect& aClipRect); |
|
101 void DrawText(const TDesC& aText,const TTextParameters* aParam,const TRect& aClipFillRect,TInt aBaselineOffset,TTextAlign aHrz=ELeft,TInt aMargin=0); |
|
102 void DrawTextVertical(const TDesC& aText,const TTextParameters* aParam,TBool aUp); |
|
103 void DrawTextVertical(const TDesC& aText,const TTextParameters* aParam,const TPoint& aPosition,TBool aUp); |
|
104 void DrawTextVertical(const TDesC& aText,const TTextParameters* aParam,const TRect& aClipRect,TBool aUp); |
|
105 void DrawTextVertical(const TDesC& aText,const TTextParameters* aParam,const TRect& aClipRect,TInt aBaselineOffset,TBool aUp,TTextAlign aVert=ELeft,TInt aMargin=0); |
|
106 void DrawTextVertical(const TDesC& aText,const TTextParameters* aParam,const TRect& aClipRect,TInt aBaselineOffset,TInt aTextWidth,TBool aUp,TTextAlign aVert=ELeft,TInt aMargin=0); |
|
107 void MoveTo(const TPoint& aPoint); |
|
108 void MoveBy(const TPoint& aVector); |
|
109 void Plot(const TPoint& aPoint); |
|
110 void Reset(); |
|
111 void SetBrushColor(const TRgb& aColor); |
|
112 void SetBrushOrigin(const TPoint& aOrigin); |
|
113 void SetBrushStyle(TBrushStyle aBrushStyle); |
|
114 void SetClippingRegion(const TRegion& aRegion); |
|
115 void SetDrawMode(TDrawMode aDrawMode); |
|
116 void SetOrigin(const TPoint& aPoint = TPoint(0, 0)); |
|
117 void SetPenColor(const TRgb& aColor); |
|
118 void SetPenStyle(TPenStyle aPenStyle); |
|
119 void SetPenSize(const TSize& aSize); |
|
120 void SetTextShadowColor(const TRgb& aColor); |
|
121 void SetCharJustification(TInt aExcessWidth, TInt aNumChars); |
|
122 void SetWordJustification(TInt aExcessWidth, TInt aNumGaps); |
|
123 void SetUnderlineStyle(TFontUnderline aUnderlineStyle); |
|
124 void SetStrikethroughStyle(TFontStrikethrough aStrikethroughStyle); |
|
125 void SetBrushPattern(const CFbsBitmap& aBitmap); |
|
126 void SetBrushPattern(TInt aFbsBitmapHandle); |
|
127 void SetFont(const CFont* aFont); |
|
128 void CopyRect(const TPoint& aOffset, const TRect& aRect); |
|
129 void UpdateJustification(const TDesC& aText,const TTextParameters* aParam); |
|
130 void UpdateJustificationVertical(const TDesC& aText,const TTextParameters* aParam,TBool aUp); |
|
131 void SetFontNoDuplicate(const CFont* aFont); |
|
132 TBool HasBrushPattern() const; |
|
133 TBool HasFont() const; |
|
134 TRgb BrushColor() const; |
|
135 TRgb PenColor() const; |
|
136 TRgb TextShadowColor() const; |
|
137 TInt GetError(); |
|
138 TPoint Origin() const; |
|
139 const TRegion& ClippingRegion(); |
|
140 TInt Push(); |
|
141 void Pop(); |
|
142 |
|
143 private: |
|
144 CNvgRenderStage(); |
|
145 void ConstructL(CWsRenderStage* aNextStage); |
|
146 |
|
147 private: |
|
148 // Helper methods that support the implementation of MWsGraphicsContext |
|
149 CFbsBitmap* GetConvertedBitmap(const CFbsBitmap& aSourceBitmap); |
|
150 void CopyExtendedBitmapToNormalBitmap(const CFbsBitmap& aExtendedBitmapSrc, CFbsBitmap& aBitmapDst); |
|
151 |
|
152 private: |
|
153 MWsGraphicsContext* iGc; |
|
154 TInt iExtendedBitmapError; |
|
155 TPoint iOrigin; |
|
156 RRegion iEmptyRegion; |
|
157 CFbsBitmap* iBrushPattern; |
|
158 CFbsBitmap* iInternalBrushPattern; |
|
159 MWsGraphicsContext::TBrushStyle iBrushStyle; |
|
160 CVGIGraphicsInterface* iGraphicsInterface; |
|
161 CNvgEngine* iNvgEngine; |
|
162 |
|
163 // LRU Cache of rendered bitmaps |
|
164 #define MAX_NVG_CACHE_SIZE 128 |
|
165 |
|
166 TDblQue<TCachedConversion> iCache; |
|
167 TDblQueIter<TCachedConversion> iCacheIterator; |
|
168 TUint iCacheFree; |
|
169 }; |
|
170 |
|
171 // #define DEBUG_NVG_RENDERSTAGE |
|
172 |
|
173 #endif // NVGRENDERSTAGE_H |