diff options
author | Caolán McNamara <caolanm@redhat.com> | 2023-01-09 16:16:18 +0000 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2023-01-10 13:56:23 +0000 |
commit | d8bccf8cbeebe8d5cf9354f3818da795a072899d (patch) | |
tree | 61fb656413597363ce9b5d491544677449d29f63 /vcl/unx | |
parent | c4243e71a59013a5532ae945ffd80f9b13485721 (diff) |
reorg to make use of X11SalFrame/X11SalVirtualDevice surface
Change-Id: I56ac5181a51aef8f6ae698c14551925847a9f400
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/145252
Tested-by: Jenkins
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
Diffstat (limited to 'vcl/unx')
-rw-r--r-- | vcl/unx/generic/gdi/X11CairoSalGraphicsImpl.cxx | 142 | ||||
-rw-r--r-- | vcl/unx/generic/gdi/X11CairoSalGraphicsImpl.hxx | 21 | ||||
-rw-r--r-- | vcl/unx/generic/gdi/salgdi.cxx | 34 | ||||
-rw-r--r-- | vcl/unx/generic/gdi/x11cairotextrender.cxx | 2 |
4 files changed, 95 insertions, 104 deletions
diff --git a/vcl/unx/generic/gdi/X11CairoSalGraphicsImpl.cxx b/vcl/unx/generic/gdi/X11CairoSalGraphicsImpl.cxx index 39f661e46b4d..557ac8960bca 100644 --- a/vcl/unx/generic/gdi/X11CairoSalGraphicsImpl.cxx +++ b/vcl/unx/generic/gdi/X11CairoSalGraphicsImpl.cxx @@ -22,107 +22,112 @@ #include <basegfx/polygon/b2dpolypolygontools.hxx> #include <basegfx/curve/b2dcubicbezier.hxx> -X11CairoSalGraphicsImpl::X11CairoSalGraphicsImpl(X11SalGraphics& rParent, X11Common& rX11Common) +X11CairoSalGraphicsImpl::X11CairoSalGraphicsImpl(X11SalGraphics& rParent, CairoCommon& rCairoCommon) : X11SalGraphicsImpl(rParent) - , mrX11Common(rX11Common) - , moPenColor(std::nullopt) - , moFillColor(std::nullopt) + , mrCairoCommon(rCairoCommon) { } void X11CairoSalGraphicsImpl::drawRect(tools::Long nX, tools::Long nY, tools::Long nWidth, tools::Long nHeight) { - cairo_t* cr = mrX11Common.getCairoContext(); - clipRegion(cr); + cairo_t* cr = mrCairoCommon.getCairoContext(true, getAntiAlias()); + basegfx::B2DRange extents; + mrCairoCommon.clipRegion(cr); - CairoCommon::drawRect(cr, nullptr, moPenColor, moFillColor, getAntiAlias(), nX, nY, nWidth, - nHeight); + CairoCommon::drawRect(cr, &extents, mrCairoCommon.m_oLineColor, mrCairoCommon.m_oFillColor, + getAntiAlias(), nX, nY, nWidth, nHeight); - X11Common::releaseCairoContext(cr); + mrCairoCommon.releaseCairoContext(cr, true, extents); } void X11CairoSalGraphicsImpl::drawPolygon(sal_uInt32 nPoints, const Point* pPtAry) { - cairo_t* cr = mrX11Common.getCairoContext(); - clipRegion(cr); + cairo_t* cr = mrCairoCommon.getCairoContext(true, getAntiAlias()); + basegfx::B2DRange extents; + mrCairoCommon.clipRegion(cr); - CairoCommon::drawPolygon(cr, nullptr, moPenColor, moFillColor, getAntiAlias(), nPoints, pPtAry); + CairoCommon::drawPolygon(cr, &extents, mrCairoCommon.m_oLineColor, mrCairoCommon.m_oFillColor, + getAntiAlias(), nPoints, pPtAry); - X11Common::releaseCairoContext(cr); + mrCairoCommon.releaseCairoContext(cr, true, extents); } -void X11CairoSalGraphicsImpl::drawPolyPolygon(sal_uInt32 nPoly, const sal_uInt32* pPoints, +void X11CairoSalGraphicsImpl::drawPolyPolygon(sal_uInt32 nPoly, const sal_uInt32* pPointCounts, const Point** pPtAry) { - cairo_t* cr = mrX11Common.getCairoContext(); - clipRegion(cr); + cairo_t* cr = mrCairoCommon.getCairoContext(true, getAntiAlias()); + basegfx::B2DRange extents; + mrCairoCommon.clipRegion(cr); - CairoCommon::drawPolyPolygon(cr, nullptr, moPenColor, moFillColor, getAntiAlias(), nPoly, - pPoints, pPtAry); + CairoCommon::drawPolyPolygon(cr, &extents, mrCairoCommon.m_oLineColor, + mrCairoCommon.m_oFillColor, getAntiAlias(), nPoly, pPointCounts, + pPtAry); - X11Common::releaseCairoContext(cr); + mrCairoCommon.releaseCairoContext(cr, true, extents); } bool X11CairoSalGraphicsImpl::drawPolyPolygon(const basegfx::B2DHomMatrix& rObjectToDevice, const basegfx::B2DPolyPolygon& rPolyPolygon, double fTransparency) { - cairo_t* cr = mrX11Common.getCairoContext(); - clipRegion(cr); + cairo_t* cr = mrCairoCommon.getCairoContext(true, getAntiAlias()); + basegfx::B2DRange extents; + mrCairoCommon.clipRegion(cr); - bool bRetVal(CairoCommon::drawPolyPolygon(cr, nullptr, moPenColor, moFillColor, getAntiAlias(), + bool bRetVal(CairoCommon::drawPolyPolygon(cr, &extents, mrCairoCommon.m_oLineColor, + mrCairoCommon.m_oFillColor, getAntiAlias(), rObjectToDevice, rPolyPolygon, fTransparency)); - X11Common::releaseCairoContext(cr); + mrCairoCommon.releaseCairoContext(cr, true, extents); + return bRetVal; } void X11CairoSalGraphicsImpl::drawPixel(tools::Long nX, tools::Long nY) { - drawPixel(nX, nY, *moPenColor); + drawPixel(nX, nY, *mrCairoCommon.m_oLineColor); } -void X11CairoSalGraphicsImpl::drawPixel(tools::Long nX, tools::Long nY, Color nColor) +void X11CairoSalGraphicsImpl::drawPixel(tools::Long nX, tools::Long nY, Color aColor) { - cairo_t* cr = mrX11Common.getCairoContext(); - clipRegion(cr); + cairo_t* cr = mrCairoCommon.getCairoContext(true, getAntiAlias()); + basegfx::B2DRange extents; + mrCairoCommon.clipRegion(cr); - CairoCommon::drawPixel(cr, nullptr, nColor, nX, nY); + CairoCommon::drawPixel(cr, &extents, aColor, nX, nY); - X11Common::releaseCairoContext(cr); + mrCairoCommon.releaseCairoContext(cr, true, extents); } Color X11CairoSalGraphicsImpl::getPixel(tools::Long nX, tools::Long nY) { - cairo_t* cr = mrX11Common.getCairoContext(); - - Color aRet = CairoCommon::getPixel(cairo_get_target(cr), nX, nY); - - X11Common::releaseCairoContext(cr); - - return aRet; + return CairoCommon::getPixel(mrCairoCommon.m_pSurface, nX, nY); } void X11CairoSalGraphicsImpl::drawLine(tools::Long nX1, tools::Long nY1, tools::Long nX2, tools::Long nY2) { - cairo_t* cr = mrX11Common.getCairoContext(); - clipRegion(cr); + cairo_t* cr = mrCairoCommon.getCairoContext(false, getAntiAlias()); + basegfx::B2DRange extents; + mrCairoCommon.clipRegion(cr); - CairoCommon::drawLine(cr, nullptr, *moPenColor, getAntiAlias(), nX1, nY1, nX2, nY2); + CairoCommon::drawLine(cr, &extents, *mrCairoCommon.m_oLineColor, getAntiAlias(), nX1, nY1, nX2, + nY2); - X11Common::releaseCairoContext(cr); + mrCairoCommon.releaseCairoContext(cr, false, extents); } void X11CairoSalGraphicsImpl::drawPolyLine(sal_uInt32 nPoints, const Point* pPtAry) { - cairo_t* cr = mrX11Common.getCairoContext(); - clipRegion(cr); + cairo_t* cr = mrCairoCommon.getCairoContext(false, getAntiAlias()); + basegfx::B2DRange aExtents; + mrCairoCommon.clipRegion(cr); - CairoCommon::drawPolyLine(cr, nullptr, *moPenColor, getAntiAlias(), nPoints, pPtAry); + CairoCommon::drawPolyLine(cr, &aExtents, *mrCairoCommon.m_oLineColor, getAntiAlias(), nPoints, + pPtAry); - X11Common::releaseCairoContext(cr); + mrCairoCommon.releaseCairoContext(cr, false, aExtents); } bool X11CairoSalGraphicsImpl::drawPolyLine(const basegfx::B2DHomMatrix& rObjectToDevice, @@ -137,16 +142,18 @@ bool X11CairoSalGraphicsImpl::drawPolyLine(const basegfx::B2DHomMatrix& rObjectT if (0 == rPolyLine.count() || fTransparency < 0.0 || fTransparency >= 1.0) return true; - cairo_t* cr = mrX11Common.getCairoContext(); - clipRegion(cr); + cairo_t* cr = mrCairoCommon.getCairoContext(false, getAntiAlias()); + basegfx::B2DRange aExtents; + mrCairoCommon.clipRegion(cr); // Use the now available static drawPolyLine from the Cairo-Headless-Fallback // that will take care of all needed stuff - const bool bRetval(CairoCommon::drawPolyLine( - cr, nullptr, *moPenColor, getAntiAlias(), rObjectToDevice, rPolyLine, fTransparency, - fLineWidth, pStroke, eLineJoin, eLineCap, fMiterMinimumAngle, bPixelSnapHairline)); + bool bRetval(CairoCommon::drawPolyLine(cr, &aExtents, *mrCairoCommon.m_oLineColor, + getAntiAlias(), rObjectToDevice, rPolyLine, + fTransparency, fLineWidth, pStroke, eLineJoin, eLineCap, + fMiterMinimumAngle, bPixelSnapHairline)); - X11Common::releaseCairoContext(cr); + mrCairoCommon.releaseCairoContext(cr, false, aExtents); return bRetval; } @@ -154,13 +161,14 @@ bool X11CairoSalGraphicsImpl::drawPolyLine(const basegfx::B2DHomMatrix& rObjectT bool X11CairoSalGraphicsImpl::drawAlphaRect(tools::Long nX, tools::Long nY, tools::Long nWidth, tools::Long nHeight, sal_uInt8 nTransparency) { - cairo_t* cr = mrX11Common.getCairoContext(); - clipRegion(cr); + cairo_t* cr = mrCairoCommon.getCairoContext(false, getAntiAlias()); + basegfx::B2DRange extents; + mrCairoCommon.clipRegion(cr); - const bool bRetval(CairoCommon::drawAlphaRect(cr, nullptr, *moPenColor, *moFillColor, nX, nY, - nWidth, nHeight, nTransparency)); - - X11Common::releaseCairoContext(cr); + const bool bRetval(CairoCommon::drawAlphaRect(cr, &extents, *mrCairoCommon.m_oLineColor, + *mrCairoCommon.m_oFillColor, nX, nY, nWidth, + nHeight, nTransparency)); + mrCairoCommon.releaseCairoContext(cr, false, extents); return bRetval; } @@ -168,13 +176,14 @@ bool X11CairoSalGraphicsImpl::drawAlphaRect(tools::Long nX, tools::Long nY, tool bool X11CairoSalGraphicsImpl::drawGradient(const tools::PolyPolygon& rPolyPolygon, const Gradient& rGradient) { - cairo_t* cr = mrX11Common.getCairoContext(); - clipRegion(cr); + cairo_t* cr = mrCairoCommon.getCairoContext(true, getAntiAlias()); + basegfx::B2DRange extents; + mrCairoCommon.clipRegion(cr); const bool bRetval( - CairoCommon::drawGradient(cr, nullptr, getAntiAlias(), rPolyPolygon, rGradient)); + CairoCommon::drawGradient(cr, &extents, getAntiAlias(), rPolyPolygon, rGradient)); - X11Common::releaseCairoContext(cr); + mrCairoCommon.releaseCairoContext(cr, true, extents); return bRetval; } @@ -182,15 +191,16 @@ bool X11CairoSalGraphicsImpl::drawGradient(const tools::PolyPolygon& rPolyPolygo bool X11CairoSalGraphicsImpl::implDrawGradient(basegfx::B2DPolyPolygon const& rPolyPolygon, SalGradient const& rGradient) { - cairo_t* cr = mrX11Common.getCairoContext(); - clipRegion(cr); + cairo_t* cr = mrCairoCommon.getCairoContext(true, getAntiAlias()); + basegfx::B2DRange extents; + mrCairoCommon.clipRegion(cr); - const bool bRetval( - CairoCommon::implDrawGradient(cr, nullptr, getAntiAlias(), rPolyPolygon, rGradient)); + bool bRetVal( + CairoCommon::implDrawGradient(cr, &extents, getAntiAlias(), rPolyPolygon, rGradient)); - X11Common::releaseCairoContext(cr); + mrCairoCommon.releaseCairoContext(cr, true, extents); - return bRetval; + return bRetVal; } bool X11CairoSalGraphicsImpl::hasFastDrawTransformedBitmap() const diff --git a/vcl/unx/generic/gdi/X11CairoSalGraphicsImpl.hxx b/vcl/unx/generic/gdi/X11CairoSalGraphicsImpl.hxx index 9e94b0dff7ea..f7e3a13287f9 100644 --- a/vcl/unx/generic/gdi/X11CairoSalGraphicsImpl.hxx +++ b/vcl/unx/generic/gdi/X11CairoSalGraphicsImpl.hxx @@ -27,51 +27,48 @@ class X11CairoSalGraphicsImpl : public X11SalGraphicsImpl { private: - X11Common& mrX11Common; - vcl::Region maClipRegion; - std::optional<Color> moPenColor; - std::optional<Color> moFillColor; + CairoCommon& mrCairoCommon; public: - X11CairoSalGraphicsImpl(X11SalGraphics& rParent, X11Common& rX11Common); + X11CairoSalGraphicsImpl(X11SalGraphics& rParent, CairoCommon& rCairoCommon); void ResetClipRegion() override { - maClipRegion.SetNull(); + mrCairoCommon.m_aClipRegion.SetNull(); X11SalGraphicsImpl::ResetClipRegion(); } void setClipRegion(const vcl::Region& i_rClip) override { - maClipRegion = i_rClip; + mrCairoCommon.m_aClipRegion = i_rClip; X11SalGraphicsImpl::setClipRegion(i_rClip); } void SetLineColor() override { - moPenColor = std::nullopt; + mrCairoCommon.m_oLineColor = std::nullopt; X11SalGraphicsImpl::SetLineColor(); } void SetLineColor(Color nColor) override { - moPenColor = nColor; + mrCairoCommon.m_oLineColor = nColor; X11SalGraphicsImpl::SetLineColor(nColor); } void SetFillColor() override { - moFillColor = std::nullopt; + mrCairoCommon.m_oFillColor = std::nullopt; X11SalGraphicsImpl::SetFillColor(); } void SetFillColor(Color nColor) override { - moFillColor = nColor; + mrCairoCommon.m_oFillColor = nColor; X11SalGraphicsImpl::SetFillColor(nColor); } - void clipRegion(cairo_t* cr) { CairoCommon::clipRegion(cr, maClipRegion); } + void clipRegion(cairo_t* cr) { CairoCommon::clipRegion(cr, mrCairoCommon.m_aClipRegion); } void drawPixel(tools::Long nX, tools::Long nY) override; void drawPixel(tools::Long nX, tools::Long nY, Color nColor) override; diff --git a/vcl/unx/generic/gdi/salgdi.cxx b/vcl/unx/generic/gdi/salgdi.cxx index 74be730fe9fa..e17f73050732 100644 --- a/vcl/unx/generic/gdi/salgdi.cxx +++ b/vcl/unx/generic/gdi/salgdi.cxx @@ -66,20 +66,8 @@ X11Common::X11Common() : m_hDrawable(None) , m_pColormap(nullptr) - , m_pExternalSurface(nullptr) {} -cairo_t* X11Common::getCairoContext() -{ - assert(m_pExternalSurface && "must be already set"); - return cairo_create(m_pExternalSurface); -} - -void X11Common::releaseCairoContext(cairo_t* cr) -{ - cairo_destroy(cr); -} - bool X11Common::SupportsCairo() const { static bool bSupportsCairo = [this] { @@ -113,7 +101,7 @@ X11SalGraphics::X11SalGraphics(): #endif { mxTextRenderImpl.reset(new X11CairoTextRender(*this)); - mxImpl.reset(new X11CairoSalGraphicsImpl(*this, maX11Common)); + mxImpl.reset(new X11CairoSalGraphicsImpl(*this, maCairoCommon)); } } @@ -158,9 +146,15 @@ SalGraphicsImpl* X11SalGraphics::GetImpl() const return mxImpl.get(); } -void X11SalGraphics::SetDrawable(Drawable aDrawable, cairo_surface_t* pExternalSurface, SalX11Screen nXScreen) +void X11SalGraphics::SetDrawable(Drawable aDrawable, cairo_surface_t* pSurface, SalX11Screen nXScreen) { - maX11Common.m_pExternalSurface = pExternalSurface; + maCairoCommon.m_pSurface = pSurface; + if (maCairoCommon.m_pSurface) + { + maCairoCommon.m_aFrameSize.setX(cairo_xlib_surface_get_width(pSurface)); + maCairoCommon.m_aFrameSize.setY(cairo_xlib_surface_get_height(pSurface)); + dl_cairo_surface_get_device_scale(pSurface, &maCairoCommon.m_fScale, nullptr); + } // shortcut if nothing changed if( maX11Common.m_hDrawable == aDrawable ) @@ -457,14 +451,4 @@ SalGeometryProvider *X11SalGraphics::GetGeometryProvider() const return static_cast< SalGeometryProvider * >(m_pVDev); } -cairo_t* X11SalGraphics::getCairoContext() -{ - return maX11Common.getCairoContext(); -} - -void X11SalGraphics::releaseCairoContext(cairo_t* cr) -{ - X11Common::releaseCairoContext(cr); -} - /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/vcl/unx/generic/gdi/x11cairotextrender.cxx b/vcl/unx/generic/gdi/x11cairotextrender.cxx index 6bbbbc1bff87..bdd522a17928 100644 --- a/vcl/unx/generic/gdi/x11cairotextrender.cxx +++ b/vcl/unx/generic/gdi/x11cairotextrender.cxx @@ -60,7 +60,7 @@ void X11CairoTextRender::clipRegion(cairo_t* cr) void X11CairoTextRender::releaseCairoContext(cairo_t* cr) { - X11SalGraphics::releaseCairoContext(cr); + mrParent.releaseCairoContext(cr, basegfx::B2DRange()); } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |