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;
21 class SingleThreadProxy : public Proxy, LayerTreeHostImplClient {
23 static scoped_ptr<Proxy> Create(LayerTreeHost* layer_tree_host);
24 virtual ~SingleThreadProxy();
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;
52 // LayerTreeHostImplClient implementation
53 virtual void DidLoseOutputSurfaceOnImplThread() OVERRIDE;
54 virtual void OnSwapBuffersCompleteOnImplThread() OVERRIDE {}
55 virtual void BeginImplFrame(const BeginFrameArgs& args)
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(
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)
75 virtual void DidActivatePendingTree() OVERRIDE {}
77 // Called by the legacy path where RenderWidget does the scheduling.
78 void CompositeImmediately(base::TimeTicks frame_begin_time);
81 explicit SingleThreadProxy(LayerTreeHost* layer_tree_host);
83 void OnOutputSurfaceInitializeAttempted(bool success);
84 bool CommitAndComposite(base::TimeTicks frame_begin_time,
85 gfx::Rect device_viewport_damage_rect,
87 LayerTreeHostImpl::FrameData* frame);
88 void DoCommit(scoped_ptr<ResourceUpdateQueue> queue);
90 scoped_refptr<cc::ContextProvider> offscreen_context_provider,
91 base::TimeTicks frame_begin_time,
92 gfx::Rect device_viewport_damage_rect,
94 LayerTreeHostImpl::FrameData* frame);
97 bool ShouldComposite() const;
98 void UpdateBackgroundAnimateTicking();
100 // Accessed on main thread only.
101 LayerTreeHost* layer_tree_host_;
102 bool created_offscreen_context_provider_;
104 // Holds the first output surface passed from Start. Should not be used for
106 scoped_ptr<OutputSurface> first_output_surface_;
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_;
113 bool next_frame_is_newly_committed_frame_;
117 DISALLOW_COPY_AND_ASSIGN(SingleThreadProxy);
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 {
124 explicit DebugScopedSetImplThread(Proxy* proxy) : proxy_(proxy) {
126 previous_value_ = proxy_->impl_thread_is_overridden_;
127 proxy_->SetCurrentThreadIsImplThread(true);
130 ~DebugScopedSetImplThread() {
132 proxy_->SetCurrentThreadIsImplThread(previous_value_);
137 bool previous_value_;
140 DISALLOW_COPY_AND_ASSIGN(DebugScopedSetImplThread);
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 {
147 explicit DebugScopedSetMainThread(Proxy* proxy) : proxy_(proxy) {
149 previous_value_ = proxy_->impl_thread_is_overridden_;
150 proxy_->SetCurrentThreadIsImplThread(false);
153 ~DebugScopedSetMainThread() {
155 proxy_->SetCurrentThreadIsImplThread(previous_value_);
160 bool previous_value_;
163 DISALLOW_COPY_AND_ASSIGN(DebugScopedSetMainThread);
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 {
171 explicit DebugScopedSetImplThreadAndMainThreadBlocked(Proxy* proxy)
172 : impl_thread_(proxy), main_thread_blocked_(proxy) {}
175 DebugScopedSetImplThread impl_thread_;
176 DebugScopedSetMainThreadBlocked main_thread_blocked_;
178 DISALLOW_COPY_AND_ASSIGN(DebugScopedSetImplThreadAndMainThreadBlocked);
183 #endif // CC_TREES_SINGLE_THREAD_PROXY_H_