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 "LWCToolkit.h"
27 #import "ThreadUtilities.h"
28
29 /*
30 * Convert the mode string to the more convinient bits per pixel value
31 */
32 static int getBPPFromModeString(CFStringRef mode)
33 {
34 if ((CFStringCompare(mode, CFSTR(kIO30BitDirectPixels), kCFCompareCaseInsensitive) == kCFCompareEqualTo)) {
35 // This is a strange mode, where we using 10 bits per RGB component and pack it into 32 bits
36 // Java is not ready to work with this mode but we have to specify it as supported
37 return 30;
38 }
39 else if (CFStringCompare(mode, CFSTR(IO32BitDirectPixels), kCFCompareCaseInsensitive) == kCFCompareEqualTo) {
40 return 32;
41 }
42 else if (CFStringCompare(mode, CFSTR(IO16BitDirectPixels), kCFCompareCaseInsensitive) == kCFCompareEqualTo) {
43 return 16;
44 }
45 else if (CFStringCompare(mode, CFSTR(IO8BitIndexedPixels), kCFCompareCaseInsensitive) == kCFCompareEqualTo) {
46 return 8;
47 }
48
183
184 /*
185 * Class: sun_awt_CGraphicsDevice
186 * Method: nativeGetScreenInsets
187 * Signature: (I)D
188 */
189 JNIEXPORT jobject JNICALL
190 Java_sun_awt_CGraphicsDevice_nativeGetScreenInsets
191 (JNIEnv *env, jclass class, jint displayID)
192 {
193 jobject ret = NULL;
194 __block NSRect frame = NSZeroRect;
195 __block NSRect visibleFrame = NSZeroRect;
196 JNF_COCOA_ENTER(env);
197
198 [ThreadUtilities performOnMainThreadWaiting:YES block:^(){
199 NSArray *screens = [NSScreen screens];
200 for (NSScreen *screen in screens) {
201 NSDictionary *screenInfo = [screen deviceDescription];
202 NSNumber *screenID = [screenInfo objectForKey:@"NSScreenNumber"];
203 if ([screenID pointerValue] == displayID){
204 frame = [screen frame];
205 visibleFrame = [screen visibleFrame];
206 break;
207 }
208 }
209 }];
210 // Convert between Cocoa's coordinate system and Java.
211 jint bottom = visibleFrame.origin.y - frame.origin.y;
212 jint top = frame.size.height - visibleFrame.size.height - bottom;
213 jint left = visibleFrame.origin.x - frame.origin.x;
214 jint right = frame.size.width - visibleFrame.size.width - left;
215
216 static JNF_CLASS_CACHE(jc_Insets, "java/awt/Insets");
217 static JNF_CTOR_CACHE(jc_Insets_ctor, jc_Insets, "(IIII)V");
218 ret = JNFNewObject(env, jc_Insets_ctor, top, left, bottom, right);
219
220 JNF_COCOA_EXIT(env);
221
222 return ret;
223 }
316 }
317
318 /*
319 * Class: sun_awt_CGraphicsDevice
320 * Method: nativeGetScaleFactor
321 * Signature: (I)D
322 */
323 JNIEXPORT jdouble JNICALL
324 Java_sun_awt_CGraphicsDevice_nativeGetScaleFactor
325 (JNIEnv *env, jclass class, jint displayID)
326 {
327 __block jdouble ret = 1.0f;
328
329 JNF_COCOA_ENTER(env);
330
331 [ThreadUtilities performOnMainThreadWaiting:YES block:^(){
332 NSArray *screens = [NSScreen screens];
333 for (NSScreen *screen in screens) {
334 NSDictionary *screenInfo = [screen deviceDescription];
335 NSNumber *screenID = [screenInfo objectForKey:@"NSScreenNumber"];
336 if ([screenID pointerValue] == displayID){
337 if ([screen respondsToSelector:@selector(backingScaleFactor)]) {
338 ret = [screen backingScaleFactor];
339 }
340 break;
341 }
342 }
343 }];
344
345 JNF_COCOA_EXIT(env);
346 return ret;
347 }
|
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 "LWCToolkit.h"
27 #import "ThreadUtilities.h"
28
29 #import <JavaNativeFoundation/JavaNativeFoundation.h>
30
31 /*
32 * Convert the mode string to the more convinient bits per pixel value
33 */
34 static int getBPPFromModeString(CFStringRef mode)
35 {
36 if ((CFStringCompare(mode, CFSTR(kIO30BitDirectPixels), kCFCompareCaseInsensitive) == kCFCompareEqualTo)) {
37 // This is a strange mode, where we using 10 bits per RGB component and pack it into 32 bits
38 // Java is not ready to work with this mode but we have to specify it as supported
39 return 30;
40 }
41 else if (CFStringCompare(mode, CFSTR(IO32BitDirectPixels), kCFCompareCaseInsensitive) == kCFCompareEqualTo) {
42 return 32;
43 }
44 else if (CFStringCompare(mode, CFSTR(IO16BitDirectPixels), kCFCompareCaseInsensitive) == kCFCompareEqualTo) {
45 return 16;
46 }
47 else if (CFStringCompare(mode, CFSTR(IO8BitIndexedPixels), kCFCompareCaseInsensitive) == kCFCompareEqualTo) {
48 return 8;
49 }
50
185
186 /*
187 * Class: sun_awt_CGraphicsDevice
188 * Method: nativeGetScreenInsets
189 * Signature: (I)D
190 */
191 JNIEXPORT jobject JNICALL
192 Java_sun_awt_CGraphicsDevice_nativeGetScreenInsets
193 (JNIEnv *env, jclass class, jint displayID)
194 {
195 jobject ret = NULL;
196 __block NSRect frame = NSZeroRect;
197 __block NSRect visibleFrame = NSZeroRect;
198 JNF_COCOA_ENTER(env);
199
200 [ThreadUtilities performOnMainThreadWaiting:YES block:^(){
201 NSArray *screens = [NSScreen screens];
202 for (NSScreen *screen in screens) {
203 NSDictionary *screenInfo = [screen deviceDescription];
204 NSNumber *screenID = [screenInfo objectForKey:@"NSScreenNumber"];
205 if ([screenID unsignedIntValue] == displayID){
206 frame = [screen frame];
207 visibleFrame = [screen visibleFrame];
208 break;
209 }
210 }
211 }];
212 // Convert between Cocoa's coordinate system and Java.
213 jint bottom = visibleFrame.origin.y - frame.origin.y;
214 jint top = frame.size.height - visibleFrame.size.height - bottom;
215 jint left = visibleFrame.origin.x - frame.origin.x;
216 jint right = frame.size.width - visibleFrame.size.width - left;
217
218 static JNF_CLASS_CACHE(jc_Insets, "java/awt/Insets");
219 static JNF_CTOR_CACHE(jc_Insets_ctor, jc_Insets, "(IIII)V");
220 ret = JNFNewObject(env, jc_Insets_ctor, top, left, bottom, right);
221
222 JNF_COCOA_EXIT(env);
223
224 return ret;
225 }
318 }
319
320 /*
321 * Class: sun_awt_CGraphicsDevice
322 * Method: nativeGetScaleFactor
323 * Signature: (I)D
324 */
325 JNIEXPORT jdouble JNICALL
326 Java_sun_awt_CGraphicsDevice_nativeGetScaleFactor
327 (JNIEnv *env, jclass class, jint displayID)
328 {
329 __block jdouble ret = 1.0f;
330
331 JNF_COCOA_ENTER(env);
332
333 [ThreadUtilities performOnMainThreadWaiting:YES block:^(){
334 NSArray *screens = [NSScreen screens];
335 for (NSScreen *screen in screens) {
336 NSDictionary *screenInfo = [screen deviceDescription];
337 NSNumber *screenID = [screenInfo objectForKey:@"NSScreenNumber"];
338 if ([screenID unsignedIntValue] == displayID){
339 if ([screen respondsToSelector:@selector(backingScaleFactor)]) {
340 ret = [screen backingScaleFactor];
341 }
342 break;
343 }
344 }
345 }];
346
347 JNF_COCOA_EXIT(env);
348 return ret;
349 }
|