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 GrDistanceFieldTextContext::GrDistanceFieldTextContext(GrContext* context, | 43 GrDistanceFieldTextContext::GrDistanceFieldTextContext(GrContext* context, |
44 const SkDeviceProperties&
properties, | 44 const SkDeviceProperties&
properties, |
45 bool enable) | 45 bool enable) |
46 : GrTextContext(context, pro
perties) { | 46 : GrTextContext(context, pro
perties) { |
47 #if SK_FORCE_DISTANCE_FIELD_TEXT | 47 #if SK_FORCE_DISTANCE_FIELD_TEXT |
48 fEnableDFRendering = true; | 48 fEnableDFRendering = true; |
(...skipping 24 matching lines...) Expand all Loading... |
73 textContext->fFallbackTextContext = GrBitmapTextContext::Create(context, pro
ps); | 73 textContext->fFallbackTextContext = GrBitmapTextContext::Create(context, pro
ps); |
74 | 74 |
75 return textContext; | 75 return textContext; |
76 } | 76 } |
77 | 77 |
78 GrDistanceFieldTextContext::~GrDistanceFieldTextContext() { | 78 GrDistanceFieldTextContext::~GrDistanceFieldTextContext() { |
79 SkSafeSetNull(fGammaTexture); | 79 SkSafeSetNull(fGammaTexture); |
80 } | 80 } |
81 | 81 |
82 bool GrDistanceFieldTextContext::canDraw(const SkPaint& paint, const SkMatrix& v
iewMatrix) { | 82 bool GrDistanceFieldTextContext::canDraw(const SkPaint& paint, const SkMatrix& v
iewMatrix) { |
83 if (!fEnableDFRendering && !paint.isDistanceFieldTextTEMP()) { | 83 // TODO: support perspective (need getMaxScale replacement) |
| 84 if (viewMatrix.hasPerspective()) { |
84 return false; | 85 return false; |
85 } | 86 } |
86 | 87 |
| 88 SkScalar maxScale = viewMatrix.getMaxScale(); |
| 89 SkScalar scaledTextSize = maxScale*paint.getTextSize(); |
| 90 // Scaling up beyond 2x yields undesireable artifacts |
| 91 if (scaledTextSize > 2*kLargeDFFontSize) { |
| 92 return false; |
| 93 } |
| 94 |
| 95 if (!fEnableDFRendering && !paint.isDistanceFieldTextTEMP() && |
| 96 scaledTextSize < kLargeDFFontSize) { |
| 97 return false; |
| 98 } |
| 99 |
87 // rasterizers and mask filters modify alpha, which doesn't | 100 // rasterizers and mask filters modify alpha, which doesn't |
88 // translate well to distance | 101 // translate well to distance |
89 if (paint.getRasterizer() || paint.getMaskFilter() || | 102 if (paint.getRasterizer() || paint.getMaskFilter() || |
90 !fContext->getTextTarget()->caps()->shaderDerivativeSupport()) { | 103 !fContext->getTextTarget()->caps()->shaderDerivativeSupport()) { |
91 return false; | 104 return false; |
92 } | 105 } |
93 | 106 |
94 // TODO: add some stroking support | 107 // TODO: add some stroking support |
95 if (paint.getStyle() != SkPaint::kFill_Style) { | 108 if (paint.getStyle() != SkPaint::kFill_Style) { |
96 return false; | 109 return false; |
97 } | 110 } |
98 | 111 |
99 // TODO: choose an appropriate maximum scale for distance fields and | |
100 // enable perspective | |
101 if (SkDraw::ShouldDrawTextAsPaths(paint, viewMatrix)) { | |
102 return false; | |
103 } | |
104 | |
105 return true; | 112 return true; |
106 } | 113 } |
107 | 114 |
108 inline void GrDistanceFieldTextContext::init(const GrPaint& paint, const SkPaint
& skPaint) { | 115 inline void GrDistanceFieldTextContext::init(const GrPaint& paint, const SkPaint
& skPaint) { |
109 GrTextContext::init(paint, skPaint); | 116 GrTextContext::init(paint, skPaint); |
110 | 117 |
111 fStrike = NULL; | 118 fStrike = NULL; |
112 | 119 |
113 const SkMatrix& ctm = fViewMatrix; | 120 const SkMatrix& ctm = fViewMatrix; |
114 | 121 |
(...skipping 569 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
684 } | 691 } |
685 } | 692 } |
686 | 693 |
687 inline void GrDistanceFieldTextContext::finish() { | 694 inline void GrDistanceFieldTextContext::finish() { |
688 this->flush(); | 695 this->flush(); |
689 fTotalVertexCount = 0; | 696 fTotalVertexCount = 0; |
690 | 697 |
691 GrTextContext::finish(); | 698 GrTextContext::finish(); |
692 } | 699 } |
693 | 700 |
OLD | NEW |