1 #include <xf86drm.h> 2 #include <stdexcept> 3 #include <cmath> 4 5 #include <kms++/modedb.h> 6 7 using namespace std; 8 9 namespace kms 10 { 11 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]; 16 17 if (m.hdisplay != width || m.vdisplay != height) 18 continue; 19 20 if (ilace != m.interlace()) 21 continue; 22 23 if (vrefresh && vrefresh != m.calculated_vrefresh()) 24 continue; 25 26 return m; 27 } 28 29 // If not found, do another round using rounded vrefresh 30 31 for (unsigned i = 0; modes[i].clock; ++i) { 32 const Videomode& m = modes[i]; 33 34 if (m.hdisplay != width || m.vdisplay != height) 35 continue; 36 37 if (ilace != m.interlace()) 38 continue; 39 40 if (vrefresh && vrefresh != roundf(m.calculated_vrefresh())) 41 continue; 42 43 return m; 44 } 45 46 throw invalid_argument("mode not found"); 47 } 48 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 } 53 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 } 58 59 } 60