epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2006 The Android Open Source Project |
| 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 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 8 | |
| 9 | #include "SkScalerContext.h" |
robertphillips | c5035e7 | 2016-03-17 06:58:39 -0700 | [diff] [blame] | 10 | #include "SkAutoPixmapStorage.h" |
agl@chromium.org | 309485b | 2009-07-21 17:41:32 +0000 | [diff] [blame] | 11 | #include "SkColorPriv.h" |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 12 | #include "SkDescriptor.h" |
| 13 | #include "SkDraw.h" |
bungeman@google.com | bbe5013 | 2012-07-24 20:33:21 +0000 | [diff] [blame] | 14 | #include "SkGlyph.h" |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 15 | #include "SkMaskFilter.h" |
bungeman@google.com | 97efada | 2012-07-30 20:40:50 +0000 | [diff] [blame] | 16 | #include "SkMaskGamma.h" |
bungeman | 5f14c5e | 2014-12-05 12:26:44 -0800 | [diff] [blame] | 17 | #include "SkMatrix22.h" |
commit-bot@chromium.org | 8b0e8ac | 2014-01-30 18:58:24 +0000 | [diff] [blame] | 18 | #include "SkReadBuffer.h" |
| 19 | #include "SkWriteBuffer.h" |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 20 | #include "SkPathEffect.h" |
| 21 | #include "SkRasterizer.h" |
reed@google.com | 045e62d | 2011-10-24 12:19:46 +0000 | [diff] [blame] | 22 | #include "SkRasterClip.h" |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 23 | #include "SkStroke.h" |
halcanary | 435657f | 2015-09-15 12:53:07 -0700 | [diff] [blame] | 24 | #include "SkStrokeRec.h" |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 25 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 26 | #define ComputeBWRowBytes(width) (((unsigned)(width) + 7) >> 3) |
| 27 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 28 | void SkGlyph::toMask(SkMask* mask) const { |
| 29 | SkASSERT(mask); |
| 30 | |
| 31 | mask->fImage = (uint8_t*)fImage; |
| 32 | mask->fBounds.set(fLeft, fTop, fLeft + fWidth, fTop + fHeight); |
| 33 | mask->fRowBytes = this->rowBytes(); |
reed@android.com | 6c14b43 | 2009-03-23 20:11:11 +0000 | [diff] [blame] | 34 | mask->fFormat = static_cast<SkMask::Format>(fMaskFormat); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 35 | } |
| 36 | |
| 37 | size_t SkGlyph::computeImageSize() const { |
agl@chromium.org | 309485b | 2009-07-21 17:41:32 +0000 | [diff] [blame] | 38 | const size_t size = this->rowBytes() * fHeight; |
| 39 | |
| 40 | switch (fMaskFormat) { |
reed@google.com | 7db9fe6 | 2011-04-11 11:57:54 +0000 | [diff] [blame] | 41 | case SkMask::k3D_Format: |
| 42 | return 3 * size; |
| 43 | default: |
| 44 | return size; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 45 | } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 46 | } |
| 47 | |
reed@android.com | 62900b4 | 2009-02-11 15:07:19 +0000 | [diff] [blame] | 48 | void SkGlyph::zeroMetrics() { |
| 49 | fAdvanceX = 0; |
| 50 | fAdvanceY = 0; |
| 51 | fWidth = 0; |
| 52 | fHeight = 0; |
| 53 | fTop = 0; |
| 54 | fLeft = 0; |
| 55 | fRsbDelta = 0; |
| 56 | fLsbDelta = 0; |
| 57 | } |
| 58 | |
| 59 | /////////////////////////////////////////////////////////////////////////////// |
| 60 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 61 | #ifdef SK_DEBUG |
| 62 | #define DUMP_RECx |
| 63 | #endif |
| 64 | |
reed | a9322c2 | 2016-04-12 06:47:05 -0700 | [diff] [blame] | 65 | SkScalerContext::SkScalerContext(SkTypeface* typeface, const SkScalerContextEffects& effects, |
| 66 | const SkDescriptor* desc) |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 67 | : fRec(*static_cast<const Rec*>(desc->findEntry(kRec_SkDescriptorTag, nullptr))) |
bungeman@google.com | a76de72 | 2012-10-26 19:35:54 +0000 | [diff] [blame] | 68 | |
reed | a9322c2 | 2016-04-12 06:47:05 -0700 | [diff] [blame] | 69 | , fTypeface(sk_ref_sp(typeface)) |
| 70 | , fPathEffect(sk_ref_sp(effects.fPathEffect)) |
| 71 | , fMaskFilter(sk_ref_sp(effects.fMaskFilter)) |
| 72 | , fRasterizer(sk_ref_sp(effects.fRasterizer)) |
bungeman@google.com | a76de72 | 2012-10-26 19:35:54 +0000 | [diff] [blame] | 73 | // Initialize based on our settings. Subclasses can also force this. |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 74 | , fGenerateImageFromPath(fRec.fFrameWidth > 0 || fPathEffect != nullptr || fRasterizer != nullptr) |
bungeman@google.com | a76de72 | 2012-10-26 19:35:54 +0000 | [diff] [blame] | 75 | |
bungeman@google.com | a76de72 | 2012-10-26 19:35:54 +0000 | [diff] [blame] | 76 | , fPreBlend(fMaskFilter ? SkMaskGamma::PreBlend() : SkScalerContext::GetMaskPreBlend(fRec)) |
| 77 | , fPreBlendForFilter(fMaskFilter ? SkScalerContext::GetMaskPreBlend(fRec) |
| 78 | : SkMaskGamma::PreBlend()) |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 79 | { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 80 | #ifdef DUMP_REC |
| 81 | desc->assertChecksum(); |
commit-bot@chromium.org | 34abef1 | 2014-02-17 15:28:55 +0000 | [diff] [blame] | 82 | SkDebugf("SkScalerContext checksum %x count %d length %d\n", |
reed@google.com | 7db9fe6 | 2011-04-11 11:57:54 +0000 | [diff] [blame] | 83 | desc->getChecksum(), desc->getCount(), desc->getLength()); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 84 | SkDebugf(" textsize %g prescale %g preskew %g post [%g %g %g %g]\n", |
| 85 | rec->fTextSize, rec->fPreScaleX, rec->fPreSkewX, rec->fPost2x2[0][0], |
| 86 | rec->fPost2x2[0][1], rec->fPost2x2[1][0], rec->fPost2x2[1][1]); |
caryclark | d7ea92f | 2016-03-16 07:34:02 -0700 | [diff] [blame] | 87 | SkDebugf(" frame %g miter %g hints %d framefill %d format %d join %d cap %d\n", |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 88 | rec->fFrameWidth, rec->fMiterLimit, rec->fHints, rec->fFrameAndFill, |
caryclark | d7ea92f | 2016-03-16 07:34:02 -0700 | [diff] [blame] | 89 | rec->fMaskFormat, rec->fStrokeJoin, rec->fStrokeCap); |
reed@google.com | 7db9fe6 | 2011-04-11 11:57:54 +0000 | [diff] [blame] | 90 | SkDebugf(" pathEffect %x maskFilter %x\n", |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 91 | desc->findEntry(kPathEffect_SkDescriptorTag, nullptr), |
| 92 | desc->findEntry(kMaskFilter_SkDescriptorTag, nullptr)); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 93 | #endif |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 94 | } |
| 95 | |
reed | a9322c2 | 2016-04-12 06:47:05 -0700 | [diff] [blame] | 96 | SkScalerContext::~SkScalerContext() {} |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 97 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 98 | void SkScalerContext::getAdvance(SkGlyph* glyph) { |
| 99 | // mark us as just having a valid advance |
| 100 | glyph->fMaskFormat = MASK_FORMAT_JUST_ADVANCE; |
| 101 | // we mark the format before making the call, in case the impl |
| 102 | // internally ends up calling its generateMetrics, which is OK |
| 103 | // albeit slower than strictly necessary |
djsollen | 1b27704 | 2014-08-06 06:58:06 -0700 | [diff] [blame] | 104 | generateAdvance(glyph); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 105 | } |
| 106 | |
| 107 | void SkScalerContext::getMetrics(SkGlyph* glyph) { |
djsollen | 1b27704 | 2014-08-06 06:58:06 -0700 | [diff] [blame] | 108 | generateMetrics(glyph); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 109 | |
| 110 | // for now we have separate cache entries for devkerning on and off |
| 111 | // in the future we might share caches, but make our measure/draw |
| 112 | // code make the distinction. Thus we zap the values if the caller |
| 113 | // has not asked for them. |
| 114 | if ((fRec.fFlags & SkScalerContext::kDevKernText_Flag) == 0) { |
| 115 | // no devkern, so zap the fields |
| 116 | glyph->fLsbDelta = glyph->fRsbDelta = 0; |
| 117 | } |
| 118 | |
| 119 | // if either dimension is empty, zap the image bounds of the glyph |
| 120 | if (0 == glyph->fWidth || 0 == glyph->fHeight) { |
| 121 | glyph->fWidth = 0; |
| 122 | glyph->fHeight = 0; |
| 123 | glyph->fTop = 0; |
| 124 | glyph->fLeft = 0; |
| 125 | glyph->fMaskFormat = 0; |
| 126 | return; |
| 127 | } |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 128 | |
reed@google.com | a767fa0 | 2011-08-05 21:40:26 +0000 | [diff] [blame] | 129 | if (fGenerateImageFromPath) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 130 | SkPath devPath, fillPath; |
| 131 | SkMatrix fillToDevMatrix; |
| 132 | |
| 133 | this->internalGetPath(*glyph, &fillPath, &devPath, &fillToDevMatrix); |
| 134 | |
| 135 | if (fRasterizer) { |
| 136 | SkMask mask; |
| 137 | |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 138 | if (fRasterizer->rasterize(fillPath, fillToDevMatrix, nullptr, |
reed | a9322c2 | 2016-04-12 06:47:05 -0700 | [diff] [blame] | 139 | fMaskFilter.get(), &mask, |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 140 | SkMask::kJustComputeBounds_CreateMode)) { |
| 141 | glyph->fLeft = mask.fBounds.fLeft; |
| 142 | glyph->fTop = mask.fBounds.fTop; |
| 143 | glyph->fWidth = SkToU16(mask.fBounds.width()); |
| 144 | glyph->fHeight = SkToU16(mask.fBounds.height()); |
| 145 | } else { |
senorblanco@chromium.org | 7767cd8 | 2009-11-25 17:14:32 +0000 | [diff] [blame] | 146 | goto SK_ERROR; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 147 | } |
| 148 | } else { |
| 149 | // just use devPath |
reed | b07a94f | 2014-11-19 05:03:18 -0800 | [diff] [blame] | 150 | const SkIRect ir = devPath.getBounds().roundOut(); |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 151 | |
reed@android.com | b757f8d | 2009-12-08 22:02:26 +0000 | [diff] [blame] | 152 | if (ir.isEmpty() || !ir.is16Bit()) { |
senorblanco@chromium.org | 7767cd8 | 2009-11-25 17:14:32 +0000 | [diff] [blame] | 153 | goto SK_ERROR; |
reed@android.com | d457775 | 2009-11-21 02:48:11 +0000 | [diff] [blame] | 154 | } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 155 | glyph->fLeft = ir.fLeft; |
| 156 | glyph->fTop = ir.fTop; |
| 157 | glyph->fWidth = SkToU16(ir.width()); |
| 158 | glyph->fHeight = SkToU16(ir.height()); |
bungeman@google.com | 0abbff9 | 2013-07-27 20:37:56 +0000 | [diff] [blame] | 159 | |
| 160 | if (glyph->fWidth > 0) { |
rmistry@google.com | d6bab02 | 2013-12-02 13:50:38 +0000 | [diff] [blame] | 161 | switch (fRec.fMaskFormat) { |
| 162 | case SkMask::kLCD16_Format: |
rmistry@google.com | d6bab02 | 2013-12-02 13:50:38 +0000 | [diff] [blame] | 163 | glyph->fWidth += 2; |
| 164 | glyph->fLeft -= 1; |
| 165 | break; |
| 166 | default: |
| 167 | break; |
| 168 | } |
bungeman@google.com | 0abbff9 | 2013-07-27 20:37:56 +0000 | [diff] [blame] | 169 | } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 170 | } |
| 171 | } |
| 172 | |
robertphillips@google.com | a22e211 | 2012-08-16 14:58:06 +0000 | [diff] [blame] | 173 | if (SkMask::kARGB32_Format != glyph->fMaskFormat) { |
| 174 | glyph->fMaskFormat = fRec.fMaskFormat; |
| 175 | } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 176 | |
reed@google.com | 5bdfb33 | 2013-05-02 18:55:44 +0000 | [diff] [blame] | 177 | // If we are going to create the mask, then we cannot keep the color |
| 178 | if ((fGenerateImageFromPath || fMaskFilter) && |
| 179 | SkMask::kARGB32_Format == glyph->fMaskFormat) { |
| 180 | glyph->fMaskFormat = SkMask::kA8_Format; |
| 181 | } |
| 182 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 183 | if (fMaskFilter) { |
| 184 | SkMask src, dst; |
| 185 | SkMatrix matrix; |
| 186 | |
| 187 | glyph->toMask(&src); |
| 188 | fRec.getMatrixFrom2x2(&matrix); |
| 189 | |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 190 | src.fImage = nullptr; // only want the bounds from the filter |
| 191 | if (fMaskFilter->filterMask(&dst, src, matrix, nullptr)) { |
reed@google.com | 8136d58 | 2012-09-21 17:38:06 +0000 | [diff] [blame] | 192 | if (dst.fBounds.isEmpty() || !dst.fBounds.is16Bit()) { |
| 193 | goto SK_ERROR; |
| 194 | } |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 195 | SkASSERT(dst.fImage == nullptr); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 196 | glyph->fLeft = dst.fBounds.fLeft; |
| 197 | glyph->fTop = dst.fBounds.fTop; |
| 198 | glyph->fWidth = SkToU16(dst.fBounds.width()); |
| 199 | glyph->fHeight = SkToU16(dst.fBounds.height()); |
| 200 | glyph->fMaskFormat = dst.fFormat; |
| 201 | } |
| 202 | } |
reed@android.com | d457775 | 2009-11-21 02:48:11 +0000 | [diff] [blame] | 203 | return; |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 204 | |
senorblanco@chromium.org | 7767cd8 | 2009-11-25 17:14:32 +0000 | [diff] [blame] | 205 | SK_ERROR: |
reed@android.com | d457775 | 2009-11-21 02:48:11 +0000 | [diff] [blame] | 206 | // draw nothing 'cause we failed |
| 207 | glyph->fLeft = 0; |
| 208 | glyph->fTop = 0; |
| 209 | glyph->fWidth = 0; |
| 210 | glyph->fHeight = 0; |
reed@android.com | b757f8d | 2009-12-08 22:02:26 +0000 | [diff] [blame] | 211 | // put a valid value here, in case it was earlier set to |
| 212 | // MASK_FORMAT_JUST_ADVANCE |
| 213 | glyph->fMaskFormat = fRec.fMaskFormat; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 214 | } |
| 215 | |
bungeman@google.com | 0abbff9 | 2013-07-27 20:37:56 +0000 | [diff] [blame] | 216 | #define SK_SHOW_TEXT_BLIT_COVERAGE 0 |
bungeman@google.com | a76de72 | 2012-10-26 19:35:54 +0000 | [diff] [blame] | 217 | |
| 218 | static void applyLUTToA8Mask(const SkMask& mask, const uint8_t* lut) { |
| 219 | uint8_t* SK_RESTRICT dst = (uint8_t*)mask.fImage; |
| 220 | unsigned rowBytes = mask.fRowBytes; |
| 221 | |
| 222 | for (int y = mask.fBounds.height() - 1; y >= 0; --y) { |
| 223 | for (int x = mask.fBounds.width() - 1; x >= 0; --x) { |
| 224 | dst[x] = lut[dst[x]]; |
| 225 | } |
| 226 | dst += rowBytes; |
| 227 | } |
| 228 | } |
| 229 | |
bungeman@google.com | 97efada | 2012-07-30 20:40:50 +0000 | [diff] [blame] | 230 | template<bool APPLY_PREBLEND> |
reed | 41e010c | 2015-06-09 12:16:53 -0700 | [diff] [blame] | 231 | static void pack4xHToLCD16(const SkPixmap& src, const SkMask& dst, |
bungeman@google.com | a76de72 | 2012-10-26 19:35:54 +0000 | [diff] [blame] | 232 | const SkMaskGamma::PreBlend& maskPreBlend) { |
bungeman@google.com | 0abbff9 | 2013-07-27 20:37:56 +0000 | [diff] [blame] | 233 | #define SAMPLES_PER_PIXEL 4 |
| 234 | #define LCD_PER_PIXEL 3 |
reed@google.com | 900ecf2 | 2014-02-20 20:55:37 +0000 | [diff] [blame] | 235 | SkASSERT(kAlpha_8_SkColorType == src.colorType()); |
reed@google.com | cf598b1 | 2011-08-22 21:13:23 +0000 | [diff] [blame] | 236 | SkASSERT(SkMask::kLCD16_Format == dst.fFormat); |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 237 | |
bungeman@google.com | 0abbff9 | 2013-07-27 20:37:56 +0000 | [diff] [blame] | 238 | const int sample_width = src.width(); |
| 239 | const int height = src.height(); |
| 240 | |
reed@google.com | cf598b1 | 2011-08-22 21:13:23 +0000 | [diff] [blame] | 241 | uint16_t* dstP = (uint16_t*)dst.fImage; |
| 242 | size_t dstRB = dst.fRowBytes; |
bungeman@google.com | 0abbff9 | 2013-07-27 20:37:56 +0000 | [diff] [blame] | 243 | // An N tap FIR is defined by |
| 244 | // out[n] = coeff[0]*x[n] + coeff[1]*x[n-1] + ... + coeff[N]*x[n-N] |
| 245 | // or |
| 246 | // out[n] = sum(i, 0, N, coeff[i]*x[n-i]) |
| 247 | |
| 248 | // The strategy is to use one FIR (different coefficients) for each of r, g, and b. |
| 249 | // This means using every 4th FIR output value of each FIR and discarding the rest. |
| 250 | // The FIRs are aligned, and the coefficients reach 5 samples to each side of their 'center'. |
| 251 | // (For r and b this is technically incorrect, but the coeffs outside round to zero anyway.) |
skia.committer@gmail.com | 27e21fe | 2013-07-28 07:01:03 +0000 | [diff] [blame] | 252 | |
bungeman@google.com | 0abbff9 | 2013-07-27 20:37:56 +0000 | [diff] [blame] | 253 | // These are in some fixed point repesentation. |
| 254 | // Adding up to more than one simulates ink spread. |
| 255 | // For implementation reasons, these should never add up to more than two. |
| 256 | |
| 257 | // Coefficients determined by a gausian where 5 samples = 3 std deviations (0x110 'contrast'). |
| 258 | // Calculated using tools/generate_fir_coeff.py |
| 259 | // With this one almost no fringing is ever seen, but it is imperceptibly blurry. |
| 260 | // The lcd smoothed text is almost imperceptibly different from gray, |
| 261 | // but is still sharper on small stems and small rounded corners than gray. |
| 262 | // This also seems to be about as wide as one can get and only have a three pixel kernel. |
| 263 | // TODO: caculate these at runtime so parameters can be adjusted (esp contrast). |
| 264 | static const unsigned int coefficients[LCD_PER_PIXEL][SAMPLES_PER_PIXEL*3] = { |
| 265 | //The red subpixel is centered inside the first sample (at 1/6 pixel), and is shifted. |
| 266 | { 0x03, 0x0b, 0x1c, 0x33, 0x40, 0x39, 0x24, 0x10, 0x05, 0x01, 0x00, 0x00, }, |
| 267 | //The green subpixel is centered between two samples (at 1/2 pixel), so is symetric |
| 268 | { 0x00, 0x02, 0x08, 0x16, 0x2b, 0x3d, 0x3d, 0x2b, 0x16, 0x08, 0x02, 0x00, }, |
| 269 | //The blue subpixel is centered inside the last sample (at 5/6 pixel), and is shifted. |
| 270 | { 0x00, 0x00, 0x01, 0x05, 0x10, 0x24, 0x39, 0x40, 0x33, 0x1c, 0x0b, 0x03, }, |
| 271 | }; |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 272 | |
reed@google.com | cf598b1 | 2011-08-22 21:13:23 +0000 | [diff] [blame] | 273 | for (int y = 0; y < height; ++y) { |
reed | 41e010c | 2015-06-09 12:16:53 -0700 | [diff] [blame] | 274 | const uint8_t* srcP = src.addr8(0, y); |
bungeman@google.com | 0abbff9 | 2013-07-27 20:37:56 +0000 | [diff] [blame] | 275 | |
| 276 | // TODO: this fir filter implementation is straight forward, but slow. |
| 277 | // It should be possible to make it much faster. |
| 278 | for (int sample_x = -4, pixel_x = 0; sample_x < sample_width + 4; sample_x += 4, ++pixel_x) { |
| 279 | int fir[LCD_PER_PIXEL] = { 0 }; |
| 280 | for (int sample_index = SkMax32(0, sample_x - 4), coeff_index = sample_index - (sample_x - 4) |
| 281 | ; sample_index < SkMin32(sample_x + 8, sample_width) |
| 282 | ; ++sample_index, ++coeff_index) |
| 283 | { |
| 284 | int sample_value = srcP[sample_index]; |
| 285 | for (int subpxl_index = 0; subpxl_index < LCD_PER_PIXEL; ++subpxl_index) { |
| 286 | fir[subpxl_index] += coefficients[subpxl_index][coeff_index] * sample_value; |
| 287 | } |
| 288 | } |
| 289 | for (int subpxl_index = 0; subpxl_index < LCD_PER_PIXEL; ++subpxl_index) { |
| 290 | fir[subpxl_index] /= 0x100; |
| 291 | fir[subpxl_index] = SkMin32(fir[subpxl_index], 255); |
| 292 | } |
| 293 | |
| 294 | U8CPU r = sk_apply_lut_if<APPLY_PREBLEND>(fir[0], maskPreBlend.fR); |
| 295 | U8CPU g = sk_apply_lut_if<APPLY_PREBLEND>(fir[1], maskPreBlend.fG); |
| 296 | U8CPU b = sk_apply_lut_if<APPLY_PREBLEND>(fir[2], maskPreBlend.fB); |
| 297 | #if SK_SHOW_TEXT_BLIT_COVERAGE |
| 298 | r = SkMax32(r, 10); g = SkMax32(g, 10); b = SkMax32(b, 10); |
| 299 | #endif |
| 300 | dstP[pixel_x] = SkPack888ToRGB16(r, g, b); |
reed@google.com | a767fa0 | 2011-08-05 21:40:26 +0000 | [diff] [blame] | 301 | } |
reed@google.com | cf598b1 | 2011-08-22 21:13:23 +0000 | [diff] [blame] | 302 | dstP = (uint16_t*)((char*)dstP + dstRB); |
| 303 | } |
| 304 | } |
| 305 | |
rmistry@google.com | d6bab02 | 2013-12-02 13:50:38 +0000 | [diff] [blame] | 306 | static inline int convert_8_to_1(unsigned byte) { |
| 307 | SkASSERT(byte <= 0xFF); |
| 308 | return byte >> 7; |
| 309 | } |
| 310 | |
| 311 | static uint8_t pack_8_to_1(const uint8_t alpha[8]) { |
| 312 | unsigned bits = 0; |
| 313 | for (int i = 0; i < 8; ++i) { |
| 314 | bits <<= 1; |
| 315 | bits |= convert_8_to_1(alpha[i]); |
| 316 | } |
| 317 | return SkToU8(bits); |
| 318 | } |
| 319 | |
| 320 | static void packA8ToA1(const SkMask& mask, const uint8_t* src, size_t srcRB) { |
| 321 | const int height = mask.fBounds.height(); |
| 322 | const int width = mask.fBounds.width(); |
| 323 | const int octs = width >> 3; |
| 324 | const int leftOverBits = width & 7; |
| 325 | |
| 326 | uint8_t* dst = mask.fImage; |
| 327 | const int dstPad = mask.fRowBytes - SkAlign8(width)/8; |
| 328 | SkASSERT(dstPad >= 0); |
| 329 | |
commit-bot@chromium.org | f117781 | 2014-04-23 19:19:44 +0000 | [diff] [blame] | 330 | SkASSERT(width >= 0); |
| 331 | SkASSERT(srcRB >= (size_t)width); |
| 332 | const size_t srcPad = srcRB - width; |
rmistry@google.com | d6bab02 | 2013-12-02 13:50:38 +0000 | [diff] [blame] | 333 | |
| 334 | for (int y = 0; y < height; ++y) { |
| 335 | for (int i = 0; i < octs; ++i) { |
| 336 | *dst++ = pack_8_to_1(src); |
| 337 | src += 8; |
| 338 | } |
| 339 | if (leftOverBits > 0) { |
| 340 | unsigned bits = 0; |
| 341 | int shift = 7; |
| 342 | for (int i = 0; i < leftOverBits; ++i, --shift) { |
robertphillips@google.com | c932c9f | 2013-12-02 15:43:39 +0000 | [diff] [blame] | 343 | bits |= convert_8_to_1(*src++) << shift; |
rmistry@google.com | d6bab02 | 2013-12-02 13:50:38 +0000 | [diff] [blame] | 344 | } |
| 345 | *dst++ = bits; |
| 346 | } |
| 347 | src += srcPad; |
| 348 | dst += dstPad; |
| 349 | } |
| 350 | } |
| 351 | |
bungeman@google.com | a76de72 | 2012-10-26 19:35:54 +0000 | [diff] [blame] | 352 | static void generateMask(const SkMask& mask, const SkPath& path, |
| 353 | const SkMaskGamma::PreBlend& maskPreBlend) { |
rmistry@google.com | d6bab02 | 2013-12-02 13:50:38 +0000 | [diff] [blame] | 354 | SkPaint paint; |
reed@google.com | cf598b1 | 2011-08-22 21:13:23 +0000 | [diff] [blame] | 355 | |
| 356 | int srcW = mask.fBounds.width(); |
| 357 | int srcH = mask.fBounds.height(); |
| 358 | int dstW = srcW; |
| 359 | int dstH = srcH; |
| 360 | int dstRB = mask.fRowBytes; |
| 361 | |
| 362 | SkMatrix matrix; |
| 363 | matrix.setTranslate(-SkIntToScalar(mask.fBounds.fLeft), |
| 364 | -SkIntToScalar(mask.fBounds.fTop)); |
| 365 | |
rmistry@google.com | d6bab02 | 2013-12-02 13:50:38 +0000 | [diff] [blame] | 366 | paint.setAntiAlias(SkMask::kBW_Format != mask.fFormat); |
| 367 | switch (mask.fFormat) { |
| 368 | case SkMask::kBW_Format: |
| 369 | dstRB = 0; // signals we need a copy |
| 370 | break; |
| 371 | case SkMask::kA8_Format: |
| 372 | break; |
| 373 | case SkMask::kLCD16_Format: |
rmistry@google.com | d6bab02 | 2013-12-02 13:50:38 +0000 | [diff] [blame] | 374 | // TODO: trigger off LCD orientation |
| 375 | dstW = 4*dstW - 8; |
| 376 | matrix.setTranslate(-SkIntToScalar(mask.fBounds.fLeft + 1), |
| 377 | -SkIntToScalar(mask.fBounds.fTop)); |
| 378 | matrix.postScale(SkIntToScalar(4), SK_Scalar1); |
| 379 | dstRB = 0; // signals we need a copy |
| 380 | break; |
| 381 | default: |
| 382 | SkDEBUGFAIL("unexpected mask format"); |
reed@google.com | cf598b1 | 2011-08-22 21:13:23 +0000 | [diff] [blame] | 383 | } |
| 384 | |
reed@google.com | 045e62d | 2011-10-24 12:19:46 +0000 | [diff] [blame] | 385 | SkRasterClip clip; |
| 386 | clip.setRect(SkIRect::MakeWH(dstW, dstH)); |
reed@google.com | cf598b1 | 2011-08-22 21:13:23 +0000 | [diff] [blame] | 387 | |
commit-bot@chromium.org | a3264e5 | 2014-05-30 13:26:10 +0000 | [diff] [blame] | 388 | const SkImageInfo info = SkImageInfo::MakeA8(dstW, dstH); |
reed | 41e010c | 2015-06-09 12:16:53 -0700 | [diff] [blame] | 389 | SkAutoPixmapStorage dst; |
reed@google.com | cf598b1 | 2011-08-22 21:13:23 +0000 | [diff] [blame] | 390 | |
| 391 | if (0 == dstRB) { |
reed | 41e010c | 2015-06-09 12:16:53 -0700 | [diff] [blame] | 392 | if (!dst.tryAlloc(info)) { |
reed@google.com | 9be5727 | 2012-12-17 14:21:38 +0000 | [diff] [blame] | 393 | // can't allocate offscreen, so empty the mask and return |
| 394 | sk_bzero(mask.fImage, mask.computeImageSize()); |
| 395 | return; |
| 396 | } |
reed@google.com | cf598b1 | 2011-08-22 21:13:23 +0000 | [diff] [blame] | 397 | } else { |
reed | 41e010c | 2015-06-09 12:16:53 -0700 | [diff] [blame] | 398 | dst.reset(info, mask.fImage, dstRB); |
reed@google.com | cf598b1 | 2011-08-22 21:13:23 +0000 | [diff] [blame] | 399 | } |
reed | 41e010c | 2015-06-09 12:16:53 -0700 | [diff] [blame] | 400 | sk_bzero(dst.writable_addr(), dst.getSafeSize()); |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 401 | |
reed@google.com | cf598b1 | 2011-08-22 21:13:23 +0000 | [diff] [blame] | 402 | SkDraw draw; |
reed | 41e010c | 2015-06-09 12:16:53 -0700 | [diff] [blame] | 403 | draw.fDst = dst; |
reed@google.com | 045e62d | 2011-10-24 12:19:46 +0000 | [diff] [blame] | 404 | draw.fRC = &clip; |
reed@google.com | cf598b1 | 2011-08-22 21:13:23 +0000 | [diff] [blame] | 405 | draw.fMatrix = &matrix; |
reed@google.com | cf598b1 | 2011-08-22 21:13:23 +0000 | [diff] [blame] | 406 | draw.drawPath(path, paint); |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 407 | |
bungeman@google.com | 0c5f376 | 2012-10-26 20:48:54 +0000 | [diff] [blame] | 408 | switch (mask.fFormat) { |
rmistry@google.com | d6bab02 | 2013-12-02 13:50:38 +0000 | [diff] [blame] | 409 | case SkMask::kBW_Format: |
reed | 41e010c | 2015-06-09 12:16:53 -0700 | [diff] [blame] | 410 | packA8ToA1(mask, dst.addr8(0, 0), dst.rowBytes()); |
rmistry@google.com | d6bab02 | 2013-12-02 13:50:38 +0000 | [diff] [blame] | 411 | break; |
bungeman@google.com | 0c5f376 | 2012-10-26 20:48:54 +0000 | [diff] [blame] | 412 | case SkMask::kA8_Format: |
| 413 | if (maskPreBlend.isApplicable()) { |
| 414 | applyLUTToA8Mask(mask, maskPreBlend.fG); |
| 415 | } |
| 416 | break; |
| 417 | case SkMask::kLCD16_Format: |
| 418 | if (maskPreBlend.isApplicable()) { |
reed | 41e010c | 2015-06-09 12:16:53 -0700 | [diff] [blame] | 419 | pack4xHToLCD16<true>(dst, mask, maskPreBlend); |
bungeman@google.com | 0c5f376 | 2012-10-26 20:48:54 +0000 | [diff] [blame] | 420 | } else { |
reed | 41e010c | 2015-06-09 12:16:53 -0700 | [diff] [blame] | 421 | pack4xHToLCD16<false>(dst, mask, maskPreBlend); |
bungeman@google.com | 0c5f376 | 2012-10-26 20:48:54 +0000 | [diff] [blame] | 422 | } |
| 423 | break; |
bungeman@google.com | 0c5f376 | 2012-10-26 20:48:54 +0000 | [diff] [blame] | 424 | default: |
| 425 | break; |
reed@google.com | cf598b1 | 2011-08-22 21:13:23 +0000 | [diff] [blame] | 426 | } |
| 427 | } |
| 428 | |
reed@google.com | 5bdfb33 | 2013-05-02 18:55:44 +0000 | [diff] [blame] | 429 | static void extract_alpha(const SkMask& dst, |
| 430 | const SkPMColor* srcRow, size_t srcRB) { |
| 431 | int width = dst.fBounds.width(); |
| 432 | int height = dst.fBounds.height(); |
| 433 | int dstRB = dst.fRowBytes; |
| 434 | uint8_t* dstRow = dst.fImage; |
| 435 | |
| 436 | for (int y = 0; y < height; ++y) { |
| 437 | for (int x = 0; x < width; ++x) { |
| 438 | dstRow[x] = SkGetPackedA32(srcRow[x]); |
| 439 | } |
| 440 | // zero any padding on each row |
| 441 | for (int x = width; x < dstRB; ++x) { |
| 442 | dstRow[x] = 0; |
| 443 | } |
| 444 | dstRow += dstRB; |
| 445 | srcRow = (const SkPMColor*)((const char*)srcRow + srcRB); |
| 446 | } |
| 447 | } |
| 448 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 449 | void SkScalerContext::getImage(const SkGlyph& origGlyph) { |
| 450 | const SkGlyph* glyph = &origGlyph; |
| 451 | SkGlyph tmpGlyph; |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 452 | |
reed@google.com | 5bdfb33 | 2013-05-02 18:55:44 +0000 | [diff] [blame] | 453 | // in case we need to call generateImage on a mask-format that is different |
| 454 | // (i.e. larger) than what our caller allocated by looking at origGlyph. |
| 455 | SkAutoMalloc tmpGlyphImageStorage; |
| 456 | |
| 457 | // If we are going to draw-from-path, then we cannot generate color, since |
| 458 | // the path only makes a mask. This case should have been caught up in |
| 459 | // generateMetrics(). |
| 460 | SkASSERT(!fGenerateImageFromPath || |
| 461 | SkMask::kARGB32_Format != origGlyph.fMaskFormat); |
| 462 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 463 | if (fMaskFilter) { // restore the prefilter bounds |
herb | b69d0e0 | 2015-02-25 06:47:06 -0800 | [diff] [blame] | 464 | tmpGlyph.initGlyphIdFrom(origGlyph); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 465 | |
| 466 | // need the original bounds, sans our maskfilter |
reed | a9322c2 | 2016-04-12 06:47:05 -0700 | [diff] [blame] | 467 | SkMaskFilter* mf = fMaskFilter.release(); // temp disable |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 468 | this->getMetrics(&tmpGlyph); |
reed | a9322c2 | 2016-04-12 06:47:05 -0700 | [diff] [blame] | 469 | fMaskFilter = sk_sp<SkMaskFilter>(mf); // restore |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 470 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 471 | // we need the prefilter bounds to be <= filter bounds |
| 472 | SkASSERT(tmpGlyph.fWidth <= origGlyph.fWidth); |
| 473 | SkASSERT(tmpGlyph.fHeight <= origGlyph.fHeight); |
reed@google.com | 5bdfb33 | 2013-05-02 18:55:44 +0000 | [diff] [blame] | 474 | |
| 475 | if (tmpGlyph.fMaskFormat == origGlyph.fMaskFormat) { |
| 476 | tmpGlyph.fImage = origGlyph.fImage; |
| 477 | } else { |
| 478 | tmpGlyphImageStorage.reset(tmpGlyph.computeImageSize()); |
| 479 | tmpGlyph.fImage = tmpGlyphImageStorage.get(); |
| 480 | } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 481 | glyph = &tmpGlyph; |
| 482 | } |
| 483 | |
reed@google.com | a767fa0 | 2011-08-05 21:40:26 +0000 | [diff] [blame] | 484 | if (fGenerateImageFromPath) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 485 | SkPath devPath, fillPath; |
| 486 | SkMatrix fillToDevMatrix; |
reed@google.com | cf598b1 | 2011-08-22 21:13:23 +0000 | [diff] [blame] | 487 | SkMask mask; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 488 | |
| 489 | this->internalGetPath(*glyph, &fillPath, &devPath, &fillToDevMatrix); |
reed@google.com | cf598b1 | 2011-08-22 21:13:23 +0000 | [diff] [blame] | 490 | glyph->toMask(&mask); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 491 | |
| 492 | if (fRasterizer) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 493 | mask.fFormat = SkMask::kA8_Format; |
reed@android.com | 4516f47 | 2009-06-29 16:25:36 +0000 | [diff] [blame] | 494 | sk_bzero(glyph->fImage, mask.computeImageSize()); |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 495 | |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 496 | if (!fRasterizer->rasterize(fillPath, fillToDevMatrix, nullptr, |
reed | a9322c2 | 2016-04-12 06:47:05 -0700 | [diff] [blame] | 497 | fMaskFilter.get(), &mask, |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 498 | SkMask::kJustRenderImage_CreateMode)) { |
| 499 | return; |
| 500 | } |
bungeman@google.com | a76de72 | 2012-10-26 19:35:54 +0000 | [diff] [blame] | 501 | if (fPreBlend.isApplicable()) { |
| 502 | applyLUTToA8Mask(mask, fPreBlend.fG); |
bungeman@google.com | 97efada | 2012-07-30 20:40:50 +0000 | [diff] [blame] | 503 | } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 504 | } else { |
reed@google.com | 5bdfb33 | 2013-05-02 18:55:44 +0000 | [diff] [blame] | 505 | SkASSERT(SkMask::kARGB32_Format != mask.fFormat); |
bungeman@google.com | a76de72 | 2012-10-26 19:35:54 +0000 | [diff] [blame] | 506 | generateMask(mask, devPath, fPreBlend); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 507 | } |
| 508 | } else { |
djsollen | 1b27704 | 2014-08-06 06:58:06 -0700 | [diff] [blame] | 509 | generateImage(*glyph); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 510 | } |
| 511 | |
| 512 | if (fMaskFilter) { |
| 513 | SkMask srcM, dstM; |
| 514 | SkMatrix matrix; |
| 515 | |
| 516 | // the src glyph image shouldn't be 3D |
| 517 | SkASSERT(SkMask::k3D_Format != glyph->fMaskFormat); |
reed@google.com | 5bdfb33 | 2013-05-02 18:55:44 +0000 | [diff] [blame] | 518 | |
| 519 | SkAutoSMalloc<32*32> a8storage; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 520 | glyph->toMask(&srcM); |
reed@google.com | 5bdfb33 | 2013-05-02 18:55:44 +0000 | [diff] [blame] | 521 | if (SkMask::kARGB32_Format == srcM.fFormat) { |
| 522 | // now we need to extract the alpha-channel from the glyph's image |
| 523 | // and copy it into a temp buffer, and then point srcM at that temp. |
| 524 | srcM.fFormat = SkMask::kA8_Format; |
| 525 | srcM.fRowBytes = SkAlign4(srcM.fBounds.width()); |
| 526 | size_t size = srcM.computeImageSize(); |
| 527 | a8storage.reset(size); |
| 528 | srcM.fImage = (uint8_t*)a8storage.get(); |
| 529 | extract_alpha(srcM, |
| 530 | (const SkPMColor*)glyph->fImage, glyph->rowBytes()); |
| 531 | } |
skia.committer@gmail.com | 2fd42c4 | 2013-05-03 07:01:00 +0000 | [diff] [blame] | 532 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 533 | fRec.getMatrixFrom2x2(&matrix); |
| 534 | |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 535 | if (fMaskFilter->filterMask(&dstM, srcM, matrix, nullptr)) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 536 | int width = SkFastMin32(origGlyph.fWidth, dstM.fBounds.width()); |
| 537 | int height = SkFastMin32(origGlyph.fHeight, dstM.fBounds.height()); |
| 538 | int dstRB = origGlyph.rowBytes(); |
| 539 | int srcRB = dstM.fRowBytes; |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 540 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 541 | const uint8_t* src = (const uint8_t*)dstM.fImage; |
| 542 | uint8_t* dst = (uint8_t*)origGlyph.fImage; |
| 543 | |
| 544 | if (SkMask::k3D_Format == dstM.fFormat) { |
| 545 | // we have to copy 3 times as much |
| 546 | height *= 3; |
| 547 | } |
| 548 | |
| 549 | // clean out our glyph, since it may be larger than dstM |
reed@android.com | 4516f47 | 2009-06-29 16:25:36 +0000 | [diff] [blame] | 550 | //sk_bzero(dst, height * dstRB); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 551 | |
| 552 | while (--height >= 0) { |
| 553 | memcpy(dst, src, width); |
| 554 | src += srcRB; |
| 555 | dst += dstRB; |
| 556 | } |
| 557 | SkMask::FreeImage(dstM.fImage); |
bungeman@google.com | 97efada | 2012-07-30 20:40:50 +0000 | [diff] [blame] | 558 | |
bungeman@google.com | a76de72 | 2012-10-26 19:35:54 +0000 | [diff] [blame] | 559 | if (fPreBlendForFilter.isApplicable()) { |
| 560 | applyLUTToA8Mask(srcM, fPreBlendForFilter.fG); |
| 561 | } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 562 | } |
| 563 | } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 564 | } |
| 565 | |
reed@google.com | 7db9fe6 | 2011-04-11 11:57:54 +0000 | [diff] [blame] | 566 | void SkScalerContext::getPath(const SkGlyph& glyph, SkPath* path) { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 567 | this->internalGetPath(glyph, nullptr, path, nullptr); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 568 | } |
| 569 | |
reed@google.com | 0a01f5a | 2013-05-08 14:19:08 +0000 | [diff] [blame] | 570 | void SkScalerContext::getFontMetrics(SkPaint::FontMetrics* fm) { |
bungeman | 4107806 | 2014-07-07 08:16:37 -0700 | [diff] [blame] | 571 | this->generateFontMetrics(fm); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 572 | } |
| 573 | |
reed@android.com | 9d3a985 | 2010-01-08 14:07:42 +0000 | [diff] [blame] | 574 | SkUnichar SkScalerContext::generateGlyphToChar(uint16_t glyph) { |
| 575 | return 0; |
| 576 | } |
| 577 | |
reed@google.com | 7db9fe6 | 2011-04-11 11:57:54 +0000 | [diff] [blame] | 578 | /////////////////////////////////////////////////////////////////////////////// |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 579 | |
reed@google.com | 7db9fe6 | 2011-04-11 11:57:54 +0000 | [diff] [blame] | 580 | void SkScalerContext::internalGetPath(const SkGlyph& glyph, SkPath* fillPath, |
| 581 | SkPath* devPath, SkMatrix* fillToDevMatrix) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 582 | SkPath path; |
djsollen | 1b27704 | 2014-08-06 06:58:06 -0700 | [diff] [blame] | 583 | generatePath(glyph, &path); |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 584 | |
reed@google.com | cf598b1 | 2011-08-22 21:13:23 +0000 | [diff] [blame] | 585 | if (fRec.fFlags & SkScalerContext::kSubpixelPositioning_Flag) { |
| 586 | SkFixed dx = glyph.getSubXFixed(); |
| 587 | SkFixed dy = glyph.getSubYFixed(); |
| 588 | if (dx | dy) { |
| 589 | path.offset(SkFixedToScalar(dx), SkFixedToScalar(dy)); |
| 590 | } |
| 591 | } |
| 592 | |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 593 | if (fRec.fFrameWidth > 0 || fPathEffect != nullptr) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 594 | // need the path in user-space, with only the point-size applied |
| 595 | // so that our stroking and effects will operate the same way they |
| 596 | // would if the user had extracted the path themself, and then |
| 597 | // called drawPath |
| 598 | SkPath localPath; |
| 599 | SkMatrix matrix, inverse; |
| 600 | |
| 601 | fRec.getMatrixFrom2x2(&matrix); |
bungeman@google.com | 9575fb8 | 2012-04-09 20:49:03 +0000 | [diff] [blame] | 602 | if (!matrix.invert(&inverse)) { |
| 603 | // assume fillPath and devPath are already empty. |
| 604 | return; |
| 605 | } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 606 | path.transform(inverse, &localPath); |
| 607 | // now localPath is only affected by the paint settings, and not the canvas matrix |
| 608 | |
reed@google.com | fd4be26 | 2012-05-25 01:04:12 +0000 | [diff] [blame] | 609 | SkStrokeRec rec(SkStrokeRec::kFill_InitStyle); |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 610 | |
reed@google.com | fd4be26 | 2012-05-25 01:04:12 +0000 | [diff] [blame] | 611 | if (fRec.fFrameWidth > 0) { |
| 612 | rec.setStrokeStyle(fRec.fFrameWidth, |
| 613 | SkToBool(fRec.fFlags & kFrameAndFill_Flag)); |
| 614 | // glyphs are always closed contours, so cap type is ignored, |
| 615 | // so we just pass something. |
caryclark | d7ea92f | 2016-03-16 07:34:02 -0700 | [diff] [blame] | 616 | rec.setStrokeParams((SkPaint::Cap)fRec.fStrokeCap, |
reed@google.com | fd4be26 | 2012-05-25 01:04:12 +0000 | [diff] [blame] | 617 | (SkPaint::Join)fRec.fStrokeJoin, |
| 618 | fRec.fMiterLimit); |
| 619 | } |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 620 | |
reed@google.com | 7db9fe6 | 2011-04-11 11:57:54 +0000 | [diff] [blame] | 621 | if (fPathEffect) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 622 | SkPath effectPath; |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 623 | if (fPathEffect->filterPath(&effectPath, localPath, &rec, nullptr)) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 624 | localPath.swap(effectPath); |
reed@google.com | 7db9fe6 | 2011-04-11 11:57:54 +0000 | [diff] [blame] | 625 | } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 626 | } |
| 627 | |
reed@google.com | fd4be26 | 2012-05-25 01:04:12 +0000 | [diff] [blame] | 628 | if (rec.needToApply()) { |
| 629 | SkPath strokePath; |
| 630 | if (rec.applyToPath(&strokePath, localPath)) { |
| 631 | localPath.swap(strokePath); |
| 632 | } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 633 | } |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 634 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 635 | // now return stuff to the caller |
reed@google.com | 7db9fe6 | 2011-04-11 11:57:54 +0000 | [diff] [blame] | 636 | if (fillToDevMatrix) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 637 | *fillToDevMatrix = matrix; |
reed@google.com | 7db9fe6 | 2011-04-11 11:57:54 +0000 | [diff] [blame] | 638 | } |
| 639 | if (devPath) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 640 | localPath.transform(matrix, devPath); |
reed@google.com | 7db9fe6 | 2011-04-11 11:57:54 +0000 | [diff] [blame] | 641 | } |
| 642 | if (fillPath) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 643 | fillPath->swap(localPath); |
reed@google.com | 7db9fe6 | 2011-04-11 11:57:54 +0000 | [diff] [blame] | 644 | } |
| 645 | } else { // nothing tricky to do |
| 646 | if (fillToDevMatrix) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 647 | fillToDevMatrix->reset(); |
reed@google.com | 7db9fe6 | 2011-04-11 11:57:54 +0000 | [diff] [blame] | 648 | } |
| 649 | if (devPath) { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 650 | if (fillPath == nullptr) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 651 | devPath->swap(path); |
reed@google.com | 7db9fe6 | 2011-04-11 11:57:54 +0000 | [diff] [blame] | 652 | } else { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 653 | *devPath = path; |
reed@google.com | 7db9fe6 | 2011-04-11 11:57:54 +0000 | [diff] [blame] | 654 | } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 655 | } |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 656 | |
reed@google.com | 7db9fe6 | 2011-04-11 11:57:54 +0000 | [diff] [blame] | 657 | if (fillPath) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 658 | fillPath->swap(path); |
reed@google.com | 7db9fe6 | 2011-04-11 11:57:54 +0000 | [diff] [blame] | 659 | } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 660 | } |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 661 | |
reed@google.com | 7db9fe6 | 2011-04-11 11:57:54 +0000 | [diff] [blame] | 662 | if (devPath) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 663 | devPath->updateBoundsCache(); |
reed@google.com | 7db9fe6 | 2011-04-11 11:57:54 +0000 | [diff] [blame] | 664 | } |
| 665 | if (fillPath) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 666 | fillPath->updateBoundsCache(); |
reed@google.com | 7db9fe6 | 2011-04-11 11:57:54 +0000 | [diff] [blame] | 667 | } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 668 | } |
| 669 | |
| 670 | |
reed@google.com | a9d4e84 | 2012-08-14 19:13:55 +0000 | [diff] [blame] | 671 | void SkScalerContextRec::getMatrixFrom2x2(SkMatrix* dst) const { |
bungeman@google.com | 50dd410 | 2013-01-14 18:25:55 +0000 | [diff] [blame] | 672 | dst->setAll(fPost2x2[0][0], fPost2x2[0][1], 0, |
| 673 | fPost2x2[1][0], fPost2x2[1][1], 0, |
reed | 3f43f8a | 2015-01-20 19:58:36 -0800 | [diff] [blame] | 674 | 0, 0, 1); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 675 | } |
| 676 | |
reed@google.com | a9d4e84 | 2012-08-14 19:13:55 +0000 | [diff] [blame] | 677 | void SkScalerContextRec::getLocalMatrix(SkMatrix* m) const { |
reed@google.com | ed43dff | 2013-06-04 16:56:27 +0000 | [diff] [blame] | 678 | SkPaint::SetTextMatrix(m, fTextSize, fPreScaleX, fPreSkewX); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 679 | } |
| 680 | |
reed@google.com | a9d4e84 | 2012-08-14 19:13:55 +0000 | [diff] [blame] | 681 | void SkScalerContextRec::getSingleMatrix(SkMatrix* m) const { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 682 | this->getLocalMatrix(m); |
| 683 | |
| 684 | // now concat the device matrix |
reed@google.com | 7db9fe6 | 2011-04-11 11:57:54 +0000 | [diff] [blame] | 685 | SkMatrix deviceMatrix; |
| 686 | this->getMatrixFrom2x2(&deviceMatrix); |
| 687 | m->postConcat(deviceMatrix); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 688 | } |
| 689 | |
bungeman | 5f14c5e | 2014-12-05 12:26:44 -0800 | [diff] [blame] | 690 | void SkScalerContextRec::computeMatrices(PreMatrixScale preMatrixScale, SkVector* s, SkMatrix* sA, |
| 691 | SkMatrix* GsA, SkMatrix* G_inv, SkMatrix* A_out) |
| 692 | { |
| 693 | // A is the 'total' matrix. |
| 694 | SkMatrix A; |
| 695 | this->getSingleMatrix(&A); |
| 696 | |
| 697 | // The caller may find the 'total' matrix useful when dealing directly with EM sizes. |
| 698 | if (A_out) { |
| 699 | *A_out = A; |
| 700 | } |
| 701 | |
bungeman | 3490263 | 2014-12-10 21:43:27 -0800 | [diff] [blame] | 702 | // If the 'total' matrix is singular, set the 'scale' to something finite and zero the matrices. |
| 703 | // All underlying ports have issues with zero text size, so use the matricies to zero. |
| 704 | |
bungeman | e37514d | 2016-02-25 11:34:10 -0800 | [diff] [blame] | 705 | // Map the vectors [0,1], [1,0], [1,1] and [1,-1] (the EM) through the 'total' matrix. |
bungeman | 3490263 | 2014-12-10 21:43:27 -0800 | [diff] [blame] | 706 | // If the length of one of these vectors is less than 1/256 then an EM filling square will |
| 707 | // never affect any pixels. |
bungeman | e37514d | 2016-02-25 11:34:10 -0800 | [diff] [blame] | 708 | SkVector diag[4] = { { A.getScaleX() , A.getSkewY() }, |
| 709 | { A.getSkewX(), A.getScaleY() }, |
| 710 | { A.getScaleX() + A.getSkewX(), A.getScaleY() + A.getSkewY() }, |
bungeman | 3490263 | 2014-12-10 21:43:27 -0800 | [diff] [blame] | 711 | { A.getScaleX() - A.getSkewX(), A.getScaleY() - A.getSkewY() }, }; |
| 712 | if (diag[0].lengthSqd() <= SK_ScalarNearlyZero * SK_ScalarNearlyZero || |
bungeman | e37514d | 2016-02-25 11:34:10 -0800 | [diff] [blame] | 713 | diag[1].lengthSqd() <= SK_ScalarNearlyZero * SK_ScalarNearlyZero || |
| 714 | diag[2].lengthSqd() <= SK_ScalarNearlyZero * SK_ScalarNearlyZero || |
| 715 | diag[3].lengthSqd() <= SK_ScalarNearlyZero * SK_ScalarNearlyZero) |
bungeman | 3490263 | 2014-12-10 21:43:27 -0800 | [diff] [blame] | 716 | { |
| 717 | s->fX = SK_Scalar1; |
| 718 | s->fY = SK_Scalar1; |
| 719 | sA->setScale(0, 0); |
| 720 | if (GsA) { |
| 721 | GsA->setScale(0, 0); |
| 722 | } |
| 723 | if (G_inv) { |
| 724 | G_inv->reset(); |
| 725 | } |
| 726 | return; |
| 727 | } |
| 728 | |
bungeman | 5f14c5e | 2014-12-05 12:26:44 -0800 | [diff] [blame] | 729 | // GA is the matrix A with rotation removed. |
| 730 | SkMatrix GA; |
| 731 | bool skewedOrFlipped = A.getSkewX() || A.getSkewY() || A.getScaleX() < 0 || A.getScaleY() < 0; |
| 732 | if (skewedOrFlipped) { |
| 733 | // h is where A maps the horizontal baseline. |
| 734 | SkPoint h = SkPoint::Make(SK_Scalar1, 0); |
| 735 | A.mapPoints(&h, 1); |
| 736 | |
| 737 | // G is the Givens Matrix for A (rotational matrix where GA[0][1] == 0). |
| 738 | SkMatrix G; |
| 739 | SkComputeGivensRotation(h, &G); |
| 740 | |
| 741 | GA = G; |
| 742 | GA.preConcat(A); |
| 743 | |
| 744 | // The 'remainingRotation' is G inverse, which is fairly simple since G is 2x2 rotational. |
| 745 | if (G_inv) { |
| 746 | G_inv->setAll( |
| 747 | G.get(SkMatrix::kMScaleX), -G.get(SkMatrix::kMSkewX), G.get(SkMatrix::kMTransX), |
| 748 | -G.get(SkMatrix::kMSkewY), G.get(SkMatrix::kMScaleY), G.get(SkMatrix::kMTransY), |
| 749 | G.get(SkMatrix::kMPersp0), G.get(SkMatrix::kMPersp1), G.get(SkMatrix::kMPersp2)); |
| 750 | } |
| 751 | } else { |
| 752 | GA = A; |
| 753 | if (G_inv) { |
| 754 | G_inv->reset(); |
| 755 | } |
| 756 | } |
| 757 | |
| 758 | // At this point, given GA, create s. |
| 759 | switch (preMatrixScale) { |
| 760 | case kFull_PreMatrixScale: |
| 761 | s->fX = SkScalarAbs(GA.get(SkMatrix::kMScaleX)); |
| 762 | s->fY = SkScalarAbs(GA.get(SkMatrix::kMScaleY)); |
| 763 | break; |
| 764 | case kVertical_PreMatrixScale: { |
| 765 | SkScalar yScale = SkScalarAbs(GA.get(SkMatrix::kMScaleY)); |
| 766 | s->fX = yScale; |
| 767 | s->fY = yScale; |
| 768 | break; |
| 769 | } |
| 770 | case kVerticalInteger_PreMatrixScale: { |
| 771 | SkScalar realYScale = SkScalarAbs(GA.get(SkMatrix::kMScaleY)); |
| 772 | SkScalar intYScale = SkScalarRoundToScalar(realYScale); |
| 773 | if (intYScale == 0) { |
| 774 | intYScale = SK_Scalar1; |
| 775 | } |
| 776 | s->fX = intYScale; |
| 777 | s->fY = intYScale; |
| 778 | break; |
| 779 | } |
| 780 | } |
| 781 | |
| 782 | // The 'remaining' matrix sA is the total matrix A without the scale. |
bungeman | 3490263 | 2014-12-10 21:43:27 -0800 | [diff] [blame] | 783 | if (!skewedOrFlipped && ( |
| 784 | (kFull_PreMatrixScale == preMatrixScale) || |
| 785 | (kVertical_PreMatrixScale == preMatrixScale && A.getScaleX() == A.getScaleY()))) |
| 786 | { |
bungeman | 5f14c5e | 2014-12-05 12:26:44 -0800 | [diff] [blame] | 787 | // If GA == A and kFull_PreMatrixScale, sA is identity. |
bungeman | 3490263 | 2014-12-10 21:43:27 -0800 | [diff] [blame] | 788 | // If GA == A and kVertical_PreMatrixScale and A.scaleX == A.scaleY, sA is identity. |
bungeman | 5f14c5e | 2014-12-05 12:26:44 -0800 | [diff] [blame] | 789 | sA->reset(); |
bungeman | 3490263 | 2014-12-10 21:43:27 -0800 | [diff] [blame] | 790 | } else if (!skewedOrFlipped && kVertical_PreMatrixScale == preMatrixScale) { |
| 791 | // If GA == A and kVertical_PreMatrixScale, sA.scaleY is SK_Scalar1. |
| 792 | sA->reset(); |
| 793 | sA->setScaleX(A.getScaleX() / s->fY); |
bungeman | 5f14c5e | 2014-12-05 12:26:44 -0800 | [diff] [blame] | 794 | } else { |
bungeman | 5f14c5e | 2014-12-05 12:26:44 -0800 | [diff] [blame] | 795 | // TODO: like kVertical_PreMatrixScale, kVerticalInteger_PreMatrixScale with int scales. |
| 796 | *sA = A; |
| 797 | sA->preScale(SkScalarInvert(s->fX), SkScalarInvert(s->fY)); |
| 798 | } |
| 799 | |
| 800 | // The 'remainingWithoutRotation' matrix GsA is the non-rotational part of A without the scale. |
| 801 | if (GsA) { |
| 802 | *GsA = GA; |
| 803 | // G is rotational so reorders with the scale. |
| 804 | GsA->preScale(SkScalarInvert(s->fX), SkScalarInvert(s->fY)); |
| 805 | } |
| 806 | } |
| 807 | |
bungeman | 27876bc | 2016-02-29 11:22:55 -0800 | [diff] [blame] | 808 | SkAxisAlignment SkScalerContext::computeAxisAlignmentForHText() { |
| 809 | // Why fPost2x2 can be used here. |
| 810 | // getSingleMatrix multiplies in getLocalMatrix, which consists of |
| 811 | // * fTextSize (a scale, which has no effect) |
| 812 | // * fPreScaleX (a scale in x, which has no effect) |
| 813 | // * fPreSkewX (has no effect, but would on vertical text alignment). |
| 814 | // In other words, making the text bigger, stretching it along the |
| 815 | // horizontal axis, or fake italicizing it does not move the baseline. |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 816 | |
bungeman | 27876bc | 2016-02-29 11:22:55 -0800 | [diff] [blame] | 817 | if (0 == fRec.fPost2x2[1][0]) { |
| 818 | // The x axis is mapped onto the x axis. |
reed@google.com | 2e68478 | 2011-08-24 15:38:46 +0000 | [diff] [blame] | 819 | return kX_SkAxisAlignment; |
| 820 | } |
bungeman | 27876bc | 2016-02-29 11:22:55 -0800 | [diff] [blame] | 821 | if (0 == fRec.fPost2x2[0][0]) { |
| 822 | // The x axis is mapped onto the y axis. |
reed@google.com | 2e68478 | 2011-08-24 15:38:46 +0000 | [diff] [blame] | 823 | return kY_SkAxisAlignment; |
| 824 | } |
| 825 | return kNone_SkAxisAlignment; |
| 826 | } |
| 827 | |
reed@android.com | 62900b4 | 2009-02-11 15:07:19 +0000 | [diff] [blame] | 828 | /////////////////////////////////////////////////////////////////////////////// |
| 829 | |
reed@android.com | 62900b4 | 2009-02-11 15:07:19 +0000 | [diff] [blame] | 830 | class SkScalerContext_Empty : public SkScalerContext { |
| 831 | public: |
reed | a9322c2 | 2016-04-12 06:47:05 -0700 | [diff] [blame] | 832 | SkScalerContext_Empty(SkTypeface* typeface, const SkScalerContextEffects& effects, |
| 833 | const SkDescriptor* desc) |
| 834 | : SkScalerContext(typeface, effects, desc) {} |
reed@android.com | 62900b4 | 2009-02-11 15:07:19 +0000 | [diff] [blame] | 835 | |
| 836 | protected: |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 837 | unsigned generateGlyphCount() override { |
reed@android.com | 62900b4 | 2009-02-11 15:07:19 +0000 | [diff] [blame] | 838 | return 0; |
| 839 | } |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 840 | uint16_t generateCharToGlyph(SkUnichar uni) override { |
reed@android.com | 62900b4 | 2009-02-11 15:07:19 +0000 | [diff] [blame] | 841 | return 0; |
| 842 | } |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 843 | void generateAdvance(SkGlyph* glyph) override { |
reed@android.com | 62900b4 | 2009-02-11 15:07:19 +0000 | [diff] [blame] | 844 | glyph->zeroMetrics(); |
| 845 | } |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 846 | void generateMetrics(SkGlyph* glyph) override { |
reed@android.com | 62900b4 | 2009-02-11 15:07:19 +0000 | [diff] [blame] | 847 | glyph->zeroMetrics(); |
| 848 | } |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 849 | void generateImage(const SkGlyph& glyph) override {} |
| 850 | void generatePath(const SkGlyph& glyph, SkPath* path) override {} |
| 851 | void generateFontMetrics(SkPaint::FontMetrics* metrics) override { |
bungeman | 4107806 | 2014-07-07 08:16:37 -0700 | [diff] [blame] | 852 | if (metrics) { |
| 853 | sk_bzero(metrics, sizeof(*metrics)); |
reed@android.com | 62900b4 | 2009-02-11 15:07:19 +0000 | [diff] [blame] | 854 | } |
| 855 | } |
| 856 | }; |
| 857 | |
reed@android.com | f2b98d6 | 2010-12-20 18:26:13 +0000 | [diff] [blame] | 858 | extern SkScalerContext* SkCreateColorScalerContext(const SkDescriptor* desc); |
| 859 | |
reed | a9322c2 | 2016-04-12 06:47:05 -0700 | [diff] [blame] | 860 | SkScalerContext* SkTypeface::createScalerContext(const SkScalerContextEffects& effects, |
| 861 | const SkDescriptor* desc, |
reed@google.com | 84e22d8 | 2013-07-10 15:38:20 +0000 | [diff] [blame] | 862 | bool allowFailure) const { |
reed | a9322c2 | 2016-04-12 06:47:05 -0700 | [diff] [blame] | 863 | SkScalerContext* c = this->onCreateScalerContext(effects, desc); |
reed@google.com | 84e22d8 | 2013-07-10 15:38:20 +0000 | [diff] [blame] | 864 | |
| 865 | if (!c && !allowFailure) { |
reed | a9322c2 | 2016-04-12 06:47:05 -0700 | [diff] [blame] | 866 | c = new SkScalerContext_Empty(const_cast<SkTypeface*>(this), effects, desc); |
reed@android.com | 62900b4 | 2009-02-11 15:07:19 +0000 | [diff] [blame] | 867 | } |
| 868 | return c; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 869 | } |