Home | History | Annotate | Download | only in batches
      1 /*
      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 "GrColor.h"
     12 #include "GrDefaultGeoProcFactory.h"
     13 #include "GrVertexBatch.h"
     14 
     15 class GrDrawAtlasBatch : public GrVertexBatch {
     16 public:
     17     DEFINE_BATCH_CLASS_ID
     18 
     19     struct Geometry {
     20         GrColor                 fColor;
     21         SkTArray<uint8_t, true> fVerts;
     22     };
     23 
     24     static GrDrawBatch* Create(const Geometry& geometry, const SkMatrix& viewMatrix,
     25                                int spriteCount, const SkRSXform* xforms, const SkRect* rects,
     26                                const SkColor* colors) {
     27         return new GrDrawAtlasBatch(geometry, viewMatrix, spriteCount, xforms, rects, colors);
     28     }
     29 
     30     const char* name() const override { return "DrawAtlasBatch"; }
     31 
     32     void computePipelineOptimizations(GrInitInvariantOutput* color,
     33                                       GrInitInvariantOutput* coverage,
     34                                       GrBatchToXPOverrides* overrides) const override {
     35         // When this is called on a batch, there is only one geometry bundle
     36         if (this->hasColors()) {
     37             color->setUnknownFourComponents();
     38         } else {
     39             color->setKnownFourComponents(fGeoData[0].fColor);
     40         }
     41         coverage->setKnownSingleComponent(0xff);
     42     }
     43 
     44     SkSTArray<1, Geometry, true>* geoData() { return &fGeoData; }
     45 
     46 private:
     47     void onPrepareDraws(Target*) const override;
     48 
     49     void initBatchTracker(const GrXPOverridesForBatch&) override;
     50 
     51     GrDrawAtlasBatch(const Geometry& geometry, const SkMatrix& viewMatrix, int spriteCount,
     52                      const SkRSXform* xforms, const SkRect* rects, const SkColor* colors);
     53 
     54     GrColor color() const { return fColor; }
     55     bool colorIgnored() const { return fColorIgnored; }
     56     const SkMatrix& viewMatrix() const { return fViewMatrix; }
     57     bool hasColors() const { return fHasColors; }
     58     int quadCount() const { return fQuadCount; }
     59     bool coverageIgnored() const { return fCoverageIgnored; }
     60 
     61     bool onCombineIfPossible(GrBatch* t, const GrCaps&) override;
     62     SkSTArray<1, Geometry, true> fGeoData;
     63 
     64     SkMatrix fViewMatrix;
     65     GrColor  fColor;
     66     int      fQuadCount;
     67     bool     fColorIgnored;
     68     bool     fCoverageIgnored;
     69     bool     fHasColors;
     70 
     71     typedef GrVertexBatch INHERITED;
     72 };
     73 
     74 #endif
     75