optimized image caching code

This commit is contained in:
louis 2014-11-25 14:33:59 +01:00
parent 0422c52c6e
commit d684cec70e
8 changed files with 133 additions and 154 deletions

View File

@ -46,25 +46,24 @@ void cImageCache::CacheLogo(int width, int height) {
if (width == 0 || height == 0) if (width == 0 || height == 0)
return; return;
int channelsCached = 0; int logosCached = 0;
for (const cChannel *channel = Channels.First(); channel; channel = Channels.Next(channel)) { for (const cChannel *channel = Channels.First(); channel; channel = Channels.Next(channel)) {
if (channelsCached >= config.numLogosPerSizeInitial) if (logosCached >= config.numLogosPerSizeInitial)
break; break;
if (channel->GroupSep()) { if (channel->GroupSep()) {
continue; continue;
} }
bool success = LoadLogo(channel);
if (success) {
channelsCached++;
cImage *image = CreateImage(width, height);
stringstream logoName; stringstream logoName;
logoName << *channel->GetChannelID().ToString() << "_" << width << "x" << height; logoName << *channel->GetChannelID().ToString() << "_" << width << "x" << height;
std::map<std::string, cImage*>::iterator hit = channelLogoCache.find(logoName.str()); map<string, cImage*>::iterator hit = channelLogoCache.find(logoName.str());
if (hit != channelLogoCache.end()) { if (hit != channelLogoCache.end()) {
delete image; continue;
return;
} }
bool success = LoadLogo(channel);
if (success) {
logosCached++;
cImage *image = CreateImage(width, height);
channelLogoCache.insert(pair<string, cImage*>(logoName.str(), image)); channelLogoCache.insert(pair<string, cImage*>(logoName.str(), image));
} }
} }
@ -158,13 +157,7 @@ bool cImageCache::SeparatorLogoExists(string name) {
void cImageCache::CacheIcon(eImageType type, string name, int width, int height) { void cImageCache::CacheIcon(eImageType type, string name, int width, int height) {
if (width < 1 || width > 1920 || height < 1 || height > 1080) if (width < 1 || width > 1920 || height < 1 || height > 1080)
return; return;
bool success = LoadIcon(type, name); GetIcon(type, name, width, height);
if (!success)
return;
stringstream iconName;
iconName << name << "_" << width << "x" << height;
cImage *image = CreateImage(width, height, true);
iconCache.insert(pair<string, cImage*>(iconName.str(), image));
} }
cImage *cImageCache::GetIcon(eImageType type, string name, int width, int height) { cImage *cImageCache::GetIcon(eImageType type, string name, int width, int height) {
@ -281,13 +274,7 @@ bool cImageCache::MenuIconExists(string name) {
void cImageCache::CacheSkinpart(string name, int width, int height) { void cImageCache::CacheSkinpart(string name, int width, int height) {
if (width < 1 || width > 1920 || height < 1 || height > 1080) if (width < 1 || width > 1920 || height < 1 || height > 1080)
return; return;
bool success = LoadSkinpart(name); GetSkinpart(name, width, height);
if (!success)
return;
stringstream iconName;
iconName << name << "_" << width << "x" << height;
cImage *image = CreateImage(width, height, false);
skinPartsCache.insert(pair<string, cImage*>(iconName.str(), image));
} }
cImage *cImageCache::GetSkinpart(string name, int width, int height) { cImage *cImageCache::GetSkinpart(string name, int width, int height) {

View File

@ -104,7 +104,6 @@ vector< pair<string, int> > cTemplate::GetUsedFonts(void) {
void cTemplate::CacheImages(void) { void cTemplate::CacheImages(void) {
CacheImages(rootView); CacheImages(rootView);
rootView->InitSubViewIterator(); rootView->InitSubViewIterator();
cTemplateView *subView = NULL; cTemplateView *subView = NULL;
while(subView = rootView->GetNextSubView()) { while(subView = rootView->GetNextSubView()) {
@ -113,9 +112,7 @@ void cTemplate::CacheImages(void) {
} }
void cTemplate::Debug(void) { void cTemplate::Debug(void) {
rootView->Debug(); rootView->Debug();
} }
/******************************************************************* /*******************************************************************
@ -213,13 +210,7 @@ void cTemplate::CacheImages(cTemplateView *view) {
viewElement->InitIterator(); viewElement->InitIterator();
cTemplatePixmap *pix = NULL; cTemplatePixmap *pix = NULL;
while(pix = viewElement->GetNextPixmap()) { while(pix = viewElement->GetNextPixmap()) {
pix->InitIterator(); CachePixmapImages(pix);
cTemplateFunction *func = NULL;
while(func = pix->GetNextFunction()) {
if (func->GetType() == ftDrawImage) {
CacheImage(func);
}
}
} }
} }
//used images in viewLists pixmaps //used images in viewLists pixmaps
@ -229,17 +220,31 @@ void cTemplate::CacheImages(cTemplateView *view) {
viewList->InitIterator(); viewList->InitIterator();
cTemplatePixmap *pix = NULL; cTemplatePixmap *pix = NULL;
while(pix = viewList->GetNextPixmap()) { while(pix = viewList->GetNextPixmap()) {
pix->InitIterator(); CachePixmapImages(pix);
cTemplateFunction *func = NULL;
while(func = pix->GetNextFunction()) {
if (func->GetType() == ftDrawImage) {
CacheImage(func);
}
}
} }
cTemplateViewElement *listElement = viewList->GetListElement(); cTemplateViewElement *listElement = viewList->GetListElement();
listElement->InitIterator(); listElement->InitIterator();
while(pix = listElement->GetNextPixmap()) { while(pix = listElement->GetNextPixmap()) {
CachePixmapImages(pix);
}
cTemplateViewElement *currentElement = viewList->GetListElementCurrent();
if (!currentElement) {
continue;
}
currentElement->InitIterator();
while(pix = currentElement->GetNextPixmap()) {
CachePixmapImages(pix);
}
}
//used images in viewTabs
view->InitViewTabIterator();
cTemplateViewTab *viewTab = NULL;
while(viewTab = view->GetNextViewTab()) {
CachePixmapImages(viewTab);
}
}
void cTemplate::CachePixmapImages(cTemplatePixmap *pix) {
pix->InitIterator(); pix->InitIterator();
cTemplateFunction *func = NULL; cTemplateFunction *func = NULL;
while(func = pix->GetNextFunction()) { while(func = pix->GetNextFunction()) {
@ -248,20 +253,6 @@ void cTemplate::CacheImages(cTemplateView *view) {
} }
} }
} }
}
//used logos in viewTabs
view->InitViewTabIterator();
cTemplateViewTab *viewTab = NULL;
while(viewTab = view->GetNextViewTab()) {
viewTab->InitIterator();
cTemplateFunction *func = NULL;
while(func = viewTab->GetNextFunction()) {
if (func->GetType() == ftDrawImage) {
CacheImage(func);
}
}
}
}
void cTemplate::CacheImage(cTemplateFunction *func) { void cTemplate::CacheImage(cTemplateFunction *func) {
eImageType imgType = (eImageType)func->GetNumericParameter(ptImageType); eImageType imgType = (eImageType)func->GetNumericParameter(ptImageType);

View File

@ -32,6 +32,7 @@ enum eViewType {
class cTemplate { class cTemplate {
private: private:
eViewType viewType; eViewType viewType;
void CachePixmapImages(cTemplatePixmap *pix);
void CacheImage(cTemplateFunction *func); void CacheImage(cTemplateFunction *func);
protected: protected:
cGlobals *globals; cGlobals *globals;

View File

@ -209,5 +209,5 @@
</areascroll> </areascroll>
</currentelement> </currentelement>
</menuitems> </menuitems>
</menuschedules> </menuschedules>