17bdf92f3SAxel Dörfler /* 24165dff9SAxel Dörfler * Copyright 2007-2008, Axel Dörfler, axeld@pinc-software.de. All rights reserved. 37bdf92f3SAxel Dörfler * Distributed under the terms of the MIT License. 47bdf92f3SAxel Dörfler */ 57bdf92f3SAxel Dörfler 67bdf92f3SAxel Dörfler 77bdf92f3SAxel Dörfler #include <create_display_modes.h> 87bdf92f3SAxel Dörfler 97bdf92f3SAxel Dörfler #include <math.h> 107bdf92f3SAxel Dörfler #include <stdlib.h> 117bdf92f3SAxel Dörfler #include <string.h> 127bdf92f3SAxel Dörfler 137bdf92f3SAxel Dörfler #include <video_overlay.h> 147bdf92f3SAxel Dörfler 157bdf92f3SAxel Dörfler 167bdf92f3SAxel Dörfler #define POSITIVE_SYNC \ 177bdf92f3SAxel Dörfler (B_POSITIVE_HSYNC | B_POSITIVE_VSYNC) 187bdf92f3SAxel Dörfler #define MODE_FLAGS \ 197bdf92f3SAxel Dörfler (B_8_BIT_DAC | B_HARDWARE_CURSOR | B_PARALLEL_ACCESS | B_DPMS | B_SUPPORTS_OVERLAYS) 207bdf92f3SAxel Dörfler 217bdf92f3SAxel Dörfler // TODO: move this list into the app_server 227bdf92f3SAxel Dörfler static const display_mode kBaseModeList[] = { 237bdf92f3SAxel Dörfler {{25175, 640, 656, 752, 800, 350, 387, 389, 449, B_POSITIVE_HSYNC}, B_CMAP8, 640, 350, 0, 0, MODE_FLAGS}, /* 640x350 - www.epanorama.net/documents/pc/vga_timing.html) */ 247bdf92f3SAxel Dörfler {{25175, 640, 656, 752, 800, 400, 412, 414, 449, B_POSITIVE_VSYNC}, B_CMAP8, 640, 400, 0, 0, MODE_FLAGS}, /* 640x400 - www.epanorama.net/documents/pc/vga_timing.html) */ 257bdf92f3SAxel Dörfler {{25175, 640, 656, 752, 800, 480, 490, 492, 525, 0}, B_CMAP8, 640, 480, 0, 0, MODE_FLAGS}, /* Vesa_Monitor_@60Hz_(640X480X8.Z1) */ 267bdf92f3SAxel Dörfler {{27500, 640, 672, 768, 864, 480, 488, 494, 530, 0}, B_CMAP8, 640, 480, 0, 0, MODE_FLAGS}, /* 640X480X60Hz */ 277bdf92f3SAxel Dörfler {{30500, 640, 672, 768, 864, 480, 517, 523, 588, 0}, B_CMAP8, 640, 480, 0, 0, MODE_FLAGS}, /* SVGA_640X480X60HzNI */ 287bdf92f3SAxel Dörfler {{31500, 640, 664, 704, 832, 480, 489, 492, 520, 0}, B_CMAP8, 640, 480, 0, 0, MODE_FLAGS}, /* Vesa_Monitor_@70-72Hz_(640X480X8.Z1) */ 297bdf92f3SAxel Dörfler {{31500, 640, 656, 720, 840, 480, 481, 484, 500, 0}, B_CMAP8, 640, 480, 0, 0, MODE_FLAGS}, /* Vesa_Monitor_@75Hz_(640X480X8.Z1) */ 307bdf92f3SAxel Dörfler {{36000, 640, 696, 752, 832, 480, 481, 484, 509, 0}, B_CMAP8, 640, 480, 0, 0, MODE_FLAGS}, /* Vesa_Monitor_@85Hz_(640X480X8.Z1) */ 31*6c398600SAxel Dörfler {{29580, 800, 816, 896, 992, 480, 481, 484, 497, B_POSITIVE_VSYNC}, B_CMAP8, 800, 480, 0, 0, MODE_FLAGS}, /* 800x480x60Hz */ 327bdf92f3SAxel Dörfler {{38100, 800, 832, 960, 1088, 600, 602, 606, 620, 0}, B_CMAP8, 800, 600, 0, 0, MODE_FLAGS}, /* SVGA_800X600X56HzNI */ 337bdf92f3SAxel Dörfler {{40000, 800, 840, 968, 1056, 600, 601, 605, 628, POSITIVE_SYNC}, B_CMAP8, 800, 600, 0, 0, MODE_FLAGS}, /* Vesa_Monitor_@60Hz_(800X600X8.Z1) */ 347bdf92f3SAxel Dörfler {{49500, 800, 816, 896, 1056, 600, 601, 604, 625, POSITIVE_SYNC}, B_CMAP8, 800, 600, 0, 0, MODE_FLAGS}, /* Vesa_Monitor_@75Hz_(800X600X8.Z1) */ 357bdf92f3SAxel Dörfler {{50000, 800, 856, 976, 1040, 600, 637, 643, 666, POSITIVE_SYNC}, B_CMAP8, 800, 600, 0, 0, MODE_FLAGS}, /* Vesa_Monitor_@70-72Hz_(800X600X8.Z1) */ 367bdf92f3SAxel Dörfler {{56250, 800, 832, 896, 1048, 600, 601, 604, 631, POSITIVE_SYNC}, B_CMAP8, 800, 600, 0, 0, MODE_FLAGS}, /* Vesa_Monitor_@85Hz_(800X600X8.Z1) */ 377bdf92f3SAxel Dörfler {{65000, 1024, 1048, 1184, 1344, 768, 771, 777, 806, 0}, B_CMAP8, 1024, 768, 0, 0, MODE_FLAGS}, /* Vesa_Monitor_@60Hz_(1024X768X8.Z1) */ 387bdf92f3SAxel Dörfler {{75000, 1024, 1048, 1184, 1328, 768, 771, 777, 806, 0}, B_CMAP8, 1024, 768, 0, 0, MODE_FLAGS}, /* Vesa_Monitor_@70-72Hz_(1024X768X8.Z1) */ 397bdf92f3SAxel Dörfler {{78750, 1024, 1040, 1136, 1312, 768, 769, 772, 800, POSITIVE_SYNC}, B_CMAP8, 1024, 768, 0, 0, MODE_FLAGS}, /* Vesa_Monitor_@75Hz_(1024X768X8.Z1) */ 407bdf92f3SAxel Dörfler {{94500, 1024, 1072, 1168, 1376, 768, 769, 772, 808, POSITIVE_SYNC}, B_CMAP8, 1024, 768, 0, 0, MODE_FLAGS}, /* Vesa_Monitor_@85Hz_(1024X768X8.Z1) */ 417bdf92f3SAxel Dörfler {{94200, 1152, 1184, 1280, 1472, 864, 865, 868, 914, POSITIVE_SYNC}, B_CMAP8, 1152, 864, 0, 0, MODE_FLAGS}, /* Vesa_Monitor_@70Hz_(1152X864X8.Z1) */ 427bdf92f3SAxel Dörfler {{108000, 1152, 1216, 1344, 1600, 864, 865, 868, 900, POSITIVE_SYNC}, B_CMAP8, 1152, 864, 0, 0, MODE_FLAGS}, /* Vesa_Monitor_@75Hz_(1152X864X8.Z1) */ 437bdf92f3SAxel Dörfler {{121500, 1152, 1216, 1344, 1568, 864, 865, 868, 911, POSITIVE_SYNC}, B_CMAP8, 1152, 864, 0, 0, MODE_FLAGS}, /* Vesa_Monitor_@85Hz_(1152X864X8.Z1) */ 444165dff9SAxel Dörfler {{74520, 1280, 1368, 1424, 1656, 720, 724, 730, 750, POSITIVE_SYNC}, B_CMAP8, 1280, 720, 0, 0, MODE_FLAGS}, /* Vesa_Monitor_@60Hz_(1280X720) */ 45*6c398600SAxel Dörfler {{83460, 1280, 1344, 1480, 1680, 800, 801, 804, 828, B_POSITIVE_VSYNC}, B_CMAP8, 1280, 800, 0, 0, MODE_FLAGS}, /* WXGA (1280x800x60) */ 467bdf92f3SAxel Dörfler {{108000, 1280, 1328, 1440, 1688, 1024, 1025, 1028, 1066, POSITIVE_SYNC}, B_CMAP8, 1280, 1024, 0, 0, MODE_FLAGS}, /* Vesa_Monitor_@60Hz_(1280X1024X8.Z1) */ 477bdf92f3SAxel Dörfler {{135000, 1280, 1296, 1440, 1688, 1024, 1025, 1028, 1066, POSITIVE_SYNC}, B_CMAP8, 1280, 1024, 0, 0, MODE_FLAGS}, /* Vesa_Monitor_@75Hz_(1280X1024X8.Z1) */ 487bdf92f3SAxel Dörfler {{157500, 1280, 1344, 1504, 1728, 1024, 1025, 1028, 1072, POSITIVE_SYNC}, B_CMAP8, 1280, 1024, 0, 0, MODE_FLAGS}, /* Vesa_Monitor_@85Hz_(1280X1024X8.Z1) */ 494165dff9SAxel Dörfler {{122600, 1400, 1488, 1640, 1880, 1050, 1051, 1054, 1087, POSITIVE_SYNC}, B_CMAP8, 1400, 1050, 0, 0, MODE_FLAGS}, /* Vesa_Monitor_@60Hz_(1400X1050) */ 507bdf92f3SAxel Dörfler 517bdf92f3SAxel Dörfler {{106500, 1440, 1520, 1672, 1904, 900, 901, 904, 932, POSITIVE_SYNC}, B_CMAP8, 1440, 900, 0, 0, MODE_FLAGS}, /* Vesa_Monitor_@60Hz_(1440X900) */ 527bdf92f3SAxel Dörfler 537bdf92f3SAxel Dörfler {{162000, 1600, 1664, 1856, 2160, 1200, 1201, 1204, 1250, POSITIVE_SYNC}, B_CMAP8, 1600, 1200, 0, 0, MODE_FLAGS}, /* Vesa_Monitor_@60Hz_(1600X1200X8.Z1) */ 547bdf92f3SAxel Dörfler {{175500, 1600, 1664, 1856, 2160, 1200, 1201, 1204, 1250, POSITIVE_SYNC}, B_CMAP8, 1600, 1200, 0, 0, MODE_FLAGS}, /* Vesa_Monitor_@65Hz_(1600X1200X8.Z1) */ 557bdf92f3SAxel Dörfler {{189000, 1600, 1664, 1856, 2160, 1200, 1201, 1204, 1250, POSITIVE_SYNC}, B_CMAP8, 1600, 1200, 0, 0, MODE_FLAGS}, /* Vesa_Monitor_@70Hz_(1600X1200X8.Z1) */ 567bdf92f3SAxel Dörfler {{202500, 1600, 1664, 1856, 2160, 1200, 1201, 1204, 1250, POSITIVE_SYNC}, B_CMAP8, 1600, 1200, 0, 0, MODE_FLAGS}, /* Vesa_Monitor_@75Hz_(1600X1200X8.Z1) */ 577bdf92f3SAxel Dörfler {{216000, 1600, 1664, 1856, 2160, 1200, 1201, 1204, 1250, POSITIVE_SYNC}, B_CMAP8, 1600, 1200, 0, 0, MODE_FLAGS}, /* Vesa_Monitor_@80Hz_(1600X1200X8.Z1) */ 587bdf92f3SAxel Dörfler {{229500, 1600, 1664, 1856, 2160, 1200, 1201, 1204, 1250, POSITIVE_SYNC}, B_CMAP8, 1600, 1200, 0, 0, MODE_FLAGS}, /* Vesa_Monitor_@85Hz_(1600X1200X8.Z1) */ 597bdf92f3SAxel Dörfler 607bdf92f3SAxel Dörfler {{147100, 1680, 1784, 1968, 2256, 1050, 1051, 1054, 1087, POSITIVE_SYNC}, B_CMAP8, 1680, 1050, 0, 0, MODE_FLAGS}, /* Vesa_Monitor_@60Hz_(1680X1050) */ 617bdf92f3SAxel Dörfler 624020e749SAxel Dörfler {{160000, 1920, 2010, 2060, 2110, 1200, 1202, 1208, 1235, POSITIVE_SYNC}, B_CMAP8, 1920, 1200, 0, 0, MODE_FLAGS}, /* Vesa_Monitor_@60Hz_(1920X1200) */ 637bdf92f3SAxel Dörfler }; 647bdf92f3SAxel Dörfler static const uint32 kNumBaseModes = sizeof(kBaseModeList) / sizeof(display_mode); 657bdf92f3SAxel Dörfler 667bdf92f3SAxel Dörfler 677bdf92f3SAxel Dörfler namespace BPrivate { 687bdf92f3SAxel Dörfler 697bdf92f3SAxel Dörfler class ModeList { 707bdf92f3SAxel Dörfler public: 717bdf92f3SAxel Dörfler ModeList(); 727bdf92f3SAxel Dörfler ~ModeList(); 737bdf92f3SAxel Dörfler 747bdf92f3SAxel Dörfler bool AddModes(edid1_info* info); 757bdf92f3SAxel Dörfler bool AddModes(const display_mode* modes, uint32 count); 767bdf92f3SAxel Dörfler 777bdf92f3SAxel Dörfler bool CreateColorSpaces(const color_space* spaces, uint32 count); 787bdf92f3SAxel Dörfler void Filter(check_display_mode_hook hook); 797bdf92f3SAxel Dörfler void Clean(); 807bdf92f3SAxel Dörfler 817bdf92f3SAxel Dörfler const display_mode* Modes() const { return fModes; } 827bdf92f3SAxel Dörfler uint32 Count() const { return fCount; } 837bdf92f3SAxel Dörfler 847bdf92f3SAxel Dörfler private: 857bdf92f3SAxel Dörfler bool _MakeSpace(uint32 count); 867bdf92f3SAxel Dörfler bool _AddMode(const display_mode* mode); 877bdf92f3SAxel Dörfler void _RemoveModeAt(uint32 index); 887bdf92f3SAxel Dörfler void _AddBaseMode(uint16 width, uint16 height, uint32 refresh); 897bdf92f3SAxel Dörfler 907bdf92f3SAxel Dörfler display_mode* fModes; 917bdf92f3SAxel Dörfler uint32 fCount; 927bdf92f3SAxel Dörfler uint32 fCapacity; 937bdf92f3SAxel Dörfler }; 947bdf92f3SAxel Dörfler 957bdf92f3SAxel Dörfler } // namespace BPrivate 967bdf92f3SAxel Dörfler 977bdf92f3SAxel Dörfler using namespace BPrivate; 987bdf92f3SAxel Dörfler 997bdf92f3SAxel Dörfler 1007bdf92f3SAxel Dörfler static float 1017bdf92f3SAxel Dörfler get_refresh_rate(const display_mode& mode) 1027bdf92f3SAxel Dörfler { 1037bdf92f3SAxel Dörfler // we have to be catious as refresh rate cannot be controlled directly, 1047bdf92f3SAxel Dörfler // so it suffers under rounding errors and hardware restrictions 1057bdf92f3SAxel Dörfler return rint(10 * float(mode.timing.pixel_clock * 1000) / 1067bdf92f3SAxel Dörfler float(mode.timing.h_total * mode.timing.v_total)) / 10.0; 1077bdf92f3SAxel Dörfler } 1087bdf92f3SAxel Dörfler 1097bdf92f3SAxel Dörfler 1107bdf92f3SAxel Dörfler static int 1117bdf92f3SAxel Dörfler compare_mode(const void* _mode1, const void* _mode2) 1127bdf92f3SAxel Dörfler { 1137bdf92f3SAxel Dörfler display_mode *mode1 = (display_mode *)_mode1; 1147bdf92f3SAxel Dörfler display_mode *mode2 = (display_mode *)_mode2; 1157bdf92f3SAxel Dörfler uint16 width1, width2, height1, height2; 1167bdf92f3SAxel Dörfler 1177bdf92f3SAxel Dörfler width1 = mode1->virtual_width; 1187bdf92f3SAxel Dörfler height1 = mode1->virtual_height; 1197bdf92f3SAxel Dörfler width2 = mode2->virtual_width; 1207bdf92f3SAxel Dörfler height2 = mode2->virtual_height; 1217bdf92f3SAxel Dörfler 1227bdf92f3SAxel Dörfler if (width1 != width2) 1237bdf92f3SAxel Dörfler return width1 - width2; 1247bdf92f3SAxel Dörfler 1257bdf92f3SAxel Dörfler if (height1 != height2) 1267bdf92f3SAxel Dörfler return height1 - height2; 1277bdf92f3SAxel Dörfler 1287bdf92f3SAxel Dörfler if (mode1->space != mode2->space) 1297bdf92f3SAxel Dörfler return mode1->space - mode2->space; 1307bdf92f3SAxel Dörfler 1317bdf92f3SAxel Dörfler return (int)(10 * get_refresh_rate(*mode1) 1327bdf92f3SAxel Dörfler - 10 * get_refresh_rate(*mode2)); 1337bdf92f3SAxel Dörfler } 1347bdf92f3SAxel Dörfler 1357bdf92f3SAxel Dörfler 1367bdf92f3SAxel Dörfler // #pragma mark - 1377bdf92f3SAxel Dörfler 1387bdf92f3SAxel Dörfler 1397bdf92f3SAxel Dörfler ModeList::ModeList() 1407bdf92f3SAxel Dörfler : 1417bdf92f3SAxel Dörfler fModes(NULL), 1427bdf92f3SAxel Dörfler fCount(0), 1437bdf92f3SAxel Dörfler fCapacity(0) 1447bdf92f3SAxel Dörfler { 1457bdf92f3SAxel Dörfler } 1467bdf92f3SAxel Dörfler 1477bdf92f3SAxel Dörfler 1487bdf92f3SAxel Dörfler ModeList::~ModeList() 1497bdf92f3SAxel Dörfler { 1507bdf92f3SAxel Dörfler free(fModes); 1517bdf92f3SAxel Dörfler } 1527bdf92f3SAxel Dörfler 1537bdf92f3SAxel Dörfler 1547bdf92f3SAxel Dörfler bool 1557bdf92f3SAxel Dörfler ModeList::AddModes(edid1_info* info) 1567bdf92f3SAxel Dörfler { 1577bdf92f3SAxel Dörfler if (info->established_timing.res_720x400x70) 1587bdf92f3SAxel Dörfler _AddBaseMode(720, 400, 70); 1597bdf92f3SAxel Dörfler if (info->established_timing.res_720x400x88) 1607bdf92f3SAxel Dörfler _AddBaseMode(720, 400, 88); 1617bdf92f3SAxel Dörfler 1627bdf92f3SAxel Dörfler if (info->established_timing.res_640x480x60) 1637bdf92f3SAxel Dörfler _AddBaseMode(640, 480, 60); 1647bdf92f3SAxel Dörfler if (info->established_timing.res_640x480x67) 1657bdf92f3SAxel Dörfler _AddBaseMode(640, 480, 67); 1667bdf92f3SAxel Dörfler if (info->established_timing.res_640x480x72) 1677bdf92f3SAxel Dörfler _AddBaseMode(640, 480, 72); 1687bdf92f3SAxel Dörfler if (info->established_timing.res_640x480x75) 1697bdf92f3SAxel Dörfler _AddBaseMode(640, 480, 75); 1707bdf92f3SAxel Dörfler 1717bdf92f3SAxel Dörfler if (info->established_timing.res_800x600x56) 1727bdf92f3SAxel Dörfler _AddBaseMode(800, 600, 56); 1737bdf92f3SAxel Dörfler if (info->established_timing.res_800x600x60) 1747bdf92f3SAxel Dörfler _AddBaseMode(800, 600, 60); 1757bdf92f3SAxel Dörfler if (info->established_timing.res_800x600x72) 1767bdf92f3SAxel Dörfler _AddBaseMode(800, 600, 72); 1777bdf92f3SAxel Dörfler if (info->established_timing.res_800x600x75) 1787bdf92f3SAxel Dörfler _AddBaseMode(800, 600, 75); 1797bdf92f3SAxel Dörfler 1807bdf92f3SAxel Dörfler #if 0 1817bdf92f3SAxel Dörfler if (info->established_timing.res_832x624x75) 1827bdf92f3SAxel Dörfler _AddBaseMode(832, 624, 75); 1837bdf92f3SAxel Dörfler 1847bdf92f3SAxel Dörfler if (info->established_timing.res_1024x768x87i) 1857bdf92f3SAxel Dörfler _AddBaseMode(1024, 768, 87); 1867bdf92f3SAxel Dörfler #endif 1877bdf92f3SAxel Dörfler if (info->established_timing.res_1024x768x60) 1887bdf92f3SAxel Dörfler _AddBaseMode(1024, 768, 60); 1897bdf92f3SAxel Dörfler if (info->established_timing.res_1024x768x70) 1907bdf92f3SAxel Dörfler _AddBaseMode(1024, 768, 70); 1917bdf92f3SAxel Dörfler if (info->established_timing.res_1024x768x75) 1927bdf92f3SAxel Dörfler _AddBaseMode(1024, 768, 75); 1937bdf92f3SAxel Dörfler 1947bdf92f3SAxel Dörfler if (info->established_timing.res_1152x870x75) 1957bdf92f3SAxel Dörfler _AddBaseMode(1152, 870, 75); 1967bdf92f3SAxel Dörfler if (info->established_timing.res_1280x1024x75) 1977bdf92f3SAxel Dörfler _AddBaseMode(1280, 1024, 75); 1987bdf92f3SAxel Dörfler 1997bdf92f3SAxel Dörfler for (uint32 i = 0; i < EDID1_NUM_STD_TIMING; ++i) { 2007bdf92f3SAxel Dörfler if (info->std_timing[i].h_size <= 256) 2017bdf92f3SAxel Dörfler continue; 2027bdf92f3SAxel Dörfler 2037bdf92f3SAxel Dörfler _AddBaseMode(info->std_timing[i].h_size, info->std_timing[i].v_size, 2047bdf92f3SAxel Dörfler info->std_timing[i].refresh); 2057bdf92f3SAxel Dörfler } 2067bdf92f3SAxel Dörfler 2077bdf92f3SAxel Dörfler for (uint32 i = 0; i < EDID1_NUM_DETAILED_MONITOR_DESC; ++i) { 2087bdf92f3SAxel Dörfler if (info->detailed_monitor[i].monitor_desc_type != EDID1_IS_DETAILED_TIMING) 2097bdf92f3SAxel Dörfler continue; 2107bdf92f3SAxel Dörfler 211f6e4cbb9SAxel Dörfler // TODO: handle sync and flags correctly! 2127bdf92f3SAxel Dörfler const edid1_detailed_timing& timing = info->detailed_monitor[i].data.detailed_timing; 2137bdf92f3SAxel Dörfler display_mode mode; 2147bdf92f3SAxel Dörfler mode.timing.pixel_clock = timing.pixel_clock * 10; 2157bdf92f3SAxel Dörfler mode.timing.h_display = timing.h_active; 216fe2aaee7SAxel Dörfler mode.timing.h_sync_start = timing.h_active + timing.h_sync_off; 217fe2aaee7SAxel Dörfler mode.timing.h_sync_end = mode.timing.h_sync_start + timing.h_sync_width; 218fe2aaee7SAxel Dörfler mode.timing.h_total = timing.h_active + timing.h_blank; 2197bdf92f3SAxel Dörfler mode.timing.v_display = timing.v_active; 220fe2aaee7SAxel Dörfler mode.timing.v_sync_start = timing.v_active + timing.v_sync_off; 221fe2aaee7SAxel Dörfler mode.timing.v_sync_end = mode.timing.v_sync_start + timing.v_sync_width; 222fe2aaee7SAxel Dörfler mode.timing.v_total = timing.v_active + timing.v_blank; 2237bdf92f3SAxel Dörfler mode.timing.flags = POSITIVE_SYNC; 224fe2aaee7SAxel Dörfler if (timing.interlaced) 225fe2aaee7SAxel Dörfler mode.timing.flags |= B_TIMING_INTERLACED; 2267bdf92f3SAxel Dörfler mode.space = B_RGB32; 2277bdf92f3SAxel Dörfler mode.virtual_width = timing.h_active; 2287bdf92f3SAxel Dörfler mode.virtual_height = timing.v_active; 2297bdf92f3SAxel Dörfler mode.h_display_start = 0; 2307bdf92f3SAxel Dörfler mode.v_display_start = 0; 2317bdf92f3SAxel Dörfler mode.flags = MODE_FLAGS; 2327bdf92f3SAxel Dörfler } 2337bdf92f3SAxel Dörfler 2347bdf92f3SAxel Dörfler // TODO: add other modes from the base list that satisfy the display's 2357bdf92f3SAxel Dörfler // requirements! 2367bdf92f3SAxel Dörfler 2377bdf92f3SAxel Dörfler return true; 2387bdf92f3SAxel Dörfler } 2397bdf92f3SAxel Dörfler 2407bdf92f3SAxel Dörfler 2417bdf92f3SAxel Dörfler bool 2427bdf92f3SAxel Dörfler ModeList::AddModes(const display_mode* modes, uint32 count) 2437bdf92f3SAxel Dörfler { 2447bdf92f3SAxel Dörfler if (!_MakeSpace(count)) 2457bdf92f3SAxel Dörfler return false; 2467bdf92f3SAxel Dörfler 2477bdf92f3SAxel Dörfler for (uint32 i = 0; i < count; i++) { 2487bdf92f3SAxel Dörfler fModes[fCount++] = modes[i]; 2497bdf92f3SAxel Dörfler } 2507bdf92f3SAxel Dörfler 2517bdf92f3SAxel Dörfler return true; 2527bdf92f3SAxel Dörfler } 2537bdf92f3SAxel Dörfler 2547bdf92f3SAxel Dörfler 2557bdf92f3SAxel Dörfler bool 2567bdf92f3SAxel Dörfler ModeList::CreateColorSpaces(const color_space* spaces, uint32 count) 2577bdf92f3SAxel Dörfler { 2587bdf92f3SAxel Dörfler uint32 modeCount = fCount; 2597bdf92f3SAxel Dörfler 2607bdf92f3SAxel Dörfler for (uint32 i = 0; i < count; i++) { 2617bdf92f3SAxel Dörfler if (i > 0 && !AddModes(fModes, modeCount)) 2627bdf92f3SAxel Dörfler return false; 2637bdf92f3SAxel Dörfler 2647bdf92f3SAxel Dörfler for (uint32 j = 0; j < modeCount; j++) { 2657bdf92f3SAxel Dörfler fModes[j + fCount - modeCount].space = spaces[i]; 2667bdf92f3SAxel Dörfler } 2677bdf92f3SAxel Dörfler } 2687bdf92f3SAxel Dörfler 2697bdf92f3SAxel Dörfler return true; 2707bdf92f3SAxel Dörfler } 2717bdf92f3SAxel Dörfler 2727bdf92f3SAxel Dörfler 2737bdf92f3SAxel Dörfler void 2747bdf92f3SAxel Dörfler ModeList::Filter(check_display_mode_hook hook) 2757bdf92f3SAxel Dörfler { 2767bdf92f3SAxel Dörfler if (hook == NULL) 2777bdf92f3SAxel Dörfler return; 2787bdf92f3SAxel Dörfler 2797bdf92f3SAxel Dörfler for (uint32 i = fCount; i-- > 0;) { 2807bdf92f3SAxel Dörfler if (!hook(&fModes[i])) 2817bdf92f3SAxel Dörfler _RemoveModeAt(i); 2827bdf92f3SAxel Dörfler } 2837bdf92f3SAxel Dörfler } 2847bdf92f3SAxel Dörfler 2857bdf92f3SAxel Dörfler 2867bdf92f3SAxel Dörfler void 2877bdf92f3SAxel Dörfler ModeList::Clean() 2887bdf92f3SAxel Dörfler { 2897bdf92f3SAxel Dörfler // sort mode list 2907bdf92f3SAxel Dörfler qsort(fModes, fCount, sizeof(display_mode), compare_mode); 2917bdf92f3SAxel Dörfler 2927bdf92f3SAxel Dörfler // remove duplicates 2937bdf92f3SAxel Dörfler for (uint32 i = fCount; i-- > 1;) { 2947bdf92f3SAxel Dörfler if (compare_mode(&fModes[i], &fModes[i - 1]) == 0) 2957bdf92f3SAxel Dörfler _RemoveModeAt(i); 2967bdf92f3SAxel Dörfler } 2977bdf92f3SAxel Dörfler } 2987bdf92f3SAxel Dörfler 2997bdf92f3SAxel Dörfler 3007bdf92f3SAxel Dörfler void 3017bdf92f3SAxel Dörfler ModeList::_AddBaseMode(uint16 width, uint16 height, uint32 refresh) 3027bdf92f3SAxel Dörfler { 3037bdf92f3SAxel Dörfler for (uint32 i = 0; i < kNumBaseModes; i++) { 3047bdf92f3SAxel Dörfler const display_mode& mode = kBaseModeList[i]; 3057bdf92f3SAxel Dörfler 3067bdf92f3SAxel Dörfler if (mode.timing.h_display == width && mode.timing.v_display == height 3077bdf92f3SAxel Dörfler && get_refresh_rate(mode) == refresh) { 3087bdf92f3SAxel Dörfler _AddMode(&mode); 3097bdf92f3SAxel Dörfler return; 3107bdf92f3SAxel Dörfler } 3117bdf92f3SAxel Dörfler } 3127bdf92f3SAxel Dörfler } 3137bdf92f3SAxel Dörfler 3147bdf92f3SAxel Dörfler 3157bdf92f3SAxel Dörfler bool 3167bdf92f3SAxel Dörfler ModeList::_MakeSpace(uint32 count) 3177bdf92f3SAxel Dörfler { 3187bdf92f3SAxel Dörfler if (fCount + count <= fCapacity) 3197bdf92f3SAxel Dörfler return true; 3207bdf92f3SAxel Dörfler 3217bdf92f3SAxel Dörfler uint32 capacity = (fCapacity + count + 0xf) & ~0xf; 3227bdf92f3SAxel Dörfler display_mode* modes = (display_mode*)realloc(fModes, 3237bdf92f3SAxel Dörfler capacity * sizeof(display_mode)); 3247bdf92f3SAxel Dörfler if (modes == NULL) 3257bdf92f3SAxel Dörfler return false; 3267bdf92f3SAxel Dörfler 3277bdf92f3SAxel Dörfler fModes = modes; 3287bdf92f3SAxel Dörfler fCapacity = capacity; 3297bdf92f3SAxel Dörfler return true; 3307bdf92f3SAxel Dörfler } 3317bdf92f3SAxel Dörfler 3327bdf92f3SAxel Dörfler 3337bdf92f3SAxel Dörfler bool 3347bdf92f3SAxel Dörfler ModeList::_AddMode(const display_mode* mode) 3357bdf92f3SAxel Dörfler { 3367bdf92f3SAxel Dörfler if (!_MakeSpace(1)) 3377bdf92f3SAxel Dörfler return false; 3387bdf92f3SAxel Dörfler 3397bdf92f3SAxel Dörfler fModes[fCount++] = *mode; 3407bdf92f3SAxel Dörfler return true; 3417bdf92f3SAxel Dörfler } 3427bdf92f3SAxel Dörfler 3437bdf92f3SAxel Dörfler 3447bdf92f3SAxel Dörfler void 3457bdf92f3SAxel Dörfler ModeList::_RemoveModeAt(uint32 index) 3467bdf92f3SAxel Dörfler { 3477bdf92f3SAxel Dörfler if (index < fCount - 1) { 3487bdf92f3SAxel Dörfler memmove(&fModes[index], &fModes[index + 1], 3497bdf92f3SAxel Dörfler (fCount - 1 - index) * sizeof(display_mode)); 3507bdf92f3SAxel Dörfler } 3517bdf92f3SAxel Dörfler 3527bdf92f3SAxel Dörfler fCount--; 3537bdf92f3SAxel Dörfler } 3547bdf92f3SAxel Dörfler 3557bdf92f3SAxel Dörfler 3567bdf92f3SAxel Dörfler // #pragma mark - 3577bdf92f3SAxel Dörfler 3587bdf92f3SAxel Dörfler 3597bdf92f3SAxel Dörfler extern "C" area_id 3607bdf92f3SAxel Dörfler create_display_modes(const char* name, edid1_info* edid, 3617bdf92f3SAxel Dörfler const display_mode* initialModes, uint32 initialModeCount, 3627bdf92f3SAxel Dörfler const color_space *spaces, uint32 spacesCount, 3637bdf92f3SAxel Dörfler check_display_mode_hook hook, display_mode** _modes, uint32* _count) 3647bdf92f3SAxel Dörfler { 3657bdf92f3SAxel Dörfler if (_modes == NULL || _count == NULL) 3667bdf92f3SAxel Dörfler return B_BAD_VALUE; 3677bdf92f3SAxel Dörfler 3687bdf92f3SAxel Dörfler // compile initial mode list from the different sources 3697bdf92f3SAxel Dörfler 3707bdf92f3SAxel Dörfler ModeList modes; 3717bdf92f3SAxel Dörfler modes.AddModes(initialModes, initialModeCount); 3727bdf92f3SAxel Dörfler 3737bdf92f3SAxel Dörfler if (edid != NULL) 3747bdf92f3SAxel Dörfler modes.AddModes(edid); 3757bdf92f3SAxel Dörfler else 3767bdf92f3SAxel Dörfler modes.AddModes(kBaseModeList, kNumBaseModes); 3777bdf92f3SAxel Dörfler 3787bdf92f3SAxel Dörfler // filter out modes the caller doesn't like, and multiply modes for 3797bdf92f3SAxel Dörfler // every color space 3807bdf92f3SAxel Dörfler 3817bdf92f3SAxel Dörfler if (spaces == NULL) { 3827bdf92f3SAxel Dörfler const color_space kDefaultSpaces[] = {B_RGB32_LITTLE, B_RGB16_LITTLE, 3837bdf92f3SAxel Dörfler B_RGB15_LITTLE, B_CMAP8}; 3847bdf92f3SAxel Dörfler modes.CreateColorSpaces(kDefaultSpaces, 3857bdf92f3SAxel Dörfler sizeof(kDefaultSpaces) / sizeof(kDefaultSpaces[0])); 3867bdf92f3SAxel Dörfler } else 3877bdf92f3SAxel Dörfler modes.CreateColorSpaces(spaces, spacesCount); 3887bdf92f3SAxel Dörfler 3897bdf92f3SAxel Dörfler modes.Filter(hook); 3907bdf92f3SAxel Dörfler modes.Clean(); 3917bdf92f3SAxel Dörfler 3927bdf92f3SAxel Dörfler // create area for output modes 3937bdf92f3SAxel Dörfler 3947bdf92f3SAxel Dörfler size_t size = (sizeof(display_mode) * modes.Count() + B_PAGE_SIZE - 1) 3957bdf92f3SAxel Dörfler & ~(B_PAGE_SIZE - 1); 3967bdf92f3SAxel Dörfler display_mode *list; 3977bdf92f3SAxel Dörfler area_id area = create_area(name, (void **)&list, B_ANY_ADDRESS, 3987bdf92f3SAxel Dörfler size, B_NO_LOCK, B_READ_AREA | B_WRITE_AREA); 3997bdf92f3SAxel Dörfler if (area < B_OK) 4007bdf92f3SAxel Dörfler return area; 4017bdf92f3SAxel Dörfler 4027bdf92f3SAxel Dörfler memcpy(list, modes.Modes(), sizeof(display_mode) * modes.Count()); 4037bdf92f3SAxel Dörfler *_modes = list; 4047bdf92f3SAxel Dörfler *_count = modes.Count(); 4057bdf92f3SAxel Dörfler 4067bdf92f3SAxel Dörfler return area; 4077bdf92f3SAxel Dörfler } 4087bdf92f3SAxel Dörfler 409