1 /* 2 * Copyright (C) 2023 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 android.tools.common.traces.surfaceflinger 18 19 import android.tools.common.datatypes.ActiveBuffer 20 import android.tools.common.datatypes.Color 21 import android.tools.common.datatypes.Rect 22 import android.tools.common.datatypes.RectF 23 import android.tools.common.datatypes.Region 24 import android.tools.common.withCache 25 import kotlin.js.JsExport 26 import kotlin.js.JsName 27 28 /** {@inheritDoc} */ 29 @JsExport 30 class LayerProperties 31 private constructor( 32 override val visibleRegion: Region = Region.EMPTY, 33 override val activeBuffer: ActiveBuffer = ActiveBuffer.EMPTY, 34 override val flags: Int = 0, 35 override val bounds: RectF = RectF.EMPTY, 36 override val color: Color = Color.EMPTY, 37 private val _isOpaque: Boolean = false, 38 override val shadowRadius: Float = 0f, 39 override val cornerRadius: Float = 0f, 40 override val type: String = "", 41 override val screenBounds: RectF = RectF.EMPTY, 42 override val transform: Transform = Transform.EMPTY, 43 override val sourceBounds: RectF = RectF.EMPTY, 44 override val effectiveScalingMode: Int = 0, 45 override val bufferTransform: Transform = Transform.EMPTY, 46 override val hwcCompositionType: HwcCompositionType = HwcCompositionType.INVALID, 47 override val hwcCrop: RectF = RectF.EMPTY, 48 override val hwcFrame: Rect = Rect.EMPTY, 49 override val backgroundBlurRadius: Int = 0, 50 override val crop: Rect = Rect.EMPTY, 51 override val isRelativeOf: Boolean = false, 52 override val zOrderRelativeOfId: Int = 0, 53 override val stackId: Int = 0, 54 override val requestedTransform: Transform = Transform.EMPTY, 55 override val requestedColor: Color = Color.EMPTY, 56 override val cornerRadiusCrop: RectF = RectF.EMPTY, 57 override val inputTransform: Transform = Transform.EMPTY, 58 override val inputRegion: Region? = null, 59 override val excludesCompositionState: Boolean = false 60 ) : ILayerProperties { 61 override val isOpaque: Boolean = if (color.a != 1.0f) false else _isOpaque 62 hashCodenull63 override fun hashCode(): Int { 64 var result = visibleRegion.hashCode() 65 result = 31 * result + activeBuffer.hashCode() 66 result = 31 * result + flags 67 result = 31 * result + bounds.hashCode() 68 result = 31 * result + color.hashCode() 69 result = 31 * result + _isOpaque.hashCode() 70 result = 31 * result + shadowRadius.hashCode() 71 result = 31 * result + cornerRadius.hashCode() 72 result = 31 * result + type.hashCode() 73 result = 31 * result + screenBounds.hashCode() 74 result = 31 * result + transform.hashCode() 75 result = 31 * result + sourceBounds.hashCode() 76 result = 31 * result + effectiveScalingMode 77 result = 31 * result + bufferTransform.hashCode() 78 result = 31 * result + hwcCompositionType.hashCode() 79 result = 31 * result + hwcCrop.hashCode() 80 result = 31 * result + hwcFrame.hashCode() 81 result = 31 * result + backgroundBlurRadius 82 result = 31 * result + crop.hashCode() 83 result = 31 * result + isRelativeOf.hashCode() 84 result = 31 * result + zOrderRelativeOfId 85 result = 31 * result + stackId 86 result = 31 * result + requestedTransform.hashCode() 87 result = 31 * result + requestedColor.hashCode() 88 result = 31 * result + cornerRadiusCrop.hashCode() 89 result = 31 * result + inputTransform.hashCode() 90 result = 31 * result + (inputRegion?.hashCode() ?: 0) 91 result = 31 * result + screenBounds.hashCode() 92 result = 31 * result + isOpaque.hashCode() 93 result = 31 * result + excludesCompositionState.hashCode() 94 return result 95 } 96 toStringnull97 override fun toString(): String { 98 return "LayerProperties(visibleRegion=$visibleRegion, activeBuffer=$activeBuffer, " + 99 "flags=$flags, bounds=$bounds, color=$color, _isOpaque=$_isOpaque, " + 100 "shadowRadius=$shadowRadius, cornerRadius=$cornerRadius, type='$type', " + 101 "screenBounds=$screenBounds, transform=$transform, sourceBounds=$sourceBounds, " + 102 "effectiveScalingMode=$effectiveScalingMode, bufferTransform=$bufferTransform, " + 103 "hwcCompositionType=$hwcCompositionType, hwcCrop=$hwcCrop, hwcFrame=$hwcFrame, " + 104 "backgroundBlurRadius=$backgroundBlurRadius, crop=$crop, isRelativeOf=$isRelativeOf, " + 105 "zOrderRelativeOfId=$zOrderRelativeOfId, stackId=$stackId, " + 106 "requestedTransform=$requestedTransform, requestedColor=$requestedColor, " + 107 "cornerRadiusCrop=$cornerRadiusCrop, inputTransform=$inputTransform, " + 108 "inputRegion=$inputRegion, screenBounds=$screenBounds, isOpaque=$isOpaque, " + 109 "excludesCompositionState=$excludesCompositionState)" 110 } 111 equalsnull112 override fun equals(other: Any?): Boolean { 113 if (this === other) return true 114 if (other !is LayerProperties) return false 115 116 if (visibleRegion != other.visibleRegion) return false 117 if (activeBuffer != other.activeBuffer) return false 118 if (flags != other.flags) return false 119 if (bounds != other.bounds) return false 120 if (color != other.color) return false 121 if (_isOpaque != other._isOpaque) return false 122 if (shadowRadius != other.shadowRadius) return false 123 if (cornerRadius != other.cornerRadius) return false 124 if (type != other.type) return false 125 if (screenBounds != other.screenBounds) return false 126 if (transform != other.transform) return false 127 if (sourceBounds != other.sourceBounds) return false 128 if (effectiveScalingMode != other.effectiveScalingMode) return false 129 if (bufferTransform != other.bufferTransform) return false 130 if (hwcCompositionType != other.hwcCompositionType) return false 131 if (hwcCrop != other.hwcCrop) return false 132 if (hwcFrame != other.hwcFrame) return false 133 if (backgroundBlurRadius != other.backgroundBlurRadius) return false 134 if (crop != other.crop) return false 135 if (isRelativeOf != other.isRelativeOf) return false 136 if (zOrderRelativeOfId != other.zOrderRelativeOfId) return false 137 if (stackId != other.stackId) return false 138 if (requestedTransform != other.requestedTransform) return false 139 if (requestedColor != other.requestedColor) return false 140 if (cornerRadiusCrop != other.cornerRadiusCrop) return false 141 if (inputTransform != other.inputTransform) return false 142 if (inputRegion != other.inputRegion) return false 143 if (screenBounds != other.screenBounds) return false 144 if (isOpaque != other.isOpaque) return false 145 if (excludesCompositionState != other.excludesCompositionState) return false 146 147 return true 148 } 149 150 companion object { 151 @JsName("EMPTY") 152 val EMPTY: LayerProperties <lambda>null153 get() = withCache { LayerProperties() } 154 155 @JsName("from") fromnull156 fun from( 157 visibleRegion: Region, 158 activeBuffer: ActiveBuffer, 159 flags: Int, 160 bounds: RectF, 161 color: Color, 162 isOpaque: Boolean, 163 shadowRadius: Float, 164 cornerRadius: Float, 165 type: String, 166 screenBounds: RectF, 167 transform: Transform, 168 sourceBounds: RectF, 169 effectiveScalingMode: Int, 170 bufferTransform: Transform, 171 hwcCompositionType: HwcCompositionType, 172 hwcCrop: RectF, 173 hwcFrame: Rect, 174 backgroundBlurRadius: Int, 175 crop: Rect?, 176 isRelativeOf: Boolean, 177 zOrderRelativeOfId: Int, 178 stackId: Int, 179 requestedTransform: Transform, 180 requestedColor: Color, 181 cornerRadiusCrop: RectF, 182 inputTransform: Transform, 183 inputRegion: Region?, 184 excludesCompositionState: Boolean 185 ): ILayerProperties { 186 return withCache { 187 LayerProperties( 188 visibleRegion, 189 activeBuffer, 190 flags, 191 bounds, 192 color, 193 isOpaque, 194 shadowRadius, 195 cornerRadius, 196 type, 197 screenBounds, 198 transform, 199 sourceBounds, 200 effectiveScalingMode, 201 bufferTransform, 202 hwcCompositionType, 203 hwcCrop, 204 hwcFrame, 205 backgroundBlurRadius, 206 crop ?: Rect.EMPTY, 207 isRelativeOf, 208 zOrderRelativeOfId, 209 stackId, 210 requestedTransform, 211 requestedColor, 212 cornerRadiusCrop, 213 inputTransform, 214 inputRegion, 215 excludesCompositionState 216 ) 217 } 218 } 219 } 220 } 221