*** empty log message ***
This commit is contained in:
parent
6b9b2d302f
commit
23d09086e3
|
@ -39,16 +39,80 @@
|
|||
* @version $Revision$
|
||||
*/
|
||||
|
||||
#include <JavaVM/jni.h>
|
||||
#include "org_lwjgl_Display.h"
|
||||
#include "common_tools.h"
|
||||
#include "tools.h"
|
||||
|
||||
static CFDictionaryRef original_mode;
|
||||
|
||||
JNIEXPORT void JNICALL Java_org_lwjgl_Display_init(JNIEnv * env, jclass clazz) {
|
||||
original_mode = CGDisplayCurrentMode(kCGDirectMainDisplay);
|
||||
long width;
|
||||
long height;
|
||||
long bpp;
|
||||
long freq;
|
||||
getDictLong(original_mode, kCGDisplayWidth, &width);
|
||||
getDictLong(original_mode, kCGDisplayHeight, &height);
|
||||
getDictLong(original_mode, kCGDisplayBitsPerPixel, &bpp);
|
||||
getDictLong(original_mode, kCGDisplayRefreshRate, &freq);
|
||||
jclass jclass_DisplayMode = env->FindClass("org/lwjgl/DisplayMode");
|
||||
jmethodID ctor = env->GetMethodID(jclass_DisplayMode, "<init>", "(IIII)V");
|
||||
jobject newMode = env->NewObject(jclass_DisplayMode, ctor, width, height, bpp, freq);
|
||||
jfieldID fid_initialMode = env->GetStaticFieldID(clazz, "mode", "Lorg/lwjgl/DisplayMode;");
|
||||
env->SetStaticObjectField(clazz, fid_initialMode, newMode);
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL Java_org_lwjgl_Display_setDisplayMode(JNIEnv * env, jclass clazz, jobject mode) {
|
||||
jclass cls_displayMode = env->FindClass("org/lwjgl/DisplayMode");
|
||||
jfieldID fid_width = env->GetFieldID(cls_displayMode, "width", "I");
|
||||
jfieldID fid_height = env->GetFieldID(cls_displayMode, "height", "I");
|
||||
jfieldID fid_bpp = env->GetFieldID(cls_displayMode, "bpp", "I");
|
||||
jfieldID fid_freq = env->GetFieldID(cls_displayMode, "freq", "I");
|
||||
int width = env->GetIntField(mode, fid_width);
|
||||
int height = env->GetIntField(mode, fid_height);
|
||||
int bpp = env->GetIntField(mode, fid_bpp);
|
||||
int freq = env->GetIntField(mode, fid_freq);
|
||||
CGDisplayCapture(kCGDirectMainDisplay);
|
||||
CFDictionaryRef displayMode = CGDisplayBestModeForParametersAndRefreshRate(kCGDirectMainDisplay, bpp, width, height, freq, NULL);
|
||||
CGDisplaySwitchToMode(kCGDirectMainDisplay, displayMode);
|
||||
|
||||
jmethodID ctor = env->GetMethodID(cls_displayMode, "<init>", "(IIII)V");
|
||||
jobject newMode = env->NewObject(cls_displayMode, ctor, width, height, bpp, freq);
|
||||
jfieldID fid_initialMode = env->GetStaticFieldID(clazz, "mode", "Lorg/lwjgl/DisplayMode;");
|
||||
env->SetStaticObjectField(clazz, fid_initialMode, newMode);
|
||||
}
|
||||
|
||||
JNIEXPORT jobjectArray JNICALL Java_org_lwjgl_Display_nGetAvailableDisplayModes(JNIEnv * env, jclass clazz) {
|
||||
CFArrayRef modes = CGDisplayAvailableModes(kCGDirectMainDisplay);
|
||||
int size = CFArrayGetCount(modes);
|
||||
int avail_modes = 0;
|
||||
for (int i = 0; i < size; i++) {
|
||||
CFDictionaryRef mode = (CFDictionaryRef)CFArrayGetValueAtIndex(modes, i);
|
||||
long bpp;
|
||||
getDictLong(mode, kCGDisplayBitsPerPixel, &bpp);
|
||||
if (bpp > 8)
|
||||
avail_modes++;
|
||||
}
|
||||
jclass displayModeClass = env->FindClass("org/lwjgl/DisplayMode");
|
||||
jobjectArray ret = env->NewObjectArray(avail_modes, displayModeClass, NULL);
|
||||
jmethodID displayModeConstructor = env->GetMethodID(displayModeClass, "<init>", "(IIII)V");
|
||||
int array_index = 0;
|
||||
for (int i = 0; i < size; i++) {
|
||||
CFDictionaryRef mode = (CFDictionaryRef)CFArrayGetValueAtIndex(modes, i);
|
||||
long width;
|
||||
long height;
|
||||
long bpp;
|
||||
long freq;
|
||||
getDictLong(mode, kCGDisplayWidth, &width);
|
||||
getDictLong(mode, kCGDisplayHeight, &height);
|
||||
getDictLong(mode, kCGDisplayBitsPerPixel, &bpp);
|
||||
getDictLong(mode, kCGDisplayRefreshRate, &freq);
|
||||
if (bpp > 8) {
|
||||
jobject displayMode = env->NewObject(displayModeClass, displayModeConstructor, width, height, bpp, freq);
|
||||
env->SetObjectArrayElement(ret, array_index++, displayMode);
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
JNIEXPORT jint JNICALL Java_org_lwjgl_Display_getPlatform(JNIEnv * env, jclass clazz) {
|
||||
|
@ -62,6 +126,8 @@ JNIEXPORT jboolean JNICALL Java_org_lwjgl_Display_setGammaRamp(JNIEnv *env, jcla
|
|||
}
|
||||
|
||||
JNIEXPORT void JNICALL Java_org_lwjgl_Display_resetDisplayMode(JNIEnv *, jclass) {
|
||||
CGDisplaySwitchToMode(kCGDirectMainDisplay, original_mode);
|
||||
CGDisplayRelease(kCGDirectMainDisplay);
|
||||
}
|
||||
|
||||
JNIEXPORT jstring JNICALL Java_org_lwjgl_Display_getAdapter(JNIEnv * , jclass) {
|
||||
|
|
|
@ -134,16 +134,6 @@ static void printCFNumber(CFNumberRef num) {
|
|||
printf("0x%lx (%ld)", number, number);
|
||||
}
|
||||
*/
|
||||
static bool getLongProperty(CFDictionaryRef dict, CFStringRef key, long *key_value) {
|
||||
CFTypeRef val = CFDictionaryGetValue(dict, key);
|
||||
if (val != NULL) {
|
||||
CFTypeID type = CFGetTypeID(val);
|
||||
if (type == CFNumberGetTypeID())
|
||||
if (CFNumberGetValue((CFNumberRef)val, kCFNumberLongType, key_value))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/*static void printProperty(CFDictionaryRef dict, CFStringRef key) {
|
||||
CFTypeRef val = CFDictionaryGetValue(dict, key);
|
||||
|
@ -224,9 +214,9 @@ static void searchDictionary(CFDictionaryRef dict) {
|
|||
long cookie_num;
|
||||
long usage;
|
||||
long usage_page;
|
||||
if (!getLongProperty(dict, CFSTR(kIOHIDElementCookieKey), &cookie_num) ||
|
||||
!getLongProperty(dict, CFSTR(kIOHIDElementUsageKey), &usage) ||
|
||||
!getLongProperty(dict, CFSTR(kIOHIDElementUsagePageKey), &usage_page))
|
||||
if (!getDictLong(dict, CFSTR(kIOHIDElementCookieKey), &cookie_num) ||
|
||||
!getDictLong(dict, CFSTR(kIOHIDElementUsageKey), &usage) ||
|
||||
!getDictLong(dict, CFSTR(kIOHIDElementUsagePageKey), &usage_page))
|
||||
return;
|
||||
testCookie(usage_page, usage, (IOHIDElementCookie)cookie_num, &x_axis_cookie, kHIDPage_GenericDesktop, kHIDUsage_GD_X);
|
||||
testCookie(usage_page, usage, (IOHIDElementCookie)cookie_num, &y_axis_cookie, kHIDPage_GenericDesktop, kHIDUsage_GD_Y);
|
||||
|
@ -284,8 +274,8 @@ static bool findDevice(void) {
|
|||
if (kern_err == KERN_SUCCESS && dev_props != NULL) {
|
||||
long usage;
|
||||
long usage_page;
|
||||
if (getLongProperty(dev_props, CFSTR(kIOHIDPrimaryUsageKey), &usage) &&
|
||||
getLongProperty(dev_props, CFSTR(kIOHIDPrimaryUsagePageKey), &usage_page) &&
|
||||
if (getDictLong(dev_props, CFSTR(kIOHIDPrimaryUsageKey), &usage) &&
|
||||
getDictLong(dev_props, CFSTR(kIOHIDPrimaryUsagePageKey), &usage_page) &&
|
||||
usage_page == kHIDPage_GenericDesktop && usage == kHIDUsage_GD_Mouse) {
|
||||
success = initDevice(hid_device, dev_props);
|
||||
}
|
||||
|
|
|
@ -162,8 +162,8 @@ static void destroy(void) {
|
|||
static bool createContext(JNIEnv *env, jint bpp, jint alpha, jint depth, jint stencil) {
|
||||
AGLDrawable drawable = GetWindowPort(win_ref);
|
||||
SetPort(drawable);
|
||||
GLint attrib[] = {AGL_RGBA,
|
||||
AGL_DOUBLEBUFFER,
|
||||
GLint attrib[] = {AGL_RGBA,
|
||||
AGL_DOUBLEBUFFER,
|
||||
AGL_ACCELERATED,
|
||||
AGL_NO_RECOVERY,
|
||||
AGL_MINIMUM_POLICY,
|
||||
|
@ -227,7 +227,7 @@ JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Window_nCreate(JNIEnv *env, jclass
|
|||
return;
|
||||
}
|
||||
if (current_fullscreen)
|
||||
status = BeginFullScreen(&fullscreen_ptr, NULL, 0, 0, &win_ref, NULL, 0);
|
||||
status = BeginFullScreen(&fullscreen_ptr, NULL, NULL, NULL, &win_ref, NULL, 0);
|
||||
else
|
||||
status = CreateNewWindow(kDocumentWindowClass, window_attr, &rect, &win_ref);
|
||||
if (noErr != status) {
|
||||
|
@ -274,7 +274,7 @@ JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Window_nSetTitle(JNIEnv * env, jcla
|
|||
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Window_update(JNIEnv *env, jclass clazz) {
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Window_swapBuffers(JNIEnv * env, jclass clazz) {
|
||||
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Window_swapBuffers(JNIEnv * env, jclass clazz) {
|
||||
aglSwapBuffers(context);
|
||||
}
|
||||
|
||||
|
|
|
@ -4,6 +4,17 @@
|
|||
|
||||
MPCriticalRegionID critical_region;
|
||||
|
||||
bool getDictLong(CFDictionaryRef dict, CFStringRef key, long *key_value) {
|
||||
CFTypeRef val = CFDictionaryGetValue(dict, key);
|
||||
if (val != NULL) {
|
||||
CFTypeID type = CFGetTypeID(val);
|
||||
if (type == CFNumberGetTypeID())
|
||||
if (CFNumberGetValue((CFNumberRef)val, kCFNumberLongType, key_value))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool registerHandler(JNIEnv* env, WindowRef win_ref, EventHandlerProcPtr func, UInt32 event_class, UInt32 event_kind) {
|
||||
EventTypeSpec event_type;
|
||||
EventHandlerUPP handler_upp = NewEventHandlerUPP(func);
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
#define lock() {lockLWJGL();
|
||||
#define unlock() unlockLWJGL();}
|
||||
|
||||
extern bool getDictLong(CFDictionaryRef dict, CFStringRef key, long *key_value);
|
||||
extern bool registerHandler(JNIEnv* env, WindowRef win_ref, EventHandlerProcPtr func, UInt32 event_class, UInt32 event_kind);
|
||||
extern bool initLock(JNIEnv* env);
|
||||
extern void destroyLock(void);
|
||||
|
|
Loading…
Reference in New Issue