From 25d66ea15c6620bb2e639b43faec4d679f48dbb3 Mon Sep 17 00:00:00 2001 From: Fabian Bumberger Date: Thu, 21 Nov 2013 09:20:26 +0100 Subject: Pass the QQuickWindow to the cache for texture creation Change-Id: I97f66d5fbf1aa809afd6e5e3f1ed18044c01a3cc Reviewed-by: Alex Blasche --- src/imports/location/mapnode_sg.cpp | 1 - src/imports/location/mapnode_sg_p.h | 1 + src/imports/location/qdeclarativegeomap.cpp | 28 +++++++++++++++------------ src/imports/location/qdeclarativegeomap_p.h | 3 +-- src/location/maps/qgeomap_p.h | 2 ++ src/location/maps/qgeomapdata_p_p.h | 2 ++ src/location/maps/qgeomappingmanager.cpp | 11 ++++++++++- src/location/maps/qgeomappingmanager_p.h | 4 ++-- src/location/maps/qgeomapscene.cpp | 30 +++++++++++++++++++++++++++++ src/location/maps/qgeomapsscene_qt3d.cpp | 30 ----------------------------- src/location/maps/qgeotilecache.cpp | 12 ++++++++++-- src/location/maps/qgeotilecache_p.h | 6 +++++- 12 files changed, 79 insertions(+), 51 deletions(-) diff --git a/src/imports/location/mapnode_sg.cpp b/src/imports/location/mapnode_sg.cpp index 3a44e0b1..8a4ba5a3 100644 --- a/src/imports/location/mapnode_sg.cpp +++ b/src/imports/location/mapnode_sg.cpp @@ -60,5 +60,4 @@ void MapNode::setSize(const QSize &size) void MapNode::update() { - } diff --git a/src/imports/location/mapnode_sg_p.h b/src/imports/location/mapnode_sg_p.h index 02c2ddd9..be45e509 100644 --- a/src/imports/location/mapnode_sg_p.h +++ b/src/imports/location/mapnode_sg_p.h @@ -43,6 +43,7 @@ #define MAPNODE_SG_P_H #include +#include QT_BEGIN_NAMESPACE diff --git a/src/imports/location/qdeclarativegeomap.cpp b/src/imports/location/qdeclarativegeomap.cpp index 02f65437..a9990018 100644 --- a/src/imports/location/qdeclarativegeomap.cpp +++ b/src/imports/location/qdeclarativegeomap.cpp @@ -299,11 +299,15 @@ void QDeclarativeGeoMap::pluginReady() return; } +#ifdef NO_QT3D_RENDERER + qDebug() << "Listening for window changed" << window(); + connect(this, SIGNAL(windowChanged(QQuickWindow*)), this, SLOT(windowWasChanged())); +#else if (!mappingManager_->isInitialized()) connect(mappingManager_, SIGNAL(initialized()), this, SLOT(mappingManagerInitialized())); else mappingManagerInitialized(); - +#endif // make sure this is only called once disconnect(this, SLOT(pluginReady())); } @@ -381,16 +385,6 @@ QDeclarativeGeoMapGestureArea *QDeclarativeGeoMap::gesture() return gestureArea_; } -/*! - \internal -*/ -void QDeclarativeGeoMap::itemChange(ItemChange change, const ItemChangeData & data) -{ - QLOC_TRACE0; - if (change == ItemSceneChange) - window_ = data.window; -} - /*! \internal */ @@ -437,6 +431,9 @@ QSGNode *QDeclarativeGeoMap::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeDa if (!node) { node = new MapNode(map_); +#ifdef NO_QT3D_RENDERER + qDebug() << "Setting window" << window(); +#endif } if (!mappingManagerInitialized_) @@ -483,7 +480,8 @@ void QDeclarativeGeoMap::mappingManagerInitialized() { mappingManagerInitialized_ = true; - map_ = mappingManager_->createMap(this); + qDebug() << "Creating the map" << window(); + map_ = mappingManager_->createMap(this, window()); gestureArea_->setMap(map_); //The zoom level limits are only restricted by the plugins values, if the user has set a more @@ -560,6 +558,12 @@ void QDeclarativeGeoMap::mappingManagerInitialized() } } +void QDeclarativeGeoMap::windowWasChanged() +{ + if (window()) + connect(window(), SIGNAL(sceneGraphInitialized()), this, SLOT(mappingManagerInitialized())); +} + /*! \internal */ diff --git a/src/imports/location/qdeclarativegeomap_p.h b/src/imports/location/qdeclarativegeomap_p.h index b231c76e..ecb4d60a 100644 --- a/src/imports/location/qdeclarativegeomap_p.h +++ b/src/imports/location/qdeclarativegeomap_p.h @@ -123,8 +123,6 @@ public: virtual QSGNode *updatePaintNode(QSGNode *, UpdatePaintNodeData *); virtual void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry); - void itemChange(ItemChange change, const ItemChangeData & data); - void setPlugin(QDeclarativeGeoServiceProvider *plugin); QDeclarativeGeoServiceProvider *plugin() const; @@ -193,6 +191,7 @@ Q_SIGNALS: void mapItemsChanged(); private Q_SLOTS: + void windowWasChanged(); void updateMapDisplay(const QRectF &target); void mappingManagerInitialized(); void mapZoomLevelChanged(qreal zoom); diff --git a/src/location/maps/qgeomap_p.h b/src/location/maps/qgeomap_p.h index d27fd178..7ea67dc1 100644 --- a/src/location/maps/qgeomap_p.h +++ b/src/location/maps/qgeomap_p.h @@ -108,6 +108,8 @@ public: QString pluginString(); + QGeoMapData *mapData() { return mapData_; } + public Q_SLOTS: void update(); void cameraStopped(); // optional hint for prefetch diff --git a/src/location/maps/qgeomapdata_p_p.h b/src/location/maps/qgeomapdata_p_p.h index 0c1238a9..9737da00 100644 --- a/src/location/maps/qgeomapdata_p_p.h +++ b/src/location/maps/qgeomapdata_p_p.h @@ -107,7 +107,9 @@ private: int height_; double aspectRatio_; +#ifndef NO_QT3D_RENDERER QGLCamera *camera_; +#endif QGeoMapData *map_; QGeoMappingManagerEngine *engine_; QString pluginString_; diff --git a/src/location/maps/qgeomappingmanager.cpp b/src/location/maps/qgeomappingmanager.cpp index 24e08278..c6761d16 100644 --- a/src/location/maps/qgeomappingmanager.cpp +++ b/src/location/maps/qgeomappingmanager.cpp @@ -45,6 +45,10 @@ #include "qgeotiledmapreply_p.h" #include "qgeocameracapabilities_p.h" +#ifdef NO_QT3D_RENDERER +#include "qgeotiledmapdata_p.h" +#include "qgeotilecache_p.h" +#endif #include "qgeomap_p.h" @@ -135,9 +139,14 @@ QGeoCameraCapabilities QGeoMappingManager::cameraCapabilities() const /*! Returns a new QGeoMap instance which will be managed by this manager. */ -QGeoMap *QGeoMappingManager::createMap(QObject *parent) +QGeoMap *QGeoMappingManager::createMap(QObject *parent, QQuickWindow *window) { QGeoMapData *mapData = d_ptr->engine->createMapData(); +#ifdef NO_QT3D_RENDERER + QGeoTiledMapData *tMapData = qobject_cast(mapData); + qDebug() << "Setting window"; + tMapData->tileCache()->setQQuickWindow(window); +#endif QGeoMap *map = new QGeoMap(mapData, parent); return map; } diff --git a/src/location/maps/qgeomappingmanager_p.h b/src/location/maps/qgeomappingmanager_p.h index fd1a8ae6..976d1804 100644 --- a/src/location/maps/qgeomappingmanager_p.h +++ b/src/location/maps/qgeomappingmanager_p.h @@ -69,7 +69,7 @@ class QGeoMappingManagerPrivate; class QGeoMapRequestOptions; class QGeoMappingManagerEngine; class QGeoCameraCapabilities; - +class QQuickWindow; class Q_LOCATION_EXPORT QGeoMappingManager : public QObject { @@ -81,7 +81,7 @@ public: QString managerName() const; int managerVersion() const; - QGeoMap *createMap(QObject *parent); + QGeoMap *createMap(QObject *parent, QQuickWindow *window = 0); QList supportedMapTypes() const; diff --git a/src/location/maps/qgeomapscene.cpp b/src/location/maps/qgeomapscene.cpp index feade05e..e182ed73 100644 --- a/src/location/maps/qgeomapscene.cpp +++ b/src/location/maps/qgeomapscene.cpp @@ -337,5 +337,35 @@ void QGeoMapScenePrivate::setTileBounds(const QSet &tiles) } } +QRectF QGeoMapScenePrivate::buildGeometry(const QGeoTileSpec &spec) +{ + int x = spec.x(); + + if (x < tileXWrapsBelow_) + x += sideLength_; + + if ((x < minTileX_) + || (maxTileX_ < x) + || (spec.y() < minTileY_) + || (maxTileY_ < spec.y()) + || (spec.zoom() != tileZ_)) { + return QRectF(); + } + + double edge = scaleFactor_ * tileSize_; + + double x1 = (x - minTileX_); + double x2 = x1 + 1.0; + + double y1 = (minTileY_ - spec.y()); + double y2 = y1 - 1.0; + + x1 *= edge; + x2 *= edge; + y1 *= edge; + y2 *= edge; + return QRectF(x1, y1, x2-x1, y2-y1); +} + QT_END_NAMESPACE diff --git a/src/location/maps/qgeomapsscene_qt3d.cpp b/src/location/maps/qgeomapsscene_qt3d.cpp index fa15001f..8d2fd5e4 100644 --- a/src/location/maps/qgeomapsscene_qt3d.cpp +++ b/src/location/maps/qgeomapsscene_qt3d.cpp @@ -191,36 +191,6 @@ void QGeoMapScenePrivate::updateTiles(const QSet &tiles) } } -QRectF QGeoMapScenePrivate::buildGeometry(const QGeoTileSpec &spec) -{ - int x = spec.x(); - - if (x < tileXWrapsBelow_) - x += sideLength_; - - if ((x < minTileX_) - || (maxTileX_ < x) - || (spec.y() < minTileY_) - || (maxTileY_ < spec.y()) - || (spec.zoom() != tileZ_)) { - return QRectF(); - } - - double edge = scaleFactor_ * tileSize_; - - double x1 = (x - minTileX_); - double x2 = x1 + 1.0; - - double y1 = (minTileY_ - spec.y()); - double y2 = y1 - 1.0; - - x1 *= edge; - x2 *= edge; - y1 *= edge; - y2 *= edge; - return QRectF(x1, y1, x2-x1, y2-y1); -} - void QGeoMapScenePrivate::removeTiles(const QSet &oldTiles) { typedef QSet::const_iterator iter; diff --git a/src/location/maps/qgeotilecache.cpp b/src/location/maps/qgeotilecache.cpp index a79e29e7..41dc498d 100644 --- a/src/location/maps/qgeotilecache.cpp +++ b/src/location/maps/qgeotilecache.cpp @@ -65,7 +65,7 @@ QMutex QGeoTileCache::cleanupMutex_; #ifndef NO_QT3D_RENDERER QList QGeoTileCache::cleanupList_; #else -QList QGeoTileCache::cleanupList_; +QList QGeoTileCache::cleanupList_; #endif @@ -116,6 +116,9 @@ QGeoTileTexture::~QGeoTileTexture() QGeoTileCache::QGeoTileCache(const QString &directory, QObject *parent) : QObject(parent), directory_(directory), minTextureUsage_(0), extraTextureUsage_(0) +#ifdef NO_QT3D_RENDERER + , m_containingWindow(0) +#endif { qRegisterMetaType(); qRegisterMetaType >(); @@ -301,6 +304,11 @@ void QGeoTileCache::GLContextAvailable() cleanupList_.pop_front(); } } +#else +void QGeoTileCache::setQQuickWindow(QQuickWindow *window) +{ + m_containingWindow = window; +} #endif QSharedPointer QGeoTileCache::get(const QGeoTileSpec &spec) @@ -420,7 +428,7 @@ QSharedPointer QGeoTileCache::addToTextureCache(const QGeoTileS tt->texture->setHorizontalWrap(QGL::ClampToEdge); tt->texture->setVerticalWrap(QGL::ClampToEdge); #else - //tt->texture = QQuickWindow::createTextureFromImage(pixmap.toImage()); + tt->texture = m_containingWindow->createTextureFromImage(pixmap.toImage()); tt->texture->setHorizontalWrapMode(QSGTexture::ClampToEdge); tt->texture->setVerticalWrapMode(QSGTexture::ClampToEdge); #endif diff --git a/src/location/maps/qgeotilecache_p.h b/src/location/maps/qgeotilecache_p.h index 1dbb0363..2d473dad 100644 --- a/src/location/maps/qgeotilecache_p.h +++ b/src/location/maps/qgeotilecache_p.h @@ -75,6 +75,7 @@ class QGeoTileCache; class QGLTexture2D; #else class QSGTexture; +class QQuickWindow; #endif class QPixmap; @@ -142,6 +143,8 @@ public: #ifndef NO_QT3D_RENDERER void GLContextAvailable(); +#else + void setQQuickWindow(QQuickWindow *window); #endif QSharedPointer get(const QGeoTileSpec &spec); @@ -182,7 +185,8 @@ private: #ifndef NO_QT3D_RENDERER static QList cleanupList_; #else - static QList cleanupList_; + static QList cleanupList_; + QQuickWindow *m_containingWindow; #endif }; -- cgit v1.2.3