| 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 14 matching lines...) Expand all Loading... |
| 25 #include "SkGlyphCache.h" | 25 #include "SkGlyphCache.h" |
| 26 #include "SkGpuDevice.h" | 26 #include "SkGpuDevice.h" |
| 27 #include "SkPath.h" | 27 #include "SkPath.h" |
| 28 #include "SkRTConf.h" | 28 #include "SkRTConf.h" |
| 29 #include "SkStrokeRec.h" | 29 #include "SkStrokeRec.h" |
| 30 #include "effects/GrDistanceFieldTextureEffect.h" | 30 #include "effects/GrDistanceFieldTextureEffect.h" |
| 31 | 31 |
| 32 SK_CONF_DECLARE(bool, c_DumpFontCache, "gpu.dumpFontCache", false, | 32 SK_CONF_DECLARE(bool, c_DumpFontCache, "gpu.dumpFontCache", false, |
| 33 "Dump the contents of the font cache before every purge."); | 33 "Dump the contents of the font cache before every purge."); |
| 34 | 34 |
| 35 static const int kSmallDFFontSize = 32; | 35 static const int kMinDFFontSize = 18; |
| 36 static const int kSmallDFFontLimit = 32; | 36 static const int kSmallDFFontSize = 40; |
| 37 static const int kMediumDFFontSize = 72; | 37 static const int kSmallDFFontLimit = 40; |
| 38 static const int kMediumDFFontLimit = 72; | 38 static const int kMediumDFFontSize = 81; |
| 39 static const int kMediumDFFontLimit = 81; |
| 39 static const int kLargeDFFontSize = 162; | 40 static const int kLargeDFFontSize = 162; |
| 40 | 41 |
| 41 static const int kVerticesPerGlyph = 4; | 42 static const int kVerticesPerGlyph = 4; |
| 42 static const int kIndicesPerGlyph = 6; | 43 static const int kIndicesPerGlyph = 6; |
| 43 | 44 |
| 44 GrDistanceFieldTextContext::GrDistanceFieldTextContext(GrContext* context, | 45 GrDistanceFieldTextContext::GrDistanceFieldTextContext(GrContext* context, |
| 45 const SkDeviceProperties&
properties, | 46 const SkDeviceProperties&
properties, |
| 46 bool enable) | 47 bool enable) |
| 47 : GrTextContext(context, pro
perties) { | 48 : GrTextContext(context, pro
perties) { |
| 48 #if SK_FORCE_DISTANCE_FIELD_TEXT | 49 #if SK_FORCE_DISTANCE_FIELD_TEXT |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 81 } | 82 } |
| 82 | 83 |
| 83 bool GrDistanceFieldTextContext::canDraw(const SkPaint& paint, const SkMatrix& v
iewMatrix) { | 84 bool GrDistanceFieldTextContext::canDraw(const SkPaint& paint, const SkMatrix& v
iewMatrix) { |
| 84 // TODO: support perspective (need getMaxScale replacement) | 85 // TODO: support perspective (need getMaxScale replacement) |
| 85 if (viewMatrix.hasPerspective()) { | 86 if (viewMatrix.hasPerspective()) { |
| 86 return false; | 87 return false; |
| 87 } | 88 } |
| 88 | 89 |
| 89 SkScalar maxScale = viewMatrix.getMaxScale(); | 90 SkScalar maxScale = viewMatrix.getMaxScale(); |
| 90 SkScalar scaledTextSize = maxScale*paint.getTextSize(); | 91 SkScalar scaledTextSize = maxScale*paint.getTextSize(); |
| 92 // Hinted text looks far better at small resolutions |
| 91 // Scaling up beyond 2x yields undesireable artifacts | 93 // Scaling up beyond 2x yields undesireable artifacts |
| 92 if (scaledTextSize > 2*kLargeDFFontSize) { | 94 if (scaledTextSize < kMinDFFontSize || scaledTextSize > 2*kLargeDFFontSize)
{ |
| 93 return false; | 95 return false; |
| 94 } | 96 } |
| 95 | 97 |
| 96 if (!fEnableDFRendering && !paint.isDistanceFieldTextTEMP() && | 98 if (!fEnableDFRendering && !paint.isDistanceFieldTextTEMP() && |
| 97 scaledTextSize < kLargeDFFontSize) { | 99 scaledTextSize < kLargeDFFontSize) { |
| 98 return false; | 100 return false; |
| 99 } | 101 } |
| 100 | 102 |
| 101 // rasterizers and mask filters modify alpha, which doesn't | 103 // rasterizers and mask filters modify alpha, which doesn't |
| 102 // translate well to distance | 104 // translate well to distance |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 135 | 137 |
| 136 fVertices = NULL; | 138 fVertices = NULL; |
| 137 fCurrVertex = 0; | 139 fCurrVertex = 0; |
| 138 fAllocVertexCount = 0; | 140 fAllocVertexCount = 0; |
| 139 fTotalVertexCount = 0; | 141 fTotalVertexCount = 0; |
| 140 | 142 |
| 141 if (scaledTextSize <= kSmallDFFontLimit) { | 143 if (scaledTextSize <= kSmallDFFontLimit) { |
| 142 fTextRatio = textSize / kSmallDFFontSize; | 144 fTextRatio = textSize / kSmallDFFontSize; |
| 143 fSkPaint.setTextSize(SkIntToScalar(kSmallDFFontSize)); | 145 fSkPaint.setTextSize(SkIntToScalar(kSmallDFFontSize)); |
| 144 #if DEBUG_TEXT_SIZE | 146 #if DEBUG_TEXT_SIZE |
| 145 fSkPaint.setColor(SkColorSetARGB(0xFF, 0x00, 0x00, 0xFF)); | 147 fSkPaint.setColor(SkColorSetARGB(0xFF, 0x00, 0x00, 0x7F)); |
| 146 fPaint.setColor(GrColorPackRGBA(0x00, 0x00, 0xFF, 0xFF)); | 148 fPaint.setColor(GrColorPackRGBA(0x00, 0x00, 0x7F, 0xFF)); |
| 147 #endif | 149 #endif |
| 148 } else if (scaledTextSize <= kMediumDFFontLimit) { | 150 } else if (scaledTextSize <= kMediumDFFontLimit) { |
| 149 fTextRatio = textSize / kMediumDFFontSize; | 151 fTextRatio = textSize / kMediumDFFontSize; |
| 150 fSkPaint.setTextSize(SkIntToScalar(kMediumDFFontSize)); | 152 fSkPaint.setTextSize(SkIntToScalar(kMediumDFFontSize)); |
| 151 #if DEBUG_TEXT_SIZE | 153 #if DEBUG_TEXT_SIZE |
| 152 fSkPaint.setColor(SkColorSetARGB(0xFF, 0x00, 0xFF, 0x00)); | 154 fSkPaint.setColor(SkColorSetARGB(0xFF, 0x00, 0x3F, 0x00)); |
| 153 fPaint.setColor(GrColorPackRGBA(0x00, 0xFF, 0x00, 0xFF)); | 155 fPaint.setColor(GrColorPackRGBA(0x00, 0x3F, 0x00, 0xFF)); |
| 154 #endif | 156 #endif |
| 155 } else { | 157 } else { |
| 156 fTextRatio = textSize / kLargeDFFontSize; | 158 fTextRatio = textSize / kLargeDFFontSize; |
| 157 fSkPaint.setTextSize(SkIntToScalar(kLargeDFFontSize)); | 159 fSkPaint.setTextSize(SkIntToScalar(kLargeDFFontSize)); |
| 158 #if DEBUG_TEXT_SIZE | 160 #if DEBUG_TEXT_SIZE |
| 159 fSkPaint.setColor(SkColorSetARGB(0xFF, 0xFF, 0x00, 0x00)); | 161 fSkPaint.setColor(SkColorSetARGB(0xFF, 0x7F, 0x00, 0x00)); |
| 160 fPaint.setColor(GrColorPackRGBA(0xFF, 0x00, 0x00, 0xFF)); | 162 fPaint.setColor(GrColorPackRGBA(0x7F, 0x00, 0x00, 0xFF)); |
| 161 #endif | 163 #endif |
| 162 } | 164 } |
| 163 | 165 |
| 164 fUseLCDText = fSkPaint.isLCDRenderText(); | 166 fUseLCDText = fSkPaint.isLCDRenderText(); |
| 165 | 167 |
| 166 fSkPaint.setLCDRenderText(false); | 168 fSkPaint.setLCDRenderText(false); |
| 167 fSkPaint.setAutohinted(false); | 169 fSkPaint.setAutohinted(false); |
| 168 fSkPaint.setHinting(SkPaint::kNormal_Hinting); | 170 fSkPaint.setHinting(SkPaint::kNormal_Hinting); |
| 169 fSkPaint.setSubpixelText(true); | 171 fSkPaint.setSubpixelText(true); |
| 170 } | 172 } |
| (...skipping 549 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 720 } | 722 } |
| 721 } | 723 } |
| 722 | 724 |
| 723 inline void GrDistanceFieldTextContext::finish() { | 725 inline void GrDistanceFieldTextContext::finish() { |
| 724 this->flush(); | 726 this->flush(); |
| 725 fTotalVertexCount = 0; | 727 fTotalVertexCount = 0; |
| 726 | 728 |
| 727 GrTextContext::finish(); | 729 GrTextContext::finish(); |
| 728 } | 730 } |
| 729 | 731 |
| OLD | NEW |