Tracker: style fixes to IconCache

This commit is contained in:
John Scipione
2014-06-21 03:03:35 -04:00
parent 7dbe212003
commit d73129ff46
+59 -51
View File
@@ -885,7 +885,8 @@ IconCache::Preload(AutoLock<SimpleIconCache>* nodeCacheLocker,
// resultingOpenCache is the locker that points to the cache that // resultingOpenCache is the locker that points to the cache that
// ended with a hit and will be used for the drawing // ended with a hit and will be used for the drawing
{ // scope for modelOpener {
// scope for modelOpener
ModelNodeLazyOpener modelOpener(model); ModelNodeLazyOpener modelOpener(model);
// this opener takes care of opening the model and possibly // this opener takes care of opening the model and possibly
@@ -903,39 +904,41 @@ IconCache::Preload(AutoLock<SimpleIconCache>* nodeCacheLocker,
&resultingOpenCache, model, source, mode, size, &resultingOpenCache, model, source, mode, size,
&lazyBitmap, entry, permanent); &lazyBitmap, entry, permanent);
if (!entry || !entry->HaveIconBitmap(mode, size)) if (entry == NULL || !entry->HaveIconBitmap(mode, size)) {
// look for volume defined icon // look for volume defined icon
entry = GetVolumeIcon(nodeCacheLocker, sharedCacheLocker, entry = GetVolumeIcon(nodeCacheLocker, sharedCacheLocker,
&resultingOpenCache, model, source, mode, &resultingOpenCache, model, source, mode,
size, &lazyBitmap); size, &lazyBitmap);
}
} else if (model->IsRoot()) { } else if (model->IsRoot()) {
entry = GetRootIcon(nodeCacheLocker, sharedCacheLocker, entry = GetRootIcon(nodeCacheLocker, sharedCacheLocker,
&resultingOpenCache, model, source, mode, size, &lazyBitmap); &resultingOpenCache, model, source, mode, size,
ASSERT(entry); &lazyBitmap);
ASSERT(entry != NULL);
} else { } else {
if (source == kUnknownSource) if (source == kUnknownSource) {
// look for node icons first // look for node icons first
entry = GetNodeIcon(&modelOpener, nodeCacheLocker, entry = GetNodeIcon(&modelOpener, nodeCacheLocker,
&resultingOpenCache, model, source, &resultingOpenCache, model, source,
mode, size, &lazyBitmap, entry, permanent); mode, size, &lazyBitmap, entry, permanent);
}
if (entry == NULL) {
if (!entry) {
// no node icon, look for file type based one // no node icon, look for file type based one
modelOpener.OpenNode(); modelOpener.OpenNode();
// use file types to get the icon // use file types to get the icon
resultingOpenCache = sharedCacheLocker; resultingOpenCache = sharedCacheLocker;
resultingOpenCache->Lock(); resultingOpenCache->Lock();
entry = GetIconFromFileTypes(&modelOpener, source, mode, size, entry = GetIconFromFileTypes(&modelOpener, source, mode,
&lazyBitmap, 0); size, &lazyBitmap, 0);
if (!entry) // we don't have an icon, go with the generic if (entry == NULL) {
entry = GetGenericIcon(sharedCacheLocker, &resultingOpenCache, // we don't have an icon, go with the generic
model, source, mode, size, &lazyBitmap, entry); entry = GetGenericIcon(sharedCacheLocker,
&resultingOpenCache, model, source, mode,
size, &lazyBitmap, entry);
}
} }
} }
@@ -953,8 +956,9 @@ IconCache::Preload(AutoLock<SimpleIconCache>* nodeCacheLocker,
&resultingOpenCache, model, source, mode, &resultingOpenCache, model, source, mode,
size, &lazyBitmap, entry, permanent); size, &lazyBitmap, entry, permanent);
if (entry) { if (entry != NULL) {
entry = IconCacheEntry::ResolveIfAlias(&fSharedCache, entry); entry = IconCacheEntry::ResolveIfAlias(&fSharedCache,
entry);
if (!entry->HaveIconBitmap(mode, size) if (!entry->HaveIconBitmap(mode, size)
&& entry->HaveIconBitmap(NORMAL_ICON_ONLY, size)) { && entry->HaveIconBitmap(NORMAL_ICON_ONLY, size)) {
entry->ConstructBitmap(mode, size, &lazyBitmap); entry->ConstructBitmap(mode, size, &lazyBitmap);
@@ -970,11 +974,11 @@ IconCache::Preload(AutoLock<SimpleIconCache>* nodeCacheLocker,
&lazyBitmap); &lazyBitmap);
break; break;
} else { } else {
entry = GetWellKnownIcon(nodeCacheLocker, sharedCacheLocker, entry = GetWellKnownIcon(nodeCacheLocker,
&resultingOpenCache, model, source, mode, size, sharedCacheLocker, &resultingOpenCache, model,
&lazyBitmap); source, mode, size, &lazyBitmap);
if (entry) if (entry != NULL)
break; break;
} }
// fall through // fall through
@@ -984,10 +988,12 @@ IconCache::Preload(AutoLock<SimpleIconCache>* nodeCacheLocker,
entry = GetNodeIcon(&modelOpener, nodeCacheLocker, entry = GetNodeIcon(&modelOpener, nodeCacheLocker,
&resultingOpenCache, model, source, &resultingOpenCache, model, source,
mode, size, &lazyBitmap, entry, permanent); mode, size, &lazyBitmap, entry, permanent);
if (!entry || !entry->HaveIconBitmap(mode, size)) if (entry == NULL
entry = GetVolumeIcon(nodeCacheLocker, sharedCacheLocker, || !entry->HaveIconBitmap(mode, size)) {
&resultingOpenCache, model, source, mode, size, entry = GetVolumeIcon(nodeCacheLocker,
&lazyBitmap); sharedCacheLocker, &resultingOpenCache, model,
source, mode, size, &lazyBitmap);
}
break; break;
} }
// fall through // fall through
@@ -997,25 +1003,27 @@ IconCache::Preload(AutoLock<SimpleIconCache>* nodeCacheLocker,
resultingOpenCache = sharedCacheLocker; resultingOpenCache = sharedCacheLocker;
resultingOpenCache->Lock(); resultingOpenCache->Lock();
entry = GetIconFromFileTypes(&modelOpener, source, mode, size, entry = GetIconFromFileTypes(&modelOpener, source, mode,
&lazyBitmap, 0); size, &lazyBitmap, 0);
ASSERT(!entry || entry->HaveIconBitmap(mode, size)); ASSERT(entry != NULL || entry->HaveIconBitmap(mode, size));
if (!entry || !entry->HaveIconBitmap(mode, size)) if (entry == NULL || !entry->HaveIconBitmap(mode, size)) {
// we don't have an icon, go with the generic // we don't have an icon, go with the generic
entry = GetGenericIcon(sharedCacheLocker, &resultingOpenCache, entry = GetGenericIcon(sharedCacheLocker,
model, source, mode, size, &lazyBitmap, entry); &resultingOpenCache, model, source, mode, size,
&lazyBitmap, entry);
}
model->SetIconFrom(source); model->SetIconFrom(source);
// the source shouldn't change in this case; if it does though we // The source shouldn't change in this case; if it does
// might never be hitting the correct icon and instead keep leaking // though we might never be hitting the correct icon and
// entries after each miss // instead keep leaking entries after each miss this now
// this now happens if an app defines an icon but a GetIconForType // happens if an app defines an icon but a
// fails and we fall back to generic icon // GetIconForType() fails and we fall back to generic
// ToDo: // icon.
// fix this and add an assert to the effect // ToDo: fix this and add an assert to the effect
ASSERT(entry); ASSERT(entry != NULL);
ASSERT(entry->HaveIconBitmap(mode, size)); ASSERT(entry->HaveIconBitmap(mode, size));
break; break;
@@ -1025,7 +1033,7 @@ IconCache::Preload(AutoLock<SimpleIconCache>* nodeCacheLocker,
} }
} }
if (!entry || !entry->HaveIconBitmap(mode, size)) { if (entry == NULL || !entry->HaveIconBitmap(mode, size)) {
// we don't have an icon, go with the generic // we don't have an icon, go with the generic
PRINT( PRINT(
("icon cache complete miss, falling back on generic icon " ("icon cache complete miss, falling back on generic icon "
@@ -1035,7 +1043,7 @@ IconCache::Preload(AutoLock<SimpleIconCache>* nodeCacheLocker,
// we don't even have generic, something is really broken, // we don't even have generic, something is really broken,
// go with hardcoded generic icon // go with hardcoded generic icon
if (!entry || !entry->HaveIconBitmap(mode, size)) { if (entry == NULL || !entry->HaveIconBitmap(mode, size)) {
PRINT( PRINT(
("icon cache complete miss, falling back on generic " ("icon cache complete miss, falling back on generic "
"icon for %s\n", model->Name())); "icon for %s\n", model->Name()));
@@ -1050,9 +1058,9 @@ IconCache::Preload(AutoLock<SimpleIconCache>* nodeCacheLocker,
} }
} }
ASSERT(entry && entry->HaveIconBitmap(mode, size)); ASSERT(entry != NULL && entry->HaveIconBitmap(mode, size));
if (resultingCache) if (resultingCache != NULL)
*resultingCache = resultingOpenCache; *resultingCache = resultingOpenCache;
return entry; return entry;
@@ -1075,10 +1083,10 @@ IconCache::Draw(Model* model, BView* view, BPoint where, IconDrawMode mode,
// Preload finds/creates the appropriate entry, locking down the // Preload finds/creates the appropriate entry, locking down the
// cache it is in and returns the whole state back to here // cache it is in and returns the whole state back to here
if (!entry) if (entry == NULL)
return; return;
ASSERT(entry); ASSERT(entry != NULL);
ASSERT(entry->HaveIconBitmap(mode, size)); ASSERT(entry->HaveIconBitmap(mode, size));
// got the entry, now draw it // got the entry, now draw it
resultingCacheLocker->LockedItem()->Draw(entry, view, where, mode, resultingCacheLocker->LockedItem()->Draw(entry, view, where, mode,
@@ -1102,10 +1110,10 @@ IconCache::SyncDraw(Model* model, BView* view, BPoint where,
IconCacheEntry* entry = Preload(&nodeCacheLocker, &sharedCacheLocker, IconCacheEntry* entry = Preload(&nodeCacheLocker, &sharedCacheLocker,
&resultingCacheLocker, model, mode, size, false); &resultingCacheLocker, model, mode, size, false);
if (!entry) if (entry == NULL)
return; return;
ASSERT(entry); ASSERT(entry != NULL);
ASSERT(entry->HaveIconBitmap(mode, size)); ASSERT(entry->HaveIconBitmap(mode, size));
resultingCacheLocker->LockedItem()->Draw(entry, view, where, resultingCacheLocker->LockedItem()->Draw(entry, view, where,
mode, size, blitFunc, passThruState); mode, size, blitFunc, passThruState);
@@ -1139,7 +1147,7 @@ IconCache::Preload(const char* fileType, IconDrawMode mode, icon_size size)
// try getting the icon from the preferred app for the signature // try getting the icon from the preferred app for the signature
IconCacheEntry* entry = GetIconForPreferredApp(fileType, preferredAppSig, IconCacheEntry* entry = GetIconForPreferredApp(fileType, preferredAppSig,
mode, size, &lazyBitmap, 0); mode, size, &lazyBitmap, 0);
if (entry) if (entry != NULL)
return B_OK; return B_OK;
// try getting the icon directly from the metamime // try getting the icon directly from the metamime
@@ -1207,13 +1215,13 @@ IconCache::IconChanged(const char* mimeType, const char* appSignature)
{ {
AutoLock<SimpleIconCache> sharedLock(&fSharedCache); AutoLock<SimpleIconCache> sharedLock(&fSharedCache);
SharedCacheEntry* entry = fSharedCache.FindItem(mimeType, appSignature); SharedCacheEntry* entry = fSharedCache.FindItem(mimeType, appSignature);
if (!entry) if (entry == NULL)
return; return;
AutoLock<SimpleIconCache> nodeLock(&fNodeCache); AutoLock<SimpleIconCache> nodeLock(&fNodeCache);
entry = (SharedCacheEntry*)fSharedCache.ResolveIfAlias(entry); entry = (SharedCacheEntry*)fSharedCache.ResolveIfAlias(entry);
ASSERT(entry); ASSERT(entry != NULL);
int32 index = fSharedCache.EntryIndex(entry); int32 index = fSharedCache.EntryIndex(entry);
fNodeCache.RemoveAliasesTo(index); fNodeCache.RemoveAliasesTo(index);
@@ -1350,7 +1358,7 @@ IconCache::IconHitTest(BPoint where, const Model* model, IconDrawMode mode,
// Preload finds/creates the appropriate entry, locking down the // Preload finds/creates the appropriate entry, locking down the
// cache it is in and returns the whole state back to here // cache it is in and returns the whole state back to here
if (entry) if (entry != NULL)
return entry->IconHitTest(where, mode, size); return entry->IconHitTest(where, mode, size);
return false; return false;