refactor: 优化dde-dock内存

1. PreviewContainer改为非静态对象,并使用后进行销毁
2. AppSnapshot调整获取截图逻辑,优先使用kwin的接口,如无法获取再使用共享内存或X的方式

Log: 优化了dde-dock的内存
Influence: 优化内存,无功能性影响
Task: https://pms.uniontech.com/zentao/task-view-92574.html
Change-Id: I709a28d40214df97596ed52c1863018b271979bb
This commit is contained in:
guoyao 2021-11-25 01:55:52 -04:00
parent 2edbfc41c8
commit 266c311a45
5 changed files with 13 additions and 47 deletions

View File

@ -24,7 +24,6 @@
#include "themeappicon.h"
#include "xcb_misc.h"
#include "appswingeffectbuilder.h"
#include "appspreviewprovider.h"
#include "utils.h"
#include <X11/X.h>
@ -333,7 +332,7 @@ void AppItem::mouseReleaseEvent(QMouseEvent *e)
m_itemEntryInter->Activate(QX11Info::getTimestamp());
// play launch effect
if (m_windowInfos.isEmpty() && DGuiApplicationHelper::isSpecialEffectsEnvironment())
if (m_windowInfos.isEmpty() && DGuiApplicationHelper::isSpecialEffectsEnvironment())
playSwingEffect();
}
}
@ -640,7 +639,10 @@ void AppItem::onRefreshIcon()
void AppItem::onResetPreview()
{
m_appPreviewTips = nullptr;
if (m_appPreviewTips != nullptr) {
m_appPreviewTips->deleteLater();
m_appPreviewTips = nullptr;
}
}
void AppItem::activeChanged()
@ -653,7 +655,11 @@ void AppItem::showPreview()
if (m_windowInfos.isEmpty())
return;
m_appPreviewTips = PreviewWindow(m_windowInfos, m_itemEntryInter->GetAllowedCloseWindows().value(), DockPosition);
m_appPreviewTips = new PreviewContainer;
m_appPreviewTips->setWindowInfos(m_windowInfos, m_itemEntryInter->GetAllowedCloseWindows().value());
m_appPreviewTips->updateSnapshots();
m_appPreviewTips->updateLayoutDirection(DockPosition);
connect(m_appPreviewTips, &PreviewContainer::requestActivateWindow, this, &AppItem::requestActivateWindow, Qt::QueuedConnection);
connect(m_appPreviewTips, &PreviewContainer::requestPreviewWindow, this, &AppItem::requestPreviewWindow, Qt::QueuedConnection);

View File

@ -206,8 +206,8 @@ void AppSnapshot::fetchSnapshot()
uchar *image_data = nullptr;
XImage *ximage = nullptr;
// wayland环境下使用KWin提供的接口
if (isKWinAvailable() && Utils::IS_WAYLAND_DISPLAY) {
// 优先使用窗管进行窗口截图
if (isKWinAvailable()) {
QDBusInterface interface(QStringLiteral("org.kde.KWin"), QStringLiteral("/Screenshot"), QStringLiteral("org.kde.kwin.Screenshot"));
qDebug() << "windowsID:"<< m_wid;
@ -244,6 +244,7 @@ void AppSnapshot::fetchSnapshot()
// get window image from XGetImage(a little slow)
qDebug() << "get Image from dxcbplugin SHM failed!";
qDebug() << "get Image from Xlib...";
// guoyao note这里会造成内存泄漏而且是通过demo在X环境经过验证改用xcb库同样会有内存泄漏这里暂时未找到解决方案所以优先使用kwin提供的接口
ximage = getImageXlib();
if (!ximage) {
qDebug() << "get Image from Xlib failed! giving up...";
@ -342,13 +343,6 @@ void AppSnapshot::paintEvent(QPaintEvent *e)
painter.drawRoundedRect(m_snapshotSrcRect, radius * ratio, radius * ratio);
}
void AppSnapshot::resizeEvent(QResizeEvent *e)
{
QWidget::resizeEvent(e);
QTimer::singleShot(1, this, &AppSnapshot::fetchSnapshot);
}
void AppSnapshot::mousePressEvent(QMouseEvent *e)
{
QWidget::mousePressEvent(e);

View File

@ -96,7 +96,6 @@ private:
void enterEvent(QEvent *e) override;
void leaveEvent(QEvent *e) override;
void paintEvent(QPaintEvent *e) override;
void resizeEvent(QResizeEvent *e) override;
void mousePressEvent(QMouseEvent *e) override;
bool eventFilter(QObject *watched, QEvent *e) override;
SHMInfo *getImageDSHM();

View File

@ -1,22 +0,0 @@
#ifndef APPSPREVIEWPROVIDER_H
#define APPSPREVIEWPROVIDER_H
#include "previewcontainer.h"
static PreviewContainer *PreviewWindow(const WindowInfoMap &infos, const WindowList &allowClose, const Dock::Position dockPos)
{
static PreviewContainer *preview;
if (!preview) {
preview = new PreviewContainer;
}
preview->disconnect();
preview->setWindowInfos(infos, allowClose);
preview->updateSnapshots();
preview->updateLayoutDirection(dockPos);
return preview;
}
#endif /* APPSPREVIEWPROVIDER_H */

View File

@ -26,7 +26,6 @@
#include <gtest/gtest.h>
#include "previewcontainer.h"
#include "appspreviewprovider.h"
class Test_PreviewContainer : public ::testing::Test
{};
@ -150,13 +149,3 @@ TEST_F(Test_PreviewContainer, event_test)
data->deleteLater();
ASSERT_TRUE(true);
}
TEST_F(Test_PreviewContainer, PreviewWindow)
{
WindowList list;
PreviewContainer *preview = PreviewWindow(WindowInfoMap(), list, Dock::Position::Top);
ASSERT_TRUE(preview);
delete preview;
}