File: animator.h

package info (click to toggle)
chromium 139.0.7258.127-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 6,122,068 kB
  • sloc: cpp: 35,100,771; ansic: 7,163,530; javascript: 4,103,002; python: 1,436,920; asm: 946,517; xml: 746,709; pascal: 187,653; perl: 88,691; sh: 88,436; objc: 79,953; sql: 51,488; cs: 44,583; fortran: 24,137; makefile: 22,147; tcl: 15,277; php: 13,980; yacc: 8,984; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (85 lines) | stat: -rw-r--r-- 3,436 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
// Copyright 2017 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef THIRD_PARTY_BLINK_RENDERER_MODULES_ANIMATIONWORKLET_ANIMATOR_H_
#define THIRD_PARTY_BLINK_RENDERER_MODULES_ANIMATIONWORKLET_ANIMATOR_H_

#include "third_party/blink/renderer/core/animation/timing.h"
#include "third_party/blink/renderer/modules/animationworklet/worklet_animation_effect_timings.h"
#include "third_party/blink/renderer/modules/animationworklet/worklet_animation_options.h"
#include "third_party/blink/renderer/modules/animationworklet/worklet_group_effect.h"
#include "third_party/blink/renderer/platform/bindings/name_client.h"
#include "third_party/blink/renderer/platform/bindings/trace_wrapper_v8_reference.h"
#include "third_party/blink/renderer/platform/graphics/animation_worklet_mutators_state.h"
#include "third_party/blink/renderer/platform/heap/garbage_collected.h"

#include "v8/include/v8.h"

namespace blink {

class AnimatorDefinition;

// Represents an animator instance. It owns the underlying |v8::Object| for the
// instance and knows how to invoke the |animate| function on it.
// See also |AnimationWorkletGlobalScope::CreateInstance|.
class Animator final : public GarbageCollected<Animator>, public NameClient {
 public:
  Animator(v8::Isolate*,
           AnimatorDefinition*,
           v8::Local<v8::Value> instance,
           const String& name,
           WorkletAnimationOptions options,
           const Vector<std::optional<base::TimeDelta>>& local_times,
           const Vector<Timing>& timings,
           const Vector<Timing::NormalizedTiming>& normalized_timings);
  ~Animator() final;
  void Trace(Visitor*) const;
  const char* GetHumanReadableName() const override { return "Animator"; }

  // Returns true if it successfully invoked animate callback in JS. It receives
  // latest state coming from |AnimationHost| as input and fills
  // the output state with new updates.
  bool Animate(v8::Isolate* isolate,
               double current_time,
               AnimationWorkletDispatcherOutput::AnimationState* output);
  v8::Local<v8::Value> State(v8::Isolate*, ExceptionState&);

  template <typename T>
  void GetLocalTimes(T& local_times) const {
    local_times.clear();

    const auto& children = group_effect_->getChildren();
    local_times.resize(children.size());

    for (wtf_size_t i = 0; i < children.size(); i++) {
      local_times[i] = children[i]->local_time();
    }
  }

  Vector<Timing> GetTimings() const;
  Vector<Timing::NormalizedTiming> GetNormalizedTimings() const;
  bool IsStateful() const;

  const String& name() const { return name_; }
  WorkletAnimationOptions options() { return options_; }

 private:
  // This object keeps the definition object, and animator instance alive.
  // It participates in wrapper tracing as it holds onto V8 wrappers.
  Member<AnimatorDefinition> definition_;
  TraceWrapperV8Reference<v8::Value> instance_;

  // The 'name' and 'options' of the animator need to be stored to be
  // migrated to the new animator upon switching global scopes. For other
  // properties, 'animation id' and 'number of effects' can be, and 'state'
  // should be queried on the fly.
  String name_;
  WorkletAnimationOptions options_;

  Member<WorkletGroupEffect> group_effect_;
};

}  // namespace blink

#endif  // THIRD_PARTY_BLINK_RENDERER_MODULES_ANIMATIONWORKLET_ANIMATOR_H_