Skip to content

Commit 27f19ba

Browse files
authored
Merge pull request #477 from rdkcentral/docs/dpi
Documentation update for the device-pixel-ratio and precision
2 parents a0c8891 + fc0d5a9 commit 27f19ba

1 file changed

Lines changed: 24 additions & 5 deletions

File tree

docs/RuntimeConfig/index.md

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ const App = new MyApp(options);
3535
| `w` | Number | 1920 | Stage width in pixels |
3636
| `h` | Number | 1080 | Stage height in pixels |
3737
| `precision` | Float | 1 | Global stage scaling (see details below) |
38+
| `devicePixelRatio` | Float | 1 | Handling high DPI (see details below) |
3839
| `memoryPressure` | Number | 24e6 | Maximum GPU memory usage in pixels (see details below) |
3940
| `clearColor` | Float[] | [0,0,0,0] | Background color in ARGB values (0 to 1) |
4041
| `defaultFontFace` | String | "sans-serif" | Default font family to use for text. See the [fontFace Text property](../RenderEngine/Textures/Text.md#properties) for how this value ends up being used. The special [CSS defined font family values](https://developer.mozilla.org/en-US/docs/Web/CSS/font-family#values) of "serif" and "sans-serif" may be used as well. |
@@ -52,21 +53,39 @@ const App = new MyApp(options);
5253
| `devicePixelRatio` | Number | 1 | The DPR is the logical to physical pixel density for a touch enabled device and affects how we calculate collisions |
5354

5455

55-
## Downscaling
56+
## Global stage scaling
5657

5758
> We advise you to always develop your TV App in a **1080p** coordinate system (the Lightning default).
5859
5960

60-
Assume that you have created an App for 1080p quality, so you have used a 1920x1080 coordinate system to position all of the content. However, you have found out that the App needs to be displayed in a 1280x720 resolution.
61+
Assume that you have created an App for 1080p quality, where you've used a 1920x1080 coordinate system to position all of the content. However, you've found out that the App needs to be displayed in a 1280x720 resolution.
6162

6263

63-
You can use the `precision` property to perform a *global rescale* of the coordinate system. For example, if you specify `precision: 2/3`, the 1920 x-position will be mapped to the 1280-output pixel coordinate.
64+
To make this adjustment, you can use the `precision` property to perform a *global rescale* of the coordinate system. For example, if you specify `precision: 2/3`, the 1920 x-position will be mapped to the 1280-output pixel coordinate. This downscaling generally works well and can improve quality (less pixel interpolation) while reducing memory usage.
6465

66+
By setting `precision: 2`, the 1920 x-position will be mapped to a 3840-output pixel coordinate, effectively upscaling the content for 4K resolution. Please note that upscaling may result in reduced performance due to the higher GPU memory usage.
6567

66-
As a result, the text and off-screen textures are rendered at a *lower resolution* by the [Render Engine](../RenderEngine/index.md), which increases quality (less pixel interpolation) and reduces memory usage.
68+
Keep in mind that WebGL rasterizes at pixel boundaries. This means that when it uses a line width of 2 in 1080p quality, it may render at either 2px or 3px in 720p (depending on the rendered pixel offset). If you encounter such problems, you'll need to set the sizing at a multiple of 3 to ensure proper rendering.
6769

70+
# Handling high pixel density (high DPI)
6871

69-
Downscaling with the `precision` option generally works well. But keep in mind that WebGL rasterizes as *pixel boundaries*, so when it uses a line width of 2 in 1080p quality, it may render at either 2px or 3px in 720p (depending on the rendered pixel offset). If you encounter such problems, you have to set the sizing at a multiple of 3.
72+
With the increasing number of devices in the market having high pixel densities (DPI), it's important to handle high DPI properly in your Lightning app. Fortunately, you can take advantage of the higher resolution by setting the devicePixelRatio property, which is a minor and generally non-disruptive change.
73+
It's worth noting that canvas elements, like most graphics elements, have two sizes
74+
75+
- The size they are displayed in the page
76+
- The size of their content
77+
78+
For a canvas element, the size of the content or drawingBuffer is determined by the width and height attributes of the canvas, while the display size is determined by the CSS attributes applied to the canvas. Setting `devicePixelRatio: 2` will result in the following:
79+
80+
```html
81+
<canvas width="3840" height="2060" style="width: 1920px; height: 1080px;"></canvas>
82+
```
83+
84+
a canvas that has a drawingBuffer of size 3840x2060 pixels but is displayed at a 1920x1080 viewport.
85+
86+
When viewed on High DPI displays, the browser will automatically upscale the canvas content to ensure that it appears at the correct size on the screen. However, if the devicePixelRatio (DPR) is not set properly, a Lightning application may appear to render at a lower-than-native resolution, which can introduce aliasing.
87+
88+
It's essential to handle high DPI properly to ensure that your Lightning app looks crisp and clear on high DPI displays
7089

7190

7291
## FontSharp

0 commit comments

Comments
 (0)