GrScissorState.h 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  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 GrScissorState_DEFINED
  8. #define GrScissorState_DEFINED
  9. #include "include/core/SkRect.h"
  10. class GrScissorState {
  11. public:
  12. GrScissorState() : fEnabled(false) {}
  13. GrScissorState(const SkIRect& rect) : fEnabled(true), fRect(rect) {}
  14. void setDisabled() { fEnabled = false; }
  15. void set(const SkIRect& rect) { fRect = rect; fEnabled = true; }
  16. bool SK_WARN_UNUSED_RESULT intersect(const SkIRect& rect) {
  17. if (!fEnabled) {
  18. this->set(rect);
  19. return true;
  20. }
  21. return fRect.intersect(rect);
  22. }
  23. bool operator==(const GrScissorState& other) const {
  24. return fEnabled == other.fEnabled &&
  25. (false == fEnabled || fRect == other.fRect);
  26. }
  27. bool operator!=(const GrScissorState& other) const { return !(*this == other); }
  28. bool enabled() const { return fEnabled; }
  29. const SkIRect& rect() const { return fRect; }
  30. private:
  31. bool fEnabled;
  32. SkIRect fRect;
  33. };
  34. #endif