[cairo-commit] CairoJava/test/org/cairographics/cairo/test TestCairo.java, 1.4, 1.5 TestCairoImage.java, 1.3, 1.4

Soorya Kuloor commit at pdx.freedesktop.org
Fri Apr 30 10:56:31 PDT 2004


Committed by: skuloor

Update of /cvs/cairo/CairoJava/test/org/cairographics/cairo/test
In directory pdx:/tmp/cvs-serv16737/test/org/cairographics/cairo/test

Modified Files:
	TestCairo.java TestCairoImage.java 
Log Message:
1. Modified the test code to use the new Surface classes.
2. Added Glitz test

Index: TestCairo.java
===================================================================
RCS file: /cvs/cairo/CairoJava/test/org/cairographics/cairo/test/TestCairo.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** a/TestCairo.java	23 Dec 2003 17:37:15 -0000	1.4
--- b/TestCairo.java	30 Apr 2004 17:56:29 -0000	1.5
***************
*** 33,36 ****
--- 33,37 ----
  import org.cairographics.cairo.Cairo;
  import org.cairographics.cairo.CairoFont;
+ import org.cairographics.cairo.CairoSWTSurface;
  import org.eclipse.swt.events.PaintEvent;
  import org.eclipse.swt.events.PaintListener;
***************
*** 48,61 ****
          this.addPaintListener(new PaintListener() {
              public void paintControl(PaintEvent e) {
!                 TestCairo.this.repaint(e);
              }
          });
      }
  
!     public void repaint(PaintEvent e) {
          org.eclipse.swt.graphics.Rectangle size = getBounds();
          Image img = new Image(getDisplay(), size.width, size.height);
!         Cairo cairo = new Cairo(img);
! 
          //cairo.save();
  
--- 49,64 ----
          this.addPaintListener(new PaintListener() {
              public void paintControl(PaintEvent e) {
!                 TestCairo.this.repaintUsingImage(e);
              }
          });
      }
  
!     public void repaintUsingImage(PaintEvent e) {
          org.eclipse.swt.graphics.Rectangle size = getBounds();
          Image img = new Image(getDisplay(), size.width, size.height);
!         CairoSWTSurface sf = new CairoSWTSurface(img);
!         Cairo cairo = new Cairo();
!         cairo.setTarget(sf);
!         
          //cairo.save();
  
***************
*** 87,90 ****
--- 90,95 ----
          cairo.showText(msg);
          double[] exts = cairo.getTextExtents(msg);
+         
+         /*
          System.out.println(
              "DEBUG: extents: ["
***************
*** 100,103 ****
--- 105,109 ----
                  + ", "
                  + exts[5]);
+         */
          cairo.rect(200 + exts[0], 200 + exts[1], exts[2], exts[3], 0, 0);
          cairo.stroke();
***************
*** 111,115 ****
  
          cairo.dispose();
! 
          e.gc.drawImage(img, 0, 0);
          img.dispose();
--- 117,122 ----
  
          cairo.dispose();
!         sf.dispose();
!         
          e.gc.drawImage(img, 0, 0);
          img.dispose();

Index: TestCairoImage.java
===================================================================
RCS file: /cvs/cairo/CairoJava/test/org/cairographics/cairo/test/TestCairoImage.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** a/TestCairoImage.java	7 Aug 2003 20:43:38 -0000	1.3
--- b/TestCairoImage.java	30 Apr 2004 17:56:29 -0000	1.4
***************
*** 32,36 ****
  
  import org.cairographics.cairo.Cairo;
! import org.cairographics.cairo.CairoImage;
  import org.cairographics.cairo.CairoSurface;
  
--- 32,39 ----
  
  import org.cairographics.cairo.Cairo;
! import org.cairographics.cairo.CairoGlitzSurface;
! import org.cairographics.cairo.CairoImageBuffer;
! import org.cairographics.cairo.CairoImageBufferSurface;
! import org.cairographics.cairo.CairoSWTSurface;
  import org.cairographics.cairo.CairoSurface;
  
***************
*** 44,48 ****
  
  /**
!  * This class tests Xr by doing some basic drawings
   */
  public class TestCairoImage extends Shell {
--- 47,51 ----
  
  /**
!  * This class tests Cairo by doing some basic drawings
   */
  public class TestCairoImage extends Shell {
***************
*** 52,56 ****
          this.addPaintListener(new PaintListener() {
              public void paintControl(PaintEvent e) {
!                 TestCairoImage.this.paintWithCairoImage(e);
              }
          });
--- 55,60 ----
          this.addPaintListener(new PaintListener() {
              public void paintControl(PaintEvent e) {
!                 //TestCairoImage.this.paintWithCairoImage(e);
!                 TestCairoImage.this.paintWithGlitz(e);
              }
          });
***************
*** 174,179 ****
          long t1 = System.currentTimeMillis();
  
!         CairoImage img = new CairoImage(e.width, e.height);
!         CairoSurface sf = new CairoSurface(img);
          Cairo cairo = new Cairo(sf);
          cairo.translate(-e.x, -e.y);
--- 178,183 ----
          long t1 = System.currentTimeMillis();
  
!         CairoImageBuffer img = new CairoImageBuffer(e.width, e.height);
!         CairoSurface sf = new CairoImageBufferSurface(img);
          Cairo cairo = new Cairo(sf);
          cairo.translate(-e.x, -e.y);
***************
*** 194,197 ****
--- 198,236 ----
      }
  
+     private boolean firstPaintDone = false;
+     
+     /**
+      * Paints using a local image buffer. Does not use the Render extension, uses libic.
+      * 
+      * @param e The paint event object.
+      */
+     public void paintWithGlitz(PaintEvent e) {
+         org.eclipse.swt.graphics.Rectangle size = getBounds();
+ 
+         long t1 = System.currentTimeMillis();
+ 
+         CairoGlitzSurface sf = new CairoGlitzSurface(this);
+         Cairo cairo = new Cairo(sf);
+         sf.flush(0, 0, this.getSize().x, this.getSize().y);
+         //cairo.translate(-e.x, -e.y);
+         
+         long t2 = System.currentTimeMillis();
+         draw_stuff(cairo);
+ 
+         sf.flush(0, 0, this.getSize().x, this.getSize().y);
+         cairo.dispose();
+         
+         long t3 = System.currentTimeMillis();
+ 
+         sf.dispose();
+ 
+         System.out.println("CairoImage drawing time: " + (t3 - t1) + " msecs");
+         
+         if (! firstPaintDone) {
+             redraw();
+             firstPaintDone = true;
+         }
+     }
+ 
      /**
       * Paints on a pixmap. Required Render extension.
***************
*** 205,209 ****
          long t1 = System.currentTimeMillis();
  
!         Cairo cairo = new Cairo(img);
          cairo.translate(-e.x, -e.y);
  
--- 244,249 ----
          long t1 = System.currentTimeMillis();
  
!         CairoSWTSurface sf = new CairoSWTSurface(img);
!         Cairo cairo = new Cairo(sf);
          cairo.translate(-e.x, -e.y);
  
***************
*** 212,216 ****
  
          cairo.dispose();
! 
          long t3 = System.currentTimeMillis();
  
--- 252,256 ----
  
          cairo.dispose();
!         sf.dispose();
          long t3 = System.currentTimeMillis();
  
***************
*** 222,231 ****
  
      public static void main(String[] args) {
-         System.out.println("Inside main...");
          Display display = Display.getDefault();
  
          TestCairoImage shell = new TestCairoImage();
          shell.open();
!         shell.setText("Xr/Image Test");
          shell.setSize(600, 550);
  
--- 262,270 ----
  
      public static void main(String[] args) {
          Display display = Display.getDefault();
  
          TestCairoImage shell = new TestCairoImage();
          shell.open();
!         shell.setText("Cairo Image Test");
          shell.setSize(600, 550);
  
***************
*** 234,238 ****
                  display.sleep();
          }
-         System.out.println("Main done...");
      }
  }
--- 273,276 ----





More information about the cairo-commit mailing list