| 65 | |
| 66 | #if !defined(TARGET_IOS) && !defined(TARGET_IOS_SIMULATOR) |
| 67 | void getRecommendedResolution(RectDesc* rect) |
| 68 | { |
| 69 | float dpiScale[2]; |
| 70 | const uint32_t monitorIdx = getActiveMonitorIdx(); |
| 71 | getMonitorDpiScale(monitorIdx, dpiScale); |
| 72 | |
| 73 | MonitorDesc* pMonitor = getMonitor(monitorIdx); |
| 74 | |
| 75 | // Early exit |
| 76 | if (arrlenu(pMonitor->resolutions) == 1) |
| 77 | { |
| 78 | rect->left = 0; |
| 79 | rect->top = 0; |
| 80 | rect->right = (int32_t)pMonitor->resolutions[0].mWidth; |
| 81 | rect->bottom = (int32_t)pMonitor->resolutions[0].mHeight; |
| 82 | return; |
| 83 | } |
| 84 | |
| 85 | rect->left = 0; |
| 86 | rect->top = 0; |
| 87 | |
| 88 | ASSERT(pMonitor->resolutions && pMonitor->currentResolution < arrlen(pMonitor->resolutions)); |
| 89 | |
| 90 | const uint32_t monitorWidth = (uint32_t)pMonitor->resolutions[pMonitor->currentResolution].mWidth; |
| 91 | const uint32_t monitorHeight = (uint32_t)pMonitor->resolutions[pMonitor->currentResolution].mHeight; |
| 92 | |
| 93 | const uint32_t desiredWidth = (uint32_t)(monitorWidth * RECOMMENDED_WINDOW_SIZE_DISPLAY_FRACTION); |
| 94 | const uint32_t desiredHeight = (uint32_t)(monitorHeight * RECOMMENDED_WINDOW_SIZE_DISPLAY_FRACTION); |
| 95 | |
| 96 | const uint32_t minWidth = (uint32_t)(desiredWidth * RECOMMENDED_WINDOW_SIZE_MIN_DESIRED_FRACTION); |
| 97 | const uint32_t minHeight = (uint32_t)(desiredHeight * RECOMMENDED_WINDOW_SIZE_MIN_DESIRED_FRACTION); |
| 98 | |
| 99 | uint32_t resultIndex = UINT32_MAX; |
| 100 | uint32_t resultWidth = 0; |
| 101 | uint32_t resultHeight = 0; |
| 102 | |
| 103 | // The search is based on the constraints below, which are relaxed one by one |
| 104 | // until we find some valid resolution. |
| 105 | // 1. Resolution should be divisible by the factor. |
| 106 | // Ensures that odd resolutions are not selected. |
| 107 | // 2. Resolution should be bigger than min desired |
| 108 | // Ensures that resolution is not too far off from the desired |
| 109 | // 3. Resolution should be less or equal to desired resolution |
| 110 | // Ensures that resolution can fit onto screen. |
| 111 | // 4. Resolution should be less than display resolution |
| 112 | // |
| 113 | // Also we always take bigger resolution of the two that satisfy the constraints |
| 114 | |
| 115 | for (uint32_t factor = RECOMMENDED_WINDOW_SIZE_FACTOR; factor > 0 && resultIndex == UINT32_MAX; factor = factor >> 1) |
| 116 | { |
| 117 | for (uint32_t i = 0; i < arrlenu(pMonitor->resolutions); ++i) |
| 118 | { |
| 119 | const Resolution resolution = pMonitor->resolutions[i]; |
| 120 | |
| 121 | if (resolution.mWidth % factor == 0 && resolution.mHeight % factor == 0 && resolution.mWidth >= minWidth && |
| 122 | resolution.mHeight >= minHeight && resolution.mWidth <= desiredWidth && resolution.mHeight <= desiredHeight && |
| 123 | resolution.mWidth >= resultWidth && resolution.mHeight >= resultHeight) |
| 124 | { |
no test coverage detected