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