photosgallery/viewframework/texturemanager/src/glxbitmapdecoderwrapper.cpp
branchRCL_3
changeset 75 01504893d9cb
parent 60 5b3385a43d68
equal deleted inserted replaced
68:5b238bc8ffb6 75:01504893d9cb
    39 
    39 
    40     // Photos low_ram_threshold [8.637 MB] as in oomconfig.xml
    40     // Photos low_ram_threshold [8.637 MB] as in oomconfig.xml
    41     const TInt KGlxCriticalRAMForPhotos = 9056550;
    41     const TInt KGlxCriticalRAMForPhotos = 9056550;
    42     const TInt KGlxDecodeBitmapFactor = 3;
    42     const TInt KGlxDecodeBitmapFactor = 3;
    43     
    43     
    44     _LIT(KMimeJpeg,"image/jpeg");
       
    45     _LIT(KMimeJpg,"image/jpg");
       
    46     }
    44     }
    47 
    45 
    48 // ---------------------------------------------------------------------------
    46 // ---------------------------------------------------------------------------
    49 // Two-phased constructor.
    47 // Two-phased constructor.
    50 // ---------------------------------------------------------------------------
    48 // ---------------------------------------------------------------------------
    62 
    60 
    63 // ---------------------------------------------------------------------------
    61 // ---------------------------------------------------------------------------
    64 // Constructor
    62 // Constructor
    65 // ---------------------------------------------------------------------------
    63 // ---------------------------------------------------------------------------
    66 //
    64 //
    67 CGlxBitmapDecoderWrapper::CGlxBitmapDecoderWrapper() :
    65 CGlxBitmapDecoderWrapper::CGlxBitmapDecoderWrapper()
    68     CActive(EPriorityLow)
       
    69     {
    66     {
    70     TRACER("CGlxBitmapDecoderWrapper::CGlxBitmapDecoderWrapper()");
    67     TRACER("CGlxBitmapDecoderWrapper::CGlxBitmapDecoderWrapper()");
    71     }		
    68     }		
    72 
    69 
    73 // ---------------------------------------------------------------------------
    70 // ---------------------------------------------------------------------------
    75 // ---------------------------------------------------------------------------
    72 // ---------------------------------------------------------------------------
    76 //
    73 //
    77 CGlxBitmapDecoderWrapper::~CGlxBitmapDecoderWrapper()
    74 CGlxBitmapDecoderWrapper::~CGlxBitmapDecoderWrapper()
    78     {
    75     {
    79     TRACER("CGlxBitmapDecoderWrapper::~CGlxBitmapDecoderWrapper()");
    76     TRACER("CGlxBitmapDecoderWrapper::~CGlxBitmapDecoderWrapper()");
    80     iFs.Close();
    77     if (iTnManager)
    81     Cancel();
    78         {
    82     if (iImageDecoder)
    79         iTnManager->CancelRequest(iTnReqId);
    83         {
    80         delete iTnManager;
    84         delete iImageDecoder;
    81         iTnManager = NULL;
    85         iImageDecoder = NULL;
    82         }
       
    83     if(iBitmap)
       
    84         {
       
    85         delete iBitmap;
       
    86         iBitmap = NULL;
    86         }
    87         }
    87     if (iImagePath)
    88     if (iImagePath)
    88         {
    89         {
    89         delete iImagePath;
    90         delete iImagePath;
    90         iImagePath = NULL;
    91         iImagePath = NULL;
    96 // ---------------------------------------------------------------------------
    97 // ---------------------------------------------------------------------------
    97 void CGlxBitmapDecoderWrapper::ConstructL(MGlxBitmapDecoderObserver* aObserver)
    98 void CGlxBitmapDecoderWrapper::ConstructL(MGlxBitmapDecoderObserver* aObserver)
    98     {
    99     {
    99     TRACER("CGlxBitmapDecoderWrapper::ConstructL ");
   100     TRACER("CGlxBitmapDecoderWrapper::ConstructL ");
   100     iObserver = aObserver;
   101     iObserver = aObserver;
   101     User::LeaveIfError(iFs.Connect());
       
   102     CActiveScheduler::Add( this );
       
   103     }
   102     }
   104 
   103 
   105 // ---------------------------------------------------------------------------
   104 // ---------------------------------------------------------------------------
   106 // DoDecodeImageL
   105 // DoDecodeImageL
   107 // ---------------------------------------------------------------------------		
   106 // ---------------------------------------------------------------------------		
   108 void CGlxBitmapDecoderWrapper::DoDecodeImageL(const TDesC& aSourceFileName,
   107 void CGlxBitmapDecoderWrapper::DoDecodeImageL(const TGlxMedia& aMedia,
   109         TInt aIndex)
   108         TInt aIndex)
   110     {
   109     {
   111     TRACER("CGlxBitmapDecoderWrapper::DoDecodeImageL()");
   110     TRACER("CGlxBitmapDecoderWrapper::DoDecodeImageL()");
   112     GLX_LOG_URI("CGlxBitmapDecoderWrapper::DoDecodeImageL(%S)",
       
   113             &aSourceFileName);
       
   114 
   111 
   115     iThumbnailIndex = aIndex;
   112     iThumbnailIndex = aIndex;
   116 
   113     TSize originalDim;
   117 #ifdef _DEBUG
   114     aMedia.GetDimensions(originalDim);
   118     iStartTime.HomeTime();
   115     iOriginalSize.iWidth = originalDim.iWidth;
   119 #endif                          
   116     iOriginalSize.iHeight = originalDim.iHeight;
   120 
   117 
   121     if (iImageDecoder)
       
   122         {
       
   123         delete iImageDecoder;
       
   124         iImageDecoder = NULL;
       
   125         }
       
   126 
       
   127     CImageDecoder::TOptions options =
       
   128             (CImageDecoder::TOptions) (CImageDecoder::EOptionNoDither
       
   129                     | CImageDecoder::EOptionAlwaysThread);
       
   130 
       
   131     // Use extended JPEG decoder
       
   132     GLX_DEBUG1("DoDecodeImageL:: EHwImplementation" );
       
   133     TRAPD( err, iImageDecoder = CExtJpegDecoder::FileNewL(
       
   134                     CExtJpegDecoder::EHwImplementation, iFs,
       
   135                     aSourceFileName, options ) );
       
   136     GLX_DEBUG2("DoDecodeImageL:: EHwImplementation (%d)", err);
       
   137     if (KErrNone != err)
       
   138         {
       
   139         TRAP(err,iImageDecoder = CExtJpegDecoder::FileNewL(
       
   140                         CExtJpegDecoder::ESwImplementation, iFs,
       
   141                         aSourceFileName, options ) );
       
   142         GLX_DEBUG2("DoDecodeImageL:: ESwImplementation (%d)", err);
       
   143         if (KErrNone != err)
       
   144             {
       
   145             GLX_DEBUG1("DoDecodeImageL::CImageDecoder");
       
   146             // Not a JPEG - use standard decoder
       
   147             iImageDecoder = CImageDecoder::FileNewL(iFs, aSourceFileName,
       
   148                     options);
       
   149             }
       
   150         }
       
   151 #ifdef _DEBUG
       
   152     iStopTime.HomeTime();
       
   153     GLX_DEBUG2("*** Decoder Creation took <%d> us ***",
       
   154             (TInt)iStopTime.MicroSecondsFrom(iStartTime).Int64());
       
   155 #endif                          
       
   156 
       
   157     TSize imageSize = iImageDecoder->FrameInfo().iOverallSizeInPixels;
       
   158     GLX_DEBUG3("GlxDecoderWrapper::DecodeImageL() - OverallSize: w=%d, h=%d",
       
   159             imageSize.iWidth, imageSize.iHeight);
       
   160     iOriginalSize.iWidth = imageSize.iWidth;
       
   161     iOriginalSize.iHeight = imageSize.iHeight;
       
   162 
       
   163     if (iBitmap)
       
   164         {
       
   165         delete iBitmap;
       
   166         iBitmap = NULL;
       
   167         }
       
   168     
       
   169     if (iImagePath)
   118     if (iImagePath)
   170         {
   119         {
   171         delete iImagePath;
   120         delete iImagePath;
   172         iImagePath = NULL;
   121         iImagePath = NULL;
   173         }
   122         }
   174     iImagePath = aSourceFileName.Alloc();
   123 
       
   124     const TDesC& uri = aMedia.Uri();
       
   125     GLX_LOG_URI("CGlxBitmapDecoderWrapper::DoDecodeImageL(%S)", &uri);
       
   126     iImagePath = uri.Alloc();
   175     
   127     
   176     DecodeImageL();
   128     DecodeImageL();
   177     }
   129     }
   178 
   130 
   179 // ---------------------------------------------------------------------------
   131 // ---------------------------------------------------------------------------
   227         __ASSERT_DEBUG(width > 0 && height > 0, Panic(EGlxPanicIllegalArgument));      
   179         __ASSERT_DEBUG(width > 0 && height > 0, Panic(EGlxPanicIllegalArgument));      
   228 
   180 
   229         if (minmemorytodecode < (freeMemory - KGlxCriticalRAMForPhotos))
   181         if (minmemorytodecode < (freeMemory - KGlxCriticalRAMForPhotos))
   230             {
   182             {
   231             GLX_DEBUG1("DecodeImageL:RAM available decoding image");            
   183             GLX_DEBUG1("DecodeImageL:RAM available decoding image");            
   232             iBitmap = new (ELeave) CFbsBitmap();
   184              
   233             iBitmap->Create(ReCalculateSizeL(),
   185             GetThumbnailL(iImagePath);
   234                     iImageDecoder->FrameInfo().iFrameDisplayMode);
       
   235 #ifdef _DEBUG
       
   236             iStartTime.HomeTime(); // Get home time
       
   237 #endif                          
       
   238             iImageDecoder->Convert(&iStatus, *iBitmap);
       
   239             }
   186             }
   240         else
   187         else
   241             {
   188             {
   242             //case when sufficient memory is not available
   189             //case when sufficient memory is not available
   243             //request OOM FW to release the required memory
   190             //request OOM FW to release the required memory
   255                 err = OOMRequestFreeMemoryL(minmemorytodecode);
   202                 err = OOMRequestFreeMemoryL(minmemorytodecode);
   256                 }
   203                 }
   257             if (err != KErrNoMemory)
   204             if (err != KErrNoMemory)
   258                 {
   205                 {
   259                 GLX_DEBUG1("DecodeImageL:Sufficient RAM available");                
   206                 GLX_DEBUG1("DecodeImageL:Sufficient RAM available");                
   260                 iBitmap = new (ELeave) CFbsBitmap();
   207                 GetThumbnailL(iImagePath);
   261                 iBitmap->Create(ReCalculateSizeL(),
       
   262                         iImageDecoder->FrameInfo().iFrameDisplayMode);
       
   263 #ifdef _DEBUG
       
   264                 iStartTime.HomeTime(); // Get home time
       
   265 #endif                          
       
   266                 iImageDecoder->Convert(&iStatus, *iBitmap);
       
   267                 }
   208                 }
   268             else
   209             else
   269                 {
   210                 {
   270                 GLX_DEBUG1("NOT ENOUGH MEMORY - "
   211                 GLX_DEBUG1("NOT ENOUGH MEMORY - "
   271                         "Using the Fullscreen Thumbnail For Zoom");
   212                         "Using the Fullscreen Thumbnail For Zoom");
   272                 //release the file held by decoder immediately.
       
   273                 iImageDecoder->Cancel();
       
   274                 delete iImageDecoder;
       
   275                 iImageDecoder = NULL;
       
   276                 //Inform the client that there is no decode happened and there we take care 
   213                 //Inform the client that there is no decode happened and there we take care 
   277                 //of showing the fullscreen thumbnail.
   214                 //of showing the fullscreen thumbnail.
   278                 iObserver->HandleBitmapDecodedL(iThumbnailIndex, NULL);
   215                 iObserver->HandleBitmapDecodedL(iThumbnailIndex, NULL);
   279                 return;
   216                 return;
   280                 }
   217                 }
   281             }
   218             }
   282 
       
   283         SetActive();
       
   284         }
       
   285     }
       
   286 
       
   287 // ---------------------------------------------------------------------------
       
   288 // RunL
       
   289 // ---------------------------------------------------------------------------
       
   290 //
       
   291 void CGlxBitmapDecoderWrapper::RunL()
       
   292     {
       
   293     TRACER("CGlxBitmapDecoderWrapper::RunL()");
       
   294     if( iStatus == KErrNone )
       
   295         {
       
   296         iObserver->HandleBitmapDecodedL(iThumbnailIndex,iBitmap);
       
   297         iBitmap = NULL;
       
   298 
       
   299         //release the file held by decoder immediately.
       
   300         GLX_DEBUG1("CGlxBitmapDecoderWrapper::RunL:Decoding Finished");
       
   301         iImageDecoder->Cancel();
       
   302         delete iImageDecoder;
       
   303         iImageDecoder = NULL;
       
   304 #ifdef _DEBUG
       
   305         iStopTime.HomeTime();
       
   306         GLX_DEBUG2("*** Image Decode took <%d> us ***", 
       
   307                        (TInt)iStopTime.MicroSecondsFrom(iStartTime).Int64());            
       
   308 #endif                          
       
   309 
       
   310         }
       
   311     }
       
   312 
       
   313 // ---------------------------------------------------------------------------
       
   314 // DoCancel
       
   315 // ---------------------------------------------------------------------------
       
   316 //
       
   317 void CGlxBitmapDecoderWrapper::DoCancel()
       
   318     {
       
   319     TRACER("CGlxBitmapDecoderWrapper::DoCancel ");
       
   320     if(iImageDecoder)
       
   321         {
       
   322         GLX_DEBUG1("CGlxBitmapDecoderWrapper::DoCancel iImageDecoder delete");
       
   323         iImageDecoder->Cancel();
       
   324         delete iImageDecoder;
       
   325         iImageDecoder = NULL;
       
   326         }
       
   327     if(iBitmap)
       
   328         {
       
   329         delete iBitmap;
       
   330         iBitmap = NULL;
       
   331         }
   219         }
   332     }
   220     }
   333 
   221 
   334 // ---------------------------------------------------------------------------
   222 // ---------------------------------------------------------------------------
   335 // OOMRequestFreeMemoryL
   223 // OOMRequestFreeMemoryL
   357     oomMonitor.Close();
   245     oomMonitor.Close();
   358     return errorCode;
   246     return errorCode;
   359     }
   247     }
   360 
   248 
   361 // -----------------------------------------------------------------------------
   249 // -----------------------------------------------------------------------------
   362 // DoesMimeTypeNeedsRecalculateL()
   250 // CGlxBitmapDecoderWrapper::GetThumbnailL()
   363 // -----------------------------------------------------------------------------
   251 // -----------------------------------------------------------------------------
   364 //
   252 //
   365 TBool CGlxBitmapDecoderWrapper::DoesMimeTypeNeedsRecalculateL()
   253 void CGlxBitmapDecoderWrapper::GetThumbnailL( HBufC* aImagePath )
   366     {
   254     {
   367     TRACER("CGlxBitmapDecoderWrapper::DoesMimeTypeNeedsRecalculateL");
   255     TRACER("CGlxBitmapDecoderWrapper::GetThumbnailL");
   368     RApaLsSession session;
   256     if (!iTnManager)
   369     TDataType mimeType;
   257         {
   370     TUid uid;
   258         iTnManager = CThumbnailManager::NewL(*this);
   371 
   259         iTnManager->SetDisplayModeL(EColor16M);
   372     User::LeaveIfError(session.Connect());
   260         }
   373     CleanupClosePushL(session);
   261 
   374     User::LeaveIfError(session.AppForDocument(iImagePath->Des(), uid,
   262     iTnManager->SetFlagsL(CThumbnailManager::EDefaultFlags);
   375             mimeType));
   263     iTnManager->SetThumbnailSizeL(iTargetBitmapSize);
   376     CleanupStack::PopAndDestroy(&session);
   264     iTnManager->SetQualityPreferenceL(CThumbnailManager::EOptimizeForQuality);
   377 
   265     const TDesC& uri = aImagePath->Des();
   378     if (mimeType.Des().Compare(KMimeJpeg) == 0 || mimeType.Des().Compare(
   266     GLX_LOG_URI("CGlxBitmapDecoderWrapper::GetThumbnailL: (%S)", aImagePath );
   379             KMimeJpg) == 0)
   267     CThumbnailObjectSource* source = CThumbnailObjectSource::NewLC(uri, 0);
   380         {
   268 #ifdef _DEBUG
   381         GLX_LOG_INFO("CGlxBitmapDecoderWrapper::DoesMimeTypeNeedsRecalculateL - jpeg");
   269     iStartTime.HomeTime(); // Get home time
   382         return EFalse;
   270 #endif                          
   383         }
   271     iTnReqId = iTnManager->GetThumbnailL(*source);
   384     else
   272     CleanupStack::PopAndDestroy(source);
   385         {
   273     }
   386         GLX_LOG_INFO("CGlxHdmiSurfaceUpdater::DoesMimeTypeNeedsRecalculateL - non jpeg");
   274 
   387         return ETrue;
   275 // -----------------------------------------------------------------------------
   388         }
   276 // CGlxBitmapDecoderWrapper::ThumbnailPreviewReady
   389     }
   277 // From MThumbnailManagerObserver
   390 
   278 // -----------------------------------------------------------------------------
   391 // -----------------------------------------------------------------------------
   279 //
   392 // ReCalculateSize 
   280 void CGlxBitmapDecoderWrapper::ThumbnailPreviewReady( MThumbnailData& /*aThumbnail*/, 
   393 // -----------------------------------------------------------------------------
   281                             TThumbnailRequestId /*aId*/ )
   394 TSize CGlxBitmapDecoderWrapper::ReCalculateSizeL()
   282     {
   395     {
   283     TRACER("CGlxBitmapDecoderWrapper::ThumbnailPreviewReady");    
   396     TRACER("CGlxBitmapDecoderWrapper::ReCalculateSizeL()");
   284     }
   397     if (DoesMimeTypeNeedsRecalculateL())
   285 
   398         {
   286 // -----------------------------------------------------------------------------
   399         TSize fullFrameSize = iImageDecoder->FrameInfo().iOverallSizeInPixels;
   287 // CGlxBitmapDecoderWrapper::ThumbnailReady
   400         // calculate the reduction factor on what size we need
   288 // From MThumbnailManagerObserver
   401         TInt reductionFactor = iImageDecoder->ReductionFactor(fullFrameSize,
   289 // -----------------------------------------------------------------------------
   402                 iTargetBitmapSize);
   290 //                            
   403         // get the reduced size onto destination size
   291 void CGlxBitmapDecoderWrapper::ThumbnailReady( TInt aError, 
   404         TSize destSize;
   292                      MThumbnailData& aThumbnail, 
   405         User::LeaveIfError(iImageDecoder->ReducedSize(fullFrameSize,
   293                      TThumbnailRequestId /*aId*/ )
   406                 reductionFactor, destSize));
   294     {
   407         GLX_LOG_INFO2("CGlxBitmapDecoderWrapper::ReCalculateSizeL() "
   295     TRACER("CGlxBitmapDecoderWrapper::ThumbnailReady");
   408                         "destSize=%d, %d",destSize.iWidth,destSize.iHeight);
   296 #ifdef _DEBUG
   409         return destSize;
   297     iStopTime.HomeTime();
   410         }
   298     GLX_DEBUG2("*** CGlxBitmapDecoderWrapper::ThumbnailReady() TNM took <%d> us to decode***",
   411     else
   299             (TInt)iStopTime.MicroSecondsFrom(iStartTime).Int64());
   412         {
   300 #endif                          
   413         return iTargetBitmapSize;
   301 
   414         }
   302     if (aError == KErrNone)
   415     }
   303         {
       
   304         if (iBitmap)
       
   305             {
       
   306             delete iBitmap;
       
   307             iBitmap = NULL;
       
   308             }
       
   309         iBitmap = aThumbnail.DetachBitmap();
       
   310         iObserver->HandleBitmapDecodedL(iThumbnailIndex, iBitmap);
       
   311         iBitmap = NULL;
       
   312 		}
       
   313     }
       
   314 
       
   315 // -----------------------------------------------------------------------------
       
   316 // CGlxBitmapDecoderWrapper::CancelRequest()
       
   317 // Cancels all the pending requests and release resources
       
   318 // -----------------------------------------------------------------------------
       
   319 //
       
   320 void CGlxBitmapDecoderWrapper::CancelRequest()
       
   321     {
       
   322     TRACER("CGlxBitmapDecoderWrapper::CancelRequest");
       
   323     if (iTnManager)
       
   324         {
       
   325         iTnManager->CancelRequest(iTnReqId);
       
   326         delete iTnManager;
       
   327         iTnManager = NULL;
       
   328         }
       
   329 
       
   330     if (iBitmap)
       
   331         {
       
   332         delete iBitmap;
       
   333         iBitmap = NULL;
       
   334         }
       
   335     }