diff options
author | Samuel Rødal <sroedal@trolltech.com> | 2009-09-02 12:33:57 (GMT) |
---|---|---|
committer | Samuel Rødal <sroedal@trolltech.com> | 2009-09-03 12:13:09 (GMT) |
commit | 4feb152405e96125b6be2807d515293e3f25ab1a (patch) | |
tree | 52b0be39e7f435db7f7e41ed73a2bc53e01f4c8e /src/plugins/graphicssystems | |
parent | d4a4b01f2f08a9031d692344d0d264de472da25e (diff) | |
download | Qt-4feb152405e96125b6be2807d515293e3f25ab1a.zip Qt-4feb152405e96125b6be2807d515293e3f25ab1a.tar.gz Qt-4feb152405e96125b6be2807d515293e3f25ab1a.tar.bz2 |
Added trace graphics system for painting performance profiling.
When running an application with graphics system trace everything that
gets painted to the window surface is proxied through a QPaintBuffer,
which is then both streamed to a trace file and replayed on a raster
window surface. The trace file can then be replayed with
tools/qttracereplay to measure pure painting performance.
Reviewed-by: Gunnar Sletta
Diffstat (limited to 'src/plugins/graphicssystems')
-rw-r--r-- | src/plugins/graphicssystems/graphicssystems.pro | 1 | ||||
-rw-r--r-- | src/plugins/graphicssystems/trace/main.cpp | 69 | ||||
-rw-r--r-- | src/plugins/graphicssystems/trace/qgraphicssystem_trace.cpp | 133 | ||||
-rw-r--r-- | src/plugins/graphicssystems/trace/qgraphicssystem_trace_p.h | 71 | ||||
-rw-r--r-- | src/plugins/graphicssystems/trace/trace.pro | 12 |
5 files changed, 286 insertions, 0 deletions
diff --git a/src/plugins/graphicssystems/graphicssystems.pro b/src/plugins/graphicssystems/graphicssystems.pro index bfdec6a..14e3cfc 100644 --- a/src/plugins/graphicssystems/graphicssystems.pro +++ b/src/plugins/graphicssystems/graphicssystems.pro @@ -1,4 +1,5 @@ TEMPLATE = subdirs +SUBDIRS += trace contains(QT_CONFIG, opengl):SUBDIRS += opengl contains(QT_CONFIG, openvg):contains(QT_CONFIG, egl):SUBDIRS += openvg diff --git a/src/plugins/graphicssystems/trace/main.cpp b/src/plugins/graphicssystems/trace/main.cpp new file mode 100644 index 0000000..908e3f4 --- /dev/null +++ b/src/plugins/graphicssystems/trace/main.cpp @@ -0,0 +1,69 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.1, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <private/qgraphicssystemplugin_p.h> +#include "qgraphicssystem_trace_p.h" + +QT_BEGIN_NAMESPACE + +class QTraceGraphicsSystemPlugin : public QGraphicsSystemPlugin +{ +public: + QStringList keys() const; + QGraphicsSystem *create(const QString&); +}; + +QStringList QTraceGraphicsSystemPlugin::keys() const +{ + return QStringList(QLatin1String("Trace")); +} + +QGraphicsSystem* QTraceGraphicsSystemPlugin::create(const QString& system) +{ + if (system.toLower() == QLatin1String("trace")) + return new QTraceGraphicsSystem; + + return 0; +} + +Q_EXPORT_PLUGIN2(trace, QTraceGraphicsSystemPlugin) + +QT_END_NAMESPACE diff --git a/src/plugins/graphicssystems/trace/qgraphicssystem_trace.cpp b/src/plugins/graphicssystems/trace/qgraphicssystem_trace.cpp new file mode 100644 index 0000000..36a8df1 --- /dev/null +++ b/src/plugins/graphicssystems/trace/qgraphicssystem_trace.cpp @@ -0,0 +1,133 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.1, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qgraphicssystem_trace_p.h" +#include <private/qpixmap_raster_p.h> +#include <private/qpaintbuffer_p.h> +#include <private/qwindowsurface_raster_p.h> + +#include <QFile> +#include <QPainter> +#include <QtDebug> + +QT_BEGIN_NAMESPACE + +class QTraceWindowSurface : public QRasterWindowSurface +{ +public: + QTraceWindowSurface(QWidget *widget); + ~QTraceWindowSurface(); + + QPaintDevice *paintDevice(); + void endPaint(const QRegion &rgn); + +private: + QPaintBuffer *buffer; + + QFile *outputFile; + QDataStream *out; + + int frameId; +}; + +QTraceWindowSurface::QTraceWindowSurface(QWidget *widget) + : QRasterWindowSurface(widget) + , buffer(0) + , outputFile(0) + , out(0) + , frameId(0) +{ +} + +QTraceWindowSurface::~QTraceWindowSurface() +{ + delete out; + delete outputFile; +} + +QPaintDevice *QTraceWindowSurface::paintDevice() +{ + if (!buffer) { + buffer = new QPaintBuffer; + buffer->setBoundingRect(geometry()); + } + return buffer; +} + +void QTraceWindowSurface::endPaint(const QRegion &rgn) +{ + if (!out) { + outputFile = new QFile(QString(QLatin1String("qtgraphics-%0.trace")).arg((qulonglong)window()->winId())); + if (outputFile->open(QIODevice::WriteOnly)) + out = new QDataStream(outputFile); + } + + QPainter p(QRasterWindowSurface::paintDevice()); + buffer->draw(&p); + p.end(); + + if (out) { + *out << frameId++; + *out << (qulonglong)window()->winId(); + *out << geometry(); + *out << rgn; + *out << *buffer; + } + + delete buffer; + buffer = 0; +} + +QTraceGraphicsSystem::QTraceGraphicsSystem() +{ +} + +QPixmapData *QTraceGraphicsSystem::createPixmapData(QPixmapData::PixelType type) const +{ + return new QRasterPixmapData(type); +} + +QWindowSurface *QTraceGraphicsSystem::createWindowSurface(QWidget *widget) const +{ + return new QTraceWindowSurface(widget); +} + +QT_END_NAMESPACE diff --git a/src/plugins/graphicssystems/trace/qgraphicssystem_trace_p.h b/src/plugins/graphicssystems/trace/qgraphicssystem_trace_p.h new file mode 100644 index 0000000..5deafc9 --- /dev/null +++ b/src/plugins/graphicssystems/trace/qgraphicssystem_trace_p.h @@ -0,0 +1,71 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.1, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QGRAPHICSSYSTEM_TRACE_P_H +#define QGRAPHICSSYSTEM_TRACE_P_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists for the convenience +// of other Qt classes. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +#include <QtGui/private/qgraphicssystem_p.h> + +QT_BEGIN_NAMESPACE + +class QTraceGraphicsSystem : public QGraphicsSystem +{ +public: + QTraceGraphicsSystem(); + + QPixmapData *createPixmapData(QPixmapData::PixelType type) const; + QWindowSurface *createWindowSurface(QWidget *widget) const; +}; + +QT_END_NAMESPACE + +#endif diff --git a/src/plugins/graphicssystems/trace/trace.pro b/src/plugins/graphicssystems/trace/trace.pro new file mode 100644 index 0000000..d548a6c --- /dev/null +++ b/src/plugins/graphicssystems/trace/trace.pro @@ -0,0 +1,12 @@ +TARGET = qtracegraphicssystem +include(../../qpluginbase.pri) + +QT += network + +QTDIR_build:DESTDIR = $$QT_BUILD_TREE/plugins/graphicssystems + +SOURCES = main.cpp qgraphicssystem_trace.cpp + +target.path += $$[QT_INSTALL_PLUGINS]/graphicssystems +INSTALLS += target +INCLUDEPATH += ../../../3rdparty/harfbuzz/src |