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