src/java.desktop/share/classes/sun/java2d/SunGraphicsEnvironment.java
author aghaisas
Wed, 20 Feb 2019 17:00:40 +0530
branchmetal-prototype-branch
changeset 57196 a95707a39ff5
parent 50482 18f8e3b6f3b7
child 55176 3e0a90050182
permissions -rw-r--r--
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering Contributed-by: jdv, aghaisas
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
50482
18f8e3b6f3b7 8196030: AWT Robot mouseMove fails on Windows 10 1709 with HiDPI
serb
parents: 47216
diff changeset
     2
 * Copyright (c) 1997, 2018, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3938
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3938
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3938
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3938
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3938
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package sun.java2d;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
20434
19c5cdb0d7a2 8025652: [macos] build failed
malenkov
parents: 20433
diff changeset
    28
import java.awt.AWTError;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.awt.Color;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.awt.Font;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.awt.Graphics2D;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.awt.GraphicsConfiguration;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.awt.GraphicsDevice;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.awt.GraphicsEnvironment;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.awt.Insets;
50482
18f8e3b6f3b7 8196030: AWT Robot mouseMove fails on Windows 10 1709 with HiDPI
serb
parents: 47216
diff changeset
    36
import java.awt.Point;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import java.awt.Rectangle;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import java.awt.Toolkit;
50482
18f8e3b6f3b7 8196030: AWT Robot mouseMove fails on Windows 10 1709 with HiDPI
serb
parents: 47216
diff changeset
    39
import java.awt.geom.AffineTransform;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import java.awt.image.BufferedImage;
887
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 883
diff changeset
    41
import java.awt.peer.ComponentPeer;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
import java.io.BufferedReader;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
import java.io.File;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
import java.io.FileInputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
import java.io.InputStreamReader;
50482
18f8e3b6f3b7 8196030: AWT Robot mouseMove fails on Windows 10 1709 with HiDPI
serb
parents: 47216
diff changeset
    46
import java.security.AccessController;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
import java.util.Locale;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
import java.util.TreeMap;
50482
18f8e3b6f3b7 8196030: AWT Robot mouseMove fails on Windows 10 1709 with HiDPI
serb
parents: 47216
diff changeset
    49
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
import sun.awt.DisplayChangedListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
import sun.awt.SunDisplayChanger;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
import sun.font.FontManager;
3928
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 1724
diff changeset
    53
import sun.font.FontManagerFactory;
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 1724
diff changeset
    54
import sun.font.FontManagerForSGE;
50482
18f8e3b6f3b7 8196030: AWT Robot mouseMove fails on Windows 10 1709 with HiDPI
serb
parents: 47216
diff changeset
    55
import sun.java2d.pipe.Region;
34394
259d6e4e0978 8073320: Windows HiDPI Graphics support
alexsch
parents: 31900
diff changeset
    56
import sun.security.action.GetPropertyAction;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 * This is an implementation of a GraphicsEnvironment object for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 * default local GraphicsEnvironment.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 * @see GraphicsDevice
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 * @see GraphicsConfiguration
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
public abstract class SunGraphicsEnvironment extends GraphicsEnvironment
3928
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 1724
diff changeset
    66
    implements DisplayChangedListener {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
3928
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 1724
diff changeset
    68
    public static boolean isOpenSolaris;
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 1724
diff changeset
    69
    private static Font defaultFont;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
34394
259d6e4e0978 8073320: Windows HiDPI Graphics support
alexsch
parents: 31900
diff changeset
    71
    private static final boolean uiScaleEnabled;
259d6e4e0978 8073320: Windows HiDPI Graphics support
alexsch
parents: 31900
diff changeset
    72
    private static final double debugScale;
259d6e4e0978 8073320: Windows HiDPI Graphics support
alexsch
parents: 31900
diff changeset
    73
259d6e4e0978 8073320: Windows HiDPI Graphics support
alexsch
parents: 31900
diff changeset
    74
    static {
259d6e4e0978 8073320: Windows HiDPI Graphics support
alexsch
parents: 31900
diff changeset
    75
        uiScaleEnabled = "true".equals(AccessController.doPrivileged(
259d6e4e0978 8073320: Windows HiDPI Graphics support
alexsch
parents: 31900
diff changeset
    76
                new GetPropertyAction("sun.java2d.uiScale.enabled", "true")));
259d6e4e0978 8073320: Windows HiDPI Graphics support
alexsch
parents: 31900
diff changeset
    77
        debugScale = uiScaleEnabled ? getScaleFactor("sun.java2d.uiScale") : -1;
259d6e4e0978 8073320: Windows HiDPI Graphics support
alexsch
parents: 31900
diff changeset
    78
    }
259d6e4e0978 8073320: Windows HiDPI Graphics support
alexsch
parents: 31900
diff changeset
    79
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    public SunGraphicsEnvironment() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
        java.security.AccessController.doPrivileged(
24522
3a0bbf9f5e81 8038644: Fix raw and unchecked warnings in sun.java2d.*
henryjen
parents: 22584
diff changeset
    82
                                    new java.security.PrivilegedAction<Object>() {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
            public Object run() {
31900
b6961b1116d0 8132408: Check os.name before os.version in SunGraphicsEnvironment constructor
simonis
parents: 25859
diff changeset
    84
                String osName = System.getProperty("os.name");
b6961b1116d0 8132408: Check os.name before os.version in SunGraphicsEnvironment constructor
simonis
parents: 25859
diff changeset
    85
                if ("SunOS".equals(osName)) {
883
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
    86
                    String version = System.getProperty("os.version", "0.0");
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
    87
                    try {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
    88
                        float ver = Float.parseFloat(version);
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
    89
                        if (ver > 5.10f) {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
    90
                            File f = new File("/etc/release");
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
    91
                            FileInputStream fis = new FileInputStream(f);
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
    92
                            InputStreamReader isr
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
    93
                                = new InputStreamReader(fis, "ISO-8859-1");
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
    94
                            BufferedReader br = new BufferedReader(isr);
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
    95
                            String line = br.readLine();
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
    96
                            if (line.indexOf("OpenSolaris") >= 0) {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
    97
                                isOpenSolaris = true;
8128
4980e459a3a7 6940890: Java doesn't pick up the correct fontconfig files in latest Solaris Next builds
prr
parents: 7947
diff changeset
    98
                            } else {
4980e459a3a7 6940890: Java doesn't pick up the correct fontconfig files in latest Solaris Next builds
prr
parents: 7947
diff changeset
    99
                                /* We are using isOpenSolaris as meaning
4980e459a3a7 6940890: Java doesn't pick up the correct fontconfig files in latest Solaris Next builds
prr
parents: 7947
diff changeset
   100
                                 * we know the Solaris commercial fonts aren't
4980e459a3a7 6940890: Java doesn't pick up the correct fontconfig files in latest Solaris Next builds
prr
parents: 7947
diff changeset
   101
                                 * present. "Solaris Next" (03/10) did not
4980e459a3a7 6940890: Java doesn't pick up the correct fontconfig files in latest Solaris Next builds
prr
parents: 7947
diff changeset
   102
                                 * include these even though its was not
4980e459a3a7 6940890: Java doesn't pick up the correct fontconfig files in latest Solaris Next builds
prr
parents: 7947
diff changeset
   103
                                 * OpenSolaris. Need to revisit how this is
4980e459a3a7 6940890: Java doesn't pick up the correct fontconfig files in latest Solaris Next builds
prr
parents: 7947
diff changeset
   104
                                 * handled but for now as in 6ux, we'll use
4980e459a3a7 6940890: Java doesn't pick up the correct fontconfig files in latest Solaris Next builds
prr
parents: 7947
diff changeset
   105
                                 * the test for a standard font resource as
4980e459a3a7 6940890: Java doesn't pick up the correct fontconfig files in latest Solaris Next builds
prr
parents: 7947
diff changeset
   106
                                 * being an indicator as to whether we need
4980e459a3a7 6940890: Java doesn't pick up the correct fontconfig files in latest Solaris Next builds
prr
parents: 7947
diff changeset
   107
                                 * to treat this as OpenSolaris from a font
4980e459a3a7 6940890: Java doesn't pick up the correct fontconfig files in latest Solaris Next builds
prr
parents: 7947
diff changeset
   108
                                 * config perspective.
4980e459a3a7 6940890: Java doesn't pick up the correct fontconfig files in latest Solaris Next builds
prr
parents: 7947
diff changeset
   109
                                 */
4980e459a3a7 6940890: Java doesn't pick up the correct fontconfig files in latest Solaris Next builds
prr
parents: 7947
diff changeset
   110
                                String courierNew =
4980e459a3a7 6940890: Java doesn't pick up the correct fontconfig files in latest Solaris Next builds
prr
parents: 7947
diff changeset
   111
                                    "/usr/openwin/lib/X11/fonts/TrueType/CourierNew.ttf";
4980e459a3a7 6940890: Java doesn't pick up the correct fontconfig files in latest Solaris Next builds
prr
parents: 7947
diff changeset
   112
                                File courierFile = new File(courierNew);
4980e459a3a7 6940890: Java doesn't pick up the correct fontconfig files in latest Solaris Next builds
prr
parents: 7947
diff changeset
   113
                                isOpenSolaris = !courierFile.exists();
883
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
   114
                            }
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
   115
                            fis.close();
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
   116
                        }
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
   117
                    } catch (Exception e) {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 2
diff changeset
   118
                    }
31900
b6961b1116d0 8132408: Check os.name before os.version in SunGraphicsEnvironment constructor
simonis
parents: 25859
diff changeset
   119
                }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
                /* Establish the default font to be used by SG2D etc */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
                defaultFont = new Font(Font.DIALOG, Font.PLAIN, 12);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
        });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
    protected GraphicsDevice[] screens;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
     * Returns an array of all of the screen devices.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
    public synchronized GraphicsDevice[] getScreenDevices() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
        GraphicsDevice[] ret = screens;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
        if (ret == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
            int num = getNumScreens();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
            ret = new GraphicsDevice[num];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
            for (int i = 0; i < num; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
                ret[i] = makeScreenDevice(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
            screens = ret;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
        return ret;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
3928
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 1724
diff changeset
   146
    /**
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 1724
diff changeset
   147
     * Returns the number of screen devices of this graphics environment.
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 1724
diff changeset
   148
     *
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 1724
diff changeset
   149
     * @return the number of screen devices of this graphics environment
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 1724
diff changeset
   150
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
    protected abstract int getNumScreens();
3928
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 1724
diff changeset
   152
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 1724
diff changeset
   153
    /**
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 1724
diff changeset
   154
     * Create and return the screen device with the specified number. The
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 34394
diff changeset
   155
     * device with number {@code 0} will be the default device (returned
3928
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 1724
diff changeset
   156
     * by {@link #getDefaultScreenDevice()}.
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 1724
diff changeset
   157
     *
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 1724
diff changeset
   158
     * @param screennum the number of the screen to create
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 1724
diff changeset
   159
     *
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 1724
diff changeset
   160
     * @return the created screen device
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 1724
diff changeset
   161
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
    protected abstract GraphicsDevice makeScreenDevice(int screennum);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
     * Returns the default screen graphics device.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
    public GraphicsDevice getDefaultScreenDevice() {
20433
f6d501f12376 7117595: ArrayIndexOutOfBoundsException in Win32GraphicsEnvironment if display is removed
malenkov
parents: 9050
diff changeset
   168
        GraphicsDevice[] screens = getScreenDevices();
f6d501f12376 7117595: ArrayIndexOutOfBoundsException in Win32GraphicsEnvironment if display is removed
malenkov
parents: 9050
diff changeset
   169
        if (screens.length == 0) {
f6d501f12376 7117595: ArrayIndexOutOfBoundsException in Win32GraphicsEnvironment if display is removed
malenkov
parents: 9050
diff changeset
   170
            throw new AWTError("no screen devices");
f6d501f12376 7117595: ArrayIndexOutOfBoundsException in Win32GraphicsEnvironment if display is removed
malenkov
parents: 9050
diff changeset
   171
        }
f6d501f12376 7117595: ArrayIndexOutOfBoundsException in Win32GraphicsEnvironment if display is removed
malenkov
parents: 9050
diff changeset
   172
        return screens[0];
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
     * Returns a Graphics2D object for rendering into the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
     * given BufferedImage.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
     * @throws NullPointerException if BufferedImage argument is null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
    public Graphics2D createGraphics(BufferedImage img) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
        if (img == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
            throw new NullPointerException("BufferedImage cannot be null");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
        SurfaceData sd = SurfaceData.getPrimarySurfaceData(img);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
        return new SunGraphics2D(sd, Color.white, Color.black, defaultFont);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
7947
236cfb73d510 6980204: closed/java/awt/font/LogicalFonts/MappingTest.java fails
prr
parents: 5506
diff changeset
   188
    public static FontManagerForSGE getFontManagerForSGE() {
3928
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 1724
diff changeset
   189
        FontManager fm = FontManagerFactory.getInstance();
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 1724
diff changeset
   190
        return (FontManagerForSGE) fm;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
    }
8945
4718885476ee 7032930: A way to specify MS Mincho to be used in dialoginput on windows JA locale
prr
parents: 8128
diff changeset
   192
4718885476ee 7032930: A way to specify MS Mincho to be used in dialoginput on windows JA locale
prr
parents: 8128
diff changeset
   193
    /* Modifies the behaviour of a subsequent call to preferLocaleFonts()
4718885476ee 7032930: A way to specify MS Mincho to be used in dialoginput on windows JA locale
prr
parents: 8128
diff changeset
   194
     * to use Mincho instead of Gothic for dialoginput in JA locales
4718885476ee 7032930: A way to specify MS Mincho to be used in dialoginput on windows JA locale
prr
parents: 8128
diff changeset
   195
     * on windows. Not needed on other platforms.
4718885476ee 7032930: A way to specify MS Mincho to be used in dialoginput on windows JA locale
prr
parents: 8128
diff changeset
   196
     *
36917
02e8440be4d6 8051519: Deprecate sun.java2d.SunGraphicsEnvironment.useAlternateFontforJALocales
prr
parents: 35667
diff changeset
   197
     * @deprecated as of JDK9. To be removed in a future release
8945
4718885476ee 7032930: A way to specify MS Mincho to be used in dialoginput on windows JA locale
prr
parents: 8128
diff changeset
   198
     */
36917
02e8440be4d6 8051519: Deprecate sun.java2d.SunGraphicsEnvironment.useAlternateFontforJALocales
prr
parents: 35667
diff changeset
   199
    @Deprecated
8945
4718885476ee 7032930: A way to specify MS Mincho to be used in dialoginput on windows JA locale
prr
parents: 8128
diff changeset
   200
    public static void useAlternateFontforJALocales() {
4718885476ee 7032930: A way to specify MS Mincho to be used in dialoginput on windows JA locale
prr
parents: 8128
diff changeset
   201
        getFontManagerForSGE().useAlternateFontforJALocales();
4718885476ee 7032930: A way to specify MS Mincho to be used in dialoginput on windows JA locale
prr
parents: 8128
diff changeset
   202
    }
4718885476ee 7032930: A way to specify MS Mincho to be used in dialoginput on windows JA locale
prr
parents: 8128
diff changeset
   203
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
     /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
     * Returns all fonts available in this environment.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
    public Font[] getAllFonts() {
3928
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 1724
diff changeset
   208
        FontManagerForSGE fm = getFontManagerForSGE();
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 1724
diff changeset
   209
        Font[] installedFonts = fm.getAllInstalledFonts();
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 1724
diff changeset
   210
        Font[] created = fm.getCreatedFonts();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
        if (created == null || created.length == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
            return installedFonts;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
            int newlen = installedFonts.length + created.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
            Font [] fonts = java.util.Arrays.copyOf(installedFonts, newlen);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
            System.arraycopy(created, 0, fonts,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
                             installedFonts.length, created.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
            return fonts;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
    public String[] getAvailableFontFamilyNames(Locale requestedLocale) {
3928
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 1724
diff changeset
   223
        FontManagerForSGE fm = getFontManagerForSGE();
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 1724
diff changeset
   224
        String[] installed = fm.getInstalledFontFamilyNames(requestedLocale);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
        /* Use a new TreeMap as used in getInstalledFontFamilyNames
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
         * and insert all the keys in lower case, so that the sort order
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
         * is the same as the installed families. This preserves historical
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
         * behaviour and inserts new families in the right place.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
         * It would have been marginally more efficient to directly obtain
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
         * the tree map and just insert new entries, but not so much as
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
         * to justify the extra internal interface.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
         */
3928
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 1724
diff changeset
   233
        TreeMap<String, String> map = fm.getCreatedFontFamilyNames();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
        if (map == null || map.size() == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
            return installed;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
            for (int i=0; i<installed.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
                map.put(installed[i].toLowerCase(requestedLocale),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
                        installed[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
            String[] retval =  new String[map.size()];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
            Object [] keyNames = map.keySet().toArray();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
            for (int i=0; i < keyNames.length; i++) {
22584
eed64ee05369 8032733: Fix cast lint warnings in client libraries
darcy
parents: 20434
diff changeset
   244
                retval[i] = map.get(keyNames[i]);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
            return retval;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
    public String[] getAvailableFontFamilyNames() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
        return getAvailableFontFamilyNames(Locale.getDefault());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
     * Return the bounds of a GraphicsDevice, less its screen insets.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
     * See also java.awt.GraphicsEnvironment.getUsableBounds();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
    public static Rectangle getUsableBounds(GraphicsDevice gd) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
        GraphicsConfiguration gc = gd.getDefaultConfiguration();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
        Insets insets = Toolkit.getDefaultToolkit().getScreenInsets(gc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
        Rectangle usableBounds = gc.getBounds();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
        usableBounds.x += insets.left;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
        usableBounds.y += insets.top;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
        usableBounds.width -= (insets.left + insets.right);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
        usableBounds.height -= (insets.top + insets.bottom);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
        return usableBounds;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
     * From the DisplayChangedListener interface; called
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
     * when the display mode has been changed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
    public void displayChanged() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
        // notify screens in device array to do display update stuff
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
        for (GraphicsDevice gd : getScreenDevices()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
            if (gd instanceof DisplayChangedListener) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
                ((DisplayChangedListener) gd).displayChanged();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
        // notify SunDisplayChanger list (e.g. VolatileSurfaceManagers and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
        // SurfaceDataProxies) about the display change event
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
        displayChanger.notifyListeners();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
     * Part of the DisplayChangedListener interface:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
     * propagate this event to listeners
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
    public void paletteChanged() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
        displayChanger.notifyPaletteChanged();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
1724
a22a286aa16f 6748082: remove platform-specific code from SwingUtilities2.isDisplayLocal
tdv
parents: 1716
diff changeset
   296
    /**
a22a286aa16f 6748082: remove platform-specific code from SwingUtilities2.isDisplayLocal
tdv
parents: 1716
diff changeset
   297
     * Returns true when the display is local, false for remote displays.
a22a286aa16f 6748082: remove platform-specific code from SwingUtilities2.isDisplayLocal
tdv
parents: 1716
diff changeset
   298
     *
a22a286aa16f 6748082: remove platform-specific code from SwingUtilities2.isDisplayLocal
tdv
parents: 1716
diff changeset
   299
     * @return true when the display is local, false for remote displays
a22a286aa16f 6748082: remove platform-specific code from SwingUtilities2.isDisplayLocal
tdv
parents: 1716
diff changeset
   300
     */
a22a286aa16f 6748082: remove platform-specific code from SwingUtilities2.isDisplayLocal
tdv
parents: 1716
diff changeset
   301
    public abstract boolean isDisplayLocal();
a22a286aa16f 6748082: remove platform-specific code from SwingUtilities2.isDisplayLocal
tdv
parents: 1716
diff changeset
   302
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
     * ----DISPLAY CHANGE SUPPORT----
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
    protected SunDisplayChanger displayChanger = new SunDisplayChanger();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
     * Add a DisplayChangeListener to be notified when the display settings
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
     * are changed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
    public void addDisplayChangedListener(DisplayChangedListener client) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
        displayChanger.add(client);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
     * Remove a DisplayChangeListener from Win32GraphicsEnvironment
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
    public void removeDisplayChangedListener(DisplayChangedListener client) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
        displayChanger.remove(client);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
     * ----END DISPLAY CHANGE SUPPORT----
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
     */
887
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 883
diff changeset
   327
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 883
diff changeset
   328
    /**
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 883
diff changeset
   329
     * Returns true if FlipBufferStrategy with COPIED buffer contents
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 883
diff changeset
   330
     * is preferred for this peer's GraphicsConfiguration over
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 883
diff changeset
   331
     * BlitBufferStrategy, false otherwise.
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 883
diff changeset
   332
     *
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 883
diff changeset
   333
     * The reason FlipBS could be preferred is that in some configurations
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 883
diff changeset
   334
     * an accelerated copy to the screen is supported (like Direct3D 9)
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 883
diff changeset
   335
     *
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 883
diff changeset
   336
     * @return true if flip strategy should be used, false otherwise
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 883
diff changeset
   337
     */
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 883
diff changeset
   338
    public boolean isFlipStrategyPreferred(ComponentPeer peer) {
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 883
diff changeset
   339
        return false;
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 883
diff changeset
   340
    }
34394
259d6e4e0978 8073320: Windows HiDPI Graphics support
alexsch
parents: 31900
diff changeset
   341
259d6e4e0978 8073320: Windows HiDPI Graphics support
alexsch
parents: 31900
diff changeset
   342
    public static boolean isUIScaleEnabled() {
259d6e4e0978 8073320: Windows HiDPI Graphics support
alexsch
parents: 31900
diff changeset
   343
        return uiScaleEnabled;
259d6e4e0978 8073320: Windows HiDPI Graphics support
alexsch
parents: 31900
diff changeset
   344
    }
259d6e4e0978 8073320: Windows HiDPI Graphics support
alexsch
parents: 31900
diff changeset
   345
259d6e4e0978 8073320: Windows HiDPI Graphics support
alexsch
parents: 31900
diff changeset
   346
    public static double getDebugScale() {
259d6e4e0978 8073320: Windows HiDPI Graphics support
alexsch
parents: 31900
diff changeset
   347
        return debugScale;
259d6e4e0978 8073320: Windows HiDPI Graphics support
alexsch
parents: 31900
diff changeset
   348
    }
259d6e4e0978 8073320: Windows HiDPI Graphics support
alexsch
parents: 31900
diff changeset
   349
259d6e4e0978 8073320: Windows HiDPI Graphics support
alexsch
parents: 31900
diff changeset
   350
    public static double getScaleFactor(String propertyName) {
259d6e4e0978 8073320: Windows HiDPI Graphics support
alexsch
parents: 31900
diff changeset
   351
259d6e4e0978 8073320: Windows HiDPI Graphics support
alexsch
parents: 31900
diff changeset
   352
        String scaleFactor = AccessController.doPrivileged(
259d6e4e0978 8073320: Windows HiDPI Graphics support
alexsch
parents: 31900
diff changeset
   353
                new GetPropertyAction(propertyName, "-1"));
259d6e4e0978 8073320: Windows HiDPI Graphics support
alexsch
parents: 31900
diff changeset
   354
259d6e4e0978 8073320: Windows HiDPI Graphics support
alexsch
parents: 31900
diff changeset
   355
        if (scaleFactor == null || scaleFactor.equals("-1")) {
259d6e4e0978 8073320: Windows HiDPI Graphics support
alexsch
parents: 31900
diff changeset
   356
            return -1;
259d6e4e0978 8073320: Windows HiDPI Graphics support
alexsch
parents: 31900
diff changeset
   357
        }
259d6e4e0978 8073320: Windows HiDPI Graphics support
alexsch
parents: 31900
diff changeset
   358
259d6e4e0978 8073320: Windows HiDPI Graphics support
alexsch
parents: 31900
diff changeset
   359
        try {
259d6e4e0978 8073320: Windows HiDPI Graphics support
alexsch
parents: 31900
diff changeset
   360
            double units = 1.0;
259d6e4e0978 8073320: Windows HiDPI Graphics support
alexsch
parents: 31900
diff changeset
   361
259d6e4e0978 8073320: Windows HiDPI Graphics support
alexsch
parents: 31900
diff changeset
   362
            if (scaleFactor.endsWith("x")) {
259d6e4e0978 8073320: Windows HiDPI Graphics support
alexsch
parents: 31900
diff changeset
   363
                scaleFactor = scaleFactor.substring(0, scaleFactor.length() - 1);
259d6e4e0978 8073320: Windows HiDPI Graphics support
alexsch
parents: 31900
diff changeset
   364
            } else if (scaleFactor.endsWith("dpi")) {
259d6e4e0978 8073320: Windows HiDPI Graphics support
alexsch
parents: 31900
diff changeset
   365
                units = 96;
259d6e4e0978 8073320: Windows HiDPI Graphics support
alexsch
parents: 31900
diff changeset
   366
                scaleFactor = scaleFactor.substring(0, scaleFactor.length() - 3);
259d6e4e0978 8073320: Windows HiDPI Graphics support
alexsch
parents: 31900
diff changeset
   367
            } else if (scaleFactor.endsWith("%")) {
259d6e4e0978 8073320: Windows HiDPI Graphics support
alexsch
parents: 31900
diff changeset
   368
                units = 100;
259d6e4e0978 8073320: Windows HiDPI Graphics support
alexsch
parents: 31900
diff changeset
   369
                scaleFactor = scaleFactor.substring(0, scaleFactor.length() - 1);
259d6e4e0978 8073320: Windows HiDPI Graphics support
alexsch
parents: 31900
diff changeset
   370
            }
259d6e4e0978 8073320: Windows HiDPI Graphics support
alexsch
parents: 31900
diff changeset
   371
259d6e4e0978 8073320: Windows HiDPI Graphics support
alexsch
parents: 31900
diff changeset
   372
            double scale = Double.parseDouble(scaleFactor);
259d6e4e0978 8073320: Windows HiDPI Graphics support
alexsch
parents: 31900
diff changeset
   373
            return scale <= 0 ? -1 : scale / units;
259d6e4e0978 8073320: Windows HiDPI Graphics support
alexsch
parents: 31900
diff changeset
   374
        } catch (NumberFormatException ignored) {
259d6e4e0978 8073320: Windows HiDPI Graphics support
alexsch
parents: 31900
diff changeset
   375
            return -1;
259d6e4e0978 8073320: Windows HiDPI Graphics support
alexsch
parents: 31900
diff changeset
   376
        }
259d6e4e0978 8073320: Windows HiDPI Graphics support
alexsch
parents: 31900
diff changeset
   377
    }
50482
18f8e3b6f3b7 8196030: AWT Robot mouseMove fails on Windows 10 1709 with HiDPI
serb
parents: 47216
diff changeset
   378
18f8e3b6f3b7 8196030: AWT Robot mouseMove fails on Windows 10 1709 with HiDPI
serb
parents: 47216
diff changeset
   379
    /**
18f8e3b6f3b7 8196030: AWT Robot mouseMove fails on Windows 10 1709 with HiDPI
serb
parents: 47216
diff changeset
   380
     * Returns the graphics configuration which bounds contain the given point.
18f8e3b6f3b7 8196030: AWT Robot mouseMove fails on Windows 10 1709 with HiDPI
serb
parents: 47216
diff changeset
   381
     *
18f8e3b6f3b7 8196030: AWT Robot mouseMove fails on Windows 10 1709 with HiDPI
serb
parents: 47216
diff changeset
   382
     * @param  current the default configuration which is checked in the first
18f8e3b6f3b7 8196030: AWT Robot mouseMove fails on Windows 10 1709 with HiDPI
serb
parents: 47216
diff changeset
   383
     *         place
18f8e3b6f3b7 8196030: AWT Robot mouseMove fails on Windows 10 1709 with HiDPI
serb
parents: 47216
diff changeset
   384
     * @param  x the x coordinate of the given point
18f8e3b6f3b7 8196030: AWT Robot mouseMove fails on Windows 10 1709 with HiDPI
serb
parents: 47216
diff changeset
   385
     * @param  y the y coordinate of the given point
18f8e3b6f3b7 8196030: AWT Robot mouseMove fails on Windows 10 1709 with HiDPI
serb
parents: 47216
diff changeset
   386
     * @return the graphics configuration
18f8e3b6f3b7 8196030: AWT Robot mouseMove fails on Windows 10 1709 with HiDPI
serb
parents: 47216
diff changeset
   387
     */
18f8e3b6f3b7 8196030: AWT Robot mouseMove fails on Windows 10 1709 with HiDPI
serb
parents: 47216
diff changeset
   388
    public static GraphicsConfiguration getGraphicsConfigurationAtPoint(
18f8e3b6f3b7 8196030: AWT Robot mouseMove fails on Windows 10 1709 with HiDPI
serb
parents: 47216
diff changeset
   389
            GraphicsConfiguration current, double x, double y) {
18f8e3b6f3b7 8196030: AWT Robot mouseMove fails on Windows 10 1709 with HiDPI
serb
parents: 47216
diff changeset
   390
        if (current.getBounds().contains(x, y)) {
18f8e3b6f3b7 8196030: AWT Robot mouseMove fails on Windows 10 1709 with HiDPI
serb
parents: 47216
diff changeset
   391
            return current;
18f8e3b6f3b7 8196030: AWT Robot mouseMove fails on Windows 10 1709 with HiDPI
serb
parents: 47216
diff changeset
   392
        }
18f8e3b6f3b7 8196030: AWT Robot mouseMove fails on Windows 10 1709 with HiDPI
serb
parents: 47216
diff changeset
   393
        GraphicsEnvironment env = getLocalGraphicsEnvironment();
18f8e3b6f3b7 8196030: AWT Robot mouseMove fails on Windows 10 1709 with HiDPI
serb
parents: 47216
diff changeset
   394
        for (GraphicsDevice device : env.getScreenDevices()) {
18f8e3b6f3b7 8196030: AWT Robot mouseMove fails on Windows 10 1709 with HiDPI
serb
parents: 47216
diff changeset
   395
            GraphicsConfiguration config = device.getDefaultConfiguration();
18f8e3b6f3b7 8196030: AWT Robot mouseMove fails on Windows 10 1709 with HiDPI
serb
parents: 47216
diff changeset
   396
            if (config.getBounds().contains(x, y)) {
18f8e3b6f3b7 8196030: AWT Robot mouseMove fails on Windows 10 1709 with HiDPI
serb
parents: 47216
diff changeset
   397
                return config;
18f8e3b6f3b7 8196030: AWT Robot mouseMove fails on Windows 10 1709 with HiDPI
serb
parents: 47216
diff changeset
   398
            }
18f8e3b6f3b7 8196030: AWT Robot mouseMove fails on Windows 10 1709 with HiDPI
serb
parents: 47216
diff changeset
   399
        }
18f8e3b6f3b7 8196030: AWT Robot mouseMove fails on Windows 10 1709 with HiDPI
serb
parents: 47216
diff changeset
   400
        return current;
18f8e3b6f3b7 8196030: AWT Robot mouseMove fails on Windows 10 1709 with HiDPI
serb
parents: 47216
diff changeset
   401
    }
18f8e3b6f3b7 8196030: AWT Robot mouseMove fails on Windows 10 1709 with HiDPI
serb
parents: 47216
diff changeset
   402
18f8e3b6f3b7 8196030: AWT Robot mouseMove fails on Windows 10 1709 with HiDPI
serb
parents: 47216
diff changeset
   403
    /**
18f8e3b6f3b7 8196030: AWT Robot mouseMove fails on Windows 10 1709 with HiDPI
serb
parents: 47216
diff changeset
   404
     * Converts coordinates from the user's space to the device space using
18f8e3b6f3b7 8196030: AWT Robot mouseMove fails on Windows 10 1709 with HiDPI
serb
parents: 47216
diff changeset
   405
     * appropriate device transformation.
18f8e3b6f3b7 8196030: AWT Robot mouseMove fails on Windows 10 1709 with HiDPI
serb
parents: 47216
diff changeset
   406
     *
18f8e3b6f3b7 8196030: AWT Robot mouseMove fails on Windows 10 1709 with HiDPI
serb
parents: 47216
diff changeset
   407
     * @param  x coordinate in the user space
18f8e3b6f3b7 8196030: AWT Robot mouseMove fails on Windows 10 1709 with HiDPI
serb
parents: 47216
diff changeset
   408
     * @param  y coordinate in the user space
18f8e3b6f3b7 8196030: AWT Robot mouseMove fails on Windows 10 1709 with HiDPI
serb
parents: 47216
diff changeset
   409
     * @return the point which uses device space(pixels)
18f8e3b6f3b7 8196030: AWT Robot mouseMove fails on Windows 10 1709 with HiDPI
serb
parents: 47216
diff changeset
   410
     */
18f8e3b6f3b7 8196030: AWT Robot mouseMove fails on Windows 10 1709 with HiDPI
serb
parents: 47216
diff changeset
   411
    public static Point convertToDeviceSpace(double x, double y) {
18f8e3b6f3b7 8196030: AWT Robot mouseMove fails on Windows 10 1709 with HiDPI
serb
parents: 47216
diff changeset
   412
        GraphicsConfiguration gc = getLocalGraphicsEnvironment()
18f8e3b6f3b7 8196030: AWT Robot mouseMove fails on Windows 10 1709 with HiDPI
serb
parents: 47216
diff changeset
   413
                        .getDefaultScreenDevice().getDefaultConfiguration();
18f8e3b6f3b7 8196030: AWT Robot mouseMove fails on Windows 10 1709 with HiDPI
serb
parents: 47216
diff changeset
   414
        gc = getGraphicsConfigurationAtPoint(gc, x, y);
18f8e3b6f3b7 8196030: AWT Robot mouseMove fails on Windows 10 1709 with HiDPI
serb
parents: 47216
diff changeset
   415
18f8e3b6f3b7 8196030: AWT Robot mouseMove fails on Windows 10 1709 with HiDPI
serb
parents: 47216
diff changeset
   416
        AffineTransform tx = gc.getDefaultTransform();
18f8e3b6f3b7 8196030: AWT Robot mouseMove fails on Windows 10 1709 with HiDPI
serb
parents: 47216
diff changeset
   417
        x = Region.clipRound(x * tx.getScaleX());
18f8e3b6f3b7 8196030: AWT Robot mouseMove fails on Windows 10 1709 with HiDPI
serb
parents: 47216
diff changeset
   418
        y = Region.clipRound(y * tx.getScaleY());
18f8e3b6f3b7 8196030: AWT Robot mouseMove fails on Windows 10 1709 with HiDPI
serb
parents: 47216
diff changeset
   419
18f8e3b6f3b7 8196030: AWT Robot mouseMove fails on Windows 10 1709 with HiDPI
serb
parents: 47216
diff changeset
   420
        return new Point((int) x, (int) y);
18f8e3b6f3b7 8196030: AWT Robot mouseMove fails on Windows 10 1709 with HiDPI
serb
parents: 47216
diff changeset
   421
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
}