1 /* 2 * Copyright 2017 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 SkSGGroup_DEFINED 9 #define SkSGGroup_DEFINED 10 11 #include "modules/sksg/include/SkSGRenderNode.h" 12 13 #include <vector> 14 15 namespace sksg { 16 17 /** 18 * Concrete node, grouping together multiple descendants. 19 */ 20 class Group : public RenderNode { 21 public: Make()22 static sk_sp<Group> Make() { 23 return sk_sp<Group>(new Group(std::vector<sk_sp<RenderNode>>())); 24 } 25 Make(std::vector<sk_sp<RenderNode>> children)26 static sk_sp<Group> Make(std::vector<sk_sp<RenderNode>> children) { 27 return sk_sp<Group>(new Group(std::move(children))); 28 } 29 30 void addChild(sk_sp<RenderNode>); 31 void removeChild(const sk_sp<RenderNode>&); 32 size()33 size_t size() const { return fChildren.size(); } empty()34 bool empty() const { return fChildren.empty(); } 35 void clear(); 36 37 protected: 38 Group(); 39 explicit Group(std::vector<sk_sp<RenderNode>>); 40 ~Group() override; 41 42 void onRender(SkCanvas*, const RenderContext*) const override; 43 const RenderNode* onNodeAt(const SkPoint&) const override; 44 45 SkRect onRevalidate(InvalidationController*, const SkMatrix&) override; 46 47 private: 48 std::vector<sk_sp<RenderNode>> fChildren; 49 bool fRequiresIsolation = true; 50 51 using INHERITED = RenderNode; 52 }; 53 54 } // namespace sksg 55 56 #endif // SkSGGroup_DEFINED 57