Qt 4.8
qpaintengine_raster_p.h
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
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 Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/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 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41 
42 #ifndef QPAINTENGINE_RASTER_P_H
43 #define QPAINTENGINE_RASTER_P_H
44 
45 //
46 // W A R N I N G
47 // -------------
48 //
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.
52 //
53 // We mean it.
54 //
55 
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"
66 
67 #include <stdlib.h>
68 
70 
71 class QOutlineMapper;
73 class QRasterBuffer;
74 class QClipData;
76 
78 {
79 public:
83 
84 
89 
93 
96 
98 
100 // QRect clipRect;
101 // QRegion clipRegion;
102 
103 // QPainter::RenderHints hints;
104 // QPainter::CompositionMode compositionMode;
105 
107 
108  struct Flags {
109  uint has_clip_ownership : 1; // should delete the clip member..
110  uint fast_pen : 1; // cosmetic 1-width pens, using midpoint drawlines
111  uint non_complex_pen : 1; // can use rasterizer, rather than stroker
118  };
119 
120  union {
123  };
124 };
125 
126 
127 
128 
129 /*******************************************************************************
130  * QRasterPaintEngine
131  */
132 class
133 #ifdef Q_WS_QWS
135 #endif
137 {
139 public:
140 
143  bool begin(QPaintDevice *device);
144  bool end();
145 
146  void penChanged();
147  void brushChanged();
148  void brushOriginChanged();
149  void opacityChanged();
150  void compositionModeChanged();
151  void renderHintsChanged();
152  void transformChanged();
153  void clipEnabledChanged();
154 
155  void setState(QPainterState *s);
156  QPainterState *createState(QPainterState *orig) const;
158  return static_cast<QRasterPaintEngineState *>(QPaintEngineEx::state());
159  }
160  inline const QRasterPaintEngineState *state() const {
161  return static_cast<const QRasterPaintEngineState *>(QPaintEngineEx::state());
162  }
163 
164  void updateBrush(const QBrush &brush);
165  void updatePen(const QPen &pen);
166 
167  void updateMatrix(const QTransform &matrix);
168 
169  void drawPolygon(const QPointF *points, int pointCount, PolygonDrawMode mode);
170  void drawPolygon(const QPoint *points, int pointCount, PolygonDrawMode mode);
171  void fillPath(const QPainterPath &path, QSpanData *fillData);
172  void fillPolygon(const QPointF *points, int pointCount, PolygonDrawMode mode);
173 
174  void drawEllipse(const QRectF &rect);
175 
176  void fillRect(const QRectF &rect, const QBrush &brush);
177  void fillRect(const QRectF &rect, const QColor &color);
178 
179  void drawRects(const QRect *rects, int rectCount);
180  void drawRects(const QRectF *rects, int rectCount);
181 
182  void drawPixmap(const QPointF &p, const QPixmap &pm);
183  void drawPixmap(const QRectF &r, const QPixmap &pm, const QRectF &sr);
184  void drawImage(const QPointF &p, const QImage &img);
185  void drawImage(const QRectF &r, const QImage &pm, const QRectF &sr,
186  Qt::ImageConversionFlags falgs = Qt::AutoColor);
187  void drawTiledPixmap(const QRectF &r, const QPixmap &pm, const QPointF &sr);
188  void drawTextItem(const QPointF &p, const QTextItem &textItem);
189 
190  void drawLines(const QLine *line, int lineCount);
191  void drawLines(const QLineF *line, int lineCount);
192 
193  void drawPoints(const QPointF *points, int pointCount);
194  void drawPoints(const QPoint *points, int pointCount);
195 
196  void stroke(const QVectorPath &path, const QPen &pen);
197  void fill(const QVectorPath &path, const QBrush &brush);
198 
199  void clip(const QVectorPath &path, Qt::ClipOperation op);
200  void clip(const QRect &rect, Qt::ClipOperation op);
201  void clip(const QRegion &region, Qt::ClipOperation op);
202 
203  void drawStaticTextItem(QStaticTextItem *textItem);
204 
205  enum ClipType {
207  ComplexClip
208  };
209  ClipType clipType() const;
210  QRect clipBoundingRect() const;
211 
212 #ifdef Q_NO_USING_KEYWORD
213  inline void drawEllipse(const QRect &rect) { QPaintEngineEx::drawEllipse(rect); }
214 #else
217 #endif
218 
219  void releaseBuffer();
220 
221  QSize size() const;
222 
223 #ifndef QT_NO_DEBUG
224  void saveBuffer(const QString &s) const;
225 #endif
226 
227 #ifdef Q_WS_MAC
228  void setCGContext(CGContextRef ref);
229  CGContextRef getCGContext() const;
230 #endif
231 
232 #ifdef Q_WS_WIN
233  void setDC(HDC hdc);
234  HDC getDC() const;
235  void releaseDC(HDC hdc) const;
236 #endif
237 
238  void alphaPenBlt(const void* src, int bpl, int depth, int rx,int ry,int w,int h);
239 
240  Type type() const { return Raster; }
241 
242  QPoint coordinateOffset() const;
243 
244 #if defined(Q_WS_QWS) && !defined(QT_NO_RASTERCALLBACKS)
245  virtual void drawColorSpans(const QSpan *spans, int count, uint color);
246  virtual void drawBufferSpan(const uint *buffer, int bufsize,
247  int x, int y, int length, uint const_alpha);
248 #endif
249  bool supportsTransformations(const QFontEngine *fontEngine) const;
250  bool supportsTransformations(qreal pixelSize, const QTransform &m) const;
251 
252 protected:
254 private:
255  friend struct QSpanData;
256  friend class QBlitterPaintEngine;
258  void init();
259 
260  void fillRect(const QRectF &rect, QSpanData *data);
261  void drawBitmap(const QPointF &pos, const QImage &image, QSpanData *fill);
262 
263  bool drawCachedGlyphs(int numGlyphs, const glyph_t *glyphs, const QFixedPoint *positions,
264  QFontEngine *fontEngine);
265 
266 #if defined(Q_OS_SYMBIAN) && defined(QT_NO_FREETYPE)
267  void drawGlyphsS60(const QPointF &p, const QTextItemInt &ti);
268 #endif // Q_OS_SYMBIAN && QT_NO_FREETYPE
269 
270  bool setClipRectInDeviceCoords(const QRect &r, Qt::ClipOperation op);
271 
272  inline void ensureBrush(const QBrush &brush) {
273  if (!qbrush_fast_equals(state()->lastBrush, brush) || (brush.style() != Qt::NoBrush && state()->fillFlags))
274  updateBrush(brush);
275  }
276  inline void ensureBrush() { ensureBrush(state()->brush); }
277 
278  inline void ensurePen(const QPen &pen) {
279  if (!qpen_fast_equals(state()->lastPen, pen) || (pen.style() != Qt::NoPen && state()->strokeFlags))
280  updatePen(pen);
281  }
282  inline void ensurePen() { ensurePen(state()->pen); }
283 
284  void updateOutlineMapper();
285  inline void ensureOutlineMapper();
286 
287  void updateState();
288  inline void ensureState() {
289  if (state()->dirty)
290  updateState();
291  }
292 };
293 
294 
295 /*******************************************************************************
296  * QRasterPaintEnginePrivate
297  */
298 class
299 #ifdef Q_WS_QWS
301 #endif
303 {
305 public:
307 
308  void rasterizeLine_dashed(QLineF line, qreal width,
309  int *dashIndex, qreal *dashOffset, bool *inDash);
311  void rasterize(QT_FT_Outline *outline, ProcessSpans callback, void *userData, QRasterBuffer *rasterBuffer);
312  void updateMatrixData(QSpanData *spanData, const QBrush &brush, const QTransform &brushMatrix);
313 
314  void systemStateChanged();
315 
316  void drawImage(const QPointF &pt, const QImage &img, SrcOverBlendFunc func,
317  const QRect &clip, int alpha, const QRect &sr = QRect());
318 
320  Q_Q(const QRasterPaintEngine);
321  const QRasterPaintEngineState *s = q->state();
322  QTransform m(s->matrix);
323  m.translate(s->brushOrigin.x(), s->brushOrigin.y());
324  return m;
325  }
326 
327  bool isUnclipped_normalized(const QRect &rect) const;
328  bool isUnclipped(const QRect &rect, int penWidth) const;
329  bool isUnclipped(const QRectF &rect, int penWidth) const;
330  ProcessSpans getPenFunc(const QRectF &rect, const QSpanData *data) const;
331  ProcessSpans getBrushFunc(const QRect &rect, const QSpanData *data) const;
332  ProcessSpans getBrushFunc(const QRectF &rect, const QSpanData *data) const;
333 
334 #ifdef Q_WS_QWS
336 #endif
337 
338  inline const QClipData *clip() const;
339 
340  void initializeRasterizer(QSpanData *data);
341 
342  void recalculateFastImages();
343  bool canUseFastImageBlending(QPainter::CompositionMode mode, const QImage &image) const;
344 
348 
349 #if defined (Q_WS_WIN)
350  HDC hdc;
351 #elif defined(Q_WS_MAC)
352  CGContextRef cgContext;
353 #endif
354 
357 
360 
362 
367 
368 
370 
372 
374 
377 
378 #ifdef Q_WS_WIN
380 #endif
381 
383 };
384 
385 
386 class
387 #ifdef Q_WS_QWS
389 #endif
390 QClipData {
391 public:
392  QClipData(int height);
393  ~QClipData();
394 
396  struct ClipLine {
397  int count;
399  } *m_clipLines;
400 
401  void initialize();
402 
403  inline ClipLine *clipLines() {
404  if (!m_clipLines)
405  initialize();
406  return m_clipLines;
407  }
408 
409  inline QSpan *spans() {
410  if (!m_spans)
411  initialize();
412  return m_spans;
413  }
414 
416  int count;
418  int xmin, xmax, ymin, ymax;
419 
422 
426 
427  void appendSpan(int x, int length, int y, int coverage);
428  void appendSpans(const QSpan *s, int num);
429 
430  // ### Should optimize and actually kill the QSpans if the rect is
431  // ### a subset of The current region. Thus the "fast" clipspan
432  // ### callback can be used
433  void setClipRect(const QRect &rect);
434  void setClipRegion(const QRegion &region);
435  void fixup();
436 };
437 
438 inline void QClipData::appendSpan(int x, int length, int y, int coverage)
439 {
440  Q_ASSERT(m_spans); // initialize() has to be called prior to adding spans..
441 
442  if (count == allocated) {
443  allocated *= 2;
444  m_spans = (QSpan *)realloc(m_spans, allocated*sizeof(QSpan));
445  }
446  m_spans[count].x = x;
447  m_spans[count].len = length;
448  m_spans[count].y = y;
449  m_spans[count].coverage = coverage;
450  ++count;
451 }
452 
453 inline void QClipData::appendSpans(const QSpan *s, int num)
454 {
455  Q_ASSERT(m_spans);
456 
457  if (count + num > allocated) {
458  do {
459  allocated *= 2;
460  } while (count + num > allocated);
461  m_spans = (QSpan *)realloc(m_spans, allocated*sizeof(QSpan));
462  }
463  memcpy(m_spans+count, s, num*sizeof(QSpan));
464  count += num;
465 }
466 
467 #ifdef Q_WS_QWS
469 {
470 public:
472 
473  int devType() const { return QInternal::CustomRaster; }
474 
475  virtual int metric(PaintDeviceMetric m) const;
476 
477  virtual void* memory() const { return 0; }
478 
479  virtual QImage::Format format() const {
481  }
482 
483  virtual int bytesPerLine() const;
484 
485  virtual QSize size() const {
486  return static_cast<QRasterPaintEngine*>(paintEngine())->size();
487  }
488 
489 private:
491 };
492 #endif // Q_WS_QWS
493 
494 /*******************************************************************************
495  * QRasterBuffer
496  */
497 class
498 #ifdef Q_WS_QWS
500 #endif
502 {
503 public:
504  QRasterBuffer() : m_width(0), m_height(0), m_buffer(0) { init(); }
505 
506  ~QRasterBuffer();
507 
508  void init();
509 
510  QImage::Format prepare(QImage *image);
511  QImage::Format prepare(QPixmap *pix);
512 #ifdef Q_WS_QWS
513  void prepare(QCustomRasterPaintDevice *device);
514 #endif
515  void prepare(int w, int h);
516  void prepareBuffer(int w, int h);
517 
518  void resetBuffer(int val=0);
519 
520  uchar *scanLine(int y) { Q_ASSERT(y>=0); Q_ASSERT(y<m_height); return m_buffer + y * bytes_per_line; }
521 
522 #ifndef QT_NO_DEBUG
523  QImage bufferImage() const;
524 #endif
525 
526  void flushToARGBImage(QImage *image) const;
527 
528  int width() const { return m_width; }
529  int height() const { return m_height; }
530  int bytesPerLine() const { return bytes_per_line; }
531  int bytesPerPixel() const { return bytes_per_pixel; }
532 
533  uchar *buffer() const { return m_buffer; }
534 
538 
542  QImage colorizeBitmap(const QImage &image, const QColor &color);
543 
544 private:
545  int m_width;
546  int m_height;
550 };
551 
553  if (d_func()->outlinemapper_xform_dirty)
554  updateOutlineMapper();
555 }
556 
558  Q_Q(const QRasterPaintEngine);
559  if (q->state() && q->state()->clip && q->state()->clip->enabled)
560  return q->state()->clip;
561  return baseClip.data();
562 }
563 
564 
566 #endif // QPAINTENGINE_RASTER_P_H
The QColor class provides colors based on RGB, HSV or CMYK values.
Definition: qcolor.h:67
double d
Definition: qnumeric_p.h:62
void ensureBrush(const QBrush &brush)
QPaintEngine::DirtyFlags state() const
Returns a combination of flags identifying the set of properties that need to be updated when updatin...
Definition: qpaintengine.h:292
QScopedPointer< QClipData > baseClip
Format
The following image formats are available in Qt.
Definition: qimage.h:91
static void callback(AuServer *, AuEventHandlerRec *, AuEvent *e, AuPointer p)
Definition: qsound_x11.cpp:170
QImage::Format format
unsigned int QRgb
Definition: qrgb.h:53
double qreal
Definition: qglobal.h:1193
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
QPointer< QWidget > widget
The QCustomRasterPaintDevice class is provided to activate hardware accelerated paint engines in Qt f...
QRasterPaintEngineState * state()
CompositionMode
Defines the modes supported for digital image compositing.
Definition: qpainter.h:138
The QLine class provides a two-dimensional vector using integer precision.
Definition: qline.h:57
The QPainterPath class provides a container for painting operations, enabling graphical shapes to be ...
Definition: qpainterpath.h:67
Qt::PenStyle style() const
Returns the pen style.
Definition: qpen.cpp:428
bool qbrush_fast_equals(const QBrush &a, const QBrush &b)
Definition: qpainter_p.h:95
void updateMatrixData(QSpanData *spanData, const QBrush &brush, const QTransform &brushMatrix)
#define Q_GUI_EXPORT
Definition: qglobal.h:1450
The QPointF class defines a point in the plane using floating point precision.
Definition: qpoint.h:214
ClipLine * clipLines()
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:150
QT_FT_SpanFunc ProcessSpans
const QRasterPaintEngineState * state() const
ProcessSpans getBrushFunc(const QRect &rect, const QSpanData *data) const
QTransform matrix
Definition: qpainter_p.h:161
QTransform & translate(qreal dx, qreal dy)
Moves the coordinate system dx along the x axis and dy along the y axis, and returns a reference to t...
Definition: qtransform.cpp:417
virtual QImage::Format format() const
Returns the format of the device&#39;s memory buffet.
QScopedPointer< QDashStroker > dashStroker
QScopedPointer< QRasterBuffer > rasterBuffer
static QImage colorizeBitmap(const QImage &image, const QColor &color)
The QString class provides a Unicode character string.
Definition: qstring.h:83
int bytesPerLine() const
QMatrix matrix() const
Returns the matrix in the current paint engine state.
Definition: qpainter.cpp:9355
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
bool isUnclipped_normalized(const QRect &rect) const
Returns true if the rectangle is completely within the current clip state of the paint engine...
The QPen class defines how a QPainter should draw lines and outlines of shapes.
Definition: qpen.h:64
void init(QPainter *p)
Definition: qpainter.cpp:8770
QPainter::CompositionMode compositionMode
bool qpen_fast_equals(const QPen &a, const QPen &b)
Definition: qpainter_p.h:86
qreal x() const
Returns the x-coordinate of this point.
Definition: qpoint.h:282
#define Q_Q(Class)
Definition: qglobal.h:2483
The QLineF class provides a two-dimensional vector using floating point precision.
Definition: qline.h:212
void initializeRasterizer(QSpanData *data)
unsigned char uchar
Definition: qglobal.h:994
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
QBrush brush() const
Returns the brush in the current paint engine state.
Definition: qpainter.cpp:9273
The QRectF class defines a rectangle in the plane using floating point precision. ...
Definition: qrect.h:511
static float pixelSize(const QFontDef &request, int dpi)
Definition: qfont_win.cpp:80
static const QCssKnownValue positions[NumKnownPositionModes - 1]
Definition: qcssparser.cpp:329
static void drawRects(const T *rects, int n, const QTransform &transform, IDirectFBSurface *surface)
Internal QTextItem.
The QImage class provides a hardware-independent image representation that allows direct access to th...
Definition: qimage.h:87
static const char * data(const QByteArray &arr)
unsigned int uint
Definition: qglobal.h:996
QDataBuffer< QLineF > cachedLines
void rasterize(QT_FT_Outline *outline, ProcessSpans callback, QSpanData *spanData, QRasterBuffer *rasterBuffer)
The QRegion class specifies a clip region for a painter.
Definition: qregion.h:68
static void drawBufferSpan(QSpanData *data, const uint *buffer, int bufsize, int x, int y, int length, uint const_alpha)
Qt::BrushStyle style() const
Returns the brush style.
Definition: qbrush.h:182
uchar * scanLine(int y)
void(* SrcOverBlendFunc)(uchar *destPixels, int dbpl, const uchar *src, int spbl, int w, int h, int const_alpha)
bool isUnclipped(const QRect &rect, int penWidth) const
void appendSpan(int x, int length, int y, int coverage)
virtual void drawPolygon(const QPointF *points, int pointCount, PolygonDrawMode mode)
Reimplement this virtual function to draw the polygon defined by the pointCount first points in point...
The QBrush class defines the fill pattern of shapes drawn by QPainter.
Definition: qbrush.h:76
int bytesPerPixel() const
void appendSpans(const QSpan *s, int num)
void prepare(QCustomRasterPaintDevice *)
#define Q_DECLARE_PUBLIC(Class)
Definition: qglobal.h:2477
void rasterizeLine_dashed(QLineF line, qreal width, int *dashIndex, qreal *dashOffset, bool *inDash)
QCustomRasterPaintDevice(QWidget *w)
Constructs a custom raster based paint device for the given top-level widget.
Type type() const
Reimplemented Function
DrawHelper * drawHelper
The QPoint class defines a point in the plane using integer precision.
Definition: qpoint.h:53
QScopedPointer< QT_FT_Raster > grayRaster
QPointF brushOrigin
Definition: qpainter_p.h:149
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
const QClipData * clip() const
friend class QRasterPaintEngine
Definition: qpaintengine.h:319
void drawImage(const QPointF &pt, const QImage &img, SrcOverBlendFunc func, const QRect &clip, int alpha, const QRect &sr=QRect())
static void drawPoints(const T *points, int n, const QTransform &transform, IDirectFBSurface *surface)
qreal y() const
Returns the y-coordinate of this point.
Definition: qpoint.h:287
ProcessSpans getPenFunc(const QRectF &rect, const QSpanData *data) const
The QPixmap class is an off-screen image representation that can be used as a paint device...
Definition: qpixmap.h:71
virtual void * memory() const
Returns a pointer to the paint device&#39;s memory buffer, or 0 if no such buffer exists.
void fillRect(const QRectF &rect, const QColor &, bool alpha)
uchar * buffer() const
The QSize class defines the size of a two-dimensional object using integer point precision.
Definition: qsize.h:53
#define Q_DECLARE_PRIVATE(Class)
Definition: qglobal.h:2467
QPen pen() const
Returns the pen in the current paint engine state.
Definition: qpainter.cpp:9259
struct CGContext * CGContextRef
The QRasterPaintEngine class enables hardware acceleration of painting operations in Qt for Embedded ...
QFontEngineGlyphCache::Type glyphCacheType
QScopedPointer< QOutlineMapper > outlineMapper
static void drawLines(const T *lines, int n, const QTransform &transform, IDirectFBSurface *surface)
The QTextItem class provides all the information required to draw text in a custom paint engine...
Definition: qpaintengine.h:68
virtual QSize size() const
static const KeyPair *const end
QScopedPointer< QRasterizer > rasterizer
void ensurePen(const QPen &pen)
unsigned int glyph_t
QPainterState * state()
bool canUseFastImageBlending(QPainter::CompositionMode mode, const QImage &image) const
virtual void drawEllipse(const QRectF &r)
Reimplement this function to draw the largest ellipse that can be contained within rectangle rect...
The QTransform class specifies 2D transformations of a coordinate system.
Definition: qtransform.h:65
ClipOperation
Definition: qnamespace.h:1495