OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright 2013 Google Inc. | 2 * Copyright 2013 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 "GrDistanceFieldTextContext.h" | 8 #include "GrDistanceFieldTextContext.h" |
9 #include "GrAtlas.h" | 9 #include "GrAtlas.h" |
10 #include "GrBitmapTextContext.h" | 10 #include "GrBitmapTextContext.h" |
(...skipping 15 matching lines...) Expand all Loading... | |
26 #include "SkPath.h" | 26 #include "SkPath.h" |
27 #include "SkRTConf.h" | 27 #include "SkRTConf.h" |
28 #include "SkStrokeRec.h" | 28 #include "SkStrokeRec.h" |
29 #include "effects/GrDistanceFieldTextureEffect.h" | 29 #include "effects/GrDistanceFieldTextureEffect.h" |
30 | 30 |
31 SK_CONF_DECLARE(bool, c_DumpFontCache, "gpu.dumpFontCache", false, | 31 SK_CONF_DECLARE(bool, c_DumpFontCache, "gpu.dumpFontCache", false, |
32 "Dump the contents of the font cache before every purge."); | 32 "Dump the contents of the font cache before every purge."); |
33 | 33 |
34 static const int kSmallDFFontSize = 32; | 34 static const int kSmallDFFontSize = 32; |
35 static const int kSmallDFFontLimit = 32; | 35 static const int kSmallDFFontLimit = 32; |
36 static const int kMediumDFFontSize = 64; | 36 static const int kMediumDFFontSize = 78; |
37 static const int kMediumDFFontLimit = 64; | 37 static const int kMediumDFFontLimit = 78; |
38 static const int kLargeDFFontSize = 128; | 38 static const int kLargeDFFontSize = 192; |
39 | 39 |
40 static const int kVerticesPerGlyph = 4; | 40 static const int kVerticesPerGlyph = 4; |
41 static const int kIndicesPerGlyph = 6; | 41 static const int kIndicesPerGlyph = 6; |
42 | 42 |
43 static const int kMaxFontCacheSize = 256; | |
44 | |
43 GrDistanceFieldTextContext::GrDistanceFieldTextContext(GrContext* context, | 45 GrDistanceFieldTextContext::GrDistanceFieldTextContext(GrContext* context, |
44 const SkDeviceProperties& properties, | 46 const SkDeviceProperties& properties, |
45 bool enable) | 47 bool enable) |
46 : GrTextContext(context, pro perties) { | 48 : GrTextContext(context, pro perties) { |
47 #if SK_FORCE_DISTANCE_FIELD_TEXT | 49 #if SK_FORCE_DISTANCE_FIELD_TEXT |
48 fEnableDFRendering = true; | 50 fEnableDFRendering = true; |
49 #else | 51 #else |
50 fEnableDFRendering = enable; | 52 fEnableDFRendering = enable; |
51 #endif | 53 #endif |
52 fStrike = NULL; | 54 fStrike = NULL; |
(...skipping 20 matching lines...) Expand all Loading... | |
73 textContext->fFallbackTextContext = GrBitmapTextContext::Create(context, pro ps); | 75 textContext->fFallbackTextContext = GrBitmapTextContext::Create(context, pro ps); |
74 | 76 |
75 return textContext; | 77 return textContext; |
76 } | 78 } |
77 | 79 |
78 GrDistanceFieldTextContext::~GrDistanceFieldTextContext() { | 80 GrDistanceFieldTextContext::~GrDistanceFieldTextContext() { |
79 SkSafeSetNull(fGammaTexture); | 81 SkSafeSetNull(fGammaTexture); |
80 } | 82 } |
81 | 83 |
82 bool GrDistanceFieldTextContext::canDraw(const SkPaint& paint, const SkMatrix& v iewMatrix) { | 84 bool GrDistanceFieldTextContext::canDraw(const SkPaint& paint, const SkMatrix& v iewMatrix) { |
83 if (!fEnableDFRendering && !paint.isDistanceFieldTextTEMP()) { | 85 // TODO: support perspective (need getMaxScale replacement) |
86 if (viewMatrix.hasPerspective()) { | |
84 return false; | 87 return false; |
85 } | 88 } |
86 | 89 |
90 SkScalar maxScale = viewMatrix.getMaxScale(); | |
91 SkScalar scaledTextSize = maxScale*paint.getTextSize(); | |
robertphillips
2015/01/28 00:03:16
// Scaling up beyond 2x yields undesireable artifa
jvanverth1
2015/01/28 17:47:38
Done.
| |
92 if (scaledTextSize > 2*kLargeDFFontSize) { | |
93 return false; | |
94 } | |
95 | |
96 if (!fEnableDFRendering && !paint.isDistanceFieldTextTEMP() && | |
97 scaledTextSize < kMaxFontCacheSize) { | |
98 return false; | |
99 } | |
100 | |
87 // rasterizers and mask filters modify alpha, which doesn't | 101 // rasterizers and mask filters modify alpha, which doesn't |
88 // translate well to distance | 102 // translate well to distance |
89 if (paint.getRasterizer() || paint.getMaskFilter() || | 103 if (paint.getRasterizer() || paint.getMaskFilter() || |
90 !fContext->getTextTarget()->caps()->shaderDerivativeSupport()) { | 104 !fContext->getTextTarget()->caps()->shaderDerivativeSupport()) { |
91 return false; | 105 return false; |
92 } | 106 } |
93 | 107 |
94 // TODO: add some stroking support | 108 // TODO: add some stroking support |
95 if (paint.getStyle() != SkPaint::kFill_Style) { | 109 if (paint.getStyle() != SkPaint::kFill_Style) { |
96 return false; | 110 return false; |
97 } | 111 } |
98 | 112 |
99 // TODO: choose an appropriate maximum scale for distance fields and | |
100 // enable perspective | |
robertphillips
2015/01/28 00:03:16
Is ShouldDrawTextAsPaths still used anywhere?
jvanverth1
2015/01/28 17:47:38
It's still used in BitmapTextContext, and in raste
| |
101 if (SkDraw::ShouldDrawTextAsPaths(paint, viewMatrix)) { | |
102 return false; | |
103 } | |
104 | |
105 return true; | 113 return true; |
106 } | 114 } |
107 | 115 |
108 inline void GrDistanceFieldTextContext::init(const GrPaint& paint, const SkPaint & skPaint) { | 116 inline void GrDistanceFieldTextContext::init(const GrPaint& paint, const SkPaint & skPaint) { |
109 GrTextContext::init(paint, skPaint); | 117 GrTextContext::init(paint, skPaint); |
110 | 118 |
111 fStrike = NULL; | 119 fStrike = NULL; |
112 | 120 |
113 const SkMatrix& ctm = fViewMatrix; | 121 const SkMatrix& ctm = fViewMatrix; |
114 | 122 |
(...skipping 569 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
684 } | 692 } |
685 } | 693 } |
686 | 694 |
687 inline void GrDistanceFieldTextContext::finish() { | 695 inline void GrDistanceFieldTextContext::finish() { |
688 this->flush(); | 696 this->flush(); |
689 fTotalVertexCount = 0; | 697 fTotalVertexCount = 0; |
690 | 698 |
691 GrTextContext::finish(); | 699 GrTextContext::finish(); |
692 } | 700 } |
693 | 701 |
OLD | NEW |