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 { |
Robert Phillips | 787fd9d | 2021-03-22 14:48:09 -0400 | [diff] [blame] | 107 | void setData(const GrGLSLProgramDataManager&, const GrGeometryProcessor&) override {} |
Chris Dalton | 49d14e9 | 2018-07-27 12:38:35 -0600 | [diff] [blame] | 108 | |
| 109 | void onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) override { |
Robert Phillips | 787fd9d | 2021-03-22 14:48:09 -0400 | [diff] [blame] | 110 | const ClockwiseTestProcessor& proc = args.fGeomProc.cast<ClockwiseTestProcessor>(); |
Chris Dalton | 49d14e9 | 2018-07-27 12:38:35 -0600 | [diff] [blame] | 111 | args.fVaryingHandler->emitAttributes(proc); |
Stephen White | 1e1ad8d | 2019-06-19 14:19:47 -0400 | [diff] [blame] | 112 | gpArgs->fPositionVar.set(kFloat2_GrSLType, "position"); |
Chris Dalton | 49d14e9 | 2018-07-27 12:38:35 -0600 | [diff] [blame] | 113 | args.fFragBuilder->codeAppendf( |
John Stiles | 4d7ac49 | 2021-03-09 20:16:43 -0500 | [diff] [blame] | 114 | "half4 %s = sk_Clockwise ? half4(0,1,0,1) : half4(1,0,0,1);", |
| 115 | args.fOutputColor); |
Robert Phillips | 5d07c52 | 2019-11-18 11:19:51 -0500 | [diff] [blame] | 116 | if (!proc.readSkFragCoord()) { |
John Stiles | 4d7ac49 | 2021-03-09 20:16:43 -0500 | [diff] [blame] | 117 | args.fFragBuilder->codeAppendf("const half4 %s = half4(1);", args.fOutputCoverage); |
Chris Dalton | 49d14e9 | 2018-07-27 12:38:35 -0600 | [diff] [blame] | 118 | } else { |
| 119 | // 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] | 120 | args.fFragBuilder->codeAppendf("half4 %s = half4(min(half(sk_FragCoord.y), 1));", |
Chris Dalton | 49d14e9 | 2018-07-27 12:38:35 -0600 | [diff] [blame] | 121 | args.fOutputCoverage); |
| 122 | } |
| 123 | } |
| 124 | }; |
| 125 | |
Robert Phillips | f10535f | 2021-03-23 09:30:45 -0400 | [diff] [blame^] | 126 | GrGLSLGeometryProcessor* ClockwiseTestProcessor::createGLSLInstance(const GrShaderCaps&) const { |
Chris Dalton | 49d14e9 | 2018-07-27 12:38:35 -0600 | [diff] [blame] | 127 | return new GLSLClockwiseTestProcessor; |
| 128 | } |
| 129 | |
| 130 | //////////////////////////////////////////////////////////////////////////////////////////////////// |
| 131 | // Draw Op. |
| 132 | |
| 133 | class ClockwiseTestOp : public GrDrawOp { |
| 134 | public: |
| 135 | DEFINE_OP_CLASS_ID |
| 136 | |
Herb Derby | c76d409 | 2020-10-07 16:46:15 -0400 | [diff] [blame] | 137 | static GrOp::Owner Make(GrRecordingContext* context, |
| 138 | bool readSkFragCoord, int y = 0) { |
| 139 | return GrOp::Make<ClockwiseTestOp>(context, readSkFragCoord, y); |
Chris Dalton | 49d14e9 | 2018-07-27 12:38:35 -0600 | [diff] [blame] | 140 | } |
| 141 | |
| 142 | private: |
| 143 | ClockwiseTestOp(bool readSkFragCoord, float y) |
Robert Phillips | 5d07c52 | 2019-11-18 11:19:51 -0500 | [diff] [blame] | 144 | : GrDrawOp(ClassID()) |
| 145 | , fReadSkFragCoord(readSkFragCoord) |
| 146 | , fY(y) { |
Greg Daniel | 5faf474 | 2019-10-01 15:14:44 -0400 | [diff] [blame] | 147 | this->setBounds(SkRect::MakeXYWH(0, fY, 100, 100), HasAABloat::kNo, IsHairline::kNo); |
Chris Dalton | 49d14e9 | 2018-07-27 12:38:35 -0600 | [diff] [blame] | 148 | } |
| 149 | |
| 150 | const char* name() const override { return "ClockwiseTestOp"; } |
| 151 | FixedFunctionFlags fixedFunctionFlags() const override { return FixedFunctionFlags::kNone; } |
Chris Dalton | 6ce447a | 2019-06-23 18:07:38 -0600 | [diff] [blame] | 152 | GrProcessorSet::Analysis finalize(const GrCaps&, const GrAppliedClip*, |
| 153 | bool hasMixedSampledCoverage, GrClampType) override { |
Chris Dalton | 4b62aed | 2019-01-15 11:53:00 -0700 | [diff] [blame] | 154 | return GrProcessorSet::EmptySetAnalysis(); |
Chris Dalton | 49d14e9 | 2018-07-27 12:38:35 -0600 | [diff] [blame] | 155 | } |
Robert Phillips | df70f15 | 2019-11-15 14:57:05 -0500 | [diff] [blame] | 156 | |
Robert Phillips | ac6156c | 2020-02-28 16:02:40 -0500 | [diff] [blame] | 157 | GrProgramInfo* createProgramInfo(const GrCaps* caps, |
| 158 | SkArenaAlloc* arena, |
Adlai Holler | e2296f7 | 2020-11-19 13:41:26 -0500 | [diff] [blame] | 159 | const GrSurfaceProxyView& writeView, |
Robert Phillips | ac6156c | 2020-02-28 16:02:40 -0500 | [diff] [blame] | 160 | GrAppliedClip&& appliedClip, |
Greg Daniel | d358cbe | 2020-09-11 09:33:54 -0400 | [diff] [blame] | 161 | const GrXferProcessor::DstProxyView& dstProxyView, |
Greg Daniel | 42dbca5 | 2020-11-20 10:22:43 -0500 | [diff] [blame] | 162 | GrXferBarrierFlags renderPassXferBarriers, |
| 163 | GrLoadOp colorLoadOp) const { |
Robert Phillips | ac6156c | 2020-02-28 16:02:40 -0500 | [diff] [blame] | 164 | GrGeometryProcessor* geomProc = ClockwiseTestProcessor::Make(arena, fReadSkFragCoord); |
| 165 | |
Brian Salomon | 8afde5f | 2020-04-01 16:22:00 -0400 | [diff] [blame] | 166 | return sk_gpu_test::CreateProgramInfo(caps, arena, writeView, |
Robert Phillips | ac6156c | 2020-02-28 16:02:40 -0500 | [diff] [blame] | 167 | std::move(appliedClip), dstProxyView, |
| 168 | geomProc, SkBlendMode::kPlus, |
Greg Daniel | d358cbe | 2020-09-11 09:33:54 -0400 | [diff] [blame] | 169 | GrPrimitiveType::kTriangleStrip, |
Greg Daniel | 42dbca5 | 2020-11-20 10:22:43 -0500 | [diff] [blame] | 170 | renderPassXferBarriers, colorLoadOp); |
Robert Phillips | ac6156c | 2020-02-28 16:02:40 -0500 | [diff] [blame] | 171 | } |
| 172 | |
| 173 | GrProgramInfo* createProgramInfo(GrOpFlushState* flushState) const { |
| 174 | return this->createProgramInfo(&flushState->caps(), |
| 175 | flushState->allocator(), |
Brian Salomon | 8afde5f | 2020-04-01 16:22:00 -0400 | [diff] [blame] | 176 | flushState->writeView(), |
Robert Phillips | ac6156c | 2020-02-28 16:02:40 -0500 | [diff] [blame] | 177 | flushState->detachAppliedClip(), |
Greg Daniel | d358cbe | 2020-09-11 09:33:54 -0400 | [diff] [blame] | 178 | flushState->dstProxyView(), |
Greg Daniel | 42dbca5 | 2020-11-20 10:22:43 -0500 | [diff] [blame] | 179 | flushState->renderPassBarriers(), |
| 180 | flushState->colorLoadOp()); |
Robert Phillips | ac6156c | 2020-02-28 16:02:40 -0500 | [diff] [blame] | 181 | } |
| 182 | |
Robert Phillips | df70f15 | 2019-11-15 14:57:05 -0500 | [diff] [blame] | 183 | void onPrePrepare(GrRecordingContext* context, |
Adlai Holler | e2296f7 | 2020-11-19 13:41:26 -0500 | [diff] [blame] | 184 | const GrSurfaceProxyView& writeView, |
Robert Phillips | 34cea00 | 2019-11-21 16:02:34 -0500 | [diff] [blame] | 185 | GrAppliedClip* clip, |
Greg Daniel | d358cbe | 2020-09-11 09:33:54 -0400 | [diff] [blame] | 186 | const GrXferProcessor::DstProxyView& dstProxyView, |
Greg Daniel | 42dbca5 | 2020-11-20 10:22:43 -0500 | [diff] [blame] | 187 | GrXferBarrierFlags renderPassXferBarriers, |
| 188 | GrLoadOp colorLoadOp) final { |
Robert Phillips | d4fb7c7 | 2019-11-15 17:28:37 -0500 | [diff] [blame] | 189 | SkArenaAlloc* arena = context->priv().recordTimeAllocator(); |
Robert Phillips | df70f15 | 2019-11-15 14:57:05 -0500 | [diff] [blame] | 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, |
Greg Daniel | d358cbe | 2020-09-11 09:33:54 -0400 | [diff] [blame] | 195 | std::move(appliedClip), dstProxyView, |
Greg Daniel | 42dbca5 | 2020-11-20 10:22:43 -0500 | [diff] [blame] | 196 | 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 | }; |
Greg Daniel | f793de1 | 2019-09-05 13:23:23 -0400 | [diff] [blame] | 208 | fVertexBuffer = flushState->resourceProvider()->createBuffer( |
| 209 | sizeof(vertices), GrGpuBufferType::kVertex, kStatic_GrAccessPattern, vertices); |
| 210 | } |
Robert Phillips | df70f15 | 2019-11-15 14:57:05 -0500 | [diff] [blame] | 211 | |
Greg Daniel | f793de1 | 2019-09-05 13:23:23 -0400 | [diff] [blame] | 212 | void onExecute(GrOpFlushState* flushState, const SkRect& chainBounds) override { |
| 213 | if (!fVertexBuffer) { |
Chris Dalton | 79f99f7 | 2018-07-27 14:15:10 -0600 | [diff] [blame] | 214 | return; |
| 215 | } |
Robert Phillips | df70f15 | 2019-11-15 14:57:05 -0500 | [diff] [blame] | 216 | |
Robert Phillips | 34cea00 | 2019-11-21 16:02:34 -0500 | [diff] [blame] | 217 | if (!fProgramInfo) { |
Robert Phillips | ac6156c | 2020-02-28 16:02:40 -0500 | [diff] [blame] | 218 | fProgramInfo = this->createProgramInfo(flushState); |
Robert Phillips | 34cea00 | 2019-11-21 16:02:34 -0500 | [diff] [blame] | 219 | } |
| 220 | |
Chris Dalton | aa0e45c | 2020-03-16 10:05:11 -0600 | [diff] [blame] | 221 | flushState->bindPipeline(*fProgramInfo, SkRect::MakeXYWH(0, fY, 100, 100)); |
Greg Daniel | 426274b | 2020-07-20 11:37:38 -0400 | [diff] [blame] | 222 | flushState->bindBuffers(nullptr, nullptr, std::move(fVertexBuffer)); |
Chris Dalton | aa0e45c | 2020-03-16 10:05:11 -0600 | [diff] [blame] | 223 | flushState->draw(4, 0); |
Chris Dalton | 49d14e9 | 2018-07-27 12:38:35 -0600 | [diff] [blame] | 224 | } |
| 225 | |
Robert Phillips | 5d07c52 | 2019-11-18 11:19:51 -0500 | [diff] [blame] | 226 | sk_sp<GrBuffer> fVertexBuffer; |
| 227 | const bool fReadSkFragCoord; |
| 228 | const float fY; |
Robert Phillips | df70f15 | 2019-11-15 14:57:05 -0500 | [diff] [blame] | 229 | |
Robert Phillips | 787fd9d | 2021-03-22 14:48:09 -0400 | [diff] [blame] | 230 | // 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] | 231 | // allocated, are allocated in either the ddl-record-time or flush-time arena. It is the |
| 232 | // 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] | 233 | // 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] | 234 | // guaranteed to have the same lifetime as the program info. |
Robert Phillips | 5d07c52 | 2019-11-18 11:19:51 -0500 | [diff] [blame] | 235 | GrProgramInfo* fProgramInfo = nullptr; |
Chris Dalton | 49d14e9 | 2018-07-27 12:38:35 -0600 | [diff] [blame] | 236 | |
Herb Derby | c76d409 | 2020-10-07 16:46:15 -0400 | [diff] [blame] | 237 | friend class ::GrOp; // for ctor |
Robert Phillips | 5d07c52 | 2019-11-18 11:19:51 -0500 | [diff] [blame] | 238 | |
John Stiles | 7571f9e | 2020-09-02 22:42:33 -0400 | [diff] [blame] | 239 | using INHERITED = GrDrawOp; |
Chris Dalton | 49d14e9 | 2018-07-27 12:38:35 -0600 | [diff] [blame] | 240 | }; |
| 241 | |
| 242 | //////////////////////////////////////////////////////////////////////////////////////////////////// |
| 243 | // Test. |
| 244 | |
Brian Salomon | eebe735 | 2020-12-09 16:37:04 -0500 | [diff] [blame] | 245 | void ClockwiseGM::onDraw(GrRecordingContext* ctx, GrSurfaceDrawContext* rtc, SkCanvas* canvas) { |
Michael Ludwig | 81d4172 | 2020-05-26 16:57:38 -0400 | [diff] [blame] | 246 | rtc->clear(SK_PMColor4fBLACK); |
Chris Dalton | 49d14e9 | 2018-07-27 12:38:35 -0600 | [diff] [blame] | 247 | |
| 248 | // Draw the test directly to the frame buffer. |
Brian Salomon | 70fe17e | 2020-11-30 14:33:58 -0500 | [diff] [blame] | 249 | rtc->addDrawOp(ClockwiseTestOp::Make(ctx, false, 0)); |
| 250 | rtc->addDrawOp(ClockwiseTestOp::Make(ctx, true, 100)); |
Chris Dalton | 49d14e9 | 2018-07-27 12:38:35 -0600 | [diff] [blame] | 251 | |
| 252 | // Draw the test to an off-screen, top-down render target. |
Greg Daniel | c594e62 | 2019-10-15 14:01:49 -0400 | [diff] [blame] | 253 | GrColorType rtcColorType = rtc->colorInfo().colorType(); |
Brian Salomon | eebe735 | 2020-12-09 16:37:04 -0500 | [diff] [blame] | 254 | if (auto topLeftRTC = GrSurfaceDrawContext::Make( |
Greg Daniel | e20fcad | 2020-01-08 11:52:34 -0500 | [diff] [blame] | 255 | ctx, rtcColorType, nullptr, SkBackingFit::kExact, {100, 200}, 1, |
Brian Salomon | 7e67dca | 2020-07-21 09:27:25 -0400 | [diff] [blame] | 256 | GrMipmapped::kNo, GrProtected::kNo, kTopLeft_GrSurfaceOrigin, SkBudgeted::kYes, |
Greg Daniel | e20fcad | 2020-01-08 11:52:34 -0500 | [diff] [blame] | 257 | nullptr)) { |
Michael Ludwig | 81d4172 | 2020-05-26 16:57:38 -0400 | [diff] [blame] | 258 | topLeftRTC->clear(SK_PMColor4fTRANSPARENT); |
Brian Salomon | 70fe17e | 2020-11-30 14:33:58 -0500 | [diff] [blame] | 259 | topLeftRTC->addDrawOp(ClockwiseTestOp::Make(ctx, false, 0)); |
| 260 | topLeftRTC->addDrawOp(ClockwiseTestOp::Make(ctx, true, 100)); |
Brian Salomon | e69b9ef | 2020-07-22 11:18:06 -0400 | [diff] [blame] | 261 | rtc->drawTexture(nullptr, |
| 262 | topLeftRTC->readSurfaceView(), |
| 263 | rtc->colorInfo().alphaType(), |
| 264 | GrSamplerState::Filter::kNearest, |
| 265 | GrSamplerState::MipmapMode::kNone, |
| 266 | SkBlendMode::kSrcOver, |
| 267 | SK_PMColor4fWHITE, |
| 268 | {0, 0, 100, 200}, |
| 269 | {100, 0, 200, 200}, |
| 270 | GrAA::kNo, |
| 271 | GrQuadAAFlags::kNone, |
| 272 | SkCanvas::SrcRectConstraint::kStrict_SrcRectConstraint, |
| 273 | SkMatrix::I(), |
Brian Osman | 3d139a4 | 2018-11-19 10:42:10 -0500 | [diff] [blame] | 274 | nullptr); |
Chris Dalton | 49d14e9 | 2018-07-27 12:38:35 -0600 | [diff] [blame] | 275 | } |
| 276 | |
| 277 | // Draw the test to an off-screen, bottom-up render target. |
Brian Salomon | eebe735 | 2020-12-09 16:37:04 -0500 | [diff] [blame] | 278 | if (auto topLeftRTC = GrSurfaceDrawContext::Make( |
Greg Daniel | e20fcad | 2020-01-08 11:52:34 -0500 | [diff] [blame] | 279 | ctx, rtcColorType, nullptr, SkBackingFit::kExact, {100, 200}, 1, |
Brian Salomon | 7e67dca | 2020-07-21 09:27:25 -0400 | [diff] [blame] | 280 | GrMipmapped::kNo, GrProtected::kNo, kBottomLeft_GrSurfaceOrigin, SkBudgeted::kYes, |
Greg Daniel | e20fcad | 2020-01-08 11:52:34 -0500 | [diff] [blame] | 281 | nullptr)) { |
Michael Ludwig | 81d4172 | 2020-05-26 16:57:38 -0400 | [diff] [blame] | 282 | topLeftRTC->clear(SK_PMColor4fTRANSPARENT); |
Brian Salomon | 70fe17e | 2020-11-30 14:33:58 -0500 | [diff] [blame] | 283 | topLeftRTC->addDrawOp(ClockwiseTestOp::Make(ctx, false, 0)); |
| 284 | topLeftRTC->addDrawOp(ClockwiseTestOp::Make(ctx, true, 100)); |
Brian Salomon | e69b9ef | 2020-07-22 11:18:06 -0400 | [diff] [blame] | 285 | rtc->drawTexture(nullptr, |
| 286 | topLeftRTC->readSurfaceView(), |
| 287 | rtc->colorInfo().alphaType(), |
| 288 | GrSamplerState::Filter::kNearest, |
| 289 | GrSamplerState::MipmapMode::kNone, |
| 290 | SkBlendMode::kSrcOver, |
| 291 | SK_PMColor4fWHITE, |
| 292 | {0, 0, 100, 200}, |
| 293 | {200, 0, 300, 200}, |
| 294 | GrAA::kNo, |
| 295 | GrQuadAAFlags::kNone, |
| 296 | SkCanvas::SrcRectConstraint::kStrict_SrcRectConstraint, |
| 297 | SkMatrix::I(), |
Brian Osman | 3d139a4 | 2018-11-19 10:42:10 -0500 | [diff] [blame] | 298 | nullptr); |
Chris Dalton | 49d14e9 | 2018-07-27 12:38:35 -0600 | [diff] [blame] | 299 | } |
| 300 | } |
| 301 | |
| 302 | //////////////////////////////////////////////////////////////////////////////////////////////////// |
| 303 | |
| 304 | DEF_GM( return new ClockwiseGM(); ) |
| 305 | |
John Stiles | a6841be | 2020-08-06 14:11:56 -0400 | [diff] [blame] | 306 | } // namespace |