|
1 /* |
|
2 * Copyright (c) 2006-2007 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: Definition of CHuiCanvasPainter. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 #ifndef __HUICANVASPAINTER_H__ |
|
21 #define __HUICANVASPAINTER_H__ |
|
22 |
|
23 |
|
24 #include <e32cmn.h> |
|
25 #include <e32std.h> |
|
26 #include <e32base.h> |
|
27 #include <e32def.h> |
|
28 #include "huicanvastexturecache.h" |
|
29 |
|
30 |
|
31 /* Forward declarations. */ |
|
32 class CHuiControl; |
|
33 class THuiCanvasDrawImageParams; |
|
34 class THuiCanvasTextParameters; |
|
35 class CHuiCanvasGc ; |
|
36 class CHuiGc; |
|
37 class CHuiCanvasCommandBuffer; |
|
38 |
|
39 const TInt KHuiCanvasCommandBufferRegionGranularity = 5; |
|
40 |
|
41 enum THuiCanvasBufferStatusFlags |
|
42 { |
|
43 /** Buffer is new */ |
|
44 EHuiCanvasBufferStatusNew = 0x1, |
|
45 /** Buffer has been scanned */ |
|
46 EHuiCanvasBufferStatusScanned = 0x2, |
|
47 /** Buffer has been drawn */ |
|
48 EHuiCanvasBufferStatusDrawn = 0x4, |
|
49 |
|
50 /** Flag to say wheter buffer really contains somethign that really draws something */ |
|
51 EHuiCanvasBufferContainsDrawing = 0x8000, |
|
52 /** All flags, can be used for clearing all flags */ |
|
53 EHuiCanvasBufferStatusAll = 0xFFFFFFFF |
|
54 }; |
|
55 |
|
56 |
|
57 NONSHARABLE_CLASS( MHuiCmdBufDestroyObserver ) |
|
58 { |
|
59 public: |
|
60 virtual void DestroyBuffer(CHuiCanvasCommandBuffer *aBuffer)=0; |
|
61 }; |
|
62 |
|
63 NONSHARABLE_CLASS( CHuiCanvasCommandBuffer ) : public CBase |
|
64 { |
|
65 public: |
|
66 CHuiCanvasCommandBuffer() : |
|
67 iChanged(ETrue), |
|
68 iStatusFlags(EHuiCanvasBufferStatusNew) |
|
69 { |
|
70 iCreationTime.UniversalTime(); |
|
71 } |
|
72 ~CHuiCanvasCommandBuffer() |
|
73 { |
|
74 TInt count = iObservers.Count(); |
|
75 for(int i=0;i<count;i++) |
|
76 { |
|
77 iObservers[i]->DestroyBuffer(this); |
|
78 } |
|
79 iObservers.Close(); |
|
80 delete iCommands; |
|
81 iUpdateRegion.Close(); |
|
82 iOriginalUpdateRegion.Close(); |
|
83 #ifdef HUI_DEBUG_TRACK_DRAWING |
|
84 delete iProcessName; |
|
85 #endif |
|
86 } |
|
87 |
|
88 void SetStatusFlags(THuiCanvasBufferStatusFlags aStatusFlags) |
|
89 { |
|
90 iStatusFlags |= aStatusFlags; |
|
91 } |
|
92 |
|
93 void ClearStatusFlags(THuiCanvasBufferStatusFlags aStatusFlags) |
|
94 { |
|
95 iStatusFlags &= ~aStatusFlags; |
|
96 } |
|
97 void AddDestroyObserver(MHuiCmdBufDestroyObserver *aObserver ) |
|
98 { |
|
99 iObservers.AppendL(aObserver); |
|
100 } |
|
101 void RemoveDestroyObserver(MHuiCmdBufDestroyObserver *aObserver) |
|
102 { |
|
103 TInt count = iObservers.Count(); |
|
104 for(int i=count-1;i>=0;i--) |
|
105 { |
|
106 if (iObservers[i]==aObserver) |
|
107 { |
|
108 iObservers.Remove(i); |
|
109 } |
|
110 } |
|
111 } |
|
112 public: |
|
113 /** Buffer containing the drawing commands */ |
|
114 HBufC8* iCommands; |
|
115 |
|
116 /** Optional region which specifies the area where commands are to be drawn */ |
|
117 RRegionBuf<KHuiCanvasCommandBufferRegionGranularity> iUpdateRegion; |
|
118 |
|
119 /** The original iUpdateRegion before any intersection with the shape region */ |
|
120 RRegionBuf<KHuiCanvasCommandBufferRegionGranularity> iOriginalUpdateRegion; |
|
121 |
|
122 /** Rect of the visual when command buffer was set/added */ |
|
123 THuiRealRect iOriginalDisplayRect; |
|
124 |
|
125 /** The position of the visual, when the update region was last modfied */ |
|
126 TPoint iPositionForUpdateRegion; |
|
127 |
|
128 /** Internal flag that can be used to track changes. This is similar to visual changed flag. */ |
|
129 TBool iChanged; |
|
130 |
|
131 /** Internal flag that can be used to track buffer status. This is mainly used for optimizing drawing. */ |
|
132 TInt iStatusFlags; |
|
133 |
|
134 /** Time when this buffer has been created */ |
|
135 TTime iCreationTime; |
|
136 |
|
137 /** Display orientation when this buffer has been created */ |
|
138 CHuiGc::TOrientation iOrientation; |
|
139 |
|
140 /** Flag to tell if buffer has unsupported commands (fallback mode is needed) */ |
|
141 TBool iContainsUnsupportedCommands; |
|
142 |
|
143 #ifdef HUI_DEBUG_TRACK_DRAWING |
|
144 TBool iTrackedBuffer; |
|
145 |
|
146 HBufC16* iProcessName; |
|
147 #endif |
|
148 |
|
149 RPointerArray<MHuiCmdBufDestroyObserver> iObservers; |
|
150 }; |
|
151 |
|
152 enum THuiCanvasBufferAction |
|
153 { |
|
154 /** Draw buffer content to the canvas */ |
|
155 EDrawBuffer, |
|
156 |
|
157 /** Scan buffer content */ |
|
158 EScanBuffer |
|
159 }; |
|
160 |
|
161 /** |
|
162 * This class is used internally by the toolkit and thus should |
|
163 * not be used by the applications directly. |
|
164 */ |
|
165 NONSHARABLE_CLASS (CHuiCanvasPainter) : public CBase |
|
166 { |
|
167 |
|
168 public: |
|
169 |
|
170 /** |
|
171 * Sets buffer that contains canvas drawing commands. This |
|
172 * method clears previous buffer(s), so this is eqvivalent |
|
173 * to calling both ClearCommandSet and AddCommandSetL. |
|
174 * |
|
175 * @param aCommands Commanbuffer |
|
176 */ |
|
177 virtual void SetCommandSetL( const TDesC8& aCommands ); |
|
178 |
|
179 /** |
|
180 * Clears buffer(s) that contains canvas drawing commands. |
|
181 */ |
|
182 virtual void ClearCommandSet(); |
|
183 |
|
184 /** |
|
185 * Adds buffer that contains more canvas drawing commands, |
|
186 * those will be executed after the buffers that has been |
|
187 * added previously. |
|
188 * @param aMoreCommands Commanbuffer |
|
189 */ |
|
190 virtual void AddCommandSetL( const TDesC8& aMoreCommands ); |
|
191 |
|
192 /** |
|
193 * Adds partial buffer that contains more canvas drawing commands. These |
|
194 * commands are appended to the commands set previously with this method |
|
195 * until param aLastPart has value ETrue. After that whole command set |
|
196 * will be added among possibly already existing command sets and |
|
197 * it will be drawable. |
|
198 * |
|
199 * @param aMoreCommands Commanbuffer |
|
200 * @param aLastPart EFalse if there are more commands to be added into this |
|
201 * command set before it is wanted to be available for drawing. ETrue if |
|
202 * command set is ready and no more parts are expected. |
|
203 */ |
|
204 virtual void AddPartialCommandSetL( const TDesC8& aMoreCommands, TBool aLastPart ); |
|
205 |
|
206 #ifdef HUI_DEBUG_TRACK_DRAWING |
|
207 virtual void SetTrackCommandSet( TFileName& aFileName, TBool aTrack ); |
|
208 #endif |
|
209 /** |
|
210 * Clears internal cached texts and images. |
|
211 */ |
|
212 virtual void ClearCache()= 0; |
|
213 |
|
214 /** |
|
215 * Handles the command buffer(s), either draws or performs a scan. |
|
216 * |
|
217 * @param aDisplayRect Area in screen coordinates where painter is supposed to draw, |
|
218 * method implementation should modify the given rect to contain the real (smaller) |
|
219 * area where drawing happens. |
|
220 * |
|
221 * @param aAction Action that painter is supposed to do with the buffer. |
|
222 * |
|
223 * Possible values are: |
|
224 * |
|
225 * EScanBuffer - Painter is supposed to scan the buffer and |
|
226 * 1) Prepare its internal caches (if it uses such) and other |
|
227 * similar opearations which may take relatively long time to complete. |
|
228 * 2) Prepare PaintedAreaCount() and PaintedArea() to contain the |
|
229 * real rectangles where drawing is going to happen. |
|
230 * |
|
231 * EDrawBuffer - Painter is supposed to draw the content of the |
|
232 * buffer to the given display rect. This action is supposed to |
|
233 * be as fast as possible. |
|
234 * |
|
235 * @param aUser Canvas visual using this painter |
|
236 * @param aGc Toolkit graphics context |
|
237 * @param @aPos The current position of the visual. This is used for drawing |
|
238 * the buffers on correct location, if the visual position changes |
|
239 */ |
|
240 virtual void HandleBufferL(TRect& aDisplayRect, TInt aAction, const CHuiCanvasVisual& aUser, CHuiGc* aGc, TPoint aPos ) = 0; |
|
241 |
|
242 /** Same as the other handlebuffer, except it allows external command buffers to be provided |
|
243 * |
|
244 */ |
|
245 virtual void HandleBufferL(TRect& aDisplayRect, TInt aAction, const CHuiCanvasVisual& aUser, CHuiGc* aGc, TPoint aPos, TPtrC8 aCommands, CHuiCanvasCommandBuffer *buf) =0; |
|
246 /** |
|
247 * Returns the number of rectangular areas which contain something that is |
|
248 * drawn by the painter. |
|
249 * |
|
250 * @return number of painted areas. |
|
251 * @see PaintedArea() |
|
252 */ |
|
253 virtual TInt PaintedAreaCount() const = 0; |
|
254 |
|
255 /** |
|
256 * Returns information of the painted area at given index. |
|
257 * |
|
258 * @aIndex Index of the painted area. |
|
259 * @return Painted area info. |
|
260 * @see PaintedAreaCount() |
|
261 */ |
|
262 virtual THuiCanvasPaintedArea PaintedArea(TInt aIndex) = 0; |
|
263 |
|
264 /** |
|
265 * Draws content of the window in pixel format to the given bitmap. |
|
266 * This method may not be supported in all commanbuffertype/renderer combinations. |
|
267 * |
|
268 * @param aTargetBuffer where content of the window is to be drawn. NULL if the drawing |
|
269 * is to be stopped. |
|
270 * |
|
271 * @return KErrNotSupported if the current renderer/painter does not support the |
|
272 * feature. Leave happens in other unexpected error situtations. |
|
273 * |
|
274 */ |
|
275 virtual TInt SetCapturingBufferL(CFbsBitmap* /*aTarget*/) = 0; |
|
276 |
|
277 /** |
|
278 * Tells painter to enable/disable render buffer (if it is supported by the |
|
279 * painter implementation) |
|
280 * |
|
281 * @return KErrNotSupported if the current renderer/painter does not support the |
|
282 * feature. * |
|
283 */ |
|
284 virtual TInt EnableRenderBuffer(TBool aEnable = ETrue) = 0; |
|
285 |
|
286 /** |
|
287 * Destructor |
|
288 */ |
|
289 virtual ~CHuiCanvasPainter(); |
|
290 |
|
291 /** |
|
292 * Returns reference to used canvas gc |
|
293 */ |
|
294 virtual CHuiCanvasGc& CanvasGc() const = 0; |
|
295 |
|
296 /** |
|
297 * Sets canvas visual that this painter draws into |
|
298 */ |
|
299 void SetVisual(CHuiCanvasVisual* aVisual); |
|
300 |
|
301 /** |
|
302 * Gets canvas visual that this painter is drawing into. |
|
303 */ |
|
304 CHuiCanvasVisual* Visual(); |
|
305 |
|
306 /** |
|
307 * Does this painter have command buffers |
|
308 */ |
|
309 TBool HasCommandBuffers(); |
|
310 |
|
311 /** |
|
312 * Is any of the buffers changed |
|
313 */ |
|
314 TBool BuffersChanged() const; |
|
315 |
|
316 /** |
|
317 * Clear every buffers changed flag. |
|
318 */ |
|
319 void ClearAllBuffersChanged(); |
|
320 |
|
321 /** |
|
322 * Sets every buffers changed flag to the given value. |
|
323 * @param aChange flag value |
|
324 */ |
|
325 void SetAllBuffersChanged(TBool aChanged); |
|
326 |
|
327 /** |
|
328 * Requests env to start refresh of whole visual tree |
|
329 */ |
|
330 void RequestContinueRefresh(); |
|
331 |
|
332 /** |
|
333 * Sets given status for every buffer. |
|
334 */ |
|
335 void SetAllBufferStatusFlags(THuiCanvasBufferStatusFlags aStatus); |
|
336 |
|
337 /** |
|
338 * Clears given status for every buffer. |
|
339 */ |
|
340 void ClearAllBufferStatusFlags(THuiCanvasBufferStatusFlags aStatus); |
|
341 |
|
342 /** |
|
343 * Does this painter have command buffers with given statusflags. |
|
344 */ |
|
345 TBool HasCommandBuffers(THuiCanvasBufferStatusFlags aStatusFlags); |
|
346 |
|
347 /** |
|
348 * Does this painter have command buffers without given statusflags. |
|
349 */ |
|
350 TBool HasCommandBuffersWithoutFlags(THuiCanvasBufferStatusFlags aStatusFlags); |
|
351 |
|
352 /** |
|
353 * Does this painter have command buffers older than given time. |
|
354 */ |
|
355 TBool HasOldCommandBuffers(TInt aLifeTimeInMs); |
|
356 |
|
357 TInt NumBuffers() const { return iCommandBuffers.Count(); } |
|
358 CHuiCanvasCommandBuffer *At(TInt aIndex) const { return iCommandBuffers[aIndex]; } |
|
359 protected: |
|
360 |
|
361 /** Command buffers */ |
|
362 RPointerArray<CHuiCanvasCommandBuffer> iCommandBuffers; |
|
363 |
|
364 /** Partial command buffer which will be updated with more commands soon. This buffer is not yet ready for drawing */ |
|
365 HBufC8* iPartialCommandBuffer; |
|
366 |
|
367 /** Canvas visual which uses this background */ |
|
368 CHuiCanvasVisual* iCanvasVisual; |
|
369 }; |
|
370 #endif // __HUICANVASPAINTER_H__ |