Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support asset imports in bundles #9

Merged
merged 7 commits into from
Oct 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,9 @@ endif()
if(ANDROID)
add_subdirectory(android)
endif()

if(PROJECT_IS_TOP_LEVEL)
enable_testing()

add_subdirectory(test)
endif()
2 changes: 1 addition & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ android {
externalNativeBuild {
cmake {
targets "bare_kit"
arguments "-DCMAKE_MODULE_PATH=$System.env.CMAKE_MODULE_PATH", "-DANDROID_STL=none"
arguments "-DCMAKE_MODULE_PATH=$System.env.CMAKE_MODULE_PATH", "-DANDROID_STL=c++_shared"
}
}
}
Expand Down
11 changes: 9 additions & 2 deletions android/src/main/java/to/holepunch/bare/kit/Worklet.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,19 @@ private interface NativePushCallback {

public static class Options {
public int memoryLimit = 0;
public String assets = null;

public Options
memoryLimit (int memoryLimit) {
this.memoryLimit = memoryLimit;
return this;
}

public Options
assets (String assets) {
this.assets = assets;
return this;
}
}

private ByteBuffer handle;
Expand All @@ -46,13 +53,13 @@ public static class Options {
public Worklet(Options options) {
if (options == null) options = new Options();

handle = init(options.memoryLimit);
handle = init(options.memoryLimit, options.assets);

handler = Handler.createAsync(Looper.getMainLooper());
}

private native ByteBuffer
init (int memoryLimit);
init (int memoryLimit, String assets);

private native void
start (ByteBuffer handle, String filename, ByteBuffer source, int len, String[] arguments);
Expand Down
18 changes: 14 additions & 4 deletions android/src/main/jni/Worklet.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,28 @@ typedef struct {
} bare_worklet_push_context_t;

JNIEXPORT jobject JNICALL
Java_to_holepunch_bare_kit_Worklet_init (JNIEnv *env, jobject self, jint jmemory_limit) {
Java_to_holepunch_bare_kit_Worklet_init (JNIEnv *env, jobject self, jint jmemory_limit, jobject jassets) {
int err;

bare_worklet_t *worklet = malloc(sizeof(bare_worklet_t));

bare_worklet_options_t options = {
.memory_limit = (int) jmemory_limit,
};
bare_worklet_options_t options;

options.memory_limit = (int) jmemory_limit;

if ((*env)->IsSameObject(env, jassets, NULL)) {
options.assets = NULL;
} else {
options.assets = (*env)->GetStringUTFChars(env, jassets, NULL);
}

err = bare_worklet_init(worklet, &options);
assert(err == 0);

if (options.assets) {
(*env)->ReleaseStringUTFChars(env, jassets, options.assets);
}

jobject handle = (*env)->NewDirectByteBuffer(env, (void *) worklet, sizeof(bare_worklet_t));

return handle;
Expand Down
1 change: 1 addition & 0 deletions apple/BareKit/BareKit.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
@interface BareWorkletConfiguration : NSObject

@property NSUInteger memoryLimit;
@property(nullable, copy) NSString *assets;

+ (BareWorkletConfiguration *_Nullable)defaultWorkletConfiguration;

Expand Down
3 changes: 3 additions & 0 deletions apple/BareKit/BareKit.m
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ - (_Nullable instancetype)init {

if (self) {
_memoryLimit = 0;
_assets = nil;
}

return self;
Expand All @@ -118,8 +119,10 @@ - (_Nullable instancetype)initWithConfiguration:(BareWorkletConfiguration *_Null

if (options) {
_options.memory_limit = options.memoryLimit;
_options.assets = [options.assets UTF8String];
} else {
_options.memory_limit = 0;
_options.assets = nil;
}

int err;
Expand Down
Loading
Loading