Handle F16Norm clamping in SkPaint->GrPaint conversion.
Previously this clamping was inserted by the program builder.
Adds GrSaturateProcessor to handle saturating in the fragment shader.
Clamp the GrPaint color rather than using a fp when possible.
Has to be plumbed through GrTextureOp because that skips SkPaint
conversion.
Removes a usage of GrPixelConfig.
Bug: skia:6718
Change-Id: Ifa6544496d34677f17e797433e6ef3a97be5c2b2
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/242558
Reviewed-by: Michael Ludwig <michaelludwig@google.com>
Reviewed-by: Brian Osman <brianosman@google.com>
Commit-Queue: Brian Salomon <bsalomon@google.com>
diff --git a/src/gpu/SkGr.cpp b/src/gpu/SkGr.cpp
index 750e554..d105747 100644
--- a/src/gpu/SkGr.cpp
+++ b/src/gpu/SkGr.cpp
@@ -5,6 +5,8 @@
* found in the LICENSE file.
*/
+#include "src/gpu/SkGr.h"
+
#include "include/core/SkCanvas.h"
#include "include/core/SkColorFilter.h"
#include "include/core/SkData.h"
@@ -33,16 +35,15 @@
#include "src/gpu/GrRecordingContextPriv.h"
#include "src/gpu/GrTextureProxy.h"
#include "src/gpu/GrXferProcessor.h"
-#include "src/gpu/SkGr.h"
#include "src/gpu/effects/GrBicubicEffect.h"
#include "src/gpu/effects/GrPorterDuffXferProcessor.h"
#include "src/gpu/effects/GrSkSLFP.h"
#include "src/gpu/effects/GrXfermodeFragmentProcessor.h"
#include "src/gpu/effects/generated/GrConstColorProcessor.h"
+#include "src/gpu/effects/generated/GrSaturateProcessor.h"
#include "src/image/SkImage_Base.h"
#include "src/shaders/SkShaderBase.h"
-#if SK_SUPPORT_GPU
GR_FP_SRC_STRING SKSL_DITHER_SRC = R"(
// This controls the range of values added to color channels
layout(key) in int rangeType;
@@ -82,7 +83,6 @@
color = half4(clamp(color.rgb + value * range, 0.0, color.a), color.a);
}
)";
-#endif
GrSurfaceDesc GrImageInfoToSurfaceDesc(const SkImageInfo& info) {
GrSurfaceDesc desc;
@@ -472,6 +472,17 @@
}
}
#endif
+ if (GrColorTypeClampType(colorSpaceInfo.colorType()) == GrClampType::kManual) {
+ if (grPaint->numColorFragmentProcessors()) {
+ grPaint->addColorFragmentProcessor(GrSaturateProcessor::Make());
+ } else {
+ auto color = grPaint->getColor4f();
+ grPaint->setColor4f({SkTPin(color.fR, 0.f, 1.f),
+ SkTPin(color.fG, 0.f, 1.f),
+ SkTPin(color.fB, 0.f, 1.f),
+ SkTPin(color.fA, 0.f, 1.f)});
+ }
+ }
return true;
}