OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-dev/] [or1k-gcc/] [libjava/] [classpath/] [gnu/] [java/] [awt/] [peer/] [x/] [PixmapVolatileImage.java] - Blame information for rev 769

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 769 jeremybenn
/* PixmapVolatileImage.java -- VolatileImage implementation around a Pixmap
2
   Copyright (C) 2007 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.x;
39
 
40
import gnu.x11.GC;
41
import gnu.x11.Pixmap;
42
import gnu.x11.image.Image;
43
import gnu.x11.image.ZPixmap;
44
 
45
import java.awt.Graphics2D;
46
import java.awt.GraphicsConfiguration;
47
import java.awt.GraphicsEnvironment;
48
import java.awt.ImageCapabilities;
49
import java.awt.Point;
50
import java.awt.Transparency;
51
import java.awt.color.ColorSpace;
52
import java.awt.image.BufferedImage;
53
import java.awt.image.ColorModel;
54
import java.awt.image.ComponentColorModel;
55
import java.awt.image.ComponentSampleModel;
56
import java.awt.image.DataBuffer;
57
import java.awt.image.ImageObserver;
58
import java.awt.image.Raster;
59
import java.awt.image.SampleModel;
60
import java.awt.image.VolatileImage;
61
import java.awt.image.WritableRaster;
62
 
63
/**
64
 * A {@link VolatileImage} implementation that wraps an X Pixmap.
65
 */
66
class PixmapVolatileImage
67
  extends VolatileImage
68
{
69
 
70
  /**
71
   * The shared capabilities instance.
72
   */
73
  private static final ImageCapabilities caps = new ImageCapabilities(true);
74
 
75
  /**
76
   * The underlying pixmap.
77
   */
78
  private Pixmap pixmap;
79
 
80
  /**
81
   * Creates a new PixmapVolatileImage.
82
   *
83
   * @param w the width of the image
84
   * @param h the height of the image
85
   */
86
  public PixmapVolatileImage(int w, int h)
87
  {
88
    GraphicsEnvironment env =
89
      GraphicsEnvironment.getLocalGraphicsEnvironment();
90
    XGraphicsDevice dev = (XGraphicsDevice) env.getDefaultScreenDevice();
91
    pixmap = new Pixmap(dev.getDisplay(), w, h);
92
 
93
    // Clear pixmap.
94
    GC gc = new GC(pixmap);
95
    gc.set_foreground(0xffffffff);
96
    pixmap.fill_rectangle(gc, 0, 0, w, h);
97
 
98
  }
99
 
100
  @Override
101
  public boolean contentsLost()
102
  {
103
    return false;
104
  }
105
 
106
  @Override
107
  public Graphics2D createGraphics()
108
  {
109
    return new XGraphics2D(pixmap);
110
  }
111
 
112
  @Override
113
  public ImageCapabilities getCapabilities()
114
  {
115
    return caps;
116
  }
117
 
118
  @Override
119
  public int getHeight()
120
  {
121
    return pixmap.height;
122
  }
123
 
124
  @Override
125
  public BufferedImage getSnapshot()
126
  {
127
    // TODO: Support non-24-bit resolutions.
128
    int w = pixmap.width;
129
    int h = pixmap.height;
130
    ZPixmap zpixmap = (ZPixmap) pixmap.image(0, 0, w, h, 0xffffffff,
131
                                             Image.Format.ZPIXMAP);
132
    DataBuffer buffer = new ZPixmapDataBuffer(zpixmap);
133
    SampleModel sm = new ComponentSampleModel(DataBuffer.TYPE_BYTE, w, h, 4,
134
                                              w * 4,
135
                                              new int[]{0, 1, 2, 3 });
136
    ColorSpace cs = ColorSpace.getInstance(ColorSpace.CS_LINEAR_RGB);
137
    ColorModel cm = new ComponentColorModel(cs, true, false,
138
                                            Transparency.OPAQUE,
139
                                            DataBuffer.TYPE_BYTE);
140
    WritableRaster raster = Raster.createWritableRaster(sm, buffer,
141
                                                        new Point(0, 0));
142
    return new BufferedImage(cm, raster, false, null);
143
  }
144
 
145
  @Override
146
  public int getWidth()
147
  {
148
    return pixmap.width;
149
  }
150
 
151
  @Override
152
  public int validate(GraphicsConfiguration gc)
153
  {
154
    // TODO: Check compatibility with gc.
155
    return IMAGE_OK;
156
  }
157
 
158
  @Override
159
  public int getHeight(ImageObserver observer)
160
  {
161
    return getHeight();
162
  }
163
 
164
  @Override
165
  public Object getProperty(String name, ImageObserver observer)
166
  {
167
    return null;
168
  }
169
 
170
  @Override
171
  public int getWidth(ImageObserver observer)
172
  {
173
    return getWidth();
174
  }
175
 
176
  /**
177
   * Returns the underlying X pixmap. This is used for the graphics code.
178
   *
179
   * @return the underlying X pixmap
180
   */
181
  Pixmap getPixmap()
182
  {
183
    return pixmap;
184
  }
185
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.