CanOverflow -> ClampIfNeeded

Centralize the clamping in ClampIfNeeded, and switch it to clamp_1.

Change-Id: I056ac029d3ddc81e3f0f194f2b9c9924cad4caae
Reviewed-on: https://skia-review.googlesource.com/19401
Commit-Queue: Mike Klein <mtklein@google.com>
Reviewed-by: Mike Reed <reed@google.com>
This commit is contained in:
Mike Klein 2017-06-09 15:58:37 -04:00 committed by Skia Commit-Bot
parent 06e547cb5f
commit cb3ceb79cb
5 changed files with 21 additions and 24 deletions

View File

@ -8,10 +8,6 @@
#include "SkBlendModePriv.h"
#include "SkRasterPipeline.h"
bool SkBlendMode_CanOverflow(SkBlendMode mode) {
return mode == SkBlendMode::kPlus;
}
bool SkBlendMode_SupportsCoverageAsAlpha(SkBlendMode mode) {
switch (mode) {
case SkBlendMode::kDst:
@ -65,7 +61,7 @@ bool SkBlendMode_AsCoeff(SkBlendMode mode, SkBlendModeCoeff* src, SkBlendModeCoe
return true;
}
void SkBlendMode_AppendStages(SkBlendMode mode, SkRasterPipeline* p) {
void SkBlendMode_AppendStagesNoClamp(SkBlendMode mode, SkRasterPipeline* p) {
auto stage = SkRasterPipeline::srcover;
switch (mode) {
case SkBlendMode::kClear: stage = SkRasterPipeline::clear; break;
@ -103,6 +99,14 @@ void SkBlendMode_AppendStages(SkBlendMode mode, SkRasterPipeline* p) {
p->append(stage);
}
void SkBlendMode_AppendClampIfNeeded(SkBlendMode mode, SkRasterPipeline* p) {
if (mode == SkBlendMode::kPlus) {
// Both clamp_a and clamp_1 would preserve premultiplication invariants here,
// so we pick clamp_1 for being a smidge faster.
p->append(SkRasterPipeline::clamp_1);
}
}
SkPM4f SkBlendMode_Apply(SkBlendMode mode, SkPM4f src, SkPM4f dst) {
// special-case simple/common modes...
switch (mode) {
@ -123,9 +127,6 @@ SkPM4f SkBlendMode_Apply(SkBlendMode mode, SkPM4f src, SkPM4f dst) {
p.append(SkRasterPipeline::move_src_dst);
p.append(SkRasterPipeline::load_f32, &src_ctx);
SkBlendMode_AppendStages(mode, &p);
if (SkBlendMode_CanOverflow(mode)) {
p.append(SkRasterPipeline::clamp_1);
}
p.append(SkRasterPipeline::store_f32, &dst_ctx);
p.run(0, 0, 1);
return dst;

View File

@ -14,8 +14,15 @@
class SkRasterPipeline;
bool SkBlendMode_SupportsCoverageAsAlpha(SkBlendMode);
bool SkBlendMode_CanOverflow(SkBlendMode);
void SkBlendMode_AppendStages(SkBlendMode, SkRasterPipeline*);
void SkBlendMode_AppendStagesNoClamp(SkBlendMode, SkRasterPipeline*);
void SkBlendMode_AppendClampIfNeeded(SkBlendMode, SkRasterPipeline*);
static inline void SkBlendMode_AppendStages(SkBlendMode mode, SkRasterPipeline* p) {
// Only plus clamps, so maybe append a clamping plus here instead of a second stage?
SkBlendMode_AppendStagesNoClamp(mode, p);
SkBlendMode_AppendClampIfNeeded(mode, p);
}
#if SK_SUPPORT_GPU
#include "GrXferProcessor.h"

View File

@ -89,11 +89,7 @@ void SkModeColorFilter::onAppendStages(SkRasterPipeline* p,
p->append(SkRasterPipeline::move_src_dst);
p->append(SkRasterPipeline::constant_color, color);
auto mode = (SkBlendMode)fMode;
SkBlendMode_AppendStages(mode, p);
if (SkBlendMode_CanOverflow(mode)) {
p->append(SkRasterPipeline::clamp_a);
}
SkBlendMode_AppendStages(fMode, p);
}
sk_sp<SkColorFilter> SkModeColorFilter::onMakeColorSpace(SkColorSpaceXformer* xformer) const {

View File

@ -268,13 +268,11 @@ void SkRasterPipelineBlitter::append_store(SkRasterPipeline* p) const {
}
void SkRasterPipelineBlitter::append_blend(SkRasterPipeline* p) const {
SkBlendMode_AppendStages(fBlend, p);
SkBlendMode_AppendStagesNoClamp(fBlend, p);
}
void SkRasterPipelineBlitter::maybe_clamp(SkRasterPipeline* p) const {
if (SkBlendMode_CanOverflow(fBlend)) {
p->append(SkRasterPipeline::clamp_a);
}
SkBlendMode_AppendClampIfNeeded(fBlend, p);
}
void SkRasterPipelineBlitter::maybe_shade(int x, int y, int w) {

View File

@ -110,12 +110,7 @@ bool SkComposeShader::onAppendStages(SkRasterPipeline* pipeline, SkColorSpace* d
pipeline->append(SkRasterPipeline::load_rgba, storage->fRGBA);
if (!this->isJustLerp()) {
// Idea: should time this, and see if it helps to have custom versions of the overflow modes
// that do their own clamping, avoiding the overhead of an extra stage.
SkBlendMode_AppendStages(fMode, pipeline);
if (SkBlendMode_CanOverflow(fMode)) {
pipeline->append(SkRasterPipeline::clamp_a);
}
}
if (!this->isJustMode()) {
pipeline->append(SkRasterPipeline::lerp_1_float, &fLerpT);