when generating the page image in an internal secondary thread (started by the base generator), then also calculate the page bounding box in the thread

svn path=/trunk/KDE/kdegraphics/okular/; revision=810380
This commit is contained in:
Pino Toscano 2008-05-20 15:20:40 +00:00
parent 20fc951749
commit 6725e71340
3 changed files with 28 additions and 6 deletions

View file

@ -98,8 +98,8 @@ void GeneratorPrivate::pixmapGenerationFinished()
}
const QImage& img = mPixmapGenerationThread->image();
if ( !request->page()->isBoundingBoxKnown() )
q->updatePageBoundingBox( request->page()->number(), Utils::imageBoundingBox( &img ) );
if ( mPixmapGenerationThread->calcBoundingBox() )
q->updatePageBoundingBox( request->page()->number(), mPixmapGenerationThread->boundingBox() );
request->page()->setPixmap( request->id(), new QPixmap( QPixmap::fromImage( img ) ) );
q->signalPixmapRequestDone( request );
@ -218,7 +218,7 @@ void Generator::generatePixmap( PixmapRequest *request )
if ( hasFeature( Threaded ) )
{
d->pixmapGenerationThread()->startGeneration( request );
d->pixmapGenerationThread()->startGeneration( request, !request->page()->isBoundingBoxKnown() );
/**
* We create the text page for every page that is visible to the

View file

@ -13,17 +13,19 @@
#include "fontinfo.h"
#include "generator.h"
#include "utils.h"
using namespace Okular;
PixmapGenerationThread::PixmapGenerationThread( Generator *generator )
: mGenerator( generator ), mRequest( 0 )
: mGenerator( generator ), mRequest( 0 ), mCalcBoundingBox( false )
{
}
void PixmapGenerationThread::startGeneration( PixmapRequest *request )
void PixmapGenerationThread::startGeneration( PixmapRequest *request, bool calcBoundingBox )
{
mRequest = request;
mCalcBoundingBox = calcBoundingBox;
start( QThread::InheritPriority );
}
@ -43,12 +45,26 @@ QImage PixmapGenerationThread::image() const
return mImage;
}
bool PixmapGenerationThread::calcBoundingBox() const
{
return mCalcBoundingBox;
}
NormalizedRect PixmapGenerationThread::boundingBox() const
{
return mBoundingBox;
}
void PixmapGenerationThread::run()
{
mImage = QImage();
if ( mRequest )
{
mImage = mGenerator->image( mRequest );
if ( mCalcBoundingBox )
mBoundingBox = Utils::imageBoundingBox( &mImage );
}
}

View file

@ -10,6 +10,8 @@
#ifndef OKULAR_THREADEDGENERATOR_P_H
#define OKULAR_THREADEDGENERATOR_P_H
#include "area.h"
#include <QtCore/QSet>
#include <QtCore/QThread>
#include <QtGui/QImage>
@ -87,13 +89,15 @@ class PixmapGenerationThread : public QThread
public:
PixmapGenerationThread( Generator *generator );
void startGeneration( PixmapRequest *request );
void startGeneration( PixmapRequest *request, bool calcBoundingRect );
void endGeneration();
PixmapRequest *request() const;
QImage image() const;
bool calcBoundingBox() const;
NormalizedRect boundingBox() const;
protected:
virtual void run();
@ -102,6 +106,8 @@ class PixmapGenerationThread : public QThread
Generator *mGenerator;
PixmapRequest *mRequest;
QImage mImage;
NormalizedRect mBoundingBox;
bool mCalcBoundingBox : 1;
};