From 58886842bc381cd30bac7102d4f70497c0128aa7 Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Thu, 19 Nov 2015 16:08:18 -0800 Subject: [core] Move MapData storage to MapContext This allows MapData members to hold GL resources which must be released on the MapContext thread -- necessary for the following commit. --- include/mbgl/map/map.hpp | 2 +- src/mbgl/map/map.cpp | 6 ++++-- src/mbgl/map/map_context.cpp | 6 ++++-- src/mbgl/map/map_context.hpp | 6 +++++- test/miscellaneous/map_context.cpp | 4 ++-- 5 files changed, 16 insertions(+), 8 deletions(-) diff --git a/include/mbgl/map/map.hpp b/include/mbgl/map/map.hpp index 8401976e15..bce99ebe4d 100644 --- a/include/mbgl/map/map.hpp +++ b/include/mbgl/map/map.hpp @@ -178,8 +178,8 @@ public: private: View& view; const std::unique_ptr transform; - const std::unique_ptr data; const std::unique_ptr> context; + MapData* data; enum class RenderState { never, diff --git a/src/mbgl/map/map.cpp b/src/mbgl/map/map.cpp index 57f8c3e7f3..08265ae1e8 100644 --- a/src/mbgl/map/map.cpp +++ b/src/mbgl/map/map.cpp @@ -17,8 +17,10 @@ namespace mbgl { Map::Map(View& view_, FileSource& fileSource, MapMode mapMode, GLContextMode contextMode, ConstrainMode constrainMode) : view(view_), transform(std::make_unique(view, constrainMode)), - data(std::make_unique(mapMode, contextMode, view.getPixelRatio())), - context(std::make_unique>(util::ThreadContext{"Map", util::ThreadType::Map, util::ThreadPriority::Regular}, view, fileSource, *data)) + context(std::make_unique>( + util::ThreadContext{"Map", util::ThreadType::Map, util::ThreadPriority::Regular}, + view, fileSource, mapMode, contextMode, view.getPixelRatio())), + data(&context->invokeSync(&MapContext::getData)) { view.initialize(this); update(Update::Dimensions); diff --git a/src/mbgl/map/map_context.cpp b/src/mbgl/map/map_context.cpp index 400b2880da..32cf760afa 100644 --- a/src/mbgl/map/map_context.cpp +++ b/src/mbgl/map/map_context.cpp @@ -25,9 +25,10 @@ namespace mbgl { -MapContext::MapContext(View& view_, FileSource& fileSource, MapData& data_) +MapContext::MapContext(View& view_, FileSource& fileSource, MapMode mode_, GLContextMode contextMode_, const float pixelRatio_) : view(view_), - data(data_), + dataPtr(std::make_unique(mode_, contextMode_, pixelRatio_)), + data(*dataPtr), asyncUpdate([this] { update(); }), asyncInvalidate([&view_] { view_.invalidate(); }), texturePool(std::make_unique()) { @@ -57,6 +58,7 @@ void MapContext::cleanup() { style.reset(); painter.reset(); texturePool.reset(); + dataPtr.reset(); glObjectStore.performCleanup(); diff --git a/src/mbgl/map/map_context.hpp b/src/mbgl/map/map_context.hpp index c0ee68a614..06be31ed85 100644 --- a/src/mbgl/map/map_context.hpp +++ b/src/mbgl/map/map_context.hpp @@ -5,6 +5,7 @@ #include #include #include +#include #include #include #include @@ -27,9 +28,11 @@ struct FrameData { class MapContext : public Style::Observer { public: - MapContext(View&, FileSource&, MapData&); + MapContext(View&, FileSource&, MapMode, GLContextMode, const float pixelRatio); ~MapContext(); + MapData& getData() { return data; } + void pause(); void triggerUpdate(const TransformState&, Update = Update::Nothing); @@ -69,6 +72,7 @@ private: void loadStyleJSON(const std::string& json, const std::string& base); View& view; + std::unique_ptr dataPtr; MapData& data; util::GLObjectStore glObjectStore; diff --git a/test/miscellaneous/map_context.cpp b/test/miscellaneous/map_context.cpp index fac21ee959..9645572358 100644 --- a/test/miscellaneous/map_context.cpp +++ b/test/miscellaneous/map_context.cpp @@ -13,9 +13,9 @@ TEST(MapContext, DoubleStyleLoad) { std::shared_ptr display = std::make_shared(); HeadlessView view(display, 1, 512, 512); DefaultFileSource fileSource(nullptr); - MapData data(MapMode::Continuous, GLContextMode::Unique, view.getPixelRatio()); - util::Thread context({"Map", util::ThreadType::Map, util::ThreadPriority::Regular}, view, fileSource, data); + util::Thread context({"Map", util::ThreadType::Map, util::ThreadPriority::Regular}, + view, fileSource, MapMode::Continuous, GLContextMode::Unique, view.getPixelRatio()); context.invokeSync(&MapContext::setStyleJSON, "", ""); context.invokeSync(&MapContext::setStyleJSON, "", ""); -- cgit v1.2.1