From 5fa144647d83316a20e861c08fd5b6179312ad08 Mon Sep 17 00:00:00 2001 From: Bruno de Oliveira Abinader Date: Tue, 20 Oct 2015 10:47:24 -0700 Subject: [PATCH] [core] Added GLContextMode to MapData Adding new mbgl::GLContextMode enum to mbgl::Map ctor, which gets stored in MapData. In shared GL context environments, we cannot assume that the GL state that has been left since the last draw is the same, so we reset the GL configurations to their default values. --- include/mbgl/map/map.hpp | 3 ++- include/mbgl/map/mode.hpp | 9 +++++++-- src/mbgl/map/map.cpp | 4 ++-- src/mbgl/map/map_data.hpp | 4 +++- test/miscellaneous/map_context.cpp | 2 +- test/miscellaneous/style_parser.cpp | 3 ++- test/style/resource_loading.cpp | 2 +- 7 files changed, 18 insertions(+), 9 deletions(-) diff --git a/include/mbgl/map/map.hpp b/include/mbgl/map/map.hpp index 9661bcc7b..65f988b5b 100644 --- a/include/mbgl/map/map.hpp +++ b/include/mbgl/map/map.hpp @@ -44,7 +44,8 @@ class Map : private util::noncopyable { public: explicit Map(View&, FileSource&, - MapMode mode = MapMode::Continuous); + MapMode mapMode = MapMode::Continuous, + GLContextMode contextMode = GLContextMode::Unique); ~Map(); // Pauses the render thread. The render thread will stop running but will not be terminated and will not lose state until resumed. diff --git a/include/mbgl/map/mode.hpp b/include/mbgl/map/mode.hpp index 4ade870d9..3e838dca9 100644 --- a/include/mbgl/map/mode.hpp +++ b/include/mbgl/map/mode.hpp @@ -10,6 +10,11 @@ enum class MapMode : uint8_t { Still, // a once-off still image }; -} +enum class GLContextMode : uint8_t { + Unique, + Shared, +}; -#endif \ No newline at end of file +} // namespace mbgl + +#endif // MBGL_MAP_MODE diff --git a/src/mbgl/map/map.cpp b/src/mbgl/map/map.cpp index 3e0feb266..729726837 100644 --- a/src/mbgl/map/map.cpp +++ b/src/mbgl/map/map.cpp @@ -14,10 +14,10 @@ namespace mbgl { -Map::Map(View& view_, FileSource& fileSource, MapMode mode) +Map::Map(View& view_, FileSource& fileSource, MapMode mapMode, GLContextMode contextMode) : view(view_), transform(std::make_unique(view)), - data(std::make_unique(mode, view.getPixelRatio())), + data(std::make_unique(mapMode, contextMode, view.getPixelRatio())), context(std::make_unique>(util::ThreadContext{"Map", util::ThreadType::Map, util::ThreadPriority::Regular}, view, fileSource, *data)) { view.initialize(this); diff --git a/src/mbgl/map/map_data.hpp b/src/mbgl/map/map_data.hpp index 0a3718d87..c1898fc37 100644 --- a/src/mbgl/map/map_data.hpp +++ b/src/mbgl/map/map_data.hpp @@ -20,8 +20,9 @@ class MapData { using Lock = std::lock_guard; public: - inline MapData(MapMode mode_, const float pixelRatio_) + inline MapData(MapMode mode_, GLContextMode contextMode_, const float pixelRatio_) : mode(mode_) + , contextMode(contextMode_) , pixelRatio(pixelRatio_) , animationTime(Duration::zero()) , defaultFadeDuration(mode_ == MapMode::Continuous ? std::chrono::milliseconds(300) : Duration::zero()) @@ -125,6 +126,7 @@ public: public: const MapMode mode; + const GLContextMode contextMode; const float pixelRatio; private: diff --git a/test/miscellaneous/map_context.cpp b/test/miscellaneous/map_context.cpp index ec88862f0..fac21ee95 100644 --- a/test/miscellaneous/map_context.cpp +++ b/test/miscellaneous/map_context.cpp @@ -13,7 +13,7 @@ TEST(MapContext, DoubleStyleLoad) { std::shared_ptr display = std::make_shared(); HeadlessView view(display, 1, 512, 512); DefaultFileSource fileSource(nullptr); - MapData data(MapMode::Continuous, view.getPixelRatio()); + MapData data(MapMode::Continuous, GLContextMode::Unique, view.getPixelRatio()); util::Thread context({"Map", util::ThreadType::Map, util::ThreadPriority::Regular}, view, fileSource, data); diff --git a/test/miscellaneous/style_parser.cpp b/test/miscellaneous/style_parser.cpp index e88d79841..cbb896bac 100644 --- a/test/miscellaneous/style_parser.cpp +++ b/test/miscellaneous/style_parser.cpp @@ -39,9 +39,10 @@ TEST_P(StyleParserTest, ParseStyle) { Log::setObserver(std::unique_ptr(observer)); MapMode mapMode = MapMode::Continuous; + GLContextMode contextMode = GLContextMode::Unique; const float pixelRatio = 1.0f; - MapData data(mapMode, pixelRatio); + MapData data(mapMode, contextMode, pixelRatio); StyleParser parser(data); parser.parse(styleDoc); diff --git a/test/style/resource_loading.cpp b/test/style/resource_loading.cpp index d4cb92919..e0c4590c7 100644 --- a/test/style/resource_loading.cpp +++ b/test/style/resource_loading.cpp @@ -23,7 +23,7 @@ public: MockMapContext(View& view, FileSource& fileSource, const std::function& callback) - : data_(MapMode::Still, view.getPixelRatio()), + : data_(MapMode::Still, GLContextMode::Unique, view.getPixelRatio()), transform_(view), callback_(callback) { util::ThreadContext::setFileSource(&fileSource);