From eb50f434f0ff175153127875601e9bb3c0bfa5b5 Mon Sep 17 00:00:00 2001 From: Mike Klein Date: Fri, 7 Sep 2018 11:08:53 -0400 Subject: [PATCH] add clamp_gamut This should be cheaper in both float and lowp modes. Change-Id: If6bba3abd31990b622f010c8fcdebff3288c9d70 Reviewed-on: https://skia-review.googlesource.com/152581 Reviewed-by: Brian Osman Commit-Queue: Mike Klein --- src/core/SkRasterPipeline.h | 2 +- src/core/SkRasterPipelineBlitter.cpp | 4 +--- src/opts/SkRasterPipeline_opts.h | 12 ++++++++++++ 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/core/SkRasterPipeline.h b/src/core/SkRasterPipeline.h index be197e4c6e..d6372409b3 100644 --- a/src/core/SkRasterPipeline.h +++ b/src/core/SkRasterPipeline.h @@ -37,7 +37,7 @@ #define SK_RASTER_PIPELINE_STAGES(M) \ M(callback) \ M(move_src_dst) M(move_dst_src) \ - M(clamp_0) M(clamp_1) M(clamp_a) M(clamp_a_dst) \ + M(clamp_0) M(clamp_1) M(clamp_a) M(clamp_a_dst) M(clamp_gamut) \ M(unpremul) M(premul) M(premul_dst) \ M(force_opaque) M(force_opaque_dst) \ M(set_rgb) M(swap_rb) \ diff --git a/src/core/SkRasterPipelineBlitter.cpp b/src/core/SkRasterPipelineBlitter.cpp index 0ae6df3f0c..5e4ec64fea 100644 --- a/src/core/SkRasterPipelineBlitter.cpp +++ b/src/core/SkRasterPipelineBlitter.cpp @@ -97,9 +97,7 @@ static void append_color_pipeline(SkRasterPipeline* p, dstInfo.colorType() != kRGBA_F32_SkColorType && dstInfo.alphaType() == kPremul_SkAlphaType) { - // TODO: this will be common enough that we may want to fuse into ::clamp_premul. - p->append(SkRasterPipeline::clamp_0); - p->append(SkRasterPipeline::clamp_a); + p->append(SkRasterPipeline::clamp_gamut); } } diff --git a/src/opts/SkRasterPipeline_opts.h b/src/opts/SkRasterPipeline_opts.h index 0144becf83..fb1f6a099d 100644 --- a/src/opts/SkRasterPipeline_opts.h +++ b/src/opts/SkRasterPipeline_opts.h @@ -1276,6 +1276,13 @@ STAGE(clamp_a_dst, Ctx::None) { db = min(db, da); } +STAGE(clamp_gamut, Ctx::None) { + // If you're using this stage, a should already be in [0,1]. + r = min(max(r, 0), a); + g = min(max(g, 0), a); + b = min(max(b, 0), a); +} + STAGE(set_rgb, const float* rgb) { r = rgb[0]; g = rgb[1]; @@ -2573,6 +2580,11 @@ STAGE_PP(clamp_a_dst, Ctx::None) { db = min(db, da); } +STAGE_PP(clamp_gamut, Ctx::None) { + // It shouldn't be possible to get out-of-gamut + // colors when working in lowp. +} + STAGE_PP(premul, Ctx::None) { r = div255(r * a); g = div255(g * a);