Fix build break
[chromium-blink-merge.git] / cc / trees / thread_proxy.h
blobfccde44645ebea06a826c6ce5dfbb375d883fc9a
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_THREAD_PROXY_H_
6 #define CC_TREES_THREAD_PROXY_H_
8 #include "base/memory/scoped_ptr.h"
9 #include "base/memory/weak_ptr.h"
10 #include "base/time.h"
11 #include "cc/animation/animation_events.h"
12 #include "cc/base/completion_event.h"
13 #include "cc/resources/resource_update_controller.h"
14 #include "cc/scheduler/scheduler.h"
15 #include "cc/scheduler/vsync_time_source.h"
16 #include "cc/trees/layer_tree_host_impl.h"
17 #include "cc/trees/proxy.h"
19 namespace cc {
21 class ContextProvider;
22 class InputHandler;
23 class LayerTreeHost;
24 class ResourceUpdateQueue;
25 class Scheduler;
26 class ScopedThreadProxy;
27 class Thread;
29 class ThreadProxy : public Proxy,
30 LayerTreeHostImplClient,
31 SchedulerClient,
32 ResourceUpdateControllerClient,
33 VSyncProvider {
34 public:
35 static scoped_ptr<Proxy> Create(LayerTreeHost* layer_tree_host,
36 scoped_ptr<Thread> impl_thread);
38 virtual ~ThreadProxy();
40 // Proxy implementation
41 virtual bool CompositeAndReadback(void* pixels, gfx::Rect rect) OVERRIDE;
42 virtual void FinishAllRendering() OVERRIDE;
43 virtual bool IsStarted() const OVERRIDE;
44 virtual bool InitializeOutputSurface() OVERRIDE;
45 virtual void SetSurfaceReady() OVERRIDE;
46 virtual void SetVisible(bool visible) OVERRIDE;
47 virtual bool InitializeRenderer() OVERRIDE;
48 virtual bool RecreateOutputSurface() OVERRIDE;
49 virtual const RendererCapabilities& GetRendererCapabilities() const OVERRIDE;
50 virtual void SetNeedsAnimate() OVERRIDE;
51 virtual void SetNeedsCommit() OVERRIDE;
52 virtual void SetNeedsRedraw(const gfx::Rect& damage_rect) OVERRIDE;
53 virtual void SetDeferCommits(bool defer_commits) OVERRIDE;
54 virtual bool CommitRequested() const OVERRIDE;
55 virtual void MainThreadHasStoppedFlinging() OVERRIDE;
56 virtual void Start() OVERRIDE;
57 virtual void Stop() OVERRIDE;
58 virtual size_t MaxPartialTextureUpdates() const OVERRIDE;
59 virtual void AcquireLayerTextures() OVERRIDE;
60 virtual void ForceSerializeOnSwapBuffers() OVERRIDE;
61 virtual skia::RefPtr<SkPicture> CapturePicture() OVERRIDE;
62 virtual scoped_ptr<base::Value> AsValue() const OVERRIDE;
63 virtual bool CommitPendingForTesting() OVERRIDE;
65 // LayerTreeHostImplClient implementation
66 virtual void DidLoseOutputSurfaceOnImplThread() OVERRIDE;
67 virtual void OnSwapBuffersCompleteOnImplThread() OVERRIDE;
68 virtual void OnVSyncParametersChanged(base::TimeTicks timebase,
69 base::TimeDelta interval) OVERRIDE;
70 virtual void DidVSync(base::TimeTicks frame_time) OVERRIDE;
71 virtual void OnCanDrawStateChanged(bool can_draw) OVERRIDE;
72 virtual void OnHasPendingTreeStateChanged(bool has_pending_tree) OVERRIDE;
73 virtual void SetNeedsRedrawOnImplThread() OVERRIDE;
74 virtual void DidInitializeVisibleTileOnImplThread() OVERRIDE;
75 virtual void SetNeedsCommitOnImplThread() OVERRIDE;
76 virtual void SetNeedsManageTilesOnImplThread() OVERRIDE;
77 virtual void PostAnimationEventsToMainThreadOnImplThread(
78 scoped_ptr<AnimationEventsVector> queue,
79 base::Time wall_clock_time) OVERRIDE;
80 virtual bool ReduceContentsTextureMemoryOnImplThread(size_t limit_bytes,
81 int priority_cutoff)
82 OVERRIDE;
83 virtual void ReduceWastedContentsTextureMemoryOnImplThread() OVERRIDE;
84 virtual void SendManagedMemoryStats() OVERRIDE;
85 virtual bool IsInsideDraw() OVERRIDE;
86 virtual void RenewTreePriority() OVERRIDE;
87 virtual void RequestScrollbarAnimationOnImplThread(base::TimeDelta delay)
88 OVERRIDE;
90 // SchedulerClient implementation
91 virtual void ScheduledActionBeginFrame() OVERRIDE;
92 virtual ScheduledActionDrawAndSwapResult
93 ScheduledActionDrawAndSwapIfPossible() OVERRIDE;
94 virtual ScheduledActionDrawAndSwapResult ScheduledActionDrawAndSwapForced()
95 OVERRIDE;
96 virtual void ScheduledActionCommit() OVERRIDE;
97 virtual void ScheduledActionCheckForCompletedTileUploads() OVERRIDE;
98 virtual void ScheduledActionActivatePendingTreeIfNeeded() OVERRIDE;
99 virtual void ScheduledActionBeginContextRecreation() OVERRIDE;
100 virtual void ScheduledActionAcquireLayerTexturesForMainThread() OVERRIDE;
101 virtual void DidAnticipatedDrawTimeChange(base::TimeTicks time) OVERRIDE;
103 // ResourceUpdateControllerClient implementation
104 virtual void ReadyToFinalizeTextureUpdates() OVERRIDE;
106 // VSyncProvider implementation
107 virtual void RequestVSyncNotification(VSyncClient* client) OVERRIDE;
109 int MaxFramesPendingForTesting() const {
110 return scheduler_on_impl_thread_->MaxFramesPending();
113 private:
114 ThreadProxy(LayerTreeHost* layer_tree_host, scoped_ptr<Thread> impl_thread);
116 struct BeginFrameAndCommitState {
117 BeginFrameAndCommitState();
118 ~BeginFrameAndCommitState();
120 base::TimeTicks monotonic_frame_begin_time;
121 scoped_ptr<ScrollAndScaleSet> scroll_info;
122 gfx::Transform impl_transform;
123 size_t memory_allocation_limit_bytes;
126 // Called on main thread.
127 void BeginFrame(scoped_ptr<BeginFrameAndCommitState> begin_frame_state);
128 void DidCommitAndDrawFrame();
129 void DidCompleteSwapBuffers();
130 void SetAnimationEvents(scoped_ptr<AnimationEventsVector> queue,
131 base::Time wall_clock_time);
132 void BeginContextRecreation();
133 void TryToRecreateOutputSurface();
135 // Called on impl thread.
136 struct ReadbackRequest {
137 CompletionEvent completion;
138 bool success;
139 void* pixels;
140 gfx::Rect rect;
142 struct CommitPendingRequest {
143 CompletionEvent completion;
144 bool commit_pending;
146 void ForceBeginFrameOnImplThread(CompletionEvent* completion);
147 void BeginFrameCompleteOnImplThread(
148 CompletionEvent* completion,
149 ResourceUpdateQueue* queue,
150 scoped_refptr<cc::ContextProvider> offscreen_context_provider);
151 void BeginFrameAbortedOnImplThread();
152 void RequestReadbackOnImplThread(ReadbackRequest* request);
153 void FinishAllRenderingOnImplThread(CompletionEvent* completion);
154 void InitializeImplOnImplThread(CompletionEvent* completion,
155 InputHandler* input_handler);
156 void SetSurfaceReadyOnImplThread();
157 void SetVisibleOnImplThread(CompletionEvent* completion, bool visible);
158 void InitializeOutputSurfaceOnImplThread(
159 scoped_ptr<OutputSurface> output_surface);
160 void InitializeRendererOnImplThread(CompletionEvent* completion,
161 bool* initialize_succeeded,
162 RendererCapabilities* capabilities);
163 void LayerTreeHostClosedOnImplThread(CompletionEvent* completion);
164 void ManageTilesOnImplThread();
165 void SetViewportDamageOnImplThread(const gfx::Rect& damage_rect);
166 void AcquireLayerTexturesForMainThreadOnImplThread(
167 CompletionEvent* completion);
168 void RecreateOutputSurfaceOnImplThread(
169 CompletionEvent* completion,
170 scoped_ptr<OutputSurface> output_surface,
171 scoped_refptr<cc::ContextProvider> offscreen_context_provider,
172 bool* recreate_succeeded,
173 RendererCapabilities* capabilities);
174 ScheduledActionDrawAndSwapResult ScheduledActionDrawAndSwapInternal(
175 bool forced_draw);
176 void ForceSerializeOnSwapBuffersOnImplThread(CompletionEvent* completion);
177 void SetNeedsForcedCommitOnImplThread();
178 void CheckOutputSurfaceStatusOnImplThread();
179 void CommitPendingOnImplThreadForTesting(CommitPendingRequest* request);
180 void CapturePictureOnImplThread(CompletionEvent* completion,
181 skia::RefPtr<SkPicture>* picture);
182 void AsValueOnImplThread(CompletionEvent* completion,
183 base::DictionaryValue* state) const;
184 void RenewTreePriorityOnImplThread();
185 void DidSwapUseIncompleteTileOnImplThread();
186 void StartScrollbarAnimationOnImplThread();
188 // Accessed on main thread only.
190 // Set only when SetNeedsAnimate is called.
191 bool animate_requested_;
192 // Set only when SetNeedsCommit is called.
193 bool commit_requested_;
194 // Set by SetNeedsCommit and SetNeedsAnimate.
195 bool commit_request_sent_to_impl_thread_;
196 // Set by BeginFrame
197 bool created_offscreen_context_provider_;
198 base::CancelableClosure output_surface_recreation_callback_;
199 LayerTreeHost* layer_tree_host_;
200 bool renderer_initialized_;
201 RendererCapabilities renderer_capabilities_main_thread_copy_;
202 bool started_;
203 bool textures_acquired_;
204 bool in_composite_and_readback_;
205 bool manage_tiles_pending_;
206 // Weak pointer to use when posting tasks to the impl thread.
207 base::WeakPtr<ThreadProxy> impl_thread_weak_ptr_;
209 base::WeakPtrFactory<ThreadProxy> weak_factory_on_impl_thread_;
211 base::WeakPtr<ThreadProxy> main_thread_weak_ptr_;
212 base::WeakPtrFactory<ThreadProxy> weak_factory_;
214 scoped_ptr<LayerTreeHostImpl> layer_tree_host_impl_;
216 scoped_ptr<InputHandler> input_handler_on_impl_thread_;
218 scoped_ptr<Scheduler> scheduler_on_impl_thread_;
220 // Holds on to the context we might use for compositing in between
221 // InitializeContext() and InitializeRenderer() calls.
222 scoped_ptr<OutputSurface>
223 output_surface_before_initialization_on_impl_thread_;
225 // Set when the main thread is waiting on a ScheduledActionBeginFrame to be
226 // issued.
227 CompletionEvent* begin_frame_completion_event_on_impl_thread_;
229 // Set when the main thread is waiting on a readback.
230 ReadbackRequest* readback_request_on_impl_thread_;
232 // Set when the main thread is waiting on a commit to complete.
233 CompletionEvent* commit_completion_event_on_impl_thread_;
235 // Set when the main thread is waiting on a pending tree activation.
236 CompletionEvent* completion_event_for_commit_held_on_tree_activation_;
238 // Set when the main thread is waiting on layers to be drawn.
239 CompletionEvent* texture_acquisition_completion_event_on_impl_thread_;
241 scoped_ptr<ResourceUpdateController>
242 current_resource_update_controller_on_impl_thread_;
244 // Set when the next draw should post DidCommitAndDrawFrame to the main
245 // thread.
246 bool next_frame_is_newly_committed_frame_on_impl_thread_;
248 bool render_vsync_enabled_;
249 bool render_vsync_notification_enabled_;
250 VSyncClient* vsync_client_;
252 bool inside_draw_;
254 bool defer_commits_;
255 scoped_ptr<BeginFrameAndCommitState> pending_deferred_commit_;
257 base::TimeTicks smoothness_takes_priority_expiration_time_;
258 bool renew_tree_priority_on_impl_thread_pending_;
260 DISALLOW_COPY_AND_ASSIGN(ThreadProxy);
263 } // namespace cc
265 #endif // CC_TREES_THREAD_PROXY_H_