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