Commit 6e775cd0 authored by Philipp Erhardt's avatar Philipp Erhardt
Browse files

Improve render queue for presenterlayout

parent 272f7772
Pipeline #318 skipped
......@@ -20,6 +20,42 @@
using namespace std;
Request::Request(int width, int index) {
for (int i = 0; i < 3; i++) {
this->width[i] = -1;
}
this->width[index] = width;
}
int Request::get_lowest_index() {
for (int i = 0; i < 3; i++) {
if (width[i] != -1) {
return i;
}
}
// will not happen
return 0;
}
bool Request::has_index(int index) {
return width[index] != -1;
}
bool Request::remove_index_ok(int index) {
width[index] = -1;
for (int i = 0; i < 3; i++) {
if (width[i] != -1) {
return true;
}
}
return false;
}
void Request::update(int width, int index) {
this->width[index] = width;
}
ResourceManager::ResourceManager(const QString &file, Viewer *v) :
viewer(v),
file(file),
......@@ -251,10 +287,12 @@ void ResourceManager::collect_garbage(int keep_min, int keep_max, int index) {
return;
}
requestMutex.lock();
for (map<int,pair<int,int> >::iterator it = requests.begin(); it != requests.end(); ) {
if (it->first < keep_min || it->first > keep_max) {
requestSemaphore.acquire(1);
requests.erase(it++);
for (map<int,Request>::iterator it = requests.begin(); it != requests.end(); ) {
if ((it->first < keep_min || it->first > keep_max) && it->second.has_index(index)) {
if (!it->second.remove_index_ok(index)) { // no index left in request -> delete
requestSemaphore.acquire(1);
requests.erase(it++);
}
} else {
++it;
}
......@@ -350,14 +388,12 @@ void ResourceManager::inotify_slot() {
void ResourceManager::enqueue(int page, int width, int index) {
requestMutex.lock();
map<int,pair<int,int> >::iterator it = requests.find(page);
map<int,Request>::iterator it = requests.find(page);
if (it == requests.end()) {
requests[page] = make_pair(index, width);
requests.insert(make_pair(page, Request(width, index)));
requestSemaphore.release(1);
} else {
if (index <= it->second.first) {
it->second = make_pair(index, width);
}
it->second.update(width, index);
}
requestMutex.unlock();
}
......
......@@ -26,6 +26,19 @@ class QDomDocument;
class SelectionLine;
class Request {
public:
Request(int width, int index);
int get_lowest_index();
bool has_index(int index);
bool remove_index_ok(int index);
void update(int width, int index);
int width[3];
};
class ResourceManager : public QObject {
Q_OBJECT
......@@ -94,8 +107,8 @@ private:
int center_page;
float max_aspect;
float min_aspect;
std::map<int,std::pair<int,int> > requests; // page, index, width
std::set<int> garbage;
std::map<int, Request> requests; // page, index, width
std::set<int> garbage[3];
QMutex link_mutex;
KPage *k_page;
......
......@@ -35,34 +35,32 @@ void Worker::run() {
// get next page to render
res->requestMutex.lock();
int page, width, index;
map<int,pair<int,int> >::iterator less = res->requests.lower_bound(res->center_page);
map<int,pair<int,int> >::iterator greater = less--;
map<int,Request>::iterator less = res->requests.lower_bound(res->center_page);
map<int,Request>::iterator greater = less--;
map<int,Request>::iterator closest;
if (greater != res->requests.end()) {
if (greater != res->requests.begin()) {
// favour nearby page, go down first
if (greater->first + less->first <= res->center_page * 2) {
page = greater->first;
index = greater->second.first;
width = greater->second.second;
res->requests.erase(greater);
closest = greater;
} else {
page = less->first;
index = less->second.first;
width = less->second.second;
res->requests.erase(less);
closest = less;
}
} else {
page = greater->first;
index = greater->second.first;
width = greater->second.second;
res->requests.erase(greater);
closest = greater;
}
} else {
page = less->first;
index = less->second.first;
width = less->second.second;
res->requests.erase(less);
closest = less;
}
page = closest->first;
index = closest->second.get_lowest_index();
width = closest->second.width[index];
if (closest->second.remove_index_ok(index)) {
res->requestSemaphore.release(1);
} else {
res->requests.erase(closest);
}
res->requestMutex.unlock();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment