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 Skottie_DEFINED 9#define Skottie_DEFINED 10 11#include "SkRefCnt.h" 12#include "SkSize.h" 13#include "SkString.h" 14#include "SkTArray.h" 15#include "SkTHash.h" 16#include "SkTypes.h" 17 18#include <memory> 19 20class SkCanvas; 21struct SkRect; 22class SkStream; 23 24namespace Json { class Value; } 25 26namespace sksg { class Scene; } 27 28namespace skottie { 29 30class ResourceProvider : public SkNoncopyable { 31public: 32 virtual ~ResourceProvider() = default; 33 34 virtual std::unique_ptr<SkStream> openStream(const char resource[]) const = 0; 35}; 36 37class Animation : public SkNoncopyable { 38public: 39 static std::unique_ptr<Animation> Make(SkStream*, const ResourceProvider&); 40 static std::unique_ptr<Animation> MakeFromFile(const char path[], 41 const ResourceProvider* = nullptr); 42 43 ~Animation(); 44 45 void render(SkCanvas*, const SkRect* dst = nullptr) const; 46 47 void animationTick(SkMSec); 48 49 const SkString& version() const { return fVersion; } 50 const SkSize& size() const { return fSize; } 51 SkScalar frameRate() const { return fFrameRate; } 52 SkScalar inPoint() const { return fInPoint; } 53 SkScalar outPoint() const { return fOutPoint; } 54 55 void setShowInval(bool show); 56 57private: 58 Animation(const ResourceProvider&, 59 SkString ver, const SkSize& size, SkScalar fps, 60 const Json::Value&); 61 62 SkString fVersion; 63 SkSize fSize; 64 SkScalar fFrameRate, 65 fInPoint, 66 fOutPoint; 67 68 std::unique_ptr<sksg::Scene> fScene; 69 70 typedef SkNoncopyable INHERITED; 71}; 72 73} // namespace skottie 74 75#endif // Skottie_DEFINED 76