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