Skip to content

Commit

Permalink
Respect offset in OpacityLayer's paint bounds (#6826)
Browse files Browse the repository at this point in the history
This fixes flutter/flutter#23890

I'll add unit tests to flutter/flutter shortly.
  • Loading branch information
liyuqian authored Nov 12, 2018
1 parent 28e7002 commit b1b5891
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion flow/layers/opacity_layer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ void OpacityLayer::Preroll(PrerollContext* context, const SkMatrix& matrix) {
SkMatrix child_matrix = matrix;
child_matrix.postTranslate(offset_.fX, offset_.fY);
ContainerLayer::Preroll(context, child_matrix);
set_paint_bounds(paint_bounds().makeOffset(offset_.fX, offset_.fY));
if (context->raster_cache && layers().size() == 1) {
Layer* child = layers()[0].get();
SkMatrix ctm = child_matrix;
Expand Down Expand Up @@ -54,8 +55,22 @@ 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.
//
// Note that the following lines are only accessible when the raster cache is
// not available (e.g., when we're using the software backend in golden
// tests).
SkRect saveLayerBounds;
paint_bounds()
.makeOffset(-offset_.fX, -offset_.fY)
.roundOut(&saveLayerBounds);

Layer::AutoSaveLayer save_layer =
Layer::AutoSaveLayer::Create(context, paint_bounds(), &paint);
Layer::AutoSaveLayer::Create(context, saveLayerBounds, &paint);
PaintChildren(context);
}

Expand Down

0 comments on commit b1b5891

Please sign in to comment.