mirror of
https://projects.vdr-developer.org/git/vdr-plugin-skindesigner.git
synced 2023-10-19 17:58:31 +02:00
optimized image caching code
This commit is contained in:
parent
0422c52c6e
commit
d684cec70e
@ -46,25 +46,24 @@ void cImageCache::CacheLogo(int width, int height) {
|
||||
if (width == 0 || height == 0)
|
||||
return;
|
||||
|
||||
int channelsCached = 0;
|
||||
int logosCached = 0;
|
||||
|
||||
for (const cChannel *channel = Channels.First(); channel; channel = Channels.Next(channel)) {
|
||||
if (channelsCached >= config.numLogosPerSizeInitial)
|
||||
if (logosCached >= config.numLogosPerSizeInitial)
|
||||
break;
|
||||
if (channel->GroupSep()) {
|
||||
continue;
|
||||
}
|
||||
stringstream logoName;
|
||||
logoName << *channel->GetChannelID().ToString() << "_" << width << "x" << height;
|
||||
map<string, cImage*>::iterator hit = channelLogoCache.find(logoName.str());
|
||||
if (hit != channelLogoCache.end()) {
|
||||
continue;
|
||||
}
|
||||
bool success = LoadLogo(channel);
|
||||
if (success) {
|
||||
channelsCached++;
|
||||
logosCached++;
|
||||
cImage *image = CreateImage(width, height);
|
||||
stringstream logoName;
|
||||
logoName << *channel->GetChannelID().ToString() << "_" << width << "x" << height;
|
||||
std::map<std::string, cImage*>::iterator hit = channelLogoCache.find(logoName.str());
|
||||
if (hit != channelLogoCache.end()) {
|
||||
delete image;
|
||||
return;
|
||||
}
|
||||
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) {
|
||||
if (width < 1 || width > 1920 || height < 1 || height > 1080)
|
||||
return;
|
||||
bool success = LoadIcon(type, name);
|
||||
if (!success)
|
||||
return;
|
||||
stringstream iconName;
|
||||
iconName << name << "_" << width << "x" << height;
|
||||
cImage *image = CreateImage(width, height, true);
|
||||
iconCache.insert(pair<string, cImage*>(iconName.str(), image));
|
||||
GetIcon(type, name, width, 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) {
|
||||
if (width < 1 || width > 1920 || height < 1 || height > 1080)
|
||||
return;
|
||||
bool success = LoadSkinpart(name);
|
||||
if (!success)
|
||||
return;
|
||||
stringstream iconName;
|
||||
iconName << name << "_" << width << "x" << height;
|
||||
cImage *image = CreateImage(width, height, false);
|
||||
skinPartsCache.insert(pair<string, cImage*>(iconName.str(), image));
|
||||
GetSkinpart(name, width, height);
|
||||
}
|
||||
|
||||
cImage *cImageCache::GetSkinpart(string name, int width, int height) {
|
||||
|
@ -104,7 +104,6 @@ vector< pair<string, int> > cTemplate::GetUsedFonts(void) {
|
||||
|
||||
void cTemplate::CacheImages(void) {
|
||||
CacheImages(rootView);
|
||||
|
||||
rootView->InitSubViewIterator();
|
||||
cTemplateView *subView = NULL;
|
||||
while(subView = rootView->GetNextSubView()) {
|
||||
@ -113,9 +112,7 @@ void cTemplate::CacheImages(void) {
|
||||
}
|
||||
|
||||
void cTemplate::Debug(void) {
|
||||
|
||||
rootView->Debug();
|
||||
|
||||
}
|
||||
|
||||
/*******************************************************************
|
||||
@ -213,13 +210,7 @@ void cTemplate::CacheImages(cTemplateView *view) {
|
||||
viewElement->InitIterator();
|
||||
cTemplatePixmap *pix = NULL;
|
||||
while(pix = viewElement->GetNextPixmap()) {
|
||||
pix->InitIterator();
|
||||
cTemplateFunction *func = NULL;
|
||||
while(func = pix->GetNextFunction()) {
|
||||
if (func->GetType() == ftDrawImage) {
|
||||
CacheImage(func);
|
||||
}
|
||||
}
|
||||
CachePixmapImages(pix);
|
||||
}
|
||||
}
|
||||
//used images in viewLists pixmaps
|
||||
@ -229,40 +220,40 @@ void cTemplate::CacheImages(cTemplateView *view) {
|
||||
viewList->InitIterator();
|
||||
cTemplatePixmap *pix = NULL;
|
||||
while(pix = viewList->GetNextPixmap()) {
|
||||
pix->InitIterator();
|
||||
cTemplateFunction *func = NULL;
|
||||
while(func = pix->GetNextFunction()) {
|
||||
if (func->GetType() == ftDrawImage) {
|
||||
CacheImage(func);
|
||||
}
|
||||
}
|
||||
CachePixmapImages(pix);
|
||||
}
|
||||
cTemplateViewElement *listElement = viewList->GetListElement();
|
||||
listElement->InitIterator();
|
||||
while(pix = listElement->GetNextPixmap()) {
|
||||
pix->InitIterator();
|
||||
cTemplateFunction *func = NULL;
|
||||
while(func = pix->GetNextFunction()) {
|
||||
if (func->GetType() == ftDrawImage) {
|
||||
CacheImage(func);
|
||||
}
|
||||
}
|
||||
CachePixmapImages(pix);
|
||||
}
|
||||
cTemplateViewElement *currentElement = viewList->GetListElementCurrent();
|
||||
if (!currentElement) {
|
||||
continue;
|
||||
}
|
||||
currentElement->InitIterator();
|
||||
while(pix = currentElement->GetNextPixmap()) {
|
||||
CachePixmapImages(pix);
|
||||
}
|
||||
}
|
||||
//used logos in viewTabs
|
||||
//used images 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);
|
||||
}
|
||||
}
|
||||
CachePixmapImages(viewTab);
|
||||
}
|
||||
}
|
||||
|
||||
void cTemplate::CachePixmapImages(cTemplatePixmap *pix) {
|
||||
pix->InitIterator();
|
||||
cTemplateFunction *func = NULL;
|
||||
while(func = pix->GetNextFunction()) {
|
||||
if (func->GetType() == ftDrawImage) {
|
||||
CacheImage(func);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void cTemplate::CacheImage(cTemplateFunction *func) {
|
||||
eImageType imgType = (eImageType)func->GetNumericParameter(ptImageType);
|
||||
int width = func->GetNumericParameter(ptWidth);
|
||||
|
@ -32,6 +32,7 @@ enum eViewType {
|
||||
class cTemplate {
|
||||
private:
|
||||
eViewType viewType;
|
||||
void CachePixmapImages(cTemplatePixmap *pix);
|
||||
void CacheImage(cTemplateFunction *func);
|
||||
protected:
|
||||
cGlobals *globals;
|
||||
|
@ -25,26 +25,26 @@ public:
|
||||
// Data structure for service "RegisterPlugin"
|
||||
class RegisterPlugin {
|
||||
public:
|
||||
RegisterPlugin(void) {
|
||||
name = "";
|
||||
};
|
||||
void SetMenu(int key, string templateName) {
|
||||
menus.insert(pair<int, string>(key, templateName));
|
||||
}
|
||||
RegisterPlugin(void) {
|
||||
name = "";
|
||||
};
|
||||
void SetMenu(int key, string templateName) {
|
||||
menus.insert(pair<int, string>(key, templateName));
|
||||
}
|
||||
// in
|
||||
string name; //name of plugin
|
||||
map< int, string > menus; //menus as key -> templatename hashmap
|
||||
string name; //name of plugin
|
||||
map< int, string > menus; //menus as key -> templatename hashmap
|
||||
//out
|
||||
};
|
||||
|
||||
// Data structure for service "GetDisplayMenu"
|
||||
class GetDisplayMenu {
|
||||
public:
|
||||
GetDisplayMenu(void) {
|
||||
displayMenu = NULL;
|
||||
};
|
||||
GetDisplayMenu(void) {
|
||||
displayMenu = NULL;
|
||||
};
|
||||
// in
|
||||
//out
|
||||
cSDDisplayMenu *displayMenu;
|
||||
//out
|
||||
cSDDisplayMenu *displayMenu;
|
||||
};
|
||||
#endif //__SKINDESIGNERSERVICES_H
|
@ -4,11 +4,11 @@
|
||||
* cSkindesignerOsdItem
|
||||
**********************************************************************/
|
||||
cSkindesignerOsdItem::cSkindesignerOsdItem(eOSState State) : cOsdItem(State) {
|
||||
sdDisplayMenu = NULL;
|
||||
sdDisplayMenu = NULL;
|
||||
}
|
||||
|
||||
cSkindesignerOsdItem::cSkindesignerOsdItem(const char *Text, eOSState State, bool Selectable) : cOsdItem(Text, State, Selectable) {
|
||||
sdDisplayMenu = NULL;
|
||||
sdDisplayMenu = NULL;
|
||||
}
|
||||
|
||||
cSkindesignerOsdItem::~cSkindesignerOsdItem() {
|
||||
@ -16,33 +16,33 @@ cSkindesignerOsdItem::~cSkindesignerOsdItem() {
|
||||
}
|
||||
|
||||
void cSkindesignerOsdItem::SetMenuItem(cSkinDisplayMenu *DisplayMenu, int Index, bool Current, bool Selectable) {
|
||||
if (sdDisplayMenu) {
|
||||
if (!sdDisplayMenu->SetItemPlugin(&stringTokens, &intTokens, &loopTokens, Index, Current, Selectable)) {
|
||||
DisplayMenu->SetItem(Text(), Index, Current, Selectable);
|
||||
}
|
||||
} else {
|
||||
DisplayMenu->SetItem(Text(), Index, Current, Selectable);
|
||||
}
|
||||
if (sdDisplayMenu) {
|
||||
if (!sdDisplayMenu->SetItemPlugin(&stringTokens, &intTokens, &loopTokens, Index, Current, Selectable)) {
|
||||
DisplayMenu->SetItem(Text(), Index, Current, Selectable);
|
||||
}
|
||||
} else {
|
||||
DisplayMenu->SetItem(Text(), Index, Current, Selectable);
|
||||
}
|
||||
}
|
||||
|
||||
void cSkindesignerOsdItem::AddStringToken(string key, string value) {
|
||||
stringTokens.insert(pair<string,string>(key, value));
|
||||
stringTokens.insert(pair<string,string>(key, value));
|
||||
}
|
||||
|
||||
void cSkindesignerOsdItem::AddIntToken(string key, int value) {
|
||||
intTokens.insert(pair<string,int>(key, value));
|
||||
intTokens.insert(pair<string,int>(key, value));
|
||||
}
|
||||
|
||||
void cSkindesignerOsdItem::AddLoopToken(string loopName, map<string, string> &tokens) {
|
||||
map<string, vector<map<string, string> > >::iterator hitLoop = loopTokens.find(loopName);
|
||||
if (hitLoop == loopTokens.end()) {
|
||||
vector<map<string, string> > tokenVector;
|
||||
tokenVector.push_back(tokens);
|
||||
loopTokens.insert(pair<string, vector<map<string, string> > >(loopName, tokenVector));
|
||||
} else {
|
||||
vector<map<string, string> > *tokenVector = &hitLoop->second;
|
||||
tokenVector->push_back(tokens);
|
||||
}
|
||||
map<string, vector<map<string, string> > >::iterator hitLoop = loopTokens.find(loopName);
|
||||
if (hitLoop == loopTokens.end()) {
|
||||
vector<map<string, string> > tokenVector;
|
||||
tokenVector.push_back(tokens);
|
||||
loopTokens.insert(pair<string, vector<map<string, string> > >(loopName, tokenVector));
|
||||
} else {
|
||||
vector<map<string, string> > *tokenVector = &hitLoop->second;
|
||||
tokenVector->push_back(tokens);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -50,12 +50,12 @@ void cSkindesignerOsdItem::AddLoopToken(string loopName, map<string, string> &to
|
||||
* cSkindesignerOsdMenu
|
||||
**********************************************************************/
|
||||
cSkindesignerOsdMenu::cSkindesignerOsdMenu(const char *Title, int c0, int c1, int c2, int c3, int c4) : cOsdMenu(Title, c0, c1, c2, c3, c4) {
|
||||
init = true;
|
||||
init = true;
|
||||
displayText = false;
|
||||
sdDisplayMenu = NULL;
|
||||
pluginName = "";
|
||||
SetMenuCategory(mcPlugin);
|
||||
SetSkinDesignerDisplayMenu();
|
||||
sdDisplayMenu = NULL;
|
||||
pluginName = "";
|
||||
SetMenuCategory(mcPlugin);
|
||||
SetSkinDesignerDisplayMenu();
|
||||
}
|
||||
|
||||
cSkindesignerOsdMenu::~cSkindesignerOsdMenu() {
|
||||
@ -63,56 +63,56 @@ cSkindesignerOsdMenu::~cSkindesignerOsdMenu() {
|
||||
}
|
||||
|
||||
void cSkindesignerOsdMenu::SetPluginMenu(int menu, eMenuType type) {
|
||||
if (type == mtList)
|
||||
displayText = false;
|
||||
else if (type == mtText)
|
||||
displayText = true;
|
||||
if (type == mtList)
|
||||
displayText = false;
|
||||
else if (type == mtText)
|
||||
displayText = true;
|
||||
|
||||
if (sdDisplayMenu) {
|
||||
sdDisplayMenu->SetPluginMenu(pluginName, menu, type, init);
|
||||
}
|
||||
if (sdDisplayMenu) {
|
||||
sdDisplayMenu->SetPluginMenu(pluginName, menu, type, init);
|
||||
}
|
||||
init = false;
|
||||
}
|
||||
|
||||
bool cSkindesignerOsdMenu::SetSkinDesignerDisplayMenu(void) {
|
||||
static cPlugin *pSkinDesigner = cPluginManager::GetPlugin("skindesigner");
|
||||
if (!pSkinDesigner) {
|
||||
return false;
|
||||
}
|
||||
GetDisplayMenu call;
|
||||
bool ok = pSkinDesigner->Service("GetDisplayMenu", &call);
|
||||
if (ok && call.displayMenu) {
|
||||
sdDisplayMenu = call.displayMenu;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
static cPlugin *pSkinDesigner = cPluginManager::GetPlugin("skindesigner");
|
||||
if (!pSkinDesigner) {
|
||||
return false;
|
||||
}
|
||||
GetDisplayMenu call;
|
||||
bool ok = pSkinDesigner->Service("GetDisplayMenu", &call);
|
||||
if (ok && call.displayMenu) {
|
||||
sdDisplayMenu = call.displayMenu;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void cSkindesignerOsdMenu::ClearTokens(void) {
|
||||
text = "";
|
||||
text = "";
|
||||
stringTokens.clear();
|
||||
intTokens.clear();
|
||||
loopTokens.clear();
|
||||
}
|
||||
|
||||
void cSkindesignerOsdMenu::AddStringToken(string key, string value) {
|
||||
stringTokens.insert(pair<string,string>(key, value));
|
||||
stringTokens.insert(pair<string,string>(key, value));
|
||||
}
|
||||
|
||||
void cSkindesignerOsdMenu::AddIntToken(string key, int value) {
|
||||
intTokens.insert(pair<string,int>(key, value));
|
||||
intTokens.insert(pair<string,int>(key, value));
|
||||
}
|
||||
|
||||
void cSkindesignerOsdMenu::AddLoopToken(string loopName, map<string, string> &tokens) {
|
||||
map<string, vector<map<string, string> > >::iterator hitLoop = loopTokens.find(loopName);
|
||||
if (hitLoop == loopTokens.end()) {
|
||||
vector<map<string, string> > tokenVector;
|
||||
tokenVector.push_back(tokens);
|
||||
loopTokens.insert(pair<string, vector<map<string, string> > >(loopName, tokenVector));
|
||||
} else {
|
||||
vector<map<string, string> > *tokenVector = &hitLoop->second;
|
||||
tokenVector->push_back(tokens);
|
||||
}
|
||||
map<string, vector<map<string, string> > >::iterator hitLoop = loopTokens.find(loopName);
|
||||
if (hitLoop == loopTokens.end()) {
|
||||
vector<map<string, string> > tokenVector;
|
||||
tokenVector.push_back(tokens);
|
||||
loopTokens.insert(pair<string, vector<map<string, string> > >(loopName, tokenVector));
|
||||
} else {
|
||||
vector<map<string, string> > *tokenVector = &hitLoop->second;
|
||||
tokenVector->push_back(tokens);
|
||||
}
|
||||
}
|
||||
|
||||
void cSkindesignerOsdMenu::TextKeyLeft(void) {
|
||||
@ -140,9 +140,9 @@ void cSkindesignerOsdMenu::TextKeyDown(void) {
|
||||
}
|
||||
|
||||
void cSkindesignerOsdMenu::Display(void) {
|
||||
if (displayText) {
|
||||
if (sdDisplayMenu) {
|
||||
if (sdDisplayMenu->SetPluginText(&stringTokens, &intTokens, &loopTokens)) {
|
||||
if (displayText) {
|
||||
if (sdDisplayMenu) {
|
||||
if (sdDisplayMenu->SetPluginText(&stringTokens, &intTokens, &loopTokens)) {
|
||||
esyslog("skindesclient: template found");
|
||||
sdDisplayMenu->Flush();
|
||||
} else {
|
||||
@ -151,19 +151,19 @@ void cSkindesignerOsdMenu::Display(void) {
|
||||
DisplayMenu()->SetText(text.c_str(), false);
|
||||
DisplayMenu()->Flush();
|
||||
}
|
||||
} else {
|
||||
} else {
|
||||
DisplayMenu()->Clear();
|
||||
DisplayMenu()->SetText(text.c_str(), false);
|
||||
DisplayMenu()->SetText(text.c_str(), false);
|
||||
DisplayMenu()->Flush();
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (sdDisplayMenu) {
|
||||
for (cOsdItem *item = First(); item; item = Next(item)) {
|
||||
cSkindesignerOsdItem *sdItem = dynamic_cast<cSkindesignerOsdItem*>(item);
|
||||
if (sdItem)
|
||||
sdItem->SetDisplayMenu(sdDisplayMenu);
|
||||
}
|
||||
}
|
||||
cOsdMenu::Display();
|
||||
}
|
||||
if (sdDisplayMenu) {
|
||||
for (cOsdItem *item = First(); item; item = Next(item)) {
|
||||
cSkindesignerOsdItem *sdItem = dynamic_cast<cSkindesignerOsdItem*>(item);
|
||||
if (sdItem)
|
||||
sdItem->SetDisplayMenu(sdDisplayMenu);
|
||||
}
|
||||
}
|
||||
cOsdMenu::Display();
|
||||
}
|
||||
|
@ -12,8 +12,8 @@
|
||||
|
||||
class cSkindesignerOsdItem : public cOsdItem {
|
||||
private:
|
||||
cSDDisplayMenu *sdDisplayMenu;
|
||||
map < string, string > stringTokens;
|
||||
cSDDisplayMenu *sdDisplayMenu;
|
||||
map < string, string > stringTokens;
|
||||
map < string, int > intTokens;
|
||||
map < string, vector< map< string, string > > > loopTokens;
|
||||
protected:
|
||||
@ -22,9 +22,9 @@ public:
|
||||
cSkindesignerOsdItem(const char *Text, eOSState State = osUnknown, bool Selectable = true);
|
||||
virtual ~cSkindesignerOsdItem();
|
||||
virtual void SetMenuItem(cSkinDisplayMenu *DisplayMenu, int Index, bool Current, bool Selectable);
|
||||
void SetDisplayMenu(cSDDisplayMenu *sdDisplayMenu) { this->sdDisplayMenu = sdDisplayMenu; };
|
||||
void SetDisplayMenu(cSDDisplayMenu *sdDisplayMenu) { this->sdDisplayMenu = sdDisplayMenu; };
|
||||
void AddStringToken(string key, string value);
|
||||
void AddIntToken(string key, int value);
|
||||
void AddIntToken(string key, int value);
|
||||
void AddLoopToken(string loopName, map<string, string> &tokens);
|
||||
};
|
||||
|
||||
@ -34,16 +34,16 @@ private:
|
||||
bool init;
|
||||
bool displayText;
|
||||
string pluginName;
|
||||
cSDDisplayMenu *sdDisplayMenu;
|
||||
cSDDisplayMenu *sdDisplayMenu;
|
||||
string text;
|
||||
map < string, string > stringTokens;
|
||||
map < string, int > intTokens;
|
||||
map < string, vector< map< string, string > > > loopTokens;
|
||||
bool SetSkinDesignerDisplayMenu(void);
|
||||
bool SetSkinDesignerDisplayMenu(void);
|
||||
protected:
|
||||
void ClearTokens(void);
|
||||
void SetPluginName(string name) {pluginName = name; };
|
||||
void SetPluginMenu(int menu, eMenuType type);
|
||||
void SetPluginMenu(int menu, eMenuType type);
|
||||
void SetText(string text) { this->text = text; };
|
||||
void AddStringToken(string key, string value);
|
||||
void AddIntToken(string key, int value);
|
||||
|
@ -7,17 +7,17 @@
|
||||
#include "libskindesigner/skindesignerosdbase.h"
|
||||
|
||||
enum eMenus {
|
||||
meListMain,
|
||||
meListMain,
|
||||
meListSub,
|
||||
meDetail
|
||||
meDetail
|
||||
};
|
||||
|
||||
class cPlugOsdMenu : public cSkindesignerOsdMenu {
|
||||
private:
|
||||
void SetMenu(int numItems, bool subfolder = false);
|
||||
void SetMenu(int numItems, bool subfolder = false);
|
||||
void SetDetailView(int element);
|
||||
public:
|
||||
cPlugOsdMenu(void);
|
||||
cPlugOsdMenu(void);
|
||||
virtual ~cPlugOsdMenu();
|
||||
virtual eOSState ProcessKey(eKeys key);
|
||||
};
|
||||
@ -28,12 +28,12 @@ public:
|
||||
//***************************************************************************
|
||||
|
||||
cPlugOsdMenu::cPlugOsdMenu(void) : cSkindesignerOsdMenu("Skindesigner Client") {
|
||||
SetPluginName("skindesclient");
|
||||
SetMenu(10);
|
||||
SetPluginName("skindesclient");
|
||||
SetMenu(10);
|
||||
}
|
||||
|
||||
cPlugOsdMenu::~cPlugOsdMenu(void) {
|
||||
|
||||
|
||||
}
|
||||
|
||||
eOSState cPlugOsdMenu::ProcessKey(eKeys key) {
|
||||
|
@ -209,5 +209,5 @@
|
||||
</areascroll>
|
||||
</currentelement>
|
||||
</menuitems>
|
||||
</menuschedules>
|
||||
|
||||
</menuschedules>
|
Loading…
Reference in New Issue
Block a user