aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/gpu/ops/GrDrawAtlasOp.h
blob: 90fe07fda2b06aaec060d52af667635be73a8519 (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
/*
 * Copyright 2015 Google Inc.
 *
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 */

#ifndef GrDrawAtlasOp_DEFINED
#define GrDrawAtlasOp_DEFINED

#include "GrColor.h"
#include "GrDefaultGeoProcFactory.h"
#include "GrMeshDrawOp.h"

class GrDrawAtlasOp final : public GrMeshDrawOp {
public:
    DEFINE_OP_CLASS_ID

    static std::unique_ptr<GrDrawOp> Make(GrColor color, const SkMatrix& viewMatrix,
                                          int spriteCount, const SkRSXform* xforms,
                                          const SkRect* rects, const SkColor* colors) {
        return std::unique_ptr<GrDrawOp>(
                new GrDrawAtlasOp(color, viewMatrix, spriteCount, xforms, rects, colors));
    }

    const char* name() const override { return "DrawAtlasOp"; }

    SkString dumpInfo() const override {
        SkString string;
        for (const auto& geo : fGeoData) {
            string.appendf("Color: 0x%08x, Quads: %d\n", geo.fColor, geo.fVerts.count() / 4);
        }
        string.append(DumpPipelineInfo(*this->pipeline()));
        string.append(INHERITED::dumpInfo());
        return string;
    }

private:
    GrDrawAtlasOp(GrColor color, const SkMatrix& viewMatrix, int spriteCount,
                  const SkRSXform* xforms, const SkRect* rects, const SkColor* colors);

    void getPipelineAnalysisInput(GrPipelineAnalysisDrawOpInput* input) const override {
        if (this->hasColors()) {
            input->pipelineColorInput()->setToUnknown();
        } else {
            input->pipelineColorInput()->setToConstant(fGeoData[0].fColor);
        }
        input->pipelineCoverageInput()->setToSolidCoverage();
    }

    void onPrepareDraws(Target*) const override;

    void applyPipelineOptimizations(const GrPipelineOptimizations&) override;

    GrColor color() const { return fColor; }
    const SkMatrix& viewMatrix() const { return fViewMatrix; }
    bool hasColors() const { return fHasColors; }
    int quadCount() const { return fQuadCount; }

    bool onCombineIfPossible(GrOp* t, const GrCaps&) override;

    struct Geometry {
        GrColor fColor;
        SkTArray<uint8_t, true> fVerts;
    };

    SkSTArray<1, Geometry, true> fGeoData;

    SkMatrix fViewMatrix;
    GrColor fColor;
    int fQuadCount;
    bool fHasColors;

    typedef GrMeshDrawOp INHERITED;
};

#endif