[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.
This commit is contained in:
@@ -178,8 +178,8 @@ public:
|
||||
private:
|
||||
View& view;
|
||||
const std::unique_ptr<Transform> transform;
|
||||
const std::unique_ptr<MapData> data;
|
||||
const std::unique_ptr<util::Thread<MapContext>> context;
|
||||
MapData* data;
|
||||
|
||||
enum class RenderState {
|
||||
never,
|
||||
|
||||
@@ -17,8 +17,10 @@ namespace mbgl {
|
||||
Map::Map(View& view_, FileSource& fileSource, MapMode mapMode, GLContextMode contextMode, ConstrainMode constrainMode)
|
||||
: view(view_),
|
||||
transform(std::make_unique<Transform>(view, constrainMode)),
|
||||
data(std::make_unique<MapData>(mapMode, contextMode, view.getPixelRatio())),
|
||||
context(std::make_unique<util::Thread<MapContext>>(util::ThreadContext{"Map", util::ThreadType::Map, util::ThreadPriority::Regular}, view, fileSource, *data))
|
||||
context(std::make_unique<util::Thread<MapContext>>(
|
||||
util::ThreadContext{"Map", util::ThreadType::Map, util::ThreadPriority::Regular},
|
||||
view, fileSource, mapMode, contextMode, view.getPixelRatio())),
|
||||
data(&context->invokeSync<MapData&>(&MapContext::getData))
|
||||
{
|
||||
view.initialize(this);
|
||||
update(Update::Dimensions);
|
||||
|
||||
@@ -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<MapData>(mode_, contextMode_, pixelRatio_)),
|
||||
data(*dataPtr),
|
||||
asyncUpdate([this] { update(); }),
|
||||
asyncInvalidate([&view_] { view_.invalidate(); }),
|
||||
texturePool(std::make_unique<TexturePool>()) {
|
||||
@@ -57,6 +58,7 @@ void MapContext::cleanup() {
|
||||
style.reset();
|
||||
painter.reset();
|
||||
texturePool.reset();
|
||||
dataPtr.reset();
|
||||
|
||||
glObjectStore.performCleanup();
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
#include <mbgl/map/update.hpp>
|
||||
#include <mbgl/map/transform_state.hpp>
|
||||
#include <mbgl/map/map.hpp>
|
||||
#include <mbgl/map/map_data.hpp>
|
||||
#include <mbgl/style/style.hpp>
|
||||
#include <mbgl/util/async_task.hpp>
|
||||
#include <mbgl/util/gl_object_store.hpp>
|
||||
@@ -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<MapData> dataPtr;
|
||||
MapData& data;
|
||||
|
||||
util::GLObjectStore glObjectStore;
|
||||
|
||||
@@ -13,9 +13,9 @@ TEST(MapContext, DoubleStyleLoad) {
|
||||
std::shared_ptr<HeadlessDisplay> display = std::make_shared<HeadlessDisplay>();
|
||||
HeadlessView view(display, 1, 512, 512);
|
||||
DefaultFileSource fileSource(nullptr);
|
||||
MapData data(MapMode::Continuous, GLContextMode::Unique, view.getPixelRatio());
|
||||
|
||||
util::Thread<MapContext> context({"Map", util::ThreadType::Map, util::ThreadPriority::Regular}, view, fileSource, data);
|
||||
util::Thread<MapContext> context({"Map", util::ThreadType::Map, util::ThreadPriority::Regular},
|
||||
view, fileSource, MapMode::Continuous, GLContextMode::Unique, view.getPixelRatio());
|
||||
|
||||
context.invokeSync(&MapContext::setStyleJSON, "", "");
|
||||
context.invokeSync(&MapContext::setStyleJSON, "", "");
|
||||
|
||||
Reference in New Issue
Block a user