diff options
author | Philipp Erhardt <Philipp.Erhardt@informatik.stud.uni-erlangen.de> | 2016-03-22 22:50:05 +0100 |
---|---|---|
committer | Philipp Erhardt <Philipp.Erhardt@informatik.stud.uni-erlangen.de> | 2016-03-22 22:50:05 +0100 |
commit | 6e775cd09a3b7a253255d0293253e2367277f527 (patch) | |
tree | 9994d226c05dc8248f3473ad567b647169a10771 | |
parent | 272f7772511a7578a10a676c9e0d3d54e193d198 (diff) |
Improve render queue for presenterlayout
-rw-r--r-- | src/resourcemanager.cpp | 54 | ||||
-rw-r--r-- | src/resourcemanager.h | 17 | ||||
-rw-r--r-- | src/worker.cpp | 34 |
3 files changed, 76 insertions, 29 deletions
diff --git a/src/resourcemanager.cpp b/src/resourcemanager.cpp index 8c3de19..d0d7d12 100644 --- a/src/resourcemanager.cpp +++ b/src/resourcemanager.cpp @@ -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(); } diff --git a/src/resourcemanager.h b/src/resourcemanager.h index e83525f..c0e38f0 100644 --- a/src/resourcemanager.h +++ b/src/resourcemanager.h @@ -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; diff --git a/src/worker.cpp b/src/worker.cpp index d978121..47572e4 100644 --- a/src/worker.cpp +++ b/src/worker.cpp @@ -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(); |