joshualitt | 96880d9 | 2016-02-16 10:36:53 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2016 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
| 7 | |
| 8 | #include "GrPathRenderingDrawContext.h" |
| 9 | |
| 10 | #include "GrDrawingManager.h" |
| 11 | |
| 12 | #include "text/GrStencilAndCoverTextContext.h" |
| 13 | |
| 14 | #define ASSERT_SINGLE_OWNER \ |
| 15 | SkDEBUGCODE(GrSingleOwner::AutoEnforce debug_SingleOwner(this->singleOwner());) |
robertphillips | 7761d61 | 2016-05-16 09:14:53 -0700 | [diff] [blame] | 16 | #define RETURN_IF_ABANDONED if (this->drawingManager()->wasAbandoned()) { return; } |
joshualitt | 96880d9 | 2016-02-16 10:36:53 -0800 | [diff] [blame] | 17 | |
| 18 | void GrPathRenderingDrawContext::drawText(const GrClip& clip, const GrPaint& grPaint, |
| 19 | const SkPaint& skPaint, |
| 20 | const SkMatrix& viewMatrix, const char text[], |
| 21 | size_t byteLength, SkScalar x, SkScalar y, |
| 22 | const SkIRect& clipBounds) { |
| 23 | ASSERT_SINGLE_OWNER |
| 24 | RETURN_IF_ABANDONED |
| 25 | SkDEBUGCODE(this->validate();) |
| 26 | GR_AUDIT_TRAIL_AUTO_FRAME(this->auditTrail(), "GrPathRenderingDrawContext::drawText"); |
| 27 | |
| 28 | if (!fStencilAndCoverTextContext) { |
brianosman | 86e7626 | 2016-08-11 12:17:31 -0700 | [diff] [blame] | 29 | GrAtlasTextContext* fallbackContext = this->drawingManager()->getAtlasTextContext(); |
| 30 | fStencilAndCoverTextContext.reset(GrStencilAndCoverTextContext::Create(fallbackContext)); |
joshualitt | 96880d9 | 2016-02-16 10:36:53 -0800 | [diff] [blame] | 31 | } |
| 32 | |
| 33 | fStencilAndCoverTextContext->drawText(this->drawingManager()->getContext(), this, clip, grPaint, |
| 34 | skPaint, viewMatrix, this->surfaceProps(), |
| 35 | text, byteLength, x, y, clipBounds); |
| 36 | } |
| 37 | |
| 38 | void GrPathRenderingDrawContext::drawPosText(const GrClip& clip, const GrPaint& grPaint, |
| 39 | const SkPaint& skPaint, |
| 40 | const SkMatrix& viewMatrix, const char text[], |
| 41 | size_t byteLength, const SkScalar pos[], |
| 42 | int scalarsPerPosition, const SkPoint& offset, |
| 43 | const SkIRect& clipBounds) { |
| 44 | ASSERT_SINGLE_OWNER |
| 45 | RETURN_IF_ABANDONED |
| 46 | SkDEBUGCODE(this->validate();) |
| 47 | GR_AUDIT_TRAIL_AUTO_FRAME(this->auditTrail(), "GrPathRenderingDrawContext::drawPosText"); |
| 48 | |
| 49 | if (!fStencilAndCoverTextContext) { |
brianosman | 86e7626 | 2016-08-11 12:17:31 -0700 | [diff] [blame] | 50 | GrAtlasTextContext* fallbackContext = this->drawingManager()->getAtlasTextContext(); |
| 51 | fStencilAndCoverTextContext.reset(GrStencilAndCoverTextContext::Create(fallbackContext)); |
joshualitt | 96880d9 | 2016-02-16 10:36:53 -0800 | [diff] [blame] | 52 | } |
| 53 | |
| 54 | fStencilAndCoverTextContext->drawPosText(this->drawingManager()->getContext(), this, clip, |
| 55 | grPaint, skPaint, viewMatrix, this->surfaceProps(), |
| 56 | text, byteLength, pos, scalarsPerPosition, offset, |
| 57 | clipBounds); |
| 58 | } |
| 59 | |
| 60 | void GrPathRenderingDrawContext::drawTextBlob(const GrClip& clip, const SkPaint& skPaint, |
| 61 | const SkMatrix& viewMatrix, const SkTextBlob* blob, |
| 62 | SkScalar x, SkScalar y, |
| 63 | SkDrawFilter* filter, const SkIRect& clipBounds) { |
| 64 | ASSERT_SINGLE_OWNER |
| 65 | RETURN_IF_ABANDONED |
| 66 | SkDEBUGCODE(this->validate();) |
| 67 | GR_AUDIT_TRAIL_AUTO_FRAME(this->auditTrail(), "GrPathRenderingDrawContext::drawTextBlob"); |
| 68 | |
| 69 | if (!fStencilAndCoverTextContext) { |
brianosman | 86e7626 | 2016-08-11 12:17:31 -0700 | [diff] [blame] | 70 | GrAtlasTextContext* fallbackContext = this->drawingManager()->getAtlasTextContext(); |
| 71 | fStencilAndCoverTextContext.reset(GrStencilAndCoverTextContext::Create(fallbackContext)); |
joshualitt | 96880d9 | 2016-02-16 10:36:53 -0800 | [diff] [blame] | 72 | } |
| 73 | |
| 74 | fStencilAndCoverTextContext->drawTextBlob(this->drawingManager()->getContext(), this, clip, |
| 75 | skPaint, viewMatrix, this->surfaceProps(), blob, x, |
| 76 | y, filter, clipBounds); |
| 77 | } |