• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 {
find_from_table(const Videomode * modes,uint32_t width,uint32_t height,float vrefresh,bool ilace)11 static const Videomode& find_from_table(const Videomode* modes, uint32_t width, uint32_t height, float vrefresh, bool ilace)
12 {
13 	for (unsigned i = 0; modes[i].clock; ++i) {
14 		const Videomode& m = modes[i];
15 
16 		if (m.hdisplay != width || m.vdisplay != height)
17 			continue;
18 
19 		if (ilace != m.interlace())
20 			continue;
21 
22 		if (vrefresh && vrefresh != m.calculated_vrefresh())
23 			continue;
24 
25 		return m;
26 	}
27 
28 	// If not found, do another round using rounded vrefresh
29 
30 	for (unsigned i = 0; modes[i].clock; ++i) {
31 		const Videomode& m = modes[i];
32 
33 		if (m.hdisplay != width || m.vdisplay != height)
34 			continue;
35 
36 		if (ilace != m.interlace())
37 			continue;
38 
39 		if (vrefresh && vrefresh != roundf(m.calculated_vrefresh()))
40 			continue;
41 
42 		return m;
43 	}
44 
45 	throw invalid_argument("mode not found");
46 }
47 
find_dmt(uint32_t width,uint32_t height,float vrefresh,bool ilace)48 const Videomode& find_dmt(uint32_t width, uint32_t height, float vrefresh, bool ilace)
49 {
50 	return find_from_table(dmt_modes, width, height, vrefresh, ilace);
51 }
52 
find_cea(uint32_t width,uint32_t height,float vrefresh,bool ilace)53 const Videomode& find_cea(uint32_t width, uint32_t height, float vrefresh, bool ilace)
54 {
55 	return find_from_table(cea_modes, width, height, vrefresh, ilace);
56 }
57 
58 } // namespace kms
59