[Libreoffice-commits] core.git: vcl/inc vcl/skia vcl/win

Luboš Luňák (via logerrit) logerrit at kemper.freedesktop.org
Wed Apr 7 15:02:29 UTC 2021


 vcl/inc/skia/win/font.hxx |   41 +++++++++++++++++++++++++++++++++++++++++
 vcl/skia/win/gdiimpl.cxx  |   33 +++++++++++++++++++--------------
 vcl/win/gdi/salfont.cxx   |    9 +++++++++
 3 files changed, 69 insertions(+), 14 deletions(-)

New commits:
commit 43bcc236d8253dff80b0911836fe73504b561f9a
Author:     Luboš Luňák <l.lunak at centrum.cz>
AuthorDate: Wed Apr 7 12:48:35 2021 +0000
Commit:     Luboš Luňák <l.lunak at collabora.com>
CommitDate: Wed Apr 7 17:01:40 2021 +0200

    cache Skia font
    
    The conversion costs a little bit and it was done for each drawing.
    
    Change-Id: Ifaad42308213f15839d9277beb837d21535bfc25
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/113735
    Tested-by: Jenkins
    Reviewed-by: Luboš Luňák <l.lunak at collabora.com>

diff --git a/vcl/inc/skia/win/font.hxx b/vcl/inc/skia/win/font.hxx
new file mode 100644
index 000000000000..4dc0bdf047d5
--- /dev/null
+++ b/vcl/inc/skia/win/font.hxx
@@ -0,0 +1,41 @@
+/* -*- 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_INC_SKIA_WIN_FONT_HXX
+#define INCLUDED_VCL_INC_SKIA_WIN_FONT_HXX
+
+#include <win/winlayout.hxx>
+
+#include <SkTypeface.h>
+
+// This class only adds SkTypeface in order to allow its caching.
+class SkiaWinFontInstance : public WinFontInstance
+{
+    friend rtl::Reference<LogicalFontInstance>
+    WinFontFace::CreateFontInstance(const FontSelectPattern&) const;
+
+public:
+    sk_sp<SkTypeface> GetSkiaTypeface() const { return m_skiaTypeface; }
+    bool GetSkiaDWrite() const { return m_skiaDWrite; }
+    void SetSkiaTypeface(const sk_sp<SkTypeface>& typeface, bool dwrite)
+    {
+        m_skiaTypeface = typeface;
+        m_skiaDWrite = dwrite;
+    }
+
+private:
+    using WinFontInstance::WinFontInstance;
+    sk_sp<SkTypeface> m_skiaTypeface;
+    bool m_skiaDWrite;
+};
+
+#endif // INCLUDED_VCL_INC_SKIA_WIN_FONT_HXX
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/skia/win/gdiimpl.cxx b/vcl/skia/win/gdiimpl.cxx
index 6b09375c4138..94162bb55fbe 100644
--- a/vcl/skia/win/gdiimpl.cxx
+++ b/vcl/skia/win/gdiimpl.cxx
@@ -13,7 +13,7 @@
 #include <vcl/skia/SkiaHelper.hxx>
 #include <skia/utils.hxx>
 #include <skia/zone.hxx>
-#include <win/winlayout.hxx>
+#include <skia/win/font.hxx>
 #include <comphelper/windowserrorstring.hxx>
 
 #include <SkCanvas.h>
@@ -199,11 +199,9 @@ sk_sp<SkTypeface> WinSkiaSalGraphicsImpl::createDirectWriteTypeface(HDC hdc, HFO
 
 bool WinSkiaSalGraphicsImpl::DrawTextLayout(const GenericSalLayout& rLayout)
 {
-    const WinFontInstance& rWinFont = static_cast<const WinFontInstance&>(rLayout.GetFont());
-    float fHScale = rWinFont.getHScale();
-
-    assert(dynamic_cast<const WinFontInstance*>(&rLayout.GetFont()));
-    const WinFontInstance* pWinFont = static_cast<const WinFontInstance*>(&rLayout.GetFont());
+    assert(dynamic_cast<const SkiaWinFontInstance*>(&rLayout.GetFont()));
+    const SkiaWinFontInstance* pWinFont
+        = static_cast<const SkiaWinFontInstance*>(&rLayout.GetFont());
     const HFONT hLayoutFont = pWinFont->GetHFONT();
     LOGFONTW logFont;
     if (GetObjectW(hLayoutFont, sizeof(logFont), &logFont) == 0)
@@ -211,12 +209,18 @@ bool WinSkiaSalGraphicsImpl::DrawTextLayout(const GenericSalLayout& rLayout)
         assert(false);
         return false;
     }
-    sk_sp<SkTypeface> typeface = createDirectWriteTypeface(mWinParent.getHDC(), hLayoutFont);
-    GlyphOrientation glyphOrientation = GlyphOrientation::Apply;
-    if (!typeface) // fall back to GDI text rendering
+    sk_sp<SkTypeface> typeface = pWinFont->GetSkiaTypeface();
+    if (!typeface)
     {
-        typeface.reset(SkCreateTypefaceFromLOGFONT(logFont));
-        glyphOrientation = GlyphOrientation::Ignore;
+        typeface = createDirectWriteTypeface(mWinParent.getHDC(), hLayoutFont);
+        bool dwrite = true;
+        if (!typeface) // fall back to GDI text rendering
+        {
+            typeface.reset(SkCreateTypefaceFromLOGFONT(logFont));
+            dwrite = false;
+        }
+        // Cache the typeface.
+        const_cast<SkiaWinFontInstance*>(pWinFont)->SetSkiaTypeface(typeface, dwrite);
     }
     // lfHeight actually depends on DPI, so it's not really font height as such,
     // but for LOGFONT-based typefaces Skia simply sets lfHeight back to this value
@@ -224,14 +228,15 @@ bool WinSkiaSalGraphicsImpl::DrawTextLayout(const GenericSalLayout& rLayout)
     double fontHeight = logFont.lfHeight;
     if (fontHeight < 0)
         fontHeight = -fontHeight;
-    SkFont font(typeface, fontHeight, fHScale, 0);
+    SkFont font(typeface, fontHeight, pWinFont->getHScale(), 0);
     font.setEdging(fontEdging);
     assert(dynamic_cast<SkiaSalGraphicsImpl*>(mWinParent.GetImpl()));
     SkiaSalGraphicsImpl* impl = static_cast<SkiaSalGraphicsImpl*>(mWinParent.GetImpl());
     COLORREF color = ::GetTextColor(mWinParent.getHDC());
     Color salColor(GetRValue(color), GetGValue(color), GetBValue(color));
-    // The font already is set up to have glyphs rotated as needed.
-    impl->drawGenericLayout(rLayout, salColor, font, glyphOrientation);
+    impl->drawGenericLayout(rLayout, salColor, font,
+                            pWinFont->GetSkiaDWrite() ? GlyphOrientation::Apply
+                                                      : GlyphOrientation::Ignore);
     return true;
 }
 
diff --git a/vcl/win/gdi/salfont.cxx b/vcl/win/gdi/salfont.cxx
index 4b67b9d1e384..6fd4836e3040 100644
--- a/vcl/win/gdi/salfont.cxx
+++ b/vcl/win/gdi/salfont.cxx
@@ -62,6 +62,11 @@
 #include <impfontmetricdata.hxx>
 #include <impglyphitem.hxx>
 
+#if HAVE_FEATURE_SKIA
+#include <vcl/skia/SkiaHelper.hxx>
+#include <skia/win/font.hxx>
+#endif
+
 using namespace vcl;
 
 static FIXED FixedFromDouble( double d )
@@ -662,6 +667,10 @@ sal_IntPtr WinFontFace::GetFontId() const
 
 rtl::Reference<LogicalFontInstance> WinFontFace::CreateFontInstance(const FontSelectPattern& rFSD) const
 {
+#if HAVE_FEATURE_SKIA
+    if (SkiaHelper::isVCLSkiaEnabled())
+        return new SkiaWinFontInstance(*this, rFSD);
+#endif
     return new WinFontInstance(*this, rFSD);
 }
 


More information about the Libreoffice-commits mailing list