66 return arena->
make([&](
void* ptr) {
67 return new (ptr) FwidthSquircleTestProcessor(viewMatrix);
71 const char*
name()
const override {
return "FwidthSquircleTestProcessor"; }
75 std::unique_ptr<ProgramImpl> makeProgramImpl(
const GrShaderCaps&)
const final;
78 FwidthSquircleTestProcessor(
const SkMatrix& viewMatrix)
81 this->setVertexAttributesWithImplicitOffsets(&gVertex, 1);
89std::unique_ptr<GrGeometryProcessor::ProgramImpl> FwidthSquircleTestProcessor::makeProgramImpl(
96 const auto& proc = geomProc.
cast<FwidthSquircleTestProcessor>();
97 pdman.
setSkMatrix(fViewMatrixHandle, proc.fViewMatrix);
101 void onEmitCode(EmitArgs&
args, GrGPArgs* gpArgs)
override {
102 const auto& proc =
args.fGeomProc.cast<FwidthSquircleTestProcessor>();
104 auto* uniforms =
args.fUniformHandler;
105 fViewMatrixHandle = uniforms->addUniform(
nullptr,
110 auto* varyings =
args.fVaryingHandler;
111 varyings->emitAttributes(proc);
114 varyings->addVarying(
"bboxcoord", &squircleCoord);
116 auto* v =
args.fVertBuilder;
117 v->codeAppendf(
"float2x2 R = float2x2(cos(.05), sin(.05), -sin(.05), cos(.05));");
119 v->codeAppendf(
"%s = bboxcoord * 1.25;", squircleCoord.vsOut());
120 v->codeAppendf(
"float3 vertexpos = float3(bboxcoord * 100 * R + 100, 1);");
121 v->codeAppendf(
"vertexpos = %s * vertexpos;",
122 uniforms->getUniformCStr(fViewMatrixHandle));
125 auto*
f =
args.fFragBuilder;
126 f->codeAppendf(
"float golden_ratio = 1.61803398875;");
127 f->codeAppendf(
"float pi = 3.141592653589793;");
128 f->codeAppendf(
"float x = abs(%s.x), y = abs(%s.y);",
129 squircleCoord.fsIn(), squircleCoord.fsIn());
132 f->codeAppendf(
"float fn = half(pow(x, golden_ratio*pi) + "
133 "pow(y, golden_ratio*pi) - 1);");
134 f->codeAppendf(
"float fnwidth = fwidth(fn);");
135 f->codeAppendf(
"fnwidth += 1e-10;");
136 f->codeAppendf(
"half coverage = clamp(half(.5 - fn/fnwidth), 0, 1);");
138 f->codeAppendf(
"half4 %s = half4(.51, .42, .71, 1) * .89;",
args.fOutputColor);
139 f->codeAppendf(
"half4 %s = half4(coverage);",
args.fOutputCoverage);
142 UniformHandle fViewMatrixHandle;
145 return std::make_unique<Impl>();
151class FwidthSquircleTestOp :
public GrDrawOp {
156 return GrOp::Make<FwidthSquircleTestOp>(ctx, viewMatrix);
160 FwidthSquircleTestOp(
const SkMatrix& viewMatrix)
166 const char*
name()
const override {
return "FwidthSquircleTestOp"; }
175 bool usesMSAASurface,
182 return sk_gpu_test::CreateProgramInfo(caps, arena, writeView, usesMSAASurface,
183 std::move(appliedClip), dstProxyView,
186 renderPassXferBarriers, colorLoadOp);
190 return this->createProgramInfo(&flushState->
caps(),
206 SkArenaAlloc* arena = context->priv().recordTimeAllocator();
214 fProgramInfo = this->createProgramInfo(context->priv().caps(), arena, writeView,
215 usesMSAASurface, std::move(appliedClip),
216 dstProxyView, renderPassXferBarriers, colorLoadOp);
218 context->priv().recordProgramInfo(fProgramInfo);
228 fVertexBuffer = flushState->resourceProvider()->createBuffer(vertices,
240 fProgramInfo = this->createProgramInfo(flushState);
244 flushState->bindBuffers(
nullptr,
nullptr, std::move(
fVertexBuffer));
245 flushState->draw(4, 0);
249 static const int kWidth = 200;
250 static const int kHeight = 200;
275 if (!rContext->priv().caps()->shaderCaps()->fShaderDerivativeSupport) {
276 *errorMsg =
"Shader derivatives not supported.";
#define DEFINE_OP_CLASS_ID
@ kStatic_GrAccessPattern
@ kFloat2_GrVertexAttribType
@ kSrcOver
r = s + (1-sa)*d
constexpr SkColor SK_ColorWHITE
static SkPath clip(const SkPath &path, const SkHalfPlane &plane)
#define INHERITED(method,...)
sk_sp< const GrBuffer > fVertexBuffer
static GrAppliedClip Disabled()
void setSkMatrix(UniformHandle, const SkMatrix &) const
GrLoadOp colorLoadOp() const final
const GrDstProxyView & dstProxyView() const final
GrXferBarrierFlags renderPassBarriers() const final
SkArenaAlloc * allocator() override
const GrSurfaceProxyView & writeView() const final
GrAppliedClip detachAppliedClip() final
const GrCaps & caps() const final
bool usesMSAASurface() const final
std::unique_ptr< GrOp > Owner
static constexpr Analysis EmptySetAnalysis()
GrRenderTargetProxy * asRenderTargetProxy() const
auto make(Ctor &&ctor) -> decltype(ctor(nullptr))
static constexpr char kErrorMsg_DrawSkippedGpuOnly[]
G_BEGIN_DECLS G_MODULE_EXPORT FlValue * args
SK_API sk_sp< SkDocument > Make(SkWStream *dst, const SkSerialProcs *=nullptr, std::function< void(const SkPicture *)> onEndPage=nullptr)
DEF_SWITCHES_START aot vmservice shared library name
SurfaceDrawContext * TopDeviceSurfaceDrawContext(const SkCanvas *canvas)
DEF_SIMPLE_GPU_GM_CAN_FAIL(clear_swizzle, rContext, canvas, errorMsg, 6 *kSize, 2 *kSize)
static SkRect MakeIWH(int w, int h)