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