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 #3548

Merged
merged 6 commits into from Feb 12, 2019

Bug 1523495 - Adjust shadow blur target sizes to avoid down-scaling a…

  • Loading branch information
nical authored and moz-gfx committed Feb 11, 2019
commit e1a6d80a2a0afa637ee76d0ba53aa73fb2e4d86d
@@ -2956,7 +2956,7 @@ impl PicturePrimitive {
PictureCompositeMode::Filter(FilterOp::DropShadow(offset, blur_radius, color)) => {
let blur_std_deviation = blur_radius * frame_context.device_pixel_scale.0;
let blur_range = (blur_std_deviation * BLUR_SAMPLE_SCALE).ceil() as i32;

let rounded_std_dev = blur_std_deviation.round();
// The clipped field is the part of the picture that is visible
// on screen. The unclipped field is the screen-space rect of
// the complete picture, if no screen / clip-chain was applied
@@ -2965,10 +2965,13 @@ impl PicturePrimitive {
// blur results, inflate that clipped area by the blur range, and
// then intersect with the total screen rect, to minimize the
// allocation size.
let device_rect = clipped
.inflate(blur_range, blur_range)
.intersection(&unclipped.to_i32())
.unwrap();
let mut device_rect = clipped.inflate(blur_range, blur_range)
.intersection(&unclipped.to_i32())
.unwrap();
device_rect.size = RenderTask::adjusted_blur_source_size(
device_rect.size,
rounded_std_dev,
);

let uv_rect_kind = calculate_uv_rect_kind(
&pic_rect,
@@ -2992,7 +2995,7 @@ impl PicturePrimitive {
let picture_task_id = frame_state.render_tasks.add(picture_task);

let blur_render_task = RenderTask::new_blur(
blur_std_deviation.round(),
rounded_std_dev,
picture_task_id,
frame_state.render_tasks,
RenderTargetKind::Color,
@@ -626,6 +626,25 @@ impl RenderTask {
)
}

// In order to do the blur down-scaling passes without introducing errors, we need the
// source of each down-scale pass to be a multuple of two. If need be, this inflates
// the source size so that each down-scale pass will sample correctly.
pub fn adjusted_blur_source_size(original_size: DeviceIntSize, mut std_dev: f32) -> DeviceIntSize {
let mut adjusted_size = original_size;
let mut scale_factor = 1.0;
while std_dev > MAX_BLUR_STD_DEVIATION {
if adjusted_size.width < MIN_DOWNSCALING_RT_SIZE ||
adjusted_size.height < MIN_DOWNSCALING_RT_SIZE {
break;
}
std_dev *= 0.5;
scale_factor *= 2.0;
adjusted_size = (original_size.to_f32() / scale_factor).ceil().to_i32();
}

adjusted_size * scale_factor as i32
}

// Construct a render task to apply a blur to a primitive.
// The render task chain that is constructed looks like:
//
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.