aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/gpu/batches/GrDrawVerticesBatch.h
blob: 9b2faf3d3dbafbd14a3f856a7fe3abb7805bddc6 (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
/*
 * 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 GrDrawVerticesBatch_DEFINED
#define GrDrawVerticesBatch_DEFINED

#include "GrColor.h"
#include "GrTypes.h"
#include "GrVertexBatch.h"
#include "SkMatrix.h"
#include "SkRect.h"
#include "SkTDArray.h"

class GrBatchFlushState;
struct GrInitInvariantOutput;

class GrDrawVerticesBatch : public GrVertexBatch {
public:
    DEFINE_BATCH_CLASS_ID

    struct Geometry {
        GrColor fColor; // Only used if there are no per-vertex colors
        SkTDArray<SkPoint> fPositions;
        SkTDArray<uint16_t> fIndices;
        SkTDArray<GrColor> fColors;
        SkTDArray<SkPoint> fLocalCoords;
    };

    static GrDrawBatch* Create(const Geometry& geometry, GrPrimitiveType primitiveType,
                               const SkMatrix& viewMatrix,
                               const SkPoint* positions, int vertexCount,
                               const uint16_t* indices, int indexCount,
                               const GrColor* colors, const SkPoint* localCoords,
                               const SkRect& bounds) {
        return new GrDrawVerticesBatch(geometry, primitiveType, viewMatrix, positions, vertexCount,
                                       indices, indexCount, colors, localCoords, bounds);
    }

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

    void computePipelineOptimizations(GrInitInvariantOutput* color, 
                                      GrInitInvariantOutput* coverage,
                                      GrBatchToXPOverrides* overrides) const override;

    SkSTArray<1, Geometry, true>* geoData() { return &fGeoData; }

private:
    void onPrepareDraws(Target*) const override;
    void initBatchTracker(const GrXPOverridesForBatch&) override;

    GrDrawVerticesBatch(const Geometry& geometry, GrPrimitiveType primitiveType,
                        const SkMatrix& viewMatrix,
                        const SkPoint* positions, int vertexCount,
                        const uint16_t* indices, int indexCount,
                        const GrColor* colors, const SkPoint* localCoords, const SkRect& bounds);

    GrPrimitiveType primitiveType() const { return fPrimitiveType; }
    bool batchablePrimitiveType() const {
        return kTriangles_GrPrimitiveType == fPrimitiveType ||
               kLines_GrPrimitiveType == fPrimitiveType ||
               kPoints_GrPrimitiveType == fPrimitiveType;
    }

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

    GrPrimitiveType     fPrimitiveType;
    SkMatrix            fViewMatrix;
    bool                fVariableColor;
    int                 fVertexCount;
    int                 fIndexCount;
    bool                fCoverageIgnored; // comes from initBatchTracker.

    SkSTArray<1, Geometry, true> fGeoData;

    typedef GrVertexBatch INHERITED;
};

#endif