diff options
author | 2017-07-05 12:33:06 -0400 | |
---|---|---|
committer | 2017-07-05 16:56:24 +0000 | |
commit | 7aad8cc2ff7a580bd5852d57289ace8c8dced6f5 (patch) | |
tree | 037fd3d1e11b69cb46d068a3ed4553904cde2e8d /src/core | |
parent | 1efedd948d909e6987e123a651652d48fb6e2c11 (diff) |
optimize for diff matrix types
Bug: skia:
Change-Id: I671e07c5bbb9e4ced92303c9959143324f7a6bdc
Reviewed-on: https://skia-review.googlesource.com/21523
Commit-Queue: Mike Reed <reed@google.com>
Reviewed-by: Herb Derby <herb@google.com>
Diffstat (limited to 'src/core')
-rw-r--r-- | src/core/SkRasterPipeline.cpp | 43 | ||||
-rw-r--r-- | src/core/SkRasterPipeline.h | 1 |
2 files changed, 38 insertions, 6 deletions
diff --git a/src/core/SkRasterPipeline.cpp b/src/core/SkRasterPipeline.cpp index 6f5ae8c435..05fa75f062 100644 --- a/src/core/SkRasterPipeline.cpp +++ b/src/core/SkRasterPipeline.cpp @@ -83,13 +83,44 @@ void SkRasterPipeline::append_from_srgb_dst(SkAlphaType at) { } } +//static int gCounts[5] = { 0, 0, 0, 0, 0 }; + void SkRasterPipeline::append_matrix(SkArenaAlloc* alloc, const SkMatrix& matrix) { - float* storage = alloc->makeArray<float>(9); - // TODO: consider adding special stages for scale+translate and possibly just translate. - if (matrix.asAffine(storage)) { - this->append(SkRasterPipeline::matrix_2x3, storage); + SkMatrix::TypeMask mt = matrix.getType(); +#if 0 + if (mt > 4) mt = 4; + gCounts[mt] += 1; + SkDebugf("matrices: %d %d %d %d %d\n", + gCounts[0], gCounts[1], gCounts[2], gCounts[3], gCounts[4]); +#endif + + // Based on a histogram of skps, we determined the following special cases were common, more + // or fewer can be used if client behaviors change. + + if (mt == SkMatrix::kIdentity_Mask) { + return; + } + if (mt == SkMatrix::kTranslate_Mask) { + float* trans = alloc->makeArrayDefault<float>(2); + trans[0] = matrix.getTranslateX(); + trans[1] = matrix.getTranslateY(); + this->append(SkRasterPipeline::matrix_translate, trans); + } else if ((mt | (SkMatrix::kScale_Mask | SkMatrix::kTranslate_Mask)) == + (SkMatrix::kScale_Mask | SkMatrix::kTranslate_Mask)) { + float* scaleTrans = alloc->makeArrayDefault<float>(4); + scaleTrans[0] = matrix.getTranslateX(); + scaleTrans[1] = matrix.getTranslateY(); + scaleTrans[2] = matrix.getScaleX(); + scaleTrans[3] = matrix.getScaleY(); + this->append(SkRasterPipeline::matrix_scale_translate, scaleTrans); } else { - matrix.get9(storage); - this->append(SkRasterPipeline::matrix_perspective, storage); + float* storage = alloc->makeArrayDefault<float>(9); + if (matrix.asAffine(storage)) { + // note: asAffine and the 2x3 stage really only need 6 entries + this->append(SkRasterPipeline::matrix_2x3, storage); + } else { + matrix.get9(storage); + this->append(SkRasterPipeline::matrix_perspective, storage); + } } } diff --git a/src/core/SkRasterPipeline.h b/src/core/SkRasterPipeline.h index 9a467a5024..2374201e05 100644 --- a/src/core/SkRasterPipeline.h +++ b/src/core/SkRasterPipeline.h @@ -65,6 +65,7 @@ struct SkJumper_constants; M(hue) M(saturation) M(color) M(luminosity) \ M(srcover_rgba_8888) \ M(luminance_to_alpha) \ + M(matrix_translate) M(matrix_scale_translate) \ M(matrix_2x3) M(matrix_3x4) M(matrix_4x5) M(matrix_4x3) \ M(matrix_perspective) \ M(parametric_r) M(parametric_g) M(parametric_b) \ |