Repository.mk                                         |    1 
 include/vcl/outdev.hxx                                |    2 
 vcl/Executable_benchmarktests.mk                      |   41 +
 vcl/Library_vcl.mk                                    |    1 
 vcl/Module_vcl.mk                                     |    5 
 vcl/backendtest/benchmark/BenchmarkApp.cxx            |  395 ++++++++++++++++++
 vcl/backendtest/benchmark/outputdevice/Benchmarks.cxx |  392 +++++++++++++++++
 vcl/inc/headless/SvpGraphicsBackend.hxx               |    2 
 vcl/inc/qt5/QtGraphics.hxx                            |    2 
 vcl/inc/quartz/salgdi.h                               |    2 
 vcl/inc/salgdi.hxx                                    |    7 
 vcl/inc/salgdiimpl.hxx                                |    2 
 vcl/inc/test/Benchmarks.hxx                           |   44 ++
 vcl/inc/unx/GenPspGfxBackend.hxx                      |    2 
 vcl/source/outdev/outdev.cxx                          |    5 
 vcl/unx/generic/gdi/gdiimpl.cxx                       |    5 
 vcl/unx/generic/gdi/gdiimpl.hxx                       |    2 
 vcl/win/gdi/gdiimpl.cxx                               |    5 
 vcl/win/gdi/gdiimpl.hxx                               |    2 
 19 files changed, 913 insertions(+), 4 deletions(-)

New commits:
commit b167059facb2b01de1d0a46777ef3ff01fa61a83
Author:     Akshit Kushwaha <akshitsa...@gmail.com>
AuthorDate: Fri Feb 18 13:14:09 2022 +0530
Commit:     Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk>
CommitDate: Mon Dec 12 17:13:55 2022 +0900

    Introduced the Flush() method for aiding the benchmarks
    
    This Flush() method would help in clearing any and all
    queued drawing calls in order to prevent unnecessary
    time addition to the benchmarks.
    
    Change-Id: Ie4170bc5ebbf5011b6be315daa6a0035ffb3aa24

diff --git a/include/vcl/outdev.hxx b/include/vcl/outdev.hxx
index b2053f412b49..5ad5d5eb7de7 100644
--- a/include/vcl/outdev.hxx
+++ b/include/vcl/outdev.hxx
@@ -426,7 +426,7 @@ public:
     ///@{
 
 public:
-    virtual void                Flush() {}
+    virtual void                Flush();
 
     virtual void                DrawOutDev(
                                     const Point& rDestPt, const Size& 
rDestSize,
diff --git a/vcl/backendtest/benchmark/outputdevice/Benchmarks.cxx 
b/vcl/backendtest/benchmark/outputdevice/Benchmarks.cxx
index d7cf1cdeb345..94e50a8865a3 100644
--- a/vcl/backendtest/benchmark/outputdevice/Benchmarks.cxx
+++ b/vcl/backendtest/benchmark/outputdevice/Benchmarks.cxx
@@ -57,6 +57,7 @@ Bitmap Benchmark::setupMultiplePolygonsWithPolyPolygon()
         aPolyPolygon.Insert(aPolygon1);
     }
 
+    mpVirtualDevice->Flush();
     m_xStart = std::chrono::steady_clock::now();
     mpVirtualDevice->DrawPolyPolygon(aPolyPolygon);
     Bitmap aBitmap = mpVirtualDevice->GetBitmap(maVDRectangle.TopLeft(), 
maVDRectangle.GetSize());
@@ -71,6 +72,7 @@ Bitmap Benchmark::setupWavelines()
     mpVirtualDevice->SetLineColor(constLineColor);
     mpVirtualDevice->SetFillColor();
 
+    mpVirtualDevice->Flush();
     m_xStart = std::chrono::steady_clock::now();
     for (int i = 1; i <= 4094; i += 2)
     {
@@ -91,6 +93,7 @@ Bitmap Benchmark::setupGrid()
     mpVirtualDevice->SetLineColor(constLineColor);
     mpVirtualDevice->SetFillColor();
 
+    mpVirtualDevice->Flush();
     m_xStart = std::chrono::steady_clock::now();
     for (int i = 1; i <= 4096; i += 2)
     {
@@ -109,6 +112,7 @@ Bitmap Benchmark::setupGridWithDottedLine()
     mpVirtualDevice->SetLineColor(constLineColor);
     mpVirtualDevice->SetFillColor();
 
+    mpVirtualDevice->Flush();
     m_xStart = std::chrono::steady_clock::now();
     for (int i = 1; i <= 4096; i += 2)
     {
@@ -148,6 +152,7 @@ Bitmap Benchmark::setupBitmap()
     Point aPoint((maVDRectangle.GetWidth() / 2.0) - (aBitmapSize.Width() / 
2.0),
                  (maVDRectangle.GetHeight() / 2.0) - (aBitmapSize.Height() / 
2.0));
 
+    mpVirtualDevice->Flush();
     m_xStart = std::chrono::steady_clock::now();
 
     mpVirtualDevice->DrawBitmapEx(aPoint, BitmapEx(aBitmap));
@@ -185,6 +190,7 @@ Bitmap Benchmark::setupBitmapWithAlpha()
     Point aPoint((maVDRectangle.GetWidth() / 2.0) - (aRect.GetWidth() / 2.0),
                  (maVDRectangle.GetHeight() / 2.0) - (aRect.GetHeight() / 
2.0));
 
+    mpVirtualDevice->Flush();
     m_xStart = std::chrono::steady_clock::now();
 
     mpVirtualDevice->DrawBitmapEx(tools::Rectangle(aPoint, 
aRect.GetSize()).TopLeft(),
@@ -212,6 +218,7 @@ Bitmap Benchmark::setupScaledBitmap()
         aWriteAccess->DrawRect(tools::Rectangle(i + 1, i + 1, 100 - i - 1, 100 
- i - 1));
     }
 
+    mpVirtualDevice->Flush();
     m_xStart = std::chrono::steady_clock::now();
 
     BitmapEx aBitmapEx(aBitmap);
@@ -241,6 +248,7 @@ Bitmap Benchmark::setupReducedBitmap()
         aWriteAccess->DrawRect(tools::Rectangle(i + 1, i + 1, 8096 - i - 1, 
8096 - i - 1));
     }
 
+    mpVirtualDevice->Flush();
     m_xStart = std::chrono::steady_clock::now();
 
     BitmapEx aBitmapEx(aBitmap);
@@ -273,6 +281,7 @@ Bitmap Benchmark::setupRotatedBitmap()
     Point aPoint((maVDRectangle.GetWidth() / 2.0) - (aBitmapSize.Width() / 
2.0),
                  (maVDRectangle.GetHeight() / 2.0) - (aBitmapSize.Height() / 
2.0));
 
+    mpVirtualDevice->Flush();
     m_xStart = std::chrono::steady_clock::now();
 
     BitmapEx aBitmapEx(aBitmap);
@@ -298,6 +307,7 @@ Bitmap Benchmark::setupLinearGradient()
             { Color(0x65, 0x4E, 0xA3), Color(0xEA, 0xAF, 0xC8) },
             { Color(0xFF, 0x41, 0x6C), Color(0xFF, 0x4B, 0x2B) } };
 
+    mpVirtualDevice->Flush();
     m_xStart = std::chrono::steady_clock::now();
     for (int i = 0, nLeftOffset = 0, nRightOffset = 3840; i < 16;
          i++, nLeftOffset += 256, nRightOffset -= 256)
@@ -330,6 +340,7 @@ Bitmap Benchmark::setupAxialGradient()
             { Color(0x65, 0x4E, 0xA3), Color(0xEA, 0xAF, 0xC8) },
             { Color(0xFF, 0x41, 0x6C), Color(0xFF, 0x4B, 0x2B) } };
 
+    mpVirtualDevice->Flush();
     m_xStart = std::chrono::steady_clock::now();
     for (int i = 0, nLeftOffset = 0, nRightOffset = 3840; i < 16;
          i++, nLeftOffset += 256, nRightOffset -= 256)
@@ -361,6 +372,7 @@ Bitmap Benchmark::setupRadialGradient()
             { Color(0x65, 0x4E, 0xA3), Color(0xEA, 0xAF, 0xC8) },
             { Color(0xFF, 0x41, 0x6C), Color(0xFF, 0x4B, 0x2B) } };
 
+    mpVirtualDevice->Flush();
     m_xStart = std::chrono::steady_clock::now();
     for (int i = 0, nLeftOffset = 0, nRightOffset = 3840; i < 16;
          i++, nLeftOffset += 256, nRightOffset -= 256)
diff --git a/vcl/inc/headless/SvpGraphicsBackend.hxx 
b/vcl/inc/headless/SvpGraphicsBackend.hxx
index 997f1bc84e9d..246bd766493e 100644
--- a/vcl/inc/headless/SvpGraphicsBackend.hxx
+++ b/vcl/inc/headless/SvpGraphicsBackend.hxx
@@ -47,6 +47,8 @@ public:
 
     tools::Long GetGraphicsWidth() const override;
 
+    void Flush() override {}
+
     void SetLineColor() override;
     void SetLineColor(Color nColor) override;
     void SetFillColor() override;
diff --git a/vcl/inc/qt5/QtGraphics.hxx b/vcl/inc/qt5/QtGraphics.hxx
index b8a168d1a3cf..ea88b8b60db8 100644
--- a/vcl/inc/qt5/QtGraphics.hxx
+++ b/vcl/inc/qt5/QtGraphics.hxx
@@ -58,6 +58,8 @@ public:
     QtGraphicsBackend(QtFrame* pFrame, QImage* pQImage);
     ~QtGraphicsBackend() override;
 
+    void Flush() override {};
+
     void Init() override {}
 
     QImage* getQImage() { return m_pQImage; }
diff --git a/vcl/inc/quartz/salgdi.h b/vcl/inc/quartz/salgdi.h
index 9e070c4215ce..4d4ffb25725a 100644
--- a/vcl/inc/quartz/salgdi.h
+++ b/vcl/inc/quartz/salgdi.h
@@ -331,6 +331,8 @@ public:
     AquaGraphicsBackend(AquaSharedAttributes & rShared);
     ~AquaGraphicsBackend() override;
 
+    void Flush() override {};
+
     void Init() override;
 
     void freeResources() override;
diff --git a/vcl/inc/salgdi.hxx b/vcl/inc/salgdi.hxx
index 0b8952b74123..a7f5dc6080b9 100644
--- a/vcl/inc/salgdi.hxx
+++ b/vcl/inc/salgdi.hxx
@@ -96,6 +96,8 @@ public:
 
     // public SalGraphics methods, the interface to the independent vcl part
 
+    virtual void Flush() = 0;
+
     // get device resolution
     virtual void                GetResolution( sal_Int32& rDPIX, sal_Int32& 
rDPIY ) = 0;
 
@@ -656,6 +658,11 @@ public:
         return GetImpl()->GetGraphicsWidth();
     }
 
+    void Flush() override
+    {
+        GetImpl()->Flush();
+    }
+
     void ResetClipRegion() override
     {
         GetImpl()->ResetClipRegion();
diff --git a/vcl/inc/salgdiimpl.hxx b/vcl/inc/salgdiimpl.hxx
index 55f7544587ed..dc5cb315a554 100644
--- a/vcl/inc/salgdiimpl.hxx
+++ b/vcl/inc/salgdiimpl.hxx
@@ -88,6 +88,8 @@ public:
 
     virtual void ResetClipRegion() = 0;
 
+    virtual void Flush() = 0;
+
     virtual void SetLineColor() = 0;
 
     virtual void SetLineColor( Color nColor ) = 0;
diff --git a/vcl/inc/unx/GenPspGfxBackend.hxx b/vcl/inc/unx/GenPspGfxBackend.hxx
index a37ee433e6eb..600606845007 100644
--- a/vcl/inc/unx/GenPspGfxBackend.hxx
+++ b/vcl/inc/unx/GenPspGfxBackend.hxx
@@ -26,6 +26,8 @@ public:
     GenPspGfxBackend(psp::PrinterGfx* pPrinterGfx);
     ~GenPspGfxBackend() override;
 
+    void Flush() override {}
+
     void Init() override;
     void freeResources() override;
     OUString getRenderBackendName() const override { return "genpsp"; }
diff --git a/vcl/source/outdev/outdev.cxx b/vcl/source/outdev/outdev.cxx
index b4c1eac4499e..3c8cea776722 100644
--- a/vcl/source/outdev/outdev.cxx
+++ b/vcl/source/outdev/outdev.cxx
@@ -141,6 +141,11 @@ OutputDevice::~OutputDevice()
     disposeOnce();
 }
 
+void OutputDevice::Flush()
+{
+    mpGraphics->Flush();
+}
+
 void OutputDevice::dispose()
 {
     if ( GetUnoGraphicsList() )
diff --git a/vcl/unx/generic/gdi/gdiimpl.cxx b/vcl/unx/generic/gdi/gdiimpl.cxx
index ad28e0fb39a9..19b545795c95 100644
--- a/vcl/unx/generic/gdi/gdiimpl.cxx
+++ b/vcl/unx/generic/gdi/gdiimpl.cxx
@@ -946,6 +946,11 @@ void X11SalGraphicsImpl::ResetClipRegion()
     mrParent.mpClipRegion    = nullptr;
 }
 
+void X11SalGraphicsImpl::Flush()
+{
+    mrParent.Flush();
+}
+
 bool X11SalGraphicsImpl::setClipRegion( const vcl::Region& i_rClip )
 {
     if( mrParent.mpClipRegion )
diff --git a/vcl/unx/generic/gdi/gdiimpl.hxx b/vcl/unx/generic/gdi/gdiimpl.hxx
index 48211b13d472..ac59a4cf5983 100644
--- a/vcl/unx/generic/gdi/gdiimpl.hxx
+++ b/vcl/unx/generic/gdi/gdiimpl.hxx
@@ -111,6 +111,8 @@ public:
 
     virtual ~X11SalGraphicsImpl() override;
 
+    void Flush() override;
+
     virtual OUString getRenderBackendName() const override { return "gen"; }
 
     virtual bool setClipRegion( const vcl::Region& ) override;
diff --git a/vcl/win/gdi/gdiimpl.cxx b/vcl/win/gdi/gdiimpl.cxx
index 81d41cf41d33..4ae3383fb95f 100644
--- a/vcl/win/gdi/gdiimpl.cxx
+++ b/vcl/win/gdi/gdiimpl.cxx
@@ -1032,6 +1032,11 @@ static bool containsOnlyHorizontalAndVerticalEdges(const 
basegfx::B2DPolyPolygon
     return true;
 }
 
+void WinSalGraphicsImpl::Flush()
+{
+    mrParent.Flush();
+}
+
 bool WinSalGraphicsImpl::setClipRegion( const vcl::Region& i_rClip )
 {
     if ( mrParent.mhRegion )
diff --git a/vcl/win/gdi/gdiimpl.hxx b/vcl/win/gdi/gdiimpl.hxx
index 86342533fc6c..3728244deb0e 100644
--- a/vcl/win/gdi/gdiimpl.hxx
+++ b/vcl/win/gdi/gdiimpl.hxx
@@ -66,6 +66,8 @@ public:
 
     virtual ~WinSalGraphicsImpl() override;
 
+    void Flush() override;
+
     virtual void Init() override;
 
     virtual void freeResources() override;
commit 998c7c9d4d65d2262003e4a4d49b1ded46ccb463
Author:     homeboy445 <akshitsa...@gmail.com>
AuthorDate: Wed Oct 20 21:29:48 2021 +0530
Commit:     Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk>
CommitDate: Mon Dec 12 17:13:35 2022 +0900

    benchmark: Draw Gradient
    
    This patch includes the method for checking the duration of
    drawing of gradient for benchmarking.
    
    Change-Id: I741bb07a1c2ac6e3c8a643c93be9d1a8afef5ccb

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();
 };
commit 1ce100df8615738275894b0cd834515fd82ea6ef
Author:     homeboy445 <akshitsa...@gmail.com>
AuthorDate: Tue Oct 12 17:58:32 2021 +0530
Commit:     Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk>
CommitDate: Mon Dec 12 17:13:17 2022 +0900

    benchmark: Drawing Bitmap
    
    This patch includes the method for checking the duration of
    drawing of a Bitmap for benchmarking.
    
    Change-Id: I6a2f30add99d7e0be8f30921c62040b58e8d998c

diff --git a/vcl/backendtest/benchmark/BenchmarkApp.cxx 
b/vcl/backendtest/benchmark/BenchmarkApp.cxx
index 90c6429a57e9..dcd32df8150f 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 = 4;
+    static constexpr unsigned char gnNumberOfTests = 9;
     unsigned char mnTest;
     ScopedVclPtr<VirtualDevice> mpVDev;
 
@@ -180,6 +180,70 @@ public:
         drawBitmapScaledAndCentered(aRectangle, aBitmap, rRenderContext);
         updateResults(rRenderContext, aOutDevTest.getElapsedTime());
     }
+    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++];
+        Benchmark aOutDevTest;
+        Bitmap aBitmap = aOutDevTest.setupBitmap();
+        drawBitmapScaledAndCentered(aRectangle, aBitmap, rRenderContext);
+        updateResults(rRenderContext, aOutDevTest.getElapsedTime());
+    }
+
+    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++];
+        Benchmark aOutDevTest;
+        Bitmap aBitmap = aOutDevTest.setupBitmapWithAlpha();
+        drawBitmapScaledAndCentered(aRectangle, aBitmap, rRenderContext);
+        updateResults(rRenderContext, aOutDevTest.getElapsedTime());
+    }
+
+    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++];
+        Benchmark aOutDevTest;
+        Bitmap aBitmap = aOutDevTest.setupScaledBitmap();
+        drawBitmapScaledAndCentered(aRectangle, aBitmap, rRenderContext);
+        updateResults(rRenderContext, aOutDevTest.getElapsedTime());
+    }
+
+    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++];
+        Benchmark aOutDevTest;
+        Bitmap aBitmap = aOutDevTest.setupReducedBitmap();
+        drawBitmapScaledAndCentered(aRectangle, aBitmap, rRenderContext);
+        updateResults(rRenderContext, aOutDevTest.getElapsedTime());
+    }
+
+    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++];
+        Benchmark aOutDevTest;
+        Bitmap aBitmap = aOutDevTest.setupRotatedBitmap();
+        drawBitmapScaledAndCentered(aRectangle, aBitmap, rRenderContext);
+        updateResults(rRenderContext, aOutDevTest.getElapsedTime());
+    }
 
     virtual void Paint(vcl::RenderContext& rRenderContext,
                        const tools::Rectangle& /*rRect*/) override
@@ -204,6 +268,26 @@ public:
             drawGrid(rRenderContext, nWidth, nHeight);
         }
         else if (mnTest % gnNumberOfTests == 3)
+        {
+            drawBitmap(rRenderContext, nWidth, nHeight);
+        }
+        else if (mnTest % gnNumberOfTests == 4)
+        {
+            drawBitmapWithAlpha(rRenderContext, nWidth, nHeight);
+        }
+        else if (mnTest % gnNumberOfTests == 5)
+        {
+            drawScaledBitmap(rRenderContext, nWidth, nHeight);
+        }
+        else if (mnTest % gnNumberOfTests == 6)
+        {
+            drawReducedBitmap(rRenderContext, nWidth, nHeight);
+        }
+        else if (mnTest % gnNumberOfTests == 7)
+        {
+            drawRotatedBitmap(rRenderContext, nWidth, nHeight);
+        }
+        else if (mnTest % gnNumberOfTests == 8)
         {
             drawGridWithDottedLines(rRenderContext, nWidth, nHeight);
         }
diff --git a/vcl/backendtest/benchmark/outputdevice/Benchmarks.cxx 
b/vcl/backendtest/benchmark/outputdevice/Benchmarks.cxx
index d4d0dd73900f..db3c8649085d 100644
--- a/vcl/backendtest/benchmark/outputdevice/Benchmarks.cxx
+++ b/vcl/backendtest/benchmark/outputdevice/Benchmarks.cxx
@@ -11,6 +11,8 @@
 #include <test/Benchmarks.hxx>
 #include <basegfx/polygon/WaveLine.hxx>
 #include <vcl/lineinfo.hxx>
+#include <vcl/bitmapex.hxx>
+#include <bitmap/BitmapWriteAccess.hxx>
 
 const Color Benchmark::constBackgroundColor(COL_LIGHTGRAY);
 const Color Benchmark::constLineColor(COL_LIGHTBLUE);
@@ -95,6 +97,160 @@ Bitmap Benchmark::setupGridWithDottedLine()
     return aBitmap;
 }
 
+Bitmap Benchmark::setupBitmap()
+{
+    initialSetup(4096, 4096, constBackgroundColor);
+
+    Size aBitmapSize(4095, 4095);
+    Bitmap aBitmap(aBitmapSize, vcl::PixelFormat::N24_BPP);
+
+    BitmapScopedWriteAccess aWriteAccess(aBitmap);
+    aWriteAccess->Erase(constFillColor);
+    aWriteAccess->SetLineColor(constLineColor);
+
+    for (int i = 1; i < 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));
+    }
+
+    Point aPoint((maVDRectangle.GetWidth() / 2.0) - (aBitmapSize.Width() / 
2.0),
+                 (maVDRectangle.GetHeight() / 2.0) - (aBitmapSize.Height() / 
2.0));
+
+    m_xStart = std::chrono::steady_clock::now();
+
+    mpVirtualDevice->DrawBitmapEx(aPoint, BitmapEx(aBitmap));
+    Bitmap rBitmap = mpVirtualDevice->GetBitmap(maVDRectangle.TopLeft(), 
maVDRectangle.GetSize());
+
+    m_xEnd = std::chrono::steady_clock::now();
+    return rBitmap;
+}
+
+Bitmap Benchmark::setupBitmapWithAlpha()
+    Size aBitmapSize(4095, 4095);
+    Bitmap aBitmap(aBitmapSize, vcl::PixelFormat::N24_BPP);
+
+    BitmapScopedWriteAccess aWriteAccess(aBitmap);
+    aWriteAccess->Erase(constFillColor);
+    aWriteAccess->SetLineColor(Color(0xFF, 0xFF, 0x00));
+
+    AlphaMask aAlpha(aBitmapSize);
+    AlphaScopedWriteAccess rWriteAccess(aAlpha);
+    rWriteAccess->Erase(COL_WHITE);
+    rWriteAccess->SetLineColor(Color(0x44, 0x44, 0x44));
+
+    for (int i = 1; i < 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));
+        rWriteAccess->DrawRect(tools::Rectangle(i, i, 4095 - i, 4095 - i));
+        rWriteAccess->DrawRect(tools::Rectangle(i + 1, i + 1, 4095 - i - 1, 
4095 - i - 1));
+    }
+
+    tools::Rectangle aRect(Point(), aBitmapSize);
+    Point aPoint((maVDRectangle.GetWidth() / 2.0) - (aRect.GetWidth() / 2.0),
+                 (maVDRectangle.GetHeight() / 2.0) - (aRect.GetHeight() / 
2.0));
+
+    m_xStart = std::chrono::steady_clock::now();
+
+    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();
+    return rBitmap;
+}
+
+Bitmap Benchmark::setupScaledBitmap()
+{
+    initialSetup(4096, 4096, constBackgroundColor);
+
+    Size aBitmapSize(100, 100);
+    Bitmap aBitmap(aBitmapSize, vcl::PixelFormat::N24_BPP);
+
+    BitmapScopedWriteAccess aWriteAccess(aBitmap);
+    aWriteAccess->Erase(constFillColor);
+    aWriteAccess->SetLineColor(constLineColor);
+
+    for (int i = 1; i + 4 <= 100; i += 4)
+    {
+        aWriteAccess->DrawRect(tools::Rectangle(i, i, 100 - i, 100 - i));
+        aWriteAccess->DrawRect(tools::Rectangle(i + 1, i + 1, 100 - i - 1, 100 
- i - 1));
+    }
+
+    m_xStart = std::chrono::steady_clock::now();
+
+    BitmapEx aBitmapEx(aBitmap);
+    aBitmapEx.Scale(Size(4095, 4095), BmpScaleFlag::Fast);
+
+    mpVirtualDevice->DrawBitmapEx(Point(0, 0), aBitmapEx);
+    Bitmap rBitmap = mpVirtualDevice->GetBitmap(maVDRectangle.TopLeft(), 
maVDRectangle.GetSize());
+
+    m_xEnd = std::chrono::steady_clock::now();
+    return rBitmap;
+}
+
+Bitmap Benchmark::setupReducedBitmap()
+{
+    initialSetup(4096, 4096, constBackgroundColor);
+
+    Size aBitmapSize(8096, 8096);
+    Bitmap aBitmap(aBitmapSize, vcl::PixelFormat::N24_BPP);
+
+    BitmapScopedWriteAccess aWriteAccess(aBitmap);
+    aWriteAccess->Erase(constFillColor);
+    aWriteAccess->SetLineColor(constLineColor);
+
+    for (int i = 1; i + 4 <= 8096; i += 4)
+    {
+        aWriteAccess->DrawRect(tools::Rectangle(i, i, 8096 - i, 8096 - i));
+        aWriteAccess->DrawRect(tools::Rectangle(i + 1, i + 1, 8096 - i - 1, 
8096 - i - 1));
+    }
+
+    m_xStart = std::chrono::steady_clock::now();
+
+    BitmapEx aBitmapEx(aBitmap);
+    aBitmapEx.Scale(Size(4095, 4095), BmpScaleFlag::Fast);
+
+    mpVirtualDevice->DrawBitmapEx(Point(0, 0), aBitmapEx);
+    Bitmap rBitmap = mpVirtualDevice->GetBitmap(maVDRectangle.TopLeft(), 
maVDRectangle.GetSize());
+
+    m_xEnd = std::chrono::steady_clock::now();
+    return rBitmap;
+}
+
+Bitmap Benchmark::setupRotatedBitmap()
+{
+    initialSetup(4096, 4096, constBackgroundColor);
+
+    Size aBitmapSize(4095, 4095);
+    Bitmap aBitmap(aBitmapSize, vcl::PixelFormat::N24_BPP);
+
+    BitmapScopedWriteAccess aWriteAccess(aBitmap);
+    aWriteAccess->Erase(constFillColor);
+    aWriteAccess->SetLineColor(constLineColor);
+
+    for (int i = 1; i < 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));
+    }
+
+    Point aPoint((maVDRectangle.GetWidth() / 2.0) - (aBitmapSize.Width() / 
2.0),
+                 (maVDRectangle.GetHeight() / 2.0) - (aBitmapSize.Height() / 
2.0));
+
+    m_xStart = std::chrono::steady_clock::now();
+
+    BitmapEx aBitmapEx(aBitmap);
+    aBitmapEx.Rotate(Degree10(3600), COL_RED);
+    mpVirtualDevice->DrawBitmapEx(aPoint, aBitmapEx);
+    Bitmap rBitmap = mpVirtualDevice->GetBitmap(maVDRectangle.TopLeft(), 
maVDRectangle.GetSize());
+
+    m_xEnd = std::chrono::steady_clock::now();
+    return rBitmap;
+}
+
 Bitmap Benchmark::setupMultiplePolygonsWithPolyPolygon()
 {
     initialSetup(4096, 4096, constBackgroundColor);
diff --git a/vcl/inc/test/Benchmarks.hxx b/vcl/inc/test/Benchmarks.hxx
index 6f77cf189961..2a11f7613908 100644
--- a/vcl/inc/test/Benchmarks.hxx
+++ b/vcl/inc/test/Benchmarks.hxx
@@ -32,5 +32,10 @@ public:
     Bitmap setupWavelines();
     Bitmap setupGrid();
     Bitmap setupGridWithDottedLine();
+    Bitmap setupBitmap();
+    Bitmap setupBitmapWithAlpha();
+    Bitmap setupScaledBitmap();
+    Bitmap setupReducedBitmap();
+    Bitmap setupRotatedBitmap();
     Bitmap setupMultiplePolygonsWithPolyPolygon();
 };
commit 5c83ec9819df4f6306e81e36d9a779f976b1c0b6
Author:     homeboy445 <akshitsa...@gmail.com>
AuthorDate: Sun Oct 10 17:45:17 2021 +0530
Commit:     Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk>
CommitDate: Mon Dec 12 17:12:57 2022 +0900

    benchmark: Drawing Grid
    
    This patch introduces a method for drawing grid lines
    for benchmarking.
    
    Change-Id: I9f94c83b2f6476bdb896308df2e302daffb11f68

diff --git a/vcl/backendtest/benchmark/BenchmarkApp.cxx 
b/vcl/backendtest/benchmark/BenchmarkApp.cxx
index a0fe63649398..90c6429a57e9 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 = 2;
+    static constexpr unsigned char gnNumberOfTests = 4;
     unsigned char mnTest;
     ScopedVclPtr<VirtualDevice> mpVDev;
 
@@ -155,6 +155,32 @@ public:
         updateResults(rRenderContext, aOutDevTest.getElapsedTime());
     }
 
+    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++];
+        Benchmark aOutDevTest;
+        Bitmap aBitmap = aOutDevTest.setupGrid();
+        drawBitmapScaledAndCentered(aRectangle, aBitmap, rRenderContext);
+        updateResults(rRenderContext, aOutDevTest.getElapsedTime());
+    }
+
+    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++];
+        Benchmark aOutDevTest;
+        Bitmap aBitmap = aOutDevTest.setupGridWithDottedLine();
+        drawBitmapScaledAndCentered(aRectangle, aBitmap, rRenderContext);
+        updateResults(rRenderContext, aOutDevTest.getElapsedTime());
+    }
+
     virtual void Paint(vcl::RenderContext& rRenderContext,
                        const tools::Rectangle& /*rRect*/) override
     {
@@ -173,6 +199,14 @@ public:
         {
             drawWavelines(rRenderContext, nWidth, nHeight);
         }
+        else if (mnTest % gnNumberOfTests == 2)
+        {
+            drawGrid(rRenderContext, nWidth, nHeight);
+        }
+        else if (mnTest % gnNumberOfTests == 3)
+        {
+            drawGridWithDottedLines(rRenderContext, nWidth, nHeight);
+        }
     }
 };
 }
diff --git a/vcl/backendtest/benchmark/outputdevice/Benchmarks.cxx 
b/vcl/backendtest/benchmark/outputdevice/Benchmarks.cxx
index 5ca7ad95419c..d4d0dd73900f 100644
--- a/vcl/backendtest/benchmark/outputdevice/Benchmarks.cxx
+++ b/vcl/backendtest/benchmark/outputdevice/Benchmarks.cxx
@@ -10,6 +10,7 @@
 
 #include <test/Benchmarks.hxx>
 #include <basegfx/polygon/WaveLine.hxx>
+#include <vcl/lineinfo.hxx>
 
 const Color Benchmark::constBackgroundColor(COL_LIGHTGRAY);
 const Color Benchmark::constLineColor(COL_LIGHTBLUE);
@@ -50,6 +51,50 @@ Bitmap Benchmark::setupWavelines()
     return aBitmap;
 }
 
+Bitmap Benchmark::setupGrid()
+{
+    initialSetup(4096, 4096, constBackgroundColor);
+
+    mpVirtualDevice->SetLineColor(constLineColor);
+    mpVirtualDevice->SetFillColor();
+
+    m_xStart = std::chrono::steady_clock::now();
+    for (int i = 1; i <= 4096; i += 2)
+    {
+        mpVirtualDevice->DrawLine(Point(1, i), Point(4096, i));
+        mpVirtualDevice->DrawLine(Point(i, 1), Point(i, 4096));
+    }
+    Bitmap aBitmap = mpVirtualDevice->GetBitmap(maVDRectangle.TopLeft(), 
maVDRectangle.GetSize());
+    m_xEnd = std::chrono::steady_clock::now();
+    return aBitmap;
+}
+
+Bitmap Benchmark::setupGridWithDottedLine()
+{
+    initialSetup(4096, 4096, constBackgroundColor);
+
+    mpVirtualDevice->SetLineColor(constLineColor);
+    mpVirtualDevice->SetFillColor();
+
+    m_xStart = std::chrono::steady_clock::now();
+    for (int i = 1; i <= 4096; i += 2)
+    {
+        LineInfo aLineInfo(LineStyle::Dash, 1);
+        aLineInfo.SetDashCount(10);
+        aLineInfo.SetDashLen(1);
+        aLineInfo.SetDotCount(10);
+        aLineInfo.SetDotLen(1);
+        aLineInfo.SetDistance(1);
+        aLineInfo.SetLineJoin(basegfx::B2DLineJoin::Bevel);
+        aLineInfo.SetLineCap(css::drawing::LineCap_BUTT);
+        mpVirtualDevice->DrawLine(Point(1, i), Point(4096, i), aLineInfo);
+        mpVirtualDevice->DrawLine(Point(i, 1), Point(i, 4096), aLineInfo);
+    }
+    Bitmap aBitmap = mpVirtualDevice->GetBitmap(maVDRectangle.TopLeft(), 
maVDRectangle.GetSize());
+    m_xEnd = std::chrono::steady_clock::now();
+    return aBitmap;
+}
+
 Bitmap Benchmark::setupMultiplePolygonsWithPolyPolygon()
 {
     initialSetup(4096, 4096, constBackgroundColor);
diff --git a/vcl/inc/test/Benchmarks.hxx b/vcl/inc/test/Benchmarks.hxx
index 6e50c0a5d595..6f77cf189961 100644
--- a/vcl/inc/test/Benchmarks.hxx
+++ b/vcl/inc/test/Benchmarks.hxx
@@ -30,5 +30,7 @@ class VCL_DLLPUBLIC Benchmark
 public:
     sal_Int64 getElapsedTime();
     Bitmap setupWavelines();
+    Bitmap setupGrid();
+    Bitmap setupGridWithDottedLine();
     Bitmap setupMultiplePolygonsWithPolyPolygon();
 };
commit 75e2e032445d5fa4a3ccf255c8dc42680fdad641
Author:     homeboy445 <akshitsa...@gmail.com>
AuthorDate: Mon Oct 4 17:09:33 2021 +0530
Commit:     Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk>
CommitDate: Mon Dec 12 17:12:31 2022 +0900

    benchmark: Drawing wavelines
    
    This test includes checking the duration of drawing
    waveline in the graphics backend.
    
    Change-Id: Ia4b08f459a7d512fa60f49e83451e3d5d699ecd5

diff --git a/vcl/backendtest/benchmark/BenchmarkApp.cxx 
b/vcl/backendtest/benchmark/BenchmarkApp.cxx
index b680bed11567..a0fe63649398 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 = 1;
+    static constexpr unsigned char gnNumberOfTests = 2;
     unsigned char mnTest;
     ScopedVclPtr<VirtualDevice> mpVDev;
 
@@ -85,8 +85,6 @@ public:
 
     virtual ~BenchMarkWindow() override { disposeOnce(); }
 
-    DECL_LINK(updateHdl, Timer*, void);
-
     virtual void KeyInput(const KeyEvent& rKEvt) override
     {
         sal_uInt16 nCode = rKEvt.GetKeyCode().GetCode();
@@ -129,7 +127,7 @@ public:
         return aRegions;
     }
 
-    static void testMultiplePolygonsWithPolyPolygon(vcl::RenderContext& 
rRenderContext, int nWidth,
+    static void drawMultiplePolygonsWithPolyPolygon(vcl::RenderContext& 
rRenderContext, int nWidth,
                                                     int nHeight)
     {
         tools::Rectangle aRectangle;
@@ -144,6 +142,19 @@ public:
         updateResults(rRenderContext, aOutDevTest.getElapsedTime());
     }
 
+    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++];
+        Benchmark aOutDevTest;
+        Bitmap aBitmap = aOutDevTest.setupWavelines();
+        drawBitmapScaledAndCentered(aRectangle, aBitmap, rRenderContext);
+        updateResults(rRenderContext, aOutDevTest.getElapsedTime());
+    }
+
     virtual void Paint(vcl::RenderContext& rRenderContext,
                        const tools::Rectangle& /*rRect*/) override
     {
@@ -156,7 +167,11 @@ public:
 
         if (mnTest % gnNumberOfTests == 0)
         {
-            testMultiplePolygonsWithPolyPolygon(rRenderContext, nWidth, 
nHeight);
+            drawMultiplePolygonsWithPolyPolygon(rRenderContext, nWidth, 
nHeight);
+        }
+        else if (mnTest % gnNumberOfTests == 1)
+        {
+            drawWavelines(rRenderContext, nWidth, nHeight);
         }
     }
 };
diff --git a/vcl/backendtest/benchmark/outputdevice/Benchmarks.cxx 
b/vcl/backendtest/benchmark/outputdevice/Benchmarks.cxx
index 025414952b19..5ca7ad95419c 100644
--- a/vcl/backendtest/benchmark/outputdevice/Benchmarks.cxx
+++ b/vcl/backendtest/benchmark/outputdevice/Benchmarks.cxx
@@ -9,6 +9,7 @@
  */
 
 #include <test/Benchmarks.hxx>
+#include <basegfx/polygon/WaveLine.hxx>
 
 const Color Benchmark::constBackgroundColor(COL_LIGHTGRAY);
 const Color Benchmark::constLineColor(COL_LIGHTBLUE);
@@ -29,6 +30,26 @@ sal_Int64 Benchmark::getElapsedTime()
     return std::chrono::duration_cast<std::chrono::milliseconds>(m_xEnd - 
m_xStart).count();
 }
 
+Bitmap Benchmark::setupWavelines()
+{
+    initialSetup(4096, 4096, constBackgroundColor);
+
+    mpVirtualDevice->SetLineColor(constLineColor);
+    mpVirtualDevice->SetFillColor();
+
+    m_xStart = std::chrono::steady_clock::now();
+    for (int i = 1; i <= 4094; i += 2)
+    {
+        const basegfx::B2DRectangle aWaveLineRectangle(1, i, 4096, i + 2);
+        const basegfx::B2DPolygon aWaveLinePolygon
+            = basegfx::createWaveLinePolygon(aWaveLineRectangle);
+        mpVirtualDevice->DrawPolyLine(aWaveLinePolygon);
+    }
+    Bitmap aBitmap = mpVirtualDevice->GetBitmap(maVDRectangle.TopLeft(), 
maVDRectangle.GetSize());
+    m_xEnd = std::chrono::steady_clock::now();
+    return aBitmap;
+}
+
 Bitmap Benchmark::setupMultiplePolygonsWithPolyPolygon()
 {
     initialSetup(4096, 4096, constBackgroundColor);
diff --git a/vcl/inc/test/Benchmarks.hxx b/vcl/inc/test/Benchmarks.hxx
index 088b38093ed5..6e50c0a5d595 100644
--- a/vcl/inc/test/Benchmarks.hxx
+++ b/vcl/inc/test/Benchmarks.hxx
@@ -29,5 +29,6 @@ class VCL_DLLPUBLIC Benchmark
 
 public:
     sal_Int64 getElapsedTime();
+    Bitmap setupWavelines();
     Bitmap setupMultiplePolygonsWithPolyPolygon();
 };
commit 38025a2691daaec974398996f1282ece89ce8e21
Author:     homeboy445 <akshitsa...@gmail.com>
AuthorDate: Thu Sep 30 14:44:48 2021 +0530
Commit:     Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk>
CommitDate: Mon Dec 12 17:11:50 2022 +0900

    Added the executable for running benchmark tests
    
    This executable would come in handy in running the benchmark tests
    of drawing calls.
    
    Change-Id: I3c7cee169ec24cce8b356a4dde0504b6b8ebcfbc

diff --git a/Repository.mk b/Repository.mk
index 56d8b2d28b84..2a75be836a59 100644
--- a/Repository.mk
+++ b/Repository.mk
@@ -80,6 +80,7 @@ $(eval $(call gb_Helper_register_executables,NONE, \
        tiledrendering \
        mtfdemo \
        visualbackendtest \
+    benchmark \
        listfonts \
        listglyphs \
        $(if $(and $(ENABLE_GTK3), $(filter LINUX %BSD SOLARIS,$(OS))), 
gtktiledviewer) \
diff --git a/vcl/Executable_benchmarktests.mk b/vcl/Executable_benchmarktests.mk
new file mode 100644
index 000000000000..be24bc63368e
--- /dev/null
+++ b/vcl/Executable_benchmarktests.mk
@@ -0,0 +1,41 @@
+# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*-
+#
+#
+# This file is part of the LibreOffice project.
+#
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+#
+
+$(eval $(call gb_Executable_Executable,benchmark))
+
+$(eval $(call gb_Executable_use_api,benchmark,\
+    offapi \
+    udkapi \
+))
+
+$(eval $(call gb_Executable_use_external,benchmark,boost_headers))
+
+$(eval $(call gb_Executable_set_include,benchmark,\
+    $$(INCLUDE) \
+    -I$(SRCDIR)/vcl/inc \
+))
+
+$(eval $(call gb_Executable_use_libraries,benchmark,\
+       basegfx \
+    comphelper \
+    cppu \
+    cppuhelper \
+    tl \
+    sal \
+       salhelper \
+))
+
+$(eval $(call gb_Executable_use_vclmain,benchmark,-lm))
+
+$(eval $(call gb_Executable_add_exception_objects,benchmark,\
+    vcl/backendtest/benchmark/BenchmarkApp \
+))
+
+# vim: set noet sw=4 ts=4:
diff --git a/vcl/Library_vcl.mk b/vcl/Library_vcl.mk
index cff520ccb03f..d44bfcdb22ea 100644
--- a/vcl/Library_vcl.mk
+++ b/vcl/Library_vcl.mk
@@ -519,6 +519,7 @@ $(eval $(call gb_Library_add_exception_objects,vcl,\
     vcl/backendtest/outputdevice/text \
     vcl/backendtest/outputdevice/rectangle \
     vcl/backendtest/GraphicsRenderTests \
+    vcl/backendtest/benchmark/outputdevice/Benchmarks \
     vcl/jsdialog/enabled \
     vcl/jsdialog/jsdialogbuilder \
     vcl/jsdialog/executor \
diff --git a/vcl/Module_vcl.mk b/vcl/Module_vcl.mk
index 596ed5b8c03a..6b1a028c3432 100644
--- a/vcl/Module_vcl.mk
+++ b/vcl/Module_vcl.mk
@@ -43,9 +43,8 @@ $(eval $(call gb_Module_add_targets,vcl,\
                 Executable_vcldemo \
                 Executable_icontest \
                 Executable_visualbackendtest \
-                Executable_mtfdemo \
-            ) \
-    )) \
+                Executable_benchmarktests \
+                Executable_mtfdemo ))) \
 ))
 
 ifeq ($(CROSS_COMPILING)$(DISABLE_DYNLOADING),)
diff --git a/vcl/backendtest/benchmark/BenchmarkApp.cxx 
b/vcl/backendtest/benchmark/BenchmarkApp.cxx
new file mode 100644
index 000000000000..b680bed11567
--- /dev/null
+++ b/vcl/backendtest/benchmark/BenchmarkApp.cxx
@@ -0,0 +1,223 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#include <math.h>
+#include <sal/log.hxx>
+
+#include <comphelper/processfactory.hxx>
+#include <cppuhelper/bootstrap.hxx>
+#include <com/sun/star/lang/XComponent.hpp>
+#include <com/sun/star/uno/XComponentContext.hpp>
+#include <com/sun/star/lang/XMultiServiceFactory.hpp>
+
+#include <vcl/bitmapex.hxx>
+#include <vcl/event.hxx>
+#include <vcl/gradient.hxx>
+#include <vcl/vclmain.hxx>
+
+#include <vcl/svapp.hxx>
+#include <vcl/wrkwin.hxx>
+#include <vcl/virdev.hxx>
+
+#include <basegfx/numeric/ftools.hxx>
+#include <tools/diagnose_ex.h>
+
+#include <iostream>
+
+#include <test/Benchmarks.hxx>
+
+using namespace css;
+
+static void drawBitmapCentered(tools::Rectangle const& rRect, const Bitmap& 
aBitmap,
+                               vcl::RenderContext& rRenderContext)
+{
+    tools::Long nWidth = rRect.GetWidth();
+    tools::Long nHeight = rRect.GetHeight();
+
+    Size aBitmapSize(aBitmap.GetSizePixel());
+
+    Point aPoint(rRect.TopLeft());
+
+    aPoint.AdjustX((nWidth - aBitmapSize.Width()) / 2);
+    aPoint.AdjustY((nHeight - aBitmapSize.Height()) / 2);
+
+    rRenderContext.DrawBitmap(aPoint, aBitmap);
+}
+
+static void drawBitmapScaledAndCentered(tools::Rectangle const& rRect, Bitmap 
aBitmap,
+                                        vcl::RenderContext& rRenderContext,
+                                        BmpScaleFlag aFlag = 
BmpScaleFlag::Fast)
+{
+    tools::Long nWidth = rRect.GetWidth();
+    tools::Long nHeight = rRect.GetHeight();
+
+    Size aBitmapSize(aBitmap.GetSizePixel());
+
+    double fWidthHeight = std::min(nWidth, nHeight);
+    double fScale = fWidthHeight / aBitmapSize.Width();
+    aBitmap.Scale(fScale, fScale, aFlag);
+
+    drawBitmapCentered(rRect, aBitmap, rRenderContext);
+}
+
+namespace
+{
+class BenchMarkWindow : public WorkWindow
+{
+private:
+    static constexpr unsigned char gnNumberOfTests = 1;
+    unsigned char mnTest;
+    ScopedVclPtr<VirtualDevice> mpVDev;
+
+public:
+    BenchMarkWindow()
+        : WorkWindow(nullptr, WB_APP | WB_STDWORK)
+        , mnTest(10 * gnNumberOfTests)
+        , mpVDev(VclPtr<VirtualDevice>::Create())
+    {
+    }
+
+    virtual ~BenchMarkWindow() override { disposeOnce(); }
+
+    DECL_LINK(updateHdl, Timer*, void);
+
+    virtual void KeyInput(const KeyEvent& rKEvt) override
+    {
+        sal_uInt16 nCode = rKEvt.GetKeyCode().GetCode();
+
+        if (nCode == KEY_BACKSPACE)
+            mnTest--;
+        else if (nCode == KEY_SPACE)
+            mnTest++;
+
+        if (nCode != KEY_BACKSPACE && nCode != KEY_SPACE)
+            return;
+
+        Invalidate();
+    }
+
+    static void updateResults(vcl::RenderContext& rRenderContext, sal_Int64 
aTimeElapsed)
+    {
+        rRenderContext.SetTextColor(COL_YELLOW);
+        rRenderContext.DrawText(Point(10, 10), "Time Taken to Render: "
+                                                   + 
OUString::number(float(aTimeElapsed)) + " ms");
+    }
+
+    static std::vector<tools::Rectangle> setupRegions(int nPartitionsX, int 
nPartitionsY,
+                                                      int nWidth, int nHeight)
+    {
+        std::vector<tools::Rectangle> aRegions;
+
+        for (int y = 0; y < nPartitionsY; y++)
+        {
+            for (int x = 0; x < nPartitionsX; x++)
+            {
+                tools::Long x1 = x * (nWidth / nPartitionsX);
+                tools::Long y1 = y * (nHeight / nPartitionsY);
+                tools::Long x2 = (x + 1) * (nWidth / nPartitionsX);
+                tools::Long y2 = (y + 1) * (nHeight / nPartitionsY);
+
+                aRegions.emplace_back(x1 + 1, y1 + 1, x2 - 6, y2 - 2);
+            }
+        }
+        return aRegions;
+    }
+
+    static void testMultiplePolygonsWithPolyPolygon(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++];
+        Benchmark aOutDevTest;
+        Bitmap aBitmap = aOutDevTest.setupMultiplePolygonsWithPolyPolygon();
+        drawBitmapScaledAndCentered(aRectangle, aBitmap, rRenderContext);
+        updateResults(rRenderContext, aOutDevTest.getElapsedTime());
+    }
+
+    virtual void Paint(vcl::RenderContext& rRenderContext,
+                       const tools::Rectangle& /*rRect*/) override
+    {
+        rRenderContext.SetBackground(Wallpaper(Color(0x36, 0x45, 0X4F)));
+
+        Size aSize = GetOutputSizePixel();
+
+        tools::Long nWidth = aSize.Width();
+        tools::Long nHeight = aSize.Height();
+
+        if (mnTest % gnNumberOfTests == 0)
+        {
+            testMultiplePolygonsWithPolyPolygon(rRenderContext, nWidth, 
nHeight);
+        }
+    }
+};
+}
+
+namespace
+{
+class BenchMarkApp : public Application
+{
+public:
+    BenchMarkApp() {}
+
+    virtual int Main() override
+    {
+        try
+        {
+            ScopedVclPtrInstance<BenchMarkWindow> aMainWindow;
+
+            aMainWindow->SetText("Benchmarks");
+            aMainWindow->Show();
+
+            Application::Execute();
+        }
+        catch (const css::uno::Exception&)
+        {
+            DBG_UNHANDLED_EXCEPTION("vcl.app", "Fatal");
+            return 1;
+        }
+        catch (const std::exception& rException)
+        {
+            SAL_WARN("vcl.app", "Fatal exception: " << rException.what());
+            return 1;
+        }
+        return 0;
+    }
+
+protected:
+    void Init() override
+    {
+        try
+        {
+            uno::Reference<uno::XComponentContext> xComponentContext
+                = ::cppu::defaultBootstrap_InitialComponentContext();
+            uno::Reference<lang::XMultiServiceFactory> 
xMSF(xComponentContext->getServiceManager(),
+                                                            uno::UNO_QUERY);
+
+            if (!xMSF.is())
+                Application::Abort("Bootstrap failure - no service manager");
+
+            comphelper::setProcessServiceFactory(xMSF);
+        }
+        catch (const uno::Exception& e)
+        {
+            Application::Abort("Bootstrap exception " + e.Message);
+        }
+    }
+
+    void DeInit() override { comphelper::setProcessServiceFactory(nullptr); }
+};
+}
+
+void vclmain::createApplication() { static BenchMarkApp aApplication; }
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/backendtest/benchmark/outputdevice/Benchmarks.cxx 
b/vcl/backendtest/benchmark/outputdevice/Benchmarks.cxx
new file mode 100644
index 000000000000..025414952b19
--- /dev/null
+++ b/vcl/backendtest/benchmark/outputdevice/Benchmarks.cxx
@@ -0,0 +1,59 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ */
+
+#include <test/Benchmarks.hxx>
+
+const Color Benchmark::constBackgroundColor(COL_LIGHTGRAY);
+const Color Benchmark::constLineColor(COL_LIGHTBLUE);
+const Color Benchmark::constFillColor(COL_BLUE);
+
+void Benchmark::initialSetup(tools::Long nWidth, tools::Long nHeight, Color 
aColor)
+{
+    mpVirtualDevice = VclPtr<VirtualDevice>::Create(DeviceFormat::DEFAULT);
+    maVDRectangle = tools::Rectangle(Point(), Size(nWidth, nHeight));
+    mpVirtualDevice->SetOutputSizePixel(maVDRectangle.GetSize());
+    mpVirtualDevice->SetAntialiasing(AntialiasingFlags::NONE);
+    mpVirtualDevice->SetBackground(Wallpaper(aColor));
+    mpVirtualDevice->Erase();
+}
+
+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;
+}
diff --git a/vcl/inc/test/Benchmarks.hxx b/vcl/inc/test/Benchmarks.hxx
new file mode 100644
index 000000000000..088b38093ed5
--- /dev/null
+++ b/vcl/inc/test/Benchmarks.hxx
@@ -0,0 +1,33 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ */
+
+#pragma once
+
+#include <vcl/virdev.hxx>
+
+#include <chrono>
+
+class VCL_DLLPUBLIC Benchmark
+{
+    ScopedVclPtr<VirtualDevice> mpVirtualDevice;
+    tools::Rectangle maVDRectangle;
+    std::chrono::steady_clock::time_point m_xStart;
+    std::chrono::steady_clock::time_point m_xEnd;
+
+    static const Color constBackgroundColor;
+    static const Color constLineColor;
+    static const Color constFillColor;
+
+    void initialSetup(tools::Long nWidth, tools::Long nHeight, Color aColor);
+
+public:
+    sal_Int64 getElapsedTime();
+    Bitmap setupMultiplePolygonsWithPolyPolygon();
+};

Reply via email to