blob: d9adf22a60a986e66247c84148ff8a97e7f4ab0a [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:
reed1b55a962015-09-17 20:16:13 -070017 DEFINE_BATCH_CLASS_ID
18
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
24 void computePipelineOptimizations(GrInitInvariantOutput* color,
ethannicholasff210322015-11-24 12:10:10 -080025 GrInitInvariantOutput* coverage,
26 GrBatchToXPOverrides* overrides) const override {
jvanverth14b88032015-08-07 12:18:54 -070027 // When this is called on a batch, there is only one geometry bundle
28 if (this->hasColors()) {
ethannicholasff210322015-11-24 12:10:10 -080029 color->setUnknownFourComponents();
jvanverth14b88032015-08-07 12:18:54 -070030 } else {
ethannicholasff210322015-11-24 12:10:10 -080031 color->setKnownFourComponents(fGeoData[0].fColor);
jvanverth14b88032015-08-07 12:18:54 -070032 }
ethannicholasff210322015-11-24 12:10:10 -080033 coverage->setKnownSingleComponent(0xff);
jvanverth14b88032015-08-07 12:18:54 -070034 }
bsalomone46f9fe2015-08-18 06:05:14 -070035
jvanverth14b88032015-08-07 12:18:54 -070036private:
joshualitt144c3c82015-11-30 12:30:13 -080037 void onPrepareDraws(Target*) const override;
bsalomon75398562015-08-17 12:55:38 -070038
ethannicholasff210322015-11-24 12:10:10 -080039 void initBatchTracker(const GrXPOverridesForBatch&) override;
bsalomone46f9fe2015-08-18 06:05:14 -070040
jvanverth14b88032015-08-07 12:18:54 -070041 GrColor color() const { return fColor; }
42 bool colorIgnored() const { return fColorIgnored; }
43 const SkMatrix& viewMatrix() const { return fViewMatrix; }
44 bool hasColors() const { return fHasColors; }
jvanverth5a4d2352015-08-12 08:15:31 -070045 int quadCount() const { return fQuadCount; }
jvanverth14b88032015-08-07 12:18:54 -070046 bool coverageIgnored() const { return fCoverageIgnored; }
halcanary9d524f22016-03-29 09:03:52 -070047
bsalomoncb02b382015-08-12 11:14:50 -070048 bool onCombineIfPossible(GrBatch* t, const GrCaps&) override;
bsalomon0432dd62016-06-30 07:19:27 -070049
50 struct Geometry {
51 GrColor fColor;
52 SkTArray<uint8_t, true> fVerts;
53 };
54
jvanverth14b88032015-08-07 12:18:54 -070055 SkSTArray<1, Geometry, true> fGeoData;
halcanary9d524f22016-03-29 09:03:52 -070056
jvanverth14b88032015-08-07 12:18:54 -070057 SkMatrix fViewMatrix;
58 GrColor fColor;
jvanverth5a4d2352015-08-12 08:15:31 -070059 int fQuadCount;
jvanverth14b88032015-08-07 12:18:54 -070060 bool fColorIgnored;
61 bool fCoverageIgnored;
62 bool fHasColors;
reed1b55a962015-09-17 20:16:13 -070063
64 typedef GrVertexBatch INHERITED;
jvanverth14b88032015-08-07 12:18:54 -070065};
66
67#endif