Move still image callback to MapContext

This commit is contained in:
John Firebaugh
2015-04-23 15:18:47 -07:00
parent f0b229730f
commit f8db45f19a
5 changed files with 26 additions and 29 deletions

View File

@@ -26,6 +26,7 @@
#include <mbgl/util/worker.hpp>
#include <mbgl/util/texture_pool.hpp>
#include <mbgl/util/mapbox.hpp>
#include <mbgl/util/exception.hpp>
namespace mbgl {
@@ -226,6 +227,19 @@ void MapContext::update() {
}
}
void MapContext::renderStill(StillImageCallback fn) {
if (data.mode != MapMode::Still) {
throw util::Exception("Map is not in still image render mode");
}
if (callback) {
throw util::Exception("Map is currently rendering an image");
}
callback = fn;
triggerUpdate(Update::RenderStill);
}
void MapContext::render() {
assert(Environment::currentlyOn(ThreadType::Map));
@@ -237,16 +251,9 @@ void MapContext::render() {
painter->render(*style, transformState, data.getAnimationTime());
if (data.mode == MapMode::Still && data.callback && style->isLoaded() && getSprite()->isLoaded()) {
auto image = view.readStillImage();
// We are moving the callback out of the way and empty it in case the callback function
// starts the next map image render.
MapData::StillImageCallback cb;
std::swap(cb, data.callback);
// Now we can finally invoke the callback function with the map image we rendered.
cb(std::move(image));
if (data.mode == MapMode::Still && callback && style->isLoaded() && getSprite()->isLoaded()) {
callback(view.readStillImage());
callback = nullptr;
}
// Schedule another rerender when we definitely need a next frame.