Replace AWT code for getAvailableDisplayMode and other DisplayModes
stuff to use pure native Cococa code.
This commit is contained in:
parent
409b3fea6d
commit
db4eb9c5c8
|
@ -39,8 +39,6 @@ package org.lwjgl.opengl;
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import java.awt.Canvas;
|
import java.awt.Canvas;
|
||||||
import java.awt.GraphicsDevice;
|
|
||||||
import java.awt.GraphicsEnvironment;
|
|
||||||
import java.awt.Robot;
|
import java.awt.Robot;
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
import java.nio.FloatBuffer;
|
import java.nio.FloatBuffer;
|
||||||
|
@ -57,10 +55,6 @@ import org.lwjgl.MemoryUtil;
|
||||||
import org.lwjgl.LWJGLException;
|
import org.lwjgl.LWJGLException;
|
||||||
import org.lwjgl.LWJGLUtil;
|
import org.lwjgl.LWJGLUtil;
|
||||||
|
|
||||||
import com.apple.eawt.Application;
|
|
||||||
import com.apple.eawt.ApplicationAdapter;
|
|
||||||
import com.apple.eawt.ApplicationEvent;
|
|
||||||
|
|
||||||
import static org.lwjgl.opengl.GL11.*;
|
import static org.lwjgl.opengl.GL11.*;
|
||||||
|
|
||||||
final class MacOSXDisplay implements DisplayImplementation {
|
final class MacOSXDisplay implements DisplayImplementation {
|
||||||
|
@ -72,7 +66,7 @@ final class MacOSXDisplay implements DisplayImplementation {
|
||||||
private Robot robot;
|
private Robot robot;
|
||||||
private MacOSXMouseEventQueue mouse_queue;
|
private MacOSXMouseEventQueue mouse_queue;
|
||||||
private KeyboardEventQueue keyboard_queue;
|
private KeyboardEventQueue keyboard_queue;
|
||||||
private java.awt.DisplayMode requested_mode;
|
private DisplayMode requested_mode;
|
||||||
|
|
||||||
/* Members for native window use */
|
/* Members for native window use */
|
||||||
private MacOSXNativeMouse mouse;
|
private MacOSXNativeMouse mouse;
|
||||||
|
@ -99,6 +93,10 @@ final class MacOSXDisplay implements DisplayImplementation {
|
||||||
|
|
||||||
private native ByteBuffer nCreateWindow(int x, int y, int width, int height, boolean fullscreen, boolean undecorated, boolean resizable, boolean parented, ByteBuffer peer_info_handle, ByteBuffer window_handle) throws LWJGLException;
|
private native ByteBuffer nCreateWindow(int x, int y, int width, int height, boolean fullscreen, boolean undecorated, boolean resizable, boolean parented, ByteBuffer peer_info_handle, ByteBuffer window_handle) throws LWJGLException;
|
||||||
|
|
||||||
|
private native Object nGetCurrentDisplayMode();
|
||||||
|
|
||||||
|
private native void nGetDisplayModes(Object modesList);
|
||||||
|
|
||||||
private native boolean nIsMiniaturized(ByteBuffer window_handle);
|
private native boolean nIsMiniaturized(ByteBuffer window_handle);
|
||||||
|
|
||||||
private native boolean nIsFocused(ByteBuffer window_handle);
|
private native boolean nIsFocused(ByteBuffer window_handle);
|
||||||
|
@ -220,26 +218,22 @@ final class MacOSXDisplay implements DisplayImplementation {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean equals(java.awt.DisplayMode awt_mode, DisplayMode mode) {
|
private static boolean equals(DisplayMode mode1, DisplayMode mode2) {
|
||||||
return awt_mode.getWidth() == mode.getWidth() && awt_mode.getHeight() == mode.getHeight()
|
return mode1.getWidth() == mode2.getWidth() && mode1.getHeight() == mode2.getHeight()
|
||||||
&& awt_mode.getBitDepth() == mode.getBitsPerPixel() && awt_mode.getRefreshRate() == mode.getFrequency();
|
&& mode1.getBitsPerPixel() == mode2.getBitsPerPixel() && mode1.getFrequency() == mode2.getFrequency();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void switchDisplayMode(DisplayMode mode) throws LWJGLException {
|
public void switchDisplayMode(DisplayMode mode) throws LWJGLException {
|
||||||
java.awt.DisplayMode[] awt_modes = getDevice().getDisplayModes();
|
DisplayMode[] modes = getAvailableDisplayModes();
|
||||||
for ( java.awt.DisplayMode awt_mode : awt_modes ) {
|
|
||||||
if (equals(awt_mode, mode)) {
|
for (DisplayMode available_mode : modes) {
|
||||||
requested_mode = awt_mode;
|
if (equals(available_mode, mode)) {
|
||||||
|
requested_mode = available_mode;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
throw new LWJGLException(mode + " is not supported");
|
|
||||||
}
|
|
||||||
|
|
||||||
private static GraphicsDevice getDevice() {
|
throw new LWJGLException(mode + " is not supported");
|
||||||
GraphicsEnvironment g_env = GraphicsEnvironment.getLocalGraphicsEnvironment();
|
|
||||||
GraphicsDevice device = g_env.getDefaultScreenDevice();
|
|
||||||
return device;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void resetDisplayMode() {
|
public void resetDisplayMode() {
|
||||||
|
@ -249,32 +243,24 @@ final class MacOSXDisplay implements DisplayImplementation {
|
||||||
|
|
||||||
private native void restoreGamma();
|
private native void restoreGamma();
|
||||||
|
|
||||||
private static DisplayMode createLWJGLDisplayMode(java.awt.DisplayMode awt_mode) {
|
public Object createDisplayMode(int width, int height, int bitsPerPixel, int refreshRate) {
|
||||||
int bit_depth;
|
return new DisplayMode(width, height, bitsPerPixel, refreshRate);
|
||||||
int refresh_rate;
|
|
||||||
int awt_bit_depth = awt_mode.getBitDepth();
|
|
||||||
int awt_refresh_rate = awt_mode.getRefreshRate();
|
|
||||||
if (awt_bit_depth != java.awt.DisplayMode.BIT_DEPTH_MULTI)
|
|
||||||
bit_depth = awt_bit_depth;
|
|
||||||
else
|
|
||||||
bit_depth = 32; // Assume the best bit depth
|
|
||||||
if (awt_refresh_rate != java.awt.DisplayMode.REFRESH_RATE_UNKNOWN)
|
|
||||||
refresh_rate = awt_refresh_rate;
|
|
||||||
else
|
|
||||||
refresh_rate = 0;
|
|
||||||
return new DisplayMode(awt_mode.getWidth(), awt_mode.getHeight(), bit_depth, refresh_rate);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public DisplayMode init() throws LWJGLException {
|
public DisplayMode init() throws LWJGLException {
|
||||||
return createLWJGLDisplayMode(getDevice().getDisplayMode());
|
java.awt.Toolkit.getDefaultToolkit(); // force start AWT Application loop
|
||||||
|
return (DisplayMode) nGetCurrentDisplayMode();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addDisplayMode(Object modesList, int width, int height, int bitsPerPixel, int refreshRate) {
|
||||||
|
List<DisplayMode> modes = (List<DisplayMode>) modesList;
|
||||||
|
DisplayMode displayMode = new DisplayMode(width, height, bitsPerPixel, refreshRate);
|
||||||
|
modes.add(displayMode);
|
||||||
}
|
}
|
||||||
|
|
||||||
public DisplayMode[] getAvailableDisplayModes() throws LWJGLException {
|
public DisplayMode[] getAvailableDisplayModes() throws LWJGLException {
|
||||||
java.awt.DisplayMode[] awt_modes = getDevice().getDisplayModes();
|
|
||||||
List<DisplayMode> modes = new ArrayList<DisplayMode>();
|
List<DisplayMode> modes = new ArrayList<DisplayMode>();
|
||||||
for ( java.awt.DisplayMode awt_mode : awt_modes )
|
nGetDisplayModes(modes); // will populate the above list
|
||||||
if ( awt_mode.getBitDepth() >= 16 )
|
|
||||||
modes.add(createLWJGLDisplayMode(awt_mode));
|
|
||||||
return modes.toArray(new DisplayMode[modes.size()]);
|
return modes.toArray(new DisplayMode[modes.size()]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -83,6 +83,8 @@ typedef struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
+ (NSOpenGLPixelFormat*)defaultPixelFormat;
|
+ (NSOpenGLPixelFormat*)defaultPixelFormat;
|
||||||
|
- (BOOL)windowShouldClose:(id)sender;
|
||||||
|
- (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)sender;
|
||||||
- (id)initWithFrame:(NSRect)frameRect pixelFormat:(NSOpenGLPixelFormat*)format;
|
- (id)initWithFrame:(NSRect)frameRect pixelFormat:(NSOpenGLPixelFormat*)format;
|
||||||
- (void)setOpenGLContext:(NSOpenGLContext*)context;
|
- (void)setOpenGLContext:(NSOpenGLContext*)context;
|
||||||
- (NSOpenGLContext*)openGLContext;
|
- (NSOpenGLContext*)openGLContext;
|
||||||
|
|
|
@ -618,6 +618,65 @@ JNIEXPORT jboolean JNICALL Java_org_lwjgl_opengl_MacOSXDisplay_nIsNativeMode(JNI
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
JNIEXPORT jobject JNICALL Java_org_lwjgl_opengl_MacOSXDisplay_nGetCurrentDisplayMode(JNIEnv *env, jobject this) {
|
||||||
|
|
||||||
|
jclass displayClass = (*env)->GetObjectClass(env, this);
|
||||||
|
jmethodID createDisplayModeMethod = (*env)->GetMethodID(env, displayClass, "createDisplayMode", "(IIII)Ljava/lang/Object;");
|
||||||
|
|
||||||
|
CGDisplayModeRef mode = CGDisplayCopyDisplayMode(kCGDirectMainDisplay);
|
||||||
|
|
||||||
|
int width = (int) CGDisplayModeGetWidth(mode);
|
||||||
|
int height = (int) CGDisplayModeGetHeight(mode);
|
||||||
|
int refreshRate = (int)CGDisplayModeGetRefreshRate(mode);
|
||||||
|
int bitsPerPixel;
|
||||||
|
|
||||||
|
// get bitsPerPixel
|
||||||
|
CFStringRef pixelEncoding = CGDisplayModeCopyPixelEncoding(mode);
|
||||||
|
|
||||||
|
if(CFStringCompare(pixelEncoding, CFSTR(IO16BitDirectPixels), kCFCompareCaseInsensitive) == kCFCompareEqualTo) {
|
||||||
|
bitsPerPixel = 16;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
bitsPerPixel = 32;
|
||||||
|
}
|
||||||
|
|
||||||
|
jobject displayMode = (*env)->CallObjectMethod(env, this, createDisplayModeMethod, width, height, bitsPerPixel, refreshRate);
|
||||||
|
|
||||||
|
return displayMode;
|
||||||
|
}
|
||||||
|
|
||||||
|
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_MacOSXDisplay_nGetDisplayModes(JNIEnv *env, jobject this, jobject modesList) {
|
||||||
|
CFArrayRef modes = CGDisplayCopyAllDisplayModes(kCGDirectMainDisplay, NULL);
|
||||||
|
|
||||||
|
jclass displayClass = (*env)->GetObjectClass(env, this);
|
||||||
|
jmethodID addDisplayModeMethod = (*env)->GetMethodID(env, displayClass, "addDisplayMode", "(Ljava/lang/Object;IIII)V");
|
||||||
|
|
||||||
|
int i = 0;
|
||||||
|
|
||||||
|
for (i = 0; i < CFArrayGetCount(modes); i++) {
|
||||||
|
CGDisplayModeRef mode = (CGDisplayModeRef)CFArrayGetValueAtIndex(modes, i);
|
||||||
|
|
||||||
|
int width = (int) CGDisplayModeGetWidth(mode);
|
||||||
|
int height = (int) CGDisplayModeGetHeight(mode);
|
||||||
|
int refreshRate = (int)CGDisplayModeGetRefreshRate(mode);
|
||||||
|
int bitsPerPixel;
|
||||||
|
|
||||||
|
// get bitsPerPixel
|
||||||
|
CFStringRef pixelEncoding = CGDisplayModeCopyPixelEncoding(mode);
|
||||||
|
if(CFStringCompare(pixelEncoding, CFSTR(IO32BitDirectPixels), kCFCompareCaseInsensitive) == kCFCompareEqualTo) {
|
||||||
|
bitsPerPixel = 32;
|
||||||
|
}
|
||||||
|
else if(CFStringCompare(pixelEncoding, CFSTR(IO16BitDirectPixels), kCFCompareCaseInsensitive) == kCFCompareEqualTo) {
|
||||||
|
bitsPerPixel = 16;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
continue; // ignore DisplayMode of other bitsPerPixel rates
|
||||||
|
}
|
||||||
|
|
||||||
|
(*env)->CallVoidMethod(env, this, addDisplayModeMethod, modesList, width, height, bitsPerPixel, refreshRate);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
JNIEXPORT jint JNICALL Java_org_lwjgl_DefaultSysImplementation_getJNIVersion(JNIEnv *env, jobject ignored) {
|
JNIEXPORT jint JNICALL Java_org_lwjgl_DefaultSysImplementation_getJNIVersion(JNIEnv *env, jobject ignored) {
|
||||||
return org_lwjgl_MacOSXSysImplementation_JNI_VERSION;
|
return org_lwjgl_MacOSXSysImplementation_JNI_VERSION;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue