blob: 449882c356c1d50c71b5460a8b528d9bb1afffa3 [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
jvanverth14b88032015-08-07 12:18:54 -070011#include "GrColor.h"
12#include "GrDefaultGeoProcFactory.h"
bsalomon16b99132015-08-13 14:55:50 -070013#include "GrVertexBatch.h"
jvanverth14b88032015-08-07 12:18:54 -070014
bsalomonabd30f52015-08-13 13:34:48 -070015class GrDrawAtlasBatch : public GrVertexBatch {
jvanverth14b88032015-08-07 12:18:54 -070016public:
Brian Salomon25a88092016-12-01 09:36:50 -050017 DEFINE_OP_CLASS_ID
reed1b55a962015-09-17 20:16:13 -070018
bsalomon0432dd62016-06-30 07:19:27 -070019 GrDrawAtlasBatch(GrColor color, const SkMatrix& viewMatrix, int spriteCount,
20 const SkRSXform* xforms, const SkRect* rects, const SkColor* colors);
halcanary9d524f22016-03-29 09:03:52 -070021
jvanverth14b88032015-08-07 12:18:54 -070022 const char* name() const override { return "DrawAtlasBatch"; }
halcanary9d524f22016-03-29 09:03:52 -070023
Brian Salomon7c3e7182016-12-01 09:35:30 -050024 SkString dumpInfo() const override {
25 SkString string;
26 for (const auto& geo : fGeoData) {
27 string.appendf("Color: 0x%08x, Quads: %d\n", geo.fColor, geo.fVerts.count() / 4);
28 }
29 string.append(DumpPipelineInfo(*this->pipeline()));
30 string.append(INHERITED::dumpInfo());
31 return string;
32 }
33
halcanary9d524f22016-03-29 09:03:52 -070034 void computePipelineOptimizations(GrInitInvariantOutput* color,
ethannicholasff210322015-11-24 12:10:10 -080035 GrInitInvariantOutput* coverage,
36 GrBatchToXPOverrides* overrides) const override {
jvanverth14b88032015-08-07 12:18:54 -070037 // When this is called on a batch, there is only one geometry bundle
38 if (this->hasColors()) {
ethannicholasff210322015-11-24 12:10:10 -080039 color->setUnknownFourComponents();
jvanverth14b88032015-08-07 12:18:54 -070040 } else {
ethannicholasff210322015-11-24 12:10:10 -080041 color->setKnownFourComponents(fGeoData[0].fColor);
jvanverth14b88032015-08-07 12:18:54 -070042 }
ethannicholasff210322015-11-24 12:10:10 -080043 coverage->setKnownSingleComponent(0xff);
jvanverth14b88032015-08-07 12:18:54 -070044 }
bsalomone46f9fe2015-08-18 06:05:14 -070045
jvanverth14b88032015-08-07 12:18:54 -070046private:
joshualitt144c3c82015-11-30 12:30:13 -080047 void onPrepareDraws(Target*) const override;
bsalomon75398562015-08-17 12:55:38 -070048
ethannicholasff210322015-11-24 12:10:10 -080049 void initBatchTracker(const GrXPOverridesForBatch&) override;
bsalomone46f9fe2015-08-18 06:05:14 -070050
jvanverth14b88032015-08-07 12:18:54 -070051 GrColor color() const { return fColor; }
52 bool colorIgnored() const { return fColorIgnored; }
53 const SkMatrix& viewMatrix() const { return fViewMatrix; }
54 bool hasColors() const { return fHasColors; }
jvanverth5a4d2352015-08-12 08:15:31 -070055 int quadCount() const { return fQuadCount; }
jvanverth14b88032015-08-07 12:18:54 -070056 bool coverageIgnored() const { return fCoverageIgnored; }
halcanary9d524f22016-03-29 09:03:52 -070057
Brian Salomon25a88092016-12-01 09:36:50 -050058 bool onCombineIfPossible(GrOp* t, const GrCaps&) override;
bsalomon0432dd62016-06-30 07:19:27 -070059
60 struct Geometry {
61 GrColor fColor;
62 SkTArray<uint8_t, true> fVerts;
63 };
64
jvanverth14b88032015-08-07 12:18:54 -070065 SkSTArray<1, Geometry, true> fGeoData;
halcanary9d524f22016-03-29 09:03:52 -070066
jvanverth14b88032015-08-07 12:18:54 -070067 SkMatrix fViewMatrix;
68 GrColor fColor;
jvanverth5a4d2352015-08-12 08:15:31 -070069 int fQuadCount;
jvanverth14b88032015-08-07 12:18:54 -070070 bool fColorIgnored;
71 bool fCoverageIgnored;
72 bool fHasColors;
reed1b55a962015-09-17 20:16:13 -070073
74 typedef GrVertexBatch INHERITED;
jvanverth14b88032015-08-07 12:18:54 -070075};
76
77#endif