2017-12-30 17:27:00 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2017 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
2018-01-16 22:04:30 +00:00
|
|
|
#ifndef Skottie_DEFINED
|
|
|
|
#define Skottie_DEFINED
|
2017-12-30 17:27:00 +00:00
|
|
|
|
|
|
|
#include "SkRefCnt.h"
|
|
|
|
#include "SkSize.h"
|
|
|
|
#include "SkString.h"
|
|
|
|
#include "SkTypes.h"
|
|
|
|
|
|
|
|
#include <memory>
|
|
|
|
|
|
|
|
class SkCanvas;
|
2018-08-06 18:13:04 +00:00
|
|
|
class SkData;
|
2018-01-08 13:25:27 +00:00
|
|
|
struct SkRect;
|
2017-12-30 17:27:00 +00:00
|
|
|
class SkStream;
|
|
|
|
|
2018-06-14 20:16:01 +00:00
|
|
|
namespace skjson { class ObjectValue; }
|
2018-01-22 17:57:06 +00:00
|
|
|
namespace sksg { class Scene; }
|
2017-12-30 17:27:00 +00:00
|
|
|
|
2018-01-16 22:04:30 +00:00
|
|
|
namespace skottie {
|
2017-12-30 17:27:00 +00:00
|
|
|
|
2018-07-16 21:44:06 +00:00
|
|
|
class SK_API ResourceProvider {
|
2018-01-08 17:51:12 +00:00
|
|
|
public:
|
2018-07-16 21:44:06 +00:00
|
|
|
ResourceProvider() = default;
|
2018-01-08 17:51:12 +00:00
|
|
|
virtual ~ResourceProvider() = default;
|
2018-07-16 21:44:06 +00:00
|
|
|
ResourceProvider(const ResourceProvider&) = delete;
|
|
|
|
ResourceProvider& operator=(const ResourceProvider&) = delete;
|
2018-01-08 17:51:12 +00:00
|
|
|
|
2018-08-06 18:13:04 +00:00
|
|
|
virtual sk_sp<SkData> load(const char resource_path[], const char resource_name[]) const = 0;
|
2018-01-08 17:51:12 +00:00
|
|
|
};
|
|
|
|
|
2018-05-23 20:35:56 +00:00
|
|
|
class SK_API Animation : public SkRefCnt {
|
2017-12-30 17:27:00 +00:00
|
|
|
public:
|
2018-04-30 14:32:18 +00:00
|
|
|
struct Stats {
|
|
|
|
float fTotalLoadTimeMS,
|
|
|
|
fJsonParseTimeMS,
|
|
|
|
fSceneParseTimeMS;
|
|
|
|
size_t fJsonSize,
|
|
|
|
fAnimatorCount;
|
|
|
|
};
|
|
|
|
|
2018-08-06 15:07:05 +00:00
|
|
|
static sk_sp<Animation> Make(const char* data, size_t length,
|
|
|
|
const ResourceProvider* = nullptr, Stats* = nullptr);
|
2018-05-31 16:17:55 +00:00
|
|
|
static sk_sp<Animation> Make(SkStream*, const ResourceProvider* = nullptr, Stats* = nullptr);
|
2018-04-30 14:32:18 +00:00
|
|
|
static sk_sp<Animation> MakeFromFile(const char path[], const ResourceProvider* = nullptr,
|
|
|
|
Stats* = nullptr);
|
2017-12-30 17:27:00 +00:00
|
|
|
|
2018-02-23 16:10:22 +00:00
|
|
|
~Animation() override;
|
2017-12-30 17:27:00 +00:00
|
|
|
|
2018-05-29 17:46:54 +00:00
|
|
|
/**
|
|
|
|
* Draws the current animation frame.
|
|
|
|
*
|
|
|
|
* @param canvas destination canvas
|
|
|
|
* @param dst optional destination rect
|
|
|
|
*/
|
|
|
|
void render(SkCanvas* canvas, const SkRect* dst = nullptr) const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Updates the animation state for |t|.
|
|
|
|
*
|
2018-05-31 20:45:29 +00:00
|
|
|
* @param t normalized [0..1] frame selector (0 -> first frame, 1 -> final frame)
|
|
|
|
*
|
2018-05-29 17:46:54 +00:00
|
|
|
*/
|
|
|
|
void seek(SkScalar t);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the animation duration in seconds.
|
|
|
|
*/
|
|
|
|
SkScalar duration() const {
|
|
|
|
return (fOutPoint - fInPoint) / fFrameRate;
|
|
|
|
}
|
2017-12-30 17:27:00 +00:00
|
|
|
|
2017-12-31 16:08:42 +00:00
|
|
|
const SkString& version() const { return fVersion; }
|
|
|
|
const SkSize& size() const { return fSize; }
|
2017-12-30 17:27:00 +00:00
|
|
|
|
2018-01-22 17:57:06 +00:00
|
|
|
void setShowInval(bool show);
|
2017-12-30 17:27:00 +00:00
|
|
|
|
|
|
|
private:
|
2018-05-04 19:10:54 +00:00
|
|
|
Animation(const ResourceProvider&, SkString ver, const SkSize& size, SkScalar fps,
|
2018-08-20 14:02:12 +00:00
|
|
|
SkScalar in, SkScalar out, const skjson::ObjectValue&, Stats*);
|
2017-12-30 17:27:00 +00:00
|
|
|
|
2018-01-22 17:57:06 +00:00
|
|
|
SkString fVersion;
|
|
|
|
SkSize fSize;
|
|
|
|
SkScalar fFrameRate,
|
|
|
|
fInPoint,
|
|
|
|
fOutPoint;
|
2017-12-30 17:27:00 +00:00
|
|
|
|
2018-01-22 17:57:06 +00:00
|
|
|
std::unique_ptr<sksg::Scene> fScene;
|
2017-12-30 17:27:00 +00:00
|
|
|
|
2018-02-23 16:10:22 +00:00
|
|
|
typedef SkRefCnt INHERITED;
|
2017-12-30 17:27:00 +00:00
|
|
|
};
|
|
|
|
|
2018-01-16 22:04:30 +00:00
|
|
|
} // namespace skottie
|
2017-12-30 17:27:00 +00:00
|
|
|
|
2018-01-16 22:04:30 +00:00
|
|
|
#endif // Skottie_DEFINED
|