| 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); | |
| 86 run.setText(text, byteLength, x, y); | 85 run.setText(text, byteLength, x, y); |
| 87 run.draw(context, dc, &pipelineBuilder, clip, paint.getColor(), view
Matrix, props, 0, 0, | 86 run.draw(context, dc, paint, clip, paint.getColor(), viewMatrix, pro
ps, 0, 0, |
| 88 clipBounds, fFallbackTextContext, skPaint); | 87 clipBounds, fFallbackTextContext, skPaint); |
| 89 } | 88 } |
| 90 return; | 89 return; |
| 91 } else if (fFallbackTextContext->canDraw(skPaint, viewMatrix, props, | 90 } else if (fFallbackTextContext->canDraw(skPaint, viewMatrix, props, |
| 92 *context->caps()->shaderCaps())) { | 91 *context->caps()->shaderCaps())) { |
| 93 fFallbackTextContext->drawText(context, dc, clip, paint, skPaint, viewMa
trix, props, text, | 92 fFallbackTextContext->drawText(context, dc, clip, paint, skPaint, viewMa
trix, props, text, |
| 94 byteLength, x, y, clipBounds); | 93 byteLength, x, y, clipBounds); |
| 95 return; | 94 return; |
| 96 } | 95 } |
| 97 | 96 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 110 size_t byteLength, | 109 size_t byteLength, |
| 111 const SkScalar pos[], | 110 const SkScalar pos[], |
| 112 int scalarsPerPosition, | 111 int scalarsPerPosition, |
| 113 const SkPoint& offset, | 112 const SkPoint& offset, |
| 114 const SkIRect& clipBounds) { | 113 const SkIRect& clipBounds) { |
| 115 if (context->abandoned()) { | 114 if (context->abandoned()) { |
| 116 return; | 115 return; |
| 117 } else if (this->canDraw(skPaint, viewMatrix)) { | 116 } else if (this->canDraw(skPaint, viewMatrix)) { |
| 118 if (skPaint.getTextSize() > 0) { | 117 if (skPaint.getTextSize() > 0) { |
| 119 TextRun run(skPaint); | 118 TextRun run(skPaint); |
| 120 GrPipelineBuilder pipelineBuilder(paint); | |
| 121 run.setPosText(text, byteLength, pos, scalarsPerPosition, offset); | 119 run.setPosText(text, byteLength, pos, scalarsPerPosition, offset); |
| 122 run.draw(context, dc, &pipelineBuilder, clip, paint.getColor(), view
Matrix, props, 0, 0, | 120 run.draw(context, dc, paint, clip, paint.getColor(), viewMatrix, pro
ps, 0, 0, |
| 123 clipBounds, fFallbackTextContext, skPaint); | 121 clipBounds, fFallbackTextContext, skPaint); |
| 124 } | 122 } |
| 125 return; | 123 return; |
| 126 } else if (fFallbackTextContext->canDraw(skPaint, viewMatrix, props, | 124 } else if (fFallbackTextContext->canDraw(skPaint, viewMatrix, props, |
| 127 *context->caps()->shaderCaps())) { | 125 *context->caps()->shaderCaps())) { |
| 128 fFallbackTextContext->drawPosText(context, dc, clip, paint, skPaint, vie
wMatrix, props, | 126 fFallbackTextContext->drawPosText(context, dc, clip, paint, skPaint, vie
wMatrix, props, |
| 129 text, byteLength, pos, | 127 text, byteLength, pos, |
| 130 scalarsPerPosition, offset, clipBounds
); | 128 scalarsPerPosition, offset, clipBounds
); |
| 131 return; | 129 return; |
| 132 } | 130 } |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 218 drawFilter, clipBounds); | 216 drawFilter, clipBounds); |
| 219 return; | 217 return; |
| 220 } | 218 } |
| 221 | 219 |
| 222 GrPaint paint; | 220 GrPaint paint; |
| 223 if (!SkPaintToGrPaint(context, skPaint, viewMatrix, dc->isGammaCorrect(), &p
aint)) { | 221 if (!SkPaintToGrPaint(context, skPaint, viewMatrix, dc->isGammaCorrect(), &p
aint)) { |
| 224 return; | 222 return; |
| 225 } | 223 } |
| 226 | 224 |
| 227 const TextBlob& blob = this->findOrCreateTextBlob(skBlob, skPaint); | 225 const TextBlob& blob = this->findOrCreateTextBlob(skBlob, skPaint); |
| 228 GrPipelineBuilder pipelineBuilder(paint); | |
| 229 | 226 |
| 230 TextBlob::Iter iter(blob); | 227 TextBlob::Iter iter(blob); |
| 231 for (TextRun* run = iter.get(); run; run = iter.next()) { | 228 for (TextRun* run = iter.get(); run; run = iter.next()) { |
| 232 run->draw(context, dc, &pipelineBuilder, clip, paint.getColor(), viewMat
rix, props, x, y, | 229 run->draw(context, dc, paint, clip, paint.getColor(), viewMatrix, props,
x, y, |
| 233 clipBounds, fFallbackTextContext, skPaint); | 230 clipBounds, fFallbackTextContext, skPaint); |
| 234 run->releaseGlyphCache(); | 231 run->releaseGlyphCache(); |
| 235 } | 232 } |
| 236 } | 233 } |
| 237 | 234 |
| 238 static inline int style_key_cnt(const GrStyle& style) { | 235 static inline int style_key_cnt(const GrStyle& style) { |
| 239 int cnt = GrStyle::KeySize(style, GrStyle::Apply::kPathEffectAndStrokeRec); | 236 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. | 237 // We should be able to make a key because we filtered out arbitrary path ef
fects. |
| 241 SkASSERT(cnt > 0); | 238 SkASSERT(cnt > 0); |
| 242 return cnt; | 239 return cnt; |
| (...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 589 } | 586 } |
| 590 fallback->appendGlyph(glyph.getGlyphID(), pos); | 587 fallback->appendGlyph(glyph.getGlyphID(), pos); |
| 591 } else { | 588 } else { |
| 592 fInstanceData->append(glyph.getGlyphID(), fTextInverseRatio * pos.x(), | 589 fInstanceData->append(glyph.getGlyphID(), fTextInverseRatio * pos.x(), |
| 593 fTextInverseRatio * pos.y()); | 590 fTextInverseRatio * pos.y()); |
| 594 } | 591 } |
| 595 } | 592 } |
| 596 | 593 |
| 597 void GrStencilAndCoverTextContext::TextRun::draw(GrContext* ctx, | 594 void GrStencilAndCoverTextContext::TextRun::draw(GrContext* ctx, |
| 598 GrDrawContext* drawContext, | 595 GrDrawContext* drawContext, |
| 599 GrPipelineBuilder* pipelineBuil
der, | 596 const GrPaint& grPaint, |
| 600 const GrClip& clip, | 597 const GrClip& clip, |
| 601 GrColor color, | 598 GrColor color, |
| 602 const SkMatrix& viewMatrix, | 599 const SkMatrix& viewMatrix, |
| 603 const SkSurfaceProps& props, | 600 const SkSurfaceProps& props, |
| 604 SkScalar x, SkScalar y, | 601 SkScalar x, SkScalar y, |
| 605 const SkIRect& clipBounds, | 602 const SkIRect& clipBounds, |
| 606 GrAtlasTextContext* fallbackTex
tContext, | 603 GrAtlasTextContext* fallbackTex
tContext, |
| 607 const SkPaint& originalSkPaint)
const { | 604 const SkPaint& originalSkPaint)
const { |
| 608 SkASSERT(fInstanceData); | 605 SkASSERT(fInstanceData); |
| 609 SkASSERT(drawContext->isStencilBufferMultisampled() || !fFont.isAntiAlias())
; | 606 SkASSERT(drawContext->isStencilBufferMultisampled() || !fFont.isAntiAlias())
; |
| 610 | 607 |
| 611 if (fInstanceData->count()) { | 608 if (fInstanceData->count()) { |
| 612 pipelineBuilder->setState(GrPipelineBuilder::kHWAntialias_Flag, fFont.is
AntiAlias()); | |
| 613 | |
| 614 static constexpr GrUserStencilSettings kCoverPass( | 609 static constexpr GrUserStencilSettings kCoverPass( |
| 615 GrUserStencilSettings::StaticInit< | 610 GrUserStencilSettings::StaticInit< |
| 616 0x0000, | 611 0x0000, |
| 617 GrUserStencilTest::kNotEqual, // Stencil pass accounts for clip. | 612 GrUserStencilTest::kNotEqual, // Stencil pass accounts for clip. |
| 618 0xffff, | 613 0xffff, |
| 619 GrUserStencilOp::kZero, | 614 GrUserStencilOp::kZero, |
| 620 GrUserStencilOp::kKeep, | 615 GrUserStencilOp::kKeep, |
| 621 0xffff>() | 616 0xffff>() |
| 622 ); | 617 ); |
| 623 | 618 |
| 624 pipelineBuilder->setUserStencil(&kCoverPass); | |
| 625 | |
| 626 SkAutoTUnref<GrPathRange> glyphs(this->createGlyphs(ctx)); | 619 SkAutoTUnref<GrPathRange> glyphs(this->createGlyphs(ctx)); |
| 627 if (fLastDrawnGlyphsID != glyphs->getUniqueID()) { | 620 if (fLastDrawnGlyphsID != glyphs->getUniqueID()) { |
| 628 // Either this is the first draw or the glyphs object was purged sin
ce last draw. | 621 // Either this is the first draw or the glyphs object was purged sin
ce last draw. |
| 629 glyphs->loadPathsIfNeeded(fInstanceData->indices(), fInstanceData->c
ount()); | 622 glyphs->loadPathsIfNeeded(fInstanceData->indices(), fInstanceData->c
ount()); |
| 630 fLastDrawnGlyphsID = glyphs->getUniqueID(); | 623 fLastDrawnGlyphsID = glyphs->getUniqueID(); |
| 631 } | 624 } |
| 632 | 625 |
| 633 // Don't compute a bounding box. For dst copy texture, we'll opt instead
for it to just copy | 626 // Don't compute a bounding box. For dst copy texture, we'll opt instead
for it to just copy |
| 634 // the entire dst. Realistically this is a moot point, because any conte
xt that supports | 627 // the entire dst. Realistically this is a moot point, because any conte
xt that supports |
| 635 // NV_path_rendering will also support NV_blend_equation_advanced. | 628 // NV_path_rendering will also support NV_blend_equation_advanced. |
| 636 // For clipping we'll just skip any optimizations based on the bounds. T
his does, however, | 629 // For clipping we'll just skip any optimizations based on the bounds. T
his does, however, |
| 637 // hurt batching. | 630 // hurt batching. |
| 638 const SkRect bounds = SkRect::MakeIWH(drawContext->width(), drawContext-
>height()); | 631 const SkRect bounds = SkRect::MakeIWH(drawContext->width(), drawContext-
>height()); |
| 639 | 632 |
| 640 SkAutoTUnref<GrDrawBatch> batch( | 633 SkAutoTUnref<GrDrawBatch> batch( |
| 641 GrDrawPathRangeBatch::Create(viewMatrix, fTextRatio, fTextInverseRat
io * x, | 634 GrDrawPathRangeBatch::Create(viewMatrix, fTextRatio, fTextInverseRat
io * x, |
| 642 fTextInverseRatio * y, color, | 635 fTextInverseRatio * y, color, |
| 643 GrPathRendering::kWinding_FillType, gly
phs, fInstanceData, | 636 GrPathRendering::kWinding_FillType, gly
phs, fInstanceData, |
| 644 bounds)); | 637 bounds)); |
| 645 | 638 |
| 646 drawContext->drawBatch(*pipelineBuilder, clip, batch); | 639 GrPipelineBuilder pipelineBuilder(grPaint); |
| 640 pipelineBuilder.setState(GrPipelineBuilder::kHWAntialias_Flag, fFont.isA
ntiAlias()); |
| 641 pipelineBuilder.setUserStencil(&kCoverPass); |
| 642 |
| 643 drawContext->drawBatch(pipelineBuilder, clip, batch); |
| 647 } | 644 } |
| 648 | 645 |
| 649 if (fFallbackTextBlob) { | 646 if (fFallbackTextBlob) { |
| 650 SkPaint fallbackSkPaint(originalSkPaint); | 647 SkPaint fallbackSkPaint(originalSkPaint); |
| 651 fStyle.strokeRec().applyToPaint(&fallbackSkPaint); | 648 fStyle.strokeRec().applyToPaint(&fallbackSkPaint); |
| 652 if (!fStyle.isSimpleFill()) { | 649 if (!fStyle.isSimpleFill()) { |
| 653 fallbackSkPaint.setStrokeWidth(fStyle.strokeRec().getWidth() * fText
Ratio); | 650 fallbackSkPaint.setStrokeWidth(fStyle.strokeRec().getWidth() * fText
Ratio); |
| 654 } | 651 } |
| 655 | 652 |
| 656 fallbackTextContext->drawTextBlob(ctx, drawContext, clip, fallbackSkPain
t, viewMatrix, | 653 fallbackTextContext->drawTextBlob(ctx, drawContext, clip, fallbackSkPain
t, viewMatrix, |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 729 } | 726 } |
| 730 | 727 |
| 731 const SkTextBlob* GrStencilAndCoverTextContext::FallbackBlobBuilder::buildIfNeed
ed(int *count) { | 728 const SkTextBlob* GrStencilAndCoverTextContext::FallbackBlobBuilder::buildIfNeed
ed(int *count) { |
| 732 *count = fCount; | 729 *count = fCount; |
| 733 if (fCount) { | 730 if (fCount) { |
| 734 this->flush(); | 731 this->flush(); |
| 735 return fBuilder->build(); | 732 return fBuilder->build(); |
| 736 } | 733 } |
| 737 return nullptr; | 734 return nullptr; |
| 738 } | 735 } |
| OLD | NEW |