diff options
author | Mike Reed <reed@google.com> | 2017-07-05 12:33:06 -0400 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2017-07-05 16:56:24 +0000 |
commit | 7aad8cc2ff7a580bd5852d57289ace8c8dced6f5 (patch) | |
tree | 037fd3d1e11b69cb46d068a3ed4553904cde2e8d /src/core/SkRasterPipeline.cpp | |
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/SkRasterPipeline.cpp')
-rw-r--r-- | src/core/SkRasterPipeline.cpp | 43 |
1 files changed, 37 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); + } } } |