funnel all constant colors through append_constant_color()

My next step is to change the uniform_color context to

    struct {
       float r,g,b,a;
       uint32_t rgba;
    };

so that it's trivial to load in both float and 8-bit pipelines.

Change-Id: If9bdde353ced3bf9eb0c63204b4770ed614ad16b
Reviewed-on: https://skia-review.googlesource.com/30481
Reviewed-by: Florin Malita <fmalita@chromium.org>
Commit-Queue: Mike Klein <mtklein@chromium.org>
This commit is contained in:
Mike Klein 2017-08-03 10:22:42 -04:00 committed by Skia Commit-Bot
parent 073073e4a4
commit 16776dfb4b
6 changed files with 28 additions and 16 deletions

View File

@ -123,8 +123,9 @@ public:
SkColorSpaceTransferFn from_2dot2 = gamma( 2.2f),
to_2dot2 = gamma(1/2.2f);
SkRasterPipeline_<256> p;
p.append(SkRasterPipeline::uniform_color, &c);
SkSTArenaAlloc<256> alloc;
SkRasterPipeline p(&alloc);
p.append_constant_color(&alloc, c);
p.append(SkRasterPipeline::parametric_r, &from_2dot2);
p.append(SkRasterPipeline::parametric_g, &from_2dot2);
p.append(SkRasterPipeline::parametric_b, &from_2dot2);

View File

@ -167,8 +167,9 @@ static inline SkColor4f to_colorspace(const SkColor4f& c, SkColorSpace* src, SkC
float scratch_matrix_3x4[12];
SkRasterPipeline_<256> p;
p.append(SkRasterPipeline::uniform_color, &color4f);
SkSTArenaAlloc<256> alloc;
SkRasterPipeline p(&alloc);
p.append_constant_color(&alloc, color4f);
append_gamut_transform(&p, scratch_matrix_3x4, src, dst, kUnpremul_SkAlphaType);
p.append(SkRasterPipeline::store_f32, &color4f_ptr);

View File

@ -19,7 +19,8 @@ void SkRasterPipeline::reset() {
}
void SkRasterPipeline::append(StockStage stage, void* ctx) {
SkASSERT(stage != from_srgb);
SkASSERT(stage != from_srgb); // Please use append_from_srgb().
SkASSERT(stage != uniform_color); // Please use append_constant_color().
this->unchecked_append(stage, ctx);
}
void SkRasterPipeline::unchecked_append(StockStage stage, void* ctx) {
@ -78,17 +79,17 @@ void SkRasterPipeline::dump() const {
#define INC_COLOR
#endif
void SkRasterPipeline::append_constant_color(SkArenaAlloc* alloc, const SkPM4f& c) {
if (c.r() == 0 && c.g() == 0 && c.b() == 0 && c.a() == 1) {
void SkRasterPipeline::append_constant_color(SkArenaAlloc* alloc, const float rgba[4]) {
if (rgba[0] == 0 && rgba[1] == 0 && rgba[2] == 0 && rgba[3] == 1) {
this->append(black_color);
INC_BLACK;
} else if (c.r() == 1 && c.g() == 1 && c.b() == 1 && c.a() == 1) {
} else if (rgba[0] == 1 && rgba[1] == 1 && rgba[2] == 1 && rgba[3] == 1) {
this->append(white_color);
INC_WHITE;
} else {
float* storage = alloc->makeArray<float>(4);
memcpy(storage, c.fVec, 4 * sizeof(float));
this->append(uniform_color, storage);
memcpy(storage, rgba, 4 * sizeof(float));
this->unchecked_append(uniform_color, storage);
INC_COLOR;
}

View File

@ -11,6 +11,7 @@
#include "SkArenaAlloc.h"
#include "SkImageInfo.h"
#include "SkNx.h"
#include "SkPM4f.h"
#include "SkTArray.h"
#include "SkTypes.h"
#include <functional>
@ -18,7 +19,6 @@
struct SkJumper_constants;
struct SkJumper_Engine;
struct SkPM4f;
/**
* SkRasterPipeline provides a cheap way to chain together a pixel processing pipeline.
@ -135,7 +135,14 @@ public:
// Appends a stage for a constant uniform color.
// Tries to optimize the stage based on the color.
void append_constant_color(SkArenaAlloc*, const SkPM4f& color);
void append_constant_color(SkArenaAlloc*, const float rgba[4]);
void append_constant_color(SkArenaAlloc* alloc, const SkPM4f& color) {
this->append_constant_color(alloc, color.fVec);
}
void append_constant_color(SkArenaAlloc* alloc, const SkColor4f& color) {
this->append_constant_color(alloc, color.vec());
}
bool empty() const { return fStages == nullptr; }

View File

@ -71,8 +71,9 @@ DEF_TEST(sk_pipeline_srgb_edge_cases, r) {
SkJumper_MemoryCtx dst = { &color, 0 };
SkRasterPipeline_<256> p;
p.append(SkRasterPipeline::uniform_color, &color);
SkSTArenaAlloc<256> alloc;
SkRasterPipeline p(&alloc);
p.append_constant_color(&alloc, color);
p.append(SkRasterPipeline::to_srgb);
p.append(SkRasterPipeline::store_f32, &dst);
p.run(0,0,4,1);

View File

@ -282,8 +282,9 @@ DEF_TEST(SkRasterPipeline_repeat_tiling, r) {
float out[4 * SkJumper_kMaxStride];
SkJumper_TileCtx tile = { 9.0f, 1/9.0f };
SkRasterPipeline_<256> p;
p.append(SkRasterPipeline::uniform_color, in);
SkSTArenaAlloc<256> alloc;
SkRasterPipeline p(&alloc);
p.append_constant_color(&alloc, in);
p.append(SkRasterPipeline::repeat_x, &tile);
p.append(SkRasterPipeline::store_rgba, out);
p.run(0,0,1,1);