Qt 4.8
qgraphicssystem_trace.cpp
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 plugins 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 
43 #include <private/qpixmap_raster_p.h>
44 #include <private/qpaintbuffer_p.h>
45 #include <private/qwindowsurface_raster_p.h>
46 
47 #include <QFile>
48 #include <QPainter>
49 #include <QtDebug>
50 
52 
54 {
55 public:
58 
60  void beginPaint(const QRegion &rgn);
61  void endPaint(const QRegion &rgn);
62 
63  bool scroll(const QRegion &area, int dx, int dy);
64 
65 private:
68 
70 };
71 
73  : QRasterWindowSurface(widget)
74  , buffer(0)
75  , winId(0)
76 {
77 }
78 
80 {
81  if (buffer) {
82  QFile outputFile(QString(QLatin1String("qtgraphics-%0.trace")).arg(winId));
83  if (outputFile.open(QIODevice::WriteOnly)) {
84  QDataStream out(&outputFile);
86 
87  out.writeBytes("qttraceV2", 9);
88 
89  uint version = 1;
90 
91  out << version << *buffer << updates;
92  }
93  delete buffer;
94  }
95 }
96 
98 {
99  if (!buffer) {
100  buffer = new QPaintBuffer;
101 #ifdef Q_WS_QPA
102  buffer->setBoundingRect(QRect(QPoint(), size()));
103 #else
105 #endif
106  }
107  return buffer;
108 }
109 
111 {
112  // ensure paint buffer is created
113  paintDevice();
115 
117 }
118 
120 {
122  buffer->draw(&p, buffer->numFrames()-1);
123  p.end();
124 
125  winId = (qulonglong)window()->winId();
126 
127  updates << rgn;
128 
130 }
131 
132 bool QTraceWindowSurface::scroll(const QRegion &, int, int)
133 {
134  // TODO: scrolling should also be streamed and replayed
135  // to test scrolling performance
136  return false;
137 }
138 
140 {
141 }
142 
144 {
145  return new QRasterPixmapData(type);
146 }
147 
149 {
150  return new QTraceWindowSurface(widget);
151 }
152 
QTraceWindowSurface(QWidget *widget)
The QPainter class performs low-level painting on widgets and other paint devices.
Definition: qpainter.h:86
QRect geometry() const
Returns the currently allocated area on the screen.
int type
Definition: qmetatype.cpp:239
QWindowSurface * createWindowSurface(QWidget *widget) const
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
QPointer< QWidget > widget
bool open(OpenMode flags)
Opens the file using OpenMode mode, returning true if successful; otherwise false.
Definition: qfile.cpp:1064
void beginPaint(const QRegion &rgn)
This function is called before painting onto the surface begins, with the region in which the paintin...
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:150
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
The QString class provides a Unicode character string.
Definition: qstring.h:83
void endPaint(const QRegion &rgn)
This function is called after painting onto the surface has ended, with the region in which the paint...
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
QDataStream & writeBytes(const char *, uint len)
Writes the length specifier len and the buffer s to the stream and returns a reference to the stream...
unsigned int uint
Definition: qglobal.h:996
The QRegion class specifies a clip region for a painter.
Definition: qregion.h:68
The QWindowSurface class provides the drawing area for top-level windows.
void draw(QPainter *painter, int frame=0) const
The QFile class provides an interface for reading from and writing to files.
Definition: qfile.h:65
virtual void endPaint(const QRegion &)
This function is called after painting onto the surface has ended, with the region in which the paint...
void beginPaint(const QRegion &rgn)
This function is called before painting onto the surface begins, with the region in which the paintin...
QPaintDevice * paintDevice()
Implement this function to return the appropriate paint device.
The QPoint class defines a point in the plane using integer precision.
Definition: qpoint.h:53
QPaintDevice * paintDevice()
Implement this function to return the appropriate paint device.
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
int numFrames() const
QPixmapData * createPixmapData(QPixmapData::PixelType type) const
void beginNewFrame()
WId winId() const
Returns the window system identifier of the widget.
Definition: qwidget.cpp:2557
The QDataStream class provides serialization of binary data to a QIODevice.
Definition: qdatastream.h:71
quint64 qulonglong
Definition: qglobal.h:952
bool scroll(const QRegion &area, int dx, int dy)
Scrolls the given area dx pixels to the right and dy downward; both dx and dy may be negative...
void setFloatingPointPrecision(FloatingPointPrecision precision)
Sets the floating point precision of the data stream to precision.
QWidget * window() const
Returns a pointer to the top-level window associated with this surface.
bool end()
Ends painting.
Definition: qpainter.cpp:1929
void setBoundingRect(const QRectF &rect)
static int area(const QSize &s)
Definition: qicon.cpp:155