mirror of
https://github.com/linuxdeepin/dde-dock.git
synced 2025-06-03 00:15:21 +00:00
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:
parent
2edbfc41c8
commit
266c311a45
@ -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);
|
||||
|
@ -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);
|
||||
|
@ -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();
|
||||
|
@ -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 */
|
@ -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;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user