OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2011 Google Inc. | 3 * Copyright 2011 Google Inc. |
4 * | 4 * |
5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
7 */ | 7 */ |
8 | 8 |
9 | 9 |
10 #include "GrPathRendererChain.h" | 10 #include "GrPathRendererChain.h" |
11 | 11 |
12 #include "GrCaps.h" | 12 #include "GrCaps.h" |
13 #include "GrContext.h" | 13 #include "GrContext.h" |
14 #include "GrGpu.h" | 14 #include "GrGpu.h" |
15 | 15 |
16 #include "batches/GrAAConvexPathRenderer.h" | 16 #include "batches/GrAAConvexPathRenderer.h" |
17 #include "batches/GrAADistanceFieldPathRenderer.h" | 17 #include "batches/GrAADistanceFieldPathRenderer.h" |
18 #include "batches/GrAAHairLinePathRenderer.h" | 18 #include "batches/GrAAHairLinePathRenderer.h" |
19 #include "batches/GrAALinearizingConvexPathRenderer.h" | 19 #include "batches/GrAALinearizingConvexPathRenderer.h" |
20 #include "batches/GrDashLinePathRenderer.h" | 20 #include "batches/GrDashLinePathRenderer.h" |
21 #include "batches/GrDefaultPathRenderer.h" | 21 #include "batches/GrDefaultPathRenderer.h" |
22 #include "batches/GrStencilAndCoverPathRenderer.h" | 22 #include "batches/GrStencilAndCoverPathRenderer.h" |
23 #include "batches/GrTessellatingPathRenderer.h" | 23 #include "batches/GrTessellatingPathRenderer.h" |
24 | 24 |
25 GrPathRendererChain::GrPathRendererChain(GrContext* context) | 25 GrPathRendererChain::GrPathRendererChain(GrContext* context) { |
26 : fInit(false) | 26 const GrCaps& caps = *context->caps(); |
27 , fOwner(context) { | 27 this->addPathRenderer(new GrDashLinePathRenderer)->unref(); |
| 28 |
| 29 if (GrPathRenderer* pr = GrStencilAndCoverPathRenderer::Create(context->reso
urceProvider(), |
| 30 caps)) { |
| 31 this->addPathRenderer(pr)->unref(); |
| 32 } |
| 33 this->addPathRenderer(new GrTessellatingPathRenderer)->unref(); |
| 34 this->addPathRenderer(new GrAAHairLinePathRenderer)->unref(); |
| 35 this->addPathRenderer(new GrAAConvexPathRenderer)->unref(); |
| 36 this->addPathRenderer(new GrAALinearizingConvexPathRenderer)->unref(); |
| 37 this->addPathRenderer(new GrAADistanceFieldPathRenderer)->unref(); |
| 38 this->addPathRenderer(new GrDefaultPathRenderer(caps.twoSidedStencilSupport(
), |
| 39 caps.stencilWrapOpsSupport()
))->unref(); |
28 } | 40 } |
29 | 41 |
30 GrPathRendererChain::~GrPathRendererChain() { | 42 GrPathRendererChain::~GrPathRendererChain() { |
31 for (int i = 0; i < fChain.count(); ++i) { | 43 for (int i = 0; i < fChain.count(); ++i) { |
32 fChain[i]->unref(); | 44 fChain[i]->unref(); |
33 } | 45 } |
34 } | 46 } |
35 | 47 |
36 GrPathRenderer* GrPathRendererChain::addPathRenderer(GrPathRenderer* pr) { | 48 GrPathRenderer* GrPathRendererChain::addPathRenderer(GrPathRenderer* pr) { |
37 fChain.push_back() = pr; | 49 fChain.push_back() = pr; |
38 pr->ref(); | 50 pr->ref(); |
39 return pr; | 51 return pr; |
40 } | 52 } |
41 | 53 |
42 GrPathRenderer* GrPathRendererChain::getPathRenderer(const GrPathRenderer::CanDr
awPathArgs& args, | 54 GrPathRenderer* GrPathRendererChain::getPathRenderer(const GrPathRenderer::CanDr
awPathArgs& args, |
43 DrawType drawType, | 55 DrawType drawType, |
44 GrPathRenderer::StencilSupp
ort* stencilSupport) { | 56 GrPathRenderer::StencilSupp
ort* stencilSupport) { |
45 if (!fInit) { | |
46 this->init(); | |
47 } | |
48 | |
49 GR_STATIC_ASSERT(GrPathRenderer::kNoSupport_StencilSupport < | 57 GR_STATIC_ASSERT(GrPathRenderer::kNoSupport_StencilSupport < |
50 GrPathRenderer::kStencilOnly_StencilSupport); | 58 GrPathRenderer::kStencilOnly_StencilSupport); |
51 GR_STATIC_ASSERT(GrPathRenderer::kStencilOnly_StencilSupport < | 59 GR_STATIC_ASSERT(GrPathRenderer::kStencilOnly_StencilSupport < |
52 GrPathRenderer::kNoRestriction_StencilSupport); | 60 GrPathRenderer::kNoRestriction_StencilSupport); |
53 GrPathRenderer::StencilSupport minStencilSupport; | 61 GrPathRenderer::StencilSupport minStencilSupport; |
54 if (kStencilOnly_DrawType == drawType) { | 62 if (kStencilOnly_DrawType == drawType) { |
55 minStencilSupport = GrPathRenderer::kStencilOnly_StencilSupport; | 63 minStencilSupport = GrPathRenderer::kStencilOnly_StencilSupport; |
56 } else if (kStencilAndColor_DrawType == drawType || | 64 } else if (kStencilAndColor_DrawType == drawType || |
57 kStencilAndColorAntiAlias_DrawType == drawType) { | 65 kStencilAndColorAntiAlias_DrawType == drawType) { |
58 minStencilSupport = GrPathRenderer::kNoRestriction_StencilSupport; | 66 minStencilSupport = GrPathRenderer::kNoRestriction_StencilSupport; |
59 } else { | 67 } else { |
60 minStencilSupport = GrPathRenderer::kNoSupport_StencilSupport; | 68 minStencilSupport = GrPathRenderer::kNoSupport_StencilSupport; |
61 } | 69 } |
62 | 70 |
63 | |
64 for (int i = 0; i < fChain.count(); ++i) { | 71 for (int i = 0; i < fChain.count(); ++i) { |
65 if (fChain[i]->canDrawPath(args)) { | 72 if (fChain[i]->canDrawPath(args)) { |
66 if (GrPathRenderer::kNoSupport_StencilSupport != minStencilSupport)
{ | 73 if (GrPathRenderer::kNoSupport_StencilSupport != minStencilSupport)
{ |
67 GrPathRenderer::StencilSupport support = | 74 GrPathRenderer::StencilSupport support = |
68 fChain[i]->getStencilSupport(*args.fPath
, *args.fStroke); | 75 fChain[i]->getStencilSupport(*args.fPath
, *args.fStroke); |
69 if (support < minStencilSupport) { | 76 if (support < minStencilSupport) { |
70 continue; | 77 continue; |
71 } else if (stencilSupport) { | 78 } else if (stencilSupport) { |
72 *stencilSupport = support; | 79 *stencilSupport = support; |
73 } | 80 } |
74 } | 81 } |
75 return fChain[i]; | 82 return fChain[i]; |
76 } | 83 } |
77 } | 84 } |
78 return nullptr; | 85 return nullptr; |
79 } | 86 } |
80 | |
81 void GrPathRendererChain::init() { | |
82 SkASSERT(!fInit); | |
83 const GrCaps& caps = *fOwner->caps(); | |
84 this->addPathRenderer(new GrDashLinePathRenderer)->unref(); | |
85 | |
86 if (GrPathRenderer* pr = GrStencilAndCoverPathRenderer::Create(fOwner->resou
rceProvider(), | |
87 caps)) { | |
88 this->addPathRenderer(pr)->unref(); | |
89 } | |
90 this->addPathRenderer(new GrTessellatingPathRenderer)->unref(); | |
91 this->addPathRenderer(new GrAAHairLinePathRenderer)->unref(); | |
92 this->addPathRenderer(new GrAAConvexPathRenderer)->unref(); | |
93 this->addPathRenderer(new GrAALinearizingConvexPathRenderer)->unref(); | |
94 this->addPathRenderer(new GrAADistanceFieldPathRenderer)->unref(); | |
95 this->addPathRenderer(new GrDefaultPathRenderer(caps.twoSidedStencilSupport(
), | |
96 caps.stencilWrapOpsSupport()
))->unref(); | |
97 fInit = true; | |
98 } | |
OLD | NEW |