diff options
author | Noel Grandin <noel.grandin@collabora.co.uk> | 2020-04-19 11:10:43 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2020-04-19 12:23:46 +0200 |
commit | 2ee60f02c456f39a80edb2dbfed48c3e0147a7f7 (patch) | |
tree | ca4b9c95c2c1f28dcfd4ecb3307015c7f82603b9 /drawinglayer/source/primitive2d/sceneprimitive2d.cxx | |
parent | 9df2821e61979dab32390d5c64dd49bee868adbb (diff) |
loplugin:flatten in drawinglayer
Change-Id: Ieb5f682ec627c8d8ddfc286ec0e4422104b4d847
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/92494
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'drawinglayer/source/primitive2d/sceneprimitive2d.cxx')
-rw-r--r-- | drawinglayer/source/primitive2d/sceneprimitive2d.cxx | 430 |
1 files changed, 215 insertions, 215 deletions
diff --git a/drawinglayer/source/primitive2d/sceneprimitive2d.cxx b/drawinglayer/source/primitive2d/sceneprimitive2d.cxx index c0c0fec7d41a..e58c05e406af 100644 --- a/drawinglayer/source/primitive2d/sceneprimitive2d.cxx +++ b/drawinglayer/source/primitive2d/sceneprimitive2d.cxx @@ -236,255 +236,255 @@ namespace drawinglayer::primitive2d calculateDiscreteSizes(rViewInformation, aDiscreteRange, aVisibleDiscreteRange, aUnitVisibleRange); - if(!aVisibleDiscreteRange.isEmpty()) + if(aVisibleDiscreteRange.isEmpty()) + return; + + // test if discrete view size (pixel) maybe too big and limit it + double fViewSizeX(aVisibleDiscreteRange.getWidth()); + double fViewSizeY(aVisibleDiscreteRange.getHeight()); + const double fViewVisibleArea(fViewSizeX * fViewSizeY); + const SvtOptionsDrawinglayer aDrawinglayerOpt; + const double fMaximumVisibleArea(aDrawinglayerOpt.GetQuadratic3DRenderLimit()); + double fReduceFactor(1.0); + + if(fViewVisibleArea > fMaximumVisibleArea) { - // test if discrete view size (pixel) maybe too big and limit it - double fViewSizeX(aVisibleDiscreteRange.getWidth()); - double fViewSizeY(aVisibleDiscreteRange.getHeight()); - const double fViewVisibleArea(fViewSizeX * fViewSizeY); - const SvtOptionsDrawinglayer aDrawinglayerOpt; - const double fMaximumVisibleArea(aDrawinglayerOpt.GetQuadratic3DRenderLimit()); - double fReduceFactor(1.0); - - if(fViewVisibleArea > fMaximumVisibleArea) - { - fReduceFactor = sqrt(fMaximumVisibleArea / fViewVisibleArea); - fViewSizeX *= fReduceFactor; - fViewSizeY *= fReduceFactor; - } + fReduceFactor = sqrt(fMaximumVisibleArea / fViewVisibleArea); + fViewSizeX *= fReduceFactor; + fViewSizeY *= fReduceFactor; + } - if(rViewInformation.getReducedDisplayQuality()) + if(rViewInformation.getReducedDisplayQuality()) + { + // when reducing the visualisation is allowed (e.g. an OverlayObject + // only needed for dragging), reduce resolution extra + // to speed up dragging interactions + const double fArea(fViewSizeX * fViewSizeY); + if (fArea != 0.0) { - // when reducing the visualisation is allowed (e.g. an OverlayObject - // only needed for dragging), reduce resolution extra - // to speed up dragging interactions - const double fArea(fViewSizeX * fViewSizeY); - if (fArea != 0.0) - { - double fReducedVisualisationFactor(1.0 / (sqrt(fArea) * (1.0 / 170.0))); - - if(fReducedVisualisationFactor > 1.0) - { - fReducedVisualisationFactor = 1.0; - } - else if(fReducedVisualisationFactor < 0.20) - { - fReducedVisualisationFactor = 0.20; - } + double fReducedVisualisationFactor(1.0 / (sqrt(fArea) * (1.0 / 170.0))); - if(fReducedVisualisationFactor != 1.0) - { - fReduceFactor *= fReducedVisualisationFactor; - } + if(fReducedVisualisationFactor > 1.0) + { + fReducedVisualisationFactor = 1.0; } - } - - // determine the oversample value - static const sal_uInt16 nDefaultOversampleValue(3); - const sal_uInt16 nOversampleValue(aDrawinglayerOpt.IsAntiAliasing() ? nDefaultOversampleValue : 0); - - geometry::ViewInformation3D aViewInformation3D(getViewInformation3D()); - { - // calculate a transformation from DiscreteRange to evtl. rotated/sheared content. - // Start with full transformation from object to discrete units - basegfx::B2DHomMatrix aObjToUnit(rViewInformation.getObjectToViewTransformation() * getObjectTransformation()); - - // bring to unit coordinates by applying inverse DiscreteRange - aObjToUnit.translate(-aDiscreteRange.getMinX(), -aDiscreteRange.getMinY()); - if (aDiscreteRange.getWidth() != 0.0 && aDiscreteRange.getHeight() != 0.0) + else if(fReducedVisualisationFactor < 0.20) { - aObjToUnit.scale(1.0 / aDiscreteRange.getWidth(), 1.0 / aDiscreteRange.getHeight()); + fReducedVisualisationFactor = 0.20; } - // calculate transformed user coordinate system - const basegfx::B2DPoint aStandardNull(0.0, 0.0); - const basegfx::B2DPoint aUnitRangeTopLeft(aObjToUnit * aStandardNull); - const basegfx::B2DVector aStandardXAxis(1.0, 0.0); - const basegfx::B2DVector aUnitRangeXAxis(aObjToUnit * aStandardXAxis); - const basegfx::B2DVector aStandardYAxis(0.0, 1.0); - const basegfx::B2DVector aUnitRangeYAxis(aObjToUnit * aStandardYAxis); - - if(!aUnitRangeTopLeft.equal(aStandardNull) || !aUnitRangeXAxis.equal(aStandardXAxis) || !aUnitRangeYAxis.equal(aStandardYAxis)) + if(fReducedVisualisationFactor != 1.0) { - // build transformation from unit range to user coordinate system; the unit range - // X and Y axes are the column vectors, the null point is the offset - basegfx::B2DHomMatrix aUnitRangeToUser; - - aUnitRangeToUser.set3x2( - aUnitRangeXAxis.getX(), aUnitRangeYAxis.getX(), aUnitRangeTopLeft.getX(), - aUnitRangeXAxis.getY(), aUnitRangeYAxis.getY(), aUnitRangeTopLeft.getY()); - - // decompose to allow to apply this to the 3D transformation - basegfx::B2DVector aScale, aTranslate; - double fRotate, fShearX; - aUnitRangeToUser.decompose(aScale, aTranslate, fRotate, fShearX); - - // apply before DeviceToView and after Projection, 3D is in range [-1.0 .. 1.0] in X,Y and Z - // and not yet flipped in Y - basegfx::B3DHomMatrix aExtendedProjection(aViewInformation3D.getProjection()); - - // bring to unit coordinates, flip Y, leave Z unchanged - aExtendedProjection.scale(0.5, -0.5, 1.0); - aExtendedProjection.translate(0.5, 0.5, 0.0); - - // apply extra; Y is flipped now, go with positive shear and rotate values - aExtendedProjection.scale(aScale.getX(), aScale.getY(), 1.0); - aExtendedProjection.shearXZ(fShearX, 0.0); - aExtendedProjection.rotate(0.0, 0.0, fRotate); - aExtendedProjection.translate(aTranslate.getX(), aTranslate.getY(), 0.0); - - // back to state after projection - aExtendedProjection.translate(-0.5, -0.5, 0.0); - aExtendedProjection.scale(2.0, -2.0, 1.0); - - aViewInformation3D = geometry::ViewInformation3D( - aViewInformation3D.getObjectTransformation(), - aViewInformation3D.getOrientation(), - aExtendedProjection, - aViewInformation3D.getDeviceToView(), - aViewInformation3D.getViewTime(), - aViewInformation3D.getExtendedInformationSequence()); + fReduceFactor *= fReducedVisualisationFactor; } } + } - // calculate logic render size in world coordinates for usage in renderer - const basegfx::B2DHomMatrix& aInverseOToV(rViewInformation.getInverseObjectToViewTransformation()); - const double fLogicX((aInverseOToV * basegfx::B2DVector(aDiscreteRange.getWidth() * fReduceFactor, 0.0)).getLength()); - const double fLogicY((aInverseOToV * basegfx::B2DVector(0.0, aDiscreteRange.getHeight() * fReduceFactor)).getLength()); + // determine the oversample value + static const sal_uInt16 nDefaultOversampleValue(3); + const sal_uInt16 nOversampleValue(aDrawinglayerOpt.IsAntiAliasing() ? nDefaultOversampleValue : 0); - // generate ViewSizes - const double fFullViewSizeX((rViewInformation.getObjectToViewTransformation() * basegfx::B2DVector(fLogicX, 0.0)).getLength()); - const double fFullViewSizeY((rViewInformation.getObjectToViewTransformation() * basegfx::B2DVector(0.0, fLogicY)).getLength()); + geometry::ViewInformation3D aViewInformation3D(getViewInformation3D()); + { + // calculate a transformation from DiscreteRange to evtl. rotated/sheared content. + // Start with full transformation from object to discrete units + basegfx::B2DHomMatrix aObjToUnit(rViewInformation.getObjectToViewTransformation() * getObjectTransformation()); + + // bring to unit coordinates by applying inverse DiscreteRange + aObjToUnit.translate(-aDiscreteRange.getMinX(), -aDiscreteRange.getMinY()); + if (aDiscreteRange.getWidth() != 0.0 && aDiscreteRange.getHeight() != 0.0) + { + aObjToUnit.scale(1.0 / aDiscreteRange.getWidth(), 1.0 / aDiscreteRange.getHeight()); + } - // generate RasterWidth and RasterHeight for visible part - const sal_Int32 nRasterWidth(basegfx::fround(fFullViewSizeX * aUnitVisibleRange.getWidth()) + 1); - const sal_Int32 nRasterHeight(basegfx::fround(fFullViewSizeY * aUnitVisibleRange.getHeight()) + 1); + // calculate transformed user coordinate system + const basegfx::B2DPoint aStandardNull(0.0, 0.0); + const basegfx::B2DPoint aUnitRangeTopLeft(aObjToUnit * aStandardNull); + const basegfx::B2DVector aStandardXAxis(1.0, 0.0); + const basegfx::B2DVector aUnitRangeXAxis(aObjToUnit * aStandardXAxis); + const basegfx::B2DVector aStandardYAxis(0.0, 1.0); + const basegfx::B2DVector aUnitRangeYAxis(aObjToUnit * aStandardYAxis); - if(nRasterWidth && nRasterHeight) + if(!aUnitRangeTopLeft.equal(aStandardNull) || !aUnitRangeXAxis.equal(aStandardXAxis) || !aUnitRangeYAxis.equal(aStandardYAxis)) { - // create view unit buffer - basegfx::BZPixelRaster aBZPixelRaster( - nOversampleValue ? nRasterWidth * nOversampleValue : nRasterWidth, - nOversampleValue ? nRasterHeight * nOversampleValue : nRasterHeight); + // build transformation from unit range to user coordinate system; the unit range + // X and Y axes are the column vectors, the null point is the offset + basegfx::B2DHomMatrix aUnitRangeToUser; + + aUnitRangeToUser.set3x2( + aUnitRangeXAxis.getX(), aUnitRangeYAxis.getX(), aUnitRangeTopLeft.getX(), + aUnitRangeXAxis.getY(), aUnitRangeYAxis.getY(), aUnitRangeTopLeft.getY()); + + // decompose to allow to apply this to the 3D transformation + basegfx::B2DVector aScale, aTranslate; + double fRotate, fShearX; + aUnitRangeToUser.decompose(aScale, aTranslate, fRotate, fShearX); + + // apply before DeviceToView and after Projection, 3D is in range [-1.0 .. 1.0] in X,Y and Z + // and not yet flipped in Y + basegfx::B3DHomMatrix aExtendedProjection(aViewInformation3D.getProjection()); + + // bring to unit coordinates, flip Y, leave Z unchanged + aExtendedProjection.scale(0.5, -0.5, 1.0); + aExtendedProjection.translate(0.5, 0.5, 0.0); + + // apply extra; Y is flipped now, go with positive shear and rotate values + aExtendedProjection.scale(aScale.getX(), aScale.getY(), 1.0); + aExtendedProjection.shearXZ(fShearX, 0.0); + aExtendedProjection.rotate(0.0, 0.0, fRotate); + aExtendedProjection.translate(aTranslate.getX(), aTranslate.getY(), 0.0); + + // back to state after projection + aExtendedProjection.translate(-0.5, -0.5, 0.0); + aExtendedProjection.scale(2.0, -2.0, 1.0); + + aViewInformation3D = geometry::ViewInformation3D( + aViewInformation3D.getObjectTransformation(), + aViewInformation3D.getOrientation(), + aExtendedProjection, + aViewInformation3D.getDeviceToView(), + aViewInformation3D.getViewTime(), + aViewInformation3D.getExtendedInformationSequence()); + } + } - // check for parallel execution possibilities - static bool bMultithreadAllowed = false; // loplugin:constvars:ignore - sal_Int32 nThreadCount(0); - comphelper::ThreadPool& rThreadPool(comphelper::ThreadPool::getSharedOptimalPool()); + // calculate logic render size in world coordinates for usage in renderer + const basegfx::B2DHomMatrix& aInverseOToV(rViewInformation.getInverseObjectToViewTransformation()); + const double fLogicX((aInverseOToV * basegfx::B2DVector(aDiscreteRange.getWidth() * fReduceFactor, 0.0)).getLength()); + const double fLogicY((aInverseOToV * basegfx::B2DVector(0.0, aDiscreteRange.getHeight() * fReduceFactor)).getLength()); - if(bMultithreadAllowed) - { - nThreadCount = rThreadPool.getWorkerCount(); + // generate ViewSizes + const double fFullViewSizeX((rViewInformation.getObjectToViewTransformation() * basegfx::B2DVector(fLogicX, 0.0)).getLength()); + const double fFullViewSizeY((rViewInformation.getObjectToViewTransformation() * basegfx::B2DVector(0.0, fLogicY)).getLength()); - if(nThreadCount > 1) - { - // at least use 10px per processor, so limit number of processors to - // target pixel size divided by 10 (which might be zero what is okay) - nThreadCount = std::min(nThreadCount, nRasterHeight / 10); - } - } + // generate RasterWidth and RasterHeight for visible part + const sal_Int32 nRasterWidth(basegfx::fround(fFullViewSizeX * aUnitVisibleRange.getWidth()) + 1); + const sal_Int32 nRasterHeight(basegfx::fround(fFullViewSizeY * aUnitVisibleRange.getHeight()) + 1); - if(nThreadCount > 1) - { - class Executor : public comphelper::ThreadTask - { - private: - std::unique_ptr<processor3d::ZBufferProcessor3D> mpZBufferProcessor3D; - const primitive3d::Primitive3DContainer& mrChildren3D; - - public: - explicit Executor( - std::shared_ptr<comphelper::ThreadTaskTag> const & rTag, - std::unique_ptr<processor3d::ZBufferProcessor3D> pZBufferProcessor3D, - const primitive3d::Primitive3DContainer& rChildren3D) - : comphelper::ThreadTask(rTag), - mpZBufferProcessor3D(std::move(pZBufferProcessor3D)), - mrChildren3D(rChildren3D) - { - } + if(!(nRasterWidth && nRasterHeight)) + return; - virtual void doWork() override - { - mpZBufferProcessor3D->process(mrChildren3D); - mpZBufferProcessor3D->finish(); - mpZBufferProcessor3D.reset(); - } - }; + // create view unit buffer + basegfx::BZPixelRaster aBZPixelRaster( + nOversampleValue ? nRasterWidth * nOversampleValue : nRasterWidth, + nOversampleValue ? nRasterHeight * nOversampleValue : nRasterHeight); - const sal_uInt32 nLinesPerThread(aBZPixelRaster.getHeight() / nThreadCount); - std::shared_ptr<comphelper::ThreadTaskTag> aTag = comphelper::ThreadPool::createThreadTaskTag(); + // check for parallel execution possibilities + static bool bMultithreadAllowed = false; // loplugin:constvars:ignore + sal_Int32 nThreadCount(0); + comphelper::ThreadPool& rThreadPool(comphelper::ThreadPool::getSharedOptimalPool()); - for(sal_Int32 a(0); a < nThreadCount; a++) - { - std::unique_ptr<processor3d::ZBufferProcessor3D> pNewZBufferProcessor3D(new processor3d::ZBufferProcessor3D( - aViewInformation3D, - getSdrSceneAttribute(), - getSdrLightingAttribute(), - aUnitVisibleRange, - nOversampleValue, - fFullViewSizeX, - fFullViewSizeY, - aBZPixelRaster, - nLinesPerThread * a, - a + 1 == nThreadCount ? aBZPixelRaster.getHeight() : nLinesPerThread * (a + 1))); - std::unique_ptr<Executor> pExecutor(new Executor(aTag, std::move(pNewZBufferProcessor3D), getChildren3D())); - rThreadPool.pushTask(std::move(pExecutor)); - } + if(bMultithreadAllowed) + { + nThreadCount = rThreadPool.getWorkerCount(); + + if(nThreadCount > 1) + { + // at least use 10px per processor, so limit number of processors to + // target pixel size divided by 10 (which might be zero what is okay) + nThreadCount = std::min(nThreadCount, nRasterHeight / 10); + } + } - rThreadPool.waitUntilDone(aTag); + if(nThreadCount > 1) + { + class Executor : public comphelper::ThreadTask + { + private: + std::unique_ptr<processor3d::ZBufferProcessor3D> mpZBufferProcessor3D; + const primitive3d::Primitive3DContainer& mrChildren3D; + + public: + explicit Executor( + std::shared_ptr<comphelper::ThreadTaskTag> const & rTag, + std::unique_ptr<processor3d::ZBufferProcessor3D> pZBufferProcessor3D, + const primitive3d::Primitive3DContainer& rChildren3D) + : comphelper::ThreadTask(rTag), + mpZBufferProcessor3D(std::move(pZBufferProcessor3D)), + mrChildren3D(rChildren3D) + { } - else + + virtual void doWork() override { - // use default 3D primitive processor to create BitmapEx for aUnitVisiblePart and process - processor3d::ZBufferProcessor3D aZBufferProcessor3D( - aViewInformation3D, - getSdrSceneAttribute(), - getSdrLightingAttribute(), - aUnitVisibleRange, - nOversampleValue, - fFullViewSizeX, - fFullViewSizeY, - aBZPixelRaster, - 0, - aBZPixelRaster.getHeight()); - - aZBufferProcessor3D.process(getChildren3D()); - aZBufferProcessor3D.finish(); + mpZBufferProcessor3D->process(mrChildren3D); + mpZBufferProcessor3D->finish(); + mpZBufferProcessor3D.reset(); } + }; - const_cast< ScenePrimitive2D* >(this)->maOldRenderedBitmap = BPixelRasterToBitmapEx(aBZPixelRaster, nOversampleValue); - const Size aBitmapSizePixel(maOldRenderedBitmap.GetSizePixel()); + const sal_uInt32 nLinesPerThread(aBZPixelRaster.getHeight() / nThreadCount); + std::shared_ptr<comphelper::ThreadTaskTag> aTag = comphelper::ThreadPool::createThreadTaskTag(); - if(aBitmapSizePixel.getWidth() && aBitmapSizePixel.getHeight()) - { - // create transform for the created bitmap in discrete coordinates first. - basegfx::B2DHomMatrix aNew2DTransform; + for(sal_Int32 a(0); a < nThreadCount; a++) + { + std::unique_ptr<processor3d::ZBufferProcessor3D> pNewZBufferProcessor3D(new processor3d::ZBufferProcessor3D( + aViewInformation3D, + getSdrSceneAttribute(), + getSdrLightingAttribute(), + aUnitVisibleRange, + nOversampleValue, + fFullViewSizeX, + fFullViewSizeY, + aBZPixelRaster, + nLinesPerThread * a, + a + 1 == nThreadCount ? aBZPixelRaster.getHeight() : nLinesPerThread * (a + 1))); + std::unique_ptr<Executor> pExecutor(new Executor(aTag, std::move(pNewZBufferProcessor3D), getChildren3D())); + rThreadPool.pushTask(std::move(pExecutor)); + } - aNew2DTransform.set(0, 0, aVisibleDiscreteRange.getWidth()); - aNew2DTransform.set(1, 1, aVisibleDiscreteRange.getHeight()); - aNew2DTransform.set(0, 2, aVisibleDiscreteRange.getMinX()); - aNew2DTransform.set(1, 2, aVisibleDiscreteRange.getMinY()); + rThreadPool.waitUntilDone(aTag); + } + else + { + // use default 3D primitive processor to create BitmapEx for aUnitVisiblePart and process + processor3d::ZBufferProcessor3D aZBufferProcessor3D( + aViewInformation3D, + getSdrSceneAttribute(), + getSdrLightingAttribute(), + aUnitVisibleRange, + nOversampleValue, + fFullViewSizeX, + fFullViewSizeY, + aBZPixelRaster, + 0, + aBZPixelRaster.getHeight()); + + aZBufferProcessor3D.process(getChildren3D()); + aZBufferProcessor3D.finish(); + } - // transform back to world coordinates for usage in primitive creation - aNew2DTransform *= aInverseOToV; + const_cast< ScenePrimitive2D* >(this)->maOldRenderedBitmap = BPixelRasterToBitmapEx(aBZPixelRaster, nOversampleValue); + const Size aBitmapSizePixel(maOldRenderedBitmap.GetSizePixel()); - // create bitmap primitive and add - rContainer.push_back( - new BitmapPrimitive2D( - VCLUnoHelper::CreateVCLXBitmap(maOldRenderedBitmap), - aNew2DTransform)); + if(!(aBitmapSizePixel.getWidth() && aBitmapSizePixel.getHeight())) + return; - // test: Allow to add an outline in the debugger when tests are needed - static bool bAddOutlineToCreated3DSceneRepresentation(false); // loplugin:constvars:ignore + // create transform for the created bitmap in discrete coordinates first. + basegfx::B2DHomMatrix aNew2DTransform; - if(bAddOutlineToCreated3DSceneRepresentation) - { - basegfx::B2DPolygon aOutline(basegfx::utils::createUnitPolygon()); - aOutline.transform(aNew2DTransform); - rContainer.push_back(new PolygonHairlinePrimitive2D(aOutline, basegfx::BColor(1.0, 0.0, 0.0))); - } - } - } + aNew2DTransform.set(0, 0, aVisibleDiscreteRange.getWidth()); + aNew2DTransform.set(1, 1, aVisibleDiscreteRange.getHeight()); + aNew2DTransform.set(0, 2, aVisibleDiscreteRange.getMinX()); + aNew2DTransform.set(1, 2, aVisibleDiscreteRange.getMinY()); + + // transform back to world coordinates for usage in primitive creation + aNew2DTransform *= aInverseOToV; + + // create bitmap primitive and add + rContainer.push_back( + new BitmapPrimitive2D( + VCLUnoHelper::CreateVCLXBitmap(maOldRenderedBitmap), + aNew2DTransform)); + + // test: Allow to add an outline in the debugger when tests are needed + static bool bAddOutlineToCreated3DSceneRepresentation(false); // loplugin:constvars:ignore + + if(bAddOutlineToCreated3DSceneRepresentation) + { + basegfx::B2DPolygon aOutline(basegfx::utils::createUnitPolygon()); + aOutline.transform(aNew2DTransform); + rContainer.push_back(new PolygonHairlinePrimitive2D(aOutline, basegfx::BColor(1.0, 0.0, 0.0))); } } |