diff options
author | Mikhail Pozdnyakov <mikhail.pozdnyakov@mapbox.com> | 2020-03-19 22:14:12 +0200 |
---|---|---|
committer | Mikhail Pozdnyakov <mikhail.pozdnyakov@mapbox.com> | 2020-03-20 11:43:59 +0200 |
commit | 8bf841a9513c28057fcedb0dab032bb00016b90c (patch) | |
tree | b429559bcd8f8e20e60b6e89ce39d34171e7eb41 | |
parent | cb1d5053b09e91df72b655041b6995d23f9f0161 (diff) | |
download | qtlocation-mapboxgl-8bf841a9513c28057fcedb0dab032bb00016b90c.tar.gz |
[core] Render::clearData clears fonts
-rw-r--r-- | CHANGELOG.md | 2 | ||||
-rw-r--r-- | src/mbgl/renderer/render_orchestrator.cpp | 1 | ||||
-rw-r--r-- | test/map/map.test.cpp | 46 |
3 files changed, 26 insertions, 23 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index fb396c4c59..afb1fa5591 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,7 +6,7 @@ - [core] Add Renderer::clearData() ([#16323](https://github.com/mapbox/mapbox-gl-native/pull/16323)) - The newly added `Renderer::clearData()` method allows to clear render data and thus save memory and make sure outdated tiles are not shown. + 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/src/mbgl/renderer/render_orchestrator.cpp b/src/mbgl/renderer/render_orchestrator.cpp index 08338ff616..9cab1d7caa 100644 --- a/src/mbgl/renderer/render_orchestrator.cpp +++ b/src/mbgl/renderer/render_orchestrator.cpp @@ -709,6 +709,7 @@ void RenderOrchestrator::clearData() { if (!patternAtlas->isEmpty()) patternAtlas = std::make_unique<PatternAtlas>(); imageManager->clear(); + glyphManager->evict(fontStacks(*layerImpls)); } void RenderOrchestrator::onGlyphsError(const FontStack& fontStack, const GlyphRange& glyphRange, std::exception_ptr error) { diff --git a/test/map/map.test.cpp b/test/map/map.test.cpp index baf1cd03a6..f582a662e0 100644 --- a/test/map/map.test.cpp +++ b/test/map/map.test.cpp @@ -1349,42 +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<std::string>(util::read_file("test/fixtures/resources/" + file)); + return result; + }; } +} // namespace + TEST(Map, KeepRenderData) { MapTest<> test; - int requestsCount = 0; - test.fileSource->tileResponse = [&](const Resource&) { - ++requestsCount; - Response res; - res.noContent = true; - return res; - }; + + 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.jumpTo(CameraOptions().withZoom(10)); + 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.map.getStyle().loadJSON(styleJSON); test.frontend.render(test.map); - EXPECT_EQ(4, requestsCount); + EXPECT_EQ(resourcesCount, 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); + EXPECT_EQ(resourcesCount * i, requestsCount); } }
\ No newline at end of file |