src/macosx/native/sun/awt/CGraphicsDevice.m

Print this page


   1 /*
   2  * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
   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


 139     h = CGDisplayModeGetHeight(mode);
 140     w = CGDisplayModeGetWidth(mode);
 141     CFRelease(currentBPP);
 142     static JNF_CLASS_CACHE(jc_DisplayMode, "java/awt/DisplayMode");
 143     static JNF_CTOR_CACHE(jc_DisplayMode_ctor, jc_DisplayMode, "(IIII)V");
 144     ret = JNFNewObject(env, jc_DisplayMode_ctor, w, h, bpp, refrate);
 145     JNF_COCOA_EXIT(env);
 146     return ret;
 147 }
 148 
 149 
 150 /*
 151  * Class:     sun_awt_CGraphicsDevice
 152  * Method:    nativeGetXResolution
 153  * Signature: (I)D
 154  */
 155 JNIEXPORT jdouble JNICALL
 156 Java_sun_awt_CGraphicsDevice_nativeGetXResolution
 157   (JNIEnv *env, jclass class, jint displayID)
 158 {
 159     // TODO: this is the physically correct answer, but we probably want
 160     // to use NSScreen API instead...
 161     CGSize size = CGDisplayScreenSize(displayID);
 162     CGRect rect = CGDisplayBounds(displayID);
 163     // 1 inch == 25.4 mm
 164     jfloat inches = size.width / 25.4f;
 165     jfloat dpi = rect.size.width / inches;
 166     return dpi;
 167 }
 168 
 169 /*
 170  * Class:     sun_awt_CGraphicsDevice
 171  * Method:    nativeGetYResolution
 172  * Signature: (I)D
 173  */
 174 JNIEXPORT jdouble JNICALL
 175 Java_sun_awt_CGraphicsDevice_nativeGetYResolution
 176   (JNIEnv *env, jclass class, jint displayID)
 177 {
 178     // TODO: this is the physically correct answer, but we probably want
 179     // to use NSScreen API instead...
 180     CGSize size = CGDisplayScreenSize(displayID);
 181     CGRect rect = CGDisplayBounds(displayID);
 182     // 1 inch == 25.4 mm
 183     jfloat inches = size.height / 25.4f;
 184     jfloat dpi = rect.size.height / inches;
 185     return dpi;
 186 }
 187 
 188 /*
 189  * Class:     sun_awt_CGraphicsDevice
 190  * Method:    nativeGetScreenInsets
 191  * Signature: (I)D
 192  */
 193 JNIEXPORT jobject JNICALL
 194 Java_sun_awt_CGraphicsDevice_nativeGetScreenInsets
 195   (JNIEnv *env, jclass class, jint displayID)
 196 {
 197     jobject ret = NULL;
 198     __block NSRect frame = NSZeroRect;
 199     __block NSRect visibleFrame = NSZeroRect;
 200 JNF_COCOA_ENTER(env);
 201     
 202     [ThreadUtilities performOnMainThreadWaiting:YES block:^(){
 203         NSArray *screens = [NSScreen screens];
 204         for (NSScreen *screen in screens) {
 205             NSDictionary *screenInfo = [screen deviceDescription];


   1 /*
   2  * Copyright (c) 2012, 2014, Oracle and/or its affiliates. All rights reserved.
   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


 139     h = CGDisplayModeGetHeight(mode);
 140     w = CGDisplayModeGetWidth(mode);
 141     CFRelease(currentBPP);
 142     static JNF_CLASS_CACHE(jc_DisplayMode, "java/awt/DisplayMode");
 143     static JNF_CTOR_CACHE(jc_DisplayMode_ctor, jc_DisplayMode, "(IIII)V");
 144     ret = JNFNewObject(env, jc_DisplayMode_ctor, w, h, bpp, refrate);
 145     JNF_COCOA_EXIT(env);
 146     return ret;
 147 }
 148 
 149 
 150 /*
 151  * Class:     sun_awt_CGraphicsDevice
 152  * Method:    nativeGetXResolution
 153  * Signature: (I)D
 154  */
 155 JNIEXPORT jdouble JNICALL
 156 Java_sun_awt_CGraphicsDevice_nativeGetXResolution
 157   (JNIEnv *env, jclass class, jint displayID)
 158 {
 159      // CGDisplayScreenSize can return 0 if displayID is invalid

 160     CGSize size = CGDisplayScreenSize(displayID);
 161     CGRect rect = CGDisplayBounds(displayID);
 162     // 1 inch == 25.4 mm
 163     jfloat inches = size.width / 25.4f;
 164     return inches > 0 ? rect.size.width / inches : 72;

 165 }
 166 
 167 /*
 168  * Class:     sun_awt_CGraphicsDevice
 169  * Method:    nativeGetYResolution
 170  * Signature: (I)D
 171  */
 172 JNIEXPORT jdouble JNICALL
 173 Java_sun_awt_CGraphicsDevice_nativeGetYResolution
 174   (JNIEnv *env, jclass class, jint displayID)
 175 {
 176      // CGDisplayScreenSize can return 0 if displayID is invalid

 177     CGSize size = CGDisplayScreenSize(displayID);
 178     CGRect rect = CGDisplayBounds(displayID);
 179     // 1 inch == 25.4 mm
 180     jfloat inches = size.height / 25.4f;
 181     return inches > 0 ? rect.size.height / inches : 72;

 182 }
 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];