aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMattias Andrée <maandree@operamail.com>2014-05-21 23:38:55 +0200
committerMattias Andrée <maandree@operamail.com>2014-05-21 23:38:55 +0200
commit09afa14c7772e010733844574e27d07ea7fe5446 (patch)
treeadfab9bec5865c765f5a816fdd3c4a3499196ec3
parentmisc (diff)
downloadlibgamma-09afa14c7772e010733844574e27d07ea7fe5446.tar.gz
libgamma-09afa14c7772e010733844574e27d07ea7fe5446.tar.bz2
libgamma-09afa14c7772e010733844574e27d07ea7fe5446.tar.xz
misc awesomeness
Signed-off-by: Mattias Andrée <maandree@operamail.com>
Diffstat (limited to '')
-rw-r--r--Makefile2
-rw-r--r--src/gamma-dummy.c23
-rw-r--r--src/gamma-dummy.h16
-rw-r--r--src/gamma-helper.c193
-rw-r--r--src/gamma-helper.h149
-rw-r--r--src/gamma-linux-drm.c60
-rw-r--r--src/gamma-linux-drm.h16
-rw-r--r--src/gamma-quartz-cg.c66
-rw-r--r--src/gamma-quartz-cg.h16
-rw-r--r--src/gamma-w32-gdi.c158
-rw-r--r--src/gamma-w32-gdi.h16
-rw-r--r--src/gamma-x-randr.c98
-rw-r--r--src/gamma-x-randr.h16
-rw-r--r--src/gamma-x-vidmode.c64
-rw-r--r--src/gamma-x-vidmode.h16
-rw-r--r--src/libgamma-error.h49
-rw-r--r--src/libgamma-method.h26
17 files changed, 750 insertions, 234 deletions
diff --git a/Makefile b/Makefile
index 4b8ebb9..31ba47a 100644
--- a/Makefile
+++ b/Makefile
@@ -62,7 +62,7 @@ C_FLAGS = $(OPTIMISE) $(WARN) -std=$(STD) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) \
# Object files for the library.
-LIBOBJ = libgamma-facade
+LIBOBJ = libgamma-facade gamma-helper
# Include configurations from `./configure`.
diff --git a/src/gamma-dummy.c b/src/gamma-dummy.c
index e7f1309..ba3c55a 100644
--- a/src/gamma-dummy.c
+++ b/src/gamma-dummy.c
@@ -22,6 +22,7 @@
#include "gamma-dummy.h"
#include "libgamma-error.h"
+#include "gamma-helper.h"
/**
@@ -102,17 +103,6 @@ void libgamma_dummy_partition_destroy(libgamma_partition_state_t* restrict this)
/**
- * Release all resources held by a partition state
- * and free the partition state pointer
- *
- * @param this The partition state
- */
-void libgamma_dummy_partition_free(libgamma_partition_state_t* restrict this)
-{
-}
-
-
-/**
* Restore the gamma ramps all CRTCS with a partition to the system settings
*
* @param this The partition state
@@ -151,17 +141,6 @@ void libgamma_dummy_crtc_destroy(libgamma_crtc_state_t* restrict this)
/**
- * Release all resources held by a CRTC state
- * and free the CRTC state pointer
- *
- * @param this The CRTC state
- */
-void libgamma_dummy_crtc_free(libgamma_crtc_state_t* restrict this)
-{
-}
-
-
-/**
* Restore the gamma ramps for a CRTC to the system settings for that CRTC
*
* @param this The CRTC state
diff --git a/src/gamma-dummy.h b/src/gamma-dummy.h
index e825381..ae0b4f9 100644
--- a/src/gamma-dummy.h
+++ b/src/gamma-dummy.h
@@ -87,14 +87,6 @@ int libgamma_dummy_partition_initialise(libgamma_partition_state_t* restrict thi
void libgamma_dummy_partition_destroy(libgamma_partition_state_t* restrict this);
/**
- * Release all resources held by a partition state
- * and free the partition state pointer
- *
- * @param this The partition state
- */
-void libgamma_dummy_partition_free(libgamma_partition_state_t* restrict this);
-
-/**
* Restore the gamma ramps all CRTCS with a partition to the system settings
*
* @param this The partition state
@@ -124,14 +116,6 @@ int libgamma_dummy_crtc_initialise(libgamma_crtc_state_t* restrict this,
void libgamma_dummy_crtc_destroy(libgamma_crtc_state_t* restrict this);
/**
- * Release all resources held by a CRTC state
- * and free the CRTC state pointer
- *
- * @param this The CRTC state
- */
-void libgamma_dummy_crtc_free(libgamma_crtc_state_t* restrict this);
-
-/**
* Restore the gamma ramps for a CRTC to the system settings for that CRTC
*
* @param this The CRTC state
diff --git a/src/gamma-helper.c b/src/gamma-helper.c
new file mode 100644
index 0000000..78a38fc
--- /dev/null
+++ b/src/gamma-helper.c
@@ -0,0 +1,193 @@
+/**
+ * libgamma — Display server abstraction layer for gamma ramp adjustments
+ * Copyright © 2014 Mattias Andrée (maandree@member.fsf.org)
+ *
+ * This library is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this library. If not, see <http://www.gnu.org/licenses/>.
+ */
+#include "gamma-helper.h"
+
+#include "libgamma-method.h"
+#include "libgamma-error.h"
+
+#include <errno.h>
+#include <stdlib.h>
+#include <stdint.h>
+
+
+#define ANY bits64
+
+/**
+ * Get current the gamma ramps for a CRTC, re-encoding version
+ *
+ * @param this The CRTC state
+ * @param ramps The gamma ramps to fill with the current values
+ * @param depth_user The depth of the gamma ramps that are provided by the user,
+ * `-1` for `float`, `-2` for `double`
+ * @param depth_system The depth of the gamma ramps as required by the adjustment method,
+ * `-1` for `float`, `-2` for `double`
+ * @param fun Function that is to be used read the ramps, its parameters have
+ * the same function as those of this function with the same names,
+ * and the return value too is identical
+ * @return Zero on success, otherwise (negative) the value of an
+ * error identifier provided by this library
+ */
+int libgamma_translated_ramp_get_(libgamma_crtc_state_t* restrict this,
+ libgamma_gamma_ramps_any_t* restrict ramps,
+ signed depth_user, signed depth_system,
+ libgamma_get_ramps_any_fun* fun)
+{
+ size_t n = ramps->ANY.red_size + ramps->ANY.green_size + ramps->ANY.blue_size;
+ size_t d, i;
+ int r, e;
+ libgamma_gamma_ramps_any_t ramps_sys;
+ uint64_t* ramps_full;
+
+ switch (depth_system)
+ {
+ case 16: d = sizeof(uint16_t); break;
+ case 32: d = sizeof(uint32_t); break;
+ case 64: d = sizeof(uint64_t); break;
+ case -1: d = sizeof(float); break;
+ case -2: d = sizeof(double); break;
+ default:
+ return errno = EINVAL, LIBGAMMA_ERRNO_SET;
+ }
+
+ ramps_sys.ANY. red_size = ramps->ANY. red_size;
+ ramps_sys.ANY.green_size = ramps->ANY.green_size;
+ ramps_sys.ANY. blue_size = ramps->ANY. blue_size;
+
+ ramps_sys.ANY.red = malloc(n * d);
+ ramps_sys.ANY.green = (void*)(((char*)(ramps_sys.ANY. red)) + ramps->ANY. red_size * d / sizeof(char));
+ ramps_sys.ANY.blue = (void*)(((char*)(ramps_sys.ANY.green)) + ramps->ANY.green_size * d / sizeof(char));
+ if (ramps_sys.ANY.red == NULL)
+ return LIBGAMMA_ERRNO_SET;
+
+ if ((r = fun(this, &ramps_sys)))
+ {
+ e = errno;
+ free(ramps_sys.ANY.red);
+ return errno = e, r;
+ }
+
+ ramps_full = malloc(n * sizeof(uint64_t));
+ if (ramps_full)
+ {
+ e = errno;
+ free(ramps_sys.ANY.red);
+ return errno = e, r;
+ }
+
+ switch (depth_system)
+ {
+ case 16:
+ for (i = 0; i < n; i++)
+ ramps_full[i] = (uint64_t)(ramps_sys.bits16.red[i]) * 0x0001000100010001ULL;
+ break;
+
+ case 32:
+ for (i = 0; i < n; i++)
+ ramps_full[i] = (uint64_t)(ramps_sys.bits32.red[i]) * 0x0000000100000001ULL;
+ break;
+
+ case 64:
+ for (i = 0; i < n; i++)
+ ramps_full[i] = ramps_sys.bits64.red[i];
+ break;
+
+ case -1:
+ for (i = 0; i < n; i++)
+ ramps_full[i] = (uint64_t)(ramps_sys.float_single.red[i] * (float)UINT64_MAX);
+ break;
+
+ case -2:
+ for (i = 0; i < n; i++)
+ ramps_full[i] = (uint64_t)(ramps_sys.float_double.red[i] * (double)UINT64_MAX);
+ break;
+
+ default: /* This is not possible. */
+ abort();
+ break;
+ }
+
+ free(ramps_sys.ANY.red);
+
+ if ((0 < depth_user) && (depth_user < 64))
+ for (i = 0; i < n; i++)
+ {
+ ramps_full[i] >>= (64 - depth_user - 1);
+ ramps_full[i] = (ramps_full[i] & 1) | (ramps_full[i] >> 1);
+ }
+
+ switch (depth_user)
+ {
+ case 16:
+ for (i = 0; i < n; i++)
+ ramps->bits16.red[i] = (uint16_t)(ramps_full[i]);
+ break;
+
+ case 32:
+ for (i = 0; i < n; i++)
+ ramps->bits32.red[i] = (uint32_t)(ramps_full[i]);
+ break;
+
+ case 64:
+ for (i = 0; i < n; i++)
+ ramps->bits64.red[i] = ramps_full[i];
+ break;
+
+ case -1:
+ for (i = 0; i < n; i++)
+ ramps->float_single.red[i] = (float)(ramps_full[i]) / (float)UINT64_MAX;
+ break;
+
+ case -2:
+ for (i = 0; i < n; i++)
+ ramps->float_double.red[i] = (double)(ramps_full[i]) / (double)UINT64_MAX;
+ break;
+
+ default: /* This is not possible. */
+ abort();
+ break;
+ }
+
+ free(ramps_full);
+ return 0;
+}
+
+
+/**
+ * Set the gamma ramps for a CRTC, re-encoding version
+ *
+ * @param this The CRTC state
+ * @param ramps The gamma ramps to apply
+ * @param depth_user The depth of the gamma ramps that are provided by the user,
+ * `-1` for `float`, `-2` for `double`
+ * @param depth_system The depth of the gamma ramps as required by the adjustment method,
+ * `-1` for `float`, `-2` for `double`
+ * @param fun Function that is to be used write the ramps, its parameters have
+ * the same function as those of this function with the same names,
+ * and the return value too is identical
+ * @return Zero on success, otherwise (negative) the value of an
+ * error identifier provided by this library
+ */
+int libgamma_translated_ramp_set_(libgamma_crtc_state_t* restrict this,
+ libgamma_gamma_ramps_any_t ramps,
+ signed depth_user, signed depth_system,
+ libgamma_set_ramps_any_fun* fun)
+{
+}
+
+#undef ANY
+
diff --git a/src/gamma-helper.h b/src/gamma-helper.h
new file mode 100644
index 0000000..00eaa85
--- /dev/null
+++ b/src/gamma-helper.h
@@ -0,0 +1,149 @@
+/**
+ * libgamma — Display server abstraction layer for gamma ramp adjustments
+ * Copyright © 2014 Mattias Andrée (maandree@member.fsf.org)
+ *
+ * This library is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this library. If not, see <http://www.gnu.org/licenses/>.
+ */
+#ifndef LIBGAMMA_GAMMA_HELPER_H
+#define LIBGAMMA_GAMMA_HELPER_H
+
+
+#include "libgamma-method.h"
+
+
+/**
+ * Gamma ramp structure union for different depths
+ */
+typedef union libgamma_gamma_ramps_any
+{
+ /**
+ * 16-bit gamma ramps
+ */
+ libgamma_gamma_ramps_t bits16;
+
+ /**
+ * 32-bit gamma ramps
+ */
+ libgamma_gamma_ramps32_t bits32;
+
+ /**
+ * 64-bit gamma ramps
+ */
+ libgamma_gamma_ramps64_t bits64;
+
+ /**
+ * Single precision float gamma ramps
+ */
+ libgamma_gamma_rampsf_t float_single;
+
+ /**
+ * Double precision float gamma ramps
+ */
+ libgamma_gamma_rampsd_t float_double;
+
+} libgamma_gamma_ramps_any_t;
+
+
+typedef int libgamma_get_ramps_any_fun(libgamma_crtc_state_t* restrict this,
+ libgamma_gamma_ramps_any_t* restrict ramps);
+
+typedef int libgamma_set_ramps_any_fun(libgamma_crtc_state_t* restrict this,
+ libgamma_gamma_ramps_any_t ramps);
+
+
+
+/**
+ * Get current the gamma ramps for a CRTC, re-encoding version
+ *
+ * @param this The CRTC state
+ * @param ramps The gamma ramps to fill with the current values
+ * @param depth_user The depth of the gamma ramps that are provided by the user,
+ * `-1` for `float`, `-2` for `double`
+ * @param depth_system The depth of the gamma ramps as required by the adjustment method,
+ * `-1` for `float`, `-2` for `double`
+ * @param fun Function that is to be used read the ramps, its parameters have
+ * the same function as those of this function with the same names,
+ * and the return value too is identical
+ * @return Zero on success, otherwise (negative) the value of an
+ * error identifier provided by this library
+ */
+#define libgamma_translated_ramp_get(this, ramps, depth_user, depth_system, fun) \
+ libgamma_translated_ramp_get_(this, (libgamma_gamma_ramps_any_t*)(ramps), depth_user, depth_system, \
+ (libgamma_get_ramps_any_fun*)(fun))
+
+
+/**
+ * Set the gamma ramps for a CRTC, re-encoding version
+ *
+ * @param this The CRTC state
+ * @param ramps The gamma ramps to apply
+ * @param depth_user The depth of the gamma ramps that are provided by the user,
+ * `-1` for `float`, `-2` for `double`
+ * @param depth_system The depth of the gamma ramps as required by the adjustment method,
+ * `-1` for `float`, `-2` for `double`
+ * @param fun Function that is to be used write the ramps, its parameters have
+ * the same function as those of this function with the same names,
+ * and the return value too is identical
+ * @return Zero on success, otherwise (negative) the value of an
+ * error identifier provided by this library
+ */
+#define libgamma_translated_ramp_set(this, ramps, depth_user, depth_system, fun) \
+ libgamma_translated_ramp_set_(this, (libgamma_gamma_ramps_any_t)(ramps), depth_user, depth_system, \
+ (libgamma_set_ramps_any_fun*)(fun))
+
+
+/**
+ * Get current the gamma ramps for a CRTC, re-encoding version
+ *
+ * @param this The CRTC state
+ * @param ramps The gamma ramps to fill with the current values
+ * @param depth_user The depth of the gamma ramps that are provided by the user,
+ * `-1` for `float`, `-2` for `double`
+ * @param depth_system The depth of the gamma ramps as required by the adjustment method,
+ * `-1` for `float`, `-2` for `double`
+ * @param fun Function that is to be used read the ramps, its parameters have
+ * the same function as those of this function with the same names,
+ * and the return value too is identical
+ * @return Zero on success, otherwise (negative) the value of an
+ * error identifier provided by this library
+ */
+int libgamma_translated_ramp_get_(libgamma_crtc_state_t* restrict this,
+ libgamma_gamma_ramps_any_t* restrict ramps,
+ signed depth_user, signed depth_system,
+ libgamma_get_ramps_any_fun* fun);
+
+
+/**
+ * Set the gamma ramps for a CRTC, re-encoding version
+ *
+ * @param this The CRTC state
+ * @param ramps The gamma ramps to apply
+ * @param depth_user The depth of the gamma ramps that are provided by the user,
+ * `-1` for `float`, `-2` for `double`
+ * @param depth_system The depth of the gamma ramps as required by the adjustment method,
+ * `-1` for `float`, `-2` for `double`
+ * @param fun Function that is to be used write the ramps, its parameters have
+ * the same function as those of this function with the same names,
+ * and the return value too is identical
+ * @return Zero on success, otherwise (negative) the value of an
+ * error identifier provided by this library
+ */
+int libgamma_translated_ramp_set_(libgamma_crtc_state_t* restrict this,
+ libgamma_gamma_ramps_any_t ramps,
+ signed depth_user, signed depth_system,
+ libgamma_set_ramps_any_fun* fun);
+
+
+#endif
+
diff --git a/src/gamma-linux-drm.c b/src/gamma-linux-drm.c
index f6b40a8..f33e07a 100644
--- a/src/gamma-linux-drm.c
+++ b/src/gamma-linux-drm.c
@@ -22,6 +22,9 @@
#include "gamma-linux-drm.h"
#include "libgamma-error.h"
+#include "gamma-helper.h"
+
+#include <errno.h>
/**
@@ -31,6 +34,30 @@
*/
void libgamma_linux_drm_method_capabilities(libgamma_method_capabilities_t* restrict this)
{
+ this->crtc_information = CRTC_INFO_EDID
+ | CRTC_INFO_WIDTH_MM
+ | CRTC_INFO_HEIGHT_MM
+ | CRTC_INFO_WIDTH_MM_EDID
+ | CRTC_INFO_HEIGHT_MM_EDID
+ | CRTC_INFO_GAMMA_SIZE
+ | CRTC_INFO_GAMMA_DEPTH
+ | CRTC_INFO_SUBPIXEL_ORDER
+ | CRTC_INFO_CONNECTOR_NAME
+ | CRTC_INFO_CONNECTOR_TYPE
+ | CRTC_INFO_GAMMA;
+ this->default_site_known = NULL;
+ this->multiple_sites = 0;
+ this->multiple_partitions = 1;
+ this->multiple_crtcs = 1;
+ this->partitions_are_graphics_cards = 1;
+ this->site_restore = 0;
+ this->partition_restore = 0;
+ this->crtc_restore = 0;
+ this->identical_gamma_sizes = 1;
+ this->fixed_gamma_size = 0;
+ this->fixed_gamma_depth = 1;
+ this->real = 1;
+ this->fake = 0;
}
@@ -72,6 +99,8 @@ void libgamma_linux_drm_site_destroy(libgamma_site_state_t* restrict this)
*/
int libgamma_linux_drm_site_restore(libgamma_site_state_t* restrict this)
{
+ (void) this;
+ return errno = ENOTSUP, LIBGAMMA_ERRNO_SET;
}
@@ -102,17 +131,6 @@ void libgamma_linux_drm_partition_destroy(libgamma_partition_state_t* restrict t
/**
- * Release all resources held by a partition state
- * and free the partition state pointer
- *
- * @param this The partition state
- */
-void libgamma_linux_drm_partition_free(libgamma_partition_state_t* restrict this)
-{
-}
-
-
-/**
* Restore the gamma ramps all CRTCS with a partition to the system settings
*
* @param this The partition state
@@ -121,6 +139,8 @@ void libgamma_linux_drm_partition_free(libgamma_partition_state_t* restrict this
*/
int libgamma_linux_drm_partition_restore(libgamma_partition_state_t* restrict this)
{
+ (void) this;
+ return errno = ENOTSUP, LIBGAMMA_ERRNO_SET;
}
@@ -170,6 +190,8 @@ void libgamma_linux_drm_crtc_free(libgamma_crtc_state_t* restrict this)
*/
int libgamma_linux_drm_crtc_restore(libgamma_crtc_state_t* restrict this)
{
+ (void) this;
+ return errno = ENOTSUP, LIBGAMMA_ERRNO_SET;
}
@@ -228,6 +250,8 @@ int libgamma_linux_drm_crtc_set_gamma_ramps(libgamma_crtc_state_t* restrict this
int libgamma_linux_drm_crtc_get_gamma_ramps32(libgamma_crtc_state_t* restrict this,
libgamma_gamma_ramps32_t* restrict ramps)
{
+ return libgamma_translated_ramp_get(this, ramps, 32, 16,
+ libgamma_linux_drm_crtc_get_gamma_ramps);
}
@@ -242,6 +266,8 @@ int libgamma_linux_drm_crtc_get_gamma_ramps32(libgamma_crtc_state_t* restrict th
int libgamma_linux_drm_crtc_set_gamma_ramps32(libgamma_crtc_state_t* restrict this,
libgamma_gamma_ramps32_t ramps)
{
+ return libgamma_translated_ramp_set(this, ramps, 32, 16,
+ libgamma_linux_drm_crtc_set_gamma_ramps);
}
@@ -257,6 +283,8 @@ int libgamma_linux_drm_crtc_set_gamma_ramps32(libgamma_crtc_state_t* restrict th
int libgamma_linux_drm_crtc_get_gamma_ramps64(libgamma_crtc_state_t* restrict this,
libgamma_gamma_ramps64_t* restrict ramps)
{
+ return libgamma_translated_ramp_get(this, ramps, 64, 16,
+ libgamma_linux_drm_crtc_get_gamma_ramps);
}
@@ -271,6 +299,8 @@ int libgamma_linux_drm_crtc_get_gamma_ramps64(libgamma_crtc_state_t* restrict th
int libgamma_linux_drm_crtc_set_gamma_ramps64(libgamma_crtc_state_t* restrict this,
libgamma_gamma_ramps64_t ramps)
{
+ return libgamma_translated_ramp_set(this, ramps, 64, 16,
+ libgamma_linux_drm_crtc_set_gamma_ramps);
}
@@ -286,6 +316,8 @@ int libgamma_linux_drm_crtc_set_gamma_ramps64(libgamma_crtc_state_t* restrict th
int libgamma_linux_drm_crtc_get_gamma_rampsf(libgamma_crtc_state_t* restrict this,
libgamma_gamma_rampsf_t* restrict ramps)
{
+ return libgamma_translated_ramp_get(this, ramps, -1, 16,
+ libgamma_linux_drm_crtc_get_gamma_ramps);
}
@@ -300,6 +332,8 @@ int libgamma_linux_drm_crtc_get_gamma_rampsf(libgamma_crtc_state_t* restrict thi
int libgamma_linux_drm_crtc_set_gamma_rampsf(libgamma_crtc_state_t* restrict this,
libgamma_gamma_rampsf_t ramps)
{
+ return libgamma_translated_ramp_set(this, ramps, -1, 16,
+ libgamma_linux_drm_crtc_set_gamma_ramps);
}
@@ -314,6 +348,8 @@ int libgamma_linux_drm_crtc_set_gamma_rampsf(libgamma_crtc_state_t* restrict thi
int libgamma_linux_drm_crtc_get_gamma_rampsd(libgamma_crtc_state_t* restrict this,
libgamma_gamma_rampsd_t* restrict ramps)
{
+ return libgamma_translated_ramp_get(this, ramps, -2, 16,
+ libgamma_linux_drm_crtc_get_gamma_ramps);
}
@@ -328,5 +364,7 @@ int libgamma_linux_drm_crtc_get_gamma_rampsd(libgamma_crtc_state_t* restrict thi
int libgamma_linux_drm_crtc_set_gamma_rampsd(libgamma_crtc_state_t* restrict this,
libgamma_gamma_rampsd_t ramps)
{
+ return libgamma_translated_ramp_set(this, ramps, -2, 16,
+ libgamma_linux_drm_crtc_set_gamma_ramps);
}
diff --git a/src/gamma-linux-drm.h b/src/gamma-linux-drm.h
index 6ac5134..fb34eab 100644
--- a/src/gamma-linux-drm.h
+++ b/src/gamma-linux-drm.h
@@ -87,14 +87,6 @@ int libgamma_linux_drm_partition_initialise(libgamma_partition_state_t* restrict
void libgamma_linux_drm_partition_destroy(libgamma_partition_state_t* restrict this);
/**
- * Release all resources held by a partition state
- * and free the partition state pointer
- *
- * @param this The partition state
- */
-void libgamma_linux_drm_partition_free(libgamma_partition_state_t* restrict this);
-
-/**
* Restore the gamma ramps all CRTCS with a partition to the system settings
*
* @param this The partition state
@@ -124,14 +116,6 @@ int libgamma_linux_drm_crtc_initialise(libgamma_crtc_state_t* restrict this,
void libgamma_linux_drm_crtc_destroy(libgamma_crtc_state_t* restrict this);
/**
- * Release all resources held by a CRTC state
- * and free the CRTC state pointer
- *
- * @param this The CRTC state
- */
-void libgamma_linux_drm_crtc_free(libgamma_crtc_state_t* restrict this);
-
-/**
* Restore the gamma ramps for a CRTC to the system settings for that CRTC
*
* @param this The CRTC state
diff --git a/src/gamma-quartz-cg.c b/src/gamma-quartz-cg.c
index bb4e307..582b12a 100644
--- a/src/gamma-quartz-cg.c
+++ b/src/gamma-quartz-cg.c
@@ -22,6 +22,7 @@
#include "gamma-quartz-cg.h"
#include "libgamma-error.h"
+#include "gamma-helper.h"
/**
@@ -31,6 +32,30 @@
*/
void libgamma_quartz_cg_method_capabilities(libgamma_method_capabilities_t* restrict this)
{
+ this->crtc_information = CRTC_INFO_GAMMA_SIZE
+ | CRTC_INFO_GAMMA_DEPTH;
+ this->default_site_known = NULL;
+ this->multiple_sites = 0;
+ this->multiple_partitions = 0;
+ this->multiple_crtcs = 1;
+ this->partitions_are_graphics_cards = 0;
+ this->site_restore = 1;
+ this->partition_restore = 1;
+ this->crtc_restore = 0;
+ this->identical_gamma_sizes = 1;
+ this->fixed_gamma_size = 0;
+ this->fixed_gamma_depth = 1;
+#ifdef FAKE_GAMMA_METHOD_QUARTZ_CORE_GRAPHICS
+ this->fake = 1;
+# ifdef HAVE_GAMMA_METHOD_X_RANDR
+ this->real = 1;
+# else
+ this->real = 0;
+# endif
+#else
+ this->fake = 0;
+ this->real = 1;
+#endif
}
@@ -102,17 +127,6 @@ void libgamma_quartz_cg_partition_destroy(libgamma_partition_state_t* restrict t
/**
- * Release all resources held by a partition state
- * and free the partition state pointer
- *
- * @param this The partition state
- */
-void libgamma_quartz_cg_partition_free(libgamma_partition_state_t* restrict this)
-{
-}
-
-
-/**
* Restore the gamma ramps all CRTCS with a partition to the system settings
*
* @param this The partition state
@@ -121,6 +135,7 @@ void libgamma_quartz_cg_partition_free(libgamma_partition_state_t* restrict this
*/
int libgamma_quartz_cg_partition_restore(libgamma_partition_state_t* restrict this)
{
+ return libgamma_quartz_cg_site_restore(this->site);
}
@@ -151,17 +166,6 @@ void libgamma_quartz_cg_crtc_destroy(libgamma_crtc_state_t* restrict this)
/**
- * Release all resources held by a CRTC state
- * and free the CRTC state pointer
- *
- * @param this The CRTC state
- */
-void libgamma_quartz_cg_crtc_free(libgamma_crtc_state_t* restrict this)
-{
-}
-
-
-/**
* Restore the gamma ramps for a CRTC to the system settings for that CRTC
*
* @param this The CRTC state
@@ -170,6 +174,8 @@ void libgamma_quartz_cg_crtc_free(libgamma_crtc_state_t* restrict this)
*/
int libgamma_quartz_cg_crtc_restore(libgamma_crtc_state_t* restrict this)
{
+ (void) this;
+ return errno = ENOTSUP, LIBGAMMA_ERRNO_SET;
}
@@ -199,6 +205,8 @@ int libgamma_quartz_cg_get_crtc_information(libgamma_crtc_information_t* restric
int libgamma_quartz_cg_crtc_get_gamma_ramps(libgamma_crtc_state_t* restrict this,
libgamma_gamma_ramps_t* restrict ramps)
{
+ return libgamma_translated_ramp_get(this, ramps, 16, -1,
+ libgamma_quartz_cg_crtc_get_gamma_ramps);
}
@@ -213,6 +221,8 @@ int libgamma_quartz_cg_crtc_get_gamma_ramps(libgamma_crtc_state_t* restrict this
int libgamma_quartz_cg_crtc_set_gamma_ramps(libgamma_crtc_state_t* restrict this,
libgamma_gamma_ramps_t ramps)
{
+ return libgamma_translated_ramp_set(this, ramps, 16, -1,
+ libgamma_quartz_cg_crtc_set_gamma_ramps);
}
@@ -228,6 +238,8 @@ int libgamma_quartz_cg_crtc_set_gamma_ramps(libgamma_crtc_state_t* restrict this
int libgamma_quartz_cg_crtc_get_gamma_ramps32(libgamma_crtc_state_t* restrict this,
libgamma_gamma_ramps32_t* restrict ramps)
{
+ return libgamma_translated_ramp_get(this, ramps, 32, -1,
+ libgamma_quartz_cg_crtc_get_gamma_ramps);
}
@@ -242,6 +254,8 @@ int libgamma_quartz_cg_crtc_get_gamma_ramps32(libgamma_crtc_state_t* restrict th
int libgamma_quartz_cg_crtc_set_gamma_ramps32(libgamma_crtc_state_t* restrict this,
libgamma_gamma_ramps32_t ramps)
{
+ return libgamma_translated_ramp_set(this, ramps, 32, -1,
+ libgamma_quartz_cg_crtc_set_gamma_ramps);
}
@@ -257,6 +271,8 @@ int libgamma_quartz_cg_crtc_set_gamma_ramps32(libgamma_crtc_state_t* restrict th
int libgamma_quartz_cg_crtc_get_gamma_ramps64(libgamma_crtc_state_t* restrict this,
libgamma_gamma_ramps64_t* restrict ramps)
{
+ return libgamma_translated_ramp_get(this, ramps, 64, -1,
+ libgamma_quartz_cg_crtc_get_gamma_ramps);
}
@@ -271,6 +287,8 @@ int libgamma_quartz_cg_crtc_get_gamma_ramps64(libgamma_crtc_state_t* restrict th
int libgamma_quartz_cg_crtc_set_gamma_ramps64(libgamma_crtc_state_t* restrict this,
libgamma_gamma_ramps64_t ramps)
{
+ return libgamma_translated_ramp_set(this, ramps, 64, -1,
+ libgamma_quartz_cg_crtc_set_gamma_ramps);
}
@@ -314,6 +332,8 @@ int libgamma_quartz_cg_crtc_set_gamma_rampsf(libgamma_crtc_state_t* restrict thi
int libgamma_quartz_cg_crtc_get_gamma_rampsd(libgamma_crtc_state_t* restrict this,
libgamma_gamma_rampsd_t* restrict ramps)
{
+ return libgamma_translated_ramp_get(this, ramps, -2, -1,
+ libgamma_quartz_cg_crtc_get_gamma_ramps);
}
@@ -328,5 +348,7 @@ int libgamma_quartz_cg_crtc_get_gamma_rampsd(libgamma_crtc_state_t* restrict thi
int libgamma_quartz_cg_crtc_set_gamma_rampsd(libgamma_crtc_state_t* restrict this,
libgamma_gamma_rampsd_t ramps)
{
+ return libgamma_translated_ramp_set(this, ramps, -2, -1,
+ libgamma_quartz_cg_crtc_set_gamma_ramps);
}
diff --git a/src/gamma-quartz-cg.h b/src/gamma-quartz-cg.h
index f5f830c..74432b6 100644
--- a/src/gamma-quartz-cg.h
+++ b/src/gamma-quartz-cg.h
@@ -87,14 +87,6 @@ int libgamma_quartz_cg_partition_initialise(libgamma_partition_state_t* restrict
void libgamma_quartz_cg_partition_destroy(libgamma_partition_state_t* restrict this);
/**
- * Release all resources held by a partition state
- * and free the partition state pointer
- *
- * @param this The partition state
- */
-void libgamma_quartz_cg_partition_free(libgamma_partition_state_t* restrict this);
-
-/**
* Restore the gamma ramps all CRTCS with a partition to the system settings
*
* @param this The partition state
@@ -124,14 +116,6 @@ int libgamma_quartz_cg_crtc_initialise(libgamma_crtc_state_t* restrict this,
void libgamma_quartz_cg_crtc_destroy(libgamma_crtc_state_t* restrict this);
/**
- * Release all resources held by a CRTC state
- * and free the CRTC state pointer
- *
- * @param this The CRTC state
- */
-void libgamma_quartz_cg_crtc_free(libgamma_crtc_state_t* restrict this);
-
-/**
* Restore the gamma ramps for a CRTC to the system settings for that CRTC
*
* @param this The CRTC state
diff --git a/src/gamma-w32-gdi.c b/src/gamma-w32-gdi.c
index ac8592f..0819ac0 100644
--- a/src/gamma-w32-gdi.c
+++ b/src/gamma-w32-gdi.c
@@ -1,4 +1,4 @@
-/**
+x/**
* libgamma — Display server abstraction layer for gamma ramp adjustments
* Copyright © 2014 Mattias Andrée (maandree@member.fsf.org)
*
@@ -22,6 +22,19 @@
#include "gamma-w32-gdi.h"
#include "libgamma-error.h"
+#include "gamma-helper.h"
+
+#ifndef WINVER
+# define WINVER 0x0500
+#endif
+#ifdef FAKE_GAMMA_METHOD_W32_GDI
+# include "fake-w32-gdi.h"
+#else
+# include <windows.h>
+# include <wingdi.h>
+#endif
+
+#define GAMMA_RAMP_SIZE 256
/**
@@ -31,6 +44,31 @@
*/
void libgamma_w32_gdi_method_capabilities(libgamma_method_capabilities_t* restrict this)
{
+ this->crtc_information = CRTC_INFO_GAMMA_SIZE
+ | CRTC_INFO_GAMMA_DEPTH
+ | CRTC_INFO_GAMMA_SUPPORT;
+ this->default_site_known = NULL;
+ this->multiple_sites = 0;
+ this->multiple_partitions = 0;
+ this->multiple_crtcs = 1;
+ this->partitions_are_graphics_cards = 0;
+ this->site_restore = 0;
+ this->partition_restore = 0;
+ this->crtc_restore = 0;
+ this->identical_gamma_sizes = 1;
+ this->fixed_gamma_size = 1;
+ this->fixed_gamma_depth = 1;
+#ifdef FAKE_GAMMA_METHOD_W32_GDI
+ this->fake = 1;
+# ifdef HAVE_GAMMA_METHOD_X_RANDR
+ this->real = 1;
+# else
+ this->real = 0;
+# endif
+#else
+ this->fake = 0;
+ this->real = 1;
+#endif
}
@@ -50,6 +88,11 @@ void libgamma_w32_gdi_method_capabilities(libgamma_method_capabilities_t* restri
int libgamma_w32_gdi_site_initialise(libgamma_site_state_t* restrict this,
char* restrict site)
{
+ if (site != NULL)
+ return LIBGAMMA_NO_SUCH_SITE;
+
+ this->partitions_available = 1;
+ return 0;
}
@@ -60,6 +103,7 @@ int libgamma_w32_gdi_site_initialise(libgamma_site_state_t* restrict this,
*/
void libgamma_w32_gdi_site_destroy(libgamma_site_state_t* restrict this)
{
+ (void) this;
}
@@ -72,6 +116,8 @@ void libgamma_w32_gdi_site_destroy(libgamma_site_state_t* restrict this)
*/
int libgamma_w32_gdi_site_restore(libgamma_site_state_t* restrict this)
{
+ (void) this;
+ return errno = ENOTSUP, LIBGAMMA_ERRNO_SET;
}
@@ -88,6 +134,24 @@ int libgamma_w32_gdi_site_restore(libgamma_site_state_t* restrict this)
int libgamma_w32_gdi_partition_initialise(libgamma_partition_state_t* restrict this,
libgamma_site_state_t* restrict site, size_t partition)
{
+ DISPLAY_DEVICE display;
+
+ (void) site;
+
+ if (partition != 0)
+ return LIBGAMMA_NO_SUCH_PARTITION;
+
+ this->crtcs_available = 0;
+ display.cb = sizeof(DISPLAY_DEVICE);
+ for (;;)
+ {
+ if (!EnumDisplayDevices(NULL, this->crtcs_available, &display, 0))
+ break;
+ this->crtcs_available++;
+ if (this->crtcs_available == 0)
+ return LIBGAMMA_IMPOSSIBLE_AMOUNT;
+ }
+ return 0;
}
@@ -98,17 +162,7 @@ int libgamma_w32_gdi_partition_initialise(libgamma_partition_state_t* restrict t
*/
void libgamma_w32_gdi_partition_destroy(libgamma_partition_state_t* restrict this)
{
-}
-
-
-/**
- * Release all resources held by a partition state
- * and free the partition state pointer
- *
- * @param this The partition state
- */
-void libgamma_w32_gdi_partition_free(libgamma_partition_state_t* restrict this)
-{
+ (void) this;
}
@@ -121,6 +175,8 @@ void libgamma_w32_gdi_partition_free(libgamma_partition_state_t* restrict this)
*/
int libgamma_w32_gdi_partition_restore(libgamma_partition_state_t* restrict this)
{
+ (void) this;
+ return errno = ENOTSUP, LIBGAMMA_ERRNO_SET;
}
@@ -137,6 +193,22 @@ int libgamma_w32_gdi_partition_restore(libgamma_partition_state_t* restrict this
int libgamma_w32_gdi_crtc_initialise(libgamma_crtc_state_t* restrict this,
libgamma_partition_state_t* restrict partition, size_t crtc)
{
+ DISPLAY_DEVICE display;
+ HDC context;
+
+ (void) partition;
+
+ this->data = NULL;
+ display.cb = sizeof(DISPLAY_DEVICE);
+ if (!EnumDisplayDevices(NULL, crtc, &display, 0))
+ return LIBGAMMA_NO_SUCH_CRTC;
+ if (!(display.StateFlags & DISPLAY_DEVICE_ACTIVE))
+ return LIBGAMMA_CONNECTOR_DISABLED;
+ context = CreateDC(TEXT("DISPLAY"), display.DeviceName, NULL, NULL);
+ if (context == NULL)
+ return LIBGAMMA_OPEN_CRTC_FAILED;
+ this->data = context;
+ return 0;
}
@@ -147,17 +219,8 @@ int libgamma_w32_gdi_crtc_initialise(libgamma_crtc_state_t* restrict this,
*/
void libgamma_w32_gdi_crtc_destroy(libgamma_crtc_state_t* restrict this)
{
-}
-
-
-/**
- * Release all resources held by a CRTC state
- * and free the CRTC state pointer
- *
- * @param this The CRTC state
- */
-void libgamma_w32_gdi_crtc_free(libgamma_crtc_state_t* restrict this)
-{
+ if (this->data)
+ ReleaseDC(NULL, this->data);
}
@@ -170,6 +233,8 @@ void libgamma_w32_gdi_crtc_free(libgamma_crtc_state_t* restrict this)
*/
int libgamma_w32_gdi_crtc_restore(libgamma_crtc_state_t* restrict this)
{
+ (void) this;
+ return errno = ENOTSUP, LIBGAMMA_ERRNO_SET;
}
@@ -185,6 +250,31 @@ int libgamma_w32_gdi_crtc_restore(libgamma_crtc_state_t* restrict this)
int libgamma_w32_gdi_get_crtc_information(libgamma_crtc_information_t* restrict this,
libgamma_crtc_state_t* restrict crtc, int32_t fields)
{
+#define _E(FIELD) ((fields & FIELD) ? LIBGAMMA_CRTC_INFO_NOT_SUPPORTED : 0)
+
+ this->edid_error = _E(CRTC_INFO_EDID);
+ this->width_mm_error = _E(CRTC_INFO_WIDTH_MM);
+ this->height_mm_error = _E(CRTC_INFO_HEIGHT_MM);
+ this->width_mm_edid_error = _E(CRTC_INFO_WIDTH_MM_EDID);
+ this->height_mm_edid_error = _E(CRTC_INFO_HEIGHT_MM_EDID);
+ this->red_gamma_size = GAMMA_SIZE;
+ this->green_gamma_size = GAMMA_SIZE;
+ this->blue_gamma_size = GAMMA_SIZE;
+ this->gamma_size_error = 0;
+ this->gamma_depth = 16;
+ this->gamma_depth_error = 0;
+ if ((fields & CRTC_INFO_GAMMA_SUPPORT))
+ this->gamma_support = GetDeviceCaps(hDC, COLORMGMTCAPS) == CM_GAMMA_RAMP;
+ this->gamma_support_error = 0;
+ this->subpixel_order_error = _E(CRTC_INFO_SUBPIXEL_ORDER);
+ this->active_error = _E(CRTC_INFO_ACTIVE);
+ this->connector_name_error = _E(CRTC_INFO_CONNECTOR_NAME);
+ this->connector_type_error = _E(CRTC_INFO_CONNECTOR_TYPE);
+ this->gamma_error = _E(CRTC_INFO_GAMMA);
+
+#undef _E
+
+ return 0;
}
@@ -199,6 +289,9 @@ int libgamma_w32_gdi_get_crtc_information(libgamma_crtc_information_t* restrict
int libgamma_w32_gdi_crtc_get_gamma_ramps(libgamma_crtc_state_t* restrict this,
libgamma_gamma_ramps_t* restrict ramps)
{
+ if (!GetDeviceGammaRamp(this->data, ramps->red))
+ return LIBGAMMA_GAMMA_RAMP_READ_FAILED;
+ return 0;
}
@@ -213,6 +306,9 @@ int libgamma_w32_gdi_crtc_get_gamma_ramps(libgamma_crtc_state_t* restrict this,
int libgamma_w32_gdi_crtc_set_gamma_ramps(libgamma_crtc_state_t* restrict this,
libgamma_gamma_ramps_t ramps)
{
+ if (!SetDeviceGammaRamp(this->data, ramps.red))
+ return LIBGAMMA_GAMMA_RAMP_WRITE_FAILED;
+ return 0;
}
@@ -228,6 +324,8 @@ int libgamma_w32_gdi_crtc_set_gamma_ramps(libgamma_crtc_state_t* restrict this,
int libgamma_w32_gdi_crtc_get_gamma_ramps32(libgamma_crtc_state_t* restrict this,
libgamma_gamma_ramps32_t* restrict ramps)
{
+ return libgamma_translated_ramp_get(this, ramps, 32, 16,
+ libgamma_w32_gdi_crtc_get_gamma_ramps);
}
@@ -242,6 +340,8 @@ int libgamma_w32_gdi_crtc_get_gamma_ramps32(libgamma_crtc_state_t* restrict this
int libgamma_w32_gdi_crtc_set_gamma_ramps32(libgamma_crtc_state_t* restrict this,
libgamma_gamma_ramps32_t ramps)
{
+ return libgamma_translated_ramp_set(this, ramps, 32, 16,
+ libgamma_w32_gdi_crtc_set_gamma_ramps);
}
@@ -257,6 +357,8 @@ int libgamma_w32_gdi_crtc_set_gamma_ramps32(libgamma_crtc_state_t* restrict this
int libgamma_w32_gdi_crtc_get_gamma_ramps64(libgamma_crtc_state_t* restrict this,
libgamma_gamma_ramps64_t* restrict ramps)
{
+ return libgamma_translated_ramp_get(this, ramps, 64, 16,
+ libgamma_w32_gdi_crtc_get_gamma_ramps);
}
@@ -271,6 +373,8 @@ int libgamma_w32_gdi_crtc_get_gamma_ramps64(libgamma_crtc_state_t* restrict this
int libgamma_w32_gdi_crtc_set_gamma_ramps64(libgamma_crtc_state_t* restrict this,
libgamma_gamma_ramps64_t ramps)
{
+ return libgamma_translated_ramp_set(this, ramps, 64, 16,
+ libgamma_w32_gdi_crtc_set_gamma_ramps);
}
@@ -286,6 +390,8 @@ int libgamma_w32_gdi_crtc_set_gamma_ramps64(libgamma_crtc_state_t* restrict this
int libgamma_w32_gdi_crtc_get_gamma_rampsf(libgamma_crtc_state_t* restrict this,
libgamma_gamma_rampsf_t* restrict ramps)
{
+ return libgamma_translated_ramp_get(this, ramps, -1, 16,
+ libgamma_w32_gdi_crtc_get_gamma_ramps);
}
@@ -300,6 +406,8 @@ int libgamma_w32_gdi_crtc_get_gamma_rampsf(libgamma_crtc_state_t* restrict this,
int libgamma_w32_gdi_crtc_set_gamma_rampsf(libgamma_crtc_state_t* restrict this,
libgamma_gamma_rampsf_t ramps)
{
+ return libgamma_translated_ramp_set(this, ramps, -1, 16,
+ libgamma_w32_gdi_crtc_set_gamma_ramps);
}
@@ -314,6 +422,8 @@ int libgamma_w32_gdi_crtc_set_gamma_rampsf(libgamma_crtc_state_t* restrict this,
int libgamma_w32_gdi_crtc_get_gamma_rampsd(libgamma_crtc_state_t* restrict this,
libgamma_gamma_rampsd_t* restrict ramps)
{
+ return libgamma_translated_ramp_get(this, ramps, -2, 16,
+ libgamma_w32_gdi_crtc_get_gamma_ramps);
}
@@ -328,5 +438,7 @@ int libgamma_w32_gdi_crtc_get_gamma_rampsd(libgamma_crtc_state_t* restrict this,
int libgamma_w32_gdi_crtc_set_gamma_rampsd(libgamma_crtc_state_t* restrict this,
libgamma_gamma_rampsd_t ramps)
{
+ return libgamma_translated_ramp_set(this, ramps, -2, 16,
+ libgamma_w32_gdi_crtc_set_gamma_ramps);
}
diff --git a/src/gamma-w32-gdi.h b/src/gamma-w32-gdi.h
index 71a0a65..dacc1c7 100644
--- a/src/gamma-w32-gdi.h
+++ b/src/gamma-w32-gdi.h
@@ -87,14 +87,6 @@ int libgamma_w32_gdi_partition_initialise(libgamma_partition_state_t* restrict t
void libgamma_w32_gdi_partition_destroy(libgamma_partition_state_t* restrict this);
/**
- * Release all resources held by a partition state
- * and free the partition state pointer
- *
- * @param this The partition state
- */
-void libgamma_w32_gdi_partition_free(libgamma_partition_state_t* restrict this);
-
-/**
* Restore the gamma ramps all CRTCS with a partition to the system settings
*
* @param this The partition state
@@ -124,14 +116,6 @@ int libgamma_w32_gdi_crtc_initialise(libgamma_crtc_state_t* restrict this,
void libgamma_w32_gdi_crtc_destroy(libgamma_crtc_state_t* restrict this);
/**
- * Release all resources held by a CRTC state
- * and free the CRTC state pointer
- *
- * @param this The CRTC state
- */
-void libgamma_w32_gdi_crtc_free(libgamma_crtc_state_t* restrict this);
-
-/**
* Restore the gamma ramps for a CRTC to the system settings for that CRTC
*
* @param this The CRTC state
diff --git a/src/gamma-x-randr.c b/src/gamma-x-randr.c
index 5338e07..67e2a3b 100644
--- a/src/gamma-x-randr.c
+++ b/src/gamma-x-randr.c
@@ -22,6 +22,25 @@
#include "gamma-x-randr.h"
#include "libgamma-error.h"
+#include "gamma-helper.h"
+
+#include <stdlib.h>
+#include <errno.h>
+
+#include <xcb/xcb.h>
+#include <xcb/randr.h>
+
+
+/**
+ * The major version of RandR the library expects
+ */
+#define RANDR_VERSION_MAJOR 1
+
+/**
+ * The minor version of RandR the library expects
+ */
+#define RANDR_VERSION_MINOR 3
+
/**
@@ -31,6 +50,31 @@
*/
void libgamma_x_randr_method_capabilities(libgamma_method_capabilities_t* restrict this)
{
+ char* display = getenv("DISPLAY");
+ this->crtc_information = CRTC_INFO_EDID
+ | CRTC_INFO_WIDTH_MM
+ | CRTC_INFO_HEIGHT_MM
+ | CRTC_INFO_WIDTH_MM_EDID
+ | CRTC_INFO_HEIGHT_MM_EDID
+ | CRTC_INFO_GAMMA_SIZE
+ | CRTC_INFO_GAMMA_DEPTH
+ | CRTC_INFO_SUBPIXEL_ORDER
+ | CRTC_INFO_CONNECTOR_NAME
+ | CRTC_INFO_CONNECTOR_TYPE
+ | CRTC_INFO_GAMMA;
+ this->default_site_known = (display && *display) ? 1 : 0;
+ this->multiple_sites = 1;
+ this->multiple_partitions = 1;
+ this->multiple_crtcs = 1;
+ this->partitions_are_graphics_cards = 0;
+ this->site_restore = 0;
+ this->partition_restore = 0;
+ this->crtc_restore = 0;
+ this->identical_gamma_sizes = 1;
+ this->fixed_gamma_size = 0;
+ this->fixed_gamma_depth = 1;
+ this->real = 1;
+ this->fake = 0;
}
@@ -50,6 +94,7 @@ void libgamma_x_randr_method_capabilities(libgamma_method_capabilities_t* restri
int libgamma_x_randr_site_initialise(libgamma_site_state_t* restrict this,
char* restrict site)
{
+ /* TODO */
}
@@ -60,6 +105,7 @@ int libgamma_x_randr_site_initialise(libgamma_site_state_t* restrict this,
*/
void libgamma_x_randr_site_destroy(libgamma_site_state_t* restrict this)
{
+ /* TODO */
}
@@ -72,6 +118,8 @@ void libgamma_x_randr_site_destroy(libgamma_site_state_t* restrict this)
*/
int libgamma_x_randr_site_restore(libgamma_site_state_t* restrict this)
{
+ (void) this;
+ return errno = ENOTSUP, LIBGAMMA_ERRNO_SET;
}
@@ -88,6 +136,7 @@ int libgamma_x_randr_site_restore(libgamma_site_state_t* restrict this)
int libgamma_x_randr_partition_initialise(libgamma_partition_state_t* restrict this,
libgamma_site_state_t* restrict site, size_t partition)
{
+ /* TODO */
}
@@ -98,17 +147,7 @@ int libgamma_x_randr_partition_initialise(libgamma_partition_state_t* restrict t
*/
void libgamma_x_randr_partition_destroy(libgamma_partition_state_t* restrict this)
{
-}
-
-
-/**
- * Release all resources held by a partition state
- * and free the partition state pointer
- *
- * @param this The partition state
- */
-void libgamma_x_randr_partition_free(libgamma_partition_state_t* restrict this)
-{
+ /* TODO */
}
@@ -121,6 +160,8 @@ void libgamma_x_randr_partition_free(libgamma_partition_state_t* restrict this)
*/
int libgamma_x_randr_partition_restore(libgamma_partition_state_t* restrict this)
{
+ (void) this;
+ return errno = ENOTSUP, LIBGAMMA_ERRNO_SET;
}
@@ -137,6 +178,7 @@ int libgamma_x_randr_partition_restore(libgamma_partition_state_t* restrict this
int libgamma_x_randr_crtc_initialise(libgamma_crtc_state_t* restrict this,
libgamma_partition_state_t* restrict partition, size_t crtc)
{
+ /* TODO */
}
@@ -147,17 +189,7 @@ int libgamma_x_randr_crtc_initialise(libgamma_crtc_state_t* restrict this,
*/
void libgamma_x_randr_crtc_destroy(libgamma_crtc_state_t* restrict this)
{
-}
-
-
-/**
- * Release all resources held by a CRTC state
- * and free the CRTC state pointer
- *
- * @param this The CRTC state
- */
-void libgamma_x_randr_crtc_free(libgamma_crtc_state_t* restrict this)
-{
+ /* TODO */
}
@@ -170,6 +202,8 @@ void libgamma_x_randr_crtc_free(libgamma_crtc_state_t* restrict this)
*/
int libgamma_x_randr_crtc_restore(libgamma_crtc_state_t* restrict this)
{
+ (void) this;
+ return errno = ENOTSUP, LIBGAMMA_ERRNO_SET;
}
@@ -185,6 +219,7 @@ int libgamma_x_randr_crtc_restore(libgamma_crtc_state_t* restrict this)
int libgamma_x_randr_get_crtc_information(libgamma_crtc_information_t* restrict this,
libgamma_crtc_state_t* restrict crtc, int32_t fields)
{
+ /* TODO */
}
@@ -199,6 +234,7 @@ int libgamma_x_randr_get_crtc_information(libgamma_crtc_information_t* restrict
int libgamma_x_randr_crtc_get_gamma_ramps(libgamma_crtc_state_t* restrict this,
libgamma_gamma_ramps_t* restrict ramps)
{
+ /* TODO */
}
@@ -213,6 +249,7 @@ int libgamma_x_randr_crtc_get_gamma_ramps(libgamma_crtc_state_t* restrict this,
int libgamma_x_randr_crtc_set_gamma_ramps(libgamma_crtc_state_t* restrict this,
libgamma_gamma_ramps_t ramps)
{
+ /* TODO */
}
@@ -228,6 +265,8 @@ int libgamma_x_randr_crtc_set_gamma_ramps(libgamma_crtc_state_t* restrict this,
int libgamma_x_randr_crtc_get_gamma_ramps32(libgamma_crtc_state_t* restrict this,
libgamma_gamma_ramps32_t* restrict ramps)
{
+ return libgamma_translated_ramp_get(this, ramps, 32, 16,
+ libgamma_x_randr_crtc_get_gamma_ramps);
}
@@ -242,6 +281,8 @@ int libgamma_x_randr_crtc_get_gamma_ramps32(libgamma_crtc_state_t* restrict this
int libgamma_x_randr_crtc_set_gamma_ramps32(libgamma_crtc_state_t* restrict this,
libgamma_gamma_ramps32_t ramps)
{
+ return libgamma_translated_ramp_set(this, ramps, 32, 16,
+ libgamma_x_randr_crtc_set_gamma_ramps);
}
@@ -257,6 +298,8 @@ int libgamma_x_randr_crtc_set_gamma_ramps32(libgamma_crtc_state_t* restrict this
int libgamma_x_randr_crtc_get_gamma_ramps64(libgamma_crtc_state_t* restrict this,
libgamma_gamma_ramps64_t* restrict ramps)
{
+ return libgamma_translated_ramp_get(this, ramps, 64, 16,
+ libgamma_x_randr_crtc_get_gamma_ramps);
}
@@ -271,6 +314,8 @@ int libgamma_x_randr_crtc_get_gamma_ramps64(libgamma_crtc_state_t* restrict this
int libgamma_x_randr_crtc_set_gamma_ramps64(libgamma_crtc_state_t* restrict this,
libgamma_gamma_ramps64_t ramps)
{
+ return libgamma_translated_ramp_set(this, ramps, 64, 16,
+ libgamma_x_randr_crtc_set_gamma_ramps);
}
@@ -286,6 +331,8 @@ int libgamma_x_randr_crtc_set_gamma_ramps64(libgamma_crtc_state_t* restrict this
int libgamma_x_randr_crtc_get_gamma_rampsf(libgamma_crtc_state_t* restrict this,
libgamma_gamma_rampsf_t* restrict ramps)
{
+ return libgamma_translated_ramp_get(this, ramps, -1, 16,
+ libgamma_x_randr_crtc_get_gamma_ramps);
}
@@ -300,9 +347,12 @@ int libgamma_x_randr_crtc_get_gamma_rampsf(libgamma_crtc_state_t* restrict this,
int libgamma_x_randr_crtc_set_gamma_rampsf(libgamma_crtc_state_t* restrict this,
libgamma_gamma_rampsf_t ramps)
{
+ return libgamma_translated_ramp_set(this, ramps, -1, 16,
+ libgamma_x_randr_crtc_set_gamma_ramps);
}
+
/**
* Get current the gamma ramps for a CRTC, `double` version
*
@@ -314,6 +364,8 @@ int libgamma_x_randr_crtc_set_gamma_rampsf(libgamma_crtc_state_t* restrict this,
int libgamma_x_randr_crtc_get_gamma_rampsd(libgamma_crtc_state_t* restrict this,
libgamma_gamma_rampsd_t* restrict ramps)
{
+ return libgamma_translated_ramp_get(this, ramps, -2, 16,
+ libgamma_x_randr_crtc_get_gamma_ramps);
}
@@ -328,5 +380,7 @@ int libgamma_x_randr_crtc_get_gamma_rampsd(libgamma_crtc_state_t* restrict this,
int libgamma_x_randr_crtc_set_gamma_rampsd(libgamma_crtc_state_t* restrict this,
libgamma_gamma_rampsd_t ramps)
{
+ return libgamma_translated_ramp_set(this, ramps, -2, 16,
+ libgamma_x_randr_crtc_set_gamma_ramps);
}
diff --git a/src/gamma-x-randr.h b/src/gamma-x-randr.h
index cc4ddde..009e107 100644
--- a/src/gamma-x-randr.h
+++ b/src/gamma-x-randr.h
@@ -87,14 +87,6 @@ int libgamma_x_randr_partition_initialise(libgamma_partition_state_t* restrict t
void libgamma_x_randr_partition_destroy(libgamma_partition_state_t* restrict this);
/**
- * Release all resources held by a partition state
- * and free the partition state pointer
- *
- * @param this The partition state
- */
-void libgamma_x_randr_partition_free(libgamma_partition_state_t* restrict this);
-
-/**
* Restore the gamma ramps all CRTCS with a partition to the system settings
*
* @param this The partition state
@@ -124,14 +116,6 @@ int libgamma_x_randr_crtc_initialise(libgamma_crtc_state_t* restrict this,
void libgamma_x_randr_crtc_destroy(libgamma_crtc_state_t* restrict this);
/**
- * Release all resources held by a CRTC state
- * and free the CRTC state pointer
- *
- * @param this The CRTC state
- */
-void libgamma_x_randr_crtc_free(libgamma_crtc_state_t* restrict this);
-
-/**
* Restore the gamma ramps for a CRTC to the system settings for that CRTC
*
* @param this The CRTC state
diff --git a/src/gamma-x-vidmode.c b/src/gamma-x-vidmode.c
index 739c386..aa9a75d 100644
--- a/src/gamma-x-vidmode.c
+++ b/src/gamma-x-vidmode.c
@@ -22,6 +22,9 @@
#include "gamma-x-vidmode.h"
#include "libgamma-error.h"
+#include "gamma-helper.h"
+
+#include <errno.h>
/**
@@ -31,6 +34,22 @@
*/
void libgamma_x_vidmode_method_capabilities(libgamma_method_capabilities_t* restrict this)
{
+ char* display = getenv("DISPLAY");
+ this->crtc_information = CRTC_INFO_GAMMA_SIZE
+ | CRTC_INFO_GAMMA_DEPTH;
+ this->default_site_known = (display && *display);
+ this->multiple_sites = 1;
+ this->multiple_partitions = 1;
+ this->multiple_crtcs = 1;
+ this->partitions_are_graphics_cards = 0;
+ this->site_restore = 0;
+ this->partition_restore = 0;
+ this->crtc_restore = 0;
+ this->identical_gamma_sizes = 1;
+ this->fixed_gamma_size = 0;
+ this->fixed_gamma_depth = 1;
+ this->real = 1;
+ this->fake = 0;
}
@@ -72,6 +91,8 @@ void libgamma_x_vidmode_site_destroy(libgamma_site_state_t* restrict this)
*/
int libgamma_x_vidmode_site_restore(libgamma_site_state_t* restrict this)
{
+ (void) this;
+ return errno = ENOTSUP, LIBGAMMA_ERRNO_SET;
}
@@ -102,17 +123,6 @@ void libgamma_x_vidmode_partition_destroy(libgamma_partition_state_t* restrict t
/**
- * Release all resources held by a partition state
- * and free the partition state pointer
- *
- * @param this The partition state
- */
-void libgamma_x_vidmode_partition_free(libgamma_partition_state_t* restrict this)
-{
-}
-
-
-/**
* Restore the gamma ramps all CRTCS with a partition to the system settings
*
* @param this The partition state
@@ -121,6 +131,8 @@ void libgamma_x_vidmode_partition_free(libgamma_partition_state_t* restrict this
*/
int libgamma_x_vidmode_partition_restore(libgamma_partition_state_t* restrict this)
{
+ (void) this;
+ return errno = ENOTSUP, LIBGAMMA_ERRNO_SET;
}
@@ -151,17 +163,6 @@ void libgamma_x_vidmode_crtc_destroy(libgamma_crtc_state_t* restrict this)
/**
- * Release all resources held by a CRTC state
- * and free the CRTC state pointer
- *
- * @param this The CRTC state
- */
-void libgamma_x_vidmode_crtc_free(libgamma_crtc_state_t* restrict this)
-{
-}
-
-
-/**
* Restore the gamma ramps for a CRTC to the system settings for that CRTC
*
* @param this The CRTC state
@@ -170,6 +171,8 @@ void libgamma_x_vidmode_crtc_free(libgamma_crtc_state_t* restrict this)
*/
int libgamma_x_vidmode_crtc_restore(libgamma_crtc_state_t* restrict this)
{
+ (void) this;
+ return errno = ENOTSUP, LIBGAMMA_ERRNO_SET;
}
@@ -228,6 +231,8 @@ int libgamma_x_vidmode_crtc_set_gamma_ramps(libgamma_crtc_state_t* restrict this
int libgamma_x_vidmode_crtc_get_gamma_ramps32(libgamma_crtc_state_t* restrict this,
libgamma_gamma_ramps32_t* restrict ramps)
{
+ return libgamma_translated_ramp_get(this, ramps, 32, 16,
+ libgamma_x_vidmode_crtc_get_gamma_ramps);
}
@@ -242,6 +247,8 @@ int libgamma_x_vidmode_crtc_get_gamma_ramps32(libgamma_crtc_state_t* restrict th
int libgamma_x_vidmode_crtc_set_gamma_ramps32(libgamma_crtc_state_t* restrict this,
libgamma_gamma_ramps32_t ramps)
{
+ return libgamma_translated_ramp_set(this, ramps, 32, 16,
+ libgamma_x_vidmode_crtc_set_gamma_ramps);
}
@@ -257,6 +264,8 @@ int libgamma_x_vidmode_crtc_set_gamma_ramps32(libgamma_crtc_state_t* restrict th
int libgamma_x_vidmode_crtc_get_gamma_ramps64(libgamma_crtc_state_t* restrict this,
libgamma_gamma_ramps64_t* restrict ramps)
{
+ return libgamma_translated_ramp_get(this, ramps, 64, 16,
+ libgamma_x_vidmode_crtc_get_gamma_ramps);
}
@@ -271,6 +280,8 @@ int libgamma_x_vidmode_crtc_get_gamma_ramps64(libgamma_crtc_state_t* restrict th
int libgamma_x_vidmode_crtc_set_gamma_ramps64(libgamma_crtc_state_t* restrict this,
libgamma_gamma_ramps64_t ramps)
{
+ return libgamma_translated_ramp_set(this, ramps, 64, 16,
+ libgamma_x_vidmode_crtc_set_gamma_ramps);
}
@@ -286,6 +297,8 @@ int libgamma_x_vidmode_crtc_set_gamma_ramps64(libgamma_crtc_state_t* restrict th
int libgamma_x_vidmode_crtc_get_gamma_rampsf(libgamma_crtc_state_t* restrict this,
libgamma_gamma_rampsf_t* restrict ramps)
{
+ return libgamma_translated_ramp_get(this, ramps, -1, 16,
+ libgamma_x_vidmode_crtc_get_gamma_ramps);
}
@@ -300,9 +313,12 @@ int libgamma_x_vidmode_crtc_get_gamma_rampsf(libgamma_crtc_state_t* restrict thi
int libgamma_x_vidmode_crtc_set_gamma_rampsf(libgamma_crtc_state_t* restrict this,
libgamma_gamma_rampsf_t ramps)
{
+ return libgamma_translated_ramp_set(this, ramps, -1, 16,
+ libgamma_x_vidmode_crtc_set_gamma_ramps);
}
+
/**
* Get current the gamma ramps for a CRTC, `double` version
*
@@ -314,6 +330,8 @@ int libgamma_x_vidmode_crtc_set_gamma_rampsf(libgamma_crtc_state_t* restrict thi
int libgamma_x_vidmode_crtc_get_gamma_rampsd(libgamma_crtc_state_t* restrict this,
libgamma_gamma_rampsd_t* restrict ramps)
{
+ return libgamma_translated_ramp_get(this, ramps, -2, 16,
+ libgamma_x_vidmode_crtc_get_gamma_ramps);
}
@@ -328,5 +346,7 @@ int libgamma_x_vidmode_crtc_get_gamma_rampsd(libgamma_crtc_state_t* restrict thi
int libgamma_x_vidmode_crtc_set_gamma_rampsd(libgamma_crtc_state_t* restrict this,
libgamma_gamma_rampsd_t ramps)
{
+ return libgamma_translated_ramp_set(this, ramps, -2, 16,
+ libgamma_x_vidmode_crtc_set_gamma_ramps);
}
diff --git a/src/gamma-x-vidmode.h b/src/gamma-x-vidmode.h
index 670e06d..2f3e2cd 100644
--- a/src/gamma-x-vidmode.h
+++ b/src/gamma-x-vidmode.h
@@ -87,14 +87,6 @@ int libgamma_x_vidmode_partition_initialise(libgamma_partition_state_t* restrict
void libgamma_x_vidmode_partition_destroy(libgamma_partition_state_t* restrict this);
/**
- * Release all resources held by a partition state
- * and free the partition state pointer
- *
- * @param this The partition state
- */
-void libgamma_x_vidmode_partition_free(libgamma_partition_state_t* restrict this);
-
-/**
* Restore the gamma ramps all CRTCS with a partition to the system settings
*
* @param this The partition state
@@ -124,14 +116,6 @@ int libgamma_x_vidmode_crtc_initialise(libgamma_crtc_state_t* restrict this,
void libgamma_x_vidmode_crtc_destroy(libgamma_crtc_state_t* restrict this);
/**
- * Release all resources held by a CRTC state
- * and free the CRTC state pointer
- *
- * @param this The CRTC state
- */
-void libgamma_x_vidmode_crtc_free(libgamma_crtc_state_t* restrict this);
-
-/**
* Restore the gamma ramps for a CRTC to the system settings for that CRTC
*
* @param this The CRTC state
diff --git a/src/libgamma-error.h b/src/libgamma-error.h
index d17eac8..639d59f 100644
--- a/src/libgamma-error.h
+++ b/src/libgamma-error.h
@@ -27,13 +27,58 @@
* The selected adjustment method does not exist
* or has been excluded at compile-time
*/
-#define LIBGAMMA_NO_SUCH_ADJUSTMENT_METHOD -1
+#define LIBGAMMA_NO_SUCH_ADJUSTMENT_METHOD (-1)
/**
* `errno` has be set with a standard error number
* to indicate the what has gone wrong
*/
-#define LIBGAMMA_ERRNO_SET -2
+#define LIBGAMMA_ERRNO_SET (-2)
+
+/**
+ * The selected site does not exist
+ */
+#define LIBGAMMA_NO_SUCH_SITE (-3)
+
+/**
+ * The selected partition does not exist
+ */
+#define LIBGAMMA_NO_SUCH_PARTITION (-4)
+
+/**
+ * The selected CRTC does not exist
+ */
+#define LIBGAMMA_NO_SUCH_CRTC (-5)
+
+/**
+ * Counter overflowed when counting the number of available items
+ */
+#define LIBGAMMA_IMPOSSIBLE_AMOUNT (-6)
+
+/**
+ * The selected connector is disabled, it does not have a CRTC
+ */
+#define LIBGAMMA_CONNECTOR_DISABLED (-7)
+
+/**
+ * The selected CRTC could not be opened, reason unknown
+ */
+#define LIBGAMMA_OPEN_CRTC_FAILED (-8)
+
+/**
+ * The CRTC information field is not supported by the adjustment method
+ */
+#define LIBGAMMA_CRTC_INFO_NOT_SUPPORTED (-9)
+
+/**
+ * Failed to read the current gamma ramps for the selected CRTC, reason unknown
+ */
+#define LIBGAMMA_GAMMA_RAMP_READ_FAILED (-10)
+
+/**
+ * Failed to write the current gamma ramps for the selected CRTC, reason unknown
+ */
+#define LIBGAMMA_GAMMA_RAMP_WRITE_FAILED (-11)
#endif
diff --git a/src/libgamma-method.h b/src/libgamma-method.h
index 3fac0da..ec15f86 100644
--- a/src/libgamma-method.h
+++ b/src/libgamma-method.h
@@ -125,75 +125,75 @@ typedef struct libgamma_method_capabilities {
* Whether the default site is known, if true the site is integrated
* to the system or can be determined using environment variables
*/
- int default_site_known : 1;
+ unsigned default_site_known : 1;
/**
* Whether the adjustment method supports multiple sites rather
* than just the default site
*/
- int multiple_sites : 1;
+ unsigned multiple_sites : 1;
/**
* Whether the adjustment method supports multiple partitions
* per site
*/
- int multiple_partitions : 1;
+ unsigned multiple_partitions : 1;
/**
* Whether the adjustment method supports multiple CRTC:s
* per partition per site
*/
- int multiple_crtcs : 1;
+ unsigned multiple_crtcs : 1;
/**
* Whether the partition to graphics card is a bijection
*/
- int partitions_are_graphics_cards : 1;
+ unsigned partitions_are_graphics_cards : 1;
/**
* Whether the adjustment method supports `libgamma_site_restore`
*/
- int site_restore : 1;
+ unsigned site_restore : 1;
/**
* Whether the adjustment method supports `libgamma_partition_restore`
*/
- int partition_restore : 1;
+ unsigned partition_restore : 1;
/**
* Whether the adjustment method supports `libgamma_crtc_restore`
*/
- int crtc_restore : 1;
+ unsigned crtc_restore : 1;
/**
* Whether the `red_gamma_size`, `green_gamma_size` and `blue_gamma_size`
* fields in `libgamma_crtc_information_t` will always have the same
* values as each other for the adjustment method
*/
- int identical_gamma_sizes : 1;
+ unsigned identical_gamma_sizes : 1;
/**
* Whether the `red_gamma_size`, `green_gamma_size` and `blue_gamma_size`
* fields in `libgamma_crtc_information_t` will always be filled with the
* same value for the adjustment method
*/
- int fixed_gamma_size : 1;
+ unsigned fixed_gamma_size : 1;
/**
* Whether the `gamma_depth` field in `libgamma_crtc_information_t`
* will always be filled with the same value for the adjustment method
*/
- int fixed_gamma_depth : 1;
+ unsigned fixed_gamma_depth : 1;
/**
* Whether the adjustment method will actually perform adjustments
*/
- int real : 1;
+ unsigned real : 1;
/**
* Whether the adjustment method is implement using a translation layer
*/
- int fake : 1;
+ unsigned fake : 1;
} libgamma_method_capabilities_t;