summaryrefslogtreecommitdiff
path: root/libkms++/atomicreq.cpp
blob: 3346af9e53a808a232305143f5d02eca9fd1d702 (plain)
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
#include <cassert>

#include <xf86drm.h>
#include <xf86drmMode.h>

#include "atomicreq.h"
#include "property.h"
#include "card.h"

#ifndef DRM_CLIENT_CAP_ATOMIC

#define DRM_MODE_ATOMIC_TEST_ONLY 0

struct _drmModeAtomicReq;
typedef struct _drmModeAtomicReq* drmModeAtomicReqPtr;

static inline drmModeAtomicReqPtr drmModeAtomicAlloc() { return 0; }
static inline void drmModeAtomicFree(drmModeAtomicReqPtr) { }
static inline int drmModeAtomicAddProperty(drmModeAtomicReqPtr, uint32_t, uint32_t, uint64_t) { return 0; }
static inline int drmModeAtomicCommit(int, drmModeAtomicReqPtr, int, void*) { return 0; }

#endif // DRM_CLIENT_CAP_ATOMIC

namespace kms
{
AtomicReq::AtomicReq(Card& card)
	: m_card(card)
{
	assert(card.has_atomic());
	m_req = drmModeAtomicAlloc();
}

AtomicReq::~AtomicReq()
{
	drmModeAtomicFree(m_req);
}

void AtomicReq::add(uint32_t ob_id, uint32_t prop_id, uint64_t value)
{
	int r = drmModeAtomicAddProperty(m_req, ob_id, prop_id, value);
	if (r <= 0)
		throw std::invalid_argument("foo");
}

void AtomicReq::add(DrmObject *ob, Property *prop, uint64_t value)
{
	add(ob->id(), prop->id(), value);
}

int AtomicReq::test()
{
	uint32_t flags = DRM_MODE_ATOMIC_TEST_ONLY;

	return drmModeAtomicCommit(m_card.fd(), m_req, flags, 0);
}

int AtomicReq::commit()
{
	uint32_t flags = DRM_MODE_PAGE_FLIP_EVENT;
	void* data = 0;

	return drmModeAtomicCommit(m_card.fd(), m_req, flags, data);
}
}