2002-08-15 11:46:18 -04:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2002 Light Weight Java Game Library Project
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions are
|
|
|
|
* met:
|
|
|
|
*
|
|
|
|
* * Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
2002-08-11 07:49:32 -04:00
|
|
|
*
|
2002-08-15 11:46:18 -04:00
|
|
|
* * Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
2002-08-11 07:49:32 -04:00
|
|
|
*
|
2002-08-15 11:46:18 -04:00
|
|
|
* * Neither the name of 'Light Weight Java Game Library' nor the names of
|
|
|
|
* its contributors may be used to endorse or promote products derived
|
|
|
|
* from this software without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
|
|
|
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
|
|
|
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
|
|
|
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
|
|
|
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
|
|
|
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
|
|
|
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
|
|
|
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
|
|
|
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
|
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* $Id$
|
2002-08-11 07:49:32 -04:00
|
|
|
*
|
2002-08-15 11:46:18 -04:00
|
|
|
* Win32 specific library for display handdling.
|
2002-08-11 07:49:32 -04:00
|
|
|
*
|
2002-08-15 11:46:18 -04:00
|
|
|
* @author cix_foo <cix_foo@users.sourceforge.net>
|
|
|
|
* @version $Revision$
|
2002-08-11 07:49:32 -04:00
|
|
|
*/
|
|
|
|
|
2003-03-27 20:28:04 -05:00
|
|
|
#include "Window.h"
|
2002-08-11 07:49:32 -04:00
|
|
|
#include "org_lwjgl_Display.h"
|
2002-08-15 10:53:18 -04:00
|
|
|
|
2002-08-17 10:13:12 -04:00
|
|
|
#define WINDOWCLASSNAME "LWJGLWINDOW"
|
2002-08-11 07:49:32 -04:00
|
|
|
|
2003-03-03 16:49:46 -05:00
|
|
|
jobjectArray GetAvailableDisplayModesNT(JNIEnv * env);
|
|
|
|
jobjectArray GetAvailableDisplayModes9x(JNIEnv * env);
|
2003-02-07 16:54:31 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
2002-08-11 07:49:32 -04:00
|
|
|
/*
|
|
|
|
* Class: org_lwjgl_Display
|
2003-03-03 16:51:13 -05:00
|
|
|
* Method: nGetAvailableDisplayModes
|
2002-08-11 07:49:32 -04:00
|
|
|
* Signature: ()[Lorg/lwjgl/DisplayMode;
|
|
|
|
*/
|
2003-03-03 16:49:46 -05:00
|
|
|
JNIEXPORT jobjectArray JNICALL Java_org_lwjgl_Display_nGetAvailableDisplayModes
|
2002-08-11 07:49:32 -04:00
|
|
|
(JNIEnv * env, jclass clazz)
|
|
|
|
{
|
2003-03-03 16:49:46 -05:00
|
|
|
// Determine whether to use a display name or NULL, which depends on the operating
|
|
|
|
// system
|
|
|
|
OSVERSIONINFO osvi;
|
2002-08-24 17:19:06 -04:00
|
|
|
|
2003-03-03 16:49:46 -05:00
|
|
|
osvi.dwOSVersionInfoSize = sizeof(osvi);
|
|
|
|
GetVersionEx(&osvi);
|
2002-12-23 08:23:29 -05:00
|
|
|
|
2003-03-03 16:49:46 -05:00
|
|
|
if (osvi.dwPlatformId == VER_PLATFORM_WIN32_NT) {
|
|
|
|
#ifdef _DEBUG
|
|
|
|
printf("Selecting NT display mode check");
|
|
|
|
#endif
|
|
|
|
return GetAvailableDisplayModesNT(env);
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef _DEBUG
|
|
|
|
printf("Selecting 9x display mode check");
|
|
|
|
#endif
|
|
|
|
return GetAvailableDisplayModes9x(env);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Choose displaymodes using NT codepath (multiple displaydevices)
|
|
|
|
*/
|
|
|
|
jobjectArray GetAvailableDisplayModesNT(JNIEnv * env) {
|
2003-03-19 07:41:28 -05:00
|
|
|
int i = 0, j = 0, n = 0;
|
|
|
|
int AvailableModes = 0;
|
2003-03-03 16:49:46 -05:00
|
|
|
|
2003-03-19 07:41:28 -05:00
|
|
|
DISPLAY_DEVICE DisplayDevice;
|
|
|
|
DEVMODE DevMode;
|
2003-03-03 16:49:46 -05:00
|
|
|
|
2003-03-19 07:41:28 -05:00
|
|
|
DevMode.dmSize = sizeof(DEVMODE);
|
|
|
|
DisplayDevice.cb = sizeof(DISPLAY_DEVICE);
|
2003-03-03 16:49:46 -05:00
|
|
|
|
|
|
|
//enumerate all displays, and all of their displaymodes
|
2003-03-19 07:41:28 -05:00
|
|
|
while(EnumDisplayDevices(NULL, i++, &DisplayDevice, 0) != 0) {
|
|
|
|
while(EnumDisplaySettings(DisplayDevice.DeviceName, j++, &DevMode) != 0) {
|
|
|
|
if (DevMode.dmBitsPerPel > 8) {
|
|
|
|
AvailableModes++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2003-03-03 16:49:46 -05:00
|
|
|
|
|
|
|
#ifdef _DEBUG
|
2003-03-19 07:41:28 -05:00
|
|
|
printf("Found %d displaymodes\n", AvailableModes);
|
2003-03-03 16:49:46 -05:00
|
|
|
#endif
|
|
|
|
|
2003-03-19 07:41:28 -05:00
|
|
|
// now that we have the count create the classes, and add 'em all - we'll remove dups in Java
|
|
|
|
// Allocate an array of DisplayModes big enough
|
2002-08-24 17:19:06 -04:00
|
|
|
jclass displayModeClass = env->FindClass("org/lwjgl/DisplayMode");
|
2002-12-22 14:52:44 -05:00
|
|
|
|
2003-03-19 07:41:28 -05:00
|
|
|
jobjectArray ret = env->NewObjectArray(AvailableModes, displayModeClass, NULL);
|
|
|
|
jmethodID displayModeConstructor = env->GetMethodID(displayModeClass, "<init>", "(IIII)V");
|
2003-03-03 16:49:46 -05:00
|
|
|
|
2003-03-19 07:41:28 -05:00
|
|
|
i = 0, j = 0, n = 0;
|
|
|
|
while(EnumDisplayDevices(NULL, i++, &DisplayDevice, 0) != 0) {
|
|
|
|
while(EnumDisplaySettings(DisplayDevice.DeviceName, j++, &DevMode) != 0) {
|
|
|
|
// Filter out indexed modes
|
|
|
|
if (DevMode.dmBitsPerPel > 8) {
|
|
|
|
jobject displayMode;
|
|
|
|
displayMode = env->NewObject(displayModeClass, displayModeConstructor,
|
|
|
|
DevMode.dmPelsWidth, DevMode.dmPelsHeight,
|
|
|
|
DevMode.dmBitsPerPel, DevMode.dmDisplayFrequency);
|
|
|
|
|
|
|
|
env->SetObjectArrayElement(ret, n++, displayMode);
|
2003-03-03 16:49:46 -05:00
|
|
|
}
|
2003-03-19 07:41:28 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return ret;
|
2003-03-03 16:49:46 -05:00
|
|
|
}
|
2002-12-22 14:52:44 -05:00
|
|
|
|
2003-03-03 16:49:46 -05:00
|
|
|
/**
|
|
|
|
* Choose displaymodes using 9x codepath (single displaydevice)
|
|
|
|
*/
|
|
|
|
jobjectArray GetAvailableDisplayModes9x(JNIEnv * env) {
|
2003-03-19 07:41:28 -05:00
|
|
|
int i = 0, j = 0, n = 0;
|
|
|
|
int AvailableModes = 0;
|
2003-03-03 16:49:46 -05:00
|
|
|
|
2003-03-19 07:41:28 -05:00
|
|
|
DEVMODE DevMode;
|
2003-03-03 16:49:46 -05:00
|
|
|
|
2003-03-19 07:41:28 -05:00
|
|
|
DevMode.dmSize = sizeof(DEVMODE);
|
2003-03-03 16:49:46 -05:00
|
|
|
|
2003-03-19 07:41:28 -05:00
|
|
|
//enumerate all displaymodes
|
|
|
|
while(EnumDisplaySettings(NULL, j++, &DevMode) != 0) {
|
|
|
|
if (DevMode.dmBitsPerPel > 8) {
|
|
|
|
AvailableModes++;
|
|
|
|
}
|
|
|
|
}
|
2003-03-03 16:49:46 -05:00
|
|
|
|
|
|
|
#ifdef _DEBUG
|
2003-03-19 07:41:28 -05:00
|
|
|
printf("Found %d displaymodes\n", AvailableModes);
|
2003-03-03 16:49:46 -05:00
|
|
|
#endif
|
|
|
|
|
2003-03-19 07:41:28 -05:00
|
|
|
// now that we have the count create the classes, and add 'em all - we'll remove dups in Java
|
|
|
|
// Allocate an array of DisplayModes big enough
|
2003-03-03 16:49:46 -05:00
|
|
|
jclass displayModeClass = env->FindClass("org/lwjgl/DisplayMode");
|
2002-12-22 14:52:44 -05:00
|
|
|
|
2003-03-22 16:39:52 -05:00
|
|
|
jobjectArray ret = env->NewObjectArray(AvailableModes, displayModeClass, NULL);
|
2003-03-19 07:41:28 -05:00
|
|
|
jmethodID displayModeConstructor = env->GetMethodID(displayModeClass, "<init>", "(IIII)V");
|
2003-03-03 16:49:46 -05:00
|
|
|
|
2003-03-19 07:41:28 -05:00
|
|
|
i = 0, j = 0, n = 0;
|
|
|
|
while(EnumDisplaySettings(NULL, j++, &DevMode) != 0) {
|
|
|
|
// Filter out indexed modes
|
|
|
|
if (DevMode.dmBitsPerPel > 8) {
|
|
|
|
jobject displayMode;
|
|
|
|
displayMode = env->NewObject(displayModeClass, displayModeConstructor,
|
|
|
|
DevMode.dmPelsWidth, DevMode.dmPelsHeight,
|
|
|
|
DevMode.dmBitsPerPel, DevMode.dmDisplayFrequency);
|
|
|
|
env->SetObjectArrayElement(ret, n++, displayMode);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ret;
|
2002-08-11 07:49:32 -04:00
|
|
|
}
|
|
|
|
|
2003-03-27 20:28:04 -05:00
|
|
|
|
2002-08-11 07:49:32 -04:00
|
|
|
/*
|
|
|
|
* Class: org_lwjgl_Display
|
2003-03-27 20:28:04 -05:00
|
|
|
* Method: getPlatform
|
|
|
|
* Signature: ()I
|
2002-08-11 07:49:32 -04:00
|
|
|
*/
|
2003-03-27 20:28:04 -05:00
|
|
|
JNIEXPORT jint JNICALL Java_org_lwjgl_Display_getPlatform
|
|
|
|
(JNIEnv * env, jclass clazz)
|
2002-08-11 07:49:32 -04:00
|
|
|
{
|
2003-03-27 20:28:04 -05:00
|
|
|
return org_lwjgl_Display_PLATFORM_WGL;
|
|
|
|
}
|
2002-12-19 11:35:35 -05:00
|
|
|
|
2003-03-27 20:28:04 -05:00
|
|
|
/*
|
|
|
|
* Class: org_lwjgl_Display
|
|
|
|
* Method: setDisplayMode
|
|
|
|
* Signature: (Lorg/lwjgl/DisplayMode;)V
|
|
|
|
*/
|
|
|
|
JNIEXPORT void JNICALL Java_org_lwjgl_Display_setDisplayMode
|
|
|
|
(JNIEnv * env, jclass clazz, jobject mode)
|
|
|
|
{
|
2002-12-19 11:35:35 -05:00
|
|
|
|
2003-03-27 20:28:04 -05:00
|
|
|
jfieldID fid_width = env->GetFieldID(clazz, "width", "I");
|
|
|
|
jfieldID fid_height = env->GetFieldID(clazz, "height", "I");
|
|
|
|
jfieldID fid_bpp = env->GetFieldID(clazz, "bpp", "I");
|
|
|
|
jfieldID fid_freq = env->GetFieldID(clazz, "freq", "I");
|
2003-01-31 14:04:45 -05:00
|
|
|
|
2003-03-27 20:28:04 -05:00
|
|
|
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);
|
2002-12-19 11:35:35 -05:00
|
|
|
|
|
|
|
|
2003-03-27 20:28:04 -05:00
|
|
|
DEVMODE devmode;
|
|
|
|
devmode.dmSize = sizeof(DEVMODE);
|
|
|
|
devmode.dmBitsPerPel = bpp;
|
|
|
|
devmode.dmPelsWidth = width;
|
|
|
|
devmode.dmPelsHeight = height;
|
|
|
|
devmode.dmDisplayFlags = 0;
|
|
|
|
devmode.dmDisplayFrequency = freq;
|
|
|
|
devmode.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT | DM_DISPLAYFLAGS;
|
|
|
|
if (freq != 0)
|
|
|
|
devmode.dmFields |= DM_DISPLAYFREQUENCY;
|
2002-12-19 11:35:35 -05:00
|
|
|
|
2003-02-12 04:33:11 -05:00
|
|
|
|
2003-03-27 20:28:04 -05:00
|
|
|
LONG cdsret = ChangeDisplaySettings(&devmode, CDS_FULLSCREEN);
|
2002-12-19 11:35:35 -05:00
|
|
|
|
2003-03-27 20:28:04 -05:00
|
|
|
if (cdsret != DISP_CHANGE_SUCCESSFUL) {
|
|
|
|
// Failed: so let's check to see if it's a wierd dual screen display
|
2002-12-19 11:35:35 -05:00
|
|
|
#ifdef _DEBUG
|
2003-03-27 20:28:04 -05:00
|
|
|
printf("Failed to set display mode... assuming dual monitors\n");
|
2002-12-19 11:35:35 -05:00
|
|
|
#endif
|
2003-03-27 20:28:04 -05:00
|
|
|
devmode.dmPelsWidth = width * 2;
|
|
|
|
cdsret = ChangeDisplaySettings(&devmode, CDS_FULLSCREEN);
|
2002-12-19 11:35:35 -05:00
|
|
|
|
2003-03-27 20:28:04 -05:00
|
|
|
if (cdsret != DISP_CHANGE_SUCCESSFUL) {
|
|
|
|
#ifdef _DEBUG
|
|
|
|
printf("Failed to set display mode using dual monitors\n");
|
|
|
|
#endif
|
|
|
|
throwException(env, "Failed to set display mode.");
|
|
|
|
}
|
2002-08-11 07:49:32 -04:00
|
|
|
}
|
|
|
|
|
2003-03-27 20:28:04 -05:00
|
|
|
// The change was successful but might not be the exact change we were expecting.
|
|
|
|
// Now we'll construct a new DisplayMode instance and stash it back in the Display
|
|
|
|
// class's mode instance variable.
|
|
|
|
|
|
|
|
// Get the screen
|
|
|
|
HDC screenDC = CreateCompatibleDC(NULL);
|
|
|
|
// Get the device caps
|
|
|
|
width = GetDeviceCaps(screenDC, HORZRES);
|
|
|
|
height = GetDeviceCaps(screenDC, VERTRES);
|
|
|
|
bpp = GetDeviceCaps(screenDC, COLORRES);
|
|
|
|
freq = GetDeviceCaps(screenDC, VREFRESH);
|
|
|
|
if (freq <= 1)
|
|
|
|
freq = 0; // Unknown
|
|
|
|
ReleaseDC(NULL, screenDC);
|
|
|
|
|
|
|
|
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_mode= env->GetStaticFieldID(clazz, "mode", "[org/lwjgl/DisplayMode;");
|
|
|
|
env->SetStaticObjectField(clazz, fid_mode, newMode);
|
|
|
|
env->DeleteLocalRef(newMode);
|
2002-08-17 10:13:12 -04:00
|
|
|
|
2002-08-11 07:49:32 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Class: org_lwjgl_Display
|
2003-03-27 20:28:04 -05:00
|
|
|
* Method: resetDisplayMode
|
2002-08-11 07:49:32 -04:00
|
|
|
* Signature: ()V
|
|
|
|
*/
|
2003-03-27 20:28:04 -05:00
|
|
|
JNIEXPORT void JNICALL Java_org_lwjgl_Display_resetDisplayMode
|
2002-08-11 07:49:32 -04:00
|
|
|
(JNIEnv * env, jclass clazz)
|
|
|
|
{
|
2003-03-27 20:28:04 -05:00
|
|
|
// Under Win32, all we have to do is:
|
|
|
|
ChangeDisplaySettings(NULL, 0);
|
|
|
|
|
|
|
|
// And we'll call init() again to put the correct mode back in Display
|
|
|
|
Java_org_lwjgl_Display_init(env, clazz);
|
2002-08-11 07:49:32 -04:00
|
|
|
}
|
2002-12-19 11:35:35 -05:00
|
|
|
|
2003-02-07 16:54:31 -05:00
|
|
|
/*
|
|
|
|
* Class: org_lwjgl_Display
|
2003-03-27 20:28:04 -05:00
|
|
|
* Method: getGammaRamp
|
|
|
|
* Signature: ()[I
|
2003-02-07 16:54:31 -05:00
|
|
|
*/
|
2003-03-27 20:28:04 -05:00
|
|
|
JNIEXPORT jintArray JNICALL Java_org_lwjgl_Display_getGammaRamp
|
2003-02-07 16:54:31 -05:00
|
|
|
(JNIEnv * env, jclass clazz)
|
|
|
|
{
|
2003-03-27 20:28:04 -05:00
|
|
|
return NULL;
|
|
|
|
}
|
2003-02-07 16:54:31 -05:00
|
|
|
|
2003-03-27 20:28:04 -05:00
|
|
|
/*
|
|
|
|
* Class: org_lwjgl_Display
|
|
|
|
* Method: setGammaRamp
|
|
|
|
* Signature: ([I)V
|
|
|
|
*/
|
|
|
|
JNIEXPORT void JNICALL Java_org_lwjgl_Display_setGammaRamp
|
|
|
|
(JNIEnv * env, jclass clazz, jintArray gamma)
|
|
|
|
{
|
2003-02-07 16:54:31 -05:00
|
|
|
}
|
2003-03-21 12:08:26 -05:00
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Class: org_lwjgl_Display
|
2003-03-27 20:28:04 -05:00
|
|
|
* Method: init
|
|
|
|
* Signature: ()V
|
2003-03-21 12:08:26 -05:00
|
|
|
*/
|
2003-03-27 20:28:04 -05:00
|
|
|
JNIEXPORT void JNICALL Java_org_lwjgl_Display_init
|
2003-03-21 12:08:26 -05:00
|
|
|
(JNIEnv * env, jclass clazz)
|
|
|
|
{
|
2003-03-27 20:28:04 -05:00
|
|
|
// Determine the current screen resolution
|
|
|
|
|
|
|
|
// Get the screen
|
|
|
|
HDC screenDC = CreateCompatibleDC(NULL);
|
|
|
|
// Get the device caps
|
|
|
|
int width = GetDeviceCaps(screenDC, HORZRES);
|
|
|
|
int height = GetDeviceCaps(screenDC, VERTRES);
|
|
|
|
int bpp = GetDeviceCaps(screenDC, COLORRES);
|
|
|
|
int freq = GetDeviceCaps(screenDC, VREFRESH);
|
|
|
|
if (freq <= 1)
|
|
|
|
freq = 0; // Unknown
|
|
|
|
ReleaseDC(NULL, screenDC);
|
|
|
|
|
|
|
|
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->GetFieldID(clazz, "initialMode", "[org/lwjgl/DisplayMode;");
|
|
|
|
env->SetStaticObjectField(clazz, fid_initialMode, newMode);
|
|
|
|
env->DeleteLocalRef(newMode);
|
2003-03-21 12:08:26 -05:00
|
|
|
}
|
|
|
|
|
2003-03-27 20:28:04 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|