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 GrAtlasTextBlob_DEFINED | 8 #ifndef GrAtlasTextBlob_DEFINED |
9 #define GrAtlasTextBlob_DEFINED | 9 #define GrAtlasTextBlob_DEFINED |
10 | 10 |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
56 * pointing. It would be a bit expensive to figure out ahead of time whether
or not a run | 56 * pointing. It would be a bit expensive to figure out ahead of time whether
or not a run |
57 * can flush in this manner, so we always allocate vertices for the run, reg
ardless of | 57 * can flush in this manner, so we always allocate vertices for the run, reg
ardless of |
58 * whether or not it is too large. The benefit of this strategy is that we
can always reuse | 58 * whether or not it is too large. The benefit of this strategy is that we
can always reuse |
59 * a blob allocation regardless of viewmatrix changes. We could store posit
ions for these | 59 * a blob allocation regardless of viewmatrix changes. We could store posit
ions for these |
60 * glyphs. However, its not clear if this is a win because we'd still have
to either go the | 60 * glyphs. However, its not clear if this is a win because we'd still have
to either go the |
61 * glyph cache to get the path at flush time, or hold onto the path in the c
ache, which | 61 * glyph cache to get the path at flush time, or hold onto the path in the c
ache, which |
62 * would greatly increase the memory of these cached items. | 62 * would greatly increase the memory of these cached items. |
63 */ | 63 */ |
64 struct Run { | 64 struct Run { |
65 Run() | 65 Run() |
66 : fColor(GrColor_ILLEGAL) | 66 : fInitialized(false) |
67 , fInitialized(false) | |
68 , fDrawAsPaths(false) { | 67 , fDrawAsPaths(false) { |
69 fVertexBounds.setLargestInverted(); | 68 fVertexBounds.setLargestInverted(); |
70 // To ensure we always have one subrun, we push back a fresh run her
e | 69 // To ensure we always have one subrun, we push back a fresh run her
e |
71 fSubRunInfo.push_back(); | 70 fSubRunInfo.push_back(); |
72 } | 71 } |
73 struct SubRunInfo { | 72 struct SubRunInfo { |
74 SubRunInfo() | 73 SubRunInfo() |
75 : fAtlasGeneration(GrBatchAtlas::kInvalidAtlasGeneration) | 74 : fAtlasGeneration(GrBatchAtlas::kInvalidAtlasGeneration) |
76 , fVertexStartIndex(0) | 75 , fVertexStartIndex(0) |
77 , fVertexEndIndex(0) | 76 , fVertexEndIndex(0) |
78 , fGlyphStartIndex(0) | 77 , fGlyphStartIndex(0) |
79 , fGlyphEndIndex(0) | 78 , fGlyphEndIndex(0) |
| 79 , fColor(GrColor_ILLEGAL) |
80 , fMaskFormat(kA8_GrMaskFormat) | 80 , fMaskFormat(kA8_GrMaskFormat) |
81 , fDrawAsDistanceFields(false) | 81 , fDrawAsDistanceFields(false) |
82 , fUseLCDText(false) {} | 82 , fUseLCDText(false) {} |
83 SubRunInfo(const SubRunInfo& that) | 83 SubRunInfo(const SubRunInfo& that) |
84 : fBulkUseToken(that.fBulkUseToken) | 84 : fBulkUseToken(that.fBulkUseToken) |
85 , fStrike(SkSafeRef(that.fStrike.get())) | 85 , fStrike(SkSafeRef(that.fStrike.get())) |
86 , fAtlasGeneration(that.fAtlasGeneration) | 86 , fAtlasGeneration(that.fAtlasGeneration) |
87 , fVertexStartIndex(that.fVertexStartIndex) | 87 , fVertexStartIndex(that.fVertexStartIndex) |
88 , fVertexEndIndex(that.fVertexEndIndex) | 88 , fVertexEndIndex(that.fVertexEndIndex) |
89 , fGlyphStartIndex(that.fGlyphStartIndex) | 89 , fGlyphStartIndex(that.fGlyphStartIndex) |
90 , fGlyphEndIndex(that.fGlyphEndIndex) | 90 , fGlyphEndIndex(that.fGlyphEndIndex) |
| 91 , fColor(that.fColor) |
91 , fMaskFormat(that.fMaskFormat) | 92 , fMaskFormat(that.fMaskFormat) |
92 , fDrawAsDistanceFields(that.fDrawAsDistanceFields) | 93 , fDrawAsDistanceFields(that.fDrawAsDistanceFields) |
93 , fUseLCDText(that.fUseLCDText) { | 94 , fUseLCDText(that.fUseLCDText) { |
94 } | 95 } |
95 | 96 |
96 // TODO when this object is more internal, drop the privacy | 97 // TODO when this object is more internal, drop the privacy |
97 void resetBulkUseToken() { fBulkUseToken.reset(); } | 98 void resetBulkUseToken() { fBulkUseToken.reset(); } |
98 GrBatchAtlas::BulkUseTokenUpdater* bulkUseToken() { return &fBulkUse
Token; } | 99 GrBatchAtlas::BulkUseTokenUpdater* bulkUseToken() { return &fBulkUse
Token; } |
99 void setStrike(GrBatchTextStrike* strike) { fStrike.reset(SkRef(stri
ke)); } | 100 void setStrike(GrBatchTextStrike* strike) { fStrike.reset(SkRef(stri
ke)); } |
100 GrBatchTextStrike* strike() const { return fStrike.get(); } | 101 GrBatchTextStrike* strike() const { return fStrike.get(); } |
101 | 102 |
102 void setAtlasGeneration(uint64_t atlasGeneration) { fAtlasGeneration
= atlasGeneration;} | 103 void setAtlasGeneration(uint64_t atlasGeneration) { fAtlasGeneration
= atlasGeneration;} |
103 uint64_t atlasGeneration() const { return fAtlasGeneration; } | 104 uint64_t atlasGeneration() const { return fAtlasGeneration; } |
104 | 105 |
105 size_t byteCount() const { return fVertexEndIndex - fVertexStartInde
x; } | 106 size_t byteCount() const { return fVertexEndIndex - fVertexStartInde
x; } |
106 size_t vertexStartIndex() const { return fVertexStartIndex; } | 107 size_t vertexStartIndex() const { return fVertexStartIndex; } |
107 size_t vertexEndIndex() const { return fVertexEndIndex; } | 108 size_t vertexEndIndex() const { return fVertexEndIndex; } |
108 void appendVertices(size_t vertexStride) { | 109 void appendVertices(size_t vertexStride) { |
109 fVertexEndIndex += vertexStride * kVerticesPerGlyph; | 110 fVertexEndIndex += vertexStride * kVerticesPerGlyph; |
110 } | 111 } |
111 | 112 |
112 uint32_t glyphCount() const { return fGlyphEndIndex - fGlyphStartInd
ex; } | 113 uint32_t glyphCount() const { return fGlyphEndIndex - fGlyphStartInd
ex; } |
113 uint32_t glyphStartIndex() const { return fGlyphStartIndex; } | 114 uint32_t glyphStartIndex() const { return fGlyphStartIndex; } |
114 uint32_t glyphEndIndex() const { return fGlyphEndIndex; } | 115 uint32_t glyphEndIndex() const { return fGlyphEndIndex; } |
115 void glyphAppended() { fGlyphEndIndex++; } | 116 void glyphAppended() { fGlyphEndIndex++; } |
| 117 void setColor(GrColor color) { fColor = color; } |
| 118 GrColor color() const { return fColor; } |
116 void setMaskFormat(GrMaskFormat format) { fMaskFormat = format; } | 119 void setMaskFormat(GrMaskFormat format) { fMaskFormat = format; } |
117 GrMaskFormat maskFormat() const { return fMaskFormat; } | 120 GrMaskFormat maskFormat() const { return fMaskFormat; } |
118 | 121 |
119 void setAsSuccessor(const SubRunInfo& prev) { | 122 void setAsSuccessor(const SubRunInfo& prev) { |
120 fGlyphStartIndex = prev.glyphEndIndex(); | 123 fGlyphStartIndex = prev.glyphEndIndex(); |
121 fGlyphEndIndex = prev.glyphEndIndex(); | 124 fGlyphEndIndex = prev.glyphEndIndex(); |
122 | 125 |
123 fVertexStartIndex = prev.vertexEndIndex(); | 126 fVertexStartIndex = prev.vertexEndIndex(); |
124 fVertexEndIndex = prev.vertexEndIndex(); | 127 fVertexEndIndex = prev.vertexEndIndex(); |
125 } | 128 } |
126 | 129 |
127 // df properties | 130 // df properties |
128 void setUseLCDText(bool useLCDText) { fUseLCDText = useLCDText; } | 131 void setUseLCDText(bool useLCDText) { fUseLCDText = useLCDText; } |
129 bool hasUseLCDText() const { return fUseLCDText; } | 132 bool hasUseLCDText() const { return fUseLCDText; } |
130 void setDrawAsDistanceFields() { fDrawAsDistanceFields = true; } | 133 void setDrawAsDistanceFields() { fDrawAsDistanceFields = true; } |
131 bool drawAsDistanceFields() const { return fDrawAsDistanceFields; } | 134 bool drawAsDistanceFields() const { return fDrawAsDistanceFields; } |
132 | 135 |
133 private: | 136 private: |
134 GrBatchAtlas::BulkUseTokenUpdater fBulkUseToken; | 137 GrBatchAtlas::BulkUseTokenUpdater fBulkUseToken; |
135 SkAutoTUnref<GrBatchTextStrike> fStrike; | 138 SkAutoTUnref<GrBatchTextStrike> fStrike; |
136 uint64_t fAtlasGeneration; | 139 uint64_t fAtlasGeneration; |
137 size_t fVertexStartIndex; | 140 size_t fVertexStartIndex; |
138 size_t fVertexEndIndex; | 141 size_t fVertexEndIndex; |
139 uint32_t fGlyphStartIndex; | 142 uint32_t fGlyphStartIndex; |
140 uint32_t fGlyphEndIndex; | 143 uint32_t fGlyphEndIndex; |
| 144 GrColor fColor; |
141 GrMaskFormat fMaskFormat; | 145 GrMaskFormat fMaskFormat; |
142 bool fDrawAsDistanceFields; // df property | 146 bool fDrawAsDistanceFields; // df property |
143 bool fUseLCDText; // df property | 147 bool fUseLCDText; // df property |
144 }; | 148 }; |
145 | 149 |
146 SubRunInfo& push_back() { | 150 SubRunInfo& push_back() { |
147 // Forward glyph / vertex information to seed the new sub run | 151 // Forward glyph / vertex information to seed the new sub run |
148 SubRunInfo& newSubRun = fSubRunInfo.push_back(); | 152 SubRunInfo& newSubRun = fSubRunInfo.push_back(); |
149 const SubRunInfo& prevSubRun = fSubRunInfo.fromBack(1); | 153 const SubRunInfo& prevSubRun = fSubRunInfo.fromBack(1); |
150 | 154 |
151 newSubRun.setAsSuccessor(prevSubRun); | 155 newSubRun.setAsSuccessor(prevSubRun); |
152 return newSubRun; | 156 return newSubRun; |
153 } | 157 } |
154 static const int kMinSubRuns = 1; | 158 static const int kMinSubRuns = 1; |
155 SkAutoTUnref<SkTypeface> fTypeface; | 159 SkAutoTUnref<SkTypeface> fTypeface; |
156 SkRect fVertexBounds; | 160 SkRect fVertexBounds; |
157 SkSTArray<kMinSubRuns, SubRunInfo> fSubRunInfo; | 161 SkSTArray<kMinSubRuns, SubRunInfo> fSubRunInfo; |
158 SkAutoDescriptor fDescriptor; | 162 SkAutoDescriptor fDescriptor; |
159 | 163 |
160 // Distance field text cannot draw coloremoji, and so has to fall back.
However, | 164 // Distance field text cannot draw coloremoji, and so has to fall back.
However, |
161 // though the distance field text and the coloremoji may share the same
run, they | 165 // though the distance field text and the coloremoji may share the same
run, they |
162 // will have different descriptors. If fOverrideDescriptor is non-nullp
tr, then it | 166 // will have different descriptors. If fOverrideDescriptor is non-nullp
tr, then it |
163 // will be used in place of the run's descriptor to regen texture coords | 167 // will be used in place of the run's descriptor to regen texture coords |
164 SkAutoTDelete<SkAutoDescriptor> fOverrideDescriptor; // df properties | 168 SkAutoTDelete<SkAutoDescriptor> fOverrideDescriptor; // df properties |
165 GrColor fColor; | |
166 bool fInitialized; | 169 bool fInitialized; |
167 bool fDrawAsPaths; | 170 bool fDrawAsPaths; |
168 }; | 171 }; |
169 | 172 |
170 struct BigGlyph { | 173 struct BigGlyph { |
171 BigGlyph(const SkPath& path, SkScalar vx, SkScalar vy, SkScalar scale, b
ool applyVM) | 174 BigGlyph(const SkPath& path, SkScalar vx, SkScalar vy, SkScalar scale, b
ool applyVM) |
172 : fPath(path) | 175 : fPath(path) |
173 , fVx(vx) | 176 , fVx(vx) |
174 , fVy(vy) | 177 , fVy(vy) |
175 , fScale(scale) | 178 , fScale(scale) |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
303 static const size_t kLCDTextVASize = kGrayTextVASize; | 306 static const size_t kLCDTextVASize = kGrayTextVASize; |
304 static const int kVerticesPerGlyph = 4; | 307 static const int kVerticesPerGlyph = 4; |
305 | 308 |
306 #ifdef CACHE_SANITY_CHECK | 309 #ifdef CACHE_SANITY_CHECK |
307 static void AssertEqual(const GrAtlasTextBlob&, const GrAtlasTextBlob&); | 310 static void AssertEqual(const GrAtlasTextBlob&, const GrAtlasTextBlob&); |
308 size_t fSize; | 311 size_t fSize; |
309 #endif | 312 #endif |
310 }; | 313 }; |
311 | 314 |
312 #endif | 315 #endif |
OLD | NEW |