1 /* Copyright (C) 2000, 2003 Free Software Foundation
3 This file is part of libgcj.
5 This software is copyrighted work licensed under the terms of the
6 Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
11 import java
.awt
.Image
;
12 import java
.awt
.Graphics
;
13 import java
.awt
.Graphics2D
;
14 import java
.awt
.GraphicsConfiguration
;
15 import java
.awt
.image
.ColorModel
;
16 import java
.awt
.image
.ImageObserver
;
17 import java
.awt
.image
.ImageProducer
;
18 import java
.util
.Hashtable
;
19 import gnu
.awt
.j2d
.DirectRasterGraphics
;
20 import gnu
.awt
.j2d
.Graphics2DImpl
;
21 import gnu
.awt
.j2d
.IntegerGraphicsState
;
22 import gnu
.gcj
.xlib
.Drawable
;
23 import gnu
.gcj
.xlib
.Pixmap
;
24 import gnu
.gcj
.xlib
.Screen
;
25 import gnu
.gcj
.xlib
.Visual
;
27 /** Image class for xlib off-screen buffers.
28 * The image is stored in a server-side pixmap for best performance.
29 * This class supports getGraphics, so you can draw on the pixmap, and is
30 * specially handled when doing drawImage, so that the image copy is done
31 * entirely in the X server.
32 * This class does not support rasterization, for which you'd need an XImage.
34 * @author scott gilbertson <scottg@mantatest.com> <sgilbertson@cogeco.ca>
36 public class XOffScreenImage
extends Image
37 implements IntegerGraphicsState
.ScreenCoupledImage
39 private Pixmap pixmap
;
40 private XGraphicsConfiguration config
;
44 /** Create a new XOffScreenImage
45 * @param config Graphics configuration, to compare against on-screen
46 * components and to create the appropriate Graphics
47 * @param drawable The drawable with which the image is compatible
48 * @param width The width of the image
49 * @param height The height of the image
51 XOffScreenImage (XGraphicsConfiguration config
, Drawable drawable
, int width
, int height
)
56 pixmap
= new Pixmap (drawable
, width
, height
, drawable
.getDepth ());
59 /** Get the pixmap which contains this image
62 public Pixmap
getPixmap ()
67 /** Flushes (that is, destroys) any resources used for this image. This
68 * includes the actual image data.
72 // FIXME: should dispose pixmap
76 /** Returns a graphics context object for drawing an off-screen object.
77 * This method is only valid for off-screen objects.
79 * @return a graphics context object for an off-screen object
80 * @see Graphics#createImage(int, int)
82 public Graphics
getGraphics ()
84 DirectRasterGraphics gfxDevice
= new XGraphics (pixmap
, config
);
85 IntegerGraphicsState igState
= new IntegerGraphicsState (gfxDevice
);
86 Graphics2DImpl gfx2d
= new Graphics2DImpl (config
);
87 gfx2d
.setState (igState
);
91 /** Returns the height of the image, or -1 if it is unknown. If the
92 * image height is unknown, the observer object will be notified when
95 * @param observer the image observer for this object
96 * @return the height in pixels
97 * @see #getWidth(ImageObserver)
99 public int getHeight (ImageObserver observer
)
104 /** Returns the height of the image, or -1 if it is unknown. If the
105 * image height is unknown, the observer object will be notified when
106 * the value is known.
108 * @return the height in pixels
111 public int getHeight ()
116 /** Returns the image producer object for this object. The producer is the
117 * object which generates pixels for this image.
119 * @return the image producer for this object
121 public ImageProducer
getSource ()
123 throw new UnsupportedOperationException ("getSource not supported");
126 /** Returns the width of the image, or -1 if it is unknown. If the
127 * image width is unknown, the observer object will be notified when
128 * the value is known.
130 * @param observer the image observer for this object
131 * @return the width in pixels
132 * @see #getHeight(ImageObserver)
134 public int getWidth (ImageObserver observer
)
139 /** Returns the width of the image, or -1 if it is unknown. If the
140 * image width is unknown, the observer object will be notified when
141 * the value is known.
143 * @return the width in pixels
146 public int getWidth ()
151 /** This method requests a named property for an object. The value of the
152 * property is returned. The value <code>UndefinedProperty</code> is
153 * returned if there is no property with the specified name. The value
154 * <code>null</code> is returned if the properties for the object are
155 * not yet known. In this case, the specified image observer is notified
156 * when the properties are known.
158 * @param name the requested property name
159 * @param observer the image observer for this object
160 * @return the named property, if available
161 * @see #UndefinedProperty
163 public Object
getProperty (String name
, ImageObserver observer
)
168 /** Get the GraphicsConfiguration to which this image is coupled
169 * @return the GraphicsConfiguration
171 public GraphicsConfiguration
getGraphicsConfiguration ()