1 /* 2 * Copyright 2012 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 GrSoftwarePathRenderer_DEFINED 9 #define GrSoftwarePathRenderer_DEFINED 10 11 #include "src/gpu/GrPathRenderer.h" 12 #include "src/gpu/GrSurfaceProxyView.h" 13 14 class GrProxyProvider; 15 16 /** 17 * This class uses the software side to render a path to an SkBitmap and 18 * then uploads the result to the gpu 19 */ 20 class GrSoftwarePathRenderer : public GrPathRenderer { 21 public: name()22 const char* name() const final { return "SW"; } 23 GrSoftwarePathRenderer(GrProxyProvider * proxyProvider,bool allowCaching)24 GrSoftwarePathRenderer(GrProxyProvider* proxyProvider, bool allowCaching) 25 : fProxyProvider(proxyProvider) 26 , fAllowCaching(allowCaching) { 27 } 28 29 static bool GetShapeAndClipBounds(GrRenderTargetContext*, 30 const GrClip* clip, 31 const GrStyledShape& shape, 32 const SkMatrix& matrix, 33 SkIRect* unclippedDevShapeBounds, 34 SkIRect* clippedDevShapeBounds, 35 SkIRect* devClipBounds); 36 37 private: 38 static void DrawNonAARect(GrRenderTargetContext* renderTargetContext, 39 GrPaint&& paint, 40 const GrUserStencilSettings& userStencilSettings, 41 const GrClip* clip, 42 const SkMatrix& viewMatrix, 43 const SkRect& rect, 44 const SkMatrix& localMatrix); 45 static void DrawAroundInvPath(GrRenderTargetContext* renderTargetContext, 46 GrPaint&& paint, 47 const GrUserStencilSettings& userStencilSettings, 48 const GrClip* clip, 49 const SkMatrix& viewMatrix, 50 const SkIRect& devClipBounds, 51 const SkIRect& devPathBounds); 52 53 // This utility draws a path mask using a provided paint. The rectangle is drawn in device 54 // space. The 'viewMatrix' will be used to ensure the correct local coords are provided to 55 // any fragment processors in the paint. 56 static void DrawToTargetWithShapeMask(GrSurfaceProxyView, 57 GrRenderTargetContext* renderTargetContext, 58 GrPaint&& paint, 59 const GrUserStencilSettings& userStencilSettings, 60 const GrClip* clip, 61 const SkMatrix& viewMatrix, 62 const SkIPoint& textureOriginInDeviceSpace, 63 const SkIRect& deviceSpaceRectToDraw); 64 onGetStencilSupport(const GrStyledShape &)65 StencilSupport onGetStencilSupport(const GrStyledShape&) const override { 66 return GrPathRenderer::kNoSupport_StencilSupport; 67 } 68 69 CanDrawPath onCanDrawPath(const CanDrawPathArgs&) const override; 70 71 bool onDrawPath(const DrawPathArgs&) override; 72 73 private: 74 GrProxyProvider* fProxyProvider; 75 bool fAllowCaching; 76 77 using INHERITED = GrPathRenderer; 78 }; 79 80 #endif 81