src/java.desktop/macosx/classes/sun/awt/CGraphicsDevice.java
author serb
Fri, 02 Nov 2018 12:15:37 -0700
changeset 52537 814c49afb1a7
parent 47216 71c04702a3d5
child 53673 e04d39094915
permissions -rw-r--r--
8211992: GraphicsConfiguration.getDevice().getDisplayMode() causes JVM crash on Mac Reviewed-by: prr
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
     1
/*
52537
814c49afb1a7 8211992: GraphicsConfiguration.getDevice().getDisplayMode() causes JVM crash on Mac
serb
parents: 47216
diff changeset
     2
 * Copyright (c) 2012, 2018, Oracle and/or its affiliates. All rights reserved.
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
     4
 *
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    10
 *
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    15
 * accompanied this code).
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    16
 *
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    20
 *
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    23
 * questions.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    24
 */
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    25
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    26
package sun.awt;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    27
15988
6db6e40405cf 8008660: Failure in 2D Queue Flusher thread on Mac
serb
parents: 15331
diff changeset
    28
import java.awt.AWTPermission;
6db6e40405cf 8008660: Failure in 2D Queue Flusher thread on Mac
serb
parents: 15331
diff changeset
    29
import java.awt.DisplayMode;
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    30
import java.awt.GraphicsConfiguration;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    31
import java.awt.GraphicsDevice;
15989
0fe0985a7bde 8003169: [macosx] JVM crash after disconnecting from projector
serb
parents: 15988
diff changeset
    32
import java.awt.Insets;
52537
814c49afb1a7 8211992: GraphicsConfiguration.getDevice().getDisplayMode() causes JVM crash on Mac
serb
parents: 47216
diff changeset
    33
import java.awt.Rectangle;
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    34
import java.awt.Window;
52537
814c49afb1a7 8211992: GraphicsConfiguration.getDevice().getDisplayMode() causes JVM crash on Mac
serb
parents: 47216
diff changeset
    35
import java.awt.geom.Rectangle2D;
15331
410070becfef 8003173: [macosx] Fullscreen on Mac leaves an empty rectangle
serb
parents: 14166
diff changeset
    36
import java.util.Objects;
52537
814c49afb1a7 8211992: GraphicsConfiguration.getDevice().getDisplayMode() causes JVM crash on Mac
serb
parents: 47216
diff changeset
    37
36900
3940219afc12 8150844: [hidpi] [macosx] -Dsun.java2d.uiScale should be taken into account for OS X
alexsch
parents: 30469
diff changeset
    38
import sun.java2d.SunGraphicsEnvironment;
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    39
import sun.java2d.opengl.CGLGraphicsConfig;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    40
17151
9bfcf2a592fc 8009012: [macosx] DisplayChangedListener is not implemented in LWWindowPeer/CGraphicsEnvironment
serb
parents: 16840
diff changeset
    41
public final class CGraphicsDevice extends GraphicsDevice
9bfcf2a592fc 8009012: [macosx] DisplayChangedListener is not implemented in LWWindowPeer/CGraphicsEnvironment
serb
parents: 16840
diff changeset
    42
        implements DisplayChangedListener {
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    43
17151
9bfcf2a592fc 8009012: [macosx] DisplayChangedListener is not implemented in LWWindowPeer/CGraphicsEnvironment
serb
parents: 16840
diff changeset
    44
    /**
9bfcf2a592fc 8009012: [macosx] DisplayChangedListener is not implemented in LWWindowPeer/CGraphicsEnvironment
serb
parents: 16840
diff changeset
    45
     * CoreGraphics display ID. This identifier can become non-valid at any time
9bfcf2a592fc 8009012: [macosx] DisplayChangedListener is not implemented in LWWindowPeer/CGraphicsEnvironment
serb
parents: 16840
diff changeset
    46
     * therefore methods, which is using this id should be ready to it.
9bfcf2a592fc 8009012: [macosx] DisplayChangedListener is not implemented in LWWindowPeer/CGraphicsEnvironment
serb
parents: 16840
diff changeset
    47
     */
9bfcf2a592fc 8009012: [macosx] DisplayChangedListener is not implemented in LWWindowPeer/CGraphicsEnvironment
serb
parents: 16840
diff changeset
    48
    private volatile int displayID;
9bfcf2a592fc 8009012: [macosx] DisplayChangedListener is not implemented in LWWindowPeer/CGraphicsEnvironment
serb
parents: 16840
diff changeset
    49
    private volatile double xResolution;
9bfcf2a592fc 8009012: [macosx] DisplayChangedListener is not implemented in LWWindowPeer/CGraphicsEnvironment
serb
parents: 16840
diff changeset
    50
    private volatile double yResolution;
52537
814c49afb1a7 8211992: GraphicsConfiguration.getDevice().getDisplayMode() causes JVM crash on Mac
serb
parents: 47216
diff changeset
    51
    private volatile Rectangle bounds;
17151
9bfcf2a592fc 8009012: [macosx] DisplayChangedListener is not implemented in LWWindowPeer/CGraphicsEnvironment
serb
parents: 16840
diff changeset
    52
    private volatile int scale;
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    53
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    54
    // Array of all GraphicsConfig instances for this device
12636
03f4fb9b26be 7124400: [macosx] CGraphicsDevice.getConfigurations() returns reference to member (does not copy configs)
bae
parents: 12047
diff changeset
    55
    private final GraphicsConfiguration[] configs;
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    56
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    57
    // Default config (temporarily hard coded)
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    58
    private final int DEFAULT_CONFIG = 0;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    59
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    60
    private static AWTPermission fullScreenExclusivePermission;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    61
13241
92c2140b5bb2 7182902: [macosx] Test api/java_awt/GraphicsDevice/indexTGF.html#SetDisplayMode fails on Mac OS X 10.7
alexsch
parents: 12836
diff changeset
    62
    // Save/restore DisplayMode for the Full Screen mode
92c2140b5bb2 7182902: [macosx] Test api/java_awt/GraphicsDevice/indexTGF.html#SetDisplayMode fails on Mac OS X 10.7
alexsch
parents: 12836
diff changeset
    63
    private DisplayMode originalMode;
92c2140b5bb2 7182902: [macosx] Test api/java_awt/GraphicsDevice/indexTGF.html#SetDisplayMode fails on Mac OS X 10.7
alexsch
parents: 12836
diff changeset
    64
17151
9bfcf2a592fc 8009012: [macosx] DisplayChangedListener is not implemented in LWWindowPeer/CGraphicsEnvironment
serb
parents: 16840
diff changeset
    65
    public CGraphicsDevice(final int displayID) {
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    66
        this.displayID = displayID;
12636
03f4fb9b26be 7124400: [macosx] CGraphicsDevice.getConfigurations() returns reference to member (does not copy configs)
bae
parents: 12047
diff changeset
    67
        configs = new GraphicsConfiguration[] {
52537
814c49afb1a7 8211992: GraphicsConfiguration.getDevice().getDisplayMode() causes JVM crash on Mac
serb
parents: 47216
diff changeset
    68
            CGLGraphicsConfig.getConfig(this, displayID, 0)
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    69
        };
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    70
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    71
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    72
    /**
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    73
     * Return a list of all configurations.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    74
     */
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    75
    @Override
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    76
    public GraphicsConfiguration[] getConfigurations() {
12636
03f4fb9b26be 7124400: [macosx] CGraphicsDevice.getConfigurations() returns reference to member (does not copy configs)
bae
parents: 12047
diff changeset
    77
        return configs.clone();
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    78
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    79
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    80
    /**
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    81
     * Return the default configuration.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    82
     */
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    83
    @Override
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    84
    public GraphicsConfiguration getDefaultConfiguration() {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    85
        return configs[DEFAULT_CONFIG];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    86
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    87
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    88
    /**
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    89
     * Return a human-readable screen description.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    90
     */
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    91
    @Override
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    92
    public String getIDstring() {
17151
9bfcf2a592fc 8009012: [macosx] DisplayChangedListener is not implemented in LWWindowPeer/CGraphicsEnvironment
serb
parents: 16840
diff changeset
    93
        return "Display " + displayID;
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    94
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    95
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    96
    /**
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    97
     * Returns the type of the graphics device.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    98
     * @see #TYPE_RASTER_SCREEN
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    99
     * @see #TYPE_PRINTER
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   100
     * @see #TYPE_IMAGE_BUFFER
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   101
     */
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   102
    @Override
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   103
    public int getType() {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   104
        return TYPE_RASTER_SCREEN;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   105
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   106
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   107
    public double getXResolution() {
17151
9bfcf2a592fc 8009012: [macosx] DisplayChangedListener is not implemented in LWWindowPeer/CGraphicsEnvironment
serb
parents: 16840
diff changeset
   108
        return xResolution;
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   109
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   110
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   111
    public double getYResolution() {
17151
9bfcf2a592fc 8009012: [macosx] DisplayChangedListener is not implemented in LWWindowPeer/CGraphicsEnvironment
serb
parents: 16840
diff changeset
   112
        return yResolution;
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   113
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   114
52537
814c49afb1a7 8211992: GraphicsConfiguration.getDevice().getDisplayMode() causes JVM crash on Mac
serb
parents: 47216
diff changeset
   115
    Rectangle getBounds() {
814c49afb1a7 8211992: GraphicsConfiguration.getDevice().getDisplayMode() causes JVM crash on Mac
serb
parents: 47216
diff changeset
   116
        return bounds.getBounds();
814c49afb1a7 8211992: GraphicsConfiguration.getDevice().getDisplayMode() causes JVM crash on Mac
serb
parents: 47216
diff changeset
   117
    }
814c49afb1a7 8211992: GraphicsConfiguration.getDevice().getDisplayMode() causes JVM crash on Mac
serb
parents: 47216
diff changeset
   118
15989
0fe0985a7bde 8003169: [macosx] JVM crash after disconnecting from projector
serb
parents: 15988
diff changeset
   119
    public Insets getScreenInsets() {
29256
751f31639710 8072069: Toolkit.getScreenInsets() doesn't update if insets change
anashaty
parents: 28235
diff changeset
   120
        // the insets are queried synchronously and are not cached
751f31639710 8072069: Toolkit.getScreenInsets() doesn't update if insets change
anashaty
parents: 28235
diff changeset
   121
        // since there are no Quartz or Cocoa means to receive notifications
751f31639710 8072069: Toolkit.getScreenInsets() doesn't update if insets change
anashaty
parents: 28235
diff changeset
   122
        // on insets changes (e.g. when the Dock is resized):
751f31639710 8072069: Toolkit.getScreenInsets() doesn't update if insets change
anashaty
parents: 28235
diff changeset
   123
        // the existing CGDisplayReconfigurationCallBack is not notified
751f31639710 8072069: Toolkit.getScreenInsets() doesn't update if insets change
anashaty
parents: 28235
diff changeset
   124
        // as well as the NSApplicationDidChangeScreenParametersNotification
751f31639710 8072069: Toolkit.getScreenInsets() doesn't update if insets change
anashaty
parents: 28235
diff changeset
   125
        // is fired on the Dock location changes only
751f31639710 8072069: Toolkit.getScreenInsets() doesn't update if insets change
anashaty
parents: 28235
diff changeset
   126
        return nativeGetScreenInsets(displayID);
17151
9bfcf2a592fc 8009012: [macosx] DisplayChangedListener is not implemented in LWWindowPeer/CGraphicsEnvironment
serb
parents: 16840
diff changeset
   127
    }
9bfcf2a592fc 8009012: [macosx] DisplayChangedListener is not implemented in LWWindowPeer/CGraphicsEnvironment
serb
parents: 16840
diff changeset
   128
9bfcf2a592fc 8009012: [macosx] DisplayChangedListener is not implemented in LWWindowPeer/CGraphicsEnvironment
serb
parents: 16840
diff changeset
   129
    public int getScaleFactor() {
9bfcf2a592fc 8009012: [macosx] DisplayChangedListener is not implemented in LWWindowPeer/CGraphicsEnvironment
serb
parents: 16840
diff changeset
   130
        return scale;
9bfcf2a592fc 8009012: [macosx] DisplayChangedListener is not implemented in LWWindowPeer/CGraphicsEnvironment
serb
parents: 16840
diff changeset
   131
    }
9bfcf2a592fc 8009012: [macosx] DisplayChangedListener is not implemented in LWWindowPeer/CGraphicsEnvironment
serb
parents: 16840
diff changeset
   132
9bfcf2a592fc 8009012: [macosx] DisplayChangedListener is not implemented in LWWindowPeer/CGraphicsEnvironment
serb
parents: 16840
diff changeset
   133
    public void invalidate(final int defaultDisplayID) {
9bfcf2a592fc 8009012: [macosx] DisplayChangedListener is not implemented in LWWindowPeer/CGraphicsEnvironment
serb
parents: 16840
diff changeset
   134
        displayID = defaultDisplayID;
9bfcf2a592fc 8009012: [macosx] DisplayChangedListener is not implemented in LWWindowPeer/CGraphicsEnvironment
serb
parents: 16840
diff changeset
   135
    }
9bfcf2a592fc 8009012: [macosx] DisplayChangedListener is not implemented in LWWindowPeer/CGraphicsEnvironment
serb
parents: 16840
diff changeset
   136
9bfcf2a592fc 8009012: [macosx] DisplayChangedListener is not implemented in LWWindowPeer/CGraphicsEnvironment
serb
parents: 16840
diff changeset
   137
    @Override
9bfcf2a592fc 8009012: [macosx] DisplayChangedListener is not implemented in LWWindowPeer/CGraphicsEnvironment
serb
parents: 16840
diff changeset
   138
    public void displayChanged() {
9bfcf2a592fc 8009012: [macosx] DisplayChangedListener is not implemented in LWWindowPeer/CGraphicsEnvironment
serb
parents: 16840
diff changeset
   139
        xResolution = nativeGetXResolution(displayID);
9bfcf2a592fc 8009012: [macosx] DisplayChangedListener is not implemented in LWWindowPeer/CGraphicsEnvironment
serb
parents: 16840
diff changeset
   140
        yResolution = nativeGetYResolution(displayID);
52537
814c49afb1a7 8211992: GraphicsConfiguration.getDevice().getDisplayMode() causes JVM crash on Mac
serb
parents: 47216
diff changeset
   141
        bounds = nativeGetBounds(displayID).getBounds(); //does integer rounding
36900
3940219afc12 8150844: [hidpi] [macosx] -Dsun.java2d.uiScale should be taken into account for OS X
alexsch
parents: 30469
diff changeset
   142
        initScaleFactor();
17151
9bfcf2a592fc 8009012: [macosx] DisplayChangedListener is not implemented in LWWindowPeer/CGraphicsEnvironment
serb
parents: 16840
diff changeset
   143
        //TODO configs/fullscreenWindow/modes?
9bfcf2a592fc 8009012: [macosx] DisplayChangedListener is not implemented in LWWindowPeer/CGraphicsEnvironment
serb
parents: 16840
diff changeset
   144
    }
9bfcf2a592fc 8009012: [macosx] DisplayChangedListener is not implemented in LWWindowPeer/CGraphicsEnvironment
serb
parents: 16840
diff changeset
   145
9bfcf2a592fc 8009012: [macosx] DisplayChangedListener is not implemented in LWWindowPeer/CGraphicsEnvironment
serb
parents: 16840
diff changeset
   146
    @Override
9bfcf2a592fc 8009012: [macosx] DisplayChangedListener is not implemented in LWWindowPeer/CGraphicsEnvironment
serb
parents: 16840
diff changeset
   147
    public void paletteChanged() {
9bfcf2a592fc 8009012: [macosx] DisplayChangedListener is not implemented in LWWindowPeer/CGraphicsEnvironment
serb
parents: 16840
diff changeset
   148
        // devices do not need to react to this event.
15989
0fe0985a7bde 8003169: [macosx] JVM crash after disconnecting from projector
serb
parents: 15988
diff changeset
   149
    }
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   150
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   151
    /**
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   152
     * Enters full-screen mode, or returns to windowed mode.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   153
     */
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   154
    @Override
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   155
    public synchronized void setFullScreenWindow(Window w) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   156
        Window old = getFullScreenWindow();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   157
        if (w == old) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   158
            return;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   159
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   160
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   161
        boolean fsSupported = isFullScreenSupported();
13241
92c2140b5bb2 7182902: [macosx] Test api/java_awt/GraphicsDevice/indexTGF.html#SetDisplayMode fails on Mac OS X 10.7
alexsch
parents: 12836
diff changeset
   162
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   163
        if (fsSupported && old != null) {
21790
dae43c3c462d 8028512: [macosx] Crash in full screen api if incorrect display mode is used
serb
parents: 17151
diff changeset
   164
            // enter windowed mode and restore original display mode
dae43c3c462d 8028512: [macosx] Crash in full screen api if incorrect display mode is used
serb
parents: 17151
diff changeset
   165
            exitFullScreenExclusive(old);
13241
92c2140b5bb2 7182902: [macosx] Test api/java_awt/GraphicsDevice/indexTGF.html#SetDisplayMode fails on Mac OS X 10.7
alexsch
parents: 12836
diff changeset
   166
            if (originalMode != null) {
92c2140b5bb2 7182902: [macosx] Test api/java_awt/GraphicsDevice/indexTGF.html#SetDisplayMode fails on Mac OS X 10.7
alexsch
parents: 12836
diff changeset
   167
                setDisplayMode(originalMode);
92c2140b5bb2 7182902: [macosx] Test api/java_awt/GraphicsDevice/indexTGF.html#SetDisplayMode fails on Mac OS X 10.7
alexsch
parents: 12836
diff changeset
   168
                originalMode = null;
92c2140b5bb2 7182902: [macosx] Test api/java_awt/GraphicsDevice/indexTGF.html#SetDisplayMode fails on Mac OS X 10.7
alexsch
parents: 12836
diff changeset
   169
            }
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   170
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   171
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   172
        super.setFullScreenWindow(w);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   173
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   174
        if (fsSupported && w != null) {
13241
92c2140b5bb2 7182902: [macosx] Test api/java_awt/GraphicsDevice/indexTGF.html#SetDisplayMode fails on Mac OS X 10.7
alexsch
parents: 12836
diff changeset
   175
            if (isDisplayChangeSupported()) {
92c2140b5bb2 7182902: [macosx] Test api/java_awt/GraphicsDevice/indexTGF.html#SetDisplayMode fails on Mac OS X 10.7
alexsch
parents: 12836
diff changeset
   176
                originalMode = getDisplayMode();
92c2140b5bb2 7182902: [macosx] Test api/java_awt/GraphicsDevice/indexTGF.html#SetDisplayMode fails on Mac OS X 10.7
alexsch
parents: 12836
diff changeset
   177
            }
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   178
            // enter fullscreen mode
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   179
            enterFullScreenExclusive(w);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   180
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   181
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   182
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   183
    /**
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   184
     * Returns true if this GraphicsDevice supports
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   185
     * full-screen exclusive mode and false otherwise.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   186
     */
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   187
    @Override
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   188
    public boolean isFullScreenSupported() {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   189
        return isFSExclusiveModeAllowed();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   190
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   191
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   192
    private static boolean isFSExclusiveModeAllowed() {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   193
        SecurityManager security = System.getSecurityManager();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   194
        if (security != null) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   195
            if (fullScreenExclusivePermission == null) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   196
                fullScreenExclusivePermission =
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   197
                    new AWTPermission("fullScreenExclusive");
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   198
            }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   199
            try {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   200
                security.checkPermission(fullScreenExclusivePermission);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   201
            } catch (SecurityException e) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   202
                return false;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   203
            }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   204
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   205
        return true;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   206
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   207
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   208
    private static void enterFullScreenExclusive(Window w) {
30469
bac0a7ff7e1e 8074028: Remove API references to java.awt.peer
serb
parents: 29256
diff changeset
   209
        FullScreenCapable peer = AWTAccessor.getComponentAccessor().getPeer(w);
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   210
        if (peer != null) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   211
            peer.enterFullScreenMode();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   212
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   213
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   214
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   215
    private static void exitFullScreenExclusive(Window w) {
30469
bac0a7ff7e1e 8074028: Remove API references to java.awt.peer
serb
parents: 29256
diff changeset
   216
        FullScreenCapable peer = AWTAccessor.getComponentAccessor().getPeer(w);
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   217
        if (peer != null) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   218
            peer.exitFullScreenMode();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   219
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   220
    }
12836
66cabfe1972f 7124247: [macosx] Implement GraphicsDevice.setDisplayMode()
kizune
parents: 12636
diff changeset
   221
66cabfe1972f 7124247: [macosx] Implement GraphicsDevice.setDisplayMode()
kizune
parents: 12636
diff changeset
   222
    @Override
66cabfe1972f 7124247: [macosx] Implement GraphicsDevice.setDisplayMode()
kizune
parents: 12636
diff changeset
   223
    public boolean isDisplayChangeSupported() {
66cabfe1972f 7124247: [macosx] Implement GraphicsDevice.setDisplayMode()
kizune
parents: 12636
diff changeset
   224
        return true;
66cabfe1972f 7124247: [macosx] Implement GraphicsDevice.setDisplayMode()
kizune
parents: 12636
diff changeset
   225
    }
66cabfe1972f 7124247: [macosx] Implement GraphicsDevice.setDisplayMode()
kizune
parents: 12636
diff changeset
   226
66cabfe1972f 7124247: [macosx] Implement GraphicsDevice.setDisplayMode()
kizune
parents: 12636
diff changeset
   227
    @Override
15331
410070becfef 8003173: [macosx] Fullscreen on Mac leaves an empty rectangle
serb
parents: 14166
diff changeset
   228
    public void setDisplayMode(final DisplayMode dm) {
14161
2b346f8e3b8f 7175704: [macosx] "8" PIT: NPE in GetDisplayMode fullscreen test
kizune
parents: 13241
diff changeset
   229
        if (dm == null) {
2b346f8e3b8f 7175704: [macosx] "8" PIT: NPE in GetDisplayMode fullscreen test
kizune
parents: 13241
diff changeset
   230
            throw new IllegalArgumentException("Invalid display mode");
2b346f8e3b8f 7175704: [macosx] "8" PIT: NPE in GetDisplayMode fullscreen test
kizune
parents: 13241
diff changeset
   231
        }
15331
410070becfef 8003173: [macosx] Fullscreen on Mac leaves an empty rectangle
serb
parents: 14166
diff changeset
   232
        if (!Objects.equals(dm, getDisplayMode())) {
410070becfef 8003173: [macosx] Fullscreen on Mac leaves an empty rectangle
serb
parents: 14166
diff changeset
   233
            nativeSetDisplayMode(displayID, dm.getWidth(), dm.getHeight(),
21790
dae43c3c462d 8028512: [macosx] Crash in full screen api if incorrect display mode is used
serb
parents: 17151
diff changeset
   234
                    dm.getBitDepth(), dm.getRefreshRate());
dae43c3c462d 8028512: [macosx] Crash in full screen api if incorrect display mode is used
serb
parents: 17151
diff changeset
   235
            if (isFullScreenSupported() && getFullScreenWindow() != null) {
dae43c3c462d 8028512: [macosx] Crash in full screen api if incorrect display mode is used
serb
parents: 17151
diff changeset
   236
                getFullScreenWindow().setSize(dm.getWidth(), dm.getHeight());
15331
410070becfef 8003173: [macosx] Fullscreen on Mac leaves an empty rectangle
serb
parents: 14166
diff changeset
   237
            }
12836
66cabfe1972f 7124247: [macosx] Implement GraphicsDevice.setDisplayMode()
kizune
parents: 12636
diff changeset
   238
        }
66cabfe1972f 7124247: [macosx] Implement GraphicsDevice.setDisplayMode()
kizune
parents: 12636
diff changeset
   239
    }
66cabfe1972f 7124247: [macosx] Implement GraphicsDevice.setDisplayMode()
kizune
parents: 12636
diff changeset
   240
66cabfe1972f 7124247: [macosx] Implement GraphicsDevice.setDisplayMode()
kizune
parents: 12636
diff changeset
   241
    @Override
66cabfe1972f 7124247: [macosx] Implement GraphicsDevice.setDisplayMode()
kizune
parents: 12636
diff changeset
   242
    public DisplayMode getDisplayMode() {
66cabfe1972f 7124247: [macosx] Implement GraphicsDevice.setDisplayMode()
kizune
parents: 12636
diff changeset
   243
        return nativeGetDisplayMode(displayID);
66cabfe1972f 7124247: [macosx] Implement GraphicsDevice.setDisplayMode()
kizune
parents: 12636
diff changeset
   244
    }
66cabfe1972f 7124247: [macosx] Implement GraphicsDevice.setDisplayMode()
kizune
parents: 12636
diff changeset
   245
66cabfe1972f 7124247: [macosx] Implement GraphicsDevice.setDisplayMode()
kizune
parents: 12636
diff changeset
   246
    @Override
66cabfe1972f 7124247: [macosx] Implement GraphicsDevice.setDisplayMode()
kizune
parents: 12636
diff changeset
   247
    public DisplayMode[] getDisplayModes() {
66cabfe1972f 7124247: [macosx] Implement GraphicsDevice.setDisplayMode()
kizune
parents: 12636
diff changeset
   248
        return nativeGetDisplayModes(displayID);
66cabfe1972f 7124247: [macosx] Implement GraphicsDevice.setDisplayMode()
kizune
parents: 12636
diff changeset
   249
    }
66cabfe1972f 7124247: [macosx] Implement GraphicsDevice.setDisplayMode()
kizune
parents: 12636
diff changeset
   250
36900
3940219afc12 8150844: [hidpi] [macosx] -Dsun.java2d.uiScale should be taken into account for OS X
alexsch
parents: 30469
diff changeset
   251
    private void initScaleFactor() {
3940219afc12 8150844: [hidpi] [macosx] -Dsun.java2d.uiScale should be taken into account for OS X
alexsch
parents: 30469
diff changeset
   252
        if (SunGraphicsEnvironment.isUIScaleEnabled()) {
3940219afc12 8150844: [hidpi] [macosx] -Dsun.java2d.uiScale should be taken into account for OS X
alexsch
parents: 30469
diff changeset
   253
            double debugScale = SunGraphicsEnvironment.getDebugScale();
3940219afc12 8150844: [hidpi] [macosx] -Dsun.java2d.uiScale should be taken into account for OS X
alexsch
parents: 30469
diff changeset
   254
            scale = (int) (debugScale >= 1
3940219afc12 8150844: [hidpi] [macosx] -Dsun.java2d.uiScale should be taken into account for OS X
alexsch
parents: 30469
diff changeset
   255
                    ? Math.round(debugScale)
3940219afc12 8150844: [hidpi] [macosx] -Dsun.java2d.uiScale should be taken into account for OS X
alexsch
parents: 30469
diff changeset
   256
                    : nativeGetScaleFactor(displayID));
3940219afc12 8150844: [hidpi] [macosx] -Dsun.java2d.uiScale should be taken into account for OS X
alexsch
parents: 30469
diff changeset
   257
        } else {
3940219afc12 8150844: [hidpi] [macosx] -Dsun.java2d.uiScale should be taken into account for OS X
alexsch
parents: 30469
diff changeset
   258
            scale = 1;
3940219afc12 8150844: [hidpi] [macosx] -Dsun.java2d.uiScale should be taken into account for OS X
alexsch
parents: 30469
diff changeset
   259
        }
3940219afc12 8150844: [hidpi] [macosx] -Dsun.java2d.uiScale should be taken into account for OS X
alexsch
parents: 30469
diff changeset
   260
    }
3940219afc12 8150844: [hidpi] [macosx] -Dsun.java2d.uiScale should be taken into account for OS X
alexsch
parents: 30469
diff changeset
   261
16840
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents: 15989
diff changeset
   262
    private static native double nativeGetScaleFactor(int displayID);
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents: 15989
diff changeset
   263
15989
0fe0985a7bde 8003169: [macosx] JVM crash after disconnecting from projector
serb
parents: 15988
diff changeset
   264
    private static native void nativeSetDisplayMode(int displayID, int w, int h, int bpp, int refrate);
0fe0985a7bde 8003169: [macosx] JVM crash after disconnecting from projector
serb
parents: 15988
diff changeset
   265
0fe0985a7bde 8003169: [macosx] JVM crash after disconnecting from projector
serb
parents: 15988
diff changeset
   266
    private static native DisplayMode nativeGetDisplayMode(int displayID);
0fe0985a7bde 8003169: [macosx] JVM crash after disconnecting from projector
serb
parents: 15988
diff changeset
   267
0fe0985a7bde 8003169: [macosx] JVM crash after disconnecting from projector
serb
parents: 15988
diff changeset
   268
    private static native DisplayMode[] nativeGetDisplayModes(int displayID);
12836
66cabfe1972f 7124247: [macosx] Implement GraphicsDevice.setDisplayMode()
kizune
parents: 12636
diff changeset
   269
15989
0fe0985a7bde 8003169: [macosx] JVM crash after disconnecting from projector
serb
parents: 15988
diff changeset
   270
    private static native double nativeGetXResolution(int displayID);
12836
66cabfe1972f 7124247: [macosx] Implement GraphicsDevice.setDisplayMode()
kizune
parents: 12636
diff changeset
   271
15989
0fe0985a7bde 8003169: [macosx] JVM crash after disconnecting from projector
serb
parents: 15988
diff changeset
   272
    private static native double nativeGetYResolution(int displayID);
0fe0985a7bde 8003169: [macosx] JVM crash after disconnecting from projector
serb
parents: 15988
diff changeset
   273
0fe0985a7bde 8003169: [macosx] JVM crash after disconnecting from projector
serb
parents: 15988
diff changeset
   274
    private static native Insets nativeGetScreenInsets(int displayID);
52537
814c49afb1a7 8211992: GraphicsConfiguration.getDevice().getDisplayMode() causes JVM crash on Mac
serb
parents: 47216
diff changeset
   275
814c49afb1a7 8211992: GraphicsConfiguration.getDevice().getDisplayMode() causes JVM crash on Mac
serb
parents: 47216
diff changeset
   276
    private static native Rectangle2D nativeGetBounds(int displayID);
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   277
}