< prev index next >

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

Print this page

  1 /*
  2  * Copyright (c) 2012, 2019, 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
 23  * questions.
 24  */
 25 
 26 #import "LWCToolkit.h"
 27 #import "ThreadUtilities.h"
 28 #include "GeomUtilities.h"
 29 #include "JNIUtilities.h"
 30 
 31 /**
 32  * Some default values for invalid CoreGraphics display ID.
 33  */
 34 #define DEFAULT_DEVICE_WIDTH 1024
 35 #define DEFAULT_DEVICE_HEIGHT 768
 36 #define DEFAULT_DEVICE_DPI 72
 37 

 38 /*
 39  * Convert the mode string to the more convenient bits per pixel value
 40  */
 41 static int getBPPFromModeString(CFStringRef mode)
 42 {
 43     if ((CFStringCompare(mode, CFSTR(kIO30BitDirectPixels), kCFCompareCaseInsensitive) == kCFCompareEqualTo)) {
 44         // This is a strange mode, where we using 10 bits per RGB component and pack it into 32 bits
 45         // Java is not ready to work with this mode but we have to specify it as supported
 46         return 30;
 47     }
 48     else if (CFStringCompare(mode, CFSTR(IO32BitDirectPixels), kCFCompareCaseInsensitive) == kCFCompareEqualTo) {
 49         return 32;
 50     }
 51     else if (CFStringCompare(mode, CFSTR(IO16BitDirectPixels), kCFCompareCaseInsensitive) == kCFCompareEqualTo) {
 52         return 16;
 53     }
 54     else if (CFStringCompare(mode, CFSTR(IO8BitIndexedPixels), kCFCompareCaseInsensitive) == kCFCompareEqualTo) {
 55         return 8;
 56     }
 57 
 58     return 0;
 59 }
 60 
 61 static BOOL isValidDisplayMode(CGDisplayModeRef mode){










 62     return (1 < CGDisplayModeGetWidth(mode) && 1 < CGDisplayModeGetHeight(mode));
 63 }
 64 
 65 static CFMutableArrayRef getAllValidDisplayModes(jint displayID){
 66     // CGDisplayCopyAllDisplayModes can return NULL if displayID is invalid
 67     CFArrayRef allModes = CGDisplayCopyAllDisplayModes(displayID, NULL);
 68     CFMutableArrayRef validModes = nil;
 69     if (allModes) {
 70         CFIndex numModes = CFArrayGetCount(allModes);
 71         validModes = CFArrayCreateMutable(kCFAllocatorDefault, numModes + 1, &kCFTypeArrayCallBacks);
 72 
 73         CFIndex n;
 74         for (n=0; n < numModes; n++) {
 75             CGDisplayModeRef cRef = (CGDisplayModeRef) CFArrayGetValueAtIndex(allModes, n);
 76             if (cRef != NULL && isValidDisplayMode(cRef)) {
 77                 CFArrayAppendValue(validModes, cRef);
 78             }
 79         }
 80         CFRelease(allModes);
 81 

  1 /*
  2  * Copyright (c) 2012, 2023, 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
 23  * questions.
 24  */
 25 
 26 #import "LWCToolkit.h"
 27 #import "ThreadUtilities.h"
 28 #include "GeomUtilities.h"
 29 #include "JNIUtilities.h"
 30 
 31 /**
 32  * Some default values for invalid CoreGraphics display ID.
 33  */
 34 #define DEFAULT_DEVICE_WIDTH 1024
 35 #define DEFAULT_DEVICE_HEIGHT 768
 36 #define DEFAULT_DEVICE_DPI 72
 37 
 38 static NSInteger architecture = -1;
 39 /*
 40  * Convert the mode string to the more convenient bits per pixel value
 41  */
 42 static int getBPPFromModeString(CFStringRef mode)
 43 {
 44     if ((CFStringCompare(mode, CFSTR(kIO30BitDirectPixels), kCFCompareCaseInsensitive) == kCFCompareEqualTo)) {
 45         // This is a strange mode, where we using 10 bits per RGB component and pack it into 32 bits
 46         // Java is not ready to work with this mode but we have to specify it as supported
 47         return 30;
 48     }
 49     else if (CFStringCompare(mode, CFSTR(IO32BitDirectPixels), kCFCompareCaseInsensitive) == kCFCompareEqualTo) {
 50         return 32;
 51     }
 52     else if (CFStringCompare(mode, CFSTR(IO16BitDirectPixels), kCFCompareCaseInsensitive) == kCFCompareEqualTo) {
 53         return 16;
 54     }
 55     else if (CFStringCompare(mode, CFSTR(IO8BitIndexedPixels), kCFCompareCaseInsensitive) == kCFCompareEqualTo) {
 56         return 8;
 57     }
 58 
 59     return 0;
 60 }
 61 
 62 static BOOL isValidDisplayMode(CGDisplayModeRef mode) {
 63     // Workaround for apple bug FB13261205, since it only affects arm based macs
 64     // and arm support started with macOS 11 ignore the workaround for previous versions
 65     if (@available(macOS 11, *)) {
 66         if (architecture == -1) {
 67             architecture = [[NSRunningApplication currentApplication] executableArchitecture];
 68         }
 69         if (architecture == NSBundleExecutableArchitectureARM64) {
 70             return (CGDisplayModeGetPixelWidth(mode) >= 800);
 71         }
 72     }
 73     return (1 < CGDisplayModeGetWidth(mode) && 1 < CGDisplayModeGetHeight(mode));
 74 }
 75 
 76 static CFMutableArrayRef getAllValidDisplayModes(jint displayID){
 77     // CGDisplayCopyAllDisplayModes can return NULL if displayID is invalid
 78     CFArrayRef allModes = CGDisplayCopyAllDisplayModes(displayID, NULL);
 79     CFMutableArrayRef validModes = nil;
 80     if (allModes) {
 81         CFIndex numModes = CFArrayGetCount(allModes);
 82         validModes = CFArrayCreateMutable(kCFAllocatorDefault, numModes + 1, &kCFTypeArrayCallBacks);
 83 
 84         CFIndex n;
 85         for (n=0; n < numModes; n++) {
 86             CGDisplayModeRef cRef = (CGDisplayModeRef) CFArrayGetValueAtIndex(allModes, n);
 87             if (cRef != NULL && isValidDisplayMode(cRef)) {
 88                 CFArrayAppendValue(validModes, cRef);
 89             }
 90         }
 91         CFRelease(allModes);
 92 
< prev index next >