[gui][patch] AWT Native Interface implementation

Anthony Green green@redhat.com
Sun Feb 13 19:41:00 GMT 2005


On Fri, 2005-02-11 at 23:00 -0500, Thomas Fitzsimmons wrote:
> I'll be testing other packages in the weeks to come, like Eclipse,
> OpenOffice.org and the JOGL bindings.

I tried this with jogl and came up with the attached patch.
The magic number values came from the public docs for a product called
jniwrapper, here:
http://www.jniwrapper.com/docs/javadoc_v1/constant-values.html

It's quite likely that the Lock and Unlock implementations are
completely bogus.  I just wanted to get it to build and show something
on the screen.  Hopefully it's not too far off from the right thing.

AG


-------------- next part --------------
2005-02-13  Anthony Green  <green@redhat.com>

	* jni/gtk-peer/gtk_jawt.c (classpath_jawt_get_drawable,
	classpath_jawt_lock, classpath_jawt_unlock): New functions.
	* jawt.c (_Jv_AWTLock, _Jv_AWTUnlock): New functions.
	(_Jv_GetDrawingSurface): Set visualID.
	(_Jv_FreeDrawingSurfaceInfo): Clear visualID.
	(JAWT_GetAWT): Set Lock and Unlock.
	* include/jawt_md.h (struct _JAWT_X11DrawingSurfaceInfo): Add visualID.
	* include/jawt.h (JAWT_VERSION_1_4, JAWT_LOCK_ERROR,
	JAWT_LOCK_CLIP_CHANGED, JAWT_LOCK_BOUNDS_CHANGED,
	JAWT_LOCK_SURFACE_CHANGED): New macros.
	(struct _JAWT): Add Lock and Unlock.


diff -cr ./include/jawt.h /home/green/FSF/gcc/libjava/include/jawt.h
*** ./include/jawt.h	2005-02-13 10:42:15.205492864 -0800
--- /home/green/FSF/gcc/libjava/include/jawt.h	2005-02-12 20:43:31.000000000 -0800
***************
*** 50,57 ****
--- 50,61 ----
  #endif
  
  #define JAWT_VERSION_1_3 0x10003
+ #define JAWT_VERSION_1_4 0x10004
  
  #define JAWT_LOCK_ERROR 0x1
+ #define JAWT_LOCK_CLIP_CHANGED 0x2
+ #define JAWT_LOCK_BOUNDS_CHANGED 0x4
+ #define JAWT_LOCK_SURFACE_CHANGED 0x8
  
  struct _JAWT_DrawingSurfaceInfo
  {
***************
*** 77,82 ****
--- 81,88 ----
    jint version;
    struct _JAWT_DrawingSurface* (JNICALL* GetDrawingSurface) (JNIEnv*, jobject);
    void (JNICALL* FreeDrawingSurface) (struct _JAWT_DrawingSurface*);
+   void (JNICALL *Lock) (JNIEnv*);
+   void (JNICALL *Unlock) (JNIEnv*);
  };
  
  typedef struct _JAWT_DrawingSurfaceInfo JAWT_DrawingSurfaceInfo;
diff -cr ./include/jawt_md.h /home/green/FSF/gcc/libjava/include/jawt_md.h
*** ./include/jawt_md.h	2005-02-13 10:42:15.207492560 -0800
--- /home/green/FSF/gcc/libjava/include/jawt_md.h	2005-02-12 20:48:37.000000000 -0800
***************
*** 52,57 ****
--- 52,58 ----
  {
    Display* display;
    Drawable drawable;
+   VisualID visualID;
  };
  
  typedef struct _JAWT_X11DrawingSurfaceInfo JAWT_X11DrawingSurfaceInfo;
diff -cr ./jawt.c /home/green/FSF/gcc/libjava/jawt.c
*** ./jawt.c	2005-02-13 10:42:12.343927888 -0800
--- /home/green/FSF/gcc/libjava/jawt.c	2005-02-12 20:53:16.000000000 -0800
***************
*** 50,55 ****
--- 50,57 ----
  static JAWT_DrawingSurface* (JNICALL _Jv_GetDrawingSurface) (JNIEnv* env,
  							     jobject canvas);
  static void (JNICALL _Jv_FreeDrawingSurface) (JAWT_DrawingSurface* surface);
+ static void (JNICALL _Jv_AWTLock) (JNIEnv*);
+ static void (JNICALL _Jv_AWTUnlock) (JNIEnv*);
  
  JNIEXPORT jboolean JNICALL
  JAWT_GetAWT (JNIEnv* env, JAWT* awt)
***************
*** 63,68 ****
--- 65,72 ----
  
    awt->GetDrawingSurface = _Jv_GetDrawingSurface;
    awt->FreeDrawingSurface = _Jv_FreeDrawingSurface;
+   awt->Lock = _Jv_AWTLock;
+   awt->Unlock = _Jv_AWTUnlock;
  
    return JNI_TRUE;
  }
***************
*** 103,108 ****
--- 107,113 ----
  
    surface_info_x11->display = NULL;
    surface_info_x11->drawable = 0;
+   surface_info_x11->visualID = 0;
  
    free (surface_info);
    surface_info = NULL;
***************
*** 142,147 ****
--- 147,153 ----
  
    surface_info_x11->display = classpath_jawt_get_default_display (env, canvas);
    surface_info_x11->drawable = classpath_jawt_get_drawable (env, canvas);
+   surface_info_x11->visualID = classpath_jawt_get_visualID (env, canvas);
  
    /* FIXME: also include bounding rectangle of drawing surface */
    /* FIXME: also include current clipping region */
***************
*** 154,156 ****
--- 160,175 ----
  {
    free (surface);
  }
+ 
+ static void
+ (JNICALL _Jv_AWTLock) (JNIEnv* env)
+ {
+   classpath_jawt_lock ();
+ }
+ 
+ static void
+ (JNICALL _Jv_AWTUnlock) (JNIEnv* env)
+ {
+   classpath_jawt_unlock ();
+ }
+ 
diff -cr ./jni/classpath/classpath_jawt.h /home/green/FSF/gcc/libjava/jni/classpath/classpath_jawt.h
*** ./jni/classpath/classpath_jawt.h	2005-02-13 10:42:15.208492408 -0800
--- /home/green/FSF/gcc/libjava/jni/classpath/classpath_jawt.h	2005-02-12 21:11:51.000000000 -0800
***************
*** 53,58 ****
--- 53,59 ----
  jint     classpath_jawt_get_awt_version ();
  Display* classpath_jawt_get_default_display (JNIEnv* env, jobject canvas);
  Drawable classpath_jawt_get_drawable (JNIEnv* env, jobject canvas);
+ VisualID classpath_jawt_get_visualID (JNIEnv* env, jobject canvas);
  jint     classpath_jawt_lock ();
  void     classpath_jawt_unlock ();
  
diff -cr ./jni/gtk-peer/gtk_jawt.c /home/green/FSF/gcc/libjava/jni/gtk-peer/gtk_jawt.c
*** ./jni/gtk-peer/gtk_jawt.c	2005-02-13 10:42:15.208492408 -0800
--- /home/green/FSF/gcc/libjava/jni/gtk-peer/gtk_jawt.c	2005-02-12 21:24:01.000000000 -0800
***************
*** 85,90 ****
--- 85,124 ----
    return xdisplay;
  }
  
+ VisualID
+ classpath_jawt_get_visualID (JNIEnv* env, jobject canvas)
+ {
+   GtkWidget *widget;
+   Visual *visual;
+   void *ptr;
+   jobject peer;
+   jclass class_id;
+   jmethodID method_id;
+ 
+   class_id = (*env)->GetObjectClass (env, canvas);
+ 
+   method_id = (*env)->GetMethodID (env, class_id,
+ 				   "getPeer",
+ 				   "()Ljava/awt/peer/ComponentPeer;");
+ 
+   peer = (*env)->CallObjectMethod (env, canvas, method_id);
+ 
+   ptr = NSA_GET_PTR (env, peer);
+ 
+   gdk_threads_enter ();
+ 
+   widget = GTK_WIDGET (ptr);
+ 
+   g_assert (GTK_WIDGET_REALIZED (widget));
+ 
+   visual = gdk_x11_visual_get_xvisual (gtk_widget_get_visual (widget));
+   g_assert (visual != NULL);
+ 
+   gdk_threads_leave ();
+ 
+   return visual->visualid;
+ }
+ 
  Drawable
  classpath_jawt_get_drawable (JNIEnv* env, jobject canvas)
  {


More information about the Java-patches mailing list