[Libreoffice-commits] core.git: external/skia vcl/inc vcl/Library_vclplug_osx.mk vcl/osx vcl/quartz vcl/skia
LuboÅ¡ LuÅák (via logerrit)
logerrit at kemper.freedesktop.org
Mon Aug 23 12:59:43 UTC 2021
external/skia/make-api-visible.patch.1 | 8 --
vcl/Library_vclplug_osx.mk | 7 ++
vcl/inc/quartz/salgdi.h | 26 ++++++++-
vcl/inc/skia/osx/gdiimpl.hxx | 42 ++++++++++++++
vcl/inc/skia/osx/rastercontext.hxx | 42 ++++++++++++++
vcl/osx/salinst.cxx | 22 +++++++
vcl/osx/salmacos.cxx | 2
vcl/quartz/AquaGraphicsBackend.cxx | 2
vcl/quartz/salgdi.cxx | 18 +++++-
vcl/skia/osx/gdiimpl.cxx | 93 +++++++++++++++++++++++++++++++++
vcl/skia/osx/rastercontext.cxx | 51 ++++++++++++++++++
11 files changed, 298 insertions(+), 15 deletions(-)
New commits:
commit 13acc8a5df8db5fa24d72c1d44b35e41e4ca2a7c
Author: Luboš Luňák <l.lunak at collabora.com>
AuthorDate: Thu Aug 12 13:24:07 2021 +0200
Commit: Luboš Luňák <l.lunak at collabora.com>
CommitDate: Mon Aug 23 14:59:08 2021 +0200
first WIP version of mac skia SalGraphics backend
It doesn't yet blit to screen, but the basics should be there.
Change-Id: I0f77b66756f578d84d0cee16cda00e7a2fea714f
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/120805
Tested-by: Jenkins
Reviewed-by: Luboš Luňák <l.lunak at collabora.com>
diff --git a/external/skia/make-api-visible.patch.1 b/external/skia/make-api-visible.patch.1
index 6f2cd3b05a6c..822313006dc6 100644
--- a/external/skia/make-api-visible.patch.1
+++ b/external/skia/make-api-visible.patch.1
@@ -1,15 +1,11 @@
--- a/tools/sk_app/WindowContext.h
+++ b/tools/sk_app/WindowContext.h
-@@ -17,7 +17,11 @@
+@@ -18,7 +18,7 @@
namespace sk_app {
-class WindowContext {
-+class
-+#if defined __clang__ && !defined _MSC_VER
-+__attribute__((type_visibility("default")))
-+#endif
-+WindowContext {
++class SK_API WindowContext {
public:
WindowContext(const DisplayParams&);
diff --git a/vcl/Library_vclplug_osx.mk b/vcl/Library_vclplug_osx.mk
index 4b2b4a61b3f4..3e0e0ff481be 100644
--- a/vcl/Library_vclplug_osx.mk
+++ b/vcl/Library_vclplug_osx.mk
@@ -57,6 +57,9 @@ $(eval $(call gb_Library_use_libraries,vclplug_osx,\
$(eval $(call gb_Library_use_externals,vclplug_osx,\
boost_headers \
harfbuzz \
+ $(if $(filter SKIA,$(BUILD_TYPE)), \
+ skia \
+ ) \
))
ifeq ($(DISABLE_GUI),)
@@ -138,6 +141,10 @@ $(eval $(call gb_Library_add_exception_objects,vclplug_osx,\
vcl/quartz/salvd \
vcl/quartz/utils \
vcl/quartz/AquaGraphicsBackend \
+ $(if $(filter SKIA,$(BUILD_TYPE)), \
+ vcl/skia/osx/gdiimpl \
+ vcl/skia/osx/rastercontext \
+ ) \
))
$(eval $(call gb_Library_use_system_darwin_frameworks,vclplug_osx,\
diff --git a/vcl/inc/quartz/salgdi.h b/vcl/inc/quartz/salgdi.h
index afddffb6a9f9..ab7a25ee9b7c 100644
--- a/vcl/inc/quartz/salgdi.h
+++ b/vcl/inc/quartz/salgdi.h
@@ -267,11 +267,31 @@ struct AquaSharedAttributes
}
};
-class AquaGraphicsBackend final : public SalGraphicsImpl
+class AquaGraphicsBackendBase
{
private:
+ SalGraphicsImpl* mpImpl = nullptr;
+protected:
AquaSharedAttributes& mrShared;
+public:
+ AquaGraphicsBackendBase(AquaSharedAttributes& rShared)
+ : mrShared( rShared )
+ {}
+ virtual ~AquaGraphicsBackendBase() = 0;
+ AquaSharedAttributes& GetShared() { return mrShared; }
+ SalGraphicsImpl* GetImpl()
+ {
+ if(mpImpl == nullptr)
+ mpImpl = dynamic_cast<SalGraphicsImpl*>(this);
+ return mpImpl;
+ }
+};
+
+inline AquaGraphicsBackendBase::~AquaGraphicsBackendBase() {}
+class AquaGraphicsBackend final : public SalGraphicsImpl, public AquaGraphicsBackendBase
+{
+private:
void drawPixelImpl( tools::Long nX, tools::Long nY, const RGBAColor& rColor); // helper to draw single pixels
#ifdef MACOSX
@@ -400,7 +420,7 @@ public:
class AquaSalGraphics : public SalGraphicsAutoDelegateToImpl
{
AquaSharedAttributes maShared;
- std::unique_ptr<AquaGraphicsBackend> mpBackend;
+ std::unique_ptr<AquaGraphicsBackendBase> mpBackend;
/// device resolution of this graphics
sal_Int32 mnRealDPIX;
@@ -443,7 +463,7 @@ public:
// InvalidateContext does an UnsetState and sets mrContext to 0
void InvalidateContext();
- AquaGraphicsBackend* getAquaGraphicsBackend() const
+ AquaGraphicsBackendBase* getAquaGraphicsBackend() const
{
return mpBackend.get();
}
diff --git a/vcl/inc/skia/osx/gdiimpl.hxx b/vcl/inc/skia/osx/gdiimpl.hxx
new file mode 100644
index 000000000000..8523d272e897
--- /dev/null
+++ b/vcl/inc/skia/osx/gdiimpl.hxx
@@ -0,0 +1,42 @@
+/* -*- 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_OSX_GDIIMPL_HXX
+#define INCLUDED_VCL_INC_SKIA_OSX_GDIIMPL_HXX
+
+#include <vcl/dllapi.h>
+
+#include <quartz/salgdi.h>
+
+#include <skia/gdiimpl.hxx>
+#include <skia/utils.hxx>
+
+class VCL_PLUGIN_PUBLIC AquaSkiaSalGraphicsImpl final : public SkiaSalGraphicsImpl,
+ public AquaGraphicsBackendBase
+{
+public:
+ AquaSkiaSalGraphicsImpl(AquaSalGraphics& rParent, AquaSharedAttributes& rShared);
+ virtual ~AquaSkiaSalGraphicsImpl() override;
+
+ virtual void Init() override;
+ virtual void DeInit() override;
+ virtual void freeResources() override;
+ // virtual void Flush() override;
+
+ static void prepareSkia();
+
+private:
+ virtual void createWindowContext(bool forceRaster = false) override;
+ virtual void performFlush() override;
+ friend std::unique_ptr<sk_app::WindowContext> createVulkanWindowContext(bool);
+};
+
+#endif // INCLUDED_VCL_INC_SKIA_OSX_GDIIMPL_HXX
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/inc/skia/osx/rastercontext.hxx b/vcl/inc/skia/osx/rastercontext.hxx
new file mode 100644
index 000000000000..84891d4b8642
--- /dev/null
+++ b/vcl/inc/skia/osx/rastercontext.hxx
@@ -0,0 +1,42 @@
+/* -*- 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_OSX_RASTERCONTEXT_HXX
+#define INCLUDED_VCL_INC_SKIA_OSX_RASTERCONTEXT_HXX
+
+#include <tools/sk_app/WindowContext.h>
+
+class AquaSkiaSalGraphicsImpl;
+
+// RasterWindowContext_mac uses OpenGL internally, which
+// we don't want, so make our own raster window context
+// based on SkBitmap, and our code will handle things like flush.
+
+class AquaSkiaWindowContextRaster : public sk_app::WindowContext
+{
+public:
+ AquaSkiaWindowContextRaster(int w, int h, const sk_app::DisplayParams& params);
+ virtual sk_sp<SkSurface> getBackbufferSurface() override { return mSurface; }
+ // Not to be called, our mac code should be used.
+ virtual void swapBuffers(const SkIRect* = nullptr) override { abort(); }
+ virtual bool isValid() override { return mSurface.get(); };
+ virtual void resize(int w, int h) override;
+ virtual void setDisplayParams(const sk_app::DisplayParams& params) override;
+
+protected:
+ virtual bool isGpuContext() override { return false; }
+
+private:
+ void createSurface();
+ sk_sp<SkSurface> mSurface;
+};
+
+#endif // INCLUDED_VCL_INC_SKIA_OSX_RASTERCONTEXT_HXX
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/osx/salinst.cxx b/vcl/osx/salinst.cxx
index 75aea4d5415a..08fae66b4ad3 100644
--- a/vcl/osx/salinst.cxx
+++ b/vcl/osx/salinst.cxx
@@ -73,6 +73,13 @@
#include <apple_remote/RemoteControl.h>
#include <postmac.h>
+#include <config_features.h>
+#if HAVE_FEATURE_SKIA
+#include <vcl/skia/SkiaHelper.hxx>
+#include <skia/salbmp.hxx>
+#include <skia/osx/gdiimpl.hxx>
+#endif
+
extern "C" {
#include <crt_externs.h>
}
@@ -350,6 +357,10 @@ AquaSalInstance::AquaSalInstance()
ImplSVData* pSVData = ImplGetSVData();
pSVData->maAppData.mxToolkitName = OUString("osx");
+
+#if HAVE_FEATURE_SKIA
+ AquaSkiaSalGraphicsImpl::prepareSkia();
+#endif
}
AquaSalInstance::~AquaSalInstance()
@@ -361,6 +372,10 @@ AquaSalInstance::~AquaSalInstance()
[pDockMenu release];
pDockMenu = nil;
}
+
+#if HAVE_FEATURE_SKIA
+ SkiaHelper::cleanup();
+#endif
}
void AquaSalInstance::TriggerUserEventProcessing()
@@ -877,7 +892,12 @@ SalSystem* AquaSalInstance::CreateSalSystem()
std::shared_ptr<SalBitmap> AquaSalInstance::CreateSalBitmap()
{
- return std::make_shared<QuartzSalBitmap>();
+#if HAVE_FEATURE_SKIA
+ if (SkiaHelper::isVCLSkiaEnabled())
+ return std::make_shared<SkiaSalBitmap>();
+ else
+#endif
+ return std::make_shared<QuartzSalBitmap>();
}
OUString AquaSalInstance::getOSVersion()
diff --git a/vcl/osx/salmacos.cxx b/vcl/osx/salmacos.cxx
index bc5afba086b1..78b06fc911dd 100644
--- a/vcl/osx/salmacos.cxx
+++ b/vcl/osx/salmacos.cxx
@@ -103,7 +103,7 @@ void AquaGraphicsBackend::copyBits(const SalTwoRect &rPosAry, SalGraphics *pSrcG
if (pSrcGraphics)
{
AquaSalGraphics* pSrc = static_cast<AquaSalGraphics*>(pSrcGraphics);
- pSrcShared = &pSrc->getAquaGraphicsBackend()->mrShared;
+ pSrcShared = &pSrc->getAquaGraphicsBackend()->GetShared();
}
else
pSrcShared = &mrShared;
diff --git a/vcl/quartz/AquaGraphicsBackend.cxx b/vcl/quartz/AquaGraphicsBackend.cxx
index ee3362e4462b..056d2cd0e32f 100644
--- a/vcl/quartz/AquaGraphicsBackend.cxx
+++ b/vcl/quartz/AquaGraphicsBackend.cxx
@@ -191,7 +191,7 @@ void drawPattern50(void*, CGContextRef rContext)
}
AquaGraphicsBackend::AquaGraphicsBackend(AquaSharedAttributes& rShared)
- : mrShared(rShared)
+ : AquaGraphicsBackendBase(rShared)
{
}
diff --git a/vcl/quartz/salgdi.cxx b/vcl/quartz/salgdi.cxx
index c938cf772030..1fa3d425a6d4 100644
--- a/vcl/quartz/salgdi.cxx
+++ b/vcl/quartz/salgdi.cxx
@@ -56,6 +56,12 @@
#include <sallayout.hxx>
#include <sft.hxx>
+#include <config_features.h>
+#include <vcl/skia/SkiaHelper.hxx>
+#if HAVE_FEATURE_SKIA
+#include <skia/osx/gdiimpl.hxx>
+#endif
+
using namespace vcl;
namespace {
@@ -186,14 +192,20 @@ bool CoreTextFontFace::GetFontCapabilities(vcl::FontCapabilities &rFontCapabilit
}
AquaSalGraphics::AquaSalGraphics()
- : mpBackend(new AquaGraphicsBackend(maShared))
- , mnRealDPIX( 0 )
+ : mnRealDPIX( 0 )
, mnRealDPIY( 0 )
, maTextColor( COL_BLACK )
, mbNonAntialiasedText( false )
{
SAL_INFO( "vcl.quartz", "AquaSalGraphics::AquaSalGraphics() this=" << this );
+#if HAVE_FEATURE_SKIA
+ if(SkiaHelper::isVCLSkiaEnabled())
+ mpBackend.reset(new AquaSkiaSalGraphicsImpl(*this, maShared));
+#endif
+ else
+ mpBackend.reset(new AquaGraphicsBackend(maShared));
+
for (int i = 0; i < MAX_FALLBACK; ++i)
mpTextStyle[i] = nullptr;
@@ -233,7 +245,7 @@ AquaSalGraphics::~AquaSalGraphics()
SalGraphicsImpl* AquaSalGraphics::GetImpl() const
{
- return mpBackend.get();
+ return mpBackend->GetImpl();
}
void AquaSalGraphics::SetTextColor( Color nColor )
diff --git a/vcl/skia/osx/gdiimpl.cxx b/vcl/skia/osx/gdiimpl.cxx
new file mode 100644
index 000000000000..e15406ea831c
--- /dev/null
+++ b/vcl/skia/osx/gdiimpl.cxx
@@ -0,0 +1,93 @@
+/* -*- 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/osx/gdiimpl.hxx>
+
+#include <skia/utils.hxx>
+#include <skia/zone.hxx>
+
+#include <skia/osx/rastercontext.hxx>
+
+using namespace SkiaHelper;
+
+AquaSkiaSalGraphicsImpl::AquaSkiaSalGraphicsImpl(AquaSalGraphics& rParent,
+ AquaSharedAttributes& rShared)
+ : SkiaSalGraphicsImpl(rParent, rShared.mpFrame)
+ , AquaGraphicsBackendBase(rShared)
+{
+}
+
+AquaSkiaSalGraphicsImpl::~AquaSkiaSalGraphicsImpl() { DeInit(); }
+
+void AquaSkiaSalGraphicsImpl::Init()
+{
+ // The m_pFrame and m_pVDev pointers are updated late in X11
+ // setProvider(mX11Parent.GetGeometryProvider());
+ // SkiaSalGraphicsImpl::Init();
+}
+
+void AquaSkiaSalGraphicsImpl::DeInit()
+{
+ SkiaZone zone;
+ SkiaSalGraphicsImpl::DeInit();
+ mWindowContext.reset();
+}
+
+void AquaSkiaSalGraphicsImpl::freeResources() {}
+
+void AquaSkiaSalGraphicsImpl::createWindowContext(bool forceRaster)
+{
+ SkiaZone zone;
+ sk_app::DisplayParams displayParams;
+ displayParams.fColorType = kN32_SkColorType;
+ RenderMethod renderMethod = forceRaster ? RenderRaster : renderMethodToUse();
+ switch (renderMethod)
+ {
+ case RenderRaster:
+ displayParams.fColorType = kBGRA_8888_SkColorType; // TODO
+ mWindowContext.reset(
+ new AquaSkiaWindowContextRaster(GetWidth(), GetHeight(), displayParams));
+ break;
+ case RenderVulkan:
+ abort();
+ break;
+ }
+}
+
+//void AquaSkiaSalGraphicsImpl::Flush() { performFlush(); }
+
+void AquaSkiaSalGraphicsImpl::performFlush()
+{
+ SkiaZone zone;
+ flushDrawing();
+ if (mWindowContext)
+ {
+ if (mDirtyRect.intersect(SkIRect::MakeWH(GetWidth(), GetHeight())))
+ mWindowContext->swapBuffers(&mDirtyRect); // TODO
+ mDirtyRect.setEmpty();
+ }
+}
+
+std::unique_ptr<sk_app::WindowContext> createVulkanWindowContext(bool /*temporary*/)
+{
+ return nullptr;
+}
+
+void AquaSkiaSalGraphicsImpl::prepareSkia() { SkiaHelper::prepareSkia(createVulkanWindowContext); }
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/skia/osx/rastercontext.cxx b/vcl/skia/osx/rastercontext.cxx
new file mode 100644
index 000000000000..a2a514483710
--- /dev/null
+++ b/vcl/skia/osx/rastercontext.cxx
@@ -0,0 +1,51 @@
+/* -*- 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/osx/rastercontext.hxx>
+
+#include <SkSurface.h>
+
+AquaSkiaWindowContextRaster::AquaSkiaWindowContextRaster(int w, int h,
+ const sk_app::DisplayParams& params)
+ : WindowContext(params)
+{
+ fWidth = w;
+ fHeight = h;
+ resize(w, h);
+}
+
+void AquaSkiaWindowContextRaster::resize(int w, int h)
+{
+ fWidth = w;
+ fHeight = h;
+ createSurface();
+}
+
+void AquaSkiaWindowContextRaster::setDisplayParams(const sk_app::DisplayParams& params)
+{
+ fDisplayParams = params;
+}
+
+void AquaSkiaWindowContextRaster::createSurface()
+{
+ SkImageInfo info = SkImageInfo::Make(fWidth, fHeight, fDisplayParams.fColorType,
+ kPremul_SkAlphaType, fDisplayParams.fColorSpace);
+ mSurface = SkSurface::MakeRaster(info, &fDisplayParams.fSurfaceProps);
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
More information about the Libreoffice-commits
mailing list