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 "SkRegion.h" 13 #include "SkTArray.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 */ 21 class SkCanvasStack : public SkNWayCanvas { 22 public: 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 */ addCanvas(SkCanvas *)35 void addCanvas(SkCanvas*) override { SkDEBUGFAIL("Invalid Op"); } removeCanvas(SkCanvas *)36 void removeCanvas(SkCanvas*) override { SkDEBUGFAIL("Invalid Op"); } 37 38 protected: 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 onClipRegion(const SkRegion&, SkClipOp) override; 45 46 private: 47 void clipToZOrderedBounds(); 48 49 struct CanvasData { 50 SkIPoint origin; 51 SkRegion requiredClip; 52 std::unique_ptr<SkCanvas> ownedCanvas; 53 }; 54 55 SkTArray<CanvasData> fCanvasData; 56 57 typedef SkNWayCanvas INHERITED; 58 }; 59 60 #endif 61