[core] Use AsyncTask on the MapContext

This commit is contained in:
Thiago Marcos P. Santos
2015-11-09 17:10:02 +02:00
parent 6762cd0ca9
commit 1d62332204
3 changed files with 17 additions and 21 deletions

View File

@@ -16,7 +16,6 @@
#include <mbgl/sprite/sprite_store.hpp>
#include <mbgl/util/gl_object_store.hpp>
#include <mbgl/util/uv_detail.hpp>
#include <mbgl/util/worker.hpp>
#include <mbgl/util/texture_pool.hpp>
#include <mbgl/util/exception.hpp>
@@ -29,16 +28,16 @@ namespace mbgl {
MapContext::MapContext(View& view_, FileSource& fileSource, MapData& data_)
: view(view_),
data(data_),
asyncUpdate(std::make_unique<uv::async>(util::RunLoop::getLoop(), [this] { update(); })),
asyncInvalidate(std::make_unique<uv::async>(util::RunLoop::getLoop(), [&view_] { view_.invalidate(); })),
asyncUpdate([this] { update(); }),
asyncInvalidate([&view_] { view_.invalidate(); }),
texturePool(std::make_unique<TexturePool>()) {
assert(util::ThreadContext::currentlyOn(util::ThreadType::Map));
util::ThreadContext::setFileSource(&fileSource);
util::ThreadContext::setGLObjectStore(&glObjectStore);
asyncUpdate->unref();
asyncInvalidate->unref();
asyncUpdate.unref();
asyncInvalidate.unref();
view.activate();
}
@@ -76,14 +75,14 @@ void MapContext::pause() {
view.activate();
asyncInvalidate->send();
asyncInvalidate.send();
}
void MapContext::triggerUpdate(const TransformState& state, const Update flags) {
transformState = state;
updateFlags |= flags;
asyncUpdate->send();
asyncUpdate.send();
}
void MapContext::setStyleURL(const std::string& url) {
@@ -152,7 +151,7 @@ void MapContext::loadStyleJSON(const std::string& json, const std::string& base)
data.loading = true;
updateFlags |= Update::DefaultTransition | Update::Classes | Update::Zoom | Update::Annotations;
asyncUpdate->send();
asyncUpdate.send();
}
void MapContext::update() {
@@ -184,7 +183,7 @@ void MapContext::update() {
style->update(transformState, *texturePool);
if (data.mode == MapMode::Continuous) {
asyncInvalidate->send();
asyncInvalidate.send();
} else if (callback && style->isLoaded()) {
renderSync(transformState, frameData);
}
@@ -223,7 +222,7 @@ void MapContext::renderStill(const TransformState& state, const FrameData& frame
frameData = frame;
updateFlags |= Update::RenderStill;
asyncUpdate->send();
asyncUpdate.send();
}
bool MapContext::renderSync(const TransformState& state, const FrameData& frame) {
@@ -253,10 +252,10 @@ bool MapContext::renderSync(const TransformState& state, const FrameData& frame)
if (style->hasTransitions()) {
updateFlags |= Update::Classes;
asyncUpdate->send();
asyncUpdate.send();
} else if (painter->needsAnimation()) {
updateFlags |= Update::Repaint;
asyncUpdate->send();
asyncUpdate.send();
}
return isLoaded();
@@ -284,7 +283,7 @@ void MapContext::setSourceTileCacheSize(size_t size) {
for (const auto &source : style->sources) {
source->setCacheSize(sourceCacheSize);
}
asyncInvalidate->send();
asyncInvalidate.send();
}
}
@@ -294,7 +293,7 @@ void MapContext::onLowMemory() {
for (const auto &source : style->sources) {
source->onLowMemory();
}
asyncInvalidate->send();
asyncInvalidate.send();
}
void MapContext::setSprite(const std::string& name, std::shared_ptr<const SpriteImage> sprite) {
@@ -312,7 +311,7 @@ void MapContext::onTileDataChanged() {
assert(util::ThreadContext::currentlyOn(util::ThreadType::Map));
updateFlags |= Update::Repaint;
asyncUpdate->send();
asyncUpdate.send();
}
void MapContext::onResourceLoadingFailed(std::exception_ptr error) {

View File

@@ -6,15 +6,12 @@
#include <mbgl/map/transform_state.hpp>
#include <mbgl/map/map.hpp>
#include <mbgl/style/style.hpp>
#include <mbgl/util/async_task.hpp>
#include <mbgl/util/gl_object_store.hpp>
#include <mbgl/util/ptr.hpp>
#include <vector>
namespace uv {
class async;
}
namespace mbgl {
class View;
@@ -77,8 +74,8 @@ private:
util::GLObjectStore glObjectStore;
Update updateFlags = Update::Nothing;
std::unique_ptr<uv::async> asyncUpdate;
std::unique_ptr<uv::async> asyncInvalidate;
util::AsyncTask asyncUpdate;
util::AsyncTask asyncInvalidate;
std::unique_ptr<TexturePool> texturePool;
std::unique_ptr<Painter> painter;