1 /* 2 * Copyright 2007-2011, Axel Dörfler, axeld@pinc-software.de. 3 * Distributed under the terms of the MIT License. 4 */ 5 6 7 #include <create_display_modes.h> 8 9 #include <math.h> 10 #include <stdlib.h> 11 #include <string.h> 12 13 #include <compute_display_timing.h> 14 #include <video_overlay.h> 15 16 17 #define POSITIVE_SYNC \ 18 (B_POSITIVE_HSYNC | B_POSITIVE_VSYNC) 19 #define MODE_FLAGS \ 20 (B_8_BIT_DAC | B_HARDWARE_CURSOR | B_PARALLEL_ACCESS | B_DPMS \ 21 | B_SUPPORTS_OVERLAYS) 22 23 // TODO: move this list into the app_server 24 static const display_mode kBaseModeList[] = { 25 {{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) */ 26 27 {{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) */ 28 29 {{25175, 640, 656, 752, 800, 480, 490, 492, 525, 0}, B_CMAP8, 640, 480, 0, 0, MODE_FLAGS}, /* Vesa_Monitor_@60Hz_(640X480X8.Z1) */ 30 {{31500, 640, 664, 704, 832, 480, 489, 492, 520, 0}, B_CMAP8, 640, 480, 0, 0, MODE_FLAGS}, /* Vesa_Monitor_@70-72Hz_(640X480X8.Z1) */ 31 {{31500, 640, 656, 720, 840, 480, 481, 484, 500, 0}, B_CMAP8, 640, 480, 0, 0, MODE_FLAGS}, /* Vesa_Monitor_@75Hz_(640X480X8.Z1) */ 32 {{36000, 640, 696, 752, 832, 480, 481, 484, 509, 0}, B_CMAP8, 640, 480, 0, 0, MODE_FLAGS}, /* Vesa_Monitor_@85Hz_(640X480X8.Z1) */ 33 34 {{29580, 800, 816, 896, 992, 480, 481, 484, 497, B_POSITIVE_VSYNC}, B_CMAP8, 800, 480, 0, 0, MODE_FLAGS}, /* 800x480x60Hz */ 35 36 {{38100, 800, 832, 960, 1088, 600, 602, 606, 620, 0}, B_CMAP8, 800, 600, 0, 0, MODE_FLAGS}, /* SVGA_800X600X56HzNI */ 37 {{40000, 800, 840, 968, 1056, 600, 601, 605, 628, POSITIVE_SYNC}, B_CMAP8, 800, 600, 0, 0, MODE_FLAGS}, /* Vesa_Monitor_@60Hz_(800X600X8.Z1) */ 38 {{49500, 800, 816, 896, 1056, 600, 601, 604, 625, POSITIVE_SYNC}, B_CMAP8, 800, 600, 0, 0, MODE_FLAGS}, /* Vesa_Monitor_@75Hz_(800X600X8.Z1) */ 39 {{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) */ 40 {{56250, 800, 832, 896, 1048, 600, 601, 604, 631, POSITIVE_SYNC}, B_CMAP8, 800, 600, 0, 0, MODE_FLAGS}, /* Vesa_Monitor_@85Hz_(800X600X8.Z1) */ 41 42 {{65000, 1024, 1048, 1184, 1344, 768, 771, 777, 806, 0}, B_CMAP8, 1024, 768, 0, 0, MODE_FLAGS}, /* Vesa_Monitor_@60Hz_(1024X768X8.Z1) */ 43 {{75000, 1024, 1048, 1184, 1328, 768, 771, 777, 806, 0}, B_CMAP8, 1024, 768, 0, 0, MODE_FLAGS}, /* Vesa_Monitor_@70-72Hz_(1024X768X8.Z1) */ 44 {{78750, 1024, 1040, 1136, 1312, 768, 769, 772, 800, POSITIVE_SYNC}, B_CMAP8, 1024, 768, 0, 0, MODE_FLAGS}, /* Vesa_Monitor_@75Hz_(1024X768X8.Z1) */ 45 {{94500, 1024, 1072, 1168, 1376, 768, 769, 772, 808, POSITIVE_SYNC}, B_CMAP8, 1024, 768, 0, 0, MODE_FLAGS}, /* Vesa_Monitor_@85Hz_(1024X768X8.Z1) */ 46 47 {{81640, 1152, 1216, 1336, 1520, 864, 865, 868, 895, POSITIVE_SYNC}, B_CMAP8, 1152, 864, 0, 0, MODE_FLAGS}, /* 1152x864x60Hz */ 48 {{94200, 1152, 1184, 1280, 1472, 864, 865, 868, 914, POSITIVE_SYNC}, B_CMAP8, 1152, 864, 0, 0, MODE_FLAGS}, /* Vesa_Monitor_@70Hz_(1152X864X8.Z1) */ 49 {{108000, 1152, 1216, 1344, 1600, 864, 865, 868, 900, POSITIVE_SYNC}, B_CMAP8, 1152, 864, 0, 0, MODE_FLAGS}, /* Vesa_Monitor_@75Hz_(1152X864X8.Z1) */ 50 {{121500, 1152, 1216, 1344, 1568, 864, 865, 868, 911, POSITIVE_SYNC}, B_CMAP8, 1152, 864, 0, 0, MODE_FLAGS}, /* Vesa_Monitor_@85Hz_(1152X864X8.Z1) */ 51 52 {{74520, 1280, 1368, 1424, 1656, 720, 724, 730, 750, POSITIVE_SYNC}, B_CMAP8, 1280, 720, 0, 0, MODE_FLAGS}, /* Vesa_Monitor_@60Hz_(1280X720) */ 53 54 {{83460, 1280, 1344, 1480, 1680, 800, 801, 804, 828, B_POSITIVE_VSYNC}, B_CMAP8, 1280, 800, 0, 0, MODE_FLAGS}, /* WXGA (1280x800x60) */ 55 56 {{108000, 1280, 1328, 1440, 1688, 1024, 1025, 1028, 1066, POSITIVE_SYNC}, B_CMAP8, 1280, 1024, 0, 0, MODE_FLAGS}, /* Vesa_Monitor_@60Hz_(1280X1024X8.Z1) */ 57 {{135000, 1280, 1296, 1440, 1688, 1024, 1025, 1028, 1066, POSITIVE_SYNC}, B_CMAP8, 1280, 1024, 0, 0, MODE_FLAGS}, /* Vesa_Monitor_@75Hz_(1280X1024X8.Z1) */ 58 {{157500, 1280, 1344, 1504, 1728, 1024, 1025, 1028, 1072, POSITIVE_SYNC}, B_CMAP8, 1280, 1024, 0, 0, MODE_FLAGS}, /* Vesa_Monitor_@85Hz_(1280X1024X8.Z1) */ 59 60 {{122600, 1400, 1488, 1640, 1880, 1050, 1051, 1054, 1087, POSITIVE_SYNC}, B_CMAP8, 1400, 1050, 0, 0, MODE_FLAGS}, /* Vesa_Monitor_@60Hz_(1400X1050) */ 61 {{155800, 1400, 1464, 1784, 1912, 1050, 1052, 1064, 1090, POSITIVE_SYNC}, B_CMAP8, 1400, 1050, 0, 0, MODE_FLAGS}, /* Vesa_Monitor_@75Hz_(1400X1050) */ 62 63 {{106500, 1440, 1520, 1672, 1904, 900, 901, 904, 932, POSITIVE_SYNC}, B_CMAP8, 1440, 900, 0, 0, MODE_FLAGS}, /* Vesa_Monitor_@60Hz_(1440X900) */ 64 65 {{149400, 1366, 1494, 1624, 1798, 768, 770, 776, 795, POSITIVE_SYNC}, B_CMAP8, 1366, 768, 0, 0, MODE_FLAGS}, /* 1366x768 60Hz */ 66 67 {{162000, 1600, 1664, 1856, 2160, 1200, 1201, 1204, 1250, POSITIVE_SYNC}, B_CMAP8, 1600, 1200, 0, 0, MODE_FLAGS}, /* Vesa_Monitor_@60Hz_(1600X1200X8.Z1) */ 68 {{175500, 1600, 1664, 1856, 2160, 1200, 1201, 1204, 1250, POSITIVE_SYNC}, B_CMAP8, 1600, 1200, 0, 0, MODE_FLAGS}, /* Vesa_Monitor_@65Hz_(1600X1200X8.Z1) */ 69 {{189000, 1600, 1664, 1856, 2160, 1200, 1201, 1204, 1250, POSITIVE_SYNC}, B_CMAP8, 1600, 1200, 0, 0, MODE_FLAGS}, /* Vesa_Monitor_@70Hz_(1600X1200X8.Z1) */ 70 {{202500, 1600, 1664, 1856, 2160, 1200, 1201, 1204, 1250, POSITIVE_SYNC}, B_CMAP8, 1600, 1200, 0, 0, MODE_FLAGS}, /* Vesa_Monitor_@75Hz_(1600X1200X8.Z1) */ 71 {{216000, 1600, 1664, 1856, 2160, 1200, 1201, 1204, 1250, POSITIVE_SYNC}, B_CMAP8, 1600, 1200, 0, 0, MODE_FLAGS}, /* Vesa_Monitor_@80Hz_(1600X1200X8.Z1) */ 72 {{229500, 1600, 1664, 1856, 2160, 1200, 1201, 1204, 1250, POSITIVE_SYNC}, B_CMAP8, 1600, 1200, 0, 0, MODE_FLAGS}, /* Vesa_Monitor_@85Hz_(1600X1200X8.Z1) */ 73 74 {{147100, 1680, 1784, 1968, 2256, 1050, 1051, 1054, 1087, POSITIVE_SYNC}, B_CMAP8, 1680, 1050, 0, 0, MODE_FLAGS}, /* Vesa_Monitor_@60Hz_(1680X1050) */ 75 76 {{172000, 1920, 2040, 2248, 2576, 1080, 1081, 1084, 1118, POSITIVE_SYNC}, B_CMAP8, 1920, 1080, 0, 0, MODE_FLAGS}, /* 1920x1080 60Hz */ 77 //{{160000, 1920, 2010, 2060, 2110, 1200, 1202, 1208, 1235, POSITIVE_SYNC}, B_CMAP8, 1920, 1200, 0, 0, MODE_FLAGS}, /* Vesa_Monitor_@60Hz_(1920X1200) */ 78 {{193160, 1920, 2048, 2256, 2592, 1200, 1201, 1204, 1242, POSITIVE_SYNC}, B_CMAP8, 1920, 1200, 0, 0, MODE_FLAGS}, /* Vesa_Monitor_@60Hz_(1920X1200) */ 79 }; 80 static const uint32 kNumBaseModes = sizeof(kBaseModeList) / sizeof(display_mode); 81 82 83 namespace BPrivate { 84 85 class ModeList { 86 public: 87 ModeList(); 88 ~ModeList(); 89 90 bool AddModes(edid1_info* info); 91 bool AddModes(const display_mode* modes, 92 uint32 count); 93 94 bool CreateColorSpaces(const color_space* spaces, 95 uint32 count); 96 void Filter(check_display_mode_hook hook); 97 void Clean(); 98 99 const display_mode* Modes() const { return fModes; } 100 uint32 Count() const { return fCount; } 101 102 private: 103 bool _MakeSpace(uint32 count); 104 bool _AddMode(const display_mode& mode); 105 void _RemoveModeAt(uint32 index); 106 void _AddBaseMode(uint16 width, uint16 height, 107 uint32 refresh); 108 display_mode* _FindMode(uint16 width, uint16 height) const; 109 110 private: 111 display_mode* fModes; 112 uint32 fCount; 113 uint32 fCapacity; 114 }; 115 116 } // namespace BPrivate 117 118 using namespace BPrivate; 119 120 121 static float 122 get_refresh_rate(const display_mode& mode) 123 { 124 return float(mode.timing.pixel_clock * 1000) 125 / float(mode.timing.h_total * mode.timing.v_total); 126 } 127 128 129 static int 130 compare_mode(const void* _mode1, const void* _mode2) 131 { 132 display_mode *mode1 = (display_mode *)_mode1; 133 display_mode *mode2 = (display_mode *)_mode2; 134 uint16 width1, width2, height1, height2; 135 136 width1 = mode1->virtual_width; 137 height1 = mode1->virtual_height; 138 width2 = mode2->virtual_width; 139 height2 = mode2->virtual_height; 140 141 if (width1 != width2) 142 return width1 - width2; 143 144 if (height1 != height2) 145 return height1 - height2; 146 147 if (mode1->space != mode2->space) 148 return mode1->space - mode2->space; 149 150 return (int)(100 * (get_refresh_rate(*mode1) - get_refresh_rate(*mode2))); 151 } 152 153 154 // #pragma mark - 155 156 157 ModeList::ModeList() 158 : 159 fModes(NULL), 160 fCount(0), 161 fCapacity(0) 162 { 163 } 164 165 166 ModeList::~ModeList() 167 { 168 free(fModes); 169 } 170 171 172 bool 173 ModeList::AddModes(edid1_info* info) 174 { 175 if (info->established_timing.res_720x400x70) 176 _AddBaseMode(720, 400, 70); 177 if (info->established_timing.res_720x400x88) 178 _AddBaseMode(720, 400, 88); 179 180 if (info->established_timing.res_640x480x60) 181 _AddBaseMode(640, 480, 60); 182 if (info->established_timing.res_640x480x67) 183 _AddBaseMode(640, 480, 67); 184 if (info->established_timing.res_640x480x72) 185 _AddBaseMode(640, 480, 72); 186 if (info->established_timing.res_640x480x75) 187 _AddBaseMode(640, 480, 75); 188 189 if (info->established_timing.res_800x600x56) 190 _AddBaseMode(800, 600, 56); 191 if (info->established_timing.res_800x600x60) 192 _AddBaseMode(800, 600, 60); 193 if (info->established_timing.res_800x600x72) 194 _AddBaseMode(800, 600, 72); 195 if (info->established_timing.res_800x600x75) 196 _AddBaseMode(800, 600, 75); 197 198 #if 0 199 if (info->established_timing.res_832x624x75) 200 _AddBaseMode(832, 624, 75); 201 202 if (info->established_timing.res_1024x768x87i) 203 _AddBaseMode(1024, 768, 87); 204 #endif 205 if (info->established_timing.res_1024x768x60) 206 _AddBaseMode(1024, 768, 60); 207 if (info->established_timing.res_1024x768x70) 208 _AddBaseMode(1024, 768, 70); 209 if (info->established_timing.res_1024x768x75) 210 _AddBaseMode(1024, 768, 75); 211 212 if (info->established_timing.res_1152x870x75) 213 _AddBaseMode(1152, 870, 75); 214 if (info->established_timing.res_1280x1024x75) 215 _AddBaseMode(1280, 1024, 75); 216 217 for (uint32 i = 0; i < EDID1_NUM_STD_TIMING; ++i) { 218 if (info->std_timing[i].h_size <= 256) 219 continue; 220 221 _AddBaseMode(info->std_timing[i].h_size, info->std_timing[i].v_size, 222 info->std_timing[i].refresh); 223 } 224 225 bool hasRanges = false; 226 uint32 minHorizontalFrequency = 0; 227 uint32 maxHorizontalFrequency = 0; 228 uint32 minVerticalFrequency = 0; 229 uint32 maxVerticalFrequency = 0; 230 uint32 maxPixelClock = 0; 231 232 for (uint32 i = 0; i < EDID1_NUM_DETAILED_MONITOR_DESC; ++i) { 233 if (info->detailed_monitor[i].monitor_desc_type 234 == EDID1_MONITOR_RANGES) { 235 edid1_monitor_range& range 236 = info->detailed_monitor[i].data.monitor_range; 237 238 hasRanges = true; 239 minHorizontalFrequency = range.min_h; 240 maxHorizontalFrequency = range.max_h; 241 minVerticalFrequency = range.min_v; 242 maxVerticalFrequency = range.max_v; 243 maxPixelClock = range.max_clock * 10000; 244 continue; 245 } else if (info->detailed_monitor[i].monitor_desc_type 246 != EDID1_IS_DETAILED_TIMING) 247 continue; 248 249 // TODO: handle flags correctly! 250 const edid1_detailed_timing& timing 251 = info->detailed_monitor[i].data.detailed_timing; 252 display_mode mode; 253 254 if (timing.pixel_clock <= 0/* || timing.sync != 3*/) 255 continue; 256 257 mode.timing.pixel_clock = timing.pixel_clock * 10; 258 mode.timing.h_display = timing.h_active; 259 mode.timing.h_sync_start = timing.h_active + timing.h_sync_off; 260 mode.timing.h_sync_end = mode.timing.h_sync_start + timing.h_sync_width; 261 mode.timing.h_total = timing.h_active + timing.h_blank; 262 mode.timing.v_display = timing.v_active; 263 mode.timing.v_sync_start = timing.v_active + timing.v_sync_off; 264 mode.timing.v_sync_end = mode.timing.v_sync_start + timing.v_sync_width; 265 mode.timing.v_total = timing.v_active + timing.v_blank; 266 mode.timing.flags = 0; 267 if (timing.sync == 3) { 268 if (timing.misc & 1) 269 mode.timing.flags |= B_POSITIVE_HSYNC; 270 if (timing.misc & 2) 271 mode.timing.flags |= B_POSITIVE_VSYNC; 272 } 273 if (timing.interlaced) 274 mode.timing.flags |= B_TIMING_INTERLACED; 275 mode.space = B_RGB32; 276 mode.virtual_width = timing.h_active; 277 mode.virtual_height = timing.v_active; 278 mode.h_display_start = 0; 279 mode.v_display_start = 0; 280 mode.flags = MODE_FLAGS; 281 282 _AddMode(mode); 283 } 284 285 // Add other modes from the base list that satisfy the display's 286 // requirements 287 288 for (uint32 i = 0; i < kNumBaseModes; i++) { 289 const display_mode& mode = kBaseModeList[i]; 290 291 // Check if a mode with this resolution already exists 292 293 if (_FindMode(mode.timing.h_display, mode.timing.v_display) != NULL) 294 continue; 295 296 // Check monitor limits 297 298 if (hasRanges) { 299 uint32 verticalFrequency = 1000 * mode.timing.pixel_clock 300 / (mode.timing.h_total * mode.timing.v_total); 301 uint32 horizontalFrequency = mode.timing.h_total * verticalFrequency 302 / 1000; 303 304 if (minHorizontalFrequency > horizontalFrequency 305 || maxHorizontalFrequency < horizontalFrequency 306 || minVerticalFrequency > verticalFrequency 307 || maxVerticalFrequency < verticalFrequency 308 || maxPixelClock < mode.timing.pixel_clock) 309 continue; 310 } 311 312 _AddMode(mode); 313 } 314 315 return true; 316 } 317 318 319 bool 320 ModeList::AddModes(const display_mode* modes, uint32 count) 321 { 322 if (!_MakeSpace(count)) 323 return false; 324 325 for (uint32 i = 0; i < count; i++) { 326 fModes[fCount++] = modes[i]; 327 } 328 329 return true; 330 } 331 332 333 bool 334 ModeList::CreateColorSpaces(const color_space* spaces, uint32 count) 335 { 336 uint32 baseModeCount = fCount; 337 size_t baseModesSize = baseModeCount * sizeof(display_mode); 338 display_mode* baseModes = (display_mode*)malloc(baseModesSize); 339 if (baseModes == NULL) 340 return false; 341 342 memcpy(baseModes, fModes, baseModesSize); 343 344 for (uint32 i = 0; i < count; i++) { 345 if (i > 0 && !AddModes(baseModes, baseModeCount)) { 346 free(baseModes); 347 return false; 348 } 349 350 for (uint32 j = 0; j < baseModeCount; j++) { 351 fModes[j + fCount - baseModeCount].space = spaces[i]; 352 } 353 } 354 355 free(baseModes); 356 return true; 357 } 358 359 360 void 361 ModeList::Filter(check_display_mode_hook hook) 362 { 363 if (hook == NULL) 364 return; 365 366 for (uint32 i = fCount; i-- > 0;) { 367 if (!hook(&fModes[i])) 368 _RemoveModeAt(i); 369 } 370 } 371 372 373 void 374 ModeList::Clean() 375 { 376 // sort mode list 377 qsort(fModes, fCount, sizeof(display_mode), compare_mode); 378 379 // remove duplicates 380 for (uint32 i = fCount; i-- > 1;) { 381 if (compare_mode(&fModes[i], &fModes[i - 1]) == 0) 382 _RemoveModeAt(i); 383 } 384 } 385 386 387 void 388 ModeList::_AddBaseMode(uint16 width, uint16 height, uint32 refresh) 389 { 390 // Check the manually tweaked list first 391 392 for (uint32 i = 0; i < kNumBaseModes; i++) { 393 const display_mode& mode = kBaseModeList[i]; 394 395 // Add mode if width and height match, and the computed refresh rate of 396 // the mode is within 1.2 percent of the refresh rate specified by the 397 // caller. Note that refresh rates computed from mode parameters is 398 // not exact; thus, the tolerance of 1.2% was obtained by testing the 399 // various established modes that can be selected by the EDID info. 400 401 if (mode.timing.h_display == width && mode.timing.v_display == height 402 && fabs(get_refresh_rate(mode) - refresh) < refresh * 0.012) { 403 _AddMode(mode); 404 return; 405 } 406 } 407 408 // If that didn't have any entries, compute the entry 409 display_mode mode; 410 if (compute_display_timing(width, height, refresh, false, &mode.timing) 411 != B_OK) 412 return; 413 414 fill_display_mode(width, height, &mode); 415 416 _AddMode(mode); 417 } 418 419 420 display_mode* 421 ModeList::_FindMode(uint16 width, uint16 height) const 422 { 423 for (uint32 i = 0; i < fCount; i++) { 424 const display_mode& mode = fModes[i]; 425 426 if (mode.timing.h_display == width && mode.timing.v_display == height) 427 return &fModes[i]; 428 } 429 430 return NULL; 431 } 432 433 434 bool 435 ModeList::_MakeSpace(uint32 count) 436 { 437 if (fCount + count <= fCapacity) 438 return true; 439 440 uint32 capacity = (fCapacity + count + 0xf) & ~0xf; 441 display_mode* modes = (display_mode*)realloc(fModes, 442 capacity * sizeof(display_mode)); 443 if (modes == NULL) 444 return false; 445 446 fModes = modes; 447 fCapacity = capacity; 448 return true; 449 } 450 451 452 bool 453 ModeList::_AddMode(const display_mode& mode) 454 { 455 // TODO: filter by monitor timing constraints! 456 // TODO: remove double entries 457 if (!_MakeSpace(1)) 458 return false; 459 460 fModes[fCount++] = mode; 461 return true; 462 } 463 464 465 void 466 ModeList::_RemoveModeAt(uint32 index) 467 { 468 if (index < fCount - 1) { 469 memmove(&fModes[index], &fModes[index + 1], 470 (fCount - 1 - index) * sizeof(display_mode)); 471 } 472 473 fCount--; 474 } 475 476 477 // #pragma mark - 478 479 480 extern "C" area_id 481 create_display_modes(const char* name, edid1_info* edid, 482 const display_mode* initialModes, uint32 initialModeCount, 483 const color_space *spaces, uint32 spacesCount, 484 check_display_mode_hook hook, display_mode** _modes, uint32* _count) 485 { 486 if (_modes == NULL || _count == NULL) 487 return B_BAD_VALUE; 488 489 // compile initial mode list from the different sources 490 491 ModeList modes; 492 if (initialModes != NULL) 493 modes.AddModes(initialModes, initialModeCount); 494 495 if (edid != NULL) 496 modes.AddModes(edid); 497 else 498 modes.AddModes(kBaseModeList, kNumBaseModes); 499 500 // filter out modes the caller doesn't like, and multiply modes for 501 // every color space 502 503 if (spaces == NULL) { 504 const color_space kDefaultSpaces[] = {B_RGB32_LITTLE, B_RGB16_LITTLE, 505 B_RGB15_LITTLE, B_CMAP8}; 506 modes.CreateColorSpaces(kDefaultSpaces, 507 sizeof(kDefaultSpaces) / sizeof(kDefaultSpaces[0])); 508 } else 509 modes.CreateColorSpaces(spaces, spacesCount); 510 511 modes.Filter(hook); 512 modes.Clean(); 513 514 // create area for output modes 515 516 size_t size = (sizeof(display_mode) * modes.Count() + B_PAGE_SIZE - 1) 517 & ~(B_PAGE_SIZE - 1); 518 display_mode *list; 519 area_id area = create_area(name, (void **)&list, B_ANY_ADDRESS, 520 size, B_NO_LOCK, B_READ_AREA | B_WRITE_AREA); 521 if (area < B_OK) 522 return area; 523 524 memcpy(list, modes.Modes(), sizeof(display_mode) * modes.Count()); 525 *_modes = list; 526 *_count = modes.Count(); 527 528 return area; 529 } 530 531 532 void 533 fill_display_mode(uint32 width, uint32 height, display_mode* mode) 534 { 535 mode->space = B_CMAP8; 536 mode->virtual_width = width; 537 mode->virtual_height = height; 538 mode->h_display_start = 0; 539 mode->v_display_start = 0; 540 mode->flags = MODE_FLAGS; 541 } 542