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 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 run.setText(text, byteLength, x, y); | 85 run.setText(text, byteLength, x, y); |
86 run.draw(context, dc, paint, clip, paint.getColor(), viewMatrix, pro
ps, 0, 0, | 86 run.draw(context, dc, paint, clip, viewMatrix, props, 0, 0, |
87 clipBounds, fFallbackTextContext, skPaint); | 87 clipBounds, fFallbackTextContext, skPaint); |
88 } | 88 } |
89 return; | 89 return; |
90 } else if (fFallbackTextContext->canDraw(skPaint, viewMatrix, props, | 90 } else if (fFallbackTextContext->canDraw(skPaint, viewMatrix, props, |
91 *context->caps()->shaderCaps())) { | 91 *context->caps()->shaderCaps())) { |
92 fFallbackTextContext->drawText(context, dc, clip, paint, skPaint, viewMa
trix, props, text, | 92 fFallbackTextContext->drawText(context, dc, clip, paint, skPaint, viewMa
trix, props, text, |
93 byteLength, x, y, clipBounds); | 93 byteLength, x, y, clipBounds); |
94 return; | 94 return; |
95 } | 95 } |
96 | 96 |
(...skipping 13 matching lines...) Expand all Loading... |
110 const SkScalar pos[], | 110 const SkScalar pos[], |
111 int scalarsPerPosition, | 111 int scalarsPerPosition, |
112 const SkPoint& offset, | 112 const SkPoint& offset, |
113 const SkIRect& clipBounds) { | 113 const SkIRect& clipBounds) { |
114 if (context->abandoned()) { | 114 if (context->abandoned()) { |
115 return; | 115 return; |
116 } else if (this->canDraw(skPaint, viewMatrix)) { | 116 } else if (this->canDraw(skPaint, viewMatrix)) { |
117 if (skPaint.getTextSize() > 0) { | 117 if (skPaint.getTextSize() > 0) { |
118 TextRun run(skPaint); | 118 TextRun run(skPaint); |
119 run.setPosText(text, byteLength, pos, scalarsPerPosition, offset); | 119 run.setPosText(text, byteLength, pos, scalarsPerPosition, offset); |
120 run.draw(context, dc, paint, clip, paint.getColor(), viewMatrix, pro
ps, 0, 0, | 120 run.draw(context, dc, paint, clip, viewMatrix, props, 0, 0, |
121 clipBounds, fFallbackTextContext, skPaint); | 121 clipBounds, fFallbackTextContext, skPaint); |
122 } | 122 } |
123 return; | 123 return; |
124 } else if (fFallbackTextContext->canDraw(skPaint, viewMatrix, props, | 124 } else if (fFallbackTextContext->canDraw(skPaint, viewMatrix, props, |
125 *context->caps()->shaderCaps())) { | 125 *context->caps()->shaderCaps())) { |
126 fFallbackTextContext->drawPosText(context, dc, clip, paint, skPaint, vie
wMatrix, props, | 126 fFallbackTextContext->drawPosText(context, dc, clip, paint, skPaint, vie
wMatrix, props, |
127 text, byteLength, pos, | 127 text, byteLength, pos, |
128 scalarsPerPosition, offset, clipBounds
); | 128 scalarsPerPosition, offset, clipBounds
); |
129 return; | 129 return; |
130 } | 130 } |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
219 | 219 |
220 GrPaint paint; | 220 GrPaint paint; |
221 if (!SkPaintToGrPaint(context, skPaint, viewMatrix, dc->isGammaCorrect(), &p
aint)) { | 221 if (!SkPaintToGrPaint(context, skPaint, viewMatrix, dc->isGammaCorrect(), &p
aint)) { |
222 return; | 222 return; |
223 } | 223 } |
224 | 224 |
225 const TextBlob& blob = this->findOrCreateTextBlob(skBlob, skPaint); | 225 const TextBlob& blob = this->findOrCreateTextBlob(skBlob, skPaint); |
226 | 226 |
227 TextBlob::Iter iter(blob); | 227 TextBlob::Iter iter(blob); |
228 for (TextRun* run = iter.get(); run; run = iter.next()) { | 228 for (TextRun* run = iter.get(); run; run = iter.next()) { |
229 run->draw(context, dc, paint, clip, paint.getColor(), viewMatrix, props,
x, y, | 229 // The run's "font" overrides the anti-aliasing of the passed in paint! |
| 230 paint.setAntiAlias(run->isAntiAlias()); |
| 231 run->draw(context, dc, paint, clip, viewMatrix, props, x, y, |
230 clipBounds, fFallbackTextContext, skPaint); | 232 clipBounds, fFallbackTextContext, skPaint); |
231 run->releaseGlyphCache(); | 233 run->releaseGlyphCache(); |
232 } | 234 } |
233 } | 235 } |
234 | 236 |
235 static inline int style_key_cnt(const GrStyle& style) { | 237 static inline int style_key_cnt(const GrStyle& style) { |
236 int cnt = GrStyle::KeySize(style, GrStyle::Apply::kPathEffectAndStrokeRec); | 238 int cnt = GrStyle::KeySize(style, GrStyle::Apply::kPathEffectAndStrokeRec); |
237 // We should be able to make a key because we filtered out arbitrary path ef
fects. | 239 // We should be able to make a key because we filtered out arbitrary path ef
fects. |
238 SkASSERT(cnt > 0); | 240 SkASSERT(cnt > 0); |
239 return cnt; | 241 return cnt; |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
355 SkPaint fFont; | 357 SkPaint fFont; |
356 int fBuffIdx; | 358 int fBuffIdx; |
357 int fCount; | 359 int fCount; |
358 uint16_t fGlyphIds[kWriteBufferSize]; | 360 uint16_t fGlyphIds[kWriteBufferSize]; |
359 SkPoint fPositions[kWriteBufferSize]; | 361 SkPoint fPositions[kWriteBufferSize]; |
360 }; | 362 }; |
361 | 363 |
362 ////////////////////////////////////////////////////////////////////////////////
//////////////////// | 364 ////////////////////////////////////////////////////////////////////////////////
//////////////////// |
363 | 365 |
364 GrStencilAndCoverTextContext::TextRun::TextRun(const SkPaint& fontAndStroke) | 366 GrStencilAndCoverTextContext::TextRun::TextRun(const SkPaint& fontAndStroke) |
365 : fStyle(fontAndStroke), | 367 : fStyle(fontAndStroke) |
366 fFont(fontAndStroke), | 368 , fFont(fontAndStroke) |
367 fTotalGlyphCount(0), | 369 , fTotalGlyphCount(0) |
368 fFallbackGlyphCount(0), | 370 , fFallbackGlyphCount(0) |
369 fDetachedGlyphCache(nullptr), | 371 , fDetachedGlyphCache(nullptr) |
370 fLastDrawnGlyphsID(SK_InvalidUniqueID) { | 372 , fLastDrawnGlyphsID(SK_InvalidUniqueID) { |
371 SkASSERT(fFont.getTextSize() > 0); | 373 SkASSERT(fFont.getTextSize() > 0); |
372 SkASSERT(!fStyle.hasNonDashPathEffect()); // Arbitrary path effects not supp
orted. | 374 SkASSERT(!fStyle.hasNonDashPathEffect()); // Arbitrary path effects not supp
orted. |
373 SkASSERT(!fStyle.isSimpleHairline()); // Hairlines are not supported. | 375 SkASSERT(!fStyle.isSimpleHairline()); // Hairlines are not supported. |
374 | 376 |
375 // Setting to "fill" ensures that no strokes get baked into font outlines. (
We use the GPU path | 377 // Setting to "fill" ensures that no strokes get baked into font outlines. (
We use the GPU path |
376 // rendering API for stroking). | 378 // rendering API for stroking). |
377 fFont.setStyle(SkPaint::kFill_Style); | 379 fFont.setStyle(SkPaint::kFill_Style); |
378 | 380 |
379 if (fFont.isFakeBoldText() && fStyle.isSimpleFill()) { | 381 if (fFont.isFakeBoldText() && fStyle.isSimpleFill()) { |
380 const SkStrokeRec& stroke = fStyle.strokeRec(); | 382 const SkStrokeRec& stroke = fStyle.strokeRec(); |
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
592 } else { | 594 } else { |
593 fInstanceData->append(glyph.getGlyphID(), fTextInverseRatio * pos.x(), | 595 fInstanceData->append(glyph.getGlyphID(), fTextInverseRatio * pos.x(), |
594 fTextInverseRatio * pos.y()); | 596 fTextInverseRatio * pos.y()); |
595 } | 597 } |
596 } | 598 } |
597 | 599 |
598 void GrStencilAndCoverTextContext::TextRun::draw(GrContext* ctx, | 600 void GrStencilAndCoverTextContext::TextRun::draw(GrContext* ctx, |
599 GrDrawContext* drawContext, | 601 GrDrawContext* drawContext, |
600 const GrPaint& grPaint, | 602 const GrPaint& grPaint, |
601 const GrClip& clip, | 603 const GrClip& clip, |
602 GrColor color, | |
603 const SkMatrix& viewMatrix, | 604 const SkMatrix& viewMatrix, |
604 const SkSurfaceProps& props, | 605 const SkSurfaceProps& props, |
605 SkScalar x, SkScalar y, | 606 SkScalar x, SkScalar y, |
606 const SkIRect& clipBounds, | 607 const SkIRect& clipBounds, |
607 GrAtlasTextContext* fallbackTex
tContext, | 608 GrAtlasTextContext* fallbackTex
tContext, |
608 const SkPaint& originalSkPaint)
const { | 609 const SkPaint& originalSkPaint)
const { |
609 SkASSERT(fInstanceData); | 610 SkASSERT(fInstanceData); |
610 SkASSERT(drawContext->isStencilBufferMultisampled() || !fFont.isAntiAlias())
; | 611 SkASSERT(drawContext->isStencilBufferMultisampled() || !grPaint.isAntiAlias(
)); |
611 | 612 |
612 if (fInstanceData->count()) { | 613 if (fInstanceData->count()) { |
613 static constexpr GrUserStencilSettings kCoverPass( | 614 static constexpr GrUserStencilSettings kCoverPass( |
614 GrUserStencilSettings::StaticInit< | 615 GrUserStencilSettings::StaticInit< |
615 0x0000, | 616 0x0000, |
616 GrUserStencilTest::kNotEqual, // Stencil pass accounts for clip. | 617 GrUserStencilTest::kNotEqual, // Stencil pass accounts for clip. |
617 0xffff, | 618 0xffff, |
618 GrUserStencilOp::kZero, | 619 GrUserStencilOp::kZero, |
619 GrUserStencilOp::kKeep, | 620 GrUserStencilOp::kKeep, |
620 0xffff>() | 621 0xffff>() |
621 ); | 622 ); |
622 | 623 |
623 SkAutoTUnref<GrPathRange> glyphs(this->createGlyphs(ctx)); | 624 SkAutoTUnref<GrPathRange> glyphs(this->createGlyphs(ctx)); |
624 if (fLastDrawnGlyphsID != glyphs->getUniqueID()) { | 625 if (fLastDrawnGlyphsID != glyphs->getUniqueID()) { |
625 // Either this is the first draw or the glyphs object was purged sin
ce last draw. | 626 // Either this is the first draw or the glyphs object was purged sin
ce last draw. |
626 glyphs->loadPathsIfNeeded(fInstanceData->indices(), fInstanceData->c
ount()); | 627 glyphs->loadPathsIfNeeded(fInstanceData->indices(), fInstanceData->c
ount()); |
627 fLastDrawnGlyphsID = glyphs->getUniqueID(); | 628 fLastDrawnGlyphsID = glyphs->getUniqueID(); |
628 } | 629 } |
629 | 630 |
630 // Don't compute a bounding box. For dst copy texture, we'll opt instead
for it to just copy | 631 // Don't compute a bounding box. For dst copy texture, we'll opt instead
for it to just copy |
631 // the entire dst. Realistically this is a moot point, because any conte
xt that supports | 632 // the entire dst. Realistically this is a moot point, because any conte
xt that supports |
632 // NV_path_rendering will also support NV_blend_equation_advanced. | 633 // NV_path_rendering will also support NV_blend_equation_advanced. |
633 // For clipping we'll just skip any optimizations based on the bounds. T
his does, however, | 634 // For clipping we'll just skip any optimizations based on the bounds. T
his does, however, |
634 // hurt batching. | 635 // hurt batching. |
635 const SkRect bounds = SkRect::MakeIWH(drawContext->width(), drawContext-
>height()); | 636 const SkRect bounds = SkRect::MakeIWH(drawContext->width(), drawContext-
>height()); |
636 | 637 |
637 SkAutoTUnref<GrDrawBatch> batch( | 638 SkAutoTUnref<GrDrawBatch> batch( |
638 GrDrawPathRangeBatch::Create(viewMatrix, fTextRatio, fTextInverseRat
io * x, | 639 GrDrawPathRangeBatch::Create(viewMatrix, fTextRatio, fTextInverseRat
io * x, |
639 fTextInverseRatio * y, color, | 640 fTextInverseRatio * y, grPaint.getColor
(), |
640 GrPathRendering::kWinding_FillType, gly
phs, fInstanceData, | 641 GrPathRendering::kWinding_FillType, gly
phs, fInstanceData, |
641 bounds)); | 642 bounds)); |
642 | 643 |
643 GrPipelineBuilder pipelineBuilder(grPaint); | 644 GrPipelineBuilder pipelineBuilder(grPaint); |
644 pipelineBuilder.setState(GrPipelineBuilder::kHWAntialias_Flag, fFont.isA
ntiAlias()); | 645 pipelineBuilder.setState(GrPipelineBuilder::kHWAntialias_Flag, grPaint.i
sAntiAlias()); |
645 pipelineBuilder.setUserStencil(&kCoverPass); | 646 pipelineBuilder.setUserStencil(&kCoverPass); |
646 | 647 |
647 drawContext->drawBatch(pipelineBuilder, clip, batch); | 648 drawContext->drawBatch(pipelineBuilder, clip, batch); |
648 } | 649 } |
649 | 650 |
650 if (fFallbackTextBlob) { | 651 if (fFallbackTextBlob) { |
651 SkPaint fallbackSkPaint(originalSkPaint); | 652 SkPaint fallbackSkPaint(originalSkPaint); |
652 fStyle.strokeRec().applyToPaint(&fallbackSkPaint); | 653 fStyle.strokeRec().applyToPaint(&fallbackSkPaint); |
653 if (!fStyle.isSimpleFill()) { | 654 if (!fStyle.isSimpleFill()) { |
654 fallbackSkPaint.setStrokeWidth(fStyle.strokeRec().getWidth() * fText
Ratio); | 655 fallbackSkPaint.setStrokeWidth(fStyle.strokeRec().getWidth() * fText
Ratio); |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
730 } | 731 } |
731 | 732 |
732 const SkTextBlob* GrStencilAndCoverTextContext::FallbackBlobBuilder::buildIfNeed
ed(int *count) { | 733 const SkTextBlob* GrStencilAndCoverTextContext::FallbackBlobBuilder::buildIfNeed
ed(int *count) { |
733 *count = fCount; | 734 *count = fCount; |
734 if (fCount) { | 735 if (fCount) { |
735 this->flush(); | 736 this->flush(); |
736 return fBuilder->build(); | 737 return fBuilder->build(); |
737 } | 738 } |
738 return nullptr; | 739 return nullptr; |
739 } | 740 } |
OLD | NEW |