[plasma/kwin] src: Drop snapToPixelGrid

Vlad Zahorodnii <[email protected]>
Newsgroups gmane.comp.kde.cvs
Message-ID <[email protected]>
Git commit 37d35f6eff18c816942c39c16732962a65855f1e by Vlad Zahorodnii.
Committed on 22/07/2026 at 06:51.
Pushed by vladz into branch 'master'.

Drop snapToPixelGrid

We have RectF::rounded() instead now and for QPointF, toPoint() is good
enough.

M  +0    -22   src/core/pixelgrid.h
M  +2    -2    src/core/renderviewport.cpp
M  +1    -1    src/scene/item.cpp
M  +4    -4    src/scene/surfaceitem.cpp
M  +2    -2    src/scene/workspacescene.cpp

https://invent.kde.org/plasma/kwin/-/commit/37d35f6eff18c816942c39c16732962a65855f1e

diff --git a/src/core/pixelgrid.h b/src/core/pixelgrid.h
index 26824c719e5..cb664240332 100644
--- a/src/core/pixelgrid.h
+++ b/src/core/pixelgrid.h
@@ -14,28 +14,6 @@
 namespace KWin
 {
 
-KWIN_EXPORT inline QPoint snapToPixelGrid(const QPointF &point)
-{
-    return QPoint(std::round(point.x()), std::round(point.y()));
-}
-
-KWIN_EXPORT inline QPointF snapToPixelGridF(const QPointF &point)
-{
-    return QPointF(std::round(point.x()), std::round(point.y()));
-}
-
-KWIN_EXPORT inline QRect snapToPixelGrid(const QRectF &rect)
-{
-    const QPoint topLeft = snapToPixelGrid(rect.topLeft());
-    const QPoint bottomRight = snapToPixelGrid(rect.bottomRight());
-    return QRect(topLeft.x(), topLeft.y(), bottomRight.x() - topLeft.x(), bottomRight.y() - topLeft.y());
-}
-
-KWIN_EXPORT inline QRectF snapToPixelGridF(const QRectF &rect)
-{
-    return QRectF(snapToPixelGridF(rect.topLeft()), snapToPixelGridF(rect.bottomRight()));
-}
-
 KWIN_EXPORT constexpr double snapToPixels(double logicalValue, double scale)
 {
     return std::round(logicalValue * scale) / scale;
diff --git a/src/core/renderviewport.cpp b/src/core/renderviewport.cpp
index 291fea55cd1..64e9fc2ce69 100644
--- a/src/core/renderviewport.cpp
+++ b/src/core/renderviewport.cpp
@@ -156,7 +156,7 @@ Rect RenderViewport::mapToRenderTarget(const Rect &logicalGeometry) const
 
 QPoint RenderViewport::mapToRenderTarget(const QPoint &logicalGeometry) const
 {
-    const QPoint devicePoint = snapToPixelGrid(QPointF(logicalGeometry) * m_scale) - m_scaledRenderRect.topLeft() + m_renderOffset;
+    const QPoint devicePoint = logicalGeometry * m_scale - m_scaledRenderRect.topLeft() + m_renderOffset;
     return m_transform.map(devicePoint, m_transformBounds);
 }
 
@@ -192,7 +192,7 @@ Rect RenderViewport::mapToRenderTargetTexture(const Rect &logicalGeometry) const
 
 QPoint RenderViewport::mapToRenderTargetTexture(const QPoint &logicalGeometry) const
 {
-    return snapToPixelGrid(QPointF(logicalGeometry) * m_scale) - m_scaledRenderRect.topLeft() + m_renderOffset;
+    return logicalGeometry * m_scale - m_scaledRenderRect.topLeft() + m_renderOffset;
 }
 
 QPointF RenderViewport::mapToRenderTargetTexture(const QPointF &logicalGeometry) const
diff --git a/src/scene/item.cpp b/src/scene/item.cpp
index 73221d97dcf..53c1df68369 100644
--- a/src/scene/item.cpp
+++ b/src/scene/item.cpp
@@ -357,7 +357,7 @@ Rect Item::paintedDeviceArea(RenderView *view, const RectF &rect) const
                           .mapRect(snapped);
         }
 
-        snapped.translate(snapToPixelGridF(item->position() * scale));
+        snapped.translate((item->position() * scale).toPoint());
     }
     return view->mapToDeviceCoordinatesAligned(snapped.scaled(1.0 / scale)) & view->deviceRect();
 }
diff --git a/src/scene/surfaceitem.cpp b/src/scene/surfaceitem.cpp
index 77005ad4ac9..ce3458a03ac 100644
--- a/src/scene/surfaceitem.cpp
+++ b/src/scene/surfaceitem.cpp
@@ -207,10 +207,10 @@ WindowQuadList SurfaceItem::buildQuads() const
     for (const RectF &rect : region.rects()) {
         WindowQuad quad;
 
-        const QPointF bufferTopLeft = snapToPixelGridF(m_bufferSourceBox.topLeft() + m_surfaceToBufferTransform.map(QPointF(rect.left() * xScale, rect.top() * yScale), sourceBox.size()));
-        const QPointF bufferTopRight = snapToPixelGridF(m_bufferSourceBox.topLeft() + m_surfaceToBufferTransform.map(QPointF(rect.right() * xScale, rect.top() * yScale), sourceBox.size()));
-        const QPointF bufferBottomRight = snapToPixelGridF(m_bufferSourceBox.topLeft() + m_surfaceToBufferTransform.map(QPointF(rect.right() * xScale, rect.bottom() * yScale), sourceBox.size()));
-        const QPointF bufferBottomLeft = snapToPixelGridF(m_bufferSourceBox.topLeft() + m_surfaceToBufferTransform.map(QPointF(rect.left() * xScale, rect.bottom() * yScale), sourceBox.size()));
+        const QPointF bufferTopLeft = (m_bufferSourceBox.topLeft() + m_surfaceToBufferTransform.map(QPointF(rect.left() * xScale, rect.top() * yScale), sourceBox.size())).toPoint();
+        const QPointF bufferTopRight = (m_bufferSourceBox.topLeft() + m_surfaceToBufferTransform.map(QPointF(rect.right() * xScale, rect.top() * yScale), sourceBox.size())).toPoint();
+        const QPointF bufferBottomRight = (m_bufferSourceBox.topLeft() + m_surfaceToBufferTransform.map(QPointF(rect.right() * xScale, rect.bottom() * yScale), sourceBox.size())).toPoint();
+        const QPointF bufferBottomLeft = (m_bufferSourceBox.topLeft() + m_surfaceToBufferTransform.map(QPointF(rect.left() * xScale, rect.bottom() * yScale), sourceBox.size())).toPoint();
 
         quad[0] = WindowVertex(rect.topLeft(), bufferTopLeft);
         quad[1] = WindowVertex(rect.topRight(), bufferTopRight);
diff --git a/src/scene/workspacescene.cpp b/src/scene/workspacescene.cpp
index c83ede3472b..b7475261f5d 100644
--- a/src/scene/workspacescene.cpp
+++ b/src/scene/workspacescene.cpp
@@ -621,9 +621,9 @@ static void addOpaqueRegionRecursive(SceneView *view, Item *item, const std::opt
     if (corner.has_value()) {
         opaque = corner->radius.clip(item->opaque(), corner->box);
     }
-    const Rect deviceRect = snapToPixelGrid(view->mapToDeviceCoordinates(item->mapToView(item->rect(), view)));
+    const Rect deviceRect = view->mapToDeviceCoordinates(item->mapToView(item->rect(), view)).rounded();
     for (const RectF &rect : opaque.rects()) {
-        ret |= snapToPixelGrid(view->mapToDeviceCoordinates(item->mapToView(rect, view))) & deviceRect;
+        ret |= view->mapToDeviceCoordinates(item->mapToView(rect, view)).rounded() & deviceRect;
     }
     const auto children = item->childItems();
     for (Item *child : children) {
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.