[cairo-commit] cairo-java/src/jni org_freedesktop_cairo_Cairo.c, 1.10, 1.11

Jeffrey Morgan commit at pdx.freedesktop.org
Mon Mar 14 18:12:03 PST 2005


Committed by: kuzman

Update of /cvs/cairo/cairo-java/src/jni
In directory gabe:/tmp/cvs-serv10534/src/jni

Modified Files:
	org_freedesktop_cairo_Cairo.c 
Log Message:
caching jmethodID and new example

Index: org_freedesktop_cairo_Cairo.c
===================================================================
RCS file: /cvs/cairo/cairo-java/src/jni/org_freedesktop_cairo_Cairo.c,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -d -r1.10 -r1.11
--- org_freedesktop_cairo_Cairo.c	14 Mar 2005 16:24:06 -0000	1.10
+++ org_freedesktop_cairo_Cairo.c	15 Mar 2005 02:12:01 -0000	1.11
@@ -17,6 +17,17 @@
 extern "C" {
 #endif
 
+static jmethodID move_to = NULL;
+static jmethodID line_to = NULL;
+static jmethodID curve_to = NULL;
+static jmethodID close_path = NULL;
+
+typedef struct {
+  JNIEnv *env;
+  jobject obj;
+} CairoCallback;
+
+
 /*
  * Class:     org_freedesktop_cairo_Cairo
  * Method:    cairo_create
@@ -1157,14 +1168,6 @@
 }
 
 
-typedef struct {
-  JNIEnv *env;
-  jobject obj;
-  jmethodID move_to;
-  jmethodID line_to;
-  jmethodID curve_to;
-  jmethodID close_path;
-} CairoCallback;
 
 CairoCallback* callback_data(JNIEnv *env, jclass cls, jobject cb)
 {
@@ -1176,37 +1179,37 @@
 	cbdata->env = env;
 	cbdata->obj = (*env)->NewGlobalRef(env, cb);
 
-	cbdata->move_to = 
-		(*env)->GetMethodID(env, cls, "move_to", "(DD)V");
-    if (cbdata->move_to == NULL ) {
-        g_free(cbdata);
-        // Error!  Throw exception!
-        return NULL;
-    }
+	if (NULL == move_to) {
+		move_to = (*env)->GetMethodID(env, cls, "move_to", "(DD)V");
+	    if (move_to == NULL ) {
+	        g_free(cbdata);
+	        return NULL;
+	    }
+	}
 
-	cbdata->line_to = 
-		(*env)->GetMethodID(env, cls, "line_to", "(DD)V");
-    if (cbdata->line_to == NULL ) {
-        g_free(cbdata);
-        // Error!  Throw exception!
-        return NULL;
-    }
+	if (NULL == line_to) {
+		line_to = (*env)->GetMethodID(env, cls, "line_to", "(DD)V");
+	    if (line_to == NULL ) {
+	        g_free(cbdata);
+	        return NULL;
+	    }
+	}
 
-	cbdata->curve_to = 
-		(*env)->GetMethodID(env, cls, "curve_to", "(DDDDDD)V");
-    if (cbdata->curve_to == NULL ) {
-        g_free(cbdata);
-        // Error!  Throw exception!
-        return NULL;
-    }
+	if (NULL == curve_to) {
+		curve_to = (*env)->GetMethodID(env, cls, "curve_to", "(DDDDDD)V");
+	    if (curve_to == NULL ) {
+	        g_free(cbdata);
+	        return NULL;
+	    }
+	}
 
-	cbdata->close_path = 
-		(*env)->GetMethodID(env, cls, "close_path", "()V");
-    if (cbdata->close_path == NULL ) {
-        g_free(cbdata);
-        // Error!  Throw exception!
-        return NULL;
-    }
+	if (NULL == close_path) {
+		close_path = (*env)->GetMethodID(env, cls, "close_path", "()V");
+	    if (close_path == NULL ) {
+	        g_free(cbdata);
+	        return NULL;
+	    }
+	}
     
     return cbdata;
 }
@@ -1218,7 +1221,7 @@
 
 	(*cbdata->env)->CallVoidMethod(cbdata->env, 
 				       cbdata->obj, 
-				       cbdata->move_to,
+				       move_to,
 				       x, y); 
 	if (exc) {
 		/* Print stack trace */
@@ -1235,7 +1238,7 @@
 	
 	(*cbdata->env)->CallVoidMethod(cbdata->env, 
 				       cbdata->obj, 
-				       cbdata->line_to, 
+				       line_to, 
 				       x, y);
 
 	if (exc) {
@@ -1254,7 +1257,7 @@
 	
 	(*cbdata->env)->CallVoidMethod(cbdata->env, 
 				       cbdata->obj, 
-				       cbdata->curve_to, 
+				       curve_to, 
 				       x1, y1, x2, y2, x3, y3);
 	if (exc) {
 		/* Print stack trace */
@@ -1271,8 +1274,7 @@
 	
 	(*cbdata->env)->CallVoidMethod(cbdata->env, 
 				       cbdata->obj, 
-				       cbdata->move_to);
-	exc = (* cbdata->env)->ExceptionOccurred(cbdata->env);
+				       move_to);
 	if (exc) {
 		/* Print stack trace */
 		(* cbdata->env)->ExceptionDescribe(cbdata->env);
@@ -1281,7 +1283,6 @@
 	}
 }
 
-
 /*
  * Class:     org_freedesktop_cairo_Cairo
  * Method:    cairo_get_path




More information about the cairo-commit mailing list