jvanverth@google.com | d830d13 | 2013-11-11 20:54:09 +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 "GrDistanceFieldTextContext.h" |
| 9 | #include "GrAtlas.h" |
jvanverth | 2d2a68c | 2014-06-10 06:42:56 -0700 | [diff] [blame] | 10 | #include "SkColorFilter.h" |
jvanverth@google.com | d830d13 | 2013-11-11 20:54:09 +0000 | [diff] [blame] | 11 | #include "GrDrawTarget.h" |
commit-bot@chromium.org | 6c89c34 | 2014-02-14 21:48:29 +0000 | [diff] [blame] | 12 | #include "GrDrawTargetCaps.h" |
jvanverth@google.com | d830d13 | 2013-11-11 20:54:09 +0000 | [diff] [blame] | 13 | #include "GrFontScaler.h" |
commit-bot@chromium.org | 8128d8c | 2013-12-19 16:12:25 +0000 | [diff] [blame] | 14 | #include "SkGlyphCache.h" |
jvanverth | 2d2a68c | 2014-06-10 06:42:56 -0700 | [diff] [blame] | 15 | #include "GrGpu.h" |
jvanverth@google.com | d830d13 | 2013-11-11 20:54:09 +0000 | [diff] [blame] | 16 | #include "GrIndexBuffer.h" |
egdaniel | d58a0ba | 2014-06-11 10:30:05 -0700 | [diff] [blame] | 17 | #include "GrStrokeInfo.h" |
jvanverth@google.com | d830d13 | 2013-11-11 20:54:09 +0000 | [diff] [blame] | 18 | #include "GrTextStrike.h" |
| 19 | #include "GrTextStrike_impl.h" |
commit-bot@chromium.org | 64b08a1 | 2014-04-15 17:53:21 +0000 | [diff] [blame] | 20 | #include "SkDistanceFieldGen.h" |
commit-bot@chromium.org | 9f94b91 | 2014-01-30 15:22:54 +0000 | [diff] [blame] | 21 | #include "SkDraw.h" |
commit-bot@chromium.org | e8612d9 | 2014-01-28 22:02:07 +0000 | [diff] [blame] | 22 | #include "SkGpuDevice.h" |
jvanverth@google.com | d830d13 | 2013-11-11 20:54:09 +0000 | [diff] [blame] | 23 | #include "SkPath.h" |
| 24 | #include "SkRTConf.h" |
| 25 | #include "SkStrokeRec.h" |
| 26 | #include "effects/GrDistanceFieldTextureEffect.h" |
| 27 | |
jvanverth | feceba5 | 2014-07-25 19:03:34 -0700 | [diff] [blame] | 28 | SK_CONF_DECLARE(bool, c_DumpFontCache, "gpu.dumpFontCache", false, |
| 29 | "Dump the contents of the font cache before every purge."); |
| 30 | |
| 31 | static const int kGlyphCoordsNoColorAttributeIndex = 1; |
| 32 | static const int kGlyphCoordsWithColorAttributeIndex = 2; |
jvanverth@google.com | d830d13 | 2013-11-11 20:54:09 +0000 | [diff] [blame] | 33 | |
commit-bot@chromium.org | dc5cd85 | 2014-04-02 19:24:32 +0000 | [diff] [blame] | 34 | static const int kSmallDFFontSize = 32; |
| 35 | static const int kSmallDFFontLimit = 32; |
| 36 | static const int kMediumDFFontSize = 64; |
| 37 | static const int kMediumDFFontLimit = 64; |
| 38 | static const int kLargeDFFontSize = 128; |
commit-bot@chromium.org | 8128d8c | 2013-12-19 16:12:25 +0000 | [diff] [blame] | 39 | |
jvanverth | feceba5 | 2014-07-25 19:03:34 -0700 | [diff] [blame] | 40 | namespace { |
| 41 | // position + texture coord |
| 42 | extern const GrVertexAttrib gTextVertexAttribs[] = { |
| 43 | {kVec2f_GrVertexAttribType, 0, kPosition_GrVertexAttribBinding}, |
| 44 | {kVec2f_GrVertexAttribType, sizeof(SkPoint) , kEffect_GrVertexAttribBinding} |
| 45 | }; |
| 46 | |
| 47 | // position + color + texture coord |
| 48 | extern const GrVertexAttrib gTextVertexWithColorAttribs[] = { |
| 49 | {kVec2f_GrVertexAttribType, 0, kPosition_GrVertexAttribBinding}, |
| 50 | {kVec4ub_GrVertexAttribType, sizeof(SkPoint), kColor_GrVertexAttribBinding}, |
| 51 | {kVec2f_GrVertexAttribType, sizeof(SkPoint) + sizeof(GrColor), kEffect_GrVertexAttribBinding} |
| 52 | }; |
| 53 | |
| 54 | }; |
jvanverth@google.com | d830d13 | 2013-11-11 20:54:09 +0000 | [diff] [blame] | 55 | |
skia.committer@gmail.com | e5d7015 | 2014-01-29 07:01:48 +0000 | [diff] [blame] | 56 | GrDistanceFieldTextContext::GrDistanceFieldTextContext(GrContext* context, |
commit-bot@chromium.org | 6fcd1ef | 2014-05-02 12:39:41 +0000 | [diff] [blame] | 57 | const SkDeviceProperties& properties, |
| 58 | bool enable) |
commit-bot@chromium.org | cbbc481 | 2014-01-30 22:05:47 +0000 | [diff] [blame] | 59 | : GrTextContext(context, properties) { |
commit-bot@chromium.org | 6fcd1ef | 2014-05-02 12:39:41 +0000 | [diff] [blame] | 60 | #if SK_FORCE_DISTANCEFIELD_FONTS |
| 61 | fEnableDFRendering = true; |
| 62 | #else |
| 63 | fEnableDFRendering = enable; |
| 64 | #endif |
jvanverth@google.com | d830d13 | 2013-11-11 20:54:09 +0000 | [diff] [blame] | 65 | fStrike = NULL; |
jvanverth | 2d2a68c | 2014-06-10 06:42:56 -0700 | [diff] [blame] | 66 | fGammaTexture = NULL; |
jvanverth@google.com | d830d13 | 2013-11-11 20:54:09 +0000 | [diff] [blame] | 67 | |
jvanverth | 9bcd23b | 2014-08-01 14:05:19 -0700 | [diff] [blame] | 68 | fCurrTexture = NULL; |
jvanverth@google.com | d830d13 | 2013-11-11 20:54:09 +0000 | [diff] [blame] | 69 | fCurrVertex = 0; |
jvanverth | 78f0718 | 2014-07-30 06:17:59 -0700 | [diff] [blame] | 70 | fEffectTextureUniqueID = SK_InvalidUniqueID; |
| 71 | fEffectColor = GrColor_ILLEGAL; |
| 72 | fEffectFlags = 0; |
jvanverth | 1723bfc | 2014-07-30 09:16:33 -0700 | [diff] [blame] | 73 | |
jvanverth@google.com | d830d13 | 2013-11-11 20:54:09 +0000 | [diff] [blame] | 74 | fVertices = NULL; |
jvanverth | 9bcd23b | 2014-08-01 14:05:19 -0700 | [diff] [blame] | 75 | fMaxVertices = 0; |
jvanverth | 1723bfc | 2014-07-30 09:16:33 -0700 | [diff] [blame] | 76 | |
| 77 | fVertexBounds.setLargestInverted(); |
jvanverth@google.com | d830d13 | 2013-11-11 20:54:09 +0000 | [diff] [blame] | 78 | } |
| 79 | |
| 80 | GrDistanceFieldTextContext::~GrDistanceFieldTextContext() { |
| 81 | this->flushGlyphs(); |
jvanverth | 2d2a68c | 2014-06-10 06:42:56 -0700 | [diff] [blame] | 82 | SkSafeSetNull(fGammaTexture); |
jvanverth@google.com | d830d13 | 2013-11-11 20:54:09 +0000 | [diff] [blame] | 83 | } |
| 84 | |
commit-bot@chromium.org | cbbc481 | 2014-01-30 22:05:47 +0000 | [diff] [blame] | 85 | bool GrDistanceFieldTextContext::canDraw(const SkPaint& paint) { |
commit-bot@chromium.org | 6fcd1ef | 2014-05-02 12:39:41 +0000 | [diff] [blame] | 86 | if (!fEnableDFRendering && !paint.isDistanceFieldTextTEMP()) { |
commit-bot@chromium.org | eefd8a0 | 2014-04-08 20:14:32 +0000 | [diff] [blame] | 87 | return false; |
| 88 | } |
| 89 | |
skia.committer@gmail.com | e1d9443 | 2014-04-09 03:04:11 +0000 | [diff] [blame] | 90 | // rasterizers and mask filters modify alpha, which doesn't |
commit-bot@chromium.org | eefd8a0 | 2014-04-08 20:14:32 +0000 | [diff] [blame] | 91 | // translate well to distance |
| 92 | if (paint.getRasterizer() || paint.getMaskFilter() || |
| 93 | !fContext->getTextTarget()->caps()->shaderDerivativeSupport()) { |
| 94 | return false; |
| 95 | } |
| 96 | |
| 97 | // TODO: add some stroking support |
| 98 | if (paint.getStyle() != SkPaint::kFill_Style) { |
| 99 | return false; |
| 100 | } |
| 101 | |
| 102 | // TODO: choose an appropriate maximum scale for distance fields and |
| 103 | // enable perspective |
| 104 | if (SkDraw::ShouldDrawTextAsPaths(paint, fContext->getMatrix())) { |
| 105 | return false; |
| 106 | } |
| 107 | |
| 108 | // distance fields cannot represent color fonts |
| 109 | SkScalerContext::Rec rec; |
| 110 | SkScalerContext::MakeRec(paint, &fDeviceProperties, NULL, &rec); |
| 111 | return rec.getFormat() != SkMask::kARGB32_Format; |
commit-bot@chromium.org | cbbc481 | 2014-01-30 22:05:47 +0000 | [diff] [blame] | 112 | } |
| 113 | |
jvanverth@google.com | d830d13 | 2013-11-11 20:54:09 +0000 | [diff] [blame] | 114 | static inline GrColor skcolor_to_grcolor_nopremultiply(SkColor c) { |
| 115 | unsigned r = SkColorGetR(c); |
| 116 | unsigned g = SkColorGetG(c); |
| 117 | unsigned b = SkColorGetB(c); |
| 118 | return GrColorPackRGBA(r, g, b, 0xff); |
| 119 | } |
| 120 | |
jvanverth | 78f0718 | 2014-07-30 06:17:59 -0700 | [diff] [blame] | 121 | void GrDistanceFieldTextContext::setupCoverageEffect(const SkColor& filteredColor) { |
| 122 | GrTextureParams params(SkShader::kRepeat_TileMode, GrTextureParams::kBilerp_FilterMode); |
| 123 | GrTextureParams gammaParams(SkShader::kClamp_TileMode, GrTextureParams::kNone_FilterMode); |
| 124 | |
jvanverth | 9bcd23b | 2014-08-01 14:05:19 -0700 | [diff] [blame] | 125 | uint32_t textureUniqueID = fCurrTexture->getUniqueID(); |
jvanverth | 78f0718 | 2014-07-30 06:17:59 -0700 | [diff] [blame] | 126 | |
| 127 | // set up any flags |
| 128 | uint32_t flags = 0; |
| 129 | flags |= fContext->getMatrix().isSimilarity() ? kSimilarity_DistanceFieldEffectFlag : 0; |
| 130 | flags |= fUseLCDText ? kUseLCD_DistanceFieldEffectFlag : 0; |
| 131 | flags |= fUseLCDText && fContext->getMatrix().rectStaysRect() ? |
| 132 | kRectToRect_DistanceFieldEffectFlag : 0; |
| 133 | bool useBGR = SkDeviceProperties::Geometry::kBGR_Layout == |
| 134 | fDeviceProperties.fGeometry.getLayout(); |
| 135 | flags |= fUseLCDText && useBGR ? kBGR_DistanceFieldEffectFlag : 0; |
| 136 | |
| 137 | // see if we need to create a new effect |
| 138 | if (textureUniqueID != fEffectTextureUniqueID || |
| 139 | filteredColor != fEffectColor || |
| 140 | flags != fEffectFlags) { |
| 141 | if (fUseLCDText) { |
| 142 | GrColor colorNoPreMul = skcolor_to_grcolor_nopremultiply(filteredColor); |
jvanverth | 9bcd23b | 2014-08-01 14:05:19 -0700 | [diff] [blame] | 143 | fCachedEffect.reset(GrDistanceFieldLCDTextureEffect::Create(fCurrTexture, |
jvanverth | 78f0718 | 2014-07-30 06:17:59 -0700 | [diff] [blame] | 144 | params, |
| 145 | fGammaTexture, |
| 146 | gammaParams, |
| 147 | colorNoPreMul, |
| 148 | flags)); |
| 149 | } else { |
| 150 | #ifdef SK_GAMMA_APPLY_TO_A8 |
| 151 | U8CPU lum = SkColorSpaceLuminance::computeLuminance(fDeviceProperties.fGamma, |
| 152 | filteredColor); |
jvanverth | 9bcd23b | 2014-08-01 14:05:19 -0700 | [diff] [blame] | 153 | fCachedEffect.reset(GrDistanceFieldTextureEffect::Create(fCurrTexture, |
jvanverth | 78f0718 | 2014-07-30 06:17:59 -0700 | [diff] [blame] | 154 | params, |
| 155 | fGammaTexture, |
| 156 | gammaParams, |
| 157 | lum/255.f, |
| 158 | flags)); |
| 159 | #else |
jvanverth | 7883132 | 2014-08-01 17:15:20 -0700 | [diff] [blame^] | 160 | fCachedEffect.reset(GrDistanceFieldTextureEffect::Create(fCurrTexture, |
jvanverth | 78f0718 | 2014-07-30 06:17:59 -0700 | [diff] [blame] | 161 | params, flags)); |
| 162 | #endif |
| 163 | } |
| 164 | fEffectTextureUniqueID = textureUniqueID; |
| 165 | fEffectColor = filteredColor; |
| 166 | fEffectFlags = flags; |
| 167 | } |
| 168 | |
| 169 | } |
| 170 | |
jvanverth@google.com | d830d13 | 2013-11-11 20:54:09 +0000 | [diff] [blame] | 171 | void GrDistanceFieldTextContext::flushGlyphs() { |
| 172 | if (NULL == fDrawTarget) { |
| 173 | return; |
| 174 | } |
| 175 | |
| 176 | GrDrawState* drawState = fDrawTarget->drawState(); |
| 177 | GrDrawState::AutoRestoreEffects are(drawState); |
| 178 | drawState->setFromPaint(fPaint, fContext->getMatrix(), fContext->getRenderTarget()); |
| 179 | |
| 180 | if (fCurrVertex > 0) { |
| 181 | // setup our sampler state for our text texture/atlas |
commit-bot@chromium.org | 972f9cd | 2014-03-28 17:58:28 +0000 | [diff] [blame] | 182 | SkASSERT(SkIsAlign4(fCurrVertex)); |
jvanverth@google.com | d830d13 | 2013-11-11 20:54:09 +0000 | [diff] [blame] | 183 | |
jvanverth | 78f0718 | 2014-07-30 06:17:59 -0700 | [diff] [blame] | 184 | // get our current color |
jvanverth | 2d2a68c | 2014-06-10 06:42:56 -0700 | [diff] [blame] | 185 | SkColor filteredColor; |
| 186 | SkColorFilter* colorFilter = fSkPaint.getColorFilter(); |
| 187 | if (NULL != colorFilter) { |
| 188 | filteredColor = colorFilter->filterColor(fSkPaint.getColor()); |
| 189 | } else { |
| 190 | filteredColor = fSkPaint.getColor(); |
| 191 | } |
jvanverth | 78f0718 | 2014-07-30 06:17:59 -0700 | [diff] [blame] | 192 | this->setupCoverageEffect(filteredColor); |
| 193 | |
| 194 | // Effects could be stored with one of the cache objects (atlas?) |
| 195 | int coordsIdx = drawState->hasColorVertexAttribute() ? kGlyphCoordsWithColorAttributeIndex : |
| 196 | kGlyphCoordsNoColorAttributeIndex; |
| 197 | drawState->addCoverageEffect(fCachedEffect.get(), coordsIdx); |
| 198 | |
| 199 | // Set draw state |
commit-bot@chromium.org | 609ced4 | 2014-04-03 18:25:48 +0000 | [diff] [blame] | 200 | if (fUseLCDText) { |
jvanverth | 2d2a68c | 2014-06-10 06:42:56 -0700 | [diff] [blame] | 201 | GrColor colorNoPreMul = skcolor_to_grcolor_nopremultiply(filteredColor); |
jvanverth@google.com | d830d13 | 2013-11-11 20:54:09 +0000 | [diff] [blame] | 202 | if (kOne_GrBlendCoeff != fPaint.getSrcBlendCoeff() || |
| 203 | kISA_GrBlendCoeff != fPaint.getDstBlendCoeff() || |
| 204 | fPaint.numColorStages()) { |
| 205 | GrPrintf("LCD Text will not draw correctly.\n"); |
| 206 | } |
jvanverth | feceba5 | 2014-07-25 19:03:34 -0700 | [diff] [blame] | 207 | SkASSERT(!drawState->hasColorVertexAttribute()); |
jvanverth@google.com | d830d13 | 2013-11-11 20:54:09 +0000 | [diff] [blame] | 208 | // We don't use the GrPaint's color in this case because it's been premultiplied by |
| 209 | // alpha. Instead we feed in a non-premultiplied color, and multiply its alpha by |
| 210 | // the mask texture color. The end result is that we get |
| 211 | // mask*paintAlpha*paintColor + (1-mask*paintAlpha)*dstColor |
commit-bot@chromium.org | 8128d8c | 2013-12-19 16:12:25 +0000 | [diff] [blame] | 212 | int a = SkColorGetA(fSkPaint.getColor()); |
jvanverth@google.com | d830d13 | 2013-11-11 20:54:09 +0000 | [diff] [blame] | 213 | // paintAlpha |
| 214 | drawState->setColor(SkColorSetARGB(a, a, a, a)); |
| 215 | // paintColor |
jvanverth | 2d2a68c | 2014-06-10 06:42:56 -0700 | [diff] [blame] | 216 | drawState->setBlendConstant(colorNoPreMul); |
jvanverth@google.com | d830d13 | 2013-11-11 20:54:09 +0000 | [diff] [blame] | 217 | drawState->setBlendFunc(kConstC_GrBlendCoeff, kISC_GrBlendCoeff); |
| 218 | } else { |
| 219 | // set back to normal in case we took LCD path previously. |
| 220 | drawState->setBlendFunc(fPaint.getSrcBlendCoeff(), fPaint.getDstBlendCoeff()); |
jvanverth | feceba5 | 2014-07-25 19:03:34 -0700 | [diff] [blame] | 221 | //drawState->setColor(fPaint.getColor()); |
| 222 | // We're using per-vertex color. |
| 223 | SkASSERT(drawState->hasColorVertexAttribute()); |
| 224 | drawState->setColor(0xFFFFFFFF); |
jvanverth@google.com | d830d13 | 2013-11-11 20:54:09 +0000 | [diff] [blame] | 225 | } |
jvanverth@google.com | d830d13 | 2013-11-11 20:54:09 +0000 | [diff] [blame] | 226 | int nGlyphs = fCurrVertex / 4; |
| 227 | fDrawTarget->setIndexSourceToBuffer(fContext->getQuadIndexBuffer()); |
| 228 | fDrawTarget->drawIndexedInstances(kTriangles_GrPrimitiveType, |
| 229 | nGlyphs, |
jvanverth | 1723bfc | 2014-07-30 09:16:33 -0700 | [diff] [blame] | 230 | 4, 6, &fVertexBounds); |
jvanverth | 9bcd23b | 2014-08-01 14:05:19 -0700 | [diff] [blame] | 231 | fDrawTarget->resetVertexSource(); |
| 232 | fVertices = NULL; |
| 233 | fMaxVertices = 0; |
jvanverth@google.com | d830d13 | 2013-11-11 20:54:09 +0000 | [diff] [blame] | 234 | fCurrVertex = 0; |
jvanverth | 9bcd23b | 2014-08-01 14:05:19 -0700 | [diff] [blame] | 235 | SkSafeSetNull(fCurrTexture); |
jvanverth | 1723bfc | 2014-07-30 09:16:33 -0700 | [diff] [blame] | 236 | fVertexBounds.setLargestInverted(); |
jvanverth@google.com | d830d13 | 2013-11-11 20:54:09 +0000 | [diff] [blame] | 237 | } |
| 238 | } |
| 239 | |
jvanverth@google.com | d830d13 | 2013-11-11 20:54:09 +0000 | [diff] [blame] | 240 | void GrDistanceFieldTextContext::drawPackedGlyph(GrGlyph::PackedID packed, |
commit-bot@chromium.org | 972f9cd | 2014-03-28 17:58:28 +0000 | [diff] [blame] | 241 | SkFixed vx, SkFixed vy, |
jvanverth@google.com | d830d13 | 2013-11-11 20:54:09 +0000 | [diff] [blame] | 242 | GrFontScaler* scaler) { |
jvanverth | 9bcd23b | 2014-08-01 14:05:19 -0700 | [diff] [blame] | 243 | if (NULL == fDrawTarget) { |
| 244 | return; |
| 245 | } |
| 246 | |
| 247 | if (NULL == fStrike) { |
| 248 | fStrike = fContext->getFontCache()->getStrike(scaler, true); |
| 249 | } |
| 250 | |
jvanverth@google.com | d830d13 | 2013-11-11 20:54:09 +0000 | [diff] [blame] | 251 | GrGlyph* glyph = fStrike->getGlyph(packed, scaler); |
| 252 | if (NULL == glyph || glyph->fBounds.isEmpty()) { |
| 253 | return; |
| 254 | } |
| 255 | |
| 256 | SkScalar sx = SkFixedToScalar(vx); |
| 257 | SkScalar sy = SkFixedToScalar(vy); |
| 258 | /* |
| 259 | // not valid, need to find a different solution for this |
| 260 | vx += SkIntToFixed(glyph->fBounds.fLeft); |
| 261 | vy += SkIntToFixed(glyph->fBounds.fTop); |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 262 | |
jvanverth@google.com | d830d13 | 2013-11-11 20:54:09 +0000 | [diff] [blame] | 263 | // keep them as ints until we've done the clip-test |
| 264 | GrFixed width = glyph->fBounds.width(); |
| 265 | GrFixed height = glyph->fBounds.height(); |
| 266 | |
| 267 | // check if we clipped out |
| 268 | if (true || NULL == glyph->fPlot) { |
| 269 | int x = vx >> 16; |
| 270 | int y = vy >> 16; |
| 271 | if (fClipRect.quickReject(x, y, x + width, y + height)) { |
| 272 | // SkCLZ(3); // so we can set a break-point in the debugger |
| 273 | return; |
| 274 | } |
| 275 | } |
| 276 | */ |
| 277 | if (NULL == glyph->fPlot) { |
commit-bot@chromium.org | c9b2c88 | 2014-03-03 14:30:25 +0000 | [diff] [blame] | 278 | if (fStrike->addGlyphToAtlas(glyph, scaler)) { |
jvanverth@google.com | d830d13 | 2013-11-11 20:54:09 +0000 | [diff] [blame] | 279 | goto HAS_ATLAS; |
| 280 | } |
| 281 | |
| 282 | // try to clear out an unused plot before we flush |
commit-bot@chromium.org | c9b2c88 | 2014-03-03 14:30:25 +0000 | [diff] [blame] | 283 | if (fContext->getFontCache()->freeUnusedPlot(fStrike) && |
| 284 | fStrike->addGlyphToAtlas(glyph, scaler)) { |
jvanverth@google.com | d830d13 | 2013-11-11 20:54:09 +0000 | [diff] [blame] | 285 | goto HAS_ATLAS; |
| 286 | } |
| 287 | |
| 288 | if (c_DumpFontCache) { |
| 289 | #ifdef SK_DEVELOPER |
| 290 | fContext->getFontCache()->dump(); |
| 291 | #endif |
| 292 | } |
| 293 | |
| 294 | // before we purge the cache, we must flush any accumulated draws |
| 295 | this->flushGlyphs(); |
| 296 | fContext->flush(); |
| 297 | |
commit-bot@chromium.org | c9b2c88 | 2014-03-03 14:30:25 +0000 | [diff] [blame] | 298 | // we should have an unused plot now |
| 299 | if (fContext->getFontCache()->freeUnusedPlot(fStrike) && |
| 300 | fStrike->addGlyphToAtlas(glyph, scaler)) { |
jvanverth@google.com | d830d13 | 2013-11-11 20:54:09 +0000 | [diff] [blame] | 301 | goto HAS_ATLAS; |
| 302 | } |
| 303 | |
| 304 | if (NULL == glyph->fPath) { |
| 305 | SkPath* path = SkNEW(SkPath); |
| 306 | if (!scaler->getGlyphPath(glyph->glyphID(), path)) { |
| 307 | // flag the glyph as being dead? |
| 308 | delete path; |
| 309 | return; |
| 310 | } |
| 311 | glyph->fPath = path; |
| 312 | } |
| 313 | |
| 314 | GrContext::AutoMatrix am; |
commit-bot@chromium.org | 762cd80 | 2014-04-14 22:05:07 +0000 | [diff] [blame] | 315 | SkMatrix ctm; |
| 316 | ctm.setScale(fTextRatio, fTextRatio); |
| 317 | ctm.postTranslate(sx, sy); |
jvanverth@google.com | d830d13 | 2013-11-11 20:54:09 +0000 | [diff] [blame] | 318 | GrPaint tmpPaint(fPaint); |
commit-bot@chromium.org | 762cd80 | 2014-04-14 22:05:07 +0000 | [diff] [blame] | 319 | am.setPreConcat(fContext, ctm, &tmpPaint); |
egdaniel | d58a0ba | 2014-06-11 10:30:05 -0700 | [diff] [blame] | 320 | GrStrokeInfo strokeInfo(SkStrokeRec::kFill_InitStyle); |
| 321 | fContext->drawPath(tmpPaint, *glyph->fPath, strokeInfo); |
jvanverth@google.com | d830d13 | 2013-11-11 20:54:09 +0000 | [diff] [blame] | 322 | return; |
| 323 | } |
| 324 | |
| 325 | HAS_ATLAS: |
| 326 | SkASSERT(glyph->fPlot); |
| 327 | GrDrawTarget::DrawToken drawToken = fDrawTarget->getCurrentDrawToken(); |
| 328 | glyph->fPlot->setDrawToken(drawToken); |
| 329 | |
| 330 | GrTexture* texture = glyph->fPlot->texture(); |
| 331 | SkASSERT(texture); |
| 332 | |
jvanverth | 9bcd23b | 2014-08-01 14:05:19 -0700 | [diff] [blame] | 333 | if (fCurrTexture != texture || fCurrVertex + 4 > fMaxVertices) { |
| 334 | this->flushGlyphs(); |
| 335 | fCurrTexture = texture; |
| 336 | fCurrTexture->ref(); |
| 337 | } |
| 338 | |
| 339 | bool useColorVerts = !fUseLCDText; |
| 340 | |
| 341 | if (NULL == fVertices) { |
| 342 | // If we need to reserve vertices allow the draw target to suggest |
| 343 | // a number of verts to reserve and whether to perform a flush. |
| 344 | fMaxVertices = kMinRequestedVerts; |
| 345 | if (useColorVerts) { |
| 346 | fDrawTarget->drawState()->setVertexAttribs<gTextVertexWithColorAttribs>( |
| 347 | SK_ARRAY_COUNT(gTextVertexWithColorAttribs)); |
| 348 | } else { |
| 349 | fDrawTarget->drawState()->setVertexAttribs<gTextVertexAttribs>( |
| 350 | SK_ARRAY_COUNT(gTextVertexAttribs)); |
| 351 | } |
| 352 | bool flush = fDrawTarget->geometryHints(&fMaxVertices, NULL); |
| 353 | if (flush) { |
| 354 | this->flushGlyphs(); |
| 355 | fContext->flush(); |
| 356 | if (useColorVerts) { |
| 357 | fDrawTarget->drawState()->setVertexAttribs<gTextVertexWithColorAttribs>( |
| 358 | SK_ARRAY_COUNT(gTextVertexWithColorAttribs)); |
| 359 | } else { |
| 360 | fDrawTarget->drawState()->setVertexAttribs<gTextVertexAttribs>( |
| 361 | SK_ARRAY_COUNT(gTextVertexAttribs)); |
| 362 | } |
| 363 | } |
| 364 | fMaxVertices = kDefaultRequestedVerts; |
| 365 | // ignore return, no point in flushing again. |
| 366 | fDrawTarget->geometryHints(&fMaxVertices, NULL); |
| 367 | |
| 368 | int maxQuadVertices = 4 * fContext->getQuadIndexBuffer()->maxQuads(); |
| 369 | if (fMaxVertices < kMinRequestedVerts) { |
| 370 | fMaxVertices = kDefaultRequestedVerts; |
| 371 | } else if (fMaxVertices > maxQuadVertices) { |
| 372 | // don't exceed the limit of the index buffer |
| 373 | fMaxVertices = maxQuadVertices; |
| 374 | } |
| 375 | bool success = fDrawTarget->reserveVertexAndIndexSpace(fMaxVertices, |
| 376 | 0, |
| 377 | &fVertices, |
| 378 | NULL); |
| 379 | GrAlwaysAssert(success); |
| 380 | } |
| 381 | |
commit-bot@chromium.org | 64b08a1 | 2014-04-15 17:53:21 +0000 | [diff] [blame] | 382 | SkScalar dx = SkIntToScalar(glyph->fBounds.fLeft + SK_DistanceFieldInset); |
| 383 | SkScalar dy = SkIntToScalar(glyph->fBounds.fTop + SK_DistanceFieldInset); |
| 384 | SkScalar width = SkIntToScalar(glyph->fBounds.width() - 2*SK_DistanceFieldInset); |
| 385 | SkScalar height = SkIntToScalar(glyph->fBounds.height() - 2*SK_DistanceFieldInset); |
jvanverth@google.com | d830d13 | 2013-11-11 20:54:09 +0000 | [diff] [blame] | 386 | |
| 387 | SkScalar scale = fTextRatio; |
| 388 | dx *= scale; |
| 389 | dy *= scale; |
| 390 | sx += dx; |
| 391 | sy += dy; |
| 392 | width *= scale; |
| 393 | height *= scale; |
jvanverth | 1723bfc | 2014-07-30 09:16:33 -0700 | [diff] [blame] | 394 | |
commit-bot@chromium.org | 64b08a1 | 2014-04-15 17:53:21 +0000 | [diff] [blame] | 395 | SkFixed tx = SkIntToFixed(glyph->fAtlasLocation.fX + SK_DistanceFieldInset); |
| 396 | SkFixed ty = SkIntToFixed(glyph->fAtlasLocation.fY + SK_DistanceFieldInset); |
| 397 | SkFixed tw = SkIntToFixed(glyph->fBounds.width() - 2*SK_DistanceFieldInset); |
| 398 | SkFixed th = SkIntToFixed(glyph->fBounds.height() - 2*SK_DistanceFieldInset); |
jvanverth@google.com | d830d13 | 2013-11-11 20:54:09 +0000 | [diff] [blame] | 399 | |
jvanverth | 1723bfc | 2014-07-30 09:16:33 -0700 | [diff] [blame] | 400 | SkRect r; |
jvanverth | 9bcd23b | 2014-08-01 14:05:19 -0700 | [diff] [blame] | 401 | r.fLeft = sx; |
| 402 | r.fTop = sy; |
| 403 | r.fRight = sx + width; |
| 404 | r.fBottom = sy + height; |
jvanverth | 1723bfc | 2014-07-30 09:16:33 -0700 | [diff] [blame] | 405 | |
| 406 | fVertexBounds.growToInclude(r); |
| 407 | |
jvanverth | feceba5 | 2014-07-25 19:03:34 -0700 | [diff] [blame] | 408 | size_t vertSize = fUseLCDText ? (2 * sizeof(SkPoint)) |
| 409 | : (2 * sizeof(SkPoint) + sizeof(GrColor)); |
jvanverth | 1723bfc | 2014-07-30 09:16:33 -0700 | [diff] [blame] | 410 | |
jvanverth | feceba5 | 2014-07-25 19:03:34 -0700 | [diff] [blame] | 411 | SkASSERT(vertSize == fDrawTarget->getDrawState().getVertexSize()); |
jvanverth | 1723bfc | 2014-07-30 09:16:33 -0700 | [diff] [blame] | 412 | |
jvanverth | f17bc6c | 2014-07-25 16:46:53 -0700 | [diff] [blame] | 413 | SkPoint* positions = reinterpret_cast<SkPoint*>( |
jvanverth | feceba5 | 2014-07-25 19:03:34 -0700 | [diff] [blame] | 414 | reinterpret_cast<intptr_t>(fVertices) + vertSize * fCurrVertex); |
jvanverth | 1723bfc | 2014-07-30 09:16:33 -0700 | [diff] [blame] | 415 | positions->setRectFan(r.fLeft, r.fTop, r.fRight, r.fBottom, vertSize); |
| 416 | |
jvanverth | feceba5 | 2014-07-25 19:03:34 -0700 | [diff] [blame] | 417 | // The texture coords are last in both the with and without color vertex layouts. |
jvanverth | f17bc6c | 2014-07-25 16:46:53 -0700 | [diff] [blame] | 418 | SkPoint* textureCoords = reinterpret_cast<SkPoint*>( |
jvanverth | feceba5 | 2014-07-25 19:03:34 -0700 | [diff] [blame] | 419 | reinterpret_cast<intptr_t>(positions) + vertSize - sizeof(SkPoint)); |
jvanverth | f17bc6c | 2014-07-25 16:46:53 -0700 | [diff] [blame] | 420 | textureCoords->setRectFan(SkFixedToFloat(texture->normalizeFixedX(tx)), |
jvanverth | feceba5 | 2014-07-25 19:03:34 -0700 | [diff] [blame] | 421 | SkFixedToFloat(texture->normalizeFixedY(ty)), |
| 422 | SkFixedToFloat(texture->normalizeFixedX(tx + tw)), |
| 423 | SkFixedToFloat(texture->normalizeFixedY(ty + th)), |
| 424 | vertSize); |
jvanverth | 9bcd23b | 2014-08-01 14:05:19 -0700 | [diff] [blame] | 425 | if (useColorVerts) { |
jvanverth | feceba5 | 2014-07-25 19:03:34 -0700 | [diff] [blame] | 426 | // color comes after position. |
| 427 | GrColor* colors = reinterpret_cast<GrColor*>(positions + 1); |
| 428 | for (int i = 0; i < 4; ++i) { |
| 429 | *colors = fPaint.getColor(); |
| 430 | colors = reinterpret_cast<GrColor*>(reinterpret_cast<intptr_t>(colors) + vertSize); |
| 431 | } |
| 432 | } |
jvanverth | 1723bfc | 2014-07-30 09:16:33 -0700 | [diff] [blame] | 433 | |
jvanverth@google.com | d830d13 | 2013-11-11 20:54:09 +0000 | [diff] [blame] | 434 | fCurrVertex += 4; |
| 435 | } |
commit-bot@chromium.org | 8128d8c | 2013-12-19 16:12:25 +0000 | [diff] [blame] | 436 | |
commit-bot@chromium.org | cbbc481 | 2014-01-30 22:05:47 +0000 | [diff] [blame] | 437 | inline void GrDistanceFieldTextContext::init(const GrPaint& paint, const SkPaint& skPaint) { |
| 438 | GrTextContext::init(paint, skPaint); |
| 439 | |
| 440 | fStrike = NULL; |
| 441 | |
commit-bot@chromium.org | cbbc481 | 2014-01-30 22:05:47 +0000 | [diff] [blame] | 442 | fCurrVertex = 0; |
| 443 | |
| 444 | fVertices = NULL; |
commit-bot@chromium.org | cbbc481 | 2014-01-30 22:05:47 +0000 | [diff] [blame] | 445 | |
commit-bot@chromium.org | dc5cd85 | 2014-04-02 19:24:32 +0000 | [diff] [blame] | 446 | if (fSkPaint.getTextSize() <= kSmallDFFontLimit) { |
| 447 | fTextRatio = fSkPaint.getTextSize()/kSmallDFFontSize; |
| 448 | fSkPaint.setTextSize(SkIntToScalar(kSmallDFFontSize)); |
| 449 | } else if (fSkPaint.getTextSize() <= kMediumDFFontLimit) { |
| 450 | fTextRatio = fSkPaint.getTextSize()/kMediumDFFontSize; |
| 451 | fSkPaint.setTextSize(SkIntToScalar(kMediumDFFontSize)); |
| 452 | } else { |
| 453 | fTextRatio = fSkPaint.getTextSize()/kLargeDFFontSize; |
| 454 | fSkPaint.setTextSize(SkIntToScalar(kLargeDFFontSize)); |
| 455 | } |
skia.committer@gmail.com | 4c18e9f | 2014-01-31 03:01:59 +0000 | [diff] [blame] | 456 | |
commit-bot@chromium.org | 609ced4 | 2014-04-03 18:25:48 +0000 | [diff] [blame] | 457 | fUseLCDText = fSkPaint.isLCDRenderText(); |
skia.committer@gmail.com | 221b911 | 2014-04-04 03:04:32 +0000 | [diff] [blame] | 458 | |
commit-bot@chromium.org | cbbc481 | 2014-01-30 22:05:47 +0000 | [diff] [blame] | 459 | fSkPaint.setLCDRenderText(false); |
| 460 | fSkPaint.setAutohinted(false); |
jvanverth | 2d2a68c | 2014-06-10 06:42:56 -0700 | [diff] [blame] | 461 | fSkPaint.setHinting(SkPaint::kNormal_Hinting); |
commit-bot@chromium.org | 0bed43c | 2014-03-14 21:22:38 +0000 | [diff] [blame] | 462 | fSkPaint.setSubpixelText(true); |
jvanverth | 2d2a68c | 2014-06-10 06:42:56 -0700 | [diff] [blame] | 463 | |
commit-bot@chromium.org | cbbc481 | 2014-01-30 22:05:47 +0000 | [diff] [blame] | 464 | } |
| 465 | |
| 466 | inline void GrDistanceFieldTextContext::finish() { |
jvanverth | feceba5 | 2014-07-25 19:03:34 -0700 | [diff] [blame] | 467 | this->flushGlyphs(); |
commit-bot@chromium.org | cbbc481 | 2014-01-30 22:05:47 +0000 | [diff] [blame] | 468 | |
| 469 | GrTextContext::finish(); |
| 470 | } |
| 471 | |
jvanverth | 2d2a68c | 2014-06-10 06:42:56 -0700 | [diff] [blame] | 472 | static void setup_gamma_texture(GrContext* context, const SkGlyphCache* cache, |
| 473 | const SkDeviceProperties& deviceProperties, |
| 474 | GrTexture** gammaTexture) { |
| 475 | if (NULL == *gammaTexture) { |
| 476 | int width, height; |
| 477 | size_t size; |
| 478 | |
| 479 | #ifdef SK_GAMMA_CONTRAST |
| 480 | SkScalar contrast = SK_GAMMA_CONTRAST; |
| 481 | #else |
| 482 | SkScalar contrast = 0.5f; |
| 483 | #endif |
| 484 | SkScalar paintGamma = deviceProperties.fGamma; |
| 485 | SkScalar deviceGamma = deviceProperties.fGamma; |
| 486 | |
| 487 | size = SkScalerContext::GetGammaLUTSize(contrast, paintGamma, deviceGamma, |
| 488 | &width, &height); |
| 489 | |
| 490 | SkAutoTArray<uint8_t> data((int)size); |
| 491 | SkScalerContext::GetGammaLUTData(contrast, paintGamma, deviceGamma, data.get()); |
| 492 | |
| 493 | // TODO: Update this to use the cache rather than directly creating a texture. |
| 494 | GrTextureDesc desc; |
| 495 | desc.fFlags = kDynamicUpdate_GrTextureFlagBit; |
| 496 | desc.fWidth = width; |
| 497 | desc.fHeight = height; |
| 498 | desc.fConfig = kAlpha_8_GrPixelConfig; |
| 499 | |
| 500 | *gammaTexture = context->getGpu()->createTexture(desc, NULL, 0); |
| 501 | if (NULL == *gammaTexture) { |
| 502 | return; |
| 503 | } |
| 504 | |
| 505 | context->writeTexturePixels(*gammaTexture, |
| 506 | 0, 0, width, height, |
| 507 | (*gammaTexture)->config(), data.get(), 0, |
| 508 | GrContext::kDontFlush_PixelOpsFlag); |
| 509 | } |
| 510 | } |
| 511 | |
commit-bot@chromium.org | cbbc481 | 2014-01-30 22:05:47 +0000 | [diff] [blame] | 512 | void GrDistanceFieldTextContext::drawText(const GrPaint& paint, const SkPaint& skPaint, |
| 513 | const char text[], size_t byteLength, |
commit-bot@chromium.org | e8612d9 | 2014-01-28 22:02:07 +0000 | [diff] [blame] | 514 | SkScalar x, SkScalar y) { |
commit-bot@chromium.org | 8128d8c | 2013-12-19 16:12:25 +0000 | [diff] [blame] | 515 | SkASSERT(byteLength == 0 || text != NULL); |
| 516 | |
commit-bot@chromium.org | e8612d9 | 2014-01-28 22:02:07 +0000 | [diff] [blame] | 517 | // nothing to draw or can't draw |
| 518 | if (text == NULL || byteLength == 0 /* no raster clip? || fRC->isEmpty()*/ |
| 519 | || fSkPaint.getRasterizer()) { |
commit-bot@chromium.org | 8128d8c | 2013-12-19 16:12:25 +0000 | [diff] [blame] | 520 | return; |
| 521 | } |
skia.committer@gmail.com | e5d7015 | 2014-01-29 07:01:48 +0000 | [diff] [blame] | 522 | |
commit-bot@chromium.org | cbbc481 | 2014-01-30 22:05:47 +0000 | [diff] [blame] | 523 | this->init(paint, skPaint); |
| 524 | |
commit-bot@chromium.org | 8128d8c | 2013-12-19 16:12:25 +0000 | [diff] [blame] | 525 | SkScalar sizeRatio = fTextRatio; |
| 526 | |
| 527 | SkDrawCacheProc glyphCacheProc = fSkPaint.getDrawCacheProc(); |
| 528 | |
jvanverth | 2d2a68c | 2014-06-10 06:42:56 -0700 | [diff] [blame] | 529 | SkAutoGlyphCacheNoGamma autoCache(fSkPaint, &fDeviceProperties, NULL); |
| 530 | SkGlyphCache* cache = autoCache.getCache(); |
| 531 | GrFontScaler* fontScaler = GetGrFontScaler(cache); |
| 532 | |
| 533 | setup_gamma_texture(fContext, cache, fDeviceProperties, &fGammaTexture); |
skia.committer@gmail.com | e5d7015 | 2014-01-29 07:01:48 +0000 | [diff] [blame] | 534 | |
commit-bot@chromium.org | 8128d8c | 2013-12-19 16:12:25 +0000 | [diff] [blame] | 535 | // need to measure first |
| 536 | // TODO - generate positions and pre-load cache as well? |
| 537 | const char* stop = text + byteLength; |
| 538 | if (fSkPaint.getTextAlign() != SkPaint::kLeft_Align) { |
| 539 | SkFixed stopX = 0; |
| 540 | SkFixed stopY = 0; |
| 541 | |
| 542 | const char* textPtr = text; |
| 543 | while (textPtr < stop) { |
| 544 | // don't need x, y here, since all subpixel variants will have the |
| 545 | // same advance |
| 546 | const SkGlyph& glyph = glyphCacheProc(cache, &textPtr, 0, 0); |
| 547 | |
| 548 | stopX += glyph.fAdvanceX; |
| 549 | stopY += glyph.fAdvanceY; |
| 550 | } |
| 551 | SkASSERT(textPtr == stop); |
| 552 | |
| 553 | SkScalar alignX = SkFixedToScalar(stopX)*sizeRatio; |
| 554 | SkScalar alignY = SkFixedToScalar(stopY)*sizeRatio; |
| 555 | |
| 556 | if (fSkPaint.getTextAlign() == SkPaint::kCenter_Align) { |
| 557 | alignX = SkScalarHalf(alignX); |
| 558 | alignY = SkScalarHalf(alignY); |
| 559 | } |
| 560 | |
| 561 | x -= alignX; |
| 562 | y -= alignY; |
| 563 | } |
| 564 | |
commit-bot@chromium.org | 5408f8f | 2014-05-21 19:44:24 +0000 | [diff] [blame] | 565 | SkFixed fx = SkScalarToFixed(x); |
| 566 | SkFixed fy = SkScalarToFixed(y); |
commit-bot@chromium.org | 8128d8c | 2013-12-19 16:12:25 +0000 | [diff] [blame] | 567 | SkFixed fixedScale = SkScalarToFixed(sizeRatio); |
| 568 | while (text < stop) { |
commit-bot@chromium.org | a9dae71 | 2014-03-24 18:34:04 +0000 | [diff] [blame] | 569 | const SkGlyph& glyph = glyphCacheProc(cache, &text, 0, 0); |
commit-bot@chromium.org | 8128d8c | 2013-12-19 16:12:25 +0000 | [diff] [blame] | 570 | |
| 571 | if (glyph.fWidth) { |
| 572 | this->drawPackedGlyph(GrGlyph::Pack(glyph.getGlyphID(), |
| 573 | glyph.getSubXFixed(), |
| 574 | glyph.getSubYFixed()), |
commit-bot@chromium.org | 5408f8f | 2014-05-21 19:44:24 +0000 | [diff] [blame] | 575 | fx, |
| 576 | fy, |
commit-bot@chromium.org | 8128d8c | 2013-12-19 16:12:25 +0000 | [diff] [blame] | 577 | fontScaler); |
| 578 | } |
| 579 | |
| 580 | fx += SkFixedMul_portable(glyph.fAdvanceX, fixedScale); |
| 581 | fy += SkFixedMul_portable(glyph.fAdvanceY, fixedScale); |
| 582 | } |
commit-bot@chromium.org | cbbc481 | 2014-01-30 22:05:47 +0000 | [diff] [blame] | 583 | |
| 584 | this->finish(); |
commit-bot@chromium.org | 8128d8c | 2013-12-19 16:12:25 +0000 | [diff] [blame] | 585 | } |
| 586 | |
commit-bot@chromium.org | cbbc481 | 2014-01-30 22:05:47 +0000 | [diff] [blame] | 587 | void GrDistanceFieldTextContext::drawPosText(const GrPaint& paint, const SkPaint& skPaint, |
| 588 | const char text[], size_t byteLength, |
commit-bot@chromium.org | 8128d8c | 2013-12-19 16:12:25 +0000 | [diff] [blame] | 589 | const SkScalar pos[], SkScalar constY, |
commit-bot@chromium.org | e8612d9 | 2014-01-28 22:02:07 +0000 | [diff] [blame] | 590 | int scalarsPerPosition) { |
commit-bot@chromium.org | 8128d8c | 2013-12-19 16:12:25 +0000 | [diff] [blame] | 591 | |
| 592 | SkASSERT(byteLength == 0 || text != NULL); |
| 593 | SkASSERT(1 == scalarsPerPosition || 2 == scalarsPerPosition); |
| 594 | |
| 595 | // nothing to draw |
commit-bot@chromium.org | cbbc481 | 2014-01-30 22:05:47 +0000 | [diff] [blame] | 596 | if (text == NULL || byteLength == 0 /* no raster clip? || fRC->isEmpty()*/) { |
commit-bot@chromium.org | 8128d8c | 2013-12-19 16:12:25 +0000 | [diff] [blame] | 597 | return; |
| 598 | } |
| 599 | |
commit-bot@chromium.org | cbbc481 | 2014-01-30 22:05:47 +0000 | [diff] [blame] | 600 | this->init(paint, skPaint); |
| 601 | |
commit-bot@chromium.org | 8128d8c | 2013-12-19 16:12:25 +0000 | [diff] [blame] | 602 | SkDrawCacheProc glyphCacheProc = fSkPaint.getDrawCacheProc(); |
| 603 | |
jvanverth | 2d2a68c | 2014-06-10 06:42:56 -0700 | [diff] [blame] | 604 | SkAutoGlyphCacheNoGamma autoCache(fSkPaint, &fDeviceProperties, NULL); |
| 605 | SkGlyphCache* cache = autoCache.getCache(); |
| 606 | GrFontScaler* fontScaler = GetGrFontScaler(cache); |
| 607 | |
| 608 | setup_gamma_texture(fContext, cache, fDeviceProperties, &fGammaTexture); |
skia.committer@gmail.com | e5d7015 | 2014-01-29 07:01:48 +0000 | [diff] [blame] | 609 | |
commit-bot@chromium.org | 8128d8c | 2013-12-19 16:12:25 +0000 | [diff] [blame] | 610 | const char* stop = text + byteLength; |
| 611 | |
| 612 | if (SkPaint::kLeft_Align == fSkPaint.getTextAlign()) { |
| 613 | while (text < stop) { |
| 614 | // the last 2 parameters are ignored |
| 615 | const SkGlyph& glyph = glyphCacheProc(cache, &text, 0, 0); |
| 616 | |
| 617 | if (glyph.fWidth) { |
| 618 | SkScalar x = pos[0]; |
| 619 | SkScalar y = scalarsPerPosition == 1 ? constY : pos[1]; |
| 620 | |
| 621 | this->drawPackedGlyph(GrGlyph::Pack(glyph.getGlyphID(), |
| 622 | glyph.getSubXFixed(), |
| 623 | glyph.getSubYFixed()), |
commit-bot@chromium.org | 5408f8f | 2014-05-21 19:44:24 +0000 | [diff] [blame] | 624 | SkScalarToFixed(x), |
| 625 | SkScalarToFixed(y), |
commit-bot@chromium.org | 8128d8c | 2013-12-19 16:12:25 +0000 | [diff] [blame] | 626 | fontScaler); |
| 627 | } |
| 628 | pos += scalarsPerPosition; |
| 629 | } |
| 630 | } else { |
| 631 | int alignShift = SkPaint::kCenter_Align == fSkPaint.getTextAlign() ? 1 : 0; |
| 632 | while (text < stop) { |
| 633 | // the last 2 parameters are ignored |
| 634 | const SkGlyph& glyph = glyphCacheProc(cache, &text, 0, 0); |
| 635 | |
| 636 | if (glyph.fWidth) { |
| 637 | SkScalar x = pos[0]; |
| 638 | SkScalar y = scalarsPerPosition == 1 ? constY : pos[1]; |
skia.committer@gmail.com | 22e9672 | 2013-12-20 07:01:36 +0000 | [diff] [blame] | 639 | |
commit-bot@chromium.org | 8128d8c | 2013-12-19 16:12:25 +0000 | [diff] [blame] | 640 | this->drawPackedGlyph(GrGlyph::Pack(glyph.getGlyphID(), |
| 641 | glyph.getSubXFixed(), |
| 642 | glyph.getSubYFixed()), |
commit-bot@chromium.org | 5408f8f | 2014-05-21 19:44:24 +0000 | [diff] [blame] | 643 | SkScalarToFixed(x) - (glyph.fAdvanceX >> alignShift), |
| 644 | SkScalarToFixed(y) - (glyph.fAdvanceY >> alignShift), |
commit-bot@chromium.org | 8128d8c | 2013-12-19 16:12:25 +0000 | [diff] [blame] | 645 | fontScaler); |
| 646 | } |
| 647 | pos += scalarsPerPosition; |
| 648 | } |
| 649 | } |
commit-bot@chromium.org | cbbc481 | 2014-01-30 22:05:47 +0000 | [diff] [blame] | 650 | |
| 651 | this->finish(); |
commit-bot@chromium.org | 8128d8c | 2013-12-19 16:12:25 +0000 | [diff] [blame] | 652 | } |