Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Refactor TileDataMonitors #5143

Merged
merged 32 commits into from
Jun 10, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
e8d8f52
[core] *TileMonitor => *TileSource
kkaefer May 19, 2016
99b1df4
[core] introduce a RasterTileMonitor
kkaefer May 19, 2016
46b0ebc
[core] rename VectorTileData => GeometryTileData
kkaefer May 19, 2016
6b729cc
[core] store Resource instead of dependents to build URL
kkaefer May 19, 2016
2b6d075
[core] restructure TileSource construction and callbacks
kkaefer May 20, 2016
436d8eb
[core] introduce TileDataObserver
kkaefer May 23, 2016
971807d
[core] move parsePending() call to TileData
kkaefer May 23, 2016
4357fed
[core] merge similar implementation of VectorTileSource and ImageTile…
kkaefer May 23, 2016
f180179
[core] allow changing the necessity of a TileSource
kkaefer May 23, 2016
91895b9
[core] only perform optional requests if the FileSource supports it
kkaefer May 27, 2016
913d28e
[core] TileSources always start out as Optional
kkaefer May 27, 2016
4673a9d
[core] remove unused TileSource::loaded
kkaefer May 27, 2016
2c7f7fb
[core] createTile callback can load optional and required tiles
kkaefer May 27, 2016
8a8f828
[core] rename onPlacementRedone -> onNeedsRepaint
kkaefer May 27, 2016
fce5dd5
[core] TileData objects now store whether an optional load attempt wa…
kkaefer May 27, 2016
4e5d065
[core] load parents of missing tiles as optional
kkaefer May 27, 2016
ebd19db
[core] Remove unused includes
jfirebaugh Jun 6, 2016
7235ba0
[core] Repeat some code so that all branches are parallel
jfirebaugh Jun 6, 2016
5f05294
[core] Move cache lookup out of Source::createTile
jfirebaugh Jun 6, 2016
a7cc291
[core] Move setObserver out of Source::createTile
jfirebaugh Jun 6, 2016
908f3f0
[core] Introduce GeometryTileData subclasses
jfirebaugh Jun 6, 2016
c3a8534
[core] Push conditional initialization into subclasses
jfirebaugh Jun 6, 2016
dbf1644
[core] Eliminate Source dependency on TileSource
jfirebaugh Jun 7, 2016
b45713e
[core] Eliminate TileData dependency on TileSource
jfirebaugh Jun 7, 2016
d62baff
[core] Merge AnnotationTileSource into AnnotationTileData
jfirebaugh Jun 7, 2016
91ddcbc
[core] Merge GeoJSONTileSource into GeoJSONTileData
jfirebaugh Jun 7, 2016
8d8d03a
[core] Merge VectorTileSource into VectorTileData
jfirebaugh Jun 7, 2016
4596157
[core] Merge ImageTileSource into RasterTileData
jfirebaugh Jun 7, 2016
a1d1bb0
[core] Simplify FileBasedTileSource
jfirebaugh Jun 7, 2016
94cfb1e
[core] Factor common code into FileBasedTileSource
jfirebaugh Jun 7, 2016
49120b1
[core] Merge FileBasedTileSource and TileSource
jfirebaugh Jun 7, 2016
ca8b26b
[core] Inline TileSource::isRequired, remove unused isOptional
jfirebaugh Jun 7, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions include/mbgl/storage/default_file_source.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ class DefaultFileSource : public FileSource {
uint64_t maximumCacheSize = util::DEFAULT_MAX_CACHE_SIZE);
~DefaultFileSource() override;

bool supportsOptionalRequests() const override {
return true;
}

void setAccessToken(const std::string&);
std::string getAccessToken() const;

Expand Down
8 changes: 8 additions & 0 deletions include/mbgl/storage/file_source.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,14 @@ class FileSource : private util::noncopyable {
// If the request is cancelled before the callback is executed, the callback will
// not be executed.
virtual std::unique_ptr<AsyncRequest> request(const Resource&, Callback) = 0;

// When a file source supports optional requests, it must return true.
// Optional requests are requests that aren't as urgent, but could be useful, e.g.
// to cover part of the map while loading. The FileSource should only do cheap actions to
// retrieve the data, e.g. load it from a cache, but not from the internet.
virtual bool supportsOptionalRequests() const {
return false;
}
};

} // namespace mbgl
28 changes: 19 additions & 9 deletions src/mbgl/algorithm/update_renderables.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,19 +39,21 @@ void updateRenderables(GetTileDataFn getTileData,

// if (source has the tile and bucket is loaded) {
if (data->isRenderable()) {
retainTileData(*data);
retainTileData(*data, true);
renderTile(idealRenderTileID, *data);
} else {
bool triedPrevious = data->hasTriedOptional();

// The tile isn't loaded yet, but retain it anyway because it's an ideal tile.
retainTileData(*data);
retainTileData(*data, true);
covered = true;
overscaledZ = dataTileZoom + 1;
if (overscaledZ > info.maxZoom) {
// We're looking for an overzoomed child tile.
const auto childDataTileID = idealDataTileID.scaledTo(overscaledZ);
data = getTileData(childDataTileID);
if (data && data->isRenderable()) {
retainTileData(*data);
retainTileData(*data, false);
renderTile(idealRenderTileID, *data);
} else {
covered = false;
Expand All @@ -62,7 +64,7 @@ void updateRenderables(GetTileDataFn getTileData,
const OverscaledTileID childDataTileID(overscaledZ, childTileID);
data = getTileData(childDataTileID);
if (data && data->isRenderable()) {
retainTileData(*data);
retainTileData(*data, false);
renderTile(childDataTileID.unwrapTo(idealRenderTileID.wrap), *data);
} else {
// At least one child tile doesn't exist, so we are going to look for
Expand All @@ -88,11 +90,19 @@ void updateRenderables(GetTileDataFn getTileData,
}

data = getTileData(parentDataTileID);
if (data && data->isRenderable()) {
retainTileData(*data);
renderTile(parentRenderTileID, *data);
// Break parent tile ascent, since we found one.
break;
if (!data && triedPrevious) {
data = createTileData(parentDataTileID);
}

if (data) {
triedPrevious = data->hasTriedOptional();
retainTileData(*data, false);

if (data->isRenderable()) {
renderTile(parentRenderTileID, *data);
// Break parent tile ascent, since we found one.
break;
}
}
}
}
Expand Down
15 changes: 8 additions & 7 deletions src/mbgl/annotation/annotation_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <mbgl/annotation/fill_annotation_impl.hpp>
#include <mbgl/annotation/style_sourced_annotation_impl.hpp>
#include <mbgl/style/source.hpp>
#include <mbgl/tile/annotation_tile_data.hpp>
#include <mbgl/style/style.hpp>
#include <mbgl/style/layers/symbol_layer.hpp>
#include <mbgl/style/layers/symbol_layer_impl.hpp>
Expand Down Expand Up @@ -134,18 +135,18 @@ void AnnotationManager::updateStyle(Style& style) {

obsoleteShapeAnnotationLayers.clear();

for (auto& monitor : monitors) {
monitor->update(getTile(monitor->tileID.canonical));
for (auto& data : monitors) {
data->setData(getTile(data->id.canonical), {}, {});
}
}

void AnnotationManager::addTileMonitor(AnnotationTileMonitor& monitor) {
monitors.insert(&monitor);
monitor.update(getTile(monitor.tileID.canonical));
void AnnotationManager::addTileData(AnnotationTileData& data) {
monitors.insert(&data);
data.setData(getTile(data.id.canonical), {}, {});
}

void AnnotationManager::removeTileMonitor(AnnotationTileMonitor& monitor) {
monitors.erase(&monitor);
void AnnotationManager::removeTileData(AnnotationTileData& data) {
monitors.erase(&data);
}

void AnnotationManager::addIcon(const std::string& name, std::shared_ptr<const SpriteImage> sprite) {
Expand Down
8 changes: 4 additions & 4 deletions src/mbgl/annotation/annotation_manager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
namespace mbgl {

class AnnotationTile;
class AnnotationTileMonitor;
class AnnotationTileData;
class SymbolAnnotationImpl;
class ShapeAnnotationImpl;

Expand All @@ -41,8 +41,8 @@ class AnnotationManager : private util::noncopyable {

void updateStyle(style::Style&);

void addTileMonitor(AnnotationTileMonitor&);
void removeTileMonitor(AnnotationTileMonitor&);
void addTileData(AnnotationTileData&);
void removeTileData(AnnotationTileData&);

static const std::string SourceID;
static const std::string PointLayerID;
Expand All @@ -65,7 +65,7 @@ class AnnotationManager : private util::noncopyable {
SymbolAnnotationMap symbolAnnotations;
ShapeAnnotationMap shapeAnnotations;
std::vector<std::string> obsoleteShapeAnnotationLayers;
std::set<AnnotationTileMonitor*> monitors;
std::set<AnnotationTileData*> monitors;

SpriteStore spriteStore;
SpriteAtlas spriteAtlas;
Expand Down
19 changes: 0 additions & 19 deletions src/mbgl/annotation/annotation_tile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,23 +32,4 @@ util::ptr<GeometryTileLayer> AnnotationTile::getLayer(const std::string& name) c
return nullptr;
}

AnnotationTileMonitor::AnnotationTileMonitor(const OverscaledTileID& tileID_, AnnotationManager& annotationManager_)
: tileID(tileID_),
annotationManager(annotationManager_) {
}

AnnotationTileMonitor::~AnnotationTileMonitor() {
annotationManager.removeTileMonitor(*this);
}

std::unique_ptr<AsyncRequest> AnnotationTileMonitor::monitorTile(const GeometryTileMonitor::Callback& callback_) {
callback = callback_;
annotationManager.addTileMonitor(*this);
return nullptr;
}

void AnnotationTileMonitor::update(std::unique_ptr<GeometryTile> tile) {
callback(nullptr, std::move(tile), {}, {});
}

} // namespace mbgl
23 changes: 1 addition & 22 deletions src/mbgl/annotation/annotation_tile.hpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
#pragma once

#include <mbgl/tile/geometry_tile.hpp>
#include <mbgl/tile/tile_id.hpp>

#include <map>
#include <unordered_map>

namespace mbgl {

Expand Down Expand Up @@ -40,24 +36,7 @@ class AnnotationTile : public GeometryTile {
public:
util::ptr<GeometryTileLayer> getLayer(const std::string&) const override;

std::map<std::string, util::ptr<AnnotationTileLayer>> layers;
};

class AnnotationManager;

class AnnotationTileMonitor : public GeometryTileMonitor {
public:
AnnotationTileMonitor(const OverscaledTileID&, AnnotationManager&);
~AnnotationTileMonitor();

void update(std::unique_ptr<GeometryTile>);
std::unique_ptr<AsyncRequest> monitorTile(const GeometryTileMonitor::Callback&) override;

OverscaledTileID tileID;

private:
AnnotationManager& annotationManager;
GeometryTileMonitor::Callback callback;
std::unordered_map<std::string, util::ptr<AnnotationTileLayer>> layers;
};

} // namespace mbgl
1 change: 1 addition & 0 deletions src/mbgl/annotation/symbol_annotation_impl.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include <mbgl/annotation/symbol_annotation_impl.hpp>
#include <mbgl/annotation/annotation_tile.hpp>
#include <mbgl/tile/tile_id.hpp>
#include <mbgl/math/clamp.hpp>

namespace mbgl {
Expand Down
4 changes: 2 additions & 2 deletions src/mbgl/map/map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class Map::Impl : public style::Observer {
public:
Impl(View&, FileSource&, MapMode, GLContextMode, ConstrainMode, ViewportMode);

void onResourceLoaded() override;
void onNeedsRepaint() override;
void onResourceError(std::exception_ptr) override;

void update();
Expand Down Expand Up @@ -836,7 +836,7 @@ void Map::onLowMemory() {
impl->view.invalidate();
}

void Map::Impl::onResourceLoaded() {
void Map::Impl::onNeedsRepaint() {
updateFlags |= Update::Repaint;
asyncUpdate.send();
}
Expand Down
6 changes: 3 additions & 3 deletions src/mbgl/style/observer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ class Observer : public GlyphStoreObserver,
* In addition to the individual glyph, sprite, and source events, the
* following "rollup" events are provided for convenience. They are
* strictly additive; e.g. when a source is loaded, both `onSourceLoaded`
* and `onResourceLoaded` will be called.
* and `onNeedsRepaint` will be called.
*/
virtual void onResourceLoaded() {};
virtual void onResourceError(std::exception_ptr) {};
virtual void onNeedsRepaint() {}
virtual void onResourceError(std::exception_ptr) {}
};

} // namespace style
Expand Down
Loading