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

[core] Modularize FileSource codebase #15768

Merged
merged 5 commits into from
Jan 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
28 changes: 21 additions & 7 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

## Master

### New features
### ✨ New features

- [core] Port line-sort-key and fill-sort-key ([#15839](https://github.com/mapbox/mapbox-gl-native/pull/15839))

The new feature allows to sort line and fill layer features. Similar to `symbol-sort-key`.
Expand All @@ -27,7 +28,8 @@

This patch introduces batch conversion between LatLng and ScreenCoordinate in Gl-Native core, so for multiple conversions with single point/latLng previously now it can be done with invoking one function call by passing vector of points/latLngs.

### Bug fixes
### 🐞 Bug fixes

- [core] Stable position of labels at tile borders in tile mode ([#16040](https://github.com/mapbox/mapbox-gl-native/pull/16040))

These changes allow to avoid cutting-off labels on tile borders if the variable text placement is enabled.
Expand Down Expand Up @@ -78,7 +80,8 @@

This fixes rendering by account for the 1px texture padding around icons that were stretched with icon-text-fit.

### Performance improvements
### 🏁 Performance improvements

- [core] Calculate GeoJSON tile geometries in a background thread ([#15953](https://github.com/mapbox/mapbox-gl-native/pull/15953))

Call `mapbox::geojsonvt::GeoJSONVT::getTile()` in a background thread, so that the rendering thread is not blocked.
Expand All @@ -97,11 +100,22 @@

Before this fix, repeated request for an already obtained image was erroneously treated as pending, and it prevented from the tiles load completion.

### Architectural changes
- [core] Remove Map::cycleDebugOptions ([#16005](https://github.com/mapbox/mapbox-gl-native/pull/16005))

This function was mostly used by the Android API, which is no longer necessary.
### 🧩 Architectural changes

- [core] Merge style::Layer::set{Layout,Paint}Property ([#15997](https://github.com/mapbox/mapbox-gl-native/pull/15997))

- [core] Use expected.hpp from mapbox-base ([#15898](https://github.com/mapbox/mapbox-gl-native/pull/15898))

##### ⚠️ Breaking changes

- [core] Refactor DefaultFileSource codebase ([#15768](https://github.com/mapbox/mapbox-gl-native/pull/15768))
- Adds `FileSourceManager` interface that provides access to `FileSource` instances and means of registering / unregistering `FileSource` factories
- Splits `DefaultFileSource` into smaller parts
- Adds `DatabaseFileSource` interface and it's default implementation
- Removes inter-dependencies between concrete `FileSource` classes
- All sources operate on dedicated thread, except `MainResourceLoader` that acts as a dispatcher and works on thread that requested it.
- Removes `ResourceOptions::withCacheOnlyRequestsSupport` method

- [core] Remove Map::cycleDebugOptions ([#16005](https://github.com/mapbox/mapbox-gl-native/pull/16005))

This function was mostly used by the Android API, which is no longer necessary.
11 changes: 6 additions & 5 deletions bin/cache.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include <mbgl/storage/default_file_source.hpp>
#include <mbgl/storage/file_source_manager.hpp>
#include <mbgl/storage/resource.hpp>
#include <mbgl/storage/resource_options.hpp>
#include <mbgl/util/chrono.hpp>
#include <mbgl/util/run_loop.hpp>

Expand Down Expand Up @@ -89,9 +90,9 @@ int main(int argc, char* argv[]) {
}

mbgl::util::RunLoop loop;
mbgl::DefaultFileSource fileSource(args::get(cacheValue), ".");

fileSource.put(resource, response);

auto dbfs = mbgl::FileSourceManager::get()->getFileSource(
mbgl::FileSourceType::Database, mbgl::ResourceOptions().withCachePath(args::get(cacheValue)));
dbfs->forward(resource, response, [&loop] { loop.stop(); });
loop.run();
return 0;
}
70 changes: 36 additions & 34 deletions bin/offline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
#include <mbgl/util/string.hpp>
#include <mbgl/util/geojson.hpp>

#include <mbgl/storage/default_file_source.hpp>
#include <mbgl/storage/database_file_source.hpp>
#include <mbgl/storage/file_source_manager.hpp>
#include <mbgl/storage/resource_options.hpp>

#include <args.hxx>

Expand Down Expand Up @@ -161,17 +163,16 @@ int main(int argc, char *argv[]) {


util::RunLoop loop;
DefaultFileSource fileSource(output, ".");
std::unique_ptr<OfflineRegion> region;
std::shared_ptr<DatabaseFileSource> fileSource =
std::static_pointer_cast<DatabaseFileSource>(FileSourceManager::get()->getFileSource(
FileSourceType::Database,
ResourceOptions().withAccessToken(token).withBaseURL(apiBaseURL).withCachePath(output)));

fileSource.setAccessToken(token);
fileSource.setAPIBaseURL(apiBaseURL);
std::unique_ptr<OfflineRegion> region;

if (inputDb && mergePath) {
DefaultFileSource inputSource(*inputDb, ".");
inputSource.setAccessToken(token);
inputSource.setAPIBaseURL(apiBaseURL);

DatabaseFileSource inputSource(ResourceOptions().withCachePath(*inputDb));

int retCode = 0;
std::cout << "Start Merge" << std::endl;
inputSource.mergeOfflineRegions(*mergePath, [&] (mbgl::expected<std::vector<OfflineRegion>, std::exception_ptr> result) {
Expand All @@ -193,13 +194,15 @@ int main(int argc, char *argv[]) {

class Observer : public OfflineRegionObserver {
public:
Observer(OfflineRegion& region_, DefaultFileSource& fileSource_, util::RunLoop& loop_, mbgl::optional<std::string> mergePath_)
Observer(OfflineRegion& region_,
std::shared_ptr<DatabaseFileSource> fileSource_,
util::RunLoop& loop_,
mbgl::optional<std::string> mergePath_)
: region(region_),
fileSource(fileSource_),
fileSource(std::move(fileSource_)),
loop(loop_),
mergePath(std::move(mergePath_)),
start(util::now()) {
}
start(util::now()) {}

void statusChanged(OfflineRegionStatus status) override {
if (status.downloadState == OfflineRegionDownloadState::Inactive) {
Expand All @@ -215,14 +218,11 @@ int main(int argc, char *argv[]) {
bytesPerSecond = util::toString(status.completedResourceSize / elapsedSeconds);
}

std::cout << status.completedResourceCount << " / " << status.requiredResourceCount
<< " resources"
<< status.completedTileCount << " / " << status.requiredTileCount
<< "tiles"
<< (status.requiredResourceCountIsPrecise ? "; " : " (indeterminate); ")
std::cout << status.completedResourceCount << " / " << status.requiredResourceCount << " resources | "
<< status.completedTileCount << " / " << status.requiredTileCount << " tiles"
<< (status.requiredResourceCountIsPrecise ? " | " : " (indeterminate); ")
<< status.completedResourceSize << " bytes downloaded"
<< " (" << bytesPerSecond << " bytes/sec)"
<< std::endl;
<< " (" << bytesPerSecond << " bytes/sec)" << std::endl;

if (status.complete()) {
std::cout << "Finished Download" << std::endl;
Expand All @@ -239,7 +239,7 @@ int main(int argc, char *argv[]) {
}

OfflineRegion& region;
DefaultFileSource& fileSource;
std::shared_ptr<DatabaseFileSource> fileSource;
util::RunLoop& loop;
mbgl::optional<std::string> mergePath;
Timestamp start;
Expand All @@ -248,24 +248,26 @@ int main(int argc, char *argv[]) {
static auto stop = [&] {
if (region) {
std::cout << "Stopping download... ";
fileSource.setOfflineRegionDownloadState(*region, OfflineRegionDownloadState::Inactive);
fileSource->setOfflineRegionDownloadState(*region, OfflineRegionDownloadState::Inactive);
}
};

std::signal(SIGINT, [] (int) { stop(); });

fileSource.createOfflineRegion(definition, metadata, [&] (mbgl::expected<OfflineRegion, std::exception_ptr> region_) {
if (!region_) {
std::cerr << "Error creating region: " << util::toString(region_.error()) << std::endl;
loop.stop();
exit(1);
} else {
assert(region_);
region = std::make_unique<OfflineRegion>(std::move(*region_));
fileSource.setOfflineRegionObserver(*region, std::make_unique<Observer>(*region, fileSource, loop, mergePath));
fileSource.setOfflineRegionDownloadState(*region, OfflineRegionDownloadState::Active);
}
});
fileSource->createOfflineRegion(
definition, metadata, [&](mbgl::expected<OfflineRegion, std::exception_ptr> region_) {
if (!region_) {
std::cerr << "Error creating region: " << util::toString(region_.error()) << std::endl;
loop.stop();
exit(1);
} else {
assert(region_);
region = std::make_unique<OfflineRegion>(std::move(*region_));
fileSource->setOfflineRegionObserver(*region,
std::make_unique<Observer>(*region, fileSource, loop, mergePath));
fileSource->setOfflineRegionDownloadState(*region, OfflineRegionDownloadState::Active);
}
});

loop.run();
return 0;
Expand Down
3 changes: 3 additions & 0 deletions cmake/node.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ target_include_directories(mbgl-node INTERFACE
target_link_libraries(mbgl-node INTERFACE
mbgl-core
mbgl-loop-node
# link against default filesource code, so that the node map
# can register it's default resource loader.
mbgl-filesource
)

set_target_properties(mbgl-node.all PROPERTIES FOLDER "Node.js")
Expand Down
Loading