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