|
1 /* |
|
2 * Copyright (c) 2008-2009 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: Gif Texture creator implementation |
|
15 * |
|
16 */ |
|
17 |
|
18 #include <e32math.h> |
|
19 #include <imageconversion.h> |
|
20 #include <glxtracer.h> |
|
21 #include <glxlog.h> |
|
22 #include <alf/ialfwidgeteventhandler.h> // The interface for event handlers used by widget controls |
|
23 #include <mul/imulmodel.h> // An interface for the data model |
|
24 #include <alf/alfutil.h> // AlfUtil |
|
25 #include <glxmedia.h> |
|
26 |
|
27 #include "glxtexturemanager.h" |
|
28 #include "glxbinding.h" |
|
29 #include "glxuiutility.h" |
|
30 #include "glxdrmgiftexturecreator.h" |
|
31 #include "glxdrmgifactivedecoder.h" |
|
32 |
|
33 const TInt KTimerInterval = 200000; |
|
34 |
|
35 // ----------------------------------------------------------------------------- |
|
36 // NewLC |
|
37 // ----------------------------------------------------------------------------- |
|
38 CGlxDrmGifTextureCreator* CGlxDrmGifTextureCreator::NewL( |
|
39 const CGlxBinding& aBinding, const TGlxMedia& aMedia, |
|
40 TInt aItemIndex, Alf::IMulModel* aModel) |
|
41 { |
|
42 TRACER("CGlxDrmGifTextureCreator* CGlxDrmGifTextureCreator::NewL()"); |
|
43 CGlxDrmGifTextureCreator* self = new (ELeave) CGlxDrmGifTextureCreator( |
|
44 aBinding, aMedia, aItemIndex, aModel); |
|
45 CleanupStack::PushL(self); |
|
46 self->ConstructL(); |
|
47 CleanupStack::Pop(self); |
|
48 return self; |
|
49 } |
|
50 |
|
51 // ----------------------------------------------------------------------------- |
|
52 // destructor |
|
53 // ----------------------------------------------------------------------------- |
|
54 CGlxDrmGifTextureCreator::~CGlxDrmGifTextureCreator() |
|
55 { |
|
56 TRACER("CGlxDrmGifTextureCreator::~CGlxDrmGifTextureCreator()"); |
|
57 ReleaseContent(); |
|
58 |
|
59 // Delete the animation timer |
|
60 if (iAnimationTimer) |
|
61 { |
|
62 iAnimationTimer->Cancel(); |
|
63 delete iAnimationTimer; |
|
64 } |
|
65 |
|
66 iUiUtility->Close(); |
|
67 |
|
68 delete iGlxDecoderAO; |
|
69 |
|
70 iFsSession.Close(); |
|
71 } |
|
72 |
|
73 // ----------------------------------------------------------------------------- |
|
74 // ReleaseContent |
|
75 // ----------------------------------------------------------------------------- |
|
76 void CGlxDrmGifTextureCreator::ReleaseContent() |
|
77 { |
|
78 TRACER("void CGlxDrmGifTextureCreator::ReleaseContent()"); |
|
79 if (iGlxDecoderAO) |
|
80 { |
|
81 iGlxDecoderAO->Cancel(); |
|
82 } |
|
83 |
|
84 for (TInt i = 0; i < iFrameCount; i++) |
|
85 { |
|
86 GLX_LOG_INFO1("CGlxDrmGifTextureCreator::ReleaseContent(). Releasing AnimBitmaps %d", i); |
|
87 delete (iDecodedBitmap[i]); |
|
88 iDecodedBitmap[i] = NULL; |
|
89 delete (iDecodedMask[i]); |
|
90 iDecodedMask[i] = NULL; |
|
91 } |
|
92 |
|
93 if (iUiUtility && iMedia) |
|
94 { |
|
95 iUiUtility->GlxTextureManager().RemoveTexture(iMedia->Id()); |
|
96 } |
|
97 |
|
98 if (iImageDecoder) |
|
99 { |
|
100 delete iImageDecoder; |
|
101 iImageDecoder = NULL; |
|
102 } |
|
103 } |
|
104 |
|
105 // ----------------------------------------------------------------------------- |
|
106 // Constructor |
|
107 // ----------------------------------------------------------------------------- |
|
108 CGlxDrmGifTextureCreator::CGlxDrmGifTextureCreator( |
|
109 const CGlxBinding& aBinding, const TGlxMedia& aMedia, |
|
110 TInt aItemIndex, Alf::IMulModel* aModel) : |
|
111 iBinding(&aBinding), iMedia(&aMedia), iModel(aModel), iItemIndex( |
|
112 aItemIndex) |
|
113 { |
|
114 TRACER("CGlxDrmGifTextureCreator::CGlxDrmGifTextureCreator()"); |
|
115 // Implement nothing here |
|
116 } |
|
117 |
|
118 // ----------------------------------------------------------------------------- |
|
119 // ConstructL |
|
120 // ----------------------------------------------------------------------------- |
|
121 void CGlxDrmGifTextureCreator::ConstructL() |
|
122 { |
|
123 TRACER("CGlxDrmGifTextureCreator::ConstructL()"); |
|
124 iUiUtility = CGlxUiUtility::UtilityL(); |
|
125 User::LeaveIfError(iFsSession.Connect()); |
|
126 iBitmapReady = EFalse; |
|
127 iAnimCount = 0; |
|
128 iAnimateFlag = EFalse; |
|
129 |
|
130 //Set the initial texture, it could be default or the FS texture |
|
131 SetTexture(); |
|
132 // Create the active object |
|
133 iGlxDecoderAO = CGlxDRMgifDecoderAO::NewL(this); |
|
134 #ifdef _DEBUG |
|
135 iStartTime.HomeTime(); |
|
136 #endif |
|
137 CreateImageDecoderL(iMedia->Uri()); |
|
138 CreateBitmapAndStartDecodingL(); |
|
139 } |
|
140 |
|
141 // ----------------------------------------------------------------------------- |
|
142 // UpdateNewImageL |
|
143 // ----------------------------------------------------------------------------- |
|
144 void CGlxDrmGifTextureCreator::UpdateNewImageL(const TGlxMedia& aMedia, |
|
145 TInt aItemIndex) |
|
146 { |
|
147 TRACER("CGlxDrmGifTextureCreator::UpdateNewImageL()"); |
|
148 GLX_LOG_INFO1("CGlxDrmGifTextureCreator::UpdateNewImageL() aItemIndex=%d", aItemIndex); |
|
149 if(aItemIndex == iItemIndex) |
|
150 { |
|
151 return; |
|
152 } |
|
153 iTransparencyPossible = EFalse; |
|
154 iItemIndex = aItemIndex; |
|
155 iMedia = &aMedia; |
|
156 // First release the contents before proceeding further |
|
157 ReleaseContent(); |
|
158 |
|
159 iBitmapReady = EFalse; |
|
160 iAnimCount = 0; |
|
161 iAnimateFlag = EFalse; |
|
162 //Set the initial texture, it could be default or the FS texture |
|
163 SetTexture(); |
|
164 #ifdef _DEBUG |
|
165 iStartTime.HomeTime(); |
|
166 #endif |
|
167 CreateImageDecoderL(iMedia->Uri()); |
|
168 CreateBitmapAndStartDecodingL(); |
|
169 } |
|
170 |
|
171 // ----------------------------------------------------------------------------- |
|
172 // AnimateDRMGifItem |
|
173 // ----------------------------------------------------------------------------- |
|
174 void CGlxDrmGifTextureCreator::AnimateDRMGifItem(TBool aAnimate) |
|
175 { |
|
176 TRACER("CGlxDrmGifTextureCreator::AnimateDRMGifItem()"); |
|
177 if (!iAnimationTimer) |
|
178 { |
|
179 return; |
|
180 } |
|
181 |
|
182 if (aAnimate && iBitmapReady) |
|
183 { |
|
184 if (!iAnimationTimer->IsActive()) |
|
185 { |
|
186 GLX_LOG_INFO1("CGlxDrmGifTextureCreator::AnimateDRMGifItem() - Gif iAnimCount =%d", iAnimCount); |
|
187 GLX_LOG_INFO1("=>CGlxDrmGifTextureCreator::AnimateDRMGifItem() - Gif Frame Interval <%d> us", |
|
188 (TInt)iFrameInfo.iDelay.Int64()); |
|
189 TInt interval =((TInt)iFrameInfo.iDelay.Int64())?((TInt)iFrameInfo.iDelay.Int64()) |
|
190 :KTimerInterval; |
|
191 iAnimationTimer->Start(interval, interval, TCallBack(TimerCallbackL, this)); |
|
192 } |
|
193 iAnimateFlag = ETrue; |
|
194 } |
|
195 else |
|
196 { |
|
197 if (iAnimationTimer->IsActive()) |
|
198 { |
|
199 iAnimationTimer->Cancel(); |
|
200 iAnimateFlag = EFalse; |
|
201 } |
|
202 } |
|
203 } |
|
204 |
|
205 // ----------------------------------------------------------------------------- |
|
206 // RefreshL |
|
207 // ----------------------------------------------------------------------------- |
|
208 void CGlxDrmGifTextureCreator::RefreshL() |
|
209 { |
|
210 TRACER("CGlxDrmGifTextureCreator::RefreshL()"); |
|
211 GLX_LOG_INFO1("CGlxDrmGifTextureCreator::RefreshL() iAnimCount = %d",iAnimCount); |
|
212 TInt textureId = KErrNotFound; |
|
213 if (iTransparencyPossible) |
|
214 { |
|
215 textureId |
|
216 = (iUiUtility->GlxTextureManager().CreateDRMAnimatedGifTextureL( |
|
217 *iMedia, iMedia->IdSpaceId(), iAnimCount, |
|
218 iDecodedBitmap[iAnimCount], iDecodedMask[iAnimCount])).Id(); |
|
219 } |
|
220 else |
|
221 { |
|
222 textureId |
|
223 = (iUiUtility->GlxTextureManager().CreateDRMAnimatedGifTextureL( |
|
224 *iMedia, iMedia->IdSpaceId(), iAnimCount, |
|
225 iDecodedBitmap[iAnimCount], NULL)).Id(); |
|
226 } |
|
227 |
|
228 SetTexture(textureId); |
|
229 iAnimCount++; |
|
230 // Advance animation if the animation count is becoming maximum, |
|
231 // then set it to zero, such that it can animate again frm begining |
|
232 if (iAnimCount >= iFrameCount) |
|
233 { |
|
234 GLX_LOG_INFO("CGlxDrmGifTextureCreator::RefreshL() Reset iAnimCount"); |
|
235 iAnimCount = 0; |
|
236 } |
|
237 } |
|
238 |
|
239 // ----------------------------------------------------------------------------- |
|
240 // CreateBitmapAndStartDecodingL |
|
241 // ----------------------------------------------------------------------------- |
|
242 void CGlxDrmGifTextureCreator::CreateBitmapAndStartDecodingL() |
|
243 { |
|
244 TRACER("CGlxDrmGifTextureCreator::CreateBitmapAndStartDecodingL()"); |
|
245 TSize scrnSize = AlfUtil::ScreenSize(); |
|
246 TSize targetBitmapSize; |
|
247 |
|
248 GLX_LOG_INFO2("CGlxDrmGifTextureCreator::CreateBitmapAndDecodingL() - bitmapsize=%d, %d", |
|
249 iOrigImageDimensions.iWidth,iOrigImageDimensions.iHeight); |
|
250 TReal32 scaleFactor = 0.0f; |
|
251 if (scrnSize.iWidth * iOrigImageDimensions.iHeight > scrnSize.iHeight |
|
252 * iOrigImageDimensions.iWidth) |
|
253 { |
|
254 scaleFactor = (TReal32) scrnSize.iHeight |
|
255 / (TReal32) iOrigImageDimensions.iHeight; |
|
256 } |
|
257 else |
|
258 { |
|
259 scaleFactor = (TReal32) scrnSize.iWidth |
|
260 / (TReal32) iOrigImageDimensions.iWidth; |
|
261 } |
|
262 GLX_LOG_INFO1("CGlxDrmGifTextureCreator::CreateBitmapAndDecodingL() - scaleFactor=%f",scaleFactor); |
|
263 targetBitmapSize.iHeight = iOrigImageDimensions.iHeight * scaleFactor; |
|
264 targetBitmapSize.iWidth = iOrigImageDimensions.iWidth * scaleFactor; |
|
265 GLX_LOG_INFO2("CGlxDrmGifTextureCreator::CreateBitmapAndDecodingL() - targetBitmapSize=%d, %d", |
|
266 targetBitmapSize.iWidth,targetBitmapSize.iHeight); |
|
267 GLX_LOG_INFO1("CGlxDrmGifTextureCreator::CreateBitmapAndDecodingL() iAnimCount =%d", iAnimCount); |
|
268 |
|
269 //create the bitmap for the required size |
|
270 iDecodedBitmap[iAnimCount] = new (ELeave) CFbsBitmap(); |
|
271 iDecodedBitmap[iAnimCount]->Create(ReCalculateSizeL(targetBitmapSize), |
|
272 iFrameInfo.iFrameDisplayMode); |
|
273 User::LeaveIfNull(iDecodedBitmap[iAnimCount]); |
|
274 |
|
275 if (iFrameInfo.iFlags & TFrameInfo::ETransparencyPossible) |
|
276 { |
|
277 iDecodedMask[iAnimCount] = new (ELeave) CFbsBitmap(); |
|
278 iDecodedMask[iAnimCount]->Create(ReCalculateSizeL( |
|
279 targetBitmapSize), iFrameInfo.iFlags |
|
280 & TFrameInfo::EAlphaChannel ? EGray256 : EGray2); |
|
281 User::LeaveIfNull(iDecodedMask[iAnimCount]); |
|
282 |
|
283 // decoding the image |
|
284 iGlxDecoderAO->ConvertImageL(iDecodedBitmap[iAnimCount], |
|
285 iDecodedMask[iAnimCount], iAnimCount, iImageDecoder); |
|
286 iTransparencyPossible = ETrue; |
|
287 } |
|
288 else |
|
289 { |
|
290 // decoding the image |
|
291 iGlxDecoderAO->ConvertImageL(iDecodedBitmap[iAnimCount], NULL, |
|
292 iAnimCount, iImageDecoder); |
|
293 } |
|
294 iAnimCount++; |
|
295 } |
|
296 |
|
297 // ----------------------------------------------------------------------------- |
|
298 // HandleRunL |
|
299 // ----------------------------------------------------------------------------- |
|
300 void CGlxDrmGifTextureCreator::HandleRunL(TRequestStatus& aStatus) |
|
301 { |
|
302 TRACER("CGlxDrmGifTextureCreator::HandleRunL()"); |
|
303 GLX_LOG_INFO2("CGlxDrmGifTextureCreator::HandleRunL() - gif image frame=%d/%d", |
|
304 iAnimCount,iFrameCount); |
|
305 |
|
306 if (iAnimCount < iFrameCount ) |
|
307 { |
|
308 if (!iGlxDecoderAO->IsActive()) |
|
309 { |
|
310 CreateBitmapAndStartDecodingL(); |
|
311 } |
|
312 } |
|
313 else |
|
314 { |
|
315 #ifdef _DEBUG |
|
316 iStopTime.HomeTime(); |
|
317 GLX_LOG_INFO1("CGlxDrmGifTextureCreator::HandleRunL() ConvertImageL took" |
|
318 " <%d> us", (TInt)iStopTime.MicroSecondsFrom(iStartTime).Int64()); |
|
319 #endif |
|
320 TInt err = aStatus.Int(); |
|
321 GLX_LOG_INFO1("CGlxDrmGifTextureCreator::HandleRunL : err=%d", err); |
|
322 |
|
323 if (err == KErrNone) |
|
324 { |
|
325 iBitmapReady = ETrue; |
|
326 iAnimateFlag = ETrue; |
|
327 iAnimCount = 0; |
|
328 ProcessImageL(); |
|
329 } |
|
330 |
|
331 //release imagedecoder after the conversion is over |
|
332 if (iImageDecoder) |
|
333 { |
|
334 delete iImageDecoder; |
|
335 iImageDecoder = NULL; |
|
336 } |
|
337 } |
|
338 } |
|
339 |
|
340 // ----------------------------------------------------------------------------- |
|
341 // ProcessImageL |
|
342 // ----------------------------------------------------------------------------- |
|
343 void CGlxDrmGifTextureCreator::ProcessImageL() |
|
344 { |
|
345 TRACER("CGlxDrmGifTextureCreator::ProcessImageL()"); |
|
346 RefreshL(); |
|
347 |
|
348 GLX_LOG_INFO1("CGlxDrmGifTextureCreator::ProcessImageL() iAnimCount =%d", iAnimCount); |
|
349 GLX_LOG_INFO1("=>CGlxDrmGifTextureCreator::ProcessImageL() - Gif Frame Interval <%d> us", |
|
350 (TInt)iFrameInfo.iDelay.Int64()); |
|
351 iAnimationTimer->Cancel(); |
|
352 if (iAnimateFlag) |
|
353 { |
|
354 // Next frame |
|
355 TInt interval =((TInt)iFrameInfo.iDelay.Int64())?((TInt)iFrameInfo.iDelay.Int64()) |
|
356 :KTimerInterval; |
|
357 iAnimationTimer->Start(interval,interval, TCallBack(TimerCallbackL, this)); |
|
358 } |
|
359 } |
|
360 |
|
361 // ----------------------------------------------------------------------------- |
|
362 // CreateImageDecoderL |
|
363 // ----------------------------------------------------------------------------- |
|
364 void CGlxDrmGifTextureCreator::CreateImageDecoderL(const TDesC& aImageFile) |
|
365 { |
|
366 TRACER("CGlxDrmGifTextureCreator::CreateImageDecoderL()"); |
|
367 GLX_LOG_URI("CGlxDrmGifTextureCreator::CreateImageDecoderL(%S)", &aImageFile); |
|
368 |
|
369 CImageDecoder::TOptions options = |
|
370 (CImageDecoder::TOptions) (CImageDecoder::EOptionNoDither |
|
371 | CImageDecoder::EOptionAlwaysThread); |
|
372 // Create a decoder for the image in the named file |
|
373 TRAPD(error,iImageDecoder = CImageDecoder::FileNewL(iFsSession, |
|
374 aImageFile, options, KNullUid)); |
|
375 if (error != KErrNone) |
|
376 { |
|
377 User::Leave(error); |
|
378 } |
|
379 iFrameInfo = iImageDecoder->FrameInfo(); |
|
380 iOrigImageDimensions = iImageDecoder->FrameInfo().iOverallSizeInPixels; |
|
381 GLX_LOG_INFO1("=>CGlxDrmGifTextureCreator::CreateImageDecoderL() - Gif Frame Interval <%d> us", |
|
382 (TInt)iFrameInfo.iDelay.Int64()); |
|
383 iFrameCount = iImageDecoder->FrameCount(); |
|
384 |
|
385 // We are creating array of KGlxMaxFrameCount frames |
|
386 // So re-setting the array-count with the no. |
|
387 // It will animate till that no. of frames. |
|
388 if (iFrameCount > KGlxMaxFrameCount) |
|
389 { |
|
390 iFrameCount = KGlxMaxFrameCount; |
|
391 } |
|
392 //dont create the timer if it is a singleframe.no need to animate |
|
393 if (iFrameCount > 1) |
|
394 { |
|
395 iAnimationTimer = CPeriodic::NewL(CActive::EPriorityLow); |
|
396 } |
|
397 } |
|
398 |
|
399 // ----------------------------------------------------------------------------- |
|
400 // TimerCallbackL |
|
401 // ----------------------------------------------------------------------------- |
|
402 TInt CGlxDrmGifTextureCreator::TimerCallbackL(TAny* aThis) |
|
403 { |
|
404 TRACER("CGlxDrmGifTextureCreator::TimerCallbackL()"); |
|
405 static_cast<CGlxDrmGifTextureCreator*> (aThis)->ProcessTimerEventL(); |
|
406 return KErrNone; |
|
407 } |
|
408 |
|
409 // ----------------------------------------------------------------------------- |
|
410 // ProcessTimerEventL |
|
411 // ----------------------------------------------------------------------------- |
|
412 void CGlxDrmGifTextureCreator::ProcessTimerEventL() |
|
413 { |
|
414 TRACER("CGlxDrmGifTextureCreator::ProcessTimerEventL()"); |
|
415 ProcessImageL(); |
|
416 } |
|
417 |
|
418 // ----------------------------------------------------------------------------- |
|
419 // ReCalculateSize |
|
420 // ----------------------------------------------------------------------------- |
|
421 TSize CGlxDrmGifTextureCreator::ReCalculateSizeL(TSize& aTargetBitmapSize) |
|
422 { |
|
423 TRACER("CGlxDrmGifTextureCreator::ReCalculateSizeL()"); |
|
424 // calculate the reduction factor on what size we need |
|
425 TInt reductionFactor = iImageDecoder->ReductionFactor(iOrigImageDimensions, |
|
426 aTargetBitmapSize); |
|
427 // get the reduced size onto destination size |
|
428 TSize destSize; |
|
429 User::LeaveIfError(iImageDecoder->ReducedSize(iOrigImageDimensions, |
|
430 reductionFactor, destSize)); |
|
431 GLX_LOG_INFO2("CGlxDrmGifTextureCreator::ReCalculateSizeL() destSize=%d, %d", |
|
432 destSize.iWidth,destSize.iHeight); |
|
433 return destSize; |
|
434 } |
|
435 |
|
436 // ----------------------------------------------------------------------------- |
|
437 // SetTexture |
|
438 // ----------------------------------------------------------------------------- |
|
439 void CGlxDrmGifTextureCreator::SetTexture(TInt aTextureId) |
|
440 { |
|
441 TRACER("CGlxDrmGifTextureCreator::SetTexture()"); |
|
442 auto_ptr<MulVisualItem> item(new (EMM) MulVisualItem()); |
|
443 iBinding->PopulateT(*item, *iMedia, ETrue, aTextureId); |
|
444 iModel->SetData(iItemIndex, item); |
|
445 } |