-
Notifications
You must be signed in to change notification settings - Fork 6k
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 layer integral offset snapping #17712
Conversation
Thank you! |
@@ -31,9 +31,6 @@ void ImageFilterLayer::Preroll(PrerollContext* context, | |||
if (!context->has_platform_view && context->raster_cache && | |||
SkRect::Intersects(context->cull_rect, paint_bounds())) { | |||
SkMatrix ctm = matrix; | |||
#ifndef SUPPORT_FRACTIONAL_TRANSLATION | |||
ctm = RasterCache::GetIntegralTransCTM(ctm); | |||
#endif | |||
context->raster_cache->Prepare(context, this, ctm); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For cases like these (and I'm guessing there are a large number of them, the ctm
local variable is unnecessary and should be deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done in #17915
@@ -31,9 +31,6 @@ void ImageFilterLayer::Preroll(PrerollContext* context, | |||
if (!context->has_platform_view && context->raster_cache && | |||
SkRect::Intersects(context->cull_rect, paint_bounds())) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How many of these if statements have identical tests? Could this be added as a boilerplate method either in the base Layer
or in the PrerollContext
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
context.leaf_nodes_canvas->setMatrix(RasterCache::GetIntegralTransCTM( | ||
context.leaf_nodes_canvas->getTotalMatrix())); | ||
#endif | ||
|
||
if (context.raster_cache) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similarly, is this all boilerplate for many layers?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done in #17791
@@ -51,9 +51,6 @@ void OpacityLayer::Preroll(PrerollContext* context, const SkMatrix& matrix) { | |||
if (!context->has_platform_view && context->raster_cache && | |||
SkRect::Intersects(context->cull_rect, paint_bounds())) { | |||
SkMatrix ctm = child_matrix; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ctm not needed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done in #17915
@@ -87,8 +79,7 @@ void OpacityLayer::Paint(PaintContext& context) const { | |||
// Skia may clip the content with saveLayerBounds (although it's not a | |||
// guaranteed clip). So we have to provide a big enough saveLayerBounds. To do | |||
// so, we first remove the offset from paint bounds since it's already in the | |||
// matrix. Then we round out the bounds because of our | |||
// RasterCache::GetIntegralTransCTM optimization. | |||
// matrix. Then we round out the bounds. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps we introduced the offset into the CTM prematurely above? If we hadn't already added it, we wouldn't have to adjust for it here...?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(aka line 70 in this method)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need the offset in ctm
to draw the raster cache correctly. Meanwhile, the offset is subtracted from the paint_bounds()
. We have to add the offset to paint_bounds()
because it will be used by its parent layer.
@@ -26,9 +26,6 @@ void PictureLayer::Preroll(PrerollContext* context, const SkMatrix& matrix) { | |||
|
|||
SkMatrix ctm = matrix; | |||
ctm.postTranslate(offset_.x(), offset_.y()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So, this is a counter-example for getting rid of the ctm local (that doesn't mean we shouldn't get rid of it in other methods where it really is superficial).
Is there something different about the way that picture_layer handles the offset that might benefit the other uses of the raster cache?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The difference seems to be that OpacityLayer
is using MutatorsStack
to track the offset due to possible PlatformView children.
Thanks @flar ! Will address your comments in a future PR! |
This seems to have broken flutter engine ios bot https://ci.chromium.org/p/flutter/builders/prod/Mac%20iOS%20Engine/4827 |
This reverts commit 99f8d00. I found some problems. Will revise and reland later, and put more details about the problems in the new PR. TBR: @chinmaygarde @flar
This reverts commit b5aedb3 and relands #17712. Fixes flutter/flutter#53288 and flutter/flutter#41654. Together with #17791, this reland addresses some of Jim's concerns in the original PR #17712. The major part of this PR is still the same as the original PR, and the performance / golden image impacts should be the same.
This fixes flutter/flutter#53288 and flutter/flutter#41654. It removes the problematic
GetIntegralTransCTM
, but preserves the rect round-out inRasterCacheResult::draw
for performance considerations: the average frame raster time doesn't change much but the worst frame raster time significantly regressed if rect round-out is removed. That's probably because a new shader needs to be compiled to draw raster cache with fractional offsets.Correctness test
The fixing of flutter/flutter#41654 is verified by running the unit test in flutter/flutter#41654 (comment) against the locally built engine. That unit test will be added to the framework repo once this PR is rolled into the framework.
This PR may change golden images so manual engine and google rolls may be required.
Performance test
The performance impact of this PR is measured by A/B testing the following framework devicelab test:
We tested 3 variants: (1) an engine without any change (2) an engine with this PR that removes integral snapping (3) an engine with both this PR, and additionally removes the rect round-out in
RasterCacheResult::draw
.The
average_frame_rasterizer_time_millis
of those 3 variants are as follows:The
worst_frame_rasterizer_time_millis
of those 3 variants are as follows:Here are full A/B test results:
RasterCacheResult::draw