blob: bc882b2bfa55289191c02d8c07d13809acf809b6 [file] [log] [blame]
jvanverth14b88032015-08-07 12:18:54 -07001/*
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 GrDrawAtlasBatch_DEFINED
9#define GrDrawAtlasBatch_DEFINED
10
11#include "GrBatch.h"
12#include "GrColor.h"
13#include "GrDefaultGeoProcFactory.h"
14
15class GrDrawAtlasBatch : public GrBatch {
16public:
17 struct Geometry {
jvanverth5a4d2352015-08-12 08:15:31 -070018 GrColor fColor;
19 SkTArray<uint8_t, true> fVerts;
jvanverth14b88032015-08-07 12:18:54 -070020 };
21
jvanverth5a4d2352015-08-12 08:15:31 -070022 static GrBatch* Create(const Geometry& geometry, const SkMatrix& viewMatrix, int spriteCount,
23 const SkRSXform* xforms, const SkRect* rects, const SkColor* colors) {
24 return SkNEW_ARGS(GrDrawAtlasBatch, (geometry, viewMatrix, spriteCount,
25 xforms, rects, colors));
jvanverth14b88032015-08-07 12:18:54 -070026 }
27
28 const char* name() const override { return "DrawAtlasBatch"; }
29
30 void getInvariantOutputColor(GrInitInvariantOutput* out) const override {
31 // When this is called on a batch, there is only one geometry bundle
32 if (this->hasColors()) {
33 out->setUnknownFourComponents();
34 } else {
35 out->setKnownFourComponents(fGeoData[0].fColor);
36 }
37 }
38
39 void getInvariantOutputCoverage(GrInitInvariantOutput* out) const override {
40 out->setKnownSingleComponent(0xff);
41 }
42
bsalomon91d844d2015-08-10 10:47:29 -070043 void initBatchTracker(const GrPipelineOptimizations&) override;
jvanverth14b88032015-08-07 12:18:54 -070044 void generateGeometry(GrBatchTarget* batchTarget) override;
45
46 SkSTArray<1, Geometry, true>* geoData() { return &fGeoData; }
47
48private:
jvanverth5a4d2352015-08-12 08:15:31 -070049 GrDrawAtlasBatch(const Geometry& geometry, const SkMatrix& viewMatrix, int spriteCount,
50 const SkRSXform* xforms, const SkRect* rects, const SkColor* colors);
jvanverth14b88032015-08-07 12:18:54 -070051
52 GrColor color() const { return fColor; }
53 bool colorIgnored() const { return fColorIgnored; }
54 const SkMatrix& viewMatrix() const { return fViewMatrix; }
55 bool hasColors() const { return fHasColors; }
jvanverth5a4d2352015-08-12 08:15:31 -070056 int quadCount() const { return fQuadCount; }
jvanverth14b88032015-08-07 12:18:54 -070057 bool coverageIgnored() const { return fCoverageIgnored; }
58
59 bool onCombineIfPossible(GrBatch* t) override;
60 SkSTArray<1, Geometry, true> fGeoData;
61
62 SkMatrix fViewMatrix;
63 GrColor fColor;
jvanverth5a4d2352015-08-12 08:15:31 -070064 int fQuadCount;
jvanverth14b88032015-08-07 12:18:54 -070065 bool fColorIgnored;
66 bool fCoverageIgnored;
67 bool fHasColors;
68};
69
70#endif