Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / cc / trees / single_thread_proxy.h
1 // Copyright 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef CC_TREES_SINGLE_THREAD_PROXY_H_
6 #define CC_TREES_SINGLE_THREAD_PROXY_H_
7
8 #include <limits>
9
10 #include "base/cancelable_callback.h"
11 #include "base/time/time.h"
12 #include "cc/animation/animation_events.h"
13 #include "cc/output/begin_frame_args.h"
14 #include "cc/scheduler/scheduler.h"
15 #include "cc/trees/blocking_task_runner.h"
16 #include "cc/trees/layer_tree_host_impl.h"
17 #include "cc/trees/proxy.h"
18 #include "cc/trees/proxy_timing_history.h"
19
20 namespace cc {
21
22 class ContextProvider;
23 class LayerTreeHost;
24 class LayerTreeHostSingleThreadClient;
25
26 class CC_EXPORT SingleThreadProxy : public Proxy,
27                                     NON_EXPORTED_BASE(LayerTreeHostImplClient),
28                                     SchedulerClient {
29  public:
30   static scoped_ptr<Proxy> Create(
31       LayerTreeHost* layer_tree_host,
32       LayerTreeHostSingleThreadClient* client,
33       scoped_refptr<base::SingleThreadTaskRunner> main_task_runner);
34   ~SingleThreadProxy() override;
35
36   // Proxy implementation
37   void FinishAllRendering() override;
38   bool IsStarted() const override;
39   void SetOutputSurface(scoped_ptr<OutputSurface>) override;
40   void SetLayerTreeHostClientReady() override;
41   void SetVisible(bool visible) override;
42   const RendererCapabilities& GetRendererCapabilities() const override;
43   void SetNeedsAnimate() override;
44   void SetNeedsUpdateLayers() override;
45   void SetNeedsCommit() override;
46   void SetNeedsRedraw(const gfx::Rect& damage_rect) override;
47   void SetNextCommitWaitsForActivation() override;
48   void NotifyInputThrottledUntilCommit() override {}
49   void SetDeferCommits(bool defer_commits) override;
50   bool CommitRequested() const override;
51   bool BeginMainFrameRequested() const override;
52   void MainThreadHasStoppedFlinging() override {}
53   void Start() override;
54   void Stop() override;
55   size_t MaxPartialTextureUpdates() const override;
56   void ForceSerializeOnSwapBuffers() override;
57   bool SupportsImplScrolling() const override;
58   void AsValueInto(base::debug::TracedValue* state) const override;
59   bool MainFrameWillHappenForTesting() override;
60
61   // SchedulerClient implementation
62   BeginFrameSource* ExternalBeginFrameSource() override;
63   void WillBeginImplFrame(const BeginFrameArgs& args) override;
64   void ScheduledActionSendBeginMainFrame() override;
65   DrawResult ScheduledActionDrawAndSwapIfPossible() override;
66   DrawResult ScheduledActionDrawAndSwapForced() override;
67   void ScheduledActionCommit() override;
68   void ScheduledActionAnimate() override;
69   void ScheduledActionUpdateVisibleTiles() override;
70   void ScheduledActionActivateSyncTree() override;
71   void ScheduledActionBeginOutputSurfaceCreation() override;
72   void ScheduledActionManageTiles() override;
73   void DidAnticipatedDrawTimeChange(base::TimeTicks time) override;
74   base::TimeDelta DrawDurationEstimate() override;
75   base::TimeDelta BeginMainFrameToCommitDurationEstimate() override;
76   base::TimeDelta CommitToActivateDurationEstimate() override;
77   void DidBeginImplFrameDeadline() override;
78
79   // LayerTreeHostImplClient implementation
80   void UpdateRendererCapabilitiesOnImplThread() override;
81   void DidLoseOutputSurfaceOnImplThread() override;
82   void CommitVSyncParameters(base::TimeTicks timebase,
83                              base::TimeDelta interval) override {}
84   void SetEstimatedParentDrawTime(base::TimeDelta draw_time) override {}
85   void SetMaxSwapsPendingOnImplThread(int max) override {}
86   void DidSwapBuffersOnImplThread() override;
87   void DidSwapBuffersCompleteOnImplThread() override;
88   void OnCanDrawStateChanged(bool can_draw) override;
89   void NotifyReadyToActivate() override;
90   void SetNeedsRedrawOnImplThread() override;
91   void SetNeedsRedrawRectOnImplThread(const gfx::Rect& dirty_rect) override;
92   void SetNeedsAnimateOnImplThread() override;
93   void SetNeedsManageTilesOnImplThread() override;
94   void DidInitializeVisibleTileOnImplThread() override;
95   void SetNeedsCommitOnImplThread() override;
96   void PostAnimationEventsToMainThreadOnImplThread(
97       scoped_ptr<AnimationEventsVector> events) override;
98   bool ReduceContentsTextureMemoryOnImplThread(size_t limit_bytes,
99                                                int priority_cutoff) override;
100   bool IsInsideDraw() override;
101   void RenewTreePriority() override {}
102   void PostDelayedScrollbarFadeOnImplThread(const base::Closure& start_fade,
103                                             base::TimeDelta delay) override {}
104   void DidActivateSyncTree() override;
105   void DidManageTiles() override;
106   void SetDebugState(const LayerTreeDebugState& debug_state) override {}
107
108   void RequestNewOutputSurface();
109
110   // Called by the legacy path where RenderWidget does the scheduling.
111   void CompositeImmediately(base::TimeTicks frame_begin_time);
112
113  private:
114   SingleThreadProxy(
115       LayerTreeHost* layer_tree_host,
116       LayerTreeHostSingleThreadClient* client,
117       scoped_refptr<base::SingleThreadTaskRunner> main_task_runner);
118
119   void BeginMainFrame();
120   void BeginMainFrameAbortedOnImplThread();
121   void DoBeginMainFrame(const BeginFrameArgs& begin_frame_args);
122   void DoCommit();
123   DrawResult DoComposite(base::TimeTicks frame_begin_time,
124                          LayerTreeHostImpl::FrameData* frame);
125   void DoSwap();
126   void DidCommitAndDrawFrame();
127   void CommitComplete();
128
129   bool ShouldComposite() const;
130   void UpdateBackgroundAnimateTicking();
131   void ScheduleRequestNewOutputSurface();
132
133   // Accessed on main thread only.
134   LayerTreeHost* layer_tree_host_;
135   LayerTreeHostSingleThreadClient* client_;
136
137   // Used on the Thread, but checked on main thread during
138   // initialization/shutdown.
139   scoped_ptr<LayerTreeHostImpl> layer_tree_host_impl_;
140   RendererCapabilities renderer_capabilities_for_main_thread_;
141
142   // Accessed from both threads.
143   scoped_ptr<Scheduler> scheduler_on_impl_thread_;
144   ProxyTimingHistory timing_history_;
145
146   scoped_ptr<BlockingTaskRunner::CapturePostTasks> commit_blocking_task_runner_;
147   scoped_ptr<ResourceUpdateQueue> queue_for_commit_;
148   bool next_frame_is_newly_committed_frame_;
149
150   bool inside_draw_;
151   bool defer_commits_;
152   bool commit_was_deferred_;
153   bool commit_requested_;
154   bool inside_synchronous_composite_;
155
156   // True if a request to the LayerTreeHostClient to create an output surface
157   // is still outstanding.
158   bool output_surface_creation_requested_;
159
160   // This is the callback for the scheduled RequestNewOutputSurface.
161   base::CancelableClosure output_surface_creation_callback_;
162
163   base::WeakPtrFactory<SingleThreadProxy> weak_factory_;
164
165   DISALLOW_COPY_AND_ASSIGN(SingleThreadProxy);
166 };
167
168 // For use in the single-threaded case. In debug builds, it pretends that the
169 // code is running on the impl thread to satisfy assertion checks.
170 class DebugScopedSetImplThread {
171  public:
172   explicit DebugScopedSetImplThread(Proxy* proxy) : proxy_(proxy) {
173 #if DCHECK_IS_ON
174     previous_value_ = proxy_->impl_thread_is_overridden_;
175     proxy_->SetCurrentThreadIsImplThread(true);
176 #endif
177   }
178   ~DebugScopedSetImplThread() {
179 #if DCHECK_IS_ON
180     proxy_->SetCurrentThreadIsImplThread(previous_value_);
181 #endif
182   }
183
184  private:
185   bool previous_value_;
186   Proxy* proxy_;
187
188   DISALLOW_COPY_AND_ASSIGN(DebugScopedSetImplThread);
189 };
190
191 // For use in the single-threaded case. In debug builds, it pretends that the
192 // code is running on the main thread to satisfy assertion checks.
193 class DebugScopedSetMainThread {
194  public:
195   explicit DebugScopedSetMainThread(Proxy* proxy) : proxy_(proxy) {
196 #if DCHECK_IS_ON
197     previous_value_ = proxy_->impl_thread_is_overridden_;
198     proxy_->SetCurrentThreadIsImplThread(false);
199 #endif
200   }
201   ~DebugScopedSetMainThread() {
202 #if DCHECK_IS_ON
203     proxy_->SetCurrentThreadIsImplThread(previous_value_);
204 #endif
205   }
206
207  private:
208   bool previous_value_;
209   Proxy* proxy_;
210
211   DISALLOW_COPY_AND_ASSIGN(DebugScopedSetMainThread);
212 };
213
214 // For use in the single-threaded case. In debug builds, it pretends that the
215 // code is running on the impl thread and that the main thread is blocked to
216 // satisfy assertion checks
217 class DebugScopedSetImplThreadAndMainThreadBlocked {
218  public:
219   explicit DebugScopedSetImplThreadAndMainThreadBlocked(Proxy* proxy)
220       : impl_thread_(proxy), main_thread_blocked_(proxy) {}
221
222  private:
223   DebugScopedSetImplThread impl_thread_;
224   DebugScopedSetMainThreadBlocked main_thread_blocked_;
225
226   DISALLOW_COPY_AND_ASSIGN(DebugScopedSetImplThreadAndMainThreadBlocked);
227 };
228
229 }  // namespace cc
230
231 #endif  // CC_TREES_SINGLE_THREAD_PROXY_H_