compositor.h 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574
  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
  3. // found in the LICENSE file.
  4. #ifndef UI_COMPOSITOR_COMPOSITOR_H_
  5. #define UI_COMPOSITOR_COMPOSITOR_H_
  6. #include <stdint.h>
  7. #include <memory>
  8. #include <unordered_set>
  9. #include "base/callback_forward.h"
  10. #include "base/containers/flat_map.h"
  11. #include "base/containers/flat_set.h"
  12. #include "base/memory/raw_ptr.h"
  13. #include "base/memory/ref_counted.h"
  14. #include "base/observer_list.h"
  15. #include "base/power_monitor/power_observer.h"
  16. #include "base/task/single_thread_task_runner.h"
  17. #include "base/time/time.h"
  18. #include "build/build_config.h"
  19. #include "build/chromeos_buildflags.h"
  20. #include "cc/metrics/events_metrics_manager.h"
  21. #include "cc/metrics/frame_sequence_tracker.h"
  22. #include "cc/paint/element_id.h"
  23. #include "cc/trees/layer_tree_host.h"
  24. #include "cc/trees/layer_tree_host_client.h"
  25. #include "cc/trees/layer_tree_host_single_thread_client.h"
  26. #include "cc/trees/paint_holding_reason.h"
  27. #include "components/viz/common/frame_sinks/begin_frame_args.h"
  28. #include "components/viz/common/surfaces/frame_sink_id.h"
  29. #include "components/viz/common/surfaces/subtree_capture_id.h"
  30. #include "components/viz/host/host_frame_sink_client.h"
  31. #include "mojo/public/cpp/bindings/pending_remote.h"
  32. #include "services/viz/privileged/mojom/compositing/vsync_parameter_observer.mojom-forward.h"
  33. #include "third_party/skia/include/core/SkColor.h"
  34. #include "third_party/skia/include/core/SkM44.h"
  35. #include "ui/compositor/compositor_animation_observer.h"
  36. #include "ui/compositor/compositor_export.h"
  37. #include "ui/compositor/compositor_lock.h"
  38. #include "ui/compositor/compositor_observer.h"
  39. #include "ui/compositor/layer_animator_collection.h"
  40. #include "ui/compositor/throughput_tracker.h"
  41. #include "ui/compositor/throughput_tracker_host.h"
  42. #include "ui/gfx/display_color_spaces.h"
  43. #include "ui/gfx/geometry/size.h"
  44. #include "ui/gfx/geometry/vector2d.h"
  45. #include "ui/gfx/gpu_memory_buffer.h"
  46. #include "ui/gfx/native_widget_types.h"
  47. #include "ui/gfx/overlay_transform.h"
  48. namespace base {
  49. class SingleThreadTaskRunner;
  50. }
  51. namespace cc {
  52. class AnimationHost;
  53. class AnimationTimeline;
  54. class Layer;
  55. class LayerTreeDebugState;
  56. class LayerTreeFrameSink;
  57. class LayerTreeSettings;
  58. class TaskGraphRunner;
  59. }
  60. namespace gfx {
  61. namespace mojom {
  62. class DelegatedInkPointRenderer;
  63. } // namespace mojom
  64. struct PresentationFeedback;
  65. class Rect;
  66. class Size;
  67. }
  68. namespace gpu {
  69. class GpuMemoryBufferManager;
  70. }
  71. namespace viz {
  72. namespace mojom {
  73. class DisplayPrivate;
  74. class ExternalBeginFrameController;
  75. } // namespace mojom
  76. class ContextProvider;
  77. class HostFrameSinkManager;
  78. class LocalSurfaceId;
  79. class RasterContextProvider;
  80. } // namespace viz
  81. namespace ui {
  82. class Compositor;
  83. class Layer;
  84. class ScopedAnimationDurationScaleMode;
  85. class ScrollInputHandler;
  86. class ThroughputTracker;
  87. struct PendingBeginFrameArgs;
  88. constexpr int kCompositorLockTimeoutMs = 67;
  89. // This class abstracts the creation of the 3D context for the compositor. It is
  90. // a global object.
  91. class COMPOSITOR_EXPORT ContextFactory {
  92. public:
  93. virtual ~ContextFactory() {}
  94. // Creates an output surface for the given compositor. The factory may keep
  95. // per-compositor data (e.g. a shared context), that needs to be cleaned up
  96. // by calling RemoveCompositor when the compositor gets destroyed.
  97. virtual void CreateLayerTreeFrameSink(
  98. base::WeakPtr<Compositor> compositor) = 0;
  99. // Return a reference to a shared offscreen context provider usable from the
  100. // main thread.
  101. virtual scoped_refptr<viz::ContextProvider>
  102. SharedMainThreadContextProvider() = 0;
  103. // Return a reference to a shared offscreen context provider usable from the
  104. // main thread.
  105. virtual scoped_refptr<viz::RasterContextProvider>
  106. SharedMainThreadRasterContextProvider() = 0;
  107. // Destroys per-compositor data.
  108. virtual void RemoveCompositor(Compositor* compositor) = 0;
  109. // Gets the GPU memory buffer manager.
  110. virtual gpu::GpuMemoryBufferManager* GetGpuMemoryBufferManager() = 0;
  111. // Gets the task graph runner.
  112. virtual cc::TaskGraphRunner* GetTaskGraphRunner() = 0;
  113. // Allocate a new client ID for the display compositor.
  114. virtual viz::FrameSinkId AllocateFrameSinkId() = 0;
  115. // Allocates a new capture ID for a layer subtree within a frame sink.
  116. virtual viz::SubtreeCaptureId AllocateSubtreeCaptureId() = 0;
  117. // Gets the frame sink manager host instance.
  118. virtual viz::HostFrameSinkManager* GetHostFrameSinkManager() = 0;
  119. };
  120. // Compositor object to take care of GPU painting.
  121. // A Browser compositor object is responsible for generating the final
  122. // displayable form of pixels comprising a single widget's contents. It draws an
  123. // appropriately transformed texture for each transformed view in the widget's
  124. // view hierarchy.
  125. class COMPOSITOR_EXPORT Compositor : public base::PowerSuspendObserver,
  126. public cc::LayerTreeHostClient,
  127. public cc::LayerTreeHostSingleThreadClient,
  128. public viz::HostFrameSinkClient,
  129. public ThroughputTrackerHost {
  130. public:
  131. Compositor(const viz::FrameSinkId& frame_sink_id,
  132. ui::ContextFactory* context_factory,
  133. scoped_refptr<base::SingleThreadTaskRunner> task_runner,
  134. bool enable_pixel_canvas,
  135. bool use_external_begin_frame_control = false,
  136. bool force_software_compositor = false,
  137. bool enable_compositing_based_throttling = false,
  138. size_t memory_limit_when_visible_mb = 0);
  139. Compositor(const Compositor&) = delete;
  140. Compositor& operator=(const Compositor&) = delete;
  141. ~Compositor() override;
  142. ui::ContextFactory* context_factory() { return context_factory_; }
  143. void AddChildFrameSink(const viz::FrameSinkId& frame_sink_id);
  144. void RemoveChildFrameSink(const viz::FrameSinkId& frame_sink_id);
  145. void SetLayerTreeFrameSink(std::unique_ptr<cc::LayerTreeFrameSink> surface,
  146. viz::mojom::DisplayPrivate* display_private);
  147. void SetExternalBeginFrameController(viz::mojom::ExternalBeginFrameController*
  148. external_begin_frame_controller);
  149. // Called when a child surface is about to resize.
  150. void OnChildResizing();
  151. // Schedules a redraw of the layer tree associated with this compositor.
  152. void ScheduleDraw();
  153. // Sets the root of the layer tree drawn by this Compositor. The root layer
  154. // must have no parent. The compositor's root layer is reset if the root layer
  155. // is destroyed. NULL can be passed to reset the root layer, in which case the
  156. // compositor will stop drawing anything.
  157. // The Compositor does not own the root layer.
  158. const Layer* root_layer() const { return root_layer_; }
  159. Layer* root_layer() { return root_layer_; }
  160. void SetRootLayer(Layer* root_layer);
  161. // HideHelper temporarily hides the root layer and replaces it with a
  162. // temporary layer, without calling SetRootLayer (but doing much of the work
  163. // that SetRootLayer does). During that time we must disable ticking
  164. // of animations, since animations that animate layers that are not in
  165. // cc's layer tree must not tick. These methods make those changes
  166. // and record/reflect that state.
  167. void DisableAnimations();
  168. void EnableAnimations();
  169. bool animations_are_enabled() const { return animations_are_enabled_; }
  170. cc::AnimationTimeline* GetAnimationTimeline() const;
  171. // The scale factor of the device that this compositor is
  172. // compositing layers on.
  173. float device_scale_factor() const { return device_scale_factor_; }
  174. // Gets and sets the color matrix used to transform the output colors of what
  175. // this compositor renders.
  176. const SkM44& display_color_matrix() const { return display_color_matrix_; }
  177. void SetDisplayColorMatrix(const SkM44& matrix);
  178. // Where possible, draws are scissored to a damage region calculated from
  179. // changes to layer properties. This bypasses that and indicates that
  180. // the whole frame needs to be drawn.
  181. void ScheduleFullRedraw();
  182. // Schedule redraw and append damage_rect to the damage region calculated
  183. // from changes to layer properties.
  184. void ScheduleRedrawRect(const gfx::Rect& damage_rect);
  185. #if BUILDFLAG(IS_WIN)
  186. // Until this is called with |should| true then both DisableSwapUntilResize()
  187. // and ReenableSwap() do nothing.
  188. void SetShouldDisableSwapUntilResize(bool should);
  189. // Attempts to immediately swap a frame with the current size if possible,
  190. // then disables swapping on this surface until it is resized.
  191. void DisableSwapUntilResize();
  192. void ReenableSwap();
  193. #endif
  194. // Sets the compositor's device scale factor and size.
  195. void SetScaleAndSize(float scale,
  196. const gfx::Size& size_in_pixel,
  197. const viz::LocalSurfaceId& local_surface_id);
  198. // Set the output color profile into which this compositor should render. Also
  199. // sets the SDR white level (in nits) used to scale HDR color space primaries.
  200. void SetDisplayColorSpaces(
  201. const gfx::DisplayColorSpaces& display_color_spaces);
  202. const gfx::DisplayColorSpaces& display_color_spaces() const {
  203. return display_color_spaces_;
  204. }
  205. // Set the transform/rotation info for the display output surface.
  206. void SetDisplayTransformHint(gfx::OverlayTransform hint);
  207. gfx::OverlayTransform display_transform_hint() const {
  208. return host_->display_transform_hint();
  209. }
  210. // Returns the size of the widget that is being drawn to in pixel coordinates.
  211. const gfx::Size& size() const { return size_; }
  212. // Sets the background color used for areas that aren't covered by
  213. // the |root_layer|.
  214. void SetBackgroundColor(SkColor color);
  215. // Inform the display corresponding to this compositor if it is visible. When
  216. // false it does not need to produce any frames. Visibility is reset for each
  217. // call to CreateLayerTreeFrameSink.
  218. void SetVisible(bool visible);
  219. // Gets the visibility of the underlying compositor.
  220. bool IsVisible();
  221. // Gets or sets the scroll offset for the given layer in step with the
  222. // cc::InputHandler. Returns true if the layer is active on the impl side.
  223. bool GetScrollOffsetForLayer(cc::ElementId element_id,
  224. gfx::PointF* offset) const;
  225. bool ScrollLayerTo(cc::ElementId element_id, const gfx::PointF& offset);
  226. // Mac path for transporting vsync parameters to the display. Other platforms
  227. // update it via the BrowserCompositorLayerTreeFrameSink directly.
  228. void SetDisplayVSyncParameters(base::TimeTicks timebase,
  229. base::TimeDelta interval);
  230. void AddVSyncParameterObserver(
  231. mojo::PendingRemote<viz::mojom::VSyncParameterObserver> observer);
  232. // Sets the widget for the compositor to render into.
  233. void SetAcceleratedWidget(gfx::AcceleratedWidget widget);
  234. // Releases the widget previously set through SetAcceleratedWidget().
  235. // After returning it will not be used for rendering anymore.
  236. // The compositor must be set to invisible when taking away a widget.
  237. gfx::AcceleratedWidget ReleaseAcceleratedWidget();
  238. gfx::AcceleratedWidget widget() const;
  239. // This flag is used to force a compositor into software compositing even tho
  240. // in general chrome is using gpu compositing. This allows the compositor to
  241. // be created without a gpu context, and does not go through the gpu path at
  242. // all. This flag can not be used with a compositor that embeds any external
  243. // content via a SurfaceLayer, as they would not agree on what compositing
  244. // mode to use for resources, but may be used eg for tooltip windows.
  245. bool force_software_compositor() { return force_software_compositor_; }
  246. // Returns the main thread task runner this compositor uses. Users of the
  247. // compositor generally shouldn't use this.
  248. scoped_refptr<base::SingleThreadTaskRunner> task_runner() const {
  249. return task_runner_;
  250. }
  251. // Compositor does not own observers. It is the responsibility of the
  252. // observer to remove itself when it is done observing.
  253. void AddObserver(CompositorObserver* observer);
  254. void RemoveObserver(CompositorObserver* observer);
  255. bool HasObserver(const CompositorObserver* observer) const;
  256. void AddAnimationObserver(CompositorAnimationObserver* observer);
  257. void RemoveAnimationObserver(CompositorAnimationObserver* observer);
  258. bool HasAnimationObserver(const CompositorAnimationObserver* observer) const;
  259. // Creates a compositor lock. Returns NULL if it is not possible to lock at
  260. // this time (i.e. we're waiting to complete a previous unlock). If the
  261. // timeout is null, then no timeout is used.
  262. std::unique_ptr<CompositorLock> GetCompositorLock(
  263. CompositorLockClient* client,
  264. base::TimeDelta timeout = base::Milliseconds(kCompositorLockTimeoutMs)) {
  265. return lock_manager_.GetCompositorLock(client, timeout,
  266. host_->DeferMainFrameUpdate());
  267. }
  268. // Registers a callback that is run when the next frame successfully makes it
  269. // to the screen (it's entirely possible some frames may be dropped between
  270. // the time this is called and the callback is run).
  271. // See ui/gfx/presentation_feedback.h for details on the args (TimeTicks is
  272. // always non-zero).
  273. using PresentationTimeCallback =
  274. base::OnceCallback<void(const gfx::PresentationFeedback&)>;
  275. void RequestPresentationTimeForNextFrame(PresentationTimeCallback callback);
  276. void IssueExternalBeginFrame(
  277. const viz::BeginFrameArgs& args,
  278. bool force,
  279. base::OnceCallback<void(const viz::BeginFrameAck&)> callback);
  280. // Creates a ThroughputTracker for tracking this Compositor.
  281. ThroughputTracker RequestNewThroughputTracker();
  282. // Returns a percentage of dropped frames of the last second.
  283. double GetPercentDroppedFrames() const;
  284. // Activates a scoped monitor for the current event to track its metrics.
  285. // `done_callback` is called when the monitor goes out of scope.
  286. std::unique_ptr<cc::EventsMetricsManager::ScopedMonitor>
  287. GetScopedEventMetricsMonitor(
  288. cc::EventsMetricsManager::ScopedMonitor::DoneCallback done_callback);
  289. // LayerTreeHostClient implementation.
  290. void WillBeginMainFrame() override {}
  291. void DidBeginMainFrame() override {}
  292. void OnDeferMainFrameUpdatesChanged(bool) override {}
  293. void OnDeferCommitsChanged(
  294. bool,
  295. cc::PaintHoldingReason,
  296. absl::optional<cc::PaintHoldingCommitTrigger>) override {}
  297. void WillUpdateLayers() override {}
  298. void DidUpdateLayers() override;
  299. void BeginMainFrame(const viz::BeginFrameArgs& args) override;
  300. void BeginMainFrameNotExpectedSoon() override;
  301. void BeginMainFrameNotExpectedUntil(base::TimeTicks time) override;
  302. void UpdateLayerTreeHost() override;
  303. void ApplyViewportChanges(const cc::ApplyViewportChangesArgs& args) override {
  304. }
  305. void UpdateCompositorScrollState(
  306. const cc::CompositorCommitData& commit_data) override {}
  307. void RequestNewLayerTreeFrameSink() override;
  308. void DidInitializeLayerTreeFrameSink() override {}
  309. void DidFailToInitializeLayerTreeFrameSink() override;
  310. void WillCommit(const cc::CommitState&) override {}
  311. void DidCommit(base::TimeTicks, base::TimeTicks) override;
  312. void DidCommitAndDrawFrame() override {}
  313. void DidReceiveCompositorFrameAck() override;
  314. void DidCompletePageScaleAnimation() override {}
  315. void DidPresentCompositorFrame(
  316. uint32_t frame_token,
  317. const gfx::PresentationFeedback& feedback) override;
  318. void RecordStartOfFrameMetrics() override {}
  319. void RecordEndOfFrameMetrics(
  320. base::TimeTicks frame_begin_time,
  321. cc::ActiveFrameSequenceTrackers trackers) override {}
  322. std::unique_ptr<cc::BeginMainFrameMetrics> GetBeginMainFrameMetrics()
  323. override;
  324. std::unique_ptr<cc::WebVitalMetrics> GetWebVitalMetrics() override;
  325. void NotifyThroughputTrackerResults(
  326. cc::CustomTrackerResults results) override;
  327. void DidObserveFirstScrollDelay(
  328. base::TimeDelta first_scroll_delay,
  329. base::TimeTicks first_scroll_timestamp) override {}
  330. void ReportEventLatency(
  331. std::vector<cc::EventLatencyTracker::LatencyData> latencies) override;
  332. // cc::LayerTreeHostSingleThreadClient implementation.
  333. void DidSubmitCompositorFrame() override;
  334. void DidLoseLayerTreeFrameSink() override {}
  335. void FrameIntervalUpdated(base::TimeDelta interval) override;
  336. void FrameSinksToThrottleUpdated(
  337. const base::flat_set<viz::FrameSinkId>& ids) override;
  338. // viz::HostFrameSinkClient implementation.
  339. void OnFirstSurfaceActivation(const viz::SurfaceInfo& surface_info) override;
  340. void OnFrameTokenChanged(uint32_t frame_token,
  341. base::TimeTicks activation_time) override;
  342. // ThroughputTrackerHost implementation.
  343. void StartThroughputTracker(
  344. TrackerId tracker_id,
  345. ThroughputTrackerHost::ReportCallback callback) override;
  346. bool StopThroughtputTracker(TrackerId tracker_id) override;
  347. void CancelThroughtputTracker(TrackerId tracker_id) override;
  348. // base::PowerSuspendObserver:
  349. void OnResume() override;
  350. // TODO(crbug.com/1052397): Revisit the macro expression once build flag switch
  351. // of lacros-chrome is complete.
  352. #if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS_LACROS)
  353. void OnCompleteSwapWithNewSize(const gfx::Size& size);
  354. #endif
  355. bool IsLocked() { return lock_manager_.IsLocked(); }
  356. void SetOutputIsSecure(bool output_is_secure);
  357. const cc::LayerTreeDebugState& GetLayerTreeDebugState() const;
  358. void SetLayerTreeDebugState(const cc::LayerTreeDebugState& debug_state);
  359. LayerAnimatorCollection* layer_animator_collection() {
  360. return &layer_animator_collection_;
  361. }
  362. const viz::FrameSinkId& frame_sink_id() const { return frame_sink_id_; }
  363. int activated_frame_count() const { return activated_frame_count_; }
  364. float refresh_rate() const { return refresh_rate_; }
  365. bool use_external_begin_frame_control() const {
  366. return use_external_begin_frame_control_;
  367. }
  368. void SetAllowLocksToExtendTimeout(bool allowed) {
  369. lock_manager_.set_allow_locks_to_extend_timeout(allowed);
  370. }
  371. // If true, all paint commands are recorded at pixel size instead of DIP.
  372. bool is_pixel_canvas() const { return is_pixel_canvas_; }
  373. ScrollInputHandler* scroll_input_handler() const {
  374. return scroll_input_handler_.get();
  375. }
  376. virtual void SetDelegatedInkPointRenderer(
  377. mojo::PendingReceiver<gfx::mojom::DelegatedInkPointRenderer> receiver);
  378. const cc::LayerTreeSettings& GetLayerTreeSettings() const;
  379. private:
  380. friend class base::RefCounted<Compositor>;
  381. friend class TotalAnimationThroughputReporter;
  382. // Called when collected metrics for the tracker of |tracker_id| is ready.
  383. void ReportMetricsForTracker(
  384. int tracker_id,
  385. const cc::FrameSequenceMetrics::CustomReportData& data);
  386. gfx::Size size_;
  387. raw_ptr<ui::ContextFactory> context_factory_;
  388. // |display_private_| can be null for:
  389. // 1. Tests that don't set |display_private_|.
  390. // 2. Intermittently on creation or if there is some kind of error (GPU crash,
  391. // GL context loss, etc.) that triggers reinitializing message pipes to the
  392. // GPU process RootCompositorFrameSinkImpl.
  393. // Therefore, it should always be null checked for safety before use.
  394. //
  395. // These pointers are owned by |context_factory_|, and must be reset before
  396. // calling RemoveCompositor();
  397. raw_ptr<viz::mojom::DisplayPrivate, DanglingUntriaged> display_private_ =
  398. nullptr;
  399. raw_ptr<viz::mojom::ExternalBeginFrameController>
  400. external_begin_frame_controller_ = nullptr;
  401. std::unique_ptr<PendingBeginFrameArgs> pending_begin_frame_args_;
  402. // The root of the Layer tree drawn by this compositor.
  403. raw_ptr<Layer> root_layer_ = nullptr;
  404. base::ObserverList<CompositorObserver, true>::Unchecked observer_list_;
  405. base::ObserverList<CompositorAnimationObserver>::Unchecked
  406. animation_observer_list_;
  407. gfx::AcceleratedWidget widget_ = gfx::kNullAcceleratedWidget;
  408. // A sequence number of a current compositor frame for use with metrics.
  409. int activated_frame_count_ = 0;
  410. // Current vsync refresh rate per second. Initialized to 60hz as a reasonable
  411. // value until first begin frame arrives with the real refresh rate.
  412. float refresh_rate_ = 60.f;
  413. // A map from child id to parent id.
  414. std::unordered_set<viz::FrameSinkId, viz::FrameSinkIdHash> child_frame_sinks_;
  415. bool widget_valid_ = false;
  416. bool layer_tree_frame_sink_requested_ = false;
  417. const viz::FrameSinkId frame_sink_id_;
  418. scoped_refptr<cc::Layer> root_web_layer_;
  419. std::unique_ptr<cc::AnimationHost> animation_host_;
  420. std::unique_ptr<cc::LayerTreeHost> host_;
  421. base::WeakPtr<cc::InputHandler> input_handler_weak_;
  422. scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
  423. // Snapshot of last set vsync parameters, to avoid redundant IPCs.
  424. base::TimeTicks vsync_timebase_;
  425. base::TimeDelta vsync_interval_ = viz::BeginFrameArgs::DefaultInterval();
  426. bool has_vsync_params_ = false;
  427. const bool use_external_begin_frame_control_;
  428. const bool force_software_compositor_;
  429. // The device scale factor of the monitor that this compositor is compositing
  430. // layers on.
  431. float device_scale_factor_ = 0.f;
  432. LayerAnimatorCollection layer_animator_collection_;
  433. scoped_refptr<cc::AnimationTimeline> animation_timeline_;
  434. std::unique_ptr<ScopedAnimationDurationScaleMode> slow_animations_;
  435. SkM44 display_color_matrix_;
  436. gfx::DisplayColorSpaces display_color_spaces_;
  437. bool output_is_secure_ = false;
  438. // If true, all paint commands are recorded at pixel size instead of DIP.
  439. const bool is_pixel_canvas_;
  440. CompositorLockManager lock_manager_;
  441. std::unique_ptr<ScrollInputHandler> scroll_input_handler_;
  442. #if BUILDFLAG(IS_WIN)
  443. bool should_disable_swap_until_resize_ = false;
  444. #endif
  445. // Set in DisableSwapUntilResize and reset when a resize happens.
  446. bool disabled_swap_until_resize_ = false;
  447. bool animations_are_enabled_ = true;
  448. TrackerId next_throughput_tracker_id_ = 1u;
  449. struct TrackerState {
  450. TrackerState();
  451. TrackerState(TrackerState&&);
  452. TrackerState& operator=(TrackerState&&);
  453. ~TrackerState();
  454. // Whether a tracker is waiting for report and `report_callback` should be
  455. // invoked. This is set to true when a tracker is stopped.
  456. bool should_report = false;
  457. // Whether the report for a tracker has happened. This is set when an
  458. // involuntary report happens before the tracker is stopped and set
  459. // `should_report` field above.
  460. bool report_attempted = false;
  461. // Invoked to send report to the owner of a tracker.
  462. ThroughputTrackerHost::ReportCallback report_callback;
  463. };
  464. using ThroughputTrackerMap = base::flat_map<TrackerId, TrackerState>;
  465. ThroughputTrackerMap throughput_tracker_map_;
  466. base::WeakPtrFactory<Compositor> context_creation_weak_ptr_factory_{this};
  467. base::WeakPtrFactory<Compositor> weak_ptr_factory_{this};
  468. };
  469. } // namespace ui
  470. #endif // UI_COMPOSITOR_COMPOSITOR_H_