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