From 4d8ba36488f84175b71af36bc2c487290ec753a7 Mon Sep 17 00:00:00 2001 From: Albert Astals Cid Date: Fri, 9 Mar 2012 00:12:20 +0100 Subject: [PATCH] Add greedy preloading option Based on a patch by Sebastian Rose REVIEW: 103129 BUGS: 184196 --- conf/dlgperformance.cpp | 4 +- conf/dlgperformancebase.ui | 183 +++++++++++++++++++------------------ conf/okular.kcfg | 1 + core/document.cpp | 10 ++ ui/pageview.cpp | 8 +- ui/presentationwidget.cpp | 16 +++- 6 files changed, 129 insertions(+), 93 deletions(-) diff --git a/conf/dlgperformance.cpp b/conf/dlgperformance.cpp index fd0e30bfa..45dc2d895 100644 --- a/conf/dlgperformance.cpp +++ b/conf/dlgperformance.cpp @@ -48,7 +48,9 @@ void DlgPerformance::radioGroup_changed( int which ) case 2: m_dlg->descLabel->setText( i18n("Keeps everything in memory. Preload next pages. Boost searches. (For systems with more than 512MB of memory.)") ); break; - + case 3: + m_dlg->descLabel->setText( i18n("Loads and keeps everything in memory. Preload all pages. (Will use at maximum 50% of your total memory or your free memory, whatever is bigger.)")); + break; } } diff --git a/conf/dlgperformancebase.ui b/conf/dlgperformancebase.ui index b022f5694..8d58c9418 100644 --- a/conf/dlgperformancebase.ui +++ b/conf/dlgperformancebase.ui @@ -1,59 +1,60 @@ - + + DlgPerformanceBase - - + + 0 0 - 303 - 256 + 316 + 289 - - - 0 - - + + 6 + + 0 + - - + + CPU Usage - - - 9 - - + + 6 + + 9 + - - - 0 - - + + 6 + + 0 + - - - 0 - - + + 6 + + 0 + - - + + Enable &transparency effects - - + + Enable &background generation @@ -61,19 +62,17 @@ - - - 0 - - + + 6 + + 0 + - - - - 0 - 0 + + + 0 0 @@ -82,13 +81,13 @@ - + Qt::Vertical - + QSizePolicy::Minimum - + 21 1 @@ -104,70 +103,75 @@ - - + + Memory Usage - - - 9 - - + + 6 + + 9 + - - - 0 - - + + 6 + + 0 + - - - 0 - - + + 6 + + 0 + - - + + &Low - - + + &Normal (default) - - + + &Aggressive + + + + &Greedy + + + - - - 0 - - + + 6 + + 0 + - - - - 0 - 0 + + + 0 0 @@ -176,13 +180,13 @@ - + Qt::Vertical - + QSizePolicy::Minimum - + 21 1 @@ -195,17 +199,17 @@ - - + + - + Qt::PlainText - + Qt::AlignVCenter - + true @@ -215,13 +219,13 @@ - + Qt::Vertical - + QSizePolicy::Expanding - + 20 4 @@ -237,11 +241,10 @@ QGroupBox
kbuttongroup.h
1 - - kiconloader.h + kiconloader.h diff --git a/conf/okular.kcfg b/conf/okular.kcfg index b1373b3e2..5cd4ee2e4 100644 --- a/conf/okular.kcfg +++ b/conf/okular.kcfg @@ -59,6 +59,7 @@ + diff --git a/core/document.cpp b/core/document.cpp index 74757f168..76b33cecd 100644 --- a/core/document.cpp +++ b/core/document.cpp @@ -199,6 +199,12 @@ void DocumentPrivate::cleanupPixmapMemory( qulonglong /*sure? bytesOffset*/ ) if (m_allocatedPixmapsTotalMemory > freeMemory) clipValue = (m_allocatedPixmapsTotalMemory - freeMemory) / 2; } break; + case Settings::EnumMemoryLevel::Greedy: + { + const qulonglong memoryLimit = qMax(getFreeMemory(), getTotalMemory() / 2); + if (m_allocatedPixmapsTotalMemory > memoryLimit) clipValue = (m_allocatedPixmapsTotalMemory - memoryLimit) / 2; + } + break; } if ( clipValue > memoryToFree ) @@ -3589,6 +3595,10 @@ void DocumentPrivate::calculateMaxTextPages() case Settings::EnumMemoryLevel::Aggressive: m_maxAllocatedTextPages = multipliers * 250; break; + + case Settings::EnumMemoryLevel::Greedy: + m_maxAllocatedTextPages = multipliers * 1250; + break; } } diff --git a/ui/pageview.cpp b/ui/pageview.cpp index 28835ed19..7dbc47479 100644 --- a/ui/pageview.cpp +++ b/ui/pageview.cpp @@ -1209,7 +1209,8 @@ void PageView::notifyZoom( int factor ) bool PageView::canUnloadPixmap( int pageNumber ) const { - if ( Okular::Settings::memoryLevel() != Okular::Settings::EnumMemoryLevel::Aggressive ) + if ( Okular::Settings::memoryLevel() == Okular::Settings::EnumMemoryLevel::Low || + Okular::Settings::memoryLevel() == Okular::Settings::EnumMemoryLevel::Normal ) { // if the item is visible, forbid unloading QLinkedList< PageViewItem * >::const_iterator vIt = d->visibleItems.constBegin(), vEnd = d->visibleItems.constEnd(); @@ -3945,6 +3946,11 @@ void PageView::slotRequestVisiblePixmaps( int newValue ) // request first the next page and then the previous int pagesToPreload = viewColumns(); + + // if the greedy option is set, preload all pages + if (Okular::Settings::memoryLevel() == Okular::Settings::EnumMemoryLevel::Greedy) + pagesToPreload = d->items.count(); + for( int j = 1; j <= pagesToPreload; j++ ) { // add the page after the 'visible series' in preload diff --git a/ui/presentationwidget.cpp b/ui/presentationwidget.cpp index bbeb9f5d6..6a8ef27c1 100644 --- a/ui/presentationwidget.cpp +++ b/ui/presentationwidget.cpp @@ -356,7 +356,8 @@ void PresentationWidget::notifyPageChanged( int pageNumber, int changedFlags ) bool PresentationWidget::canUnloadPixmap( int pageNumber ) const { - if ( Okular::Settings::memoryLevel() != Okular::Settings::EnumMemoryLevel::Aggressive ) + if ( Okular::Settings::memoryLevel() == Okular::Settings::EnumMemoryLevel::Low || + Okular::Settings::memoryLevel() == Okular::Settings::EnumMemoryLevel::Normal ) { // can unload all pixmaps except for the currently visible one return pageNumber != m_frameIndex; @@ -1162,6 +1163,19 @@ void PresentationWidget::requestPixmaps() if ( !prevFrame->page->hasPixmap( PRESENTATION_ID, pixW, pixH ) ) requests.push_back( new Okular::PixmapRequest( PRESENTATION_ID, m_frameIndex - 1, pixW, pixH, PRESENTATION_PRELOAD_PRIO, true ) ); } + + // If greedy, preload everything + if (Okular::Settings::memoryLevel() == Okular::Settings::EnumMemoryLevel::Greedy) + { + for(int i = 0; i < (int)m_document->pages(); ++i) + { + PresentationFrame *loopFrame = m_frames[ i ]; + pixW = loopFrame->geometry.width(); + pixH = loopFrame->geometry.height(); + if ( !loopFrame->page->hasPixmap( PRESENTATION_ID, pixW, pixH )) + requests.push_back( new Okular::PixmapRequest( PRESENTATION_ID, i, pixW, pixH, PRESENTATION_PRELOAD_PRIO, true ) ); + } + } } m_document->requestPixmaps( requests ); }