From 7ae941ad52de7cf30a0a552f5a3596e9869cd9e9 Mon Sep 17 00:00:00 2001 From: Marc Rousavy Date: Wed, 21 Feb 2024 11:24:12 +0100 Subject: [PATCH] fix generics --- .../android/src/main/cpp/AndroidFilamentProxy.h | 2 +- package/android/src/main/cpp/AndroidSurface.h | 2 +- package/android/src/main/cpp/JNISharedPtr.cpp | 11 ----------- package/android/src/main/cpp/JNISharedPtr.h | 15 +++++++++++++-- package/cpp/FilamentProxy.h | 3 --- package/cpp/FilamentView.h | 3 --- package/cpp/Surface.h | 2 -- 7 files changed, 15 insertions(+), 23 deletions(-) diff --git a/package/android/src/main/cpp/AndroidFilamentProxy.h b/package/android/src/main/cpp/AndroidFilamentProxy.h index 6266c524..5d64b0b0 100644 --- a/package/android/src/main/cpp/AndroidFilamentProxy.h +++ b/package/android/src/main/cpp/AndroidFilamentProxy.h @@ -19,7 +19,7 @@ using namespace facebook; class AndroidFilamentProxy : public FilamentProxy { public: explicit AndroidFilamentProxy(jni::alias_ref filamentProxy); - ~AndroidFilamentProxy() override; + ~AndroidFilamentProxy(); private: // TODO(hanno): implement diff --git a/package/android/src/main/cpp/AndroidSurface.h b/package/android/src/main/cpp/AndroidSurface.h index 34329ead..26f3d3cc 100644 --- a/package/android/src/main/cpp/AndroidSurface.h +++ b/package/android/src/main/cpp/AndroidSurface.h @@ -19,7 +19,7 @@ using namespace facebook; class AndroidSurface : public Surface { public: explicit AndroidSurface(jni::alias_ref javaSurface); - ~AndroidSurface() override; + ~AndroidSurface(); void* getSurface() override; int getWidth() override; diff --git a/package/android/src/main/cpp/JNISharedPtr.cpp b/package/android/src/main/cpp/JNISharedPtr.cpp index f2b63783..5ac16c78 100644 --- a/package/android/src/main/cpp/JNISharedPtr.cpp +++ b/package/android/src/main/cpp/JNISharedPtr.cpp @@ -6,16 +6,5 @@ namespace margelo { -void GlobalRefDeleter::operator()(jni::global_ref* ref) { - if (ref) { - ref->release(); - delete ref; - } -} - -template , T>::value>::type*> -std::shared_ptr JNISharedPtr::make_shared_from_jni(jni::global_ref ref) { - return std::shared_ptr(ref->cthis(), GlobalRefDeleter{}); -} } // namespace margelo \ No newline at end of file diff --git a/package/android/src/main/cpp/JNISharedPtr.h b/package/android/src/main/cpp/JNISharedPtr.h index 5339cfa7..62b1bf64 100644 --- a/package/android/src/main/cpp/JNISharedPtr.h +++ b/package/android/src/main/cpp/JNISharedPtr.h @@ -11,14 +11,25 @@ namespace margelo { using namespace facebook; +template struct GlobalRefDeleter { - void operator()(jni::global_ref* ref); + explicit GlobalRefDeleter(jni::global_ref ref): _ref(ref) {} + + void operator()(T* _) { + if (_ref) { + _ref.release(); + } + } +private: + jni::global_ref _ref; }; class JNISharedPtr { public: template , T>::value>::type* = nullptr> - static std::shared_ptr make_shared_from_jni(jni::global_ref ref); + static std::shared_ptr make_shared_from_jni(jni::global_ref ref) { + return std::shared_ptr(ref->cthis(), GlobalRefDeleter {ref}); + } }; } // namespace margelo diff --git a/package/cpp/FilamentProxy.h b/package/cpp/FilamentProxy.h index 0a38016e..29c6a5b3 100644 --- a/package/cpp/FilamentProxy.h +++ b/package/cpp/FilamentProxy.h @@ -16,9 +16,6 @@ namespace margelo { using namespace facebook; class FilamentProxy : public jsi::HostObject { -public: - virtual ~FilamentProxy() = 0; - private: virtual int loadModel(const std::string& path) = 0; virtual std::shared_ptr findFilamentView(int id) = 0; diff --git a/package/cpp/FilamentView.h b/package/cpp/FilamentView.h index e517038b..7d0362b3 100644 --- a/package/cpp/FilamentView.h +++ b/package/cpp/FilamentView.h @@ -15,9 +15,6 @@ namespace margelo { using namespace facebook; class FilamentView { -public: - virtual ~FilamentView() = 0; - public: virtual const SurfaceProvider& getSurfaceProvider() = 0; }; diff --git a/package/cpp/Surface.h b/package/cpp/Surface.h index c152d7dc..69a0fdbe 100644 --- a/package/cpp/Surface.h +++ b/package/cpp/Surface.h @@ -11,8 +11,6 @@ namespace margelo { class Surface { public: - virtual ~Surface() = 0; - /** * Returns the surface ("native window") that can be used as a render target. * On Android, this is a `ANativeWindow*`, on iOS it is a `CAMetalLayer*`.