[core] Use weak annotation manager

Map and renderer / orchestrator should be able to run on a separate threads,
however, legacy AnnotationManager is shared between Map and Renderer, therefore
is not a thread safe. Until AnnotationManager is deprecated and removed from a
code-base, use it only via weak pointers.
This commit is contained in:
Alexander Shalamov
2020-02-27 11:46:17 +02:00
parent c5155dcf33
commit 81e116d41a
14 changed files with 89 additions and 83 deletions

View File

@@ -11,6 +11,8 @@
#include <unordered_set>
#include <unordered_map>
#include <mapbox/weak.hpp>
namespace mbgl {
class LatLngBounds;
@@ -48,6 +50,8 @@ public:
static const std::string PointLayerID;
static const std::string ShapeLayerID;
mapbox::base::WeakPtr<AnnotationManager> makeWeakPtr() { return weakFactory.makeWeakPtr(); }
private:
void add(const AnnotationID&, const SymbolAnnotation&);
void add(const AnnotationID&, const LineAnnotation&);
@@ -84,6 +88,7 @@ private:
ImageMap images;
std::unordered_set<AnnotationTile*> tiles;
mapbox::base::WeakPtrFactory<AnnotationManager> weakFactory{this};
};
} // namespace mbgl

View File

@@ -11,11 +11,17 @@ AnnotationTile::AnnotationTile(const OverscaledTileID& overscaledTileID,
const TileParameters& parameters)
: GeometryTile(overscaledTileID, AnnotationManager::SourceID, parameters),
annotationManager(parameters.annotationManager) {
annotationManager.addTile(*this);
auto guard = annotationManager.lock();
if (annotationManager) {
annotationManager->addTile(*this);
}
}
AnnotationTile::~AnnotationTile() {
annotationManager.removeTile(*this);
auto guard = annotationManager.lock();
if (annotationManager) {
annotationManager->removeTile(*this);
}
}
class AnnotationTileFeatureData {

View File

@@ -15,7 +15,7 @@ public:
~AnnotationTile() override;
private:
AnnotationManager& annotationManager;
mapbox::base::WeakPtr<AnnotationManager> annotationManager;
};
class AnnotationTileFeatureData;

View File

@@ -48,26 +48,24 @@ void Map::Impl::onUpdate() {
transform.updateTransitions(timePoint);
UpdateParameters params = {
style->impl->isLoaded(),
mode,
pixelRatio,
debugOptions,
timePoint,
transform.getState(),
style->impl->getGlyphURL(),
style->impl->spriteLoaded,
style->impl->getTransitionOptions(),
style->impl->getLight()->impl,
style->impl->getImageImpls(),
style->impl->getSourceImpls(),
style->impl->getLayerImpls(),
annotationManager,
fileSource,
prefetchZoomDelta,
bool(stillImageRequest),
crossSourceCollisions
};
UpdateParameters params = {style->impl->isLoaded(),
mode,
pixelRatio,
debugOptions,
timePoint,
transform.getState(),
style->impl->getGlyphURL(),
style->impl->spriteLoaded,
style->impl->getTransitionOptions(),
style->impl->getLight()->impl,
style->impl->getImageImpls(),
style->impl->getSourceImpls(),
style->impl->getLayerImpls(),
annotationManager.makeWeakPtr(),
fileSource,
prefetchZoomDelta,
bool(stillImageRequest),
crossSourceCollisions};
rendererFrontend.update(std::make_shared<UpdateParameters>(std::move(params)));
}

View File

@@ -144,7 +144,10 @@ std::unique_ptr<RenderTree> RenderOrchestrator::createRenderTree(
}
if (LayerManager::annotationsEnabled) {
updateParameters->annotationManager.updateData();
auto guard = updateParameters->annotationManager.lock();
if (updateParameters->annotationManager) {
updateParameters->annotationManager->updateData();
}
}
const bool zoomChanged =

View File

@@ -4,6 +4,8 @@
#include <memory>
#include <mapbox/weak.hpp>
namespace mbgl {
class TransformState;
@@ -19,7 +21,7 @@ public:
const TransformState& transformState;
std::shared_ptr<FileSource> fileSource;
const MapMode mode;
AnnotationManager& annotationManager;
mapbox::base::WeakPtr<AnnotationManager> annotationManager;
ImageManager& imageManager;
GlyphManager& glyphManager;
const uint8_t prefetchZoomDelta;

View File

@@ -11,6 +11,8 @@
#include <vector>
#include <mapbox/weak.hpp>
namespace mbgl {
class AnnotationManager;
@@ -33,7 +35,7 @@ public:
const Immutable<std::vector<Immutable<style::Source::Impl>>> sources;
const Immutable<std::vector<Immutable<style::Layer::Impl>>> layers;
AnnotationManager& annotationManager;
mapbox::base::WeakPtr<AnnotationManager> annotationManager;
std::shared_ptr<FileSource> fileSource;
const uint8_t prefetchZoomDelta;

View File

@@ -69,7 +69,7 @@ public:
transformState,
fileSource,
mapMode,
annotationManager,
annotationManager.makeWeakPtr(),
imageManager,
glyphManager,
0};

View File

@@ -30,17 +30,15 @@ public:
ImageManager imageManager;
GlyphManager glyphManager;
TileParameters tileParameters {
1.0,
MapDebugOptions(),
transformState,
fileSource,
MapMode::Continuous,
annotationManager,
imageManager,
glyphManager,
0
};
TileParameters tileParameters{1.0,
MapDebugOptions(),
transformState,
fileSource,
MapMode::Continuous,
annotationManager.makeWeakPtr(),
imageManager,
glyphManager,
0};
};
TEST(CustomGeometryTile, InvokeFetchTile) {

View File

@@ -31,17 +31,15 @@ public:
GlyphManager glyphManager;
Tileset tileset { { "https://example.com" }, { 0, 22 }, "none" };
TileParameters tileParameters {
1.0,
MapDebugOptions(),
transformState,
fileSource,
MapMode::Continuous,
annotationManager,
imageManager,
glyphManager,
0
};
TileParameters tileParameters{1.0,
MapDebugOptions(),
transformState,
fileSource,
MapMode::Continuous,
annotationManager.makeWeakPtr(),
imageManager,
glyphManager,
0};
};
namespace {

View File

@@ -25,17 +25,15 @@ public:
GlyphManager glyphManager;
Tileset tileset { { "https://example.com" }, { 0, 22 }, "none" };
TileParameters tileParameters {
1.0,
MapDebugOptions(),
transformState,
fileSource,
MapMode::Continuous,
annotationManager,
imageManager,
glyphManager,
0
};
TileParameters tileParameters{1.0,
MapDebugOptions(),
transformState,
fileSource,
MapMode::Continuous,
annotationManager.makeWeakPtr(),
imageManager,
glyphManager,
0};
};
TEST(RasterDEMTile, setError) {

View File

@@ -25,17 +25,15 @@ public:
GlyphManager glyphManager;
Tileset tileset { { "https://example.com" }, { 0, 22 }, "none" };
TileParameters tileParameters {
1.0,
MapDebugOptions(),
transformState,
fileSource,
MapMode::Continuous,
annotationManager,
imageManager,
glyphManager,
0
};
TileParameters tileParameters{1.0,
MapDebugOptions(),
transformState,
fileSource,
MapMode::Continuous,
annotationManager.makeWeakPtr(),
imageManager,
glyphManager,
0};
};
TEST(RasterTile, setError) {

View File

@@ -39,7 +39,7 @@ public:
transformState,
fileSource,
MapMode::Continuous,
annotationManager,
annotationManager.makeWeakPtr(),
imageManager,
glyphManager,
0};

View File

@@ -31,17 +31,15 @@ public:
GlyphManager glyphManager;
Tileset tileset { { "https://example.com" }, { 0, 22 }, "none" };
TileParameters tileParameters {
1.0,
MapDebugOptions(),
transformState,
fileSource,
MapMode::Continuous,
annotationManager,
imageManager,
glyphManager,
0
};
TileParameters tileParameters{1.0,
MapDebugOptions(),
transformState,
fileSource,
MapMode::Continuous,
annotationManager.makeWeakPtr(),
imageManager,
glyphManager,
0};
};
TEST(VectorTile, setError) {