classpath-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[cp-patches] make libjawt binary-compatible with Sun's implementation


From: Thomas Fitzsimmons
Subject: [cp-patches] make libjawt binary-compatible with Sun's implementation
Date: Sat, 20 Aug 2005 19:19:29 -0400

Hi,

This patch makes our AWT Native Interface implementation binary-
compatible with Sun's.  I obtained the structure layouts using gdb and
ptype.  I tested this with our JAWT demo; libDemoJAWT.so can be built
and run interchangeably between JamVM and the JDK.

There are still functions in the interface that we don't currently
implement; we can implement those as we find Free Software applications
that use them.

One issue remains for our libjawtgnu.so to be a drop-in replacement for
Sun's libjawt.so.  We must somehow set libjawtgnu.so's SONAME ELF field
to "libjawt.so".  Libtool does not currently support overriding SONAME,
but a patch is being reviewed by libtool's maintainers:

http://lists.gnu.org/archive/html/libtool/2005-07/msg00093.html

Tom

2005-08-20  Thomas Fitzsimmons  <address@hidden>

        * native/jni/gtk-peer/gtk_jawt.c
        (classpath_jawt_get_default_display): Remove locking.
        (classpath_jawt_get_visualID): Likewise.
        (classpath_jawt_get_drawable): Likewise.
        (classpath_jawt_object_lock): Remove function.
        (classpath_jawt_object_unlock): Likewise.
        (classpath_jawt_create_lock): Likewise.
        (classpath_jawt_destroy_lock): Likewise.
        * native/jni/classpath/classpath_jawt.h
        (classpath_jawt_object_lock): Remove function.
        (classpath_jawt_object_unlock): Likewise.
        (classpath_jawt_create_lock): Likewise.
        (classpath_jawt_destroy_lock): Likewise.
        * native/jawt/jawt.c [!__GNUC__] (__attribute__): Define to
        nothing.
        (_Jv_Lock): Call classpath_jawt_lock.
        (_Jv_Unlock): Call classpath_jawt_unlock.
        (_Jv_GetDrawingSurfaceInfo): Move surface_info_x11 initialization
        from ...
        (_Jv_GetDrawingSurface): Remove surface_info_x11 initialization.
        (_Jv_FreeDrawingSurface): Don't destroy target object.
        * native/jawt/Makefile.am: Add SONAME FIXME.
        * include/jawt_md.h (struct _JAWT_X11DrawingSurfaceInfo): Re-order
        display field.  Add colour map, depth and GetAWTColor function
        pointer fields.
        * include/jawt.h (struct _JAWT_Rectangle): New structure.
        (struct _JAWT_DrawingSurfaceInfo): Add drawing surface, bounds,
        clip size and clipping rectangle fields.
        (struct _JAWT_DrawingSurface): Add env field.  Rename lock field
        target.  Re-order function pointer and lock fields.  Remove
        surface_info field.
        (struct _JAWT): Add GetComponent function pointer field.

Index: include/jawt.h
===================================================================
RCS file: /cvsroot/classpath/classpath/include/jawt.h,v
retrieving revision 1.1
diff -u -r1.1 jawt.h
--- include/jawt.h      19 Aug 2005 15:24:48 -0000      1.1
+++ include/jawt.h      20 Aug 2005 22:07:54 -0000
@@ -57,26 +57,31 @@
 #define JAWT_LOCK_BOUNDS_CHANGED 0x4
 #define JAWT_LOCK_SURFACE_CHANGED 0x8
 
+struct _JAWT_Rectangle
+{
+  jint x;
+  jint y;
+  jint width;
+  jint height;
+};
+
 struct _JAWT_DrawingSurfaceInfo
 {
   void* platformInfo;
+  struct _JAWT_DrawingSurface *ds;
+  struct _JAWT_Rectangle bounds;
+  jint clipSize;
+  struct _JAWT_Rectangle *clip;
 };
 
 struct _JAWT_DrawingSurface
 {
+  JNIEnv* env;
+  jobject target;
   jint (JNICALL* Lock) (struct _JAWT_DrawingSurface*);
-  void (JNICALL* Unlock) (struct _JAWT_DrawingSurface*);
-
   struct _JAWT_DrawingSurfaceInfo* (JNICALL* GetDrawingSurfaceInfo) (struct 
_JAWT_DrawingSurface*);
   void (JNICALL* FreeDrawingSurfaceInfo) (struct _JAWT_DrawingSurfaceInfo*);
-
-  struct _JAWT_DrawingSurfaceInfo* surface_info;
-
-  /* An object we're going to use for locking the surface.  */
-  jobject lock;
-
-  /* FIXME: also include bounding rectangle of drawing surface. */
-  /* FIXME: also include current clipping region. */
+  void (JNICALL* Unlock) (struct _JAWT_DrawingSurface*);
 };
 
 struct _JAWT
@@ -86,8 +91,10 @@
   void (JNICALL* FreeDrawingSurface) (struct _JAWT_DrawingSurface*);
   void (JNICALL *Lock) (JNIEnv*);
   void (JNICALL *Unlock) (JNIEnv*);
+  jobject (JNICALL *GetComponent)(JNIEnv*, void*);
 };
 
+typedef struct _JAWT_Rectangle JAWT_Rectangle;
 typedef struct _JAWT_DrawingSurfaceInfo JAWT_DrawingSurfaceInfo;
 typedef struct _JAWT_DrawingSurface JAWT_DrawingSurface;
 typedef struct _JAWT JAWT;
Index: include/jawt_md.h
===================================================================
RCS file: /cvsroot/classpath/classpath/include/jawt_md.h,v
retrieving revision 1.1
diff -u -r1.1 jawt_md.h
--- include/jawt_md.h   19 Aug 2005 15:24:48 -0000      1.1
+++ include/jawt_md.h   20 Aug 2005 22:07:54 -0000
@@ -50,9 +50,12 @@
 
 struct _JAWT_X11DrawingSurfaceInfo
 {
-  Display* display;
   Drawable drawable;
+  Display* display;
   VisualID visualID;
+  Colormap colormapID;
+  int depth;
+  int (JNICALL *GetAWTColor)(struct _JAWT_DrawingSurface*, int, int, int);
 };
 
 typedef struct _JAWT_X11DrawingSurfaceInfo JAWT_X11DrawingSurfaceInfo;
Index: native/jawt/Makefile.am
===================================================================
RCS file: /cvsroot/classpath/classpath/native/jawt/Makefile.am,v
retrieving revision 1.1
diff -u -r1.1 Makefile.am
--- native/jawt/Makefile.am     19 Aug 2005 15:24:48 -0000      1.1
+++ native/jawt/Makefile.am     20 Aug 2005 22:07:56 -0000
@@ -2,6 +2,10 @@
 
 libjawtgnu_la_SOURCES = jawt.c
 libjawtgnu_la_LIBADD = $(top_builddir)/native/jni/gtk-peer/libgtkpeer.la
+# FIXME: libtool doesn't allow overriding SONAME, but we need to set
+# it to libjawt.so for binary compatibility.
+#
+# libjawtgnu_la_LDFLAGS = -Wl,-soname -Wl,libjawt.so
 
 AM_LDFLAGS = @CLASSPATH_MODULE@ @GTK_LIBS@ @CAIRO_LIBS@ @PANGOFT2_LIBS@ 
@X_LIBS@ -lXtst
 AM_CPPFLAGS = @CLASSPATH_INCLUDES@
Index: native/jawt/jawt.c
===================================================================
RCS file: /cvsroot/classpath/classpath/native/jawt/jawt.c,v
retrieving revision 1.1
diff -u -r1.1 jawt.c
--- native/jawt/jawt.c  19 Aug 2005 15:24:48 -0000      1.1
+++ native/jawt/jawt.c  20 Aug 2005 22:07:56 -0000
@@ -41,6 +41,10 @@
 #include <jawt_md.h>
 #include "classpath_jawt.h"
 
+#ifndef __GNUC__
+#define __attribute__(x) /* nothing */
+#endif
+
 static jint (JNICALL _Jv_Lock) (JAWT_DrawingSurface* surface);
 static void (JNICALL _Jv_Unlock) (JAWT_DrawingSurface* surface);
 static JAWT_DrawingSurfaceInfo* (JNICALL _Jv_GetDrawingSurfaceInfo)
@@ -74,24 +78,49 @@
 /* JAWT_DrawingSurface functions */
 
 static jint
-(JNICALL _Jv_Lock) (JAWT_DrawingSurface* surface)
+(JNICALL _Jv_Lock) (JAWT_DrawingSurface* surface __attribute__((unused)))
 {
-  return classpath_jawt_object_lock (surface->lock);
+  return classpath_jawt_lock ();
 }
 
 static void
-(JNICALL _Jv_Unlock) (JAWT_DrawingSurface* surface)
+(JNICALL _Jv_Unlock) (JAWT_DrawingSurface* surface __attribute__((unused)))
 {
-  classpath_jawt_object_unlock (surface->lock);
+  classpath_jawt_unlock ();
 }
 
 static JAWT_DrawingSurfaceInfo*
 (JNICALL _Jv_GetDrawingSurfaceInfo) (JAWT_DrawingSurface* surface)
 {
-  if (surface == NULL)
+  JAWT_DrawingSurfaceInfo* surface_info;
+  JAWT_X11DrawingSurfaceInfo* surface_info_x11;
+
+  if (surface == NULL || surface->target == NULL)
+    return NULL;
+
+  surface_info = (JAWT_DrawingSurfaceInfo*) malloc (sizeof 
(JAWT_DrawingSurfaceInfo));
+
+  if (surface_info == NULL)
     return NULL;
 
-  return surface->surface_info;
+  surface_info->platformInfo = malloc (sizeof (JAWT_X11DrawingSurfaceInfo));
+
+  if (surface_info->platformInfo == NULL)
+    return NULL;
+
+  surface_info_x11 = (JAWT_X11DrawingSurfaceInfo*) surface_info->platformInfo;
+
+  surface_info_x11->display = classpath_jawt_get_default_display (surface->env,
+                                                                  
surface->target);
+  surface_info_x11->drawable = classpath_jawt_get_drawable (surface->env,
+                                                            surface->target);
+  surface_info_x11->visualID = classpath_jawt_get_visualID (surface->env,
+                                                            surface->target);
+
+  /* FIXME: also include bounding rectangle of drawing surface */
+  /* FIXME: also include current clipping region */
+
+  return surface_info;
 }
 
 static void
@@ -119,13 +148,15 @@
 (JNICALL _Jv_GetDrawingSurface) (JNIEnv* env, jobject canvas)
 {
   JAWT_DrawingSurface* surface;
-  JAWT_X11DrawingSurfaceInfo* surface_info_x11;
 
   surface = (JAWT_DrawingSurface*) malloc (sizeof (JAWT_DrawingSurface));
 
   if (surface == NULL)
     return NULL;
 
+  surface->env = env;
+  surface->target = canvas;
+
   /* initialize function pointers */
   surface->GetDrawingSurfaceInfo = _Jv_GetDrawingSurfaceInfo;
   surface->FreeDrawingSurfaceInfo = _Jv_FreeDrawingSurfaceInfo;
@@ -133,34 +164,12 @@
   surface->Lock = _Jv_Lock;
   surface->Unlock = _Jv_Unlock;
 
-  surface->surface_info = (JAWT_DrawingSurfaceInfo*) malloc (sizeof 
(JAWT_DrawingSurfaceInfo));
-
-  surface->lock = classpath_jawt_create_lock ();
-
-  if (surface->surface_info == NULL)
-    return NULL;
-
-  surface->surface_info->platformInfo = malloc (sizeof 
(JAWT_X11DrawingSurfaceInfo));
-
-  if (surface->surface_info->platformInfo == NULL)
-    return NULL;
-
-  surface_info_x11 = (JAWT_X11DrawingSurfaceInfo*) 
surface->surface_info->platformInfo;
-
-  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 */
-
   return surface;
 }
 
 static void
 (JNICALL _Jv_FreeDrawingSurface) (JAWT_DrawingSurface* surface)
 {
-  classpath_jawt_destroy_lock (surface->lock);
   free (surface);
 }
 
@@ -175,4 +184,3 @@
 {
   classpath_jawt_unlock ();
 }
-
Index: native/jni/classpath/classpath_jawt.h
===================================================================
RCS file: /cvsroot/classpath/classpath/native/jni/classpath/classpath_jawt.h,v
retrieving revision 1.3
diff -u -r1.3 classpath_jawt.h
--- native/jni/classpath/classpath_jawt.h       8 Aug 2005 21:46:48 -0000       
1.3
+++ native/jni/classpath/classpath_jawt.h       20 Aug 2005 22:07:56 -0000
@@ -54,11 +54,7 @@
 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_object_lock (jobject lock);
-void     classpath_jawt_object_unlock (jobject lock);
 jint     classpath_jawt_lock (void);
 void     classpath_jawt_unlock (void);
-jobject  classpath_jawt_create_lock (void);
-void     classpath_jawt_destroy_lock (jobject lock);
 
 #endif /* __classpath_jawt_h__ */
Index: native/jni/gtk-peer/gtk_jawt.c
===================================================================
RCS file: /cvsroot/classpath/classpath/native/jni/gtk-peer/gtk_jawt.c,v
retrieving revision 1.1
diff -u -r1.1 gtk_jawt.c
--- native/jni/gtk-peer/gtk_jawt.c      8 Aug 2005 21:46:48 -0000       1.1
+++ native/jni/gtk-peer/gtk_jawt.c      20 Aug 2005 22:07:56 -0000
@@ -47,6 +47,8 @@
   return CLASSPATH_JAWT_VERSION;
 }
 
+/* Does not require locking: meant to be called after the drawing
+   surface is locked. */
 Display*
 classpath_jawt_get_default_display (JNIEnv* env, jobject canvas)
 {
@@ -69,8 +71,6 @@
 
   ptr = NSA_GET_PTR (env, peer);
 
-  gdk_threads_enter ();
-
   widget = GTK_WIDGET (ptr);
 
   /* widget should be realized before Canvas.paint is called. */
@@ -80,11 +80,11 @@
 
   xdisplay = GDK_DISPLAY_XDISPLAY (display);
 
-  gdk_threads_leave ();
-
   return xdisplay;
 }
 
+/* Does not require locking: meant to be called after the drawing
+   surface is locked. */
 VisualID
 classpath_jawt_get_visualID (JNIEnv* env, jobject canvas)
 {
@@ -105,8 +105,6 @@
 
   ptr = NSA_GET_PTR (env, peer);
 
-  gdk_threads_enter ();
-
   widget = GTK_WIDGET (ptr);
 
   g_assert (GTK_WIDGET_REALIZED (widget));
@@ -114,11 +112,11 @@
   visual = gdk_x11_visual_get_xvisual (gtk_widget_get_visual (widget));
   g_assert (visual != NULL);
 
-  gdk_threads_leave ();
-
   return visual->visualid;
 }
 
+/* Does not require locking: meant to be called after the drawing
+   surface is locked. */
 Drawable
 classpath_jawt_get_drawable (JNIEnv* env, jobject canvas)
 {
@@ -139,35 +137,16 @@
 
   ptr = NSA_GET_PTR (env, peer);
 
-  gdk_threads_enter ();
-
   widget = GTK_WIDGET (ptr);
 
   g_assert (GTK_WIDGET_REALIZED (widget));
 
   drawable = GDK_DRAWABLE_XID (widget->window);
 
-  gdk_threads_leave ();
-
   return drawable;
 }
 
 jint
-classpath_jawt_object_lock (jobject lock)
-{
-  JNIEnv *env = cp_gtk_gdk_env();
-  (*env)->MonitorEnter (env, lock);
-  return 0;
-}
-
-void
-classpath_jawt_object_unlock (jobject lock)
-{
-  JNIEnv *env = cp_gtk_gdk_env();
-  (*env)->MonitorExit (env, lock);
-}
-
-jint
 classpath_jawt_lock ()
 {
   gdk_threads_enter ();
@@ -178,20 +157,4 @@
 classpath_jawt_unlock ()
 {
   gdk_threads_leave ();
-}
-
-jobject
-classpath_jawt_create_lock ()
-{
-  JNIEnv *env = cp_gtk_gdk_env ();
-  jobject lock = (*env)->NewStringUTF (env, "jawt-lock");
-  NSA_SET_GLOBAL_REF (env, lock);
-  return lock;
-}
-
-void
-classpath_jawt_destroy_lock (jobject lock)
-{
-  JNIEnv *env = cp_gtk_gdk_env ();
-  NSA_DEL_GLOBAL_REF (env, lock);
 }

reply via email to

[Prev in Thread] Current Thread [Next in Thread]