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