Chris Dalton | 4e99853 | 2020-02-10 11:06:42 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2020 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 | |
Robert Phillips | 769b488 | 2021-09-07 16:48:46 -0400 | [diff] [blame] | 8 | #ifndef DrawAtlasPathOp_DEFINED |
| 9 | #define DrawAtlasPathOp_DEFINED |
Chris Dalton | 4e99853 | 2020-02-10 11:06:42 -0700 | [diff] [blame] | 10 | |
Chris Dalton | d2dc8dd | 2020-05-19 16:32:02 -0600 | [diff] [blame] | 11 | #include "src/core/SkIPoint16.h" |
Robert Phillips | ef80d7b | 2021-09-14 16:10:56 -0400 | [diff] [blame] | 12 | #include "src/gpu/ops/AtlasInstancedHelper.h" |
Chris Dalton | 4e99853 | 2020-02-10 11:06:42 -0700 | [diff] [blame] | 13 | #include "src/gpu/ops/GrDrawOp.h" |
| 14 | |
Robert Phillips | 769b488 | 2021-09-07 16:48:46 -0400 | [diff] [blame] | 15 | namespace skgpu::v1 { |
| 16 | |
Chris Dalton | ee40d5a | 2021-07-07 16:34:36 -0600 | [diff] [blame] | 17 | // Fills a rectangle of pixels with a clip against coverage values from an atlas. |
Robert Phillips | 769b488 | 2021-09-07 16:48:46 -0400 | [diff] [blame] | 18 | class DrawAtlasPathOp final : public GrDrawOp { |
Chris Dalton | 4e99853 | 2020-02-10 11:06:42 -0700 | [diff] [blame] | 19 | public: |
| 20 | DEFINE_OP_CLASS_ID |
| 21 | |
Robert Phillips | 769b488 | 2021-09-07 16:48:46 -0400 | [diff] [blame] | 22 | DrawAtlasPathOp(SkArenaAlloc* arena, const SkIRect& fillBounds, const SkMatrix& localToDevice, |
| 23 | GrPaint&& paint, SkIPoint16 locationInAtlas, const SkIRect& pathDevIBounds, |
| 24 | bool transposedInAtlas, GrSurfaceProxyView atlasView, bool isInverseFill) |
Chris Dalton | 4e99853 | 2020-02-10 11:06:42 -0700 | [diff] [blame] | 25 | : GrDrawOp(ClassID()) |
Chris Dalton | ee40d5a | 2021-07-07 16:34:36 -0600 | [diff] [blame] | 26 | , fHeadInstance(arena->make<Instance>(fillBounds, localToDevice, paint.getColor4f(), |
| 27 | locationInAtlas, pathDevIBounds, |
| 28 | transposedInAtlas)) |
| 29 | , fTailInstance(&fHeadInstance->fNext) |
Chris Dalton | b1fd64e | 2021-07-08 15:38:51 -0600 | [diff] [blame] | 30 | , fAtlasHelper(std::move(atlasView), |
Robert Phillips | ef80d7b | 2021-09-14 16:10:56 -0400 | [diff] [blame] | 31 | isInverseFill ? AtlasInstancedHelper::ShaderFlags::kCheckBounds | |
| 32 | AtlasInstancedHelper::ShaderFlags::kInvertCoverage |
| 33 | : AtlasInstancedHelper::ShaderFlags::kNone) |
Chris Dalton | 4e99853 | 2020-02-10 11:06:42 -0700 | [diff] [blame] | 34 | , fProcessors(std::move(paint)) { |
Chris Dalton | ee40d5a | 2021-07-07 16:34:36 -0600 | [diff] [blame] | 35 | this->setBounds(SkRect::Make(fillBounds), HasAABloat::kYes, IsHairline::kNo); |
Chris Dalton | 4e99853 | 2020-02-10 11:06:42 -0700 | [diff] [blame] | 36 | } |
| 37 | |
Robert Phillips | 769b488 | 2021-09-07 16:48:46 -0400 | [diff] [blame] | 38 | const char* name() const override { return "DrawAtlasPathOp"; } |
Chris Dalton | cc29a39 | 2021-07-12 15:16:29 -0600 | [diff] [blame] | 39 | FixedFunctionFlags fixedFunctionFlags() const override { return FixedFunctionFlags::kNone; } |
Robert Phillips | 294723d | 2021-06-17 09:23:58 -0400 | [diff] [blame] | 40 | void visitProxies(const GrVisitProxyFunc& func) const override { |
Chris Dalton | b1fd64e | 2021-07-08 15:38:51 -0600 | [diff] [blame] | 41 | func(fAtlasHelper.proxy(), GrMipmapped::kNo); |
Robert Phillips | 294723d | 2021-06-17 09:23:58 -0400 | [diff] [blame] | 42 | fProcessors.visitProxies(func); |
Chris Dalton | 4e99853 | 2020-02-10 11:06:42 -0700 | [diff] [blame] | 43 | } |
Chris Dalton | 57ab06c | 2021-04-22 12:57:28 -0600 | [diff] [blame] | 44 | GrProcessorSet::Analysis finalize(const GrCaps&, const GrAppliedClip*, GrClampType) override; |
Herb Derby | e25c300 | 2020-10-27 15:57:27 -0400 | [diff] [blame] | 45 | CombineResult onCombineIfPossible(GrOp*, SkArenaAlloc*, const GrCaps&) override; |
Chris Dalton | ee40d5a | 2021-07-07 16:34:36 -0600 | [diff] [blame] | 46 | |
| 47 | void onPrePrepare(GrRecordingContext*, const GrSurfaceProxyView& writeView, GrAppliedClip*, |
| 48 | const GrDstProxyView&, GrXferBarrierFlags, GrLoadOp colorLoadOp) override; |
Chris Dalton | 4e99853 | 2020-02-10 11:06:42 -0700 | [diff] [blame] | 49 | void onPrepare(GrOpFlushState*) override; |
| 50 | void onExecute(GrOpFlushState*, const SkRect& chainBounds) override; |
| 51 | |
| 52 | private: |
Chris Dalton | ee40d5a | 2021-07-07 16:34:36 -0600 | [diff] [blame] | 53 | void prepareProgram(const GrCaps&, SkArenaAlloc*, const GrSurfaceProxyView& writeView, |
Chris Dalton | cc29a39 | 2021-07-12 15:16:29 -0600 | [diff] [blame] | 54 | bool usesMSAASurface, GrAppliedClip&&, const GrDstProxyView&, |
| 55 | GrXferBarrierFlags, GrLoadOp colorLoadOp); |
Robert Phillips | c655c3a | 2020-03-18 13:23:45 -0400 | [diff] [blame] | 56 | |
Chris Dalton | 4e99853 | 2020-02-10 11:06:42 -0700 | [diff] [blame] | 57 | struct Instance { |
Chris Dalton | ee40d5a | 2021-07-07 16:34:36 -0600 | [diff] [blame] | 58 | Instance(const SkIRect& fillIBounds, const SkMatrix& m, |
| 59 | const SkPMColor4f& color, SkIPoint16 locationInAtlas, |
| 60 | const SkIRect& pathDevIBounds, bool transposedInAtlas) |
| 61 | : fFillBounds(fillIBounds) |
| 62 | , fLocalToDeviceIfUsingLocalCoords{m.getScaleX(), m.getSkewY(), |
| 63 | m.getSkewX(), m.getScaleY(), |
| 64 | m.getTranslateX(), m.getTranslateY()} |
Chris Dalton | 4e99853 | 2020-02-10 11:06:42 -0700 | [diff] [blame] | 65 | , fColor(color) |
Chris Dalton | b1fd64e | 2021-07-08 15:38:51 -0600 | [diff] [blame] | 66 | , fAtlasInstance(locationInAtlas, pathDevIBounds, transposedInAtlas) { |
Chris Dalton | 4e99853 | 2020-02-10 11:06:42 -0700 | [diff] [blame] | 67 | } |
Chris Dalton | ee40d5a | 2021-07-07 16:34:36 -0600 | [diff] [blame] | 68 | SkIRect fFillBounds; |
| 69 | std::array<float, 6> fLocalToDeviceIfUsingLocalCoords; |
Chris Dalton | 4e99853 | 2020-02-10 11:06:42 -0700 | [diff] [blame] | 70 | SkPMColor4f fColor; |
Robert Phillips | ef80d7b | 2021-09-14 16:10:56 -0400 | [diff] [blame] | 71 | AtlasInstancedHelper::Instance fAtlasInstance; |
Chris Dalton | baae2dd | 2021-06-25 14:52:49 -0600 | [diff] [blame] | 72 | Instance* fNext = nullptr; |
Chris Dalton | 4e99853 | 2020-02-10 11:06:42 -0700 | [diff] [blame] | 73 | }; |
| 74 | |
Chris Dalton | ee40d5a | 2021-07-07 16:34:36 -0600 | [diff] [blame] | 75 | Instance* fHeadInstance; |
| 76 | Instance** fTailInstance; |
| 77 | |
Robert Phillips | ef80d7b | 2021-09-14 16:10:56 -0400 | [diff] [blame] | 78 | AtlasInstancedHelper fAtlasHelper; |
Chris Dalton | 4e99853 | 2020-02-10 11:06:42 -0700 | [diff] [blame] | 79 | bool fUsesLocalCoords = false; |
| 80 | |
Chris Dalton | 4e99853 | 2020-02-10 11:06:42 -0700 | [diff] [blame] | 81 | int fInstanceCount = 1; |
| 82 | |
Chris Dalton | baae2dd | 2021-06-25 14:52:49 -0600 | [diff] [blame] | 83 | GrProgramInfo* fProgram = nullptr; |
| 84 | |
Chris Dalton | 4e99853 | 2020-02-10 11:06:42 -0700 | [diff] [blame] | 85 | sk_sp<const GrBuffer> fInstanceBuffer; |
| 86 | int fBaseInstance; |
| 87 | |
Chris Dalton | a05ccc3 | 2021-06-29 19:42:13 -0600 | [diff] [blame] | 88 | // Only used if sk_VertexID is not supported. |
| 89 | sk_sp<const GrGpuBuffer> fVertexBufferIfNoIDSupport; |
| 90 | |
Chris Dalton | 4e99853 | 2020-02-10 11:06:42 -0700 | [diff] [blame] | 91 | GrProcessorSet fProcessors; |
| 92 | }; |
| 93 | |
Robert Phillips | 769b488 | 2021-09-07 16:48:46 -0400 | [diff] [blame] | 94 | } // namespace skgpu::v1 |
| 95 | |
| 96 | #endif // DrawAtlasPathOp_DEFINED |