diff options
author | Luboš Luňák <l.lunak@collabora.com> | 2019-07-30 15:14:02 +0200 |
---|---|---|
committer | Luboš Luňák <l.lunak@collabora.com> | 2019-07-30 15:14:02 +0200 |
commit | 3d9784325f56d23eda48b0f370e16d14f6478da6 (patch) | |
tree | b55e5ac045f5ac5e4cca9179e4c3b3b26641a79c | |
parent | 4c611d5b943e7527a0d77146fbd21bda844ca124 (diff) |
WIP skia integration
Change-Id: I3c810d8eaf242527e6274cb59c7caaa7da30bb23
-rw-r--r-- | RepositoryExternal.mk | 1 | ||||
-rw-r--r-- | include/vcl/skia/SkiaHelper.hxx | 32 | ||||
-rw-r--r-- | vcl/Library_vcl.mk | 1 | ||||
-rw-r--r-- | vcl/Library_vclplug_gen.mk | 1 | ||||
-rw-r--r-- | vcl/inc/skia/salbmp.hxx | 65 | ||||
-rw-r--r-- | vcl/inc/skia/skiagdiimpl.hxx | 298 | ||||
-rw-r--r-- | vcl/inc/skia/x11/gdiimpl.hxx | 49 | ||||
-rw-r--r-- | vcl/inc/skia/x11/salvd.hxx | 46 | ||||
-rw-r--r-- | vcl/inc/unx/salgdi.h | 1 | ||||
-rw-r--r-- | vcl/source/app/svapp.cxx | 1 | ||||
-rw-r--r-- | vcl/source/gdi/bitmap3.cxx | 1 | ||||
-rw-r--r-- | vcl/source/outdev/bitmap.cxx | 2 | ||||
-rw-r--r-- | vcl/source/skia/SkiaHelper.cxx | 86 | ||||
-rw-r--r-- | vcl/unx/generic/app/saldisp.cxx | 1 | ||||
-rw-r--r-- | vcl/unx/generic/gdi/salbmp.cxx | 6 | ||||
-rw-r--r-- | vcl/unx/generic/gdi/salgdi.cxx | 17 | ||||
-rw-r--r-- | vcl/unx/generic/gdi/salvd.cxx | 6 | ||||
-rw-r--r-- | vcl/unx/generic/gdi/skiax11cairotextrender.hxx | 27 |
18 files changed, 635 insertions, 6 deletions
diff --git a/RepositoryExternal.mk b/RepositoryExternal.mk index b2292a8367d5..07017f520183 100644 --- a/RepositoryExternal.mk +++ b/RepositoryExternal.mk @@ -119,6 +119,7 @@ define gb_LinkTarget__use_skia $(call gb_LinkTarget_set_include,$(1),\ -I$(call gb_UnpackedTarball_get_dir,skia)/include/core \ -I$(call gb_UnpackedTarball_get_dir,skia)/include/config \ + -I$(call gb_UnpackedTarball_get_dir,skia) \ $$(INCLUDE) \ ) $(call gb_LinkTarget_use_external_project,$(1),skia) diff --git a/include/vcl/skia/SkiaHelper.hxx b/include/vcl/skia/SkiaHelper.hxx new file mode 100644 index 000000000000..3e6df274614b --- /dev/null +++ b/include/vcl/skia/SkiaHelper.hxx @@ -0,0 +1,32 @@ +/* -*- 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_SKIA_SKIAHELPER_HXX +#define INCLUDED_VCL_SKIA_SKIAHELPER_HXX + +#include <epoxy/gl.h> +#include <sal/detail/log.h> +#include <vcl/dllapi.h> +#include <vcl/bitmapex.hxx> + +#include <rtl/ustring.hxx> +#include <sstream> + +// All member functions static and VCL_DLLPUBLIC. Basically a glorified namespace. +struct VCL_DLLPUBLIC SkiaHelper +{ + SkiaHelper() = delete; // Should not be instantiated + +public: + static bool isVCLSkiaEnabled(); +}; + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/vcl/Library_vcl.mk b/vcl/Library_vcl.mk index 1c3f0b31eb2d..e11170a42073 100644 --- a/vcl/Library_vcl.mk +++ b/vcl/Library_vcl.mk @@ -568,6 +568,7 @@ $(eval $(call gb_Library_add_exception_objects,vcl,\ vcl/opengl/LineRenderUtils \ vcl/source/opengl/OpenGLContext \ vcl/source/opengl/OpenGLHelper \ + vcl/source/skia/SkiaHelper \ )) # runtime dependency diff --git a/vcl/Library_vclplug_gen.mk b/vcl/Library_vclplug_gen.mk index 8781324a6da6..21ed5bfef1e7 100644 --- a/vcl/Library_vclplug_gen.mk +++ b/vcl/Library_vclplug_gen.mk @@ -58,6 +58,7 @@ $(eval $(call gb_Library_use_externals,vclplug_gen,\ icuuc \ valgrind \ Xrender \ + skia \ )) $(eval $(call gb_Library_add_libs,vclplug_gen,\ diff --git a/vcl/inc/skia/salbmp.hxx b/vcl/inc/skia/salbmp.hxx new file mode 100644 index 000000000000..f8c9aa65540b --- /dev/null +++ b/vcl/inc/skia/salbmp.hxx @@ -0,0 +1,65 @@ +/* -*- 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_INC_SKIA_SALBMP_H +#define INCLUDED_VCL_INC_SKIA_SALBMP_H + +#include <salbmp.hxx> + +#include <SkBitmap.h> + +class VCL_PLUGIN_PUBLIC SkiaSalBitmap : public SalBitmap +{ +public: + SkiaSalBitmap(); + virtual ~SkiaSalBitmap() override; + +public: + // SalBitmap methods + bool Create(const Size& rSize, sal_uInt16 nBitCount, const BitmapPalette& rPal) override; + bool Create(const SalBitmap& rSalBmp) override; + bool Create(const SalBitmap& rSalBmp, SalGraphics* pGraphics) override; + bool Create(const SalBitmap& rSalBmp, sal_uInt16 nNewBitCount) override; + virtual bool Create(const css::uno::Reference<css::rendering::XBitmapCanvas>& rBitmapCanvas, + Size& rSize, bool bMask = false) override; + + void Destroy() final override; + + Size GetSize() const override; + sal_uInt16 GetBitCount() const override; + + BitmapBuffer* AcquireBuffer(BitmapAccessMode nMode) override; + void ReleaseBuffer(BitmapBuffer* pBuffer, BitmapAccessMode nMode) override; + + bool GetSystemData(BitmapSystemData& rData) override; + + bool ScalingSupported() const override; + bool Scale(const double& rScaleX, const double& rScaleY, BmpScaleFlag nScaleFlag) override; + bool Replace(const Color& rSearchColor, const Color& rReplaceColor, sal_uInt8 nTol) override; + bool ConvertToGreyscale() override; + + void ImplScale(const double& rScaleX, const double& rScaleY, BmpScaleFlag nScaleFlag); + +private: + SkBitmap mBitmap; +}; + +#endif // INCLUDED_VCL_INC_OPENGL_SALBMP_H + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/vcl/inc/skia/skiagdiimpl.hxx b/vcl/inc/skia/skiagdiimpl.hxx new file mode 100644 index 000000000000..e6c07afa5f0d --- /dev/null +++ b/vcl/inc/skia/skiagdiimpl.hxx @@ -0,0 +1,298 @@ +/* -*- 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_SKIA_SKIAGDIIMPL_HXX +#define INCLUDED_VCL_SKIA_SKIAGDIIMPL_HXX + +#include <vcl/dllapi.h> + +class VCL_DLLPUBLIC SkiaSalGraphicsImpl : public SalGraphicsImpl +{ +protected: + SalGraphics& mrParent; + /// Pointer to the SalFrame or SalVirtualDevice + SalGeometryProvider* mpProvider; + + // clipping + vcl::Region maClipRegion; + bool mbUseScissor; + bool mbUseStencil; + + bool mbXORMode; + + bool mbAcquiringSkiaContext; + + Color mnLineColor; + Color mnFillColor; +#ifdef DBG_UTIL + bool mProgramIsSolidColor; +#endif + sal_uInt32 mnDrawCount; + sal_uInt32 mnDrawCountAtFlush; + Color mProgramSolidColor; + double mProgramSolidTransparency; + + std::unique_ptr<RenderList> mpRenderList; + + void ImplInitClipRegion(); + void ImplSetClipBit(const vcl::Region& rClip, GLuint nMask); + void ImplDrawLineAA(double nX1, double nY1, double nX2, double nY2, bool edge); + void CheckOffscreenTexture(); + + void ApplyProgramMatrices(float fPixelOffset = 0.0); + +public: + bool UseProgram(const OUString& rVertexShader, const OUString& rFragmentShader, + const OString& preamble = ""); + bool UseSolid(Color nColor, sal_uInt8 nTransparency); + bool UseSolid(Color nColor, double fTransparency); + bool UseSolid(Color nColor); + void UseSolid(); + bool UseLine(Color nColor, double fTransparency, GLfloat fLineWidth, bool bUseAA); + void UseLine(GLfloat fLineWidth, bool bUseAA); + bool UseInvert50(); + bool UseInvert(SalInvert nFlags); + + void DrawConvexPolygon(sal_uInt32 nPoints, const SalPoint* pPtAry, bool blockAA = false); + void DrawConvexPolygon(const tools::Polygon& rPolygon, bool blockAA); + void DrawTrapezoid(const basegfx::B2DTrapezoid& trapezoid, bool blockAA); + void DrawRect(long nX, long nY, long nWidth, long nHeight); + void DrawRect(const tools::Rectangle& rRect); + void DrawPolygon(sal_uInt32 nPoints, const SalPoint* pPtAry); + void DrawLineSegment(float x1, float y1, float x2, float y2); + void DrawPolyPolygon(const basegfx::B2DPolyPolygon& rPolyPolygon, bool blockAA = false); + void DrawRegionBand(const RegionBand& rRegion); + void DrawTextureRect(const SalTwoRect& rPosAry); + // void DrawTexture( OpenGLTexture& rTexture, const SalTwoRect& rPosAry, bool bInverted = false ); + // void DrawTransformedTexture( OpenGLTexture& rTexture, OpenGLTexture& rMask, const basegfx::B2DPoint& rNull, const basegfx::B2DPoint& rX, const basegfx::B2DPoint& rY ); + // void DrawAlphaTexture( OpenGLTexture& rTexture, const SalTwoRect& rPosAry, bool bInverted, bool pPremultiplied ); + // void DrawTextureDiff( OpenGLTexture& rTexture, OpenGLTexture& rMask, const SalTwoRect& rPosAry, bool bInverted ); + // void DrawTextureWithMask( OpenGLTexture& rTexture, OpenGLTexture& rMask, const SalTwoRect& rPosAry ); + // void DrawBlendedTexture( OpenGLTexture& rTexture, OpenGLTexture& rMask, OpenGLTexture& rAlpha, const SalTwoRect& rPosAry ); + // void DrawMask( OpenGLTexture& rTexture, Color nMaskColor, const SalTwoRect& rPosAry ); + void DrawLinearGradient(const Gradient& rGradient, const tools::Rectangle& rRect); + void DrawAxialGradient(const Gradient& rGradient, const tools::Rectangle& rRect); + void DrawRadialGradient(const Gradient& rGradient, const tools::Rectangle& rRect); + // void DeferredTextDraw(OpenGLTexture const & rTexture, const Color nMaskColor, const SalTwoRect& rPosAry); + + void FlushDeferredDrawing(); + void FlushLinesOrTriangles(DrawShaderType eType, RenderParameters const& rParameters); + +public: + // get the width of the device + GLfloat GetWidth() const { return mpProvider ? mpProvider->GetWidth() : 1; } + + // get the height of the device + GLfloat GetHeight() const { return mpProvider ? mpProvider->GetHeight() : 1; } + + /** + * check whether this instance is used for offscreen (Virtual Device) + * rendering ie. does it need its own context. + */ + bool IsOffscreen() const { return mpProvider == nullptr || mpProvider->IsOffScreen(); } + + /// Oddly not all operations obey the XOR option. + enum XOROption + { + IGNORE_XOR, + IMPLEMENT_XOR + }; + + // initialize pre-draw state + void InitializePreDrawState(XOROption eOpt); + + // operations to do before painting + void PreDraw(XOROption eOpt = IGNORE_XOR); + + // operations to do after painting + void PostDraw(); + + void PostBatchDraw(); + +protected: + bool AcquireContext(bool bForceCreate = false); + void ReleaseContext(); + +public: + SkiaSalGraphicsImpl(SalGraphics& pParent, SalGeometryProvider* pProvider); + virtual ~SkiaSalGraphicsImpl() override; + + virtual void Init() override; + + virtual void DeInit() override; + + virtual void freeResources() override; + + const vcl::Region& getClipRegion() const; + virtual bool setClipRegion(const vcl::Region&) override; + + // + // get the depth of the device + virtual sal_uInt16 GetBitCount() const override; + + // get the width of the device + virtual long GetGraphicsWidth() const override; + + // set the clip region to empty + virtual void ResetClipRegion() override; + + // set the line color to transparent (= don't draw lines) + + virtual void SetLineColor() override; + + // set the line color to a specific color + virtual void SetLineColor(Color nColor) override; + + // set the fill color to transparent (= don't fill) + virtual void SetFillColor() override; + + // set the fill color to a specific color, shapes will be + // filled accordingly + virtual void SetFillColor(Color nColor) override; + + // enable/disable XOR drawing + virtual void SetXORMode(bool bSet, bool bInvertOnly) override; + + // set line color for raster operations + virtual void SetROPLineColor(SalROPColor nROPColor) override; + + // set fill color for raster operations + virtual void SetROPFillColor(SalROPColor nROPColor) override; + + // draw --> LineColor and FillColor and RasterOp and ClipRegion + virtual void drawPixel(long nX, long nY) override; + virtual void drawPixel(long nX, long nY, Color nColor) override; + + virtual void drawLine(long nX1, long nY1, long nX2, long nY2) override; + + virtual void drawRect(long nX, long nY, long nWidth, long nHeight) override; + + virtual void drawPolyLine(sal_uInt32 nPoints, const SalPoint* pPtAry) override; + + virtual void drawPolygon(sal_uInt32 nPoints, const SalPoint* pPtAry) override; + + virtual void drawPolyPolygon(sal_uInt32 nPoly, const sal_uInt32* pPoints, + PCONSTSALPOINT* pPtAry) override; + + virtual bool drawPolyPolygon(const basegfx::B2DHomMatrix& rObjectToDevice, + const basegfx::B2DPolyPolygon&, double fTransparency) override; + + virtual bool drawPolyLine(const basegfx::B2DHomMatrix& rObjectToDevice, + const basegfx::B2DPolygon&, double fTransparency, + const basegfx::B2DVector& rLineWidths, basegfx::B2DLineJoin, + css::drawing::LineCap, double fMiterMinimumAngle, + bool bPixelSnapHairline) override; + + virtual bool drawPolyLineBezier(sal_uInt32 nPoints, const SalPoint* pPtAry, + const PolyFlags* pFlgAry) override; + + virtual bool drawPolygonBezier(sal_uInt32 nPoints, const SalPoint* pPtAry, + const PolyFlags* pFlgAry) override; + + virtual bool drawPolyPolygonBezier(sal_uInt32 nPoly, const sal_uInt32* pPoints, + const SalPoint* const* pPtAry, + const PolyFlags* const* pFlgAry) override; + + // CopyArea --> No RasterOp, but ClipRegion + virtual void copyArea(long nDestX, long nDestY, long nSrcX, long nSrcY, long nSrcWidth, + long nSrcHeight, bool bWindowInvalidate) override; + + // CopyBits and DrawBitmap --> RasterOp and ClipRegion + // CopyBits() --> pSrcGraphics == NULL, then CopyBits on same Graphics + void DoCopyBits(const SalTwoRect& rPosAry, SkiaSalGraphicsImpl& rSrcImpl); + + virtual bool blendBitmap(const SalTwoRect&, const SalBitmap& rBitmap) override; + + virtual bool blendAlphaBitmap(const SalTwoRect&, const SalBitmap& rSrcBitmap, + const SalBitmap& rMaskBitmap, + const SalBitmap& rAlphaBitmap) override; + + virtual void drawBitmap(const SalTwoRect& rPosAry, const SalBitmap& rSalBitmap) override; + + virtual void drawBitmap(const SalTwoRect& rPosAry, const SalBitmap& rSalBitmap, + const SalBitmap& rMaskBitmap) override; + + virtual void drawMask(const SalTwoRect& rPosAry, const SalBitmap& rSalBitmap, + Color nMaskColor) override; + + virtual std::shared_ptr<SalBitmap> getBitmap(long nX, long nY, long nWidth, + long nHeight) override; + + virtual Color getPixel(long nX, long nY) override; + + // invert --> ClipRegion (only Windows or VirDevs) + virtual void invert(long nX, long nY, long nWidth, long nHeight, SalInvert nFlags) override; + + virtual void invert(sal_uInt32 nPoints, const SalPoint* pPtAry, SalInvert nFlags) override; + + virtual bool drawEPS(long nX, long nY, long nWidth, long nHeight, void* pPtr, + sal_uInt32 nSize) override; + + /** Render bitmap with alpha channel + + @param rSourceBitmap + Source bitmap to blit + + @param rAlphaBitmap + Alpha channel to use for blitting + + @return true, if the operation succeeded, and false + otherwise. In this case, clients should try to emulate alpha + compositing themselves + */ + virtual bool drawAlphaBitmap(const SalTwoRect&, const SalBitmap& rSourceBitmap, + const SalBitmap& rAlphaBitmap) override; + + /** draw transformed bitmap (maybe with alpha) where Null, X, Y define the coordinate system */ + virtual bool drawTransformedBitmap(const basegfx::B2DPoint& rNull, const basegfx::B2DPoint& rX, + const basegfx::B2DPoint& rY, const SalBitmap& rSourceBitmap, + const SalBitmap* pAlphaBitmap) override; + + /** Render solid rectangle with given transparency + + @param nX Top left coordinate of rectangle + + @param nY Bottom right coordinate of rectangle + + @param nWidth Width of rectangle + + @param nHeight Height of rectangle + + @param nTransparency Transparency value (0-255) to use. 0 blits and opaque, 255 a + fully transparent rectangle + + @returns true if successfully drawn, false if not able to draw rectangle + */ + virtual bool drawAlphaRect(long nX, long nY, long nWidth, long nHeight, + sal_uInt8 nTransparency) override; + + virtual bool drawGradient(const tools::PolyPolygon& rPolygon, + const Gradient& rGradient) override; + + /// queue an idle flush of contents of the back-buffer to the screen + void flush(); + +public: + /// do flush of contents of the back-buffer to the screen & swap. + void doFlush(); +}; + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/vcl/inc/skia/x11/gdiimpl.hxx b/vcl/inc/skia/x11/gdiimpl.hxx new file mode 100644 index 000000000000..6cf260da190e --- /dev/null +++ b/vcl/inc/skia/x11/gdiimpl.hxx @@ -0,0 +1,49 @@ +/* -*- 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_X11_GDIIMPL_HXX +#define INCLUDED_VCL_INC_SKIA_X11_GDIIMPL_HXX + +#include <vcl/dllapi.h> + +#include <unx/salgdi.h> +#include <unx/x11/x11gdiimpl.h> +#include <skia/skiagdiimpl.hxx> + +class VCL_PLUGIN_PUBLIC X11SkiaSalGraphicsImpl : public SkiaSalGraphicsImpl, public X11GraphicsImpl +{ +private: + X11SalGraphics& mrX11Parent; + +public: + X11SkiaSalGraphicsImpl(X11SalGraphics& rParent); + virtual ~X11SkiaSalGraphicsImpl() override; + +protected: + void RenderPixmap(X11Pixmap const* pPixmap, X11Pixmap const* pMask, int nX, int nY, + TextureCombo& rCombo); + +public: + // implementation of X11GraphicsImpl + + virtual void copyBits(const SalTwoRect& rPosAry, SalGraphics* pSrcGraphics) override; + + virtual void Init() override; + + void FillPixmapFromScreen(X11Pixmap* pPixmap, int nX, int nY) override; + bool RenderPixmapToScreen(X11Pixmap* pPixmap, X11Pixmap* pMask, int nX, int nY) override; + + bool RenderAndCacheNativeControl(X11Pixmap* pPixmap, X11Pixmap* pMask, int nX, int nY, + ControlCacheKey& aControlCacheKey) override; + bool TryRenderCachedNativeControl(ControlCacheKey& rControlCacheKey, int nX, int nY) override; +}; + +#endif // INCLUDED_VCL_INC_SKIA_X11_GDIIMPL_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/vcl/inc/skia/x11/salvd.hxx b/vcl/inc/skia/x11/salvd.hxx new file mode 100644 index 000000000000..8ff75175dc70 --- /dev/null +++ b/vcl/inc/skia/x11/salvd.hxx @@ -0,0 +1,46 @@ +/* -*- 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_X11_SALVD_H +#define INCLUDED_VCL_INC_SKIA_X11_SALVD_H + +#include <salvd.hxx> + +class X11SkiaSalVirtualDevice : public SalVirtualDevice +{ + SalDisplay* mpDisplay; + std::unique_ptr<X11SalGraphics> mpGraphics; + bool mbGraphics; // is Graphics used + SalX11Screen mnXScreen; + int mnWidth; + int mnHeight; + +public: + X11SkiaSalVirtualDevice(SalGraphics const* pGraphics, long nDX, long nDY, + const SystemGraphicsData* pData, + std::unique_ptr<X11SalGraphics> pNewGraphics); + virtual ~X11SkiaSalVirtualDevice() override; + + // SalGeometryProvider + virtual long GetWidth() const override { return mnWidth; } + virtual long GetHeight() const override { return mnHeight; } + + SalDisplay* GetDisplay() const { return mpDisplay; } + const SalX11Screen& GetXScreenNumber() const { return mnXScreen; } + + virtual SalGraphics* AcquireGraphics() override; + virtual void ReleaseGraphics(SalGraphics* pGraphics) override; + + // Set new size, without saving the old contents + virtual bool SetSize(long nNewDX, long nNewDY) override; +}; + +#endif // INCLUDED_VCL_INC_SKIA_X11_SALVD_H + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/vcl/inc/unx/salgdi.h b/vcl/inc/unx/salgdi.h index 22f6d8604b83..8bcb824384c8 100644 --- a/vcl/inc/unx/salgdi.h +++ b/vcl/inc/unx/salgdi.h @@ -343,6 +343,7 @@ protected: bool bVirDev_ : 1; // is VirDev bool bFontGC_ : 1; // is Font GC valid bool const m_bOpenGL : 1; + bool const m_bSkia : 1; private: std::unique_ptr<SalGraphicsImpl> mxImpl; diff --git a/vcl/source/app/svapp.cxx b/vcl/source/app/svapp.cxx index 7814e6755fc6..0379a8164e79 100644 --- a/vcl/source/app/svapp.cxx +++ b/vcl/source/app/svapp.cxx @@ -1149,6 +1149,7 @@ OUString Application::GetHWOSConfInfo() aDetails.append( "; " ); aDetails.append( VclResId(SV_APP_UIRENDER) ); +// TODO skia #if HAVE_FEATURE_OPENGL if ( OpenGLWrapper::isVCLOpenGLEnabled() ) aDetails.append( VclResId(SV_APP_GL) ); diff --git a/vcl/source/gdi/bitmap3.cxx b/vcl/source/gdi/bitmap3.cxx index 3f3f36e86112..100bf253b651 100644 --- a/vcl/source/gdi/bitmap3.cxx +++ b/vcl/source/gdi/bitmap3.cxx @@ -834,6 +834,7 @@ bool Bitmap::Scale( const Size& rNewSize, BmpScaleFlag nScaleFlag ) bool Bitmap::HasFastScale() { +// TODO skia #if HAVE_FEATURE_OPENGL return OpenGLHelper::isVCLOpenGLEnabled(); #else diff --git a/vcl/source/outdev/bitmap.cxx b/vcl/source/outdev/bitmap.cxx index 10b58b208db5..d17ff626be4b 100644 --- a/vcl/source/outdev/bitmap.cxx +++ b/vcl/source/outdev/bitmap.cxx @@ -29,6 +29,7 @@ #if HAVE_FEATURE_OPENGL #include <vcl/opengl/OpenGLHelper.hxx> #endif +#include <vcl/skia/SkiaHelper.hxx> #include <vcl/outdev.hxx> #include <vcl/virdev.hxx> #include <vcl/image.hxx> @@ -691,6 +692,7 @@ void OutputDevice::DrawDeviceAlphaBitmap( const Bitmap& rBmp, const AlphaMask& r #if HAVE_FEATURE_OPENGL assert(!OpenGLHelper::isVCLOpenGLEnabled()); #endif + assert(!SkiaHelper::isVCLSkiaEnabled()); tools::Rectangle aBmpRect(Point(), rBmp.GetSizePixel()); if (!aBmpRect.Intersection(tools::Rectangle(rSrcPtPixel, rSrcSizePixel)).IsEmpty()) { diff --git a/vcl/source/skia/SkiaHelper.cxx b/vcl/source/skia/SkiaHelper.cxx new file mode 100644 index 000000000000..560e2a469cb9 --- /dev/null +++ b/vcl/source/skia/SkiaHelper.cxx @@ -0,0 +1,86 @@ +/* -*- 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/skia/SkiaHelper.hxx> + +#include <vcl/svapp.hxx> + +bool SkiaHelper::isVCLSkiaEnabled() +{ + /** + * The !bSet part should only be called once! Changing the results in the same + * run will mix OpenGL and normal rendering. + */ + + static bool bSet = false; + static bool bEnable = false; + static bool bForceOpenGL = false; + + // No hardware rendering, so no OpenGL + if (Application::IsBitmapRendering()) + return false; + + //tdf#106155, disable GL while loading certain bitmaps needed for the initial toplevel windows + //under raw X (kde) vclplug + // TODO + // if (bTempOpenGLDisabled) + // return false; + + if (bSet) + { + return bForceOpenGL || bEnable; + } + + // TODO + return true; +#if 0 + /* + * There are a number of cases that these environment variables cover: + * * SAL_FORCEGL forces OpenGL independent of any other option + * * SAL_DISABLEGL or a blacklisted driver avoid the use of OpenGL if SAL_FORCEGL is not set + */ + + bSet = true; + bForceOpenGL = !!getenv("SAL_FORCEGL") || officecfg::Office::Common::VCL::ForceOpenGL::get(); + + bool bRet = false; + bool bSupportsVCLOpenGL = supportsVCLOpenGL(); + // always call supportsVCLOpenGL to de-zombie the glxtest child process on X11 + if (bForceOpenGL) + { + bRet = true; + } + else if (bSupportsVCLOpenGL) + { + static bool bEnableGLEnv = !!getenv("SAL_ENABLEGL"); + + bEnable = bEnableGLEnv; + + if (officecfg::Office::Common::VCL::UseOpenGL::get()) + bEnable = true; + + // Force disable in safe mode + if (Application::IsSafeModeEnabled()) + bEnable = false; + + bRet = bEnable; + } + + if (bRet) + { + if (!getenv("SAL_DISABLE_GL_WATCHDOG")) + OpenGLWatchdogThread::start(); + } + CrashReporter::AddKeyValue("UseOpenGL", OUString::boolean(bRet)); + + return bRet; +#endif +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/vcl/unx/generic/app/saldisp.cxx b/vcl/unx/generic/app/saldisp.cxx index d2f94a73622c..cd1c19e408bc 100644 --- a/vcl/unx/generic/app/saldisp.cxx +++ b/vcl/unx/generic/app/saldisp.cxx @@ -218,6 +218,7 @@ bool SalDisplay::BestVisual( Display *pDisplay, if( nVID && sal_GetVisualInfo( pDisplay, nVID, rVI ) ) return rVI.visualid == nDefVID; +// TODO skia bool bUseOpenGL = OpenGLHelper::isVCLOpenGLEnabled(); if (bUseOpenGL && BestOpenGLVisual(pDisplay, nScreen, rVI)) return rVI.visualid == nDefVID; diff --git a/vcl/unx/generic/gdi/salbmp.cxx b/vcl/unx/generic/gdi/salbmp.cxx index b8d4df762c61..b69d3c0c52ef 100644 --- a/vcl/unx/generic/gdi/salbmp.cxx +++ b/vcl/unx/generic/gdi/salbmp.cxx @@ -47,6 +47,8 @@ #include <o3tl/safeint.hxx> #include <opengl/salbmp.hxx> #include <vcl/opengl/OpenGLHelper.hxx> +#include <skia/salbmp.hxx> +#include <vcl/skia/SkiaHelper.hxx> #if defined HAVE_VALGRIND_HEADERS #include <valgrind/memcheck.h> @@ -57,7 +59,9 @@ std::shared_ptr<SalBitmap> X11SalInstance::CreateSalBitmap() { - if (OpenGLHelper::isVCLOpenGLEnabled()) + if (SkiaHelper::isVCLSkiaEnabled()) + return std::make_shared<SkiaSalBitmap>(); + else if (OpenGLHelper::isVCLOpenGLEnabled()) return std::make_shared<OpenGLSalBitmap>(); else return std::make_shared<X11SalBitmap>(); diff --git a/vcl/unx/generic/gdi/salgdi.cxx b/vcl/unx/generic/gdi/salgdi.cxx index 2cfe4058a224..680a1f6a57b8 100644 --- a/vcl/unx/generic/gdi/salgdi.cxx +++ b/vcl/unx/generic/gdi/salgdi.cxx @@ -58,8 +58,10 @@ #include <textrender.hxx> #include "gdiimpl.hxx" #include <opengl/x11/gdiimpl.hxx> +#include <skia/x11/gdiimpl.hxx> #include "x11cairotextrender.hxx" #include "openglx11cairotextrender.hxx" +#include "skiax11cairotextrender.hxx" #include <unx/printergfx.hxx> #include <unx/x11/xrender_peer.hxx> @@ -67,6 +69,7 @@ #include <cairo-xlib.h> #include <vcl/opengl/OpenGLHelper.hxx> +#include <vcl/skia/SkiaHelper.hxx> X11SalGraphics::X11SalGraphics(): m_pFrame(nullptr), @@ -88,9 +91,15 @@ X11SalGraphics::X11SalGraphics(): bWindow_(false), bVirDev_(false), bFontGC_(false), - m_bOpenGL(OpenGLHelper::isVCLOpenGLEnabled()) + m_bOpenGL(OpenGLHelper::isVCLOpenGLEnabled()), + m_bSkia(SkiaHelper::isVCLSkiaEnabled()) { - if (m_bOpenGL) + if (m_bSkia) + { + mxImpl.reset(new X11SkiaSalGraphicsImpl(*this)); + mxTextRenderImpl.reset(new SkiaX11CairoTextRender(*this)); + } + else if (m_bOpenGL) { mxImpl.reset(new X11OpenGLSalGraphicsImpl(*this)); mxTextRenderImpl.reset(new OpenGLX11CairoTextRender(*this)); @@ -605,7 +614,7 @@ bool X11SalGraphics::drawPolyPolygon( // enable by setting to something static const char* pUseCairoForPolygons(getenv("SAL_ENABLE_USE_CAIRO_FOR_POLYGONS")); - if (!m_bOpenGL && nullptr != pUseCairoForPolygons && SupportsCairo()) + if (!m_bOpenGL && !m_bSkia && nullptr != pUseCairoForPolygons && SupportsCairo()) { // snap to raster if requested const bool bSnapPoints(!getAntiAliasB2DDraw()); @@ -725,7 +734,7 @@ bool X11SalGraphics::drawPolyLine( // disable by setting to something static const char* pUseCairoForFatLines(getenv("SAL_DISABLE_USE_CAIRO_FOR_FATLINES")); - if (!m_bOpenGL && nullptr == pUseCairoForFatLines && SupportsCairo()) + if (!m_bOpenGL && !m_bSkia && nullptr == pUseCairoForFatLines && SupportsCairo()) { cairo_t* cr = getCairoContext(); clipRegion(cr); diff --git a/vcl/unx/generic/gdi/salvd.cxx b/vcl/unx/generic/gdi/salvd.cxx index 5d422b6433ed..409214df1e52 100644 --- a/vcl/unx/generic/gdi/salvd.cxx +++ b/vcl/unx/generic/gdi/salvd.cxx @@ -33,14 +33,18 @@ #include <salinst.hxx> #include <vcl/opengl/OpenGLHelper.hxx> +#include <vcl/skia/SkiaHelper.hxx> #include <opengl/x11/salvd.hxx> +#include <skia/x11/salvd.hxx> std::unique_ptr<SalVirtualDevice> X11SalInstance::CreateX11VirtualDevice(SalGraphics const * pGraphics, long &nDX, long &nDY, DeviceFormat eFormat, const SystemGraphicsData *pData, std::unique_ptr<X11SalGraphics> pNewGraphics) { assert(pNewGraphics); - if (OpenGLHelper::isVCLOpenGLEnabled()) + if (SkiaHelper::isVCLSkiaEnabled()) + return std::unique_ptr<SalVirtualDevice>(new X11SkiaSalVirtualDevice( pGraphics, nDX, nDY, pData, std::move(pNewGraphics) )); + else if (OpenGLHelper::isVCLOpenGLEnabled()) return std::unique_ptr<SalVirtualDevice>(new X11OpenGLSalVirtualDevice( pGraphics, nDX, nDY, pData, std::move(pNewGraphics) )); else return std::unique_ptr<SalVirtualDevice>(new X11SalVirtualDevice(pGraphics, nDX, nDY, eFormat, pData, std::move(pNewGraphics))); diff --git a/vcl/unx/generic/gdi/skiax11cairotextrender.hxx b/vcl/unx/generic/gdi/skiax11cairotextrender.hxx new file mode 100644 index 000000000000..e46ac36ba54a --- /dev/null +++ b/vcl/unx/generic/gdi/skiax11cairotextrender.hxx @@ -0,0 +1,27 @@ +/* -*- 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_GENERIC_GDI_SKIAX11CAIROTEXTRENDER_HXX +#define INCLUDED_VCL_UNX_GENERIC_GDI_SKIAX11CAIROTEXTRENDER_HXX + +#include "x11cairotextrender.hxx" + +class SkiaX11CairoTextRender : public X11CairoTextRender +{ +public: + explicit SkiaX11CairoTextRender(X11SalGraphics& rParent); + + virtual cairo_t* getCairoContext() override; + virtual void getSurfaceOffset(double& nDX, double& nDY) override; + virtual void releaseCairoContext(cairo_t* cr) override; +}; + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |