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 "GrBatchFontCache.h" | 9 #include "GrBatchFontCache.h" |
10 #include "GrBatchFlushState.h" | 10 #include "GrBatchFlushState.h" |
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
221 // reduce to our finite number of bits | 221 // reduce to our finite number of bits |
222 canonicalColor = SkMaskGamma::CanonicalColor(SkColorSetRGB(lum, lum, lum
)); | 222 canonicalColor = SkMaskGamma::CanonicalColor(SkColorSetRGB(lum, lum, lum
)); |
223 } | 223 } |
224 return canonicalColor; | 224 return canonicalColor; |
225 } | 225 } |
226 | 226 |
227 // TODO if this function ever shows up in profiling, then we can compute this va
lue when the | 227 // TODO if this function ever shows up in profiling, then we can compute this va
lue when the |
228 // textblob is being built and cache it. However, for the time being textblobs
mostly only have 1 | 228 // textblob is being built and cache it. However, for the time being textblobs
mostly only have 1 |
229 // run so this is not a big deal to compute here. | 229 // run so this is not a big deal to compute here. |
230 bool GrAtlasTextContext::HasLCD(const SkTextBlob* blob) { | 230 bool GrAtlasTextContext::HasLCD(const SkTextBlob* blob) { |
231 SkTextBlob::RunIterator it(blob); | 231 SkTextBlobRunIterator it(blob); |
232 for (; !it.done(); it.next()) { | 232 for (; !it.done(); it.next()) { |
233 if (it.isLCD()) { | 233 if (it.isLCD()) { |
234 return true; | 234 return true; |
235 } | 235 } |
236 } | 236 } |
237 return false; | 237 return false; |
238 } | 238 } |
239 | 239 |
240 bool GrAtlasTextContext::MustRegenerateBlob(SkScalar* outTransX, SkScalar* outTr
ansY, | 240 bool GrAtlasTextContext::MustRegenerateBlob(SkScalar* outTransX, SkScalar* outTr
ansY, |
241 const GrAtlasTextBlob& blob, const S
kPaint& paint, | 241 const GrAtlasTextBlob& blob, const S
kPaint& paint, |
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
489 // The color here is the GrPaint color, and it is used to determine whether
we | 489 // The color here is the GrPaint color, and it is used to determine whether
we |
490 // have to regenerate LCD text blobs. | 490 // have to regenerate LCD text blobs. |
491 // We use this color vs the SkPaint color because it has the colorfilter app
lied. | 491 // We use this color vs the SkPaint color because it has the colorfilter app
lied. |
492 cacheBlob->fPaintColor = color; | 492 cacheBlob->fPaintColor = color; |
493 cacheBlob->fViewMatrix = viewMatrix; | 493 cacheBlob->fViewMatrix = viewMatrix; |
494 cacheBlob->fX = x; | 494 cacheBlob->fX = x; |
495 cacheBlob->fY = y; | 495 cacheBlob->fY = y; |
496 | 496 |
497 // Regenerate textblob | 497 // Regenerate textblob |
498 SkPaint runPaint = skPaint; | 498 SkPaint runPaint = skPaint; |
499 SkTextBlob::RunIterator it(blob); | 499 SkTextBlobRunIterator it(blob); |
500 for (int run = 0; !it.done(); it.next(), run++) { | 500 for (int run = 0; !it.done(); it.next(), run++) { |
501 int glyphCount = it.glyphCount(); | 501 int glyphCount = it.glyphCount(); |
502 size_t textLen = glyphCount * sizeof(uint16_t); | 502 size_t textLen = glyphCount * sizeof(uint16_t); |
503 const SkPoint& offset = it.offset(); | 503 const SkPoint& offset = it.offset(); |
504 // applyFontToPaint() always overwrites the exact same attributes, | 504 // applyFontToPaint() always overwrites the exact same attributes, |
505 // so it is safe to not re-seed the paint for this reason. | 505 // so it is safe to not re-seed the paint for this reason. |
506 it.applyFontToPaint(&runPaint); | 506 it.applyFontToPaint(&runPaint); |
507 | 507 |
508 if (drawFilter && !drawFilter->filter(&runPaint, SkDrawFilter::kText_Typ
e)) { | 508 if (drawFilter && !drawFilter->filter(&runPaint, SkDrawFilter::kText_Typ
e)) { |
509 // A false return from filter() means we should abort the current dr
aw. | 509 // A false return from filter() means we should abort the current dr
aw. |
(...skipping 1533 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2043 GrBatchFontCache* fFontCache; | 2043 GrBatchFontCache* fFontCache; |
2044 | 2044 |
2045 // Distance field properties | 2045 // Distance field properties |
2046 SkAutoTUnref<const DistanceAdjustTable> fDistanceAdjustTable; | 2046 SkAutoTUnref<const DistanceAdjustTable> fDistanceAdjustTable; |
2047 SkColor fFilteredColor; | 2047 SkColor fFilteredColor; |
2048 | 2048 |
2049 typedef GrVertexBatch INHERITED; | 2049 typedef GrVertexBatch INHERITED; |
2050 }; | 2050 }; |
2051 | 2051 |
2052 void GrAtlasTextContext::flushRunAsPaths(GrDrawContext* dc, GrRenderTarget* rt, | 2052 void GrAtlasTextContext::flushRunAsPaths(GrDrawContext* dc, GrRenderTarget* rt, |
2053 const SkTextBlob::RunIterator& it, | 2053 const SkTextBlobRunIterator& it, |
2054 const GrClip& clip, const SkPaint& skPa
int, | 2054 const GrClip& clip, const SkPaint& skPa
int, |
2055 SkDrawFilter* drawFilter, const SkMatri
x& viewMatrix, | 2055 SkDrawFilter* drawFilter, const SkMatri
x& viewMatrix, |
2056 const SkIRect& clipBounds, SkScalar x,
SkScalar y) { | 2056 const SkIRect& clipBounds, SkScalar x,
SkScalar y) { |
2057 SkPaint runPaint = skPaint; | 2057 SkPaint runPaint = skPaint; |
2058 | 2058 |
2059 size_t textLen = it.glyphCount() * sizeof(uint16_t); | 2059 size_t textLen = it.glyphCount() * sizeof(uint16_t); |
2060 const SkPoint& offset = it.offset(); | 2060 const SkPoint& offset = it.offset(); |
2061 | 2061 |
2062 it.applyFontToPaint(&runPaint); | 2062 it.applyFontToPaint(&runPaint); |
2063 | 2063 |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2183 const SkMatrix& viewMatrix, | 2183 const SkMatrix& viewMatrix, |
2184 const SkIRect& clipBounds, | 2184 const SkIRect& clipBounds, |
2185 SkScalar x, SkScalar y, | 2185 SkScalar x, SkScalar y, |
2186 SkScalar transX, SkScalar transY) { | 2186 SkScalar transX, SkScalar transY) { |
2187 // We loop through the runs of the blob, flushing each. If any run is too l
arge, then we flush | 2187 // We loop through the runs of the blob, flushing each. If any run is too l
arge, then we flush |
2188 // it as paths | 2188 // it as paths |
2189 GrPipelineBuilder pipelineBuilder(grPaint, rt, clip); | 2189 GrPipelineBuilder pipelineBuilder(grPaint, rt, clip); |
2190 | 2190 |
2191 GrColor color = grPaint.getColor(); | 2191 GrColor color = grPaint.getColor(); |
2192 | 2192 |
2193 SkTextBlob::RunIterator it(blob); | 2193 SkTextBlobRunIterator it(blob); |
2194 for (int run = 0; !it.done(); it.next(), run++) { | 2194 for (int run = 0; !it.done(); it.next(), run++) { |
2195 if (cacheBlob->fRuns[run].fDrawAsPaths) { | 2195 if (cacheBlob->fRuns[run].fDrawAsPaths) { |
2196 this->flushRunAsPaths(dc, rt, it, clip, skPaint, | 2196 this->flushRunAsPaths(dc, rt, it, clip, skPaint, |
2197 drawFilter, viewMatrix, clipBounds, x, y); | 2197 drawFilter, viewMatrix, clipBounds, x, y); |
2198 continue; | 2198 continue; |
2199 } | 2199 } |
2200 cacheBlob->fRuns[run].fVertexBounds.offset(transX, transY); | 2200 cacheBlob->fRuns[run].fVertexBounds.offset(transX, transY); |
2201 this->flushRun(dc, &pipelineBuilder, cacheBlob, run, color, | 2201 this->flushRun(dc, &pipelineBuilder, cacheBlob, run, color, |
2202 transX, transY, skPaint); | 2202 transX, transY, skPaint); |
2203 } | 2203 } |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2282 gTextContext->createDrawTextBlob(rt, clip, grPaint, skPaint, viewMat
rix, text, | 2282 gTextContext->createDrawTextBlob(rt, clip, grPaint, skPaint, viewMat
rix, text, |
2283 static_cast<size_t>(textLen), 0, 0,
noClip)); | 2283 static_cast<size_t>(textLen), 0, 0,
noClip)); |
2284 | 2284 |
2285 SkScalar transX = static_cast<SkScalar>(random->nextU()); | 2285 SkScalar transX = static_cast<SkScalar>(random->nextU()); |
2286 SkScalar transY = static_cast<SkScalar>(random->nextU()); | 2286 SkScalar transY = static_cast<SkScalar>(random->nextU()); |
2287 const GrAtlasTextBlob::Run::SubRunInfo& info = blob->fRuns[0].fSubRunInfo[0]
; | 2287 const GrAtlasTextBlob::Run::SubRunInfo& info = blob->fRuns[0].fSubRunInfo[0]
; |
2288 return gTextContext->createBatch(blob, info, textLen, 0, 0, color, transX, t
ransY, skPaint); | 2288 return gTextContext->createBatch(blob, info, textLen, 0, 0, color, transX, t
ransY, skPaint); |
2289 } | 2289 } |
2290 | 2290 |
2291 #endif | 2291 #endif |
OLD | NEW |