diff options
author | Mattias Andrée <maandree@operamail.com> | 2014-09-05 03:07:03 +0200 |
---|---|---|
committer | Mattias Andrée <maandree@operamail.com> | 2014-09-05 03:07:03 +0200 |
commit | 482ed442d9d3c18adf3b3dcee694356e3ecb536e (patch) | |
tree | 2c332197ab95116b967c7641cda65548a60beaab /src/libgamma_CRTC.c | |
parent | implement c code for libgammaexception (diff) | |
download | jlibgamma-482ed442d9d3c18adf3b3dcee694356e3ecb536e.tar.gz jlibgamma-482ed442d9d3c18adf3b3dcee694356e3ecb536e.tar.bz2 jlibgamma-482ed442d9d3c18adf3b3dcee694356e3ecb536e.tar.xz |
implement c code for crtc
Signed-off-by: Mattias Andrée <maandree@operamail.com>
Diffstat (limited to 'src/libgamma_CRTC.c')
-rw-r--r-- | src/libgamma_CRTC.c | 283 |
1 files changed, 267 insertions, 16 deletions
diff --git a/src/libgamma_CRTC.c b/src/libgamma_CRTC.c index 947f5de..4146de6 100644 --- a/src/libgamma_CRTC.c +++ b/src/libgamma_CRTC.c @@ -17,6 +17,9 @@ */ #include "libgamma_CRTC.h" +#include <errno.h> +#include <stdlib.h> + #include <libgamma.h> @@ -25,6 +28,41 @@ /** + * Make a failure-return. + * + * @param error_code The error code returned from the failing function or zero to read `errno`. + * @return The object to return. + */ +static jlongArray fail(JNIEnv* env, int error_code) +{ + jlongArray rc = (*env)->NewLongArray(env, 2); + jlong e, z = 0; + if ((error_code == LIBGAMMA_ERRNO_SET) || !error_code) + error_code = errno; + e = (jlong)error_code; + (*env)->SetLongArrayRegion(env, rc, 0, 1, &z); + (*env)->SetLongArrayRegion(env, rc, 1, 1, &e); + return rc; +} + + +/** + * Make a success-return. + * + * @param state The native object. + * @return The object to return. + */ +static jlongArray ok(JNIEnv* env, void* state) +{ + jlong a = (jlong)(size_t)state, z = 0; + jlongArray rc = (*env)->NewLongArray(env, 2); + (*env)->SetLongArrayRegion(env, rc, 0, 1, &a); + (*env)->SetLongArrayRegion(env, rc, 1, 1, &z); + return rc; +} + + +/** * Create a CRTC state. * * @param partition The partition state for the partition that the CRTC belongs to. @@ -32,7 +70,19 @@ * @return Element 0: The value for {@link #address}. * Element 1: Error code, zero on success. */ -jlongArray Java_libgamma_CRTC_libgamma_1crtc_1create(J, jlong partition, jint crtc); +jlongArray Java_libgamma_CRTC_libgamma_1crtc_1create(J, jlong partition, jint crtc) +{ + libgamma_crtc_state_t* state = malloc(sizeof(libgamma_crtc_state_t)); + void* super = (void*)(size_t)partition; + int r; + if (state == NULL) + return fail(env, 0); + r = libgamma_crtc_initialise(state, super, crtc); + if (r != 0) + return fail(env, r); + return ok(env, state); + (void) class; +} /** @@ -41,7 +91,13 @@ jlongArray Java_libgamma_CRTC_libgamma_1crtc_1create(J, jlong partition, jint cr * * @param address The CRTC state. */ -void Java_libgamma_CRTC_libgamma_1crtc_1free(J, jlong address); +void Java_libgamma_CRTC_libgamma_1crtc_1free(J, jlong address) +{ + void* this = (void*)(size_t)address; + libgamma_crtc_free(this); + (void) env; + (void) class; +} /** @@ -50,7 +106,16 @@ void Java_libgamma_CRTC_libgamma_1crtc_1free(J, jlong address); * @param address The CRTC state. * @return Zero on success, and error code on failure. */ -jint Java_libgamma_CRTC_libgamma_1crtc_1restore(J, jlong address); +jint Java_libgamma_CRTC_libgamma_1crtc_1restore(J, jlong address) +{ + void* this = (void*)(size_t)address; + int r = libgamma_crtc_restore(this); + if (r != 0) + return r == LIBGAMMA_ERRNO_SET ? errno : r; + return 0; + (void) env; + (void) class; +} /** @@ -60,7 +125,73 @@ jint Java_libgamma_CRTC_libgamma_1crtc_1restore(J, jlong address); * @param fields OR:ed identifiers for the information about the CRTC that should be read. * @return Input parameters for the constructor of {@link CRTCInformation} */ -jobjectArray Java_libgamma_CRTC_libgamma_1get_1crtc_1information(J, jlong crtc, jint fields); +jobjectArray Java_libgamma_CRTC_libgamma_1get_1crtc_1information(J, jlong crtc, jint fields) +{ + void* this_voidp = (void*)(size_t)crtc; + libgamma_crtc_state_t* this = this_voidp; + jbyteArray edid = NULL; + jstring connector_name = NULL; + jclass class_of_jobject = (*env)->FindClass(env, "java/lang/Object"); + jintArray ints_ = (*env)->NewIntArray(env, 25); + jfloatArray gamma_ = (*env)->NewFloatArray(env, 3); + jobjectArray rc = (*env)->NewObjectArray(env, 4, class_of_jobject, NULL); + libgamma_crtc_information_t info; + jint ints[25]; + jfloat gamma[3]; + + libgamma_get_crtc_information(&info, this, fields); + + if (info.edid != NULL) + { + edid = (*env)->NewByteArray(env, info.edid_length); + (*env)->SetByteArrayRegion(env, edid, 0, info.edid_length, (const jbyte*)(info.edid)); + free(info.edid); + } + + if (connector_name != NULL) + connector_name = (*env)->NewStringUTF(env, info.connector_name); + + gamma[0] = (jfloat)info.gamma_red; + gamma[1] = (jfloat)info.gamma_green; + gamma[2] = (jfloat)info.gamma_blue; + + ints[0] = (jint)info.edid_error; + ints[1] = (jint)info.width_mm; + ints[2] = (jint)info.width_mm_error; + ints[3] = (jint)info.height_mm; + ints[4] = (jint)info.height_mm_error; + ints[5] = (jint)info.width_mm_edid; + ints[6] = (jint)info.width_mm_edid_error; + ints[7] = (jint)info.height_mm_edid; + ints[8] = (jint)info.height_mm_edid_error; + ints[9] = (jint)info.red_gamma_size; + ints[10] = (jint)info.green_gamma_size; + ints[11] = (jint)info.blue_gamma_size; + ints[12] = (jint)info.gamma_size_error; + ints[13] = (jint)info.gamma_depth; + ints[14] = (jint)info.gamma_depth_error; + ints[15] = (jint)info.gamma_support; + ints[16] = (jint)info.gamma_support_error; + ints[17] = (jint)info.subpixel_order; + ints[18] = (jint)info.subpixel_order_error; + ints[19] = (jint)info.active; + ints[20] = (jint)info.active_error; + ints[21] = (jint)info.connector_name_error; + ints[22] = (jint)info.connector_type; + ints[23] = (jint)info.connector_type_error; + ints[24] = (jint)info.gamma_error; + + (*env)->SetIntArrayRegion(env, ints_, 0, 25, ints); + (*env)->SetFloatArrayRegion(env, gamma_, 0, 3, gamma); + + (*env)->SetObjectArrayElement(env, rc, 0, edid); + (*env)->SetObjectArrayElement(env, rc, 1, connector_name); + (*env)->SetObjectArrayElement(env, rc, 2, gamma_); + (*env)->SetObjectArrayElement(env, rc, 3, ints_); + + return rc; + (void) class; +} @@ -71,7 +202,17 @@ jobjectArray Java_libgamma_CRTC_libgamma_1get_1crtc_1information(J, jlong crtc, * @param ramps The gamma ramps to fill with the current values * @return Zero on success, an error code on failure. */ -jint Java_libgamma_CRTC_libgamma_1crtc_1get_1gamma_1ramps8(J, jlong address, jlong ramps); +jint Java_libgamma_CRTC_libgamma_1crtc_1get_1gamma_1ramps8(J, jlong address, jlong ramps) +{ + void* crtc_voidp = (void*)(size_t)address; + libgamma_crtc_state_t* crtc = crtc_voidp; + void* output_voidp = (void*)(size_t)ramps; + libgamma_gamma_ramps8_t* output = output_voidp; + int r = libgamma_crtc_get_gamma_ramps8(crtc, output); + return r == LIBGAMMA_ERRNO_SET ? errno : r; + (void) env; + (void) class; +} /** @@ -81,7 +222,17 @@ jint Java_libgamma_CRTC_libgamma_1crtc_1get_1gamma_1ramps8(J, jlong address, jlo * @param ramps The gamma ramps to apply. * @return Zero on success, an error code on failure. */ -jint Java_libgamma_CRTC_libgamma_1crtc_1set_1gamma_1ramps8(J, jlong address, jlong ramps); +jint Java_libgamma_CRTC_libgamma_1crtc_1set_1gamma_1ramps8(J, jlong address, jlong ramps) +{ + void* crtc_voidp = (void*)(size_t)address; + libgamma_crtc_state_t* crtc = crtc_voidp; + void* values_voidp = (void*)(size_t)ramps; + libgamma_gamma_ramps8_t* values = values_voidp; + int r = libgamma_crtc_set_gamma_ramps8(crtc, *values); + return r == LIBGAMMA_ERRNO_SET ? errno : r; + (void) env; + (void) class; +} @@ -92,7 +243,17 @@ jint Java_libgamma_CRTC_libgamma_1crtc_1set_1gamma_1ramps8(J, jlong address, jlo * @param ramps The gamma ramps to fill with the current values * @return Zero on success, an error code on failure. */ -jint Java_libgamma_CRTC_libgamma_1crtc_1get_1gamma_1ramps16(J, jlong address, jlong ramps); +jint Java_libgamma_CRTC_libgamma_1crtc_1get_1gamma_1ramps16(J, jlong address, jlong ramps) +{ + void* crtc_voidp = (void*)(size_t)address; + libgamma_crtc_state_t* crtc = crtc_voidp; + void* output_voidp = (void*)(size_t)ramps; + libgamma_gamma_ramps16_t* output = output_voidp; + int r = libgamma_crtc_get_gamma_ramps16(crtc, output); + return r == LIBGAMMA_ERRNO_SET ? errno : r; + (void) env; + (void) class; +} /** @@ -102,7 +263,17 @@ jint Java_libgamma_CRTC_libgamma_1crtc_1get_1gamma_1ramps16(J, jlong address, jl * @param ramps The gamma ramps to apply. * @return Zero on success, an error code on failure. */ -jint Java_libgamma_CRTC_libgamma_1crtc_1set_1gamma_1ramps16(J, jlong address, jlong ramps); +jint Java_libgamma_CRTC_libgamma_1crtc_1set_1gamma_1ramps16(J, jlong address, jlong ramps) +{ + void* crtc_voidp = (void*)(size_t)address; + libgamma_crtc_state_t* crtc = crtc_voidp; + void* values_voidp = (void*)(size_t)ramps; + libgamma_gamma_ramps16_t* values = values_voidp; + int r = libgamma_crtc_set_gamma_ramps16(crtc, *values); + return r == LIBGAMMA_ERRNO_SET ? errno : r; + (void) env; + (void) class; +} @@ -113,7 +284,17 @@ jint Java_libgamma_CRTC_libgamma_1crtc_1set_1gamma_1ramps16(J, jlong address, jl * @param ramps The gamma ramps to fill with the current values. * @return Zero on success, an error code on failure. */ -jint Java_libgamma_CRTC_libgamma_1crtc_1get_1gamma_1ramps32(J, jlong address, jlong ramps); +jint Java_libgamma_CRTC_libgamma_1crtc_1get_1gamma_1ramps32(J, jlong address, jlong ramps) +{ + void* crtc_voidp = (void*)(size_t)address; + libgamma_crtc_state_t* crtc = crtc_voidp; + void* output_voidp = (void*)(size_t)ramps; + libgamma_gamma_ramps32_t* output = output_voidp; + int r = libgamma_crtc_get_gamma_ramps32(crtc, output); + return r == LIBGAMMA_ERRNO_SET ? errno : r; + (void) env; + (void) class; +} /** @@ -123,7 +304,17 @@ jint Java_libgamma_CRTC_libgamma_1crtc_1get_1gamma_1ramps32(J, jlong address, jl * @param ramps The gamma ramps to apply. * @return Zero on success, an error code on failure. */ -jint Java_libgamma_CRTC_libgamma_1crtc_1set_1gamma_1ramps32(J, jlong address, jlong ramps); +jint Java_libgamma_CRTC_libgamma_1crtc_1set_1gamma_1ramps32(J, jlong address, jlong ramps) +{ + void* crtc_voidp = (void*)(size_t)address; + libgamma_crtc_state_t* crtc = crtc_voidp; + void* values_voidp = (void*)(size_t)ramps; + libgamma_gamma_ramps32_t* values = values_voidp; + int r = libgamma_crtc_set_gamma_ramps32(crtc, *values); + return r == LIBGAMMA_ERRNO_SET ? errno : r; + (void) env; + (void) class; +} @@ -134,7 +325,17 @@ jint Java_libgamma_CRTC_libgamma_1crtc_1set_1gamma_1ramps32(J, jlong address, jl * @param ramps The gamma ramps to fill with the current values. * @return Zero on success, an error code on failure. */ -jint Java_libgamma_CRTC_libgamma_1crtc_1get_1gamma_1ramps64(J, jlong address, jlong ramps); +jint Java_libgamma_CRTC_libgamma_1crtc_1get_1gamma_1ramps64(J, jlong address, jlong ramps) +{ + void* crtc_voidp = (void*)(size_t)address; + libgamma_crtc_state_t* crtc = crtc_voidp; + void* output_voidp = (void*)(size_t)ramps; + libgamma_gamma_ramps64_t* output = output_voidp; + int r = libgamma_crtc_get_gamma_ramps64(crtc, output); + return r == LIBGAMMA_ERRNO_SET ? errno : r; + (void) env; + (void) class; +} /** @@ -144,7 +345,17 @@ jint Java_libgamma_CRTC_libgamma_1crtc_1get_1gamma_1ramps64(J, jlong address, jl * @param ramps The gamma ramps to apply. * @return Zero on success, an error code on failure. */ -jint Java_libgamma_CRTC_libgamma_1crtc_1set_1gamma_1ramps64(J, jlong address, jlong ramps); +jint Java_libgamma_CRTC_libgamma_1crtc_1set_1gamma_1ramps64(J, jlong address, jlong ramps) +{ + void* crtc_voidp = (void*)(size_t)address; + libgamma_crtc_state_t* crtc = crtc_voidp; + void* values_voidp = (void*)(size_t)ramps; + libgamma_gamma_ramps64_t* values = values_voidp; + int r = libgamma_crtc_set_gamma_ramps64(crtc, *values); + return r == LIBGAMMA_ERRNO_SET ? errno : r; + (void) env; + (void) class; +} @@ -155,7 +366,17 @@ jint Java_libgamma_CRTC_libgamma_1crtc_1set_1gamma_1ramps64(J, jlong address, jl * @param ramps The gamma ramps to apply. * @return Zero on success, an error code on failure. */ -jint Java_libgamma_CRTC_libgamma_1crtc_1set_1gamma_1rampsf(J, jlong address, jlong ramps); +jint Java_libgamma_CRTC_libgamma_1crtc_1set_1gamma_1rampsf(J, jlong address, jlong ramps) +{ + void* crtc_voidp = (void*)(size_t)address; + libgamma_crtc_state_t* crtc = crtc_voidp; + void* output_voidp = (void*)(size_t)ramps; + libgamma_gamma_rampsf_t* output = output_voidp; + int r = libgamma_crtc_get_gamma_rampsf(crtc, output); + return r == LIBGAMMA_ERRNO_SET ? errno : r; + (void) env; + (void) class; +} /** @@ -165,7 +386,17 @@ jint Java_libgamma_CRTC_libgamma_1crtc_1set_1gamma_1rampsf(J, jlong address, jlo * @param ramps The gamma ramps to fill with the current values. * @return Zero on success, an error code on failure. */ -jint Java_libgamma_CRTC_libgamma_1crtc_1get_1gamma_1rampsf(J, jlong address, jlong ramps); +jint Java_libgamma_CRTC_libgamma_1crtc_1get_1gamma_1rampsf(J, jlong address, jlong ramps) +{ + void* crtc_voidp = (void*)(size_t)address; + libgamma_crtc_state_t* crtc = crtc_voidp; + void* values_voidp = (void*)(size_t)ramps; + libgamma_gamma_rampsf_t* values = values_voidp; + int r = libgamma_crtc_set_gamma_rampsf(crtc, *values); + return r == LIBGAMMA_ERRNO_SET ? errno : r; + (void) env; + (void) class; +} @@ -176,7 +407,17 @@ jint Java_libgamma_CRTC_libgamma_1crtc_1get_1gamma_1rampsf(J, jlong address, jlo * @param ramps The gamma ramps to fill with the current values. * @return Zero on success, an error code on failure. */ -jint Java_libgamma_CRTC_libgamma_1crtc_1get_1gamma_1rampsd(J, jlong address, jlong ramps); +jint Java_libgamma_CRTC_libgamma_1crtc_1get_1gamma_1rampsd(J, jlong address, jlong ramps) +{ + void* crtc_voidp = (void*)(size_t)address; + libgamma_crtc_state_t* crtc = crtc_voidp; + void* output_voidp = (void*)(size_t)ramps; + libgamma_gamma_rampsd_t* output = output_voidp; + int r = libgamma_crtc_get_gamma_rampsd(crtc, output); + return r == LIBGAMMA_ERRNO_SET ? errno : r; + (void) env; + (void) class; +} /** @@ -186,5 +427,15 @@ jint Java_libgamma_CRTC_libgamma_1crtc_1get_1gamma_1rampsd(J, jlong address, jlo * @param ramps The gamma ramps to apply. * @return Zero on success, an error code on failure. */ -jint Java_libgamma_CRTC_libgamma_1crtc_1set_1gamma_1rampsd(J, jlong address, jlong ramps); +jint Java_libgamma_CRTC_libgamma_1crtc_1set_1gamma_1rampsd(J, jlong address, jlong ramps) +{ + void* crtc_voidp = (void*)(size_t)address; + libgamma_crtc_state_t* crtc = crtc_voidp; + void* values_voidp = (void*)(size_t)ramps; + libgamma_gamma_rampsd_t* values = values_voidp; + int r = libgamma_crtc_set_gamma_rampsd(crtc, *values); + return r == LIBGAMMA_ERRNO_SET ? errno : r; + (void) env; + (void) class; +} |