From d94b6f057d7f4506a8b5d95a06ef36f0800e7848 Mon Sep 17 00:00:00 2001 From: llornkcor Date: Tue, 08 Jul 2003 23:43:32 +0000 Subject: graphics performance test --- (limited to 'development/performance') diff --git a/development/performance/main.cpp b/development/performance/main.cpp new file mode 100644 index 0000000..8802777 --- a/dev/null +++ b/development/performance/main.cpp @@ -0,0 +1,33 @@ +/********************************************************************** +** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. +** +** This file is part of the Qtopia Environment. +** +** This file may be distributed and/or modified under the terms of the +** GNU General Public License version 2 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. +** +** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +** +** See http://www.trolltech.com/gpl/ for GPL licensing information. +** +** Contact info@trolltech.com if any conditions of this licensing are +** not clear to you. +** +**********************************************************************/ + +#include "performancetest.h" + +#include + +int main( int argc, char ** argv ) +{ + QPEApplication a( argc, argv ); + + PerformanceTest mw; + a.showMainWidget( &mw ); + + return a.exec(); +} diff --git a/development/performance/opie-performance.control b/development/performance/opie-performance.control new file mode 100644 index 0000000..299fda2 --- a/dev/null +++ b/development/performance/opie-performance.control @@ -0,0 +1,10 @@ +Files: bin/performance apps/Applications/performance.desktop +Priority: optional +Section: opie/other +Maintainer: Trolltech (www.trolltech.com) +Architecture: $CPU_ARCH +Arch: $DEVICE_ARCH +Version: $QPE_VERSION-10 +Depends: qpe-libqtopia +Description: Graphics performance tester + Graphics performance tester for Qtopia. diff --git a/development/performance/performance.pro b/development/performance/performance.pro new file mode 100644 index 0000000..ab3a51a --- a/dev/null +++ b/development/performance/performance.pro @@ -0,0 +1,12 @@ +TEMPLATE = app +CONFIG += qt warn_on release +#DESTDIR = $(QPEDIR)/bin +HEADERS = performancetest.h +SOURCES = main.cpp performancetest.cpp +INTERFACES = performancetestbase.ui +TARGET = performance +INCLUDEPATH += $(OPIEDIR)/include +DEPENDPATH += $(OPIEDIR)/include +LIBS += -lqpe -lqte + +include ( $(OPIEDIR)/include.pro ) diff --git a/development/performance/performancetest.cpp b/development/performance/performancetest.cpp new file mode 100644 index 0000000..1bc8ee0 --- a/dev/null +++ b/development/performance/performancetest.cpp @@ -0,0 +1,176 @@ + +#include "performancetest.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +class TestItem +{ +public: + TestItem( const QString &d, int it ) : msecs(0), desc(d), iter(it) + { + } + + void begin() + { + timeKeeper.start(); + } + + void end() + { + msecs = timeKeeper.elapsed(); + } + + QString report() const + { + QString rpt( "%1 (%2): %3msecs" ); + return rpt.arg(desc).arg(iter).arg(msecs); + } + + int iterations() const { return iter; } + int elapsed() const { return msecs; } + +private: + int msecs; + QString desc; + int iter; + QTime timeKeeper; +}; + +void fillRect( QWidget *w, TestItem *ti ) +{ + QPainter p( w ); + ti->begin(); + for ( int i = 0; i < ti->iterations(); i++ ) { + p.fillRect( rand() % 40, rand() % 40, 200, 200, Qt::red ); + } + ti->end(); +} + +void bitBlt( QWidget *w, TestItem *ti ) +{ + QPixmap pm( 200, 200 ); + QPainter pmp( &pm ); + pmp.setBrush( Qt::white ); + pmp.drawRect( 0, 0, 200, 200 ); + pmp.drawLine( 0, 0, 200, 200 ); + pmp.drawLine( 0, 200, 200, 0 ); + pmp.end(); + + QPainter p( w ); + ti->begin(); + for ( int i = 0; i < ti->iterations(); i++ ) { + p.drawPixmap( rand() % 100, rand() % 100, pm ); + } + ti->end(); +} + +void alphaBlt( QWidget *w, TestItem *ti ) +{ + QImage img( 200, 200, 32 ); + img.setAlphaBuffer( TRUE ); + for ( int y = 0; y < img.height(); y++ ) { + for ( int x = 0; x < img.width(); x++ ) { + QColor col; + col.setHsv( 360*x/img.width(), 255, 255 ); + QRgb rgb = col.rgb(); + rgb &= 0x00ffffff; + rgb |= (255*y/img.height()) << 24; + img.setPixel( x, y, rgb ); + } + } + + QPixmap pm; + pm.convertFromImage( img ); + QPainter p( w ); + ti->begin(); + for ( int i = 0; i < ti->iterations(); i++ ) { + p.drawPixmap( rand() % 20, rand() % 20, pm ); + } + ti->end(); +} + +void drawText( QWidget *w, TestItem *ti ) +{ + QPainter p( w ); + p.setPen( Qt::white ); + QString text( "The quick red fox jumps over the lazy brown dog." ); // No tr + ti->begin(); + for ( int i = 0; i < ti->iterations(); i++ ) { + p.drawText( rand() % 100, rand() % 300, text ); + } + ti->end(); +} + + +struct { + int id; + const char *name; + int iterations; + void (*testFunc)(QWidget *, TestItem *); +} +perfTests[] = +{ + { 0, "Fill Rect", 1000, &fillRect }, // No tr + { 1, "Bit Blt", 1000, &bitBlt }, // No tr + { 2, "Alpha Blt", 100, &alphaBlt }, // No tr + { 3, "Draw Text", 5000, &drawText }, // No tr + {-1, "", 0, 0 } +}; + +PerformanceTest::PerformanceTest( QWidget *parent, const char *name, WFlags f ) + : PerformanceTestBase( parent, name, f ) +{ + connect( testButton, SIGNAL(clicked()), this, SLOT(doTest()) ); + connect( optionGroup, SIGNAL(clicked(int)), this, SLOT(testClicked(int)) ); + QVBoxLayout *vb = new QVBoxLayout( testFrame ); + testWidget = new QWidget( testFrame ); + testWidget->setBackgroundColor( black ); + vb->addWidget( testWidget ); + + int count = 0; + while ( perfTests[count].id >= 0 ) { + QCheckBox *cb = new QCheckBox( perfTests[count].name, optionGroup ); + cb->setChecked( TRUE ); + optionGroupLayout->addWidget( cb ); + count++; + } + enabledTests.resize( count ); + enabledTests.fill( TRUE ); +} + +void PerformanceTest::testClicked( int btn ) +{ + enabledTests[btn] = optionGroup->find( btn )->isOn(); +} + +void PerformanceTest::doTest() +{ + testButton->setEnabled( FALSE ); + qApp->processEvents(); + int totalTime = 0; + int i = 0; + while ( perfTests[i].id >= 0 ) { + if ( enabledTests[i] ) { + srand( 1 ); + testButton->setText( perfTests[i].name ); + qApp->processEvents(); + TestItem ti( perfTests[i].name, perfTests[i].iterations ); + (perfTests[i].testFunc)(testWidget, &ti); + resultsEdit->append( ti.report() ); + totalTime += ti.elapsed(); + testWidget->erase(); + } + i++; + } + resultsEdit->append( QString("-> Total time: %1ms\n").arg(totalTime) ); // No tr + testButton->setText( "Test" ); // No tr + testButton->setEnabled( TRUE ); +} diff --git a/development/performance/performancetest.h b/development/performance/performancetest.h new file mode 100644 index 0000000..c0a80c4 --- a/dev/null +++ b/development/performance/performancetest.h @@ -0,0 +1,18 @@ + +#include "performancetestbase.h" + +class PerformanceTest : public PerformanceTestBase +{ + Q_OBJECT +public: + PerformanceTest( QWidget *parent=0, const char *name=0, WFlags fl=0 ); + +protected slots: + void testClicked( int ); + void doTest(); + +private: + QWidget *testWidget; + QArray enabledTests; +}; + diff --git a/development/performance/performancetestbase.ui b/development/performance/performancetestbase.ui new file mode 100644 index 0000000..156aa5f --- a/dev/null +++ b/development/performance/performancetestbase.ui @@ -0,0 +1,167 @@ + +PerformanceTestBase + + QWidget + + name + PerformanceTestBase + + + geometry + + 0 + 0 + 219 + 261 + + + + caption + Performance Tester + + + layoutMargin + + + + margin + 0 + + + spacing + 6 + + + QTabWidget + + name + TabWidget2 + + + layoutMargin + + + QWidget + + name + tab + + + title + Test + + + + margin + 6 + + + spacing + 6 + + + QFrame + + name + testFrame + + + frameShape + StyledPanel + + + frameShadow + Raised + + + + QPushButton + + name + testButton + + + text + Test + + + + + + QWidget + + name + tab + + + title + Setup + + + + margin + 11 + + + spacing + 6 + + + QButtonGroup + + name + optionGroup + + + title + Tests + + + + margin + 11 + + + spacing + 6 + + + + + + + QWidget + + name + tab + + + title + Results + + + + margin + 6 + + + spacing + 6 + + + QMultiLineEdit + + name + resultsEdit + + + readOnly + true + + + + + + + + -- cgit v0.9.0.2