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.Rect 20 import android.tools.common.datatypes.Size 21 import android.tools.common.withCache 22 import kotlin.js.JsExport 23 import kotlin.js.JsName 24 25 /** Wrapper for DisplayProto (frameworks/native/services/surfaceflinger/layerproto/display.proto) */ 26 @JsExport 27 class Display 28 private constructor( 29 @JsName("id") val id: String, 30 @JsName("name") val name: String, 31 @JsName("layerStackId") val layerStackId: Int, 32 @JsName("size") val size: Size, 33 @JsName("layerStackSpace") val layerStackSpace: Rect, 34 @JsName("transform") val transform: Transform, 35 @JsName("isVirtual") val isVirtual: Boolean 36 ) { 37 @JsName("isOff") val isOff = layerStackId == BLANK_LAYER_STACK 38 @JsName("isOn") val isOn = !isOff 39 40 // Alias for layerStackSpace, since bounds is what is used for layers 41 val bounds = layerStackSpace 42 equalsnull43 override fun equals(other: Any?): Boolean { 44 if (this === other) return true 45 if (other !is Display) return false 46 47 if (id != other.id) return false 48 if (name != other.name) return false 49 if (layerStackId != other.layerStackId) return false 50 if (size != other.size) return false 51 if (layerStackSpace != other.layerStackSpace) return false 52 if (transform != other.transform) return false 53 if (isVirtual != other.isVirtual) return false 54 55 return true 56 } 57 hashCodenull58 override fun hashCode(): Int { 59 var result = id.hashCode() 60 result = 31 * result + name.hashCode() 61 result = 31 * result + layerStackId 62 result = 31 * result + size.hashCode() 63 result = 31 * result + layerStackSpace.hashCode() 64 result = 31 * result + transform.hashCode() 65 result = 31 * result + isVirtual.hashCode() 66 return result 67 } 68 69 companion object { 70 const val BLANK_LAYER_STACK = -1 71 72 @JsName("EMPTY") 73 val EMPTY: Display <lambda>null74 get() = withCache { 75 Display( 76 id = "0", 77 name = "EMPTY", 78 layerStackId = BLANK_LAYER_STACK, 79 size = Size.EMPTY, 80 layerStackSpace = Rect.EMPTY, 81 transform = Transform.EMPTY, 82 isVirtual = false 83 ) 84 } 85 86 @JsName("from") fromnull87 fun from( 88 id: String, 89 name: String, 90 layerStackId: Int, 91 size: Size, 92 layerStackSpace: Rect, 93 transform: Transform, 94 isVirtual: Boolean 95 ): Display = withCache { 96 Display(id, name, layerStackId, size, layerStackSpace, transform, isVirtual) 97 } 98 } 99 } 100