From 4557bd79fe323af6b192e40ba6a035fe06d6adcf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Caol=C3=A1n=20McNamara?= Date: Wed, 11 Jan 2023 09:22:40 +0000 Subject: [PATCH] merge duplicate CairoTextRender impls MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit drop getSurfaceOffset because both impls just set these to 0, so its a no opt Change-Id: Ie4f28d57fb8a170c7a46d3cafceef3e049c26e2f Reviewed-on: https://gerrit.libreoffice.org/c/core/+/145325 Tested-by: Jenkins Reviewed-by: Caolán McNamara --- compilerplugins/clang/reservedid.cxx | 4 +- .../UnitTest.xcodeproj/project.pbxproj | 2 - solenv/clang-format/excludelist | 3 - vcl/Library_vcl.mk | 1 - vcl/Library_vclplug_gen.mk | 1 - vcl/headless/svpcairotextrender.cxx | 34 ---------- vcl/headless/svpgdi.cxx | 2 +- vcl/inc/headless/svpcairotextrender.hxx | 32 --------- vcl/inc/headless/svpgdi.hxx | 10 +-- vcl/inc/unx/cairotextrender.hxx | 16 ++--- vcl/inc/unx/salgdi.h | 10 --- vcl/inc/unx/x11/x11cairotextrender.hxx | 41 ------------ vcl/unx/generic/gdi/cairotextrender.cxx | 24 +++++-- vcl/unx/generic/gdi/salgdi.cxx | 4 +- vcl/unx/generic/gdi/x11cairotextrender.cxx | 66 ------------------- 15 files changed, 34 insertions(+), 216 deletions(-) delete mode 100644 vcl/headless/svpcairotextrender.cxx delete mode 100644 vcl/inc/headless/svpcairotextrender.hxx delete mode 100644 vcl/inc/unx/x11/x11cairotextrender.hxx delete mode 100644 vcl/unx/generic/gdi/x11cairotextrender.cxx diff --git a/compilerplugins/clang/reservedid.cxx b/compilerplugins/clang/reservedid.cxx index 1c2cd1ebbb00..f0840ace62ed 100644 --- a/compilerplugins/clang/reservedid.cxx +++ b/compilerplugins/clang/reservedid.cxx @@ -220,9 +220,7 @@ bool ReservedId::VisitNamedDecl(NamedDecl const * decl) { && s != "_SurfaceCellRenderer" // vcl/unx/gtk4/surfacecellrenderer.cxx && s != "_SurfaceCellRendererClass" // vcl/unx/gtk4/surfacecellrenderer.cxx && s != "_TransferableContent" // vcl/unx/gtk4/transferableprovider.cxx - && s != "_TransferableContentClass" // vcl/unx/gtk4/transferableprovider.cxx - && s != "_XRegion" // vcl/unx/generic/gdi/x11cairotextrender.cxx - && s != "_XTrap") // vcl/unx/generic/gdi/xrender_peer.hxx + && s != "_TransferableContentClass") // vcl/unx/gtk4/transferableprovider.cxx { report( DiagnosticsEngine::Warning, diff --git a/ios/UnitTest/UnitTest.xcodeproj/project.pbxproj b/ios/UnitTest/UnitTest.xcodeproj/project.pbxproj index 398007d9d2b8..940d62120390 100644 --- a/ios/UnitTest/UnitTest.xcodeproj/project.pbxproj +++ b/ios/UnitTest/UnitTest.xcodeproj/project.pbxproj @@ -98,7 +98,6 @@ BEA20D652166596F0032F67B /* svpvd.cxx */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; name = svpvd.cxx; path = ../../vcl/headless/svpvd.cxx; sourceTree = ""; }; BEA20D662166596F0032F67B /* svpframe.cxx */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; name = svpframe.cxx; path = ../../vcl/headless/svpframe.cxx; sourceTree = ""; }; BEA20D672166596F0032F67B /* svpbmp.cxx */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; name = svpbmp.cxx; path = ../../vcl/headless/svpbmp.cxx; sourceTree = ""; }; - BEA20D682166596F0032F67B /* svpcairotextrender.cxx */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; name = svpcairotextrender.cxx; path = ../../vcl/headless/svpcairotextrender.cxx; sourceTree = ""; }; BEA20D692166596F0032F67B /* svpgdi.cxx */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; name = svpgdi.cxx; path = ../../vcl/headless/svpgdi.cxx; sourceTree = ""; }; BEA20D6A2166596F0032F67B /* svpglyphcache.cxx */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; name = svpglyphcache.cxx; path = ../../vcl/headless/svpglyphcache.cxx; sourceTree = ""; }; BEA20D6B2166596F0032F67B /* svpinst.cxx */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; name = svpinst.cxx; path = ../../vcl/headless/svpinst.cxx; sourceTree = ""; }; @@ -355,7 +354,6 @@ children = ( BEA20D6D2166596F0032F67B /* headlessinst.cxx */, BEA20D672166596F0032F67B /* svpbmp.cxx */, - BEA20D682166596F0032F67B /* svpcairotextrender.cxx */, BEA20D6E2166596F0032F67B /* svpdata.cxx */, BEA20D6F2166596F0032F67B /* svpdummies.cxx */, BEA20D662166596F0032F67B /* svpframe.cxx */, diff --git a/solenv/clang-format/excludelist b/solenv/clang-format/excludelist index fe6d29b40a68..58d49b46a3b3 100644 --- a/solenv/clang-format/excludelist +++ b/solenv/clang-format/excludelist @@ -14380,7 +14380,6 @@ vcl/inc/unx/sm.hxx vcl/inc/unx/wmadaptor.hxx vcl/inc/unx/x11/x11sys.hxx vcl/inc/unx/x11/xlimits.hxx -vcl/inc/unx/x11/xrender_peer.hxx vcl/inc/unx/x11_cursors/ase_curs.h vcl/inc/unx/x11_cursors/ase_mask.h vcl/inc/unx/x11_cursors/asn_curs.h @@ -14981,8 +14980,6 @@ vcl/unx/generic/gdi/salbmp.cxx vcl/unx/generic/gdi/salgdi.cxx vcl/unx/generic/gdi/salgdi2.cxx vcl/unx/generic/gdi/salvd.cxx -vcl/unx/generic/gdi/x11cairotextrender.cxx -vcl/unx/generic/gdi/xrender_peer.cxx vcl/unx/generic/glyphs/freetype_glyphcache.cxx vcl/unx/generic/glyphs/glyphcache.cxx vcl/unx/generic/print/bitmap_gfx.cxx diff --git a/vcl/Library_vcl.mk b/vcl/Library_vcl.mk index ca32ff803ebe..f66bfc53db9e 100644 --- a/vcl/Library_vcl.mk +++ b/vcl/Library_vcl.mk @@ -557,7 +557,6 @@ vcl_headless_freetype_code=\ vcl/unx/generic/fontmanager/fontconfig \ vcl/unx/generic/fontmanager/fontmanager \ vcl/unx/generic/fontmanager/helper \ - vcl/headless/svpcairotextrender \ vcl/unx/generic/print/bitmap_gfx \ vcl/unx/generic/print/common_gfx \ vcl/unx/generic/print/glyphset \ diff --git a/vcl/Library_vclplug_gen.mk b/vcl/Library_vclplug_gen.mk index 4c6a5c7b0ef3..c117fb3bbee4 100644 --- a/vcl/Library_vclplug_gen.mk +++ b/vcl/Library_vclplug_gen.mk @@ -98,7 +98,6 @@ $(eval $(call gb_Library_add_exception_objects,vclplug_gen,\ vcl/unx/generic/dtrans/X11_service \ vcl/unx/generic/dtrans/X11_transferable \ vcl/unx/generic/gdi/cairo_xlib_cairo \ - vcl/unx/generic/gdi/x11cairotextrender \ vcl/unx/generic/gdi/X11CairoSalGraphicsImpl \ vcl/unx/generic/gdi/gdiimpl \ vcl/unx/generic/gdi/salgdi2 \ diff --git a/vcl/headless/svpcairotextrender.cxx b/vcl/headless/svpcairotextrender.cxx deleted file mode 100644 index c64bafae0969..000000000000 --- a/vcl/headless/svpcairotextrender.cxx +++ /dev/null @@ -1,34 +0,0 @@ -/* -*- 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 -#include -#include - -SvpCairoTextRender::SvpCairoTextRender(SvpSalGraphics& rParent) - : mrParent(rParent) -{ -} - -cairo_t* SvpCairoTextRender::getCairoContext() { return mrParent.getCairoContext(); } - -void SvpCairoTextRender::getSurfaceOffset(double& nDX, double& nDY) -{ - nDX = 0; - nDY = 0; -} - -void SvpCairoTextRender::clipRegion(cairo_t* cr) { mrParent.clipRegion(cr); } - -void SvpCairoTextRender::releaseCairoContext(cairo_t* cr) -{ - mrParent.releaseCairoContext(cr, basegfx::B2DRange()); -} - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/vcl/headless/svpgdi.cxx b/vcl/headless/svpgdi.cxx index a7ce0e3c769e..c9edd7e9a19c 100644 --- a/vcl/headless/svpgdi.cxx +++ b/vcl/headless/svpgdi.cxx @@ -26,7 +26,7 @@ #include SvpSalGraphics::SvpSalGraphics() - : m_aTextRenderImpl(*this) + : m_aTextRenderImpl(m_aCairoCommon) , m_pBackend(new SvpGraphicsBackend(m_aCairoCommon)) { bool bLOKActive = comphelper::LibreOfficeKit::isActive(); diff --git a/vcl/inc/headless/svpcairotextrender.hxx b/vcl/inc/headless/svpcairotextrender.hxx deleted file mode 100644 index 35744d5a2e3e..000000000000 --- a/vcl/inc/headless/svpcairotextrender.hxx +++ /dev/null @@ -1,32 +0,0 @@ -/* -*- 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/. - */ - -#ifndef INCLUDED_VCL_UNX_GTK3_GDI_GTK3CAIROTEXTRENDER_HXX -#define INCLUDED_VCL_UNX_GTK3_GDI_GTK3CAIROTEXTRENDER_HXX - -#include - -class SvpSalGraphics; - -class SvpCairoTextRender final : public CairoTextRender -{ - SvpSalGraphics& mrParent; - -public: - explicit SvpCairoTextRender(SvpSalGraphics& rParent); - - virtual cairo_t* getCairoContext() override; - virtual void getSurfaceOffset(double& nDX, double& nDY) override; - virtual void clipRegion(cairo_t* cr) override; - virtual void releaseCairoContext(cairo_t* cr) override; -}; - -#endif - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/vcl/inc/headless/svpgdi.hxx b/vcl/inc/headless/svpgdi.hxx index 740edd93f149..29b7dd53c7c2 100644 --- a/vcl/inc/headless/svpgdi.hxx +++ b/vcl/inc/headless/svpgdi.hxx @@ -33,7 +33,7 @@ #include #include #include -#include "svpcairotextrender.hxx" +#include #include #include @@ -45,7 +45,7 @@ class FreetypeFont; class VCL_DLLPUBLIC SvpSalGraphics : public SalGraphicsAutoDelegateToImpl { CairoCommon m_aCairoCommon; - SvpCairoTextRender m_aTextRenderImpl; + CairoTextRender m_aTextRenderImpl; std::unique_ptr m_pBackend; public: @@ -98,15 +98,11 @@ public: return m_aCairoCommon.getCairoContext(/*bXorModeAllowed*/false, getAntiAlias()); } - void releaseCairoContext(cairo_t* cr, const basegfx::B2DRange& rExtents) const - { - return m_aCairoCommon.releaseCairoContext(cr, /*bXorModeAllowed*/false, rExtents); - } - void clipRegion(cairo_t* cr) { m_aCairoCommon.clipRegion(cr); } + void copySource(const SalTwoRect& rTR, cairo_surface_t* source) { m_aCairoCommon.copySource(rTR, source, getAntiAlias()); diff --git a/vcl/inc/unx/cairotextrender.hxx b/vcl/inc/unx/cairotextrender.hxx index e9a85739827b..05f15d14ee27 100644 --- a/vcl/inc/unx/cairotextrender.hxx +++ b/vcl/inc/unx/cairotextrender.hxx @@ -24,26 +24,26 @@ class GenericSalLayout; class SalGraphics; +struct CairoCommon; typedef struct _cairo cairo_t; typedef struct _cairo_font_options cairo_font_options_t; class VCL_DLLPUBLIC CairoTextRender : public FreeTypeTextRenderImpl { private: + CairoCommon& mrCairoCommon; // https://gitlab.freedesktop.org/cairo/cairo/-/merge_requests/235 // I don't want to have CAIRO_ROUND_GLYPH_POS_ON set in the cairo // surfaces font_options, but that's private, so tricky to achieve - cairo_font_options_t* mpRoundGlyphPosOffOptions; + cairo_font_options_t* mpRoundGlyphPosOffOptions; protected: - virtual cairo_t* getCairoContext() = 0; - virtual void getSurfaceOffset(double& nDX, double& nDY) = 0; - virtual void releaseCairoContext(cairo_t* cr) = 0; - - virtual void clipRegion(cairo_t* cr) = 0; + cairo_t* getCairoContext(); + void releaseCairoContext(cairo_t* cr); + void clipRegion(cairo_t* cr); public: - virtual void DrawTextLayout(const GenericSalLayout&, const SalGraphics&) override; - CairoTextRender(); + virtual void DrawTextLayout(const GenericSalLayout&, const SalGraphics&) override; + CairoTextRender(CairoCommon& rCairoCommon); virtual ~CairoTextRender(); }; diff --git a/vcl/inc/unx/salgdi.h b/vcl/inc/unx/salgdi.h index 9fa31a2295a2..99a1a3e91af6 100644 --- a/vcl/inc/unx/salgdi.h +++ b/vcl/inc/unx/salgdi.h @@ -141,16 +141,6 @@ public: */ void YieldGraphicsExpose(); - cairo_t* getCairoContext() const - { - return maCairoCommon.getCairoContext(/*bXorModeAllowed*/false, getAntiAlias()); - } - - void releaseCairoContext(cairo_t* cr, const basegfx::B2DRange& rExtents) const - { - return maCairoCommon.releaseCairoContext(cr, /*bXorModeAllowed*/false, rExtents); - } - private: using SalGraphics::GetPixel; void SetClipRegion( GC pGC, Region pXReg = nullptr ) const; diff --git a/vcl/inc/unx/x11/x11cairotextrender.hxx b/vcl/inc/unx/x11/x11cairotextrender.hxx deleted file mode 100644 index 1da78384d0bd..000000000000 --- a/vcl/inc/unx/x11/x11cairotextrender.hxx +++ /dev/null @@ -1,41 +0,0 @@ -/* -*- 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/. - * - * This file incorporates work covered by the following license notice: - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed - * with this work for additional information regarding copyright - * ownership. The ASF licenses this file to you under the Apache - * License, Version 2.0 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.apache.org/licenses/LICENSE-2.0 . - */ - -#ifndef INCLUDED_VCL_UNX_GENERIC_GDI_X11CAIROTEXTRENDER_HXX -#define INCLUDED_VCL_UNX_GENERIC_GDI_X11CAIROTEXTRENDER_HXX - -#include -#include - -class X11CairoTextRender final : public CairoTextRender -{ - X11SalGraphics& mrParent; - -public: - explicit X11CairoTextRender(X11SalGraphics& rParent); - - virtual cairo_t* getCairoContext() override; - virtual void getSurfaceOffset(double& nDX, double& nDY) override; - virtual void clipRegion(cairo_t* cr) override; - virtual void releaseCairoContext(cairo_t* cr) override; -}; - -#endif - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/vcl/unx/generic/gdi/cairotextrender.cxx b/vcl/unx/generic/gdi/cairotextrender.cxx index 878eb3e1ac99..edc06f1bf3fa 100644 --- a/vcl/unx/generic/gdi/cairotextrender.cxx +++ b/vcl/unx/generic/gdi/cairotextrender.cxx @@ -131,7 +131,8 @@ extern "C" } #endif -CairoTextRender::CairoTextRender() +CairoTextRender::CairoTextRender(CairoCommon& rCairoCommon) + : mrCairoCommon(rCairoCommon) { // https://gitlab.freedesktop.org/cairo/cairo/-/merge_requests/235 // I don't want to have CAIRO_ROUND_GLYPH_POS_ON set in the cairo surfaces @@ -309,10 +310,6 @@ void CairoTextRender::DrawTextLayout(const GenericSalLayout& rLayout, const SalG cairo_set_font_options(cr, pFontOptions); } - double nDX, nDY; - getSurfaceOffset(nDX, nDY); - cairo_translate(cr, nDX, nDY); - clipRegion(cr); cairo_set_source_rgb(cr, @@ -412,6 +409,23 @@ void CairoTextRender::DrawTextLayout(const GenericSalLayout& rLayout, const SalG #endif } +cairo_t* CairoTextRender::getCairoContext() +{ + // Note that cairo_set_antialias (bAntiAlias property) doesn't affect cairo + // text rendering. That's affected by cairo_font_options_set_antialias instead. + return mrCairoCommon.getCairoContext(/*bXorModeAllowed*/false, /*bAntiAlias*/true); +} + +void CairoTextRender::clipRegion(cairo_t* cr) +{ + mrCairoCommon.clipRegion(cr); +} + +void CairoTextRender::releaseCairoContext(cairo_t* cr) +{ + mrCairoCommon.releaseCairoContext(cr, /*bXorModeAllowed*/false, basegfx::B2DRange()); +} + void FontConfigFontOptions::cairo_font_options_substitute(FcPattern* pPattern) { const cairo_font_options_t* pFontOptions = GetSalInstance()->GetCairoFontOptions(); diff --git a/vcl/unx/generic/gdi/salgdi.cxx b/vcl/unx/generic/gdi/salgdi.cxx index 76f31e02d5cf..89e6217c0645 100644 --- a/vcl/unx/generic/gdi/salgdi.cxx +++ b/vcl/unx/generic/gdi/salgdi.cxx @@ -53,7 +53,7 @@ #include "gdiimpl.hxx" #include -#include +#include #include "cairo_xlib_cairo.hxx" #include @@ -96,8 +96,8 @@ X11SalGraphics::X11SalGraphics(): else #endif { - mxTextRenderImpl.reset(new X11CairoTextRender(*this)); mxImpl.reset(new X11CairoSalGraphicsImpl(*this, maCairoCommon)); + mxTextRenderImpl.reset(new CairoTextRender(maCairoCommon)); } } diff --git a/vcl/unx/generic/gdi/x11cairotextrender.cxx b/vcl/unx/generic/gdi/x11cairotextrender.cxx deleted file mode 100644 index bdd522a17928..000000000000 --- a/vcl/unx/generic/gdi/x11cairotextrender.cxx +++ /dev/null @@ -1,66 +0,0 @@ -/* -*- 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/. - * - * This file incorporates work covered by the following license notice: - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed - * with this work for additional information regarding copyright - * ownership. The ASF licenses this file to you under the Apache - * License, Version 2.0 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.apache.org/licenses/LICENSE-2.0 . - */ - -#include - -#include -#include -#include -#include -#include - -X11CairoTextRender::X11CairoTextRender(X11SalGraphics& rParent) - : mrParent(rParent) -{ -} - -cairo_t* X11CairoTextRender::getCairoContext() -{ - return mrParent.getCairoContext(); -} - -void X11CairoTextRender::getSurfaceOffset( double& nDX, double& nDY ) -{ - nDX = 0; - nDY = 0; -} - -void X11CairoTextRender::clipRegion(cairo_t* cr) -{ - Region pClipRegion = mrParent.mpClipRegion; - if( pClipRegion && !XEmptyRegion( pClipRegion ) ) - { - for (tools::Long i = 0; i < pClipRegion->numRects; ++i) - { - cairo_rectangle(cr, - pClipRegion->rects[i].x1, - pClipRegion->rects[i].y1, - pClipRegion->rects[i].x2 - pClipRegion->rects[i].x1, - pClipRegion->rects[i].y2 - pClipRegion->rects[i].y1); - } - cairo_clip(cr); - } -} - -void X11CairoTextRender::releaseCairoContext(cairo_t* cr) -{ - mrParent.releaseCairoContext(cr, basegfx::B2DRange()); -} - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */