7124417: [macosx] failure in Window.initGC on Mac with monitor sleeping
authorserb
Fri, 21 Mar 2014 15:09:49 +0400
changeset 23684 7a91a5f90266
parent 23683 2d5bf8043a38
child 23685 3a2788a3f2ee
7124417: [macosx] failure in Window.initGC on Mac with monitor sleeping Reviewed-by: anthony, pchelko
jdk/src/macosx/native/sun/awt/CGraphicsEnv.m
--- a/jdk/src/macosx/native/sun/awt/CGraphicsEnv.m	Thu Mar 20 19:59:58 2014 +0400
+++ b/jdk/src/macosx/native/sun/awt/CGraphicsEnv.m	Fri Mar 21 15:09:49 2014 +0400
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2011, 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
@@ -25,6 +25,7 @@
 
 #import <JavaNativeFoundation/JavaNativeFoundation.h>
 
+#import "jni_util.h"
 #import "LWCToolkit.h"
 #import "AWT_debug.h"
 
@@ -64,7 +65,7 @@
 
     /* Get the count */
     CGDisplayCount displayCount;
-    if (CGGetActiveDisplayList(MAX_DISPLAYS, NULL, &displayCount) != kCGErrorSuccess) {
+    if (CGGetOnlineDisplayList(MAX_DISPLAYS, NULL, &displayCount) != kCGErrorSuccess) {
         [JNFException raise:env
                          as:kInternalError
                      reason:"CGGetOnlineDisplayList() failed to get display count"];
@@ -73,23 +74,36 @@
 
     /* Allocate an array and get the size list of display Ids */
     CGDirectDisplayID displays[MAX_DISPLAYS];
-    if (CGGetActiveDisplayList(displayCount, displays, &displayCount) != kCGErrorSuccess) {
+    if (CGGetOnlineDisplayList(displayCount, displays, &displayCount) != kCGErrorSuccess) {
         [JNFException raise:env
                          as:kInternalError
                      reason:"CGGetOnlineDisplayList() failed to get display list"];
         return NULL;
     }
 
+    CGDisplayCount i;
+    CGDisplayCount displayActiveCount = 0; //Active and sleeping.
+    for (i = 0; i < displayCount; ++i) {
+        if (CGDisplayMirrorsDisplay(displays[i]) == kCGNullDirectDisplay) {
+            ++displayActiveCount;
+        } else {
+            displays[i] = kCGNullDirectDisplay;
+        }
+    }
+
     /* Allocate a java array for display identifiers */
-    ret = JNFNewIntArray(env, displayCount);
+    ret = JNFNewIntArray(env, displayActiveCount);
 
     /* Initialize and return the backing int array */
     assert(sizeof(jint) >= sizeof(CGDirectDisplayID));
     jint *elems = (*env)->GetIntArrayElements(env, ret, 0);
+    CHECK_NULL_RETURN(elems, NULL);
 
-    CGDisplayCount i;
-    for (i = 0; i < displayCount; i++) {
-        elems[i] = displays[i];
+    /* Filter out the mirrored displays */
+    for (i = 0; i < displayCount; ++i) {
+        if (displays[i] != kCGNullDirectDisplay) {
+            elems[--displayActiveCount] = displays[i];
+        }
     }
 
     (*env)->ReleaseIntArrayElements(env, ret, elems, 0);