Skip to content

fix: replace QIcon(svg) with DDciIcon for icon aliasing under Wayland fractional scaling - #100

Open
tianming-1996 wants to merge 1 commit into
linuxdeepin:release/eaglefrom
tianming-1996:fix/icon-aliasing-193447
Open

tianming-1996 wants to merge 1 commit into
linuxdeepin:release/eaglefrom
tianming-1996:fix/icon-aliasing-193447

Conversation

@tianming-1996

@tianming-1996 tianming-1996 commented Oct 27, 2026 •

Copy link
Copy Markdown

Root Cause Analysis

The OCR app window titlebar icon is set via QIcon(svg) (src/mainwidget.cpp:692,695,746,749). The DStyle::PE_Icon SI_QIcon rendering path calls icon.paint(p, rect) without passing devicePixelRatioF(). Under Wayland fractional scaling (1.5x), devicePixelRatio() returns integer 1, so the 32×32 SVG renders at only 32×32 physical pixels and gets upscaled to 48×48, causing severe aliasing.

Key evidence: dtkwidget dstyle.cpp:1257-1271 (SI_QIcon path, no DPR) vs :1273-1285 (SI_DciIcon path, passes devicePixelRatioF()); KB _shared/spec/technical-facts/qt-wayland-fractional-dpr.md confirms Wayland fractional DPR returns integer.

Fix Approach

Replace QIcon(svg) with DDciIcon/DCI format. Created appicon.dci with dark/light themes at 3x scale (96×96 physical pixels for 32px logical icon). Use DDciIcon::pixmap(App->devicePixelRatioF(), 32, theme) to pre-render at correct DPR, then wrap the resulting QPixmap in QIcon for setWindowIcon() and titlebar()->setIcon(). This follows the existing icon_tips.dci pattern already used in the same file.

Change Safety Assessment

Code Safety

  • Risk Level: Low
  • Target lines are from baseline sync commit (c12efa8), not a historical bug fix — this change does not revert any existing fix
  • 4 callers of setIcons() use the same function signature unchanged; no caller behavior affected

Business Impact Scope

Affected module: window titlebar icon display (dark/light themes). User scenarios: viewing the OCR app titlebar icon at different scaling factors (especially 1.5x on Wayland), and switching between dark/light themes.

Verification Suggestion

Focus on verifying the titlebar icon is sharp at Wayland 1.5x scaling. Regression test: 1x/2x scaling, dark/light theme switching, icon display on window open and image open.


根因分析

OCR 应用窗口标题栏图标通过 QIcon(svg) 设置(src/mainwidget.cpp:692,695,746,749)。DStyle::PE_Icon 的 SI_QIcon 渲染路径调用 icon.paint(p, rect) 时未传 devicePixelRatioF()。Wayland 分数缩放(1.5x)下 devicePixelRatio() 返回整数 1,32×32 SVG 仅按 32×32 物理像素渲染后被放大到 48×48,导致严重锯齿。

关键证据:dtkwidget dstyle.cpp:1257-1271(SI_QIcon 无 DPR)vs :1273-1285(SI_DciIcon 有 devicePixelRatioF());KB _shared/spec/technical-facts/qt-wayland-fractional-dpr.md 确认 Wayland 分数 DPR 返回整数。

修复方案

将 QIcon(svg) 替换为 DDciIcon/DCI 格式。创建 appicon.dci(含深色/浅色主题,3 倍缩放 = 96×96 物理像素),使用 DDciIcon::pixmap(App->devicePixelRatioF(), 32, theme) 按正确 DPR 渲染后包装为 QIcon。与同文件已有的 icon_tips.dci 用法一致。

改动安全评估

代码安全评估

  • 风险等级: 低风险
  • 目标行来自基线同步提交(c12efa8),非历史修复产物,本次改动不撤销任何已有修复
  • setIcons() 的 4 个调用方使用相同函数签名,不受影响

业务影响范围

受影响模块:窗口标题栏图标显示(深色/浅色主题)。用户场景:不同缩放比例(特别是 Wayland 1.5x)下查看 OCR 应用标题栏图标,以及深色/浅色主题切换。

验证建议

重点验证 Wayland 1.5x 缩放下标题栏图标无锯齿。回归验证:1x/2x 缩放、深色/浅色主题切换、窗口打开和图片打开时图标显示。

Summary by Sourcery

Render the application titlebar icons through device-pixel-ratio-aware DCI assets to keep them sharp across display scaling modes.

Bug Fixes:

  • Fix aliasing of the application and titlebar icons under Wayland fractional scaling by rendering them at the correct device pixel ratio.

Enhancements:

  • Use themed DCI app icons for consistent dark and light titlebar icon display.

Build:

  • Update resource packaging to include the new application DCI icon asset.

@deepin-ci-robot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: tianming-1996

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@sourcery-ai

sourcery-ai Bot commented Oct 27, 2026

Copy link
Copy Markdown
Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

The PR fixes blurry titlebar icons under Wayland fractional scaling by replacing direct SVG loading with a themed DDciIcon asset rendered at the application’s fractional device-pixel ratio, while preserving dark/light theme handling and existing callers.

Sequence diagram for fractional-DPR titlebar icon rendering

sequenceDiagram
    participant MainWidget
    participant DDciIcon
    participant App
    participant Titlebar

    MainWidget->>DDciIcon: pixmap(App->devicePixelRatioF(), 32, theme)
    DDciIcon-->>MainWidget: themed high-resolution QPixmap
    MainWidget->>App: setWindowIcon(QIcon(pixmap))
    MainWidget->>Titlebar: setIcon(QIcon(pixmap))
Loading

File-Level Changes

Change Details Files
Replace SVG-based application and titlebar icons with DPR-aware DCI rendering to prevent fractional-scaling aliasing.
  • Add a themed, high-resolution DCI asset containing dark and light variants.
  • Render the DCI at App->devicePixelRatioF() and 32 logical pixels before wrapping it in QIcon.
  • Apply the rendered icon to both the application window icon and the main window titlebar.
  • Register the new asset in the Qt resource file.
assets/appicon.dci
resource.qrc
src/mainwidget.cpp

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@github-actions

Copy link
Copy Markdown

CLA Assistant Lite bot:

如果你是以企业贡献者的身份进行提交,请联系我们签署企业贡献者许可协议
If you submit as corporate contributor, please contact us to sign our Corporate Contributor License Agreement

感谢您的提交,我们非常感谢。 像许多开源项目一样,在接受您的贡献之前,我们要求您签署我们的个人贡献者许可协议。 您只需发布与以下格式相同的评论即可签署个人贡献者许可协议。
Thank you for your submission, we really appreciate it. Like many open-source projects, we ask that you sign our Individual Contributor License Agreement before we can accept your contribution. You can sign the Individual Contributor License Agreement by just posting a Pull Request Comment same as the below format.


I have read the CLA Document and I hereby sign the CLA.

deepin seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.
You can retrigger this bot by commenting recheck in this Pull Request

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've reviewed your changes and they look great!


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

… fractional scaling

1. Root cause: QIcon(svg) renders via DStyle SI_QIcon path which
   does not pass devicePixelRatioF(), 32x32 physical pixels
   upscaled to 48x48 under Wayland fractional scaling
2. Fix: create appicon.dci (DCI format) with dark/light themes at
   3x scale, use DDciIcon::pixmap() to render at correct DPR
   before wrapping in QIcon for setWindowIcon/titlebar setIcon
3. Cleanup: update SPDX copyright year to 2022-2026, remove unused
   appicon_dark.svg and appicon_light.svg from resource.qrc
4. Impact: titlebar icon renders at correct physical pixel size
   under Wayland fractional scaling, no aliasing

Log: fix OCR app icon aliasing under Wayland fractional scaling

Influence:
1. Test icon display at 1x/1.25x/1.5x/2x scaling on Wayland
2. Verify icon in both dark and light themes
3. Check icon when switching theme at runtime

fix: 修复Wayland分数缩放下OCR标题栏图标锯齿问题

1. 根因:QIcon(svg)经DStyle的SI_QIcon路径渲染,未传递
   devicePixelRatioF(),32x32物理像素被放大到48x48产生锯齿
2. 方案:创建appicon.dci(DCI格式,含深色/浅色主题,3倍缩放),
   使用DDciIcon::pixmap()按正确DPR渲染后包装为QIcon
3. 清理:更新SPDX版权年份至2022-2026,移除resource.qrc中
   已无引用的appicon_dark.svg和appicon_light.svg
4. 影响:标题栏图标在Wayland分数缩放下按正确物理像素渲染,
   消除锯齿

Log: 修复OCR识别图标在Wayland分数缩放下锯齿严重的问题

Influence:
1. 测试Wayland下1x/1.25x/1.5x/2x缩放的图标显示
2. 验证深色和浅色主题下的图标
3. 检查运行时切换主题时的图标显示

PMS: BUG-193447
@tianming-1996
tianming-1996 force-pushed the fix/icon-aliasing-193447 branch from b42c8d1 to 9539bba Compare October 28, 2026 00:17
@deepin-ci-robot

Copy link
Copy Markdown

deepin pr auto review

🤖 AI 代码审查报告

总体评分: 97 分 (通过阈值: 70分)

Pass


📊 总体评价

项目 结果
审查结论 代码审查通过
评分详情 本次提交将 QIcon(svg) 替换为 DDciIcon 以修复 Wayland 分数缩放下的图标锯齿问题, 变更范围小且聚焦,语法逻辑正确,无安全漏洞。代码质量方面存在轻微的重复代码 (DDciIcon 对象在 Dark/Light 分支中重复创建),性能方面存在可优化的重复 pixmap 生成, 但均不影响功能正确性。综合评分 97 分,审查通过。

🔍 详细分析

1. 语法逻辑 ✅

评价: 语法正确,逻辑清晰 ✅ 通过

潜在问题:
✅ 未发现明显问题

建议: ['无需修改,语法逻辑完全正确。']


2. 代码质量 ✅

评价: 代码结构清晰,存在轻微重复代码 ✅ 通过

潜在问题:
✅ 未发现明显问题

建议: ['可将 DDciIcon 对象的创建提升到 if/else 分支之前,避免重复创建;或在分支内仅确定主题参数后统一调用,减少重复代码。例如:先创建 DDciIcon appDci,再根据 themeType 选择 DDciIcon::Theme,最后统一生成 pixmap。']


3. 代码性能 ✅

评价: 性能良好,存在轻微优化空间 ✅ 通过

潜在问题:
✅ 未发现明显问题

建议: ['在每个分支内将 pixmap 结果保存到局部变量,复用于 setWindowIcon 和 titlebar->setIcon,避免重复生成。例如:QPixmap iconPixmap = appDci.pixmap(App->devicePixelRatioF(), 32, DDciIcon::Theme::Dark); App->setWindowIcon(QIcon(iconPixmap)); ... mainWindow->titlebar()->setIcon(QIcon(iconPixmap));']


4. 代码安全 🔒

评价: 存在0个安全漏洞 ✅ 通过

🔐 发现 0 个安全漏洞

安全漏洞详情:
✅ 未发现安全漏洞

建议: ['无安全风险,无需额外安全加固。']


💡 改进建议代码示例

// 优化示例:减少重复代码和重复 pixmap 生成
void MainWidget::setIcons(DGuiApplicationHelper::ColorType themeType)
{
    // ... 前置代码不变 ...

    DDciIcon appDci(QStringLiteral(":/assets/appicon.dci"));
    DDciIcon::Theme dciTheme = (themeType == DGuiApplicationHelper::DarkType)
                               ? DDciIcon::Theme::Dark
                               : DDciIcon::Theme::Light;
    QPixmap iconPixmap = appDci.pixmap(App->devicePixelRatioF(), 32, dciTheme);

    App->setWindowIcon(QIcon(iconPixmap));
    DMainWindow *mainWindow = static_cast<DMainWindow *>(this->parent());
    if (mainWindow) {
        mainWindow->titlebar()->setIcon(QIcon(iconPixmap));
    }

    // ... 后续代码不变 ...
}

本报告由 AI 代码审查工具自动生成

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants