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

Port dot/dash to border brushes, remove old border code. #2795

Merged
merged 3 commits into from Jun 4, 2018
Merged
Changes from 1 commit
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

Next

Port dot/dash to border brushes, remove old border code.

This ports the last remaining legacy border styles to run with
the new border brush implementation.

With the complete, it's possible to remove all the old border
path code and shaders.

The dash/dot placement is not quite the same as the previous
code. It's better in some cases, and worse in others. Working
on this as a follow up to handle all the possible edge cases
should be much easier once this patch lands.

This completes the work of moving borders to be brush images,
which gives some very significant performance wins - mostly
stemming from (a) caching of border primitives across scrolls
and display lists and (b) much better batching during the main
scene pass, since all borders are now batched as brush_images.
  • Loading branch information
gw3583 committed Jun 1, 2018
commit c05f4d95e4d7236310127fee8326a87d797c479e
@@ -95,10 +95,10 @@ void brush_vs(
// works. That assumption may not hold if this
// is used for other purposes in the future.
if ((brush_flags & BRUSH_FLAG_SEGMENT_REPEAT_X) != 0) {
stretch_size.x = texel_rect.z - texel_rect.x;
stretch_size.x = (texel_rect.z - texel_rect.x) / uDevicePixelRatio;
}
if ((brush_flags & BRUSH_FLAG_SEGMENT_REPEAT_Y) != 0) {
stretch_size.y = texel_rect.w - texel_rect.y;
stretch_size.y = (texel_rect.w - texel_rect.y) / uDevicePixelRatio;
}

uv0 = res.uv_rect.p0 + texel_rect.xy;
@@ -13,8 +13,8 @@ flat varying vec4 vColor1[2];
// transition occurs. Used for corners only.
flat varying vec4 vColorLine;

// x = segment, y = styles, z = edge axes
flat varying ivec3 vConfig;
// x = segment, y = styles, z = edge axes, w = clip mode
flat varying ivec4 vConfig;

// xy = Local space position of the clip center.
// zw = Scale the rect origin by this to get the outer
@@ -31,6 +31,10 @@ flat varying vec4 vEdgeReference;
// Stores widths/2 and widths/3 to save doing this in FS.
flat varying vec4 vPartialWidths;

// Clipping parameters for dot or dash.
flat varying vec4 vClipParams1;
flat varying vec4 vClipParams2;

// Local space position
varying vec2 vPos;

@@ -55,6 +59,10 @@ varying vec2 vPos;
#define BORDER_STYLE_INSET 8
#define BORDER_STYLE_OUTSET 9

#define CLIP_NONE 0
#define CLIP_DASH 1
#define CLIP_DOT 2

#ifdef WR_VERTEX_SHADER

in vec2 aTaskOrigin;
@@ -64,6 +72,8 @@ in vec4 aColor1;
in int aFlags;
in vec2 aWidths;
in vec2 aRadii;
in vec4 aClipParams1;
in vec4 aClipParams2;

vec2 get_outer_corner_scale(int segment) {
vec2 p;
@@ -120,6 +130,7 @@ void main(void) {
int segment = aFlags & 0xff;
int style0 = (aFlags >> 8) & 0xff;
int style1 = (aFlags >> 16) & 0xff;
int clip_mode = (aFlags >> 24) & 0xff;

vec2 outer_scale = get_outer_corner_scale(segment);
vec2 outer = outer_scale * aRect.zw;
@@ -161,10 +172,11 @@ void main(void) {
break;
}

vConfig = ivec3(
vConfig = ivec4(
segment,
style0 | (style1 << 16),
edge_axis.x | (edge_axis.y << 16)
edge_axis.x | (edge_axis.y << 16),
clip_mode
);
vPartialWidths = vec4(aWidths / 3.0, aWidths / 2.0);
vPos = aRect.zw * aPosition.xy;
@@ -175,6 +187,19 @@ void main(void) {
vClipRadii = vec4(aRadii, max(aRadii - aWidths, 0.0));
vColorLine = vec4(outer, aWidths.y * -clip_sign.y, aWidths.x * clip_sign.x);
vEdgeReference = vec4(edge_reference, edge_reference + aWidths);
vClipParams1 = aClipParams1;
vClipParams2 = aClipParams2;

// For the case of dot clips, optimize the number of pixels that
// are hit to just include the dot itself.
// TODO(gw): We should do something similar in the future for
// dash clips!
if (clip_mode == CLIP_DOT) {
float expanded_radius = aClipParams1.z + 2.0;
vPos = vClipParams1.xy - vec2(expanded_radius);
vPos += (aPosition.xy * vec2(expanded_radius * 2.0));
vPos = clamp(vPos, vec2(0.0), aRect.zw);
}

gl_Position = uTransform * vec4(aTaskOrigin + aRect.xy + vPos, 0.0, 1.0);
}
@@ -282,6 +307,7 @@ void main(void) {
int segment = vConfig.x;
ivec2 style = ivec2(vConfig.y & 0xffff, vConfig.y >> 16);
ivec2 edge_axis = ivec2(vConfig.z & 0xffff, vConfig.z >> 16);
int clip_mode = vConfig.w;

float mix_factor = 0.0;
if (edge_axis.x != edge_axis.y) {
@@ -293,6 +319,29 @@ void main(void) {
vec2 clip_relative_pos = vPos - vClipCenter_Sign.xy;
bool in_clip_region = all(lessThan(vClipCenter_Sign.zw * clip_relative_pos, vec2(0.0)));

switch (clip_mode) {
case CLIP_DOT: {
// Set clip distance based or dot position and radius.
d = distance(vClipParams1.xy, vPos) - vClipParams1.z;
break;
}
case CLIP_DASH: {
// Get SDF for the two line/tangent clip lines,
// do SDF subtract to get clip distance.
float d0 = distance_to_line(vClipParams1.xy,
vClipParams1.zw,
vPos);
float d1 = distance_to_line(vClipParams2.xy,
vClipParams2.zw,
vPos);
d = max(d0, -d1);
break;
}
case CLIP_NONE:
default:
break;
}

if (in_clip_region) {
float d_radii_a = distance_to_ellipse(clip_relative_pos, vClipRadii.xy, aa_range);
float d_radii_b = distance_to_ellipse(clip_relative_pos, vClipRadii.zw, aa_range);

This file was deleted.

ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.