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