drawinglayer/source/processor2d/d2dpixelprocessor2d.cxx | 133 ++++++++++++++- include/drawinglayer/processor2d/d2dpixelprocessor2d.hxx | 9 + 2 files changed, 138 insertions(+), 4 deletions(-)
New commits: commit 7d948d5c7edbbfd29a77b97a5101aa43917e5ec2 Author: Armin Le Grand (allotropia) <armin.le.grand.ext...@allotropia.de> AuthorDate: Tue Dec 20 18:42:42 2022 +0100 Commit: Armin Le Grand <armin.le.gr...@me.com> CommitDate: Tue Dec 20 19:45:56 2022 +0000 SDPR: Add handling/direct rendering of some simple Primitives (SDPR == SystemDependentPrimitiveRenderer) Make D2DPixelProcessor2D directly render the added simple Primitives LineRectanglePrimitive2D FilledRectanglePrimitive2D SingleLinePrimitive2D to use less ressources & get faster since no conversion to Polygons is done. These are Primitives that *may* be handled directly, but do not have to - I checked that the decomposes do work before adding direct handling. Change-Id: Ifa97c595c262d84a9889f92571b2c9909bcef0e0 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/144626 Tested-by: Jenkins Reviewed-by: Armin Le Grand <armin.le.gr...@me.com> diff --git a/drawinglayer/source/processor2d/d2dpixelprocessor2d.cxx b/drawinglayer/source/processor2d/d2dpixelprocessor2d.cxx old mode 100755 new mode 100644 index 9e76cfa461a3..e2657d9cf677 --- a/drawinglayer/source/processor2d/d2dpixelprocessor2d.cxx +++ b/drawinglayer/source/processor2d/d2dpixelprocessor2d.cxx @@ -1476,10 +1476,10 @@ void D2DPixelProcessor2D::processPolygonStrokePrimitive2D( const basegfx::B2DHomMatrix& rObjectToView( getViewInformation2D().getObjectToViewTransformation()); const double fDiscreteLineWidth( - bHairline ? 1.0 - : ceil(basegfx::B2DVector(rObjectToView - * basegfx::B2DVector(rLineAttribute.getWidth(), 0.0)) - .getLength())); + bHairline + ? 1.0 + : basegfx::B2DVector(rObjectToView * basegfx::B2DVector(rLineAttribute.getWidth(), 0.0)) + .getLength()); // Here for every combination which the system-specific implementation is not // capable of visualizing, use the (for decomposable Primitives always possible) @@ -1672,6 +1672,113 @@ void D2DPixelProcessor2D::processPolygonStrokePrimitive2D( } } +void D2DPixelProcessor2D::processLineRectanglePrimitive2D( + const primitive2d::LineRectanglePrimitive2D& rLineRectanglePrimitive2D) +{ + if (rLineRectanglePrimitive2D.getB2DRange().isEmpty()) + { + // no geometry, done + return; + } + + const basegfx::BColor aHairlineColor( + maBColorModifierStack.getModifiedColor(rLineRectanglePrimitive2D.getBColor())); + const D2D1::ColorF aD2DColor(aHairlineColor.getRed(), aHairlineColor.getGreen(), + aHairlineColor.getBlue()); + ID2D1SolidColorBrush* pColorBrush(nullptr); + HRESULT hr(getRenderTarget().CreateSolidColorBrush(aD2DColor, &pColorBrush)); + bool bDone(false); + + if (SUCCEEDED(hr)) + { + const double fAAOffset(getViewInformation2D().getUseAntiAliasing() ? 0.5 : 0.0); + const basegfx::B2DHomMatrix aLocalTransform( + getViewInformation2D().getObjectToViewTransformation()); + getRenderTarget().SetTransform(D2D1::Matrix3x2F( + aLocalTransform.a(), aLocalTransform.b(), aLocalTransform.c(), aLocalTransform.d(), + aLocalTransform.e() + fAAOffset, aLocalTransform.f() + fAAOffset)); + const basegfx::B2DRange& rRange(rLineRectanglePrimitive2D.getB2DRange()); + const D2D1_RECT_F rect + = { rRange.getMinX(), rRange.getMinY(), rRange.getMaxX(), rRange.getMaxY() }; + const double fDiscreteLineWidth( + basegfx::B2DVector(getViewInformation2D().getInverseObjectToViewTransformation() + * basegfx::B2DVector(1.44, 0.0)) + .getLength()); + + getRenderTarget().DrawRectangle(&rect, pColorBrush, fDiscreteLineWidth); + bDone = true; + } + + if (!bDone) + increaseError(); +} + +void D2DPixelProcessor2D::processFilledRectanglePrimitive2D( + const primitive2d::FilledRectanglePrimitive2D& rFilledRectanglePrimitive2D) +{ + if (rFilledRectanglePrimitive2D.getB2DRange().isEmpty()) + { + // no geometry, done + return; + } + + const basegfx::BColor aFillColor( + maBColorModifierStack.getModifiedColor(rFilledRectanglePrimitive2D.getBColor())); + const D2D1::ColorF aD2DColor(aFillColor.getRed(), aFillColor.getGreen(), aFillColor.getBlue()); + ID2D1SolidColorBrush* pColorBrush(nullptr); + HRESULT hr(getRenderTarget().CreateSolidColorBrush(aD2DColor, &pColorBrush)); + bool bDone(false); + + if (SUCCEEDED(hr)) + { + const double fAAOffset(getViewInformation2D().getUseAntiAliasing() ? 0.5 : 0.0); + const basegfx::B2DHomMatrix aLocalTransform( + getViewInformation2D().getObjectToViewTransformation()); + getRenderTarget().SetTransform(D2D1::Matrix3x2F( + aLocalTransform.a(), aLocalTransform.b(), aLocalTransform.c(), aLocalTransform.d(), + aLocalTransform.e() + fAAOffset, aLocalTransform.f() + fAAOffset)); + const basegfx::B2DRange& rRange(rFilledRectanglePrimitive2D.getB2DRange()); + const D2D1_RECT_F rect + = { rRange.getMinX(), rRange.getMinY(), rRange.getMaxX(), rRange.getMaxY() }; + + getRenderTarget().FillRectangle(&rect, pColorBrush); + bDone = true; + } + + if (!bDone) + increaseError(); +} + +void D2DPixelProcessor2D::processSingleLinePrimitive2D( + const primitive2d::SingleLinePrimitive2D& rSingleLinePrimitive2D) +{ + const basegfx::BColor aLineColor( + maBColorModifierStack.getModifiedColor(rSingleLinePrimitive2D.getBColor())); + const D2D1::ColorF aD2DColor(aLineColor.getRed(), aLineColor.getGreen(), aLineColor.getBlue()); + ID2D1SolidColorBrush* pColorBrush(nullptr); + HRESULT hr(getRenderTarget().CreateSolidColorBrush(aD2DColor, &pColorBrush)); + bool bDone(false); + + if (SUCCEEDED(hr)) + { + const double fAAOffset(getViewInformation2D().getUseAntiAliasing() ? 0.5 : 0.0); + basegfx::B2DHomMatrix aLocalTransform( + getViewInformation2D().getObjectToViewTransformation()); + const basegfx::B2DPoint aStart(aLocalTransform * rSingleLinePrimitive2D.getStart()); + const basegfx::B2DPoint aEnd(aLocalTransform * rSingleLinePrimitive2D.getEnd()); + + getRenderTarget().SetTransform(D2D1::Matrix3x2F::Identity()); + const D2D1_POINT_2F aD2D1Start = { aStart.getX() + fAAOffset, aStart.getY() + fAAOffset }; + const D2D1_POINT_2F aD2D1End = { aEnd.getX() + fAAOffset, aEnd.getY() + fAAOffset }; + + getRenderTarget().DrawLine(aD2D1Start, aD2D1End, pColorBrush, 1.44f); + bDone = true; + } + + if (!bDone) + increaseError(); +} + void D2DPixelProcessor2D::processBasePrimitive2D(const primitive2d::BasePrimitive2D& rCandidate) { if (0 == mnRecursionCounter) @@ -1765,6 +1872,24 @@ void D2DPixelProcessor2D::processBasePrimitive2D(const primitive2d::BasePrimitiv static_cast<const primitive2d::PolygonStrokePrimitive2D&>(rCandidate)); break; } + case PRIMITIVE2D_ID_LINERECTANGLEPRIMITIVE2D: + { + processLineRectanglePrimitive2D( + static_cast<const primitive2d::LineRectanglePrimitive2D&>(rCandidate)); + break; + } + case PRIMITIVE2D_ID_FILLEDRECTANGLEPRIMITIVE2D: + { + processFilledRectanglePrimitive2D( + static_cast<const primitive2d::FilledRectanglePrimitive2D&>(rCandidate)); + break; + } + case PRIMITIVE2D_ID_SINGLELINEPRIMITIVE2D: + { + processSingleLinePrimitive2D( + static_cast<const primitive2d::SingleLinePrimitive2D&>(rCandidate)); + break; + } // continue with decompose default: diff --git a/include/drawinglayer/processor2d/d2dpixelprocessor2d.hxx b/include/drawinglayer/processor2d/d2dpixelprocessor2d.hxx old mode 100755 new mode 100644 index 75c3931fa7cf..3d84d6dd42af --- a/include/drawinglayer/processor2d/d2dpixelprocessor2d.hxx +++ b/include/drawinglayer/processor2d/d2dpixelprocessor2d.hxx @@ -40,6 +40,9 @@ class TransformPrimitive2D; class PointArrayPrimitive2D; class MarkerArrayPrimitive2D; class PolygonStrokePrimitive2D; +class LineRectanglePrimitive2D; +class FilledRectanglePrimitive2D; +class SingleLinePrimitive2D; } struct ID2D1RenderTarget; @@ -79,6 +82,12 @@ class DRAWINGLAYER_DLLPUBLIC D2DPixelProcessor2D : public BaseProcessor2D const primitive2d::BackgroundColorPrimitive2D& rBackgroundColorCandidate); void D2DPixelProcessor2D::processPolygonStrokePrimitive2D( const primitive2d::PolygonStrokePrimitive2D& rPolygonStrokeCandidate); + void processLineRectanglePrimitive2D( + const primitive2d::LineRectanglePrimitive2D& rLineRectanglePrimitive2D); + void processFilledRectanglePrimitive2D( + const primitive2d::FilledRectanglePrimitive2D& rFilledRectanglePrimitive2D); + void + processSingleLinePrimitive2D(const primitive2d::SingleLinePrimitive2D& rSingleLinePrimitive2D); // common helpers ID2D1Bitmap* implCreateAlpha_Direct(const primitive2d::TransparencePrimitive2D& rTransCandidate,