SkCanvasStack.h 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /*
  2. * Copyright 2013 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 SkCanvasStack_DEFINED
  8. #define SkCanvasStack_DEFINED
  9. #include "include/core/SkRegion.h"
  10. #include "include/private/SkTArray.h"
  11. #include "include/utils/SkNWayCanvas.h"
  12. /**
  13. * Like NWayCanvas, in that it forwards all canvas methods to each sub-canvas that is "pushed".
  14. *
  15. * Unlike NWayCanvas, this takes ownership of each subcanvas, and deletes them when this canvas
  16. * is deleted.
  17. */
  18. class SkCanvasStack : public SkNWayCanvas {
  19. public:
  20. SkCanvasStack(int width, int height);
  21. ~SkCanvasStack() override;
  22. void pushCanvas(std::unique_ptr<SkCanvas>, const SkIPoint& origin);
  23. void removeAll() override;
  24. /*
  25. * The following add/remove canvas methods are overrides from SkNWayCanvas
  26. * that do not make sense in the context of our CanvasStack, but since we
  27. * can share most of the other implementation of NWay we override those
  28. * methods to be no-ops.
  29. */
  30. void addCanvas(SkCanvas*) override { SkDEBUGFAIL("Invalid Op"); }
  31. void removeCanvas(SkCanvas*) override { SkDEBUGFAIL("Invalid Op"); }
  32. protected:
  33. void didSetMatrix(const SkMatrix&) override;
  34. void onClipRect(const SkRect&, SkClipOp, ClipEdgeStyle) override;
  35. void onClipRRect(const SkRRect&, SkClipOp, ClipEdgeStyle) override;
  36. void onClipPath(const SkPath&, SkClipOp, ClipEdgeStyle) override;
  37. void onClipRegion(const SkRegion&, SkClipOp) override;
  38. private:
  39. void clipToZOrderedBounds();
  40. struct CanvasData {
  41. SkIPoint origin;
  42. SkRegion requiredClip;
  43. std::unique_ptr<SkCanvas> ownedCanvas;
  44. };
  45. SkTArray<CanvasData> fCanvasData;
  46. typedef SkNWayCanvas INHERITED;
  47. };
  48. #endif