summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDennis Nienhüser <nienhueser@kde.org>2016-11-05 17:34:02 (GMT)
committerDennis Nienhüser <nienhueser@kde.org>2016-11-05 17:34:02 (GMT)
commit53a9f2b61c0569a5a8baa3d1a737251d6ed4d725 (patch)
tree27fc728ec35357298a5349e85c04fd1e712ece3f
parent116108b7c33e6b5c500ce230bae1408b3104db63 (diff)
Avoid intersects() call when the result can be determined easier.
Inner tiles of the pyramid always intersect with the viewport, so the check can be simplified. Also moves the intersection calculation to the items() method where it should have been done in the first place. The idea for this patch is from Lars Grønning, see https://phabricator.kde.org/D3176. Thanks!
-rw-r--r--src/lib/marble/GeoGraphicsScene.cpp14
-rw-r--r--src/lib/marble/layers/GeometryLayer.cpp36
2 files changed, 21 insertions, 29 deletions
diff --git a/src/lib/marble/GeoGraphicsScene.cpp b/src/lib/marble/GeoGraphicsScene.cpp
index 810ebd5..584ae84 100644
--- a/src/lib/marble/GeoGraphicsScene.cpp
+++ b/src/lib/marble/GeoGraphicsScene.cpp
@@ -110,13 +110,7 @@ QList< GeoGraphicsItem* > GeoGraphicsScene::items( const GeoDataLatLonBox &box,
right.setNorth( box.north() );
right.setSouth( box.south() );
- QList< GeoGraphicsItem* > allItems = items( left, zoomLevel );
- foreach( GeoGraphicsItem* item, items( right, zoomLevel ) ) {
- if ( !allItems.contains( item ) ) {
- allItems << item;
- }
- }
- return allItems;
+ return items(left, zoomLevel) + items(right, zoomLevel);
}
QList< GeoGraphicsItem* > result;
@@ -141,11 +135,15 @@ QList< GeoGraphicsItem* > GeoGraphicsScene::items( const GeoDataLatLonBox &box,
int x1, y1, x2, y2;
coords.getCoords( &x1, &y1, &x2, &y2 );
for ( int x = x1; x <= x2; ++x ) {
+ bool const isBorderX = x == x1 || x == x2;
for ( int y = y1; y <= y2; ++y ) {
+ bool const isBorder = isBorderX || y == y1 || y == y2;
const TileId tileId = TileId( 0, level, x, y );
foreach(GeoGraphicsItem *object, d->m_items.value( tileId )) {
if (object->minZoomLevel() <= zoomLevel && object->visible()) {
- result.push_back(object);
+ if (!isBorder || object->latLonAltBox().intersects(box)) {
+ result.push_back(object);
+ }
}
}
}
diff --git a/src/lib/marble/layers/GeometryLayer.cpp b/src/lib/marble/layers/GeometryLayer.cpp
index f4915d6..0871ce3 100644
--- a/src/lib/marble/layers/GeometryLayer.cpp
+++ b/src/lib/marble/layers/GeometryLayer.cpp
@@ -131,30 +131,25 @@ bool GeometryLayer::render( GeoPainter *painter, ViewportParams *viewport,
typedef QPair<QString, GeoGraphicsItem*> LayerItem;
QList<LayerItem> defaultLayer;
- int paintedItems = 0;
QHash<QString, QVector<GeoGraphicsItem*> > paintedFragments;
QSet<QString> const knownLayers = QSet<QString>::fromList(d->m_styleBuilder->renderOrder());
- auto const viewLatLonAltBox = viewport->viewLatLonAltBox();
foreach( GeoGraphicsItem* item, items ) {
- if ( item->latLonAltBox().intersects(viewLatLonAltBox) ) {
- QStringList paintLayers = item->paintLayers();
- if (paintLayers.isEmpty()) {
- mDebug() << item << " provides no paint layers, so I force one onto it.";
- paintLayers << QString();
- }
- foreach(const auto &layer, paintLayers) {
- if (knownLayers.contains(layer)) {
- paintedFragments[layer] << item;
- } else {
- defaultLayer << LayerItem(layer, item);
- static QSet<QString> missingLayers;
- if (!missingLayers.contains(layer)) {
- mDebug() << "Missing layer " << layer << ", in render order, will render it on top";
- missingLayers << layer;
- }
+ QStringList paintLayers = item->paintLayers();
+ if (paintLayers.isEmpty()) {
+ mDebug() << item << " provides no paint layers, so I force one onto it.";
+ paintLayers << QString();
+ }
+ foreach(const auto &layer, paintLayers) {
+ if (knownLayers.contains(layer)) {
+ paintedFragments[layer] << item;
+ } else {
+ defaultLayer << LayerItem(layer, item);
+ static QSet<QString> missingLayers;
+ if (!missingLayers.contains(layer)) {
+ mDebug() << "Missing layer " << layer << ", in render order, will render it on top";
+ missingLayers << layer;
}
}
- ++paintedItems;
}
}
@@ -174,9 +169,8 @@ bool GeometryLayer::render( GeoPainter *painter, ViewportParams *viewport,
}
painter->restore();
- d->m_runtimeTrace = QStringLiteral("Geometries: %1 Drawn: %2 Zoom: %3")
+ d->m_runtimeTrace = QStringLiteral("Geometries: %1 Zoom: %2")
.arg( items.size() )
- .arg( paintedItems )
.arg( maxZoomLevel );
return true;
}