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 SkDescriptor& desc) |
18 : fDesc(desc.copy()), | 18 : fScalerContext(typeface.createScalerContext(&desc)) |
19 fScalerContext(typeface.createScalerContext(fDesc)) { | 19 #ifdef SK_DEBUG |
| 20 , fDesc(desc.copy()) |
| 21 #endif |
| 22 { |
20 fFlipMatrix.setScale(1, -1); | 23 fFlipMatrix.setScale(1, -1); |
21 } | 24 } |
22 | 25 |
23 virtual ~GlyphGenerator() { | 26 virtual ~GlyphGenerator() { |
| 27 #ifdef SK_DEBUG |
24 SkDescriptor::Free(fDesc); | 28 SkDescriptor::Free(fDesc); |
| 29 #endif |
25 } | 30 } |
26 | 31 |
27 int getNumPaths() override { | 32 int getNumPaths() override { |
28 return fScalerContext->getGlyphCount(); | 33 return fScalerContext->getGlyphCount(); |
29 } | 34 } |
30 | 35 |
31 void generatePath(int glyphID, SkPath* out) override { | 36 void generatePath(int glyphID, SkPath* out) override { |
32 SkGlyph skGlyph; | 37 SkGlyph skGlyph; |
33 skGlyph.initWithGlyphID(glyphID); | 38 skGlyph.initWithGlyphID(glyphID); |
34 fScalerContext->getMetrics(&skGlyph); | 39 fScalerContext->getMetrics(&skGlyph); |
35 | 40 |
36 fScalerContext->getPath(skGlyph, out); | 41 fScalerContext->getPath(skGlyph, out); |
37 out->transform(fFlipMatrix); // Load glyphs with the inverted y-directio
n. | 42 out->transform(fFlipMatrix); // Load glyphs with the inverted y-directio
n. |
38 } | 43 } |
39 | 44 #ifdef SK_DEBUG |
40 bool isEqualTo(const SkDescriptor& desc) const override { | 45 bool isEqualTo(const SkDescriptor& desc) const override { |
41 return fDesc->equals(desc); | 46 return fDesc->equals(desc); |
42 } | 47 } |
43 | 48 #endif |
44 private: | 49 private: |
45 SkDescriptor* const fDesc; | |
46 const SkAutoTDelete<SkScalerContext> fScalerContext; | 50 const SkAutoTDelete<SkScalerContext> fScalerContext; |
47 SkMatrix fFlipMatrix; | 51 SkMatrix fFlipMatrix; |
| 52 #ifdef SK_DEBUG |
| 53 SkDescriptor* const fDesc; |
| 54 #endif |
48 }; | 55 }; |
49 | 56 |
50 GrPathRange* GrPathRendering::createGlyphs(const SkTypeface* typeface, | 57 GrPathRange* GrPathRendering::createGlyphs(const SkTypeface* typeface, |
51 const SkDescriptor* desc, | 58 const SkDescriptor* desc, |
52 const SkStrokeRec& stroke) { | 59 const GrStrokeInfo& stroke) { |
53 if (NULL == typeface) { | 60 if (NULL == typeface) { |
54 typeface = SkTypeface::GetDefaultTypeface(); | 61 typeface = SkTypeface::GetDefaultTypeface(); |
55 SkASSERT(NULL != typeface); | 62 SkASSERT(NULL != typeface); |
56 } | 63 } |
57 | 64 |
58 if (desc) { | 65 if (desc) { |
59 SkAutoTUnref<GlyphGenerator> generator(SkNEW_ARGS(GlyphGenerator, (*type
face, *desc))); | 66 SkAutoTUnref<GlyphGenerator> generator(SkNEW_ARGS(GlyphGenerator, (*type
face, *desc))); |
60 return this->createPathRange(generator, stroke); | 67 return this->createPathRange(generator, stroke); |
61 } | 68 } |
62 | 69 |
63 SkScalerContextRec rec; | 70 SkScalerContextRec rec; |
64 memset(&rec, 0, sizeof(rec)); | 71 memset(&rec, 0, sizeof(rec)); |
65 rec.fFontID = typeface->uniqueID(); | 72 rec.fFontID = typeface->uniqueID(); |
66 rec.fTextSize = SkPaint::kCanonicalTextSizeForPaths; | 73 rec.fTextSize = SkPaint::kCanonicalTextSizeForPaths; |
67 rec.fPreScaleX = rec.fPost2x2[0][0] = rec.fPost2x2[1][1] = SK_Scalar1; | 74 rec.fPreScaleX = rec.fPost2x2[0][0] = rec.fPost2x2[1][1] = SK_Scalar1; |
68 // Don't bake stroke information into the glyphs, we'll let the GPU do the s
troking. | 75 // Don't bake stroke information into the glyphs, we'll let the GPU do the s
troking. |
69 | 76 |
70 SkAutoDescriptor ad(sizeof(rec) + SkDescriptor::ComputeOverhead(1)); | 77 SkAutoDescriptor ad(sizeof(rec) + SkDescriptor::ComputeOverhead(1)); |
71 SkDescriptor* genericDesc = ad.getDesc(); | 78 SkDescriptor* genericDesc = ad.getDesc(); |
72 | 79 |
73 genericDesc->init(); | 80 genericDesc->init(); |
74 genericDesc->addEntry(kRec_SkDescriptorTag, sizeof(rec), &rec); | 81 genericDesc->addEntry(kRec_SkDescriptorTag, sizeof(rec), &rec); |
75 genericDesc->computeChecksum(); | 82 genericDesc->computeChecksum(); |
76 | 83 |
77 SkAutoTUnref<GlyphGenerator> generator(SkNEW_ARGS(GlyphGenerator, (*typeface
, *genericDesc))); | 84 SkAutoTUnref<GlyphGenerator> generator(SkNEW_ARGS(GlyphGenerator, (*typeface
, *genericDesc))); |
78 return this->createPathRange(generator, stroke); | 85 return this->createPathRange(generator, stroke); |
79 } | 86 } |
OLD | NEW |