1/****************************************************************************
2**
3** Copyright (C) 2016 The Qt Company Ltd.
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the QtGui module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://www.qt.io/contact-us.
16**
17** GNU Lesser General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU Lesser
19** General Public License version 3 as published by the Free Software
20** Foundation and appearing in the file LICENSE.LGPL3 included in the
21** packaging of this file. Please review the following information to
22** ensure the GNU Lesser General Public License version 3 requirements
23** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
24**
25** GNU General Public License Usage
26** Alternatively, this file may be used under the terms of the GNU
27** General Public License version 2.0 or (at your option) the GNU General
28** Public license version 3 or any later version approved by the KDE Free
29** Qt Foundation. The licenses are as published by the Free Software
30** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
31** included in the packaging of this file. Please review the following
32** information to ensure the GNU General Public License requirements will
33** be met: https://www.gnu.org/licenses/gpl-2.0.html and
34** https://www.gnu.org/licenses/gpl-3.0.html.
35**
36** $QT_END_LICENSE$
37**
38****************************************************************************/
39
40#ifndef QPIXMAP_BLITTER_P_H
41#define QPIXMAP_BLITTER_P_H
42
43//
44// W A R N I N G
45// -------------
46//
47// This file is not part of the Qt API. It exists purely as an
48// implementation detail. This header file may change from version to
49// version without notice, or even be removed.
50//
51// We mean it.
52//
53
54#include <QtGui/private/qtguiglobal_p.h>
55#include <qpa/qplatformpixmap.h>
56#include <private/qpaintengine_blitter_p.h>
57
58#ifndef QT_NO_BLITTABLE
59QT_BEGIN_NAMESPACE
60
61class Q_GUI_EXPORT QBlittablePlatformPixmap : public QPlatformPixmap
62{
63// Q_DECLARE_PRIVATE(QBlittablePlatformPixmap)
64public:
65 QBlittablePlatformPixmap();
66 ~QBlittablePlatformPixmap();
67
68 virtual QBlittable *createBlittable(const QSize &size, bool alpha) const = 0;
69 QBlittable *blittable() const;
70 void setBlittable(QBlittable *blittable);
71
72 void resize(int width, int height) override;
73 int metric(QPaintDevice::PaintDeviceMetric metric) const override;
74 void fill(const QColor &color) override;
75 QImage *buffer() override;
76 QImage toImage() const override;
77 bool hasAlphaChannel() const override;
78 void fromImage(const QImage &image, Qt::ImageConversionFlags flags) override;
79 qreal devicePixelRatio() const override;
80 void setDevicePixelRatio(qreal scaleFactor) override;
81
82 QPaintEngine *paintEngine() const override;
83
84 void markRasterOverlay(const QRectF &);
85 void markRasterOverlay(const QPointF &, const QTextItem &);
86 void markRasterOverlay(const QVectorPath &);
87 void markRasterOverlay(const QPainterPath &);
88 void markRasterOverlay(const QRect *rects, int rectCount);
89 void markRasterOverlay(const QRectF *rects, int rectCount);
90 void markRasterOverlay(const QPointF *points, int pointCount);
91 void markRasterOverlay(const QPoint *points, int pointCount);
92 void unmarkRasterOverlay(const QRectF &);
93
94#ifdef QT_BLITTER_RASTEROVERLAY
95 void mergeOverlay();
96 void unmergeOverlay();
97 QImage *overlay();
98
99#endif //QT_BLITTER_RASTEROVERLAY
100protected:
101 QScopedPointer<QBlitterPaintEngine> m_engine;
102 QScopedPointer<QBlittable> m_blittable;
103 bool m_alpha;
104 qreal m_devicePixelRatio;
105
106#ifdef QT_BLITTER_RASTEROVERLAY
107 QImage *m_rasterOverlay;
108 QImage *m_unmergedCopy;
109 QColor m_overlayColor;
110
111 void markRasterOverlayImpl(const QRectF &);
112 void unmarkRasterOverlayImpl(const QRectF &);
113 QRectF clipAndTransformRect(const QRectF &) const;
114#endif //QT_BLITTER_RASTEROVERLAY
115
116};
117
118inline void QBlittablePlatformPixmap::markRasterOverlay(const QRectF &rect)
119{
120#ifdef QT_BLITTER_RASTEROVERLAY
121 markRasterOverlayImpl(rect);
122#else
123 Q_UNUSED(rect);
124#endif
125}
126
127inline void QBlittablePlatformPixmap::markRasterOverlay(const QVectorPath &path)
128{
129#ifdef QT_BLITTER_RASTEROVERLAY
130 markRasterOverlayImpl(path.convertToPainterPath().boundingRect());
131#else
132 Q_UNUSED(path);
133#endif
134}
135
136inline void QBlittablePlatformPixmap::markRasterOverlay(const QPointF &pos, const QTextItem &ti)
137{
138#ifdef QT_BLITTER_RASTEROVERLAY
139 QFontMetricsF fm(ti.font());
140 QRectF rect = fm.tightBoundingRect(ti.text());
141 rect.moveBottomLeft(pos);
142 markRasterOverlay(rect);
143#else
144 Q_UNUSED(pos);
145 Q_UNUSED(ti);
146#endif
147}
148
149inline void QBlittablePlatformPixmap::markRasterOverlay(const QRect *rects, int rectCount)
150{
151#ifdef QT_BLITTER_RASTEROVERLAY
152 for (int i = 0; i < rectCount; i++) {
153 markRasterOverlay(rects[i]);
154 }
155#else
156 Q_UNUSED(rects);
157 Q_UNUSED(rectCount);
158#endif
159}
160inline void QBlittablePlatformPixmap::markRasterOverlay(const QRectF *rects, int rectCount)
161{
162#ifdef QT_BLITTER_RASTEROVERLAY
163 for (int i = 0; i < rectCount; i++) {
164 markRasterOverlay(rects[i]);
165 }
166#else
167 Q_UNUSED(rects);
168 Q_UNUSED(rectCount);
169#endif
170}
171
172inline void QBlittablePlatformPixmap::markRasterOverlay(const QPointF *points, int pointCount)
173{
174#ifdef QT_BLITTER_RASTEROVERLAY
175#error "not ported yet"
176#else
177 Q_UNUSED(points);
178 Q_UNUSED(pointCount);
179#endif
180}
181
182inline void QBlittablePlatformPixmap::markRasterOverlay(const QPoint *points, int pointCount)
183{
184#ifdef QT_BLITTER_RASTEROVERLAY
185#error "not ported yet"
186#else
187 Q_UNUSED(points);
188 Q_UNUSED(pointCount);
189#endif
190}
191
192inline void QBlittablePlatformPixmap::markRasterOverlay(const QPainterPath& path)
193{
194#ifdef QT_BLITTER_RASTEROVERLAY
195#error "not ported yet"
196#else
197 Q_UNUSED(path);
198#endif
199}
200
201inline void QBlittablePlatformPixmap::unmarkRasterOverlay(const QRectF &rect)
202{
203#ifdef QT_BLITTER_RASTEROVERLAY
204 unmarkRasterOverlayImpl(rect);
205#else
206 Q_UNUSED(rect);
207#endif
208}
209
210QT_END_NAMESPACE
211#endif // QT_NO_BLITTABLE
212#endif // QPIXMAP_BLITTER_P_H
213