diff --git a/CHANGELOG.md b/CHANGELOG.md index 21dd8c669d1..afb1fa55917 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,21 +4,9 @@ ### ✨ New features -- [tile mode][static mode] Clear render data for the new still image request ([#16318](https://github.com/mapbox/mapbox-gl-native/pull/16318)) +- [core] Add Renderer::clearData() ([#16323](https://github.com/mapbox/mapbox-gl-native/pull/16323)) - The new `keepRenderData` map options flag is added to control whether render data shall be kept between `renderStill()` calls. - -### 🐞 Bug fixes - -- [tile mode][static mode] Clear render data for the new still image request ([#16318](https://github.com/mapbox/mapbox-gl-native/pull/16318)) - - If the `keepRenderData` map options flag is unset all render data is cleared between `renderStill()` calls, thus stale tiles from the previous `renderStill()` call are never shown. - -### 🏁 Performance improvements - -- [tile mode][static mode] Clear render data for the new still image request ([#16318](https://github.com/mapbox/mapbox-gl-native/pull/16318)) - - If the `keepRenderData` map options flag is unset all render data is cleared between `renderStill()` calls, thus saving memory being used. + The newly added `Renderer::clearData()` method allows to clear render data and thus save memory and make sure outdated tiles are not shown. It clears data more agressively than `Renderer::reduceMemoryUse()` does, as it clears not only the cache but all orchestration data, including the data used by the currently rendered frame. ## maps-v1.4.1 diff --git a/include/mbgl/map/map_options.hpp b/include/mbgl/map/map_options.hpp index 7fd17c2dff7..fcb8c8f32fd 100644 --- a/include/mbgl/map/map_options.hpp +++ b/include/mbgl/map/map_options.hpp @@ -88,28 +88,6 @@ class MapOptions final { */ 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/include/mbgl/renderer/renderer.hpp b/include/mbgl/renderer/renderer.hpp index 91f2b6146ce..1d71a016b6c 100644 --- a/include/mbgl/renderer/renderer.hpp +++ b/include/mbgl/renderer/renderer.hpp @@ -63,6 +63,7 @@ class Renderer { // Memory void reduceMemoryUse(); + void clearData(); private: class Impl; diff --git a/metrics/android-render-test-runner/render-tests/map-mode/tile-avoid-edges/metrics.json b/metrics/android-render-test-runner/render-tests/map-mode/tile-avoid-edges/metrics.json index 7cc366b904f..1a5ac27a6f6 100644 --- a/metrics/android-render-test-runner/render-tests/map-mode/tile-avoid-edges/metrics.json +++ b/metrics/android-render-test-runner/render-tests/map-mode/tile-avoid-edges/metrics.json @@ -2,8 +2,8 @@ "network": [ [ "probeNetwork - default - end", - 12, - 340753 + 8, + 246523 ], [ "probeNetwork - default - start", diff --git a/metrics/android-render-test-runner/render-tests/symbol-placement/line-center-buffer-tile-map-mode/metrics.json b/metrics/android-render-test-runner/render-tests/symbol-placement/line-center-buffer-tile-map-mode/metrics.json index 2286b68baeb..228731dd4e2 100644 --- a/metrics/android-render-test-runner/render-tests/symbol-placement/line-center-buffer-tile-map-mode/metrics.json +++ b/metrics/android-render-test-runner/render-tests/symbol-placement/line-center-buffer-tile-map-mode/metrics.json @@ -2,8 +2,8 @@ "network": [ [ "probeNetwork - default - end", - 5, - 183111 + 6, + 268053 ], [ "probeNetwork - default - start", diff --git a/metrics/android-render-test-runner/render-tests/symbol-placement/line-center-tile-map-mode/metrics.json b/metrics/android-render-test-runner/render-tests/symbol-placement/line-center-tile-map-mode/metrics.json index 534add1f963..e6f162de074 100644 --- a/metrics/android-render-test-runner/render-tests/symbol-placement/line-center-tile-map-mode/metrics.json +++ b/metrics/android-render-test-runner/render-tests/symbol-placement/line-center-tile-map-mode/metrics.json @@ -2,8 +2,8 @@ "network": [ [ "probeNetwork - default - end", - 5, - 1500180 + 8, + 1755006 ], [ "probeNetwork - default - start", diff --git a/metrics/android-render-test-runner/render-tests/text-variable-anchor/all-anchors-tile-map-mode/metrics.json b/metrics/android-render-test-runner/render-tests/text-variable-anchor/all-anchors-tile-map-mode/metrics.json index 54a19167d9d..1a348fa3efe 100644 --- a/metrics/android-render-test-runner/render-tests/text-variable-anchor/all-anchors-tile-map-mode/metrics.json +++ b/metrics/android-render-test-runner/render-tests/text-variable-anchor/all-anchors-tile-map-mode/metrics.json @@ -2,8 +2,8 @@ "network": [ [ "probeNetwork - default - end", - 13, - 2413450 + 16, + 2668276 ], [ "probeNetwork - default - start", diff --git a/metrics/android-render-test-runner/render-tests/text-variable-anchor/left-top-right-bottom-offset-tile-map-mode/metrics.json b/metrics/android-render-test-runner/render-tests/text-variable-anchor/left-top-right-bottom-offset-tile-map-mode/metrics.json index b8b5612ad63..22295b952a8 100644 --- a/metrics/android-render-test-runner/render-tests/text-variable-anchor/left-top-right-bottom-offset-tile-map-mode/metrics.json +++ b/metrics/android-render-test-runner/render-tests/text-variable-anchor/left-top-right-bottom-offset-tile-map-mode/metrics.json @@ -2,8 +2,8 @@ "network": [ [ "probeNetwork - default - end", - 15, - 2585276 + 22, + 3183754 ], [ "probeNetwork - default - start", diff --git a/metrics/ios-render-test-runner/render-tests/map-mode/tile-avoid-edges/metrics.json b/metrics/ios-render-test-runner/render-tests/map-mode/tile-avoid-edges/metrics.json index 7cc366b904f..1a5ac27a6f6 100644 --- a/metrics/ios-render-test-runner/render-tests/map-mode/tile-avoid-edges/metrics.json +++ b/metrics/ios-render-test-runner/render-tests/map-mode/tile-avoid-edges/metrics.json @@ -2,8 +2,8 @@ "network": [ [ "probeNetwork - default - end", - 12, - 340753 + 8, + 246523 ], [ "probeNetwork - default - start", diff --git a/metrics/ios-render-test-runner/render-tests/symbol-placement/line-center-buffer-tile-map-mode/metrics.json b/metrics/ios-render-test-runner/render-tests/symbol-placement/line-center-buffer-tile-map-mode/metrics.json index 2286b68baeb..228731dd4e2 100644 --- a/metrics/ios-render-test-runner/render-tests/symbol-placement/line-center-buffer-tile-map-mode/metrics.json +++ b/metrics/ios-render-test-runner/render-tests/symbol-placement/line-center-buffer-tile-map-mode/metrics.json @@ -2,8 +2,8 @@ "network": [ [ "probeNetwork - default - end", - 5, - 183111 + 6, + 268053 ], [ "probeNetwork - default - start", diff --git a/metrics/ios-render-test-runner/render-tests/symbol-placement/line-center-tile-map-mode/metrics.json b/metrics/ios-render-test-runner/render-tests/symbol-placement/line-center-tile-map-mode/metrics.json index 534add1f963..e6f162de074 100644 --- a/metrics/ios-render-test-runner/render-tests/symbol-placement/line-center-tile-map-mode/metrics.json +++ b/metrics/ios-render-test-runner/render-tests/symbol-placement/line-center-tile-map-mode/metrics.json @@ -2,8 +2,8 @@ "network": [ [ "probeNetwork - default - end", - 5, - 1500180 + 8, + 1755006 ], [ "probeNetwork - default - start", diff --git a/metrics/ios-render-test-runner/render-tests/text-variable-anchor/all-anchors-tile-map-mode/metrics.json b/metrics/ios-render-test-runner/render-tests/text-variable-anchor/all-anchors-tile-map-mode/metrics.json index 54a19167d9d..1a348fa3efe 100644 --- a/metrics/ios-render-test-runner/render-tests/text-variable-anchor/all-anchors-tile-map-mode/metrics.json +++ b/metrics/ios-render-test-runner/render-tests/text-variable-anchor/all-anchors-tile-map-mode/metrics.json @@ -2,8 +2,8 @@ "network": [ [ "probeNetwork - default - end", - 13, - 2413450 + 16, + 2668276 ], [ "probeNetwork - default - start", diff --git a/metrics/ios-render-test-runner/render-tests/text-variable-anchor/left-top-right-bottom-offset-tile-map-mode/metrics.json b/metrics/ios-render-test-runner/render-tests/text-variable-anchor/left-top-right-bottom-offset-tile-map-mode/metrics.json index b8b5612ad63..22295b952a8 100644 --- a/metrics/ios-render-test-runner/render-tests/text-variable-anchor/left-top-right-bottom-offset-tile-map-mode/metrics.json +++ b/metrics/ios-render-test-runner/render-tests/text-variable-anchor/left-top-right-bottom-offset-tile-map-mode/metrics.json @@ -2,8 +2,8 @@ "network": [ [ "probeNetwork - default - end", - 15, - 2585276 + 22, + 3183754 ], [ "probeNetwork - default - start", diff --git a/metrics/linux-clang8-release/render-tests/map-mode/tile-avoid-edges/metrics.json b/metrics/linux-clang8-release/render-tests/map-mode/tile-avoid-edges/metrics.json index 7cc366b904f..1a5ac27a6f6 100644 --- a/metrics/linux-clang8-release/render-tests/map-mode/tile-avoid-edges/metrics.json +++ b/metrics/linux-clang8-release/render-tests/map-mode/tile-avoid-edges/metrics.json @@ -2,8 +2,8 @@ "network": [ [ "probeNetwork - default - end", - 12, - 340753 + 8, + 246523 ], [ "probeNetwork - default - start", diff --git a/metrics/linux-clang8-release/render-tests/symbol-placement/line-center-buffer-tile-map-mode/metrics.json b/metrics/linux-clang8-release/render-tests/symbol-placement/line-center-buffer-tile-map-mode/metrics.json index 2286b68baeb..228731dd4e2 100644 --- a/metrics/linux-clang8-release/render-tests/symbol-placement/line-center-buffer-tile-map-mode/metrics.json +++ b/metrics/linux-clang8-release/render-tests/symbol-placement/line-center-buffer-tile-map-mode/metrics.json @@ -2,8 +2,8 @@ "network": [ [ "probeNetwork - default - end", - 5, - 183111 + 6, + 268053 ], [ "probeNetwork - default - start", diff --git a/metrics/linux-clang8-release/render-tests/symbol-placement/line-center-tile-map-mode/metrics.json b/metrics/linux-clang8-release/render-tests/symbol-placement/line-center-tile-map-mode/metrics.json index 534add1f963..e6f162de074 100644 --- a/metrics/linux-clang8-release/render-tests/symbol-placement/line-center-tile-map-mode/metrics.json +++ b/metrics/linux-clang8-release/render-tests/symbol-placement/line-center-tile-map-mode/metrics.json @@ -2,8 +2,8 @@ "network": [ [ "probeNetwork - default - end", - 5, - 1500180 + 8, + 1755006 ], [ "probeNetwork - default - start", diff --git a/metrics/linux-clang8-release/render-tests/text-variable-anchor/all-anchors-tile-map-mode/metrics.json b/metrics/linux-clang8-release/render-tests/text-variable-anchor/all-anchors-tile-map-mode/metrics.json index 54a19167d9d..1a348fa3efe 100644 --- a/metrics/linux-clang8-release/render-tests/text-variable-anchor/all-anchors-tile-map-mode/metrics.json +++ b/metrics/linux-clang8-release/render-tests/text-variable-anchor/all-anchors-tile-map-mode/metrics.json @@ -2,8 +2,8 @@ "network": [ [ "probeNetwork - default - end", - 13, - 2413450 + 16, + 2668276 ], [ "probeNetwork - default - start", diff --git a/metrics/linux-clang8-release/render-tests/text-variable-anchor/left-top-right-bottom-offset-tile-map-mode/metrics.json b/metrics/linux-clang8-release/render-tests/text-variable-anchor/left-top-right-bottom-offset-tile-map-mode/metrics.json index b8b5612ad63..22295b952a8 100644 --- a/metrics/linux-clang8-release/render-tests/text-variable-anchor/left-top-right-bottom-offset-tile-map-mode/metrics.json +++ b/metrics/linux-clang8-release/render-tests/text-variable-anchor/left-top-right-bottom-offset-tile-map-mode/metrics.json @@ -2,8 +2,8 @@ "network": [ [ "probeNetwork - default - end", - 15, - 2585276 + 22, + 3183754 ], [ "probeNetwork - default - start", diff --git a/metrics/linux-gcc8-release/render-tests/map-mode/tile-avoid-edges/metrics.json b/metrics/linux-gcc8-release/render-tests/map-mode/tile-avoid-edges/metrics.json index 7cc366b904f..1a5ac27a6f6 100644 --- a/metrics/linux-gcc8-release/render-tests/map-mode/tile-avoid-edges/metrics.json +++ b/metrics/linux-gcc8-release/render-tests/map-mode/tile-avoid-edges/metrics.json @@ -2,8 +2,8 @@ "network": [ [ "probeNetwork - default - end", - 12, - 340753 + 8, + 246523 ], [ "probeNetwork - default - start", diff --git a/metrics/linux-gcc8-release/render-tests/symbol-placement/line-center-buffer-tile-map-mode/metrics.json b/metrics/linux-gcc8-release/render-tests/symbol-placement/line-center-buffer-tile-map-mode/metrics.json index 2286b68baeb..228731dd4e2 100644 --- a/metrics/linux-gcc8-release/render-tests/symbol-placement/line-center-buffer-tile-map-mode/metrics.json +++ b/metrics/linux-gcc8-release/render-tests/symbol-placement/line-center-buffer-tile-map-mode/metrics.json @@ -2,8 +2,8 @@ "network": [ [ "probeNetwork - default - end", - 5, - 183111 + 6, + 268053 ], [ "probeNetwork - default - start", diff --git a/metrics/linux-gcc8-release/render-tests/symbol-placement/line-center-tile-map-mode/metrics.json b/metrics/linux-gcc8-release/render-tests/symbol-placement/line-center-tile-map-mode/metrics.json index 534add1f963..e6f162de074 100644 --- a/metrics/linux-gcc8-release/render-tests/symbol-placement/line-center-tile-map-mode/metrics.json +++ b/metrics/linux-gcc8-release/render-tests/symbol-placement/line-center-tile-map-mode/metrics.json @@ -2,8 +2,8 @@ "network": [ [ "probeNetwork - default - end", - 5, - 1500180 + 8, + 1755006 ], [ "probeNetwork - default - start", diff --git a/metrics/linux-gcc8-release/render-tests/text-variable-anchor/all-anchors-tile-map-mode/metrics.json b/metrics/linux-gcc8-release/render-tests/text-variable-anchor/all-anchors-tile-map-mode/metrics.json index 54a19167d9d..1a348fa3efe 100644 --- a/metrics/linux-gcc8-release/render-tests/text-variable-anchor/all-anchors-tile-map-mode/metrics.json +++ b/metrics/linux-gcc8-release/render-tests/text-variable-anchor/all-anchors-tile-map-mode/metrics.json @@ -2,8 +2,8 @@ "network": [ [ "probeNetwork - default - end", - 13, - 2413450 + 16, + 2668276 ], [ "probeNetwork - default - start", diff --git a/metrics/linux-gcc8-release/render-tests/text-variable-anchor/left-top-right-bottom-offset-tile-map-mode/metrics.json b/metrics/linux-gcc8-release/render-tests/text-variable-anchor/left-top-right-bottom-offset-tile-map-mode/metrics.json index b8b5612ad63..22295b952a8 100644 --- a/metrics/linux-gcc8-release/render-tests/text-variable-anchor/left-top-right-bottom-offset-tile-map-mode/metrics.json +++ b/metrics/linux-gcc8-release/render-tests/text-variable-anchor/left-top-right-bottom-offset-tile-map-mode/metrics.json @@ -2,8 +2,8 @@ "network": [ [ "probeNetwork - default - end", - 15, - 2585276 + 22, + 3183754 ], [ "probeNetwork - default - start", diff --git a/render-test/runner.cpp b/render-test/runner.cpp index 4fc68d0a1a5..de43e5ddd8c 100644 --- a/render-test/runner.cpp +++ b/render-test/runner.cpp @@ -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() {} diff --git a/src/mbgl/map/map_impl.cpp b/src/mbgl/map/map_impl.cpp index 60d4d6021ce..0edc7151343 100644 --- a/src/mbgl/map/map_impl.cpp +++ b/src/mbgl/map/map_impl.cpp @@ -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(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(std::move(params))); } diff --git a/src/mbgl/map/map_impl.hpp b/src/mbgl/map/map_impl.hpp index 56b18e4b2d3..416662f9e56 100644 --- a/src/mbgl/map/map_impl.hpp +++ b/src/mbgl/map/map_impl.hpp @@ -59,7 +59,6 @@ class Map::Impl : public style::Observer, public RendererObserver { 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 1e93125fd7e..4cebb6adabb 100644 --- a/src/mbgl/map/map_options.cpp +++ b/src/mbgl/map/map_options.cpp @@ -9,7 +9,6 @@ class MapOptions::Impl { 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; diff --git a/src/mbgl/renderer/render_orchestrator.cpp b/src/mbgl/renderer/render_orchestrator.cpp index 985aac98b47..9cab1d7caad 100644 --- a/src/mbgl/renderer/render_orchestrator.cpp +++ b/src/mbgl/renderer/render_orchestrator.cpp @@ -141,10 +141,6 @@ std::unique_ptr RenderOrchestrator::createRenderTree( if (!isMapModeContinuous) { // Reset zoom history state. zoomHistory.first = true; - if (!updateParameters->keepRenderData && stillImageRequest != updateParameters->stillImageRequest) { - clearData(); - stillImageRequest = updateParameters->stillImageRequest; - } } if (LayerManager::annotationsEnabled) { @@ -713,6 +709,7 @@ void RenderOrchestrator::clearData() { if (!patternAtlas->isEmpty()) patternAtlas = std::make_unique(); imageManager->clear(); + glyphManager->evict(fontStacks(*layerImpls)); } void RenderOrchestrator::onGlyphsError(const FontStack& fontStack, const GlyphRange& glyphRange, std::exception_ptr error) { diff --git a/src/mbgl/renderer/render_orchestrator.hpp b/src/mbgl/renderer/render_orchestrator.hpp index 312b28fd561..7c1abfe1f4c 100644 --- a/src/mbgl/renderer/render_orchestrator.hpp +++ b/src/mbgl/renderer/render_orchestrator.hpp @@ -75,11 +75,11 @@ class RenderOrchestrator final : public GlyphManagerObserver, 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 @@ class RenderOrchestrator final : public GlyphManagerObserver, 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/renderer.cpp b/src/mbgl/renderer/renderer.cpp index 5afbbbd47ee..ac2f327a4ee 100644 --- a/src/mbgl/renderer/renderer.cpp +++ b/src/mbgl/renderer/renderer.cpp @@ -131,4 +131,8 @@ void Renderer::reduceMemoryUse() { impl->orchestrator.reduceMemoryUse(); } +void Renderer::clearData() { + impl->orchestrator.clearData(); +} + } // namespace mbgl diff --git a/src/mbgl/renderer/update_parameters.hpp b/src/mbgl/renderer/update_parameters.hpp index fbdebc4197a..4336fa0972f 100644 --- a/src/mbgl/renderer/update_parameters.hpp +++ b/src/mbgl/renderer/update_parameters.hpp @@ -41,12 +41,9 @@ class UpdateParameters { 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 diff --git a/test/map/map.test.cpp b/test/map/map.test.cpp index 0e619d3d1f1..f582a662e01 100644 --- a/test/map/map.test.cpp +++ b/test/map/map.test.cpp @@ -10,6 +10,7 @@ #include #include #include +#include #include #include #include @@ -1348,53 +1349,44 @@ TEST(Map, TEST_REQUIRES_SERVER(ExpiredSpriteSheet)) { } namespace { -constexpr auto styleJSON = R"STYLE({ - "sources": { - "a": { "type": "vector", "tiles": [ "a/{z}/{x}/{y}" ] } - }, - "layers": [{ - "id": "a", - "type": "fill", - "source": "a", - "source-layer": "a" - }] -})STYLE"; + +int requestsCount = 0; +auto makeResponse(const std::string& file, bool incrementCounter = false) { + return [file, incrementCounter](const Resource&) { + if (incrementCounter) ++requestsCount; + Response result; + result.data = std::make_shared(util::read_file("test/fixtures/resources/" + file)); + return result; + }; } +} // namespace + TEST(Map, KeepRenderData) { - MapTest<> test{std::move(MapOptions().withMapMode(MapMode::Static).withKeepRenderData(true))}; - 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); + MapTest<> test; - test.map.getStyle().loadJSON(styleJSON); - test.frontend.render(test.map); - EXPECT_EQ(4, requestsCount); -} + test.fileSource->tileResponse = makeResponse("vector.tile", true); + test.fileSource->glyphsResponse = makeResponse("glyphs.pbf", true); + // The resources below belong to style and requested on style re-load. + test.fileSource->styleResponse = makeResponse("style_vector.json"); + test.fileSource->sourceResponse = makeResponse("source_vector.json"); + test.fileSource->spriteJSONResponse = makeResponse("sprite.json"); + test.fileSource->spriteImageResponse = makeResponse("sprite.png"); -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); + test.map.getStyle().loadURL("mapbox://streets"); + const int iterations = 3; + const int resourcesCount = 4 /*tiles*/ + 3 /*fonts*/; + // Keep render data. + for (int i = 1; i <= iterations; ++i) { + test.frontend.render(test.map); + EXPECT_EQ(resourcesCount, requestsCount); + } + requestsCount = 0; + // Clear render data. + for (int i = 1; i <= iterations; ++i) { + test.frontend.getRenderer()->clearData(); + test.frontend.render(test.map); + EXPECT_EQ(resourcesCount * i, requestsCount); + } } \ No newline at end of file