skins/AknSkins/srvsrc/AknsSrvChunkLookup.cpp
changeset 0 05e9090e2422
child 2 abcbdabaa4c5
equal deleted inserted replaced
-1:000000000000 0:05e9090e2422
       
     1 /*
       
     2 * Copyright (c) 2003-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:  Memory chunk lookup.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 
       
    21 #include <AknsSrvChunkLookup.h>
       
    22 
       
    23 #include "AknsSrvChunkMaintainer.h"
       
    24 #include "AknsSrvItemDef.h"
       
    25 #include <AknsImageAttributeData.h>
       
    26 #include "AknsSrvChunkMaintainer.h"
       
    27 #include "AknsSrvDescriptorFileLayout.h"
       
    28 #include <AknsConstants.h>
       
    29 
       
    30 #include <fbs.h>
       
    31 
       
    32 #include "AknsDebug.h"
       
    33 
       
    34 // -----------------------------------------------------------------------------
       
    35 // C++ default constructor.
       
    36 // -----------------------------------------------------------------------------
       
    37 //
       
    38 CAknsSrvChunkLookup::CAknsSrvChunkLookup()
       
    39     {
       
    40     }
       
    41 
       
    42 // -----------------------------------------------------------------------------
       
    43 // Destructor.
       
    44 // -----------------------------------------------------------------------------
       
    45 //
       
    46 CAknsSrvChunkLookup::~CAknsSrvChunkLookup()
       
    47     {
       
    48     iSharedChunk.Close();
       
    49     iWaitSema.Close();
       
    50     iRenderMutex.Close();
       
    51     }
       
    52 
       
    53 // -----------------------------------------------------------------------------
       
    54 // Symbian 1st phase constructor.
       
    55 // -----------------------------------------------------------------------------
       
    56 //
       
    57 CAknsSrvChunkLookup* CAknsSrvChunkLookup::NewL()
       
    58     {
       
    59     CAknsSrvChunkLookup* self = new (ELeave) CAknsSrvChunkLookup();
       
    60     CleanupStack::PushL(self);
       
    61     self->ConstructL();
       
    62     CleanupStack::Pop( self );
       
    63     return self;
       
    64     }
       
    65 
       
    66 // -----------------------------------------------------------------------------
       
    67 // Symbian 2nd phase constructor.
       
    68 // -----------------------------------------------------------------------------
       
    69 //
       
    70 void CAknsSrvChunkLookup::ConstructL()
       
    71     {
       
    72     // Open the chunk in read only mode.
       
    73     User::LeaveIfError(
       
    74         iSharedChunk.OpenGlobal(KAKNSSRVSHAREDMEMORYCHUNKNAME, ETrue) );
       
    75     User::LeaveIfError(
       
    76         iWaitSema.OpenGlobal(KAKNSSRVWAITSEMAPHORENAME) );
       
    77     User::LeaveIfError(
       
    78         iRenderMutex.OpenGlobal(KAKNSSRVRENDERMUTEXNAME) );
       
    79     }
       
    80 
       
    81 // -----------------------------------------------------------------------------
       
    82 // RAknsSrvSession::LookupAndCreateDefL
       
    83 // -----------------------------------------------------------------------------
       
    84 //
       
    85 EXPORT_C CAknsItemDef* CAknsSrvChunkLookup::LookupAndCreateDefL(
       
    86     const TAknsItemID& aID )
       
    87     {
       
    88     CAknsItemDef* itemdef = NULL;
       
    89     TAknsSrvMPPtr<TAknsSrvDef*>* defptr = NULL;
       
    90     TAknsItemType itemtype = EAknsITUnknown;
       
    91     //TAknsItemID* itemid = NULL;
       
    92     TInt* baseptr;
       
    93 
       
    94     // special case trying to search non-existent item, just return in that case
       
    95     if (aID == KAknsIIDNone)
       
    96         {
       
    97         return NULL;
       
    98         }
       
    99 
       
   100     // Block write access to the shared memory chunk.
       
   101     BeginRead();
       
   102 
       
   103     TUint32* chunkAddr = reinterpret_cast<TUint32*>(iSharedChunk.Base());
       
   104     TBool found = EFalse;
       
   105     
       
   106     //TInt defcount = chunkAddr[EAknsSrvItemDefAreaCurrentSizeOffset] / sizeof(TAknsSrvDef);
       
   107        
       
   108     TUint hashindex = (TUint)(aID.iMajor + aID.iMinor) % 128;
       
   109     
       
   110     TAknsSrvHashTable* h = reinterpret_cast<TAknsSrvHashTable*>(chunkAddr +
       
   111                 (chunkAddr[EAknsSrvItemDefHashBaseOffset])/4 +
       
   112                 hashindex* sizeof(TAknsSrvHashTable)/4);
       
   113     TAknsSrvDef* item = NULL;
       
   114     if ( h->iHead >= 0 )
       
   115         {
       
   116         TInt def = h->iHead;
       
   117         while ( def >= 0)
       
   118             {
       
   119             item = reinterpret_cast<TAknsSrvDef*>(chunkAddr +
       
   120                             (chunkAddr[EAknsSrvItemDefAreaBaseOffset])/4 +
       
   121                             def* sizeof(TAknsSrvDef)/4);
       
   122             if (TAknsItemID::LinearOrder( aID, item->iID) == 0 )
       
   123                 {
       
   124                 found = ETrue;
       
   125                 chunkAddr = chunkAddr+
       
   126                     ((chunkAddr[EAknsSrvItemDefAreaBaseOffset])/4)+
       
   127                     def* sizeof(TAknsSrvDef)/4;
       
   128                 break;
       
   129                 }
       
   130             def = item->iHashNext;
       
   131             }
       
   132          }
       
   133     
       
   134     
       
   135     if (!found)
       
   136         {
       
   137         // Reached the end of the lookup table and found no match
       
   138         EndRead();
       
   139         return NULL;
       
   140         }
       
   141 
       
   142     itemtype = static_cast<TAknsItemType>(*(chunkAddr+2));
       
   143     defptr = reinterpret_cast<TAknsSrvMPPtr<TAknsSrvDef*>*>(chunkAddr+3);
       
   144     TInt creationError = KErrNone;
       
   145     if (defptr->iPtrType == EAknsSrvMPPtrAbsoluteROM)
       
   146         {
       
   147         baseptr = NULL;
       
   148         TRAP( creationError,
       
   149             (itemdef=CreateUnprotectedL( aID, defptr->Address(baseptr), itemtype,
       
   150             baseptr )) );
       
   151         }
       
   152     else
       
   153         {
       
   154         baseptr = (TInt*)iSharedChunk.Base();
       
   155         TRAP( creationError,
       
   156             (itemdef=CreateUnprotectedL( aID, defptr->Address(baseptr+(baseptr[3]/4)), itemtype,
       
   157             baseptr )) );
       
   158         }
       
   159 
       
   160     // Reading done, allow writes to the shared memory again.
       
   161     EndRead();
       
   162 
       
   163     if( creationError != KErrNone )
       
   164         {
       
   165         User::Leave( creationError );
       
   166         }
       
   167 
       
   168     return itemdef;
       
   169     }
       
   170 
       
   171 // -----------------------------------------------------------------------------
       
   172 // CAknsSrvChunkLookup::LookupAndCreateScalableItemL
       
   173 // -----------------------------------------------------------------------------
       
   174 //
       
   175 EXPORT_C void CAknsSrvChunkLookup::LookupAndCreateScalableItemL(
       
   176     const TAknsItemID& aID, const TInt aLayout, const TSize& aLayoutSize, CFbsBitmap*& aBitmap,
       
   177     CFbsBitmap*& aMask, TInt& aMorphing)
       
   178     {
       
   179     BeginRead();
       
   180 
       
   181     TRAPD( err, LookupAndCreateScalableItemUnprotectedL(
       
   182         aID, aLayout, aLayoutSize,  aBitmap, aMask,aMorphing ) );
       
   183 
       
   184     EndRead();
       
   185 
       
   186     if( err )
       
   187         {
       
   188         User::Leave( err );
       
   189         }
       
   190     }
       
   191 
       
   192 // -----------------------------------------------------------------------------
       
   193 // CAknsSrvChunkLookup::BeginRead
       
   194 // -----------------------------------------------------------------------------
       
   195 //
       
   196 void CAknsSrvChunkLookup::BeginRead()
       
   197     {
       
   198     // Wait if there is a write in progress.
       
   199     iWaitSema.Wait();
       
   200     }
       
   201 
       
   202 // -----------------------------------------------------------------------------
       
   203 // CAknsSrvChunkLookup::EndRead
       
   204 // -----------------------------------------------------------------------------
       
   205 //
       
   206 void CAknsSrvChunkLookup::EndRead()
       
   207     {
       
   208     iWaitSema.Signal();
       
   209     }
       
   210 
       
   211 // -----------------------------------------------------------------------------
       
   212 // CAknsSrvChunkLookup::BeginRender
       
   213 // -----------------------------------------------------------------------------
       
   214 //
       
   215 EXPORT_C void CAknsSrvChunkLookup::BeginRender()
       
   216     {
       
   217     // Wait if there is a rendering operation in progress...
       
   218     iRenderMutex.Wait();
       
   219     }
       
   220 
       
   221 // -----------------------------------------------------------------------------
       
   222 // CAknsSrvChunkLookup::EndRender
       
   223 // -----------------------------------------------------------------------------
       
   224 //
       
   225 EXPORT_C void CAknsSrvChunkLookup::EndRender()
       
   226     {
       
   227     iRenderMutex.Signal();
       
   228     }
       
   229 
       
   230 // -----------------------------------------------------------------------------
       
   231 // RAknsSrvSession::Reserved
       
   232 // -----------------------------------------------------------------------------
       
   233 //
       
   234 EXPORT_C TInt CAknsSrvChunkLookup::Reserved()
       
   235     {
       
   236     return 0;
       
   237     }
       
   238 
       
   239 // -----------------------------------------------------------------------------
       
   240 // CAknsSrvChunkLookup::CreateUnprotectedL
       
   241 // -----------------------------------------------------------------------------
       
   242 //
       
   243 CAknsItemDef* CAknsSrvChunkLookup::CreateUnprotectedL( const TAknsItemID& aID,
       
   244     const TAny* aDef, const TAknsItemType aType, const TAny* aBasePtr )
       
   245     {
       
   246     CAknsItemDef* itemdef = NULL;
       
   247     TInt* baseptr = (TInt*)aBasePtr;
       
   248 
       
   249     switch( aType )
       
   250         {
       
   251 
       
   252         case EAknsITBitmap:
       
   253             {
       
   254             if (baseptr)
       
   255                 {
       
   256                 baseptr = baseptr+(baseptr[EAknsSrvFilenameAreaBaseOffset]/4);
       
   257                 }
       
   258             const TAknsSrvBitmapDef* def =
       
   259                 reinterpret_cast<const TAknsSrvBitmapDef*>(aDef);
       
   260             itemdef = CAknsBitmapItemDef::NewL( aID,
       
   261                 TPtrC(def->iFilename.Address(baseptr)),
       
   262                 def->iIndex);
       
   263             CleanupStack::PushL( itemdef );
       
   264 
       
   265             TAknsImageAttributeData attr;
       
   266             attr.iAttributes =
       
   267                 static_cast<TAknsImageAttribute>(def->iImageAttributes);
       
   268             attr.iAlignment =
       
   269                 static_cast<TAknsImageAlignment>(def->iImageAlignment);
       
   270             attr.iCoords = TPoint( def->iImageCoordX, def->iImageCoordY );
       
   271             attr.iSize = TSize( def->iImageSizeW, def->iImageSizeH );
       
   272             static_cast<CAknsImageItemDef*>(itemdef)->SetAttributesL( attr );
       
   273 
       
   274             CleanupStack::Pop( itemdef );
       
   275             break;
       
   276             }
       
   277 
       
   278         case EAknsITMaskedBitmap:
       
   279             {
       
   280             if (baseptr)
       
   281                 {
       
   282                 baseptr = baseptr+(baseptr[EAknsSrvFilenameAreaBaseOffset]/4);
       
   283                 }
       
   284             const TAknsSrvMaskedBitmapDef* def =
       
   285                 reinterpret_cast<const TAknsSrvMaskedBitmapDef*>(aDef);
       
   286             itemdef = CAknsMaskedBitmapItemDef::NewL(aID,
       
   287                 TPtrC(def->iFilename.Address(baseptr)),  def->iIndex,
       
   288                 def->iMaskIndex);
       
   289             CleanupStack::PushL( itemdef );
       
   290 
       
   291             TAknsImageAttributeData attr;
       
   292             attr.iAttributes =
       
   293                 static_cast<TAknsImageAttribute>(def->iImageAttributes);
       
   294             attr.iAlignment =
       
   295                 static_cast<TAknsImageAlignment>(def->iImageAlignment);
       
   296             attr.iCoords = TPoint( def->iImageCoordX, def->iImageCoordY );
       
   297             attr.iSize = TSize( def->iImageSizeW, def->iImageSizeH );
       
   298             static_cast<CAknsImageItemDef*>(itemdef)->SetAttributesL( attr );
       
   299 
       
   300             CleanupStack::Pop( itemdef );
       
   301             break;
       
   302             }
       
   303 
       
   304         case EAknsITColorTable:
       
   305             {
       
   306             if (baseptr)
       
   307                 {
       
   308                 baseptr = baseptr+(baseptr[EAknsSrvDataAreaBaseOffset]/4);
       
   309                 }
       
   310             const TAknsSrvColorTableDef* def =
       
   311                 reinterpret_cast<const TAknsSrvColorTableDef*>(aDef);
       
   312             itemdef = CAknsColorTableItemDef::NewL( aID,
       
   313                 def->iNumberOfColors, def->iColors.Address(baseptr) );
       
   314             CleanupStack::PushL( itemdef );
       
   315 
       
   316             TAknsImageAttributeData attr;
       
   317             attr.iAttributes =
       
   318                 static_cast<TAknsImageAttribute>(def->iImageAttributes);
       
   319             attr.iAlignment =
       
   320                 static_cast<TAknsImageAlignment>(def->iImageAlignment);
       
   321             attr.iCoords = TPoint( def->iImageCoordX, def->iImageCoordY );
       
   322             attr.iSize = TSize( def->iImageSizeW, def->iImageSizeH );
       
   323             static_cast<CAknsImageItemDef*>(itemdef)->SetAttributesL( attr );
       
   324 
       
   325             CleanupStack::Pop( itemdef );
       
   326             break;
       
   327             }
       
   328 
       
   329         case EAknsITImageTable:
       
   330             {
       
   331             if (baseptr)
       
   332                 {
       
   333                 baseptr = baseptr+(baseptr[EAknsSrvDataAreaBaseOffset]/4);
       
   334                 }
       
   335             const TAknsSrvImageTableDef* def =
       
   336                 reinterpret_cast<const TAknsSrvImageTableDef*>(aDef);
       
   337             itemdef = CAknsImageTableItemDef::NewL(aID,
       
   338                 def->iNumberOfImages,
       
   339                 def->iImages.Address(baseptr));
       
   340             CleanupStack::PushL( itemdef );
       
   341 
       
   342             TAknsImageAttributeData attr;
       
   343             attr.iAttributes =
       
   344                 static_cast<TAknsImageAttribute>(def->iImageAttributes);
       
   345             attr.iAlignment =
       
   346                 static_cast<TAknsImageAlignment>(def->iImageAlignment);
       
   347             attr.iCoords = TPoint( def->iImageCoordX, def->iImageCoordY );
       
   348             attr.iSize = TSize( def->iImageSizeW, def->iImageSizeH );
       
   349             static_cast<CAknsImageItemDef*>(itemdef)->SetAttributesL( attr );
       
   350 
       
   351             CleanupStack::Pop( itemdef );
       
   352             break;
       
   353             }
       
   354 
       
   355         case EAknsITBmpAnim:
       
   356             {
       
   357             if (baseptr)
       
   358                 {
       
   359                 baseptr = baseptr+(baseptr[EAknsSrvDataAreaBaseOffset]/4);
       
   360                 }
       
   361             const TAknsSrvBmpAnimDef* def =
       
   362                 reinterpret_cast<const TAknsSrvBmpAnimDef*>(aDef);
       
   363             itemdef = CAknsBmpAnimItemDef::NewL( aID,
       
   364                 def->iNumberOfImages,
       
   365                 def->iImages.Address(baseptr),
       
   366                 def->iFrameInfos.Address(baseptr) );
       
   367             CleanupStack::PushL( itemdef );
       
   368 
       
   369             TAknsImageAttributeData attr;
       
   370             attr.iAttributes =
       
   371                 static_cast<TAknsImageAttribute>(def->iImageAttributes);
       
   372             attr.iAlignment =
       
   373                 static_cast<TAknsImageAlignment>(def->iImageAlignment);
       
   374             attr.iCoords = TPoint( def->iImageCoordX, def->iImageCoordY );
       
   375             attr.iSize = TSize( def->iImageSizeW, def->iImageSizeH );
       
   376             static_cast<CAknsImageItemDef*>(itemdef)->SetAttributesL( attr );
       
   377 
       
   378             static_cast<CAknsBmpAnimItemDef*>(itemdef)->SetLastFrameBackground(
       
   379                 def->iLastFrameBackground );
       
   380             static_cast<CAknsBmpAnimItemDef*>(itemdef)->SetFrameInterval(
       
   381                 def->iFrameInterval );
       
   382             static_cast<CAknsBmpAnimItemDef*>(itemdef)->SetPlayMode(
       
   383                 def->iPlayMode );
       
   384             static_cast<CAknsBmpAnimItemDef*>(itemdef)->SetFlash(
       
   385                 def->iFlash );
       
   386 
       
   387             CleanupStack::Pop( itemdef );
       
   388             break;
       
   389             }
       
   390 
       
   391         case EAknsITString:
       
   392             {
       
   393             if (baseptr)
       
   394                 {
       
   395                 baseptr = baseptr+(baseptr[EAknsSrvDataAreaBaseOffset]/4);
       
   396                 }
       
   397             const TAknsSrvStringDef* def =
       
   398                 reinterpret_cast<const TAknsSrvStringDef*>(aDef);
       
   399             itemdef = CAknsStringItemDef::NewL( aID );
       
   400             CleanupStack::PushL( itemdef );
       
   401 
       
   402             TPtrC string( def->iString.Address(baseptr) );
       
   403             static_cast<CAknsStringItemDef*>(itemdef)->SetStringL(
       
   404                  string );
       
   405 
       
   406             CleanupStack::Pop( itemdef );
       
   407             break;
       
   408             }
       
   409 
       
   410         case EAknsITEffectQueue:
       
   411             {
       
   412             // Create def from raw data
       
   413             itemdef = CreateEffectQueueL( aID, aDef, aBasePtr );
       
   414             break;
       
   415             }
       
   416 
       
   417         case EAknsITAnimation:
       
   418             {
       
   419             // Create def from raw data
       
   420             itemdef = CreateAnimationL( aID, aDef, aBasePtr );
       
   421             break;
       
   422             }
       
   423 
       
   424         case EAknsITUnknown:
       
   425         case EAknsITImage:
       
   426         default:
       
   427             {
       
   428             User::Leave(KErrUnknown);
       
   429             break;
       
   430             }
       
   431 
       
   432         }
       
   433 
       
   434     return itemdef;
       
   435     }
       
   436 
       
   437 // -----------------------------------------------------------------------------
       
   438 // CAknsSrvChunkLookup::LookupAndCreateScalableItemUnprotectedL
       
   439 // -----------------------------------------------------------------------------
       
   440 //
       
   441 void CAknsSrvChunkLookup::LookupAndCreateScalableItemUnprotectedL(
       
   442     const TAknsItemID& aID, const TInt aLayout, const TSize& aLayoutSize, CFbsBitmap*& aBitmap,
       
   443     CFbsBitmap*& aMask, TInt& aMorphing)
       
   444     {
       
   445     TTime currenttime;
       
   446     currenttime.HomeTime();
       
   447 
       
   448     TUint32* chunkAddr = reinterpret_cast<TUint32*>(iSharedChunk.Base());
       
   449     TInt defcount = chunkAddr[EAknsSrvScalableGfxAreaCurrentSizeOffset] /
       
   450         sizeof(TAknsSrvScalableItemDef);
       
   451     chunkAddr = chunkAddr+((chunkAddr[EAknsSrvScalableGfxAreaBaseOffset])/4);
       
   452 
       
   453     TAknsSrvScalableItemDef* table = (TAknsSrvScalableItemDef*)(chunkAddr);
       
   454 
       
   455     TInt bitmapHandle = 0;
       
   456     TInt maskHandle = 0;
       
   457 
       
   458     for (TInt index = 0; index < defcount; index++)
       
   459         {
       
   460         if ((table[index].iID == aID) &&
       
   461             (table[index].iLayoutType == aLayout) &&
       
   462             (table[index].iLayoutSize == aLayoutSize))
       
   463             {
       
   464             bitmapHandle = table[index].iBitmapHandle;
       
   465             if (table[index].iMaskHandle)
       
   466                 {
       
   467                 maskHandle = table[index].iMaskHandle;
       
   468                 }
       
   469             // Update timestamp
       
   470             table[index].iTimeStamp = currenttime;
       
   471             aMorphing = table[index].isMorphing;
       
   472             break; // Break the loop, a match was found.
       
   473             }
       
   474         }
       
   475 
       
   476     // Avoid unnecessary duplicating
       
   477     if( bitmapHandle && aBitmap && (aBitmap->Handle()==bitmapHandle) )
       
   478         {
       
   479         if( (!maskHandle) && (!aMask) )
       
   480             {
       
   481             // No mask, everything OK.
       
   482             return;
       
   483             }
       
   484 
       
   485         if( maskHandle && aMask && (aMask->Handle()==maskHandle) )
       
   486             {
       
   487             // Mask is the same as well
       
   488             return;
       
   489             }
       
   490         }
       
   491 
       
   492     // Initialize to NULL and destroy any previous bitmaps
       
   493     delete aBitmap;
       
   494     aBitmap = NULL;
       
   495     delete aMask;
       
   496     aMask = NULL;
       
   497 
       
   498     CFbsBitmap* bitmap = new (ELeave) CFbsBitmap;
       
   499     CleanupStack::PushL( bitmap ); // (1)
       
   500     CFbsBitmap* mask = new (ELeave) CFbsBitmap;
       
   501     CleanupStack::PushL( mask ); // (2)
       
   502 
       
   503     if( bitmapHandle )
       
   504         {
       
   505         User::LeaveIfError( bitmap->Duplicate( bitmapHandle ) );
       
   506 
       
   507         if( maskHandle )
       
   508             {
       
   509             User::LeaveIfError( mask->Duplicate( maskHandle ) );
       
   510             }
       
   511         else
       
   512             {
       
   513             CleanupStack::PopAndDestroy(1); // mask (1)
       
   514             mask = NULL;
       
   515             CleanupStack::PushL( mask ); // (2)
       
   516             }
       
   517 
       
   518         CleanupStack::Pop(2); // mask, bitmap (0)
       
   519         aBitmap = bitmap;
       
   520         aMask = mask;
       
   521         }
       
   522     else
       
   523         {
       
   524         // No match
       
   525         CleanupStack::PopAndDestroy(2); // mask, bitmap (0)
       
   526         }
       
   527     }
       
   528 
       
   529 // -----------------------------------------------------------------------------
       
   530 // CAknsSrvChunkLookup::CreateEffectQueueL
       
   531 // -----------------------------------------------------------------------------
       
   532 //
       
   533 CAknsEffectQueueItemDef* CAknsSrvChunkLookup::CreateEffectQueueL(
       
   534     const TAknsItemID& aID, const TAny* aDefPtr, const TAny* aBasePtr )
       
   535     {
       
   536     const TAknsSrvEffectQueueDef* def =
       
   537         reinterpret_cast<const TAknsSrvEffectQueueDef*>(aDefPtr);
       
   538     CAknsEffectQueueItemDef* itemdef = CAknsEffectQueueItemDef::NewL(aID);
       
   539     CleanupStack::PushL(itemdef);
       
   540 
       
   541     if (def->iRefMajor && def->iRefMinor)
       
   542         {
       
   543         TAknsItemID id;
       
   544         id.iMajor = def->iRefMajor;
       
   545         id.iMinor = def->iRefMinor;
       
   546 
       
   547         static_cast<CAknsEffectQueueItemDef*>(itemdef)->SetReference(id);
       
   548         CleanupStack::Pop( itemdef );
       
   549         return itemdef;
       
   550         }
       
   551 
       
   552     static_cast<CAknsEffectQueueItemDef*>(itemdef)->SetLayerIndexesAndModes(
       
   553         def->iInputLayerIndex, def->iInputLayerMode,
       
   554         def->iOutputLayerIndex, def->iOutputLayerMode);
       
   555 
       
   556     TUint32 effectcount = def->iEffectCount;
       
   557     TUint32 baseoffset = sizeof(TAknsSrvEffectQueueDef);
       
   558     for (TUint32 ecount = 0; ecount < effectcount; ecount++)
       
   559         {
       
   560         CAknsEffectItemDef* effectitemdef = NULL;
       
   561         TUint32 effectlen = CreateEffectL( effectitemdef, baseoffset, aDefPtr, aBasePtr, EFalse );
       
   562 
       
   563         CleanupStack::PushL(effectitemdef);
       
   564         static_cast<CAknsEffectQueueItemDef*>(itemdef)->AddEffectL(effectitemdef);
       
   565         CleanupStack::Pop( effectitemdef );
       
   566 
       
   567         baseoffset += effectlen;
       
   568         }
       
   569     CleanupStack::Pop( itemdef );
       
   570     return itemdef;
       
   571     }
       
   572 
       
   573 // -----------------------------------------------------------------------------
       
   574 // CAknsSrvChunkLookup::CreateAnimationL
       
   575 // -----------------------------------------------------------------------------
       
   576 //
       
   577 CAknsAnimationItemDef* CAknsSrvChunkLookup::CreateAnimationL(
       
   578     const TAknsItemID& aID, const TAny* aDefPtr, const TAny* aBasePtr )
       
   579     {
       
   580     const TAknsSrvEffectAnimDef* def =
       
   581         reinterpret_cast<const TAknsSrvEffectAnimDef*>(aDefPtr);
       
   582 
       
   583     CAknsAnimationItemDef* itemDef = CAknsAnimationItemDef::NewL( aID );
       
   584     CleanupStack::PushL( itemDef );
       
   585 
       
   586     // TODO Add referencing support
       
   587 
       
   588     // SetLayerIndices would be more posh function name
       
   589     itemDef->SetLayerIndexesAndModes( def->iInputLayerIndex,
       
   590                                       def->iInputLayerMode,
       
   591                                       def->iOutputLayerIndex,
       
   592                                       def->iOutputLayerMode );
       
   593     itemDef->SetMinInterval( def->iMinInterval );
       
   594 
       
   595     if( def->iAnimType == 1 )
       
   596         {
       
   597         itemDef->SetMorphing( ETrue );
       
   598         }
       
   599     else
       
   600         {
       
   601         itemDef->SetMorphing( EFalse );
       
   602         }
       
   603 
       
   604     TUint32 baseoffset = sizeof(TAknsSrvEffectAnimDef);
       
   605     TUint32 i = 0;
       
   606     TUint32 length = 0;
       
   607 
       
   608     // Fetch preprocess commands
       
   609     TUint32 count = def->iPreprocessCount;
       
   610     for( i = 0; i < count; i++)
       
   611         {
       
   612         CAknsEffectItemDef* effect = NULL;
       
   613         length = CreateEffectL( effect, baseoffset, aDefPtr, aBasePtr, EFalse );
       
   614 
       
   615         CleanupStack::PushL(effect);
       
   616         itemDef->AddPreprocessCommandL(effect);
       
   617         CleanupStack::Pop(effect);
       
   618 
       
   619         baseoffset += length;
       
   620         }
       
   621 
       
   622     // Fetch animation commands
       
   623     count = def->iAnimCommandCount;
       
   624     for( i = 0; i < count; i++ )
       
   625         {
       
   626         CAknsEffectItemDef* effect = NULL;
       
   627         length = CreateEffectL( effect, baseoffset, aDefPtr, aBasePtr, ETrue );
       
   628 
       
   629         CleanupStack::PushL(effect);
       
   630         CAknsAnimationCommandItemDef* command =
       
   631             static_cast<CAknsAnimationCommandItemDef*>( effect );
       
   632         itemDef->AddAnimationCommandItemL(command);
       
   633         CleanupStack::Pop(effect);
       
   634 
       
   635         baseoffset += length;
       
   636         }
       
   637 
       
   638     // Fetch animation values
       
   639     count = def->iAnimValueCount;
       
   640     for( i = 0; i < count; i++ )
       
   641         {
       
   642         const TAknsSrvParamGroupDef* groupDef =
       
   643             reinterpret_cast<const TAknsSrvParamGroupDef*>(((TUint8*)aDefPtr) + baseoffset);
       
   644 
       
   645         CAknsAnimationValueDef* value = CAknsAnimationValueDef::NewL();
       
   646         CleanupStack::PushL( value );
       
   647 
       
   648         value->SetAnimationValueUid( TUid::Uid( groupDef->iValueA ) );
       
   649         value->SetTimingModelId( groupDef->iValueB );
       
   650 
       
   651         baseoffset += sizeof(TAknsSrvParamGroupDef);
       
   652 
       
   653         TUint32 paramlen = 0;
       
   654         for (TUint32 pcount = 0; pcount < groupDef->iParameterCount; pcount++)
       
   655             {
       
   656             CAknsEffectParamDef* pdef = NULL;
       
   657 
       
   658             paramlen = CreateParameterL( pdef, baseoffset, aDefPtr, aBasePtr );
       
   659             CleanupStack::PushL( pdef );
       
   660             value->AddParameterL( pdef );
       
   661             CleanupStack::Pop( pdef );
       
   662 
       
   663             baseoffset += paramlen;
       
   664             }
       
   665 
       
   666         itemDef->AddAnimationValueL( value );
       
   667         CleanupStack::Pop( value );
       
   668         }
       
   669 
       
   670     // Fetch timing models
       
   671     count = def->iTimingModelCount;
       
   672     for( i = 0; i < count; i++ )
       
   673         {
       
   674         const TAknsSrvParamGroupDef* groupDef =
       
   675             reinterpret_cast<const TAknsSrvParamGroupDef*>(((TUint8*)aDefPtr) + baseoffset);
       
   676 
       
   677         CAknsTimingModelDef* model = CAknsTimingModelDef::NewL();
       
   678         CleanupStack::PushL( model );
       
   679 
       
   680         model->SetTimingModelUid( TUid::Uid( groupDef->iValueA) );
       
   681 
       
   682         baseoffset += sizeof(TAknsSrvParamGroupDef);
       
   683 
       
   684         TUint32 paramlen = 0;
       
   685         for (TUint32 pcount = 0; pcount < groupDef->iParameterCount; pcount++)
       
   686             {
       
   687             CAknsEffectParamDef* pdef = NULL;
       
   688 
       
   689             paramlen = CreateParameterL( pdef, baseoffset, aDefPtr, aBasePtr );
       
   690             CleanupStack::PushL( pdef );
       
   691             model->AddParameterL( pdef );
       
   692             CleanupStack::Pop( pdef );
       
   693 
       
   694             baseoffset += paramlen;
       
   695             }
       
   696 
       
   697         itemDef->AddTimingModelL( model );
       
   698         CleanupStack::Pop( model );
       
   699         }
       
   700 
       
   701     // Fetch size bound params
       
   702     count = def->iSizeBoundCount;
       
   703     for( i = 0; i < count; i++ )
       
   704         {
       
   705         const TAknsSrvParamGroupDef* groupDef =
       
   706             reinterpret_cast<const TAknsSrvParamGroupDef*>(((TUint8*)aDefPtr) + baseoffset);
       
   707 
       
   708         CAknsSizeBoundParamDef* sizeBound = CAknsSizeBoundParamDef::NewL();
       
   709         CleanupStack::PushL( sizeBound );
       
   710 
       
   711         // SizeBoundValue has one parameter which contains the sizebound
       
   712         // parameter's name. Extra parameters mean corrupted data.
       
   713         if( groupDef->iParameterCount != 1 )
       
   714             {
       
   715             User::Leave( KErrCorrupt );
       
   716             }
       
   717 
       
   718         baseoffset += sizeof(TAknsSrvParamGroupDef);
       
   719 
       
   720         CAknsEffectParamDef* pdef = NULL;
       
   721         baseoffset += CreateParameterL( pdef, baseoffset, aDefPtr, aBasePtr );
       
   722         CleanupStack::PushL( pdef );
       
   723 
       
   724         if( !pdef->GetName() )
       
   725             {
       
   726             User::Leave( KErrCorrupt );
       
   727             }
       
   728 
       
   729         sizeBound->SetDataL( *pdef->GetName(),
       
   730                              groupDef->iValueA,
       
   731                              groupDef->iValueB );
       
   732 
       
   733         itemDef->AddSizeBoundParamL( sizeBound );
       
   734 
       
   735         CleanupStack::PopAndDestroy( pdef );
       
   736         CleanupStack::Pop( sizeBound );
       
   737         }
       
   738 
       
   739     CleanupStack::Pop( itemDef );
       
   740     return itemDef;
       
   741     }
       
   742 
       
   743 // -----------------------------------------------------------------------------
       
   744 // CAknsSrvChunkLookup::CreateParameterL
       
   745 // -----------------------------------------------------------------------------
       
   746 //
       
   747 TUint32 CAknsSrvChunkLookup::CreateParameterL( CAknsEffectParamDef*& aDef,
       
   748     const TUint32 aOffset, const TAny* aDefPtr, const TAny* aBasePtr )
       
   749     {
       
   750     const TAknsSrvEffectParameterDef* paramdef =
       
   751         reinterpret_cast<const TAknsSrvEffectParameterDef*>
       
   752         (((TUint8*)aDefPtr)+aOffset);
       
   753 
       
   754     CAknsEffectParamDef* pdef = CAknsEffectParamDef::NewL();
       
   755     CleanupStack::PushL(pdef);
       
   756 
       
   757     pdef->SetType(paramdef->iParameterType);
       
   758     const TUint8* content = reinterpret_cast<TUint8*>(
       
   759         ((TUint8*)aDefPtr)+aOffset+sizeof(TAknsSrvEffectParameterDef));
       
   760 
       
   761     if (paramdef->iParameterType == 0 ||
       
   762         paramdef->iParameterType == 3 ) // Number of named reference
       
   763         {
       
   764         TUint16 paramnamelen = *((TUint16*)content);
       
   765         if (paramnamelen)
       
   766             {
       
   767             HBufC* name = HBufC::NewL(paramnamelen);
       
   768             CleanupStack::PushL(name);
       
   769             TPtr nam(name->Des());
       
   770             nam.Copy((TUint16*)(content+2),paramnamelen);
       
   771             pdef->SetNameL(*name);
       
   772             CleanupStack::PopAndDestroy( name );
       
   773             }
       
   774 
       
   775         TUint32 value = 0;
       
   776         Mem::Copy(&value,(content+2+paramnamelen*2),sizeof(TUint32));
       
   777         pdef->SetValue(value);
       
   778         }
       
   779     else if (paramdef->iParameterType == 1) // string
       
   780         {
       
   781         TUint16 paramnamelen = *((TUint16*)content);
       
   782         if (paramnamelen)
       
   783             {
       
   784             HBufC* name = HBufC::NewL(paramnamelen);
       
   785             CleanupStack::PushL(name);
       
   786             TPtr nam(name->Des());
       
   787             nam.Copy((TUint16*)(content+2),paramnamelen);
       
   788             pdef->SetNameL(*name);
       
   789             CleanupStack::PopAndDestroy( name );
       
   790             }
       
   791 
       
   792         TUint16 strlen = *((TUint16*)(content+2+paramnamelen*2));
       
   793         if (strlen)
       
   794             {
       
   795             HBufC* str = HBufC::NewL(strlen);
       
   796             CleanupStack::PushL(str);
       
   797             TPtr strptr(str->Des());
       
   798             strptr.Copy((TUint16*)(content+2+paramnamelen*2+2),strlen);
       
   799             pdef->SetValueL(*str);
       
   800             CleanupStack::PopAndDestroy( str );
       
   801             }
       
   802         }
       
   803     else if (paramdef->iParameterType == 2) // graphics
       
   804         {
       
   805         TUint16 paramnamelen = *((TUint16*)content);
       
   806         if (paramnamelen)
       
   807             {
       
   808             HBufC* name = HBufC::NewL(paramnamelen);
       
   809             CleanupStack::PushL(name);
       
   810             TPtr nam(name->Des());
       
   811             nam.Copy((TUint16*)(content+2),paramnamelen);
       
   812             pdef->SetNameL(*name);
       
   813             CleanupStack::PopAndDestroy( name );
       
   814             }
       
   815 
       
   816         TUint32 bmpindex = 0;
       
   817         TUint32 maskindex = 0;
       
   818         TUint32 filenameoffset = 0;
       
   819         Mem::Copy(&bmpindex, (content+2+paramnamelen*2), sizeof(TUint32));
       
   820         Mem::Copy(&maskindex, (content+6+paramnamelen*2), sizeof(TUint32));
       
   821         Mem::Copy(&filenameoffset, (content+10+paramnamelen*2), sizeof(TUint32));
       
   822         TInt* baseptr = (TInt*)(aBasePtr);
       
   823         baseptr = baseptr+(baseptr[EAknsSrvFilenameAreaBaseOffset]/4);
       
   824 
       
   825         TAknsSrvMPPtr<const TText*> iFilename;
       
   826         iFilename.iPtrType = EAknsSrvMPPtrBaseRelativeRAM;
       
   827         iFilename.iAddressOrOffset = reinterpret_cast<const TUint16*>( filenameoffset );
       
   828 
       
   829 
       
   830         HBufC* fname = HBufC::NewL(512);
       
   831         CleanupStack::PushL(fname);
       
   832         TPtr fnptr(fname->Des());
       
   833         fnptr.Copy((TUint16*)(iFilename.Address( baseptr )));
       
   834         pdef->SetValueL(*fname, bmpindex, maskindex);
       
   835         CleanupStack::PopAndDestroy( fname );
       
   836         }
       
   837 
       
   838     CleanupStack::Pop( pdef );
       
   839 
       
   840     aDef = pdef;
       
   841     return paramdef->iParameterLength;
       
   842     }
       
   843 
       
   844 // -----------------------------------------------------------------------------
       
   845 // CAknsSrvChunkLookup::CreateEffectL
       
   846 // -----------------------------------------------------------------------------
       
   847 //
       
   848 TUint32 CAknsSrvChunkLookup::CreateEffectL( CAknsEffectItemDef*& aDef,
       
   849     const TUint32 aOffset, const TAny* aDefPtr, const TAny* aBasePtr,
       
   850     const TBool aIsAnimationCommand )
       
   851     {
       
   852     const TAknsSrvEffectDef* effectdef =
       
   853         reinterpret_cast<const TAknsSrvEffectDef*>(
       
   854         ((TUint8*)aDefPtr)+aOffset);
       
   855 
       
   856     CAknsEffectItemDef* effect = NULL;
       
   857     CAknsAnimationCommandItemDef* animCmd = NULL;
       
   858     if( aIsAnimationCommand )
       
   859         {
       
   860         animCmd = CAknsAnimationCommandItemDef::NewL();
       
   861         effect = animCmd;
       
   862         CleanupStack::PushL( animCmd );
       
   863         }
       
   864     else
       
   865         {
       
   866         effect = CAknsEffectItemDef::NewL();
       
   867         CleanupStack::PushL( effect );
       
   868         }
       
   869 
       
   870     effect->SetEffectUid(TUid(effectdef->iEffectUid));
       
   871     effect->SetLayerIndexesAndModes(
       
   872         effectdef->iInputLayerAIndex,
       
   873         effectdef->iInputLayerAMode,
       
   874         effectdef->iInputLayerBIndex,
       
   875         effectdef->iInputLayerBMode,
       
   876         effectdef->iOutputLayerIndex,
       
   877         effectdef->iOutputLayerMode );
       
   878     TUint32 paramcount = effectdef->iEffectParameterCount;
       
   879     TUint32 baseoffset = sizeof(TAknsSrvEffectDef);
       
   880 
       
   881     TUint32 paramlen = 0;
       
   882 
       
   883     for (TUint32 pcount = 0; pcount < paramcount; pcount++)
       
   884         {
       
   885         CAknsEffectParamDef* pdef = NULL;
       
   886 
       
   887         paramlen = CreateParameterL( pdef, baseoffset, (TAny*)effectdef, aBasePtr );
       
   888 
       
   889         if( pdef->GetType() == 3 ) // Hijack named refs
       
   890             {
       
   891             if( animCmd )
       
   892                 {
       
   893                 CleanupStack::PushL( pdef );
       
   894 
       
   895                 CAknsNamedReferenceDef* namedRef = CAknsNamedReferenceDef::NewL();
       
   896                 CleanupStack::PushL( namedRef );
       
   897                 namedRef->SetDataL( *pdef->GetName(), pdef->GetNumber() );
       
   898                 animCmd->AddNamedReferenceL( namedRef );
       
   899                 CleanupStack::Pop( namedRef );
       
   900 
       
   901                 CleanupStack::PopAndDestroy( pdef );
       
   902                 }
       
   903             else // Theoretical case, named ref defined for non-animation
       
   904                 {
       
   905                 delete pdef;
       
   906                 pdef = NULL;
       
   907                 }
       
   908             }
       
   909         else
       
   910             {
       
   911             CleanupStack::PushL( pdef );
       
   912             effect->AddParameterL( pdef );
       
   913             CleanupStack::Pop( pdef );
       
   914             }
       
   915 
       
   916         baseoffset += paramlen;
       
   917         }
       
   918 
       
   919     CleanupStack::Pop(); // effect xor animCmd
       
   920 
       
   921     aDef = effect;
       
   922     return baseoffset;
       
   923     }
       
   924 
       
   925 // End of file.