Source for gnu.java.awt.peer.gtk.GtkVolatileImage

   1: /* GtkVolatileImage.java -- wraps an X pixmap
   2:    Copyright (C) 2005  Free Software Foundation, Inc.
   3: 
   4: This file is part of GNU Classpath.
   5: 
   6: GNU Classpath is free software; you can redistribute it and/or modify
   7: it under the terms of the GNU General Public License as published by
   8: the Free Software Foundation; either version 2, or (at your option)
   9: any later version.
  10: 
  11: GNU Classpath is distributed in the hope that it will be useful, but
  12: WITHOUT ANY WARRANTY; without even the implied warranty of
  13: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  14: General Public License for more details.
  15: 
  16: You should have received a copy of the GNU General Public License
  17: along with GNU Classpath; see the file COPYING.  If not, write to the
  18: Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  19: 02110-1301 USA.
  20: 
  21: Linking this library statically or dynamically with other modules is
  22: making a combined work based on this library.  Thus, the terms and
  23: conditions of the GNU General Public License cover the whole
  24: combination.
  25: 
  26: As a special exception, the copyright holders of this library give you
  27: permission to link this library with independent modules to produce an
  28: executable, regardless of the license terms of these independent
  29: modules, and to copy and distribute the resulting executable under
  30: terms of your choice, provided that you also meet, for each linked
  31: independent module, the terms and conditions of the license of that
  32: module.  An independent module is a module which is not derived from
  33: or based on this library.  If you modify this library, you may extend
  34: this exception to your version of the library, but you are not
  35: obligated to do so.  If you do not wish to do so, delete this
  36: exception statement from your version. */
  37: 
  38: package gnu.java.awt.peer.gtk;
  39: 
  40: import java.awt.ImageCapabilities;
  41: import java.awt.Graphics;
  42: import java.awt.Graphics2D;
  43: import java.awt.GraphicsConfiguration;
  44: import java.awt.image.BufferedImage;
  45: import java.awt.image.ImageObserver;
  46: import java.awt.image.VolatileImage;
  47: 
  48: public class GtkVolatileImage extends VolatileImage
  49: {
  50:   int width, height;
  51:   private ImageCapabilities caps;
  52: 
  53:   final GtkComponentPeer component;
  54: 
  55:   /**
  56:    * Don't touch, accessed from native code.
  57:    */
  58:   long nativePointer;
  59: 
  60:   native long init(GtkComponentPeer component, int width, int height);
  61: 
  62:   native void destroy(long pointer);
  63: 
  64:   native int[] nativeGetPixels(long pointer);
  65:   public int[] getPixels()
  66:   {
  67:     return nativeGetPixels(nativePointer);
  68:   }
  69: 
  70:   native void nativeCopyArea(long pointer, int x, int y, int w, int h, int dx,
  71:                              int dy );
  72:   public void copyArea(int x, int y, int w, int h, int dx, int dy)
  73:   {
  74:     nativeCopyArea(nativePointer, x, y, w, h, dx, dy);
  75:   }
  76: 
  77:   native void nativeDrawVolatile(long pointer, long srcPtr, int x, int y,
  78:                                  int w, int h );
  79:   public void drawVolatile(long srcPtr, int x, int y, int w, int h )
  80:   {
  81:     nativeDrawVolatile(nativePointer, srcPtr, x, y, w, h);
  82:   }
  83: 
  84:   public GtkVolatileImage(GtkComponentPeer component, 
  85:               int width, int height, ImageCapabilities caps)
  86:   {
  87:     this.width = width;
  88:     this.height = height;
  89:     this.caps = caps;
  90:     this.component = component;
  91:     nativePointer = init( component, width, height );
  92:   }
  93: 
  94:   public GtkVolatileImage(int width, int height, ImageCapabilities caps)
  95:   {
  96:     this(null, width, height, caps);
  97:   }
  98: 
  99:   public GtkVolatileImage(int width, int height)
 100:   {
 101:     this(null, width, height, null);
 102:   }
 103: 
 104:   public void finalize()
 105:   {
 106:     dispose();
 107:   }
 108: 
 109:   public void dispose()
 110:   {
 111:     destroy(nativePointer);
 112:   }
 113: 
 114:   public BufferedImage getSnapshot()
 115:   {
 116:     CairoSurface cs = new CairoSurface( width, height );
 117:     cs.setPixels( getPixels() );
 118:     return CairoSurface.getBufferedImage( cs );
 119:   }
 120: 
 121:   public Graphics getGraphics()
 122:   {
 123:     return createGraphics();
 124:   }
 125: 
 126:   public Graphics2D createGraphics()
 127:   {
 128:     return new VolatileImageGraphics( this );
 129:   }
 130: 
 131:   public int validate(GraphicsConfiguration gc)
 132:   {
 133:     return VolatileImage.IMAGE_OK;
 134:   }
 135: 
 136:   public boolean contentsLost()
 137:   {
 138:     return false;
 139:   }
 140: 
 141:   public ImageCapabilities getCapabilities()
 142:   {
 143:     return caps;
 144:   }
 145: 
 146:   public int getWidth()
 147:   {
 148:     return width;
 149:   }
 150: 
 151:   public int getHeight()
 152:   {
 153:     return height;
 154:   }
 155: 
 156:   public int getWidth(java.awt.image.ImageObserver observer)
 157:   {
 158:     return width;
 159:   }
 160:   
 161:   public int getHeight(java.awt.image.ImageObserver observer)
 162:   {
 163:     return height;
 164:   }
 165: 
 166:   public Object getProperty(String name, ImageObserver observer)
 167:   {
 168:     return null;
 169:   }
 170: }