diff options
author | Mike Klein <mtklein@chromium.org> | 2017-08-03 10:22:42 -0400 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2017-08-03 15:37:37 +0000 |
commit | 16776dfb4b307c70d08e316f2ecf2a53953f2e0d (patch) | |
tree | b95896287b957f1286a8f99c872fda9673def4ae | |
parent | 073073e4a49993818a7fc4996a7fb42f3ec79640 (diff) |
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>
-rw-r--r-- | bench/SkRasterPipelineBench.cpp | 5 | ||||
-rw-r--r-- | src/core/SkPM4fPriv.h | 5 | ||||
-rw-r--r-- | src/core/SkRasterPipeline.cpp | 13 | ||||
-rw-r--r-- | src/core/SkRasterPipeline.h | 11 | ||||
-rw-r--r-- | tests/SRGBTest.cpp | 5 | ||||
-rw-r--r-- | tests/SkRasterPipelineTest.cpp | 5 |
6 files changed, 28 insertions, 16 deletions
diff --git a/bench/SkRasterPipelineBench.cpp b/bench/SkRasterPipelineBench.cpp index 0df8086401..818ab2b447 100644 --- a/bench/SkRasterPipelineBench.cpp +++ b/bench/SkRasterPipelineBench.cpp @@ -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); diff --git a/src/core/SkPM4fPriv.h b/src/core/SkPM4fPriv.h index 0ded5e5116..be65159fb8 100644 --- a/src/core/SkPM4fPriv.h +++ b/src/core/SkPM4fPriv.h @@ -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); diff --git a/src/core/SkRasterPipeline.cpp b/src/core/SkRasterPipeline.cpp index bdb3795915..ba07467dfc 100644 --- a/src/core/SkRasterPipeline.cpp +++ b/src/core/SkRasterPipeline.cpp @@ -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; } diff --git a/src/core/SkRasterPipeline.h b/src/core/SkRasterPipeline.h index ff7bada24c..2a041d3a1e 100644 --- a/src/core/SkRasterPipeline.h +++ b/src/core/SkRasterPipeline.h @@ -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; } diff --git a/tests/SRGBTest.cpp b/tests/SRGBTest.cpp index 1db9eb306f..cda6fc410a 100644 --- a/tests/SRGBTest.cpp +++ b/tests/SRGBTest.cpp @@ -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); diff --git a/tests/SkRasterPipelineTest.cpp b/tests/SkRasterPipelineTest.cpp index 33e8b4fe15..6f707ce97e 100644 --- a/tests/SkRasterPipelineTest.cpp +++ b/tests/SkRasterPipelineTest.cpp @@ -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); |