Home | History | Annotate | Download | only in graphics
      1 #define LOG_TAG "GraphicsJNI"
      2 
      3 #include "jni.h"
      4 #include "JNIHelp.h"
      5 #include "GraphicsJNI.h"
      6 
      7 #include "SkCanvas.h"
      8 #include "SkDevice.h"
      9 #include "SkPicture.h"
     10 #include "SkRegion.h"
     11 #include <android_runtime/AndroidRuntime.h>
     12 
     13 void doThrowNPE(JNIEnv* env) {
     14     jniThrowNullPointerException(env, NULL);
     15 }
     16 
     17 void doThrowAIOOBE(JNIEnv* env) {
     18     jniThrowException(env, "java/lang/ArrayIndexOutOfBoundsException", NULL);
     19 }
     20 
     21 void doThrowRE(JNIEnv* env, const char* msg) {
     22     jniThrowRuntimeException(env, msg);
     23 }
     24 
     25 void doThrowIAE(JNIEnv* env, const char* msg) {
     26     jniThrowException(env, "java/lang/IllegalArgumentException", msg);
     27 }
     28 
     29 void doThrowISE(JNIEnv* env, const char* msg) {
     30     jniThrowException(env, "java/lang/IllegalStateException", msg);
     31 }
     32 
     33 void doThrowOOME(JNIEnv* env, const char* msg) {
     34     jniThrowException(env, "java/lang/OutOfMemoryError", msg);
     35 }
     36 
     37 void doThrowIOE(JNIEnv* env, const char* msg) {
     38     jniThrowException(env, "java/io/IOException", msg);
     39 }
     40 
     41 bool GraphicsJNI::hasException(JNIEnv *env) {
     42     if (env->ExceptionCheck() != 0) {
     43         LOGE("*** Uncaught exception returned from Java call!\n");
     44         env->ExceptionDescribe();
     45         return true;
     46     }
     47     return false;
     48 }
     49 
     50 ///////////////////////////////////////////////////////////////////////////////
     51 
     52 AutoJavaFloatArray::AutoJavaFloatArray(JNIEnv* env, jfloatArray array,
     53                                        int minLength, JNIAccess access)
     54 : fEnv(env), fArray(array), fPtr(NULL), fLen(0) {
     55     SkASSERT(env);
     56     if (array) {
     57         fLen = env->GetArrayLength(array);
     58         if (fLen < minLength) {
     59             sk_throw();
     60         }
     61         fPtr = env->GetFloatArrayElements(array, NULL);
     62     }
     63     fReleaseMode = (access == kRO_JNIAccess) ? JNI_ABORT : 0;
     64 }
     65 
     66 AutoJavaFloatArray::~AutoJavaFloatArray() {
     67     if (fPtr) {
     68         fEnv->ReleaseFloatArrayElements(fArray, fPtr, fReleaseMode);
     69     }
     70 }
     71 
     72 AutoJavaIntArray::AutoJavaIntArray(JNIEnv* env, jintArray array,
     73                                        int minLength)
     74 : fEnv(env), fArray(array), fPtr(NULL), fLen(0) {
     75     SkASSERT(env);
     76     if (array) {
     77         fLen = env->GetArrayLength(array);
     78         if (fLen < minLength) {
     79             sk_throw();
     80         }
     81         fPtr = env->GetIntArrayElements(array, NULL);
     82     }
     83 }
     84 
     85 AutoJavaIntArray::~AutoJavaIntArray() {
     86     if (fPtr) {
     87         fEnv->ReleaseIntArrayElements(fArray, fPtr, 0);
     88     }
     89 }
     90 
     91 AutoJavaShortArray::AutoJavaShortArray(JNIEnv* env, jshortArray array,
     92                                        int minLength, JNIAccess access)
     93 : fEnv(env), fArray(array), fPtr(NULL), fLen(0) {
     94     SkASSERT(env);
     95     if (array) {
     96         fLen = env->GetArrayLength(array);
     97         if (fLen < minLength) {
     98             sk_throw();
     99         }
    100         fPtr = env->GetShortArrayElements(array, NULL);
    101     }
    102     fReleaseMode = (access == kRO_JNIAccess) ? JNI_ABORT : 0;
    103 }
    104 
    105 AutoJavaShortArray::~AutoJavaShortArray() {
    106     if (fPtr) {
    107         fEnv->ReleaseShortArrayElements(fArray, fPtr, fReleaseMode);
    108     }
    109 }
    110 
    111 AutoJavaByteArray::AutoJavaByteArray(JNIEnv* env, jbyteArray array,
    112                                        int minLength)
    113 : fEnv(env), fArray(array), fPtr(NULL), fLen(0) {
    114     SkASSERT(env);
    115     if (array) {
    116         fLen = env->GetArrayLength(array);
    117         if (fLen < minLength) {
    118             sk_throw();
    119         }
    120         fPtr = env->GetByteArrayElements(array, NULL);
    121     }
    122 }
    123 
    124 AutoJavaByteArray::~AutoJavaByteArray() {
    125     if (fPtr) {
    126         fEnv->ReleaseByteArrayElements(fArray, fPtr, 0);
    127     }
    128 }
    129 
    130 ///////////////////////////////////////////////////////////////////////////////
    131 
    132 static jclass   gRect_class;
    133 static jfieldID gRect_leftFieldID;
    134 static jfieldID gRect_topFieldID;
    135 static jfieldID gRect_rightFieldID;
    136 static jfieldID gRect_bottomFieldID;
    137 
    138 static jclass   gRectF_class;
    139 static jfieldID gRectF_leftFieldID;
    140 static jfieldID gRectF_topFieldID;
    141 static jfieldID gRectF_rightFieldID;
    142 static jfieldID gRectF_bottomFieldID;
    143 
    144 static jclass   gPoint_class;
    145 static jfieldID gPoint_xFieldID;
    146 static jfieldID gPoint_yFieldID;
    147 
    148 static jclass   gPointF_class;
    149 static jfieldID gPointF_xFieldID;
    150 static jfieldID gPointF_yFieldID;
    151 
    152 static jclass   gBitmap_class;
    153 static jfieldID gBitmap_nativeInstanceID;
    154 static jmethodID gBitmap_constructorMethodID;
    155 
    156 static jclass   gBitmapConfig_class;
    157 static jfieldID gBitmapConfig_nativeInstanceID;
    158 
    159 static jclass   gBitmapRegionDecoder_class;
    160 static jmethodID gBitmapRegionDecoder_constructorMethodID;
    161 
    162 static jclass   gCanvas_class;
    163 static jfieldID gCanvas_nativeInstanceID;
    164 
    165 static jclass   gPaint_class;
    166 static jfieldID gPaint_nativeInstanceID;
    167 
    168 static jclass   gPicture_class;
    169 static jfieldID gPicture_nativeInstanceID;
    170 
    171 static jclass   gRegion_class;
    172 static jfieldID gRegion_nativeInstanceID;
    173 static jmethodID gRegion_constructorMethodID;
    174 
    175 ///////////////////////////////////////////////////////////////////////////////
    176 
    177 void GraphicsJNI::get_jrect(JNIEnv* env, jobject obj, int* L, int* T, int* R, int* B)
    178 {
    179     SkASSERT(env->IsInstanceOf(obj, gRect_class));
    180 
    181     *L = env->GetIntField(obj, gRect_leftFieldID);
    182     *T = env->GetIntField(obj, gRect_topFieldID);
    183     *R = env->GetIntField(obj, gRect_rightFieldID);
    184     *B = env->GetIntField(obj, gRect_bottomFieldID);
    185 }
    186 
    187 void GraphicsJNI::set_jrect(JNIEnv* env, jobject obj, int L, int T, int R, int B)
    188 {
    189     SkASSERT(env->IsInstanceOf(obj, gRect_class));
    190 
    191     env->SetIntField(obj, gRect_leftFieldID, L);
    192     env->SetIntField(obj, gRect_topFieldID, T);
    193     env->SetIntField(obj, gRect_rightFieldID, R);
    194     env->SetIntField(obj, gRect_bottomFieldID, B);
    195 }
    196 
    197 SkIRect* GraphicsJNI::jrect_to_irect(JNIEnv* env, jobject obj, SkIRect* ir)
    198 {
    199     SkASSERT(env->IsInstanceOf(obj, gRect_class));
    200 
    201     ir->set(env->GetIntField(obj, gRect_leftFieldID),
    202             env->GetIntField(obj, gRect_topFieldID),
    203             env->GetIntField(obj, gRect_rightFieldID),
    204             env->GetIntField(obj, gRect_bottomFieldID));
    205     return ir;
    206 }
    207 
    208 void GraphicsJNI::irect_to_jrect(const SkIRect& ir, JNIEnv* env, jobject obj)
    209 {
    210     SkASSERT(env->IsInstanceOf(obj, gRect_class));
    211 
    212     env->SetIntField(obj, gRect_leftFieldID, ir.fLeft);
    213     env->SetIntField(obj, gRect_topFieldID, ir.fTop);
    214     env->SetIntField(obj, gRect_rightFieldID, ir.fRight);
    215     env->SetIntField(obj, gRect_bottomFieldID, ir.fBottom);
    216 }
    217 
    218 SkRect* GraphicsJNI::jrectf_to_rect(JNIEnv* env, jobject obj, SkRect* r)
    219 {
    220     SkASSERT(env->IsInstanceOf(obj, gRectF_class));
    221 
    222     r->set(SkFloatToScalar(env->GetFloatField(obj, gRectF_leftFieldID)),
    223            SkFloatToScalar(env->GetFloatField(obj, gRectF_topFieldID)),
    224            SkFloatToScalar(env->GetFloatField(obj, gRectF_rightFieldID)),
    225            SkFloatToScalar(env->GetFloatField(obj, gRectF_bottomFieldID)));
    226     return r;
    227 }
    228 
    229 SkRect* GraphicsJNI::jrect_to_rect(JNIEnv* env, jobject obj, SkRect* r)
    230 {
    231     SkASSERT(env->IsInstanceOf(obj, gRect_class));
    232 
    233     r->set(SkIntToScalar(env->GetIntField(obj, gRect_leftFieldID)),
    234            SkIntToScalar(env->GetIntField(obj, gRect_topFieldID)),
    235            SkIntToScalar(env->GetIntField(obj, gRect_rightFieldID)),
    236            SkIntToScalar(env->GetIntField(obj, gRect_bottomFieldID)));
    237     return r;
    238 }
    239 
    240 void GraphicsJNI::rect_to_jrectf(const SkRect& r, JNIEnv* env, jobject obj)
    241 {
    242     SkASSERT(env->IsInstanceOf(obj, gRectF_class));
    243 
    244     env->SetFloatField(obj, gRectF_leftFieldID, SkScalarToFloat(r.fLeft));
    245     env->SetFloatField(obj, gRectF_topFieldID, SkScalarToFloat(r.fTop));
    246     env->SetFloatField(obj, gRectF_rightFieldID, SkScalarToFloat(r.fRight));
    247     env->SetFloatField(obj, gRectF_bottomFieldID, SkScalarToFloat(r.fBottom));
    248 }
    249 
    250 SkIPoint* GraphicsJNI::jpoint_to_ipoint(JNIEnv* env, jobject obj, SkIPoint* point)
    251 {
    252     SkASSERT(env->IsInstanceOf(obj, gPoint_class));
    253 
    254     point->set(env->GetIntField(obj, gPoint_xFieldID),
    255                env->GetIntField(obj, gPoint_yFieldID));
    256     return point;
    257 }
    258 
    259 void GraphicsJNI::ipoint_to_jpoint(const SkIPoint& ir, JNIEnv* env, jobject obj)
    260 {
    261     SkASSERT(env->IsInstanceOf(obj, gPoint_class));
    262 
    263     env->SetIntField(obj, gPoint_xFieldID, ir.fX);
    264     env->SetIntField(obj, gPoint_yFieldID, ir.fY);
    265 }
    266 
    267 SkPoint* GraphicsJNI::jpointf_to_point(JNIEnv* env, jobject obj, SkPoint* point)
    268 {
    269     SkASSERT(env->IsInstanceOf(obj, gPointF_class));
    270 
    271     point->set(SkFloatToScalar(env->GetIntField(obj, gPointF_xFieldID)),
    272                SkFloatToScalar(env->GetIntField(obj, gPointF_yFieldID)));
    273     return point;
    274 }
    275 
    276 void GraphicsJNI::point_to_jpointf(const SkPoint& r, JNIEnv* env, jobject obj)
    277 {
    278     SkASSERT(env->IsInstanceOf(obj, gPointF_class));
    279 
    280     env->SetFloatField(obj, gPointF_xFieldID, SkScalarToFloat(r.fX));
    281     env->SetFloatField(obj, gPointF_yFieldID, SkScalarToFloat(r.fY));
    282 }
    283 
    284 SkBitmap* GraphicsJNI::getNativeBitmap(JNIEnv* env, jobject bitmap) {
    285     SkASSERT(env);
    286     SkASSERT(bitmap);
    287     SkASSERT(env->IsInstanceOf(bitmap, gBitmap_class));
    288     SkBitmap* b = (SkBitmap*)env->GetIntField(bitmap, gBitmap_nativeInstanceID);
    289     SkASSERT(b);
    290     return b;
    291 }
    292 
    293 SkBitmap::Config GraphicsJNI::getNativeBitmapConfig(JNIEnv* env,
    294                                                     jobject jconfig) {
    295     SkASSERT(env);
    296     if (NULL == jconfig) {
    297         return SkBitmap::kNo_Config;
    298     }
    299     SkASSERT(env->IsInstanceOf(jconfig, gBitmapConfig_class));
    300     int c = env->GetIntField(jconfig, gBitmapConfig_nativeInstanceID);
    301     if (c < 0 || c >= SkBitmap::kConfigCount) {
    302         c = SkBitmap::kNo_Config;
    303     }
    304     return static_cast<SkBitmap::Config>(c);
    305 }
    306 
    307 SkCanvas* GraphicsJNI::getNativeCanvas(JNIEnv* env, jobject canvas) {
    308     SkASSERT(env);
    309     SkASSERT(canvas);
    310     SkASSERT(env->IsInstanceOf(canvas, gCanvas_class));
    311     SkCanvas* c = (SkCanvas*)env->GetIntField(canvas, gCanvas_nativeInstanceID);
    312     SkASSERT(c);
    313     return c;
    314 }
    315 
    316 SkPaint* GraphicsJNI::getNativePaint(JNIEnv* env, jobject paint) {
    317     SkASSERT(env);
    318     SkASSERT(paint);
    319     SkASSERT(env->IsInstanceOf(paint, gPaint_class));
    320     SkPaint* p = (SkPaint*)env->GetIntField(paint, gPaint_nativeInstanceID);
    321     SkASSERT(p);
    322     return p;
    323 }
    324 
    325 SkPicture* GraphicsJNI::getNativePicture(JNIEnv* env, jobject picture)
    326 {
    327     SkASSERT(env);
    328     SkASSERT(picture);
    329     SkASSERT(env->IsInstanceOf(picture, gPicture_class));
    330     SkPicture* p = (SkPicture*)env->GetIntField(picture, gPicture_nativeInstanceID);
    331     SkASSERT(p);
    332     return p;
    333 }
    334 
    335 SkRegion* GraphicsJNI::getNativeRegion(JNIEnv* env, jobject region)
    336 {
    337     SkASSERT(env);
    338     SkASSERT(region);
    339     SkASSERT(env->IsInstanceOf(region, gRegion_class));
    340     SkRegion* r = (SkRegion*)env->GetIntField(region, gRegion_nativeInstanceID);
    341     SkASSERT(r);
    342     return r;
    343 }
    344 
    345 ///////////////////////////////////////////////////////////////////////////////////////////
    346 
    347 jobject GraphicsJNI::createBitmap(JNIEnv* env, SkBitmap* bitmap, jbyteArray buffer,
    348                                   bool isMutable, jbyteArray ninepatch, int density)
    349 {
    350     SkASSERT(bitmap);
    351     SkASSERT(bitmap->pixelRef());
    352 
    353     jobject obj = env->NewObject(gBitmap_class, gBitmap_constructorMethodID,
    354             static_cast<jint>(reinterpret_cast<uintptr_t>(bitmap)),
    355             buffer, isMutable, ninepatch, density);
    356     hasException(env); // For the side effect of logging.
    357     return obj;
    358 }
    359 
    360 jobject GraphicsJNI::createBitmap(JNIEnv* env, SkBitmap* bitmap, bool isMutable,
    361                             jbyteArray ninepatch, int density)
    362 {
    363     return createBitmap(env, bitmap, NULL, isMutable, ninepatch, density);
    364 }
    365 
    366 
    367 jobject GraphicsJNI::createBitmapRegionDecoder(JNIEnv* env, SkBitmapRegionDecoder* bitmap)
    368 {
    369     SkASSERT(bitmap != NULL);
    370 
    371     jobject obj = env->NewObject(gBitmapRegionDecoder_class,
    372             gBitmapRegionDecoder_constructorMethodID,
    373             static_cast<jint>(reinterpret_cast<uintptr_t>(bitmap)));
    374     hasException(env); // For the side effect of logging.
    375     return obj;
    376 }
    377 
    378 jobject GraphicsJNI::createRegion(JNIEnv* env, SkRegion* region)
    379 {
    380     SkASSERT(region != NULL);
    381     jobject obj = env->NewObject(gRegion_class, gRegion_constructorMethodID,
    382             static_cast<jint>(reinterpret_cast<uintptr_t>(region)), 0);
    383     hasException(env); // For the side effect of logging.
    384     return obj;
    385 }
    386 
    387 static JNIEnv* vm2env(JavaVM* vm)
    388 {
    389     JNIEnv* env = NULL;
    390     if (vm->GetEnv((void**)&env, JNI_VERSION_1_4) != JNI_OK || NULL == env)
    391     {
    392         SkDebugf("------- [%p] vm->GetEnv() failed\n", vm);
    393         sk_throw();
    394     }
    395     return env;
    396 }
    397 
    398 ///////////////////////////////////////////////////////////////////////////////
    399 
    400 AndroidPixelRef::AndroidPixelRef(JNIEnv* env, void* storage, size_t size, jbyteArray storageObj,
    401         SkColorTable* ctable) : SkMallocPixelRef(storage, size, ctable) {
    402     SkASSERT(storage);
    403     SkASSERT(env);
    404 
    405     if (env->GetJavaVM(&fVM) != JNI_OK) {
    406         SkDebugf("------ [%p] env->GetJavaVM failed\n", env);
    407         sk_throw();
    408     }
    409     fStorageObj = storageObj;
    410     fHasGlobalRef = false;
    411     fGlobalRefCnt = 0;
    412 
    413     // If storageObj is NULL, the memory was NOT allocated on the Java heap
    414     fOnJavaHeap = (storageObj != NULL);
    415 
    416 }
    417 
    418 AndroidPixelRef::~AndroidPixelRef() {
    419     if (fOnJavaHeap) {
    420         JNIEnv* env = vm2env(fVM);
    421 
    422         if (fStorageObj && fHasGlobalRef) {
    423             env->DeleteGlobalRef(fStorageObj);
    424         }
    425         fStorageObj = NULL;
    426 
    427         // Set this to NULL to prevent the SkMallocPixelRef destructor
    428         // from freeing the memory.
    429         fStorage = NULL;
    430     }
    431 }
    432 
    433 void AndroidPixelRef::setLocalJNIRef(jbyteArray arr) {
    434     if (!fHasGlobalRef) {
    435         fStorageObj = arr;
    436     }
    437 }
    438 
    439 void AndroidPixelRef::globalRef(void* localref) {
    440     if (fOnJavaHeap && sk_atomic_inc(&fGlobalRefCnt) == 0) {
    441         JNIEnv *env = vm2env(fVM);
    442 
    443         // If JNI ref was passed, it is always used
    444         if (localref) fStorageObj = (jbyteArray) localref;
    445 
    446         if (fStorageObj == NULL) {
    447             SkDebugf("No valid local ref to create a JNI global ref\n");
    448             sk_throw();
    449         }
    450         if (fHasGlobalRef) {
    451             // This should never happen
    452             SkDebugf("Already holding a JNI global ref");
    453             sk_throw();
    454         }
    455 
    456         fStorageObj = (jbyteArray) env->NewGlobalRef(fStorageObj);
    457         // TODO: Check for failure here
    458         fHasGlobalRef = true;
    459     }
    460     ref();
    461 }
    462 
    463 void AndroidPixelRef::globalUnref() {
    464     if (fOnJavaHeap && sk_atomic_dec(&fGlobalRefCnt) == 1) {
    465         JNIEnv *env = vm2env(fVM);
    466         if (!fHasGlobalRef) {
    467             SkDebugf("We don't have a global ref!");
    468             sk_throw();
    469         }
    470         env->DeleteGlobalRef(fStorageObj);
    471         fStorageObj = NULL;
    472         fHasGlobalRef = false;
    473     }
    474     unref();
    475 }
    476 
    477 ///////////////////////////////////////////////////////////////////////////////
    478 
    479 extern "C" jbyte* jniGetNonMovableArrayElements(C_JNIEnv* env, jarray arrayObj);
    480 
    481 jbyteArray GraphicsJNI::allocateJavaPixelRef(JNIEnv* env, SkBitmap* bitmap,
    482                                              SkColorTable* ctable) {
    483     Sk64 size64 = bitmap->getSize64();
    484     if (size64.isNeg() || !size64.is32()) {
    485         jniThrowException(env, "java/lang/IllegalArgumentException",
    486                           "bitmap size exceeds 32bits");
    487         return NULL;
    488     }
    489 
    490     size_t size = size64.get32();
    491     jbyteArray arrayObj = env->NewByteArray(size);
    492     if (arrayObj) {
    493         // TODO: make this work without jniGetNonMovableArrayElements
    494         jbyte* addr = jniGetNonMovableArrayElements(&env->functions, arrayObj);
    495         if (addr) {
    496             SkPixelRef* pr = new AndroidPixelRef(env, (void*) addr, size, arrayObj, ctable);
    497             bitmap->setPixelRef(pr)->unref();
    498             // since we're already allocated, we lockPixels right away
    499             // HeapAllocator behaves this way too
    500             bitmap->lockPixels();
    501         }
    502     }
    503 
    504     return arrayObj;
    505 }
    506 
    507 ///////////////////////////////////////////////////////////////////////////////
    508 
    509 JavaPixelAllocator::JavaPixelAllocator(JNIEnv* env)
    510     : fStorageObj(NULL),
    511       fAllocCount(0) {
    512     if (env->GetJavaVM(&fVM) != JNI_OK) {
    513         SkDebugf("------ [%p] env->GetJavaVM failed\n", env);
    514         sk_throw();
    515     }
    516 }
    517 
    518 bool JavaPixelAllocator::allocPixelRef(SkBitmap* bitmap, SkColorTable* ctable) {
    519     JNIEnv* env = vm2env(fVM);
    520 
    521     // If allocating in the Java heap, only allow a single object to be
    522     // allocated for the lifetime of this object.
    523     if (fStorageObj != NULL) {
    524         SkDebugf("WARNING: One-shot allocator has already allocated (alloc count = %d)\n", fAllocCount);
    525 //        sk_throw();
    526     }
    527     fStorageObj = GraphicsJNI::allocateJavaPixelRef(env, bitmap, ctable);
    528     fAllocCount += 1;
    529     return fStorageObj != NULL;
    530 }
    531 
    532 ////////////////////////////////////////////////////////////////////////////////
    533 
    534 JavaHeapBitmapRef::JavaHeapBitmapRef(JNIEnv* env, SkBitmap* nativeBitmap, jbyteArray buffer) {
    535     fEnv = env;
    536     fNativeBitmap = nativeBitmap;
    537     fBuffer = buffer;
    538 
    539     // If the buffer is NULL, the backing memory wasn't allocated on the Java heap
    540     if (fBuffer) {
    541         ((AndroidPixelRef*) fNativeBitmap->pixelRef())->setLocalJNIRef(fBuffer);
    542     }
    543 }
    544 
    545 JavaHeapBitmapRef::~JavaHeapBitmapRef() {
    546     if (fBuffer) {
    547         ((AndroidPixelRef*) fNativeBitmap->pixelRef())->setLocalJNIRef(NULL);
    548     }
    549 }
    550 
    551 ////////////////////////////////////////////////////////////////////////////////
    552 
    553 static jclass make_globalref(JNIEnv* env, const char classname[])
    554 {
    555     jclass c = env->FindClass(classname);
    556     SkASSERT(c);
    557     return (jclass)env->NewGlobalRef(c);
    558 }
    559 
    560 static jfieldID getFieldIDCheck(JNIEnv* env, jclass clazz,
    561                                 const char fieldname[], const char type[])
    562 {
    563     jfieldID id = env->GetFieldID(clazz, fieldname, type);
    564     SkASSERT(id);
    565     return id;
    566 }
    567 
    568 int register_android_graphics_Graphics(JNIEnv* env)
    569 {
    570     jmethodID m;
    571     jclass c;
    572 
    573     gRect_class = make_globalref(env, "android/graphics/Rect");
    574     gRect_leftFieldID = getFieldIDCheck(env, gRect_class, "left", "I");
    575     gRect_topFieldID = getFieldIDCheck(env, gRect_class, "top", "I");
    576     gRect_rightFieldID = getFieldIDCheck(env, gRect_class, "right", "I");
    577     gRect_bottomFieldID = getFieldIDCheck(env, gRect_class, "bottom", "I");
    578 
    579     gRectF_class = make_globalref(env, "android/graphics/RectF");
    580     gRectF_leftFieldID = getFieldIDCheck(env, gRectF_class, "left", "F");
    581     gRectF_topFieldID = getFieldIDCheck(env, gRectF_class, "top", "F");
    582     gRectF_rightFieldID = getFieldIDCheck(env, gRectF_class, "right", "F");
    583     gRectF_bottomFieldID = getFieldIDCheck(env, gRectF_class, "bottom", "F");
    584 
    585     gPoint_class = make_globalref(env, "android/graphics/Point");
    586     gPoint_xFieldID = getFieldIDCheck(env, gPoint_class, "x", "I");
    587     gPoint_yFieldID = getFieldIDCheck(env, gPoint_class, "y", "I");
    588 
    589     gPointF_class = make_globalref(env, "android/graphics/PointF");
    590     gPointF_xFieldID = getFieldIDCheck(env, gPointF_class, "x", "F");
    591     gPointF_yFieldID = getFieldIDCheck(env, gPointF_class, "y", "F");
    592 
    593     gBitmap_class = make_globalref(env, "android/graphics/Bitmap");
    594     gBitmap_nativeInstanceID = getFieldIDCheck(env, gBitmap_class, "mNativeBitmap", "I");
    595     gBitmap_constructorMethodID = env->GetMethodID(gBitmap_class, "<init>",
    596                                             "(I[BZ[BI)V");
    597     gBitmapRegionDecoder_class = make_globalref(env, "android/graphics/BitmapRegionDecoder");
    598     gBitmapRegionDecoder_constructorMethodID = env->GetMethodID(gBitmapRegionDecoder_class, "<init>", "(I)V");
    599 
    600     gBitmapConfig_class = make_globalref(env, "android/graphics/Bitmap$Config");
    601     gBitmapConfig_nativeInstanceID = getFieldIDCheck(env, gBitmapConfig_class,
    602                                                      "nativeInt", "I");
    603 
    604     gCanvas_class = make_globalref(env, "android/graphics/Canvas");
    605     gCanvas_nativeInstanceID = getFieldIDCheck(env, gCanvas_class, "mNativeCanvas", "I");
    606 
    607     gPaint_class = make_globalref(env, "android/graphics/Paint");
    608     gPaint_nativeInstanceID = getFieldIDCheck(env, gPaint_class, "mNativePaint", "I");
    609 
    610     gPicture_class = make_globalref(env, "android/graphics/Picture");
    611     gPicture_nativeInstanceID = getFieldIDCheck(env, gPicture_class, "mNativePicture", "I");
    612 
    613     gRegion_class = make_globalref(env, "android/graphics/Region");
    614     gRegion_nativeInstanceID = getFieldIDCheck(env, gRegion_class, "mNativeRegion", "I");
    615     gRegion_constructorMethodID = env->GetMethodID(gRegion_class, "<init>",
    616         "(II)V");
    617 
    618     return 0;
    619 }
    620