File: surface_id.h

package info (click to toggle)
chromium 139.0.7258.127-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 6,122,156 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 (99 lines) | stat: -rw-r--r-- 3,380 bytes parent folder | download | duplicates (6)
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
// Copyright 2014 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_COMMON_SURFACES_SURFACE_ID_H_
#define COMPONENTS_VIZ_COMMON_SURFACES_SURFACE_ID_H_

#include <stdint.h>

#include <compare>
#include <iosfwd>
#include <string>
#include <string_view>

#include "base/hash/hash.h"
#include "components/viz/common/surfaces/frame_sink_id.h"
#include "components/viz/common/surfaces/local_surface_id.h"
#include "components/viz/common/viz_common_export.h"
#include "mojo/public/cpp/bindings/struct_traits.h"

namespace viz {

namespace mojom {
class SurfaceIdDataView;
}

class VIZ_COMMON_EXPORT SurfaceId {
 public:
  constexpr SurfaceId() = default;

  constexpr SurfaceId(const SurfaceId& other) = default;
  constexpr SurfaceId& operator=(const SurfaceId& other) = default;

  // A SurfaceId consists of two components: FrameSinkId and LocalSurfaceId.
  // A |frame_sink_id| consists of two components; one is allocated by the
  // display compositor service and one is allocated by the client. The
  // |frame_sink_id| uniquely identifies a FrameSink (and frame source).
  // A |local_surface_id| is a sequentially allocated ID generated by the frame
  // source that uniquely identifies a sequential set of frames of the same size
  // and device scale factor.
  constexpr SurfaceId(const FrameSinkId& frame_sink_id,
                      const LocalSurfaceId& local_surface_id)
      : frame_sink_id_(frame_sink_id), local_surface_id_(local_surface_id) {}

  static constexpr SurfaceId MaxSequenceId(const FrameSinkId& frame_sink_id) {
    return SurfaceId(frame_sink_id, LocalSurfaceId::MaxSequenceId());
  }

  bool is_valid() const {
    return frame_sink_id_.is_valid() && local_surface_id_.is_valid();
  }

  size_t hash() const {
    return base::HashInts(static_cast<uint64_t>(frame_sink_id_.hash()),
                          static_cast<uint64_t>(local_surface_id_.hash()));
  }

  const FrameSinkId& frame_sink_id() const { return frame_sink_id_; }

  const LocalSurfaceId& local_surface_id() const { return local_surface_id_; }

  std::string ToString() const;

  std::string ToString(std::string_view frame_sink_debug_label) const;

  // Returns whether this SurfaceId was generated after |other|.
  bool IsNewerThan(const SurfaceId& other) const;

  // Returns whether this SurfaceId is the same as or was generated after
  // |other|.
  bool IsSameOrNewerThan(const SurfaceId& other) const;

  // Returns the smallest valid SurfaceId with the same FrameSinkId and embed
  // token as this SurfaceId.
  SurfaceId ToSmallestId() const;

  // Returns whether this SurfaceId has the same embed token as |other|.
  bool HasSameEmbedTokenAs(const SurfaceId& other) const;

  friend std::strong_ordering operator<=>(const SurfaceId&,
                                          const SurfaceId&) = default;

 private:
  friend struct mojo::StructTraits<mojom::SurfaceIdDataView, SurfaceId>;

  FrameSinkId frame_sink_id_;
  LocalSurfaceId local_surface_id_;
};

VIZ_COMMON_EXPORT std::ostream& operator<<(std::ostream& out,
                                           const SurfaceId& surface_id);

struct SurfaceIdHash {
  size_t operator()(const SurfaceId& key) const { return key.hash(); }
};

}  // namespace viz

#endif  // COMPONENTS_VIZ_COMMON_SURFACES_SURFACE_ID_H_