1 /* <lambda>null2 * Copyright (C) 2022 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 17 package com.android.server.wm.traces.common.layers 18 19 import com.android.server.wm.traces.common.FlickerComponentName 20 import com.android.server.wm.traces.common.ITraceEntry 21 import com.android.server.wm.traces.common.prettyTimestamp 22 23 abstract class BaseLayerTraceEntry : ITraceEntry { 24 abstract val hwcBlob: String 25 abstract val where: String 26 abstract val displays: Array<Display> 27 val stableId: String get() = this::class.simpleName ?: error("Unable to determine class") 28 val name: String get() = prettyTimestamp(timestamp) 29 30 abstract val flattenedLayers: Array<Layer> 31 val visibleLayers: Array<Layer> 32 get() = flattenedLayers.filter { it.isVisible }.toTypedArray() 33 34 // for winscope 35 val isVisible: Boolean = true 36 val children: Array<Layer> 37 get() = flattenedLayers.filter { it.isRootLayer }.toTypedArray() 38 39 fun getLayerWithBuffer(name: String): Layer? { 40 return flattenedLayers.firstOrNull { 41 it.name.contains(name) && it.activeBuffer.isNotEmpty 42 } 43 } 44 45 fun getLayerById(layerId: Int): Layer? = this.flattenedLayers.firstOrNull { it.id == layerId } 46 47 /** 48 * Checks if any layer in the screen is animating. 49 * 50 * The screen is animating when a layer is not simple rotation, of when the pip overlay 51 * layer is visible 52 */ 53 fun isAnimating(windowName: String = ""): Boolean { 54 val layers = visibleLayers.filter { it.name.contains(windowName) } 55 val layersAnimating = layers.any { layer -> !layer.transform.isSimpleRotation } 56 val pipAnimating = isVisible(FlickerComponentName.PIP_CONTENT_OVERLAY.toWindowName()) 57 return layersAnimating || pipAnimating 58 } 59 60 /** 61 * Check if at least one window which matches provided window name is visible. 62 */ 63 fun isVisible(windowName: String): Boolean = 64 visibleLayers.any { it.name.contains(windowName) } 65 66 fun asTrace(): LayersTrace = LayersTrace(arrayOf(this)) 67 68 override fun toString(): String { 69 return "${prettyTimestamp(timestamp)} (timestamp=$timestamp)" 70 } 71 72 override fun equals(other: Any?): Boolean { 73 return other is BaseLayerTraceEntry && other.timestamp == this.timestamp 74 } 75 76 override fun hashCode(): Int { 77 var result = timestamp.hashCode() 78 result = 31 * result + hwcBlob.hashCode() 79 result = 31 * result + where.hashCode() 80 result = 31 * result + displays.contentHashCode() 81 result = 31 * result + isVisible.hashCode() 82 result = 31 * result + flattenedLayers.contentHashCode() 83 return result 84 } 85 }