|
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: Implementation of CHuiCanvasVisual. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 #include "uiacceltk/HuiCanvasVisual.h" |
|
21 #include "HuiRenderPlugin.h" |
|
22 #include "uiacceltk/HuiGc.h" |
|
23 #include "uiacceltk/HuiPanic.h" |
|
24 #include "uiacceltk/HuiUtil.h" |
|
25 #include "uiacceltk/HuiStatic.h" |
|
26 #include "uiacceltk/HuiEnv.h" |
|
27 #include "uiacceltk/HuiControl.h" |
|
28 #include "uiacceltk/HuiVisual.h" |
|
29 #include "uiacceltk/HuiLayout.h" |
|
30 #include "uiacceltk/HuiTextMesh.h" |
|
31 #include "uiacceltk/HuiCanvasCmdBufferReader.h" |
|
32 #include "uiacceltk/HuiTransformation.h" |
|
33 #include "huicanvasgc.h" |
|
34 #include "HuiRenderSurface.h" |
|
35 #include "huicanvastexturecache.h" |
|
36 #include "huicanvasbackground.h" |
|
37 #include <graphics/wsgraphicscontext.h> |
|
38 #include <e32cmn.h> |
|
39 #include <AknLayoutFont.h> |
|
40 #include "huicanvasalfpainter.h" |
|
41 #include "huicanvaswspainter.h" |
|
42 #include "HuiRosterImpl.h" |
|
43 #include "huilayoutdata.h" |
|
44 #include "Matrix.h" |
|
45 |
|
46 |
|
47 #include "HuiFxEffect.h" |
|
48 #include "HuiCmdBufferBrush.h" |
|
49 |
|
50 /** Flag to convienintly disable/enable canvas render buffer usage if needed */ |
|
51 /* Turned to EFalse as DFS77 was having booting problems in wk26 */ |
|
52 /* Now checked dynamically from CHuiRenderer to allow different behaviour in DFS77 and DFS79 */ |
|
53 //const TBool KHuiCanvasVisualUseRenderBuffer = EFalse; |
|
54 |
|
55 NONSHARABLE_STRUCT( CHuiCanvasVisual::THuiCanvasVisualData ) |
|
56 { |
|
57 THuiCanvasVisualData(){}; |
|
58 TInt iCommandSetType; |
|
59 TInt iCanvasFlags; |
|
60 |
|
61 // Canvas background |
|
62 CHuiCanvasBackground* iBackground; |
|
63 CHuiCanvasPainter* iCanvasPainter; |
|
64 |
|
65 // External draw content. Can be layout visual that have child visuals. |
|
66 CHuiVisual* iExternalContentVisual; // Not owned |
|
67 |
|
68 CHuiCanvasVisual* iParentCanvas; // Not owned |
|
69 RPointerArray<CHuiCanvasVisual> iChildCanvasList; // Does not own contained visuals |
|
70 RRegionBuf<5> iClipRegion; |
|
71 RRegionBuf<20> iPaintedRegion; |
|
72 CHuiCanvasRenderBuffer* iStoredRenderBuffer; |
|
73 |
|
74 // For handling possible background surface that window may have |
|
75 TBool iLayerUsesAlphaFlag; |
|
76 TRect iLayerExtent; |
|
77 }; |
|
78 |
|
79 EXPORT_C CHuiCanvasVisual* CHuiCanvasVisual::AddNewL(CHuiControl& aOwnerControl, |
|
80 CHuiLayout* aParentLayout) |
|
81 { |
|
82 CHuiCanvasVisual* canvas = STATIC_CAST(CHuiCanvasVisual*, |
|
83 aOwnerControl.AppendVisualL(EHuiVisualTypeCanvas, aParentLayout)); |
|
84 return canvas; |
|
85 } |
|
86 |
|
87 |
|
88 CHuiCanvasVisual::CHuiCanvasVisual(MHuiVisualOwner& aOwner) |
|
89 : CHuiLayout(aOwner) |
|
90 { |
|
91 } |
|
92 |
|
93 void CHuiCanvasVisual::ConstructL() |
|
94 { |
|
95 CHuiLayout::ConstructL(); |
|
96 |
|
97 iCanvasVisualData = new (ELeave) THuiCanvasVisualData; |
|
98 iCanvasVisualData->iCommandSetType = ECommandBufferWs; |
|
99 iCanvasVisualData->iCanvasFlags = 0; |
|
100 iCanvasVisualData->iExternalContentVisual = NULL; |
|
101 iCanvasVisualData->iParentCanvas = NULL; |
|
102 iCanvasVisualData->iBackground = NULL; |
|
103 iCanvasVisualData->iCanvasPainter = NULL; |
|
104 |
|
105 iCanvasVisualData->iBackground = CHuiCanvasBackground::NewL(); |
|
106 iCanvasVisualData->iBackground->SetVisual(this); |
|
107 |
|
108 iCanvasVisualData->iCanvasPainter = CHuiCanvasWsPainter::NewL(); |
|
109 iCanvasVisualData->iCanvasPainter->SetVisual(this); |
|
110 iCanvasVisualData->iStoredRenderBuffer = 0; |
|
111 |
|
112 TBool useCanvasRenderBuffer = CHuiStatic::Renderer().Allows(EHuiRenderPluginAllowVisualPBufferSurfaces); |
|
113 iCanvasVisualData->iCanvasPainter->EnableRenderBuffer(useCanvasRenderBuffer); |
|
114 |
|
115 iCanvasVisualData->iLayerUsesAlphaFlag = EFalse; |
|
116 iCanvasVisualData->iLayerExtent = TRect(); |
|
117 |
|
118 // subwindow effects |
|
119 EnableBrushesL(ETrue); |
|
120 } |
|
121 |
|
122 |
|
123 CHuiCanvasVisual::~CHuiCanvasVisual() |
|
124 { |
|
125 FreeRenderBuffer(); |
|
126 if(iCanvasVisualData->iExternalContentVisual) |
|
127 { |
|
128 // Allow the external content visual to be drawn normally |
|
129 iCanvasVisualData->iExternalContentVisual->ClearFlag(EHuiVisualFlagDrawOnlyAsExternalContent); |
|
130 } |
|
131 |
|
132 if (iCanvasVisualData) |
|
133 { |
|
134 ClearCommandSet(); |
|
135 delete iCanvasVisualData->iBackground; |
|
136 iCanvasVisualData->iBackground = NULL; |
|
137 delete iCanvasVisualData->iCanvasPainter; |
|
138 iCanvasVisualData->iCanvasPainter = NULL; |
|
139 iCanvasVisualData->iExternalContentVisual = NULL; |
|
140 |
|
141 // Tell parent that we are destructed |
|
142 if (iCanvasVisualData->iParentCanvas) |
|
143 { |
|
144 iCanvasVisualData->iParentCanvas->RemoveChildCanvas(this); |
|
145 } |
|
146 |
|
147 // Tell children |
|
148 for (TInt i=0; i<iCanvasVisualData->iChildCanvasList.Count(); i++) |
|
149 { |
|
150 iCanvasVisualData->iChildCanvasList[i]->SetParentCanvas(NULL); |
|
151 } |
|
152 |
|
153 iCanvasVisualData->iPaintedRegion.Close(); |
|
154 iCanvasVisualData->iClipRegion.Close(); |
|
155 iCanvasVisualData->iChildCanvasList.Close(); |
|
156 } |
|
157 |
|
158 delete iCanvasVisualData; |
|
159 iCanvasVisualData = NULL; |
|
160 |
|
161 } |
|
162 |
|
163 CHuiCanvasGc& CHuiCanvasVisual::CanvasGc() const |
|
164 { |
|
165 return iCanvasVisualData->iCanvasPainter->CanvasGc(); |
|
166 } |
|
167 |
|
168 EXPORT_C void CHuiCanvasVisual::SetClearBackground(CHuiDisplay::TClearMode aClearBackground) |
|
169 { |
|
170 if (iCanvasVisualData->iBackground->ClearBackground() != aClearBackground) |
|
171 { |
|
172 iCanvasVisualData->iBackground->SetClearBackground(aClearBackground); |
|
173 SetChanged(); |
|
174 } |
|
175 } |
|
176 |
|
177 EXPORT_C void CHuiCanvasVisual::SetBackgroundColor(const TRgb& aBackgroundColor) |
|
178 { |
|
179 if (iCanvasVisualData->iBackground->BackgroundColor() != aBackgroundColor) |
|
180 { |
|
181 iCanvasVisualData->iBackground->SetBackgroundColor(aBackgroundColor); |
|
182 SetChanged(); |
|
183 } |
|
184 } |
|
185 |
|
186 EXPORT_C void CHuiCanvasVisual::SetBackgroundItems(const RArray<THuiDisplayBackgroundItem>& aItems) |
|
187 { |
|
188 iCanvasVisualData->iBackground->SetBackgroundItems(aItems); |
|
189 } |
|
190 |
|
191 |
|
192 EXPORT_C void CHuiCanvasVisual::SetExternalContentL(CHuiVisual* aVisual) |
|
193 { |
|
194 if (aVisual) |
|
195 { |
|
196 // Clip external content to canvas visual rect |
|
197 SetClipping(ETrue); |
|
198 } |
|
199 else |
|
200 { |
|
201 SetClipping(EFalse); |
|
202 } |
|
203 |
|
204 iCanvasVisualData->iExternalContentVisual = aVisual; |
|
205 } |
|
206 |
|
207 EXPORT_C CHuiVisual* CHuiCanvasVisual::ExternalContent() |
|
208 { |
|
209 return iCanvasVisualData->iExternalContentVisual; |
|
210 } |
|
211 |
|
212 |
|
213 void CHuiCanvasVisual::ExpandRectWithContent(TRect& aRect) const |
|
214 { |
|
215 TRect scannedRect(0,0,0,0); |
|
216 |
|
217 // HandleBuffer tries to return area where the drawing actually happens, area |
|
218 // may be smaller than the visuals displayarea. In that case we dont expand |
|
219 // rect but make it smaller. |
|
220 HandleBuffer(scannedRect, EScanBuffer, NULL); |
|
221 |
|
222 // Note: this could be improved to take care of dirty rects |
|
223 if (Effect() && Display()) |
|
224 { |
|
225 // If there is effect enabled, we cannot say anything about dirty area so |
|
226 // we set whole screen dirty. |
|
227 scannedRect = TRect(TPoint(0,0), Display()->VisibleArea().Size()); |
|
228 } |
|
229 else if (IsBackgroundDrawingEnabled() || IsExternalContentDrawingEnabled()) |
|
230 { |
|
231 // If the visual has external content or draws background, |
|
232 // set always the whole window area as a content. |
|
233 scannedRect = aRect; |
|
234 } |
|
235 |
|
236 if (scannedRect != TRect(0,0,0,0)) |
|
237 { |
|
238 if (!Brushes()) |
|
239 { |
|
240 aRect = scannedRect; |
|
241 } |
|
242 else |
|
243 { |
|
244 // However if there are brushes they need to know the visual displayrect |
|
245 // so incase scanned rect is smaller we use bounding rect as the expanded rect |
|
246 if (!Clipping()) |
|
247 { |
|
248 aRect.BoundingRect(scannedRect); |
|
249 } |
|
250 } |
|
251 } |
|
252 |
|
253 CHuiLayout::ExpandRectWithContent(aRect); |
|
254 } |
|
255 |
|
256 void CHuiCanvasVisual::HandleBuffer(TRect& aDisplayRect, TInt aAction, CHuiGc* aGc) const |
|
257 { |
|
258 if (iCanvasVisualData->iCommandSetType == ECommandBufferWs || iCanvasVisualData->iCommandSetType == ECommandBufferAlf) |
|
259 { |
|
260 TRAPD(err, iCanvasVisualData->iCanvasPainter->HandleBufferL(aDisplayRect, aAction, *this, aGc, DisplayRect().iTl.Round())); |
|
261 if (err) |
|
262 { |
|
263 HUI_DEBUG2(_L("CHuiCanvasVisual::HandleBufferL returned:%d command type was: %d"), err,iCanvasVisualData->iCommandSetType); |
|
264 } |
|
265 } |
|
266 else |
|
267 { |
|
268 // do nothing |
|
269 } |
|
270 |
|
271 } |
|
272 |
|
273 |
|
274 TBool CHuiCanvasVisual::PrepareDrawL() |
|
275 { |
|
276 if (Flags() & EHuiVisualFlagDrawOnlyAsExternalContent) |
|
277 { |
|
278 // This is used only as external content visual. Return now if we are not currently drawing |
|
279 // external content. |
|
280 if (!Display() || !Display()->RosterImpl().IsDrawingExternalContent()) |
|
281 { |
|
282 return ETrue; |
|
283 } |
|
284 } |
|
285 |
|
286 TBool ret = CHuiLayout::PrepareDrawL(); |
|
287 |
|
288 if (ret && IsExternalContentDrawingEnabled()) |
|
289 { |
|
290 if (Display()) |
|
291 { |
|
292 // Enable drawing external visual tree |
|
293 Display()->RosterImpl().SetDrawingExternalContent(ETrue); |
|
294 ret = iCanvasVisualData->iExternalContentVisual->PrepareDrawL(); |
|
295 Display()->RosterImpl().SetDrawingExternalContent(EFalse); |
|
296 } |
|
297 } |
|
298 return ret; |
|
299 } |
|
300 |
|
301 |
|
302 void CHuiCanvasVisual::Draw(CHuiGc& aGc) const |
|
303 { |
|
304 if (Flags() & EHuiVisualFlagDrawOnlyAsExternalContent) |
|
305 { |
|
306 // This is used only as external content visual. Return now if we are not currently drawing |
|
307 // external content. |
|
308 if (!Display() || !Display()->RosterImpl().IsDrawingExternalContent()) |
|
309 { |
|
310 return; |
|
311 } |
|
312 } |
|
313 |
|
314 TBool semiTranparentEffectActive = (Effect() && Effect()->IsSemitransparent()); |
|
315 TBool childWindowEffectActive = (Effect() && EffectIsAppliedToChildren()); |
|
316 TBool invisible = (iOpacity.Now() <= EPSILON && !semiTranparentEffectActive); |
|
317 |
|
318 if( invisible || |
|
319 (!HasCommandBuffers(ETrue /*include children*/) && |
|
320 !childWindowEffectActive && |
|
321 !IsBackgroundDrawingEnabled() && |
|
322 !IsExternalContentDrawingEnabled()&& |
|
323 !IsExternalContentDrawingEnabled(ETrue /*include children*/) |
|
324 |
|
325 )) |
|
326 { |
|
327 // This will not be visible due to being completely transparent, or the visual does not actually draw anything |
|
328 |
|
329 // However, the draw should continue, if the effect is possibly manipulating the opacity of the visual. See CHuiFxVisualLayer::Draw. |
|
330 return; |
|
331 } |
|
332 |
|
333 if ((IsDelayedEffectSource() || Freezed())) |
|
334 { |
|
335 if (StoredRenderBuffer()) |
|
336 { |
|
337 DrawStoredFullScreenRenderBuffer(aGc); |
|
338 return; |
|
339 } |
|
340 else if (iCanvasVisualData->iStoredRenderBuffer) |
|
341 { |
|
342 DrawStoredVisualRenderBuffer(); |
|
343 return; |
|
344 } |
|
345 } |
|
346 |
|
347 // If this visual is completely under another visual, then this visual |
|
348 // shouldn't draw anything, but of course there might still be children |
|
349 // that should be drawn. |
|
350 // For example, consider the case where you have two visuals: |
|
351 // - visual B is child of window A. |
|
352 // - visual A and B have exactly same position and size. |
|
353 // - both are opaque. |
|
354 // Thus, window A can have 'under opaque' hint, but not window B. |
|
355 const TBool drawVisualContent = !( Flags() & EHuiVisualFlagUnderOpaqueHint ); |
|
356 |
|
357 THuiRealRect area = DisplayRect(); |
|
358 |
|
359 // Apply local transformation. |
|
360 EnterLocalProjection(aGc, ETrue, 0.f, &area); |
|
361 Transform(aGc, ETrue, &area); |
|
362 |
|
363 if (drawVisualContent) |
|
364 { |
|
365 DrawBrushes(aGc, EHuiBrushLayerBackground); |
|
366 } |
|
367 |
|
368 if(Clipping()) |
|
369 { |
|
370 // @todo Clipping not going to work if there is a transformation? |
|
371 // Layout clipping is not affected by transformation. |
|
372 aGc.Enable(CHuiGc::EFeatureClipping); |
|
373 aGc.PushClip(); |
|
374 aGc.Clip(area); |
|
375 } |
|
376 |
|
377 // Flag to know what we did |
|
378 TBool didDrawEffect = EFalse; |
|
379 |
|
380 if (EffectActive()) |
|
381 { |
|
382 // Note that EHuiVisualFlagOpaqueHint improves performance a lot in cached effect drawing |
|
383 TBool transparent = EFalse; |
|
384 transparent |= (!(Flags() & EHuiVisualFlagOpaqueHint)); // Does not have opaque hint -> always transparent |
|
385 transparent |= iOpacity.Now() < 1.0f; // Opacity less than 1.0f -> always transparent |
|
386 |
|
387 TBool refreshCache = EFalse; |
|
388 if (EffectIsAppliedToChildren()) |
|
389 { |
|
390 refreshCache |= ChildTreeChanged(EHuiCanvasFlagExcludeFromParentEffect); |
|
391 } |
|
392 else |
|
393 { |
|
394 refreshCache |= Changed(); |
|
395 } |
|
396 |
|
397 // TODO: We could update this somewhere else, not here everytime |
|
398 iCanvasVisualData->iPaintedRegion.Clear(); |
|
399 TInt paintedAreaCount = PaintedAreaCount(); |
|
400 for (TInt i=0; i<paintedAreaCount; i++ ) |
|
401 { |
|
402 iCanvasVisualData->iPaintedRegion.AddRect( CanvasPaintedArea(i).iPaintedRect.Round() ); |
|
403 } |
|
404 |
|
405 didDrawEffect = Effect()->CachedDraw(aGc, area, refreshCache, !transparent, iCanvasVisualData->iPaintedRegion); |
|
406 } |
|
407 |
|
408 if ( !didDrawEffect ) |
|
409 { |
|
410 DrawSelf(aGc, area); |
|
411 } |
|
412 else |
|
413 { |
|
414 // Effect was drawn, OpenGLES/OpenVG may be in different state than what Gc thinks so we restore it. |
|
415 aGc.RestoreState(); |
|
416 } |
|
417 |
|
418 if (!didDrawEffect) |
|
419 { |
|
420 // Draw all children |
|
421 DrawCanvasChildren(aGc, 0, 0); |
|
422 } |
|
423 else if (didDrawEffect && !EffectIsAppliedToChildren()) |
|
424 { |
|
425 // Draw all children |
|
426 DrawCanvasChildren(aGc, 0, 0); |
|
427 } |
|
428 else if (didDrawEffect && EffectIsAppliedToChildren()) |
|
429 { |
|
430 // Draw only children which do not want to have parent effect applied to them |
|
431 DrawCanvasChildren(aGc, EHuiCanvasFlagExcludeFromParentEffect, 0); |
|
432 } |
|
433 |
|
434 if (drawVisualContent && IsContentDrawingEnabled() && IsExternalContentDrawingEnabled()) |
|
435 { |
|
436 if (Display()) |
|
437 { |
|
438 // Enable drawing external visual tree |
|
439 Display()->RosterImpl().SetDrawingExternalContent(ETrue); |
|
440 // The possible effect has been attached to the layout of the visual itself |
|
441 // If the external content needs an effect, too, it should probably be defined |
|
442 // separately, or alternatively the drawing of an effect should be able to |
|
443 // handle the external content, too. |
|
444 iCanvasVisualData->iExternalContentVisual->Draw(aGc); |
|
445 Display()->RosterImpl().SetDrawingExternalContent(EFalse); |
|
446 } |
|
447 } |
|
448 |
|
449 if(Clipping()) |
|
450 { |
|
451 // Restore original clipping rectangle. |
|
452 aGc.PopClip(); |
|
453 } |
|
454 |
|
455 if (drawVisualContent) |
|
456 { |
|
457 DrawBrushes(aGc, EHuiBrushLayerForeground); |
|
458 } |
|
459 |
|
460 // Restore original transformation. |
|
461 Transform(aGc, EFalse); |
|
462 EnterLocalProjection(aGc, EFalse); |
|
463 } |
|
464 |
|
465 |
|
466 void CHuiCanvasVisual::DrawSelf(CHuiGc& aGc, const TRect& aDisplayRect) const |
|
467 { |
|
468 #ifdef HUI_DEBUG_TRACK_DRAWING |
|
469 if ( Tracking() ) |
|
470 { |
|
471 RDebug::Print(_L("CHuiCanvasVisual::DrawSelf - tracked visual")); |
|
472 } |
|
473 #endif |
|
474 |
|
475 TReal32 effectiveOpacity = EffectiveOpacity(); |
|
476 |
|
477 if (effectiveOpacity <= 0 || !HasCommandBuffers(ETrue)) |
|
478 { |
|
479 // In case background drawing is enabled, and even if we don't have command buffers we still |
|
480 // want to issue clear. If the background drawing is enabled here, it means that the |
|
481 // window bound to this visual has a background surface. If we dont do the clear, the |
|
482 // surface will be covered by the Alf surface, ie. the underlying surface is not visible |
|
483 // It's quite common for applications using Khronos APIs not to issue any drawing commands, |
|
484 // as the drawing goes directly via Khronos APIs. |
|
485 // In that case, the background clearing should only be skipped if the window is not |
|
486 // visible (ie. the visual is inactive), and that should already be handled elsewhere. |
|
487 if (!IsBackgroundDrawingEnabled()) |
|
488 { |
|
489 return; |
|
490 } |
|
491 } |
|
492 |
|
493 if ((IsDelayedEffectSource() || Freezed())) |
|
494 { |
|
495 if (StoredRenderBuffer()) |
|
496 { |
|
497 DrawStoredFullScreenRenderBuffer(aGc); |
|
498 return; |
|
499 } |
|
500 else if (iCanvasVisualData->iStoredRenderBuffer) |
|
501 { |
|
502 DrawStoredVisualRenderBuffer(); |
|
503 return; |
|
504 } |
|
505 } |
|
506 |
|
507 // Use 'under opaque' hint to optimize drawing. |
|
508 // See comment from CHuiCanvasVisual::Draw for further details. |
|
509 const TBool drawVisualContent = !( Flags() & EHuiVisualFlagUnderOpaqueHint ); |
|
510 |
|
511 // Canvas clipping is done in DrawSelf instead of Draw so that canvas clipping does not clip effects |
|
512 if (IsCanvasClippingEnabled()) |
|
513 { |
|
514 aGc.Enable(CHuiGc::EFeatureClipping); |
|
515 aGc.PushClip(); |
|
516 aGc.Clip(ClipRegion()); |
|
517 } |
|
518 |
|
519 // Draws background if it has been defined |
|
520 if (drawVisualContent && IsBackgroundDrawingEnabled()) |
|
521 { |
|
522 iCanvasVisualData->iBackground->DrawSelf(aGc, aDisplayRect); |
|
523 } |
|
524 |
|
525 aGc.Push(EHuiGcMatrixModel); |
|
526 |
|
527 TRect displayRect = aDisplayRect; |
|
528 |
|
529 if (IsContentDrawingEnabled()) |
|
530 { |
|
531 // Handle buffer normally unless layered subwindow effects are active |
|
532 if (drawVisualContent && !IsContentDrawingLayered()) |
|
533 { |
|
534 HandleBuffer(displayRect, EDrawBuffer, &aGc); |
|
535 } |
|
536 |
|
537 if (EffectActive() && EffectIsAppliedToChildren()) |
|
538 { |
|
539 DrawCanvasChildren(aGc, 0, EHuiCanvasFlagExcludeFromParentEffect); |
|
540 } |
|
541 } |
|
542 |
|
543 aGc.Pop(EHuiGcMatrixModel); |
|
544 |
|
545 if(IsCanvasClippingEnabled()) |
|
546 { |
|
547 // Restore original clipping rectangle. |
|
548 aGc.PopClip(); |
|
549 } |
|
550 } |
|
551 |
|
552 void CHuiCanvasVisual::DrawChildren(CHuiGc& aGc) const |
|
553 { |
|
554 // Draw child windows, begin |
|
555 TBool afterOthers = EFalse; |
|
556 const TInt count = Count(); |
|
557 for(TInt i = 0; i < count; ++i) |
|
558 { |
|
559 CHuiVisual* visual = iHuiLayoutPrivateData->iChildren[i]; |
|
560 //Ignore inactive child visuals |
|
561 if ( visual->Flags()& EHuiVisualFlagInactive ) |
|
562 { |
|
563 continue; |
|
564 } |
|
565 if(visual->Flags() & EHuiVisualFlagDrawAfterOthers) |
|
566 { |
|
567 afterOthers = ETrue; |
|
568 continue; |
|
569 } |
|
570 |
|
571 // @todo No need to draw children that won't be visible. |
|
572 visual->Draw(aGc); |
|
573 } |
|
574 if(afterOthers) |
|
575 { |
|
576 for(TInt i = 0; i < count; ++i) |
|
577 { |
|
578 if(iHuiLayoutPrivateData->iChildren[i]->Flags() & EHuiVisualFlagDrawAfterOthers) |
|
579 { |
|
580 iHuiLayoutPrivateData->iChildren[i]->Draw(aGc); |
|
581 } |
|
582 } |
|
583 } |
|
584 } |
|
585 |
|
586 void CHuiCanvasVisual::DrawCanvasChildren(CHuiGc& aGc, TInt aIncludeCanvasFlags, TInt aExcludeCanvasFlags) const |
|
587 { |
|
588 // Draw child windows, begin |
|
589 TBool afterOthers = EFalse; |
|
590 const TInt count = Count(); |
|
591 for(TInt i = 0; i < count; ++i) |
|
592 { |
|
593 // This cast is not really safe, but dynamic cast is slow |
|
594 CHuiCanvasVisual* visual = (CHuiCanvasVisual*) iHuiLayoutPrivateData->iChildren[i]; |
|
595 //Ignore inactive child visuals |
|
596 if ((visual->Flags()& EHuiVisualFlagInactive)) |
|
597 { |
|
598 continue; |
|
599 } |
|
600 |
|
601 if (aIncludeCanvasFlags && !(visual->CanvasFlags()& aIncludeCanvasFlags)) |
|
602 { |
|
603 continue; |
|
604 } |
|
605 |
|
606 if (aExcludeCanvasFlags && (visual->CanvasFlags()& aExcludeCanvasFlags)) |
|
607 { |
|
608 continue; |
|
609 } |
|
610 |
|
611 if(visual->Flags() & EHuiVisualFlagDrawAfterOthers) |
|
612 { |
|
613 afterOthers = ETrue; |
|
614 continue; |
|
615 } |
|
616 |
|
617 // @todo No need to draw children that won't be visible. |
|
618 visual->Draw(aGc); |
|
619 } |
|
620 if(afterOthers) |
|
621 { |
|
622 for(TInt i = 0; i < count; ++i) |
|
623 { |
|
624 if(iHuiLayoutPrivateData->iChildren[i]->Flags() & EHuiVisualFlagDrawAfterOthers) |
|
625 { |
|
626 iHuiLayoutPrivateData->iChildren[i]->Draw(aGc); |
|
627 } |
|
628 } |
|
629 } |
|
630 } |
|
631 |
|
632 TBool CHuiCanvasVisual::Changed() const |
|
633 { |
|
634 if (iCanvasVisualData->iCanvasPainter->BuffersChanged()) |
|
635 { |
|
636 return ETrue; |
|
637 } |
|
638 else if(CHuiLayout::Changed()) |
|
639 { |
|
640 return ETrue; |
|
641 } |
|
642 |
|
643 TBool hasChanged = EFalse; |
|
644 if (IsExternalContentDrawingEnabled()) |
|
645 { |
|
646 hasChanged = iCanvasVisualData->iExternalContentVisual->Changed(); |
|
647 } |
|
648 |
|
649 return hasChanged; |
|
650 } |
|
651 |
|
652 TBool CHuiCanvasVisual::ChildTreeChanged(TInt aExcludeCanvasFlags) const |
|
653 { |
|
654 // CHuiLayout::Changed() does not check children. |
|
655 // This utility method checks whole child tree below this visual. |
|
656 TBool changed = EFalse; |
|
657 |
|
658 // Check wheter we should include this visual or igonre it. |
|
659 if (aExcludeCanvasFlags) |
|
660 { |
|
661 if (!(iCanvasVisualData->iCanvasFlags & aExcludeCanvasFlags)) |
|
662 { |
|
663 changed |= Changed(); |
|
664 } |
|
665 } |
|
666 |
|
667 const TInt count = Count(); |
|
668 for(TInt i = 0; i < count; ++i) |
|
669 { |
|
670 CHuiCanvasVisual* visual = (CHuiCanvasVisual*) iHuiLayoutPrivateData->iChildren[i]; |
|
671 changed |= visual->ChildTreeChanged(aExcludeCanvasFlags); |
|
672 if (changed) |
|
673 { |
|
674 break; |
|
675 } |
|
676 } |
|
677 return changed; |
|
678 } |
|
679 |
|
680 |
|
681 EXPORT_C void CHuiCanvasVisual::ClearChanged() |
|
682 { |
|
683 iCanvasVisualData->iCanvasPainter->ClearAllBuffersChanged(); |
|
684 CHuiLayout::ClearChanged(); |
|
685 } |
|
686 |
|
687 EXPORT_C void CHuiCanvasVisual::SetChanged() |
|
688 { |
|
689 iCanvasVisualData->iCanvasPainter->SetAllBuffersChanged(ETrue); |
|
690 CHuiLayout::SetChanged(); |
|
691 } |
|
692 |
|
693 EXPORT_C void CHuiCanvasVisual::SetCommandSetL( const TDesC8& aCommands ) |
|
694 { |
|
695 Env().CanvasTextureCache().EnableTouchCountCheck(); |
|
696 ClearCommandSet(); |
|
697 TRAP_IGNORE(iCanvasVisualData->iCanvasPainter->SetCommandSetL(aCommands)); |
|
698 |
|
699 // Memory optimization. Do not prepare cache if visual is inactive. |
|
700 TBool rosterFrozen = Display() && Display()->Roster().IsVisibleContentFrozen(); |
|
701 TBool inactive = EFalse; |
|
702 inactive |= Flags() & EHuiVisualFlagInactive; |
|
703 inactive |= Flags() & EHuiVisualFlagUnderOpaqueHint; |
|
704 |
|
705 if (rosterFrozen || inactive) |
|
706 { |
|
707 ClearCache(); |
|
708 } |
|
709 else |
|
710 { |
|
711 PrepareCache(); |
|
712 } |
|
713 |
|
714 SetChanged(); |
|
715 Env().CanvasTextureCache().EnableTouchCountCheck(EFalse); |
|
716 } |
|
717 |
|
718 THuiRealPoint CHuiCanvasVisual::ConvertPoint(const THuiRealPoint& aPointInUnits) const |
|
719 { |
|
720 // Convert first from units to pixels |
|
721 THuiRealPoint converted = LocalPointInPixels(aPointInUnits); |
|
722 |
|
723 // Pixels are relative to the canvas visual itself, change to display relative |
|
724 THuiRealRect displayRect = DisplayRect(); |
|
725 converted.iX += displayRect.iTl.iX; |
|
726 converted.iY += displayRect.iTl.iY; |
|
727 |
|
728 return converted; |
|
729 } |
|
730 |
|
731 void CHuiCanvasVisual::ExpandRect(TRect& aRectToExpand, const TRect& aNewRect) const |
|
732 { |
|
733 if (aRectToExpand == TRect(0,0,0,0)) |
|
734 { |
|
735 aRectToExpand = aNewRect; |
|
736 } |
|
737 else |
|
738 { |
|
739 aRectToExpand.BoundingRect(aNewRect); |
|
740 } |
|
741 } |
|
742 |
|
743 EXPORT_C void CHuiCanvasVisual::SetCommandType( TInt aCommandType ) |
|
744 { |
|
745 TRAP_IGNORE(SetCommandTypeL(aCommandType)); |
|
746 } |
|
747 |
|
748 EXPORT_C void CHuiCanvasVisual::ClearCommandSet() |
|
749 { |
|
750 iCanvasVisualData->iCanvasPainter->ClearCommandSet(); |
|
751 SetChanged(); |
|
752 } |
|
753 |
|
754 #ifdef HUI_DEBUG_TRACK_DRAWING |
|
755 EXPORT_C void CHuiCanvasVisual::SetTrackCommandSet( TFileName& aFileName, TBool aTrack ) |
|
756 { |
|
757 iCanvasVisualData->iCanvasPainter->SetTrackCommandSet( aFileName, aTrack || iTrackVisual ); |
|
758 } |
|
759 #else |
|
760 EXPORT_C void CHuiCanvasVisual::SetTrackCommandSet( TFileName&, TBool){ |
|
761 } |
|
762 #endif |
|
763 |
|
764 |
|
765 EXPORT_C void CHuiCanvasVisual::AddCommandSetL( const TDesC8& aMoreCommands ) |
|
766 { |
|
767 Env().CanvasTextureCache().EnableTouchCountCheck(); |
|
768 TRAP_IGNORE(iCanvasVisualData->iCanvasPainter->AddCommandSetL(aMoreCommands)); |
|
769 |
|
770 // Memory optimization. Do not prepare cache if visual is inactive. |
|
771 TBool rosterFrozen = Display() && Display()->Roster().IsVisibleContentFrozen(); |
|
772 TBool inactive = EFalse; |
|
773 inactive |= Flags() & EHuiVisualFlagInactive; |
|
774 inactive |= Flags() & EHuiVisualFlagUnderOpaqueHint; |
|
775 |
|
776 if (rosterFrozen || inactive) |
|
777 { |
|
778 ClearCache(); |
|
779 } |
|
780 else |
|
781 { |
|
782 PrepareCache(); |
|
783 } |
|
784 |
|
785 SetChanged(); |
|
786 Env().CanvasTextureCache().EnableTouchCountCheck(EFalse); |
|
787 } |
|
788 |
|
789 EXPORT_C void CHuiCanvasVisual::AddPartialCommandSetL( const TDesC8& aMoreCommands, TBool aLastPart ) |
|
790 { |
|
791 iCanvasVisualData->iCanvasPainter->AddPartialCommandSetL(aMoreCommands, aLastPart); |
|
792 } |
|
793 |
|
794 |
|
795 EXPORT_C void CHuiCanvasVisual::ClearCache() |
|
796 { |
|
797 iCanvasVisualData->iCanvasPainter->ClearCache(); |
|
798 } |
|
799 |
|
800 EXPORT_C void CHuiCanvasVisual::PrepareCache() |
|
801 { |
|
802 if (iCanvasVisualData->iCanvasPainter->HasCommandBuffers()) |
|
803 { |
|
804 TRect displayRect = DisplayRect(); |
|
805 HandleBuffer(displayRect, EScanBuffer, NULL); |
|
806 } |
|
807 } |
|
808 |
|
809 void CHuiCanvasVisual::SetCommandTypeL(TInt aCommandType) |
|
810 { |
|
811 if (iCanvasVisualData->iCommandSetType == aCommandType) |
|
812 { |
|
813 return; |
|
814 } |
|
815 |
|
816 if (aCommandType == ECommandBufferAlf) |
|
817 { |
|
818 delete iCanvasVisualData->iCanvasPainter; |
|
819 iCanvasVisualData->iCanvasPainter = NULL; |
|
820 iCanvasVisualData->iCommandSetType = ECommandBufferAlf; |
|
821 iCanvasVisualData->iCanvasPainter = CHuiCanvasAlfPainter::NewL(); |
|
822 iCanvasVisualData->iCanvasPainter->SetVisual(this); |
|
823 } |
|
824 else if (aCommandType == ECommandBufferWs) |
|
825 { |
|
826 delete iCanvasVisualData->iCanvasPainter; |
|
827 iCanvasVisualData->iCanvasPainter = NULL; |
|
828 iCanvasVisualData->iCommandSetType = ECommandBufferWs; |
|
829 iCanvasVisualData->iCanvasPainter = CHuiCanvasWsPainter::NewL(); |
|
830 iCanvasVisualData->iCanvasPainter->SetVisual(this); |
|
831 TBool useCanvasRenderBuffer = CHuiStatic::Renderer().Allows(EHuiRenderPluginAllowVisualPBufferSurfaces); |
|
832 iCanvasVisualData->iCanvasPainter->EnableRenderBuffer(useCanvasRenderBuffer); |
|
833 } |
|
834 else |
|
835 { |
|
836 // For pc lint |
|
837 } |
|
838 } |
|
839 |
|
840 EXPORT_C TInt CHuiCanvasVisual::PaintedAreaCount() const |
|
841 { |
|
842 TInt count = 0; |
|
843 |
|
844 count = iCanvasVisualData->iCanvasPainter->PaintedAreaCount(); |
|
845 |
|
846 // Check if there is background clearing, it may increase painted area count |
|
847 if (IsBackgroundDrawingEnabled()) |
|
848 { |
|
849 TInt backgroundItemCount = iCanvasVisualData->iBackground->BackgroundItemsCount(); |
|
850 |
|
851 if (backgroundItemCount > 0) |
|
852 { |
|
853 // Background items |
|
854 count += backgroundItemCount; |
|
855 } |
|
856 else |
|
857 { |
|
858 // If there are no background items, then color clearing is used. |
|
859 count += 1; |
|
860 } |
|
861 } |
|
862 |
|
863 return count; |
|
864 } |
|
865 |
|
866 EXPORT_C THuiCanvasPaintedArea CHuiCanvasVisual::PaintedArea(TInt aIndex) |
|
867 { |
|
868 return CanvasPaintedArea(aIndex); |
|
869 } |
|
870 |
|
871 THuiCanvasPaintedArea CHuiCanvasVisual::CanvasPaintedArea(TInt aIndex) const |
|
872 { |
|
873 if (IsBackgroundDrawingEnabled()) |
|
874 { |
|
875 // Check if there is background clearing, it may increase painted area count |
|
876 THuiCanvasPaintedArea background; |
|
877 TInt backgroundItemCount = iCanvasVisualData->iBackground->BackgroundItemsCount(); |
|
878 |
|
879 if (backgroundItemCount > 0) |
|
880 { |
|
881 // Background items |
|
882 if (aIndex < backgroundItemCount) |
|
883 { |
|
884 RArray<THuiDisplayBackgroundItem> backgroundItems; |
|
885 iCanvasVisualData->iBackground->GetBackgroundItems(backgroundItems); |
|
886 |
|
887 if (backgroundItems[aIndex].ClearMode() == CHuiDisplay::EClearNone) |
|
888 { |
|
889 // No clearing -> transparent |
|
890 background.iPaintType = EHuiCanvasPaintTypeTransparent; |
|
891 } |
|
892 else if (backgroundItems[aIndex].ClearMode() == CHuiDisplay::EClearWithColor) |
|
893 { |
|
894 // Clearing with color, transparency does NOT depend on alpha but is always opaque |
|
895 // because clearing is done with "fast" clear and it just writes the alpha |
|
896 // instead of blending |
|
897 background.iPaintType = EHuiCanvasPaintTypeOpaque; |
|
898 } |
|
899 else |
|
900 { |
|
901 // By default assume opaque |
|
902 background.iPaintType = EHuiCanvasPaintTypeOpaque; |
|
903 } |
|
904 |
|
905 background.iPaintedRect = backgroundItems[aIndex].Rect(); |
|
906 return background; |
|
907 } |
|
908 else |
|
909 { |
|
910 return iCanvasVisualData->iCanvasPainter->PaintedArea(aIndex - backgroundItemCount); |
|
911 } |
|
912 } |
|
913 else |
|
914 { |
|
915 // If there are no background items, then color clearing is used. |
|
916 if (aIndex == 0) |
|
917 { |
|
918 background.iPaintedRect = DisplayRect(); |
|
919 background.iPaintType = /*(iCanvasVisualData->iBackground->BackgroundColor().Alpha() == 255) ?*/ EHuiCanvasPaintTypeOpaque;// : EHuiCanvasPaintTypeTransparent; |
|
920 return background; |
|
921 } |
|
922 } |
|
923 } |
|
924 |
|
925 return iCanvasVisualData->iCanvasPainter->PaintedArea(aIndex); |
|
926 } |
|
927 |
|
928 EXPORT_C TInt CHuiCanvasVisual::SetCapturingBufferL(CFbsBitmap* aTargetBuffer) |
|
929 { |
|
930 return iCanvasVisualData->iCanvasPainter->SetCapturingBufferL(aTargetBuffer); |
|
931 } |
|
932 |
|
933 EXPORT_C void CHuiCanvasVisual::SetCanvasFlags(TInt aCanvasFlags) |
|
934 { |
|
935 TInt oldFlags = iCanvasVisualData->iCanvasFlags; |
|
936 iCanvasVisualData->iCanvasFlags |= aCanvasFlags; |
|
937 |
|
938 // Set visual changed if flags were really changed |
|
939 if (oldFlags != iCanvasVisualData->iCanvasFlags) |
|
940 { |
|
941 SetChanged(); |
|
942 } |
|
943 } |
|
944 |
|
945 EXPORT_C void CHuiCanvasVisual::ClearCanvasFlags(TInt aCanvasFlags) |
|
946 { |
|
947 TInt oldFlags = iCanvasVisualData->iCanvasFlags; |
|
948 iCanvasVisualData->iCanvasFlags &= ~aCanvasFlags; |
|
949 |
|
950 // Set visual changed if flags were really changed |
|
951 if (oldFlags != iCanvasVisualData->iCanvasFlags) |
|
952 { |
|
953 SetChanged(); |
|
954 } |
|
955 } |
|
956 |
|
957 EXPORT_C TInt CHuiCanvasVisual::CanvasFlags() |
|
958 { |
|
959 return iCanvasVisualData->iCanvasFlags; |
|
960 } |
|
961 |
|
962 |
|
963 EXPORT_C TBool CHuiCanvasVisual::IsBackgroundDrawingEnabled() const |
|
964 { |
|
965 TBool drawBackground = EFalse; |
|
966 drawBackground |= (iCanvasVisualData->iBackground->ClearBackground() != CHuiDisplay::EClearNone); |
|
967 drawBackground |= (iCanvasVisualData->iBackground->BackgroundItemsCount() > 0); |
|
968 |
|
969 if (iCanvasVisualData->iCanvasFlags & EHuiCanvasFlagDisableCanvasBackground) |
|
970 { |
|
971 drawBackground = EFalse; |
|
972 } |
|
973 return drawBackground; |
|
974 } |
|
975 |
|
976 TBool CHuiCanvasVisual::IsContentDrawingEnabled() const |
|
977 { |
|
978 TBool drawContent = ETrue; |
|
979 if (iCanvasVisualData->iCanvasFlags & EHuiCanvasFlagDisableCanvasContent) |
|
980 { |
|
981 drawContent = EFalse; |
|
982 } |
|
983 return drawContent; |
|
984 } |
|
985 |
|
986 TBool CHuiCanvasVisual::IsExternalContentDrawingEnabled(TBool aIncludeChildren) const |
|
987 { |
|
988 TBool drawExternalContent = EFalse; |
|
989 if (iCanvasVisualData->iExternalContentVisual) |
|
990 { |
|
991 drawExternalContent = ETrue; |
|
992 } |
|
993 if (aIncludeChildren) |
|
994 { |
|
995 for (TInt i=0; !drawExternalContent && i<Count(); i++) |
|
996 { |
|
997 CHuiCanvasVisual* canvasVisual = (CHuiCanvasVisual*) &Visual(i); |
|
998 drawExternalContent |= canvasVisual->IsExternalContentDrawingEnabled(ETrue); |
|
999 } |
|
1000 } |
|
1001 return drawExternalContent; |
|
1002 } |
|
1003 |
|
1004 EXPORT_C void CHuiCanvasVisual::SetParentCanvas(CHuiCanvasVisual* aParent) |
|
1005 { |
|
1006 iCanvasVisualData->iParentCanvas = aParent; |
|
1007 if (aParent) |
|
1008 { |
|
1009 aParent->AddChildCanvas(this); |
|
1010 } |
|
1011 } |
|
1012 |
|
1013 const TRegion& CHuiCanvasVisual::ClipRegion() const |
|
1014 { |
|
1015 iCanvasVisualData->iClipRegion.Clear(); |
|
1016 // TODO: This should be region in cases when canvas shape is non-rectangular, |
|
1017 // for now just use display rect. Window Shape is currently only known by the wspainter, |
|
1018 // so new interface is needed to query it. |
|
1019 iCanvasVisualData->iClipRegion.AddRect(DisplayRect().Round()); |
|
1020 |
|
1021 CHuiCanvasVisual* parent = iCanvasVisualData->iParentCanvas; |
|
1022 if (parent) |
|
1023 { |
|
1024 const TRegion& parentClipRegion = parent->ClipRegion(); |
|
1025 iCanvasVisualData->iClipRegion.Intersect(parentClipRegion); |
|
1026 } |
|
1027 |
|
1028 return iCanvasVisualData->iClipRegion; |
|
1029 } |
|
1030 |
|
1031 void CHuiCanvasVisual::AddChildCanvas(CHuiCanvasVisual* aChild) |
|
1032 { |
|
1033 if (iCanvasVisualData->iChildCanvasList.Find(aChild) == KErrNotFound) |
|
1034 { |
|
1035 iCanvasVisualData->iChildCanvasList.Append(aChild); |
|
1036 } |
|
1037 } |
|
1038 |
|
1039 void CHuiCanvasVisual::RemoveChildCanvas(CHuiCanvasVisual* aChild) |
|
1040 { |
|
1041 for (TInt i=0; i<iCanvasVisualData->iChildCanvasList.Count(); i++) |
|
1042 { |
|
1043 if (iCanvasVisualData->iChildCanvasList[i] == aChild) |
|
1044 { |
|
1045 iCanvasVisualData->iChildCanvasList.Remove(i); |
|
1046 break; |
|
1047 } |
|
1048 } |
|
1049 } |
|
1050 |
|
1051 EXPORT_C TBool CHuiCanvasVisual::LayerUsesAlphaFlag() |
|
1052 { |
|
1053 return iCanvasVisualData->iLayerUsesAlphaFlag; |
|
1054 } |
|
1055 |
|
1056 EXPORT_C void CHuiCanvasVisual::SetLayerUsesAlphaFlag(TBool aEnabled) |
|
1057 { |
|
1058 iCanvasVisualData->iLayerUsesAlphaFlag = aEnabled; |
|
1059 } |
|
1060 |
|
1061 EXPORT_C TRect& CHuiCanvasVisual::LayerExtent() |
|
1062 { |
|
1063 return iCanvasVisualData->iLayerExtent; |
|
1064 } |
|
1065 |
|
1066 EXPORT_C void CHuiCanvasVisual::SetLayerExtent(TRect& aExtent) |
|
1067 { |
|
1068 iCanvasVisualData->iLayerExtent = aExtent; |
|
1069 if(0)// aExtent != TRect() ) // background surface was set or moved to new place |
|
1070 { |
|
1071 EnableTransformationL(); |
|
1072 CHuiTransformation& transformation = Transformation(); |
|
1073 |
|
1074 TPoint extentPos = aExtent.iTl; |
|
1075 TPoint visualPos = Pos().Now(); |
|
1076 |
|
1077 TReal32 xDif = (TReal32)(extentPos.iX - visualPos.iX); |
|
1078 TReal32 yDif = (TReal32)(extentPos.iY - visualPos.iY); |
|
1079 |
|
1080 TSize extentSize = aExtent.Size(); |
|
1081 TPoint visualSize = Size().Now(); |
|
1082 |
|
1083 TReal32 hVisualWidth = (TReal32)visualSize.iX/2; |
|
1084 TReal32 hVisualHeigth = (TReal32)visualSize.iY/2; |
|
1085 |
|
1086 |
|
1087 TReal32 xScale = (TReal32)extentSize.iWidth/visualSize.iX; |
|
1088 TReal32 yScale = (TReal32)extentSize.iHeight/visualSize.iY; |
|
1089 |
|
1090 // create transformation when applying first time |
|
1091 if(transformation.Count() == 0) |
|
1092 { |
|
1093 transformation.Translate(xDif,yDif); |
|
1094 // for moving the visual origo to visual's top left corner |
|
1095 transformation.Translate(-hVisualWidth,-hVisualHeigth); |
|
1096 transformation.Scale(xScale,yScale); |
|
1097 // move back |
|
1098 transformation.Translate(hVisualWidth,hVisualHeigth); |
|
1099 } |
|
1100 else // update existing transformations |
|
1101 { |
|
1102 CHuiTransformation::TTransform& translate = transformation[0]; |
|
1103 translate.iParams[EHuiTransformParamTranslateX] = xDif; |
|
1104 translate.iParams[EHuiTransformParamTranslateY] = yDif; |
|
1105 |
|
1106 CHuiTransformation::TTransform& translateforscale = transformation[1]; |
|
1107 translateforscale.iParams[EHuiTransformParamTranslateX] = -hVisualWidth; |
|
1108 translateforscale.iParams[EHuiTransformParamTranslateY] = -hVisualHeigth; |
|
1109 |
|
1110 CHuiTransformation::TTransform& scale = transformation[2]; |
|
1111 scale.iParams[EHuiTransformParamScaleX] = xScale; |
|
1112 scale.iParams[EHuiTransformParamScaleY] = yScale; |
|
1113 |
|
1114 CHuiTransformation::TTransform& translateback = transformation[3]; |
|
1115 translateback.iParams[EHuiTransformParamTranslateX] = hVisualWidth; |
|
1116 translateback.iParams[EHuiTransformParamTranslateY] = hVisualHeigth; |
|
1117 } |
|
1118 } |
|
1119 else // background surface was removed |
|
1120 { |
|
1121 EnableTransformationL(EFalse); |
|
1122 } |
|
1123 } |
|
1124 |
|
1125 |
|
1126 TBool CHuiCanvasVisual::IsCanvasClippingEnabled() const |
|
1127 { |
|
1128 return iCanvasVisualData->iCanvasFlags & EHuiCanvasFlagEnableCanvasClipping; |
|
1129 } |
|
1130 |
|
1131 TBool CHuiCanvasVisual::EffectActive() const |
|
1132 { |
|
1133 return Effect() && !LoadingEffect(); |
|
1134 } |
|
1135 |
|
1136 TBool CHuiCanvasVisual::IsContentDrawingLayered() const |
|
1137 { |
|
1138 // TODO: real flag here to check if drawing normally or layered with brushes |
|
1139 return (Brushes() && (Brushes()->Count() > 0)); |
|
1140 } |
|
1141 |
|
1142 EXPORT_C void CHuiCanvasVisual::StoreRenderBufferL() |
|
1143 { |
|
1144 CHuiCanvasGc& gc = CanvasGc(); |
|
1145 CHuiCanvasRenderBuffer *content_rb = Env().CanvasTextureCache().FindCachedRenderBuffer(*this); |
|
1146 if (content_rb) |
|
1147 { |
|
1148 if (!iCanvasVisualData->iStoredRenderBuffer) |
|
1149 { |
|
1150 iCanvasVisualData->iStoredRenderBuffer = gc.CreateRenderBufferL(TSize(0,0)); |
|
1151 } |
|
1152 iCanvasVisualData->iStoredRenderBuffer->InitializeL(content_rb->Size()); |
|
1153 iCanvasVisualData->iStoredRenderBuffer->Copy(*content_rb); |
|
1154 } |
|
1155 } |
|
1156 |
|
1157 void CHuiCanvasVisual::DrawStoredVisualRenderBuffer() const |
|
1158 { |
|
1159 CHuiCanvasGc& gc = CanvasGc(); |
|
1160 THuiRealPoint dest_point = DisplayRect().iTl; |
|
1161 CHuiCanvasRenderBuffer *stored = iCanvasVisualData->iStoredRenderBuffer; |
|
1162 gc.DrawImage(*stored, dest_point); |
|
1163 } |
|
1164 |
|
1165 void CHuiCanvasVisual::DrawStoredFullScreenRenderBuffer(CHuiGc& aGc) const |
|
1166 { |
|
1167 if (!Display()) return; |
|
1168 CHuiCanvasGc& gc = *iHuiLayoutPrivateData->iGc; |
|
1169 gc.SetGc(aGc); |
|
1170 gc.SetDefaults(); |
|
1171 gc.PushTransformationMatrix(); |
|
1172 |
|
1173 TRect displayArea = Display()->VisibleArea(); |
|
1174 TInt h = displayArea.Height(); |
|
1175 |
|
1176 // Pixels are upside down in OpenVG canvas render buffer |
|
1177 if (CHuiStatic::Env().Renderer() == EHuiRendererVg10) |
|
1178 { |
|
1179 gc.Translate(0.0f, h, 0.0f); |
|
1180 gc.Scale(1.f, -1.f, 1.f); |
|
1181 } |
|
1182 |
|
1183 THuiRealPoint dest_point = DisplayRect().iTl; |
|
1184 CHuiCanvasRenderBuffer *stored = StoredRenderBuffer(); |
|
1185 gc.DrawImage(*stored, dest_point); |
|
1186 |
|
1187 gc.PopTransformationMatrix(); |
|
1188 } |
|
1189 |
|
1190 EXPORT_C void CHuiCanvasVisual::FreeRenderBuffer() |
|
1191 { |
|
1192 if (iCanvasVisualData) |
|
1193 { |
|
1194 if (iCanvasVisualData->iStoredRenderBuffer) |
|
1195 { |
|
1196 delete iCanvasVisualData->iStoredRenderBuffer; |
|
1197 iCanvasVisualData->iStoredRenderBuffer = NULL; |
|
1198 } |
|
1199 } |
|
1200 } |
|
1201 |
|
1202 EXPORT_C TBool CHuiCanvasVisual::HasCommandBuffers(TBool aIncludeChildren) const |
|
1203 { |
|
1204 TBool hasCommandBuffers = iCanvasVisualData->iCanvasPainter->HasCommandBuffers(); |
|
1205 if (aIncludeChildren) |
|
1206 { |
|
1207 for (TInt i=0; i<Count(); i++) |
|
1208 { |
|
1209 CHuiCanvasVisual* canvasVisual = (CHuiCanvasVisual*) &Visual(i); // Dynamic cast is too slow for us ;) |
|
1210 hasCommandBuffers |= canvasVisual->HasCommandBuffers(aIncludeChildren); |
|
1211 if (hasCommandBuffers) |
|
1212 { |
|
1213 break; |
|
1214 } |
|
1215 } |
|
1216 } |
|
1217 return hasCommandBuffers; |
|
1218 } |
|
1219 |
|
1220 |
|
1221 void CHuiCanvasVisual::SetSize(const THuiRealSize& aSize, TInt aTransitionTime) |
|
1222 { |
|
1223 CHuiLayout::SetSize(aSize, aTransitionTime); |
|
1224 UpdateChildrenLayout(aTransitionTime); |
|
1225 } |
|
1226 |
|
1227 TBool CHuiCanvasVisual::ChildSize(TInt aOrdinal, TSize& aSize) |
|
1228 { |
|
1229 TBool result(EFalse); |
|
1230 THuiRealRect rect; |
|
1231 TInt childRectStatus(THuiLayoutChildRectUpdateNotNeeded); |
|
1232 childRectStatus = ChildRect(aOrdinal, rect); |
|
1233 if(childRectStatus != THuiLayoutChildRectNotImplemented) |
|
1234 { |
|
1235 result = (childRectStatus & THuiLayoutChildRectSizeUpdateNeeded); |
|
1236 if(result) |
|
1237 { |
|
1238 THuiRealPoint size(rect.Width(), rect.Height()); |
|
1239 aSize = LocalPointInPixels(size).AsSize(); |
|
1240 } |
|
1241 } |
|
1242 return result; |
|
1243 } |
|
1244 |
|
1245 TBool CHuiCanvasVisual::ChildPos(TInt aOrdinal, TPoint& aPos) |
|
1246 { |
|
1247 TBool result(EFalse); |
|
1248 THuiRealRect rect; |
|
1249 TInt childRectStatus(THuiLayoutChildRectUpdateNotNeeded); |
|
1250 childRectStatus = ChildRect(aOrdinal, rect); |
|
1251 if(childRectStatus != THuiLayoutChildRectNotImplemented) |
|
1252 { |
|
1253 result = (childRectStatus & THuiLayoutChildRectPosUpdateNeeded); |
|
1254 if(result) |
|
1255 { |
|
1256 aPos = LocalPointInPixels(rect.iTl); |
|
1257 } |
|
1258 } |
|
1259 return result; |
|
1260 } |
|
1261 |
|
1262 TInt CHuiCanvasVisual::ChildRect(TInt /*aOrdinal*/, THuiRealRect& aPos) |
|
1263 { |
|
1264 THuiRealSize innerSize = InnerSize(); |
|
1265 aPos.iTl = InnerTopLeft(); |
|
1266 aPos.iBr = aPos.iTl + THuiRealPoint(innerSize.iWidth, innerSize.iHeight) ; |
|
1267 return THuiLayoutChildRectLayoutUpdateNeeded; |
|
1268 } |
|
1269 |
|
1270 |