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/] [XGraphicsConfiguration.java] - Blame information for rev 769

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 769 jeremybenn
/* XGraphicsConfiguration.java -- GraphicsConfiguration for X
2
   Copyright (C) 2006 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.Display;
41
import gnu.x11.Screen;
42
 
43
import java.awt.Dimension;
44
import java.awt.GraphicsConfiguration;
45
import java.awt.GraphicsDevice;
46
import java.awt.Point;
47
import java.awt.Rectangle;
48
import java.awt.Transparency;
49
import java.awt.color.ColorSpace;
50
import java.awt.geom.AffineTransform;
51
import java.awt.image.BufferedImage;
52
import java.awt.image.ColorModel;
53
import java.awt.image.ComponentColorModel;
54
import java.awt.image.ComponentSampleModel;
55
import java.awt.image.DataBuffer;
56
import java.awt.image.Raster;
57
import java.awt.image.SampleModel;
58
import java.awt.image.VolatileImage;
59
import java.awt.image.WritableRaster;
60
 
61
public class XGraphicsConfiguration
62
    extends GraphicsConfiguration
63
{
64
 
65
  XGraphicsDevice device;
66
 
67
  XGraphicsConfiguration(XGraphicsDevice dev)
68
  {
69
    device = dev;
70
  }
71
 
72
  public GraphicsDevice getDevice()
73
  {
74
    return device;
75
  }
76
 
77
  public BufferedImage createCompatibleImage(int w, int h)
78
  {
79
    return createCompatibleImage(w, h, Transparency.OPAQUE);
80
  }
81
 
82
  public BufferedImage createCompatibleImage(int w, int h, int transparency)
83
  {
84
    BufferedImage bi;
85
    switch (transparency)
86
      {
87
        case Transparency.OPAQUE:
88
          DataBuffer buffer = new ZPixmapDataBuffer(w, h);
89
          SampleModel sm = new ComponentSampleModel(DataBuffer.TYPE_BYTE, w, h,
90
                                                    4, w * 4,
91
                                                    new int[]{0, 1, 2, 3 });
92
          ColorSpace cs = ColorSpace.getInstance(ColorSpace.CS_LINEAR_RGB);
93
          ColorModel cm = new ComponentColorModel(cs, true, false,
94
                                                  Transparency.OPAQUE,
95
                                                  DataBuffer.TYPE_BYTE);
96
          WritableRaster raster = Raster.createWritableRaster(sm, buffer,
97
                                                              new Point(0, 0));
98
          bi = new BufferedImage(cm, raster, false, null);
99
          break;
100
        case Transparency.BITMASK:
101
        case Transparency.TRANSLUCENT:
102
          bi = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);
103
          break;
104
        default:
105
          throw new IllegalArgumentException("Illegal transparency: "
106
                                             + transparency);
107
      }
108
    return bi;
109
  }
110
 
111
  public VolatileImage createCompatibleVolatileImage(int w, int h)
112
  {
113
    return createCompatibleVolatileImage(w, h, Transparency.OPAQUE);
114
  }
115
 
116
  public VolatileImage createCompatibleVolatileImage(int width, int height,
117
                                                     int transparency)
118
  {
119
    VolatileImage im;
120
    switch (transparency)
121
      {
122
      case Transparency.OPAQUE:
123
        im = new PixmapVolatileImage(width, height);
124
        break;
125
      case Transparency.BITMASK:
126
      case Transparency.TRANSLUCENT:
127
        throw new UnsupportedOperationException("Not yet implemented");
128
      default:
129
        throw new IllegalArgumentException("Unknown transparency type: "
130
                                           + transparency);
131
      }
132
    return im;
133
  }
134
 
135
  public ColorModel getColorModel()
136
  {
137
    // TODO: Implement this.
138
    throw new UnsupportedOperationException("Not yet implemented.");
139
  }
140
 
141
  public ColorModel getColorModel(int transparency)
142
  {
143
    // TODO: Implement this.
144
    throw new UnsupportedOperationException("Not yet implemented.");
145
  }
146
 
147
  public AffineTransform getDefaultTransform()
148
  {
149
    return new AffineTransform();
150
  }
151
 
152
  public AffineTransform getNormalizingTransform()
153
  {
154
    // TODO: Implement this.
155
    throw new UnsupportedOperationException("Not yet implemented.");
156
  }
157
 
158
  public Rectangle getBounds()
159
  {
160
    Display d = device.getDisplay();
161
    Screen screen = d.default_screen;
162
 
163
    return new Rectangle(0, 0, screen.width, screen.height);
164
  }
165
 
166
  /**
167
   * Determines the size of the primary screen.
168
   *
169
   * @return the size of the primary screen
170
   */
171
  Dimension getSize()
172
  {
173
    // TODO: A GraphicsConfiguration should correspond to a Screen instance.
174
    Display d = device.getDisplay();
175
    Screen screen = d.default_screen;
176
    int w = screen.width;
177
    int h = screen.height;
178
    return new Dimension(w, h);
179
  }
180
 
181
  /**
182
   * Determines the resolution of the primary screen in pixel-per-inch.
183
   *
184
   * @returnthe resolution of the primary screen in pixel-per-inch
185
   */
186
  int getResolution()
187
  {
188
    Display d = device.getDisplay();
189
    Screen screen = d.default_screen;
190
    int w = screen.width * 254;
191
    int h = screen.height * 254;
192
    int wmm = screen.width_in_mm * 10;
193
    int hmm = screen.height_in_mm * 10;
194
    int xdpi = w / wmm;
195
    int ydpi = h / hmm;
196
    int dpi = (xdpi + ydpi) / 2;
197
    return dpi;
198
  }
199
 
200
}

powered by: WebSVN 2.1.0

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