Skip to content

Commit 55bd6a0

Browse files
committed
Better fractional scaling support
1 parent e5c27db commit 55bd6a0

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

lib/RoundedCornersEffect.vala

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@
44
*/
55

66
public class Gala.RoundedCornersEffect : Clutter.OffscreenEffect {
7-
public float clip_radius { get; construct; }
7+
public int clip_radius { get; construct; }
88
public float monitor_scale { get; construct set; }
99

1010
private int offset_location;
1111
private int actor_size_location;
1212
private int full_texture_size_location;
1313
private int clip_radius_location;
1414

15-
public RoundedCornersEffect (float clip_radius, float monitor_scale) {
15+
public RoundedCornersEffect (int clip_radius, float monitor_scale) {
1616
Object (clip_radius: clip_radius, monitor_scale: monitor_scale);
1717
}
1818

@@ -28,7 +28,7 @@ public class Gala.RoundedCornersEffect : Clutter.OffscreenEffect {
2828
uniform vec2 offset;
2929
uniform vec2 actor_size;
3030
uniform vec2 full_texture_size;
31-
uniform float clip_radius;
31+
uniform int clip_radius;
3232
3333
float rounded_rect_coverage (vec2 p) {
3434
float center_left = clip_radius;
@@ -71,7 +71,8 @@ public class Gala.RoundedCornersEffect : Clutter.OffscreenEffect {
7171
}
7272
7373
// Only pixels on the edge of the curve need expensive antialiasing
74-
return smoothstep (outer_radius, inner_radius, sqrt (dist_squared));
74+
// return smoothstep (outer_radius, inner_radius, sqrt (dist_squared));
75+
return outer_radius - sqrt (dist_squared);
7576
}
7677
""",
7778
null
@@ -84,7 +85,7 @@ public class Gala.RoundedCornersEffect : Clutter.OffscreenEffect {
8485
if (texture_coord.x < offset.x || texture_coord.x > offset.x + actor_size.x ||
8586
texture_coord.y < offset.y || texture_coord.y > offset.y + actor_size.y
8687
) {
87-
cogl_color_out = sample * cogl_color_in;
88+
cogl_color_out = vec4(0, 0, 0, 0);
8889
return;
8990
}
9091
@@ -116,15 +117,21 @@ public class Gala.RoundedCornersEffect : Clutter.OffscreenEffect {
116117
float texture_width, texture_height;
117118
get_target_size (out texture_width, out texture_height);
118119

120+
var resource_scale = actor.get_resource_scale ();
121+
119122
var actor_box = actor.get_allocation_box ();
123+
actor_box.scale (resource_scale);
120124
var effect_box = actor_box.copy ();
121125
clutter_actor_box_enlarge_for_effects (ref effect_box);
122126

127+
var offset_x = Math.ceilf ((actor_box.x1 - effect_box.x1) * resource_scale);
128+
var offset_y = Math.ceilf ((actor_box.y1 - effect_box.y1) * resource_scale);
129+
123130
unowned var pipeline = get_pipeline ();
124-
pipeline.set_uniform_float (offset_location, 2, 1, { actor_box.x1 - effect_box.x1, actor_box.y1 - effect_box.y1 });
125-
pipeline.set_uniform_float (actor_size_location, 2, 1, { actor.width, actor.height });
131+
pipeline.set_uniform_float (offset_location, 2, 1, { offset_x, offset_y });
132+
pipeline.set_uniform_float (actor_size_location, 2, 1, { Math.ceilf (actor_box.get_width ()), Math.ceilf (actor_box.get_height ()) });
126133
pipeline.set_uniform_float (full_texture_size_location, 2, 1, { texture_width, texture_height });
127-
pipeline.set_uniform_1f (clip_radius_location, clip_radius * monitor_scale);
134+
pipeline.set_uniform_1i (clip_radius_location, Utils.scale_to_int (clip_radius, monitor_scale));
128135

129136
base.paint_target (node, paint_context);
130137
}

0 commit comments

Comments
 (0)