~ubuntu-branches/ubuntu/precise/koffice/precise

« back to all changes in this revision

Viewing changes to krita/plugins/viewplugins/performancetest/perftest.cc

  • Committer: Bazaar Package Importer
  • Author(s): Jonathan Riddell
  • Date: 2006-04-20 21:38:53 UTC
  • mfrom: (1.1.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20060420213853-j5lxluqvymxt2zny
Tags: 1:1.5.0-0ubuntu2
UbuntuĀ uploadĀ 

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * perftest.cc -- Part of Krita
 
3
 *
 
4
 * Copyright (c) 2004 Boudewijn Rempt <boud@valdyas.org>
 
5
 *
 
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.
 
10
 *
 
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.
 
15
 *
 
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.
 
19
 */
 
20
 
 
21
#include <math.h>
 
22
 
 
23
#include <stdlib.h>
 
24
 
 
25
#include <qslider.h>
 
26
#include <qpoint.h>
 
27
#include <qradiobutton.h>
 
28
#include <qcheckbox.h>
 
29
#include <qlabel.h>
 
30
#include <qtextedit.h>
 
31
#include <qdatetime.h>
 
32
 
 
33
#include <klocale.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>
 
40
#include <kdebug.h>
 
41
#include <kgenericfactory.h>
 
42
#include <knuminput.h>
 
43
 
 
44
#include <qcolor.h>
 
45
 
 
46
#include "kis_meta_registry.h"
 
47
#include <kis_resourceserver.h>
 
48
#include "kis_cursor.h"
 
49
#include <kis_doc.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>
 
55
#include <kis_view.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>
 
61
#include <kis_id.h>
 
62
#include <kis_paint_device.h>
 
63
#include <kis_iterators_pixel.h>
 
64
#include "perftest.h"
 
65
#include "kis_filter_config_widget.h"
 
66
#include "kis_factory.h"
 
67
 
 
68
#include "dlg_perftest.h"
 
69
#include "wdg_perftest.h"
 
70
 
 
71
#define USE_CALLGRIND 0
 
72
 
 
73
#if USE_CALLGRIND
 
74
#include <valgrind/callgrind.h>
 
75
#endif
 
76
 
 
77
 
 
78
typedef KGenericFactory<PerfTest> PerfTestFactory;
 
79
K_EXPORT_COMPONENT_FACTORY( kritaperftest, PerfTestFactory( "krita" ) )
 
80
 
 
81
PerfTest::PerfTest(QObject *parent, const char *name, const QStringList &)
 
82
    : KParts::Plugin(parent, name)
 
83
{
 
84
    if ( parent->inherits("KisView") )
 
85
    {
 
86
        setInstance(PerfTestFactory::instance());
 
87
        setXMLFile(locate("data","kritaplugins/perftest.rc"), true);
 
88
 
 
89
        (void) new KAction(i18n("&Performance Test..."), 0, 0, this, SLOT(slotPerfTest()), actionCollection(), "perf_test");
 
90
 
 
91
        m_view = (KisView*) parent;
 
92
    }
 
93
}
 
94
 
 
95
PerfTest::~PerfTest()
 
96
{
 
97
    m_view = 0;
 
98
}
 
99
 
 
100
void PerfTest::slotPerfTest()
 
101
{
 
102
    KisImageSP image = m_view->canvasSubject()->currentImg();
 
103
 
 
104
    if (!image) return;
 
105
 
 
106
    DlgPerfTest * dlgPerfTest = new DlgPerfTest(m_view, "PerfTest");
 
107
    Q_CHECK_PTR(dlgPerfTest);
 
108
 
 
109
    dlgPerfTest->setCaption(i18n("Performance Test"));
 
110
 
 
111
    QString report = QString("");
 
112
 
 
113
        if (dlgPerfTest->exec() == QDialog::Accepted) {
 
114
 
 
115
        Q_INT32 testCount = (Q_INT32)qRound(dlgPerfTest->page()->intTestCount->value());
 
116
 
 
117
        if (dlgPerfTest->page()->chkBitBlt->isChecked()) {
 
118
            kdDebug() << "bltTest:\n";
 
119
            QString s = bltTest(testCount);
 
120
            report = report.append(s);
 
121
            kdDebug() << s << "\n";
 
122
        }
 
123
        if (dlgPerfTest->page()->chkFill->isChecked()) {
 
124
            kdDebug() << "Filltest\n";
 
125
            QString s= fillTest(testCount);
 
126
            report = report.append(s);
 
127
            kdDebug() << s << "\n";
 
128
        }
 
129
        if (dlgPerfTest->page()->chkGradient->isChecked()) {
 
130
            kdDebug() << "Gradienttest\n";
 
131
            QString s = gradientTest(testCount);
 
132
            report = report.append(s);
 
133
            kdDebug() << s << "\n";
 
134
        }
 
135
        if (dlgPerfTest->page()->chkPixel->isChecked()) {
 
136
            kdDebug() << "Pixeltest\n";
 
137
            QString s = pixelTest(testCount);
 
138
            report = report.append(s);
 
139
            kdDebug() << s << "\n";
 
140
        }
 
141
        if (dlgPerfTest->page()->chkShape->isChecked()) {
 
142
            kdDebug() << "Shapetest\n";
 
143
            QString s = shapeTest(testCount);
 
144
            report = report.append(s);
 
145
            kdDebug() << s << "\n";
 
146
        }
 
147
        if (dlgPerfTest->page()->chkLayer->isChecked()) {
 
148
            kdDebug() << "LayerTest\n";
 
149
            QString s = layerTest(testCount);
 
150
            report = report.append(s);
 
151
            kdDebug() << s << "\n";
 
152
        }
 
153
        if (dlgPerfTest->page()->chkScale->isChecked()) {
 
154
            kdDebug() << "Scaletest\n";
 
155
            QString s = scaleTest(testCount);
 
156
            report = report.append(s);
 
157
            kdDebug() << s << "\n";
 
158
        }
 
159
        if (dlgPerfTest->page()->chkRotate->isChecked()) {
 
160
            kdDebug() << "Rotatetest\n";
 
161
            QString s = rotateTest(testCount);
 
162
            report = report.append(s);
 
163
            kdDebug() << s << "\n";
 
164
        }
 
165
        if (dlgPerfTest->page()->chkRender->isChecked()) {
 
166
            kdDebug() << "Rendertest\n";
 
167
            QString s = renderTest(testCount);
 
168
            report = report.append(s);
 
169
            kdDebug() << s << "\n";
 
170
        }
 
171
        if (dlgPerfTest->page()->chkSelection->isChecked()) {
 
172
            kdDebug() << "Selectiontest\n";
 
173
            QString s = selectionTest(testCount);
 
174
            report = report.append(s);
 
175
            kdDebug() << s << "\n";
 
176
        }
 
177
        if (dlgPerfTest->page()->chkColorConversion->isChecked()) {
 
178
            kdDebug() << "Colorconversiontest\n";
 
179
            QString s = colorConversionTest(testCount);
 
180
            report = report.append(s);
 
181
            kdDebug() << s << "\n";
 
182
        }
 
183
        if (dlgPerfTest->page()->chkFilter-> isChecked()) {
 
184
            kdDebug() << "filtertest\n";
 
185
            QString s = filterTest(testCount);
 
186
            report = report.append(s);
 
187
            kdDebug() << s << "\n";
 
188
        }
 
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";
 
194
        }
 
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";
 
200
        }
 
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";
 
206
        }
 
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";
 
212
        }
 
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";
 
218
        }
 
219
        KDialogBase * d = new KDialogBase(m_view, "", true, "", KDialogBase::Ok);
 
220
        Q_CHECK_PTR(d);
 
221
 
 
222
        d->setCaption("Performance test results");
 
223
        QTextEdit * e = new QTextEdit(d);
 
224
        Q_CHECK_PTR(e);
 
225
        d->setMainWidget(e);
 
226
        e->setText(report);
 
227
        e->setMinimumWidth(600);
 
228
        e->setMinimumHeight(600);
 
229
        d->exec();
 
230
        delete d;
 
231
 
 
232
    }
 
233
        delete dlgPerfTest;
 
234
}
 
235
 
 
236
QString PerfTest::bltTest(Q_UINT32 testCount)
 
237
{
 
238
    QString report = QString("* bitBlt test\n");
 
239
 
 
240
    KisDoc * doc = m_view->canvasSubject()->document();
 
241
    KisIDList l = KisMetaRegistry::instance()->csRegistry()->listKeys();
 
242
 
 
243
    for (KisIDList::Iterator it = l.begin(); it != l.end(); ++it) {
 
244
 
 
245
        kdDebug() << "Image->" << (*it).name() << "\n";
 
246
 
 
247
        report = report.append( "  Testing blitting on " + (*it).name() + "\n");
 
248
 
 
249
         KisImageSP img = doc->newImage("blt-" + (*it).name(), 1000, 1000,
 
250
                KisMetaRegistry::instance()->csRegistry()->getColorSpace(*it,""));
 
251
 
 
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");
 
260
    }
 
261
 
 
262
    return report;
 
263
 
 
264
 
 
265
}
 
266
 
 
267
 
 
268
QString PerfTest::doBlit(const KisCompositeOp& op,
 
269
                         KisID cspace,
 
270
                         Q_UINT8 opacity,
 
271
                         Q_UINT32 testCount,
 
272
                         KisImageSP img)
 
273
{
 
274
 
 
275
    QTime t;
 
276
    QString report;
 
277
 
 
278
    // ------------------------------------------------------------------------------
 
279
    // Small
 
280
 
 
281
    KisPaintDeviceSP small = new KisPaintDevice(KisMetaRegistry::instance()->csRegistry()->getColorSpace(cspace,""), "small blit");
 
282
    Q_CHECK_PTR(small);
 
283
 
 
284
    KisFillPainter pf(small.data()) ;
 
285
    pf.fillRect(0, 0, 32, 32, KisColor(Qt::black, KisMetaRegistry::instance()->csRegistry()->getRGB8()));
 
286
    pf.end();
 
287
 
 
288
    t.restart();
 
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);
 
292
    }
 
293
    p.end();
 
294
 
 
295
    report = report.append(QString("   %1 blits of rectangles < tilesize with opacity %2 and composite op %3: %4ms\n")
 
296
                   .arg(testCount)
 
297
                   .arg(opacity)
 
298
                   .arg(op.id().name())
 
299
                   .arg(t.elapsed()));
 
300
 
 
301
 
 
302
    // ------------------------------------------------------------------------------
 
303
    // Medium
 
304
    KisPaintDeviceSP medium = new KisPaintDevice(KisMetaRegistry::instance()->csRegistry()->getColorSpace(cspace,""), "medium blit");
 
305
    Q_CHECK_PTR(medium);
 
306
 
 
307
    pf.begin(medium.data()) ;
 
308
    pf.fillRect(0, 0, 64 * 3, 64 * 3, KisColor(Qt::black, KisMetaRegistry::instance()->csRegistry()->getRGB8()));
 
309
    pf.end();
 
310
 
 
311
    t.restart();
 
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);
 
315
    }
 
316
    p.end();
 
317
 
 
318
    report = report.append(QString("   %1 blits of rectangles 3 * tilesize with opacity %2 and composite op %3: %4ms\n")
 
319
                   .arg(testCount)
 
320
                   .arg(opacity)
 
321
                   .arg(op.id().name())
 
322
                   .arg(t.elapsed()));
 
323
 
 
324
 
 
325
    // ------------------------------------------------------------------------------
 
326
    // Big
 
327
    KisPaintDeviceSP big = new KisPaintDevice(KisMetaRegistry::instance()->csRegistry()->getColorSpace(cspace,""), "big blit");
 
328
    Q_CHECK_PTR(big);
 
329
 
 
330
    pf.begin(big.data()) ;
 
331
    pf.fillRect(0, 0, 800, 800, KisColor(Qt::black, KisMetaRegistry::instance()->csRegistry()->getRGB8()));
 
332
    pf.end();
 
333
 
 
334
    t.restart();
 
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);
 
338
 
 
339
    }
 
340
    p.end();
 
341
    report = report.append(QString("   %1 blits of rectangles 800 x 800 with opacity %2 and composite op %3: %4ms\n")
 
342
                   .arg(testCount)
 
343
                   .arg(opacity)
 
344
                   .arg(op.id().name())
 
345
                   .arg(t.elapsed()));
 
346
 
 
347
 
 
348
    // ------------------------------------------------------------------------------
 
349
    // Outside
 
350
 
 
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()));
 
355
    pf.end();
 
356
 
 
357
    t.restart();
 
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);
 
361
 
 
362
    }
 
363
    p.end();
 
364
    report = report.append(QString("   %1 blits of rectangles 500 x 500 at 600,600 with opacity %2 and composite op %3: %4ms\n")
 
365
                   .arg(testCount)
 
366
                   .arg(opacity)
 
367
                   .arg(op.id().name())
 
368
                   .arg(t.elapsed()));
 
369
 
 
370
    // ------------------------------------------------------------------------------
 
371
    // Small with varied source opacity
 
372
 
 
373
    KisPaintDeviceSP small_with_alpha = new KisPaintDevice(KisMetaRegistry::instance()->csRegistry()->getColorSpace(cspace,""), "small blit with alpha");
 
374
    Q_CHECK_PTR(small_with_alpha);
 
375
 
 
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);
 
380
    pf.end();
 
381
 
 
382
    t.restart();
 
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);
 
386
    }
 
387
    p.end();
 
388
 
 
389
    report = report.append(QString("   %1 blits of rectangles < tilesize with source alpha, with opacity %2 and composite op %3: %4ms\n")
 
390
                   .arg(testCount)
 
391
                   .arg(opacity)
 
392
                   .arg(op.id().name())
 
393
                   .arg(t.elapsed()));
 
394
 
 
395
    return report;
 
396
 
 
397
}
 
398
 
 
399
QString PerfTest::fillTest(Q_UINT32 testCount)
 
400
{
 
401
    QString report = QString("* Fill test\n");
 
402
 
 
403
    KisDoc * doc = m_view->canvasSubject()->document();
 
404
    KisIDList l = KisMetaRegistry::instance()->csRegistry()->listKeys();
 
405
 
 
406
    for (KisIDList::Iterator it = l.begin(); it != l.end(); ++it) {
 
407
        kdDebug() << "Filltest on " << (*it).name() + "\n";
 
408
 
 
409
        report = report.append( "  Testing blitting on " + (*it).name() + "\n");
 
410
 
 
411
        KisImageSP img = doc->newImage("fill-" + (*it).name(), 1000, 1000, KisMetaRegistry::instance()->csRegistry()->getColorSpace(*it,""));
 
412
        KisPaintDeviceSP l = img->activeDevice();
 
413
 
 
414
        // Rect fill
 
415
        KisFillPainter p(l.data());
 
416
        QTime t;
 
417
        t.restart();
 
418
        for (Q_UINT32 i = 0; i < testCount; ++i) {
 
419
            p.eraseRect(0, 0, 1000, 1000);
 
420
        }
 
421
        report = report.append(QString("    Erased 1000 x 1000 layer %1 times: %2\n").arg(testCount).arg(t.elapsed()));
 
422
 
 
423
 
 
424
        t.restart();
 
425
        for (Q_UINT32 i = 0; i < testCount; ++i) {
 
426
            p.eraseRect(50, 50, 500, 500);
 
427
        }
 
428
        report = report.append(QString("    Erased 500 x 500 layer %1 times: %2\n").arg(testCount).arg(t.elapsed()));
 
429
 
 
430
 
 
431
        t.restart();
 
432
        for (Q_UINT32 i = 0; i < testCount; ++i) {
 
433
            p.eraseRect(-50, -50, 1100, 1100);
 
434
        }
 
435
        report = report.append(QString("    Erased rect bigger than layer %1 times: %2\n").arg(testCount).arg(t.elapsed()));
 
436
 
 
437
 
 
438
        // Opaque Rect fill
 
439
        t.restart();
 
440
        for (Q_UINT32 i = 0; i < testCount; ++i) {
 
441
            p.fillRect(0, 0, 1000, 1000, KisColor(Qt::black, KisMetaRegistry::instance()->csRegistry()->getRGB8()));
 
442
        }
 
443
        report = report.append(QString("    Opaque fill 1000 x 1000 layer %1 times: %2\n").arg(testCount).arg(t.elapsed()));
 
444
 
 
445
 
 
446
        t.restart();
 
447
        for (Q_UINT32 i = 0; i < testCount; ++i) {
 
448
            p.fillRect(50, 50, 500, 500, KisColor(Qt::black, KisMetaRegistry::instance()->csRegistry()->getRGB8()));
 
449
        }
 
450
        report = report.append(QString("    Opaque fill 500 x 500 layer %1 times: %2\n").arg(testCount).arg(t.elapsed()));
 
451
 
 
452
 
 
453
        t.restart();
 
454
        for (Q_UINT32 i = 0; i < testCount; ++i) {
 
455
            p.fillRect(-50, -50, 1100, 1100, KisColor(Qt::black, KisMetaRegistry::instance()->csRegistry()->getRGB8()));
 
456
        }
 
457
        report = report.append(QString("    Opaque fill rect bigger than layer %1 times: %2\n").arg(testCount).arg(t.elapsed()));
 
458
 
 
459
        // Transparent rect fill
 
460
 
 
461
        t.restart();
 
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);
 
464
        }
 
465
        report = report.append(QString("    Opaque fill 1000 x 1000 layer %1 times: %2\n").arg(testCount).arg(t.elapsed()));
 
466
 
 
467
 
 
468
        t.restart();
 
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);
 
471
        }
 
472
        report = report.append(QString("    Opaque fill 500 x 500 layer %1 times: %2\n").arg(testCount).arg(t.elapsed()));
 
473
 
 
474
 
 
475
        t.restart();
 
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);
 
478
        }
 
479
        report = report.append(QString("    Opaque fill rect bigger than layer %1 times: %2\n").arg(testCount).arg(t.elapsed()));
 
480
 
 
481
        // Colour fill
 
482
 
 
483
        t.restart();
 
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);
 
490
            p.fillColor(0,0);
 
491
        }
 
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()));
 
493
 
 
494
 
 
495
        // Pattern fill
 
496
        t.restart();
 
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");
 
502
            Q_CHECK_PTR(r);
 
503
            p.setPattern((KisPattern*)r->resources().first());
 
504
            p.setFillThreshold(15);
 
505
            p.setCompositeOp(COMPOSITE_OVER);
 
506
            p.fillPattern(0,0);
 
507
        }
 
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()));
 
509
 
 
510
 
 
511
 
 
512
    }
 
513
 
 
514
 
 
515
 
 
516
    return report;
 
517
 
 
518
}
 
519
 
 
520
QString PerfTest::gradientTest(Q_UINT32 testCount)
 
521
{
 
522
    return QString("Gradient test\n");
 
523
}
 
524
 
 
525
QString PerfTest::pixelTest(Q_UINT32 testCount)
 
526
{
 
527
    QString report = QString("* pixel/setpixel test\n");
 
528
 
 
529
    KisDoc * doc = m_view->canvasSubject()->document();
 
530
    KisIDList l = KisMetaRegistry::instance()->csRegistry()->listKeys();
 
531
 
 
532
 
 
533
    for (KisIDList::Iterator it = l.begin(); it != l.end(); ++it) {
 
534
        report = report.append( "  Testing pixel/setpixel on " + (*it).name() + "\n");
 
535
 
 
536
         KisImageSP img = doc->newImage("fill-" + (*it).name(), 1000, 1000, KisMetaRegistry::instance()->csRegistry()->getColorSpace(*it,""));
 
537
 
 
538
        KisPaintDeviceSP l = img->activeDevice();
 
539
 
 
540
         QTime t;
 
541
         t.restart();
 
542
 
 
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);
 
549
                }
 
550
            }
 
551
         }
 
552
        report = report.append(QString("    read 1000 x 1000 pixels %1 times: %2\n").arg(testCount).arg(t.elapsed()));
 
553
 
 
554
        c= Qt::black;
 
555
         t.restart();
 
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);
 
560
                }
 
561
            }
 
562
         }
 
563
        report = report.append(QString("    written 1000 x 1000 pixels %1 times: %2\n").arg(testCount).arg(t.elapsed()));
 
564
 
 
565
    }
 
566
 
 
567
 
 
568
 
 
569
 
 
570
    return report;
 
571
 
 
572
}
 
573
 
 
574
QString PerfTest::shapeTest(Q_UINT32 testCount)
 
575
{
 
576
    return QString("Shape test\n");
 
577
}
 
578
 
 
579
QString PerfTest::layerTest(Q_UINT32 testCount)
 
580
{
 
581
    return QString("Layer test\n");
 
582
}
 
583
 
 
584
QString PerfTest::scaleTest(Q_UINT32 testCount)
 
585
{
 
586
    return QString("Scale test\n");
 
587
}
 
588
 
 
589
QString PerfTest::rotateTest(Q_UINT32 testCount)
 
590
{
 
591
    QString report = QString("* Rotate test\n");
 
592
 
 
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) {
 
596
 
 
597
        doc->undoAdapter()->setUndo( false );
 
598
        QTime t;
 
599
 
 
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;
 
606
                delete img;
 
607
            }
 
608
        }
 
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()));
 
610
    }
 
611
    return report;
 
612
}
 
613
 
 
614
QString PerfTest::renderTest(Q_UINT32 restCount)
 
615
{
 
616
    return QString("Render test\n");
 
617
}
 
618
 
 
619
QString PerfTest::selectionTest(Q_UINT32 testCount)
 
620
{
 
621
    return QString("Selection test\n");
 
622
}
 
623
 
 
624
QString PerfTest::colorConversionTest(Q_UINT32 testCount)
 
625
{
 
626
    QString report = QString("* Colorspace conversion test\n");
 
627
 
 
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) {
 
631
 
 
632
        KisImage * img = doc->newImage("cs-" + (*it).name(), 1000, 1000, KisMetaRegistry::instance()->csRegistry()->getColorSpace(*it,""));
 
633
 
 
634
        QTime t;
 
635
 
 
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;
 
639
            
 
640
            t.restart();
 
641
            for (uint i = 0; i < testCount; ++i) {
 
642
                KisImage * img2 = new KisImage(*img);
 
643
                img2->convertTo(KisMetaRegistry::instance()->csRegistry()->getColorSpace(*it2,""));
 
644
                delete img2;
 
645
            }
 
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()));
 
647
 
 
648
        }
 
649
 
 
650
        delete img;
 
651
 
 
652
    }
 
653
    return report;
 
654
 
 
655
}
 
656
 
 
657
QString PerfTest::filterTest(Q_UINT32 testCount)
 
658
{
 
659
 
 
660
    QString report = QString("* Filter test\n");
 
661
 
 
662
    KisIDList filters = KisFilterRegistry::instance()->listKeys();
 
663
    KisDoc * doc = m_view->canvasSubject()->document();
 
664
    KisIDList l = KisMetaRegistry::instance()->csRegistry()->listKeys();
 
665
 
 
666
    for (KisIDList::Iterator it = l.begin(); it != l.end(); ++it) {
 
667
        report = report.append( "  Testing filtering on " + (*it).name() + "\n");
 
668
 
 
669
        KisImageSP img = doc->newImage("filter-" + (*it).name(), 1000, 1000, KisMetaRegistry::instance()->csRegistry()->getColorSpace(*it,""));
 
670
        KisPaintDeviceSP l = img->activeDevice();
 
671
 
 
672
        QTime t;
 
673
 
 
674
        for (KisIDList::Iterator it = filters.begin(); it != filters.end(); ++it) {
 
675
            
 
676
            KisFilterSP f = KisFilterRegistry::instance()->get(*it);
 
677
            t.restart();
 
678
            kdDebug() << "test filter " << f->id().name() << " on " << img->colorSpace()->id().name() << endl;
 
679
            for (Q_UINT32 i = 0; i < testCount; ++i) {
 
680
                f->enableProgress();
 
681
                f->process(l.data(), l.data(), f->configuration(f->createConfigurationWidget(m_view, l.data())), QRect(0, 0, 1000, 1000));
 
682
                f->disableProgress();
 
683
            }
 
684
            report = report.append(QString("    filtered " + (*it).name() + "1000 x 1000 pixels %1 times: %2\n").arg(testCount).arg(t.elapsed()));
 
685
 
 
686
        }
 
687
 
 
688
    }
 
689
    return report;
 
690
 
 
691
}
 
692
 
 
693
QString PerfTest::readBytesTest(Q_UINT32 testCount)
 
694
{
 
695
    QString report = QString("* Read bytes test\n\n");
 
696
 
 
697
    // On default tiles
 
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();
 
701
 
 
702
    QTime t;
 
703
    t.restart();
 
704
 
 
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);
 
709
        delete[] newData;
 
710
    }
 
711
 
 
712
    report = report.append(QString("    read 1000 x 1000 pixels %1 times from empty image: %2\n").arg(testCount).arg(t.elapsed()));
 
713
 
 
714
    // On tiles with data
 
715
 
 
716
    KisFillPainter p(l.data());
 
717
    p.fillRect(0, 0, 1000, 1000, KisColor(Qt::black, KisMetaRegistry::instance()->csRegistry()->getRGB8()));
 
718
    p.end();
 
719
 
 
720
    t.restart();
 
721
 
 
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);
 
726
        delete[] newData;
 
727
    }
 
728
 
 
729
    report = report.append(QString("    read 1000 x 1000 pixels %1 times from filled image: %2\n").arg(testCount).arg(t.elapsed()));
 
730
 
 
731
    return report;
 
732
}
 
733
 
 
734
 
 
735
QString PerfTest::writeBytesTest(Q_UINT32 testCount)
 
736
{
 
737
    QString report = QString("* Write bytes test");
 
738
 
 
739
    // On default tiles
 
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()));
 
745
    p.end();
 
746
 
 
747
 
 
748
    Q_UINT8 * data = new Q_UINT8[1000 * 1000 * l->pixelSize()];
 
749
    Q_CHECK_PTR(data);
 
750
    l->readBytes(data, 0, 0, 1000, 1000);
 
751
 
 
752
    QTime t;
 
753
    t.restart();
 
754
    for (Q_UINT32 i = 0; i < testCount; ++i) {
 
755
        l->writeBytes(data, 0, 0, 1000, 1000);
 
756
    }
 
757
    delete[] data;
 
758
    report = report.append(QString("    written 1000 x 1000 pixels %1 times: %2\n").arg(testCount).arg(t.elapsed()));
 
759
    return report;
 
760
 
 
761
 
 
762
}
 
763
 
 
764
/////// Iterator tests
 
765
 
 
766
 
 
767
QString hlineRODefault(KisDoc * doc, Q_UINT32 testCount)
 
768
{
 
769
    KisImageSP img = doc->newImage("", 1000, 1000, KisMetaRegistry::instance()->csRegistry()->getColorSpace(KisID("RGBA", ""),""));
 
770
    KisPaintDeviceSP l = img->activeDevice();
 
771
 
 
772
    QTime t;
 
773
    t.restart();
 
774
 
 
775
 
 
776
    for (Q_UINT32 i = 0; i < testCount; ++i) {
 
777
         int adv;
 
778
 
 
779
        for(Q_INT32 y2 = 0; y2 < 0 + 1000; y2++)
 
780
        {
 
781
            KisHLineIterator hiter = l->createHLineIterator(0, y2, 1000, false);
 
782
            while(! hiter.isDone())
 
783
            {
 
784
                 adv = hiter.nConseqHPixels();
 
785
                 hiter += adv;
 
786
            }
 
787
        }
 
788
 
 
789
    }
 
790
 
 
791
    return QString("    hline iterated read-only 1000 x 1000 pixels %1 times over default tile: %2\n").arg(testCount).arg(t.elapsed());
 
792
 
 
793
 
 
794
}
 
795
 
 
796
QString hlineRO(KisDoc * doc, Q_UINT32 testCount)
 
797
{
 
798
    KisImageSP img = doc->newImage("", 1000, 1000, KisMetaRegistry::instance()->csRegistry()->getColorSpace(KisID("RGBA", ""),""));
 
799
    KisPaintDeviceSP l = img->activeDevice();
 
800
 
 
801
    KisFillPainter p(l.data());
 
802
    p.fillRect(0, 0, 1000, 1000, KisColor(Qt::black, KisMetaRegistry::instance()->csRegistry()->getRGB8()));
 
803
    p.end();
 
804
 
 
805
    QTime t;
 
806
    t.restart();
 
807
 
 
808
    for (Q_UINT32 i = 0; i < testCount; ++i) {
 
809
         int adv;
 
810
 
 
811
        for(Q_INT32 y2 = 0; y2 < 0 + 1000; y2++)
 
812
        {
 
813
            KisHLineIterator hiter = l->createHLineIterator(0, y2, 1000, false);
 
814
            while(! hiter.isDone())
 
815
            {
 
816
                 adv = hiter.nConseqHPixels();
 
817
                 hiter += adv;
 
818
            }
 
819
        }
 
820
 
 
821
    }
 
822
 
 
823
    return QString("    hline iterated read-only 1000 x 1000 pixels %1 times over existing tile: %2\n").arg(testCount).arg(t.elapsed());
 
824
 
 
825
}
 
826
 
 
827
QString hlineWRDefault(KisDoc * doc, Q_UINT32 testCount)
 
828
{
 
829
    KisImageSP img = doc->newImage("", 1000, 1000, KisMetaRegistry::instance()->csRegistry()->getColorSpace(KisID("RGBA", ""),""));
 
830
    KisPaintDeviceSP l = img->activeDevice();
 
831
 
 
832
    QTime t;
 
833
    t.restart();
 
834
 
 
835
    for (Q_UINT32 i = 0; i < testCount; ++i) {
 
836
         int adv;
 
837
 
 
838
        for(Q_INT32 y2 = 0; y2 < 0 + 1000; y2++)
 
839
        {
 
840
            KisHLineIterator hiter = l->createHLineIterator(0, y2, 1000, true);
 
841
            while(! hiter.isDone())
 
842
            {
 
843
                 adv = hiter.nConseqHPixels();
 
844
                 hiter += adv;
 
845
            }
 
846
        }
 
847
 
 
848
    }
 
849
 
 
850
    return QString("    hline iterated writable 1000 x 1000 pixels %1 times over default tile: %2\n").arg(testCount).arg(t.elapsed());
 
851
 
 
852
}
 
853
 
 
854
QString hlineWR(KisDoc * doc, Q_UINT32 testCount)
 
855
{
 
856
    KisImageSP img = doc->newImage("", 1000, 1000, KisMetaRegistry::instance()->csRegistry()->getColorSpace(KisID("RGBA", ""),""));
 
857
    KisPaintDeviceSP l = img->activeDevice();
 
858
 
 
859
    KisFillPainter p(l.data());
 
860
    p.fillRect(0, 0, 1000, 1000, KisColor(Qt::black, KisMetaRegistry::instance()->csRegistry()->getRGB8()));
 
861
    p.end();
 
862
 
 
863
 
 
864
    QTime t;
 
865
    t.restart();
 
866
 
 
867
    for (Q_UINT32 i = 0; i < testCount; ++i) {
 
868
         int adv;
 
869
        for(Q_INT32 y2 = 0; y2 < 0 + 1000; y2++)
 
870
        {
 
871
            KisHLineIterator hiter = l->createHLineIterator(0, y2, 1000, true);
 
872
            while(! hiter.isDone())
 
873
            {
 
874
                 adv = hiter.nConseqHPixels();
 
875
                 hiter += adv;
 
876
            }
 
877
        }
 
878
 
 
879
    }
 
880
 
 
881
    return QString("    hline iterated writable 1000 x 1000 pixels %1 times over existing tile: %2\n").arg(testCount).arg(t.elapsed());
 
882
 
 
883
}
 
884
 
 
885
 
 
886
QString vlineRODefault(KisDoc * doc, Q_UINT32 testCount)
 
887
{
 
888
    KisImageSP img = doc->newImage("", 1000, 1000, KisMetaRegistry::instance()->csRegistry()->getColorSpace(KisID("RGBA", ""),""));
 
889
    KisPaintDeviceSP l = img->activeDevice();
 
890
 
 
891
    QTime t;
 
892
    t.restart();
 
893
 
 
894
    for (Q_UINT32 i = 0; i < testCount; ++i) {
 
895
        for(Q_INT32 y2 = 0; y2 < 0 + 1000; y2++)
 
896
        {
 
897
            KisVLineIterator hiter = l->createVLineIterator(y2, 0, 1000, true);
 
898
            while(! hiter.isDone())
 
899
            {
 
900
                 ++hiter;
 
901
            }
 
902
        }
 
903
 
 
904
    }
 
905
 
 
906
    return QString("    vline iterated read-only 1000 x 1000 pixels %1 times over default tile: %2\n").arg(testCount).arg(t.elapsed());
 
907
 
 
908
}
 
909
 
 
910
QString vlineRO(KisDoc * doc, Q_UINT32 testCount)
 
911
{
 
912
    KisImageSP img = doc->newImage("", 1000, 1000, KisMetaRegistry::instance()->csRegistry()->getColorSpace(KisID("RGBA", ""),""));
 
913
    KisPaintDeviceSP l = img->activeDevice();
 
914
 
 
915
    KisFillPainter p(l.data());
 
916
    p.fillRect(0, 0, 1000, 1000, KisColor(Qt::black, KisMetaRegistry::instance()->csRegistry()->getRGB8()));
 
917
    p.end();
 
918
 
 
919
 
 
920
    QTime t;
 
921
    t.restart();
 
922
 
 
923
    for (Q_UINT32 i = 0; i < testCount; ++i) {
 
924
        for(Q_INT32 y2 = 0; y2 < 0 + 1000; y2++)
 
925
        {
 
926
            KisVLineIterator hiter = l->createVLineIterator(y2, 0, 1000, true);
 
927
            while(! hiter.isDone())
 
928
            {
 
929
                 ++hiter;
 
930
            }
 
931
        }
 
932
 
 
933
    }
 
934
 
 
935
    return QString("    vline iterated read-only 1000 x 1000 pixels %1 times over existing tile: %2\n").arg(testCount).arg(t.elapsed());
 
936
 
 
937
}
 
938
 
 
939
QString vlineWRDefault(KisDoc * doc, Q_UINT32 testCount)
 
940
{
 
941
    KisImageSP img = doc->newImage("", 1000, 1000, KisMetaRegistry::instance()->csRegistry()->getColorSpace(KisID("RGBA", ""),""));
 
942
    KisPaintDeviceSP l = img->activeDevice();
 
943
 
 
944
    QTime t;
 
945
    t.restart();
 
946
 
 
947
    for (Q_UINT32 i = 0; i < testCount; ++i) {
 
948
 
 
949
        for(Q_INT32 y2 = 0; y2 < 0 + 1000; y2++)
 
950
        {
 
951
            KisVLineIterator hiter = l->createVLineIterator(y2, 0, 1000, true);
 
952
            while(! hiter.isDone())
 
953
            {
 
954
                 ++hiter;
 
955
            }
 
956
        }
 
957
 
 
958
    }
 
959
 
 
960
    return QString("    vline iterated writable 1000 x 1000 pixels %1 times over default tile: %2\n").arg(testCount).arg(t.elapsed());
 
961
}
 
962
 
 
963
QString vlineWR(KisDoc * doc, Q_UINT32 testCount)
 
964
{
 
965
 
 
966
    KisImageSP img = doc->newImage("", 1000, 1000, KisMetaRegistry::instance()->csRegistry()->getColorSpace(KisID("RGBA", ""),""));
 
967
    KisPaintDeviceSP l = img->activeDevice();
 
968
 
 
969
    KisFillPainter p(l.data());
 
970
    p.fillRect(0, 0, 1000, 1000, KisColor(Qt::black, KisMetaRegistry::instance()->csRegistry()->getRGB8()));
 
971
    p.end();
 
972
 
 
973
    QTime t;
 
974
    t.restart();
 
975
 
 
976
    for (Q_UINT32 i = 0; i < testCount; ++i) {
 
977
        for(Q_INT32 y2 = 0; y2 < 0 + 1000; y2++)
 
978
        {
 
979
            KisHLineIterator hiter = l->createHLineIterator(y2, 0, 1000, true);
 
980
            while(! hiter.isDone())
 
981
            {
 
982
                 ++hiter;
 
983
            }
 
984
        }
 
985
 
 
986
    }
 
987
 
 
988
    return QString("    vline iterated writable 1000 x 1000 pixels %1 times over existing tile: %2\n").arg(testCount).arg(t.elapsed());
 
989
 
 
990
}
 
991
 
 
992
QString rectRODefault(KisDoc * doc, Q_UINT32 testCount)
 
993
{
 
994
    KisImageSP img = doc->newImage("", 1000, 1000, KisMetaRegistry::instance()->csRegistry()->getColorSpace(KisID("RGBA", ""),""));
 
995
    KisPaintDeviceSP l = img->activeDevice();
 
996
;
 
997
    QTime t;
 
998
    t.restart();
 
999
 
 
1000
    for (Q_UINT32 i = 0; i < testCount; ++i) {
 
1001
        KisRectIterator r = l->createRectIterator(0, 0, 1000, 1000, false);
 
1002
        while(! r.isDone())
 
1003
        {
 
1004
            ++r;
 
1005
        }
 
1006
    }
 
1007
 
 
1008
    return QString("    rect iterated read-only 1000 x 1000 pixels %1 times over default tile: %2\n").arg(testCount).arg(t.elapsed());
 
1009
 
 
1010
 
 
1011
}
 
1012
 
 
1013
QString rectRO(KisDoc * doc, Q_UINT32 testCount)
 
1014
{
 
1015
    KisImageSP img = doc->newImage("", 1000, 1000, KisMetaRegistry::instance()->csRegistry()->getColorSpace(KisID("RGBA", ""),""));
 
1016
    KisPaintDeviceSP l = img->activeDevice();
 
1017
 
 
1018
    KisFillPainter p(l.data());
 
1019
    p.fillRect(0, 0, 1000, 1000, KisColor(Qt::black, KisMetaRegistry::instance()->csRegistry()->getRGB8()));
 
1020
    p.end();
 
1021
 
 
1022
    QTime t;
 
1023
    t.restart();
 
1024
 
 
1025
    for (Q_UINT32 i = 0; i < testCount; ++i) {
 
1026
        KisRectIterator r = l->createRectIterator(0, 0, 1000, 1000, false);
 
1027
        while(! r.isDone())
 
1028
        {
 
1029
            ++r;
 
1030
        }
 
1031
    }
 
1032
 
 
1033
    return QString("    rect iterated read-only 1000 x 1000 pixels %1 times over existing tile: %2\n").arg(testCount).arg(t.elapsed());
 
1034
 
 
1035
}
 
1036
 
 
1037
QString rectWRDefault(KisDoc * doc, Q_UINT32 testCount)
 
1038
{
 
1039
 
 
1040
 
 
1041
    KisImageSP img = doc->newImage("", 1000, 1000, KisMetaRegistry::instance()->csRegistry()->getColorSpace(KisID("RGBA", ""),""));
 
1042
    KisPaintDeviceSP l = img->activeDevice();
 
1043
 
 
1044
    QTime t;
 
1045
    t.restart();
 
1046
 
 
1047
    for (Q_UINT32 i = 0; i < testCount; ++i) {
 
1048
        KisRectIterator r = l->createRectIterator(0, 0, 1000, 1000, true);
 
1049
        while(! r.isDone())
 
1050
        {
 
1051
            ++r;
 
1052
        }
 
1053
    }
 
1054
 
 
1055
    return QString("    rect iterated writable 1000 x 1000 pixels %1 times over default tile: %2\n").arg(testCount).arg(t.elapsed());
 
1056
 
 
1057
}
 
1058
 
 
1059
QString rectWR(KisDoc * doc, Q_UINT32 testCount)
 
1060
{
 
1061
    KisImageSP img = doc->newImage("", 1000, 1000, KisMetaRegistry::instance()->csRegistry()->getColorSpace(KisID("RGBA", ""),""));
 
1062
    KisPaintDeviceSP l = img->activeDevice();
 
1063
 
 
1064
    KisFillPainter p(l.data());
 
1065
    p.fillRect(0, 0, 1000, 1000, KisColor(Qt::black, KisMetaRegistry::instance()->csRegistry()->getRGB8()));
 
1066
    p.end();
 
1067
 
 
1068
 
 
1069
    QTime t;
 
1070
    t.restart();
 
1071
 
 
1072
 
 
1073
    for (Q_UINT32 i = 0; i < testCount; ++i) {
 
1074
        KisRectIterator r = l->createRectIterator(0, 0, 1000, 1000, true);
 
1075
        while(! r.isDone())
 
1076
        {
 
1077
            ++r;
 
1078
        }
 
1079
    }
 
1080
 
 
1081
 
 
1082
    return QString("    rect iterated writable 1000 x 1000 pixels %1 times over existing tile: %2\n").arg(testCount).arg(t.elapsed());
 
1083
 
 
1084
 
 
1085
}
 
1086
QString PerfTest::iteratorTest(Q_UINT32 testCount)
 
1087
{
 
1088
    QString report = "Iterator test";
 
1089
 
 
1090
    KisDoc * doc = m_view->canvasSubject()->document();
 
1091
 
 
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));
 
1096
 
 
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));
 
1101
 
 
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));
 
1106
 
 
1107
    return report;
 
1108
 
 
1109
 
 
1110
}
 
1111
 
 
1112
QString PerfTest::paintViewTest(Q_UINT32 testCount)
 
1113
{
 
1114
    QString report = QString("* paintView test\n\n");
 
1115
 
 
1116
    KisDoc * doc = m_view->canvasSubject()->document();
 
1117
 
 
1118
    KisImageSP img = doc->currentImage();
 
1119
    img->resize(512,512);
 
1120
 
 
1121
 
 
1122
    KisPaintDeviceSP l = img->activeDevice();
 
1123
 
 
1124
    KisFillPainter p(l.data());
 
1125
    p.fillRect(0, 0, 512, 512, KisColor(Qt::black, KisMetaRegistry::instance()->csRegistry()->getRGB8()));
 
1126
    p.end();
 
1127
 
 
1128
    QTime t;
 
1129
    t.restart();
 
1130
 
 
1131
#if USE_CALLGRIND
 
1132
    CALLGRIND_ZERO_STATS();
 
1133
#endif
 
1134
 
 
1135
    for (Q_UINT32 i = 0; i < testCount; ++i) {
 
1136
        m_view->getCanvasController()->updateCanvas(QRect(0, 0, 512, 512));
 
1137
    }
 
1138
 
 
1139
#if USE_CALLGRIND
 
1140
    CALLGRIND_DUMP_STATS();
 
1141
#endif
 
1142
 
 
1143
    report = report.append(QString("    painted a 512 x 512 image %1 times: %2 ms\n").arg(testCount).arg(t.elapsed()));
 
1144
 
 
1145
    img->newLayer("layer 2", OPACITY_OPAQUE);
 
1146
    l = img->activeDevice();
 
1147
 
 
1148
    p.begin(l.data());
 
1149
    p.fillRect(0, 0, 512, 512, KisColor(Qt::black, KisMetaRegistry::instance()->csRegistry()->getRGB8()));
 
1150
    p.end();
 
1151
 
 
1152
    img->newLayer("layer 3", OPACITY_OPAQUE);
 
1153
    l = img->activeDevice();
 
1154
 
 
1155
    p.begin(l.data());
 
1156
    p.fillRect(0, 0, 512, 512, KisColor(Qt::black, KisMetaRegistry::instance()->csRegistry()->getRGB8()));
 
1157
    p.end();
 
1158
 
 
1159
    t.restart();
 
1160
 
 
1161
    for (Q_UINT32 i = 0; i < testCount; ++i) {
 
1162
        m_view->getCanvasController()->updateCanvas(QRect(0, 0, 512, 512));
 
1163
    }
 
1164
 
 
1165
    report = report.append(QString("    painted a 512 x 512 image with 3 layers %1 times: %2 ms\n").arg(testCount).arg(t.elapsed()));
 
1166
 
 
1167
    return report;
 
1168
}
 
1169
 
 
1170
QString PerfTest::paintViewFPSTest()
 
1171
{
 
1172
    QString report = QString("* paintView (fps) test\n\n");
 
1173
 
 
1174
    QTime t;
 
1175
    t.restart();
 
1176
 
 
1177
#if USE_CALLGRIND
 
1178
    CALLGRIND_ZERO_STATS();
 
1179
#endif
 
1180
 
 
1181
    int numViewsPainted = 0;
 
1182
    const int millisecondsPerSecond = 1000;
 
1183
 
 
1184
    while (t.elapsed() < millisecondsPerSecond) {
 
1185
        m_view->getCanvasController()->updateCanvas();
 
1186
        numViewsPainted++;
 
1187
    }
 
1188
 
 
1189
#if USE_CALLGRIND
 
1190
    CALLGRIND_DUMP_STATS();
 
1191
#endif
 
1192
 
 
1193
    report = report.append(QString("    painted current view at %1 frames per second\n").arg(numViewsPainted));
 
1194
 
 
1195
    return report;
 
1196
}
 
1197
 
 
1198
#include "perftest.moc"