Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(166)

Side by Side Diff: ui/compositor/compositor.h

Issue 548153004: Unified BeginFrame scheduling (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: git cl format Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ui/compositor/DEPS ('k') | ui/compositor/compositor.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef UI_COMPOSITOR_COMPOSITOR_H_ 5 #ifndef UI_COMPOSITOR_COMPOSITOR_H_
6 #define UI_COMPOSITOR_COMPOSITOR_H_ 6 #define UI_COMPOSITOR_COMPOSITOR_H_
7 7
8 #include <string> 8 #include <string>
9 9
10 #include "base/containers/hash_tables.h" 10 #include "base/containers/hash_tables.h"
11 #include "base/memory/ref_counted.h" 11 #include "base/memory/ref_counted.h"
12 #include "base/memory/scoped_ptr.h" 12 #include "base/memory/scoped_ptr.h"
13 #include "base/observer_list.h" 13 #include "base/observer_list.h"
14 #include "base/single_thread_task_runner.h" 14 #include "base/single_thread_task_runner.h"
15 #include "base/time/time.h" 15 #include "base/time/time.h"
16 #include "cc/output/begin_frame_args.h"
16 #include "cc/trees/layer_tree_host_client.h" 17 #include "cc/trees/layer_tree_host_client.h"
17 #include "cc/trees/layer_tree_host_single_thread_client.h" 18 #include "cc/trees/layer_tree_host_single_thread_client.h"
18 #include "third_party/skia/include/core/SkColor.h" 19 #include "third_party/skia/include/core/SkColor.h"
20 #include "ui/base/compositor/compositor_begin_frame_observer.h"
19 #include "ui/compositor/compositor_animation_observer.h" 21 #include "ui/compositor/compositor_animation_observer.h"
20 #include "ui/compositor/compositor_export.h" 22 #include "ui/compositor/compositor_export.h"
21 #include "ui/compositor/compositor_observer.h" 23 #include "ui/compositor/compositor_observer.h"
22 #include "ui/compositor/layer_animator_collection.h" 24 #include "ui/compositor/layer_animator_collection.h"
23 #include "ui/gfx/native_widget_types.h" 25 #include "ui/gfx/native_widget_types.h"
24 #include "ui/gfx/size.h" 26 #include "ui/gfx/size.h"
25 #include "ui/gfx/vector2d.h" 27 #include "ui/gfx/vector2d.h"
26 28
27 class SkBitmap; 29 class SkBitmap;
28 30
(...skipping 15 matching lines...) Expand all
44 class Size; 46 class Size;
45 } 47 }
46 48
47 namespace gpu { 49 namespace gpu {
48 struct Mailbox; 50 struct Mailbox;
49 } 51 }
50 52
51 namespace ui { 53 namespace ui {
52 54
53 class Compositor; 55 class Compositor;
54 class CompositorVSyncManager;
55 class Layer; 56 class Layer;
56 class Reflector; 57 class Reflector;
57 class Texture; 58 class Texture;
58 struct LatencyInfo; 59 struct LatencyInfo;
59 60
60 // This class abstracts the creation of the 3D context for the compositor. It is 61 // This class abstracts the creation of the 3D context for the compositor. It is
61 // a global object. 62 // a global object.
62 class COMPOSITOR_EXPORT ContextFactory { 63 class COMPOSITOR_EXPORT ContextFactory {
63 public: 64 public:
64 virtual ~ContextFactory() {} 65 virtual ~ContextFactory() {}
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
185 // Sets the background color used for areas that aren't covered by 186 // Sets the background color used for areas that aren't covered by
186 // the |root_layer|. 187 // the |root_layer|.
187 void SetBackgroundColor(SkColor color); 188 void SetBackgroundColor(SkColor color);
188 189
189 // Set the visibility of the underlying compositor. 190 // Set the visibility of the underlying compositor.
190 void SetVisible(bool visible); 191 void SetVisible(bool visible);
191 192
192 // Returns the widget for this compositor. 193 // Returns the widget for this compositor.
193 gfx::AcceleratedWidget widget() const { return widget_; } 194 gfx::AcceleratedWidget widget() const { return widget_; }
194 195
195 // Returns the vsync manager for this compositor. 196 // The "authoritative" vsync interval, if provided, will override interval
196 scoped_refptr<CompositorVSyncManager> vsync_manager() const; 197 // reported from 3D context. This is typically the value reported by a more
198 // reliable source, e.g, the platform display configuration.
199 // In the particular case of ChromeOS -- this is the value queried through
200 // XRandR, which is more reliable than the value queried through the 3D
201 // context.
202 void SetAuthoritativeVSyncInterval(base::TimeDelta interval) const;
203
204 // Request BeginFrame scheduling to OutputSurface.
205 void StartBeginFrame(const cc::BeginFrameArgs& args) const;
197 206
198 // Returns the main thread task runner this compositor uses. Users of the 207 // Returns the main thread task runner this compositor uses. Users of the
199 // compositor generally shouldn't use this. 208 // compositor generally shouldn't use this.
200 scoped_refptr<base::SingleThreadTaskRunner> task_runner() const { 209 scoped_refptr<base::SingleThreadTaskRunner> task_runner() const {
201 return task_runner_; 210 return task_runner_;
202 } 211 }
203 212
204 // Compositor does not own observers. It is the responsibility of the 213 // Compositor does not own observers. It is the responsibility of the
205 // observer to remove itself when it is done observing. 214 // observer to remove itself when it is done observing.
206 void AddObserver(CompositorObserver* observer); 215 void AddObserver(CompositorObserver* observer);
207 void RemoveObserver(CompositorObserver* observer); 216 void RemoveObserver(CompositorObserver* observer);
208 bool HasObserver(CompositorObserver* observer); 217 bool HasObserver(CompositorObserver* observer);
209 218
210 void AddAnimationObserver(CompositorAnimationObserver* observer); 219 void AddAnimationObserver(CompositorAnimationObserver* observer);
211 void RemoveAnimationObserver(CompositorAnimationObserver* observer); 220 void RemoveAnimationObserver(CompositorAnimationObserver* observer);
212 bool HasAnimationObserver(CompositorAnimationObserver* observer); 221 bool HasAnimationObserver(CompositorAnimationObserver* observer);
213 222
223 void AddBeginFrameObserver(
224 CompositorBeginFrameObserver* observer,
225 const cc::BeginFrameArgs& last_begin_frame_args_sent_to_observer);
226 void RemoveBeginFrameObserver(CompositorBeginFrameObserver* observer);
227
214 // Creates a compositor lock. Returns NULL if it is not possible to lock at 228 // Creates a compositor lock. Returns NULL if it is not possible to lock at
215 // this time (i.e. we're waiting to complete a previous unlock). 229 // this time (i.e. we're waiting to complete a previous unlock).
216 scoped_refptr<CompositorLock> GetCompositorLock(); 230 scoped_refptr<CompositorLock> GetCompositorLock();
217 231
218 // Internal functions, called back by command-buffer contexts on swap buffer 232 // Internal functions, called back by command-buffer contexts on swap buffer
219 // events. 233 // events.
220 234
221 // Signals swap has been posted. 235 // Signals swap has been posted.
222 void OnSwapBuffersPosted(); 236 void OnSwapBuffersPosted();
223 237
224 // Signals swap has completed. 238 // Signals swap has completed.
225 void OnSwapBuffersComplete(); 239 void OnSwapBuffersComplete();
226 240
227 // Signals swap has aborted (e.g. lost context). 241 // Signals swap has aborted (e.g. lost context).
228 void OnSwapBuffersAborted(); 242 void OnSwapBuffersAborted();
229 243
230 // LayerTreeHostClient implementation. 244 // LayerTreeHostClient implementation.
231 virtual void WillBeginMainFrame(int frame_id) OVERRIDE {} 245 virtual void WillBeginMainFrame(int frame_id) OVERRIDE {}
232 virtual void DidBeginMainFrame() OVERRIDE {} 246 virtual void DidBeginMainFrame() OVERRIDE {}
233 virtual void BeginMainFrame(const cc::BeginFrameArgs& args) OVERRIDE; 247 virtual void BeginMainFrame(const cc::BeginFrameArgs& args) OVERRIDE;
234 virtual void Layout() OVERRIDE; 248 virtual void Layout() OVERRIDE;
235 virtual void ApplyScrollAndScale(const gfx::Vector2d& scroll_delta, 249 virtual void ApplyScrollAndScale(const gfx::Vector2d& scroll_delta,
236 float page_scale) OVERRIDE {} 250 float page_scale) OVERRIDE {}
237 virtual scoped_ptr<cc::OutputSurface> CreateOutputSurface(bool fallback) 251 virtual scoped_ptr<cc::OutputSurface> CreateOutputSurface(bool fallback)
238 OVERRIDE; 252 OVERRIDE;
239 virtual void DidInitializeOutputSurface() OVERRIDE {} 253 virtual void DidInitializeOutputSurface() OVERRIDE;
254 virtual void DidLoseOutputSurface() OVERRIDE;
240 virtual void WillCommit() OVERRIDE {} 255 virtual void WillCommit() OVERRIDE {}
241 virtual void DidCommit() OVERRIDE; 256 virtual void DidCommit() OVERRIDE;
242 virtual void DidCommitAndDrawFrame() OVERRIDE; 257 virtual void DidCommitAndDrawFrame() OVERRIDE;
243 virtual void DidCompleteSwapBuffers() OVERRIDE; 258 virtual void DidCompleteSwapBuffers() OVERRIDE;
259 virtual void SendBeginFrameToChildren(
260 const cc::BeginFrameArgs& args) OVERRIDE;
244 261
245 // cc::LayerTreeHostSingleThreadClient implementation. 262 // cc::LayerTreeHostSingleThreadClient implementation.
246 virtual void ScheduleComposite() OVERRIDE; 263 virtual void ScheduleComposite() OVERRIDE;
247 virtual void ScheduleAnimation() OVERRIDE; 264 virtual void ScheduleAnimation() OVERRIDE;
248 virtual void DidPostSwapBuffers() OVERRIDE; 265 virtual void DidPostSwapBuffers() OVERRIDE;
249 virtual void DidAbortSwapBuffers() OVERRIDE; 266 virtual void DidAbortSwapBuffers() OVERRIDE;
250 267
251 int last_started_frame() { return last_started_frame_; } 268 int last_started_frame() { return last_started_frame_; }
252 int last_ended_frame() { return last_ended_frame_; } 269 int last_ended_frame() { return last_ended_frame_; }
253 270
(...skipping 12 matching lines...) Expand all
266 283
267 // Called by CompositorLock. 284 // Called by CompositorLock.
268 void UnlockCompositor(); 285 void UnlockCompositor();
269 286
270 // Called to release any pending CompositorLock 287 // Called to release any pending CompositorLock
271 void CancelCompositorLock(); 288 void CancelCompositorLock();
272 289
273 // Notifies the compositor that compositing is complete. 290 // Notifies the compositor that compositing is complete.
274 void NotifyEnd(); 291 void NotifyEnd();
275 292
293 // Request scheduling of next BeginFrame to LayerTreeHost.
294 void SetChildrenNeedBeginFrames(bool need_begin_frame);
295
276 gfx::Size size_; 296 gfx::Size size_;
277 297
278 ui::ContextFactory* context_factory_; 298 ui::ContextFactory* context_factory_;
279 299
280 // The root of the Layer tree drawn by this compositor. 300 // The root of the Layer tree drawn by this compositor.
281 Layer* root_layer_; 301 Layer* root_layer_;
282 302
283 ObserverList<CompositorObserver> observer_list_; 303 ObserverList<CompositorObserver> observer_list_;
284 ObserverList<CompositorAnimationObserver> animation_observer_list_; 304 ObserverList<CompositorAnimationObserver> animation_observer_list_;
305 ObserverList<CompositorBeginFrameObserver> begin_frame_observer_list_;
285 306
286 gfx::AcceleratedWidget widget_; 307 gfx::AcceleratedWidget widget_;
287 scoped_refptr<cc::Layer> root_web_layer_; 308 scoped_refptr<cc::Layer> root_web_layer_;
288 scoped_ptr<cc::LayerTreeHost> host_; 309 scoped_ptr<cc::LayerTreeHost> host_;
289 scoped_refptr<base::MessageLoopProxy> compositor_thread_loop_; 310 scoped_refptr<base::MessageLoopProxy> compositor_thread_loop_;
290 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; 311 scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
291 312
292 // The manager of vsync parameters for this compositor.
293 scoped_refptr<CompositorVSyncManager> vsync_manager_;
294
295 // The device scale factor of the monitor that this compositor is compositing 313 // The device scale factor of the monitor that this compositor is compositing
296 // layers on. 314 // layers on.
297 float device_scale_factor_; 315 float device_scale_factor_;
298 316
299 int last_started_frame_; 317 int last_started_frame_;
300 int last_ended_frame_; 318 int last_ended_frame_;
301 319
302 bool disable_schedule_composite_; 320 bool disable_schedule_composite_;
303 321
304 CompositorLock* compositor_lock_; 322 CompositorLock* compositor_lock_;
305 323
306 // Prevent more than one draw from being scheduled. 324 // Prevent more than one draw from being scheduled.
307 bool defer_draw_scheduling_; 325 bool defer_draw_scheduling_;
308 326
309 // Used to prevent Draw()s while a composite is in progress. 327 // Used to prevent Draw()s while a composite is in progress.
310 bool waiting_on_compositing_end_; 328 bool waiting_on_compositing_end_;
311 bool draw_on_compositing_end_; 329 bool draw_on_compositing_end_;
312 enum SwapState { SWAP_NONE, SWAP_POSTED, SWAP_COMPLETED }; 330 enum SwapState { SWAP_NONE, SWAP_POSTED, SWAP_COMPLETED };
313 SwapState swap_state_; 331 SwapState swap_state_;
314 332
315 LayerAnimatorCollection layer_animator_collection_; 333 LayerAnimatorCollection layer_animator_collection_;
316 334
317 base::WeakPtrFactory<Compositor> schedule_draw_factory_; 335 base::WeakPtrFactory<Compositor> schedule_draw_factory_;
318 336
337 // Used to send to any new BeginFrame observers immediately.
338 cc::BeginFrameArgs last_begin_frame_args_;
339
340 // Only used to post OutputSurface::BeginFrame to |task_runner_|. because
341 // requesting a BeginFrame from compositor is only used on single threaded
342 // mode.
343 base::WeakPtr<cc::OutputSurface> output_surface_weak_ptr_;
344
345 bool output_surface_lost_;
346
319 DISALLOW_COPY_AND_ASSIGN(Compositor); 347 DISALLOW_COPY_AND_ASSIGN(Compositor);
320 }; 348 };
321 349
322 } // namespace ui 350 } // namespace ui
323 351
324 #endif // UI_COMPOSITOR_COMPOSITOR_H_ 352 #endif // UI_COMPOSITOR_COMPOSITOR_H_
OLDNEW
« no previous file with comments | « ui/compositor/DEPS ('k') | ui/compositor/compositor.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698