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:
parent
974aad487a
commit
6b59bf424c
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -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:
|
||||
|
@ -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();
|
||||
|
@ -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) {
|
||||
|
@ -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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user