Skip to content

fix: use display-aware resolution for sidebar thumbnails - #439

Draft
GongHeng2017 wants to merge 1 commit into
linuxdeepin:masterfrom
GongHeng2017:fix/bug-173857-thumbnail-blur
Draft

GongHeng2017 wants to merge 1 commit into
linuxdeepin:masterfrom
GongHeng2017:fix/bug-173857-thumbnail-blur

Conversation

@GongHeng2017

@GongHeng2017 GongHeng2017 commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

Root Cause Analysis

The sidebar thumbnail rendering pipeline has a resolution mismatch: PageRenderThread::execNextDocPageThumbnailTask() (PageRenderThread.cpp:817) hardcoded the render resolution at 174×174, while the display side (ThumbnailDelegate::paint()) draws the thumbnail at 174 * pixScale * dpr. When the sidebar is widened (pixScale > 1.0) or on HiDPI displays (dpr > 1.0), Qt upscales the 174px source image, causing visible blur. The root cause is that the pixScale factor — already available on the display side via the adaptScale property — was never propagated to the render side.

Fix Approach

Added a pixScale field to DocPageThumbnailTask (default 1.0 for backward compatibility). Both task creation sites in SideBarImageViewModel now read adaptScale from the parent widget and assign it to the task. The render call in execNextDocPageThumbnailTask() computes the actual render size as 174 * pixScale * dpr, matching the display-side drawing dimensions and eliminating upscaling.

Change Safety Assessment

Code Safety

  • Risk Level: Medium
  • Target code is the product of a prior fix (commit 5e36ac0) that introduced pixScale on the display side but did not propagate it to the render side; this change supplements rather than reverts that fix
  • DocPageThumbnailTask is an internal struct (not public API); the new pixScale field defaults to 1.0, preserving existing behavior when unset

Business Impact Scope

  • Thumbnail rendering — sidebar PDF page thumbnails are affected. Users will see sharper thumbnails when the sidebar is widened or on HiDPI displays. No impact on document rendering, annotation, or other features.
  • Affected callers: SideBarImageViewModel::data() and SideBarImageViewModel::onUpdateImage() (task creation), PageRenderThread::execNextDocPageThumbnailTask() (render execution)

Verification Suggestion

Focus regression testing on thumbnail clarity at various sidebar widths and system zoom levels (100%, 125%, 150%, 200%), plus HiDPI 2x displays. Verify dark-theme thumbnail inversion and XPS document thumbnail performance are unaffected.


根因分析

侧边栏缩略图渲染管线存在分辨率不匹配问题:PageRenderThread::execNextDocPageThumbnailTask()(PageRenderThread.cpp:817)硬编码渲染分辨率为 174×174,而显示侧(ThumbnailDelegate::paint())按 174 * pixScale * dpr 绘制。当侧边栏变宽(pixScale > 1.0)或在 HiDPI 显示器上(dpr > 1.0)时,Qt 将 174px 源图像放大,导致明显模糊。根因是显示侧已通过 adaptScale 属性获取的 pixScale 因子从未传递到渲染侧。

修复方案

在 DocPageThumbnailTask 中新增 pixScale 字段(默认 1.0,保证向后兼容)。SideBarImageViewModel 的两个 task 创建点从父组件的 adaptScale 属性读取并赋值。execNextDocPageThumbnailTask() 中的渲染调用按 174 * pixScale * dpr 计算实际渲染尺寸,与显示侧绘制尺寸匹配,消除放大模糊。

改动安全评估

代码安全评估

  • 风险等级: 中风险
  • 目标代码是历史修复(commit 5e36ac0)的产物,该修复在显示侧引入了 pixScale 缩放但未同步到渲染侧;本次改动补充而非撤销该修复
  • DocPageThumbnailTask 是内部结构体(非公开 API);新增 pixScale 字段默认 1.0,未赋值时行为不变

业务影响范围

  • 缩略图渲染 — 侧边栏 PDF 页面缩略图受影响。用户在侧边栏变宽或 HiDPI 设备上会看到更清晰的缩略图。不影响文档渲染、批注等其他功能。
  • 受影响调用方:SideBarImageViewModel::data() 和 SideBarImageViewModel::onUpdateImage()(task 创建),PageRenderThread::execNextDocPageThumbnailTask()(渲染执行)

验证建议

回归测试重点:不同侧边栏宽度和系统缩放比例(100%、125%、150%、200%)下的缩略图清晰度,以及 HiDPI 2x 显示器上的表现。验证深色主题缩略图反色和 XPS 文档缩略图性能不受影响。

Summary by Sourcery

Match sidebar thumbnail rendering resolution to its display size so thumbnails remain sharp across sidebar widths and HiDPI displays.

Bug Fixes:

  • Render sidebar thumbnails at display-aware resolutions to prevent blur when sidebar scaling or display pixel density increases.

Enhancements:

  • Propagate the sidebar scaling factor through thumbnail tasks while preserving the existing default behavior for callers that do not provide it.

1. Root cause: PageRenderThread hardcoded 174x174 render resolution
   while display side draws at 174*pixScale*dpr, causing Qt upscaling
   blur when sidebar is widened or on HiDPI displays
2. Fix: add pixScale field to DocPageThumbnailTask, set it from
   adaptScale property at both task creation sites, compute render
   size as 174*pixScale*dpr in execNextDocPageThumbnailTask
3. Impact: thumbnails now render at display-matched resolution;
   default pixScale=1.0 and dpr=1.0 preserves existing behavior

Log: Fix blurred sidebar thumbnails in document viewer

Influence:
1. Test thumbnail clarity at default sidebar width (266px)
2. Test thumbnail clarity after widening sidebar (125%-200%)
3. Test thumbnail clarity on HiDPI 2x displays
4. Verify dark-theme thumbnail inversion still works
5. Verify XPS document thumbnail performance unaffected

fix: 修复侧边栏缩略图模糊问题

1. 根因:PageRenderThread 渲染缩略图时硬编码 174x174 分辨率,而显示侧
   按 174*pixScale*dpr 绘制,侧边栏变宽或 HiDPI 设备上 Qt 放大导致模糊
2. 方案:DocPageThumbnailTask 新增 pixScale 字段,两个 task 创建点从
   adaptScale 属性读取赋值,渲染时按 174*pixScale*dpr 计算实际渲染尺寸
3. 影响:缩略图按显示匹配分辨率渲染;pixScale=1.0 且 dpr=1.0 时行为不变

Log: 修复文档查看器侧边栏缩略图模糊问题

Influence:
1. 测试默认侧边栏宽度(266px)下缩略图清晰度
2. 测试拖宽侧边栏后(125%-200%)缩略图清晰度
3. 测试 HiDPI 2x 屏幕下缩略图清晰度
4. 验证深色主题缩略图反色功能不受影响
5. 验证 XPS 文档缩略图性能不受影响

PMS: BUG-173857
@deepin-ci-robot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: GongHeng2017

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 29, 2026

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

Reviewer's Guide

This PR fixes blurry sidebar thumbnails by carrying the UI's adaptScale into DocPageThumbnailTask and using it with the device pixel ratio to size both thumbnail rendering and associated image rectangles, while retaining 1.0-scale backward-compatible behavior.

Sequence diagram for display-aware sidebar thumbnail rendering

sequenceDiagram
    participant UI as SideBarImageViewModel
    participant Queue as PageRenderThread
    participant Renderer as DocumentRenderer
    participant View as ThumbnailDelegate

    UI->>UI: property(adaptScale)
    UI->>Queue: appendTask(DocPageThumbnailTask.pixScale)
    Queue->>Queue: execNextDocPageThumbnailTask()
    Queue->>Queue: compute renderSize = 174 * pixScale * devicePixelRatio()
    Queue->>Renderer: getImage(index, renderSize, renderSize)
    Queue->>Renderer: getImageObjectRects(index, renderSize, renderSize)
    Renderer-->>Queue: image and imageRects
    Queue-->>View: sigDocPageThumbnailTaskFinished()
    View->>View: paint at 174 * pixScale * dpr
Loading

File-Level Changes

Change Details Files
Propagate the sidebar display scale into thumbnail rendering so generated images match their on-screen pixel dimensions.
  • Added a defaulted pixScale field to thumbnail tasks.
  • Captured adaptScale when tasks are created in both model paths.
  • Computed render and image-object-rectangle sizes as 174 * pixScale * devicePixelRatio().
  • Kept thumbnail and dark-theme image overlays at identical dimensions.
reader/browser/PageRenderThread.h
reader/browser/PageRenderThread.cpp
reader/sidebar/SideBarImageViewModel.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

@GongHeng2017
GongHeng2017 marked this pull request as draft October 29, 2026 20:42

@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 ✨

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