1 /*
   2  * Copyright (c) 2010, 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
  23  * questions.
  24  */
  25 
  26 #import <UIKit/UIKit.h>
  27 #import <QuartzCore/QuartzCore.h>
  28 
  29 #import "common.h"
  30 #import "GlassMacros.h"
  31 #import "GlassScreen.h"
  32 #import "GlassStatics.h"
  33 #import "GlassTimer.h"
  34 
  35 static inline jobject createJavaScreen(JNIEnv *env, UIScreen* screen)
  36 {
  37     jmethodID screenInit = (*env)->GetMethodID(env, mat_jScreenClass,
  38                                                    "<init>",
  39                                                    "(JIIIIIIIIIIIF)V");
  40 
  41     return (jobject)(*env)->NewObject(env, mat_jScreenClass, screenInit,
  42                                       ptr_to_jlong(screen),
  43 
  44                                       32,
  45 
  46                                       (jint)[screen bounds].origin.x,
  47                                       (jint)[screen bounds].origin.y,
  48                                       (jint)[screen bounds].size.width,
  49                                       (jint)[screen bounds].size.height,
  50 
  51                                       (jint)[screen applicationFrame].origin.x,
  52                                       (jint)[screen applicationFrame].origin.y,
  53                                       (jint)[screen applicationFrame].size.width,
  54                                       (jint)[screen applicationFrame].size.height,
  55 
  56 
  57                                       (jint)[screen currentMode].size.width,
  58                                       (jint)[screen currentMode].size.height,
  59                                       (jfloat)[screen scale]);
  60 
  61 }
  62 
  63 void GlassScreenDidChangeScreenParameters(JNIEnv *env)
  64 {
  65     jmethodID jScreenNotifySettingsChanged = (*env)->GetStaticMethodID(env, mat_jScreenClass, "notifySettingsChanged", "()V");
  66 
  67     (*env)->CallStaticVoidMethod(env, mat_jScreenClass, jScreenNotifySettingsChanged);
  68 }
  69 
  70 jobjectArray createJavaScreens(JNIEnv* env) {
  71     NSArray* screens = [UIScreen screens];
  72 
  73     if (mat_jScreenClass == NULL)
  74     {
  75         mat_jScreenClass = (*env)->NewGlobalRef(env, (*env)->FindClass(env, "com/sun/glass/ui/Screen"));
  76     }
  77 
  78     jobjectArray screenArray = (*env)->NewObjectArray(env,
  79                                                       [screens count],
  80                                                       mat_jScreenClass,
  81                                                       NULL);
  82 
  83     for (NSUInteger index = 0; index < [screens count]; index++) {
  84         jobject javaScreen = createJavaScreen(env, [screens objectAtIndex:index]);
  85         (*env)->SetObjectArrayElement(env, screenArray, index, javaScreen);
  86     }
  87 
  88     return screenArray;
  89 }
  90 
  91