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.traces.surfaceflinger 18 19 import android.graphics.Color 20 import android.graphics.RectF 21 import android.graphics.Region 22 import android.tools.datatypes.ActiveBuffer 23 import android.tools.datatypes.emptyColor 24 import android.tools.withCache 25 26 /** {@inheritDoc} */ 27 class LayerProperties 28 private constructor( 29 override val visibleRegion: Region = Region(), 30 override val activeBuffer: ActiveBuffer = ActiveBuffer.EMPTY, 31 override val flags: Int = 0, 32 override val bounds: RectF = RectF(), 33 override val color: Color = emptyColor(), 34 private val _isOpaque: Boolean = false, 35 override val shadowRadius: Float = 0f, 36 override val cornerRadius: Float = 0f, 37 override val screenBounds: RectF = RectF(), 38 override val transform: Transform = Transform.EMPTY, 39 override val effectiveScalingMode: Int = 0, 40 override val bufferTransform: Transform = Transform.EMPTY, 41 override val hwcCompositionType: HwcCompositionType = HwcCompositionType.HWC_TYPE_UNSPECIFIED, 42 override val backgroundBlurRadius: Int = 0, 43 override val crop: RectF = RectF(), 44 override val isRelativeOf: Boolean = false, 45 override val zOrderRelativeOfId: Int = 0, 46 override val stackId: Int = 0, 47 override val excludesCompositionState: Boolean = false 48 ) : ILayerProperties { 49 override val isOpaque: Boolean = if (color.alpha() != 1.0f) false else _isOpaque 50 hashCodenull51 override fun hashCode(): Int { 52 var result = visibleRegion.hashCode() 53 result = 31 * result + activeBuffer.hashCode() 54 result = 31 * result + flags 55 result = 31 * result + bounds.hashCode() 56 result = 31 * result + color.hashCode() 57 result = 31 * result + _isOpaque.hashCode() 58 result = 31 * result + shadowRadius.hashCode() 59 result = 31 * result + cornerRadius.hashCode() 60 result = 31 * result + screenBounds.hashCode() 61 result = 31 * result + transform.hashCode() 62 result = 31 * result + effectiveScalingMode 63 result = 31 * result + bufferTransform.hashCode() 64 result = 31 * result + hwcCompositionType.hashCode() 65 result = 31 * result + backgroundBlurRadius 66 result = 31 * result + crop.hashCode() 67 result = 31 * result + isRelativeOf.hashCode() 68 result = 31 * result + zOrderRelativeOfId 69 result = 31 * result + stackId 70 result = 31 * result + screenBounds.hashCode() 71 result = 31 * result + isOpaque.hashCode() 72 result = 31 * result + excludesCompositionState.hashCode() 73 return result 74 } 75 toStringnull76 override fun toString(): String { 77 return "LayerProperties(visibleRegion=$visibleRegion, activeBuffer=$activeBuffer, " + 78 "flags=$flags, bounds=$bounds, color=$color, _isOpaque=$_isOpaque, " + 79 "shadowRadius=$shadowRadius, cornerRadius=$cornerRadius, " + 80 "screenBounds=$screenBounds, transform=$transform, " + 81 "effectiveScalingMode=$effectiveScalingMode, bufferTransform=$bufferTransform, " + 82 "hwcCompositionType=$hwcCompositionType, " + 83 "backgroundBlurRadius=$backgroundBlurRadius, crop=$crop, isRelativeOf=$isRelativeOf, " + 84 "zOrderRelativeOfId=$zOrderRelativeOfId, stackId=$stackId, " + 85 "screenBounds=$screenBounds, isOpaque=$isOpaque, " + 86 "excludesCompositionState=$excludesCompositionState)" 87 } 88 equalsnull89 override fun equals(other: Any?): Boolean { 90 if (this === other) return true 91 if (other !is LayerProperties) return false 92 93 if (visibleRegion != other.visibleRegion) return false 94 if (activeBuffer != other.activeBuffer) return false 95 if (flags != other.flags) return false 96 if (bounds != other.bounds) return false 97 if (color != other.color) return false 98 if (_isOpaque != other._isOpaque) return false 99 if (shadowRadius != other.shadowRadius) return false 100 if (cornerRadius != other.cornerRadius) return false 101 if (screenBounds != other.screenBounds) return false 102 if (transform != other.transform) return false 103 if (effectiveScalingMode != other.effectiveScalingMode) return false 104 if (bufferTransform != other.bufferTransform) return false 105 if (hwcCompositionType != other.hwcCompositionType) return false 106 if (backgroundBlurRadius != other.backgroundBlurRadius) return false 107 if (crop != other.crop) return false 108 if (isRelativeOf != other.isRelativeOf) return false 109 if (zOrderRelativeOfId != other.zOrderRelativeOfId) return false 110 if (stackId != other.stackId) return false 111 if (screenBounds != other.screenBounds) return false 112 if (isOpaque != other.isOpaque) return false 113 if (excludesCompositionState != other.excludesCompositionState) return false 114 115 return true 116 } 117 118 companion object { 119 val EMPTY: LayerProperties <lambda>null120 get() = withCache { LayerProperties() } 121 fromnull122 fun from( 123 visibleRegion: Region, 124 activeBuffer: ActiveBuffer, 125 flags: Int, 126 bounds: RectF, 127 color: Color, 128 isOpaque: Boolean, 129 shadowRadius: Float, 130 cornerRadius: Float, 131 screenBounds: RectF, 132 transform: Transform, 133 effectiveScalingMode: Int, 134 bufferTransform: Transform, 135 hwcCompositionType: HwcCompositionType, 136 backgroundBlurRadius: Int, 137 crop: RectF?, 138 isRelativeOf: Boolean, 139 zOrderRelativeOfId: Int, 140 stackId: Int, 141 excludesCompositionState: Boolean 142 ): ILayerProperties { 143 return withCache { 144 LayerProperties( 145 visibleRegion, 146 activeBuffer, 147 flags, 148 bounds, 149 color, 150 isOpaque, 151 shadowRadius, 152 cornerRadius, 153 screenBounds, 154 transform, 155 effectiveScalingMode, 156 bufferTransform, 157 hwcCompositionType, 158 backgroundBlurRadius, 159 crop ?: RectF(), 160 isRelativeOf, 161 zOrderRelativeOfId, 162 stackId, 163 excludesCompositionState 164 ) 165 } 166 } 167 } 168 } 169