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