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 "SkColorFilter.h" | 10 #include "SkColorFilter.h" |
(...skipping 20 matching lines...) Expand all Loading... |
31 static const int kSmallDFFontSize = 32; | 31 static const int kSmallDFFontSize = 32; |
32 static const int kSmallDFFontLimit = 32; | 32 static const int kSmallDFFontLimit = 32; |
33 static const int kMediumDFFontSize = 64; | 33 static const int kMediumDFFontSize = 64; |
34 static const int kMediumDFFontLimit = 64; | 34 static const int kMediumDFFontLimit = 64; |
35 static const int kLargeDFFontSize = 128; | 35 static const int kLargeDFFontSize = 128; |
36 | 36 |
37 namespace { | 37 namespace { |
38 // position + texture coord | 38 // position + texture coord |
39 extern const GrVertexAttrib gTextVertexAttribs[] = { | 39 extern const GrVertexAttrib gTextVertexAttribs[] = { |
40 {kVec2f_GrVertexAttribType, 0, kPosition_GrVertexAttribBindin
g}, | 40 {kVec2f_GrVertexAttribType, 0, kPosition_GrVertexAttribBindin
g}, |
41 {kVec2f_GrVertexAttribType, sizeof(SkPoint) , kEffect_GrVertexAttribBinding} | 41 {kVec2f_GrVertexAttribType, sizeof(SkPoint) , kGeometryProcessor_GrVertexAtt
ribBinding} |
42 }; | 42 }; |
43 | 43 |
44 static const size_t kTextVASize = 2 * sizeof(SkPoint); | 44 static const size_t kTextVASize = 2 * sizeof(SkPoint); |
45 | 45 |
46 // position + color + texture coord | 46 // position + color + texture coord |
47 extern const GrVertexAttrib gTextVertexWithColorAttribs[] = { | 47 extern const GrVertexAttrib gTextVertexWithColorAttribs[] = { |
48 {kVec2f_GrVertexAttribType, 0, kPosition_Gr
VertexAttribBinding}, | 48 {kVec2f_GrVertexAttribType, 0, kPosition_Gr
VertexAttribBinding}, |
49 {kVec4ub_GrVertexAttribType, sizeof(SkPoint), kColor_GrVer
texAttribBinding}, | 49 {kVec4ub_GrVertexAttribType, sizeof(SkPoint), kColor_GrVer
texAttribBinding}, |
50 {kVec2f_GrVertexAttribType, sizeof(SkPoint) + sizeof(GrColor), kEffect_GrVe
rtexAttribBinding} | 50 {kVec2f_GrVertexAttribType, sizeof(SkPoint) + sizeof(GrColor), kGeometryPro
cessor_GrVertexAttribBinding} |
51 }; | 51 }; |
52 | 52 |
53 static const size_t kTextVAColorSize = 2 * sizeof(SkPoint) + sizeof(GrColor); | 53 static const size_t kTextVAColorSize = 2 * sizeof(SkPoint) + sizeof(GrColor); |
54 | 54 |
55 }; | 55 }; |
56 | 56 |
57 GrDistanceFieldTextContext::GrDistanceFieldTextContext(GrContext* context, | 57 GrDistanceFieldTextContext::GrDistanceFieldTextContext(GrContext* context, |
58 const SkDeviceProperties&
properties, | 58 const SkDeviceProperties&
properties, |
59 bool enable) | 59 bool enable) |
60 : GrTextContext(context, pro
perties) { | 60 : GrTextContext(context, pro
perties) { |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
134 bool useBGR = SkDeviceProperties::Geometry::kBGR_Layout == | 134 bool useBGR = SkDeviceProperties::Geometry::kBGR_Layout == |
135 fDeviceProperties.fGeometry.getLayout(); | 135 fDeviceProperties.fGeometry.getLayout(); |
136 flags |= fUseLCDText && useBGR ? kBGR_DistanceFieldEffectFlag : 0; | 136 flags |= fUseLCDText && useBGR ? kBGR_DistanceFieldEffectFlag : 0; |
137 | 137 |
138 // see if we need to create a new effect | 138 // see if we need to create a new effect |
139 if (textureUniqueID != fEffectTextureUniqueID || | 139 if (textureUniqueID != fEffectTextureUniqueID || |
140 filteredColor != fEffectColor || | 140 filteredColor != fEffectColor || |
141 flags != fEffectFlags) { | 141 flags != fEffectFlags) { |
142 if (fUseLCDText) { | 142 if (fUseLCDText) { |
143 GrColor colorNoPreMul = skcolor_to_grcolor_nopremultiply(filteredCol
or); | 143 GrColor colorNoPreMul = skcolor_to_grcolor_nopremultiply(filteredCol
or); |
144 fCachedEffect.reset(GrDistanceFieldLCDTextureEffect::Create(fCurrTex
ture, | 144 fCachedGeometryProcessor.reset( |
145 params, | 145 GrDistanceFieldLCDTextureEffect::Create(fCurrTexture, |
146 fGammaTe
xture, | 146 params, |
147 gammaPar
ams, | 147 fGammaTexture, |
148 colorNoP
reMul, | 148 gammaParams, |
149 flags)); | 149 colorNoPreMul, |
| 150 flags)); |
150 } else { | 151 } else { |
151 #ifdef SK_GAMMA_APPLY_TO_A8 | 152 #ifdef SK_GAMMA_APPLY_TO_A8 |
152 U8CPU lum = SkColorSpaceLuminance::computeLuminance(fDevicePropertie
s.fGamma, | 153 U8CPU lum = SkColorSpaceLuminance::computeLuminance(fDevicePropertie
s.fGamma, |
153 filteredColor); | 154 filteredColor); |
154 fCachedEffect.reset(GrDistanceFieldTextureEffect::Create(fCurrTextur
e, | 155 fCachedGeometryProcessor.reset( |
155 params, | 156 GrDistanceFieldTextureEffect::Create(fCurrTexture, |
156 fGammaTextu
re, | 157 params, |
157 gammaParams
, | 158 fGammaTexture, |
158 lum/255.f, | 159 gammaParams, |
159 flags)); | 160 lum/255.f, |
| 161 flags)); |
160 #else | 162 #else |
161 fCachedEffect.reset(GrDistanceFieldTextureEffect::Create(fCurrTextur
e, | 163 fCachedGeometryProcessor.reset(GrDistanceFieldTextureEffect::Create(
fCurrTexture, |
162 params, fla
gs)); | 164
params, flags)); |
163 #endif | 165 #endif |
164 } | 166 } |
165 fEffectTextureUniqueID = textureUniqueID; | 167 fEffectTextureUniqueID = textureUniqueID; |
166 fEffectColor = filteredColor; | 168 fEffectColor = filteredColor; |
167 fEffectFlags = flags; | 169 fEffectFlags = flags; |
168 } | 170 } |
169 | 171 |
170 } | 172 } |
171 | 173 |
172 void GrDistanceFieldTextContext::flushGlyphs() { | 174 void GrDistanceFieldTextContext::flushGlyphs() { |
(...skipping 14 matching lines...) Expand all Loading... |
187 SkColor filteredColor; | 189 SkColor filteredColor; |
188 SkColorFilter* colorFilter = fSkPaint.getColorFilter(); | 190 SkColorFilter* colorFilter = fSkPaint.getColorFilter(); |
189 if (colorFilter) { | 191 if (colorFilter) { |
190 filteredColor = colorFilter->filterColor(fSkPaint.getColor()); | 192 filteredColor = colorFilter->filterColor(fSkPaint.getColor()); |
191 } else { | 193 } else { |
192 filteredColor = fSkPaint.getColor(); | 194 filteredColor = fSkPaint.getColor(); |
193 } | 195 } |
194 this->setupCoverageEffect(filteredColor); | 196 this->setupCoverageEffect(filteredColor); |
195 | 197 |
196 // Effects could be stored with one of the cache objects (atlas?) | 198 // Effects could be stored with one of the cache objects (atlas?) |
197 drawState->setGeometryProcessor(fCachedEffect.get()); | 199 drawState->setGeometryProcessor(fCachedGeometryProcessor.get()); |
198 | 200 |
199 // Set draw state | 201 // Set draw state |
200 if (fUseLCDText) { | 202 if (fUseLCDText) { |
201 GrColor colorNoPreMul = skcolor_to_grcolor_nopremultiply(filteredCol
or); | 203 GrColor colorNoPreMul = skcolor_to_grcolor_nopremultiply(filteredCol
or); |
202 if (kOne_GrBlendCoeff != fPaint.getSrcBlendCoeff() || | 204 if (kOne_GrBlendCoeff != fPaint.getSrcBlendCoeff() || |
203 kISA_GrBlendCoeff != fPaint.getDstBlendCoeff() || | 205 kISA_GrBlendCoeff != fPaint.getDstBlendCoeff() || |
204 fPaint.numColorStages()) { | 206 fPaint.numColorStages()) { |
205 GrPrintf("LCD Text will not draw correctly.\n"); | 207 GrPrintf("LCD Text will not draw correctly.\n"); |
206 } | 208 } |
207 SkASSERT(!drawState->hasColorVertexAttribute()); | 209 SkASSERT(!drawState->hasColorVertexAttribute()); |
(...skipping 454 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
662 SkScalarToFixed(x) - (glyph.fAdvanceX >> a
lignShift), | 664 SkScalarToFixed(x) - (glyph.fAdvanceX >> a
lignShift), |
663 SkScalarToFixed(y) - (glyph.fAdvanceY >> a
lignShift), | 665 SkScalarToFixed(y) - (glyph.fAdvanceY >> a
lignShift), |
664 fontScaler); | 666 fontScaler); |
665 } | 667 } |
666 pos += scalarsPerPosition; | 668 pos += scalarsPerPosition; |
667 } | 669 } |
668 } | 670 } |
669 | 671 |
670 this->finish(); | 672 this->finish(); |
671 } | 673 } |
OLD | NEW |