• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 
2 /*
3  * Copyright 2011 Google Inc.
4  *
5  * Use of this source code is governed by a BSD-style license that can be
6  * found in the LICENSE file.
7  */
8 
9 
10 #include "GrPathRendererChain.h"
11 
12 #include "GrContext.h"
13 #include "GrDefaultPathRenderer.h"
14 #include "GrDrawTargetCaps.h"
15 #include "GrGpu.h"
16 
GrPathRendererChain(GrContext * context)17 GrPathRendererChain::GrPathRendererChain(GrContext* context)
18     : fInit(false)
19     , fOwner(context) {
20 }
21 
~GrPathRendererChain()22 GrPathRendererChain::~GrPathRendererChain() {
23     for (int i = 0; i < fChain.count(); ++i) {
24         fChain[i]->unref();
25     }
26 }
27 
addPathRenderer(GrPathRenderer * pr)28 GrPathRenderer* GrPathRendererChain::addPathRenderer(GrPathRenderer* pr) {
29     fChain.push_back() = pr;
30     pr->ref();
31     return pr;
32 }
33 
getPathRenderer(const GrDrawTarget * target,const GrPipelineBuilder * pipelineBuilder,const SkMatrix & viewMatrix,const SkPath & path,const GrStrokeInfo & stroke,DrawType drawType,StencilSupport * stencilSupport)34 GrPathRenderer* GrPathRendererChain::getPathRenderer(const GrDrawTarget* target,
35                                                      const GrPipelineBuilder* pipelineBuilder,
36                                                      const SkMatrix& viewMatrix,
37                                                      const SkPath& path,
38                                                      const GrStrokeInfo& stroke,
39                                                      DrawType drawType,
40                                                      StencilSupport* stencilSupport) {
41     if (!fInit) {
42         this->init();
43     }
44     bool antiAlias = (kColorAntiAlias_DrawType == drawType ||
45                       kStencilAndColorAntiAlias_DrawType == drawType);
46 
47     GR_STATIC_ASSERT(GrPathRenderer::kNoSupport_StencilSupport <
48                      GrPathRenderer::kStencilOnly_StencilSupport);
49     GR_STATIC_ASSERT(GrPathRenderer::kStencilOnly_StencilSupport <
50                      GrPathRenderer::kNoRestriction_StencilSupport);
51     GrPathRenderer::StencilSupport minStencilSupport;
52     if (kStencilOnly_DrawType == drawType) {
53         minStencilSupport = GrPathRenderer::kStencilOnly_StencilSupport;
54     } else if (kStencilAndColor_DrawType == drawType ||
55                kStencilAndColorAntiAlias_DrawType == drawType) {
56         minStencilSupport = GrPathRenderer::kNoRestriction_StencilSupport;
57     } else {
58         minStencilSupport = GrPathRenderer::kNoSupport_StencilSupport;
59     }
60 
61 
62     for (int i = 0; i < fChain.count(); ++i) {
63         if (fChain[i]->canDrawPath(target, pipelineBuilder, viewMatrix, path, stroke, antiAlias)) {
64             if (GrPathRenderer::kNoSupport_StencilSupport != minStencilSupport) {
65                 GrPathRenderer::StencilSupport support =
66                     fChain[i]->getStencilSupport(target, pipelineBuilder, path, stroke);
67                 if (support < minStencilSupport) {
68                     continue;
69                 } else if (stencilSupport) {
70                     *stencilSupport = support;
71                 }
72             }
73             return fChain[i];
74         }
75     }
76     return NULL;
77 }
78 
init()79 void GrPathRendererChain::init() {
80     SkASSERT(!fInit);
81     GrGpu* gpu = fOwner->getGpu();
82     bool twoSided = gpu->caps()->twoSidedStencilSupport();
83     bool wrapOp = gpu->caps()->stencilWrapOpsSupport();
84     GrPathRenderer::AddPathRenderers(fOwner, this);
85     this->addPathRenderer(SkNEW_ARGS(GrDefaultPathRenderer,
86                                      (twoSided, wrapOp)))->unref();
87     fInit = true;
88 }
89