Lots of random cleanups, mostly for native_theme_win.cc:
[chromium-blink-merge.git] / cc / trees / single_thread_proxy.h
blob73fa653222556c30678ac40403e4a8aadeaa5f51
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 CC_EXPORT SingleThreadProxy : public Proxy,
23 NON_EXPORTED_BASE(LayerTreeHostImplClient) {
24 public:
25 static scoped_ptr<Proxy> Create(
26 LayerTreeHost* layer_tree_host,
27 LayerTreeHostSingleThreadClient* client);
28 virtual ~SingleThreadProxy();
30 // Proxy implementation
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 const RendererCapabilities& GetRendererCapabilities() const OVERRIDE;
36 virtual void SetNeedsAnimate() OVERRIDE;
37 virtual void SetNeedsUpdateLayers() OVERRIDE;
38 virtual void SetNeedsCommit() OVERRIDE;
39 virtual void SetNeedsRedraw(const gfx::Rect& damage_rect) OVERRIDE;
40 virtual void SetNextCommitWaitsForActivation() OVERRIDE;
41 virtual void NotifyInputThrottledUntilCommit() OVERRIDE {}
42 virtual void SetDeferCommits(bool defer_commits) OVERRIDE;
43 virtual bool CommitRequested() const OVERRIDE;
44 virtual bool BeginMainFrameRequested() const OVERRIDE;
45 virtual void MainThreadHasStoppedFlinging() OVERRIDE {}
46 virtual void Start() OVERRIDE;
47 virtual void Stop() OVERRIDE;
48 virtual size_t MaxPartialTextureUpdates() const OVERRIDE;
49 virtual void ForceSerializeOnSwapBuffers() OVERRIDE;
50 virtual bool SupportsImplScrolling() const OVERRIDE;
51 virtual scoped_ptr<base::Value> AsValue() const OVERRIDE;
52 virtual bool CommitPendingForTesting() OVERRIDE;
54 // LayerTreeHostImplClient implementation
55 virtual void UpdateRendererCapabilitiesOnImplThread() OVERRIDE;
56 virtual void DidLoseOutputSurfaceOnImplThread() OVERRIDE;
57 virtual void CommitVSyncParameters(base::TimeTicks timebase,
58 base::TimeDelta interval) OVERRIDE {}
59 virtual void SetEstimatedParentDrawTime(base::TimeDelta draw_time) OVERRIDE {}
60 virtual void SetMaxSwapsPendingOnImplThread(int max) OVERRIDE {}
61 virtual void DidSwapBuffersOnImplThread() OVERRIDE;
62 virtual void DidSwapBuffersCompleteOnImplThread() OVERRIDE;
63 virtual void BeginFrame(const BeginFrameArgs& args) OVERRIDE {}
64 virtual void OnCanDrawStateChanged(bool can_draw) OVERRIDE;
65 virtual void NotifyReadyToActivate() OVERRIDE;
66 virtual void SetNeedsRedrawOnImplThread() OVERRIDE;
67 virtual void SetNeedsRedrawRectOnImplThread(
68 const gfx::Rect& dirty_rect) OVERRIDE;
69 virtual void SetNeedsAnimateOnImplThread() OVERRIDE;
70 virtual void SetNeedsManageTilesOnImplThread() OVERRIDE;
71 virtual void DidInitializeVisibleTileOnImplThread() OVERRIDE;
72 virtual void SetNeedsCommitOnImplThread() OVERRIDE;
73 virtual void PostAnimationEventsToMainThreadOnImplThread(
74 scoped_ptr<AnimationEventsVector> events) OVERRIDE;
75 virtual bool ReduceContentsTextureMemoryOnImplThread(
76 size_t limit_bytes,
77 int priority_cutoff) OVERRIDE;
78 virtual bool IsInsideDraw() OVERRIDE;
79 virtual void RenewTreePriority() OVERRIDE {}
80 virtual void PostDelayedScrollbarFadeOnImplThread(
81 const base::Closure& start_fade,
82 base::TimeDelta delay) OVERRIDE {}
83 virtual void DidActivateSyncTree() OVERRIDE {}
84 virtual void DidManageTiles() OVERRIDE {}
85 virtual void SetDebugState(const LayerTreeDebugState& debug_state) OVERRIDE {}
87 // Attempts to create the context and renderer synchronously. Calls
88 // LayerTreeHost::OnCreateAndInitializeOutputSurfaceAttempted with the result.
89 void CreateAndInitializeOutputSurface();
91 // Called by the legacy path where RenderWidget does the scheduling.
92 void CompositeImmediately(base::TimeTicks frame_begin_time);
94 private:
95 SingleThreadProxy(LayerTreeHost* layer_tree_host,
96 LayerTreeHostSingleThreadClient* client);
98 void DoCommit(scoped_ptr<ResourceUpdateQueue> queue);
99 bool DoComposite(LayerTreeHostImpl::FrameData* frame);
100 void DidSwapFrame();
102 bool ShouldComposite() const;
103 void UpdateBackgroundAnimateTicking();
105 // Accessed on main thread only.
106 LayerTreeHost* layer_tree_host_;
107 LayerTreeHostSingleThreadClient* client_;
109 // Used on the Thread, but checked on main thread during
110 // initialization/shutdown.
111 scoped_ptr<LayerTreeHostImpl> layer_tree_host_impl_;
112 RendererCapabilities renderer_capabilities_for_main_thread_;
114 bool next_frame_is_newly_committed_frame_;
116 bool inside_draw_;
118 DISALLOW_COPY_AND_ASSIGN(SingleThreadProxy);
121 // For use in the single-threaded case. In debug builds, it pretends that the
122 // code is running on the impl thread to satisfy assertion checks.
123 class DebugScopedSetImplThread {
124 public:
125 explicit DebugScopedSetImplThread(Proxy* proxy) : proxy_(proxy) {
126 #if DCHECK_IS_ON
127 previous_value_ = proxy_->impl_thread_is_overridden_;
128 proxy_->SetCurrentThreadIsImplThread(true);
129 #endif
131 ~DebugScopedSetImplThread() {
132 #if DCHECK_IS_ON
133 proxy_->SetCurrentThreadIsImplThread(previous_value_);
134 #endif
137 private:
138 bool previous_value_;
139 Proxy* proxy_;
141 DISALLOW_COPY_AND_ASSIGN(DebugScopedSetImplThread);
144 // For use in the single-threaded case. In debug builds, it pretends that the
145 // code is running on the main thread to satisfy assertion checks.
146 class DebugScopedSetMainThread {
147 public:
148 explicit DebugScopedSetMainThread(Proxy* proxy) : proxy_(proxy) {
149 #if DCHECK_IS_ON
150 previous_value_ = proxy_->impl_thread_is_overridden_;
151 proxy_->SetCurrentThreadIsImplThread(false);
152 #endif
154 ~DebugScopedSetMainThread() {
155 #if DCHECK_IS_ON
156 proxy_->SetCurrentThreadIsImplThread(previous_value_);
157 #endif
160 private:
161 bool previous_value_;
162 Proxy* proxy_;
164 DISALLOW_COPY_AND_ASSIGN(DebugScopedSetMainThread);
167 // For use in the single-threaded case. In debug builds, it pretends that the
168 // code is running on the impl thread and that the main thread is blocked to
169 // satisfy assertion checks
170 class DebugScopedSetImplThreadAndMainThreadBlocked {
171 public:
172 explicit DebugScopedSetImplThreadAndMainThreadBlocked(Proxy* proxy)
173 : impl_thread_(proxy), main_thread_blocked_(proxy) {}
175 private:
176 DebugScopedSetImplThread impl_thread_;
177 DebugScopedSetMainThreadBlocked main_thread_blocked_;
179 DISALLOW_COPY_AND_ASSIGN(DebugScopedSetImplThreadAndMainThreadBlocked);
182 } // namespace cc
184 #endif // CC_TREES_SINGLE_THREAD_PROXY_H_