| 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 "GrAtlas.h" | 9 #include "GrAtlas.h" |
| 10 #include "GrBatch.h" | 10 #include "GrBatch.h" |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 86 } | 86 } |
| 87 | 87 |
| 88 bool GrAtlasTextContext::canDraw(const GrRenderTarget*, | 88 bool GrAtlasTextContext::canDraw(const GrRenderTarget*, |
| 89 const GrClip&, | 89 const GrClip&, |
| 90 const GrPaint&, | 90 const GrPaint&, |
| 91 const SkPaint& skPaint, | 91 const SkPaint& skPaint, |
| 92 const SkMatrix& viewMatrix) { | 92 const SkMatrix& viewMatrix) { |
| 93 return !SkDraw::ShouldDrawTextAsPaths(skPaint, viewMatrix); | 93 return !SkDraw::ShouldDrawTextAsPaths(skPaint, viewMatrix); |
| 94 } | 94 } |
| 95 | 95 |
| 96 inline void GrAtlasTextContext::init(GrRenderTarget* rt, const GrClip& clip, | |
| 97 const GrPaint& paint, const SkPaint& skPain
t, | |
| 98 const SkIRect& regionClipBounds) { | |
| 99 INHERITED::init(rt, clip, paint, skPaint, regionClipBounds); | |
| 100 | |
| 101 fCurrStrike = NULL; | |
| 102 } | |
| 103 | |
| 104 bool GrAtlasTextContext::MustRegenerateBlob(const BitmapTextBlob& blob, const Sk
Paint& paint, | 96 bool GrAtlasTextContext::MustRegenerateBlob(const BitmapTextBlob& blob, const Sk
Paint& paint, |
| 105 const SkMatrix& viewMatrix, SkScalar
x, SkScalar y) { | 97 const SkMatrix& viewMatrix, SkScalar
x, SkScalar y) { |
| 106 // We always regenerate blobs with patheffects or mask filters we could cach
e these | 98 // We always regenerate blobs with patheffects or mask filters we could cach
e these |
| 107 // TODO find some way to cache the maskfilter / patheffects on the textblob | 99 // TODO find some way to cache the maskfilter / patheffects on the textblob |
| 108 return !blob.fViewMatrix.cheapEqualTo(viewMatrix) || blob.fX != x || blob.fY
!= y || | 100 return !blob.fViewMatrix.cheapEqualTo(viewMatrix) || blob.fX != x || blob.fY
!= y || |
| 109 paint.getMaskFilter() || paint.getPathEffect() || paint.getStyle() !
= blob.fStyle; | 101 paint.getMaskFilter() || paint.getPathEffect() || paint.getStyle() !
= blob.fStyle; |
| 110 } | 102 } |
| 111 | 103 |
| 112 | 104 |
| 113 inline SkGlyphCache* GrAtlasTextContext::setupCache(BitmapTextBlob::Run* run, | 105 inline SkGlyphCache* GrAtlasTextContext::setupCache(BitmapTextBlob::Run* run, |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 185 cacheBlob = CreateBlob(glyphCount, runCount); | 177 cacheBlob = CreateBlob(glyphCount, runCount); |
| 186 fCache.set(blob->uniqueID(), cacheBlob); | 178 fCache.set(blob->uniqueID(), cacheBlob); |
| 187 this->regenerateTextBlob(cacheBlob, skPaint, viewMatrix, blob, x, y, dra
wFilter, clipRect); | 179 this->regenerateTextBlob(cacheBlob, skPaint, viewMatrix, blob, x, y, dra
wFilter, clipRect); |
| 188 } | 180 } |
| 189 | 181 |
| 190 // Though for the time being runs in the textblob can override the paint, th
ey only touch font | 182 // Though for the time being runs in the textblob can override the paint, th
ey only touch font |
| 191 // info. | 183 // info. |
| 192 GrPaint grPaint; | 184 GrPaint grPaint; |
| 193 SkPaint2GrPaintShader(fContext, rt, skPaint, viewMatrix, true, &grPaint); | 185 SkPaint2GrPaintShader(fContext, rt, skPaint, viewMatrix, true, &grPaint); |
| 194 | 186 |
| 195 this->flush(fContext->getTextTarget(), cacheBlob, rt, grPaint, clip, viewMat
rix, | 187 this->flush(fContext->getTextTarget(), blob, cacheBlob, rt, skPaint, grPaint
, drawFilter, |
| 196 fSkPaint.getAlpha()); | 188 clip, viewMatrix, clipBounds, x, y); |
| 197 } | 189 } |
| 198 | 190 |
| 199 void GrAtlasTextContext::regenerateTextBlob(BitmapTextBlob* cacheBlob, | 191 void GrAtlasTextContext::regenerateTextBlob(BitmapTextBlob* cacheBlob, |
| 200 const SkPaint& skPaint, const SkMatr
ix& viewMatrix, | 192 const SkPaint& skPaint, const SkMatr
ix& viewMatrix, |
| 201 const SkTextBlob* blob, SkScalar x,
SkScalar y, | 193 const SkTextBlob* blob, SkScalar x,
SkScalar y, |
| 202 SkDrawFilter* drawFilter, const SkIR
ect& clipRect) { | 194 SkDrawFilter* drawFilter, const SkIR
ect& clipRect) { |
| 203 cacheBlob->fViewMatrix = viewMatrix; | 195 cacheBlob->fViewMatrix = viewMatrix; |
| 204 cacheBlob->fX = x; | 196 cacheBlob->fX = x; |
| 205 cacheBlob->fY = y; | 197 cacheBlob->fY = y; |
| 206 cacheBlob->fStyle = skPaint.getStyle(); | 198 cacheBlob->fStyle = skPaint.getStyle(); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 231 PerSubRunInfo& newRun = cacheBlob->fRuns[run].fSubRunInfo.back(); | 223 PerSubRunInfo& newRun = cacheBlob->fRuns[run].fSubRunInfo.back(); |
| 232 PerSubRunInfo& lastRun = cacheBlob->fRuns[run - 1].fSubRunInfo.back(
); | 224 PerSubRunInfo& lastRun = cacheBlob->fRuns[run - 1].fSubRunInfo.back(
); |
| 233 | 225 |
| 234 newRun.fVertexStartIndex = lastRun.fVertexEndIndex; | 226 newRun.fVertexStartIndex = lastRun.fVertexEndIndex; |
| 235 newRun.fVertexEndIndex = lastRun.fVertexEndIndex; | 227 newRun.fVertexEndIndex = lastRun.fVertexEndIndex; |
| 236 | 228 |
| 237 newRun.fGlyphStartIndex = lastRun.fGlyphEndIndex; | 229 newRun.fGlyphStartIndex = lastRun.fGlyphEndIndex; |
| 238 newRun.fGlyphEndIndex = lastRun.fGlyphEndIndex; | 230 newRun.fGlyphEndIndex = lastRun.fGlyphEndIndex; |
| 239 } | 231 } |
| 240 | 232 |
| 233 if (SkDraw::ShouldDrawTextAsPaths(skPaint, viewMatrix)) { |
| 234 cacheBlob->fRuns[run].fDrawAsPaths = true; |
| 235 continue; |
| 236 } |
| 237 cacheBlob->fRuns[run].fDrawAsPaths = false; |
| 238 |
| 241 switch (it.positioning()) { | 239 switch (it.positioning()) { |
| 242 case SkTextBlob::kDefault_Positioning: | 240 case SkTextBlob::kDefault_Positioning: |
| 243 this->internalDrawText(cacheBlob, run, cache, runPaint, viewMatr
ix, | 241 this->internalDrawText(cacheBlob, run, cache, runPaint, viewMatr
ix, |
| 244 (const char *)it.glyphs(), textLen, | 242 (const char *)it.glyphs(), textLen, |
| 245 x + offset.x(), y + offset.y(), clipRect)
; | 243 x + offset.x(), y + offset.y(), clipRect)
; |
| 246 break; | 244 break; |
| 247 case SkTextBlob::kHorizontal_Positioning: | 245 case SkTextBlob::kHorizontal_Positioning: |
| 248 this->internalDrawPosText(cacheBlob, run, cache, runPaint, viewM
atrix, | 246 this->internalDrawPosText(cacheBlob, run, cache, runPaint, viewM
atrix, |
| 249 (const char*)it.glyphs(), textLen, it.
pos(), 1, | 247 (const char*)it.glyphs(), textLen, it.
pos(), 1, |
| 250 SkPoint::Make(x, y + offset.y()), clip
Rect); | 248 SkPoint::Make(x, y + offset.y()), clip
Rect); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 278 blob->fStyle = skPaint.getStyle(); | 276 blob->fStyle = skPaint.getStyle(); |
| 279 | 277 |
| 280 SkIRect clipRect; | 278 SkIRect clipRect; |
| 281 clip.getConservativeBounds(rt->width(), rt->height(), &clipRect); | 279 clip.getConservativeBounds(rt->width(), rt->height(), &clipRect); |
| 282 | 280 |
| 283 // setup cache | 281 // setup cache |
| 284 SkGlyphCache* cache = this->setupCache(&blob->fRuns[0], skPaint, viewMatrix)
; | 282 SkGlyphCache* cache = this->setupCache(&blob->fRuns[0], skPaint, viewMatrix)
; |
| 285 this->internalDrawText(blob, 0, cache, skPaint, viewMatrix, text, byteLength
, x, y, clipRect); | 283 this->internalDrawText(blob, 0, cache, skPaint, viewMatrix, text, byteLength
, x, y, clipRect); |
| 286 SkGlyphCache::AttachCache(cache); | 284 SkGlyphCache::AttachCache(cache); |
| 287 | 285 |
| 288 this->flush(fContext->getTextTarget(), blob, rt, paint, clip, viewMatrix, sk
Paint.getAlpha()); | 286 this->flush(fContext->getTextTarget(), blob, rt, skPaint, paint, clip, viewM
atrix); |
| 289 } | 287 } |
| 290 | 288 |
| 291 void GrAtlasTextContext::internalDrawText(BitmapTextBlob* blob, int runIndex, | 289 void GrAtlasTextContext::internalDrawText(BitmapTextBlob* blob, int runIndex, |
| 292 SkGlyphCache* cache, const SkPaint& sk
Paint, | 290 SkGlyphCache* cache, const SkPaint& sk
Paint, |
| 293 const SkMatrix& viewMatrix, | 291 const SkMatrix& viewMatrix, |
| 294 const char text[], size_t byteLength, | 292 const char text[], size_t byteLength, |
| 295 SkScalar x, SkScalar y, const SkIRect&
clipRect) { | 293 SkScalar x, SkScalar y, const SkIRect&
clipRect) { |
| 296 SkASSERT(byteLength == 0 || text != NULL); | 294 SkASSERT(byteLength == 0 || text != NULL); |
| 297 | 295 |
| 298 // nothing to draw | 296 // nothing to draw |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 391 | 389 |
| 392 SkIRect clipRect; | 390 SkIRect clipRect; |
| 393 clip.getConservativeBounds(rt->width(), rt->height(), &clipRect); | 391 clip.getConservativeBounds(rt->width(), rt->height(), &clipRect); |
| 394 | 392 |
| 395 // setup cache | 393 // setup cache |
| 396 SkGlyphCache* cache = this->setupCache(&blob->fRuns[0], skPaint, viewMatrix)
; | 394 SkGlyphCache* cache = this->setupCache(&blob->fRuns[0], skPaint, viewMatrix)
; |
| 397 this->internalDrawPosText(blob, 0, cache, skPaint, viewMatrix, text, byteLen
gth, pos, | 395 this->internalDrawPosText(blob, 0, cache, skPaint, viewMatrix, text, byteLen
gth, pos, |
| 398 scalarsPerPosition, offset, clipRect); | 396 scalarsPerPosition, offset, clipRect); |
| 399 SkGlyphCache::AttachCache(cache); | 397 SkGlyphCache::AttachCache(cache); |
| 400 | 398 |
| 401 this->flush(fContext->getTextTarget(), blob, rt, paint, clip, viewMatrix, fS
kPaint.getAlpha()); | 399 this->flush(fContext->getTextTarget(), blob, rt, skPaint, paint, clip, viewM
atrix); |
| 402 } | 400 } |
| 403 | 401 |
| 404 void GrAtlasTextContext::internalDrawPosText(BitmapTextBlob* blob, int runIndex, | 402 void GrAtlasTextContext::internalDrawPosText(BitmapTextBlob* blob, int runIndex, |
| 405 SkGlyphCache* cache, const SkPaint&
skPaint, | 403 SkGlyphCache* cache, const SkPaint&
skPaint, |
| 406 const SkMatrix& viewMatrix, | 404 const SkMatrix& viewMatrix, |
| 407 const char text[], size_t byteLengt
h, | 405 const char text[], size_t byteLengt
h, |
| 408 const SkScalar pos[], int scalarsPe
rPosition, | 406 const SkScalar pos[], int scalarsPe
rPosition, |
| 409 const SkPoint& offset, const SkIRec
t& clipRect) { | 407 const SkPoint& offset, const SkIRec
t& clipRect) { |
| 410 SkASSERT(byteLength == 0 || text != NULL); | 408 SkASSERT(byteLength == 0 || text != NULL); |
| 411 SkASSERT(1 == scalarsPerPosition || 2 == scalarsPerPosition); | 409 SkASSERT(1 == scalarsPerPosition || 2 == scalarsPerPosition); |
| (...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 687 : fBlob(SkRef(geometry.fBlob.get())) | 685 : fBlob(SkRef(geometry.fBlob.get())) |
| 688 , fRun(geometry.fRun) | 686 , fRun(geometry.fRun) |
| 689 , fSubRun(geometry.fSubRun) | 687 , fSubRun(geometry.fSubRun) |
| 690 , fColor(geometry.fColor) {} | 688 , fColor(geometry.fColor) {} |
| 691 SkAutoTUnref<Blob> fBlob; | 689 SkAutoTUnref<Blob> fBlob; |
| 692 int fRun; | 690 int fRun; |
| 693 int fSubRun; | 691 int fSubRun; |
| 694 GrColor fColor; | 692 GrColor fColor; |
| 695 }; | 693 }; |
| 696 | 694 |
| 697 static GrBatch* Create(const Geometry& geometry, GrColor color, GrMaskFormat
maskFormat, | 695 static GrBatch* Create(const Geometry& geometry, GrMaskFormat maskFormat, |
| 698 int glyphCount, GrBatchFontCache* fontCache) { | 696 int glyphCount, GrBatchFontCache* fontCache) { |
| 699 return SkNEW_ARGS(BitmapTextBatch, (geometry, color, maskFormat, glyphCo
unt, fontCache)); | 697 return SkNEW_ARGS(BitmapTextBatch, (geometry, maskFormat, glyphCount, fo
ntCache)); |
| 700 } | 698 } |
| 701 | 699 |
| 702 const char* name() const override { return "BitmapTextBatch"; } | 700 const char* name() const override { return "BitmapTextBatch"; } |
| 703 | 701 |
| 704 void getInvariantOutputColor(GrInitInvariantOutput* out) const override { | 702 void getInvariantOutputColor(GrInitInvariantOutput* out) const override { |
| 705 if (kARGB_GrMaskFormat == fMaskFormat) { | 703 if (kARGB_GrMaskFormat == fMaskFormat) { |
| 706 out->setUnknownFourComponents(); | 704 out->setUnknownFourComponents(); |
| 707 } else { | 705 } else { |
| 708 out->setKnownFourComponents(fBatch.fColor); | 706 out->setKnownFourComponents(fBatch.fColor); |
| 709 } | 707 } |
| (...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 886 | 884 |
| 887 currVertex += byteCount; | 885 currVertex += byteCount; |
| 888 } | 886 } |
| 889 | 887 |
| 890 this->flush(batchTarget, &drawInfo, instancesToFlush, maxInstancesPerDra
w); | 888 this->flush(batchTarget, &drawInfo, instancesToFlush, maxInstancesPerDra
w); |
| 891 } | 889 } |
| 892 | 890 |
| 893 SkSTArray<1, Geometry, true>* geoData() { return &fGeoData; } | 891 SkSTArray<1, Geometry, true>* geoData() { return &fGeoData; } |
| 894 | 892 |
| 895 private: | 893 private: |
| 896 BitmapTextBatch(const Geometry& geometry, GrColor color, GrMaskFormat maskFo
rmat, | 894 BitmapTextBatch(const Geometry& geometry, GrMaskFormat maskFormat, |
| 897 int glyphCount, GrBatchFontCache* fontCache) | 895 int glyphCount, GrBatchFontCache* fontCache) |
| 898 : fMaskFormat(maskFormat) | 896 : fMaskFormat(maskFormat) |
| 899 , fPixelConfig(fontCache->getPixelConfig(maskFormat)) | 897 , fPixelConfig(fontCache->getPixelConfig(maskFormat)) |
| 900 , fFontCache(fontCache) { | 898 , fFontCache(fontCache) { |
| 901 this->initClassID<BitmapTextBatch>(); | 899 this->initClassID<BitmapTextBatch>(); |
| 902 fGeoData.push_back(geometry); | 900 fGeoData.push_back(geometry); |
| 903 fBatch.fColor = color; | 901 fBatch.fColor = geometry.fColor; |
| 904 fBatch.fViewMatrix = geometry.fBlob->fViewMatrix; | 902 fBatch.fViewMatrix = geometry.fBlob->fViewMatrix; |
| 905 fBatch.fNumGlyphs = glyphCount; | 903 fBatch.fNumGlyphs = glyphCount; |
| 906 } | 904 } |
| 907 | 905 |
| 908 void regenerateTextureCoords(GrGlyph* glyph, intptr_t vertex, size_t vertexS
tride) { | 906 void regenerateTextureCoords(GrGlyph* glyph, intptr_t vertex, size_t vertexS
tride) { |
| 909 int width = glyph->fBounds.width(); | 907 int width = glyph->fBounds.width(); |
| 910 int height = glyph->fBounds.height(); | 908 int height = glyph->fBounds.height(); |
| 911 int u0 = glyph->fAtlasLocation.fX; | 909 int u0 = glyph->fAtlasLocation.fX; |
| 912 int v0 = glyph->fAtlasLocation.fY; | 910 int v0 = glyph->fAtlasLocation.fY; |
| 913 int u1 = u0 + width; | 911 int u1 = u0 + width; |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1008 int fNumGlyphs; | 1006 int fNumGlyphs; |
| 1009 }; | 1007 }; |
| 1010 | 1008 |
| 1011 BatchTracker fBatch; | 1009 BatchTracker fBatch; |
| 1012 SkSTArray<1, Geometry, true> fGeoData; | 1010 SkSTArray<1, Geometry, true> fGeoData; |
| 1013 GrMaskFormat fMaskFormat; | 1011 GrMaskFormat fMaskFormat; |
| 1014 GrPixelConfig fPixelConfig; | 1012 GrPixelConfig fPixelConfig; |
| 1015 GrBatchFontCache* fFontCache; | 1013 GrBatchFontCache* fFontCache; |
| 1016 }; | 1014 }; |
| 1017 | 1015 |
| 1018 void GrAtlasTextContext::flush(GrDrawTarget* target, BitmapTextBlob* blob, GrRen
derTarget* rt, | 1016 void GrAtlasTextContext::flushRunAsPaths(const SkTextBlob::RunIterator& it, cons
t SkPaint& skPaint, |
| 1019 const GrPaint& paint, const GrClip& clip, | 1017 SkDrawFilter* drawFilter, const SkMatri
x& viewMatrix, |
| 1020 const SkMatrix& viewMatrix, int paintAlpha) { | 1018 const SkIRect& clipBounds, SkScalar x,
SkScalar y) { |
| 1021 GrPipelineBuilder pipelineBuilder; | 1019 SkPaint runPaint = skPaint; |
| 1022 pipelineBuilder.setFromPaint(paint, rt, clip); | |
| 1023 | 1020 |
| 1024 GrColor color = paint.getColor(); | 1021 size_t textLen = it.glyphCount() * sizeof(uint16_t); |
| 1025 for (uint32_t run = 0; run < blob->fRunCount; run++) { | 1022 const SkPoint& offset = it.offset(); |
| 1026 for (int subRun = 0; subRun < blob->fRuns[run].fSubRunInfo.count(); subR
un++) { | |
| 1027 PerSubRunInfo& info = blob->fRuns[run].fSubRunInfo[subRun]; | |
| 1028 int glyphCount = info.fGlyphEndIndex - info.fGlyphStartIndex; | |
| 1029 if (0 == glyphCount) { | |
| 1030 continue; | |
| 1031 } | |
| 1032 | 1023 |
| 1033 GrMaskFormat format = info.fMaskFormat; | 1024 it.applyFontToPaint(&runPaint); |
| 1034 GrColor subRunColor = kARGB_GrMaskFormat == format ? | |
| 1035 SkColorSetARGB(paintAlpha, paintAlpha, paintAl
pha, paintAlpha) : | |
| 1036 color; | |
| 1037 | 1025 |
| 1038 BitmapTextBatch::Geometry geometry; | 1026 if (drawFilter && !drawFilter->filter(&runPaint, SkDrawFilter::kText_Type))
{ |
| 1039 geometry.fBlob.reset(SkRef(blob)); | 1027 return; |
| 1040 geometry.fRun = run; | |
| 1041 geometry.fSubRun = subRun; | |
| 1042 geometry.fColor = color; | |
| 1043 SkAutoTUnref<GrBatch> batch(BitmapTextBatch::Create(geometry, subRun
Color, format, | |
| 1044 glyphCount, | |
| 1045 fContext->getBat
chFontCache())); | |
| 1046 | |
| 1047 target->drawBatch(&pipelineBuilder, batch, &blob->fRuns[run].fVertex
Bounds); | |
| 1048 } | |
| 1049 } | 1028 } |
| 1050 | 1029 |
| 1051 // Now flush big glyphs | 1030 runPaint.setFlags(fGpuDevice->filterTextFlags(runPaint)); |
| 1052 for (int i = 0; i < blob->fBigGlyphs.count(); i++) { | 1031 |
| 1053 BitmapTextBlob::BigGlyph& bigGlyph = blob->fBigGlyphs[i]; | 1032 switch (it.positioning()) { |
| 1033 case SkTextBlob::kDefault_Positioning: |
| 1034 this->drawTextAsPath(runPaint, viewMatrix, (const char *)it.glyphs()
, |
| 1035 textLen, x + offset.x(), y + offset.y(), clipBo
unds); |
| 1036 break; |
| 1037 case SkTextBlob::kHorizontal_Positioning: |
| 1038 this->drawPosTextAsPath(runPaint, viewMatrix, (const char*)it.glyphs
(), |
| 1039 textLen, it.pos(), 1, SkPoint::Make(x, y + o
ffset.y()), |
| 1040 clipBounds); |
| 1041 break; |
| 1042 case SkTextBlob::kFull_Positioning: |
| 1043 this->drawPosTextAsPath(runPaint, viewMatrix, (const char*)it.glyphs
(), |
| 1044 textLen, it.pos(), 2, SkPoint::Make(x, y), c
lipBounds); |
| 1045 break; |
| 1046 } |
| 1047 } |
| 1048 |
| 1049 inline void GrAtlasTextContext::flushRun(GrDrawTarget* target, GrPipelineBuilder
* pipelineBuilder, |
| 1050 BitmapTextBlob* cacheBlob, int run, GrC
olor color, |
| 1051 uint8_t paintAlpha) { |
| 1052 for (int subRun = 0; subRun < cacheBlob->fRuns[run].fSubRunInfo.count(); sub
Run++) { |
| 1053 const PerSubRunInfo& info = cacheBlob->fRuns[run].fSubRunInfo[subRun]; |
| 1054 int glyphCount = info.fGlyphEndIndex - info.fGlyphStartIndex; |
| 1055 if (0 == glyphCount) { |
| 1056 continue; |
| 1057 } |
| 1058 |
| 1059 GrMaskFormat format = info.fMaskFormat; |
| 1060 GrColor subRunColor = kARGB_GrMaskFormat == format ? |
| 1061 SkColorSetARGB(paintAlpha, paintAlpha, paintAlpha,
paintAlpha) : |
| 1062 color; |
| 1063 |
| 1064 BitmapTextBatch::Geometry geometry; |
| 1065 geometry.fBlob.reset(SkRef(cacheBlob)); |
| 1066 geometry.fRun = run; |
| 1067 geometry.fSubRun = subRun; |
| 1068 geometry.fColor = subRunColor; |
| 1069 SkAutoTUnref<GrBatch> batch(BitmapTextBatch::Create(geometry, format, gl
yphCount, |
| 1070 fContext->getBatchFo
ntCache())); |
| 1071 |
| 1072 target->drawBatch(pipelineBuilder, batch, &cacheBlob->fRuns[run].fVertex
Bounds); |
| 1073 } |
| 1074 } |
| 1075 |
| 1076 inline void GrAtlasTextContext::flushBigGlyphs(BitmapTextBlob* cacheBlob, GrRend
erTarget* rt, |
| 1077 const GrPaint& grPaint, const GrC
lip& clip) { |
| 1078 for (int i = 0; i < cacheBlob->fBigGlyphs.count(); i++) { |
| 1079 const BitmapTextBlob::BigGlyph& bigGlyph = cacheBlob->fBigGlyphs[i]; |
| 1054 SkMatrix translate; | 1080 SkMatrix translate; |
| 1055 translate.setTranslate(SkIntToScalar(bigGlyph.fVx), SkIntToScalar(bigGly
ph.fVy)); | 1081 translate.setTranslate(SkIntToScalar(bigGlyph.fVx), SkIntToScalar(bigGly
ph.fVy)); |
| 1056 SkPath tmpPath(bigGlyph.fPath); | 1082 SkPath tmpPath(bigGlyph.fPath); |
| 1057 tmpPath.transform(translate); | 1083 tmpPath.transform(translate); |
| 1058 GrStrokeInfo strokeInfo(SkStrokeRec::kFill_InitStyle); | 1084 GrStrokeInfo strokeInfo(SkStrokeRec::kFill_InitStyle); |
| 1059 fContext->drawPath(rt, clip, paint, SkMatrix::I(), tmpPath, strokeInfo); | 1085 fContext->drawPath(rt, clip, grPaint, SkMatrix::I(), tmpPath, strokeInfo
); |
| 1060 } | 1086 } |
| 1061 } | 1087 } |
| 1088 |
| 1089 void GrAtlasTextContext::flush(GrDrawTarget* target, |
| 1090 const SkTextBlob* blob, |
| 1091 BitmapTextBlob* cacheBlob, |
| 1092 GrRenderTarget* rt, |
| 1093 const SkPaint& skPaint, |
| 1094 const GrPaint& grPaint, |
| 1095 SkDrawFilter* drawFilter, |
| 1096 const GrClip& clip, |
| 1097 const SkMatrix& viewMatrix, |
| 1098 const SkIRect& clipBounds, |
| 1099 SkScalar x, |
| 1100 SkScalar y) { |
| 1101 // We loop through the runs of the blob, flushing each. If any run is too l
arge, then we flush |
| 1102 // it as paths |
| 1103 GrPipelineBuilder pipelineBuilder; |
| 1104 pipelineBuilder.setFromPaint(grPaint, rt, clip); |
| 1105 |
| 1106 GrColor color = grPaint.getColor(); |
| 1107 uint8_t paintAlpha = skPaint.getAlpha(); |
| 1108 |
| 1109 SkTextBlob::RunIterator it(blob); |
| 1110 for (int run = 0; !it.done(); it.next(), run++) { |
| 1111 if (cacheBlob->fRuns[run].fDrawAsPaths) { |
| 1112 this->flushRunAsPaths(it, skPaint, drawFilter, viewMatrix, clipBound
s, x, y); |
| 1113 continue; |
| 1114 } |
| 1115 this->flushRun(target, &pipelineBuilder, cacheBlob, run, color, paintAlp
ha); |
| 1116 } |
| 1117 |
| 1118 // Now flush big glyphs |
| 1119 this->flushBigGlyphs(cacheBlob, rt, grPaint, clip); |
| 1120 } |
| 1121 |
| 1122 void GrAtlasTextContext::flush(GrDrawTarget* target, |
| 1123 BitmapTextBlob* cacheBlob, |
| 1124 GrRenderTarget* rt, |
| 1125 const SkPaint& skPaint, |
| 1126 const GrPaint& grPaint, |
| 1127 const GrClip& clip, |
| 1128 const SkMatrix& viewMatrix) { |
| 1129 GrPipelineBuilder pipelineBuilder; |
| 1130 pipelineBuilder.setFromPaint(grPaint, rt, clip); |
| 1131 |
| 1132 GrColor color = grPaint.getColor(); |
| 1133 uint8_t paintAlpha = skPaint.getAlpha(); |
| 1134 for (int run = 0; run < cacheBlob->fRunCount; run++) { |
| 1135 this->flushRun(target, &pipelineBuilder, cacheBlob, run, color, paintAlp
ha); |
| 1136 } |
| 1137 |
| 1138 // Now flush big glyphs |
| 1139 this->flushBigGlyphs(cacheBlob, rt, grPaint, clip); |
| 1140 } |
| OLD | NEW |