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