]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - android/external-libkmsxx.git/blob - kms++/src/modedb.cpp
crtc: add disable_mode()
[android/external-libkmsxx.git] / kms++ / src / modedb.cpp
1 #include <xf86drm.h>
2 #include <stdexcept>
3 #include <cmath>
5 #include <kms++/modedb.h>
7 using namespace std;
9 namespace kms
10 {
12 static const Videomode& find_from_table(const Videomode* modes, uint32_t width, uint32_t height, float vrefresh, bool ilace)
13 {
14         for (unsigned i = 0; modes[i].clock; ++i) {
15                 const Videomode& m = modes[i];
17                 if (m.hdisplay != width || m.vdisplay != height)
18                         continue;
20                 if (ilace != m.interlace())
21                         continue;
23                 if (vrefresh && vrefresh != m.calculated_vrefresh())
24                         continue;
26                 return m;
27         }
29         // If not found, do another round using rounded vrefresh
31         for (unsigned i = 0; modes[i].clock; ++i) {
32                 const Videomode& m = modes[i];
34                 if (m.hdisplay != width || m.vdisplay != height)
35                         continue;
37                 if (ilace != m.interlace())
38                         continue;
40                 if (vrefresh && vrefresh != roundf(m.calculated_vrefresh()))
41                         continue;
43                 return m;
44         }
46         throw invalid_argument("mode not found");
47 }
49 const Videomode& find_dmt(uint32_t width, uint32_t height, float vrefresh, bool ilace)
50 {
51         return find_from_table(dmt_modes, width, height, vrefresh, ilace);
52 }
54 const Videomode& find_cea(uint32_t width, uint32_t height, float vrefresh, bool ilace)
55 {
56         return find_from_table(cea_modes, width, height, vrefresh, ilace);
57 }
59 }