blob: b20583ba41ca29006d5262a143aca229c8f7f826 [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
11#include "src/gpu/ops/GrDrawOp.h"
12
13class GrDrawAtlasPathOp : public GrDrawOp {
14public:
15 DEFINE_OP_CLASS_ID
16
17 GrDrawAtlasPathOp(int numRenderTargetSamples, sk_sp<GrTextureProxy> atlasProxy,
18 const SkIRect& devIBounds, const SkIVector& devToAtlasOffset,
19 const SkMatrix& viewMatrix, GrPaint&& paint)
20 : GrDrawOp(ClassID())
21 , fEnableHWAA(numRenderTargetSamples > 1)
22 , fAtlasProxy(std::move(atlasProxy))
23 , fInstanceList(devIBounds, devToAtlasOffset, paint.getColor4f(), viewMatrix)
24 , fProcessors(std::move(paint)) {
Chris Dalton4e998532020-02-10 11:06:42 -070025 this->setBounds(SkRect::Make(devIBounds), HasAABloat::kYes, IsHairline::kNo);
26 }
27
28 const char* name() const override { return "GrDrawAtlasPathOp"; }
29 FixedFunctionFlags fixedFunctionFlags() const override {
30 return (fEnableHWAA) ? FixedFunctionFlags::kUsesHWAA : FixedFunctionFlags::kNone;
31 }
32 void visitProxies(const VisitProxyFunc& fn) const override {
33 fn(fAtlasProxy.get(), GrMipMapped::kNo);
34 fProcessors.visitProxies(fn);
35 }
36 GrProcessorSet::Analysis finalize(const GrCaps&, const GrAppliedClip*,
37 bool hasMixedSampledCoverage, GrClampType) override;
38 CombineResult onCombineIfPossible(GrOp*, GrRecordingContext::Arenas*, const GrCaps&) override;
39 void onPrepare(GrOpFlushState*) override;
40 void onExecute(GrOpFlushState*, const SkRect& chainBounds) override;
41
42private:
Robert Phillipsc655c3a2020-03-18 13:23:45 -040043 void onPrePrepare(GrRecordingContext*,
Brian Salomon8afde5f2020-04-01 16:22:00 -040044 const GrSurfaceProxyView* writeView,
Robert Phillipsc655c3a2020-03-18 13:23:45 -040045 GrAppliedClip*,
46 const GrXferProcessor::DstProxyView&) override;
47
Chris Dalton4e998532020-02-10 11:06:42 -070048 struct Instance {
49 constexpr static size_t Stride(bool usesLocalCoords) {
50 size_t stride = sizeof(Instance);
51 if (!usesLocalCoords) {
52 stride -= sizeof(Instance::fViewMatrixIfUsingLocalCoords);
53 }
54 return stride;
55 }
56 Instance(const SkIRect& devIBounds, SkIVector devToAtlasOffset, const SkPMColor4f& color,
57 const SkMatrix& m)
58 : fDevIBounds(devIBounds)
59 , fDevToAtlasOffset(devToAtlasOffset)
60 , fColor(color)
61 , fViewMatrixIfUsingLocalCoords{m.getScaleX(), m.getSkewY(),
62 m.getSkewX(), m.getScaleY(),
63 m.getTranslateX(), m.getTranslateY()} {
64 }
65 SkIRect fDevIBounds;
66 SkIVector fDevToAtlasOffset;
67 SkPMColor4f fColor;
68 float fViewMatrixIfUsingLocalCoords[6];
69 };
70
71 struct InstanceList {
72 InstanceList(const SkIRect& devIBounds, SkIVector devToAtlasOffset,
73 const SkPMColor4f& color, const SkMatrix& viewMatrix)
74 : fInstance(devIBounds, devToAtlasOffset, color, viewMatrix) {
75 }
76 InstanceList* fNext = nullptr;
77 Instance fInstance;
78 };
79
80 const bool fEnableHWAA;
81 const sk_sp<GrTextureProxy> fAtlasProxy;
82 bool fUsesLocalCoords = false;
83
84 InstanceList fInstanceList;
85 InstanceList** fInstanceTail = &fInstanceList.fNext;
86 int fInstanceCount = 1;
87
88 sk_sp<const GrBuffer> fInstanceBuffer;
89 int fBaseInstance;
90
91 GrProcessorSet fProcessors;
92};
93
94#endif