[core] Introduce Renderer::clearData() instead of keepRenderData map options
`Renderer::clearData()` is a better API than the removed `MapOptions::keepRenderData()`: - gives more flexibility to the client - similar to the existing `Renderer::reduceMemoryUse()` - the `MapOptions::keepRenderData()` API implementation could not handle the raise condition, which happened if the new still image request had come before all tiles from the previous requests were loaded. Co-authored-by: Dane Springmeyer <dane@mapbox.com>
This commit is contained in:
@@ -88,28 +88,6 @@ 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.
|
||||
|
||||
@@ -63,6 +63,7 @@ public:
|
||||
|
||||
// Memory
|
||||
void reduceMemoryUse();
|
||||
void clearData();
|
||||
|
||||
private:
|
||||
class Impl;
|
||||
|
||||
@@ -641,6 +641,7 @@ TestOperations getAfterOperations(const Manifest& manifest) {
|
||||
}
|
||||
|
||||
void resetContext(const TestMetadata& metadata, TestContext& ctx) {
|
||||
ctx.getFrontend().getRenderer()->clearData();
|
||||
ctx.getFrontend().setSize(metadata.size);
|
||||
auto& map = ctx.getMap();
|
||||
map.setSize(metadata.size);
|
||||
@@ -683,8 +684,7 @@ TestRunner::Impl::Impl(const TestMetadata& metadata, const mbgl::ResourceOptions
|
||||
.withMapMode(metadata.mapMode)
|
||||
.withSize(metadata.size)
|
||||
.withPixelRatio(metadata.pixelRatio)
|
||||
.withCrossSourceCollisions(metadata.crossSourceCollisions)
|
||||
.withKeepRenderData(metadata.mapMode != MapMode::Tile),
|
||||
.withCrossSourceCollisions(metadata.crossSourceCollisions),
|
||||
resourceOptions) {}
|
||||
|
||||
TestRunner::Impl::~Impl() {}
|
||||
|
||||
@@ -17,7 +17,6 @@ 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) {
|
||||
@@ -65,9 +64,8 @@ void Map::Impl::onUpdate() {
|
||||
annotationManager.makeWeakPtr(),
|
||||
fileSource,
|
||||
prefetchZoomDelta,
|
||||
stillImageRequest.get(),
|
||||
crossSourceCollisions,
|
||||
keepRenderData};
|
||||
bool(stillImageRequest),
|
||||
crossSourceCollisions};
|
||||
|
||||
rendererFrontend.update(std::make_shared<UpdateParameters>(std::move(params)));
|
||||
}
|
||||
|
||||
@@ -59,7 +59,6 @@ public:
|
||||
const MapMode mode;
|
||||
const float pixelRatio;
|
||||
const bool crossSourceCollisions;
|
||||
const bool keepRenderData;
|
||||
|
||||
MapDebugOptions debugOptions { MapDebugOptions::NoDebug };
|
||||
|
||||
|
||||
@@ -9,7 +9,6 @@ public:
|
||||
ViewportMode viewportMode = ViewportMode::Default;
|
||||
NorthOrientation orientation = NorthOrientation::Upwards;
|
||||
bool crossSourceCollisions = true;
|
||||
bool keepRenderData = true;
|
||||
Size size = { 64, 64 };
|
||||
float pixelRatio = 1.0;
|
||||
};
|
||||
@@ -55,15 +54,6 @@ 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;
|
||||
|
||||
@@ -141,10 +141,6 @@ std::unique_ptr<RenderTree> RenderOrchestrator::createRenderTree(
|
||||
if (!isMapModeContinuous) {
|
||||
// Reset zoom history state.
|
||||
zoomHistory.first = true;
|
||||
if (!updateParameters->keepRenderData && stillImageRequest != updateParameters->stillImageRequest) {
|
||||
clearData();
|
||||
stillImageRequest = updateParameters->stillImageRequest;
|
||||
}
|
||||
}
|
||||
|
||||
if (LayerManager::annotationsEnabled) {
|
||||
|
||||
@@ -75,11 +75,11 @@ public:
|
||||
|
||||
void reduceMemoryUse();
|
||||
void dumpDebugLogs();
|
||||
void clearData();
|
||||
|
||||
private:
|
||||
bool isLoaded() const;
|
||||
bool hasTransitions(TimePoint) const;
|
||||
void clearData();
|
||||
|
||||
RenderSource* getRenderSource(const std::string& id) const;
|
||||
|
||||
@@ -127,7 +127,6 @@ private:
|
||||
|
||||
const bool backgroundLayerAsColor;
|
||||
bool contextLost = false;
|
||||
const void* stillImageRequest = nullptr;
|
||||
|
||||
// Vectors with reserved capacity of layerImpls->size() to avoid reallocation
|
||||
// on each frame.
|
||||
|
||||
@@ -131,4 +131,8 @@ void Renderer::reduceMemoryUse() {
|
||||
impl->orchestrator.reduceMemoryUse();
|
||||
}
|
||||
|
||||
void Renderer::clearData() {
|
||||
impl->orchestrator.clearData();
|
||||
}
|
||||
|
||||
} // namespace mbgl
|
||||
|
||||
@@ -41,12 +41,9 @@ public:
|
||||
const uint8_t prefetchZoomDelta;
|
||||
|
||||
// For still image requests, render requested
|
||||
const void* stillImageRequest;
|
||||
const bool stillImageRequest;
|
||||
|
||||
const bool crossSourceCollisions;
|
||||
|
||||
// If set, the render data from the previous render calls is kept.
|
||||
const bool keepRenderData;
|
||||
};
|
||||
|
||||
} // namespace mbgl
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
#include <mbgl/gl/context.hpp>
|
||||
#include <mbgl/map/map_options.hpp>
|
||||
#include <mbgl/math/log2.hpp>
|
||||
#include <mbgl/renderer/renderer.hpp>
|
||||
#include <mbgl/renderer/update_parameters.hpp>
|
||||
#include <mbgl/storage/file_source_manager.hpp>
|
||||
#include <mbgl/storage/main_resource_loader.hpp>
|
||||
@@ -1362,7 +1363,7 @@ constexpr auto styleJSON = R"STYLE({
|
||||
}
|
||||
|
||||
TEST(Map, KeepRenderData) {
|
||||
MapTest<> test{std::move(MapOptions().withMapMode(MapMode::Static).withKeepRenderData(true))};
|
||||
MapTest<> test;
|
||||
int requestsCount = 0;
|
||||
test.fileSource->tileResponse = [&](const Resource&) {
|
||||
++requestsCount;
|
||||
@@ -1371,30 +1372,19 @@ TEST(Map, KeepRenderData) {
|
||||
return res;
|
||||
};
|
||||
test.map.jumpTo(CameraOptions().withZoom(10));
|
||||
test.map.getStyle().loadJSON(styleJSON);
|
||||
test.frontend.render(test.map);
|
||||
EXPECT_EQ(4, requestsCount);
|
||||
|
||||
test.map.getStyle().loadJSON(styleJSON);
|
||||
test.frontend.render(test.map);
|
||||
EXPECT_EQ(4, requestsCount);
|
||||
}
|
||||
|
||||
TEST(Map, DontKeepRenderData) {
|
||||
MapTest<> test{std::move(MapOptions().withMapMode(MapMode::Static).withKeepRenderData(false))};
|
||||
int requestsCount = 0;
|
||||
test.fileSource->tileResponse = [&](const Resource&) {
|
||||
++requestsCount;
|
||||
Response res;
|
||||
res.noContent = true;
|
||||
return res;
|
||||
};
|
||||
test.map.jumpTo(CameraOptions().withZoom(10));
|
||||
test.map.getStyle().loadJSON(styleJSON);
|
||||
test.frontend.render(test.map);
|
||||
EXPECT_EQ(4, requestsCount);
|
||||
|
||||
test.map.getStyle().loadJSON(styleJSON);
|
||||
test.frontend.render(test.map);
|
||||
EXPECT_EQ(8, requestsCount);
|
||||
const int iterations = 3;
|
||||
// Keep render data.
|
||||
for (int i = 1; i <= iterations; ++i) {
|
||||
test.map.getStyle().loadJSON(styleJSON);
|
||||
test.frontend.render(test.map);
|
||||
EXPECT_EQ(4, requestsCount);
|
||||
}
|
||||
requestsCount = 0;
|
||||
// Clear render data.
|
||||
for (int i = 1; i <= iterations; ++i) {
|
||||
test.frontend.getRenderer()->clearData();
|
||||
test.map.getStyle().loadJSON(styleJSON);
|
||||
test.frontend.render(test.map);
|
||||
EXPECT_EQ(4 * i, requestsCount);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user