|
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". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // |
|
15 |
|
16 /** |
|
17 @file |
|
18 @test |
|
19 @internalComponent - Internal Symbian test code |
|
20 */ |
|
21 |
|
22 #include <bitstd.h> |
|
23 #include <graphics/wsgraphicdrawer.h> |
|
24 #include "ratelimitdrawer.h" |
|
25 #include "wsratelimitdrawer.h" |
|
26 #include <graphics/wsgraphicscontext.h> |
|
27 |
|
28 //Constant message handle, which is used to send count value between client and plug-in |
|
29 const TUint8 KCmdCount=0; |
|
30 // First Frame |
|
31 const TInt KFirstFrame = 0; |
|
32 |
|
33 /** |
|
34 Creates new test framerate object. |
|
35 */ |
|
36 CWsRateLimitGraphicDrawer* CWsRateLimitGraphicDrawer::NewL() |
|
37 { |
|
38 return new(ELeave) CWsRateLimitGraphicDrawer; |
|
39 } |
|
40 |
|
41 CWsRateLimitGraphicDrawer::CWsRateLimitGraphicDrawer() |
|
42 { |
|
43 InitialiseMembers(); |
|
44 } |
|
45 |
|
46 void CWsRateLimitGraphicDrawer::InitialiseMembers() |
|
47 { |
|
48 iColors[0] = TRgb(0x000000); |
|
49 iColors[1] = TRgb(0x555555); |
|
50 iColors[2] = TRgb(0x000080); |
|
51 iColors[3] = TRgb(0x008000); |
|
52 iColors[4] = TRgb(0x008080); |
|
53 iColors[5] = TRgb(0x800000); |
|
54 iColors[6] = TRgb(0x800080); |
|
55 iColors[7] = TRgb(0x808000); |
|
56 iColors[8] = TRgb(0x0000ff); |
|
57 iColors[9] = TRgb(0x00ff00); |
|
58 iColors[10] = TRgb(0x000000); |
|
59 iColors[11] = TRgb(0x555555); |
|
60 iColors[12] = TRgb(0x000080); |
|
61 iColors[13] = TRgb(0x008000); |
|
62 iColors[14] = TRgb(0x008080); |
|
63 iColors[15] = TRgb(0x800000); |
|
64 iColors[16] = TRgb(0x800080); |
|
65 iColors[17] = TRgb(0x808000); |
|
66 iColors[18] = TRgb(0x0000ff); |
|
67 iColors[19] = TRgb(0x00ff00); |
|
68 iColors[20] = TRgb(0x000000); |
|
69 iColors[21] = TRgb(0x555555); |
|
70 iColors[22] = TRgb(0x000080); |
|
71 iColors[23] = TRgb(0x008000); |
|
72 iColors[24] = TRgb(0x008080); |
|
73 iColors[25] = TRgb(0x800000); |
|
74 iColors[26] = TRgb(0x800080); |
|
75 iColors[27] = TRgb(0x808000); |
|
76 iColors[28] = TRgb(0x0000ff); |
|
77 iColors[29] = TRgb(0x00ff00); |
|
78 iColors[30] = TRgb(0x000000); |
|
79 iColors[31] = TRgb(0x555555); |
|
80 iColors[32] = TRgb(0x000080); |
|
81 iColors[33] = TRgb(0x008000); |
|
82 iColors[34] = TRgb(0x008080); |
|
83 iColors[35] = TRgb(0x800000); |
|
84 iColors[36] = TRgb(0x800080); |
|
85 iColors[37] = TRgb(0x808000); |
|
86 iColors[38] = TRgb(0x0000ff); |
|
87 iColors[39] = TRgb(0x00ff00); |
|
88 |
|
89 iFrameRate = 0.0; |
|
90 } |
|
91 |
|
92 |
|
93 CWsRateLimitGraphicDrawer::~CWsRateLimitGraphicDrawer() |
|
94 { |
|
95 } |
|
96 |
|
97 void CWsRateLimitGraphicDrawer::ConstructL(MWsGraphicDrawerEnvironment& aEnv,const TGraphicDrawerId& aId,MWsClient& aOwner,const TDesC8& /*aData*/) |
|
98 { |
|
99 BaseConstructL(aEnv,aId,aOwner); |
|
100 } |
|
101 |
|
102 /** |
|
103 Simulate two animations of different frame rate with their respective schedule. |
|
104 |
|
105 @param MWsGc Window server graphic context to draw the animation |
|
106 @param TRect Rectangle are required to draw the animation |
|
107 @param TDesC Parameter value to use inside this function. |
|
108 */ |
|
109 void CWsRateLimitGraphicDrawer::DoDraw(MWsGc& aGc,const TRect& aRect,const TDesC8& /*aData*/) const |
|
110 { |
|
111 TPoint KWinPos = aRect.iTl + TPoint(10,10); |
|
112 const TSize KWinSize(100,100); |
|
113 const TRect KWinRect(KWinPos,KWinSize); |
|
114 |
|
115 MWsGraphicsContext* context = static_cast<MWsGraphicsContext*>(aGc.ResolveObjectInterface(KMWsGraphicsContext)); |
|
116 |
|
117 //Get the time the animation starts |
|
118 if(iFrame == KFirstFrame) |
|
119 { |
|
120 iStartTime = aGc.Now(); |
|
121 } |
|
122 |
|
123 //Draw a filled rect with the chosen color |
|
124 context->Push(); |
|
125 context->SetBrushStyle(MWsGraphicsContext::ESolidBrush); |
|
126 context->SetBrushColor(iColors[iFrame]); |
|
127 context->DrawRect(KWinRect); |
|
128 context->Pop(); |
|
129 |
|
130 if(iFrame < KMaxFrames) |
|
131 { |
|
132 aGc.ScheduleAnimation(KWinRect,0); |
|
133 } |
|
134 else |
|
135 { |
|
136 TTimeIntervalMicroSeconds animLength = aGc.Now().MicroSecondsFrom(iStartTime); |
|
137 |
|
138 iFrameRate = static_cast<TReal>(KMaxFrames)/(static_cast<TReal>(animLength.Int64())/KOneSecondInMicroSecs); |
|
139 } |
|
140 |
|
141 iFrame++; |
|
142 } |
|
143 |
|
144 /** |
|
145 Handles message between client and plug-in. |
|
146 |
|
147 @param TDesC Constant message command. |
|
148 */ |
|
149 void CWsRateLimitGraphicDrawer::HandleMessage(const TDesC8& aData) |
|
150 { |
|
151 switch (aData[0]) |
|
152 { |
|
153 case KCmdCount: |
|
154 TPckgBuf<TAnimData> buf; |
|
155 buf().iFrameRate = iFrameRate; |
|
156 TInt err = SendMessage(buf); |
|
157 __ASSERT_DEBUG(err>=KErrNone, User::Invariant()); |
|
158 break; |
|
159 } |
|
160 } |
|
161 |