kis_mask_generator_benchmark.cpp 2.96 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
/*
 *  Copyright (c) 2010 Cyrille Berger <cberger@cberger.net>
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 */

Yuri Chornoivan's avatar
Yuri Chornoivan committed
19
#include <config-vc.h>
Sven Langkamp's avatar
Sven Langkamp committed
20
#ifdef HAVE_VC
21 22 23 24 25 26
#if defined _MSC_VER
// Lets shut up the "possible loss of data" and "forcing value to bool 'true' or 'false'
#pragma warning ( push )
#pragma warning ( disable : 4244 )
#pragma warning ( disable : 4800 )
#endif
27 28
#include <Vc/Vc>
#include <Vc/IO>
29 30 31
#if defined _MSC_VER
#pragma warning ( pop )
#endif
Sven Langkamp's avatar
Sven Langkamp committed
32 33
#endif

34
#include <QTest>
Sven Langkamp's avatar
Sven Langkamp committed
35

36 37 38 39 40 41 42
#include "kis_mask_generator_benchmark.h"

#include "kis_circle_mask_generator.h"
#include "kis_rect_mask_generator.h"

void KisMaskGeneratorBenchmark::benchmarkCircle()
{
43
    KisCircleMaskGenerator gen(1000, 0.5, 0.5, 0.5, 3, true);
44 45 46 47 48 49 50 51 52 53 54
    QBENCHMARK{
        for(int i = -600; i < 600; ++i)
        {
            for(int j = -600; j < 600; ++j)
            {
                gen.valueAt(i, j);
            }
        }
    }
}

55 56 57 58 59 60 61 62
#include <KoColorSpace.h>
#include <KoColorSpaceRegistry.h>
#include "kis_fixed_paint_device.h"
#include "kis_types.h"
#include "kis_brush_mask_applicator_base.h"
#include "krita_utils.h"


63
void benchmarkSIMD(qreal fade) {
64 65
    const KoColorSpace * cs = KoColorSpaceRegistry::instance()->rgb8();
    KisFixedPaintDeviceSP dev = new KisFixedPaintDevice(cs);
66
    dev->setRect(QRect(0, 0, 1000, 1000));
67 68 69 70
    dev->initialize();

    MaskProcessingData data(dev, cs,
                            0.0, 1.0,
71
                            500, 500, 0);
72

73
    KisCircleMaskGenerator gen(1000, 1.0, fade, fade, 2, false);
74 75 76 77 78

    KisBrushMaskApplicatorBase *applicator = gen.applicator();
    applicator->initializeData(&data);

    QVector<QRect> rects = KritaUtils::splitRectIntoPatches(dev->bounds(), QSize(63, 63));
79 80

    QBENCHMARK{
81 82
        Q_FOREACH (const QRect &rc, rects) {
            applicator->process(rc);
83 84
        }
    }
85 86 87 88 89 90 91 92 93 94
}

void KisMaskGeneratorBenchmark::benchmarkSIMD_SharpBrush()
{
    benchmarkSIMD(1.0);
}

void KisMaskGeneratorBenchmark::benchmarkSIMD_FadedBrush()
{
    benchmarkSIMD(0.5);
95 96
}

97 98
void KisMaskGeneratorBenchmark::benchmarkSquare()
{
99
    KisRectangleMaskGenerator gen(1000, 0.5, 0.5, 0.5, 3, true);
100 101 102 103 104 105 106 107 108 109 110
    QBENCHMARK{
        for(int i = -600; i < 600; ++i)
        {
            for(int j = -600; j < 600; ++j)
            {
                gen.valueAt(i, j);
            }
        }
    }
}

111
QTEST_MAIN(KisMaskGeneratorBenchmark)