1 /* 2 * Copyright 2020 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 SkottieAdapter_DEFINED 9 #define SkottieAdapter_DEFINED 10 11 #include "modules/skottie/src/animator/Animator.h" 12 13 namespace skottie { 14 namespace internal { 15 16 template <typename AdapterT, typename T> 17 class DiscardableAdapterBase : public AnimatablePropertyContainer { 18 public: 19 template <typename... Args> Make(Args &&...args)20 static sk_sp<AdapterT> Make(Args&&... args) { 21 sk_sp<AdapterT> adapter(new AdapterT(std::forward<Args>(args)...)); 22 adapter->shrink_to_fit(); 23 return adapter; 24 } 25 node()26 const sk_sp<T>& node() const { return fNode; } 27 28 protected: DiscardableAdapterBase()29 DiscardableAdapterBase() 30 : fNode(T::Make()) {} 31 DiscardableAdapterBase(sk_sp<T> node)32 explicit DiscardableAdapterBase(sk_sp<T> node) 33 : fNode(std::move(node)) {} 34 35 private: 36 const sk_sp<T> fNode; 37 }; 38 39 } // namespace internal 40 } // namespace skottie 41 42 #endif // SkottieAdapter_DEFINED 43