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 DidLoseOutputSurfaceOnImplThread() OVERRIDE
;
58 virtual void DidSwapBuffersOnImplThread() OVERRIDE
;
59 virtual void OnSwapBuffersCompleteOnImplThread() OVERRIDE
;
60 virtual void BeginImplFrame(const BeginFrameArgs
& args
)
62 virtual void OnCanDrawStateChanged(bool can_draw
) OVERRIDE
;
63 virtual void NotifyReadyToActivate() OVERRIDE
;
64 virtual void SetNeedsRedrawOnImplThread() OVERRIDE
;
65 virtual void SetNeedsRedrawRectOnImplThread(
66 const gfx::Rect
& dirty_rect
) OVERRIDE
;
67 virtual void SetNeedsManageTilesOnImplThread() OVERRIDE
;
68 virtual void DidInitializeVisibleTileOnImplThread() OVERRIDE
;
69 virtual void SetNeedsCommitOnImplThread() OVERRIDE
;
70 virtual void PostAnimationEventsToMainThreadOnImplThread(
71 scoped_ptr
<AnimationEventsVector
> events
,
72 base::Time wall_clock_time
) OVERRIDE
;
73 virtual bool ReduceContentsTextureMemoryOnImplThread(
75 int priority_cutoff
) OVERRIDE
;
76 virtual void SendManagedMemoryStats() OVERRIDE
;
77 virtual bool IsInsideDraw() OVERRIDE
;
78 virtual void RenewTreePriority() OVERRIDE
{}
79 virtual void RequestScrollbarAnimationOnImplThread(base::TimeDelta delay
)
81 virtual void DidActivatePendingTree() OVERRIDE
{}
82 virtual void DidManageTiles() OVERRIDE
{}
84 // Called by the legacy path where RenderWidget does the scheduling.
85 void CompositeImmediately(base::TimeTicks frame_begin_time
);
88 SingleThreadProxy(LayerTreeHost
* layer_tree_host
,
89 LayerTreeHostSingleThreadClient
* client
);
91 void OnOutputSurfaceInitializeAttempted(bool success
);
92 bool CommitAndComposite(base::TimeTicks frame_begin_time
,
93 const gfx::Rect
& device_viewport_damage_rect
,
95 LayerTreeHostImpl::FrameData
* frame
);
96 void DoCommit(scoped_ptr
<ResourceUpdateQueue
> queue
);
97 bool DoComposite(scoped_refptr
<ContextProvider
> offscreen_context_provider
,
98 base::TimeTicks frame_begin_time
,
99 const gfx::Rect
& device_viewport_damage_rect
,
101 LayerTreeHostImpl::FrameData
* frame
);
104 bool ShouldComposite() const;
105 void UpdateBackgroundAnimateTicking();
107 // Accessed on main thread only.
108 LayerTreeHost
* layer_tree_host_
;
109 LayerTreeHostSingleThreadClient
* client_
;
110 bool created_offscreen_context_provider_
;
112 // Used on the Thread, but checked on main thread during
113 // initialization/shutdown.
114 scoped_ptr
<LayerTreeHostImpl
> layer_tree_host_impl_
;
115 RendererCapabilities renderer_capabilities_for_main_thread_
;
117 bool next_frame_is_newly_committed_frame_
;
121 DISALLOW_COPY_AND_ASSIGN(SingleThreadProxy
);
124 // For use in the single-threaded case. In debug builds, it pretends that the
125 // code is running on the impl thread to satisfy assertion checks.
126 class DebugScopedSetImplThread
{
128 explicit DebugScopedSetImplThread(Proxy
* proxy
) : proxy_(proxy
) {
130 previous_value_
= proxy_
->impl_thread_is_overridden_
;
131 proxy_
->SetCurrentThreadIsImplThread(true);
134 ~DebugScopedSetImplThread() {
136 proxy_
->SetCurrentThreadIsImplThread(previous_value_
);
141 bool previous_value_
;
144 DISALLOW_COPY_AND_ASSIGN(DebugScopedSetImplThread
);
147 // For use in the single-threaded case. In debug builds, it pretends that the
148 // code is running on the main thread to satisfy assertion checks.
149 class DebugScopedSetMainThread
{
151 explicit DebugScopedSetMainThread(Proxy
* proxy
) : proxy_(proxy
) {
153 previous_value_
= proxy_
->impl_thread_is_overridden_
;
154 proxy_
->SetCurrentThreadIsImplThread(false);
157 ~DebugScopedSetMainThread() {
159 proxy_
->SetCurrentThreadIsImplThread(previous_value_
);
164 bool previous_value_
;
167 DISALLOW_COPY_AND_ASSIGN(DebugScopedSetMainThread
);
170 // For use in the single-threaded case. In debug builds, it pretends that the
171 // code is running on the impl thread and that the main thread is blocked to
172 // satisfy assertion checks
173 class DebugScopedSetImplThreadAndMainThreadBlocked
{
175 explicit DebugScopedSetImplThreadAndMainThreadBlocked(Proxy
* proxy
)
176 : impl_thread_(proxy
), main_thread_blocked_(proxy
) {}
179 DebugScopedSetImplThread impl_thread_
;
180 DebugScopedSetMainThreadBlocked main_thread_blocked_
;
182 DISALLOW_COPY_AND_ASSIGN(DebugScopedSetImplThreadAndMainThreadBlocked
);
187 #endif // CC_TREES_SINGLE_THREAD_PROXY_H_