djsollen@google.com | 339e79f | 2013-09-04 17:16:00 +0000 | [diff] [blame] | 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 | |
| 8 | #ifndef SkCanvasStack_DEFINED |
| 9 | #define SkCanvasStack_DEFINED |
| 10 | |
| 11 | #include "SkNWayCanvas.h" |
| 12 | #include "SkTArray.h" |
| 13 | |
Mike Reed | 584ca89 | 2016-11-15 11:52:55 -0500 | [diff] [blame] | 14 | /** |
| 15 | * Like NWayCanvas, in that it forwards all canvas methods to each sub-canvas that is "pushed". |
| 16 | * |
| 17 | * Unlike NWayCanvas, this takes ownership of each subcanvas, and deletes them when this canvas |
| 18 | * is deleted. |
| 19 | */ |
djsollen@google.com | 339e79f | 2013-09-04 17:16:00 +0000 | [diff] [blame] | 20 | class SkCanvasStack : public SkNWayCanvas { |
| 21 | public: |
| 22 | SkCanvasStack(int width, int height); |
| 23 | virtual ~SkCanvasStack(); |
| 24 | |
Mike Reed | 584ca89 | 2016-11-15 11:52:55 -0500 | [diff] [blame] | 25 | void pushCanvas(std::unique_ptr<SkCanvas>, const SkIPoint& origin); |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 26 | void removeAll() override; |
djsollen@google.com | 339e79f | 2013-09-04 17:16:00 +0000 | [diff] [blame] | 27 | |
| 28 | /* |
| 29 | * The following add/remove canvas methods are overrides from SkNWayCanvas |
| 30 | * that do not make sense in the context of our CanvasStack, but since we |
| 31 | * can share most of the other implementation of NWay we override those |
| 32 | * methods to be no-ops. |
| 33 | */ |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 34 | void addCanvas(SkCanvas*) override { SkDEBUGFAIL("Invalid Op"); } |
| 35 | void removeCanvas(SkCanvas*) override { SkDEBUGFAIL("Invalid Op"); } |
djsollen@google.com | 339e79f | 2013-09-04 17:16:00 +0000 | [diff] [blame] | 36 | |
robertphillips@google.com | 8f90a89 | 2014-02-28 18:19:39 +0000 | [diff] [blame] | 37 | protected: |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 38 | void didSetMatrix(const SkMatrix&) override; |
commit-bot@chromium.org | 44c48d0 | 2014-03-13 20:03:58 +0000 | [diff] [blame] | 39 | |
Mike Reed | c1f7774 | 2016-12-09 09:00:50 -0500 | [diff] [blame] | 40 | void onClipRect(const SkRect&, SkClipOp, ClipEdgeStyle) override; |
| 41 | void onClipRRect(const SkRRect&, SkClipOp, ClipEdgeStyle) override; |
| 42 | void onClipPath(const SkPath&, SkClipOp, ClipEdgeStyle) override; |
| 43 | void onClipRegion(const SkRegion&, SkClipOp) override; |
djsollen@google.com | 339e79f | 2013-09-04 17:16:00 +0000 | [diff] [blame] | 44 | |
| 45 | private: |
| 46 | void clipToZOrderedBounds(); |
| 47 | |
| 48 | struct CanvasData { |
| 49 | SkIPoint origin; |
| 50 | SkRegion requiredClip; |
Mike Reed | 584ca89 | 2016-11-15 11:52:55 -0500 | [diff] [blame] | 51 | std::unique_ptr<SkCanvas> ownedCanvas; |
djsollen@google.com | 339e79f | 2013-09-04 17:16:00 +0000 | [diff] [blame] | 52 | }; |
| 53 | |
| 54 | SkTArray<CanvasData> fCanvasData; |
| 55 | |
| 56 | typedef SkNWayCanvas INHERITED; |
| 57 | }; |
| 58 | |
| 59 | #endif |