SkClipStackDevice.h 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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 SkClipStackDevice_DEFINED
  8. #define SkClipStackDevice_DEFINED
  9. #include "src/core/SkClipStack.h"
  10. #include "src/core/SkDevice.h"
  11. class SkClipStackDevice : public SkBaseDevice {
  12. public:
  13. SkClipStackDevice(const SkImageInfo& info, const SkSurfaceProps& props)
  14. : SkBaseDevice(info, props)
  15. , fClipStack(fStorage, sizeof(fStorage))
  16. {}
  17. SkClipStack& cs() { return fClipStack; }
  18. const SkClipStack& cs() const { return fClipStack; }
  19. SkIRect devClipBounds() const;
  20. protected:
  21. void onSave() override;
  22. void onRestore() override;
  23. void onClipRect(const SkRect& rect, SkClipOp, bool aa) override;
  24. void onClipRRect(const SkRRect& rrect, SkClipOp, bool aa) override;
  25. void onClipPath(const SkPath& path, SkClipOp, bool aa) override;
  26. void onClipRegion(const SkRegion& deviceRgn, SkClipOp) override;
  27. void onSetDeviceClipRestriction(SkIRect* mutableClipRestriction) override;
  28. bool onClipIsAA() const override;
  29. void onAsRgnClip(SkRegion*) const override;
  30. ClipType onGetClipType() const override;
  31. private:
  32. enum {
  33. kPreallocCount = 16 // empirically determined, adjust as needed to reduce mallocs
  34. };
  35. intptr_t fStorage[kPreallocCount * sizeof(SkClipStack::Element) / sizeof(intptr_t)];
  36. SkClipStack fClipStack;
  37. typedef SkBaseDevice INHERITED;
  38. };
  39. #endif