File: compositing_reasons.cc

package info (click to toggle)
chromium 138.0.7204.183-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 6,071,908 kB
  • sloc: cpp: 34,937,088; ansic: 7,176,967; javascript: 4,110,704; python: 1,419,953; asm: 946,768; xml: 739,971; pascal: 187,324; sh: 89,623; perl: 88,663; objc: 79,944; sql: 50,304; cs: 41,786; fortran: 24,137; makefile: 21,806; php: 13,980; tcl: 13,166; yacc: 8,925; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (172 lines) | stat: -rw-r--r-- 7,479 bytes parent folder | download | duplicates (2)
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
// 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.

#include "third_party/blink/renderer/platform/graphics/compositing_reasons.h"

#include <array>

#include "third_party/blink/renderer/platform/wtf/std_lib_extras.h"
#include "third_party/blink/renderer/platform/wtf/text/string_builder.h"

namespace blink {

namespace {

#define V(name) #name,
constexpr auto kShortNames =
    std::to_array<const char* const>({FOR_EACH_COMPOSITING_REASON(V)});
#undef V

struct ReasonAndDescription {
  CompositingReasons reason;
  const char* description;
};
constexpr auto kReasonDescriptionMap = std::to_array<ReasonAndDescription>({
    {CompositingReason::k3DTransform, "Has a 3d transform."},
    {CompositingReason::k3DScale, "Has a 3d scale."},
    {CompositingReason::k3DRotate, "Has a 3d rotate."},
    {CompositingReason::k3DTranslate, "Has a 3d translate."},
    {CompositingReason::kTrivial3DTransform, "Has a trivial 3d transform."},
    {CompositingReason::kIFrame, "Is an accelerated iFrame."},
    {CompositingReason::kActiveTransformAnimation,
     "Has an active accelerated transform animation or transition."},
    {CompositingReason::kActiveScaleAnimation,
     "Has an active accelerated scale animation or transition."},
    {CompositingReason::kActiveRotateAnimation,
     "Has an active accelerated rotate animation or transition."},
    {CompositingReason::kActiveTranslateAnimation,
     "Has an active accelerated translate animation or transition."},
    {CompositingReason::kActiveOpacityAnimation,
     "Has an active accelerated opacity animation or transition."},
    {CompositingReason::kActiveFilterAnimation,
     "Has an active accelerated filter animation or transition."},
    {CompositingReason::kActiveBackdropFilterAnimation,
     "Has an active accelerated backdrop filter animation or transition."},
    {CompositingReason::kAffectedByOuterViewportBoundsDelta,
     "Is fixed position affected by outer viewport bounds delta."},
    {CompositingReason::kAffectedBySafeAreaBottom,
     "Is fixed position affected by safe area bottom."},
    {CompositingReason::kFixedPosition,
     "Is fixed position in a scrollable view."},
    {CompositingReason::kUndoOverscroll,
     "Is fixed position that should undo overscroll of the viewport."},
    {CompositingReason::kStickyPosition, "Is sticky position."},
    {CompositingReason::kAnchorPosition,
     "Is an anchor-positioned element translated by its anchor's scroll "
     "offset."},
    {CompositingReason::kBackdropFilter, "Has a backdrop filter."},
    {CompositingReason::kBackdropFilterMask, "Is a mask for backdrop filter."},
    {CompositingReason::kRootScroller, "Is the document.rootScroller."},
    {CompositingReason::kViewport, "Is for the visual viewport."},
    {CompositingReason::kWillChangeTransform,
     "Has a will-change: transform compositing hint."},
    {CompositingReason::kWillChangeScale,
     "Has a will-change: scale compositing hint."},
    {CompositingReason::kWillChangeRotate,
     "Has a will-change: rotate compositing hint."},
    {CompositingReason::kWillChangeTranslate,
     "Has a will-change: translate compositing hint."},
    {CompositingReason::kWillChangeOpacity,
     "Has a will-change: opacity compositing hint."},
    {CompositingReason::kWillChangeFilter,
     "Has a will-change: filter compositing hint."},
    {CompositingReason::kWillChangeBackdropFilter,
     "Has a will-change: backdrop-filter compositing hint."},
    {CompositingReason::kWillChangeClipPath,
     "Has a will-change: clip-path compositing hint."},
    {CompositingReason::kWillChangeMixBlendMode,
     "Has a will-change: mix-blend-mode compositing hint."},
    {CompositingReason::kWillChangeOther,
     "Has a will-change compositing hint other than transform, opacity, filter"
     " and backdrop-filter."},
    {CompositingReason::kBackfaceInvisibility3DAncestor,
     "Ancestor in same 3D rendering context has a hidden backface."},
    {CompositingReason::kTransform3DSceneLeaf,
     "Leaf of a 3D scene, for flattening its descendants into that scene."},
    {CompositingReason::kPerspectiveWith3DDescendants,
     "Has a perspective transform that needs to be known by compositor because "
     "of 3d descendants."},
    {CompositingReason::kPreserve3DWith3DDescendants,
     "Has a preserves-3d property that needs to be known by compositor because "
     "of 3d descendants."},
    {CompositingReason::kViewTransitionElement,
     "This element is shared during view transition."},
    {CompositingReason::kViewTransitionPseudoElement,
     "This element is a part of a pseudo element tree representing the view "
     "transition."},
    {CompositingReason::kViewTransitionElementDescendantWithClipPath,
     "This element's ancestor is shared during view transition and it has a "
     "clip-path"},
    {CompositingReason::kOverflowScrolling,
     "Is a scrollable overflow element using accelerated scrolling."},
    {CompositingReason::kElementCapture,
     "This element is undergoing element-level capture."},
    {CompositingReason::kOverlap, "Overlaps other composited content."},
    {CompositingReason::kBackfaceVisibilityHidden,
     "Has backface-visibility: hidden."},
    {CompositingReason::kFixedAttachmentBackground,
     "Is an accelerated background-attachment:fixed background."},
    {CompositingReason::kCaret, "Is a caret in an editor."},
    {CompositingReason::kVideo, "Is an accelerated video."},
    {CompositingReason::kCanvas,
     "Is an accelerated canvas, or is a display list backed canvas that was "
     "promoted to a layer based on a performance heuristic."},
    {CompositingReason::kPlugin, "Is an accelerated plugin."},
    {CompositingReason::kScrollbar, "Is an accelerated scrollbar."},
    {CompositingReason::kLinkHighlight, "Is a tap highlight on a link."},
    {CompositingReason::kDevToolsOverlay, "Is DevTools overlay."},
    {CompositingReason::kViewTransitionContent,
     "The layer containing the contents of a view transition element."},
});

}  // anonymous namespace

std::vector<const char*> CompositingReason::ShortNames(
    CompositingReasons reasons) {
  std::vector<const char*> result;
  if (reasons == kNone) {
    return result;
  }
  for (size_t i = 0; i < std::size(kShortNames); i++) {
    if (reasons & (UINT64_C(1) << i)) {
      result.push_back(kShortNames[i]);
    }
  }
  return result;
}

std::vector<const char*> CompositingReason::Descriptions(
    CompositingReasons reasons) {
#define V(name)                                                      \
  static_assert(                                                     \
      CompositingReason::k##name ==                                  \
          kReasonDescriptionMap[CompositingReason::kE##name].reason, \
      "kReasonDescriptionMap needs update for CompositingReason::k" #name);

  FOR_EACH_COMPOSITING_REASON(V)
#undef V

  std::vector<const char*> result;
  if (reasons == kNone) {
    return result;
  }
  for (auto& map : kReasonDescriptionMap) {
    if (reasons & map.reason) {
      result.push_back(map.description);
    }
  }
  return result;
}

String CompositingReason::ToString(CompositingReasons reasons) {
  StringBuilder builder;
  for (const char* name : ShortNames(reasons)) {
    if (builder.length())
      builder.Append(',');
    builder.Append(name);
  }
  return builder.ToString();
}

}  // namespace blink