OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2015 Google Inc. | 2 * Copyright 2015 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 #include "GrAtlasTextContext.h" | 7 #include "GrAtlasTextContext.h" |
8 | 8 |
9 #include "GrBatch.h" | 9 #include "GrBatch.h" |
10 #include "GrBatchFontCache.h" | 10 #include "GrBatchFontCache.h" |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
90 return GrColorPackRGBA(r, g, b, 0xff); | 90 return GrColorPackRGBA(r, g, b, 0xff); |
91 } | 91 } |
92 | 92 |
93 }; | 93 }; |
94 | 94 |
95 // TODO | 95 // TODO |
96 // Distance field text in textblobs | 96 // Distance field text in textblobs |
97 | 97 |
98 GrAtlasTextContext::GrAtlasTextContext(GrContext* context, | 98 GrAtlasTextContext::GrAtlasTextContext(GrContext* context, |
99 GrDrawContext* drawContext, | 99 GrDrawContext* drawContext, |
100 const SkDeviceProperties& properties, | 100 const SkDeviceProperties& properties) |
101 bool useDFT) | |
102 : INHERITED(context, drawContext, properties) | 101 : INHERITED(context, drawContext, properties) |
103 , fDistanceAdjustTable(SkNEW_ARGS(DistanceAdjustTable, (properties.gamma()))
) { | 102 , fDistanceAdjustTable(SkNEW_ARGS(DistanceAdjustTable, (properties.gamma()))
) { |
104 // We overallocate vertices in our textblobs based on the assumption that A8
has the greatest | 103 // We overallocate vertices in our textblobs based on the assumption that A8
has the greatest |
105 // vertexStride | 104 // vertexStride |
106 SK_COMPILE_ASSERT(kGrayTextVASize >= kColorTextVASize && kGrayTextVASize >=
kLCDTextVASize, | 105 SK_COMPILE_ASSERT(kGrayTextVASize >= kColorTextVASize && kGrayTextVASize >=
kLCDTextVASize, |
107 vertex_attribute_changed); | 106 vertex_attribute_changed); |
108 fCurrStrike = NULL; | 107 fCurrStrike = NULL; |
109 fCache = context->getTextBlobCache(); | 108 fCache = context->getTextBlobCache(); |
110 | |
111 #if SK_FORCE_DISTANCE_FIELD_TEXT | |
112 fEnableDFRendering = true; | |
113 #else | |
114 fEnableDFRendering = useDFT; | |
115 #endif | |
116 } | 109 } |
117 | 110 |
118 void GrAtlasTextContext::DistanceAdjustTable::buildDistanceAdjustTable(float gam
ma) { | 111 void GrAtlasTextContext::DistanceAdjustTable::buildDistanceAdjustTable(float gam
ma) { |
119 | 112 |
120 // This is used for an approximation of the mask gamma hack, used by raster
and bitmap | 113 // This is used for an approximation of the mask gamma hack, used by raster
and bitmap |
121 // text. The mask gamma hack is based off of guessing what the blend color i
s going to | 114 // text. The mask gamma hack is based off of guessing what the blend color i
s going to |
122 // be, and adjusting the mask so that when run through the linear blend will | 115 // be, and adjusting the mask so that when run through the linear blend will |
123 // produce the value closest to the desired result. However, in practice thi
s means | 116 // produce the value closest to the desired result. However, in practice thi
s means |
124 // that the 'adjusted' mask is just increasing or decreasing the coverage of | 117 // that the 'adjusted' mask is just increasing or decreasing the coverage of |
125 // the mask depending on what it is thought it will blit against. For black
(on | 118 // the mask depending on what it is thought it will blit against. For black
(on |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
192 | 185 |
193 fTable[row] = d; | 186 fTable[row] = d; |
194 break; | 187 break; |
195 } | 188 } |
196 } | 189 } |
197 } | 190 } |
198 } | 191 } |
199 | 192 |
200 GrAtlasTextContext* GrAtlasTextContext::Create(GrContext* context, | 193 GrAtlasTextContext* GrAtlasTextContext::Create(GrContext* context, |
201 GrDrawContext* drawContext, | 194 GrDrawContext* drawContext, |
202 const SkDeviceProperties& props, | 195 const SkDeviceProperties& props)
{ |
203 bool useDFT) { | 196 return SkNEW_ARGS(GrAtlasTextContext, (context, drawContext, props)); |
204 return SkNEW_ARGS(GrAtlasTextContext, (context, drawContext, props, useDFT))
; | |
205 } | 197 } |
206 | 198 |
207 bool GrAtlasTextContext::canDraw(const GrRenderTarget*, | 199 bool GrAtlasTextContext::canDraw(const GrRenderTarget*, |
208 const GrClip&, | 200 const GrClip&, |
209 const GrPaint&, | 201 const GrPaint&, |
210 const SkPaint& skPaint, | 202 const SkPaint& skPaint, |
211 const SkMatrix& viewMatrix) { | 203 const SkMatrix& viewMatrix) { |
212 return this->canDrawAsDistanceFields(skPaint, viewMatrix) || | 204 return this->canDrawAsDistanceFields(skPaint, viewMatrix) || |
213 !SkDraw::ShouldDrawTextAsPaths(skPaint, viewMatrix); | 205 !SkDraw::ShouldDrawTextAsPaths(skPaint, viewMatrix); |
214 } | 206 } |
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
443 } | 435 } |
444 | 436 |
445 SkScalar maxScale = viewMatrix.getMaxScale(); | 437 SkScalar maxScale = viewMatrix.getMaxScale(); |
446 SkScalar scaledTextSize = maxScale*skPaint.getTextSize(); | 438 SkScalar scaledTextSize = maxScale*skPaint.getTextSize(); |
447 // Hinted text looks far better at small resolutions | 439 // Hinted text looks far better at small resolutions |
448 // Scaling up beyond 2x yields undesireable artifacts | 440 // Scaling up beyond 2x yields undesireable artifacts |
449 if (scaledTextSize < kMinDFFontSize || scaledTextSize > kLargeDFFontLimit) { | 441 if (scaledTextSize < kMinDFFontSize || scaledTextSize > kLargeDFFontLimit) { |
450 return false; | 442 return false; |
451 } | 443 } |
452 | 444 |
453 if (!fEnableDFRendering && !skPaint.isDistanceFieldTextTEMP() && | 445 bool useDFT = fDeviceProperties.useDFT(); |
454 scaledTextSize < kLargeDFFontSize) { | 446 #if SK_FORCE_DISTANCE_FIELD_TEXT |
| 447 useDFT = true; |
| 448 #endif |
| 449 |
| 450 if (!useDFT && !skPaint.isDistanceFieldTextTEMP() && scaledTextSize < kLarge
DFFontSize) { |
455 return false; | 451 return false; |
456 } | 452 } |
457 | 453 |
458 // rasterizers and mask filters modify alpha, which doesn't | 454 // rasterizers and mask filters modify alpha, which doesn't |
459 // translate well to distance | 455 // translate well to distance |
460 if (skPaint.getRasterizer() || skPaint.getMaskFilter() || | 456 if (skPaint.getRasterizer() || skPaint.getMaskFilter() || |
461 !fContext->caps()->shaderCaps()->shaderDerivativeSupport()) { | 457 !fContext->caps()->shaderCaps()->shaderDerivativeSupport()) { |
462 return false; | 458 return false; |
463 } | 459 } |
464 | 460 |
(...skipping 1756 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2221 | 2217 |
2222 BATCH_TEST_DEFINE(TextBlobBatch) { | 2218 BATCH_TEST_DEFINE(TextBlobBatch) { |
2223 static uint32_t gContextID = SK_InvalidGenID; | 2219 static uint32_t gContextID = SK_InvalidGenID; |
2224 static GrAtlasTextContext* gTextContext = NULL; | 2220 static GrAtlasTextContext* gTextContext = NULL; |
2225 static SkDeviceProperties gDevProperties; | 2221 static SkDeviceProperties gDevProperties; |
2226 | 2222 |
2227 if (context->uniqueID() != gContextID) { | 2223 if (context->uniqueID() != gContextID) { |
2228 gContextID = context->uniqueID(); | 2224 gContextID = context->uniqueID(); |
2229 SkDELETE(gTextContext); | 2225 SkDELETE(gTextContext); |
2230 | 2226 |
2231 static const bool kUseDFT = false; | |
2232 // We don't yet test the fall back to paths in the GrTextContext base cl
ass. This is mostly | 2227 // We don't yet test the fall back to paths in the GrTextContext base cl
ass. This is mostly |
2233 // because we don't really want to have a gpu device here. | 2228 // because we don't really want to have a gpu device here. |
2234 // We enable distance fields by twiddling a knob on the paint | 2229 // We enable distance fields by twiddling a knob on the paint |
2235 GrDrawContext* drawContext = context->drawContext(&gDevProperties, kUseD
FT); | 2230 GrDrawContext* drawContext = context->drawContext(&gDevProperties); |
2236 | 2231 |
2237 gTextContext = GrAtlasTextContext::Create(context, drawContext, gDevProp
erties, kUseDFT); | 2232 gTextContext = GrAtlasTextContext::Create(context, drawContext, gDevProp
erties); |
2238 } | 2233 } |
2239 | 2234 |
2240 // create dummy render target | 2235 // create dummy render target |
2241 GrSurfaceDesc desc; | 2236 GrSurfaceDesc desc; |
2242 desc.fFlags = kRenderTarget_GrSurfaceFlag; | 2237 desc.fFlags = kRenderTarget_GrSurfaceFlag; |
2243 desc.fWidth = 1024; | 2238 desc.fWidth = 1024; |
2244 desc.fHeight = 1024; | 2239 desc.fHeight = 1024; |
2245 desc.fConfig = kRGBA_8888_GrPixelConfig; | 2240 desc.fConfig = kRGBA_8888_GrPixelConfig; |
2246 desc.fSampleCnt = 0; | 2241 desc.fSampleCnt = 0; |
2247 SkAutoTUnref<GrTexture> texture(context->textureProvider()->createTexture(de
sc, true, NULL, 0)); | 2242 SkAutoTUnref<GrTexture> texture(context->textureProvider()->createTexture(de
sc, true, NULL, 0)); |
(...skipping 29 matching lines...) Expand all Loading... |
2277 gTextContext->createDrawTextBlob(rt, clip, grPaint, skPaint, viewMat
rix, text, | 2272 gTextContext->createDrawTextBlob(rt, clip, grPaint, skPaint, viewMat
rix, text, |
2278 static_cast<size_t>(textLen), 0, 0,
noClip)); | 2273 static_cast<size_t>(textLen), 0, 0,
noClip)); |
2279 | 2274 |
2280 SkScalar transX = static_cast<SkScalar>(random->nextU()); | 2275 SkScalar transX = static_cast<SkScalar>(random->nextU()); |
2281 SkScalar transY = static_cast<SkScalar>(random->nextU()); | 2276 SkScalar transY = static_cast<SkScalar>(random->nextU()); |
2282 const GrAtlasTextContext::BitmapTextBlob::Run::SubRunInfo& info = blob->fRun
s[0].fSubRunInfo[0]; | 2277 const GrAtlasTextContext::BitmapTextBlob::Run::SubRunInfo& info = blob->fRun
s[0].fSubRunInfo[0]; |
2283 return gTextContext->createBatch(blob, info, textLen, 0, 0, color, transX, t
ransY, skPaint); | 2278 return gTextContext->createBatch(blob, info, textLen, 0, 0, color, transX, t
ransY, skPaint); |
2284 } | 2279 } |
2285 | 2280 |
2286 #endif | 2281 #endif |
OLD | NEW |