summaryrefslogtreecommitdiffstats
path: root/cc/trees/proxy_impl.h
blob: a335d8abe1ac4e75ce7e017221ad6857234c92c6 (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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
// 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_PROXY_IMPL_H_
#define CC_TREES_PROXY_IMPL_H_

#include "base/macros.h"
#include "base/memory/scoped_ptr.h"
#include "cc/base/completion_event.h"
#include "cc/base/delayed_unique_notifier.h"
#include "cc/input/top_controls_state.h"
#include "cc/scheduler/scheduler.h"
#include "cc/trees/channel_impl.h"
#include "cc/trees/layer_tree_host_impl.h"

namespace cc {

// This class aggregates all the interactions that the main side of the
// compositor needs to have with the impl side. It is created and owned by the
// ChannelImpl implementation. The class lives entirely on the impl thread.
class CC_EXPORT ProxyImpl : public NON_EXPORTED_BASE(LayerTreeHostImplClient),
                            public NON_EXPORTED_BASE(SchedulerClient) {
 public:
  static scoped_ptr<ProxyImpl> Create(
      ChannelImpl* channel_impl,
      LayerTreeHost* layer_tree_host,
      TaskRunnerProvider* task_runner_provider,
      scoped_ptr<BeginFrameSource> external_begin_frame_source);

  ~ProxyImpl() override;

  // Virtual for testing.
  virtual void UpdateTopControlsStateOnImpl(TopControlsState constraints,
                                            TopControlsState current,
                                            bool animate);
  virtual void InitializeOutputSurfaceOnImpl(OutputSurface* output_surface);
  virtual void MainThreadHasStoppedFlingingOnImpl();
  virtual void SetInputThrottledUntilCommitOnImpl(bool is_throttled);
  virtual void SetDeferCommitsOnImpl(bool defer_commits) const;
  virtual void SetNeedsRedrawOnImpl(const gfx::Rect& damage_rect);
  virtual void SetNeedsCommitOnImpl();
  virtual void BeginMainFrameAbortedOnImpl(
      CommitEarlyOutReason reason,
      base::TimeTicks main_thread_start_time);
  virtual void FinishAllRenderingOnImpl(CompletionEvent* completion);
  virtual void SetVisibleOnImpl(bool visible);
  virtual void ReleaseOutputSurfaceOnImpl(CompletionEvent* completion);
  virtual void FinishGLOnImpl(CompletionEvent* completion);
  virtual void MainFrameWillHappenOnImplForTesting(
      CompletionEvent* completion,
      bool* main_frame_will_happen);
  virtual void StartCommitOnImpl(CompletionEvent* completion,
                                 LayerTreeHost* layer_tree_host,
                                 base::TimeTicks main_thread_start_time,
                                 bool hold_commit_for_activation);

 protected:
  // protected for testing.
  ProxyImpl(ChannelImpl* channel_impl,
            LayerTreeHost* layer_tree_host,
            TaskRunnerProvider* task_runner_provider,
            scoped_ptr<BeginFrameSource> external_begin_frame_source);

 private:
  // The members of this struct should be accessed on the impl thread only when
  // the main thread is blocked for a commit.
  struct BlockedMainCommitOnly {
    BlockedMainCommitOnly();
    ~BlockedMainCommitOnly();
    LayerTreeHost* layer_tree_host;
  };

  friend class ProxyImplForTest;

  // LayerTreeHostImplClient implementation
  void UpdateRendererCapabilitiesOnImplThread() override;
  void DidLoseOutputSurfaceOnImplThread() override;
  void CommitVSyncParameters(base::TimeTicks timebase,
                             base::TimeDelta interval) override;
  void SetEstimatedParentDrawTime(base::TimeDelta draw_time) override;
  void DidSwapBuffersOnImplThread() override;
  void DidSwapBuffersCompleteOnImplThread() override;
  void OnCanDrawStateChanged(bool can_draw) override;
  void NotifyReadyToActivate() override;
  void NotifyReadyToDraw() override;
  // Please call these 3 functions through
  // LayerTreeHostImpl's SetNeedsRedraw(), SetNeedsRedrawRect() and
  // SetNeedsOneBeginImplFrame().
  void SetNeedsRedrawOnImplThread() override;
  void SetNeedsRedrawRectOnImplThread(const gfx::Rect& dirty_rect) override;
  void SetNeedsOneBeginImplFrameOnImplThread() override;
  void SetNeedsPrepareTilesOnImplThread() override;
  void SetNeedsCommitOnImplThread() override;
  void SetVideoNeedsBeginFrames(bool needs_begin_frames) override;
  void PostAnimationEventsToMainThreadOnImplThread(
      scoped_ptr<AnimationEvents> events) override;
  bool IsInsideDraw() override;
  void RenewTreePriority() override;
  void PostDelayedAnimationTaskOnImplThread(const base::Closure& task,
                                            base::TimeDelta delay) override;
  void DidActivateSyncTree() override;
  void WillPrepareTiles() override;
  void DidPrepareTiles() override;
  void DidCompletePageScaleAnimationOnImplThread() override;
  void OnDrawForOutputSurface(bool resourceless_software_draw) override;
  // This should only be called by LayerTreeHostImpl::PostFrameTimingEvents.
  void PostFrameTimingEventsOnImplThread(
      scoped_ptr<FrameTimingTracker::CompositeTimingSet> composite_events,
      scoped_ptr<FrameTimingTracker::MainFrameTimingSet> main_frame_events)
      override;

  // SchedulerClient implementation
  void WillBeginImplFrame(const BeginFrameArgs& args) override;
  void DidFinishImplFrame() override;
  void ScheduledActionSendBeginMainFrame(const BeginFrameArgs& args) override;
  DrawResult ScheduledActionDrawAndSwapIfPossible() override;
  DrawResult ScheduledActionDrawAndSwapForced() override;
  void ScheduledActionCommit() override;
  void ScheduledActionActivateSyncTree() override;
  void ScheduledActionBeginOutputSurfaceCreation() override;
  void ScheduledActionPrepareTiles() override;
  void ScheduledActionInvalidateOutputSurface() override;
  void SendBeginFramesToChildren(const BeginFrameArgs& args) override;
  void SendBeginMainFrameNotExpectedSoon() override;

  DrawResult DrawAndSwapInternal(bool forced_draw);

  bool IsImplThread() const;
  bool IsMainThreadBlocked() const;

  const int layer_tree_host_id_;

  scoped_ptr<Scheduler> scheduler_;

  // Set when the main thread is waiting on a pending tree activation.
  bool next_commit_waits_for_activation_;

  // Set when the main thread is waiting on a commit to complete or on a
  // pending tree activation.
  CompletionEvent* commit_completion_event_;

  // Set when the next draw should post DidCommitAndDrawFrame to the main
  // thread.
  bool next_frame_is_newly_committed_frame_;

  bool inside_draw_;
  bool input_throttled_until_commit_;

  TaskRunnerProvider* task_runner_provider_;

  DelayedUniqueNotifier smoothness_priority_expiration_notifier_;

  scoped_ptr<BeginFrameSource> external_begin_frame_source_;
  scoped_ptr<BeginFrameSource> unthrottled_begin_frame_source_;
  scoped_ptr<SyntheticBeginFrameSource> synthetic_begin_frame_source_;

  RenderingStatsInstrumentation* rendering_stats_instrumentation_;

  // Values used to keep track of frame durations. Used only in frame timing.
  BeginFrameArgs last_begin_main_frame_args_;
  BeginFrameArgs last_processed_begin_main_frame_args_;

  scoped_ptr<LayerTreeHostImpl> layer_tree_host_impl_;

  ChannelImpl* channel_impl_;

  // Use accessors instead of this variable directly.
  BlockedMainCommitOnly main_thread_blocked_commit_vars_unsafe_;
  BlockedMainCommitOnly& blocked_main_commit();

  DISALLOW_COPY_AND_ASSIGN(ProxyImpl);
};

}  // namespace cc

#endif  // CC_TREES_PROXY_IMPL_H_