Chromium Code Reviews| Index: src/gpu/text/GrStencilAndCoverTextContext.cpp |
| diff --git a/src/gpu/text/GrStencilAndCoverTextContext.cpp b/src/gpu/text/GrStencilAndCoverTextContext.cpp |
| index d28f1a803a0abe7df26843e7848fd21821d8b4f5..1a4ff0dd13c85a9e79ed015d556925c3f978a6f8 100644 |
| --- a/src/gpu/text/GrStencilAndCoverTextContext.cpp |
| +++ b/src/gpu/text/GrStencilAndCoverTextContext.cpp |
| @@ -12,6 +12,7 @@ |
| #include "GrPath.h" |
| #include "GrPathRange.h" |
| #include "GrResourceProvider.h" |
| +#include "GrTextUtils.h" |
| #include "SkAutoKern.h" |
| #include "SkDraw.h" |
| #include "SkDrawProcs.h" |
| @@ -51,6 +52,7 @@ GrStencilAndCoverTextContext::Create(GrContext* context, const SkSurfaceProps& s |
| } |
| GrStencilAndCoverTextContext::~GrStencilAndCoverTextContext() { |
| + delete fFallbackTextContext; |
| fBlobIdCache.foreach(delete_hash_map_entry<uint32_t, TextBlob*>); |
| fBlobKeyCache.foreach(delete_hash_table_entry<TextBlob*>); |
| } |
| @@ -71,38 +73,61 @@ bool GrStencilAndCoverTextContext::internalCanDraw(const SkPaint& skPaint) { |
| return SkPaint::kStroke_Style != skPaint.getStyle() || 0 != skPaint.getStrokeWidth(); |
| } |
| -void GrStencilAndCoverTextContext::onDrawText(GrDrawContext* dc, |
| - const GrClip& clip, |
| - const GrPaint& paint, |
| - const SkPaint& skPaint, |
| - const SkMatrix& viewMatrix, |
| - const char text[], |
| - size_t byteLength, |
| - SkScalar x, SkScalar y, |
| - const SkIRect& clipBounds) { |
| - TextRun run(skPaint); |
| - GrPipelineBuilder pipelineBuilder(paint, dc->accessRenderTarget(), clip); |
| - run.setText(text, byteLength, x, y); |
| - run.draw(fContext, dc, &pipelineBuilder, paint.getColor(), viewMatrix, 0, 0, clipBounds, |
| - fFallbackTextContext, skPaint); |
| +void GrStencilAndCoverTextContext::drawText(GrDrawContext* dc, |
| + const GrClip& clip, const GrPaint& paint, |
| + const SkPaint& skPaint, const SkMatrix& viewMatrix, |
| + const char text[], size_t byteLength, |
| + SkScalar x, SkScalar y, const SkIRect& clipBounds) { |
| + if (fContext->abandoned()) { |
| + return; |
| + } else if (this->canDraw(skPaint, viewMatrix)) { |
| + TextRun run(skPaint); |
| + GrPipelineBuilder pipelineBuilder(paint, dc->accessRenderTarget(), clip); |
| + run.setText(text, byteLength, x, y); |
| + run.draw(fContext, dc, &pipelineBuilder, paint.getColor(), viewMatrix, 0, 0, clipBounds, |
| + fFallbackTextContext, skPaint); |
| + return; |
| + } else if (fFallbackTextContext->canDraw(skPaint, viewMatrix)) { |
| + fFallbackTextContext->drawText(dc, clip, paint, skPaint, viewMatrix, text, |
| + byteLength, x, y, clipBounds); |
| + return; |
| + } |
| + |
| + // fall back to drawing as a path |
| + GrTextUtils::DrawTextAsPath(fContext, dc, clip, skPaint, viewMatrix, text, byteLength, x, y, |
| + clipBounds); |
| } |
| -void GrStencilAndCoverTextContext::onDrawPosText(GrDrawContext* dc, |
| - const GrClip& clip, |
| - const GrPaint& paint, |
| - const SkPaint& skPaint, |
| - const SkMatrix& viewMatrix, |
| - const char text[], |
| - size_t byteLength, |
| - const SkScalar pos[], |
| - int scalarsPerPosition, |
| - const SkPoint& offset, |
| - const SkIRect& clipBounds) { |
| - TextRun run(skPaint); |
| - GrPipelineBuilder pipelineBuilder(paint, dc->accessRenderTarget(), clip); |
| - run.setPosText(text, byteLength, pos, scalarsPerPosition, offset); |
| - run.draw(fContext, dc, &pipelineBuilder, paint.getColor(), viewMatrix, 0, 0, clipBounds, |
| - fFallbackTextContext, skPaint); |
| +void GrStencilAndCoverTextContext::drawPosText(GrDrawContext* dc, |
| + const GrClip& clip, |
| + const GrPaint& paint, |
| + const SkPaint& skPaint, |
| + const SkMatrix& viewMatrix, |
| + const char text[], |
| + size_t byteLength, |
| + const SkScalar pos[], |
| + int scalarsPerPosition, |
| + const SkPoint& offset, |
| + const SkIRect& clipBounds) { |
| + if (fContext->abandoned()) { |
| + return; |
| + } else if (this->canDraw(skPaint, viewMatrix)) { |
| + TextRun run(skPaint); |
| + GrPipelineBuilder pipelineBuilder(paint, dc->accessRenderTarget(), clip); |
| + run.setPosText(text, byteLength, pos, scalarsPerPosition, offset); |
| + run.draw(fContext, dc, &pipelineBuilder, paint.getColor(), viewMatrix, 0, 0, clipBounds, |
| + fFallbackTextContext, skPaint); |
| + return; |
| + } else if (fFallbackTextContext->canDraw(skPaint, viewMatrix)) { |
| + fFallbackTextContext->drawPosText(dc, clip, paint, skPaint, viewMatrix, |
| + text, byteLength, pos, |
| + scalarsPerPosition, offset, clipBounds); |
| + return; |
| + } |
| + |
| + // fall back to drawing as a path |
| + GrTextUtils::DrawPosTextAsPath(fContext, dc, fSurfaceProps, clip, skPaint, viewMatrix, text, |
| + byteLength, pos, scalarsPerPosition, offset, clipBounds); |
| } |
| void GrStencilAndCoverTextContext::drawTextBlob(GrDrawContext* dc, |
| @@ -111,6 +136,10 @@ void GrStencilAndCoverTextContext::drawTextBlob(GrDrawContext* dc, |
| const SkTextBlob* skBlob, SkScalar x, SkScalar y, |
| SkDrawFilter* drawFilter, |
| const SkIRect& clipBounds) { |
| + if (fContext->abandoned()) { |
| + return; |
| + } |
| + |
| if (!this->internalCanDraw(skPaint)) { |
| fFallbackTextContext->drawTextBlob(dc, clip, skPaint, viewMatrix, skBlob, x, y, |
| drawFilter, clipBounds); |
| @@ -119,12 +148,8 @@ void GrStencilAndCoverTextContext::drawTextBlob(GrDrawContext* dc, |
| if (drawFilter || skPaint.getPathEffect()) { |
| // This draw can't be cached. |
|
robertphillips
2016/02/10 18:28:45
This doesn't seem quite right ...
joshualitt
2016/02/10 20:06:05
Acknowledged.
|
| - INHERITED::drawTextBlob(dc, clip, skPaint, viewMatrix, skBlob, x, y, drawFilter, |
| - clipBounds); |
| - return; |
| - } |
| - |
| - if (fContext->abandoned()) { |
| + fFallbackTextContext->drawTextBlob(dc, clip, skPaint, viewMatrix, skBlob, x, y, drawFilter, |
| + clipBounds); |
| return; |
| } |