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

Implementing Blur filter #5546

Merged
merged 1 commit into from Apr 16, 2015
Merged

Implementing Blur filter #5546

merged 1 commit into from Apr 16, 2015

Conversation

@Adenilson
Copy link
Contributor

Adenilson commented Apr 6, 2015

See discussion on #5190 and #5496.

Review on Reviewable

@hoppipolla-critic-bot
Copy link

hoppipolla-critic-bot commented Apr 6, 2015

Critic review: https://critic.hoppipolla.co.uk/r/4533

This is an external review system which you may optionally use for the code review of your pull request.

In order to help critic track your changes, please do not make in-place history rewrites (e.g. via git rebase -i or git commit --amend) when updating this pull request.

@Adenilson
Copy link
Contributor Author

Adenilson commented Apr 6, 2015

@SimonSapin and @pcwalton

I have one question about paint_context + StackingContext.

As was commented, it might be needed to adjust the overflow regions or (quote) “else display list optimization might clip out the edges of a blurred object”.

But reading the code, I noticed that the filters are only draw (e.g. http://mxr.mozilla.org/servo/source/components/gfx/paint_context.rs#923) way past the display list optimizer has executed (i.e. http://mxr.mozilla.org/servo/source/components/gfx/display_list/mod.rs#383).

If so, that would require changes on optimize_and_draw_into_context() i.ie to take into account the fact that there are filters before performing the display list optimization?

@Adenilson
Copy link
Contributor Author

Adenilson commented Apr 6, 2015

Testing with the following test case (used 512px as IIRC, that is the default tile size): https://gist.github.com/Adenilson/ae28080d9fc25bb64ff1

Got attached result. The clipping probably is responsible for the smaller size, but what about the white lines in the green rectangle?

ff_blur
servo_blur

@pcwalton
Copy link
Contributor

pcwalton commented Apr 6, 2015

@Adenilson That indicates that your intermediate draw target sizes are incorrect. The white lines are on tile boundaries (the sizes of which can be changed with the -s flag).

@pcwalton
Copy link
Contributor

pcwalton commented Apr 6, 2015

@Adenilson Looking at the box-shadow painting code may help, as it carefully deals with this problem. The idea is to inflate the intermediate draw target sizes by BLUR_INFLATION_FACTOR, overdraw in those regions, and then clip them out when blitting onto the final destination surface.

@Adenilson Adenilson force-pushed the Adenilson:blurFilter01 branch from 9f50249 to aae491a Apr 10, 2015
@Adenilson
Copy link
Contributor Author

Adenilson commented Apr 10, 2015

WIP.
screen shot 2015-04-10 at 10 33 12 am

@maxhoffmann
Copy link

maxhoffmann commented Apr 14, 2015

Some time ago I saw this video about color blurring being broken. Not sure if this is the right thread to mention it, but maybe Servo could be the first rendering engine to blur colors correctly? :)

https://www.youtube.com/watch?v=LKnqECcg6Gw

@SimonSapin
Copy link
Member

SimonSapin commented Apr 14, 2015

@maxhoffmann We (Servo) will not unilaterally implement a behavior incompatible with other browsers, however more correct it might be. This is a proposal for W3C.

That said, is the color-interpolation-filters property doing this already?

impl ToCss for SpecifiedFilter {
fn to_css<W>(&self, dest: &mut W) -> text_writer::Result where W: TextWriter {
match *self {
SpecifiedFilter::Blur(value) => try!(write!(dest, "blur({:?})", value)),

This comment has been minimized.

@SimonSapin

SimonSapin Apr 14, 2015

Member

{:?} is not necessarily doing the right formatting here. Use value.to_css(dest) instead, like hue-rotate(). I made a PR into your PR’s branch Adenilson#1. Merging it should automatically update this one.

@SimonSapin
Copy link
Member

SimonSapin commented Apr 14, 2015

r=me on the components/style changes if Adenilson#1 is included.

@maxhoffmann
Copy link

maxhoffmann commented Apr 14, 2015

@SimonSapin As far as I understand the video, the calculations of the blended colors are calculated wrongly independent of the color space, so the mentioned property wouldn’t fix that. Thanks for the quick answer.

@SimonSapin
Copy link
Member

SimonSapin commented Apr 14, 2015

“Square root everything” sounds a lot like a color space, but I don’t know. Regardless, rather than Servo just deviating from the spec, the right way to make this happen is to first discuss at W3C to change the spec. See “Feedback” at the top of http://dev.w3.org/fxtf/filters/

@Adenilson
Copy link
Contributor Author

Adenilson commented Apr 15, 2015

Related #5668.

// Pre-calculate if there is a blur expansion need.
let accum_blur = filters::calculate_accumulated_blur(filters);
let mut matrix = Matrix2D::identity();
if accum_blur > Au::new(0) {

This comment has been minimized.

@pcwalton

pcwalton Apr 15, 2015

Contributor

nit: I prefer just Au(0)


let temporary_draw_target =
self.draw_target.create_similar_draw_target(&size, self.draw_target.get_format());
temporary_draw_target.set_transform(&self.draw_target.get_transform());

if accum_blur > Au::new(0) {

This comment has been minimized.

@pcwalton

pcwalton Apr 15, 2015

Contributor

same here: Au(0)


// Pre-calculate if there is a blur expansion need.
let accum_blur = filters::calculate_accumulated_blur(filters);
let mut matrix = Matrix2D::identity();

This comment has been minimized.

@pcwalton

pcwalton Apr 15, 2015

Contributor

Why not just use let mut matrix = self.draw_target.get_transform();? Then you wouldn't need the second if accum_blur > Au(0) { ... below.

let (filter_node, opacity) = filters::create_filters(&self.draw_target,
temporary_draw_target,
filters);
filters, &mut accum_blur);

This comment has been minimized.

@pcwalton

pcwalton Apr 15, 2015

Contributor

nit: line up this argument with the others


// Create the Azure filter pipeline.
let mut accum_blur = Au::new(0);

This comment has been minimized.

@pcwalton

pcwalton Apr 15, 2015

Contributor

nit: Au(0)

self.draw_target.draw_filter(&filter_node, &rect, &rect.origin, draw_options);

// If there is a blur expansion, shift the transform and update the size.
if accum_blur > Au::new(0) {

This comment has been minimized.

@pcwalton

pcwalton Apr 15, 2015

Contributor

nit: Au(0)

let rect = Rect(Point2D(0, 0), size);
let side_inflation = accum_blur * BLUR_INFLATION_FACTOR;
let inflated_size = rect.inflate(side_inflation.to_nearest_px() as i32, side_inflation.to_nearest_px() as i32);
size = inflated_size.size;

This comment has been minimized.

@pcwalton

pcwalton Apr 15, 2015

Contributor

If you're just using the size part of the rect, why use a rect and inflate() at all? Isn't size = Size2D((side_inflation.to_nearest_px() * 2) as i32, (side_inflation.to_nearest_px() * 2) as i32 enough?

@pcwalton
Copy link
Contributor

pcwalton commented Apr 15, 2015

Looks good to me. Squash away!

@Adenilson Adenilson force-pushed the Adenilson:blurFilter01 branch from 691e7c7 to 05dd176 Apr 15, 2015
@Adenilson
Copy link
Contributor Author

Adenilson commented Apr 15, 2015

Done.

@pcwalton
Copy link
Contributor

pcwalton commented Apr 15, 2015

@bors-servo
Copy link
Contributor

bors-servo commented Apr 15, 2015

📌 Commit 05dd176 has been approved by pcwalton

@bors-servo
Copy link
Contributor

bors-servo commented Apr 15, 2015

Testing commit 05dd176 with merge 1fd6a48...

bors-servo pushed a commit that referenced this pull request Apr 15, 2015
See discussion on #5190 and #5496.

<!-- Reviewable:start -->
[<img src="https://reviewable.io/review_button.png" height=40 alt="Review on Reviewable"/>](https://reviewable.io/reviews/servo/servo/5546)
<!-- Reviewable:end -->
@bors-servo
Copy link
Contributor

bors-servo commented Apr 16, 2015

☀️ Test successful - android, gonk, linux1, linux2, mac1, mac2

@bors-servo bors-servo merged commit 05dd176 into servo:master Apr 16, 2015
2 checks passed
2 checks passed
continuous-integration/travis-ci/pr The Travis CI build passed
Details
homu Test successful
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

8 participants
You can’t perform that action at this time.