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