| 1 | /* |
| 2 | * Copyright 2019 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 SkottieMotionBlurEffect_DEFINED |
| 9 | #define SkottieMotionBlurEffect_DEFINED |
| 10 | |
| 11 | #include "modules/sksg/include/SkSGRenderNode.h" |
| 12 | #include "modules/sksg/include/SkSGScene.h" |
| 13 | |
| 14 | namespace skottie { |
| 15 | namespace internal { |
| 16 | |
| 17 | class Animator; |
| 18 | |
| 19 | class MotionBlurEffect final : public sksg::CustomRenderNode { |
| 20 | public: |
| 21 | static sk_sp<MotionBlurEffect> Make(sk_sp<Animator> animator, |
| 22 | sk_sp<sksg::RenderNode> child, |
| 23 | size_t samples_per_frame, |
| 24 | float shutter_angle, float shutter_phase); |
| 25 | |
| 26 | SG_ATTRIBUTE(T, float, fT) |
| 27 | |
| 28 | private: |
| 29 | class AutoInvalBlocker; |
| 30 | |
| 31 | const RenderNode* onNodeAt(const SkPoint&) const override; |
| 32 | |
| 33 | SkRect onRevalidate(sksg::InvalidationController* ic, const SkMatrix& ctm) override; |
| 34 | |
| 35 | void onRender(SkCanvas* canvas, const RenderContext* ctx) const override; |
| 36 | |
| 37 | void renderToRaster8888Pow2Samples(SkCanvas* canvas, const RenderContext* ctx) const; |
| 38 | |
| 39 | SkRect seekToSample(size_t sample_idx, const SkMatrix& ctm) const; |
| 40 | |
| 41 | MotionBlurEffect(sk_sp<Animator> animator, |
| 42 | sk_sp<sksg::RenderNode> child, |
| 43 | size_t sample_count, float phase, float dt); |
| 44 | |
| 45 | const sk_sp<Animator> fAnimator; |
| 46 | const size_t fSampleCount; |
| 47 | const float fPhase, |
| 48 | fDT; |
| 49 | |
| 50 | float fT = 0; |
| 51 | size_t fVisibleSampleCount = 0; |
| 52 | |
| 53 | using INHERITED = sksg::CustomRenderNode; |
| 54 | }; |
| 55 | |
| 56 | } // namespace internal |
| 57 | } // namespace skottie |
| 58 | |
| 59 | #endif // SkottieMotionBlurEffect_DEFINED |
| 60 | |