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 6.44 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
#include <QImage>
22
#include <QDebug>
23

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

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

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

#include <KoColorSpace.h>
#include <KoColorSpaceRegistry.h>
36
#include <KoCompositeOp.h>
Lukáš Tvrdý's avatar
Lukáš Tvrdý committed
37 38 39 40
#include <KoColor.h>

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

43 44

#define CYCLES 20
45
static const int LINE_COUNT = 100;
Lukáš Tvrdý's avatar
Lukáš Tvrdý committed
46 47 48 49 50

void KisPainterBenchmark::initTestCase()
{
    m_colorSpace = KoColorSpaceRegistry::instance()->rgb8();    
    
51 52
    m_color = KoColor(m_colorSpace);
    m_color.fromQColor(Qt::red);
53 54 55 56 57 58 59
    
    
    srand48(0);
    for (int i = 0; i < LINE_COUNT ;i++){
        m_points.append( QPointF(drand48() * TEST_IMAGE_WIDTH, drand48() * TEST_IMAGE_HEIGHT) );
        m_points.append( QPointF(drand48() * TEST_IMAGE_WIDTH, drand48() * TEST_IMAGE_HEIGHT) );
    }
Lukáš Tvrdý's avatar
Lukáš Tvrdý committed
60 61 62 63 64 65 66 67 68 69
}

void KisPainterBenchmark::cleanupTestCase()
{
}

void KisPainterBenchmark::benchmarkBitBlt()
{
    KisPaintDeviceSP src = new KisPaintDevice(m_colorSpace);
    KisPaintDeviceSP dst = new KisPaintDevice(m_colorSpace);
70 71 72 73 74 75
    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);
76
    QRect rc(0,0,TEST_IMAGE_WIDTH, TEST_IMAGE_HEIGHT);
77 78 79 80 81 82 83 84 85
    
    QBENCHMARK{
        for (int i = 0; i < CYCLES ; i++){
            gc.bitBlt(pos,src,rc);
        }
    }

}

86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105
void KisPainterBenchmark::benchmarkFastBitBlt()
{
    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());

    KisPainter gc(dst);
    gc.setCompositeOp(m_colorSpace->compositeOp(COMPOSITE_COPY));

    QPoint pos(0,0);
    QRect rc(0,0,TEST_IMAGE_WIDTH, TEST_IMAGE_HEIGHT);

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

}
106 107 108 109 110 111 112 113 114 115 116 117

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
118
    
119 120
    KisPainter gc(dst);
    gc.setSelection(selection);
Lukáš Tvrdý's avatar
Lukáš Tvrdý committed
121 122
    
    QPoint pos(0,0);
123
    QRect rc(0,0,TEST_IMAGE_WIDTH, TEST_IMAGE_HEIGHT);
124 125 126 127 128 129 130
    
    QBENCHMARK{
        for (int i = 0; i < CYCLES ; i++){
            gc.bitBlt(pos,src,rc);
        }
    }

Lukáš Tvrdý's avatar
Lukáš Tvrdý committed
131
    
132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175
}


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();

176
    QBENCHMARK{
177 178 179
        for (int i = 0; i < CYCLES ; i++){
            gc.bltFixed(pos,fdev,rc);
        }
Lukáš Tvrdý's avatar
Lukáš Tvrdý committed
180 181 182 183
    }

}

184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236
void KisPainterBenchmark::benchmarkDrawThickLine()
{
    KisPaintDeviceSP dev = new KisPaintDevice(m_colorSpace);
    KoColor color(m_colorSpace);
    color.fromQColor(Qt::white);
    
    dev->clear();
    dev->fill(0,0,TEST_IMAGE_WIDTH,TEST_IMAGE_HEIGHT,color.data());
    
    color.fromQColor(Qt::black);
    
    KisPainter painter(dev);
    painter.setPaintColor(color);
    
    QBENCHMARK{
        for (int i = 0; i < LINE_COUNT; i++){
            painter.drawThickLine(m_points[i*2],m_points[i*2+1],10,10);
        }
    }
    //dev->convertToQImage(m_colorSpace->profile()).save("drawThickLine.png");
}


void KisPainterBenchmark::benchmarkDrawQtLine()
{
    KisPaintDeviceSP dev = new KisPaintDevice(m_colorSpace);
    KoColor color(m_colorSpace);
    color.fromQColor(Qt::white);
    
    dev->clear();
    dev->fill(0,0,TEST_IMAGE_WIDTH,TEST_IMAGE_HEIGHT,color.data());
    
    color.fromQColor(Qt::black);
    
    KisPainter painter(dev);
    painter.setPaintColor(color);
    painter.setFillStyle(KisPainter::FillStyleForegroundColor);
    
    QPen pen;
    pen.setWidth(10);
    pen.setColor(Qt::white);
    pen.setCapStyle(Qt::RoundCap);
    
    QBENCHMARK{
        for (int i = 0; i < LINE_COUNT; i++){
            QPainterPath path;
            path.moveTo(m_points[i*2]);
            path.lineTo(m_points[i*2 + 1]);
            painter.drawPainterPath(path, pen);
        }
    }
    //dev->convertToQImage(m_colorSpace->profile(),0,0,TEST_IMAGE_WIDTH,TEST_IMAGE_HEIGHT).save("drawQtLine.png");
}
Lukáš Tvrdý's avatar
Lukáš Tvrdý committed
237 238 239 240


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