Factor out COLRv1 transforms to separate function

Preparation for optimizing the case of PaintGlyph + PaintSolid /
PaintGradient so that the remainder of the colrv1_draw_paint() function
can be turned into configuring an SkPaint.

Perform canvas CTM concatenation at the end of the function instead of
in each individual case as before.

No functional changes.

Bug: 11851
Change-Id: I04a77134d406f1625efebd5f623cfdbcca19b7cb
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/396036
Commit-Queue: Dominik Röttsches <drott@chromium.org>
Commit-Queue: Ben Wagner <bungeman@google.com>
Auto-Submit: Dominik Röttsches <drott@chromium.org>
Reviewed-by: Ben Wagner <bungeman@google.com>
This commit is contained in:
Dominik Röttsches 2021-04-13 21:49:54 +03:00 committed by Skia Commit-Bot
parent debcbbf6a8
commit ac04d95061

View File

@ -665,27 +665,39 @@ void colrv1_draw_paint(SkCanvas* canvas,
canvas->drawPaint(paint);
break;
}
case FT_COLR_PAINTFORMAT_TRANSFORMED: {
SkMatrix transform = ToSkMatrix(colrv1_paint.u.transformed.affine);
case FT_COLR_PAINTFORMAT_TRANSFORMED:
case FT_COLR_PAINTFORMAT_TRANSLATE:
case FT_COLR_PAINTFORMAT_ROTATE:
case FT_COLR_PAINTFORMAT_SKEW:
SkASSERT(false); // Transforms handled in colrv1_transform.
break;
default:
paint.setShader(nullptr);
paint.setColor(SK_ColorCYAN);
break;
}
}
canvas->concat(transform);
void colrv1_transform(SkCanvas* canvas, FT_Face face, FT_COLR_Paint colrv1_paint) {
SkMatrix transform;
switch (colrv1_paint.format) {
case FT_COLR_PAINTFORMAT_TRANSFORMED: {
transform = ToSkMatrix(colrv1_paint.u.transformed.affine);
break;
}
case FT_COLR_PAINTFORMAT_TRANSLATE: {
SkMatrix translate = SkMatrix::Translate(
transform = SkMatrix::Translate(
SkFixedToScalar(colrv1_paint.u.translate.dx),
-SkFixedToScalar(colrv1_paint.u.translate.dy));
canvas->concat(translate);
break;
}
case FT_COLR_PAINTFORMAT_ROTATE: {
SkMatrix rotation = SkMatrix::RotateDeg(
transform = SkMatrix::RotateDeg(
SkFixedToScalar(colrv1_paint.u.rotate.angle),
SkPoint::Make(SkFixedToScalar(colrv1_paint.u.rotate.center_x),
-SkFixedToScalar(colrv1_paint.u.rotate.center_y)));
canvas->concat(rotation);
break;
}
case FT_COLR_PAINTFORMAT_SKEW: {
@ -717,18 +729,18 @@ void colrv1_draw_paint(SkCanvas* canvas,
tan_y, 1, 0,
0, 0, 1);
SkMatrix skew = translate_from_origin.postConcat(skew_x).postConcat(skew_y).postConcat(translate_to_origin);
canvas->concat(skew);
transform = translate_from_origin.postConcat(skew_x).postConcat(skew_y).postConcat(translate_to_origin);
break;
}
default:
paint.setShader(nullptr);
paint.setColor(SK_ColorCYAN);
break;
default: {
// Only transforms are handled in this function.
SkASSERT(false);
}
}
canvas->concat(transform);
}
bool colrv1_start_glyph(SkCanvas* canvas,
const FT_Color* palette,
FT_Face ft_face,
@ -768,24 +780,20 @@ bool colrv1_traverse_paint(SkCanvas* canvas,
FT_COLOR_NO_ROOT_TRANSFORM);
break;
case FT_COLR_PAINTFORMAT_TRANSFORMED:
// Traverse / draw operation will apply transform.
colrv1_draw_paint(canvas, palette, face, paint);
colrv1_transform(canvas, face, paint);
traverse_result =
colrv1_traverse_paint(canvas, palette, face, paint.u.transformed.paint);
break;
case FT_COLR_PAINTFORMAT_TRANSLATE:
// Traverse / draw operation will apply transform.
colrv1_draw_paint(canvas, palette, face, paint);
colrv1_transform(canvas, face, paint);
traverse_result = colrv1_traverse_paint(canvas, palette, face, paint.u.translate.paint);
break;
case FT_COLR_PAINTFORMAT_ROTATE:
// Traverse / draw operation will apply transform.
colrv1_draw_paint(canvas, palette, face, paint);
colrv1_transform(canvas, face, paint);
traverse_result = colrv1_traverse_paint(canvas, palette, face, paint.u.rotate.paint);
break;
case FT_COLR_PAINTFORMAT_SKEW:
// Traverse / draw operation will apply transform.
colrv1_draw_paint(canvas, palette, face, paint);
colrv1_transform(canvas, face, paint);
traverse_result = colrv1_traverse_paint(canvas, palette, face, paint.u.skew.paint);
break;
case FT_COLR_PAINTFORMAT_COMPOSITE: {