CHuiCanvasGc::TClipRectVisibility CHuiCanvasGc::IsClipped(const TRect& aRect, const TRegion& aClippingRegion) const { TClipRectVisibility isClipped = EFullyOutside; if (!aClippingRegion.Count()) { return EFullyInside; } if (!aRect.IsEmpty() && aClippingRegion.Count()) { #if 0 TBool test = EFalse; if (test) { for (TInt i=0; i<aClippingRegion.Count(); i++) { #ifdef _DEBUG RDebug::Print(_L("aClippingRegion Rect: %d %d %d %d"), aClippingRegion[i].iTl.iX, aClippingRegion[i].iTl.iY, aClippingRegion[i].iBr.iX, aClippingRegion[i].iBr.iY); #endif } } #endif if (aClippingRegion.Intersects(aRect)) { iTempRegion.Clear(); iTempRegion2.Clear(); iTempRegion.AddRect(aRect); iTempRegion2.Intersection(aClippingRegion, iTempRegion); iTempRegion2.Tidy(); // Assume it is only partially inside region -> Clipped isClipped = EPartialOverlap; if (iTempRegion2.Count() == 1) { if (iTempRegion2[0] == aRect) { // Fully inside region -> Not clipped isClipped = EFullyInside; } } } else { // No overlap -> aRect is completely outside region -> Clipped isClipped = EFullyOutside; } } return isClipped; }
void TestRRegion::CheckRectRegion(const TRegion& region,const TRect& rect) // Check the region matches the rectangle { const TRect* rlist; if (rect.IsEmpty()) test(region.Count()==0); else { test(region.Count()==1); rlist=region.RectangleList(); test(rlist[0]==rect); test(region[0]==rect); } }
void RWindows::Update(const TRegion& aRgn,const TSize& aSize) { if(aRgn.CheckError()) UpdateRect(TRect(aSize),aSize); else for(TInt count=0;count<aRgn.Count();count++) UpdateRect(aRgn[count],aSize); }
void CDataWrapperBase::LogRegion(const TDesC& aMessage, const TRegion& aRegion) { INFO_PRINTF2(KLogRegion, &aMessage); TInt indCount = aRegion.Count(); if ( indCount==0 ) { INFO_PRINTF1(KLogEmpty); } else { const TRect* rect=aRegion.RectangleList(); for ( TInt index=0; index<indCount; ++index ) { INFO_PRINTF6(KLogRegionsRect, index, rect[index].iTl.iX, rect[index].iTl.iY, rect[index].iBr.iX, rect[index].iBr.iY); } } }
TBool CDataWrapperBase::GetRegionFromConfig(const TDesC& aSectName, const TDesC& aKeyName, TRegion& aResult) { TBuf<KMaxTestExecuteCommandLength> tempStore; TRect rect; aResult.Clear(); TBool moreData=ETrue; for ( TInt index=0; moreData; ) { tempStore.Format(KFormatFieldNumber, &aKeyName, ++index); moreData=GetRectFromConfig(aSectName, tempStore, rect); if ( moreData ) { aResult.AddRect(rect); } } return aResult.Count()>0; }
CHuiCanvasGc::TClipRectVisibility CHuiCanvasGc::IsClipped(const TRegion& aTestedRegion, const TRegion& aClippingRegion) const { TClipRectVisibility isWholeRegionClipped = EUnknown; TInt count = aTestedRegion.Count(); if (count == 0) { isWholeRegionClipped = EFullyOutside; } for (TInt i=0; i<count; i++) { TClipRectVisibility isRectClipped = IsClipped(aTestedRegion[i], aClippingRegion); if (isWholeRegionClipped == EFullyInside) { if (isRectClipped == EFullyOutside || isRectClipped == EPartialOverlap ) { isWholeRegionClipped = EPartialOverlap; } } else if (isWholeRegionClipped == EFullyOutside) { if (isRectClipped == EFullyInside || isRectClipped == EPartialOverlap ) { isWholeRegionClipped = EPartialOverlap; } } else if (isWholeRegionClipped == EPartialOverlap) { // No changes to isWholeRegionClipped in this case and no need to look further break; } else { isWholeRegionClipped = isRectClipped; } } return isWholeRegionClipped; }
EXPORT_C void CHuiCanvasGc::ClipRegion(const TRegion& aClipRegion) { if (!iGc) { return; } switch (iClipMode) { case EHuiCanvasClipModeNormal: { // If previous clipping region set, cancel it first. if (iClippingRegion.Count()) { CancelClipping(); } // Set new region, ignore empty rects if any for (TInt i=0; i < aClipRegion.Count(); i++) { if (!aClipRegion[i].IsEmpty()) { iClippingRegion.AddRect(aClipRegion[i]); } } iClippingRegion.Tidy(); if (iClippingRegion.Count() == 1) { // If only one rect, then do simple clipping... iGc->Enable(CHuiGc::EFeatureClipping); iGc->PushClip(); iGc->Clip(iClippingRegion[0]); } else if (iClippingRegion.Count() > 1) { // ...otherewise must do region clipping. iGc->Enable(CHuiGc::EFeatureClipping); iGc->PushClip(); if (MaxNumberOfClipRects() > 1) { iGc->Clip(iClippingRegion); } else { // region clipping is not available, try boundingrect iGc->Clip(iClippingRegion.BoundingRect()); } } else { // No clip rects set, do nothing here. } break; } case EHuiCanvasClipModeDelayed: { // If previous clipping region set, cancel it first. if (iClippingRegion.Count()) { CancelClipping(); } // Set new region, ignore empty rects if any for (TInt i=0; i < aClipRegion.Count(); i++) { if (!aClipRegion[i].IsEmpty()) { iClippingRegion.AddRect(aClipRegion[i]); } } iClippingRegion.Tidy(); break; } case EHuiCanvasClipModeNone: default: { // Do nothing break; } } }
// TODO: effect area should be reduced if aClipRegion is smaller than aDisplayRect. TBool CHuiFxEffect::CachedDraw(CHuiGc& aGc, const TRect& aDisplayRect, TBool aRefreshCachedRenderTarget, TBool aOpaque, const TRegion& aClipRegion, TBool aHasSurface, TInt aAlpha) { #ifdef HUIFX_TRACE RDebug::Print(_L("CHuiFxEffect::CachedDraw - 0x%x"), this); #endif iFramesDrawn++; if (!CHuiStatic::Renderer().Allows(EHuiRenderPluginAllowVisualPBufferSurfaces)) { return EFalse; } CHuiFxRenderbuffer* target = NULL; // Prepare all layers TRect displayArea = aGc.DisplayArea(); TRect targetArea = aDisplayRect; targetArea.Intersection(displayArea); if (targetArea.Width() <= 0 || targetArea.Height() <= 0) { // Not visible return ETrue; } if (!iEngine || !iRoot) { return EFalse; } if (iEngine->LowMemoryState()) { // No memory, no effects. return EFalse; } // Check if margins are allowed to be used for this effect if (EffectFlags() & KHuiFxEffectDisableMarginsFlag) { iRoot->EnableMargin(EFalse); } // Check if surface pixels are to be used for this effect in all layers. if (EffectFlags() & KHuiFxEnableBackgroundInAllLayers) { iRoot->SetAlwaysReadSurfacePixels(ETrue); } iRoot->SetTargetRect(targetArea); iRoot->SetSourceRect(targetArea); iRoot->SetDisplayArea(displayArea); TRAPD(err, iRoot->PrepareDrawL(*iEngine)); if (err != KErrNone) { return EFalse; } if (IsCachedRenderTargetSupported() && IsCachedRenderTargetPreferred()) { // Background needs to be captured from surface if effect uses background AND // Visual is transparent or margin is enabled AND // Background has not been disabled with a effect specific flag TBool enableBackground = IsAppliedToBackground() && (!aOpaque || iRoot->IsMarginEnabled()) && !(EffectFlags() & KHuiFxDisableBackground); if (EffectFlags() & KHuiFxEnableBackgroundInAllLayers) { enableBackground = ETrue; } TBool useFrozenBackground = (EffectFlags() & KHuiFxFrozenBackground); // Check if cache is up-to date or does it need to be refreshed TBool cachedRenderTargetNeedsRefresh = (iRoot->Changed() || aRefreshCachedRenderTarget || (enableBackground && !useFrozenBackground)); if (!iCachedRenderTarget || (iCachedRenderTarget && iCachedRenderTarget->Size() != iRoot->VisualRect().Size())) { cachedRenderTargetNeedsRefresh = ETrue; } // Try to apply also margins, we cannot just use aDisplayRect directly TRect targetRect = iRoot->VisualRect(); // Size is always same as target rect. It contains margins if those are enabled. TSize cachedRenderTargetSize = targetRect.Size(); // Prepare cached offscreen render target PrepareCachedRenderTarget(targetRect.iTl, cachedRenderTargetSize, cachedRenderTargetNeedsRefresh, enableBackground); // If it is available, then lets do it if (iCachedRenderTarget) { // Disable clipping, otherwise strange things happen. aGc.Disable(CHuiGc::EFeatureClipping); if (cachedRenderTargetNeedsRefresh) { // Render to cached render target iRoot->Draw(*iEngine, aGc, *iCachedRenderTarget, *iCachedRenderTarget, aHasSurface); #ifdef HUIFX_TRACE RDebug::Print(_L("CHuiFxEffect::CachedDraw - refreshed cached render buffer 0x%x"), this); #endif } if (aClipRegion.Count()) { aGc.Enable(CHuiGc::EFeatureClipping); aGc.PushClip(); aGc.Clip(aClipRegion); } // Write cached buffer to the display iEngine->Composite(aGc, *iCachedRenderTarget, targetRect.iTl, aOpaque && !(EffectFlags() & KHuiFxAlwaysBlend), aAlpha); if (aClipRegion.Count()) { aGc.PopClip(); } aGc.Enable(CHuiGc::EFeatureClipping); #ifdef HUIFX_TRACE RDebug::Print(_L("CHuiFxEffect::CachedDraw - Cached render buffer drawn 0x%x"), this); RDebug::Print(_L("CHuiFxEffect::CachedDraw - displayrect: %i,%i, %i,%i "), aDisplayRect.iTl.iX, aDisplayRect.iTl.iY, aDisplayRect.iBr.iX, aDisplayRect.iBr.iY); #endif } else { // It might not be available e.g. in low memory situations, just indiacte that we could not draw. return EFalse; } } else { // Release cached render target just in case it is reserved for some reason ReleaseCachedRenderTarget(); // Use default onscreen render target if (!target) { target = iEngine->DefaultRenderbuffer(); } if (!target) { return EFalse; } // Normal drawing iRoot->Draw(*iEngine, aGc, *target, *target, aHasSurface); } return ETrue; }