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

Remove support for start/end center in radial gradients #2534

Merged
merged 1 commit into from Mar 18, 2018
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

Remove support for start/end center in radial gardients

Though this may be necessary for SVG, it is currently unused and
blocking optimizations to the gradient shader.

This is part of #2439.
  • Loading branch information
mrobinson committed Mar 16, 2018
commit 54d0f7f0fe2b70cd023609cf814db8e0c47c9a7b
@@ -9,8 +9,7 @@
flat varying int vGradientAddress;
flat varying float vGradientRepeat;

flat varying vec2 vStartCenter;
flat varying vec2 vEndCenter;
flat varying vec2 vCenter;
flat varying float vStartRadius;
flat varying float vEndRadius;

@@ -23,8 +22,8 @@ varying vec2 vLocalPos;
#ifdef WR_VERTEX_SHADER

struct RadialGradient {
vec4 start_end_center;
vec4 start_end_radius_ratio_xy_extend_mode;
vec4 center_start_end_radius;
vec4 ratio_xy_extend_mode;
};

RadialGradient fetch_radial_gradient(int address) {
@@ -43,23 +42,20 @@ void brush_vs(

vPos = vi.local_pos - local_rect.p0;

vStartCenter = gradient.start_end_center.xy;
vEndCenter = gradient.start_end_center.zw;

vStartRadius = gradient.start_end_radius_ratio_xy_extend_mode.x;
vEndRadius = gradient.start_end_radius_ratio_xy_extend_mode.y;
vCenter = gradient.center_start_end_radius.xy;
vStartRadius = gradient.center_start_end_radius.z;
vEndRadius = gradient.center_start_end_radius.w;

// Transform all coordinates by the y scale so the
// fragment shader can work with circles
float ratio_xy = gradient.start_end_radius_ratio_xy_extend_mode.z;
float ratio_xy = gradient.ratio_xy_extend_mode.x;
vPos.y *= ratio_xy;
vStartCenter.y *= ratio_xy;
vEndCenter.y *= ratio_xy;
vCenter.y *= ratio_xy;

vGradientAddress = user_data.x;

// Whether to repeat the gradient instead of clamping.
vGradientRepeat = float(int(gradient.start_end_radius_ratio_xy_extend_mode.w) != EXTEND_MODE_CLAMP);
vGradientRepeat = float(int(gradient.ratio_xy_extend_mode.y) != EXTEND_MODE_CLAMP);

#ifdef WR_FEATURE_ALPHA_PASS
vLocalPos = vi.local_pos;
@@ -69,14 +65,13 @@ void brush_vs(

#ifdef WR_FRAGMENT_SHADER
vec4 brush_fs() {
vec2 cd = vEndCenter - vStartCenter;
vec2 pd = vPos - vStartCenter;
vec2 pd = vPos - vCenter;
float rd = vEndRadius - vStartRadius;

// Solve for t in length(t * cd - pd) = vStartRadius + t * rd
// Solve for t in length(t - pd) = vStartRadius + t * rd
// using a quadratic equation in form of At^2 - 2Bt + C = 0
float A = dot(cd, cd) - rd * rd;
float B = dot(pd, cd) + vStartRadius * rd;
float A = -(rd * rd);
float B = vStartRadius * rd;
float C = dot(pd, pd) - vStartRadius * vStartRadius;

float offset;
@@ -738,9 +738,8 @@ impl<'a> DisplayListFlattener<'a> {
self.add_radial_gradient(
clip_and_scroll,
&prim_info,
info.gradient.start_center,
info.gradient.center,
info.gradient.start_radius,
info.gradient.end_center,
info.gradient.end_radius,
info.gradient.ratio_xy,
item.gradient_stops(),
@@ -1824,9 +1823,8 @@ impl<'a> DisplayListFlattener<'a> {
self.add_radial_gradient(
clip_and_scroll,
&info,
border.gradient.start_center - segment_rel,
border.gradient.center - segment_rel,
border.gradient.start_radius,
border.gradient.end_center - segment_rel,
border.gradient.end_radius,
border.gradient.ratio_xy,
gradient_stops,
@@ -1938,9 +1936,8 @@ impl<'a> DisplayListFlattener<'a> {
&mut self,
clip_and_scroll: ScrollNodeAndClipChain,
info: &LayerPrimitiveInfo,
start_center: LayerPoint,
center: LayerPoint,
start_radius: f32,
end_center: LayerPoint,
end_radius: f32,
ratio_xy: f32,
stops: ItemRange<GradientStop>,
@@ -1951,8 +1948,7 @@ impl<'a> DisplayListFlattener<'a> {
BrushKind::RadialGradient {
stops_range: stops,
extend_mode,
start_center,
end_center,
center,
start_radius,
end_radius,
ratio_xy,
@@ -1973,9 +1969,8 @@ impl<'a> DisplayListFlattener<'a> {
&mut self,
clip_and_scroll: ScrollNodeAndClipChain,
info: &LayerPrimitiveInfo,
start_center: LayerPoint,
center: LayerPoint,
start_radius: f32,
end_center: LayerPoint,
end_radius: f32,
ratio_xy: f32,
stops: ItemRange<GradientStop>,
@@ -1996,9 +1991,8 @@ impl<'a> DisplayListFlattener<'a> {
self.add_radial_gradient_impl(
clip_and_scroll,
info,
start_center,
center,
start_radius,
end_center,
end_radius,
ratio_xy,
stops,
@@ -2010,9 +2004,8 @@ impl<'a> DisplayListFlattener<'a> {
self.add_radial_gradient_impl(
clip_and_scroll,
&prim_info,
start_center,
center,
start_radius,
end_center,
end_radius,
ratio_xy,
stops,
@@ -222,8 +222,7 @@ pub enum BrushKind {
gradient_index: CachedGradientIndex,
stops_range: ItemRange<GradientStop>,
extend_mode: ExtendMode,
start_center: LayerPoint,
end_center: LayerPoint,
center: LayerPoint,
start_radius: f32,
end_radius: f32,
ratio_xy: f32,
@@ -378,18 +377,18 @@ impl BrushPrimitive {
0.0,
]);
}
BrushKind::RadialGradient { start_center, end_center, start_radius, end_radius, ratio_xy, extend_mode, .. } => {
request.push([
start_center.x,
start_center.y,
end_center.x,
end_center.y,
]);
BrushKind::RadialGradient { center, start_radius, end_radius, ratio_xy, extend_mode, .. } => {
request.push([
center.x,
center.y,
start_radius,
end_radius,
]);
request.push([
ratio_xy,
pack_as_float(extend_mode as u32),
0.,
0.,
]);
}
}
@@ -418,9 +418,8 @@ pub struct GradientStop {

#[derive(Clone, Copy, Debug, Deserialize, PartialEq, Serialize)]
pub struct RadialGradient {
pub start_center: LayoutPoint,
pub center: LayoutPoint,
pub start_radius: f32,
pub end_center: LayoutPoint,
pub end_radius: f32,
pub ratio_xy: f32,
pub extend_mode: ExtendMode,
@@ -1188,9 +1188,8 @@ impl DisplayListBuilder {
self.push_stops(&stops);

return RadialGradient {
start_center: center,
center,
start_radius: 0.0,
end_center: center,
end_radius: 1.0,
ratio_xy: 1.0,
extend_mode,
@@ -1203,9 +1202,8 @@ impl DisplayListBuilder {
self.push_stops(&stops);

RadialGradient {
start_center: center,
center,
start_radius: radius.width * start_offset,
end_center: center,
end_radius: radius.width * end_offset,
ratio_xy: radius.width / radius.height,
extend_mode,
@@ -1216,9 +1214,8 @@ impl DisplayListBuilder {
// because create_gradient stores the stops in anticipation
pub fn create_complex_radial_gradient(
&mut self,
start_center: LayoutPoint,
center: LayoutPoint,
start_radius: f32,
end_center: LayoutPoint,
end_radius: f32,
ratio_xy: f32,
stops: Vec<GradientStop>,
@@ -1227,9 +1224,8 @@ impl DisplayListBuilder {
self.push_stops(&stops);

RadialGradient {
start_center,
center,
start_radius,
end_center,
end_radius,
ratio_xy,
extend_mode,
@@ -3,57 +3,50 @@ root:
items:
- type: radial-gradient
bounds: [ 0, 0, 1980, 1080]
start-center: [ 990, 540 ]
center: [ 990, 540 ]
start-radius: 5
end-center: [ 990, 540 ]
end-radius: 8000
stops: [ 0.0, black, 1.0, white ]
repeat: false
- type: radial-gradient
bounds: [ 0, 0, 1980, 1080]
start-center: [ 990, 540 ]
center: [ 990, 540 ]
start-radius: 5
end-center: [ 990, 540 ]
end-radius: 8000
stops: [ 0.0, black, 1.0, white ]
repeat: false
- type: radial-gradient
bounds: [ 0, 0, 1980, 1080]
start-center: [ 990, 540 ]
center: [ 990, 540 ]
start-radius: 5
end-center: [ 990, 540 ]
end-radius: 8000
stops: [ 0.0, black, 1.0, white ]
repeat: false
- type: radial-gradient
bounds: [ 0, 0, 1980, 1080]
start-center: [ 990, 540 ]
center: [ 990, 540 ]
start-radius: 5
end-center: [ 990, 540 ]
end-radius: 8000
stops: [ 0.0, black, 1.0, white ]
repeat: false
- type: radial-gradient
bounds: [ 0, 0, 1980, 1080]
start-center: [ 990, 540 ]
center: [ 990, 540 ]
start-radius: 5
end-center: [ 990, 540 ]
end-radius: 8000
stops: [ 0.0, black, 1.0, white ]
repeat: false
- type: radial-gradient
bounds: [ 0, 0, 1980, 1080]
start-center: [ 990, 540 ]
center: [ 990, 540 ]
start-radius: 5
end-center: [ 990, 540 ]
end-radius: 8000
stops: [ 0.0, black, 1.0, white ]
repeat: false
- type: radial-gradient
bounds: [ 0, 0, 1980, 1080]
start-center: [ 990, 540 ]
center: [ 990, 540 ]
start-radius: 5
end-center: [ 990, 540 ]
end-radius: 8000
stops: [ 0.0, black, 1.0, white ]
repeat: false
@@ -6,65 +6,57 @@ root:
items:
- type: radial-gradient # top left
bounds: [ 0, 0, 10, 10]
start-center: [ 25, 25 ]
center: [ 25, 25 ]
start-radius: 15
end-center: [ 25, 25 ]
end-radius: 35
stops: [ 0.0, red, 1.0, green ]
repeat: false
- type: radial-gradient # top right
bounds: [ 40, 0, 10, 10]
start-center: [ -15, 25 ]
center: [ -15, 25 ]
start-radius: 15
end-center: [ -15, 25 ]
end-radius: 35
stops: [ 0.0, red, 1.0, green ]
repeat: false
- type: radial-gradient # bottom left
bounds: [ 0, 40, 10, 10]
start-center: [ 25, -15 ]
center: [ 25, -15 ]
start-radius: 15
end-center: [ 25, -15 ]
end-radius: 35
stops: [ 0.0, red, 1.0, green ]
repeat: false
- type: radial-gradient # bottom right
bounds: [ 40, 40, 10, 10]
start-center: [ -15, -15 ]
center: [ -15, -15 ]
start-radius: 15
end-center: [ -15, -15 ]
end-radius: 35
stops: [ 0.0, red, 1.0, green ]
repeat: false
- type: radial-gradient # top
bounds: [ 10, 0, 30, 10]
start-center: [ 15, 25 ]
center: [ 15, 25 ]
start-radius: 15
end-center: [ 15, 25 ]
end-radius: 35
stops: [ 0.0, red, 1.0, green ]
repeat: false
- type: radial-gradient # right
bounds: [ 40, 10, 10, 30]
start-center: [ -15, 15 ]
center: [ -15, 15 ]
start-radius: 15
end-center: [ -15, 15 ]
end-radius: 35
stops: [ 0.0, red, 1.0, green ]
repeat: false
- type: radial-gradient # bottom
bounds: [ 10, 40, 30, 10]
start-center: [ 15, -15 ]
center: [ 15, -15 ]
start-radius: 15
end-center: [ 15, -15 ]
end-radius: 35
stops: [ 0.0, red, 1.0, green ]
repeat: false
- type: radial-gradient # left
bounds: [ 0, 10, 10, 30]
start-center: [ 25, 15 ]
center: [ 25, 15 ]
start-radius: 15
end-center: [ 25, 15 ]
end-radius: 35
stops: [ 0.0, red, 1.0, green ]
repeat: false
@@ -8,9 +8,8 @@ root:
bounds: [ 0, 0, 50, 50 ]
width: [ 10, 10, 10, 10 ]
border-type: radial-gradient
start-center: [ 25, 25 ]
center: [ 25, 25 ]
start-radius: 15
end-center: [ 25, 25 ]
end-radius: 35
stops: [ 0.0, red, 1.0, green ]
outset: [ 0, 0, 0, 0 ]
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.