diff options
author | Armin Le Grand (Collabora) <Armin.Le.Grand@me.com> | 2024-07-15 18:55:56 +0200 |
---|---|---|
committer | Armin Le Grand <Armin.Le.Grand@me.com> | 2024-07-16 13:10:10 +0200 |
commit | a073b6133960734b809c1bc93e39a76fdf1e7c15 (patch) | |
tree | d75a5e2dbeea7e35e5d2c8c0d56526656c212028 /drawinglayer | |
parent | f10d51709d08bdafdbd5c92f73ddb62cb217b6dd (diff) |
CairoSDPR: Direct support for RGBA Gradients (I)
Detect where created when a RGBA gradient could be
used directly and create a primitive representing
that, a PolyPolygonRGBAGradientPrimitive2D.
That primitive decomposes to what was created before,
so no primitive renderer has to be touched, all will
work as before.
NOTE: That helper primitive just holds references to
what would be created anyways, so one depth step
added but not really any additional data.
This is the 1st step for direct support, the 2nd is
to then detect and use that primitive in SDPR
implementations directly.
Change-Id: I4f247636ce58a8a1fd1e0df32dabed0d6cc10d0e
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/170527
Tested-by: Jenkins
Reviewed-by: Armin Le Grand <Armin.Le.Grand@me.com>
Diffstat (limited to 'drawinglayer')
-rw-r--r-- | drawinglayer/source/attribute/fillgradientattribute.cxx | 33 | ||||
-rw-r--r-- | drawinglayer/source/primitive2d/PolyPolygonGradientPrimitive2D.cxx | 46 | ||||
-rw-r--r-- | drawinglayer/source/primitive2d/Tools.cxx | 2 |
3 files changed, 81 insertions, 0 deletions
diff --git a/drawinglayer/source/attribute/fillgradientattribute.cxx b/drawinglayer/source/attribute/fillgradientattribute.cxx index e02fdd4a5dad..54f455f647ef 100644 --- a/drawinglayer/source/attribute/fillgradientattribute.cxx +++ b/drawinglayer/source/attribute/fillgradientattribute.cxx @@ -223,6 +223,39 @@ namespace drawinglayer::attribute return mpFillGradientAttribute->getSteps(); } + bool FillGradientAttribute::sameDefinitionThanAlpha(const FillGradientAttribute& rAlpha) const + { + // entries that are used by all gradient styles + if (getStyle() != rAlpha.getStyle() + || getBorder() != rAlpha.getBorder() + || getSteps() != rAlpha.getSteps()) + { + return false; + } + + // check for offsets if not ignored + const bool bIgnoreOffset(css::awt::GradientStyle_LINEAR == getStyle() || css::awt::GradientStyle_AXIAL == getStyle()); + if (!bIgnoreOffset && (getOffsetX() != rAlpha.getOffsetX() || getOffsetY() != rAlpha.getOffsetY())) + { + return false; + } + + // check for angle if not ignored + const bool bIgnoreAngle(css::awt::GradientStyle_RADIAL == getStyle()); + if (!bIgnoreAngle && getAngle() != rAlpha.getAngle()) + { + return false; + } + + // check for same count & offsets in the gradients (all except 'colors') + if (!getColorStops().sameSizeAndDistances(rAlpha.getColorStops())) + { + return false; + } + + return true; + } + } // end of namespace /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/drawinglayer/source/primitive2d/PolyPolygonGradientPrimitive2D.cxx b/drawinglayer/source/primitive2d/PolyPolygonGradientPrimitive2D.cxx index 4fe3321e62f8..2e6b83ab526f 100644 --- a/drawinglayer/source/primitive2d/PolyPolygonGradientPrimitive2D.cxx +++ b/drawinglayer/source/primitive2d/PolyPolygonGradientPrimitive2D.cxx @@ -22,6 +22,8 @@ #include <drawinglayer/primitive2d/drawinglayer_primitivetypes2d.hxx> #include <drawinglayer/primitive2d/fillgradientprimitive2d.hxx> #include <drawinglayer/primitive2d/maskprimitive2d.hxx> +#include <drawinglayer/primitive2d/transparenceprimitive2d.hxx> +#include <basegfx/polygon/b2dpolypolygontools.hxx> #include <rtl/ref.hxx> #include <utility> @@ -84,6 +86,50 @@ sal_uInt32 PolyPolygonGradientPrimitive2D::getPrimitive2DID() const return PRIMITIVE2D_ID_POLYPOLYGONGRADIENTPRIMITIVE2D; } +Primitive2DReference PolyPolygonRGBAGradientPrimitive2D::create2DDecomposition( + const geometry::ViewInformation2D& /*rViewInformation*/) const +{ + Primitive2DContainer aContent{ new PolyPolygonGradientPrimitive2D( + getB2DPolyPolygon(), getDefinitionRange(), getFillGradient()) }; + + Primitive2DContainer aAlpha{ new FillGradientPrimitive2D( + basegfx::utils::getRange(getB2DPolyPolygon()), getDefinitionRange(), + getFillGradientAlpha()) }; + + return Primitive2DReference{ new TransparencePrimitive2D(std::move(aContent), + std::move(aAlpha)) }; +} + +PolyPolygonRGBAGradientPrimitive2D::PolyPolygonRGBAGradientPrimitive2D( + basegfx::B2DPolyPolygon aPolyPolygon, const basegfx::B2DRange& rDefinitionRange, + attribute::FillGradientAttribute aFillGradient, + attribute::FillGradientAttribute aFillGradientAlpha) + : PolyPolygonGradientPrimitive2D(aPolyPolygon, rDefinitionRange, aFillGradient) + , maFillGradientAlpha(aFillGradientAlpha) +{ + // assert when the definition is not allowed, it HAS to fulfil the + // requested preconditions + assert(aFillGradient.sameDefinitionThanAlpha(aFillGradientAlpha)); +} + +bool PolyPolygonRGBAGradientPrimitive2D::operator==(const BasePrimitive2D& rPrimitive) const +{ + if (PolyPolygonGradientPrimitive2D::operator==(rPrimitive)) + { + const PolyPolygonRGBAGradientPrimitive2D& rCompare + = static_cast<const PolyPolygonRGBAGradientPrimitive2D&>(rPrimitive); + + return getFillGradientAlpha() == rCompare.getFillGradientAlpha(); + } + + return false; +} + +sal_uInt32 PolyPolygonRGBAGradientPrimitive2D::getPrimitive2DID() const +{ + return PRIMITIVE2D_ID_POLYPOLYGONRGBAGRADIENTPRIMITIVE2D; +} + } // end drawinglayer::primitive2d namespace /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/drawinglayer/source/primitive2d/Tools.cxx b/drawinglayer/source/primitive2d/Tools.cxx index bd74a4b5cd00..b13505bc3fd6 100644 --- a/drawinglayer/source/primitive2d/Tools.cxx +++ b/drawinglayer/source/primitive2d/Tools.cxx @@ -233,6 +233,8 @@ OUString idToString(sal_uInt32 nId) return u"SINGLELINEPRIMITIVE"_ustr; case PRIMITIVE2D_ID_EXCLUSIVEEDITVIEWPRIMITIVE2D: return u"EXCLUSIVEEDITVIEWPRIMITIVE2D"_ustr; + case PRIMITIVE2D_ID_POLYPOLYGONRGBAGRADIENTPRIMITIVE2D: + return u"POLYPOLYGONRGBAGRADIENTPRIMITIVE2D"_ustr; default: return OUString::number((nId >> 16) & 0xFF) + "|" + OUString::number(nId & 0xFF); } |