void CRecognizerContainer::ViewFinderStartStop() { CALLSTACKITEM_N(_CL("CRecognizerContainer"), _CL("ViewFinderStartStop")); Reporting().DebugLog(_L("ViewFinderStartStop")); started=true; if (!iVCS || !iTakingPicture) { delete iVCS; iVCS=0; iBitmap=0; iVCS=new (ELeave) CVisualCodeSystem(AppContext()); iVCS->ConstructL(); iVCS->AddObserver(this); } if (iTakingPicture) { if (iBitmap) { CFbsBitmap* temp=iBitmap; iBitmap=new (ELeave) CFbsBitmap; owns_bitmap=true; User::LeaveIfError(iBitmap->Duplicate(temp->Handle())); } delete iVCS; iVCS=0; iTakingPicture=FALSE; } else { iTakingPicture = TRUE; // start with: updates on, translation off, rotation off, low-quality recognition on iVCS->Start(TRUE, FALSE, FALSE, TRUE); } }
void CMMABitmapWindow::SetDestinationBitmapL(CFbsBitmap* aBitmap) { CFbsBitmap* bitmap = new(ELeave)CFbsBitmap(); CleanupStack::PushL(bitmap); User::LeaveIfError(bitmap->Duplicate(aBitmap->Handle())); // create context for bitmap CFbsBitmapDevice* bitmapDevice = CFbsBitmapDevice::NewL(aBitmap); CleanupStack::PushL(bitmapDevice); CGraphicsContext* bitmapContext = NULL; User::LeaveIfError(bitmapDevice->CreateContext(bitmapContext)); CleanupStack::Pop(bitmapDevice); // bitmapDevice CleanupStack::Pop(bitmap); // bitmap delete iBitmap; iBitmap = bitmap; delete iBitmapDevice; iBitmapDevice = bitmapDevice; delete iBitmapContext; iBitmapContext = bitmapContext; if (iDrawRect.IsEmpty()) { iDrawRect.SetSize(iBitmap->SizeInPixels()); } }
void CMMABitmapWindow::DrawFrameL(const CFbsBitmap* aBitmap) { if (iBitmap) { // leave in this function will panic thread CFbsBitmap* bitmap = new(ELeave)CFbsBitmap(); CleanupStack::PushL(bitmap); User::LeaveIfError(bitmap->Duplicate(aBitmap->Handle())); // set incoming bitmap display mode to 16MA if (EColor16MU == bitmap->DisplayMode()) { bitmap->SetDisplayMode(EColor16MA); } AknIconUtils::ScaleBitmapL(iDrawRect, iBitmap, bitmap); CleanupStack::PopAndDestroy(bitmap); } }
/** @SYMTestCaseID GRAPHICS-FBSERV-0512 @SYMTestCaseDesc Creates bitmaps in different ways and checks if memory allocation succeeded @SYMTestActions Creates normal size bitmaps, large bitmaps, loads bitmaps, loads shared bitmaps, duplicated bitmaps, resizes bitmaps, compresses bitmaps, externalized bitmaps to write store, internalizes bitmaps back again from write store. All ways of creating bitmaps are tested against Out Of Memory error conditions @SYMTestExpectedResults Test should pass */ void CTAlloc::BitmapsL() { TInt heapMarkCheckFlag; if( !iStep->GetIntFromConfig(KDefaultSectionName, KFbsHeapMarkCheckFlag, heapMarkCheckFlag) ) { INFO_PRINTF1(_L("Error reading ini file")); User::Leave(KErrNotFound); } CFbsBitmap iBitmap; CFbsBitmap iBitmap2; iTestBitmapName = KTestBitmapOnZ; TInt ret = iBitmap.Load(iTestBitmapName,ETfbs,NULL); TEST2(ret, KErrNone); ret = iBitmap.Create(KLargeSize,EColor256); // Expand server caches TEST2(ret, KErrNone); iBitmap.Reset(); TInt count; // Create bitmap INFO_PRINTF1(_L("CFbsBitmap::Create()\r\n")); for (count = 1; ; count++) { iFbs->SendCommand(EFbsMessDefaultAllocFail,count); if(heapMarkCheckFlag) { iFbs->SendCommand(EFbsMessDefaultMark); iFbs->SendCommand(EFbsMessUserMark); } ret = iBitmap.Create(KSmallSize,EColor256); if (ret == KErrNoMemory) { if(heapMarkCheckFlag) { iFbs->SendCommand(EFbsMessDefaultMark); iFbs->SendCommand(EFbsMessUserMark); } } else if (ret == KErrNone) { iBitmap.Reset(); if(heapMarkCheckFlag) { iFbs->SendCommand(EFbsMessDefaultMark); iFbs->SendCommand(EFbsMessUserMark); } break; } else TEST2(ret, KErrNone); } iFbs->SendCommand(EFbsMessDefaultAllocFail,0); iFbs->SendCommand(EFbsMessUserAllocFail,0); TEST(iFbs->ResourceCount()==0); for (count = 1; ; count++) { iFbs->SendCommand(EFbsMessUserAllocFail,count); if(heapMarkCheckFlag) { iFbs->SendCommand(EFbsMessDefaultMark); iFbs->SendCommand(EFbsMessUserMark); } ret=iBitmap.Create(KSmallSize,EGray2); if (ret == KErrNoMemory) { if(heapMarkCheckFlag) { iFbs->SendCommand(EFbsMessDefaultMarkEnd); iFbs->SendCommand(EFbsMessUserMarkEnd); } } else if (ret == KErrNone) { iBitmap.Reset(); if(heapMarkCheckFlag) { iFbs->SendCommand(EFbsMessDefaultMarkEnd); iFbs->SendCommand(EFbsMessUserMarkEnd); } break; } else TEST2(ret, KErrNone); } iFbs->SendCommand(EFbsMessDefaultAllocFail,0); iFbs->SendCommand(EFbsMessUserAllocFail,0); TEST(iFbs->ResourceCount()==0); // Create (large) for (count = 1; ; count++) { iFbs->SendCommand(EFbsMessDefaultAllocFail,count); if(heapMarkCheckFlag) { iFbs->SendCommand(EFbsMessDefaultMark); iFbs->SendCommand(EFbsMessUserMark); } ret = iBitmap.Create(KLargeSize,EColor256); if (ret == KErrNoMemory) { if(heapMarkCheckFlag) { iFbs->SendCommand(EFbsMessDefaultMarkEnd); iFbs->SendCommand(EFbsMessUserMarkEnd); } } else if (ret == KErrNone) { iBitmap.Reset(); if(heapMarkCheckFlag) { iFbs->SendCommand(EFbsMessDefaultMarkEnd); iFbs->SendCommand(EFbsMessUserMarkEnd); } break; } else TEST2(ret, KErrNone); } iFbs->SendCommand(EFbsMessDefaultAllocFail,0); iFbs->SendCommand(EFbsMessUserAllocFail,0); TEST(iFbs->ResourceCount()==0); for (count = 1; ; count++) { iFbs->SendCommand(EFbsMessUserAllocFail,count); if(heapMarkCheckFlag) { iFbs->SendCommand(EFbsMessDefaultMark); iFbs->SendCommand(EFbsMessUserMark); } ret = iBitmap.Create(KLargeSize,EColor256); if (ret == KErrNoMemory) { if(heapMarkCheckFlag) { iFbs->SendCommand(EFbsMessDefaultMarkEnd); iFbs->SendCommand(EFbsMessUserMarkEnd); } } else if (ret == KErrNone) { iBitmap.Reset(); if(heapMarkCheckFlag) { iFbs->SendCommand(EFbsMessDefaultMarkEnd); iFbs->SendCommand(EFbsMessUserMarkEnd); } break; } else TEST2(ret, KErrNone); } iFbs->SendCommand(EFbsMessDefaultAllocFail,0); iFbs->SendCommand(EFbsMessUserAllocFail,0); TEST(iFbs->ResourceCount()==0); // Load INFO_PRINTF1(_L("CFbsBitmap::Load()\r\n")); ret = iBitmap.Load(iTestBitmapName,ETfbs,NULL); TEST2(ret, KErrNone); iBitmap.Reset(); for (count = 1; ; count++) { iFbs->SendCommand(EFbsMessDefaultAllocFail,count); if(heapMarkCheckFlag) { iFbs->SendCommand(EFbsMessDefaultMark); iFbs->SendCommand(EFbsMessUserMark); } ret = iBitmap.Load(iTestBitmapName,ETfbs,NULL); if (ret == KErrNoMemory) { if(heapMarkCheckFlag) { iFbs->SendCommand(EFbsMessDefaultMarkEnd); iFbs->SendCommand(EFbsMessUserMarkEnd); } } else if (ret == KErrNone) { iBitmap.Reset(); if(heapMarkCheckFlag) { iFbs->SendCommand(EFbsMessDefaultMarkEnd); iFbs->SendCommand(EFbsMessUserMarkEnd); } break; } else TEST2(ret, KErrNone); } iFbs->SendCommand(EFbsMessDefaultAllocFail,0); iFbs->SendCommand(EFbsMessUserAllocFail,0); TEST(iFbs->ResourceCount()==0); for (count = 1; ; count++) { iFbs->SendCommand(EFbsMessUserAllocFail,count); if(heapMarkCheckFlag) { iFbs->SendCommand(EFbsMessDefaultMark); iFbs->SendCommand(EFbsMessUserMark); } ret = iBitmap.Load(iTestBitmapName,ETfbs,NULL); if (ret == KErrNoMemory) { if(heapMarkCheckFlag) { iFbs->SendCommand(EFbsMessDefaultMarkEnd); iFbs->SendCommand(EFbsMessUserMarkEnd); } } else if (ret == KErrNone) { iBitmap.Reset(); if(heapMarkCheckFlag) { iFbs->SendCommand(EFbsMessDefaultMarkEnd); iFbs->SendCommand(EFbsMessUserMarkEnd); } break; } else TEST2(ret, KErrNone); } iFbs->SendCommand(EFbsMessDefaultAllocFail,0); iFbs->SendCommand(EFbsMessUserAllocFail,0); TEST(iFbs->ResourceCount()==0); // Load (shared) INFO_PRINTF1(_L("CFbsBitmap::Load() - shared \r\n")); // Do an initial load to ensure the StreamId cache does not get updated whilst OOM testing ret = iBitmap.Load(iTestBitmapName,ETfbs,ETrue); TEST2(ret, KErrNone); iBitmap.Reset(); for (count = 1; ; count++) { iFbs->SendCommand(EFbsMessDefaultAllocFail,count); if(heapMarkCheckFlag) { iFbs->SendCommand(EFbsMessDefaultMark); iFbs->SendCommand(EFbsMessUserMark); } ret = iBitmap.Load(iTestBitmapName,ETfbs,ETrue); if (ret == KErrNoMemory) { if(heapMarkCheckFlag) { iFbs->SendCommand(EFbsMessDefaultMarkEnd); iFbs->SendCommand(EFbsMessUserMarkEnd); } continue; } else if (ret != KErrNone) TEST2(ret, KErrNone); ret = iBitmap2.Load(iTestBitmapName,ETfbs,ETrue); if (ret == KErrNoMemory) { iBitmap.Reset(); if(heapMarkCheckFlag) { iFbs->SendCommand(EFbsMessDefaultMarkEnd); iFbs->SendCommand(EFbsMessUserMarkEnd); } continue; } else if (ret == KErrNone) { iBitmap.Reset(); iBitmap2.Reset(); if(heapMarkCheckFlag) { iFbs->SendCommand(EFbsMessDefaultMarkEnd); iFbs->SendCommand(EFbsMessUserMarkEnd); } break; } else TEST2(ret, KErrNone); } iFbs->SendCommand(EFbsMessDefaultAllocFail,0); iFbs->SendCommand(EFbsMessUserAllocFail,0); TEST(iFbs->ResourceCount()==0); for (count = 1; ; count++) { iFbs->SendCommand(EFbsMessUserAllocFail,count); if(heapMarkCheckFlag) { iFbs->SendCommand(EFbsMessDefaultMark); iFbs->SendCommand(EFbsMessUserMark); } ret = iBitmap.Load(iTestBitmapName,ETfbs,ETrue); if (ret == KErrNoMemory) { if(heapMarkCheckFlag) { iFbs->SendCommand(EFbsMessDefaultMarkEnd); iFbs->SendCommand(EFbsMessUserMarkEnd); } continue; } else if (ret != KErrNone) TEST2(ret, KErrNone); ret = iBitmap2.Load(iTestBitmapName,ETfbs,ETrue); if (ret == KErrNoMemory) { iBitmap.Reset(); if(heapMarkCheckFlag) { iFbs->SendCommand(EFbsMessDefaultMarkEnd); iFbs->SendCommand(EFbsMessUserMarkEnd); } continue; } else if (ret == KErrNone) { iBitmap.Reset(); iBitmap2.Reset(); if(heapMarkCheckFlag) { iFbs->SendCommand(EFbsMessDefaultMarkEnd); iFbs->SendCommand(EFbsMessUserMarkEnd); } break; } else TEST2(ret, KErrNone); } iFbs->SendCommand(EFbsMessDefaultAllocFail,0); iFbs->SendCommand(EFbsMessUserAllocFail,0); TEST(iFbs->ResourceCount()==0); // Duplicate CFbsBitmap bmpalt; ret = bmpalt.Create(KSmallSize,EColor256); TEST2(ret, KErrNone); INFO_PRINTF1(_L("CFbsBitmap::Duplicate()\r\n")); for (count = 1; ; count++) { iFbs->SendCommand(EFbsMessDefaultAllocFail,count); if(heapMarkCheckFlag) { iFbs->SendCommand(EFbsMessDefaultMark); iFbs->SendCommand(EFbsMessUserMark); } ret = iBitmap.Duplicate(bmpalt.Handle()); if (ret == KErrNoMemory) { if(heapMarkCheckFlag) { iFbs->SendCommand(EFbsMessDefaultMarkEnd); iFbs->SendCommand(EFbsMessUserMarkEnd); } } else if (ret == KErrNone) { iBitmap.Reset(); if(heapMarkCheckFlag) { iFbs->SendCommand(EFbsMessDefaultMarkEnd); iFbs->SendCommand(EFbsMessUserMarkEnd); } break; } else TEST2(ret, KErrNone); } iFbs->SendCommand(EFbsMessDefaultAllocFail,0); iFbs->SendCommand(EFbsMessUserAllocFail,0); TEST(iFbs->ResourceCount()==1); ret = bmpalt.Create(KSmallSize,EColor256); TEST2(ret, KErrNone); for (count = 1; ; count++) { iFbs->SendCommand(EFbsMessUserAllocFail,count); if(heapMarkCheckFlag) { iFbs->SendCommand(EFbsMessDefaultMark); iFbs->SendCommand(EFbsMessUserMark); } ret = iBitmap.Duplicate(bmpalt.Handle()); if (ret == KErrNoMemory) { if(heapMarkCheckFlag) { iFbs->SendCommand(EFbsMessDefaultMarkEnd); iFbs->SendCommand(EFbsMessUserMarkEnd); } } else if (ret == KErrNone) { iBitmap.Reset(); if(heapMarkCheckFlag) { iFbs->SendCommand(EFbsMessDefaultMarkEnd); iFbs->SendCommand(EFbsMessUserMarkEnd); } break; } else TEST2(ret, KErrNone); } iFbs->SendCommand(EFbsMessDefaultAllocFail,0); iFbs->SendCommand(EFbsMessUserAllocFail,0); bmpalt.Reset(); TEST(iFbs->ResourceCount()==0); // Resize // force fbserv to do a resize. This makes the pile to insert an index in it's array // If the array is empty when the tests below are run then the insert will look like a mem leak ret=iBitmap.Create(KLargeSize,EColor256); iBitmap.Resize(KLargeSizeAlt); iBitmap.Reset(); ret=iBitmap.Create(KSmallSize,EColor256); TEST2(ret, KErrNone); INFO_PRINTF1(_L("CFbsBitmap::Resize()\r\n")); for (count = 1; ; count++) { iFbs->SendCommand(EFbsMessDefaultAllocFail,count); if(heapMarkCheckFlag) { iFbs->SendCommand(EFbsMessDefaultMark); iFbs->SendCommand(EFbsMessUserMark); } ret = iBitmap.Resize(KSmallSizeAlt); if (ret == KErrNoMemory) { if(heapMarkCheckFlag) { iFbs->SendCommand(EFbsMessDefaultMarkEnd); iFbs->SendCommand(EFbsMessUserMarkEnd); } } else if (ret == KErrNone) { iBitmap.Reset(); if(heapMarkCheckFlag) { iFbs->SendCommand(EFbsMessDefaultMarkEnd); iFbs->SendCommand(EFbsMessUserMarkEnd); } break; } else TEST2(ret, KErrNone); } iFbs->SendCommand(EFbsMessDefaultAllocFail,0); iFbs->SendCommand(EFbsMessUserAllocFail,0); TEST(iFbs->ResourceCount()==0); // force fbserv to do a resize. This makes the pile to insert an index in it's array // If the array is empty when the tests below are run then the insert will look like a mem leak ret=iBitmap.Create(KLargeSize,EColor256); iBitmap.Resize(KLargeSizeAlt); iBitmap.Reset(); ret=iBitmap.Create(KLargeSize,EColor256); TEST2(ret, KErrNone); for (count = 1; ; count++) { iFbs->SendCommand(EFbsMessUserAllocFail,count); if(heapMarkCheckFlag) { iFbs->SendCommand(EFbsMessDefaultMark); iFbs->SendCommand(EFbsMessUserMark); } ret = iBitmap.Resize(KLargeSizeAlt); if (ret == KErrNoMemory) { if(heapMarkCheckFlag) { iFbs->SendCommand(EFbsMessDefaultMarkEnd); iFbs->SendCommand(EFbsMessUserMarkEnd); } } else if (ret == KErrNone) { iBitmap.Reset(); if(heapMarkCheckFlag) { iFbs->SendCommand(EFbsMessDefaultMarkEnd); iFbs->SendCommand(EFbsMessUserMarkEnd); } break; } else TEST2(ret, KErrNone); } iFbs->SendCommand(EFbsMessDefaultAllocFail,0); iFbs->SendCommand(EFbsMessUserAllocFail,0); TEST(iFbs->ResourceCount()==0); // Compress ret=iBitmap.Create(KSmallSize,EColor256); TEST2(ret, KErrNone); INFO_PRINTF1(_L("CFbsBitmap::Compress()\r\n")); for (count = 1; ; count++) { iFbs->SendCommand(EFbsMessDefaultAllocFail,count); if(heapMarkCheckFlag) { iFbs->SendCommand(EFbsMessDefaultMark); iFbs->SendCommand(EFbsMessUserMark); } ret = iBitmap.Compress(); if (ret == KErrNoMemory) { if(heapMarkCheckFlag) { iFbs->SendCommand(EFbsMessDefaultMarkEnd); iFbs->SendCommand(EFbsMessUserMarkEnd); } } else if (ret == KErrNone) { iBitmap.Reset(); if(heapMarkCheckFlag) { iFbs->SendCommand(EFbsMessDefaultMarkEnd); iFbs->SendCommand(EFbsMessUserMarkEnd); } break; } else TEST2(ret, KErrNone); } iFbs->SendCommand(EFbsMessDefaultAllocFail,0); iFbs->SendCommand(EFbsMessUserAllocFail,0); TEST(iFbs->ResourceCount()==0); ret=iBitmap.Create(KLargeSize,EColor256); TEST2(ret, KErrNone); INFO_PRINTF1(_L("CFbsBitmap::Compress()\r\n")); for (count = 1; ; count++) { iFbs->SendCommand(EFbsMessDefaultAllocFail,count); if(heapMarkCheckFlag) { iFbs->SendCommand(EFbsMessDefaultMark); iFbs->SendCommand(EFbsMessUserMark); } ret = iBitmap.Compress(); if (ret == KErrNoMemory) { if(heapMarkCheckFlag) { iFbs->SendCommand(EFbsMessDefaultMarkEnd); iFbs->SendCommand(EFbsMessUserMarkEnd); } } else if (ret == KErrNone) { iBitmap.Reset(); if(heapMarkCheckFlag) { iFbs->SendCommand(EFbsMessDefaultMarkEnd); iFbs->SendCommand(EFbsMessUserMarkEnd); } break; } else TEST2(ret, KErrNone); } iFbs->SendCommand(EFbsMessDefaultAllocFail,0); iFbs->SendCommand(EFbsMessUserAllocFail,0); TEST(iFbs->ResourceCount()==0); // WriteStore creation RFs fs; ret=fs.Connect(); TEST2(ret, KErrNone); CDirectFileStore* writestore=NULL; //Construct filename using the thread id to enable concurrent test runs. _LIT(KSbmFileName,"c:\\tall_"); TBuf<36> buf(KSbmFileName); TThreadId threadId = RThread().Id(); TUint64 id = threadId.Id(); TBuf<20> threadIdBuf; threadIdBuf.Num(id); buf.Append(threadIdBuf); buf.Append(_L(".sbm")); TRAP(ret,writestore=CDirectFileStore::ReplaceL(fs,buf,EFileStream|EFileWrite)); TEST2(ret, KErrNone); TUidType uidtype(KDirectFileStoreLayoutUid,KMultiBitmapFileImageUid); TRAP(ret,writestore->SetTypeL(uidtype)); TEST2(ret, KErrNone); RStoreWriteStream writestrm; TStreamId headerid(0); TRAP(ret,headerid=writestrm.CreateL(*writestore)); TEST2(ret, KErrNone); TRAP(ret,writestore->SetRootL(headerid)); TEST2(ret, KErrNone); // Externalize ret=iBitmap.Create(KSmallSize,EColor256); TEST2(ret, KErrNone); INFO_PRINTF1(_L("CFbsBitmap::ExternalizeL()\r\n")); for (count = 1; ; count++) { __UHEAP_SETFAIL(RHeap::EDeterministic,count); __UHEAP_MARK; TRAP(ret,iBitmap.ExternalizeL(writestrm)); if (ret == KErrNoMemory) { __UHEAP_MARKEND; } else if (ret == KErrNone) { iBitmap.Reset(); __UHEAP_MARKEND; break; } else { __UHEAP_MARKEND; TEST2(ret, KErrNone); } } __UHEAP_RESET; TEST(iFbs->ResourceCount()==0); // ExternalizeRectangle ret=iBitmap.Create(KSmallSize,EColor256); TEST2(ret, KErrNone); INFO_PRINTF1(_L("CFbsBitmap::ExternalizeRectangleL()\r\n")); for (count = 1; ; count++) { __UHEAP_SETFAIL(RHeap::EDeterministic,count); __UHEAP_MARK; TRAP(ret,iBitmap.ExternalizeRectangleL(writestrm,TRect(3,3,7,7))); if (ret == KErrNoMemory) { __UHEAP_MARKEND; } else if (ret == KErrNone) { __UHEAP_MARKEND; break; } else { __UHEAP_MARKEND; TEST2(ret, KErrNone); } } __UHEAP_RESET; writestrm.Close(); delete writestore; iBitmap.Reset(); TEST(iFbs->ResourceCount()==0); // Internalize INFO_PRINTF1(_L("CFbsBitmap::InternalizeL()\r\n")); for (count = 1; ; count++) { // ReadStore creation CDirectFileStore* readstore=NULL; TRAP(ret,readstore=CDirectFileStore::OpenL(fs,buf,EFileStream|EFileRead|EFileShareAny)); TEST2(ret, KErrNone); RStoreReadStream readstrm; headerid=readstore->Root(); TRAP(ret,readstrm.OpenL(*readstore,headerid)); TEST2(ret, KErrNone); iFbs->SendCommand(EFbsMessDefaultAllocFail,count); if(heapMarkCheckFlag) { iFbs->SendCommand(EFbsMessDefaultMark); iFbs->SendCommand(EFbsMessUserMark); } TRAP(ret,iBitmap.InternalizeL(readstrm)); readstrm.Close(); delete readstore; if (ret == KErrNoMemory) { if(heapMarkCheckFlag) { iFbs->SendCommand(EFbsMessDefaultMarkEnd); iFbs->SendCommand(EFbsMessUserMarkEnd); } } else if (ret == KErrNone) { iBitmap.Reset(); if(heapMarkCheckFlag) { iFbs->SendCommand(EFbsMessDefaultMarkEnd); iFbs->SendCommand(EFbsMessUserMarkEnd); } break; } else TEST2(ret, KErrNone); } iFbs->SendCommand(EFbsMessDefaultAllocFail,0); iFbs->SendCommand(EFbsMessUserAllocFail,0); TEST(iFbs->ResourceCount()==0); for (count = 1; ; count++) { // ReadStore re-creation CDirectFileStore* readstore=NULL; // TRAP(ret,readstore=CDirectFileStore::OpenL(fs,_L("c:\\tall.sbm"),EFileStream|EFileRead|EFileShareAny)); TRAP(ret,readstore=CDirectFileStore::OpenL(fs,buf,EFileStream|EFileRead|EFileShareAny)); TEST2(ret, KErrNone); headerid=readstore->Root(); RStoreReadStream readstrm; TRAP(ret,readstrm.OpenL(*readstore,headerid)); TEST2(ret, KErrNone); iFbs->SendCommand(EFbsMessUserAllocFail,count); if(heapMarkCheckFlag) { iFbs->SendCommand(EFbsMessDefaultMark); iFbs->SendCommand(EFbsMessUserMark); } TRAP(ret,iBitmap.InternalizeL(readstrm)); readstrm.Close(); delete readstore; if (ret == KErrNoMemory) { if(heapMarkCheckFlag) { iFbs->SendCommand(EFbsMessDefaultMarkEnd); iFbs->SendCommand(EFbsMessUserMarkEnd); } } else if (ret == KErrNone) { iBitmap.Reset(); if(heapMarkCheckFlag) { iFbs->SendCommand(EFbsMessDefaultMarkEnd); iFbs->SendCommand(EFbsMessUserMarkEnd); } break; } else TEST2(ret, KErrNone); } iFbs->SendCommand(EFbsMessDefaultAllocFail,0); iFbs->SendCommand(EFbsMessUserAllocFail,0); TEST(iFbs->ResourceCount()==0); fs.Delete(buf); fs.Close(); }
EXPORT_C void AknsUtils::CreateAppIconLC( MAknsSkinInstance* aInstance, TUid aAppUid, TAknsAppIconType aType, CFbsBitmap*& aBitmap, CFbsBitmap*& aMask ) { aBitmap = NULL; aMask = NULL; if (!aInstance) { User::Leave(KErrArgument); } TSize legacySize( 42, 29 ); TInt bitmapIndex( 0 ); TInt maskIndex( 1 ); if( aType == EAknsAppIconTypeContext ) { legacySize = TSize( 44, 44 ); bitmapIndex = 2; maskIndex = 3; } else if( aType != EAknsAppIconTypeList ) { User::Leave( KErrArgument ); } // Make the forthcoming pushes safe (up to level 2) CleanupStack::PushL( static_cast<TAny*>(NULL) ); CleanupStack::PushL( static_cast<TAny*>(NULL) ); CleanupStack::Pop( 2 ); // 1. Check if the icon has been configured. TInt ret = KErrNone; TBool configuredIcon = EFalse; // CAknsAppSkinInstance* apskin = static_cast<CAknsAppSkinInstance*>(aInstance); if ( apskin ) { TInt config = apskin->IsIconConfiguredL( aAppUid ); if ( config > 0 ) configuredIcon = ETrue; } if ( !configuredIcon ) { // 2. Skin-originating icon ret = GetAppIconFromSkin( aInstance, aAppUid, legacySize, aBitmap, aMask ); if( ret == KErrNone ) { // These pushes are safe CleanupStack::PushL( aBitmap ); // (1) CleanupStack::PushL( aMask ); // (2) return; } } // Cache connected apparc session for future reuse, if not already cached // This is done per appskininstance when necessary... if (!apskin->iCachedApaSession) { apskin->iCachedApaSession = new (ELeave) RApaLsSession; User::LeaveIfError(apskin->iCachedApaSession->Connect()); } RApaLsSession* lsSession = apskin->iCachedApaSession; TBool forceDefaultIcon = EFalse; TApaAppInfo appInfo; TFileName filename; // 3. New appicon framework HBufC* filenameBuf = NULL; TBool javaIcon = EFalse; ret = lsSession->GetAppIcon( aAppUid, filenameBuf ); if( filenameBuf ) { filename.Copy( *filenameBuf ); delete filenameBuf; } if( ret == KErrNone ) { ret = lsSession->GetAppInfo( appInfo, aAppUid ); } if( (ret==KErrNone) && (filename.Length()>2) && (appInfo.iFullName.Length()>2) ) { // Correct drive letter, if necessary if( appInfo.iFullName[1]==':' ) { if( filename[1]==':' ) { filename[0] = appInfo.iFullName[0]; } else if( filename[0]=='\\' ) { filename.Insert( 0, appInfo.iFullName.Left(2) ); } } // check if the icon is java icon javaIcon = AknsJavaUtils::IsJavaIcon(filename); if( AknIconUtils::IsMifFile( filename ) ) { // SVG icon // SVG always has only one icon bitmapIndex = 0; maskIndex = 1; AknIconUtils::ValidateLogicalAppIconId( filename, bitmapIndex, maskIndex ); if (javaIcon) { AknsJavaUtils::CreateIconLC(*lsSession, aAppUid, aBitmap, aMask, bitmapIndex, maskIndex ); // aBitmap, aMask (2) } else { AknIconUtils::CreateIconLC( aBitmap, aMask, filename, bitmapIndex, maskIndex ); // aBitmap, aMask (2) } AknInternalIconUtils::SetAppIcon(aBitmap); //icon case return; } else { // MBM icon AknIconUtils::ValidateLogicalAppIconId( filename, bitmapIndex, maskIndex ); TRAP( ret, AknIconUtils::CreateIconL( aBitmap, aMask, filename, bitmapIndex, maskIndex ) ); if( ret == KErrNone ) { // These pushes are safe CleanupStack::PushL( aBitmap ); // (1) CleanupStack::PushL( aMask ); // (2) } else { bitmapIndex = 0; maskIndex = 1; AknIconUtils::ValidateLogicalAppIconId( filename, bitmapIndex, maskIndex ); AknIconUtils::CreateIconLC( aBitmap, aMask, filename, bitmapIndex, maskIndex ); // aBitmap, aMask (2) } AknInternalIconUtils::SetAppIcon(aBitmap); //icon case return; } } else if( ret!=KErrNotSupported ) { // New framework, but no icon defined forceDefaultIcon = ETrue; } CApaMaskedBitmap* apaBmp = CApaMaskedBitmap::NewLC(); // apaBmp (1) // 3. Old (AIF-based) framework if( !forceDefaultIcon ) { TInt apaErr = lsSession->GetAppIcon( aAppUid, legacySize, *apaBmp ); // Use default icon if APPARC did not initialize icon bitmaps if( apaErr || (!apaBmp) || (!apaBmp->Mask()) || (!apaBmp->Handle()) || (!apaBmp->Mask()->Handle()) ) { forceDefaultIcon = ETrue; } } if( forceDefaultIcon ) { // Default icon CleanupStack::PopAndDestroy( 1 ); // apaBmp (0) TAknsItemID iid = KAknsIIDQgnMenuUnknownLst; bitmapIndex = EMbmAvkonQgn_menu_unknown_lst; maskIndex = EMbmAvkonQgn_menu_unknown_lst_mask; if( aType == EAknsAppIconTypeContext ) { iid = KAknsIIDQgnMenuUnknownCxt; bitmapIndex = EMbmAvkonQgn_menu_unknown_cxt; maskIndex = EMbmAvkonQgn_menu_unknown_cxt_mask; } AknsUtils::CreateIconLC( aInstance, iid, aBitmap, aMask, AknIconUtils::AvkonIconFileName(), bitmapIndex, maskIndex ); // aBitmap, aMask (2) } else { // AIF-based icon CFbsBitmap* iconOwnedBitmap = new (ELeave) CFbsBitmap(); CleanupStack::PushL( iconOwnedBitmap ); // iob (3) CFbsBitmap* iconOwnedMask = new (ELeave) CFbsBitmap(); CleanupStack::PushL( iconOwnedMask ); // iom (4) User::LeaveIfError( iconOwnedBitmap->Duplicate( apaBmp->Handle() ) ); User::LeaveIfError( iconOwnedMask->Duplicate( apaBmp->Mask()->Handle() ) ); CAknIcon* tmpIcon = CAknIcon::NewL(); CleanupStack::Pop( 2 ); // iom, iob (2) CleanupStack::PopAndDestroy( 1 ); // apaBmp (0) // Ownership is transferred tmpIcon->SetBitmap( iconOwnedBitmap ); tmpIcon->SetMask( iconOwnedMask ); // Ownership of tmpIcon is transferred CAknIcon* appIcon = AknIconUtils::CreateIconL( tmpIcon ); aBitmap = appIcon->Bitmap(); aMask = appIcon->Mask(); // Detach and delete appIcon->SetBitmap( NULL ); appIcon->SetMask( NULL ); delete appIcon; // These are both safe CleanupStack::PushL( aBitmap ); // (1) CleanupStack::PushL( aMask ); // (2) } }