jvanverth@google.com | d830d13 | 2013-11-11 20:54:09 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2013 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 "GrDistanceFieldTextContext.h" |
| 9 | #include "GrAtlas.h" |
jvanverth | 8c27a18 | 2014-10-14 08:45:50 -0700 | [diff] [blame] | 10 | #include "GrBitmapTextContext.h" |
jvanverth@google.com | d830d13 | 2013-11-11 20:54:09 +0000 | [diff] [blame] | 11 | #include "GrDrawTarget.h" |
commit-bot@chromium.org | 6c89c34 | 2014-02-14 21:48:29 +0000 | [diff] [blame] | 12 | #include "GrDrawTargetCaps.h" |
jvanverth@google.com | d830d13 | 2013-11-11 20:54:09 +0000 | [diff] [blame] | 13 | #include "GrFontScaler.h" |
jvanverth | 2d2a68c | 2014-06-10 06:42:56 -0700 | [diff] [blame] | 14 | #include "GrGpu.h" |
jvanverth@google.com | d830d13 | 2013-11-11 20:54:09 +0000 | [diff] [blame] | 15 | #include "GrIndexBuffer.h" |
egdaniel | d58a0ba | 2014-06-11 10:30:05 -0700 | [diff] [blame] | 16 | #include "GrStrokeInfo.h" |
bsalomon | afbf2d6 | 2014-09-30 12:18:44 -0700 | [diff] [blame] | 17 | #include "GrTexturePriv.h" |
jvanverth@google.com | d830d13 | 2013-11-11 20:54:09 +0000 | [diff] [blame] | 18 | #include "GrTextStrike.h" |
| 19 | #include "GrTextStrike_impl.h" |
bsalomon | afbf2d6 | 2014-09-30 12:18:44 -0700 | [diff] [blame] | 20 | |
| 21 | #include "SkColorFilter.h" |
commit-bot@chromium.org | 64b08a1 | 2014-04-15 17:53:21 +0000 | [diff] [blame] | 22 | #include "SkDistanceFieldGen.h" |
commit-bot@chromium.org | 9f94b91 | 2014-01-30 15:22:54 +0000 | [diff] [blame] | 23 | #include "SkDraw.h" |
bsalomon | afbf2d6 | 2014-09-30 12:18:44 -0700 | [diff] [blame] | 24 | #include "SkGlyphCache.h" |
commit-bot@chromium.org | e8612d9 | 2014-01-28 22:02:07 +0000 | [diff] [blame] | 25 | #include "SkGpuDevice.h" |
jvanverth@google.com | d830d13 | 2013-11-11 20:54:09 +0000 | [diff] [blame] | 26 | #include "SkPath.h" |
| 27 | #include "SkRTConf.h" |
| 28 | #include "SkStrokeRec.h" |
| 29 | #include "effects/GrDistanceFieldTextureEffect.h" |
| 30 | |
jvanverth | feceba5 | 2014-07-25 19:03:34 -0700 | [diff] [blame] | 31 | SK_CONF_DECLARE(bool, c_DumpFontCache, "gpu.dumpFontCache", false, |
| 32 | "Dump the contents of the font cache before every purge."); |
| 33 | |
commit-bot@chromium.org | dc5cd85 | 2014-04-02 19:24:32 +0000 | [diff] [blame] | 34 | static const int kSmallDFFontSize = 32; |
| 35 | static const int kSmallDFFontLimit = 32; |
| 36 | static const int kMediumDFFontSize = 64; |
| 37 | static const int kMediumDFFontLimit = 64; |
| 38 | static const int kLargeDFFontSize = 128; |
commit-bot@chromium.org | 8128d8c | 2013-12-19 16:12:25 +0000 | [diff] [blame] | 39 | |
jvanverth | feceba5 | 2014-07-25 19:03:34 -0700 | [diff] [blame] | 40 | namespace { |
| 41 | // position + texture coord |
| 42 | extern const GrVertexAttrib gTextVertexAttribs[] = { |
| 43 | {kVec2f_GrVertexAttribType, 0, kPosition_GrVertexAttribBinding}, |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 44 | {kVec2f_GrVertexAttribType, sizeof(SkPoint) , kGeometryProcessor_GrVertexAttribBinding} |
jvanverth | feceba5 | 2014-07-25 19:03:34 -0700 | [diff] [blame] | 45 | }; |
| 46 | |
egdaniel | 7b3d5ee | 2014-08-28 05:41:14 -0700 | [diff] [blame] | 47 | static const size_t kTextVASize = 2 * sizeof(SkPoint); |
| 48 | |
jvanverth | feceba5 | 2014-07-25 19:03:34 -0700 | [diff] [blame] | 49 | // position + color + texture coord |
| 50 | extern const GrVertexAttrib gTextVertexWithColorAttribs[] = { |
| 51 | {kVec2f_GrVertexAttribType, 0, kPosition_GrVertexAttribBinding}, |
| 52 | {kVec4ub_GrVertexAttribType, sizeof(SkPoint), kColor_GrVertexAttribBinding}, |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 53 | {kVec2f_GrVertexAttribType, sizeof(SkPoint) + sizeof(GrColor), kGeometryProcessor_GrVertexAttribBinding} |
jvanverth | feceba5 | 2014-07-25 19:03:34 -0700 | [diff] [blame] | 54 | }; |
| 55 | |
egdaniel | 7b3d5ee | 2014-08-28 05:41:14 -0700 | [diff] [blame] | 56 | static const size_t kTextVAColorSize = 2 * sizeof(SkPoint) + sizeof(GrColor); |
| 57 | |
jvanverth | feceba5 | 2014-07-25 19:03:34 -0700 | [diff] [blame] | 58 | }; |
jvanverth@google.com | d830d13 | 2013-11-11 20:54:09 +0000 | [diff] [blame] | 59 | |
skia.committer@gmail.com | e5d7015 | 2014-01-29 07:01:48 +0000 | [diff] [blame] | 60 | GrDistanceFieldTextContext::GrDistanceFieldTextContext(GrContext* context, |
commit-bot@chromium.org | 6fcd1ef | 2014-05-02 12:39:41 +0000 | [diff] [blame] | 61 | const SkDeviceProperties& properties, |
| 62 | bool enable) |
Mike Klein | 6a25bd0 | 2014-08-29 10:03:59 -0400 | [diff] [blame] | 63 | : GrTextContext(context, properties) { |
commit-bot@chromium.org | 6fcd1ef | 2014-05-02 12:39:41 +0000 | [diff] [blame] | 64 | #if SK_FORCE_DISTANCEFIELD_FONTS |
Mike Klein | 6a25bd0 | 2014-08-29 10:03:59 -0400 | [diff] [blame] | 65 | fEnableDFRendering = true; |
commit-bot@chromium.org | 6fcd1ef | 2014-05-02 12:39:41 +0000 | [diff] [blame] | 66 | #else |
Mike Klein | 6a25bd0 | 2014-08-29 10:03:59 -0400 | [diff] [blame] | 67 | fEnableDFRendering = enable; |
commit-bot@chromium.org | 6fcd1ef | 2014-05-02 12:39:41 +0000 | [diff] [blame] | 68 | #endif |
Mike Klein | 6a25bd0 | 2014-08-29 10:03:59 -0400 | [diff] [blame] | 69 | fStrike = NULL; |
| 70 | fGammaTexture = NULL; |
| 71 | |
| 72 | fCurrTexture = NULL; |
| 73 | fCurrVertex = 0; |
| 74 | fEffectTextureUniqueID = SK_InvalidUniqueID; |
| 75 | fEffectColor = GrColor_ILLEGAL; |
| 76 | fEffectFlags = 0; |
| 77 | |
| 78 | fVertices = NULL; |
| 79 | fMaxVertices = 0; |
| 80 | |
jvanverth | 1723bfc | 2014-07-30 09:16:33 -0700 | [diff] [blame] | 81 | fVertexBounds.setLargestInverted(); |
jvanverth@google.com | d830d13 | 2013-11-11 20:54:09 +0000 | [diff] [blame] | 82 | } |
| 83 | |
jvanverth | 8c27a18 | 2014-10-14 08:45:50 -0700 | [diff] [blame] | 84 | GrDistanceFieldTextContext* GrDistanceFieldTextContext::Create(GrContext* context, |
| 85 | const SkDeviceProperties& props, |
| 86 | bool enable) { |
| 87 | GrDistanceFieldTextContext* textContext = SkNEW_ARGS(GrDistanceFieldTextContext, |
| 88 | (context, props, enable)); |
| 89 | textContext->fFallbackTextContext = GrBitmapTextContext::Create(context, props); |
| 90 | |
| 91 | return textContext; |
| 92 | } |
| 93 | |
jvanverth@google.com | d830d13 | 2013-11-11 20:54:09 +0000 | [diff] [blame] | 94 | GrDistanceFieldTextContext::~GrDistanceFieldTextContext() { |
jvanverth | 0fedb19 | 2014-10-08 09:07:27 -0700 | [diff] [blame] | 95 | this->flush(); |
jvanverth | 2d2a68c | 2014-06-10 06:42:56 -0700 | [diff] [blame] | 96 | SkSafeSetNull(fGammaTexture); |
jvanverth@google.com | d830d13 | 2013-11-11 20:54:09 +0000 | [diff] [blame] | 97 | } |
| 98 | |
commit-bot@chromium.org | cbbc481 | 2014-01-30 22:05:47 +0000 | [diff] [blame] | 99 | bool GrDistanceFieldTextContext::canDraw(const SkPaint& paint) { |
commit-bot@chromium.org | 6fcd1ef | 2014-05-02 12:39:41 +0000 | [diff] [blame] | 100 | if (!fEnableDFRendering && !paint.isDistanceFieldTextTEMP()) { |
commit-bot@chromium.org | eefd8a0 | 2014-04-08 20:14:32 +0000 | [diff] [blame] | 101 | return false; |
| 102 | } |
| 103 | |
skia.committer@gmail.com | e1d9443 | 2014-04-09 03:04:11 +0000 | [diff] [blame] | 104 | // rasterizers and mask filters modify alpha, which doesn't |
commit-bot@chromium.org | eefd8a0 | 2014-04-08 20:14:32 +0000 | [diff] [blame] | 105 | // translate well to distance |
| 106 | if (paint.getRasterizer() || paint.getMaskFilter() || |
| 107 | !fContext->getTextTarget()->caps()->shaderDerivativeSupport()) { |
| 108 | return false; |
| 109 | } |
| 110 | |
| 111 | // TODO: add some stroking support |
| 112 | if (paint.getStyle() != SkPaint::kFill_Style) { |
| 113 | return false; |
| 114 | } |
| 115 | |
| 116 | // TODO: choose an appropriate maximum scale for distance fields and |
| 117 | // enable perspective |
| 118 | if (SkDraw::ShouldDrawTextAsPaths(paint, fContext->getMatrix())) { |
| 119 | return false; |
| 120 | } |
| 121 | |
| 122 | // distance fields cannot represent color fonts |
| 123 | SkScalerContext::Rec rec; |
| 124 | SkScalerContext::MakeRec(paint, &fDeviceProperties, NULL, &rec); |
| 125 | return rec.getFormat() != SkMask::kARGB32_Format; |
commit-bot@chromium.org | cbbc481 | 2014-01-30 22:05:47 +0000 | [diff] [blame] | 126 | } |
| 127 | |
commit-bot@chromium.org | cbbc481 | 2014-01-30 22:05:47 +0000 | [diff] [blame] | 128 | inline void GrDistanceFieldTextContext::init(const GrPaint& paint, const SkPaint& skPaint) { |
| 129 | GrTextContext::init(paint, skPaint); |
| 130 | |
| 131 | fStrike = NULL; |
| 132 | |
jvanverth | 76ce81e | 2014-09-22 14:26:53 -0700 | [diff] [blame] | 133 | const SkMatrix& ctm = fContext->getMatrix(); |
jvanverth | 9564ce6 | 2014-09-16 05:45:19 -0700 | [diff] [blame] | 134 | |
| 135 | // getMaxScale doesn't support perspective, so neither do we at the moment |
jvanverth | 76ce81e | 2014-09-22 14:26:53 -0700 | [diff] [blame] | 136 | SkASSERT(!ctm.hasPerspective()); |
| 137 | SkScalar maxScale = ctm.getMaxScale(); |
jvanverth | 9564ce6 | 2014-09-16 05:45:19 -0700 | [diff] [blame] | 138 | SkScalar textSize = fSkPaint.getTextSize(); |
jvanverth | 76ce81e | 2014-09-22 14:26:53 -0700 | [diff] [blame] | 139 | SkScalar scaledTextSize = textSize; |
| 140 | // if we have non-unity scale, we need to choose our base text size |
| 141 | // based on the SkPaint's text size multiplied by the max scale factor |
jvanverth | 9564ce6 | 2014-09-16 05:45:19 -0700 | [diff] [blame] | 142 | // TODO: do we need to do this if we're scaling down (i.e. maxScale < 1)? |
| 143 | if (maxScale > 0 && !SkScalarNearlyEqual(maxScale, SK_Scalar1)) { |
jvanverth | 76ce81e | 2014-09-22 14:26:53 -0700 | [diff] [blame] | 144 | scaledTextSize *= maxScale; |
jvanverth | 9564ce6 | 2014-09-16 05:45:19 -0700 | [diff] [blame] | 145 | } |
| 146 | |
commit-bot@chromium.org | cbbc481 | 2014-01-30 22:05:47 +0000 | [diff] [blame] | 147 | fCurrVertex = 0; |
| 148 | |
| 149 | fVertices = NULL; |
commit-bot@chromium.org | cbbc481 | 2014-01-30 22:05:47 +0000 | [diff] [blame] | 150 | |
jvanverth | 76ce81e | 2014-09-22 14:26:53 -0700 | [diff] [blame] | 151 | if (scaledTextSize <= kSmallDFFontLimit) { |
jvanverth | 9564ce6 | 2014-09-16 05:45:19 -0700 | [diff] [blame] | 152 | fTextRatio = textSize / kSmallDFFontSize; |
commit-bot@chromium.org | dc5cd85 | 2014-04-02 19:24:32 +0000 | [diff] [blame] | 153 | fSkPaint.setTextSize(SkIntToScalar(kSmallDFFontSize)); |
jvanverth | 76ce81e | 2014-09-22 14:26:53 -0700 | [diff] [blame] | 154 | } else if (scaledTextSize <= kMediumDFFontLimit) { |
jvanverth | 9564ce6 | 2014-09-16 05:45:19 -0700 | [diff] [blame] | 155 | fTextRatio = textSize / kMediumDFFontSize; |
commit-bot@chromium.org | dc5cd85 | 2014-04-02 19:24:32 +0000 | [diff] [blame] | 156 | fSkPaint.setTextSize(SkIntToScalar(kMediumDFFontSize)); |
| 157 | } else { |
jvanverth | 9564ce6 | 2014-09-16 05:45:19 -0700 | [diff] [blame] | 158 | fTextRatio = textSize / kLargeDFFontSize; |
commit-bot@chromium.org | dc5cd85 | 2014-04-02 19:24:32 +0000 | [diff] [blame] | 159 | fSkPaint.setTextSize(SkIntToScalar(kLargeDFFontSize)); |
| 160 | } |
skia.committer@gmail.com | 4c18e9f | 2014-01-31 03:01:59 +0000 | [diff] [blame] | 161 | |
commit-bot@chromium.org | 609ced4 | 2014-04-03 18:25:48 +0000 | [diff] [blame] | 162 | fUseLCDText = fSkPaint.isLCDRenderText(); |
skia.committer@gmail.com | 221b911 | 2014-04-04 03:04:32 +0000 | [diff] [blame] | 163 | |
commit-bot@chromium.org | cbbc481 | 2014-01-30 22:05:47 +0000 | [diff] [blame] | 164 | fSkPaint.setLCDRenderText(false); |
| 165 | fSkPaint.setAutohinted(false); |
jvanverth | 2d2a68c | 2014-06-10 06:42:56 -0700 | [diff] [blame] | 166 | fSkPaint.setHinting(SkPaint::kNormal_Hinting); |
commit-bot@chromium.org | 0bed43c | 2014-03-14 21:22:38 +0000 | [diff] [blame] | 167 | fSkPaint.setSubpixelText(true); |
jvanverth | 2d2a68c | 2014-06-10 06:42:56 -0700 | [diff] [blame] | 168 | |
commit-bot@chromium.org | cbbc481 | 2014-01-30 22:05:47 +0000 | [diff] [blame] | 169 | } |
| 170 | |
jvanverth | 2d2a68c | 2014-06-10 06:42:56 -0700 | [diff] [blame] | 171 | static void setup_gamma_texture(GrContext* context, const SkGlyphCache* cache, |
| 172 | const SkDeviceProperties& deviceProperties, |
| 173 | GrTexture** gammaTexture) { |
| 174 | if (NULL == *gammaTexture) { |
| 175 | int width, height; |
| 176 | size_t size; |
| 177 | |
| 178 | #ifdef SK_GAMMA_CONTRAST |
| 179 | SkScalar contrast = SK_GAMMA_CONTRAST; |
| 180 | #else |
| 181 | SkScalar contrast = 0.5f; |
| 182 | #endif |
reed | b2d77e4 | 2014-10-14 08:26:33 -0700 | [diff] [blame] | 183 | SkScalar paintGamma = deviceProperties.gamma(); |
| 184 | SkScalar deviceGamma = deviceProperties.gamma(); |
jvanverth | 2d2a68c | 2014-06-10 06:42:56 -0700 | [diff] [blame] | 185 | |
| 186 | size = SkScalerContext::GetGammaLUTSize(contrast, paintGamma, deviceGamma, |
| 187 | &width, &height); |
| 188 | |
| 189 | SkAutoTArray<uint8_t> data((int)size); |
| 190 | SkScalerContext::GetGammaLUTData(contrast, paintGamma, deviceGamma, data.get()); |
| 191 | |
| 192 | // TODO: Update this to use the cache rather than directly creating a texture. |
| 193 | GrTextureDesc desc; |
| 194 | desc.fFlags = kDynamicUpdate_GrTextureFlagBit; |
| 195 | desc.fWidth = width; |
| 196 | desc.fHeight = height; |
| 197 | desc.fConfig = kAlpha_8_GrPixelConfig; |
| 198 | |
| 199 | *gammaTexture = context->getGpu()->createTexture(desc, NULL, 0); |
| 200 | if (NULL == *gammaTexture) { |
| 201 | return; |
| 202 | } |
| 203 | |
bsalomon | 81beccc | 2014-10-13 12:32:55 -0700 | [diff] [blame] | 204 | (*gammaTexture)->writePixels(0, 0, width, height, |
| 205 | (*gammaTexture)->config(), data.get(), 0, |
| 206 | GrContext::kDontFlush_PixelOpsFlag); |
jvanverth | 2d2a68c | 2014-06-10 06:42:56 -0700 | [diff] [blame] | 207 | } |
| 208 | } |
| 209 | |
jvanverth | 8c27a18 | 2014-10-14 08:45:50 -0700 | [diff] [blame] | 210 | void GrDistanceFieldTextContext::onDrawText(const GrPaint& paint, const SkPaint& skPaint, |
commit-bot@chromium.org | cbbc481 | 2014-01-30 22:05:47 +0000 | [diff] [blame] | 211 | const char text[], size_t byteLength, |
commit-bot@chromium.org | e8612d9 | 2014-01-28 22:02:07 +0000 | [diff] [blame] | 212 | SkScalar x, SkScalar y) { |
commit-bot@chromium.org | 8128d8c | 2013-12-19 16:12:25 +0000 | [diff] [blame] | 213 | SkASSERT(byteLength == 0 || text != NULL); |
| 214 | |
commit-bot@chromium.org | e8612d9 | 2014-01-28 22:02:07 +0000 | [diff] [blame] | 215 | // nothing to draw or can't draw |
| 216 | if (text == NULL || byteLength == 0 /* no raster clip? || fRC->isEmpty()*/ |
| 217 | || fSkPaint.getRasterizer()) { |
commit-bot@chromium.org | 8128d8c | 2013-12-19 16:12:25 +0000 | [diff] [blame] | 218 | return; |
| 219 | } |
skia.committer@gmail.com | e5d7015 | 2014-01-29 07:01:48 +0000 | [diff] [blame] | 220 | |
commit-bot@chromium.org | cbbc481 | 2014-01-30 22:05:47 +0000 | [diff] [blame] | 221 | this->init(paint, skPaint); |
| 222 | |
commit-bot@chromium.org | 8128d8c | 2013-12-19 16:12:25 +0000 | [diff] [blame] | 223 | SkScalar sizeRatio = fTextRatio; |
| 224 | |
| 225 | SkDrawCacheProc glyphCacheProc = fSkPaint.getDrawCacheProc(); |
| 226 | |
jvanverth | 2d2a68c | 2014-06-10 06:42:56 -0700 | [diff] [blame] | 227 | SkAutoGlyphCacheNoGamma autoCache(fSkPaint, &fDeviceProperties, NULL); |
| 228 | SkGlyphCache* cache = autoCache.getCache(); |
| 229 | GrFontScaler* fontScaler = GetGrFontScaler(cache); |
| 230 | |
| 231 | setup_gamma_texture(fContext, cache, fDeviceProperties, &fGammaTexture); |
skia.committer@gmail.com | e5d7015 | 2014-01-29 07:01:48 +0000 | [diff] [blame] | 232 | |
commit-bot@chromium.org | 8128d8c | 2013-12-19 16:12:25 +0000 | [diff] [blame] | 233 | // need to measure first |
| 234 | // TODO - generate positions and pre-load cache as well? |
| 235 | const char* stop = text + byteLength; |
| 236 | if (fSkPaint.getTextAlign() != SkPaint::kLeft_Align) { |
| 237 | SkFixed stopX = 0; |
| 238 | SkFixed stopY = 0; |
| 239 | |
| 240 | const char* textPtr = text; |
| 241 | while (textPtr < stop) { |
| 242 | // don't need x, y here, since all subpixel variants will have the |
| 243 | // same advance |
| 244 | const SkGlyph& glyph = glyphCacheProc(cache, &textPtr, 0, 0); |
| 245 | |
| 246 | stopX += glyph.fAdvanceX; |
| 247 | stopY += glyph.fAdvanceY; |
| 248 | } |
| 249 | SkASSERT(textPtr == stop); |
| 250 | |
| 251 | SkScalar alignX = SkFixedToScalar(stopX)*sizeRatio; |
| 252 | SkScalar alignY = SkFixedToScalar(stopY)*sizeRatio; |
| 253 | |
| 254 | if (fSkPaint.getTextAlign() == SkPaint::kCenter_Align) { |
| 255 | alignX = SkScalarHalf(alignX); |
| 256 | alignY = SkScalarHalf(alignY); |
| 257 | } |
| 258 | |
| 259 | x -= alignX; |
| 260 | y -= alignY; |
| 261 | } |
| 262 | |
commit-bot@chromium.org | 5408f8f | 2014-05-21 19:44:24 +0000 | [diff] [blame] | 263 | SkFixed fx = SkScalarToFixed(x); |
| 264 | SkFixed fy = SkScalarToFixed(y); |
commit-bot@chromium.org | 8128d8c | 2013-12-19 16:12:25 +0000 | [diff] [blame] | 265 | SkFixed fixedScale = SkScalarToFixed(sizeRatio); |
| 266 | while (text < stop) { |
commit-bot@chromium.org | a9dae71 | 2014-03-24 18:34:04 +0000 | [diff] [blame] | 267 | const SkGlyph& glyph = glyphCacheProc(cache, &text, 0, 0); |
commit-bot@chromium.org | 8128d8c | 2013-12-19 16:12:25 +0000 | [diff] [blame] | 268 | |
| 269 | if (glyph.fWidth) { |
jvanverth | 0fedb19 | 2014-10-08 09:07:27 -0700 | [diff] [blame] | 270 | this->appendGlyph(GrGlyph::Pack(glyph.getGlyphID(), |
| 271 | glyph.getSubXFixed(), |
| 272 | glyph.getSubYFixed()), |
| 273 | fx, |
| 274 | fy, |
| 275 | fontScaler); |
commit-bot@chromium.org | 8128d8c | 2013-12-19 16:12:25 +0000 | [diff] [blame] | 276 | } |
| 277 | |
| 278 | fx += SkFixedMul_portable(glyph.fAdvanceX, fixedScale); |
| 279 | fy += SkFixedMul_portable(glyph.fAdvanceY, fixedScale); |
| 280 | } |
commit-bot@chromium.org | cbbc481 | 2014-01-30 22:05:47 +0000 | [diff] [blame] | 281 | |
| 282 | this->finish(); |
commit-bot@chromium.org | 8128d8c | 2013-12-19 16:12:25 +0000 | [diff] [blame] | 283 | } |
| 284 | |
jvanverth | 8c27a18 | 2014-10-14 08:45:50 -0700 | [diff] [blame] | 285 | void GrDistanceFieldTextContext::onDrawPosText(const GrPaint& paint, const SkPaint& skPaint, |
commit-bot@chromium.org | cbbc481 | 2014-01-30 22:05:47 +0000 | [diff] [blame] | 286 | const char text[], size_t byteLength, |
fmalita | 05c4a43 | 2014-09-29 06:29:53 -0700 | [diff] [blame] | 287 | const SkScalar pos[], int scalarsPerPosition, |
| 288 | const SkPoint& offset) { |
commit-bot@chromium.org | 8128d8c | 2013-12-19 16:12:25 +0000 | [diff] [blame] | 289 | |
| 290 | SkASSERT(byteLength == 0 || text != NULL); |
| 291 | SkASSERT(1 == scalarsPerPosition || 2 == scalarsPerPosition); |
| 292 | |
| 293 | // nothing to draw |
commit-bot@chromium.org | cbbc481 | 2014-01-30 22:05:47 +0000 | [diff] [blame] | 294 | if (text == NULL || byteLength == 0 /* no raster clip? || fRC->isEmpty()*/) { |
commit-bot@chromium.org | 8128d8c | 2013-12-19 16:12:25 +0000 | [diff] [blame] | 295 | return; |
| 296 | } |
| 297 | |
commit-bot@chromium.org | cbbc481 | 2014-01-30 22:05:47 +0000 | [diff] [blame] | 298 | this->init(paint, skPaint); |
| 299 | |
commit-bot@chromium.org | 8128d8c | 2013-12-19 16:12:25 +0000 | [diff] [blame] | 300 | SkDrawCacheProc glyphCacheProc = fSkPaint.getDrawCacheProc(); |
| 301 | |
jvanverth | 2d2a68c | 2014-06-10 06:42:56 -0700 | [diff] [blame] | 302 | SkAutoGlyphCacheNoGamma autoCache(fSkPaint, &fDeviceProperties, NULL); |
| 303 | SkGlyphCache* cache = autoCache.getCache(); |
| 304 | GrFontScaler* fontScaler = GetGrFontScaler(cache); |
| 305 | |
| 306 | setup_gamma_texture(fContext, cache, fDeviceProperties, &fGammaTexture); |
skia.committer@gmail.com | e5d7015 | 2014-01-29 07:01:48 +0000 | [diff] [blame] | 307 | |
commit-bot@chromium.org | 8128d8c | 2013-12-19 16:12:25 +0000 | [diff] [blame] | 308 | const char* stop = text + byteLength; |
| 309 | |
| 310 | if (SkPaint::kLeft_Align == fSkPaint.getTextAlign()) { |
| 311 | while (text < stop) { |
| 312 | // the last 2 parameters are ignored |
| 313 | const SkGlyph& glyph = glyphCacheProc(cache, &text, 0, 0); |
| 314 | |
| 315 | if (glyph.fWidth) { |
fmalita | 05c4a43 | 2014-09-29 06:29:53 -0700 | [diff] [blame] | 316 | SkScalar x = offset.x() + pos[0]; |
| 317 | SkScalar y = offset.y() + (2 == scalarsPerPosition ? pos[1] : 0); |
commit-bot@chromium.org | 8128d8c | 2013-12-19 16:12:25 +0000 | [diff] [blame] | 318 | |
jvanverth | 0fedb19 | 2014-10-08 09:07:27 -0700 | [diff] [blame] | 319 | this->appendGlyph(GrGlyph::Pack(glyph.getGlyphID(), |
| 320 | glyph.getSubXFixed(), |
| 321 | glyph.getSubYFixed()), |
| 322 | SkScalarToFixed(x), |
| 323 | SkScalarToFixed(y), |
| 324 | fontScaler); |
commit-bot@chromium.org | 8128d8c | 2013-12-19 16:12:25 +0000 | [diff] [blame] | 325 | } |
| 326 | pos += scalarsPerPosition; |
| 327 | } |
| 328 | } else { |
| 329 | int alignShift = SkPaint::kCenter_Align == fSkPaint.getTextAlign() ? 1 : 0; |
| 330 | while (text < stop) { |
| 331 | // the last 2 parameters are ignored |
| 332 | const SkGlyph& glyph = glyphCacheProc(cache, &text, 0, 0); |
| 333 | |
| 334 | if (glyph.fWidth) { |
fmalita | 05c4a43 | 2014-09-29 06:29:53 -0700 | [diff] [blame] | 335 | SkScalar x = offset.x() + pos[0]; |
| 336 | SkScalar y = offset.y() + (2 == scalarsPerPosition ? pos[1] : 0); |
skia.committer@gmail.com | 22e9672 | 2013-12-20 07:01:36 +0000 | [diff] [blame] | 337 | |
jvanverth | 0fedb19 | 2014-10-08 09:07:27 -0700 | [diff] [blame] | 338 | this->appendGlyph(GrGlyph::Pack(glyph.getGlyphID(), |
| 339 | glyph.getSubXFixed(), |
| 340 | glyph.getSubYFixed()), |
| 341 | SkScalarToFixed(x) - (glyph.fAdvanceX >> alignShift), |
| 342 | SkScalarToFixed(y) - (glyph.fAdvanceY >> alignShift), |
| 343 | fontScaler); |
commit-bot@chromium.org | 8128d8c | 2013-12-19 16:12:25 +0000 | [diff] [blame] | 344 | } |
| 345 | pos += scalarsPerPosition; |
| 346 | } |
| 347 | } |
commit-bot@chromium.org | cbbc481 | 2014-01-30 22:05:47 +0000 | [diff] [blame] | 348 | |
| 349 | this->finish(); |
commit-bot@chromium.org | 8128d8c | 2013-12-19 16:12:25 +0000 | [diff] [blame] | 350 | } |
jvanverth | 0fedb19 | 2014-10-08 09:07:27 -0700 | [diff] [blame] | 351 | |
| 352 | static inline GrColor skcolor_to_grcolor_nopremultiply(SkColor c) { |
| 353 | unsigned r = SkColorGetR(c); |
| 354 | unsigned g = SkColorGetG(c); |
| 355 | unsigned b = SkColorGetB(c); |
| 356 | return GrColorPackRGBA(r, g, b, 0xff); |
| 357 | } |
| 358 | |
| 359 | void GrDistanceFieldTextContext::setupCoverageEffect(const SkColor& filteredColor) { |
| 360 | GrTextureParams params(SkShader::kRepeat_TileMode, GrTextureParams::kBilerp_FilterMode); |
| 361 | GrTextureParams gammaParams(SkShader::kClamp_TileMode, GrTextureParams::kNone_FilterMode); |
| 362 | |
| 363 | uint32_t textureUniqueID = fCurrTexture->getUniqueID(); |
| 364 | const SkMatrix& ctm = fContext->getMatrix(); |
| 365 | |
| 366 | // set up any flags |
| 367 | uint32_t flags = 0; |
| 368 | flags |= ctm.isSimilarity() ? kSimilarity_DistanceFieldEffectFlag : 0; |
| 369 | flags |= fUseLCDText ? kUseLCD_DistanceFieldEffectFlag : 0; |
| 370 | flags |= fUseLCDText && ctm.rectStaysRect() ? |
| 371 | kRectToRect_DistanceFieldEffectFlag : 0; |
reed | b2d77e4 | 2014-10-14 08:26:33 -0700 | [diff] [blame] | 372 | bool useBGR = SkPixelGeometryIsBGR(fDeviceProperties.pixelGeometry()); |
jvanverth | 0fedb19 | 2014-10-08 09:07:27 -0700 | [diff] [blame] | 373 | flags |= fUseLCDText && useBGR ? kBGR_DistanceFieldEffectFlag : 0; |
| 374 | |
| 375 | // see if we need to create a new effect |
| 376 | if (textureUniqueID != fEffectTextureUniqueID || |
| 377 | filteredColor != fEffectColor || |
| 378 | flags != fEffectFlags) { |
| 379 | if (fUseLCDText) { |
| 380 | GrColor colorNoPreMul = skcolor_to_grcolor_nopremultiply(filteredColor); |
| 381 | fCachedGeometryProcessor.reset(GrDistanceFieldLCDTextureEffect::Create(fCurrTexture, |
| 382 | params, |
| 383 | fGammaTexture, |
| 384 | gammaParams, |
| 385 | colorNoPreMul, |
| 386 | flags)); |
| 387 | } else { |
| 388 | #ifdef SK_GAMMA_APPLY_TO_A8 |
reed | b2d77e4 | 2014-10-14 08:26:33 -0700 | [diff] [blame] | 389 | U8CPU lum = SkColorSpaceLuminance::computeLuminance(fDeviceProperties.gamma(), |
jvanverth | 0fedb19 | 2014-10-08 09:07:27 -0700 | [diff] [blame] | 390 | filteredColor); |
| 391 | fCachedGeometryProcessor.reset(GrDistanceFieldTextureEffect::Create(fCurrTexture, |
| 392 | params, |
| 393 | fGammaTexture, |
| 394 | gammaParams, |
| 395 | lum/255.f, |
| 396 | flags)); |
| 397 | #else |
| 398 | fCachedGeometryProcessor.reset(GrDistanceFieldTextureEffect::Create(fCurrTexture, |
| 399 | params, flags)); |
| 400 | #endif |
| 401 | } |
| 402 | fEffectTextureUniqueID = textureUniqueID; |
| 403 | fEffectColor = filteredColor; |
| 404 | fEffectFlags = flags; |
| 405 | } |
| 406 | |
| 407 | } |
| 408 | |
| 409 | void GrDistanceFieldTextContext::appendGlyph(GrGlyph::PackedID packed, |
| 410 | SkFixed vx, SkFixed vy, |
| 411 | GrFontScaler* scaler) { |
| 412 | if (NULL == fDrawTarget) { |
| 413 | return; |
| 414 | } |
| 415 | |
| 416 | if (NULL == fStrike) { |
| 417 | fStrike = fContext->getFontCache()->getStrike(scaler, true); |
| 418 | } |
| 419 | |
| 420 | GrGlyph* glyph = fStrike->getGlyph(packed, scaler); |
| 421 | if (NULL == glyph || glyph->fBounds.isEmpty()) { |
| 422 | return; |
| 423 | } |
| 424 | |
jvanverth | 294c326 | 2014-10-10 11:36:12 -0700 | [diff] [blame] | 425 | // TODO: support color glyphs |
| 426 | if (kA8_GrMaskFormat != glyph->fMaskFormat) { |
| 427 | return; |
| 428 | } |
| 429 | |
jvanverth | 0fedb19 | 2014-10-08 09:07:27 -0700 | [diff] [blame] | 430 | SkScalar sx = SkFixedToScalar(vx); |
| 431 | SkScalar sy = SkFixedToScalar(vy); |
| 432 | /* |
| 433 | // not valid, need to find a different solution for this |
| 434 | vx += SkIntToFixed(glyph->fBounds.fLeft); |
| 435 | vy += SkIntToFixed(glyph->fBounds.fTop); |
| 436 | |
| 437 | // keep them as ints until we've done the clip-test |
| 438 | GrFixed width = glyph->fBounds.width(); |
| 439 | GrFixed height = glyph->fBounds.height(); |
| 440 | |
| 441 | // check if we clipped out |
| 442 | if (true || NULL == glyph->fPlot) { |
| 443 | int x = vx >> 16; |
| 444 | int y = vy >> 16; |
| 445 | if (fClipRect.quickReject(x, y, x + width, y + height)) { |
| 446 | // SkCLZ(3); // so we can set a break-point in the debugger |
| 447 | return; |
| 448 | } |
| 449 | } |
| 450 | */ |
| 451 | if (NULL == glyph->fPlot) { |
| 452 | if (!fStrike->glyphTooLargeForAtlas(glyph)) { |
| 453 | if (fStrike->addGlyphToAtlas(glyph, scaler)) { |
| 454 | goto HAS_ATLAS; |
| 455 | } |
| 456 | |
| 457 | // try to clear out an unused plot before we flush |
jvanverth | 294c326 | 2014-10-10 11:36:12 -0700 | [diff] [blame] | 458 | if (fContext->getFontCache()->freeUnusedPlot(fStrike, glyph) && |
jvanverth | 0fedb19 | 2014-10-08 09:07:27 -0700 | [diff] [blame] | 459 | fStrike->addGlyphToAtlas(glyph, scaler)) { |
| 460 | goto HAS_ATLAS; |
| 461 | } |
| 462 | |
| 463 | if (c_DumpFontCache) { |
| 464 | #ifdef SK_DEVELOPER |
| 465 | fContext->getFontCache()->dump(); |
| 466 | #endif |
| 467 | } |
| 468 | |
| 469 | // before we purge the cache, we must flush any accumulated draws |
| 470 | this->flush(); |
| 471 | fContext->flush(); |
| 472 | |
| 473 | // we should have an unused plot now |
jvanverth | 294c326 | 2014-10-10 11:36:12 -0700 | [diff] [blame] | 474 | if (fContext->getFontCache()->freeUnusedPlot(fStrike, glyph) && |
jvanverth | 0fedb19 | 2014-10-08 09:07:27 -0700 | [diff] [blame] | 475 | fStrike->addGlyphToAtlas(glyph, scaler)) { |
| 476 | goto HAS_ATLAS; |
| 477 | } |
| 478 | } |
| 479 | |
| 480 | if (NULL == glyph->fPath) { |
| 481 | SkPath* path = SkNEW(SkPath); |
| 482 | if (!scaler->getGlyphPath(glyph->glyphID(), path)) { |
| 483 | // flag the glyph as being dead? |
| 484 | delete path; |
| 485 | return; |
| 486 | } |
| 487 | glyph->fPath = path; |
| 488 | } |
| 489 | |
bsalomon | ec87dc6 | 2014-10-14 10:52:00 -0700 | [diff] [blame] | 490 | // flush any accumulated draws before drawing this glyph as a path. |
| 491 | this->flush(); |
| 492 | |
jvanverth | 0fedb19 | 2014-10-08 09:07:27 -0700 | [diff] [blame] | 493 | GrContext::AutoMatrix am; |
| 494 | SkMatrix ctm; |
| 495 | ctm.setScale(fTextRatio, fTextRatio); |
| 496 | ctm.postTranslate(sx, sy); |
| 497 | GrPaint tmpPaint(fPaint); |
| 498 | am.setPreConcat(fContext, ctm, &tmpPaint); |
| 499 | GrStrokeInfo strokeInfo(SkStrokeRec::kFill_InitStyle); |
| 500 | fContext->drawPath(tmpPaint, *glyph->fPath, strokeInfo); |
| 501 | return; |
| 502 | } |
| 503 | |
| 504 | HAS_ATLAS: |
| 505 | SkASSERT(glyph->fPlot); |
| 506 | GrDrawTarget::DrawToken drawToken = fDrawTarget->getCurrentDrawToken(); |
| 507 | glyph->fPlot->setDrawToken(drawToken); |
| 508 | |
| 509 | GrTexture* texture = glyph->fPlot->texture(); |
| 510 | SkASSERT(texture); |
| 511 | |
| 512 | if (fCurrTexture != texture || fCurrVertex + 4 > fMaxVertices) { |
| 513 | this->flush(); |
| 514 | fCurrTexture = texture; |
| 515 | fCurrTexture->ref(); |
| 516 | } |
| 517 | |
| 518 | bool useColorVerts = !fUseLCDText; |
| 519 | |
| 520 | if (NULL == fVertices) { |
| 521 | // If we need to reserve vertices allow the draw target to suggest |
| 522 | // a number of verts to reserve and whether to perform a flush. |
| 523 | fMaxVertices = kMinRequestedVerts; |
| 524 | if (useColorVerts) { |
| 525 | fDrawTarget->drawState()->setVertexAttribs<gTextVertexWithColorAttribs>( |
| 526 | SK_ARRAY_COUNT(gTextVertexWithColorAttribs), kTextVAColorSize); |
| 527 | } else { |
| 528 | fDrawTarget->drawState()->setVertexAttribs<gTextVertexAttribs>( |
| 529 | SK_ARRAY_COUNT(gTextVertexAttribs), kTextVASize); |
| 530 | } |
| 531 | bool flush = fDrawTarget->geometryHints(&fMaxVertices, NULL); |
| 532 | if (flush) { |
| 533 | this->flush(); |
| 534 | fContext->flush(); |
| 535 | if (useColorVerts) { |
| 536 | fDrawTarget->drawState()->setVertexAttribs<gTextVertexWithColorAttribs>( |
| 537 | SK_ARRAY_COUNT(gTextVertexWithColorAttribs), kTextVAColorSize); |
| 538 | } else { |
| 539 | fDrawTarget->drawState()->setVertexAttribs<gTextVertexAttribs>( |
| 540 | SK_ARRAY_COUNT(gTextVertexAttribs), kTextVASize); |
| 541 | } |
| 542 | } |
| 543 | fMaxVertices = kDefaultRequestedVerts; |
| 544 | // ignore return, no point in flushing again. |
| 545 | fDrawTarget->geometryHints(&fMaxVertices, NULL); |
| 546 | |
| 547 | int maxQuadVertices = 4 * fContext->getQuadIndexBuffer()->maxQuads(); |
| 548 | if (fMaxVertices < kMinRequestedVerts) { |
| 549 | fMaxVertices = kDefaultRequestedVerts; |
| 550 | } else if (fMaxVertices > maxQuadVertices) { |
| 551 | // don't exceed the limit of the index buffer |
| 552 | fMaxVertices = maxQuadVertices; |
| 553 | } |
| 554 | bool success = fDrawTarget->reserveVertexAndIndexSpace(fMaxVertices, |
| 555 | 0, |
| 556 | &fVertices, |
| 557 | NULL); |
| 558 | GrAlwaysAssert(success); |
| 559 | } |
| 560 | |
| 561 | SkScalar dx = SkIntToScalar(glyph->fBounds.fLeft + SK_DistanceFieldInset); |
| 562 | SkScalar dy = SkIntToScalar(glyph->fBounds.fTop + SK_DistanceFieldInset); |
| 563 | SkScalar width = SkIntToScalar(glyph->fBounds.width() - 2*SK_DistanceFieldInset); |
| 564 | SkScalar height = SkIntToScalar(glyph->fBounds.height() - 2*SK_DistanceFieldInset); |
| 565 | |
| 566 | SkScalar scale = fTextRatio; |
| 567 | dx *= scale; |
| 568 | dy *= scale; |
| 569 | sx += dx; |
| 570 | sy += dy; |
| 571 | width *= scale; |
| 572 | height *= scale; |
| 573 | |
| 574 | SkFixed tx = SkIntToFixed(glyph->fAtlasLocation.fX + SK_DistanceFieldInset); |
| 575 | SkFixed ty = SkIntToFixed(glyph->fAtlasLocation.fY + SK_DistanceFieldInset); |
| 576 | SkFixed tw = SkIntToFixed(glyph->fBounds.width() - 2*SK_DistanceFieldInset); |
| 577 | SkFixed th = SkIntToFixed(glyph->fBounds.height() - 2*SK_DistanceFieldInset); |
| 578 | |
| 579 | SkRect r; |
| 580 | r.fLeft = sx; |
| 581 | r.fTop = sy; |
| 582 | r.fRight = sx + width; |
| 583 | r.fBottom = sy + height; |
| 584 | |
| 585 | fVertexBounds.joinNonEmptyArg(r); |
| 586 | |
| 587 | size_t vertSize = fUseLCDText ? (2 * sizeof(SkPoint)) |
| 588 | : (2 * sizeof(SkPoint) + sizeof(GrColor)); |
| 589 | |
| 590 | SkASSERT(vertSize == fDrawTarget->getDrawState().getVertexStride()); |
| 591 | |
| 592 | SkPoint* positions = reinterpret_cast<SkPoint*>( |
| 593 | reinterpret_cast<intptr_t>(fVertices) + vertSize * fCurrVertex); |
| 594 | positions->setRectFan(r.fLeft, r.fTop, r.fRight, r.fBottom, vertSize); |
| 595 | |
| 596 | // The texture coords are last in both the with and without color vertex layouts. |
| 597 | SkPoint* textureCoords = reinterpret_cast<SkPoint*>( |
| 598 | reinterpret_cast<intptr_t>(positions) + vertSize - sizeof(SkPoint)); |
| 599 | textureCoords->setRectFan(SkFixedToFloat(texture->texturePriv().normalizeFixedX(tx)), |
| 600 | SkFixedToFloat(texture->texturePriv().normalizeFixedY(ty)), |
| 601 | SkFixedToFloat(texture->texturePriv().normalizeFixedX(tx + tw)), |
| 602 | SkFixedToFloat(texture->texturePriv().normalizeFixedY(ty + th)), |
| 603 | vertSize); |
| 604 | if (useColorVerts) { |
| 605 | if (0xFF == GrColorUnpackA(fPaint.getColor())) { |
| 606 | fDrawTarget->drawState()->setHint(GrDrawState::kVertexColorsAreOpaque_Hint, true); |
| 607 | } |
| 608 | // color comes after position. |
| 609 | GrColor* colors = reinterpret_cast<GrColor*>(positions + 1); |
| 610 | for (int i = 0; i < 4; ++i) { |
| 611 | *colors = fPaint.getColor(); |
| 612 | colors = reinterpret_cast<GrColor*>(reinterpret_cast<intptr_t>(colors) + vertSize); |
| 613 | } |
| 614 | } |
| 615 | |
| 616 | fCurrVertex += 4; |
| 617 | } |
| 618 | |
| 619 | void GrDistanceFieldTextContext::flush() { |
| 620 | if (NULL == fDrawTarget) { |
| 621 | return; |
| 622 | } |
| 623 | |
| 624 | GrDrawState* drawState = fDrawTarget->drawState(); |
| 625 | GrDrawState::AutoRestoreEffects are(drawState); |
| 626 | |
| 627 | drawState->setFromPaint(fPaint, fContext->getMatrix(), fContext->getRenderTarget()); |
| 628 | |
| 629 | if (fCurrVertex > 0) { |
| 630 | // setup our sampler state for our text texture/atlas |
| 631 | SkASSERT(SkIsAlign4(fCurrVertex)); |
| 632 | |
| 633 | // get our current color |
| 634 | SkColor filteredColor; |
| 635 | SkColorFilter* colorFilter = fSkPaint.getColorFilter(); |
| 636 | if (colorFilter) { |
| 637 | filteredColor = colorFilter->filterColor(fSkPaint.getColor()); |
| 638 | } else { |
| 639 | filteredColor = fSkPaint.getColor(); |
| 640 | } |
| 641 | this->setupCoverageEffect(filteredColor); |
| 642 | |
| 643 | // Effects could be stored with one of the cache objects (atlas?) |
| 644 | drawState->setGeometryProcessor(fCachedGeometryProcessor.get()); |
| 645 | |
| 646 | // Set draw state |
| 647 | if (fUseLCDText) { |
| 648 | GrColor colorNoPreMul = skcolor_to_grcolor_nopremultiply(filteredColor); |
| 649 | if (kOne_GrBlendCoeff != fPaint.getSrcBlendCoeff() || |
| 650 | kISA_GrBlendCoeff != fPaint.getDstBlendCoeff() || |
| 651 | fPaint.numColorStages()) { |
| 652 | GrPrintf("LCD Text will not draw correctly.\n"); |
| 653 | } |
| 654 | SkASSERT(!drawState->hasColorVertexAttribute()); |
| 655 | // We don't use the GrPaint's color in this case because it's been premultiplied by |
| 656 | // alpha. Instead we feed in a non-premultiplied color, and multiply its alpha by |
| 657 | // the mask texture color. The end result is that we get |
| 658 | // mask*paintAlpha*paintColor + (1-mask*paintAlpha)*dstColor |
| 659 | int a = SkColorGetA(fSkPaint.getColor()); |
| 660 | // paintAlpha |
| 661 | drawState->setColor(SkColorSetARGB(a, a, a, a)); |
| 662 | // paintColor |
| 663 | drawState->setBlendConstant(colorNoPreMul); |
| 664 | drawState->setBlendFunc(kConstC_GrBlendCoeff, kISC_GrBlendCoeff); |
| 665 | } else { |
| 666 | // set back to normal in case we took LCD path previously. |
| 667 | drawState->setBlendFunc(fPaint.getSrcBlendCoeff(), fPaint.getDstBlendCoeff()); |
| 668 | // We're using per-vertex color. |
| 669 | SkASSERT(drawState->hasColorVertexAttribute()); |
| 670 | } |
| 671 | int nGlyphs = fCurrVertex / 4; |
| 672 | fDrawTarget->setIndexSourceToBuffer(fContext->getQuadIndexBuffer()); |
| 673 | fDrawTarget->drawIndexedInstances(kTriangles_GrPrimitiveType, |
| 674 | nGlyphs, |
| 675 | 4, 6, &fVertexBounds); |
| 676 | fDrawTarget->resetVertexSource(); |
| 677 | fVertices = NULL; |
| 678 | fMaxVertices = 0; |
| 679 | fCurrVertex = 0; |
| 680 | SkSafeSetNull(fCurrTexture); |
| 681 | fVertexBounds.setLargestInverted(); |
| 682 | } |
| 683 | } |
| 684 | |
| 685 | inline void GrDistanceFieldTextContext::finish() { |
| 686 | this->flush(); |
| 687 | |
| 688 | GrTextContext::finish(); |
| 689 | } |
| 690 | |