56 DrawAtlasPathShader(
bool usesLocalCoords,
60 , fUsesLocalCoords(usesLocalCoords)
61 , fAtlasHelper(atlasHelper)
63 fAtlasHelper->proxy()->backendFormat(),
64 fAtlasHelper->atlasSwizzle()) {
66 constexpr static Attribute kUnitCoordAttrib(
68 this->setVertexAttributesWithImplicitOffsets(&kUnitCoordAttrib, 1);
71 if (fUsesLocalCoords) {
75 SkASSERT(fAttribs.size() == this->colorAttribIdx());
77 fAtlasHelper->appendInstanceAttribs(&fAttribs);
78 SkASSERT(fAttribs.size() <= kMaxInstanceAttribs);
79 this->setInstanceAttributesWithImplicitOffsets(fAttribs.data(), fAttribs.size());
80 this->setTextureSamplerCnt(1);
86 int colorAttribIdx()
const {
return fUsesLocalCoords ? 3 : 1; }
87 const char*
name()
const override {
return "DrawAtlasPathShader"; }
89 b->addBits(1, fUsesLocalCoords,
"localCoords");
90 fAtlasHelper->getKeyBits(
b);
92 const TextureSampler& onTextureSampler(
int)
const override {
return fAtlasAccess; }
93 std::unique_ptr<ProgramImpl> makeProgramImpl(
const GrShaderCaps&)
const override;
95 const bool fUsesLocalCoords;
97 TextureSampler fAtlasAccess;
98 constexpr static int kMaxInstanceAttribs = 6;
102class DrawAtlasPathShader::Impl :
public ProgramImpl {
107 auto* atlasHelper = geomProc.
cast<DrawAtlasPathShader>().fAtlasHelper;
112 void onEmitCode(EmitArgs&
args, GrGPArgs* gpArgs)
override {
113 const auto& shader =
args.fGeomProc.cast<DrawAtlasPathShader>();
114 args.fVaryingHandler->emitAttributes(shader);
116 if (
args.fShaderCaps->fVertexIDSupport) {
119 args.fVertBuilder->codeAppendf(R
"(
120 float2 unitCoord = float2(sk_VertexID & 1, sk_VertexID >> 1);)");
123 args.fVertBuilder->codeAppendf(R"(
124 float2 devCoord = mix(fillBounds.xy, fillBounds.zw, unitCoord);)");
127 if (shader.fUsesLocalCoords) {
128 args.fVertBuilder->codeAppendf(R
"(
129 float2x2 M = float2x2(affineMatrix.xy, affineMatrix.zw);
130 float2 localCoord = inverse(M) * (devCoord - translate);)");
134 args.fFragBuilder->codeAppendf(
"half4 %s = half4(1);",
args.fOutputCoverage);
135 shader.fAtlasHelper->injectShaderCode(
args, gpArgs->fPositionVar, &fAtlasAdjustUniform);
137 args.fFragBuilder->codeAppendf(
"half4 %s;",
args.fOutputColor);
138 args.fVaryingHandler->addPassThroughAttribute(
139 shader.fAttribs[shader.colorAttribIdx()].asShaderVar(),
147std::unique_ptr<GrGeometryProcessor::ProgramImpl> DrawAtlasPathShader::makeProgramImpl(
149 return std::make_unique<Impl>();
169 fProcessors != that->fProcessors) {
173 SkASSERT(fUsesLocalCoords == that->fUsesLocalCoords);
174 *fTailInstance = that->fHeadInstance;
175 fTailInstance = that->fTailInstance;
176 fInstanceCount += that->fInstanceCount;
188 initArgs.
fCaps = ∩︀
191 auto pipeline = arena->
make<
GrPipeline>(initArgs, std::move(fProcessors),
192 std::move(appliedClip));
193 auto shader = arena->
make<DrawAtlasPathShader>(fUsesLocalCoords, &fAtlasHelper,
195 fProgram = arena->
make<
GrProgramInfo>(caps, writeView, usesMSAASurface, pipeline,
198 renderPassXferBarriers, colorLoadOp);
209 writeView, usesMSAASurface, std::move(*appliedClip), dstProxyView,
210 renderPassXferBarriers, colorLoadOp);
229 for (
const Instance*
i = fHeadInstance;
i;
i =
i->fNext) {
232 i->fLocalToDeviceIfUsingLocalCoords)
234 fAtlasHelper.writeInstanceData(&instanceWriter, &
i->fAtlasInstance);
239 constexpr static SkPoint kUnitQuad[4] = {{0,0}, {0,1}, {1,0}, {1,1}};
254 flushState->
bindBuffers(
nullptr, std::move(fInstanceBuffer), fVertexBufferIfNoIDSupport);
255 flushState->
drawInstanced(fInstanceCount, fBaseInstance, 4, 0);
@ kFloat2_GrVertexAttribType
@ kFloat4_GrVertexAttribType
#define SKGPU_DEFINE_STATIC_UNIQUE_KEY(name)
static SkPath clip(const SkPath &path, const SkHalfPlane &plane)
const GrCaps * caps() const
const GrShaderCaps * shaderCaps() const
size_t instanceStride() const
bool hasVertexAttributes() const
skgpu::VertexWriter makeVertexWriter(size_t vertexSize, int vertexCount, sk_sp< const GrBuffer > *, int *startVertex)
GrLoadOp colorLoadOp() const final
const GrDstProxyView & dstProxyView() const final
GrXferBarrierFlags renderPassBarriers() const final
SkArenaAlloc * allocator() override
void bindPipelineAndScissorClip(const GrProgramInfo &programInfo, const SkRect &drawBounds)
void bindBuffers(sk_sp< const GrBuffer > indexBuffer, sk_sp< const GrBuffer > instanceBuffer, sk_sp< const GrBuffer > vertexBuffer, GrPrimitiveRestart primitiveRestart=GrPrimitiveRestart::kNo)
const GrSurfaceProxyView & writeView() const final
void drawInstanced(int instanceCount, int baseInstance, int vertexCount, int baseVertex)
GrResourceProvider * resourceProvider() const final
GrAppliedClip detachAppliedClip() final
const GrCaps & caps() const final
void bindTextures(const GrGeometryProcessor &geomProc, const GrSurfaceProxy &singleGeomProcTexture, const GrPipeline &pipeline)
bool usesMSAASurface() const final
const SkRect & bounds() const
bool usesLocalCoords() const
Analysis finalize(const GrProcessorAnalysisColor &, const GrProcessorAnalysisCoverage, const GrAppliedClip *, const GrUserStencilSettings *, const GrCaps &, GrClampType, SkPMColor4f *inputColorOverride)
const GrPipeline & pipeline() const
const GrGeometryProcessor & geomProc() const
void recordProgramInfo(const GrProgramInfo *programInfo)
SkArenaAlloc * recordTimeAllocator()
GrRecordingContextPriv priv()
sk_sp< const GrGpuBuffer > findOrMakeStaticBuffer(GrGpuBufferType intendedType, size_t size, const skgpu::UniqueKey &key, InitializeBufferFn)
skgpu::Swizzle swizzle() const
GrRenderTargetProxy * asRenderTargetProxy() const
auto make(Ctor &&ctor) -> decltype(ctor(nullptr))
void setUniformData(const GrGLSLProgramDataManager &, const GrGLSLUniformHandler::UniformHandle &atlasAdjustUniformHandle) const
bool isCompatible(const AtlasInstancedHelper &helper)
void onPrePrepare(GrRecordingContext *, const GrSurfaceProxyView &writeView, GrAppliedClip *, const GrDstProxyView &, GrXferBarrierFlags, GrLoadOp colorLoadOp) override
GrProcessorSet::Analysis finalize(const GrCaps &, const GrAppliedClip *, GrClampType) override
void onExecute(GrOpFlushState *, const SkRect &chainBounds) override
CombineResult onCombineIfPossible(GrOp *, SkArenaAlloc *, const GrCaps &) override
void onPrepare(GrOpFlushState *) override
G_BEGIN_DECLS G_MODULE_EXPORT FlValue * args
DEF_SWITCHES_START aot vmservice shared library name
SKGPU_DECLARE_STATIC_UNIQUE_KEY(gUnitQuadBufferKey)
skgpu::Swizzle fWriteSwizzle
GrDstProxyView fDstProxyView
static const GrUserStencilSettings & kUnused
static SkRect Make(const SkISize &size)
static Conditional< T > If(bool condition, const T &value)