src/java.desktop/macosx/classes/sun/awt/CGraphicsDevice.java
changeset 52537 814c49afb1a7
parent 47216 71c04702a3d5
child 53673 e04d39094915
equal deleted inserted replaced
52536:d09e1ab4bd1d 52537:814c49afb1a7
     1 /*
     1 /*
     2  * Copyright (c) 2012, 2015, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 2012, 2018, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.  Oracle designates this
     7  * published by the Free Software Foundation.  Oracle designates this
    28 import java.awt.AWTPermission;
    28 import java.awt.AWTPermission;
    29 import java.awt.DisplayMode;
    29 import java.awt.DisplayMode;
    30 import java.awt.GraphicsConfiguration;
    30 import java.awt.GraphicsConfiguration;
    31 import java.awt.GraphicsDevice;
    31 import java.awt.GraphicsDevice;
    32 import java.awt.Insets;
    32 import java.awt.Insets;
       
    33 import java.awt.Rectangle;
    33 import java.awt.Window;
    34 import java.awt.Window;
       
    35 import java.awt.geom.Rectangle2D;
    34 import java.util.Objects;
    36 import java.util.Objects;
       
    37 
    35 import sun.java2d.SunGraphicsEnvironment;
    38 import sun.java2d.SunGraphicsEnvironment;
    36 import sun.java2d.opengl.CGLGraphicsConfig;
    39 import sun.java2d.opengl.CGLGraphicsConfig;
    37 
    40 
    38 public final class CGraphicsDevice extends GraphicsDevice
    41 public final class CGraphicsDevice extends GraphicsDevice
    39         implements DisplayChangedListener {
    42         implements DisplayChangedListener {
    43      * therefore methods, which is using this id should be ready to it.
    46      * therefore methods, which is using this id should be ready to it.
    44      */
    47      */
    45     private volatile int displayID;
    48     private volatile int displayID;
    46     private volatile double xResolution;
    49     private volatile double xResolution;
    47     private volatile double yResolution;
    50     private volatile double yResolution;
       
    51     private volatile Rectangle bounds;
    48     private volatile int scale;
    52     private volatile int scale;
    49 
    53 
    50     // Array of all GraphicsConfig instances for this device
    54     // Array of all GraphicsConfig instances for this device
    51     private final GraphicsConfiguration[] configs;
    55     private final GraphicsConfiguration[] configs;
    52 
    56 
    59     private DisplayMode originalMode;
    63     private DisplayMode originalMode;
    60 
    64 
    61     public CGraphicsDevice(final int displayID) {
    65     public CGraphicsDevice(final int displayID) {
    62         this.displayID = displayID;
    66         this.displayID = displayID;
    63         configs = new GraphicsConfiguration[] {
    67         configs = new GraphicsConfiguration[] {
    64             CGLGraphicsConfig.getConfig(this, 0)
    68             CGLGraphicsConfig.getConfig(this, displayID, 0)
    65         };
    69         };
    66     }
       
    67 
       
    68     /**
       
    69      * Returns CGDirectDisplayID, which is the same id as @"NSScreenNumber" in
       
    70      * NSScreen.
       
    71      *
       
    72      * @return CoreGraphics display id.
       
    73      */
       
    74     public int getCGDisplayID() {
       
    75         return displayID;
       
    76     }
    70     }
    77 
    71 
    78     /**
    72     /**
    79      * Return a list of all configurations.
    73      * Return a list of all configurations.
    80      */
    74      */
   114         return xResolution;
   108         return xResolution;
   115     }
   109     }
   116 
   110 
   117     public double getYResolution() {
   111     public double getYResolution() {
   118         return yResolution;
   112         return yResolution;
       
   113     }
       
   114 
       
   115     Rectangle getBounds() {
       
   116         return bounds.getBounds();
   119     }
   117     }
   120 
   118 
   121     public Insets getScreenInsets() {
   119     public Insets getScreenInsets() {
   122         // the insets are queried synchronously and are not cached
   120         // the insets are queried synchronously and are not cached
   123         // since there are no Quartz or Cocoa means to receive notifications
   121         // since there are no Quartz or Cocoa means to receive notifications
   138 
   136 
   139     @Override
   137     @Override
   140     public void displayChanged() {
   138     public void displayChanged() {
   141         xResolution = nativeGetXResolution(displayID);
   139         xResolution = nativeGetXResolution(displayID);
   142         yResolution = nativeGetYResolution(displayID);
   140         yResolution = nativeGetYResolution(displayID);
       
   141         bounds = nativeGetBounds(displayID).getBounds(); //does integer rounding
   143         initScaleFactor();
   142         initScaleFactor();
   144         //TODO configs/fullscreenWindow/modes?
   143         //TODO configs/fullscreenWindow/modes?
   145     }
   144     }
   146 
   145 
   147     @Override
   146     @Override
   271     private static native double nativeGetXResolution(int displayID);
   270     private static native double nativeGetXResolution(int displayID);
   272 
   271 
   273     private static native double nativeGetYResolution(int displayID);
   272     private static native double nativeGetYResolution(int displayID);
   274 
   273 
   275     private static native Insets nativeGetScreenInsets(int displayID);
   274     private static native Insets nativeGetScreenInsets(int displayID);
       
   275 
       
   276     private static native Rectangle2D nativeGetBounds(int displayID);
   276 }
   277 }