Skip to content

Commit

Permalink
Bug 1573886 - Fix backdrop-filter blur errors due to incorrect scalin…
Browse files Browse the repository at this point in the history
  • Loading branch information
cbrewster authored and wrupdater committed Aug 15, 2019
1 parent ce380c5 commit 60d37bd
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 17 deletions.
6 changes: 4 additions & 2 deletions webrender/res/cs_blur.glsl
Expand Up @@ -25,14 +25,16 @@ in int aBlurDirection;
struct BlurTask {
RenderTaskCommonData common_data;
float blur_radius;
vec2 blur_region;
};

BlurTask fetch_blur_task(int address) {
RenderTaskData task_data = fetch_render_task_data(address);

BlurTask task = BlurTask(
task_data.common_data,
task_data.user_data.x
task_data.user_data.x,
task_data.user_data.yz
);

return task;
Expand Down Expand Up @@ -72,7 +74,7 @@ void main(void) {
}

vUvRect = vec4(src_rect.p0 + vec2(0.5),
src_rect.p0 + src_rect.size - vec2(0.5));
src_rect.p0 + blur_task.blur_region - vec2(0.5));
vUvRect /= texture_size.xyxy;

vec2 pos = target_rect.p0 + target_rect.size * aPosition.xy;
Expand Down
28 changes: 15 additions & 13 deletions webrender/src/picture.rs
Expand Up @@ -2563,7 +2563,7 @@ impl PicturePrimitive {
blur_std_deviation * scale_factors.0,
blur_std_deviation * scale_factors.1
);
let device_rect = if self.options.inflate_if_required {
let mut device_rect = if self.options.inflate_if_required {
let inflation_factor = frame_state.surfaces[raster_config.surface_index.0].inflation_factor;
let inflation_factor = (inflation_factor * device_pixel_scale.0).ceil();

Expand All @@ -2582,26 +2582,26 @@ impl PicturePrimitive {
.intersection(&unclipped)
.unwrap();

let mut device_rect = match device_rect.try_cast::<i32>() {
match device_rect.try_cast::<i32>() {
Some(rect) => rect,
None => {
return None
}
};

// Adjust the size to avoid introducing sampling errors during the down-scaling passes.
// what would be even better is to rasterize the picture at the down-scaled size
// directly.
device_rect.size = RenderTask::adjusted_blur_source_size(
device_rect.size,
blur_std_deviation,
);

device_rect
}
} else {
clipped
};

let original_size = device_rect.size;

// Adjust the size to avoid introducing sampling errors during the down-scaling passes.
// what would be even better is to rasterize the picture at the down-scaled size
// directly.
device_rect.size = RenderTask::adjusted_blur_source_size(
device_rect.size,
blur_std_deviation,
);

let uv_rect_kind = calculate_uv_rect_kind(
&pic_rect,
&transform,
Expand Down Expand Up @@ -2630,6 +2630,7 @@ impl PicturePrimitive {
RenderTargetKind::Color,
ClearMode::Transparent,
None,
original_size,
);

Some((blur_render_task_id, picture_task_id))
Expand Down Expand Up @@ -2701,6 +2702,7 @@ impl PicturePrimitive {
RenderTargetKind::Color,
ClearMode::Transparent,
Some(&mut blur_tasks),
device_rect.size,
);
}

Expand Down
13 changes: 11 additions & 2 deletions webrender/src/render_task.rs
Expand Up @@ -559,6 +559,7 @@ pub struct BlurTask {
pub blur_std_deviation: f32,
pub target_kind: RenderTargetKind,
pub uv_rect_handle: GpuCacheHandle,
pub blur_region: DeviceIntSize,
uv_rect_kind: UvRectKind,
}

Expand Down Expand Up @@ -975,6 +976,7 @@ impl RenderTask {
RenderTargetKind::Alpha,
ClearMode::Zero,
None,
cache_size,
)
}
));
Expand Down Expand Up @@ -1086,6 +1088,7 @@ impl RenderTask {
target_kind: RenderTargetKind,
clear_mode: ClearMode,
mut blur_cache: Option<&mut BlurTaskCache>,
blur_region: DeviceIntSize,
) -> RenderTaskId {
// Adjust large std deviation value.
let mut adjusted_blur_std_deviation = blur_std_deviation;
Expand Down Expand Up @@ -1137,6 +1140,8 @@ impl RenderTask {
None => None,
};

let blur_region = blur_region / (scale_factor as i32);

let blur_task_id = cached_task.unwrap_or_else(|| {
let blur_task_v = RenderTask::with_dynamic_location(
adjusted_blur_target_size,
Expand All @@ -1145,6 +1150,7 @@ impl RenderTask {
blur_std_deviation: adjusted_blur_std_deviation.height,
target_kind,
uv_rect_handle: GpuCacheHandle::new(),
blur_region,
uv_rect_kind,
}),
clear_mode,
Expand All @@ -1159,6 +1165,7 @@ impl RenderTask {
blur_std_deviation: adjusted_blur_std_deviation.width,
target_kind,
uv_rect_handle: GpuCacheHandle::new(),
blur_region,
uv_rect_kind,
}),
clear_mode,
Expand Down Expand Up @@ -1363,6 +1370,7 @@ impl RenderTask {
RenderTargetKind::Color,
ClearMode::Transparent,
None,
content_size,
)
}
FilterPrimitiveKind::Opacity(ref opacity) => {
Expand Down Expand Up @@ -1432,6 +1440,7 @@ impl RenderTask {
RenderTargetKind::Color,
ClearMode::Transparent,
None,
content_size,
);

let task = RenderTask::new_svg_filter_primitive(
Expand Down Expand Up @@ -1585,8 +1594,8 @@ impl RenderTask {
RenderTaskKind::HorizontalBlur(ref task) => {
[
task.blur_std_deviation,
0.0,
0.0,
task.blur_region.width as f32,
task.blur_region.height as f32,
]
}
RenderTaskKind::Readback(..) |
Expand Down

0 comments on commit 60d37bd

Please sign in to comment.