]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - android/external-libkmsxx.git/blob - kms++/src/atomicreq.cpp
01934ae1358b80756b6372c04b0873e5465d547d
[android/external-libkmsxx.git] / kms++ / src / atomicreq.cpp
1 #include <cassert>
2 #include <stdexcept>
4 #include <xf86drm.h>
5 #include <xf86drmMode.h>
7 #include <kms++/kms++.h>
9 #ifndef DRM_CLIENT_CAP_ATOMIC
11 #define DRM_MODE_ATOMIC_TEST_ONLY 0
12 #define DRM_MODE_ATOMIC_NONBLOCK 0
14 struct _drmModeAtomicReq;
15 typedef struct _drmModeAtomicReq* drmModeAtomicReqPtr;
17 static inline drmModeAtomicReqPtr drmModeAtomicAlloc() { return 0; }
18 static inline void drmModeAtomicFree(drmModeAtomicReqPtr) { }
19 static inline int drmModeAtomicAddProperty(drmModeAtomicReqPtr, uint32_t, uint32_t, uint64_t) { return 0; }
20 static inline int drmModeAtomicCommit(int, drmModeAtomicReqPtr, int, void*) { return 0; }
22 #endif // DRM_CLIENT_CAP_ATOMIC
24 using namespace std;
26 namespace kms
27 {
28 AtomicReq::AtomicReq(Card& card)
29         : m_card(card)
30 {
31         assert(card.has_atomic());
32         m_req = drmModeAtomicAlloc();
33 }
35 AtomicReq::~AtomicReq()
36 {
37         drmModeAtomicFree(m_req);
38 }
40 void AtomicReq::add(uint32_t ob_id, uint32_t prop_id, uint64_t value)
41 {
42         int r = drmModeAtomicAddProperty(m_req, ob_id, prop_id, value);
43         if (r <= 0)
44                 throw std::invalid_argument("foo");
45 }
47 void AtomicReq::add(DrmObject *ob, Property *prop, uint64_t value)
48 {
49         add(ob->id(), prop->id(), value);
50 }
52 void AtomicReq::add(DrmObject* ob, const string& prop, uint64_t value)
53 {
54         add(ob, m_card.get_prop(prop), value);
55 }
57 void AtomicReq::add(DrmObject* ob, const map<string, uint64_t>& values)
58 {
59         for(const auto& kvp : values)
60                 add(ob, kvp.first, kvp.second);
61 }
63 int AtomicReq::test(bool allow_modeset)
64 {
65         uint32_t flags = DRM_MODE_ATOMIC_TEST_ONLY;
67         if (allow_modeset)
68                 flags |= DRM_MODE_ATOMIC_ALLOW_MODESET;
70         return drmModeAtomicCommit(m_card.fd(), m_req, flags, 0);
71 }
73 int AtomicReq::commit(void* data, bool allow_modeset)
74 {
75         uint32_t flags = DRM_MODE_PAGE_FLIP_EVENT | DRM_MODE_ATOMIC_NONBLOCK;
77         if (allow_modeset)
78                 flags |= DRM_MODE_ATOMIC_ALLOW_MODESET;
80         return drmModeAtomicCommit(m_card.fd(), m_req, flags, data);
81 }
83 int AtomicReq::commit_sync(bool allow_modeset)
84 {
85         uint32_t flags = 0;
87         if (allow_modeset)
88                 flags |= DRM_MODE_ATOMIC_ALLOW_MODESET;
90         return drmModeAtomicCommit(m_card.fd(), m_req, flags, 0);
91 }
92 }