Update contrib.
1 // Copyright (c) 1995-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.
16 #include "stdgraphicdrawer.h"
17 #include "wsgraphicdrawercontext.h"
18 #include "graphics/WSGRAPHICMSGBUF.H"
19 #include "graphics/W32STDGRAPHICTEST.H"
22 #include "W32STDGRAPHIC.H"
24 // CWsGraphicDrawerBitmapAnimation::CFrame \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
26 NONSHARABLE_STRUCT(CWsGraphicDrawerBitmapAnimation::CFrame): public CBase
29 TFrameInfo iFrameInfo;
32 mutable RRegionBuf<12> iVisibleRegion;
35 CWsGraphicDrawerBitmapAnimation::CFrame::~CFrame()
39 iVisibleRegion.Close();
42 // CWsGraphicDrawerBitmapAnimation \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
44 CWsGraphicDrawerBitmapAnimation* CWsGraphicDrawerBitmapAnimation::CreateL()
46 return new(ELeave) CWsGraphicDrawerBitmapAnimation;
49 CWsGraphicDrawerBitmapAnimation::CWsGraphicDrawerBitmapAnimation()
53 CWsGraphicDrawerBitmapAnimation::~CWsGraphicDrawerBitmapAnimation()
60 iFrames.ResetAndDestroy();
63 void CWsGraphicDrawerBitmapAnimation::ConstructL(MWsGraphicDrawerEnvironment& aEnv,const TGraphicDrawerId& aId,MWsClient& aOwner,const TDesC8& aData)
65 __ASSERT_COMPILE(sizeof(TInt) == sizeof(TInt32));
66 RDesReadStream in(aData);
68 const TInt count = in.ReadInt32L();
69 for(TInt i=0; i<count; i++)
71 CFrame* frame = new(ELeave) CFrame;
72 CleanupStack::PushL(frame);
73 in.ReadL(reinterpret_cast<TUint8*>(&(frame->iFrameInfo)),sizeof(TFrameInfo));
74 const TInt bitmapHandle = in.ReadInt32L();
77 frame->iBitmap = new(ELeave) CFbsBitmap;
78 User::LeaveIfError(frame->iBitmap->Duplicate(bitmapHandle));
80 const TInt maskHandle = in.ReadInt32L();
83 frame->iMask = new(ELeave) CFbsBitmap;
84 User::LeaveIfError(frame->iMask->Duplicate(maskHandle));
86 iFrames.AppendL(frame);
87 CleanupStack::Pop(frame);
88 TInt64 delay = frame->iFrameInfo.iDelay.Int64();
89 if((delay < 0) || (delay > KMaxTUint32))
91 User::Leave(KErrCorrupt);
93 iAnimationLength += delay;
96 BaseConstructL(aEnv,aId,aOwner);
97 if (!(aEnv.Screen(0)->ResolveObjectInterface(KMWsCompositionContext) || aEnv.Screen(0)->ResolveObjectInterface(KMWsScene)))
99 iContext = CWsGraphicDrawerNonNgaContext::NewL();
103 iContext = CWsGraphicDrawerNgaContext::NewL();
107 void CWsGraphicDrawerBitmapAnimation::DoDraw(MWsGc& aGc,const TRect& aRect,const TDesC8& aData) const
109 const TInt count = iFrames.Count();
115 TWsGraphicMsgBufParser buf(aData);
116 if(KErrNone != buf.Verify())
121 TWsGraphicMsgAnimation anim;
122 if (KErrNone != anim.Load(buf))
127 if (KErrNone != iContext->Push(aGc))
132 const TInt64 now_microseconds = (iAnimationLength ? anim.AnimationTime(iContext->Now(aGc),iAnimationLength).Int64(): 0LL);
133 TInt64 time_microseconds = 0LL;
137 while((endFrame<count) && (time_microseconds <= now_microseconds))
140 time_microseconds += iFrames[endFrame]->iFrameInfo.iDelay.Int64();
144 TBool drawError = EFalse;
145 // work out visible regions
146 for(TInt i = 0; (i < endFrame) && !drawError; i++)
148 const CFrame* frame = iFrames[i];
149 const TRect frameRect(frame->iFrameInfo.iFrameCoordsInPixels);
150 frame->iVisibleRegion.Clear();
152 if((i == (endFrame - 1)) || frame->iFrameInfo.iFlags & TFrameInfo::ELeaveInPlace) // ELeave - Enum TFrameInfo::ELeaveInPlace triggers leavescan
154 frame->iVisibleRegion.AddRect(frameRect);
155 drawError = frame->iVisibleRegion.CheckError();
159 if(frame->iFrameInfo.iFlags & TFrameInfo::ERestoreToBackground)
161 for(TInt j = 0; j <= i; j++)
163 iFrames[j]->iVisibleRegion.SubRect(frameRect);
164 // coverity[unchecked_value]
165 drawError |= iFrames[j]->iVisibleRegion.CheckError();
168 else if(!(frame->iFrameInfo.iFlags & TFrameInfo::ERestoreToPrevious)) // if no disposal method is set, treat it as leave in place
170 frame->iVisibleRegion.AddRect(frameRect);
171 drawError = frame->iVisibleRegion.CheckError();
176 //draw each of the visible sub frames
177 for(TInt i = 0; (i < endFrame) && !drawError; i++)
179 const CFrame* frame = iFrames[i];
182 const TRegionFix<1> bitmapRegion(frame->iFrameInfo.iFrameCoordsInPixels);
183 frame->iVisibleRegion.Intersect(bitmapRegion);
184 frame->iVisibleRegion.Tidy();
185 if(frame->iVisibleRegion.CheckError())
192 const TInt clipCount = frame->iVisibleRegion.Count();
193 for(TInt j = 0; j < clipCount; j++)
195 TRect frameRect = frame->iVisibleRegion.RectangleList()[j];
196 TRect clipRect(frameRect);
197 clipRect.Move(aRect.iTl);
198 clipRect.Intersection(aRect);
200 frameRect.Move(aRect.iTl);
201 frameRect.Intersection(aRect);
202 frameRect.Move(-aRect.iTl);
203 frameRect.Move(-frame->iFrameInfo.iFrameCoordsInPixels.iTl);
205 if(!clipRect.IsEmpty() && !frameRect.IsEmpty())
207 iContext->DrawBitmap(aGc,clipRect.iTl, frame->iBitmap, frameRect, frame->iMask);
214 if(0 <= buf.Find(TUid::Uid(TWsGraphicFrameRate::ETypeId)))
216 iContext->DrawFrameRate(aGc,aRect,iFps);
220 if(anim.IsPlaying(iContext->Now(aGc),iAnimationLength))
222 iContext->ScheduleAnimation(aGc, aRect,(time_microseconds - now_microseconds));
226 iContext->ScheduleAnimation(aGc, aRect,now_microseconds + 1000000); // retry in 1 second
232 void CWsGraphicDrawerBitmapAnimation::HandleMessage(const TDesC8& /*aData*/)