summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMikhail Pozdnyakov <mikhail.pozdnyakov@mapbox.com>2020-03-18 14:29:46 +0200
committerMikhail Pozdnyakov <mikhail.pozdnyakov@mapbox.com>2020-03-18 18:38:22 +0200
commit5037232a7f919d29ab61d865e706ef946d20df65 (patch)
treef9a1fe249fda27ef4b7c83347e359ba8c5c9e0aa
parent14f19f0201a371dc6cf8ddee4b8f0c73bdc5be5d (diff)
downloadqtlocation-mapboxgl-5037232a7f919d29ab61d865e706ef946d20df65.tar.gz
[core][tile|static mode] Introduce MapOptions::keepRenderData() flag
Render orchestrator stores the render data between render frames if this flag is set.
-rw-r--r--include/mbgl/map/map_options.hpp22
-rw-r--r--src/mbgl/map/map_impl.cpp6
-rw-r--r--src/mbgl/map/map_impl.hpp1
-rw-r--r--src/mbgl/map/map_options.cpp10
-rw-r--r--src/mbgl/renderer/render_orchestrator.cpp7
-rw-r--r--src/mbgl/renderer/render_orchestrator.hpp1
-rw-r--r--src/mbgl/renderer/update_parameters.hpp7
7 files changed, 50 insertions, 4 deletions
diff --git a/include/mbgl/map/map_options.hpp b/include/mbgl/map/map_options.hpp
index fcb8c8f32f..7fd17c2dff 100644
--- a/include/mbgl/map/map_options.hpp
+++ b/include/mbgl/map/map_options.hpp
@@ -89,6 +89,28 @@ public:
bool crossSourceCollisions() const;
/**
+ * @brief Specify whether render data for layers, sources and images should be kept between renderStill() calls.
+ *
+ * This flag is ignored in Continuous mode. In Static mode and Tile mode, if this flag is set to false, all the data
+ * are created from scratch for every renderStill() call, which guaranties that no extra memory is used, however it
+ * might cause higher CPU load and network traffic.
+ *
+ * By default, it is set to true.
+ *
+ * @param keepRenderData true to enable, false to disable
+ * @return MapOptions for chaining options together.
+ */
+ MapOptions& withKeepRenderData(bool keepRenderData);
+
+ /**
+ * @brief Gets the previously set (or default) keepRenderData value.
+ *
+ * @return true if render data is kept between renderStill() calls,
+ * false otherwise.
+ */
+ bool keepRenderData() const;
+
+ /**
* @brief Sets the orientation of the Map. By default, it is set to
* Upwards.
*
diff --git a/src/mbgl/map/map_impl.cpp b/src/mbgl/map/map_impl.cpp
index 0edc715134..60d4d6021c 100644
--- a/src/mbgl/map/map_impl.cpp
+++ b/src/mbgl/map/map_impl.cpp
@@ -17,6 +17,7 @@ Map::Impl::Impl(RendererFrontend& frontend_,
mode(mapOptions.mapMode()),
pixelRatio(mapOptions.pixelRatio()),
crossSourceCollisions(mapOptions.crossSourceCollisions()),
+ keepRenderData(mapOptions.keepRenderData()),
fileSource(std::move(fileSource_)),
style(std::make_unique<style::Style>(fileSource, pixelRatio)),
annotationManager(*style) {
@@ -64,8 +65,9 @@ void Map::Impl::onUpdate() {
annotationManager.makeWeakPtr(),
fileSource,
prefetchZoomDelta,
- bool(stillImageRequest),
- crossSourceCollisions};
+ stillImageRequest.get(),
+ crossSourceCollisions,
+ keepRenderData};
rendererFrontend.update(std::make_shared<UpdateParameters>(std::move(params)));
}
diff --git a/src/mbgl/map/map_impl.hpp b/src/mbgl/map/map_impl.hpp
index 416662f9e5..56b18e4b2d 100644
--- a/src/mbgl/map/map_impl.hpp
+++ b/src/mbgl/map/map_impl.hpp
@@ -59,6 +59,7 @@ public:
const MapMode mode;
const float pixelRatio;
const bool crossSourceCollisions;
+ const bool keepRenderData;
MapDebugOptions debugOptions { MapDebugOptions::NoDebug };
diff --git a/src/mbgl/map/map_options.cpp b/src/mbgl/map/map_options.cpp
index 4cebb6adab..1e93125fd7 100644
--- a/src/mbgl/map/map_options.cpp
+++ b/src/mbgl/map/map_options.cpp
@@ -9,6 +9,7 @@ public:
ViewportMode viewportMode = ViewportMode::Default;
NorthOrientation orientation = NorthOrientation::Upwards;
bool crossSourceCollisions = true;
+ bool keepRenderData = true;
Size size = { 64, 64 };
float pixelRatio = 1.0;
};
@@ -54,6 +55,15 @@ bool MapOptions::crossSourceCollisions() const {
return impl_->crossSourceCollisions;
}
+MapOptions& MapOptions::withKeepRenderData(bool keepRenderData_) {
+ impl_->keepRenderData = keepRenderData_;
+ return *this;
+}
+
+bool MapOptions::keepRenderData() const {
+ return impl_->keepRenderData;
+}
+
MapOptions& MapOptions::withNorthOrientation(NorthOrientation orientation) {
impl_->orientation = orientation;
return *this;
diff --git a/src/mbgl/renderer/render_orchestrator.cpp b/src/mbgl/renderer/render_orchestrator.cpp
index 7fb6eff29c..5851da98eb 100644
--- a/src/mbgl/renderer/render_orchestrator.cpp
+++ b/src/mbgl/renderer/render_orchestrator.cpp
@@ -141,6 +141,13 @@ std::unique_ptr<RenderTree> RenderOrchestrator::createRenderTree(
if (!isMapModeContinuous) {
// Reset zoom history state.
zoomHistory.first = true;
+ if (!updateParameters->keepRenderData && stillImageRequest != updateParameters->stillImageRequest) {
+ sourceImpls = makeMutable<std::vector<Immutable<style::Source::Impl>>>();
+ layerImpls = makeMutable<std::vector<Immutable<style::Layer::Impl>>>();
+ renderSources.clear();
+ renderLayers.clear();
+ stillImageRequest = updateParameters->stillImageRequest;
+ }
}
if (LayerManager::annotationsEnabled) {
diff --git a/src/mbgl/renderer/render_orchestrator.hpp b/src/mbgl/renderer/render_orchestrator.hpp
index 4983538749..7ede688dd7 100644
--- a/src/mbgl/renderer/render_orchestrator.hpp
+++ b/src/mbgl/renderer/render_orchestrator.hpp
@@ -126,6 +126,7 @@ private:
const bool backgroundLayerAsColor;
bool contextLost = false;
+ const void* stillImageRequest = nullptr;
// Vectors with reserved capacity of layerImpls->size() to avoid reallocation
// on each frame.
diff --git a/src/mbgl/renderer/update_parameters.hpp b/src/mbgl/renderer/update_parameters.hpp
index 8dd256329a..fbdebc4197 100644
--- a/src/mbgl/renderer/update_parameters.hpp
+++ b/src/mbgl/renderer/update_parameters.hpp
@@ -41,9 +41,12 @@ public:
const uint8_t prefetchZoomDelta;
// For still image requests, render requested
- const bool stillImageRequest;
-
+ const void* stillImageRequest;
+
const bool crossSourceCollisions;
+
+ // If set, the render data from the previous render calls is kept.
+ const bool keepRenderData;
};
} // namespace mbgl