This fixes some bugs with copyArea, including the one that caused
JScrollpanes not to work.

2006-06-02  Sven de Marothy  <[EMAIL PROTECTED]>

        PR 27879 
        * gnu/java/awt/peer/gtk/CairoGraphics2D.java
        (copyArea): Implement.
        (copyAreaImpl, getRealBounds): New methods.
        * gnu/java/awt/peer/gtk/CairoSurfaceGraphics.java
        * gnu/java/awt/peer/gtk/ComponentGraphics.java
        * gnu/java/awt/peer/gtk/BufferedImageGraphics.java
        (copyAreaImpl, getRealBounds): Implement.
        * native/jni/gtk-peer/gnu_java_awt_peer_gtk_CairoSurface.c
        (nativeCopyArea): Reimplement.  
        

Index: gnu/java/awt/peer/gtk/BufferedImageGraphics.java
===================================================================
RCS file: /sources/classpath/classpath/gnu/java/awt/peer/gtk/BufferedImageGraphics.java,v
retrieving revision 1.6
diff -U3 -r1.6 BufferedImageGraphics.java
--- gnu/java/awt/peer/gtk/BufferedImageGraphics.java	2 Jun 2006 18:29:13 -0000	1.6
+++ gnu/java/awt/peer/gtk/BufferedImageGraphics.java	2 Jun 2006 22:49:13 -0000
@@ -48,6 +48,7 @@
 import java.awt.Shape;
 import java.awt.font.GlyphVector;
 import java.awt.geom.AffineTransform;
+import java.awt.geom.Rectangle2D;
 import java.awt.image.BufferedImage;
 import java.awt.image.DataBuffer;
 import java.awt.image.DataBufferInt;
@@ -204,35 +205,14 @@
   {
     return null;
   }
+
+  protected Rectangle2D getRealBounds()
+  {
+    return new Rectangle2D.Double(0.0, 0.0, imageWidth, imageHeight);
+  }
   
-  public void copyArea(int x, int y, int width, int height, int dx, int dy)
+  public void copyAreaImpl(int x, int y, int width, int height, int dx, int dy)
   {
-    // Return if outside the surface
-    if( x + dx > surface.width || y + dy > surface.height )
-      return;
-
-    if( x + dx + width < 0 || y + dy + height < 0 )
-      return;
-
-    // Clip edges if necessary 
-    if( x + dx < 0 ) // left
-      {
-	width = x + dx + width;
-	x = -dx;
-      }
-
-    if( y + dy < 0 ) // top
-      {
-	height = y + dy + height;
-	y = -dy;
-      }
-
-    if( x + dx + width >= surface.width ) // right
-      width = surface.width - dx - x;
-
-    if( y + dy + height >= surface.height ) // bottom
-      height = surface.height - dy - y;
-
     surface.copyAreaNative(x, y, width, height, dx, dy, surface.width);
     updateBufferedImage(x + dx, y + dy, width, height);
   }
Index: gnu/java/awt/peer/gtk/CairoGraphics2D.java
===================================================================
RCS file: /sources/classpath/classpath/gnu/java/awt/peer/gtk/CairoGraphics2D.java,v
retrieving revision 1.12
diff -U3 -r1.12 CairoGraphics2D.java
--- gnu/java/awt/peer/gtk/CairoGraphics2D.java	2 Jun 2006 18:29:13 -0000	1.12
+++ gnu/java/awt/peer/gtk/CairoGraphics2D.java	2 Jun 2006 22:49:15 -0000
@@ -292,7 +292,11 @@
 
   public abstract GraphicsConfiguration getDeviceConfiguration();
 
-  public abstract void copyArea(int x, int y, int width, int height, int dx, int dy);
+  protected abstract void copyAreaImpl(int x, int y, 
+				       int width, int height, int dx, int dy);
+
+
+  protected abstract Rectangle2D getRealBounds();
 
   ////// Native Methods ////////////////////////////////////////////////////
 
@@ -909,6 +913,60 @@
     fill(new RoundRectangle2D.Double(x, y, width, height, arcWidth, arcHeight));
   }
 
+  /**
+   * CopyArea - performs clipping to the native surface as a convenience 
+   * (requires getRealBounds). Then calls copyAreaImpl.
+   */
+  public void copyArea(int ox, int oy, int owidth, int oheight, 
+		       int odx, int ody)
+  {
+    Point2D pos = transform.transform(new Point2D.Double(ox, oy),
+				      (Point2D) null);
+    Point2D dim = transform.transform(new Point2D.Double(ox + owidth, 
+							 oy + oheight),
+				      (Point2D) null);
+    Point2D p2 = transform.transform(new Point2D.Double(ox + odx, oy + ody),
+				     (Point2D) null);
+    int x = (int)pos.getX();
+    int y = (int)pos.getY();
+    int width = (int)(dim.getX() - pos.getX());
+    int height = (int)(dim.getY() - pos.getY());
+    int dx = (int)(p2.getX() - pos.getX());
+    int dy = (int)(p2.getY() - pos.getY());
+
+    Rectangle2D r = getRealBounds();
+
+    if( width < 0 || height < 0 )
+      return;
+    // Return if outside the surface
+    if( x + dx > r.getWidth() || y + dy > r.getHeight() )
+      return;
+
+    if( x + dx + width < r.getX() || y + dy + height < r.getY() )
+      return;
+
+    // Clip edges if necessary 
+    if( x + dx < r.getX() ) // left
+      {
+	width = x + dx + width;
+	x = (int)r.getX() - dx;
+      }
+
+    if( y + dy < r.getY() ) // top
+      {
+	height = y + dy + height;
+	y = (int)r.getY() - dy;
+      }
+
+    if( x + dx + width >= r.getWidth() ) // right
+      width = (int)r.getWidth() - dx - x;
+
+    if( y + dy + height >= r.getHeight() ) // bottom
+      height = (int)r.getHeight() - dy - y;
+
+    copyAreaImpl(x, y, width, height, dx, dy);
+  }
+
   ///////////////////////// RENDERING HINTS ///////////////////////////////////
 
   /**
Index: gnu/java/awt/peer/gtk/CairoSurfaceGraphics.java
===================================================================
RCS file: /sources/classpath/classpath/gnu/java/awt/peer/gtk/CairoSurfaceGraphics.java,v
retrieving revision 1.3
diff -U3 -r1.3 CairoSurfaceGraphics.java
--- gnu/java/awt/peer/gtk/CairoSurfaceGraphics.java	2 Jun 2006 18:29:13 -0000	1.3
+++ gnu/java/awt/peer/gtk/CairoSurfaceGraphics.java	2 Jun 2006 22:49:15 -0000
@@ -44,6 +44,7 @@
 import java.awt.Point;
 import java.awt.Graphics2D;
 import java.awt.GraphicsConfiguration;
+import java.awt.geom.Rectangle2D;
 import java.awt.image.*;
 
 /**
@@ -87,34 +88,13 @@
     throw new UnsupportedOperationException();
   }
   
-  public void copyArea(int x, int y, int width, int height, int dx, int dy)
+  protected Rectangle2D getRealBounds()
   {
-    // Return if outside the surface
-    if( x + dx > surface.width || y + dy > surface.height )
-      return;
-
-    if( x + dx + width < 0 || y + dy + height < 0 )
-      return;
-
-    // Clip edges if necessary 
-    if( x + dx < 0 ) // left
-      {
-	width = x + dx + width;
-	x = -dx;
-      }
-
-    if( y + dy < 0 ) // top
-      {
-	height = y + dy + height;
-	y = -dy;
-      }
-
-    if( x + dx + width >= surface.width ) // right
-      width = surface.width - dx - x;
-
-    if( y + dy + height >= surface.height ) // bottom
-      height = surface.height - dy - y;
+    return new Rectangle2D.Double(0.0, 0.0, surface.width, surface.height);
+  }
 
+  public void copyAreaImpl(int x, int y, int width, int height, int dx, int dy)
+  {
     surface.copyAreaNative(x, y, width, height, dx, dy, surface.width);
   }
 }
Index: gnu/java/awt/peer/gtk/ComponentGraphics.java
===================================================================
RCS file: /sources/classpath/classpath/gnu/java/awt/peer/gtk/ComponentGraphics.java,v
retrieving revision 1.6
diff -U3 -r1.6 ComponentGraphics.java
--- gnu/java/awt/peer/gtk/ComponentGraphics.java	2 Jun 2006 18:29:13 -0000	1.6
+++ gnu/java/awt/peer/gtk/ComponentGraphics.java	2 Jun 2006 22:49:15 -0000
@@ -49,6 +49,7 @@
 import java.awt.font.FontRenderContext;
 import java.awt.font.GlyphVector;
 import java.awt.geom.AffineTransform;
+import java.awt.geom.Rectangle2D;
 import java.awt.image.BufferedImage;
 import java.awt.image.ImageObserver;
 import java.awt.image.ImagingOpException;
@@ -132,36 +133,13 @@
     return new ComponentGraphics(this);
   }
   
-  public void copyArea(int x, int y, int width, int height, int dx, int dy)
+  protected Rectangle2D getRealBounds()
   {
-    Rectangle r = component.awtComponent.getBounds();
-
-    // Return if outside the component
-    if( x + dx > r.width || y + dy > r.height )
-      return;
-
-    if( x + dx + width < 0 || y + dy + height < 0 )
-      return;
-
-    // Clip edges if necessary 
-    if( x + dx < 0 ) // left
-      {
-	width = x + dx + width;
-	x = -dx;
-      }
-
-    if( y + dy < 0 ) // top
-      {
-	height = y + dy + height;
-	y = -dy;
-      }
-
-    if( x + dx + width >= r.width ) // right
-      width = r.width - dx - x;
-
-    if( y + dy + height >= r.height ) // bottom
-      height = r.height - dy - y;
+    return component.awtComponent.getBounds();
+  }
 
+  public void copyAreaImpl(int x, int y, int width, int height, int dx, int dy)
+  {
     copyAreaNative(component, x, y, width, height, dx, dy);
   }
 
Index: native/jni/gtk-peer/gnu_java_awt_peer_gtk_CairoSurface.c
===================================================================
RCS file: /sources/classpath/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_CairoSurface.c,v
retrieving revision 1.12
diff -U3 -r1.12 gnu_java_awt_peer_gtk_CairoSurface.c
--- native/jni/gtk-peer/gnu_java_awt_peer_gtk_CairoSurface.c	2 Jun 2006 18:29:14 -0000	1.12
+++ native/jni/gtk-peer/gnu_java_awt_peer_gtk_CairoSurface.c	2 Jun 2006 22:49:24 -0000
@@ -240,18 +240,17 @@
   jint *pixeldata = (jint *)getNativeObject(env, obj, BUFFER);
   g_assert( pixeldata != NULL );
 
-  temp = g_malloc( w * sizeof( jint ) );
+  temp = g_malloc( h * w * 4 );
   g_assert( temp != NULL );
 
-  srcOffset = x + y * stride;
-  dstOffset = (x + dx) + (y + dy) * stride;
-  for( row = 0; row < h; row++)
-    {
-      memcpy( temp, pixeldata + srcOffset, w * sizeof(jint) );
-      memcpy( pixeldata + dstOffset, temp, w * sizeof(jint) );
-      srcOffset += stride;
-      dstOffset += stride;
-    }
+  srcOffset = x + (y * stride);
+  dstOffset = (x + dx) + ((y + dy) * stride);
+
+  for( row = 0; row < h; row++ )
+    memcpy( temp + (w * row), pixeldata + srcOffset + (stride * row), w * 4 );
+
+  for( row = 0; row < h; row++ )
+    memcpy( pixeldata + dstOffset + (stride * row), temp + (w * row), w * 4 );
 
   g_free( temp );
 }

Reply via email to