blob: 22cfc3e53847cba2ac0904e6945ff7e0cb6cfe4c [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"
Mike Reed267be7f2017-02-13 09:32:54 -050012#include "SkRegion.h"
djsollen@google.com339e79f2013-09-04 17:16:00 +000013#include "SkTArray.h"
14
Mike Reed584ca892016-11-15 11:52:55 -050015/**
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.com339e79f2013-09-04 17:16:00 +000021class SkCanvasStack : public SkNWayCanvas {
22public:
23 SkCanvasStack(int width, int height);
Brian Salomond3b65972017-03-22 12:05:03 -040024 ~SkCanvasStack() override;
djsollen@google.com339e79f2013-09-04 17:16:00 +000025
Mike Reed584ca892016-11-15 11:52:55 -050026 void pushCanvas(std::unique_ptr<SkCanvas>, const SkIPoint& origin);
mtklein36352bf2015-03-25 18:17:31 -070027 void removeAll() override;
djsollen@google.com339e79f2013-09-04 17:16:00 +000028
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 */
mtklein36352bf2015-03-25 18:17:31 -070035 void addCanvas(SkCanvas*) override { SkDEBUGFAIL("Invalid Op"); }
36 void removeCanvas(SkCanvas*) override { SkDEBUGFAIL("Invalid Op"); }
djsollen@google.com339e79f2013-09-04 17:16:00 +000037
robertphillips@google.com8f90a892014-02-28 18:19:39 +000038protected:
mtklein36352bf2015-03-25 18:17:31 -070039 void didSetMatrix(const SkMatrix&) override;
commit-bot@chromium.org44c48d02014-03-13 20:03:58 +000040
Mike Reedc1f77742016-12-09 09:00:50 -050041 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.com339e79f2013-09-04 17:16:00 +000045
46private:
47 void clipToZOrderedBounds();
48
49 struct CanvasData {
50 SkIPoint origin;
51 SkRegion requiredClip;
Mike Reed584ca892016-11-15 11:52:55 -050052 std::unique_ptr<SkCanvas> ownedCanvas;
djsollen@google.com339e79f2013-09-04 17:16:00 +000053 };
54
55 SkTArray<CanvasData> fCanvasData;
56
57 typedef SkNWayCanvas INHERITED;
58};
59
60#endif