author | pchelko |
Fri, 14 Mar 2014 16:01:04 +0400 | |
changeset 23651 | e41298d0da2f |
parent 23010 | 6dadb192ad81 |
child 23684 | 7a91a5f90266 |
permissions | -rw-r--r-- |
12047 | 1 |
/* |
23010
6dadb192ad81
8029235: Update copyright year to match last edit in jdk8 jdk repository for 2013
lana
parents:
17151
diff
changeset
|
2 |
* Copyright (c) 2011, 2013, 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 |
||
26 |
#import <JavaNativeFoundation/JavaNativeFoundation.h> |
|
27 |
||
28 |
#import "LWCToolkit.h" |
|
29 |
#import "AWT_debug.h" |
|
30 |
||
31 |
||
32 |
/* |
|
33 |
* Class: sun_awt_CGraphicsEnvironment |
|
34 |
* Method: initCocoa |
|
35 |
* Signature: ()V |
|
36 |
*/ |
|
37 |
JNIEXPORT void JNICALL |
|
38 |
Java_sun_awt_CGraphicsEnvironment_initCocoa |
|
39 |
(JNIEnv *env, jclass self) |
|
40 |
{ |
|
41 |
JNF_COCOA_ENTER(env); |
|
42 |
||
43 |
// Inform Cocoa that we're multi-threaded. |
|
44 |
// Creating a short-lived NSThread is the recommended way of doing so. |
|
45 |
[NSThread detachNewThreadSelector:@selector(self) toTarget:[NSObject class] withObject:nil]; |
|
46 |
||
47 |
JNF_COCOA_EXIT(env); |
|
48 |
} |
|
49 |
||
50 |
#define MAX_DISPLAYS 64 |
|
51 |
||
52 |
/* |
|
53 |
* Class: sun_awt_CGraphicsEnvironment |
|
54 |
* Method: getDisplayIDs |
|
55 |
* Signature: ()[I |
|
56 |
*/ |
|
57 |
JNIEXPORT jintArray JNICALL |
|
58 |
Java_sun_awt_CGraphicsEnvironment_getDisplayIDs |
|
59 |
(JNIEnv *env, jclass class) |
|
60 |
{ |
|
61 |
jintArray ret = NULL; |
|
62 |
||
63 |
JNF_COCOA_ENTER(env); |
|
64 |
||
65 |
/* Get the count */ |
|
66 |
CGDisplayCount displayCount; |
|
67 |
if (CGGetActiveDisplayList(MAX_DISPLAYS, NULL, &displayCount) != kCGErrorSuccess) { |
|
68 |
[JNFException raise:env |
|
69 |
as:kInternalError |
|
70 |
reason:"CGGetOnlineDisplayList() failed to get display count"]; |
|
71 |
return NULL; |
|
72 |
} |
|
73 |
||
74 |
/* Allocate an array and get the size list of display Ids */ |
|
75 |
CGDirectDisplayID displays[MAX_DISPLAYS]; |
|
76 |
if (CGGetActiveDisplayList(displayCount, displays, &displayCount) != kCGErrorSuccess) { |
|
77 |
[JNFException raise:env |
|
78 |
as:kInternalError |
|
79 |
reason:"CGGetOnlineDisplayList() failed to get display list"]; |
|
80 |
return NULL; |
|
81 |
} |
|
82 |
||
83 |
/* Allocate a java array for display identifiers */ |
|
84 |
ret = JNFNewIntArray(env, displayCount); |
|
85 |
||
86 |
/* Initialize and return the backing int array */ |
|
87 |
assert(sizeof(jint) >= sizeof(CGDirectDisplayID)); |
|
88 |
jint *elems = (*env)->GetIntArrayElements(env, ret, 0); |
|
89 |
||
90 |
CGDisplayCount i; |
|
91 |
for (i = 0; i < displayCount; i++) { |
|
92 |
elems[i] = displays[i]; |
|
93 |
} |
|
94 |
||
95 |
(*env)->ReleaseIntArrayElements(env, ret, elems, 0); |
|
96 |
||
97 |
JNF_COCOA_EXIT(env); |
|
98 |
||
99 |
return ret; |
|
100 |
} |
|
101 |
||
102 |
/* |
|
103 |
* Class: sun_awt_CGraphicsEnvironment |
|
104 |
* Method: getMainDisplayID |
|
105 |
* Signature: ()I |
|
106 |
*/ |
|
107 |
JNIEXPORT jint JNICALL |
|
108 |
Java_sun_awt_CGraphicsEnvironment_getMainDisplayID |
|
109 |
(JNIEnv *env, jclass class) |
|
110 |
{ |
|
111 |
return CGMainDisplayID(); |
|
112 |
} |
|
113 |
||
114 |
/* |
|
115 |
* Post the display reconfiguration event. |
|
116 |
*/ |
|
117 |
static void displaycb_handle |
|
118 |
(CGDirectDisplayID display, CGDisplayChangeSummaryFlags flags, void *userInfo) |
|
119 |
{ |
|
120 |
if (flags == kCGDisplayBeginConfigurationFlag) return; |
|
121 |
||
122 |
JNFPerformEnvBlock(JNFThreadDetachImmediately, ^(JNIEnv *env) { |
|
123 |
JNFWeakJObjectWrapper *wrapper = (JNFWeakJObjectWrapper *)userInfo; |
|
124 |
||
125 |
jobject graphicsEnv = [wrapper jObjectWithEnv:env]; |
|
126 |
if (graphicsEnv == NULL) return; // ref already GC'd |
|
127 |
static JNF_CLASS_CACHE(jc_CGraphicsEnvironment, "sun/awt/CGraphicsEnvironment"); |
|
17151
9bfcf2a592fc
8009012: [macosx] DisplayChangedListener is not implemented in LWWindowPeer/CGraphicsEnvironment
serb
parents:
12047
diff
changeset
|
128 |
static JNF_MEMBER_CACHE(jm_displayReconfiguration, jc_CGraphicsEnvironment, "_displayReconfiguration", "(IZ)V"); |
9bfcf2a592fc
8009012: [macosx] DisplayChangedListener is not implemented in LWWindowPeer/CGraphicsEnvironment
serb
parents:
12047
diff
changeset
|
129 |
JNFCallVoidMethod(env, graphicsEnv, jm_displayReconfiguration, |
9bfcf2a592fc
8009012: [macosx] DisplayChangedListener is not implemented in LWWindowPeer/CGraphicsEnvironment
serb
parents:
12047
diff
changeset
|
130 |
(jint) display, |
9bfcf2a592fc
8009012: [macosx] DisplayChangedListener is not implemented in LWWindowPeer/CGraphicsEnvironment
serb
parents:
12047
diff
changeset
|
131 |
(jboolean) flags & kCGDisplayRemoveFlag); |
12047 | 132 |
}); |
133 |
} |
|
134 |
||
135 |
/* |
|
136 |
* Class: sun_awt_CGraphicsEnvironment |
|
137 |
* Method: registerDisplayReconfiguration |
|
138 |
* Signature: ()J |
|
139 |
*/ |
|
140 |
JNIEXPORT jlong JNICALL |
|
141 |
Java_sun_awt_CGraphicsEnvironment_registerDisplayReconfiguration |
|
142 |
(JNIEnv *env, jobject this) |
|
143 |
{ |
|
144 |
jlong ret = 0L; |
|
145 |
||
146 |
JNF_COCOA_ENTER(env); |
|
147 |
||
23651
e41298d0da2f
8037099: [macosx] Remove all references to GC from native OBJ-C code
pchelko
parents:
23010
diff
changeset
|
148 |
JNFWeakJObjectWrapper *wrapper = [[JNFWeakJObjectWrapper wrapperWithJObject:this withEnv:env] retain]; |
12047 | 149 |
|
150 |
/* Register the callback */ |
|
151 |
if (CGDisplayRegisterReconfigurationCallback(&displaycb_handle, wrapper) != kCGErrorSuccess) { |
|
152 |
[JNFException raise:env |
|
153 |
as:kInternalError |
|
154 |
reason:"CGDisplayRegisterReconfigurationCallback() failed"]; |
|
155 |
return 0L; |
|
156 |
} |
|
157 |
||
158 |
ret = ptr_to_jlong(wrapper); |
|
159 |
||
160 |
JNF_COCOA_EXIT(env); |
|
161 |
||
162 |
return ret; |
|
163 |
} |
|
164 |
||
165 |
/* |
|
166 |
* Class: sun_awt_CGraphicsEnvironment |
|
167 |
* Method: deregisterDisplayReconfiguration |
|
168 |
* Signature: (J)V |
|
169 |
*/ |
|
170 |
JNIEXPORT void JNICALL |
|
171 |
Java_sun_awt_CGraphicsEnvironment_deregisterDisplayReconfiguration |
|
172 |
(JNIEnv *env, jobject this, jlong p) |
|
173 |
{ |
|
174 |
JNF_COCOA_ENTER(env); |
|
175 |
||
176 |
JNFWeakJObjectWrapper *wrapper = (JNFWeakJObjectWrapper *)jlong_to_ptr(p); |
|
177 |
if (!wrapper) return; |
|
178 |
||
179 |
/* Remove the registration */ |
|
180 |
if (CGDisplayRemoveReconfigurationCallback(&displaycb_handle, wrapper) != kCGErrorSuccess) { |
|
181 |
[JNFException raise:env |
|
182 |
as:kInternalError |
|
183 |
reason:"CGDisplayRemoveReconfigurationCallback() failed, leaking the callback context!"]; |
|
184 |
return; |
|
185 |
} |
|
186 |
||
187 |
[wrapper setJObject:NULL withEnv:env]; // more efficiant to pre-clear |
|
23651
e41298d0da2f
8037099: [macosx] Remove all references to GC from native OBJ-C code
pchelko
parents:
23010
diff
changeset
|
188 |
[wrapper release]; |
12047 | 189 |
|
190 |
JNF_COCOA_EXIT(env); |
|
191 |
} |