Pass gfx::Rect and gfx::RectF by const ref.
[chromium-blink-merge.git] / cc / trees / single_thread_proxy.h
blob616f5767b1e14c66b2a3fe669d92e31b1678c1b4
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_
8 #include <limits>
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"
16 namespace cc {
18 class ContextProvider;
19 class LayerTreeHost;
20 class LayerTreeHostSingleThreadClient;
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();
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)
61 OVERRIDE {}
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(
74 size_t limit_bytes,
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)
80 OVERRIDE {}
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);
87 private:
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,
94 bool for_readback,
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,
100 bool for_readback,
101 LayerTreeHostImpl::FrameData* frame);
102 void DidSwapFrame();
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_;
119 bool inside_draw_;
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 {
127 public:
128 explicit DebugScopedSetImplThread(Proxy* proxy) : proxy_(proxy) {
129 #ifndef NDEBUG
130 previous_value_ = proxy_->impl_thread_is_overridden_;
131 proxy_->SetCurrentThreadIsImplThread(true);
132 #endif
134 ~DebugScopedSetImplThread() {
135 #ifndef NDEBUG
136 proxy_->SetCurrentThreadIsImplThread(previous_value_);
137 #endif
140 private:
141 bool previous_value_;
142 Proxy* proxy_;
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 {
150 public:
151 explicit DebugScopedSetMainThread(Proxy* proxy) : proxy_(proxy) {
152 #ifndef NDEBUG
153 previous_value_ = proxy_->impl_thread_is_overridden_;
154 proxy_->SetCurrentThreadIsImplThread(false);
155 #endif
157 ~DebugScopedSetMainThread() {
158 #ifndef NDEBUG
159 proxy_->SetCurrentThreadIsImplThread(previous_value_);
160 #endif
163 private:
164 bool previous_value_;
165 Proxy* proxy_;
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 {
174 public:
175 explicit DebugScopedSetImplThreadAndMainThreadBlocked(Proxy* proxy)
176 : impl_thread_(proxy), main_thread_blocked_(proxy) {}
178 private:
179 DebugScopedSetImplThread impl_thread_;
180 DebugScopedSetMainThreadBlocked main_thread_blocked_;
182 DISALLOW_COPY_AND_ASSIGN(DebugScopedSetImplThreadAndMainThreadBlocked);
185 } // namespace cc
187 #endif // CC_TREES_SINGLE_THREAD_PROXY_H_