File: overlay_layer_id.h

package info (click to toggle)
chromium 139.0.7258.127-2
  • links: PTS, VCS
  • area: main
  • in suites: forky
  • 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 (107 lines) | stat: -rw-r--r-- 3,713 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
// Copyright 2024 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef UI_GFX_OVERLAY_LAYER_ID_H_
#define UI_GFX_OVERLAY_LAYER_ID_H_

#include <stdint.h>

#include <array>
#include <compare>
#include <optional>
#include <string>
#include <utility>
#include <variant>

#include "base/component_export.h"
#include "base/types/id_type.h"

namespace viz {
class AggregatedRenderPass;
}

namespace gfx {

// An identifier for an overlay layer that is unique within a frame. Should be
// stable across frames if OS compositor subtree reuse is desired.
class COMPONENT_EXPORT(GFX) OverlayLayerId {
 public:
  using NamespaceId = std::pair<uint32_t, uint32_t>;
  // Copy of AggregatedRenderPassId, since we cannot depend on viz from here.
  using RenderPassId = base::IdTypeU64<viz::AggregatedRenderPass>;

  // The default constructed instance represents the implicit root node of the
  // OS compositor tree.
  OverlayLayerId();
  // `layer_namespace_id` must be non-zero.
  OverlayLayerId(const NamespaceId& layer_namespace_id,
                 uint32_t layer_id,
                 uint32_t sqs_z_order = 0);
  ~OverlayLayerId();

  // The set of named layers that Viz make create that do not (or cannot) map
  // back to anything in any compositor frames.
  enum class VizInternalId : uint32_t {
    kOsCompositorRoot,
    kDelegatedInkTrail,
  };

  // Create a named `OverlayLayerId` that is namespaced for internal viz use.
  static OverlayLayerId MakeVizInternal(VizInternalId layer_id);

  // Create an `OverlayLayerId` that is namespaced for internal viz use and
  // identifies a render pass ID.
  static OverlayLayerId MakeVizInternalRenderPass(RenderPassId render_pass_id);

  // Create an `OverlayLayerId` with a `layer_namespace_id` of {1,1}.
  static OverlayLayerId MakeForTesting(uint32_t layer_id);

  // We are currently using the `SharedQuadState` layer ID, which is unique if a
  // layer only contains one quad. In the case a layer contains more than one
  // quad, use this function to derive unique IDs for the children.
  OverlayLayerId MakeForChildOfSharedQuadStateLayer(
      uint32_t non_zero_z_order) const;

  auto operator<=>(const OverlayLayerId&) const = default;

  std::string ToString() const;

  // TODO(crbug.com/324460866): remove when we remove partial delegation.
  using SharedQuadStateLayerId = std::tuple<NamespaceId, uint32_t, uint32_t>;
  std::optional<SharedQuadStateLayerId> shared_quad_state_layer_id() const;

 private:
  // Represents a layer ID that is constructed from a `cc::Layer` and the frame
  // sink it came from.
  struct RendererLayer {
    // See `viz::SharedQuadState::layer_namespace_id`.
    // A value of 0 is reserved for Viz use.
    NamespaceId layer_namespace_id;
    // See `viz::SharedQuadState::layer_id`.
    uint32_t layer_id = 0;

    // An identifier to disambiguate multiple `SharedQuadState` produced by the
    // same `cc::Layer`.
    uint32_t sqs_z_order = 0;

    auto operator<=>(const RendererLayer&) const = default;
  };

  // Note we store the `RenderPassId` as a byte array to not force `impl_` (and
  // its discriminant) to be aligned to 8 bytes.
  std::variant<VizInternalId,
               std::array<uint8_t, sizeof(RenderPassId)>,
               RendererLayer>
      impl_;

  // This is a hack while we need to derive a stable layer ID statelessly in
  // viz. This is non-zero and used for child layers when a cc layer has more
  // than one quad under it. When this is zero this ID refers to the container
  // node that represents the cc layer itself.
  uint32_t z_order_ = 0;
};

}  // namespace gfx

#endif  // UI_GFX_OVERLAY_LAYER_ID_H_