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