GrStencilClip.h 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. /*
  2. * Copyright 2017 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 GrStencilClip_DEFINED
  8. #define GrStencilClip_DEFINED
  9. #include "src/gpu/GrAppliedClip.h"
  10. #include "src/gpu/GrFixedClip.h"
  11. /**
  12. * Implements GrHardClip with the currently-existing stencil buffer contents and GrFixedClip.
  13. */
  14. class GrStencilClip final : public GrHardClip {
  15. public:
  16. GrStencilClip(uint32_t stencilStackID = SK_InvalidGenID) : fStencilStackID(stencilStackID) {}
  17. explicit GrStencilClip(const SkIRect& scissorRect, uint32_t stencilStackID = SK_InvalidGenID)
  18. : fFixedClip(scissorRect)
  19. , fStencilStackID(stencilStackID) {
  20. }
  21. const GrFixedClip& fixedClip() const { return fFixedClip; }
  22. GrFixedClip& fixedClip() { return fFixedClip; }
  23. bool stencilStackID() const { return fStencilStackID; }
  24. bool hasStencilClip() const { return SK_InvalidGenID != fStencilStackID; }
  25. void setStencilClip(uint32_t stencilStackID) { fStencilStackID = stencilStackID; }
  26. bool quickContains(const SkRect& rect) const override {
  27. return !this->hasStencilClip() && fFixedClip.quickContains(rect);
  28. }
  29. void getConservativeBounds(int width, int height, SkIRect* bounds, bool* iior) const override {
  30. fFixedClip.getConservativeBounds(width, height, bounds, iior);
  31. }
  32. bool isRRect(const SkRect& rtBounds, SkRRect* rr, GrAA* aa) const override {
  33. return !this->hasStencilClip() && fFixedClip.isRRect(rtBounds, rr, aa);
  34. }
  35. bool apply(int rtWidth, int rtHeight, GrAppliedHardClip* out, SkRect* bounds) const override {
  36. if (!fFixedClip.apply(rtWidth, rtHeight, out, bounds)) {
  37. return false;
  38. }
  39. if (this->hasStencilClip()) {
  40. out->addStencilClip(fStencilStackID);
  41. }
  42. return true;
  43. }
  44. private:
  45. GrFixedClip fFixedClip;
  46. uint32_t fStencilStackID;
  47. typedef GrClip INHERITED;
  48. };
  49. #endif