blob: 9913ec29062335563753639c53f2b742d284ff04 [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
Brian Salomonfc527d22016-12-14 21:07:01 -05008#ifndef GrDrawAtlasOp_DEFINED
9#define GrDrawAtlasOp_DEFINED
jvanverth14b88032015-08-07 12:18:54 -070010
jvanverth14b88032015-08-07 12:18:54 -070011#include "GrColor.h"
12#include "GrDefaultGeoProcFactory.h"
Brian Salomondad29232016-12-01 16:40:24 -050013#include "GrMeshDrawOp.h"
jvanverth14b88032015-08-07 12:18:54 -070014
Brian Salomonfc527d22016-12-14 21:07:01 -050015class GrDrawAtlasOp final : public GrMeshDrawOp {
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
Brian Salomonfc527d22016-12-14 21:07:01 -050019 static sk_sp<GrDrawOp> Make(GrColor color, const SkMatrix& viewMatrix, int spriteCount,
20 const SkRSXform* xforms, const SkRect* rects,
21 const SkColor* colors) {
22 return sk_sp<GrDrawOp>(
23 new GrDrawAtlasOp(color, viewMatrix, spriteCount, xforms, rects, colors));
24 }
halcanary9d524f22016-03-29 09:03:52 -070025
Brian Salomonfc527d22016-12-14 21:07:01 -050026 const char* name() const override { return "DrawAtlasOp"; }
halcanary9d524f22016-03-29 09:03:52 -070027
Brian Salomon7c3e7182016-12-01 09:35:30 -050028 SkString dumpInfo() const override {
29 SkString string;
30 for (const auto& geo : fGeoData) {
31 string.appendf("Color: 0x%08x, Quads: %d\n", geo.fColor, geo.fVerts.count() / 4);
32 }
33 string.append(DumpPipelineInfo(*this->pipeline()));
34 string.append(INHERITED::dumpInfo());
35 return string;
36 }
37
halcanary9d524f22016-03-29 09:03:52 -070038 void computePipelineOptimizations(GrInitInvariantOutput* color,
ethannicholasff210322015-11-24 12:10:10 -080039 GrInitInvariantOutput* coverage,
40 GrBatchToXPOverrides* overrides) const override {
Brian Salomonfc527d22016-12-14 21:07:01 -050041 // When this is called there is only one atlas draw.
jvanverth14b88032015-08-07 12:18:54 -070042 if (this->hasColors()) {
ethannicholasff210322015-11-24 12:10:10 -080043 color->setUnknownFourComponents();
jvanverth14b88032015-08-07 12:18:54 -070044 } else {
ethannicholasff210322015-11-24 12:10:10 -080045 color->setKnownFourComponents(fGeoData[0].fColor);
jvanverth14b88032015-08-07 12:18:54 -070046 }
ethannicholasff210322015-11-24 12:10:10 -080047 coverage->setKnownSingleComponent(0xff);
jvanverth14b88032015-08-07 12:18:54 -070048 }
bsalomone46f9fe2015-08-18 06:05:14 -070049
jvanverth14b88032015-08-07 12:18:54 -070050private:
Brian Salomonfc527d22016-12-14 21:07:01 -050051 GrDrawAtlasOp(GrColor color, const SkMatrix& viewMatrix, int spriteCount,
52 const SkRSXform* xforms, const SkRect* rects, const SkColor* colors);
53
joshualitt144c3c82015-11-30 12:30:13 -080054 void onPrepareDraws(Target*) const override;
bsalomon75398562015-08-17 12:55:38 -070055
ethannicholasff210322015-11-24 12:10:10 -080056 void initBatchTracker(const GrXPOverridesForBatch&) override;
bsalomone46f9fe2015-08-18 06:05:14 -070057
jvanverth14b88032015-08-07 12:18:54 -070058 GrColor color() const { return fColor; }
59 bool colorIgnored() const { return fColorIgnored; }
60 const SkMatrix& viewMatrix() const { return fViewMatrix; }
61 bool hasColors() const { return fHasColors; }
jvanverth5a4d2352015-08-12 08:15:31 -070062 int quadCount() const { return fQuadCount; }
jvanverth14b88032015-08-07 12:18:54 -070063 bool coverageIgnored() const { return fCoverageIgnored; }
halcanary9d524f22016-03-29 09:03:52 -070064
Brian Salomon25a88092016-12-01 09:36:50 -050065 bool onCombineIfPossible(GrOp* t, const GrCaps&) override;
bsalomon0432dd62016-06-30 07:19:27 -070066
67 struct Geometry {
Brian Salomonfc527d22016-12-14 21:07:01 -050068 GrColor fColor;
bsalomon0432dd62016-06-30 07:19:27 -070069 SkTArray<uint8_t, true> fVerts;
70 };
71
jvanverth14b88032015-08-07 12:18:54 -070072 SkSTArray<1, Geometry, true> fGeoData;
halcanary9d524f22016-03-29 09:03:52 -070073
jvanverth14b88032015-08-07 12:18:54 -070074 SkMatrix fViewMatrix;
Brian Salomonfc527d22016-12-14 21:07:01 -050075 GrColor fColor;
76 int fQuadCount;
77 bool fColorIgnored;
78 bool fCoverageIgnored;
79 bool fHasColors;
reed1b55a962015-09-17 20:16:13 -070080
Brian Salomondad29232016-12-01 16:40:24 -050081 typedef GrMeshDrawOp INHERITED;
jvanverth14b88032015-08-07 12:18:54 -070082};
83
84#endif