uifw/AvKon/src/AknSmileyImage.cpp
branchRCL_3
changeset 9 aabf2c525e0f
parent 0 2f259fa3e83a
child 15 08e69e956a8c
equal deleted inserted replaced
4:8ca85d2f0db7 9:aabf2c525e0f
    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         TRAP_IGNORE( AknsUtils::CreateColorIconL(skin, iImageSkinItem, 
   237         TRAPD(err, 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         TRAP_IGNORE( AknIconUtils::CreateIconL(iFrame, iFrameMask, smileyMifName, iImagePkgItem, iImagePkgItem));
   245         TRAPD(err, 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);
       
   261     TUid i = iFrame->ExtendedBitmapType();
   225     }
   262     }
   226 
   263 
   227 void CSmileyImage::DoRelease()
   264 void CSmileyImage::DoRelease()
   228     {
   265     {
   229     StopAnyAsynchronousTask();
   266     StopAsynchronousTaskTimer();
   230     
   267 
   231     if(!iFrame) return;
   268     if(!iFrame) return;
   232 
   269 
   233     DELZ(iFrame);
   270     DELZ(iFrame);
   234     DELZ(iFrameMask);
   271     DELZ(iFrameMask);
   235     iFrameSnap->Reset();
   272     iFrameSnap->Reset();
   236     
   273     
   237     iReadyToDraw = FALSE;
   274     iReadyToDraw = EFalse;
   238     }
   275     }
   239 
   276 
   240 void CSmileyImage::StopAnyAsynchronousTask()
   277 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     {
   278     {
   272     DoRelease();
   279     DoRelease();
   273     
   280     
   274     if(iRepeatCount != 0)
   281     if(iRepeatCount != 0)
   275         {
   282         {
   276         iRepeatCount--;
   283         iRepeatCount--;
   277         DoLoadL();
   284         DoLoadL();
   278         }
   285         }
   279     }
   286     }
   280 
   287 
   281 void CSmileyImage::StartLoadAsynchronousL(TInt aRepeat, TInt aDelayMicroSeconds)
   288 void CSmileyImage::StopAsynchronousTaskTimer()
   282     {
   289     {
   283     iRepeatCount = aRepeat;
       
   284 
       
   285     iAsynchronousTaskTimer->Cancel();
   290     iAsynchronousTaskTimer->Cancel();
       
   291     }
       
   292 
       
   293 void CSmileyImage::StartLoadAsynchronousL(TInt aDelayMicroSeconds)
       
   294     {
       
   295     StopAsynchronousTaskTimer();
   286     iAsynchronousTaskTimer->Start(aDelayMicroSeconds, 1, TCallBack(StartLoadAsynchronousCallBackL,this));
   296     iAsynchronousTaskTimer->Start(aDelayMicroSeconds, 1, TCallBack(StartLoadAsynchronousCallBackL,this));
   287     }
   297     }
   288 
   298 
   289 TInt CSmileyImage::StartLoadAsynchronousCallBackL(TAny* aPtr)
   299 TInt CSmileyImage::StartLoadAsynchronousCallBackL(TAny* aPtr)
   290     {
   300     {
   291     CSmileyImage* self = (CSmileyImage*)aPtr;
   301     CSmileyImage* self = (CSmileyImage*)aPtr;
   292     self->StopAnyAsynchronousTask();
   302     self->StopAsynchronousTaskTimer();
   293     self->DoLoadL();
   303     self->DoLoadL();
   294     return KErrNone;
   304     return KErrNone;
   295     }
   305     }
   296 
   306 
   297 void CSmileyImage::StopAnimationAsynchronousL(TInt aDelayMicroSeconds)
   307 void CSmileyImage::StopAnimationAsynchronousL(TInt aDelayMicroSeconds)
   298     {
   308     {
   299     iAsynchronousTaskTimer->Cancel();
   309     StopAsynchronousTaskTimer();
   300     iAsynchronousTaskTimer->Start(aDelayMicroSeconds, 1, TCallBack(StopAnimationAsynchronousCallBackL,this));
   310     iAsynchronousTaskTimer->Start(aDelayMicroSeconds, 1, TCallBack(StopAnimationAsynchronousCallBackL,this));
   301     }
   311     }
   302 
   312 
   303 TInt CSmileyImage::StopAnimationAsynchronousCallBackL(TAny* aPtr)
   313 TInt CSmileyImage::StopAnimationAsynchronousCallBackL(TAny* aPtr)
   304     {
   314     {
   305     CSmileyImage* self = (CSmileyImage*)aPtr;
   315     CSmileyImage* self = (CSmileyImage*)aPtr;
   306     self->StopAnyAsynchronousTask();
   316     self->StopAsynchronousTaskTimer();
   307     self->HandleAnimationEndedL();
   317     self->DoHandleEndedL();
   308     return KErrNone;
   318     return KErrNone;
   309     }
   319     }
   310 
   320 
   311 
   321 
   312 // end of file
   322 // end of file