Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Commit

Permalink
[core] Move MapData storage to MapContext
Browse files Browse the repository at this point in the history
This allows MapData members to hold GL resources which must be released
on the MapContext thread -- necessary for the following commit.
  • Loading branch information
jfirebaugh committed Dec 1, 2015
1 parent 40ebf5d commit 5888684
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 8 deletions.
2 changes: 1 addition & 1 deletion include/mbgl/map/map.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,8 @@ class Map : private util::noncopyable {
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,
Expand Down
6 changes: 4 additions & 2 deletions src/mbgl/map/map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
6 changes: 4 additions & 2 deletions src/mbgl/map/map_context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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>()) {
Expand Down Expand Up @@ -57,6 +58,7 @@ void MapContext::cleanup() {
style.reset();
painter.reset();
texturePool.reset();
dataPtr.reset();

glObjectStore.performCleanup();

Expand Down
6 changes: 5 additions & 1 deletion src/mbgl/map/map_context.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand All @@ -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);
Expand Down Expand Up @@ -69,6 +72,7 @@ class MapContext : public Style::Observer {
void loadStyleJSON(const std::string& json, const std::string& base);

View& view;
std::unique_ptr<MapData> dataPtr;
MapData& data;

util::GLObjectStore glObjectStore;
Expand Down
4 changes: 2 additions & 2 deletions test/miscellaneous/map_context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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, "", "");
Expand Down

0 comments on commit 5888684

Please sign in to comment.