blob: af4ba6434380af7225244ecae71e539fb38eb329 [file] [log] [blame]
kkinnunenc6cb56f2014-06-24 00:12:27 -07001/*
2 * Copyright 2014 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 "GrStencilAndCoverTextContext.h"
9#include "GrDrawTarget.h"
kkinnunenc6cb56f2014-06-24 00:12:27 -070010#include "GrGpu.h"
11#include "GrPath.h"
cdaltonb85a0aa2014-07-21 15:32:44 -070012#include "GrPathRange.h"
kkinnunenc6cb56f2014-06-24 00:12:27 -070013#include "SkAutoKern.h"
14#include "SkDraw.h"
15#include "SkDrawProcs.h"
16#include "SkGlyphCache.h"
17#include "SkGpuDevice.h"
18#include "SkPath.h"
19#include "SkTextMapStateProc.h"
20
bsalomon6d3fe022014-07-25 08:35:45 -070021class GrStencilAndCoverTextContext::GlyphPathRange : public GrGpuResource {
cdaltonb85a0aa2014-07-21 15:32:44 -070022 static const int kMaxGlyphCount = 1 << 16; // Glyph IDs are uint16_t's
23 static const int kGlyphGroupSize = 16; // Glyphs get tracked in groups of 16
24
25public:
26 static GlyphPathRange* Create(GrContext* context,
27 SkGlyphCache* cache,
28 const SkStrokeRec& stroke) {
29 static const GrCacheID::Domain gGlyphPathRangeDomain = GrCacheID::GenerateDomain();
30
31 GrCacheID::Key key;
32 key.fData32[0] = cache->getDescriptor().getChecksum();
33 key.fData32[1] = cache->getScalerContext()->getTypeface()->uniqueID();
34 key.fData64[1] = GrPath::ComputeStrokeKey(stroke);
35
36 GrResourceKey resourceKey(GrCacheID(gGlyphPathRangeDomain, key),
37 GrPathRange::resourceType(), 0);
38 SkAutoTUnref<GlyphPathRange> glyphs(
39 static_cast<GlyphPathRange*>(context->findAndRefCachedResource(resourceKey)));
40
41 if (NULL == glyphs ||
42 !glyphs->fDesc->equals(cache->getDescriptor() /*checksum collision*/)) {
43 glyphs.reset(SkNEW_ARGS(GlyphPathRange, (context, cache->getDescriptor(), stroke)));
44 context->addResourceToCache(resourceKey, glyphs);
45 }
46
47 return glyphs.detach();
48 }
49
50 const GrPathRange* pathRange() const { return fPathRange.get(); }
51
52 void preloadGlyph(uint16_t glyphID, SkGlyphCache* cache) {
53 const uint16_t groupIndex = glyphID / kGlyphGroupSize;
54 const uint16_t groupByte = groupIndex >> 3;
55 const uint8_t groupBit = 1 << (groupIndex & 7);
56
57 const bool hasGlyph = 0 != (fLoadedGlyphs[groupByte] & groupBit);
58 if (hasGlyph) {
59 return;
60 }
61
62 // We track which glyphs are loaded in groups of kGlyphGroupSize. To
63 // mark a glyph loaded we need to load the entire group.
64 const uint16_t groupFirstID = groupIndex * kGlyphGroupSize;
65 const uint16_t groupLastID = groupFirstID + kGlyphGroupSize - 1;
66 SkPath skPath;
67 for (int id = groupFirstID; id <= groupLastID; ++id) {
68 const SkGlyph& skGlyph = cache->getGlyphIDMetrics(id);
69 if (const SkPath* skPath = cache->findPath(skGlyph)) {
70 fPathRange->initAt(id, *skPath);
71 } // GrGpu::drawPaths will silently ignore undefined paths.
72 }
73
74 fLoadedGlyphs[groupByte] |= groupBit;
75 this->didChangeGpuMemorySize();
76 }
77
bsalomon6d3fe022014-07-25 08:35:45 -070078 // GrGpuResource overrides
cdaltonb85a0aa2014-07-21 15:32:44 -070079 virtual size_t gpuMemorySize() const SK_OVERRIDE { return fPathRange->gpuMemorySize(); }
cdaltonb85a0aa2014-07-21 15:32:44 -070080
81private:
82 GlyphPathRange(GrContext* context, const SkDescriptor& desc, const SkStrokeRec& stroke)
bsalomonc44be0e2014-07-25 07:32:33 -070083 : INHERITED(context->getGpu(), false)
84 , fDesc(desc.copy())
cdaltonb85a0aa2014-07-21 15:32:44 -070085 // We reserve a range of kMaxGlyphCount paths because of fallbacks fonts. We
86 // can't know exactly how many glyphs we might need without preloading every
87 // fallback, which we don't want to do at this point.
88 , fPathRange(context->getGpu()->createPathRange(kMaxGlyphCount, stroke)) {
89 memset(fLoadedGlyphs, 0, sizeof(fLoadedGlyphs));
90 }
91
92 ~GlyphPathRange() {
bsalomonc44be0e2014-07-25 07:32:33 -070093 this->release();
cdaltonb85a0aa2014-07-21 15:32:44 -070094 SkDescriptor::Free(fDesc);
95 }
96
97 static const int kMaxGroupCount = (kMaxGlyphCount + (kGlyphGroupSize - 1)) / kGlyphGroupSize;
98 SkDescriptor* const fDesc;
99 uint8_t fLoadedGlyphs[(kMaxGroupCount + 7) >> 3]; // One bit per glyph group
100 SkAutoTUnref<GrPathRange> fPathRange;
101
bsalomon6d3fe022014-07-25 08:35:45 -0700102 typedef GrGpuResource INHERITED;
cdaltonb85a0aa2014-07-21 15:32:44 -0700103};
104
kkinnunenc6cb56f2014-06-24 00:12:27 -0700105
106GrStencilAndCoverTextContext::GrStencilAndCoverTextContext(
107 GrContext* context, const SkDeviceProperties& properties)
108 : GrTextContext(context, properties)
cdaltonb85a0aa2014-07-21 15:32:44 -0700109 , fStroke(SkStrokeRec::kFill_InitStyle)
110 , fPendingGlyphCount(0) {
kkinnunenc6cb56f2014-06-24 00:12:27 -0700111}
112
113GrStencilAndCoverTextContext::~GrStencilAndCoverTextContext() {
114}
115
116void GrStencilAndCoverTextContext::drawText(const GrPaint& paint,
117 const SkPaint& skPaint,
118 const char text[],
119 size_t byteLength,
120 SkScalar x, SkScalar y) {
121 SkASSERT(byteLength == 0 || text != NULL);
122
123 if (text == NULL || byteLength == 0 /*|| fRC->isEmpty()*/) {
124 return;
125 }
126
127 // This is the slow path, mainly used by Skia unit tests. The other
128 // backends (8888, gpu, ...) use device-space dependent glyph caches. In
129 // order to match the glyph positions that the other code paths produce, we
130 // must also use device-space dependent glyph cache. This has the
131 // side-effect that the glyph shape outline will be in device-space,
132 // too. This in turn has the side-effect that NVPR can not stroke the paths,
133 // as the stroke in NVPR is defined in object-space.
134 // NOTE: here we have following coincidence that works at the moment:
135 // - When using the device-space glyphs, the transforms we pass to NVPR
136 // instanced drawing are the global transforms, and the view transform is
137 // identity. NVPR can not use non-affine transforms in the instanced
138 // drawing. This is taken care of by SkDraw::ShouldDrawTextAsPaths since it
139 // will turn off the use of device-space glyphs when perspective transforms
140 // are in use.
141
cdaltonb2808cd2014-07-25 14:13:57 -0700142 this->init(paint, skPaint, byteLength, kUseIfNeeded_DeviceSpaceGlyphsBehavior);
kkinnunenc6cb56f2014-06-24 00:12:27 -0700143
144 SkMatrix* glyphCacheTransform = NULL;
145 // Transform our starting point.
146 if (fNeedsDeviceSpaceGlyphs) {
147 SkPoint loc;
cdaltonb2808cd2014-07-25 14:13:57 -0700148 fContextInitialMatrix.mapXY(x, y, &loc);
kkinnunenc6cb56f2014-06-24 00:12:27 -0700149 x = loc.fX;
150 y = loc.fY;
cdaltonb2808cd2014-07-25 14:13:57 -0700151 glyphCacheTransform = &fContextInitialMatrix;
kkinnunenc6cb56f2014-06-24 00:12:27 -0700152 }
153
154 SkDrawCacheProc glyphCacheProc = fSkPaint.getDrawCacheProc();
155 SkAutoGlyphCache autoCache(fSkPaint, &fDeviceProperties, glyphCacheTransform);
cdaltonb85a0aa2014-07-21 15:32:44 -0700156 fGlyphCache = autoCache.getCache();
157 fGlyphs = GlyphPathRange::Create(fContext, fGlyphCache, fStroke);
kkinnunenccdaa042014-08-20 01:36:23 -0700158 fTransformType = GrPathRendering::kTranslate_PathTransformType;
kkinnunenc6cb56f2014-06-24 00:12:27 -0700159
160 const char* stop = text + byteLength;
161
162 // Measure first if needed.
163 if (fSkPaint.getTextAlign() != SkPaint::kLeft_Align) {
164 SkFixed stopX = 0;
165 SkFixed stopY = 0;
166
167 const char* textPtr = text;
168 while (textPtr < stop) {
169 // We don't need x, y here, since all subpixel variants will have the
170 // same advance.
cdaltonb85a0aa2014-07-21 15:32:44 -0700171 const SkGlyph& glyph = glyphCacheProc(fGlyphCache, &textPtr, 0, 0);
kkinnunenc6cb56f2014-06-24 00:12:27 -0700172
173 stopX += glyph.fAdvanceX;
174 stopY += glyph.fAdvanceY;
175 }
176 SkASSERT(textPtr == stop);
177
178 SkScalar alignX = SkFixedToScalar(stopX) * fTextRatio;
179 SkScalar alignY = SkFixedToScalar(stopY) * fTextRatio;
180
181 if (fSkPaint.getTextAlign() == SkPaint::kCenter_Align) {
182 alignX = SkScalarHalf(alignX);
183 alignY = SkScalarHalf(alignY);
184 }
185
186 x -= alignX;
187 y -= alignY;
188 }
189
190 SkAutoKern autokern;
191
192 SkFixed fixedSizeRatio = SkScalarToFixed(fTextRatio);
193
194 SkFixed fx = SkScalarToFixed(x);
195 SkFixed fy = SkScalarToFixed(y);
196 while (text < stop) {
cdaltonb85a0aa2014-07-21 15:32:44 -0700197 const SkGlyph& glyph = glyphCacheProc(fGlyphCache, &text, 0, 0);
kkinnunenc6cb56f2014-06-24 00:12:27 -0700198 fx += SkFixedMul_portable(autokern.adjust(glyph), fixedSizeRatio);
199 if (glyph.fWidth) {
cdaltonb85a0aa2014-07-21 15:32:44 -0700200 this->appendGlyph(glyph.getGlyphID(), SkFixedToScalar(fx), SkFixedToScalar(fy));
kkinnunenc6cb56f2014-06-24 00:12:27 -0700201 }
202
203 fx += SkFixedMul_portable(glyph.fAdvanceX, fixedSizeRatio);
204 fy += SkFixedMul_portable(glyph.fAdvanceY, fixedSizeRatio);
205 }
206
207 this->finish();
208}
209
210void GrStencilAndCoverTextContext::drawPosText(const GrPaint& paint,
211 const SkPaint& skPaint,
212 const char text[],
213 size_t byteLength,
214 const SkScalar pos[],
215 SkScalar constY,
216 int scalarsPerPosition) {
217 SkASSERT(byteLength == 0 || text != NULL);
218 SkASSERT(1 == scalarsPerPosition || 2 == scalarsPerPosition);
219
220 // nothing to draw
221 if (text == NULL || byteLength == 0/* || fRC->isEmpty()*/) {
222 return;
223 }
224
225 // This is the fast path. Here we do not bake in the device-transform to
226 // the glyph outline or the advances. This is because we do not need to
227 // position the glyphs at all, since the caller has done the positioning.
228 // The positioning is based on SkPaint::measureText of individual
229 // glyphs. That already uses glyph cache without device transforms. Device
230 // transform is not part of SkPaint::measureText API, and thus we use the
231 // same glyphs as what were measured.
kkinnunenc6cb56f2014-06-24 00:12:27 -0700232
cdaltonb2808cd2014-07-25 14:13:57 -0700233 const float textTranslateY = (1 == scalarsPerPosition ? constY : 0);
234 this->init(paint, skPaint, byteLength, kDoNotUse_DeviceSpaceGlyphsBehavior, textTranslateY);
kkinnunenc6cb56f2014-06-24 00:12:27 -0700235
236 SkDrawCacheProc glyphCacheProc = fSkPaint.getDrawCacheProc();
237
238 SkAutoGlyphCache autoCache(fSkPaint, &fDeviceProperties, NULL);
cdaltonb85a0aa2014-07-21 15:32:44 -0700239 fGlyphCache = autoCache.getCache();
240 fGlyphs = GlyphPathRange::Create(fContext, fGlyphCache, fStroke);
kkinnunenc6cb56f2014-06-24 00:12:27 -0700241
242 const char* stop = text + byteLength;
kkinnunenc6cb56f2014-06-24 00:12:27 -0700243
244 if (SkPaint::kLeft_Align == fSkPaint.getTextAlign()) {
cdaltonb2808cd2014-07-25 14:13:57 -0700245 if (1 == scalarsPerPosition) {
kkinnunenccdaa042014-08-20 01:36:23 -0700246 fTransformType = GrPathRendering::kTranslateX_PathTransformType;
cdaltonb2808cd2014-07-25 14:13:57 -0700247 while (text < stop) {
248 const SkGlyph& glyph = glyphCacheProc(fGlyphCache, &text, 0, 0);
249 if (glyph.fWidth) {
250 this->appendGlyph(glyph.getGlyphID(), *pos);
251 }
252 pos++;
kkinnunenc6cb56f2014-06-24 00:12:27 -0700253 }
cdaltonb2808cd2014-07-25 14:13:57 -0700254 } else {
255 SkASSERT(2 == scalarsPerPosition);
kkinnunenccdaa042014-08-20 01:36:23 -0700256 fTransformType = GrPathRendering::kTranslate_PathTransformType;
cdaltonb2808cd2014-07-25 14:13:57 -0700257 while (text < stop) {
258 const SkGlyph& glyph = glyphCacheProc(fGlyphCache, &text, 0, 0);
259 if (glyph.fWidth) {
260 this->appendGlyph(glyph.getGlyphID(), pos[0], pos[1]);
261 }
262 pos += 2;
263 }
kkinnunenc6cb56f2014-06-24 00:12:27 -0700264 }
265 } else {
kkinnunenccdaa042014-08-20 01:36:23 -0700266 fTransformType = GrPathRendering::kTranslate_PathTransformType;
cdaltonb2808cd2014-07-25 14:13:57 -0700267 SkTextMapStateProc tmsProc(SkMatrix::I(), 0, scalarsPerPosition);
268 SkTextAlignProcScalar alignProc(fSkPaint.getTextAlign());
kkinnunenc6cb56f2014-06-24 00:12:27 -0700269 while (text < stop) {
cdaltonb85a0aa2014-07-21 15:32:44 -0700270 const SkGlyph& glyph = glyphCacheProc(fGlyphCache, &text, 0, 0);
kkinnunenc6cb56f2014-06-24 00:12:27 -0700271 if (glyph.fWidth) {
272 SkPoint tmsLoc;
273 tmsProc(pos, &tmsLoc);
274 SkPoint loc;
275 alignProc(tmsLoc, glyph, &loc);
276
cdaltonb85a0aa2014-07-21 15:32:44 -0700277 this->appendGlyph(glyph.getGlyphID(), loc.x(), loc.y());
kkinnunenc6cb56f2014-06-24 00:12:27 -0700278 }
279 pos += scalarsPerPosition;
280 }
281 }
282
283 this->finish();
284}
285
286bool GrStencilAndCoverTextContext::canDraw(const SkPaint& paint) {
287 if (paint.getRasterizer()) {
288 return false;
289 }
290 if (paint.getMaskFilter()) {
291 return false;
292 }
293 if (paint.getPathEffect()) {
294 return false;
295 }
296
297 // No hairlines unless we can map the 1 px width to the object space.
298 if (paint.getStyle() == SkPaint::kStroke_Style
299 && paint.getStrokeWidth() == 0
300 && fContext->getMatrix().hasPerspective()) {
301 return false;
302 }
303
304 // No color bitmap fonts.
305 SkScalerContext::Rec rec;
306 SkScalerContext::MakeRec(paint, &fDeviceProperties, NULL, &rec);
307 return rec.getFormat() != SkMask::kARGB32_Format;
308}
309
310void GrStencilAndCoverTextContext::init(const GrPaint& paint,
311 const SkPaint& skPaint,
cdaltonb2808cd2014-07-25 14:13:57 -0700312 size_t textByteLength,
313 DeviceSpaceGlyphsBehavior deviceSpaceGlyphsBehavior,
314 SkScalar textTranslateY) {
kkinnunenc6cb56f2014-06-24 00:12:27 -0700315 GrTextContext::init(paint, skPaint);
316
cdaltonb2808cd2014-07-25 14:13:57 -0700317 fContextInitialMatrix = fContext->getMatrix();
318
kkinnunenc6cb56f2014-06-24 00:12:27 -0700319 bool otherBackendsWillDrawAsPaths =
cdaltonb2808cd2014-07-25 14:13:57 -0700320 SkDraw::ShouldDrawTextAsPaths(skPaint, fContextInitialMatrix);
kkinnunenc6cb56f2014-06-24 00:12:27 -0700321
322 if (otherBackendsWillDrawAsPaths) {
323 // This is to reproduce SkDraw::drawText_asPaths glyph positions.
324 fSkPaint.setLinearText(true);
325 fTextRatio = fSkPaint.getTextSize() / SkPaint::kCanonicalTextSizeForPaths;
cdaltonb2808cd2014-07-25 14:13:57 -0700326 fTextInverseRatio = SkPaint::kCanonicalTextSizeForPaths / fSkPaint.getTextSize();
kkinnunenc6cb56f2014-06-24 00:12:27 -0700327 fSkPaint.setTextSize(SkIntToScalar(SkPaint::kCanonicalTextSizeForPaths));
328 if (fSkPaint.getStyle() != SkPaint::kFill_Style) {
329 // Compensate the glyphs being scaled up by fTextRatio by scaling the
330 // stroke down.
331 fSkPaint.setStrokeWidth(fSkPaint.getStrokeWidth() / fTextRatio);
332 }
333 fNeedsDeviceSpaceGlyphs = false;
334 } else {
cdaltonb2808cd2014-07-25 14:13:57 -0700335 fTextRatio = fTextInverseRatio = 1.0f;
336 fNeedsDeviceSpaceGlyphs =
337 kUseIfNeeded_DeviceSpaceGlyphsBehavior == deviceSpaceGlyphsBehavior &&
338 (fContextInitialMatrix.getType() &
339 (SkMatrix::kScale_Mask | SkMatrix::kAffine_Mask)) != 0;
kkinnunenc6cb56f2014-06-24 00:12:27 -0700340 // SkDraw::ShouldDrawTextAsPaths takes care of perspective transforms.
cdaltonb2808cd2014-07-25 14:13:57 -0700341 SkASSERT(!fContextInitialMatrix.hasPerspective());
kkinnunenc6cb56f2014-06-24 00:12:27 -0700342 }
343
344 fStroke = SkStrokeRec(fSkPaint);
345
346 if (fNeedsDeviceSpaceGlyphs) {
cdaltonb2808cd2014-07-25 14:13:57 -0700347 SkASSERT(1.0f == fTextRatio);
348 SkASSERT(0.0f == textTranslateY);
349 fPaint.localCoordChangeInverse(fContextInitialMatrix);
350 fContext->setIdentityMatrix();
351
kkinnunenc6cb56f2014-06-24 00:12:27 -0700352 // The whole shape is baked into the glyph. Make NVPR just fill the
353 // baked shape.
354 fStroke.setStrokeStyle(-1, false);
355 } else {
cdaltonb2808cd2014-07-25 14:13:57 -0700356 if (1.0f != fTextRatio || 0.0f != textTranslateY) {
357 SkMatrix textMatrix;
358 textMatrix.setTranslate(0, textTranslateY);
359 textMatrix.preScale(fTextRatio, fTextRatio);
360 fPaint.localCoordChange(textMatrix);
361 fContext->concatMatrix(textMatrix);
362 }
363
kkinnunenc6cb56f2014-06-24 00:12:27 -0700364 if (fSkPaint.getStrokeWidth() == 0.0f) {
365 if (fSkPaint.getStyle() == SkPaint::kStrokeAndFill_Style) {
366 fStroke.setStrokeStyle(-1, false);
367 } else if (fSkPaint.getStyle() == SkPaint::kStroke_Style) {
368 // Approximate hairline stroke.
369 const SkMatrix& ctm = fContext->getMatrix();
370 SkScalar strokeWidth = SK_Scalar1 /
cdaltonb2808cd2014-07-25 14:13:57 -0700371 (SkVector::Make(ctm.getScaleX(), ctm.getSkewY()).length());
kkinnunenc6cb56f2014-06-24 00:12:27 -0700372 fStroke.setStrokeStyle(strokeWidth, false);
373 }
374 }
375
376 // Make glyph cache produce paths geometry for fill. We will stroke them
377 // by passing fStroke to drawPath. This is the fast path.
378 fSkPaint.setStyle(SkPaint::kFill_Style);
379 }
380 fStateRestore.set(fDrawTarget->drawState());
381
382 fDrawTarget->drawState()->setFromPaint(fPaint, fContext->getMatrix(),
383 fContext->getRenderTarget());
384
385 GR_STATIC_CONST_SAME_STENCIL(kStencilPass,
386 kZero_StencilOp,
387 kZero_StencilOp,
388 kNotEqual_StencilFunc,
389 0xffff,
390 0x0000,
391 0xffff);
392
393 *fDrawTarget->drawState()->stencil() = kStencilPass;
394
cdaltonb85a0aa2014-07-21 15:32:44 -0700395 SkASSERT(0 == fPendingGlyphCount);
kkinnunenc6cb56f2014-06-24 00:12:27 -0700396}
397
cdaltonb2808cd2014-07-25 14:13:57 -0700398inline void GrStencilAndCoverTextContext::appendGlyph(uint16_t glyphID, float x) {
kkinnunenccdaa042014-08-20 01:36:23 -0700399 SkASSERT(GrPathRendering::kTranslateX_PathTransformType == fTransformType);
cdaltonb2808cd2014-07-25 14:13:57 -0700400
cdaltonb85a0aa2014-07-21 15:32:44 -0700401 if (fPendingGlyphCount >= kGlyphBufferSize) {
402 this->flush();
403 }
404
405 fGlyphs->preloadGlyph(glyphID, fGlyphCache);
406
407 fIndexBuffer[fPendingGlyphCount] = glyphID;
cdaltonb2808cd2014-07-25 14:13:57 -0700408 fTransformBuffer[fPendingGlyphCount] = fTextInverseRatio * x;
409
410 ++fPendingGlyphCount;
411}
412
413inline void GrStencilAndCoverTextContext::appendGlyph(uint16_t glyphID, float x, float y) {
kkinnunenccdaa042014-08-20 01:36:23 -0700414 SkASSERT(GrPathRendering::kTranslate_PathTransformType == fTransformType);
cdaltonb2808cd2014-07-25 14:13:57 -0700415
416 if (fPendingGlyphCount >= kGlyphBufferSize) {
417 this->flush();
418 }
419
420 fGlyphs->preloadGlyph(glyphID, fGlyphCache);
421
422 fIndexBuffer[fPendingGlyphCount] = glyphID;
423 fTransformBuffer[2 * fPendingGlyphCount] = fTextInverseRatio * x;
424 fTransformBuffer[2 * fPendingGlyphCount + 1] = fTextInverseRatio * y;
cdaltonb85a0aa2014-07-21 15:32:44 -0700425
426 ++fPendingGlyphCount;
427}
428
429void GrStencilAndCoverTextContext::flush() {
430 if (0 == fPendingGlyphCount) {
kkinnunenc6cb56f2014-06-24 00:12:27 -0700431 return;
432 }
433
cdaltonb85a0aa2014-07-21 15:32:44 -0700434 fDrawTarget->drawPaths(fGlyphs->pathRange(), fIndexBuffer, fPendingGlyphCount,
cdaltonb2808cd2014-07-25 14:13:57 -0700435 fTransformBuffer, fTransformType, SkPath::kWinding_FillType);
cdaltonb85a0aa2014-07-21 15:32:44 -0700436
437 fPendingGlyphCount = 0;
kkinnunenc6cb56f2014-06-24 00:12:27 -0700438}
439
440void GrStencilAndCoverTextContext::finish() {
cdaltonb85a0aa2014-07-21 15:32:44 -0700441 this->flush();
kkinnunenc6cb56f2014-06-24 00:12:27 -0700442
cdaltonb85a0aa2014-07-21 15:32:44 -0700443 SkSafeUnref(fGlyphs);
444 fGlyphs = NULL;
445 fGlyphCache = NULL;
kkinnunenc6cb56f2014-06-24 00:12:27 -0700446
447 fDrawTarget->drawState()->stencil()->setDisabled();
448 fStateRestore.set(NULL);
cdaltonb2808cd2014-07-25 14:13:57 -0700449 fContext->setMatrix(fContextInitialMatrix);
kkinnunenc6cb56f2014-06-24 00:12:27 -0700450 GrTextContext::finish();
451}
452