| 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 "GrContext.h" | 9 #include "GrContext.h" |
| 10 #include "GrDrawContext.h" | 10 #include "GrDrawContext.h" |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 89 | 89 |
| 90 SkAutoTUnref<GrAtlasTextBlob> cacheBlob; | 90 SkAutoTUnref<GrAtlasTextBlob> cacheBlob; |
| 91 SkMaskFilter::BlurRec blurRec; | 91 SkMaskFilter::BlurRec blurRec; |
| 92 GrAtlasTextBlob::Key key; | 92 GrAtlasTextBlob::Key key; |
| 93 // It might be worth caching these things, but its not clear at this time | 93 // It might be worth caching these things, but its not clear at this time |
| 94 // TODO for animated mask filters, this will fill up our cache. We need a s
afeguard here | 94 // TODO for animated mask filters, this will fill up our cache. We need a s
afeguard here |
| 95 const SkMaskFilter* mf = skPaint.getMaskFilter(); | 95 const SkMaskFilter* mf = skPaint.getMaskFilter(); |
| 96 bool canCache = !(skPaint.getPathEffect() || | 96 bool canCache = !(skPaint.getPathEffect() || |
| 97 (mf && !mf->asABlur(&blurRec)) || | 97 (mf && !mf->asABlur(&blurRec)) || |
| 98 drawFilter); | 98 drawFilter); |
| 99 uint32_t scalerContextFlags = ComputeScalerContextFlags(dc); |
| 99 | 100 |
| 100 GrTextBlobCache* cache = context->getTextBlobCache(); | 101 GrTextBlobCache* cache = context->getTextBlobCache(); |
| 101 if (canCache) { | 102 if (canCache) { |
| 102 bool hasLCD = HasLCD(blob); | 103 bool hasLCD = HasLCD(blob); |
| 103 | 104 |
| 104 // We canonicalize all non-lcd draws to use kUnknown_SkPixelGeometry | 105 // We canonicalize all non-lcd draws to use kUnknown_SkPixelGeometry |
| 105 SkPixelGeometry pixelGeometry = hasLCD ? props.pixelGeometry() : | 106 SkPixelGeometry pixelGeometry = hasLCD ? props.pixelGeometry() : |
| 106 kUnknown_SkPixelGeometry; | 107 kUnknown_SkPixelGeometry; |
| 107 | 108 |
| 108 // TODO we want to figure out a way to be able to use the canonical colo
r on LCD text, | 109 // TODO we want to figure out a way to be able to use the canonical colo
r on LCD text, |
| 109 // see the note on ComputeCanonicalColor above. We pick a dummy value f
or LCD text to | 110 // see the note on ComputeCanonicalColor above. We pick a dummy value f
or LCD text to |
| 110 // ensure we always match the same key | 111 // ensure we always match the same key |
| 111 GrColor canonicalColor = hasLCD ? SK_ColorTRANSPARENT : | 112 GrColor canonicalColor = hasLCD ? SK_ColorTRANSPARENT : |
| 112 ComputeCanonicalColor(skPaint, hasLCD)
; | 113 ComputeCanonicalColor(skPaint, hasLCD)
; |
| 113 | 114 |
| 114 key.fPixelGeometry = pixelGeometry; | 115 key.fPixelGeometry = pixelGeometry; |
| 115 key.fUniqueID = blob->uniqueID(); | 116 key.fUniqueID = blob->uniqueID(); |
| 116 key.fStyle = skPaint.getStyle(); | 117 key.fStyle = skPaint.getStyle(); |
| 117 key.fHasBlur = SkToBool(mf); | 118 key.fHasBlur = SkToBool(mf); |
| 118 key.fCanonicalColor = canonicalColor; | 119 key.fCanonicalColor = canonicalColor; |
| 120 key.fScalerContextFlags = scalerContextFlags; |
| 119 cacheBlob.reset(SkSafeRef(cache->find(key))); | 121 cacheBlob.reset(SkSafeRef(cache->find(key))); |
| 120 } | 122 } |
| 121 | 123 |
| 122 // Though for the time being runs in the textblob can override the paint, th
ey only touch font | 124 // Though for the time being runs in the textblob can override the paint, th
ey only touch font |
| 123 // info. | 125 // info. |
| 124 GrPaint grPaint; | 126 GrPaint grPaint; |
| 125 if (!SkPaintToGrPaint(context, skPaint, viewMatrix, props.isGammaCorrect(),
&grPaint)) { | 127 if (!SkPaintToGrPaint(context, skPaint, viewMatrix, props.isGammaCorrect(),
&grPaint)) { |
| 126 return; | 128 return; |
| 127 } | 129 } |
| 128 | 130 |
| 129 uint32_t scalerContextFlags = ComputeScalerContextFlags(dc); | |
| 130 | |
| 131 if (cacheBlob) { | 131 if (cacheBlob) { |
| 132 if (cacheBlob->mustRegenerate(skPaint, grPaint.getColor(), blurRec, view
Matrix, x, y)) { | 132 if (cacheBlob->mustRegenerate(skPaint, grPaint.getColor(), blurRec, view
Matrix, x, y)) { |
| 133 // We have to remake the blob because changes may invalidate our mas
ks. | 133 // We have to remake the blob because changes may invalidate our mas
ks. |
| 134 // TODO we could probably get away reuse most of the time if the poi
nter is unique, | 134 // TODO we could probably get away reuse most of the time if the poi
nter is unique, |
| 135 // but we'd have to clear the subrun information | 135 // but we'd have to clear the subrun information |
| 136 cache->remove(cacheBlob); | 136 cache->remove(cacheBlob); |
| 137 cacheBlob.reset(SkRef(cache->createCachedBlob(blob, key, blurRec, sk
Paint))); | 137 cacheBlob.reset(SkRef(cache->createCachedBlob(blob, key, blurRec, sk
Paint))); |
| 138 RegenerateTextBlob(cacheBlob, context->getBatchFontCache(), | 138 RegenerateTextBlob(cacheBlob, context->getBatchFontCache(), |
| 139 *context->caps()->shaderCaps(), skPaint, grPaint.
getColor(), | 139 *context->caps()->shaderCaps(), skPaint, grPaint.
getColor(), |
| 140 scalerContextFlags, viewMatrix, props, | 140 scalerContextFlags, viewMatrix, props, |
| (...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 425 viewMatrix, | 425 viewMatrix, |
| 426 gSurfaceProps, text, | 426 gSurfaceProps, text, |
| 427 static_cast<size_t>(textLen), x,
y)); | 427 static_cast<size_t>(textLen), x,
y)); |
| 428 | 428 |
| 429 return blob->test_createBatch(textLen, 0, 0, viewMatrix, x, y, color, skPain
t, | 429 return blob->test_createBatch(textLen, 0, 0, viewMatrix, x, y, color, skPain
t, |
| 430 gSurfaceProps, gTextContext->dfAdjustTable(), | 430 gSurfaceProps, gTextContext->dfAdjustTable(), |
| 431 context->getBatchFontCache()); | 431 context->getBatchFontCache()); |
| 432 } | 432 } |
| 433 | 433 |
| 434 #endif | 434 #endif |
| OLD | NEW |