X11GraphicsConfig.java revision 215
/*
* Copyright 1997-2007 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
/**
* This is an implementation of a GraphicsConfiguration object for a
* single X11 visual.
*
* @see GraphicsEnvironment
* @see GraphicsDevice
*/
public class X11GraphicsConfig extends GraphicsConfiguration
implements SurfaceManager.ProxiedGraphicsConfig
{
protected X11GraphicsDevice screen;
protected int visual;
int depth;
int colormap;
long aData;
boolean doubleBuffer;
private BufferCapabilities bufferCaps;
private static ImageCapabilities imageCaps =
// will be set on native level from init()
protected int bitsPerPixel;
protected SurfaceType surfaceType;
public RenderLoops solidloops;
int colormap,
boolean doubleBuffer)
{
}
/*
* Note this method is currently here for backward compatability
* as this was the method used in jdk 1.2 beta4 to create the
* X11GraphicsConfig objects. Java3D code had called this method
* explicitly so without this, if a user tries to use JDK1.2 fcs
* with Java3D beta1, a NoSuchMethod execption is thrown and
* the program exits. REMOVE this method after Java3D fcs is
* released!
*/
{
}
private native int getNumColors();
private native ColorModel makeColorModel();
int colormap, boolean doubleBuffer)
{
this.doubleBuffer = doubleBuffer;
// add a record to the Disposer so that we destroy the native
// AwtGraphicsConfigData when this object goes away (i.e. after a
// display change event)
long x11CfgData = getAData();
new X11GCDisposerRecord(x11CfgData));
}
/**
* Return the graphics device associated with this configuration.
*/
public GraphicsDevice getDevice() {
return screen;
}
/**
* Returns the visual id associated with this configuration.
*/
public int getVisual () {
return visual;
}
/**
* Returns the depth associated with this configuration.
*/
public int getDepth () {
return depth;
}
/**
* Returns the colormap associated with this configuration.
*/
public int getColormap () {
return colormap;
}
/**
* Returns a number of bits allocated per pixel
* (might be different from depth)
*/
public int getBitsPerPixel() {
return bitsPerPixel;
}
public synchronized SurfaceType getSurfaceType() {
if (surfaceType != null) {
return surfaceType;
}
return surfaceType;
}
public Object getProxyKey() {
}
/**
* Return the RenderLoops this type of destination uses for
* solid fills and strokes.
*/
if (solidloops == null) {
stype);
}
return solidloops;
}
/**
* Returns the color model associated with this configuration.
*/
public synchronized ColorModel getColorModel() {
if (colorModel == null) {
// Force SystemColors to be resolved before we create the CM
// This method, makeColorModel(), can return null if the
// toolkit is not initialized yet.
// The toolkit will then call back to this routine after it
// is initialized and makeColorModel() should return a non-null
// colorModel.
colorModel = makeColorModel();
if (colorModel == null)
}
return colorModel;
}
/**
* Returns the color model associated with this configuration that
* supports the specified transparency.
*/
switch (transparency) {
case Transparency.OPAQUE:
return getColorModel();
case Transparency.BITMASK:
case Transparency.TRANSLUCENT:
return ColorModel.getRGBdefault();
default:
return null;
}
}
/**
* Returns the default Transform for this configuration. This
* Transform is typically the Identity transform for most normal
* screens. Device coordinates for screen and printer devices will
* have the origin in the upper left-hand corner of the target region of
* the device, with X coordinates
* increasing to the right and Y coordinates increasing downwards.
* For image buffers, this Transform will be the Identity transform.
*/
public AffineTransform getDefaultTransform() {
return new AffineTransform();
}
/**
*
* Returns a Transform that can be composed with the default Transform
* of a Graphics2D so that 72 units in user space will equal 1 inch
* in device space.
* Given a Graphics2D, g, one can reset the transformation to create
* such a mapping by using the following pseudocode:
* <pre>
* GraphicsConfiguration gc = g.getGraphicsConfiguration();
*
* g.setTransform(gc.getDefaultTransform());
* g.transform(gc.getNormalizingTransform());
* </pre>
* Note that sometimes this Transform will be identity (e.g. for
* printers or metafile output) and that this Transform is only
* as accurate as the information supplied by the underlying system.
* For image buffers, this Transform will be the Identity transform,
* since there is no valid distance measurement.
*/
public AffineTransform getNormalizingTransform() {
}
private native double getXResolution(int screen);
private native double getYResolution(int screen);
public long getAData() {
return aData;
}
return ("X11GraphicsConfig[dev="+screen+
"]");
}
/*
* Initialize JNI field and method IDs for fields that may be
* accessed from C.
*/
private static native void initIDs();
static {
initIDs ();
}
}
private static class XDBECapabilities extends BufferCapabilities {
public XDBECapabilities() {
}
}
public BufferCapabilities getBufferCapabilities() {
if (bufferCaps == null) {
if (doubleBuffer) {
bufferCaps = new XDBECapabilities();
} else {
bufferCaps = super.getBufferCapabilities();
}
}
return bufferCaps;
}
public ImageCapabilities getImageCapabilities() {
return imageCaps;
}
public boolean isDoubleBuffered() {
return doubleBuffer;
}
private static native void dispose(long x11ConfigData);
private static class X11GCDisposerRecord implements DisposerRecord {
private long x11ConfigData;
public X11GCDisposerRecord(long x11CfgData) {
this.x11ConfigData = x11CfgData;
}
public synchronized void dispose() {
if (x11ConfigData != 0L) {
x11ConfigData = 0L;
}
}
}
/**
* The following methods are invoked from {M,X}Toolkit.java and
* X11ComponentPeer.java rather than having the X11-dependent
* implementations hardcoded in those classes. This way the appropriate
* actions are taken based on the peer's GraphicsConfig, whether it is
* an X11GraphicsConfig or a GLXGraphicsConfig.
*/
/**
* Creates a new SurfaceData that will be associated with the given
* X11ComponentPeer.
*/
}
/**
* Creates a new hidden-acceleration image of the given width and height
* that is associated with the target Component.
*/
{
// As of 1.7 we no longer create pmoffscreens here...
}
/**
* The following methods correspond to the multibuffering methods in
*/
/**
* Attempts to create an XDBE-based backbuffer for the given peer. If
* the requested configuration is not natively supported, an AWTException
* is thrown. Otherwise, if the backbuffer creation is successful, a
* handle to the native backbuffer is returned.
*/
throws AWTException
{
if (!X11GraphicsDevice.isDBESupported()) {
throw new AWTException("Page flipping is not supported");
}
if (numBuffers > 2) {
throw new AWTException(
"Only double or single buffering is supported");
}
if (!configCaps.isPageFlipping()) {
throw new AWTException("Page flipping is not supported");
}
}
/**
* Destroys the backbuffer object represented by the given handle value.
*/
public native void destroyBackBuffer(long backBuffer);
/**
* Creates a VolatileImage that essentially wraps the target Component's
* backbuffer, using the provided backbuffer handle.
*/
long backBuffer)
{
return new SunVolatileImage(target,
}
/**
* Performs the native XDBE flip operation for the given target Component.
*/
{
}
/**
* Maps the given FlipContents constant to the associated XDBE swap
* action constant.
*/
private static int getSwapAction(
return 0x01;
return 0x02;
return 0x03;
} else {
return 0x00; // UNDEFINED
}
}
}