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

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

Issue 2773433003: Fix CompositorResizeLock to do something. (Closed)
Patch Set: resizelock: . Created 3 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
« no previous file with comments | « ui/compositor/BUILD.gn ('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 <stdint.h> 8 #include <stdint.h>
9 9
10 #include <memory> 10 #include <memory>
11 #include <string> 11 #include <string>
12 12
13 #include "base/containers/hash_tables.h" 13 #include "base/containers/hash_tables.h"
14 #include "base/macros.h" 14 #include "base/macros.h"
15 #include "base/memory/ref_counted.h" 15 #include "base/memory/ref_counted.h"
16 #include "base/observer_list.h" 16 #include "base/observer_list.h"
17 #include "base/single_thread_task_runner.h" 17 #include "base/single_thread_task_runner.h"
18 #include "base/time/time.h" 18 #include "base/time/time.h"
19 #include "build/build_config.h" 19 #include "build/build_config.h"
20 #include "cc/output/begin_frame_args.h" 20 #include "cc/output/begin_frame_args.h"
21 #include "cc/surfaces/surface_sequence.h" 21 #include "cc/surfaces/surface_sequence.h"
22 #include "cc/trees/layer_tree_host_client.h" 22 #include "cc/trees/layer_tree_host_client.h"
23 #include "cc/trees/layer_tree_host_single_thread_client.h" 23 #include "cc/trees/layer_tree_host_single_thread_client.h"
24 #include "third_party/skia/include/core/SkColor.h" 24 #include "third_party/skia/include/core/SkColor.h"
25 #include "ui/compositor/compositor_animation_observer.h" 25 #include "ui/compositor/compositor_animation_observer.h"
26 #include "ui/compositor/compositor_export.h" 26 #include "ui/compositor/compositor_export.h"
27 #include "ui/compositor/compositor_lock.h"
27 #include "ui/compositor/compositor_observer.h" 28 #include "ui/compositor/compositor_observer.h"
28 #include "ui/compositor/layer_animator_collection.h" 29 #include "ui/compositor/layer_animator_collection.h"
29 #include "ui/gfx/color_space.h" 30 #include "ui/gfx/color_space.h"
30 #include "ui/gfx/geometry/size.h" 31 #include "ui/gfx/geometry/size.h"
31 #include "ui/gfx/geometry/vector2d.h" 32 #include "ui/gfx/geometry/vector2d.h"
32 #include "ui/gfx/gpu_memory_buffer.h" 33 #include "ui/gfx/gpu_memory_buffer.h"
33 #include "ui/gfx/native_widget_types.h" 34 #include "ui/gfx/native_widget_types.h"
34 35
35 namespace base { 36 namespace base {
36 class SingleThreadTaskRunner; 37 class SingleThreadTaskRunner;
(...skipping 24 matching lines...) Expand all
61 62
62 namespace ui { 63 namespace ui {
63 64
64 class Compositor; 65 class Compositor;
65 class CompositorVSyncManager; 66 class CompositorVSyncManager;
66 class LatencyInfo; 67 class LatencyInfo;
67 class Layer; 68 class Layer;
68 class Reflector; 69 class Reflector;
69 class ScopedAnimationDurationScaleMode; 70 class ScopedAnimationDurationScaleMode;
70 71
71 const int kCompositorLockTimeoutMs = 67; 72 constexpr int kCompositorLockTimeoutMs = 67;
72 73
73 class COMPOSITOR_EXPORT ContextFactoryObserver { 74 class COMPOSITOR_EXPORT ContextFactoryObserver {
74 public: 75 public:
75 virtual ~ContextFactoryObserver() {} 76 virtual ~ContextFactoryObserver() {}
76 77
77 // Notifies that the ContextProvider returned from 78 // Notifies that the ContextProvider returned from
78 // ui::ContextFactory::SharedMainThreadContextProvider was lost. When this 79 // ui::ContextFactory::SharedMainThreadContextProvider was lost. When this
79 // is called, the old resources (e.g. shared context, GL helper) still 80 // is called, the old resources (e.g. shared context, GL helper) still
80 // exist, but are about to be destroyed. Getting a reference to those 81 // exist, but are about to be destroyed. Getting a reference to those
81 // resources from the ContextFactory (e.g. through 82 // resources from the ContextFactory (e.g. through
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
160 virtual gpu::GpuMemoryBufferManager* GetGpuMemoryBufferManager() = 0; 161 virtual gpu::GpuMemoryBufferManager* GetGpuMemoryBufferManager() = 0;
161 162
162 // Gets the task graph runner. 163 // Gets the task graph runner.
163 virtual cc::TaskGraphRunner* GetTaskGraphRunner() = 0; 164 virtual cc::TaskGraphRunner* GetTaskGraphRunner() = 0;
164 165
165 virtual void AddObserver(ContextFactoryObserver* observer) = 0; 166 virtual void AddObserver(ContextFactoryObserver* observer) = 0;
166 167
167 virtual void RemoveObserver(ContextFactoryObserver* observer) = 0; 168 virtual void RemoveObserver(ContextFactoryObserver* observer) = 0;
168 }; 169 };
169 170
170 // This class represents a lock on the compositor, that can be used to prevent
171 // commits to the compositor tree while we're waiting for an asynchronous
172 // event. The typical use case is when waiting for a renderer to produce a frame
173 // at the right size. The caller keeps a reference on this object, and drops the
174 // reference once it desires to release the lock.
175 // By default, the lock will be cancelled after a short timeout to ensure
176 // responsiveness of the UI, so the compositor tree should be kept in a
177 // "reasonable" state while the lock is held. If the compositor sets
178 // locks to not time out, then the lock will remain in effect until destroyed.
179 // Don't instantiate this class directly, use Compositor::GetCompositorLock.
180 class COMPOSITOR_EXPORT CompositorLock
181 : public base::RefCounted<CompositorLock>,
182 public base::SupportsWeakPtr<CompositorLock> {
183 private:
184 friend class base::RefCounted<CompositorLock>;
185 friend class Compositor;
186
187 explicit CompositorLock(Compositor* compositor);
188 ~CompositorLock();
189
190 void CancelLock();
191
192 Compositor* compositor_;
193 DISALLOW_COPY_AND_ASSIGN(CompositorLock);
194 };
195
196 // Compositor object to take care of GPU painting. 171 // Compositor object to take care of GPU painting.
197 // A Browser compositor object is responsible for generating the final 172 // A Browser compositor object is responsible for generating the final
198 // displayable form of pixels comprising a single widget's contents. It draws an 173 // displayable form of pixels comprising a single widget's contents. It draws an
199 // appropriately transformed texture for each transformed view in the widget's 174 // appropriately transformed texture for each transformed view in the widget's
200 // view hierarchy. 175 // view hierarchy.
201 class COMPOSITOR_EXPORT Compositor 176 class COMPOSITOR_EXPORT Compositor
202 : NON_EXPORTED_BASE(public cc::LayerTreeHostClient), 177 : NON_EXPORTED_BASE(public cc::LayerTreeHostClient),
203 NON_EXPORTED_BASE(public cc::LayerTreeHostSingleThreadClient) { 178 NON_EXPORTED_BASE(public cc::LayerTreeHostSingleThreadClient),
179 NON_EXPORTED_BASE(public CompositorLockDelegate) {
204 public: 180 public:
205 Compositor(const cc::FrameSinkId& frame_sink_id, 181 Compositor(const cc::FrameSinkId& frame_sink_id,
206 ui::ContextFactory* context_factory, 182 ui::ContextFactory* context_factory,
207 ui::ContextFactoryPrivate* context_factory_private, 183 ui::ContextFactoryPrivate* context_factory_private,
208 scoped_refptr<base::SingleThreadTaskRunner> task_runner); 184 scoped_refptr<base::SingleThreadTaskRunner> task_runner);
209 ~Compositor() override; 185 ~Compositor() override;
210 186
211 ui::ContextFactory* context_factory() { return context_factory_; } 187 ui::ContextFactory* context_factory() { return context_factory_; }
212 188
213 ui::ContextFactoryPrivate* context_factory_private() { 189 ui::ContextFactoryPrivate* context_factory_private() {
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
318 // Compositor does not own observers. It is the responsibility of the 294 // Compositor does not own observers. It is the responsibility of the
319 // observer to remove itself when it is done observing. 295 // observer to remove itself when it is done observing.
320 void AddObserver(CompositorObserver* observer); 296 void AddObserver(CompositorObserver* observer);
321 void RemoveObserver(CompositorObserver* observer); 297 void RemoveObserver(CompositorObserver* observer);
322 bool HasObserver(const CompositorObserver* observer) const; 298 bool HasObserver(const CompositorObserver* observer) const;
323 299
324 void AddAnimationObserver(CompositorAnimationObserver* observer); 300 void AddAnimationObserver(CompositorAnimationObserver* observer);
325 void RemoveAnimationObserver(CompositorAnimationObserver* observer); 301 void RemoveAnimationObserver(CompositorAnimationObserver* observer);
326 bool HasAnimationObserver(const CompositorAnimationObserver* observer) const; 302 bool HasAnimationObserver(const CompositorAnimationObserver* observer) const;
327 303
328 // Change the timeout behavior for all future locks that are created. Locks
329 // should time out if there is an expectation that the compositor will be
330 // responsive.
331 void SetLocksWillTimeOut(bool locks_will_time_out) {
332 locks_will_time_out_ = locks_will_time_out;
333 }
334
335 // Creates a compositor lock. Returns NULL if it is not possible to lock at 304 // Creates a compositor lock. Returns NULL if it is not possible to lock at
336 // this time (i.e. we're waiting to complete a previous unlock). 305 // this time (i.e. we're waiting to complete a previous unlock). If the
337 scoped_refptr<CompositorLock> GetCompositorLock(); 306 // timeout is null, then no timeout is used.
307 std::unique_ptr<CompositorLock> GetCompositorLock(
308 CompositorLockClient* client,
309 base::TimeDelta timeout =
310 base::TimeDelta::FromMilliseconds(kCompositorLockTimeoutMs));
338 311
339 // Internal functions, called back by command-buffer contexts on swap buffer 312 // Internal functions, called back by command-buffer contexts on swap buffer
340 // events. 313 // events.
341 314
342 // Signals swap has been posted. 315 // Signals swap has been posted.
343 void OnSwapBuffersPosted(); 316 void OnSwapBuffersPosted();
344 317
345 // Signals swap has completed. 318 // Signals swap has completed.
346 void OnSwapBuffersComplete(); 319 void OnSwapBuffersComplete();
347 320
(...skipping 17 matching lines...) Expand all
365 void WillCommit() override {} 338 void WillCommit() override {}
366 void DidCommit() override; 339 void DidCommit() override;
367 void DidCommitAndDrawFrame() override {} 340 void DidCommitAndDrawFrame() override {}
368 void DidReceiveCompositorFrameAck() override; 341 void DidReceiveCompositorFrameAck() override;
369 void DidCompletePageScaleAnimation() override {} 342 void DidCompletePageScaleAnimation() override {}
370 343
371 // cc::LayerTreeHostSingleThreadClient implementation. 344 // cc::LayerTreeHostSingleThreadClient implementation.
372 void DidSubmitCompositorFrame() override; 345 void DidSubmitCompositorFrame() override;
373 void DidLoseCompositorFrameSink() override {} 346 void DidLoseCompositorFrameSink() override {}
374 347
375 bool IsLocked() { return compositor_lock_ != NULL; } 348 bool IsLocked() { return !active_locks_.empty(); }
376 349
377 void SetOutputIsSecure(bool output_is_secure); 350 void SetOutputIsSecure(bool output_is_secure);
378 351
379 const cc::LayerTreeDebugState& GetLayerTreeDebugState() const; 352 const cc::LayerTreeDebugState& GetLayerTreeDebugState() const;
380 void SetLayerTreeDebugState(const cc::LayerTreeDebugState& debug_state); 353 void SetLayerTreeDebugState(const cc::LayerTreeDebugState& debug_state);
381 const cc::RendererSettings& GetRendererSettings() const; 354 const cc::RendererSettings& GetRendererSettings() const;
382 355
383 LayerAnimatorCollection* layer_animator_collection() { 356 LayerAnimatorCollection* layer_animator_collection() {
384 return &layer_animator_collection_; 357 return &layer_animator_collection_;
385 } 358 }
386 359
387 const cc::FrameSinkId& frame_sink_id() const { return frame_sink_id_; } 360 const cc::FrameSinkId& frame_sink_id() const { return frame_sink_id_; }
388 int committed_frame_number() const { return committed_frame_number_; } 361 int committed_frame_number() const { return committed_frame_number_; }
389 float refresh_rate() const { return refresh_rate_; } 362 float refresh_rate() const { return refresh_rate_; }
390 363
391 private: 364 private:
392 friend class base::RefCounted<Compositor>; 365 friend class base::RefCounted<Compositor>;
393 friend class CompositorLock;
394 366
395 // Called by CompositorLock. 367 // CompositorLockDelegate implementation.
396 void UnlockCompositor(); 368 void RemoveCompositorLock(CompositorLock* lock) override;
397 369
398 // Called to release any pending CompositorLock 370 // Causes all active CompositorLocks to be timed out.
399 void CancelCompositorLock(); 371 void TimeoutLocks();
400 372
401 gfx::Size size_; 373 gfx::Size size_;
402 374
403 ui::ContextFactory* context_factory_; 375 ui::ContextFactory* context_factory_;
404 ui::ContextFactoryPrivate* context_factory_private_; 376 ui::ContextFactoryPrivate* context_factory_private_;
405 377
406 // The root of the Layer tree drawn by this compositor. 378 // The root of the Layer tree drawn by this compositor.
407 Layer* root_layer_; 379 Layer* root_layer_ = nullptr;
408 380
409 base::ObserverList<CompositorObserver, true> observer_list_; 381 base::ObserverList<CompositorObserver, true> observer_list_;
410 base::ObserverList<CompositorAnimationObserver> animation_observer_list_; 382 base::ObserverList<CompositorAnimationObserver> animation_observer_list_;
411 383
412 gfx::AcceleratedWidget widget_; 384 gfx::AcceleratedWidget widget_ = gfx::kNullAcceleratedWidget;
413 // A sequence number of a current compositor frame for use with metrics. 385 // A sequence number of a current compositor frame for use with metrics.
414 int committed_frame_number_; 386 int committed_frame_number_ = 0;
415 387
416 // current VSYNC refresh rate per second. 388 // Current vsync refresh rate per second.
417 float refresh_rate_; 389 float refresh_rate_ = 0.f;
418 390
419 // A map from child id to parent id. 391 // A map from child id to parent id.
420 std::unordered_set<cc::FrameSinkId, cc::FrameSinkIdHash> child_frame_sinks_; 392 std::unordered_set<cc::FrameSinkId, cc::FrameSinkIdHash> child_frame_sinks_;
421 bool widget_valid_; 393 bool widget_valid_ = false;
422 bool compositor_frame_sink_requested_; 394 bool compositor_frame_sink_requested_ = false;
423 const cc::FrameSinkId frame_sink_id_; 395 const cc::FrameSinkId frame_sink_id_;
424 scoped_refptr<cc::Layer> root_web_layer_; 396 scoped_refptr<cc::Layer> root_web_layer_;
425 std::unique_ptr<cc::AnimationHost> animation_host_; 397 std::unique_ptr<cc::AnimationHost> animation_host_;
426 std::unique_ptr<cc::LayerTreeHost> host_; 398 std::unique_ptr<cc::LayerTreeHost> host_;
427 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; 399 scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
428 400
429 // The manager of vsync parameters for this compositor. 401 // The manager of vsync parameters for this compositor.
430 scoped_refptr<CompositorVSyncManager> vsync_manager_; 402 scoped_refptr<CompositorVSyncManager> vsync_manager_;
431 403
432 // The device scale factor of the monitor that this compositor is compositing 404 // The device scale factor of the monitor that this compositor is compositing
433 // layers on. 405 // layers on.
434 float device_scale_factor_; 406 float device_scale_factor_ = 0.f;
435 407
436 bool locks_will_time_out_; 408 std::vector<CompositorLock*> active_locks_;
437 CompositorLock* compositor_lock_;
438 409
439 LayerAnimatorCollection layer_animator_collection_; 410 LayerAnimatorCollection layer_animator_collection_;
440 scoped_refptr<cc::AnimationTimeline> animation_timeline_; 411 scoped_refptr<cc::AnimationTimeline> animation_timeline_;
441 std::unique_ptr<ScopedAnimationDurationScaleMode> slow_animations_; 412 std::unique_ptr<ScopedAnimationDurationScaleMode> slow_animations_;
442 413
443 gfx::ColorSpace output_color_space_; 414 gfx::ColorSpace output_color_space_;
444 gfx::ColorSpace blending_color_space_; 415 gfx::ColorSpace blending_color_space_;
445 416
446 base::WeakPtrFactory<Compositor> weak_ptr_factory_; 417 base::WeakPtrFactory<Compositor> weak_ptr_factory_;
418 base::WeakPtrFactory<Compositor> lock_timeout_weak_ptr_factory_;
piman 2017/03/24 18:42:34 nit: do we need 2 separate WeakPtrFactory? I don't
danakj 2017/03/24 18:44:33 Oh, I wanted to invalidate when the last lock is r
447 419
448 DISALLOW_COPY_AND_ASSIGN(Compositor); 420 DISALLOW_COPY_AND_ASSIGN(Compositor);
449 }; 421 };
450 422
451 } // namespace ui 423 } // namespace ui
452 424
453 #endif // UI_COMPOSITOR_COMPOSITOR_H_ 425 #endif // UI_COMPOSITOR_COMPOSITOR_H_
OLDNEW
« no previous file with comments | « ui/compositor/BUILD.gn ('k') | ui/compositor/compositor.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698