1/*
2 * Copyright 2015 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 GrDrawAtlasOp_DEFINED
9#define GrDrawAtlasOp_DEFINED
10
11#include "GrColor.h"
12#include "GrDefaultGeoProcFactory.h"
13#include "GrMeshDrawOp.h"
14#include "GrSimpleMeshDrawOpHelper.h"
15
16class GrDrawAtlasOp final : public GrMeshDrawOp {
17private:
18    using Helper = GrSimpleMeshDrawOpHelper;
19
20public:
21    DEFINE_OP_CLASS_ID
22
23    static std::unique_ptr<GrDrawOp> Make(GrPaint&& paint, const SkMatrix& viewMatrix,
24                                          GrAAType aaType, int spriteCount, const SkRSXform* xforms,
25                                          const SkRect* rects, const SkColor* colors) {
26        return Helper::FactoryHelper<GrDrawAtlasOp>(std::move(paint), viewMatrix, aaType,
27                                                    spriteCount, xforms, rects, colors);
28    }
29
30    GrDrawAtlasOp(const Helper::MakeArgs& helperArgs, GrColor color, const SkMatrix& viewMatrix,
31                  GrAAType, int spriteCount, const SkRSXform* xforms, const SkRect* rects,
32                  const SkColor* colors);
33
34    const char* name() const override { return "DrawAtlasOp"; }
35
36    void visitProxies(const VisitProxyFunc& func) const override {
37        fHelper.visitProxies(func);
38    }
39
40    SkString dumpInfo() const override;
41
42    FixedFunctionFlags fixedFunctionFlags() const override;
43
44    RequiresDstTexture finalize(const GrCaps& caps, const GrAppliedClip* clip,
45                                GrPixelConfigIsClamped dstIsClamped) override;
46
47private:
48    void onPrepareDraws(Target*) override;
49
50    GrColor color() const { return fColor; }
51    const SkMatrix& viewMatrix() const { return fViewMatrix; }
52    bool hasColors() const { return fHasColors; }
53    int quadCount() const { return fQuadCount; }
54
55    bool onCombineIfPossible(GrOp* t, const GrCaps&) override;
56
57    struct Geometry {
58        GrColor fColor;
59        SkTArray<uint8_t, true> fVerts;
60    };
61
62    SkSTArray<1, Geometry, true> fGeoData;
63    Helper fHelper;
64    SkMatrix fViewMatrix;
65    GrColor fColor;
66    int fQuadCount;
67    bool fHasColors;
68
69    typedef GrMeshDrawOp INHERITED;
70};
71
72#endif
73