Win32GraphicsConfig.java revision 430
0N/A/*
0N/A * Copyright 1997-2008 Sun Microsystems Microsystems, Inc. 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
0N/A * published by the Free Software Foundation. Sun designates this
0N/A * particular file as subject to the "Classpath" exception as provided
0N/A * by Sun 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
873N/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 *
0N/A * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
0N/A * CA 95054 USA or visit www.sun.com if you need additional information or
0N/A * have any questions.
5065N/A */
0N/A
0N/Apackage sun.awt;
0N/A
0N/Aimport java.awt.AWTException;
0N/Aimport java.awt.BufferCapabilities;
0N/Aimport java.awt.Component;
0N/Aimport java.awt.Graphics;
0N/Aimport java.awt.GraphicsConfiguration;
0N/Aimport java.awt.GraphicsDevice;
2636N/Aimport java.awt.GraphicsEnvironment;
2636N/Aimport java.awt.Image;
2636N/Aimport java.awt.ImageCapabilities;
2636N/Aimport java.awt.Rectangle;
0N/Aimport java.awt.Toolkit;
2636N/Aimport java.awt.Transparency;
2636N/Aimport java.awt.Window;
2636N/Aimport java.awt.geom.AffineTransform;
2636N/Aimport java.awt.image.BufferedImage;
2636N/Aimport java.awt.image.ColorModel;
0N/Aimport java.awt.image.DirectColorModel;
2636N/Aimport java.awt.image.Raster;
2636N/Aimport java.awt.image.VolatileImage;
2636N/Aimport java.awt.image.WritableRaster;
2636N/A
2636N/Aimport sun.awt.windows.WComponentPeer;
2636N/Aimport sun.awt.image.OffScreenImage;
2636N/Aimport sun.awt.image.SunVolatileImage;
2636N/Aimport sun.awt.image.SurfaceManager;
2636N/Aimport sun.java2d.SurfaceData;
2636N/Aimport sun.java2d.InvalidPipeException;
2636N/Aimport sun.java2d.loops.RenderLoops;
2636N/Aimport sun.java2d.loops.SurfaceType;
2636N/Aimport sun.java2d.loops.CompositeType;
2636N/Aimport sun.java2d.windows.GDIWindowSurfaceData;
2636N/A
2636N/A/**
2636N/A * This is an implementation of a GraphicsConfiguration object for a
0N/A * single Win32 visual.
2636N/A *
2636N/A * @see GraphicsEnvironment
2636N/A * @see GraphicsDevice
0N/A */
0N/Apublic class Win32GraphicsConfig extends GraphicsConfiguration
2636N/A implements DisplayChangedListener, SurfaceManager.ProxiedGraphicsConfig
2636N/A{
2636N/A protected Win32GraphicsDevice screen;
0N/A protected int visual; //PixelFormatID
2636N/A protected RenderLoops solidloops;
2636N/A
2636N/A private static native void initIDs();
2636N/A
2636N/A static {
2636N/A initIDs();
2636N/A }
2636N/A
2636N/A /**
2636N/A * Returns a Win32GraphicsConfiguration object with the given device
2636N/A * and PixelFormat. Note that this method does NOT check to ensure that
2636N/A * the returned Win32GraphicsConfig will correctly support rendering into a
2636N/A * Java window. This method is provided so that client code can do its
2636N/A * own checking as to the appropriateness of a particular PixelFormat.
2636N/A * Safer access to Win32GraphicsConfigurations is provided by
2636N/A * Win32GraphicsDevice.getConfigurations().
2636N/A */
2636N/A public static Win32GraphicsConfig getConfig(Win32GraphicsDevice device,
2636N/A int pixFormatID)
2636N/A {
2636N/A return new Win32GraphicsConfig(device, pixFormatID);
2636N/A }
0N/A
0N/A /**
2636N/A * @deprecated as of JDK version 1.3
2636N/A * replaced by <code>getConfig()</code>
2636N/A */
0N/A @Deprecated
0N/A public Win32GraphicsConfig(GraphicsDevice device, int visualnum) {
2636N/A this.screen = (Win32GraphicsDevice)device;
2636N/A this.visual = visualnum;
2636N/A ((Win32GraphicsDevice)device).addDisplayChangedListener(this);
2636N/A }
2636N/A
2636N/A /**
2636N/A * Return the graphics device associated with this configuration.
2636N/A */
2636N/A public GraphicsDevice getDevice() {
0N/A return screen;
2636N/A }
2636N/A
2636N/A /**
2636N/A * Return the PixelFormatIndex this GraphicsConfig uses
2636N/A */
2636N/A public int getVisual() {
2636N/A return visual;
2636N/A }
2636N/A
2636N/A public Object getProxyKey() {
2636N/A return screen;
2636N/A }
2636N/A
2636N/A /**
2636N/A * Return the RenderLoops this type of destination uses for
2636N/A * solid fills and strokes.
2636N/A */
2636N/A private SurfaceType sTypeOrig = null;
0N/A public synchronized RenderLoops getSolidLoops(SurfaceType stype) {
0N/A if (solidloops == null || sTypeOrig != stype) {
2636N/A solidloops = SurfaceData.makeRenderLoops(SurfaceType.OpaqueColor,
2636N/A CompositeType.SrcNoEa,
2636N/A stype);
2636N/A sTypeOrig = stype;
2636N/A }
2636N/A return solidloops;
2636N/A }
2636N/A
2636N/A /**
2636N/A * Returns the color model associated with this configuration.
2636N/A */
0N/A public synchronized ColorModel getColorModel() {
0N/A return screen.getColorModel();
2636N/A }
2636N/A
2636N/A /**
2636N/A * Returns a new color model for this configuration. This call
0N/A * is only used internally, by images and components that are
2636N/A * associated with the graphics device. When attributes of that
2636N/A * device change (for example, when the device palette is updated),
0N/A * then this device-based color model will be updated internally
0N/A * to reflect the new situation.
2636N/A */
2636N/A public ColorModel getDeviceColorModel() {
2636N/A return screen.getDynamicColorModel();
2636N/A }
0N/A
2636N/A /**
2636N/A * Returns the color model associated with this configuration that
2636N/A * supports the specified transparency.
2636N/A */
0N/A public ColorModel getColorModel(int transparency) {
2636N/A switch (transparency) {
2636N/A case Transparency.OPAQUE:
2636N/A return getColorModel();
0N/A case Transparency.BITMASK:
2636N/A return new DirectColorModel(25, 0xff0000, 0xff00, 0xff, 0x1000000);
2636N/A case Transparency.TRANSLUCENT:
2636N/A return ColorModel.getRGBdefault();
0N/A default:
2636N/A return null;
2636N/A }
2636N/A }
2636N/A
2636N/A /**
2636N/A * Returns the default Transform for this configuration. This
2636N/A * Transform is typically the Identity transform for most normal
2636N/A * screens. Device coordinates for screen and printer devices will
2636N/A * have the origin in the upper left-hand corner of the target region of
0N/A * the device, with X coordinates
2636N/A * increasing to the right and Y coordinates increasing downwards.
2636N/A * For image buffers, this Transform will be the Identity transform.
2636N/A */
2636N/A public AffineTransform getDefaultTransform() {
2636N/A return new AffineTransform();
2636N/A }
2636N/A
2636N/A /**
2636N/A *
2636N/A * Returns a Transform that can be composed with the default Transform
2636N/A * of a Graphics2D so that 72 units in user space will equal 1 inch
2636N/A * in device space.
2636N/A * Given a Graphics2D, g, one can reset the transformation to create
2636N/A * such a mapping by using the following pseudocode:
2636N/A * <pre>
2636N/A * GraphicsConfiguration gc = g.getGraphicsConfiguration();
2636N/A *
2636N/A * g.setTransform(gc.getDefaultTransform());
2636N/A * g.transform(gc.getNormalizingTransform());
2636N/A * </pre>
2636N/A * Note that sometimes this Transform will be identity (e.g. for
2636N/A * printers or metafile output) and that this Transform is only
2636N/A * as accurate as the information supplied by the underlying system.
2636N/A * For image buffers, this Transform will be the Identity transform,
2636N/A * since there is no valid distance measurement.
2636N/A */
2636N/A public AffineTransform getNormalizingTransform() {
2636N/A Win32GraphicsEnvironment ge = (Win32GraphicsEnvironment)
2636N/A GraphicsEnvironment.getLocalGraphicsEnvironment();
0N/A double xscale = ge.getXResolution() / 72.0;
2636N/A double yscale = ge.getYResolution() / 72.0;
2636N/A return new AffineTransform(xscale, 0.0, 0.0, yscale, 0.0, 0.0);
2636N/A }
2636N/A
0N/A public String toString() {
2636N/A return (super.toString()+"[dev="+screen+",pixfmt="+visual+"]");
2636N/A }
2636N/A
2636N/A private native Rectangle getBounds(int screen);
2636N/A
2636N/A public Rectangle getBounds() {
2636N/A return getBounds(screen.getScreen());
2636N/A }
2636N/A
2636N/A public synchronized void displayChanged() {
2636N/A solidloops = null;
2636N/A }
2636N/A
2636N/A public void paletteChanged() {}
2636N/A
2636N/A /**
2636N/A * The following methods are invoked from WComponentPeer.java rather
2636N/A * than having the Win32-dependent implementations hardcoded in that
0N/A * class. This way the appropriate actions are taken based on the peer's
2636N/A * GraphicsConfig, whether it is a Win32GraphicsConfig or a
2636N/A * WGLGraphicsConfig.
2636N/A */
2636N/A
2636N/A /**
2636N/A * Creates a new SurfaceData that will be associated with the given
2636N/A * WComponentPeer.
2636N/A */
2636N/A public SurfaceData createSurfaceData(WComponentPeer peer,
2636N/A int numBackBuffers)
2636N/A {
2636N/A return GDIWindowSurfaceData.createData(peer);
2636N/A }
2636N/A
2636N/A /**
2636N/A * Creates a new managed image of the given width and height
2636N/A * that is associated with the target Component.
2636N/A */
2636N/A public Image createAcceleratedImage(Component target,
2636N/A int width, int height)
2636N/A {
2636N/A ColorModel model = getColorModel(Transparency.OPAQUE);
2636N/A WritableRaster wr =
2636N/A model.createCompatibleWritableRaster(width, height);
2636N/A return new OffScreenImage(target, model, wr,
2636N/A model.isAlphaPremultiplied());
2636N/A }
2636N/A
2636N/A /**
2636N/A * The following methods correspond to the multibuffering methods in
2636N/A * WComponentPeer.java...
2636N/A */
2636N/A
2636N/A /**
2636N/A * Checks that the requested configuration is natively supported; if not,
2636N/A * an AWTException is thrown.
2636N/A */
2636N/A public void assertOperationSupported(Component target,
0N/A int numBuffers,
0N/A BufferCapabilities caps)
2636N/A throws AWTException
2636N/A {
2636N/A // the default pipeline doesn't support flip buffer strategy
0N/A throw new AWTException(
0N/A "The operation requested is not supported");
2636N/A }
2636N/A
2636N/A /**
0N/A * This method is called from WComponentPeer when a surface data is replaced
2636N/A * REMIND: while the default pipeline doesn't support flipping, it may
2636N/A * happen that the accelerated device may have this graphics config
2636N/A * (like if the device restoration failed when one device exits fs mode
2636N/A * while others remain).
2636N/A */
2636N/A public VolatileImage createBackBuffer(WComponentPeer peer) {
2636N/A Component target = (Component)peer.getTarget();
2636N/A return new SunVolatileImage(target,
2636N/A target.getWidth(), target.getHeight(),
2636N/A Boolean.TRUE);
2636N/A }
2636N/A
2636N/A /**
2636N/A * Performs the native flip operation for the given target Component.
2636N/A *
2636N/A * REMIND: we should really not get here because that would mean that
2636N/A * a FLIP BufferStrategy has been created, and one could only be created
2636N/A * if accelerated pipeline is present but in some rare (and transitional)
2636N/A * cases it may happen that the accelerated graphics device may have a
0N/A * default graphics configuraiton, so this is just a precaution.
0N/A */
2636N/A public void flip(WComponentPeer peer,
2636N/A Component target, VolatileImage backBuffer,
2636N/A int x1, int y1, int x2, int y2,
2636N/A BufferCapabilities.FlipContents flipAction)
2636N/A {
2636N/A if (flipAction == BufferCapabilities.FlipContents.COPIED ||
2636N/A flipAction == BufferCapabilities.FlipContents.UNDEFINED) {
2636N/A Graphics g = peer.getGraphics();
2636N/A try {
4005N/A g.drawImage(backBuffer,
4005N/A x1, y1, x2, y2,
2636N/A x1, y1, x2, y2,
2636N/A null);
2636N/A } finally {
2636N/A g.dispose();
2636N/A }
2636N/A } else if (flipAction == BufferCapabilities.FlipContents.BACKGROUND) {
2636N/A Graphics g = backBuffer.getGraphics();
2636N/A try {
2636N/A g.setColor(target.getBackground());
2636N/A g.fillRect(0, 0,
2636N/A backBuffer.getWidth(),
2636N/A backBuffer.getHeight());
2636N/A } finally {
2636N/A g.dispose();
2636N/A }
2636N/A }
0N/A // the rest of the flip actions are not supported
0N/A }
2636N/A}
2636N/A