Skip to content

Commit c1a29cb

Browse files
authored
meta-crtc-xrandr.c: use nearest neighbor filter for integer randr scales (#692)
Use the nearest neighbor filter if the scaling factor is an integer. This provides a crisper, less blurry scale when the scale is an integer. Note that this change only affects fractional scaling when the "scale-up" mode is used. Scaling down is unaffected by this change, and non-integer scaling up is also unaffected by this change. This behavior was already in Cinnamon 5.4, but it was lost at some point in between 5.4 and now. Note finally that the "nearest" filter is a filter guaranteed to exist by the RENDER protocol [1]. [1] https://cgit.freedesktop.org/xorg/proto/renderproto/tree/renderproto.txt
1 parent b15de53 commit c1a29cb

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

src/backends/x11/meta-crtc-xrandr.c

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ meta_crtc_xrandr_set_scale (MetaCrtc *crtc,
135135
DOUBLE_TO_FIXED (0), DOUBLE_TO_FIXED (1), DOUBLE_TO_FIXED (0),
136136
DOUBLE_TO_FIXED (0), DOUBLE_TO_FIXED (0), DOUBLE_TO_FIXED (1)
137137
};
138+
float integer_scale;
138139

139140
if (!(meta_monitor_manager_get_capabilities (monitor_manager) &
140141
META_MONITOR_MANAGER_CAPABILITY_NATIVE_OUTPUT_SCALING))
@@ -145,9 +146,19 @@ meta_crtc_xrandr_set_scale (MetaCrtc *crtc,
145146

146147
if (fabsf (scale - 1.0f) > 0.001)
147148
{
148-
scale_filter = FilterGood;
149-
transformation.matrix11 = DOUBLE_TO_FIXED (1.0 / scale);
150-
transformation.matrix22 = DOUBLE_TO_FIXED (1.0 / scale);
149+
integer_scale = roundf (scale);
150+
if (fabsf (scale - integer_scale) > 0.001)
151+
{
152+
scale_filter = FilterGood;
153+
transformation.matrix11 = DOUBLE_TO_FIXED (1.0 / scale);
154+
transformation.matrix22 = DOUBLE_TO_FIXED (1.0 / scale);
155+
}
156+
else /* if integer multiple then use nearest neighbor filter */
157+
{
158+
scale_filter = "nearest";
159+
transformation.matrix11 = DOUBLE_TO_FIXED (1.0 / integer_scale);
160+
transformation.matrix22 = DOUBLE_TO_FIXED (1.0 / integer_scale);
161+
}
151162
}
152163
else
153164
scale_filter = FilterFast;

0 commit comments

Comments
 (0)