/src/qtbase/src/gui/painting/qpaintdevice.cpp
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 | | #include "qpaintdevice.h" |
6 | | |
7 | | QT_BEGIN_NAMESPACE |
8 | | |
9 | | QPaintDevice::QPaintDevice() noexcept |
10 | 386M | { |
11 | 386M | painters = 0; |
12 | 386M | } |
13 | | |
14 | | QPaintDevice::~QPaintDevice() |
15 | 386M | { |
16 | 386M | if (paintingActive()) |
17 | 386M | qWarning("QPaintDevice: Cannot destroy paint device that is being " |
18 | 0 | "painted"); |
19 | 386M | } |
20 | | |
21 | | /*! |
22 | | \internal |
23 | | */ |
24 | | // ### Qt 7: Replace this workaround mechanism: virtual devicePixelRatio() and virtual metricF() |
25 | | double QPaintDevice::getDecodedMetricF(PaintDeviceMetric metricA, PaintDeviceMetric metricB) const |
26 | 0 | { |
27 | 0 | qint32 buf[2]; |
28 | | // The Encoded metric enum values come in pairs of one odd and one even value. |
29 | | // We map those to the 0 and 1 indexes of buf by taking just the least significant bit. |
30 | | // Same mapping here as in the encodeMetricF() function, to ensure correct order. |
31 | 0 | buf[metricA & 1] = metric(metricA); |
32 | 0 | buf[metricB & 1] = metric(metricB); |
33 | 0 | double res; |
34 | 0 | memcpy(&res, buf, sizeof(res)); |
35 | 0 | return res; |
36 | 0 | } |
37 | | |
38 | | qreal QPaintDevice::devicePixelRatio() const |
39 | 132k | { |
40 | 132k | Q_STATIC_ASSERT((PdmDevicePixelRatioF_EncodedA & 1) != (PdmDevicePixelRatioF_EncodedB & 1)); |
41 | 132k | double res; |
42 | 132k | int scaledDpr = metric(PdmDevicePixelRatioScaled); |
43 | 132k | if (scaledDpr == int(devicePixelRatioFScale())) { |
44 | 132k | res = 1; // Shortcut for common case |
45 | 132k | } else if (scaledDpr == 2 * int(devicePixelRatioFScale())) { |
46 | 0 | res = 2; // Shortcut for common case |
47 | 0 | } else { |
48 | 0 | res = getDecodedMetricF(PdmDevicePixelRatioF_EncodedA, PdmDevicePixelRatioF_EncodedB); |
49 | 0 | if (res <= 0) // These metrics not implemented, fall back to PdmDevicePixelRatioScaled |
50 | 0 | res = scaledDpr / devicePixelRatioFScale(); |
51 | 0 | } |
52 | 132k | return res; |
53 | 132k | } |
54 | | |
55 | | /*! |
56 | | \internal |
57 | | */ |
58 | | void QPaintDevice::initPainter(QPainter *) const |
59 | 109k | { |
60 | 109k | } |
61 | | |
62 | | /*! |
63 | | \internal |
64 | | */ |
65 | | QPaintDevice *QPaintDevice::redirected(QPoint *) const |
66 | 109k | { |
67 | 109k | return nullptr; |
68 | 109k | } |
69 | | |
70 | | /*! |
71 | | \internal |
72 | | */ |
73 | | QPainter *QPaintDevice::sharedPainter() const |
74 | 219k | { |
75 | 219k | return nullptr; |
76 | 219k | } |
77 | | |
78 | | Q_GUI_EXPORT int qt_paint_device_metric(const QPaintDevice *device, QPaintDevice::PaintDeviceMetric metric) |
79 | 0 | { |
80 | 0 | return device->metric(metric); |
81 | 0 | } |
82 | | |
83 | | int QPaintDevice::metric(PaintDeviceMetric m) const |
84 | 0 | { |
85 | | // Fallback: A subclass has not implemented PdmDevicePixelRatioScaled but might |
86 | | // have implemented PdmDevicePixelRatio. |
87 | 0 | if (m == PdmDevicePixelRatioScaled) |
88 | 0 | return this->metric(PdmDevicePixelRatio) * devicePixelRatioFScale(); |
89 | 0 | if (m == PdmNumColors) |
90 | 0 | return 0; |
91 | 0 | if (m == PdmDevicePixelRatio) |
92 | 0 | return 1; |
93 | | |
94 | 0 | qWarning("QPaintDevice::metrics: Device has no metric information"); |
95 | |
|
96 | 0 | switch (m) { |
97 | 0 | case PdmDevicePixelRatioScaled: |
98 | 0 | case PdmDevicePixelRatio: |
99 | 0 | case PdmNumColors: |
100 | 0 | Q_UNREACHABLE(); |
101 | 0 | break; |
102 | 0 | case PdmDpiX: |
103 | 0 | case PdmDpiY: |
104 | 0 | return 72; |
105 | 0 | case PdmDevicePixelRatioF_EncodedA: |
106 | 0 | case PdmDevicePixelRatioF_EncodedB: |
107 | 0 | return 0; |
108 | 0 | case PdmWidth: |
109 | 0 | case PdmHeight: |
110 | 0 | case PdmWidthMM: |
111 | 0 | case PdmHeightMM: |
112 | 0 | case PdmDepth: |
113 | 0 | case PdmPhysicalDpiX: |
114 | 0 | case PdmPhysicalDpiY: |
115 | 0 | return 0; |
116 | 0 | } |
117 | 0 | qDebug("Unrecognized metric %d!", m); |
118 | 0 | return 0; |
119 | 0 | } |
120 | | |
121 | | QT_END_NAMESPACE |