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 "GrDefaultGeoProcFactory.h" | 13 #include "GrDefaultGeoProcFactory.h" |
13 #include "GrDrawTarget.h" | 14 #include "GrDrawTarget.h" |
14 #include "GrFontScaler.h" | 15 #include "GrFontScaler.h" |
15 #include "GrIndexBuffer.h" | 16 #include "GrIndexBuffer.h" |
16 #include "GrResourceProvider.h" | 17 #include "GrResourceProvider.h" |
17 #include "GrStrokeInfo.h" | 18 #include "GrStrokeInfo.h" |
18 #include "GrTextBlobCache.h" | 19 #include "GrTextBlobCache.h" |
19 #include "GrTexturePriv.h" | 20 #include "GrTexturePriv.h" |
20 #include "GrVertexBuffer.h" | 21 #include "GrVertexBuffer.h" |
21 | 22 |
(...skipping 654 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
676 blob->fViewMatrix = viewMatrix; | 677 blob->fViewMatrix = viewMatrix; |
677 Run& run = blob->fRuns[0]; | 678 Run& run = blob->fRuns[0]; |
678 PerSubRunInfo& subRun = run.fSubRunInfo.back(); | 679 PerSubRunInfo& subRun = run.fSubRunInfo.back(); |
679 subRun.fUseLCDText = origPaint.isLCDRenderText(); | 680 subRun.fUseLCDText = origPaint.isLCDRenderText(); |
680 subRun.fDrawAsDistanceFields = true; | 681 subRun.fDrawAsDistanceFields = true; |
681 | 682 |
682 *cache = this->setupCache(&blob->fRuns[0], *dfPaint, NULL, true); | 683 *cache = this->setupCache(&blob->fRuns[0], *dfPaint, NULL, true); |
683 return blob; | 684 return blob; |
684 } | 685 } |
685 | 686 |
686 void GrAtlasTextContext::onDrawText(GrRenderTarget* rt, const GrClip& clip, | 687 inline GrAtlasTextContext::BitmapTextBlob* |
687 const GrPaint& paint, const SkPaint& skPaint
, | 688 GrAtlasTextContext::createDrawTextBlob(GrRenderTarget* rt, const GrClip& clip, |
688 const SkMatrix& viewMatrix, | 689 const GrPaint& paint, const SkPaint& skPa
int, |
689 const char text[], size_t byteLength, | 690 const SkMatrix& viewMatrix, |
690 SkScalar x, SkScalar y, const SkIRect& regio
nClipBounds) { | 691 const char text[], size_t byteLength, |
| 692 SkScalar x, SkScalar y, const SkIRect& re
gionClipBounds) { |
691 int glyphCount = skPaint.countText(text, byteLength); | 693 int glyphCount = skPaint.countText(text, byteLength); |
692 SkIRect clipRect; | 694 SkIRect clipRect; |
693 clip.getConservativeBounds(rt->width(), rt->height(), &clipRect); | 695 clip.getConservativeBounds(rt->width(), rt->height(), &clipRect); |
694 | 696 |
695 // setup cache | 697 BitmapTextBlob* blob; |
696 if (this->canDrawAsDistanceFields(skPaint, viewMatrix)) { | 698 if (this->canDrawAsDistanceFields(skPaint, viewMatrix)) { |
697 SkPaint dfPaint; | 699 SkPaint dfPaint; |
698 SkScalar textRatio; | 700 SkScalar textRatio; |
699 SkGlyphCache* cache; | 701 SkGlyphCache* cache; |
700 SkAutoTUnref<BitmapTextBlob> blob(this->setupDFBlob(glyphCount, skPaint,
viewMatrix, &cache, | 702 blob = this->setupDFBlob(glyphCount, skPaint, viewMatrix, &cache, &dfPai
nt, &textRatio); |
701 &dfPaint, &textRatio
)); | |
702 | 703 |
703 SkTDArray<char> fallbackTxt; | 704 SkTDArray<char> fallbackTxt; |
704 SkTDArray<SkScalar> fallbackPos; | 705 SkTDArray<SkScalar> fallbackPos; |
705 SkPoint offset; | 706 SkPoint offset; |
706 this->internalDrawDFText(blob, 0, cache, dfPaint, paint.getColor(), view
Matrix, text, | 707 this->internalDrawDFText(blob, 0, cache, dfPaint, paint.getColor(), view
Matrix, text, |
707 byteLength, x, y, clipRect, textRatio, &fallbac
kTxt, &fallbackPos, | 708 byteLength, x, y, clipRect, textRatio, &fallbac
kTxt, &fallbackPos, |
708 &offset, skPaint); | 709 &offset, skPaint); |
709 SkGlyphCache::AttachCache(cache); | 710 SkGlyphCache::AttachCache(cache); |
710 if (fallbackTxt.count()) { | 711 if (fallbackTxt.count()) { |
711 this->fallbackDrawPosText(blob, 0, rt, clip, paint, skPaint, viewMat
rix, fallbackTxt, | 712 this->fallbackDrawPosText(blob, 0, rt, clip, paint, skPaint, viewMat
rix, fallbackTxt, |
712 fallbackPos, 2, offset, clipRect); | 713 fallbackPos, 2, offset, clipRect); |
713 } | 714 } |
714 this->flush(fContext->getTextTarget(), blob, rt, skPaint, paint, clip); | |
715 } else { | 715 } else { |
716 SkAutoTUnref<BitmapTextBlob> blob(fCache->createBlob(glyphCount, 1, kGra
yTextVASize)); | 716 blob = fCache->createBlob(glyphCount, 1, kGrayTextVASize); |
717 blob->fViewMatrix = viewMatrix; | 717 blob->fViewMatrix = viewMatrix; |
718 | 718 |
719 SkGlyphCache* cache = this->setupCache(&blob->fRuns[0], skPaint, &viewMa
trix, false); | 719 SkGlyphCache* cache = this->setupCache(&blob->fRuns[0], skPaint, &viewMa
trix, false); |
720 this->internalDrawBMPText(blob, 0, cache, skPaint, paint.getColor(), vie
wMatrix, text, | 720 this->internalDrawBMPText(blob, 0, cache, skPaint, paint.getColor(), vie
wMatrix, text, |
721 byteLength, x, y, clipRect); | 721 byteLength, x, y, clipRect); |
722 SkGlyphCache::AttachCache(cache); | 722 SkGlyphCache::AttachCache(cache); |
723 this->flush(fContext->getTextTarget(), blob, rt, skPaint, paint, clip); | |
724 } | 723 } |
| 724 return blob; |
725 } | 725 } |
726 | 726 |
727 void GrAtlasTextContext::onDrawPosText(GrRenderTarget* rt, const GrClip& clip, | 727 inline GrAtlasTextContext::BitmapTextBlob* |
728 const GrPaint& paint, const SkPaint& skPa
int, | 728 GrAtlasTextContext::createDrawPosTextBlob(GrRenderTarget* rt, const GrClip& clip
, |
729 const SkMatrix& viewMatrix, | 729 const GrPaint& paint, const SkPaint& s
kPaint, |
730 const char text[], size_t byteLength, | 730 const SkMatrix& viewMatrix, |
731 const SkScalar pos[], int scalarsPerPosit
ion, | 731 const char text[], size_t byteLength, |
732 const SkPoint& offset, const SkIRect& reg
ionClipBounds) { | 732 const SkScalar pos[], int scalarsPerPo
sition, |
| 733 const SkPoint& offset, const SkIRect&
regionClipBounds) { |
733 int glyphCount = skPaint.countText(text, byteLength); | 734 int glyphCount = skPaint.countText(text, byteLength); |
734 | 735 |
735 SkIRect clipRect; | 736 SkIRect clipRect; |
736 clip.getConservativeBounds(rt->width(), rt->height(), &clipRect); | 737 clip.getConservativeBounds(rt->width(), rt->height(), &clipRect); |
737 | 738 |
| 739 BitmapTextBlob* blob; |
738 if (this->canDrawAsDistanceFields(skPaint, viewMatrix)) { | 740 if (this->canDrawAsDistanceFields(skPaint, viewMatrix)) { |
739 SkPaint dfPaint; | 741 SkPaint dfPaint; |
740 SkScalar textRatio; | 742 SkScalar textRatio; |
741 SkGlyphCache* cache; | 743 SkGlyphCache* cache; |
742 SkAutoTUnref<BitmapTextBlob> blob(this->setupDFBlob(glyphCount, skPaint,
viewMatrix, &cache, | 744 blob = this->setupDFBlob(glyphCount, skPaint, viewMatrix, &cache, &dfPai
nt, &textRatio); |
743 &dfPaint, &textRatio
)); | |
744 | 745 |
745 SkTDArray<char> fallbackTxt; | 746 SkTDArray<char> fallbackTxt; |
746 SkTDArray<SkScalar> fallbackPos; | 747 SkTDArray<SkScalar> fallbackPos; |
747 this->internalDrawDFPosText(blob, 0, cache, dfPaint, paint.getColor(), v
iewMatrix, text, | 748 this->internalDrawDFPosText(blob, 0, cache, dfPaint, paint.getColor(), v
iewMatrix, text, |
748 byteLength, pos, scalarsPerPosition, offset,
clipRect, | 749 byteLength, pos, scalarsPerPosition, offset,
clipRect, |
749 textRatio, &fallbackTxt, &fallbackPos); | 750 textRatio, &fallbackTxt, &fallbackPos); |
750 SkGlyphCache::AttachCache(cache); | 751 SkGlyphCache::AttachCache(cache); |
751 if (fallbackTxt.count()) { | 752 if (fallbackTxt.count()) { |
752 this->fallbackDrawPosText(blob, 0, rt, clip, paint, skPaint, viewMat
rix, fallbackTxt, | 753 this->fallbackDrawPosText(blob, 0, rt, clip, paint, skPaint, viewMat
rix, fallbackTxt, |
753 fallbackPos, scalarsPerPosition, offset, c
lipRect); | 754 fallbackPos, scalarsPerPosition, offset, c
lipRect); |
754 } | 755 } |
755 this->flush(fContext->getTextTarget(), blob, rt, skPaint, paint, clip); | |
756 } else { | 756 } else { |
757 SkAutoTUnref<BitmapTextBlob> blob(fCache->createBlob(glyphCount, 1, kGra
yTextVASize)); | 757 blob = fCache->createBlob(glyphCount, 1, kGrayTextVASize); |
758 blob->fViewMatrix = viewMatrix; | 758 blob->fViewMatrix = viewMatrix; |
759 SkGlyphCache* cache = this->setupCache(&blob->fRuns[0], skPaint, &viewMa
trix, false); | 759 SkGlyphCache* cache = this->setupCache(&blob->fRuns[0], skPaint, &viewMa
trix, false); |
760 this->internalDrawBMPPosText(blob, 0, cache, skPaint, paint.getColor(),
viewMatrix, text, | 760 this->internalDrawBMPPosText(blob, 0, cache, skPaint, paint.getColor(),
viewMatrix, text, |
761 byteLength, pos, scalarsPerPosition, offset
, clipRect); | 761 byteLength, pos, scalarsPerPosition, offset
, clipRect); |
762 SkGlyphCache::AttachCache(cache); | 762 SkGlyphCache::AttachCache(cache); |
763 this->flush(fContext->getTextTarget(), blob, rt, skPaint, paint, clip); | |
764 } | 763 } |
| 764 return blob; |
| 765 } |
| 766 |
| 767 void GrAtlasTextContext::onDrawText(GrRenderTarget* rt, const GrClip& clip, |
| 768 const GrPaint& paint, const SkPaint& skPaint
, |
| 769 const SkMatrix& viewMatrix, |
| 770 const char text[], size_t byteLength, |
| 771 SkScalar x, SkScalar y, const SkIRect& regio
nClipBounds) { |
| 772 SkAutoTUnref<BitmapTextBlob> blob( |
| 773 this->createDrawTextBlob(rt, clip, paint, skPaint, viewMatrix, |
| 774 text, byteLength, x, y, regionClipBounds)); |
| 775 this->flush(fContext->getTextTarget(), blob, rt, skPaint, paint, clip); |
| 776 } |
| 777 |
| 778 void GrAtlasTextContext::onDrawPosText(GrRenderTarget* rt, const GrClip& clip, |
| 779 const GrPaint& paint, const SkPaint& skPa
int, |
| 780 const SkMatrix& viewMatrix, |
| 781 const char text[], size_t byteLength, |
| 782 const SkScalar pos[], int scalarsPerPosit
ion, |
| 783 const SkPoint& offset, const SkIRect& reg
ionClipBounds) { |
| 784 SkAutoTUnref<BitmapTextBlob> blob( |
| 785 this->createDrawPosTextBlob(rt, clip, paint, skPaint, viewMatrix, |
| 786 text, byteLength, |
| 787 pos, scalarsPerPosition, |
| 788 offset, regionClipBounds)); |
| 789 |
| 790 this->flush(fContext->getTextTarget(), blob, rt, skPaint, paint, clip); |
765 } | 791 } |
766 | 792 |
767 void GrAtlasTextContext::internalDrawBMPText(BitmapTextBlob* blob, int runIndex, | 793 void GrAtlasTextContext::internalDrawBMPText(BitmapTextBlob* blob, int runIndex, |
768 SkGlyphCache* cache, const SkPaint&
skPaint, | 794 SkGlyphCache* cache, const SkPaint&
skPaint, |
769 GrColor color, | 795 GrColor color, |
770 const SkMatrix& viewMatrix, | 796 const SkMatrix& viewMatrix, |
771 const char text[], size_t byteLengt
h, | 797 const char text[], size_t byteLengt
h, |
772 SkScalar x, SkScalar y, const SkIRe
ct& clipRect) { | 798 SkScalar x, SkScalar y, const SkIRe
ct& clipRect) { |
773 SkASSERT(byteLength == 0 || text != NULL); | 799 SkASSERT(byteLength == 0 || text != NULL); |
774 | 800 |
(...skipping 1268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2043 textLen, it.pos(), 1, SkPoint::Make(x, y + o
ffset.y()), | 2069 textLen, it.pos(), 1, SkPoint::Make(x, y + o
ffset.y()), |
2044 clipBounds); | 2070 clipBounds); |
2045 break; | 2071 break; |
2046 case SkTextBlob::kFull_Positioning: | 2072 case SkTextBlob::kFull_Positioning: |
2047 this->drawPosTextAsPath(runPaint, viewMatrix, (const char*)it.glyphs
(), | 2073 this->drawPosTextAsPath(runPaint, viewMatrix, (const char*)it.glyphs
(), |
2048 textLen, it.pos(), 2, SkPoint::Make(x, y), c
lipBounds); | 2074 textLen, it.pos(), 2, SkPoint::Make(x, y), c
lipBounds); |
2049 break; | 2075 break; |
2050 } | 2076 } |
2051 } | 2077 } |
2052 | 2078 |
| 2079 |
| 2080 inline BitmapTextBatch* |
| 2081 GrAtlasTextContext::createBatch(BitmapTextBlob* cacheBlob, const PerSubRunInfo&
info, |
| 2082 int glyphCount, int run, int subRun, |
| 2083 GrColor color, SkScalar transX, SkScalar transY, |
| 2084 const SkPaint& skPaint) { |
| 2085 GrMaskFormat format = info.fMaskFormat; |
| 2086 GrColor subRunColor; |
| 2087 if (kARGB_GrMaskFormat == format) { |
| 2088 uint8_t paintAlpha = skPaint.getAlpha(); |
| 2089 subRunColor = SkColorSetARGB(paintAlpha, paintAlpha, paintAlpha, paintAl
pha); |
| 2090 } else { |
| 2091 subRunColor = color; |
| 2092 } |
| 2093 |
| 2094 BitmapTextBatch* batch; |
| 2095 if (info.fDrawAsDistanceFields) { |
| 2096 SkColor filteredColor; |
| 2097 SkColorFilter* colorFilter = skPaint.getColorFilter(); |
| 2098 if (colorFilter) { |
| 2099 filteredColor = colorFilter->filterColor(skPaint.getColor()); |
| 2100 } else { |
| 2101 filteredColor = skPaint.getColor(); |
| 2102 } |
| 2103 bool useBGR = SkPixelGeometryIsBGR(fDeviceProperties.pixelGeometry()); |
| 2104 float gamma = fDeviceProperties.gamma(); |
| 2105 batch = BitmapTextBatch::Create(format, glyphCount, fContext->getBatchFo
ntCache(), |
| 2106 fDistanceAdjustTable, filteredColor, |
| 2107 info.fUseLCDText, useBGR, |
| 2108 gamma); |
| 2109 } else { |
| 2110 batch = BitmapTextBatch::Create(format, glyphCount, fContext->getBatchFo
ntCache()); |
| 2111 } |
| 2112 BitmapTextBatch::Geometry& geometry = batch->geometry(); |
| 2113 geometry.fBlob = SkRef(cacheBlob); |
| 2114 geometry.fRun = run; |
| 2115 geometry.fSubRun = subRun; |
| 2116 geometry.fColor = subRunColor; |
| 2117 geometry.fTransX = transX; |
| 2118 geometry.fTransY = transY; |
| 2119 batch->init(); |
| 2120 |
| 2121 return batch; |
| 2122 } |
| 2123 |
2053 inline void GrAtlasTextContext::flushRun(GrDrawTarget* target, GrPipelineBuilder
* pipelineBuilder, | 2124 inline void GrAtlasTextContext::flushRun(GrDrawTarget* target, GrPipelineBuilder
* pipelineBuilder, |
2054 BitmapTextBlob* cacheBlob, int run, GrC
olor color, | 2125 BitmapTextBlob* cacheBlob, int run, GrC
olor color, |
2055 SkScalar transX, SkScalar transY, const
SkPaint& skPaint) { | 2126 SkScalar transX, SkScalar transY, const
SkPaint& skPaint) { |
2056 for (int subRun = 0; subRun < cacheBlob->fRuns[run].fSubRunInfo.count(); sub
Run++) { | 2127 for (int subRun = 0; subRun < cacheBlob->fRuns[run].fSubRunInfo.count(); sub
Run++) { |
2057 const PerSubRunInfo& info = cacheBlob->fRuns[run].fSubRunInfo[subRun]; | 2128 const PerSubRunInfo& info = cacheBlob->fRuns[run].fSubRunInfo[subRun]; |
2058 int glyphCount = info.fGlyphEndIndex - info.fGlyphStartIndex; | 2129 int glyphCount = info.fGlyphEndIndex - info.fGlyphStartIndex; |
2059 if (0 == glyphCount) { | 2130 if (0 == glyphCount) { |
2060 continue; | 2131 continue; |
2061 } | 2132 } |
2062 | 2133 |
2063 GrMaskFormat format = info.fMaskFormat; | 2134 SkAutoTUnref<BitmapTextBatch> batch(this->createBatch(cacheBlob, info, g
lyphCount, run, |
2064 GrColor subRunColor; | 2135 subRun, color, tra
nsX, transY, |
2065 if (kARGB_GrMaskFormat == format) { | 2136 skPaint)); |
2066 uint8_t paintAlpha = skPaint.getAlpha(); | |
2067 subRunColor = SkColorSetARGB(paintAlpha, paintAlpha, paintAlpha, pai
ntAlpha); | |
2068 } else { | |
2069 subRunColor = color; | |
2070 } | |
2071 | |
2072 SkAutoTUnref<BitmapTextBatch> batch; | |
2073 if (info.fDrawAsDistanceFields) { | |
2074 SkColor filteredColor; | |
2075 SkColorFilter* colorFilter = skPaint.getColorFilter(); | |
2076 if (colorFilter) { | |
2077 filteredColor = colorFilter->filterColor(skPaint.getColor()); | |
2078 } else { | |
2079 filteredColor = skPaint.getColor(); | |
2080 } | |
2081 bool useBGR = SkPixelGeometryIsBGR(fDeviceProperties.pixelGeometry()
); | |
2082 float gamma = fDeviceProperties.gamma(); | |
2083 batch.reset(BitmapTextBatch::Create(format, glyphCount, fContext->ge
tBatchFontCache(), | |
2084 fDistanceAdjustTable, filteredCo
lor, | |
2085 info.fUseLCDText, useBGR, | |
2086 gamma)); | |
2087 } else { | |
2088 batch.reset(BitmapTextBatch::Create(format, glyphCount, fContext->ge
tBatchFontCache())); | |
2089 } | |
2090 BitmapTextBatch::Geometry& geometry = batch->geometry(); | |
2091 geometry.fBlob = SkRef(cacheBlob); | |
2092 geometry.fRun = run; | |
2093 geometry.fSubRun = subRun; | |
2094 geometry.fColor = subRunColor; | |
2095 geometry.fTransX = transX; | |
2096 geometry.fTransY = transY; | |
2097 batch->init(); | |
2098 | |
2099 target->drawBatch(pipelineBuilder, batch); | 2137 target->drawBatch(pipelineBuilder, batch); |
2100 } | 2138 } |
2101 } | 2139 } |
2102 | 2140 |
2103 inline void GrAtlasTextContext::flushBigGlyphs(BitmapTextBlob* cacheBlob, GrRend
erTarget* rt, | 2141 inline void GrAtlasTextContext::flushBigGlyphs(BitmapTextBlob* cacheBlob, GrRend
erTarget* rt, |
2104 const GrPaint& grPaint, const GrC
lip& clip, | 2142 const GrPaint& grPaint, const GrC
lip& clip, |
2105 SkScalar transX, SkScalar transY)
{ | 2143 SkScalar transX, SkScalar transY)
{ |
2106 for (int i = 0; i < cacheBlob->fBigGlyphs.count(); i++) { | 2144 for (int i = 0; i < cacheBlob->fBigGlyphs.count(); i++) { |
2107 BitmapTextBlob::BigGlyph& bigGlyph = cacheBlob->fBigGlyphs[i]; | 2145 BitmapTextBlob::BigGlyph& bigGlyph = cacheBlob->fBigGlyphs[i]; |
2108 bigGlyph.fVx += SkScalarTruncToInt(transX); | 2146 bigGlyph.fVx += SkScalarTruncToInt(transX); |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2160 pipelineBuilder.setFromPaint(grPaint, rt, clip); | 2198 pipelineBuilder.setFromPaint(grPaint, rt, clip); |
2161 | 2199 |
2162 GrColor color = grPaint.getColor(); | 2200 GrColor color = grPaint.getColor(); |
2163 for (int run = 0; run < cacheBlob->fRunCount; run++) { | 2201 for (int run = 0; run < cacheBlob->fRunCount; run++) { |
2164 this->flushRun(target, &pipelineBuilder, cacheBlob, run, color, 0, 0, sk
Paint); | 2202 this->flushRun(target, &pipelineBuilder, cacheBlob, run, color, 0, 0, sk
Paint); |
2165 } | 2203 } |
2166 | 2204 |
2167 // Now flush big glyphs | 2205 // Now flush big glyphs |
2168 this->flushBigGlyphs(cacheBlob, rt, grPaint, clip, 0, 0); | 2206 this->flushBigGlyphs(cacheBlob, rt, grPaint, clip, 0, 0); |
2169 } | 2207 } |
| 2208 |
| 2209 ////////////////////////////////////////////////////////////////////////////////
/////////////////// |
| 2210 |
| 2211 #ifdef GR_TEST_UTILS |
| 2212 |
| 2213 BATCH_TEST_DEFINE(TextBlob) { |
| 2214 static uint32_t gContextID = SK_InvalidGenID; |
| 2215 static GrAtlasTextContext* gTextContext = NULL; |
| 2216 static SkDeviceProperties gDeviceProperties(SkDeviceProperties::kLegacyLCD_I
nitType); |
| 2217 |
| 2218 if (context->uniqueID() != gContextID) { |
| 2219 gContextID = context->uniqueID(); |
| 2220 SkDELETE(gTextContext); |
| 2221 // We don't yet test the fall back to paths in the GrTextContext base cl
ass. This is mostly |
| 2222 // because we don't really want to have a gpu device here. |
| 2223 // We enable distance fields by twiddling a knob on the paint |
| 2224 gTextContext = GrAtlasTextContext::Create(context, NULL, gDeviceProperti
es, false); |
| 2225 } |
| 2226 |
| 2227 // create dummy render target |
| 2228 GrSurfaceDesc desc; |
| 2229 desc.fFlags = kRenderTarget_GrSurfaceFlag; |
| 2230 desc.fWidth = 1024; |
| 2231 desc.fHeight = 1024; |
| 2232 desc.fConfig = kRGBA_8888_GrPixelConfig; |
| 2233 desc.fSampleCnt = 1; |
| 2234 SkAutoTUnref<GrTexture> texture(context->textureProvider()->createTexture(de
sc, true, NULL, 0)); |
| 2235 SkASSERT(texture); |
| 2236 SkASSERT(NULL != texture->asRenderTarget()); |
| 2237 GrRenderTarget* rt = texture->asRenderTarget(); |
| 2238 |
| 2239 // Setup dummy SkPaint / GrPaint |
| 2240 GrColor color = GrRandomColor(random); |
| 2241 SkMatrix viewMatrix = GrTest::TestMatrix(random); |
| 2242 SkPaint skPaint; |
| 2243 skPaint.setDistanceFieldTextTEMP(random->nextBool()); |
| 2244 skPaint.setColor(color); |
| 2245 skPaint.setLCDRenderText(random->nextBool()); |
| 2246 skPaint.setAntiAlias(skPaint.isLCDRenderText() ? true : random->nextBool()); |
| 2247 skPaint.setSubpixelText(random->nextBool()); |
| 2248 |
| 2249 GrPaint grPaint; |
| 2250 if (!SkPaint2GrPaint(context, rt, skPaint, viewMatrix, true, &grPaint)) { |
| 2251 SkFAIL("couldn't convert paint\n"); |
| 2252 } |
| 2253 |
| 2254 const char* text = "The quick brown fox jumps over the lazy dog."; |
| 2255 int textLen = (int)strlen(text); |
| 2256 |
| 2257 // Setup clip |
| 2258 GrClip clip; |
| 2259 SkIRect noClip = SkIRect::MakeLargest(); |
| 2260 |
| 2261 // right now we don't handle textblobs, nor do we handle drawPosText. Since
we only |
| 2262 // intend to test the batch with this unit test, that is okay. |
| 2263 SkAutoTUnref<GrAtlasTextContext::BitmapTextBlob> blob( |
| 2264 gTextContext->createDrawTextBlob(rt, clip, grPaint, skPaint, viewMat
rix, text, |
| 2265 static_cast<size_t>(textLen), 0, 0,
noClip)); |
| 2266 |
| 2267 SkScalar transX = static_cast<SkScalar>(random->nextU()); |
| 2268 SkScalar transY = static_cast<SkScalar>(random->nextU()); |
| 2269 const GrAtlasTextContext::BitmapTextBlob::Run::SubRunInfo& info = blob->fRun
s[0].fSubRunInfo[0]; |
| 2270 return gTextContext->createBatch(blob, info, textLen, 0, 0, color, transX, t
ransY, skPaint); |
| 2271 } |
| 2272 |
| 2273 #endif |
OLD | NEW |