Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/windows/classes/sun/awt/Win32GraphicsConfig.java
32287 views
/*1* Copyright (c) 1997, 2009, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package sun.awt;2627import java.awt.AWTException;28import java.awt.BufferCapabilities;29import java.awt.Component;30import java.awt.Graphics;31import java.awt.GraphicsConfiguration;32import java.awt.GraphicsDevice;33import java.awt.GraphicsEnvironment;34import java.awt.Image;35import java.awt.ImageCapabilities;36import java.awt.Rectangle;37import java.awt.Toolkit;38import java.awt.Transparency;39import java.awt.Window;40import java.awt.geom.AffineTransform;41import java.awt.image.BufferedImage;42import java.awt.image.ColorModel;43import java.awt.image.DirectColorModel;44import java.awt.image.Raster;45import java.awt.image.VolatileImage;46import java.awt.image.WritableRaster;4748import sun.awt.windows.WComponentPeer;49import sun.awt.image.OffScreenImage;50import sun.awt.image.SunVolatileImage;51import sun.awt.image.SurfaceManager;52import sun.java2d.SurfaceData;53import sun.java2d.InvalidPipeException;54import sun.java2d.loops.RenderLoops;55import sun.java2d.loops.SurfaceType;56import sun.java2d.loops.CompositeType;57import sun.java2d.windows.GDIWindowSurfaceData;5859/**60* This is an implementation of a GraphicsConfiguration object for a61* single Win32 visual.62*63* @see GraphicsEnvironment64* @see GraphicsDevice65*/66public class Win32GraphicsConfig extends GraphicsConfiguration67implements DisplayChangedListener, SurfaceManager.ProxiedGraphicsConfig68{69protected Win32GraphicsDevice screen;70protected int visual; //PixelFormatID71protected RenderLoops solidloops;7273private static native void initIDs();7475static {76initIDs();77}7879/**80* Returns a Win32GraphicsConfiguration object with the given device81* and PixelFormat. Note that this method does NOT check to ensure that82* the returned Win32GraphicsConfig will correctly support rendering into a83* Java window. This method is provided so that client code can do its84* own checking as to the appropriateness of a particular PixelFormat.85* Safer access to Win32GraphicsConfigurations is provided by86* Win32GraphicsDevice.getConfigurations().87*/88public static Win32GraphicsConfig getConfig(Win32GraphicsDevice device,89int pixFormatID)90{91return new Win32GraphicsConfig(device, pixFormatID);92}9394/**95* @deprecated as of JDK version 1.396* replaced by <code>getConfig()</code>97*/98@Deprecated99public Win32GraphicsConfig(GraphicsDevice device, int visualnum) {100this.screen = (Win32GraphicsDevice)device;101this.visual = visualnum;102((Win32GraphicsDevice)device).addDisplayChangedListener(this);103}104105/**106* Return the graphics device associated with this configuration.107*/108public GraphicsDevice getDevice() {109return screen;110}111112/**113* Return the PixelFormatIndex this GraphicsConfig uses114*/115public int getVisual() {116return visual;117}118119public Object getProxyKey() {120return screen;121}122123/**124* Return the RenderLoops this type of destination uses for125* solid fills and strokes.126*/127private SurfaceType sTypeOrig = null;128public synchronized RenderLoops getSolidLoops(SurfaceType stype) {129if (solidloops == null || sTypeOrig != stype) {130solidloops = SurfaceData.makeRenderLoops(SurfaceType.OpaqueColor,131CompositeType.SrcNoEa,132stype);133sTypeOrig = stype;134}135return solidloops;136}137138/**139* Returns the color model associated with this configuration.140*/141public synchronized ColorModel getColorModel() {142return screen.getColorModel();143}144145/**146* Returns a new color model for this configuration. This call147* is only used internally, by images and components that are148* associated with the graphics device. When attributes of that149* device change (for example, when the device palette is updated),150* then this device-based color model will be updated internally151* to reflect the new situation.152*/153public ColorModel getDeviceColorModel() {154return screen.getDynamicColorModel();155}156157/**158* Returns the color model associated with this configuration that159* supports the specified transparency.160*/161public ColorModel getColorModel(int transparency) {162switch (transparency) {163case Transparency.OPAQUE:164return getColorModel();165case Transparency.BITMASK:166return new DirectColorModel(25, 0xff0000, 0xff00, 0xff, 0x1000000);167case Transparency.TRANSLUCENT:168return ColorModel.getRGBdefault();169default:170return null;171}172}173174/**175* Returns the default Transform for this configuration. This176* Transform is typically the Identity transform for most normal177* screens. Device coordinates for screen and printer devices will178* have the origin in the upper left-hand corner of the target region of179* the device, with X coordinates180* increasing to the right and Y coordinates increasing downwards.181* For image buffers, this Transform will be the Identity transform.182*/183public AffineTransform getDefaultTransform() {184return new AffineTransform();185}186187/**188*189* Returns a Transform that can be composed with the default Transform190* of a Graphics2D so that 72 units in user space will equal 1 inch191* in device space.192* Given a Graphics2D, g, one can reset the transformation to create193* such a mapping by using the following pseudocode:194* <pre>195* GraphicsConfiguration gc = g.getGraphicsConfiguration();196*197* g.setTransform(gc.getDefaultTransform());198* g.transform(gc.getNormalizingTransform());199* </pre>200* Note that sometimes this Transform will be identity (e.g. for201* printers or metafile output) and that this Transform is only202* as accurate as the information supplied by the underlying system.203* For image buffers, this Transform will be the Identity transform,204* since there is no valid distance measurement.205*/206public AffineTransform getNormalizingTransform() {207Win32GraphicsEnvironment ge = (Win32GraphicsEnvironment)208GraphicsEnvironment.getLocalGraphicsEnvironment();209double xscale = ge.getXResolution() / 72.0;210double yscale = ge.getYResolution() / 72.0;211return new AffineTransform(xscale, 0.0, 0.0, yscale, 0.0, 0.0);212}213214public String toString() {215return (super.toString()+"[dev="+screen+",pixfmt="+visual+"]");216}217218private native Rectangle getBounds(int screen);219220public Rectangle getBounds() {221return getBounds(screen.getScreen());222}223224public synchronized void displayChanged() {225solidloops = null;226}227228public void paletteChanged() {}229230/**231* The following methods are invoked from WComponentPeer.java rather232* than having the Win32-dependent implementations hardcoded in that233* class. This way the appropriate actions are taken based on the peer's234* GraphicsConfig, whether it is a Win32GraphicsConfig or a235* WGLGraphicsConfig.236*/237238/**239* Creates a new SurfaceData that will be associated with the given240* WComponentPeer.241*/242public SurfaceData createSurfaceData(WComponentPeer peer,243int numBackBuffers)244{245return GDIWindowSurfaceData.createData(peer);246}247248/**249* Creates a new managed image of the given width and height250* that is associated with the target Component.251*/252public Image createAcceleratedImage(Component target,253int width, int height)254{255ColorModel model = getColorModel(Transparency.OPAQUE);256WritableRaster wr =257model.createCompatibleWritableRaster(width, height);258return new OffScreenImage(target, model, wr,259model.isAlphaPremultiplied());260}261262/**263* The following methods correspond to the multibuffering methods in264* WComponentPeer.java...265*/266267/**268* Checks that the requested configuration is natively supported; if not,269* an AWTException is thrown.270*/271public void assertOperationSupported(Component target,272int numBuffers,273BufferCapabilities caps)274throws AWTException275{276// the default pipeline doesn't support flip buffer strategy277throw new AWTException(278"The operation requested is not supported");279}280281/**282* This method is called from WComponentPeer when a surface data is replaced283* REMIND: while the default pipeline doesn't support flipping, it may284* happen that the accelerated device may have this graphics config285* (like if the device restoration failed when one device exits fs mode286* while others remain).287*/288public VolatileImage createBackBuffer(WComponentPeer peer) {289Component target = (Component)peer.getTarget();290return new SunVolatileImage(target,291target.getWidth(), target.getHeight(),292Boolean.TRUE);293}294295/**296* Performs the native flip operation for the given target Component.297*298* REMIND: we should really not get here because that would mean that299* a FLIP BufferStrategy has been created, and one could only be created300* if accelerated pipeline is present but in some rare (and transitional)301* cases it may happen that the accelerated graphics device may have a302* default graphics configuraiton, so this is just a precaution.303*/304public void flip(WComponentPeer peer,305Component target, VolatileImage backBuffer,306int x1, int y1, int x2, int y2,307BufferCapabilities.FlipContents flipAction)308{309if (flipAction == BufferCapabilities.FlipContents.COPIED ||310flipAction == BufferCapabilities.FlipContents.UNDEFINED) {311Graphics g = peer.getGraphics();312try {313g.drawImage(backBuffer,314x1, y1, x2, y2,315x1, y1, x2, y2,316null);317} finally {318g.dispose();319}320} else if (flipAction == BufferCapabilities.FlipContents.BACKGROUND) {321Graphics g = backBuffer.getGraphics();322try {323g.setColor(target.getBackground());324g.fillRect(0, 0,325backBuffer.getWidth(),326backBuffer.getHeight());327} finally {328g.dispose();329}330}331// the rest of the flip actions are not supported332}333334@Override335public boolean isTranslucencyCapable() {336//XXX: worth checking if 8-bit? Anyway, it doesn't hurt.337return true;338}339}340341342