GrFixedClip.h 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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 GrFixedClip_DEFINED
  8. #define GrFixedClip_DEFINED
  9. #include "src/gpu/GrClip.h"
  10. #include "src/gpu/GrScissorState.h"
  11. #include "src/gpu/GrWindowRectsState.h"
  12. /**
  13. * Implements GrHardClip with scissor and window rectangles.
  14. */
  15. class GrFixedClip final : public GrHardClip {
  16. public:
  17. GrFixedClip() = default;
  18. explicit GrFixedClip(const SkIRect& scissorRect) : fScissorState(scissorRect) {}
  19. const GrScissorState& scissorState() const { return fScissorState; }
  20. bool scissorEnabled() const { return fScissorState.enabled(); }
  21. const SkIRect& scissorRect() const { SkASSERT(scissorEnabled()); return fScissorState.rect(); }
  22. void disableScissor() { fScissorState.setDisabled(); }
  23. void setScissor(const SkIRect& irect) {
  24. fScissorState.set(irect);
  25. }
  26. bool SK_WARN_UNUSED_RESULT intersect(const SkIRect& irect) {
  27. return fScissorState.intersect(irect);
  28. }
  29. const GrWindowRectsState& windowRectsState() const { return fWindowRectsState; }
  30. bool hasWindowRectangles() const { return fWindowRectsState.enabled(); }
  31. void disableWindowRectangles() { fWindowRectsState.setDisabled(); }
  32. void setWindowRectangles(const GrWindowRectangles& windows, GrWindowRectsState::Mode mode) {
  33. fWindowRectsState.set(windows, mode);
  34. }
  35. bool quickContains(const SkRect&) const override;
  36. void getConservativeBounds(int w, int h, SkIRect* devResult, bool* iior) const override;
  37. bool isRRect(const SkRect& rtBounds, SkRRect* rr, GrAA*) const override;
  38. bool apply(int rtWidth, int rtHeight, GrAppliedHardClip*, SkRect*) const override;
  39. static const GrFixedClip& Disabled();
  40. private:
  41. GrScissorState fScissorState;
  42. GrWindowRectsState fWindowRectsState;
  43. };
  44. #endif