aboutsummaryrefslogtreecommitdiffstats
path: root/libgamma_dummy_get_crtc_information.c
blob: 541ae7787e4533b0d1ab39a6491cf5b5dbf96e56 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/* See LICENSE file for copyright and license details. */
#define IN_LIBGAMMA_DUMMY
#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; on error refer to the error reports in `this`
 */
int
libgamma_dummy_get_crtc_information(struct libgamma_crtc_information *restrict this,
                                    struct libgamma_crtc_state *restrict crtc, unsigned long long fields)
{
	struct libgamma_dummy_crtc *restrict data = crtc->data;
	unsigned long long supported = libgamma_dummy_internal_configurations.capabilities.crtc_information;
	int e = 0;
	size_t n;

	/* Copy over information */
	*this = data->info;

	/* Duplicate strings */
	if (this->edid) {
		this->edid = malloc(this->edid_length * sizeof(char));
		if (!this->edid)
			this->edid_error = errno;
		memcpy(this->edid, data->info.edid, this->edid_length * sizeof(char));
	}
	if (this->connector_name) {
		n = strlen(this->connector_name);
		this->connector_name = malloc((n + 1) * sizeof(char));
		if (!this->connector_name)
			this->connector_name_error = errno;
		memcpy(this->connector_name, data->info.connector_name, (n + 1) * sizeof(char));
	}

	/* Parse EDID */
	if (this->edid_error)
		this->width_mm_edid_error = this->height_mm_edid_error = this->gamma_error = this->edid_error;
	else if (fields & (LIBGAMMA_CRTC_INFO_MACRO_EDID ^ LIBGAMMA_CRTC_INFO_EDID))
		e |= libgamma_internal_parse_edid(this, fields);

	/* Test errors */
#define _E(FIELD, VAR)\
	((fields & FIELD) ? ((supported & FIELD) ? VAR : (VAR = LIBGAMMA_CRTC_INFO_NOT_SUPPORTED)) : 0)
	e |= _E(LIBGAMMA_CRTC_INFO_EDID,           this->edid_error);
	e |= _E(LIBGAMMA_CRTC_INFO_WIDTH_MM,       this->width_mm_error);
	e |= _E(LIBGAMMA_CRTC_INFO_HEIGHT_MM,      this->height_mm_error);
	e |= _E(LIBGAMMA_CRTC_INFO_GAMMA_SIZE,     this->gamma_size_error);
	e |= _E(LIBGAMMA_CRTC_INFO_GAMMA_DEPTH,    this->gamma_depth_error);
	e |= _E(LIBGAMMA_CRTC_INFO_GAMMA_SUPPORT,  this->gamma_support_error);
	e |= _E(LIBGAMMA_CRTC_INFO_SUBPIXEL_ORDER, this->subpixel_order_error);
	e |= _E(LIBGAMMA_CRTC_INFO_ACTIVE,         this->active_error);
	e |= _E(LIBGAMMA_CRTC_INFO_CONNECTOR_NAME, this->connector_name_error);
	e |= _E(LIBGAMMA_CRTC_INFO_CONNECTOR_TYPE, this->connector_type_error);

	if ((fields & LIBGAMMA_CRTC_INFO_WIDTH_MM_EDID) && !(supported & LIBGAMMA_CRTC_INFO_WIDTH_MM_EDID))
		e |= this->width_mm_edid_error = LIBGAMMA_CRTC_INFO_NOT_SUPPORTED;
	if ((fields & LIBGAMMA_CRTC_INFO_HEIGHT_MM_EDID) && !(supported & LIBGAMMA_CRTC_INFO_HEIGHT_MM_EDID))
		e |= this->height_mm_edid_error = LIBGAMMA_CRTC_INFO_NOT_SUPPORTED;
	if ((fields & LIBGAMMA_CRTC_INFO_GAMMA) && !(supported & LIBGAMMA_CRTC_INFO_GAMMA))
		e |= this->gamma_error = LIBGAMMA_CRTC_INFO_NOT_SUPPORTED;
#undef _E

	return e ? -1 : 0;
}