8042212: [macosx] Toolkit.getScreenResolution() can return incorrect resolution
Reviewed-by: anthony, pchelko
--- a/jdk/src/macosx/native/sun/awt/CGraphicsDevice.m Wed Apr 30 19:28:05 2014 +0400
+++ b/jdk/src/macosx/native/sun/awt/CGraphicsDevice.m Mon May 05 19:42:11 2014 +0400
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2012, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -156,14 +156,12 @@
Java_sun_awt_CGraphicsDevice_nativeGetXResolution
(JNIEnv *env, jclass class, jint displayID)
{
- // TODO: this is the physically correct answer, but we probably want
- // to use NSScreen API instead...
+ // CGDisplayScreenSize can return 0 if displayID is invalid
CGSize size = CGDisplayScreenSize(displayID);
CGRect rect = CGDisplayBounds(displayID);
// 1 inch == 25.4 mm
jfloat inches = size.width / 25.4f;
- jfloat dpi = rect.size.width / inches;
- return dpi;
+ return inches > 0 ? rect.size.width / inches : 72;
}
/*
@@ -175,14 +173,12 @@
Java_sun_awt_CGraphicsDevice_nativeGetYResolution
(JNIEnv *env, jclass class, jint displayID)
{
- // TODO: this is the physically correct answer, but we probably want
- // to use NSScreen API instead...
+ // CGDisplayScreenSize can return 0 if displayID is invalid
CGSize size = CGDisplayScreenSize(displayID);
CGRect rect = CGDisplayBounds(displayID);
// 1 inch == 25.4 mm
jfloat inches = size.height / 25.4f;
- jfloat dpi = rect.size.height / inches;
- return dpi;
+ return inches > 0 ? rect.size.height / inches : 72;
}
/*