• Home
  • History
  • Annotate
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1  /*
2   * Copyright 2014 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  #ifndef GrPathRendering_DEFINED
9  #define GrPathRendering_DEFINED
10  
11  #include "SkPath.h"
12  #include "GrPipeline.h"
13  
14  class GrGpu;
15  class GrPath;
16  class GrStencilSettings;
17  class GrStyle;
18  struct SkScalerContextEffects;
19  class SkDescriptor;
20  class SkTypeface;
21  
22  /**
23   * Abstract class wrapping HW path rendering API.
24   *
25   * The subclasses of this class use the possible HW API to render paths (as opposed to path
26   * rendering implemented in Skia on top of a "3d" HW API).
27   * The subclasses hold the global state needed to render paths, including shadow of the global HW
28   * API state. Similar to GrGpu.
29   *
30   * It is expected that the lifetimes of GrGpuXX and GrXXPathRendering are the same. The call context
31   * interface (eg.  * the concrete instance of GrGpu subclass) should be provided to the instance
32   * during construction.
33   */
34  class GrPathRendering {
35  public:
~GrPathRendering()36      virtual ~GrPathRendering() { }
37  
38      enum PathTransformType {
39          kNone_PathTransformType,        //!< []
40          kTranslateX_PathTransformType,  //!< [kMTransX]
41          kTranslateY_PathTransformType,  //!< [kMTransY]
42          kTranslate_PathTransformType,   //!< [kMTransX, kMTransY]
43          kAffine_PathTransformType,      //!< [kMScaleX, kMSkewX, kMTransX, kMSkewY, kMScaleY, kMTransY]
44  
45          kLast_PathTransformType = kAffine_PathTransformType
46      };
47  
PathTransformSize(PathTransformType type)48      static inline int PathTransformSize(PathTransformType type) {
49          switch (type) {
50              case kNone_PathTransformType:
51                  return 0;
52              case kTranslateX_PathTransformType:
53              case kTranslateY_PathTransformType:
54                  return 1;
55              case kTranslate_PathTransformType:
56                  return 2;
57              case kAffine_PathTransformType:
58                  return 6;
59  
60              default:
61                  SK_ABORT("Unknown path transform type");
62                  return 0;
63          }
64      }
65  
66      // No native support for inverse at this time
67      enum FillType {
68          /** Specifies that "inside" is computed by a non-zero sum of signed
69              edge crossings
70          */
71          kWinding_FillType,
72          /** Specifies that "inside" is computed by an odd number of edge
73              crossings
74          */
75          kEvenOdd_FillType,
76      };
77  
78      static const GrUserStencilSettings& GetStencilPassSettings(FillType);
79  
80      /**
81       * Creates a new gpu path, based on the specified path and stroke and returns it.
82       *
83       * @param SkPath    the geometry.
84       * @param GrStyle   the style applied to the path. Styles with non-dash path effects are not
85       *                  allowed.
86       * @return a new GPU path object.
87       */
88      virtual sk_sp<GrPath> createPath(const SkPath&, const GrStyle&) = 0;
89  
90      /** None of these params are optional, pointers used just to avoid making copies. */
91      struct StencilPathArgs {
StencilPathArgsStencilPathArgs92          StencilPathArgs(bool useHWAA,
93                          GrRenderTargetProxy* proxy,
94                          const SkMatrix* viewMatrix,
95                          const GrScissorState* scissor,
96                          const GrStencilSettings* stencil)
97              : fUseHWAA(useHWAA)
98              , fProxy(proxy)
99              , fViewMatrix(viewMatrix)
100              , fScissor(scissor)
101              , fStencil(stencil) {
102          }
103          bool                     fUseHWAA;
104          GrRenderTargetProxy*     fProxy;
105          const SkMatrix*          fViewMatrix;
106          const GrScissorState*    fScissor;
107          const GrStencilSettings* fStencil;
108      };
109  
110      void stencilPath(const StencilPathArgs& args, const GrPath* path);
111  
112      void drawPath(GrRenderTarget*, GrSurfaceOrigin,
113                    const GrPrimitiveProcessor& primProc,
114                    const GrPipeline& pipeline,
115                    const GrPipeline::FixedDynamicState&,
116                    const GrStencilSettings& stencilPassSettings,  // Cover pass settings in pipeline.
117                    const GrPath* path);
118  
119  protected:
GrPathRendering(GrGpu * gpu)120      GrPathRendering(GrGpu* gpu) : fGpu(gpu) { }
121  
122      virtual void onStencilPath(const StencilPathArgs&, const GrPath*) = 0;
123      virtual void onDrawPath(GrRenderTarget*, GrSurfaceOrigin,
124                              const GrPrimitiveProcessor&,
125                              const GrPipeline&,
126                              const GrPipeline::FixedDynamicState&,
127                              const GrStencilSettings&,
128                              const GrPath*) = 0;
129  
130      GrGpu* fGpu;
131  private:
132      GrPathRendering& operator=(const GrPathRendering&);
133  };
134  
135  #endif
136