GrPathRenderingRenderTargetContext.cpp revision fe17456d5e528078ce69b5f15cf7adf1fab963f9
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 "GrPathRenderingRenderTargetContext.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());)
16#define RETURN_IF_ABANDONED        if (this->drawingManager()->wasAbandoned()) { return; }
17
18void GrPathRenderingRenderTargetContext::drawText(const GrClip& clip, const SkPaint& skPaint,
19                                                  const SkMatrix& viewMatrix, const char text[],
20                                                  size_t byteLength, SkScalar x, SkScalar y,
21                                                  const SkIRect& clipBounds) {
22    ASSERT_SINGLE_OWNER
23    RETURN_IF_ABANDONED
24    SkDEBUGCODE(this->validate();)
25    GR_AUDIT_TRAIL_AUTO_FRAME(this->auditTrail(), "GrPathRenderingRenderTargetContext::drawText");
26
27    if (!fStencilAndCoverTextContext) {
28        GrAtlasTextContext* fallbackContext = this->drawingManager()->getAtlasTextContext();
29        fStencilAndCoverTextContext.reset(GrStencilAndCoverTextContext::Create(fallbackContext));
30    }
31
32    fStencilAndCoverTextContext->drawText(this->drawingManager()->getContext(), this, clip, skPaint,
33                                          viewMatrix, this->surfaceProps(), text, byteLength, x, y,
34                                          clipBounds);
35}
36
37void GrPathRenderingRenderTargetContext::drawPosText(const GrClip& clip, const SkPaint& skPaint,
38                                                     const SkMatrix& viewMatrix, const char text[],
39                                                     size_t byteLength, const SkScalar pos[],
40                                                     int scalarsPerPosition, const SkPoint& offset,
41                                                     const SkIRect& clipBounds) {
42    ASSERT_SINGLE_OWNER
43    RETURN_IF_ABANDONED
44    SkDEBUGCODE(this->validate();)
45    GR_AUDIT_TRAIL_AUTO_FRAME(this->auditTrail(),
46                              "GrPathRenderingRenderTargetContext::drawPosText");
47
48    if (!fStencilAndCoverTextContext) {
49        GrAtlasTextContext* fallbackContext = this->drawingManager()->getAtlasTextContext();
50        fStencilAndCoverTextContext.reset(GrStencilAndCoverTextContext::Create(fallbackContext));
51    }
52
53    fStencilAndCoverTextContext->drawPosText(
54            this->drawingManager()->getContext(), this, clip, skPaint, viewMatrix,
55            this->surfaceProps(), text, byteLength, pos, scalarsPerPosition, offset, clipBounds);
56}
57
58void GrPathRenderingRenderTargetContext::drawTextBlob(const GrClip& clip, const SkPaint& skPaint,
59                                                      const SkMatrix& viewMatrix,
60                                                      const SkTextBlob* blob,
61                                                      SkScalar x, SkScalar y,
62                                                      SkDrawFilter* filter,
63                                                      const SkIRect& clipBounds) {
64    ASSERT_SINGLE_OWNER
65    RETURN_IF_ABANDONED
66    SkDEBUGCODE(this->validate();)
67    GR_AUDIT_TRAIL_AUTO_FRAME(this->auditTrail(),
68                              "GrPathRenderingRenderTargetContext::drawTextBlob");
69
70    if (!fStencilAndCoverTextContext) {
71        GrAtlasTextContext* fallbackContext = this->drawingManager()->getAtlasTextContext();
72        fStencilAndCoverTextContext.reset(GrStencilAndCoverTextContext::Create(fallbackContext));
73    }
74
75    fStencilAndCoverTextContext->drawTextBlob(this->drawingManager()->getContext(), this, clip,
76                                              skPaint, viewMatrix, this->surfaceProps(), blob, x,
77                                              y, filter, clipBounds);
78}
79