Chris Dalton | 0921219 | 2018-11-13 15:07:24 -0500 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2018 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
| 7 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 8 | #include "gm/gm.h" |
Ben Wagner | 7fde8e1 | 2019-05-01 17:28:53 -0400 | [diff] [blame] | 9 | #include "include/core/SkBlendMode.h" |
| 10 | #include "include/core/SkCanvas.h" |
| 11 | #include "include/core/SkColor.h" |
| 12 | #include "include/core/SkMatrix.h" |
| 13 | #include "include/core/SkPoint.h" |
| 14 | #include "include/core/SkRect.h" |
| 15 | #include "include/core/SkRefCnt.h" |
| 16 | #include "include/core/SkString.h" |
Robert Phillips | b7bfbc2 | 2020-07-01 12:55:01 -0400 | [diff] [blame] | 17 | #include "include/gpu/GrRecordingContext.h" |
Ben Wagner | 7fde8e1 | 2019-05-01 17:28:53 -0400 | [diff] [blame] | 18 | #include "include/private/GrTypesPriv.h" |
Robert Phillips | 7a0d3c3 | 2021-07-21 15:39:51 -0400 | [diff] [blame] | 19 | #include "src/core/SkCanvasPriv.h" |
Ben Wagner | 7fde8e1 | 2019-05-01 17:28:53 -0400 | [diff] [blame] | 20 | #include "src/gpu/GrBuffer.h" |
| 21 | #include "src/gpu/GrCaps.h" |
Adlai Holler | a069304 | 2020-10-14 11:23:11 -0400 | [diff] [blame] | 22 | #include "src/gpu/GrDirectContextPriv.h" |
Ben Wagner | 7fde8e1 | 2019-05-01 17:28:53 -0400 | [diff] [blame] | 23 | #include "src/gpu/GrGeometryProcessor.h" |
| 24 | #include "src/gpu/GrGpuBuffer.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 25 | #include "src/gpu/GrMemoryPool.h" |
| 26 | #include "src/gpu/GrOpFlushState.h" |
Greg Daniel | 2d41d0d | 2019-08-26 11:08:51 -0400 | [diff] [blame] | 27 | #include "src/gpu/GrOpsRenderPass.h" |
Ben Wagner | 7fde8e1 | 2019-05-01 17:28:53 -0400 | [diff] [blame] | 28 | #include "src/gpu/GrPipeline.h" |
Ben Wagner | 7fde8e1 | 2019-05-01 17:28:53 -0400 | [diff] [blame] | 29 | #include "src/gpu/GrProcessor.h" |
| 30 | #include "src/gpu/GrProcessorSet.h" |
Robert Phillips | 901aff0 | 2019-10-08 12:32:56 -0400 | [diff] [blame] | 31 | #include "src/gpu/GrProgramInfo.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 32 | #include "src/gpu/GrRecordingContextPriv.h" |
Ben Wagner | 7fde8e1 | 2019-05-01 17:28:53 -0400 | [diff] [blame] | 33 | #include "src/gpu/GrResourceProvider.h" |
| 34 | #include "src/gpu/GrShaderCaps.h" |
| 35 | #include "src/gpu/GrShaderVar.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 36 | #include "src/gpu/glsl/GrGLSLFragmentShaderBuilder.h" |
| 37 | #include "src/gpu/glsl/GrGLSLGeometryProcessor.h" |
Ben Wagner | 7fde8e1 | 2019-05-01 17:28:53 -0400 | [diff] [blame] | 38 | #include "src/gpu/glsl/GrGLSLProgramDataManager.h" |
| 39 | #include "src/gpu/glsl/GrGLSLUniformHandler.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 40 | #include "src/gpu/glsl/GrGLSLVarying.h" |
| 41 | #include "src/gpu/glsl/GrGLSLVertexGeoBuilder.h" |
Ben Wagner | 7fde8e1 | 2019-05-01 17:28:53 -0400 | [diff] [blame] | 42 | #include "src/gpu/ops/GrDrawOp.h" |
| 43 | #include "src/gpu/ops/GrOp.h" |
Robert Phillips | 4dca831 | 2021-07-28 15:13:20 -0400 | [diff] [blame] | 44 | #include "src/gpu/v1/SurfaceDrawContext_v1.h" |
Robert Phillips | 34cea00 | 2019-11-21 16:02:34 -0500 | [diff] [blame] | 45 | #include "tools/gpu/ProxyUtils.h" |
Ben Wagner | 7fde8e1 | 2019-05-01 17:28:53 -0400 | [diff] [blame] | 46 | |
| 47 | #include <memory> |
| 48 | #include <utility> |
| 49 | |
| 50 | class GrAppliedClip; |
Chris Dalton | 0921219 | 2018-11-13 15:07:24 -0500 | [diff] [blame] | 51 | |
Chris Dalton | 3a77837 | 2019-02-07 15:23:36 -0700 | [diff] [blame] | 52 | /** |
| 53 | * This test ensures that fwidth() works properly on GPU configs by drawing a squircle. |
| 54 | */ |
Robert Phillips | 7a0d3c3 | 2021-07-21 15:39:51 -0400 | [diff] [blame] | 55 | namespace { |
Chris Dalton | 0921219 | 2018-11-13 15:07:24 -0500 | [diff] [blame] | 56 | |
| 57 | static constexpr GrGeometryProcessor::Attribute gVertex = |
| 58 | {"bboxcoord", kFloat2_GrVertexAttribType, kFloat2_GrSLType}; |
| 59 | |
Chris Dalton | 0921219 | 2018-11-13 15:07:24 -0500 | [diff] [blame] | 60 | //////////////////////////////////////////////////////////////////////////////////////////////////// |
| 61 | // SkSL code. |
| 62 | |
| 63 | class FwidthSquircleTestProcessor : public GrGeometryProcessor { |
| 64 | public: |
Robert Phillips | 5d07c52 | 2019-11-18 11:19:51 -0500 | [diff] [blame] | 65 | static GrGeometryProcessor* Make(SkArenaAlloc* arena, const SkMatrix& viewMatrix) { |
Mike Klein | f124108 | 2020-12-14 15:59:09 -0600 | [diff] [blame] | 66 | return arena->make([&](void* ptr) { |
| 67 | return new (ptr) FwidthSquircleTestProcessor(viewMatrix); |
| 68 | }); |
Robert Phillips | 5d07c52 | 2019-11-18 11:19:51 -0500 | [diff] [blame] | 69 | } |
| 70 | |
| 71 | const char* name() const override { return "FwidthSquircleTestProcessor"; } |
| 72 | |
| 73 | void getGLSLProcessorKey(const GrShaderCaps&, GrProcessorKeyBuilder* b) const final {} |
| 74 | |
Robert Phillips | f10535f | 2021-03-23 09:30:45 -0400 | [diff] [blame] | 75 | GrGLSLGeometryProcessor* createGLSLInstance(const GrShaderCaps&) const final; |
Robert Phillips | 5d07c52 | 2019-11-18 11:19:51 -0500 | [diff] [blame] | 76 | |
| 77 | private: |
Chris Dalton | 0921219 | 2018-11-13 15:07:24 -0500 | [diff] [blame] | 78 | FwidthSquircleTestProcessor(const SkMatrix& viewMatrix) |
| 79 | : GrGeometryProcessor(kFwidthSquircleTestProcessor_ClassID) |
| 80 | , fViewMatrix(viewMatrix) { |
| 81 | this->setVertexAttributes(&gVertex, 1); |
| 82 | } |
Chris Dalton | 0921219 | 2018-11-13 15:07:24 -0500 | [diff] [blame] | 83 | |
Chris Dalton | 0921219 | 2018-11-13 15:07:24 -0500 | [diff] [blame] | 84 | const SkMatrix fViewMatrix; |
| 85 | |
| 86 | class Impl; |
Robert Phillips | 5d07c52 | 2019-11-18 11:19:51 -0500 | [diff] [blame] | 87 | |
John Stiles | 7571f9e | 2020-09-02 22:42:33 -0400 | [diff] [blame] | 88 | using INHERITED = GrGeometryProcessor; |
Chris Dalton | 0921219 | 2018-11-13 15:07:24 -0500 | [diff] [blame] | 89 | }; |
| 90 | |
| 91 | class FwidthSquircleTestProcessor::Impl : public GrGLSLGeometryProcessor { |
| 92 | void onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) override { |
Robert Phillips | 787fd9d | 2021-03-22 14:48:09 -0400 | [diff] [blame] | 93 | const auto& proc = args.fGeomProc.cast<FwidthSquircleTestProcessor>(); |
Chris Dalton | 0921219 | 2018-11-13 15:07:24 -0500 | [diff] [blame] | 94 | |
| 95 | auto* uniforms = args.fUniformHandler; |
Ethan Nicholas | 16464c3 | 2020-04-06 13:53:05 -0400 | [diff] [blame] | 96 | fViewMatrixHandle = uniforms->addUniform(nullptr, kVertex_GrShaderFlag, kFloat3x3_GrSLType, |
| 97 | "viewmatrix"); |
Chris Dalton | 0921219 | 2018-11-13 15:07:24 -0500 | [diff] [blame] | 98 | |
| 99 | auto* varyings = args.fVaryingHandler; |
| 100 | varyings->emitAttributes(proc); |
| 101 | |
| 102 | GrGLSLVarying squircleCoord(kFloat2_GrSLType); |
| 103 | varyings->addVarying("bboxcoord", &squircleCoord); |
| 104 | |
| 105 | auto* v = args.fVertBuilder; |
| 106 | v->codeAppendf("float2x2 R = float2x2(cos(.05), sin(.05), -sin(.05), cos(.05));"); |
| 107 | |
| 108 | v->codeAppendf("%s = bboxcoord * 1.25;", squircleCoord.vsOut()); |
| 109 | v->codeAppendf("float3 vertexpos = float3(bboxcoord * 100 * R + 100, 1);"); |
| 110 | v->codeAppendf("vertexpos = %s * vertexpos;", uniforms->getUniformCStr(fViewMatrixHandle)); |
| 111 | gpArgs->fPositionVar.set(kFloat3_GrSLType, "vertexpos"); |
| 112 | |
| 113 | auto* f = args.fFragBuilder; |
| 114 | f->codeAppendf("float golden_ratio = 1.61803398875;"); |
| 115 | f->codeAppendf("float pi = 3.141592653589793;"); |
| 116 | f->codeAppendf("float x = abs(%s.x), y = abs(%s.y);", |
| 117 | squircleCoord.fsIn(), squircleCoord.fsIn()); |
| 118 | |
| 119 | // Squircle function! |
Ethan Nicholas | e1f5502 | 2019-02-05 17:17:40 -0500 | [diff] [blame] | 120 | f->codeAppendf("float fn = half(pow(x, golden_ratio*pi) + pow(y, golden_ratio*pi) - 1);"); |
Chris Dalton | 0921219 | 2018-11-13 15:07:24 -0500 | [diff] [blame] | 121 | f->codeAppendf("float fnwidth = fwidth(fn);"); |
| 122 | f->codeAppendf("fnwidth += 1e-10;"); // Guard against divide-by-zero. |
Ethan Nicholas | e1f5502 | 2019-02-05 17:17:40 -0500 | [diff] [blame] | 123 | f->codeAppendf("half coverage = clamp(half(.5 - fn/fnwidth), 0, 1);"); |
Chris Dalton | 0921219 | 2018-11-13 15:07:24 -0500 | [diff] [blame] | 124 | |
John Stiles | 4d7ac49 | 2021-03-09 20:16:43 -0500 | [diff] [blame] | 125 | f->codeAppendf("half4 %s = half4(.51, .42, .71, 1) * .89;", args.fOutputColor); |
| 126 | f->codeAppendf("half4 %s = half4(coverage);", args.fOutputCoverage); |
Chris Dalton | 0921219 | 2018-11-13 15:07:24 -0500 | [diff] [blame] | 127 | } |
| 128 | |
Brian Osman | 609f159 | 2020-07-01 15:14:39 -0400 | [diff] [blame] | 129 | void setData(const GrGLSLProgramDataManager& pdman, |
Brian Salomon | 5a32828 | 2021-04-14 10:32:25 -0400 | [diff] [blame] | 130 | const GrShaderCaps&, |
Robert Phillips | 787fd9d | 2021-03-22 14:48:09 -0400 | [diff] [blame] | 131 | const GrGeometryProcessor& geomProc) override { |
| 132 | const auto& proc = geomProc.cast<FwidthSquircleTestProcessor>(); |
Chris Dalton | 0921219 | 2018-11-13 15:07:24 -0500 | [diff] [blame] | 133 | pdman.setSkMatrix(fViewMatrixHandle, proc.fViewMatrix); |
| 134 | } |
| 135 | |
| 136 | UniformHandle fViewMatrixHandle; |
| 137 | }; |
| 138 | |
Robert Phillips | f10535f | 2021-03-23 09:30:45 -0400 | [diff] [blame] | 139 | GrGLSLGeometryProcessor* FwidthSquircleTestProcessor::createGLSLInstance( |
Chris Dalton | 0921219 | 2018-11-13 15:07:24 -0500 | [diff] [blame] | 140 | const GrShaderCaps&) const { |
| 141 | return new Impl(); |
| 142 | } |
| 143 | |
| 144 | //////////////////////////////////////////////////////////////////////////////////////////////////// |
| 145 | // Draw Op. |
| 146 | |
| 147 | class FwidthSquircleTestOp : public GrDrawOp { |
| 148 | public: |
| 149 | DEFINE_OP_CLASS_ID |
| 150 | |
Herb Derby | c76d409 | 2020-10-07 16:46:15 -0400 | [diff] [blame] | 151 | static GrOp::Owner Make(GrRecordingContext* ctx, const SkMatrix& viewMatrix) { |
| 152 | return GrOp::Make<FwidthSquircleTestOp>(ctx, viewMatrix); |
Chris Dalton | 0921219 | 2018-11-13 15:07:24 -0500 | [diff] [blame] | 153 | } |
| 154 | |
| 155 | private: |
| 156 | FwidthSquircleTestOp(const SkMatrix& viewMatrix) |
| 157 | : GrDrawOp(ClassID()) |
| 158 | , fViewMatrix(viewMatrix) { |
Greg Daniel | 5faf474 | 2019-10-01 15:14:44 -0400 | [diff] [blame] | 159 | this->setBounds(SkRect::MakeIWH(kWidth, kHeight), HasAABloat::kNo, IsHairline::kNo); |
Chris Dalton | 0921219 | 2018-11-13 15:07:24 -0500 | [diff] [blame] | 160 | } |
| 161 | |
Robert Phillips | 901aff0 | 2019-10-08 12:32:56 -0400 | [diff] [blame] | 162 | const char* name() const override { return "FwidthSquircleTestOp"; } |
Chris Dalton | 0921219 | 2018-11-13 15:07:24 -0500 | [diff] [blame] | 163 | FixedFunctionFlags fixedFunctionFlags() const override { return FixedFunctionFlags::kNone; } |
Chris Dalton | 57ab06c | 2021-04-22 12:57:28 -0600 | [diff] [blame] | 164 | GrProcessorSet::Analysis finalize(const GrCaps&, const GrAppliedClip*, GrClampType) override { |
Chris Dalton | 4b62aed | 2019-01-15 11:53:00 -0700 | [diff] [blame] | 165 | return GrProcessorSet::EmptySetAnalysis(); |
Chris Dalton | 0921219 | 2018-11-13 15:07:24 -0500 | [diff] [blame] | 166 | } |
Robert Phillips | 5d07c52 | 2019-11-18 11:19:51 -0500 | [diff] [blame] | 167 | |
Robert Phillips | ac6156c | 2020-02-28 16:02:40 -0500 | [diff] [blame] | 168 | GrProgramInfo* createProgramInfo(const GrCaps* caps, |
| 169 | SkArenaAlloc* arena, |
Adlai Holler | e2296f7 | 2020-11-19 13:41:26 -0500 | [diff] [blame] | 170 | const GrSurfaceProxyView& writeView, |
Robert Phillips | ac6156c | 2020-02-28 16:02:40 -0500 | [diff] [blame] | 171 | GrAppliedClip&& appliedClip, |
John Stiles | 52cb1d0 | 2021-06-02 11:58:05 -0400 | [diff] [blame] | 172 | const GrDstProxyView& dstProxyView, |
Greg Daniel | 42dbca5 | 2020-11-20 10:22:43 -0500 | [diff] [blame] | 173 | GrXferBarrierFlags renderPassXferBarriers, |
| 174 | GrLoadOp colorLoadOp) const { |
Robert Phillips | ac6156c | 2020-02-28 16:02:40 -0500 | [diff] [blame] | 175 | GrGeometryProcessor* geomProc = FwidthSquircleTestProcessor::Make(arena, fViewMatrix); |
| 176 | |
Brian Salomon | 8afde5f | 2020-04-01 16:22:00 -0400 | [diff] [blame] | 177 | return sk_gpu_test::CreateProgramInfo(caps, arena, writeView, |
Robert Phillips | ac6156c | 2020-02-28 16:02:40 -0500 | [diff] [blame] | 178 | std::move(appliedClip), dstProxyView, |
| 179 | geomProc, SkBlendMode::kSrcOver, |
Greg Daniel | d358cbe | 2020-09-11 09:33:54 -0400 | [diff] [blame] | 180 | GrPrimitiveType::kTriangleStrip, |
Greg Daniel | 42dbca5 | 2020-11-20 10:22:43 -0500 | [diff] [blame] | 181 | renderPassXferBarriers, colorLoadOp); |
Robert Phillips | ac6156c | 2020-02-28 16:02:40 -0500 | [diff] [blame] | 182 | } |
| 183 | |
| 184 | GrProgramInfo* createProgramInfo(GrOpFlushState* flushState) const { |
| 185 | return this->createProgramInfo(&flushState->caps(), |
| 186 | flushState->allocator(), |
Brian Salomon | 8afde5f | 2020-04-01 16:22:00 -0400 | [diff] [blame] | 187 | flushState->writeView(), |
Robert Phillips | ac6156c | 2020-02-28 16:02:40 -0500 | [diff] [blame] | 188 | flushState->detachAppliedClip(), |
Greg Daniel | d358cbe | 2020-09-11 09:33:54 -0400 | [diff] [blame] | 189 | flushState->dstProxyView(), |
Greg Daniel | 42dbca5 | 2020-11-20 10:22:43 -0500 | [diff] [blame] | 190 | flushState->renderPassBarriers(), |
| 191 | flushState->colorLoadOp()); |
Robert Phillips | ac6156c | 2020-02-28 16:02:40 -0500 | [diff] [blame] | 192 | } |
| 193 | |
Robert Phillips | 5d07c52 | 2019-11-18 11:19:51 -0500 | [diff] [blame] | 194 | void onPrePrepare(GrRecordingContext* context, |
Adlai Holler | e2296f7 | 2020-11-19 13:41:26 -0500 | [diff] [blame] | 195 | const GrSurfaceProxyView& writeView, |
Robert Phillips | 34cea00 | 2019-11-21 16:02:34 -0500 | [diff] [blame] | 196 | GrAppliedClip* clip, |
John Stiles | 52cb1d0 | 2021-06-02 11:58:05 -0400 | [diff] [blame] | 197 | const GrDstProxyView& dstProxyView, |
Greg Daniel | 42dbca5 | 2020-11-20 10:22:43 -0500 | [diff] [blame] | 198 | GrXferBarrierFlags renderPassXferBarriers, |
| 199 | GrLoadOp colorLoadOp) final { |
Robert Phillips | 5d07c52 | 2019-11-18 11:19:51 -0500 | [diff] [blame] | 200 | SkArenaAlloc* arena = context->priv().recordTimeAllocator(); |
| 201 | |
Robert Phillips | 34cea00 | 2019-11-21 16:02:34 -0500 | [diff] [blame] | 202 | // This is equivalent to a GrOpFlushState::detachAppliedClip |
Michael Ludwig | d1d997e | 2020-06-04 15:52:44 -0400 | [diff] [blame] | 203 | GrAppliedClip appliedClip = clip ? std::move(*clip) : GrAppliedClip::Disabled(); |
Robert Phillips | 5d07c52 | 2019-11-18 11:19:51 -0500 | [diff] [blame] | 204 | |
Brian Salomon | 8afde5f | 2020-04-01 16:22:00 -0400 | [diff] [blame] | 205 | fProgramInfo = this->createProgramInfo(context->priv().caps(), arena, writeView, |
Greg Daniel | d358cbe | 2020-09-11 09:33:54 -0400 | [diff] [blame] | 206 | std::move(appliedClip), dstProxyView, |
Greg Daniel | 42dbca5 | 2020-11-20 10:22:43 -0500 | [diff] [blame] | 207 | renderPassXferBarriers, colorLoadOp); |
Robert Phillips | 5d07c52 | 2019-11-18 11:19:51 -0500 | [diff] [blame] | 208 | |
Robert Phillips | ac6156c | 2020-02-28 16:02:40 -0500 | [diff] [blame] | 209 | context->priv().recordProgramInfo(fProgramInfo); |
Robert Phillips | 5d07c52 | 2019-11-18 11:19:51 -0500 | [diff] [blame] | 210 | } |
| 211 | |
| 212 | void onPrepare(GrOpFlushState* flushState) final { |
Chris Dalton | 0921219 | 2018-11-13 15:07:24 -0500 | [diff] [blame] | 213 | SkPoint vertices[4] = { |
| 214 | {-1, -1}, |
| 215 | {+1, -1}, |
| 216 | {-1, +1}, |
| 217 | {+1, +1}, |
| 218 | }; |
Greg Daniel | f793de1 | 2019-09-05 13:23:23 -0400 | [diff] [blame] | 219 | fVertexBuffer = flushState->resourceProvider()->createBuffer( |
| 220 | sizeof(vertices), GrGpuBufferType::kVertex, kStatic_GrAccessPattern, vertices); |
| 221 | } |
Robert Phillips | 5d07c52 | 2019-11-18 11:19:51 -0500 | [diff] [blame] | 222 | |
| 223 | void onExecute(GrOpFlushState* flushState, const SkRect& chainBounds) final { |
Greg Daniel | f793de1 | 2019-09-05 13:23:23 -0400 | [diff] [blame] | 224 | if (!fVertexBuffer) { |
Chris Dalton | 0921219 | 2018-11-13 15:07:24 -0500 | [diff] [blame] | 225 | return; |
| 226 | } |
Robert Phillips | 901aff0 | 2019-10-08 12:32:56 -0400 | [diff] [blame] | 227 | |
Robert Phillips | 34cea00 | 2019-11-21 16:02:34 -0500 | [diff] [blame] | 228 | if (!fProgramInfo) { |
Robert Phillips | ac6156c | 2020-02-28 16:02:40 -0500 | [diff] [blame] | 229 | fProgramInfo = this->createProgramInfo(flushState); |
Robert Phillips | 34cea00 | 2019-11-21 16:02:34 -0500 | [diff] [blame] | 230 | } |
| 231 | |
Chris Dalton | aa0e45c | 2020-03-16 10:05:11 -0600 | [diff] [blame] | 232 | flushState->bindPipeline(*fProgramInfo, SkRect::MakeIWH(kWidth, kHeight)); |
Greg Daniel | 426274b | 2020-07-20 11:37:38 -0400 | [diff] [blame] | 233 | flushState->bindBuffers(nullptr, nullptr, std::move(fVertexBuffer)); |
Chris Dalton | aa0e45c | 2020-03-16 10:05:11 -0600 | [diff] [blame] | 234 | flushState->draw(4, 0); |
Robert Phillips | 5d07c52 | 2019-11-18 11:19:51 -0500 | [diff] [blame] | 235 | |
Chris Dalton | 0921219 | 2018-11-13 15:07:24 -0500 | [diff] [blame] | 236 | } |
| 237 | |
Greg Daniel | 55e5be3 | 2019-09-30 12:23:26 -0400 | [diff] [blame] | 238 | static const int kWidth = 200; |
| 239 | static const int kHeight = 200; |
Chris Dalton | 0921219 | 2018-11-13 15:07:24 -0500 | [diff] [blame] | 240 | |
Robert Phillips | 5d07c52 | 2019-11-18 11:19:51 -0500 | [diff] [blame] | 241 | sk_sp<GrBuffer> fVertexBuffer; |
| 242 | const SkMatrix fViewMatrix; |
| 243 | |
Robert Phillips | 787fd9d | 2021-03-22 14:48:09 -0400 | [diff] [blame] | 244 | // The program info (and both the GrPipeline and GrGeometryProcessor it relies on), when |
Robert Phillips | 34cea00 | 2019-11-21 16:02:34 -0500 | [diff] [blame] | 245 | // allocated, are allocated in either the ddl-record-time or flush-time arena. It is the |
| 246 | // arena's job to free up their memory so we just have a bare programInfo pointer here. We |
Robert Phillips | 787fd9d | 2021-03-22 14:48:09 -0400 | [diff] [blame] | 247 | // don't even store the GrPipeline and GrGeometryProcessor pointers here bc they are |
Robert Phillips | 34cea00 | 2019-11-21 16:02:34 -0500 | [diff] [blame] | 248 | // guaranteed to have the same lifetime as the program info. |
Robert Phillips | 5d07c52 | 2019-11-18 11:19:51 -0500 | [diff] [blame] | 249 | GrProgramInfo* fProgramInfo = nullptr; |
| 250 | |
Herb Derby | c76d409 | 2020-10-07 16:46:15 -0400 | [diff] [blame] | 251 | friend class ::GrOp; // for ctor |
Robert Phillips | 5d07c52 | 2019-11-18 11:19:51 -0500 | [diff] [blame] | 252 | |
John Stiles | 7571f9e | 2020-09-02 22:42:33 -0400 | [diff] [blame] | 253 | using INHERITED = GrDrawOp; |
Chris Dalton | 0921219 | 2018-11-13 15:07:24 -0500 | [diff] [blame] | 254 | }; |
| 255 | |
Robert Phillips | 7a0d3c3 | 2021-07-21 15:39:51 -0400 | [diff] [blame] | 256 | } // namespace |
| 257 | |
Chris Dalton | 0921219 | 2018-11-13 15:07:24 -0500 | [diff] [blame] | 258 | //////////////////////////////////////////////////////////////////////////////////////////////////// |
| 259 | // Test. |
| 260 | |
Robert Phillips | 7a0d3c3 | 2021-07-21 15:39:51 -0400 | [diff] [blame] | 261 | namespace skiagm { |
| 262 | |
| 263 | DEF_SIMPLE_GPU_GM_CAN_FAIL(fwidth_squircle, rContext, canvas, errorMsg, 200, 200) { |
| 264 | if (!rContext->priv().caps()->shaderCaps()->shaderDerivativeSupport()) { |
Chris Dalton | 50e24d7 | 2019-02-07 16:20:09 -0700 | [diff] [blame] | 265 | *errorMsg = "Shader derivatives not supported."; |
| 266 | return DrawResult::kSkip; |
Chris Dalton | 0921219 | 2018-11-13 15:07:24 -0500 | [diff] [blame] | 267 | } |
| 268 | |
Robert Phillips | 7a0d3c3 | 2021-07-21 15:39:51 -0400 | [diff] [blame] | 269 | auto sdc = SkCanvasPriv::TopDeviceSurfaceDrawContext(canvas); |
| 270 | if (!sdc) { |
| 271 | *errorMsg = GM::kErrorMsg_DrawSkippedGpuOnly; |
| 272 | return DrawResult::kSkip; |
| 273 | } |
| 274 | |
Chris Dalton | 0921219 | 2018-11-13 15:07:24 -0500 | [diff] [blame] | 275 | // Draw the test directly to the frame buffer. |
Chris Dalton | 3a77837 | 2019-02-07 15:23:36 -0700 | [diff] [blame] | 276 | canvas->clear(SK_ColorWHITE); |
Robert Phillips | 7a0d3c3 | 2021-07-21 15:39:51 -0400 | [diff] [blame] | 277 | sdc->addDrawOp(FwidthSquircleTestOp::Make(rContext, canvas->getTotalMatrix())); |
Chris Dalton | 50e24d7 | 2019-02-07 16:20:09 -0700 | [diff] [blame] | 278 | return skiagm::DrawResult::kOk; |
Chris Dalton | 0921219 | 2018-11-13 15:07:24 -0500 | [diff] [blame] | 279 | } |
| 280 | |
John Stiles | a6841be | 2020-08-06 14:11:56 -0400 | [diff] [blame] | 281 | } // namespace skiagm |