Flutter Engine
The Flutter Engine
Public Member Functions | List of all members
GrBicubicEffect::Impl Class Reference
Inheritance diagram for GrBicubicEffect::Impl:
GrFragmentProcessor::ProgramImpl

Public Member Functions

void emitCode (EmitArgs &) override
 
- Public Member Functions inherited from GrFragmentProcessor::ProgramImpl
 ProgramImpl ()=default
 
virtual ~ProgramImpl ()=default
 
virtual void emitCode (EmitArgs &)=0
 
void setData (const GrGLSLProgramDataManager &pdman, const GrFragmentProcessor &processor)
 
int numChildProcessors () const
 
ProgramImplchildProcessor (int index) const
 
void setFunctionName (SkString name)
 
const char * functionName () const
 
SkString invokeChild (int childIndex, EmitArgs &parentArgs, std::string_view skslCoords={})
 
SkString invokeChildWithMatrix (int childIndex, EmitArgs &parentArgs)
 
SkString invokeChild (int childIndex, const char *inputColor, EmitArgs &parentArgs, std::string_view skslCoords={})
 
SkString invokeChildWithMatrix (int childIndex, const char *inputColor, EmitArgs &parentArgs)
 
SkString invokeChild (int childIndex, const char *inputColor, const char *destColor, EmitArgs &parentArgs, std::string_view skslCoords={})
 
SkString invokeChildWithMatrix (int childIndex, const char *inputColor, const char *destColor, EmitArgs &parentArgs)
 

Additional Inherited Members

- Public Types inherited from GrFragmentProcessor::ProgramImpl
using UniformHandle = GrGLSLUniformHandler::UniformHandle
 
using SamplerHandle = GrGLSLUniformHandler::SamplerHandle
 

Detailed Description

Definition at line 34 of file GrBicubicEffect.cpp.

Member Function Documentation

◆ emitCode()

void GrBicubicEffect::Impl::emitCode ( EmitArgs args)
overridevirtual

Implements GrFragmentProcessor::ProgramImpl.

Definition at line 45 of file GrBicubicEffect.cpp.

45 {
46 const GrBicubicEffect& bicubicEffect = args.fFp.cast<GrBicubicEffect>();
47
48 GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder;
49
50 const char* coeffs;
51 fCoefficientUni = args.fUniformHandler->addUniform(&args.fFp, kFragment_GrShaderFlag,
52 SkSLType::kHalf4x4, "coefficients", &coeffs);
53 // We determine our fractional offset (f) within the texel. We then snap coord to a texel
54 // center. The snap prevents cases where the starting coords are near a texel boundary and
55 // offsets with imperfect precision would cause us to skip/double hit a texel.
56 // The use of "texel" above is somewhat abstract as we're sampling a child processor. It is
57 // assumed the child processor represents something akin to a nearest neighbor sampled texture.
58 if (bicubicEffect.fDirection == GrBicubicEffect::Direction::kXY) {
59 fragBuilder->codeAppendf("float2 coord = %s - float2(0.5);", args.fSampleCoord);
60 fragBuilder->codeAppend("half2 f = half2(fract(coord));");
61 fragBuilder->codeAppend("coord += 0.5 - f;");
62 fragBuilder->codeAppendf("half4 wx = %s * half4(1.0, f.x, f.x * f.x, f.x * f.x * f.x);",
63 coeffs);
64 fragBuilder->codeAppendf("half4 wy = %s * half4(1.0, f.y, f.y * f.y, f.y * f.y * f.y);",
65 coeffs);
66 fragBuilder->codeAppend("half4 rowColors[4];");
67 for (int y = 0; y < 4; ++y) {
68 for (int x = 0; x < 4; ++x) {
69 auto coord = SkSL::String::printf("coord + float2(%d, %d)", x - 1, y - 1);
70 auto childStr = this->invokeChild(0, args, coord);
71 fragBuilder->codeAppendf("rowColors[%d] = %s;", x, childStr.c_str());
72 }
73 fragBuilder->codeAppendf(
74 "half4 s%d = wx.x * rowColors[0] + wx.y * rowColors[1] + wx.z * rowColors[2] + "
75 "wx.w * rowColors[3];",
76 y);
77 }
78 fragBuilder->codeAppend(
79 "half4 bicubicColor = wy.x * s0 + wy.y * s1 + wy.z * s2 + wy.w * s3;");
80 } else {
81 const char* d = bicubicEffect.fDirection == Direction::kX ? "x" : "y";
82 fragBuilder->codeAppendf("float coord = %s.%s - 0.5;", args.fSampleCoord, d);
83 fragBuilder->codeAppend("half f = half(fract(coord));");
84 fragBuilder->codeAppend("coord += 0.5 - f;");
85 fragBuilder->codeAppend("half f2 = f * f;");
86 fragBuilder->codeAppendf("half4 w = %s * half4(1.0, f, f2, f2 * f);", coeffs);
87 fragBuilder->codeAppend("half4 c[4];");
88 for (int i = 0; i < 4; ++i) {
89 std::string coord;
90 if (bicubicEffect.fDirection == Direction::kX) {
91 coord = SkSL::String::printf("float2(coord + %d, %s.y)", i - 1, args.fSampleCoord);
92 } else {
93 coord = SkSL::String::printf("float2(%s.x, coord + %d)", args.fSampleCoord, i - 1);
94 }
95 auto childStr = this->invokeChild(0, args, coord);
96 fragBuilder->codeAppendf("c[%d] = %s;", i, childStr.c_str());
97 }
98 fragBuilder->codeAppend(
99 "half4 bicubicColor = c[0] * w.x + c[1] * w.y + c[2] * w.z + c[3] * w.w;");
100 }
101 // Bicubic can send colors out of range, so clamp to get them back in (source) gamut.
102 // The kind of clamp we have to do depends on the alpha type.
103 switch (bicubicEffect.fClamp) {
104 case Clamp::kUnpremul:
105 fragBuilder->codeAppend("bicubicColor = saturate(bicubicColor);");
106 break;
107 case Clamp::kPremul:
108 fragBuilder->codeAppend("bicubicColor.a = saturate(bicubicColor.a);");
109 fragBuilder->codeAppend(
110 "bicubicColor.rgb = max(half3(0.0), min(bicubicColor.rgb, bicubicColor.aaa));");
111 break;
112 }
113 fragBuilder->codeAppendf("return bicubicColor;");
114}
@ kFragment_GrShaderFlag
Definition: GrTypesPriv.h:287
SkString invokeChild(int childIndex, EmitArgs &parentArgs, std::string_view skslCoords={})
VULKAN_HPP_DEFAULT_DISPATCH_LOADER_DYNAMIC_STORAGE auto & d
Definition: main.cc:19
G_BEGIN_DECLS G_MODULE_EXPORT FlValue * args
double y
double x
std::string printf(const char *fmt,...) SK_PRINTF_LIKE(1
Definition: SkSLString.cpp:83

The documentation for this class was generated from the following file: