Prepare for using Thread<MapContext>

This commit is contained in:
John Firebaugh
2015-04-20 18:51:47 -07:00
parent fc9b958bb8
commit 41a44280ca
3 changed files with 37 additions and 9 deletions

View File

@@ -374,7 +374,7 @@ const LatLng Map::latLngForPixel(const vec2<double> pixel) const {
void Map::setDefaultPointAnnotationSymbol(const std::string& symbol) {
assert(Environment::currentlyOn(ThreadType::Main));
context->invokeTask([=] {
data->annotationManager.setDefaultPointAnnotationSymbol(symbol);
context->setDefaultPointAnnotationSymbol(symbol);
});
}
@@ -392,9 +392,7 @@ uint32_t Map::addPointAnnotation(const LatLng& point, const std::string& symbol)
std::vector<uint32_t> Map::addPointAnnotations(const std::vector<LatLng>& points, const std::vector<std::string>& symbols) {
assert(Environment::currentlyOn(ThreadType::Main));
return context->invokeSyncTask([&] {
auto result = data->annotationManager.addPointAnnotations(points, symbols, *data);
context->updateAnnotationTiles(result.first);
return result.second;
return context->addPointAnnotations(points, symbols);
});
}
@@ -406,22 +404,21 @@ void Map::removeAnnotation(uint32_t annotation) {
void Map::removeAnnotations(const std::vector<uint32_t>& annotations) {
assert(Environment::currentlyOn(ThreadType::Main));
context->invokeTask([=] {
auto result = data->annotationManager.removeAnnotations(annotations, *data);
context->updateAnnotationTiles(result);
context->removeAnnotations(annotations);
});
}
std::vector<uint32_t> Map::getAnnotationsInBounds(const LatLngBounds& bounds) {
assert(Environment::currentlyOn(ThreadType::Main));
return context->invokeSyncTask([&] {
return data->annotationManager.getAnnotationsInBounds(bounds, *data);
return context->getAnnotationsInBounds(bounds);
});
}
LatLngBounds Map::getBoundsForAnnotations(const std::vector<uint32_t>& annotations) {
assert(Environment::currentlyOn(ThreadType::Main));
return context->invokeSyncTask([&] {
return data->annotationManager.getBoundsForAnnotations(annotations);
return context->getBoundsForAnnotations(annotations);
});
}

View File

@@ -415,6 +415,10 @@ void MapContext::processTasks() {
}
}
void MapContext::setDefaultPointAnnotationSymbol(const std::string& symbol) {
data.annotationManager.setDefaultPointAnnotationSymbol(symbol);
}
double MapContext::getTopOffsetPixelsForAnnotationSymbol(const std::string& symbol) {
assert(Environment::currentlyOn(ThreadType::Map));
assert(sprite);
@@ -422,6 +426,25 @@ double MapContext::getTopOffsetPixelsForAnnotationSymbol(const std::string& symb
return -pos.height / pos.pixelRatio / 2;
}
std::vector<uint32_t> MapContext::addPointAnnotations(const std::vector<LatLng>& points, const std::vector<std::string>& symbols) {
auto result = data.annotationManager.addPointAnnotations(points, symbols, data);
updateAnnotationTiles(result.first);
return result.second;
}
void MapContext::removeAnnotations(const std::vector<uint32_t>& annotations) {
auto result = data.annotationManager.removeAnnotations(annotations, data);
updateAnnotationTiles(result);
}
std::vector<uint32_t> MapContext::getAnnotationsInBounds(const LatLngBounds& bounds) {
return data.annotationManager.getAnnotationsInBounds(bounds, data);
}
LatLngBounds MapContext::getBoundsForAnnotations(const std::vector<uint32_t>& annotations) {
return data.annotationManager.getBoundsForAnnotations(annotations);
}
void MapContext::setSourceTileCacheSize(size_t size) {
assert(Environment::currentlyOn(ThreadType::Map));
if (size != sourceCacheSize) {

View File

@@ -28,6 +28,8 @@ class Painter;
class Sprite;
class Style;
class Worker;
struct LatLng;
struct LatLngBounds;
class MapContext {
public:
@@ -57,8 +59,13 @@ public:
return promise.get_future().get();
}
void updateAnnotationTiles(const std::vector<TileID>& ids);
void setDefaultPointAnnotationSymbol(const std::string& symbol);
double getTopOffsetPixelsForAnnotationSymbol(const std::string& symbol);
std::vector<uint32_t> addPointAnnotations(const std::vector<LatLng>& points, const std::vector<std::string>& symbols);
void removeAnnotations(const std::vector<uint32_t>& annotations);
std::vector<uint32_t> getAnnotationsInBounds(const LatLngBounds&);
LatLngBounds getBoundsForAnnotations(const std::vector<uint32_t>&);
void setSourceTileCacheSize(size_t size);
void onLowMemory();
@@ -66,6 +73,7 @@ public:
private:
// Checks if render thread needs to pause
void checkForPause();
void updateAnnotationTiles(const std::vector<TileID>& ids);
Worker& getWorker();
util::ptr<Sprite> getSprite();