Upstream version 5.34.104.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/time/time.h"
11 #include "cc/animation/animation_events.h"
12 #include "cc/output/begin_frame_args.h"
13 #include "cc/trees/layer_tree_host_impl.h"
14 #include "cc/trees/proxy.h"
15
16 namespace cc {
17
18 class ContextProvider;
19 class LayerTreeHost;
20 class LayerTreeHostSingleThreadClient;
21
22 class SingleThreadProxy : public Proxy, LayerTreeHostImplClient {
23  public:
24   static scoped_ptr<Proxy> Create(
25       LayerTreeHost* layer_tree_host,
26       LayerTreeHostSingleThreadClient* client);
27   virtual ~SingleThreadProxy();
28
29   // Proxy implementation
30   virtual bool CompositeAndReadback(void* pixels,
31                                     const gfx::Rect& rect) OVERRIDE;
32   virtual void FinishAllRendering() OVERRIDE;
33   virtual bool IsStarted() const OVERRIDE;
34   virtual void SetLayerTreeHostClientReady() OVERRIDE;
35   virtual void SetVisible(bool visible) OVERRIDE;
36   virtual void CreateAndInitializeOutputSurface() OVERRIDE;
37   virtual const RendererCapabilities& GetRendererCapabilities() const OVERRIDE;
38   virtual void SetNeedsAnimate() OVERRIDE;
39   virtual void SetNeedsUpdateLayers() OVERRIDE;
40   virtual void SetNeedsCommit() OVERRIDE;
41   virtual void SetNeedsRedraw(const gfx::Rect& damage_rect) OVERRIDE;
42   virtual void SetNextCommitWaitsForActivation() OVERRIDE;
43   virtual void NotifyInputThrottledUntilCommit() OVERRIDE {}
44   virtual void SetDeferCommits(bool defer_commits) OVERRIDE;
45   virtual bool CommitRequested() const OVERRIDE;
46   virtual bool BeginMainFrameRequested() const OVERRIDE;
47   virtual void MainThreadHasStoppedFlinging() OVERRIDE {}
48   virtual void Start() OVERRIDE;
49   virtual void Stop() OVERRIDE;
50   virtual size_t MaxPartialTextureUpdates() const OVERRIDE;
51   virtual void AcquireLayerTextures() OVERRIDE {}
52   virtual void ForceSerializeOnSwapBuffers() OVERRIDE;
53   virtual scoped_ptr<base::Value> AsValue() const OVERRIDE;
54   virtual bool CommitPendingForTesting() OVERRIDE;
55
56   // LayerTreeHostImplClient implementation
57   virtual void UpdateRendererCapabilitiesOnImplThread() OVERRIDE;
58   virtual void DidLoseOutputSurfaceOnImplThread() OVERRIDE;
59   virtual void DidSwapBuffersOnImplThread() OVERRIDE;
60   virtual void OnSwapBuffersCompleteOnImplThread() OVERRIDE;
61   virtual void BeginImplFrame(const BeginFrameArgs& args)
62       OVERRIDE {}
63   virtual void OnCanDrawStateChanged(bool can_draw) OVERRIDE;
64   virtual void NotifyReadyToActivate() OVERRIDE;
65   virtual void SetNeedsRedrawOnImplThread() OVERRIDE;
66   virtual void SetNeedsRedrawRectOnImplThread(
67       const gfx::Rect& dirty_rect) OVERRIDE;
68   virtual void SetNeedsManageTilesOnImplThread() OVERRIDE;
69   virtual void DidInitializeVisibleTileOnImplThread() OVERRIDE;
70   virtual void SetNeedsCommitOnImplThread() OVERRIDE;
71   virtual void PostAnimationEventsToMainThreadOnImplThread(
72       scoped_ptr<AnimationEventsVector> events,
73       base::Time wall_clock_time) OVERRIDE;
74   virtual bool ReduceContentsTextureMemoryOnImplThread(
75       size_t limit_bytes,
76       int priority_cutoff) OVERRIDE;
77   virtual void SendManagedMemoryStats() OVERRIDE;
78   virtual bool IsInsideDraw() OVERRIDE;
79   virtual void RenewTreePriority() OVERRIDE {}
80   virtual void RequestScrollbarAnimationOnImplThread(base::TimeDelta delay)
81       OVERRIDE {}
82   virtual void DidActivatePendingTree() OVERRIDE {}
83   virtual void DidManageTiles() OVERRIDE {}
84
85   // Called by the legacy path where RenderWidget does the scheduling.
86   void CompositeImmediately(base::TimeTicks frame_begin_time);
87
88  private:
89   SingleThreadProxy(LayerTreeHost* layer_tree_host,
90                     LayerTreeHostSingleThreadClient* client);
91
92   void OnOutputSurfaceInitializeAttempted(bool success);
93   bool CommitAndComposite(base::TimeTicks frame_begin_time,
94                           const gfx::Rect& device_viewport_damage_rect,
95                           bool for_readback,
96                           LayerTreeHostImpl::FrameData* frame);
97   void DoCommit(scoped_ptr<ResourceUpdateQueue> queue);
98   bool DoComposite(scoped_refptr<ContextProvider> offscreen_context_provider,
99                    base::TimeTicks frame_begin_time,
100                    const gfx::Rect& device_viewport_damage_rect,
101                    bool for_readback,
102                    LayerTreeHostImpl::FrameData* frame);
103   void DidSwapFrame();
104
105   bool ShouldComposite() const;
106   void UpdateBackgroundAnimateTicking();
107
108   // Accessed on main thread only.
109   LayerTreeHost* layer_tree_host_;
110   LayerTreeHostSingleThreadClient* client_;
111   bool created_offscreen_context_provider_;
112
113   // Used on the Thread, but checked on main thread during
114   // initialization/shutdown.
115   scoped_ptr<LayerTreeHostImpl> layer_tree_host_impl_;
116   RendererCapabilities renderer_capabilities_for_main_thread_;
117
118   bool next_frame_is_newly_committed_frame_;
119
120   bool inside_draw_;
121
122   DISALLOW_COPY_AND_ASSIGN(SingleThreadProxy);
123 };
124
125 // For use in the single-threaded case. In debug builds, it pretends that the
126 // code is running on the impl thread to satisfy assertion checks.
127 class DebugScopedSetImplThread {
128  public:
129   explicit DebugScopedSetImplThread(Proxy* proxy) : proxy_(proxy) {
130 #ifndef NDEBUG
131     previous_value_ = proxy_->impl_thread_is_overridden_;
132     proxy_->SetCurrentThreadIsImplThread(true);
133 #endif
134   }
135   ~DebugScopedSetImplThread() {
136 #ifndef NDEBUG
137     proxy_->SetCurrentThreadIsImplThread(previous_value_);
138 #endif
139   }
140
141  private:
142   bool previous_value_;
143   Proxy* proxy_;
144
145   DISALLOW_COPY_AND_ASSIGN(DebugScopedSetImplThread);
146 };
147
148 // For use in the single-threaded case. In debug builds, it pretends that the
149 // code is running on the main thread to satisfy assertion checks.
150 class DebugScopedSetMainThread {
151  public:
152   explicit DebugScopedSetMainThread(Proxy* proxy) : proxy_(proxy) {
153 #ifndef NDEBUG
154     previous_value_ = proxy_->impl_thread_is_overridden_;
155     proxy_->SetCurrentThreadIsImplThread(false);
156 #endif
157   }
158   ~DebugScopedSetMainThread() {
159 #ifndef NDEBUG
160     proxy_->SetCurrentThreadIsImplThread(previous_value_);
161 #endif
162   }
163
164  private:
165   bool previous_value_;
166   Proxy* proxy_;
167
168   DISALLOW_COPY_AND_ASSIGN(DebugScopedSetMainThread);
169 };
170
171 // For use in the single-threaded case. In debug builds, it pretends that the
172 // code is running on the impl thread and that the main thread is blocked to
173 // satisfy assertion checks
174 class DebugScopedSetImplThreadAndMainThreadBlocked {
175  public:
176   explicit DebugScopedSetImplThreadAndMainThreadBlocked(Proxy* proxy)
177       : impl_thread_(proxy), main_thread_blocked_(proxy) {}
178
179  private:
180   DebugScopedSetImplThread impl_thread_;
181   DebugScopedSetMainThreadBlocked main_thread_blocked_;
182
183   DISALLOW_COPY_AND_ASSIGN(DebugScopedSetImplThreadAndMainThreadBlocked);
184 };
185
186 }  // namespace cc
187
188 #endif  // CC_TREES_SINGLE_THREAD_PROXY_H_