添加单向渲染逻辑和内存强制回收措施

dev-wuyize
karlis 2023-03-23 16:17:01 +08:00
parent aa9743d4e7
commit 5d5ea2307f
6 changed files with 22 additions and 9 deletions

View File

@ -212,7 +212,7 @@
<ClInclude Include="src\Editor\LayerWrapper.h" />
<ClInclude Include="src\Editor\util\EncodeUtil.hpp" />
<ClInclude Include="src\Editor\util\JsonUtil.hpp" />
<ClInclude Include="src\Editor\ElementManager.h" />
<QtMoc Include="src\Editor\ElementManager.h" />
<QtMoc Include="src\Editor\ElementPoolWidget.h" />
<ClInclude Include="src\Editor\GraphicElement.h" />
<ClInclude Include="src\Editor\LayerManager.h" />

View File

@ -329,6 +329,9 @@
<QtMoc Include="src\Editor\EditorWidgetComponent\LayerContainerListWidget.h">
<Filter>Header Files</Filter>
</QtMoc>
<QtMoc Include="src\Editor\ElementManager.h">
<Filter>Header Files\Editor\Element</Filter>
</QtMoc>
</ItemGroup>
<ItemGroup>
<None Include="..\data.json" />
@ -519,9 +522,6 @@
<ClInclude Include="src\Editor\util\EncodeUtil.hpp">
<Filter>Header Files\Editor\util</Filter>
</ClInclude>
<ClInclude Include="src\Editor\ElementManager.h">
<Filter>Header Files\Editor\Element</Filter>
</ClInclude>
<ClInclude Include="src\Editor\GraphicElement.h">
<Filter>Header Files\Editor\Element</Filter>
</ClInclude>

View File

@ -18,6 +18,14 @@ ElementManager::ElementManager(QJsonObject source, QString fileHome)
}
for (auto element : elements)
element->index = index++;
timer = new QTimer();
timer->setInterval(30000);
connect(timer, &QTimer::timeout, this, [this]() {
for (auto element : elements)
if (typeid(*element) == typeid(SimpleElement))
((SimpleElement*)element)->forceRefresh = true;
});
timer->start();
}
void ElementManager::addElement(GraphicElement *element)

View File

@ -4,17 +4,20 @@
#include <QJsonArray>
#include "../Renderer/Preview/ElementRenderer.h"
#include <vector>
#include <QTimer>
using std::vector;
class LayerManager;
class GraphicElement;
class Renderer::ElementRenderer;
class FolderLayerWrapper;
class ElementManager
class ElementManager : public QObject
{
Q_OBJECT
public:
vector<GraphicElement *> elements;
QString fileHome;
QTimer* timer;
public:
ElementManager(QJsonObject source, QString fileHome);

View File

@ -112,12 +112,12 @@ void SimpleElement::paint(QPainter* painter, QTransform transform, const LayerSt
maxScale = std::max(fabs(transform.m11() / cos(angle)), fabs(transform.m22() / cos(angle)));
else
maxScale = std::max(fabs(transform.m12() / sin(angle)), fabs(transform.m21() / sin(angle)));
//double pixelRatio = maxScale * QGuiApplication::primaryScreen()->devicePixelRatio();
double pixelRatio = 5;
if (painterPath == painterPathPrev && styles.getHash() == stylesHashValue && fabs(pixelRatio - pixelRatioPrev) < 1e-3)
double pixelRatio = maxScale * QGuiApplication::primaryScreen()->devicePixelRatio();
//double pixelRatio = 5;
if (painterPath == painterPathPrev && styles.getHash() == stylesHashValue && pixelRatioPrev >= pixelRatio && !forceRefresh)
{
transform.translate(movPrev.x(), movPrev.y());
painter->setTransform(transform.scale(1 / pixelRatio, 1 / pixelRatio));
painter->setTransform(transform.scale(1 / pixelRatioPrev, 1 / pixelRatioPrev));
painter->drawImage(0, 0, imagePrev);
}
else
@ -131,6 +131,7 @@ void SimpleElement::paint(QPainter* painter, QTransform transform, const LayerSt
imagePrev = img;
movPrev = mov;
pixelRatioPrev = pixelRatio;
forceRefresh = false;
}
}

View File

@ -61,6 +61,7 @@ public:
void paint(QPainter* painter, QTransform transform, const LayerStyleContainer& styles) override;
bool isClosed() const override;
void paintPreview(QPainter* painter) override;
bool forceRefresh = false;
};
class GroupElement : public GraphicElement