This is the mail archive of the java-patches@gcc.gnu.org mailing list for the Java project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

patch: requirements to enable GdkGraphics2D


Hi,

This is more of an informative patch, as I'm not (at the moment)
suggesting it be applied. The underlying GdkGraphics2D code isn't
sufficiently complete to take over from GdkGraphics just yet.

Anyways, this patch is the necessary wiring -- aside from the makefile
stuff which is completely straightforward -- to enable the GTK peers
to switch to using GdkGraphics2D as their Graphics object. I'm just
posting it here for the sake of review, in case someone would like to
comment on the technique. I don't think there's anything contentious
about it, but who knows.

-graydon

Index: libjava/java/awt/Component.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/awt/Component.java,v
retrieving revision 1.26
diff -u -r1.26 Component.java
--- libjava/java/awt/Component.java	25 Jul 2003 12:50:44 -0000	1.26
+++ libjava/java/awt/Component.java	28 Aug 2003 22:48:04 -0000
@@ -1867,10 +1867,15 @@
    */
   public Image createImage(int width, int height)
   {
-    if (GraphicsEnvironment.isHeadless())
-      return null;
-    GraphicsConfiguration config = getGraphicsConfiguration();
-    return config == null ? null : config.createCompatibleImage(width, height);
+    Image returnValue = null;
+    if (!GraphicsEnvironment.isHeadless ())
+    {
+      if (isLightweight () && parent != null)
+        returnValue = parent.createImage (width, height);
+      else if (peer != null)
+        returnValue = peer.createImage (width, height);
+    }
+    return returnValue;
   }
 
   /**
Index: libjava/gnu/java/awt/peer/gtk/GtkComponentPeer.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/gnu/java/awt/peer/gtk/GtkComponentPeer.java,v
retrieving revision 1.5
diff -u -r1.5 GtkComponentPeer.java
--- libjava/gnu/java/awt/peer/gtk/GtkComponentPeer.java	5 Aug 2003 18:04:09 -0000	1.5
+++ libjava/gnu/java/awt/peer/gtk/GtkComponentPeer.java	28 Aug 2003 22:48:04 -0000
@@ -48,6 +48,7 @@
 import java.awt.FontMetrics;
 import java.awt.Frame;
 import java.awt.Graphics;
+import java.awt.Graphics2D;
 import java.awt.GraphicsConfiguration;
 import java.awt.Image;
 import java.awt.Insets;
@@ -139,7 +140,8 @@
 
   public Image createImage (int width, int height)
   {
-    GdkGraphics g = new GdkGraphics (width, height);
+    Graphics2D g = new GdkGraphics2D (width, height);
+    g.setBackground (getBackground ());
     return new GtkOffScreenImage (null, g, width, height);
   }
 
Index: libjava/gnu/java/awt/peer/gtk/GtkContainerPeer.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/gnu/java/awt/peer/gtk/GtkContainerPeer.java,v
retrieving revision 1.3
diff -u -r1.3 GtkContainerPeer.java
--- libjava/gnu/java/awt/peer/gtk/GtkContainerPeer.java	9 Jul 2003 07:50:00 -0000	1.3
+++ libjava/gnu/java/awt/peer/gtk/GtkContainerPeer.java	28 Aug 2003 22:48:04 -0000
@@ -94,7 +94,7 @@
 
   public Graphics getGraphics ()
   {
-    return new GdkGraphics (this);
+    return new GdkGraphics2D (this);
   }
 
   public void handleEvent (AWTEvent event)
Index: libjava/gnu/java/awt/peer/gtk/GtkFramePeer.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/gnu/java/awt/peer/gtk/GtkFramePeer.java,v
retrieving revision 1.3
diff -u -r1.3 GtkFramePeer.java
--- libjava/gnu/java/awt/peer/gtk/GtkFramePeer.java	13 Jul 2003 15:09:20 -0000	1.3
+++ libjava/gnu/java/awt/peer/gtk/GtkFramePeer.java	28 Aug 2003 22:48:04 -0000
@@ -41,6 +41,7 @@
 import java.awt.Component;
 import java.awt.Frame;
 import java.awt.Graphics;
+import java.awt.Graphics2D;
 import java.awt.Image;
 import java.awt.MenuBar;
 import java.awt.Rectangle;
@@ -91,8 +92,8 @@
 
   public Graphics getGraphics ()
   {
-    GdkGraphics g = new GdkGraphics (this);
-    g.translateNative (-insets.left, -insets.top);
+    Graphics2D g = new GdkGraphics2D (this);
+    g.translate (-insets.left, -insets.top);
     return g;
   }
 
Index: libjava/gnu/java/awt/peer/gtk/GtkCanvasPeer.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/gnu/java/awt/peer/gtk/GtkCanvasPeer.java,v
retrieving revision 1.2
diff -u -r1.2 GtkCanvasPeer.java
--- libjava/gnu/java/awt/peer/gtk/GtkCanvasPeer.java	13 Jul 2003 15:09:20 -0000	1.2
+++ libjava/gnu/java/awt/peer/gtk/GtkCanvasPeer.java	28 Aug 2003 22:48:04 -0000
@@ -56,7 +56,7 @@
 
   public Graphics getGraphics ()
   {
-    return new GdkGraphics (this);
+    return new GdkGraphics2D (this);
   }
 
   public void handleEvent (AWTEvent event)
Index: libjava/gnu/java/awt/peer/gtk/GtkToolkit.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/gnu/java/awt/peer/gtk/GtkToolkit.java,v
retrieving revision 1.3
diff -u -r1.3 GtkToolkit.java
--- libjava/gnu/java/awt/peer/gtk/GtkToolkit.java	27 Jul 2003 19:04:42 -0000	1.3
+++ libjava/gnu/java/awt/peer/gtk/GtkToolkit.java	28 Aug 2003 22:48:04 -0000
@@ -56,6 +56,7 @@
 import gnu.java.awt.EmbeddedWindowSupport;
 import gnu.java.awt.peer.EmbeddedWindowPeer;
 import gnu.classpath.Configuration;
+import gnu.java.awt.peer.gtk.GdkPixbufDecoder;
 
 /* This class uses a deprecated method java.awt.peer.ComponentPeer.getPeer().
    This merits comment.  We are basically calling Sun's bluff on this one.
@@ -99,16 +100,12 @@
 
   public Image createImage (String filename)
   {
-    // FIXME - gcj local: GdkPixbufDecoder doesn't work.
-    // return new GtkImage (new GdkPixbufDecoder (filename), null);
-    return null;
+    return new GtkImage (new GdkPixbufDecoder (filename), null);
   }
 
   public Image createImage (URL url)
   {
-    // FIXME - gcj local: GdkPixbufDecoder doesn't work.
-    // return new GtkImage (new GdkPixbufDecoder (url), null);
-    return null;
+    return new GtkImage (new GdkPixbufDecoder (url), null);
   }
 
   public Image createImage (ImageProducer producer) 
@@ -144,18 +141,14 @@
 
   public Image getImage (String filename) 
   {
-    // FIXME - gcj local: GdkPixbufDecoder doesn't work.
-    // return new GtkImage (new GdkPixbufDecoder (filename), null);
-    return null;
+    return new GtkImage (new GdkPixbufDecoder (filename), null);
   }
 
   public Image getImage (URL url) 
   {
-    // FIXME - gcj local: GdkPixbufDecoder doesn't work.
-    // return new GtkImage (new GdkPixbufDecoder (url), null);
-    return null;
+    return new GtkImage (new GdkPixbufDecoder (url), null);
   }
-
+  
   public PrintJob getPrintJob (Frame frame, String jobtitle, Properties props) 
   {
     return null;
Index: libjava/jni/gtk-peer/gtkpeer.h
===================================================================
RCS file: /cvs/gcc/gcc/libjava/jni/gtk-peer/gtkpeer.h,v
retrieving revision 1.3
diff -u -r1.3 gtkpeer.h
--- libjava/jni/gtk-peer/gtkpeer.h	5 Aug 2003 18:04:09 -0000	1.3
+++ libjava/jni/gtk-peer/gtkpeer.h	28 Aug 2003 22:48:04 -0000
@@ -43,6 +43,9 @@
 #include <config.h>
 #include "native_state.h"
 
+#include <cairo.h>
+#include <gdk-pixbuf/gdk-pixbuf.h>
+
 #include <jni.h>
 
 #define RC_FILE      ".classpath-gtkrc"
@@ -79,6 +82,40 @@
   GdkColormap *cm;
   jint x_offset, y_offset;
 };
+
+/* 
+   A graphics2d struct is both simpler and uglier than a graphics
+   struct. 
+
+   Most of the graphics2d drawing state is held in the referenced cairo_t
+   and corresponding cairo_surface_t, so we can ignore it.
+
+   In addition to the cairo_t, we need to hold an extra reference to the
+   underlying GdkDrawable so its refcount matches the lifecycle of the java
+   Graphics object which is peering with us; also a reference to a byte
+   buffer and cairo_surface_t which contain the pattern you're drawing from
+   (if it exists).
+
+   Finally, it is possible that we are using a non-RENDER capable X server,
+   therefore we will be drawing to an cairo_surface_t which is actually a
+   pixbuf. When this is the case, the pointer to a GdkPixbuf will be
+   non-NULL and any drawing operation needs to be bracketed by pixbuf
+   load/save operations. If the GdkPixbuf pointer is NULL, we will treat
+   the cairo_surface_t as RENDER-capable.
+ */
+
+struct graphics2d
+{
+  cairo_t *cr;
+  cairo_surface_t *surface;
+  GdkDrawable *drawable;
+  GdkWindow *win;
+  GdkPixbuf *drawbuf;
+  char *pattern_pixels;
+  cairo_surface_t *pattern;
+  gboolean debug;
+};
+
 
 #define AWT_DEFAULT_CURSOR 0
 #define AWT_CROSSHAIR_CURSOR 1

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]