2
* perftest.cc -- Part of Krita
4
* Copyright (c) 2004 Boudewijn Rempt <boud@valdyas.org>
6
* This program is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation; either version 2 of the License, or
9
* (at your option) any later version.
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU General Public License for more details.
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
27
#include <qradiobutton.h>
28
#include <qcheckbox.h>
30
#include <qtextedit.h>
31
#include <qdatetime.h>
34
#include <kiconloader.h>
35
#include <kinstance.h>
36
#include <kdialogbase.h>
37
#include <kmessagebox.h>
38
#include <kstandarddirs.h>
39
#include <ktempfile.h>
41
#include <kgenericfactory.h>
42
#include <knuminput.h>
46
#include "kis_meta_registry.h"
47
#include <kis_resourceserver.h>
48
#include "kis_cursor.h"
50
#include <kis_config.h>
51
#include <kis_image.h>
52
#include <kis_layer.h>
53
#include <kis_global.h>
54
#include <kis_types.h>
56
#include <kis_selection.h>
57
#include <kis_colorspace_factory_registry.h>
58
#include <kis_colorspace.h>
59
#include <kis_painter.h>
60
#include <kis_fill_painter.h>
62
#include <kis_paint_device.h>
63
#include <kis_iterators_pixel.h>
65
#include "kis_filter_config_widget.h"
66
#include "kis_factory.h"
68
#include "dlg_perftest.h"
69
#include "wdg_perftest.h"
71
#define USE_CALLGRIND 0
74
#include <valgrind/callgrind.h>
78
typedef KGenericFactory<PerfTest> PerfTestFactory;
79
K_EXPORT_COMPONENT_FACTORY( kritaperftest, PerfTestFactory( "krita" ) )
81
PerfTest::PerfTest(QObject *parent, const char *name, const QStringList &)
82
: KParts::Plugin(parent, name)
84
if ( parent->inherits("KisView") )
86
setInstance(PerfTestFactory::instance());
87
setXMLFile(locate("data","kritaplugins/perftest.rc"), true);
89
(void) new KAction(i18n("&Performance Test..."), 0, 0, this, SLOT(slotPerfTest()), actionCollection(), "perf_test");
91
m_view = (KisView*) parent;
100
void PerfTest::slotPerfTest()
102
KisImageSP image = m_view->canvasSubject()->currentImg();
106
DlgPerfTest * dlgPerfTest = new DlgPerfTest(m_view, "PerfTest");
107
Q_CHECK_PTR(dlgPerfTest);
109
dlgPerfTest->setCaption(i18n("Performance Test"));
111
QString report = QString("");
113
if (dlgPerfTest->exec() == QDialog::Accepted) {
115
Q_INT32 testCount = (Q_INT32)qRound(dlgPerfTest->page()->intTestCount->value());
117
if (dlgPerfTest->page()->chkBitBlt->isChecked()) {
118
kdDebug() << "bltTest:\n";
119
QString s = bltTest(testCount);
120
report = report.append(s);
121
kdDebug() << s << "\n";
123
if (dlgPerfTest->page()->chkFill->isChecked()) {
124
kdDebug() << "Filltest\n";
125
QString s= fillTest(testCount);
126
report = report.append(s);
127
kdDebug() << s << "\n";
129
if (dlgPerfTest->page()->chkGradient->isChecked()) {
130
kdDebug() << "Gradienttest\n";
131
QString s = gradientTest(testCount);
132
report = report.append(s);
133
kdDebug() << s << "\n";
135
if (dlgPerfTest->page()->chkPixel->isChecked()) {
136
kdDebug() << "Pixeltest\n";
137
QString s = pixelTest(testCount);
138
report = report.append(s);
139
kdDebug() << s << "\n";
141
if (dlgPerfTest->page()->chkShape->isChecked()) {
142
kdDebug() << "Shapetest\n";
143
QString s = shapeTest(testCount);
144
report = report.append(s);
145
kdDebug() << s << "\n";
147
if (dlgPerfTest->page()->chkLayer->isChecked()) {
148
kdDebug() << "LayerTest\n";
149
QString s = layerTest(testCount);
150
report = report.append(s);
151
kdDebug() << s << "\n";
153
if (dlgPerfTest->page()->chkScale->isChecked()) {
154
kdDebug() << "Scaletest\n";
155
QString s = scaleTest(testCount);
156
report = report.append(s);
157
kdDebug() << s << "\n";
159
if (dlgPerfTest->page()->chkRotate->isChecked()) {
160
kdDebug() << "Rotatetest\n";
161
QString s = rotateTest(testCount);
162
report = report.append(s);
163
kdDebug() << s << "\n";
165
if (dlgPerfTest->page()->chkRender->isChecked()) {
166
kdDebug() << "Rendertest\n";
167
QString s = renderTest(testCount);
168
report = report.append(s);
169
kdDebug() << s << "\n";
171
if (dlgPerfTest->page()->chkSelection->isChecked()) {
172
kdDebug() << "Selectiontest\n";
173
QString s = selectionTest(testCount);
174
report = report.append(s);
175
kdDebug() << s << "\n";
177
if (dlgPerfTest->page()->chkColorConversion->isChecked()) {
178
kdDebug() << "Colorconversiontest\n";
179
QString s = colorConversionTest(testCount);
180
report = report.append(s);
181
kdDebug() << s << "\n";
183
if (dlgPerfTest->page()->chkFilter-> isChecked()) {
184
kdDebug() << "filtertest\n";
185
QString s = filterTest(testCount);
186
report = report.append(s);
187
kdDebug() << s << "\n";
189
if (dlgPerfTest->page()->chkReadBytes->isChecked()) {
190
kdDebug() << "Readbytes test\n";
191
QString s = readBytesTest(testCount);
192
report = report.append(s);
193
kdDebug() << s << "\n";
195
if (dlgPerfTest->page()->chkWriteBytes-> isChecked()) {
196
kdDebug() << "Writebytes test\n";
197
QString s = writeBytesTest(testCount);
198
report = report.append(s);
199
kdDebug() << s << "\n";
201
if (dlgPerfTest->page()->chkIterators->isChecked()) {
202
kdDebug() << "Iterators test\n";
203
QString s = iteratorTest(testCount);
204
report = report.append(s);
205
kdDebug() << s << "\n";
207
if (dlgPerfTest->page()->chkPaintView->isChecked()) {
208
kdDebug() << "paintview test\n";
209
QString s = paintViewTest(testCount);
210
report = report.append(s);
211
kdDebug() << s << "\n";
213
if (dlgPerfTest->page()->chkPaintViewFPS->isChecked()) {
214
kdDebug() << "paint current view (fps) test\n";
215
QString s = paintViewFPSTest();
216
report = report.append(s);
217
kdDebug() << s << "\n";
219
KDialogBase * d = new KDialogBase(m_view, "", true, "", KDialogBase::Ok);
222
d->setCaption("Performance test results");
223
QTextEdit * e = new QTextEdit(d);
227
e->setMinimumWidth(600);
228
e->setMinimumHeight(600);
236
QString PerfTest::bltTest(Q_UINT32 testCount)
238
QString report = QString("* bitBlt test\n");
240
KisDoc * doc = m_view->canvasSubject()->document();
241
KisIDList l = KisMetaRegistry::instance()->csRegistry()->listKeys();
243
for (KisIDList::Iterator it = l.begin(); it != l.end(); ++it) {
245
kdDebug() << "Image->" << (*it).name() << "\n";
247
report = report.append( " Testing blitting on " + (*it).name() + "\n");
249
KisImageSP img = doc->newImage("blt-" + (*it).name(), 1000, 1000,
250
KisMetaRegistry::instance()->csRegistry()->getColorSpace(*it,""));
252
report = report.append(doBlit(COMPOSITE_OVER, *it, OPACITY_OPAQUE, testCount, img));
253
report = report.append( "\n");
254
report = report.append(doBlit(COMPOSITE_OVER, *it, OPACITY_OPAQUE / 2, testCount, img));
255
report = report.append( "\n");
256
report = report.append(doBlit(COMPOSITE_COPY, *it, OPACITY_OPAQUE, testCount, img));
257
report = report.append( "\n");
258
report = report.append(doBlit(COMPOSITE_COPY, *it, OPACITY_OPAQUE / 2, testCount, img));
259
report = report.append( "\n");
268
QString PerfTest::doBlit(const KisCompositeOp& op,
278
// ------------------------------------------------------------------------------
281
KisPaintDeviceSP small = new KisPaintDevice(KisMetaRegistry::instance()->csRegistry()->getColorSpace(cspace,""), "small blit");
284
KisFillPainter pf(small.data()) ;
285
pf.fillRect(0, 0, 32, 32, KisColor(Qt::black, KisMetaRegistry::instance()->csRegistry()->getRGB8()));
289
KisPainter p(img->activeDevice());
290
for (Q_UINT32 i = 0; i < testCount; ++i) {
291
p.bitBlt(0, 0, op, small.data(),0,0,32, 32);
295
report = report.append(QString(" %1 blits of rectangles < tilesize with opacity %2 and composite op %3: %4ms\n")
302
// ------------------------------------------------------------------------------
304
KisPaintDeviceSP medium = new KisPaintDevice(KisMetaRegistry::instance()->csRegistry()->getColorSpace(cspace,""), "medium blit");
307
pf.begin(medium.data()) ;
308
pf.fillRect(0, 0, 64 * 3, 64 * 3, KisColor(Qt::black, KisMetaRegistry::instance()->csRegistry()->getRGB8()));
312
p.begin(img->activeDevice().data());
313
for (Q_UINT32 i = 0; i < testCount; ++i) {
314
p.bitBlt(0, 0, op, medium.data(),0,0,96, 96);
318
report = report.append(QString(" %1 blits of rectangles 3 * tilesize with opacity %2 and composite op %3: %4ms\n")
325
// ------------------------------------------------------------------------------
327
KisPaintDeviceSP big = new KisPaintDevice(KisMetaRegistry::instance()->csRegistry()->getColorSpace(cspace,""), "big blit");
330
pf.begin(big.data()) ;
331
pf.fillRect(0, 0, 800, 800, KisColor(Qt::black, KisMetaRegistry::instance()->csRegistry()->getRGB8()));
335
p.begin(img->activeDevice().data());
336
for (Q_UINT32 i = 0; i < testCount; ++i) {
337
p.bitBlt(0, 0, op, big.data(),0,0,800,800);
341
report = report.append(QString(" %1 blits of rectangles 800 x 800 with opacity %2 and composite op %3: %4ms\n")
348
// ------------------------------------------------------------------------------
351
KisPaintDeviceSP outside = new KisPaintDevice(KisMetaRegistry::instance()->csRegistry()->getColorSpace(cspace,""), "outside blit");
352
Q_CHECK_PTR(outside);
353
pf.begin(outside.data()) ;
354
pf.fillRect(0, 0, 500, 500, KisColor(Qt::black, KisMetaRegistry::instance()->csRegistry()->getRGB8()));
358
p.begin(img->activeDevice().data());
359
for (Q_UINT32 i = 0; i < testCount; ++i) {
360
p.bitBlt(600, 600, op, outside.data(),0,0,500,500);
364
report = report.append(QString(" %1 blits of rectangles 500 x 500 at 600,600 with opacity %2 and composite op %3: %4ms\n")
370
// ------------------------------------------------------------------------------
371
// Small with varied source opacity
373
KisPaintDeviceSP small_with_alpha = new KisPaintDevice(KisMetaRegistry::instance()->csRegistry()->getColorSpace(cspace,""), "small blit with alpha");
374
Q_CHECK_PTR(small_with_alpha);
376
pf.begin(small_with_alpha.data()) ;
377
pf.fillRect(0, 0, 32, 32, KisColor(Qt::black, KisMetaRegistry::instance()->csRegistry()->getRGB8()), OPACITY_TRANSPARENT);
378
pf.fillRect(4, 4, 24, 24, KisColor(Qt::black, KisMetaRegistry::instance()->csRegistry()->getRGB8()), OPACITY_OPAQUE / 2);
379
pf.fillRect(8, 8, 16, 16, KisColor(Qt::black, KisMetaRegistry::instance()->csRegistry()->getRGB8()), OPACITY_OPAQUE);
383
p.begin(img->activeDevice().data());
384
for (Q_UINT32 i = 0; i < testCount; ++i) {
385
p.bitBlt(0, 0, op, small_with_alpha.data(), 0, 0, 32, 32);
389
report = report.append(QString(" %1 blits of rectangles < tilesize with source alpha, with opacity %2 and composite op %3: %4ms\n")
399
QString PerfTest::fillTest(Q_UINT32 testCount)
401
QString report = QString("* Fill test\n");
403
KisDoc * doc = m_view->canvasSubject()->document();
404
KisIDList l = KisMetaRegistry::instance()->csRegistry()->listKeys();
406
for (KisIDList::Iterator it = l.begin(); it != l.end(); ++it) {
407
kdDebug() << "Filltest on " << (*it).name() + "\n";
409
report = report.append( " Testing blitting on " + (*it).name() + "\n");
411
KisImageSP img = doc->newImage("fill-" + (*it).name(), 1000, 1000, KisMetaRegistry::instance()->csRegistry()->getColorSpace(*it,""));
412
KisPaintDeviceSP l = img->activeDevice();
415
KisFillPainter p(l.data());
418
for (Q_UINT32 i = 0; i < testCount; ++i) {
419
p.eraseRect(0, 0, 1000, 1000);
421
report = report.append(QString(" Erased 1000 x 1000 layer %1 times: %2\n").arg(testCount).arg(t.elapsed()));
425
for (Q_UINT32 i = 0; i < testCount; ++i) {
426
p.eraseRect(50, 50, 500, 500);
428
report = report.append(QString(" Erased 500 x 500 layer %1 times: %2\n").arg(testCount).arg(t.elapsed()));
432
for (Q_UINT32 i = 0; i < testCount; ++i) {
433
p.eraseRect(-50, -50, 1100, 1100);
435
report = report.append(QString(" Erased rect bigger than layer %1 times: %2\n").arg(testCount).arg(t.elapsed()));
440
for (Q_UINT32 i = 0; i < testCount; ++i) {
441
p.fillRect(0, 0, 1000, 1000, KisColor(Qt::black, KisMetaRegistry::instance()->csRegistry()->getRGB8()));
443
report = report.append(QString(" Opaque fill 1000 x 1000 layer %1 times: %2\n").arg(testCount).arg(t.elapsed()));
447
for (Q_UINT32 i = 0; i < testCount; ++i) {
448
p.fillRect(50, 50, 500, 500, KisColor(Qt::black, KisMetaRegistry::instance()->csRegistry()->getRGB8()));
450
report = report.append(QString(" Opaque fill 500 x 500 layer %1 times: %2\n").arg(testCount).arg(t.elapsed()));
454
for (Q_UINT32 i = 0; i < testCount; ++i) {
455
p.fillRect(-50, -50, 1100, 1100, KisColor(Qt::black, KisMetaRegistry::instance()->csRegistry()->getRGB8()));
457
report = report.append(QString(" Opaque fill rect bigger than layer %1 times: %2\n").arg(testCount).arg(t.elapsed()));
459
// Transparent rect fill
462
for (Q_UINT32 i = 0; i < testCount; ++i) {
463
p.fillRect(0, 0, 1000, 1000, KisColor(Qt::black, KisMetaRegistry::instance()->csRegistry()->getRGB8()), OPACITY_OPAQUE / 2);
465
report = report.append(QString(" Opaque fill 1000 x 1000 layer %1 times: %2\n").arg(testCount).arg(t.elapsed()));
469
for (Q_UINT32 i = 0; i < testCount; ++i) {
470
p.fillRect(50, 50, 500, 500, KisColor(Qt::black, KisMetaRegistry::instance()->csRegistry()->getRGB8()), OPACITY_OPAQUE / 2);
472
report = report.append(QString(" Opaque fill 500 x 500 layer %1 times: %2\n").arg(testCount).arg(t.elapsed()));
476
for (Q_UINT32 i = 0; i < testCount; ++i) {
477
p.fillRect(-50, -50, 1100, 1100, KisColor(Qt::black, KisMetaRegistry::instance()->csRegistry()->getRGB8()), OPACITY_OPAQUE / 2);
479
report = report.append(QString(" Opaque fill rect bigger than layer %1 times: %2\n").arg(testCount).arg(t.elapsed()));
484
for (Q_UINT32 i = 0; i < testCount; ++i) {
485
p.eraseRect(0, 0, 1000, 1000);
486
// p.paintEllipse(500, 1000, 100, 0, 0);
487
p.setPaintColor(KisColor(Qt::black, KisMetaRegistry::instance()->csRegistry()->getRGB8()));
488
p.setFillThreshold(15);
489
p.setCompositeOp(COMPOSITE_OVER);
492
report = report.append(QString(" Opaque floodfill of whole circle (incl. erase and painting of circle) %1 times: %2\n").arg(testCount).arg(t.elapsed()));
497
for (Q_UINT32 i = 0; i < testCount; ++i) {
498
p.eraseRect(0, 0, 1000, 1000);
499
// p.paintEllipse(500, 1000, 100, 0, 0);
500
p.setPaintColor(KisColor(Qt::black, KisMetaRegistry::instance()->csRegistry()->getRGB8()));
501
KisResourceServerBase* r = KisResourceServerRegistry::instance()->get("PatternServer");
503
p.setPattern((KisPattern*)r->resources().first());
504
p.setFillThreshold(15);
505
p.setCompositeOp(COMPOSITE_OVER);
508
report = report.append(QString(" Opaque patternfill of whole circle (incl. erase and painting of circle) %1 times: %2\n").arg(testCount).arg(t.elapsed()));
520
QString PerfTest::gradientTest(Q_UINT32 testCount)
522
return QString("Gradient test\n");
525
QString PerfTest::pixelTest(Q_UINT32 testCount)
527
QString report = QString("* pixel/setpixel test\n");
529
KisDoc * doc = m_view->canvasSubject()->document();
530
KisIDList l = KisMetaRegistry::instance()->csRegistry()->listKeys();
533
for (KisIDList::Iterator it = l.begin(); it != l.end(); ++it) {
534
report = report.append( " Testing pixel/setpixel on " + (*it).name() + "\n");
536
KisImageSP img = doc->newImage("fill-" + (*it).name(), 1000, 1000, KisMetaRegistry::instance()->csRegistry()->getColorSpace(*it,""));
538
KisPaintDeviceSP l = img->activeDevice();
543
QColor c = Qt::black;
544
Q_UINT8 opacity = OPACITY_OPAQUE;
545
for (Q_UINT32 i = 0; i < testCount; ++i) {
546
for (Q_UINT32 x = 0; x < 1000; ++x) {
547
for (Q_UINT32 y = 0; y < 1000; ++y) {
548
l->pixel(x, y, &c, &opacity);
552
report = report.append(QString(" read 1000 x 1000 pixels %1 times: %2\n").arg(testCount).arg(t.elapsed()));
556
for (Q_UINT32 i = 0; i < testCount; ++i) {
557
for (Q_UINT32 x = 0; x < 1000; ++x) {
558
for (Q_UINT32 y = 0; y < 1000; ++y) {
559
l->setPixel(x, y, c, 128);
563
report = report.append(QString(" written 1000 x 1000 pixels %1 times: %2\n").arg(testCount).arg(t.elapsed()));
574
QString PerfTest::shapeTest(Q_UINT32 testCount)
576
return QString("Shape test\n");
579
QString PerfTest::layerTest(Q_UINT32 testCount)
581
return QString("Layer test\n");
584
QString PerfTest::scaleTest(Q_UINT32 testCount)
586
return QString("Scale test\n");
589
QString PerfTest::rotateTest(Q_UINT32 testCount)
591
QString report = QString("* Rotate test\n");
593
KisDoc * doc = m_view->canvasSubject()->document();
594
KisIDList l = KisMetaRegistry::instance()->csRegistry()->listKeys();
595
for (KisIDList::Iterator it = l.begin(); it != l.end(); ++it) {
597
doc->undoAdapter()->setUndo( false );
600
for (uint i = 0; i < testCount; ++i) {
601
for (double angle = 0; angle < 360; ++angle) {
602
kdDebug() << "Rotating " << (*it).name() << " at " << angle << " degrees\n";
603
KisImage * img = doc->newImage("cs-" + (*it).name(), 1000, 1000, KisMetaRegistry::instance()->csRegistry()->getColorSpace(*it,""));
604
img->rotate(angle, m_view->canvasSubject()->progressDisplay());
605
kdDebug() << "Size: " << img->projection()->extent() << endl;
609
report = report.append(QString(" rotated 1000 x 1000 pixels over 360 degrees, degree by degree, %1 times: %2\n").arg(testCount).arg(t.elapsed()));
614
QString PerfTest::renderTest(Q_UINT32 restCount)
616
return QString("Render test\n");
619
QString PerfTest::selectionTest(Q_UINT32 testCount)
621
return QString("Selection test\n");
624
QString PerfTest::colorConversionTest(Q_UINT32 testCount)
626
QString report = QString("* Colorspace conversion test\n");
628
KisDoc * doc = m_view->canvasSubject()->document();
629
KisIDList l = KisMetaRegistry::instance()->csRegistry()->listKeys();
630
for (KisIDList::Iterator it = l.begin(); it != l.end(); ++it) {
632
KisImage * img = doc->newImage("cs-" + (*it).name(), 1000, 1000, KisMetaRegistry::instance()->csRegistry()->getColorSpace(*it,""));
636
KisIDList l2 = KisMetaRegistry::instance()->csRegistry()->listKeys();
637
for (KisIDList::Iterator it2 = l2.begin(); it2 != l2.end(); ++it2) {
638
kdDebug() << "test conversion from " << (*it).name() << " to " << (*it2).name() << endl;
641
for (uint i = 0; i < testCount; ++i) {
642
KisImage * img2 = new KisImage(*img);
643
img2->convertTo(KisMetaRegistry::instance()->csRegistry()->getColorSpace(*it2,""));
646
report = report.append(QString(" converted from " + (*it).name() + " to " + (*it2).name() + " 1000 x 1000 pixels %1 times: %2\n").arg(testCount).arg(t.elapsed()));
657
QString PerfTest::filterTest(Q_UINT32 testCount)
660
QString report = QString("* Filter test\n");
662
KisIDList filters = KisFilterRegistry::instance()->listKeys();
663
KisDoc * doc = m_view->canvasSubject()->document();
664
KisIDList l = KisMetaRegistry::instance()->csRegistry()->listKeys();
666
for (KisIDList::Iterator it = l.begin(); it != l.end(); ++it) {
667
report = report.append( " Testing filtering on " + (*it).name() + "\n");
669
KisImageSP img = doc->newImage("filter-" + (*it).name(), 1000, 1000, KisMetaRegistry::instance()->csRegistry()->getColorSpace(*it,""));
670
KisPaintDeviceSP l = img->activeDevice();
674
for (KisIDList::Iterator it = filters.begin(); it != filters.end(); ++it) {
676
KisFilterSP f = KisFilterRegistry::instance()->get(*it);
678
kdDebug() << "test filter " << f->id().name() << " on " << img->colorSpace()->id().name() << endl;
679
for (Q_UINT32 i = 0; i < testCount; ++i) {
681
f->process(l.data(), l.data(), f->configuration(f->createConfigurationWidget(m_view, l.data())), QRect(0, 0, 1000, 1000));
682
f->disableProgress();
684
report = report.append(QString(" filtered " + (*it).name() + "1000 x 1000 pixels %1 times: %2\n").arg(testCount).arg(t.elapsed()));
693
QString PerfTest::readBytesTest(Q_UINT32 testCount)
695
QString report = QString("* Read bytes test\n\n");
698
KisDoc * doc = m_view->canvasSubject()->document();
699
KisImageSP img = doc->newImage("Readbytes ", 1000, 1000, KisMetaRegistry::instance()->csRegistry()->getColorSpace(KisID("RGBA",""),""));
700
KisPaintDeviceSP l = img->activeDevice();
705
for (Q_UINT32 i = 0; i < testCount; ++i) {
706
Q_UINT8 * newData = new Q_UINT8[1000 * 1000 * l->pixelSize()];
707
Q_CHECK_PTR(newData);
708
l->readBytes(newData, 0, 0, 1000, 1000);
712
report = report.append(QString(" read 1000 x 1000 pixels %1 times from empty image: %2\n").arg(testCount).arg(t.elapsed()));
714
// On tiles with data
716
KisFillPainter p(l.data());
717
p.fillRect(0, 0, 1000, 1000, KisColor(Qt::black, KisMetaRegistry::instance()->csRegistry()->getRGB8()));
722
for (Q_UINT32 i = 0; i < testCount; ++i) {
723
Q_UINT8 * newData = new Q_UINT8[1000 * 1000 * l->pixelSize()];
724
Q_CHECK_PTR(newData);
725
l->readBytes(newData, 0, 0, 1000, 1000);
729
report = report.append(QString(" read 1000 x 1000 pixels %1 times from filled image: %2\n").arg(testCount).arg(t.elapsed()));
735
QString PerfTest::writeBytesTest(Q_UINT32 testCount)
737
QString report = QString("* Write bytes test");
740
KisDoc * doc = m_view->canvasSubject()->document();
741
KisImageSP img = doc->newImage("Writebytes ", 1000, 1000, KisMetaRegistry::instance()->csRegistry()->getColorSpace(KisID("RGBA", ""),""));
742
KisPaintDeviceSP l = img->activeDevice();
743
KisFillPainter p(l.data());
744
p.fillRect(0, 0, 1000, 1000, KisColor(Qt::black, KisMetaRegistry::instance()->csRegistry()->getRGB8()));
748
Q_UINT8 * data = new Q_UINT8[1000 * 1000 * l->pixelSize()];
750
l->readBytes(data, 0, 0, 1000, 1000);
754
for (Q_UINT32 i = 0; i < testCount; ++i) {
755
l->writeBytes(data, 0, 0, 1000, 1000);
758
report = report.append(QString(" written 1000 x 1000 pixels %1 times: %2\n").arg(testCount).arg(t.elapsed()));
764
/////// Iterator tests
767
QString hlineRODefault(KisDoc * doc, Q_UINT32 testCount)
769
KisImageSP img = doc->newImage("", 1000, 1000, KisMetaRegistry::instance()->csRegistry()->getColorSpace(KisID("RGBA", ""),""));
770
KisPaintDeviceSP l = img->activeDevice();
776
for (Q_UINT32 i = 0; i < testCount; ++i) {
779
for(Q_INT32 y2 = 0; y2 < 0 + 1000; y2++)
781
KisHLineIterator hiter = l->createHLineIterator(0, y2, 1000, false);
782
while(! hiter.isDone())
784
adv = hiter.nConseqHPixels();
791
return QString(" hline iterated read-only 1000 x 1000 pixels %1 times over default tile: %2\n").arg(testCount).arg(t.elapsed());
796
QString hlineRO(KisDoc * doc, Q_UINT32 testCount)
798
KisImageSP img = doc->newImage("", 1000, 1000, KisMetaRegistry::instance()->csRegistry()->getColorSpace(KisID("RGBA", ""),""));
799
KisPaintDeviceSP l = img->activeDevice();
801
KisFillPainter p(l.data());
802
p.fillRect(0, 0, 1000, 1000, KisColor(Qt::black, KisMetaRegistry::instance()->csRegistry()->getRGB8()));
808
for (Q_UINT32 i = 0; i < testCount; ++i) {
811
for(Q_INT32 y2 = 0; y2 < 0 + 1000; y2++)
813
KisHLineIterator hiter = l->createHLineIterator(0, y2, 1000, false);
814
while(! hiter.isDone())
816
adv = hiter.nConseqHPixels();
823
return QString(" hline iterated read-only 1000 x 1000 pixels %1 times over existing tile: %2\n").arg(testCount).arg(t.elapsed());
827
QString hlineWRDefault(KisDoc * doc, Q_UINT32 testCount)
829
KisImageSP img = doc->newImage("", 1000, 1000, KisMetaRegistry::instance()->csRegistry()->getColorSpace(KisID("RGBA", ""),""));
830
KisPaintDeviceSP l = img->activeDevice();
835
for (Q_UINT32 i = 0; i < testCount; ++i) {
838
for(Q_INT32 y2 = 0; y2 < 0 + 1000; y2++)
840
KisHLineIterator hiter = l->createHLineIterator(0, y2, 1000, true);
841
while(! hiter.isDone())
843
adv = hiter.nConseqHPixels();
850
return QString(" hline iterated writable 1000 x 1000 pixels %1 times over default tile: %2\n").arg(testCount).arg(t.elapsed());
854
QString hlineWR(KisDoc * doc, Q_UINT32 testCount)
856
KisImageSP img = doc->newImage("", 1000, 1000, KisMetaRegistry::instance()->csRegistry()->getColorSpace(KisID("RGBA", ""),""));
857
KisPaintDeviceSP l = img->activeDevice();
859
KisFillPainter p(l.data());
860
p.fillRect(0, 0, 1000, 1000, KisColor(Qt::black, KisMetaRegistry::instance()->csRegistry()->getRGB8()));
867
for (Q_UINT32 i = 0; i < testCount; ++i) {
869
for(Q_INT32 y2 = 0; y2 < 0 + 1000; y2++)
871
KisHLineIterator hiter = l->createHLineIterator(0, y2, 1000, true);
872
while(! hiter.isDone())
874
adv = hiter.nConseqHPixels();
881
return QString(" hline iterated writable 1000 x 1000 pixels %1 times over existing tile: %2\n").arg(testCount).arg(t.elapsed());
886
QString vlineRODefault(KisDoc * doc, Q_UINT32 testCount)
888
KisImageSP img = doc->newImage("", 1000, 1000, KisMetaRegistry::instance()->csRegistry()->getColorSpace(KisID("RGBA", ""),""));
889
KisPaintDeviceSP l = img->activeDevice();
894
for (Q_UINT32 i = 0; i < testCount; ++i) {
895
for(Q_INT32 y2 = 0; y2 < 0 + 1000; y2++)
897
KisVLineIterator hiter = l->createVLineIterator(y2, 0, 1000, true);
898
while(! hiter.isDone())
906
return QString(" vline iterated read-only 1000 x 1000 pixels %1 times over default tile: %2\n").arg(testCount).arg(t.elapsed());
910
QString vlineRO(KisDoc * doc, Q_UINT32 testCount)
912
KisImageSP img = doc->newImage("", 1000, 1000, KisMetaRegistry::instance()->csRegistry()->getColorSpace(KisID("RGBA", ""),""));
913
KisPaintDeviceSP l = img->activeDevice();
915
KisFillPainter p(l.data());
916
p.fillRect(0, 0, 1000, 1000, KisColor(Qt::black, KisMetaRegistry::instance()->csRegistry()->getRGB8()));
923
for (Q_UINT32 i = 0; i < testCount; ++i) {
924
for(Q_INT32 y2 = 0; y2 < 0 + 1000; y2++)
926
KisVLineIterator hiter = l->createVLineIterator(y2, 0, 1000, true);
927
while(! hiter.isDone())
935
return QString(" vline iterated read-only 1000 x 1000 pixels %1 times over existing tile: %2\n").arg(testCount).arg(t.elapsed());
939
QString vlineWRDefault(KisDoc * doc, Q_UINT32 testCount)
941
KisImageSP img = doc->newImage("", 1000, 1000, KisMetaRegistry::instance()->csRegistry()->getColorSpace(KisID("RGBA", ""),""));
942
KisPaintDeviceSP l = img->activeDevice();
947
for (Q_UINT32 i = 0; i < testCount; ++i) {
949
for(Q_INT32 y2 = 0; y2 < 0 + 1000; y2++)
951
KisVLineIterator hiter = l->createVLineIterator(y2, 0, 1000, true);
952
while(! hiter.isDone())
960
return QString(" vline iterated writable 1000 x 1000 pixels %1 times over default tile: %2\n").arg(testCount).arg(t.elapsed());
963
QString vlineWR(KisDoc * doc, Q_UINT32 testCount)
966
KisImageSP img = doc->newImage("", 1000, 1000, KisMetaRegistry::instance()->csRegistry()->getColorSpace(KisID("RGBA", ""),""));
967
KisPaintDeviceSP l = img->activeDevice();
969
KisFillPainter p(l.data());
970
p.fillRect(0, 0, 1000, 1000, KisColor(Qt::black, KisMetaRegistry::instance()->csRegistry()->getRGB8()));
976
for (Q_UINT32 i = 0; i < testCount; ++i) {
977
for(Q_INT32 y2 = 0; y2 < 0 + 1000; y2++)
979
KisHLineIterator hiter = l->createHLineIterator(y2, 0, 1000, true);
980
while(! hiter.isDone())
988
return QString(" vline iterated writable 1000 x 1000 pixels %1 times over existing tile: %2\n").arg(testCount).arg(t.elapsed());
992
QString rectRODefault(KisDoc * doc, Q_UINT32 testCount)
994
KisImageSP img = doc->newImage("", 1000, 1000, KisMetaRegistry::instance()->csRegistry()->getColorSpace(KisID("RGBA", ""),""));
995
KisPaintDeviceSP l = img->activeDevice();
1000
for (Q_UINT32 i = 0; i < testCount; ++i) {
1001
KisRectIterator r = l->createRectIterator(0, 0, 1000, 1000, false);
1008
return QString(" rect iterated read-only 1000 x 1000 pixels %1 times over default tile: %2\n").arg(testCount).arg(t.elapsed());
1013
QString rectRO(KisDoc * doc, Q_UINT32 testCount)
1015
KisImageSP img = doc->newImage("", 1000, 1000, KisMetaRegistry::instance()->csRegistry()->getColorSpace(KisID("RGBA", ""),""));
1016
KisPaintDeviceSP l = img->activeDevice();
1018
KisFillPainter p(l.data());
1019
p.fillRect(0, 0, 1000, 1000, KisColor(Qt::black, KisMetaRegistry::instance()->csRegistry()->getRGB8()));
1025
for (Q_UINT32 i = 0; i < testCount; ++i) {
1026
KisRectIterator r = l->createRectIterator(0, 0, 1000, 1000, false);
1033
return QString(" rect iterated read-only 1000 x 1000 pixels %1 times over existing tile: %2\n").arg(testCount).arg(t.elapsed());
1037
QString rectWRDefault(KisDoc * doc, Q_UINT32 testCount)
1041
KisImageSP img = doc->newImage("", 1000, 1000, KisMetaRegistry::instance()->csRegistry()->getColorSpace(KisID("RGBA", ""),""));
1042
KisPaintDeviceSP l = img->activeDevice();
1047
for (Q_UINT32 i = 0; i < testCount; ++i) {
1048
KisRectIterator r = l->createRectIterator(0, 0, 1000, 1000, true);
1055
return QString(" rect iterated writable 1000 x 1000 pixels %1 times over default tile: %2\n").arg(testCount).arg(t.elapsed());
1059
QString rectWR(KisDoc * doc, Q_UINT32 testCount)
1061
KisImageSP img = doc->newImage("", 1000, 1000, KisMetaRegistry::instance()->csRegistry()->getColorSpace(KisID("RGBA", ""),""));
1062
KisPaintDeviceSP l = img->activeDevice();
1064
KisFillPainter p(l.data());
1065
p.fillRect(0, 0, 1000, 1000, KisColor(Qt::black, KisMetaRegistry::instance()->csRegistry()->getRGB8()));
1073
for (Q_UINT32 i = 0; i < testCount; ++i) {
1074
KisRectIterator r = l->createRectIterator(0, 0, 1000, 1000, true);
1082
return QString(" rect iterated writable 1000 x 1000 pixels %1 times over existing tile: %2\n").arg(testCount).arg(t.elapsed());
1086
QString PerfTest::iteratorTest(Q_UINT32 testCount)
1088
QString report = "Iterator test";
1090
KisDoc * doc = m_view->canvasSubject()->document();
1092
report = report.append(hlineRODefault(doc, testCount));
1093
report = report.append(hlineRO(doc, testCount));
1094
report = report.append(hlineWRDefault(doc, testCount));
1095
report = report.append(hlineWR(doc, testCount));
1097
report = report.append(vlineRODefault(doc, testCount));
1098
report = report.append(vlineRO(doc, testCount));
1099
report = report.append(vlineWRDefault(doc, testCount));
1100
report = report.append(vlineWR(doc, testCount));
1102
report = report.append(rectRODefault(doc, testCount));
1103
report = report.append(rectRO(doc, testCount));
1104
report = report.append(rectWRDefault(doc, testCount));
1105
report = report.append(rectWR(doc, testCount));
1112
QString PerfTest::paintViewTest(Q_UINT32 testCount)
1114
QString report = QString("* paintView test\n\n");
1116
KisDoc * doc = m_view->canvasSubject()->document();
1118
KisImageSP img = doc->currentImage();
1119
img->resize(512,512);
1122
KisPaintDeviceSP l = img->activeDevice();
1124
KisFillPainter p(l.data());
1125
p.fillRect(0, 0, 512, 512, KisColor(Qt::black, KisMetaRegistry::instance()->csRegistry()->getRGB8()));
1132
CALLGRIND_ZERO_STATS();
1135
for (Q_UINT32 i = 0; i < testCount; ++i) {
1136
m_view->getCanvasController()->updateCanvas(QRect(0, 0, 512, 512));
1140
CALLGRIND_DUMP_STATS();
1143
report = report.append(QString(" painted a 512 x 512 image %1 times: %2 ms\n").arg(testCount).arg(t.elapsed()));
1145
img->newLayer("layer 2", OPACITY_OPAQUE);
1146
l = img->activeDevice();
1149
p.fillRect(0, 0, 512, 512, KisColor(Qt::black, KisMetaRegistry::instance()->csRegistry()->getRGB8()));
1152
img->newLayer("layer 3", OPACITY_OPAQUE);
1153
l = img->activeDevice();
1156
p.fillRect(0, 0, 512, 512, KisColor(Qt::black, KisMetaRegistry::instance()->csRegistry()->getRGB8()));
1161
for (Q_UINT32 i = 0; i < testCount; ++i) {
1162
m_view->getCanvasController()->updateCanvas(QRect(0, 0, 512, 512));
1165
report = report.append(QString(" painted a 512 x 512 image with 3 layers %1 times: %2 ms\n").arg(testCount).arg(t.elapsed()));
1170
QString PerfTest::paintViewFPSTest()
1172
QString report = QString("* paintView (fps) test\n\n");
1178
CALLGRIND_ZERO_STATS();
1181
int numViewsPainted = 0;
1182
const int millisecondsPerSecond = 1000;
1184
while (t.elapsed() < millisecondsPerSecond) {
1185
m_view->getCanvasController()->updateCanvas();
1190
CALLGRIND_DUMP_STATS();
1193
report = report.append(QString(" painted current view at %1 frames per second\n").arg(numViewsPainted));
1198
#include "perftest.moc"