*** empty log message ***
This commit is contained in:
parent
d61172410c
commit
8cabcd523f
|
@ -215,12 +215,13 @@ public final class Display {
|
||||||
* @param contrast The contrast, larger than 0.0.
|
* @param contrast The contrast, larger than 0.0.
|
||||||
* @return true if the call succeeded, false otherwise
|
* @return true if the call succeeded, false otherwise
|
||||||
*/
|
*/
|
||||||
public static boolean setDisplayConfiguration(float gamma, float brightness, float contrast) {
|
public static void setDisplayConfiguration(float gamma, float brightness, float contrast) throws Exception {
|
||||||
assert brightness >= -1.0f && brightness <= 1.0f;
|
assert brightness >= -1.0f && brightness <= 1.0f;
|
||||||
assert contrast >= 0.0f;
|
assert contrast >= 0.0f;
|
||||||
int rampSize = getGammaRampLength();
|
int rampSize = getGammaRampLength();
|
||||||
if (rampSize == 0)
|
if (rampSize == 0) {
|
||||||
return false;
|
throw new Exception("Display configuration not supported");
|
||||||
|
}
|
||||||
FloatBuffer gammaRamp = ByteBuffer.allocateDirect(rampSize*4).order(ByteOrder.nativeOrder()).asFloatBuffer();
|
FloatBuffer gammaRamp = ByteBuffer.allocateDirect(rampSize*4).order(ByteOrder.nativeOrder()).asFloatBuffer();
|
||||||
for (int i = 0; i < rampSize; i++) {
|
for (int i = 0; i < rampSize; i++) {
|
||||||
float intensity = (float)i/(rampSize - 1);
|
float intensity = (float)i/(rampSize - 1);
|
||||||
|
@ -237,12 +238,10 @@ public final class Display {
|
||||||
rampEntry = 0.0f;
|
rampEntry = 0.0f;
|
||||||
gammaRamp.put(i, rampEntry);
|
gammaRamp.put(i, rampEntry);
|
||||||
}
|
}
|
||||||
if (!setGammaRamp(gammaRamp))
|
setGammaRamp(gammaRamp);
|
||||||
return false;
|
|
||||||
if (Sys.DEBUG) {
|
if (Sys.DEBUG) {
|
||||||
System.out.println("Gamma set, gamma = " + gamma + ", brightness = " + brightness + ", contrast = " + contrast);
|
System.out.println("Gamma set, gamma = " + gamma + ", brightness = " + brightness + ", contrast = " + contrast);
|
||||||
}
|
}
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -256,7 +255,7 @@ public final class Display {
|
||||||
/**
|
/**
|
||||||
* Native method to set the gamma ramp.
|
* Native method to set the gamma ramp.
|
||||||
*/
|
*/
|
||||||
private static native boolean setGammaRamp(FloatBuffer gammaRamp);
|
private static native void setGammaRamp(FloatBuffer gammaRamp) throws Exception ;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the driver adapter string. This is a unique string describing the actual card's hardware, eg. "Geforce2", "PS2",
|
* Get the driver adapter string. This is a unique string describing the actual card's hardware, eg. "Geforce2", "PS2",
|
||||||
|
|
|
@ -13,9 +13,9 @@ import org.lwjgl.*;
|
||||||
*/
|
*/
|
||||||
public class DisplayConfigurationTest {
|
public class DisplayConfigurationTest {
|
||||||
private static void changeConfig(float gamma, float brightness, float contrast) {
|
private static void changeConfig(float gamma, float brightness, float contrast) {
|
||||||
Display.setDisplayConfiguration(gamma, brightness, contrast);
|
|
||||||
System.out.println("Configuration changed, gamma = " + gamma + " brightness = " + brightness + " contrast = " + contrast);
|
|
||||||
try {
|
try {
|
||||||
|
Display.setDisplayConfiguration(gamma, brightness, contrast);
|
||||||
|
System.out.println("Configuration changed, gamma = " + gamma + " brightness = " + brightness + " contrast = " + contrast);
|
||||||
Thread.sleep(3000);
|
Thread.sleep(3000);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
|
|
@ -70,24 +70,26 @@ JNIEXPORT jint JNICALL Java_org_lwjgl_Display_getGammaRampLength
|
||||||
/*
|
/*
|
||||||
* Class: org_lwjgl_Display
|
* Class: org_lwjgl_Display
|
||||||
* Method: setGammaRamp
|
* Method: setGammaRamp
|
||||||
* Signature: (Ljava/nio/FloatBuffer;)Z
|
* Signature: (Ljava/nio/FloatBuffer;)V
|
||||||
*/
|
*/
|
||||||
JNIEXPORT jboolean JNICALL Java_org_lwjgl_Display_setGammaRamp
|
JNIEXPORT void JNICALL Java_org_lwjgl_Display_setGammaRamp
|
||||||
(JNIEnv *, jclass, jobject);
|
(JNIEnv *, jclass, jobject);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Class: org_lwjgl_Display
|
* Class: org_lwjgl_Display
|
||||||
* Method: getAdapter
|
* Method: getAdapter
|
||||||
|
* Signature: ()Ljava/lang/String;
|
||||||
*/
|
*/
|
||||||
JNIEXPORT jstring JNICALL Java_org_lwjgl_Display_getAdapter
|
JNIEXPORT jstring JNICALL Java_org_lwjgl_Display_getAdapter
|
||||||
(JNIEnv * , jclass);
|
(JNIEnv *, jclass);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Class: org_lwjgl_Display
|
* Class: org_lwjgl_Display
|
||||||
* Method: getVersion
|
* Method: getVersion
|
||||||
|
* Signature: ()Ljava/lang/String;
|
||||||
*/
|
*/
|
||||||
JNIEXPORT jstring JNICALL Java_org_lwjgl_Display_getVersion
|
JNIEXPORT jstring JNICALL Java_org_lwjgl_Display_getVersion
|
||||||
(JNIEnv * , jclass);
|
(JNIEnv *, jclass);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|
|
@ -276,44 +276,23 @@ JNIEXPORT jobjectArray JNICALL Java_org_lwjgl_Display_nGetAvailableDisplayModes
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
JNIEXPORT jint JNICALL Java_org_lwjgl_Display_getPlatform(JNIEnv * env, jclass clazz) {
|
||||||
* Class: org_lwjgl_Display
|
|
||||||
* Method: getPlatform
|
|
||||||
* Signature: ()I
|
|
||||||
*/
|
|
||||||
JNIEXPORT jint JNICALL Java_org_lwjgl_Display_getPlatform
|
|
||||||
(JNIEnv * env, jclass clazz)
|
|
||||||
{
|
|
||||||
return org_lwjgl_Display_PLATFORM_GLX;
|
return org_lwjgl_Display_PLATFORM_GLX;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
JNIEXPORT jint JNICALL Java_org_lwjgl_Display_getGammaRampLength(JNIEnv *env, jclass clazz) {
|
||||||
* Class: org_lwjgl_Display
|
|
||||||
* Method: getGammaRampLength
|
|
||||||
* Signature: ()I
|
|
||||||
*/
|
|
||||||
JNIEXPORT jint JNICALL Java_org_lwjgl_Display_getGammaRampLength
|
|
||||||
(JNIEnv *env, jclass clazz)
|
|
||||||
{
|
|
||||||
return gamma_ramp_length;
|
return gamma_ramp_length;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
JNIEXPORT void JNICALL Java_org_lwjgl_Display_setGammaRamp(JNIEnv *env, jclass clazz, jobject gamma_ramp_buffer) {
|
||||||
* Class: org_lwjgl_Display
|
if (gamma_ramp_length == 0) {
|
||||||
* Method: setGammaRamp
|
throwException(env, "gamma ramp length == 0.");
|
||||||
* Signature: (I)Z
|
return;
|
||||||
*/
|
}
|
||||||
JNIEXPORT jboolean JNICALL Java_org_lwjgl_Display_setGammaRamp
|
|
||||||
(JNIEnv *env, jclass clazz, jobject gamma_ramp_buffer)
|
|
||||||
{
|
|
||||||
if (gamma_ramp_length == 0)
|
|
||||||
return JNI_FALSE;
|
|
||||||
Display * disp = XOpenDisplay(NULL);
|
Display * disp = XOpenDisplay(NULL);
|
||||||
if (disp == NULL) {
|
if (disp == NULL) {
|
||||||
#ifdef _DEBUG
|
throwException(env, "Could not open X connection.");
|
||||||
printf("Could not open X connection\n");
|
return;
|
||||||
#endif
|
|
||||||
return JNI_FALSE;
|
|
||||||
}
|
}
|
||||||
int screen = DefaultScreen(disp);
|
int screen = DefaultScreen(disp);
|
||||||
const float *gamma_ramp = (const float *)env->GetDirectBufferAddress(gamma_ramp_buffer);
|
const float *gamma_ramp = (const float *)env->GetDirectBufferAddress(gamma_ramp_buffer);
|
||||||
|
@ -324,14 +303,9 @@ JNIEXPORT jboolean JNICALL Java_org_lwjgl_Display_setGammaRamp
|
||||||
ramp[i] = (unsigned short)round(scaled_gamma);
|
ramp[i] = (unsigned short)round(scaled_gamma);
|
||||||
}
|
}
|
||||||
if (XF86VidModeSetGammaRamp(disp, screen, gamma_ramp_length, ramp, ramp, ramp) == False) {
|
if (XF86VidModeSetGammaRamp(disp, screen, gamma_ramp_length, ramp, ramp, ramp) == False) {
|
||||||
#ifdef _DEBUG
|
throwException(env, "Could not set gamma ramp.");
|
||||||
printf("Could not set gamma ramp\n");
|
|
||||||
#endif
|
|
||||||
XCloseDisplay(disp);
|
|
||||||
return JNI_FALSE;
|
|
||||||
}
|
}
|
||||||
XCloseDisplay(disp);
|
XCloseDisplay(disp);
|
||||||
return JNI_TRUE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
JNIEXPORT jstring JNICALL Java_org_lwjgl_Display_getAdapter
|
JNIEXPORT jstring JNICALL Java_org_lwjgl_Display_getAdapter
|
||||||
|
|
|
@ -44,8 +44,11 @@
|
||||||
#include "common_tools.h"
|
#include "common_tools.h"
|
||||||
#include "tools.h"
|
#include "tools.h"
|
||||||
|
|
||||||
|
#define GAMMARAMP_LENGTH 256
|
||||||
|
|
||||||
static CFDictionaryRef original_mode;
|
static CFDictionaryRef original_mode;
|
||||||
static bool initialized = false;
|
static bool initialized = false;
|
||||||
|
static bool display_captured = false;
|
||||||
|
|
||||||
static void saveMode(JNIEnv *env, long width, long height, long bpp, long freq) {
|
static void saveMode(JNIEnv *env, long width, long height, long bpp, long freq) {
|
||||||
jclass display_class = env->FindClass("org/lwjgl/Display");
|
jclass display_class = env->FindClass("org/lwjgl/Display");
|
||||||
|
@ -76,9 +79,23 @@ static void init(JNIEnv *env) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void captureDisplay(void) {
|
||||||
|
if (!display_captured) {
|
||||||
|
display_captured = true;
|
||||||
|
CGDisplayCapture(kCGDirectMainDisplay);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void releaseDisplay(void) {
|
||||||
|
if (display_captured) {
|
||||||
|
display_captured = false;
|
||||||
|
CGDisplayRelease(kCGDirectMainDisplay);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void switchMode(JNIEnv *env, long width, long height, long bpp, long freq) {
|
void switchMode(JNIEnv *env, long width, long height, long bpp, long freq) {
|
||||||
init(env);
|
init(env);
|
||||||
CGDisplayCapture(kCGDirectMainDisplay);
|
captureDisplay();
|
||||||
CFDictionaryRef displayMode = CGDisplayBestModeForParametersAndRefreshRate(kCGDirectMainDisplay, bpp, width, height, freq, NULL);
|
CFDictionaryRef displayMode = CGDisplayBestModeForParametersAndRefreshRate(kCGDirectMainDisplay, bpp, width, height, freq, NULL);
|
||||||
CGDisplaySwitchToMode(kCGDirectMainDisplay, displayMode);
|
CGDisplaySwitchToMode(kCGDirectMainDisplay, displayMode);
|
||||||
saveMode(env, width, height, bpp, freq);
|
saveMode(env, width, height, bpp, freq);
|
||||||
|
@ -86,8 +103,9 @@ void switchMode(JNIEnv *env, long width, long height, long bpp, long freq) {
|
||||||
|
|
||||||
void resetMode(JNIEnv *env) {
|
void resetMode(JNIEnv *env) {
|
||||||
init(env);
|
init(env);
|
||||||
|
CGDisplayRestoreColorSyncSettings();
|
||||||
CGDisplaySwitchToMode(kCGDirectMainDisplay, original_mode);
|
CGDisplaySwitchToMode(kCGDirectMainDisplay, original_mode);
|
||||||
CGDisplayRelease(kCGDirectMainDisplay);
|
releaseDisplay();
|
||||||
saveOriginalMode(env);
|
saveOriginalMode(env);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -146,9 +164,15 @@ JNIEXPORT jint JNICALL Java_org_lwjgl_Display_getPlatform(JNIEnv * env, jclass c
|
||||||
}
|
}
|
||||||
|
|
||||||
JNIEXPORT jint JNICALL Java_org_lwjgl_Display_getGammaRampLength(JNIEnv *env, jclass clazz) {
|
JNIEXPORT jint JNICALL Java_org_lwjgl_Display_getGammaRampLength(JNIEnv *env, jclass clazz) {
|
||||||
|
return GAMMARAMP_LENGTH;
|
||||||
}
|
}
|
||||||
|
|
||||||
JNIEXPORT jboolean JNICALL Java_org_lwjgl_Display_setGammaRamp(JNIEnv *env, jclass clazz, jobject gamma_ramp_buffer) {
|
JNIEXPORT void JNICALL Java_org_lwjgl_Display_setGammaRamp(JNIEnv *env, jclass clazz, jobject gamma_ramp_buffer) {
|
||||||
|
const float *gamma_ramp = (const float *)env->GetDirectBufferAddress(gamma_ramp_buffer);
|
||||||
|
CGDisplayErr err = CGSetDisplayTransferByTable(kCGDirectMainDisplay, GAMMARAMP_LENGTH, gamma_ramp, gamma_ramp, gamma_ramp);
|
||||||
|
if (err) {
|
||||||
|
throwException(env, "Could not set gamma.");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
JNIEXPORT void JNICALL Java_org_lwjgl_Display_resetDisplayMode(JNIEnv *env, jclass clazz) {
|
JNIEXPORT void JNICALL Java_org_lwjgl_Display_resetDisplayMode(JNIEnv *env, jclass clazz) {
|
||||||
|
|
|
@ -391,7 +391,7 @@ JNIEXPORT jint JNICALL Java_org_lwjgl_Display_getGammaRampLength
|
||||||
* Method: setGammaRamp
|
* Method: setGammaRamp
|
||||||
* Signature: (I)Z
|
* Signature: (I)Z
|
||||||
*/
|
*/
|
||||||
JNIEXPORT jboolean JNICALL Java_org_lwjgl_Display_setGammaRamp
|
JNIEXPORT void JNICALL Java_org_lwjgl_Display_setGammaRamp
|
||||||
(JNIEnv * env, jclass clazz, jobject gammaRampBuffer)
|
(JNIEnv * env, jclass clazz, jobject gammaRampBuffer)
|
||||||
{
|
{
|
||||||
const float *gammaRamp = (const float *)env->GetDirectBufferAddress(gammaRampBuffer);
|
const float *gammaRamp = (const float *)env->GetDirectBufferAddress(gammaRampBuffer);
|
||||||
|
@ -404,24 +404,15 @@ JNIEXPORT jboolean JNICALL Java_org_lwjgl_Display_setGammaRamp
|
||||||
currentGamma[i + 256] = rampEntry;
|
currentGamma[i + 256] = rampEntry;
|
||||||
currentGamma[i + 512] = rampEntry;
|
currentGamma[i + 512] = rampEntry;
|
||||||
}
|
}
|
||||||
jboolean ret;
|
|
||||||
HDC screenDC = GetDC(NULL);
|
HDC screenDC = GetDC(NULL);
|
||||||
try {
|
try {
|
||||||
if (SetDeviceGammaRamp(screenDC, currentGamma) == FALSE) {
|
if (SetDeviceGammaRamp(screenDC, currentGamma) == FALSE) {
|
||||||
#ifdef _DEBUG
|
throwException(env, "Failed to set device gamma.")
|
||||||
printf("Failed to set device gamma\n");
|
|
||||||
#endif
|
|
||||||
ret = JNI_FALSE;
|
|
||||||
} else {
|
|
||||||
ret = JNI_TRUE;
|
|
||||||
}
|
}
|
||||||
} catch (...) {
|
} catch (...) {
|
||||||
printf("Exception occurred in SetDeviceGammaRamp\n");
|
throwException(env, "Exception occurred in SetDeviceGammaRamp.")
|
||||||
ret = JNI_FALSE;
|
|
||||||
}
|
}
|
||||||
ReleaseDC(NULL, screenDC);
|
ReleaseDC(NULL, screenDC);
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue