aboutsummaryrefslogtreecommitdiffstats
path: root/libgamma_get_crtc_information.c
blob: 58011dd012d889754317d91276bad78a101030bb (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
/* 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   size    Should be `sizeof(*this)`, used to let the library know which version
 *                  of the structure is used so that it does not write outside of it
 * @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_get_crtc_information(libgamma_crtc_information_t *restrict this, size_t size,
                              libgamma_crtc_state_t *restrict crtc, unsigned long long fields)
{
	libgamma_crtc_information_t info_;
	int r, (*func)(libgamma_crtc_information_t *restrict, libgamma_crtc_state_t *restrict, unsigned long long);

	this->edid = NULL;
	this->connector_name = NULL;

	switch (crtc->partition->site->method) {
#define X(CONST, CNAME, ...)\
	case CONST:\
		func = libgamma_##CNAME##_get_crtc_information;\
		break;
	LIST_AVAILABLE_METHODS(X)
#undef X
	default:
		return LIBGAMMA_NO_SUCH_ADJUSTMENT_METHOD;
	}

	if (size == sizeof(info_)) {
		r = func(this, crtc, fields);
		this->struct_version = LIBGAMMA_CRTC_INFORMATION_STRUCT_VERSION;
		return r;
	} else {
		info_.struct_version = LIBGAMMA_CRTC_INFORMATION_STRUCT_VERSION;
		r = func(&info_, crtc, fields);
		if (size < sizeof(info_)) {
			memcpy(this, &info_, size);
		} else {
			memcpy(this, &info_, sizeof(info_));
			memset(&((char *)this)[size], 0, size - sizeof(info_));
		}
		return r;
	}
}