blob: 1448ef9f2524798aa2acfc72afa97b8a2755d939 [file] [log] [blame]
Chris Dalton4e998532020-02-10 11:06:42 -07001/*
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 Daltond2dc8dd2020-05-19 16:32:02 -060011#include "src/core/SkIPoint16.h"
Chris Dalton4e998532020-02-10 11:06:42 -070012#include "src/gpu/ops/GrDrawOp.h"
13
14class GrDrawAtlasPathOp : public GrDrawOp {
15public:
16 DEFINE_OP_CLASS_ID
17
18 GrDrawAtlasPathOp(int numRenderTargetSamples, sk_sp<GrTextureProxy> atlasProxy,
Chris Daltond2dc8dd2020-05-19 16:32:02 -060019 const SkIRect& devIBounds, const SkIPoint16& locationInAtlas,
20 bool transposedInAtlas, const SkMatrix& viewMatrix, GrPaint&& paint)
Chris Dalton4e998532020-02-10 11:06:42 -070021 : GrDrawOp(ClassID())
22 , fEnableHWAA(numRenderTargetSamples > 1)
23 , fAtlasProxy(std::move(atlasProxy))
Chris Daltond2dc8dd2020-05-19 16:32:02 -060024 , fInstanceList(devIBounds, locationInAtlas, transposedInAtlas, paint.getColor4f(),
25 viewMatrix)
Chris Dalton4e998532020-02-10 11:06:42 -070026 , fProcessors(std::move(paint)) {
Chris Dalton4e998532020-02-10 11:06:42 -070027 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 {
Brian Salomon7e67dca2020-07-21 09:27:25 -040035 fn(fAtlasProxy.get(), GrMipmapped::kNo);
Chris Dalton4e998532020-02-10 11:06:42 -070036 fProcessors.visitProxies(fn);
37 }
38 GrProcessorSet::Analysis finalize(const GrCaps&, const GrAppliedClip*,
39 bool hasMixedSampledCoverage, GrClampType) override;
Herb Derbye25c3002020-10-27 15:57:27 -040040 CombineResult onCombineIfPossible(GrOp*, SkArenaAlloc*, const GrCaps&) override;
Chris Dalton4e998532020-02-10 11:06:42 -070041 void onPrepare(GrOpFlushState*) override;
42 void onExecute(GrOpFlushState*, const SkRect& chainBounds) override;
43
44private:
Robert Phillipsc655c3a2020-03-18 13:23:45 -040045 void onPrePrepare(GrRecordingContext*,
Brian Salomon8afde5f2020-04-01 16:22:00 -040046 const GrSurfaceProxyView* writeView,
Robert Phillipsc655c3a2020-03-18 13:23:45 -040047 GrAppliedClip*,
Greg Danield358cbe2020-09-11 09:33:54 -040048 const GrXferProcessor::DstProxyView&,
49 GrXferBarrierFlags renderPassXferBarriers) override;
Robert Phillipsc655c3a2020-03-18 13:23:45 -040050
Chris Dalton4e998532020-02-10 11:06:42 -070051 struct Instance {
52 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 }
Chris Daltond2dc8dd2020-05-19 16:32:02 -060059 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()}
Chris Dalton4e998532020-02-10 11:06:42 -070065 , fColor(color)
66 , fViewMatrixIfUsingLocalCoords{m.getScaleX(), m.getSkewY(),
67 m.getSkewX(), m.getScaleY(),
68 m.getTranslateX(), m.getTranslateY()} {
69 }
Chris Daltond2dc8dd2020-05-19 16:32:02 -060070 std::array<int, 4> fDevXYWH;
71 std::array<int, 2> fAtlasXY;
Chris Dalton4e998532020-02-10 11:06:42 -070072 SkPMColor4f fColor;
73 float fViewMatrixIfUsingLocalCoords[6];
74 };
75
76 struct InstanceList {
Chris Daltond2dc8dd2020-05-19 16:32:02 -060077 InstanceList(const SkIRect& devIBounds, const SkIPoint16& locationInAtlas,
78 bool transposedInAtlas, const SkPMColor4f& color, const SkMatrix& viewMatrix)
79 : fInstance(devIBounds, locationInAtlas, transposedInAtlas, color, viewMatrix) {
Chris Dalton4e998532020-02-10 11:06:42 -070080 }
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