/****************************************************************************
**
** Copyright (C) 2020 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the documentation of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:FDL$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU Free Documentation License Usage
** Alternatively, this file may be used under the terms of the GNU Free
** Documentation License version 1.3 as published by the Free Software
** Foundation and appearing in the file included in the packaging of
** this file. Please review the following information to ensure
** the GNU Free Documentation License version 1.3 requirements
** will be met: https://www.gnu.org/licenses/fdl-1.3.html.
** $QT_END_LICENSE$
**
****************************************************************************/
/*!
    \page highdpi.html
    \title High DPI
    \brief Describes Qt's support for high DPI displays.

    High-DPI displays – also known as retina displays – are displays with high
    resolution (pixels) in relation to their physical size (mm), resulting in a
    high pixel density, or high number of \e{dots per inch} (DPI). The increased
    resolution is used to provide more detailed content on screen (smoother text,
    more detailed icons), rather than more content (more windows, larger window
    sizes).

    Qt supports high-DPI displays on all platforms, and provides a unified API
    that abstracts over any platform differences. Qt will automatically account
    for the display resolution when using  higher level APIs such as Qt Widgets
    and Qt Quick, and applications only need to provide high-resolution assets,
    such as images and icons. Changes in the platform's user preferences are
    automatically picked up.

    Lower-level graphics drawing (such as OpenGL code) need to be high-DPI aware,
    but can use cross platform Qt APIs to learn about the platform's display
    resolutions.

    \section1 Conceptual Model

    Qt uses a model where the application coordinate system is independent of the
    display device resolution. The application operates in \e{device-independent pixels},
    which are then mapped to the physical pixels of the display via a scale factor,
    known as the \e{device pixel ratio}. The scale factor is expressed as a floating
    point number, for example \c 1.0 or \c 2.0, or informally as \c 1x and \c 2x.

    For example, creating a QWindow or QWidget, and setting its size to 200x200
    will result in a corresponding window of 200x200 pixels on a normal density
    display (with a device pixel ratio of 1.0), but will result in a window of
    400x400 pixel on a high density display (with a device pixel ratio of 2.0).

    This model applies to most units in higher level Qt Gui, Widgets, and Quick
    APIs, including widget and item geometry, event geometry, desktop, window and
    screen geometry, as well as animation velocities.

    \note The model does not handle differences between UI classes, such as the
    size of touch targets vs mouse targets.

    \section1 Drawing

    Qt will automatically take advantage of the increased density of a high-DPI
    display when using drawing APIs such as QPainter, or when rendering graphic
    primitives or text in Qt Quick.

    As a result the application can operate in a single unified coordinate system,
    without needing to account for the possible display densities the application
    will run on.

    However, when using lower level drawing APIs, for example OpenGL, the
    application needs to take the device pixel ratio of the display into
    account. This is available both per window, as QWindow::devicePixelRatio()
    (tracking the device pixel ratio of the window when moved between displays),
    or per display, as QScreen::devicePixelRatio().

    Image buffers such as QImage and QPixmap represent the raw pixels, and
    as a result do not operate in the device independent coordinate system
    described earlier. A QImage of size 400x400, with a device pixel ratio
    of 2.0, will fit a 200x200 QWindow on a high density (2x) display, or
    will be automatically downscaled to 200x200 during drawing if targeting
    a normal density (1x) display. See \l{Drawing High Resolution Versions
    of Pixmaps and Images} for more details.

    \section1 Image Assets

    To take advantage of the increased pixel density of high-DPI displays,
    the application should also include high-DPI versions of static image
    assets. This is achieved by using a special naming convention for the
    high density assets, for example \c logo@2x.png, and loading both the
    normal density image and the high-density image into a QIcon. Qt will
    automatically choose the best representation for the target display at
    runtime. See \l{High DPI Icons} for more details.

    \section1 Configuring

    As an end user you may want to adjust the DPI or scale settings to
    match display hardware, or to account for viewing distance and personal
    preferences. These adjustments should be done using the native display
    settings of the platform, so that all applications will agree on the same
    DPI or scale factor values. Qt does not provide end user facilities to
    configure the behavior of Qt's high-DPI support.

    The operating system may represent the scale factor either as a factor (1.5),
    as a percentage (150%), or as dots per inch (144 DPI). Qt translates these
    to the device pixel ratio seen by the application. In the latter case
    Qt assumes a "base" DPI – e.g 96 on X11 – and calculates the resulting
    device pixel ratio accordingly.

    Integer scale factors (e.g. 1.0 or 2.0) are preferred for best results.
    "Rounding" the scale factor to 25% increments can also give good results.
    Setting the scale factor or DPI to the exact physical display DPI may not
    give good visual results due to the fractional scaling involved. If the
    application suffers from visual artifacts in this scenario, it can use
    QGuiApplication::setHighDpiScaleFactorRoundingPolicy() to limit the scale
    factors it will see.

    \section2 Platform Details

    The following table describes how to configure high-DPI on various platforms.

    \table
        \header
            \li Platform
            \li Configuration
        \row
            \li \macos
            \li Set the scale for each display in the display preferences.
                \macos will reflect this to Qt as an integer device pixel ratio.
        \row
            \li Windows
            \li Set the scale factor for each display in the display settings.
                The base scale factor is 100%, and can be adjusted in 25% steps.
        \row
            \li Ubuntu
            \li Set the scale factor in display settings. On Ubuntu 20.04 and later
                this can be done per display, in increments of 25%. Earlier versions
                support setting a global scale to either 100% or 200%.
        \row
            \li X11
            \li Set the \c Xft.dpi setting, which is a global logical DPI.
                Qt assumes that the base DPI is 96, and scales the UI accordingly.
        \row
            \li Wayland
            \li Qt reads \c{wl_output::scale}, which is restricted to integer values.
                Wayland compositors typically have a configuration option for setting
                the scale factor, for example \c{weston --scale}.
        \row
            \li EGLFS
            \li Set \c QT_FONT_DPI to the desired logical DPI value, for example \c{QT_FONT_DPI=192}.
                Qt assumes that the base DPI is 96, and scales the UI accordingly.
    \endtable

    \note Some windowing systems may have limitations that are then reflected
    in Qt. Qt does not provide workarounds for these limitations. Instead,
    consider workarounds on the windowing system level.

    \section1 Testing

    The DprGadget test application can be used to inspect the native
    configuration, and how Qt reacts to it:

    \image dprgadget.png

    DprGadget displays the device pixel ratio of the window, as reported by
    QWindow::devicePixelRatio(). In addition is displays the native DPI and
    device pixel ratio of the screen the widow is on, as reported by
    QPlatformScreen::logicalDpi() and QPlatformScreen::devicePixelRatio().

    The displayed values should be updated automatically on screen and DPI
    changes, and the dialog should maintain the same size. If this does happen
    then that indicate there might be a bug in Qt.

    DprGradget is a part Qt's manual test suite, and can
    be found at \c{qtbase/tests/manual/highdpi/pixelgadget}.
*/
