Members of the KDE Community are recommended to subscribe to the kde-community mailing list at https://mail.kde.org/mailman/listinfo/kde-community to allow them to participate in important discussions and receive other important announcements

kis_painter_benchmark.cpp 4.03 KB
Newer Older
Lukáš Tvrdý's avatar
Lukáš Tvrdý committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
/*
 *  Copyright (c) 2010 Lukáš Tvrdý lukast.dev@gmail.com
 *
 *  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.
 */

#include <qtest_kde.h>

21 22
#include <QImage>

Lukáš Tvrdý's avatar
Lukáš Tvrdý committed
23 24 25 26
#include "kis_painter_benchmark.h"
#include "kis_benchmark_values.h"

#include "kis_paint_device.h"
27 28 29 30
#include "kis_fixed_paint_device.h"

#include "kis_selection.h"
#include "kis_pixel_selection.h"
Lukáš Tvrdý's avatar
Lukáš Tvrdý committed
31 32 33 34 35 36 37 38
#include "kis_iterators_pixel.h"

#include <KoColorSpace.h>
#include <KoColorSpaceRegistry.h>
#include <KoColor.h>

#include <kis_image.h>
#include <kis_painter.h>
39
#include <kis_types.h>
Lukáš Tvrdý's avatar
Lukáš Tvrdý committed
40

41 42

#define CYCLES 20
Lukáš Tvrdý's avatar
Lukáš Tvrdý committed
43 44 45 46 47

void KisPainterBenchmark::initTestCase()
{
    m_colorSpace = KoColorSpaceRegistry::instance()->rgb8();    
    
48 49
    m_color = KoColor(m_colorSpace);
    m_color.fromQColor(Qt::red);
Lukáš Tvrdý's avatar
Lukáš Tvrdý committed
50 51 52 53 54 55 56 57 58 59 60
}

void KisPainterBenchmark::cleanupTestCase()
{
}


void KisPainterBenchmark::benchmarkBitBlt()
{
    KisPaintDeviceSP src = new KisPaintDevice(m_colorSpace);
    KisPaintDeviceSP dst = new KisPaintDevice(m_colorSpace);
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
    src->fill(0,0,TEST_IMAGE_WIDTH, TEST_IMAGE_HEIGHT, m_color.data());
    dst->fill(0,0,TEST_IMAGE_WIDTH, TEST_IMAGE_HEIGHT, m_color.data());
    
    KisPainter gc(dst);
    
    QPoint pos(0,0);
    QRect rc(0,0,TEST_IMAGE_WIDTH, TEST_IMAGE_WIDTH);
    
    QBENCHMARK{
        for (int i = 0; i < CYCLES ; i++){
            gc.bitBlt(pos,src,rc);
        }
    }

}


void KisPainterBenchmark::benchmarkBitBltSelection()
{
    KisPaintDeviceSP src = new KisPaintDevice(m_colorSpace);
    KisPaintDeviceSP dst = new KisPaintDevice(m_colorSpace);
    src->fill(0,0,TEST_IMAGE_WIDTH, TEST_IMAGE_HEIGHT, m_color.data());
    dst->fill(0,0,TEST_IMAGE_WIDTH, TEST_IMAGE_HEIGHT, m_color.data());

    KisSelectionSP selection = new KisSelection();
    selection->getOrCreatePixelSelection()->select(QRect(0, 0, TEST_IMAGE_WIDTH, TEST_IMAGE_HEIGHT));
    selection->updateProjection();

Lukáš Tvrdý's avatar
Lukáš Tvrdý committed
89
    
90 91
    KisPainter gc(dst);
    gc.setSelection(selection);
Lukáš Tvrdý's avatar
Lukáš Tvrdý committed
92 93
    
    QPoint pos(0,0);
94 95 96 97 98 99 100 101
    QRect rc(0,0,TEST_IMAGE_WIDTH, TEST_IMAGE_WIDTH);
    
    QBENCHMARK{
        for (int i = 0; i < CYCLES ; i++){
            gc.bitBlt(pos,src,rc);
        }
    }

Lukáš Tvrdý's avatar
Lukáš Tvrdý committed
102
    
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146
}


void KisPainterBenchmark::benchmarkFixedBitBlt()
{
    QImage img(TEST_IMAGE_WIDTH,TEST_IMAGE_HEIGHT,QImage::Format_ARGB32);
    img.fill(255);

    KisFixedPaintDeviceSP fdev = new KisFixedPaintDevice(m_colorSpace);
    fdev->convertFromQImage(img, "");

    KisPaintDeviceSP dst = new KisPaintDevice(m_colorSpace);
    KisPainter gc(dst);
    QPoint pos(0, 0);
    QRect rc = img.rect();

    QBENCHMARK{
        for (int i = 0; i < CYCLES ; i++){
            gc.bltFixed(pos,fdev,rc);
        }
    }
}


void KisPainterBenchmark::benchmarkFixedBitBltSelection()
{
    QImage img(TEST_IMAGE_WIDTH,TEST_IMAGE_HEIGHT,QImage::Format_ARGB32);
    img.fill(128);

    KisFixedPaintDeviceSP fdev = new KisFixedPaintDevice(m_colorSpace);
    fdev->convertFromQImage(img, "");

    KisPaintDeviceSP dst = new KisPaintDevice(m_colorSpace);

    KisSelectionSP selection = new KisSelection();
    selection->getOrCreatePixelSelection()->select(QRect(0, 0, TEST_IMAGE_WIDTH , TEST_IMAGE_HEIGHT));
    selection->updateProjection();

    KisPainter gc(dst);
    gc.setSelection(selection);

    QPoint pos(0, 0);
    QRect rc = img.rect();

147
    QBENCHMARK{
148 149 150
        for (int i = 0; i < CYCLES ; i++){
            gc.bltFixed(pos,fdev,rc);
        }
Lukáš Tvrdý's avatar
Lukáš Tvrdý committed
151 152 153 154 155 156 157 158
    }

}



QTEST_KDEMAIN(KisPainterBenchmark, NoGUI)
#include "kis_painter_benchmark.moc"