OSDN Git Service

53bcd739d9e8d48adf35c094eb0ab1723dc1cbcf
[pf3gnuchains/gcc-fork.git] / libjava / classpath / gnu / java / awt / peer / gtk / GtkVolatileImage.java
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   /**
54    * Don't touch, accessed from native code.
55    */
56   long nativePointer;
57
58   native long init(GtkComponentPeer component, int width, int height);
59
60   native void destroy();
61
62   native int[] getPixels();
63
64   native void copyArea( int x, int y, int w, int h, int dx, int dy );
65
66   native void drawVolatile( long ptr, int x, int y, int w, int h );
67   
68   public GtkVolatileImage(GtkComponentPeer component, 
69                           int width, int height, ImageCapabilities caps)
70   {
71     this.width = width;
72     this.height = height;
73     this.caps = caps;
74     nativePointer = init( component, width, height );
75   }
76
77   public GtkVolatileImage(int width, int height, ImageCapabilities caps)
78   {
79     this(null, width, height, caps);
80   }
81
82   public GtkVolatileImage(int width, int height)
83   {
84     this(null, width, height, null);
85   }
86
87   public void finalize()
88   {
89     dispose();
90   }
91
92   public void dispose()
93   {
94     destroy();
95   }
96
97   public BufferedImage getSnapshot()
98   {
99     CairoSurface cs = new CairoSurface( width, height );
100     cs.setPixels( getPixels() );
101     return CairoSurface.getBufferedImage( cs );
102   }
103
104   public Graphics getGraphics()
105   {
106     return createGraphics();
107   }
108
109   public Graphics2D createGraphics()
110   {
111     return new VolatileImageGraphics( this );
112   }
113
114   public int validate(GraphicsConfiguration gc)
115   {
116     return VolatileImage.IMAGE_OK;
117   }
118
119   public boolean contentsLost()
120   {
121     return false;
122   }
123
124   public ImageCapabilities getCapabilities()
125   {
126     return caps;
127   }
128
129   public int getWidth()
130   {
131     return width;
132   }
133
134   public int getHeight()
135   {
136     return height;
137   }
138
139   public int getWidth(java.awt.image.ImageObserver observer)
140   {
141     return width;
142   }
143   
144   public int getHeight(java.awt.image.ImageObserver observer)
145   {
146     return height;
147   }
148
149   public Object getProperty(String name, ImageObserver observer)
150   {
151     return null;
152   }
153 }