| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2014 Google Inc. | 2 * Copyright 2014 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 | 7 |
| 8 #include "GrStencilAndCoverTextContext.h" | 8 #include "GrStencilAndCoverTextContext.h" |
| 9 #include "GrAtlasTextContext.h" | 9 #include "GrAtlasTextContext.h" |
| 10 #include "GrContext.h" | 10 #include "GrContext.h" |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 75 const GrClip& clip, const GrPaint& p
aint, | 75 const GrClip& clip, const GrPaint& p
aint, |
| 76 const SkPaint& skPaint, const SkMatr
ix& viewMatrix, | 76 const SkPaint& skPaint, const SkMatr
ix& viewMatrix, |
| 77 const SkSurfaceProps& props, | 77 const SkSurfaceProps& props, |
| 78 const char text[], size_t byteLength
, | 78 const char text[], size_t byteLength
, |
| 79 SkScalar x, SkScalar y, const SkIRec
t& clipBounds) { | 79 SkScalar x, SkScalar y, const SkIRec
t& clipBounds) { |
| 80 if (context->abandoned()) { | 80 if (context->abandoned()) { |
| 81 return; | 81 return; |
| 82 } else if (this->canDraw(skPaint, viewMatrix)) { | 82 } else if (this->canDraw(skPaint, viewMatrix)) { |
| 83 if (skPaint.getTextSize() > 0) { | 83 if (skPaint.getTextSize() > 0) { |
| 84 TextRun run(skPaint); | 84 TextRun run(skPaint); |
| 85 GrPipelineBuilder pipelineBuilder(paint, dc->accessRenderTarget(), c
lip); | 85 GrPipelineBuilder pipelineBuilder(paint, dc->accessRenderTarget()); |
| 86 run.setText(text, byteLength, x, y); | 86 run.setText(text, byteLength, x, y); |
| 87 run.draw(context, dc, &pipelineBuilder, paint.getColor(), viewMatrix
, props, 0, 0, | 87 run.draw(context, dc, &pipelineBuilder, clip, paint.getColor(), view
Matrix, props, 0, 0, |
| 88 clipBounds, fFallbackTextContext, skPaint); | 88 clipBounds, fFallbackTextContext, skPaint); |
| 89 } | 89 } |
| 90 return; | 90 return; |
| 91 } else if (fFallbackTextContext->canDraw(skPaint, viewMatrix, props, | 91 } else if (fFallbackTextContext->canDraw(skPaint, viewMatrix, props, |
| 92 *context->caps()->shaderCaps())) { | 92 *context->caps()->shaderCaps())) { |
| 93 fFallbackTextContext->drawText(context, dc, clip, paint, skPaint, viewMa
trix, props, text, | 93 fFallbackTextContext->drawText(context, dc, clip, paint, skPaint, viewMa
trix, props, text, |
| 94 byteLength, x, y, clipBounds); | 94 byteLength, x, y, clipBounds); |
| 95 return; | 95 return; |
| 96 } | 96 } |
| 97 | 97 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 110 size_t byteLength, | 110 size_t byteLength, |
| 111 const SkScalar pos[], | 111 const SkScalar pos[], |
| 112 int scalarsPerPosition, | 112 int scalarsPerPosition, |
| 113 const SkPoint& offset, | 113 const SkPoint& offset, |
| 114 const SkIRect& clipBounds) { | 114 const SkIRect& clipBounds) { |
| 115 if (context->abandoned()) { | 115 if (context->abandoned()) { |
| 116 return; | 116 return; |
| 117 } else if (this->canDraw(skPaint, viewMatrix)) { | 117 } else if (this->canDraw(skPaint, viewMatrix)) { |
| 118 if (skPaint.getTextSize() > 0) { | 118 if (skPaint.getTextSize() > 0) { |
| 119 TextRun run(skPaint); | 119 TextRun run(skPaint); |
| 120 GrPipelineBuilder pipelineBuilder(paint, dc->accessRenderTarget(), c
lip); | 120 GrPipelineBuilder pipelineBuilder(paint, dc->accessRenderTarget()); |
| 121 run.setPosText(text, byteLength, pos, scalarsPerPosition, offset); | 121 run.setPosText(text, byteLength, pos, scalarsPerPosition, offset); |
| 122 run.draw(context, dc, &pipelineBuilder, paint.getColor(), viewMatrix
, props, 0, 0, | 122 run.draw(context, dc, &pipelineBuilder, clip, paint.getColor(), view
Matrix, props, 0, 0, |
| 123 clipBounds, fFallbackTextContext, skPaint); | 123 clipBounds, fFallbackTextContext, skPaint); |
| 124 } | 124 } |
| 125 return; | 125 return; |
| 126 } else if (fFallbackTextContext->canDraw(skPaint, viewMatrix, props, | 126 } else if (fFallbackTextContext->canDraw(skPaint, viewMatrix, props, |
| 127 *context->caps()->shaderCaps())) { | 127 *context->caps()->shaderCaps())) { |
| 128 fFallbackTextContext->drawPosText(context, dc, clip, paint, skPaint, vie
wMatrix, props, | 128 fFallbackTextContext->drawPosText(context, dc, clip, paint, skPaint, vie
wMatrix, props, |
| 129 text, byteLength, pos, | 129 text, byteLength, pos, |
| 130 scalarsPerPosition, offset, clipBounds
); | 130 scalarsPerPosition, offset, clipBounds
); |
| 131 return; | 131 return; |
| 132 } | 132 } |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 218 drawFilter, clipBounds); | 218 drawFilter, clipBounds); |
| 219 return; | 219 return; |
| 220 } | 220 } |
| 221 | 221 |
| 222 GrPaint paint; | 222 GrPaint paint; |
| 223 if (!SkPaintToGrPaint(context, skPaint, viewMatrix, dc->isGammaCorrect(), &p
aint)) { | 223 if (!SkPaintToGrPaint(context, skPaint, viewMatrix, dc->isGammaCorrect(), &p
aint)) { |
| 224 return; | 224 return; |
| 225 } | 225 } |
| 226 | 226 |
| 227 const TextBlob& blob = this->findOrCreateTextBlob(skBlob, skPaint); | 227 const TextBlob& blob = this->findOrCreateTextBlob(skBlob, skPaint); |
| 228 GrPipelineBuilder pipelineBuilder(paint, dc->accessRenderTarget(), clip); | 228 GrPipelineBuilder pipelineBuilder(paint, dc->accessRenderTarget()); |
| 229 | 229 |
| 230 TextBlob::Iter iter(blob); | 230 TextBlob::Iter iter(blob); |
| 231 for (TextRun* run = iter.get(); run; run = iter.next()) { | 231 for (TextRun* run = iter.get(); run; run = iter.next()) { |
| 232 run->draw(context, dc, &pipelineBuilder, paint.getColor(), viewMatrix, p
rops, x, y, | 232 run->draw(context, dc, &pipelineBuilder, clip, paint.getColor(), viewMat
rix, props, x, y, |
| 233 clipBounds, fFallbackTextContext, skPaint); | 233 clipBounds, fFallbackTextContext, skPaint); |
| 234 run->releaseGlyphCache(); | 234 run->releaseGlyphCache(); |
| 235 } | 235 } |
| 236 } | 236 } |
| 237 | 237 |
| 238 static inline int style_key_cnt(const GrStyle& style) { | 238 static inline int style_key_cnt(const GrStyle& style) { |
| 239 int cnt = GrStyle::KeySize(style, GrStyle::Apply::kPathEffectAndStrokeRec); | 239 int cnt = GrStyle::KeySize(style, GrStyle::Apply::kPathEffectAndStrokeRec); |
| 240 // We should be able to make a key because we filtered out arbitrary path ef
fects. | 240 // We should be able to make a key because we filtered out arbitrary path ef
fects. |
| 241 SkASSERT(cnt > 0); | 241 SkASSERT(cnt > 0); |
| 242 return cnt; | 242 return cnt; |
| (...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 590 fallback->appendGlyph(glyph.getGlyphID(), pos); | 590 fallback->appendGlyph(glyph.getGlyphID(), pos); |
| 591 } else { | 591 } else { |
| 592 fInstanceData->append(glyph.getGlyphID(), fTextInverseRatio * pos.x(), | 592 fInstanceData->append(glyph.getGlyphID(), fTextInverseRatio * pos.x(), |
| 593 fTextInverseRatio * pos.y()); | 593 fTextInverseRatio * pos.y()); |
| 594 } | 594 } |
| 595 } | 595 } |
| 596 | 596 |
| 597 void GrStencilAndCoverTextContext::TextRun::draw(GrContext* ctx, | 597 void GrStencilAndCoverTextContext::TextRun::draw(GrContext* ctx, |
| 598 GrDrawContext* dc, | 598 GrDrawContext* dc, |
| 599 GrPipelineBuilder* pipelineBuil
der, | 599 GrPipelineBuilder* pipelineBuil
der, |
| 600 const GrClip& clip, |
| 600 GrColor color, | 601 GrColor color, |
| 601 const SkMatrix& viewMatrix, | 602 const SkMatrix& viewMatrix, |
| 602 const SkSurfaceProps& props, | 603 const SkSurfaceProps& props, |
| 603 SkScalar x, SkScalar y, | 604 SkScalar x, SkScalar y, |
| 604 const SkIRect& clipBounds, | 605 const SkIRect& clipBounds, |
| 605 GrAtlasTextContext* fallbackTex
tContext, | 606 GrAtlasTextContext* fallbackTex
tContext, |
| 606 const SkPaint& originalSkPaint)
const { | 607 const SkPaint& originalSkPaint)
const { |
| 607 SkASSERT(fInstanceData); | 608 SkASSERT(fInstanceData); |
| 608 SkASSERT(dc->accessRenderTarget()->isStencilBufferMultisampled() || !fFont.i
sAntiAlias()); | 609 SkASSERT(dc->accessRenderTarget()->isStencilBufferMultisampled() || !fFont.i
sAntiAlias()); |
| 609 | 610 |
| (...skipping 26 matching lines...) Expand all Loading... |
| 636 // hurt batching. | 637 // hurt batching. |
| 637 SkRect bounds = SkRect::MakeIWH(pipelineBuilder->getRenderTarget()->widt
h(), | 638 SkRect bounds = SkRect::MakeIWH(pipelineBuilder->getRenderTarget()->widt
h(), |
| 638 pipelineBuilder->getRenderTarget()->heig
ht()); | 639 pipelineBuilder->getRenderTarget()->heig
ht()); |
| 639 | 640 |
| 640 SkAutoTUnref<GrDrawBatch> batch( | 641 SkAutoTUnref<GrDrawBatch> batch( |
| 641 GrDrawPathRangeBatch::Create(viewMatrix, fTextRatio, fTextInverseRat
io * x, | 642 GrDrawPathRangeBatch::Create(viewMatrix, fTextRatio, fTextInverseRat
io * x, |
| 642 fTextInverseRatio * y, color, | 643 fTextInverseRatio * y, color, |
| 643 GrPathRendering::kWinding_FillType, gly
phs, fInstanceData, | 644 GrPathRendering::kWinding_FillType, gly
phs, fInstanceData, |
| 644 bounds)); | 645 bounds)); |
| 645 | 646 |
| 646 dc->drawBatch(pipelineBuilder, batch); | 647 dc->drawBatch(pipelineBuilder, clip, batch); |
| 647 } | 648 } |
| 648 | 649 |
| 649 if (fFallbackTextBlob) { | 650 if (fFallbackTextBlob) { |
| 650 SkPaint fallbackSkPaint(originalSkPaint); | 651 SkPaint fallbackSkPaint(originalSkPaint); |
| 651 fStyle.strokeRec().applyToPaint(&fallbackSkPaint); | 652 fStyle.strokeRec().applyToPaint(&fallbackSkPaint); |
| 652 if (!fStyle.isSimpleFill()) { | 653 if (!fStyle.isSimpleFill()) { |
| 653 fallbackSkPaint.setStrokeWidth(fStyle.strokeRec().getWidth() * fText
Ratio); | 654 fallbackSkPaint.setStrokeWidth(fStyle.strokeRec().getWidth() * fText
Ratio); |
| 654 } | 655 } |
| 655 | 656 |
| 656 fallbackTextContext->drawTextBlob(ctx, dc, pipelineBuilder->clip(), fall
backSkPaint, | 657 fallbackTextContext->drawTextBlob(ctx, dc, clip, fallbackSkPaint, viewMa
trix, props, |
| 657 viewMatrix, props, fFallbackTextBlob,
x, y, nullptr, | 658 fFallbackTextBlob, x, y, nullptr, clip
Bounds); |
| 658 clipBounds); | |
| 659 } | 659 } |
| 660 } | 660 } |
| 661 | 661 |
| 662 SkGlyphCache* GrStencilAndCoverTextContext::TextRun::getGlyphCache() const { | 662 SkGlyphCache* GrStencilAndCoverTextContext::TextRun::getGlyphCache() const { |
| 663 if (!fDetachedGlyphCache) { | 663 if (!fDetachedGlyphCache) { |
| 664 fDetachedGlyphCache = fFont.detachCache(nullptr, SkPaint::kNone_ScalerCo
ntextFlags, | 664 fDetachedGlyphCache = fFont.detachCache(nullptr, SkPaint::kNone_ScalerCo
ntextFlags, |
| 665 nullptr); | 665 nullptr); |
| 666 } | 666 } |
| 667 return fDetachedGlyphCache; | 667 return fDetachedGlyphCache; |
| 668 } | 668 } |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 730 } | 730 } |
| 731 | 731 |
| 732 const SkTextBlob* GrStencilAndCoverTextContext::FallbackBlobBuilder::buildIfNeed
ed(int *count) { | 732 const SkTextBlob* GrStencilAndCoverTextContext::FallbackBlobBuilder::buildIfNeed
ed(int *count) { |
| 733 *count = fCount; | 733 *count = fCount; |
| 734 if (fCount) { | 734 if (fCount) { |
| 735 this->flush(); | 735 this->flush(); |
| 736 return fBuilder->build(); | 736 return fBuilder->build(); |
| 737 } | 737 } |
| 738 return nullptr; | 738 return nullptr; |
| 739 } | 739 } |
| OLD | NEW |