summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Firebaugh <john.firebaugh@gmail.com>2016-06-17 08:28:19 -0700
committerAntonio Zugaldia <antonio@mapbox.com>2016-06-17 13:24:22 -0400
commit11dd4afc5b271c4efb0e900320bdca4d137cd049 (patch)
tree14777849adf64b498b7bbb5d28c829712246d2ad
parentebbe90983f1360126254b8d055beae14f59a35ea (diff)
downloadqtlocation-mapboxgl-11dd4afc5b271c4efb0e900320bdca4d137cd049.tar.gz
[core] Bring optimized animated annotations to Android release branch
Part of #5385
-rw-r--r--include/mbgl/map/update.hpp3
-rw-r--r--src/mbgl/annotation/annotation_manager.cpp29
-rw-r--r--src/mbgl/annotation/annotation_manager.hpp6
-rw-r--r--src/mbgl/map/map.cpp17
-rw-r--r--src/mbgl/style/style.cpp6
-rw-r--r--src/mbgl/style/style.hpp2
-rw-r--r--src/mbgl/tile/tile_worker.cpp17
-rw-r--r--src/mbgl/tile/tile_worker.hpp2
-rw-r--r--src/mbgl/tile/vector_tile_data.cpp28
-rw-r--r--src/mbgl/tile/vector_tile_data.hpp5
-rw-r--r--test/api/annotations.cpp2
11 files changed, 75 insertions, 42 deletions
diff --git a/include/mbgl/map/update.hpp b/include/mbgl/map/update.hpp
index 3915545bb0..1c1270ac70 100644
--- a/include/mbgl/map/update.hpp
+++ b/include/mbgl/map/update.hpp
@@ -13,7 +13,8 @@ enum class Update : uint8_t {
RecalculateStyle = 1 << 3,
RenderStill = 1 << 4,
Repaint = 1 << 5,
- Annotations = 1 << 6,
+ AnnotationStyle = 1 << 6,
+ AnnotationData = 1 << 7,
};
inline Update operator| (const Update& lhs, const Update& rhs) {
diff --git a/src/mbgl/annotation/annotation_manager.cpp b/src/mbgl/annotation/annotation_manager.cpp
index 1febc757a4..5cd2616960 100644
--- a/src/mbgl/annotation/annotation_manager.cpp
+++ b/src/mbgl/annotation/annotation_manager.cpp
@@ -49,14 +49,29 @@ AnnotationManager::addShapeAnnotations(const std::vector<ShapeAnnotation>& shape
return annotationIDs;
}
-void AnnotationManager::updatePointAnnotation(const AnnotationID& id, const PointAnnotation& point, const uint8_t) {
+Update AnnotationManager::updatePointAnnotation(const AnnotationID& id, const PointAnnotation& point, const uint8_t) {
auto foundAnnotation = pointAnnotations.find(id);
- if (foundAnnotation != pointAnnotations.end()) {
- auto updatedAnnotation = std::make_shared<PointAnnotationImpl>(id, point);
- pointTree.remove(foundAnnotation->second);
- pointTree.insert(updatedAnnotation);
- foundAnnotation->second = updatedAnnotation;
+ if (foundAnnotation == pointAnnotations.end()) {
+ return Update::Nothing;
}
+
+ Update result = Update::Nothing;
+ const PointAnnotation& existing = foundAnnotation->second->point;
+
+ if (existing.position != point.position) {
+ result |= Update::AnnotationData;
+ }
+
+ if (existing.icon != point.icon) {
+ result |= Update::AnnotationData | Update::AnnotationStyle;
+ }
+
+ auto updatedAnnotation = std::make_shared<PointAnnotationImpl>(id, point);
+ pointTree.remove(foundAnnotation->second);
+ pointTree.insert(updatedAnnotation);
+ foundAnnotation->second = updatedAnnotation;
+
+ return result;
}
void AnnotationManager::removeAnnotations(const AnnotationIDs& ids) {
@@ -135,7 +150,9 @@ void AnnotationManager::updateStyle(Style& style) {
}
obsoleteShapeAnnotationLayers.clear();
+}
+void AnnotationManager::updateData() {
for (auto& monitor : monitors) {
monitor->update(getTile(monitor->tileID.canonical));
}
diff --git a/src/mbgl/annotation/annotation_manager.hpp b/src/mbgl/annotation/annotation_manager.hpp
index aaa60278cf..560a166894 100644
--- a/src/mbgl/annotation/annotation_manager.hpp
+++ b/src/mbgl/annotation/annotation_manager.hpp
@@ -5,7 +5,7 @@
#include <mbgl/annotation/shape_annotation_impl.hpp>
#include <mbgl/sprite/sprite_store.hpp>
#include <mbgl/sprite/sprite_atlas.hpp>
-#include <mbgl/util/geo.hpp>
+#include <mbgl/map/update.hpp>
#include <mbgl/util/noncopyable.hpp>
#include <string>
@@ -14,6 +14,7 @@
namespace mbgl {
+class LatLngBounds;
class PointAnnotation;
class ShapeAnnotation;
class AnnotationTile;
@@ -27,7 +28,7 @@ public:
AnnotationIDs addPointAnnotations(const std::vector<PointAnnotation>&, const uint8_t maxZoom);
AnnotationIDs addShapeAnnotations(const std::vector<ShapeAnnotation>&, const uint8_t maxZoom);
- void updatePointAnnotation(const AnnotationID&, const PointAnnotation&, const uint8_t maxZoom);
+ Update updatePointAnnotation(const AnnotationID&, const PointAnnotation&, const uint8_t maxZoom);
void removeAnnotations(const AnnotationIDs&);
AnnotationIDs getPointAnnotationsInBounds(const LatLngBounds&) const;
@@ -38,6 +39,7 @@ public:
SpriteAtlas& getSpriteAtlas() { return spriteAtlas; }
void updateStyle(Style&);
+ void updateData();
void addTileMonitor(AnnotationTileMonitor&);
void removeTileMonitor(AnnotationTileMonitor&);
diff --git a/src/mbgl/map/map.cpp b/src/mbgl/map/map.cpp
index 841b4607c6..99262beb2e 100644
--- a/src/mbgl/map/map.cpp
+++ b/src/mbgl/map/map.cpp
@@ -211,11 +211,15 @@ void Map::Impl::update() {
// - Hint style sources to notify when all its tiles are loaded;
timePoint = Clock::now();
- if (style->loaded && updateFlags & Update::Annotations) {
+ if (style->loaded && updateFlags & Update::AnnotationStyle) {
annotationManager->updateStyle(*style);
updateFlags |= Update::Classes;
}
+ if (updateFlags & Update::AnnotationData) {
+ annotationManager->updateData();
+ }
+
if (updateFlags & Update::Classes) {
style->cascade(timePoint, mode);
}
@@ -344,7 +348,7 @@ void Map::Impl::loadStyleJSON(const std::string& json, const std::string& base)
// force style cascade, causing all pending transitions to complete.
style->cascade(Clock::now(), mode);
- updateFlags |= Update::Classes | Update::RecalculateStyle | Update::Annotations;
+ updateFlags |= Update::Classes | Update::RecalculateStyle | Update::AnnotationStyle;
asyncUpdate.send();
}
@@ -700,7 +704,7 @@ AnnotationID Map::addPointAnnotation(const PointAnnotation& annotation) {
AnnotationIDs Map::addPointAnnotations(const std::vector<PointAnnotation>& annotations) {
auto result = impl->annotationManager->addPointAnnotations(annotations, getMaxZoom());
- update(Update::Annotations);
+ update(Update::AnnotationStyle | Update::AnnotationData);
return result;
}
@@ -710,13 +714,12 @@ AnnotationID Map::addShapeAnnotation(const ShapeAnnotation& annotation) {
AnnotationIDs Map::addShapeAnnotations(const std::vector<ShapeAnnotation>& annotations) {
auto result = impl->annotationManager->addShapeAnnotations(annotations, getMaxZoom());
- update(Update::Annotations);
+ update(Update::AnnotationStyle | Update::AnnotationData);
return result;
}
void Map::updatePointAnnotation(AnnotationID annotationId, const PointAnnotation& annotation) {
- impl->annotationManager->updatePointAnnotation(annotationId, annotation, getMaxZoom());
- update(Update::Annotations);
+ update(impl->annotationManager->updatePointAnnotation(annotationId, annotation, getMaxZoom()));
}
void Map::removeAnnotation(AnnotationID annotation) {
@@ -725,7 +728,7 @@ void Map::removeAnnotation(AnnotationID annotation) {
void Map::removeAnnotations(const AnnotationIDs& annotations) {
impl->annotationManager->removeAnnotations(annotations);
- update(Update::Annotations);
+ update(Update::AnnotationStyle | Update::AnnotationData);
}
AnnotationIDs Map::getPointAnnotationsInBounds(const LatLngBounds& bounds) {
diff --git a/src/mbgl/style/style.cpp b/src/mbgl/style/style.cpp
index bc2a1d9a40..774e523b7b 100644
--- a/src/mbgl/style/style.cpp
+++ b/src/mbgl/style/style.cpp
@@ -109,11 +109,11 @@ void Style::addSource(std::unique_ptr<Source> source) {
sources.emplace_back(std::move(source));
}
-std::vector<std::unique_ptr<StyleLayer>> Style::getLayers() const {
- std::vector<std::unique_ptr<StyleLayer>> result;
+std::vector<const StyleLayer*> Style::getLayers() const {
+ std::vector<const StyleLayer*> result;
result.reserve(layers.size());
for (const auto& layer : layers) {
- result.push_back(layer->clone());
+ result.push_back(layer.get());
}
return result;
}
diff --git a/src/mbgl/style/style.hpp b/src/mbgl/style/style.hpp
index 5fdd6cdc8e..1150c9daf5 100644
--- a/src/mbgl/style/style.hpp
+++ b/src/mbgl/style/style.hpp
@@ -69,7 +69,7 @@ public:
Source* getSource(const std::string& id) const;
void addSource(std::unique_ptr<Source>);
- std::vector<std::unique_ptr<StyleLayer>> getLayers() const;
+ std::vector<const StyleLayer*> getLayers() const;
StyleLayer* getLayer(const std::string& id) const;
void addLayer(std::unique_ptr<StyleLayer>,
optional<std::string> beforeLayerID = {});
diff --git a/src/mbgl/tile/tile_worker.cpp b/src/mbgl/tile/tile_worker.cpp
index 266e357ab1..ae26ccd4a3 100644
--- a/src/mbgl/tile/tile_worker.cpp
+++ b/src/mbgl/tile/tile_worker.cpp
@@ -3,8 +3,6 @@
#include <mbgl/tile/geometry_tile.hpp>
#include <mbgl/style/style_layer.hpp>
#include <mbgl/style/style_bucket_parameters.hpp>
-#include <mbgl/layer/background_layer.hpp>
-#include <mbgl/layer/custom_layer.hpp>
#include <mbgl/layer/symbol_layer.hpp>
#include <mbgl/sprite/sprite_atlas.hpp>
#include <mbgl/geometry/glyph_atlas.hpp>
@@ -13,19 +11,18 @@
#include <mbgl/util/constants.hpp>
#include <mbgl/util/string.hpp>
#include <mbgl/util/exception.hpp>
+
#include <utility>
using namespace mbgl;
TileWorker::TileWorker(const OverscaledTileID& id_,
- std::string sourceID_,
SpriteStore& spriteStore_,
GlyphAtlas& glyphAtlas_,
GlyphStore& glyphStore_,
const util::Atomic<bool>& obsolete_,
const MapMode mode_)
: id(id_),
- sourceID(std::move(sourceID_)),
spriteStore(spriteStore_),
glyphAtlas(glyphAtlas_),
glyphStore(glyphStore_),
@@ -134,18 +131,6 @@ void TileWorker::parseLayer(const StyleLayer* layer) {
if (obsolete)
return;
- // Background and custom layers are special cases.
- if (layer->is<BackgroundLayer>() || layer->is<CustomLayer>())
- return;
-
- // Skip this bucket if we are to not render this
- if ((layer->source != sourceID) ||
- (id.overscaledZ < std::floor(layer->minZoom)) ||
- (id.overscaledZ >= std::ceil(layer->maxZoom)) ||
- (layer->visibility == VisibilityType::None)) {
- return;
- }
-
auto geometryLayer = geometryTile->getLayer(layer->sourceLayer);
if (!geometryLayer) {
// The layer specified in the bucket does not exist. Do nothing.
diff --git a/src/mbgl/tile/tile_worker.hpp b/src/mbgl/tile/tile_worker.hpp
index e19d803ac4..5a8b336e31 100644
--- a/src/mbgl/tile/tile_worker.hpp
+++ b/src/mbgl/tile/tile_worker.hpp
@@ -43,7 +43,6 @@ using TileParseResult = variant<
class TileWorker : public util::noncopyable {
public:
TileWorker(const OverscaledTileID&,
- std::string sourceID,
SpriteStore&,
GlyphAtlas&,
GlyphStore&,
@@ -67,7 +66,6 @@ private:
std::unique_ptr<CollisionTile> placeLayers(PlacementConfig);
const OverscaledTileID id;
- const std::string sourceID;
SpriteStore& spriteStore;
GlyphAtlas& glyphAtlas;
diff --git a/src/mbgl/tile/vector_tile_data.cpp b/src/mbgl/tile/vector_tile_data.cpp
index 428c605f26..e81e94ed5a 100644
--- a/src/mbgl/tile/vector_tile_data.cpp
+++ b/src/mbgl/tile/vector_tile_data.cpp
@@ -1,6 +1,8 @@
#include <mbgl/tile/vector_tile_data.hpp>
#include <mbgl/tile/geometry_tile.hpp>
#include <mbgl/style/style_layer.hpp>
+#include <mbgl/layer/background_layer.hpp>
+#include <mbgl/layer/custom_layer.hpp>
#include <mbgl/util/worker.hpp>
#include <mbgl/util/work_request.hpp>
#include <mbgl/style/style.hpp>
@@ -13,15 +15,15 @@ namespace mbgl {
VectorTileData::VectorTileData(const OverscaledTileID& id_,
std::unique_ptr<GeometryTileMonitor> monitor_,
- std::string sourceID,
+ std::string sourceID_,
Style& style_,
const MapMode mode_,
const std::function<void(std::exception_ptr)>& callback)
: TileData(id_),
+ sourceID(std::move(sourceID_)),
style(style_),
worker(style_.workers),
tileWorker(id_,
- sourceID,
*style_.spriteStore,
*style_.glyphAtlas,
*style_.glyphStore,
@@ -60,7 +62,7 @@ VectorTileData::VectorTileData(const OverscaledTileID& id_,
// when tile data changed. Replacing the workdRequest will cancel a pending work
// request in case there is one.
workRequest.reset();
- workRequest = worker.parseGeometryTile(tileWorker, style.getLayers(), std::move(tile), targetConfig, [callback, this, config = targetConfig] (TileParseResult result) {
+ workRequest = worker.parseGeometryTile(tileWorker, cloneStyleLayers(), std::move(tile), targetConfig, [callback, this, config = targetConfig] (TileParseResult result) {
workRequest.reset();
std::exception_ptr error;
@@ -97,6 +99,26 @@ VectorTileData::~VectorTileData() {
cancel();
}
+std::vector<std::unique_ptr<StyleLayer>> VectorTileData::cloneStyleLayers() const {
+ std::vector<std::unique_ptr<StyleLayer>> result;
+
+ for (const StyleLayer* layer : style.getLayers()) {
+ // Avoid cloning and including irrelevant layers.
+ if (layer->is<BackgroundLayer>() ||
+ layer->is<CustomLayer>() ||
+ layer->source != sourceID ||
+ id.overscaledZ < std::floor(layer->minZoom) ||
+ id.overscaledZ >= std::ceil(layer->maxZoom) ||
+ layer->visibility == VisibilityType::None) {
+ continue;
+ }
+
+ result.push_back(layer->clone());
+ }
+
+ return result;
+}
+
bool VectorTileData::parsePending(std::function<void(std::exception_ptr)> callback) {
if (workRequest) {
// There's already parsing or placement going on.
diff --git a/src/mbgl/tile/vector_tile_data.hpp b/src/mbgl/tile/vector_tile_data.hpp
index ec557e2023..a6ed6213ce 100644
--- a/src/mbgl/tile/vector_tile_data.hpp
+++ b/src/mbgl/tile/vector_tile_data.hpp
@@ -8,10 +8,12 @@
#include <memory>
#include <unordered_map>
+#include <vector>
namespace mbgl {
class Style;
+class StyleLayer;
class AsyncRequest;
class GeometryTileMonitor;
class FeatureIndex;
@@ -43,6 +45,9 @@ public:
void cancel() override;
private:
+ std::vector<std::unique_ptr<StyleLayer>> cloneStyleLayers() const;
+
+ const std::string sourceID;
Style& style;
Worker& worker;
TileWorker tileWorker;
diff --git a/test/api/annotations.cpp b/test/api/annotations.cpp
index 8640ce9dbe..0764cd8a5d 100644
--- a/test/api/annotations.cpp
+++ b/test/api/annotations.cpp
@@ -159,7 +159,7 @@ TEST(Annotations, UpdateIcon) {
map.removeAnnotationIcon("flipped_marker");
map.addAnnotationIcon("flipped_marker", namedMarker("flipped_marker.png"));
- map.update(Update::Annotations);
+ map.update(Update::AnnotationData | Update::AnnotationStyle);
checkRendering(map, "update_icon");
}