xref: /aosp_15_r20/development/tools/winscope/src/viewers/common/operations/add_chips.ts (revision 90c8c64db3049935a07c6143d7fd006e26f8ecca)
1/*
2 * Copyright (C) 2024 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17import {LayerCompositionType} from 'trace/layer_composition_type';
18import {Operation} from 'trace/tree_node/operations/operation';
19import {
20  DUPLICATE_CHIP,
21  GPU_CHIP,
22  HIDDEN_BY_POLICY_CHIP,
23  HWC_CHIP,
24  MISSING_Z_PARENT_CHIP,
25  RELATIVE_Z_CHIP,
26  RELATIVE_Z_PARENT_CHIP,
27  VISIBLE_CHIP,
28} from 'viewers/common/chip';
29import {UiHierarchyTreeNode} from 'viewers/common/ui_hierarchy_tree_node';
30
31export class AddChips implements Operation<UiHierarchyTreeNode> {
32  private relZParentIds: string[] = [];
33
34  apply(node: UiHierarchyTreeNode): void {
35    this.addAllChipsExceptRelZParent(node);
36    this.addRelZParentChips(node);
37  }
38
39  private addAllChipsExceptRelZParent(node: UiHierarchyTreeNode) {
40    if (!node.isRoot()) {
41      const compositionType = node
42        .getEagerPropertyByName('compositionType')
43        ?.getValue();
44      if (compositionType === LayerCompositionType.GPU) {
45        node.addChip(GPU_CHIP);
46      } else if (compositionType === LayerCompositionType.HWC) {
47        node.addChip(HWC_CHIP);
48      }
49
50      if (node.getEagerPropertyByName('isComputedVisible')?.getValue()) {
51        node.addChip(VISIBLE_CHIP);
52      }
53
54      if (node.getEagerPropertyByName('isDuplicate')?.getValue()) {
55        node.addChip(DUPLICATE_CHIP);
56      }
57
58      if (node.getEagerPropertyByName('isHiddenByPolicy')?.getValue()) {
59        node.addChip(HIDDEN_BY_POLICY_CHIP);
60      }
61
62      const zOrderRelativeOfId = node
63        .getEagerPropertyByName('zOrderRelativeOf')
64        ?.getValue();
65      if (zOrderRelativeOfId && zOrderRelativeOfId !== -1) {
66        node.addChip(RELATIVE_Z_CHIP);
67        this.relZParentIds.push(zOrderRelativeOfId);
68
69        if (node.getEagerPropertyByName('isMissingZParent')?.getValue()) {
70          node.addChip(MISSING_Z_PARENT_CHIP);
71        }
72      }
73    }
74
75    node
76      .getAllChildren()
77      .forEach((child) => this.addAllChipsExceptRelZParent(child));
78  }
79
80  private addRelZParentChips(node: UiHierarchyTreeNode) {
81    const treeLayerId = node.getEagerPropertyByName('id')?.getValue();
82    if (this.relZParentIds.includes(treeLayerId)) {
83      node.addChip(RELATIVE_Z_PARENT_CHIP);
84    }
85
86    node.getAllChildren().forEach((child) => this.addRelZParentChips(child));
87  }
88}
89