From e12966b25924ccf6edd10c11aff3bf29ececdc83 Mon Sep 17 00:00:00 2001 From: Fabio D'Urso Date: Thu, 8 Nov 2012 20:46:47 +0100 Subject: [PATCH] Removed possibility to have a tiles manager per observer Now only the PageView can have a tiles manager. --- core/document.cpp | 33 +++++++++++++++------------- core/document_p.h | 2 +- core/page.cpp | 55 +++++++++++++++++----------------------------- core/page.h | 11 ++++------ core/page_p.h | 7 +++++- ui/pagepainter.cpp | 3 ++- ui/pageview.cpp | 10 ++++----- 7 files changed, 56 insertions(+), 65 deletions(-) diff --git a/core/document.cpp b/core/document.cpp index a4b877f35..17147796d 100644 --- a/core/document.cpp +++ b/core/document.cpp @@ -266,11 +266,11 @@ void DocumentPrivate::cleanupPixmapMemory( qulonglong memoryToFree ) QLinkedList< AllocatedPixmap * > pixmapsToKeep; while ( memoryToFree > 0 ) { - AllocatedPixmap * p = searchLowestPriorityPixmap( false, true ); + AllocatedPixmap * p = searchLowestPriorityPixmap( false, true, PAGEVIEW_ID ); if ( !p ) // No pixmap to remove break; - TilesManager *tilesManager = m_pagesVector.at( p->page )->tilesManager( p->id ); + TilesManager *tilesManager = m_pagesVector.at( p->page )->tilesManager(); if ( tilesManager && tilesManager->totalMemory() > 0 ) { qulonglong memoryDiff = p->memory; @@ -305,7 +305,7 @@ void DocumentPrivate::cleanupPixmapMemory( qulonglong memoryToFree ) * thenRemoveIt is set, the pixmap is removed from m_allocatedPixmaps before * returning it */ -AllocatedPixmap * DocumentPrivate::searchLowestPriorityPixmap( bool unloadableOnly, bool thenRemoveIt ) +AllocatedPixmap * DocumentPrivate::searchLowestPriorityPixmap( bool unloadableOnly, bool thenRemoveIt, int observerId ) { QLinkedList< AllocatedPixmap * >::iterator pIt = m_allocatedPixmaps.begin(); QLinkedList< AllocatedPixmap * >::iterator pEnd = m_allocatedPixmaps.end(); @@ -317,11 +317,15 @@ AllocatedPixmap * DocumentPrivate::searchLowestPriorityPixmap( bool unloadableOn while ( pIt != pEnd ) { const AllocatedPixmap * p = *pIt; - const int distance = qAbs( p->page - currentViewportPage ); - if ( maxDistance < distance && ( !unloadableOnly || m_observers.value( p->id )->canUnloadPixmap( p->page ) ) ) + // Filter by observer + if ( observerId == -1 || p->id == observerId ) { - maxDistance = distance; - farthestPixmap = pIt; + const int distance = qAbs( p->page - currentViewportPage ); + if ( maxDistance < distance && ( !unloadableOnly || m_observers.value( p->id )->canUnloadPixmap( p->page ) ) ) + { + maxDistance = distance; + farthestPixmap = pIt; + } } ++pIt; } @@ -1049,7 +1053,7 @@ void DocumentPrivate::sendGeneratorRequest() } QRect requestRect = r->isTile() ? r->normalizedRect().geometry( r->width(), r->height() ) : QRect( 0, 0, r->width(), r->height() ); - TilesManager *tilesManager = r->page()->tilesManager( r->id() ); + TilesManager *tilesManager = ( r->id() == PAGEVIEW_ID ) ? r->page()->tilesManager() : 0; // request only if page isn't already present or request has invalid id if ( ( !r->d->mForce && r->page()->hasPixmap( r->id(), r->width(), r->height(), r->normalizedRect() ) ) || r->id() <= 0 || r->id() >= MAX_OBSERVER_ID ) @@ -1092,7 +1096,7 @@ void DocumentPrivate::sendGeneratorRequest() } tilesManager->setRequest( r->normalizedRect(), r->width(), r->height() ); r->page()->deletePixmap( r->id() ); - r->page()->setTilesManager( r->id(), tilesManager ); + r->page()->d->setTilesManager( tilesManager ); r->setTile( true ); // Change normalizedRect to the smallest rect that contains all @@ -1157,7 +1161,7 @@ void DocumentPrivate::sendGeneratorRequest() // [MEM] preventive memory freeing qulonglong pixmapBytes = 0; - TilesManager * tm = request->page()->tilesManager( request->id() ); + TilesManager * tm = ( request->id() == PAGEVIEW_ID ) ? request->page()->tilesManager() : 0; if ( tm ) pixmapBytes = tm->totalMemory(); else @@ -1289,13 +1293,12 @@ void DocumentPrivate::refreshPixmaps( int pageNumber ) requestedPixmaps.push_back( p ); } - QMap< int, TilesManager* >::const_iterator tmIt = page->d->m_tilesManagers.constBegin(), tmEnd = page->d->m_tilesManagers.constEnd(); - for ( ; tmIt != tmEnd; tmIt++ ) + TilesManager *tilesManager = page->tilesManager(); + if ( tilesManager ) { - TilesManager * tilesManager = *tmIt; tilesManager->markDirty(); - PixmapRequest * p = new PixmapRequest( tmIt.key(), pageNumber, tilesManager->width(), tilesManager->height(), 1, true ); + PixmapRequest * p = new PixmapRequest( PAGEVIEW_ID, pageNumber, tilesManager->width(), tilesManager->height(), 1, true ); NormalizedRect tilesRect; @@ -4062,7 +4065,7 @@ void DocumentPrivate::requestDone( PixmapRequest * req ) { // [MEM] 1.2 append memory allocation descriptor to the FIFO qulonglong memoryBytes = 0; - const TilesManager *tm = req->page()->tilesManager( req->id() ); + const TilesManager *tm = ( req->id() == PAGEVIEW_ID ) ? req->page()->tilesManager() : 0; if ( tm ) memoryBytes = tm->totalMemory(); else diff --git a/core/document_p.h b/core/document_p.h index c9a80fe2b..e51cae380 100644 --- a/core/document_p.h +++ b/core/document_p.h @@ -98,7 +98,7 @@ class DocumentPrivate qulonglong calculateMemoryToFree(); void cleanupPixmapMemory(); void cleanupPixmapMemory( qulonglong memoryToFree ); - AllocatedPixmap * searchLowestPriorityPixmap( bool unloadableOnly = false, bool thenRemoveIt = false ); + AllocatedPixmap * searchLowestPriorityPixmap( bool unloadableOnly = false, bool thenRemoveIt = false, int observerId = -1 /* any */ ); void calculateMaxTextPages(); qulonglong getTotalMemory(); qulonglong getFreeMemory( qulonglong *freeSwap = 0 ); diff --git a/core/page.cpp b/core/page.cpp index d02cd2e0d..c3c6cc094 100644 --- a/core/page.cpp +++ b/core/page.cpp @@ -62,7 +62,7 @@ static void deleteObjectRects( QLinkedList< ObjectRect * >& rects, const QSettilesManager( job->id() ); + TilesManager *tm = ( job->id() == PAGEVIEW_ID ) ? m_page->tilesManager() : 0; if ( tm ) { QPixmap *pixmap = new QPixmap( QPixmap::fromImage( job->image() ) ); @@ -214,7 +214,7 @@ void Page::setBoundingBox( const NormalizedRect& bbox ) bool Page::hasPixmap( int id, int width, int height, const NormalizedRect &rect ) const { - TilesManager *tm = tilesManager( id ); + TilesManager *tm = ( id == PAGEVIEW_ID ) ? tilesManager() : 0; if ( tm ) { if ( width != tm->width() || height != tm->height() ) @@ -391,16 +391,10 @@ void PagePrivate::rotateAt( Rotation orientation ) } /** - * Rotate tiles managers + * Rotate tiles manager */ - QMapIterator< int, TilesManager* > tIt( m_tilesManagers ); - while ( it.hasNext() ) - { - it.next(); - - TilesManager *tilesManager = tIt.value(); - tilesManager->setRotation( m_rotation ); - } + if ( m_tilesManager ) + m_tilesManager->setRotation( m_rotation ); /** * Rotate the object rects on the page. @@ -498,7 +492,7 @@ QLinkedList< FormField * > Page::formFields() const void Page::setPixmap( int id, QPixmap *pixmap, const NormalizedRect &rect ) { if ( d->m_rotation == Rotation0 ) { - TilesManager *tm = tilesManager( id ); + TilesManager *tm = ( id == PAGEVIEW_ID ) ? tilesManager() : 0; if ( tm ) { tm->setPixmap( pixmap, rect ); @@ -703,9 +697,11 @@ void Page::setFormFields( const QLinkedList< FormField * >& fields ) void Page::deletePixmap( int id ) { - TilesManager *tm = d->m_tilesManagers.take( id ); - if ( tm ) - delete tm; + if ( id == PAGEVIEW_ID && d->m_tilesManager ) + { + delete d->m_tilesManager; + d->m_tilesManager = 0; + } else { PagePrivate::PixmapObject object = d->m_pixmaps.take( id ); @@ -722,8 +718,8 @@ void Page::deletePixmaps() } d->m_pixmaps.clear(); - qDeleteAll( d->m_tilesManagers ); - d->m_tilesManagers.clear(); + delete d->m_tilesManager; + d->m_tilesManager = 0; } void Page::deleteRects() @@ -978,25 +974,14 @@ const QPixmap * Page::_o_nearestPixmap( int pixID, int w, int h ) const return pixmap; } -TilesManager *Page::tilesManager( int id ) const +TilesManager *Page::tilesManager() const { - TilesManager *tilesManager = 0; - - QMap< int, TilesManager* >::iterator itTilesManager = d->m_tilesManagers.find( id ); - if ( itTilesManager != d->m_tilesManagers.end() ) - tilesManager = *itTilesManager; - - return tilesManager; + return d->m_tilesManager; } -void Page::setTilesManager( int id, TilesManager *tm ) +void PagePrivate::setTilesManager( TilesManager *tm ) { - QMap< int, TilesManager* >::const_iterator itTilesManager = d->m_tilesManagers.constFind( id ); - if ( itTilesManager != d->m_tilesManagers.constEnd() ) - { - if ( *itTilesManager ) - delete *itTilesManager; - } - - d->m_tilesManagers.insert( id, tm ); + delete m_tilesManager; + m_tilesManager = tm; } + diff --git a/core/page.h b/core/page.h index 349daf196..366fb76d5 100644 --- a/core/page.h +++ b/core/page.h @@ -362,14 +362,11 @@ class OKULAR_EXPORT Page void deleteAnnotations(); /** - * Returns the tile manager for the observer with the given @p id. - */ - TilesManager *tilesManager( int id ) const; - - /** - * Sets a tiles manager for the given @p id + * Returns the tile manager for the PAGEVIEW_ID observer. + * + * @since 0.16 (KDE 4.10) */ - void setTilesManager( int id, TilesManager *tm ); + TilesManager *tilesManager() const; private: PagePrivate* const d; diff --git a/core/page_p.h b/core/page_p.h index 92fc72df9..a1af7d882 100644 --- a/core/page_p.h +++ b/core/page_p.h @@ -103,6 +103,11 @@ class PagePrivate */ void deleteTextSelections(); + /** + * Sets the tiles manager for the PAGEVIEW_ID observer + */ + void setTilesManager( TilesManager *tm ); + class PixmapObject { public: @@ -110,7 +115,7 @@ class PagePrivate Rotation m_rotation; }; QMap< int, PixmapObject > m_pixmaps; - QMap< int, TilesManager* > m_tilesManagers; + TilesManager* m_tilesManager; Page *m_page; int m_number; diff --git a/ui/pagepainter.cpp b/ui/pagepainter.cpp index 56c774dba..28d3c6362 100644 --- a/ui/pagepainter.cpp +++ b/ui/pagepainter.cpp @@ -30,6 +30,7 @@ #include "core/utils.h" #include "guiutils.h" #include "settings.h" +#include "core/observer.h" #include "core/tilesmanager_p.h" K_GLOBAL_STATIC_WITH_ARGS( QPixmap, busyPixmap, ( KIconLoader::global()->loadIcon("okular", KIconLoader::NoGroup, 32, KIconLoader::DefaultState, QStringList(), 0, true) ) ) @@ -85,7 +86,7 @@ void PagePainter::paintCroppedPageOnPainter( QPainter * destPainter, const Okula } destPainter->fillRect( limits, backgroundColor ); - Okular::TilesManager *tilesManager = page->tilesManager( pixID ); + Okular::TilesManager *tilesManager = ( pixID == PAGEVIEW_ID ) ? page->tilesManager() : 0; const QPixmap *pixmap = 0; if ( !tilesManager ) { diff --git a/ui/pageview.cpp b/ui/pageview.cpp index b766058cd..6a1851e97 100644 --- a/ui/pageview.cpp +++ b/ui/pageview.cpp @@ -3144,7 +3144,7 @@ void PageView::drawDocumentOnPainter( const QRect & contentsRect, QPainter * p ) Okular::NormalizedRect crop; - if ( item->page()->tilesManager( PAGEVIEW_ID ) ) + if ( item->page()->tilesManager() ) { QVector< Okular::VisiblePageRect * >::const_iterator vIt = d->document->visiblePageRects().constBegin(), vEnd = d->document->visiblePageRects().constEnd(); for ( ; vIt != vEnd; ++vIt ) @@ -4019,7 +4019,7 @@ void PageView::slotRequestVisiblePixmaps( int newValue ) kWarning() << "checking for text for page" << i->pageNumber() << "=" << i->page()->hasTextPage(); #endif - Okular::TilesManager *tilesManager = i->page()->tilesManager( PAGEVIEW_ID ); + Okular::TilesManager *tilesManager = i->page()->tilesManager(); Okular::NormalizedRect expandedVisibleRect = vItem->rect; if ( tilesManager && Okular::Settings::memoryLevel() != Okular::Settings::EnumMemoryLevel::Low ) { @@ -4047,7 +4047,7 @@ void PageView::slotRequestVisiblePixmaps( int newValue ) if ( tilesManager ) { Okular::NormalizedRect tilesRect; - QList tiles = i->page()->tilesManager( PAGEVIEW_ID )->tilesAt( expandedVisibleRect ); + QList tiles = tilesManager->tilesAt( expandedVisibleRect ); QList::const_iterator tIt = tiles.constBegin(), tEnd = tiles.constEnd(); while ( tIt != tEnd ) { @@ -4113,7 +4113,7 @@ void PageView::slotRequestVisiblePixmaps( int newValue ) if ( tailRequest < (int)d->items.count() ) { PageViewItem * i = d->items[ tailRequest ]; - Okular::TilesManager *tilesManager = i->page()->tilesManager( PAGEVIEW_ID ); + Okular::TilesManager *tilesManager = i->page()->tilesManager(); Okular::NormalizedRect preRenderRegion; QRect intersectionRect = expandedViewportRect.intersect( i->croppedGeometry() ); @@ -4161,7 +4161,7 @@ void PageView::slotRequestVisiblePixmaps( int newValue ) if ( headRequest >= 0 ) { PageViewItem * i = d->items[ headRequest ]; - Okular::TilesManager *tilesManager = i->page()->tilesManager( PAGEVIEW_ID ); + Okular::TilesManager *tilesManager = i->page()->tilesManager(); Okular::NormalizedRect preRenderRegion; QRect intersectionRect = expandedViewportRect.intersect( i->croppedGeometry() );