| | 47 | |
| | 48 | |
| | 49 | static int |
| | 50 | compare_video_modes(video_mode *a, video_mode *b) |
| | 51 | { |
| | 52 | int compare = a->width - b->width; |
| | 53 | if (compare != 0) |
| | 54 | return compare; |
| | 55 | |
| | 56 | compare = a->height - b->height; |
| | 57 | if (compare != 0) |
| | 58 | return compare; |
| | 59 | |
| | 60 | // TODO: compare video_mode::mode? |
| | 61 | return a->bits_per_pixel - b->bits_per_pixel; |
| | 62 | } |
| | 63 | |
| | 64 | |
| | 65 | /** Insert the video mode into the list, sorted by resolution and bit depth. |
| | 66 | * Higher resolutions/depths come first. |
| | 67 | */ |
| | 68 | |
| | 69 | static void |
| | 70 | add_video_mode(video_mode *videoMode) |
| | 71 | { |
| | 72 | video_mode *mode = NULL; |
| | 73 | while ((mode = (video_mode *)list_get_next_item(&sModeList, mode)) != NULL) { |
| | 74 | int compare = compare_video_modes(videoMode, mode); |
| | 75 | if (compare == 0) { |
| | 76 | // mode already exists |
| | 77 | return; |
| | 78 | } |
| | 79 | |
| | 80 | if (compare > 0) |
| | 81 | break; |
| | 82 | } |
| | 83 | |
| | 84 | list_insert_item_before(&sModeList, mode, videoMode); |
| | 85 | } |
| | 86 | |
| | 87 | |
| | 88 | static video_mode * |
| | 89 | find_video_mode(int32 width, int32 height, int32 depth) |
| | 90 | { |
| | 91 | video_mode *mode = NULL; |
| | 92 | while ((mode = (video_mode *)list_get_next_item(&sModeList, mode)) != NULL) { |
| | 93 | if (mode->width == width |
| | 94 | && mode->height == height |
| | 95 | && mode->bits_per_pixel == depth) { |
| | 96 | return mode; |
| | 97 | } |
| | 98 | } |
| | 99 | |
| | 100 | return NULL; |
| | 101 | } |
| | 102 | |
| | 103 | |
| | 104 | static void |
| | 105 | get_mode_from_settings(void) |
| | 106 | { |
| | 107 | if (sSettingsLoaded) |
| | 108 | return; |
| | 109 | |
| | 110 | void *handle = load_driver_settings("vesa"); |
| | 111 | if (handle == NULL) |
| | 112 | return; |
| | 113 | |
| | 114 | const driver_settings *settings = get_driver_settings(handle); |
| | 115 | if (settings == NULL) |
| | 116 | goto out; |
| | 117 | |
| | 118 | sSettingsLoaded = true; |
| | 119 | |
| | 120 | for (int32 i = 0; i < settings->parameter_count; i++) { |
| | 121 | driver_parameter ¶meter = settings->parameters[i]; |
| | 122 | |
| | 123 | if (!strcmp(parameter.name, "mode") && parameter.value_count > 2) { |
| | 124 | // parameter found, now get its values |
| | 125 | int32 width = strtol(parameter.values[0], NULL, 0); |
| | 126 | int32 height = strtol(parameter.values[1], NULL, 0); |
| | 127 | int32 depth = strtol(parameter.values[2], NULL, 0); |
| | 128 | |
| | 129 | // search mode that fits |
| | 130 | |
| | 131 | video_mode *mode = find_video_mode(width, height, depth); |
| | 132 | if (mode != NULL) |
| | 133 | sMode = mode; |
| | 134 | } |
| | 135 | } |
| | 136 | |
| | 137 | out: |
| | 138 | unload_driver_settings(handle); |
| | 139 | } |
| | 140 | |
| | 141 | |
| | 142 | // #pragma mark - vga |
| 344 | | } |
| 345 | | |
| 346 | | |
| 347 | | static video_mode * |
| 348 | | find_video_mode(int32 width, int32 height, int32 depth) |
| 349 | | { |
| 350 | | video_mode *mode = NULL; |
| 351 | | while ((mode = (video_mode *)list_get_next_item(&sModeList, mode)) != NULL) { |
| 352 | | if (mode->width == width |
| 353 | | && mode->height == height |
| 354 | | && mode->bits_per_pixel == depth) { |
| 355 | | return mode; |
| 356 | | } |
| 357 | | } |
| 358 | | |
| 359 | | return NULL; |
| 360 | | } |
| 361 | | |
| 362 | | |
| 363 | | static void |
| 364 | | get_mode_from_settings(void) |
| 365 | | { |
| 366 | | if (sSettingsLoaded) |
| 367 | | return; |
| 368 | | |
| 369 | | void *handle = load_driver_settings("vesa"); |
| 370 | | if (handle == NULL) |
| 371 | | return; |
| 372 | | |
| 373 | | const driver_settings *settings = get_driver_settings(handle); |
| 374 | | if (settings == NULL) |
| 375 | | goto out; |
| 376 | | |
| 377 | | sSettingsLoaded = true; |
| 378 | | |
| 379 | | for (int32 i = 0; i < settings->parameter_count; i++) { |
| 380 | | driver_parameter ¶meter = settings->parameters[i]; |
| 381 | | |
| 382 | | if (!strcmp(parameter.name, "mode") && parameter.value_count > 2) { |
| 383 | | // parameter found, now get its values |
| 384 | | int32 width = strtol(parameter.values[0], NULL, 0); |
| 385 | | int32 height = strtol(parameter.values[1], NULL, 0); |
| 386 | | int32 depth = strtol(parameter.values[2], NULL, 0); |
| 387 | | |
| 388 | | // search mode that fits |
| 389 | | |
| 390 | | video_mode *mode = find_video_mode(width, height, depth); |
| 391 | | if (mode != NULL) |
| 392 | | sMode = mode; |
| 393 | | } |
| 394 | | } |
| 395 | | |
| 396 | | out: |
| 397 | | unload_driver_settings(handle); |