|
1 /* |
|
2 * Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: AlfRenderStage provides a method for redirect avkon drawing to a graphics accelerator |
|
15 * |
|
16 */ |
|
17 |
|
18 #ifndef CALFRSGC_H_ |
|
19 #define CALFRSGC_H_ |
|
20 |
|
21 #include <graphics/wsgraphicscontext.h> |
|
22 #include <s32mem.h> |
|
23 #include <e32std.h> |
|
24 #include <gdi.h> |
|
25 |
|
26 class CAlfRsSendBuffer; |
|
27 class CFbsBitGc; |
|
28 class CFbsScreenDevice; |
|
29 |
|
30 const TInt KAlfRsGcMaxClippingRects = 20; |
|
31 |
|
32 /** |
|
33 * This class serializes commands sent to graphics context by using CAlfRsSendBuffer . |
|
34 * |
|
35 * @lib alfrenderstage.lib |
|
36 * @since S60 v5.2 |
|
37 */ |
|
38 |
|
39 NONSHARABLE_CLASS(CAlfGraphicsContext) : public CBase, public MWsGraphicsContext |
|
40 { |
|
41 public: // New methods |
|
42 |
|
43 /** |
|
44 * NewL |
|
45 * |
|
46 * Constructor |
|
47 * |
|
48 * @param aAlfSendBuffer Send buffer |
|
49 * @return New instance of the class |
|
50 */ |
|
51 static CAlfGraphicsContext* NewL( CAlfRsSendBuffer& aAlfSendBuffer ); |
|
52 |
|
53 /** |
|
54 * C++ destructor |
|
55 */ |
|
56 ~CAlfGraphicsContext(); |
|
57 |
|
58 /** |
|
59 * ResetDrawCommandCount |
|
60 * |
|
61 * Each call of command which requires drawing increases iDrawCommandCount. This is used for |
|
62 * skipping serialization of draw commands that have no effect on screen. @See DrawCommandCount. |
|
63 */ |
|
64 void ResetDrawCommandCount() |
|
65 { |
|
66 iDrawCommandCount = 0; |
|
67 }; |
|
68 |
|
69 /** |
|
70 * DrawCommandCount |
|
71 * |
|
72 * @return Amount of effective draw commands since last call of ResetDrawCommand. |
|
73 */ |
|
74 TInt DrawCommandCount() |
|
75 { |
|
76 return iDrawCommandCount; |
|
77 }; |
|
78 |
|
79 #ifdef _OPTIMIZE_WS_COMMANDS_ADVANCED_ |
|
80 /** |
|
81 * CheckDelayedClipping |
|
82 * |
|
83 * Assertains if the previous clipping (EAlfSetClipRegion) command can be delayed or skipped. |
|
84 * |
|
85 * @param aClippingRect |
|
86 * @return previous clipping command status |
|
87 */ |
|
88 TBool CheckDelayedClipping( TRect aClippingRect ); |
|
89 #endif |
|
90 #ifdef _OPTIMIZE_WS_COMMANDS_BASIC_ |
|
91 /** |
|
92 * FlushStateL |
|
93 * |
|
94 * Flushes all the modified Gc states. |
|
95 * |
|
96 * @param aRollbackClippingState contains states that should be rollbacked after flush. |
|
97 * Currently this is relevant only for clipping. |
|
98 * |
|
99 */ |
|
100 void FlushStateL( TInt& aRollbackClippingState ); |
|
101 #endif |
|
102 |
|
103 public: // From MWsGraphicsContext |
|
104 |
|
105 /** |
|
106 * Following commands are serialized |
|
107 */ |
|
108 |
|
109 void BitBlt(const TPoint& aDestPos, const CFbsBitmap& aSourceBitmap); |
|
110 void BitBlt(const TPoint& aDestPos, const CFbsBitmap& aSourceBitmap, const TRect& aSourceRect); |
|
111 void BitBltMasked(const TPoint& aDestPos, const CFbsBitmap& aSourceBitmap, const TRect& aSourceRect, const CFbsBitmap& aMaskBitmap, TBool aInvertMask); |
|
112 void BitBltMasked(const TPoint& aDestPos, const CFbsBitmap& aSourceBitmap, const TRect& aSourceRect, const CFbsBitmap& aMaskBitmap, const TPoint& aMaskPos); |
|
113 void ResetClippingRegion(); |
|
114 void Clear(); |
|
115 void Clear(const TRect& aRect); |
|
116 void ResetBrushPattern(); |
|
117 void ResetFont(); |
|
118 void DrawArc(const TRect& aRect, const TPoint& aStart, const TPoint& aEnd); |
|
119 void DrawPie(const TRect& aRect, const TPoint& aStart, const TPoint& aEnd); |
|
120 void DrawBitmap(const TRect& aDestRect, const CFbsBitmap& aSourceBitmap); |
|
121 void DrawBitmap(const TRect& aDestRect, const CFbsBitmap& aSourceBitmap, const TRect& aSourceRect); |
|
122 void DrawBitmap(const TPoint &aTopLeft, const CFbsBitmap &aSource); |
|
123 void DrawBitmapMasked(const TRect& aDestRect, const CFbsBitmap& aSourceBitmap, const TRect& aSourceRect, const CFbsBitmap& aMaskBitmap, TBool aInvertMask); |
|
124 void DrawRoundRect(const TRect& aRect, const TSize& aEllipse); |
|
125 void DrawPolyLine(const TArray<TPoint>& aPointList); |
|
126 void DrawPolyLine(const CArrayFix<TPoint>* aPointList); |
|
127 void DrawPolyLine(const TPoint *aPointList, TInt aNumPoints); |
|
128 void DrawPolyLineNoEndPoint(const TArray<TPoint>& aPointList); |
|
129 void DrawPolyLineNoEndPoint(const CArrayFix<TPoint>* aPointList); |
|
130 void DrawPolyLineNoEndPoint(const TPoint *aPointList, TInt aNumPoints); |
|
131 void DrawPolygon(const CArrayFix<TPoint>* aPointList, TFillRule aFillRule=EAlternate); |
|
132 void DrawPolygon(const TArray<TPoint>& aPointList, TFillRule aFillRule=EAlternate); |
|
133 void DrawPolygon(const TPoint *aPointList, TInt aNumPoints, TFillRule aFillRule=EAlternate); |
|
134 void DrawEllipse(const TRect& aRect); |
|
135 void DrawLine(const TPoint& aStart, const TPoint& aEnd); |
|
136 void DrawLineTo(const TPoint& aPoint); |
|
137 void DrawLineBy(const TPoint& aVector); |
|
138 void DrawRect(const TRect& aRect); |
|
139 |
|
140 void DrawText(const TDesC& aText,const TTextParameters* aParam); |
|
141 void DrawText(const TDesC& aText,const TTextParameters* aParam,const TPoint& aPosition); |
|
142 void DrawText(const TDesC& aText,const TTextParameters* aParam,const TRect& aClipRect); |
|
143 void DrawText(const TDesC& aText,const TTextParameters* aParam,const TRect& aClipFillRect,TInt aBaselineOffset,TTextAlign aHrz=ELeft,TInt aMargin=0); |
|
144 void DrawTextVertical(const TDesC& aText,const TTextParameters* aParam,TBool aUp); |
|
145 void DrawTextVertical(const TDesC& aText,const TTextParameters* aParam,const TPoint& aPosition,TBool aUp); |
|
146 void DrawTextVertical(const TDesC& aText,const TTextParameters* aParam,const TRect& aClipRect,TBool aUp); |
|
147 void DrawTextVertical(const TDesC& aText,const TTextParameters* aParam,const TRect& aClipRect,TInt aBaselineOffset,TBool aUp,TTextAlign aVert=ELeft,TInt aMargin=0); |
|
148 void DrawTextVertical(const TDesC& aText,const TTextParameters* aParam,const TRect& aClipRect,TInt aBaselineOffset,TInt aTextWidth,TBool aUp,TTextAlign aVert=ELeft,TInt aMargin=0); |
|
149 |
|
150 |
|
151 void MoveTo(const TPoint& aPoint); |
|
152 void MoveBy(const TPoint& aVector); |
|
153 void Plot(const TPoint& aPoint); |
|
154 void Reset(); |
|
155 void SetBrushColor(const TRgb& aColor); |
|
156 void SetBrushOrigin(const TPoint& aOrigin); |
|
157 void SetBrushStyle(TBrushStyle aBrushStyle); |
|
158 void SetClippingRegion(const TRegion& aRegion); |
|
159 void SetDrawMode(TDrawMode aDrawMode); |
|
160 void SetOrigin(const TPoint& aPoint = TPoint(0, 0)); |
|
161 void SetPenColor(const TRgb& aColor); |
|
162 void SetPenStyle(TPenStyle aPenStyle); |
|
163 void SetPenSize(const TSize& aSize); |
|
164 void SetTextShadowColor(const TRgb& aColor); |
|
165 void SetCharJustification(TInt aExcessWidth, TInt aNumChars); |
|
166 void SetWordJustification(TInt aExcessWidth, TInt aNumGaps); |
|
167 void SetUnderlineStyle(TFontUnderline aUnderlineStyle); |
|
168 void SetStrikethroughStyle(TFontStrikethrough aStrikethroughStyle); |
|
169 void SetBrushPattern(const CFbsBitmap& aBitmap); |
|
170 void SetBrushPattern(TInt aFbsBitmapHandle); |
|
171 void SetFont(const CFont* aFont); |
|
172 void CopyRect(const TPoint& aOffset, const TRect& aRect); |
|
173 |
|
174 void UpdateJustification(const TDesC& aText,const TTextParameters* aParam); |
|
175 void UpdateJustificationVertical(const TDesC& aText,const TTextParameters* aParam,TBool aUp); |
|
176 |
|
177 void SetFontNoDuplicate(const CFont* aFont); |
|
178 TBool HasBrushPattern() const; |
|
179 TBool HasFont() const; |
|
180 void InternalizeL(RReadStream& aReadStream); |
|
181 void ExternalizeL(RWriteStream& aWriteStream); |
|
182 TRgb BrushColor() const; |
|
183 TRgb PenColor() const; |
|
184 TRgb TextShadowColor() const; |
|
185 void CopySettings(const MWsGraphicsContext& aGc); |
|
186 void SetFaded(TBool aFaded); |
|
187 void SetFadingParameters(TUint8 aBlackMap, TUint8 aWhiteMap); |
|
188 void FadeArea(const TRegion *aRegion); |
|
189 void MapColors(const TRect &aRect, const TRgb *aColors, TInt aNumPairs=2, TBool aMapForwards=ETrue); |
|
190 void SetUserDisplayMode(TDisplayMode aDisplayMode); |
|
191 TInt UseFont(TInt aFontHandle); |
|
192 |
|
193 /** |
|
194 * GetError |
|
195 * |
|
196 * Return current error status of MWsGraphicsContext |
|
197 * |
|
198 * @return |
|
199 */ |
|
200 TInt GetError() |
|
201 { |
|
202 return KErrNone; // @todo |
|
203 } |
|
204 |
|
205 /** |
|
206 * Origin |
|
207 * |
|
208 * The origin of the GC relative to the screen's origin |
|
209 * |
|
210 * @return Origin |
|
211 */ |
|
212 TPoint Origin() const; |
|
213 |
|
214 /** |
|
215 * ClippingRegion |
|
216 * |
|
217 * The clipping region currently being used |
|
218 * |
|
219 * @return Clipping region |
|
220 */ |
|
221 const TRegion& ClippingRegion() |
|
222 { |
|
223 return iClippingRegion; |
|
224 } |
|
225 |
|
226 /** |
|
227 * Push |
|
228 * |
|
229 * Saves the state of the GC to an internal buffer. Several GC states can be saved in a FILO. |
|
230 * Do not restore a GC (using Pop()) that wasn't properly saved! |
|
231 * |
|
232 * @return KErrNone if successful, else one of the system-wide error codes |
|
233 */ |
|
234 TInt Push() |
|
235 { |
|
236 return KErrNotSupported; // @todo |
|
237 } |
|
238 |
|
239 /** |
|
240 * Pop |
|
241 * |
|
242 * Restores the last GC state that was saved. |
|
243 */ |
|
244 void Pop() |
|
245 { |
|
246 // @todo |
|
247 } |
|
248 |
|
249 private: // New methods |
|
250 |
|
251 /** |
|
252 * C++ constructor |
|
253 * |
|
254 * @param aAlfSendBuffer |
|
255 */ |
|
256 CAlfGraphicsContext( CAlfRsSendBuffer& aAlfSendBuffer ); |
|
257 |
|
258 /** |
|
259 * ConstructL |
|
260 * |
|
261 * Construct |
|
262 */ |
|
263 void ConstructL( ); |
|
264 |
|
265 /** |
|
266 * DoReset |
|
267 * |
|
268 * Reset all context variables to their default values |
|
269 */ |
|
270 void DoReset(); |
|
271 |
|
272 private: |
|
273 |
|
274 /** |
|
275 * locally cached context variables. |
|
276 */ |
|
277 TPoint iOrigin; |
|
278 |
|
279 /** |
|
280 * clipping regions are in screen coordinates |
|
281 */ |
|
282 RRegionBuf<KAlfRsGcMaxClippingRects> iClippingRegion; |
|
283 |
|
284 TRect iClippingRect; |
|
285 |
|
286 TInt iFontHandle; |
|
287 |
|
288 TRgb iTextShadowColor; |
|
289 |
|
290 TBool iBrushPatternSet; |
|
291 |
|
292 TInt iBrushPattern; |
|
293 |
|
294 TRgb iPenColor; |
|
295 |
|
296 TRgb iBrushColor; |
|
297 |
|
298 TSize iPenSize; |
|
299 |
|
300 TInt iDrawMode; |
|
301 |
|
302 TPoint iLinePosition; |
|
303 |
|
304 TBool iBrushUsed; |
|
305 |
|
306 TPoint iBrushOrigin; |
|
307 |
|
308 TInt iBrushStyle; |
|
309 |
|
310 TInt iCharJustExcess; |
|
311 |
|
312 TInt iCharJustNum; |
|
313 |
|
314 TInt iWordJustExcess; |
|
315 |
|
316 TInt iWordJustNum; |
|
317 |
|
318 TPoint iDitherOrigin; |
|
319 |
|
320 TInt iDotLength; |
|
321 |
|
322 TInt iDotMask; |
|
323 |
|
324 TInt iDotParam; |
|
325 |
|
326 TInt iDotDirection; |
|
327 |
|
328 TInt iShadowMode; |
|
329 |
|
330 TInt iStrikethrough; |
|
331 |
|
332 TInt iUnderline; |
|
333 |
|
334 TInt iUserDisplayMode; |
|
335 |
|
336 TInt iPenStyle; |
|
337 |
|
338 /** |
|
339 * Not owned. |
|
340 */ |
|
341 CAlfRsSendBuffer& iSendBuffer; |
|
342 |
|
343 /* |
|
344 * Increased whenever command that requires actual drawing is called. |
|
345 */ |
|
346 TInt iDrawCommandCount; |
|
347 |
|
348 #ifdef _OPTIMIZE_WS_COMMANDS_ADVANCED_ |
|
349 |
|
350 RRegionBuf<5> iDelayedClippingRegion; |
|
351 RRegionBuf<5> iDelayedDrawRegion; |
|
352 |
|
353 enum TRollbackStates |
|
354 { |
|
355 ERollbackClippingState = 1 |
|
356 //ERollbackFontState = 2 |
|
357 }; |
|
358 |
|
359 RRegionBuf<20> iPreviousClippingRegion; |
|
360 |
|
361 #endif |
|
362 |
|
363 #ifdef _OPTIMIZE_WS_COMMANDS_BASIC_ |
|
364 |
|
365 TInt iRollback; |
|
366 |
|
367 enum TDelayedContextState |
|
368 { |
|
369 EModifiedPenStyle = 1, |
|
370 EModifiedBrushStyle = 2, |
|
371 EModifiedPenColor = 4, |
|
372 EModifiedBrushColor = 8, |
|
373 |
|
374 EModifiedClipRect = 16, |
|
375 EModifiedClipReset = 32, |
|
376 |
|
377 EModifiedJustification = 64, |
|
378 EModifiedBrushPattern1 = 128, |
|
379 EModifiedBrushPattern2 = 256, |
|
380 |
|
381 EModifiedSetFontNoDuplicate = 512, |
|
382 EModifiedResetFont = 1024 |
|
383 }; |
|
384 |
|
385 TInt iPreviousPenStyle; |
|
386 TInt iPreviousBrushStyle; |
|
387 TRgb iPreviousPenColor; |
|
388 TRgb iPreviousBrushColor; |
|
389 TInt iPreviousBrushPattern; |
|
390 TInt iPreviousFontHandle; |
|
391 |
|
392 TInt32 iDelayedContextState; |
|
393 |
|
394 #endif |
|
395 |
|
396 }; |
|
397 #endif /*CALFRSGC_H_*/ |