File: frame_sink_bundle_impl.h

package info (click to toggle)
chromium 139.0.7258.127-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 6,122,068 kB
  • sloc: cpp: 35,100,771; ansic: 7,163,530; javascript: 4,103,002; python: 1,436,920; asm: 946,517; xml: 746,709; pascal: 187,653; perl: 88,691; sh: 88,436; objc: 79,953; sql: 51,488; cs: 44,583; fortran: 24,137; makefile: 22,147; tcl: 15,277; php: 13,980; yacc: 8,984; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (119 lines) | stat: -rw-r--r-- 4,880 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
// Copyright 2021 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef COMPONENTS_VIZ_SERVICE_FRAME_SINKS_FRAME_SINK_BUNDLE_IMPL_H_
#define COMPONENTS_VIZ_SERVICE_FRAME_SINKS_FRAME_SINK_BUNDLE_IMPL_H_

#include <cstdint>
#include <map>
#include <memory>
#include <set>
#include <vector>

#include "base/containers/flat_map.h"
#include "base/memory/raw_ref.h"
#include "build/build_config.h"
#include "components/viz/common/frame_sinks/begin_frame_source.h"
#include "components/viz/common/surfaces/frame_sink_bundle_id.h"
#include "mojo/public/cpp/bindings/receiver.h"
#include "mojo/public/cpp/bindings/receiver_set.h"
#include "mojo/public/cpp/bindings/remote.h"
#include "services/viz/public/mojom/compositing/compositor_frame_sink.mojom.h"
#include "services/viz/public/mojom/compositing/frame_sink_bundle.mojom.h"

namespace viz {

class CompositorFrameSinkImpl;
class CompositorFrameSinkSupport;
class FrameSinkManagerImpl;

// This object receives aggregate SubmitCompositorFrame and DidNotProduceFrame
// messages from remote CompositorFrameSink clients, with the `client_id`, who
// who were created as part of this bundle.
//
// Outgoing client messages from the corresponding CompositorFrameSinkImpls are
// also aggregated here and sent in batch back to the client.
//
// The bundle accepts any kind of sink from the same client, and messages are
// batched together for sinks which share a BeginFrameSource.
class FrameSinkBundleImpl : public mojom::FrameSinkBundle {
 public:
  // Constructs a new FrameSinkBundleImpl for a subset of sinks belonging to
  // `client_id`.
  FrameSinkBundleImpl(FrameSinkManagerImpl& manager,
                      const FrameSinkBundleId& id,
                      mojo::PendingReceiver<mojom::FrameSinkBundle> receiver,
                      mojo::PendingRemote<mojom::FrameSinkBundleClient> client);
  FrameSinkBundleImpl(const FrameSinkBundleImpl&) = delete;
  FrameSinkBundleImpl& operator=(const FrameSinkBundleImpl&) = delete;
  ~FrameSinkBundleImpl() override;

  const FrameSinkBundleId& id() const { return id_; }

  // Called by the identified sink itself to notify the bundle that the sink
  // needs (or no longer needs) BeginFrame notifications. This is distinct from
  // SetNeedsBeginFrame(), as the latter is only called by clients.
  void SetSinkNeedsBeginFrame(uint32_t sink_id, bool needs_begin_frame);

  void AddFrameSink(CompositorFrameSinkSupport* support);
  void UpdateFrameSink(CompositorFrameSinkSupport* support,
                       BeginFrameSource* old_source);
  void RemoveFrameSink(CompositorFrameSinkSupport* support);

  // mojom::FrameSinkBundle implementation:
  void SetNeedsBeginFrame(uint32_t sink_id, bool needs_begin_frame) override;
  void Submit(
      std::vector<mojom::BundledFrameSubmissionPtr> submissions) override;

#if BUILDFLAG(IS_ANDROID)
  void SetThreads(uint32_t sink_id,
                  const std::vector<Thread>& threads) override;
#endif

  // Helpers used by each CompositorFrameSinkImpl to proxy their client messages
  // to this object for potentially batched communication.
  void EnqueueDidReceiveCompositorFrameAck(
      uint32_t sink_id,
      std::vector<ReturnedResource> resources);
  void EnqueueOnBeginFrame(
      uint32_t sink_id,
      const BeginFrameArgs& args,
      const base::flat_map<uint32_t, FrameTimingDetails>& details,
      std::vector<ReturnedResource> resources);
  void EnqueueReclaimResources(uint32_t sink_id,
                               std::vector<ReturnedResource> resources);
  void SendOnBeginFramePausedChanged(uint32_t sink_id, bool paused);
  void SendOnCompositorFrameTransitionDirectiveProcessed(uint32_t sink_id,
                                                         uint32_t sequence_id);

 private:
  class SinkGroup;

  void RemoveFrameSinkImpl(BeginFrameSource* source, uint32_t sink_id);

  CompositorFrameSinkImpl* GetFrameSink(uint32_t sink_id) const;
  CompositorFrameSinkSupport* GetFrameSinkSupport(uint32_t sink_id) const;
  SinkGroup* GetSinkGroup(uint32_t sink_id) const;

  void OnDisconnect();

  const raw_ref<FrameSinkManagerImpl> manager_;
  const FrameSinkBundleId id_;

  mojo::Receiver<mojom::FrameSinkBundle> receiver_;
  mojo::Remote<mojom::FrameSinkBundleClient> client_;

  // Set of sinks that are in the bundle but don't yet have a known
  // BeginFrameSource. These sinks will not receive OnBeginFrame notifications
  // until they get a BeginFrameSource.
  std::set<uint32_t> sourceless_sinks_;

  // Mapping from BeginFrameSource to the SinkGroup which manages batched
  // communication for all the sinks which share that source.
  base::flat_map<BeginFrameSource*, std::unique_ptr<SinkGroup>> sink_groups_;
};

}  // namespace viz

#endif  // COMPONENTS_VIZ_SERVICE_FRAME_SINKS_FRAME_SINK_BUNDLE_IMPL_H_