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 | 4e99853 | 2020-02-10 11:06:42 -0700 | [diff] [blame] | 12 | #include "src/gpu/ops/GrDrawOp.h" |
| 13 | |
| 14 | class GrDrawAtlasPathOp : public GrDrawOp { |
| 15 | public: |
| 16 | DEFINE_OP_CLASS_ID |
| 17 | |
| 18 | GrDrawAtlasPathOp(int numRenderTargetSamples, sk_sp<GrTextureProxy> atlasProxy, |
Chris Dalton | d2dc8dd | 2020-05-19 16:32:02 -0600 | [diff] [blame^] | 19 | const SkIRect& devIBounds, const SkIPoint16& locationInAtlas, |
| 20 | bool transposedInAtlas, const SkMatrix& viewMatrix, GrPaint&& paint) |
Chris Dalton | 4e99853 | 2020-02-10 11:06:42 -0700 | [diff] [blame] | 21 | : GrDrawOp(ClassID()) |
| 22 | , fEnableHWAA(numRenderTargetSamples > 1) |
| 23 | , fAtlasProxy(std::move(atlasProxy)) |
Chris Dalton | d2dc8dd | 2020-05-19 16:32:02 -0600 | [diff] [blame^] | 24 | , fInstanceList(devIBounds, locationInAtlas, transposedInAtlas, paint.getColor4f(), |
| 25 | viewMatrix) |
Chris Dalton | 4e99853 | 2020-02-10 11:06:42 -0700 | [diff] [blame] | 26 | , fProcessors(std::move(paint)) { |
Chris Dalton | 4e99853 | 2020-02-10 11:06:42 -0700 | [diff] [blame] | 27 | this->setBounds(SkRect::Make(devIBounds), HasAABloat::kYes, IsHairline::kNo); |
| 28 | } |
| 29 | |
| 30 | const char* name() const override { return "GrDrawAtlasPathOp"; } |
| 31 | FixedFunctionFlags fixedFunctionFlags() const override { |
| 32 | return (fEnableHWAA) ? FixedFunctionFlags::kUsesHWAA : FixedFunctionFlags::kNone; |
| 33 | } |
| 34 | void visitProxies(const VisitProxyFunc& fn) const override { |
| 35 | fn(fAtlasProxy.get(), GrMipMapped::kNo); |
| 36 | fProcessors.visitProxies(fn); |
| 37 | } |
| 38 | GrProcessorSet::Analysis finalize(const GrCaps&, const GrAppliedClip*, |
| 39 | bool hasMixedSampledCoverage, GrClampType) override; |
| 40 | CombineResult onCombineIfPossible(GrOp*, GrRecordingContext::Arenas*, const GrCaps&) override; |
| 41 | void onPrepare(GrOpFlushState*) override; |
| 42 | void onExecute(GrOpFlushState*, const SkRect& chainBounds) override; |
| 43 | |
| 44 | private: |
Robert Phillips | c655c3a | 2020-03-18 13:23:45 -0400 | [diff] [blame] | 45 | void onPrePrepare(GrRecordingContext*, |
Brian Salomon | 8afde5f | 2020-04-01 16:22:00 -0400 | [diff] [blame] | 46 | const GrSurfaceProxyView* writeView, |
Robert Phillips | c655c3a | 2020-03-18 13:23:45 -0400 | [diff] [blame] | 47 | GrAppliedClip*, |
| 48 | const GrXferProcessor::DstProxyView&) override; |
| 49 | |
Chris Dalton | 4e99853 | 2020-02-10 11:06:42 -0700 | [diff] [blame] | 50 | struct Instance { |
| 51 | constexpr static size_t Stride(bool usesLocalCoords) { |
| 52 | size_t stride = sizeof(Instance); |
| 53 | if (!usesLocalCoords) { |
| 54 | stride -= sizeof(Instance::fViewMatrixIfUsingLocalCoords); |
| 55 | } |
| 56 | return stride; |
| 57 | } |
Chris Dalton | d2dc8dd | 2020-05-19 16:32:02 -0600 | [diff] [blame^] | 58 | Instance(const SkIRect& devIBounds, const SkIPoint16& locationInAtlas, |
| 59 | bool transposedInAtlas, const SkPMColor4f& color, const SkMatrix& m) |
| 60 | : fDevXYWH{devIBounds.left(), devIBounds.top(), devIBounds.width(), |
| 61 | // We use negative height to indicate that the path is transposed. |
| 62 | (transposedInAtlas) ? -devIBounds.height() : devIBounds.height()} |
| 63 | , fAtlasXY{locationInAtlas.x(), locationInAtlas.y()} |
Chris Dalton | 4e99853 | 2020-02-10 11:06:42 -0700 | [diff] [blame] | 64 | , fColor(color) |
| 65 | , fViewMatrixIfUsingLocalCoords{m.getScaleX(), m.getSkewY(), |
| 66 | m.getSkewX(), m.getScaleY(), |
| 67 | m.getTranslateX(), m.getTranslateY()} { |
| 68 | } |
Chris Dalton | d2dc8dd | 2020-05-19 16:32:02 -0600 | [diff] [blame^] | 69 | std::array<int, 4> fDevXYWH; |
| 70 | std::array<int, 2> fAtlasXY; |
Chris Dalton | 4e99853 | 2020-02-10 11:06:42 -0700 | [diff] [blame] | 71 | SkPMColor4f fColor; |
| 72 | float fViewMatrixIfUsingLocalCoords[6]; |
| 73 | }; |
| 74 | |
| 75 | struct InstanceList { |
Chris Dalton | d2dc8dd | 2020-05-19 16:32:02 -0600 | [diff] [blame^] | 76 | InstanceList(const SkIRect& devIBounds, const SkIPoint16& locationInAtlas, |
| 77 | bool transposedInAtlas, const SkPMColor4f& color, const SkMatrix& viewMatrix) |
| 78 | : fInstance(devIBounds, locationInAtlas, transposedInAtlas, color, viewMatrix) { |
Chris Dalton | 4e99853 | 2020-02-10 11:06:42 -0700 | [diff] [blame] | 79 | } |
| 80 | InstanceList* fNext = nullptr; |
| 81 | Instance fInstance; |
| 82 | }; |
| 83 | |
| 84 | const bool fEnableHWAA; |
| 85 | const sk_sp<GrTextureProxy> fAtlasProxy; |
| 86 | bool fUsesLocalCoords = false; |
| 87 | |
| 88 | InstanceList fInstanceList; |
| 89 | InstanceList** fInstanceTail = &fInstanceList.fNext; |
| 90 | int fInstanceCount = 1; |
| 91 | |
| 92 | sk_sp<const GrBuffer> fInstanceBuffer; |
| 93 | int fBaseInstance; |
| 94 | |
| 95 | GrProcessorSet fProcessors; |
| 96 | }; |
| 97 | |
| 98 | #endif |