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>
This commit is contained in:
Mike Reed 2017-07-03 21:26:44 -04:00 committed by Skia Commit-Bot
parent 974aad487a
commit 6b59bf424c
5 changed files with 19 additions and 21 deletions

View File

@ -82,3 +82,14 @@ void SkRasterPipeline::append_from_srgb_dst(SkAlphaType at) {
this->append(SkRasterPipeline::clamp_a_dst); 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);
}
}

View File

@ -127,6 +127,10 @@ public:
void append_from_srgb(SkAlphaType); void append_from_srgb(SkAlphaType);
void append_from_srgb_dst(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; } bool empty() const { return fStages == nullptr; }
private: private:

View File

@ -295,17 +295,11 @@ bool SkImageShader::onAppendStages(SkRasterPipeline* p, SkColorSpace* dstCS, SkA
struct MiscCtx { struct MiscCtx {
std::unique_ptr<SkBitmapController::State> state; std::unique_ptr<SkBitmapController::State> state;
SkColor4f paint_color; SkColor4f paint_color;
float matrix[9];
}; };
auto misc = alloc->make<MiscCtx>(); auto misc = alloc->make<MiscCtx>();
misc->state = std::move(state); // Extend lifetime to match the pipeline's. misc->state = std::move(state); // Extend lifetime to match the pipeline's.
misc->paint_color = SkColor4f_from_SkColor(paint.getColor(), dstCS); misc->paint_color = SkColor4f_from_SkColor(paint.getColor(), dstCS);
if (matrix.asAffine(misc->matrix)) { p->append_matrix(alloc, matrix);
p->append(SkRasterPipeline::matrix_2x3, misc->matrix);
} else {
matrix.get9(misc->matrix);
p->append(SkRasterPipeline::matrix_perspective, misc->matrix);
}
auto gather = alloc->make<SkJumper_GatherCtx>(); auto gather = alloc->make<SkJumper_GatherCtx>();
gather->pixels = pm.addr(); gather->pixels = pm.addr();

View File

@ -382,15 +382,7 @@ bool SkGradientShaderBase::onAppendStages(SkRasterPipeline* p,
} }
p->append(SkRasterPipeline::seed_shader); p->append(SkRasterPipeline::seed_shader);
p->append_matrix(alloc, matrix);
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->extend(tPipeline); p->extend(tPipeline);
switch(fTileMode) { switch(fTileMode) {

View File

@ -190,11 +190,8 @@ bool SkTwoPointConicalGradient::adjustMatrixAndAppendStages(SkArenaAlloc* alloc,
auto scale = fRadius2 / dRadius; auto scale = fRadius2 / dRadius;
auto bias = -fRadius1 / dRadius; auto bias = -fRadius1 / dRadius;
auto mad_matrix = SkMatrix::Concat(SkMatrix::MakeTrans(bias, 0), p->append_matrix(alloc, SkMatrix::Concat(SkMatrix::MakeTrans(bias, 0),
SkMatrix::MakeScale(scale, 1)); SkMatrix::MakeScale(scale, 1)));
auto m = alloc->makeArrayDefault<float>(6);
SkAssertResult(mad_matrix.asAffine(m));
p->append(SkRasterPipeline::matrix_2x3, m);
return true; return true;
} }