blob: 1380f7dc78a5b85ad0e109b8fe159e4dde5a25fa [file] [log] [blame]
joshualitt96880d92016-02-16 10:36:53 -08001/*
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());)
robertphillips7761d612016-05-16 09:14:53 -070016#define RETURN_IF_ABANDONED if (this->drawingManager()->wasAbandoned()) { return; }
joshualitt96880d92016-02-16 10:36:53 -080017
18void 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) {
brianosman86e76262016-08-11 12:17:31 -070029 GrAtlasTextContext* fallbackContext = this->drawingManager()->getAtlasTextContext();
30 fStencilAndCoverTextContext.reset(GrStencilAndCoverTextContext::Create(fallbackContext));
joshualitt96880d92016-02-16 10:36:53 -080031 }
32
33 fStencilAndCoverTextContext->drawText(this->drawingManager()->getContext(), this, clip, grPaint,
34 skPaint, viewMatrix, this->surfaceProps(),
35 text, byteLength, x, y, clipBounds);
36}
37
38void 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) {
brianosman86e76262016-08-11 12:17:31 -070050 GrAtlasTextContext* fallbackContext = this->drawingManager()->getAtlasTextContext();
51 fStencilAndCoverTextContext.reset(GrStencilAndCoverTextContext::Create(fallbackContext));
joshualitt96880d92016-02-16 10:36:53 -080052 }
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
60void 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) {
brianosman86e76262016-08-11 12:17:31 -070070 GrAtlasTextContext* fallbackContext = this->drawingManager()->getAtlasTextContext();
71 fStencilAndCoverTextContext.reset(GrStencilAndCoverTextContext::Create(fallbackContext));
joshualitt96880d92016-02-16 10:36:53 -080072 }
73
74 fStencilAndCoverTextContext->drawTextBlob(this->drawingManager()->getContext(), this, clip,
75 skPaint, viewMatrix, this->surfaceProps(), blob, x,
76 y, filter, clipBounds);
77}