summaryrefslogtreecommitdiffstats
path: root/content/renderer/android/synchronous_compositor_external_begin_frame_source.h
blob: 83fed03bf58d3e23cb62494f17b06e4eda3b78a1 (plain)
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
// Copyright 2014 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.

#ifndef CONTENT_RENDERER_ANDROID_SYNCHRONOUS_COMPOSITOR_EXTERNAL_BEGIN_FRAME_SOURCE_H_
#define CONTENT_RENDERER_ANDROID_SYNCHRONOUS_COMPOSITOR_EXTERNAL_BEGIN_FRAME_SOURCE_H_

#include "base/compiler_specific.h"
#include "base/macros.h"
#include "base/threading/thread_checker.h"
#include "cc/scheduler/begin_frame_source.h"

namespace content {

class SynchronousCompositorRegistry;

class SynchronousCompositorExternalBeginFrameSourceClient {
 public:
  virtual void OnNeedsBeginFramesChange(bool needs_begin_frames) = 0;

 protected:
  virtual ~SynchronousCompositorExternalBeginFrameSourceClient() {}
};

// Make sure that this is initialized and set to client before output
// surface is bound to compositor.
class SynchronousCompositorExternalBeginFrameSource
    : public cc::BeginFrameSourceBase {
 public:
  SynchronousCompositorExternalBeginFrameSource(
      int routing_id,
      SynchronousCompositorRegistry* registry);
  ~SynchronousCompositorExternalBeginFrameSource() override;

  void BeginFrame(const cc::BeginFrameArgs& args);
  void SetClient(SynchronousCompositorExternalBeginFrameSourceClient* client);
  using cc::BeginFrameSourceBase::SetBeginFrameSourcePaused;

  // cc::BeginFrameSourceBase implementation.
  void OnNeedsBeginFramesChange(bool needs_begin_frames) override;
  void SetClientReady() override;

 private:
  bool CalledOnValidThread() const;

  const int routing_id_;
  SynchronousCompositorRegistry* const registry_;
  bool registered_;

  // Not owned.
  SynchronousCompositorExternalBeginFrameSourceClient* client_;

  base::ThreadChecker thread_checker_;

  DISALLOW_COPY_AND_ASSIGN(SynchronousCompositorExternalBeginFrameSource);
};

}  // namespace content

#endif  // CONTENT_RENDERER_ANDROID_SYNCHRONOUS_COMPOSITOR_EXTERNAL_BEGIN_FRAME_SOURCE_H_