mirror of
git://projects.qi-hardware.com/gmenu2x.git
synced 2024-11-17 23:10:17 +02:00
Removed screenshot caching from Selector
The way the caching was implemented was rather problematic. Also I'm not convinced caching is useful at all. So I removed it. If at some point we decide that caching is a good idea, it would be best to re-implement it from scratch, so nothing of value is lost by removing the existing caching code. One problem was that the prepare method would check the existence of a screenshot file for every file in the directory, which adds to the noticable delay before showing a directory which holds many files. Another problem is there was no upper limit to the number of screenshots that would be cached. On directories with many screenshots the memory use could rise to several hundred megabytes, which can be problematic on some of the systems we want to support. Also there was a rather nasty hack present to ensure screenshots were loaded without an alpha channel. My main doubt about the usefulness of screenshot caching is that caching will only speed up the showing of an image from the second time onwards. In typical use, the average screenshot is displayed at most once. If the image load time is long enough to annoy the user, any real solution would have to work also for the first showing. For example, background (asynchronous) loading could be implemented.
This commit is contained in:
parent
3305cf289b
commit
1229ef32e5
@ -85,13 +85,13 @@ int Selector::exec(int startSelection) {
|
|||||||
unsigned int firstElement = 0;
|
unsigned int firstElement = 0;
|
||||||
unsigned int selected = constrain(startSelection, 0, fl.size() - 1);
|
unsigned int selected = constrain(startSelection, 0, fl.size() - 1);
|
||||||
|
|
||||||
vector<string> screens, titles;
|
vector<string> titles;
|
||||||
prepare(&fl,&screens,&titles);
|
prepare(&fl,&titles);
|
||||||
|
|
||||||
//Add the folder icon manually to be sure to load it with alpha support since we are going to disable it for screenshots
|
auto folderIcon = gmenu2x->sc.skinRes("imgs/folder.png");
|
||||||
if (gmenu2x->sc.skinRes("imgs/folder.png")==NULL)
|
if (!folderIcon) {
|
||||||
gmenu2x->sc.addSkinRes("imgs/folder.png");
|
folderIcon = gmenu2x->sc.addSkinRes("imgs/folder.png");
|
||||||
gmenu2x->sc.defaultAlpha = false;
|
}
|
||||||
|
|
||||||
bool close = false, result = true;
|
bool close = false, result = true;
|
||||||
while (!close) {
|
while (!close) {
|
||||||
@ -105,9 +105,10 @@ int Selector::exec(int startSelection) {
|
|||||||
firstElement = selected;
|
firstElement = selected;
|
||||||
|
|
||||||
//Screenshot
|
//Screenshot
|
||||||
if (selected-fl.dirCount()<screens.size()
|
if (fl.isFile(selected)) {
|
||||||
&& !screens[selected-fl.dirCount()].empty()) {
|
string& noext = titles[selected - fl.dirCount()];
|
||||||
Surface *screenshot = gmenu2x->sc[screens[selected-fl.dirCount()]];
|
string path = screendir + noext + ".png";
|
||||||
|
auto screenshot = OffscreenSurface::loadImage(path, "", false);
|
||||||
if (screenshot) {
|
if (screenshot) {
|
||||||
screenshot->blitRight(s, 320, 0, 320, 240, 128u);
|
screenshot->blitRight(s, 320, 0, 320, 240, 128u);
|
||||||
}
|
}
|
||||||
@ -124,7 +125,7 @@ int Selector::exec(int startSelection) {
|
|||||||
&& i < firstElement + nb_elements; i++) {
|
&& i < firstElement + nb_elements; i++) {
|
||||||
iY = i-firstElement;
|
iY = i-firstElement;
|
||||||
if (fl.isDirectory(i)) {
|
if (fl.isDirectory(i)) {
|
||||||
gmenu2x->sc["imgs/folder.png"]->blit(s, 4, top + (iY * fontheight));
|
folderIcon->blit(s, 4, top + (iY * fontheight));
|
||||||
gmenu2x->font->write(s, fl[i], 21,
|
gmenu2x->font->write(s, fl[i], 21,
|
||||||
top + (iY * fontheight) + (fontheight / 2),
|
top + (iY * fontheight) + (fontheight / 2),
|
||||||
Font::HAlignLeft, Font::VAlignMiddle);
|
Font::HAlignLeft, Font::VAlignMiddle);
|
||||||
@ -185,7 +186,7 @@ int Selector::exec(int startSelection) {
|
|||||||
dir = dir.substr(0,p+1);
|
dir = dir.substr(0,p+1);
|
||||||
selected = 0;
|
selected = 0;
|
||||||
firstElement = 0;
|
firstElement = 0;
|
||||||
prepare(&fl,&screens,&titles);
|
prepare(&fl,&titles);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -202,7 +203,7 @@ int Selector::exec(int startSelection) {
|
|||||||
|
|
||||||
selected = 0;
|
selected = 0;
|
||||||
firstElement = 0;
|
firstElement = 0;
|
||||||
prepare(&fl,&screens,&titles);
|
prepare(&fl,&titles);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -211,19 +212,14 @@ int Selector::exec(int startSelection) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
gmenu2x->sc.defaultAlpha = true;
|
|
||||||
freeScreenshots(&screens);
|
|
||||||
|
|
||||||
return result ? (int)selected : -1;
|
return result ? (int)selected : -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Selector::prepare(FileLister *fl, vector<string> *screens, vector<string> *titles) {
|
void Selector::prepare(FileLister *fl, vector<string> *titles) {
|
||||||
fl->setPath(dir);
|
fl->setPath(dir);
|
||||||
freeScreenshots(screens);
|
|
||||||
screens->resize(fl->getFiles().size());
|
|
||||||
titles->resize(fl->getFiles().size());
|
titles->resize(fl->getFiles().size());
|
||||||
|
|
||||||
string screendir = dir;
|
screendir = dir;
|
||||||
if (!screendir.empty() && screendir[screendir.length() - 1] != '/') {
|
if (!screendir.empty() && screendir[screendir.length() - 1] != '/') {
|
||||||
screendir += "/";
|
screendir += "/";
|
||||||
}
|
}
|
||||||
@ -237,19 +233,5 @@ void Selector::prepare(FileLister *fl, vector<string> *screens, vector<string> *
|
|||||||
if (pos!=string::npos && pos>0)
|
if (pos!=string::npos && pos>0)
|
||||||
noext = noext.substr(0, pos);
|
noext = noext.substr(0, pos);
|
||||||
titles->at(i) = noext;
|
titles->at(i) = noext;
|
||||||
|
|
||||||
DEBUG("Searching for screen '%s%s.png'\n", screendir.c_str(), noext.c_str());
|
|
||||||
|
|
||||||
if (fileExists(screendir+noext+".png"))
|
|
||||||
screens->at(i) = screendir+noext+".png";
|
|
||||||
else
|
|
||||||
screens->at(i) = "";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void Selector::freeScreenshots(vector<string> *screens) {
|
|
||||||
for (uint i=0; i<screens->size(); i++) {
|
|
||||||
if (!screens->at(i).empty())
|
|
||||||
gmenu2x->sc.del(screens->at(i));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -34,11 +34,9 @@ class Selector : protected Dialog {
|
|||||||
private:
|
private:
|
||||||
int selRow;
|
int selRow;
|
||||||
LinkApp *link;
|
LinkApp *link;
|
||||||
std::string file, dir;
|
std::string file, dir, screendir;
|
||||||
|
|
||||||
void prepare(FileLister *fl, std::vector<std::string> *screens,
|
void prepare(FileLister *fl, std::vector<std::string> *titles);
|
||||||
std::vector<std::string> *titles);
|
|
||||||
void freeScreenshots(std::vector<std::string> *screens);
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Selector(GMenu2X *gmenu2x, LinkApp *link,
|
Selector(GMenu2X *gmenu2x, LinkApp *link,
|
||||||
|
Loading…
Reference in New Issue
Block a user