svgtviewer/SvgtViewerPlugin/ScreenSaverPluginSrc/SvgRenderFrameControl.cpp
branchRCL_3
changeset 14 20b99a6d6175
parent 0 632761c941a7
equal deleted inserted replaced
13:e52958d06c29 14:20b99a6d6175
       
     1 /*
       
     2 * Copyright (c) 2005 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:  This file implements a control which displays svg files using 
       
    15 *                renderframes engine api, used by Screen Saver application 
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 #include <eikenv.h>
       
    21 #include <eikappui.h>
       
    22 #include <gdi.h>
       
    23 #include <AknUtils.h>
       
    24 #include <SVGEngineInterfaceImpl.h>
       
    25 #include <SVGTUIDialog.hrh>
       
    26 #include <SVGTAppObserver.h>
       
    27 #include <flogger.h>
       
    28 
       
    29 #include "SvgRenderFrameControl.h"
       
    30 #include "SvgRenderFrameTimer.h"
       
    31 
       
    32 const TUint KConvertToMicroSecond = 1000;
       
    33 const TInt  KMilliSecondsBetweenFrame = 50;
       
    34 
       
    35 // Font Ids for use with Engine-Init
       
    36 const TInt KApacFontId = EApacPlain16;
       
    37 const TInt KLatintFontId = ELatinBold12;
       
    38 
       
    39 // Duration const returned by engine when indefinite animations are present
       
    40 const TUint KIndefiniteDur = 0xffffffff;
       
    41 
       
    42 #ifdef _DEBUG
       
    43 _LIT( KFileLoggingDir, "ScreenSaver" );
       
    44 _LIT( KFileLog, "FromSvgPlugin.txt" );
       
    45 #endif
       
    46 
       
    47 // ============================ MEMBER FUNCTIONS ===============================
       
    48 
       
    49 // -----------------------------------------------------------------------------
       
    50 // CSvgRenderFrameControl::NewL
       
    51 // -----------------------------------------------------------------------------
       
    52 //
       
    53 CSvgRenderFrameControl* CSvgRenderFrameControl::NewL( 
       
    54                                              const CCoeControl* aParent, 
       
    55                                              RFile& aFileHandle ,
       
    56                                              MSvgtAppObserver* aObserver )
       
    57     {
       
    58     CSvgRenderFrameControl* self = CSvgRenderFrameControl::NewLC( aParent,
       
    59                                                                   aFileHandle,
       
    60                                                                   aObserver );   
       
    61     CleanupStack::Pop( self );
       
    62     return self;
       
    63     }
       
    64     
       
    65 // -----------------------------------------------------------------------------
       
    66 // CSvgRenderFrameControl::NewL
       
    67 // -----------------------------------------------------------------------------
       
    68 //
       
    69 CSvgRenderFrameControl* CSvgRenderFrameControl::NewLC( 
       
    70                                              const CCoeControl* aParent, 
       
    71                                              RFile& aFileHandle ,
       
    72                                              MSvgtAppObserver* aObserver )
       
    73     {
       
    74     CSvgRenderFrameControl* self = new (ELeave) CSvgRenderFrameControl(
       
    75                                    aFileHandle, aObserver );
       
    76     CleanupStack::PushL( self );
       
    77     self->ConstructL( aParent );    
       
    78     return self;
       
    79     }    
       
    80 
       
    81 // -----------------------------------------------------------------------------
       
    82 // CSvgRenderFrameControl::~CSvgRenderFrameControl
       
    83 // -----------------------------------------------------------------------------
       
    84 //   
       
    85 CSvgRenderFrameControl::~CSvgRenderFrameControl()
       
    86     {     
       
    87     DeleteEngine();  
       
    88     delete iBmap;  
       
    89     delete iRenderFrameTimer;          
       
    90     }
       
    91 
       
    92 // -----------------------------------------------------------------------------
       
    93 // CSvgRenderFrameControl::SizeChanged
       
    94 // -----------------------------------------------------------------------------
       
    95 // 
       
    96 void CSvgRenderFrameControl::SizeChanged()
       
    97     {
       
    98     iRect = iParent->Rect();
       
    99     
       
   100     }
       
   101 // -----------------------------------------------------------------------------
       
   102 // CSvgRenderFrameControl::UpdateScreen
       
   103 // -----------------------------------------------------------------------------
       
   104 //
       
   105 void CSvgRenderFrameControl::UpdateScreen()
       
   106     {
       
   107     }
       
   108     
       
   109 // -----------------------------------------------------------------------------
       
   110 // CSvgRenderFrameControl::ScriptCall
       
   111 // -----------------------------------------------------------------------------
       
   112 //    
       
   113 TBool CSvgRenderFrameControl::ScriptCall( const TDesC& /*aScript*/,
       
   114                                           CSvgElementImpl* /*aCallerElement*/ )
       
   115     {    
       
   116     return ETrue;
       
   117     }
       
   118 
       
   119 // -----------------------------------------------------------------------------
       
   120 // CSvgRenderFrameControl::FetchImage
       
   121 // -----------------------------------------------------------------------------
       
   122 //    
       
   123 TInt CSvgRenderFrameControl::FetchImage( const TDesC& aUri, RFs& aSession, 
       
   124                                          RFile& aFileHandle )
       
   125     {
       
   126     if ( iAppObserver )
       
   127         {
       
   128         return iAppObserver->FetchImage( aUri, aSession, aFileHandle );        
       
   129         }
       
   130     else
       
   131         {
       
   132         return KErrNotFound;
       
   133         }
       
   134     
       
   135     }
       
   136 
       
   137 TInt CSvgRenderFrameControl::FetchFont( const TDesC& /* aUri */, 
       
   138                                     RFs& /* aSession */, RFile& /* aFileHandle */ )
       
   139     {
       
   140     return KErrNotSupported;
       
   141     }
       
   142 // -----------------------------------------------------------------------------
       
   143 // CSvgRenderFrameControl::GetSmilFitValue
       
   144 // -----------------------------------------------------------------------------
       
   145 //
       
   146 void CSvgRenderFrameControl::GetSmilFitValue(TDes& /*aSmilValue*/)
       
   147     {
       
   148     }
       
   149 
       
   150 // -----------------------------------------------------------------------------
       
   151 // CSvgRenderFrameControl::UpdatePresentation
       
   152 // -----------------------------------------------------------------------------
       
   153 //    
       
   154 void CSvgRenderFrameControl::UpdatePresentation( const TInt32&  
       
   155                                                  /*aNoOfAnimation*/ )
       
   156     {
       
   157     }
       
   158 
       
   159 // -----------------------------------------------------------------------------
       
   160 // CSvgRenderFrameControl::Draw
       
   161 // -----------------------------------------------------------------------------
       
   162 // 
       
   163 void CSvgRenderFrameControl::Draw(const TRect& /*aRect*/) const
       
   164     {       
       
   165        
       
   166     // Calculate rectangle for the whole bitmap
       
   167     TRect bmpPieceRect(TPoint(0,0), iRect.Size() );    
       
   168     
       
   169     // Get the standard graphics context
       
   170     CWindowGc& gc = SystemGc();    
       
   171     
       
   172     gc.SetBrushColor(CGraphicsContext::ENullBrush );
       
   173     gc.SetPenColor( CGraphicsContext::ENullPen );
       
   174     
       
   175     gc.BitBlt( TPoint(0,0),iBitmapFrames[iCurrentFrame],
       
   176               bmpPieceRect );       
       
   177     }
       
   178     
       
   179 // -----------------------------------------------------------------------------
       
   180 // CSvgRenderFrameControl::SetTimer
       
   181 // -----------------------------------------------------------------------------
       
   182 // 
       
   183 void CSvgRenderFrameControl::SetTimer()    
       
   184     {    
       
   185     if ( !iRenderFrameTimer )
       
   186         {        
       
   187         TRAP_IGNORE( iRenderFrameTimer = 
       
   188                     CSvgRenderFrameTimer::NewL( this ) );
       
   189         }
       
   190     if ( iCanPlay )               
       
   191         {
       
   192         // Since the number of delay intervals is one less than 
       
   193         // the number of bitmaps need to have a bound check
       
   194         iRenderFrameTimer->SetTimeOut( iDelayIntervals[
       
   195            iCurrentFrame >= iDelayIntervals.Count() ? 0 : iCurrentFrame]
       
   196            * KConvertToMicroSecond );       
       
   197         }  
       
   198     }
       
   199  
       
   200 // -----------------------------------------------------------------------------
       
   201 // CSvgRenderFrameControl::CancelTimer
       
   202 // -----------------------------------------------------------------------------
       
   203 //      
       
   204 void CSvgRenderFrameControl::CancelTimer()
       
   205     {
       
   206     if (iRenderFrameTimer)
       
   207         {
       
   208         iRenderFrameTimer->Cancel();
       
   209         delete iRenderFrameTimer;
       
   210         iRenderFrameTimer = NULL;
       
   211         }
       
   212     }
       
   213     
       
   214 // -----------------------------------------------------------------------------
       
   215 // CSvgRenderFrameControl::ProcessViewerCommandL
       
   216 // -----------------------------------------------------------------------------
       
   217 //    
       
   218 void CSvgRenderFrameControl::ProcessViewerCommandL( TInt aCommandId )
       
   219     {
       
   220     if ( aCommandId == ESvgtDlgPlayCommand )
       
   221         {
       
   222          _LIT(msg1, "start event " );    
       
   223         PrintDebugMsg( msg1 );    
       
   224         iCanPlay = ETrue;
       
   225         SetTimer();
       
   226         }
       
   227     if ( aCommandId == ESvgtDlgPauseCommand )
       
   228         {
       
   229          _LIT(msg1, "end event " );    
       
   230         PrintDebugMsg( msg1 );    
       
   231         iCanPlay = EFalse;
       
   232         CancelTimer();
       
   233         }        
       
   234     }
       
   235 
       
   236 // -----------------------------------------------------------------------------
       
   237 // CSvgRenderFrameControl::GetCurrentIndex
       
   238 // -----------------------------------------------------------------------------
       
   239 //
       
   240 TInt CSvgRenderFrameControl::GetCurrentIndex() const
       
   241     {
       
   242     return iCurrentFrame;
       
   243     }
       
   244 
       
   245 // -----------------------------------------------------------------------------
       
   246 // CSvgRenderFrameControl::SetCurrentIndex
       
   247 // -----------------------------------------------------------------------------
       
   248 //        
       
   249 void CSvgRenderFrameControl::SetCurrentIndex( TInt aIndex )
       
   250     {
       
   251     iCurrentFrame = aIndex;
       
   252     }
       
   253 
       
   254 // -----------------------------------------------------------------------------
       
   255 // CSvgRenderFrameControl::AnimationTimeOut
       
   256 // -----------------------------------------------------------------------------
       
   257 //     
       
   258 void CSvgRenderFrameControl::AnimationTimeOut()
       
   259     {   
       
   260     DrawNow();
       
   261     SetTimer();
       
   262     MoveIndex();    
       
   263     }
       
   264 
       
   265 // -----------------------------------------------------------------------------
       
   266 // CSvgRenderFrameControl::InitializeEngineL
       
   267 // -----------------------------------------------------------------------------
       
   268 //  
       
   269 void CSvgRenderFrameControl::InitializeEngineL( TBool aCheckFile,
       
   270                                      MSvgRequestObserver* aObserver )
       
   271     {    
       
   272     
       
   273     iBmap =  new ( ELeave ) CFbsBitmap();    
       
   274     TSize dummyScreenSize( 10,10  );    
       
   275     iBmap->Create( dummyScreenSize, EColor16MU );    
       
   276            
       
   277     if ( !iSvgEngine )
       
   278         {
       
   279         TInt fontId = KLatintFontId;
       
   280     
       
   281         switch ( AknLayoutUtils::Variant() )
       
   282             {
       
   283             case EApacVariant:
       
   284                 {
       
   285                 fontId = KApacFontId;
       
   286                 }
       
   287                 break;
       
   288             case EEuropeanVariant:
       
   289             default:
       
   290                 break;
       
   291             }
       
   292         const CFont* font = AknLayoutUtils::FontFromId( fontId );
       
   293         TFontSpec spec = font->FontSpecInTwips();
       
   294 
       
   295         iSvgEngine = CSvgEngineInterfaceImpl::NewL( iBmap,
       
   296                                                     aObserver,
       
   297                                                     spec );                    
       
   298                                                         
       
   299         if ( iSvgEngine && !iSvgDom  )
       
   300             {       
       
   301             if ( aCheckFile )
       
   302                 {
       
   303                 /* Set Thumbnail Mode if check file mode
       
   304                  * so that the rights wont be consumed 
       
   305                  */
       
   306                 iSvgEngine->SetThumbNailMode( ETrue );
       
   307                 }
       
   308                 
       
   309             MSvgError* parseResult = iSvgEngine->PrepareDom( *iFileHandle, 
       
   310                                                              iSvgDom );
       
   311             
       
   312             if ( aCheckFile )
       
   313                 {
       
   314                 /* Reset Thumbnail Mode */                
       
   315                 iSvgEngine->SetThumbNailMode( EFalse );
       
   316                 }                                               
       
   317                                                                
       
   318             if ( parseResult && 
       
   319                  parseResult->HasError() && 
       
   320                  !parseResult->IsWarning() )
       
   321                 {   
       
   322                 if ( parseResult->HasError() == ESvgNoMemory )
       
   323                     {
       
   324                     User::Leave( KErrNoMemory );        
       
   325                     }
       
   326                 else
       
   327                     {
       
   328                     User::Leave( KErrGeneral );
       
   329                     }
       
   330                 }        
       
   331             if ( !aCheckFile )
       
   332                 {
       
   333                 MSvgError* pResult = iSvgEngine->UseDom( iSvgDom, iBmap );
       
   334                 if ( pResult->HasError() && !pResult->IsWarning() )
       
   335                     {                
       
   336                     User::Leave( KErrGeneral );
       
   337                     }               
       
   338                 }
       
   339             }
       
   340         else
       
   341             {
       
   342             User::Leave( KErrGeneral );
       
   343             }
       
   344         }
       
   345     else
       
   346         {
       
   347         User::Leave( KErrGeneral );
       
   348         }
       
   349     return;
       
   350     
       
   351     }
       
   352 
       
   353 // -----------------------------------------------------------------------------
       
   354 // CSvgRenderFrameControl::DeleteEngine
       
   355 // -----------------------------------------------------------------------------
       
   356 //  
       
   357 void CSvgRenderFrameControl::DeleteEngine()
       
   358     {       
       
   359     for ( TInt i = 0; i < iBitmapFrames.Count(); i++ )
       
   360         {
       
   361         delete iBitmapFrames[i];
       
   362         }        
       
   363 
       
   364     for ( TInt i = 0; i < iMaskFrames.Count(); i++ )
       
   365         {
       
   366         delete iMaskFrames[i];
       
   367         }        
       
   368 
       
   369     iBitmapFrames.Reset();
       
   370     iMaskFrames.Reset();
       
   371     iDelayIntervals.Reset();
       
   372     
       
   373     iBitmapFrames.Close();
       
   374     iMaskFrames.Close();
       
   375     iDelayIntervals.Close();
       
   376     
       
   377     iCurrentFrame = 0; 
       
   378     iDuration = 0;
       
   379     
       
   380     if ( iSvgDom )
       
   381         {
       
   382         iSvgEngine->DeleteDom( iSvgDom );
       
   383         iSvgDom = 0;
       
   384         }
       
   385     delete iSvgEngine;    
       
   386     iSvgEngine = NULL;
       
   387     
       
   388     }   
       
   389 
       
   390 // -----------------------------------------------------------------------------
       
   391 // CSvgRenderFrameControl::RenderMyFrames
       
   392 // -----------------------------------------------------------------------------
       
   393 //  
       
   394 TInt CSvgRenderFrameControl::RenderMyFrames()
       
   395     {
       
   396     
       
   397     TUint interval = iSvgEngine->Duration();   
       
   398    
       
   399     if ( interval == KIndefiniteDur || interval > KMaxTimeDuration )
       
   400         {
       
   401         // Infinite content
       
   402         // Dont try to handle using Render Frames
       
   403         // return Error
       
   404         return KErrGeneral;     
       
   405         }
       
   406 
       
   407     
       
   408     
       
   409     MSvgError* result = iSvgEngine->RenderFrames(
       
   410                                        iSvgDom,
       
   411                                        iRect.Size(),
       
   412                                        0, 
       
   413                                        interval,
       
   414                                        KMilliSecondsBetweenFrame,
       
   415                                        EColor64K, EGray2,
       
   416                                        iBitmapFrames,
       
   417                                        iMaskFrames,
       
   418                                        iDelayIntervals,
       
   419                                        ETrue /*Remove redundant frames*/ );
       
   420                                           
       
   421                                        
       
   422     if ( result->HasError() && !result->IsWarning() )
       
   423         {
       
   424         return KErrGeneral;
       
   425         } 
       
   426     else
       
   427         {
       
   428         return KErrNone;
       
   429         }
       
   430     }
       
   431    
       
   432 
       
   433 // -----------------------------------------------------------------------------
       
   434 // CSvgRenderFrameControl::MoveIndex
       
   435 // -----------------------------------------------------------------------------
       
   436 //     
       
   437 void CSvgRenderFrameControl::MoveIndex()
       
   438     {
       
   439     
       
   440     TBuf<64> buffer1;
       
   441     _LIT(msg1, "Index is : %d" );
       
   442     buffer1.Format( msg1, iCurrentFrame );
       
   443     PrintDebugMsg( buffer1 );    
       
   444     
       
   445     iCurrentFrame++;    
       
   446     if ( iCurrentFrame == iBitmapFrames.Count() )
       
   447         {
       
   448         iCurrentFrame = 0;
       
   449         }
       
   450     }
       
   451 
       
   452 // -----------------------------------------------------------------------------
       
   453 // CSvgRenderFrameControl::CSvgRenderFrameControl
       
   454 // -----------------------------------------------------------------------------
       
   455 //
       
   456 CSvgRenderFrameControl::CSvgRenderFrameControl( RFile& aFileHandle,
       
   457                                                 MSvgtAppObserver* aObserver )
       
   458     {
       
   459     iCurrentFrame = 0;
       
   460     iDuration = 0; 
       
   461     iSvgEngine = NULL;
       
   462     iSvgDom = 0;    
       
   463     iFileHandle = &aFileHandle;
       
   464     iCanPlay = EFalse;  
       
   465     iParent = NULL; 
       
   466     iAppObserver = aObserver; 
       
   467     }
       
   468  
       
   469 // -----------------------------------------------------------------------------
       
   470 // CSvgRenderFrameControl::ConstructL
       
   471 // -----------------------------------------------------------------------------
       
   472 //    
       
   473 void CSvgRenderFrameControl::ConstructL( const CCoeControl* aParent )
       
   474     {       
       
   475     
       
   476     if ( aParent )
       
   477         {
       
   478         CreateWindowL(aParent); 
       
   479         iParent = aParent;
       
   480         iRect = aParent->Rect();
       
   481         }    
       
   482      
       
   483     InitializeEngineL( EFalse /*Not checkFile mode*/  , this );    
       
   484        
       
   485     User::LeaveIfError(RenderMyFrames()); 
       
   486     
       
   487     SetRect( iRect );
       
   488     
       
   489     ActivateL();
       
   490     
       
   491     }
       
   492     
       
   493 // -----------------------------------------------------------------------------
       
   494 // CScreenSaverAnimPlugin::PrintDebugMsg
       
   495 // -----------------------------------------------------------------------------
       
   496 //
       
   497 #ifndef _DEBUG        
       
   498 void CSvgRenderFrameControl::PrintDebugMsg( const TDesC&  /* aMsg */ ) const
       
   499 #else
       
   500 void CSvgRenderFrameControl::PrintDebugMsg( const TDesC&  aMsg ) const
       
   501 #endif
       
   502     {
       
   503 #ifdef _DEBUG        
       
   504     RFileLogger::Write( KFileLoggingDir, KFileLog, 
       
   505                         EFileLoggingModeAppend, aMsg );
       
   506 #endif    
       
   507     }  
       
   508           
       
   509 // End Of file.
       
   510