< prev index next >

src/java.desktop/macosx/native/libawt_lwawt/awt/CGraphicsEnv.m

Print this page




   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 "AWT_debug.h"
  27 
  28 #import "jni_util.h"

  29 
  30 #import <JavaNativeFoundation/JavaNativeFoundation.h>
  31 
  32 #define MAX_DISPLAYS 64
  33 
  34 /*
  35  * Class:     sun_awt_CGraphicsEnvironment
  36  * Method:    getDisplayIDs
  37  * Signature: ()[I
  38  */
  39 JNIEXPORT jintArray JNICALL
  40 Java_sun_awt_CGraphicsEnvironment_getDisplayIDs
  41 (JNIEnv *env, jclass class)
  42 {
  43     jintArray ret = NULL;
  44 
  45 JNF_COCOA_ENTER(env);
  46 
  47     /* Get the count */
  48     CGDisplayCount displayCount;


  97 /*
  98  * Class:     sun_awt_CGraphicsEnvironment
  99  * Method:    getMainDisplayID
 100  * Signature: ()I
 101  */
 102 JNIEXPORT jint JNICALL
 103 Java_sun_awt_CGraphicsEnvironment_getMainDisplayID
 104 (JNIEnv *env, jclass class)
 105 {
 106     return CGMainDisplayID();
 107 }
 108 
 109 /*
 110  * Post the display reconfiguration event.
 111  */
 112 static void displaycb_handle
 113 (CGDirectDisplayID display, CGDisplayChangeSummaryFlags flags, void *userInfo)
 114 {
 115     if (flags == kCGDisplayBeginConfigurationFlag) return;
 116 


 117     JNFPerformEnvBlock(JNFThreadDetachImmediately, ^(JNIEnv *env) {
 118         JNFWeakJObjectWrapper *wrapper = (JNFWeakJObjectWrapper *)userInfo;
 119 
 120         jobject graphicsEnv = [wrapper jObjectWithEnv:env];
 121         if (graphicsEnv == NULL) return; // ref already GC'd
 122         static JNF_CLASS_CACHE(jc_CGraphicsEnvironment, "sun/awt/CGraphicsEnvironment");
 123         static JNF_MEMBER_CACHE(jm_displayReconfiguration, jc_CGraphicsEnvironment, "_displayReconfiguration", "(IZ)V");

 124         JNFCallVoidMethod(env, graphicsEnv, jm_displayReconfiguration,
 125                             (jint) display, 
 126                             (jboolean) flags & kCGDisplayRemoveFlag);
 127     });

 128 }
 129 
 130 /*
 131  * Class:     sun_awt_CGraphicsEnvironment
 132  * Method:    registerDisplayReconfiguration
 133  * Signature: ()J
 134  */
 135 JNIEXPORT jlong JNICALL
 136 Java_sun_awt_CGraphicsEnvironment_registerDisplayReconfiguration
 137 (JNIEnv *env, jobject this)
 138 {
 139     jlong ret = 0L;
 140 
 141 JNF_COCOA_ENTER(env);
 142 
 143     JNFWeakJObjectWrapper *wrapper = [[JNFWeakJObjectWrapper wrapperWithJObject:this withEnv:env] retain];
 144 
 145     /* Register the callback */
 146     if (CGDisplayRegisterReconfigurationCallback(&displaycb_handle, wrapper) != kCGErrorSuccess) {
 147         [JNFException raise:env




   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 "AWT_debug.h"
  27 
  28 #import "jni_util.h"
  29 #import "ThreadUtilities.h"
  30 
  31 #import <JavaNativeFoundation/JavaNativeFoundation.h>
  32 
  33 #define MAX_DISPLAYS 64
  34 
  35 /*
  36  * Class:     sun_awt_CGraphicsEnvironment
  37  * Method:    getDisplayIDs
  38  * Signature: ()[I
  39  */
  40 JNIEXPORT jintArray JNICALL
  41 Java_sun_awt_CGraphicsEnvironment_getDisplayIDs
  42 (JNIEnv *env, jclass class)
  43 {
  44     jintArray ret = NULL;
  45 
  46 JNF_COCOA_ENTER(env);
  47 
  48     /* Get the count */
  49     CGDisplayCount displayCount;


  98 /*
  99  * Class:     sun_awt_CGraphicsEnvironment
 100  * Method:    getMainDisplayID
 101  * Signature: ()I
 102  */
 103 JNIEXPORT jint JNICALL
 104 Java_sun_awt_CGraphicsEnvironment_getMainDisplayID
 105 (JNIEnv *env, jclass class)
 106 {
 107     return CGMainDisplayID();
 108 }
 109 
 110 /*
 111  * Post the display reconfiguration event.
 112  */
 113 static void displaycb_handle
 114 (CGDirectDisplayID display, CGDisplayChangeSummaryFlags flags, void *userInfo)
 115 {
 116     if (flags == kCGDisplayBeginConfigurationFlag) return;
 117 
 118     [ThreadUtilities performOnMainThreadWaiting:NO block:^() {
 119 
 120         JNFPerformEnvBlock(JNFThreadDetachImmediately, ^(JNIEnv *env) {
 121             JNFWeakJObjectWrapper *wrapper = (JNFWeakJObjectWrapper *)userInfo;
 122 
 123             jobject graphicsEnv = [wrapper jObjectWithEnv:env];
 124             if (graphicsEnv == NULL) return; // ref already GC'd
 125             static JNF_CLASS_CACHE(jc_CGraphicsEnvironment, "sun/awt/CGraphicsEnvironment");
 126             static JNF_MEMBER_CACHE(jm_displayReconfiguration,
 127                     jc_CGraphicsEnvironment, "_displayReconfiguration","(IZ)V");
 128             JNFCallVoidMethod(env, graphicsEnv, jm_displayReconfiguration,
 129                     (jint) display, (jboolean) flags & kCGDisplayRemoveFlag);

 130         });
 131     }];
 132 }
 133 
 134 /*
 135  * Class:     sun_awt_CGraphicsEnvironment
 136  * Method:    registerDisplayReconfiguration
 137  * Signature: ()J
 138  */
 139 JNIEXPORT jlong JNICALL
 140 Java_sun_awt_CGraphicsEnvironment_registerDisplayReconfiguration
 141 (JNIEnv *env, jobject this)
 142 {
 143     jlong ret = 0L;
 144 
 145 JNF_COCOA_ENTER(env);
 146 
 147     JNFWeakJObjectWrapper *wrapper = [[JNFWeakJObjectWrapper wrapperWithJObject:this withEnv:env] retain];
 148 
 149     /* Register the callback */
 150     if (CGDisplayRegisterReconfigurationCallback(&displaycb_handle, wrapper) != kCGErrorSuccess) {
 151         [JNFException raise:env


< prev index next >