[render test runner] Enable pixel ratio in tile mode
This commit is contained in:
@@ -466,14 +466,42 @@ TestMetadata parseTestMetadata(const TestPaths& paths) {
|
||||
|
||||
const mbgl::JSValue& testValue = metadataValue["test"];
|
||||
|
||||
if (testValue.HasMember("mapMode")) {
|
||||
metadata.outputsImage = true;
|
||||
assert(testValue["mapMode"].IsString());
|
||||
std::string mapModeStr = testValue["mapMode"].GetString();
|
||||
if (mapModeStr == "tile") {
|
||||
metadata.mapMode = mbgl::MapMode::Tile;
|
||||
// In the tile mode, map is showing exactly one tile.
|
||||
metadata.size = {uint32_t(mbgl::util::tileSize), uint32_t(mbgl::util::tileSize)};
|
||||
} else if (mapModeStr == "continuous") {
|
||||
metadata.mapMode = mbgl::MapMode::Continuous;
|
||||
metadata.outputsImage = false;
|
||||
} else if (mapModeStr == "static")
|
||||
metadata.mapMode = mbgl::MapMode::Static;
|
||||
else {
|
||||
mbgl::Log::Warning(
|
||||
mbgl::Event::ParseStyle, "Unknown map mode: %s. Falling back to static mode", mapModeStr.c_str());
|
||||
metadata.mapMode = mbgl::MapMode::Static;
|
||||
}
|
||||
}
|
||||
|
||||
if (testValue.HasMember("width")) {
|
||||
assert(testValue["width"].IsNumber());
|
||||
metadata.size.width = testValue["width"].GetInt();
|
||||
if (metadata.mapMode == mbgl::MapMode::Tile) {
|
||||
mbgl::Log::Warning(mbgl::Event::ParseStyle, "The 'width' metadata field is ignored in tile map mode");
|
||||
} else {
|
||||
metadata.size.width = testValue["width"].GetInt();
|
||||
}
|
||||
}
|
||||
|
||||
if (testValue.HasMember("height")) {
|
||||
assert(testValue["height"].IsNumber());
|
||||
metadata.size.height = testValue["height"].GetInt();
|
||||
if (metadata.mapMode == mbgl::MapMode::Tile) {
|
||||
mbgl::Log::Warning(mbgl::Event::ParseStyle, "The 'height' metadata field is ignored in tile map mode");
|
||||
} else {
|
||||
metadata.size.height = testValue["height"].GetInt();
|
||||
}
|
||||
}
|
||||
|
||||
if (testValue.HasMember("pixelRatio")) {
|
||||
@@ -492,25 +520,6 @@ TestMetadata parseTestMetadata(const TestPaths& paths) {
|
||||
std::string{testValue["description"].GetString(), testValue["description"].GetStringLength()};
|
||||
}
|
||||
|
||||
if (testValue.HasMember("mapMode")) {
|
||||
metadata.outputsImage = true;
|
||||
assert(testValue["mapMode"].IsString());
|
||||
std::string mapModeStr = testValue["mapMode"].GetString();
|
||||
if (mapModeStr == "tile") {
|
||||
metadata.mapMode = mbgl::MapMode::Tile;
|
||||
metadata.size = {uint32_t(mbgl::util::tileSize), uint32_t(mbgl::util::tileSize)};
|
||||
} else if (mapModeStr == "continuous") {
|
||||
metadata.mapMode = mbgl::MapMode::Continuous;
|
||||
metadata.outputsImage = false;
|
||||
} else if (mapModeStr == "static")
|
||||
metadata.mapMode = mbgl::MapMode::Static;
|
||||
else {
|
||||
mbgl::Log::Warning(
|
||||
mbgl::Event::ParseStyle, "Unknown map mode: %s. Falling back to static mode", mapModeStr.c_str());
|
||||
metadata.mapMode = mbgl::MapMode::Static;
|
||||
}
|
||||
}
|
||||
|
||||
// Test operations handled in runner.cpp.
|
||||
|
||||
if (testValue.HasMember("debug")) {
|
||||
|
||||
@@ -658,15 +658,17 @@ LatLng getTileCenterCoordinates(const UnwrappedTileID& tileId) {
|
||||
return Projection::unproject(tileCenter, scale);
|
||||
}
|
||||
|
||||
constexpr auto kTileSizeUint = uint32_t(util::tileSize);
|
||||
uint32_t getTileScreenPixelSize(float pixelRatio) {
|
||||
return util::tileSize * pixelRatio;
|
||||
}
|
||||
|
||||
uint32_t getImageTileOffset(const std::set<uint32_t>& dims, uint32_t dim) {
|
||||
uint32_t getImageTileOffset(const std::set<uint32_t>& dims, uint32_t dim, float pixelRatio) {
|
||||
auto it = dims.find(dim);
|
||||
if (it == dims.end()) {
|
||||
assert(false);
|
||||
return 0;
|
||||
}
|
||||
return static_cast<uint32_t>(std::distance(dims.begin(), it)) * kTileSizeUint;
|
||||
return static_cast<uint32_t>(std::distance(dims.begin(), it)) * getTileScreenPixelSize(pixelRatio);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
@@ -757,9 +759,10 @@ void TestRunner::run(TestMetadata& metadata) {
|
||||
yDims.insert(tileId.canonical.y);
|
||||
assert(tileId.canonical.z == uint8_t(*camera.zoom));
|
||||
}
|
||||
auto tileScreenSize = getTileScreenPixelSize(metadata.pixelRatio);
|
||||
|
||||
result.image =
|
||||
PremultipliedImage({uint32_t(xDims.size()) * kTileSizeUint, uint32_t(yDims.size()) * kTileSizeUint});
|
||||
PremultipliedImage({uint32_t(xDims.size()) * tileScreenSize, uint32_t(yDims.size()) * tileScreenSize});
|
||||
for (const auto& tileId : tileIds) {
|
||||
resetContext(metadata, ctx);
|
||||
auto cameraForTile{camera};
|
||||
@@ -772,8 +775,8 @@ void TestRunner::run(TestMetadata& metadata) {
|
||||
return;
|
||||
}
|
||||
|
||||
auto xOffset = getImageTileOffset(xDims, tileId.canonical.x);
|
||||
auto yOffset = getImageTileOffset(yDims, tileId.canonical.y);
|
||||
auto xOffset = getImageTileOffset(xDims, tileId.canonical.x, metadata.pixelRatio);
|
||||
auto yOffset = getImageTileOffset(yDims, tileId.canonical.y, metadata.pixelRatio);
|
||||
PremultipliedImage::copy(
|
||||
resultForTile.image, result.image, {0, 0}, {xOffset, yOffset}, resultForTile.image.size);
|
||||
result.stats += resultForTile.stats;
|
||||
|
||||
Reference in New Issue
Block a user