< prev index next >
modules/javafx.graphics/src/main/native-glass/mac/GlassTimer.m
Print this page
*** 1,7 ****
/*
! * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
--- 1,7 ----
/*
! * Copyright (c) 2011, 2018, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
*** 106,115 ****
--- 106,118 ----
}
return NULL;
}
+ BOOL detachCVDisplayLinkThread = FALSE;
+ JavaVMAttachArgs attachArgs = {JNI_VERSION_1_2, "PulseTimer-CVDisplayLink thread", NULL};
+
CVReturn CVOutputCallback(CVDisplayLinkRef displayLink,
const CVTimeStamp *inNow, const CVTimeStamp *inOutputTime,
CVOptionFlags flagsIn, CVOptionFlags *flagsOut,
void *displayLinkContext) {
*** 117,145 ****
if (displayLinkContext != NULL)
{
GlassTimer *timer = (GlassTimer*)displayLinkContext;
! // Attach the thread every time. Cocoa changes the thread when a new
! // display resolution is selected so we need to make sure that we are
! // able to call into Java. Attaching the same thread multiple times
! // does nothing.
! jint error = (*MAIN_JVM)->AttachCurrentThreadAsDaemon(MAIN_JVM, (void **)&timer->_env, NULL);
if (error == 0)
{
if (timer->_runnable != NULL)
{
(*timer->_env)->CallVoidMethod(timer->_env, timer->_runnable, jRunnableRun);
}
! // Do not detach the thread - continuously attaching and detaching a thread
! // kills some debuggers making it impossible to step through Prism. Since
! // the thread is attached as a daemon, it will not stop Java from exiting.
! // error = (*MAIN_JVM)->DetachCurrentThread(MAIN_JVM);
! // if (error != JNI_OK) {
! // NSLog(@"ERROR: Glass could not detach CVDisplayLink _thread to VM, result:%d\n", (int)error);
! // }
} else {
NSLog(@"ERROR: Glass could not attach CVDisplayLink _thread to VM, result:%d\n", (int)error);
}
}
--- 120,154 ----
if (displayLinkContext != NULL)
{
GlassTimer *timer = (GlassTimer*)displayLinkContext;
! // CVDisplayLinkStart() starts a new CVDisplayLink thread. This thread
! // should be attached to JVM. Cocoa changes the thread when a new display
! // resolution is selected so we need to make sure that we are able to
! // call into Java. Attaching the same thread multiple times does nothing.
! // The thread is attached as a daemon, it will not stop Java from exiting.
!
! jint error = (*MAIN_JVM)->AttachCurrentThreadAsDaemon(MAIN_JVM, (void **)&timer->_env, (void*)&attachArgs);
if (error == 0)
{
if (timer->_runnable != NULL)
{
(*timer->_env)->CallVoidMethod(timer->_env, timer->_runnable, jRunnableRun);
}
! if (detachCVDisplayLinkThread)
! {
! // _pause() calls CVDisplayLinkStop() on current CVDisplayLink thread, which
! // stops the thread, so the thread should be detached.
! detachCVDisplayLinkThread = FALSE;
! error = (*MAIN_JVM)->DetachCurrentThread(MAIN_JVM);
! if (error != JNI_OK)
! {
! NSLog(@"ERROR: Glass could not detach CVDisplayLink _thread to VM, result:%d\n", (int)error);
! }
! }
} else {
NSLog(@"ERROR: Glass could not attach CVDisplayLink _thread to VM, result:%d\n", (int)error);
}
}
*** 285,294 ****
--- 294,373 ----
}
}
GLASS_POOL_EXIT;
GLASS_CHECK_EXCEPTION(env);
}
+
+ /*
+ * Class: com_sun_glass_ui_mac_MacTimer
+ * Method: _pause
+ * Signature: ()I
+ */
+ JNIEXPORT void JNICALL Java_com_sun_glass_ui_mac_MacTimer__1pause
+ (JNIEnv * env, jclass cls, jlong jTimerPtr)
+ {
+ LOG("Java_com_sun_glass_ui_mac_MacTimer__1pause");
+
+ GLASS_ASSERT_MAIN_JAVA_THREAD(env);
+ GLASS_POOL_ENTER;
+ {
+ GlassTimer *timer = (GlassTimer*)jlong_to_ptr(jTimerPtr);
+ if (timer->_period == 0)
+ {
+ // Stop the CVDisplayLink thread. There is no API to pause the CVDisplayLink
+ // thread. CVDisplayLinkStop() stops the CVDisplayLink thread.
+ if (GlassDisplayLink != NULL && CVDisplayLinkIsRunning(GlassDisplayLink))
+ {
+ CVDisplayLinkStop(GlassDisplayLink);
+ detachCVDisplayLinkThread = TRUE;
+ }
+ }
+ else
+ {
+ timer->_running = NO;
+ }
+ }
+ GLASS_POOL_EXIT;
+ GLASS_CHECK_EXCEPTION(env);
+ }
+
+
+ /*
+ * Class: com_sun_glass_ui_mac_MacTimer
+ * Method: _resume
+ * Signature: ()I
+ */
+ JNIEXPORT void JNICALL Java_com_sun_glass_ui_mac_MacTimer__1resume
+ (JNIEnv * env, jclass cls, jlong jTimerPtr)
+ {
+ LOG("Java_com_sun_glass_ui_mac_MacTimer__1resume");
+
+ GLASS_ASSERT_MAIN_JAVA_THREAD(env);
+ GLASS_POOL_ENTER;
+ {
+ GlassTimer *timer = (GlassTimer*)jlong_to_ptr(jTimerPtr);
+ if (timer->_period == 0)
+ {
+ // Start the CVDisplayLink thread. There is no API to resume the CVDisplayLink
+ // thread. CVDisplayLinkStart() starts a new CVDisplayLink thread.
+ if (GlassDisplayLink != NULL && !CVDisplayLinkIsRunning(GlassDisplayLink))
+ {
+ CVReturn err = CVDisplayLinkStart(GlassDisplayLink);
+ if (err != kCVReturnSuccess)
+ {
+ NSLog(@"CVDisplayLinkStart error: %d", err);
+ }
+ }
+ }
+ else
+ {
+ timer->_running = YES;
+ }
+ }
+ GLASS_POOL_EXIT;
+ GLASS_CHECK_EXCEPTION(env);
+ }
/*
* Class: com_sun_glass_ui_mac_MacTimer
* Method: _getMinPeriod
* Signature: ()I
< prev index next >