|
1 /* |
|
2 * Copyright (c) 2007-2008 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: Default effect order manager |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 // Include Files |
|
22 #include "shwdefaulteffectmanager.h" |
|
23 |
|
24 #include <e32math.h> |
|
25 |
|
26 #include <glxlog.h> |
|
27 #include <glxtracer.h> |
|
28 |
|
29 #include "shwcleanupwrapper.h" |
|
30 #include "shweffect.h" |
|
31 #include "shwconstants.h" |
|
32 #include "shwslideshowenginepanic.h" |
|
33 |
|
34 // ----------------------------------------------------------------------------- |
|
35 // C++ Constructor. Save a few bits of rom with inlining |
|
36 // ----------------------------------------------------------------------------- |
|
37 inline CShwDefaultEffectManager::CShwDefaultEffectManager() |
|
38 : iEffectOrder( MShwEffectManager::EEffectOrderLinear ) // default order |
|
39 { |
|
40 TRACER("CShwDefaultEffectManager::CShwDefaultEffectManager()"); |
|
41 GLX_LOG_INFO( "CShwDefaultEffectManager::CShwDefaultEffectManager()" ); |
|
42 // no implementation required |
|
43 } |
|
44 |
|
45 // ----------------------------------------------------------------------------- |
|
46 // NewL. Static construction |
|
47 // ----------------------------------------------------------------------------- |
|
48 CShwDefaultEffectManager* CShwDefaultEffectManager::NewL() |
|
49 { |
|
50 TRACER("CShwDefaultEffectManager::NewL()"); |
|
51 GLX_LOG_INFO( "CShwDefaultEffectManager::NewL" ); |
|
52 CShwDefaultEffectManager* self = new( ELeave ) CShwDefaultEffectManager; |
|
53 return self; |
|
54 } |
|
55 |
|
56 // ----------------------------------------------------------------------------- |
|
57 // Destructor. |
|
58 // ----------------------------------------------------------------------------- |
|
59 CShwDefaultEffectManager::~CShwDefaultEffectManager() |
|
60 { |
|
61 TRACER("CShwDefaultEffectManager::~CShwDefaultEffectManager"); |
|
62 GLX_LOG_INFO( "CShwDefaultEffectManager::~CShwDefaultEffectManager" ); |
|
63 |
|
64 // Delete the effect objects |
|
65 ResetAndDestroyEffects( iAvailableEffects ); |
|
66 iAvailableEffects.Close(); |
|
67 |
|
68 // Close the "working" effects array |
|
69 // Note that iEffects just references the same elements as iAvailableEffects |
|
70 // so don't delete them again. |
|
71 iEffects.Close(); |
|
72 } |
|
73 |
|
74 // ----------------------------------------------------------------------------- |
|
75 // AddEffectL. |
|
76 // ----------------------------------------------------------------------------- |
|
77 void CShwDefaultEffectManager::AddEffectL( MShwEffect* aEffect ) |
|
78 { |
|
79 TRACER("CShwDefaultEffectManager::AddEffectL"); |
|
80 GLX_LOG_INFO( "CShwDefaultEffectManager::AddEffectL" ); |
|
81 // dont add NULLs to the array |
|
82 if( aEffect ) |
|
83 { |
|
84 iAvailableEffects.AppendL( aEffect ); |
|
85 } |
|
86 } |
|
87 |
|
88 // ----------------------------------------------------------------------------- |
|
89 // CurrentEffect. |
|
90 // ----------------------------------------------------------------------------- |
|
91 MShwEffect* CShwDefaultEffectManager::CurrentEffect() |
|
92 { |
|
93 TRACER("CShwDefaultEffectManager::CurrentEffect"); |
|
94 GLX_LOG_INFO( "CShwDefaultEffectManager::CurrentEffect" ); |
|
95 // check that we have something in iEffects |
|
96 __ASSERT_DEBUG( iEffects.Count() > 0 && iEffects.Count() > iCurrentEffect, |
|
97 NShwEngine::Panic( NShwEngine::EIncorrectEffectIndex ) ); |
|
98 |
|
99 return iEffects[ iCurrentEffect ]; |
|
100 } |
|
101 |
|
102 // ----------------------------------------------------------------------------- |
|
103 // Effect |
|
104 // ----------------------------------------------------------------------------- |
|
105 MShwEffect* CShwDefaultEffectManager::Effect( TInt aDirection ) |
|
106 { |
|
107 TRACER("CShwDefaultEffectManager::Effect"); |
|
108 GLX_LOG_INFO1( "CShwDefaultEffectManager::Effect, direction %d", |
|
109 aDirection ); |
|
110 // check that we have something in iEffects |
|
111 __ASSERT_DEBUG( iEffects.Count() > 0 && iEffects.Count() > iCurrentEffect, |
|
112 NShwEngine::Panic( NShwEngine::EIncorrectEffectIndex ) ); |
|
113 |
|
114 TInt nextEffectIndex = CalculateNextEffectIndex( aDirection ); |
|
115 return iEffects[ nextEffectIndex ]; |
|
116 } |
|
117 |
|
118 // ----------------------------------------------------------------------------- |
|
119 // ProceedToEffect. |
|
120 // ----------------------------------------------------------------------------- |
|
121 void CShwDefaultEffectManager::ProceedToEffect( TInt aDirection ) |
|
122 { |
|
123 TRACER("CShwDefaultEffectManager::ProceedToEffect"); |
|
124 GLX_LOG_INFO1( "CShwDefaultEffectManager::ProceedToEffect,\ |
|
125 direction %d", aDirection ); |
|
126 // calculate new effects |
|
127 CalculateEffects( aDirection ); |
|
128 } |
|
129 |
|
130 // ----------------------------------------------------------------------------- |
|
131 // SetEffectOrder. |
|
132 // ----------------------------------------------------------------------------- |
|
133 void CShwDefaultEffectManager::SetEffectOrder(MShwEffectManager::TShwEffectOrder |
|
134 aOrder) |
|
135 { |
|
136 TRACER("CShwDefaultEffectManager::SetEffectOrder"); |
|
137 GLX_LOG_INFO("CShwDefaultEffectManager::SetEffectOrder"); |
|
138 iEffectOrder = aOrder; |
|
139 /// @todo implement the rest for increment 7 |
|
140 } |
|
141 |
|
142 // ----------------------------------------------------------------------------- |
|
143 // EffectOrder. |
|
144 // ----------------------------------------------------------------------------- |
|
145 MShwEffectManager::TShwEffectOrder CShwDefaultEffectManager::EffectOrder() |
|
146 { |
|
147 TRACER("CShwDefaultEffectManager::EffectOrder"); |
|
148 GLX_LOG_INFO("CShwDefaultEffectManager::EffectOrder"); |
|
149 return iEffectOrder; |
|
150 } |
|
151 |
|
152 // ----------------------------------------------------------------------------- |
|
153 // SetProgrammedEffects. |
|
154 // ----------------------------------------------------------------------------- |
|
155 void CShwDefaultEffectManager::SetProgrammedEffects( |
|
156 RArray<TShwEffectInfo>& /*aEffects*/ ) |
|
157 { |
|
158 TRACER("CShwDefaultEffectManager::SetProgrammedEffects"); |
|
159 GLX_LOG_INFO("CShwDefaultEffectManager::SetProgrammedEffects"); |
|
160 /// @todo implement for increment 7 |
|
161 } |
|
162 |
|
163 // ----------------------------------------------------------------------------- |
|
164 // SetDefaultEffect. |
|
165 // ----------------------------------------------------------------------------- |
|
166 void CShwDefaultEffectManager::SetDefaultEffectL( TShwEffectInfo aInfo ) |
|
167 { |
|
168 TRACER("CShwDefaultEffectManager::SetDefaultEffectL"); |
|
169 GLX_LOG_INFO( "CShwDefaultEffectManager::SetDefaultEffectL" ); |
|
170 |
|
171 // Loop through the effects to find the one with matching info |
|
172 TInt index = iAvailableEffects.Count(); |
|
173 MShwEffect* effect = NULL; |
|
174 while( index-- > 0 ) |
|
175 { |
|
176 // get effect |
|
177 effect = iAvailableEffects[ index ]; |
|
178 // get its info |
|
179 TShwEffectInfo info = effect->EffectInfo(); |
|
180 // check if we got a match |
|
181 if( info == aInfo ) |
|
182 { |
|
183 break; |
|
184 } |
|
185 } |
|
186 // if no effect or no match |
|
187 if( !effect || index < 0 ) |
|
188 { |
|
189 // effect not found |
|
190 User::Leave( KErrArgument ); |
|
191 } |
|
192 |
|
193 // Need to clone the effect as in current release |
|
194 // we have once single effect at a time and one effect instance can only |
|
195 // handle one visual |
|
196 /// @todo fix this so that once the effect order is solved, the effects |
|
197 /// are cloned as needed |
|
198 MShwEffect* clone = effect->CloneLC(); |
|
199 iAvailableEffects.AppendL( clone ); |
|
200 |
|
201 // This will cause a code scanner warning, but it is not possible to do |
|
202 // CleanupStack::Pop(clone) because the pointer pushed |
|
203 // onto the cleanup stack was either of class CShwZoomAndPanEffect |
|
204 // or a CShwCrossFadeEffect and the object 'clone' is of |
|
205 // class MShwEffect |
|
206 CleanupStack::Pop(); //clone |
|
207 |
|
208 iEffects.Append( effect ); |
|
209 iEffects.Append( clone ); |
|
210 |
|
211 // calculate the effects |
|
212 CalculateEffects( 1 ); |
|
213 } |
|
214 |
|
215 // ----------------------------------------------------------------------------- |
|
216 // GetActiveEffectsL |
|
217 // ----------------------------------------------------------------------------- |
|
218 void CShwDefaultEffectManager::GetActiveEffectsL( |
|
219 RPointerArray< MShwEffect >& aEffects ) |
|
220 { |
|
221 TRACER("CShwDefaultEffectManager::GetActiveEffectsL"); |
|
222 GLX_LOG_INFO( "CShwDefaultEffectManager::GetActiveEffectsL" ); |
|
223 ShwCleanupResetAndDestroyPushL(aEffects); |
|
224 // Retrieve each effect |
|
225 for( TInt i = 0; i < iEffects.Count(); ++i ) |
|
226 { |
|
227 // append the effect pointer to the given array |
|
228 aEffects.AppendL( iEffects[i] ); |
|
229 } |
|
230 CleanupStack::Pop(&aEffects); |
|
231 } |
|
232 |
|
233 // ----------------------------------------------------------------------------- |
|
234 // CalculateEffects. |
|
235 // ----------------------------------------------------------------------------- |
|
236 void CShwDefaultEffectManager::CalculateEffects( TInt aDirection ) |
|
237 { |
|
238 TRACER("CShwDefaultEffectManager::CalculateEffects"); |
|
239 GLX_LOG_INFO1( "CShwDefaultEffectManager::CalculateEffects,\ |
|
240 direction %d", aDirection ); |
|
241 // This method updates both the current and next indices for the given |
|
242 // direction. If we're proceeding forwards, temporarily store the |
|
243 // "next" index to set it as "current" after the new "next" value has |
|
244 // been determined (as the next value is determined from the current value). |
|
245 if ( aDirection > 0 ) |
|
246 { |
|
247 // Next effect is "forward" |
|
248 iCurrentEffect = iNextEffect; |
|
249 } |
|
250 else |
|
251 { |
|
252 // moving "backwards" |
|
253 iNextEffect = iCurrentEffect; |
|
254 } |
|
255 |
|
256 if( iEffectOrder == MShwEffectManager::EEffectOrderLinear ) |
|
257 { |
|
258 // As iAvailableEffects is used to store the effects it can be |
|
259 // walked directly and the order will always be correct |
|
260 // |
|
261 TInt nextEffect = CalculateNextEffectIndex( aDirection ); |
|
262 if ( aDirection > 0 ) |
|
263 { |
|
264 // moving forwards |
|
265 iNextEffect = nextEffect; |
|
266 } |
|
267 else |
|
268 { |
|
269 // moving backwards |
|
270 iCurrentEffect = nextEffect; |
|
271 } |
|
272 } |
|
273 } |
|
274 |
|
275 // ----------------------------------------------------------------------------- |
|
276 // ResetAndDestroyEffects. |
|
277 // ----------------------------------------------------------------------------- |
|
278 void CShwDefaultEffectManager::ResetAndDestroyEffects(RArray< MShwEffect* >& |
|
279 aArray) |
|
280 { |
|
281 TRACER("CShwDefaultEffectManager::ResetAndDestroyEffects"); |
|
282 // get the count |
|
283 TInt count = aArray.Count(); |
|
284 GLX_LOG_INFO1( |
|
285 "CShwDefaultEffectManager::ResetAndDestroyEffects %d", count ); |
|
286 |
|
287 // Delete the effect objects |
|
288 for( TInt i = 0; i < count; i++ ) |
|
289 { |
|
290 // call the destructor |
|
291 delete aArray[ i ]; |
|
292 } |
|
293 aArray.Reset(); |
|
294 } |
|
295 |
|
296 // ----------------------------------------------------------------------------- |
|
297 // CalculateNextEffectIndex. |
|
298 // ----------------------------------------------------------------------------- |
|
299 TInt CShwDefaultEffectManager::CalculateNextEffectIndex( TInt aDirection ) |
|
300 { |
|
301 TRACER("CShwDefaultEffectManager::CalculateNextEffectIndex"); |
|
302 GLX_LOG_INFO1( |
|
303 "CShwDefaultEffectManager::CalculateNextEffectIndex %d", aDirection); |
|
304 TInt effectsCount = iEffects.Count(); |
|
305 // Guard against direction exceeding the number of effects |
|
306 TInt direction = aDirection % effectsCount; |
|
307 TInt nextEffect = iCurrentEffect + direction; |
|
308 |
|
309 // ensure index is still in bounds |
|
310 if ( nextEffect < 0 ) |
|
311 { |
|
312 // -ve index: wrap around to the last element |
|
313 nextEffect = effectsCount - 1; |
|
314 } |
|
315 else if ( nextEffect >= effectsCount ) |
|
316 { |
|
317 // passed the end so return to the start. |
|
318 nextEffect = 0; |
|
319 } |
|
320 return nextEffect; |
|
321 } |