Qt 4.8
qpaintbuffer_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 QPAINTBUFFER_P_H
43 #define QPAINTBUFFER_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 purely as an
50 // implementation detail. 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 <qpaintdevice.h>
57 
58 #include <private/qpaintengineex_p.h>
59 #include <private/qtextengine_p.h>
60 #include <QDebug>
61 
63 
65 class QPaintBufferPlayback;
66 
68 {
70 public:
71  QPaintBuffer();
72  QPaintBuffer(const QPaintBuffer &other);
73  ~QPaintBuffer();
74 
75  bool isEmpty() const;
76 
77  void beginNewFrame();
78  int numFrames() const;
79 
80  void draw(QPainter *painter, int frame = 0) const;
81 
82  int frameStartIndex(int frame) const;
83  int frameEndIndex(int frame) const;
84  int processCommands(QPainter *painter, int begin, int end) const;
85 #ifndef QT_NO_DEBUG_STREAM
86  QString commandDescription(int command) const;
87 #endif
88 
89  void setBoundingRect(const QRectF &rect);
90  QRectF boundingRect() const;
91 
92  virtual QPaintEngine *paintEngine() const;
93  virtual int metric(PaintDeviceMetric m) const;
94  virtual int devType() const;
95 
96  QPaintBuffer &operator=(const QPaintBuffer &other);
97 
98 private:
99  friend class QPainterReplayer;
100  friend class QOpenGLReplayer;
101 
104 
106 };
107 
110 
111 class QPaintBufferEngine;
112 
114 {
115 public:
116  QTextItemIntCopy(const QTextItem &item);
117  ~QTextItemIntCopy();
118  QTextItemInt &operator () () {return m_item;}
119 private:
122 };
123 
125 {
126  uint id : 8;
127  uint size : 24;
128 
129  int offset;
130  int offset2;
131  int extra;
132 };
133 
136 
138 
140 {
141 public:
142  enum Command {
145 
155 
160 
164 
180 
183 
186 
192 
196 
197  // new commands must be added above this line
198 
199  Cmd_LastCommand
200  };
201 
204 
205  int addData(const int *data, int count) {
206  if (count <= 0)
207  return 0;
208  int pos = ints.size();
209  ints.resize(pos + count);
210  memcpy(ints.data() + pos, data, count * sizeof(int));
211  return pos;
212  }
213 
214  int addData(const qreal *data, int count) {
215  if (count <= 0)
216  return 0;
217  int pos = floats.size();
218  floats.resize(pos + count);
219  memcpy(floats.data() + pos, data, count * sizeof(qreal));
220  return pos;
221  }
222 
223  int addData(const QVariant &var) {
224  variants << var;
225  return variants.size() - 1;
226  }
227 
230  cmd.id = command;
231  cmd.size = cmd.offset = cmd.offset2 = cmd.extra = 0;
232  commands << cmd;
233  return &commands.last();
234  }
235 
238  cmd.id = command;
239  cmd.offset = addData(var);
240  cmd.size = cmd.offset2 = cmd.extra = 0;
241  commands << cmd;
242  return &commands.last();
243  }
244 
247  cmd.id = command;
248  cmd.offset = addData(path.points(), path.elementCount() * 2);
249  cmd.offset2 = ints.size();
250  ints << path.hints();
251  // The absence of path elements is indicated by setting the highest bit in 'cmd.offset2'.
252  if (path.elements())
253  addData((const int *) path.elements(), path.elementCount());
254  else
255  cmd.offset2 |= 0x80000000;
256  cmd.size = path.elementCount();
257  cmd.extra = 0;
258  commands << cmd;
259  return &commands.last();
260  }
261 
262  QPaintBufferCommand *addCommand(Command command , const qreal *pts, int arrayLength, int elementCount) {
264  cmd.id = command;
265  cmd.offset = addData(pts, arrayLength);
266  cmd.size = elementCount;
267  cmd.offset2 = cmd.extra = 0;
268  commands << cmd;
269  return &commands.last();
270  }
271 
272  QPaintBufferCommand *addCommand(Command command , const int *pts, int arrayLength, int elementCount) {
274  cmd.id = command;
275  cmd.offset = addData(pts, arrayLength);
276  cmd.size = elementCount;
277  cmd.offset2 = cmd.extra = 0;
278  commands << cmd;
279  return &commands.last();
280  }
281 
282  inline void updateBoundingRect(const QRectF &rect);
283 
285 
289 
292 
297 
298  void *cache;
299 };
300 
301 
303 {
304  // The absence of path elements is indicated by setting the highest bit in 'cmd.offset2'.
306  : vectorPath(d->floats.constData() + cmd.offset,
307  cmd.size,
308  cmd.offset2 & 0x80000000
309  ? 0
310  : (const QPainterPath::ElementType *) (d->ints.constData() + cmd.offset2 + 1),
311  *(d->ints.constData() + (cmd.offset2 & 0x7fffffff))) {}
312 
313  inline const QVectorPath &operator()() const { return vectorPath; }
314 
316 };
317 
318 
320 {
321 public:
323 
324  virtual ~QPainterReplayer() { }
325 
326  void setupTransform(QPainter *painter);
327  virtual void process(const QPaintBufferCommand &cmd);
328  void processCommands(const QPaintBuffer &buffer, QPainter *painter, int begin, int end);
329 
330 protected:
333 
335 };
336 
338 {
339 public:
341 
342  virtual void process(const QPaintBufferCommand &cmd);
343 };
344 
346 
348 {
350 public:
352 
353  virtual bool begin(QPaintDevice *device);
354  virtual bool end();
355 
356  virtual Type type() const { return QPaintEngine::PaintBuffer; }
357 
358  virtual QPainterState *createState(QPainterState *orig) const;
359 
360  virtual void draw(const QVectorPath &path);
361  virtual void fill(const QVectorPath &path, const QBrush &brush);
362  virtual void stroke(const QVectorPath &path, const QPen &pen);
363 
364  virtual void clip(const QVectorPath &path, Qt::ClipOperation op);
365  virtual void clip(const QRect &rect, Qt::ClipOperation op);
366  virtual void clip(const QRegion &region, Qt::ClipOperation op);
367  virtual void clip(const QPainterPath &path, Qt::ClipOperation op);
368 
369  virtual void clipEnabledChanged();
370  virtual void penChanged();
371  virtual void brushChanged();
372  virtual void brushOriginChanged();
373  virtual void opacityChanged();
374  virtual void compositionModeChanged();
375  virtual void renderHintsChanged();
376  virtual void transformChanged();
377  virtual void backgroundModeChanged();
378 
379  virtual void fillRect(const QRectF &rect, const QBrush &brush);
380  virtual void fillRect(const QRectF &rect, const QColor &color);
381 
382  virtual void drawRects(const QRect *rects, int rectCount);
383  virtual void drawRects(const QRectF *rects, int rectCount);
384 
385  virtual void drawLines(const QLine *lines, int lineCount);
386  virtual void drawLines(const QLineF *lines, int lineCount);
387 
388  virtual void drawEllipse(const QRectF &r);
389  virtual void drawEllipse(const QRect &r);
390 
391  virtual void drawPath(const QPainterPath &path);
392 
393  virtual void drawPoints(const QPointF *points, int pointCount);
394  virtual void drawPoints(const QPoint *points, int pointCount);
395 
396  virtual void drawPolygon(const QPointF *points, int pointCount, PolygonDrawMode mode);
397  virtual void drawPolygon(const QPoint *points, int pointCount, PolygonDrawMode mode);
398 
399  virtual void drawPixmap(const QRectF &r, const QPixmap &pm, const QRectF &sr);
400  virtual void drawPixmap(const QPointF &pos, const QPixmap &pm);
401 
402  virtual void drawImage(const QRectF &r, const QImage &pm, const QRectF &sr,
403  Qt::ImageConversionFlags flags = Qt::AutoColor);
404  virtual void drawImage(const QPointF &pos, const QImage &image);
405 
406  virtual void drawTiledPixmap(const QRectF &r, const QPixmap &pixmap, const QPointF &s);
407 
408  virtual void drawTextItem(const QPointF &pos, const QTextItem &ti);
409  virtual void drawStaticTextItem(QStaticTextItem *staticTextItem);
410 
411  virtual void setState(QPainterState *s);
412  virtual uint flags() const {return QPaintEngineEx::DoNotEmulate;}
413 
415 
416  mutable int m_begin_detected : 1;
417  mutable int m_save_detected : 1;
418  mutable int m_stream_raw_text_items : 1;
419  mutable int m_unused : 29;
420 
422 };
423 
425 {
426  Q_OBJECT
427 public:
430  emit aboutToDestroy(buffer);
431  }
432  static QPaintBufferSignalProxy *instance();
433 Q_SIGNALS:
434  void aboutToDestroy(const QPaintBufferPrivate *buffer);
435 };
436 
437 // One resource per paint buffer and vice versa.
439 {
440  Q_OBJECT
441 public:
442  typedef void (*FreeFunc)(void *);
443 
444  QPaintBufferResource(FreeFunc f, QObject *parent = 0);
446  // Set resource 'value' for 'key'.
447  void insert(const QPaintBufferPrivate *key, void *value);
448  // Return resource for 'key'.
449  void *value(const QPaintBufferPrivate *key);
450 public slots:
451  // Remove entry 'key' from cache and delete resource.
452  void remove(const QPaintBufferPrivate *key);
453 private:
455  Cache m_cache;
456  FreeFunc free;
457 };
458 
460 
461 #endif // QPAINTBUFFER_P_H
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
QHash< const QPaintBufferPrivate *, void * > Cache
virtual uint flags() const
The QPainter class performs low-level painting on widgets and other paint devices.
Definition: qpainter.h:86
The QColor class provides colors based on RGB, HSV or CMYK values.
Definition: qcolor.h:67
double d
Definition: qnumeric_p.h:62
Q_GUI_EXPORT QDataStream & operator<<(QDataStream &stream, const QPaintBuffer &buffer)
QPaintBufferCommand * addCommand(Command command, const int *pts, int arrayLength, int elementCount)
double qreal
Definition: qglobal.h:1193
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
QPaintBufferPrivate * d_ptr
int elementCount() const
The QLine class provides a two-dimensional vector using integer precision.
Definition: qline.h:57
The QAtomicInt class provides platform-independent atomic operations on integers. ...
Definition: qatomic.h:55
The QPainterPath class provides a container for painting operations, enabling graphical shapes to be ...
Definition: qpainterpath.h:67
#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
QPaintBufferCommand * addCommand(Command command, const qreal *pts, int arrayLength, int elementCount)
void emitAboutToDestroy(const QPaintBufferPrivate *buffer)
Q_GUI_EXPORT QDataStream & operator>>(QDataStream &stream, QPaintBuffer &buffer)
The QString class provides a Unicode character string.
Definition: qstring.h:83
Q_DECLARE_TYPEINFO(QPaintBufferCommand, Q_MOVABLE_TYPE)
The QObject class is the base class of all Qt objects.
Definition: qobject.h:111
#define Q_SIGNALS
Definition: qobjectdefs.h:72
The QPen class defines how a QPainter should draw lines and outlines of shapes.
Definition: qpen.h:64
virtual int devType() const
Definition: qpaintdevice.h:167
const QPainterPath::ElementType * elements() const
The QLineF class provides a two-dimensional vector using floating point precision.
Definition: qline.h:212
static const QRectF boundingRect(const QPointF *points, int pointCount)
QPaintBufferCommand * addCommand(Command command, const QVectorPath &path)
QPaintBufferPrivate * buffer
QVector< int > ints
int addData(const int *data, int count)
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
The QRectF class defines a rectangle in the plane using floating point precision. ...
Definition: qrect.h:511
QVectorPathCmd(QPaintBufferPrivate *d, const QPaintBufferCommand &cmd)
static FILE * stream
static bool isEmpty(const char *str)
QVector< QPaintBufferCommand > commands
int addData(const QVariant &var)
static void drawRects(const T *rects, int n, const QTransform &transform, IDirectFBSurface *surface)
#define emit
Definition: qobjectdefs.h:76
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
virtual ~QPainterReplayer()
The QRegion class specifies a clip region for a painter.
Definition: qregion.h:68
virtual Type type() const
Reimplement this function to return the paint engine Type.
QVectorPath vectorPath
The QPaintEngine class provides an abstract definition of how QPainter draws to a given device on a g...
Definition: qpaintengine.h:90
QPaintBufferPrivate * d
#define Q_OBJECT
Definition: qobjectdefs.h:157
uint hints() const
The QBrush class defines the fill pattern of shapes drawn by QPainter.
Definition: qbrush.h:76
virtual QPaintEngine * paintEngine() const =0
QPaintBufferEngine * engine
QTextItemInt m_item
The QFont class specifies a font used for drawing text.
Definition: qfont.h:64
const QVectorPath & operator()() const
int key
The QPoint class defines a point in the plane using integer precision.
Definition: qpoint.h:53
const qreal * points() const
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
virtual int metric(PaintDeviceMetric metric) const
static void drawPoints(const T *points, int n, const QTransform &transform, IDirectFBSurface *surface)
QPainterState * m_created_state
The QPixmap class is an off-screen image representation that can be used as a paint device...
Definition: qpixmap.h:71
QPaintBufferCommand * addCommand(Command command)
#define Q_DECLARE_PRIVATE(Class)
Definition: qglobal.h:2467
int addData(const qreal *data, int count)
The QDataStream class provides serialization of binary data to a QIODevice.
Definition: qdatastream.h:71
QPainter * painter
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
#define slots
Definition: qobjectdefs.h:68
static const KeyPair *const end
QPaintBufferCommand * addCommand(Command command, const QVariant &var)
QTransform m_world_matrix
QVector< QVariant > variants
QVector< qreal > floats
The QTransform class specifies 2D transformations of a coordinate system.
Definition: qtransform.h:65
ClipOperation
Definition: qnamespace.h:1495