blob: 73a3386c0f2fd803507ed9df4ffc40b8e0f0c269 [file] [log] [blame]
djsollen@google.com339e79f2013-09-04 17:16:00 +00001/*
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 Reed584ca892016-11-15 11:52:55 -050014/**
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.com339e79f2013-09-04 17:16:00 +000020class SkCanvasStack : public SkNWayCanvas {
21public:
22 SkCanvasStack(int width, int height);
23 virtual ~SkCanvasStack();
24
Mike Reed584ca892016-11-15 11:52:55 -050025 void pushCanvas(std::unique_ptr<SkCanvas>, const SkIPoint& origin);
mtklein36352bf2015-03-25 18:17:31 -070026 void removeAll() override;
djsollen@google.com339e79f2013-09-04 17:16:00 +000027
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 */
mtklein36352bf2015-03-25 18:17:31 -070034 void addCanvas(SkCanvas*) override { SkDEBUGFAIL("Invalid Op"); }
35 void removeCanvas(SkCanvas*) override { SkDEBUGFAIL("Invalid Op"); }
djsollen@google.com339e79f2013-09-04 17:16:00 +000036
robertphillips@google.com8f90a892014-02-28 18:19:39 +000037protected:
mtklein36352bf2015-03-25 18:17:31 -070038 void didSetMatrix(const SkMatrix&) override;
commit-bot@chromium.org44c48d02014-03-13 20:03:58 +000039
Mike Reedc1f77742016-12-09 09:00:50 -050040 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.com339e79f2013-09-04 17:16:00 +000044
45private:
46 void clipToZOrderedBounds();
47
48 struct CanvasData {
49 SkIPoint origin;
50 SkRegion requiredClip;
Mike Reed584ca892016-11-15 11:52:55 -050051 std::unique_ptr<SkCanvas> ownedCanvas;
djsollen@google.com339e79f2013-09-04 17:16:00 +000052 };
53
54 SkTArray<CanvasData> fCanvasData;
55
56 typedef SkNWayCanvas INHERITED;
57};
58
59#endif