Skip to content

Commit

Permalink
Include MLN_WITH_PMTILES to enable or disable PMTiles support
Browse files Browse the repository at this point in the history
  • Loading branch information
tdcosta100 committed Oct 6, 2024
1 parent a888a1a commit 5e9e6cc
Show file tree
Hide file tree
Showing 9 changed files with 88 additions and 8 deletions.
11 changes: 10 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ option(MLN_WITH_OPENGL "Build with OpenGL renderer" ON)
option(MLN_WITH_EGL "Build with EGL renderer" OFF)
option(MLN_WITH_VULKAN "Build with Vulkan renderer" OFF)
option(MLN_WITH_OSMESA "Build with OSMesa (Software) renderer" OFF)
option(MLN_WITH_PMTILES "Build with PMTiles support" ON)
option(MLN_WITH_WERROR "Make all compilation warnings errors" ON)
option(MLN_LEGACY_RENDERER "Include the legacy rendering pathway" ON)
option(MLN_DRAWABLE_RENDERER "Include the drawable rendering pathway" OFF)
Expand Down Expand Up @@ -1466,7 +1467,7 @@ target_link_libraries(
mbgl-vendor-earcut.hpp
mbgl-vendor-eternal
mbgl-vendor-parsedate
mbgl-vendor-pmtiles
$<$<BOOL:${MLN_WITH_PMTILES}>:mbgl-vendor-pmtiles>
mbgl-vendor-polylabel
mbgl-vendor-protozero
mbgl-vendor-unique_resource
Expand Down Expand Up @@ -1532,6 +1533,14 @@ if(MLN_WITH_VULKAN)
)
endif()

if(MLN_WITH_PMTILES)
target_compile_definitions(
mbgl-core
PUBLIC
MLN_WITH_PMTILES
)
endif()

set_target_properties(
mbgl-core
PROPERTIES
Expand Down
2 changes: 2 additions & 0 deletions include/mbgl/storage/file_source.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ enum FileSourceType : uint8_t {
FileSystem,
Network,
Mbtiles,
#ifdef MLN_WITH_PMTILES
Pmtiles,
#endif
ResourceLoader ///< %Resource loader acts as a proxy and has logic
/// for request delegation to Asset, Cache, and other
/// file sources.
Expand Down
2 changes: 1 addition & 1 deletion platform/android/android.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ target_sources(
${PROJECT_SOURCE_DIR}/platform/default/src/mbgl/storage/offline_database.cpp
${PROJECT_SOURCE_DIR}/platform/default/src/mbgl/storage/offline_download.cpp
${PROJECT_SOURCE_DIR}/platform/default/src/mbgl/storage/online_file_source.cpp
${PROJECT_SOURCE_DIR}/platform/default/src/mbgl/storage/pmtiles_file_source.cpp
$<$<BOOL:${MLN_WITH_PMTILES}>:${PROJECT_SOURCE_DIR}/platform/default/src/mbgl/storage/pmtiles_file_source.cpp>
${PROJECT_SOURCE_DIR}/platform/default/src/mbgl/storage/sqlite3.cpp
${PROJECT_SOURCE_DIR}/platform/default/src/mbgl/text/bidi.cpp
${PROJECT_SOURCE_DIR}/platform/default/src/mbgl/util/compression.cpp
Expand Down
4 changes: 2 additions & 2 deletions platform/default/src/mbgl/storage/file_source_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@ class DefaultFileSourceManagerImpl final : public FileSourceManager {
[](const ResourceOptions& resourceOptions, const ClientOptions& clientOptions) {
return std::make_unique<MBTilesFileSource>(resourceOptions, clientOptions);
});

#ifdef MLN_WITH_PMTILES
registerFileSourceFactory(FileSourceType::Pmtiles,
[](const ResourceOptions& resourceOptions, const ClientOptions& clientOptions) {
return std::make_unique<PMTilesFileSource>(resourceOptions, clientOptions);
});

#endif
registerFileSourceFactory(FileSourceType::Network,
[](const ResourceOptions& resourceOptions, const ClientOptions& clientOptions) {
return std::make_unique<OnlineFileSource>(resourceOptions, clientOptions);
Expand Down
69 changes: 69 additions & 0 deletions platform/default/src/mbgl/storage/main_resource_loader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ namespace mbgl {

class MainResourceLoaderThread {
public:
#ifdef MLN_WITH_PMTILES
MainResourceLoaderThread(std::shared_ptr<FileSource> assetFileSource_,
std::shared_ptr<FileSource> databaseFileSource_,
std::shared_ptr<FileSource> localFileSource_,
Expand All @@ -29,6 +30,18 @@ class MainResourceLoaderThread {
onlineFileSource(std::move(onlineFileSource_)),
mbtilesFileSource(std::move(mbtilesFileSource_)),
pmtilesFileSource(std::move(pmtilesFileSource_)) {}
#else
MainResourceLoaderThread(std::shared_ptr<FileSource> assetFileSource_,
std::shared_ptr<FileSource> databaseFileSource_,
std::shared_ptr<FileSource> localFileSource_,
std::shared_ptr<FileSource> onlineFileSource_,
std::shared_ptr<FileSource> mbtilesFileSource_)
: assetFileSource(std::move(assetFileSource_)),
databaseFileSource(std::move(databaseFileSource_)),
localFileSource(std::move(localFileSource_)),
onlineFileSource(std::move(onlineFileSource_)),
mbtilesFileSource(std::move(mbtilesFileSource_)) {}
#endif

void request(AsyncRequest* req, const Resource& resource, const ActorRef<FileSourceRequest>& ref) {
auto callback = [ref](const Response& res) {
Expand Down Expand Up @@ -72,9 +85,11 @@ class MainResourceLoaderThread {
} else if (mbtilesFileSource && mbtilesFileSource->canRequest(resource)) {
// Local file request
tasks[req] = mbtilesFileSource->request(resource, callback);
#ifdef MLN_WITH_PMTILES
} else if (pmtilesFileSource && pmtilesFileSource->canRequest(resource)) {
// Local file request
tasks[req] = pmtilesFileSource->request(resource, callback);
#endif
} else if (localFileSource && localFileSource->canRequest(resource)) {
// Local file request
tasks[req] = localFileSource->request(resource, callback);
Expand Down Expand Up @@ -136,12 +151,15 @@ class MainResourceLoaderThread {
const std::shared_ptr<FileSource> localFileSource;
const std::shared_ptr<FileSource> onlineFileSource;
const std::shared_ptr<FileSource> mbtilesFileSource;
#ifdef MLN_WITH_PMTILES
const std::shared_ptr<FileSource> pmtilesFileSource;
#endif
std::map<AsyncRequest*, std::unique_ptr<AsyncRequest>> tasks;
};

class MainResourceLoader::Impl {
public:
#ifdef MLN_WITH_PMTILES
Impl(const ResourceOptions& resourceOptions_,
const ClientOptions& clientOptions_,
std::shared_ptr<FileSource> assetFileSource_,
Expand All @@ -168,6 +186,31 @@ class MainResourceLoader::Impl {
pmtilesFileSource)),
resourceOptions(resourceOptions_.clone()),
clientOptions(clientOptions_.clone()) {}
#else
Impl(const ResourceOptions& resourceOptions_,
const ClientOptions& clientOptions_,
std::shared_ptr<FileSource> assetFileSource_,
std::shared_ptr<FileSource> databaseFileSource_,
std::shared_ptr<FileSource> localFileSource_,
std::shared_ptr<FileSource> onlineFileSource_,
std::shared_ptr<FileSource> mbtilesFileSource_)
: assetFileSource(std::move(assetFileSource_)),
databaseFileSource(std::move(databaseFileSource_)),
localFileSource(std::move(localFileSource_)),
onlineFileSource(std::move(onlineFileSource_)),
mbtilesFileSource(std::move(mbtilesFileSource_)),
supportsCacheOnlyRequests_(bool(databaseFileSource)),
thread(std::make_unique<util::Thread<MainResourceLoaderThread>>(
util::makeThreadPrioritySetter(platform::EXPERIMENTAL_THREAD_PRIORITY_WORKER),
"ResourceLoaderThread",
assetFileSource,
databaseFileSource,
localFileSource,
onlineFileSource,
mbtilesFileSource)),
resourceOptions(resourceOptions_.clone()),
clientOptions(clientOptions_.clone()) {}
#endif

std::unique_ptr<AsyncRequest> request(const Resource& resource, Callback callback) {
auto req = std::make_unique<FileSourceRequest>(std::move(callback));
Expand All @@ -180,12 +223,20 @@ class MainResourceLoader::Impl {
}

bool canRequest(const Resource& resource) const {
#ifdef MLN_WITH_PMTILES
return (assetFileSource && assetFileSource->canRequest(resource)) ||
(localFileSource && localFileSource->canRequest(resource)) ||
(databaseFileSource && databaseFileSource->canRequest(resource)) ||
(onlineFileSource && onlineFileSource->canRequest(resource)) ||
(mbtilesFileSource && mbtilesFileSource->canRequest(resource)) ||
(pmtilesFileSource && pmtilesFileSource->canRequest(resource));
#else
return (assetFileSource && assetFileSource->canRequest(resource)) ||
(localFileSource && localFileSource->canRequest(resource)) ||
(databaseFileSource && databaseFileSource->canRequest(resource)) ||
(onlineFileSource && onlineFileSource->canRequest(resource)) ||
(mbtilesFileSource && mbtilesFileSource->canRequest(resource));
#endif
}

bool supportsCacheOnlyRequests() const { return supportsCacheOnlyRequests_; }
Expand All @@ -202,7 +253,9 @@ class MainResourceLoader::Impl {
localFileSource->setResourceOptions(options.clone());
onlineFileSource->setResourceOptions(options.clone());
mbtilesFileSource->setResourceOptions(options.clone());
#ifdef MLN_WITH_PMTILES
pmtilesFileSource->setResourceOptions(options.clone());
#endif
}

ResourceOptions getResourceOptions() {
Expand All @@ -218,7 +271,9 @@ class MainResourceLoader::Impl {
localFileSource->setClientOptions(options.clone());
onlineFileSource->setClientOptions(options.clone());
mbtilesFileSource->setClientOptions(options.clone());
#ifdef MLN_WITH_PMTILES
pmtilesFileSource->setClientOptions(options.clone());
#endif
}

ClientOptions getClientOptions() {
Expand All @@ -232,7 +287,9 @@ class MainResourceLoader::Impl {
const std::shared_ptr<FileSource> localFileSource;
const std::shared_ptr<FileSource> onlineFileSource;
const std::shared_ptr<FileSource> mbtilesFileSource;
#ifdef MLN_WITH_PMTILES
const std::shared_ptr<FileSource> pmtilesFileSource;
#endif
const bool supportsCacheOnlyRequests_;
const std::unique_ptr<util::Thread<MainResourceLoaderThread>> thread;
mutable std::mutex resourceOptionsMutex;
Expand All @@ -241,6 +298,7 @@ class MainResourceLoader::Impl {
ClientOptions clientOptions;
};

#ifdef MLN_WITH_PMTILES
MainResourceLoader::MainResourceLoader(const ResourceOptions& resourceOptions, const ClientOptions& clientOptions)
: impl(std::make_unique<Impl>(
resourceOptions.clone(),
Expand All @@ -251,6 +309,17 @@ MainResourceLoader::MainResourceLoader(const ResourceOptions& resourceOptions, c
FileSourceManager::get()->getFileSource(FileSourceType::Network, resourceOptions, clientOptions),
FileSourceManager::get()->getFileSource(FileSourceType::Mbtiles, resourceOptions, clientOptions),
FileSourceManager::get()->getFileSource(FileSourceType::Pmtiles, resourceOptions, clientOptions))) {}
#else
MainResourceLoader::MainResourceLoader(const ResourceOptions& resourceOptions, const ClientOptions& clientOptions)
: impl(std::make_unique<Impl>(
resourceOptions.clone(),
clientOptions.clone(),
FileSourceManager::get()->getFileSource(FileSourceType::Asset, resourceOptions, clientOptions),
FileSourceManager::get()->getFileSource(FileSourceType::Database, resourceOptions, clientOptions),
FileSourceManager::get()->getFileSource(FileSourceType::FileSystem, resourceOptions, clientOptions),
FileSourceManager::get()->getFileSource(FileSourceType::Network, resourceOptions, clientOptions),
FileSourceManager::get()->getFileSource(FileSourceType::Mbtiles, resourceOptions, clientOptions))) {}
#endif

MainResourceLoader::~MainResourceLoader() = default;

Expand Down
2 changes: 1 addition & 1 deletion platform/linux/linux.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ target_sources(
${PROJECT_SOURCE_DIR}/platform/default/src/mbgl/storage/offline_database.cpp
${PROJECT_SOURCE_DIR}/platform/default/src/mbgl/storage/offline_download.cpp
${PROJECT_SOURCE_DIR}/platform/default/src/mbgl/storage/online_file_source.cpp
${PROJECT_SOURCE_DIR}/platform/default/src/mbgl/storage/pmtiles_file_source.cpp
$<$<BOOL:${MLN_WITH_PMTILES}>:${PROJECT_SOURCE_DIR}/platform/default/src/mbgl/storage/pmtiles_file_source.cpp>
${PROJECT_SOURCE_DIR}/platform/default/src/mbgl/storage/sqlite3.cpp
${PROJECT_SOURCE_DIR}/platform/default/src/mbgl/text/bidi.cpp
${PROJECT_SOURCE_DIR}/platform/default/src/mbgl/text/local_glyph_rasterizer.cpp
Expand Down
2 changes: 1 addition & 1 deletion platform/macos/macos.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ target_sources(
${PROJECT_SOURCE_DIR}/platform/default/src/mbgl/storage/offline_database.cpp
${PROJECT_SOURCE_DIR}/platform/default/src/mbgl/storage/offline_download.cpp
${PROJECT_SOURCE_DIR}/platform/default/src/mbgl/storage/online_file_source.cpp
${PROJECT_SOURCE_DIR}/platform/default/src/mbgl/storage/pmtiles_file_source.cpp
$<$<BOOL:${MLN_WITH_PMTILES}>:${PROJECT_SOURCE_DIR}/platform/default/src/mbgl/storage/pmtiles_file_source.cpp>
${PROJECT_SOURCE_DIR}/platform/default/src/mbgl/storage/sqlite3.cpp
${PROJECT_SOURCE_DIR}/platform/default/src/mbgl/text/bidi.cpp
${PROJECT_SOURCE_DIR}/platform/default/src/mbgl/util/compression.cpp
Expand Down
2 changes: 1 addition & 1 deletion platform/qt/qt.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ target_sources(
${PROJECT_SOURCE_DIR}/platform/default/src/mbgl/storage/offline_database.cpp
${PROJECT_SOURCE_DIR}/platform/default/src/mbgl/storage/offline_download.cpp
${PROJECT_SOURCE_DIR}/platform/default/src/mbgl/storage/online_file_source.cpp
${PROJECT_SOURCE_DIR}/platform/default/src/mbgl/storage/pmtiles_file_source.cpp
$<$<BOOL:${MLN_WITH_PMTILES}>:${PROJECT_SOURCE_DIR}/platform/default/src/mbgl/storage/pmtiles_file_source.cpp>
${PROJECT_SOURCE_DIR}/platform/$<IF:$<BOOL:${MLN_QT_WITH_INTERNAL_SQLITE}>,default/src/mbgl/storage/sqlite3.cpp,qt/src/mbgl/sqlite3.cpp>
${PROJECT_SOURCE_DIR}/platform/default/src/mbgl/util/compression.cpp
${PROJECT_SOURCE_DIR}/platform/default/src/mbgl/util/filesystem.cpp
Expand Down
2 changes: 1 addition & 1 deletion platform/windows/windows.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ target_sources(
${PROJECT_SOURCE_DIR}/platform/default/src/mbgl/storage/offline_database.cpp
${PROJECT_SOURCE_DIR}/platform/default/src/mbgl/storage/offline_download.cpp
${PROJECT_SOURCE_DIR}/platform/default/src/mbgl/storage/online_file_source.cpp
${PROJECT_SOURCE_DIR}/platform/default/src/mbgl/storage/pmtiles_file_source.cpp
$<$<BOOL:${MLN_WITH_PMTILES}>:${PROJECT_SOURCE_DIR}/platform/default/src/mbgl/storage/pmtiles_file_source.cpp>
${PROJECT_SOURCE_DIR}/platform/default/src/mbgl/storage/sqlite3.cpp
${PROJECT_SOURCE_DIR}/platform/default/src/mbgl/text/bidi.cpp
${PROJECT_SOURCE_DIR}/platform/default/src/mbgl/text/local_glyph_rasterizer.cpp
Expand Down

0 comments on commit 5e9e6cc

Please sign in to comment.