diff options
author | Mike Reed <reed@google.com> | 2017-07-03 21:26:44 -0400 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2017-07-04 01:48:12 +0000 |
commit | 6b59bf424c9d9d8a72d3c002871f143e6aff623e (patch) | |
tree | b534999fcdb00f07aeb86e9cd599bada966692c3 | |
parent | 974aad487a81e507ca9e953e0b7e016a42ba3c39 (diff) |
consolidate logic for matrix stage
Bug: skia:
Change-Id: Id1559b31692a1aed9aa4d15620b2019ae9c7c22b
Reviewed-on: https://skia-review.googlesource.com/21404
Commit-Queue: Mike Reed <reed@google.com>
Reviewed-by: Florin Malita <fmalita@chromium.org>
-rw-r--r-- | src/core/SkRasterPipeline.cpp | 11 | ||||
-rw-r--r-- | src/core/SkRasterPipeline.h | 4 | ||||
-rw-r--r-- | src/shaders/SkImageShader.cpp | 8 | ||||
-rw-r--r-- | src/shaders/gradients/SkGradientShader.cpp | 10 | ||||
-rw-r--r-- | src/shaders/gradients/SkTwoPointConicalGradient.cpp | 7 |
5 files changed, 19 insertions, 21 deletions
diff --git a/src/core/SkRasterPipeline.cpp b/src/core/SkRasterPipeline.cpp index 45d081bec5..6f5ae8c435 100644 --- a/src/core/SkRasterPipeline.cpp +++ b/src/core/SkRasterPipeline.cpp @@ -82,3 +82,14 @@ void SkRasterPipeline::append_from_srgb_dst(SkAlphaType at) { this->append(SkRasterPipeline::clamp_a_dst); } } + +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); + } else { + matrix.get9(storage); + this->append(SkRasterPipeline::matrix_perspective, storage); + } +} diff --git a/src/core/SkRasterPipeline.h b/src/core/SkRasterPipeline.h index a4175c65a8..9a467a5024 100644 --- a/src/core/SkRasterPipeline.h +++ b/src/core/SkRasterPipeline.h @@ -127,6 +127,10 @@ public: void append_from_srgb(SkAlphaType); void append_from_srgb_dst(SkAlphaType); + // Appends a stage for the specified matrix. Tries to optimize the stage by analyzing + // the type of matrix. + void append_matrix(SkArenaAlloc*, const SkMatrix&); + bool empty() const { return fStages == nullptr; } private: diff --git a/src/shaders/SkImageShader.cpp b/src/shaders/SkImageShader.cpp index 9538232cf0..064fe7b975 100644 --- a/src/shaders/SkImageShader.cpp +++ b/src/shaders/SkImageShader.cpp @@ -295,17 +295,11 @@ bool SkImageShader::onAppendStages(SkRasterPipeline* p, SkColorSpace* dstCS, SkA struct MiscCtx { std::unique_ptr<SkBitmapController::State> state; SkColor4f paint_color; - float matrix[9]; }; auto misc = alloc->make<MiscCtx>(); misc->state = std::move(state); // Extend lifetime to match the pipeline's. misc->paint_color = SkColor4f_from_SkColor(paint.getColor(), dstCS); - if (matrix.asAffine(misc->matrix)) { - p->append(SkRasterPipeline::matrix_2x3, misc->matrix); - } else { - matrix.get9(misc->matrix); - p->append(SkRasterPipeline::matrix_perspective, misc->matrix); - } + p->append_matrix(alloc, matrix); auto gather = alloc->make<SkJumper_GatherCtx>(); gather->pixels = pm.addr(); diff --git a/src/shaders/gradients/SkGradientShader.cpp b/src/shaders/gradients/SkGradientShader.cpp index 40da6940fe..6e952ae17f 100644 --- a/src/shaders/gradients/SkGradientShader.cpp +++ b/src/shaders/gradients/SkGradientShader.cpp @@ -382,15 +382,7 @@ bool SkGradientShaderBase::onAppendStages(SkRasterPipeline* p, } p->append(SkRasterPipeline::seed_shader); - - auto* m = alloc->makeArrayDefault<float>(9); - if (matrix.asAffine(m)) { - p->append(SkRasterPipeline::matrix_2x3, m); - } else { - matrix.get9(m); - p->append(SkRasterPipeline::matrix_perspective, m); - } - + p->append_matrix(alloc, matrix); p->extend(tPipeline); switch(fTileMode) { diff --git a/src/shaders/gradients/SkTwoPointConicalGradient.cpp b/src/shaders/gradients/SkTwoPointConicalGradient.cpp index f79e78c310..f355971e43 100644 --- a/src/shaders/gradients/SkTwoPointConicalGradient.cpp +++ b/src/shaders/gradients/SkTwoPointConicalGradient.cpp @@ -190,11 +190,8 @@ bool SkTwoPointConicalGradient::adjustMatrixAndAppendStages(SkArenaAlloc* alloc, auto scale = fRadius2 / dRadius; auto bias = -fRadius1 / dRadius; - auto mad_matrix = SkMatrix::Concat(SkMatrix::MakeTrans(bias, 0), - SkMatrix::MakeScale(scale, 1)); - auto m = alloc->makeArrayDefault<float>(6); - SkAssertResult(mad_matrix.asAffine(m)); - p->append(SkRasterPipeline::matrix_2x3, m); + p->append_matrix(alloc, SkMatrix::Concat(SkMatrix::MakeTrans(bias, 0), + SkMatrix::MakeScale(scale, 1))); return true; } |