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 "include/core/SkRegion.h"
12#include "include/private/SkTArray.h"
13#include "include/utils/SkNWayCanvas.h"
14
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 */
21class SkCanvasStack : public SkNWayCanvas {
22public:
23 SkCanvasStack(int width, int height);
24 ~SkCanvasStack() override;
25
26 void pushCanvas(std::unique_ptr<SkCanvas>, const SkIPoint& origin);
27 void removeAll() override;
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 */
35 void addCanvas(SkCanvas*) override { SkDEBUGFAIL("Invalid Op"); }
36 void removeCanvas(SkCanvas*) override { SkDEBUGFAIL("Invalid Op"); }
37
38protected:
39 void didSetMatrix(const SkMatrix&) override;
40
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 onClipShader(sk_sp<SkShader>, SkClipOp) override;
45 void onClipRegion(const SkRegion&, SkClipOp) override;
46
47private:
48 void clipToZOrderedBounds();
49
50 struct CanvasData {
51 SkIPoint origin;
52 SkRegion requiredClip;
53 std::unique_ptr<SkCanvas> ownedCanvas;
54 };
55
56 SkTArray<CanvasData> fCanvasData;
57
58 typedef SkNWayCanvas INHERITED;
59};
60
61#endif
62