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 QPLATFORMPIXMAP_H
5#define QPLATFORMPIXMAP_H
6
7//
8// W A R N I N G
9// -------------
10//
11// This file is part of the QPA API and is not meant to be used
12// in applications. Usage of this API may make your code
13// source and binary incompatible with future versions of Qt.
14//
15
16#include <QtGui/qtguiglobal.h>
17#include <QtGui/qpixmap.h>
18#include <QtCore/qatomic.h>
19
20QT_BEGIN_NAMESPACE
21
22
23class QImageReader;
24
25class Q_GUI_EXPORT QPlatformPixmap
26{
27public:
28 enum PixelType {
29 // WARNING: Do not change the first two
30 // Must match QPixmap::Type
31 PixmapType, BitmapType
32 };
33
34 enum ClassId { RasterClass, DirectFBClass,
35 BlitterClass, Direct2DClass,
36 X11Class, CustomClass = 1024 };
37
38 QPlatformPixmap(PixelType pixelType, int classId);
39 virtual ~QPlatformPixmap();
40
41 virtual QPlatformPixmap *createCompatiblePlatformPixmap() const;
42
43 virtual void resize(int width, int height) = 0;
44 virtual void fromImage(const QImage &image,
45 Qt::ImageConversionFlags flags) = 0;
46 virtual void fromImageInPlace(QImage &image,
47 Qt::ImageConversionFlags flags)
48 {
49 fromImage(image, flags);
50 }
51
52 virtual void fromImageReader(QImageReader *imageReader,
53 Qt::ImageConversionFlags flags);
54
55 virtual bool fromFile(const QString &filename, const char *format,
56 Qt::ImageConversionFlags flags);
57 virtual bool fromData(const uchar *buffer, uint len, const char *format,
58 Qt::ImageConversionFlags flags);
59
60 virtual void copy(const QPlatformPixmap *data, const QRect &rect);
61 virtual bool scroll(int dx, int dy, const QRect &rect);
62
63 virtual int metric(QPaintDevice::PaintDeviceMetric metric) const = 0;
64 virtual void fill(const QColor &color) = 0;
65
66 virtual QBitmap mask() const;
67 virtual void setMask(const QBitmap &mask);
68
69 virtual bool hasAlphaChannel() const = 0;
70 virtual QPixmap transformed(const QTransform &matrix,
71 Qt::TransformationMode mode) const;
72
73 virtual QImage toImage() const = 0;
74 virtual QImage toImage(const QRect &rect) const;
75 virtual QPaintEngine* paintEngine() const = 0;
76
77 inline int serialNumber() const { return ser_no; }
78
79 inline PixelType pixelType() const { return type; }
80 inline ClassId classId() const { return static_cast<ClassId>(id); }
81
82 virtual qreal devicePixelRatio() const = 0;
83 virtual void setDevicePixelRatio(qreal scaleFactor) = 0;
84
85 virtual QImage* buffer();
86
87 inline int width() const { return w; }
88 inline int height() const { return h; }
89 inline int colorCount() const { return metric(metric: QPaintDevice::PdmNumColors); }
90 inline int depth() const { return d; }
91 inline bool isNull() const { return is_null; }
92 inline qint64 cacheKey() const {
93 int classKey = id;
94 if (classKey >= 1024)
95 classKey = -(classKey >> 10);
96 return ((((qint64) classKey) << 56)
97 | (((qint64) ser_no) << 32)
98 | ((qint64) detach_no));
99 }
100
101 static QPlatformPixmap *create(int w, int h, PixelType type);
102
103protected:
104
105 void setSerialNumber(int serNo);
106 void setDetachNumber(int detNo);
107 int w;
108 int h;
109 int d;
110 bool is_null;
111
112private:
113 friend class QPixmap;
114 friend class QX11PlatformPixmap;
115 friend class QImagePixmapCleanupHooks; // Needs to set is_cached
116 friend class QOpenGLTextureCache; //Needs to check the reference count
117 friend class QExplicitlySharedDataPointer<QPlatformPixmap>;
118
119 QAtomicInt ref;
120 int detach_no;
121
122 PixelType type;
123 int id;
124 int ser_no;
125 uint is_cached;
126};
127
128# define QT_XFORM_TYPE_MSBFIRST 0
129# define QT_XFORM_TYPE_LSBFIRST 1
130Q_GUI_EXPORT bool qt_xForm_helper(const QTransform&, int, int, int, uchar*, qsizetype, int, int, const uchar*, qsizetype, int, int);
131
132QT_END_NAMESPACE
133
134#endif // QPLATFORMPIXMAP_H
135

source code of qtbase/src/gui/image/qplatformpixmap.h