Navigation Menu

Skip to content

Commit

Permalink
Have QgsRasterDrawer::draw check for interrupted rendering, reduce ra…
Browse files Browse the repository at this point in the history
…ster block tile dimensions, to greatly enhance responsiveness when dealing with reprojected raster layers
  • Loading branch information
manisandro authored and nyalldawson committed Jun 6, 2016
1 parent 1e8abb1 commit d984148
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 5 deletions.
8 changes: 7 additions & 1 deletion python/core/raster/qgsrasterdrawer.sip
Expand Up @@ -9,7 +9,13 @@ class QgsRasterDrawer
public:
QgsRasterDrawer( QgsRasterIterator *iterator );

void draw( QPainter* p, QgsRasterViewPort* viewPort, const QgsMapToPixel* theQgsMapToPixel );
/** Draws raster data.
* @param p destination QPainter
* @param viewPort viewport to render
* @param theQgsMapToPixel map to pixel convertor
* @param ctx render context
*/
void draw( QPainter* p, QgsRasterViewPort* viewPort, const QgsMapToPixel* theQgsMapToPixel, const QgsRenderContext *ctx = nullptr );

protected:
/** Draws raster part
Expand Down
5 changes: 4 additions & 1 deletion src/core/raster/qgsrasterdrawer.cpp
Expand Up @@ -20,6 +20,7 @@
#include "qgsrasteriterator.h"
#include "qgsrasterviewport.h"
#include "qgsmaptopixel.h"
#include "qgsrendercontext.h"
#include <QImage>
#include <QPainter>
#include <QPrinter>
Expand All @@ -28,7 +29,7 @@ QgsRasterDrawer::QgsRasterDrawer( QgsRasterIterator* iterator ): mIterator( iter
{
}

void QgsRasterDrawer::draw( QPainter* p, QgsRasterViewPort* viewPort, const QgsMapToPixel* theQgsMapToPixel )
void QgsRasterDrawer::draw( QPainter* p, QgsRasterViewPort* viewPort, const QgsMapToPixel* theQgsMapToPixel, const QgsRenderContext* ctx )
{
QgsDebugMsgLevel( "Entered", 4 );
if ( !p || !mIterator || !viewPort || !theQgsMapToPixel )
Expand Down Expand Up @@ -88,6 +89,8 @@ void QgsRasterDrawer::draw( QPainter* p, QgsRasterViewPort* viewPort, const QgsM
drawImage( p, viewPort, img, topLeftCol, topLeftRow, theQgsMapToPixel );

delete block;
if ( ctx && ctx->renderingStopped() )
break;
}
}

Expand Down
9 changes: 8 additions & 1 deletion src/core/raster/qgsrasterdrawer.h
Expand Up @@ -24,6 +24,7 @@
class QPainter;
class QImage;
class QgsMapToPixel;
class QgsRenderContext;
struct QgsRasterViewPort;
class QgsRasterIterator;

Expand All @@ -35,7 +36,13 @@ class CORE_EXPORT QgsRasterDrawer
public:
QgsRasterDrawer( QgsRasterIterator *iterator );

void draw( QPainter* p, QgsRasterViewPort* viewPort, const QgsMapToPixel* theQgsMapToPixel );
/** Draws raster data.
* @param p destination QPainter
* @param viewPort viewport to render
* @param theQgsMapToPixel map to pixel convertor
* @param ctx render context
*/
void draw( QPainter* p, QgsRasterViewPort* viewPort, const QgsMapToPixel* theQgsMapToPixel, const QgsRenderContext *ctx = nullptr );

protected:
/** Draws raster part
Expand Down
2 changes: 1 addition & 1 deletion src/core/raster/qgsrasteriterator.cpp
Expand Up @@ -18,7 +18,7 @@
#include "qgsrasterviewport.h"

QgsRasterIterator::QgsRasterIterator( QgsRasterInterface* input ): mInput( input ),
mMaximumTileWidth( 2000 ), mMaximumTileHeight( 2000 )
mMaximumTileWidth( 256 ), mMaximumTileHeight( 256 )
{
}

Expand Down
3 changes: 2 additions & 1 deletion src/core/raster/qgsrasterlayerrenderer.cpp
Expand Up @@ -25,6 +25,7 @@ QgsRasterLayerRenderer::QgsRasterLayerRenderer( QgsRasterLayer* layer, QgsRender
: QgsMapLayerRenderer( layer->id() )
, mRasterViewPort( nullptr )
, mPipe( nullptr )
, mContext( rendererContext )
{

mPainter = rendererContext.painter();
Expand Down Expand Up @@ -209,7 +210,7 @@ bool QgsRasterLayerRenderer::render()
// Drawer to pipe?
QgsRasterIterator iterator( mPipe->last() );
QgsRasterDrawer drawer( &iterator );
drawer.draw( mPainter, mRasterViewPort, mMapToPixel );
drawer.draw( mPainter, mRasterViewPort, mMapToPixel, &mContext );

QgsDebugMsgLevel( QString( "total raster draw time (ms): %1" ).arg( time.elapsed(), 5 ), 4 );

Expand Down
1 change: 1 addition & 0 deletions src/core/raster/qgsrasterlayerrenderer.h
Expand Up @@ -47,6 +47,7 @@ class QgsRasterLayerRenderer : public QgsMapLayerRenderer
QgsRasterViewPort* mRasterViewPort;

QgsRasterPipe* mPipe;
QgsRenderContext& mContext;
};

#endif // QGSRASTERLAYERRENDERER_H

0 comments on commit d984148

Please sign in to comment.