aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/gpu/ccpr/GrCCDrawPathsOp.h
blob: 071a21a614f10f617868d971c505caab6ef5d525 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
/*
 * Copyright 2018 Google Inc.
 *
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 */

#ifndef GrCCDrawPathsOp_DEFINED
#define GrCCDrawPathsOp_DEFINED

#include "SkTInternalLList.h"
#include "ccpr/GrCCPathProcessor.h"
#include "ccpr/GrCCSTLList.h"
#include "ops/GrDrawOp.h"

struct GrCCPerFlushResourceSpecs;
class GrCCAtlas;
class GrCCPerFlushResources;
class GrCCPerOpListPaths;

/**
 * This is the Op that draws paths to the actual canvas, using atlases generated by CCPR.
 */
class GrCCDrawPathsOp : public GrDrawOp {
public:
    DEFINE_OP_CLASS_ID
    SK_DECLARE_INTERNAL_LLIST_INTERFACE(GrCCDrawPathsOp);

    static std::unique_ptr<GrCCDrawPathsOp> Make(GrContext*, const SkIRect& clipIBounds,
                                                 const SkMatrix&, const SkPath&,
                                                 const SkRect& devBounds, GrPaint&&);
    ~GrCCDrawPathsOp() override;

    const char* name() const override { return "GrCCDrawOp"; }
    FixedFunctionFlags fixedFunctionFlags() const override { return FixedFunctionFlags::kNone; }
    RequiresDstTexture finalize(const GrCaps&, const GrAppliedClip*,
                                GrPixelConfigIsClamped) override;
    bool onCombineIfPossible(GrOp* other, const GrCaps& caps) override;
    void visitProxies(const VisitProxyFunc& func) const override {
        fProcessors.visitProxies(func);
    }
    void onPrepare(GrOpFlushState*) override {}

    void wasRecorded(GrCCPerOpListPaths* owningPerOpListPaths);
    void accountForOwnPaths(GrCCPerFlushResourceSpecs*) const;
    void setupResources(GrCCPerFlushResources*, GrOnFlushResourceProvider*);
    SkDEBUGCODE(int numSkippedInstances_debugOnly() const { return fNumSkippedInstances; })

    void onExecute(GrOpFlushState*) override;

private:
    friend class GrOpMemoryPool;

    GrCCDrawPathsOp(const SkIRect& looseClippedIBounds, const SkMatrix&, const SkPath&,
                    const SkRect& devBounds, GrPaint&&);

    struct InstanceRange {
        const GrTextureProxy* fAtlasProxy;
        int fEndInstanceIdx;
    };

    void recordInstanceRange(const GrTextureProxy* atlasProxy, int endInstanceIdx) {
        SkASSERT(endInstanceIdx > fBaseInstance);
        SkASSERT(fInstanceRanges.empty() ||
                 endInstanceIdx > fInstanceRanges.back().fEndInstanceIdx);
        fInstanceRanges.push_back() = {atlasProxy, endInstanceIdx};
    }

    const SkMatrix fViewMatrixIfUsingLocalCoords;
    const uint32_t fSRGBFlags;

    struct SingleDraw {
        SkIRect fLooseClippedIBounds;
        SkMatrix fMatrix;
        SkPath fPath;
        GrColor fColor;
        SingleDraw* fNext;
    };

    GrCCSTLList<SingleDraw> fDraws;
    SkDEBUGCODE(int fNumDraws = 1);

    GrCCPerOpListPaths* fOwningPerOpListPaths = nullptr;
    GrProcessorSet fProcessors;

    int fBaseInstance;
    SkSTArray<1, InstanceRange, true> fInstanceRanges;
    SkDEBUGCODE(int fNumSkippedInstances = 0);
};

#endif