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 SkDescriptor& desc) | 17 GlyphGenerator(const SkTypeface& typeface, const SkScalerContextEffects& eff
ects, |
18 : fScalerContext(typeface.createScalerContext(&desc)) | 18 const SkDescriptor& desc) |
| 19 : fScalerContext(typeface.createScalerContext(effects, &desc)) |
19 #ifdef SK_DEBUG | 20 #ifdef SK_DEBUG |
20 , fDesc(desc.copy()) | 21 , fDesc(desc.copy()) |
21 #endif | 22 #endif |
22 {} | 23 {} |
23 | 24 |
24 virtual ~GlyphGenerator() { | 25 virtual ~GlyphGenerator() { |
25 #ifdef SK_DEBUG | 26 #ifdef SK_DEBUG |
26 SkDescriptor::Free(fDesc); | 27 SkDescriptor::Free(fDesc); |
27 #endif | 28 #endif |
28 } | 29 } |
(...skipping 15 matching lines...) Expand all Loading... |
44 } | 45 } |
45 #endif | 46 #endif |
46 private: | 47 private: |
47 const SkAutoTDelete<SkScalerContext> fScalerContext; | 48 const SkAutoTDelete<SkScalerContext> fScalerContext; |
48 #ifdef SK_DEBUG | 49 #ifdef SK_DEBUG |
49 SkDescriptor* const fDesc; | 50 SkDescriptor* const fDesc; |
50 #endif | 51 #endif |
51 }; | 52 }; |
52 | 53 |
53 GrPathRange* GrPathRendering::createGlyphs(const SkTypeface* typeface, | 54 GrPathRange* GrPathRendering::createGlyphs(const SkTypeface* typeface, |
| 55 const SkScalerContextEffects& effects
, |
54 const SkDescriptor* desc, | 56 const SkDescriptor* desc, |
55 const GrStrokeInfo& stroke) { | 57 const GrStrokeInfo& stroke) { |
56 if (nullptr == typeface) { | 58 if (nullptr == typeface) { |
57 typeface = SkTypeface::GetDefaultTypeface(); | 59 typeface = SkTypeface::GetDefaultTypeface(); |
58 SkASSERT(nullptr != typeface); | 60 SkASSERT(nullptr != typeface); |
59 } | 61 } |
60 | 62 |
61 if (desc) { | 63 if (desc) { |
62 SkAutoTUnref<GlyphGenerator> generator(new GlyphGenerator(*typeface, *de
sc)); | 64 SkAutoTUnref<GlyphGenerator> generator(new GlyphGenerator(*typeface, eff
ects, *desc)); |
63 return this->createPathRange(generator, stroke); | 65 return this->createPathRange(generator, stroke); |
64 } | 66 } |
65 | 67 |
66 SkScalerContextRec rec; | 68 SkScalerContextRec rec; |
67 memset(&rec, 0, sizeof(rec)); | 69 memset(&rec, 0, sizeof(rec)); |
68 rec.fFontID = typeface->uniqueID(); | 70 rec.fFontID = typeface->uniqueID(); |
69 rec.fTextSize = SkPaint::kCanonicalTextSizeForPaths; | 71 rec.fTextSize = SkPaint::kCanonicalTextSizeForPaths; |
70 rec.fPreScaleX = rec.fPost2x2[0][0] = rec.fPost2x2[1][1] = SK_Scalar1; | 72 rec.fPreScaleX = rec.fPost2x2[0][0] = rec.fPost2x2[1][1] = SK_Scalar1; |
71 // Don't bake stroke information into the glyphs, we'll let the GPU do the s
troking. | 73 // Don't bake stroke information into the glyphs, we'll let the GPU do the s
troking. |
72 | 74 |
73 SkAutoDescriptor ad(sizeof(rec) + SkDescriptor::ComputeOverhead(1)); | 75 SkAutoDescriptor ad(sizeof(rec) + SkDescriptor::ComputeOverhead(1)); |
74 SkDescriptor* genericDesc = ad.getDesc(); | 76 SkDescriptor* genericDesc = ad.getDesc(); |
75 | 77 |
76 genericDesc->init(); | 78 genericDesc->init(); |
77 genericDesc->addEntry(kRec_SkDescriptorTag, sizeof(rec), &rec); | 79 genericDesc->addEntry(kRec_SkDescriptorTag, sizeof(rec), &rec); |
78 genericDesc->computeChecksum(); | 80 genericDesc->computeChecksum(); |
| 81 |
| 82 // No effects, so we make a dummy struct |
| 83 SkScalerContextEffects noEffects; |
79 | 84 |
80 SkAutoTUnref<GlyphGenerator> generator(new GlyphGenerator(*typeface, *generi
cDesc)); | 85 SkAutoTUnref<GlyphGenerator> generator(new GlyphGenerator(*typeface, noEffec
ts, *genericDesc)); |
81 return this->createPathRange(generator, stroke); | 86 return this->createPathRange(generator, stroke); |
82 } | 87 } |
OLD | NEW |