Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Revert "Support border corners with differing styles" #1239

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

@@ -2,51 +2,35 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

float clip_against_ellipse_if_needed(vec2 pos,
float current_distance,
vec4 ellipse_center_radius,
vec2 sign_modifier,
float afwidth) {
float ellipse_distance = distance_to_ellipse(pos - ellipse_center_radius.xy,
ellipse_center_radius.zw);

return mix(current_distance,
ellipse_distance + afwidth,
all(lessThan(sign_modifier * pos, sign_modifier * ellipse_center_radius.xy)));
}

float rounded_rect(vec2 pos) {
float current_distance = 0.0;

// Apply AA
float afwidth = 0.5 * length(fwidth(pos));

// Clip against each ellipse.
current_distance = clip_against_ellipse_if_needed(pos,
current_distance,
vClipCenter_Radius_TL,
vec2(1.0),
afwidth);

current_distance = clip_against_ellipse_if_needed(pos,
current_distance,
vClipCenter_Radius_TR,
vec2(-1.0, 1.0),
afwidth);

current_distance = clip_against_ellipse_if_needed(pos,
current_distance,
vClipCenter_Radius_BR,
vec2(-1.0),
afwidth);

current_distance = clip_against_ellipse_if_needed(pos,
current_distance,
vClipCenter_Radius_BL,
vec2(1.0, -1.0),
afwidth);

return smoothstep(0.0, afwidth, 1.0 - current_distance);
vec2 ref_tl = vClipRect.xy + vec2( vClipRadius.x, vClipRadius.x);
vec2 ref_tr = vClipRect.zy + vec2(-vClipRadius.y, vClipRadius.y);
vec2 ref_br = vClipRect.zw + vec2(-vClipRadius.z, -vClipRadius.z);
vec2 ref_bl = vClipRect.xw + vec2( vClipRadius.w, -vClipRadius.w);

float d_tl = distance(pos, ref_tl);
float d_tr = distance(pos, ref_tr);
float d_br = distance(pos, ref_br);
float d_bl = distance(pos, ref_bl);

float pixels_per_fragment = length(fwidth(pos.xy));
float nudge = 0.5 * pixels_per_fragment;
vec4 distances = vec4(d_tl, d_tr, d_br, d_bl) - vClipRadius + nudge;

bvec4 is_out = bvec4(pos.x < ref_tl.x && pos.y < ref_tl.y,
pos.x > ref_tr.x && pos.y < ref_tr.y,
pos.x > ref_br.x && pos.y > ref_br.y,
pos.x < ref_bl.x && pos.y > ref_bl.y);

float distance_from_border = dot(vec4(is_out),
max(vec4(0.0, 0.0, 0.0, 0.0), distances));

// Move the distance back into pixels.
distance_from_border /= pixels_per_fragment;
// Apply a more gradual fade out to transparent.
//distance_from_border -= 0.5;

return 1.0 - smoothstep(0.0, 1.0, distance_from_border);
}


@@ -5,8 +5,6 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

varying vec3 vPos;
flat varying vec4 vClipRect;
flat varying vec4 vClipRadius;
flat varying float vClipMode;
flat varying vec4 vClipCenter_Radius_TL;
flat varying vec4 vClipCenter_Radius_TR;
flat varying vec4 vClipCenter_Radius_BL;
flat varying vec4 vClipCenter_Radius_BR;
@@ -57,20 +57,9 @@ void main(void) {
vPos = vi.local_pos;

vClipMode = clip.rect.mode.x;

RectWithEndpoint clip_rect = to_rect_with_endpoint(local_rect);

vClipCenter_Radius_TL = vec4(clip_rect.p0 + clip.top_left.outer_inner_radius.xy,
clip.top_left.outer_inner_radius.xy);

vClipCenter_Radius_TR = vec4(clip_rect.p1.x - clip.top_right.outer_inner_radius.x,
clip_rect.p0.y + clip.top_right.outer_inner_radius.y,
clip.top_right.outer_inner_radius.xy);

vClipCenter_Radius_BR = vec4(clip_rect.p1 - clip.bottom_right.outer_inner_radius.xy,
clip.bottom_right.outer_inner_radius.xy);

vClipCenter_Radius_BL = vec4(clip_rect.p0.x + clip.bottom_left.outer_inner_radius.x,
clip_rect.p1.y - clip.bottom_left.outer_inner_radius.y,
clip.bottom_left.outer_inner_radius.xy);
vClipRect = vec4(local_rect.p0, local_rect.p0 + local_rect.size);
vClipRadius = vec4(clip.top_left.outer_inner_radius.x,
clip.top_right.outer_inner_radius.x,
clip.bottom_right.outer_inner_radius.x,
clip.bottom_left.outer_inner_radius.x);
}
@@ -878,66 +878,4 @@ vec4 sample_gradient(float offset, float gradient_repeat, float gradient_index,
return dither(texture(sGradients, vec2(x, y) / gradient_size));
}

//
// Signed distance to an ellipse.
// Taken from http://www.iquilezles.org/www/articles/ellipsedist/ellipsedist.htm
// Note that this fails for exact circles.
//
float sdEllipse( vec2 p, in vec2 ab ) {
p = abs( p ); if( p.x > p.y ){ p=p.yx; ab=ab.yx; }
float l = ab.y*ab.y - ab.x*ab.x;

float m = ab.x*p.x/l;
float n = ab.y*p.y/l;
float m2 = m*m;
float n2 = n*n;

float c = (m2 + n2 - 1.0)/3.0;
float c3 = c*c*c;

float q = c3 + m2*n2*2.0;
float d = c3 + m2*n2;
float g = m + m*n2;

float co;

if( d<0.0 )
{
float p = acos(q/c3)/3.0;
float s = cos(p);
float t = sin(p)*sqrt(3.0);
float rx = sqrt( -c*(s + t + 2.0) + m2 );
float ry = sqrt( -c*(s - t + 2.0) + m2 );
co = ( ry + sign(l)*rx + abs(g)/(rx*ry) - m)/2.0;
}
else
{
float h = 2.0*m*n*sqrt( d );
float s = sign(q+h)*pow( abs(q+h), 1.0/3.0 );
float u = sign(q-h)*pow( abs(q-h), 1.0/3.0 );
float rx = -s - u - c*4.0 + 2.0*m2;
float ry = (s - u)*sqrt(3.0);
float rm = sqrt( rx*rx + ry*ry );
float p = ry/sqrt(rm-rx);
co = (p + 2.0*g/rm - m)/2.0;
}

float si = sqrt( 1.0 - co*co );

vec2 r = vec2( ab.x*co, ab.y*si );

return length(r - p ) * sign(p.y-r.y);
}

float distance_to_ellipse(vec2 p, vec2 radii) {
// sdEllipse fails on exact circles, so handle equal
// radii here. The branch coherency should make this
// a performance win for the circle case too.
if (radii.x == radii.y) {
return length(p) - radii.x;
} else {
return sdEllipse(p, radii);
}
}

#endif //WR_FRAGMENT_SHADER
@@ -3,6 +3,68 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

//
// Signed distance to an ellipse.
// Taken from http://www.iquilezles.org/www/articles/ellipsedist/ellipsedist.htm
// Note that this fails for exact circles.
//
float sdEllipse( vec2 p, in vec2 ab ) {
p = abs( p ); if( p.x > p.y ){ p=p.yx; ab=ab.yx; }
float l = ab.y*ab.y - ab.x*ab.x;

float m = ab.x*p.x/l;
float n = ab.y*p.y/l;
float m2 = m*m;
float n2 = n*n;

float c = (m2 + n2 - 1.0)/3.0;
float c3 = c*c*c;

float q = c3 + m2*n2*2.0;
float d = c3 + m2*n2;
float g = m + m*n2;

float co;

if( d<0.0 )
{
float p = acos(q/c3)/3.0;
float s = cos(p);
float t = sin(p)*sqrt(3.0);
float rx = sqrt( -c*(s + t + 2.0) + m2 );
float ry = sqrt( -c*(s - t + 2.0) + m2 );
co = ( ry + sign(l)*rx + abs(g)/(rx*ry) - m)/2.0;
}
else
{
float h = 2.0*m*n*sqrt( d );
float s = sign(q+h)*pow( abs(q+h), 1.0/3.0 );
float u = sign(q-h)*pow( abs(q-h), 1.0/3.0 );
float rx = -s - u - c*4.0 + 2.0*m2;
float ry = (s - u)*sqrt(3.0);
float rm = sqrt( rx*rx + ry*ry );
float p = ry/sqrt(rm-rx);
co = (p + 2.0*g/rm - m)/2.0;
}

float si = sqrt( 1.0 - co*co );

vec2 r = vec2( ab.x*co, ab.y*si );

return length(r - p ) * sign(p.y-r.y);
}

float distance_to_ellipse(vec2 p, vec2 radii) {
// sdEllipse fails on exact circles, so handle equal
// radii here. The branch coherency should make this
// a performance win for the circle case too.
if (radii.x == radii.y) {
return length(p) - radii.x;
} else {
return sdEllipse(p, radii);
}
}

void main(void) {
float alpha = 1.0;
#ifdef WR_FEATURE_TRANSFORM

This file was deleted.

Binary file not shown.

This file was deleted.

@@ -1,6 +1,6 @@
!= inset-simple.yaml inset-simple-ref.yaml
!= inset-spread.yaml inset-spread-ref.yaml
== inset-no-blur-radius.yaml inset-no-blur-radius-ref.png
#== inset-no-blur-radius.yaml inset-no-blur-radius-ref.png #temporary disabled, see #1239
== inset-spread-large.yaml inset-spread-large-ref.yaml
fuzzy(1,396) == inset-large-offset.yaml inset-large-offset-ref.png

Binary file not shown.
@@ -8,4 +8,3 @@ include border/reftest.list
include gradient/reftest.list
include text/reftest.list
include split/reftest.list
include aa/reftest.list
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.