Before preloading pixmaps check that they fit in cache

remotes/origin/KDE/4.10
Fabio D'Urso 14 years ago
parent 00afec8617
commit 569c9b84ce
  1. 25
      core/document.cpp
  2. 14
      core/generator.cpp
  3. 1
      core/generator_p.h

@ -11,6 +11,7 @@
#include "document.h"
#include "document_p.h"
#include <limits.h>
#ifdef Q_OS_WIN
#define _WIN32_WINNT 0x0500
#include <windows.h>
@ -973,6 +974,20 @@ void DocumentPrivate::slotTimedMemoryCheck()
void DocumentPrivate::sendGeneratorRequest()
{
/* If the pixmap cache will have to be cleaned in order to make room for the
* next request, get the distance from the current viewport of the page
* whose pixmap will be removed. We will ignore preload requests for pages
* that are at the same distance or farther */
const qulonglong memoryToFree = calculateMemoryToFree();
const int currentViewportPage = (*m_viewportIterator).pageNumber;
int maxDistance = INT_MAX; // Default: No maximum
if ( memoryToFree )
{
AllocatedPixmap *pixmapToReplace = searchLowestPriorityUnloadablePixmap();
if ( pixmapToReplace )
maxDistance = qAbs( pixmapToReplace->page - currentViewportPage );
}
// find a request
PixmapRequest * request = 0;
m_pixmapRequestsMutex.lock();
@ -1000,8 +1015,16 @@ void DocumentPrivate::sendGeneratorRequest()
}
delete r;
}
else if ( !r->d->mForce && r->d->isPreload() && qAbs( r->pageNumber() - currentViewportPage ) >= maxDistance )
{
m_pixmapRequestsStack.pop_back();
//kDebug() << "Ignoring request that doesn't fit in cache";
delete r;
}
else
{
request = r;
}
}
// if no request found (or already generated), return
@ -1014,7 +1037,7 @@ void DocumentPrivate::sendGeneratorRequest()
// [MEM] preventive memory freeing
qulonglong pixmapBytes = 4 * request->width() * request->height();
if ( pixmapBytes > (1024 * 1024) )
cleanupPixmapMemory();
cleanupPixmapMemory( memoryToFree /* previously calculated value */ );
// submit the request to the generator
if ( m_generator->canGeneratePixmap() )

@ -10,6 +10,7 @@
#include "generator.h"
#include "generator_p.h"
#include "observer.h"
#include <qeventloop.h>
#include <QtGui/QPrinter>
@ -477,6 +478,19 @@ void PixmapRequestPrivate::swap()
qSwap( mWidth, mHeight );
}
bool PixmapRequestPrivate::isPreload() const
{
switch ( mPriority )
{
case PAGEVIEW_PRELOAD_PRIO:
case THUMBNAILS_PRELOAD_PRIO:
case PRESENTATION_PRELOAD_PRIO:
return true;
default:
return false;
}
}
class Okular::ExportFormatPrivate : public QSharedData
{
public:

@ -70,6 +70,7 @@ class PixmapRequestPrivate
{
public:
void swap();
bool isPreload() const;
int mId;
int mPageNumber;

Loading…
Cancel
Save