File indexing completed on 2024-04-28 04:21:33

0001 /*
0002  *  SPDX-FileCopyrightText: 2017 Dmitry Kazakov <dimula73@gmail.com>
0003  *
0004  *  SPDX-License-Identifier: GPL-2.0-or-later
0005  */
0006 
0007 #include "KisAnimationRenderingBenchmark.h"
0008 
0009 #include <simpletest.h>
0010 
0011 #include <testutil.h>
0012 #include "kis_time_span.h"
0013 #include "dialogs/KisAsyncAnimationFramesSaveDialog.h"
0014 #include "kis_image_animation_interface.h"
0015 #include "KisPart.h"
0016 #include "KisDocument.h"
0017 #include "kis_image.h"
0018 #include "kis_image_config.h"
0019 
0020 namespace {
0021 void removeTempFiles(const QString &filesMask)
0022 {
0023     QFileInfo info(filesMask);
0024     QDir dir(info.absolutePath());
0025     QStringList filesList = dir.entryList({ info.fileName() });
0026     if (!filesList.isEmpty()) {
0027         Q_FOREACH (const QString &file, filesList) {
0028             if (!dir.remove(file)) {
0029                 QFAIL("Couldn't remove the old testing file!");
0030             }
0031         }
0032     }
0033 }
0034 
0035 void runRenderingTest(KisImageSP image, int numCores, int numClones)
0036 {
0037     {
0038         KisImageConfig cfg(false);
0039         cfg.setMaxNumberOfThreads(numCores);
0040         cfg.setFrameRenderingClones(numClones);
0041     }
0042 
0043     const KisTimeSpan range = image->animationInterface()->documentPlaybackRange();
0044 
0045     KisAsyncAnimationFramesSaveDialog dlg(image, range, "temp_frames.png", 0, false, 0);
0046     dlg.setBatchMode(true);
0047 
0048     // repeat rendering twice!
0049     for (int i = 0; i < 1; i++) {
0050         removeTempFiles(dlg.savedFilesMaskWildcard());
0051         KisAsyncAnimationFramesSaveDialog::Result result = dlg.regenerateRange(0);
0052         QCOMPARE(result, KisAsyncAnimationFramesSaveDialog::RenderComplete);
0053         removeTempFiles(dlg.savedFilesMaskWildcard());
0054     }
0055 }
0056 
0057 
0058 }
0059 
0060 
0061 
0062 
0063 void KisAnimationRenderingBenchmark::testCacheRendering()
0064 {
0065     const QString fileName = TestUtil::fetchDataFileLazy("miloor_turntable_002.kra", true);
0066     QVERIFY(QFileInfo(fileName).exists());
0067 
0068 
0069     QScopedPointer<KisDocument> doc(KisPart::instance()->createDocument());
0070 
0071     bool loadingResult = doc->loadNativeFormat(fileName);
0072     QVERIFY(loadingResult);
0073 
0074 
0075     doc->image()->barrierLock();
0076     doc->image()->unlock();
0077 
0078 
0079     for (int numCores = 1; numCores <= QThread::idealThreadCount(); numCores++) {
0080         QElapsedTimer timer;
0081         timer.start();
0082 
0083         const int numClones = qMax(1, numCores / 2);
0084         runRenderingTest(doc->image(), numCores, numClones);
0085 
0086         qDebug() << "Cores:" << numCores << "Clones:" << numClones << "Time:" << timer.elapsed();
0087     }
0088 
0089     for (int numCores = 1; numCores <= QThread::idealThreadCount(); numCores++) {
0090         QElapsedTimer timer;
0091         timer.start();
0092 
0093         const int numClones = numCores;
0094         runRenderingTest(doc->image(), numCores, numClones);
0095 
0096         qDebug() << "Cores:" << numCores << "Clones:" << numClones << "Time:" << timer.elapsed();
0097     }
0098 }
0099 
0100 SIMPLE_TEST_MAIN(KisAnimationRenderingBenchmark)