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 "GrDrawContext.h" | 10 #include "GrDrawContext.h" |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
73 | 73 |
74 void GrStencilAndCoverTextContext::drawText(GrContext* context, GrDrawContext* d
c, | 74 void GrStencilAndCoverTextContext::drawText(GrContext* context, GrDrawContext* d
c, |
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 TextRun run(skPaint); | 83 if (skPaint.getTextSize() > 0) { |
84 GrPipelineBuilder pipelineBuilder(paint, dc->accessRenderTarget(), clip)
; | 84 TextRun run(skPaint); |
85 run.setText(text, byteLength, x, y); | 85 GrPipelineBuilder pipelineBuilder(paint, dc->accessRenderTarget(), c
lip); |
86 run.draw(context, dc, &pipelineBuilder, paint.getColor(), viewMatrix, pr
ops, 0, 0, | 86 run.setText(text, byteLength, x, y); |
87 clipBounds, fFallbackTextContext, skPaint); | 87 run.draw(context, dc, &pipelineBuilder, paint.getColor(), viewMatrix
, props, 0, 0, |
| 88 clipBounds, fFallbackTextContext, skPaint); |
| 89 } |
88 return; | 90 return; |
89 } else if (fFallbackTextContext->canDraw(skPaint, viewMatrix, props, | 91 } else if (fFallbackTextContext->canDraw(skPaint, viewMatrix, props, |
90 *context->caps()->shaderCaps())) { | 92 *context->caps()->shaderCaps())) { |
91 fFallbackTextContext->drawText(context, dc, clip, paint, skPaint, viewMa
trix, props, text, | 93 fFallbackTextContext->drawText(context, dc, clip, paint, skPaint, viewMa
trix, props, text, |
92 byteLength, x, y, clipBounds); | 94 byteLength, x, y, clipBounds); |
93 return; | 95 return; |
94 } | 96 } |
95 | 97 |
96 // fall back to drawing as a path | 98 // fall back to drawing as a path |
97 GrTextUtils::DrawTextAsPath(context, dc, clip, skPaint, viewMatrix, text, by
teLength, x, y, | 99 GrTextUtils::DrawTextAsPath(context, dc, clip, skPaint, viewMatrix, text, by
teLength, x, y, |
98 clipBounds); | 100 clipBounds); |
99 } | 101 } |
100 | 102 |
101 void GrStencilAndCoverTextContext::drawPosText(GrContext* context, GrDrawContext
* dc, | 103 void GrStencilAndCoverTextContext::drawPosText(GrContext* context, GrDrawContext
* dc, |
102 const GrClip& clip, | 104 const GrClip& clip, |
103 const GrPaint& paint, | 105 const GrPaint& paint, |
104 const SkPaint& skPaint, | 106 const SkPaint& skPaint, |
105 const SkMatrix& viewMatrix, | 107 const SkMatrix& viewMatrix, |
106 const SkSurfaceProps& props, | 108 const SkSurfaceProps& props, |
107 const char text[], | 109 const char text[], |
108 size_t byteLength, | 110 size_t byteLength, |
109 const SkScalar pos[], | 111 const SkScalar pos[], |
110 int scalarsPerPosition, | 112 int scalarsPerPosition, |
111 const SkPoint& offset, | 113 const SkPoint& offset, |
112 const SkIRect& clipBounds) { | 114 const SkIRect& clipBounds) { |
113 if (context->abandoned()) { | 115 if (context->abandoned()) { |
114 return; | 116 return; |
115 } else if (this->canDraw(skPaint, viewMatrix)) { | 117 } else if (this->canDraw(skPaint, viewMatrix)) { |
116 TextRun run(skPaint); | 118 if (skPaint.getTextSize() > 0) { |
117 GrPipelineBuilder pipelineBuilder(paint, dc->accessRenderTarget(), clip)
; | 119 TextRun run(skPaint); |
118 run.setPosText(text, byteLength, pos, scalarsPerPosition, offset); | 120 GrPipelineBuilder pipelineBuilder(paint, dc->accessRenderTarget(), c
lip); |
119 run.draw(context, dc, &pipelineBuilder, paint.getColor(), viewMatrix, pr
ops, 0, 0, | 121 run.setPosText(text, byteLength, pos, scalarsPerPosition, offset); |
120 clipBounds, fFallbackTextContext, skPaint); | 122 run.draw(context, dc, &pipelineBuilder, paint.getColor(), viewMatrix
, props, 0, 0, |
| 123 clipBounds, fFallbackTextContext, skPaint); |
| 124 } |
121 return; | 125 return; |
122 } else if (fFallbackTextContext->canDraw(skPaint, viewMatrix, props, | 126 } else if (fFallbackTextContext->canDraw(skPaint, viewMatrix, props, |
123 *context->caps()->shaderCaps())) { | 127 *context->caps()->shaderCaps())) { |
124 fFallbackTextContext->drawPosText(context, dc, clip, paint, skPaint, vie
wMatrix, props, | 128 fFallbackTextContext->drawPosText(context, dc, clip, paint, skPaint, vie
wMatrix, props, |
125 text, byteLength, pos, | 129 text, byteLength, pos, |
126 scalarsPerPosition, offset, clipBounds
); | 130 scalarsPerPosition, offset, clipBounds
); |
127 return; | 131 return; |
128 } | 132 } |
129 | 133 |
130 // fall back to drawing as a path | 134 // fall back to drawing as a path |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
287 } | 291 } |
288 | 292 |
289 ////////////////////////////////////////////////////////////////////////////////
//////////////////// | 293 ////////////////////////////////////////////////////////////////////////////////
//////////////////// |
290 | 294 |
291 void GrStencilAndCoverTextContext::TextBlob::init(const SkTextBlob* skBlob, | 295 void GrStencilAndCoverTextContext::TextBlob::init(const SkTextBlob* skBlob, |
292 const SkPaint& skPaint) { | 296 const SkPaint& skPaint) { |
293 fCpuMemorySize = sizeof(TextBlob); | 297 fCpuMemorySize = sizeof(TextBlob); |
294 SkPaint runPaint(skPaint); | 298 SkPaint runPaint(skPaint); |
295 for (SkTextBlobRunIterator iter(skBlob); !iter.done(); iter.next()) { | 299 for (SkTextBlobRunIterator iter(skBlob); !iter.done(); iter.next()) { |
296 iter.applyFontToPaint(&runPaint); // No need to re-seed the paint. | 300 iter.applyFontToPaint(&runPaint); // No need to re-seed the paint. |
| 301 if (runPaint.getTextSize() <= 0) { |
| 302 continue; |
| 303 } |
297 TextRun* run = this->addToTail(runPaint); | 304 TextRun* run = this->addToTail(runPaint); |
298 | 305 |
299 const char* text = reinterpret_cast<const char*>(iter.glyphs()); | 306 const char* text = reinterpret_cast<const char*>(iter.glyphs()); |
300 size_t byteLength = sizeof(uint16_t) * iter.glyphCount(); | 307 size_t byteLength = sizeof(uint16_t) * iter.glyphCount(); |
301 const SkPoint& runOffset = iter.offset(); | 308 const SkPoint& runOffset = iter.offset(); |
302 | 309 |
303 switch (iter.positioning()) { | 310 switch (iter.positioning()) { |
304 case SkTextBlob::kDefault_Positioning: | 311 case SkTextBlob::kDefault_Positioning: |
305 run->setText(text, byteLength, runOffset.fX, runOffset.fY); | 312 run->setText(text, byteLength, runOffset.fX, runOffset.fY); |
306 break; | 313 break; |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
345 | 352 |
346 ////////////////////////////////////////////////////////////////////////////////
//////////////////// | 353 ////////////////////////////////////////////////////////////////////////////////
//////////////////// |
347 | 354 |
348 GrStencilAndCoverTextContext::TextRun::TextRun(const SkPaint& fontAndStroke) | 355 GrStencilAndCoverTextContext::TextRun::TextRun(const SkPaint& fontAndStroke) |
349 : fStroke(fontAndStroke), | 356 : fStroke(fontAndStroke), |
350 fFont(fontAndStroke), | 357 fFont(fontAndStroke), |
351 fTotalGlyphCount(0), | 358 fTotalGlyphCount(0), |
352 fFallbackGlyphCount(0), | 359 fFallbackGlyphCount(0), |
353 fDetachedGlyphCache(nullptr), | 360 fDetachedGlyphCache(nullptr), |
354 fLastDrawnGlyphsID(SK_InvalidUniqueID) { | 361 fLastDrawnGlyphsID(SK_InvalidUniqueID) { |
| 362 SkASSERT(fFont.getTextSize() > 0); |
355 SkASSERT(!fStroke.isHairlineStyle()); // Hairlines are not supported. | 363 SkASSERT(!fStroke.isHairlineStyle()); // Hairlines are not supported. |
356 | 364 |
357 // Setting to "fill" ensures that no strokes get baked into font outlines. (
We use the GPU path | 365 // Setting to "fill" ensures that no strokes get baked into font outlines. (
We use the GPU path |
358 // rendering API for stroking). | 366 // rendering API for stroking). |
359 fFont.setStyle(SkPaint::kFill_Style); | 367 fFont.setStyle(SkPaint::kFill_Style); |
360 | 368 |
361 if (fFont.isFakeBoldText() && SkStrokeRec::kStroke_Style != fStroke.getStyle
()) { | 369 if (fFont.isFakeBoldText() && SkStrokeRec::kStroke_Style != fStroke.getStyle
()) { |
362 // Instead of letting fake bold get baked into the glyph outlines, do it
with GPU stroke. | 370 // Instead of letting fake bold get baked into the glyph outlines, do it
with GPU stroke. |
363 SkScalar fakeBoldScale = SkScalarInterpFunc(fFont.getTextSize(), | 371 SkScalar fakeBoldScale = SkScalarInterpFunc(fFont.getTextSize(), |
364 kStdFakeBoldInterpKeys, | 372 kStdFakeBoldInterpKeys, |
(...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
696 } | 704 } |
697 | 705 |
698 const SkTextBlob* GrStencilAndCoverTextContext::FallbackBlobBuilder::buildIfNeed
ed(int *count) { | 706 const SkTextBlob* GrStencilAndCoverTextContext::FallbackBlobBuilder::buildIfNeed
ed(int *count) { |
699 *count = fCount; | 707 *count = fCount; |
700 if (fCount) { | 708 if (fCount) { |
701 this->flush(); | 709 this->flush(); |
702 return fBuilder->build(); | 710 return fBuilder->build(); |
703 } | 711 } |
704 return nullptr; | 712 return nullptr; |
705 } | 713 } |
OLD | NEW |