explicitly call .discard() to resize the view on static renders
- this is only a stopgap; we need to properly pass state between threads - doesn't fix changing the pixel ratio
This commit is contained in:
@@ -804,6 +804,9 @@ void Map::prepare() {
|
||||
}
|
||||
|
||||
if (u & static_cast<UpdateType>(Update::RenderStill)) {
|
||||
// Triggers a view resize.
|
||||
view.discard();
|
||||
|
||||
// Whenever we trigger an image render, we are unrefing all async handles so the loop will
|
||||
// eventually terminate. However, it'll stay alive as long as there are pending requests
|
||||
// (like work requests or HTTP requests).
|
||||
|
||||
63
test/api/repeated_render.cpp
Normal file
63
test/api/repeated_render.cpp
Normal file
@@ -0,0 +1,63 @@
|
||||
#include "../fixtures/util.hpp"
|
||||
#include "../fixtures/fixture_log_observer.hpp"
|
||||
|
||||
#include <mbgl/map/map.hpp>
|
||||
#include <mbgl/map/still_image.hpp>
|
||||
#include <mbgl/platform/default/headless_view.hpp>
|
||||
#include <mbgl/platform/default/headless_display.hpp>
|
||||
#include <mbgl/storage/default_file_source.hpp>
|
||||
#include <mbgl/util/image.hpp>
|
||||
#include <mbgl/util/io.hpp>
|
||||
|
||||
#include <future>
|
||||
|
||||
TEST(API, RepeatedRender) {
|
||||
using namespace mbgl;
|
||||
|
||||
const auto style = util::read_file("test/fixtures/api/water.json");
|
||||
|
||||
auto display = std::make_shared<mbgl::HeadlessDisplay>();
|
||||
HeadlessView view(display);
|
||||
DefaultFileSource fileSource(nullptr);
|
||||
|
||||
Log::setObserver(util::make_unique<FixtureLogObserver>());
|
||||
|
||||
Map map(view, fileSource);
|
||||
|
||||
map.start(Map::Mode::Static);
|
||||
|
||||
{
|
||||
view.resize(128, 512, 1);
|
||||
map.setStyleJSON(style, "test/suite");
|
||||
std::promise<std::unique_ptr<const StillImage>> promise;
|
||||
map.renderStill([&promise](std::unique_ptr<const StillImage> image) {
|
||||
promise.set_value(std::move(image));
|
||||
});
|
||||
auto result = promise.get_future().get();
|
||||
ASSERT_EQ(128, result->width);
|
||||
ASSERT_EQ(512, result->height);
|
||||
const std::string png = util::compress_png(result->width, result->height, result->pixels.get());
|
||||
util::write_file("test/fixtures/api/1.png", png);
|
||||
}
|
||||
|
||||
{
|
||||
view.resize(512, 512, 2);
|
||||
map.setStyleJSON(style, "TEST_DATA/suite");
|
||||
std::promise<std::unique_ptr<const StillImage>> promise;
|
||||
map.renderStill([&promise](std::unique_ptr<const StillImage> image) {
|
||||
promise.set_value(std::move(image));
|
||||
});
|
||||
auto result = promise.get_future().get();
|
||||
ASSERT_EQ(1024, result->width);
|
||||
ASSERT_EQ(1024, result->height);
|
||||
const std::string png = util::compress_png(result->width, result->height, result->pixels.get());
|
||||
util::write_file("test/fixtures/api/2.png", png);
|
||||
}
|
||||
|
||||
map.stop();
|
||||
|
||||
auto observer = Log::removeObserver();
|
||||
auto flo = dynamic_cast<FixtureLogObserver*>(observer.get());
|
||||
auto unchecked = flo->unchecked();
|
||||
EXPECT_TRUE(unchecked.empty()) << unchecked;
|
||||
}
|
||||
BIN
test/fixtures/api/1.png
vendored
Normal file
BIN
test/fixtures/api/1.png
vendored
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 12 KiB |
BIN
test/fixtures/api/2.png
vendored
Normal file
BIN
test/fixtures/api/2.png
vendored
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 112 KiB |
25
test/fixtures/api/water.json
vendored
Normal file
25
test/fixtures/api/water.json
vendored
Normal file
@@ -0,0 +1,25 @@
|
||||
{
|
||||
"version": 7,
|
||||
"name": "Water",
|
||||
"sources": {
|
||||
"mapbox": {
|
||||
"type": "vector",
|
||||
"url": "asset://TEST_DATA/fixtures/tiles/streets.json"
|
||||
}
|
||||
},
|
||||
"layers": [{
|
||||
"id": "background",
|
||||
"type": "background",
|
||||
"paint": {
|
||||
"background-color": "red"
|
||||
}
|
||||
}, {
|
||||
"id": "water",
|
||||
"type": "fill",
|
||||
"source": "mapbox",
|
||||
"source-layer": "water",
|
||||
"paint": {
|
||||
"fill-color": "blue"
|
||||
}
|
||||
}]
|
||||
}
|
||||
14
test/fixtures/tiles/streets.json
vendored
Normal file
14
test/fixtures/tiles/streets.json
vendored
Normal file
@@ -0,0 +1,14 @@
|
||||
{
|
||||
"bounds": [ -180, -85.0511, 180, 85.0511 ],
|
||||
"center": [ 0, 0, 0 ],
|
||||
"description": "",
|
||||
"format": "pbf",
|
||||
"id": "streets",
|
||||
"maskLevel": 8,
|
||||
"maxzoom": 15,
|
||||
"minzoom": 0,
|
||||
"name": "Streets",
|
||||
"scheme": "xyz",
|
||||
"tilejson": "2.0.0",
|
||||
"tiles": [ "asset://TEST_DATA/fixtures/tiles/streets/{z}-{x}-{y}.vector.pbf" ]
|
||||
}
|
||||
BIN
test/fixtures/tiles/streets/0-0-0.vector.pbf
vendored
Normal file
BIN
test/fixtures/tiles/streets/0-0-0.vector.pbf
vendored
Normal file
Binary file not shown.
@@ -36,6 +36,7 @@
|
||||
'fixtures/fixture_log_observer.cpp',
|
||||
|
||||
'api/set_style.cpp',
|
||||
'api/repeated_render.cpp',
|
||||
|
||||
'headless/headless.cpp',
|
||||
|
||||
|
||||
Reference in New Issue
Block a user