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