blob: 3ccca49ba3cda78804fe9de7cfe29f35e46591ef [file] [log] [blame]
joshualitt259fbf12015-07-21 11:39:34 -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
8#include "GrAtlasTextBlob.h"
9
joshualittf528e0d2015-12-09 06:42:52 -080010void GrAtlasTextBlob::appendGlyph(int runIndex,
11 const SkRect& positions,
12 GrColor color,
13 GrBatchTextStrike* strike,
joshualitt18b072d2015-12-07 12:26:12 -080014 GrGlyph* glyph) {
joshualittf528e0d2015-12-09 06:42:52 -080015 Run& run = fRuns[runIndex];
16 GrMaskFormat format = glyph->fMaskFormat;
17
18 Run::SubRunInfo* subRun = &run.fSubRunInfo.back();
19 if (run.fInitialized && subRun->maskFormat() != format) {
20 subRun = &run.push_back();
21 subRun->setStrike(strike);
22 } else if (!run.fInitialized) {
23 subRun->setStrike(strike);
24 }
25
26 run.fInitialized = true;
27
28 size_t vertexStride = GetVertexStride(format);
29
30 subRun->setMaskFormat(format);
31
32 run.fVertexBounds.joinNonEmptyArg(positions);
33 run.fColor = color;
joshualitt18b072d2015-12-07 12:26:12 -080034
35 intptr_t vertex = reinterpret_cast<intptr_t>(this->fVertices + subRun->vertexEndIndex());
36
joshualittf528e0d2015-12-09 06:42:52 -080037 if (kARGB_GrMaskFormat != glyph->fMaskFormat) {
joshualitt18b072d2015-12-07 12:26:12 -080038 // V0
39 SkPoint* position = reinterpret_cast<SkPoint*>(vertex);
40 position->set(positions.fLeft, positions.fTop);
41 SkColor* colorPtr = reinterpret_cast<SkColor*>(vertex + sizeof(SkPoint));
42 *colorPtr = color;
43 vertex += vertexStride;
44
45 // V1
46 position = reinterpret_cast<SkPoint*>(vertex);
47 position->set(positions.fLeft, positions.fBottom);
48 colorPtr = reinterpret_cast<SkColor*>(vertex + sizeof(SkPoint));
49 *colorPtr = color;
50 vertex += vertexStride;
51
52 // V2
53 position = reinterpret_cast<SkPoint*>(vertex);
54 position->set(positions.fRight, positions.fBottom);
55 colorPtr = reinterpret_cast<SkColor*>(vertex + sizeof(SkPoint));
56 *colorPtr = color;
57 vertex += vertexStride;
58
59 // V3
60 position = reinterpret_cast<SkPoint*>(vertex);
61 position->set(positions.fRight, positions.fTop);
62 colorPtr = reinterpret_cast<SkColor*>(vertex + sizeof(SkPoint));
63 *colorPtr = color;
64 } else {
65 // V0
66 SkPoint* position = reinterpret_cast<SkPoint*>(vertex);
67 position->set(positions.fLeft, positions.fTop);
68 vertex += vertexStride;
69
70 // V1
71 position = reinterpret_cast<SkPoint*>(vertex);
72 position->set(positions.fLeft, positions.fBottom);
73 vertex += vertexStride;
74
75 // V2
76 position = reinterpret_cast<SkPoint*>(vertex);
77 position->set(positions.fRight, positions.fBottom);
78 vertex += vertexStride;
79
80 // V3
81 position = reinterpret_cast<SkPoint*>(vertex);
82 position->set(positions.fRight, positions.fTop);
83 }
84 subRun->appendVertices(vertexStride);
85 fGlyphs[subRun->glyphEndIndex()] = glyph;
86 subRun->glyphAppended();
87}
88
89// TODO get this code building again
joshualitt259fbf12015-07-21 11:39:34 -070090#ifdef CACHE_SANITY_CHECK
91void GrAtlasTextBlob::AssertEqual(const GrAtlasTextBlob& l, const GrAtlasTextBlob& r) {
92 SkASSERT(l.fSize == r.fSize);
93 SkASSERT(l.fPool == r.fPool);
94
95 SkASSERT(l.fBlurRec.fSigma == r.fBlurRec.fSigma);
96 SkASSERT(l.fBlurRec.fStyle == r.fBlurRec.fStyle);
97 SkASSERT(l.fBlurRec.fQuality == r.fBlurRec.fQuality);
98
99 SkASSERT(l.fStrokeInfo.fFrameWidth == r.fStrokeInfo.fFrameWidth);
100 SkASSERT(l.fStrokeInfo.fMiterLimit == r.fStrokeInfo.fMiterLimit);
101 SkASSERT(l.fStrokeInfo.fJoin == r.fStrokeInfo.fJoin);
102
103 SkASSERT(l.fBigGlyphs.count() == r.fBigGlyphs.count());
104 for (int i = 0; i < l.fBigGlyphs.count(); i++) {
105 const BigGlyph& lBigGlyph = l.fBigGlyphs[i];
106 const BigGlyph& rBigGlyph = r.fBigGlyphs[i];
107
108 SkASSERT(lBigGlyph.fPath == rBigGlyph.fPath);
109 // We can't assert that these have the same translations
110 }
111
112 SkASSERT(l.fKey == r.fKey);
113 SkASSERT(l.fViewMatrix.cheapEqualTo(r.fViewMatrix));
114 SkASSERT(l.fPaintColor == r.fPaintColor);
115 SkASSERT(l.fMaxMinScale == r.fMaxMinScale);
116 SkASSERT(l.fMinMaxScale == r.fMinMaxScale);
117 SkASSERT(l.fTextType == r.fTextType);
118
119 SkASSERT(l.fRunCount == r.fRunCount);
120 for (int i = 0; i < l.fRunCount; i++) {
121 const Run& lRun = l.fRuns[i];
122 const Run& rRun = r.fRuns[i];
123
124 if (lRun.fStrike.get()) {
125 SkASSERT(rRun.fStrike.get());
126 SkASSERT(GrBatchTextStrike::GetKey(*lRun.fStrike) ==
127 GrBatchTextStrike::GetKey(*rRun.fStrike));
128
129 } else {
130 SkASSERT(!rRun.fStrike.get());
131 }
132
133 if (lRun.fTypeface.get()) {
134 SkASSERT(rRun.fTypeface.get());
135 SkASSERT(SkTypeface::Equal(lRun.fTypeface, rRun.fTypeface));
136 } else {
137 SkASSERT(!rRun.fTypeface.get());
138 }
139
joshualitt7e7b5c52015-07-21 12:56:56 -0700140 // We offset bounds right before flush time so they will not be correct here
joshualitt259fbf12015-07-21 11:39:34 -0700141 //SkASSERT(lRun.fVertexBounds == rRun.fVertexBounds);
142
143 SkASSERT(lRun.fDescriptor.getDesc());
144 SkASSERT(rRun.fDescriptor.getDesc());
145 SkASSERT(lRun.fDescriptor.getDesc()->equals(*rRun.fDescriptor.getDesc()));
146
147 if (lRun.fOverrideDescriptor.get()) {
148 SkASSERT(lRun.fOverrideDescriptor->getDesc());
149 SkASSERT(rRun.fOverrideDescriptor.get() && rRun.fOverrideDescriptor->getDesc());;
150 SkASSERT(lRun.fOverrideDescriptor->getDesc()->equals(
151 *rRun.fOverrideDescriptor->getDesc()));
152 } else {
153 SkASSERT(!rRun.fOverrideDescriptor.get());
154 }
155
156 // color can be changed
157 //SkASSERT(lRun.fColor == rRun.fColor);
158 SkASSERT(lRun.fInitialized == rRun.fInitialized);
159 SkASSERT(lRun.fDrawAsPaths == rRun.fDrawAsPaths);
160
161 SkASSERT(lRun.fSubRunInfo.count() == rRun.fSubRunInfo.count());
162 for(int j = 0; j < lRun.fSubRunInfo.count(); j++) {
163 const Run::SubRunInfo& lSubRun = lRun.fSubRunInfo[j];
164 const Run::SubRunInfo& rSubRun = rRun.fSubRunInfo[j];
165
166 SkASSERT(lSubRun.fVertexStartIndex == rSubRun.fVertexStartIndex);
167 SkASSERT(lSubRun.fVertexEndIndex == rSubRun.fVertexEndIndex);
168 SkASSERT(lSubRun.fGlyphStartIndex == rSubRun.fGlyphStartIndex);
169 SkASSERT(lSubRun.fGlyphEndIndex == rSubRun.fGlyphEndIndex);
170 SkASSERT(lSubRun.fTextRatio == rSubRun.fTextRatio);
171 SkASSERT(lSubRun.fMaskFormat == rSubRun.fMaskFormat);
172 SkASSERT(lSubRun.fDrawAsDistanceFields == rSubRun.fDrawAsDistanceFields);
173 SkASSERT(lSubRun.fUseLCDText == rSubRun.fUseLCDText);
174
175 //We can't compare the bulk use tokens with this method
176 /*
177 SkASSERT(lSubRun.fBulkUseToken.fPlotsToUpdate.count() ==
178 rSubRun.fBulkUseToken.fPlotsToUpdate.count());
179 SkASSERT(lSubRun.fBulkUseToken.fPlotAlreadyUpdated ==
180 rSubRun.fBulkUseToken.fPlotAlreadyUpdated);
181 for (int k = 0; k < lSubRun.fBulkUseToken.fPlotsToUpdate.count(); k++) {
182 SkASSERT(lSubRun.fBulkUseToken.fPlotsToUpdate[k] ==
183 rSubRun.fBulkUseToken.fPlotsToUpdate[k]);
184 }*/
185 }
186 }
187}
188
189#endif