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" |
11 #include "GrBatchTarget.h" | 11 #include "GrBatchTarget.h" |
12 #include "GrBatchTest.h" | 12 #include "GrBatchTest.h" |
| 13 #include "GrBlurUtils.h" |
13 #include "GrDefaultGeoProcFactory.h" | 14 #include "GrDefaultGeoProcFactory.h" |
14 #include "GrDrawContext.h" | 15 #include "GrDrawContext.h" |
15 #include "GrFontScaler.h" | 16 #include "GrFontScaler.h" |
16 #include "GrIndexBuffer.h" | 17 #include "GrIndexBuffer.h" |
17 #include "GrResourceProvider.h" | 18 #include "GrResourceProvider.h" |
18 #include "GrStrokeInfo.h" | 19 #include "GrStrokeInfo.h" |
19 #include "GrTextBlobCache.h" | 20 #include "GrTextBlobCache.h" |
20 #include "GrTexturePriv.h" | 21 #include "GrTexturePriv.h" |
21 #include "GrVertexBuffer.h" | 22 #include "GrVertexBuffer.h" |
22 | 23 |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
87 unsigned b = SkColorGetB(c); | 88 unsigned b = SkColorGetB(c); |
88 return GrColorPackRGBA(r, g, b, 0xff); | 89 return GrColorPackRGBA(r, g, b, 0xff); |
89 } | 90 } |
90 | 91 |
91 }; | 92 }; |
92 | 93 |
93 // TODO | 94 // TODO |
94 // Distance field text in textblobs | 95 // Distance field text in textblobs |
95 | 96 |
96 GrAtlasTextContext::GrAtlasTextContext(GrContext* context, | 97 GrAtlasTextContext::GrAtlasTextContext(GrContext* context, |
97 SkGpuDevice* gpuDevice, | |
98 const SkDeviceProperties& properties, | 98 const SkDeviceProperties& properties, |
99 bool enableDistanceFields) | 99 bool enableDistanceFields) |
100 : INHERITED(context, gpuDevice, properties) | 100 : INHERITED(context, properties) |
101 , fDistanceAdjustTable(SkNEW_ARGS(DistanceAdjustTable, (properties.gamma()))
) { | 101 , fDistanceAdjustTable(SkNEW_ARGS(DistanceAdjustTable, (properties.gamma()))
) { |
102 // We overallocate vertices in our textblobs based on the assumption that A8
has the greatest | 102 // We overallocate vertices in our textblobs based on the assumption that A8
has the greatest |
103 // vertexStride | 103 // vertexStride |
104 SK_COMPILE_ASSERT(kGrayTextVASize >= kColorTextVASize && kGrayTextVASize >=
kLCDTextVASize, | 104 SK_COMPILE_ASSERT(kGrayTextVASize >= kColorTextVASize && kGrayTextVASize >=
kLCDTextVASize, |
105 vertex_attribute_changed); | 105 vertex_attribute_changed); |
106 fCurrStrike = NULL; | 106 fCurrStrike = NULL; |
107 fCache = context->getTextBlobCache(); | 107 fCache = context->getTextBlobCache(); |
108 | 108 |
109 #if SK_FORCE_DISTANCE_FIELD_TEXT | 109 #if SK_FORCE_DISTANCE_FIELD_TEXT |
110 fEnableDFRendering = true; | 110 fEnableDFRendering = true; |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
189 float d = 2.0f*kDistanceFieldAAFactor*t - kDistanceFieldAAFactor
; | 189 float d = 2.0f*kDistanceFieldAAFactor*t - kDistanceFieldAAFactor
; |
190 | 190 |
191 fTable[row] = d; | 191 fTable[row] = d; |
192 break; | 192 break; |
193 } | 193 } |
194 } | 194 } |
195 } | 195 } |
196 } | 196 } |
197 | 197 |
198 GrAtlasTextContext* GrAtlasTextContext::Create(GrContext* context, | 198 GrAtlasTextContext* GrAtlasTextContext::Create(GrContext* context, |
199 SkGpuDevice* gpuDevice, | |
200 const SkDeviceProperties& props, | 199 const SkDeviceProperties& props, |
201 bool enableDistanceFields) { | 200 bool enableDistanceFields) { |
202 return SkNEW_ARGS(GrAtlasTextContext, (context, gpuDevice, props, enableDist
anceFields)); | 201 return SkNEW_ARGS(GrAtlasTextContext, (context, props, enableDistanceFields)
); |
203 } | 202 } |
204 | 203 |
205 bool GrAtlasTextContext::canDraw(const GrRenderTarget*, | 204 bool GrAtlasTextContext::canDraw(const GrRenderTarget*, |
206 const GrClip&, | 205 const GrClip&, |
207 const GrPaint&, | 206 const GrPaint&, |
208 const SkPaint& skPaint, | 207 const SkPaint& skPaint, |
209 const SkMatrix& viewMatrix) { | 208 const SkMatrix& viewMatrix) { |
210 return this->canDrawAsDistanceFields(skPaint, viewMatrix) || | 209 return this->canDrawAsDistanceFields(skPaint, viewMatrix) || |
211 !SkDraw::ShouldDrawTextAsPaths(skPaint, viewMatrix); | 210 !SkDraw::ShouldDrawTextAsPaths(skPaint, viewMatrix); |
212 } | 211 } |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
338 | 337 |
339 inline SkGlyphCache* GrAtlasTextContext::setupCache(BitmapTextBlob::Run* run, | 338 inline SkGlyphCache* GrAtlasTextContext::setupCache(BitmapTextBlob::Run* run, |
340 const SkPaint& skPaint, | 339 const SkPaint& skPaint, |
341 const SkMatrix* viewMatrix, | 340 const SkMatrix* viewMatrix, |
342 bool noGamma) { | 341 bool noGamma) { |
343 skPaint.getScalerContextDescriptor(&run->fDescriptor, &fDeviceProperties, vi
ewMatrix, noGamma); | 342 skPaint.getScalerContextDescriptor(&run->fDescriptor, &fDeviceProperties, vi
ewMatrix, noGamma); |
344 run->fTypeface.reset(SkSafeRef(skPaint.getTypeface())); | 343 run->fTypeface.reset(SkSafeRef(skPaint.getTypeface())); |
345 return SkGlyphCache::DetachCache(run->fTypeface, run->fDescriptor.getDesc())
; | 344 return SkGlyphCache::DetachCache(run->fTypeface, run->fDescriptor.getDesc())
; |
346 } | 345 } |
347 | 346 |
348 void GrAtlasTextContext::drawTextBlob(GrRenderTarget* rt, const GrClip& clip, | 347 void GrAtlasTextContext::drawTextBlob(SkGpuDevice* gpuDevice, GrRenderTarget* rt
, |
349 const SkPaint& skPaint, const SkMatrix& vi
ewMatrix, | 348 const GrClip& clip, const SkPaint& skPaint
, |
350 const SkTextBlob* blob, SkScalar x, SkScal
ar y, | 349 const SkMatrix& viewMatrix, const SkTextBl
ob* blob, |
| 350 SkScalar x, SkScalar y, |
351 SkDrawFilter* drawFilter, const SkIRect& c
lipBounds) { | 351 SkDrawFilter* drawFilter, const SkIRect& c
lipBounds) { |
352 // If we have been abandoned, then don't draw | 352 // If we have been abandoned, then don't draw |
353 if (fContext->abandoned()) { | 353 if (fContext->abandoned()) { |
354 return; | 354 return; |
355 } | 355 } |
356 | 356 |
357 GrDrawContext* drawContext = fContext->drawContext(); | 357 GrDrawContext* drawContext = fContext->drawContext(); |
358 if (!drawContext) { | 358 if (!drawContext) { |
359 return; | 359 return; |
360 } | 360 } |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
404 } | 404 } |
405 | 405 |
406 if (cacheBlob) { | 406 if (cacheBlob) { |
407 if (MustRegenerateBlob(&transX, &transY, *cacheBlob, skPaint, blurRec, v
iewMatrix, x, y)) { | 407 if (MustRegenerateBlob(&transX, &transY, *cacheBlob, skPaint, blurRec, v
iewMatrix, x, y)) { |
408 // We have to remake the blob because changes may invalidate our mas
ks. | 408 // We have to remake the blob because changes may invalidate our mas
ks. |
409 // TODO we could probably get away reuse most of the time if the poi
nter is unique, | 409 // TODO we could probably get away reuse most of the time if the poi
nter is unique, |
410 // but we'd have to clear the subrun information | 410 // but we'd have to clear the subrun information |
411 fCache->remove(cacheBlob); | 411 fCache->remove(cacheBlob); |
412 cacheBlob.reset(SkRef(fCache->createCachedBlob(blob, key, blurRec, s
kPaint, | 412 cacheBlob.reset(SkRef(fCache->createCachedBlob(blob, key, blurRec, s
kPaint, |
413 kGrayTextVASize))); | 413 kGrayTextVASize))); |
414 this->regenerateTextBlob(cacheBlob, skPaint, grPaint.getColor(), vie
wMatrix, blob, x, y, | 414 this->regenerateTextBlob(gpuDevice, cacheBlob, skPaint, grPaint.getC
olor(), viewMatrix, |
415 drawFilter, clipRect, rt, clip, grPaint); | 415 blob, x, y, drawFilter, clipRect, rt, clip,
grPaint); |
416 } else { | 416 } else { |
417 // If we can reuse the blob, then make sure we update the blob's vie
wmatrix, and x/y | 417 // If we can reuse the blob, then make sure we update the blob's vie
wmatrix, and x/y |
418 // offsets | 418 // offsets |
419 cacheBlob->fViewMatrix = viewMatrix; | 419 cacheBlob->fViewMatrix = viewMatrix; |
420 cacheBlob->fX = x; | 420 cacheBlob->fX = x; |
421 cacheBlob->fY = y; | 421 cacheBlob->fY = y; |
422 fCache->makeMRU(cacheBlob); | 422 fCache->makeMRU(cacheBlob); |
423 } | 423 } |
424 } else { | 424 } else { |
425 if (canCache) { | 425 if (canCache) { |
426 cacheBlob.reset(SkRef(fCache->createCachedBlob(blob, key, blurRec, s
kPaint, | 426 cacheBlob.reset(SkRef(fCache->createCachedBlob(blob, key, blurRec, s
kPaint, |
427 kGrayTextVASize))); | 427 kGrayTextVASize))); |
428 } else { | 428 } else { |
429 cacheBlob.reset(fCache->createBlob(blob, kGrayTextVASize)); | 429 cacheBlob.reset(fCache->createBlob(blob, kGrayTextVASize)); |
430 } | 430 } |
431 this->regenerateTextBlob(cacheBlob, skPaint, grPaint.getColor(), viewMat
rix, blob, x, y, | 431 this->regenerateTextBlob(gpuDevice, cacheBlob, skPaint, grPaint.getColor
(), viewMatrix, |
432 drawFilter, clipRect, rt, clip, grPaint); | 432 blob, x, y, drawFilter, clipRect, rt, clip, grP
aint); |
433 } | 433 } |
434 | 434 |
435 cacheBlob->fPaintColor = skPaint.getColor(); | 435 cacheBlob->fPaintColor = skPaint.getColor(); |
436 this->flush(drawContext, blob, cacheBlob, rt, skPaint, grPaint, drawFilter, | 436 this->flush(gpuDevice, drawContext, blob, cacheBlob, rt, skPaint, grPaint, d
rawFilter, |
437 clip, viewMatrix, clipBounds, x, y, transX, transY); | 437 clip, viewMatrix, clipBounds, x, y, transX, transY); |
438 } | 438 } |
439 | 439 |
440 inline bool GrAtlasTextContext::canDrawAsDistanceFields(const SkPaint& skPaint, | 440 inline bool GrAtlasTextContext::canDrawAsDistanceFields(const SkPaint& skPaint, |
441 const SkMatrix& viewMatr
ix) { | 441 const SkMatrix& viewMatr
ix) { |
442 // TODO: support perspective (need getMaxScale replacement) | 442 // TODO: support perspective (need getMaxScale replacement) |
443 if (viewMatrix.hasPerspective()) { | 443 if (viewMatrix.hasPerspective()) { |
444 return false; | 444 return false; |
445 } | 445 } |
446 | 446 |
(...skipping 18 matching lines...) Expand all Loading... |
465 } | 465 } |
466 | 466 |
467 // TODO: add some stroking support | 467 // TODO: add some stroking support |
468 if (skPaint.getStyle() != SkPaint::kFill_Style) { | 468 if (skPaint.getStyle() != SkPaint::kFill_Style) { |
469 return false; | 469 return false; |
470 } | 470 } |
471 | 471 |
472 return true; | 472 return true; |
473 } | 473 } |
474 | 474 |
475 void GrAtlasTextContext::regenerateTextBlob(BitmapTextBlob* cacheBlob, | 475 void GrAtlasTextContext::regenerateTextBlob(SkGpuDevice* gpuDevice, BitmapTextBl
ob* cacheBlob, |
476 const SkPaint& skPaint, GrColor colo
r, | 476 const SkPaint& skPaint, GrColor colo
r, |
477 const SkMatrix& viewMatrix, | 477 const SkMatrix& viewMatrix, |
478 const SkTextBlob* blob, SkScalar x,
SkScalar y, | 478 const SkTextBlob* blob, SkScalar x,
SkScalar y, |
479 SkDrawFilter* drawFilter, const SkIR
ect& clipRect, | 479 SkDrawFilter* drawFilter, const SkIR
ect& clipRect, |
480 GrRenderTarget* rt, const GrClip& cl
ip, | 480 GrRenderTarget* rt, const GrClip& cl
ip, |
481 const GrPaint& paint) { | 481 const GrPaint& paint) { |
482 cacheBlob->fViewMatrix = viewMatrix; | 482 cacheBlob->fViewMatrix = viewMatrix; |
483 cacheBlob->fX = x; | 483 cacheBlob->fX = x; |
484 cacheBlob->fY = y; | 484 cacheBlob->fY = y; |
485 | 485 |
486 // Regenerate textblob | 486 // Regenerate textblob |
487 SkPaint runPaint = skPaint; | 487 SkPaint runPaint = skPaint; |
488 SkTextBlob::RunIterator it(blob); | 488 SkTextBlob::RunIterator it(blob); |
489 for (int run = 0; !it.done(); it.next(), run++) { | 489 for (int run = 0; !it.done(); it.next(), run++) { |
490 int glyphCount = it.glyphCount(); | 490 int glyphCount = it.glyphCount(); |
491 size_t textLen = glyphCount * sizeof(uint16_t); | 491 size_t textLen = glyphCount * sizeof(uint16_t); |
492 const SkPoint& offset = it.offset(); | 492 const SkPoint& offset = it.offset(); |
493 // applyFontToPaint() always overwrites the exact same attributes, | 493 // applyFontToPaint() always overwrites the exact same attributes, |
494 // so it is safe to not re-seed the paint for this reason. | 494 // so it is safe to not re-seed the paint for this reason. |
495 it.applyFontToPaint(&runPaint); | 495 it.applyFontToPaint(&runPaint); |
496 | 496 |
497 if (drawFilter && !drawFilter->filter(&runPaint, SkDrawFilter::kText_Typ
e)) { | 497 if (drawFilter && !drawFilter->filter(&runPaint, SkDrawFilter::kText_Typ
e)) { |
498 // A false return from filter() means we should abort the current dr
aw. | 498 // A false return from filter() means we should abort the current dr
aw. |
499 runPaint = skPaint; | 499 runPaint = skPaint; |
500 continue; | 500 continue; |
501 } | 501 } |
502 | 502 |
503 runPaint.setFlags(fGpuDevice->filterTextFlags(runPaint)); | 503 runPaint.setFlags(gpuDevice->filterTextFlags(runPaint)); |
504 | 504 |
505 // setup vertex / glyphIndex for the new run | 505 // setup vertex / glyphIndex for the new run |
506 if (run > 0) { | 506 if (run > 0) { |
507 PerSubRunInfo& newRun = cacheBlob->fRuns[run].fSubRunInfo.back(); | 507 PerSubRunInfo& newRun = cacheBlob->fRuns[run].fSubRunInfo.back(); |
508 PerSubRunInfo& lastRun = cacheBlob->fRuns[run - 1].fSubRunInfo.back(
); | 508 PerSubRunInfo& lastRun = cacheBlob->fRuns[run - 1].fSubRunInfo.back(
); |
509 | 509 |
510 newRun.fVertexStartIndex = lastRun.fVertexEndIndex; | 510 newRun.fVertexStartIndex = lastRun.fVertexEndIndex; |
511 newRun.fVertexEndIndex = lastRun.fVertexEndIndex; | 511 newRun.fVertexEndIndex = lastRun.fVertexEndIndex; |
512 | 512 |
513 newRun.fGlyphStartIndex = lastRun.fGlyphEndIndex; | 513 newRun.fGlyphStartIndex = lastRun.fGlyphEndIndex; |
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
768 blob = fCache->createBlob(glyphCount, 1, kGrayTextVASize); | 768 blob = fCache->createBlob(glyphCount, 1, kGrayTextVASize); |
769 blob->fViewMatrix = viewMatrix; | 769 blob->fViewMatrix = viewMatrix; |
770 SkGlyphCache* cache = this->setupCache(&blob->fRuns[0], skPaint, &viewMa
trix, false); | 770 SkGlyphCache* cache = this->setupCache(&blob->fRuns[0], skPaint, &viewMa
trix, false); |
771 this->internalDrawBMPPosText(blob, 0, cache, skPaint, paint.getColor(),
viewMatrix, text, | 771 this->internalDrawBMPPosText(blob, 0, cache, skPaint, paint.getColor(),
viewMatrix, text, |
772 byteLength, pos, scalarsPerPosition, offset
, clipRect); | 772 byteLength, pos, scalarsPerPosition, offset
, clipRect); |
773 SkGlyphCache::AttachCache(cache); | 773 SkGlyphCache::AttachCache(cache); |
774 } | 774 } |
775 return blob; | 775 return blob; |
776 } | 776 } |
777 | 777 |
778 void GrAtlasTextContext::onDrawText(GrRenderTarget* rt, const GrClip& clip, | 778 void GrAtlasTextContext::onDrawText(GrDrawContext* drawContext, GrRenderTarget*
rt, |
| 779 const GrClip& clip, |
779 const GrPaint& paint, const SkPaint& skPaint
, | 780 const GrPaint& paint, const SkPaint& skPaint
, |
780 const SkMatrix& viewMatrix, | 781 const SkMatrix& viewMatrix, |
781 const char text[], size_t byteLength, | 782 const char text[], size_t byteLength, |
782 SkScalar x, SkScalar y, const SkIRect& regio
nClipBounds) { | 783 SkScalar x, SkScalar y, const SkIRect& regio
nClipBounds) { |
783 GrDrawContext* drawContext = fContext->drawContext(); | |
784 if (drawContext) { | 784 if (drawContext) { |
785 SkAutoTUnref<BitmapTextBlob> blob( | 785 SkAutoTUnref<BitmapTextBlob> blob( |
786 this->createDrawTextBlob(rt, clip, paint, skPaint, viewMatrix, | 786 this->createDrawTextBlob(rt, clip, paint, skPaint, viewMatrix, |
787 text, byteLength, x, y, regionClipBounds)); | 787 text, byteLength, x, y, regionClipBounds)); |
788 this->flush(drawContext, blob, rt, skPaint, paint, clip, regionClipBound
s); | 788 this->flush(drawContext, blob, rt, skPaint, paint, clip, regionClipBound
s); |
789 } | 789 } |
790 } | 790 } |
791 | 791 |
792 void GrAtlasTextContext::onDrawPosText(GrRenderTarget* rt, const GrClip& clip, | 792 void GrAtlasTextContext::onDrawPosText(GrDrawContext* drawContext, GrRenderTarge
t* rt, |
| 793 const GrClip& clip, |
793 const GrPaint& paint, const SkPaint& skPa
int, | 794 const GrPaint& paint, const SkPaint& skPa
int, |
794 const SkMatrix& viewMatrix, | 795 const SkMatrix& viewMatrix, |
795 const char text[], size_t byteLength, | 796 const char text[], size_t byteLength, |
796 const SkScalar pos[], int scalarsPerPosit
ion, | 797 const SkScalar pos[], int scalarsPerPosit
ion, |
797 const SkPoint& offset, const SkIRect& reg
ionClipBounds) { | 798 const SkPoint& offset, const SkIRect& reg
ionClipBounds) { |
798 GrDrawContext* drawContext = fContext->drawContext(); | |
799 if (drawContext) { | 799 if (drawContext) { |
800 SkAutoTUnref<BitmapTextBlob> blob( | 800 SkAutoTUnref<BitmapTextBlob> blob( |
801 this->createDrawPosTextBlob(rt, clip, paint, skPaint, viewMatrix, | 801 this->createDrawPosTextBlob(rt, clip, paint, skPaint, viewMatrix, |
802 text, byteLength, | 802 text, byteLength, |
803 pos, scalarsPerPosition, | 803 pos, scalarsPerPosition, |
804 offset, regionClipBounds)); | 804 offset, regionClipBounds)); |
805 | 805 |
806 this->flush(drawContext, blob, rt, skPaint, paint, clip, regionClipBound
s); | 806 this->flush(drawContext, blob, rt, skPaint, paint, clip, regionClipBound
s); |
807 } | 807 } |
808 } | 808 } |
(...skipping 1226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2035 | 2035 |
2036 // Distance field properties | 2036 // Distance field properties |
2037 SkAutoTUnref<DistanceAdjustTable> fDistanceAdjustTable; | 2037 SkAutoTUnref<DistanceAdjustTable> fDistanceAdjustTable; |
2038 SkColor fFilteredColor; | 2038 SkColor fFilteredColor; |
2039 bool fUseDistanceFields; | 2039 bool fUseDistanceFields; |
2040 bool fUseLCDText; | 2040 bool fUseLCDText; |
2041 bool fUseBGR; | 2041 bool fUseBGR; |
2042 float fGamma; | 2042 float fGamma; |
2043 }; | 2043 }; |
2044 | 2044 |
2045 void GrAtlasTextContext::flushRunAsPaths(const SkTextBlob::RunIterator& it, cons
t SkPaint& skPaint, | 2045 void GrAtlasTextContext::flushRunAsPaths(SkGpuDevice* gpuDevice, GrDrawContext*
drawContext, |
| 2046 GrRenderTarget* rt, const SkTextBlob::R
unIterator& it, |
| 2047 const GrClip& clip, const SkPaint& skPa
int, |
2046 SkDrawFilter* drawFilter, const SkMatri
x& viewMatrix, | 2048 SkDrawFilter* drawFilter, const SkMatri
x& viewMatrix, |
2047 const SkIRect& clipBounds, SkScalar x,
SkScalar y) { | 2049 const SkIRect& clipBounds, SkScalar x,
SkScalar y) { |
2048 SkPaint runPaint = skPaint; | 2050 SkPaint runPaint = skPaint; |
2049 | 2051 |
2050 size_t textLen = it.glyphCount() * sizeof(uint16_t); | 2052 size_t textLen = it.glyphCount() * sizeof(uint16_t); |
2051 const SkPoint& offset = it.offset(); | 2053 const SkPoint& offset = it.offset(); |
2052 | 2054 |
2053 it.applyFontToPaint(&runPaint); | 2055 it.applyFontToPaint(&runPaint); |
2054 | 2056 |
2055 if (drawFilter && !drawFilter->filter(&runPaint, SkDrawFilter::kText_Type))
{ | 2057 if (drawFilter && !drawFilter->filter(&runPaint, SkDrawFilter::kText_Type))
{ |
2056 return; | 2058 return; |
2057 } | 2059 } |
2058 | 2060 |
2059 runPaint.setFlags(fGpuDevice->filterTextFlags(runPaint)); | 2061 runPaint.setFlags(gpuDevice->filterTextFlags(runPaint)); |
2060 | 2062 |
2061 switch (it.positioning()) { | 2063 switch (it.positioning()) { |
2062 case SkTextBlob::kDefault_Positioning: | 2064 case SkTextBlob::kDefault_Positioning: |
2063 this->drawTextAsPath(runPaint, viewMatrix, (const char *)it.glyphs()
, | 2065 this->drawTextAsPath(drawContext, rt, clip, runPaint, viewMatrix, |
| 2066 (const char *)it.glyphs(), |
2064 textLen, x + offset.x(), y + offset.y(), clipBo
unds); | 2067 textLen, x + offset.x(), y + offset.y(), clipBo
unds); |
2065 break; | 2068 break; |
2066 case SkTextBlob::kHorizontal_Positioning: | 2069 case SkTextBlob::kHorizontal_Positioning: |
2067 this->drawPosTextAsPath(runPaint, viewMatrix, (const char*)it.glyphs
(), | 2070 this->drawPosTextAsPath(drawContext, rt, clip, runPaint, viewMatrix, |
| 2071 (const char*)it.glyphs(), |
2068 textLen, it.pos(), 1, SkPoint::Make(x, y + o
ffset.y()), | 2072 textLen, it.pos(), 1, SkPoint::Make(x, y + o
ffset.y()), |
2069 clipBounds); | 2073 clipBounds); |
2070 break; | 2074 break; |
2071 case SkTextBlob::kFull_Positioning: | 2075 case SkTextBlob::kFull_Positioning: |
2072 this->drawPosTextAsPath(runPaint, viewMatrix, (const char*)it.glyphs
(), | 2076 this->drawPosTextAsPath(drawContext, rt, clip, runPaint, viewMatrix, |
| 2077 (const char*)it.glyphs(), |
2073 textLen, it.pos(), 2, SkPoint::Make(x, y), c
lipBounds); | 2078 textLen, it.pos(), 2, SkPoint::Make(x, y), c
lipBounds); |
2074 break; | 2079 break; |
2075 } | 2080 } |
2076 } | 2081 } |
2077 | 2082 |
2078 | 2083 |
2079 inline BitmapTextBatch* | 2084 inline BitmapTextBatch* |
2080 GrAtlasTextContext::createBatch(BitmapTextBlob* cacheBlob, const PerSubRunInfo&
info, | 2085 GrAtlasTextContext::createBatch(BitmapTextBlob* cacheBlob, const PerSubRunInfo&
info, |
2081 int glyphCount, int run, int subRun, | 2086 int glyphCount, int run, int subRun, |
2082 GrColor color, SkScalar transX, SkScalar transY, | 2087 GrColor color, SkScalar transX, SkScalar transY, |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2132 continue; | 2137 continue; |
2133 } | 2138 } |
2134 | 2139 |
2135 SkAutoTUnref<BitmapTextBatch> batch(this->createBatch(cacheBlob, info, g
lyphCount, run, | 2140 SkAutoTUnref<BitmapTextBatch> batch(this->createBatch(cacheBlob, info, g
lyphCount, run, |
2136 subRun, color, tra
nsX, transY, | 2141 subRun, color, tra
nsX, transY, |
2137 skPaint)); | 2142 skPaint)); |
2138 drawContext->drawText(pipelineBuilder, batch); | 2143 drawContext->drawText(pipelineBuilder, batch); |
2139 } | 2144 } |
2140 } | 2145 } |
2141 | 2146 |
2142 inline void GrAtlasTextContext::flushBigGlyphs(BitmapTextBlob* cacheBlob, GrRend
erTarget* rt, | 2147 inline void GrAtlasTextContext::flushBigGlyphs(BitmapTextBlob* cacheBlob, |
2143 const SkPaint& skPaint, | 2148 GrDrawContext* drawContext, GrRen
derTarget* rt, |
| 2149 const GrClip& clip, const SkPaint
& skPaint, |
2144 SkScalar transX, SkScalar transY, | 2150 SkScalar transX, SkScalar transY, |
2145 const SkIRect& clipBounds) { | 2151 const SkIRect& clipBounds) { |
2146 if (!cacheBlob->fBigGlyphs.count()) { | 2152 if (!cacheBlob->fBigGlyphs.count()) { |
2147 return; | 2153 return; |
2148 } | 2154 } |
2149 | 2155 |
2150 SkMatrix pathMatrix; | 2156 SkMatrix pathMatrix; |
2151 if (!cacheBlob->fViewMatrix.invert(&pathMatrix)) { | 2157 if (!cacheBlob->fViewMatrix.invert(&pathMatrix)) { |
2152 SkDebugf("could not invert viewmatrix\n"); | 2158 SkDebugf("could not invert viewmatrix\n"); |
2153 return; | 2159 return; |
2154 } | 2160 } |
2155 | 2161 |
2156 for (int i = 0; i < cacheBlob->fBigGlyphs.count(); i++) { | 2162 for (int i = 0; i < cacheBlob->fBigGlyphs.count(); i++) { |
2157 BitmapTextBlob::BigGlyph& bigGlyph = cacheBlob->fBigGlyphs[i]; | 2163 BitmapTextBlob::BigGlyph& bigGlyph = cacheBlob->fBigGlyphs[i]; |
2158 bigGlyph.fVx += transX; | 2164 bigGlyph.fVx += transX; |
2159 bigGlyph.fVy += transY; | 2165 bigGlyph.fVy += transY; |
2160 SkMatrix translate = cacheBlob->fViewMatrix; | 2166 SkMatrix translate = cacheBlob->fViewMatrix; |
2161 translate.postTranslate(bigGlyph.fVx, bigGlyph.fVy); | 2167 translate.postTranslate(bigGlyph.fVx, bigGlyph.fVy); |
2162 | 2168 |
2163 fGpuDevice->internalDrawPath(bigGlyph.fPath, skPaint, translate, &pathMa
trix, clipBounds, | 2169 GrBlurUtils::drawPathWithMaskFilter(fContext, drawContext, rt, clip, big
Glyph.fPath, |
2164 false); | 2170 skPaint, translate, &pathMatrix, cli
pBounds, false); |
2165 } | 2171 } |
2166 } | 2172 } |
2167 | 2173 |
2168 void GrAtlasTextContext::flush(GrDrawContext* drawContext, | 2174 void GrAtlasTextContext::flush(SkGpuDevice* gpuDevice, |
| 2175 GrDrawContext* drawContext, |
2169 const SkTextBlob* blob, | 2176 const SkTextBlob* blob, |
2170 BitmapTextBlob* cacheBlob, | 2177 BitmapTextBlob* cacheBlob, |
2171 GrRenderTarget* rt, | 2178 GrRenderTarget* rt, |
2172 const SkPaint& skPaint, | 2179 const SkPaint& skPaint, |
2173 const GrPaint& grPaint, | 2180 const GrPaint& grPaint, |
2174 SkDrawFilter* drawFilter, | 2181 SkDrawFilter* drawFilter, |
2175 const GrClip& clip, | 2182 const GrClip& clip, |
2176 const SkMatrix& viewMatrix, | 2183 const SkMatrix& viewMatrix, |
2177 const SkIRect& clipBounds, | 2184 const SkIRect& clipBounds, |
2178 SkScalar x, SkScalar y, | 2185 SkScalar x, SkScalar y, |
2179 SkScalar transX, SkScalar transY) { | 2186 SkScalar transX, SkScalar transY) { |
2180 // 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 |
2181 // it as paths | 2188 // it as paths |
2182 GrPipelineBuilder pipelineBuilder; | 2189 GrPipelineBuilder pipelineBuilder; |
2183 pipelineBuilder.setFromPaint(grPaint, rt, clip); | 2190 pipelineBuilder.setFromPaint(grPaint, rt, clip); |
2184 | 2191 |
2185 GrColor color = grPaint.getColor(); | 2192 GrColor color = grPaint.getColor(); |
2186 | 2193 |
2187 SkTextBlob::RunIterator it(blob); | 2194 SkTextBlob::RunIterator it(blob); |
2188 for (int run = 0; !it.done(); it.next(), run++) { | 2195 for (int run = 0; !it.done(); it.next(), run++) { |
2189 if (cacheBlob->fRuns[run].fDrawAsPaths) { | 2196 if (cacheBlob->fRuns[run].fDrawAsPaths) { |
2190 this->flushRunAsPaths(it, skPaint, drawFilter, viewMatrix, clipBound
s, x, y); | 2197 this->flushRunAsPaths(gpuDevice, drawContext, rt, it, clip, skPaint, |
| 2198 drawFilter, viewMatrix, clipBounds, x, y); |
2191 continue; | 2199 continue; |
2192 } | 2200 } |
2193 cacheBlob->fRuns[run].fVertexBounds.offset(transX, transY); | 2201 cacheBlob->fRuns[run].fVertexBounds.offset(transX, transY); |
2194 this->flushRun(drawContext, &pipelineBuilder, cacheBlob, run, color, | 2202 this->flushRun(drawContext, &pipelineBuilder, cacheBlob, run, color, |
2195 transX, transY, skPaint); | 2203 transX, transY, skPaint); |
2196 } | 2204 } |
2197 | 2205 |
2198 // Now flush big glyphs | 2206 // Now flush big glyphs |
2199 this->flushBigGlyphs(cacheBlob, rt, skPaint, transX, transY, clipBounds); | 2207 this->flushBigGlyphs(cacheBlob, drawContext, rt, clip, skPaint, transX, tran
sY, clipBounds); |
2200 } | 2208 } |
2201 | 2209 |
2202 void GrAtlasTextContext::flush(GrDrawContext* drawContext, | 2210 void GrAtlasTextContext::flush(GrDrawContext* drawContext, |
2203 BitmapTextBlob* cacheBlob, | 2211 BitmapTextBlob* cacheBlob, |
2204 GrRenderTarget* rt, | 2212 GrRenderTarget* rt, |
2205 const SkPaint& skPaint, | 2213 const SkPaint& skPaint, |
2206 const GrPaint& grPaint, | 2214 const GrPaint& grPaint, |
2207 const GrClip& clip, | 2215 const GrClip& clip, |
2208 const SkIRect& clipBounds) { | 2216 const SkIRect& clipBounds) { |
2209 GrPipelineBuilder pipelineBuilder; | 2217 GrPipelineBuilder pipelineBuilder; |
2210 pipelineBuilder.setFromPaint(grPaint, rt, clip); | 2218 pipelineBuilder.setFromPaint(grPaint, rt, clip); |
2211 | 2219 |
2212 GrColor color = grPaint.getColor(); | 2220 GrColor color = grPaint.getColor(); |
2213 for (int run = 0; run < cacheBlob->fRunCount; run++) { | 2221 for (int run = 0; run < cacheBlob->fRunCount; run++) { |
2214 this->flushRun(drawContext, &pipelineBuilder, cacheBlob, run, color, 0,
0, skPaint); | 2222 this->flushRun(drawContext, &pipelineBuilder, cacheBlob, run, color, 0,
0, skPaint); |
2215 } | 2223 } |
2216 | 2224 |
2217 // Now flush big glyphs | 2225 // Now flush big glyphs |
2218 this->flushBigGlyphs(cacheBlob, rt, skPaint, 0, 0, clipBounds); | 2226 this->flushBigGlyphs(cacheBlob, drawContext, rt, clip, skPaint, 0, 0, clipBo
unds); |
2219 } | 2227 } |
2220 | 2228 |
2221 ////////////////////////////////////////////////////////////////////////////////
/////////////////// | 2229 ////////////////////////////////////////////////////////////////////////////////
/////////////////// |
2222 | 2230 |
2223 #ifdef GR_TEST_UTILS | 2231 #ifdef GR_TEST_UTILS |
2224 | 2232 |
2225 BATCH_TEST_DEFINE(TextBlobBatch) { | 2233 BATCH_TEST_DEFINE(TextBlobBatch) { |
2226 static uint32_t gContextID = SK_InvalidGenID; | 2234 static uint32_t gContextID = SK_InvalidGenID; |
2227 static GrAtlasTextContext* gTextContext = NULL; | 2235 static GrAtlasTextContext* gTextContext = NULL; |
2228 static SkDeviceProperties gDeviceProperties(SkDeviceProperties::kLegacyLCD_I
nitType); | 2236 static SkDeviceProperties gDeviceProperties(SkDeviceProperties::kLegacyLCD_I
nitType); |
2229 | 2237 |
2230 if (context->uniqueID() != gContextID) { | 2238 if (context->uniqueID() != gContextID) { |
2231 gContextID = context->uniqueID(); | 2239 gContextID = context->uniqueID(); |
2232 SkDELETE(gTextContext); | 2240 SkDELETE(gTextContext); |
2233 // We don't yet test the fall back to paths in the GrTextContext base cl
ass. This is mostly | 2241 // We don't yet test the fall back to paths in the GrTextContext base cl
ass. This is mostly |
2234 // because we don't really want to have a gpu device here. | 2242 // because we don't really want to have a gpu device here. |
2235 // We enable distance fields by twiddling a knob on the paint | 2243 // We enable distance fields by twiddling a knob on the paint |
2236 gTextContext = GrAtlasTextContext::Create(context, NULL, gDeviceProperti
es, false); | 2244 gTextContext = GrAtlasTextContext::Create(context, gDeviceProperties, fa
lse); |
2237 } | 2245 } |
2238 | 2246 |
2239 // create dummy render target | 2247 // create dummy render target |
2240 GrSurfaceDesc desc; | 2248 GrSurfaceDesc desc; |
2241 desc.fFlags = kRenderTarget_GrSurfaceFlag; | 2249 desc.fFlags = kRenderTarget_GrSurfaceFlag; |
2242 desc.fWidth = 1024; | 2250 desc.fWidth = 1024; |
2243 desc.fHeight = 1024; | 2251 desc.fHeight = 1024; |
2244 desc.fConfig = kRGBA_8888_GrPixelConfig; | 2252 desc.fConfig = kRGBA_8888_GrPixelConfig; |
2245 desc.fSampleCnt = 0; | 2253 desc.fSampleCnt = 0; |
2246 SkAutoTUnref<GrTexture> texture(context->textureProvider()->createTexture(de
sc, true, NULL, 0)); | 2254 SkAutoTUnref<GrTexture> texture(context->textureProvider()->createTexture(de
sc, true, NULL, 0)); |
(...skipping 29 matching lines...) Expand all Loading... |
2276 gTextContext->createDrawTextBlob(rt, clip, grPaint, skPaint, viewMat
rix, text, | 2284 gTextContext->createDrawTextBlob(rt, clip, grPaint, skPaint, viewMat
rix, text, |
2277 static_cast<size_t>(textLen), 0, 0,
noClip)); | 2285 static_cast<size_t>(textLen), 0, 0,
noClip)); |
2278 | 2286 |
2279 SkScalar transX = static_cast<SkScalar>(random->nextU()); | 2287 SkScalar transX = static_cast<SkScalar>(random->nextU()); |
2280 SkScalar transY = static_cast<SkScalar>(random->nextU()); | 2288 SkScalar transY = static_cast<SkScalar>(random->nextU()); |
2281 const GrAtlasTextContext::BitmapTextBlob::Run::SubRunInfo& info = blob->fRun
s[0].fSubRunInfo[0]; | 2289 const GrAtlasTextContext::BitmapTextBlob::Run::SubRunInfo& info = blob->fRun
s[0].fSubRunInfo[0]; |
2282 return gTextContext->createBatch(blob, info, textLen, 0, 0, color, transX, t
ransY, skPaint); | 2290 return gTextContext->createBatch(blob, info, textLen, 0, 0, color, transX, t
ransY, skPaint); |
2283 } | 2291 } |
2284 | 2292 |
2285 #endif | 2293 #endif |
OLD | NEW |