aboutsummaryrefslogtreecommitdiffstats
path: root/libgamma_x_vidmode_get_crtc_information.c
diff options
context:
space:
mode:
authorMattias Andrée <maandree@kth.se>2021-03-05 18:23:13 +0100
committerMattias Andrée <maandree@kth.se>2021-03-05 18:33:49 +0100
commitf52513b09580c1533e6c48a4162d3d5f61f3b081 (patch)
tree141d0974a777f4ec5b51daed9879a2cb0d781505 /libgamma_x_vidmode_get_crtc_information.c
parentSplit source files, merge public header files, eliminite use gpp, rewrite makefile (diff)
downloadlibgamma-f52513b09580c1533e6c48a4162d3d5f61f3b081.tar.gz
libgamma-f52513b09580c1533e6c48a4162d3d5f61f3b081.tar.bz2
libgamma-f52513b09580c1533e6c48a4162d3d5f61f3b081.tar.xz
misc
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to 'libgamma_x_vidmode_get_crtc_information.c')
-rw-r--r--libgamma_x_vidmode_get_crtc_information.c55
1 files changed, 55 insertions, 0 deletions
diff --git a/libgamma_x_vidmode_get_crtc_information.c b/libgamma_x_vidmode_get_crtc_information.c
new file mode 100644
index 0000000..8462b1b
--- /dev/null
+++ b/libgamma_x_vidmode_get_crtc_information.c
@@ -0,0 +1,55 @@
+/* See LICENSE file for copyright and license details. */
+#include "common.h"
+
+
+/**
+ * Read information about a CRTC
+ *
+ * @param this Instance of a data structure to fill with the information about the CRTC
+ * @param crtc The state of the CRTC whose information should be read
+ * @param fields OR:ed identifiers for the information about the CRTC that should be read
+ * @return Zero on success, -1 on error; oOn error refer to the error reports in `this`
+ */
+int
+libgamma_x_vidmode_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)
+
+ Display *restrict connection;
+ int stops = 0;
+
+ /* X VidMode does not support EDID or monitor dimensions */
+ this->edid_error = _E(LIBGAMMA_CRTC_INFO_EDID);
+ this->width_mm_error = _E(LIBGAMMA_CRTC_INFO_WIDTH_MM);
+ this->height_mm_error = _E(LIBGAMMA_CRTC_INFO_HEIGHT_MM);
+ this->width_mm_edid_error = _E(LIBGAMMA_CRTC_INFO_WIDTH_MM_EDID);
+ this->height_mm_edid_error = _E(LIBGAMMA_CRTC_INFO_HEIGHT_MM_EDID);
+ this->gamma_size_error = 0;
+ /* X VidMode does support gamma ramp size query. The gamma
+ ramps are identical but not fixed, and the query can fail. */
+ if ((fields & LIBGAMMA_CRTC_INFO_GAMMA_SIZE)) {
+ connection = crtc->partition->site->data;
+ if (!XF86VidModeGetGammaRampSize(connection, (int)crtc->partition->partition, &stops))
+ this->gamma_size_error = LIBGAMMA_GAMMA_RAMPS_SIZE_QUERY_FAILED;
+ else if (stops < 2)
+ this->gamma_size_error = LIBGAMMA_SINGLETON_GAMMA_RAMP;
+ this->red_gamma_size = this->green_gamma_size = this->blue_gamma_size = (size_t)stops;
+ }
+ /* X VidMode uses 16-bit integer ramps */
+ this->gamma_depth = 16;
+ this->gamma_depth_error = 0;
+ /* X VidMode does not support gamma ramp support queries */
+ this->gamma_support_error = _E(LIBGAMMA_CRTC_INFO_GAMMA_SUPPORT);
+ /* X VidMode does not support EDID or connector information */
+ this->subpixel_order_error = _E(LIBGAMMA_CRTC_INFO_SUBPIXEL_ORDER);
+ this->active_error = _E(LIBGAMMA_CRTC_INFO_ACTIVE);
+ this->connector_name_error = _E(LIBGAMMA_CRTC_INFO_CONNECTOR_NAME);
+ this->connector_type_error = _E(LIBGAMMA_CRTC_INFO_CONNECTOR_TYPE);
+ this->gamma_error = _E(LIBGAMMA_CRTC_INFO_GAMMA);
+
+ /* We failed if gamma ramp size query failed or if an unsupport field was queried. */
+ return (this->gamma_size_error || (fields & ~(LIBGAMMA_CRTC_INFO_GAMMA_DEPTH | LIBGAMMA_CRTC_INFO_GAMMA_SIZE))) ? -1 : 0;
+
+#undef _E
+}