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

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

Issue 1000503002: Add BeginFrameObserverProxy (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 9 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
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/surfaces/surface_sequence.h" 17 #include "cc/surfaces/surface_sequence.h"
17 #include "cc/trees/layer_tree_host_client.h" 18 #include "cc/trees/layer_tree_host_client.h"
18 #include "cc/trees/layer_tree_host_single_thread_client.h" 19 #include "cc/trees/layer_tree_host_single_thread_client.h"
19 #include "third_party/skia/include/core/SkColor.h" 20 #include "third_party/skia/include/core/SkColor.h"
20 #include "ui/compositor/compositor_animation_observer.h" 21 #include "ui/compositor/compositor_animation_observer.h"
21 #include "ui/compositor/compositor_export.h" 22 #include "ui/compositor/compositor_export.h"
22 #include "ui/compositor/compositor_observer.h" 23 #include "ui/compositor/compositor_observer.h"
23 #include "ui/compositor/layer_animator_collection.h" 24 #include "ui/compositor/layer_animator_collection.h"
24 #include "ui/gfx/geometry/size.h" 25 #include "ui/gfx/geometry/size.h"
25 #include "ui/gfx/geometry/vector2d.h" 26 #include "ui/gfx/geometry/vector2d.h"
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
124 125
125 explicit CompositorLock(Compositor* compositor); 126 explicit CompositorLock(Compositor* compositor);
126 ~CompositorLock(); 127 ~CompositorLock();
127 128
128 void CancelLock(); 129 void CancelLock();
129 130
130 Compositor* compositor_; 131 Compositor* compositor_;
131 DISALLOW_COPY_AND_ASSIGN(CompositorLock); 132 DISALLOW_COPY_AND_ASSIGN(CompositorLock);
132 }; 133 };
133 134
135 // This class observes BeginFrame notification from LayerTreeHost.
136 class COMPOSITOR_EXPORT CompositorBeginFrameObserver {
137 public:
138 virtual ~CompositorBeginFrameObserver() {}
139
140 virtual void OnSendBeginFrame(const cc::BeginFrameArgs& args) = 0;
141 };
142
134 // Compositor object to take care of GPU painting. 143 // Compositor object to take care of GPU painting.
135 // A Browser compositor object is responsible for generating the final 144 // A Browser compositor object is responsible for generating the final
136 // displayable form of pixels comprising a single widget's contents. It draws an 145 // displayable form of pixels comprising a single widget's contents. It draws an
137 // appropriately transformed texture for each transformed view in the widget's 146 // appropriately transformed texture for each transformed view in the widget's
138 // view hierarchy. 147 // view hierarchy.
139 class COMPOSITOR_EXPORT Compositor 148 class COMPOSITOR_EXPORT Compositor
140 : NON_EXPORTED_BASE(public cc::LayerTreeHostClient), 149 : NON_EXPORTED_BASE(public cc::LayerTreeHostClient),
141 NON_EXPORTED_BASE(public cc::LayerTreeHostSingleThreadClient) { 150 NON_EXPORTED_BASE(public cc::LayerTreeHostSingleThreadClient) {
142 public: 151 public:
143 Compositor(gfx::AcceleratedWidget widget, 152 Compositor(gfx::AcceleratedWidget widget,
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
219 // Compositor does not own observers. It is the responsibility of the 228 // Compositor does not own observers. It is the responsibility of the
220 // observer to remove itself when it is done observing. 229 // observer to remove itself when it is done observing.
221 void AddObserver(CompositorObserver* observer); 230 void AddObserver(CompositorObserver* observer);
222 void RemoveObserver(CompositorObserver* observer); 231 void RemoveObserver(CompositorObserver* observer);
223 bool HasObserver(const CompositorObserver* observer) const; 232 bool HasObserver(const CompositorObserver* observer) const;
224 233
225 void AddAnimationObserver(CompositorAnimationObserver* observer); 234 void AddAnimationObserver(CompositorAnimationObserver* observer);
226 void RemoveAnimationObserver(CompositorAnimationObserver* observer); 235 void RemoveAnimationObserver(CompositorAnimationObserver* observer);
227 bool HasAnimationObserver(const CompositorAnimationObserver* observer) const; 236 bool HasAnimationObserver(const CompositorAnimationObserver* observer) const;
228 237
238 void AddBeginFrameObserver(
239 CompositorBeginFrameObserver* observer,
240 const cc::BeginFrameArgs& last_begin_frame_args_sent_to_observer);
241 void RemoveBeginFrameObserver(CompositorBeginFrameObserver* observer);
242
229 // Creates a compositor lock. Returns NULL if it is not possible to lock at 243 // Creates a compositor lock. Returns NULL if it is not possible to lock at
230 // this time (i.e. we're waiting to complete a previous unlock). 244 // this time (i.e. we're waiting to complete a previous unlock).
231 scoped_refptr<CompositorLock> GetCompositorLock(); 245 scoped_refptr<CompositorLock> GetCompositorLock();
232 246
233 // Internal functions, called back by command-buffer contexts on swap buffer 247 // Internal functions, called back by command-buffer contexts on swap buffer
234 // events. 248 // events.
235 249
236 // Signals swap has been posted. 250 // Signals swap has been posted.
237 void OnSwapBuffersPosted(); 251 void OnSwapBuffersPosted();
238 252
(...skipping 18 matching lines...) Expand all
257 float page_scale, 271 float page_scale,
258 float top_controls_delta) override {} 272 float top_controls_delta) override {}
259 void RequestNewOutputSurface() override; 273 void RequestNewOutputSurface() override;
260 void DidInitializeOutputSurface() override; 274 void DidInitializeOutputSurface() override;
261 void DidFailToInitializeOutputSurface() override; 275 void DidFailToInitializeOutputSurface() override;
262 void WillCommit() override {} 276 void WillCommit() override {}
263 void DidCommit() override; 277 void DidCommit() override;
264 void DidCommitAndDrawFrame() override; 278 void DidCommitAndDrawFrame() override;
265 void DidCompleteSwapBuffers() override; 279 void DidCompleteSwapBuffers() override;
266 void DidCompletePageScaleAnimation() override {} 280 void DidCompletePageScaleAnimation() override {}
281 void SendBeginFramesToChildren(const cc::BeginFrameArgs& args) override;
267 282
268 // cc::LayerTreeHostSingleThreadClient implementation. 283 // cc::LayerTreeHostSingleThreadClient implementation.
269 void DidPostSwapBuffers() override; 284 void DidPostSwapBuffers() override;
270 void DidAbortSwapBuffers() override; 285 void DidAbortSwapBuffers() override;
271 286
272 bool IsLocked() { return compositor_lock_ != NULL; } 287 bool IsLocked() { return compositor_lock_ != NULL; }
273 288
274 const cc::LayerTreeDebugState& GetLayerTreeDebugState() const; 289 const cc::LayerTreeDebugState& GetLayerTreeDebugState() const;
275 void SetLayerTreeDebugState(const cc::LayerTreeDebugState& debug_state); 290 void SetLayerTreeDebugState(const cc::LayerTreeDebugState& debug_state);
276 const cc::RendererSettings& GetRendererSettings() const; 291 const cc::RendererSettings& GetRendererSettings() const;
277 292
278 LayerAnimatorCollection* layer_animator_collection() { 293 LayerAnimatorCollection* layer_animator_collection() {
279 return &layer_animator_collection_; 294 return &layer_animator_collection_;
280 } 295 }
281 296
282 cc::SurfaceIdAllocator* surface_id_allocator() { 297 cc::SurfaceIdAllocator* surface_id_allocator() {
283 return surface_id_allocator_.get(); 298 return surface_id_allocator_.get();
284 } 299 }
285 300
301 // Exposed for testing
302 cc::BeginFrameArgs MissedBeginFrameArgsForTesting() {
303 return missed_begin_frame_args_;
304 }
305
286 private: 306 private:
287 friend class base::RefCounted<Compositor>; 307 friend class base::RefCounted<Compositor>;
288 friend class CompositorLock; 308 friend class CompositorLock;
289 309
290 // Called by CompositorLock. 310 // Called by CompositorLock.
291 void UnlockCompositor(); 311 void UnlockCompositor();
292 312
293 // Called to release any pending CompositorLock 313 // Called to release any pending CompositorLock
294 void CancelCompositorLock(); 314 void CancelCompositorLock();
295 315
296 gfx::Size size_; 316 gfx::Size size_;
297 317
298 ui::ContextFactory* context_factory_; 318 ui::ContextFactory* context_factory_;
299 319
300 // The root of the Layer tree drawn by this compositor. 320 // The root of the Layer tree drawn by this compositor.
301 Layer* root_layer_; 321 Layer* root_layer_;
302 322
303 ObserverList<CompositorObserver, true> observer_list_; 323 ObserverList<CompositorObserver, true> observer_list_;
304 ObserverList<CompositorAnimationObserver> animation_observer_list_; 324 ObserverList<CompositorAnimationObserver> animation_observer_list_;
325 ObserverList<CompositorBeginFrameObserver> begin_frame_observer_list_;
305 326
306 gfx::AcceleratedWidget widget_; 327 gfx::AcceleratedWidget widget_;
307 scoped_ptr<cc::SurfaceIdAllocator> surface_id_allocator_; 328 scoped_ptr<cc::SurfaceIdAllocator> surface_id_allocator_;
308 scoped_refptr<cc::Layer> root_web_layer_; 329 scoped_refptr<cc::Layer> root_web_layer_;
309 scoped_ptr<cc::LayerTreeHost> host_; 330 scoped_ptr<cc::LayerTreeHost> host_;
310 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; 331 scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
311 332
312 // The manager of vsync parameters for this compositor. 333 // The manager of vsync parameters for this compositor.
313 scoped_refptr<CompositorVSyncManager> vsync_manager_; 334 scoped_refptr<CompositorVSyncManager> vsync_manager_;
314 335
315 // The device scale factor of the monitor that this compositor is compositing 336 // The device scale factor of the monitor that this compositor is compositing
316 // layers on. 337 // layers on.
317 float device_scale_factor_; 338 float device_scale_factor_;
318 339
319 int last_started_frame_; 340 int last_started_frame_;
320 int last_ended_frame_; 341 int last_ended_frame_;
321 342
322 bool disable_schedule_composite_; 343 bool disable_schedule_composite_;
323 344
324 CompositorLock* compositor_lock_; 345 CompositorLock* compositor_lock_;
325 346
326 LayerAnimatorCollection layer_animator_collection_; 347 LayerAnimatorCollection layer_animator_collection_;
327 348
349 // Used to send to any new CompositorBeginFrameObserver immediately.
350 cc::BeginFrameArgs missed_begin_frame_args_;
351
328 base::WeakPtrFactory<Compositor> weak_ptr_factory_; 352 base::WeakPtrFactory<Compositor> weak_ptr_factory_;
329 353
330 DISALLOW_COPY_AND_ASSIGN(Compositor); 354 DISALLOW_COPY_AND_ASSIGN(Compositor);
331 }; 355 };
332 356
333 } // namespace ui 357 } // namespace ui
334 358
335 #endif // UI_COMPOSITOR_COMPOSITOR_H_ 359 #endif // UI_COMPOSITOR_COMPOSITOR_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698