1 /* 2 * Copyright 2016 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 #ifndef GrClipStackClip_DEFINED 8 #define GrClipStackClip_DEFINED 9 10 #include "src/core/SkClipStack.h" 11 #include "src/gpu/GrClip.h" 12 #include "src/gpu/GrReducedClip.h" 13 14 class GrPathRenderer; 15 class GrTextureProxy; 16 17 /** 18 * GrClipStackClip can apply a generic SkClipStack to the draw state. It may need to generate an 19 * 8-bit alpha clip mask and/or modify the stencil buffer during apply(). 20 */ 21 class GrClipStackClip final : public GrClip { 22 public: 23 GrClipStackClip(const SkISize& dimensions, 24 const SkClipStack* stack = nullptr, 25 const SkMatrixProvider* matrixProvider = nullptr) fDeviceSize(dimensions)26 : fDeviceSize(dimensions) 27 , fStack(stack) 28 , fMatrixProvider(matrixProvider) {} 29 30 SkIRect getConservativeBounds() const final; 31 Effect apply(GrRecordingContext*, GrSurfaceDrawContext*, GrAAType aaType, 32 bool hasUserStencilSettings, GrAppliedClip* out, SkRect* bounds) const final; 33 PreClipResult preApply(const SkRect& drawBounds, GrAA aa) const final; 34 35 sk_sp<GrTextureProxy> testingOnly_createClipMask(GrRecordingContext*) const; 36 static const char kMaskTestTag[]; 37 38 private: 39 static bool PathNeedsSWRenderer(GrRecordingContext* context, 40 const SkIRect& scissorRect, 41 bool hasUserStencilSettings, 42 const GrSurfaceDrawContext*, 43 const SkMatrix& viewMatrix, 44 const SkClipStack::Element* element, 45 bool needsStencil); 46 47 bool applyClipMask(GrRecordingContext*, GrSurfaceDrawContext*, const GrReducedClip&, 48 bool hasUserStencilSettings, GrAppliedClip*) const; 49 50 // Creates an alpha mask of the clip. The mask is a rasterization of elements through the 51 // rect specified by clipSpaceIBounds. 52 GrSurfaceProxyView createAlphaClipMask(GrRecordingContext*, const GrReducedClip&) const; 53 54 // Similar to createAlphaClipMask but it rasterizes in SW and uploads to the result texture. 55 GrSurfaceProxyView createSoftwareClipMask(GrRecordingContext*, const GrReducedClip&, 56 GrSurfaceDrawContext*) const; 57 58 static bool UseSWOnlyPath(GrRecordingContext*, 59 bool hasUserStencilSettings, 60 const GrSurfaceDrawContext*, 61 const GrReducedClip&); 62 63 // SkClipStack does not track device bounds explicitly, but it will refine these device bounds 64 // as clip elements are added to the stack. 65 SkISize fDeviceSize; 66 const SkClipStack* fStack; 67 const SkMatrixProvider* fMatrixProvider; // for applying clip shaders 68 }; 69 70 #endif // GrClipStackClip_DEFINED 71