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