0N/A/*
2362N/A * Copyright (c) 1997, 2009, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
2362N/A * published by the Free Software Foundation. Oracle designates this
0N/A * particular file as subject to the "Classpath" exception as provided
2362N/A * by Oracle in the LICENSE file that accompanied this code.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A
0N/Apackage sun.awt;
0N/A
0N/Aimport java.awt.AWTException;
0N/Aimport java.awt.BufferCapabilities;
430N/Aimport java.awt.BufferCapabilities.FlipContents;
0N/Aimport java.awt.Component;
0N/Aimport java.awt.Toolkit;
0N/Aimport java.awt.GraphicsConfiguration;
0N/Aimport java.awt.GraphicsDevice;
0N/Aimport java.awt.Image;
0N/Aimport java.awt.ImageCapabilities;
0N/Aimport java.awt.Transparency;
0N/Aimport java.awt.image.BufferedImage;
0N/Aimport java.awt.image.ColorModel;
1221N/Aimport java.awt.color.ColorSpace;
1221N/Aimport java.awt.image.ComponentColorModel;
0N/Aimport java.awt.image.DirectColorModel;
1221N/Aimport java.awt.image.DataBuffer;
0N/Aimport java.awt.image.VolatileImage;
0N/Aimport java.awt.image.WritableRaster;
0N/Aimport java.awt.geom.AffineTransform;
0N/Aimport java.awt.Rectangle;
0N/Aimport sun.java2d.Disposer;
0N/Aimport sun.java2d.DisposerRecord;
0N/Aimport sun.java2d.SurfaceData;
0N/Aimport sun.java2d.loops.RenderLoops;
0N/Aimport sun.java2d.loops.SurfaceType;
0N/Aimport sun.java2d.loops.CompositeType;
0N/Aimport sun.java2d.x11.X11SurfaceData;
0N/Aimport sun.awt.image.OffScreenImage;
0N/Aimport sun.awt.image.SunVolatileImage;
0N/Aimport sun.awt.image.SurfaceManager;
0N/Aimport sun.awt.X11ComponentPeer;
0N/A
0N/A/**
0N/A * This is an implementation of a GraphicsConfiguration object for a
0N/A * single X11 visual.
0N/A *
0N/A * @see GraphicsEnvironment
0N/A * @see GraphicsDevice
0N/A */
0N/Apublic class X11GraphicsConfig extends GraphicsConfiguration
0N/A implements SurfaceManager.ProxiedGraphicsConfig
0N/A{
0N/A protected X11GraphicsDevice screen;
0N/A protected int visual;
0N/A int depth;
0N/A int colormap;
0N/A ColorModel colorModel;
0N/A long aData;
0N/A boolean doubleBuffer;
0N/A private Object disposerReferent = new Object();
0N/A private BufferCapabilities bufferCaps;
0N/A private static ImageCapabilities imageCaps =
0N/A new ImageCapabilities(X11SurfaceData.isAccelerationEnabled());
0N/A
0N/A // will be set on native level from init()
0N/A protected int bitsPerPixel;
0N/A
0N/A protected SurfaceType surfaceType;
0N/A
0N/A public RenderLoops solidloops;
0N/A
0N/A public static X11GraphicsConfig getConfig(X11GraphicsDevice device,
0N/A int visualnum, int depth,
0N/A int colormap,
0N/A boolean doubleBuffer)
0N/A {
0N/A return new X11GraphicsConfig(device, visualnum, depth, colormap, doubleBuffer);
0N/A }
0N/A
0N/A /*
0N/A * Note this method is currently here for backward compatability
0N/A * as this was the method used in jdk 1.2 beta4 to create the
0N/A * X11GraphicsConfig objects. Java3D code had called this method
0N/A * explicitly so without this, if a user tries to use JDK1.2 fcs
0N/A * with Java3D beta1, a NoSuchMethod execption is thrown and
0N/A * the program exits. REMOVE this method after Java3D fcs is
0N/A * released!
0N/A */
0N/A public static X11GraphicsConfig getConfig(X11GraphicsDevice device,
0N/A int visualnum, int depth,
0N/A int colormap, int type)
0N/A {
0N/A return new X11GraphicsConfig(device, visualnum, depth, colormap, false);
0N/A }
0N/A
0N/A private native int getNumColors();
0N/A private native void init(int visualNum, int screen);
0N/A private native ColorModel makeColorModel();
0N/A
0N/A protected X11GraphicsConfig(X11GraphicsDevice device,
0N/A int visualnum, int depth,
0N/A int colormap, boolean doubleBuffer)
0N/A {
0N/A this.screen = device;
0N/A this.visual = visualnum;
0N/A this.doubleBuffer = doubleBuffer;
0N/A this.depth = depth;
0N/A this.colormap = colormap;
0N/A init (visualnum, screen.getScreen());
0N/A
0N/A // add a record to the Disposer so that we destroy the native
0N/A // AwtGraphicsConfigData when this object goes away (i.e. after a
0N/A // display change event)
0N/A long x11CfgData = getAData();
0N/A Disposer.addRecord(disposerReferent,
0N/A new X11GCDisposerRecord(x11CfgData));
0N/A }
0N/A
0N/A /**
0N/A * Return the graphics device associated with this configuration.
0N/A */
0N/A public GraphicsDevice getDevice() {
0N/A return screen;
0N/A }
0N/A
0N/A /**
0N/A * Returns the visual id associated with this configuration.
0N/A */
0N/A public int getVisual () {
0N/A return visual;
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Returns the depth associated with this configuration.
0N/A */
0N/A public int getDepth () {
0N/A return depth;
0N/A }
0N/A
0N/A /**
0N/A * Returns the colormap associated with this configuration.
0N/A */
0N/A public int getColormap () {
0N/A return colormap;
0N/A }
0N/A
0N/A /**
0N/A * Returns a number of bits allocated per pixel
0N/A * (might be different from depth)
0N/A */
0N/A public int getBitsPerPixel() {
0N/A return bitsPerPixel;
0N/A }
0N/A
0N/A public synchronized SurfaceType getSurfaceType() {
0N/A if (surfaceType != null) {
0N/A return surfaceType;
0N/A }
0N/A
0N/A surfaceType = X11SurfaceData.getSurfaceType(this, Transparency.OPAQUE);
0N/A return surfaceType;
0N/A }
0N/A
0N/A public Object getProxyKey() {
0N/A return screen.getProxyKeyFor(getSurfaceType());
0N/A }
0N/A
0N/A /**
0N/A * Return the RenderLoops this type of destination uses for
0N/A * solid fills and strokes.
0N/A */
0N/A public synchronized RenderLoops getSolidLoops(SurfaceType stype) {
0N/A if (solidloops == null) {
0N/A solidloops = SurfaceData.makeRenderLoops(SurfaceType.OpaqueColor,
0N/A CompositeType.SrcNoEa,
0N/A stype);
0N/A }
0N/A return solidloops;
0N/A }
0N/A
0N/A /**
0N/A * Returns the color model associated with this configuration.
0N/A */
0N/A public synchronized ColorModel getColorModel() {
0N/A if (colorModel == null) {
0N/A // Force SystemColors to be resolved before we create the CM
0N/A java.awt.SystemColor.window.getRGB();
0N/A // This method, makeColorModel(), can return null if the
0N/A // toolkit is not initialized yet.
0N/A // The toolkit will then call back to this routine after it
0N/A // is initialized and makeColorModel() should return a non-null
0N/A // colorModel.
0N/A colorModel = makeColorModel();
0N/A if (colorModel == null)
0N/A colorModel = Toolkit.getDefaultToolkit ().getColorModel ();
0N/A }
0N/A
0N/A return colorModel;
0N/A }
0N/A
0N/A /**
0N/A * Returns the color model associated with this configuration that
0N/A * supports the specified transparency.
0N/A */
0N/A public ColorModel getColorModel(int transparency) {
0N/A switch (transparency) {
0N/A case Transparency.OPAQUE:
0N/A return getColorModel();
0N/A case Transparency.BITMASK:
0N/A return new DirectColorModel(25, 0xff0000, 0xff00, 0xff, 0x1000000);
0N/A case Transparency.TRANSLUCENT:
0N/A return ColorModel.getRGBdefault();
0N/A default:
0N/A return null;
0N/A }
0N/A }
0N/A
1221N/A public static DirectColorModel createDCM32(int rMask, int gMask, int bMask,
1221N/A int aMask, boolean aPre) {
1221N/A return new DirectColorModel(
1221N/A ColorSpace.getInstance(ColorSpace.CS_sRGB),
1221N/A 32, rMask, gMask, bMask, aMask, aPre, DataBuffer.TYPE_INT);
1221N/A }
1221N/A
1221N/A public static ComponentColorModel createABGRCCM() {
1221N/A ColorSpace cs = ColorSpace.getInstance(ColorSpace.CS_sRGB);
1221N/A int[] nBits = {8, 8, 8, 8};
1221N/A int[] bOffs = {3, 2, 1, 0};
1221N/A return new ComponentColorModel(cs, nBits, true, true,
1221N/A Transparency.TRANSLUCENT,
1221N/A DataBuffer.TYPE_BYTE);
1221N/A }
1221N/A
0N/A /**
0N/A * Returns the default Transform for this configuration. This
0N/A * Transform is typically the Identity transform for most normal
0N/A * screens. Device coordinates for screen and printer devices will
0N/A * have the origin in the upper left-hand corner of the target region of
0N/A * the device, with X coordinates
0N/A * increasing to the right and Y coordinates increasing downwards.
0N/A * For image buffers, this Transform will be the Identity transform.
0N/A */
0N/A public AffineTransform getDefaultTransform() {
0N/A return new AffineTransform();
0N/A }
0N/A
0N/A /**
0N/A *
0N/A * Returns a Transform that can be composed with the default Transform
0N/A * of a Graphics2D so that 72 units in user space will equal 1 inch
0N/A * in device space.
0N/A * Given a Graphics2D, g, one can reset the transformation to create
0N/A * such a mapping by using the following pseudocode:
0N/A * <pre>
0N/A * GraphicsConfiguration gc = g.getGraphicsConfiguration();
0N/A *
0N/A * g.setTransform(gc.getDefaultTransform());
0N/A * g.transform(gc.getNormalizingTransform());
0N/A * </pre>
0N/A * Note that sometimes this Transform will be identity (e.g. for
0N/A * printers or metafile output) and that this Transform is only
0N/A * as accurate as the information supplied by the underlying system.
0N/A * For image buffers, this Transform will be the Identity transform,
0N/A * since there is no valid distance measurement.
0N/A */
0N/A public AffineTransform getNormalizingTransform() {
0N/A double xscale = getXResolution(screen.getScreen()) / 72.0;
0N/A double yscale = getYResolution(screen.getScreen()) / 72.0;
0N/A return new AffineTransform(xscale, 0.0, 0.0, yscale, 0.0, 0.0);
0N/A }
0N/A
0N/A private native double getXResolution(int screen);
0N/A private native double getYResolution(int screen);
0N/A
0N/A public long getAData() {
0N/A return aData;
0N/A }
0N/A
0N/A public String toString() {
0N/A return ("X11GraphicsConfig[dev="+screen+
0N/A ",vis=0x"+Integer.toHexString(visual)+
0N/A "]");
0N/A }
0N/A
0N/A /*
0N/A * Initialize JNI field and method IDs for fields that may be
0N/A * accessed from C.
0N/A */
0N/A private static native void initIDs();
0N/A
0N/A static {
0N/A initIDs ();
0N/A }
0N/A
0N/A public Rectangle getBounds() {
0N/A return pGetBounds(screen.getScreen());
0N/A }
0N/A
0N/A public native Rectangle pGetBounds(int screenNum);
0N/A
0N/A private static class XDBECapabilities extends BufferCapabilities {
0N/A public XDBECapabilities() {
0N/A super(imageCaps, imageCaps, FlipContents.UNDEFINED);
0N/A }
0N/A }
0N/A
0N/A public BufferCapabilities getBufferCapabilities() {
0N/A if (bufferCaps == null) {
0N/A if (doubleBuffer) {
0N/A bufferCaps = new XDBECapabilities();
0N/A } else {
0N/A bufferCaps = super.getBufferCapabilities();
0N/A }
0N/A }
0N/A return bufferCaps;
0N/A }
0N/A
0N/A public ImageCapabilities getImageCapabilities() {
0N/A return imageCaps;
0N/A }
0N/A
0N/A public boolean isDoubleBuffered() {
0N/A return doubleBuffer;
0N/A }
0N/A
0N/A private static native void dispose(long x11ConfigData);
0N/A
0N/A private static class X11GCDisposerRecord implements DisposerRecord {
0N/A private long x11ConfigData;
0N/A public X11GCDisposerRecord(long x11CfgData) {
0N/A this.x11ConfigData = x11CfgData;
0N/A }
0N/A public synchronized void dispose() {
0N/A if (x11ConfigData != 0L) {
0N/A X11GraphicsConfig.dispose(x11ConfigData);
0N/A x11ConfigData = 0L;
0N/A }
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * The following methods are invoked from {M,X}Toolkit.java and
0N/A * X11ComponentPeer.java rather than having the X11-dependent
0N/A * implementations hardcoded in those classes. This way the appropriate
0N/A * actions are taken based on the peer's GraphicsConfig, whether it is
0N/A * an X11GraphicsConfig or a GLXGraphicsConfig.
0N/A */
0N/A
0N/A /**
0N/A * Creates a new SurfaceData that will be associated with the given
0N/A * X11ComponentPeer.
0N/A */
0N/A public SurfaceData createSurfaceData(X11ComponentPeer peer) {
0N/A return X11SurfaceData.createData(peer);
0N/A }
0N/A
0N/A /**
0N/A * Creates a new hidden-acceleration image of the given width and height
0N/A * that is associated with the target Component.
0N/A */
0N/A public Image createAcceleratedImage(Component target,
0N/A int width, int height)
0N/A {
0N/A // As of 1.7 we no longer create pmoffscreens here...
0N/A ColorModel model = getColorModel(Transparency.OPAQUE);
0N/A WritableRaster wr =
0N/A model.createCompatibleWritableRaster(width, height);
0N/A return new OffScreenImage(target, model, wr,
0N/A model.isAlphaPremultiplied());
0N/A }
0N/A
0N/A /**
0N/A * The following methods correspond to the multibuffering methods in
0N/A * X11ComponentPeer.java...
0N/A */
0N/A
0N/A private native long createBackBuffer(long window, int swapAction);
0N/A private native void swapBuffers(long window, int swapAction);
0N/A
0N/A /**
0N/A * Attempts to create an XDBE-based backbuffer for the given peer. If
0N/A * the requested configuration is not natively supported, an AWTException
0N/A * is thrown. Otherwise, if the backbuffer creation is successful, a
0N/A * handle to the native backbuffer is returned.
0N/A */
0N/A public long createBackBuffer(X11ComponentPeer peer,
0N/A int numBuffers, BufferCapabilities caps)
0N/A throws AWTException
0N/A {
0N/A if (!X11GraphicsDevice.isDBESupported()) {
0N/A throw new AWTException("Page flipping is not supported");
0N/A }
0N/A if (numBuffers > 2) {
0N/A throw new AWTException(
0N/A "Only double or single buffering is supported");
0N/A }
0N/A BufferCapabilities configCaps = getBufferCapabilities();
0N/A if (!configCaps.isPageFlipping()) {
0N/A throw new AWTException("Page flipping is not supported");
0N/A }
0N/A
0N/A long window = peer.getContentWindow();
0N/A int swapAction = getSwapAction(caps.getFlipContents());
0N/A
0N/A return createBackBuffer(window, swapAction);
0N/A }
0N/A
0N/A /**
0N/A * Destroys the backbuffer object represented by the given handle value.
0N/A */
0N/A public native void destroyBackBuffer(long backBuffer);
0N/A
0N/A /**
0N/A * Creates a VolatileImage that essentially wraps the target Component's
0N/A * backbuffer, using the provided backbuffer handle.
0N/A */
0N/A public VolatileImage createBackBufferImage(Component target,
0N/A long backBuffer)
0N/A {
0N/A return new SunVolatileImage(target,
0N/A target.getWidth(), target.getHeight(),
215N/A Long.valueOf(backBuffer));
0N/A }
0N/A
0N/A /**
0N/A * Performs the native XDBE flip operation for the given target Component.
0N/A */
0N/A public void flip(X11ComponentPeer peer,
0N/A Component target, VolatileImage xBackBuffer,
430N/A int x1, int y1, int x2, int y2,
0N/A BufferCapabilities.FlipContents flipAction)
0N/A {
0N/A long window = peer.getContentWindow();
0N/A int swapAction = getSwapAction(flipAction);
0N/A swapBuffers(window, swapAction);
0N/A }
0N/A
0N/A /**
0N/A * Maps the given FlipContents constant to the associated XDBE swap
0N/A * action constant.
0N/A */
0N/A private static int getSwapAction(
0N/A BufferCapabilities.FlipContents flipAction) {
0N/A if (flipAction == BufferCapabilities.FlipContents.BACKGROUND) {
0N/A return 0x01;
0N/A } else if (flipAction == BufferCapabilities.FlipContents.PRIOR) {
0N/A return 0x02;
0N/A } else if (flipAction == BufferCapabilities.FlipContents.COPIED) {
0N/A return 0x03;
0N/A } else {
0N/A return 0x00; // UNDEFINED
0N/A }
0N/A }
1045N/A
1045N/A @Override
1045N/A public boolean isTranslucencyCapable() {
1045N/A return isTranslucencyCapable(getAData());
1045N/A }
1045N/A
1045N/A private native boolean isTranslucencyCapable(long x11ConfigData);
0N/A}