GrClipStackClip.h 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. #include "src/core/SkClipStack.h"
  10. #include "src/gpu/GrClip.h"
  11. #include "src/gpu/GrReducedClip.h"
  12. class GrPathRenderer;
  13. class GrTextureProxy;
  14. /**
  15. * GrClipStackClip can apply a generic SkClipStack to the draw state. It may need to generate an
  16. * 8-bit alpha clip mask and/or modify the stencil buffer during apply().
  17. */
  18. class GrClipStackClip final : public GrClip {
  19. public:
  20. GrClipStackClip(const SkClipStack* stack = nullptr) { this->reset(stack); }
  21. void reset(const SkClipStack* stack) { fStack = stack; }
  22. bool quickContains(const SkRect&) const final;
  23. bool quickContains(const SkRRect&) const final;
  24. void getConservativeBounds(int width, int height, SkIRect* devResult,
  25. bool* isIntersectionOfRects) const final;
  26. bool apply(GrRecordingContext*, GrRenderTargetContext*, bool useHWAA,
  27. bool hasUserStencilSettings, GrAppliedClip* out, SkRect* bounds) const final;
  28. bool isRRect(const SkRect& rtBounds, SkRRect* rr, GrAA* aa) const override;
  29. sk_sp<GrTextureProxy> testingOnly_createClipMask(GrContext*) const;
  30. static const char kMaskTestTag[];
  31. private:
  32. static bool PathNeedsSWRenderer(GrRecordingContext* context,
  33. const SkIRect& scissorRect,
  34. bool hasUserStencilSettings,
  35. const GrRenderTargetContext*,
  36. const SkMatrix& viewMatrix,
  37. const SkClipStack::Element* element,
  38. GrPathRenderer** prOut,
  39. bool needsStencil);
  40. bool applyClipMask(GrRecordingContext*, GrRenderTargetContext*, const GrReducedClip&,
  41. bool hasUserStencilSettings, GrAppliedClip*) const;
  42. // Creates an alpha mask of the clip. The mask is a rasterization of elements through the
  43. // rect specified by clipSpaceIBounds.
  44. sk_sp<GrTextureProxy> createAlphaClipMask(GrRecordingContext*, const GrReducedClip&) const;
  45. // Similar to createAlphaClipMask but it rasterizes in SW and uploads to the result texture.
  46. sk_sp<GrTextureProxy> createSoftwareClipMask(GrRecordingContext*, const GrReducedClip&,
  47. GrRenderTargetContext*) const;
  48. static bool UseSWOnlyPath(GrRecordingContext*,
  49. bool hasUserStencilSettings,
  50. const GrRenderTargetContext*,
  51. const GrReducedClip&);
  52. const SkClipStack* fStack;
  53. };
  54. #endif // GrClipStackClip_DEFINED