libjava/ChangeLog:
[official-gcc.git] / libjava / classpath / gnu / java / awt / peer / x / XImage.java
blobfa94d00c131c569f5c5fe2208173f718eba46e63
1 /* XImage.java -- Image impl for X Pixmaps
2 Copyright (C) 2006 Free Software Foundation, Inc.
4 This file is part of GNU Classpath.
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.
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.
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.
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.
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. */
39 package gnu.java.awt.peer.x;
41 import gnu.x11.Pixmap;
42 import gnu.x11.image.ZPixmap;
44 import java.awt.Graphics;
45 import java.awt.GraphicsEnvironment;
46 import java.awt.Image;
48 import java.awt.image.ColorModel;
49 import java.awt.image.ImageConsumer;
50 import java.awt.image.ImageObserver;
51 import java.awt.image.ImageProducer;
53 import java.util.Hashtable;
54 import java.util.Vector;
56 public class XImage
57 extends Image
60 Pixmap pixmap;
62 private Hashtable properties;
64 XImage(int w, int h)
66 GraphicsEnvironment env =
67 GraphicsEnvironment.getLocalGraphicsEnvironment();
68 XGraphicsDevice dev = (XGraphicsDevice) env.getDefaultScreenDevice();
69 pixmap = new Pixmap(dev.getDisplay(), w, h);
72 public int getWidth(ImageObserver observer)
74 return pixmap.width;
77 public int getHeight(ImageObserver observer)
79 return pixmap.height;
82 public ImageProducer getSource()
84 return new XImageProducer();
87 /**
88 * Creates an XGraphics for drawing on this XImage.
90 * @return an XGraphics for drawing on this XImage
92 public Graphics getGraphics()
94 XGraphics2D g = new XGraphics2D(pixmap);
95 return g;
98 public Object getProperty(String name, ImageObserver observer)
100 Object val = null;
101 if (properties != null)
102 val = properties.get(val);
103 return val;
106 public void flush()
108 // TODO: Implement this.
109 throw new UnsupportedOperationException("Not yet implemented.");
112 protected void finalize()
114 pixmap.free();
117 protected class XImageProducer implements ImageProducer
119 private Vector<ImageConsumer> consumers = new Vector<ImageConsumer>();
121 public void addConsumer(ImageConsumer ic)
123 if (ic != null && !isConsumer(ic))
124 this.consumers.add(ic);
127 public boolean isConsumer(ImageConsumer ic)
129 return this.consumers.contains(ic);
132 public void removeConsumer(ImageConsumer ic)
134 if (ic != null)
135 this.consumers.remove(ic);
138 public void requestTopDownLeftRightResend(ImageConsumer ic)
140 /* just ignore the call */
143 public void startProduction(ImageConsumer ic)
145 this.addConsumer(ic);
147 for (ImageConsumer consumer : this.consumers)
149 int width = XImage.this.getWidth(null);
150 int height = XImage.this.getHeight(null);
152 XGraphics2D graphics = (XGraphics2D) getGraphics();
153 ColorModel model = graphics.getColorModel();
154 graphics.dispose();
156 ZPixmap zpixmap = (ZPixmap)
157 XImage.this.pixmap.image(0, 0, width, height,
158 0xffffffff,
159 gnu.x11.image.Image.Format.ZPIXMAP);
161 int size = zpixmap.get_data_length();
162 System.out.println("size: " + size + ", w = " + width + ", h = " + height);
164 int [] pixel = new int[size];
165 for (int i = 0; i < size; i++)
166 pixel[i] = zpixmap.get_data_element(i);
168 consumer.setHints(ImageConsumer.SINGLEPASS);
170 consumer.setDimensions(width, height);
171 consumer.setPixels(0, 0, width, height, model, pixel, 0, width);
172 consumer.imageComplete(ImageConsumer.STATICIMAGEDONE);
175 System.out.println("done!");