diff options
author | homeboy445 <akshitsan13@gmail.com> | 2021-10-20 21:29:48 +0530 |
---|---|---|
committer | Tomaž Vajngerl <tomaz.vajngerl@collabora.co.uk> | 2022-12-12 17:13:35 +0900 |
commit | 998c7c9d4d65d2262003e4a4d49b1ded46ccb463 (patch) | |
tree | 592d115158c7c07b1bb04a7cbaf8e75ec7b3005b | |
parent | 1ce100df8615738275894b0cd834515fd82ea6ef (diff) |
benchmark: Draw Gradient
This patch includes the method for checking the duration of
drawing of gradient for benchmarking.
Change-Id: I741bb07a1c2ac6e3c8a643c93be9d1a8afef5ccb
-rw-r--r-- | vcl/backendtest/benchmark/BenchmarkApp.cxx | 89 | ||||
-rw-r--r-- | vcl/backendtest/benchmark/outputdevice/Benchmarks.cxx | 133 | ||||
-rw-r--r-- | vcl/inc/test/Benchmarks.hxx | 5 |
3 files changed, 184 insertions, 43 deletions
diff --git a/vcl/backendtest/benchmark/BenchmarkApp.cxx b/vcl/backendtest/benchmark/BenchmarkApp.cxx index dcd32df8150f..d584983227c0 100644 --- a/vcl/backendtest/benchmark/BenchmarkApp.cxx +++ b/vcl/backendtest/benchmark/BenchmarkApp.cxx @@ -71,7 +71,7 @@ namespace class BenchMarkWindow : public WorkWindow { private: - static constexpr unsigned char gnNumberOfTests = 9; + static constexpr unsigned char gnNumberOfTests = 12; unsigned char mnTest; ScopedVclPtr<VirtualDevice> mpVDev; @@ -131,11 +131,10 @@ public: int nHeight) { tools::Rectangle aRectangle; - size_t index = 0; std::vector<tools::Rectangle> aRegions = setupRegions(1, 1, nWidth, nHeight); - aRectangle = aRegions[index++]; + aRectangle = aRegions[0]; Benchmark aOutDevTest; Bitmap aBitmap = aOutDevTest.setupMultiplePolygonsWithPolyPolygon(); drawBitmapScaledAndCentered(aRectangle, aBitmap, rRenderContext); @@ -145,10 +144,9 @@ public: static void drawWavelines(vcl::RenderContext& rRenderContext, int nWidth, int nHeight) { tools::Rectangle aRectangle; - size_t index = 0; std::vector<tools::Rectangle> aRegions = setupRegions(1, 1, nWidth, nHeight); - aRectangle = aRegions[index++]; + aRectangle = aRegions[0]; Benchmark aOutDevTest; Bitmap aBitmap = aOutDevTest.setupWavelines(); drawBitmapScaledAndCentered(aRectangle, aBitmap, rRenderContext); @@ -158,10 +156,9 @@ public: static void drawGrid(vcl::RenderContext& rRenderContext, int nWidth, int nHeight) { tools::Rectangle aRectangle; - size_t index = 0; std::vector<tools::Rectangle> aRegions = setupRegions(1, 1, nWidth, nHeight); - aRectangle = aRegions[index++]; + aRectangle = aRegions[0]; Benchmark aOutDevTest; Bitmap aBitmap = aOutDevTest.setupGrid(); drawBitmapScaledAndCentered(aRectangle, aBitmap, rRenderContext); @@ -171,10 +168,9 @@ public: static void drawGridWithDottedLines(vcl::RenderContext& rRenderContext, int nWidth, int nHeight) { tools::Rectangle aRectangle; - size_t index = 0; std::vector<tools::Rectangle> aRegions = setupRegions(1, 1, nWidth, nHeight); - aRectangle = aRegions[index++]; + aRectangle = aRegions[0]; Benchmark aOutDevTest; Bitmap aBitmap = aOutDevTest.setupGridWithDottedLine(); drawBitmapScaledAndCentered(aRectangle, aBitmap, rRenderContext); @@ -183,10 +179,9 @@ public: static void drawBitmap(vcl::RenderContext& rRenderContext, int nWidth, int nHeight) { tools::Rectangle aRectangle; - size_t index = 0; std::vector<tools::Rectangle> aRegions = setupRegions(1, 1, nWidth, nHeight); - aRectangle = aRegions[index++]; + aRectangle = aRegions[0]; Benchmark aOutDevTest; Bitmap aBitmap = aOutDevTest.setupBitmap(); drawBitmapScaledAndCentered(aRectangle, aBitmap, rRenderContext); @@ -196,10 +191,9 @@ public: static void drawBitmapWithAlpha(vcl::RenderContext& rRenderContext, int nWidth, int nHeight) { tools::Rectangle aRectangle; - size_t index = 0; std::vector<tools::Rectangle> aRegions = setupRegions(1, 1, nWidth, nHeight); - aRectangle = aRegions[index++]; + aRectangle = aRegions[0]; Benchmark aOutDevTest; Bitmap aBitmap = aOutDevTest.setupBitmapWithAlpha(); drawBitmapScaledAndCentered(aRectangle, aBitmap, rRenderContext); @@ -209,10 +203,9 @@ public: static void drawScaledBitmap(vcl::RenderContext& rRenderContext, int nWidth, int nHeight) { tools::Rectangle aRectangle; - size_t index = 0; std::vector<tools::Rectangle> aRegions = setupRegions(1, 1, nWidth, nHeight); - aRectangle = aRegions[index++]; + aRectangle = aRegions[0]; Benchmark aOutDevTest; Bitmap aBitmap = aOutDevTest.setupScaledBitmap(); drawBitmapScaledAndCentered(aRectangle, aBitmap, rRenderContext); @@ -222,10 +215,9 @@ public: static void drawReducedBitmap(vcl::RenderContext& rRenderContext, int nWidth, int nHeight) { tools::Rectangle aRectangle; - size_t index = 0; std::vector<tools::Rectangle> aRegions = setupRegions(1, 1, nWidth, nHeight); - aRectangle = aRegions[index++]; + aRectangle = aRegions[0]; Benchmark aOutDevTest; Bitmap aBitmap = aOutDevTest.setupReducedBitmap(); drawBitmapScaledAndCentered(aRectangle, aBitmap, rRenderContext); @@ -235,16 +227,51 @@ public: static void drawRotatedBitmap(vcl::RenderContext& rRenderContext, int nWidth, int nHeight) { tools::Rectangle aRectangle; - size_t index = 0; std::vector<tools::Rectangle> aRegions = setupRegions(1, 1, nWidth, nHeight); - aRectangle = aRegions[index++]; + aRectangle = aRegions[0]; Benchmark aOutDevTest; Bitmap aBitmap = aOutDevTest.setupRotatedBitmap(); drawBitmapScaledAndCentered(aRectangle, aBitmap, rRenderContext); updateResults(rRenderContext, aOutDevTest.getElapsedTime()); } + static void drawLinearGradient(vcl::RenderContext& rRenderContext, int nWidth, int nHeight) + { + tools::Rectangle aRectangle; + + std::vector<tools::Rectangle> aRegions = setupRegions(1, 1, nWidth, nHeight); + aRectangle = aRegions[0]; + Benchmark aOutDevTest; + Bitmap aBitmap = aOutDevTest.setupLinearGradient(); + drawBitmapScaledAndCentered(aRectangle, aBitmap, rRenderContext); + updateResults(rRenderContext, aOutDevTest.getElapsedTime()); + } + + static void drawAxialGradient(vcl::RenderContext& rRenderContext, int nWidth, int nHeight) + { + tools::Rectangle aRectangle; + + std::vector<tools::Rectangle> aRegions = setupRegions(1, 1, nWidth, nHeight); + aRectangle = aRegions[0]; + Benchmark aOutDevTest; + Bitmap aBitmap = aOutDevTest.setupAxialGradient(); + drawBitmapScaledAndCentered(aRectangle, aBitmap, rRenderContext); + updateResults(rRenderContext, aOutDevTest.getElapsedTime()); + } + + static void drawRadialGradient(vcl::RenderContext& rRenderContext, int nWidth, int nHeight) + { + tools::Rectangle aRectangle; + + std::vector<tools::Rectangle> aRegions = setupRegions(1, 1, nWidth, nHeight); + aRectangle = aRegions[0]; + Benchmark aOutDevTest; + Bitmap aBitmap = aOutDevTest.setupRadialGradient(); + drawBitmapScaledAndCentered(aRectangle, aBitmap, rRenderContext); + updateResults(rRenderContext, aOutDevTest.getElapsedTime()); + } + virtual void Paint(vcl::RenderContext& rRenderContext, const tools::Rectangle& /*rRect*/) override { @@ -269,27 +296,39 @@ public: } else if (mnTest % gnNumberOfTests == 3) { - drawBitmap(rRenderContext, nWidth, nHeight); + drawGridWithDottedLines(rRenderContext, nWidth, nHeight); } else if (mnTest % gnNumberOfTests == 4) { - drawBitmapWithAlpha(rRenderContext, nWidth, nHeight); + drawBitmap(rRenderContext, nWidth, nHeight); } else if (mnTest % gnNumberOfTests == 5) { - drawScaledBitmap(rRenderContext, nWidth, nHeight); + drawBitmapWithAlpha(rRenderContext, nWidth, nHeight); } else if (mnTest % gnNumberOfTests == 6) { - drawReducedBitmap(rRenderContext, nWidth, nHeight); + drawScaledBitmap(rRenderContext, nWidth, nHeight); } else if (mnTest % gnNumberOfTests == 7) { - drawRotatedBitmap(rRenderContext, nWidth, nHeight); + drawReducedBitmap(rRenderContext, nWidth, nHeight); } else if (mnTest % gnNumberOfTests == 8) { - drawGridWithDottedLines(rRenderContext, nWidth, nHeight); + drawRotatedBitmap(rRenderContext, nWidth, nHeight); + } + else if (mnTest % gnNumberOfTests == 9) + { + drawLinearGradient(rRenderContext, nWidth, nHeight); + } + else if (mnTest % gnNumberOfTests == 10) + { + drawAxialGradient(rRenderContext, nWidth, nHeight); + } + else if (mnTest % gnNumberOfTests == 11) + { + drawRadialGradient(rRenderContext, nWidth, nHeight); } } }; diff --git a/vcl/backendtest/benchmark/outputdevice/Benchmarks.cxx b/vcl/backendtest/benchmark/outputdevice/Benchmarks.cxx index db3c8649085d..d7cf1cdeb345 100644 --- a/vcl/backendtest/benchmark/outputdevice/Benchmarks.cxx +++ b/vcl/backendtest/benchmark/outputdevice/Benchmarks.cxx @@ -14,6 +14,8 @@ #include <vcl/bitmapex.hxx> #include <bitmap/BitmapWriteAccess.hxx> +#include <vector> + const Color Benchmark::constBackgroundColor(COL_LIGHTGRAY); const Color Benchmark::constLineColor(COL_LIGHTBLUE); const Color Benchmark::constFillColor(COL_BLUE); @@ -33,6 +35,35 @@ sal_Int64 Benchmark::getElapsedTime() return std::chrono::duration_cast<std::chrono::milliseconds>(m_xEnd - m_xStart).count(); } +Bitmap Benchmark::setupMultiplePolygonsWithPolyPolygon() +{ + initialSetup(4096, 4096, constBackgroundColor); + + mpVirtualDevice->SetLineColor(constLineColor); + mpVirtualDevice->SetFillColor(); + + tools::PolyPolygon aPolyPolygon(4); + + for (int nOffset = 1; nOffset <= 4096; nOffset += 4) + { + tools::Polygon aPolygon1(4); + aPolygon1.SetPoint(Point(maVDRectangle.Left() + nOffset, maVDRectangle.Top() + nOffset), 0); + aPolygon1.SetPoint(Point(maVDRectangle.Right() - nOffset, maVDRectangle.Top() + nOffset), + 1); + aPolygon1.SetPoint(Point(maVDRectangle.Right() - nOffset, maVDRectangle.Bottom() - nOffset), + 2); + aPolygon1.SetPoint(Point(maVDRectangle.Left() + nOffset, maVDRectangle.Bottom() - nOffset), + 3); + aPolyPolygon.Insert(aPolygon1); + } + + m_xStart = std::chrono::steady_clock::now(); + mpVirtualDevice->DrawPolyPolygon(aPolyPolygon); + Bitmap aBitmap = mpVirtualDevice->GetBitmap(maVDRectangle.TopLeft(), maVDRectangle.GetSize()); + m_xEnd = std::chrono::steady_clock::now(); + return aBitmap; +} + Bitmap Benchmark::setupWavelines() { initialSetup(4096, 4096, constBackgroundColor); @@ -127,6 +158,9 @@ Bitmap Benchmark::setupBitmap() } Bitmap Benchmark::setupBitmapWithAlpha() +{ + initialSetup(4096, 4096, constBackgroundColor); + Size aBitmapSize(4095, 4095); Bitmap aBitmap(aBitmapSize, vcl::PixelFormat::N24_BPP); @@ -139,7 +173,7 @@ Bitmap Benchmark::setupBitmapWithAlpha() rWriteAccess->Erase(COL_WHITE); rWriteAccess->SetLineColor(Color(0x44, 0x44, 0x44)); - for (int i = 1; i < 4095; i += 4) + for (int i = 1; i + 4 <= 4095; i += 4) { aWriteAccess->DrawRect(tools::Rectangle(i, i, 4095 - i, 4095 - i)); aWriteAccess->DrawRect(tools::Rectangle(i + 1, i + 1, 4095 - i - 1, 4095 - i - 1)); @@ -155,7 +189,6 @@ Bitmap Benchmark::setupBitmapWithAlpha() mpVirtualDevice->DrawBitmapEx(tools::Rectangle(aPoint, aRect.GetSize()).TopLeft(), BitmapEx(aBitmap, aAlpha)); - Bitmap rBitmap = mpVirtualDevice->GetBitmap(maVDRectangle.TopLeft(), maVDRectangle.GetSize()); m_xEnd = std::chrono::steady_clock::now(); @@ -251,30 +284,96 @@ Bitmap Benchmark::setupRotatedBitmap() return rBitmap; } -Bitmap Benchmark::setupMultiplePolygonsWithPolyPolygon() +Bitmap Benchmark::setupLinearGradient() { initialSetup(4096, 4096, constBackgroundColor); - mpVirtualDevice->SetLineColor(constLineColor); - mpVirtualDevice->SetFillColor(); + std::vector<std::pair<Color, Color>> aGradients + = { { Color(0x0, 0x9F, 0xFF), Color(0xEC, 0x2F, 0x4B) }, + { Color(0x12, 0xC2, 0xE9), Color(0xC4, 0x71, 0xED) }, + { Color(0xFF, 0x0, 0x99), Color(0x49, 0x32, 0x40) }, + { Color(0xF1, 0x27, 0x11), Color(0xF5, 0xAF, 0x19) }, + { Color(0x83, 0x60, 0xC3), Color(0x2E, 0xBF, 0x91) }, + { Color(0x0, 0x9F, 0xFF), Color(0xEC, 0x2F, 0x4B) }, + { Color(0x65, 0x4E, 0xA3), Color(0xEA, 0xAF, 0xC8) }, + { Color(0xFF, 0x41, 0x6C), Color(0xFF, 0x4B, 0x2B) } }; - tools::PolyPolygon aPolyPolygon(4); + m_xStart = std::chrono::steady_clock::now(); + for (int i = 0, nLeftOffset = 0, nRightOffset = 3840; i < 16; + i++, nLeftOffset += 256, nRightOffset -= 256) + { + Gradient aGradient(GradientStyle::Linear, aGradients[i % 8].first, + aGradients[i % 8].second); + aGradient.SetAngle(900_deg10); + aGradient.SetBorder(50); + tools::Rectangle aDrawRect(maVDRectangle.Left() + nLeftOffset, maVDRectangle.Top() + 1, + maVDRectangle.Right() - nRightOffset, + maVDRectangle.Bottom() - 1); + mpVirtualDevice->DrawGradient(aDrawRect, aGradient); + } + Bitmap aBitmap = mpVirtualDevice->GetBitmap(maVDRectangle.TopLeft(), maVDRectangle.GetSize()); + m_xEnd = std::chrono::steady_clock::now(); + return aBitmap; +} - for (int nOffset = 1; nOffset <= 4096; nOffset += 4) +Bitmap Benchmark::setupAxialGradient() +{ + initialSetup(4096, 4096, constBackgroundColor); + + std::vector<std::pair<Color, Color>> aGradients + = { { Color(0x0, 0x9F, 0xFF), Color(0xEC, 0x2F, 0x4B) }, + { Color(0x12, 0xC2, 0xE9), Color(0xC4, 0x71, 0xED) }, + { Color(0xFF, 0x0, 0x99), Color(0x49, 0x32, 0x40) }, + { Color(0xF1, 0x27, 0x11), Color(0xF5, 0xAF, 0x19) }, + { Color(0x83, 0x60, 0xC3), Color(0x2E, 0xBF, 0x91) }, + { Color(0x0, 0x9F, 0xFF), Color(0xEC, 0x2F, 0x4B) }, + { Color(0x65, 0x4E, 0xA3), Color(0xEA, 0xAF, 0xC8) }, + { Color(0xFF, 0x41, 0x6C), Color(0xFF, 0x4B, 0x2B) } }; + + m_xStart = std::chrono::steady_clock::now(); + for (int i = 0, nLeftOffset = 0, nRightOffset = 3840; i < 16; + i++, nLeftOffset += 256, nRightOffset -= 256) { - tools::Polygon aPolygon1(4); - aPolygon1.SetPoint(Point(maVDRectangle.Left() + nOffset, maVDRectangle.Top() + nOffset), 0); - aPolygon1.SetPoint(Point(maVDRectangle.Right() - nOffset, maVDRectangle.Top() + nOffset), - 1); - aPolygon1.SetPoint(Point(maVDRectangle.Right() - nOffset, maVDRectangle.Bottom() - nOffset), - 2); - aPolygon1.SetPoint(Point(maVDRectangle.Left() + nOffset, maVDRectangle.Bottom() - nOffset), - 3); - aPolyPolygon.Insert(aPolygon1); + Gradient aGradient(GradientStyle::Axial, aGradients[i % 8].first, aGradients[i % 8].second); + aGradient.SetAngle(900_deg10); + aGradient.SetBorder(50); + tools::Rectangle aDrawRect(maVDRectangle.Left() + nLeftOffset, maVDRectangle.Top() + 1, + maVDRectangle.Right() - nRightOffset, + maVDRectangle.Bottom() - 1); + mpVirtualDevice->DrawGradient(aDrawRect, aGradient); } + Bitmap aBitmap = mpVirtualDevice->GetBitmap(maVDRectangle.TopLeft(), maVDRectangle.GetSize()); + m_xEnd = std::chrono::steady_clock::now(); + return aBitmap; +} + +Bitmap Benchmark::setupRadialGradient() +{ + initialSetup(4096, 4096, constBackgroundColor); + + std::vector<std::pair<Color, Color>> aGradients + = { { Color(0x0, 0x9F, 0xFF), Color(0xEC, 0x2F, 0x4B) }, + { Color(0x12, 0xC2, 0xE9), Color(0xC4, 0x71, 0xED) }, + { Color(0xFF, 0x0, 0x99), Color(0x49, 0x32, 0x40) }, + { Color(0xF1, 0x27, 0x11), Color(0xF5, 0xAF, 0x19) }, + { Color(0x83, 0x60, 0xC3), Color(0x2E, 0xBF, 0x91) }, + { Color(0x0, 0x9F, 0xFF), Color(0xEC, 0x2F, 0x4B) }, + { Color(0x65, 0x4E, 0xA3), Color(0xEA, 0xAF, 0xC8) }, + { Color(0xFF, 0x41, 0x6C), Color(0xFF, 0x4B, 0x2B) } }; m_xStart = std::chrono::steady_clock::now(); - mpVirtualDevice->DrawPolyPolygon(aPolyPolygon); + for (int i = 0, nLeftOffset = 0, nRightOffset = 3840; i < 16; + i++, nLeftOffset += 256, nRightOffset -= 256) + { + Gradient aGradient(GradientStyle::Radial, aGradients[i % 8].first, + aGradients[i % 8].second); + aGradient.SetAngle(900_deg10); + aGradient.SetBorder(50); + tools::Rectangle aDrawRect(maVDRectangle.Left() + nLeftOffset, maVDRectangle.Top() + 1, + maVDRectangle.Right() - nRightOffset, + maVDRectangle.Bottom() - 1); + mpVirtualDevice->DrawGradient(aDrawRect, aGradient); + } Bitmap aBitmap = mpVirtualDevice->GetBitmap(maVDRectangle.TopLeft(), maVDRectangle.GetSize()); m_xEnd = std::chrono::steady_clock::now(); return aBitmap; diff --git a/vcl/inc/test/Benchmarks.hxx b/vcl/inc/test/Benchmarks.hxx index 2a11f7613908..193515688b9f 100644 --- a/vcl/inc/test/Benchmarks.hxx +++ b/vcl/inc/test/Benchmarks.hxx @@ -29,6 +29,7 @@ class VCL_DLLPUBLIC Benchmark public: sal_Int64 getElapsedTime(); + Bitmap setupMultiplePolygonsWithPolyPolygon(); Bitmap setupWavelines(); Bitmap setupGrid(); Bitmap setupGridWithDottedLine(); @@ -37,5 +38,7 @@ public: Bitmap setupScaledBitmap(); Bitmap setupReducedBitmap(); Bitmap setupRotatedBitmap(); - Bitmap setupMultiplePolygonsWithPolyPolygon(); + Bitmap setupLinearGradient(); + Bitmap setupAxialGradient(); + Bitmap setupRadialGradient(); }; |