tests/benchmarks/gui/image/blendbench/main.cpp
changeset 37 758a864f9613
parent 18 2f34d5167611
equal deleted inserted replaced
36:ef0373b55136 37:758a864f9613
   101 {
   101 {
   102     Q_OBJECT
   102     Q_OBJECT
   103 private slots:		
   103 private slots:		
   104     void blendBench_data();
   104     void blendBench_data();
   105     void blendBench();
   105     void blendBench();
       
   106 
       
   107     void blendBenchAlpha_data();
       
   108     void blendBenchAlpha();
       
   109 
       
   110     void unalignedBlendArgb32_data();
       
   111     void unalignedBlendArgb32();
   106 };
   112 };
   107 
   113 
   108 void BlendBench::blendBench_data()
   114 void BlendBench::blendBench_data()
   109 {
   115 {
   110     int first = 0;
   116     int first = 0;
   145     QBENCHMARK {
   151     QBENCHMARK {
   146         p.drawRect(0, 0, 512, 512);
   152         p.drawRect(0, 0, 512, 512);
   147     }
   153     }
   148 }
   154 }
   149 
   155 
       
   156 void BlendBench::blendBenchAlpha_data()
       
   157 {
       
   158     blendBench_data();
       
   159 }
       
   160 
       
   161 void BlendBench::blendBenchAlpha()
       
   162 {
       
   163     QFETCH(int, brushType);
       
   164     QFETCH(int, compositionMode);
       
   165 
       
   166     QImage img(512, 512, QImage::Format_ARGB32_Premultiplied);
       
   167     QImage src(512, 512, QImage::Format_ARGB32_Premultiplied);
       
   168     paint(&src);
       
   169     QPainter p(&img);
       
   170     p.setPen(Qt::NoPen);
       
   171 
       
   172     p.setCompositionMode(QPainter::CompositionMode(compositionMode));
       
   173     if (brushType == ImageBrush) {
       
   174         p.setBrush(QBrush(src));
       
   175     } else if (brushType == SolidBrush) {
       
   176         p.setBrush(QColor(127, 127, 127, 127));
       
   177     }
       
   178     p.setOpacity(0.7f);
       
   179 
       
   180     QBENCHMARK {
       
   181         p.drawRect(0, 0, 512, 512);
       
   182     }
       
   183 }
       
   184 
       
   185 void BlendBench::unalignedBlendArgb32_data()
       
   186 {
       
   187     // The performance of blending can depend of the alignment of the data
       
   188     // on 16 bytes. Some SIMD instruction set have significantly better
       
   189     // memory access when the memory is aligned on 16 bytes boundary.
       
   190 
       
   191     // offset in 32 bits words
       
   192     QTest::addColumn<int>("offset");
       
   193     QTest::newRow("aligned on 16 bytes") << 0;
       
   194     QTest::newRow("unaligned by 4 bytes") << 1;
       
   195     QTest::newRow("unaligned by 8 bytes") << 2;
       
   196     QTest::newRow("unaligned by 12 bytes") << 3;
       
   197 }
       
   198 
       
   199 void BlendBench::unalignedBlendArgb32()
       
   200 {
       
   201     const int dimension = 1024;
       
   202 
       
   203     // We use dst aligned by design. We don't want to test all the combination of alignemnt for src and dst.
       
   204     // Moreover, it make sense for us to align dst in the implementation because it is accessed more often.
       
   205     uchar *dstMemory = static_cast<uchar*>(qMallocAligned((dimension * dimension * sizeof(quint32)), 16));
       
   206     QImage destination(dstMemory, dimension, dimension, QImage::Format_ARGB32_Premultiplied);
       
   207     destination.fill(0x12345678); // avoid special cases of alpha
       
   208 
       
   209     uchar *srcMemory = static_cast<uchar*>(qMallocAligned((dimension * dimension * sizeof(quint32)) + 16, 16));
       
   210     QFETCH(int, offset);
       
   211     srcMemory += (offset * sizeof(quint32));
       
   212 
       
   213     QImage src(srcMemory, dimension, dimension, QImage::Format_ARGB32_Premultiplied);
       
   214     src.fill(0x87654321);
       
   215 
       
   216     QPainter painter(&destination);
       
   217     QBENCHMARK {
       
   218         painter.drawImage(QPoint(), src);
       
   219     }
       
   220 
       
   221     qFreeAligned(srcMemory);
       
   222     qFreeAligned(dstMemory);
       
   223 }
       
   224 
   150 QTEST_MAIN(BlendBench)
   225 QTEST_MAIN(BlendBench)
   151 
   226 
   152 #include "main.moc"
   227 #include "main.moc"