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 {UserWarning} from 'messaging/user_warning'; 18import {TraceRect} from 'trace/trace_rect'; 19import {PropertiesProvider} from 'trace/tree_node/properties_provider'; 20import {PropertyTreeNode} from './property_tree_node'; 21import {TreeNode} from './tree_node'; 22 23export class HierarchyTreeNode extends TreeNode { 24 private rects: TraceRect[] | undefined; 25 private secondaryRects: TraceRect[] | undefined; 26 private zParent: HierarchyTreeNode | undefined; 27 private parent: this | undefined; 28 private relativeChildren: HierarchyTreeNode[] = []; 29 private warnings: UserWarning[] = []; 30 31 constructor( 32 id: string, 33 name: string, 34 protected readonly propertiesProvider: PropertiesProvider, 35 ) { 36 super(id, name); 37 } 38 39 async getAllProperties(): Promise<PropertyTreeNode> { 40 return await this.propertiesProvider.getAll(); 41 } 42 43 getEagerPropertyByName(name: string): PropertyTreeNode | undefined { 44 return this.propertiesProvider.getEagerProperties().getChildByName(name); 45 } 46 47 addEagerProperty(property: PropertyTreeNode): void { 48 this.propertiesProvider.addEagerProperty(property); 49 } 50 51 setRects(value: TraceRect[]) { 52 this.rects = value; 53 } 54 55 getRects(): TraceRect[] | undefined { 56 return this.rects; 57 } 58 59 setSecondaryRects(value: TraceRect[]) { 60 this.secondaryRects = value; 61 } 62 63 getSecondaryRects(): TraceRect[] | undefined { 64 return this.secondaryRects; 65 } 66 67 setZParent(value: HierarchyTreeNode): void { 68 this.zParent = value; 69 } 70 71 getZParent(): HierarchyTreeNode | undefined { 72 return this.zParent ?? this.parent; 73 } 74 75 setParent(parent: this): void { 76 this.parent = parent; 77 } 78 79 getParent(): this | undefined { 80 return this.parent; 81 } 82 83 addRelativeChild(value: HierarchyTreeNode): void { 84 this.relativeChildren.push(value); 85 } 86 87 getRelativeChildren(): HierarchyTreeNode[] { 88 return this.relativeChildren; 89 } 90 91 override isRoot(): boolean { 92 return !this.parent; 93 } 94 95 findAncestor(targetNodeFilter: (node: this) => boolean): this | undefined { 96 let ancestor = this.getParent(); 97 98 while (ancestor && !targetNodeFilter(ancestor)) { 99 ancestor = ancestor.getParent(); 100 } 101 102 return ancestor; 103 } 104 105 getWarnings(): UserWarning[] { 106 return this.warnings; 107 } 108 109 addWarning(warning: UserWarning) { 110 this.warnings.push(warning); 111 } 112} 113