Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <map>
- #include <jni.h>
- #include <string>
- #include <android/asset_manager.h>
- #include <android/asset_manager_jni.h>
- #define NANOVG_GLES2_IMPLEMENTATION
- #include "context.hpp"
- #include "engine.hpp"
- #include "utils.hpp"
- std::unique_ptr<Engine> engine;
- std::map<int, Context*> contexts;
- AAssetManager *assetManager = nullptr;
- JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM* vm, void* reserved) {
- engine = std::unique_ptr<Engine>(new Engine);
- return JNI_VERSION_1_6;
- }
- extern "C" JNIEXPORT void JNICALL Java_com_engune_livewall_common_Engine_nativeOnCreateEngine(JNIEnv* env, jclass obj, jobject context, jobject assetMgr)
- {
- if (assetManager == nullptr) {
- assetManager = AAssetManager_fromJava(env, assetMgr);
- }
- }
- ....
- bool LoadFile(const char *filePath, char **buffer, int &size) {
- size = 0;
- *buffer = nullptr;
- AAsset *asset = AAssetManager_open(assetManager, filePath, AASSET_MODE_UNKNOWN);
- if (asset == nullptr)
- return false;
- size = (int) AAsset_getLength(asset);
- *buffer = (char *) malloc (size);
- AAsset_read (asset, buffer, (size_t) size);
- AAsset_close(asset);
- return true;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement