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