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

Sync changes from mozilla-central gfx/wr #3848

Merged
merged 6 commits into from Feb 4, 2020

Bug 1571974: Simplify orientation handling in line decoration shaders…

…. r=kvark

We want to use the same line decoration (dashed, dotted, wavy) shader code for
both horizontal and vertical lines, so it makes sense for them to use a
coordinate system that has been rotated (transposed, actually) so that .x always
runs parallel to the line being decorated, and .y is always perpendicular.

Before this patch, we passed the orientation enum as a vertex attribute, used a
switch to swap coordinates in the vertex shader, and then swapped them again in
the fragment shader.

This patch trades the orientation for a f32 'axis select' vertex attribute, and
uses `mix` to swap them in the vertex shader. Then no consideration is necessary
in the fragment shader: the vLocalPos varying is already in the appropriate form.

Since get_line_decoration_sizes is already thinking in terms of line-parallel
coordinates, it might seem like a good idea for decoration jobs to simply use
line-parallel coordinates throughout. However, this actually results in more
swapping and opportunities for confusion: much of the CPU work is concerned with
the rectangle the decoration's mask occupies in the texture cache, which is
axis-aligned.

Differential Revision: https://phabricator.services.mozilla.com/D60926

[ghsync] From https://hg.mozilla.org/mozilla-central/rev/dfb21632ea198c1acdc6a34ee08113d516f666d5
  • Loading branch information
Jim Blandy authored and moz-gfx committed Feb 4, 2020
commit b174a8e1b26fc99d7e274fc2a0271df9991108e6
@@ -9,41 +9,37 @@
#define LINE_STYLE_DASHED 2
#define LINE_STYLE_WAVY 3

// Local space position
// Fragment position in the coordinate system used for positioning decorations.
// To keep the code independent of whether the line is horizontal or vertical,
// vLocalPos.x is always parallel, and .y always perpendicular, to the line
// being decorated.
varying vec2 vLocalPos;

flat varying float vAxisSelect;
flat varying int vStyle;
flat varying vec4 vParams;

#ifdef WR_VERTEX_SHADER

#define LINE_ORIENTATION_VERTICAL 0
#define LINE_ORIENTATION_HORIZONTAL 1

// The size of the mask tile we're rendering, in pixels.
in vec4 aTaskRect;

// The size of the mask tile. aLocalSize.x is always horizontal and .y vertical,
// regardless of the line's orientation. The size is chosen by
// prim_store::get_line_decoration_sizes.
in vec2 aLocalSize;

// A LINE_STYLE_* value, indicating what sort of line to draw.
in int aStyle;
in int aOrientation;
in float aWavyLineThickness;

void main(void) {
vec2 size;
// 0.0 for a horizontal line, 1.0 for a vertical line.
in float aAxisSelect;

switch (aOrientation) {
case LINE_ORIENTATION_HORIZONTAL:
vAxisSelect = 0.0;
size = aLocalSize;
break;
case LINE_ORIENTATION_VERTICAL:
vAxisSelect = 1.0;
size = aLocalSize.yx;
break;
default:
vAxisSelect = 0.0;
size = vec2(0.0);
}
// The thickness of the wavy line itself, not the amplitude of the waves (i.e.,
// the thickness of the final decorated line).
in float aWavyLineThickness;

void main(void) {
vec2 size = mix(aLocalSize, aLocalSize.yx, aAxisSelect);
vStyle = aStyle;

switch (vStyle) {
@@ -86,7 +82,7 @@ void main(void) {
vParams = vec4(0.0);
}

vLocalPos = aPosition.xy * aLocalSize;
vLocalPos = mix(aPosition.xy, aPosition.yx, aAxisSelect) * size;

gl_Position = uTransform * vec4(aTaskRect.xy + aTaskRect.zw * aPosition.xy, 0.0, 1.0);
}
@@ -98,13 +94,10 @@ void main(void) {

void main(void) {
// Find the appropriate distance to apply the step over.
vec2 local_pos = vLocalPos;
float aa_range = compute_aa_range(local_pos);
vec2 pos = vLocalPos;
float aa_range = compute_aa_range(pos);
float alpha = 1.0;

// Select the x/y coord, depending on which axis this edge is.
vec2 pos = mix(local_pos.xy, local_pos.yx, vAxisSelect);

switch (vStyle) {
case LINE_STYLE_SOLID: {
break;
@@ -773,7 +773,10 @@ impl TextureCacheRenderTarget {
task_rect: target_rect.0.to_f32(),
local_size: info.local_size,
style: info.style as i32,
orientation: info.orientation as i32,
axis_select: match info.orientation {
LineOrientation::Horizontal => 0.0,
LineOrientation::Vertical => 1.0,
},
wavy_line_thickness: info.wavy_line_thickness,
});
}
@@ -1056,7 +1059,7 @@ pub struct LineDecorationJob {
pub local_size: LayoutSize,
pub wavy_line_thickness: f32,
pub style: i32,
pub orientation: i32,
pub axis_select: f32,
}

#[cfg_attr(feature = "capture", derive(Serialize))]
@@ -454,9 +454,9 @@ pub(crate) mod desc {
kind: VertexAttributeKind::I32,
},
VertexAttribute {
name: "aOrientation",
name: "aAxisSelect",
count: 1,
kind: VertexAttributeKind::I32,
kind: VertexAttributeKind::F32,
},
],
};
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.