author | serb |
Thu, 24 Oct 2019 01:02:08 -0700 | |
changeset 59171 | 85d7af399ef5 |
parent 52537 | 814c49afb1a7 |
permissions | -rw-r--r-- |
12047 | 1 |
/* |
59171
85d7af399ef5
8213119: [macos] java/awt/GraphicsDevice/CheckDisplayModes.java fails
serb
parents:
52537
diff
changeset
|
2 |
* Copyright (c) 2012, 2019, Oracle and/or its affiliates. All rights reserved. |
12047 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
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 |
|
7 |
* published by the Free Software Foundation. Oracle designates this |
|
8 |
* particular file as subject to the "Classpath" exception as provided |
|
9 |
* by Oracle in the LICENSE file that accompanied this code. |
|
10 |
* |
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
24 |
*/ |
|
25 |
||
15989
0fe0985a7bde
8003169: [macosx] JVM crash after disconnecting from projector
serb
parents:
13241
diff
changeset
|
26 |
#import "LWCToolkit.h" |
0fe0985a7bde
8003169: [macosx] JVM crash after disconnecting from projector
serb
parents:
13241
diff
changeset
|
27 |
#import "ThreadUtilities.h" |
52537
814c49afb1a7
8211992: GraphicsConfiguration.getDevice().getDisplayMode() causes JVM crash on Mac
serb
parents:
47216
diff
changeset
|
28 |
#include "GeomUtilities.h" |
12047 | 29 |
|
32872 | 30 |
#import <JavaNativeFoundation/JavaNativeFoundation.h> |
31 |
||
52537
814c49afb1a7
8211992: GraphicsConfiguration.getDevice().getDisplayMode() causes JVM crash on Mac
serb
parents:
47216
diff
changeset
|
32 |
/** |
814c49afb1a7
8211992: GraphicsConfiguration.getDevice().getDisplayMode() causes JVM crash on Mac
serb
parents:
47216
diff
changeset
|
33 |
* Some default values for invalid CoreGraphics display ID. |
814c49afb1a7
8211992: GraphicsConfiguration.getDevice().getDisplayMode() causes JVM crash on Mac
serb
parents:
47216
diff
changeset
|
34 |
*/ |
814c49afb1a7
8211992: GraphicsConfiguration.getDevice().getDisplayMode() causes JVM crash on Mac
serb
parents:
47216
diff
changeset
|
35 |
#define DEFAULT_DEVICE_WIDTH 1024 |
814c49afb1a7
8211992: GraphicsConfiguration.getDevice().getDisplayMode() causes JVM crash on Mac
serb
parents:
47216
diff
changeset
|
36 |
#define DEFAULT_DEVICE_HEIGHT 768 |
814c49afb1a7
8211992: GraphicsConfiguration.getDevice().getDisplayMode() causes JVM crash on Mac
serb
parents:
47216
diff
changeset
|
37 |
#define DEFAULT_DEVICE_DPI 72 |
814c49afb1a7
8211992: GraphicsConfiguration.getDevice().getDisplayMode() causes JVM crash on Mac
serb
parents:
47216
diff
changeset
|
38 |
|
12047 | 39 |
/* |
12836
66cabfe1972f
7124247: [macosx] Implement GraphicsDevice.setDisplayMode()
kizune
parents:
12047
diff
changeset
|
40 |
* Convert the mode string to the more convinient bits per pixel value |
66cabfe1972f
7124247: [macosx] Implement GraphicsDevice.setDisplayMode()
kizune
parents:
12047
diff
changeset
|
41 |
*/ |
13241
92c2140b5bb2
7182902: [macosx] Test api/java_awt/GraphicsDevice/indexTGF.html#SetDisplayMode fails on Mac OS X 10.7
alexsch
parents:
12840
diff
changeset
|
42 |
static int getBPPFromModeString(CFStringRef mode) |
12836
66cabfe1972f
7124247: [macosx] Implement GraphicsDevice.setDisplayMode()
kizune
parents:
12047
diff
changeset
|
43 |
{ |
66cabfe1972f
7124247: [macosx] Implement GraphicsDevice.setDisplayMode()
kizune
parents:
12047
diff
changeset
|
44 |
if ((CFStringCompare(mode, CFSTR(kIO30BitDirectPixels), kCFCompareCaseInsensitive) == kCFCompareEqualTo)) { |
66cabfe1972f
7124247: [macosx] Implement GraphicsDevice.setDisplayMode()
kizune
parents:
12047
diff
changeset
|
45 |
// This is a strange mode, where we using 10 bits per RGB component and pack it into 32 bits |
66cabfe1972f
7124247: [macosx] Implement GraphicsDevice.setDisplayMode()
kizune
parents:
12047
diff
changeset
|
46 |
// Java is not ready to work with this mode but we have to specify it as supported |
66cabfe1972f
7124247: [macosx] Implement GraphicsDevice.setDisplayMode()
kizune
parents:
12047
diff
changeset
|
47 |
return 30; |
66cabfe1972f
7124247: [macosx] Implement GraphicsDevice.setDisplayMode()
kizune
parents:
12047
diff
changeset
|
48 |
} |
66cabfe1972f
7124247: [macosx] Implement GraphicsDevice.setDisplayMode()
kizune
parents:
12047
diff
changeset
|
49 |
else if (CFStringCompare(mode, CFSTR(IO32BitDirectPixels), kCFCompareCaseInsensitive) == kCFCompareEqualTo) { |
66cabfe1972f
7124247: [macosx] Implement GraphicsDevice.setDisplayMode()
kizune
parents:
12047
diff
changeset
|
50 |
return 32; |
66cabfe1972f
7124247: [macosx] Implement GraphicsDevice.setDisplayMode()
kizune
parents:
12047
diff
changeset
|
51 |
} |
66cabfe1972f
7124247: [macosx] Implement GraphicsDevice.setDisplayMode()
kizune
parents:
12047
diff
changeset
|
52 |
else if (CFStringCompare(mode, CFSTR(IO16BitDirectPixels), kCFCompareCaseInsensitive) == kCFCompareEqualTo) { |
66cabfe1972f
7124247: [macosx] Implement GraphicsDevice.setDisplayMode()
kizune
parents:
12047
diff
changeset
|
53 |
return 16; |
66cabfe1972f
7124247: [macosx] Implement GraphicsDevice.setDisplayMode()
kizune
parents:
12047
diff
changeset
|
54 |
} |
66cabfe1972f
7124247: [macosx] Implement GraphicsDevice.setDisplayMode()
kizune
parents:
12047
diff
changeset
|
55 |
else if (CFStringCompare(mode, CFSTR(IO8BitIndexedPixels), kCFCompareCaseInsensitive) == kCFCompareEqualTo) { |
66cabfe1972f
7124247: [macosx] Implement GraphicsDevice.setDisplayMode()
kizune
parents:
12047
diff
changeset
|
56 |
return 8; |
66cabfe1972f
7124247: [macosx] Implement GraphicsDevice.setDisplayMode()
kizune
parents:
12047
diff
changeset
|
57 |
} |
13241
92c2140b5bb2
7182902: [macosx] Test api/java_awt/GraphicsDevice/indexTGF.html#SetDisplayMode fails on Mac OS X 10.7
alexsch
parents:
12840
diff
changeset
|
58 |
|
12836
66cabfe1972f
7124247: [macosx] Implement GraphicsDevice.setDisplayMode()
kizune
parents:
12047
diff
changeset
|
59 |
return 0; |
66cabfe1972f
7124247: [macosx] Implement GraphicsDevice.setDisplayMode()
kizune
parents:
12047
diff
changeset
|
60 |
} |
66cabfe1972f
7124247: [macosx] Implement GraphicsDevice.setDisplayMode()
kizune
parents:
12047
diff
changeset
|
61 |
|
16470
ccc74e8572d5
8007146: [macosx] Setting a display mode crashes JDK under VNC
alexsch
parents:
15989
diff
changeset
|
62 |
static BOOL isValidDisplayMode(CGDisplayModeRef mode){ |
ccc74e8572d5
8007146: [macosx] Setting a display mode crashes JDK under VNC
alexsch
parents:
15989
diff
changeset
|
63 |
return (1 < CGDisplayModeGetWidth(mode) && 1 < CGDisplayModeGetHeight(mode)); |
ccc74e8572d5
8007146: [macosx] Setting a display mode crashes JDK under VNC
alexsch
parents:
15989
diff
changeset
|
64 |
} |
ccc74e8572d5
8007146: [macosx] Setting a display mode crashes JDK under VNC
alexsch
parents:
15989
diff
changeset
|
65 |
|
ccc74e8572d5
8007146: [macosx] Setting a display mode crashes JDK under VNC
alexsch
parents:
15989
diff
changeset
|
66 |
static CFMutableArrayRef getAllValidDisplayModes(jint displayID){ |
52537
814c49afb1a7
8211992: GraphicsConfiguration.getDevice().getDisplayMode() causes JVM crash on Mac
serb
parents:
47216
diff
changeset
|
67 |
// CGDisplayCopyAllDisplayModes can return NULL if displayID is invalid |
16470
ccc74e8572d5
8007146: [macosx] Setting a display mode crashes JDK under VNC
alexsch
parents:
15989
diff
changeset
|
68 |
CFArrayRef allModes = CGDisplayCopyAllDisplayModes(displayID, NULL); |
52537
814c49afb1a7
8211992: GraphicsConfiguration.getDevice().getDisplayMode() causes JVM crash on Mac
serb
parents:
47216
diff
changeset
|
69 |
CFMutableArrayRef validModes = nil; |
814c49afb1a7
8211992: GraphicsConfiguration.getDevice().getDisplayMode() causes JVM crash on Mac
serb
parents:
47216
diff
changeset
|
70 |
if (allModes) { |
814c49afb1a7
8211992: GraphicsConfiguration.getDevice().getDisplayMode() causes JVM crash on Mac
serb
parents:
47216
diff
changeset
|
71 |
CFIndex numModes = CFArrayGetCount(allModes); |
814c49afb1a7
8211992: GraphicsConfiguration.getDevice().getDisplayMode() causes JVM crash on Mac
serb
parents:
47216
diff
changeset
|
72 |
validModes = CFArrayCreateMutable(kCFAllocatorDefault, numModes + 1, &kCFTypeArrayCallBacks); |
16470
ccc74e8572d5
8007146: [macosx] Setting a display mode crashes JDK under VNC
alexsch
parents:
15989
diff
changeset
|
73 |
|
52537
814c49afb1a7
8211992: GraphicsConfiguration.getDevice().getDisplayMode() causes JVM crash on Mac
serb
parents:
47216
diff
changeset
|
74 |
CFIndex n; |
814c49afb1a7
8211992: GraphicsConfiguration.getDevice().getDisplayMode() causes JVM crash on Mac
serb
parents:
47216
diff
changeset
|
75 |
for (n=0; n < numModes; n++) { |
814c49afb1a7
8211992: GraphicsConfiguration.getDevice().getDisplayMode() causes JVM crash on Mac
serb
parents:
47216
diff
changeset
|
76 |
CGDisplayModeRef cRef = (CGDisplayModeRef) CFArrayGetValueAtIndex(allModes, n); |
814c49afb1a7
8211992: GraphicsConfiguration.getDevice().getDisplayMode() causes JVM crash on Mac
serb
parents:
47216
diff
changeset
|
77 |
if (cRef != NULL && isValidDisplayMode(cRef)) { |
814c49afb1a7
8211992: GraphicsConfiguration.getDevice().getDisplayMode() causes JVM crash on Mac
serb
parents:
47216
diff
changeset
|
78 |
CFArrayAppendValue(validModes, cRef); |
814c49afb1a7
8211992: GraphicsConfiguration.getDevice().getDisplayMode() causes JVM crash on Mac
serb
parents:
47216
diff
changeset
|
79 |
} |
814c49afb1a7
8211992: GraphicsConfiguration.getDevice().getDisplayMode() causes JVM crash on Mac
serb
parents:
47216
diff
changeset
|
80 |
} |
814c49afb1a7
8211992: GraphicsConfiguration.getDevice().getDisplayMode() causes JVM crash on Mac
serb
parents:
47216
diff
changeset
|
81 |
CFRelease(allModes); |
16470
ccc74e8572d5
8007146: [macosx] Setting a display mode crashes JDK under VNC
alexsch
parents:
15989
diff
changeset
|
82 |
|
52537
814c49afb1a7
8211992: GraphicsConfiguration.getDevice().getDisplayMode() causes JVM crash on Mac
serb
parents:
47216
diff
changeset
|
83 |
// CGDisplayCopyDisplayMode can return NULL if displayID is invalid |
814c49afb1a7
8211992: GraphicsConfiguration.getDevice().getDisplayMode() causes JVM crash on Mac
serb
parents:
47216
diff
changeset
|
84 |
CGDisplayModeRef currentMode = CGDisplayCopyDisplayMode(displayID); |
814c49afb1a7
8211992: GraphicsConfiguration.getDevice().getDisplayMode() causes JVM crash on Mac
serb
parents:
47216
diff
changeset
|
85 |
if (currentMode) { |
814c49afb1a7
8211992: GraphicsConfiguration.getDevice().getDisplayMode() causes JVM crash on Mac
serb
parents:
47216
diff
changeset
|
86 |
BOOL containsCurrentMode = NO; |
814c49afb1a7
8211992: GraphicsConfiguration.getDevice().getDisplayMode() causes JVM crash on Mac
serb
parents:
47216
diff
changeset
|
87 |
numModes = CFArrayGetCount(validModes); |
814c49afb1a7
8211992: GraphicsConfiguration.getDevice().getDisplayMode() causes JVM crash on Mac
serb
parents:
47216
diff
changeset
|
88 |
for (n=0; n < numModes; n++) { |
814c49afb1a7
8211992: GraphicsConfiguration.getDevice().getDisplayMode() causes JVM crash on Mac
serb
parents:
47216
diff
changeset
|
89 |
if(CFArrayGetValueAtIndex(validModes, n) == currentMode){ |
814c49afb1a7
8211992: GraphicsConfiguration.getDevice().getDisplayMode() causes JVM crash on Mac
serb
parents:
47216
diff
changeset
|
90 |
containsCurrentMode = YES; |
814c49afb1a7
8211992: GraphicsConfiguration.getDevice().getDisplayMode() causes JVM crash on Mac
serb
parents:
47216
diff
changeset
|
91 |
break; |
814c49afb1a7
8211992: GraphicsConfiguration.getDevice().getDisplayMode() causes JVM crash on Mac
serb
parents:
47216
diff
changeset
|
92 |
} |
814c49afb1a7
8211992: GraphicsConfiguration.getDevice().getDisplayMode() causes JVM crash on Mac
serb
parents:
47216
diff
changeset
|
93 |
} |
814c49afb1a7
8211992: GraphicsConfiguration.getDevice().getDisplayMode() causes JVM crash on Mac
serb
parents:
47216
diff
changeset
|
94 |
if (!containsCurrentMode) { |
814c49afb1a7
8211992: GraphicsConfiguration.getDevice().getDisplayMode() causes JVM crash on Mac
serb
parents:
47216
diff
changeset
|
95 |
CFArrayAppendValue(validModes, currentMode); |
814c49afb1a7
8211992: GraphicsConfiguration.getDevice().getDisplayMode() causes JVM crash on Mac
serb
parents:
47216
diff
changeset
|
96 |
} |
814c49afb1a7
8211992: GraphicsConfiguration.getDevice().getDisplayMode() causes JVM crash on Mac
serb
parents:
47216
diff
changeset
|
97 |
CGDisplayModeRelease(currentMode); |
16470
ccc74e8572d5
8007146: [macosx] Setting a display mode crashes JDK under VNC
alexsch
parents:
15989
diff
changeset
|
98 |
} |
ccc74e8572d5
8007146: [macosx] Setting a display mode crashes JDK under VNC
alexsch
parents:
15989
diff
changeset
|
99 |
} |
ccc74e8572d5
8007146: [macosx] Setting a display mode crashes JDK under VNC
alexsch
parents:
15989
diff
changeset
|
100 |
|
ccc74e8572d5
8007146: [macosx] Setting a display mode crashes JDK under VNC
alexsch
parents:
15989
diff
changeset
|
101 |
return validModes; |
ccc74e8572d5
8007146: [macosx] Setting a display mode crashes JDK under VNC
alexsch
parents:
15989
diff
changeset
|
102 |
} |
ccc74e8572d5
8007146: [macosx] Setting a display mode crashes JDK under VNC
alexsch
parents:
15989
diff
changeset
|
103 |
|
12836
66cabfe1972f
7124247: [macosx] Implement GraphicsDevice.setDisplayMode()
kizune
parents:
12047
diff
changeset
|
104 |
/* |
66cabfe1972f
7124247: [macosx] Implement GraphicsDevice.setDisplayMode()
kizune
parents:
12047
diff
changeset
|
105 |
* Find the best possible match in the list of display modes that we can switch to based on |
66cabfe1972f
7124247: [macosx] Implement GraphicsDevice.setDisplayMode()
kizune
parents:
12047
diff
changeset
|
106 |
* the provided parameters. |
66cabfe1972f
7124247: [macosx] Implement GraphicsDevice.setDisplayMode()
kizune
parents:
12047
diff
changeset
|
107 |
*/ |
66cabfe1972f
7124247: [macosx] Implement GraphicsDevice.setDisplayMode()
kizune
parents:
12047
diff
changeset
|
108 |
static CGDisplayModeRef getBestModeForParameters(CFArrayRef allModes, int w, int h, int bpp, int refrate) { |
66cabfe1972f
7124247: [macosx] Implement GraphicsDevice.setDisplayMode()
kizune
parents:
12047
diff
changeset
|
109 |
CGDisplayModeRef bestGuess = NULL; |
52537
814c49afb1a7
8211992: GraphicsConfiguration.getDevice().getDisplayMode() causes JVM crash on Mac
serb
parents:
47216
diff
changeset
|
110 |
CFIndex numModes = allModes ? CFArrayGetCount(allModes) : 0, n; |
59171
85d7af399ef5
8213119: [macos] java/awt/GraphicsDevice/CheckDisplayModes.java fails
serb
parents:
52537
diff
changeset
|
111 |
|
12836
66cabfe1972f
7124247: [macosx] Implement GraphicsDevice.setDisplayMode()
kizune
parents:
12047
diff
changeset
|
112 |
for(n = 0; n < numModes; n++ ) { |
66cabfe1972f
7124247: [macosx] Implement GraphicsDevice.setDisplayMode()
kizune
parents:
12047
diff
changeset
|
113 |
CGDisplayModeRef cRef = (CGDisplayModeRef) CFArrayGetValueAtIndex(allModes, n); |
66cabfe1972f
7124247: [macosx] Implement GraphicsDevice.setDisplayMode()
kizune
parents:
12047
diff
changeset
|
114 |
if(cRef == NULL) { |
66cabfe1972f
7124247: [macosx] Implement GraphicsDevice.setDisplayMode()
kizune
parents:
12047
diff
changeset
|
115 |
continue; |
66cabfe1972f
7124247: [macosx] Implement GraphicsDevice.setDisplayMode()
kizune
parents:
12047
diff
changeset
|
116 |
} |
66cabfe1972f
7124247: [macosx] Implement GraphicsDevice.setDisplayMode()
kizune
parents:
12047
diff
changeset
|
117 |
CFStringRef modeString = CGDisplayModeCopyPixelEncoding(cRef); |
59171
85d7af399ef5
8213119: [macos] java/awt/GraphicsDevice/CheckDisplayModes.java fails
serb
parents:
52537
diff
changeset
|
118 |
int thisBpp = getBPPFromModeString(modeString); |
12836
66cabfe1972f
7124247: [macosx] Implement GraphicsDevice.setDisplayMode()
kizune
parents:
12047
diff
changeset
|
119 |
CFRelease(modeString); |
59171
85d7af399ef5
8213119: [macos] java/awt/GraphicsDevice/CheckDisplayModes.java fails
serb
parents:
52537
diff
changeset
|
120 |
int thisH = (int)CGDisplayModeGetHeight(cRef); |
85d7af399ef5
8213119: [macos] java/awt/GraphicsDevice/CheckDisplayModes.java fails
serb
parents:
52537
diff
changeset
|
121 |
int thisW = (int)CGDisplayModeGetWidth(cRef); |
85d7af399ef5
8213119: [macos] java/awt/GraphicsDevice/CheckDisplayModes.java fails
serb
parents:
52537
diff
changeset
|
122 |
if (thisBpp != bpp || thisH != h || thisW != w) { |
12836
66cabfe1972f
7124247: [macosx] Implement GraphicsDevice.setDisplayMode()
kizune
parents:
12047
diff
changeset
|
123 |
// One of the key parameters does not match |
66cabfe1972f
7124247: [macosx] Implement GraphicsDevice.setDisplayMode()
kizune
parents:
12047
diff
changeset
|
124 |
continue; |
66cabfe1972f
7124247: [macosx] Implement GraphicsDevice.setDisplayMode()
kizune
parents:
12047
diff
changeset
|
125 |
} |
13241
92c2140b5bb2
7182902: [macosx] Test api/java_awt/GraphicsDevice/indexTGF.html#SetDisplayMode fails on Mac OS X 10.7
alexsch
parents:
12840
diff
changeset
|
126 |
|
92c2140b5bb2
7182902: [macosx] Test api/java_awt/GraphicsDevice/indexTGF.html#SetDisplayMode fails on Mac OS X 10.7
alexsch
parents:
12840
diff
changeset
|
127 |
if (refrate == 0) { // REFRESH_RATE_UNKNOWN |
92c2140b5bb2
7182902: [macosx] Test api/java_awt/GraphicsDevice/indexTGF.html#SetDisplayMode fails on Mac OS X 10.7
alexsch
parents:
12840
diff
changeset
|
128 |
return cRef; |
92c2140b5bb2
7182902: [macosx] Test api/java_awt/GraphicsDevice/indexTGF.html#SetDisplayMode fails on Mac OS X 10.7
alexsch
parents:
12840
diff
changeset
|
129 |
} |
92c2140b5bb2
7182902: [macosx] Test api/java_awt/GraphicsDevice/indexTGF.html#SetDisplayMode fails on Mac OS X 10.7
alexsch
parents:
12840
diff
changeset
|
130 |
|
12836
66cabfe1972f
7124247: [macosx] Implement GraphicsDevice.setDisplayMode()
kizune
parents:
12047
diff
changeset
|
131 |
// Refresh rate might be 0 in display mode and we ask for specific display rate |
66cabfe1972f
7124247: [macosx] Implement GraphicsDevice.setDisplayMode()
kizune
parents:
12047
diff
changeset
|
132 |
// but if we do not find exact match then 0 refresh rate might be just Ok |
59171
85d7af399ef5
8213119: [macos] java/awt/GraphicsDevice/CheckDisplayModes.java fails
serb
parents:
52537
diff
changeset
|
133 |
int thisRefrate = (int)CGDisplayModeGetRefreshRate(cRef); |
85d7af399ef5
8213119: [macos] java/awt/GraphicsDevice/CheckDisplayModes.java fails
serb
parents:
52537
diff
changeset
|
134 |
if (thisRefrate == refrate) { |
12836
66cabfe1972f
7124247: [macosx] Implement GraphicsDevice.setDisplayMode()
kizune
parents:
12047
diff
changeset
|
135 |
// Exact match |
66cabfe1972f
7124247: [macosx] Implement GraphicsDevice.setDisplayMode()
kizune
parents:
12047
diff
changeset
|
136 |
return cRef; |
66cabfe1972f
7124247: [macosx] Implement GraphicsDevice.setDisplayMode()
kizune
parents:
12047
diff
changeset
|
137 |
} |
59171
85d7af399ef5
8213119: [macos] java/awt/GraphicsDevice/CheckDisplayModes.java fails
serb
parents:
52537
diff
changeset
|
138 |
if (thisRefrate == 0) { |
12836
66cabfe1972f
7124247: [macosx] Implement GraphicsDevice.setDisplayMode()
kizune
parents:
12047
diff
changeset
|
139 |
// Not exactly what was asked for, but may fit our needs if we don't find an exact match |
66cabfe1972f
7124247: [macosx] Implement GraphicsDevice.setDisplayMode()
kizune
parents:
12047
diff
changeset
|
140 |
bestGuess = cRef; |
66cabfe1972f
7124247: [macosx] Implement GraphicsDevice.setDisplayMode()
kizune
parents:
12047
diff
changeset
|
141 |
} |
66cabfe1972f
7124247: [macosx] Implement GraphicsDevice.setDisplayMode()
kizune
parents:
12047
diff
changeset
|
142 |
} |
66cabfe1972f
7124247: [macosx] Implement GraphicsDevice.setDisplayMode()
kizune
parents:
12047
diff
changeset
|
143 |
return bestGuess; |
66cabfe1972f
7124247: [macosx] Implement GraphicsDevice.setDisplayMode()
kizune
parents:
12047
diff
changeset
|
144 |
} |
66cabfe1972f
7124247: [macosx] Implement GraphicsDevice.setDisplayMode()
kizune
parents:
12047
diff
changeset
|
145 |
|
66cabfe1972f
7124247: [macosx] Implement GraphicsDevice.setDisplayMode()
kizune
parents:
12047
diff
changeset
|
146 |
/* |
52537
814c49afb1a7
8211992: GraphicsConfiguration.getDevice().getDisplayMode() causes JVM crash on Mac
serb
parents:
47216
diff
changeset
|
147 |
* Create a new java.awt.DisplayMode instance based on provided |
814c49afb1a7
8211992: GraphicsConfiguration.getDevice().getDisplayMode() causes JVM crash on Mac
serb
parents:
47216
diff
changeset
|
148 |
* CGDisplayModeRef, if CGDisplayModeRef is NULL, then some stub is returned. |
12836
66cabfe1972f
7124247: [macosx] Implement GraphicsDevice.setDisplayMode()
kizune
parents:
12047
diff
changeset
|
149 |
*/ |
52537
814c49afb1a7
8211992: GraphicsConfiguration.getDevice().getDisplayMode() causes JVM crash on Mac
serb
parents:
47216
diff
changeset
|
150 |
static jobject createJavaDisplayMode(CGDisplayModeRef mode, JNIEnv *env) { |
12836
66cabfe1972f
7124247: [macosx] Implement GraphicsDevice.setDisplayMode()
kizune
parents:
12047
diff
changeset
|
151 |
jobject ret = NULL; |
52537
814c49afb1a7
8211992: GraphicsConfiguration.getDevice().getDisplayMode() causes JVM crash on Mac
serb
parents:
47216
diff
changeset
|
152 |
jint h = DEFAULT_DEVICE_HEIGHT, w = DEFAULT_DEVICE_WIDTH, bpp = 0, refrate = 0; |
12836
66cabfe1972f
7124247: [macosx] Implement GraphicsDevice.setDisplayMode()
kizune
parents:
12047
diff
changeset
|
153 |
JNF_COCOA_ENTER(env); |
52537
814c49afb1a7
8211992: GraphicsConfiguration.getDevice().getDisplayMode() causes JVM crash on Mac
serb
parents:
47216
diff
changeset
|
154 |
if (mode) { |
814c49afb1a7
8211992: GraphicsConfiguration.getDevice().getDisplayMode() causes JVM crash on Mac
serb
parents:
47216
diff
changeset
|
155 |
CFStringRef currentBPP = CGDisplayModeCopyPixelEncoding(mode); |
814c49afb1a7
8211992: GraphicsConfiguration.getDevice().getDisplayMode() causes JVM crash on Mac
serb
parents:
47216
diff
changeset
|
156 |
bpp = getBPPFromModeString(currentBPP); |
814c49afb1a7
8211992: GraphicsConfiguration.getDevice().getDisplayMode() causes JVM crash on Mac
serb
parents:
47216
diff
changeset
|
157 |
refrate = CGDisplayModeGetRefreshRate(mode); |
814c49afb1a7
8211992: GraphicsConfiguration.getDevice().getDisplayMode() causes JVM crash on Mac
serb
parents:
47216
diff
changeset
|
158 |
h = CGDisplayModeGetHeight(mode); |
814c49afb1a7
8211992: GraphicsConfiguration.getDevice().getDisplayMode() causes JVM crash on Mac
serb
parents:
47216
diff
changeset
|
159 |
w = CGDisplayModeGetWidth(mode); |
814c49afb1a7
8211992: GraphicsConfiguration.getDevice().getDisplayMode() causes JVM crash on Mac
serb
parents:
47216
diff
changeset
|
160 |
CFRelease(currentBPP); |
814c49afb1a7
8211992: GraphicsConfiguration.getDevice().getDisplayMode() causes JVM crash on Mac
serb
parents:
47216
diff
changeset
|
161 |
} |
12836
66cabfe1972f
7124247: [macosx] Implement GraphicsDevice.setDisplayMode()
kizune
parents:
12047
diff
changeset
|
162 |
static JNF_CLASS_CACHE(jc_DisplayMode, "java/awt/DisplayMode"); |
66cabfe1972f
7124247: [macosx] Implement GraphicsDevice.setDisplayMode()
kizune
parents:
12047
diff
changeset
|
163 |
static JNF_CTOR_CACHE(jc_DisplayMode_ctor, jc_DisplayMode, "(IIII)V"); |
66cabfe1972f
7124247: [macosx] Implement GraphicsDevice.setDisplayMode()
kizune
parents:
12047
diff
changeset
|
164 |
ret = JNFNewObject(env, jc_DisplayMode_ctor, w, h, bpp, refrate); |
66cabfe1972f
7124247: [macosx] Implement GraphicsDevice.setDisplayMode()
kizune
parents:
12047
diff
changeset
|
165 |
JNF_COCOA_EXIT(env); |
66cabfe1972f
7124247: [macosx] Implement GraphicsDevice.setDisplayMode()
kizune
parents:
12047
diff
changeset
|
166 |
return ret; |
66cabfe1972f
7124247: [macosx] Implement GraphicsDevice.setDisplayMode()
kizune
parents:
12047
diff
changeset
|
167 |
} |
66cabfe1972f
7124247: [macosx] Implement GraphicsDevice.setDisplayMode()
kizune
parents:
12047
diff
changeset
|
168 |
|
66cabfe1972f
7124247: [macosx] Implement GraphicsDevice.setDisplayMode()
kizune
parents:
12047
diff
changeset
|
169 |
|
66cabfe1972f
7124247: [macosx] Implement GraphicsDevice.setDisplayMode()
kizune
parents:
12047
diff
changeset
|
170 |
/* |
12047 | 171 |
* Class: sun_awt_CGraphicsDevice |
172 |
* Method: nativeGetXResolution |
|
173 |
* Signature: (I)D |
|
174 |
*/ |
|
175 |
JNIEXPORT jdouble JNICALL |
|
176 |
Java_sun_awt_CGraphicsDevice_nativeGetXResolution |
|
177 |
(JNIEnv *env, jclass class, jint displayID) |
|
178 |
{ |
|
24545
5f998bcc934e
8042212: [macosx] Toolkit.getScreenResolution() can return incorrect resolution
serb
parents:
24536
diff
changeset
|
179 |
// CGDisplayScreenSize can return 0 if displayID is invalid |
12047 | 180 |
CGSize size = CGDisplayScreenSize(displayID); |
181 |
CGRect rect = CGDisplayBounds(displayID); |
|
182 |
// 1 inch == 25.4 mm |
|
183 |
jfloat inches = size.width / 25.4f; |
|
52537
814c49afb1a7
8211992: GraphicsConfiguration.getDevice().getDisplayMode() causes JVM crash on Mac
serb
parents:
47216
diff
changeset
|
184 |
return inches > 0 ? rect.size.width / inches : DEFAULT_DEVICE_DPI; |
12047 | 185 |
} |
186 |
||
187 |
/* |
|
188 |
* Class: sun_awt_CGraphicsDevice |
|
189 |
* Method: nativeGetYResolution |
|
190 |
* Signature: (I)D |
|
191 |
*/ |
|
192 |
JNIEXPORT jdouble JNICALL |
|
193 |
Java_sun_awt_CGraphicsDevice_nativeGetYResolution |
|
194 |
(JNIEnv *env, jclass class, jint displayID) |
|
195 |
{ |
|
24545
5f998bcc934e
8042212: [macosx] Toolkit.getScreenResolution() can return incorrect resolution
serb
parents:
24536
diff
changeset
|
196 |
// CGDisplayScreenSize can return 0 if displayID is invalid |
12047 | 197 |
CGSize size = CGDisplayScreenSize(displayID); |
198 |
CGRect rect = CGDisplayBounds(displayID); |
|
199 |
// 1 inch == 25.4 mm |
|
200 |
jfloat inches = size.height / 25.4f; |
|
52537
814c49afb1a7
8211992: GraphicsConfiguration.getDevice().getDisplayMode() causes JVM crash on Mac
serb
parents:
47216
diff
changeset
|
201 |
return inches > 0 ? rect.size.height / inches : DEFAULT_DEVICE_DPI; |
814c49afb1a7
8211992: GraphicsConfiguration.getDevice().getDisplayMode() causes JVM crash on Mac
serb
parents:
47216
diff
changeset
|
202 |
} |
814c49afb1a7
8211992: GraphicsConfiguration.getDevice().getDisplayMode() causes JVM crash on Mac
serb
parents:
47216
diff
changeset
|
203 |
|
814c49afb1a7
8211992: GraphicsConfiguration.getDevice().getDisplayMode() causes JVM crash on Mac
serb
parents:
47216
diff
changeset
|
204 |
/* |
814c49afb1a7
8211992: GraphicsConfiguration.getDevice().getDisplayMode() causes JVM crash on Mac
serb
parents:
47216
diff
changeset
|
205 |
* Class: sun_awt_CGraphicsDevice |
814c49afb1a7
8211992: GraphicsConfiguration.getDevice().getDisplayMode() causes JVM crash on Mac
serb
parents:
47216
diff
changeset
|
206 |
* Method: nativeGetBounds |
814c49afb1a7
8211992: GraphicsConfiguration.getDevice().getDisplayMode() causes JVM crash on Mac
serb
parents:
47216
diff
changeset
|
207 |
* Signature: (I)Ljava/awt/Rectangle; |
814c49afb1a7
8211992: GraphicsConfiguration.getDevice().getDisplayMode() causes JVM crash on Mac
serb
parents:
47216
diff
changeset
|
208 |
*/ |
814c49afb1a7
8211992: GraphicsConfiguration.getDevice().getDisplayMode() causes JVM crash on Mac
serb
parents:
47216
diff
changeset
|
209 |
JNIEXPORT jobject JNICALL |
814c49afb1a7
8211992: GraphicsConfiguration.getDevice().getDisplayMode() causes JVM crash on Mac
serb
parents:
47216
diff
changeset
|
210 |
Java_sun_awt_CGraphicsDevice_nativeGetBounds |
814c49afb1a7
8211992: GraphicsConfiguration.getDevice().getDisplayMode() causes JVM crash on Mac
serb
parents:
47216
diff
changeset
|
211 |
(JNIEnv *env, jclass class, jint displayID) |
814c49afb1a7
8211992: GraphicsConfiguration.getDevice().getDisplayMode() causes JVM crash on Mac
serb
parents:
47216
diff
changeset
|
212 |
{ |
814c49afb1a7
8211992: GraphicsConfiguration.getDevice().getDisplayMode() causes JVM crash on Mac
serb
parents:
47216
diff
changeset
|
213 |
CGRect rect = CGDisplayBounds(displayID); |
814c49afb1a7
8211992: GraphicsConfiguration.getDevice().getDisplayMode() causes JVM crash on Mac
serb
parents:
47216
diff
changeset
|
214 |
if (rect.size.width == 0) { |
814c49afb1a7
8211992: GraphicsConfiguration.getDevice().getDisplayMode() causes JVM crash on Mac
serb
parents:
47216
diff
changeset
|
215 |
rect.size.width = DEFAULT_DEVICE_WIDTH; |
814c49afb1a7
8211992: GraphicsConfiguration.getDevice().getDisplayMode() causes JVM crash on Mac
serb
parents:
47216
diff
changeset
|
216 |
} |
814c49afb1a7
8211992: GraphicsConfiguration.getDevice().getDisplayMode() causes JVM crash on Mac
serb
parents:
47216
diff
changeset
|
217 |
if (rect.size.height == 0) { |
814c49afb1a7
8211992: GraphicsConfiguration.getDevice().getDisplayMode() causes JVM crash on Mac
serb
parents:
47216
diff
changeset
|
218 |
rect.size.height = DEFAULT_DEVICE_HEIGHT; |
814c49afb1a7
8211992: GraphicsConfiguration.getDevice().getDisplayMode() causes JVM crash on Mac
serb
parents:
47216
diff
changeset
|
219 |
} |
814c49afb1a7
8211992: GraphicsConfiguration.getDevice().getDisplayMode() causes JVM crash on Mac
serb
parents:
47216
diff
changeset
|
220 |
return CGToJavaRect(env, rect); |
12047 | 221 |
} |
12836
66cabfe1972f
7124247: [macosx] Implement GraphicsDevice.setDisplayMode()
kizune
parents:
12047
diff
changeset
|
222 |
|
66cabfe1972f
7124247: [macosx] Implement GraphicsDevice.setDisplayMode()
kizune
parents:
12047
diff
changeset
|
223 |
/* |
66cabfe1972f
7124247: [macosx] Implement GraphicsDevice.setDisplayMode()
kizune
parents:
12047
diff
changeset
|
224 |
* Class: sun_awt_CGraphicsDevice |
15989
0fe0985a7bde
8003169: [macosx] JVM crash after disconnecting from projector
serb
parents:
13241
diff
changeset
|
225 |
* Method: nativeGetScreenInsets |
0fe0985a7bde
8003169: [macosx] JVM crash after disconnecting from projector
serb
parents:
13241
diff
changeset
|
226 |
* Signature: (I)D |
0fe0985a7bde
8003169: [macosx] JVM crash after disconnecting from projector
serb
parents:
13241
diff
changeset
|
227 |
*/ |
0fe0985a7bde
8003169: [macosx] JVM crash after disconnecting from projector
serb
parents:
13241
diff
changeset
|
228 |
JNIEXPORT jobject JNICALL |
0fe0985a7bde
8003169: [macosx] JVM crash after disconnecting from projector
serb
parents:
13241
diff
changeset
|
229 |
Java_sun_awt_CGraphicsDevice_nativeGetScreenInsets |
0fe0985a7bde
8003169: [macosx] JVM crash after disconnecting from projector
serb
parents:
13241
diff
changeset
|
230 |
(JNIEnv *env, jclass class, jint displayID) |
0fe0985a7bde
8003169: [macosx] JVM crash after disconnecting from projector
serb
parents:
13241
diff
changeset
|
231 |
{ |
0fe0985a7bde
8003169: [macosx] JVM crash after disconnecting from projector
serb
parents:
13241
diff
changeset
|
232 |
jobject ret = NULL; |
0fe0985a7bde
8003169: [macosx] JVM crash after disconnecting from projector
serb
parents:
13241
diff
changeset
|
233 |
__block NSRect frame = NSZeroRect; |
0fe0985a7bde
8003169: [macosx] JVM crash after disconnecting from projector
serb
parents:
13241
diff
changeset
|
234 |
__block NSRect visibleFrame = NSZeroRect; |
0fe0985a7bde
8003169: [macosx] JVM crash after disconnecting from projector
serb
parents:
13241
diff
changeset
|
235 |
JNF_COCOA_ENTER(env); |
52537
814c49afb1a7
8211992: GraphicsConfiguration.getDevice().getDisplayMode() causes JVM crash on Mac
serb
parents:
47216
diff
changeset
|
236 |
|
15989
0fe0985a7bde
8003169: [macosx] JVM crash after disconnecting from projector
serb
parents:
13241
diff
changeset
|
237 |
[ThreadUtilities performOnMainThreadWaiting:YES block:^(){ |
0fe0985a7bde
8003169: [macosx] JVM crash after disconnecting from projector
serb
parents:
13241
diff
changeset
|
238 |
NSArray *screens = [NSScreen screens]; |
0fe0985a7bde
8003169: [macosx] JVM crash after disconnecting from projector
serb
parents:
13241
diff
changeset
|
239 |
for (NSScreen *screen in screens) { |
0fe0985a7bde
8003169: [macosx] JVM crash after disconnecting from projector
serb
parents:
13241
diff
changeset
|
240 |
NSDictionary *screenInfo = [screen deviceDescription]; |
0fe0985a7bde
8003169: [macosx] JVM crash after disconnecting from projector
serb
parents:
13241
diff
changeset
|
241 |
NSNumber *screenID = [screenInfo objectForKey:@"NSScreenNumber"]; |
32872 | 242 |
if ([screenID unsignedIntValue] == displayID){ |
15989
0fe0985a7bde
8003169: [macosx] JVM crash after disconnecting from projector
serb
parents:
13241
diff
changeset
|
243 |
frame = [screen frame]; |
0fe0985a7bde
8003169: [macosx] JVM crash after disconnecting from projector
serb
parents:
13241
diff
changeset
|
244 |
visibleFrame = [screen visibleFrame]; |
0fe0985a7bde
8003169: [macosx] JVM crash after disconnecting from projector
serb
parents:
13241
diff
changeset
|
245 |
break; |
0fe0985a7bde
8003169: [macosx] JVM crash after disconnecting from projector
serb
parents:
13241
diff
changeset
|
246 |
} |
0fe0985a7bde
8003169: [macosx] JVM crash after disconnecting from projector
serb
parents:
13241
diff
changeset
|
247 |
} |
0fe0985a7bde
8003169: [macosx] JVM crash after disconnecting from projector
serb
parents:
13241
diff
changeset
|
248 |
}]; |
0fe0985a7bde
8003169: [macosx] JVM crash after disconnecting from projector
serb
parents:
13241
diff
changeset
|
249 |
// Convert between Cocoa's coordinate system and Java. |
0fe0985a7bde
8003169: [macosx] JVM crash after disconnecting from projector
serb
parents:
13241
diff
changeset
|
250 |
jint bottom = visibleFrame.origin.y - frame.origin.y; |
0fe0985a7bde
8003169: [macosx] JVM crash after disconnecting from projector
serb
parents:
13241
diff
changeset
|
251 |
jint top = frame.size.height - visibleFrame.size.height - bottom; |
0fe0985a7bde
8003169: [macosx] JVM crash after disconnecting from projector
serb
parents:
13241
diff
changeset
|
252 |
jint left = visibleFrame.origin.x - frame.origin.x; |
0fe0985a7bde
8003169: [macosx] JVM crash after disconnecting from projector
serb
parents:
13241
diff
changeset
|
253 |
jint right = frame.size.width - visibleFrame.size.width - left; |
52537
814c49afb1a7
8211992: GraphicsConfiguration.getDevice().getDisplayMode() causes JVM crash on Mac
serb
parents:
47216
diff
changeset
|
254 |
|
15989
0fe0985a7bde
8003169: [macosx] JVM crash after disconnecting from projector
serb
parents:
13241
diff
changeset
|
255 |
static JNF_CLASS_CACHE(jc_Insets, "java/awt/Insets"); |
0fe0985a7bde
8003169: [macosx] JVM crash after disconnecting from projector
serb
parents:
13241
diff
changeset
|
256 |
static JNF_CTOR_CACHE(jc_Insets_ctor, jc_Insets, "(IIII)V"); |
0fe0985a7bde
8003169: [macosx] JVM crash after disconnecting from projector
serb
parents:
13241
diff
changeset
|
257 |
ret = JNFNewObject(env, jc_Insets_ctor, top, left, bottom, right); |
0fe0985a7bde
8003169: [macosx] JVM crash after disconnecting from projector
serb
parents:
13241
diff
changeset
|
258 |
|
0fe0985a7bde
8003169: [macosx] JVM crash after disconnecting from projector
serb
parents:
13241
diff
changeset
|
259 |
JNF_COCOA_EXIT(env); |
0fe0985a7bde
8003169: [macosx] JVM crash after disconnecting from projector
serb
parents:
13241
diff
changeset
|
260 |
|
0fe0985a7bde
8003169: [macosx] JVM crash after disconnecting from projector
serb
parents:
13241
diff
changeset
|
261 |
return ret; |
0fe0985a7bde
8003169: [macosx] JVM crash after disconnecting from projector
serb
parents:
13241
diff
changeset
|
262 |
} |
0fe0985a7bde
8003169: [macosx] JVM crash after disconnecting from projector
serb
parents:
13241
diff
changeset
|
263 |
|
0fe0985a7bde
8003169: [macosx] JVM crash after disconnecting from projector
serb
parents:
13241
diff
changeset
|
264 |
/* |
0fe0985a7bde
8003169: [macosx] JVM crash after disconnecting from projector
serb
parents:
13241
diff
changeset
|
265 |
* Class: sun_awt_CGraphicsDevice |
12836
66cabfe1972f
7124247: [macosx] Implement GraphicsDevice.setDisplayMode()
kizune
parents:
12047
diff
changeset
|
266 |
* Method: nativeSetDisplayMode |
66cabfe1972f
7124247: [macosx] Implement GraphicsDevice.setDisplayMode()
kizune
parents:
12047
diff
changeset
|
267 |
* Signature: (IIIII)V |
66cabfe1972f
7124247: [macosx] Implement GraphicsDevice.setDisplayMode()
kizune
parents:
12047
diff
changeset
|
268 |
*/ |
66cabfe1972f
7124247: [macosx] Implement GraphicsDevice.setDisplayMode()
kizune
parents:
12047
diff
changeset
|
269 |
JNIEXPORT void JNICALL |
66cabfe1972f
7124247: [macosx] Implement GraphicsDevice.setDisplayMode()
kizune
parents:
12047
diff
changeset
|
270 |
Java_sun_awt_CGraphicsDevice_nativeSetDisplayMode |
66cabfe1972f
7124247: [macosx] Implement GraphicsDevice.setDisplayMode()
kizune
parents:
12047
diff
changeset
|
271 |
(JNIEnv *env, jclass class, jint displayID, jint w, jint h, jint bpp, jint refrate) |
66cabfe1972f
7124247: [macosx] Implement GraphicsDevice.setDisplayMode()
kizune
parents:
12047
diff
changeset
|
272 |
{ |
66cabfe1972f
7124247: [macosx] Implement GraphicsDevice.setDisplayMode()
kizune
parents:
12047
diff
changeset
|
273 |
JNF_COCOA_ENTER(env); |
16470
ccc74e8572d5
8007146: [macosx] Setting a display mode crashes JDK under VNC
alexsch
parents:
15989
diff
changeset
|
274 |
CFArrayRef allModes = getAllValidDisplayModes(displayID); |
12836
66cabfe1972f
7124247: [macosx] Implement GraphicsDevice.setDisplayMode()
kizune
parents:
12047
diff
changeset
|
275 |
CGDisplayModeRef closestMatch = getBestModeForParameters(allModes, (int)w, (int)h, (int)bpp, (int)refrate); |
52537
814c49afb1a7
8211992: GraphicsConfiguration.getDevice().getDisplayMode() causes JVM crash on Mac
serb
parents:
47216
diff
changeset
|
276 |
|
16470
ccc74e8572d5
8007146: [macosx] Setting a display mode crashes JDK under VNC
alexsch
parents:
15989
diff
changeset
|
277 |
__block CGError retCode = kCGErrorSuccess; |
12836
66cabfe1972f
7124247: [macosx] Implement GraphicsDevice.setDisplayMode()
kizune
parents:
12047
diff
changeset
|
278 |
if (closestMatch != NULL) { |
24536 | 279 |
CGDisplayModeRetain(closestMatch); |
280 |
[ThreadUtilities performOnMainThreadWaiting:YES block:^(){ |
|
12840
4157f2200059
7175566: [macosx] Glich in fix for CR7124247 caused MacOS crash during PIT testing
kizune
parents:
12836
diff
changeset
|
281 |
CGDisplayConfigRef config; |
16470
ccc74e8572d5
8007146: [macosx] Setting a display mode crashes JDK under VNC
alexsch
parents:
15989
diff
changeset
|
282 |
retCode = CGBeginDisplayConfiguration(&config); |
12840
4157f2200059
7175566: [macosx] Glich in fix for CR7124247 caused MacOS crash during PIT testing
kizune
parents:
12836
diff
changeset
|
283 |
if (retCode == kCGErrorSuccess) { |
4157f2200059
7175566: [macosx] Glich in fix for CR7124247 caused MacOS crash during PIT testing
kizune
parents:
12836
diff
changeset
|
284 |
CGConfigureDisplayWithDisplayMode(config, displayID, closestMatch, NULL); |
16470
ccc74e8572d5
8007146: [macosx] Setting a display mode crashes JDK under VNC
alexsch
parents:
15989
diff
changeset
|
285 |
retCode = CGCompleteDisplayConfiguration(config, kCGConfigureForAppOnly); |
12840
4157f2200059
7175566: [macosx] Glich in fix for CR7124247 caused MacOS crash during PIT testing
kizune
parents:
12836
diff
changeset
|
286 |
} |
24536 | 287 |
CGDisplayModeRelease(closestMatch); |
12840
4157f2200059
7175566: [macosx] Glich in fix for CR7124247 caused MacOS crash during PIT testing
kizune
parents:
12836
diff
changeset
|
288 |
}]; |
13241
92c2140b5bb2
7182902: [macosx] Test api/java_awt/GraphicsDevice/indexTGF.html#SetDisplayMode fails on Mac OS X 10.7
alexsch
parents:
12840
diff
changeset
|
289 |
} else { |
92c2140b5bb2
7182902: [macosx] Test api/java_awt/GraphicsDevice/indexTGF.html#SetDisplayMode fails on Mac OS X 10.7
alexsch
parents:
12840
diff
changeset
|
290 |
[JNFException raise:env as:kIllegalArgumentException reason:"Invalid display mode"]; |
12836
66cabfe1972f
7124247: [macosx] Implement GraphicsDevice.setDisplayMode()
kizune
parents:
12047
diff
changeset
|
291 |
} |
13241
92c2140b5bb2
7182902: [macosx] Test api/java_awt/GraphicsDevice/indexTGF.html#SetDisplayMode fails on Mac OS X 10.7
alexsch
parents:
12840
diff
changeset
|
292 |
|
16470
ccc74e8572d5
8007146: [macosx] Setting a display mode crashes JDK under VNC
alexsch
parents:
15989
diff
changeset
|
293 |
if (retCode != kCGErrorSuccess){ |
ccc74e8572d5
8007146: [macosx] Setting a display mode crashes JDK under VNC
alexsch
parents:
15989
diff
changeset
|
294 |
[JNFException raise:env as:kIllegalArgumentException reason:"Unable to set display mode!"]; |
24536 | 295 |
} |
12836
66cabfe1972f
7124247: [macosx] Implement GraphicsDevice.setDisplayMode()
kizune
parents:
12047
diff
changeset
|
296 |
CFRelease(allModes); |
66cabfe1972f
7124247: [macosx] Implement GraphicsDevice.setDisplayMode()
kizune
parents:
12047
diff
changeset
|
297 |
JNF_COCOA_EXIT(env); |
66cabfe1972f
7124247: [macosx] Implement GraphicsDevice.setDisplayMode()
kizune
parents:
12047
diff
changeset
|
298 |
} |
66cabfe1972f
7124247: [macosx] Implement GraphicsDevice.setDisplayMode()
kizune
parents:
12047
diff
changeset
|
299 |
/* |
66cabfe1972f
7124247: [macosx] Implement GraphicsDevice.setDisplayMode()
kizune
parents:
12047
diff
changeset
|
300 |
* Class: sun_awt_CGraphicsDevice |
66cabfe1972f
7124247: [macosx] Implement GraphicsDevice.setDisplayMode()
kizune
parents:
12047
diff
changeset
|
301 |
* Method: nativeGetDisplayMode |
66cabfe1972f
7124247: [macosx] Implement GraphicsDevice.setDisplayMode()
kizune
parents:
12047
diff
changeset
|
302 |
* Signature: (I)Ljava/awt/DisplayMode |
66cabfe1972f
7124247: [macosx] Implement GraphicsDevice.setDisplayMode()
kizune
parents:
12047
diff
changeset
|
303 |
*/ |
66cabfe1972f
7124247: [macosx] Implement GraphicsDevice.setDisplayMode()
kizune
parents:
12047
diff
changeset
|
304 |
JNIEXPORT jobject JNICALL |
66cabfe1972f
7124247: [macosx] Implement GraphicsDevice.setDisplayMode()
kizune
parents:
12047
diff
changeset
|
305 |
Java_sun_awt_CGraphicsDevice_nativeGetDisplayMode |
66cabfe1972f
7124247: [macosx] Implement GraphicsDevice.setDisplayMode()
kizune
parents:
12047
diff
changeset
|
306 |
(JNIEnv *env, jclass class, jint displayID) |
66cabfe1972f
7124247: [macosx] Implement GraphicsDevice.setDisplayMode()
kizune
parents:
12047
diff
changeset
|
307 |
{ |
66cabfe1972f
7124247: [macosx] Implement GraphicsDevice.setDisplayMode()
kizune
parents:
12047
diff
changeset
|
308 |
jobject ret = NULL; |
52537
814c49afb1a7
8211992: GraphicsConfiguration.getDevice().getDisplayMode() causes JVM crash on Mac
serb
parents:
47216
diff
changeset
|
309 |
// CGDisplayCopyDisplayMode can return NULL if displayID is invalid |
12836
66cabfe1972f
7124247: [macosx] Implement GraphicsDevice.setDisplayMode()
kizune
parents:
12047
diff
changeset
|
310 |
CGDisplayModeRef currentMode = CGDisplayCopyDisplayMode(displayID); |
52537
814c49afb1a7
8211992: GraphicsConfiguration.getDevice().getDisplayMode() causes JVM crash on Mac
serb
parents:
47216
diff
changeset
|
311 |
ret = createJavaDisplayMode(currentMode, env); |
12836
66cabfe1972f
7124247: [macosx] Implement GraphicsDevice.setDisplayMode()
kizune
parents:
12047
diff
changeset
|
312 |
CGDisplayModeRelease(currentMode); |
66cabfe1972f
7124247: [macosx] Implement GraphicsDevice.setDisplayMode()
kizune
parents:
12047
diff
changeset
|
313 |
return ret; |
66cabfe1972f
7124247: [macosx] Implement GraphicsDevice.setDisplayMode()
kizune
parents:
12047
diff
changeset
|
314 |
} |
66cabfe1972f
7124247: [macosx] Implement GraphicsDevice.setDisplayMode()
kizune
parents:
12047
diff
changeset
|
315 |
|
66cabfe1972f
7124247: [macosx] Implement GraphicsDevice.setDisplayMode()
kizune
parents:
12047
diff
changeset
|
316 |
/* |
66cabfe1972f
7124247: [macosx] Implement GraphicsDevice.setDisplayMode()
kizune
parents:
12047
diff
changeset
|
317 |
* Class: sun_awt_CGraphicsDevice |
66cabfe1972f
7124247: [macosx] Implement GraphicsDevice.setDisplayMode()
kizune
parents:
12047
diff
changeset
|
318 |
* Method: nativeGetDisplayMode |
66cabfe1972f
7124247: [macosx] Implement GraphicsDevice.setDisplayMode()
kizune
parents:
12047
diff
changeset
|
319 |
* Signature: (I)[Ljava/awt/DisplayModes |
66cabfe1972f
7124247: [macosx] Implement GraphicsDevice.setDisplayMode()
kizune
parents:
12047
diff
changeset
|
320 |
*/ |
66cabfe1972f
7124247: [macosx] Implement GraphicsDevice.setDisplayMode()
kizune
parents:
12047
diff
changeset
|
321 |
JNIEXPORT jobjectArray JNICALL |
66cabfe1972f
7124247: [macosx] Implement GraphicsDevice.setDisplayMode()
kizune
parents:
12047
diff
changeset
|
322 |
Java_sun_awt_CGraphicsDevice_nativeGetDisplayModes |
66cabfe1972f
7124247: [macosx] Implement GraphicsDevice.setDisplayMode()
kizune
parents:
12047
diff
changeset
|
323 |
(JNIEnv *env, jclass class, jint displayID) |
66cabfe1972f
7124247: [macosx] Implement GraphicsDevice.setDisplayMode()
kizune
parents:
12047
diff
changeset
|
324 |
{ |
66cabfe1972f
7124247: [macosx] Implement GraphicsDevice.setDisplayMode()
kizune
parents:
12047
diff
changeset
|
325 |
jobjectArray jreturnArray = NULL; |
66cabfe1972f
7124247: [macosx] Implement GraphicsDevice.setDisplayMode()
kizune
parents:
12047
diff
changeset
|
326 |
JNF_COCOA_ENTER(env); |
16470
ccc74e8572d5
8007146: [macosx] Setting a display mode crashes JDK under VNC
alexsch
parents:
15989
diff
changeset
|
327 |
CFArrayRef allModes = getAllValidDisplayModes(displayID); |
ccc74e8572d5
8007146: [macosx] Setting a display mode crashes JDK under VNC
alexsch
parents:
15989
diff
changeset
|
328 |
|
52537
814c49afb1a7
8211992: GraphicsConfiguration.getDevice().getDisplayMode() causes JVM crash on Mac
serb
parents:
47216
diff
changeset
|
329 |
CFIndex numModes = allModes ? CFArrayGetCount(allModes): 0; |
12836
66cabfe1972f
7124247: [macosx] Implement GraphicsDevice.setDisplayMode()
kizune
parents:
12047
diff
changeset
|
330 |
static JNF_CLASS_CACHE(jc_DisplayMode, "java/awt/DisplayMode"); |
66cabfe1972f
7124247: [macosx] Implement GraphicsDevice.setDisplayMode()
kizune
parents:
12047
diff
changeset
|
331 |
|
66cabfe1972f
7124247: [macosx] Implement GraphicsDevice.setDisplayMode()
kizune
parents:
12047
diff
changeset
|
332 |
jreturnArray = JNFNewObjectArray(env, &jc_DisplayMode, (jsize) numModes); |
66cabfe1972f
7124247: [macosx] Implement GraphicsDevice.setDisplayMode()
kizune
parents:
12047
diff
changeset
|
333 |
if (!jreturnArray) { |
66cabfe1972f
7124247: [macosx] Implement GraphicsDevice.setDisplayMode()
kizune
parents:
12047
diff
changeset
|
334 |
NSLog(@"CGraphicsDevice can't create java array of DisplayMode objects"); |
66cabfe1972f
7124247: [macosx] Implement GraphicsDevice.setDisplayMode()
kizune
parents:
12047
diff
changeset
|
335 |
return nil; |
66cabfe1972f
7124247: [macosx] Implement GraphicsDevice.setDisplayMode()
kizune
parents:
12047
diff
changeset
|
336 |
} |
66cabfe1972f
7124247: [macosx] Implement GraphicsDevice.setDisplayMode()
kizune
parents:
12047
diff
changeset
|
337 |
|
66cabfe1972f
7124247: [macosx] Implement GraphicsDevice.setDisplayMode()
kizune
parents:
12047
diff
changeset
|
338 |
CFIndex n; |
66cabfe1972f
7124247: [macosx] Implement GraphicsDevice.setDisplayMode()
kizune
parents:
12047
diff
changeset
|
339 |
for (n=0; n < numModes; n++) { |
66cabfe1972f
7124247: [macosx] Implement GraphicsDevice.setDisplayMode()
kizune
parents:
12047
diff
changeset
|
340 |
CGDisplayModeRef cRef = (CGDisplayModeRef) CFArrayGetValueAtIndex(allModes, n); |
66cabfe1972f
7124247: [macosx] Implement GraphicsDevice.setDisplayMode()
kizune
parents:
12047
diff
changeset
|
341 |
if (cRef != NULL) { |
52537
814c49afb1a7
8211992: GraphicsConfiguration.getDevice().getDisplayMode() causes JVM crash on Mac
serb
parents:
47216
diff
changeset
|
342 |
jobject oneMode = createJavaDisplayMode(cRef, env); |
12836
66cabfe1972f
7124247: [macosx] Implement GraphicsDevice.setDisplayMode()
kizune
parents:
12047
diff
changeset
|
343 |
(*env)->SetObjectArrayElement(env, jreturnArray, n, oneMode); |
66cabfe1972f
7124247: [macosx] Implement GraphicsDevice.setDisplayMode()
kizune
parents:
12047
diff
changeset
|
344 |
if ((*env)->ExceptionOccurred(env)) { |
66cabfe1972f
7124247: [macosx] Implement GraphicsDevice.setDisplayMode()
kizune
parents:
12047
diff
changeset
|
345 |
(*env)->ExceptionDescribe(env); |
66cabfe1972f
7124247: [macosx] Implement GraphicsDevice.setDisplayMode()
kizune
parents:
12047
diff
changeset
|
346 |
(*env)->ExceptionClear(env); |
66cabfe1972f
7124247: [macosx] Implement GraphicsDevice.setDisplayMode()
kizune
parents:
12047
diff
changeset
|
347 |
continue; |
66cabfe1972f
7124247: [macosx] Implement GraphicsDevice.setDisplayMode()
kizune
parents:
12047
diff
changeset
|
348 |
} |
66cabfe1972f
7124247: [macosx] Implement GraphicsDevice.setDisplayMode()
kizune
parents:
12047
diff
changeset
|
349 |
(*env)->DeleteLocalRef(env, oneMode); |
66cabfe1972f
7124247: [macosx] Implement GraphicsDevice.setDisplayMode()
kizune
parents:
12047
diff
changeset
|
350 |
} |
66cabfe1972f
7124247: [macosx] Implement GraphicsDevice.setDisplayMode()
kizune
parents:
12047
diff
changeset
|
351 |
} |
52537
814c49afb1a7
8211992: GraphicsConfiguration.getDevice().getDisplayMode() causes JVM crash on Mac
serb
parents:
47216
diff
changeset
|
352 |
if (allModes) { |
814c49afb1a7
8211992: GraphicsConfiguration.getDevice().getDisplayMode() causes JVM crash on Mac
serb
parents:
47216
diff
changeset
|
353 |
CFRelease(allModes); |
814c49afb1a7
8211992: GraphicsConfiguration.getDevice().getDisplayMode() causes JVM crash on Mac
serb
parents:
47216
diff
changeset
|
354 |
} |
12836
66cabfe1972f
7124247: [macosx] Implement GraphicsDevice.setDisplayMode()
kizune
parents:
12047
diff
changeset
|
355 |
JNF_COCOA_EXIT(env); |
66cabfe1972f
7124247: [macosx] Implement GraphicsDevice.setDisplayMode()
kizune
parents:
12047
diff
changeset
|
356 |
|
66cabfe1972f
7124247: [macosx] Implement GraphicsDevice.setDisplayMode()
kizune
parents:
12047
diff
changeset
|
357 |
return jreturnArray; |
66cabfe1972f
7124247: [macosx] Implement GraphicsDevice.setDisplayMode()
kizune
parents:
12047
diff
changeset
|
358 |
} |
16840
64446d4710c4
8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents:
16470
diff
changeset
|
359 |
|
64446d4710c4
8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents:
16470
diff
changeset
|
360 |
/* |
64446d4710c4
8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents:
16470
diff
changeset
|
361 |
* Class: sun_awt_CGraphicsDevice |
64446d4710c4
8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents:
16470
diff
changeset
|
362 |
* Method: nativeGetScaleFactor |
64446d4710c4
8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents:
16470
diff
changeset
|
363 |
* Signature: (I)D |
64446d4710c4
8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents:
16470
diff
changeset
|
364 |
*/ |
64446d4710c4
8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents:
16470
diff
changeset
|
365 |
JNIEXPORT jdouble JNICALL |
64446d4710c4
8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents:
16470
diff
changeset
|
366 |
Java_sun_awt_CGraphicsDevice_nativeGetScaleFactor |
64446d4710c4
8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents:
16470
diff
changeset
|
367 |
(JNIEnv *env, jclass class, jint displayID) |
64446d4710c4
8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents:
16470
diff
changeset
|
368 |
{ |
64446d4710c4
8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents:
16470
diff
changeset
|
369 |
__block jdouble ret = 1.0f; |
64446d4710c4
8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents:
16470
diff
changeset
|
370 |
|
64446d4710c4
8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents:
16470
diff
changeset
|
371 |
JNF_COCOA_ENTER(env); |
64446d4710c4
8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents:
16470
diff
changeset
|
372 |
|
64446d4710c4
8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents:
16470
diff
changeset
|
373 |
[ThreadUtilities performOnMainThreadWaiting:YES block:^(){ |
64446d4710c4
8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents:
16470
diff
changeset
|
374 |
NSArray *screens = [NSScreen screens]; |
64446d4710c4
8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents:
16470
diff
changeset
|
375 |
for (NSScreen *screen in screens) { |
64446d4710c4
8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents:
16470
diff
changeset
|
376 |
NSDictionary *screenInfo = [screen deviceDescription]; |
64446d4710c4
8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents:
16470
diff
changeset
|
377 |
NSNumber *screenID = [screenInfo objectForKey:@"NSScreenNumber"]; |
32872 | 378 |
if ([screenID unsignedIntValue] == displayID){ |
16840
64446d4710c4
8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents:
16470
diff
changeset
|
379 |
if ([screen respondsToSelector:@selector(backingScaleFactor)]) { |
64446d4710c4
8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents:
16470
diff
changeset
|
380 |
ret = [screen backingScaleFactor]; |
64446d4710c4
8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents:
16470
diff
changeset
|
381 |
} |
64446d4710c4
8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents:
16470
diff
changeset
|
382 |
break; |
64446d4710c4
8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents:
16470
diff
changeset
|
383 |
} |
64446d4710c4
8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents:
16470
diff
changeset
|
384 |
} |
64446d4710c4
8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents:
16470
diff
changeset
|
385 |
}]; |
64446d4710c4
8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents:
16470
diff
changeset
|
386 |
|
64446d4710c4
8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents:
16470
diff
changeset
|
387 |
JNF_COCOA_EXIT(env); |
64446d4710c4
8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents:
16470
diff
changeset
|
388 |
return ret; |
64446d4710c4
8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents:
16470
diff
changeset
|
389 |
} |