OLD | NEW |
| (Empty) |
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 GrStrokeRectBatch_DEFINED | |
9 #define GrStrokeRectBatch_DEFINED | |
10 | |
11 #include "GrColor.h" | |
12 #include "GrDefaultGeoProcFactory.h" | |
13 #include "GrVertexBatch.h" | |
14 | |
15 class GrStrokeRectBatch : public GrVertexBatch { | |
16 public: | |
17 DEFINE_BATCH_CLASS_ID | |
18 | |
19 struct Geometry { | |
20 GrColor fColor; | |
21 SkMatrix fViewMatrix; | |
22 SkRect fRect; | |
23 SkScalar fStrokeWidth; | |
24 }; | |
25 | |
26 static GrDrawBatch* Create(const Geometry& geometry, bool snapToPixelCenters
) { | |
27 return new GrStrokeRectBatch(geometry, snapToPixelCenters); | |
28 } | |
29 | |
30 const char* name() const override { return "GrStrokeRectBatch"; } | |
31 | |
32 void getInvariantOutputColor(GrInitInvariantOutput* out) const override { | |
33 // When this is called on a batch, there is only one geometry bundle | |
34 out->setKnownFourComponents(fGeoData[0].fColor); | |
35 } | |
36 | |
37 void getInvariantOutputCoverage(GrInitInvariantOutput* out) const override { | |
38 out->setKnownSingleComponent(0xff); | |
39 } | |
40 | |
41 private: | |
42 void onPrepareDraws(Target*) override; | |
43 void initBatchTracker(const GrPipelineOptimizations&) override; | |
44 | |
45 GrStrokeRectBatch(const Geometry& geometry, bool snapToPixelCenters); | |
46 | |
47 GrColor color() const { return fBatch.fColor; } | |
48 bool usesLocalCoords() const { return fBatch.fUsesLocalCoords; } | |
49 bool colorIgnored() const { return fBatch.fColorIgnored; } | |
50 const SkMatrix& viewMatrix() const { return fGeoData[0].fViewMatrix; } | |
51 bool hairline() const { return fBatch.fHairline; } | |
52 bool coverageIgnored() const { return fBatch.fCoverageIgnored; } | |
53 | |
54 bool onCombineIfPossible(GrBatch* t, const GrCaps&) override { | |
55 // if (!GrPipeline::CanCombine(*this->pipeline(), this->bounds(), *t->pi
peline(), | |
56 // t->bounds(), caps)) { | |
57 // return false; | |
58 // } | |
59 // GrStrokeRectBatch* that = t->cast<StrokeRectBatch>(); | |
60 | |
61 // NonAA stroke rects cannot batch right now | |
62 // TODO make these batchable | |
63 return false; | |
64 } | |
65 | |
66 struct BatchTracker { | |
67 GrColor fColor; | |
68 bool fUsesLocalCoords; | |
69 bool fColorIgnored; | |
70 bool fCoverageIgnored; | |
71 bool fHairline; | |
72 }; | |
73 | |
74 const static int kVertsPerHairlineRect = 5; | |
75 const static int kVertsPerStrokeRect = 10; | |
76 | |
77 BatchTracker fBatch; | |
78 SkSTArray<1, Geometry, true> fGeoData; | |
79 | |
80 typedef GrVertexBatch INHERITED; | |
81 }; | |
82 | |
83 #endif | |
OLD | NEW |