Chris Dalton | 49d14e9 | 2018-07-27 12:38:35 -0600 | [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/SkColorSpace.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/SkSize.h" |
| 17 | #include "include/core/SkString.h" |
| 18 | #include "include/core/SkTypes.h" |
Robert Phillips | b7bfbc2 | 2020-07-01 12:55:01 -0400 | [diff] [blame] | 19 | #include "include/gpu/GrRecordingContext.h" |
Ben Wagner | 7fde8e1 | 2019-05-01 17:28:53 -0400 | [diff] [blame] | 20 | #include "include/gpu/GrTypes.h" |
Ben Wagner | 7fde8e1 | 2019-05-01 17:28:53 -0400 | [diff] [blame] | 21 | #include "include/private/SkColorData.h" |
Robert Phillips | 59ba27b | 2022-04-12 09:59:38 -0400 | [diff] [blame] | 22 | #include "include/private/gpu/ganesh/GrTypesPriv.h" |
Robert Phillips | 7a0d3c3 | 2021-07-21 15:39:51 -0400 | [diff] [blame] | 23 | #include "src/core/SkCanvasPriv.h" |
Greg Daniel | cdeb092 | 2021-12-20 12:37:56 -0500 | [diff] [blame] | 24 | #include "src/gpu/KeyBuilder.h" |
Greg Daniel | 719239c | 2022-04-07 11:20:24 -0400 | [diff] [blame] | 25 | #include "src/gpu/ganesh/GrBuffer.h" |
Kevin Lubick | acdc108 | 2023-06-09 11:05:24 -0400 | [diff] [blame] | 26 | #include "src/gpu/ganesh/GrCanvas.h" |
Greg Daniel | 719239c | 2022-04-07 11:20:24 -0400 | [diff] [blame] | 27 | #include "src/gpu/ganesh/GrCaps.h" |
| 28 | #include "src/gpu/ganesh/GrColorSpaceXform.h" |
| 29 | #include "src/gpu/ganesh/GrDirectContextPriv.h" |
| 30 | #include "src/gpu/ganesh/GrGeometryProcessor.h" |
| 31 | #include "src/gpu/ganesh/GrGpuBuffer.h" |
| 32 | #include "src/gpu/ganesh/GrMemoryPool.h" |
| 33 | #include "src/gpu/ganesh/GrOpFlushState.h" |
| 34 | #include "src/gpu/ganesh/GrOpsRenderPass.h" |
| 35 | #include "src/gpu/ganesh/GrPipeline.h" |
| 36 | #include "src/gpu/ganesh/GrProcessor.h" |
| 37 | #include "src/gpu/ganesh/GrProcessorSet.h" |
| 38 | #include "src/gpu/ganesh/GrProgramInfo.h" |
| 39 | #include "src/gpu/ganesh/GrRecordingContextPriv.h" |
| 40 | #include "src/gpu/ganesh/GrResourceProvider.h" |
| 41 | #include "src/gpu/ganesh/GrSamplerState.h" |
| 42 | #include "src/gpu/ganesh/GrShaderCaps.h" |
| 43 | #include "src/gpu/ganesh/GrShaderVar.h" |
| 44 | #include "src/gpu/ganesh/GrSurfaceProxy.h" |
| 45 | #include "src/gpu/ganesh/GrTextureProxy.h" |
Robert Phillips | c1b9408 | 2022-08-09 17:16:19 -0400 | [diff] [blame] | 46 | #include "src/gpu/ganesh/SurfaceDrawContext.h" |
Greg Daniel | 719239c | 2022-04-07 11:20:24 -0400 | [diff] [blame] | 47 | #include "src/gpu/ganesh/glsl/GrGLSLFragmentShaderBuilder.h" |
| 48 | #include "src/gpu/ganesh/glsl/GrGLSLVarying.h" |
| 49 | #include "src/gpu/ganesh/ops/GrDrawOp.h" |
| 50 | #include "src/gpu/ganesh/ops/GrOp.h" |
Robert Phillips | 34cea00 | 2019-11-21 16:02:34 -0500 | [diff] [blame] | 51 | #include "tools/gpu/ProxyUtils.h" |
Ben Wagner | 7fde8e1 | 2019-05-01 17:28:53 -0400 | [diff] [blame] | 52 | |
| 53 | #include <memory> |
| 54 | #include <utility> |
| 55 | |
| 56 | class GrAppliedClip; |
| 57 | class GrGLSLProgramDataManager; |
Chris Dalton | 49d14e9 | 2018-07-27 12:38:35 -0600 | [diff] [blame] | 58 | |
Hal Canary | fa3305a | 2019-07-18 12:36:54 -0400 | [diff] [blame] | 59 | namespace { |
Chris Dalton | 49d14e9 | 2018-07-27 12:38:35 -0600 | [diff] [blame] | 60 | |
Brian Osman | d4c2970 | 2018-09-14 16:16:55 -0400 | [diff] [blame] | 61 | static constexpr GrGeometryProcessor::Attribute gVertex = |
Robert Phillips | 1042c00 | 2022-01-21 14:59:22 -0500 | [diff] [blame] | 62 | {"position", kFloat2_GrVertexAttribType, SkSLType::kFloat2}; |
Chris Dalton | 49d14e9 | 2018-07-27 12:38:35 -0600 | [diff] [blame] | 63 | |
Chris Dalton | 49d14e9 | 2018-07-27 12:38:35 -0600 | [diff] [blame] | 64 | //////////////////////////////////////////////////////////////////////////////////////////////////// |
| 65 | // SkSL code. |
| 66 | |
| 67 | class ClockwiseTestProcessor : public GrGeometryProcessor { |
| 68 | public: |
Robert Phillips | 5d07c52 | 2019-11-18 11:19:51 -0500 | [diff] [blame] | 69 | static GrGeometryProcessor* Make(SkArenaAlloc* arena, bool readSkFragCoord) { |
Mike Klein | f124108 | 2020-12-14 15:59:09 -0600 | [diff] [blame] | 70 | return arena->make([&](void* ptr) { |
| 71 | return new (ptr) ClockwiseTestProcessor(readSkFragCoord); |
| 72 | }); |
Robert Phillips | df70f15 | 2019-11-15 14:57:05 -0500 | [diff] [blame] | 73 | } |
| 74 | |
| 75 | const char* name() const final { return "ClockwiseTestProcessor"; } |
| 76 | |
Greg Daniel | cdeb092 | 2021-12-20 12:37:56 -0500 | [diff] [blame] | 77 | void addToKey(const GrShaderCaps&, skgpu::KeyBuilder* b) const final { |
Robert Phillips | df70f15 | 2019-11-15 14:57:05 -0500 | [diff] [blame] | 78 | b->add32(fReadSkFragCoord); |
| 79 | } |
| 80 | |
Brian Salomon | f95940b | 2021-08-09 15:56:24 -0400 | [diff] [blame] | 81 | std::unique_ptr<ProgramImpl> makeProgramImpl(const GrShaderCaps&) const final; |
Robert Phillips | df70f15 | 2019-11-15 14:57:05 -0500 | [diff] [blame] | 82 | |
Robert Phillips | 5d07c52 | 2019-11-18 11:19:51 -0500 | [diff] [blame] | 83 | bool readSkFragCoord() const { return fReadSkFragCoord; } |
| 84 | |
Robert Phillips | df70f15 | 2019-11-15 14:57:05 -0500 | [diff] [blame] | 85 | private: |
Chris Dalton | 49d14e9 | 2018-07-27 12:38:35 -0600 | [diff] [blame] | 86 | ClockwiseTestProcessor(bool readSkFragCoord) |
| 87 | : GrGeometryProcessor(kClockwiseTestProcessor_ClassID) |
| 88 | , fReadSkFragCoord(readSkFragCoord) { |
Brian Salomon | dd9ef45 | 2021-12-16 16:14:56 -0500 | [diff] [blame] | 89 | this->setVertexAttributesWithImplicitOffsets(&gVertex, 1); |
Chris Dalton | 49d14e9 | 2018-07-27 12:38:35 -0600 | [diff] [blame] | 90 | } |
Chris Dalton | 49d14e9 | 2018-07-27 12:38:35 -0600 | [diff] [blame] | 91 | |
Chris Dalton | 49d14e9 | 2018-07-27 12:38:35 -0600 | [diff] [blame] | 92 | const bool fReadSkFragCoord; |
| 93 | |
John Stiles | 7571f9e | 2020-09-02 22:42:33 -0400 | [diff] [blame] | 94 | using INHERITED = GrGeometryProcessor; |
Chris Dalton | 49d14e9 | 2018-07-27 12:38:35 -0600 | [diff] [blame] | 95 | }; |
| 96 | |
Brian Salomon | f95940b | 2021-08-09 15:56:24 -0400 | [diff] [blame] | 97 | std::unique_ptr<GrGeometryProcessor::ProgramImpl> ClockwiseTestProcessor::makeProgramImpl( |
| 98 | const GrShaderCaps&) const { |
Brian Salomon | bab2d11 | 2021-08-11 09:59:56 -0400 | [diff] [blame] | 99 | class Impl : public ProgramImpl { |
| 100 | public: |
| 101 | void setData(const GrGLSLProgramDataManager&, |
| 102 | const GrShaderCaps&, |
| 103 | const GrGeometryProcessor&) override {} |
| 104 | |
| 105 | private: |
| 106 | void onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) override { |
| 107 | const ClockwiseTestProcessor& proc = args.fGeomProc.cast<ClockwiseTestProcessor>(); |
| 108 | args.fVaryingHandler->emitAttributes(proc); |
Robert Phillips | 1042c00 | 2022-01-21 14:59:22 -0500 | [diff] [blame] | 109 | gpArgs->fPositionVar.set(SkSLType::kFloat2, "position"); |
Brian Salomon | bab2d11 | 2021-08-11 09:59:56 -0400 | [diff] [blame] | 110 | args.fFragBuilder->codeAppendf( |
| 111 | "half4 %s = sk_Clockwise ? half4(0,1,0,1) : half4(1,0,0,1);", |
| 112 | args.fOutputColor); |
| 113 | if (!proc.readSkFragCoord()) { |
| 114 | args.fFragBuilder->codeAppendf("const half4 %s = half4(1);", args.fOutputCoverage); |
| 115 | } else { |
| 116 | // Verify layout(origin_upper_left) on gl_FragCoord does not affect gl_FrontFacing. |
| 117 | args.fFragBuilder->codeAppendf("half4 %s = half4(min(half(sk_FragCoord.y), 1));", |
| 118 | args.fOutputCoverage); |
| 119 | } |
| 120 | } |
| 121 | }; |
| 122 | |
| 123 | return std::make_unique<Impl>(); |
Chris Dalton | 49d14e9 | 2018-07-27 12:38:35 -0600 | [diff] [blame] | 124 | } |
| 125 | |
| 126 | //////////////////////////////////////////////////////////////////////////////////////////////////// |
| 127 | // Draw Op. |
| 128 | |
| 129 | class ClockwiseTestOp : public GrDrawOp { |
| 130 | public: |
| 131 | DEFINE_OP_CLASS_ID |
| 132 | |
Herb Derby | c76d409 | 2020-10-07 16:46:15 -0400 | [diff] [blame] | 133 | static GrOp::Owner Make(GrRecordingContext* context, |
| 134 | bool readSkFragCoord, int y = 0) { |
| 135 | return GrOp::Make<ClockwiseTestOp>(context, readSkFragCoord, y); |
Chris Dalton | 49d14e9 | 2018-07-27 12:38:35 -0600 | [diff] [blame] | 136 | } |
| 137 | |
| 138 | private: |
| 139 | ClockwiseTestOp(bool readSkFragCoord, float y) |
Robert Phillips | 5d07c52 | 2019-11-18 11:19:51 -0500 | [diff] [blame] | 140 | : GrDrawOp(ClassID()) |
| 141 | , fReadSkFragCoord(readSkFragCoord) |
| 142 | , fY(y) { |
Greg Daniel | 5faf474 | 2019-10-01 15:14:44 -0400 | [diff] [blame] | 143 | this->setBounds(SkRect::MakeXYWH(0, fY, 100, 100), HasAABloat::kNo, IsHairline::kNo); |
Chris Dalton | 49d14e9 | 2018-07-27 12:38:35 -0600 | [diff] [blame] | 144 | } |
| 145 | |
| 146 | const char* name() const override { return "ClockwiseTestOp"; } |
| 147 | FixedFunctionFlags fixedFunctionFlags() const override { return FixedFunctionFlags::kNone; } |
Chris Dalton | 57ab06c | 2021-04-22 12:57:28 -0600 | [diff] [blame] | 148 | GrProcessorSet::Analysis finalize(const GrCaps&, const GrAppliedClip*, GrClampType) override { |
Chris Dalton | 4b62aed | 2019-01-15 11:53:00 -0700 | [diff] [blame] | 149 | return GrProcessorSet::EmptySetAnalysis(); |
Chris Dalton | 49d14e9 | 2018-07-27 12:38:35 -0600 | [diff] [blame] | 150 | } |
Robert Phillips | df70f15 | 2019-11-15 14:57:05 -0500 | [diff] [blame] | 151 | |
Robert Phillips | ac6156c | 2020-02-28 16:02:40 -0500 | [diff] [blame] | 152 | GrProgramInfo* createProgramInfo(const GrCaps* caps, |
| 153 | SkArenaAlloc* arena, |
Adlai Holler | e2296f7 | 2020-11-19 13:41:26 -0500 | [diff] [blame] | 154 | const GrSurfaceProxyView& writeView, |
Chris Dalton | 2a26c50 | 2021-08-26 10:05:11 -0600 | [diff] [blame] | 155 | bool usesMSAASurface, |
Robert Phillips | ac6156c | 2020-02-28 16:02:40 -0500 | [diff] [blame] | 156 | GrAppliedClip&& appliedClip, |
John Stiles | 52cb1d0 | 2021-06-02 11:58:05 -0400 | [diff] [blame] | 157 | const GrDstProxyView& dstProxyView, |
Greg Daniel | 42dbca5 | 2020-11-20 10:22:43 -0500 | [diff] [blame] | 158 | GrXferBarrierFlags renderPassXferBarriers, |
| 159 | GrLoadOp colorLoadOp) const { |
Robert Phillips | ac6156c | 2020-02-28 16:02:40 -0500 | [diff] [blame] | 160 | GrGeometryProcessor* geomProc = ClockwiseTestProcessor::Make(arena, fReadSkFragCoord); |
| 161 | |
Chris Dalton | 2a26c50 | 2021-08-26 10:05:11 -0600 | [diff] [blame] | 162 | return sk_gpu_test::CreateProgramInfo(caps, arena, writeView, usesMSAASurface, |
Robert Phillips | ac6156c | 2020-02-28 16:02:40 -0500 | [diff] [blame] | 163 | std::move(appliedClip), dstProxyView, |
| 164 | geomProc, SkBlendMode::kPlus, |
Greg Daniel | d358cbe | 2020-09-11 09:33:54 -0400 | [diff] [blame] | 165 | GrPrimitiveType::kTriangleStrip, |
Greg Daniel | 42dbca5 | 2020-11-20 10:22:43 -0500 | [diff] [blame] | 166 | renderPassXferBarriers, colorLoadOp); |
Robert Phillips | ac6156c | 2020-02-28 16:02:40 -0500 | [diff] [blame] | 167 | } |
| 168 | |
| 169 | GrProgramInfo* createProgramInfo(GrOpFlushState* flushState) const { |
| 170 | return this->createProgramInfo(&flushState->caps(), |
| 171 | flushState->allocator(), |
Brian Salomon | 8afde5f | 2020-04-01 16:22:00 -0400 | [diff] [blame] | 172 | flushState->writeView(), |
Chris Dalton | 2a26c50 | 2021-08-26 10:05:11 -0600 | [diff] [blame] | 173 | flushState->usesMSAASurface(), |
Robert Phillips | ac6156c | 2020-02-28 16:02:40 -0500 | [diff] [blame] | 174 | flushState->detachAppliedClip(), |
Greg Daniel | d358cbe | 2020-09-11 09:33:54 -0400 | [diff] [blame] | 175 | flushState->dstProxyView(), |
Greg Daniel | 42dbca5 | 2020-11-20 10:22:43 -0500 | [diff] [blame] | 176 | flushState->renderPassBarriers(), |
| 177 | flushState->colorLoadOp()); |
Robert Phillips | ac6156c | 2020-02-28 16:02:40 -0500 | [diff] [blame] | 178 | } |
| 179 | |
Robert Phillips | df70f15 | 2019-11-15 14:57:05 -0500 | [diff] [blame] | 180 | void onPrePrepare(GrRecordingContext* context, |
Adlai Holler | e2296f7 | 2020-11-19 13:41:26 -0500 | [diff] [blame] | 181 | const GrSurfaceProxyView& writeView, |
Robert Phillips | 34cea00 | 2019-11-21 16:02:34 -0500 | [diff] [blame] | 182 | GrAppliedClip* clip, |
John Stiles | 52cb1d0 | 2021-06-02 11:58:05 -0400 | [diff] [blame] | 183 | const GrDstProxyView& dstProxyView, |
Greg Daniel | 42dbca5 | 2020-11-20 10:22:43 -0500 | [diff] [blame] | 184 | GrXferBarrierFlags renderPassXferBarriers, |
| 185 | GrLoadOp colorLoadOp) final { |
Robert Phillips | d4fb7c7 | 2019-11-15 17:28:37 -0500 | [diff] [blame] | 186 | SkArenaAlloc* arena = context->priv().recordTimeAllocator(); |
Robert Phillips | df70f15 | 2019-11-15 14:57:05 -0500 | [diff] [blame] | 187 | |
Chris Dalton | 2a26c50 | 2021-08-26 10:05:11 -0600 | [diff] [blame] | 188 | // DMSAA is not supported on DDL. |
| 189 | bool usesMSAASurface = writeView.asRenderTargetProxy()->numSamples() > 1; |
| 190 | |
Robert Phillips | 34cea00 | 2019-11-21 16:02:34 -0500 | [diff] [blame] | 191 | // This is equivalent to a GrOpFlushState::detachAppliedClip |
Michael Ludwig | d1d997e | 2020-06-04 15:52:44 -0400 | [diff] [blame] | 192 | GrAppliedClip appliedClip = clip ? std::move(*clip) : GrAppliedClip::Disabled(); |
Robert Phillips | df70f15 | 2019-11-15 14:57:05 -0500 | [diff] [blame] | 193 | |
Brian Salomon | 8afde5f | 2020-04-01 16:22:00 -0400 | [diff] [blame] | 194 | fProgramInfo = this->createProgramInfo(context->priv().caps(), arena, writeView, |
Chris Dalton | 2a26c50 | 2021-08-26 10:05:11 -0600 | [diff] [blame] | 195 | usesMSAASurface, std::move(appliedClip), |
| 196 | dstProxyView, renderPassXferBarriers, colorLoadOp); |
Robert Phillips | df70f15 | 2019-11-15 14:57:05 -0500 | [diff] [blame] | 197 | |
Robert Phillips | ac6156c | 2020-02-28 16:02:40 -0500 | [diff] [blame] | 198 | context->priv().recordProgramInfo(fProgramInfo); |
Robert Phillips | df70f15 | 2019-11-15 14:57:05 -0500 | [diff] [blame] | 199 | } |
| 200 | |
Greg Daniel | f793de1 | 2019-09-05 13:23:23 -0400 | [diff] [blame] | 201 | void onPrepare(GrOpFlushState* flushState) override { |
Chris Dalton | 49d14e9 | 2018-07-27 12:38:35 -0600 | [diff] [blame] | 202 | SkPoint vertices[4] = { |
| 203 | {100, fY}, |
| 204 | {0, fY+100}, |
| 205 | {0, fY}, |
| 206 | {100, fY+100}, |
| 207 | }; |
Brian Salomon | 9c9ef38 | 2022-05-26 19:33:20 -0400 | [diff] [blame] | 208 | fVertexBuffer = flushState->resourceProvider()->createBuffer(vertices, |
| 209 | sizeof(vertices), |
| 210 | GrGpuBufferType::kVertex, |
| 211 | kStatic_GrAccessPattern); |
Greg Daniel | f793de1 | 2019-09-05 13:23:23 -0400 | [diff] [blame] | 212 | } |
Robert Phillips | df70f15 | 2019-11-15 14:57:05 -0500 | [diff] [blame] | 213 | |
Greg Daniel | f793de1 | 2019-09-05 13:23:23 -0400 | [diff] [blame] | 214 | void onExecute(GrOpFlushState* flushState, const SkRect& chainBounds) override { |
| 215 | if (!fVertexBuffer) { |
Chris Dalton | 79f99f7 | 2018-07-27 14:15:10 -0600 | [diff] [blame] | 216 | return; |
| 217 | } |
Robert Phillips | df70f15 | 2019-11-15 14:57:05 -0500 | [diff] [blame] | 218 | |
Robert Phillips | 34cea00 | 2019-11-21 16:02:34 -0500 | [diff] [blame] | 219 | if (!fProgramInfo) { |
Robert Phillips | ac6156c | 2020-02-28 16:02:40 -0500 | [diff] [blame] | 220 | fProgramInfo = this->createProgramInfo(flushState); |
Robert Phillips | 34cea00 | 2019-11-21 16:02:34 -0500 | [diff] [blame] | 221 | } |
| 222 | |
Chris Dalton | aa0e45c | 2020-03-16 10:05:11 -0600 | [diff] [blame] | 223 | flushState->bindPipeline(*fProgramInfo, SkRect::MakeXYWH(0, fY, 100, 100)); |
Greg Daniel | 426274b | 2020-07-20 11:37:38 -0400 | [diff] [blame] | 224 | flushState->bindBuffers(nullptr, nullptr, std::move(fVertexBuffer)); |
Chris Dalton | aa0e45c | 2020-03-16 10:05:11 -0600 | [diff] [blame] | 225 | flushState->draw(4, 0); |
Chris Dalton | 49d14e9 | 2018-07-27 12:38:35 -0600 | [diff] [blame] | 226 | } |
| 227 | |
Robert Phillips | 5d07c52 | 2019-11-18 11:19:51 -0500 | [diff] [blame] | 228 | sk_sp<GrBuffer> fVertexBuffer; |
| 229 | const bool fReadSkFragCoord; |
| 230 | const float fY; |
Robert Phillips | df70f15 | 2019-11-15 14:57:05 -0500 | [diff] [blame] | 231 | |
Robert Phillips | 787fd9d | 2021-03-22 14:48:09 -0400 | [diff] [blame] | 232 | // 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] | 233 | // allocated, are allocated in either the ddl-record-time or flush-time arena. It is the |
| 234 | // 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] | 235 | // 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] | 236 | // guaranteed to have the same lifetime as the program info. |
Robert Phillips | 5d07c52 | 2019-11-18 11:19:51 -0500 | [diff] [blame] | 237 | GrProgramInfo* fProgramInfo = nullptr; |
Chris Dalton | 49d14e9 | 2018-07-27 12:38:35 -0600 | [diff] [blame] | 238 | |
Herb Derby | c76d409 | 2020-10-07 16:46:15 -0400 | [diff] [blame] | 239 | friend class ::GrOp; // for ctor |
Robert Phillips | 5d07c52 | 2019-11-18 11:19:51 -0500 | [diff] [blame] | 240 | |
John Stiles | 7571f9e | 2020-09-02 22:42:33 -0400 | [diff] [blame] | 241 | using INHERITED = GrDrawOp; |
Chris Dalton | 49d14e9 | 2018-07-27 12:38:35 -0600 | [diff] [blame] | 242 | }; |
| 243 | |
Robert Phillips | 7a0d3c3 | 2021-07-21 15:39:51 -0400 | [diff] [blame] | 244 | } // namespace |
| 245 | |
Chris Dalton | 49d14e9 | 2018-07-27 12:38:35 -0600 | [diff] [blame] | 246 | //////////////////////////////////////////////////////////////////////////////////////////////////// |
| 247 | // Test. |
| 248 | |
Robert Phillips | 7a0d3c3 | 2021-07-21 15:39:51 -0400 | [diff] [blame] | 249 | namespace skiagm { |
| 250 | |
| 251 | /** |
| 252 | * This is a GPU-backend specific test. It ensures that SkSL properly identifies clockwise-winding |
| 253 | * triangles (sk_Clockwise), in terms of to Skia device space, in all backends and with all render |
| 254 | * target origins. We draw clockwise triangles green and counter-clockwise red. |
| 255 | */ |
| 256 | class ClockwiseGM : public GpuGM { |
Leandro Lovisolo | 24fa211 | 2023-08-15 19:05:17 +0000 | [diff] [blame] | 257 | SkString getName() const override { return SkString("clockwise"); } |
Leandro Lovisolo | 8f02388 | 2023-08-15 21:13:52 +0000 | [diff] [blame] | 258 | SkISize getISize() override { return {300, 200}; } |
Robert Phillips | 7a0d3c3 | 2021-07-21 15:39:51 -0400 | [diff] [blame] | 259 | DrawResult onDraw(GrRecordingContext*, SkCanvas*, SkString* errorMsg) override; |
| 260 | }; |
| 261 | |
| 262 | DrawResult ClockwiseGM::onDraw(GrRecordingContext* rContext, SkCanvas* canvas, SkString* errorMsg) { |
Kevin Lubick | acdc108 | 2023-06-09 11:05:24 -0400 | [diff] [blame] | 263 | auto sdc = skgpu::ganesh::TopDeviceSurfaceDrawContext(canvas); |
Robert Phillips | 7a0d3c3 | 2021-07-21 15:39:51 -0400 | [diff] [blame] | 264 | if (!sdc) { |
| 265 | *errorMsg = kErrorMsg_DrawSkippedGpuOnly; |
| 266 | return DrawResult::kSkip; |
| 267 | } |
| 268 | |
Robert Phillips | edcd431 | 2021-06-03 10:14:16 -0400 | [diff] [blame] | 269 | sdc->clear(SK_PMColor4fBLACK); |
Chris Dalton | 49d14e9 | 2018-07-27 12:38:35 -0600 | [diff] [blame] | 270 | |
| 271 | // Draw the test directly to the frame buffer. |
Robert Phillips | 7a0d3c3 | 2021-07-21 15:39:51 -0400 | [diff] [blame] | 272 | sdc->addDrawOp(ClockwiseTestOp::Make(rContext, false, 0)); |
| 273 | sdc->addDrawOp(ClockwiseTestOp::Make(rContext, true, 100)); |
Chris Dalton | 49d14e9 | 2018-07-27 12:38:35 -0600 | [diff] [blame] | 274 | |
| 275 | // Draw the test to an off-screen, top-down render target. |
Robert Phillips | 4dca831 | 2021-07-28 15:13:20 -0400 | [diff] [blame] | 276 | GrColorType sdcColorType = sdc->colorInfo().colorType(); |
Kevin Lubick | f24283f | 2023-03-17 16:10:23 -0400 | [diff] [blame] | 277 | if (auto topLeftSDC = skgpu::ganesh::SurfaceDrawContext::Make(rContext, |
| 278 | sdcColorType, |
| 279 | nullptr, |
| 280 | SkBackingFit::kExact, |
| 281 | {100, 200}, |
| 282 | SkSurfaceProps(), |
| 283 | /*label=*/{}, |
Robert Phillips | addbff5 | 2023-08-03 15:48:53 -0400 | [diff] [blame] | 284 | /* sampleCnt= */ 1, |
Kevin Lubick | df73d16 | 2023-09-11 11:56:53 -0400 | [diff] [blame] | 285 | skgpu::Mipmapped::kNo, |
Kevin Lubick | f24283f | 2023-03-17 16:10:23 -0400 | [diff] [blame] | 286 | GrProtected::kNo, |
| 287 | kTopLeft_GrSurfaceOrigin, |
| 288 | skgpu::Budgeted::kYes)) { |
Robert Phillips | 4dca831 | 2021-07-28 15:13:20 -0400 | [diff] [blame] | 289 | topLeftSDC->clear(SK_PMColor4fTRANSPARENT); |
| 290 | topLeftSDC->addDrawOp(ClockwiseTestOp::Make(rContext, false, 0)); |
| 291 | topLeftSDC->addDrawOp(ClockwiseTestOp::Make(rContext, true, 100)); |
Robert Phillips | edcd431 | 2021-06-03 10:14:16 -0400 | [diff] [blame] | 292 | sdc->drawTexture(nullptr, |
Robert Phillips | 4dca831 | 2021-07-28 15:13:20 -0400 | [diff] [blame] | 293 | topLeftSDC->readSurfaceView(), |
Robert Phillips | edcd431 | 2021-06-03 10:14:16 -0400 | [diff] [blame] | 294 | sdc->colorInfo().alphaType(), |
Brian Salomon | e69b9ef | 2020-07-22 11:18:06 -0400 | [diff] [blame] | 295 | GrSamplerState::Filter::kNearest, |
| 296 | GrSamplerState::MipmapMode::kNone, |
| 297 | SkBlendMode::kSrcOver, |
| 298 | SK_PMColor4fWHITE, |
| 299 | {0, 0, 100, 200}, |
| 300 | {100, 0, 200, 200}, |
Brian Salomon | e69b9ef | 2020-07-22 11:18:06 -0400 | [diff] [blame] | 301 | GrQuadAAFlags::kNone, |
| 302 | SkCanvas::SrcRectConstraint::kStrict_SrcRectConstraint, |
| 303 | SkMatrix::I(), |
Brian Osman | 3d139a4 | 2018-11-19 10:42:10 -0500 | [diff] [blame] | 304 | nullptr); |
Chris Dalton | 49d14e9 | 2018-07-27 12:38:35 -0600 | [diff] [blame] | 305 | } |
| 306 | |
| 307 | // Draw the test to an off-screen, bottom-up render target. |
Kevin Lubick | f24283f | 2023-03-17 16:10:23 -0400 | [diff] [blame] | 308 | if (auto topLeftSDC = skgpu::ganesh::SurfaceDrawContext::Make(rContext, |
| 309 | sdcColorType, |
| 310 | nullptr, |
| 311 | SkBackingFit::kExact, |
| 312 | {100, 200}, |
| 313 | SkSurfaceProps(), |
Robert Phillips | addbff5 | 2023-08-03 15:48:53 -0400 | [diff] [blame] | 314 | /*label=*/{})) { |
Robert Phillips | 4dca831 | 2021-07-28 15:13:20 -0400 | [diff] [blame] | 315 | topLeftSDC->clear(SK_PMColor4fTRANSPARENT); |
| 316 | topLeftSDC->addDrawOp(ClockwiseTestOp::Make(rContext, false, 0)); |
| 317 | topLeftSDC->addDrawOp(ClockwiseTestOp::Make(rContext, true, 100)); |
Robert Phillips | edcd431 | 2021-06-03 10:14:16 -0400 | [diff] [blame] | 318 | sdc->drawTexture(nullptr, |
Robert Phillips | 4dca831 | 2021-07-28 15:13:20 -0400 | [diff] [blame] | 319 | topLeftSDC->readSurfaceView(), |
Robert Phillips | edcd431 | 2021-06-03 10:14:16 -0400 | [diff] [blame] | 320 | sdc->colorInfo().alphaType(), |
Brian Salomon | e69b9ef | 2020-07-22 11:18:06 -0400 | [diff] [blame] | 321 | GrSamplerState::Filter::kNearest, |
| 322 | GrSamplerState::MipmapMode::kNone, |
| 323 | SkBlendMode::kSrcOver, |
| 324 | SK_PMColor4fWHITE, |
| 325 | {0, 0, 100, 200}, |
| 326 | {200, 0, 300, 200}, |
Brian Salomon | e69b9ef | 2020-07-22 11:18:06 -0400 | [diff] [blame] | 327 | GrQuadAAFlags::kNone, |
| 328 | SkCanvas::SrcRectConstraint::kStrict_SrcRectConstraint, |
| 329 | SkMatrix::I(), |
Brian Osman | 3d139a4 | 2018-11-19 10:42:10 -0500 | [diff] [blame] | 330 | nullptr); |
Chris Dalton | 49d14e9 | 2018-07-27 12:38:35 -0600 | [diff] [blame] | 331 | } |
Robert Phillips | 7a0d3c3 | 2021-07-21 15:39:51 -0400 | [diff] [blame] | 332 | |
| 333 | return DrawResult::kOk; |
Chris Dalton | 49d14e9 | 2018-07-27 12:38:35 -0600 | [diff] [blame] | 334 | } |
| 335 | |
| 336 | //////////////////////////////////////////////////////////////////////////////////////////////////// |
| 337 | |
| 338 | DEF_GM( return new ClockwiseGM(); ) |
| 339 | |
Robert Phillips | 7a0d3c3 | 2021-07-21 15:39:51 -0400 | [diff] [blame] | 340 | } // namespace skiagm |