xref: /aosp_15_r20/development/tools/winscope/src/parsers/surface_flinger/operations/add_composition_type.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 {perfetto} from 'protos/surfaceflinger/latest/static';
18import {LayerCompositionType} from 'trace/layer_composition_type';
19import {AddOperation} from 'trace/tree_node/operations/add_operation';
20import {PropertyTreeNode} from 'trace/tree_node/property_tree_node';
21import {DEFAULT_PROPERTY_TREE_NODE_FACTORY} from 'trace/tree_node/property_tree_node_factory';
22
23export class AddCompositionType extends AddOperation<PropertyTreeNode> {
24  protected override makeProperties(
25    value: PropertyTreeNode,
26  ): PropertyTreeNode[] {
27    const hwcCompositionType = value
28      .getChildByName('hwcCompositionType')
29      ?.getValue();
30    let compositionType: LayerCompositionType | undefined;
31
32    // must check both enum and string values due to SF perfetto dumps giving translated proto values
33    if (this.gpuLayerCompositionTypes.includes(hwcCompositionType)) {
34      compositionType = LayerCompositionType.GPU;
35    } else if (this.hwcLayerCompositionTypes.includes(hwcCompositionType)) {
36      compositionType = LayerCompositionType.HWC;
37    }
38
39    return compositionType === undefined
40      ? []
41      : [
42          DEFAULT_PROPERTY_TREE_NODE_FACTORY.makeCalculatedProperty(
43            value.id,
44            'compositionType',
45            compositionType,
46          ),
47        ];
48  }
49
50  private readonly gpuLayerCompositionTypes = [
51    perfetto.protos.HwcCompositionType.HWC_TYPE_CLIENT,
52    perfetto.protos.HwcCompositionType[
53      perfetto.protos.HwcCompositionType.HWC_TYPE_CLIENT
54    ],
55  ];
56
57  private readonly hwcLayerCompositionTypes = [
58    perfetto.protos.HwcCompositionType.HWC_TYPE_DEVICE,
59    perfetto.protos.HwcCompositionType[
60      perfetto.protos.HwcCompositionType.HWC_TYPE_DEVICE
61    ],
62    perfetto.protos.HwcCompositionType.HWC_TYPE_SOLID_COLOR,
63    perfetto.protos.HwcCompositionType[
64      perfetto.protos.HwcCompositionType.HWC_TYPE_SOLID_COLOR
65    ],
66  ];
67}
68