Benjamin Beaudry | 3c8e24e | 2024-02-16 19:10:32 | [diff] [blame] | 1 | # DIP to Screen/Screen to DIP Conversion |
| 2 | |
| 3 | ## Overview |
| 4 | |
| 5 | Converting positions and rectangles in screen physical pixels to screen DIPs |
| 6 | (device-independent pixels) in Chromium -- and vice versa -- is handled |
| 7 | differently on Windows compared to other platforms. This difference is due to |
| 8 | Windows' historical challenges with handling displays of DPIs higher than 96 and |
| 9 | the need to deal with multiple DPI displays. |
| 10 | |
| 11 | ## Windows |
| 12 | |
| 13 | On Windows, the process involves dealing with monitor physical coordinates and |
| 14 | mapping them into Chrome's DIP (Device Independent Pixels) coordinates. The key |
| 15 | points in this conversion process are as follows: |
| 16 | |
| 17 | 1. **Monitor Tree:** `DisplayInfosToScreenWinDisplays` reasons over monitors as |
| 18 | a tree using the primary monitor as the root. All monitors touching this root |
| 19 | are considered children. |
| 20 | |
| 21 | 2. **Connected Components:** This approach presumes that all monitors are |
| 22 | connected components. Windows restricts the layout of monitors to connected |
| 23 | components, except when DPI virtualization is happening. In the case of DPI |
| 24 | virtualization, scaling is relative to the (0, 0) point. |
| 25 | |
| 26 | 3. **Overlap Handling:** There can be cases where a scaled display may have |
| 27 | insufficient room to lay out its children. In these cases, a DIP point could map |
| 28 | to multiple screen points due to overlap. The first discovered screen point will |
| 29 | take precedence. |
| 30 | |
| 31 | ## Other Platforms |
| 32 | |
| 33 | On other platforms, such as macOS and Linux, the display information received |
| 34 | from the OS is already adjusted for display scaling. This makes it easier to |
| 35 | convert between screen coordinates and screen DIPs by simply multiplying or |
| 36 | dividing by the current screen's display scale factor. |
| 37 | |
| 38 | ## How to Use |
| 39 | |
| 40 | - **Windows:** |
| 41 | - The conversion of screen DIPs to screen coordinates is handled by the |
| 42 | `ScreenWin` class (`ui/display/win/screen_win.cc`). This class takes into |
|
|