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.
5 #ifndef CC_TREES_SINGLE_THREAD_PROXY_H_
6 #define CC_TREES_SINGLE_THREAD_PROXY_H_
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"
18 class ContextProvider;
20 class LayerTreeHostSingleThreadClient;
22 class SingleThreadProxy : public Proxy, LayerTreeHostImplClient {
24 static scoped_ptr<Proxy> Create(
25 LayerTreeHost* layer_tree_host,
26 LayerTreeHostSingleThreadClient* client);
27 virtual ~SingleThreadProxy();
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;
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)
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(
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)
82 virtual void DidActivatePendingTree() OVERRIDE {}
83 virtual void DidManageTiles() OVERRIDE {}
85 // Called by the legacy path where RenderWidget does the scheduling.
86 void CompositeImmediately(base::TimeTicks frame_begin_time);
89 SingleThreadProxy(LayerTreeHost* layer_tree_host,
90 LayerTreeHostSingleThreadClient* client);
92 void OnOutputSurfaceInitializeAttempted(bool success);
93 bool CommitAndComposite(base::TimeTicks frame_begin_time,
94 const gfx::Rect& device_viewport_damage_rect,
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,
102 LayerTreeHostImpl::FrameData* frame);
105 bool ShouldComposite() const;
106 void UpdateBackgroundAnimateTicking();
108 // Accessed on main thread only.
109 LayerTreeHost* layer_tree_host_;
110 LayerTreeHostSingleThreadClient* client_;
111 bool created_offscreen_context_provider_;
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_;
118 bool next_frame_is_newly_committed_frame_;
122 DISALLOW_COPY_AND_ASSIGN(SingleThreadProxy);
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 {
129 explicit DebugScopedSetImplThread(Proxy* proxy) : proxy_(proxy) {
131 previous_value_ = proxy_->impl_thread_is_overridden_;
132 proxy_->SetCurrentThreadIsImplThread(true);
135 ~DebugScopedSetImplThread() {
137 proxy_->SetCurrentThreadIsImplThread(previous_value_);
142 bool previous_value_;
145 DISALLOW_COPY_AND_ASSIGN(DebugScopedSetImplThread);
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 {
152 explicit DebugScopedSetMainThread(Proxy* proxy) : proxy_(proxy) {
154 previous_value_ = proxy_->impl_thread_is_overridden_;
155 proxy_->SetCurrentThreadIsImplThread(false);
158 ~DebugScopedSetMainThread() {
160 proxy_->SetCurrentThreadIsImplThread(previous_value_);
165 bool previous_value_;
168 DISALLOW_COPY_AND_ASSIGN(DebugScopedSetMainThread);
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 {
176 explicit DebugScopedSetImplThreadAndMainThreadBlocked(Proxy* proxy)
177 : impl_thread_(proxy), main_thread_blocked_(proxy) {}
180 DebugScopedSetImplThread impl_thread_;
181 DebugScopedSetMainThreadBlocked main_thread_blocked_;
183 DISALLOW_COPY_AND_ASSIGN(DebugScopedSetImplThreadAndMainThreadBlocked);
188 #endif // CC_TREES_SINGLE_THREAD_PROXY_H_