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