@@ -241,7 +241,6 @@ target_link_libraries(maplibre
|
||||
$<$<CONFIG:Release>:-fuse-ld=gold>
|
||||
Mapbox::Base::jni.hpp
|
||||
mbgl-core
|
||||
mbgl-vendor-nontype_functional
|
||||
mbgl-vendor-unique_resource)
|
||||
|
||||
install(TARGETS maplibre LIBRARY DESTINATION lib)
|
||||
|
||||
@@ -1,16 +1,17 @@
|
||||
#include "android_renderer_frontend.hpp"
|
||||
#include "android_renderer_backend.hpp"
|
||||
|
||||
#include <mbgl/tile/tile_operation.hpp>
|
||||
#include <mbgl/actor/scheduler.hpp>
|
||||
#include <mbgl/renderer/renderer.hpp>
|
||||
#include <mbgl/renderer/renderer_observer.hpp>
|
||||
#include <mbgl/tile/tile_operation.hpp>
|
||||
#include <mbgl/util/async_task.hpp>
|
||||
#include <mbgl/util/geojson.hpp>
|
||||
#include <mbgl/util/instrumentation.hpp>
|
||||
#include <mbgl/util/run_loop.hpp>
|
||||
#include <mbgl/util/thread.hpp>
|
||||
|
||||
#include "android_renderer_backend.hpp"
|
||||
|
||||
namespace mbgl {
|
||||
namespace android {
|
||||
|
||||
@@ -44,8 +45,8 @@ public:
|
||||
|
||||
void onDidFinishRenderingMap() override { delegate.invoke(&RendererObserver::onDidFinishRenderingMap); }
|
||||
|
||||
void onStyleImageMissing(const std::string& id, Scheduler::Task&& done) override {
|
||||
delegate.invoke(&RendererObserver::onStyleImageMissing, id, std::move(done));
|
||||
void onStyleImageMissing(const std::string& id, const StyleImageMissingCallback& done) override {
|
||||
delegate.invoke(&RendererObserver::onStyleImageMissing, id, done);
|
||||
}
|
||||
|
||||
void onRemoveUnusedStyleImages(const std::vector<std::string>& ids) override {
|
||||
|
||||
@@ -70,8 +70,7 @@ AssetManagerFileSource::AssetManagerFileSource(jni::JNIEnv& env,
|
||||
|
||||
AssetManagerFileSource::~AssetManagerFileSource() = default;
|
||||
|
||||
std::unique_ptr<AsyncRequest> AssetManagerFileSource::request(const Resource& resource,
|
||||
std::function<void(Response)> callback) {
|
||||
std::unique_ptr<AsyncRequest> AssetManagerFileSource::request(const Resource& resource, Callback callback) {
|
||||
auto req = std::make_unique<FileSourceRequest>(std::move(callback));
|
||||
|
||||
impl->actor().invoke(&Impl::request, resource.url, req->actor());
|
||||
@@ -80,7 +79,7 @@ std::unique_ptr<AsyncRequest> AssetManagerFileSource::request(const Resource& re
|
||||
}
|
||||
|
||||
bool AssetManagerFileSource::canRequest(const Resource& resource) const {
|
||||
return resource.url.starts_with(mbgl::util::ASSET_PROTOCOL);
|
||||
return 0 == resource.url.rfind(mbgl::util::ASSET_PROTOCOL, 0);
|
||||
}
|
||||
|
||||
void AssetManagerFileSource::setResourceOptions(ResourceOptions options) {
|
||||
|
||||
@@ -23,7 +23,7 @@ public:
|
||||
const ClientOptions);
|
||||
~AssetManagerFileSource() override;
|
||||
|
||||
std::unique_ptr<AsyncRequest> request(const Resource&, std::function<void(Response)>) override;
|
||||
std::unique_ptr<AsyncRequest> request(const Resource&, Callback) override;
|
||||
bool canRequest(const Resource&) const override;
|
||||
|
||||
void setResourceOptions(ResourceOptions options) override;
|
||||
|
||||
@@ -30,13 +30,13 @@ FileSource::FileSource(jni::JNIEnv& _env,
|
||||
|
||||
mbgl::FileSourceManager::get()->registerFileSourceFactory(
|
||||
mbgl::FileSourceType::Asset,
|
||||
[](const mbgl::ResourceOptions& resourceOptions_, const mbgl::ClientOptions& clientOptions_) {
|
||||
[](const mbgl::ResourceOptions& resourceOptions, const mbgl::ClientOptions& clientOptions) {
|
||||
auto env{android::AttachEnv()};
|
||||
std::unique_ptr<mbgl::FileSource> assetFileSource;
|
||||
if (android::MapLibre::hasInstance(*env)) {
|
||||
auto assetManager = android::MapLibre::getAssetManager(*env);
|
||||
assetFileSource = std::make_unique<AssetManagerFileSource>(
|
||||
*env, assetManager, resourceOptions_.clone(), clientOptions_.clone());
|
||||
*env, assetManager, resourceOptions.clone(), clientOptions.clone());
|
||||
}
|
||||
return assetFileSource;
|
||||
});
|
||||
@@ -161,7 +161,7 @@ void FileSource::setResourceCachePath(jni::JNIEnv& env,
|
||||
pathChangeCallback = {};
|
||||
});
|
||||
|
||||
databaseSource->setDatabasePath(newPath + DATABASE_FILE, std::move(pathChangeCallback));
|
||||
databaseSource->setDatabasePath(newPath + DATABASE_FILE, pathChangeCallback);
|
||||
}
|
||||
|
||||
void FileSource::resume(jni::JNIEnv&) {
|
||||
|
||||
@@ -93,7 +93,7 @@ private:
|
||||
mbgl::ResourceOptions resourceOptions;
|
||||
mbgl::ClientOptions clientOptions;
|
||||
std::unique_ptr<Actor<ResourceTransform::TransformCallback>> resourceTransform;
|
||||
std23::move_only_function<void()> pathChangeCallback;
|
||||
std::function<void()> pathChangeCallback;
|
||||
std::shared_ptr<mbgl::DatabaseFileSource> databaseSource;
|
||||
std::shared_ptr<mbgl::FileSource> onlineSource;
|
||||
std::shared_ptr<mbgl::FileSource> resourceLoader;
|
||||
|
||||
@@ -39,8 +39,8 @@ class HTTPRequest : public AsyncRequest {
|
||||
public:
|
||||
static constexpr auto Name() { return "org/maplibre/android/http/NativeHttpRequest"; };
|
||||
|
||||
HTTPRequest(jni::JNIEnv&, const Resource&, std::function<void(Response)>);
|
||||
~HTTPRequest() override;
|
||||
HTTPRequest(jni::JNIEnv&, const Resource&, FileSource::Callback);
|
||||
~HTTPRequest();
|
||||
|
||||
void onFailure(jni::JNIEnv&, int type, const jni::String& message);
|
||||
void onResponse(jni::JNIEnv&,
|
||||
@@ -57,7 +57,7 @@ public:
|
||||
|
||||
private:
|
||||
Resource resource;
|
||||
std::function<void(Response)> callback;
|
||||
FileSource::Callback callback;
|
||||
Response response;
|
||||
|
||||
util::AsyncTask async{[this] {
|
||||
@@ -88,9 +88,9 @@ void RegisterNativeHTTPRequest(jni::JNIEnv& env) {
|
||||
|
||||
} // namespace android
|
||||
|
||||
HTTPRequest::HTTPRequest(jni::JNIEnv& env, const Resource& resource_, std::function<void(Response)> callback_)
|
||||
HTTPRequest::HTTPRequest(jni::JNIEnv& env, const Resource& resource_, FileSource::Callback callback_)
|
||||
: resource(resource_),
|
||||
callback(std::move(callback_)) {
|
||||
callback(callback_) {
|
||||
std::string dataRangeStr;
|
||||
std::string etagStr;
|
||||
std::string modifiedStr;
|
||||
@@ -152,7 +152,7 @@ void HTTPRequest::onResponse(jni::JNIEnv& env,
|
||||
}
|
||||
|
||||
if (cacheControl) {
|
||||
const auto cc = http::CacheControl::parse(jni::Make<std::string>(env, cacheControl));
|
||||
const auto cc = http::CacheControl::parse(jni::Make<std::string>(env, cacheControl).c_str());
|
||||
response.expires = cc.toTimePoint();
|
||||
response.mustRevalidate = cc.mustRevalidate;
|
||||
}
|
||||
@@ -164,7 +164,7 @@ void HTTPRequest::onResponse(jni::JNIEnv& env,
|
||||
if (code == 200 || code == 206) {
|
||||
if (body) {
|
||||
auto data = std::make_shared<std::string>(body.Length(env), char());
|
||||
jni::GetArrayRegion(env, *body, 0, data->size(), reinterpret_cast<jbyte*>(data->data()));
|
||||
jni::GetArrayRegion(env, *body, 0, data->size(), reinterpret_cast<jbyte*>(&(*data)[0]));
|
||||
response.data = data;
|
||||
} else {
|
||||
response.data = std::make_shared<std::string>();
|
||||
@@ -221,9 +221,8 @@ HTTPFileSource::HTTPFileSource(const ResourceOptions& resourceOptions, const Cli
|
||||
|
||||
HTTPFileSource::~HTTPFileSource() = default;
|
||||
|
||||
std::unique_ptr<AsyncRequest> HTTPFileSource::request(const Resource& resource,
|
||||
std::function<void(Response)> callback) {
|
||||
return std::make_unique<HTTPRequest>(*impl->env, resource, std::move(callback));
|
||||
std::unique_ptr<AsyncRequest> HTTPFileSource::request(const Resource& resource, Callback callback) {
|
||||
return std::make_unique<HTTPRequest>(*impl->env, resource, callback);
|
||||
}
|
||||
|
||||
void HTTPFileSource::setResourceOptions(ResourceOptions options) {
|
||||
|
||||
@@ -63,7 +63,7 @@ ActorRef<Renderer> MapRenderer::actor() const {
|
||||
return *rendererRef;
|
||||
}
|
||||
|
||||
void MapRenderer::schedule(Task&& scheduled) {
|
||||
void MapRenderer::schedule(std::function<void()>&& scheduled) {
|
||||
MLN_TRACE_FUNC();
|
||||
try {
|
||||
// Create a runnable
|
||||
|
||||
@@ -72,8 +72,8 @@ public:
|
||||
|
||||
// From Scheduler. Schedules by using callbacks to the
|
||||
// JVM to process the mailbox on the right thread.
|
||||
void schedule(Task&& scheduled) override;
|
||||
void schedule(const util::SimpleIdentity, Task&& fn) override { schedule(std::move(fn)); };
|
||||
void schedule(std::function<void()>&& scheduled) override;
|
||||
void schedule(const util::SimpleIdentity, std::function<void()>&& fn) override { schedule(std::move(fn)); };
|
||||
|
||||
mapbox::base::WeakPtr<Scheduler> makeWeakPtr() override { return weakFactory.makeWeakPtr(); }
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
namespace mbgl {
|
||||
namespace android {
|
||||
|
||||
MapRendererRunnable::MapRendererRunnable(jni::JNIEnv& env, Scheduler::Task&& function_)
|
||||
MapRendererRunnable::MapRendererRunnable(jni::JNIEnv& env, std::function<void()> function_)
|
||||
: function(std::move(function_)) {
|
||||
// Create the Java peer and hold on to a global reference
|
||||
// Not using a weak reference here as this might oerflow
|
||||
|
||||
@@ -23,7 +23,7 @@ public:
|
||||
|
||||
static void registerNative(jni::JNIEnv&);
|
||||
|
||||
MapRendererRunnable(jni::JNIEnv&, Scheduler::Task&&);
|
||||
MapRendererRunnable(jni::JNIEnv&, std::function<void()>);
|
||||
|
||||
// Only for jni registration, unused
|
||||
MapRendererRunnable(jni::JNIEnv&) { assert(false); }
|
||||
@@ -37,7 +37,7 @@ public:
|
||||
|
||||
private:
|
||||
jni::Global<jni::Object<MapRendererRunnable>> javaPeer;
|
||||
Scheduler::Task function;
|
||||
std::function<void()> function;
|
||||
};
|
||||
|
||||
} // namespace android
|
||||
|
||||
Reference in New Issue
Block a user