File: property_tree_state.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 (138 lines) | stat: -rw-r--r-- 5,188 bytes parent folder | download | duplicates (4)
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
// Copyright 2016 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/paint/property_tree_state.h"

#include <memory>

namespace blink {

namespace {

using IsCompositedScrollFunction =
    PropertyTreeState::IsCompositedScrollFunction;

const TransformPaintPropertyNode* NearestCompositedScrollTranslation(
    const TransformPaintPropertyNode& scroll_translation,
    IsCompositedScrollFunction is_composited_scroll) {
  for (auto* t = &scroll_translation; t->Parent();
       t = &t->UnaliasedParent()->NearestScrollTranslationNode()) {
    if (is_composited_scroll(*t)) {
      return t;
    }
  }
  return nullptr;
}

bool InSameTransformCompositingBoundary(
    const TransformPaintPropertyNode& t1,
    const TransformPaintPropertyNode& t2,
    IsCompositedScrollFunction is_composited_scroll) {
  const auto* composited_ancestor1 = t1.NearestDirectlyCompositedAncestor();
  const auto* composited_ancestor2 = t2.NearestDirectlyCompositedAncestor();
  if (composited_ancestor1 != composited_ancestor2) {
    return false;
  }
  // There may be indirectly composited scroll translations below the common
  // nearest directly composited ancestor. Check if t1 and t2 have the same
  // nearest composited scroll translation.
  const auto& scroll_translation1 = t1.NearestScrollTranslationNode();
  const auto& scroll_translation2 = t2.NearestScrollTranslationNode();
  if (&scroll_translation1 == &scroll_translation2) {
    return true;
  }
  return NearestCompositedScrollTranslation(scroll_translation1,
                                            is_composited_scroll) ==
         NearestCompositedScrollTranslation(scroll_translation2,
                                            is_composited_scroll);
}

bool ClipChainInTransformCompositingBoundary(
    const ClipPaintPropertyNode& node,
    const ClipPaintPropertyNode& ancestor,
    const TransformPaintPropertyNode& transform,
    IsCompositedScrollFunction is_composited_scroll) {
  for (const auto* n = &node; n != &ancestor; n = n->UnaliasedParent()) {
    if (!InSameTransformCompositingBoundary(transform,
                                            n->LocalTransformSpace().Unalias(),
                                            is_composited_scroll)) {
      return false;
    }
  }
  return true;
}

}  // namespace

std::optional<PropertyTreeState> PropertyTreeState::CanUpcastWith(
    const PropertyTreeState& guest,
    IsCompositedScrollFunction is_composited_scroll) const {
  // A number of criteria need to be met:
  //   1. The guest effect must be a descendant of the home effect. However this
  // check is enforced by the layerization recursion. Here we assume the guest
  // has already been upcasted to the same effect.
  //   2. The guest transform and the home transform have compatible backface
  // visibility.
  //   3. The guest transform space must be within compositing boundary of the
  // home transform space.
  //   4. The local space of each clip on the ancestor chain must be within
  // compositing boundary of the home transform space.
  DCHECK_EQ(&Effect(), &guest.Effect());

  const TransformPaintPropertyNode* upcast_transform = nullptr;
  // Fast-path for the common case of the transform state being equal.
  if (&Transform() == &guest.Transform()) {
    upcast_transform = &Transform();
  } else {
    if (!InSameTransformCompositingBoundary(Transform(), guest.Transform(),
                                            is_composited_scroll)) {
      return std::nullopt;
    }
    if (Transform().IsBackfaceHidden() !=
        guest.Transform().IsBackfaceHidden()) {
      return std::nullopt;
    }
    upcast_transform =
        &Transform().LowestCommonAncestor(guest.Transform()).Unalias();
  }

  const ClipPaintPropertyNode* upcast_clip = nullptr;
  if (&Clip() == &guest.Clip()) {
    upcast_clip = &Clip();
  } else {
    upcast_clip = &Clip().LowestCommonAncestor(guest.Clip()).Unalias();
    if (!ClipChainInTransformCompositingBoundary(
            Clip(), *upcast_clip, *upcast_transform, is_composited_scroll) ||
        !ClipChainInTransformCompositingBoundary(guest.Clip(), *upcast_clip,
                                                 *upcast_transform,
                                                 is_composited_scroll)) {
      return std::nullopt;
    }
  }

  return PropertyTreeState(*upcast_transform, *upcast_clip, Effect());
}

String PropertyTreeStateOrAlias::ToString() const {
  return String::Format("t:%p c:%p e:%p", transform_, clip_, effect_);
}

#if DCHECK_IS_ON()

String PropertyTreeStateOrAlias::ToTreeString() const {
  return "transform:\n" + Transform().ToTreeString() + "\nclip:\n" +
         Clip().ToTreeString() + "\neffect:\n" + Effect().ToTreeString();
}

#endif

std::unique_ptr<JSONObject> PropertyTreeStateOrAlias::ToJSON() const {
  std::unique_ptr<JSONObject> result = std::make_unique<JSONObject>();
  result->SetObject("transform", transform_->ToJSON());
  result->SetObject("clip", clip_->ToJSON());
  result->SetObject("effect", effect_->ToJSON());
  return result;
}

}  // namespace blink