Skip to content

Commit

Permalink
fix: mask area exist two line for viewport
Browse files Browse the repository at this point in the history
mask's point maybe is extend if radius is float when scaling.
it causes mask's aplha is zero in top2bottom and right2left line.

Issue: linuxdeepin/developer-center#8313
  • Loading branch information
18202781743 committed Apr 28, 2024
1 parent 399ba96 commit b8a9035
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
10 changes: 5 additions & 5 deletions src/private/dquickitemviewport_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,14 @@ class Q_DECL_HIDDEN MaskTextureCache {
}

// 根据圆角大小获取一个蒙版材质,此材质将用于片段着色器中实现圆角效果
TextureData getTexture(QSGRenderContext *context, float radius, bool antialiasing)
TextureData getTexture(QSGRenderContext *context, int radius, bool antialiasing)
{
// 排除无效的数据
if (qIsNull(radius))
if (radius <= 0)
return TextureData();

// 用于获取材质缓存key的key
qint8 to_cache_key_key = ((antialiasing << 7) | qRound(radius));
qint8 to_cache_key_key = ((antialiasing << 7) | radius);
Texture *texture = nullptr;

if (m_radiusToCacheKey.contains(to_cache_key_key)) {
Expand All @@ -59,7 +59,7 @@ class Q_DECL_HIDDEN MaskTextureCache {

if (!texture) {
// 在边缘额外加一个像素,用于 ClampToEdge 时不会取到边缘的透明像素点
QImage mask(QSize(qRound(radius) + 1, qRound(radius) + 1), QImage::Format_ARGB32);
QImage mask(QSize(radius + 1, radius + 1), QImage::Format_ARGB32);
mask.fill(Qt::transparent);
// 必须填充为白色,在着色器中运算时会使用rgb三个通道相乘
const QColor maskColor = Qt::white;
Expand Down Expand Up @@ -220,7 +220,7 @@ class Q_DECL_HIDDEN DQuickItemViewportPrivate : public DCORE_NAMESPACE::DObjectP
if (Q_UNLIKELY(dirtyState.testFlag(DirtyMaskTexture) || !maskTexture)) {
QQuickItemPrivate *d = QQuickItemPrivate::get(q_func());
maskTexture = MaskTextureCache::instance()->getTexture(d->sceneGraphRenderContext(),
static_cast<float>(radius * d->window->effectiveDevicePixelRatio()),
qRound(radius * d->window->effectiveDevicePixelRatio()),
true);

markDirty(DirtyMaskTexture, false);
Expand Down
2 changes: 1 addition & 1 deletion src/private/dquickrectangle_p_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class Q_DECL_HIDDEN DQuickRectanglePrivate : public QQuickItemPrivate
if (!maskTexture && radius > 0) {
QQuickItemPrivate *d = QQuickItemPrivate::get(q_func());
maskTexture = MaskTextureCache::instance()->getTexture(d->sceneGraphRenderContext(),
radius * d->window->effectiveDevicePixelRatio(), true);
qRound(radius * d->window->effectiveDevicePixelRatio()), true);
}
return maskTexture->texture;
}
Expand Down

0 comments on commit b8a9035

Please sign in to comment.