Update contrib.
1 // Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
2 // All rights reserved.
3 // This component and the accompanying materials are made available
4 // under the terms of "Eclipse Public License v1.0"
5 // which accompanies this distribution, and is available
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
17 #include "openwfcpanics.h"
18 #include "elementwrapper.h"
20 #include <graphics/surfacetypes.h>
23 CElementWrapper* CElementWrapper::NewL(COpenWfcWrapper& aCOpenWfcWrapper, CElementWrapper*& aCleanupPrevRef)
25 CElementWrapper* wrapper = new (ELeave) CElementWrapper(aCOpenWfcWrapper);
26 CleanupStack::PushL(wrapper);
27 wrapper->ConstructL(aCleanupPrevRef);
28 CleanupStack::Pop(wrapper);
32 CElementWrapper::CElementWrapper(COpenWfcWrapper& aOpenWfcWrapper):
33 iUpdateFlags(EUpdate_ALL_ATTRIBS),iOpenWfcWrapper(aOpenWfcWrapper),iGlobalAlpha(0xff),
34 iFlipped(EFalse),iRotation(MWsElement::EElementAntiClockwise0)
37 CElementWrapper::~CElementWrapper()
39 wfcDestroyElement(iOpenWfcWrapper.Device(),iElement);
41 UnsetSurface(iSurfaceId);
42 iUpdateFlags = EUpdate_None;
46 iCleanupNext->iCleanupPrevRef=iCleanupPrevRef;
48 *iCleanupPrevRef=iCleanupNext;
51 void CElementWrapper::ConstructL(CElementWrapper*& aCleanupPrevRef)
55 iCleanupNext=aCleanupPrevRef;
56 iCleanupNext->iCleanupPrevRef=&iCleanupNext;
59 iCleanupPrevRef=&aCleanupPrevRef;
61 iElement=wfcCreateElement(iOpenWfcWrapper.Device(),iOpenWfcWrapper.OnScreenContext(),NULL);
62 if (iElement==WFC_INVALID_HANDLE)
63 { //if context and device are good then only explanation is memory
67 wfcGetError(iOpenWfcWrapper.Device());
68 OPENWFC_ASSERT_DEBUG(wfcErr==WFC_ERROR_OUT_OF_MEMORY,EPanicUnexpectedErrorElementConstruct);
69 User::Leave(KErrNoMemory);
73 TInt CElementWrapper::SetSourceRectangle(const TRect& aSrc)
75 if(iSurfaceId.IsNull())
78 //Check aSrc rect is within the bounds of the source image
80 HelpStreamGetHeader(&width,&height);
81 if(aSrc.iTl.iX < 0 || aSrc.iTl.iY < 0 || aSrc.iBr.iX > width || aSrc.iBr.iY > height)
87 iUpdateFlags |= EUpdate_SettingValid|EUpdate_SOURCE_RECTANGLE;
88 iOpenWfcWrapper.SetCompositionModified();
93 TInt CElementWrapper::GetSourceRectangle(TRect& aSrc)
95 if(iSurfaceId.IsNull())
98 if (iSourcRect.IsEmpty())
100 //get true source rectangle from surface
102 HelpStreamGetHeader(&width,&height);
106 aSrc.iBr.iY = height;
116 TInt CElementWrapper::SetSourceFlipping(const TBool aFlip)
118 if(iSurfaceId.IsNull())
122 iUpdateFlags |= EUpdate_SettingValid|EUpdate_SOURCE_FLIP;
127 TBool CElementWrapper::SourceFlipping() const
129 if(iSurfaceId.IsNull())
130 return EFalse; //default is not flipped
135 TInt CElementWrapper::SetGlobalAlpha(const TInt aAlpha)
137 if (aAlpha!=iGlobalAlpha)
139 if ((aAlpha>=0xff)!=(iGlobalAlpha==0xff))
141 iUpdateFlags |= EUpdate_SettingValid|EUpdate_TRANSPARENCY_TYPES;
149 iGlobalAlpha = aAlpha > 0xff ? 0xff : aAlpha;
151 iUpdateFlags |= EUpdate_SettingValid|EUpdate_GLOBAL_ALPHA;
153 iOpenWfcWrapper.SetCompositionModified();
158 void CElementWrapper::GlobalAlpha(TInt& aAlpha) const
160 aAlpha = iGlobalAlpha;
163 TInt CElementWrapper::SetDestinationRectangle(const TRect& aDest)
165 if(iSurfaceId.IsNull())
168 //Check aDest is not out of bounds
169 if(aDest.iBr.iX < aDest.iTl.iX || aDest.iBr.iY < aDest.iTl.iY)
174 TRect compositionDestRect;
175 TRect lastCompositionDestRect;
176 GetDestinationRectangle(lastCompositionDestRect);
178 //always do the translate
179 err = iOpenWfcWrapper.DisplayPolicy()->MapCoordinates(EApplicationSpace, aDest, ECompositionSpace, compositionDestRect);
181 if(compositionDestRect != lastCompositionDestRect)
183 iDestinationRect=aDest;
184 iUpdateFlags |= EUpdate_SettingValid|EUpdate_DESTINATION_RECTANGLE;
186 iOpenWfcWrapper.SetCompositionModified();
192 TInt CElementWrapper::GetDestinationRectangle(TRect& aDest) const
194 if(iSurfaceId.IsNull())
197 aDest=iDestinationRect;
202 TInt CElementWrapper::SetDestinationClippingRect(const TRect& aDestClipRect)
204 if(iSurfaceId.IsNull())
207 TRect compositionDestClipRect;
208 TRect lastCompositionDestClipRect;
209 GetDestinationClippingRect(lastCompositionDestClipRect);
211 //always do the translate
212 err = iOpenWfcWrapper.DisplayPolicy()->MapCoordinates(EApplicationSpace, aDestClipRect, ECompositionSpace, compositionDestClipRect);
214 if(compositionDestClipRect != lastCompositionDestClipRect)
216 TRect destClipRect(aDestClipRect);
217 //Check if the destination clip rectangle is not empty
218 if (!destClipRect.IsEmpty())
220 //Calculate the intersection of the destination clipped rectangle
221 destClipRect.Intersection(iDestinationRect);
222 if (!destClipRect.IsEmpty())
224 // Check if the clipped rectangle is valid,it doesn't have coordinates
225 if (destClipRect.iTl.iX < 0 || destClipRect.iTl.iY < 0)
231 if (iDestinationClippingRect != aDestClipRect)
233 iDestinationClippingRect = aDestClipRect;
234 iUpdateFlags |= EUpdate_SettingValid | EUpdate_DESTINATION_CLIP_RECTANGLE;
236 iOpenWfcWrapper.SetCompositionModified();
243 TInt CElementWrapper::GetDestinationClippingRect(TRect& aDestClipRect) const
245 if(iSurfaceId.IsNull())
248 aDestClipRect = iDestinationClippingRect;
255 Fast swap of two 32-bit TInt type integers.
256 @param aA Argument one.
257 @param aB Argument two.
259 inline void SwapInt(TInt& aA, TInt& aB)
267 Rectangle corner point enumeration.
268 Consider TopLeft point as 0
269 Consider TopRight point as 1
270 Consider BottomRight point as 2
271 Consider BottomLeft point as 3
273 enum TRectangleCornerPoint
282 Get Bottom right corner of the rectangle.
283 @param aRect input rectangle.
284 @return Bottom right corner point coordinates of rectangle.
286 inline TPoint BottomRight(const TRect& aRect)
292 Get Top left corner of the rectangle.
293 @param aRect input rectangle.
294 @return Top left corner point coordinates of rectangle.
296 inline TPoint TopLeft(const TRect& aRect)
302 Get Top right corner of the rectangle.
303 @param aRect input rectangle.
304 @return Top right corner point coordinates of rectangle.
306 inline TPoint TopRight(const TRect& aRect)
308 return TPoint(aRect.iBr.iX, aRect.iTl.iY);
312 Get Bottom left corner of the rectangle.
313 @param aRect input rectangle.
314 @return Bottom left corner point coordinates of rectangle.
316 inline TPoint BottomLeft(const TRect& aRect)
318 return TPoint(aRect.iTl.iX, aRect.iBr.iY);
322 Make horizontal flip of the corner point.
324 inline TRectangleCornerPoint FlipRectangleCorner(TRectangleCornerPoint aSourceRectCorner)
326 return static_cast<TRectangleCornerPoint> (static_cast<TInt> (aSourceRectCorner ^ 0x00000003));
330 Make clockwise rotation of corner point.
332 inline TRectangleCornerPoint RotateRectangleCorner(TRectangleCornerPoint aSourceRectCorner,const MWsElement::TElementRotation& aElementRotation)
334 return static_cast<TRectangleCornerPoint> ((static_cast<TInt> (aSourceRectCorner) + static_cast<TInt> (aElementRotation)) & 0x00000003);
338 Check if there is an inverted aspect ratio.
340 inline TBool CheckInvertedAspectRatio(const MWsElement::TElementRotation& aElementRotation)
342 return (aElementRotation & 0x00000001);
345 Compare the dedicated rectangle corner coordinates of two rectangles.
346 @param aCorner rectangle corner point.
347 @param aRect1 the first rectangle to compare.
348 @param aRect2 the second rectangle to compare.
349 @return ETrue if the checked corner coordinates are the same.
351 TBool CheckTwoRectangleCorners(TRectangleCornerPoint aCorner,const TRect& aRect1,const TRect& aRect2)
353 aCorner = static_cast<TRectangleCornerPoint> (static_cast<TInt> (aCorner) & 0x00000003); // Normalize rectangle corner value
357 return (TopLeft(aRect1) == TopLeft(aRect2));
359 return (TopRight(aRect1) == TopRight(aRect2));
361 return (BottomRight(aRect1) == BottomRight(aRect2));
363 return (BottomLeft(aRect1) == BottomLeft(aRect2));
370 Calculate the new source rectangle extent when a window is clipped by it parent window.
371 Destination clipped rectangle should match to the source rectangle with taking into account
372 flip, scaling and rotation.
373 @param aDestElementRect destination element rectangle without parent window clipping
374 @param aDestElementClippedRect destination element rectangle clipped by the parent window.
375 @param aSrcOriginalElementRect source element rectangle without any clipping changes.
376 @param aElementFlip horizontal flip flag.
377 @param aElementRotation target anti clockwise rotation factor.
378 @return clipped source rectangle.
380 TRect CElementWrapper::SetSourceDestRect(const TRect& aDestElementRect,const TRect& aDestElementClippedRect,const TRect& aSrcOriginalElementRect,const TBool& aElementFlip,const MWsElement::TElementRotation& aElementRotation) const
382 if ((aSrcOriginalElementRect.Width() == 0) || (aSrcOriginalElementRect.Height() == 0))
384 // There are either width or height equal zero.
388 TRectangleCornerPoint sourceRectangleCorner = ETopLeft;
389 TRect destElementMovedClippedRect(aDestElementClippedRect);
390 destElementMovedClippedRect.Intersection(aDestElementRect);
391 TBool fullFlipRotationScale = EFalse;
392 // Compare four corner points of Destination moved and Destination moved clipped rectangles.
393 // Find the first equal corner coordinates for Destination moved and Destination moved clipped rectangles.
394 // It is the Fixed or non changeable point/corner of the source rectangle.
395 if (destElementMovedClippedRect.IsEmpty())
399 for (sourceRectangleCorner = ETopLeft; ((TInt) sourceRectangleCorner) <= ((TInt) EBottomLeft);)
401 if (CheckTwoRectangleCorners(sourceRectangleCorner, aDestElementRect, destElementMovedClippedRect))
405 sourceRectangleCorner = static_cast<TRectangleCornerPoint> ((TInt) sourceRectangleCorner + 1);
407 // There are no equals coordinates, hence, it must be calculated with different by different way
408 if ((TInt) sourceRectangleCorner > (TInt) EBottomLeft)
410 sourceRectangleCorner = ETopLeft;
411 fullFlipRotationScale = ETrue;
414 // Clockwise rotate of the detected Fixed point/corner.
415 sourceRectangleCorner = RotateRectangleCorner(sourceRectangleCorner, aElementRotation);
417 // If flip flag set, then make horizontal flip of the Fixed point.
420 sourceRectangleCorner = FlipRectangleCorner(sourceRectangleCorner);
423 // Make scale calculation for the source clipping
426 if (fullFlipRotationScale)
428 dX = ((aDestElementRect.iTl.iX - aDestElementClippedRect.iTl.iX) * aSrcOriginalElementRect.Width()) / aDestElementRect.Width();
429 dY = ((aDestElementRect.iTl.iY - aDestElementClippedRect.iTl.iY) * aSrcOriginalElementRect.Height()) / aDestElementRect.Height();
431 TInt clipSrcWidth = (destElementMovedClippedRect.Width() * aSrcOriginalElementRect.Width()) / aDestElementRect.Width();
432 TInt clipSrcHeight = (destElementMovedClippedRect.Height() * aSrcOriginalElementRect.Height()) / aDestElementRect.Height();
433 TRect resultSourceRect = aSrcOriginalElementRect;
435 // Swap the clipping width and height if the target was rotated on 90 or 270 degrees.
436 if (CheckInvertedAspectRatio(aElementRotation))
438 SwapInt(clipSrcWidth, clipSrcHeight);
442 // Assuming that coordinates of the source Fixed corner/point was not changed due to clipping,
443 // calculate coordinates of an opposite point to the Fixed corner/point.
444 // This point must be differ from original source for providing proper clipping visual result.
445 switch (sourceRectangleCorner)
449 // If TopRight of aDestElementRect is not the same as TopRight of aDestElementClippedRect
450 if (!CheckTwoRectangleCorners(ETopRight, aDestElementRect, destElementMovedClippedRect))
451 {// calculate point ETopRight
452 resultSourceRect.iBr.iX = resultSourceRect.iTl.iX + clipSrcWidth;
454 // If BottomLeft of aDestElementRect is not the same as BottomLeft of aDestElementClippedRect
455 if (!CheckTwoRectangleCorners(EBottomLeft, aDestElementRect, destElementMovedClippedRect))
456 {// calculate point EBottomLeft
457 resultSourceRect.iBr.iY = resultSourceRect.iTl.iY + clipSrcHeight;
459 if (fullFlipRotationScale)
461 resultSourceRect.iTl.iX += dX;
462 resultSourceRect.iTl.iY += dY;
468 // if TopLeft of aDestElementRect is not the same as TopLeft of aDestElementClippedRect
469 if (!CheckTwoRectangleCorners(ETopLeft, aDestElementRect, destElementMovedClippedRect))
470 {// calculate point ETopLeft
471 resultSourceRect.iTl.iX = resultSourceRect.iBr.iX - clipSrcWidth;
473 // if BottomRight of aDestElementRect is not the same as BottomRight of aDestElementClippedRect
474 if (!CheckTwoRectangleCorners(EBottomRight, aDestElementRect, destElementMovedClippedRect))
475 {// calculate point EBottomRight
476 resultSourceRect.iBr.iY = resultSourceRect.iTl.iY + clipSrcHeight;
478 if (fullFlipRotationScale)
480 resultSourceRect.iBr.iX -= dX;
481 resultSourceRect.iTl.iY += dY;
487 // if BottomLeft of aDestElementRect is not the same as BottomLeft of aDestElementClippedRect
488 if (!CheckTwoRectangleCorners(EBottomLeft, aDestElementRect, destElementMovedClippedRect))
489 {// calculate point EBottomLeft
490 resultSourceRect.iTl.iX = resultSourceRect.iBr.iX - clipSrcWidth;
492 // if TopRight of aDestElementRect is not the same as TopRight of aDestElementClippedRect
493 if (!CheckTwoRectangleCorners(ETopRight, aDestElementRect, destElementMovedClippedRect))
494 {// calculate point ETopRight
495 resultSourceRect.iTl.iY = resultSourceRect.iBr.iY - clipSrcHeight;
497 if (fullFlipRotationScale)
499 resultSourceRect.iBr.iX -= dX;
500 resultSourceRect.iBr.iY -= dY;
506 // if BottomRight of aDestElementRect is not the same as BottomRight of aDestElementClippedRect don't change width
507 if (CheckTwoRectangleCorners(EBottomRight, aDestElementRect, destElementMovedClippedRect))
508 {// calculate point EBottomRight
509 resultSourceRect.iBr.iX = resultSourceRect.iTl.iX + clipSrcWidth;
511 // if TopLeft of aDestElementRect is not the same as TopLeft of aDestElementClippedRect
512 if (CheckTwoRectangleCorners(ETopLeft, aDestElementRect, destElementMovedClippedRect))
513 {// calculate point ETopLeft
514 resultSourceRect.iTl.iY = resultSourceRect.iBr.iY - clipSrcHeight;
516 if (fullFlipRotationScale)
518 resultSourceRect.iTl.iX += dX;
519 resultSourceRect.iBr.iY -= dY;
524 return resultSourceRect;
529 TInt CElementWrapper::SetSourceRotation(const TElementRotation aElementRotation)
531 if(iSurfaceId.IsNull())
534 if(aElementRotation < 0 || aElementRotation > 3)
537 iRotation = aElementRotation;
538 iUpdateFlags |= EUpdate_SettingValid|EUpdate_SOURCE_ROTATION;
540 iOpenWfcWrapper.SetCompositionModified();
545 MWsElement::TElementRotation CElementWrapper::SourceRotation() const
547 if(iSurfaceId.IsNull())
548 return EElementAntiClockwise0; //default rotation
553 TInt CElementWrapper::SetTargetRendererFlags(const TUint32& aTargetRendererFlags)
555 iTargetRendererFlags = aTargetRendererFlags;
556 if (iTargetRendererFlags & EElementTransparencyGlobalAlpha)
558 iUpdateFlags |= EUpdate_SettingValid|EUpdate_GLOBAL_ALPHA;
561 if (iTargetRendererFlags & EElementTransparencySource)
563 iUpdateFlags |= EUpdate_SettingValid|EUpdate_TRANSPARENCY_TYPES;
569 TInt CElementWrapper::SetRenderStageFlags(const TUint32& aRenderStageFlags)
571 iRenderStageFlags = aRenderStageFlags;
576 void CElementWrapper::GetTargetRendererFlags(TUint32& aTargetRendererFlags) const
578 aTargetRendererFlags = iTargetRendererFlags;
581 void CElementWrapper::GetRenderStageFlags(TUint32& aRenderStageFlags) const
583 aRenderStageFlags = iRenderStageFlags;
586 MWsElement* CElementWrapper::ElementAbove()
588 //Check this element has not already been reequsted to be removed
589 if (iUpdateFlags&EUpdate_Remove)
595 return iElementAbove;
599 MWsElement* CElementWrapper::ElementBelow()
601 //Check this element has not already been reequsted to be removed
602 if (iUpdateFlags&EUpdate_Remove)
608 return iElementBelow;
612 TInt CElementWrapper::ConnectSurface(const TSurfaceId& aSurface)
615 if (aSurface!=iSurfaceId)
617 if (!aSurface.IsNull())
619 if(!iOpenWfcWrapper.IncEltRefRegSource(aSurface))
625 RSurfaceManager::TInfoBuf buff;
626 err = err = SurfaceInfo(aSurface, buff);
629 return iOpenWfcWrapper.DecEltRefRegSource(aSurface);
633 iSurfaceSize=buff().iSize;
639 iSurfaceSize.SetSize(0,0);
641 UnsetSurface(iSurfaceId);
643 iUpdateFlags |= EUpdate_SettingValid|EUpdate_SOURCE;
644 if (iSourcRect.IsEmpty())
646 iUpdateFlags |= EUpdate_SettingValid|EUpdate_SOURCE_RECTANGLE;
650 { //Note this code is simply here to return the error!
651 if (!iSurfaceId.IsNull())
653 if (iOpenWfcWrapper.IncEltRefRegSource(iSurfaceId))
655 iOpenWfcWrapper.DecEltRefRegSource(iSurfaceId);
664 iOpenWfcWrapper.SetCompositionModified();
669 const TSurfaceId& CElementWrapper::ConnectedSurface() const
675 * Sets the element source to match the surface ID and optionally locks the reference count until next composition.
677 void CElementWrapper::SetEltSourceComposed()
679 iUpdateFlags |= EUpdate_SceneCommited;
683 * Sets the element source to match the surface ID and optionally locks the reference count until next composition.
685 void CElementWrapper::SetEltSource(WFCElement aElement)const
687 WFCSource source = WFC_INVALID_HANDLE;
688 if (!iSurfaceId.IsNull())
690 source=iOpenWfcWrapper.IncEltRefRegSource(iSurfaceId);
693 TInt remains=iOpenWfcWrapper.DecEltRefRegSource(iSurfaceId);
694 OPENWFC_ASSERT_DEBUG(remains>0,EPanicWfcNoStreamSurface);
697 wfcSetElementAttribi(iOpenWfcWrapper.Device(),aElement,WFC_ELEMENT_SOURCE,source);
701 * Internal method releases the previous registered surface, and clears the caller's member var.
702 * @return true if any resources released
704 TBool CElementWrapper::UnsetSurface(TSurfaceId& aSurface)
706 if (!aSurface.IsNull())
708 TInt err = iOpenWfcWrapper.DecEltRefRegSource(aSurface);
709 OPENWFC_ASSERT_DEBUG(err >= 0,EPanicWfcSourceLookupOnElementRemoval);
710 aSurface = aSurface.CreateNullId();
711 return (err == KErrNone); //>0 indicates object count non-zero
716 void CElementWrapper::SetEltTransparencyTypes(WFCElement aElement)const
718 TInt transType = WFC_TRANSPARENCY_NONE;
719 if (iTargetRendererFlags & EElementTransparencySource)
721 transType |= WFC_TRANSPARENCY_SOURCE;
723 if (iTargetRendererFlags & EElementTransparencyGlobalAlpha)
725 transType |= WFC_TRANSPARENCY_ELEMENT_GLOBAL_ALPHA;
727 wfcSetElementAttribi(iOpenWfcWrapper.Device(),aElement,WFC_ELEMENT_TRANSPARENCY_TYPES,transType);
730 void CElementWrapper::HelpStreamGetHeader(khronos_int32_t* aWidth, khronos_int32_t* aHeight)const
734 *aWidth=iSurfaceSize.iWidth;
738 *aHeight=iSurfaceSize.iHeight;
743 * Maps the source rectangle to fp values matching the region and destination rectangle data over a element object.
744 * This is when the source rectangle changes.
745 * Only repositions existing elements
747 void CElementWrapper::SetEltSourceRectangle(WFCElement aElement)
750 GetSourceRectangle(srcRect);
751 if (!iDestinationClippingRect.IsEmpty())
753 TRect destinationRect=iDestinationRect;
754 destinationRect.Intersection(iDestinationClippingRect);
755 if(!destinationRect.IsEmpty())
757 srcRect = SetSourceDestRect(iDestinationRect,destinationRect,srcRect,iFlipped,iRotation);
760 float rect[4]={srcRect.iTl.iX,srcRect.iTl.iY,srcRect.Width(),srcRect.Height()};
761 wfcSetElementAttribfv(iOpenWfcWrapper.Device(),aElement,WFC_ELEMENT_SOURCE_RECTANGLE,4,rect);
764 void CElementWrapper::SetEltSourceFlip(WFCElement aElement)const
766 wfcSetElementAttribi(iOpenWfcWrapper.Device(),aElement,WFC_ELEMENT_SOURCE_FLIP, iFlipped);
770 * Maps the region and destination rectangle data into a element object
771 * taking into account the source rectangle mapping and region data
772 * @return KErrNone or KErrMemory
774 void CElementWrapper::SetEltDestinationRectangle(WFCElement aElement)const
776 TRect destinationRect=iDestinationRect;
777 if (!iDestinationClippingRect.IsEmpty())
779 destinationRect.Intersection(iDestinationClippingRect);
781 float destRect[4]={destinationRect.iTl.iX,destinationRect.iTl.iY,destinationRect.Width()<0?0:destinationRect.Width(),destinationRect.Height()<0?0:destinationRect.Height()};
782 wfcSetElementAttribfv(iOpenWfcWrapper.Device(),aElement,WFC_ELEMENT_DESTINATION_RECTANGLE,4,destRect);
784 LILOG(("### EXIT SetEltDestinationRectangle()"));
788 * Maps the region and destination rectangle data into a element object.
789 * taking in to account the source rectangle mapping and region data
790 * @param aOffset an offset ADDED to every destination rectangle
791 * @return KErrNone or KErrMemory
793 void CElementWrapper::SetEltDestinationRectangle(WFCElement aElement, const TPoint& aOffset)const
795 TRect destinationRect=iDestinationRect;
796 if (!iDestinationClippingRect.IsEmpty())
798 destinationRect.Intersection(iDestinationClippingRect);
800 float rect[4]={destinationRect.iTl.iX+aOffset.iX,destinationRect.iTl.iY+aOffset.iY,destinationRect.Width(),destinationRect.Height()};
801 wfcSetElementAttribfv(iOpenWfcWrapper.Device(),aElement,WFC_ELEMENT_DESTINATION_RECTANGLE,4,rect);
804 void CElementWrapper::RemoveAfter(CElementWrapper** apElementBelow)
806 iUpdateFlags&=~(EUpdate_Insert|EUpdate_Remove);
809 *apElementBelow = iElementAbove;
812 iElementAbove->iElementBelow = iElementBelow;
815 iElementBelow = NULL;
816 iElementAbove = NULL;
819 void CElementWrapper::InsertAfter(CElementWrapper*& aRefElementBelow, CElementWrapper* aElementBelow, TOwfUpdates aUpdateFlag)
821 OPENWFC_ASSERT_DEBUG(aUpdateFlag&(EUpdate_Insert|aUpdateFlag&EUpdate_Remove|aUpdateFlag&EUpdate_Destroy), EPanicUnexpectedErrorElementScene);
822 iUpdateFlags |= EUpdate_SettingValid|aUpdateFlag;
823 iElementAbove = aRefElementBelow;
824 iElementBelow = aElementBelow;
825 aRefElementBelow = this;
828 iElementAbove->iElementBelow = this;
832 /* Returns a pointer referencing this object from below.
833 * @return the pointer or null if there is no "below" object
835 CElementWrapper** CElementWrapper::RefsMyElementBelow()
839 return &iElementBelow->iElementAbove;
845 CElementWrapper*& CElementWrapper::MyElementAbove()
847 return iElementAbove;
850 TInt CElementWrapper::WfcRotation(MWsElement::TElementRotation aRotation)
854 case EElementAntiClockwise0:
855 return WFC_ROTATION_0;
856 case EElementAntiClockwise90:
857 return WFC_ROTATION_270;
858 case EElementAntiClockwise180:
859 return WFC_ROTATION_180;
860 default: // EElementAntiClockwise270
861 return WFC_ROTATION_90;
865 TBool CElementWrapper::IsNewElementLegal()const
867 //OWF SI will fail if certain illegal element attributes are passed to it.
868 //Various members must be non-zero:
869 //destination rectangle
872 if (iDestinationRect.IsEmpty() || iSurfaceId.IsNull()||iGlobalAlpha==0)
876 //If the source rectangle is set it must be inside the surface size
877 if (!iSourcRect.IsEmpty())
879 if (iSourcRect.iTl.iX<0 || iSourcRect.iTl.iY<0)
885 HelpStreamGetHeader(&width,&height);
886 if (iSourcRect.iBr.iX>width || iSourcRect.iBr.iY>height)
891 //If mask is defined and enabled, Mask size must match destination rectangle size
892 //masks are currently not implemented
893 //If mask is enabled then source alpha must not be enabled
894 //masks are currently not implemented
898 * Flushes any flagged scene or attribute changes into the element objects
899 * @return EFalse if no flushing occurred - for any reason
901 TBool CElementWrapper::FlushSceneChanges()
903 TInt updateFlags=iUpdateFlags;
904 if ((updateFlags&EUpdate_AttributesIllegal) && !(updateFlags&EUpdate_SettingValid))
909 if (updateFlags==EUpdate_None)
914 if (updateFlags&(EUpdate_Remove|EUpdate_Destroy) && (updateFlags&EUpdate_SceneCommited))
916 wfcRemoveElement(iOpenWfcWrapper.Device(),iElement);
919 if (updateFlags&EUpdate_Destroy)
924 if (updateFlags&(EUpdate_Remove|EUpdate_Destroy))
926 iUpdateFlags&=~(EUpdate_Insert|EUpdate_Remove|EUpdate_SceneCommited);
930 TBool isElementLegal=IsNewElementLegal();
932 { //If the element would not be legal then it must not be inserted
933 //It may even need to be removed.
934 if (updateFlags&EUpdate_SceneCommited)
935 { //it is in the scene, remove it
936 wfcRemoveElement(iOpenWfcWrapper.Device(),iElement);
937 updateFlags &= ~EUpdate_SceneCommited;
940 //Re-flag the update but also set a flag
941 //so that we don't bother to check legality again until another attribute change.
942 updateFlags&=~EUpdate_SettingValid;
943 updateFlags|=EUpdate_AttributesIllegal;
944 iUpdateFlags=updateFlags;
946 LILOG(("### EXIT CElementWrapper::FlushSceneChanges() FALSE"));
950 WFCElement elementBelow=WFC_INVALID_HANDLE;
951 if ((updateFlags&(EUpdate_Insert|EUpdate_AttributesIllegal)))
953 if (CElementWrapper* elementWrapperBelow=iElementBelow)
955 while (elementWrapperBelow && elementWrapperBelow->iUpdateFlags&EUpdate_AttributesIllegal)
957 elementWrapperBelow=elementWrapperBelow->iElementBelow;
959 if (elementWrapperBelow)
961 elementBelow=elementWrapperBelow->iElement;
966 iUpdateFlags = EUpdate_SceneCommited;
968 if ((updateFlags&~EUpdate_Remove))
970 FlushAttributeChanges(iElement, updateFlags);
971 if (updateFlags&(EUpdate_Insert|EUpdate_AttributesIllegal))
973 wfcInsertElement(iOpenWfcWrapper.Device(),iElement,elementBelow);
977 LILOG(("### EXIT CElementWrapper::FlushSceneChanges() FALSE"));
981 void CElementWrapper::FlushAttributeChanges(WFCElement aElement, TInt aUpdateFlags)
983 LILOG(("### ENTER FlushAttributeChanges() aStart(%d), aPastMax(%d), uFl(0x%x)", aStart, aPastMax, aUpdateFlags));
985 //At present all attribute changes are flushed immediately... assert that behaviour.
986 if (aUpdateFlags&EUpdate_SOURCE_GEOMETRY_SET)
988 SetEltSourceRectangle(aElement);
990 if (aUpdateFlags&(EUpdate_SOURCE|EUpdate_SettingValid))
992 SetEltSource(aElement);
994 if (aUpdateFlags&EUpdate_SOURCE_FLIP)
996 SetEltSourceFlip(aElement);
998 if (aUpdateFlags&EUpdate_SOURCE_ROTATION)
1000 TInt wfcRot=WfcRotation(iRotation);
1001 wfcSetElementAttribi(iOpenWfcWrapper.Device(),iElement,WFC_ELEMENT_SOURCE_ROTATION,wfcRot);
1003 if (aUpdateFlags&EUpdate_TRANSPARENCY_TYPES)
1005 SetEltTransparencyTypes(aElement);
1007 if (aUpdateFlags&EUpdate_GLOBAL_ALPHA)
1009 wfcSetElementAttribi(iOpenWfcWrapper.Device(),aElement,WFC_ELEMENT_GLOBAL_ALPHA,iGlobalAlpha);
1011 if (aUpdateFlags&EUpdate_DESTINATION_RECTANGLE)
1013 SetEltDestinationRectangle(aElement);
1015 LILOG(("### EXIT FlushAttributeChanges()"));
1018 TInt CElementWrapper::ReplicateElements(WFCContext aContext, WFCElement& aPreviousTargetElement,const TPoint& aOffset)
1020 if (aContext == WFC_INVALID_HANDLE)
1022 return KErrArgument;
1025 if (!IsNewElementLegal())
1030 WFCDevice device = iOpenWfcWrapper.Device();
1031 WFCContext onScreenContext = iOpenWfcWrapper.OnScreenContext();
1032 // clean the existing system errors and look for new ones
1033 wfcGetError(device);
1034 WFCSource targetImageSource = wfcCreateSourceFromStream(device, aContext, reinterpret_cast<WFCNativeStreamType>(&iSurfaceId), NULL);
1035 if (targetImageSource == WFC_INVALID_HANDLE)
1037 return COpenWfcWrapper::TranslateOpenWfcError(wfcGetError(device));
1040 WFCElement targetElement = WFC_INVALID_HANDLE;
1042 // the elements are created but we don't get hold of them for longer than we need
1043 // all elements created now are to be destroyed when composition is completed
1044 targetElement = wfcCreateElement(device, aContext, NULL);
1045 if (targetElement == WFC_INVALID_HANDLE)
1047 return COpenWfcWrapper::TranslateOpenWfcError(wfcGetError(device));
1050 // we can just flush the attributes to the new elements because the off-screen context attributes
1051 // share the same device with the on-screen context. If this changes make device a parameter!
1052 wfcSetElementAttribi(device,targetElement,WFC_ELEMENT_SOURCE,targetImageSource);
1053 FlushAttributeChanges(targetElement, (EUpdate_ALL_ATTRIBS&~(EUpdate_SOURCE|EUpdate_DESTINATION_RECTANGLE)));
1054 SetEltDestinationRectangle(targetElement, aOffset);
1055 wfcInsertElement(iOpenWfcWrapper.Device(),targetElement,aPreviousTargetElement);
1056 aPreviousTargetElement = targetElement;
1058 return COpenWfcWrapper::TranslateOpenWfcError(wfcGetError(device));
1061 TInt CElementWrapper::SurfaceInfo(const TSurfaceId& aSurface, RSurfaceManager::TInfoBuf& aInfo)
1063 TInt err = KErrNone;
1064 switch(aSurface.Type())
1066 case TSurfaceTypes::ESurfaceManagerSurface:
1068 err = Owner().SurfaceManager().SurfaceInfo(aSurface, aInfo);
1071 case TSurfaceId::EScreenSurface:
1073 TInt screenId = aSurface.iInternal[TSurfaceId::TScreenSurfaceUsage::EScreenField];
1075 err = HAL::Get(screenId, HALData::EDisplayXPixels, width);
1076 if (err != KErrNone)
1078 iOpenWfcWrapper.DecEltRefRegSource(aSurface);
1083 err = HAL::Get(screenId, HALData::EDisplayYPixels, height);
1084 if (err != KErrNone)
1086 iOpenWfcWrapper.DecEltRefRegSource(aSurface);
1090 aInfo().iSize = TSize(width, height);
1092 #ifdef SYMBIAN_ROTATION_MODE_CHANGES
1093 TInt displayMode = aSurface.iInternal[TSurfaceId::TScreenSurfaceUsage::EHalField];
1095 TInt displayMode = 0;
1096 err = HAL::Get(screenId, HALData::EDisplayMode, displayMode);
1097 if (err != KErrNone)
1099 iOpenWfcWrapper.DecEltRefRegSource(aSurface);
1104 #if defined(SYMBIAN_ROTATION_MODE_CHANGES)
1105 if (displayMode & TSurfaceId::TScreenSurfaceUsage::EHalFlippedFlag) // 90 | 270 degree rotation
1107 // Swap dimensions and recalculate stride. Assume no padding for now.
1108 aInfo().iSize.iWidth = height;
1109 aInfo().iSize.iHeight = width;
1110 //"vertical" stride has already been fetched
1112 #elif defined(SYMBIAN_ROTATION_CHANGES)
1113 if (aSurface.iInternal[1] & (2 | 8)) // 90 | 270 degree rotation
1115 // Swap dimensions and recalculate stride. Assume no padding for now.
1116 aInfo().iSize.iWidth = height;
1117 aInfo().iSize.iHeight = width;
1124 err = KErrNotSupported;