| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2014 Google Inc. | 2 * Copyright 2014 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #include "GrPathRendering.h" | 8 #include "GrPathRendering.h" |
| 9 #include "SkDescriptor.h" | 9 #include "SkDescriptor.h" |
| 10 #include "SkGlyph.h" | 10 #include "SkGlyph.h" |
| 11 #include "SkMatrix.h" | 11 #include "SkMatrix.h" |
| 12 #include "SkTypeface.h" | 12 #include "SkTypeface.h" |
| 13 #include "GrPathRange.h" | 13 #include "GrPathRange.h" |
| 14 | 14 |
| 15 class GlyphGenerator : public GrPathRange::PathGenerator { | 15 class GlyphGenerator : public GrPathRange::PathGenerator { |
| 16 public: | 16 public: |
| 17 GlyphGenerator(const SkTypeface& typeface, const SkScalerContextEffects& eff
ects, | 17 GlyphGenerator(const SkTypeface& typeface, const SkDescriptor& desc) |
| 18 const SkDescriptor& desc) | 18 : fScalerContext(typeface.createScalerContext(&desc)) |
| 19 : fScalerContext(typeface.createScalerContext(effects, &desc)) | |
| 20 #ifdef SK_DEBUG | 19 #ifdef SK_DEBUG |
| 21 , fDesc(desc.copy()) | 20 , fDesc(desc.copy()) |
| 22 #endif | 21 #endif |
| 23 {} | 22 {} |
| 24 | 23 |
| 25 virtual ~GlyphGenerator() { | 24 virtual ~GlyphGenerator() { |
| 26 #ifdef SK_DEBUG | 25 #ifdef SK_DEBUG |
| 27 SkDescriptor::Free(fDesc); | 26 SkDescriptor::Free(fDesc); |
| 28 #endif | 27 #endif |
| 29 } | 28 } |
| (...skipping 15 matching lines...) Expand all Loading... |
| 45 } | 44 } |
| 46 #endif | 45 #endif |
| 47 private: | 46 private: |
| 48 const SkAutoTDelete<SkScalerContext> fScalerContext; | 47 const SkAutoTDelete<SkScalerContext> fScalerContext; |
| 49 #ifdef SK_DEBUG | 48 #ifdef SK_DEBUG |
| 50 SkDescriptor* const fDesc; | 49 SkDescriptor* const fDesc; |
| 51 #endif | 50 #endif |
| 52 }; | 51 }; |
| 53 | 52 |
| 54 GrPathRange* GrPathRendering::createGlyphs(const SkTypeface* typeface, | 53 GrPathRange* GrPathRendering::createGlyphs(const SkTypeface* typeface, |
| 55 const SkScalerContextEffects& effects
, | |
| 56 const SkDescriptor* desc, | 54 const SkDescriptor* desc, |
| 57 const GrStrokeInfo& stroke) { | 55 const GrStrokeInfo& stroke) { |
| 58 if (nullptr == typeface) { | 56 if (nullptr == typeface) { |
| 59 typeface = SkTypeface::GetDefaultTypeface(); | 57 typeface = SkTypeface::GetDefaultTypeface(); |
| 60 SkASSERT(nullptr != typeface); | 58 SkASSERT(nullptr != typeface); |
| 61 } | 59 } |
| 62 | 60 |
| 63 if (desc) { | 61 if (desc) { |
| 64 SkAutoTUnref<GlyphGenerator> generator(new GlyphGenerator(*typeface, eff
ects, *desc)); | 62 SkAutoTUnref<GlyphGenerator> generator(new GlyphGenerator(*typeface, *de
sc)); |
| 65 return this->createPathRange(generator, stroke); | 63 return this->createPathRange(generator, stroke); |
| 66 } | 64 } |
| 67 | 65 |
| 68 SkScalerContextRec rec; | 66 SkScalerContextRec rec; |
| 69 memset(&rec, 0, sizeof(rec)); | 67 memset(&rec, 0, sizeof(rec)); |
| 70 rec.fFontID = typeface->uniqueID(); | 68 rec.fFontID = typeface->uniqueID(); |
| 71 rec.fTextSize = SkPaint::kCanonicalTextSizeForPaths; | 69 rec.fTextSize = SkPaint::kCanonicalTextSizeForPaths; |
| 72 rec.fPreScaleX = rec.fPost2x2[0][0] = rec.fPost2x2[1][1] = SK_Scalar1; | 70 rec.fPreScaleX = rec.fPost2x2[0][0] = rec.fPost2x2[1][1] = SK_Scalar1; |
| 73 // Don't bake stroke information into the glyphs, we'll let the GPU do the s
troking. | 71 // Don't bake stroke information into the glyphs, we'll let the GPU do the s
troking. |
| 74 | 72 |
| 75 SkAutoDescriptor ad(sizeof(rec) + SkDescriptor::ComputeOverhead(1)); | 73 SkAutoDescriptor ad(sizeof(rec) + SkDescriptor::ComputeOverhead(1)); |
| 76 SkDescriptor* genericDesc = ad.getDesc(); | 74 SkDescriptor* genericDesc = ad.getDesc(); |
| 77 | 75 |
| 78 genericDesc->init(); | 76 genericDesc->init(); |
| 79 genericDesc->addEntry(kRec_SkDescriptorTag, sizeof(rec), &rec); | 77 genericDesc->addEntry(kRec_SkDescriptorTag, sizeof(rec), &rec); |
| 80 genericDesc->computeChecksum(); | 78 genericDesc->computeChecksum(); |
| 81 | |
| 82 // No effects, so we make a dummy struct | |
| 83 SkScalerContextEffects noEffects; | |
| 84 | 79 |
| 85 SkAutoTUnref<GlyphGenerator> generator(new GlyphGenerator(*typeface, noEffec
ts, *genericDesc)); | 80 SkAutoTUnref<GlyphGenerator> generator(new GlyphGenerator(*typeface, *generi
cDesc)); |
| 86 return this->createPathRange(generator, stroke); | 81 return this->createPathRange(generator, stroke); |
| 87 } | 82 } |
| OLD | NEW |