1 /****************************************************************************
3 ** Copyright (C) 2015 The Qt Company Ltd.
4 ** Copyright (C) 2016 Ivailo Monev
6 ** This file is part of the QtGui module of the Katie Toolkit.
8 ** $QT_BEGIN_LICENSE:LGPL$
10 ** GNU Lesser General Public License Usage
11 ** This file may be used under the terms of the GNU Lesser
12 ** General Public License version 2.1 as published by the Free Software
13 ** Foundation and appearing in the file LICENSE.LGPL included in the
14 ** packaging of this file. Please review the following information to
15 ** ensure the GNU Lesser General Public License version 2.1 requirements
16 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
20 ****************************************************************************/
22 #ifndef QPAINTENGINE_RASTER_P_H
23 #define QPAINTENGINE_RASTER_P_H
29 // This file is not part of the Katie API. It exists for the convenience
30 // of other Qt classes. This header file may change from version to
31 // version without notice, or even be removed.
36 #include "qpaintengineex_p.h"
37 #include "QtGui/qpainterpath.h"
38 #include "qdrawhelper_p.h"
39 #include "qpaintengine_p.h"
40 #include "qrasterizer_p.h"
41 #include "qstroker_p.h"
42 #include "qpainter_p.h"
43 #include "qfontengine_p.h"
44 #include "qoutlinemapper_p.h"
50 class QRasterPaintEnginePrivate;
54 class QRasterPaintEngineState : public QPainterState
57 QRasterPaintEngineState(QRasterPaintEngineState &other);
58 QRasterPaintEngineState();
59 ~QRasterPaintEngineState();
65 QPaintEngine::DirtyFlags strokeFlags;
69 QPaintEngine::DirtyFlags fillFlags;
77 // QRegion clipRegion;
79 // QPainter::RenderHints hints;
80 // QPainter::CompositionMode compositionMode;
82 QPaintEngine::DirtyFlags dirty;
85 bool has_clip_ownership; // should delete the clip member..
86 bool non_complex_pen; // can use rasterizer, rather than stroker
98 /*******************************************************************************
101 class QRasterPaintEngine : public QPaintEngineEx
103 Q_DECLARE_PRIVATE(QRasterPaintEngine)
106 QRasterPaintEngine(QPaintDevice *device);
107 bool begin(QPaintDevice *device);
112 void brushOriginChanged();
113 void opacityChanged();
114 void compositionModeChanged();
115 void renderHintsChanged();
116 void transformChanged();
117 void clipEnabledChanged();
119 void setState(QPainterState *s);
120 QPainterState *createState(QPainterState *orig) const;
121 inline QRasterPaintEngineState *state() {
122 return static_cast<QRasterPaintEngineState *>(QPaintEngineEx::state());
124 inline const QRasterPaintEngineState *state() const {
125 return static_cast<const QRasterPaintEngineState *>(QPaintEngineEx::state());
128 void updateBrush(const QBrush &brush);
129 void updatePen(const QPen &pen);
131 void updateMatrix(const QTransform &matrix);
133 void drawPolygon(const QPointF *points, int pointCount, PolygonDrawMode mode);
134 void drawPolygon(const QPoint *points, int pointCount, PolygonDrawMode mode);
135 void fillPath(const QPainterPath &path, QSpanData *fillData);
136 void fillPolygon(const QPointF *points, int pointCount, PolygonDrawMode mode);
138 void drawEllipse(const QRectF &rect);
140 void fillRect(const QRectF &rect, const QBrush &brush);
141 void fillRect(const QRectF &rect, const QColor &color);
143 void drawRects(const QRect *rects, int rectCount);
145 void drawPixmap(const QPointF &p, const QPixmap &pm);
146 void drawPixmap(const QRectF &r, const QPixmap &pm, const QRectF &sr);
147 void drawImage(const QPointF &p, const QImage &img);
148 void drawImage(const QRectF &r, const QImage &pm, const QRectF &sr,
149 Qt::ImageConversionFlags flags = Qt::AutoColor);
150 void drawTiledPixmap(const QRectF &r, const QPixmap &pm, const QPointF &sr);
151 void drawTextItem(const QPointF &p, const QTextItem &textItem);
153 void drawLines(const QLine *line, int lineCount);
154 void drawLines(const QLineF *line, int lineCount);
156 void drawPoints(const QPointF *points, int pointCount);
157 void drawPoints(const QPoint *points, int pointCount);
159 void stroke(const QVectorPath &path, const QPen &pen);
160 void fill(const QVectorPath &path, const QBrush &brush);
162 void clip(const QVectorPath &path, Qt::ClipOperation op);
163 void clip(const QRect &rect, Qt::ClipOperation op);
164 void clip(const QRegion ®ion, Qt::ClipOperation op);
166 #ifdef Q_NO_USING_KEYWORD
167 inline void drawEllipse(const QRect &rect) { QPaintEngineEx::drawEllipse(rect); }
169 using QPaintEngineEx::drawEllipse;
173 void saveBuffer(const QString &s) const;
176 Type type() const { return Raster; }
179 QRasterPaintEngine(QRasterPaintEnginePrivate &d, QPaintDevice *);
181 friend class QSpanData;
184 void fillRect(const QRectF &rect, QSpanData *data);
185 void drawBitmap(const QPointF &pos, const QImage &image, QSpanData *fill);
187 bool setClipRectInDeviceCoords(const QRect &r, Qt::ClipOperation op);
189 inline void ensureBrush(const QBrush &brush) {
190 if (state()->lastBrush != brush || (brush.style() != Qt::NoBrush && state()->fillFlags))
193 inline void ensureBrush() { ensureBrush(state()->brush); }
195 inline void ensurePen(const QPen &pen) {
196 if (state()->lastPen != pen || (pen.style() != Qt::NoPen && state()->strokeFlags))
199 inline void ensurePen() { ensurePen(state()->pen); }
201 void updateOutlineMapper();
203 void updateRasterState();
204 inline void ensureRasterState() {
211 /*******************************************************************************
212 * QRasterPaintEnginePrivate
214 class QRasterPaintEnginePrivate : public QPaintEngineExPrivate
216 Q_DECLARE_PUBLIC(QRasterPaintEngine)
218 QRasterPaintEnginePrivate();
220 void rasterizeLine_dashed(QLineF line, qreal width,
221 int *dashIndex, qreal *dashOffset, bool *inDash);
222 void rasterize(QT_FT_Outline *outline, ProcessSpans callback, void *userData);
223 void updateMatrixData(QSpanData *spanData, const QBrush &brush, const QTransform &brushMatrix);
225 void systemStateChanged();
227 QTransform brushMatrix() const {
228 Q_Q(const QRasterPaintEngine);
229 const QRasterPaintEngineState *s = q->state();
230 QTransform m(s->matrix);
231 m.translate(s->brushOrigin.x(), s->brushOrigin.y());
235 bool isUnclipped_normalized(const QRect &rect) const;
236 bool isUnclipped(const QRect &rect) const;
237 bool isUnclipped(const QRectF &rect) const;
238 ProcessSpans getBrushFunc(const QRect &rect, const QSpanData *data) const;
239 ProcessSpans getBrushFunc(const QRectF &rect, const QSpanData *data) const;
241 inline const QClipData *clip() const;
243 void initializeRasterizer(QSpanData *data);
245 QPaintDevice *device;
246 QScopedPointer<QOutlineMapper> outlineMapper;
247 QScopedPointer<QRasterBuffer> rasterBuffer;
251 QStroker basicStroker;
252 QScopedPointer<QDashStroker> dashStroker;
254 QSpanData image_filler;
255 QSpanData image_filler_xform;
256 QSpanData solid_color_filler;
258 QScopedPointer<QClipData> baseClip;
262 QScopedPointer<QRasterizer> rasterizer;
268 QClipData(int height);
279 inline ClipLine *clipLines() {
285 inline QSpan *spans() {
294 int xmin, xmax, ymin, ymax;
303 void appendSpan(const int x, const int length, const int y, const int coverage);
304 void appendSpans(const QSpan *s, const int num);
306 // ### Should optimize and actually kill the QSpans if the rect is
307 // ### a subset of The current region. Thus the "fast" clipspan
308 // ### callback can be used
309 void setClipRect(const QRect &rect);
310 void setClipRegion(const QRegion ®ion);
314 inline void QClipData::appendSpan(const int x, const int length, const int y, const int coverage)
316 Q_ASSERT(m_spans); // initialize() has to be called prior to adding spans..
318 if (count == allocated) {
320 m_spans = (QSpan *)realloc(m_spans, allocated*sizeof(QSpan));
322 m_spans[count].x = x;
323 m_spans[count].len = length;
324 m_spans[count].y = y;
325 m_spans[count].coverage = coverage;
329 inline void QClipData::appendSpans(const QSpan *s, const int num)
333 if (count + num > allocated) {
336 } while (count + num > allocated);
337 m_spans = (QSpan *)realloc(m_spans, allocated*sizeof(QSpan));
339 memcpy(m_spans+count, s, num*sizeof(QSpan));
343 /*******************************************************************************
353 QImage::Format prepare(QImage *image);
354 QImage::Format prepare(QPixmap *pix);
355 void prepare(int w, int h);
357 uchar *scanLine(int y) { Q_ASSERT(y>=0); Q_ASSERT(y<m_height); return m_buffer + y * bytes_per_line; }
358 const uchar *scanLine(int y) const { Q_ASSERT(y>=0); Q_ASSERT(y<m_height); return m_buffer + y * bytes_per_line; }
361 QImage bufferImage() const;
364 int width() const { return m_width; }
365 int height() const { return m_height; }
366 int bytesPerLine() const { return bytes_per_line; }
367 int bytesPerPixel() const { return bytes_per_pixel; }
369 uchar *buffer() const { return m_buffer; }
371 bool monoDestinationWithClut;
375 QPainter::CompositionMode compositionMode;
376 QImage::Format format;
377 DrawHelper *drawHelper;
378 QImage colorizeBitmap(const QImage &image, const QColor &color);
388 inline const QClipData *QRasterPaintEnginePrivate::clip() const {
389 Q_Q(const QRasterPaintEngine);
390 if (q->state() && q->state()->clip && q->state()->clip->enabled)
391 return q->state()->clip;
392 return baseClip.data();
397 #endif // QPAINTENGINE_RASTER_P_H