jvanverth@google.com | c7a40fa | 2013-10-16 18:15:34 +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 "GrBitmapTextContext.h" |
| 9 | #include "GrAtlas.h" |
joshualitt | 5478d42 | 2014-11-14 16:00:38 -0800 | [diff] [blame] | 10 | #include "GrDefaultGeoProcFactory.h" |
jvanverth@google.com | c7a40fa | 2013-10-16 18:15:34 +0000 | [diff] [blame] | 11 | #include "GrDrawTarget.h" |
jvanverth | 787cdf9 | 2014-12-04 10:46:50 -0800 | [diff] [blame] | 12 | #include "GrFontCache.h" |
jvanverth@google.com | c7a40fa | 2013-10-16 18:15:34 +0000 | [diff] [blame] | 13 | #include "GrFontScaler.h" |
| 14 | #include "GrIndexBuffer.h" |
egdaniel | d58a0ba | 2014-06-11 10:30:05 -0700 | [diff] [blame] | 15 | #include "GrStrokeInfo.h" |
bsalomon | afbf2d6 | 2014-09-30 12:18:44 -0700 | [diff] [blame] | 16 | #include "GrTexturePriv.h" |
jvanverth@google.com | c7a40fa | 2013-10-16 18:15:34 +0000 | [diff] [blame] | 17 | |
jvanverth | aab626c | 2014-10-16 08:04:39 -0700 | [diff] [blame] | 18 | #include "SkAutoKern.h" |
bsalomon | afbf2d6 | 2014-09-30 12:18:44 -0700 | [diff] [blame] | 19 | #include "SkColorPriv.h" |
commit-bot@chromium.org | 9f94b91 | 2014-01-30 15:22:54 +0000 | [diff] [blame] | 20 | #include "SkDraw.h" |
kkinnunen | cb9a2c8 | 2014-06-12 23:06:28 -0700 | [diff] [blame] | 21 | #include "SkDrawProcs.h" |
commit-bot@chromium.org | e8612d9 | 2014-01-28 22:02:07 +0000 | [diff] [blame] | 22 | #include "SkGlyphCache.h" |
| 23 | #include "SkGpuDevice.h" |
| 24 | #include "SkGr.h" |
bsalomon | afbf2d6 | 2014-09-30 12:18:44 -0700 | [diff] [blame] | 25 | #include "SkPath.h" |
| 26 | #include "SkRTConf.h" |
| 27 | #include "SkStrokeRec.h" |
kkinnunen | cb9a2c8 | 2014-06-12 23:06:28 -0700 | [diff] [blame] | 28 | #include "SkTextMapStateProc.h" |
commit-bot@chromium.org | e8612d9 | 2014-01-28 22:02:07 +0000 | [diff] [blame] | 29 | |
egdaniel | 309e346 | 2014-12-09 10:35:58 -0800 | [diff] [blame] | 30 | #include "effects/GrBitmapTextGeoProc.h" |
joshualitt | 5478d42 | 2014-11-14 16:00:38 -0800 | [diff] [blame] | 31 | #include "effects/GrSimpleTextureEffect.h" |
| 32 | |
jvanverth@google.com | c7a40fa | 2013-10-16 18:15:34 +0000 | [diff] [blame] | 33 | SK_CONF_DECLARE(bool, c_DumpFontCache, "gpu.dumpFontCache", false, |
| 34 | "Dump the contents of the font cache before every purge."); |
| 35 | |
bsalomon | 594069f | 2014-06-06 06:16:34 -0700 | [diff] [blame] | 36 | namespace { |
egdaniel | ed3af66 | 2014-10-31 06:55:45 -0700 | [diff] [blame] | 37 | static const size_t kLCDTextVASize = 2 * sizeof(SkPoint); |
| 38 | |
| 39 | // position + local coord |
egdaniel | ed3af66 | 2014-10-31 06:55:45 -0700 | [diff] [blame] | 40 | static const size_t kColorTextVASize = 2 * sizeof(SkPoint); |
egdaniel | 7b3d5ee | 2014-08-28 05:41:14 -0700 | [diff] [blame] | 41 | |
egdaniel | ed3af66 | 2014-10-31 06:55:45 -0700 | [diff] [blame] | 42 | static const size_t kGrayTextVASize = 2 * sizeof(SkPoint) + sizeof(GrColor); |
egdaniel | 7b3d5ee | 2014-08-28 05:41:14 -0700 | [diff] [blame] | 43 | |
jvanverth | 73f1053 | 2014-10-23 11:57:12 -0700 | [diff] [blame] | 44 | static const int kVerticesPerGlyph = 4; |
| 45 | static const int kIndicesPerGlyph = 6; |
bsalomon | 594069f | 2014-06-06 06:16:34 -0700 | [diff] [blame] | 46 | }; |
| 47 | |
skia.committer@gmail.com | e5d7015 | 2014-01-29 07:01:48 +0000 | [diff] [blame] | 48 | GrBitmapTextContext::GrBitmapTextContext(GrContext* context, |
commit-bot@chromium.org | e8612d9 | 2014-01-28 22:02:07 +0000 | [diff] [blame] | 49 | const SkDeviceProperties& properties) |
Mike Klein | 6a25bd0 | 2014-08-29 10:03:59 -0400 | [diff] [blame] | 50 | : GrTextContext(context, properties) { |
| 51 | fStrike = NULL; |
| 52 | |
| 53 | fCurrTexture = NULL; |
Mike Klein | 6a25bd0 | 2014-08-29 10:03:59 -0400 | [diff] [blame] | 54 | fEffectTextureUniqueID = SK_InvalidUniqueID; |
| 55 | |
| 56 | fVertices = NULL; |
jvanverth | 73f1053 | 2014-10-23 11:57:12 -0700 | [diff] [blame] | 57 | fCurrVertex = 0; |
| 58 | fAllocVertexCount = 0; |
| 59 | fTotalVertexCount = 0; |
Mike Klein | 6a25bd0 | 2014-08-29 10:03:59 -0400 | [diff] [blame] | 60 | |
commit-bot@chromium.org | 3ae0e6c | 2014-02-11 18:24:25 +0000 | [diff] [blame] | 61 | fVertexBounds.setLargestInverted(); |
jvanverth@google.com | c7a40fa | 2013-10-16 18:15:34 +0000 | [diff] [blame] | 62 | } |
| 63 | |
jvanverth | 8c27a18 | 2014-10-14 08:45:50 -0700 | [diff] [blame] | 64 | GrBitmapTextContext* GrBitmapTextContext::Create(GrContext* context, |
| 65 | const SkDeviceProperties& props) { |
| 66 | return SkNEW_ARGS(GrBitmapTextContext, (context, props)); |
| 67 | } |
| 68 | |
joshualitt | 5531d51 | 2014-12-17 15:50:11 -0800 | [diff] [blame] | 69 | bool GrBitmapTextContext::canDraw(const SkPaint& paint, const SkMatrix& viewMatrix) { |
| 70 | return !SkDraw::ShouldDrawTextAsPaths(paint, viewMatrix); |
commit-bot@chromium.org | cbbc481 | 2014-01-30 22:05:47 +0000 | [diff] [blame] | 71 | } |
| 72 | |
commit-bot@chromium.org | cbbc481 | 2014-01-30 22:05:47 +0000 | [diff] [blame] | 73 | inline void GrBitmapTextContext::init(const GrPaint& paint, const SkPaint& skPaint) { |
| 74 | GrTextContext::init(paint, skPaint); |
| 75 | |
| 76 | fStrike = NULL; |
| 77 | |
Mike Klein | 6a25bd0 | 2014-08-29 10:03:59 -0400 | [diff] [blame] | 78 | fCurrTexture = NULL; |
jvanverth | 63b9dc8 | 2014-08-28 10:39:40 -0700 | [diff] [blame] | 79 | fCurrVertex = 0; |
Mike Klein | 6a25bd0 | 2014-08-29 10:03:59 -0400 | [diff] [blame] | 80 | |
| 81 | fVertices = NULL; |
jvanverth | 73f1053 | 2014-10-23 11:57:12 -0700 | [diff] [blame] | 82 | fAllocVertexCount = 0; |
| 83 | fTotalVertexCount = 0; |
commit-bot@chromium.org | cbbc481 | 2014-01-30 22:05:47 +0000 | [diff] [blame] | 84 | } |
| 85 | |
jvanverth | aab626c | 2014-10-16 08:04:39 -0700 | [diff] [blame] | 86 | void GrBitmapTextContext::onDrawText(const GrPaint& paint, const SkPaint& skPaint, |
joshualitt | 5531d51 | 2014-12-17 15:50:11 -0800 | [diff] [blame] | 87 | const SkMatrix& viewMatrix, |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 88 | const char text[], size_t byteLength, |
| 89 | SkScalar x, SkScalar y) { |
jvanverth | aab626c | 2014-10-16 08:04:39 -0700 | [diff] [blame] | 90 | SkASSERT(byteLength == 0 || text != NULL); |
| 91 | |
| 92 | // nothing to draw |
| 93 | if (text == NULL || byteLength == 0 /*|| fRC->isEmpty()*/) { |
| 94 | return; |
| 95 | } |
| 96 | |
| 97 | this->init(paint, skPaint); |
| 98 | |
| 99 | SkDrawCacheProc glyphCacheProc = fSkPaint.getDrawCacheProc(); |
| 100 | |
joshualitt | 5531d51 | 2014-12-17 15:50:11 -0800 | [diff] [blame] | 101 | SkAutoGlyphCache autoCache(fSkPaint, &fDeviceProperties, &viewMatrix); |
jvanverth | aab626c | 2014-10-16 08:04:39 -0700 | [diff] [blame] | 102 | SkGlyphCache* cache = autoCache.getCache(); |
| 103 | GrFontScaler* fontScaler = GetGrFontScaler(cache); |
| 104 | |
| 105 | // transform our starting point |
| 106 | { |
| 107 | SkPoint loc; |
joshualitt | 5531d51 | 2014-12-17 15:50:11 -0800 | [diff] [blame] | 108 | viewMatrix.mapXY(x, y, &loc); |
jvanverth | aab626c | 2014-10-16 08:04:39 -0700 | [diff] [blame] | 109 | x = loc.fX; |
| 110 | y = loc.fY; |
| 111 | } |
| 112 | |
| 113 | // need to measure first |
jvanverth | 73f1053 | 2014-10-23 11:57:12 -0700 | [diff] [blame] | 114 | int numGlyphs; |
jvanverth | aab626c | 2014-10-16 08:04:39 -0700 | [diff] [blame] | 115 | if (fSkPaint.getTextAlign() != SkPaint::kLeft_Align) { |
jvanverth | 73f1053 | 2014-10-23 11:57:12 -0700 | [diff] [blame] | 116 | SkVector stopVector; |
| 117 | numGlyphs = MeasureText(cache, glyphCacheProc, text, byteLength, &stopVector); |
jvanverth | aab626c | 2014-10-16 08:04:39 -0700 | [diff] [blame] | 118 | |
jvanverth | 73f1053 | 2014-10-23 11:57:12 -0700 | [diff] [blame] | 119 | SkScalar stopX = stopVector.fX; |
| 120 | SkScalar stopY = stopVector.fY; |
jvanverth | aab626c | 2014-10-16 08:04:39 -0700 | [diff] [blame] | 121 | |
| 122 | if (fSkPaint.getTextAlign() == SkPaint::kCenter_Align) { |
| 123 | stopX = SkScalarHalf(stopX); |
| 124 | stopY = SkScalarHalf(stopY); |
| 125 | } |
| 126 | x -= stopX; |
| 127 | y -= stopY; |
jvanverth | 73f1053 | 2014-10-23 11:57:12 -0700 | [diff] [blame] | 128 | } else { |
| 129 | numGlyphs = fSkPaint.textToGlyphs(text, byteLength, NULL); |
jvanverth | aab626c | 2014-10-16 08:04:39 -0700 | [diff] [blame] | 130 | } |
jvanverth | 73f1053 | 2014-10-23 11:57:12 -0700 | [diff] [blame] | 131 | fTotalVertexCount = kVerticesPerGlyph*numGlyphs; |
jvanverth | aab626c | 2014-10-16 08:04:39 -0700 | [diff] [blame] | 132 | |
| 133 | const char* stop = text + byteLength; |
| 134 | |
| 135 | SkAutoKern autokern; |
| 136 | |
| 137 | SkFixed fxMask = ~0; |
| 138 | SkFixed fyMask = ~0; |
| 139 | SkFixed halfSampleX, halfSampleY; |
| 140 | if (cache->isSubpixel()) { |
| 141 | halfSampleX = halfSampleY = (SK_FixedHalf >> SkGlyph::kSubBits); |
joshualitt | 5531d51 | 2014-12-17 15:50:11 -0800 | [diff] [blame] | 142 | SkAxisAlignment baseline = SkComputeAxisAlignmentForHText(viewMatrix); |
jvanverth | aab626c | 2014-10-16 08:04:39 -0700 | [diff] [blame] | 143 | if (kX_SkAxisAlignment == baseline) { |
| 144 | fyMask = 0; |
| 145 | halfSampleY = SK_FixedHalf; |
| 146 | } else if (kY_SkAxisAlignment == baseline) { |
| 147 | fxMask = 0; |
| 148 | halfSampleX = SK_FixedHalf; |
| 149 | } |
| 150 | } else { |
| 151 | halfSampleX = halfSampleY = SK_FixedHalf; |
| 152 | } |
| 153 | |
| 154 | SkFixed fx = SkScalarToFixed(x) + halfSampleX; |
| 155 | SkFixed fy = SkScalarToFixed(y) + halfSampleY; |
| 156 | |
joshualitt | 73483d9 | 2014-12-23 07:58:02 -0800 | [diff] [blame^] | 157 | // if we have RGB, then we won't have any SkShaders so no need to use a localmatrix, but for |
| 158 | // performance reasons we just invert here instead |
| 159 | if (!viewMatrix.invert(&fLocalMatrix)) { |
| 160 | SkDebugf("Cannot invert viewmatrix\n"); |
joshualitt | 5531d51 | 2014-12-17 15:50:11 -0800 | [diff] [blame] | 161 | } |
jvanverth | aab626c | 2014-10-16 08:04:39 -0700 | [diff] [blame] | 162 | |
| 163 | while (text < stop) { |
| 164 | const SkGlyph& glyph = glyphCacheProc(cache, &text, fx & fxMask, fy & fyMask); |
| 165 | |
| 166 | fx += autokern.adjust(glyph); |
| 167 | |
| 168 | if (glyph.fWidth) { |
| 169 | this->appendGlyph(GrGlyph::Pack(glyph.getGlyphID(), |
| 170 | glyph.getSubXFixed(), |
| 171 | glyph.getSubYFixed()), |
| 172 | SkFixedFloorToFixed(fx), |
| 173 | SkFixedFloorToFixed(fy), |
| 174 | fontScaler); |
| 175 | } |
| 176 | |
| 177 | fx += glyph.fAdvanceX; |
| 178 | fy += glyph.fAdvanceY; |
| 179 | } |
| 180 | |
| 181 | this->finish(); |
| 182 | } |
| 183 | |
jvanverth | 8c27a18 | 2014-10-14 08:45:50 -0700 | [diff] [blame] | 184 | void GrBitmapTextContext::onDrawPosText(const GrPaint& paint, const SkPaint& skPaint, |
joshualitt | 5531d51 | 2014-12-17 15:50:11 -0800 | [diff] [blame] | 185 | const SkMatrix& viewMatrix, |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 186 | const char text[], size_t byteLength, |
| 187 | const SkScalar pos[], int scalarsPerPosition, |
| 188 | const SkPoint& offset) { |
commit-bot@chromium.org | e8612d9 | 2014-01-28 22:02:07 +0000 | [diff] [blame] | 189 | SkASSERT(byteLength == 0 || text != NULL); |
| 190 | SkASSERT(1 == scalarsPerPosition || 2 == scalarsPerPosition); |
| 191 | |
| 192 | // nothing to draw |
| 193 | if (text == NULL || byteLength == 0/* || fRC->isEmpty()*/) { |
| 194 | return; |
| 195 | } |
| 196 | |
commit-bot@chromium.org | cbbc481 | 2014-01-30 22:05:47 +0000 | [diff] [blame] | 197 | this->init(paint, skPaint); |
| 198 | |
commit-bot@chromium.org | e8612d9 | 2014-01-28 22:02:07 +0000 | [diff] [blame] | 199 | SkDrawCacheProc glyphCacheProc = fSkPaint.getDrawCacheProc(); |
| 200 | |
joshualitt | 5531d51 | 2014-12-17 15:50:11 -0800 | [diff] [blame] | 201 | SkAutoGlyphCache autoCache(fSkPaint, &fDeviceProperties, &viewMatrix); |
commit-bot@chromium.org | e8612d9 | 2014-01-28 22:02:07 +0000 | [diff] [blame] | 202 | SkGlyphCache* cache = autoCache.getCache(); |
| 203 | GrFontScaler* fontScaler = GetGrFontScaler(cache); |
| 204 | |
joshualitt | 73483d9 | 2014-12-23 07:58:02 -0800 | [diff] [blame^] | 205 | // if we have RGB, then we won't have any SkShaders so no need to use a localmatrix, but for |
| 206 | // performance reasons we just invert here instead |
| 207 | if (!viewMatrix.invert(&fLocalMatrix)) { |
joshualitt | 5531d51 | 2014-12-17 15:50:11 -0800 | [diff] [blame] | 208 | SkDebugf("Cannot invert viewmatrix\n"); |
| 209 | } |
commit-bot@chromium.org | e8612d9 | 2014-01-28 22:02:07 +0000 | [diff] [blame] | 210 | |
jvanverth | 73f1053 | 2014-10-23 11:57:12 -0700 | [diff] [blame] | 211 | int numGlyphs = fSkPaint.textToGlyphs(text, byteLength, NULL); |
| 212 | fTotalVertexCount = kVerticesPerGlyph*numGlyphs; |
| 213 | |
commit-bot@chromium.org | e8612d9 | 2014-01-28 22:02:07 +0000 | [diff] [blame] | 214 | const char* stop = text + byteLength; |
kkinnunen | cb9a2c8 | 2014-06-12 23:06:28 -0700 | [diff] [blame] | 215 | SkTextAlignProc alignProc(fSkPaint.getTextAlign()); |
joshualitt | 73483d9 | 2014-12-23 07:58:02 -0800 | [diff] [blame^] | 216 | SkTextMapStateProc tmsProc(viewMatrix, offset, scalarsPerPosition); |
commit-bot@chromium.org | e8612d9 | 2014-01-28 22:02:07 +0000 | [diff] [blame] | 217 | SkFixed halfSampleX = 0, halfSampleY = 0; |
| 218 | |
| 219 | if (cache->isSubpixel()) { |
| 220 | // maybe we should skip the rounding if linearText is set |
joshualitt | 73483d9 | 2014-12-23 07:58:02 -0800 | [diff] [blame^] | 221 | SkAxisAlignment baseline = SkComputeAxisAlignmentForHText(viewMatrix); |
commit-bot@chromium.org | e8612d9 | 2014-01-28 22:02:07 +0000 | [diff] [blame] | 222 | |
| 223 | SkFixed fxMask = ~0; |
| 224 | SkFixed fyMask = ~0; |
| 225 | if (kX_SkAxisAlignment == baseline) { |
| 226 | fyMask = 0; |
commit-bot@chromium.org | e8612d9 | 2014-01-28 22:02:07 +0000 | [diff] [blame] | 227 | halfSampleY = SK_FixedHalf; |
commit-bot@chromium.org | e8612d9 | 2014-01-28 22:02:07 +0000 | [diff] [blame] | 228 | } else if (kY_SkAxisAlignment == baseline) { |
| 229 | fxMask = 0; |
commit-bot@chromium.org | e8612d9 | 2014-01-28 22:02:07 +0000 | [diff] [blame] | 230 | halfSampleX = SK_FixedHalf; |
commit-bot@chromium.org | e8612d9 | 2014-01-28 22:02:07 +0000 | [diff] [blame] | 231 | } |
| 232 | |
| 233 | if (SkPaint::kLeft_Align == fSkPaint.getTextAlign()) { |
| 234 | while (text < stop) { |
kkinnunen | cb9a2c8 | 2014-06-12 23:06:28 -0700 | [diff] [blame] | 235 | SkPoint tmsLoc; |
| 236 | tmsProc(pos, &tmsLoc); |
| 237 | SkFixed fx = SkScalarToFixed(tmsLoc.fX) + halfSampleX; |
| 238 | SkFixed fy = SkScalarToFixed(tmsLoc.fY) + halfSampleY; |
commit-bot@chromium.org | e8612d9 | 2014-01-28 22:02:07 +0000 | [diff] [blame] | 239 | |
| 240 | const SkGlyph& glyph = glyphCacheProc(cache, &text, |
| 241 | fx & fxMask, fy & fyMask); |
| 242 | |
| 243 | if (glyph.fWidth) { |
jvanverth | 0fedb19 | 2014-10-08 09:07:27 -0700 | [diff] [blame] | 244 | this->appendGlyph(GrGlyph::Pack(glyph.getGlyphID(), |
| 245 | glyph.getSubXFixed(), |
| 246 | glyph.getSubYFixed()), |
| 247 | SkFixedFloorToFixed(fx), |
| 248 | SkFixedFloorToFixed(fy), |
| 249 | fontScaler); |
commit-bot@chromium.org | e8612d9 | 2014-01-28 22:02:07 +0000 | [diff] [blame] | 250 | } |
| 251 | pos += scalarsPerPosition; |
| 252 | } |
| 253 | } else { |
| 254 | while (text < stop) { |
| 255 | const char* currentText = text; |
| 256 | const SkGlyph& metricGlyph = glyphCacheProc(cache, &text, 0, 0); |
| 257 | |
| 258 | if (metricGlyph.fWidth) { |
| 259 | SkDEBUGCODE(SkFixed prevAdvX = metricGlyph.fAdvanceX;) |
| 260 | SkDEBUGCODE(SkFixed prevAdvY = metricGlyph.fAdvanceY;) |
kkinnunen | cb9a2c8 | 2014-06-12 23:06:28 -0700 | [diff] [blame] | 261 | SkPoint tmsLoc; |
| 262 | tmsProc(pos, &tmsLoc); |
commit-bot@chromium.org | e8612d9 | 2014-01-28 22:02:07 +0000 | [diff] [blame] | 263 | SkIPoint fixedLoc; |
kkinnunen | cb9a2c8 | 2014-06-12 23:06:28 -0700 | [diff] [blame] | 264 | alignProc(tmsLoc, metricGlyph, &fixedLoc); |
commit-bot@chromium.org | e8612d9 | 2014-01-28 22:02:07 +0000 | [diff] [blame] | 265 | |
| 266 | SkFixed fx = fixedLoc.fX + halfSampleX; |
| 267 | SkFixed fy = fixedLoc.fY + halfSampleY; |
| 268 | |
| 269 | // have to call again, now that we've been "aligned" |
| 270 | const SkGlyph& glyph = glyphCacheProc(cache, ¤tText, |
| 271 | fx & fxMask, fy & fyMask); |
| 272 | // the assumption is that the metrics haven't changed |
| 273 | SkASSERT(prevAdvX == glyph.fAdvanceX); |
| 274 | SkASSERT(prevAdvY == glyph.fAdvanceY); |
| 275 | SkASSERT(glyph.fWidth); |
| 276 | |
jvanverth | 0fedb19 | 2014-10-08 09:07:27 -0700 | [diff] [blame] | 277 | this->appendGlyph(GrGlyph::Pack(glyph.getGlyphID(), |
| 278 | glyph.getSubXFixed(), |
| 279 | glyph.getSubYFixed()), |
| 280 | SkFixedFloorToFixed(fx), |
| 281 | SkFixedFloorToFixed(fy), |
| 282 | fontScaler); |
commit-bot@chromium.org | e8612d9 | 2014-01-28 22:02:07 +0000 | [diff] [blame] | 283 | } |
| 284 | pos += scalarsPerPosition; |
| 285 | } |
| 286 | } |
| 287 | } else { // not subpixel |
| 288 | |
| 289 | if (SkPaint::kLeft_Align == fSkPaint.getTextAlign()) { |
| 290 | while (text < stop) { |
| 291 | // the last 2 parameters are ignored |
| 292 | const SkGlyph& glyph = glyphCacheProc(cache, &text, 0, 0); |
| 293 | |
| 294 | if (glyph.fWidth) { |
kkinnunen | cb9a2c8 | 2014-06-12 23:06:28 -0700 | [diff] [blame] | 295 | SkPoint tmsLoc; |
| 296 | tmsProc(pos, &tmsLoc); |
commit-bot@chromium.org | e8612d9 | 2014-01-28 22:02:07 +0000 | [diff] [blame] | 297 | |
kkinnunen | cb9a2c8 | 2014-06-12 23:06:28 -0700 | [diff] [blame] | 298 | SkFixed fx = SkScalarToFixed(tmsLoc.fX) + SK_FixedHalf; //halfSampleX; |
| 299 | SkFixed fy = SkScalarToFixed(tmsLoc.fY) + SK_FixedHalf; //halfSampleY; |
jvanverth | 0fedb19 | 2014-10-08 09:07:27 -0700 | [diff] [blame] | 300 | this->appendGlyph(GrGlyph::Pack(glyph.getGlyphID(), |
| 301 | glyph.getSubXFixed(), |
| 302 | glyph.getSubYFixed()), |
| 303 | SkFixedFloorToFixed(fx), |
| 304 | SkFixedFloorToFixed(fy), |
| 305 | fontScaler); |
commit-bot@chromium.org | e8612d9 | 2014-01-28 22:02:07 +0000 | [diff] [blame] | 306 | } |
| 307 | pos += scalarsPerPosition; |
| 308 | } |
| 309 | } else { |
| 310 | while (text < stop) { |
| 311 | // the last 2 parameters are ignored |
| 312 | const SkGlyph& glyph = glyphCacheProc(cache, &text, 0, 0); |
| 313 | |
| 314 | if (glyph.fWidth) { |
kkinnunen | cb9a2c8 | 2014-06-12 23:06:28 -0700 | [diff] [blame] | 315 | SkPoint tmsLoc; |
| 316 | tmsProc(pos, &tmsLoc); |
commit-bot@chromium.org | e8612d9 | 2014-01-28 22:02:07 +0000 | [diff] [blame] | 317 | |
| 318 | SkIPoint fixedLoc; |
kkinnunen | cb9a2c8 | 2014-06-12 23:06:28 -0700 | [diff] [blame] | 319 | alignProc(tmsLoc, glyph, &fixedLoc); |
commit-bot@chromium.org | e8612d9 | 2014-01-28 22:02:07 +0000 | [diff] [blame] | 320 | |
| 321 | SkFixed fx = fixedLoc.fX + SK_FixedHalf; //halfSampleX; |
| 322 | SkFixed fy = fixedLoc.fY + SK_FixedHalf; //halfSampleY; |
jvanverth | 0fedb19 | 2014-10-08 09:07:27 -0700 | [diff] [blame] | 323 | this->appendGlyph(GrGlyph::Pack(glyph.getGlyphID(), |
| 324 | glyph.getSubXFixed(), |
| 325 | glyph.getSubYFixed()), |
| 326 | SkFixedFloorToFixed(fx), |
| 327 | SkFixedFloorToFixed(fy), |
| 328 | fontScaler); |
commit-bot@chromium.org | e8612d9 | 2014-01-28 22:02:07 +0000 | [diff] [blame] | 329 | } |
| 330 | pos += scalarsPerPosition; |
| 331 | } |
| 332 | } |
| 333 | } |
commit-bot@chromium.org | cbbc481 | 2014-01-30 22:05:47 +0000 | [diff] [blame] | 334 | |
| 335 | this->finish(); |
commit-bot@chromium.org | e8612d9 | 2014-01-28 22:02:07 +0000 | [diff] [blame] | 336 | } |
| 337 | |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 338 | static size_t get_vertex_stride(GrMaskFormat maskFormat) { |
| 339 | switch (maskFormat) { |
| 340 | case kA8_GrMaskFormat: |
| 341 | return kGrayTextVASize; |
| 342 | case kARGB_GrMaskFormat: |
| 343 | return kColorTextVASize; |
| 344 | default: |
| 345 | return kLCDTextVASize; |
| 346 | } |
| 347 | } |
| 348 | |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 349 | static void* alloc_vertices(GrDrawTarget* drawTarget, |
| 350 | int numVertices, |
| 351 | GrMaskFormat maskFormat) { |
jvanverth | 73f1053 | 2014-10-23 11:57:12 -0700 | [diff] [blame] | 352 | if (numVertices <= 0) { |
| 353 | return NULL; |
| 354 | } |
| 355 | |
| 356 | // set up attributes |
jvanverth | 73f1053 | 2014-10-23 11:57:12 -0700 | [diff] [blame] | 357 | void* vertices = NULL; |
| 358 | bool success = drawTarget->reserveVertexAndIndexSpace(numVertices, |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 359 | get_vertex_stride(maskFormat), |
jvanverth | 73f1053 | 2014-10-23 11:57:12 -0700 | [diff] [blame] | 360 | 0, |
| 361 | &vertices, |
| 362 | NULL); |
| 363 | GrAlwaysAssert(success); |
| 364 | return vertices; |
| 365 | } |
| 366 | |
jvanverth | 787cdf9 | 2014-12-04 10:46:50 -0800 | [diff] [blame] | 367 | inline bool GrBitmapTextContext::uploadGlyph(GrGlyph* glyph, GrFontScaler* scaler) { |
| 368 | if (!fStrike->glyphTooLargeForAtlas(glyph)) { |
| 369 | if (fStrike->addGlyphToAtlas(glyph, scaler)) { |
| 370 | return true; |
| 371 | } |
| 372 | |
| 373 | // try to clear out an unused plot before we flush |
| 374 | if (fContext->getFontCache()->freeUnusedPlot(fStrike, glyph) && |
| 375 | fStrike->addGlyphToAtlas(glyph, scaler)) { |
| 376 | return true; |
| 377 | } |
| 378 | |
| 379 | if (c_DumpFontCache) { |
| 380 | #ifdef SK_DEVELOPER |
| 381 | fContext->getFontCache()->dump(); |
| 382 | #endif |
| 383 | } |
| 384 | |
| 385 | // before we purge the cache, we must flush any accumulated draws |
| 386 | this->flush(); |
| 387 | fContext->flush(); |
| 388 | |
| 389 | // we should have an unused plot now |
| 390 | if (fContext->getFontCache()->freeUnusedPlot(fStrike, glyph) && |
| 391 | fStrike->addGlyphToAtlas(glyph, scaler)) { |
| 392 | return true; |
| 393 | } |
| 394 | |
| 395 | // we should never get here |
| 396 | SkASSERT(false); |
| 397 | } |
| 398 | |
| 399 | return false; |
| 400 | } |
| 401 | |
jvanverth | 0fedb19 | 2014-10-08 09:07:27 -0700 | [diff] [blame] | 402 | void GrBitmapTextContext::appendGlyph(GrGlyph::PackedID packed, |
| 403 | SkFixed vx, SkFixed vy, |
| 404 | GrFontScaler* scaler) { |
Mike Klein | 6a25bd0 | 2014-08-29 10:03:59 -0400 | [diff] [blame] | 405 | if (NULL == fDrawTarget) { |
| 406 | return; |
| 407 | } |
| 408 | |
| 409 | if (NULL == fStrike) { |
| 410 | fStrike = fContext->getFontCache()->getStrike(scaler, false); |
| 411 | } |
| 412 | |
jvanverth@google.com | c7a40fa | 2013-10-16 18:15:34 +0000 | [diff] [blame] | 413 | GrGlyph* glyph = fStrike->getGlyph(packed, scaler); |
| 414 | if (NULL == glyph || glyph->fBounds.isEmpty()) { |
| 415 | return; |
| 416 | } |
| 417 | |
| 418 | vx += SkIntToFixed(glyph->fBounds.fLeft); |
| 419 | vy += SkIntToFixed(glyph->fBounds.fTop); |
| 420 | |
| 421 | // keep them as ints until we've done the clip-test |
commit-bot@chromium.org | 972f9cd | 2014-03-28 17:58:28 +0000 | [diff] [blame] | 422 | SkFixed width = glyph->fBounds.width(); |
| 423 | SkFixed height = glyph->fBounds.height(); |
jvanverth@google.com | c7a40fa | 2013-10-16 18:15:34 +0000 | [diff] [blame] | 424 | |
| 425 | // check if we clipped out |
| 426 | if (true || NULL == glyph->fPlot) { |
| 427 | int x = vx >> 16; |
| 428 | int y = vy >> 16; |
| 429 | if (fClipRect.quickReject(x, y, x + width, y + height)) { |
| 430 | // SkCLZ(3); // so we can set a break-point in the debugger |
| 431 | return; |
| 432 | } |
| 433 | } |
| 434 | |
joshualitt | c262582 | 2014-12-18 16:40:54 -0800 | [diff] [blame] | 435 | // If the glyph is too large we fall back to paths |
jvanverth | 787cdf9 | 2014-12-04 10:46:50 -0800 | [diff] [blame] | 436 | if (NULL == glyph->fPlot && !uploadGlyph(glyph, scaler)) { |
jvanverth@google.com | c7a40fa | 2013-10-16 18:15:34 +0000 | [diff] [blame] | 437 | if (NULL == glyph->fPath) { |
| 438 | SkPath* path = SkNEW(SkPath); |
| 439 | if (!scaler->getGlyphPath(glyph->glyphID(), path)) { |
| 440 | // flag the glyph as being dead? |
| 441 | delete path; |
| 442 | return; |
| 443 | } |
| 444 | glyph->fPath = path; |
| 445 | } |
| 446 | |
bsalomon | ec87dc6 | 2014-10-14 10:52:00 -0700 | [diff] [blame] | 447 | // flush any accumulated draws before drawing this glyph as a path. |
| 448 | this->flush(); |
| 449 | |
jvanverth@google.com | c7a40fa | 2013-10-16 18:15:34 +0000 | [diff] [blame] | 450 | SkMatrix translate; |
| 451 | translate.setTranslate(SkFixedToScalar(vx - SkIntToFixed(glyph->fBounds.fLeft)), |
| 452 | SkFixedToScalar(vy - SkIntToFixed(glyph->fBounds.fTop))); |
joshualitt | c262582 | 2014-12-18 16:40:54 -0800 | [diff] [blame] | 453 | SkPath tmpPath(*glyph->fPath); |
| 454 | tmpPath.transform(translate); |
egdaniel | d58a0ba | 2014-06-11 10:30:05 -0700 | [diff] [blame] | 455 | GrStrokeInfo strokeInfo(SkStrokeRec::kFill_InitStyle); |
joshualitt | c262582 | 2014-12-18 16:40:54 -0800 | [diff] [blame] | 456 | fContext->drawPath(fPaint, SkMatrix::I(), tmpPath, strokeInfo); |
jvanverth | 73f1053 | 2014-10-23 11:57:12 -0700 | [diff] [blame] | 457 | |
| 458 | // remove this glyph from the vertices we need to allocate |
| 459 | fTotalVertexCount -= kVerticesPerGlyph; |
jvanverth@google.com | c7a40fa | 2013-10-16 18:15:34 +0000 | [diff] [blame] | 460 | return; |
| 461 | } |
| 462 | |
jvanverth@google.com | c7a40fa | 2013-10-16 18:15:34 +0000 | [diff] [blame] | 463 | SkASSERT(glyph->fPlot); |
| 464 | GrDrawTarget::DrawToken drawToken = fDrawTarget->getCurrentDrawToken(); |
| 465 | glyph->fPlot->setDrawToken(drawToken); |
| 466 | |
| 467 | // now promote them to fixed (TODO: Rethink using fixed pt). |
| 468 | width = SkIntToFixed(width); |
| 469 | height = SkIntToFixed(height); |
| 470 | |
jvanverth | 294c326 | 2014-10-10 11:36:12 -0700 | [diff] [blame] | 471 | // the current texture/maskformat must match what the glyph needs |
jvanverth@google.com | c7a40fa | 2013-10-16 18:15:34 +0000 | [diff] [blame] | 472 | GrTexture* texture = glyph->fPlot->texture(); |
| 473 | SkASSERT(texture); |
| 474 | |
jvanverth | 73f1053 | 2014-10-23 11:57:12 -0700 | [diff] [blame] | 475 | if (fCurrTexture != texture || fCurrVertex + kVerticesPerGlyph > fAllocVertexCount) { |
jvanverth | 0fedb19 | 2014-10-08 09:07:27 -0700 | [diff] [blame] | 476 | this->flush(); |
Mike Klein | 6a25bd0 | 2014-08-29 10:03:59 -0400 | [diff] [blame] | 477 | fCurrTexture = texture; |
| 478 | fCurrTexture->ref(); |
jvanverth | 294c326 | 2014-10-10 11:36:12 -0700 | [diff] [blame] | 479 | fCurrMaskFormat = glyph->fMaskFormat; |
Mike Klein | 6a25bd0 | 2014-08-29 10:03:59 -0400 | [diff] [blame] | 480 | } |
| 481 | |
Mike Klein | 6a25bd0 | 2014-08-29 10:03:59 -0400 | [diff] [blame] | 482 | if (NULL == fVertices) { |
jvanverth | 73f1053 | 2014-10-23 11:57:12 -0700 | [diff] [blame] | 483 | int maxQuadVertices = kVerticesPerGlyph * fContext->getQuadIndexBuffer()->maxQuads(); |
| 484 | fAllocVertexCount = SkMin32(fTotalVertexCount, maxQuadVertices); |
egdaniel | ed3af66 | 2014-10-31 06:55:45 -0700 | [diff] [blame] | 485 | fVertices = alloc_vertices(fDrawTarget, fAllocVertexCount, fCurrMaskFormat); |
Mike Klein | 6a25bd0 | 2014-08-29 10:03:59 -0400 | [diff] [blame] | 486 | } |
| 487 | |
commit-bot@chromium.org | 972f9cd | 2014-03-28 17:58:28 +0000 | [diff] [blame] | 488 | SkFixed tx = SkIntToFixed(glyph->fAtlasLocation.fX); |
| 489 | SkFixed ty = SkIntToFixed(glyph->fAtlasLocation.fY); |
jvanverth@google.com | c7a40fa | 2013-10-16 18:15:34 +0000 | [diff] [blame] | 490 | |
commit-bot@chromium.org | 3ae0e6c | 2014-02-11 18:24:25 +0000 | [diff] [blame] | 491 | SkRect r; |
| 492 | r.fLeft = SkFixedToFloat(vx); |
| 493 | r.fTop = SkFixedToFloat(vy); |
| 494 | r.fRight = SkFixedToFloat(vx + width); |
| 495 | r.fBottom = SkFixedToFloat(vy + height); |
| 496 | |
reed | 10d0327 | 2014-10-01 09:24:12 -0700 | [diff] [blame] | 497 | fVertexBounds.joinNonEmptyArg(r); |
commit-bot@chromium.org | 3ae0e6c | 2014-02-11 18:24:25 +0000 | [diff] [blame] | 498 | |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 499 | size_t vertSize = get_vertex_stride(fCurrMaskFormat); |
bsalomon | 594069f | 2014-06-06 06:16:34 -0700 | [diff] [blame] | 500 | |
| 501 | SkPoint* positions = reinterpret_cast<SkPoint*>( |
| 502 | reinterpret_cast<intptr_t>(fVertices) + vertSize * fCurrVertex); |
| 503 | positions->setRectFan(r.fLeft, r.fTop, r.fRight, r.fBottom, vertSize); |
| 504 | |
| 505 | // The texture coords are last in both the with and without color vertex layouts. |
| 506 | SkPoint* textureCoords = reinterpret_cast<SkPoint*>( |
| 507 | reinterpret_cast<intptr_t>(positions) + vertSize - sizeof(SkPoint)); |
bsalomon | afbf2d6 | 2014-09-30 12:18:44 -0700 | [diff] [blame] | 508 | textureCoords->setRectFan(SkFixedToFloat(texture->texturePriv().normalizeFixedX(tx)), |
| 509 | SkFixedToFloat(texture->texturePriv().normalizeFixedY(ty)), |
| 510 | SkFixedToFloat(texture->texturePriv().normalizeFixedX(tx + width)), |
| 511 | SkFixedToFloat(texture->texturePriv().normalizeFixedY(ty + height)), |
bsalomon | 594069f | 2014-06-06 06:16:34 -0700 | [diff] [blame] | 512 | vertSize); |
egdaniel | ed3af66 | 2014-10-31 06:55:45 -0700 | [diff] [blame] | 513 | if (kA8_GrMaskFormat == fCurrMaskFormat) { |
bsalomon | 594069f | 2014-06-06 06:16:34 -0700 | [diff] [blame] | 514 | // color comes after position. |
| 515 | GrColor* colors = reinterpret_cast<GrColor*>(positions + 1); |
| 516 | for (int i = 0; i < 4; ++i) { |
| 517 | *colors = fPaint.getColor(); |
| 518 | colors = reinterpret_cast<GrColor*>(reinterpret_cast<intptr_t>(colors) + vertSize); |
| 519 | } |
| 520 | } |
jvanverth@google.com | c7a40fa | 2013-10-16 18:15:34 +0000 | [diff] [blame] | 521 | fCurrVertex += 4; |
| 522 | } |
jvanverth | 0fedb19 | 2014-10-08 09:07:27 -0700 | [diff] [blame] | 523 | |
jvanverth | 0fedb19 | 2014-10-08 09:07:27 -0700 | [diff] [blame] | 524 | void GrBitmapTextContext::flush() { |
| 525 | if (NULL == fDrawTarget) { |
| 526 | return; |
| 527 | } |
| 528 | |
jvanverth | 0fedb19 | 2014-10-08 09:07:27 -0700 | [diff] [blame] | 529 | if (fCurrVertex > 0) { |
joshualitt | 780b11e | 2014-11-18 09:40:40 -0800 | [diff] [blame] | 530 | GrDrawState drawState; |
| 531 | drawState.setFromPaint(fPaint, SkMatrix::I(), fContext->getRenderTarget()); |
| 532 | |
jvanverth | 0fedb19 | 2014-10-08 09:07:27 -0700 | [diff] [blame] | 533 | // setup our sampler state for our text texture/atlas |
| 534 | SkASSERT(SkIsAlign4(fCurrVertex)); |
| 535 | SkASSERT(fCurrTexture); |
jvanverth | 0fedb19 | 2014-10-08 09:07:27 -0700 | [diff] [blame] | 536 | |
jvanverth | 0fedb19 | 2014-10-08 09:07:27 -0700 | [diff] [blame] | 537 | SkASSERT(fStrike); |
joshualitt | 2e3b3e3 | 2014-12-09 13:31:14 -0800 | [diff] [blame] | 538 | GrColor color = fPaint.getColor(); |
jvanverth | 294c326 | 2014-10-10 11:36:12 -0700 | [diff] [blame] | 539 | switch (fCurrMaskFormat) { |
jvanverth | 0fedb19 | 2014-10-08 09:07:27 -0700 | [diff] [blame] | 540 | // Color bitmap text |
joshualitt | 2e3b3e3 | 2014-12-09 13:31:14 -0800 | [diff] [blame] | 541 | case kARGB_GrMaskFormat: { |
| 542 | int a = fSkPaint.getAlpha(); |
| 543 | color = SkColorSetARGB(a, a, a, a); |
jvanverth | 0fedb19 | 2014-10-08 09:07:27 -0700 | [diff] [blame] | 544 | break; |
joshualitt | 2e3b3e3 | 2014-12-09 13:31:14 -0800 | [diff] [blame] | 545 | } |
jvanverth | 0fedb19 | 2014-10-08 09:07:27 -0700 | [diff] [blame] | 546 | // LCD text |
jvanverth | 0fedb19 | 2014-10-08 09:07:27 -0700 | [diff] [blame] | 547 | case kA565_GrMaskFormat: { |
egdaniel | 378092f | 2014-12-03 10:40:13 -0800 | [diff] [blame] | 548 | // TODO: move supportsRGBCoverage check to setupCoverageEffect and only add LCD |
| 549 | // processor if the xp can support it. For now we will simply assume that if |
| 550 | // fUseLCDText is true, then we have a known color output. |
| 551 | if (!drawState.getXPFactory()->supportsRGBCoverage(0, kRGBA_GrColorComponentFlags)) { |
tfarina | 38406c8 | 2014-10-31 07:11:12 -0700 | [diff] [blame] | 552 | SkDebugf("LCD Text will not draw correctly.\n"); |
jvanverth | 0fedb19 | 2014-10-08 09:07:27 -0700 | [diff] [blame] | 553 | } |
jvanverth | 0fedb19 | 2014-10-08 09:07:27 -0700 | [diff] [blame] | 554 | break; |
| 555 | } |
| 556 | // Grayscale/BW text |
| 557 | case kA8_GrMaskFormat: |
jvanverth | 0fedb19 | 2014-10-08 09:07:27 -0700 | [diff] [blame] | 558 | break; |
| 559 | default: |
jvanverth | 294c326 | 2014-10-10 11:36:12 -0700 | [diff] [blame] | 560 | SkFAIL("Unexpected mask format."); |
jvanverth | 0fedb19 | 2014-10-08 09:07:27 -0700 | [diff] [blame] | 561 | } |
joshualitt | 2e3b3e3 | 2014-12-09 13:31:14 -0800 | [diff] [blame] | 562 | |
| 563 | GrTextureParams params(SkShader::kRepeat_TileMode, GrTextureParams::kNone_FilterMode); |
joshualitt | 2e3b3e3 | 2014-12-09 13:31:14 -0800 | [diff] [blame] | 564 | if (kARGB_GrMaskFormat == fCurrMaskFormat) { |
| 565 | uint32_t textureUniqueID = fCurrTexture->getUniqueID(); |
| 566 | if (textureUniqueID != fEffectTextureUniqueID || |
joshualitt | 56995b5 | 2014-12-11 15:44:02 -0800 | [diff] [blame] | 567 | fCachedGeometryProcessor->color() != color) { |
joshualitt | 2e3b3e3 | 2014-12-09 13:31:14 -0800 | [diff] [blame] | 568 | uint32_t flags = GrDefaultGeoProcFactory::kLocalCoord_GPType; |
| 569 | fCachedGeometryProcessor.reset(GrDefaultGeoProcFactory::Create(color, flags)); |
| 570 | fCachedTextureProcessor.reset(GrSimpleTextureEffect::Create(fCurrTexture, |
| 571 | SkMatrix::I(), |
| 572 | params)); |
joshualitt | 8fc6c2d | 2014-12-22 15:27:05 -0800 | [diff] [blame] | 573 | fEffectTextureUniqueID = textureUniqueID; |
joshualitt | 2e3b3e3 | 2014-12-09 13:31:14 -0800 | [diff] [blame] | 574 | } |
joshualitt | 2e3b3e3 | 2014-12-09 13:31:14 -0800 | [diff] [blame] | 575 | drawState.addColorProcessor(fCachedTextureProcessor.get()); |
| 576 | } else { |
| 577 | uint32_t textureUniqueID = fCurrTexture->getUniqueID(); |
| 578 | if (textureUniqueID != fEffectTextureUniqueID || |
joshualitt | 8fc6c2d | 2014-12-22 15:27:05 -0800 | [diff] [blame] | 579 | fCachedGeometryProcessor->color() != color || |
| 580 | !fCachedGeometryProcessor->localMatrix().cheapEqualTo(fLocalMatrix)) { |
joshualitt | 2e3b3e3 | 2014-12-09 13:31:14 -0800 | [diff] [blame] | 581 | bool hasColor = kA8_GrMaskFormat == fCurrMaskFormat; |
joshualitt | 56995b5 | 2014-12-11 15:44:02 -0800 | [diff] [blame] | 582 | bool opaqueVertexColors = GrColorIsOpaque(fPaint.getColor()); |
joshualitt | 2e3b3e3 | 2014-12-09 13:31:14 -0800 | [diff] [blame] | 583 | fCachedGeometryProcessor.reset(GrBitmapTextGeoProc::Create(color, |
joshualitt | 56995b5 | 2014-12-11 15:44:02 -0800 | [diff] [blame] | 584 | fCurrTexture, |
| 585 | params, |
| 586 | hasColor, |
joshualitt | 8fc6c2d | 2014-12-22 15:27:05 -0800 | [diff] [blame] | 587 | opaqueVertexColors, |
| 588 | fLocalMatrix)); |
joshualitt | 2e3b3e3 | 2014-12-09 13:31:14 -0800 | [diff] [blame] | 589 | fEffectTextureUniqueID = textureUniqueID; |
| 590 | } |
joshualitt | 2e3b3e3 | 2014-12-09 13:31:14 -0800 | [diff] [blame] | 591 | } |
| 592 | |
jvanverth | 73f1053 | 2014-10-23 11:57:12 -0700 | [diff] [blame] | 593 | int nGlyphs = fCurrVertex / kVerticesPerGlyph; |
jvanverth | 0fedb19 | 2014-10-08 09:07:27 -0700 | [diff] [blame] | 594 | fDrawTarget->setIndexSourceToBuffer(fContext->getQuadIndexBuffer()); |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 595 | fDrawTarget->drawIndexedInstances(&drawState, |
joshualitt | 56995b5 | 2014-12-11 15:44:02 -0800 | [diff] [blame] | 596 | fCachedGeometryProcessor.get(), |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 597 | kTriangles_GrPrimitiveType, |
jvanverth | 0fedb19 | 2014-10-08 09:07:27 -0700 | [diff] [blame] | 598 | nGlyphs, |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 599 | kVerticesPerGlyph, |
| 600 | kIndicesPerGlyph, |
| 601 | &fVertexBounds); |
jvanverth | 0fedb19 | 2014-10-08 09:07:27 -0700 | [diff] [blame] | 602 | |
| 603 | fDrawTarget->resetVertexSource(); |
| 604 | fVertices = NULL; |
jvanverth | 73f1053 | 2014-10-23 11:57:12 -0700 | [diff] [blame] | 605 | fAllocVertexCount = 0; |
| 606 | // reset to be those that are left |
| 607 | fTotalVertexCount -= fCurrVertex; |
jvanverth | 0fedb19 | 2014-10-08 09:07:27 -0700 | [diff] [blame] | 608 | fCurrVertex = 0; |
| 609 | fVertexBounds.setLargestInverted(); |
| 610 | SkSafeSetNull(fCurrTexture); |
| 611 | } |
| 612 | } |
| 613 | |
| 614 | inline void GrBitmapTextContext::finish() { |
| 615 | this->flush(); |
jvanverth | 73f1053 | 2014-10-23 11:57:12 -0700 | [diff] [blame] | 616 | fTotalVertexCount = 0; |
jvanverth | 0fedb19 | 2014-10-08 09:07:27 -0700 | [diff] [blame] | 617 | |
| 618 | GrTextContext::finish(); |
| 619 | } |
| 620 | |