| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2015 Google Inc. | 2 * Copyright 2015 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #ifndef GrAtlasTextBatch_DEFINED | 8 #ifndef GrAtlasTextBatch_DEFINED |
| 9 #define GrAtlasTextBatch_DEFINED | 9 #define GrAtlasTextBatch_DEFINED |
| 10 | 10 |
| 11 #include "batches/GrVertexBatch.h" | 11 #include "batches/GrVertexBatch.h" |
| 12 | 12 |
| 13 #include "text/GrAtlasTextContext.h" | 13 #include "text/GrAtlasTextContext.h" |
| 14 #include "text/GrDistanceFieldAdjustTable.h" | 14 #include "text/GrDistanceFieldAdjustTable.h" |
| 15 | 15 |
| 16 class GrAtlasTextBatch : public GrVertexBatch { | 16 class GrAtlasTextBatch : public GrVertexBatch { |
| 17 public: | 17 public: |
| 18 DEFINE_BATCH_CLASS_ID | 18 DEFINE_BATCH_CLASS_ID |
| 19 | 19 |
| 20 static const int kVerticesPerGlyph = GrAtlasTextBlob::kVerticesPerGlyph; | 20 static const int kVerticesPerGlyph = GrAtlasTextBlob::kVerticesPerGlyph; |
| 21 static const int kIndicesPerGlyph = 6; | 21 static const int kIndicesPerGlyph = 6; |
| 22 | 22 |
| 23 typedef GrAtlasTextBlob Blob; | 23 typedef GrAtlasTextBlob Blob; |
| 24 struct Geometry { | 24 struct Geometry { |
| 25 SkMatrix fViewMatrix; |
| 25 Blob* fBlob; | 26 Blob* fBlob; |
| 27 SkScalar fX; |
| 28 SkScalar fY; |
| 26 int fRun; | 29 int fRun; |
| 27 int fSubRun; | 30 int fSubRun; |
| 28 GrColor fColor; | 31 GrColor fColor; |
| 29 SkScalar fTransX; | |
| 30 SkScalar fTransY; | |
| 31 }; | 32 }; |
| 32 | 33 |
| 33 static GrAtlasTextBatch* CreateBitmap(GrMaskFormat maskFormat, int glyphCoun
t, | 34 static GrAtlasTextBatch* CreateBitmap(GrMaskFormat maskFormat, int glyphCoun
t, |
| 34 GrBatchFontCache* fontCache) { | 35 GrBatchFontCache* fontCache) { |
| 35 GrAtlasTextBatch* batch = new GrAtlasTextBatch; | 36 GrAtlasTextBatch* batch = new GrAtlasTextBatch; |
| 36 | 37 |
| 37 batch->fFontCache = fontCache; | 38 batch->fFontCache = fontCache; |
| 38 switch (maskFormat) { | 39 switch (maskFormat) { |
| 39 case kA8_GrMaskFormat: | 40 case kA8_GrMaskFormat: |
| 40 batch->fMaskType = kGrayscaleCoverageMask_MaskType; | 41 batch->fMaskType = kGrayscaleCoverageMask_MaskType; |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 72 } | 73 } |
| 73 | 74 |
| 74 // to avoid even the initial copy of the struct, we have a getter for the fi
rst item which | 75 // to avoid even the initial copy of the struct, we have a getter for the fi
rst item which |
| 75 // is used to seed the batch with its initial geometry. After seeding, the
client should call | 76 // is used to seed the batch with its initial geometry. After seeding, the
client should call |
| 76 // init() so the Batch can initialize itself | 77 // init() so the Batch can initialize itself |
| 77 Geometry& geometry() { return fGeoData[0]; } | 78 Geometry& geometry() { return fGeoData[0]; } |
| 78 | 79 |
| 79 void init() { | 80 void init() { |
| 80 const Geometry& geo = fGeoData[0]; | 81 const Geometry& geo = fGeoData[0]; |
| 81 fBatch.fColor = geo.fColor; | 82 fBatch.fColor = geo.fColor; |
| 82 fBatch.fViewMatrix = geo.fBlob->viewMatrix(); | |
| 83 | 83 |
| 84 geo.fBlob->computeSubRunBounds(&fBounds, geo.fRun, geo.fSubRun); | 84 geo.fBlob->computeSubRunBounds(&fBounds, geo.fRun, geo.fSubRun, geo.fVie
wMatrix, geo.fX, |
| 85 geo.fY); |
| 85 } | 86 } |
| 86 | 87 |
| 87 const char* name() const override { return "TextBatch"; } | 88 const char* name() const override { return "TextBatch"; } |
| 88 | 89 |
| 89 SkString dumpInfo() const override; | 90 SkString dumpInfo() const override; |
| 90 | 91 |
| 91 protected: | 92 protected: |
| 92 void computePipelineOptimizations(GrInitInvariantOutput* color, | 93 void computePipelineOptimizations(GrInitInvariantOutput* color, |
| 93 GrInitInvariantOutput* coverage, | 94 GrInitInvariantOutput* coverage, |
| 94 GrBatchToXPOverrides* overrides) const ove
rride; | 95 GrBatchToXPOverrides* overrides) const ove
rride; |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 134 } | 135 } |
| 135 | 136 |
| 136 bool isLCD() const { | 137 bool isLCD() const { |
| 137 return kLCDCoverageMask_MaskType == fMaskType || | 138 return kLCDCoverageMask_MaskType == fMaskType || |
| 138 kLCDDistanceField_MaskType == fMaskType; | 139 kLCDDistanceField_MaskType == fMaskType; |
| 139 } | 140 } |
| 140 | 141 |
| 141 inline void flush(GrVertexBatch::Target* target, FlushInfo* flushInfo) const
; | 142 inline void flush(GrVertexBatch::Target* target, FlushInfo* flushInfo) const
; |
| 142 | 143 |
| 143 GrColor color() const { return fBatch.fColor; } | 144 GrColor color() const { return fBatch.fColor; } |
| 144 const SkMatrix& viewMatrix() const { return fBatch.fViewMatrix; } | 145 const SkMatrix& viewMatrix() const { return fGeoData[0].fViewMatrix; } |
| 145 bool usesLocalCoords() const { return fBatch.fUsesLocalCoords; } | 146 bool usesLocalCoords() const { return fBatch.fUsesLocalCoords; } |
| 146 int numGlyphs() const { return fBatch.fNumGlyphs; } | 147 int numGlyphs() const { return fBatch.fNumGlyphs; } |
| 147 | 148 |
| 148 bool onCombineIfPossible(GrBatch* t, const GrCaps& caps) override; | 149 bool onCombineIfPossible(GrBatch* t, const GrCaps& caps) override; |
| 149 | 150 |
| 150 // TODO just use class params | 151 // TODO just use class params |
| 151 // TODO trying to figure out why lcd is so whack | 152 // TODO trying to figure out why lcd is so whack |
| 152 GrGeometryProcessor* setupDfProcessor(const SkMatrix& viewMatrix, SkColor fi
lteredColor, | 153 GrGeometryProcessor* setupDfProcessor(const SkMatrix& viewMatrix, SkColor fi
lteredColor, |
| 153 GrColor color, GrTexture* texture) con
st; | 154 GrColor color, GrTexture* texture) con
st; |
| 154 | 155 |
| 155 struct BatchTracker { | 156 struct BatchTracker { |
| 156 GrColor fColor; | 157 GrColor fColor; |
| 157 SkMatrix fViewMatrix; | |
| 158 bool fUsesLocalCoords; | 158 bool fUsesLocalCoords; |
| 159 bool fColorIgnored; | 159 bool fColorIgnored; |
| 160 bool fCoverageIgnored; | 160 bool fCoverageIgnored; |
| 161 int fNumGlyphs; | 161 int fNumGlyphs; |
| 162 }; | 162 }; |
| 163 | 163 |
| 164 BatchTracker fBatch; | 164 BatchTracker fBatch; |
| 165 // The minimum number of Geometry we will try to allocate. | 165 // The minimum number of Geometry we will try to allocate. |
| 166 enum { kMinGeometryAllocated = 4 }; | 166 enum { kMinGeometryAllocated = 4 }; |
| 167 SkAutoSTMalloc<kMinGeometryAllocated, Geometry> fGeoData; | 167 SkAutoSTMalloc<kMinGeometryAllocated, Geometry> fGeoData; |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 209 } | 209 } |
| 210 | 210 |
| 211 private: | 211 private: |
| 212 const GrAtlasTextBatch* fBatch; | 212 const GrAtlasTextBatch* fBatch; |
| 213 GrVertexBatch::Target* fTarget; | 213 GrVertexBatch::Target* fTarget; |
| 214 GrAtlasTextBatch::FlushInfo* fFlushInfo; | 214 GrAtlasTextBatch::FlushInfo* fFlushInfo; |
| 215 const GrGeometryProcessor* fGP; | 215 const GrGeometryProcessor* fGP; |
| 216 }; | 216 }; |
| 217 | 217 |
| 218 #endif | 218 #endif |
| OLD | NEW |