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

Commit

Permalink
[core] Remove remnants of MapContext thread
Browse files Browse the repository at this point in the history
  • Loading branch information
jfirebaugh committed Nov 17, 2015
1 parent 7cc607e commit 8e7c599
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 75 deletions.
13 changes: 3 additions & 10 deletions include/mbgl/map/map.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,22 +44,15 @@ class Map : private util::noncopyable {
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.
void pause();
bool isPaused();

// Resumes a paused render thread
void resume();

// Register a callback that will get called (on the render thread) when all resources have
// been loaded and a complete render occurs.
using StillImageCallback = std::function<void(std::exception_ptr, std::unique_ptr<const StillImage>)>;
void renderStill(StillImageCallback callback);

// Triggers a synchronous render.
void renderSync();
// Main render function.
void render();

// Notifies the Map thread that the state has changed and an update might be necessary.
// Notifies the Map that the state has changed and an update might be necessary.
void update(Update update);

// Styling
Expand Down
2 changes: 1 addition & 1 deletion platform/default/glfw_view.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ void GLFWView::run() {
const bool dirty = !clean.test_and_set();
if (dirty) {
const double started = glfwGetTime();
map->renderSync();
map->render();
report(1000 * (glfwGetTime() - started));
if (benchmark) {
map->update(mbgl::Update::Repaint);
Expand Down
23 changes: 1 addition & 22 deletions src/mbgl/map/map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,36 +24,15 @@ Map::Map(View& view_, FileSource& fileSource, MapMode mapMode, GLContextMode con
}

Map::~Map() {
resume();
context->cleanup();
}

void Map::pause() {
assert(data->mode == MapMode::Continuous);

std::unique_lock<std::mutex> lockPause(data->mutexPause);
if (!data->paused) {
context->pause();
data->condPause.wait(lockPause, [&]{ return data->paused; });
}
}

bool Map::isPaused() {
return data->paused;
}

void Map::resume() {
std::unique_lock<std::mutex> lockPause(data->mutexPause);
data->paused = false;
data->condPause.notify_all();
}

void Map::renderStill(StillImageCallback callback) {
context->renderStill(transform->getState(),
FrameData{ view.getFramebufferSize() }, callback);
}

void Map::renderSync() {
void Map::render() {
if (renderState == RenderState::never) {
view.notifyMapChange(MapChangeWillStartRenderingMap);
}
Expand Down
14 changes: 0 additions & 14 deletions src/mbgl/map/map_context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,20 +62,6 @@ void MapContext::cleanup() {
view.deactivate();
}

void MapContext::pause() {
MBGL_CHECK_ERROR(glFinish());

view.deactivate();

std::unique_lock<std::mutex> lockPause(data.mutexPause);
data.paused = true;
data.condPause.notify_all();
data.condPause.wait(lockPause, [&]{ return !data.paused; });

view.activate();
view.invalidate();
}

void MapContext::triggerUpdate(const TransformState& state, const Update flags) {
transformState = state;
updateFlags |= flags;
Expand Down
2 changes: 0 additions & 2 deletions src/mbgl/map/map_context.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@ class MapContext : public Style::Observer {
MapContext(View&, FileSource&, MapData&);
~MapContext();

void pause();

void triggerUpdate(const TransformState&, Update = Update::Nothing);
void renderStill(const TransformState&, const FrameData&, Map::StillImageCallback callback);

Expand Down
5 changes: 0 additions & 5 deletions src/mbgl/map/map_data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ namespace mbgl {
// Adds the class if it's not yet set. Returns true when it added the class, and false when it
// was already present.
bool MapData::addClass(const std::string& klass) {
Lock lock(mtx);
if (std::find(classes.begin(), classes.end(), klass) != classes.end()) return false;
classes.push_back(klass);
return true;
Expand All @@ -16,7 +15,6 @@ bool MapData::addClass(const std::string& klass) {
// Removes the class if it's present. Returns true when it remvoed the class, and false when it
// was not present.
bool MapData::removeClass(const std::string& klass) {
Lock lock(mtx);
const auto it = std::find(classes.begin(), classes.end(), klass);
if (it != classes.end()) {
classes.erase(it);
Expand All @@ -27,17 +25,14 @@ bool MapData::removeClass(const std::string& klass) {

// Returns true when class is present in the list of currently set classes.
bool MapData::hasClass(const std::string& klass) const {
Lock lock(mtx);
return std::find(classes.begin(), classes.end(), klass) != classes.end();
}

void MapData::setClasses(const std::vector<std::string>& klasses) {
Lock lock(mtx);
classes = klasses;
}

std::vector<std::string> MapData::getClasses() const {
Lock lock(mtx);
return classes;
}

Expand Down
29 changes: 8 additions & 21 deletions src/mbgl/map/map_data.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,8 @@
#include <mbgl/util/chrono.hpp>

#include <string>
#include <mutex>
#include <atomic>
#include <vector>
#include <cassert>
#include <condition_variable>

#include <mbgl/map/mode.hpp>
#include <mbgl/annotation/annotation_manager.hpp>
Expand All @@ -17,8 +14,6 @@
namespace mbgl {

class MapData {
using Lock = std::lock_guard<std::mutex>;

public:
inline MapData(MapMode mode_, GLContextMode contextMode_, const float pixelRatio_)
: mode(mode_)
Expand Down Expand Up @@ -118,10 +113,8 @@ class MapData {
defaultTransitionDelay = delay;
}

util::exclusive<AnnotationManager> getAnnotationManager() {
return util::exclusive<AnnotationManager>(
&annotationManager,
std::make_unique<std::lock_guard<std::mutex>>(annotationManagerMutex));
AnnotationManager* getAnnotationManager() {
return &annotationManager;
}

public:
Expand All @@ -130,24 +123,18 @@ class MapData {
const float pixelRatio;

private:
mutable std::mutex annotationManagerMutex;
AnnotationManager annotationManager;

mutable std::mutex mtx;

std::vector<std::string> classes;
std::atomic<uint8_t> debug { false };
std::atomic<uint8_t> collisionDebug { false };
std::atomic<Duration> animationTime;
std::atomic<Duration> defaultFadeDuration;
std::atomic<Duration> defaultTransitionDuration;
std::atomic<Duration> defaultTransitionDelay;
uint8_t debug { false };
uint8_t collisionDebug { false };
Duration animationTime;
Duration defaultFadeDuration;
Duration defaultTransitionDuration;
Duration defaultTransitionDelay;

// TODO: make private
public:
bool paused = false;
std::mutex mutexPause;
std::condition_variable condPause;
bool loading = false;
};

Expand Down

0 comments on commit 8e7c599

Please sign in to comment.