fix: Add DConfig for preview with no delay.#455
fix: Add DConfig for preview with no delay.#455deepin-bot[bot] merged 1 commit intolinuxdeepin:release/eaglefrom
Conversation
There was a problem hiding this comment.
Sorry @lichaofan2008, you have reached your weekly rate limit of 500000 diff characters.
Please try again later or upgrade to continue using Sourcery
Add DConfig for preview with no delay. DConfig中增加关于预览无延迟的配置。 Bug: https://pms.uniontech.com/bug-view-351345.html
a0490df to
afa00f9
Compare
deepin pr auto review这段代码主要实现了一个通过配置项( 以下是对该代码的审查意见,涵盖语法逻辑、代码质量、性能和安全方面: 1. 语法与逻辑审查
2. 代码质量审查
3. 性能审查
4. 安全审查
改进建议代码1. datamanager.h (改进线程安全和 const 修饰) #include <atomic>
class DataManager: public QObject
{
// ... 其他代码 ...
public:
/**
* @brief 获取是否预览无延迟
* @return
*/
bool isPreviewNoDelay() const { return m_isPreviewNoDelay; }; // 添加 const
/**
* @brief 设置是否预览无延迟
* @param noDelay 改名以更清晰
*/
void setPreviewNoDelay(bool noDelay) { m_isPreviewNoDelay = noDelay; };
private:
// 使用 atomic 保证线程安全
std::atomic<bool> m_isPreviewNoDelay {false};
};2. majorimageprocessingthread.cpp (优化逻辑) void MajorImageProcessingThread::run()
{
// ... 前置代码 ...
while (!isInterruptionRequested()) {
// ... 处理图像逻辑 ...
// 改进:如果开启无延迟模式,可以设置一个更小的休眠时间(例如 10ms,约 100 FPS)
// 或者根据分辨率动态调整,而不是完全不休眠,防止 CPU 空转
if (!DataManager::instance()->isPreviewNoDelay()) {
if (m_nVdWidth <= 1920) {
msleep(33); // 普通模式限制 ~30FPS
}
} else {
// 无延迟模式下,给极其微小的让出时间片机会,防止完全饿死其他同级线程
// 或者根据实际硬件能力,例如限制在 60FPS (16ms)
if (m_nVdWidth > 1920) {
// 高分辨率下即使无延迟,也适当限制一下保护系统
msleep(10);
}
// 低分辨率下完全不休眠,追求极速
}
}
}3. main.cpp (增加日志) if (dconfig && dconfig->isValid()) {
// 读取配置,如果 key 不存在,value() 通常返回 QVariant()
// 如果 JSON 中定义了默认值 false,这里也会读到 false
bool noDelay = dconfig->value("previewNoDelay", false).toBool();
DataManager::instance()->setPreviewNoDelay(noDelay);
// 可选:打印日志,方便调试
qDebug() << "Preview No Delay mode set to:" << noDelay;
}总结这段代码实现了基本功能,但在多线程安全性上存在隐患(非原子变量读写),在性能控制上较为激进(完全移除休眠可能导致 CPU 负载过高)。建议使用 |
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: lichaofan2008, max-lvs The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
|
/forcemerge |
|
This pr force merged! (status: unstable) |
452f400
into
linuxdeepin:release/eagle
Add DConfig for preview with no delay.
DConfig中增加关于预览无延迟的配置。
Bug: https://pms.uniontech.com/bug-view-351345.html