diff options
Diffstat (limited to 'platform/android/src/style/layers/custom_layer.cpp')
-rw-r--r-- | platform/android/src/style/layers/custom_layer.cpp | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/platform/android/src/style/layers/custom_layer.cpp b/platform/android/src/style/layers/custom_layer.cpp new file mode 100644 index 0000000000..4be6f3800d --- /dev/null +++ b/platform/android/src/style/layers/custom_layer.cpp @@ -0,0 +1,57 @@ +#include "custom_layer.hpp" + +#include <string> + +#include <mbgl/platform/log.hpp> + +namespace mbgl { +namespace android { + + CustomLayer::CustomLayer(jni::JNIEnv& env, jni::String layerId, jni::jlong initializeFunction, jni::jlong renderFunction, jni::jlong deinitializeFunction, jni::jlong context) + : Layer(env, std::make_unique<mbgl::style::CustomLayer>( + jni::Make<std::string>(env, layerId), + reinterpret_cast<mbgl::style::CustomLayerInitializeFunction>(initializeFunction), + reinterpret_cast<mbgl::style::CustomLayerRenderFunction>(renderFunction), + reinterpret_cast<mbgl::style::CustomLayerDeinitializeFunction>(deinitializeFunction), + reinterpret_cast<void*>(context)) + ) { + } + + CustomLayer::CustomLayer(mbgl::Map& map, mbgl::style::CustomLayer& coreLayer) + : Layer(map, coreLayer) { + } + + CustomLayer::~CustomLayer() = default; + + void CustomLayer::update(jni::JNIEnv&) { + if (map) { + map->update(mbgl::Update::Repaint); + } else { + Log::Error(mbgl::Event::JNI, "No map reference, cannot update"); + } + } + + jni::Class<CustomLayer> CustomLayer::javaClass; + + jni::jobject* CustomLayer::createJavaPeer(jni::JNIEnv& env) { + static auto constructor = CustomLayer::javaClass.template GetConstructor<jni::jlong>(env); + return CustomLayer::javaClass.New(env, constructor, reinterpret_cast<jni::jlong>(this)); + } + + void CustomLayer::registerNative(jni::JNIEnv& env) { + //Lookup the class + CustomLayer::javaClass = *jni::Class<CustomLayer>::Find(env).NewGlobalRef(env).release(); + + #define METHOD(MethodPtr, name) jni::MakeNativePeerMethod<decltype(MethodPtr), (MethodPtr)>(name) + + //Register the peer + jni::RegisterNativePeer<CustomLayer>( + env, CustomLayer::javaClass, "nativePtr", + std::make_unique<CustomLayer, JNIEnv&, jni::String, jni::jlong, jni::jlong, jni::jlong, jni::jlong>, + "initialize", + "finalize", + METHOD(&CustomLayer::update, "nativeUpdate")); + } + +} // namespace android +} // namespace mbgl |