1 #include <cassert>
2 #include <stdexcept>
4 #include <xf86drm.h>
5 #include <xf86drmMode.h>
7 #include "atomicreq.h"
8 #include "property.h"
9 #include "card.h"
11 #ifndef DRM_CLIENT_CAP_ATOMIC
13 #define DRM_MODE_ATOMIC_TEST_ONLY 0
14 #define DRM_MODE_ATOMIC_NONBLOCK 0
16 struct _drmModeAtomicReq;
17 typedef struct _drmModeAtomicReq* drmModeAtomicReqPtr;
19 static inline drmModeAtomicReqPtr drmModeAtomicAlloc() { return 0; }
20 static inline void drmModeAtomicFree(drmModeAtomicReqPtr) { }
21 static inline int drmModeAtomicAddProperty(drmModeAtomicReqPtr, uint32_t, uint32_t, uint64_t) { return 0; }
22 static inline int drmModeAtomicCommit(int, drmModeAtomicReqPtr, int, void*) { return 0; }
24 #endif // DRM_CLIENT_CAP_ATOMIC
26 using namespace std;
28 namespace kms
29 {
30 AtomicReq::AtomicReq(Card& card)
31 : m_card(card)
32 {
33 assert(card.has_atomic());
34 m_req = drmModeAtomicAlloc();
35 }
37 AtomicReq::~AtomicReq()
38 {
39 drmModeAtomicFree(m_req);
40 }
42 void AtomicReq::add(uint32_t ob_id, uint32_t prop_id, uint64_t value)
43 {
44 int r = drmModeAtomicAddProperty(m_req, ob_id, prop_id, value);
45 if (r <= 0)
46 throw std::invalid_argument("foo");
47 }
49 void AtomicReq::add(DrmObject *ob, Property *prop, uint64_t value)
50 {
51 add(ob->id(), prop->id(), value);
52 }
54 void AtomicReq::add(DrmObject* ob, const string& prop, uint64_t value)
55 {
56 add(ob, m_card.get_prop(prop), value);
57 }
59 void AtomicReq::add(DrmObject* ob, const map<string, uint64_t>& values)
60 {
61 for(const auto& kvp : values)
62 add(ob, kvp.first, kvp.second);
63 }
65 int AtomicReq::test(bool allow_modeset)
66 {
67 uint32_t flags = DRM_MODE_ATOMIC_TEST_ONLY;
69 if (allow_modeset)
70 flags |= DRM_MODE_ATOMIC_ALLOW_MODESET;
72 return drmModeAtomicCommit(m_card.fd(), m_req, flags, 0);
73 }
75 int AtomicReq::commit(void* data, bool allow_modeset)
76 {
77 uint32_t flags = DRM_MODE_PAGE_FLIP_EVENT | DRM_MODE_ATOMIC_NONBLOCK;
79 if (allow_modeset)
80 flags |= DRM_MODE_ATOMIC_ALLOW_MODESET;
82 return drmModeAtomicCommit(m_card.fd(), m_req, flags, data);
83 }
85 int AtomicReq::commit_sync(bool allow_modeset)
86 {
87 uint32_t flags = 0;
89 if (allow_modeset)
90 flags |= DRM_MODE_ATOMIC_ALLOW_MODESET;
92 return drmModeAtomicCommit(m_card.fd(), m_req, flags, 0);
93 }
94 }