1 /*
   2  * Copyright (c) 2011, 2014, 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 <jni.h>
  27 #import <pthread.h>
  28 #import <QuartzCore/CVDisplayLink.h>
  29 #import "GlassStatics.h"
  30 #import "GlassMacros.h"
  31 
  32 pthread_key_t GlassThreadDataKey = 0;
  33 
  34 CVDisplayLinkRef GlassDisplayLink = NULL;
  35 
  36 JavaVM *jVM = NULL;
  37 JNIEnv *jEnv = NULL;
  38 
  39 jclass jApplicationClass = NULL;
  40 jclass jWindowClass = NULL;
  41 jclass jViewClass = NULL;
  42 
  43 jclass jScreenClass = NULL;
  44 jclass jMenuBarDelegateClass = NULL;
  45 jclass jIntegerClass = NULL;
  46 jclass jLongClass = NULL;
  47 jclass jMapClass = NULL;
  48 jclass jBooleanClass = NULL;
  49 
  50 jmethodID jRunnableRun = NULL;
  51 
  52 jmethodID jWindowNotifyMove = NULL;
  53 jmethodID jWindowNotifyResize = NULL;
  54 jmethodID jWindowNotifyClose = NULL;
  55 jmethodID jWindowNotifyMoveToAnotherScreen = NULL;
  56 jmethodID jWindowNotifyScaleChanged = NULL;
  57 jmethodID jWindowNotifyFocus = NULL;
  58 jmethodID jWindowNotifyFocusUngrab = NULL;
  59 jmethodID jWindowNotifyFocusDisabled = NULL;
  60 jmethodID jWindowNotifyDestroy = NULL;
  61 jmethodID jWindowNotifyDelegatePtr = NULL;
  62 
  63 jmethodID jViewNotifyEvent = NULL;
  64 jmethodID jViewNotifyRepaint = NULL;
  65 jmethodID jViewNotifyResize = NULL;
  66 jmethodID jViewNotifyKey = NULL;
  67 jmethodID jViewNotifyMouse = NULL;
  68 jmethodID jViewNotifyMenu = NULL;
  69 jmethodID jViewNotifyInputMethod = NULL;
  70 jmethodID jViewNotifyInputMethodMac = NULL;
  71 jmethodID jViewNotifyInputMethodCandidatePosRequest = NULL;
  72 jmethodID jViewNotifyDragEnter = NULL;
  73 jmethodID jViewNotifyDragOver = NULL;
  74 jmethodID jViewNotifyDragLeave  = NULL;
  75 jmethodID jViewNotifyDragDrop = NULL;
  76 jmethodID jViewNotifyDragEnd = NULL;
  77 jmethodID jViewGetAccessible = NULL;
  78 
  79 jmethodID jScreenNotifySettingsChanged = NULL;
  80 
  81 jmethodID jMapGetMethod = NULL;
  82 jmethodID jBooleanValueMethod = NULL;
  83 jmethodID jIntegerInitMethod = NULL;
  84 jmethodID jIntegerValueMethod = NULL;
  85 jmethodID jLongValueMethod = NULL;
  86 
  87 jmethodID jSizeInit = NULL;
  88 
  89 jmethodID jPixelsAttachData = NULL;
  90 
  91 JavaIDs javaIDs;
  92 
  93 void initJavaIDsList(JNIEnv* env)
  94 {
  95     if (!javaIDs.List.add) {
  96         jclass jcls = (*env)->FindClass(env, "java/util/List");
  97         GLASS_CHECK_EXCEPTION(env);
  98         if (jcls) {
  99             javaIDs.List.add = (*env)->GetMethodID(env, jcls, "add", "(Ljava/lang/Object;)Z");
 100             GLASS_CHECK_EXCEPTION(env);
 101         }
 102     }
 103 }
 104 
 105 void initJavaIDsArrayList(JNIEnv* env)
 106 {
 107     if (!javaIDs.ArrayList.init) {
 108         jclass jcls = (*env)->FindClass(env, "java/util/ArrayList");
 109         GLASS_CHECK_EXCEPTION(env);
 110         if (jcls) {
 111             javaIDs.ArrayList.init = (*env)->GetMethodID(env, jcls, "<init>", "()V");
 112             GLASS_CHECK_EXCEPTION(env);
 113         }
 114     }
 115 }
 116 
 117 void initJavaIDsFile(JNIEnv* env)
 118 {
 119     if (!javaIDs.File.init) {
 120         jclass jcls = (*env)->FindClass(env, "java/io/File");
 121         GLASS_CHECK_EXCEPTION(env);
 122         if (jcls) {
 123             javaIDs.File.init = (*env)->GetMethodID(env, jcls, "<init>", "(Ljava/lang/String;)V");
 124             GLASS_CHECK_EXCEPTION(env);
 125         }
 126     }
 127 }
 128