summaryrefslogtreecommitdiffstats
path: root/cc/trees/threaded_channel.h
blob: ca7fc04c0a7319f5aa6ce7bfe0bc2ca4b0c102e1 (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
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
// 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.

#ifndef CC_TREES_THREADED_CHANNEL_H_
#define CC_TREES_THREADED_CHANNEL_H_

#include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h"
#include "cc/base/cc_export.h"
#include "cc/trees/channel_impl.h"
#include "cc/trees/channel_main.h"
#include "cc/trees/proxy_common.h"
#include "cc/trees/proxy_impl.h"
#include "cc/trees/proxy_main.h"
#include "cc/trees/thread_proxy.h"

namespace base {
class SingleThreadTaskRunner;
}

namespace cc {
class ChannelImpl;
class ChannelMain;
class ProxyImpl;
class ProxyMain;
class ThreadProxy;

// An implementation of ChannelMain and ChannelImpl that sends commands between
// ProxyMain and ProxyImpl across thread boundaries.
//
// LayerTreeHost creates ThreadedChannel and passes the ownership to ProxyMain.
// The object life cycle and communication across threads is as follows:
//
//
//           Main Thread              |               Impl Thread
//   LayerTreeHost->InitializeProxy   |
//               |                    |
//        ProxyMain->Start()          |
//               |              ThreadedChannel
// ---------------------------------------------------------------------------
//  ChannelMain::InitializeImpl ---PostTask---> ThreadedChannel::
//                                                   InitializeImplOnImplThread
//                                                          |
//                                                   ProxyImpl::Create
//                                                          |
//                                                   ProxyImpl->Initialize()
//                                                          .
//                                                          .
//                                          ProxyImpl::ScheduledActionBegin
//                                                     OutputSurfaceCreation
//                                                          |
//                                         ChannelImpl::RequestNewOutputSurface
// ----------------------------------------------------------------------------
//                                                          |
// ProxyMain->RequestNewOutputSurface()<----PostTask--------
//              .
//              .
// ProxyMain->LayerTreeHostClosed
//              |
// ---------------------------------------------------------------------------
// ChannelMain::SetLayerTreeClosedOnImpl---PostTask---> ProxyImpl->
//                                                        SetLayerTreeClosed
// ----------------------------------------------------------------------------

class CC_EXPORT ThreadedChannel : public ChannelMain, public ChannelImpl {
 public:
  static scoped_ptr<ThreadedChannel> Create(
      // TODO(khushalsagar): Make this ProxyMain* and write the initialization
      // sequence. Currently ThreadProxy implements both so we pass the pointer
      // and set ProxyImpl.
      ThreadProxy* thread_proxy,
      TaskRunnerProvider* task_runner_provider);

  ~ThreadedChannel() override;

  // ChannelMain Implementation
  void SetThrottleFrameProductionOnImpl(bool throttle) override;
  void UpdateTopControlsStateOnImpl(TopControlsState constraints,
                                    TopControlsState current,
                                    bool animate) override;
  void InitializeOutputSurfaceOnImpl(OutputSurface* output_surface) override;
  void MainThreadHasStoppedFlingingOnImpl() override;
  void SetInputThrottledUntilCommitOnImpl(bool is_throttled) override;
  void SetDeferCommitsOnImpl(bool defer_commits) override;
  void SetNeedsCommitOnImpl() override;
  void BeginMainFrameAbortedOnImpl(
      CommitEarlyOutReason reason,
      base::TimeTicks main_thread_start_time) override;
  void SetNeedsRedrawOnImpl(const gfx::Rect& damage_rect) override;
  void SetVisibleOnImpl(bool visible) override;

  // Blocking calls to ProxyImpl
  void FinishAllRenderingOnImpl(CompletionEvent* completion) override;
  void ReleaseOutputSurfaceOnImpl(CompletionEvent* completion) override;
  void FinishGLOnImpl(CompletionEvent* completion) override;
  void MainFrameWillHappenOnImplForTesting(
      CompletionEvent* completion,
      bool* main_frame_will_happen) override;
  void StartCommitOnImpl(CompletionEvent* completion,
                         LayerTreeHost* layer_tree_host,
                         base::TimeTicks main_thread_start_time,
                         bool hold_commit_for_activation) override;
  void InitializeImplOnImpl(CompletionEvent* completion,
                            LayerTreeHost* layer_tree_host) override;
  void LayerTreeHostClosedOnImpl(CompletionEvent* completion) override;

  // ChannelImpl Implementation
  void DidCompleteSwapBuffers() override;
  void SetRendererCapabilitiesMainCopy(
      const RendererCapabilities& capabilities) override;
  void BeginMainFrameNotExpectedSoon() override;
  void DidCommitAndDrawFrame() override;
  void SetAnimationEvents(scoped_ptr<AnimationEventsVector> queue) override;
  void DidLoseOutputSurface() override;
  void RequestNewOutputSurface() override;
  void DidInitializeOutputSurface(
      bool success,
      const RendererCapabilities& capabilities) override;
  void DidCompletePageScaleAnimation() override;
  void PostFrameTimingEventsOnMain(
      scoped_ptr<FrameTimingTracker::CompositeTimingSet> composite_events,
      scoped_ptr<FrameTimingTracker::MainFrameTimingSet> main_frame_events)
      override;
  void BeginMainFrame(
      scoped_ptr<BeginMainFrameAndCommitState> begin_main_frame_state) override;

 protected:
  ThreadedChannel(ThreadProxy* thread_proxy,
                  TaskRunnerProvider* task_runner_provider);

 private:
  base::SingleThreadTaskRunner* MainThreadTaskRunner() const;
  base::SingleThreadTaskRunner* ImplThreadTaskRunner() const;

  ProxyMain* proxy_main_;

  ProxyImpl* proxy_impl_;

  TaskRunnerProvider* task_runner_provider_;

  scoped_refptr<base::SingleThreadTaskRunner> main_task_runner_;

  scoped_refptr<base::SingleThreadTaskRunner> impl_task_runner_;

  DISALLOW_COPY_AND_ASSIGN(ThreadedChannel);
};

}  // namespace cc

#endif  // CC_TREES_THREADED_CHANNEL_H_