|
1 // Copyright (c) 2004-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 // AnimationDataProvider.cpp |
|
15 // |
|
16 // |
|
17 |
|
18 #include "ICLAnimationDataProvider.h" |
|
19 |
|
20 #include <fbs.h> |
|
21 |
|
22 #include "AnimationMixins.h" |
|
23 #include "AnimationEvents.h" |
|
24 #include "ICLAnimationDataLoader.h" |
|
25 |
|
26 /** Default constructor.*/ |
|
27 EXPORT_C CICLAnimationDataProvider::CICLAnimationDataProvider() |
|
28 { |
|
29 } |
|
30 |
|
31 /** |
|
32 Destructor. |
|
33 |
|
34 It is normal for an animation to take ownership of a data provider, and hence |
|
35 responsibility for destroying it. |
|
36 */ |
|
37 EXPORT_C CICLAnimationDataProvider::~CICLAnimationDataProvider() |
|
38 { |
|
39 Reset(); |
|
40 } //lint !e1740 suppress "pointer member not directly freed or zeroed by destructor" |
|
41 |
|
42 /** |
|
43 Specifies the file to load the animation from. |
|
44 |
|
45 This must be called before constructing an animation with this data provider. |
|
46 It may be called again for other files at any point during the lifespan of |
|
47 the animation, in which case current animation will be stopped. |
|
48 |
|
49 @param aFs A session with the file server |
|
50 @param aFileName The path to the image file to be loaded |
|
51 */ |
|
52 EXPORT_C void CICLAnimationDataProvider::SetFileL(RFs & aFs, const TFileName& aFileName) |
|
53 { |
|
54 Reset(); |
|
55 |
|
56 iDataLoader = CICLAnimationDataLoader::NewL(aFs, *this); |
|
57 iDataLoader->LoadImageDataL(aFileName); |
|
58 if (iObserver) |
|
59 { |
|
60 SendEventL(EAnimationDataChanged); |
|
61 } |
|
62 } |
|
63 |
|
64 /** |
|
65 Implmenets CAnimationDataProvider::StartL() |
|
66 |
|
67 You do not need to call this function unless you are writing a new animation |
|
68 type. |
|
69 */ |
|
70 void CICLAnimationDataProvider::StartL() |
|
71 { |
|
72 if (!iObserver) |
|
73 { |
|
74 User::Leave(KErrNotReady); |
|
75 } |
|
76 |
|
77 DataDeliveryL(); |
|
78 } |
|
79 |
|
80 void CICLAnimationDataProvider::DataDeliveryL() |
|
81 { |
|
82 if (!iDataLoader) |
|
83 { |
|
84 User::Leave(KErrNotReady); |
|
85 } |
|
86 |
|
87 if(!iCurrentFrame) |
|
88 { |
|
89 iCurrentFrame = CAnimationFrame::NewL(); |
|
90 } |
|
91 |
|
92 DecodeImageL(); |
|
93 } |
|
94 |
|
95 void CICLAnimationDataProvider::Reset() |
|
96 { |
|
97 if (iDataLoader) |
|
98 { |
|
99 iDataLoader->Cancel(); |
|
100 delete iDataLoader; |
|
101 iDataLoader = NULL; |
|
102 } |
|
103 |
|
104 delete iCurrentFrame; |
|
105 iCurrentFrame = NULL; |
|
106 } |
|
107 |
|
108 void CICLAnimationDataProvider::DecodeImageL() |
|
109 { |
|
110 iDataLoader->GetNextFrameL(iCurrentFrame); |
|
111 } |
|
112 |
|
113 CAnimationFrame::THandles CICLAnimationDataProvider::CurrentFrame() const |
|
114 { |
|
115 CAnimationFrame::THandles serverFrame; |
|
116 iCurrentFrame->GetHandles(serverFrame); |
|
117 return serverFrame; |
|
118 } |
|
119 |
|
120 void CICLAnimationDataProvider::DataLoaderEventL(TDataLoaderEvent aEvent, TInt aError) |
|
121 { |
|
122 if (aError == KErrNone) |
|
123 { |
|
124 CAnimationFrame::THandles handle; |
|
125 switch(aEvent) |
|
126 { |
|
127 case MICLAnimationDataLoaderObserver::EImagePartialConvert: |
|
128 handle = CurrentFrame(); |
|
129 SendEventL(EBitmapAnimationNewFrame, &handle, sizeof(CAnimationFrame::THandles)); |
|
130 DecodeImageL(); |
|
131 break; |
|
132 case MICLAnimationDataLoaderObserver::EImageConvertComplete: |
|
133 if (!iDataLoader->IsMngAnimation()) |
|
134 { |
|
135 handle = CurrentFrame(); |
|
136 SendEventL(EBitmapAnimationNewFrame, &handle, sizeof(CAnimationFrame::THandles)); |
|
137 } |
|
138 // If it is a mng images, the last frame submitted by ICL is superflous |
|
139 // as a blank frame, it should not be received. |
|
140 SendEventL(EBitmapAnimationComplete); |
|
141 Reset(); |
|
142 break; |
|
143 default: |
|
144 break; |
|
145 } |
|
146 } |
|
147 else |
|
148 { |
|
149 SendEventL(EAnimationDataProviderError, aError); |
|
150 } |
|
151 } |
|
152 |
|
153 /** Reserved for future use */ |
|
154 EXPORT_C void CICLAnimationDataProvider::CICLAnimationDataProvider_Reserved1() |
|
155 { |
|
156 } |
|
157 |
|
158 /** Reserved for future use */ |
|
159 EXPORT_C void CICLAnimationDataProvider::CICLAnimationDataProvider_Reserved2() |
|
160 { |
|
161 } |
|
162 |
|
163 // From CAnimationDataProvider |
|
164 /** Reserved for future use */ |
|
165 EXPORT_C void CICLAnimationDataProvider::CAnimationDataProvider_Reserved1() |
|
166 { |
|
167 CAnimationDataProvider::CAnimationDataProvider_Reserved1(); |
|
168 } |
|
169 |
|
170 /** Reserved for future use */ |
|
171 EXPORT_C void CICLAnimationDataProvider::CAnimationDataProvider_Reserved2() |
|
172 { |
|
173 CAnimationDataProvider::CAnimationDataProvider_Reserved2(); |
|
174 } |
|
175 |
|
176 |
|
177 EXPORT_C TPtrC8 CICLAnimationDataProvider::DataType() |
|
178 { |
|
179 return(KBitmapAnimationDataType()); |
|
180 } |