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

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

Issue 775143003: cc: Implement unified BeginFrame on aura (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: add unittest 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 20 matching lines...) Expand all
46 } 47 }
47 48
48 namespace gpu { 49 namespace gpu {
49 class GpuMemoryBufferManager; 50 class GpuMemoryBufferManager;
50 struct Mailbox; 51 struct Mailbox;
51 } 52 }
52 53
53 namespace ui { 54 namespace ui {
54 55
55 class Compositor; 56 class Compositor;
56 class CompositorVSyncManager;
57 class Layer; 57 class Layer;
58 class Reflector; 58 class Reflector;
59 class Texture; 59 class Texture;
60 struct LatencyInfo; 60 struct LatencyInfo;
61 61
62 // This class abstracts the creation of the 3D context for the compositor. It is 62 // This class abstracts the creation of the 3D context for the compositor. It is
63 // a global object. 63 // a global object.
64 class COMPOSITOR_EXPORT ContextFactory { 64 class COMPOSITOR_EXPORT ContextFactory {
65 public: 65 public:
66 virtual ~ContextFactory() {} 66 virtual ~ContextFactory() {}
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 121
122 explicit CompositorLock(Compositor* compositor); 122 explicit CompositorLock(Compositor* compositor);
123 ~CompositorLock(); 123 ~CompositorLock();
124 124
125 void CancelLock(); 125 void CancelLock();
126 126
127 Compositor* compositor_; 127 Compositor* compositor_;
128 DISALLOW_COPY_AND_ASSIGN(CompositorLock); 128 DISALLOW_COPY_AND_ASSIGN(CompositorLock);
129 }; 129 };
130 130
131 // This class observes BeginFrame notification from LayerTreeHost.
132 class COMPOSITOR_EXPORT CompositorBeginFrameObserver {
133 public:
134 virtual ~CompositorBeginFrameObserver() {}
135
136 virtual void OnSendBeginFrame(const cc::BeginFrameArgs& args) = 0;
137 };
138
131 // Compositor object to take care of GPU painting. 139 // Compositor object to take care of GPU painting.
132 // A Browser compositor object is responsible for generating the final 140 // A Browser compositor object is responsible for generating the final
133 // displayable form of pixels comprising a single widget's contents. It draws an 141 // displayable form of pixels comprising a single widget's contents. It draws an
134 // appropriately transformed texture for each transformed view in the widget's 142 // appropriately transformed texture for each transformed view in the widget's
135 // view hierarchy. 143 // view hierarchy.
136 class COMPOSITOR_EXPORT Compositor 144 class COMPOSITOR_EXPORT Compositor
137 : NON_EXPORTED_BASE(public cc::LayerTreeHostClient), 145 : NON_EXPORTED_BASE(public cc::LayerTreeHostClient),
138 NON_EXPORTED_BASE(public cc::LayerTreeHostSingleThreadClient) { 146 NON_EXPORTED_BASE(public cc::LayerTreeHostSingleThreadClient) {
139 public: 147 public:
140 Compositor(gfx::AcceleratedWidget widget, 148 Compositor(gfx::AcceleratedWidget widget,
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
194 // Sets the background color used for areas that aren't covered by 202 // Sets the background color used for areas that aren't covered by
195 // the |root_layer|. 203 // the |root_layer|.
196 void SetBackgroundColor(SkColor color); 204 void SetBackgroundColor(SkColor color);
197 205
198 // Sets the visibility of the underlying compositor. 206 // Sets the visibility of the underlying compositor.
199 void SetVisible(bool visible); 207 void SetVisible(bool visible);
200 208
201 // Gets the visibility of the underlying compositor. 209 // Gets the visibility of the underlying compositor.
202 bool IsVisible(); 210 bool IsVisible();
203 211
212 // The "authoritative" vsync interval, if provided, will override interval
213 // reported from 3D context. This is typically the value reported by a more
214 // reliable source, e.g, the platform display configuration.
215 // In the particular case of ChromeOS -- this is the value queried through
216 // XRandR, which is more reliable than the value queried through the 3D
217 // context.
218 void SetAuthoritativeVSyncInterval(const base::TimeDelta& interval);
219
204 // Returns the widget for this compositor. 220 // Returns the widget for this compositor.
205 gfx::AcceleratedWidget widget() const { return widget_; } 221 gfx::AcceleratedWidget widget() const { return widget_; }
206 222
207 // Returns the vsync manager for this compositor.
208 scoped_refptr<CompositorVSyncManager> vsync_manager() const;
209
210 // Returns the main thread task runner this compositor uses. Users of the 223 // Returns the main thread task runner this compositor uses. Users of the
211 // compositor generally shouldn't use this. 224 // compositor generally shouldn't use this.
212 scoped_refptr<base::SingleThreadTaskRunner> task_runner() const { 225 scoped_refptr<base::SingleThreadTaskRunner> task_runner() const {
213 return task_runner_; 226 return task_runner_;
214 } 227 }
215 228
216 // Compositor does not own observers. It is the responsibility of the 229 // Compositor does not own observers. It is the responsibility of the
217 // observer to remove itself when it is done observing. 230 // observer to remove itself when it is done observing.
218 void AddObserver(CompositorObserver* observer); 231 void AddObserver(CompositorObserver* observer);
219 void RemoveObserver(CompositorObserver* observer); 232 void RemoveObserver(CompositorObserver* observer);
220 bool HasObserver(const CompositorObserver* observer) const; 233 bool HasObserver(const CompositorObserver* observer) const;
221 234
222 void AddAnimationObserver(CompositorAnimationObserver* observer); 235 void AddAnimationObserver(CompositorAnimationObserver* observer);
223 void RemoveAnimationObserver(CompositorAnimationObserver* observer); 236 void RemoveAnimationObserver(CompositorAnimationObserver* observer);
224 bool HasAnimationObserver(const CompositorAnimationObserver* observer) const; 237 bool HasAnimationObserver(const CompositorAnimationObserver* observer) const;
225 238
239 void AddBeginFrameObserver(
240 CompositorBeginFrameObserver* observer,
241 const cc::BeginFrameArgs& last_begin_frame_args_sent_to_observer);
242 void RemoveBeginFrameObserver(CompositorBeginFrameObserver* observer);
243
226 // Creates a compositor lock. Returns NULL if it is not possible to lock at 244 // Creates a compositor lock. Returns NULL if it is not possible to lock at
227 // this time (i.e. we're waiting to complete a previous unlock). 245 // this time (i.e. we're waiting to complete a previous unlock).
228 scoped_refptr<CompositorLock> GetCompositorLock(); 246 scoped_refptr<CompositorLock> GetCompositorLock();
229 247
230 // Internal functions, called back by command-buffer contexts on swap buffer 248 // Internal functions, called back by command-buffer contexts on swap buffer
231 // events. 249 // events.
232 250
233 // Signals swap has been posted. 251 // Signals swap has been posted.
234 void OnSwapBuffersPosted(); 252 void OnSwapBuffersPosted();
235 253
(...skipping 18 matching lines...) Expand all
254 float page_scale, 272 float page_scale,
255 float top_controls_delta) override {} 273 float top_controls_delta) override {}
256 void RequestNewOutputSurface() override; 274 void RequestNewOutputSurface() override;
257 void DidInitializeOutputSurface() override; 275 void DidInitializeOutputSurface() override;
258 void DidFailToInitializeOutputSurface() override; 276 void DidFailToInitializeOutputSurface() override;
259 void WillCommit() override {} 277 void WillCommit() override {}
260 void DidCommit() override; 278 void DidCommit() override;
261 void DidCommitAndDrawFrame() override; 279 void DidCommitAndDrawFrame() override;
262 void DidCompleteSwapBuffers() override; 280 void DidCompleteSwapBuffers() override;
263 void DidCompletePageScaleAnimation() override {} 281 void DidCompletePageScaleAnimation() override {}
282 void SendBeginFramesToChildren(const cc::BeginFrameArgs& args) override;
264 283
265 // cc::LayerTreeHostSingleThreadClient implementation. 284 // cc::LayerTreeHostSingleThreadClient implementation.
266 void DidPostSwapBuffers() override; 285 void DidPostSwapBuffers() override;
267 void DidAbortSwapBuffers() override; 286 void DidAbortSwapBuffers() override;
268 287
269 bool IsLocked() { return compositor_lock_ != NULL; } 288 bool IsLocked() { return compositor_lock_ != NULL; }
270 289
271 const cc::LayerTreeDebugState& GetLayerTreeDebugState() const; 290 const cc::LayerTreeDebugState& GetLayerTreeDebugState() const;
272 void SetLayerTreeDebugState(const cc::LayerTreeDebugState& debug_state); 291 void SetLayerTreeDebugState(const cc::LayerTreeDebugState& debug_state);
273 const cc::RendererSettings& GetRendererSettings() const; 292 const cc::RendererSettings& GetRendererSettings() const;
274 293
275 LayerAnimatorCollection* layer_animator_collection() { 294 LayerAnimatorCollection* layer_animator_collection() {
276 return &layer_animator_collection_; 295 return &layer_animator_collection_;
277 } 296 }
278 297
279 cc::SurfaceIdAllocator* surface_id_allocator() { 298 cc::SurfaceIdAllocator* surface_id_allocator() {
280 return surface_id_allocator_.get(); 299 return surface_id_allocator_.get();
281 } 300 }
282 301
283 private: 302 private:
284 friend class base::RefCounted<Compositor>; 303 friend class base::RefCounted<Compositor>;
285 friend class CompositorLock; 304 friend class CompositorLock;
305 friend class CompositorTestAPI;
brianderson 2015/03/06 20:36:59 Instead of adding a CompositorTestAPI as a friend,
286 306
287 // Called by CompositorLock. 307 // Called by CompositorLock.
288 void UnlockCompositor(); 308 void UnlockCompositor();
289 309
290 // Called to release any pending CompositorLock 310 // Called to release any pending CompositorLock
291 void CancelCompositorLock(); 311 void CancelCompositorLock();
292 312
313 // Request scheduling of next BeginFrame to LayerTreeHost.
314 void SetChildrenNeedBeginFrames(bool need_begin_frame);
315
293 gfx::Size size_; 316 gfx::Size size_;
294 317
295 ui::ContextFactory* context_factory_; 318 ui::ContextFactory* context_factory_;
296 319
297 // The root of the Layer tree drawn by this compositor. 320 // The root of the Layer tree drawn by this compositor.
298 Layer* root_layer_; 321 Layer* root_layer_;
299 322
300 ObserverList<CompositorObserver, true> observer_list_; 323 ObserverList<CompositorObserver, true> observer_list_;
301 ObserverList<CompositorAnimationObserver> animation_observer_list_; 324 ObserverList<CompositorAnimationObserver> animation_observer_list_;
325 ObserverList<CompositorBeginFrameObserver> begin_frame_observer_list_;
302 326
303 gfx::AcceleratedWidget widget_; 327 gfx::AcceleratedWidget widget_;
304 scoped_ptr<cc::SurfaceIdAllocator> surface_id_allocator_; 328 scoped_ptr<cc::SurfaceIdAllocator> surface_id_allocator_;
305 scoped_refptr<cc::Layer> root_web_layer_; 329 scoped_refptr<cc::Layer> root_web_layer_;
306 scoped_ptr<cc::LayerTreeHost> host_; 330 scoped_ptr<cc::LayerTreeHost> host_;
307 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; 331 scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
308 332
309 // The manager of vsync parameters for this compositor.
310 scoped_refptr<CompositorVSyncManager> vsync_manager_;
311
312 // The device scale factor of the monitor that this compositor is compositing 333 // The device scale factor of the monitor that this compositor is compositing
313 // layers on. 334 // layers on.
314 float device_scale_factor_; 335 float device_scale_factor_;
315 336
316 int last_started_frame_; 337 int last_started_frame_;
317 int last_ended_frame_; 338 int last_ended_frame_;
318 339
319 bool disable_schedule_composite_; 340 bool disable_schedule_composite_;
320 341
321 CompositorLock* compositor_lock_; 342 CompositorLock* compositor_lock_;
322 343
323 LayerAnimatorCollection layer_animator_collection_; 344 LayerAnimatorCollection layer_animator_collection_;
324 345
346 // Used to send to any new CompositorBeginFrameObserver immediately.
347 cc::BeginFrameArgs missed_begin_frame_args_;
348
325 base::WeakPtrFactory<Compositor> weak_ptr_factory_; 349 base::WeakPtrFactory<Compositor> weak_ptr_factory_;
326 350
327 DISALLOW_COPY_AND_ASSIGN(Compositor); 351 DISALLOW_COPY_AND_ASSIGN(Compositor);
328 }; 352 };
329 353
330 } // namespace ui 354 } // namespace ui
331 355
332 #endif // UI_COMPOSITOR_COMPOSITOR_H_ 356 #endif // UI_COMPOSITOR_COMPOSITOR_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698