reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1 | /* |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 2 | * Copyright 2010 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. |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 6 | */ |
| 7 | |
tomhudson@google.com | 375ff85 | 2012-06-29 18:37:57 +0000 | [diff] [blame] | 8 | #include "GrTextContext.h" |
robertphillips | ccb1b57 | 2015-05-27 11:02:55 -0700 | [diff] [blame] | 9 | #include "GrBlurUtils.h" |
commit-bot@chromium.org | e8612d9 | 2014-01-28 22:02:07 +0000 | [diff] [blame] | 10 | #include "GrContext.h" |
robertphillips | ccb1b57 | 2015-05-27 11:02:55 -0700 | [diff] [blame] | 11 | #include "GrDrawContext.h" |
joshualitt | 570d2f8 | 2015-02-25 13:19:48 -0800 | [diff] [blame] | 12 | #include "GrFontScaler.h" |
commit-bot@chromium.org | e8612d9 | 2014-01-28 22:02:07 +0000 | [diff] [blame] | 13 | |
| 14 | #include "SkAutoKern.h" |
joshualitt | 9c32818 | 2015-03-23 08:13:04 -0700 | [diff] [blame] | 15 | #include "SkDrawFilter.h" |
joshualitt | 6e8cd96 | 2015-03-20 10:30:14 -0700 | [diff] [blame] | 16 | #include "SkDrawProcs.h" |
commit-bot@chromium.org | e8612d9 | 2014-01-28 22:02:07 +0000 | [diff] [blame] | 17 | #include "SkGlyphCache.h" |
joshualitt | 6e8cd96 | 2015-03-20 10:30:14 -0700 | [diff] [blame] | 18 | #include "SkGpuDevice.h" |
joshualitt | 9c32818 | 2015-03-23 08:13:04 -0700 | [diff] [blame] | 19 | #include "SkTextBlob.h" |
joshualitt | 6e8cd96 | 2015-03-20 10:30:14 -0700 | [diff] [blame] | 20 | #include "SkTextMapStateProc.h" |
| 21 | #include "SkTextToPathIter.h" |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 22 | |
robertphillips | ccb1b57 | 2015-05-27 11:02:55 -0700 | [diff] [blame] | 23 | GrTextContext::GrTextContext(GrContext* context, const SkDeviceProperties& properties) |
joshualitt | 6e8cd96 | 2015-03-20 10:30:14 -0700 | [diff] [blame] | 24 | : fFallbackTextContext(NULL) |
| 25 | , fContext(context) |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 26 | , fDeviceProperties(properties) { |
commit-bot@chromium.org | cbbc481 | 2014-01-30 22:05:47 +0000 | [diff] [blame] | 27 | } |
tomhudson@google.com | 375ff85 | 2012-06-29 18:37:57 +0000 | [diff] [blame] | 28 | |
jvanverth | 8c27a18 | 2014-10-14 08:45:50 -0700 | [diff] [blame] | 29 | GrTextContext::~GrTextContext() { |
| 30 | SkDELETE(fFallbackTextContext); |
| 31 | } |
| 32 | |
joshualitt | 570d2f8 | 2015-02-25 13:19:48 -0800 | [diff] [blame] | 33 | void GrTextContext::init(GrRenderTarget* rt, const GrClip& clip, const GrPaint& grPaint, |
joshualitt | 6e8cd96 | 2015-03-20 10:30:14 -0700 | [diff] [blame] | 34 | const SkPaint& skPaint, const SkIRect& regionClipBounds) { |
joshualitt | 570d2f8 | 2015-02-25 13:19:48 -0800 | [diff] [blame] | 35 | fClip = clip; |
robertphillips@google.com | beb1af7 | 2012-07-26 18:52:16 +0000 | [diff] [blame] | 36 | |
joshualitt | 25d9c15 | 2015-02-18 12:29:52 -0800 | [diff] [blame] | 37 | fRenderTarget.reset(SkRef(rt)); |
| 38 | |
joshualitt | 6e8cd96 | 2015-03-20 10:30:14 -0700 | [diff] [blame] | 39 | fRegionClipBounds = regionClipBounds; |
joshualitt | 570d2f8 | 2015-02-25 13:19:48 -0800 | [diff] [blame] | 40 | fClip.getConservativeBounds(fRenderTarget->width(), fRenderTarget->height(), &fClipRect); |
robertphillips@google.com | beb1af7 | 2012-07-26 18:52:16 +0000 | [diff] [blame] | 41 | |
commit-bot@chromium.org | cbbc481 | 2014-01-30 22:05:47 +0000 | [diff] [blame] | 42 | fPaint = grPaint; |
| 43 | fSkPaint = skPaint; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 44 | } |
commit-bot@chromium.org | e8612d9 | 2014-01-28 22:02:07 +0000 | [diff] [blame] | 45 | |
joshualitt | 6e8cd96 | 2015-03-20 10:30:14 -0700 | [diff] [blame] | 46 | void GrTextContext::drawText(GrRenderTarget* rt, const GrClip& clip, const GrPaint& paint, |
joshualitt | 570d2f8 | 2015-02-25 13:19:48 -0800 | [diff] [blame] | 47 | const SkPaint& skPaint, const SkMatrix& viewMatrix, |
jvanverth | 8c27a18 | 2014-10-14 08:45:50 -0700 | [diff] [blame] | 48 | const char text[], size_t byteLength, |
joshualitt | 6e8cd96 | 2015-03-20 10:30:14 -0700 | [diff] [blame] | 49 | SkScalar x, SkScalar y, const SkIRect& clipBounds) { |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 50 | if (fContext->abandoned()) { |
joshualitt | 6e8cd96 | 2015-03-20 10:30:14 -0700 | [diff] [blame] | 51 | return; |
joshualitt | 5f5a8d7 | 2015-02-25 14:09:45 -0800 | [diff] [blame] | 52 | } |
jvanverth | 8c27a18 | 2014-10-14 08:45:50 -0700 | [diff] [blame] | 53 | |
robertphillips | ccb1b57 | 2015-05-27 11:02:55 -0700 | [diff] [blame] | 54 | GrDrawContext* drawContext = fContext->drawContext(); |
| 55 | if (!drawContext) { |
| 56 | return; |
| 57 | } |
| 58 | |
jvanverth | aab626c | 2014-10-16 08:04:39 -0700 | [diff] [blame] | 59 | GrTextContext* textContext = this; |
| 60 | do { |
cdalton | e68f736 | 2015-03-25 14:02:37 -0700 | [diff] [blame] | 61 | if (textContext->canDraw(rt, clip, paint, skPaint, viewMatrix)) { |
robertphillips | ccb1b57 | 2015-05-27 11:02:55 -0700 | [diff] [blame] | 62 | textContext->onDrawText(drawContext, rt, clip, paint, skPaint, viewMatrix, |
| 63 | text, byteLength, x, y, clipBounds); |
joshualitt | 6e8cd96 | 2015-03-20 10:30:14 -0700 | [diff] [blame] | 64 | return; |
jvanverth | aab626c | 2014-10-16 08:04:39 -0700 | [diff] [blame] | 65 | } |
| 66 | textContext = textContext->fFallbackTextContext; |
| 67 | } while (textContext); |
jvanverth | 8c27a18 | 2014-10-14 08:45:50 -0700 | [diff] [blame] | 68 | |
joshualitt | 6e8cd96 | 2015-03-20 10:30:14 -0700 | [diff] [blame] | 69 | // fall back to drawing as a path |
robertphillips | ccb1b57 | 2015-05-27 11:02:55 -0700 | [diff] [blame] | 70 | this->drawTextAsPath(drawContext, rt, clip, skPaint, viewMatrix, |
| 71 | text, byteLength, x, y, clipBounds); |
jvanverth | 8c27a18 | 2014-10-14 08:45:50 -0700 | [diff] [blame] | 72 | } |
| 73 | |
joshualitt | 6e8cd96 | 2015-03-20 10:30:14 -0700 | [diff] [blame] | 74 | void GrTextContext::drawPosText(GrRenderTarget* rt, const GrClip& clip, const GrPaint& paint, |
joshualitt | 570d2f8 | 2015-02-25 13:19:48 -0800 | [diff] [blame] | 75 | const SkPaint& skPaint, const SkMatrix& viewMatrix, |
jvanverth | 8c27a18 | 2014-10-14 08:45:50 -0700 | [diff] [blame] | 76 | const char text[], size_t byteLength, |
| 77 | const SkScalar pos[], int scalarsPerPosition, |
joshualitt | 6e8cd96 | 2015-03-20 10:30:14 -0700 | [diff] [blame] | 78 | const SkPoint& offset, const SkIRect& clipBounds) { |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 79 | if (fContext->abandoned()) { |
joshualitt | 6e8cd96 | 2015-03-20 10:30:14 -0700 | [diff] [blame] | 80 | return; |
joshualitt | 5f5a8d7 | 2015-02-25 14:09:45 -0800 | [diff] [blame] | 81 | } |
jvanverth | 8c27a18 | 2014-10-14 08:45:50 -0700 | [diff] [blame] | 82 | |
robertphillips | ccb1b57 | 2015-05-27 11:02:55 -0700 | [diff] [blame] | 83 | GrDrawContext* drawContext = fContext->drawContext(); |
| 84 | if (!drawContext) { |
| 85 | return; |
| 86 | } |
| 87 | |
jvanverth | 8c27a18 | 2014-10-14 08:45:50 -0700 | [diff] [blame] | 88 | GrTextContext* textContext = this; |
| 89 | do { |
cdalton | e68f736 | 2015-03-25 14:02:37 -0700 | [diff] [blame] | 90 | if (textContext->canDraw(rt, clip, paint, skPaint, viewMatrix)) { |
robertphillips | ccb1b57 | 2015-05-27 11:02:55 -0700 | [diff] [blame] | 91 | textContext->onDrawPosText(drawContext, rt, clip, paint, skPaint, viewMatrix, |
| 92 | text, byteLength, pos, |
joshualitt | 6e8cd96 | 2015-03-20 10:30:14 -0700 | [diff] [blame] | 93 | scalarsPerPosition, offset, clipBounds); |
| 94 | return; |
jvanverth | 8c27a18 | 2014-10-14 08:45:50 -0700 | [diff] [blame] | 95 | } |
| 96 | textContext = textContext->fFallbackTextContext; |
| 97 | } while (textContext); |
| 98 | |
joshualitt | 6e8cd96 | 2015-03-20 10:30:14 -0700 | [diff] [blame] | 99 | // fall back to drawing as a path |
robertphillips | ccb1b57 | 2015-05-27 11:02:55 -0700 | [diff] [blame] | 100 | this->drawPosTextAsPath(drawContext, rt, clip, skPaint, viewMatrix, text, byteLength, pos, |
| 101 | scalarsPerPosition, offset, clipBounds); |
jvanverth | 8c27a18 | 2014-10-14 08:45:50 -0700 | [diff] [blame] | 102 | } |
| 103 | |
robertphillips | 9c240a1 | 2015-05-28 07:45:59 -0700 | [diff] [blame^] | 104 | bool GrTextContext::ShouldDisableLCD(const SkPaint& paint) { |
| 105 | if (paint.getShader() || |
| 106 | !SkXfermode::IsMode(paint.getXfermode(), SkXfermode::kSrcOver_Mode) || |
| 107 | paint.getMaskFilter() || |
| 108 | paint.getRasterizer() || |
| 109 | paint.getColorFilter() || |
| 110 | paint.getPathEffect() || |
| 111 | paint.isFakeBoldText() || |
| 112 | paint.getStyle() != SkPaint::kFill_Style) |
| 113 | { |
| 114 | return true; |
| 115 | } |
| 116 | return false; |
| 117 | } |
| 118 | |
| 119 | uint32_t GrTextContext::FilterTextFlags(const SkDeviceProperties& devProps, const SkPaint& paint) { |
| 120 | uint32_t flags = paint.getFlags(); |
| 121 | |
| 122 | if (!paint.isLCDRenderText() || !paint.isAntiAlias()) { |
| 123 | return flags; |
| 124 | } |
| 125 | |
| 126 | if (kUnknown_SkPixelGeometry == devProps.pixelGeometry() || ShouldDisableLCD(paint)) { |
| 127 | flags &= ~SkPaint::kLCDRenderText_Flag; |
| 128 | flags |= SkPaint::kGenA8FromLCD_Flag; |
| 129 | } |
| 130 | |
| 131 | return flags; |
| 132 | } |
| 133 | |
| 134 | void GrTextContext::drawTextBlob(GrRenderTarget* rt, |
robertphillips | ccb1b57 | 2015-05-27 11:02:55 -0700 | [diff] [blame] | 135 | const GrClip& clip, const SkPaint& skPaint, |
joshualitt | 9c32818 | 2015-03-23 08:13:04 -0700 | [diff] [blame] | 136 | const SkMatrix& viewMatrix, const SkTextBlob* blob, |
| 137 | SkScalar x, SkScalar y, |
| 138 | SkDrawFilter* drawFilter, const SkIRect& clipBounds) { |
cdalton | e68f736 | 2015-03-25 14:02:37 -0700 | [diff] [blame] | 139 | SkPaint runPaint = skPaint; |
joshualitt | 9c32818 | 2015-03-23 08:13:04 -0700 | [diff] [blame] | 140 | |
cdalton | e68f736 | 2015-03-25 14:02:37 -0700 | [diff] [blame] | 141 | SkTextBlob::RunIterator it(blob); |
| 142 | for (;!it.done(); it.next()) { |
| 143 | size_t textLen = it.glyphCount() * sizeof(uint16_t); |
| 144 | const SkPoint& offset = it.offset(); |
| 145 | // applyFontToPaint() always overwrites the exact same attributes, |
| 146 | // so it is safe to not re-seed the paint for this reason. |
| 147 | it.applyFontToPaint(&runPaint); |
| 148 | |
| 149 | if (drawFilter && !drawFilter->filter(&runPaint, SkDrawFilter::kText_Type)) { |
| 150 | // A false return from filter() means we should abort the current draw. |
| 151 | runPaint = skPaint; |
| 152 | continue; |
joshualitt | 9c32818 | 2015-03-23 08:13:04 -0700 | [diff] [blame] | 153 | } |
cdalton | e68f736 | 2015-03-25 14:02:37 -0700 | [diff] [blame] | 154 | |
robertphillips | 9c240a1 | 2015-05-28 07:45:59 -0700 | [diff] [blame^] | 155 | runPaint.setFlags(FilterTextFlags(fDeviceProperties, runPaint)); |
cdalton | e68f736 | 2015-03-25 14:02:37 -0700 | [diff] [blame] | 156 | |
| 157 | GrPaint grPaint; |
bsalomon | bed83a6 | 2015-04-15 14:18:34 -0700 | [diff] [blame] | 158 | if (!SkPaint2GrPaint(fContext, fRenderTarget, runPaint, viewMatrix, true, &grPaint)) { |
| 159 | return; |
| 160 | } |
cdalton | e68f736 | 2015-03-25 14:02:37 -0700 | [diff] [blame] | 161 | |
| 162 | switch (it.positioning()) { |
| 163 | case SkTextBlob::kDefault_Positioning: |
| 164 | this->drawText(rt, clip, grPaint, runPaint, viewMatrix, (const char *)it.glyphs(), |
| 165 | textLen, x + offset.x(), y + offset.y(), clipBounds); |
| 166 | break; |
| 167 | case SkTextBlob::kHorizontal_Positioning: |
| 168 | this->drawPosText(rt, clip, grPaint, runPaint, viewMatrix, (const char*)it.glyphs(), |
| 169 | textLen, it.pos(), 1, SkPoint::Make(x, y + offset.y()), clipBounds); |
| 170 | break; |
| 171 | case SkTextBlob::kFull_Positioning: |
| 172 | this->drawPosText(rt, clip, grPaint, runPaint, viewMatrix, (const char*)it.glyphs(), |
| 173 | textLen, it.pos(), 2, SkPoint::Make(x, y), clipBounds); |
| 174 | break; |
| 175 | default: |
| 176 | SkFAIL("unhandled positioning mode"); |
| 177 | } |
| 178 | |
| 179 | if (drawFilter) { |
| 180 | // A draw filter may change the paint arbitrarily, so we must re-seed in this case. |
| 181 | runPaint = skPaint; |
| 182 | } |
| 183 | } |
joshualitt | 9c32818 | 2015-03-23 08:13:04 -0700 | [diff] [blame] | 184 | } |
| 185 | |
robertphillips | ccb1b57 | 2015-05-27 11:02:55 -0700 | [diff] [blame] | 186 | void GrTextContext::drawTextAsPath(GrDrawContext* drawContext, GrRenderTarget* rt, |
| 187 | const GrClip& clip, |
| 188 | const SkPaint& skPaint, const SkMatrix& viewMatrix, |
joshualitt | 6e8cd96 | 2015-03-20 10:30:14 -0700 | [diff] [blame] | 189 | const char text[], size_t byteLength, SkScalar x, SkScalar y, |
| 190 | const SkIRect& clipBounds) { |
| 191 | SkTextToPathIter iter(text, byteLength, skPaint, true); |
| 192 | |
| 193 | SkMatrix matrix; |
| 194 | matrix.setScale(iter.getPathScale(), iter.getPathScale()); |
| 195 | matrix.postTranslate(x, y); |
| 196 | |
| 197 | const SkPath* iterPath; |
| 198 | SkScalar xpos, prevXPos = 0; |
| 199 | |
| 200 | while (iter.next(&iterPath, &xpos)) { |
| 201 | matrix.postTranslate(xpos - prevXPos, 0); |
| 202 | if (iterPath) { |
| 203 | const SkPaint& pnt = iter.getPaint(); |
robertphillips | ccb1b57 | 2015-05-27 11:02:55 -0700 | [diff] [blame] | 204 | GrBlurUtils::drawPathWithMaskFilter(fContext, drawContext, rt, clip, *iterPath, |
| 205 | pnt, viewMatrix, &matrix, clipBounds, false); |
joshualitt | 6e8cd96 | 2015-03-20 10:30:14 -0700 | [diff] [blame] | 206 | } |
| 207 | prevXPos = xpos; |
| 208 | } |
| 209 | } |
| 210 | |
robertphillips | ccb1b57 | 2015-05-27 11:02:55 -0700 | [diff] [blame] | 211 | void GrTextContext::drawPosTextAsPath(GrDrawContext* drawContext, GrRenderTarget* rt, |
| 212 | const GrClip& clip, |
| 213 | const SkPaint& origPaint, const SkMatrix& viewMatrix, |
joshualitt | 6e8cd96 | 2015-03-20 10:30:14 -0700 | [diff] [blame] | 214 | const char text[], size_t byteLength, |
| 215 | const SkScalar pos[], int scalarsPerPosition, |
| 216 | const SkPoint& offset, const SkIRect& clipBounds) { |
| 217 | // setup our std paint, in hopes of getting hits in the cache |
| 218 | SkPaint paint(origPaint); |
| 219 | SkScalar matrixScale = paint.setupForAsPaths(); |
| 220 | |
| 221 | SkMatrix matrix; |
| 222 | matrix.setScale(matrixScale, matrixScale); |
| 223 | |
| 224 | // Temporarily jam in kFill, so we only ever ask for the raw outline from the cache. |
| 225 | paint.setStyle(SkPaint::kFill_Style); |
| 226 | paint.setPathEffect(NULL); |
| 227 | |
| 228 | SkDrawCacheProc glyphCacheProc = paint.getDrawCacheProc(); |
| 229 | SkAutoGlyphCache autoCache(paint, NULL, NULL); |
| 230 | SkGlyphCache* cache = autoCache.getCache(); |
| 231 | |
| 232 | const char* stop = text + byteLength; |
| 233 | SkTextAlignProc alignProc(paint.getTextAlign()); |
| 234 | SkTextMapStateProc tmsProc(SkMatrix::I(), offset, scalarsPerPosition); |
| 235 | |
| 236 | // Now restore the original settings, so we "draw" with whatever style/stroking. |
| 237 | paint.setStyle(origPaint.getStyle()); |
| 238 | paint.setPathEffect(origPaint.getPathEffect()); |
| 239 | |
| 240 | while (text < stop) { |
| 241 | const SkGlyph& glyph = glyphCacheProc(cache, &text, 0, 0); |
| 242 | if (glyph.fWidth) { |
| 243 | const SkPath* path = cache->findPath(glyph); |
| 244 | if (path) { |
| 245 | SkPoint tmsLoc; |
| 246 | tmsProc(pos, &tmsLoc); |
| 247 | SkPoint loc; |
| 248 | alignProc(tmsLoc, glyph, &loc); |
| 249 | |
| 250 | matrix[SkMatrix::kMTransX] = loc.fX; |
| 251 | matrix[SkMatrix::kMTransY] = loc.fY; |
robertphillips | ccb1b57 | 2015-05-27 11:02:55 -0700 | [diff] [blame] | 252 | GrBlurUtils::drawPathWithMaskFilter(fContext, drawContext, rt, clip, *path, paint, |
| 253 | viewMatrix, &matrix, clipBounds, false); |
joshualitt | 6e8cd96 | 2015-03-20 10:30:14 -0700 | [diff] [blame] | 254 | } |
| 255 | } |
| 256 | pos += scalarsPerPosition; |
| 257 | } |
| 258 | } |
jvanverth | 8c27a18 | 2014-10-14 08:45:50 -0700 | [diff] [blame] | 259 | |
commit-bot@chromium.org | e8612d9 | 2014-01-28 22:02:07 +0000 | [diff] [blame] | 260 | //*** change to output positions? |
jvanverth | 73f1053 | 2014-10-23 11:57:12 -0700 | [diff] [blame] | 261 | int GrTextContext::MeasureText(SkGlyphCache* cache, SkDrawCacheProc glyphCacheProc, |
commit-bot@chromium.org | e8612d9 | 2014-01-28 22:02:07 +0000 | [diff] [blame] | 262 | const char text[], size_t byteLength, SkVector* stopVector) { |
| 263 | SkFixed x = 0, y = 0; |
| 264 | const char* stop = text + byteLength; |
skia.committer@gmail.com | e5d7015 | 2014-01-29 07:01:48 +0000 | [diff] [blame] | 265 | |
commit-bot@chromium.org | e8612d9 | 2014-01-28 22:02:07 +0000 | [diff] [blame] | 266 | SkAutoKern autokern; |
skia.committer@gmail.com | e5d7015 | 2014-01-29 07:01:48 +0000 | [diff] [blame] | 267 | |
jvanverth | 73f1053 | 2014-10-23 11:57:12 -0700 | [diff] [blame] | 268 | int numGlyphs = 0; |
commit-bot@chromium.org | e8612d9 | 2014-01-28 22:02:07 +0000 | [diff] [blame] | 269 | while (text < stop) { |
| 270 | // don't need x, y here, since all subpixel variants will have the |
| 271 | // same advance |
| 272 | const SkGlyph& glyph = glyphCacheProc(cache, &text, 0, 0); |
skia.committer@gmail.com | e5d7015 | 2014-01-29 07:01:48 +0000 | [diff] [blame] | 273 | |
commit-bot@chromium.org | e8612d9 | 2014-01-28 22:02:07 +0000 | [diff] [blame] | 274 | x += autokern.adjust(glyph) + glyph.fAdvanceX; |
| 275 | y += glyph.fAdvanceY; |
jvanverth | 73f1053 | 2014-10-23 11:57:12 -0700 | [diff] [blame] | 276 | ++numGlyphs; |
commit-bot@chromium.org | e8612d9 | 2014-01-28 22:02:07 +0000 | [diff] [blame] | 277 | } |
| 278 | stopVector->set(SkFixedToScalar(x), SkFixedToScalar(y)); |
skia.committer@gmail.com | e5d7015 | 2014-01-29 07:01:48 +0000 | [diff] [blame] | 279 | |
commit-bot@chromium.org | e8612d9 | 2014-01-28 22:02:07 +0000 | [diff] [blame] | 280 | SkASSERT(text == stop); |
jvanverth | 73f1053 | 2014-10-23 11:57:12 -0700 | [diff] [blame] | 281 | |
| 282 | return numGlyphs; |
commit-bot@chromium.org | e8612d9 | 2014-01-28 22:02:07 +0000 | [diff] [blame] | 283 | } |
| 284 | |
| 285 | static void GlyphCacheAuxProc(void* data) { |
| 286 | GrFontScaler* scaler = (GrFontScaler*)data; |
| 287 | SkSafeUnref(scaler); |
| 288 | } |
| 289 | |
| 290 | GrFontScaler* GrTextContext::GetGrFontScaler(SkGlyphCache* cache) { |
| 291 | void* auxData; |
| 292 | GrFontScaler* scaler = NULL; |
skia.committer@gmail.com | e5d7015 | 2014-01-29 07:01:48 +0000 | [diff] [blame] | 293 | |
commit-bot@chromium.org | e8612d9 | 2014-01-28 22:02:07 +0000 | [diff] [blame] | 294 | if (cache->getAuxProcData(GlyphCacheAuxProc, &auxData)) { |
| 295 | scaler = (GrFontScaler*)auxData; |
| 296 | } |
| 297 | if (NULL == scaler) { |
jvanverth | 733f5f5 | 2014-07-11 19:45:16 -0700 | [diff] [blame] | 298 | scaler = SkNEW_ARGS(GrFontScaler, (cache)); |
commit-bot@chromium.org | e8612d9 | 2014-01-28 22:02:07 +0000 | [diff] [blame] | 299 | cache->setAuxProc(GlyphCacheAuxProc, scaler); |
| 300 | } |
skia.committer@gmail.com | e5d7015 | 2014-01-29 07:01:48 +0000 | [diff] [blame] | 301 | |
commit-bot@chromium.org | e8612d9 | 2014-01-28 22:02:07 +0000 | [diff] [blame] | 302 | return scaler; |
| 303 | } |