Path: blob/master/src/java.desktop/share/native/libawt/java2d/Disposer.c
41152 views
/*1* Copyright (c) 2002, 2013, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/24#include "jni_util.h"25#include "Disposer.h"2627static jmethodID addRecordMID = NULL;28static jclass dispClass = NULL;2930/*31* Class: sun_java2d_Disposer32* Method: initIDs33* Signature: ()V34*/35JNIEXPORT void JNICALL36Java_sun_java2d_Disposer_initIDs(JNIEnv *env, jclass disposerClass)37{38addRecordMID = (*env)->GetStaticMethodID(env, disposerClass, "addRecord",39"(Ljava/lang/Object;JJ)V");40if (addRecordMID != 0) {41dispClass = (*env)->NewGlobalRef(env, disposerClass);42}43}4445JNIEXPORT void JNICALL46Disposer_AddRecord(JNIEnv *env, jobject obj, GeneralDisposeFunc disposer, jlong pData) {4748if (dispClass == NULL) {49/* Needed to initialize the Disposer class as it may be not yet referenced */50jclass clazz = (*env)->FindClass(env, "sun/java2d/Disposer");51if ((*env)->ExceptionCheck(env)) {52// If there's exception pending, we'll just return.53return;54}55}5657(*env)->CallStaticVoidMethod(env, dispClass, addRecordMID,58obj, ptr_to_jlong(disposer), pData);59}6061/*62* Class: sun_java2d_DefaultDisposerRecord63* Method: invokeNativeDispose64* Signature: (JJ)V65*/66JNIEXPORT void JNICALL67Java_sun_java2d_DefaultDisposerRecord_invokeNativeDispose(JNIEnv *env, jclass dispClass,68jlong disposer, jlong pData)69{70if (disposer != 0 && pData != 0) {71GeneralDisposeFunc *disposeMethod = (GeneralDisposeFunc*)(jlong_to_ptr(disposer));72disposeMethod(env, pData);73}74}757677