Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Commit

Permalink
[qt] render frontend implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
ivovandongen committed Jun 29, 2017
1 parent d6e80ba commit 121be92
Show file tree
Hide file tree
Showing 5 changed files with 111 additions and 3 deletions.
2 changes: 2 additions & 0 deletions platform/qt/qt.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ add_library(qmapboxgl SHARED
platform/qt/src/qmapbox.cpp
platform/qt/src/qmapboxgl.cpp
platform/qt/src/qmapboxgl_p.hpp
platform/qt/src/qrenderer_frontend.hpp
platform/qt/src/qrenderer_frontend.cpp
platform/default/mbgl/util/default_styles.hpp
platform/default/mbgl/util/default_styles.cpp
)
Expand Down
16 changes: 15 additions & 1 deletion platform/qt/src/qmapboxgl.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "qmapboxgl.hpp"
#include "qmapboxgl_p.hpp"
#include "qrenderer_frontend.hpp"

#include "qt_conversion.hpp"
#include "qt_geojson.hpp"
Expand Down Expand Up @@ -1430,7 +1431,7 @@ void QMapboxGL::render()
mbgl::BackendScope scope { *d_ptr, mbgl::BackendScope::ScopeType::Implicit };

d_ptr->dirty = false;
d_ptr->mapObj->render(*d_ptr);
d_ptr->render();
}

/*!
Expand Down Expand Up @@ -1469,6 +1470,8 @@ void QMapboxGL::connectionEstablished()
\a copyrightsHtml is a string with a HTML snippet.
*/

class QRendererFrontend;

QMapboxGLPrivate::QMapboxGLPrivate(QMapboxGL *q, const QMapboxGLSettings &settings, const QSize &size_, qreal pixelRatio)
: QObject(q)
, size(size_)
Expand All @@ -1479,7 +1482,13 @@ QMapboxGLPrivate::QMapboxGLPrivate(QMapboxGL *q, const QMapboxGLSettings &settin
settings.cacheDatabaseMaximumSize()))
, threadPool(mbgl::sharedThreadPool())
{
// Setup and connect the renderer frontend
auto frontend = std::make_unique<QRendererFrontend>(*this, *this);
connect(this, SIGNAL(renderRequested()), frontend.get(), SLOT(render()), Qt::DirectConnection);
connect(frontend.get(), SIGNAL(updated()), this, SLOT(invalidate()), Qt::DirectConnection);

mapObj = std::make_unique<mbgl::Map>(
std::move(frontend),
*this, sanitizedSize(size),
pixelRatio, *fileSourceObj, *threadPool,
mbgl::MapMode::Continuous,
Expand Down Expand Up @@ -1523,6 +1532,11 @@ void QMapboxGLPrivate::invalidate()
}
}

void QMapboxGLPrivate::render()
{
emit renderRequested();
}

void QMapboxGLPrivate::onCameraWillChange(mbgl::MapObserver::CameraChangeMode mode)
{
if (mode == mbgl::MapObserver::CameraChangeMode::Immediate) {
Expand Down
9 changes: 7 additions & 2 deletions platform/qt/src/qmapboxgl_p.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#include <QObject>
#include <QSize>

class QMapboxGLPrivate : public QObject, public mbgl::View, public mbgl::Backend
class QMapboxGLPrivate : public QObject, public mbgl::View, public mbgl::Backend, public mbgl::MapObserver
{
Q_OBJECT

Expand All @@ -22,12 +22,12 @@ class QMapboxGLPrivate : public QObject, public mbgl::View, public mbgl::Backend

mbgl::Size framebufferSize() const;


// mbgl::View implementation.
void bind() final;

// mbgl::Backend implementation.
void updateAssumedState() final;
void invalidate() final;
void activate() final {}
void deactivate() final {}

Expand Down Expand Up @@ -63,9 +63,14 @@ class QMapboxGLPrivate : public QObject, public mbgl::View, public mbgl::Backend

public slots:
void connectionEstablished();
void invalidate();
void render();

signals:
void needsRendering();
void mapChanged(QMapboxGL::MapChange);
void copyrightsChanged(const QString &copyrightsHtml);

// Internal signal to start rendering
void renderRequested();
};
49 changes: 49 additions & 0 deletions platform/qt/src/qrenderer_frontend.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#include "qrenderer_frontend.hpp"

#include <mbgl/map/backend_scope.hpp>
#include <mbgl/renderer/renderer.hpp>

QRendererFrontend::QRendererFrontend(mbgl::Backend& backend_, mbgl::View& view_)
: backend(backend_)
, view(view_) {
}

QRendererFrontend::~QRendererFrontend() {
mbgl::BackendScope guard { backend, mbgl::BackendScope::ScopeType::Implicit };
renderer.reset();
}

void QRendererFrontend::update(std::shared_ptr<mbgl::UpdateParameters> updateParameters_) {
updateParameters = updateParameters_;
emit updated();
}

std::vector<mbgl::Feature> QRendererFrontend::queryRenderedFeatures(std::shared_ptr<mbgl::RenderedQueryParameters> params) const {
if (!renderer) return {};
return renderer->queryRenderedFeatures(*params);
}

std::vector<mbgl::Feature> QRendererFrontend::querySourceFeatures(std::shared_ptr<mbgl::SourceQueryParameters> params) const {
if (!renderer) return {};
return renderer->querySourceFeatures(*params);
}

void QRendererFrontend::setRenderer(std::unique_ptr<mbgl::Renderer> renderer_, mbgl::RendererObserver& observer_) {
renderer = std::move(renderer_);
renderer->setObserver(&observer_);
}

void QRendererFrontend::render() {
if (!renderer || !updateParameters) return;
renderer->render(backend, view, *updateParameters);
}

void QRendererFrontend::onLowMemory() {
if (!renderer) return;
renderer->onLowMemory();
}

void QRendererFrontend::dumpDebugLogs() {
if (!renderer) return;
renderer->dumpDebugLogs();
}
38 changes: 38 additions & 0 deletions platform/qt/src/qrenderer_frontend.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#pragma once

#include <mbgl/map/backend.hpp>
#include <mbgl/renderer/renderer_frontend.hpp>

#include <QObject>

class QRendererFrontend : public QObject, public mbgl::RendererFrontend
{
Q_OBJECT

public:
explicit QRendererFrontend(mbgl::Backend&, mbgl::View&);
~QRendererFrontend() override;

void update(std::shared_ptr<mbgl::UpdateParameters> updateParameters_) override;

std::vector<mbgl::Feature> queryRenderedFeatures(std::shared_ptr<mbgl::RenderedQueryParameters> params) const override;
std::vector<mbgl::Feature> querySourceFeatures(std::shared_ptr<mbgl::SourceQueryParameters> params) const override;

void setRenderer(std::unique_ptr<mbgl::Renderer> renderer_, mbgl::RendererObserver& observer_) override;

void onLowMemory() override;
void dumpDebugLogs() override;

public slots:
void render();

signals:
void updated();

private:
mbgl::Backend& backend;
mbgl::View& view;

std::shared_ptr<mbgl::UpdateParameters> updateParameters;
std::unique_ptr<mbgl::Renderer> renderer;
};

0 comments on commit 121be92

Please sign in to comment.