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