54 bool localCoordsWillBeRead,
56 return arena->
make([&](
void* ptr) {
58 localCoordsWillBeRead);
62 const char*
name()
const override {
return "DefaultGeometryProcessor"; }
65 uint32_t
key = fFlags;
66 key |= fCoverage == 0xff ? 0x80 : 0;
67 key |= fLocalCoordsWillBeRead ? 0x100 : 0;
69 bool usesLocalMatrix = fLocalCoordsWillBeRead && !fInLocalCoords.
isInitialized();
78 return std::make_unique<Impl>();
89 SetTransform(pdman, shaderCaps, fViewMatrixUniform, dgp.fViewMatrix, &fViewMatrixPrev);
96 if (!dgp.hasVertexColor() && dgp.fColor != fColor) {
97 pdman.
set4fv(fColorUniform, 1, dgp.fColor.
vec());
101 if (dgp.fCoverage != fCoverage && !dgp.hasVertexCoverage()) {
108 void onEmitCode(EmitArgs&
args, GrGPArgs* gpArgs)
override {
120 SkASSERT(!tweakAlpha || gp.hasVertexCoverage());
121 SkASSERT(!tweakAlpha || !coverageNeedsSaturate);
125 if (gp.hasVertexColor() || tweakAlpha) {
127 varyingHandler->
addVarying(
"color", &varying);
130 if (gp.hasVertexColor()) {
131 vertBuilder->codeAppendf(
"half4 color = %s;", gp.fInColor.
name());
133 const char* colorUniformName;
134 fColorUniform = uniformHandler->
addUniform(
nullptr,
139 vertBuilder->codeAppendf(
"half4 color = %s;", colorUniformName);
144 vertBuilder->codeAppendf(
"color = color * %s;", gp.fInCoverage.
name());
146 vertBuilder->codeAppendf(
"%s = color;\n", varying.vsOut());
147 fragBuilder->
codeAppendf(
"%s = %s;",
args.fOutputColor, varying.fsIn());
158 gp.fInPosition.
name(),
160 &fViewMatrixUniform);
165 gpArgs->fLocalCoordVar = gp.fInLocalCoords.
asShaderVar();
166 }
else if (gp.fLocalCoordsWillBeRead) {
173 &fLocalMatrixUniform);
177 if (gp.hasVertexCoverage() && !tweakAlpha) {
180 if (coverageNeedsSaturate) {
181 fragBuilder->
codeAppendf(
"half4 %s = half4(saturate(alpha));",
182 args.fOutputCoverage);
184 fragBuilder->
codeAppendf(
"half4 %s = half4(alpha);",
args.fOutputCoverage);
186 }
else if (gp.fCoverage == 0xff) {
187 fragBuilder->
codeAppendf(
"const half4 %s = half4(1);",
args.fOutputCoverage);
189 const char* fragCoverage;
190 fCoverageUniform = uniformHandler->
addUniform(
nullptr,
196 args.fOutputCoverage, fragCoverage);
211 bool hasVertexColor()
const {
return fInColor.
isInitialized(); }
212 bool hasVertexCoverage()
const {
return fInCoverage.
isInitialized(); }
219 bool localCoordsWillBeRead)
222 , fViewMatrix(viewMatrix)
223 , fLocalMatrix(localMatrix)
225 , fFlags(gpTypeFlags)
226 , fLocalCoordsWillBeRead(localCoordsWillBeRead) {
251 bool fLocalCoordsWillBeRead;
260#if defined(GR_TEST_UTILS)
263 if (
d->fRandom->nextBool()) {
266 if (
d->fRandom->nextBool()) {
269 if (
d->fRandom->nextBool()) {
271 if (
d->fRandom->nextBool()) {
276 if (
d->fRandom->nextBool()) {
281 SkMatrix viewMtx = GrTest::TestMatrix(
d->fRandom);
282 SkMatrix localMtx = GrTest::TestMatrix(
d->fRandom);
283 bool readsLocalCoords =
d->fRandom->nextBool();
284 uint8_t
coverage = GrTest::RandomCoverage(
d->fRandom);
301 if (Color::kPremulGrColorAttribute_Type ==
color.fType) {
303 }
else if (Color::kPremulWideColorAttribute_Type ==
color.fType) {
306 if (Coverage::kAttribute_Type ==
coverage.fType) {
308 }
else if (Coverage::kAttributeTweakAlpha_Type ==
coverage.fType) {
310 }
else if (Coverage::kAttributeUnclamped_Type ==
coverage.fType) {
315 uint8_t inCoverage =
coverage.fCoverage;
316 bool localCoordsWillBeRead = localCoords.
fType != LocalCoords::kUnused_Type;
323 localCoordsWillBeRead,
333 if (LocalCoords::kUnused_Type != localCoords.
fType) {
334 SkASSERT(LocalCoords::kUsePosition_Type == localCoords.
fType);
static float GrNormalizeByteToFloat(uint8_t value)
@ kCoverageAttributeUnclamped_GPFlag
@ kCoverageAttribute_GPFlag
@ kCoverageAttributeTweak_GPFlag
@ kLocalCoordAttribute_GPFlag
@ kColorAttributeIsWide_GPFlag
#define GR_DECLARE_GEOMETRY_PROCESSOR_TEST
#define GR_DEFINE_GEOMETRY_PROCESSOR_TEST(...)
@ kFloat2_GrVertexAttribType
@ kFloat_GrVertexAttribType
constexpr SkPMColor4f SK_PMColor4fILLEGAL
static constexpr bool SkToBool(const T &x)
const char * name() const override
void addToKey(const GrShaderCaps &caps, skgpu::KeyBuilder *b) const override
std::unique_ptr< ProgramImpl > makeProgramImpl(const GrShaderCaps &) const override
static GrGeometryProcessor * Make(SkArenaAlloc *arena, uint32_t gpTypeFlags, const SkPMColor4f &color, const SkMatrix &viewMatrix, const SkMatrix &localMatrix, bool localCoordsWillBeRead, uint8_t coverage)
virtual void set4fv(UniformHandle, int arrayCount, const float v[]) const =0
virtual void set1f(UniformHandle, float v0) const =0
void codeAppendf(const char format[],...) SK_PRINTF_LIKE(2
void emitAttributes(const GrGeometryProcessor &)
void addPassThroughAttribute(const GrShaderVar &vsVar, const char *output, Interpolation=Interpolation::kInterpolated)
void addVarying(const char *name, GrGLSLVarying *varying, Interpolation=Interpolation::kInterpolated)
GrShaderVar asShaderVar() const
constexpr bool isInitialized() const
constexpr const char * name() const
void setupUniformColor(GrGLSLFPFragmentBuilder *fragBuilder, GrGLSLUniformHandler *uniformHandler, const char *outputName, UniformHandle *colorUniform)
GrGLSLProgramDataManager::UniformHandle UniformHandle
static uint32_t AddMatrixKeys(const GrShaderCaps &shaderCaps, uint32_t flags, const SkMatrix &viewMatrix, const SkMatrix &localMatrix)
static void WriteOutputPosition(GrGLSLVertexBuilder *, GrGPArgs *, const char *posName)
static void WriteLocalCoord(GrGLSLVertexBuilder *, GrGLSLUniformHandler *, const GrShaderCaps &, GrGPArgs *, GrShaderVar localVar, const SkMatrix &localMatrix, UniformHandle *localMatrixUniform)
GrGeometryProcessor(ClassID)
static Attribute MakeColorAttribute(const char *name, bool wideColor)
void setVertexAttributesWithImplicitOffsets(const Attribute *attrs, int attrCount)
@ kDefaultGeoProc_ClassID
auto make(Ctor &&ctor) -> decltype(ctor(nullptr))
bool invert(SkMatrix *inverse) const
static const SkMatrix & I()
static const SkMatrix & InvalidMatrix()
VULKAN_HPP_DEFAULT_DISPATCH_LOADER_DYNAMIC_STORAGE auto & d
FlutterSemanticsFlag flags
G_BEGIN_DECLS G_MODULE_EXPORT FlValue * args
GrGeometryProcessor * Make(SkArenaAlloc *, const Color &, const Coverage &, const LocalCoords &, const SkMatrix &viewMatrix)
GrGeometryProcessor * MakeForDeviceSpace(SkArenaAlloc *, const Color &, const Coverage &, const LocalCoords &, const SkMatrix &viewMatrix)
SK_API sk_sp< SkDocument > Make(SkWStream *dst, const SkSerialProcs *=nullptr, std::function< void(const SkPicture *)> onEndPage=nullptr)
bool hasLocalMatrix() const
const float * vec() const
static SkRGBA4f FromBytes_RGBA(uint32_t color)