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