office-gobmx/drawinglayer/source/primitive2d/BufferedDecompositionGroupPrimitive2D.cxx

158 lines
4.8 KiB
C++
Raw Normal View History

/* -*- 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 <sal/config.h>
#include <drawinglayer/primitive2d/BufferedDecompositionGroupPrimitive2D.hxx>
#include <drawinglayer/geometry/viewinformation2d.hxx>
Add flush mechanism to buffered Primitives There are the classes BufferedDecompositionPrimitive2D and BufferedDecompositionGroupPrimitive2D that offer a unified mechanism to preserve/buffer the decomposition of a Primitive, independent of the complexity. This may include e.g. the pixel representation of a 3D Scene, for Charts/CustomShapes and others. Until now these were refreshed when the objects change, or when the buffered decomposition decides that it is necessary, but there was no general mechanism in place to clean these up while the Primitive owning them was alive/used. This is not a big thing in Draw/Impress since this would only be relevant when zooming deep into a SdrPage, so the non-vislible parts would still hold data that would not be needed. But for Calc and Writer this is more relevant: A 3D Chart on the 1st page of a Writer document would be held buffered all the time a user would work on pages below that. This is good for guaranteeing fast re-visualization when scrolling up again, but until then would just block memory. So I added this general mechanism that allows activating flushing timer-based, on Seconds. The default is null seconds, thus deactivated. It should only be used for Primitives that can get expensive, not for all. NOTE: I checked activating for all Primitives to be on the safe side, works. It is now (initially) activated for: - GlowPrimitive2D - GraphicPrimitive2D - MetafilePrimitive2D - ScenePrimitive2D - ShadowPrimitive2D (softShadow) - SoftEdgePrimitive2D - SdrCustomShapePrimitive2D - SdrGrafPrimitive2D These are the usual suspects that may use some memory to buffer their decomposition (for good reasons, each repaint uses it). Other Primitives which may show need to be treated this way can easily be added, just by calling setCallbackSeconds(s) in their constructor. This is true for all Primitives derived from the two classes mentioned above. NOTE: Too short buffering times are *not* useful - e.g. for a expensive-to-be-recreated 3D chart representation this may not pay out, so I chose times in a way that try to respect this. NOTE: This change needs 7397fa7cdfc33f5a079df42e4d6cfa59ae9e062d to work correctly (thanks to sberg for this). Without this the office hangs/does not terminate regularly in trying to destroy the 'TimerManager'. Change-Id: Id4802afcb6d12480bb2935cc1ef67fe443b3b788 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/160926 Tested-by: Jenkins Reviewed-by: Armin Le Grand <Armin.Le.Grand@me.com>
2023-12-18 11:23:37 -06:00
namespace
{
class LocalCallbackTimer : public salhelper::Timer
{
protected:
drawinglayer::primitive2d::BufferedDecompositionGroupPrimitive2D* pCustomer;
public:
explicit LocalCallbackTimer(
drawinglayer::primitive2d::BufferedDecompositionGroupPrimitive2D& rCustomer)
: pCustomer(&rCustomer)
{
}
void clearCallback() { pCustomer = nullptr; }
Add flush mechanism to buffered Primitives There are the classes BufferedDecompositionPrimitive2D and BufferedDecompositionGroupPrimitive2D that offer a unified mechanism to preserve/buffer the decomposition of a Primitive, independent of the complexity. This may include e.g. the pixel representation of a 3D Scene, for Charts/CustomShapes and others. Until now these were refreshed when the objects change, or when the buffered decomposition decides that it is necessary, but there was no general mechanism in place to clean these up while the Primitive owning them was alive/used. This is not a big thing in Draw/Impress since this would only be relevant when zooming deep into a SdrPage, so the non-vislible parts would still hold data that would not be needed. But for Calc and Writer this is more relevant: A 3D Chart on the 1st page of a Writer document would be held buffered all the time a user would work on pages below that. This is good for guaranteeing fast re-visualization when scrolling up again, but until then would just block memory. So I added this general mechanism that allows activating flushing timer-based, on Seconds. The default is null seconds, thus deactivated. It should only be used for Primitives that can get expensive, not for all. NOTE: I checked activating for all Primitives to be on the safe side, works. It is now (initially) activated for: - GlowPrimitive2D - GraphicPrimitive2D - MetafilePrimitive2D - ScenePrimitive2D - ShadowPrimitive2D (softShadow) - SoftEdgePrimitive2D - SdrCustomShapePrimitive2D - SdrGrafPrimitive2D These are the usual suspects that may use some memory to buffer their decomposition (for good reasons, each repaint uses it). Other Primitives which may show need to be treated this way can easily be added, just by calling setCallbackSeconds(s) in their constructor. This is true for all Primitives derived from the two classes mentioned above. NOTE: Too short buffering times are *not* useful - e.g. for a expensive-to-be-recreated 3D chart representation this may not pay out, so I chose times in a way that try to respect this. NOTE: This change needs 7397fa7cdfc33f5a079df42e4d6cfa59ae9e062d to work correctly (thanks to sberg for this). Without this the office hangs/does not terminate regularly in trying to destroy the 'TimerManager'. Change-Id: Id4802afcb6d12480bb2935cc1ef67fe443b3b788 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/160926 Tested-by: Jenkins Reviewed-by: Armin Le Grand <Armin.Le.Grand@me.com>
2023-12-18 11:23:37 -06:00
protected:
virtual void SAL_CALL onShot() override;
};
void SAL_CALL LocalCallbackTimer::onShot()
{
if (nullptr != pCustomer)
flushBufferedDecomposition(*pCustomer);
}
Add flush mechanism to buffered Primitives There are the classes BufferedDecompositionPrimitive2D and BufferedDecompositionGroupPrimitive2D that offer a unified mechanism to preserve/buffer the decomposition of a Primitive, independent of the complexity. This may include e.g. the pixel representation of a 3D Scene, for Charts/CustomShapes and others. Until now these were refreshed when the objects change, or when the buffered decomposition decides that it is necessary, but there was no general mechanism in place to clean these up while the Primitive owning them was alive/used. This is not a big thing in Draw/Impress since this would only be relevant when zooming deep into a SdrPage, so the non-vislible parts would still hold data that would not be needed. But for Calc and Writer this is more relevant: A 3D Chart on the 1st page of a Writer document would be held buffered all the time a user would work on pages below that. This is good for guaranteeing fast re-visualization when scrolling up again, but until then would just block memory. So I added this general mechanism that allows activating flushing timer-based, on Seconds. The default is null seconds, thus deactivated. It should only be used for Primitives that can get expensive, not for all. NOTE: I checked activating for all Primitives to be on the safe side, works. It is now (initially) activated for: - GlowPrimitive2D - GraphicPrimitive2D - MetafilePrimitive2D - ScenePrimitive2D - ShadowPrimitive2D (softShadow) - SoftEdgePrimitive2D - SdrCustomShapePrimitive2D - SdrGrafPrimitive2D These are the usual suspects that may use some memory to buffer their decomposition (for good reasons, each repaint uses it). Other Primitives which may show need to be treated this way can easily be added, just by calling setCallbackSeconds(s) in their constructor. This is true for all Primitives derived from the two classes mentioned above. NOTE: Too short buffering times are *not* useful - e.g. for a expensive-to-be-recreated 3D chart representation this may not pay out, so I chose times in a way that try to respect this. NOTE: This change needs 7397fa7cdfc33f5a079df42e4d6cfa59ae9e062d to work correctly (thanks to sberg for this). Without this the office hangs/does not terminate regularly in trying to destroy the 'TimerManager'. Change-Id: Id4802afcb6d12480bb2935cc1ef67fe443b3b788 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/160926 Tested-by: Jenkins Reviewed-by: Armin Le Grand <Armin.Le.Grand@me.com>
2023-12-18 11:23:37 -06:00
}
namespace drawinglayer::primitive2d
{
Add flush mechanism to buffered Primitives There are the classes BufferedDecompositionPrimitive2D and BufferedDecompositionGroupPrimitive2D that offer a unified mechanism to preserve/buffer the decomposition of a Primitive, independent of the complexity. This may include e.g. the pixel representation of a 3D Scene, for Charts/CustomShapes and others. Until now these were refreshed when the objects change, or when the buffered decomposition decides that it is necessary, but there was no general mechanism in place to clean these up while the Primitive owning them was alive/used. This is not a big thing in Draw/Impress since this would only be relevant when zooming deep into a SdrPage, so the non-vislible parts would still hold data that would not be needed. But for Calc and Writer this is more relevant: A 3D Chart on the 1st page of a Writer document would be held buffered all the time a user would work on pages below that. This is good for guaranteeing fast re-visualization when scrolling up again, but until then would just block memory. So I added this general mechanism that allows activating flushing timer-based, on Seconds. The default is null seconds, thus deactivated. It should only be used for Primitives that can get expensive, not for all. NOTE: I checked activating for all Primitives to be on the safe side, works. It is now (initially) activated for: - GlowPrimitive2D - GraphicPrimitive2D - MetafilePrimitive2D - ScenePrimitive2D - ShadowPrimitive2D (softShadow) - SoftEdgePrimitive2D - SdrCustomShapePrimitive2D - SdrGrafPrimitive2D These are the usual suspects that may use some memory to buffer their decomposition (for good reasons, each repaint uses it). Other Primitives which may show need to be treated this way can easily be added, just by calling setCallbackSeconds(s) in their constructor. This is true for all Primitives derived from the two classes mentioned above. NOTE: Too short buffering times are *not* useful - e.g. for a expensive-to-be-recreated 3D chart representation this may not pay out, so I chose times in a way that try to respect this. NOTE: This change needs 7397fa7cdfc33f5a079df42e4d6cfa59ae9e062d to work correctly (thanks to sberg for this). Without this the office hangs/does not terminate regularly in trying to destroy the 'TimerManager'. Change-Id: Id4802afcb6d12480bb2935cc1ef67fe443b3b788 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/160926 Tested-by: Jenkins Reviewed-by: Armin Le Grand <Armin.Le.Grand@me.com>
2023-12-18 11:23:37 -06:00
void flushBufferedDecomposition(BufferedDecompositionGroupPrimitive2D& rTarget)
{
rTarget.acquire();
Add flush mechanism to buffered Primitives There are the classes BufferedDecompositionPrimitive2D and BufferedDecompositionGroupPrimitive2D that offer a unified mechanism to preserve/buffer the decomposition of a Primitive, independent of the complexity. This may include e.g. the pixel representation of a 3D Scene, for Charts/CustomShapes and others. Until now these were refreshed when the objects change, or when the buffered decomposition decides that it is necessary, but there was no general mechanism in place to clean these up while the Primitive owning them was alive/used. This is not a big thing in Draw/Impress since this would only be relevant when zooming deep into a SdrPage, so the non-vislible parts would still hold data that would not be needed. But for Calc and Writer this is more relevant: A 3D Chart on the 1st page of a Writer document would be held buffered all the time a user would work on pages below that. This is good for guaranteeing fast re-visualization when scrolling up again, but until then would just block memory. So I added this general mechanism that allows activating flushing timer-based, on Seconds. The default is null seconds, thus deactivated. It should only be used for Primitives that can get expensive, not for all. NOTE: I checked activating for all Primitives to be on the safe side, works. It is now (initially) activated for: - GlowPrimitive2D - GraphicPrimitive2D - MetafilePrimitive2D - ScenePrimitive2D - ShadowPrimitive2D (softShadow) - SoftEdgePrimitive2D - SdrCustomShapePrimitive2D - SdrGrafPrimitive2D These are the usual suspects that may use some memory to buffer their decomposition (for good reasons, each repaint uses it). Other Primitives which may show need to be treated this way can easily be added, just by calling setCallbackSeconds(s) in their constructor. This is true for all Primitives derived from the two classes mentioned above. NOTE: Too short buffering times are *not* useful - e.g. for a expensive-to-be-recreated 3D chart representation this may not pay out, so I chose times in a way that try to respect this. NOTE: This change needs 7397fa7cdfc33f5a079df42e4d6cfa59ae9e062d to work correctly (thanks to sberg for this). Without this the office hangs/does not terminate regularly in trying to destroy the 'TimerManager'. Change-Id: Id4802afcb6d12480bb2935cc1ef67fe443b3b788 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/160926 Tested-by: Jenkins Reviewed-by: Armin Le Grand <Armin.Le.Grand@me.com>
2023-12-18 11:23:37 -06:00
rTarget.setBuffered2DDecomposition(Primitive2DContainer());
rTarget.release();
Add flush mechanism to buffered Primitives There are the classes BufferedDecompositionPrimitive2D and BufferedDecompositionGroupPrimitive2D that offer a unified mechanism to preserve/buffer the decomposition of a Primitive, independent of the complexity. This may include e.g. the pixel representation of a 3D Scene, for Charts/CustomShapes and others. Until now these were refreshed when the objects change, or when the buffered decomposition decides that it is necessary, but there was no general mechanism in place to clean these up while the Primitive owning them was alive/used. This is not a big thing in Draw/Impress since this would only be relevant when zooming deep into a SdrPage, so the non-vislible parts would still hold data that would not be needed. But for Calc and Writer this is more relevant: A 3D Chart on the 1st page of a Writer document would be held buffered all the time a user would work on pages below that. This is good for guaranteeing fast re-visualization when scrolling up again, but until then would just block memory. So I added this general mechanism that allows activating flushing timer-based, on Seconds. The default is null seconds, thus deactivated. It should only be used for Primitives that can get expensive, not for all. NOTE: I checked activating for all Primitives to be on the safe side, works. It is now (initially) activated for: - GlowPrimitive2D - GraphicPrimitive2D - MetafilePrimitive2D - ScenePrimitive2D - ShadowPrimitive2D (softShadow) - SoftEdgePrimitive2D - SdrCustomShapePrimitive2D - SdrGrafPrimitive2D These are the usual suspects that may use some memory to buffer their decomposition (for good reasons, each repaint uses it). Other Primitives which may show need to be treated this way can easily be added, just by calling setCallbackSeconds(s) in their constructor. This is true for all Primitives derived from the two classes mentioned above. NOTE: Too short buffering times are *not* useful - e.g. for a expensive-to-be-recreated 3D chart representation this may not pay out, so I chose times in a way that try to respect this. NOTE: This change needs 7397fa7cdfc33f5a079df42e4d6cfa59ae9e062d to work correctly (thanks to sberg for this). Without this the office hangs/does not terminate regularly in trying to destroy the 'TimerManager'. Change-Id: Id4802afcb6d12480bb2935cc1ef67fe443b3b788 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/160926 Tested-by: Jenkins Reviewed-by: Armin Le Grand <Armin.Le.Grand@me.com>
2023-12-18 11:23:37 -06:00
}
const Primitive2DContainer&
BufferedDecompositionGroupPrimitive2D::getBuffered2DDecomposition() const
{
if (0 != maCallbackSeconds && maCallbackTimer.is())
{
// decomposition was used, touch/restart time
Add flush mechanism to buffered Primitives There are the classes BufferedDecompositionPrimitive2D and BufferedDecompositionGroupPrimitive2D that offer a unified mechanism to preserve/buffer the decomposition of a Primitive, independent of the complexity. This may include e.g. the pixel representation of a 3D Scene, for Charts/CustomShapes and others. Until now these were refreshed when the objects change, or when the buffered decomposition decides that it is necessary, but there was no general mechanism in place to clean these up while the Primitive owning them was alive/used. This is not a big thing in Draw/Impress since this would only be relevant when zooming deep into a SdrPage, so the non-vislible parts would still hold data that would not be needed. But for Calc and Writer this is more relevant: A 3D Chart on the 1st page of a Writer document would be held buffered all the time a user would work on pages below that. This is good for guaranteeing fast re-visualization when scrolling up again, but until then would just block memory. So I added this general mechanism that allows activating flushing timer-based, on Seconds. The default is null seconds, thus deactivated. It should only be used for Primitives that can get expensive, not for all. NOTE: I checked activating for all Primitives to be on the safe side, works. It is now (initially) activated for: - GlowPrimitive2D - GraphicPrimitive2D - MetafilePrimitive2D - ScenePrimitive2D - ShadowPrimitive2D (softShadow) - SoftEdgePrimitive2D - SdrCustomShapePrimitive2D - SdrGrafPrimitive2D These are the usual suspects that may use some memory to buffer their decomposition (for good reasons, each repaint uses it). Other Primitives which may show need to be treated this way can easily be added, just by calling setCallbackSeconds(s) in their constructor. This is true for all Primitives derived from the two classes mentioned above. NOTE: Too short buffering times are *not* useful - e.g. for a expensive-to-be-recreated 3D chart representation this may not pay out, so I chose times in a way that try to respect this. NOTE: This change needs 7397fa7cdfc33f5a079df42e4d6cfa59ae9e062d to work correctly (thanks to sberg for this). Without this the office hangs/does not terminate regularly in trying to destroy the 'TimerManager'. Change-Id: Id4802afcb6d12480bb2935cc1ef67fe443b3b788 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/160926 Tested-by: Jenkins Reviewed-by: Armin Le Grand <Armin.Le.Grand@me.com>
2023-12-18 11:23:37 -06:00
maCallbackTimer->setRemainingTime(salhelper::TTimeValue(maCallbackSeconds, 0));
}
return maBuffered2DDecomposition;
}
void BufferedDecompositionGroupPrimitive2D::setBuffered2DDecomposition(Primitive2DContainer&& rNew)
{
if (0 == maCallbackSeconds)
Add flush mechanism to buffered Primitives There are the classes BufferedDecompositionPrimitive2D and BufferedDecompositionGroupPrimitive2D that offer a unified mechanism to preserve/buffer the decomposition of a Primitive, independent of the complexity. This may include e.g. the pixel representation of a 3D Scene, for Charts/CustomShapes and others. Until now these were refreshed when the objects change, or when the buffered decomposition decides that it is necessary, but there was no general mechanism in place to clean these up while the Primitive owning them was alive/used. This is not a big thing in Draw/Impress since this would only be relevant when zooming deep into a SdrPage, so the non-vislible parts would still hold data that would not be needed. But for Calc and Writer this is more relevant: A 3D Chart on the 1st page of a Writer document would be held buffered all the time a user would work on pages below that. This is good for guaranteeing fast re-visualization when scrolling up again, but until then would just block memory. So I added this general mechanism that allows activating flushing timer-based, on Seconds. The default is null seconds, thus deactivated. It should only be used for Primitives that can get expensive, not for all. NOTE: I checked activating for all Primitives to be on the safe side, works. It is now (initially) activated for: - GlowPrimitive2D - GraphicPrimitive2D - MetafilePrimitive2D - ScenePrimitive2D - ShadowPrimitive2D (softShadow) - SoftEdgePrimitive2D - SdrCustomShapePrimitive2D - SdrGrafPrimitive2D These are the usual suspects that may use some memory to buffer their decomposition (for good reasons, each repaint uses it). Other Primitives which may show need to be treated this way can easily be added, just by calling setCallbackSeconds(s) in their constructor. This is true for all Primitives derived from the two classes mentioned above. NOTE: Too short buffering times are *not* useful - e.g. for a expensive-to-be-recreated 3D chart representation this may not pay out, so I chose times in a way that try to respect this. NOTE: This change needs 7397fa7cdfc33f5a079df42e4d6cfa59ae9e062d to work correctly (thanks to sberg for this). Without this the office hangs/does not terminate regularly in trying to destroy the 'TimerManager'. Change-Id: Id4802afcb6d12480bb2935cc1ef67fe443b3b788 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/160926 Tested-by: Jenkins Reviewed-by: Armin Le Grand <Armin.Le.Grand@me.com>
2023-12-18 11:23:37 -06:00
{
// no flush used, just set
maBuffered2DDecomposition = std::move(rNew);
return;
}
if (maCallbackTimer.is())
{
if (rNew.empty())
Add flush mechanism to buffered Primitives There are the classes BufferedDecompositionPrimitive2D and BufferedDecompositionGroupPrimitive2D that offer a unified mechanism to preserve/buffer the decomposition of a Primitive, independent of the complexity. This may include e.g. the pixel representation of a 3D Scene, for Charts/CustomShapes and others. Until now these were refreshed when the objects change, or when the buffered decomposition decides that it is necessary, but there was no general mechanism in place to clean these up while the Primitive owning them was alive/used. This is not a big thing in Draw/Impress since this would only be relevant when zooming deep into a SdrPage, so the non-vislible parts would still hold data that would not be needed. But for Calc and Writer this is more relevant: A 3D Chart on the 1st page of a Writer document would be held buffered all the time a user would work on pages below that. This is good for guaranteeing fast re-visualization when scrolling up again, but until then would just block memory. So I added this general mechanism that allows activating flushing timer-based, on Seconds. The default is null seconds, thus deactivated. It should only be used for Primitives that can get expensive, not for all. NOTE: I checked activating for all Primitives to be on the safe side, works. It is now (initially) activated for: - GlowPrimitive2D - GraphicPrimitive2D - MetafilePrimitive2D - ScenePrimitive2D - ShadowPrimitive2D (softShadow) - SoftEdgePrimitive2D - SdrCustomShapePrimitive2D - SdrGrafPrimitive2D These are the usual suspects that may use some memory to buffer their decomposition (for good reasons, each repaint uses it). Other Primitives which may show need to be treated this way can easily be added, just by calling setCallbackSeconds(s) in their constructor. This is true for all Primitives derived from the two classes mentioned above. NOTE: Too short buffering times are *not* useful - e.g. for a expensive-to-be-recreated 3D chart representation this may not pay out, so I chose times in a way that try to respect this. NOTE: This change needs 7397fa7cdfc33f5a079df42e4d6cfa59ae9e062d to work correctly (thanks to sberg for this). Without this the office hangs/does not terminate regularly in trying to destroy the 'TimerManager'. Change-Id: Id4802afcb6d12480bb2935cc1ef67fe443b3b788 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/160926 Tested-by: Jenkins Reviewed-by: Armin Le Grand <Armin.Le.Grand@me.com>
2023-12-18 11:23:37 -06:00
{
// stop timer
maCallbackTimer->stop();
Add flush mechanism to buffered Primitives There are the classes BufferedDecompositionPrimitive2D and BufferedDecompositionGroupPrimitive2D that offer a unified mechanism to preserve/buffer the decomposition of a Primitive, independent of the complexity. This may include e.g. the pixel representation of a 3D Scene, for Charts/CustomShapes and others. Until now these were refreshed when the objects change, or when the buffered decomposition decides that it is necessary, but there was no general mechanism in place to clean these up while the Primitive owning them was alive/used. This is not a big thing in Draw/Impress since this would only be relevant when zooming deep into a SdrPage, so the non-vislible parts would still hold data that would not be needed. But for Calc and Writer this is more relevant: A 3D Chart on the 1st page of a Writer document would be held buffered all the time a user would work on pages below that. This is good for guaranteeing fast re-visualization when scrolling up again, but until then would just block memory. So I added this general mechanism that allows activating flushing timer-based, on Seconds. The default is null seconds, thus deactivated. It should only be used for Primitives that can get expensive, not for all. NOTE: I checked activating for all Primitives to be on the safe side, works. It is now (initially) activated for: - GlowPrimitive2D - GraphicPrimitive2D - MetafilePrimitive2D - ScenePrimitive2D - ShadowPrimitive2D (softShadow) - SoftEdgePrimitive2D - SdrCustomShapePrimitive2D - SdrGrafPrimitive2D These are the usual suspects that may use some memory to buffer their decomposition (for good reasons, each repaint uses it). Other Primitives which may show need to be treated this way can easily be added, just by calling setCallbackSeconds(s) in their constructor. This is true for all Primitives derived from the two classes mentioned above. NOTE: Too short buffering times are *not* useful - e.g. for a expensive-to-be-recreated 3D chart representation this may not pay out, so I chose times in a way that try to respect this. NOTE: This change needs 7397fa7cdfc33f5a079df42e4d6cfa59ae9e062d to work correctly (thanks to sberg for this). Without this the office hangs/does not terminate regularly in trying to destroy the 'TimerManager'. Change-Id: Id4802afcb6d12480bb2935cc1ef67fe443b3b788 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/160926 Tested-by: Jenkins Reviewed-by: Armin Le Grand <Armin.Le.Grand@me.com>
2023-12-18 11:23:37 -06:00
}
else
Add flush mechanism to buffered Primitives There are the classes BufferedDecompositionPrimitive2D and BufferedDecompositionGroupPrimitive2D that offer a unified mechanism to preserve/buffer the decomposition of a Primitive, independent of the complexity. This may include e.g. the pixel representation of a 3D Scene, for Charts/CustomShapes and others. Until now these were refreshed when the objects change, or when the buffered decomposition decides that it is necessary, but there was no general mechanism in place to clean these up while the Primitive owning them was alive/used. This is not a big thing in Draw/Impress since this would only be relevant when zooming deep into a SdrPage, so the non-vislible parts would still hold data that would not be needed. But for Calc and Writer this is more relevant: A 3D Chart on the 1st page of a Writer document would be held buffered all the time a user would work on pages below that. This is good for guaranteeing fast re-visualization when scrolling up again, but until then would just block memory. So I added this general mechanism that allows activating flushing timer-based, on Seconds. The default is null seconds, thus deactivated. It should only be used for Primitives that can get expensive, not for all. NOTE: I checked activating for all Primitives to be on the safe side, works. It is now (initially) activated for: - GlowPrimitive2D - GraphicPrimitive2D - MetafilePrimitive2D - ScenePrimitive2D - ShadowPrimitive2D (softShadow) - SoftEdgePrimitive2D - SdrCustomShapePrimitive2D - SdrGrafPrimitive2D These are the usual suspects that may use some memory to buffer their decomposition (for good reasons, each repaint uses it). Other Primitives which may show need to be treated this way can easily be added, just by calling setCallbackSeconds(s) in their constructor. This is true for all Primitives derived from the two classes mentioned above. NOTE: Too short buffering times are *not* useful - e.g. for a expensive-to-be-recreated 3D chart representation this may not pay out, so I chose times in a way that try to respect this. NOTE: This change needs 7397fa7cdfc33f5a079df42e4d6cfa59ae9e062d to work correctly (thanks to sberg for this). Without this the office hangs/does not terminate regularly in trying to destroy the 'TimerManager'. Change-Id: Id4802afcb6d12480bb2935cc1ef67fe443b3b788 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/160926 Tested-by: Jenkins Reviewed-by: Armin Le Grand <Armin.Le.Grand@me.com>
2023-12-18 11:23:37 -06:00
{
// decomposition changed, touch
Add flush mechanism to buffered Primitives There are the classes BufferedDecompositionPrimitive2D and BufferedDecompositionGroupPrimitive2D that offer a unified mechanism to preserve/buffer the decomposition of a Primitive, independent of the complexity. This may include e.g. the pixel representation of a 3D Scene, for Charts/CustomShapes and others. Until now these were refreshed when the objects change, or when the buffered decomposition decides that it is necessary, but there was no general mechanism in place to clean these up while the Primitive owning them was alive/used. This is not a big thing in Draw/Impress since this would only be relevant when zooming deep into a SdrPage, so the non-vislible parts would still hold data that would not be needed. But for Calc and Writer this is more relevant: A 3D Chart on the 1st page of a Writer document would be held buffered all the time a user would work on pages below that. This is good for guaranteeing fast re-visualization when scrolling up again, but until then would just block memory. So I added this general mechanism that allows activating flushing timer-based, on Seconds. The default is null seconds, thus deactivated. It should only be used for Primitives that can get expensive, not for all. NOTE: I checked activating for all Primitives to be on the safe side, works. It is now (initially) activated for: - GlowPrimitive2D - GraphicPrimitive2D - MetafilePrimitive2D - ScenePrimitive2D - ShadowPrimitive2D (softShadow) - SoftEdgePrimitive2D - SdrCustomShapePrimitive2D - SdrGrafPrimitive2D These are the usual suspects that may use some memory to buffer their decomposition (for good reasons, each repaint uses it). Other Primitives which may show need to be treated this way can easily be added, just by calling setCallbackSeconds(s) in their constructor. This is true for all Primitives derived from the two classes mentioned above. NOTE: Too short buffering times are *not* useful - e.g. for a expensive-to-be-recreated 3D chart representation this may not pay out, so I chose times in a way that try to respect this. NOTE: This change needs 7397fa7cdfc33f5a079df42e4d6cfa59ae9e062d to work correctly (thanks to sberg for this). Without this the office hangs/does not terminate regularly in trying to destroy the 'TimerManager'. Change-Id: Id4802afcb6d12480bb2935cc1ef67fe443b3b788 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/160926 Tested-by: Jenkins Reviewed-by: Armin Le Grand <Armin.Le.Grand@me.com>
2023-12-18 11:23:37 -06:00
maCallbackTimer->setRemainingTime(salhelper::TTimeValue(maCallbackSeconds, 0));
if (!maCallbackTimer->isTicking())
maCallbackTimer->start();
Add flush mechanism to buffered Primitives There are the classes BufferedDecompositionPrimitive2D and BufferedDecompositionGroupPrimitive2D that offer a unified mechanism to preserve/buffer the decomposition of a Primitive, independent of the complexity. This may include e.g. the pixel representation of a 3D Scene, for Charts/CustomShapes and others. Until now these were refreshed when the objects change, or when the buffered decomposition decides that it is necessary, but there was no general mechanism in place to clean these up while the Primitive owning them was alive/used. This is not a big thing in Draw/Impress since this would only be relevant when zooming deep into a SdrPage, so the non-vislible parts would still hold data that would not be needed. But for Calc and Writer this is more relevant: A 3D Chart on the 1st page of a Writer document would be held buffered all the time a user would work on pages below that. This is good for guaranteeing fast re-visualization when scrolling up again, but until then would just block memory. So I added this general mechanism that allows activating flushing timer-based, on Seconds. The default is null seconds, thus deactivated. It should only be used for Primitives that can get expensive, not for all. NOTE: I checked activating for all Primitives to be on the safe side, works. It is now (initially) activated for: - GlowPrimitive2D - GraphicPrimitive2D - MetafilePrimitive2D - ScenePrimitive2D - ShadowPrimitive2D (softShadow) - SoftEdgePrimitive2D - SdrCustomShapePrimitive2D - SdrGrafPrimitive2D These are the usual suspects that may use some memory to buffer their decomposition (for good reasons, each repaint uses it). Other Primitives which may show need to be treated this way can easily be added, just by calling setCallbackSeconds(s) in their constructor. This is true for all Primitives derived from the two classes mentioned above. NOTE: Too short buffering times are *not* useful - e.g. for a expensive-to-be-recreated 3D chart representation this may not pay out, so I chose times in a way that try to respect this. NOTE: This change needs 7397fa7cdfc33f5a079df42e4d6cfa59ae9e062d to work correctly (thanks to sberg for this). Without this the office hangs/does not terminate regularly in trying to destroy the 'TimerManager'. Change-Id: Id4802afcb6d12480bb2935cc1ef67fe443b3b788 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/160926 Tested-by: Jenkins Reviewed-by: Armin Le Grand <Armin.Le.Grand@me.com>
2023-12-18 11:23:37 -06:00
}
}
else if (!rNew.empty())
{
// decomposition defined/set/changed, init & start timer
maCallbackTimer.set(new LocalCallbackTimer(*this));
maCallbackTimer->setRemainingTime(salhelper::TTimeValue(maCallbackSeconds, 0));
maCallbackTimer->start();
}
Add flush mechanism to buffered Primitives There are the classes BufferedDecompositionPrimitive2D and BufferedDecompositionGroupPrimitive2D that offer a unified mechanism to preserve/buffer the decomposition of a Primitive, independent of the complexity. This may include e.g. the pixel representation of a 3D Scene, for Charts/CustomShapes and others. Until now these were refreshed when the objects change, or when the buffered decomposition decides that it is necessary, but there was no general mechanism in place to clean these up while the Primitive owning them was alive/used. This is not a big thing in Draw/Impress since this would only be relevant when zooming deep into a SdrPage, so the non-vislible parts would still hold data that would not be needed. But for Calc and Writer this is more relevant: A 3D Chart on the 1st page of a Writer document would be held buffered all the time a user would work on pages below that. This is good for guaranteeing fast re-visualization when scrolling up again, but until then would just block memory. So I added this general mechanism that allows activating flushing timer-based, on Seconds. The default is null seconds, thus deactivated. It should only be used for Primitives that can get expensive, not for all. NOTE: I checked activating for all Primitives to be on the safe side, works. It is now (initially) activated for: - GlowPrimitive2D - GraphicPrimitive2D - MetafilePrimitive2D - ScenePrimitive2D - ShadowPrimitive2D (softShadow) - SoftEdgePrimitive2D - SdrCustomShapePrimitive2D - SdrGrafPrimitive2D These are the usual suspects that may use some memory to buffer their decomposition (for good reasons, each repaint uses it). Other Primitives which may show need to be treated this way can easily be added, just by calling setCallbackSeconds(s) in their constructor. This is true for all Primitives derived from the two classes mentioned above. NOTE: Too short buffering times are *not* useful - e.g. for a expensive-to-be-recreated 3D chart representation this may not pay out, so I chose times in a way that try to respect this. NOTE: This change needs 7397fa7cdfc33f5a079df42e4d6cfa59ae9e062d to work correctly (thanks to sberg for this). Without this the office hangs/does not terminate regularly in trying to destroy the 'TimerManager'. Change-Id: Id4802afcb6d12480bb2935cc1ef67fe443b3b788 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/160926 Tested-by: Jenkins Reviewed-by: Armin Le Grand <Armin.Le.Grand@me.com>
2023-12-18 11:23:37 -06:00
// tdf#158913 need to secure change when flush/multithreading is in use
std::lock_guard Guard(maCallbackLock);
Add flush mechanism to buffered Primitives There are the classes BufferedDecompositionPrimitive2D and BufferedDecompositionGroupPrimitive2D that offer a unified mechanism to preserve/buffer the decomposition of a Primitive, independent of the complexity. This may include e.g. the pixel representation of a 3D Scene, for Charts/CustomShapes and others. Until now these were refreshed when the objects change, or when the buffered decomposition decides that it is necessary, but there was no general mechanism in place to clean these up while the Primitive owning them was alive/used. This is not a big thing in Draw/Impress since this would only be relevant when zooming deep into a SdrPage, so the non-vislible parts would still hold data that would not be needed. But for Calc and Writer this is more relevant: A 3D Chart on the 1st page of a Writer document would be held buffered all the time a user would work on pages below that. This is good for guaranteeing fast re-visualization when scrolling up again, but until then would just block memory. So I added this general mechanism that allows activating flushing timer-based, on Seconds. The default is null seconds, thus deactivated. It should only be used for Primitives that can get expensive, not for all. NOTE: I checked activating for all Primitives to be on the safe side, works. It is now (initially) activated for: - GlowPrimitive2D - GraphicPrimitive2D - MetafilePrimitive2D - ScenePrimitive2D - ShadowPrimitive2D (softShadow) - SoftEdgePrimitive2D - SdrCustomShapePrimitive2D - SdrGrafPrimitive2D These are the usual suspects that may use some memory to buffer their decomposition (for good reasons, each repaint uses it). Other Primitives which may show need to be treated this way can easily be added, just by calling setCallbackSeconds(s) in their constructor. This is true for all Primitives derived from the two classes mentioned above. NOTE: Too short buffering times are *not* useful - e.g. for a expensive-to-be-recreated 3D chart representation this may not pay out, so I chose times in a way that try to respect this. NOTE: This change needs 7397fa7cdfc33f5a079df42e4d6cfa59ae9e062d to work correctly (thanks to sberg for this). Without this the office hangs/does not terminate regularly in trying to destroy the 'TimerManager'. Change-Id: Id4802afcb6d12480bb2935cc1ef67fe443b3b788 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/160926 Tested-by: Jenkins Reviewed-by: Armin Le Grand <Armin.Le.Grand@me.com>
2023-12-18 11:23:37 -06:00
maBuffered2DDecomposition = std::move(rNew);
}
BufferedDecompositionGroupPrimitive2D::BufferedDecompositionGroupPrimitive2D(
Primitive2DContainer&& aChildren)
: GroupPrimitive2D(std::move(aChildren))
Add flush mechanism to buffered Primitives There are the classes BufferedDecompositionPrimitive2D and BufferedDecompositionGroupPrimitive2D that offer a unified mechanism to preserve/buffer the decomposition of a Primitive, independent of the complexity. This may include e.g. the pixel representation of a 3D Scene, for Charts/CustomShapes and others. Until now these were refreshed when the objects change, or when the buffered decomposition decides that it is necessary, but there was no general mechanism in place to clean these up while the Primitive owning them was alive/used. This is not a big thing in Draw/Impress since this would only be relevant when zooming deep into a SdrPage, so the non-vislible parts would still hold data that would not be needed. But for Calc and Writer this is more relevant: A 3D Chart on the 1st page of a Writer document would be held buffered all the time a user would work on pages below that. This is good for guaranteeing fast re-visualization when scrolling up again, but until then would just block memory. So I added this general mechanism that allows activating flushing timer-based, on Seconds. The default is null seconds, thus deactivated. It should only be used for Primitives that can get expensive, not for all. NOTE: I checked activating for all Primitives to be on the safe side, works. It is now (initially) activated for: - GlowPrimitive2D - GraphicPrimitive2D - MetafilePrimitive2D - ScenePrimitive2D - ShadowPrimitive2D (softShadow) - SoftEdgePrimitive2D - SdrCustomShapePrimitive2D - SdrGrafPrimitive2D These are the usual suspects that may use some memory to buffer their decomposition (for good reasons, each repaint uses it). Other Primitives which may show need to be treated this way can easily be added, just by calling setCallbackSeconds(s) in their constructor. This is true for all Primitives derived from the two classes mentioned above. NOTE: Too short buffering times are *not* useful - e.g. for a expensive-to-be-recreated 3D chart representation this may not pay out, so I chose times in a way that try to respect this. NOTE: This change needs 7397fa7cdfc33f5a079df42e4d6cfa59ae9e062d to work correctly (thanks to sberg for this). Without this the office hangs/does not terminate regularly in trying to destroy the 'TimerManager'. Change-Id: Id4802afcb6d12480bb2935cc1ef67fe443b3b788 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/160926 Tested-by: Jenkins Reviewed-by: Armin Le Grand <Armin.Le.Grand@me.com>
2023-12-18 11:23:37 -06:00
, maCallbackTimer()
, maCallbackLock()
Add flush mechanism to buffered Primitives There are the classes BufferedDecompositionPrimitive2D and BufferedDecompositionGroupPrimitive2D that offer a unified mechanism to preserve/buffer the decomposition of a Primitive, independent of the complexity. This may include e.g. the pixel representation of a 3D Scene, for Charts/CustomShapes and others. Until now these were refreshed when the objects change, or when the buffered decomposition decides that it is necessary, but there was no general mechanism in place to clean these up while the Primitive owning them was alive/used. This is not a big thing in Draw/Impress since this would only be relevant when zooming deep into a SdrPage, so the non-vislible parts would still hold data that would not be needed. But for Calc and Writer this is more relevant: A 3D Chart on the 1st page of a Writer document would be held buffered all the time a user would work on pages below that. This is good for guaranteeing fast re-visualization when scrolling up again, but until then would just block memory. So I added this general mechanism that allows activating flushing timer-based, on Seconds. The default is null seconds, thus deactivated. It should only be used for Primitives that can get expensive, not for all. NOTE: I checked activating for all Primitives to be on the safe side, works. It is now (initially) activated for: - GlowPrimitive2D - GraphicPrimitive2D - MetafilePrimitive2D - ScenePrimitive2D - ShadowPrimitive2D (softShadow) - SoftEdgePrimitive2D - SdrCustomShapePrimitive2D - SdrGrafPrimitive2D These are the usual suspects that may use some memory to buffer their decomposition (for good reasons, each repaint uses it). Other Primitives which may show need to be treated this way can easily be added, just by calling setCallbackSeconds(s) in their constructor. This is true for all Primitives derived from the two classes mentioned above. NOTE: Too short buffering times are *not* useful - e.g. for a expensive-to-be-recreated 3D chart representation this may not pay out, so I chose times in a way that try to respect this. NOTE: This change needs 7397fa7cdfc33f5a079df42e4d6cfa59ae9e062d to work correctly (thanks to sberg for this). Without this the office hangs/does not terminate regularly in trying to destroy the 'TimerManager'. Change-Id: Id4802afcb6d12480bb2935cc1ef67fe443b3b788 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/160926 Tested-by: Jenkins Reviewed-by: Armin Le Grand <Armin.Le.Grand@me.com>
2023-12-18 11:23:37 -06:00
, maCallbackSeconds(0)
{
}
BufferedDecompositionGroupPrimitive2D::~BufferedDecompositionGroupPrimitive2D()
{
if (maCallbackTimer.is())
{
// no more decomposition, end callback
static_cast<LocalCallbackTimer*>(maCallbackTimer.get())->clearCallback();
maCallbackTimer->stop();
}
}
void BufferedDecompositionGroupPrimitive2D::get2DDecomposition(
Primitive2DDecompositionVisitor& rVisitor,
const geometry::ViewInformation2D& rViewInformation) const
{
if (getBuffered2DDecomposition().empty())
{
Primitive2DContainer aNewSequence;
create2DDecomposition(aNewSequence, rViewInformation);
const_cast<BufferedDecompositionGroupPrimitive2D*>(this)->setBuffered2DDecomposition(
std::move(aNewSequence));
}
if (0 == maCallbackSeconds)
{
// no flush/multithreading is in use, just call
rVisitor.visit(getBuffered2DDecomposition());
return;
}
// tdf#158913 need to secure 'visit' when flush/multithreading is in use,
// so that the local non-ref-Counted instance of the decomposition gets not
// manipulated (e.g. deleted)
std::lock_guard Guard(maCallbackLock);
rVisitor.visit(getBuffered2DDecomposition());
}
} // end of namespace drawinglayer::primitive2d
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */