JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_GdkGraphics2D_cairoSetMatrix 
   (JNIEnv *env, jobject obj, jdoubleArray java_matrix)
{
  struct graphics2d *gr = NULL;
  jdouble *native_matrix = NULL;

  gr = (struct graphics2d *) NSA_GET_G2D_PTR (env, obj);
  g_assert (gr != NULL);

  native_matrix = (*env)->GetDoubleArrayElements (env, java_matrix, NULL);  
  g_assert (native_matrix != NULL);
  g_assert ((*env)->GetArrayLength (env, java_matrix) == 6);

  if (gr->debug) printf ("cairo_set_matrix [ %f, %f, %f, %f, %f, %f ]\n",
			 native_matrix[0], native_matrix[1],
			 native_matrix[2], native_matrix[3],
			 native_matrix[4], native_matrix[5]);

  {
    cairo_matrix_t * mat = cairo_matrix_create ();
    cairo_matrix_set_affine (mat, 
			     native_matrix[0], native_matrix[1],
			     native_matrix[2], native_matrix[3],
			     native_matrix[4], native_matrix[5]);
    cairo_set_matrix (gr->cr, mat);
    cairo_matrix_destroy (mat);
  }

  (*env)->ReleaseDoubleArrayElements (env, java_matrix, native_matrix, 0);
  update_pattern_transform (gr);
}
JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_GdkGraphics2D_cairoRestore 
   (JNIEnv *env, jobject obj)
{
  struct graphics2d *gr = NULL;
  gr = (struct graphics2d *) NSA_GET_G2D_PTR (env, obj);
  g_assert (gr != NULL);
  if (gr->debug) printf ("cairo_restore\n");
  cairo_restore (gr->cr);
  update_pattern_transform (gr);
}
JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_GdkGraphics2D_cairoRestore 
   (JNIEnv *env, jobject obj)
{
  struct graphics2d *gr = NULL;

  gdk_threads_enter();
  if (peer_is_disposed(env, obj)) { gdk_threads_leave(); return; }

  gr = (struct graphics2d *) NSA_GET_G2D_PTR (env, obj);
  g_assert (gr != NULL);
  if (gr->debug) printf ("cairo_restore\n");
  cairo_restore (gr->cr);
  update_pattern_transform (gr);
  gdk_threads_leave();
}