kkinnunen | c6cb56f | 2014-06-24 00:12:27 -0700 | [diff] [blame] | 1 | /* |
| 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" |
kkinnunen | c6cb56f | 2014-06-24 00:12:27 -0700 | [diff] [blame] | 10 | #include "GrGpu.h" |
| 11 | #include "GrPath.h" |
cdalton | b85a0aa | 2014-07-21 15:32:44 -0700 | [diff] [blame] | 12 | #include "GrPathRange.h" |
kkinnunen | c6cb56f | 2014-06-24 00:12:27 -0700 | [diff] [blame] | 13 | #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 | |
bsalomon | c44be0e | 2014-07-25 07:32:33 -0700 | [diff] [blame] | 21 | class GrStencilAndCoverTextContext::GlyphPathRange : public GrGpuObject { |
cdalton | b85a0aa | 2014-07-21 15:32:44 -0700 | [diff] [blame] | 22 | 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 | |
| 25 | public: |
| 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 | |
bsalomon | c44be0e | 2014-07-25 07:32:33 -0700 | [diff] [blame] | 78 | // GrGpuObject overrides |
cdalton | b85a0aa | 2014-07-21 15:32:44 -0700 | [diff] [blame] | 79 | virtual size_t gpuMemorySize() const SK_OVERRIDE { return fPathRange->gpuMemorySize(); } |
cdalton | b85a0aa | 2014-07-21 15:32:44 -0700 | [diff] [blame] | 80 | |
| 81 | private: |
| 82 | GlyphPathRange(GrContext* context, const SkDescriptor& desc, const SkStrokeRec& stroke) |
bsalomon | c44be0e | 2014-07-25 07:32:33 -0700 | [diff] [blame] | 83 | : INHERITED(context->getGpu(), false) |
| 84 | , fDesc(desc.copy()) |
cdalton | b85a0aa | 2014-07-21 15:32:44 -0700 | [diff] [blame] | 85 | // 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() { |
bsalomon | c44be0e | 2014-07-25 07:32:33 -0700 | [diff] [blame] | 93 | this->release(); |
cdalton | b85a0aa | 2014-07-21 15:32:44 -0700 | [diff] [blame] | 94 | SkDescriptor::Free(fDesc); |
| 95 | } |
| 96 | |
bsalomon | c44be0e | 2014-07-25 07:32:33 -0700 | [diff] [blame] | 97 | virtual void onRelease() SK_OVERRIDE { |
| 98 | INHERITED::onRelease(); |
| 99 | fPathRange.reset(NULL); |
| 100 | } |
| 101 | |
| 102 | virtual void onAbandon() SK_OVERRIDE { |
| 103 | INHERITED::onAbandon(); |
| 104 | fPathRange->abandon(); |
| 105 | fPathRange.reset(NULL); |
| 106 | } |
| 107 | |
| 108 | |
cdalton | b85a0aa | 2014-07-21 15:32:44 -0700 | [diff] [blame] | 109 | static const int kMaxGroupCount = (kMaxGlyphCount + (kGlyphGroupSize - 1)) / kGlyphGroupSize; |
| 110 | SkDescriptor* const fDesc; |
| 111 | uint8_t fLoadedGlyphs[(kMaxGroupCount + 7) >> 3]; // One bit per glyph group |
| 112 | SkAutoTUnref<GrPathRange> fPathRange; |
| 113 | |
bsalomon | c44be0e | 2014-07-25 07:32:33 -0700 | [diff] [blame] | 114 | typedef GrGpuObject INHERITED; |
cdalton | b85a0aa | 2014-07-21 15:32:44 -0700 | [diff] [blame] | 115 | }; |
| 116 | |
kkinnunen | c6cb56f | 2014-06-24 00:12:27 -0700 | [diff] [blame] | 117 | |
| 118 | GrStencilAndCoverTextContext::GrStencilAndCoverTextContext( |
| 119 | GrContext* context, const SkDeviceProperties& properties) |
| 120 | : GrTextContext(context, properties) |
cdalton | b85a0aa | 2014-07-21 15:32:44 -0700 | [diff] [blame] | 121 | , fStroke(SkStrokeRec::kFill_InitStyle) |
| 122 | , fPendingGlyphCount(0) { |
kkinnunen | c6cb56f | 2014-06-24 00:12:27 -0700 | [diff] [blame] | 123 | } |
| 124 | |
| 125 | GrStencilAndCoverTextContext::~GrStencilAndCoverTextContext() { |
| 126 | } |
| 127 | |
| 128 | void GrStencilAndCoverTextContext::drawText(const GrPaint& paint, |
| 129 | const SkPaint& skPaint, |
| 130 | const char text[], |
| 131 | size_t byteLength, |
| 132 | SkScalar x, SkScalar y) { |
| 133 | SkASSERT(byteLength == 0 || text != NULL); |
| 134 | |
| 135 | if (text == NULL || byteLength == 0 /*|| fRC->isEmpty()*/) { |
| 136 | return; |
| 137 | } |
| 138 | |
| 139 | // This is the slow path, mainly used by Skia unit tests. The other |
| 140 | // backends (8888, gpu, ...) use device-space dependent glyph caches. In |
| 141 | // order to match the glyph positions that the other code paths produce, we |
| 142 | // must also use device-space dependent glyph cache. This has the |
| 143 | // side-effect that the glyph shape outline will be in device-space, |
| 144 | // too. This in turn has the side-effect that NVPR can not stroke the paths, |
| 145 | // as the stroke in NVPR is defined in object-space. |
| 146 | // NOTE: here we have following coincidence that works at the moment: |
| 147 | // - When using the device-space glyphs, the transforms we pass to NVPR |
| 148 | // instanced drawing are the global transforms, and the view transform is |
| 149 | // identity. NVPR can not use non-affine transforms in the instanced |
| 150 | // drawing. This is taken care of by SkDraw::ShouldDrawTextAsPaths since it |
| 151 | // will turn off the use of device-space glyphs when perspective transforms |
| 152 | // are in use. |
| 153 | |
| 154 | fGlyphTransform = fContext->getMatrix(); |
| 155 | |
| 156 | this->init(paint, skPaint, byteLength); |
| 157 | |
| 158 | SkMatrix* glyphCacheTransform = NULL; |
| 159 | // Transform our starting point. |
| 160 | if (fNeedsDeviceSpaceGlyphs) { |
| 161 | SkPoint loc; |
| 162 | fGlyphTransform.mapXY(x, y, &loc); |
| 163 | x = loc.fX; |
| 164 | y = loc.fY; |
| 165 | glyphCacheTransform = &fGlyphTransform; |
| 166 | } |
| 167 | |
| 168 | SkDrawCacheProc glyphCacheProc = fSkPaint.getDrawCacheProc(); |
| 169 | SkAutoGlyphCache autoCache(fSkPaint, &fDeviceProperties, glyphCacheTransform); |
cdalton | b85a0aa | 2014-07-21 15:32:44 -0700 | [diff] [blame] | 170 | fGlyphCache = autoCache.getCache(); |
| 171 | fGlyphs = GlyphPathRange::Create(fContext, fGlyphCache, fStroke); |
kkinnunen | c6cb56f | 2014-06-24 00:12:27 -0700 | [diff] [blame] | 172 | |
| 173 | const char* stop = text + byteLength; |
| 174 | |
| 175 | // Measure first if needed. |
| 176 | if (fSkPaint.getTextAlign() != SkPaint::kLeft_Align) { |
| 177 | SkFixed stopX = 0; |
| 178 | SkFixed stopY = 0; |
| 179 | |
| 180 | const char* textPtr = text; |
| 181 | while (textPtr < stop) { |
| 182 | // We don't need x, y here, since all subpixel variants will have the |
| 183 | // same advance. |
cdalton | b85a0aa | 2014-07-21 15:32:44 -0700 | [diff] [blame] | 184 | const SkGlyph& glyph = glyphCacheProc(fGlyphCache, &textPtr, 0, 0); |
kkinnunen | c6cb56f | 2014-06-24 00:12:27 -0700 | [diff] [blame] | 185 | |
| 186 | stopX += glyph.fAdvanceX; |
| 187 | stopY += glyph.fAdvanceY; |
| 188 | } |
| 189 | SkASSERT(textPtr == stop); |
| 190 | |
| 191 | SkScalar alignX = SkFixedToScalar(stopX) * fTextRatio; |
| 192 | SkScalar alignY = SkFixedToScalar(stopY) * fTextRatio; |
| 193 | |
| 194 | if (fSkPaint.getTextAlign() == SkPaint::kCenter_Align) { |
| 195 | alignX = SkScalarHalf(alignX); |
| 196 | alignY = SkScalarHalf(alignY); |
| 197 | } |
| 198 | |
| 199 | x -= alignX; |
| 200 | y -= alignY; |
| 201 | } |
| 202 | |
| 203 | SkAutoKern autokern; |
| 204 | |
| 205 | SkFixed fixedSizeRatio = SkScalarToFixed(fTextRatio); |
| 206 | |
| 207 | SkFixed fx = SkScalarToFixed(x); |
| 208 | SkFixed fy = SkScalarToFixed(y); |
| 209 | while (text < stop) { |
cdalton | b85a0aa | 2014-07-21 15:32:44 -0700 | [diff] [blame] | 210 | const SkGlyph& glyph = glyphCacheProc(fGlyphCache, &text, 0, 0); |
kkinnunen | c6cb56f | 2014-06-24 00:12:27 -0700 | [diff] [blame] | 211 | fx += SkFixedMul_portable(autokern.adjust(glyph), fixedSizeRatio); |
| 212 | if (glyph.fWidth) { |
cdalton | b85a0aa | 2014-07-21 15:32:44 -0700 | [diff] [blame] | 213 | this->appendGlyph(glyph.getGlyphID(), SkFixedToScalar(fx), SkFixedToScalar(fy)); |
kkinnunen | c6cb56f | 2014-06-24 00:12:27 -0700 | [diff] [blame] | 214 | } |
| 215 | |
| 216 | fx += SkFixedMul_portable(glyph.fAdvanceX, fixedSizeRatio); |
| 217 | fy += SkFixedMul_portable(glyph.fAdvanceY, fixedSizeRatio); |
| 218 | } |
| 219 | |
| 220 | this->finish(); |
| 221 | } |
| 222 | |
| 223 | void GrStencilAndCoverTextContext::drawPosText(const GrPaint& paint, |
| 224 | const SkPaint& skPaint, |
| 225 | const char text[], |
| 226 | size_t byteLength, |
| 227 | const SkScalar pos[], |
| 228 | SkScalar constY, |
| 229 | int scalarsPerPosition) { |
| 230 | SkASSERT(byteLength == 0 || text != NULL); |
| 231 | SkASSERT(1 == scalarsPerPosition || 2 == scalarsPerPosition); |
| 232 | |
| 233 | // nothing to draw |
| 234 | if (text == NULL || byteLength == 0/* || fRC->isEmpty()*/) { |
| 235 | return; |
| 236 | } |
| 237 | |
| 238 | // This is the fast path. Here we do not bake in the device-transform to |
| 239 | // the glyph outline or the advances. This is because we do not need to |
| 240 | // position the glyphs at all, since the caller has done the positioning. |
| 241 | // The positioning is based on SkPaint::measureText of individual |
| 242 | // glyphs. That already uses glyph cache without device transforms. Device |
| 243 | // transform is not part of SkPaint::measureText API, and thus we use the |
| 244 | // same glyphs as what were measured. |
| 245 | fGlyphTransform.reset(); |
| 246 | |
| 247 | this->init(paint, skPaint, byteLength); |
| 248 | |
| 249 | SkDrawCacheProc glyphCacheProc = fSkPaint.getDrawCacheProc(); |
| 250 | |
| 251 | SkAutoGlyphCache autoCache(fSkPaint, &fDeviceProperties, NULL); |
cdalton | b85a0aa | 2014-07-21 15:32:44 -0700 | [diff] [blame] | 252 | fGlyphCache = autoCache.getCache(); |
| 253 | fGlyphs = GlyphPathRange::Create(fContext, fGlyphCache, fStroke); |
kkinnunen | c6cb56f | 2014-06-24 00:12:27 -0700 | [diff] [blame] | 254 | |
| 255 | const char* stop = text + byteLength; |
| 256 | SkTextAlignProcScalar alignProc(fSkPaint.getTextAlign()); |
| 257 | SkTextMapStateProc tmsProc(SkMatrix::I(), constY, scalarsPerPosition); |
| 258 | |
| 259 | if (SkPaint::kLeft_Align == fSkPaint.getTextAlign()) { |
| 260 | while (text < stop) { |
| 261 | SkPoint loc; |
| 262 | tmsProc(pos, &loc); |
cdalton | b85a0aa | 2014-07-21 15:32:44 -0700 | [diff] [blame] | 263 | const SkGlyph& glyph = glyphCacheProc(fGlyphCache, &text, 0, 0); |
kkinnunen | c6cb56f | 2014-06-24 00:12:27 -0700 | [diff] [blame] | 264 | if (glyph.fWidth) { |
cdalton | b85a0aa | 2014-07-21 15:32:44 -0700 | [diff] [blame] | 265 | this->appendGlyph(glyph.getGlyphID(), loc.x(), loc.y()); |
kkinnunen | c6cb56f | 2014-06-24 00:12:27 -0700 | [diff] [blame] | 266 | } |
| 267 | pos += scalarsPerPosition; |
| 268 | } |
| 269 | } else { |
| 270 | while (text < stop) { |
cdalton | b85a0aa | 2014-07-21 15:32:44 -0700 | [diff] [blame] | 271 | const SkGlyph& glyph = glyphCacheProc(fGlyphCache, &text, 0, 0); |
kkinnunen | c6cb56f | 2014-06-24 00:12:27 -0700 | [diff] [blame] | 272 | if (glyph.fWidth) { |
| 273 | SkPoint tmsLoc; |
| 274 | tmsProc(pos, &tmsLoc); |
| 275 | SkPoint loc; |
| 276 | alignProc(tmsLoc, glyph, &loc); |
| 277 | |
cdalton | b85a0aa | 2014-07-21 15:32:44 -0700 | [diff] [blame] | 278 | this->appendGlyph(glyph.getGlyphID(), loc.x(), loc.y()); |
kkinnunen | c6cb56f | 2014-06-24 00:12:27 -0700 | [diff] [blame] | 279 | } |
| 280 | pos += scalarsPerPosition; |
| 281 | } |
| 282 | } |
| 283 | |
| 284 | this->finish(); |
| 285 | } |
| 286 | |
| 287 | bool GrStencilAndCoverTextContext::canDraw(const SkPaint& paint) { |
| 288 | if (paint.getRasterizer()) { |
| 289 | return false; |
| 290 | } |
| 291 | if (paint.getMaskFilter()) { |
| 292 | return false; |
| 293 | } |
| 294 | if (paint.getPathEffect()) { |
| 295 | return false; |
| 296 | } |
| 297 | |
| 298 | // No hairlines unless we can map the 1 px width to the object space. |
| 299 | if (paint.getStyle() == SkPaint::kStroke_Style |
| 300 | && paint.getStrokeWidth() == 0 |
| 301 | && fContext->getMatrix().hasPerspective()) { |
| 302 | return false; |
| 303 | } |
| 304 | |
| 305 | // No color bitmap fonts. |
| 306 | SkScalerContext::Rec rec; |
| 307 | SkScalerContext::MakeRec(paint, &fDeviceProperties, NULL, &rec); |
| 308 | return rec.getFormat() != SkMask::kARGB32_Format; |
| 309 | } |
| 310 | |
| 311 | void GrStencilAndCoverTextContext::init(const GrPaint& paint, |
| 312 | const SkPaint& skPaint, |
| 313 | size_t textByteLength) { |
| 314 | GrTextContext::init(paint, skPaint); |
| 315 | |
| 316 | bool otherBackendsWillDrawAsPaths = |
| 317 | SkDraw::ShouldDrawTextAsPaths(skPaint, fContext->getMatrix()); |
| 318 | |
| 319 | if (otherBackendsWillDrawAsPaths) { |
| 320 | // This is to reproduce SkDraw::drawText_asPaths glyph positions. |
| 321 | fSkPaint.setLinearText(true); |
| 322 | fTextRatio = fSkPaint.getTextSize() / SkPaint::kCanonicalTextSizeForPaths; |
| 323 | fSkPaint.setTextSize(SkIntToScalar(SkPaint::kCanonicalTextSizeForPaths)); |
| 324 | if (fSkPaint.getStyle() != SkPaint::kFill_Style) { |
| 325 | // Compensate the glyphs being scaled up by fTextRatio by scaling the |
| 326 | // stroke down. |
| 327 | fSkPaint.setStrokeWidth(fSkPaint.getStrokeWidth() / fTextRatio); |
| 328 | } |
| 329 | fNeedsDeviceSpaceGlyphs = false; |
| 330 | } else { |
| 331 | fTextRatio = 1.0f; |
| 332 | fNeedsDeviceSpaceGlyphs = (fGlyphTransform.getType() & |
| 333 | (SkMatrix::kScale_Mask | SkMatrix::kAffine_Mask)) != 0; |
| 334 | // SkDraw::ShouldDrawTextAsPaths takes care of perspective transforms. |
| 335 | SkASSERT(!fGlyphTransform.hasPerspective()); |
| 336 | if (fNeedsDeviceSpaceGlyphs) { |
| 337 | fPaint.localCoordChangeInverse(fGlyphTransform); |
| 338 | fContext->setIdentityMatrix(); |
| 339 | } |
| 340 | } |
| 341 | |
| 342 | fStroke = SkStrokeRec(fSkPaint); |
| 343 | |
| 344 | if (fNeedsDeviceSpaceGlyphs) { |
| 345 | // The whole shape is baked into the glyph. Make NVPR just fill the |
| 346 | // baked shape. |
| 347 | fStroke.setStrokeStyle(-1, false); |
| 348 | } else { |
| 349 | if (fSkPaint.getStrokeWidth() == 0.0f) { |
| 350 | if (fSkPaint.getStyle() == SkPaint::kStrokeAndFill_Style) { |
| 351 | fStroke.setStrokeStyle(-1, false); |
| 352 | } else if (fSkPaint.getStyle() == SkPaint::kStroke_Style) { |
| 353 | // Approximate hairline stroke. |
| 354 | const SkMatrix& ctm = fContext->getMatrix(); |
| 355 | SkScalar strokeWidth = SK_Scalar1 / |
| 356 | (fTextRatio * SkVector::Make(ctm.getScaleX(), ctm.getSkewY()).length()); |
| 357 | fStroke.setStrokeStyle(strokeWidth, false); |
| 358 | } |
| 359 | } |
| 360 | |
| 361 | // Make glyph cache produce paths geometry for fill. We will stroke them |
| 362 | // by passing fStroke to drawPath. This is the fast path. |
| 363 | fSkPaint.setStyle(SkPaint::kFill_Style); |
| 364 | } |
| 365 | fStateRestore.set(fDrawTarget->drawState()); |
| 366 | |
| 367 | fDrawTarget->drawState()->setFromPaint(fPaint, fContext->getMatrix(), |
| 368 | fContext->getRenderTarget()); |
| 369 | |
| 370 | GR_STATIC_CONST_SAME_STENCIL(kStencilPass, |
| 371 | kZero_StencilOp, |
| 372 | kZero_StencilOp, |
| 373 | kNotEqual_StencilFunc, |
| 374 | 0xffff, |
| 375 | 0x0000, |
| 376 | 0xffff); |
| 377 | |
| 378 | *fDrawTarget->drawState()->stencil() = kStencilPass; |
| 379 | |
cdalton | b85a0aa | 2014-07-21 15:32:44 -0700 | [diff] [blame] | 380 | SkASSERT(0 == fPendingGlyphCount); |
kkinnunen | c6cb56f | 2014-06-24 00:12:27 -0700 | [diff] [blame] | 381 | } |
| 382 | |
cdalton | b85a0aa | 2014-07-21 15:32:44 -0700 | [diff] [blame] | 383 | inline void GrStencilAndCoverTextContext::appendGlyph(uint16_t glyphID, float x, float y) { |
| 384 | if (fPendingGlyphCount >= kGlyphBufferSize) { |
| 385 | this->flush(); |
| 386 | } |
| 387 | |
| 388 | fGlyphs->preloadGlyph(glyphID, fGlyphCache); |
| 389 | |
| 390 | fIndexBuffer[fPendingGlyphCount] = glyphID; |
| 391 | fTransformBuffer[6 * fPendingGlyphCount + 0] = fTextRatio; |
| 392 | fTransformBuffer[6 * fPendingGlyphCount + 1] = 0; |
| 393 | fTransformBuffer[6 * fPendingGlyphCount + 2] = x; |
| 394 | fTransformBuffer[6 * fPendingGlyphCount + 3] = 0; |
| 395 | fTransformBuffer[6 * fPendingGlyphCount + 4] = fTextRatio; |
| 396 | fTransformBuffer[6 * fPendingGlyphCount + 5] = y; |
| 397 | |
| 398 | ++fPendingGlyphCount; |
| 399 | } |
| 400 | |
| 401 | void GrStencilAndCoverTextContext::flush() { |
| 402 | if (0 == fPendingGlyphCount) { |
kkinnunen | c6cb56f | 2014-06-24 00:12:27 -0700 | [diff] [blame] | 403 | return; |
| 404 | } |
| 405 | |
cdalton | b85a0aa | 2014-07-21 15:32:44 -0700 | [diff] [blame] | 406 | fDrawTarget->drawPaths(fGlyphs->pathRange(), fIndexBuffer, fPendingGlyphCount, |
| 407 | fTransformBuffer, GrDrawTarget::kAffine_PathTransformType, |
| 408 | SkPath::kWinding_FillType); |
| 409 | |
| 410 | fPendingGlyphCount = 0; |
kkinnunen | c6cb56f | 2014-06-24 00:12:27 -0700 | [diff] [blame] | 411 | } |
| 412 | |
| 413 | void GrStencilAndCoverTextContext::finish() { |
cdalton | b85a0aa | 2014-07-21 15:32:44 -0700 | [diff] [blame] | 414 | this->flush(); |
kkinnunen | c6cb56f | 2014-06-24 00:12:27 -0700 | [diff] [blame] | 415 | |
cdalton | b85a0aa | 2014-07-21 15:32:44 -0700 | [diff] [blame] | 416 | SkSafeUnref(fGlyphs); |
| 417 | fGlyphs = NULL; |
| 418 | fGlyphCache = NULL; |
kkinnunen | c6cb56f | 2014-06-24 00:12:27 -0700 | [diff] [blame] | 419 | |
| 420 | fDrawTarget->drawState()->stencil()->setDisabled(); |
| 421 | fStateRestore.set(NULL); |
| 422 | if (fNeedsDeviceSpaceGlyphs) { |
| 423 | fContext->setMatrix(fGlyphTransform); |
| 424 | } |
| 425 | GrTextContext::finish(); |
| 426 | } |
| 427 | |