From 14c87e7b3822a3f1d20b0e3cfd3e609171cb888f Mon Sep 17 00:00:00 2001 From: Nick Fisher Date: Mon, 17 Jun 2024 11:30:03 +0800 Subject: [PATCH] Flutter/Android - create local copy of headers --- .../thermion_flutter/android/CMakeLists.txt | 2 +- .../src/main/cpp/ThermionFlutterAndroid.cpp | 5 ++- .../android/src/main/include/ResourceBuffer.h | 44 +++++++++++++++++++ .../thermion_flutter/pubspec.yaml | 2 +- 4 files changed, 50 insertions(+), 3 deletions(-) create mode 100644 thermion_flutter/thermion_flutter/android/src/main/include/ResourceBuffer.h diff --git a/thermion_flutter/thermion_flutter/android/CMakeLists.txt b/thermion_flutter/thermion_flutter/android/CMakeLists.txt index ed93328d..e97c7290 100644 --- a/thermion_flutter/thermion_flutter/android/CMakeLists.txt +++ b/thermion_flutter/thermion_flutter/android/CMakeLists.txt @@ -1,6 +1,6 @@ cmake_minimum_required(VERSION 3.10) -include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../../../thermion_dart/native/include) +include_directories(src/main/include) include_directories(src/main/cpp) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17") set(ANDROID_STL c++_shared) diff --git a/thermion_flutter/thermion_flutter/android/src/main/cpp/ThermionFlutterAndroid.cpp b/thermion_flutter/thermion_flutter/android/src/main/cpp/ThermionFlutterAndroid.cpp index 84938776..91e84f4d 100644 --- a/thermion_flutter/thermion_flutter/android/src/main/cpp/ThermionFlutterAndroid.cpp +++ b/thermion_flutter/thermion_flutter/android/src/main/cpp/ThermionFlutterAndroid.cpp @@ -1,9 +1,12 @@ #include #include -#include "ThermionDartFFIApi.h" +#include "ResourceBuffer.h" extern "C" { + + typedef void (*FilamentRenderCallback)(void *const owner); + void* get_native_window_from_surface( jobject surface, JNIEnv* env diff --git a/thermion_flutter/thermion_flutter/android/src/main/include/ResourceBuffer.h b/thermion_flutter/thermion_flutter/android/src/main/include/ResourceBuffer.h new file mode 100644 index 00000000..eab0ee0d --- /dev/null +++ b/thermion_flutter/thermion_flutter/android/src/main/include/ResourceBuffer.h @@ -0,0 +1,44 @@ +#ifndef RESOURCE_BUFFER_H +#define RESOURCE_BUFFER_H + +#include +#include + +// +// A ResourceBuffer is a unified interface for working with +// binary assets across various platforms. +// This is simply: +// 1) a pointer to some data +// 2) the length of the data +// 3) an ID that can be passed back to the native platform to release the underlying asset when needed. +// +typedef struct ResourceBuffer +{ + const void *const data; + const int32_t size; + const int32_t id; + +#if defined(__cplusplus) + ResourceBuffer(void *const data, int32_t size, int32_t id) : data(data), size(size), id(id) {} +#endif +} ResourceBuffer; + +typedef void (*LoadFilamentResourceIntoOutPointer)(const char *uri, ResourceBuffer *out); +typedef ResourceBuffer (*LoadFilamentResource)(const char *uri); +typedef ResourceBuffer (*LoadFilamentResourceFromOwner)(const char *const, void *const owner); +typedef void (*FreeFilamentResource)(ResourceBuffer); +typedef void (*FreeFilamentResourceFromOwner)(ResourceBuffer, void *const owner); + +typedef struct ResourceLoaderWrapper +{ + LoadFilamentResource loadResource; + FreeFilamentResource freeResource; + LoadFilamentResourceFromOwner loadFromOwner; + FreeFilamentResourceFromOwner freeFromOwner; + void *owner; + LoadFilamentResourceIntoOutPointer loadToOut; +} ResourceLoaderWrapper; + +void *make_resource_loader(LoadFilamentResourceFromOwner loadFn, FreeFilamentResourceFromOwner freeFn, void *const owner); + +#endif diff --git a/thermion_flutter/thermion_flutter/pubspec.yaml b/thermion_flutter/thermion_flutter/pubspec.yaml index ec18a1e8..cf1b22f2 100644 --- a/thermion_flutter/thermion_flutter/pubspec.yaml +++ b/thermion_flutter/thermion_flutter/pubspec.yaml @@ -1,6 +1,6 @@ name: thermion_flutter description: Flutter plugin for 3D rendering with the Thermion toolkit. -version: 0.0.2 +version: 0.0.3 homepage: https://docs.page/nmfisher/thermion repository: https://github.com/nmfisher/thermion