Avoid unnecessary saveLayer() in COLRv1 paint operations

Most of the COLRv1 paint operations only need the clip and matrix to be
kept on SkCanvas, only PaintComposite needs a full saveLayer().
Adjust calls accordingly.

Bug: skia:11851
Change-Id: I85b3c27495c78306457e17fea8062c957e2f3b05
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/395617
Auto-Submit: Dominik Röttsches <drott@chromium.org>
Commit-Queue: Ben Wagner <bungeman@google.com>
Reviewed-by: Ben Wagner <bungeman@google.com>
This commit is contained in:
Dominik Röttsches 2021-04-12 17:43:29 +03:00 committed by Skia Commit-Bot
parent ee49efcc91
commit e14d72500f

View File

@ -747,6 +747,7 @@ bool colrv1_traverse_paint(SkCanvas* canvas,
// Keep track of failures to retrieve the FT_COLR_Paint from FreeType in the
// recursion, cancel recursion when a paint retrieval fails.
bool traverse_result = true;
SkAutoCanvasRestore autoRestore(canvas, true /* do_save */);
switch (paint.format) {
case FT_COLR_PAINTFORMAT_COLR_LAYERS: {
FT_LayerIterator& layer_iterator = paint.u.colr_layers.layer_iterator;
@ -758,45 +759,34 @@ bool colrv1_traverse_paint(SkCanvas* canvas,
break;
}
case FT_COLR_PAINTFORMAT_GLYPH:
canvas->saveLayer(nullptr, nullptr);
// Traverse / draw operation will clip layer.
colrv1_draw_paint(canvas, palette, face, paint);
traverse_result = colrv1_traverse_paint(canvas, palette, face, paint.u.glyph.paint);
canvas->restore();
break;
case FT_COLR_PAINTFORMAT_COLR_GLYPH:
traverse_result = colrv1_start_glyph(canvas, palette, face, paint.u.colr_glyph.glyphID,
FT_COLOR_NO_ROOT_TRANSFORM);
break;
case FT_COLR_PAINTFORMAT_TRANSFORMED:
canvas->saveLayer(nullptr, nullptr);
// Traverse / draw operation will apply transform.
colrv1_draw_paint(canvas, palette, face, paint);
traverse_result =
colrv1_traverse_paint(canvas, palette, face, paint.u.transformed.paint);
canvas->restore();
break;
case FT_COLR_PAINTFORMAT_TRANSLATE:
canvas->saveLayer(nullptr, nullptr);
case FT_COLR_PAINTFORMAT_TRANSLATE:
// Traverse / draw operation will apply transform.
colrv1_draw_paint(canvas, palette, face, paint);
traverse_result =
colrv1_traverse_paint(canvas, palette, face, paint.u.translate.paint);
canvas->restore();
traverse_result = colrv1_traverse_paint(canvas, palette, face, paint.u.translate.paint);
break;
case FT_COLR_PAINTFORMAT_ROTATE:
canvas->saveLayer(nullptr, nullptr);
case FT_COLR_PAINTFORMAT_ROTATE:
// Traverse / draw operation will apply transform.
colrv1_draw_paint(canvas, palette, face, paint);
traverse_result = colrv1_traverse_paint(canvas, palette, face, paint.u.rotate.paint);
canvas->restore();
break;
case FT_COLR_PAINTFORMAT_SKEW:
canvas->saveLayer(nullptr, nullptr);
// Traverse / draw operation will apply transform.
colrv1_draw_paint(canvas, palette, face, paint);
traverse_result = colrv1_traverse_paint(canvas, palette, face, paint.u.skew.paint);
canvas->restore();
break;
case FT_COLR_PAINTFORMAT_COMPOSITE: {
traverse_result =