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 "common.h"
  27 #import "com_sun_glass_ui_View.h"
  28 #import "com_sun_glass_ui_mac_MacView.h"
  29 #import "com_sun_glass_ui_View_Capability.h"
  30 #import "com_sun_glass_ui_Clipboard.h"
  31 #import "com_sun_glass_events_ViewEvent.h"
  32 
  33 #import "GlassMacros.h"
  34 #import "GlassWindow.h"
  35 #import "GlassView3D.h"
  36 #import "GlassHelper.h"
  37 
  38 //#define VERBOSE
  39 #ifndef VERBOSE
  40     #define LOG(MSG, ...)
  41 #else
  42     #define LOG(MSG, ...) GLASS_LOG(MSG, ## __VA_ARGS__);
  43 #endif
  44 
  45 //#define FORCE_NOISE
  46 #ifdef FORCE_NOISE
  47 static inline void *_GenerateNoise(int width, int height)
  48 {
  49     static int *pixels = NULL;
  50     pixels = realloc(pixels, width*height*4);
  51     
  52     int *src = pixels;
  53     for (int i=0; i<width*height; i++)
  54     {
  55         *src++ = random();
  56     }
  57     
  58     return (void*)pixels;
  59 }
  60 #endif
  61 
  62 static inline NSView<GlassView>* getGlassView(JNIEnv *env, jlong jPtr)
  63 {
  64     assert(jPtr != 0L);
  65 
  66     return (NSView<GlassView>*)jlong_to_ptr(jPtr);
  67 }
  68 
  69 #pragma mark --- JNI
  70 
  71 /*
  72  * Class:     com_sun_glass_ui_mac_MacView
  73  * Method:    _initIDs
  74  * Signature: ()V
  75  */
  76 JNIEXPORT void JNICALL Java_com_sun_glass_ui_mac_MacView__1initIDs
  77 (JNIEnv *env, jclass jClass)
  78 {
  79     LOG("Java_com_sun_glass_ui_mac_MacView__1initIDs");
  80     
  81     if (jViewClass == NULL)
  82     {
  83         jViewClass = (*env)->NewGlobalRef(env, jClass);
  84     }
  85     
  86     if (jIntegerClass == NULL)
  87     {
  88         jclass jcls = (*env)->FindClass(env, "java/lang/Integer");
  89         if ((*env)->ExceptionCheck(env)) return;
  90         jIntegerClass = (*env)->NewGlobalRef(env, jcls);
  91     }
  92     
  93     if (jMapClass == NULL)
  94     {
  95         jclass jcls = (*env)->FindClass(env, "java/util/Map");
  96         if ((*env)->ExceptionCheck(env)) return;
  97         jMapClass = (*env)->NewGlobalRef(env, jcls);
  98     }
  99     
 100     if (jBooleanClass == NULL)
 101     {
 102         jclass jcls = (*env)->FindClass(env, "java/lang/Boolean");
 103         if ((*env)->ExceptionCheck(env)) return;
 104         jBooleanClass = (*env)->NewGlobalRef(env, jcls);
 105     }
 106     
 107     if (jViewNotifyEvent == NULL)
 108     {
 109         jViewNotifyEvent = (*env)->GetMethodID(env, jViewClass, "notifyView", "(I)V");
 110         if ((*env)->ExceptionCheck(env)) return;
 111     }
 112     
 113     if (jViewNotifyRepaint == NULL)
 114     {
 115         jViewNotifyRepaint = (*env)->GetMethodID(env, jViewClass, "notifyRepaint", "(IIII)V");
 116         if ((*env)->ExceptionCheck(env)) return;
 117     }
 118     
 119     if (jViewNotifyResize == NULL)
 120     {
 121         jViewNotifyResize = (*env)->GetMethodID(env, jViewClass, "notifyResize", "(II)V");
 122         if ((*env)->ExceptionCheck(env)) return;
 123     }
 124     
 125     if (jViewNotifyKey == NULL)
 126     {
 127         jViewNotifyKey = (*env)->GetMethodID(env, jViewClass, "notifyKey", "(II[CI)V");
 128         if ((*env)->ExceptionCheck(env)) return;
 129     }
 130     
 131     if (jViewNotifyMenu == NULL)
 132     {
 133         jViewNotifyMenu = (*env)->GetMethodID(env, jViewClass, "notifyMenu", "(IIIIZ)V");
 134         if ((*env)->ExceptionCheck(env)) return;
 135     }
 136     
 137     if (jViewNotifyMouse == NULL)
 138     {
 139         jViewNotifyMouse = (*env)->GetMethodID(env, jViewClass, "notifyMouse", "(IIIIIIIZZ)V");
 140         if ((*env)->ExceptionCheck(env)) return;
 141     }
 142     
 143     if (jViewNotifyInputMethod == NULL)
 144     {
 145         jViewNotifyInputMethod = (*env)->GetMethodID(env, jViewClass, "notifyInputMethod", "(Ljava/lang/String;[I[I[BIII)V");
 146         if ((*env)->ExceptionCheck(env)) return;
 147     }
 148     
 149     if (jViewNotifyInputMethodMac == NULL)
 150     {
 151         jclass jMacViewClass = [GlassHelper ClassForName:"com.sun.glass.ui.mac.MacView" withEnv:env];
 152         jViewNotifyInputMethodMac = (*env)->GetMethodID(env, jMacViewClass, "notifyInputMethodMac", "(Ljava/lang/String;IIIII)V");
 153         if ((*env)->ExceptionCheck(env)) return;
 154     }
 155     
 156     if(jViewNotifyInputMethodCandidatePosRequest == NULL)
 157     {
 158         jViewNotifyInputMethodCandidatePosRequest = (*env)->GetMethodID(env, jViewClass, "notifyInputMethodCandidatePosRequest", "(I)[D");
 159         if ((*env)->ExceptionCheck(env)) return;
 160     }
 161     
 162     if (jViewNotifyDragEnter == NULL)
 163     {
 164         jViewNotifyDragEnter = (*env)->GetMethodID(env, jViewClass, "notifyDragEnter", "(IIIII)I");
 165         if ((*env)->ExceptionCheck(env)) return;
 166     }
 167     
 168     if (jViewNotifyDragOver == NULL)
 169     {
 170         jViewNotifyDragOver = (*env)->GetMethodID(env, jViewClass, "notifyDragOver", "(IIIII)I");
 171         if ((*env)->ExceptionCheck(env)) return;
 172     }
 173     
 174     if (jViewNotifyDragLeave == NULL)
 175     {
 176         jViewNotifyDragLeave = (*env)->GetMethodID(env, jViewClass, "notifyDragLeave", "()V");
 177         if ((*env)->ExceptionCheck(env)) return;
 178     }
 179     
 180     if (jViewNotifyDragDrop == NULL)
 181     {
 182         jViewNotifyDragDrop = (*env)->GetMethodID(env, jViewClass, "notifyDragDrop", "(IIIII)I");
 183         if ((*env)->ExceptionCheck(env)) return;
 184     }
 185     
 186     if (jViewNotifyDragEnd == NULL)
 187     {
 188         jViewNotifyDragEnd = (*env)->GetMethodID(env, jViewClass, "notifyDragEnd", "(I)V");
 189         if ((*env)->ExceptionCheck(env)) return;
 190     }
 191 
 192     if (jViewGetAccessible == NULL)
 193     {
 194         jViewGetAccessible = (*env)->GetMethodID(env, jViewClass, "getAccessible", "()J");
 195         if ((*env)->ExceptionCheck(env)) return;
 196     }
 197     
 198     if (jMapGetMethod == NULL)
 199     {
 200         jMapGetMethod = (*env)->GetMethodID(env, jMapClass, "get", "(Ljava/lang/Object;)Ljava/lang/Object;");
 201         if ((*env)->ExceptionCheck(env)) return;
 202     }
 203     
 204     if (jBooleanValueMethod == NULL)
 205     {
 206         jBooleanValueMethod = (*env)->GetMethodID(env, jBooleanClass, "booleanValue", "()Z");
 207         if ((*env)->ExceptionCheck(env)) return;
 208     }
 209     
 210     if (jIntegerInitMethod == NULL)
 211     {
 212         jIntegerInitMethod = (*env)->GetMethodID(env, jIntegerClass, "<init>", "(I)V");
 213         if ((*env)->ExceptionCheck(env)) return;
 214     }
 215     
 216     if (jIntegerValueMethod == NULL)
 217     {
 218         jIntegerValueMethod = (*env)->GetMethodID(env, jIntegerClass, "intValue", "()I");
 219         if ((*env)->ExceptionCheck(env)) return;
 220     }
 221         
 222     if (jLongClass == NULL)
 223     {
 224         jclass jcls = (*env)->FindClass(env, "java/lang/Long");
 225         if ((*env)->ExceptionCheck(env)) return;
 226         jLongClass = (*env)->NewGlobalRef(env, jcls);
 227     }
 228     
 229     if (jLongValueMethod == NULL)
 230     {
 231         jLongValueMethod = (*env)->GetMethodID(env, jLongClass, "longValue", "()J");
 232     }
 233 }
 234 
 235 /*
 236  * Class:     com_sun_glass_ui_mac_MacView
 237  * Method:    _getMultiClickTime_impl
 238  * Signature: ()J
 239  */
 240 JNIEXPORT jlong JNICALL Java_com_sun_glass_ui_mac_MacView__1getMultiClickTime_1impl
 241 (JNIEnv *env, jclass cls)
 242 {
 243     LOG("Java_com_sun_glass_ui_mac_MacView__1getMultiClickTime_1impl");
 244     
 245     GLASS_ASSERT_MAIN_JAVA_THREAD(env);
 246     
 247     // 10.6 API
 248     return (jlong)([NSEvent doubleClickInterval]*1000.0f);
 249 }
 250 
 251 /*
 252  * Class:     com_sun_glass_ui_mac_MacView
 253  * Method:    _getMultiClickMaxX_impl
 254  * Signature: ()I
 255  */
 256 JNIEXPORT jint JNICALL Java_com_sun_glass_ui_mac_MacView__1getMultiClickMaxX_1impl
 257 (JNIEnv *env, jclass cls)
 258 {
 259     LOG("Java_com_sun_glass_ui_mac_MacView__1getMultiClickMaxX_1impl");
 260     
 261     GLASS_ASSERT_MAIN_JAVA_THREAD(env);
 262     
 263     // gznote: there is no way to get this value out of the system
 264     // Most of the Mac machines use the value 3, so we hardcode this value
 265     return (jint)3;
 266 }
 267 
 268 /*
 269  * Class:     com_sun_glass_ui_mac_MacView
 270  * Method:    _getMultiClickMaxY_impl
 271  * Signature: ()I
 272  */
 273 JNIEXPORT jint JNICALL Java_com_sun_glass_ui_mac_MacView__1getMultiClickMaxY_1impl
 274 (JNIEnv *env, jclass cls)
 275 {
 276     LOG("Java_com_sun_glass_ui_mac_MacView__1getMultiClickMaxY_1impl");
 277     
 278     GLASS_ASSERT_MAIN_JAVA_THREAD(env);
 279     
 280     // gznote: there is no way to get this value out of the system
 281     // Most of the Mac machines use the value 3, so we hardcode this value
 282     return (jint)3;
 283 }
 284 
 285 /*
 286  * Class:     com_sun_glass_ui_mac_MacView
 287  * Method:    _create
 288  * Signature: (Ljava/util/Map;)J
 289  */
 290 JNIEXPORT jlong JNICALL Java_com_sun_glass_ui_mac_MacView__1create
 291 (JNIEnv *env, jobject jView, jobject jCapabilities)
 292 {
 293     LOG("Java_com_sun_glass_ui_mac_MacView__1create");
 294     
 295     jlong value = 0L;
 296     
 297     GLASS_ASSERT_MAIN_JAVA_THREAD(env);
 298     GLASS_POOL_ENTER;
 299     {
 300         jobject jViewRef = (*env)->NewGlobalRef(env, jView);
 301         jobject jCapabilitiesRef = NULL;
 302         if (jCapabilities != NULL)
 303         {
 304             jCapabilitiesRef = (*env)->NewGlobalRef(env, jCapabilities);
 305         }
 306 
 307         // embed ourselves into GlassHostView, so we can later swap our view between windows (ex. fullscreen mode)
 308         NSView *hostView = [[GlassHostView alloc] initWithFrame:NSMakeRect(0, 0, 0, 0)]; // alloc creates ref count of 1
 309         [hostView setAutoresizingMask:(NSViewWidthSizable|NSViewHeightSizable)];
 310         [hostView setAutoresizesSubviews:YES];
 311         
 312         NSView* view = [[GlassView3D alloc] initWithFrame:[hostView bounds] withJview:jView withJproperties:jCapabilities];
 313         [view setAutoresizingMask:(NSViewWidthSizable|NSViewHeightSizable)];
 314         
 315         [hostView addSubview:view];
 316         jfieldID jfID = (*env)->GetFieldID(env, jViewClass, "ptr", "J");
 317         GLASS_CHECK_EXCEPTION(env);
 318         (*env)->SetLongField(env, jView, jfID, ptr_to_jlong(view));
 319         
 320         value = ptr_to_jlong(view);
 321 
 322         if (jCapabilities != NULL)
 323         {
 324             (*env)->DeleteGlobalRef(env, jCapabilitiesRef);
 325         }
 326         (*env)->DeleteGlobalRef(env, jViewRef);
 327     }
 328     GLASS_POOL_EXIT;
 329     GLASS_CHECK_EXCEPTION(env);
 330     
 331     LOG("   view: %p", value);
 332     return value;
 333 }
 334 
 335 /*
 336  * Class:     com_sun_glass_ui_mac_MacView
 337  * Method:    _getNativeLayer
 338  * Signature: (J)J
 339  */
 340 JNIEXPORT jlong JNICALL Java_com_sun_glass_ui_mac_MacView__1getNativeLayer
 341 (JNIEnv *env, jobject jView, jlong jPtr)
 342 {
 343     LOG("Java_com_sun_glass_ui_mac_MacView__1_getNativeLayer");
 344     LOG("   view: %p", jPtr);
 345     if (!jPtr) return 0L;
 346     
 347     jlong ptr = 0L;
 348     
 349     GLASS_ASSERT_MAIN_JAVA_THREAD(env);
 350     GLASS_POOL_ENTER;
 351     {
 352         NSView<GlassView> *view = getGlassView(env, jPtr);
 353         ptr = ptr_to_jlong([view layer]);
 354     }
 355     GLASS_POOL_EXIT;
 356     GLASS_CHECK_EXCEPTION(env);
 357     
 358     return ptr;
 359 }
 360 
 361 /*
 362  * Class:     com_sun_glass_ui_mac_MacView
 363  * Method:    _getNativeRemoteLayerId
 364  * Signature: (JLjava/lang/String;)I
 365  */
 366 JNIEXPORT jint JNICALL Java_com_sun_glass_ui_mac_MacView__1getNativeRemoteLayerId
 367 (JNIEnv *env, jobject jView, jlong jPtr, jstring jServerString)
 368 {
 369     LOG("Java_com_sun_glass_ui_mac_MacView__1_getNativeLayerId");
 370     LOG("   layer: %p", jPtr);
 371     if (!jPtr) return 0;
 372     
 373     jint layerId = 0;
 374     
 375     GLASS_ASSERT_MAIN_JAVA_THREAD(env);
 376     GLASS_POOL_ENTER;
 377     {
 378         NSView<GlassView> *view = getGlassView(env, jPtr);
 379         layerId = (jint)[view getRemoteLayerIdForServer:[GlassHelper nsStringWithJavaString:jServerString withEnv:env]];
 380     }
 381     GLASS_POOL_EXIT;
 382     GLASS_CHECK_EXCEPTION(env);
 383     
 384     LOG("   layerId: %d", layerId);
 385     return layerId;
 386 }
 387 
 388 /*
 389  * Class:     com_sun_glass_ui_mac_MacView
 390  * Method:    _hostRemoteLayerId
 391  * Signature: (JI)V
 392  */
 393 JNIEXPORT void JNICALL Java_com_sun_glass_ui_mac_MacView__1hostRemoteLayerId
 394 (JNIEnv *env, jobject jView, jlong jPtr, jint jRemoteLayerId)
 395 {
 396     LOG("Java_com_sun_glass_ui_mac_MacView__1hostRemoteLayerId");
 397     if (!jPtr) return;
 398     
 399     GLASS_ASSERT_MAIN_JAVA_THREAD(env);
 400     GLASS_POOL_ENTER;
 401     {
 402         if (jRemoteLayerId > 0)
 403         {
 404             NSView<GlassView> *view = getGlassView(env, jPtr);
 405             [view hostRemoteLayerId:(uint32_t)jRemoteLayerId];
 406         }
 407     }
 408     GLASS_POOL_EXIT;
 409     GLASS_CHECK_EXCEPTION(env);
 410 }
 411 
 412 /*
 413  * Class:     com_sun_glass_ui_mac_MacView
 414  * Method:    _getX
 415  * Signature: ()I
 416  */
 417 JNIEXPORT jint JNICALL Java_com_sun_glass_ui_mac_MacView__1getX
 418 (JNIEnv *env, jobject jView, jlong jPtr)
 419 {
 420     LOG("Java_com_sun_glass_ui_mac_MacView__1getX");
 421     if (!jPtr) return 0;
 422     
 423     jint x = 0;
 424     
 425     GLASS_ASSERT_MAIN_JAVA_THREAD(env);
 426     GLASS_POOL_ENTER;
 427     {
 428         NSView<GlassView> *view = getGlassView(env, jPtr);
 429         NSWindow *window = [view window];
 430         if (window != nil)
 431         {
 432             NSRect frame = [window frame];
 433             NSRect contentRect = [window contentRectForFrameRect:frame];
 434             x = (jint)(contentRect.origin.x - frame.origin.x);
 435         }
 436     }
 437     GLASS_POOL_EXIT;
 438     GLASS_CHECK_EXCEPTION(env);
 439     
 440     return x;
 441 }
 442 
 443 /*
 444  * Class:     com_sun_glass_ui_mac_MacView
 445  * Method:    _getY
 446  * Signature: ()I
 447  */
 448 JNIEXPORT jint JNICALL Java_com_sun_glass_ui_mac_MacView__1getY
 449 (JNIEnv *env, jobject jView, jlong jPtr)
 450 {
 451     LOG("Java_com_sun_glass_ui_mac_MacView__1getY");
 452     if (!jPtr) return 0;
 453     
 454     jint y = 0;
 455     
 456     GLASS_ASSERT_MAIN_JAVA_THREAD(env);
 457     GLASS_POOL_ENTER;
 458     {
 459         NSView<GlassView> *view = getGlassView(env, jPtr);
 460         NSWindow * window = [view window];
 461         if (window != nil)
 462         {
 463             NSRect frame = [window frame];
 464             NSRect contentRect = [window contentRectForFrameRect:frame];
 465             
 466             // Assume that the border in the bottom is zero-sized
 467             y = (jint)(frame.size.height - contentRect.size.height);
 468         }
 469     }
 470     GLASS_POOL_EXIT;
 471     GLASS_CHECK_EXCEPTION(env);
 472     
 473     return y;
 474 }
 475 
 476 /*
 477  * Class:     com_sun_glass_ui_mac_MacView
 478  * Method:    _setParent
 479  * Signature: (JJ)V
 480  */
 481 JNIEXPORT void JNICALL Java_com_sun_glass_ui_mac_MacView__1setParent
 482 (JNIEnv *env, jobject jView, jlong jPtr, jlong parentPtr)
 483 {
 484     LOG("Java_com_sun_glass_ui_mac_MacView__1setParent");
 485     LOG("   view: %p", jPtr);
 486     LOG("   parent: %p", parentPtr);
 487     if (!jPtr) return;
 488     
 489     GLASS_ASSERT_MAIN_JAVA_THREAD(env);
 490     // TODO: Java_com_sun_glass_ui_mac_MacView__1setParent
 491 }
 492 
 493 /*
 494  * Class:     com_sun_glass_ui_mac_MacView
 495  * Method:    _close
 496  * Signature: (J)Z
 497  */
 498 JNIEXPORT jboolean JNICALL Java_com_sun_glass_ui_mac_MacView__1close
 499 (JNIEnv *env, jobject jView, jlong jPtr)
 500 {
 501     LOG("Java_com_sun_glass_ui_mac_MacView__1close");
 502     if (!jPtr) return JNI_FALSE;
 503 
 504     GLASS_ASSERT_MAIN_JAVA_THREAD(env);
 505     GLASS_POOL_ENTER;
 506     {
 507         NSView<GlassView> *view = getGlassView(env, jPtr);
 508         NSView * host = [view superview];
 509         if (host != nil) {
 510             [view removeFromSuperview];
 511             [host release];
 512         }
 513         [view release];
 514     }
 515     GLASS_POOL_EXIT;
 516     GLASS_CHECK_EXCEPTION(env);
 517 
 518     return JNI_TRUE;
 519 }
 520 
 521 /*
 522  * Class:     com_sun_glass_ui_mac_MacView
 523  * Method:    _begin
 524  * Signature: ()V
 525  */
 526 JNIEXPORT void JNICALL Java_com_sun_glass_ui_mac_MacView__1begin
 527 (JNIEnv *env, jobject jView, jlong jPtr)
 528 {
 529     LOG("Java_com_sun_glass_ui_mac_MacView__1begin");
 530     if (!jPtr) return;
 531     
 532     GLASS_ASSERT_MAIN_JAVA_THREAD(env);
 533     NSView<GlassView> *view = getGlassView(env, jPtr);
 534     GLASS_POOL_PUSH; // it will be popped by "_end"
 535     {
 536         [view retain];
 537 //        [view lockFocus];
 538         [view begin];
 539     }
 540 }
 541 
 542 /*
 543  * Class:     com_sun_glass_ui_mac_MacView
 544  * Method:    _end
 545  * Signature: (Z)V
 546  */
 547 JNIEXPORT void JNICALL Java_com_sun_glass_ui_mac_MacView__1end
 548 (JNIEnv *env, jobject jView, jlong jPtr)
 549 {
 550     LOG("Java_com_sun_glass_ui_mac_MacView__1end");
 551     if (!jPtr) return;
 552     
 553     GLASS_ASSERT_MAIN_JAVA_THREAD(env);
 554     NSView<GlassView> *view = getGlassView(env, jPtr);
 555     {
 556         [view end];
 557 //        [view unlockFocus];
 558         [view release];
 559     }
 560     GLASS_POOL_POP; // it was pushed by "_begin"
 561 }
 562 
 563 /*
 564  * Class:     com_sun_glass_ui_mac_MacView
 565  * Method:    _scheduleRepaint
 566  * Signature: ()V
 567  */
 568 JNIEXPORT void JNICALL Java_com_sun_glass_ui_mac_MacView__1scheduleRepaint
 569 (JNIEnv *env, jobject jView, jlong jPtr)
 570 {
 571     LOG("Java_com_sun_glass_ui_mac_MacView__1scheduleRepaint");
 572     if (!jPtr) return;
 573     
 574     GLASS_ASSERT_MAIN_JAVA_THREAD(env);
 575     GLASS_POOL_ENTER;
 576     {
 577         NSView<GlassView> *view = getGlassView(env, jPtr);
 578         [view setNeedsDisplay:YES];
 579     }
 580     GLASS_POOL_EXIT;
 581     GLASS_CHECK_EXCEPTION(env);
 582 }
 583 
 584 /*
 585  * Class:     com_sun_glass_ui_mac_MacView
 586  * Method:    _enterFullscreen
 587  * Signature: (ZZZ)V
 588  */
 589 JNIEXPORT jboolean JNICALL Java_com_sun_glass_ui_mac_MacView__1enterFullscreen
 590 (JNIEnv *env, jobject jView, jlong jPtr, jboolean jAnimate, jboolean jKeepRatio, jboolean jHideCursor)
 591 {
 592     LOG("Java_com_sun_glass_ui_mac_MacView__1enterFullscreen");
 593     if (!jPtr) return JNI_FALSE;
 594     
 595     GLASS_ASSERT_MAIN_JAVA_THREAD(env);
 596     GLASS_POOL_ENTER;
 597     {
 598         NSView<GlassView> *view = getGlassView(env, jPtr);
 599         [view enterFullscreenWithAnimate:(jAnimate==JNI_TRUE) withKeepRatio:(jKeepRatio==JNI_TRUE) withHideCursor:(jHideCursor==JNI_TRUE)];
 600     }
 601     GLASS_POOL_EXIT;
 602     GLASS_CHECK_EXCEPTION(env);
 603     
 604     return JNI_TRUE; // gznote: remove this return value
 605 }
 606 
 607 /*
 608  * Class:     com_sun_glass_ui_mac_MacView
 609  * Method:    _exitFullscreen
 610  * Signature: (Z)V
 611  */
 612 JNIEXPORT void JNICALL Java_com_sun_glass_ui_mac_MacView__1exitFullscreen
 613 (JNIEnv *env, jobject jView, jlong jPtr, jboolean jAnimate)
 614 {
 615     LOG("Java_com_sun_glass_ui_mac_MacView__1exitFullscreen");
 616     if (!jPtr) return;
 617     
 618     GLASS_ASSERT_MAIN_JAVA_THREAD(env);
 619     GLASS_POOL_ENTER;
 620     {
 621         NSView<GlassView> *view = getGlassView(env, jPtr);
 622         [view exitFullscreenWithAnimate:(jAnimate==JNI_TRUE)];
 623     }
 624     GLASS_POOL_EXIT;
 625     GLASS_CHECK_EXCEPTION(env);
 626 }
 627 
 628 /*
 629  * Class:     com_sun_glass_ui_mac_MacView
 630  * Method:    _uploadPixelsDirect
 631  * Signature: (JLjava/nio/Buffer;II)V
 632  */
 633 JNIEXPORT void JNICALL Java_com_sun_glass_ui_mac_MacView__1uploadPixelsDirect
 634 (JNIEnv *env, jobject jView, jlong jPtr, jobject jBuffer, jint jWidth, jint jHeight)
 635 {
 636     LOG("Java_com_sun_glass_ui_mac_MacView__1uploadPixelsDirect");
 637     if (!jPtr) return;
 638     
 639     GLASS_ASSERT_MAIN_JAVA_THREAD(env);
 640     NSView<GlassView> *view = getGlassView(env, jPtr);
 641     
 642 #ifndef FORCE_NOISE
 643     void *pixels = (*env)->GetDirectBufferAddress(env, jBuffer);
 644 #else
 645     void *pixels = _GenerateNoise(jWidth, jHeight);
 646 #endif
 647     
 648     // must be in the middle of begin/end
 649     if ((jWidth > 0) && (jHeight > 0))
 650     {
 651         [view pushPixels:pixels withWidth:(GLuint)jWidth withHeight:(GLuint)jHeight withEnv:env];
 652     }
 653 }
 654 
 655 /*
 656  * Class:     com_sun_glass_ui_mac_MacView
 657  * Method:    _uploadPixelsByteArray
 658  * Signature: (J[BIII)V
 659  */
 660 JNIEXPORT void JNICALL Java_com_sun_glass_ui_mac_MacView__1uploadPixelsByteArray
 661 (JNIEnv *env, jobject jView, jlong jPtr, jbyteArray jArray, jint jOffset, jint jWidth, jint jHeight)
 662 {
 663     LOG("Java_com_sun_glass_ui_mac_MacView__1uploadPixelsByteArray");
 664     if (!jPtr) return;
 665     
 666     GLASS_ASSERT_MAIN_JAVA_THREAD(env);
 667     
 668     jboolean isCopy = JNI_FALSE;
 669     u_int8_t *data = (*env)->GetPrimitiveArrayCritical(env, jArray, &isCopy);
 670     {
 671         assert((4*jWidth*jHeight + jOffset) == (*env)->GetArrayLength(env, jArray));
 672         
 673         NSView<GlassView> *view = getGlassView(env, jPtr);
 674         
 675 #ifndef FORCE_NOISE
 676         void *pixels = (data+jOffset);
 677 #else
 678         void *pixels = _GenerateNoise(jWidth, jHeight);
 679 #endif
 680         
 681         // must be in the middle of begin/end
 682         if ((jWidth > 0) && (jHeight > 0))
 683         {
 684             [view pushPixels:pixels withWidth:(GLuint)jWidth withHeight:(GLuint)jHeight withEnv:env];
 685         }
 686     }
 687     (*env)->ReleasePrimitiveArrayCritical(env, jArray, data, JNI_ABORT);
 688 }
 689 
 690 /*
 691  * Class:     com_sun_glass_ui_mac_MacView
 692  * Method:    _uploadPixelsIntArray
 693  * Signature: (J[IIII)V
 694  */
 695 JNIEXPORT void JNICALL Java_com_sun_glass_ui_mac_MacView__1uploadPixelsIntArray
 696 (JNIEnv *env, jobject jView, jlong jPtr, jintArray jArray, jint jOffset, jint jWidth, jint jHeight)
 697 {
 698     LOG("Java_com_sun_glass_ui_mac_MacView__1uploadPixelsIntArray");
 699     if (!jPtr) return;
 700     
 701     GLASS_ASSERT_MAIN_JAVA_THREAD(env);
 702     
 703     jboolean isCopy = JNI_FALSE;
 704     u_int32_t *data = (*env)->GetPrimitiveArrayCritical(env, jArray, &isCopy);
 705     {
 706         assert((jWidth*jHeight + jOffset) == (*env)->GetArrayLength(env, jArray));
 707         
 708         NSView<GlassView> *view = getGlassView(env, jPtr);
 709         
 710 #ifndef FORCE_NOISE
 711         void *pixels = (data+jOffset);
 712 #else
 713         void *pixels = _GenerateNoise(jWidth, jHeight);
 714 #endif
 715         
 716         // must be in the middle of begin/end
 717         if ((jWidth > 0) && (jHeight > 0))
 718         {
 719             [view pushPixels:pixels withWidth:(GLuint)jWidth withHeight:(GLuint)jHeight withEnv:env];
 720         }
 721     }
 722     (*env)->ReleasePrimitiveArrayCritical(env, jArray, data, JNI_ABORT);
 723 }
 724 
 725 /*
 726  * Input methods callback
 727  */
 728 
 729 /*
 730  * Class:     com_sun_glass_ui_mac_MacView
 731  * Method:    _enableInputMethodEvents
 732  * Signature: (JZ)V
 733  */
 734 JNIEXPORT void JNICALL Java_com_sun_glass_ui_mac_MacView__1enableInputMethodEvents
 735 (JNIEnv *env, jobject jView, jlong ptr, jboolean enable)
 736 {
 737     LOG("Java_com_sun_glass_ui_mac_MacView__1enableInputMethodEvents");
 738     if (!ptr) return;
 739 
 740     GLASS_ASSERT_MAIN_JAVA_THREAD(env);
 741     GLASS_POOL_ENTER;
 742     {
 743         NSView<GlassView> *view = getGlassView(env, ptr);
 744         [view setInputMethodEnabled:(enable==JNI_TRUE)];
 745     }
 746     GLASS_POOL_EXIT;
 747     GLASS_CHECK_EXCEPTION(env);
 748 }