Coverage Report

Created: 2026-03-31 07:41

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/work/prefix/include/QtGui/qpaintdevice.h
Line
Count
Source
1
// Copyright (C) 2016 The Qt Company Ltd.
2
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
// Qt-Security score:significant reason:default
4
5
#ifndef QPAINTDEVICE_H
6
#define QPAINTDEVICE_H
7
8
#include <QtGui/qtguiglobal.h>
9
#include <QtGui/qwindowdefs.h>
10
#include <QtCore/qrect.h>
11
12
QT_BEGIN_NAMESPACE
13
14
15
16
class QPaintEngine;
17
18
class Q_GUI_EXPORT QPaintDevice                                // device for QPainter
19
{
20
public:
21
    enum PaintDeviceMetric {
22
        PdmWidth = 1,
23
        PdmHeight,
24
        PdmWidthMM,
25
        PdmHeightMM,
26
        PdmNumColors,
27
        PdmDepth,
28
        PdmDpiX,
29
        PdmDpiY,
30
        PdmPhysicalDpiX,
31
        PdmPhysicalDpiY,
32
        PdmDevicePixelRatio,
33
        PdmDevicePixelRatioScaled,
34
        PdmDevicePixelRatioF_EncodedA,
35
        PdmDevicePixelRatioF_EncodedB,
36
    };
37
38
    virtual ~QPaintDevice();
39
40
    virtual int devType() const;
41
    bool paintingActive() const;
42
    virtual QPaintEngine *paintEngine() const = 0;
43
44
0
    int width() const { return metric(PdmWidth); }
45
0
    int height() const { return metric(PdmHeight); }
46
0
    int widthMM() const { return metric(PdmWidthMM); }
47
0
    int heightMM() const { return metric(PdmHeightMM); }
48
0
    int logicalDpiX() const { return metric(PdmDpiX); }
49
0
    int logicalDpiY() const { return metric(PdmDpiY); }
50
0
    int physicalDpiX() const { return metric(PdmPhysicalDpiX); }
51
0
    int physicalDpiY() const { return metric(PdmPhysicalDpiY); }
52
    qreal devicePixelRatio() const;
53
0
    qreal devicePixelRatioF()  const { return devicePixelRatio(); }
54
0
    int colorCount() const { return metric(PdmNumColors); }
55
0
    int depth() const { return metric(PdmDepth); }
56
57
0
    static inline qreal devicePixelRatioFScale() { return 0x10000; }
58
    static inline int encodeMetricF(PaintDeviceMetric metric, double value);
59
protected:
60
    QPaintDevice() noexcept;
61
    virtual int metric(PaintDeviceMetric metric) const;
62
    virtual void initPainter(QPainter *painter) const;
63
    virtual QPaintDevice *redirected(QPoint *offset) const;
64
    virtual QPainter *sharedPainter() const;
65
    double getDecodedMetricF(PaintDeviceMetric metricA, PaintDeviceMetric metricB) const;
66
67
    ushort        painters;                        // refcount
68
private:
69
    Q_DISABLE_COPY(QPaintDevice)
70
71
    friend class QPainter;
72
    friend class QPainterPrivate;
73
    friend class QFontEngineMac;
74
    friend class QX11PaintEngine;
75
    friend Q_GUI_EXPORT int qt_paint_device_metric(const QPaintDevice *device, PaintDeviceMetric metric);
76
};
77
78
/*****************************************************************************
79
  Inline functions
80
 *****************************************************************************/
81
82
inline int QPaintDevice::devType() const
83
0
{ return QInternal::UnknownDevice; }
84
85
inline bool QPaintDevice::paintingActive() const
86
0
{ return painters != 0; }
87
88
inline int QPaintDevice::encodeMetricF(PaintDeviceMetric metric, double value)
89
0
{
90
0
    qint32 buf[2];
91
0
    Q_STATIC_ASSERT(sizeof(buf) == sizeof(double));
92
0
    memcpy(buf, &value, sizeof(buf));
93
0
    return buf[metric & 1];
94
0
}
95
96
QT_END_NAMESPACE
97
98
#endif // QPAINTDEVICE_H