41 const char*
name() const final {
return "tessellate_SimpleTriangleShader"; }
46std::unique_ptr<GrGeometryProcessor::ProgramImpl> SimpleTriangleShader::makeProgramImpl(
53 GrGPArgs* gpArgs)
override {
55 "float2 localcoord = inputPoint;"
56 "float2 vertexpos = AFFINE_MATRIX * localcoord + TRANSLATE;");
61 return std::make_unique<Impl>();
85 if (fAttribs & PatchAttribs::kFanPoint) {
86 fInstanceAttribs.emplace_back(
"fanPointAttrib",
91 fInstanceAttribs.emplace_back(
"colorAttrib",
92 (fAttribs & PatchAttribs::kWideColorIfEnabled)
97 if (fAttribs & PatchAttribs::kExplicitCurveType) {
104 fInstanceAttribs.size());
105 SkASSERT(fInstanceAttribs.size() <= kMaxInstanceAttribCount);
115 const char*
name() const final {
return "tessellate_MiddleOutShader"; }
121 b->add32((uint32_t)(fAttribs & ~PatchAttribs::kWideColorIfEnabled));
125 constexpr static int kMaxInstanceAttribCount = 5;
129std::unique_ptr<GrGeometryProcessor::ProgramImpl> MiddleOutShader::makeProgramImpl(
136 GrGPArgs* gpArgs)
override {
137 const MiddleOutShader& middleOutShader = shader.
cast<MiddleOutShader>();
144 if (middleOutShader.fAttribs & PatchAttribs::kExplicitCurveType) {
146 "bool is_conic_curve() {"
147 "return curveType != %g;"
150 "bool is_triangular_conic_curve() {"
151 "return curveType == %g;"
156 "bool is_conic_curve() { return isinf(p23.w); }"
157 "bool is_triangular_conic_curve() { return isinf(p23.z); }");
161 "float ldexp_portable(float x, float p) {"
162 "return ldexp(x, int(p));"
166 "float ldexp_portable(float x, float p) {"
167 "return x * exp2(p);"
171 "float resolveLevel = resolveLevel_and_idx.x;"
172 "float idxInResolveLevel = resolveLevel_and_idx.y;"
173 "float2 localcoord;");
174 if (middleOutShader.fAttribs & PatchAttribs::kFanPoint) {
177 "if (resolveLevel < 0) {"
178 "localcoord = fanPointAttrib;"
182 "if (is_triangular_conic_curve()) {"
184 "localcoord = (resolveLevel != 0) ? p01.zw"
185 ": (idxInResolveLevel != 0) ? p23.xy"
188 "float2 p0=p01.xy, p1=p01.zw, p2=p23.xy, p3=p23.zw;"
190 "float maxResolveLevel;"
191 "if (is_conic_curve()) {"
194 "maxResolveLevel = wangs_formula_conic_log2(PRECISION, AFFINE_MATRIX * p0,"
195 "AFFINE_MATRIX * p1,"
196 "AFFINE_MATRIX * p2, w);"
201 "maxResolveLevel = wangs_formula_cubic_log2(PRECISION, p0, p1, p2, p3,"
204 "if (resolveLevel > maxResolveLevel) {"
207 "idxInResolveLevel = floor(ldexp_portable(idxInResolveLevel,"
208 "maxResolveLevel - resolveLevel));"
209 "resolveLevel = maxResolveLevel;"
215 "float fixedVertexID = floor(.5 + ldexp_portable("
216 "idxInResolveLevel, MAX_FIXED_RESOLVE_LEVEL - resolveLevel));"
217 "if (0 < fixedVertexID && fixedVertexID < MAX_FIXED_SEGMENTS) {"
218 "float T = fixedVertexID * (1 / MAX_FIXED_SEGMENTS);"
221 "float2 ab = mix(p0, p1, T);"
222 "float2 bc = mix(p1, p2, T);"
223 "float2 cd = mix(p2, p3, T);"
224 "float2 abc = mix(ab, bc, T);"
225 "float2 bcd = mix(bc, cd, T);"
226 "float2 abcd = mix(abc, bcd, T);"
229 "float u = mix(1.0, w, T);"
230 "float v = w + 1 - u;"
231 "float uv = mix(u, v, T);"
233 "localcoord = (w < 0) ?" "abcd:" "abc/uv;"
235 "localcoord = (fixedVertexID == 0) ? p0.xy : p3.xy;"
238 "float2 vertexpos = AFFINE_MATRIX * localcoord + TRANSLATE;");
246 v->
codeAppendf(
"%s = colorAttrib;", colorVarying.vsOut());
247 fVaryingColorName = colorVarying.fsIn();
251 return std::make_unique<Impl>();
289"float3 safe_mix(float3 a, float3 b, float T, float one_minus_T) {"
290 "return a*one_minus_T + b*T;"
292"float2 eval_rational_cubic(float4x3 P, float T) {"
293 "float one_minus_T = 1.0 - T;"
294 "float3 ab = safe_mix(P[0], P[1], T, one_minus_T);"
295 "float3 bc = safe_mix(P[1], P[2], T, one_minus_T);"
296 "float3 cd = safe_mix(P[2], P[3], T, one_minus_T);"
297 "float3 abc = safe_mix(ab, bc, T, one_minus_T);"
298 "float3 bcd = safe_mix(bc, cd, T, one_minus_T);"
299 "float3 abcd = safe_mix(abc, bcd, T, one_minus_T);"
300 "return abcd.xy / abcd.z;"
305 args.fVaryingHandler->emitAttributes(shader);
308 const char* affineMatrix, *translate;
314 args.fVertBuilder->codeAppendf(
"float2x2 AFFINE_MATRIX = float2x2(%s.xy, %s.zw);",
315 affineMatrix, affineMatrix);
316 args.fVertBuilder->codeAppendf(
"float2 TRANSLATE = %s;", translate);
320 args.fVaryingHandler,
328 args.fFragBuilder->codeAppendf(
"half4 %s = %s;",
args.fOutputColor,
color);
330 args.fFragBuilder->codeAppendf(
"half4 %s = %s;",
333 args.fFragBuilder->codeAppendf(
"const half4 %s = half4(1);",
args.fOutputCoverage);
340 pdman.
set4f(fAffineMatrixUniform,
m.getScaleX(),
m.getSkewY(),
m.getSkewX(),
m.getScaleY());
341 pdman.
set2f(fTranslateUniform,
m.getTranslateX(),
m.getTranslateY());
static constexpr SkColor kColor
@ kFloat2_GrVertexAttribType
@ kUByte4_norm_GrVertexAttribType
@ kFloat_GrVertexAttribType
@ kFloat4_GrVertexAttribType
SK_API SkString SkStringPrintf(const char *format,...) SK_PRINTF_LIKE(1
Creates a new string and writes into it using a printf()-style format.
static sk_sp< const GrXferProcessor > MakeXferProcessor()
virtual void set2f(UniformHandle, float, float) const =0
virtual void set4f(UniformHandle, float, float, float, float) const =0
void defineConstant(const char *type, const char *name, const char *value)
void codeAppend(const char *str)
void codeAppendf(const char format[],...) SK_PRINTF_LIKE(2
void addVarying(const char *name, GrGLSLVarying *varying, Interpolation=Interpolation::kInterpolated)
void insertFunction(const char *functionDefinition)
void setInstanceAttributesWithImplicitOffsets(const Attribute *attrs, int attrCount)
virtual std::unique_ptr< ProgramImpl > makeProgramImpl(const GrShaderCaps &) const =0
virtual void addToKey(const GrShaderCaps &, skgpu::KeyBuilder *) const =0
size_t instanceStride() const
void setVertexAttributesWithImplicitOffsets(const Attribute *attrs, int attrCount)
GrGLSLUniformHandler::UniformHandle fTranslateUniform
void setData(const GrGLSLProgramDataManager &, const GrShaderCaps &, const GrGeometryProcessor &) override
static const char * kEvalRationalCubicFn
GrGLSLUniformHandler::UniformHandle fAffineMatrixUniform
virtual void emitVertexCode(const GrShaderCaps &, const GrPathTessellationShader &, GrGLSLVertexBuilder *, GrGLSLVaryingHandler *, GrGPArgs *)=0
void onEmitCode(EmitArgs &, GrGPArgs *) final
GrGLSLUniformHandler::UniformHandle fColorUniform
SkString fVaryingColorName
static GrPathTessellationShader * MakeSimpleTriangleShader(SkArenaAlloc *, const SkMatrix &viewMatrix, const SkPMColor4f &)
static const GrPipeline * MakeStencilOnlyPipeline(const ProgramArgs &, GrAAType, const GrAppliedHardClip &, GrPipeline::InputFlags=GrPipeline::InputFlags::kNone)
const PatchAttribs fAttribs
static GrPathTessellationShader * Make(const GrShaderCaps &, SkArenaAlloc *, const SkMatrix &viewMatrix, const SkPMColor4f &, PatchAttribs)
virtual const char * name() const =0
static const char * WangsFormulaSkSL()
const SkPMColor4f & color() const
const SkMatrix & viewMatrix() const
auto make(Ctor &&ctor) -> decltype(ctor(nullptr))
const char * c_str() const
G_BEGIN_DECLS G_MODULE_EXPORT FlValue * args
static constexpr float kTriangularConicCurveType
static constexpr int kMaxResolveLevel
constexpr size_t PatchAttribsStride(PatchAttribs attribs)
static constexpr float kPrecision
static constexpr float kCubicCurveType
static constexpr int kMaxParametricSegments
const GrShaderCaps * fShaderCaps
bool fBitManipulationSupport