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 "include/core/SkPath.h" 12 #include "src/gpu/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 } 63 } 64 65 // No native support for inverse at this time 66 enum FillType { 67 /** Specifies that "inside" is computed by a non-zero sum of signed 68 edge crossings 69 */ 70 kWinding_FillType, 71 /** Specifies that "inside" is computed by an odd number of edge 72 crossings 73 */ 74 kEvenOdd_FillType, 75 }; 76 77 static const GrUserStencilSettings& GetStencilPassSettings(FillType); 78 79 /** 80 * Creates a new gpu path, based on the specified path and stroke and returns it. 81 * 82 * @param SkPath the geometry. 83 * @param GrStyle the style applied to the path. Styles with non-dash path effects are not 84 * allowed. 85 * @return a new GPU path object. 86 */ 87 virtual sk_sp<GrPath> createPath(const SkPath&, const GrStyle&) = 0; 88 89 /** None of these params are optional, pointers used just to avoid making copies. */ 90 struct StencilPathArgs { StencilPathArgsStencilPathArgs91 StencilPathArgs(bool useHWAA, 92 GrRenderTargetProxy* proxy, 93 const SkMatrix* viewMatrix, 94 const GrScissorState* scissor, 95 const GrStencilSettings* stencil) 96 : fUseHWAA(useHWAA) 97 , fProxy(proxy) 98 , fViewMatrix(viewMatrix) 99 , fScissor(scissor) 100 , fStencil(stencil) { 101 } 102 bool fUseHWAA; 103 GrRenderTargetProxy* fProxy; 104 const SkMatrix* fViewMatrix; 105 const GrScissorState* fScissor; 106 const GrStencilSettings* fStencil; 107 }; 108 109 void stencilPath(const StencilPathArgs& args, const GrPath* path); 110 111 void drawPath(GrRenderTarget*, GrSurfaceOrigin, 112 const GrPrimitiveProcessor& primProc, 113 const GrPipeline& pipeline, 114 const GrPipeline::FixedDynamicState&, 115 const GrStencilSettings& stencilPassSettings, // Cover pass settings in pipeline. 116 const GrPath* path); 117 118 protected: GrPathRendering(GrGpu * gpu)119 GrPathRendering(GrGpu* gpu) : fGpu(gpu) { } 120 121 virtual void onStencilPath(const StencilPathArgs&, const GrPath*) = 0; 122 virtual void onDrawPath(GrRenderTarget*, GrSurfaceOrigin, 123 const GrPrimitiveProcessor&, 124 const GrPipeline&, 125 const GrPipeline::FixedDynamicState&, 126 const GrStencilSettings&, 127 const GrPath*) = 0; 128 129 GrGpu* fGpu; 130 private: 131 GrPathRendering& operator=(const GrPathRendering&); 132 }; 133 134 #endif 135