1/* 2 * Copyright 2021, 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 {TimeUtils} from 'common/time_utils'; 18import {ElapsedTimestamp, RealTimestamp} from 'trace/timestamp'; 19import { 20 Display, 21 LayerTraceEntry, 22 LayerTraceEntryBuilder, 23 toRect, 24 toSize, 25 toTransform, 26} from '../common'; 27import {getPropertiesForDisplay} from '../mixin'; 28import {Layer} from './Layer'; 29 30LayerTraceEntry.fromProto = ( 31 protos: object[], 32 displayProtos: object[], 33 elapsedTimestamp: bigint, 34 vSyncId: number, 35 hwcBlob: string, 36 where = '', 37 realToElapsedTimeOffsetNs: bigint | undefined = undefined, 38 useElapsedTime = false, 39 excludesCompositionState = false 40): LayerTraceEntry => { 41 const layers = protos.map((it) => Layer.fromProto(it, excludesCompositionState)); 42 const displays = (displayProtos || []).map((it) => newDisplay(it)); 43 const builder = new LayerTraceEntryBuilder() 44 .setElapsedTimestamp(`${elapsedTimestamp}`) 45 .setLayers(layers) 46 .setDisplays(displays) 47 .setVSyncId(`${vSyncId}`) 48 .setHwcBlob(hwcBlob) 49 .setWhere(where) 50 .setRealToElapsedTimeOffsetNs(`${realToElapsedTimeOffsetNs ?? 0}`); 51 const entry: LayerTraceEntry = builder.build(); 52 53 addAttributes(entry, protos, realToElapsedTimeOffsetNs === undefined || useElapsedTime); 54 return entry; 55}; 56 57function addAttributes(entry: LayerTraceEntry, protos: object[], useElapsedTime = false) { 58 entry.kind = 'entry'; 59 // Avoid parsing the entry root because it is an array of layers 60 // containing all trace information, this slows down the property tree. 61 // Instead parse only key properties for debugging 62 const newObj = getPropertiesForDisplay(entry); 63 if (newObj.rects) delete newObj.rects; 64 if (newObj.flattenedLayers) delete newObj.flattenedLayers; 65 if (newObj.physicalDisplays) delete newObj.physicalDisplays; 66 if (newObj.physicalDisplayBounds) delete newObj.physicalDisplayBounds; 67 if (newObj.isVisible) delete newObj.isVisible; 68 entry.proto = newObj; 69 if (useElapsedTime || entry.clockTimestamp === undefined) { 70 entry.name = TimeUtils.format(new ElapsedTimestamp(BigInt(entry.elapsedTimestamp))); 71 entry.shortName = entry.name; 72 } else { 73 entry.name = TimeUtils.format(new RealTimestamp(entry.clockTimestamp)); 74 entry.shortName = entry.name; 75 } 76} 77 78function newDisplay(proto: any): Display { 79 return new Display( 80 `${proto.id}`, 81 proto.name, 82 proto.layerStack, 83 toSize(proto.size), 84 toRect(proto.layerStackSpaceRect), 85 toTransform(proto.transform), 86 proto.isVirtual 87 ); 88} 89 90export {LayerTraceEntry}; 91