Skip to content

Commit df3a96b

Browse files
authored
Add docs on physical-size, logical-size and pixel-ratio to guide (#129)
1 parent 9bf502a commit df3a96b

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed

docs/start.rst

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,56 @@ Rendering with wgpu:
7070
# ... wgpu code
7171
7272
73+
Physical size, logical size, and pixel-ratio
74+
--------------------------------------------
75+
76+
The context has properties for the logical size, physical size, and the
77+
pixel-ratio.
78+
79+
* The physical size represent the actual number of "harware pixels" of the canvas surface.
80+
* The logical size represents the size in "virtual pixels", which is used to scale elements like text, points, line thickness etc.
81+
* The pixel-ratio represents the factor between the physical size and the logical size.
82+
83+
On regular screens, the physical size and logical size are often equal:
84+
85+
.. code-block::
86+
87+
+----+----+----+----+
88+
| | | | | Physical pixels
89+
+----+----+----+----+
90+
+----+----+
91+
| | | Logical pixels, pixel-ratio 1.0
92+
+----+----+
93+
94+
On HiDPI / Retina displays, there are many more pixels, but they are much smaller. To prevent things like text to become tiny,
95+
the logical pixels are made larger, i.e. pixel-ratio is increased (by the operating system), usually by a factor 2:
96+
97+
.. code-block::
98+
99+
+--+--+--+--+
100+
| | | | | Physical pixels
101+
+--+--+--+--+
102+
+-----+-----+
103+
| | | Logical pixels, pixel-ratio 2.0
104+
+-----+-----+
105+
106+
Other operating system may increase the pixel-ratio as a global zoom factor, to increase the size of elements such as text in all applications.
107+
This means that the pixel-ratio can indeed be fractional:
108+
109+
.. code-block::
110+
111+
+----+----+----+----+
112+
| | | | | Physical pixels
113+
+----+----+----+----+
114+
+-----+-----+
115+
| | | Logical pixels, pixel-ratio ± 1.2
116+
+-----+-----+
117+
118+
Side note: on MacOS, the pixel-ratio is fixed to either 1.0 or 2.0, usually the latter on a Retina display with reasonable resolution settings. (The OS level
119+
zooming is implemented by rendering the whole screen to an offscreen buffer with
120+
a different size than the physical screen, and then up/down-scaling that to the
121+
screen.)
122+
73123

74124
.. _async:
75125

0 commit comments

Comments
 (0)