animator.h 1.6 KB
Newer Older
A
Adam Barth 已提交
1 2 3 4
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

5 6
#ifndef FLUTTER_SHELL_COMMON_ANIMATOR_H_
#define FLUTTER_SHELL_COMMON_ANIMATOR_H_
A
Adam Barth 已提交
7

8 9
#include "flutter/shell/common/engine.h"
#include "flutter/shell/common/rasterizer.h"
10
#include "flutter/shell/common/vsync_waiter.h"
11 12 13
#include "flutter/synchronization/pipeline.h"
#include "flutter/synchronization/semaphore.h"
#include "lib/ftl/memory/ref_ptr.h"
14
#include "lib/ftl/memory/weak_ptr.h"
A
Adam Barth 已提交
15
#include "lib/ftl/time/time_point.h"
A
Adam Barth 已提交
16 17 18 19 20

namespace shell {

class Animator {
 public:
21 22 23
  Animator(ftl::WeakPtr<Rasterizer> rasterizer,
           VsyncWaiter* waiter,
           Engine* engine);
24

A
Adam Barth 已提交
25 26 27
  ~Animator();

  void RequestFrame();
28

29 30
  void Render(std::unique_ptr<flow::LayerTree> layer_tree);

31
  void Start();
32

33
  void Stop();
34

A
Adam Barth 已提交
35
 private:
36 37
  using LayerTreePipeline = flutter::Pipeline<flow::LayerTree>;

38 39
  void BeginFrame(ftl::TimePoint frame_start_time,
                  ftl::TimePoint frame_target_time);
A
Adam Barth 已提交
40

41
  void AwaitVSync();
42

43
  ftl::WeakPtr<Rasterizer> rasterizer_;
44
  VsyncWaiter* waiter_;
A
Adam Barth 已提交
45
  Engine* engine_;
46

47
  ftl::TimePoint last_begin_frame_time_;
48
  int64_t dart_frame_deadline_;
49 50
  ftl::RefPtr<LayerTreePipeline> layer_tree_pipeline_;
  flutter::Semaphore pending_frame_semaphore_;
51
  LayerTreePipeline::ProducerContinuation producer_continuation_;
52
  int64_t frame_number_;
53
  bool paused_;
54
  bool frame_scheduled_;
A
Adam Barth 已提交
55

56
  ftl::WeakPtrFactory<Animator> weak_factory_;
A
Adam Barth 已提交
57

58
  FTL_DISALLOW_COPY_AND_ASSIGN(Animator);
A
Adam Barth 已提交
59 60 61 62
};

}  // namespace shell

63
#endif  // FLUTTER_SHELL_COMMON_ANIMATOR_H_