From f80d4f2160fda579e7c83fda1dec6c0607d24274 Mon Sep 17 00:00:00 2001 From: Sandro Giessl Date: Fri, 11 Mar 2005 14:28:19 +0000 Subject: [PATCH] add caption and resize tests. svn path=/trunk/kdebase/kwin/; revision=396655 --- tools/decobenchmark/main.cpp | 46 ++++++++++++++----- tools/decobenchmark/main.h | 12 ++++- tools/decobenchmark/preview.cpp | 78 +++++++++++++++++++-------------- tools/decobenchmark/preview.h | 10 ++++- 4 files changed, 100 insertions(+), 46 deletions(-) diff --git a/tools/decobenchmark/main.cpp b/tools/decobenchmark/main.cpp index 2b3ec6ba7b..7db2eb1530 100644 --- a/tools/decobenchmark/main.cpp +++ b/tools/decobenchmark/main.cpp @@ -39,13 +39,15 @@ static KCmdLineOptions options[] = { - { "+[STYLE]", "Decoration to use.", "kwin3_plastik" }, - { "+[N]", "Number of repetitions.", "200000" }, + { "+decoration", "Decoration library to use, such as kwin3_plastik.", 0 }, + { "+tests", "Which test should be executed ('all', 'repaint', 'caption', 'resize')", 0 }, + { "+repetitions", "Number of test repetitions.", 0 }, { 0, 0, 0 } }; -DecoBenchApplication::DecoBenchApplication(const QString &library, int count) : -m_count(count) +DecoBenchApplication::DecoBenchApplication(const QString &library, Tests tests, int count) : + m_tests(tests), + m_count(count) { KConfig kwinConfig("kwinrc"); kwinConfig.setGroup("Style"); @@ -67,11 +69,17 @@ DecoBenchApplication::~DecoBenchApplication() void DecoBenchApplication::executeTest() { - kdDebug() << "start " << m_count << " repaints..." << endl; clock_t stime = clock(); timeb astart, aend; ftime(&astart); - preview->performRepaintTest(m_count); + + if (m_tests == AllTests || m_tests == RepaintTest) + preview->performRepaintTest(m_count); + if (m_tests == AllTests || m_tests == CaptionTest) + preview->performCaptionTest(m_count); + if (m_tests == AllTests || m_tests == ResizeTest) + preview->performResizeTest(m_count); + clock_t etime = clock(); ftime(&aend); @@ -84,18 +92,36 @@ int main(int argc, char** argv) { QString style = "keramik"; // KApplication app(argc, argv); - KAboutData about("decobench", "DecoBench", "0.1", "kwin decoration performance tester...", KAboutData::License_LGPL, "(C) 2005 Sandro Giessl"); + KAboutData about("decobenchmark", "DecoBenchmark", "0.1", "kwin decoration performance tester...", KAboutData::License_LGPL, "(C) 2005 Sandro Giessl"); KCmdLineArgs::init(argc, argv, &about); KCmdLineArgs::addCmdLineOptions( options ); KCmdLineArgs *args = KCmdLineArgs::parsedArgs(); - QString library = QString(args->arg(0) ); - int count = QString(args->arg(1) ).toInt(); + if (args->count() != 3) + KCmdLineArgs::usage("Wrong number of arguments!"); - DecoBenchApplication app(library, count); + QString library = QString(args->arg(0) ); + QString t = QString(args->arg(1) ); + int count = QString(args->arg(2) ).toInt(); + + Tests test; + if (t == "all") + test = AllTests; + else if (t == "repaint") + test = RepaintTest; + else if (t == "caption") + test = CaptionTest; + else if (t == "resize") + test = ResizeTest; + else + KCmdLineArgs::usage("Specify a valid test!"); + + DecoBenchApplication app(library, test, count); QTimer::singleShot(0, &app, SLOT(executeTest())); app.exec(); } #include "main.moc" + +// kate: space-indent off; tab-width 4; diff --git a/tools/decobenchmark/main.h b/tools/decobenchmark/main.h index 422d542c69..f16f507041 100644 --- a/tools/decobenchmark/main.h +++ b/tools/decobenchmark/main.h @@ -21,11 +21,18 @@ #ifndef BENCH_MAIN_H #define BENCH_MAIN_H +enum Tests { + AllTests, + RepaintTest, + CaptionTest, + ResizeTest +}; + class DecoBenchApplication : public KApplication { Q_OBJECT public: - DecoBenchApplication(const QString &library, int count); + DecoBenchApplication(const QString &library, Tests tests, int count); ~DecoBenchApplication(); public slots: @@ -34,7 +41,10 @@ public slots: private: KDecorationPreview *preview; KDecorationPlugins *plugins; + Tests m_tests; int m_count; }; #endif // BENCH_MAIN_H + +// kate: space-indent off; tab-width 4; diff --git a/tools/decobenchmark/preview.cpp b/tools/decobenchmark/preview.cpp index 378838bbe8..e8920c6a57 100644 --- a/tools/decobenchmark/preview.cpp +++ b/tools/decobenchmark/preview.cpp @@ -19,6 +19,8 @@ #include "preview.h" +#include + #include #include #include @@ -40,7 +42,7 @@ KDecorationPreview::KDecorationPreview( QWidget* parent, const char* name ) { options = new KDecorationPreviewOptions; - bridge = new KDecorationPreviewBridge( this, true ); + bridge = new KDecorationPreviewBridge( this, true, "Deco Benchmark" ); deco = 0; @@ -58,12 +60,40 @@ KDecorationPreview::~KDecorationPreview() void KDecorationPreview::performRepaintTest(int n) { + kdDebug() << "start " << n << " repaints..." << endl; + bridge->setCaption("Deco Benchmark"); + deco->captionChange(); + positionPreviews(0); for (int i = 0; i < n; ++i) { deco->widget()->repaint(); kapp->processEvents(); } } +void KDecorationPreview::performCaptionTest(int n) +{ + kdDebug() << "start " << n << " caption changes..." << endl; + QString caption = "Deco Benchmark %1"; + positionPreviews(0); + for (int i = 0; i < n; ++i) { + bridge->setCaption(caption.arg(i) ); + deco->captionChange(); + deco->widget()->repaint(); + kapp->processEvents(); + } +} + +void KDecorationPreview::performResizeTest(int n) +{ + kdDebug() << "start " << n << " resizes..." << endl; + bridge->setCaption("Deco Benchmark"); + deco->captionChange(); + for (int i = 0; i < n; ++i) { + positionPreviews(i % 200); + kapp->processEvents(); + } +} + bool KDecorationPreview::recreateDecoration( KDecorationPlugins* plugins ) { delete deco; @@ -79,38 +109,15 @@ bool KDecorationPreview::recreateDecoration( KDecorationPlugins* plugins ) return true; } -void KDecorationPreview::positionPreviews() +void KDecorationPreview::positionPreviews(int shrink) { -// int titleBarHeight, leftBorder, rightBorder, xoffset, -// dummy1, dummy2, dummy3; - if ( !deco ) return; - QSize size = QSize(width()-2*10, height()-2*10)/*.expandedTo(deco->minimumSize()*/; + QSize size = QSize(width()-2*10-shrink, height()-2*10-shrink)/*.expandedTo(deco->minimumSize()*/; QRect geometry(QPoint(10, 10), size); deco->widget()->setGeometry(geometry); - -// // don't have more than one reference to the same dummy variable in one borders() call. -// deco[Active]->borders( dummy1, dummy2, titleBarHeight, dummy3 ); -// deco[Inactive]->borders( leftBorder, rightBorder, dummy1, dummy2 ); -// -// titleBarHeight = kMin( int( titleBarHeight * .9 ), 30 ); -// xoffset = kMin( kMax( 10, QApplication::reverseLayout() -// ? leftBorder : rightBorder ), 30 ); -// -// // Resize the active window -// size = QSize( width() - xoffset, height() - titleBarHeight ) -// .expandedTo( deco[Active]->minimumSize() ); -// geometry = QRect( QPoint( 0, titleBarHeight ), size ); -// deco[Active]->widget()->setGeometry( QStyle::visualRect( geometry, this ) ); -// -// // Resize the inactive window -// size = QSize( width() - xoffset, height() - titleBarHeight ) -// .expandedTo( deco[Inactive]->minimumSize() ); -// geometry = QRect( QPoint( xoffset, 0 ), size ); -// deco[Inactive]->widget()->setGeometry( QStyle::visualRect( geometry, this ) ); } void KDecorationPreview::setPreviewMask( const QRegion& reg, int mode ) @@ -153,10 +160,15 @@ QRegion KDecorationPreview::unobscuredRegion( bool active, const QRegion& r ) co return r; } -KDecorationPreviewBridge::KDecorationPreviewBridge( KDecorationPreview* p, bool a ) - : preview( p ), active( a ) - { - } +KDecorationPreviewBridge::KDecorationPreviewBridge( KDecorationPreview* p, bool a, const QString &c ) + : preview( p ), active( a ), m_caption( c ) +{ +} + +void KDecorationPreviewBridge::setCaption(const QString &c) +{ + m_caption = c; +} QWidget* KDecorationPreviewBridge::initialParentWidget() const { @@ -254,9 +266,9 @@ QIconSet KDecorationPreviewBridge::icon() const } QString KDecorationPreviewBridge::caption() const - { - return active ? i18n( "Active Window" ) : i18n( "Inactive Window" ); - } +{ + return m_caption; +} void KDecorationPreviewBridge::processMousePressEvent( QMouseEvent* ) { diff --git a/tools/decobenchmark/preview.h b/tools/decobenchmark/preview.h index 9bf04f8597..0c4e100643 100644 --- a/tools/decobenchmark/preview.h +++ b/tools/decobenchmark/preview.h @@ -37,13 +37,15 @@ class KDecorationPreview virtual ~KDecorationPreview(); void performRepaintTest(int n); + void performCaptionTest(int n); + void performResizeTest(int n); bool recreateDecoration( KDecorationPlugins* plugin ); void setPreviewMask( const QRegion&, int ); QRegion unobscuredRegion( bool, const QRegion& ) const; QRect windowGeometry( bool ) const; private: - void positionPreviews(); + void positionPreviews(int shrink = 0); KDecorationPreviewOptions* options; KDecorationPreviewBridge* bridge; KDecoration* deco; @@ -53,7 +55,10 @@ class KDecorationPreviewBridge : public KDecorationBridge { public: - KDecorationPreviewBridge( KDecorationPreview* preview, bool active ); + KDecorationPreviewBridge( KDecorationPreview* preview, bool active, const QString &caption ); + + void setCaption(const QString &caption); + virtual bool isActive() const; virtual bool isCloseable() const; virtual bool isMaximizable() const; @@ -100,6 +105,7 @@ class KDecorationPreviewBridge private: KDecorationPreview* preview; bool active; + QString m_caption; }; class KDecorationPreviewOptions