Print this page
Added gradle and cmake project


   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 
  30 #import <JavaNativeFoundation/JavaNativeFoundation.h>
  31 
  32 /**
  33  * Some default values for invalid CoreGraphics display ID.
  34  */
  35 #define DEFAULT_DEVICE_WIDTH 1024
  36 #define DEFAULT_DEVICE_HEIGHT 768
  37 #define DEFAULT_DEVICE_DPI 72
  38 
  39 /*
  40  * Convert the mode string to the more convinient 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     }


 367 
 368 JNF_COCOA_ENTER(env);
 369 
 370     [ThreadUtilities performOnMainThreadWaiting:YES block:^(){
 371         NSArray *screens = [NSScreen screens];
 372         for (NSScreen *screen in screens) {
 373             NSDictionary *screenInfo = [screen deviceDescription];
 374             NSNumber *screenID = [screenInfo objectForKey:@"NSScreenNumber"];
 375             if ([screenID unsignedIntValue] == displayID){
 376                 if ([screen respondsToSelector:@selector(backingScaleFactor)]) {
 377                     ret = [screen backingScaleFactor];
 378                 }
 379                 break;
 380             }
 381         }
 382     }];
 383 
 384 JNF_COCOA_EXIT(env);
 385     return ret;
 386 }






















   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 #import <Metal/Metal.h>
  30 #import <MetalKit/MetalKit.h>
  31 
  32 #import <JavaNativeFoundation/JavaNativeFoundation.h>
  33 
  34 /**
  35  * Some default values for invalid CoreGraphics display ID.
  36  */
  37 #define DEFAULT_DEVICE_WIDTH 1024
  38 #define DEFAULT_DEVICE_HEIGHT 768
  39 #define DEFAULT_DEVICE_DPI 72
  40 
  41 /*
  42  * Convert the mode string to the more convinient bits per pixel value
  43  */
  44 static int getBPPFromModeString(CFStringRef mode)
  45 {
  46     if ((CFStringCompare(mode, CFSTR(kIO30BitDirectPixels), kCFCompareCaseInsensitive) == kCFCompareEqualTo)) {
  47         // This is a strange mode, where we using 10 bits per RGB component and pack it into 32 bits
  48         // Java is not ready to work with this mode but we have to specify it as supported
  49         return 30;
  50     }


 369 
 370 JNF_COCOA_ENTER(env);
 371 
 372     [ThreadUtilities performOnMainThreadWaiting:YES block:^(){
 373         NSArray *screens = [NSScreen screens];
 374         for (NSScreen *screen in screens) {
 375             NSDictionary *screenInfo = [screen deviceDescription];
 376             NSNumber *screenID = [screenInfo objectForKey:@"NSScreenNumber"];
 377             if ([screenID unsignedIntValue] == displayID){
 378                 if ([screen respondsToSelector:@selector(backingScaleFactor)]) {
 379                     ret = [screen backingScaleFactor];
 380                 }
 381                 break;
 382             }
 383         }
 384     }];
 385 
 386 JNF_COCOA_EXIT(env);
 387     return ret;
 388 }
 389 
 390 /*
 391  * Class:     sun_awt_CGraphicsDevice
 392  * Method:    nativeGetMetalDeviceName
 393  * Signature: (I)Ljava/lang/String;
 394  */
 395 JNIEXPORT jstring JNICALL Java_sun_awt_CGraphicsDevice_nativeGetMetalDeviceName
 396   (JNIEnv *env, jclass class, jint displayID)
 397 {
 398 
 399     id<MTLDevice> device = CGDirectDisplayCopyCurrentMetalDevice(displayID);
 400     if (!device) return NULL;
 401     NSString* name = [device name];
 402     UniChar *chars = malloc(name.length * sizeof(UniChar));
 403     if (!chars) return NULL;
 404     [name getCharacters:chars range:NSMakeRange(0,name.length)];
 405     jstring javaString = (*env)->NewString(env, chars, name.length);
 406     free(chars);
 407     return javaString;
 408 }