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 { 18 HwcCompositionType, 19 Layer, 20 LayerProperties, 21 Rect, 22 toActiveBuffer, 23 toColor, 24 toCropRect, 25 toRect, 26 toRectF, 27 toRegion, 28} from '../common'; 29import {shortenName} from '../mixin'; 30import {Transform} from './Transform'; 31 32Layer.fromProto = (proto: any, excludesCompositionState = false): Layer => { 33 const visibleRegion = toRegion(proto.visibleRegion); 34 const activeBuffer = toActiveBuffer(proto.activeBuffer); 35 const bounds = toRectF(proto.bounds); 36 const color = toColor(proto.color); 37 const screenBounds = toRectF(proto.screenBounds); 38 const sourceBounds = toRectF(proto.sourceBounds); 39 const transform = Transform.fromProto(proto.transform, proto.position); 40 const bufferTransform = Transform.fromProto(proto.bufferTransform, /* position */ null); 41 const hwcCrop = toRectF(proto.hwcCrop); 42 const hwcFrame = toRect(proto.hwcFrame); 43 const requestedColor = toColor(proto.requestedColor); 44 const requestedTransform = Transform.fromProto(proto.requestedTransform, proto.requestedPosition); 45 const cornerRadiusCrop = toRectF(proto.cornerRadiusCrop); 46 const inputTransform = Transform.fromProto( 47 proto.inputWindowInfo ? proto.inputWindowInfo.transform : null 48 ); 49 const inputRegion = toRegion( 50 proto.inputWindowInfo ? proto.inputWindowInfo.touchableRegion : null 51 ); 52 const crop: Rect = toCropRect(proto.crop); 53 54 const properties = new LayerProperties( 55 visibleRegion, 56 activeBuffer, 57 /* flags */ proto.flags, 58 bounds, 59 color, 60 /* isOpaque */ proto.isOpaque, 61 /* shadowRadius */ proto.shadowRadius, 62 /* cornerRadius */ proto.cornerRadius, 63 /* type */ proto.type ?? ``, 64 screenBounds, 65 transform, 66 sourceBounds, 67 /* effectiveScalingMode */ proto.effectiveScalingMode, 68 bufferTransform, 69 /* hwcCompositionType */ new HwcCompositionType(proto.hwcCompositionType), 70 hwcCrop, 71 hwcFrame, 72 /* backgroundBlurRadius */ proto.backgroundBlurRadius, 73 crop, 74 /* isRelativeOf */ proto.isRelativeOf, 75 /* zOrderRelativeOfId */ proto.zOrderRelativeOf, 76 /* stackId */ proto.layerStack, 77 requestedTransform, 78 requestedColor, 79 cornerRadiusCrop, 80 inputTransform, 81 inputRegion, 82 excludesCompositionState 83 ); 84 85 const entry = new Layer( 86 /* name */ proto.name ?? ``, 87 /* id */ proto.id, 88 /*parentId */ proto.parent, 89 /* z */ proto.z, 90 /* currFrame */ proto.currFrame, 91 properties 92 ); 93 94 addAttributes(entry, proto); 95 return entry; 96}; 97 98function addAttributes(entry: Layer, proto: any) { 99 entry.kind = `${entry.id}`; 100 entry.shortName = shortenName(entry.name); 101 entry.proto = proto; 102 entry.rect = entry.bounds; 103 entry.rect.transform = entry.transform; 104 entry.rect.ref = entry; 105 entry.rect.label = entry.name; 106} 107 108export {Layer}; 109