summaryrefslogtreecommitdiffstats
path: root/vcl/skia/x11
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 09:06:44 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 09:06:44 +0000
commited5640d8b587fbcfed7dd7967f3de04b37a76f26 (patch)
tree7a5f7c6c9d02226d7471cb3cc8fbbf631b415303 /vcl/skia/x11
parentInitial commit. (diff)
downloadlibreoffice-ed5640d8b587fbcfed7dd7967f3de04b37a76f26.tar.xz
libreoffice-ed5640d8b587fbcfed7dd7967f3de04b37a76f26.zip
Adding upstream version 4:7.4.7.upstream/4%7.4.7upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r--vcl/skia/x11/gdiimpl.cxx175
-rw-r--r--vcl/skia/x11/salvd.cxx85
-rw-r--r--vcl/skia/x11/textrender.cxx103
3 files changed, 363 insertions, 0 deletions
diff --git a/vcl/skia/x11/gdiimpl.cxx b/vcl/skia/x11/gdiimpl.cxx
new file mode 100644
index 000000000..6a7cce14d
--- /dev/null
+++ b/vcl/skia/x11/gdiimpl.cxx
@@ -0,0 +1,175 @@
+/* -*- 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/.
+ *
+ * Some of this code is based on Skia source code, covered by the following
+ * license notice (see readlicense_oo for the full license):
+ *
+ * Copyright 2016 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ *
+ */
+
+#include <skia/x11/gdiimpl.hxx>
+
+#include <tools/sk_app/unix/WindowContextFactory_unix.h>
+
+#include <skia/utils.hxx>
+#include <skia/zone.hxx>
+
+#include <X11/Xutil.h>
+
+using namespace SkiaHelper;
+
+X11SkiaSalGraphicsImpl::X11SkiaSalGraphicsImpl(X11SalGraphics& rParent)
+ : SkiaSalGraphicsImpl(rParent, rParent.GetGeometryProvider())
+ , mX11Parent(rParent)
+{
+}
+
+void X11SkiaSalGraphicsImpl::Init()
+{
+ // The m_pFrame and m_pVDev pointers are updated late in X11
+ setProvider(mX11Parent.GetGeometryProvider());
+ SkiaSalGraphicsImpl::Init();
+}
+
+void X11SkiaSalGraphicsImpl::createWindowSurfaceInternal(bool forceRaster)
+{
+ assert(!mWindowContext);
+ assert(!mSurface);
+ assert(mX11Parent.GetDrawable() != None);
+ RenderMethod renderMethod = forceRaster ? RenderRaster : renderMethodToUse();
+ mScaling = getWindowScaling();
+ mWindowContext = createWindowContext(mX11Parent.GetXDisplay(), mX11Parent.GetDrawable(),
+ &mX11Parent.GetVisual(), GetWidth() * mScaling,
+ GetHeight() * mScaling, renderMethod, false);
+ if (mWindowContext)
+ {
+ // See flushSurfaceToWindowContext().
+ if (renderMethod == RenderRaster)
+ mSurface = mWindowContext->getBackbufferSurface();
+ else
+ mSurface = createSkSurface(GetWidth(), GetHeight());
+ }
+}
+
+std::unique_ptr<sk_app::WindowContext>
+X11SkiaSalGraphicsImpl::createWindowContext(Display* display, Drawable drawable,
+ const XVisualInfo* visual, int width, int height,
+ RenderMethod renderMethod, bool temporary)
+{
+ SkiaZone zone;
+ sk_app::DisplayParams displayParams;
+ displayParams.fColorType = kN32_SkColorType;
+#if defined LINUX
+ // WORKAROUND: VSync causes freezes that can even temporarily freeze the entire desktop.
+ // This happens even with the latest 450.66 drivers despite them claiming a fix for vsync.
+ // https://forums.developer.nvidia.com/t/hangs-freezes-when-vulkan-v-sync-vk-present-mode-fifo-khr-is-enabled/67751
+ if (getVendor() == DriverBlocklist::VendorNVIDIA)
+ displayParams.fDisableVsync = true;
+#endif
+ sk_app::window_context_factory::XlibWindowInfo winInfo;
+ assert(display);
+ winInfo.fDisplay = display;
+ winInfo.fWindow = drawable;
+ winInfo.fFBConfig = nullptr; // not used
+ winInfo.fVisualInfo = const_cast<XVisualInfo*>(visual);
+ assert(winInfo.fVisualInfo->visual != nullptr); // make sure it's not an uninitialized SalVisual
+ winInfo.fWidth = width;
+ winInfo.fHeight = height;
+#if defined DBG_UTIL && !defined NDEBUG
+ // Our patched Skia has VulkanWindowContext that shares grDirectContext, which requires
+ // that the X11 visual is always the same. Ensure it is so.
+ static VisualID checkVisualID = -1U;
+ // Exception is for the temporary case during startup, when SkiaHelper's
+ // checkDeviceDenylisted() needs a WindowContext and may be called before SalVisual
+ // is ready.
+ if (!temporary)
+ {
+ assert(checkVisualID == -1U || winInfo.fVisualInfo->visualid == checkVisualID);
+ checkVisualID = winInfo.fVisualInfo->visualid;
+ }
+#else
+ (void)temporary;
+#endif
+ switch (renderMethod)
+ {
+ case RenderRaster:
+ // Make sure we ask for color type that matches the X11 visual. If red mask
+ // is larger value than blue mask, then on little endian this means blue is first.
+ // This should also preferably match SK_R32_SHIFT set in config_skia.h, as that
+ // improves performance, the common setup seems to be BGRA (possibly because of
+ // choosing OpenGL-capable visual).
+ displayParams.fColorType
+ = (visual->red_mask > visual->blue_mask ? kBGRA_8888_SkColorType
+ : kRGBA_8888_SkColorType);
+ return sk_app::window_context_factory::MakeRasterForXlib(winInfo, displayParams);
+ case RenderVulkan:
+ return sk_app::window_context_factory::MakeVulkanForXlib(winInfo, displayParams);
+ case RenderMetal:
+ abort();
+ break;
+ }
+ abort();
+}
+
+bool X11SkiaSalGraphicsImpl::avoidRecreateByResize() const
+{
+ if (SkiaSalGraphicsImpl::avoidRecreateByResize())
+ return true;
+ if (!mSurface || isOffscreen())
+ return false;
+ // Skia's WindowContext uses actual dimensions of the X window, which due to X11 being
+ // asynchronous may be temporarily different from what VCL thinks are the dimensions.
+ // That can lead to us repeatedly calling recreateSurface() because of "incorrect"
+ // size, and we otherwise need to check for size changes, because VCL does not inform us.
+ // Avoid the problem here by checking the size of the X window and bail out if Skia
+ // would just return the same size as it is now.
+ Window r;
+ int x, y;
+ unsigned int w, h, border, depth;
+ XGetGeometry(mX11Parent.GetXDisplay(), mX11Parent.GetDrawable(), &r, &x, &y, &w, &h, &border,
+ &depth);
+ return mSurface->width() == int(w) && mSurface->height() == int(h);
+}
+
+void X11SkiaSalGraphicsImpl::freeResources() {}
+
+void X11SkiaSalGraphicsImpl::Flush() { performFlush(); }
+
+std::unique_ptr<sk_app::WindowContext> createVulkanWindowContext(bool temporary)
+{
+ SalDisplay* salDisplay = vcl_sal::getSalDisplay(GetGenericUnixSalData());
+ const XVisualInfo* visual;
+ XVisualInfo* visuals = nullptr;
+ if (!temporary)
+ visual = &salDisplay->GetVisual(salDisplay->GetDefaultXScreen());
+ else
+ {
+ // SalVisual from salDisplay may not be setup yet at this point, get
+ // info for the default visual.
+ XVisualInfo search;
+ search.visualid = XVisualIDFromVisual(
+ DefaultVisual(salDisplay->GetDisplay(), salDisplay->GetDefaultXScreen().getXScreen()));
+ int count;
+ visuals = XGetVisualInfo(salDisplay->GetDisplay(), VisualIDMask, &search, &count);
+ assert(count == 1);
+ visual = visuals;
+ }
+ std::unique_ptr<sk_app::WindowContext> ret = X11SkiaSalGraphicsImpl::createWindowContext(
+ salDisplay->GetDisplay(), None, visual, 1, 1, RenderVulkan, temporary);
+ if (temporary)
+ XFree(visuals);
+ return ret;
+}
+
+void X11SkiaSalGraphicsImpl::prepareSkia() { SkiaHelper::prepareSkia(createVulkanWindowContext); }
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/skia/x11/salvd.cxx b/vcl/skia/x11/salvd.cxx
new file mode 100644
index 000000000..73488b8a1
--- /dev/null
+++ b/vcl/skia/x11/salvd.cxx
@@ -0,0 +1,85 @@
+/* -*- 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 <vcl/sysdata.hxx>
+
+#include <unx/salunx.h>
+#include <unx/saldisp.hxx>
+#include <unx/salgdi.h>
+#include <unx/salvd.h>
+
+#include <skia/x11/salvd.hxx>
+
+void X11SalGraphics::Init(X11SkiaSalVirtualDevice* pDevice)
+{
+ SalDisplay* pDisplay = pDevice->GetDisplay();
+
+ m_nXScreen = pDevice->GetXScreenNumber();
+ maX11Common.m_pColormap = &pDisplay->GetColormap(m_nXScreen);
+
+ m_pVDev = pDevice;
+ m_pFrame = nullptr;
+
+ bWindow_ = pDisplay->IsDisplay();
+ bVirDev_ = true;
+
+ mxImpl->Init();
+}
+
+X11SkiaSalVirtualDevice::X11SkiaSalVirtualDevice(const SalGraphics& rGraphics, tools::Long nDX,
+ tools::Long nDY, const SystemGraphicsData* pData,
+ std::unique_ptr<X11SalGraphics> pNewGraphics)
+ : mpGraphics(std::move(pNewGraphics))
+ , mbGraphics(false)
+ , mnXScreen(0)
+{
+ assert(mpGraphics);
+
+ // TODO Check where a VirtualDevice is created from SystemGraphicsData
+ assert(pData == nullptr);
+ (void)pData;
+
+ mpDisplay = vcl_sal::getSalDisplay(GetGenericUnixSalData());
+ mnXScreen = static_cast<const X11SalGraphics&>(rGraphics).GetScreenNumber();
+ mnWidth = nDX;
+ mnHeight = nDY;
+ mpGraphics->Init(this);
+}
+
+X11SkiaSalVirtualDevice::~X11SkiaSalVirtualDevice() {}
+
+SalGraphics* X11SkiaSalVirtualDevice::AcquireGraphics()
+{
+ if (mbGraphics)
+ return nullptr;
+
+ if (mpGraphics)
+ mbGraphics = true;
+
+ return mpGraphics.get();
+}
+
+void X11SkiaSalVirtualDevice::ReleaseGraphics(SalGraphics*) { mbGraphics = false; }
+
+bool X11SkiaSalVirtualDevice::SetSize(tools::Long nDX, tools::Long nDY)
+{
+ if (!nDX)
+ nDX = 1;
+ if (!nDY)
+ nDY = 1;
+
+ mnWidth = nDX;
+ mnHeight = nDY;
+ if (mpGraphics)
+ mpGraphics->Init(this);
+
+ return true;
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/skia/x11/textrender.cxx b/vcl/skia/x11/textrender.cxx
new file mode 100644
index 000000000..7d344b8a2
--- /dev/null
+++ b/vcl/skia/x11/textrender.cxx
@@ -0,0 +1,103 @@
+/* -*- 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 <sal/config.h>
+
+#include <skia/x11/textrender.hxx>
+
+#include <unx/fc_fontoptions.hxx>
+#include <unx/freetype_glyphcache.hxx>
+#include <vcl/svapp.hxx>
+#include <sallayout.hxx>
+#include <skia/gdiimpl.hxx>
+
+#include <SkFont.h>
+#include <SkFontMgr_fontconfig.h>
+
+void SkiaTextRender::DrawTextLayout(const GenericSalLayout& rLayout, const SalGraphics& rGraphics)
+{
+ const FreetypeFontInstance& rInstance = static_cast<FreetypeFontInstance&>(rLayout.GetFont());
+ const FreetypeFont& rFont = rInstance.GetFreetypeFont();
+ const vcl::font::FontSelectPattern& rFSD = rInstance.GetFontSelectPattern();
+ int nHeight = rFSD.mnHeight;
+ int nWidth = rFSD.mnWidth ? rFSD.mnWidth : nHeight;
+ if (nWidth == 0 || nHeight == 0)
+ return;
+
+ if (FreetypeFont::AlmostHorizontalDrainsRenderingPool(nWidth * 10 / nHeight, rFSD))
+ return;
+
+ if (!fontManager)
+ {
+ // Get the global FcConfig that our VCL fontconfig code uses, and refcount it.
+ fontManager = SkFontMgr_New_FontConfig(FcConfigReference(nullptr));
+ }
+ sk_sp<SkTypeface> typeface
+ = SkFontMgr_createTypefaceFromFcPattern(fontManager, rFont.GetFontOptions()->GetPattern());
+ SkFont font(typeface);
+ font.setSize(nHeight);
+ font.setScaleX(1.0 * nWidth / nHeight);
+ if (rFont.NeedsArtificialItalic())
+ font.setSkewX(1.0 * -0x4000L / 0x10000L);
+ if (rFont.NeedsArtificialBold())
+ font.setEmbolden(true);
+
+ bool bSubpixelPositioning = rGraphics.getTextRenderModeForResolutionIndependentLayoutEnabled();
+ SkFont::Edging ePreferredAliasing
+ = bSubpixelPositioning ? SkFont::Edging::kSubpixelAntiAlias : SkFont::Edging::kAntiAlias;
+ if (bSubpixelPositioning)
+ {
+ // note that SkFont defaults to a BaselineSnap of true, so I think really only
+ // subpixel in text direction
+ font.setSubpixel(true);
+
+ SkFontHinting eHinting = font.getHinting();
+ bool bAllowedHintStyle
+ = eHinting == SkFontHinting::kNone || eHinting == SkFontHinting::kSlight;
+ if (!bAllowedHintStyle)
+ font.setHinting(SkFontHinting::kSlight);
+ }
+
+ font.setEdging(rFont.GetAntialiasAdvice() ? ePreferredAliasing : SkFont::Edging::kAlias);
+
+ // Vertical font, use width as "height".
+ SkFont verticalFont(font);
+ verticalFont.setSize(nWidth);
+ verticalFont.setScaleX(1.0 * nHeight / nWidth);
+
+ assert(dynamic_cast<SkiaSalGraphicsImpl*>(rGraphics.GetImpl()));
+ SkiaSalGraphicsImpl* impl = static_cast<SkiaSalGraphicsImpl*>(rGraphics.GetImpl());
+ impl->drawGenericLayout(rLayout, mnTextColor, font, verticalFont);
+}
+
+void SkiaTextRender::ClearDevFontCache() { fontManager.reset(); }
+
+#if 0
+// SKIA TODO
+void FontConfigFontOptions::cairo_font_options_substitute(FcPattern* pPattern)
+{
+ ImplSVData* pSVData = ImplGetSVData();
+ const cairo_font_options_t* pFontOptions = pSVData->mpDefInst->GetCairoFontOptions();
+ if( !pFontOptions )
+ return;
+ cairo_ft_font_options_substitute(pFontOptions, pPattern);
+}
+#endif
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */