64 { |
64 { |
65 iRoot->SetVisual(aVisual); |
65 iRoot->SetVisual(aVisual); |
66 } |
66 } |
67 EXPORT_C void CHuiFxEffect::SetVisual( MHuiEffectable *aEffectable ) |
67 EXPORT_C void CHuiFxEffect::SetVisual( MHuiEffectable *aEffectable ) |
68 { |
68 { |
69 iEffectable = aEffectable; |
|
70 iRoot->SetVisual(aEffectable); |
69 iRoot->SetVisual(aEffectable); |
71 } |
70 } |
72 EXPORT_C void CHuiFxEffect::SetEngine( CHuiFxEngine *aEngine ) |
71 EXPORT_C void CHuiFxEffect::SetEngine( CHuiFxEngine *aEngine ) |
73 { |
72 { |
74 iEngine = aEngine; |
73 iEngine = aEngine; |
83 #endif |
82 #endif |
84 } |
83 } |
85 |
84 |
86 EXPORT_C CHuiFxEffect::~CHuiFxEffect() |
85 EXPORT_C CHuiFxEffect::~CHuiFxEffect() |
87 { |
86 { |
88 ReleaseCachedRenderTarget(); |
|
89 |
|
90 delete iRoot; |
87 delete iRoot; |
91 iRoot = NULL; |
88 iRoot = NULL; |
92 NotifyEffectEndObserver(); |
89 NotifyEffectEndObserver(); |
|
90 |
|
91 ReleaseCachedRenderTarget(); |
|
92 |
93 iEngine->RemoveEffect(this); |
93 iEngine->RemoveEffect(this); |
94 if (iEngine && iGroupId != KErrNotFound && !(iFlags & KHuiReadyToDrawNotified)) |
94 if (iEngine && iGroupId != KErrNotFound && !(iFlags & KHuiReadyToDrawNotified)) |
95 { |
95 { |
96 // if effect was deleted before it was drawn, the group must be notified. If this was the last effect in the group |
96 // if effect was deleted before it was drawn, the group must be notified. If this was the last effect in the group |
97 // the group will be removed by the EffectReadyToStart |
97 // the group will be removed by the EffectReadyToStart |
178 if (iCachedRenderTarget) |
178 if (iCachedRenderTarget) |
179 { |
179 { |
180 iEngine->ReleaseRenderbuffer(iCachedRenderTarget); |
180 iEngine->ReleaseRenderbuffer(iCachedRenderTarget); |
181 iCachedRenderTarget = NULL; |
181 iCachedRenderTarget = NULL; |
182 } |
182 } |
183 |
|
184 if(iRoot) |
|
185 { |
|
186 iRoot->ReleaseAllCachedRenderTargets(*iEngine); |
|
187 } |
|
188 } |
183 } |
189 |
184 |
190 void CHuiFxEffect::PrepareCachedRenderTarget(const TPoint& aPosition, const TSize& aSize, TBool aClear, TBool aEnableBackground) |
185 void CHuiFxEffect::PrepareCachedRenderTarget(const TPoint& aPosition, const TSize& aSize, TBool aClear, TBool aEnableBackground) |
191 { |
186 { |
192 // If size has chnaged, we must delete old one |
187 // If size has chnaged, we must delete old one |
193 if (iCachedRenderTarget && |
188 if (iCachedRenderTarget && |
194 iCachedRenderTarget->Size() != aSize) |
189 iCachedRenderTarget->Size() != aSize) |
195 { |
190 { |
196 iEngine->ReleaseRenderbuffer(iCachedRenderTarget); |
191 ReleaseCachedRenderTarget(); |
197 iCachedRenderTarget = NULL; |
|
198 } |
192 } |
199 |
193 |
200 // Accure new buffer |
194 // Accure new buffer |
201 if (!iCachedRenderTarget) |
195 if (!iCachedRenderTarget) |
202 { |
196 { |
262 { |
256 { |
263 return EFalse; |
257 return EFalse; |
264 } |
258 } |
265 } |
259 } |
266 |
260 |
267 TBool CHuiFxEffect::PrepareDrawL(CHuiGc& aGc, const TRect& aDisplayRect) |
261 TBool CHuiFxEffect::CachedDraw(CHuiGc& aGc, const TRect& aDisplayRect, TBool aRefreshCachedRenderTarget, TBool aOpaque) |
268 { |
262 { |
269 if(!iEffectable || iEffectable->EffectReadyToDrawNextFrame() ) |
263 RRegion dummy; |
270 { |
264 TBool ret = CachedDraw(aGc, aDisplayRect, aRefreshCachedRenderTarget, aOpaque, dummy,EFalse); |
271 iFramesDrawn++; |
265 dummy.Close(); |
272 } |
266 return ret; |
273 |
267 } |
|
268 |
|
269 // TODO: effect area should be reduced if aClipRegion is smaller than aDisplayRect. |
|
270 TBool CHuiFxEffect::CachedDraw(CHuiGc& aGc, const TRect& aDisplayRect, TBool aRefreshCachedRenderTarget, TBool aOpaque, const TRegion& aClipRegion, TBool aHasSurface, TInt aAlpha) |
|
271 { |
|
272 #ifdef HUIFX_TRACE |
|
273 RDebug::Print(_L("CHuiFxEffect::CachedDraw - 0x%x"), this); |
|
274 #endif |
|
275 iFramesDrawn++; |
|
276 if (!CHuiStatic::Renderer().Allows(EHuiRenderPluginAllowVisualPBufferSurfaces)) |
|
277 { |
|
278 return EFalse; |
|
279 } |
|
280 |
|
281 |
|
282 CHuiFxRenderbuffer* target = NULL; |
|
283 |
274 // Prepare all layers |
284 // Prepare all layers |
275 TRect displayArea = aGc.DisplayArea(); |
285 TRect displayArea = aGc.DisplayArea(); |
276 TRect targetArea = aDisplayRect; |
286 TRect targetArea = aDisplayRect; |
277 targetArea.Intersection(displayArea); |
287 targetArea.Intersection(displayArea); |
278 |
288 |
279 if (targetArea.Width() <= 0 || targetArea.Height() <= 0) |
289 if (targetArea.Width() <= 0 || targetArea.Height() <= 0) |
280 { |
290 { |
281 // Not visible |
291 // Not visible |
282 return ETrue; |
292 return ETrue; |
283 } |
293 } |
284 |
294 |
285 if (!iEngine || !iRoot) |
295 if (!iEngine || !iRoot) |
286 { |
296 { |
287 return EFalse; |
297 return EFalse; |
288 } |
298 } |
289 |
299 |
297 if (EffectFlags() & KHuiFxEffectDisableMarginsFlag) |
307 if (EffectFlags() & KHuiFxEffectDisableMarginsFlag) |
298 { |
308 { |
299 iRoot->EnableMargin(EFalse); |
309 iRoot->EnableMargin(EFalse); |
300 } |
310 } |
301 |
311 |
|
312 // Check if surface pixels are to be used for this effect in all layers. |
|
313 if (EffectFlags() & KHuiFxEnableBackgroundInAllLayers) |
|
314 { |
|
315 iRoot->SetAlwaysReadSurfacePixels(ETrue); |
|
316 } |
302 |
317 |
303 iRoot->SetTargetRect(targetArea); |
318 iRoot->SetTargetRect(targetArea); |
304 iRoot->SetSourceRect(targetArea); |
319 iRoot->SetSourceRect(targetArea); |
305 iRoot->SetDisplayArea(displayArea); |
320 iRoot->SetDisplayArea(displayArea); |
306 |
321 |
309 if (err != KErrNone) |
324 if (err != KErrNone) |
310 { |
325 { |
311 return EFalse; |
326 return EFalse; |
312 } |
327 } |
313 |
328 |
314 return ETrue; |
|
315 } |
|
316 |
|
317 TBool CHuiFxEffect::CachedDraw(CHuiGc& aGc, const TRect& aDisplayRect, TBool aRefreshCachedRenderTarget, TBool aOpaque) |
|
318 { |
|
319 RRegion dummy; |
|
320 TBool ret = CachedDraw(aGc, aDisplayRect, aRefreshCachedRenderTarget, aOpaque, dummy,EFalse); |
|
321 dummy.Close(); |
|
322 return ret; |
|
323 } |
|
324 |
|
325 // TODO: effect area should be reduced if aClipRegion is smaller than aDisplayRect. |
|
326 TBool CHuiFxEffect::CachedDraw(CHuiGc& aGc, const TRect& aDisplayRect, TBool aRefreshCachedRenderTarget, TBool aOpaque, const TRegion& aClipRegion, TBool aHasSurface, TInt aAlpha) |
|
327 { |
|
328 #ifdef HUIFX_TRACE |
|
329 RDebug::Print(_L("CHuiFxEffect::CachedDraw - 0x%x"), this); |
|
330 #endif |
|
331 |
|
332 if (!CHuiStatic::Renderer().Allows(EHuiRenderPluginAllowVisualPBufferSurfaces)) |
|
333 { |
|
334 return EFalse; |
|
335 } |
|
336 |
|
337 CHuiFxRenderbuffer* target = NULL; |
|
338 |
|
339 // Prepare all layers |
|
340 TRect displayArea = aGc.DisplayArea(); |
|
341 TRect targetArea = aDisplayRect; |
|
342 targetArea.Intersection(displayArea); |
|
343 |
|
344 if (targetArea.Width() <= 0 || targetArea.Height() <= 0) |
|
345 { |
|
346 // Not visible |
|
347 return ETrue; |
|
348 } |
|
349 |
|
350 if (!iEngine || !iRoot) |
|
351 { |
|
352 return EFalse; |
|
353 } |
|
354 |
|
355 if (iEngine->LowMemoryState()) |
|
356 { |
|
357 // No memory, no effects. |
|
358 return EFalse; |
|
359 } |
|
360 |
|
361 // Check if surface pixels are to be used for this effect in all layers. |
|
362 if (EffectFlags() & KHuiFxEnableBackgroundInAllLayers) |
|
363 { |
|
364 iRoot->SetAlwaysReadSurfacePixels(ETrue); |
|
365 } |
|
366 |
|
367 iRoot->SetVisualContentState(aRefreshCachedRenderTarget, aOpaque); |
|
368 |
|
369 if (IsCachedRenderTargetSupported() && IsCachedRenderTargetPreferred()) |
329 if (IsCachedRenderTargetSupported() && IsCachedRenderTargetPreferred()) |
370 { |
330 { |
371 // Background needs to be captured from surface if effect uses background AND |
331 // Background needs to be captured from surface if effect uses background AND |
372 // Visual is transparent or margin is enabled AND |
332 // Visual is transparent or margin is enabled AND |
373 // Background has not been disabled with a effect specific flag |
333 // Background has not been disabled with a effect specific flag |
444 } |
404 } |
445 } |
405 } |
446 else |
406 else |
447 { |
407 { |
448 // Release cached render target just in case it is reserved for some reason |
408 // Release cached render target just in case it is reserved for some reason |
449 if (iCachedRenderTarget) |
409 ReleaseCachedRenderTarget(); |
450 { |
|
451 iEngine->ReleaseRenderbuffer(iCachedRenderTarget); |
|
452 iCachedRenderTarget = NULL; |
|
453 } |
|
454 |
410 |
455 // Use default onscreen render target |
411 // Use default onscreen render target |
456 if (!target) |
412 if (!target) |
457 { |
413 { |
458 target = iEngine->DefaultRenderbuffer(); |
414 target = iEngine->DefaultRenderbuffer(); |
464 } |
420 } |
465 |
421 |
466 // Normal drawing |
422 // Normal drawing |
467 iRoot->Draw(*iEngine, aGc, *target, *target, aHasSurface); |
423 iRoot->Draw(*iEngine, aGc, *target, *target, aHasSurface); |
468 } |
424 } |
|
425 |
469 return ETrue; |
426 return ETrue; |
470 } |
427 } |
471 |
428 |
472 EXPORT_C TBool CHuiFxEffect::Draw(CHuiGc& aGc, const TRect& aDisplayRect, TBool aHasSurface) |
429 EXPORT_C TBool CHuiFxEffect::Draw(CHuiGc& aGc, const TRect& aDisplayRect, TBool aHasSurface) |
473 { |
430 { |
474 // Prepare all layers |
431 // Prepare all layers |
475 #ifdef HUIFX_TRACE |
432 #ifdef HUIFX_TRACE |
476 RDebug::Print(_L("CHuiFxEffect::Draw - 0x%x"), this); |
433 RDebug::Print(_L("CHuiFxEffect::Draw - 0x%x"), this); |
477 #endif |
434 #endif |
|
435 iFramesDrawn++; |
478 if (!CHuiStatic::Renderer().Allows(EHuiRenderPluginAllowVisualPBufferSurfaces)) |
436 if (!CHuiStatic::Renderer().Allows(EHuiRenderPluginAllowVisualPBufferSurfaces)) |
479 { |
437 { |
480 return EFalse; |
438 return EFalse; |
481 } |
439 } |
482 |
440 |
607 #endif |
563 #endif |
608 // KHuiFxDelayRunUntilFirstFrameHasBeenDrawn flag is for giving effect chance to run |
564 // KHuiFxDelayRunUntilFirstFrameHasBeenDrawn flag is for giving effect chance to run |
609 // its whole timeline by starting the time only when first frame has been drawn. |
565 // its whole timeline by starting the time only when first frame has been drawn. |
610 if (iFlags & KHuiFxDelayRunUntilFirstFrameHasBeenDrawn) |
566 if (iFlags & KHuiFxDelayRunUntilFirstFrameHasBeenDrawn) |
611 { |
567 { |
612 // This is a backup timer. If effect won't start before this 10sec wait there must be something wrong |
568 // Sometimes the effect does not get any frames. Force the time to start, because |
613 // Force effect to start after 10seconds |
569 // otherwise will jam itself and possible the group, where the effect is. |
614 if (iElapsedTime > 10.0 && iFramesDrawn == 0) |
570 if (iElapsedTime > 0.2 && iFramesDrawn == 0) |
615 { |
571 { |
616 iFramesDrawn = 1; |
572 iFramesDrawn = 1; |
617 #ifdef HUIFX_TRACE |
573 #ifdef HUIFX_TRACE |
618 RDebug::Printf("CHuiFxEffect::AdvanceTime - Not drawn in 10sec, FORCE start. There was something wrong. release 0x%x in time %f", this, iElapsedTime); |
574 RDebug::Printf("CHuiFxEffect::AdvanceTime - Not drawn, but cannot wait. release 0x%x in time %f", this, iElapsedTime); |
619 #endif |
575 #endif |
620 } |
576 } |
621 |
577 |
622 if (iFramesDrawn) |
578 if (iFramesDrawn) |
623 { |
579 { |