Advertisement
Guest User

Untitled

a guest
Jun 16th, 2020
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.17 KB | None | 0 0
  1. #include <map>
  2. #include <jni.h>
  3. #include <string>
  4. #include <android/asset_manager.h>
  5. #include <android/asset_manager_jni.h>
  6. #define NANOVG_GLES2_IMPLEMENTATION
  7. #include "context.hpp"
  8. #include "engine.hpp"
  9. #include "utils.hpp"
  10.  
  11. std::unique_ptr<Engine> engine;
  12. std::map<int, Context*> contexts;
  13. AAssetManager *assetManager = nullptr;
  14.  
  15. JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM* vm, void* reserved) {
  16.     engine = std::unique_ptr<Engine>(new Engine);
  17.     return  JNI_VERSION_1_6;
  18. }
  19.  
  20. extern "C" JNIEXPORT void JNICALL Java_com_engune_livewall_common_Engine_nativeOnCreateEngine(JNIEnv* env, jclass obj, jobject context, jobject assetMgr)
  21. {
  22.     if (assetManager == nullptr) {
  23.         assetManager = AAssetManager_fromJava(env, assetMgr);
  24.     }
  25. }
  26.  
  27. ....
  28.  
  29. bool LoadFile(const char *filePath, char **buffer, int &size) {
  30.     size = 0;
  31.     *buffer = nullptr;
  32.  
  33.     AAsset *asset = AAssetManager_open(assetManager, filePath, AASSET_MODE_UNKNOWN);
  34.  
  35.     if (asset == nullptr)
  36.         return false;
  37.  
  38.     size = (int) AAsset_getLength(asset);
  39.     *buffer = (char *) malloc (size);
  40.     AAsset_read (asset, buffer, (size_t) size);
  41.     AAsset_close(asset);
  42.  
  43.     return true;
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement