diff --git a/core/document.cpp b/core/document.cpp index 5368638d9..d911c46c6 100644 --- a/core/document.cpp +++ b/core/document.cpp @@ -1104,7 +1104,7 @@ void DocumentPrivate::sendGeneratorPixmapRequest() if ( !r->normalizedRect().isNull() ) { NormalizedRect tilesRect; - const QList tiles = tilesManager->tilesAt( r->normalizedRect() ); + const QList tiles = tilesManager->tilesAt( r->normalizedRect(), TilesManager::TerminalTile ); QList::const_iterator tIt = tiles.constBegin(), tEnd = tiles.constEnd(); while ( tIt != tEnd ) { @@ -1313,7 +1313,7 @@ void DocumentPrivate::refreshPixmaps( int pageNumber ) break; } } - const QList tiles = tilesManager->tilesAt( visibleRect ); + const QList tiles = tilesManager->tilesAt( visibleRect, TilesManager::TerminalTile ); QList::const_iterator tIt = tiles.constBegin(), tEnd = tiles.constEnd(); while ( tIt != tEnd ) { @@ -2551,6 +2551,30 @@ void Document::requestPixmaps( const QLinkedList< PixmapRequest * > & requests, request->d->mPage = d->m_pagesVector.value( request->pageNumber() ); + if ( request->isTile() ) + { + // Change the current request rect so that only invalid tiles are + // requested. Also make sure the rect is tile-aligned. + NormalizedRect tilesRect; + const QList tiles = request->page()->d->tilesManager()->tilesAt( request->normalizedRect(), TilesManager::TerminalTile ); + QList::const_iterator tIt = tiles.constBegin(), tEnd = tiles.constEnd(); + while ( tIt != tEnd ) + { + const Tile &tile = *tIt; + if ( !tile.isValid() ) + { + if ( tilesRect.isNull() ) + tilesRect = tile.rect(); + else + tilesRect |= tile.rect(); + } + + tIt++; + } + + request->setNormalizedRect( tilesRect ); + } + if ( !request->asynchronous() ) request->d->mPriority = 0; diff --git a/core/page.cpp b/core/page.cpp index d11881fa8..4df58e049 100644 --- a/core/page.cpp +++ b/core/page.cpp @@ -992,10 +992,10 @@ bool Page::hasTilesManager() const return d->m_tilesManager != 0; } -QList Page::tilesAt( const NormalizedRect &rect, bool allowEmpty ) const +QList Page::tilesAt( const NormalizedRect &rect ) const { if ( d->m_tilesManager ) - return d->m_tilesManager->tilesAt( rect, allowEmpty ); + return d->m_tilesManager->tilesAt( rect, TilesManager::PixmapTile ); else return QList(); } diff --git a/core/page.h b/core/page.h index 1b19ccd66..6bc60c593 100644 --- a/core/page.h +++ b/core/page.h @@ -378,11 +378,11 @@ class OKULAR_EXPORT Page /** * Returns a list of all tiles intersecting with @p rect. * - * @param allowEmpty If false only tiles with a non null pixmap are returned + * The list contains only tiles with a pixmap * * @since 0.16 (KDE 4.10) */ - QList tilesAt( const NormalizedRect &rect, bool allowEmpty = true ) const; + QList tilesAt( const NormalizedRect &rect ) const; private: PagePrivate* const d; diff --git a/core/tilesmanager.cpp b/core/tilesmanager.cpp index af9239259..9f6be2cdf 100644 --- a/core/tilesmanager.cpp +++ b/core/tilesmanager.cpp @@ -34,7 +34,7 @@ class TilesManager::Private Private(); bool hasPixmap( const NormalizedRect &rect, const TileNode &tile ) const; - void tilesAt( const NormalizedRect &rect, TileNode &tile, QList &result, bool allowEmpty ); + void tilesAt( const NormalizedRect &rect, TileNode &tile, QList &result, TileLeaf tileLeaf ); void setPixmap( const QPixmap *pixmap, const NormalizedRect &rect, TileNode &tile ); /** @@ -335,20 +335,20 @@ bool TilesManager::Private::hasPixmap( const NormalizedRect &rect, const TileNod return true; } -QList TilesManager::tilesAt( const NormalizedRect &rect, bool allowEmpty ) +QList TilesManager::tilesAt( const NormalizedRect &rect, TileLeaf tileLeaf ) { QList result; NormalizedRect rotatedRect = fromRotatedRect( rect, d->rotation ); for ( int i = 0; i < 16; ++i ) { - d->tilesAt( rotatedRect, d->tiles[ i ], result, allowEmpty ); + d->tilesAt( rotatedRect, d->tiles[ i ], result, tileLeaf ); } return result; } -void TilesManager::Private::tilesAt( const NormalizedRect &rect, TileNode &tile, QList &result, bool allowEmpty ) +void TilesManager::Private::tilesAt( const NormalizedRect &rect, TileNode &tile, QList &result, TileLeaf tileLeaf ) { if ( !tile.rect.intersects( rect ) ) return; @@ -357,7 +357,7 @@ void TilesManager::Private::tilesAt( const NormalizedRect &rect, TileNode &tile, // requesting huge areas unnecessarily splitBigTiles( tile, rect ); - if ( ( allowEmpty && tile.nTiles == 0 ) || ( !allowEmpty && tile.pixmap ) ) + if ( ( tileLeaf == TerminalTile && tile.nTiles == 0 ) || ( tileLeaf == PixmapTile && tile.pixmap ) ) { NormalizedRect rotatedRect; if ( rotation != Rotation0 ) @@ -365,7 +365,7 @@ void TilesManager::Private::tilesAt( const NormalizedRect &rect, TileNode &tile, else rotatedRect = tile.rect; - if ( tile.pixmap && !allowEmpty && tile.rotation != rotation ) + if ( tile.pixmap && tileLeaf == PixmapTile && tile.rotation != rotation ) { // Lazy tiles rotation int angleToRotate = (rotation - tile.rotation)*90; @@ -417,7 +417,7 @@ void TilesManager::Private::tilesAt( const NormalizedRect &rect, TileNode &tile, else { for ( int i = 0; i < tile.nTiles; ++i ) - tilesAt( rect, tile.tiles[ i ], result, allowEmpty ); + tilesAt( rect, tile.tiles[ i ], result, tileLeaf ); } } diff --git a/core/tilesmanager_p.h b/core/tilesmanager_p.h index 61a57e646..e2d4fefc9 100644 --- a/core/tilesmanager_p.h +++ b/core/tilesmanager_p.h @@ -98,6 +98,12 @@ class TileNode class TilesManager { public: + enum TileLeaf + { + TerminalTile, ///< Return tiles without children + PixmapTile ///< Return only tiles with pixmap + }; + TilesManager( int pageNumber, int width, int height, Rotation rotation = Rotation0 ); ~TilesManager(); @@ -125,9 +131,9 @@ class TilesManager * As to avoid requests of big areas, each traversed tile is checked * for its size and split if necessary. * - * @param allowEmpty If false only tiles with a non null pixmap are returned + * @param tileLeaf Indicate the type of tile to return */ - QList tilesAt( const NormalizedRect &rect, bool allowEmpty = true ); + QList tilesAt( const NormalizedRect &rect, TileLeaf tileLeaf ); /** * The total memory consumed by the tiles manager diff --git a/ui/pagepainter.cpp b/ui/pagepainter.cpp index 2dacc009e..91ae211fb 100644 --- a/ui/pagepainter.cpp +++ b/ui/pagepainter.cpp @@ -244,7 +244,7 @@ void PagePainter::paintCroppedPageOnPainter( QPainter * destPainter, const Okula if ( hasTilesManager ) { const Okular::NormalizedRect normalizedLimits( limitsInPixmap, scaledWidth, scaledHeight ); - const QList tiles = page->tilesAt( normalizedLimits, false ); + const QList tiles = page->tilesAt( normalizedLimits ); QList::const_iterator tIt = tiles.constBegin(), tEnd = tiles.constEnd(); while ( tIt != tEnd ) { @@ -299,7 +299,7 @@ void PagePainter::paintCroppedPageOnPainter( QPainter * destPainter, const Okula backImage.fill( paperColor.rgb() ); QPainter p( &backImage ); const Okular::NormalizedRect normalizedLimits( limitsInPixmap, scaledWidth, scaledHeight ); - const QList tiles = page->tilesAt( normalizedLimits, false ); + const QList tiles = page->tilesAt( normalizedLimits ); QList::const_iterator tIt = tiles.constBegin(), tEnd = tiles.constEnd(); while ( tIt != tEnd ) { diff --git a/ui/pageview.cpp b/ui/pageview.cpp index 25208799a..bf8b54638 100644 --- a/ui/pageview.cpp +++ b/ui/pageview.cpp @@ -4112,24 +4112,7 @@ void PageView::slotRequestVisiblePixmaps( int newValue ) if ( i->page()->hasTilesManager() ) { - Okular::NormalizedRect tilesRect; - const QList tiles = i->page()->tilesAt( expandedVisibleRect ); - QList::const_iterator tIt = tiles.constBegin(), tEnd = tiles.constEnd(); - while ( tIt != tEnd ) - { - const Okular::Tile &tile = *tIt; - if ( !tile.isValid() ) - { - if ( tilesRect.isNull() ) - tilesRect = tile.rect(); - else - tilesRect |= tile.rect(); - } - - tIt++; - } - - p->setNormalizedRect( tilesRect ); + p->setNormalizedRect( expandedVisibleRect ); p->setTile( true ); } else @@ -4191,26 +4174,10 @@ void PageView::slotRequestVisiblePixmaps( int newValue ) const bool pageHasTilesManager = i->page()->hasTilesManager(); if ( pageHasTilesManager && !preRenderRegion.isNull() ) { - Okular::NormalizedRect tilesRect; - const QList tiles = i->page()->tilesAt( preRenderRegion ); - QList::const_iterator tIt = tiles.constBegin(), tEnd = tiles.constEnd(); - while ( tIt != tEnd ) - { - const Okular::Tile &tile = *tIt; - if ( !tile.isValid() ) - { - if ( tilesRect.isNull() ) - tilesRect = tile.rect(); - else - tilesRect |= tile.rect(); - } - - tIt++; - } - Okular::PixmapRequest * p = new Okular::PixmapRequest( PAGEVIEW_ID, i->pageNumber(), i->uncroppedWidth(), i->uncroppedHeight(), PAGEVIEW_PRELOAD_PRIO, true ); requestedPixmaps.push_back( p ); - p->setNormalizedRect( tilesRect ); + + p->setNormalizedRect( preRenderRegion ); p->setTile( true ); } else if ( !pageHasTilesManager ) @@ -4239,26 +4206,10 @@ void PageView::slotRequestVisiblePixmaps( int newValue ) const bool pageHasTilesManager = i->page()->hasTilesManager(); if ( pageHasTilesManager && !preRenderRegion.isNull() ) { - Okular::NormalizedRect tilesRect; - const QList tiles = i->page()->tilesAt( preRenderRegion ); - QList::const_iterator tIt = tiles.constBegin(), tEnd = tiles.constEnd(); - while ( tIt != tEnd ) - { - const Okular::Tile &tile = *tIt; - if ( !tile.isValid() ) - { - if ( tilesRect.isNull() ) - tilesRect = tile.rect(); - else - tilesRect |= tile.rect(); - } - - tIt++; - } - Okular::PixmapRequest * p = new Okular::PixmapRequest( PAGEVIEW_ID, i->pageNumber(), i->uncroppedWidth(), i->uncroppedHeight(), PAGEVIEW_PRELOAD_PRIO, true ); requestedPixmaps.push_back( p ); - p->setNormalizedRect( tilesRect ); + + p->setNormalizedRect( preRenderRegion ); p->setTile( true ); } else if ( !pageHasTilesManager )