uifw/AvKon/src/AknSmileyImage.cpp
branchRCL_3
changeset 56 d48ab3b357f1
parent 55 aecbbf00d063
child 72 a5e7a4f63858
equal deleted inserted replaced
55:aecbbf00d063 56:d48ab3b357f1
    14 * Description: 
    14 * Description: 
    15 *
    15 *
    16 */
    16 */
    17 
    17 
    18 
    18 
    19 
       
    20 #include <AknUtils.h>
    19 #include <AknUtils.h>
    21 #include <AknsUtils.h>
    20 #include <AknsUtils.h>
    22 #include <AknIconUtils.h>
    21 #include <AknIconUtils.h>
    23 #include <bautils.h>
    22 #include <bautils.h>
    24 
    23 
    25 #include "AknSmileyImage.h"
    24 #include "AknSmileyImage.h"
    26 
    25 
    27 const TInt KFrameMaxInterval = 3*1000*1000; // 30s
    26 const TInt KFrameMaxInterval = 3*1000*1000; // 3s
    28 const TInt KFrameMonitorStep = 5;           // monitor once per 5 call, for increase performence 
    27 const TInt KFrameMonitorStep = 5;           // monitor once per 5 call, for increase performence 
    29 const TInt KMaxSameFrameRepeat = 6;         // 5 * 6, animation frame keep same for 6 times will be stopped
    28 const TInt KMaxSameFrameRepeat = 6;         // 5 * 6, animation whose frame keep the same for 6 times call back, it will be stopped
    30 
    29 
    31 #define DELZ(ptr) {delete (ptr); (ptr)=NULL;}
    30 #define DELZ(ptr) {delete (ptr); (ptr)=NULL;}
    32 
    31 
    33 
    32 
    34 ///////////////////////////////////////////////////////////////////////////////////////////////
    33 ///////////////////////////////////////////////////////////////////////////////////////////////
    62     CleanupStack::PopAndDestroy(2);
    61     CleanupStack::PopAndDestroy(2);
    63     }
    62     }
    64 
    63 
    65 TBool BmpUtils::BitmpIsSame(const CFbsBitmap* aDesBmp, const CFbsBitmap* aSrcBmp)
    64 TBool BmpUtils::BitmpIsSame(const CFbsBitmap* aDesBmp, const CFbsBitmap* aSrcBmp)
    66     {
    65     {
    67     if(!aDesBmp || !aSrcBmp) return FALSE;
    66     if(!aDesBmp || !aSrcBmp) return EFalse;
    68     
    67     
    69     if(aDesBmp->SizeInPixels() == aSrcBmp->SizeInPixels())
    68     if(aDesBmp->SizeInPixels() == aSrcBmp->SizeInPixels())
    70         {
    69         {
    71         TSize size(aSrcBmp->SizeInPixels());
    70         TSize size(aSrcBmp->SizeInPixels());
    72         TInt scanLineLength = CFbsBitmap::ScanLineLength(size.iWidth, aSrcBmp->DisplayMode());
    71         TInt scanLineLength = CFbsBitmap::ScanLineLength(size.iWidth, aSrcBmp->DisplayMode());
    73         TInt length = scanLineLength*size.iHeight;
    72         TInt length = scanLineLength*size.iHeight;
    74         
    73         
    75         aDesBmp->BeginDataAccess();
    74         aDesBmp->BeginDataAccess();
    76         aSrcBmp->BeginDataAccess();
    75         aSrcBmp->BeginDataAccess();
    77         TInt result = Mem::Compare((TUint8*)aDesBmp->DataAddress(), length, (TUint8*)aSrcBmp->DataAddress(), length);
    76         TInt result = Mem::Compare((TUint8*)aDesBmp->DataAddress(), length, (TUint8*)aSrcBmp->DataAddress(), length);
    78         aSrcBmp->EndDataAccess(TRUE);
    77         aSrcBmp->EndDataAccess(ETrue);
    79         aDesBmp->EndDataAccess(TRUE);
    78         aDesBmp->EndDataAccess(ETrue);
    80         
    79         
    81         if(result == KErrNone) return TRUE;
    80         if(result == KErrNone) return ETrue;
    82         }
    81         }
    83     
    82     
    84     return FALSE;
    83     return EFalse;
    85     }
    84     }
    86 
    85 
    87 
    86 
    88 ///////////////////////////////////////////////////////////////////////////////////////////////
    87 ///////////////////////////////////////////////////////////////////////////////////////////////
    89 // SmileyUtils
    88 // SmileyUtils
   119     iFrameSnap = new (ELeave) CFbsBitmap;
   118     iFrameSnap = new (ELeave) CFbsBitmap;
   120     iAsynchronousTaskTimer = CPeriodic::NewL(CActive::EPriorityStandard);
   119     iAsynchronousTaskTimer = CPeriodic::NewL(CActive::EPriorityStandard);
   121     }
   120     }
   122 
   121 
   123 CSmileyImage::CSmileyImage(const TAknsItemID& aSkinImage, TInt aPkgImage, TBool aIsAnimation, MSmileyImageObserver* aObserver) : 
   122 CSmileyImage::CSmileyImage(const TAknsItemID& aSkinImage, TInt aPkgImage, TBool aIsAnimation, MSmileyImageObserver* aObserver) : 
   124 iImagePkgItem(aPkgImage), 
   123 iImageMifPkgItemId(aPkgImage), 
   125 iIsAnimation(aIsAnimation), 
   124 iIsAnimation(aIsAnimation), 
   126 iImageObserver(aObserver)
   125 iImageObserver(aObserver)
   127     {
   126     {
   128     iImageSkinItem.Set(aSkinImage);
   127     iImageSkinItemId.Set(aSkinImage);
   129     }
   128     }
   130 
   129 
   131 CSmileyImage::~CSmileyImage()
   130 CSmileyImage::~CSmileyImage()
   132     {
   131     {
   133     DoRelease();
   132     DoRelease();
   135     DELZ(iAsynchronousTaskTimer);
   134     DELZ(iAsynchronousTaskTimer);
   136     }
   135     }
   137 
   136 
   138 void CSmileyImage::LoadL(TInt aRepeat, TInt aDelay)
   137 void CSmileyImage::LoadL(TInt aRepeat, TInt aDelay)
   139     {
   138     {
   140     StartLoadAsynchronousL(aRepeat, aDelay);
   139     iRepeatCount = aRepeat;
       
   140     
       
   141     if(aDelay > 0)
       
   142         {
       
   143         StartLoadAsynchronousL(aDelay);
       
   144         }
       
   145     else
       
   146         {
       
   147         DoLoadL();
       
   148         }
   141     }
   149     }
   142 
   150 
   143 void CSmileyImage::Release()
   151 void CSmileyImage::Release()
   144     {
   152     {
   145     DoRelease();
   153     DoRelease();
   177     return iFrameMask;
   185     return iFrameMask;
   178     }
   186     }
   179 
   187 
   180 void CSmileyImage::BitmapChanged(CFbsBitmap* aBitmap)
   188 void CSmileyImage::BitmapChanged(CFbsBitmap* aBitmap)
   181     {
   189     {
   182     iReadyToDraw = TRUE; // animation is ready
   190     iReadyToDraw = ETrue; // animation is ready
   183 
   191 
   184     if(iImageObserver) iImageObserver->BitmapChanged(this, aBitmap);
   192     if(iImageObserver) iImageObserver->BitmapChanged(this, aBitmap);
   185 
   193 
   186     TRAP_IGNORE(MonitorAnimationEndedL());
   194     TRAP_IGNORE(MonitorAnimationEndedL());
   187     }
   195     }
   188 
   196 
       
   197 void CSmileyImage::MonitorAnimationEndedL()
       
   198     {
       
   199     // for animation doesn't call back
       
   200     StopAnimationAsynchronousL(KFrameMaxInterval);
       
   201     
       
   202     // for reduce the times of animation monitor
       
   203     iFrameCounter++;
       
   204     if(iFrameCounter % KFrameMonitorStep) return;
       
   205     
       
   206     // for not call back any more
       
   207     StopAnimationAsynchronousL(KFrameMaxInterval);
       
   208     
       
   209     // monitor the end of animation clip, replay or stop animation if ended
       
   210     if(BmpUtils::BitmpIsSame(iFrameSnap, iFrame))
       
   211         {
       
   212         iSameFrameCounter++;
       
   213         if(iSameFrameCounter > KMaxSameFrameRepeat)
       
   214             {
       
   215             StopAnimationAsynchronousL(); // can not stop animation synchronously
       
   216             }
       
   217         }
       
   218     else
       
   219         {
       
   220         iSameFrameCounter = 0;
       
   221         BmpUtils::CopyBitmpL(iFrameSnap, iFrame);
       
   222         }
       
   223     }
       
   224 
   189 void CSmileyImage::DoLoadL()
   225 void CSmileyImage::DoLoadL()
   190     {
   226     {
   191     StopAnyAsynchronousTask();
   227     StopAsynchronousTaskTimer();
   192     
   228 
   193     if(iFrame) return;
   229     if(iFrame) return;
   194 
   230 
   195     TFileName smileyMifName;
   231     TFileName smileyMifName;
   196     SmileyUtils::GetCustomizableResPath(smileyMifName, KSmileyMif);
   232     SmileyUtils::GetCustomizableResPath(smileyMifName, KSmileyMif);
   197     if(iImageSkinItem.iMinor > 0)
   233 
       
   234     if(iImageSkinItemId.iMinor > 0)
   198         {
   235         {
   199         MAknsSkinInstance* skin = AknsUtils::SkinInstance();
   236         MAknsSkinInstance* skin = AknsUtils::SkinInstance();
   200         TRAPD(err, AknsUtils::CreateColorIconL(skin, iImageSkinItem, 
   237         TRAP_IGNORE(AknsUtils::CreateColorIconL(skin, iImageSkinItemId, 
   201                                                KAknsIIDQsnTextColors, EAknsCIQsnTextColorsCG19, 
   238                                                 KAknsIIDQsnTextColors,EAknsCIQsnTextColorsCG19, 
   202                                                iFrame, iFrameMask, 
   239                                                 iFrame,iFrameMask, 
   203                                                smileyMifName, iImagePkgItem, iImagePkgItem, 
   240                                                 smileyMifName, iImageMifPkgItemId,iImageMifPkgItemId, 
   204                                                AKN_LAF_COLOR(215)));
   241                                                 AKN_LAF_COLOR(215)));
   205         }
   242         }
   206     else
   243     else
   207         {
   244         {
   208         TRAPD(err, AknIconUtils::CreateIconL(iFrame, iFrameMask, smileyMifName, iImagePkgItem, iImagePkgItem));
   245         TRAP_IGNORE(AknIconUtils::CreateIconL(iFrame,iFrameMask,smileyMifName,iImageMifPkgItemId,iImageMifPkgItemId));
   209         }
   246         }
   210     
   247     
   211     if(iIsAnimation) // the first frame of animation svg is blank without correct content
   248     if(iIsAnimation) // the first frame of animation svg is blank without correct content
   212         {
   249         {
   213         iReadyToDraw = FALSE;
   250         iReadyToDraw = EFalse;
   214         AknIconUtils::SetObserver(iFrame, this);
   251         AknIconUtils::SetObserver(iFrame, this);
   215         
   252         StopAnimationAsynchronousL(KFrameMaxInterval); // monitor for no callback
   216         StopAnimationAsynchronousL(KFrameMaxInterval);
       
   217         }
   253         }
   218     else // the first frame of static svg has correct content
   254     else // the first frame of static svg has correct content
   219         {
   255         {
   220         iReadyToDraw = TRUE;
   256         iReadyToDraw = ETrue;
   221         if(iImageObserver) iImageObserver->BitmapChanged(this, iFrame);
   257         if(iImageObserver) iImageObserver->BitmapChanged(this, iFrame);
   222         }
   258         }
   223 
   259 
   224     AknIconUtils::SetSize(iFrame, iSize);
   260     AknIconUtils::SetSize(iFrame, iSize);
   225     }
   261     }
   226 
   262 
   227 void CSmileyImage::DoRelease()
   263 void CSmileyImage::DoRelease()
   228     {
   264     {
   229     StopAnyAsynchronousTask();
   265     StopAsynchronousTaskTimer();
   230     
   266 
   231     if(!iFrame) return;
   267     if(!iFrame) return;
   232 
   268 
   233     DELZ(iFrame);
   269     DELZ(iFrame);
   234     DELZ(iFrameMask);
   270     DELZ(iFrameMask);
   235     iFrameSnap->Reset();
   271     iFrameSnap->Reset();
   236     
   272     
   237     iReadyToDraw = FALSE;
   273     iReadyToDraw = EFalse;
   238     }
   274     }
   239 
   275 
   240 void CSmileyImage::StopAnyAsynchronousTask()
   276 void CSmileyImage::DoHandleEndedL()
   241     {
       
   242     iAsynchronousTaskTimer->Cancel();
       
   243     }
       
   244 
       
   245 void CSmileyImage::MonitorAnimationEndedL()
       
   246     {
       
   247     // for animation doesn't call back
       
   248     StopAnimationAsynchronousL(KFrameMaxInterval);
       
   249     
       
   250     // for reduce the times of animation monitor
       
   251     iFrameCounter++;
       
   252     if(iFrameCounter % KFrameMonitorStep) return;
       
   253     
       
   254     // monitor the end of animation clip, replay or stop animation if ended
       
   255     if(BmpUtils::BitmpIsSame(iFrameSnap, iFrame))
       
   256         {
       
   257         iSameFrameCounter++;
       
   258         if(iSameFrameCounter > KMaxSameFrameRepeat)
       
   259             {
       
   260             StopAnimationAsynchronousL();
       
   261             }
       
   262         }
       
   263     else
       
   264         {
       
   265         iSameFrameCounter = 0;
       
   266         BmpUtils::CopyBitmpL(iFrameSnap, iFrame);
       
   267         }
       
   268     }
       
   269 
       
   270 void CSmileyImage::HandleAnimationEndedL()
       
   271     {
   277     {
   272     DoRelease();
   278     DoRelease();
   273     
   279     
   274     if(iRepeatCount != 0)
   280     if(iRepeatCount != 0)
   275         {
   281         {
   276         iRepeatCount--;
   282         iRepeatCount--;
   277         DoLoadL();
   283         DoLoadL();
   278         }
   284         }
   279     }
   285     }
   280 
   286 
   281 void CSmileyImage::StartLoadAsynchronousL(TInt aRepeat, TInt aDelayMicroSeconds)
   287 void CSmileyImage::StopAsynchronousTaskTimer()
   282     {
   288     {
   283     iRepeatCount = aRepeat;
       
   284 
       
   285     iAsynchronousTaskTimer->Cancel();
   289     iAsynchronousTaskTimer->Cancel();
       
   290     }
       
   291 
       
   292 void CSmileyImage::StartLoadAsynchronousL(TInt aDelayMicroSeconds)
       
   293     {
       
   294     StopAsynchronousTaskTimer();
   286     iAsynchronousTaskTimer->Start(aDelayMicroSeconds, 1, TCallBack(StartLoadAsynchronousCallBackL,this));
   295     iAsynchronousTaskTimer->Start(aDelayMicroSeconds, 1, TCallBack(StartLoadAsynchronousCallBackL,this));
   287     }
   296     }
   288 
   297 
   289 TInt CSmileyImage::StartLoadAsynchronousCallBackL(TAny* aPtr)
   298 TInt CSmileyImage::StartLoadAsynchronousCallBackL(TAny* aPtr)
   290     {
   299     {
   291     CSmileyImage* self = (CSmileyImage*)aPtr;
   300     CSmileyImage* self = (CSmileyImage*)aPtr;
   292     self->StopAnyAsynchronousTask();
   301     self->StopAsynchronousTaskTimer();
   293     self->DoLoadL();
   302     self->DoLoadL();
   294     return KErrNone;
   303     return KErrNone;
   295     }
   304     }
   296 
   305 
   297 void CSmileyImage::StopAnimationAsynchronousL(TInt aDelayMicroSeconds)
   306 void CSmileyImage::StopAnimationAsynchronousL(TInt aDelayMicroSeconds)
   298     {
   307     {
   299     iAsynchronousTaskTimer->Cancel();
   308     StopAsynchronousTaskTimer();
   300     iAsynchronousTaskTimer->Start(aDelayMicroSeconds, 1, TCallBack(StopAnimationAsynchronousCallBackL,this));
   309     iAsynchronousTaskTimer->Start(aDelayMicroSeconds, 1, TCallBack(StopAnimationAsynchronousCallBackL,this));
   301     }
   310     }
   302 
   311 
   303 TInt CSmileyImage::StopAnimationAsynchronousCallBackL(TAny* aPtr)
   312 TInt CSmileyImage::StopAnimationAsynchronousCallBackL(TAny* aPtr)
   304     {
   313     {
   305     CSmileyImage* self = (CSmileyImage*)aPtr;
   314     CSmileyImage* self = (CSmileyImage*)aPtr;
   306     self->StopAnyAsynchronousTask();
   315     self->StopAsynchronousTaskTimer();
   307     self->HandleAnimationEndedL();
   316     self->DoHandleEndedL();
   308     return KErrNone;
   317     return KErrNone;
   309     }
   318     }
   310 
   319 
   311 
   320 
   312 // end of file
   321 // end of file