[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:
@@ -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
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -15,7 +15,7 @@ public:
|
||||
~AnnotationTile() override;
|
||||
|
||||
private:
|
||||
AnnotationManager& annotationManager;
|
||||
mapbox::base::WeakPtr<AnnotationManager> annotationManager;
|
||||
};
|
||||
|
||||
class AnnotationTileFeatureData;
|
||||
|
||||
@@ -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)));
|
||||
}
|
||||
|
||||
@@ -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 =
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -69,7 +69,7 @@ public:
|
||||
transformState,
|
||||
fileSource,
|
||||
mapMode,
|
||||
annotationManager,
|
||||
annotationManager.makeWeakPtr(),
|
||||
imageManager,
|
||||
glyphManager,
|
||||
0};
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -39,7 +39,7 @@ public:
|
||||
transformState,
|
||||
fileSource,
|
||||
MapMode::Continuous,
|
||||
annotationManager,
|
||||
annotationManager.makeWeakPtr(),
|
||||
imageManager,
|
||||
glyphManager,
|
||||
0};
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user