OSDN Git Service

drop support for static text [ci reset]
[kde/Katie.git] / src / gui / painting / qpaintengine_raster_p.h
1 /****************************************************************************
2 **
3 ** Copyright (C) 2015 The Qt Company Ltd.
4 ** Copyright (C) 2016 Ivailo Monev
5 **
6 ** This file is part of the QtGui module of the Katie Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 **
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.
17 **
18 ** $QT_END_LICENSE$
19 **
20 ****************************************************************************/
21
22 #ifndef QPAINTENGINE_RASTER_P_H
23 #define QPAINTENGINE_RASTER_P_H
24
25 //
26 //  W A R N I N G
27 //  -------------
28 //
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.
32 //
33 // We mean it.
34 //
35
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"
45
46 #include <stdlib.h>
47
48 QT_BEGIN_NAMESPACE
49
50 class QRasterPaintEnginePrivate;
51 class QRasterBuffer;
52 class QClipData;
53
54 class QRasterPaintEngineState : public QPainterState
55 {
56 public:
57     QRasterPaintEngineState(QRasterPaintEngineState &other);
58     QRasterPaintEngineState();
59     ~QRasterPaintEngineState();
60
61
62     QPen lastPen;
63     QSpanData penData;
64     QStrokerOps *stroker;
65     QPaintEngine::DirtyFlags strokeFlags;
66
67     QBrush lastBrush;
68     QSpanData brushData;
69     QPaintEngine::DirtyFlags fillFlags;
70
71     int intOpacity;
72
73     qreal txscale;
74
75     QClipData *clip;
76 //     QRect clipRect;
77 //     QRegion clipRegion;
78
79 //     QPainter::RenderHints hints;
80 //     QPainter::CompositionMode compositionMode;
81
82     QPaintEngine::DirtyFlags dirty;
83
84     struct Flags {
85         bool has_clip_ownership;        // should delete the clip member..
86         bool non_complex_pen;           // can use rasterizer, rather than stroker
87         bool antialiased;
88         bool bilinear;
89         bool tx_noshear;
90     };
91
92     Flags flags;
93 };
94
95
96
97
98 /*******************************************************************************
99  * QRasterPaintEngine
100  */
101 class QRasterPaintEngine : public QPaintEngineEx
102 {
103     Q_DECLARE_PRIVATE(QRasterPaintEngine)
104 public:
105
106     QRasterPaintEngine(QPaintDevice *device);
107     bool begin(QPaintDevice *device);
108     bool end();
109
110     void penChanged();
111     void brushChanged();
112     void brushOriginChanged();
113     void opacityChanged();
114     void compositionModeChanged();
115     void renderHintsChanged();
116     void transformChanged();
117     void clipEnabledChanged();
118
119     void setState(QPainterState *s);
120     QPainterState *createState(QPainterState *orig) const;
121     inline QRasterPaintEngineState *state() {
122         return static_cast<QRasterPaintEngineState *>(QPaintEngineEx::state());
123     }
124     inline const QRasterPaintEngineState *state() const {
125         return static_cast<const QRasterPaintEngineState *>(QPaintEngineEx::state());
126     }
127
128     void updateBrush(const QBrush &brush);
129     void updatePen(const QPen &pen);
130
131     void updateMatrix(const QTransform &matrix);
132
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);
137
138     void drawEllipse(const QRectF &rect);
139
140     void fillRect(const QRectF &rect, const QBrush &brush);
141     void fillRect(const QRectF &rect, const QColor &color);
142
143     void drawRects(const QRect  *rects, int rectCount);
144
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);
152
153     void drawLines(const QLine *line, int lineCount);
154     void drawLines(const QLineF *line, int lineCount);
155
156     void drawPoints(const QPointF *points, int pointCount);
157     void drawPoints(const QPoint *points, int pointCount);
158
159     void stroke(const QVectorPath &path, const QPen &pen);
160     void fill(const QVectorPath &path, const QBrush &brush);
161
162     void clip(const QVectorPath &path, Qt::ClipOperation op);
163     void clip(const QRect &rect, Qt::ClipOperation op);
164     void clip(const QRegion &region, Qt::ClipOperation op);
165
166 #ifdef Q_NO_USING_KEYWORD
167     inline void drawEllipse(const QRect &rect) { QPaintEngineEx::drawEllipse(rect); }
168 #else
169     using QPaintEngineEx::drawEllipse;
170 #endif
171
172 #ifndef QT_NO_DEBUG
173     void saveBuffer(const QString &s) const;
174 #endif
175
176     Type type() const { return Raster; }
177
178 protected:
179     QRasterPaintEngine(QRasterPaintEnginePrivate &d, QPaintDevice *);
180 private:
181     friend class QSpanData;
182     void init();
183
184     void fillRect(const QRectF &rect, QSpanData *data);
185     void drawBitmap(const QPointF &pos, const QImage &image, QSpanData *fill);
186
187     bool setClipRectInDeviceCoords(const QRect &r, Qt::ClipOperation op);
188
189     inline void ensureBrush(const QBrush &brush) {
190         if (state()->lastBrush != brush || (brush.style() != Qt::NoBrush && state()->fillFlags))
191             updateBrush(brush);
192     }
193     inline void ensureBrush() { ensureBrush(state()->brush); }
194
195     inline void ensurePen(const QPen &pen) {
196         if (state()->lastPen != pen || (pen.style() != Qt::NoPen && state()->strokeFlags))
197             updatePen(pen);
198     }
199     inline void ensurePen() { ensurePen(state()->pen); }
200
201     void updateOutlineMapper();
202
203     void updateRasterState();
204     inline void ensureRasterState() {
205         if (state()->dirty)
206             updateRasterState();
207     }
208 };
209
210
211 /*******************************************************************************
212  * QRasterPaintEnginePrivate
213  */
214 class QRasterPaintEnginePrivate : public QPaintEngineExPrivate
215 {
216     Q_DECLARE_PUBLIC(QRasterPaintEngine)
217 public:
218     QRasterPaintEnginePrivate();
219
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);
224
225     void systemStateChanged();
226
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());
232         return m;
233     }
234
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;
240
241     inline const QClipData *clip() const;
242
243     void initializeRasterizer(QSpanData *data);
244
245     QPaintDevice *device;
246     QScopedPointer<QOutlineMapper> outlineMapper;
247     QScopedPointer<QRasterBuffer>  rasterBuffer;
248
249     QRect deviceRect;
250
251     QStroker basicStroker;
252     QScopedPointer<QDashStroker> dashStroker;
253
254     QSpanData image_filler;
255     QSpanData image_filler_xform;
256     QSpanData solid_color_filler;
257
258     QScopedPointer<QClipData> baseClip;
259
260     int deviceDepth;
261
262     QScopedPointer<QRasterizer> rasterizer;
263 };
264
265
266 class QClipData {
267 public:
268     QClipData(int height);
269     ~QClipData();
270
271     int clipSpanHeight;
272     struct ClipLine {
273         int count;
274         QSpan *spans;
275     } *m_clipLines;
276
277     void initialize();
278
279     inline ClipLine *clipLines() {
280         if (!m_clipLines)
281             initialize();
282         return m_clipLines;
283     }
284
285     inline QSpan *spans() {
286         if (!m_spans)
287             initialize();
288         return m_spans;
289     }
290
291     int allocated;
292     int count;
293     QSpan *m_spans;
294     int xmin, xmax, ymin, ymax;
295
296     QRect clipRect;
297     QRegion clipRegion;
298
299     bool enabled;
300     bool hasRectClip;
301     bool hasRegionClip;
302
303     void appendSpan(const int x, const int length, const int y, const int coverage);
304     void appendSpans(const QSpan *s, const int num);
305
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 &region);
311     void fixup();
312 };
313
314 inline void QClipData::appendSpan(const int x, const int length, const int y, const int coverage)
315 {
316     Q_ASSERT(m_spans); // initialize() has to be called prior to adding spans..
317
318     if (count == allocated) {
319         allocated *= 2;
320         m_spans = (QSpan *)realloc(m_spans, allocated*sizeof(QSpan));
321     }
322     m_spans[count].x = x;
323     m_spans[count].len = length;
324     m_spans[count].y = y;
325     m_spans[count].coverage = coverage;
326     ++count;
327 }
328
329 inline void QClipData::appendSpans(const QSpan *s, const int num)
330 {
331     Q_ASSERT(m_spans);
332
333     if (count + num > allocated) {
334         do {
335             allocated *= 2;
336         } while (count + num > allocated);
337         m_spans = (QSpan *)realloc(m_spans, allocated*sizeof(QSpan));
338     }
339     memcpy(m_spans+count, s, num*sizeof(QSpan));
340     count += num;
341 }
342
343 /*******************************************************************************
344  * QRasterBuffer
345  */
346 class QRasterBuffer
347 {
348 public:
349     QRasterBuffer();
350
351     ~QRasterBuffer();
352
353     QImage::Format prepare(QImage *image);
354     QImage::Format prepare(QPixmap *pix);
355     void prepare(int w, int h);
356
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; }
359
360 #ifndef QT_NO_DEBUG
361     QImage bufferImage() const;
362 #endif
363
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; }
368
369     uchar *buffer() const { return m_buffer; }
370
371     bool monoDestinationWithClut;
372     QRgb destColor0;
373     QRgb destColor1;
374
375     QPainter::CompositionMode compositionMode;
376     QImage::Format format;
377     DrawHelper *drawHelper;
378     QImage colorizeBitmap(const QImage &image, const QColor &color);
379
380 private:
381     int m_width;
382     int m_height;
383     int bytes_per_line;
384     int bytes_per_pixel;
385     uchar *m_buffer;
386 };
387
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();
393 }
394
395
396 QT_END_NAMESPACE
397 #endif // QPAINTENGINE_RASTER_P_H