1 /****************************************************************************
3 ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: Nokia Corporation (qt-info@nokia.com)
7 ** This file is part of the QtGui module of the Qt Toolkit.
9 ** $QT_BEGIN_LICENSE:LGPL$
10 ** No Commercial Usage
11 ** This file contains pre-release code and may not be distributed.
12 ** You may use this file in accordance with the terms and conditions
13 ** contained in the Technology Preview License Agreement accompanying
16 ** GNU Lesser General Public License Usage
17 ** Alternatively, this file may be used under the terms of the GNU Lesser
18 ** General Public License version 2.1 as published by the Free Software
19 ** Foundation and appearing in the file LICENSE.LGPL included in the
20 ** packaging of this file. Please review the following information to
21 ** ensure the GNU Lesser General Public License version 2.1 requirements
22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 ** In addition, as a special exception, Nokia gives you certain additional
25 ** rights. These rights are described in the Nokia Qt LGPL Exception
26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 ** If you have questions regarding the use of this file, please contact
29 ** Nokia at qt-info@nokia.com.
40 ****************************************************************************/
42 #ifndef QPAINTENGINE_RASTER_P_H
43 #define QPAINTENGINE_RASTER_P_H
49 // This file is not part of the Qt API. It exists for the convenience
50 // of other Qt classes. This header file may change from version to
51 // version without notice, or even be removed.
56 #include "private/qpaintengineex_p.h"
57 #include "QtGui/qpainterpath.h"
58 #include "private/qdatabuffer_p.h"
59 #include "private/qdrawhelper_p.h"
60 #include "private/qpaintengine_p.h"
61 #include "private/qrasterizer_p.h"
62 #include "private/qstroker_p.h"
63 #include "private/qpainter_p.h"
64 #include "private/qtextureglyphcache_p.h"
65 #include "private/qoutlinemapper_p.h"
72 class QRasterPaintEnginePrivate;
76 class QRasterPaintEngineState : public QPainterState
79 QRasterPaintEngineState(QRasterPaintEngineState &other);
80 QRasterPaintEngineState();
81 ~QRasterPaintEngineState();
100 // QRegion clipRegion;
102 // QPainter::RenderHints hints;
103 // QPainter::CompositionMode compositionMode;
108 uint has_clip_ownership : 1; // should delete the clip member..
109 uint fast_pen : 1; // cosmetic 1-width pens, using midpoint drawlines
110 uint non_complex_pen : 1; // can use rasterizer, rather than stroker
111 uint antialiased : 1;
116 uint fast_images : 1;
128 /*******************************************************************************
131 class QRasterPaintEngine : public QPaintEngineEx
133 Q_DECLARE_PRIVATE(QRasterPaintEngine)
136 QRasterPaintEngine(QPaintDevice *device);
137 ~QRasterPaintEngine();
138 bool begin(QPaintDevice *device);
143 void brushOriginChanged();
144 void opacityChanged();
145 void compositionModeChanged();
146 void renderHintsChanged();
147 void transformChanged();
148 void clipEnabledChanged();
150 void setState(QPainterState *s);
151 QPainterState *createState(QPainterState *orig) const;
152 inline QRasterPaintEngineState *state() {
153 return static_cast<QRasterPaintEngineState *>(QPaintEngineEx::state());
155 inline const QRasterPaintEngineState *state() const {
156 return static_cast<const QRasterPaintEngineState *>(QPaintEngineEx::state());
159 void updateBrush(const QBrush &brush);
160 void updatePen(const QPen &pen);
162 void updateMatrix(const QTransform &matrix);
164 void drawPolygon(const QPointF *points, int pointCount, PolygonDrawMode mode);
165 void drawPolygon(const QPoint *points, int pointCount, PolygonDrawMode mode);
166 void fillPath(const QPainterPath &path, QSpanData *fillData);
167 void fillPolygon(const QPointF *points, int pointCount, PolygonDrawMode mode);
169 void drawEllipse(const QRectF &rect);
171 void fillRect(const QRectF &rect, const QBrush &brush);
172 void fillRect(const QRectF &rect, const QColor &color);
174 void drawRects(const QRect *rects, int rectCount);
175 void drawRects(const QRectF *rects, int rectCount);
177 void drawPixmap(const QPointF &p, const QPixmap &pm);
178 void drawPixmap(const QRectF &r, const QPixmap &pm, const QRectF &sr);
179 void drawImage(const QPointF &p, const QImage &img);
180 void drawImage(const QRectF &r, const QImage &pm, const QRectF &sr,
181 Qt::ImageConversionFlags falgs = Qt::AutoColor);
182 void drawTiledPixmap(const QRectF &r, const QPixmap &pm, const QPointF &sr);
183 void drawTextItem(const QPointF &p, const QTextItem &textItem);
185 void drawLines(const QLine *line, int lineCount);
186 void drawLines(const QLineF *line, int lineCount);
188 void drawPoints(const QPointF *points, int pointCount);
189 void drawPoints(const QPoint *points, int pointCount);
191 void stroke(const QVectorPath &path, const QPen &pen);
192 void fill(const QVectorPath &path, const QBrush &brush);
194 void strokePolygonCosmetic(const QPoint *pts, int pointCount, PolygonDrawMode mode);
195 void strokePolygonCosmetic(const QPointF *pt, int pointCount, PolygonDrawMode mode);
197 void clip(const QVectorPath &path, Qt::ClipOperation op);
198 void clip(const QRect &rect, Qt::ClipOperation op);
199 void clip(const QRegion ®ion, Qt::ClipOperation op);
201 void drawStaticTextItem(QStaticTextItem *textItem);
207 ClipType clipType() const;
208 QRect clipBoundingRect() const;
210 #ifdef Q_NO_USING_KEYWORD
211 inline void drawEllipse(const QRect &rect) { QPaintEngineEx::drawEllipse(rect); }
213 using QPaintEngineEx::drawPolygon;
214 using QPaintEngineEx::drawEllipse;
217 void releaseBuffer();
222 void saveBuffer(const QString &s) const;
226 void setCGContext(CGContextRef ref);
227 CGContextRef getCGContext() const;
233 void releaseDC(HDC hdc) const;
236 void alphaPenBlt(const void* src, int bpl, int depth, int rx,int ry,int w,int h);
238 Type type() const { return Raster; }
240 QPoint coordinateOffset() const;
243 QRasterPaintEngine(QRasterPaintEnginePrivate &d, QPaintDevice *);
245 friend struct QSpanData;
246 friend class QBlitterPaintEngine;
247 friend class QBlitterPaintEnginePrivate;
250 void fillRect(const QRectF &rect, QSpanData *data);
251 void drawBitmap(const QPointF &pos, const QImage &image, QSpanData *fill);
253 bool drawCachedGlyphs(int numGlyphs, const glyph_t *glyphs, const QFixedPoint *positions,
254 QFontEngine *fontEngine);
256 #if defined(Q_OS_SYMBIAN) && defined(QT_NO_FREETYPE)
257 void drawGlyphsS60(const QPointF &p, const QTextItemInt &ti);
258 #endif // Q_OS_SYMBIAN && QT_NO_FREETYPE
260 bool setClipRectInDeviceCoords(const QRect &r, Qt::ClipOperation op);
262 inline void ensureBrush(const QBrush &brush) {
263 if (!qbrush_fast_equals(state()->lastBrush, brush) || (brush.style() != Qt::NoBrush && state()->fillFlags))
266 inline void ensureBrush() { ensureBrush(state()->brush); }
268 inline void ensurePen(const QPen &pen) {
269 if (!qpen_fast_equals(state()->lastPen, pen) || (pen.style() != Qt::NoPen && state()->strokeFlags))
272 inline void ensurePen() { ensurePen(state()->pen); }
274 void updateOutlineMapper();
275 inline void ensureOutlineMapper();
278 inline void ensureState() {
285 /*******************************************************************************
286 * QRasterPaintEnginePrivate
288 class QRasterPaintEnginePrivate : public QPaintEngineExPrivate
290 Q_DECLARE_PUBLIC(QRasterPaintEngine)
292 QRasterPaintEnginePrivate();
294 void rasterizeLine_dashed(QLineF line, qreal width,
295 int *dashIndex, qreal *dashOffset, bool *inDash);
296 void rasterize(QT_FT_Outline *outline, ProcessSpans callback, QSpanData *spanData, QRasterBuffer *rasterBuffer);
297 void rasterize(QT_FT_Outline *outline, ProcessSpans callback, void *userData, QRasterBuffer *rasterBuffer);
298 void updateMatrixData(QSpanData *spanData, const QBrush &brush, const QTransform &brushMatrix);
300 void systemStateChanged();
302 void drawImage(const QPointF &pt, const QImage &img, SrcOverBlendFunc func,
303 const QRect &clip, int alpha, const QRect &sr = QRect());
305 QTransform brushMatrix() const {
306 Q_Q(const QRasterPaintEngine);
307 const QRasterPaintEngineState *s = q->state();
308 QTransform m(s->matrix);
309 m.translate(s->brushOrigin.x(), s->brushOrigin.y());
313 bool isUnclipped_normalized(const QRect &rect) const;
314 bool isUnclipped(const QRect &rect, int penWidth) const;
315 bool isUnclipped(const QRectF &rect, int penWidth) const;
316 ProcessSpans getPenFunc(const QRect &rect, const QSpanData *data) const;
317 ProcessSpans getPenFunc(const QRectF &rect, const QSpanData *data) const;
318 ProcessSpans getBrushFunc(const QRect &rect, const QSpanData *data) const;
319 ProcessSpans getBrushFunc(const QRectF &rect, const QSpanData *data) const;
321 inline const QClipData *clip() const;
323 void initializeRasterizer(QSpanData *data);
325 void recalculateFastImages();
326 bool canUseFastImageBlending(QPainter::CompositionMode mode, const QImage &image) const;
328 QPaintDevice *device;
329 QScopedPointer<QOutlineMapper> outlineMapper;
330 QScopedPointer<QRasterBuffer> rasterBuffer;
332 #if defined (Q_WS_WIN)
334 #elif defined(Q_WS_MAC)
335 CGContextRef cgContext;
340 QStroker basicStroker;
341 QScopedPointer<QDashStroker> dashStroker;
343 QScopedPointer<QT_FT_Raster> grayRaster;
345 QDataBuffer<QLineF> cachedLines;
346 QSpanData image_filler;
347 QSpanData image_filler_xform;
348 QSpanData solid_color_filler;
351 QFontEngineGlyphCache::Type glyphCacheType;
353 QScopedPointer<QClipData> baseClip;
357 uint mono_surface : 1;
358 uint outlinemapper_xform_dirty : 1;
361 uint isPlain45DegreeRotation : 1;
364 QScopedPointer<QRasterizer> rasterizer;
370 QClipData(int height);
381 inline ClipLine *clipLines() {
387 inline QSpan *spans() {
396 int xmin, xmax, ymin, ymax;
402 uint hasRectClip : 1;
403 uint hasRegionClip : 1;
405 void appendSpan(int x, int length, int y, int coverage);
406 void appendSpans(const QSpan *s, int num);
408 // ### Should optimize and actually kill the QSpans if the rect is
409 // ### a subset of The current region. Thus the "fast" clipspan
410 // ### callback can be used
411 void setClipRect(const QRect &rect);
412 void setClipRegion(const QRegion ®ion);
416 inline void QClipData::appendSpan(int x, int length, int y, int coverage)
418 Q_ASSERT(m_spans); // initialize() has to be called prior to adding spans..
420 if (count == allocated) {
422 m_spans = (QSpan *)realloc(m_spans, allocated*sizeof(QSpan));
424 m_spans[count].x = x;
425 m_spans[count].len = length;
426 m_spans[count].y = y;
427 m_spans[count].coverage = coverage;
431 inline void QClipData::appendSpans(const QSpan *s, int num)
435 if (count + num > allocated) {
438 } while (count + num > allocated);
439 m_spans = (QSpan *)realloc(m_spans, allocated*sizeof(QSpan));
441 memcpy(m_spans+count, s, num*sizeof(QSpan));
445 /*******************************************************************************
451 QRasterBuffer() : m_width(0), m_height(0), m_buffer(0) { init(); }
457 QImage::Format prepare(QImage *image);
458 QImage::Format prepare(QPixmap *pix);
459 void prepare(int w, int h);
460 void prepareBuffer(int w, int h);
462 void resetBuffer(int val=0);
464 uchar *scanLine(int y) { Q_ASSERT(y>=0); Q_ASSERT(y<m_height); return m_buffer + y * bytes_per_line; }
467 QImage bufferImage() const;
470 void flushToARGBImage(QImage *image) const;
472 int width() const { return m_width; }
473 int height() const { return m_height; }
474 int bytesPerLine() const { return bytes_per_line; }
475 int bytesPerPixel() const { return bytes_per_pixel; }
477 uchar *buffer() const { return m_buffer; }
479 bool monoDestinationWithClut;
483 QPainter::CompositionMode compositionMode;
484 QImage::Format format;
485 DrawHelper *drawHelper;
486 QImage colorizeBitmap(const QImage &image, const QColor &color);
496 inline void QRasterPaintEngine::ensureOutlineMapper() {
497 if (d_func()->outlinemapper_xform_dirty)
498 updateOutlineMapper();
501 inline const QClipData *QRasterPaintEnginePrivate::clip() const {
502 Q_Q(const QRasterPaintEngine);
503 if (q->state() && q->state()->clip && q->state()->clip->enabled)
504 return q->state()->clip;
505 return baseClip.data();
510 #endif // QPAINTENGINE_RASTER_P_H