tvout/src/glxhdmisurfaceupdater.cpp
changeset 24 99ad1390cd33
parent 23 74c9f037fd5d
equal deleted inserted replaced
23:74c9f037fd5d 24:99ad1390cd33
    36 const TInt KZoomDelay = 10000;
    36 const TInt KZoomDelay = 10000;
    37 //100 , is decide for 20 steps of zooming , with each step being 5 pixels.
    37 //100 , is decide for 20 steps of zooming , with each step being 5 pixels.
    38 const TInt KMaxZoomLimit = 100;
    38 const TInt KMaxZoomLimit = 100;
    39 //evey time we zoom , there is a increase in the ht amd width by 10 pixels.
    39 //evey time we zoom , there is a increase in the ht amd width by 10 pixels.
    40 const TInt KSingleStepForZoom = 10;
    40 const TInt KSingleStepForZoom = 10;
    41 
       
    42 const TInt KSleepTime = 50*1000; // 100 ms
       
    43 // -----------------------------------------------------------------------------
    41 // -----------------------------------------------------------------------------
    44 // NewLC
    42 // NewLC
    45 // -----------------------------------------------------------------------------
    43 // -----------------------------------------------------------------------------
    46 CGlxHdmiSurfaceUpdater* CGlxHdmiSurfaceUpdater::NewL(RWindow* aWindow, const TDesC& aImageFile, 
    44 CGlxHdmiSurfaceUpdater* CGlxHdmiSurfaceUpdater::NewL(RWindow* aWindow, const TDesC& aImageFile, 
    47         TSize aImageDimensions, TInt aFrameCount, MGlxGenCallback* aCallBack)
    45                                                       MGlxGenCallback* aCallBack)
    48     {
    46     {
    49     TRACER("CGlxHdmiSurfaceUpdater* CGlxHdmiSurfaceUpdater::NewL()");
    47     TRACER("CGlxHdmiSurfaceUpdater* CGlxHdmiSurfaceUpdater::NewL()");
    50     CGlxHdmiSurfaceUpdater* self = new (ELeave) CGlxHdmiSurfaceUpdater(aWindow, aImageFile,
    48     CGlxHdmiSurfaceUpdater* self = new (ELeave) CGlxHdmiSurfaceUpdater(aWindow, aImageFile,
    51             aImageDimensions, aFrameCount, aCallBack);
    49                                                                     aCallBack);
    52     CleanupStack::PushL(self);
    50     CleanupStack::PushL(self);
    53     self->ConstructL(aImageDimensions);
    51     self->ConstructL();
    54     CleanupStack::Pop(self);
    52     CleanupStack::Pop(self);
    55     return self;
    53     return self;
    56     }
    54     }
    57 
    55 
    58 // -----------------------------------------------------------------------------
    56 // -----------------------------------------------------------------------------
    78     iGlxDecoderAO = NULL;
    76     iGlxDecoderAO = NULL;
    79     iFsSession.Close();
    77     iFsSession.Close();
    80     if (iSurfManager)
    78     if (iSurfManager)
    81         {
    79         {
    82         GLX_LOG_INFO("CGlxHdmiSurfaceUpdater::~CGlxHdmiSurfaceUpdater() - Close"); 
    80         GLX_LOG_INFO("CGlxHdmiSurfaceUpdater::~CGlxHdmiSurfaceUpdater() - Close"); 
    83         iSurfUpdateSession.Close();
    81         if(iSurfSessionConnected)
       
    82             {
       
    83             iSurfUpdateSession.Close();
       
    84             }
    84         if (iSurfChunk)
    85         if (iSurfChunk)
    85             {
    86             {
    86             iSurfChunk->Close();
    87             iSurfChunk->Close();
    87             }            
    88             }            
    88         delete iSurfChunk;
    89         delete iSurfChunk;
   104     TRACER("void CGlxHdmiSurfaceUpdater::ReleaseContent()"); 
   105     TRACER("void CGlxHdmiSurfaceUpdater::ReleaseContent()"); 
   105     if ( iGlxDecoderAO )
   106     if ( iGlxDecoderAO )
   106         {
   107         {
   107         iGlxDecoderAO->Cancel();
   108         iGlxDecoderAO->Cancel();
   108         }
   109         }
   109     // Delete the animation timer
   110     
   110     if(iAnimationTimer && iAnimationTimer->IsActive())
   111     if ( iDecodedBitmap )
   111         {
   112         {
   112         iAnimationTimer->Cancel();
   113         delete iDecodedBitmap;
   113         delete iAnimationTimer;   
   114         iDecodedBitmap= NULL;
   114         }
   115         }
   115     for (TInt i=0; i<= iFrameCount-1; i++)
   116     
   116         {
   117     if(iSurfBufferAO && iSurfBufferAO->IsActive())
   117         GLX_LOG_INFO1("CGlxHdmiSurfaceUpdater::ReleaseContent(). Releasing AnimBitmaps %d", i);
   118         {
   118         delete(iDecodedBitmap[i]);
   119 		iSurfBufferAO->Cancel();
   119         iDecodedBitmap[i] = NULL;
   120         }
   120         }
   121     
   121     if ( iSurfBufferAO->IsActive() )
       
   122         {
       
   123         iSurfBufferAO->Cancel();        
       
   124         }
       
   125     if ( iImageDecoder )
   122     if ( iImageDecoder )
   126         {
   123         {
   127         delete iImageDecoder;
   124         delete iImageDecoder;
   128         iImageDecoder = NULL;    
   125         iImageDecoder = NULL;    
   129         }
   126         }
   130     iSurfUpdateSession.CancelAllUpdateNotifications();
   127     
       
   128     if (iSurfSessionConnected &&  iSurfManager)
       
   129         {
       
   130         iSurfUpdateSession.CancelAllUpdateNotifications();
       
   131         }
   131     }
   132     }
   132 
   133 
   133 // -----------------------------------------------------------------------------
   134 // -----------------------------------------------------------------------------
   134 // CTor 
   135 // CTor 
   135 // -----------------------------------------------------------------------------
   136 // -----------------------------------------------------------------------------
   136 CGlxHdmiSurfaceUpdater::CGlxHdmiSurfaceUpdater(RWindow* aWindow, const TDesC& aImageFile, 
   137 CGlxHdmiSurfaceUpdater::CGlxHdmiSurfaceUpdater(RWindow* aWindow, 
   137         TSize aOrigImageDimensions, TInt aFrameCount, MGlxGenCallback* aCallBack): 
   138                           const TDesC& aImageFile, MGlxGenCallback* aCallBack): 
   138         iWindow(aWindow), iImagePath(aImageFile), iOrigImageDimensions(aOrigImageDimensions),
   139                           iWindow(aWindow), iImagePath(aImageFile), 
   139         iFrameCount(aFrameCount ),iCallBack(aCallBack)
   140                           iCallBack(aCallBack)
   140     {
   141     {
   141     TRACER("CGlxHdmiSurfaceUpdater::CGlxHdmiSurfaceUpdater()");
   142     TRACER("CGlxHdmiSurfaceUpdater::CGlxHdmiSurfaceUpdater()");
   142     // Implement nothing here
   143     // Implement nothing here
   143     }
   144     }
   144 
   145 
   145 // -----------------------------------------------------------------------------
   146 // -----------------------------------------------------------------------------
   146 // ConstructL 
   147 // ConstructL 
   147 // -----------------------------------------------------------------------------
   148 // -----------------------------------------------------------------------------
   148 void CGlxHdmiSurfaceUpdater::ConstructL(TSize /*aImageDimensions*/)
   149 void CGlxHdmiSurfaceUpdater::ConstructL()
   149     {
   150     {
   150     TRACER("CGlxHdmiSurfaceUpdater::ConstructL()");
   151     TRACER("CGlxHdmiSurfaceUpdater::ConstructL()");
   151     TInt error = iFsSession.Connect ();
   152     TInt error = iFsSession.Connect ();
   152     if ( KErrNone!= iFsSession.Connect () )
   153     GLX_LOG_INFO1("CGlxHdmiSurfaceUpdater::ConstructL() FsSession Connect error = %d", error);
   153         {
   154     User::LeaveIfError(error);
   154         User::LeaveIfError(error);
   155     
   155         }
       
   156     iBitmapReady = EFalse;
   156     iBitmapReady = EFalse;
   157     iAnimCount = 0;
       
   158     // Create the active object
   157     // Create the active object
   159     iGlxDecoderAO = CGlxHdmiDecoderAO::NewL(this, iFrameCount);
   158     iGlxDecoderAO = CGlxHdmiDecoderAO::NewL(this);
   160     CreateImageDecoderL(iImagePath);
   159     CreateImageDecoderL(iImagePath);
   161     CreateBitmapAndStartDecodingL();
   160     CreateBitmapL();
   162     CreateHdmiL();
   161     CreateHdmiL();
   163     error = iSurfUpdateSession.Connect();
   162     error = iSurfUpdateSession.Connect();
       
   163     GLX_LOG_INFO1("CGlxHdmiSurfaceUpdater::ConstructL() Surface update Session Connect error = %d", error);
       
   164     User::LeaveIfError(error);
       
   165     iSurfSessionConnected = ETrue;
       
   166     
   164 #ifdef _DEBUG
   167 #ifdef _DEBUG
   165     iStartTime.HomeTime();
   168     iStartTime.HomeTime();
   166 #endif
   169 #endif
   167     if (KErrNone !=error)
   170     //start decoding the image    
   168         {
   171     iGlxDecoderAO->ConvertImageL(*iDecodedBitmap,iImageDecoder);    
   169         GLX_LOG_INFO1("CGlxHdmiSurfaceUpdater::ConstructL() Surface update Session Connect Failed with error = %d", error);
   172     
   170         User::LeaveIfError(error);
       
   171         }
       
   172     iLeftCornerForZoom.iX = 0; 
   173     iLeftCornerForZoom.iX = 0; 
   173     iLeftCornerForZoom.iY = 0;
   174     iLeftCornerForZoom.iY = 0;
   174     iTimer = CPeriodic::NewL( CActive::EPriorityStandard );
   175     iTimer = CPeriodic::NewL( CActive::EPriorityStandard );
   175     iZoom = ETrue;
   176     iZoom = ETrue;
   176     }
   177     }
   177 
   178 
   178 // -----------------------------------------------------------------------------
   179 // -----------------------------------------------------------------------------
   179 // UpdateNewImageL 
   180 // UpdateNewImageL 
   180 // -----------------------------------------------------------------------------
   181 // -----------------------------------------------------------------------------
   181 void CGlxHdmiSurfaceUpdater::UpdateNewImageL(const TDesC& aImageFile, 
   182 void CGlxHdmiSurfaceUpdater::UpdateNewImageL(const TDesC& aImageFile)
   182         TInt aFrameCount,TSize aImageDimensions)
       
   183     {
   183     {
   184     TRACER("CGlxHdmiSurfaceUpdater::UpdateNewImageL()");
   184     TRACER("CGlxHdmiSurfaceUpdater::UpdateNewImageL()");
   185     // First release the contents before proceeding further
   185 	//Cancel the zoom timers if any
       
   186 	if(iTimer->IsActive())
       
   187         {
       
   188 		GLX_LOG_INFO("CGlxHdmiSurfaceUpdater::UpdateNewImageL() - Cancel Timer");
       
   189         iTimer->Cancel();
       
   190         }
       
   191     
       
   192 	iBitmapReady = EFalse;
       
   193 	iLeftCornerForZoom.iX = 0; 
       
   194 	iLeftCornerForZoom.iY = 0;
   186     ReleaseContent();   
   195     ReleaseContent();   
   187     iOrigImageDimensions = aImageDimensions;
       
   188     iFrameCount = aFrameCount;
       
   189 	iBitmapReady = EFalse;
       
   190 	iAnimCount = 0;
       
   191 	
       
   192     CreateImageDecoderL(aImageFile);    
   196     CreateImageDecoderL(aImageFile);    
   193     CreateBitmapAndStartDecodingL();
   197     CreateBitmapL();
   194     CreateHdmiL(EFalse);
   198     CreateHdmiL(EFalse);
   195 #ifdef _DEBUG
   199 #ifdef _DEBUG
   196     iStartTime.HomeTime();
   200     iStartTime.HomeTime();
   197 #endif
   201 #endif
       
   202     //start decoding the image
       
   203     iGlxDecoderAO->ConvertImageL(*iDecodedBitmap,iImageDecoder);
   198     }
   204     }
   199 
   205 
   200 // -----------------------------------------------------------------------------
   206 // -----------------------------------------------------------------------------
   201 // CreateHDMI 
   207 // CreateHDMI 
   202 // -----------------------------------------------------------------------------
   208 // -----------------------------------------------------------------------------
   226     {
   232     {
   227     TRACER("CGlxHdmiSurfaceUpdater::CreateSurfaceL()");
   233     TRACER("CGlxHdmiSurfaceUpdater::CreateSurfaceL()");
   228     TSize surfaceSize = iWindow->Size();   // create surface of the screen size, i.e 1280x720
   234     TSize surfaceSize = iWindow->Size();   // create surface of the screen size, i.e 1280x720
   229     iSurfManager = new(ELeave) RSurfaceManager();
   235     iSurfManager = new(ELeave) RSurfaceManager();
   230     TInt error = iSurfManager->Open();
   236     TInt error = iSurfManager->Open();
   231     if (error != KErrNone)
   237     GLX_LOG_INFO1("CGlxHdmiSurfaceUpdater::CreateSurfaceL Open Surface manager error = %d", error);
   232         {
   238     User::LeaveIfError(error);
   233         GLX_LOG_INFO1("CGlxHdmiSurfaceUpdater::CreateSurfaceL Open Surface manager failed with error = %d", error);
   239     
   234         User::LeaveIfError(error);
       
   235         }
       
   236     RSurfaceManager::TSurfaceCreationAttributesBuf attributes;
   240     RSurfaceManager::TSurfaceCreationAttributesBuf attributes;
   237     attributes().iPixelFormat           = EUidPixelFormatARGB_8888;// EUidPixelFormatYUV_420Planar;
   241     attributes().iPixelFormat           = EUidPixelFormatARGB_8888;// EUidPixelFormatYUV_420Planar;
   238     attributes().iSize                  = surfaceSize;
   242     attributes().iSize                  = surfaceSize;
   239     
   243     
   240     attributes().iBuffers               = 1;
   244     attributes().iBuffers               = 1;
   242     attributes().iAlignment             = KMulFactorToCreateBitmap;
   246     attributes().iAlignment             = KMulFactorToCreateBitmap;
   243     attributes().iContiguous            = EFalse;
   247     attributes().iContiguous            = EFalse;
   244     attributes().iMappable              = ETrue;
   248     attributes().iMappable              = ETrue;
   245         
   249         
   246     error = iSurfManager->CreateSurface(attributes, iSurfId);
   250     error = iSurfManager->CreateSurface(attributes, iSurfId);
   247     if(error)
   251     GLX_LOG_INFO1("CGlxHdmiSurfaceUpdater::CreateSurfaceL, Creating surface error : %d",error);
   248         {
   252     User::LeaveIfError(error);
   249         GLX_LOG_INFO1("CGlxHdmiSurfaceUpdater::CreateSurfaceL, Creating surface failed with error : %d",error);
   253         
   250         User::LeaveIfError(error);
       
   251         }    
       
   252     //Map the surface and stride the surface info
   254     //Map the surface and stride the surface info
   253     MapSurfaceL();
   255     MapSurfaceL();
   254     // Set the Configuration to the surface ID when creating a surface
   256     // Set the Configuration to the surface ID when creating a surface
   255     iConfig.SetSurfaceId(iSurfId);
   257     iConfig.SetSurfaceId(iSurfId);
   256     }
   258     }
   264     
   266     
   265     //Create chunk to map it to the surface ID.
   267     //Create chunk to map it to the surface ID.
   266     iSurfChunk = new(ELeave) RChunk();
   268     iSurfChunk = new(ELeave) RChunk();
   267     User::LeaveIfNull(iSurfChunk);    
   269     User::LeaveIfNull(iSurfChunk);    
   268     TInt error = iSurfManager->MapSurface(iSurfId, *iSurfChunk);
   270     TInt error = iSurfManager->MapSurface(iSurfId, *iSurfChunk);
   269     if(error!=KErrNone)
   271     GLX_LOG_INFO1("CGlxHdmiSurfaceUpdater::MapSurfaceL(), MapSurface error : %d",error);
   270         {
   272     User::LeaveIfError(error);
   271         GLX_LOG_INFO1("CGlxHdmiSurfaceUpdater::CreateSurfaceL(), MapSurface Failed wint error : %d",error);
       
   272         }  
       
   273     
   273     
   274     // Get the info from the surfaceManager
   274     // Get the info from the surfaceManager
   275     // and store pointers to the pixel data
   275     // and store pointers to the pixel data
   276     RSurfaceManager::TInfoBuf info;
   276     RSurfaceManager::TInfoBuf info;
   277     error = iSurfManager->SurfaceInfo(iSurfId, info);    
   277     error = iSurfManager->SurfaceInfo(iSurfId, info);
   278     iSurfaceStride = info().iStride;
   278     GLX_LOG_INFO1("CGlxHdmiSurfaceUpdater::MapSurfaceL(), SurfaceInfo error : %d",error);
   279     User::LeaveIfError(error);  
   279     User::LeaveIfError(error);  
       
   280     
       
   281     iSurfaceStride = info().iStride;    
   280     TInt offset = 0;
   282     TInt offset = 0;
   281     iSurfManager->GetBufferOffset( iSurfId, 0,offset);
   283     iSurfManager->GetBufferOffset( iSurfId, 0,offset);
   282     iSurfBuffer = iSurfChunk->Base()+offset;
   284     iSurfBuffer = iSurfChunk->Base()+offset;
   283     }
   285     }
   284 
   286 
   295 // Refresh 
   297 // Refresh 
   296 // -----------------------------------------------------------------------------
   298 // -----------------------------------------------------------------------------
   297 void CGlxHdmiSurfaceUpdater::Refresh()
   299 void CGlxHdmiSurfaceUpdater::Refresh()
   298     {
   300     {
   299     TRACER("CGlxHdmiSurfaceUpdater::Refresh()");
   301     TRACER("CGlxHdmiSurfaceUpdater::Refresh()");
   300     // Advance animation
       
   301     // if the animation count is becoming maximum [8], then set it to zero, 
       
   302     // such that it can animate again frm begining
       
   303     if (++iAnimCount >= iFrameCount)
       
   304         iAnimCount = 0; 
       
   305     GLX_LOG_INFO1("CGlxHdmiSurfaceUpdater::Refresh() animCOunt = %d",iAnimCount);
       
   306     // copy the decoded bitmap on to the surface
   302     // copy the decoded bitmap on to the surface
   307     SwapBuffers();   
   303     SwapBuffers();   
   308     // Modify the surface position with respect to the buffer size 
   304     // Modify the surface position with respect to the buffer size 
   309 	ModifySurfacePostion();
   305 	ModifySurfacePostion();
   310 	// refresh the window
   306 	// refresh the window
   317 // After this is done, a refresh to the window should be done to refresh the TV
   313 // After this is done, a refresh to the window should be done to refresh the TV
   318 // -----------------------------------------------------------------------------
   314 // -----------------------------------------------------------------------------
   319 void CGlxHdmiSurfaceUpdater::SwapBuffers()
   315 void CGlxHdmiSurfaceUpdater::SwapBuffers()
   320     {
   316     {
   321     TRACER("CGlxHdmiSurfaceUpdater::SwapBuffers()"); 
   317     TRACER("CGlxHdmiSurfaceUpdater::SwapBuffers()"); 
   322     GLX_LOG_INFO1("CGlxHdmiSurfaceUpdater::SwapBuffers() animCOunt = %d",iAnimCount);
   318       
   323     // Lock the heap so that subsequent call to dataaddress doesnt happen
   319     // Lock the heap so that subsequent call to dataaddress doesnt happen
   324     iDecodedBitmap[iAnimCount]->LockHeap();    
   320     iDecodedBitmap->LockHeap();    
   325     
   321     
   326     // Data stride
   322     // Data stride
   327     TUint fs = iDecodedBitmap[iAnimCount]->DataStride();    
   323     TUint fs = iDecodedBitmap->DataStride();    
   328     
   324     
   329     //Bitmap address from where the data has to be copied.
   325     //Bitmap address from where the data has to be copied.
   330     TUint8* from = (TUint8*)iDecodedBitmap[iAnimCount]->DataAddress();
   326     TUint8* from = (TUint8*)iDecodedBitmap->DataAddress();
   331     
   327     
   332     //surface chunk address to where the bitmap data has to be copied.
   328     //surface chunk address to where the bitmap data has to be copied.
   333     TUint8* to = (TUint8*)iSurfBuffer;    
   329     TUint8* to = (TUint8*)iSurfBuffer;    
   334     
   330     
   335     // To buffer (32 bit colors)
   331     // To buffer (32 bit colors)
   336     TUint ts = iSurfaceStride;
   332     TUint ts = iSurfaceStride;
   337     //No of bytes to be copied on to the surface.
   333     //No of bytes to be copied on to the surface.
   338     TUint bytes = iDecodedBitmap[iAnimCount]->SizeInPixels().iWidth * KMulFactorToCreateBitmap;
   334     TUint bytes = iDecodedBitmap->SizeInPixels().iWidth * KMulFactorToCreateBitmap;
   339     
   335     
   340     GLX_LOG_INFO2("CGlxHdmiSurfaceUpdater::SwapBuffers() - decodeSize width = %d and height %d",
   336     GLX_LOG_INFO2("CGlxHdmiSurfaceUpdater::SwapBuffers() - decodeSize width = %d and height %d",
   341             iDecodedBitmap[iAnimCount]->SizeInPixels().iWidth, iDecodedBitmap[iAnimCount]->SizeInPixels().iHeight );
   337             iDecodedBitmap->SizeInPixels().iWidth, iDecodedBitmap->SizeInPixels().iHeight );
   342     
   338     
   343     // Copy the bitmap on to the surface.
   339     // Copy the bitmap on to the surface.
   344     for (TInt y = iDecodedBitmap[iAnimCount]->SizeInPixels().iHeight; y >0; y--)
   340     for (TInt y = iDecodedBitmap->SizeInPixels().iHeight; y >0; y--)
   345         {
   341         {
   346         Mem::Copy(to, from, bytes);        
   342         Mem::Copy(to, from, bytes);        
   347         to += ts;        
   343         to += ts;        
   348         from += fs;        
   344         from += fs;        
   349         }            
   345         }            
   350     iDecodedBitmap[iAnimCount]->UnlockHeap();
   346     iDecodedBitmap->UnlockHeap();
   351     }
   347     }
   352 
   348 
   353 // -----------------------------------------------------------------------------
   349 // -----------------------------------------------------------------------------
   354 // CreateBitmapL 
   350 // CreateBitmapL 
   355 // -----------------------------------------------------------------------------
   351 // -----------------------------------------------------------------------------
   356 void CGlxHdmiSurfaceUpdater::CreateBitmapAndStartDecodingL()
   352 void CGlxHdmiSurfaceUpdater::CreateBitmapL()
   357     {
   353     {
   358     TRACER("CGlxHdmiSurfaceUpdater::CreateBitmapAndStartDecodingL()");
   354     TRACER("CGlxHdmiSurfaceUpdater::CreateBitmapL()");
   359     TSize scrnSize = iWindow->Size();
   355     TSize scrnSize = iWindow->Size();
   360     TSize targetBitmapSize;
   356     TSize targetBitmapSize;
   361     if (iFrameCount>1)
   357     TSize imageSize = iImageDecoder->FrameInfo().iOverallSizeInPixels;
   362         {
   358     GLX_LOG_INFO2("CGlxHdmiSurfaceUpdater::StartImageDecodeL() - bitmapsize=%d, %d",imageSize.iWidth,imageSize.iHeight);
   363         iAnimationTimer = CPeriodic::NewL( CActive::EPriorityLow );
       
   364         }
       
   365 
       
   366 //    if (iFrameCount >1)
       
   367 //        {
       
   368 //        // For Gif images , use the same size of its dimensions, as Image decoder wont decode to different size.
       
   369 //        GLX_LOG_INFO("CGlxHdmiSurfaceUpdater::CreateBitmapAndStartDecodingL() -1");
       
   370 //        targetBitmapSize = iOrigImageDimensions;
       
   371 //        }
       
   372 //    else
       
   373 //        {
       
   374         // for all other images, re calculate the size of the image based on aspect ratio and fit the screen
       
   375         GLX_LOG_INFO("CGlxHdmiSurfaceUpdater::CreateBitmapAndStartDecodingL() -2");
       
   376         GLX_LOG_INFO2("CGlxHdmiSurfaceUpdater::CreateBitmapAndStartDecodingL() - bitmapsize=%d, %d",iOrigImageDimensions.iWidth,iOrigImageDimensions.iHeight);
       
   377     TReal32 scaleFactor = 0.0f;
   359     TReal32 scaleFactor = 0.0f;
   378     if (scrnSize.iWidth * iOrigImageDimensions.iHeight > scrnSize.iHeight
   360     if (scrnSize.iWidth * imageSize.iHeight > scrnSize.iHeight
   379             * iOrigImageDimensions.iWidth)
   361             * imageSize.iWidth)
   380         {
   362         {
   381         scaleFactor = (TReal32) scrnSize.iHeight
   363         scaleFactor = (TReal32) scrnSize.iHeight
   382                 / (TReal32) iOrigImageDimensions.iHeight;
   364                 / (TReal32) imageSize.iHeight;
   383         }
   365         }
   384     else
   366     else
   385         {
   367         {
   386         scaleFactor = (TReal32) scrnSize.iWidth
   368         scaleFactor = (TReal32) scrnSize.iWidth
   387                 / (TReal32) iOrigImageDimensions.iWidth;
   369                 / (TReal32) imageSize.iWidth;
   388         }
   370         }
   389         GLX_LOG_INFO1("CGlxHdmiSurfaceUpdater::CreateBitmapAndStartDecodingL() - scaleFactor=%f",scaleFactor);
   371     GLX_LOG_INFO1("CGlxHdmiSurfaceUpdater::StartImageDecodeL() - scaleFactor=%f",scaleFactor);
   390         targetBitmapSize.iHeight = iOrigImageDimensions.iHeight * scaleFactor;
   372     targetBitmapSize.iHeight = imageSize.iHeight * scaleFactor;
   391         targetBitmapSize.iWidth = iOrigImageDimensions.iWidth * scaleFactor;
   373     targetBitmapSize.iWidth = imageSize.iWidth * scaleFactor;
   392 //        }
   374 
   393     GLX_LOG_INFO2("CGlxHdmiSurfaceUpdater::CreateBitmapAndStartDecodingL() - targetBitmapSize=%d, %d",targetBitmapSize.iWidth,targetBitmapSize.iHeight);
   375     GLX_LOG_INFO2("CGlxHdmiSurfaceUpdater::StartImageDecodeL() - targetBitmapSize=%d, %d",targetBitmapSize.iWidth,targetBitmapSize.iHeight);
   394     //create the bitmap for the required size
   376     //create the bitmap for the required size
   395     iDecodedBitmap[iAnimCount] = new (ELeave) CFbsBitmap();
   377     iDecodedBitmap = new (ELeave) CFbsBitmap();
   396 
   378 
   397     TInt err = iDecodedBitmap[iAnimCount]->Create(targetBitmapSize, EColor16MU);
   379     TInt err = iDecodedBitmap->Create(targetBitmapSize, EColor16MU);
   398     User::LeaveIfNull(iDecodedBitmap[iAnimCount]);
   380     User::LeaveIfNull(iDecodedBitmap);
   399     GLX_LOG_INFO2("CGlxHdmiSurfaceUpdater::CreateBitmapAndStartDecodingL() FrameCOunt = %d, AnimCOunt =%d",iFrameCount, iAnimCount);
       
   400     //start decoding the image
       
   401     iGlxDecoderAO->ConvertImageL(*iDecodedBitmap[iAnimCount],iAnimCount,iImageDecoder);
       
   402     }
   381     }
   403 
   382 
   404 // -----------------------------------------------------------------------------
   383 // -----------------------------------------------------------------------------
   405 // HandleRunL 
   384 // HandleRunL 
   406 // -----------------------------------------------------------------------------
   385 // -----------------------------------------------------------------------------
   407 void CGlxHdmiSurfaceUpdater::HandleRunL(TRequestStatus& aStatus)
   386 void CGlxHdmiSurfaceUpdater::HandleRunL(TRequestStatus& aStatus)
   408     {
   387     {
   409     TRACER("CGlxHdmiSurfaceUpdater::HandleRunL()");
   388     TRACER("CGlxHdmiSurfaceUpdater::HandleRunL()");
   410 
   389 
   411     if (iFrameCount >1 && iAnimCount !=iFrameCount-1)
   390 #ifdef _DEBUG
   412         {
   391     iStopTime.HomeTime();
   413         GLX_LOG_INFO2("CGlxHdmiSurfaceUpdater::HandleRunL() - gif image - iAnimCount= %d,FrameCOunt =%d",iAnimCount,iFrameCount);
   392     GLX_LOG_INFO1("CGlxHdmiSurfaceUpdater::HandleRunL() ConvertImageL took"
   414         while(iAnimCount != iFrameCount-1 && !iGlxDecoderAO->IsActive())
   393             " <%d> us", (TInt)iStopTime.MicroSecondsFrom(iStartTime).Int64());
       
   394 #endif
       
   395     if(aStatus.Int() !=KErrNone)
       
   396         {
       
   397         GLX_LOG_INFO("HandleRunL - Convert failed");
       
   398         ShiftToCloningMode();
       
   399         }
       
   400     else
       
   401         {        
       
   402         iZoomRectSz = iDecodedBitmap->SizeInPixels();
       
   403         if (iSurfBufferAO->iStatus != KRequestPending
       
   404                 && !iSurfBufferAO->IsActive())
   415             {
   405             {
   416             iAnimCount++;
   406             Refresh();
   417             GLX_LOG_INFO1("CGlxHdmiSurfaceUpdater::HandleRunL() - gif image - iAnimCount= %d",iAnimCount);
   407             iSurfBufferAO->iStatus = KRequestPending;
   418             CreateBitmapAndStartDecodingL();
   408             iSurfBufferAO->SetActive();
       
   409             iSurfUpdateSession.NotifyWhenAvailable(iSurfBufferAO->iStatus);
       
   410             TInt err = iSurfUpdateSession.SubmitUpdate(1, iSurfId, 0, NULL);
   419             }
   411             }
   420         }
   412 		iBitmapReady = ETrue;
   421     else
   413         }
   422         {
   414 	//release imagedecoder after the conversion is over		
   423 #ifdef _DEBUG
   415     if(iImageDecoder)
   424         iStopTime.HomeTime();
   416         {
   425         GLX_LOG_INFO1("CGlxHdmiSurfaceUpdater::HandleRunL() ConvertImageL took"
   417         delete iImageDecoder;
   426                 " <%d> us", (TInt)iStopTime.MicroSecondsFrom(iStartTime).Int64());
   418         iImageDecoder = NULL;    
   427 #endif
   419         }
   428         if(aStatus.Int() !=KErrNone)
   420     }
   429             {
   421 
   430             GLX_LOG_INFO1("HandleRunL - Convert failed with error=%d",aStatus.Int());
       
   431             ShiftToCloningMode();
       
   432             }
       
   433         else
       
   434             {
       
   435             iBitmapReady = ETrue;
       
   436             iZoomRectSz = iDecodedBitmap[iAnimCount]->SizeInPixels();
       
   437             ProcessTvImageL();
       
   438             }
       
   439         //release imagedecoder after the conversion is over     
       
   440         if(iImageDecoder)
       
   441             {
       
   442             delete iImageDecoder;
       
   443             iImageDecoder = NULL;    
       
   444             }
       
   445         }
       
   446     }
       
   447 
       
   448 // -----------------------------------------------------------------------------
       
   449 // CreateImageDecoderL 
       
   450 // -----------------------------------------------------------------------------
       
   451 void CGlxHdmiSurfaceUpdater::ProcessTvImageL()
       
   452     {
       
   453     TRACER("CGlxHdmiSurfaceUpdater::ProcessTvImageL()");
       
   454     if (iSurfBufferAO->iStatus != KRequestPending
       
   455             && !iSurfBufferAO->IsActive())
       
   456         {
       
   457         Refresh();
       
   458         iSurfBufferAO->iStatus = KRequestPending;
       
   459         iSurfBufferAO->SetActive();
       
   460         iSurfUpdateSession.NotifyWhenAvailable(iSurfBufferAO->iStatus);
       
   461         TInt err = iSurfUpdateSession.SubmitUpdate(1, iSurfId, 0, NULL);
       
   462         // If the Animation framecount is more that 1, it means this is a gif image, 
       
   463         // start the timer to refresh the TV 
       
   464         if (iFrameCount>1)
       
   465             {
       
   466             GLX_LOG_INFO1("CGlxHdmiSurfaceUpdater::ProcessTvImageL() :Gif Image, ANimCOUnt =%d",iAnimCount);
       
   467             iAnimationTimer->Cancel();   
       
   468 
       
   469             // Next frame
       
   470             iAnimationTimer->Start(KSleepTime, KSleepTime, TCallBack(TimerCallbackL, this));       
       
   471             }
       
   472         }
       
   473     }
       
   474 // -----------------------------------------------------------------------------
   422 // -----------------------------------------------------------------------------
   475 // CreateImageDecoderL 
   423 // CreateImageDecoderL 
   476 // -----------------------------------------------------------------------------
   424 // -----------------------------------------------------------------------------
   477 void CGlxHdmiSurfaceUpdater::CreateImageDecoderL(const TDesC& aImageFile)
   425 void CGlxHdmiSurfaceUpdater::CreateImageDecoderL(const TDesC& aImageFile)
   478     {
   426     {
   479     TRACER("CGlxHdmiController::CreateImageDecoderL()");
   427     TRACER("CGlxHdmiController::CreateImageDecoderL()");
   480      // Create a decoder for the image in the named file
   428      // Create a decoder for the image in the named file
   481     TRAPD(error,iImageDecoder = CImageDecoder::FileNewL(iFsSession, 
   429     TRAPD(error,iImageDecoder = CImageDecoder::FileNewL(iFsSession, 
   482             aImageFile, CImageDecoder::EOptionNone, KNullUid));
   430             aImageFile, CImageDecoder::EOptionNone, KNullUid));
   483     if (error!=KErrNone)
   431     GLX_LOG_INFO1("CreateImageDecoderL CImageDecoder:FileNewL error %d",error);
   484         {
   432     User::LeaveIfError(error);
   485         User::Leave(error);
   433     
   486         }
       
   487     }
   434     }
   488 
   435 
   489 // -----------------------------------------------------------------------------
   436 // -----------------------------------------------------------------------------
   490 // ActivateZoom 
   437 // ActivateZoom 
   491 // -----------------------------------------------------------------------------
   438 // -----------------------------------------------------------------------------
   492 void CGlxHdmiSurfaceUpdater::ActivateZoom()
   439 void CGlxHdmiSurfaceUpdater::ActivateZoom(TBool aAutoZoomOut)
   493     {
   440     {
   494     TRACER("CGlxHdmiSurfaceUpdater::ActivateZoom()");
   441     TRACER("CGlxHdmiSurfaceUpdater::ActivateZoom()");
   495     iZoom = ETrue;
   442     iZoom = ETrue;
   496     if (!(iFrameCount >1))
   443     iAutoZoomOut = aAutoZoomOut;
   497         {
   444     if(iTimer->IsActive())
   498         if(!iTimer->IsActive() && iBitmapReady)
   445         {
   499            {
   446 		GLX_LOG_INFO("CGlxHdmiSurfaceUpdater::ActivateZoom() - Cancel Timer");
   500            iTimer->Start(KZoomDelay,KZoomDelay,TCallBack( TimeOut,this ));
   447         iTimer->Cancel();
   501            }
   448         }
   502         }
   449     
       
   450     if(!iTimer->IsActive() && iBitmapReady)
       
   451        {
       
   452 	   GLX_LOG_INFO("CGlxHdmiSurfaceUpdater::ActivateZoom() - Start Timer");
       
   453        iTimer->Start(KZoomDelay,KZoomDelay,TCallBack( TimeOut,this ));
       
   454        }
   503     }
   455     }
   504 
   456 
   505 // -----------------------------------------------------------------------------
   457 // -----------------------------------------------------------------------------
   506 // DeactivateZoom 
   458 // DeactivateZoom 
   507 // -----------------------------------------------------------------------------
   459 // -----------------------------------------------------------------------------
   508 void CGlxHdmiSurfaceUpdater::DeactivateZoom()
   460 void CGlxHdmiSurfaceUpdater::DeactivateZoom()
   509     {
   461     {
   510     TRACER("CGlxHdmiSurfaceUpdater::DeactivateZoom()");
   462     TRACER("CGlxHdmiSurfaceUpdater::DeactivateZoom()");
   511     if(iDecodedBitmap[iAnimCount] && !(iFrameCount >1))
   463     
   512         {
   464     if(iTimer->IsActive())
   513         TSize bitmapsize = iDecodedBitmap[iAnimCount]->SizeInPixels(); 
   465         {
   514         iConfig.SetViewport(TRect(0,0,bitmapsize.iWidth,bitmapsize.iHeight));
   466 		GLX_LOG_INFO("CGlxHdmiSurfaceUpdater::DeactivateZoom() - Cancel Timer");
   515         iConfig.SetExtent(TRect(0,0,bitmapsize.iWidth,bitmapsize.iHeight));
   467         iTimer->Cancel();
   516         iWindow->SetBackgroundSurface(iConfig, ETrue);
   468         }
   517         }
   469     if(!iTimer->IsActive() && iBitmapReady && iLeftCornerForZoom.iX)
       
   470        {
       
   471 	   GLX_LOG_INFO("CGlxHdmiSurfaceUpdater::DeactivateZoom() - Start Timer");
       
   472 	   iZoom = EFalse;
       
   473        iTimer->Start(KZoomDelay,KZoomDelay,TCallBack( TimeOut,this ));
       
   474        }
   518     }
   475     }
   519 
   476 
   520 // ---------------------------------------------------------------------------
   477 // ---------------------------------------------------------------------------
   521 // TimeOut
   478 // TimeOut
   522 // ---------------------------------------------------------------------------
   479 // ---------------------------------------------------------------------------
   534         }
   491         }
   535     return KErrNone;
   492     return KErrNone;
   536     }
   493     }
   537 
   494 
   538 // -----------------------------------------------------------------------------
   495 // -----------------------------------------------------------------------------
   539 // TimerCallbackL 
       
   540 // -----------------------------------------------------------------------------
       
   541 TInt CGlxHdmiSurfaceUpdater::TimerCallbackL(TAny* aThis)
       
   542     {
       
   543     TRACER("CGlxHdmiSurfaceUpdater::TimerCallbackL()");
       
   544     static_cast<CGlxHdmiSurfaceUpdater*>(aThis)->ProcessTimerEventL();
       
   545     return NULL;
       
   546     }
       
   547 
       
   548 // -----------------------------------------------------------------------------
       
   549 // ProcessTimerEventL 
       
   550 // -----------------------------------------------------------------------------
       
   551 void CGlxHdmiSurfaceUpdater::ProcessTimerEventL()
       
   552     {
       
   553     TRACER("CGlxHdmiSurfaceUpdater::ProcessTimerEventL()");
       
   554     ProcessTvImageL();
       
   555     }
       
   556 
       
   557 // -----------------------------------------------------------------------------
       
   558 // Zoom 
   496 // Zoom 
   559 // -----------------------------------------------------------------------------
   497 // -----------------------------------------------------------------------------
   560 void CGlxHdmiSurfaceUpdater::Zoom(TBool aZoom)
   498 void CGlxHdmiSurfaceUpdater::Zoom(TBool aZoom)
   561     {
   499     {
   562     TRACER("CGlxHdmiSurfaceUpdater::Zoom()");
   500     TRACER("CGlxHdmiSurfaceUpdater::Zoom()");
       
   501 	
       
   502 	if(!iBitmapReady)
       
   503 		{
       
   504 		return;
       
   505 		}
       
   506 		
   563     if(iLeftCornerForZoom.iX == KMaxZoomLimit)
   507     if(iLeftCornerForZoom.iX == KMaxZoomLimit)
   564         {
   508         {
   565         iZoom = EFalse;
   509         iZoom = EFalse;
       
   510         //If autozoomout is not set then cancel the timer and do
       
   511         //the zoom out on DeactivateZoom.
       
   512         if(!iAutoZoomOut)
       
   513             {
       
   514             iTimer->Cancel();			
       
   515             }
   566         }    
   516         }    
   567     if(aZoom && iZoom)
   517     if(aZoom && iZoom)
   568         {
   518         {
   569         iZoomRectSz.iWidth = TInt(iZoomRectSz.iWidth-KSingleStepForZoom);
   519         iZoomRectSz.iWidth = TInt(iZoomRectSz.iWidth-KSingleStepForZoom);
   570         iZoomRectSz.iHeight = TInt(iZoomRectSz.iHeight-KSingleStepForZoom);
   520         iZoomRectSz.iHeight = TInt(iZoomRectSz.iHeight-KSingleStepForZoom);
   596 // ModifySurfacePostion 
   546 // ModifySurfacePostion 
   597 // -----------------------------------------------------------------------------
   547 // -----------------------------------------------------------------------------
   598 void CGlxHdmiSurfaceUpdater::ModifySurfacePostion()
   548 void CGlxHdmiSurfaceUpdater::ModifySurfacePostion()
   599 	{
   549 	{
   600 	TRACER("CGlxHdmiSurfaceUpdater::ModifySurfacePostion()");
   550 	TRACER("CGlxHdmiSurfaceUpdater::ModifySurfacePostion()");
   601 	TSize bitmapSize = iDecodedBitmap[iAnimCount]->SizeInPixels();
   551 	TSize bitmapSize = iDecodedBitmap->SizeInPixels();
   602 	TPoint startPoint(0,0);
   552 	TPoint startPoint(0,0);
   603 	if (bitmapSize.iWidth <KHdTvWidth)
   553 	if (bitmapSize.iWidth <KHdTvWidth)
   604 	    {
   554 	    {
   605 	    startPoint.iX = (KHdTvWidth - bitmapSize.iWidth)/2; 
   555 	    startPoint.iX = (KHdTvWidth - bitmapSize.iWidth)/2; 
   606 	    }
   556 	    }