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