vcl/Library_vcl.mk | 1 vcl/headless/SvpGraphicsBackend.cxx | 194 ++++++++++++++++++++++++++++++++ vcl/headless/svpgdi.cxx | 46 ------- vcl/inc/headless/SvpGraphicsBackend.hxx | 140 +++++++++++++++++++++++ vcl/inc/headless/svpgdi.hxx | 26 +--- 5 files changed, 343 insertions(+), 64 deletions(-)
New commits: commit 391776e32510ac0e925348df9ae3b832a5b07788 Author: Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk> AuthorDate: Thu Aug 26 11:51:34 2021 +0900 Commit: Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk> CommitDate: Thu Aug 26 12:02:41 2021 +0900 move cairo drawing functions into SvpGraphicsBackend SvpGraphicsBackend is derived from SalGraphicsImpl. Change-Id: Ic3abc6df3b489457cda4b942738edc20cfa8e171 diff --git a/vcl/Library_vcl.mk b/vcl/Library_vcl.mk index eb0af8aa8cc4..49de4a41f9f7 100644 --- a/vcl/Library_vcl.mk +++ b/vcl/Library_vcl.mk @@ -518,6 +518,7 @@ vcl_headless_code= \ $(if $(filter-out iOS,$(OS)), \ vcl/headless/svpbmp \ vcl/headless/svpgdi \ + vcl/headless/SvpGraphicsBackend \ $(if $(ENABLE_HEADLESS),vcl/headless/svpdata) \ vcl/headless/CustomWidgetDraw \ ) \ diff --git a/vcl/headless/SvpGraphicsBackend.cxx b/vcl/headless/SvpGraphicsBackend.cxx new file mode 100644 index 000000000000..9f98b73cc1a0 --- /dev/null +++ b/vcl/headless/SvpGraphicsBackend.cxx @@ -0,0 +1,194 @@ +/* -*- 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 <headless/SvpGraphicsBackend.hxx> + +#include <sal/log.hxx> + +SvpGraphicsBackend::SvpGraphicsBackend() {} + +void SvpGraphicsBackend::Init() {} + +void SvpGraphicsBackend::freeResources() {} + +bool SvpGraphicsBackend::setClipRegion(vcl::Region const& rRegion) { return false; } + +void SvpGraphicsBackend::ResetClipRegion() {} + +sal_uInt16 SvpGraphicsBackend::GetBitCount() const { return 0; } + +tools::Long SvpGraphicsBackend::GetGraphicsWidth() const { return 0; } + +void SvpGraphicsBackend::SetLineColor() {} + +void SvpGraphicsBackend::SetLineColor(Color nColor) {} +void SvpGraphicsBackend::SetFillColor() {} +void SvpGraphicsBackend::SetFillColor(Color nColor) {} +void SvpGraphicsBackend::SetXORMode(bool bSet, bool bInvertOnly) {} +void SvpGraphicsBackend::SetROPLineColor(SalROPColor nROPColor) {} +void SvpGraphicsBackend::SetROPFillColor(SalROPColor nROPColor) {} + +void SvpGraphicsBackend::drawPixel(tools::Long nX, tools::Long nY) {} +void SvpGraphicsBackend::drawPixel(tools::Long nX, tools::Long nY, Color nColor) {} + +void SvpGraphicsBackend::drawLine(tools::Long nX1, tools::Long nY1, tools::Long nX2, + tools::Long nY2) +{ +} +void SvpGraphicsBackend::drawRect(tools::Long nX, tools::Long nY, tools::Long nWidth, + tools::Long nHeight) +{ +} +void SvpGraphicsBackend::drawPolyLine(sal_uInt32 nPoints, const Point* pPointArray) {} +void SvpGraphicsBackend::drawPolygon(sal_uInt32 nPoints, const Point* pPointArray) {} +void SvpGraphicsBackend::drawPolyPolygon(sal_uInt32 nPoly, const sal_uInt32* pPoints, + const Point** pPointArray) +{ +} + +bool SvpGraphicsBackend::drawPolyPolygon(const basegfx::B2DHomMatrix& rObjectToDevice, + const basegfx::B2DPolyPolygon&, double fTransparency) +{ + return false; +} + +bool SvpGraphicsBackend::drawPolyLine(const basegfx::B2DHomMatrix& rObjectToDevice, + const basegfx::B2DPolygon&, double fTransparency, + double fLineWidth, const std::vector<double>* pStroke, + basegfx::B2DLineJoin, css::drawing::LineCap, + double fMiterMinimumAngle, bool bPixelSnapHairline) +{ + return false; +} + +bool SvpGraphicsBackend::drawPolyLineBezier(sal_uInt32, const Point*, const PolyFlags*) +{ + SAL_INFO("vcl.gdi", "unsupported SvpSalGraphics::drawPolyLineBezier case"); + return false; +} + +bool SvpGraphicsBackend::drawPolygonBezier(sal_uInt32, const Point*, const PolyFlags*) +{ + SAL_INFO("vcl.gdi", "unsupported SvpSalGraphics::drawPolygonBezier case"); + return false; +} + +bool SvpGraphicsBackend::drawPolyPolygonBezier(sal_uInt32, const sal_uInt32*, const Point* const*, + const PolyFlags* const*) +{ + SAL_INFO("vcl.gdi", "unsupported SvpSalGraphics::drawPolyPolygonBezier case"); + return false; +} + +void SvpGraphicsBackend::copyArea(tools::Long nDestX, tools::Long nDestY, tools::Long nSrcX, + tools::Long nSrcY, tools::Long nSrcWidth, tools::Long nSrcHeight, + bool bWindowInvalidate) +{ +} + +void SvpGraphicsBackend::copyBits(const SalTwoRect& rPosAry, SalGraphics* pSrcGraphics) {} + +void SvpGraphicsBackend::drawBitmap(const SalTwoRect& rPosAry, const SalBitmap& rSalBitmap) {} + +void SvpGraphicsBackend::drawBitmap(const SalTwoRect& rPosAry, const SalBitmap& rSalBitmap, + const SalBitmap& rMaskBitmap) +{ +} + +void SvpGraphicsBackend::drawMask(const SalTwoRect& rPosAry, const SalBitmap& rSalBitmap, + Color nMaskColor) +{ +} + +std::shared_ptr<SalBitmap> SvpGraphicsBackend::getBitmap(tools::Long nX, tools::Long nY, + tools::Long nWidth, tools::Long nHeight) +{ + return std::shared_ptr<SalBitmap>(); +} + +Color SvpGraphicsBackend::getPixel(tools::Long nX, tools::Long nY) { return Color(); } + +void SvpGraphicsBackend::invert(tools::Long nX, tools::Long nY, tools::Long nWidth, + tools::Long nHeight, SalInvert nFlags) +{ +} + +void SvpGraphicsBackend::invert(sal_uInt32 nPoints, const Point* pPtAry, SalInvert nFlags) {} + +bool SvpGraphicsBackend::drawEPS(tools::Long nX, tools::Long nY, tools::Long nWidth, + tools::Long nHeight, void* pPtr, sal_uInt32 nSize) +{ + return false; +} + +bool SvpGraphicsBackend::blendBitmap(const SalTwoRect&, const SalBitmap& rBitmap) { return false; } + +bool SvpGraphicsBackend::blendAlphaBitmap(const SalTwoRect&, const SalBitmap& rSrcBitmap, + const SalBitmap& rMaskBitmap, + const SalBitmap& rAlphaBitmap) +{ + return false; +} + +bool SvpGraphicsBackend::drawAlphaBitmap(const SalTwoRect&, const SalBitmap& rSourceBitmap, + const SalBitmap& rAlphaBitmap) +{ + return false; +} + +bool SvpGraphicsBackend::drawTransformedBitmap(const basegfx::B2DPoint& rNull, + const basegfx::B2DPoint& rX, + const basegfx::B2DPoint& rY, + const SalBitmap& rSourceBitmap, + const SalBitmap* pAlphaBitmap, double fAlpha) +{ + return false; +} + +bool SvpGraphicsBackend::hasFastDrawTransformedBitmap() const { return false; } + +bool SvpGraphicsBackend::drawAlphaRect(tools::Long nX, tools::Long nY, tools::Long nWidth, + tools::Long nHeight, sal_uInt8 nTransparency) +{ + return false; +} + +bool SvpGraphicsBackend::drawGradient(const tools::PolyPolygon& rPolygon, const Gradient& rGradient) +{ + return false; +} + +bool SvpGraphicsBackend::implDrawGradient(basegfx::B2DPolyPolygon const& rPolyPolygon, + SalGradient const& rGradient) +{ + return false; +} + +bool SvpGraphicsBackend::supportsOperation(OutDevSupportType eType) const +{ + switch (eType) + { + case OutDevSupportType::TransparentRect: + case OutDevSupportType::B2DDraw: + return true; + } + return false; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/vcl/headless/svpgdi.cxx b/vcl/headless/svpgdi.cxx index 2a5d1ba350ad..3cd95984c9e6 100644 --- a/vcl/headless/svpgdi.cxx +++ b/vcl/headless/svpgdi.cxx @@ -833,11 +833,6 @@ bool SvpSalGraphics::drawTransformedBitmap( return true; } -bool SvpSalGraphics::hasFastDrawTransformedBitmap() const -{ - return false; -} - void SvpSalGraphics::clipRegion(cairo_t* cr, const vcl::Region& rClipRegion) { RectangleVector aRectangles; @@ -1778,31 +1773,6 @@ bool SvpSalGraphics::drawPolyLine( return true; } -bool SvpSalGraphics::drawPolyLineBezier( sal_uInt32, - const Point*, - const PolyFlags* ) -{ - SAL_INFO("vcl.gdi", "unsupported SvpSalGraphics::drawPolyLineBezier case"); - return false; -} - -bool SvpSalGraphics::drawPolygonBezier( sal_uInt32, - const Point*, - const PolyFlags* ) -{ - SAL_INFO("vcl.gdi", "unsupported SvpSalGraphics::drawPolygonBezier case"); - return false; -} - -bool SvpSalGraphics::drawPolyPolygonBezier( sal_uInt32, - const sal_uInt32*, - const Point* const*, - const PolyFlags* const* ) -{ - SAL_INFO("vcl.gdi", "unsupported SvpSalGraphics::drawPolyPolygonBezier case"); - return false; -} - namespace { void add_polygon_path(cairo_t* cr, const basegfx::B2DPolyPolygon& rPolyPolygon, const basegfx::B2DHomMatrix& rObjectToDevice, bool bPixelSnap) @@ -2443,11 +2413,6 @@ void SvpSalGraphics::invert(sal_uInt32 nPoints, const Point* pPtAry, SalInvert n invert(aPoly, nFlags); } -bool SvpSalGraphics::drawEPS( tools::Long, tools::Long, tools::Long, tools::Long, void*, sal_uInt32 ) -{ - return false; -} - namespace { bool isCairoCompatible(const BitmapBuffer* pBuffer) @@ -2691,17 +2656,6 @@ SystemGraphicsData SvpSalGraphics::GetGraphicsData() const return SystemGraphicsData(); } -bool SvpSalGraphics::supportsOperation(OutDevSupportType eType) const -{ - switch (eType) - { - case OutDevSupportType::TransparentRect: - case OutDevSupportType::B2DDraw: - return true; - } - return false; -} - void dl_cairo_surface_set_device_scale(cairo_surface_t *surface, double x_scale, double y_scale) { #ifdef ANDROID diff --git a/vcl/inc/headless/SvpGraphicsBackend.hxx b/vcl/inc/headless/SvpGraphicsBackend.hxx new file mode 100644 index 000000000000..a3a5f05f47c1 --- /dev/null +++ b/vcl/inc/headless/SvpGraphicsBackend.hxx @@ -0,0 +1,140 @@ +/* -*- 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 . + */ + +#pragma once + +#include <vcl/dllapi.h> +#include <tools/long.hxx> +#include <tools/color.hxx> +#include <salgdiimpl.hxx> + +//enum class PaintMode { Over, Xor }; + +class VCL_DLLPUBLIC SvpGraphicsBackend : public SalGraphicsImpl +{ + vcl::Region m_aClipRegion; + Color m_aLineColor; + Color m_aFillColor; + //PaintMode m_ePaintMode; + +public: + SvpGraphicsBackend(); + + ~SvpGraphicsBackend() override {} + + void Init() override; + + void freeResources() override; + + OUString getRenderBackendName() const override { return "svp"; } + + bool setClipRegion(vcl::Region const& rRegion) override; + void ResetClipRegion() override; + + sal_uInt16 GetBitCount() const override; + + tools::Long GetGraphicsWidth() const override; + + void SetLineColor() override; + void SetLineColor(Color nColor) override; + void SetFillColor() override; + void SetFillColor(Color nColor) override; + void SetXORMode(bool bSet, bool bInvertOnly) override; + void SetROPLineColor(SalROPColor nROPColor) override; + void SetROPFillColor(SalROPColor nROPColor) override; + + void drawPixel(tools::Long nX, tools::Long nY) override; + void drawPixel(tools::Long nX, tools::Long nY, Color nColor) override; + + void drawLine(tools::Long nX1, tools::Long nY1, tools::Long nX2, tools::Long nY2) override; + void drawRect(tools::Long nX, tools::Long nY, tools::Long nWidth, tools::Long nHeight) override; + void drawPolyLine(sal_uInt32 nPoints, const Point* pPointArray) override; + void drawPolygon(sal_uInt32 nPoints, const Point* pPointArray) override; + void drawPolyPolygon(sal_uInt32 nPoly, const sal_uInt32* pPoints, + const Point** pPointArray) override; + + bool drawPolyPolygon(const basegfx::B2DHomMatrix& rObjectToDevice, + const basegfx::B2DPolyPolygon&, double fTransparency) override; + + bool drawPolyLine(const basegfx::B2DHomMatrix& rObjectToDevice, const basegfx::B2DPolygon&, + double fTransparency, double fLineWidth, const std::vector<double>* pStroke, + basegfx::B2DLineJoin, css::drawing::LineCap, double fMiterMinimumAngle, + bool bPixelSnapHairline) override; + + bool drawPolyLineBezier(sal_uInt32 nPoints, const Point* pPointArray, + const PolyFlags* pFlagArray) override; + + bool drawPolygonBezier(sal_uInt32 nPoints, const Point* pPointArray, + const PolyFlags* pFlagArray) override; + + bool drawPolyPolygonBezier(sal_uInt32 nPoly, const sal_uInt32* pPoints, + const Point* const* pPointArray, + const PolyFlags* const* pFlagArray) override; + + void copyArea(tools::Long nDestX, tools::Long nDestY, tools::Long nSrcX, tools::Long nSrcY, + tools::Long nSrcWidth, tools::Long nSrcHeight, bool bWindowInvalidate) override; + + void copyBits(const SalTwoRect& rPosAry, SalGraphics* pSrcGraphics) override; + + void drawBitmap(const SalTwoRect& rPosAry, const SalBitmap& rSalBitmap) override; + + void drawBitmap(const SalTwoRect& rPosAry, const SalBitmap& rSalBitmap, + const SalBitmap& rMaskBitmap) override; + + void drawMask(const SalTwoRect& rPosAry, const SalBitmap& rSalBitmap, + Color nMaskColor) override; + + std::shared_ptr<SalBitmap> getBitmap(tools::Long nX, tools::Long nY, tools::Long nWidth, + tools::Long nHeight) override; + + Color getPixel(tools::Long nX, tools::Long nY) override; + + void invert(tools::Long nX, tools::Long nY, tools::Long nWidth, tools::Long nHeight, + SalInvert nFlags) override; + + void invert(sal_uInt32 nPoints, const Point* pPtAry, SalInvert nFlags) override; + + bool drawEPS(tools::Long nX, tools::Long nY, tools::Long nWidth, tools::Long nHeight, + void* pPtr, sal_uInt32 nSize) override; + + bool blendBitmap(const SalTwoRect&, const SalBitmap& rBitmap) override; + + bool blendAlphaBitmap(const SalTwoRect&, const SalBitmap& rSrcBitmap, + const SalBitmap& rMaskBitmap, const SalBitmap& rAlphaBitmap) override; + + bool drawAlphaBitmap(const SalTwoRect&, const SalBitmap& rSourceBitmap, + const SalBitmap& rAlphaBitmap) override; + + bool drawTransformedBitmap(const basegfx::B2DPoint& rNull, const basegfx::B2DPoint& rX, + const basegfx::B2DPoint& rY, const SalBitmap& rSourceBitmap, + const SalBitmap* pAlphaBitmap, double fAlpha) override; + + bool hasFastDrawTransformedBitmap() const override; + + bool drawAlphaRect(tools::Long nX, tools::Long nY, tools::Long nWidth, tools::Long nHeight, + sal_uInt8 nTransparency) override; + + bool drawGradient(const tools::PolyPolygon& rPolygon, const Gradient& rGradient) override; + bool implDrawGradient(basegfx::B2DPolyPolygon const& rPolyPolygon, + SalGradient const& rGradient) override; + + bool supportsOperation(OutDevSupportType eType) const override; +}; + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/vcl/inc/headless/svpgdi.hxx b/vcl/inc/headless/svpgdi.hxx index e14279978d6d..363cd6c29191 100644 --- a/vcl/inc/headless/svpgdi.hxx +++ b/vcl/inc/headless/svpgdi.hxx @@ -35,6 +35,8 @@ #include "svpcairotextrender.hxx" #include <impfontmetricdata.hxx> +#include "SvpGraphicsBackend.hxx" + #include <cairo.h> //Using formats that match cairo's formats. For android we patch cairo, @@ -86,7 +88,8 @@ struct VCL_DLLPUBLIC DamageHandler damageHandler damaged; }; -class VCL_DLLPUBLIC SvpSalGraphics : public SalGraphics + +class VCL_DLLPUBLIC SvpSalGraphics : public SalGraphicsAutoDelegateToImpl { cairo_surface_t* m_pSurface; basegfx::B2IVector m_aFrameSize; @@ -95,6 +98,8 @@ class VCL_DLLPUBLIC SvpSalGraphics : public SalGraphics Color m_aFillColor; PaintMode m_ePaintMode; + std::unique_ptr<SvpGraphicsBackend> m_pBackend; + public: void setSurface(cairo_surface_t* pSurface, const basegfx::B2IVector& rSize); cairo_surface_t* getSurface() const { return m_pSurface; } @@ -146,7 +151,6 @@ protected: const SalBitmap& rSourceBitmap, const SalBitmap* pAlphaBitmap, double fAlpha) override; - virtual bool hasFastDrawTransformedBitmap() const override; virtual bool drawAlphaRect( tools::Long nX, tools::Long nY, tools::Long nWidth, tools::Long nHeight, sal_uInt8 nTransparency ) override; cairo_t* createTmpCompatibleCairoContext() const; @@ -155,7 +159,8 @@ public: SvpSalGraphics(); virtual ~SvpSalGraphics() override; - virtual SalGraphicsImpl* GetImpl() const override { return nullptr; }; + virtual SalGraphicsImpl* GetImpl() const override { return m_pBackend.get(); } + virtual void GetResolution( sal_Int32& rDPIX, sal_Int32& rDPIY ) override; virtual sal_uInt16 GetBitCount() const override; virtual tools::Long GetGraphicsWidth() const override; @@ -198,7 +203,6 @@ public: virtual std::unique_ptr<GenericSalLayout> GetTextLayout(int nFallbackLevel) override; virtual void DrawTextLayout( const GenericSalLayout& ) override; - virtual bool supportsOperation( OutDevSupportType ) const override; virtual void drawPixel( tools::Long nX, tools::Long nY ) override; virtual void drawPixel( tools::Long nX, tools::Long nY, Color nColor ) override; virtual void drawLine( tools::Long nX1, tools::Long nY1, tools::Long nX2, tools::Long nY2 ) override; @@ -224,16 +228,6 @@ public: virtual void drawPolyPolygon( sal_uInt32 nPoly, const sal_uInt32* pPoints, const Point** pPtAry ) override; - virtual bool drawPolyLineBezier( sal_uInt32 nPoints, - const Point* pPtAry, - const PolyFlags* pFlgAry ) override; - virtual bool drawPolygonBezier( sal_uInt32 nPoints, - const Point* pPtAry, - const PolyFlags* pFlgAry ) override; - virtual bool drawPolyPolygonBezier( sal_uInt32 nPoly, - const sal_uInt32* pPoints, - const Point* const* pPtAry, - const PolyFlags* const* pFlgAry ) override; virtual bool drawGradient(tools::PolyPolygon const & rPolyPolygon, Gradient const & rGradient) override; @@ -264,12 +258,8 @@ public: virtual void invert( tools::Long nX, tools::Long nY, tools::Long nWidth, tools::Long nHeight, SalInvert nFlags ) override; virtual void invert( sal_uInt32 nPoints, const Point* pPtAry, SalInvert nFlags ) override; - virtual bool drawEPS( tools::Long nX, tools::Long nY, tools::Long nWidth, tools::Long nHeight, void* pPtr, sal_uInt32 nSize ) override; - virtual SystemGraphicsData GetGraphicsData() const override; - virtual OUString getRenderBackendName() const override { return "svp"; } - #if ENABLE_CAIRO_CANVAS virtual bool SupportsCairo() const override; virtual cairo::SurfaceSharedPtr CreateSurface(const cairo::CairoSurfaceSharedPtr& rSurface) const override;