From 12fc9490065e1ddc2fada269a045cd2725a257f5 Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Thu, 19 Nov 2015 16:07:15 -0800 Subject: [tests] Don't use icons from the style for annotations --- include/mbgl/platform/default/glfw_view.hpp | 2 ++ platform/default/glfw_view.cpp | 9 ++++++- test/api/annotations.cpp | 30 +++++++++------------ .../fixtures/annotations/add_multiple/expected.png | Bin 4589 -> 2771 bytes .../annotations/fill_annotation/expected.png | Bin 1543 -> 1538 bytes .../annotations/line_annotation/expected.png | Bin 2412 -> 2088 bytes .../annotations/non_immediate_add/expected.png | Bin 1543 -> 1538 bytes .../annotations/point_annotation/expected.png | Bin 4273 -> 2594 bytes .../fixtures/annotations/switch_style/expected.png | Bin 4273 -> 2594 bytes test/fixtures/api/empty.json | 3 +-- test/fixtures/sprites/default_marker.png | Bin 0 -> 1010 bytes 11 files changed, 24 insertions(+), 20 deletions(-) create mode 100644 test/fixtures/sprites/default_marker.png diff --git a/include/mbgl/platform/default/glfw_view.hpp b/include/mbgl/platform/default/glfw_view.hpp index a434b71bb1..2318cb6ccd 100644 --- a/include/mbgl/platform/default/glfw_view.hpp +++ b/include/mbgl/platform/default/glfw_view.hpp @@ -20,6 +20,7 @@ public: std::array getFramebufferSize() const override; void initialize(mbgl::Map *map) override; + void notifyMapChange(mbgl::MapChange) override; void activate() override; void deactivate() override; void notify() override; @@ -61,6 +62,7 @@ private: std::vector spriteIDs; private: + bool initializedDefaultMarker = false; bool fullscreen = false; const bool benchmark = false; bool tracking = false; diff --git a/platform/default/glfw_view.cpp b/platform/default/glfw_view.cpp index 4e00722e21..48e9386fc7 100644 --- a/platform/default/glfw_view.cpp +++ b/platform/default/glfw_view.cpp @@ -117,6 +117,13 @@ void GLFWView::initialize(mbgl::Map *map_) { View::initialize(map_); } +void GLFWView::notifyMapChange(mbgl::MapChange change) { + if (change == mbgl::MapChange::MapChangeDidFinishLoadingMap && !initializedDefaultMarker) { + initializedDefaultMarker = true; + map->setSprite("default_marker", makeSpriteImage(22, 22, 1)); + } +} + void GLFWView::onKey(GLFWwindow *window, int key, int /*scancode*/, int action, int mods) { GLFWView *view = reinterpret_cast(glfwGetWindowUserPointer(window)); @@ -234,7 +241,7 @@ void GLFWView::addRandomPointAnnotations(int count) { std::vector points; for (int i = 0; i < count; i++) { - points.emplace_back(makeRandomPoint(), "marker-15"); + points.emplace_back(makeRandomPoint(), "default_marker"); } auto newIDs = map->addPointAnnotations(points); diff --git a/test/api/annotations.cpp b/test/api/annotations.cpp index ae9c804730..4c06b39e43 100644 --- a/test/api/annotations.cpp +++ b/test/api/annotations.cpp @@ -14,6 +14,11 @@ using namespace mbgl; +std::shared_ptr defaultMarker() { + PremultipliedImage image = decodeImage(util::read_file("test/fixtures/sprites/default_marker.png")); + return std::make_shared(image.width, image.height, 1.0, std::string(reinterpret_cast(image.data.get()), image.size())); +} + PremultipliedImage render(Map& map) { std::promise promise; map.renderStill([&](std::exception_ptr, PremultipliedImage&& image) { @@ -35,7 +40,8 @@ TEST(Annotations, PointAnnotation) { Map map(view, fileSource, MapMode::Still); map.setStyleJSON(util::read_file("test/fixtures/api/empty.json"), ""); - map.addPointAnnotation(PointAnnotation({ 0, -20 }, "default_marker")); + map.setSprite("default_marker", defaultMarker()); + map.addPointAnnotation(PointAnnotation({ 0, 0 }, "default_marker")); checkRendering(map, "point_annotation"); } @@ -99,11 +105,12 @@ TEST(Annotations, AddMultiple) { Map map(view, fileSource, MapMode::Still); map.setStyleJSON(util::read_file("test/fixtures/api/empty.json"), ""); - map.addPointAnnotation(PointAnnotation({ 0, -20 }, "default_marker")); + map.setSprite("default_marker", defaultMarker()); + map.addPointAnnotation(PointAnnotation({ 0, -10 }, "default_marker")); render(map); - map.addPointAnnotation(PointAnnotation({ 0, 20 }, "default_marker")); + map.addPointAnnotation(PointAnnotation({ 0, 10 }, "default_marker")); checkRendering(map, "add_multiple"); } @@ -135,6 +142,7 @@ TEST(Annotations, RemovePoint) { Map map(view, fileSource, MapMode::Still); map.setStyleJSON(util::read_file("test/fixtures/api/empty.json"), ""); + map.setSprite("default_marker", defaultMarker()); uint32_t point = map.addPointAnnotation(PointAnnotation({ 0, 0 }, "default_marker")); render(map); @@ -185,7 +193,8 @@ TEST(Annotations, SwitchStyle) { Map map(view, fileSource, MapMode::Still); map.setStyleJSON(util::read_file("test/fixtures/api/empty.json"), ""); - map.addPointAnnotation(PointAnnotation({ 0, -20 }, "default_marker")); + map.setSprite("default_marker", defaultMarker()); + map.addPointAnnotation(PointAnnotation({ 0, 0 }, "default_marker")); render(map); @@ -193,16 +202,3 @@ TEST(Annotations, SwitchStyle) { checkRendering(map, "switch_style"); } - -TEST(Annotations, CustomIcon) { - auto display = std::make_shared(); - HeadlessView view(display, 1); - DefaultFileSource fileSource(nullptr); - - Map map(view, fileSource, MapMode::Still); - map.setStyleJSON(util::read_file("test/fixtures/api/empty.json"), ""); - map.setSprite("cafe", std::make_shared(12, 12, 1, std::string(12 * 12 * 4, '\xFF'))); - map.addPointAnnotation(PointAnnotation({ 0, 0 }, "cafe")); - - checkRendering(map, "custom_icon"); -} diff --git a/test/fixtures/annotations/add_multiple/expected.png b/test/fixtures/annotations/add_multiple/expected.png index deedf84330..f77ddb0792 100644 Binary files a/test/fixtures/annotations/add_multiple/expected.png and b/test/fixtures/annotations/add_multiple/expected.png differ diff --git a/test/fixtures/annotations/fill_annotation/expected.png b/test/fixtures/annotations/fill_annotation/expected.png index 30f6f1eb59..09f48081a8 100644 Binary files a/test/fixtures/annotations/fill_annotation/expected.png and b/test/fixtures/annotations/fill_annotation/expected.png differ diff --git a/test/fixtures/annotations/line_annotation/expected.png b/test/fixtures/annotations/line_annotation/expected.png index 067027f1d1..b86570f990 100644 Binary files a/test/fixtures/annotations/line_annotation/expected.png and b/test/fixtures/annotations/line_annotation/expected.png differ diff --git a/test/fixtures/annotations/non_immediate_add/expected.png b/test/fixtures/annotations/non_immediate_add/expected.png index 30f6f1eb59..09f48081a8 100644 Binary files a/test/fixtures/annotations/non_immediate_add/expected.png and b/test/fixtures/annotations/non_immediate_add/expected.png differ diff --git a/test/fixtures/annotations/point_annotation/expected.png b/test/fixtures/annotations/point_annotation/expected.png index 33299a2d6a..21d38b2073 100644 Binary files a/test/fixtures/annotations/point_annotation/expected.png and b/test/fixtures/annotations/point_annotation/expected.png differ diff --git a/test/fixtures/annotations/switch_style/expected.png b/test/fixtures/annotations/switch_style/expected.png index 33299a2d6a..21d38b2073 100644 Binary files a/test/fixtures/annotations/switch_style/expected.png and b/test/fixtures/annotations/switch_style/expected.png differ diff --git a/test/fixtures/api/empty.json b/test/fixtures/api/empty.json index acc8a630ca..61a8fadcdb 100644 --- a/test/fixtures/api/empty.json +++ b/test/fixtures/api/empty.json @@ -1,6 +1,5 @@ { "version": 8, "sources": {}, - "layers": [], - "sprite": "asset://TEST_DATA/fixtures/resources/sprite" + "layers": [] } diff --git a/test/fixtures/sprites/default_marker.png b/test/fixtures/sprites/default_marker.png new file mode 100644 index 0000000000..b112096c18 Binary files /dev/null and b/test/fixtures/sprites/default_marker.png differ -- cgit v1.2.1