のねのBlog

パソコンやソフト開発で起きた問題など書きます。よろしくお願いします。

NewWithProc

    166     SkAutoTUnref<SkData> data(SkData::NewWithProc(fontPtr, fontSize,
    167             release_global_ref, reinterpret_cast<void*>(fontRef)));

Cross Reference: /frameworks/base/core/jni/android/graphics/FontFamily.cpp

    106 SkData* SkData::NewWithProc(
            const void* ptr,
            size_t length,
            ReleaseProc proc,
            void* context) {
    107     return new SkData(ptr, length, proc, context);
    108 }

Cross Reference: /external/skia/src/core/SkData.cpp

     15 SkData::SkData(const void* ptr, size_t size, ReleaseProc proc, void* context) {
     16     fPtr = const_cast<void*>(ptr);
     17     fSize = size;
     18     fReleaseProc = proc;
     19     fReleaseProcContext = context;
     20 }

Cross Reference: /external/skia/src/core/SkData.cpp

     33 SkData::~SkData() {
     34     if (fReleaseProc) {
     35         fReleaseProc(fPtr, fReleaseProcContext);
     36     }
     37 }
     38 

Cross Reference: /external/skia/src/core/SkData.cpp

     64 static void release_global_ref(const void* /*data*/, void* context) {
     65     JNIEnv* env = AndroidRuntime::getJNIEnv();
     66     bool needToAttach = (env == NULL);
     67     if (needToAttach) {
     68         JavaVMAttachArgs args;
     69         args.version = JNI_VERSION_1_4;
     70         args.name = "release_font_data";
     71         args.group = NULL;
     72         jint result = AndroidRuntime::getJavaVM()->AttachCurrentThread(&env, &args);
     73         if (result != JNI_OK) {
     74             ALOGE("failed to attach to thread to release global ref.");
     75             return;
     76         }
     77     }
     78 
     79     jobject obj = reinterpret_cast<jobject>(context);
     80     env->DeleteGlobalRef(obj);
     81 
     82     if (needToAttach) {
     83        AndroidRuntime::getJavaVM()->DetachCurrentThread();
     84     }
     85 }

Cross Reference: /frameworks/base/core/jni/android/graphics/FontFamily.cpp

  165     jobject fontRef = MakeGlobalRefOrDie(env, font);

Cross Reference: /frameworks/base/core/jni/android/graphics/FontFamily.cpp

     61 template <typename T>
     62 static inline T MakeGlobalRefOrDie(JNIEnv* env, T in) {
     63     jobject res = env->NewGlobalRef(in);
     64     LOG_ALWAYS_FATAL_IF(res == NULL, "Unable to create global reference.");
     65     return static_cast<T>(res);
     66 }

Cross Reference: /frameworks/base/core/jni/core_jni_helpers.h