From 1bfe8610c9d8a7682bba11d48a09d86333a39c62 Mon Sep 17 00:00:00 2001 From: Mailson Menezes Date: Sun, 19 Aug 2012 22:43:59 -0300 Subject: [PATCH] Do not evict visible tiles Also avoid trying to evict more tiles if the tiles manager is empty (all tiles were previously removed) --- core/document.cpp | 2 +- core/tilesmanager.cpp | 17 +++++++++++++++++ core/tilesmanager_p.h | 11 ++++++++++- ui/pageview.cpp | 10 +++++++++- 4 files changed, 37 insertions(+), 3 deletions(-) diff --git a/core/document.cpp b/core/document.cpp index 7551035c7..4acd65371 100644 --- a/core/document.cpp +++ b/core/document.cpp @@ -260,7 +260,7 @@ void DocumentPrivate::cleanupPixmapMemory( qulonglong memoryToFree ) AllocatedPixmap * p = *pIt; TilesManager *tilesManager = m_pagesVector.at( p->page )->tilesManager( p->id ); - if ( tilesManager ) + if ( tilesManager && tilesManager->totalMemory() > 0 ) { tilesManager->cleanupPixmapMemory( memoryToFree ); m_allocatedPixmapsTotalMemory -= p->memory; diff --git a/core/tilesmanager.cpp b/core/tilesmanager.cpp index 5e789846e..418d62986 100644 --- a/core/tilesmanager.cpp +++ b/core/tilesmanager.cpp @@ -64,6 +64,7 @@ class TilesManager::Private int height; long totalPixels; Rotation rotation; + NormalizedRect visibleRect; QList rankedTiles; QSize tileSize; @@ -166,6 +167,19 @@ void TilesManager::Private::markDirty( Tile &tile ) } } +void TilesManager::setVisibleRect( const NormalizedRect &rect ) +{ + if ( d->visibleRect == rect ) + return; + + d->visibleRect = rect; +} + +NormalizedRect TilesManager::visibleRect() const +{ + return d->visibleRect; +} + void TilesManager::setPixmap( const QPixmap *pixmap, const NormalizedRect &rect ) { for ( int i = 0; i < 16; ++i ) @@ -385,6 +399,9 @@ void TilesManager::cleanupPixmapMemory( qulonglong numberOfBytes ) if ( !tile->pixmap ) continue; + if ( tile->rect.intersects( d->visibleRect ) ) + continue; + long pixels = tile->pixmap->width()*tile->pixmap->height(); d->totalPixels -= pixels; if ( numberOfBytes < 4*pixels ) diff --git a/core/tilesmanager_p.h b/core/tilesmanager_p.h index 2b327fdf4..fba5eded3 100644 --- a/core/tilesmanager_p.h +++ b/core/tilesmanager_p.h @@ -109,7 +109,6 @@ class OKULAR_EXPORT TilesManager */ void cleanupPixmapMemory( qulonglong numberOfBytes = 1 ); - /** * Inform the new width of the page and mark all tiles to repaint */ @@ -124,6 +123,16 @@ class OKULAR_EXPORT TilesManager void setRotation( Rotation rotation ); Rotation rotation() const; + /** + * Sets the visible area of the page + */ + void setVisibleRect( const NormalizedRect &rect ); + + /** + * Returns the visible area of the page + */ + NormalizedRect visibleRect() const; + /** * Returns a rotated NormalizedRect given a @p rotation */ diff --git a/ui/pageview.cpp b/ui/pageview.cpp index e65b94395..6b8dd0bc4 100644 --- a/ui/pageview.cpp +++ b/ui/pageview.cpp @@ -3989,7 +3989,12 @@ void PageView::slotRequestVisiblePixmaps( int newValue ) // if the item doesn't intersect the viewport, skip it QRect intersectionRect = viewportRect.intersect( i->croppedGeometry() ); if ( intersectionRect.isEmpty() ) + { + Okular::TilesManager *tilesManager = i->page()->tilesManager( PAGEVIEW_ID ); + if ( tilesManager ) + tilesManager->setVisibleRect( Okular::NormalizedRect() ); continue; + } // add the item to the 'visible list' d->visibleItems.push_back( i ); @@ -4001,6 +4006,10 @@ void PageView::slotRequestVisiblePixmaps( int newValue ) #endif visibleRect = vItem->rect; + Okular::TilesManager *tilesManager = i->page()->tilesManager( PAGEVIEW_ID ); + if ( tilesManager ) + tilesManager->setVisibleRect( vItem->rect ); + Okular::NormalizedRect expandedVisibleRect = vItem->rect; if ( Okular::Settings::memoryLevel() != Okular::Settings::EnumMemoryLevel::Low ) { @@ -4021,7 +4030,6 @@ void PageView::slotRequestVisiblePixmaps( int newValue ) PAGEVIEW_ID, i->pageNumber(), i->uncroppedWidth(), i->uncroppedHeight(), PAGEVIEW_PRIO, true ); requestedPixmaps.push_back( p ); - Okular::TilesManager *tilesManager = i->page()->tilesManager( PAGEVIEW_ID ); if ( tilesManager ) { Okular::NormalizedRect tilesRect;