animator.h 1.7 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
#include "flutter/synchronization/pipeline.h"
#include "flutter/synchronization/semaphore.h"
13 14 15
#include "lib/fxl/memory/ref_ptr.h"
#include "lib/fxl/memory/weak_ptr.h"
#include "lib/fxl/time/time_point.h"
A
Adam Barth 已提交
16 17 18 19 20

namespace shell {

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

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

27 28 29 30
  void set_rasterizer(fxl::WeakPtr<Rasterizer> rasterizer) {
    rasterizer_ = rasterizer;
  }

A
Adam Barth 已提交
31
  void RequestFrame();
32

33 34
  void Render(std::unique_ptr<flow::LayerTree> layer_tree);

35
  void Start();
36

37
  void Stop();
38

A
Adam Barth 已提交
39
 private:
40 41
  using LayerTreePipeline = flutter::Pipeline<flow::LayerTree>;

42 43
  void BeginFrame(fxl::TimePoint frame_start_time,
                  fxl::TimePoint frame_target_time);
A
Adam Barth 已提交
44

45
  void AwaitVSync();
46

47 48
  const char* FrameParity();

49
  fxl::WeakPtr<Rasterizer> rasterizer_;
50
  VsyncWaiter* waiter_;
A
Adam Barth 已提交
51
  Engine* engine_;
52

53
  fxl::TimePoint last_begin_frame_time_;
54
  int64_t dart_frame_deadline_;
55
  fxl::RefPtr<LayerTreePipeline> layer_tree_pipeline_;
56
  flutter::Semaphore pending_frame_semaphore_;
57
  LayerTreePipeline::ProducerContinuation producer_continuation_;
58
  int64_t frame_number_;
59
  bool paused_;
60
  bool frame_scheduled_;
A
Adam Barth 已提交
61

62
  fxl::WeakPtrFactory<Animator> weak_factory_;
A
Adam Barth 已提交
63

64
  FXL_DISALLOW_COPY_AND_ASSIGN(Animator);
A
Adam Barth 已提交
65 66 67 68
};

}  // namespace shell

69
#endif  // FLUTTER_SHELL_COMMON_ANIMATOR_H_